1 /* 2 * Copyright (c) 2021-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup Drawing 18 * @{ 19 * 20 * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. 21 * 22 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 23 * 24 * @since 8 25 * @version 1.0 26 */ 27 28 /** 29 * @file drawing_brush.h 30 * 31 * @brief Declares functions related to the <b>brush</b> object in the drawing module. 32 * 33 * @kit ArkGraphics2D 34 * @library libnative_drawing.so 35 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 36 * @since 8 37 * @version 1.0 38 */ 39 40 #ifndef C_INCLUDE_DRAWING_BRUSH_H 41 #define C_INCLUDE_DRAWING_BRUSH_H 42 43 #include "drawing_error_code.h" 44 #include "drawing_types.h" 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 50 /** 51 * @brief Defines a colorspace manager. Introduces the color space information defined by ColorManager. 52 * @since 20 53 */ 54 typedef struct OH_NativeColorSpaceManager OH_NativeColorSpaceManager; 55 56 /** 57 * @brief Creates an <b>OH_Drawing_Brush</b> object. 58 * 59 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 60 * @return Returns the pointer to the <b>OH_Drawing_Brush</b> object created. 61 * @since 8 62 * @version 1.0 63 */ 64 OH_Drawing_Brush* OH_Drawing_BrushCreate(void); 65 66 /** 67 * @brief Creates an <b>OH_Drawing_Brush</b> copy object. 68 * 69 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 70 * @param brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 71 * @return Returns the pointer to the <b>OH_Drawing_Brush</b> object created. 72 * If nullptr is returned, the creation fails. 73 * The possible cause of the failure is that the available memory is empty or a nullptr is passed. 74 * @since 12 75 * @version 1.0 76 */ 77 OH_Drawing_Brush* OH_Drawing_BrushCopy(OH_Drawing_Brush* brush); 78 79 /** 80 * @brief Destroys an <b>OH_Drawing_Brush</b> object and reclaims the memory occupied by the object. 81 * 82 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 83 * @param brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 84 * @since 8 85 * @version 1.0 86 */ 87 void OH_Drawing_BrushDestroy(OH_Drawing_Brush* brush); 88 89 /** 90 * @brief Checks whether anti-aliasing is enabled for a brush. If anti-aliasing is enabled, 91 * edges will be drawn with partial transparency. 92 * 93 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 94 * @param brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 95 * @return Returns <b>true</b> if anti-aliasing is enabled; returns <b>false</b> otherwise. 96 * @since 8 97 * @version 1.0 98 */ 99 bool OH_Drawing_BrushIsAntiAlias(const OH_Drawing_Brush* brush); 100 101 /** 102 * @brief Enables or disables anti-aliasing for a brush. If anti-aliasing is enabled, 103 * edges will be drawn with partial transparency. 104 * 105 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 106 * @param brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 107 * @param antiAlias Specifies whether to enable anti-aliasing. The value <b>true</b> means 108 * to enable anti-aliasing, and <b>false</b> means the opposite. 109 * @since 8 110 * @version 1.0 111 */ 112 void OH_Drawing_BrushSetAntiAlias(OH_Drawing_Brush* brush, bool antiAlias); 113 114 /** 115 * @brief Obtains the color of a brush. The color is used by the brush to fill in a shape. 116 * 117 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 118 * @param brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 119 * @return Returns a 32-bit (ARGB) variable that describes the color. 120 * @since 8 121 * @version 1.0 122 */ 123 uint32_t OH_Drawing_BrushGetColor(const OH_Drawing_Brush* brush); 124 125 /** 126 * @brief Sets the color for a brush. The color will be used by the brush to fill in a shape. 127 * 128 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 129 * @param brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 130 * @param color Indicates the color to set, which is a 32-bit (ARGB) variable. 131 * @since 8 132 * @version 1.0 133 */ 134 void OH_Drawing_BrushSetColor(OH_Drawing_Brush* brush, uint32_t color); 135 136 /** 137 * @brief Obtains the alpha of a brush. The alpha is used by the brush to fill in a shape. 138 * 139 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 140 * @param brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 141 * @return Returns a 8-bit variable that describes the alpha. 142 * @since 11 143 * @version 1.0 144 */ 145 uint8_t OH_Drawing_BrushGetAlpha(const OH_Drawing_Brush* brush); 146 147 /** 148 * @brief Sets the alpha for a brush. The alpha will be used by the brush to fill in a shape. 149 * 150 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 151 * @param brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 152 * @param alpha Indicates the alpha to set, which is a 8-bit variable. 153 * @since 11 154 * @version 1.0 155 */ 156 void OH_Drawing_BrushSetAlpha(OH_Drawing_Brush* brush, uint8_t alpha); 157 158 /** 159 * @brief Sets the color for a brush. The color will be used by the brush to fill in a shape. 160 * The color is an ARGB structure described by floating point numbers and interpreted as being in the colorSpaceManager. 161 * If colorSpaceManager is nullptr, then color is assumed to be in the sRGB color space. 162 * 163 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 164 * @param brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 165 * @param a Indicates the alpha component of color, represented as a floating point number between 0 and 1. 166 * @param r Indicates the red component of color, represented as a floating point number between 0 and 1. 167 * @param g Indicates the green component of color, represented as a floating point number between 0 and 1. 168 * @param b Indicates the blue component of color, represented as a floating point number between 0 and 1. 169 * @param colorSpaceManager Indicates the pointer to an <b>OH_NativeColorSpaceManager</b> object. 170 * @return Returns the error code. 171 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 172 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if brush is nullptr. 173 * @since 20 174 * @version 1.0 175 */ 176 OH_Drawing_ErrorCode OH_Drawing_BrushSetColor4f(OH_Drawing_Brush* brush, float a, float r, float g, float b, 177 OH_NativeColorSpaceManager* colorSpaceManager); 178 179 /** 180 * @brief Obtains the alpha component of a brush. 181 * 182 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 183 * @param brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 184 * @param a Indicates the alpha component of color. 185 * @return Returns the error code. 186 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 187 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if brush or a is nullptr. 188 * @since 20 189 * @version 1.0 190 */ 191 OH_Drawing_ErrorCode OH_Drawing_BrushGetAlphaFloat(const OH_Drawing_Brush* brush, float* a); 192 193 /** 194 * @brief Obtains the red component of a brush. 195 * 196 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 197 * @param brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 198 * @param r Indicates the red component of color. 199 * @return Returns the error code. 200 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 201 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if brush or r is nullptr. 202 * @since 20 203 * @version 1.0 204 */ 205 OH_Drawing_ErrorCode OH_Drawing_BrushGetRedFloat(const OH_Drawing_Brush* brush, float* r); 206 207 /** 208 * @brief Obtains the green component of a brush. 209 * 210 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 211 * @param brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 212 * @param g Indicates the green component of color. 213 * @return Returns the error code. 214 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 215 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if brush or g is nullptr. 216 * @since 20 217 * @version 1.0 218 */ 219 OH_Drawing_ErrorCode OH_Drawing_BrushGetGreenFloat(const OH_Drawing_Brush* brush, float* g); 220 221 /** 222 * @brief Obtains the blue component of a brush. 223 * 224 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 225 * @param brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 226 * @param b Indicates the blue component of color. 227 * @return Returns the error code. 228 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 229 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if brush or b is nullptr. 230 * @since 20 231 * @version 1.0 232 */ 233 OH_Drawing_ErrorCode OH_Drawing_BrushGetBlueFloat(const OH_Drawing_Brush* brush, float* b); 234 235 /** 236 * @brief Sets the shaderEffect for a brush. 237 * 238 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 239 * @param brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 240 * @param shaderEffect Indicates the pointer to an <b>OH_Drawing_ShaderEffect</b> object. 241 * @since 11 242 * @version 1.0 243 */ 244 void OH_Drawing_BrushSetShaderEffect(OH_Drawing_Brush* brush, OH_Drawing_ShaderEffect* shaderEffect); 245 246 /** 247 * @brief Sets the shadowLayer for a brush. 248 * 249 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 250 * @param brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 251 * @param shadowLayer Indicates the pointer to an <b>OH_Drawing_ShadowLayer</b> object. 252 * @since 12 253 * @version 1.0 254 */ 255 void OH_Drawing_BrushSetShadowLayer(OH_Drawing_Brush* brush, OH_Drawing_ShadowLayer* shadowLayer); 256 257 /** 258 * @brief Sets the filter for a brush. 259 * 260 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 261 * @param brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 262 * @param filter Indicates the pointer to an <b>OH_Drawing_Filter</b> object. 263 * @since 11 264 * @version 1.0 265 */ 266 void OH_Drawing_BrushSetFilter(OH_Drawing_Brush* brush, OH_Drawing_Filter* filter); 267 268 /** 269 * @brief Gets the filter from a brush. 270 * 271 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 272 * @param brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 273 * @param filter Indicates the pointer to an <b>OH_Drawing_Filter</b> object. 274 * @since 12 275 * @version 1.0 276 */ 277 void OH_Drawing_BrushGetFilter(OH_Drawing_Brush* brush, OH_Drawing_Filter* filter); 278 279 /** 280 * @brief Sets a blender that implements the specified blendmode enum for a brush. 281 * 282 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 283 * @param brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 284 * @param blendMode Indicates the blend mode. 285 * @since 12 286 * @version 1.0 287 */ 288 void OH_Drawing_BrushSetBlendMode(OH_Drawing_Brush* brush, OH_Drawing_BlendMode blendMode); 289 290 /** 291 * @brief Resets all brush contents to their initial values. 292 * 293 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 294 * @param brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 295 * @since 12 296 * @version 1.0 297 */ 298 void OH_Drawing_BrushReset(OH_Drawing_Brush* brush); 299 300 #ifdef __cplusplus 301 } 302 #endif 303 /** @} */ 304 #endif 305