1 /* 2 * Copyright (c) 2023-2024 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 #ifndef C_INCLUDE_DRAWING_SHADER_EFFECT_H 17 #define C_INCLUDE_DRAWING_SHADER_EFFECT_H 18 19 /** 20 * @addtogroup Drawing 21 * @{ 22 * 23 * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. 24 * 25 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 26 * 27 * @since 11 28 * @version 1.0 29 */ 30 31 /** 32 * @file drawing_shader_effect.h 33 * 34 * @brief Declares functions related to the <b>shaderEffect</b> object in the drawing module. 35 * 36 * @since 11 37 * @version 1.0 38 */ 39 40 #include "drawing_types.h" 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 /** 47 * @brief Enumerates tile mode. 48 * 49 * @since 11 50 * @version 1.0 51 */ 52 typedef enum { 53 /** 54 * Replicate the edge color if the shader effect draws outside of its original bounds. 55 */ 56 CLAMP, 57 /** 58 * Repeat the shader effect image horizontally and vertically. 59 */ 60 REPEAT, 61 /** 62 * Repeat the shader effect image horizontally and vertically, alternating mirror images 63 * so that adjacent images always seam. 64 */ 65 MIRROR, 66 /** 67 * Only draw within the original domain, return transparent-black everywhere else. 68 */ 69 DECAL, 70 } OH_Drawing_TileMode; 71 72 /** 73 * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a shader with single color. 74 * 75 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 76 * @param color Indicates the color used by the shader. 77 * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created. 78 * @since 12 79 * @version 1.0 80 */ 81 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateColorShader(const uint32_t color); 82 83 /** 84 * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a linear gradient between the two specified points. 85 * 86 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 87 * @param startPt Indicates the start point for the gradient. 88 * @param endPt Indicates the end point for the gradient. 89 * @param colors Indicates the colors to be distributed between the two points. 90 * @param pos Indicates the relative position of each corresponding color in the colors array. 91 * If pos is nullptr, the colors are evenly distributed between the start and end point. 92 * @param size Indicates the number of colors and pos(if pos is not nullptr). 93 * @param OH_Drawing_TileMode Indicates the tile mode. 94 * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created. 95 * @since 11 96 * @version 1.0 97 */ 98 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateLinearGradient(const OH_Drawing_Point* startPt, 99 const OH_Drawing_Point* endPt, const uint32_t* colors, const float* pos, uint32_t size, OH_Drawing_TileMode); 100 101 /** 102 * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a linear gradient between the two specified points. 103 * 104 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 105 * @param startPt Indicates the start point for the gradient. 106 * @param endPt Indicates the end point for the gradient. 107 * @param colors Indicates the colors to be distributed between the two points. 108 * @param pos Indicates the relative position of each corresponding color in the colors array. 109 * If pos is nullptr, the colors are evenly distributed between the start and end point. 110 * @param size Indicates the number of colors and pos(if pos is not nullptr). 111 * @param OH_Drawing_TileMode Indicates the tile mode. 112 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object, 113 which represents the local matrix of the created <b>OH_Drawing_ShaderEffect</b> object. 114 If matrix is nullptr, defaults to the identity matrix. 115 * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created. 116 * @since 12 117 * @version 1.0 118 */ 119 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateLinearGradientWithLocalMatrix( 120 const OH_Drawing_Point2D* startPt, const OH_Drawing_Point2D* endPt, const uint32_t* colors, const float* pos, 121 uint32_t size, OH_Drawing_TileMode, const OH_Drawing_Matrix*); 122 123 /** 124 * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a radial gradient given the center and radius. 125 * 126 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 127 * @param centerPt Indicates the center of the circle for the gradient. 128 * @param radius Indicates the radius of the circle for this gradient. 129 * @param colors Indicates the colors to be distributed between the two points. 130 * @param pos Indicates the relative position of each corresponding color in the colors array. 131 * @param size Indicates the number of colors and pos. 132 * @param OH_Drawing_TileMode Indicates the tile mode. 133 * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created. 134 * @since 11 135 * @version 1.0 136 */ 137 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateRadialGradient(const OH_Drawing_Point* centerPt, float radius, 138 const uint32_t* colors, const float* pos, uint32_t size, OH_Drawing_TileMode); 139 140 /** 141 * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a radial gradient given the center and radius. 142 * 143 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 144 * @param centerPt Indicates the center of the circle for the gradient. 145 * @param radius Indicates the radius of the circle for this gradient. 146 * @param colors Indicates the colors to be distributed between the two points. 147 * @param pos Indicates the relative position of each corresponding color in the colors array. 148 * @param size Indicates the number of colors and pos. 149 * @param OH_Drawing_TileMode Indicates the tile mode. 150 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object, 151 which represents the local matrix of the created <b>OH_Drawing_ShaderEffect</b> object. 152 If matrix is nullptr, defaults to the identity matrix. 153 * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created. 154 * @since 12 155 * @version 1.0 156 */ 157 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateRadialGradientWithLocalMatrix( 158 const OH_Drawing_Point2D* centerPt, float radius, const uint32_t* colors, const float* pos, uint32_t size, 159 OH_Drawing_TileMode, const OH_Drawing_Matrix*); 160 161 /** 162 * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a sweep gradient given a center. 163 * 164 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 165 * @param centerPt Indicates the center of the circle for the gradient. 166 * @param colors Indicates the colors to be distributed between the two points. 167 * @param pos Indicates the relative position of each corresponding color in the colors array. 168 * @param size Indicates the number of colors and pos. 169 * @param OH_Drawing_TileMode Indicates the tile mode. 170 * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created. 171 * @since 11 172 * @version 1.0 173 */ 174 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateSweepGradient(const OH_Drawing_Point* centerPt, 175 const uint32_t* colors, const float* pos, uint32_t size, OH_Drawing_TileMode); 176 177 /** 178 * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a image shader. 179 * 180 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 181 * @param OH_Drawing_Image Indicates the pointer to an <b>OH_Drawing_Image</b> object. 182 * @param tileX Indicates the tileX. 183 * @param tileY Indicates the tileY. 184 * @param OH_Drawing_SamplingOptions Indicates the pointer to an <b>OH_Drawing_SamplingOptions</b> object. 185 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object. 186 * If matrix is nullptr, defaults to the identity matrix. 187 * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created. 188 * @since 12 189 * @version 1.0 190 */ 191 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateImageShader(OH_Drawing_Image*, 192 OH_Drawing_TileMode tileX, OH_Drawing_TileMode tileY, const OH_Drawing_SamplingOptions*, const OH_Drawing_Matrix*); 193 194 /** 195 * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a conical gradient given two circles. 196 * 197 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 198 * @param startPt Indicates the center of the start circle for the gradient. 199 * @param startRadius Indicates the radius of the start circle for this gradient. 200 * @param endPt Indicates the center of the start circle for the gradient. 201 * @param endRadius Indicates the radius of the start circle for this gradient. 202 * @param colors Indicates the colors to be distributed between the two points. 203 * @param pos Indicates the relative position of each corresponding color in the colors array. 204 * @param size Indicates the number of colors and pos. 205 * @param OH_Drawing_TileMode Indicates the tile mode. 206 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object, 207 which represents the local matrix of the created <b>OH_Drawing_ShaderEffect</b> object. 208 If matrix is nullptr, defaults to the identity matrix. 209 * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created. 210 * If nullptr is returned, the creation fails. 211 * The possible cause of the failure is any of startPt, endPt, colors and pos is nullptr. 212 * @since 12 213 * @version 1.0 214 */ 215 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateTwoPointConicalGradient(const OH_Drawing_Point2D* startPt, 216 float startRadius, const OH_Drawing_Point2D* endPt, float endRadius, const uint32_t* colors, const float* pos, 217 uint32_t size, OH_Drawing_TileMode, const OH_Drawing_Matrix*); 218 219 /** 220 * @brief Destroys an <b>OH_Drawing_ShaderEffect</b> object and reclaims the memory occupied by the object. 221 * 222 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 223 * @param OH_Drawing_ShaderEffect Indicates the pointer to an <b>OH_Drawing_ShaderEffect</b> object. 224 * @since 11 225 * @version 1.0 226 */ 227 void OH_Drawing_ShaderEffectDestroy(OH_Drawing_ShaderEffect*); 228 229 #ifdef __cplusplus 230 } 231 #endif 232 /** @} */ 233 #endif 234