-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibex_canvas.c
More file actions
executable file
·2041 lines (1609 loc) · 77.4 KB
/
libex_canvas.c
File metadata and controls
executable file
·2041 lines (1609 loc) · 77.4 KB
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
1000
/* -------------------------------------------------------------------------- */
/* (c) ali@balarabe.com [libex_canvas.c] */
/* -------------------------------------------------------------------------- */
#include "libex_c_precompiled.h"
#include "libex_canvas_.h"
#if defined INCLUDED_LIBEX_CANVAS_H
#include "libex_config_.h"
#include <string.h> /* for memset() */
#if PLATFORM_WIN32
#include "libex_win32_.h"
#include <wingdi.h>
#include <winuser.h>
#if defined _MSC_VER
#pragma comment (lib, "user32.lib")
/* DrawText() */
/* GetClientRect() */
/* GetDC() */
/* WindowFromDC() */
#pragma comment (lib, "gdi32.lib")
/* AngleArc() */
/* BeginPath() */
/* BitBlt() */
/* CreateCompatibleBitmap() */
/* CreateCompatibleDC() */
/* CreatePen() */
/* CreateRectRgn() */
/* CreateSolidBrush() */
/* DeleteObject() */
/* Ellipse() */
/* EndPath() */
/* ExtSelectClipRgn() */
/* ExtTextOut() */
/* GetClipRgn() */
/* GetMapMode() */
/* GetStockObject() */
/* GetTextExtentPoint32() */
/* LineTo() */
/* MoveToEx() */
/* Polygon() */
/* Polyline() */
/* Rectangle() */
/* RoundRect() */
/* SelectClipRgn() */
/* SelectObject() */
/* SetBkColor() */
/* SetBkMode() */
/* SetDCBrushColor() */
/* SetMapMode() */
/* SetTextColor() */
/* SetWindowOrgEx() */
/* StrokeAndFillPath() */
#endif
#endif /* PLATFORM_WIN32 */
#include "libex_.h"
#include "libex_call_.h"
#include "libex_const_.h"
#include "libex_logging_.h"
#include "libex_macro_.h"
#include "libex_string_class_.h"
#include "libex_stringc_.h"
#include "libex_system_.h"
#include "libex_type_.h"
#if defined __cplusplus_cli
#pragma unmanaged
#endif
/* -------------------------------------------------------------------------- */
/* Macros: */
#undef CHECK_FOR_NULL_OBJECT
#if !defined CHECK_FOR_NULL_OBJECT
#define CHECK_FOR_NULL_OBJECT( OBJECT_, SRC_UID_ ) \
{ \
if (OBJECT_ == NULL) \
{ DEBUG_WARN(_T("object_ == NULL"), SRC_UID_); RETURN(NULL); } \
} /*#*/
#endif /* !CHECK_FOR_NULL_OBJECT */
#define _ASSERT_DC \
if (&object_->hdc == NULL || object_->hdc == NULL) \
{ RETURN(NIL) } /*#*/
#define _INIT_XY \
const pixel_t x = x_ + object_->area.x; \
const pixel_t y = y_ + object_->area.y; /*#*/
#define _INIT_XY2 \
const pixel_t x1 = x1_ + object_->area.x; \
const pixel_t y1 = y1_ + object_->area.y; \
const pixel_t x2 = x2_ + object_->area.x; \
const pixel_t y2 = y2_ + object_->area.y; /*#*/
#define _SET_COLOR( OBJECT_, ARG_ ) \
if (ARG_ != COLOR_NULL) \
{ Canvas_color(object_, ARG_); } /*#*/
/* -------------------------------------------------------------------------- */
/* WinGDI.h */
#if !defined _DC_BRUSH
#define _DC_BRUSH 18
#endif
#if !defined _DC_PEN
#define _DC_PEN 19
#endif
/* -------------------------------------------------------------------------- */
NAMESPACE(c_)
/* -------------------------------------------------------------------------- */
/* Functions: Private */
#if defined __GNUC__
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#pragma GCC diagnostic ignored "-Wunused-function"
#endif
static void _gradient_fill( /*F*/
canvas_t* object_, /*-*/
pixel_t x_, /*-*/
pixel_t y_, /*-*/
const pixel_t width_, /*-*/
const pixel_t height_, /*-*/
const color_t color1_, /*-*/
const color_t color2_, /*-*/
const bool vertical_fill_ ) { /*-*/
GO (UID(FB9671));
#if PLATFORM_LINUX
IMPLEMENT_LINUX(); /* TODO: implement _gradient_fill() on Linux */
UNUSED(object_);
UNUSED(x_);
UNUSED(y_);
UNUSED(width_);
UNUSED(height_);
UNUSED(color1_);
UNUSED(color2_);
UNUSED(vertical_fill_);
#endif /* PLATFORM_LINUX */
#if PLATFORM_WIN32
double blue = 0;
double green = 0;
double red = 0;
double grow_blue = 0;
double grow_green = 0;
double grow_red = 0;
int i = 0;
RECT_win rect = { 0, 0, 0, 0 };
color_t color1 = { 0 };
color_t color2 = { 0 };
pixel_t size = 0;
_INIT_XY;
_ASSERT_DC;
if (object_->hdc == NULL) {
RETURN(NIL);
}
color1 = Color_rgb(color1_);
color2 = Color_rgb(color2_);
rect.left = CAST(LONG_win, x);
rect.top = CAST(LONG_win, y);
rect.right = CAST(LONG_win, x + width_);
rect.bottom = CAST(LONG_win, y + height_);
red = Color_getRed(color1);
green = Color_getGreen(color1);
blue = Color_getBlue(color1);
size = vertical_fill_ ? height_ : width_;
grow_red = (Color_getRed(color2) - red) / size;
grow_green = (Color_getGreen(color2) - green) / size;
grow_blue = (Color_getBlue(color2) - blue) / size;
for (i = 0; i < size; i++) {
if (vertical_fill_) {
rect.top = CAST(LONG_win, y + i);
rect.bottom = CAST(LONG_win, y + i + 1);
if (rect.bottom > y + height_) {
rect.bottom = CAST(LONG_win, y + height_);
}
} else {
rect.left = CAST(LONG_win, x + i);
rect.right = CAST(LONG_win, x + i + 1);
if (rect.right > x + width_) {
rect.right = CAST(LONG_win, x + width_);
}
}
OS_VERIFY(CLR_INVALID_win != SetBkColor_win(
object_->hdc,
Color_fromRgb(CAST(uint8_t, red),
CAST(uint8_t, green),
CAST(uint8_t, blue))), UID(E88D53));
OS_VERIFY(ExtTextOut_win(
object_->hdc,
0, 0, ETO_OPAQUE_win, &rect, NULL, 0, NULL), UID(E87483));
red += grow_red;
green += grow_green;
blue += grow_blue;
}
#endif /* PLATFORM_WIN32 */
RETURN(NIL);
} /* _gradient_fill */
#if PLATFORM_WIN32
static HBRUSH_win _set_brush( const canvas_t* object_ ) { /*F*/
GO (UID(F9FE59));
const HBRUSH_win ret =
CAST(HBRUSH_win, SelectObject_win(
object_->hdc, GetStockObject_win(_DC_BRUSH)));
OS_VERIFY(HGDI_ERROR_win != ret, UID(E89D6E));
OS_VERIFY(CLR_INVALID_win != SetDCBrushColor_win(
object_->hdc, Color_rgb(object_->color)), UID(E3ECDE));
RETURN(ret);
} /* _set_brush */
#endif /* PLATFORM_WIN32 */
/* Private: create a new pen and select it into object_->hdc. */
/* Call with make_pen_ = false to destroy the */
/* previously-created pen, without creating any new one. */
static void _make_pen( /*F*/
canvas_t* object_, /*-*/
const bool make_pen_ ) { /*-*/
GO (UID(FB481B));
#if PLATFORM_LINUX
IMPLEMENT_LINUX(); /* TODO: implement _make_pen() on Linux */
UNUSED(object_);
UNUSED(make_pen_);
#endif /* PLATFORM_LINUX */
#if PLATFORM_WIN32
static HPEN_win static_old_pen = NULL;
HPEN_win new_pen = NULL;
HPEN_win old_pen = NULL;
/* create and select a new pen */
if (make_pen_) {
new_pen = CreatePen_win(
PS_SOLID_win, /* pen style */
CAST(int, object_->line_width), /* pen width */
Color_rgb(object_->color)); /* pen color */
OS_VERIFY(new_pen != NULL, UID(EFBC40));
if (new_pen) {
old_pen = CAST(HPEN_win, SelectObject_win(object_->hdc, new_pen));
}
}
/* destroy the old pen */
if (static_old_pen != NULL &&
(!make_pen_ || (make_pen_ && new_pen != NULL &&
old_pen == static_old_pen))) {
OS_VERIFY(DeleteObject_win(static_old_pen), UID(ECE113));
static_old_pen = NULL;
}
/* remember the handle of the pen */
if (new_pen) {
static_old_pen = new_pen;
}
#endif /* PLATFORM_WIN32 */
RETURN(NIL);
} /* _make_pen */
/* -------------------------------------------------------------------------- */
/* Temporary Stubs: */
#if defined _MSC_VER
#pragma warning (push)
#pragma warning (disable:4100) /* W:L4 unreferenced formal parameter */
#endif
PUBLIC void Rect_setSize( /*M*/
rect_t* object_, /*-*/
const pixel_t width_, /*-*/
const pixel_t height_ ) { /*-*/
GO (UID(FCB19D));
UNUSED(object_);
UNUSED(width_);
UNUSED(height_);
/* TODO: implement Rect_setSize() */
RETURN(NIL);
} /* Rect_setSize */
PUBLIC void Rect_clear( rect_t* object_ ) { /*M*/
GO (UID(FF0F2E));
UNUSED(object_);
/* TODO: implement Rect_clear() */
RETURN(NIL);
} /* Rect_clear */
PUBLIC pixel_t Rect_x2( const rect_t* object_ ) { /*M*/
GO (UID(F25108));
UNUSED(object_);
RETURN(0); /* TODO: implement Rect_x2() */
} /* Rect_x2 */
PUBLIC pixel_t Rect_y2( const rect_t* object_ ) { /*M*/
GO (UID(F26017));
UNUSED(object_);
RETURN(0); /* TODO: implement Rect_y2() */
} /* Rect_y2 */
PUBLIC void Canvas_fontSet( /*M*/
CanvasFont* object_, /*-*/
const CanvasFont* font_ ) { /*-*/
GO (UID(FB997A));
UNUSED(object_);
UNUSED(font_);
/* TODO: implement Canvas_fontSet() */
RETURN(NIL);
} /* Canvas_fontSet */
PUBLIC void Canvas_fontSet7( /*M*/
CanvasFont* object_, /*-*/
chars_t font_name_, /*-*/
const int font_size_, /*-*/
const bool bold_, /*-*/
const bool italic_, /*-*/
const bool underline_, /*-*/
const bool strikeout_, /*-*/
const int angle_ ) { /*-*/
GO (UID(F18BDE));
UNUSED(object_);
UNUSED(font_name_);
UNUSED(font_size_);
UNUSED(bold_);
UNUSED(italic_);
UNUSED(underline_);
UNUSED(strikeout_);
UNUSED(angle_);
/* TODO: implement Canvas_fontSet7() */
RETURN(NIL);
} /* Canvas_fontSet7 */
PUBLIC int Poly_count( const poly_t* object_ ) { /*P*/
GO (UID(FEF863));
UNUSED(object_);
RETURN(0); /* TODO: implement Poly_count() */
} /* Poly_count */
#if PLATFORM_WIN32
PUBLIC HFONT_win Canvas_fontHfont( CanvasFont* object_ ) { /*P*/
GO (UID(FF7EA0));
RETURN(0); /* TODO: implement Canvas_fontHfont() */
} /* Canvas_fontHfont */
#endif /* PLATFORM_WIN32 */
#if defined _MSC_VER
#pragma warning (pop)
#endif
/* -------------------------------------------------------------------------- */
/* Constructors / Destructor: */
PUBLIC canvas_t Canvas_init( void ) { /*C*/
GO (UID(F75581));
canvas_t ret;
CLEAR(ret);
ret.area.x = 0;
ret.area.y = 0;
ret.area.width = 0;
ret.area.height = 0;
ret.line_width = 1;
ret.color = COLOR_BLACK;
MEMCPY(ret.font.name, _T("Arial"), 6 * sizeof(char_t));
ret.font.size = 9;
ret.font.bold = false;
ret.font.italic = false;
ret.font.underline = false;
ret.font.strikeout = false;
ret.font.angle = 0;
ret.attached_canvas = false;
ret.is_clipped = false;
ret.is_offscreen = false;
ret.memory_prepared = false;
#if PLATFORM_WIN32
ret.old_map_mode = 0;
ret.old_bk_mode = 0;
ret.old_pen = NULL;
ret.main_dc = NULL;
ret.mem_dc = NULL;
ret.hdc = NULL;
ret.old_clip_region = NULL;
ret.mem_bitmap = NULL;
ret.old_mem_bitmap = NULL;
#endif
RETURN(ret);
} /* Canvas_init */
PUBLIC canvas_t Canvas_initCopy( const canvas_t* canvas_ ) { /*C*/
GO (UID(F9FF80));
canvas_t ret = Canvas_init();
Canvas_set(&ret, canvas_);
RETURN(ret);
} /* Canvas_initCopy */
PUBLIC canvas_t Canvas_initCopyAndPosition( /*C*/
const canvas_t* canvas_, /*-*/
const rect_t rectangle_ ) { /*-*/
GO (UID(F69F31));
canvas_t ret = Canvas_init();
Canvas_set(&ret, canvas_);
ret.area = rectangle_;
RETURN(ret);
} /* Canvas_initCopyAndPosition */
/* Constructor */
#if PLATFORM_WIN32
PUBLIC canvas_t Canvas_fromDC( const HDC_win hdc_ ) { /*C*/
GO (UID(FE6A50));
canvas_t ret = Canvas_init();
Canvas_attachToDC(&ret, hdc_, true);
RETURN(ret);
} /* Canvas_fromDC */
#endif /* PLATFORM_WIN32 */
PUBLIC void Canvas_free( canvas_t* object_ ) { /*D*/
GO (UID(F146CF));
if (object_->is_offscreen) {
object_->is_offscreen = false;
Canvas_endBuffering(object_);
}
_make_pen(object_, false);
if (object_->attached_canvas) {
RETURN(NIL);
} else {
#if PLATFORM_WIN32
_ASSERT_DC;
OS_VERIFY(SetMapMode_win(object_->main_dc, object_->old_map_mode),
UID(EFE5E8));
OS_VERIFY(SetBkMode_win(object_->main_dc, object_->old_bk_mode),
UID(E62854));
OS_VERIFY(SelectObject_win(object_->main_dc, object_->old_pen),
UID(EF95FA));
#endif /* PLATFORM_WIN32 */
}
RETURN(NIL);
} /* Canvas_free */
/* -------------------------------------------------------------------------- */
/* Operators: */
PUBLIC canvas_t* Canvas_opAssign( /*O*/
canvas_t* object_, /*-*/
const canvas_t* copy_from_ ) { /*-*/
GO (UID(FEEDE9));
CHECK_FOR_NULL_OBJECT(object_, UID(E2C083));
object_->attached_canvas = copy_from_->attached_canvas;
object_->is_clipped = copy_from_->is_clipped;
object_->is_offscreen = copy_from_->is_offscreen;
object_->memory_prepared = copy_from_->memory_prepared;
#if PLATFORM_WIN32
object_->old_map_mode = copy_from_->old_map_mode;
object_->old_bk_mode = copy_from_->old_bk_mode;
object_->old_pen = copy_from_->old_pen;
object_->main_dc = copy_from_->main_dc;
object_->mem_dc = copy_from_->mem_dc;
object_->hdc = copy_from_->hdc;
object_->old_clip_region = copy_from_->old_clip_region;
object_->mem_bitmap = copy_from_->mem_bitmap;
object_->old_mem_bitmap = copy_from_->old_mem_bitmap;
#endif
RETURN(object_);
} /* Canvas_opAssign */
/* -------------------------------------------------------------------------- */
/* Methods: */
PUBLIC void Canvas_set( /*M*/
canvas_t* object_, /*-*/
const canvas_t* canvas_ ) { /*-*/
GO (UID(F38BCE));
object_->line_width = canvas_->line_width;
object_->color = canvas_->color;
object_->font = canvas_->font;
object_->is_clipped = canvas_->is_clipped;
object_->is_offscreen = canvas_->is_offscreen;
object_->memory_prepared = canvas_->memory_prepared;
#if PLATFORM_WIN32
object_->old_clip_region = canvas_->old_clip_region;
object_->old_map_mode = canvas_->old_map_mode;
object_->old_bk_mode = canvas_->old_bk_mode;
object_->old_pen = canvas_->old_pen;
#endif /* PLATFORM_WIN32 */
RETURN(NIL);
} /* Canvas_set */
PUBLIC canvas_t* Canvas_screen( void ) { /*F*/
GO (UID(F78455));
static canvas_t canvas;
#if PLATFORM_WIN32
const HDC_win screen_dc = GetDC_win(NULL);
Canvas_attachToDC(&canvas, screen_dc, false);
#endif /* PLATFORM_WIN32 */
RETURN(&canvas);
} /* Canvas_screen */
PUBLIC void Canvas_attachTo( /*M*/
canvas_t* object_, /*-*/
const canvas_t* canvas_, /*-*/
const bool resize_ ) { /*-*/
GO (UID(F284E2));
if (resize_) {
object_->area.x = canvas_->area.x;
object_->area.y = canvas_->area.y;
object_->area.width = canvas_->area.width;
object_->area.height = canvas_->area.height;
}
#if PLATFORM_WIN32
Canvas_attachToDC(object_, canvas_->hdc, false);
object_->attached_canvas = true;
#endif /* PLATFORM_WIN32 */
RETURN(NIL);
} /* Canvas_attachTo */
#if PLATFORM_WIN32
PUBLIC void Canvas_attachToDC( /*M*/
canvas_t* object_, /*-*/
const HDC_win hdc_, /*-*/
const bool resize_ ) { /*-*/
GO (UID(F6BCE0));
object_->main_dc = object_->hdc = hdc_;
if (hdc_ == NULL) {
object_->old_map_mode = 0;
object_->old_bk_mode = 0;
object_->old_pen = NULL;
_make_pen(object_, false);
} else {
object_->old_map_mode = SetMapMode_win(object_->main_dc, MM_TEXT_win);
OS_VERIFY(object_->old_map_mode, UID(EB1253));
object_->old_bk_mode = SetBkMode_win(object_->main_dc, TRANSPARENT_win);
OS_VERIFY(object_->old_bk_mode, UID(E6E1A1));
object_->old_pen = CAST(HPEN_win, SelectObject_win(
object_->hdc,
GetStockObject_win(_DC_PEN)));
OS_VERIFY(object_->old_pen, UID(E29E51));
_make_pen(object_, true);
}
if (resize_) {
Canvas_resize(object_);
}
RETURN(NIL);
} /* Canvas_attachToDC */
#endif /* PLATFORM_WIN32 */
PUBLIC void Canvas_detach( canvas_t* object_ ) { /*M*/
GO (UID(F72F79));
#if PLATFORM_LINUX
IMPLEMENT_LINUX(); /* TODO: implement Canvas_detach() on Linux */
UNUSED(object_);
#endif /* PLATFORM_LINUX */
#if PLATFORM_WIN32
_ASSERT_DC;
_make_pen(object_, false);
OS_VERIFY(SetMapMode_win(object_->main_dc, object_->old_map_mode),
UID(E6C7DD));
OS_VERIFY(SetBkMode_win(object_->main_dc, object_->old_bk_mode),
UID(EE5BA6));
OS_VERIFY(SelectObject_win(object_->main_dc, object_->old_pen),
UID(EBAB87));
#endif /* PLATFORM_WIN32 */
RETURN(NIL);
} /* Canvas_detach */
PUBLIC void Canvas_resize( canvas_t* object_ ) { /*M*/
GO (UID(FEC70A));
#if PLATFORM_LINUX
IMPLEMENT_LINUX(); /* TODO: implement Canvas_resize() on Linux */
UNUSED(object_);
#endif /* PLATFORM_LINUX */
#if PLATFORM_WIN32
HWND_win hwnd = NULL;
/* get the dimensions of the window's client area */
/* (if DC is not a memory DC) */
Rect_clear(&object_->area);
hwnd = WindowFromDC_win(object_->main_dc);
if (hwnd != NULL) {
RECT_win rect;
OS_VERIFY(GetClientRect_win(hwnd, &rect), UID(E7561D));
Rect_setSize(&object_->area, rect.right, rect.bottom);
}
#endif /* PLATFORM_WIN32 */
RETURN(NIL);
} /* Canvas_resize */
#if defined UNIMPLEMENTED
PUBLIC void Canvas_clipRect( /*M*/
canvas_t* object_, /*-*/
const pixel_t x_, /*-*/
const pixel_t y_, /*-*/
const pixel_t width_, /*-*/
const pixel_t height_ ) { /*-*/
GO (UID(F544EB));
UNUSED(x_);
UNUSED(y_);
UNUSED(width_);
UNUSED(height_);
/* TODO: implement clip_rect() */
RETURN(NIL);
} /* Canvas_clipRect */
#endif /* UNIMPLEMENTED */
#if 111
PUBLIC void Canvas_clip( canvas_t* object_ ) { /*M*/
GO (UID(F82F0D));
#if PLATFORM_LINUX
IMPLEMENT_LINUX(); /* TODO: implement Canvas_clip() on Linux */
UNUSED(object_);
#endif /* PLATFORM_LINUX */
#if PLATFORM_WIN32
_ASSERT_DC;
object_->old_clip_region = clip_rect(object_->hdc,
object_->area.x,
object_->area.y,
Rect_x2(&object_->area),
Rect_y2(&object_->area),
true);
object_->is_clipped = true;
#endif /* PLATFORM_WIN32 */
RETURN(NIL);
} /* Canvas_clip */
#endif /* 111 */
PUBLIC void Canvas_unclip( canvas_t* object_ ) { /*M*/
GO (UID(F52BA7));
#if PLATFORM_LINUX
IMPLEMENT_LINUX(); /* TODO: implement Canvas_unclip() on Linux */
UNUSED(object_);
#endif /* PLATFORM_LINUX */
#if PLATFORM_WIN32
_ASSERT_DC;
if (!object_->is_clipped) {
RETURN(NIL);
}
free_clipping_rect(object_->hdc, object_->old_clip_region);
object_->is_clipped = false;
#endif /* PLATFORM_WIN32 */
RETURN(NIL);
} /* Canvas_unclip */
/* -------------------------------------------------------------------------- */
/* Properties: Canvas Interface */
PUBLIC pixel_t Canvas_x( const canvas_t* object_ ) { /*P*/
GO (UID(F7973B));
const pixel_t ret = object_->area.x;
RETURN(ret);
} /* Canvas_x */
PUBLIC pixel_t Canvas_y( const canvas_t* object_ ) { /*P*/
GO (UID(FC659E));
const pixel_t ret = object_->area.y;
RETURN(ret);
} /* Canvas_y */
PUBLIC pixel_t Canvas_width( const canvas_t* object_ ) { /*P*/
GO (UID(F60967));
const pixel_t ret = object_->area.width;
RETURN(ret);
} /* Canvas_width */
PUBLIC pixel_t Canvas_height( const canvas_t* object_ ) { /*P*/
GO (UID(F4AF43));
const pixel_t ret = object_->area.height;
RETURN(ret);
} /* Canvas_height */
PUBLIC pixel_t Canvas_x2( const canvas_t* object_ ) { /*P*/
GO (UID(F34C9F));
const pixel_t ret = Rect_x2(&object_->area);
RETURN(ret);
} /* Canvas_x2 */
PUBLIC pixel_t Canvas_y2( const canvas_t* object_ ) { /*P*/
GO (UID(FE7A77));
const pixel_t ret = Rect_y2(&object_->area);
RETURN(ret);
} /* Canvas_y2 */
/* -------------------------------------------------------------------------- */
/* Methods: Canvas Interface */
PUBLIC void Canvas_clear( /*M*/
canvas_t* object_, /*-*/
const color_t color_ ) { /*-*/
GO (UID(F80B08));
const color_t null = COLOR_NULL;
_SET_COLOR(object_, color_);
Canvas_rectFill(object_, object_->area, null, SHADE_SOLID, null);
RETURN(NIL);
} /* Canvas_clear */
PUBLIC void Canvas_beginBuffering( canvas_t* object_ ) { /*M*/
GO (UID(F0D9D6));
#if PLATFORM_LINUX
IMPLEMENT_LINUX();
UNUSED(object_);
/* TODO: implement Canvas_beginBuffering() on Linux */
#endif /* PLATFORM_LINUX */
#if PLATFORM_WIN32
if (!object_->memory_prepared) {
object_->mem_dc = CreateCompatibleDC_win(object_->main_dc);
OS_VERIFY(object_->mem_dc, UID(E9BA32));
object_->mem_bitmap = CreateCompatibleBitmap_win(
object_->main_dc,
CAST(int, object_->area.width),
CAST(int, object_->area.height));
OS_VERIFY(object_->mem_bitmap, UID(ED41B8));
object_->old_mem_bitmap =
CAST(HBITMAP_win, SelectObject_win(object_->mem_dc,
object_->mem_bitmap));
OS_VERIFY(object_->old_mem_bitmap != HGDI_ERROR_win, UID(E97F6B));
OS_VERIFY(SetMapMode_win(object_->mem_dc,
GetMapMode_win(object_->main_dc)),
UID(E1D804));
OS_VERIFY(SetWindowOrgEx_win(object_->mem_dc,
CAST(int, object_->area.x),
CAST(int, object_->area.y),
NULL), UID(E9F4A1));
object_->memory_prepared = true;
}
object_->hdc = object_->mem_dc;
object_->is_offscreen = true;
#endif /* PLATFORM_WIN32 */
RETURN(NIL);
} /* Canvas_beginBuffering */
PUBLIC void Canvas_endBuffering( canvas_t* object_ ) { /*M*/
GO (UID(F605D0));
#if PLATFORM_LINUX
IMPLEMENT_LINUX();
UNUSED(object_);
/* TODO: implement Canvas_endBuffering() on Linux */
#endif /* PLATFORM_LINUX */
#if PLATFORM_WIN32
if (object_->is_offscreen) {
OS_VERIFY(BitBlt_win(object_->main_dc,
CAST(int, object_->area.x),
CAST(int, object_->area.y),
CAST(int, object_->area.width),
CAST(int, object_->area.height),
object_->mem_dc,
CAST(int, object_->area.x),
CAST(int, object_->area.y),
SRCCOPY_win), UID(E49256));
object_->is_offscreen = false;
}
OS_VERIFY(HGDI_ERROR_win != SelectObject_win(
object_->mem_dc, object_->old_mem_bitmap), UID(E06DCE));
object_->old_mem_bitmap = NULL;
if (object_->mem_bitmap) {
OS_VERIFY(DeleteObject_win(object_->mem_bitmap), UID(E1A17F));
}
object_->memory_prepared = false;
object_->hdc = object_->main_dc;
#endif /* PLATFORM_WIN32 */
RETURN(NIL);
} /* Canvas_endBuffering */
/* Current settings */
PUBLIC void Canvas_area( /*M*/
canvas_t* object_, /*-*/
const rect_t rect_ ) { /*-*/
GO (UID(F261C0));
object_->area = rect_;
RETURN(NIL);
} /* Canvas_area */
PUBLIC void Canvas_lineWidth( /*M*/
canvas_t* object_, /*-*/
const pixel_t line_width_ ) { /*-*/
GO (UID(F77C89));
object_->line_width = line_width_;
#if PLATFORM_WIN32
if (object_->hdc != NULL) {
_make_pen(object_, true);
}
#endif
RETURN(NIL);
} /* Canvas_lineWidth */
PUBLIC void Canvas_color( /*M*/
canvas_t* object_, /*-*/
const color_t color_ ) { /*-*/
GO (UID(F77CA2));
object_->color = color_;
#if PLATFORM_WIN32
if (object_->hdc != NULL) {
color_t rgb = Color_rgb(object_->color);
OS_VERIFY(CLR_INVALID_win != SetTextColor_win(object_->hdc, rgb),
UID(EFBFD3));
_make_pen(object_, true);
}
#endif /* PLATFORM_WIN32 */
RETURN(NIL);
} /* Canvas_color */
PUBLIC void Canvas_font( /*M*/
canvas_t* object_, /*-*/
const CanvasFont* font_ ) { /*-*/
GO (UID(F6CCFF));
Canvas_fontSet(&object_->font, font_);
RETURN(NIL);
} /* Canvas_font */
PUBLIC void Canvas_font7( /*M*/
canvas_t* object_, /*-*/
chars_t font_name_, /*-*/
const int font_size_, /*-*/
const bool bold_, /*-*/
const bool italic_, /*-*/
const bool underline_, /*-*/
const bool strikeout_, /*-*/
const int angle_ ) { /*-*/
GO (UID(FBAC1D));
Canvas_fontSet7(&object_->font, font_name_, font_size_,
bold_, italic_, underline_, strikeout_, angle_);
RETURN(NIL);
} /* Canvas_font */
/* point */
PUBLIC void Canvas_point( /*M*/
canvas_t* object_, /*-*/
const pixel_t x_, /*-*/
const pixel_t y_, /*-*/
const color_t color_ ) { /*-*/
GO (UID(F01120));
#if PLATFORM_LINUX
IMPLEMENT_LINUX(); /* TODO: implement Canvas_point() on Linux */
UNUSED(object_);
UNUSED(x_);
UNUSED(y_);
UNUSED(color_);
#endif /* PLATFORM_LINUX */
#if PLATFORM_WIN32
_INIT_XY;
_ASSERT_DC;
_SET_COLOR(object_, color_);
OS_VERIFY(MoveToEx_win(object_->hdc,
CAST(int, x), CAST(int, y), NULL), UID(EAE31E));
OS_VERIFY(LineTo_win(object_->hdc,
CAST(int, x + 1), CAST(int, y + 1)), UID(E9F7AC));
#endif /* PLATFORM_WIN32 */
RETURN(NIL);
} /* Canvas_point */
/* line */
PUBLIC void Canvas_line( /*M*/
canvas_t* object_, /*-*/