/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef C_INCLUDE_DRAWING_H
#define C_INCLUDE_DRAWING_H
/**
* @addtogroup Drawing
* @{
*
* @brief Provides functions such as 2D graphics rendering, text drawing, and image display.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
*
* @since 8
* @version 1.0
*/
/**
* @file drawing_canvas.h
*
* @brief Declares functions related to the canvas object in the drawing module.
*
* @since 8
* @version 1.0
*/
#include "drawing_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Creates an OH_Drawing_Canvas object.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @return Returns the pointer to the OH_Drawing_Canvas object created.
* @since 8
* @version 1.0
*/
OH_Drawing_Canvas* OH_Drawing_CanvasCreate(void);
/**
* @brief Destroys an OH_Drawing_Canvas object and reclaims the memory occupied by the object.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @since 8
* @version 1.0
*/
void OH_Drawing_CanvasDestroy(OH_Drawing_Canvas*);
/**
* @brief Binds a bitmap to a canvas so that the content drawn on the canvas
* is output to the bitmap (this process is called CPU rendering).
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @param OH_Drawing_Bitmap Indicates the pointer to an OH_Drawing_Bitmap object.
* @since 8
* @version 1.0
*/
void OH_Drawing_CanvasBind(OH_Drawing_Canvas*, OH_Drawing_Bitmap*);
/**
* @brief Attaches a pen to a canvas so that the canvas will use the style and color of the pen to outline a shape.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @param OH_Drawing_Pen Indicates the pointer to an OH_Drawing_Pen object.
* @since 8
* @version 1.0
*/
void OH_Drawing_CanvasAttachPen(OH_Drawing_Canvas*, const OH_Drawing_Pen*);
/**
* @brief Detaches the pen from a canvas so that the canvas will not use the style
* and color of the pen to outline a shape.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @since 8
* @version 1.0
*/
void OH_Drawing_CanvasDetachPen(OH_Drawing_Canvas*);
/**
* @brief Attaches a brush to a canvas so that the canvas will use the style and color of the brush to fill in a shape.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @param OH_Drawing_Brush Indicates the pointer to an OH_Drawing_Brush object.
* @since 8
* @version 1.0
*/
void OH_Drawing_CanvasAttachBrush(OH_Drawing_Canvas*, const OH_Drawing_Brush*);
/**
* @brief Detaches the brush from a canvas so that the canvas will not use the style
* and color of the brush to fill in a shape.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @since 8
* @version 1.0
*/
void OH_Drawing_CanvasDetachBrush(OH_Drawing_Canvas*);
/**
* @brief Saves the current canvas status (canvas matrix) to the top of the stack.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @since 8
* @version 1.0
*/
void OH_Drawing_CanvasSave(OH_Drawing_Canvas*);
/**
* @brief Restores the canvas status (canvas matrix) saved on the top of the stack.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @since 8
* @version 1.0
*/
void OH_Drawing_CanvasRestore(OH_Drawing_Canvas*);
/**
* @brief Gets the number of the canvas status (canvas matrix) saved in the stack.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @return Returns a 32-bit variable that describes the number of canvas status.
* @since 11
* @version 1.0
*/
uint32_t OH_Drawing_CanvasGetSaveCount(OH_Drawing_Canvas*);
/**
* @brief Restores the specific number of the canvas status (canvas matrix) saved in the stack.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @param saveCount Indicates the specific number of canvas status.
* @since 11
* @version 1.0
*/
void OH_Drawing_CanvasRestoreToCount(OH_Drawing_Canvas*, uint32_t saveCount);
/**
* @brief Draws a line segment.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @param x1 Indicates the x coordinate of the start point of the line segment.
* @param y1 Indicates the y coordinate of the start point of the line segment.
* @param x2 Indicates the x coordinate of the end point of the line segment.
* @param y2 Indicates the y coordinate of the end point of the line segment.
* @since 8
* @version 1.0
*/
void OH_Drawing_CanvasDrawLine(OH_Drawing_Canvas*, float x1, float y1, float x2, float y2);
/**
* @brief Draws a path.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @param OH_Drawing_Path Indicates the pointer to an OH_Drawing_Path object.
* @since 8
* @version 1.0
*/
void OH_Drawing_CanvasDrawPath(OH_Drawing_Canvas*, const OH_Drawing_Path*);
/**
* @brief Draws a bitmap.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @param OH_Drawing_Bitmap Indicates the pointer to an OH_Drawing_Bitmap object.
* @param left Indicates the left position of the OH_Drawing_Bitmap.
* @param top Indicates the top position of the OH_Drawing_Bitmap.
* @since 11
* @version 1.0
*/
void OH_Drawing_CanvasDrawBitmap(OH_Drawing_Canvas*, const OH_Drawing_Bitmap*, float left, float top);
/**
* @brief Draws a rect.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @param OH_Drawing_Rect Indicates the pointer to an OH_Drawing_Rect object.
* @since 11
* @version 1.0
*/
void OH_Drawing_CanvasDrawRect(OH_Drawing_Canvas*, const OH_Drawing_Rect*);
/**
* @brief Draws a circle.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @param OH_Drawing_Point Indicates the pointer to an OH_Drawing_Point object.
* @param radius Indicates the radius of the circle.
* @since 11
* @version 1.0
*/
void OH_Drawing_CanvasDrawCircle(OH_Drawing_Canvas*, const OH_Drawing_Point*, float radius);
/**
* @brief Draws an oval.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @param OH_Drawing_Rect Indicates the pointer to an OH_Drawing_Rect object.
* @since 11
* @version 1.0
*/
void OH_Drawing_CanvasDrawOval(OH_Drawing_Canvas*, const OH_Drawing_Rect*);
/**
* @brief Draws an arc.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @param OH_Drawing_Rect Indicates the pointer to an OH_Drawing_Rect object.
* @param startAngle Indicates the startAngle of the arc.
* @param sweepAngle Indicates the sweepAngle of the arc.
* @since 11
* @version 1.0
*/
void OH_Drawing_CanvasDrawArc(OH_Drawing_Canvas*, const OH_Drawing_Rect*, float startAngle, float sweepAngle);
/**
* @brief Draws a roundrect.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @param OH_Drawing_RoundRect Indicates the pointer to an OH_Drawing_RoundRect object.
* @since 11
* @version 1.0
*/
void OH_Drawing_CanvasDrawRoundRect(OH_Drawing_Canvas*, const OH_Drawing_RoundRect*);
/**
* @brief Draws a textblob.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @param OH_Drawing_TextBlob Indicates the pointer to an OH_Drawing_TextBlob object.
* @param x Indicates the horizontal offset applied to blob.
* @param y Indicates the vertical offset applied to blob.
* @since 11
* @version 1.0
*/
void OH_Drawing_CanvasDrawTextBlob(OH_Drawing_Canvas*, const OH_Drawing_TextBlob*, float x, float y);
/**
* @brief Enumerates clip op.
*
* @since 11
* @version 1.0
*/
typedef enum {
/**
* Clip with difference.
*/
DIFFERENCE,
/**
* Clip with intersection.
*/
INTERSECT,
} OH_Drawing_CanvasClipOp;
/**
* @brief Clip a rect.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @param OH_Drawing_Rect Indicates the pointer to an OH_Drawing_Rect object.
* @param clipOp Indicates the operation to apply to clip.
* @param doAntiAlias Indicates whether clip operation requires anti-aliased.
* @since 11
* @version 1.0
*/
void OH_Drawing_CanvasClipRect(OH_Drawing_Canvas*, const OH_Drawing_Rect*,
OH_Drawing_CanvasClipOp clipOp, bool doAntiAlias);
/**
* @brief Clip a path.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @param OH_Drawing_Path Indicates the pointer to an OH_Drawing_Path object.
* @param clipOp Indicates the operation to apply to clip.
* @param doAntiAlias Indicates whether clip operation requires anti-aliased.
* @since 11
* @version 1.0
*/
void OH_Drawing_CanvasClipPath(OH_Drawing_Canvas*, const OH_Drawing_Path*,
OH_Drawing_CanvasClipOp clipOp, bool doAntiAlias);
/**
* @brief Rotates by degrees. Positive degrees rotates clockwise.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @param degrees Indicates the amount to rotate, in degrees.
* @param px Indicates the x-axis value of the point to rotate about.
* @param py Indicates the y-axis value of the point to rotate about.
* @since 11
* @version 1.0
*/
void OH_Drawing_CanvasRotate(OH_Drawing_Canvas*, float degrees, float px, float py);
/**
* @brief Translates by dx along the x-axis and dy along the y-axis.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @param dx Indicates the distance to translate on x-axis.
* @param dy Indicates the distance to translate on y-axis.
* @since 11
* @version 1.0
*/
void OH_Drawing_CanvasTranslate(OH_Drawing_Canvas*, float dx, float dy);
/**
* @brief Scales by sx on the x-axis and sy on the y-axis.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @param sx Indicates the amount to scale on x-axis.
* @param sy Indicates the amount to scale on y-axis.
* @since 11
* @version 1.0
*/
void OH_Drawing_CanvasScale(OH_Drawing_Canvas*, float sx, float sy);
/**
* @brief Clears a canvas by using a specified color.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Canvas Indicates the pointer to an OH_Drawing_Canvas object.
* @param color Indicates the color, which is a 32-bit (ARGB) variable.
* @since 8
* @version 1.0
*/
void OH_Drawing_CanvasClear(OH_Drawing_Canvas*, uint32_t color);
#ifdef __cplusplus
}
#endif
/** @} */
#endif