gradient.odin (6735B)
1 // This file is part of Blend2D project <https://blend2d.com> 2 // 3 // See blend2d.h or LICENSE.md for license and copyright information 4 // SPDX-License-Identifier: Zlib 5 package blend2d 6 7 import "core:c" 8 9 when ODIN_OS == .Windows { 10 foreign import lib "blend2d.lib" 11 } else when ODIN_OS == .Darwin { 12 foreign import lib "libblend2d.a" 13 } else when ODIN_OS == .Linux { 14 foreign import lib "libblend2d.a" 15 } 16 17 18 //! Gradient type. 19 GradientType :: enum u32 { 20 //! Linear gradient type. 21 LINEAR = 0, 22 23 //! Radial gradient type. 24 RADIAL = 1, 25 26 //! Conic gradient type. 27 CONIC = 2, 28 29 //! Maximum value of `BLGradientType`. 30 MAX_VALUE = 2, 31 FORCE_UINT = 4294967295, 32 } 33 34 //! Gradient data index. 35 GradientValue :: enum u32 { 36 //! x0 - start 'x' for a Linear gradient and `x` center for both Radial and Conic gradients. 37 COMMON_X0 = 0, 38 39 //! y0 - start 'y' for a Linear gradient and `y` center for both Radial and Conic gradients. 40 COMMON_Y0 = 1, 41 42 //! x1 - end 'x' for a Linear gradient and focal point `x` for a Radial gradient. 43 COMMON_X1 = 2, 44 45 //! y1 - end 'y' for a Linear/gradient and focal point `y` for a Radial gradient. 46 COMMON_Y1 = 3, 47 48 //! Radial gradient center radius. 49 RADIAL_R0 = 4, 50 51 //! Radial gradient focal radius. 52 RADIAL_R1 = 5, 53 54 //! Conic gradient angle. 55 CONIC_ANGLE = 2, 56 57 //! Conic gradient angle. 58 CONIC_REPEAT = 3, 59 60 //! Maximum value of `BLGradientValue`. 61 MAX_VALUE = 5, 62 FORCE_UINT = 4294967295, 63 } 64 65 //! Gradient rendering quality. 66 GradientQuality :: enum u32 { 67 //! Nearest neighbor. 68 NEAREST = 0, 69 70 //! Use smoothing, if available (currently never available). 71 SMOOTH = 1, 72 73 //! The renderer will use an implementation-specific dithering algorithm to prevent banding. 74 DITHER = 2, 75 76 //! Maximum value of `BLGradientQuality`. 77 MAX_VALUE = 2, 78 FORCE_UINT = 4294967295, 79 } 80 81 //! Defines an `offset` and `rgba` color that us used by \ref BLGradient to define a linear transition between colors. 82 GradientStop :: struct { 83 offset: f64, 84 rgba: Rgba64, 85 } 86 87 //! Linear gradient values packed into a structure. 88 LinearGradientValues :: struct { 89 x0: f64, 90 y0: f64, 91 x1: f64, 92 y1: f64, 93 } 94 95 //! Radial gradient values packed into a structure. 96 RadialGradientValues :: struct { 97 x0: f64, 98 y0: f64, 99 x1: f64, 100 y1: f64, 101 r0: f64, 102 r1: f64, 103 } 104 105 //! Conic gradient values packed into a structure. 106 ConicGradientValues :: struct { 107 x0: f64, 108 y0: f64, 109 angle: f64, 110 repeat: f64, 111 } 112 113 //! Gradient [C API]. 114 GradientCore :: struct { 115 _d: ObjectDetail, 116 } 117 118 //! \cond INTERNAL 119 //! Gradient [C API Impl]. 120 GradientImpl :: struct { 121 //! Gradient stop data. 122 stops: ^GradientStop, 123 124 //! Gradient stop count. 125 size: c.size_t, 126 127 //! Stop capacity. 128 capacity: c.size_t, 129 130 //! Gradient transformation matrix. 131 transform: Matrix2D, 132 133 using _: struct #raw_union { 134 //! Gradient values (coordinates, radius, angle). 135 values: [6]f64, 136 137 //! Linear parameters. 138 linear: LinearGradientValues, 139 140 //! Radial parameters. 141 radial: RadialGradientValues, 142 143 //! Conic parameters. 144 conic: ConicGradientValues, 145 }, 146 } 147 148 @(default_calling_convention="c", link_prefix="bl_") 149 foreign lib { 150 //! \endcond 151 gradient_init :: proc(self: ^GradientCore) -> Result --- 152 gradient_init_move :: proc(self: ^GradientCore, other: ^GradientCore) -> Result --- 153 gradient_init_weak :: proc(self: ^GradientCore, other: ^GradientCore) -> Result --- 154 gradient_init_as :: proc(self: ^GradientCore, type: GradientType, values: rawptr, extend_mode: ExtendMode, stops: ^GradientStop, n: c.size_t, transform: ^Matrix2D) -> Result --- 155 gradient_destroy :: proc(self: ^GradientCore) -> Result --- 156 gradient_reset :: proc(self: ^GradientCore) -> Result --- 157 gradient_assign_move :: proc(self: ^GradientCore, other: ^GradientCore) -> Result --- 158 gradient_assign_weak :: proc(self: ^GradientCore, other: ^GradientCore) -> Result --- 159 gradient_create :: proc(self: ^GradientCore, type: GradientType, values: rawptr, extend_mode: ExtendMode, stops: ^GradientStop, n: c.size_t, transform: ^Matrix2D) -> Result --- 160 gradient_shrink :: proc(self: ^GradientCore) -> Result --- 161 gradient_reserve :: proc(self: ^GradientCore, n: c.size_t) -> Result --- 162 gradient_get_type :: proc(self: ^GradientCore) -> GradientType --- 163 gradient_set_type :: proc(self: ^GradientCore, type: GradientType) -> Result --- 164 gradient_get_extend_mode :: proc(self: ^GradientCore) -> ExtendMode --- 165 gradient_set_extend_mode :: proc(self: ^GradientCore, extend_mode: ExtendMode) -> Result --- 166 gradient_get_value :: proc(self: ^GradientCore, index: c.size_t) -> f64 --- 167 gradient_set_value :: proc(self: ^GradientCore, index: c.size_t, value: f64) -> Result --- 168 gradient_set_values :: proc(self: ^GradientCore, index: c.size_t, values: ^f64, n: c.size_t) -> Result --- 169 gradient_get_size :: proc(self: ^GradientCore) -> c.size_t --- 170 gradient_get_capacity :: proc(self: ^GradientCore) -> c.size_t --- 171 gradient_get_stops :: proc(self: ^GradientCore) -> ^GradientStop --- 172 gradient_reset_stops :: proc(self: ^GradientCore) -> Result --- 173 gradient_assign_stops :: proc(self: ^GradientCore, stops: ^GradientStop, n: c.size_t) -> Result --- 174 gradient_add_stop_rgba32 :: proc(self: ^GradientCore, offset: f64, argb32: u32) -> Result --- 175 gradient_add_stop_rgba64 :: proc(self: ^GradientCore, offset: f64, argb64: u64) -> Result --- 176 gradient_remove_stop :: proc(self: ^GradientCore, index: c.size_t) -> Result --- 177 gradient_remove_stop_by_offset :: proc(self: ^GradientCore, offset: f64, all: u32) -> Result --- 178 gradient_remove_stops_by_index :: proc(self: ^GradientCore, r_start: c.size_t, r_end: c.size_t) -> Result --- 179 gradient_remove_stops_by_offset :: proc(self: ^GradientCore, offset_min: f64, offset_max: f64) -> Result --- 180 gradient_replace_stop_rgba32 :: proc(self: ^GradientCore, index: c.size_t, offset: f64, rgba32: u32) -> Result --- 181 gradient_replace_stop_rgba64 :: proc(self: ^GradientCore, index: c.size_t, offset: f64, rgba64: u64) -> Result --- 182 gradient_index_of_stop :: proc(self: ^GradientCore, offset: f64) -> c.size_t --- 183 gradient_get_transform :: proc(self: ^GradientCore, transform_out: ^Matrix2D) -> Result --- 184 gradient_get_transform_type :: proc(self: ^GradientCore) -> TransformType --- 185 gradient_apply_transform_op :: proc(self: ^GradientCore, op_type: TransformOp, op_data: rawptr) -> Result --- 186 gradient_equals :: proc(a: ^GradientCore, b: ^GradientCore) -> i32 --- 187 } 188