wxdragon 0.9.15

Safe Rust bindings for wxWidgets via the wxDragon C wrapper
Documentation
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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
/// Background mode constants for device contexts
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BackgroundMode {
    /// Transparent background mode
    Transparent,
    /// Solid background mode
    Solid,
}

impl BackgroundMode {
    /// Convert to the raw FFI value
    pub fn to_raw(&self) -> i32 {
        match self {
            BackgroundMode::Transparent => wxdragon_sys::WXD_TRANSPARENT as i32,
            BackgroundMode::Solid => wxdragon_sys::WXD_SOLID as i32,
        }
    }
}

widget_style_enum!(
    name: PenStyle,
    doc: "Style flags for DC pen.",
    variants: {
        Solid: wxdragon_sys::WXD_PENSTYLE_SOLID, "Solid line style.",
        Dot: wxdragon_sys::WXD_PENSTYLE_DOT, "Dotted line style.",
        LongDash: wxdragon_sys::WXD_PENSTYLE_LONG_DASH, "Long dashed line style.",
        ShortDash: wxdragon_sys::WXD_PENSTYLE_SHORT_DASH, "Short dashed line style.",
        DotDash: wxdragon_sys::WXD_PENSTYLE_DOT_DASH, "Dot and dash line style.",
        Transparent: wxdragon_sys::WXD_PENSTYLE_TRANSPARENT, "Transparent pen.",
        Stipple: wxdragon_sys::WXD_PENSTYLE_STIPPLE, "Stippled pen.",
        UserDash: wxdragon_sys::WXD_PENSTYLE_USER_DASH, "User-defined dash pattern.",
        BDiagonalHatch: wxdragon_sys::WXD_PENSTYLE_BDIAGONAL_HATCH, "Backward diagonal hatch pattern.",
        CrossDiagHatch: wxdragon_sys::WXD_PENSTYLE_CROSSDIAG_HATCH, "Cross-diagonal hatch pattern.",
        FDiagonalHatch: wxdragon_sys::WXD_PENSTYLE_FDIAGONAL_HATCH, "Forward diagonal hatch pattern.",
        CrossHatch: wxdragon_sys::WXD_PENSTYLE_CROSS_HATCH, "Cross hatch pattern.",
        HorizontalHatch: wxdragon_sys::WXD_PENSTYLE_HORIZONTAL_HATCH, "Horizontal hatch pattern.",
        VerticalHatch: wxdragon_sys::WXD_PENSTYLE_VERTICAL_HATCH, "Vertical hatch pattern."
    },
    default_variant: Solid
);

widget_style_enum!(
    name: BrushStyle,
    doc: "Style flags for DC brush.",
    variants: {
        Solid: wxdragon_sys::WXD_BRUSHSTYLE_SOLID, "Solid brush.",
        Transparent: wxdragon_sys::WXD_BRUSHSTYLE_TRANSPARENT, "Transparent brush.",
        BDiagonalHatch: wxdragon_sys::WXD_BRUSHSTYLE_BDIAGONAL_HATCH, "Backward diagonal hatch pattern.",
        CrossDiagHatch: wxdragon_sys::WXD_BRUSHSTYLE_CROSSDIAG_HATCH, "Cross-diagonal hatch pattern.",
        FDiagonalHatch: wxdragon_sys::WXD_BRUSHSTYLE_FDIAGONAL_HATCH, "Forward diagonal hatch pattern.",
        CrossHatch: wxdragon_sys::WXD_BRUSHSTYLE_CROSS_HATCH, "Cross hatch pattern.",
        HorizontalHatch: wxdragon_sys::WXD_BRUSHSTYLE_HORIZONTAL_HATCH, "Horizontal hatch pattern.",
        VerticalHatch: wxdragon_sys::WXD_BRUSHSTYLE_VERTICAL_HATCH, "Vertical hatch pattern.",
        Stipple: wxdragon_sys::WXD_BRUSHSTYLE_STIPPLE, "Stippled brush.",
        StippleMaskOpaque: wxdragon_sys::WXD_BRUSHSTYLE_STIPPLE_MASK_OPAQUE, "Stippled brush with opaque mask.",
        StippleMask: wxdragon_sys::WXD_BRUSHSTYLE_STIPPLE_MASK, "Stippled brush with mask."
    },
    default_variant: Solid
);

/// Polygon fill modes
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PolygonFillMode {
    /// Odd-even fill rule
    OddEven,
    /// Winding fill rule
    Winding,
}

impl PolygonFillMode {
    /// Convert to the raw FFI value
    pub fn to_raw(&self) -> i32 {
        match self {
            PolygonFillMode::OddEven => wxdragon_sys::WXD_ODDEVEN_RULE as i32,
            PolygonFillMode::Winding => wxdragon_sys::WXD_WINDING_RULE as i32,
        }
    }
}

/// Flood fill modes
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FloodFillMode {
    /// Fill surface with same color
    Surface,
    /// Fill until border color
    Border,
}

impl FloodFillMode {
    /// Convert to the raw FFI value
    pub fn to_raw(&self) -> i32 {
        match self {
            FloodFillMode::Surface => wxdragon_sys::WXD_FLOOD_SURFACE as i32,
            FloodFillMode::Border => wxdragon_sys::WXD_FLOOD_BORDER as i32,
        }
    }
}

/// Logical drawing functions
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LogicalFunction {
    Clear,
    Xor,
    Invert,
    OrReverse,
    AndReverse,
    Copy,
    And,
    AndInvert,
    NoOp,
    Nor,
    Equiv,
    SrcInvert,
    OrInvert,
    Nand,
    Or,
    Set,
}

impl LogicalFunction {
    /// Convert to the raw FFI value
    pub fn to_raw(&self) -> i32 {
        match self {
            LogicalFunction::Clear => wxdragon_sys::WXD_CLEAR as i32,
            LogicalFunction::Xor => wxdragon_sys::WXD_XOR as i32,
            LogicalFunction::Invert => wxdragon_sys::WXD_INVERT as i32,
            LogicalFunction::OrReverse => wxdragon_sys::WXD_OR_REVERSE as i32,
            LogicalFunction::AndReverse => wxdragon_sys::WXD_AND_REVERSE as i32,
            LogicalFunction::Copy => wxdragon_sys::WXD_COPY as i32,
            LogicalFunction::And => wxdragon_sys::WXD_AND as i32,
            LogicalFunction::AndInvert => wxdragon_sys::WXD_AND_INVERT as i32,
            LogicalFunction::NoOp => wxdragon_sys::WXD_NO_OP as i32,
            LogicalFunction::Nor => wxdragon_sys::WXD_NOR as i32,
            LogicalFunction::Equiv => wxdragon_sys::WXD_EQUIV as i32,
            LogicalFunction::SrcInvert => wxdragon_sys::WXD_SRC_INVERT as i32,
            LogicalFunction::OrInvert => wxdragon_sys::WXD_OR_INVERT as i32,
            LogicalFunction::Nand => wxdragon_sys::WXD_NAND as i32,
            LogicalFunction::Or => wxdragon_sys::WXD_OR as i32,
            LogicalFunction::Set => wxdragon_sys::WXD_SET as i32,
        }
    }

    /// Convert from raw FFI value
    pub fn from_raw(value: i32) -> Self {
        match value {
            _ if value == wxdragon_sys::WXD_CLEAR as i32 => LogicalFunction::Clear,
            _ if value == wxdragon_sys::WXD_XOR as i32 => LogicalFunction::Xor,
            _ if value == wxdragon_sys::WXD_INVERT as i32 => LogicalFunction::Invert,
            _ if value == wxdragon_sys::WXD_OR_REVERSE as i32 => LogicalFunction::OrReverse,
            _ if value == wxdragon_sys::WXD_AND_REVERSE as i32 => LogicalFunction::AndReverse,
            _ if value == wxdragon_sys::WXD_COPY as i32 => LogicalFunction::Copy,
            _ if value == wxdragon_sys::WXD_AND as i32 => LogicalFunction::And,
            _ if value == wxdragon_sys::WXD_AND_INVERT as i32 => LogicalFunction::AndInvert,
            _ if value == wxdragon_sys::WXD_NO_OP as i32 => LogicalFunction::NoOp,
            _ if value == wxdragon_sys::WXD_NOR as i32 => LogicalFunction::Nor,
            _ if value == wxdragon_sys::WXD_EQUIV as i32 => LogicalFunction::Equiv,
            _ if value == wxdragon_sys::WXD_SRC_INVERT as i32 => LogicalFunction::SrcInvert,
            _ if value == wxdragon_sys::WXD_OR_INVERT as i32 => LogicalFunction::OrInvert,
            _ if value == wxdragon_sys::WXD_NAND as i32 => LogicalFunction::Nand,
            _ if value == wxdragon_sys::WXD_OR as i32 => LogicalFunction::Or,
            _ if value == wxdragon_sys::WXD_SET as i32 => LogicalFunction::Set,
            _ => LogicalFunction::Copy,
        }
    }
}

/// Mapping modes for coordinate systems
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MapMode {
    Text,
    Lometric,
    Twips,
    Metric,
}

impl MapMode {
    /// Convert to the raw FFI value
    pub fn to_raw(&self) -> i32 {
        match self {
            MapMode::Text => wxdragon_sys::WXD_MM_TEXT as i32,
            MapMode::Lometric => wxdragon_sys::WXD_MM_LOMETRIC as i32,
            MapMode::Twips => wxdragon_sys::WXD_MM_TWIPS as i32,
            MapMode::Metric => wxdragon_sys::WXD_MM_METRIC as i32,
        }
    }

    /// Convert from raw FFI value
    pub fn from_raw(value: i32) -> Self {
        match value {
            _ if value == wxdragon_sys::WXD_MM_TEXT as i32 => MapMode::Text,
            _ if value == wxdragon_sys::WXD_MM_LOMETRIC as i32 => MapMode::Lometric,
            _ if value == wxdragon_sys::WXD_MM_TWIPS as i32 => MapMode::Twips,
            _ if value == wxdragon_sys::WXD_MM_METRIC as i32 => MapMode::Metric,
            _ => MapMode::Text,
        }
    }
}

/// Text alignment constants
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TextAlignment {
    bits: i32,
}

impl TextAlignment {
    pub const INVALID: Self = Self {
        bits: wxdragon_sys::WXD_ALIGN_INVALID as i32,
    };
    pub const LEFT: Self = Self {
        bits: wxdragon_sys::WXD_ALIGN_LEFT as i32,
    };
    pub const TOP: Self = Self {
        bits: wxdragon_sys::WXD_ALIGN_TOP as i32,
    };
    pub const RIGHT: Self = Self {
        bits: wxdragon_sys::WXD_ALIGN_RIGHT as i32,
    };
    pub const BOTTOM: Self = Self {
        bits: wxdragon_sys::WXD_ALIGN_BOTTOM as i32,
    };
    pub const CENTER_HORIZONTAL: Self = Self {
        bits: wxdragon_sys::WXD_ALIGN_CENTRE_HORIZONTAL as i32,
    };
    pub const CENTER_VERTICAL: Self = Self {
        bits: wxdragon_sys::WXD_ALIGN_CENTRE_VERTICAL as i32,
    };
    pub const CENTER: Self = Self {
        bits: wxdragon_sys::WXD_ALIGN_CENTRE as i32,
    };

    pub const fn bits(&self) -> i32 {
        self.bits
    }

    pub const fn from_bits(bits: i32) -> Self {
        Self { bits }
    }
}

impl std::ops::BitOr for TextAlignment {
    type Output = Self;
    fn bitor(self, rhs: Self) -> Self::Output {
        Self {
            bits: self.bits | rhs.bits,
        }
    }
}

impl std::ops::BitOrAssign for TextAlignment {
    fn bitor_assign(&mut self, rhs: Self) {
        self.bits |= rhs.bits;
    }
}

/// Gradient direction constants
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GradientDirection {
    North,
    South,
    East,
    West,
}

impl GradientDirection {
    /// Convert to the raw FFI value
    pub fn to_raw(&self) -> i32 {
        match self {
            GradientDirection::North => wxdragon_sys::WXD_NORTH as i32,
            GradientDirection::South => wxdragon_sys::WXD_SOUTH as i32,
            GradientDirection::East => wxdragon_sys::WXD_EAST as i32,
            GradientDirection::West => wxdragon_sys::WXD_WEST as i32,
        }
    }
}

/// Point structure for drawing operations
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Point {
    pub x: i32,
    pub y: i32,
}

impl Point {
    pub fn new(x: i32, y: i32) -> Self {
        Self { x, y }
    }
}

impl From<Point> for wxdragon_sys::wxd_Point {
    fn from(point: Point) -> Self {
        wxdragon_sys::wxd_Point { x: point.x, y: point.y }
    }
}

impl From<wxdragon_sys::wxd_Point> for Point {
    fn from(point: wxdragon_sys::wxd_Point) -> Self {
        Point { x: point.x, y: point.y }
    }
}

/// Rectangle structure for drawing operations
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Rect {
    pub x: i32,
    pub y: i32,
    pub width: i32,
    pub height: i32,
}

impl Rect {
    pub fn new(x: i32, y: i32, width: i32, height: i32) -> Self {
        Self { x, y, width, height }
    }
}

impl From<Rect> for wxdragon_sys::wxd_Rect {
    fn from(rect: Rect) -> Self {
        wxdragon_sys::wxd_Rect {
            x: rect.x,
            y: rect.y,
            width: rect.width,
            height: rect.height,
        }
    }
}

impl From<wxdragon_sys::wxd_Rect> for Rect {
    fn from(rect: wxdragon_sys::wxd_Rect) -> Self {
        Rect {
            x: rect.x,
            y: rect.y,
            width: rect.width,
            height: rect.height,
        }
    }
}

pub mod auto_buffered_paint_dc;
pub mod client_dc;
pub mod memory_dc;
pub mod paint_dc;
pub mod screen_dc;
pub mod window_dc;

pub use auto_buffered_paint_dc::AutoBufferedPaintDC;
pub use client_dc::ClientDC;
pub use memory_dc::MemoryDC;
pub use paint_dc::PaintDC;
pub use screen_dc::ScreenDC;
pub use window_dc::WindowDC;

/// A generic device context that can wrap any raw DC pointer.
pub struct GenericDC {
    dc_ptr: *mut wxdragon_sys::wxd_DC_t,
    owned: bool,
}

impl GenericDC {
    /// Create a GenericDC from a raw FFI pointer, taking ownership.
    /// # Safety
    /// The pointer must be valid and should be destroyed by calling wxd_DC_Destroy.
    pub unsafe fn from_ffi_ptr(ptr: *mut wxdragon_sys::wxd_DC_t) -> Self {
        Self {
            dc_ptr: ptr,
            owned: true,
        }
    }

    /// Create a GenericDC from a raw FFI pointer without taking ownership.
    /// # Safety
    /// The pointer must be valid for the duration of the GenericDC's lifetime.
    pub unsafe fn from_ffi_ptr_unowned(ptr: *mut wxdragon_sys::wxd_DC_t) -> Self {
        Self {
            dc_ptr: ptr,
            owned: false,
        }
    }
}

impl DeviceContext for GenericDC {
    fn dc_ptr(&self) -> *mut wxdragon_sys::wxd_DC_t {
        self.dc_ptr
    }
}

impl Drop for GenericDC {
    fn drop(&mut self) {
        if self.owned && !self.dc_ptr.is_null() {
            unsafe { wxdragon_sys::wxd_DC_Destroy(self.dc_ptr) };
        }
    }
}

// Re-export for convenience
pub use crate::bitmap::Bitmap;
pub use crate::color::Colour;
pub use crate::font::Font;

/// Configuration for a blit operation
#[derive(Debug, Clone, Copy)]
pub struct BlitConfig {
    pub dest_x: i32,
    pub dest_y: i32,
    pub width: i32,
    pub height: i32,
    pub src_x: i32,
    pub src_y: i32,
    pub logical_func: LogicalFunction,
    pub use_mask: bool,
    pub src_mask_x: i32,
    pub src_mask_y: i32,
}

impl BlitConfig {
    pub fn new(dest_x: i32, dest_y: i32, width: i32, height: i32, src_x: i32, src_y: i32) -> Self {
        Self {
            dest_x,
            dest_y,
            width,
            height,
            src_x,
            src_y,
            logical_func: LogicalFunction::Copy,
            use_mask: false,
            src_mask_x: -1,
            src_mask_y: -1,
        }
    }

    pub fn with_logical_func(mut self, logical_func: LogicalFunction) -> Self {
        self.logical_func = logical_func;
        self
    }

    pub fn with_mask(mut self, src_mask_x: i32, src_mask_y: i32) -> Self {
        self.use_mask = true;
        self.src_mask_x = src_mask_x;
        self.src_mask_y = src_mask_y;
        self
    }
}

/// Configuration for a stretch blit operation
#[derive(Debug, Clone, Copy)]
pub struct StretchBlitConfig {
    pub dest_x: i32,
    pub dest_y: i32,
    pub dest_width: i32,
    pub dest_height: i32,
    pub src_x: i32,
    pub src_y: i32,
    pub src_width: i32,
    pub src_height: i32,
    pub logical_func: LogicalFunction,
    pub use_mask: bool,
    pub src_mask_x: i32,
    pub src_mask_y: i32,
}

impl StretchBlitConfig {
    pub fn with_logical_func(mut self, logical_func: LogicalFunction) -> Self {
        self.logical_func = logical_func;
        self
    }

    pub fn with_mask(mut self, src_mask_x: i32, src_mask_y: i32) -> Self {
        self.use_mask = true;
        self.src_mask_x = src_mask_x;
        self.src_mask_y = src_mask_y;
        self
    }
}

/// Common trait implemented by all device context types
pub trait DeviceContext {
    /// Get a pointer to the underlying DC
    fn dc_ptr(&self) -> *mut wxdragon_sys::wxd_DC_t;

    /// Clear the device context
    fn clear(&self) {
        unsafe {
            wxdragon_sys::wxd_DC_Clear(self.dc_ptr());
        }
    }

    /// Set the background color of the device context
    fn set_background(&self, colour: Colour) {
        unsafe {
            wxdragon_sys::wxd_DC_SetBackground(self.dc_ptr(), colour.into());
        }
    }

    /// Set the background mode of the device context
    fn set_background_mode(&self, mode: BackgroundMode) {
        unsafe {
            wxdragon_sys::wxd_DC_SetBackgroundMode(self.dc_ptr(), mode.to_raw());
        }
    }

    /// Set the text background color
    fn set_text_background(&self, colour: Colour) {
        unsafe {
            wxdragon_sys::wxd_DC_SetTextBackground(self.dc_ptr(), colour.into());
        }
    }

    /// Set the text foreground color
    fn set_text_foreground(&self, colour: Colour) {
        unsafe {
            wxdragon_sys::wxd_DC_SetTextForeground(self.dc_ptr(), colour.into());
        }
    }

    /// Set the font for text drawing
    fn set_font(&self, font: &Font) {
        unsafe {
            wxdragon_sys::wxd_DC_SetFont(self.dc_ptr(), font.as_ptr());
        }
    }

    /// Set the pen for drawing outlines
    fn set_pen(&self, colour: Colour, width: i32, style: PenStyle) {
        unsafe {
            wxdragon_sys::wxd_DC_SetPen(self.dc_ptr(), colour.into(), width, style.bits() as i32);
        }
    }

    /// Set the brush for filling shapes
    fn set_brush(&self, colour: Colour, style: BrushStyle) {
        unsafe {
            wxdragon_sys::wxd_DC_SetBrush(self.dc_ptr(), colour.into(), style.bits() as i32);
        }
    }

    /// Draw a point at the specified coordinates
    fn draw_point(&self, x: i32, y: i32) {
        unsafe {
            wxdragon_sys::wxd_DC_DrawPoint(self.dc_ptr(), x, y);
        }
    }

    /// Draw a line from (x1, y1) to (x2, y2)
    fn draw_line(&self, x1: i32, y1: i32, x2: i32, y2: i32) {
        unsafe {
            wxdragon_sys::wxd_DC_DrawLine(self.dc_ptr(), x1, y1, x2, y2);
        }
    }

    /// Draw a rectangle with the specified dimensions
    fn draw_rectangle(&self, x: i32, y: i32, width: i32, height: i32) {
        unsafe {
            wxdragon_sys::wxd_DC_DrawRectangle(self.dc_ptr(), x, y, width, height);
        }
    }

    /// Draw a circle with the specified center and radius
    fn draw_circle(&self, x: i32, y: i32, radius: i32) {
        unsafe {
            wxdragon_sys::wxd_DC_DrawCircle(self.dc_ptr(), x, y, radius);
        }
    }

    /// Draw an ellipse inside the specified rectangle
    fn draw_ellipse(&self, x: i32, y: i32, width: i32, height: i32) {
        unsafe {
            wxdragon_sys::wxd_DC_DrawEllipse(self.dc_ptr(), x, y, width, height);
        }
    }

    /// Draw a rounded rectangle with the specified dimensions and corner radius
    fn draw_rounded_rectangle(&self, x: i32, y: i32, width: i32, height: i32, radius: f64) {
        unsafe {
            wxdragon_sys::wxd_DC_DrawRoundedRectangle(self.dc_ptr(), x, y, width, height, radius);
        }
    }

    /// Draw text at the specified position
    fn draw_text(&self, text: &str, x: i32, y: i32) {
        use std::ffi::CString;
        if let Ok(c_text) = CString::new(text) {
            unsafe {
                wxdragon_sys::wxd_DC_DrawText(self.dc_ptr(), c_text.as_ptr(), x, y);
            }
        }
    }

    /// Draw a bitmap at the specified position
    fn draw_bitmap(&self, bitmap: &Bitmap, x: i32, y: i32, transparent: bool) {
        unsafe { wxdragon_sys::wxd_DC_DrawBitmap(self.dc_ptr(), bitmap.as_const_ptr(), x, y, transparent) };
    }

    /// Get the size of the device context
    fn get_size(&self) -> (i32, i32) {
        unsafe {
            let size = wxdragon_sys::wxd_DC_GetSize(self.dc_ptr());
            (size.width, size.height)
        }
    }

    /// Get the text extent (width and height) for the specified string
    fn get_text_extent(&self, text: &str) -> (i32, i32) {
        use std::ffi::CString;
        if let Ok(c_text) = CString::new(text) {
            let mut width = 0;
            let mut height = 0;
            unsafe { wxdragon_sys::wxd_DC_GetTextExtent(self.dc_ptr(), c_text.as_ptr(), &mut width, &mut height) };
            (width, height)
        } else {
            (0, 0)
        }
    }

    /// Set a clipping region to restrict drawing operations
    fn set_clipping_region(&self, x: i32, y: i32, width: i32, height: i32) {
        unsafe {
            wxdragon_sys::wxd_DC_SetClippingRegion(self.dc_ptr(), x, y, width, height);
        }
    }

    /// Remove the current clipping region
    fn destroy_clipping_region(&self) {
        unsafe { wxdragon_sys::wxd_DC_DestroyClippingRegion(self.dc_ptr()) };
    }

    /// Draw a polygon using the specified points
    fn draw_polygon(&self, points: &[Point], x_offset: i32, y_offset: i32, fill_mode: PolygonFillMode) {
        if points.is_empty() {
            return;
        }

        let mut ffi_points: Vec<wxdragon_sys::wxd_Point> = points.iter().map(|p| (*p).into()).collect();

        unsafe {
            wxdragon_sys::wxd_DC_DrawPolygon(
                self.dc_ptr(),
                ffi_points.len() as i32,
                ffi_points.as_mut_ptr(),
                x_offset,
                y_offset,
                fill_mode.to_raw(),
            )
        };
    }

    /// Draw an elliptic arc
    fn draw_elliptic_arc(&self, x: i32, y: i32, width: i32, height: i32, start_angle: f64, end_angle: f64) {
        unsafe { wxdragon_sys::wxd_DC_DrawEllipticArc(self.dc_ptr(), x, y, width, height, start_angle, end_angle) };
    }

    /// Draw multiple connected lines
    fn draw_lines(&self, points: &[Point], x_offset: i32, y_offset: i32) {
        if points.is_empty() {
            return;
        }

        let mut ffi_points: Vec<wxdragon_sys::wxd_Point> = points.iter().map(|p| (*p).into()).collect();

        unsafe {
            wxdragon_sys::wxd_DC_DrawLines(
                self.dc_ptr(),
                ffi_points.len() as i32,
                ffi_points.as_mut_ptr(),
                x_offset,
                y_offset,
            )
        };
    }

    /// Draw an arc from (x1, y1) to (x2, y2) with center at (xc, yc)
    fn draw_arc(&self, x1: i32, y1: i32, x2: i32, y2: i32, xc: i32, yc: i32) {
        unsafe {
            wxdragon_sys::wxd_DC_DrawArc(self.dc_ptr(), x1, y1, x2, y2, xc, yc);
        }
    }

    /// Draw a smooth spline through the given points
    fn draw_spline(&self, points: &[Point]) {
        if points.is_empty() {
            return;
        }

        let mut ffi_points: Vec<wxdragon_sys::wxd_Point> = points.iter().map(|p| (*p).into()).collect();

        unsafe { wxdragon_sys::wxd_DC_DrawSpline(self.dc_ptr(), ffi_points.len() as i32, ffi_points.as_mut_ptr()) };
    }

    /// Draw rotated text at the specified position
    fn draw_rotated_text(&self, text: &str, x: i32, y: i32, angle: f64) {
        use std::ffi::CString;
        if let Ok(c_text) = CString::new(text) {
            unsafe { wxdragon_sys::wxd_DC_DrawRotatedText(self.dc_ptr(), c_text.as_ptr(), x, y, angle) };
        }
    }

    /// Draw text with alignment within a rectangle
    fn draw_label(&self, text: &str, rect: Rect, alignment: TextAlignment, index_accel: i32) {
        use std::ffi::CString;
        if let Ok(c_text) = CString::new(text) {
            unsafe { wxdragon_sys::wxd_DC_DrawLabel(self.dc_ptr(), c_text.as_ptr(), rect.into(), alignment.bits(), index_accel) };
        }
    }

    /// Copy a portion of one DC to another using configuration struct
    fn blit(&self, source: &dyn DeviceContext, config: BlitConfig) -> bool {
        unsafe {
            wxdragon_sys::wxd_DC_Blit(
                self.dc_ptr(),
                config.dest_x,
                config.dest_y,
                config.width,
                config.height,
                source.dc_ptr(),
                config.src_x,
                config.src_y,
                config.logical_func.to_raw(),
                config.use_mask,
                config.src_mask_x,
                config.src_mask_y,
            )
        }
    }

    /// Copy and stretch a portion of one DC to another using configuration struct
    fn stretch_blit(&self, source: &dyn DeviceContext, config: StretchBlitConfig) -> bool {
        unsafe {
            wxdragon_sys::wxd_DC_StretchBlit(
                self.dc_ptr(),
                config.dest_x,
                config.dest_y,
                config.dest_width,
                config.dest_height,
                source.dc_ptr(),
                config.src_x,
                config.src_y,
                config.src_width,
                config.src_height,
                config.logical_func.to_raw(),
                config.use_mask,
                config.src_mask_x,
                config.src_mask_y,
            )
        }
    }

    /// Set clipping region from a set of points
    fn set_clipping_region_from_points(&self, points: &[Point]) {
        if points.is_empty() {
            return;
        }

        let mut ffi_points: Vec<wxdragon_sys::wxd_Point> = points.iter().map(|p| (*p).into()).collect();

        unsafe {
            wxdragon_sys::wxd_DC_SetClippingRegionFromPoints(self.dc_ptr(), ffi_points.len() as i32, ffi_points.as_mut_ptr())
        };
    }

    /// Get the clipping box coordinates
    fn get_clipping_box(&self) -> Rect {
        let mut x = 0;
        let mut y = 0;
        let mut width = 0;
        let mut height = 0;

        unsafe { wxdragon_sys::wxd_DC_GetClippingBox(self.dc_ptr(), &mut x, &mut y, &mut width, &mut height) };

        Rect::new(x, y, width, height)
    }

    /// Set the device origin
    fn set_device_origin(&self, x: i32, y: i32) {
        unsafe { wxdragon_sys::wxd_DC_SetDeviceOrigin(self.dc_ptr(), x, y) };
    }

    /// Set the logical origin
    fn set_logical_origin(&self, x: i32, y: i32) {
        unsafe { wxdragon_sys::wxd_DC_SetLogicalOrigin(self.dc_ptr(), x, y) };
    }

    /// Set the user scale factors
    fn set_user_scale(&self, x_scale: f64, y_scale: f64) {
        unsafe { wxdragon_sys::wxd_DC_SetUserScale(self.dc_ptr(), x_scale, y_scale) };
    }

    /// Set the logical scale factors
    fn set_logical_scale(&self, x_scale: f64, y_scale: f64) {
        unsafe { wxdragon_sys::wxd_DC_SetLogicalScale(self.dc_ptr(), x_scale, y_scale) };
    }

    /// Set the mapping mode
    fn set_map_mode(&self, mode: MapMode) {
        unsafe { wxdragon_sys::wxd_DC_SetMapMode(self.dc_ptr(), mode.to_raw()) };
    }

    /// Get the device origin
    fn get_device_origin(&self) -> Point {
        let origin = unsafe { wxdragon_sys::wxd_DC_GetDeviceOrigin(self.dc_ptr()) };
        origin.into()
    }

    /// Get the logical origin
    fn get_logical_origin(&self) -> Point {
        let origin = unsafe { wxdragon_sys::wxd_DC_GetLogicalOrigin(self.dc_ptr()) };
        origin.into()
    }

    /// Get the user scale factors
    fn get_user_scale(&self) -> (f64, f64) {
        let mut x_scale = 0.0;
        let mut y_scale = 0.0;

        unsafe { wxdragon_sys::wxd_DC_GetUserScale(self.dc_ptr(), &mut x_scale, &mut y_scale) };

        (x_scale, y_scale)
    }

    /// Get the logical scale factors
    fn get_logical_scale(&self) -> (f64, f64) {
        let mut x_scale = 0.0;
        let mut y_scale = 0.0;

        unsafe { wxdragon_sys::wxd_DC_GetLogicalScale(self.dc_ptr(), &mut x_scale, &mut y_scale) };

        (x_scale, y_scale)
    }

    /// Get the current mapping mode
    fn get_map_mode(&self) -> MapMode {
        let mode = unsafe { wxdragon_sys::wxd_DC_GetMapMode(self.dc_ptr()) };
        MapMode::from_raw(mode)
    }

    /// Convert device coordinates to logical coordinates (X)
    fn device_to_logical_x(&self, x: i32) -> i32 {
        unsafe { wxdragon_sys::wxd_DC_DeviceToLogicalX(self.dc_ptr(), x) }
    }

    /// Convert device coordinates to logical coordinates (Y)
    fn device_to_logical_y(&self, y: i32) -> i32 {
        unsafe { wxdragon_sys::wxd_DC_DeviceToLogicalY(self.dc_ptr(), y) }
    }

    /// Convert logical coordinates to device coordinates (X)
    fn logical_to_device_x(&self, x: i32) -> i32 {
        unsafe { wxdragon_sys::wxd_DC_LogicalToDeviceX(self.dc_ptr(), x) }
    }

    /// Convert logical coordinates to device coordinates (Y)
    fn logical_to_device_y(&self, y: i32) -> i32 {
        unsafe { wxdragon_sys::wxd_DC_LogicalToDeviceY(self.dc_ptr(), y) }
    }

    /// Get the size in millimeters
    fn get_size_mm(&self) -> (i32, i32) {
        let size = unsafe { wxdragon_sys::wxd_DC_GetSizeMM(self.dc_ptr()) };
        (size.width, size.height)
    }

    /// Get full text extent including descent and external leading
    fn get_full_text_extent(&self, text: &str, font: Option<&Font>) -> (i32, i32, i32, i32) {
        use std::ffi::CString;
        if let Ok(c_text) = CString::new(text) {
            let mut width = 0;
            let mut height = 0;
            let mut descent = 0;
            let mut external_leading = 0;

            unsafe {
                wxdragon_sys::wxd_DC_GetFullTextExtent(
                    self.dc_ptr(),
                    c_text.as_ptr(),
                    &mut width,
                    &mut height,
                    &mut descent,
                    &mut external_leading,
                    font.map(|f| f.as_ptr()).unwrap_or(std::ptr::null_mut()),
                );
            }
            (width, height, descent, external_leading)
        } else {
            (0, 0, 0, 0)
        }
    }

    /// Get text extent for multi-line text
    fn get_multi_line_text_extent(&self, text: &str, font: Option<&Font>) -> (i32, i32, i32) {
        use std::ffi::CString;
        if let Ok(c_text) = CString::new(text) {
            let mut width = 0;
            let mut height = 0;
            let mut height_line = 0;

            unsafe {
                wxdragon_sys::wxd_DC_GetMultiLineTextExtent(
                    self.dc_ptr(),
                    c_text.as_ptr(),
                    &mut width,
                    &mut height,
                    &mut height_line,
                    font.map(|f| f.as_ptr()).unwrap_or(std::ptr::null_mut()),
                );
            }
            (width, height, height_line)
        } else {
            (0, 0, 0)
        }
    }

    /// Get the character height for the current font
    fn get_char_height(&self) -> i32 {
        unsafe { wxdragon_sys::wxd_DC_GetCharHeight(self.dc_ptr()) }
    }

    /// Get the character width for the current font
    fn get_char_width(&self) -> i32 {
        unsafe { wxdragon_sys::wxd_DC_GetCharWidth(self.dc_ptr()) }
    }

    /// Get the current background color
    fn get_background(&self) -> Colour {
        let colour = unsafe { wxdragon_sys::wxd_DC_GetBackground(self.dc_ptr()) };
        Colour::new(colour.r, colour.g, colour.b, colour.a)
    }

    /// Get the current background mode
    fn get_background_mode(&self) -> BackgroundMode {
        let mode = unsafe { wxdragon_sys::wxd_DC_GetBackgroundMode(self.dc_ptr()) };
        if mode == wxdragon_sys::WXD_TRANSPARENT as i32 {
            BackgroundMode::Transparent
        } else {
            BackgroundMode::Solid
        }
    }

    /// Get the current text background color
    fn get_text_background(&self) -> Colour {
        let colour = unsafe { wxdragon_sys::wxd_DC_GetTextBackground(self.dc_ptr()) };
        Colour::new(colour.r, colour.g, colour.b, colour.a)
    }

    /// Get the current text foreground color
    fn get_text_foreground(&self) -> Colour {
        let colour = unsafe { wxdragon_sys::wxd_DC_GetTextForeground(self.dc_ptr()) };
        Colour::new(colour.r, colour.g, colour.b, colour.a)
    }

    /// Get the pixels per inch (DPI)
    fn get_ppi(&self) -> (i32, i32) {
        let ppi = unsafe { wxdragon_sys::wxd_DC_GetPPI(self.dc_ptr()) };
        (ppi.width, ppi.height)
    }

    /// Get the content scale factor (for high-DPI displays)
    fn get_content_scale_factor(&self) -> f64 {
        unsafe { wxdragon_sys::wxd_DC_GetContentScaleFactor(self.dc_ptr()) }
    }

    /// Fill a rectangle with a linear gradient
    fn gradient_fill_linear(&self, rect: Rect, initial_colour: Colour, dest_colour: Colour, direction: GradientDirection) {
        unsafe {
            wxdragon_sys::wxd_DC_GradientFillLinear(
                self.dc_ptr(),
                rect.into(),
                initial_colour.into(),
                dest_colour.into(),
                direction.to_raw(),
            )
        };
    }

    /// Fill a rectangle with a concentric gradient
    fn gradient_fill_concentric(&self, rect: Rect, initial_colour: Colour, dest_colour: Colour, circle_center: Point) {
        unsafe {
            wxdragon_sys::wxd_DC_GradientFillConcentric(
                self.dc_ptr(),
                rect.into(),
                initial_colour.into(),
                dest_colour.into(),
                circle_center.into(),
            )
        };
    }

    /// Flood fill starting from a point
    fn flood_fill(&self, x: i32, y: i32, colour: Colour, style: FloodFillMode) -> bool {
        unsafe { wxdragon_sys::wxd_DC_FloodFill(self.dc_ptr(), x, y, colour.into(), style.to_raw()) }
    }

    /// Set the logical function for drawing operations
    fn set_logical_function(&self, function: LogicalFunction) {
        unsafe { wxdragon_sys::wxd_DC_SetLogicalFunction(self.dc_ptr(), function.to_raw()) };
    }

    /// Get the current logical function
    fn get_logical_function(&self) -> LogicalFunction {
        let function = unsafe { wxdragon_sys::wxd_DC_GetLogicalFunction(self.dc_ptr()) };
        LogicalFunction::from_raw(function)
    }
}