1 /* 2 * Copyright (c) 2023 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_MATRIX_H 17 #define C_INCLUDE_DRAWING_MATRIX_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_matrix.h 33 * 34 * @brief Declares functions related to the <b>matrix</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 Creates an <b>OH_Drawing_Matrix</b> object. 48 * 49 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 50 * @return Returns the pointer to the <b>OH_Drawing_Matrix</b> object created. 51 * @since 11 52 * @version 1.0 53 */ 54 OH_Drawing_Matrix* OH_Drawing_MatrixCreate(void); 55 56 /** 57 * @brief Creates an <b>OH_Drawing_Matrix</b> object with rotation. Sets matrix to 58 * rotate by degrees about a pivot point at (px, py). 59 * 60 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 61 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object. 62 * @param deg angle of axes relative to upright axes 63 * @param x pivot on x-axis. 64 * @param y pivot on y-axis. 65 * @since 12 66 * @version 1.0 67 */ 68 OH_Drawing_Matrix* OH_Drawing_MatrixCreateRotation(float deg, float x, float y); 69 70 /** 71 * @brief Creates an <b>OH_Drawing_Matrix</b> object with scale. Sets matrix to scale 72 * by sx and sy, about a pivot point at (px, py). 73 * 74 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 75 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object. 76 * @param sx horizontal scale factor. 77 * @param sy vertical scale factor. 78 * @param px pivot on x-axis. 79 * @param py pivot on y-axis. 80 * @return Returns the pointer to the <b>OH_Drawing_Matrix</b> object created. 81 * @since 12 82 * @version 1.0 83 */ 84 OH_Drawing_Matrix* OH_Drawing_MatrixCreateScale(float sx, float sy, float px, float py); 85 86 /** 87 * @brief Creates an <b>OH_Drawing_Matrix</b> object with translation. 88 * 89 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 90 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object. 91 * @param dx horizontal translation. 92 * @param dy vertical translation. 93 * @return Returns the pointer to the <b>OH_Drawing_Matrix</b> object created. 94 * @since 12 95 * @version 1.0 96 */ 97 OH_Drawing_Matrix* OH_Drawing_MatrixCreateTranslation(float dx, float dy); 98 99 /** 100 * @brief Sets the params for a matrix. 101 * 102 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 103 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object. 104 * @param scaleX horizontal scale factor to store 105 * @param skewX horizontal skew factor to store 106 * @param transX horizontal translation to store 107 * @param skewY vertical skew factor to store 108 * @param scaleY vertical scale factor to store 109 * @param transY vertical translation to store 110 * @param persp0 input x-axis values perspective factor to store 111 * @param persp1 input y-axis values perspective factor to store 112 * @param persp2 perspective scale factor to store 113 * @since 11 114 * @version 1.0 115 */ 116 void OH_Drawing_MatrixSetMatrix(OH_Drawing_Matrix*, float scaleX, float skewX, float transX, 117 float skewY, float scaleY, float transY, float persp0, float persp1, float persp2); 118 119 /** 120 * @brief Sets matrix to matrix multiplied by matrix other. 121 * Given: 122 * | A B C | | J K L | 123 * Matrix = | D E F |, other = | M N O | 124 * | G H I | | P Q R | 125 * sets Matrix to: 126 * | A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR | 127 * Matrix * other = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR | 128 * | G H I | | P Q R | | GJ+HM+IP GK+HN+IQ GL+HO+IR | 129 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 130 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object. 131 * @param other Indicates the pointer to an <b>OH_Drawing_Matrix</b> object. 132 * @since 12 133 * @version 1.0 134 */ 135 void OH_Drawing_MatrixPreConcat(OH_Drawing_Matrix*, OH_Drawing_Matrix* other); 136 137 /** 138 * @brief Sets matrix to rotate by degrees about a pivot point at (px, py). The pivot point is unchanged 139 * when mapped with matrix. Positive degrees rotates clockwise. 140 * 141 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 142 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object. 143 * @param degree Indicates the angle of axes relative to upright axes. 144 * @param px Indicates the pivot on x-axis. 145 * @param py Indicates the pivot on y-axis. 146 * @since 12 147 * @version 1.0 148 */ 149 void OH_Drawing_MatrixRotate(OH_Drawing_Matrix*, float degree, float px, float py); 150 151 /** 152 * @brief Sets matrix to translate by (dx, dy) 153 * 154 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 155 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object. 156 * @param dx Indicates the horizontal translation. 157 * @param dy Indicates the vertical translation. 158 * @since 12 159 * @version 1.0 160 */ 161 void OH_Drawing_MatrixTranslate(OH_Drawing_Matrix*, float dx, float dy); 162 163 /** 164 * @brief Sets matrix to scale by sx and sy, about a pivot point at (px, py). 165 * 166 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 167 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object. 168 * @param sx Indicates the horizontal scale factor. 169 * @param sy Indicates the vertical scale factor. 170 * @param px Indicates the pivot on x-axis. 171 * @param py Indicates the pivot on y-axis. 172 * @since 12 173 * @version 1.0 174 */ 175 void OH_Drawing_MatrixScale(OH_Drawing_Matrix*, float sx, float sy, float px, float py); 176 177 /** 178 * @brief Sets inverse to reciprocal matrix, returning true if matrix can be inverted. 179 * 180 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 181 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object. 182 * @param inverse Indicates the pointer to an <b>OH_Drawing_Matrix</b> object. 183 * @return Returns true if matrix can be inverted, or flase. 184 * @since 12 185 * @version 1.0 186 */ 187 bool OH_Drawing_MatrixInvert(OH_Drawing_Matrix*, OH_Drawing_Matrix* inverse); 188 189 /** 190 * @brief Returns true if the first matrix equals the second matrix. 191 * 192 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 193 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object. 194 * @param other Indicates the pointer to an <b>OH_Drawing_Matrix</b> object. 195 * @return Returns true if the two matrices are equal, or flase. 196 * @since 12 197 * @version 1.0 198 */ 199 bool OH_Drawing_MatrixIsEqual(OH_Drawing_Matrix*, OH_Drawing_Matrix* other); 200 201 /** 202 * @brief Returns true if matrix is identity. 203 * Identity matrix is : | 1 0 0 | 204 * | 0 1 0 | 205 * | 0 0 1 | 206 * 207 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 208 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object. 209 * @return Returns true if matrix is identity, or flase. 210 * @since 12 211 * @version 1.0 212 */ 213 bool OH_Drawing_MatrixIsIdentity(OH_Drawing_Matrix*); 214 215 /** 216 * @brief Destroys an <b>OH_Drawing_Matrix</b> object and reclaims the memory occupied by the object. 217 * 218 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 219 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object. 220 * @since 11 221 * @version 1.0 222 */ 223 void OH_Drawing_MatrixDestroy(OH_Drawing_Matrix*); 224 225 #ifdef __cplusplus 226 } 227 #endif 228 /** @} */ 229 #endif 230