wxdragon-sys 0.9.16

Raw FFI bindings to libwxdragon (which statically links wxWidgets).
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
#include <wx/wxprec.h>
#include <wx/wx.h>
#include "../include/wxdragon.h"
#include <wx/dcmemory.h>
#include <wx/dcscreen.h>
#include <wx/dcbuffer.h>

// Type aliases for easier reference
using wxd_DC_t = struct wxd_DC_t;
using wxd_WindowDC_t = struct wxd_WindowDC_t;
using wxd_ClientDC_t = struct wxd_ClientDC_t;
using wxd_PaintDC_t = struct wxd_PaintDC_t;
using wxd_MemoryDC_t = struct wxd_MemoryDC_t;
using wxd_ScreenDC_t = struct wxd_ScreenDC_t;
using wxd_AutoBufferedPaintDC_t = struct wxd_AutoBufferedPaintDC_t;

// The wxWidgets DC hierarchy provides some challenges for C FFI
// We need to use the opaque type pattern and typecasts:
// - wxDC (base class)
//   - wxWindowDC
//     - wxClientDC
//     - wxPaintDC
//   - wxMemoryDC
//   - wxScreenDC

// Since wxDC is abstract, we need to ensure we only expose classes that wxWidgets actually provides

// DC Creation/Destruction
void
wxd_DC_Destroy(wxd_DC_t* dc)
{
    if (dc) {
        delete reinterpret_cast<wxDC*>(dc);
    }
}

wxd_WindowDC_t*
wxd_WindowDC_Create(wxd_Window_t* window)
{
    if (!window)
        return nullptr;
    wxWindow* wx_window = reinterpret_cast<wxWindow*>(window);
    return reinterpret_cast<wxd_WindowDC_t*>(new wxWindowDC(wx_window));
}

void
wxd_WindowDC_Destroy(wxd_WindowDC_t* dc)
{
    if (dc) {
        delete reinterpret_cast<wxWindowDC*>(dc);
    }
}

wxd_ClientDC_t*
wxd_ClientDC_Create(wxd_Window_t* window)
{
    if (!window)
        return nullptr;
    wxWindow* wx_window = reinterpret_cast<wxWindow*>(window);
    return reinterpret_cast<wxd_ClientDC_t*>(new wxClientDC(wx_window));
}

void
wxd_ClientDC_Destroy(wxd_ClientDC_t* dc)
{
    if (dc) {
        delete reinterpret_cast<wxClientDC*>(dc);
    }
}

wxd_PaintDC_t*
wxd_PaintDC_Create(wxd_Window_t* window)
{
    if (!window)
        return nullptr;
    wxWindow* wx_window = reinterpret_cast<wxWindow*>(window);
    return reinterpret_cast<wxd_PaintDC_t*>(new wxPaintDC(wx_window));
}

void
wxd_PaintDC_Destroy(wxd_PaintDC_t* dc)
{
    if (dc) {
        delete reinterpret_cast<wxPaintDC*>(dc);
    }
}

wxd_MemoryDC_t*
wxd_MemoryDC_Create(void)
{
    return reinterpret_cast<wxd_MemoryDC_t*>(new wxMemoryDC());
}

void
wxd_MemoryDC_Destroy(wxd_MemoryDC_t* dc)
{
    if (dc) {
        delete reinterpret_cast<wxMemoryDC*>(dc);
    }
}

wxd_ScreenDC_t*
wxd_ScreenDC_Create(void)
{
    return reinterpret_cast<wxd_ScreenDC_t*>(new wxScreenDC());
}

void
wxd_ScreenDC_Destroy(wxd_ScreenDC_t* dc)
{
    if (dc) {
        delete reinterpret_cast<wxScreenDC*>(dc);
    }
}

wxd_AutoBufferedPaintDC_t*
wxd_AutoBufferedPaintDC_Create(wxd_Window_t* window)
{
    if (!window)
        return nullptr;
    wxWindow* wx_window = reinterpret_cast<wxWindow*>(window);
    return reinterpret_cast<wxd_AutoBufferedPaintDC_t*>(new wxAutoBufferedPaintDC(wx_window));
}

void
wxd_AutoBufferedPaintDC_Destroy(wxd_AutoBufferedPaintDC_t* dc)
{
    if (dc) {
        delete reinterpret_cast<wxAutoBufferedPaintDC*>(dc);
    }
}

// Type casting functions
wxd_DC_t*
wxd_WindowDC_AsDC(wxd_WindowDC_t* dc)
{
    return reinterpret_cast<wxd_DC_t*>(static_cast<wxDC*>(reinterpret_cast<wxWindowDC*>(dc)));
}

wxd_DC_t*
wxd_ClientDC_AsDC(wxd_ClientDC_t* dc)
{
    return reinterpret_cast<wxd_DC_t*>(static_cast<wxDC*>(reinterpret_cast<wxClientDC*>(dc)));
}

wxd_DC_t*
wxd_PaintDC_AsDC(wxd_PaintDC_t* dc)
{
    return reinterpret_cast<wxd_DC_t*>(static_cast<wxDC*>(reinterpret_cast<wxPaintDC*>(dc)));
}

wxd_DC_t*
wxd_MemoryDC_AsDC(wxd_MemoryDC_t* dc)
{
    return reinterpret_cast<wxd_DC_t*>(static_cast<wxDC*>(reinterpret_cast<wxMemoryDC*>(dc)));
}

wxd_DC_t*
wxd_ScreenDC_AsDC(wxd_ScreenDC_t* dc)
{
    return reinterpret_cast<wxd_DC_t*>(static_cast<wxDC*>(reinterpret_cast<wxScreenDC*>(dc)));
}

wxd_DC_t*
wxd_AutoBufferedPaintDC_AsDC(wxd_AutoBufferedPaintDC_t* dc)
{
    return reinterpret_cast<wxd_DC_t*>(
        static_cast<wxDC*>(reinterpret_cast<wxAutoBufferedPaintDC*>(dc)));
}

// Common DC operations
void
wxd_DC_Clear(wxd_DC_t* dc)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wx_dc->Clear();
    }
}

void
wxd_DC_SetBackground(wxd_DC_t* dc, wxd_Colour_t background)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxColour wx_color(background.r, background.g, background.b, background.a);
        wx_dc->SetBackground(wxBrush(wx_color));
    }
}

void
wxd_DC_SetBackgroundMode(wxd_DC_t* dc, int mode)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        int wx_mode = mode;
        wx_dc->SetBackgroundMode(wx_mode);
    }
}

void
wxd_DC_SetTextBackground(wxd_DC_t* dc, wxd_Colour_t colour)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxColour wx_color(colour.r, colour.g, colour.b, colour.a);
        wx_dc->SetTextBackground(wx_color);
    }
}

void
wxd_DC_SetTextForeground(wxd_DC_t* dc, wxd_Colour_t colour)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxColour wx_color(colour.r, colour.g, colour.b, colour.a);
        wx_dc->SetTextForeground(wx_color);
    }
}

void
wxd_DC_SetFont(wxd_DC_t* dc, const wxd_Font_t* font)
{
    if (dc && font) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxFont* wx_font = reinterpret_cast<wxFont*>(const_cast<wxd_Font_t*>(font));
        wx_dc->SetFont(*wx_font);
    }
}

void
wxd_DC_SetPen(wxd_DC_t* dc, wxd_Colour_t colour, int width, int style)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxColour wx_color(colour.r, colour.g, colour.b, colour.a);

        wxPenStyle wx_style = static_cast<wxPenStyle>(style);

        wx_dc->SetPen(wxPen(wx_color, width, wx_style));
    }
}

void
wxd_DC_SetBrush(wxd_DC_t* dc, wxd_Colour_t colour, int style)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxColour wx_color(colour.r, colour.g, colour.b, colour.a);

        wxBrushStyle wx_style = static_cast<wxBrushStyle>(style);

        wx_dc->SetBrush(wxBrush(wx_color, wx_style));
    }
}

// Advanced drawing operations
void
wxd_DC_DrawRoundedRectangle(wxd_DC_t* dc, int x, int y, int width, int height, double radius)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wx_dc->DrawRoundedRectangle(x, y, width, height, radius);
    }
}

void
wxd_DC_DrawArc(wxd_DC_t* dc, int x1, int y1, int x2, int y2, int xc, int yc)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wx_dc->DrawArc(x1, y1, x2, y2, xc, yc);
    }
}

void
wxd_DC_DrawEllipticArc(wxd_DC_t* dc, int x, int y, int width, int height, double start, double end)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wx_dc->DrawEllipticArc(x, y, width, height, start, end);
    }
}

void
wxd_DC_DrawPolygon(wxd_DC_t* dc, int n, wxd_Point* points, int xoffset, int yoffset, int fill_style)
{
    if (dc && points) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxPoint* wx_points = reinterpret_cast<wxPoint*>(points);
        wxPolygonFillMode wx_fill_style = static_cast<wxPolygonFillMode>(fill_style);
        wx_dc->DrawPolygon(n, wx_points, xoffset, yoffset, wx_fill_style);
    }
}

void
wxd_DC_DrawLines(wxd_DC_t* dc, int n, wxd_Point* points, int xoffset, int yoffset)
{
    if (dc && points) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxPoint* wx_points = reinterpret_cast<wxPoint*>(points);
        wx_dc->DrawLines(n, wx_points, xoffset, yoffset);
    }
}

void
wxd_DC_DrawSpline(wxd_DC_t* dc, int n, wxd_Point* points)
{
    if (dc && points) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxPoint* wx_points = reinterpret_cast<wxPoint*>(points);
        wx_dc->DrawSpline(n, wx_points);
    }
}

// Text drawing operations
void
wxd_DC_DrawRotatedText(wxd_DC_t* dc, const char* text, int x, int y, double angle)
{
    if (dc && text) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxString wx_text = wxString::FromUTF8(text);
        wx_dc->DrawRotatedText(wx_text, x, y, angle);
    }
}

void
wxd_DC_DrawLabel(wxd_DC_t* dc, const char* text, wxd_Rect rect, int alignment, int indexAccel)
{
    if (dc && text) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxString wx_text = wxString::FromUTF8(text);
        wxRect wx_rect(rect.x, rect.y, rect.width, rect.height);
        int wx_alignment = alignment;

        wx_dc->DrawLabel(wx_text, wx_rect, wx_alignment, indexAccel);
    }
}

// Bitmap operations
bool
wxd_DC_Blit(wxd_DC_t* dest_dc, int xdest, int ydest, int width, int height, wxd_DC_t* source_dc,
            int xsrc, int ysrc, int logical_func, bool use_mask, int xsrc_mask, int ysrc_mask)
{
    if (!dest_dc || !source_dc)
        return false;

    wxDC* wx_dest_dc = reinterpret_cast<wxDC*>(dest_dc);
    wxDC* wx_source_dc = reinterpret_cast<wxDC*>(source_dc);

    wxRasterOperationMode wx_logical_func = static_cast<wxRasterOperationMode>(logical_func);

    return wx_dest_dc->Blit(xdest, ydest, width, height, wx_source_dc, xsrc, ysrc, wx_logical_func,
                            use_mask, xsrc_mask, ysrc_mask);
}

bool
wxd_DC_StretchBlit(wxd_DC_t* dest_dc, int xdest, int ydest, int dstWidth, int dstHeight,
                   wxd_DC_t* source_dc, int xsrc, int ysrc, int srcWidth, int srcHeight,
                   int logical_func, bool use_mask, int xsrc_mask, int ysrc_mask)
{
    if (!dest_dc || !source_dc)
        return false;

    wxDC* wx_dest_dc = reinterpret_cast<wxDC*>(dest_dc);
    wxDC* wx_source_dc = reinterpret_cast<wxDC*>(source_dc);

    wxRasterOperationMode wx_logical_func = static_cast<wxRasterOperationMode>(logical_func);

    return wx_dest_dc->StretchBlit(xdest, ydest, dstWidth, dstHeight, wx_source_dc, xsrc, ysrc,
                                   srcWidth, srcHeight, wx_logical_func, use_mask, xsrc_mask,
                                   ysrc_mask);
}

// Clipping operations
void
wxd_DC_SetClippingRegion(wxd_DC_t* dc, int x, int y, int width, int height)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wx_dc->SetClippingRegion(x, y, width, height);
    }
}

void
wxd_DC_SetClippingRegionFromPoints(wxd_DC_t* dc, int n, wxd_Point* points)
{
    if (dc && points) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxPoint* wx_points = reinterpret_cast<wxPoint*>(points);
        // Create region and get its bounding box to use the non-deprecated method
        wxRegion region(n, wx_points);
        wxRect rect = region.GetBox();
        wx_dc->SetClippingRegion(rect.x, rect.y, rect.width, rect.height);
    }
}

void
wxd_DC_DestroyClippingRegion(wxd_DC_t* dc)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wx_dc->DestroyClippingRegion();
    }
}

void
wxd_DC_GetClippingBox(wxd_DC_t* dc, int* x, int* y, int* width, int* height)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxCoord wx_x, wx_y, wx_width, wx_height;
        wx_dc->GetClippingBox(&wx_x, &wx_y, &wx_width, &wx_height);
        if (x)
            *x = wx_x;
        if (y)
            *y = wx_y;
        if (width)
            *width = wx_width;
        if (height)
            *height = wx_height;
    }
}

// Coordinate transformation
void
wxd_DC_SetDeviceOrigin(wxd_DC_t* dc, int x, int y)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wx_dc->SetDeviceOrigin(x, y);
    }
}

void
wxd_DC_SetLogicalOrigin(wxd_DC_t* dc, int x, int y)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wx_dc->SetLogicalOrigin(x, y);
    }
}

void
wxd_DC_SetUserScale(wxd_DC_t* dc, double x_scale, double y_scale)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wx_dc->SetUserScale(x_scale, y_scale);
    }
}

void
wxd_DC_SetLogicalScale(wxd_DC_t* dc, double x_scale, double y_scale)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wx_dc->SetLogicalScale(x_scale, y_scale);
    }
}

void
wxd_DC_SetMapMode(wxd_DC_t* dc, int mode)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxMappingMode wx_mode = static_cast<wxMappingMode>(mode);
        wx_dc->SetMapMode(wx_mode);
    }
}

// Drawing operations
void
wxd_DC_DrawPoint(wxd_DC_t* dc, int x, int y)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wx_dc->DrawPoint(x, y);
    }
}

void
wxd_DC_DrawLine(wxd_DC_t* dc, int x1, int y1, int x2, int y2)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wx_dc->DrawLine(x1, y1, x2, y2);
    }
}

void
wxd_DC_DrawRectangle(wxd_DC_t* dc, int x, int y, int width, int height)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wx_dc->DrawRectangle(x, y, width, height);
    }
}

void
wxd_DC_DrawCircle(wxd_DC_t* dc, int x, int y, int radius)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wx_dc->DrawCircle(x, y, radius);
    }
}

void
wxd_DC_DrawEllipse(wxd_DC_t* dc, int x, int y, int width, int height)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wx_dc->DrawEllipse(x, y, width, height);
    }
}

void
wxd_DC_DrawText(wxd_DC_t* dc, const char* text, int x, int y)
{
    if (dc && text) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxString wx_text = wxString::FromUTF8(text ? text : "");
        wx_dc->DrawText(wx_text, x, y);
    }
}

void
wxd_DC_DrawBitmap(wxd_DC_t* dc, const wxd_Bitmap_t* bitmap, int x, int y, bool transparent)
{
    if (dc && bitmap) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxBitmap* wx_bitmap = reinterpret_cast<wxBitmap*>(const_cast<wxd_Bitmap_t*>(bitmap));
        wx_dc->DrawBitmap(*wx_bitmap, x, y, transparent);
    }
}

// Device capabilities
wxd_Size
wxd_DC_GetSize(wxd_DC_t* dc)
{
    wxd_Size size = { 0, 0 };
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxSize wx_size = wx_dc->GetSize();
        size.width = wx_size.x;
        size.height = wx_size.y;
    }
    return size;
}

void
wxd_DC_GetTextExtent(wxd_DC_t* dc, const char* string, int* w, int* h)
{
    if (dc && string && w && h) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxString wx_text = wxString::FromUTF8(string);
        int width, height;
        wx_dc->GetTextExtent(wx_text, &width, &height);
        *w = width;
        *h = height;
    }
}

// MemoryDC specific operations
void
wxd_MemoryDC_SelectObject(wxd_MemoryDC_t* dc, const wxd_Bitmap_t* bitmap)
{
    if (dc && bitmap) {
        wxMemoryDC* wx_dc = reinterpret_cast<wxMemoryDC*>(dc);
        const wxBitmap* wx_bitmap = reinterpret_cast<const wxBitmap*>(bitmap);
        // Note: wxMemoryDC::SelectObject takes a non-const wxBitmap*, strange.
        wx_dc->SelectObject(*(const_cast<wxBitmap*>(wx_bitmap)));
    }
}

void
wxd_MemoryDC_SelectObjectAsSource(wxd_MemoryDC_t* dc, const wxd_Bitmap_t* bitmap)
{
    if (dc && bitmap) {
        wxMemoryDC* wx_dc = reinterpret_cast<wxMemoryDC*>(dc);
        const wxBitmap* wx_bitmap = reinterpret_cast<const wxBitmap*>(bitmap);
        wx_dc->SelectObjectAsSource(*wx_bitmap);
    }
}

// Get transformation info
wxd_Point
wxd_DC_GetDeviceOrigin(wxd_DC_t* dc)
{
    wxd_Point origin = { 0, 0 };
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxPoint wx_origin = wx_dc->GetDeviceOrigin();
        origin.x = wx_origin.x;
        origin.y = wx_origin.y;
    }
    return origin;
}

wxd_Point
wxd_DC_GetLogicalOrigin(wxd_DC_t* dc)
{
    wxd_Point origin = { 0, 0 };
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxPoint wx_origin = wx_dc->GetLogicalOrigin();
        origin.x = wx_origin.x;
        origin.y = wx_origin.y;
    }
    return origin;
}

void
wxd_DC_GetUserScale(wxd_DC_t* dc, double* x_scale, double* y_scale)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        double wx_x_scale, wx_y_scale;
        wx_dc->GetUserScale(&wx_x_scale, &wx_y_scale);
        if (x_scale)
            *x_scale = wx_x_scale;
        if (y_scale)
            *y_scale = wx_y_scale;
    }
}

void
wxd_DC_GetLogicalScale(wxd_DC_t* dc, double* x_scale, double* y_scale)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        double wx_x_scale, wx_y_scale;
        wx_dc->GetLogicalScale(&wx_x_scale, &wx_y_scale);
        if (x_scale)
            *x_scale = wx_x_scale;
        if (y_scale)
            *y_scale = wx_y_scale;
    }
}

int
wxd_DC_GetMapMode(wxd_DC_t* dc)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        return static_cast<int>(wx_dc->GetMapMode());
    }
    return static_cast<int>(wxMM_TEXT);
}

// Coordinate conversion
int
wxd_DC_DeviceToLogicalX(wxd_DC_t* dc, int x)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        return wx_dc->DeviceToLogicalX(x);
    }
    return x;
}

int
wxd_DC_DeviceToLogicalY(wxd_DC_t* dc, int y)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        return wx_dc->DeviceToLogicalY(y);
    }
    return y;
}

int
wxd_DC_LogicalToDeviceX(wxd_DC_t* dc, int x)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        return wx_dc->LogicalToDeviceX(x);
    }
    return x;
}

int
wxd_DC_LogicalToDeviceY(wxd_DC_t* dc, int y)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        return wx_dc->LogicalToDeviceY(y);
    }
    return y;
}

// Extended device capabilities
wxd_Size
wxd_DC_GetSizeMM(wxd_DC_t* dc)
{
    wxd_Size size = { 0, 0 };
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxSize wx_size = wx_dc->GetSizeMM();
        size.width = wx_size.x;
        size.height = wx_size.y;
    }
    return size;
}

void
wxd_DC_GetFullTextExtent(wxd_DC_t* dc, const char* string, int* w, int* h, int* descent,
                         int* externalLeading, const wxd_Font_t* font)
{
    if (dc && string) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxString wx_text = wxString::FromUTF8(string);
        wxCoord wx_w, wx_h, wx_descent, wx_externalLeading;

        if (font) {
            wxFont* wx_font = reinterpret_cast<wxFont*>(const_cast<wxd_Font_t*>(font));
            wx_dc->GetTextExtent(wx_text, &wx_w, &wx_h, &wx_descent, &wx_externalLeading, wx_font);
        }
        else {
            wx_dc->GetTextExtent(wx_text, &wx_w, &wx_h, &wx_descent, &wx_externalLeading);
        }

        if (w)
            *w = wx_w;
        if (h)
            *h = wx_h;
        if (descent)
            *descent = wx_descent;
        if (externalLeading)
            *externalLeading = wx_externalLeading;
    }
}

void
wxd_DC_GetMultiLineTextExtent(wxd_DC_t* dc, const char* string, int* w, int* h, int* heightLine,
                              const wxd_Font_t* font)
{
    if (dc && string) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxString wx_text = wxString::FromUTF8(string);
        wxCoord wx_w, wx_h, wx_heightLine;

        if (font) {
            wxFont* wx_font = reinterpret_cast<wxFont*>(const_cast<wxd_Font_t*>(font));
            wx_dc->GetMultiLineTextExtent(wx_text, &wx_w, &wx_h, &wx_heightLine, wx_font);
        }
        else {
            wx_dc->GetMultiLineTextExtent(wx_text, &wx_w, &wx_h, &wx_heightLine);
        }

        if (w)
            *w = wx_w;
        if (h)
            *h = wx_h;
        if (heightLine)
            *heightLine = wx_heightLine;
    }
}

int
wxd_DC_GetCharHeight(wxd_DC_t* dc)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        return wx_dc->GetCharHeight();
    }
    return 0;
}

int
wxd_DC_GetCharWidth(wxd_DC_t* dc)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        return wx_dc->GetCharWidth();
    }
    return 0;
}

// Drawing state queries
wxd_Colour_t
wxd_DC_GetBackground(wxd_DC_t* dc)
{
    wxd_Colour_t colour = { 0, 0, 0, 255 };
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxColour wx_colour = wx_dc->GetBackground().GetColour();
        colour.r = wx_colour.Red();
        colour.g = wx_colour.Green();
        colour.b = wx_colour.Blue();
        colour.a = wx_colour.Alpha();
    }
    return colour;
}

int
wxd_DC_GetBackgroundMode(wxd_DC_t* dc)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        return static_cast<int>(wx_dc->GetBackgroundMode());
    }
    return static_cast<int>(wxSOLID);
}

wxd_Colour_t
wxd_DC_GetTextBackground(wxd_DC_t* dc)
{
    wxd_Colour_t colour = { 0, 0, 0, 255 };
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxColour wx_colour = wx_dc->GetTextBackground();
        colour.r = wx_colour.Red();
        colour.g = wx_colour.Green();
        colour.b = wx_colour.Blue();
        colour.a = wx_colour.Alpha();
    }
    return colour;
}

wxd_Colour_t
wxd_DC_GetTextForeground(wxd_DC_t* dc)
{
    wxd_Colour_t colour = { 0, 0, 0, 255 };
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxColour wx_colour = wx_dc->GetTextForeground();
        colour.r = wx_colour.Red();
        colour.g = wx_colour.Green();
        colour.b = wx_colour.Blue();
        colour.a = wx_colour.Alpha();
    }
    return colour;
}

// DPI and scaling
wxd_Size
wxd_DC_GetPPI(wxd_DC_t* dc)
{
    wxd_Size ppi = { 96, 96 }; // Default DPI
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxSize wx_ppi = wx_dc->GetPPI();
        ppi.width = wx_ppi.x;
        ppi.height = wx_ppi.y;
    }
    return ppi;
}

double
wxd_DC_GetContentScaleFactor(wxd_DC_t* dc)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        return wx_dc->GetContentScaleFactor();
    }
    return 1.0;
}

// Gradient fills
void
wxd_DC_GradientFillLinear(wxd_DC_t* dc, wxd_Rect rect, wxd_Colour_t initialColour,
                          wxd_Colour_t destColour, int direction)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxRect wx_rect(rect.x, rect.y, rect.width, rect.height);
        wxColour wx_initial(initialColour.r, initialColour.g, initialColour.b, initialColour.a);
        wxColour wx_dest(destColour.r, destColour.g, destColour.b, destColour.a);

        wxDirection wx_direction = static_cast<wxDirection>(direction);

        wx_dc->GradientFillLinear(wx_rect, wx_initial, wx_dest, wx_direction);
    }
}

void
wxd_DC_GradientFillConcentric(wxd_DC_t* dc, wxd_Rect rect, wxd_Colour_t initialColour,
                              wxd_Colour_t destColour, wxd_Point circleCenter)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxRect wx_rect(rect.x, rect.y, rect.width, rect.height);
        wxColour wx_initial(initialColour.r, initialColour.g, initialColour.b, initialColour.a);
        wxColour wx_dest(destColour.r, destColour.g, destColour.b, destColour.a);
        wxPoint wx_center(circleCenter.x, circleCenter.y);

        wx_dc->GradientFillConcentric(wx_rect, wx_initial, wx_dest, wx_center);
    }
}

// Flood fill
bool
wxd_DC_FloodFill(wxd_DC_t* dc, int x, int y, wxd_Colour_t colour, int style)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxColour wx_colour(colour.r, colour.g, colour.b, colour.a);
        wxFloodFillStyle wx_style = static_cast<wxFloodFillStyle>(style);
        return wx_dc->FloodFill(x, y, wx_colour, wx_style);
    }
    return false;
}

// Drawing modes and logical functions
void
wxd_DC_SetLogicalFunction(wxd_DC_t* dc, int function)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        wxRasterOperationMode wx_function = static_cast<wxRasterOperationMode>(function);
        wx_dc->SetLogicalFunction(wx_function);
    }
}

int
wxd_DC_GetLogicalFunction(wxd_DC_t* dc)
{
    if (dc) {
        wxDC* wx_dc = reinterpret_cast<wxDC*>(dc);
        return static_cast<int>(wx_dc->GetLogicalFunction());
    }
    return static_cast<int>(wxCOPY);
}