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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
// 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**
///
/// A brush has a style, a color, a gradient and a texture.
///
/// The brush style() defines the fill pattern using the
/// Qt::BrushStyle enum. The default brush style is Qt::NoBrush
/// (depending on how you construct a brush). This style tells the
/// painter to not fill shapes. The standard style for filling is
/// Qt::SolidPattern. The style can be set when the brush is created
/// using the appropriate constructor, and in addition the setStyle()
/// function provides means for altering the style once the brush is
/// constructed.
///
/// ![Brush Styles](brush-styles.png)
///
/// The brush color() defines the color of the fill pattern. The color
/// can either be one of Qt's predefined colors, Qt::GlobalColor, or
/// any other custom QColor. The currently set color can be retrieved
/// and altered using the color() and setColor() functions,
/// respectively.
///
/// The gradient() defines the gradient fill used when the current
/// style is either Qt::LinearGradientPattern,
/// Qt::RadialGradientPattern or Qt::ConicalGradientPattern. Gradient
/// brushes are created by giving a QGradient as a constructor
/// argument when creating the QBrush. Qt provides three different
/// gradients: QLinearGradient, QConicalGradient, and QRadialGradient
/// - all of which inherit QGradient.
///
/// The texture() defines the pixmap used when the current style is
/// Qt::TexturePattern. You can create a brush with a texture by
/// providing the pixmap when the brush is created or by using
/// setTexture().
///
/// Note that applying setTexture() makes style() ==
/// Qt::TexturePattern, regardless of previous style
/// settings. Also, calling setColor() will not make a difference if
/// the style is a gradient. The same is the case if the style is
/// Qt::TexturePattern style unless the current texture is a QBitmap.
///
/// The isOpaque() function returns `true` if the brush is fully opaque
/// otherwise false. A brush is considered opaque if:
///
/// * The alpha component of the color() is 255.
/// * Its texture() does not have an alpha channel and is not a QBitmap.
/// * The colors in the gradient() all have an alpha component that is 255.
///
/// * ![Outlines](brush-outline.png)
///
/// * To specify the style and color of lines and outlines, use the QPainter's [pen](QPen)
/// combined with Qt::PenStyle and Qt::GlobalColor: Note that, by default, QPainter renders the outline (using the currently set pen) when drawing shapes. Use [\c
/// painter.setPen(Qt::NoPen)](Qt::NoPen)
/// to disable this behavior.
///
/// For more information about painting in general, see the [Paint
/// System](Paint%0A%20%20%20%20System)
///
///
/// **See also:** [`t::brush_style()`]
/// [`Painter`]
/// [`Color`]
/// # 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 Brush<'a> {
    #[doc(hidden)]
    pub data: Rc<Cell<Option<*const RUBase>>>,
    #[doc(hidden)]
    pub all_funcs: *const RUBrushAllFuncs,
    #[doc(hidden)]
    pub owned: bool,
    #[doc(hidden)]
    pub _marker: PhantomData<::std::cell::Cell<&'a ()>>,
}

impl<'a> Brush<'a> {
    pub fn new() -> Brush<'a> {
        let data = Rc::new(Cell::new(None));

        let ffi_data = unsafe {
            ((*rute_ffi_get()).create_brush)(
                ::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));

        Brush {
            data,
            all_funcs: ffi_data.all_funcs,
            owned: true,
            _marker: PhantomData,
        }
    }
    #[allow(dead_code)]
    pub(crate) fn new_from_rc(ffi_data: RUBrush) -> Brush<'a> {
        Brush {
            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: RUBrush) -> Brush<'a> {
        Brush {
            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: RUBrush) -> Brush<'a> {
        Brush {
            data: Rc::new(Cell::new(Some(ffi_data.qt_data as *const RUBase))),
            all_funcs: ffi_data.all_funcs,
            owned: false,
            _marker: PhantomData,
        }
    }
    ///
    /// Swaps brush *other* with this brush. This operation is very
    /// fast and never fails.
    pub fn swap<B: BrushTrait<'a>>(&self, other: &B) -> &Self {
        let (obj_other_1, _funcs) = other.get_brush_obj_funcs();

        let (obj_data, funcs) = self.get_brush_obj_funcs();
        unsafe {
            ((*funcs).swap)(obj_data, obj_other_1);
        }
        self
    }
    ///
    /// Returns the brush style.
    ///
    /// **See also:** [`set_style()`]
    pub fn style(&self) -> BrushStyle {
        let (obj_data, funcs) = self.get_brush_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).style)(obj_data);
            let ret_val = { transmute::<u32, BrushStyle>(ret_val) };
            ret_val
        }
    }
    ///
    /// Sets the brush style to *style.*
    ///
    /// **See also:** [`style()`]
    pub fn set_style(&self, arg0: BrushStyle) -> &Self {
        let enum_arg0_1 = arg0 as u32;

        let (obj_data, funcs) = self.get_brush_obj_funcs();
        unsafe {
            ((*funcs).set_style)(obj_data, enum_arg0_1);
        }
        self
    }
    ///
    /// Sets *matrix* as an explicit transformation matrix on the
    /// current brush. The brush transformation matrix is merged with
    /// QPainter transformation matrix to produce the final result.
    ///
    /// **See also:** [`transform()`]
    pub fn set_transform<T: TransformTrait<'a>>(&self, arg0: &T) -> &Self {
        let (obj_arg0_1, _funcs) = arg0.get_transform_obj_funcs();

        let (obj_data, funcs) = self.get_brush_obj_funcs();
        unsafe {
            ((*funcs).set_transform)(obj_data, obj_arg0_1);
        }
        self
    }
    ///
    /// Returns the custom brush pattern, or a null pixmap if no custom brush pattern
    /// has been set.
    ///
    /// **See also:** [`set_texture()`]
    ///
    /// Returns the custom brush pattern, or a null image if no custom
    /// brush pattern has been set.
    ///
    /// If the texture was set as a QPixmap it will be converted to a
    /// QImage.
    ///
    /// **See also:** [`set_texture_image()`]
    pub fn texture(&self) -> Pixmap {
        let (obj_data, funcs) = self.get_brush_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).texture)(obj_data);
            let t = ret_val;
            let ret_val;
            if t.host_data != ::std::ptr::null() {
                ret_val = Pixmap::new_from_rc(t);
            } else {
                ret_val = Pixmap::new_from_owned(t);
            }
            ret_val
        }
    }
    ///
    /// Sets the brush pixmap to *pixmap.* The style is set to
    /// Qt::TexturePattern.
    ///
    /// The current brush color will only have an effect for monochrome
    /// pixmaps, i.e. for QPixmap::depth() == 1 ( [QBitmaps](QBitmap)
    /// ).
    ///
    /// **See also:** [`texture()`]
    ///
    /// Sets the brush image to *image.* The style is set to
    /// Qt::TexturePattern.
    ///
    /// Note the current brush color will *not* have any affect on
    /// monochrome images, as opposed to calling setTexture() with a
    /// QBitmap. If you want to change the color of monochrome image
    /// brushes, either convert the image to QBitmap with `QBitmap::fromImage()` and set the resulting QBitmap as a texture,
    /// or change the entries in the color table for the image.
    ///
    /// **See also:** [`texture_image()`]
    /// [`set_texture()`]
    pub fn set_texture<P: PixmapTrait<'a>>(&self, pixmap: &P) -> &Self {
        let (obj_pixmap_1, _funcs) = pixmap.get_pixmap_obj_funcs();

        let (obj_data, funcs) = self.get_brush_obj_funcs();
        unsafe {
            ((*funcs).set_texture)(obj_data, obj_pixmap_1);
        }
        self
    }
    ///
    /// Returns the custom brush pattern, or a null image if no custom
    /// brush pattern has been set.
    ///
    /// If the texture was set as a QPixmap it will be converted to a
    /// QImage.
    ///
    /// **See also:** [`set_texture_image()`]
    pub fn texture_image(&self) -> Image {
        let (obj_data, funcs) = self.get_brush_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).texture_image)(obj_data);
            let t = ret_val;
            let ret_val;
            if t.host_data != ::std::ptr::null() {
                ret_val = Image::new_from_rc(t);
            } else {
                ret_val = Image::new_from_owned(t);
            }
            ret_val
        }
    }
    ///
    /// Sets the brush image to *image.* The style is set to
    /// Qt::TexturePattern.
    ///
    /// Note the current brush color will *not* have any affect on
    /// monochrome images, as opposed to calling setTexture() with a
    /// QBitmap. If you want to change the color of monochrome image
    /// brushes, either convert the image to QBitmap with `QBitmap::fromImage()` and set the resulting QBitmap as a texture,
    /// or change the entries in the color table for the image.
    ///
    /// **See also:** [`texture_image()`]
    /// [`set_texture()`]
    pub fn set_texture_image<I: ImageTrait<'a>>(&self, image: &I) -> &Self {
        let (obj_image_1, _funcs) = image.get_image_obj_funcs();

        let (obj_data, funcs) = self.get_brush_obj_funcs();
        unsafe {
            ((*funcs).set_texture_image)(obj_data, obj_image_1);
        }
        self
    }
    ///
    /// Returns the brush color.
    ///
    /// **See also:** [`set_color()`]
    pub fn color(&self) -> Option<Color> {
        let (obj_data, funcs) = self.get_brush_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).color)(obj_data);
            if ret_val.qt_data == ::std::ptr::null() {
                return None;
            }
            let t = ret_val;
            let ret_val;
            if t.host_data != ::std::ptr::null() {
                ret_val = Color::new_from_rc(t);
            } else {
                ret_val = Color::new_from_owned(t);
            }
            Some(ret_val)
        }
    }
    ///
    /// Sets the brush color to the given *color.*
    ///
    /// Note that calling setColor() will not make a difference if the
    /// style is a gradient. The same is the case if the style is
    /// Qt::TexturePattern style unless the current texture is a QBitmap.
    ///
    /// **See also:** [`color()`]
    ///
    /// **Overloads**
    /// Sets the brush color to the given *color.*
    pub fn set_color<C: ColorTrait<'a>>(&self, color: &C) -> &Self {
        let (obj_color_1, _funcs) = color.get_color_obj_funcs();

        let (obj_data, funcs) = self.get_brush_obj_funcs();
        unsafe {
            ((*funcs).set_color)(obj_data, obj_color_1);
        }
        self
    }
    ///
    /// Sets the brush color to the given *color.*
    ///
    /// Note that calling setColor() will not make a difference if the
    /// style is a gradient. The same is the case if the style is
    /// Qt::TexturePattern style unless the current texture is a QBitmap.
    ///
    /// **See also:** [`color()`]
    ///
    /// **Overloads**
    /// Sets the brush color to the given *color.*
    pub fn set_color_2(&self, color: GlobalColor) -> &Self {
        let enum_color_1 = color as u32;

        let (obj_data, funcs) = self.get_brush_obj_funcs();
        unsafe {
            ((*funcs).set_color_2)(obj_data, enum_color_1);
        }
        self
    }
    ///
    /// Returns `true` if the brush is fully opaque otherwise false. A brush
    /// is considered opaque if:
    ///
    /// * The alpha component of the color() is 255.
    /// * Its texture() does not have an alpha channel and is not a QBitmap.
    /// * The colors in the gradient() all have an alpha component that is 255.
    /// * It is an extended radial gradient.
    pub fn is_opaque(&self) -> bool {
        let (obj_data, funcs) = self.get_brush_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).is_opaque)(obj_data);
            ret_val
        }
    }
    pub fn is_detached(&self) -> bool {
        let (obj_data, funcs) = self.get_brush_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).is_detached)(obj_data);
            ret_val
        }
    }

    pub fn build(&self) -> Self {
        self.clone()
    }
}
pub trait BrushTrait<'a> {
    #[inline]
    #[doc(hidden)]
    fn get_brush_obj_funcs(&self) -> (*const RUBase, *const RUBrushFuncs);
}

impl<'a> BrushTrait<'a> for Brush<'a> {
    #[doc(hidden)]
    fn get_brush_obj_funcs(&self) -> (*const RUBase, *const RUBrushFuncs) {
        let obj = self.data.get().unwrap();
        unsafe { (obj, (*self.all_funcs).brush_funcs) }
    }
}