1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
// This file is auto-generated by rute_gen. DO NOT EDIT.
use std::cell::Cell;
use std::rc::Rc;
#[allow(unused_imports)]
use std::marker::PhantomData;
#[allow(unused_imports)]
use std::os::raw::c_void;
#[allow(unused_imports)]
use std::mem::transmute;
#[allow(unused_imports)]
use std::ffi::{CStr, CString};
use rute_ffi_base::*;
#[allow(unused_imports)]
use auto::*;
/// **Notice these docs are heavy WIP and not very relevent yet**
///
/// Qt currently supports three types of gradient fills:
///
/// * *Linear* gradients interpolate colors between start and end points.
/// * *Simple* radial gradients interpolate colors between a focal point and end points on a circle surrounding it.
/// * *Extended* radial gradients interpolate colors between a center and a focal circle.
/// * *Conical* gradients interpolate colors around a center point.
///
/// A gradient's type can be retrieved using the type() function.
/// Each of the types is represented by a subclass of QGradient:
///
/// * QLinearGradient
/// * QRadialGradient
/// * QConicalGradient
///
/// * ![qgradient-linear.png](qgradient-linear.png)
///
/// * ![qgradient-radial.png](qgradient-radial.png)
///
/// * ![qgradient-conical.png](qgradient-conical.png)
///
/// The colors in a gradient are defined using stop points of the
/// QGradientStop type; i.e., a position and a color. Use the setColorAt()
/// function to define a single stop point. Alternatively, use the
/// setStops() function to define several stop points in one go. Note that
/// the latter function *replaces* the current set of stop points.
///
/// It is the gradient's complete set of stop points (accessible
/// through the stops() function) that describes how the gradient area
/// should be filled. If no stop points have been specified, a gradient
/// of black at 0 to white at 1 is used.
///
/// A diagonal linear gradient from black at (100, 100) to white at
/// (200, 200) could be specified like this:
///
/// A gradient can have an arbitrary number of stop points. The
/// following would create a radial gradient starting with
/// red in the center, blue and then green on the edges:
///
/// It is possible to repeat or reflect the gradient outside its area
/// by specifiying the [spread method](QGradient::Spread)
/// using the
/// setSpread() function. The default is to pad the outside area with
/// the color at the closest stop point. The currently set [spread method](QGradient::Spread)
/// can be retrieved using the
/// spread() function. The QGradient::Spread enum defines three
/// different methods:
///
/// * ![qradialgradient-pad.png](qradialgradient-pad.png)
///
/// * ![qradialgradient-repeat.png](qradialgradient-repeat.png)
///
/// * ![qradialgradient-reflect.png](qradialgradient-reflect.png)
///
/// * [PadSpread](QGradient::PadSpread)
///
/// * [RepeatSpread](QGradient::RepeatSpread)
///
/// * [ReflectSpread](QGradient::ReflectSpread)
///
/// Note that the setSpread() function only has effect for linear and
/// radial gradients. The reason is that the conical gradient is
/// closed by definition, i.e. the *conical* gradient fills the
/// entire circle from 0 - 360 degrees, while the boundary of a radial
/// or a linear gradient can be specified through its radius or final
/// stop points, respectively.
///
/// The gradient coordinates can be specified in logical coordinates,
/// relative to device coordinates, or relative to object bounding box coordinates.
/// The [coordinate mode](QGradient::CoordinateMode)
/// can be set using the
/// setCoordinateMode() function. The default is LogicalMode, where the
/// gradient coordinates are specified in the same way as the object
/// coordinates. To retrieve the currently set [coordinate mode](QGradient::CoordinateMode)
/// use coordinateMode().
///
/// **See also:** {painting/gradients}{The Gradients Example}
/// QBrush
/// # Licence
///
/// The documentation is an adoption of the original [Qt Documentation](http://doc.qt.io/) and provided herein is licensed under the terms of the [GNU Free Documentation License version 1.3](http://www.gnu.org/licenses/fdl.html) as published by the Free Software Foundation.
#[derive(Clone)]
pub struct Gradient<'a> {
#[doc(hidden)]
pub data: Rc<Cell<Option<*const RUBase>>>,
#[doc(hidden)]
pub all_funcs: *const RUGradientAllFuncs,
#[doc(hidden)]
pub owned: bool,
#[doc(hidden)]
pub _marker: PhantomData<::std::cell::Cell<&'a ()>>,
}
impl<'a> Gradient<'a> {
pub fn new() -> Gradient<'a> {
let data = Rc::new(Cell::new(None));
let ffi_data = unsafe {
((*rute_ffi_get()).create_gradient)(
::std::ptr::null(),
transmute(rute_object_delete_callback as usize),
Rc::into_raw(data.clone()) as *const c_void,
)
};
data.set(Some(ffi_data.qt_data));
Gradient {
data,
all_funcs: ffi_data.all_funcs,
owned: true,
_marker: PhantomData,
}
}
#[allow(dead_code)]
pub(crate) fn new_from_rc(ffi_data: RUGradient) -> Gradient<'a> {
Gradient {
data: unsafe { Rc::from_raw(ffi_data.host_data as *const Cell<Option<*const RUBase>>) },
all_funcs: ffi_data.all_funcs,
owned: false,
_marker: PhantomData,
}
}
#[allow(dead_code)]
pub(crate) fn new_from_owned(ffi_data: RUGradient) -> Gradient<'a> {
Gradient {
data: Rc::new(Cell::new(Some(ffi_data.qt_data as *const RUBase))),
all_funcs: ffi_data.all_funcs,
owned: true,
_marker: PhantomData,
}
}
#[allow(dead_code)]
pub(crate) fn new_from_temporary(ffi_data: RUGradient) -> Gradient<'a> {
Gradient {
data: Rc::new(Cell::new(Some(ffi_data.qt_data as *const RUBase))),
all_funcs: ffi_data.all_funcs,
owned: false,
_marker: PhantomData,
}
}
/// Returns the type of gradient.
pub fn get_type(&self) -> Type {
let (obj_data, funcs) = self.get_gradient_obj_funcs();
unsafe {
let ret_val = ((*funcs).get_type)(obj_data);
let ret_val = { transmute::<i32, Type>(ret_val) };
ret_val
}
}
///
/// Specifies the spread *method* that should be used for this
/// gradient.
///
/// Note that this function only has effect for linear and radial
/// gradients.
///
/// **See also:** spread()
pub fn set_spread(&self, spread: Spread) -> &Self {
let enum_spread_1 = spread as i32;
let (obj_data, funcs) = self.get_gradient_obj_funcs();
unsafe {
((*funcs).set_spread)(obj_data, enum_spread_1);
}
self
}
///
/// Returns the spread method use by this gradient. The default is
/// PadSpread.
///
/// **See also:** setSpread()
pub fn spread(&self) -> Spread {
let (obj_data, funcs) = self.get_gradient_obj_funcs();
unsafe {
let ret_val = ((*funcs).spread)(obj_data);
let ret_val = { transmute::<i32, Spread>(ret_val) };
ret_val
}
}
///
/// Creates a stop point at the given *position* with the given *color.* The given *position* must be in the range 0 to 1.
///
/// **See also:** setStops()
/// stops()
pub fn set_color_at<C: ColorTrait<'a>>(&self, pos: f32, color: &C) -> &Self {
let (obj_color_2, _funcs) = color.get_color_obj_funcs();
let (obj_data, funcs) = self.get_gradient_obj_funcs();
unsafe {
((*funcs).set_color_at)(obj_data, pos, obj_color_2);
}
self
}
///
/// Returns the coordinate mode of this gradient. The default mode is
/// LogicalMode.
pub fn coordinate_mode(&self) -> CoordinateMode {
let (obj_data, funcs) = self.get_gradient_obj_funcs();
unsafe {
let ret_val = ((*funcs).coordinate_mode)(obj_data);
let ret_val = { transmute::<i32, CoordinateMode>(ret_val) };
ret_val
}
}
///
/// Sets the coordinate mode of this gradient to *mode.* The default
/// mode is LogicalMode.
pub fn set_coordinate_mode(&self, mode: CoordinateMode) -> &Self {
let enum_mode_1 = mode as i32;
let (obj_data, funcs) = self.get_gradient_obj_funcs();
unsafe {
((*funcs).set_coordinate_mode)(obj_data, enum_mode_1);
}
self
}
pub fn interpolation_mode(&self) -> InterpolationMode {
let (obj_data, funcs) = self.get_gradient_obj_funcs();
unsafe {
let ret_val = ((*funcs).interpolation_mode)(obj_data);
let ret_val = { transmute::<i32, InterpolationMode>(ret_val) };
ret_val
}
}
pub fn set_interpolation_mode(&self, mode: InterpolationMode) -> &Self {
let enum_mode_1 = mode as i32;
let (obj_data, funcs) = self.get_gradient_obj_funcs();
unsafe {
((*funcs).set_interpolation_mode)(obj_data, enum_mode_1);
}
self
}
}
pub trait GradientTrait<'a> {
#[inline]
#[doc(hidden)]
fn get_gradient_obj_funcs(&self) -> (*const RUBase, *const RUGradientFuncs);
}
impl<'a> GradientTrait<'a> for Gradient<'a> {
#[doc(hidden)]
fn get_gradient_obj_funcs(&self) -> (*const RUBase, *const RUGradientFuncs) {
let obj = self.data.get().unwrap();
unsafe { (obj, (*self.all_funcs).gradient_funcs) }
}
}
#[repr(u32)]
pub enum Type {
LinearGradient,
RadialGradient,
ConicalGradient,
NoGradient,
}
#[repr(u32)]
pub enum Spread {
PadSpread,
ReflectSpread,
RepeatSpread,
}
#[repr(u32)]
pub enum CoordinateMode {
LogicalMode,
StretchToDeviceMode,
ObjectBoundingMode,
}
#[repr(u32)]
pub enum InterpolationMode {
ColorInterpolation,
ComponentInterpolation,
}