-
Notifications
You must be signed in to change notification settings - Fork 1
/
UG.PAS
2643 lines (2422 loc) · 71.3 KB
/
UG.PAS
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
(* Original C code license *)
(* -------------------------------------------------------------------------------- *)
(* -- µGUI - Generic GUI module (C)Achim Döbler, 2015 -- *)
(* -------------------------------------------------------------------------------- *)
(* µGUI is a generic GUI module for embedded systems. *)
(* This is a free software that is open for education, research and commercial *)
(* developments under license policy of following terms. *)
(**)
(* Copyright (C) 2015, Achim Döbler, all rights reserved. *)
(* URL: http://www.embeddedlightning.com/ *)
(**)
(* * The µGUI module is a free software and there is NO WARRANTY. *)
(* * No restriction on use. You can use, modify and redistribute it for *)
(* personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY. *)
(* * Redistributions of source code must retain the above copyright notice. *)
(**)
(* -------------------------------------------------------------------------------- *)
(* -- MY SPECIAL THANKS GO TO -- *)
(* -------------------------------------------------------------------------------- *)
(* Andrey Filimonov (-->https://github.com/Sermus)*)
(* for giving valuable suggestions, reporting bugs and adding several new features. *)
(* Andrey also put a lot of work in the implementaion of anti-aliased font support. *)
(**)
(* Mikhail Podkur (-->https://github.com/MikhailPodkur) *)
(* for adding cyrillic 8x12 font, checkbox feature and RGB565 support. *)
(**)
(* Gustavo Denardin *)
(* for giving valuable suggestions regarding real-time os support. *)
(**)
(* Samuel Kleiser *)
(* for reporting bugs and giving examples how to improve µGUI. *)
(* -------------------------------------------------------------------------------- *)
(* -- REVISION HISTORY -- *)
(* -------------------------------------------------------------------------------- *)
(* Dec 20, 2015 V0.31 Checkbox component with all funtions added. *)
(* Cyrillic font 8x12 added. *)
(* RGB565 color schema added. *)
(* Windows components font could be getted from current GUI
by default *)
(* Mar 18, 2015 V0.3 Driver support added. *)
(* Window and object support added. *)
(* Touch support added. *)
(* Fixed some minor bugs. *)
(**)
(* Oct 20, 2014 V0.2 Function UG_DrawRoundFrame() added. *)
(* Function UG_FillRoundFrame() added. *)
(* Function UG_DrawArc() added. *)
(* Fixed some minor bugs. *)
(**)
(* Oct 11, 2014 V0.1 First release. *)
(* -------------------------------------------------------------------------------- *)
(* Pascal Port (C) Ioulianos Kakoulidis *)
unit UG;
{$ifdef FPC}{$mode tp}{$endif}
{$ifdef VER70}{$X+}{$endif}
{$I UG_CFG.inc}
interface
uses UG_FONTS, UG_TYPES
{$ifndef EMBEDDED}
{$ifdef FPC}, SysUtils (* Delay func *){$endif}
{$endif};
const
UG_VERSION = '0.1';
{$I UG_CLR.INC}
(* Alignments *)
ALIGN_H_LEFT = 1 shl 0;
ALIGN_H_CENTER = 1 shl 1;
ALIGN_H_RIGHT = 1 shl 2;
ALIGN_V_TOP = 1 shl 3;
ALIGN_V_CENTER = 1 shl 4;
ALIGN_V_BOTTOM = 1 shl 5;
ALIGN_BOTTOM_RIGHT = ALIGN_V_BOTTOM or ALIGN_H_RIGHT;
ALIGN_BOTTOM_CENTER = ALIGN_V_BOTTOM or ALIGN_H_CENTER;
ALIGN_BOTTOM_LEFT = ALIGN_V_BOTTOM or ALIGN_H_LEFT;
ALIGN_CENTER_RIGHT = ALIGN_V_CENTER or ALIGN_H_RIGHT;
ALIGN_CENTER = ALIGN_V_CENTER or ALIGN_H_CENTER;
ALIGN_CENTER_LEFT = ALIGN_V_CENTER or ALIGN_H_LEFT;
ALIGN_TOP_RIGHT = ALIGN_V_TOP or ALIGN_H_RIGHT;
ALIGN_TOP_CENTER = ALIGN_V_TOP or ALIGN_H_CENTER;
ALIGN_TOP_LEFT = ALIGN_V_TOP or ALIGN_H_LEFT;
(* Default IDs *)
OBJ_ID_0 = 0;
OBJ_ID_1 = 1;
OBJ_ID_2 = 2;
OBJ_ID_3 = 3;
OBJ_ID_4 = 4;
OBJ_ID_5 = 5;
OBJ_ID_6 = 6;
OBJ_ID_7 = 7;
OBJ_ID_8 = 8;
OBJ_ID_9 = 9;
OBJ_ID_10 = 10;
OBJ_ID_11 = 11;
OBJ_ID_12 = 12;
OBJ_ID_13 = 13;
OBJ_ID_14 = 14;
OBJ_ID_15 = 15;
OBJ_ID_16 = 16;
OBJ_ID_17 = 17;
OBJ_ID_18 = 18;
OBJ_ID_19 = 19;
(*
RESULT_FAIL = -1;
RESULT_OK = 0;
*)
(*
MSG_TYPE_NONE = 0;
MSG_TYPE_WINDOW = 1;
MSG_TYPE_OBJECT = 2;
*)
TOUCH_STATE_PRESSED = 1;
TOUCH_STATE_RELEASED = 0;
(*
OBJ_TYPE_NONE = 0;
OBJ_TYPE_BUTTON = 1;
OBJ_TYPE_TEXTBOX = 2;
OBJ_TYPE_IMAGE = 3;
OBJ_TYPE_CHECKBOX = 4;
*)
(* Standard object events *)
OBJ_EVENT_NONE = 0;
OBJ_EVENT_CLICKED = 1;
{$ifdef USE_PRERENDER_EVENT}
OBJ_EVENT_PRERENDER = 2;
{$endif}
{$ifdef USE_POSTRENDER_EVENT}
OBJ_EVENT_POSTRENDER = 3;
{$endif}
OBJ_EVENT_PRESSED = 4;
OBJ_EVENT_RELEASED = 5;
(* Object states *)
OBJ_STATE_FREE = 1 shl 0;
OBJ_STATE_VALID = 1 shl 1;
OBJ_STATE_BUSY = 1 shl 2;
OBJ_STATE_VISIBLE = 1 shl 3;
OBJ_STATE_ENABLE = 1 shl 4;
OBJ_STATE_UPDATE = 1 shl 5;
OBJ_STATE_REDRAW = 1 shl 6;
OBJ_STATE_TOUCH_ENABLE = 1 shl 7;
OBJ_STATE_INIT = OBJ_STATE_FREE or OBJ_STATE_VALID;
(* Object touch states *)
OBJ_TOUCH_STATE_CHANGED = 1 shl 0;
OBJ_TOUCH_STATE_PRESSED_ON_OBJECT = 1 shl 1;
OBJ_TOUCH_STATE_PRESSED_OUTSIDE_OBJECT = 1 shl 2;
OBJ_TOUCH_STATE_RELEASED_ON_OBJECT = 1 shl 3;
OBJ_TOUCH_STATE_RELEASED_OUTSIDE_OBJECT = 1 shl 4;
OBJ_TOUCH_STATE_IS_PRESSED_ON_OBJECT = 1 shl 5;
OBJ_TOUCH_STATE_IS_PRESSED = 1 shl 6;
OBJ_TOUCH_STATE_CLICK_ON_OBJECT = 1 shl 7;
OBJ_TOUCH_STATE_INIT = 0;
(* Window states *)
WND_STATE_FREE = 1 shl 0;
WND_STATE_VALID = 1 shl 1;
WND_STATE_BUSY = 1 shl 2;
WND_STATE_VISIBLE = 1 shl 3;
WND_STATE_ENABLE = 1 shl 4;
WND_STATE_UPDATE = 1 shl 5;
WND_STATE_REDRAW_TITLE = 1 shl 6;
(* Window styles *)
WND_STYLE_2D = 0 shl 0;
WND_STYLE_3D = 1 shl 0;
WND_STYLE_HIDE_TITLE = 0 shl 1;
WND_STYLE_SHOW_TITLE = 1 shl 1;
UG_SATUS_WAIT_FOR_UPDATE = 1 shl 0;
DRIVER_REGISTERED = 1 shl 0;
DRIVER_ENABLED = 1 shl 1;
(* Supported drivers *)
NUMBER_OF_DRIVERS = 3;
DRIVER_DRAW_LINE = 0;
DRIVER_FILL_FRAME = 1;
DRIVER_FILL_AREA = 2;
type
{ UG_RESULT = UG_S8; }
UG_RESULT = (RESULT_OK, RESULT_FAIL);
PUG_COLOR = ^UG_COLOR;
{$ifdef USE_COLOR_RGB888}
UG_COLOR = UG_U32;
{$endif}
{$ifdef USE_COLOR_RGB565}
UG_COLOR = UG_U16;
{$endif}
PUG_OBJECT = ^UG_OBJECT;
PUG_WINDOW = ^UG_WINDOW;
(* -------------------------------------------------------------------------- *)
(* -- UNIVERSAL STRUCTURES -- *)
(* -------------------------------------------------------------------------- *)
(* Area structure *)
UG_AREA = record
xs: UG_S16;
ys: UG_S16;
xe: UG_S16;
ye: UG_S16;
end;
(* Text structure *)
PUG_TEXT = ^UG_TEXT;
UG_TEXT = record
str: PChar;
font: PUG_FONT;
a: UG_AREA;
fc: UG_COLOR;
bc: UG_COLOR;
align: UG_U8;
h_space: UG_S16;
v_space: UG_S16;
end;
UG_MSG_TYPE = (MSG_TYPE_NONE, MSG_TYPE_WINDOW, MSG_TYPE_OBJECT);
UG_OBJ_TYPE = (OBJ_TYPE_NONE, OBJ_TYPE_BUTTON, OBJ_TYPE_TEXTBOX,
OBJ_TYPE_IMAGE, OBJ_TYPE_CHECKBOX);
(* -------------------------------------------------------------------------------- *)
(* -- MESSAGE -- *)
(* -------------------------------------------------------------------------------- *)
(* Message structure *)
PUG_MESSAGE = ^UG_MESSAGE;
UG_MESSAGE = record
mtype: UG_MSG_TYPE;
id: UG_U8;
sub_id: UG_U8;
event: UG_U8;
//src: PUG_U8;
src: Pointer;
end;
(* -------------------------------------------------------------------------------- *)
(* -- TOUCH -- *)
(* -------------------------------------------------------------------------------- *)
(* Touch structure *)
UG_TOUCH = record
state: UG_U8;
xp: UG_S16;
yp: UG_S16;
end;
(* -------------------------------------------------------------------------------- *)
(* -- OBJECTS -- *)
(* -------------------------------------------------------------------------------- *)
(* Object structure *)
PUG_CALLBACK = ^UG_CALLBACK;
UG_CALLBACK = procedure(w: PUG_WINDOW; o: PUG_OBJECT);
S_OBJECT = record
state: UG_U8; (* object state *)
touch_state: UG_U8; (* object touch state *)
update: UG_CALLBACK; (* pointer to object-specific update function *)
a_abs: UG_AREA; (* absolute area of the object *)
a_rel: UG_AREA; (* relative area of the object *)
otype: UG_OBJ_TYPE; (* object type *)
id: UG_U8; (* object ID *)
event: UG_U8; (* object-specific events *)
Data: PUG_U8; (* pointer to object-specific data *)
end;
UG_OBJECT = S_OBJECT;
(* Currently supported objects *)
(* ------------------------------------------------------------------------ *)
(* -- WINDOW -- *)
(* ------------------------------------------------------------------------ *)
(* Title structure *)
UG_TITLE = record
str: PChar;
font: PUG_FONT;
h_space: UG_S8;
v_space: UG_S8;
align: UG_U8;
fc: UG_COLOR;
bc: UG_COLOR;
ifc: UG_COLOR;
ibc: UG_COLOR;
Height: UG_U8;
end;
(* Window structure *)
UG_WINDOW_CB = procedure(msg: PUG_MESSAGE);
S_WINDOW = record
objcnt: UG_U8;
objlst: PUG_OBJECT;
state: UG_U8;
fc: UG_COLOR;
bc: UG_COLOR;
xs: UG_S16;
ys: UG_S16;
xe: UG_S16;
ye: UG_S16;
style: UG_U8;
title: UG_TITLE;
cb: UG_WINDOW_CB;
end;
UG_WINDOW = S_WINDOW;
(* -------------------------------------------------------------------------- *)
(* -- µGUI DRIVER -- *)
(* -------------------------------------------------------------------------- *)
type
UG_DRIVER = record
driver: Pointer;
state: UG_U8;
end;
(* ------------------------------------------------------------------------ *)
(* -- µGUI CORE STRUCTURE -- *)
(* ------------------------------------------------------------------------ *)
PUG_PSET = ^UG_PSET;
UG_PSET = procedure(x, y: UG_S16; c: UG_COLOR);
_HW_DRAWLINE = function(x1, y1: UG_S16; x2, y2: UG_S16; c: UG_COLOR): UG_RESULT;
_HW_FILLFRAME = function(x1, y1: UG_S16; x2, y2: UG_S16; c: UG_COLOR): UG_RESULT;
UG_CONSOLE = record
x_pos: UG_S16;
y_pos: UG_S16;
x_start: UG_S16;
y_start: UG_S16;
x_end: UG_S16;
y_end: UG_S16;
fore_color: UG_COLOR;
back_color: UG_COLOR;
end;
PUG_GUI = ^UG_GUI;
UG_GUI = record
pset: UG_PSET;
x_dim: UG_S16;
y_dim: UG_S16;
touch: UG_TOUCH;
next_window: PUG_WINDOW;
active_window: PUG_WINDOW;
last_window: PUG_WINDOW;
console: UG_CONSOLE;
font: UG_FONT;
char_h_space: UG_S8;
char_v_space: UG_S8;
fore_color: UG_COLOR;
back_color: UG_COLOR;
desktop_color: UG_COLOR;
state: UG_U8;
driver: array[0..Pred(NUMBER_OF_DRIVERS)] of UG_DRIVER;
end;
(* -------------------------------------------------------------------------- *)
(* -- PROTOTYPES -- *)
(* -------------------------------------------------------------------------- *)
(* Classic functions *)
function UG_Init(var g: UG_GUI; p: UG_PSET; x, y: UG_S16): UG_S16;
function UG_SelectGUI(g: PUG_GUI): UG_S16;
procedure UG_FontSelect(font: PUG_FONT);
procedure UG_FillScreen(c: UG_COLOR);
procedure UG_FillFrame(x1, y1: UG_S16; x2, y2: UG_S16; c: UG_COLOR);
procedure UG_FillRoundFrame(x1, y1: UG_S16; x2, y2: UG_S16; r: UG_S16; c: UG_COLOR);
procedure UG_DrawMesh(x1, y1: UG_S16; x2, y2: UG_S16; c: UG_COLOR);
procedure UG_DrawFrame(x1, y1: UG_S16; x2, y2: UG_S16; c: UG_COLOR);
procedure UG_DrawRoundFrame(x1, y1: UG_S16; x2, y2: UG_S16; r: UG_S16; c: UG_COLOR);
procedure UG_DrawPixel(x0, y0: UG_S16; c: UG_COLOR);
procedure UG_DrawCircle(x0, y0: UG_S16; r: UG_S16; c: UG_COLOR);
procedure UG_FillCircle(x0, y0: UG_S16; r: UG_S16; c: UG_COLOR);
procedure UG_DrawArc(x0, y0: UG_S16; r: UG_S16; s: UG_U8; c: UG_COLOR);
procedure UG_DrawHLine(x1, x2, y: UG_S16; c: UG_COLOR);
procedure UG_DrawVLine(y1, y2, x: UG_S16; c: UG_COLOR);
procedure UG_DrawLine(x1, y1: UG_S16; x2, y2: UG_S16; c: UG_COLOR);
procedure UG_PutString(x, y: UG_S16; str: PChar);
procedure UG_PutChar(chr: char; x, y: UG_S16; fc, bc: UG_COLOR);
procedure UG_SetForecolor(c: UG_COLOR);
procedure UG_SetBackcolor(c: UG_COLOR);
function UG_GetXDim: UG_S16;
function UG_GetYDim: UG_S16;
procedure UG_FontSetHSpace(s: UG_U16);
procedure UG_FontSetVSpace(s: UG_U16);
(* Console *)
procedure UG_ConsolePutString(str: PChar);
procedure UG_ConsoleSetArea(xs, ys: UG_S16; xe, ye: UG_S16);
procedure UG_ConsoleSetForecolor(c: UG_COLOR);
procedure UG_ConsoleSetBackcolor(c: UG_COLOR);
(* Window functions *)
function UG_WindowCreate(var wnd: UG_WINDOW; objlst: PUG_OBJECT;
objcnt: UG_U8; cb: UG_WINDOW_CB): UG_RESULT;
function UG_WindowDelete(var wnd: UG_WINDOW): UG_RESULT;
function UG_WindowShow(var wnd: UG_WINDOW): UG_RESULT;
function UG_WindowHide(var wnd: UG_WINDOW): UG_RESULT;
function UG_WindowResize(var wnd: UG_WINDOW; xs, ys: UG_S16; xe, ye: UG_S16): UG_RESULT;
function UG_WindowAlert(var wnd: UG_WINDOW): UG_RESULT;
(* Window setters *)
function UG_WindowSetForeColor(var wnd: UG_WINDOW; fc: UG_COLOR): UG_RESULT;
function UG_WindowSetBackColor(var wnd: UG_WINDOW; bc: UG_COLOR): UG_RESULT;
function UG_WindowSetTitleTextColor(var wnd: UG_WINDOW; c: UG_COLOR): UG_RESULT;
function UG_WindowSetTitleColor(var wnd: UG_WINDOW; c: UG_COLOR): UG_RESULT;
function UG_WindowSetTitleInactiveTextColor(var wnd: UG_WINDOW; c: UG_COLOR): UG_RESULT;
function UG_WindowSetTitleInactiveColor(var wnd: UG_WINDOW; c: UG_COLOR): UG_RESULT;
function UG_WindowSetTitleText(var wnd: UG_WINDOW; str: PChar): UG_RESULT;
function UG_WindowSetTitleTextFont(var wnd: UG_WINDOW; font: PUG_FONT): UG_RESULT;
function UG_WindowSetTitleTextHSpace(var wnd: UG_WINDOW; hs: UG_S8): UG_RESULT;
function UG_WindowSetTitleTextVSpace(var wnd: UG_WINDOW; vs: UG_S8): UG_RESULT;
function UG_WindowSetTitleTextAlignment(var wnd: UG_WINDOW; align: UG_U8): UG_RESULT;
function UG_WindowSetTitleHeight(var wnd: UG_WINDOW; Height: UG_U8): UG_RESULT;
function UG_WindowSetXStart(var wnd: UG_WINDOW; xs: UG_S16): UG_RESULT;
function UG_WindowSetYStart(var wnd: UG_WINDOW; ys: UG_S16): UG_RESULT;
function UG_WindowSetXEnd(var wnd: UG_WINDOW; xe: UG_S16): UG_RESULT;
function UG_WindowSetYEnd(var wnd: UG_WINDOW; ye: UG_S16): UG_RESULT;
function UG_WindowSetStyle(var wnd: UG_WINDOW; style: UG_U8): UG_RESULT;
(* Window getters *)
function UG_WindowGetForeColor(const wnd: UG_WINDOW): UG_COLOR;
function UG_WindowGetBackColor(const wnd: UG_WINDOW): UG_COLOR;
function UG_WindowGetTitleTextColor(const wnd: UG_WINDOW): UG_COLOR;
function UG_WindowGetTitleColor(const wnd: UG_WINDOW): UG_COLOR;
function UG_WindowGetTitleInactiveTextColor(const wnd: UG_WINDOW): UG_COLOR;
function UG_WindowGetTitleInactiveColor(const wnd: UG_WINDOW): UG_COLOR;
function UG_WindowGetTitleText(const wnd: UG_WINDOW): PChar;
function UG_WindowGetTitleTextFont(const wnd: UG_WINDOW): PUG_FONT;
function UG_WindowGetTitleTextHSpace(const wnd: UG_WINDOW): UG_S8;
function UG_WindowGetTitleTextVSpace(const wnd: UG_WINDOW): UG_S8;
function UG_WindowGetTitleTextAlignment(const wnd: UG_WINDOW): UG_U8;
function UG_WindowGetTitleHeight(const wnd: UG_WINDOW): UG_U8;
function UG_WindowGetXStart(const wnd: UG_WINDOW): UG_S16;
function UG_WindowGetYStart(const wnd: UG_WINDOW): UG_S16;
function UG_WindowGetXEnd(const wnd: UG_WINDOW): UG_S16;
function UG_WindowGetYEnd(const wnd: UG_WINDOW): UG_S16;
function UG_WindowGetStyle(const wnd: UG_WINDOW): UG_U8;
function UG_WindowGetArea(const wnd: UG_WINDOW; var a: UG_AREA): UG_RESULT;
function UG_WindowGetInnerWidth(const wnd: UG_WINDOW): UG_S16;
function UG_WindowGetOuterWidth(const wnd: UG_WINDOW): UG_S16;
function UG_WindowGetInnerHeight(const wnd: UG_WINDOW): UG_S16;
function UG_WindowGetOuterHeight(const wnd: UG_WINDOW): UG_S16;
{$ifdef UG_USE_BTN}
type
PUG_BUTTON = ^UG_BUTTON;
UG_BUTTON = record
state: UG_U8;
style: UG_U8;
fc: UG_COLOR;
bc: UG_COLOR;
afc: UG_COLOR;
abc: UG_COLOR;
font: PUG_FONT;
align: UG_U8;
h_space: UG_S8;
v_space: UG_S8;
str: PChar;
end;
const
(* Default button IDs *)
BTN_ID_0 = OBJ_ID_0;
BTN_ID_1 = OBJ_ID_1;
BTN_ID_2 = OBJ_ID_2;
BTN_ID_3 = OBJ_ID_3;
BTN_ID_4 = OBJ_ID_4;
BTN_ID_5 = OBJ_ID_5;
BTN_ID_6 = OBJ_ID_6;
BTN_ID_7 = OBJ_ID_7;
BTN_ID_8 = OBJ_ID_8;
BTN_ID_9 = OBJ_ID_9;
BTN_ID_10 = OBJ_ID_10;
BTN_ID_11 = OBJ_ID_11;
BTN_ID_12 = OBJ_ID_12;
BTN_ID_13 = OBJ_ID_13;
BTN_ID_14 = OBJ_ID_14;
BTN_ID_15 = OBJ_ID_15;
BTN_ID_16 = OBJ_ID_16;
BTN_ID_17 = OBJ_ID_17;
BTN_ID_18 = OBJ_ID_18;
BTN_ID_19 = OBJ_ID_19;
(* Button states *)
BTN_STATE_RELEASED = 0 shl 0;
BTN_STATE_PRESSED = 1 shl 0;
BTN_STATE_ALWAYS_REDRAW = 1 shl 1;
(* Button style *)
BTN_STYLE_2D = 0 shl 0;
BTN_STYLE_3D = 1 shl 0;
BTN_STYLE_TOGGLE_COLORS = 1 shl 1;
BTN_STYLE_USE_ALTERNATE_COLORS = 1 shl 2;
BTN_STYLE_NO_BORDERS = 1 shl 3;
BTN_STYLE_NO_FILL = 1 shl 4;
(* Button events *)
BTN_EVENT_CLICKED = OBJ_EVENT_CLICKED;
function UG_ButtonCreate(const wnd: UG_WINDOW; var btn: UG_BUTTON;
id: UG_U8; xs, ys: UG_S16; xe, ye: UG_S16): UG_RESULT;
function UG_ButtonDelete(const wnd: UG_WINDOW; id: UG_U8): UG_RESULT;
function UG_ButtonShow(const wnd: UG_WINDOW; id: UG_U8): UG_RESULT;
function UG_ButtonHide(const wnd: UG_WINDOW; id: UG_U8): UG_RESULT;
function UG_ButtonSetForeColor(const wnd: UG_WINDOW; id: UG_U8; fc: UG_COLOR): UG_RESULT;
function UG_ButtonSetBackColor(const wnd: UG_WINDOW; id: UG_U8; bc: UG_COLOR): UG_RESULT;
function UG_ButtonSetAlternateForeColor(const wnd: UG_WINDOW; id: UG_U8;
afc: UG_COLOR): UG_RESULT;
function UG_ButtonSetAlternateBackColor(const wnd: UG_WINDOW; id: UG_U8;
abc: UG_COLOR): UG_RESULT;
function UG_ButtonSetText(const wnd: UG_WINDOW; id: UG_U8; str: PChar): UG_RESULT;
function UG_ButtonSetFont(const wnd: UG_WINDOW; id: UG_U8; font: PUG_FONT): UG_RESULT;
function UG_ButtonSetStyle(const wnd: UG_WINDOW; id: UG_U8; style: UG_U8): UG_RESULT;
function UG_ButtonSetHSpace(const wnd: UG_WINDOW; id: UG_U8; hs: UG_S8): UG_RESULT;
function UG_ButtonSetVSpace(const wnd: UG_WINDOW; id: UG_U8; vs: UG_S8): UG_RESULT;
function UG_ButtonSetAlignment(const wnd: UG_WINDOW; id: UG_U8;
align: UG_U8): UG_RESULT;
function UG_ButtonGetForeColor(const wnd: UG_WINDOW; id: UG_U8): UG_COLOR;
function UG_ButtonGetBackColor(const wnd: UG_WINDOW; id: UG_U8): UG_COLOR;
function UG_ButtonGetAlternateForeColor(const wnd: UG_WINDOW; id: UG_U8): UG_COLOR;
function UG_ButtonGetAlternateBackColor(const wnd: UG_WINDOW; id: UG_U8): UG_COLOR;
function UG_ButtonGetText(const wnd: UG_WINDOW; id: UG_U8): PChar;
function UG_ButtonGetFont(const wnd: UG_WINDOW; id: UG_U8): PUG_FONT;
function UG_ButtonGetStyle(const wnd: UG_WINDOW; id: UG_U8): UG_U8;
function UG_ButtonGetHSpace(const wnd: UG_WINDOW; id: UG_U8): UG_S8;
function UG_ButtonGetVSpace(const wnd: UG_WINDOW; id: UG_U8): UG_S8;
function UG_ButtonGetAlignment(const wnd: UG_WINDOW; id: UG_U8): UG_U8;
{$endif}
{$ifdef UG_USE_TXB}
(* Textbox structure *)
type
PUG_TEXTBOX = ^UG_TEXTBOX;
UG_TEXTBOX = record
str: PChar;
font: PUG_FONT;
style: UG_U8;
fc: UG_COLOR;
bc: UG_COLOR;
align: UG_U8;
h_space: UG_S8;
v_space: UG_S8;
end;
const
(* Default textbox IDs *)
TXB_ID_0 = OBJ_ID_0;
TXB_ID_1 = OBJ_ID_1;
TXB_ID_2 = OBJ_ID_2;
TXB_ID_3 = OBJ_ID_3;
TXB_ID_4 = OBJ_ID_4;
TXB_ID_5 = OBJ_ID_5;
TXB_ID_6 = OBJ_ID_6;
TXB_ID_7 = OBJ_ID_7;
TXB_ID_8 = OBJ_ID_8;
TXB_ID_9 = OBJ_ID_9;
TXB_ID_10 = OBJ_ID_10;
TXB_ID_11 = OBJ_ID_11;
TXB_ID_12 = OBJ_ID_12;
TXB_ID_13 = OBJ_ID_13;
TXB_ID_14 = OBJ_ID_14;
TXB_ID_15 = OBJ_ID_15;
TXB_ID_16 = OBJ_ID_16;
TXB_ID_17 = OBJ_ID_17;
TXB_ID_18 = OBJ_ID_18;
TXB_ID_19 = OBJ_ID_19;
function UG_TextboxCreate(const wnd: UG_WINDOW; var txb: UG_TEXTBOX;
id: UG_U8; xs, ys: UG_S16; xe, ye: UG_S16): UG_RESULT;
function UG_TextboxDelete(const wnd: UG_WINDOW; id: UG_U8): UG_RESULT;
function UG_TextboxShow(const wnd: UG_WINDOW; id: UG_U8): UG_RESULT;
function UG_TextboxHide(const wnd: UG_WINDOW; id: UG_U8): UG_RESULT;
function UG_TextboxSetForeColor(const wnd: UG_WINDOW; id: UG_U8;
fc: UG_COLOR): UG_RESULT;
function UG_TextboxSetBackColor(const wnd: UG_WINDOW; id: UG_U8;
bc: UG_COLOR): UG_RESULT;
function UG_TextboxSetText(const wnd: UG_WINDOW; id: UG_U8; str: PChar): UG_RESULT;
function UG_TextboxSetFont(const wnd: UG_WINDOW; id: UG_U8; font: pUG_FONT): UG_RESULT;
function UG_TextboxSetHSpace(const wnd: UG_WINDOW; id: UG_U8; hs: UG_S8): UG_RESULT;
function UG_TextboxSetVSpace(const wnd: UG_WINDOW; id: UG_U8; vs: UG_S8): UG_RESULT;
function UG_TextboxSetAlignment(const wnd: UG_WINDOW; id: UG_U8;
align: UG_U8): UG_RESULT;
function UG_TextboxGetForeColor(const wnd: UG_WINDOW; id: UG_U8): UG_COLOR;
function UG_TextboxGetBackColor(const wnd: UG_WINDOW; id: UG_U8): UG_COLOR;
function UG_TextboxGetText(const wnd: UG_WINDOW; id: UG_U8): PChar;
function UG_TextboxGetFont(const wnd: UG_WINDOW; id: UG_U8): pUG_FONT;
function UG_TextboxGetHSpace(const wnd: UG_WINDOW; id: UG_U8): UG_S8;
function UG_TextboxGetVSpace(const wnd: UG_WINDOW; id: UG_U8): UG_S8;
function UG_TextboxGetAlignment(const wnd: UG_WINDOW; id: UG_U8): UG_U8;
{$endif}
{$ifdef UG_USE_IMG}
(* -------------------------------------------------------------------------- *)
(* -- IMAGE OBJECT -- *)
(* -------------------------------------------------------------------------- *)
const
(* Default image IDs *)
IMG_ID_0 = OBJ_ID_0;
IMG_ID_1 = OBJ_ID_1;
IMG_ID_2 = OBJ_ID_2;
IMG_ID_3 = OBJ_ID_3;
IMG_ID_4 = OBJ_ID_4;
IMG_ID_5 = OBJ_ID_5;
IMG_ID_6 = OBJ_ID_6;
IMG_ID_7 = OBJ_ID_7;
IMG_ID_8 = OBJ_ID_8;
IMG_ID_9 = OBJ_ID_9;
IMG_ID_10 = OBJ_ID_10;
IMG_ID_11 = OBJ_ID_11;
IMG_ID_12 = OBJ_ID_12;
IMG_ID_13 = OBJ_ID_13;
IMG_ID_14 = OBJ_ID_14;
IMG_ID_15 = OBJ_ID_15;
IMG_ID_16 = OBJ_ID_16;
IMG_ID_17 = OBJ_ID_17;
IMG_ID_18 = OBJ_ID_18;
IMG_ID_19 = OBJ_ID_19;
(* Image types *)
IMG_TYPE_BMP = 1 shl 0;
(* BMP constants *)
BMP_BPP_1 = 1 shl 0;
BMP_BPP_2 = 1 shl 1;
BMP_BPP_4 = 1 shl 2;
BMP_BPP_8 = 1 shl 3;
BMP_BPP_16 = 1 shl 4;
BMP_BPP_32 = 1 shl 5;
BMP_RGB888 = 1 shl 0;
BMP_RGB565 = 1 shl 1;
BMP_RGB555 = 1 shl 2;
(* Image structure *)
type
PUG_IMAGE = ^UG_IMAGE;
UG_IMAGE = record
img: PUG_U8;
itype: UG_U8;
end;
(* BMP structure *)
PUG_BMP = ^UG_BMP;
UG_BMP = record
p: PUG_U8;
Width: UG_U16;
Height: UG_U16;
bpp: UG_U8;
colors: UG_U8;
end;
(* Image functions *)
function UG_ImageCreate(const wnd: UG_WINDOW; var img: UG_IMAGE;
id: UG_U8; xs, ys: UG_S16; xe, ye: UG_S16): UG_RESULT;
function UG_ImageDelete(const wnd: UG_WINDOW; id: UG_U8): UG_RESULT;
function UG_ImageShow(const wnd: UG_WINDOW; id: UG_U8): UG_RESULT;
function UG_ImageHide(const wnd: UG_WINDOW; id: UG_U8): UG_RESULT;
function UG_ImageSetBMP(const wnd: UG_WINDOW; id: UG_U8; bmp: PUG_BMP): UG_RESULT;
{$endif}
(* Miscellaneous functions *)
procedure UG_WaitForUpdate;
procedure UG_Update;
procedure UG_TouchUpdate(xp, yp: UG_S16; state: UG_U8);
(* Driver functions *)
procedure UG_DriverRegister(t: UG_U8; driver: Pointer);
procedure UG_DriverEnable(t: UG_U8);
procedure UG_DriverDisable(t: UG_U8);
implementation
const
{$ifdef USE_COLOR_RGB888}
pal_window: array [0..11] of UG_COLOR =
($646464, $646464, $646464, $646464, (* Frame 0 *)
$FFFFFF, $FFFFFF, $696969, $696969, (* Frame 1 *)
$E3E3E3, $E3E3E3, $A0A0A0, $A0A0A0); (* Frame 2 *)
{$endif}
{$ifdef USE_COLOR_RGB565}
pal_window: array [0..11] of UG_COLOR =
($632C, $632C, $632C, $632C, $FFFF, $FFFF, $6B4D, $6B4D, $E71C, $E71C, $9D13, $9D13);
{$endif}
var
gui: PUG_GUI;
(* -------------------------------------------------------------------------- *)
(* -- INTERNAL FUNCTIONS -- *)
(* -------------------------------------------------------------------------- *)
procedure _UG_PutChar(chr: char; x, y: UG_S16; fc, bc: UG_COLOR; const font: UG_FONT);
var
i, j, k: UG_U16;
xo, yo: UG_U16;
c: UG_U16;
bn: UG_U16;
actual_char_width: UG_U16;
b: UG_U8;
bt: char;
(* TP7 Compat *)
index: UG_U16;
(* index: UG_U32; *)
color: UG_COLOR;
begin
bt := chr;
case Ord(bt) of
$F6: bt := char($94);
$D6: bt := char($99);
$FC: bt := char($81);
$DC: bt := char($9A);
$E4: bt := char($84);
$C4: bt := char($8E);
$B5: bt := char($E6);
$B0: bt := char($F8);
end;
if (Ord(bt) < font.start_char) or (Ord(bt) > font.end_char) then
exit;
yo := y;
bn := font.char_width;
if 0 = bn then
exit;
bn := bn shr 3;
if (font.char_width mod 8) <> 0 then
Inc(bn);
if font.widths <> nil then
actual_char_width := IncPtrU8(font.widths, Ord(bt) - font.start_char)^
else
actual_char_width := font.char_width;
(* TO DO *)
(* Is hardware acceleration available? *)
(* Not accelerated output *)
if font.font_type = FONT_TYPE_1BPP then
begin
index := (Ord(bt) - font.start_char) * (font.char_height) * bn;
for j := 0 to Pred(font.char_height) do
begin
xo := x;
c := actual_char_width;
for i := 0 to Pred(bn) do
begin
b := IncPtrU8(font.p, index)^;
Inc(index);
k := 0;
while (k < 8) and (c <> 0) do
begin
if (b and $01) <> 0 then
gui^.pset(xo, yo, fc)
else
gui^.pset(xo, yo, bc);
b := b shr 1;
Inc(xo);
Dec(c);
Inc(k);
end;
end;
Inc(yo);
end;
end
else
if font.font_type = FONT_TYPE_8BPP then
begin
index := (Ord(bt) - font.start_char) * font.char_height * font.char_width;
for j := 0 to Pred(font.char_height) do
begin
xo := x;
for i := 0 to Pred(actual_char_width) do
begin
b := IncPtrU8(font.p, index)^;
Inc(index);
color := (((fc and $FF) * b + (bc and $FF) * (256 - b)) shr 8) and
$FF or (((fc and $FF00) * b + (bc and $FF00) * (256 - b)) shr 8) and
$FF00 or (((fc and $FF0000) * b + (bc and $FF0000) * (256 - b)) shr 8) and
$FF0000;
gui^.pset(xo, yo, color);
(* Blue component *)
(* Green component *)
(* Red component *)
Inc(xo);
end;
index := index + font.char_width - actual_char_width;
Inc(yo);
end;
end;
end;
procedure _UG_PutText(var txt: UG_TEXT);
var
sl: UG_U16;
rc: UG_U16;
wl: UG_U16;
xp, yp: UG_S16;
xs, ys: UG_S16;
xe, ye: UG_S16;
align: UG_U8;
char_width, char_height: UG_S16;
char_h_space, char_v_space: UG_S16;
chr: char;
str: PChar;
c: PChar;
begin
xs := txt.a.xs;
ys := txt.a.ys;
xe := txt.a.xe;
ye := txt.a.ye;
align := txt.align;
char_width := txt.font^.char_width;
char_height := txt.font^.char_height;
char_h_space := txt.h_space;
char_v_space := txt.v_space;
str := txt.str;
c := str;
if (txt.font^.p = nil) or (str = nil) or ((ye - ys) < txt.font^.char_height) then
exit;
rc := 1;
c := str;
while c^ <> char(0) do
begin
if c^ = char($0A) then
Inc(rc);
Inc(c);
end;
yp := 0;
if (align and (ALIGN_V_CENTER or ALIGN_V_BOTTOM)) <> 0 then
begin
yp := ye - ys + 1;
yp := yp - char_height * rc;
yp := yp - char_v_space * (rc - 1);
if yp < 0 then
exit;
end;
if (align and ALIGN_V_CENTER) <> 0 then
yp := yp shr 1;
yp := yp + ys;
while True do
begin
sl := 0;
c := str;
wl := 0;
while (c^ <> char(0)) and (c^ <> char($0A)) do
begin
if (Ord(c^) < txt.font^.start_char) or (Ord(c^) > txt.font^.end_char) then
begin
Inc(c);
continue;
end;
Inc(sl);
if txt.font^.widths <> nil then
wl := wl + IncPtrU8(txt.font^.widths, Ord(c^) - txt.font^.start_char)^
else
wl := wl + char_width;
wl := wl + char_h_space;
Inc(c);
end;
wl := wl - char_h_space;
xp := xe - xs + 1;
xp := xp - wl;
if xp < 0 then
exit;
if (align and ALIGN_H_LEFT) <> 0 then
xp := 0
else if (align and ALIGN_H_CENTER) <> 0 then
xp := xp shr (1);
xp := xp + xs;
while str^ <> char($0A) do
begin
chr := str^;
Inc(str);
if Ord(chr) = 0 then
exit;
_UG_PutChar(chr, xp, yp, txt.fc, txt.bc, txt.font^);
if txt.font^.widths <> nil then
xp := xp + IncPtrU8(txt.font^.widths, Ord(chr) - txt.font^.start_char)^
else
xp := xp + char_width;
xp := xp + char_h_space;
end;
Inc(str);
yp := yp + char_height + char_v_space;
end;
end;
procedure _UG_DrawObjectFrame(xs, ys: UG_S16; xe, ye: UG_S16; p: PUG_COLOR);
begin
(* Frame 0*)
UG_DrawHLine(xs, xe - 1, ys, p^);
Inc(p);
UG_DrawVLine(ys + 1, ye - 1, xs, p^);
Inc(p);
UG_DrawHLine(xs, xe, ye, p^);
Inc(p);
UG_DrawVLine(ys, ye - 1, xe, p^);
Inc(p);
(* Frame 1*)
UG_DrawHLine(xs + 1, xe - 2, ys + 1, p^);
Inc(p);
UG_DrawVLine(ys + 2, ye - 2, xs + 1, p^);
Inc(p);
UG_DrawHLine(xs + 1, xe - 1, ye - 1, p^);
Inc(p);
UG_DrawVLine(ys + 1, ye - 2, xe - 1, p^);
Inc(p);
(* Frame 2*)
UG_DrawHLine(xs + 2, xe - 3, ys + 2, p^);
Inc(p);
UG_DrawVLine(ys + 3, ye - 3, xs + 2, p^);
Inc(p);
UG_DrawHLine(xs + 2, xe - 2, ye - 2, p^);
Inc(p);
UG_DrawVLine(ys + 2, ye - 3, xe - 2, p^);
end;
(* Window internal *)
function _UG_WindowDrawTitle(var wnd: UG_WINDOW): UG_RESULT;
var
txt: UG_TEXT;
xs, ys: UG_S16;
xe, ye: UG_S16;
begin
if (wnd.state and WND_STATE_VALID) <> 0 then
begin
xs := wnd.xs;
ys := wnd.ys;
xe := wnd.xe;
ye := wnd.ye;
(* 3D style? *)
if (wnd.style and WND_STYLE_3D) <> 0 then
begin
xs := xs + 3;
ys := ys + 3;
xe := xe - 3;
ye := ye - 3;
end;
(* Is the window active or inactive? *)
if @wnd = gui^.active_window then
begin
txt.bc := wnd.title.bc;
txt.fc := wnd.title.fc;
end
else
begin
txt.bc := wnd.title.ibc;
txt.fc := wnd.title.ifc;
end;
(* Draw title *)
UG_FillFrame(xs, ys, xe, ys + wnd.title.Height - 1, txt.bc);
(* Draw title text *)
txt.str := wnd.title.str;
txt.font := wnd.title.font;
txt.a.xs := xs + 3;
txt.a.ys := ys;
txt.a.xe := xe;
txt.a.ye := ys + wnd.title.Height - 1;
txt.align := wnd.title.align;
txt.h_space := wnd.title.h_space;
txt.v_space := wnd.title.v_space;
_UG_PutText(txt);
(* Draw line *)
UG_DrawHLine(xs, xe, ys + wnd.title.Height,
pal_window[11]);
_UG_WindowDrawTitle := RESULT_OK;
end
else
_UG_WindowDrawTitle := RESULT_FAIL;
end;
procedure _UG_WindowUpdate(var wnd: UG_WINDOW);
var
i: UG_U16;
objcnt: UG_U16;