-
Notifications
You must be signed in to change notification settings - Fork 1
/
gtalleg.c
2343 lines (2029 loc) · 62 KB
/
gtalleg.c
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
/*
* $Id: gtalleg.c,v 1.1 2012/12/10 16:47:31 wagner Exp $
*/
/*
* xHarbour Project source code:
* Allegro based virtual gt with graphic extensions.
*
* Copyright 2004 Mauricio Abre <[email protected]>
* www - http://www.xharbour.org
* www - http://www.harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
#define HB_GT_NAME COLOMBO
#define HB_MULTI_GT
#include <allegro.h>
#include "ssf.h"
#include "hbapi.h"
#include "hbapigt.h"
#include "hbapifs.h"
#include "hbapierr.h"
#include "hbset.h"
#include "hbvm.h"
#include "inkey.ch"
static int s_iStdIn, s_iStdOut, s_iStdErr;
static int s_iMsButtons, s_iMSBoundTop, s_iMSBoundLeft, s_iMSBoundBottom, s_iMSBoundRight;
static int s_iMSX, s_iMSY;
static BYTE s_byMSButtons;
static USHORT s_usScrWidth = 80, s_usScrHeight = 25;
static USHORT s_usGFXWidth = 0, s_usGFXHeight = 0;
static USHORT s_usUpdTop, s_usUpdLeft, s_usUpdBottom, s_usUpdRight;
static USHORT s_usGFXUpdTop, s_usGFXUpdLeft, s_usGFXUpdBottom, s_usGFXUpdRight;
static int s_iCTop, s_iCLeft, s_iCBottom, s_iCRight;
static USHORT s_usDispCount, s_usCursorStyle;
static SHORT s_sCurCol, s_sCurRow;
static BYTE * s_pbyScrBuffer = NULL;
static int s_pClr[16];
static BYTE s_byFontSize = 16, s_byFontWidth = 8, s_byDrawMode = GFX_MODE_SOLID;
static AL_BITMAP *bmp;
static AL_BITMAP *bf;
BOOL lClearInit = TRUE;
static void hb_gt_DoCursor( void );
static char *s_clipboard = NULL;
static ULONG s_clipsize = 0;
static int bits = 16,ubits=0;
static int num_col = 800,unum_col=0;
static int num_lin = 600,unum_lin=0;
// I'm not sure of removing these (yet)
// (they used to be static vars to center gt in hw screen, but now the
// font size is set based on screen size, so gtAlleg will use about all screen)
//
// NOTE: This is only a Linux fb & DOS issue, where we don't have windows
#define s_usHBorder 0
#define s_usVBorder 0
typedef struct {
int al_key;
int xhb_key;
} gtAllegKey;
#define GT_KEY_TABLE_SIZE 49
static const gtAllegKey sKeyTable[GT_KEY_TABLE_SIZE] = {
{AL_KEY_ESC, K_ESC},
{AL_KEY_INSERT, K_INS},
{AL_KEY_HOME, K_HOME},
{AL_KEY_PGUP, K_PGUP},
{AL_KEY_PGDN, K_PGDN},
{AL_KEY_END, K_END},
{AL_KEY_DEL, K_DEL},
{AL_KEY_UP, K_UP},
{AL_KEY_DOWN, K_DOWN},
{AL_KEY_LEFT, K_LEFT},
{AL_KEY_RIGHT, K_RIGHT},
{AL_KEY_A, K_ALT_A},
{AL_KEY_B, K_ALT_B},
{AL_KEY_C, K_ALT_C},
{AL_KEY_D, K_ALT_D},
{AL_KEY_E, K_ALT_E},
{AL_KEY_F, K_ALT_F},
{AL_KEY_G, K_ALT_G},
{AL_KEY_H, K_ALT_H},
{AL_KEY_I, K_ALT_I},
{AL_KEY_J, K_ALT_J},
{AL_KEY_K, K_ALT_K},
{AL_KEY_L, K_ALT_L},
{AL_KEY_M, K_ALT_M},
{AL_KEY_N, K_ALT_N},
{AL_KEY_O, K_ALT_O},
{AL_KEY_P, K_ALT_P},
{AL_KEY_Q, K_ALT_Q},
{AL_KEY_R, K_ALT_R},
{AL_KEY_S, K_ALT_S},
{AL_KEY_T, K_ALT_T},
{AL_KEY_U, K_ALT_U},
{AL_KEY_V, K_ALT_V},
{AL_KEY_W, K_ALT_W},
{AL_KEY_X, K_ALT_X},
{AL_KEY_Y, K_ALT_Y},
{AL_KEY_Z, K_ALT_Z},
{AL_KEY_F1, K_F1},
{AL_KEY_F2, K_F2},
{AL_KEY_F3, K_F3},
{AL_KEY_F4, K_F4},
{AL_KEY_F5, K_F5},
{AL_KEY_F6, K_F6},
{AL_KEY_F7, K_F7},
{AL_KEY_F8, K_F8},
{AL_KEY_F9, K_F9},
{AL_KEY_F10, K_F10},
{AL_KEY_F11, K_F11},
{AL_KEY_F12, K_F12}
};
#define GT_CTRL_TABLE_SIZE 11
static const gtAllegKey sCtrlTable[GT_CTRL_TABLE_SIZE] = {
{AL_KEY_LEFT, K_CTRL_LEFT},
{AL_KEY_RIGHT, K_CTRL_RIGHT},
{AL_KEY_UP, K_CTRL_UP},
{AL_KEY_DOWN, K_CTRL_DOWN},
{AL_KEY_QUOTE, K_CTRL_PRTSCR},
{AL_KEY_INSERT, K_CTRL_INS},
{AL_KEY_DEL, K_CTRL_DEL},
{AL_KEY_HOME, K_CTRL_HOME},
{AL_KEY_END, K_CTRL_END},
{AL_KEY_PGUP, K_CTRL_PGUP},
{AL_KEY_PGDN, K_CTRL_PGDN}
};
#define _GetScreenHeight() (s_usScrHeight)
#define _GetScreenWidth() (s_usScrWidth)
#define GT_UPD_RECT(t,l,b,r) if (t<s_usUpdTop) s_usUpdTop=t; if (l<s_usUpdLeft) s_usUpdLeft=l; if (b>s_usUpdBottom) s_usUpdBottom=b; if (r>s_usUpdRight) s_usUpdRight=r;
#define GT_UPD_GFXRECT(t,l,b,r) if (t<s_usGFXUpdTop) s_usGFXUpdTop=t; if (l<s_usGFXUpdLeft) s_usGFXUpdLeft=l; if (b>s_usGFXUpdBottom) s_usGFXUpdBottom=b; if (r>s_usGFXUpdRight) s_usGFXUpdRight=r;
#define MK_GT8BCOLOR(n) (n & 0xFF) / 16 | (n & 0xFF00) / 256
/*
* We don't have a cursor in gfx mode, so I have to emulate it :-)
* Cursor is drawn with in XOR method, so redrawing it erases previous one
*
*/
static void hb_gt_DoCursor()
{
static BOOL s_bVisible = 0;
int iLeft, iTop, iBottom, iRight;
if ( !s_bVisible && s_usDispCount == 0 )
{
s_bVisible = 1;
}
if ( s_bVisible && ( s_pbyScrBuffer != NULL ) )
{
iLeft = s_usHBorder + s_sCurCol * s_byFontWidth;
iRight = iLeft;
iTop = s_usVBorder + s_sCurRow * s_byFontSize;
iBottom = iTop;
switch ( s_usCursorStyle )
{
case SC_NORMAL:
iBottom += s_byFontSize - 1;
iTop = iBottom - 1;
iRight += s_byFontWidth;
break;
case SC_INSERT:
iBottom += s_byFontSize - 1;
iTop = iBottom - ( s_byFontSize / 2 ) + 1;
iRight += s_byFontWidth;
break;
case SC_SPECIAL1:
iBottom += s_byFontSize - 1;
iRight += s_byFontWidth;
break;
case SC_SPECIAL2:
iBottom += ( s_byFontSize / 2 ) - 1;
iRight += s_byFontWidth;
break;
}
if ( iRight > iLeft ) // cursor != SC_NONE
{
al_scare_mouse_area( iLeft, iTop, iRight, iBottom );
al_acquire_screen();
al_drawing_mode( DRAW_MODE_XOR, NULL, 0, 0 );
if (bf){
al_draw_rect_fill( bf, iLeft, iTop, iRight, iBottom, s_pClr[7]);
}else{
al_draw_rect_fill( al_screen, iLeft, iTop, iRight, iBottom, s_pClr[7]);
}
al_drawing_mode( DRAW_MODE_SOLID, NULL, 0, 0 );
al_release_screen();
al_unscare_mouse();
}
}
if( s_bVisible && s_usDispCount > 1 )
{
s_bVisible = FALSE; // prevent cursor flicker on buffered screen i/o
}
}
void HB_GT_FUNC(gt_Init( int iFilenoStdin, int iFilenoStdout, int iFilenoStderr ))
{
int iRet;
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_Init()"));
#endif
s_iStdIn = iFilenoStdin;
s_iStdOut = iFilenoStdout;
s_iStdErr = iFilenoStderr;
s_usCursorStyle = SC_NORMAL;
if( allegro_init() != 0 )
{
hb_errInternal( 9997, "Screen driver initialization failure: %s", allegro_error, NULL );
}
iRet = al_desktop_color_depth();
if ( iRet > 0 )
{
al_set_color_depth(32);
// setting depth to 16 defaults to a 320x200x8bpp under DOS if no matching mode :(
// } else
// {
// al_set_color_depth(32);
}
}
void HB_GT_FUNC(gt_Exit( void ))
{
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_Exit()"));
#endif
if ( s_pbyScrBuffer != NULL )
{
hb_xfree( s_pbyScrBuffer );
s_pbyScrBuffer = NULL;
al_destroy_bitmap(bmp);
}
if ( s_clipboard != NULL )
{
hb_xfree( s_clipboard );
}
}
USHORT HB_GT_FUNC(gt_GetScreenWidth( void ))
{
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_GetScreenWidth(%d)"));
#endif
return _GetScreenWidth();
}
USHORT HB_GT_FUNC(gt_GetScreenHeight( void ))
{
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_GetScreenHeight()"));
#endif
return _GetScreenHeight();
}
SHORT HB_GT_FUNC(gt_Col( void ))
{
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_Col()"));
#endif
return s_sCurCol;
}
SHORT HB_GT_FUNC(gt_Row( void ))
{
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_Row()"));
#endif
return s_sCurRow;
}
void HB_GT_FUNC(gt_SetPos( SHORT sRow, SHORT sCol, SHORT sMethod ))
{
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_SetPos(%hd, %hd, %hd)", sRow, sCol, sMethod));
#endif
HB_SYMBOL_UNUSED( sMethod );
hb_gt_DoCursor(); // hide cursor
s_sCurRow = sRow;
s_sCurCol = sCol;
hb_gt_DoCursor(); // draw it at new location
}
BOOL HB_GT_FUNC(gt_AdjustPos( BYTE *pStr, ULONG ulLen ))
{
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_AdjustPos(%s, %lu)", pStr, ulLen));
#endif
HB_SYMBOL_UNUSED( pStr );
HB_SYMBOL_UNUSED( ulLen);
return 1;
}
BOOL HB_GT_FUNC(gt_IsColor( void ))
{
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_IsColor()"));
#endif
return 1;
}
USHORT HB_GT_FUNC(gt_GetCursorStyle( void ))
{
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_GetCursorStyle()"));
#endif
return s_usCursorStyle;
}
void HB_GT_FUNC(gt_SetCursorStyle( USHORT usStyle ))
{
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_SetCursorStyle(%hu)", usStyle));
#endif
if ( usStyle != s_usCursorStyle ) // don't do unnecessary stuff
{
hb_gt_DoCursor(); // hide actual cursor
switch ( usStyle )
{
case SC_NONE:
case SC_NORMAL:
case SC_INSERT:
case SC_SPECIAL1:
case SC_SPECIAL2:
s_usCursorStyle = usStyle;
break;
default:
break;
}
hb_gt_DoCursor(); // show new cursor
}
}
static void HB_GT_FUNC(gt_ScreenUpdate( void ))
{
USHORT x, y, z;
BYTE byAttr, byChar;
HB_GT_GOBJECT *gobject;
int gcolor;
char gtext[256];
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_ScreenUpdate()"));
#endif
if ( s_usDispCount == 0 && s_usGFXUpdTop <= s_usGFXUpdBottom && s_usGFXUpdLeft <= s_usGFXUpdRight )
{
al_acquire_screen();
al_scare_mouse_area(s_usGFXUpdLeft, s_usGFXUpdTop, s_usGFXUpdRight, s_usGFXUpdBottom);
if (bf){
al_blit(bmp, bf, s_usGFXUpdLeft, s_usGFXUpdTop, s_usGFXUpdLeft, s_usGFXUpdTop, s_usGFXUpdRight - s_usGFXUpdLeft + 1, s_usGFXUpdBottom - s_usGFXUpdTop + 1);
}else{
al_blit(bmp, al_screen, s_usGFXUpdLeft, s_usGFXUpdTop, s_usGFXUpdLeft, s_usGFXUpdTop, s_usGFXUpdRight - s_usGFXUpdLeft + 1, s_usGFXUpdBottom - s_usGFXUpdTop + 1);
}
al_release_screen();
al_unscare_mouse();
s_usGFXUpdTop = s_usScrHeight;
s_usGFXUpdLeft = s_usScrWidth;
s_usGFXUpdBottom = 0;
s_usGFXUpdRight = 0;
}
if ( s_usDispCount == 0 && s_usUpdTop <= s_usUpdBottom && s_usUpdLeft <= s_usUpdRight )
{
al_acquire_bitmap( bmp );
for ( y = s_usUpdTop; y <= s_usUpdBottom; y++ )
{
z = y * _GetScreenWidth() * 2 + s_usUpdLeft * 2;
for ( x = s_usUpdLeft; x <= s_usUpdRight; x++ )
{
byChar = s_pbyScrBuffer[z++];
byAttr = s_pbyScrBuffer[z++];
if (bf){
al_draw_rect_fill( bf, x * s_byFontWidth, y * s_byFontSize, x * s_byFontWidth + s_byFontWidth - 1, y * s_byFontSize + s_byFontSize - 1, s_pClr[byAttr >> 4] );
ssfDrawChar( bf, ssfDefaultFont, byChar, x * s_byFontWidth, y * s_byFontSize, s_pClr[byAttr & 0x0F] );
}else{
al_draw_rect_fill( bmp, x * s_byFontWidth, y * s_byFontSize, x * s_byFontWidth + s_byFontWidth - 1, y * s_byFontSize + s_byFontSize - 1, s_pClr[byAttr >> 4] );
ssfDrawChar( bmp, ssfDefaultFont, byChar, x * s_byFontWidth, y * s_byFontSize, s_pClr[byAttr & 0x0F] );
}
}
}
s_usUpdLeft *= s_byFontWidth;
s_usUpdTop *= s_byFontSize;
s_usUpdRight = s_usUpdRight * s_byFontWidth + s_byFontWidth - 1;
s_usUpdBottom = s_usUpdBottom * s_byFontSize + s_byFontSize - 1;
if ( hb_gt_gobjects )
{
gobject = hb_gt_gobjects;
while ( gobject )
{
gcolor = al_make_color( MK_GT8BCOLOR(gobject->color.usRed), MK_GT8BCOLOR(gobject->color.usGreen), MK_GT8BCOLOR(gobject->color.usBlue) );
s_usUpdLeft = MIN(s_usUpdLeft,gobject->x);
s_usUpdTop = MIN(s_usUpdTop,gobject->y);
switch ( gobject->type )
{
case GTO_POINT:
al_put_pixel( bmp, gobject->x, gobject->y, gcolor );
s_usUpdRight = MAX(s_usUpdRight,gobject->x);
s_usUpdBottom = MAX(s_usUpdBottom,gobject->y);
break;
case GTO_LINE:
al_draw_line( bmp, gobject->x, gobject->y, gobject->width, gobject->height, gcolor );
if ( gobject->x > gobject->width )
{
s_usUpdLeft = MIN(s_usUpdLeft,gobject->width);
s_usUpdTop = MIN(s_usUpdTop,gobject->height);
s_usUpdRight = MAX(s_usUpdRight,gobject->x);
s_usUpdBottom = MAX(s_usUpdBottom,gobject->y);
}
else
{
s_usUpdRight = MAX(s_usUpdRight,gobject->width);
s_usUpdBottom = MAX(s_usUpdBottom,gobject->height);
}
break;
case GTO_SQUARE:
al_draw_rect( bmp, gobject->x, gobject->y, gobject->x + gobject->width - 1, gobject->y + gobject->height - 1, gcolor );
s_usUpdRight = MAX(s_usUpdRight,gobject->x+gobject->width-1);
s_usUpdBottom = MAX(s_usUpdBottom,gobject->y+gobject->height-1);
break;
case GTO_RECTANGLE:
al_draw_rect_fill( bmp, gobject->x, gobject->y, gobject->x + gobject->width - 1, gobject->y + gobject->height - 1, gcolor );
s_usUpdRight = MAX(s_usUpdRight,gobject->x+gobject->width-1);
s_usUpdBottom = MAX(s_usUpdBottom,gobject->y+gobject->height-1);
break;
case GTO_CIRCLE:
// Should be ellipses, otherwise they'll not fill entire requested area
// But I leaved circles to match its name
// al_draw_ellipse( al_screen, gobject->x, gobject->y, gobject->width / 2, gobject->height / 2, al_make_color( gcolor.usRed, gcolor.usGreen, gcolor.usBlue ) );
al_draw_circle( bmp, gobject->x + gobject->width / 2, gobject->y + gobject->height / 2, gobject->width / 2 - 1, gcolor );
s_usUpdRight = MAX(s_usUpdRight,gobject->x+gobject->width-1);
s_usUpdBottom = MAX(s_usUpdBottom,gobject->y+gobject->height-1);
break;
case GTO_DISK:
al_draw_circle_fill( bmp, gobject->x + gobject->width / 2, gobject->y + gobject->height / 2, gobject->width / 2 - 1, gcolor );
s_usUpdRight = MAX(s_usUpdRight,gobject->x+gobject->width-1);
s_usUpdBottom = MAX(s_usUpdBottom,gobject->y+gobject->height-1);
break;
case GTO_TEXT:
memcpy( gtext, gobject->data, gobject->data_len );
gtext[gobject->data_len] = '\0';
// Commented out until GtText() font width & height support is added
// if ( gobject->height != 0 )
// {
// ssfDefaultFont->fsize = (unsigned short) gobject->height;
// }
ssfDrawText( bmp, ssfDefaultFont, gtext, gobject->x, gobject->y, gcolor );
s_usUpdRight = MAX(s_usUpdRight,gobject->x+gobject->data_len*(ssfDefaultFont->fsize/2)-1);
s_usUpdBottom = MAX(s_usUpdBottom,gobject->y+ssfDefaultFont->fsize-1);
// if ( gobject->height != 0 )
// {
// ssfDefaultFont->fsize = (unsigned short) s_byFontSize;
// }
break;
default:
break;
}
gobject = gobject->next;
}
}
al_acquire_screen();
al_scare_mouse_area(s_usUpdLeft, s_usUpdTop, s_usUpdRight, s_usUpdBottom);
// Aqui devia ir para TELA
if (bf){
// al_blit(bmp, bf, s_usUpdLeft, s_usUpdTop, s_usUpdLeft, s_usUpdTop, s_usUpdRight - s_usUpdLeft + 1, s_usUpdBottom - s_usUpdTop + 1);
draw_sprite(bmp,bf,s_usUpdLeft,s_usUpdTop);
}else{
al_blit(bmp, al_screen, s_usUpdLeft, s_usUpdTop, s_usUpdLeft, s_usUpdTop, s_usUpdRight - s_usUpdLeft + 1, s_usUpdBottom - s_usUpdTop + 1);
}
al_release_bitmap(bmp);
al_release_screen();
al_unscare_mouse();
if ( s_sCurCol * s_byFontWidth >= s_usUpdLeft &&
s_sCurCol * s_byFontWidth <= s_usUpdRight &&
s_sCurRow * s_byFontSize >= s_usUpdTop &&
s_sCurRow * s_byFontSize <= s_usUpdBottom )
{
hb_gt_DoCursor();
}
s_usUpdTop = _GetScreenHeight();
s_usUpdLeft = _GetScreenWidth();
s_usUpdBottom = 0;
s_usUpdRight = 0;
}
}
void HB_GT_FUNC(gt_DispBegin( void ))
{
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_DispBegin()"));
#endif
if ( s_pbyScrBuffer == NULL )
{
HB_GT_FUNC(gt_SetMode(_GetScreenHeight(), _GetScreenWidth()));
}
if ( s_usDispCount == 0 )
{
al_acquire_bitmap(bmp);
}
s_usDispCount++;
}
void HB_GT_FUNC(gt_DispEnd( void ))
{
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_DispEnd()"));
#endif
if ( s_pbyScrBuffer == NULL )
{
HB_GT_FUNC(gt_SetMode(_GetScreenHeight(), _GetScreenWidth()));
}
if ( s_usDispCount > 0 )
{
s_usDispCount--;
if ( s_usDispCount == 0 )
{
al_release_bitmap(bmp);
HB_GT_FUNC(gt_ScreenUpdate());
}
}
}
HB_FUNC(_SET_BUFFER){
bf=(AL_BITMAP *)hb_parnl(1);
}
USHORT HB_GT_FUNC(gt_DispCount( void ))
{
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_DispCount()"));
#endif
return s_usDispCount;
}
BOOL HB_GT_FUNC(gt_GetBlink( void ))
{
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_GetBlink()"));
#endif
return FALSE;
}
void HB_GT_FUNC(gt_SetBlink( BOOL bBlink ))
{
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_SetBlink()"));
#endif
HB_SYMBOL_UNUSED( bBlink );
}
int HB_GT_FUNC(gt_RectSize( USHORT usRows, USHORT usCols ))
{
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_RectSize(%hu, %hu)", usRows, usCols));
#endif
return usRows * usCols * 2;
}
char * HB_GT_FUNC(gt_Version( int iType ))
{
if ( iType == 0 )
return HB_GT_DRVNAME( HB_GT_NAME );
return "Harbour Terminal: Multiplatform Allegro graphics console";
}
BOOL HB_GT_FUNC(gt_Suspend())
{
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_Suspend()"));
#endif
return 1;
}
BOOL HB_GT_FUNC(gt_Resume())
{
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_Resume()"));
#endif
return 1;
}
BOOL HB_GT_FUNC(gt_PreExt())
{
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_PreExt()"));
#endif
return 1;
}
BOOL HB_GT_FUNC(gt_PostExt())
{
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_PostExt()"));
#endif
return 1;
}
void HB_GT_FUNC(gt_OutStd( BYTE * pbyStr, ULONG ulLen ))
{
hb_fsWriteLarge( s_iStdOut, ( BYTE * ) pbyStr, ulLen );
}
void HB_GT_FUNC(gt_OutErr( BYTE * pbyStr, ULONG ulLen ))
{
hb_fsWriteLarge( s_iStdErr, ( BYTE * ) pbyStr, ulLen );
}
int HB_GT_FUNC(gt_ExtendedKeySupport( void ))
{
return 1;
}
void HB_GT_FUNC(gt_Puts( USHORT usRow, USHORT usCol, BYTE byAttr, BYTE *pbyStr, ULONG ulLen ))
{
USHORT i, j, k;
USHORT uL = usCol + ulLen, uR = usCol;
BOOL lUpd = FALSE;
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_Puts(%hu, %hu, %d, %p, %lu)", usRow, usCol, (int) byAttr, pbyStr, ulLen));
#endif
if ( s_pbyScrBuffer == NULL )
{
HB_GT_FUNC(gt_SetMode(_GetScreenHeight(), _GetScreenWidth()));
}
if ( usRow < _GetScreenHeight() )
{
j = (USHORT) ulLen;
if ( usCol + j > _GetScreenWidth() )
{
j = _GetScreenWidth() - usCol;
}
k = usRow * _GetScreenWidth() * 2 + usCol * 2;
for ( i = 0; i < j; i++ )
{
// if ( ( s_pbyScrBuffer[k++] != pbyStr[i] ) | ( s_pbyScrBuffer[k++] != byAttr ) )
// {
k+=2;
s_pbyScrBuffer[k - 2] = pbyStr[i];
s_pbyScrBuffer[k - 1] = byAttr;
lUpd = TRUE;
uL = MIN(uL,usCol+i);
uR = MAX(uR,usCol+i);
// }
}
if ( lUpd )
{
GT_UPD_RECT(usRow,uL,usRow,uR);
HB_GT_FUNC(gt_ScreenUpdate());
}
}
}
HB_FUNC(ZERA_RECT){
GT_UPD_RECT(hb_parni(1),hb_parni(2),hb_parni(3),hb_parni(4));
}
void HB_GT_FUNC(gt_Replicate( USHORT usRow, USHORT usCol, BYTE byAttr, BYTE byChar, ULONG ulLen ))
{
int i, l;
BYTE pbyBuf[256];
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("gt_Replicate(%hu, %hu, %d, %c, %lu)", usRow, usCol, (int) byAttr, (char) byChar, ulLen));
#endif
l = (int) MIN(ulLen+1,256);
for ( i = 0; i < l; i++ )
{
pbyBuf[i] = byChar;
}
pbyBuf[i] = '\0';
l--;
HB_GT_FUNC(gt_Puts( usRow, usCol, byAttr, (BYTE *) pbyBuf, (ULONG) l));
}
void HB_GT_FUNC(gt_GetText( USHORT usTop, USHORT usLeft, USHORT usBottom, USHORT usRight, BYTE *pbyDst ))
{
USHORT x, y, z;
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("gt_GetText(%hu, %hu, %hu, %hu, %p)", usTop, usLeft, usBottom, usRight, pbyDst));
#endif
if ( s_pbyScrBuffer == NULL )
{
HB_GT_FUNC(gt_SetMode(_GetScreenHeight(), _GetScreenWidth()));
}
if ( usTop > usBottom )
{
x = usTop;
usTop = usBottom;
usBottom = x;
}
if ( usLeft > usRight )
{
x = usLeft;
usLeft = usRight;
usRight = x;
}
if ( usBottom >= _GetScreenHeight() )
{
usBottom = _GetScreenHeight() - 1;
}
if ( usRight >= _GetScreenWidth() )
{
usRight = _GetScreenWidth() - 1;
}
if ( usTop < _GetScreenHeight() && usLeft < _GetScreenWidth() )
{
for ( y = usTop; y <= usBottom; y++ )
{
z = y * _GetScreenWidth() * 2 + usLeft * 2;
for ( x = usLeft; x <= usRight; x++ )
{
*(pbyDst++) = s_pbyScrBuffer[z++];
*(pbyDst++) = s_pbyScrBuffer[z++];
}
}
}
}
void HB_GT_FUNC(gt_PutText( USHORT usTop, USHORT usLeft, USHORT usBottom, USHORT usRight, BYTE *pbySrc ))
{
USHORT x, y, z;
USHORT uT, uL, uB, uR;
BOOL lUpd = FALSE;
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("gt_PutText(%hu, %hu, %hu, %hu, %p)", usTop, usLeft, usBottom, usRight, pbySrc));
#endif
if ( s_pbyScrBuffer == NULL )
{
HB_GT_FUNC(gt_SetMode(_GetScreenHeight(), _GetScreenWidth()));
}
// coord check
if ( usTop > usBottom )
{
x = usTop;
usTop = usBottom;
usBottom = x;
}
if ( usLeft > usRight )
{
x = usLeft;
usLeft = usRight;
usRight = x;
}
uT = usBottom;
uL = usRight;
uB = usTop;
uR = usLeft;
if ( usBottom >= _GetScreenHeight() )
{
usBottom = _GetScreenHeight() - 1;
}
if ( usRight >= _GetScreenWidth() )
{
usRight = _GetScreenWidth() - 1;
}
if ( usTop < _GetScreenHeight() && usLeft < _GetScreenWidth() )
{
for ( y = usTop; y <= usBottom; y++ )
{
z = y * _GetScreenWidth() * 2 + usLeft * 2;
for ( x = usLeft; x <= usRight; x++ )
{
// if ( ( s_pbyScrBuffer[z++] != *(pbySrc++) ) | ( s_pbyScrBuffer[z++] != *(pbySrc++) ) )
// {
z+=2;
pbySrc+=2;
s_pbyScrBuffer[z-1] = *(pbySrc-1);
s_pbyScrBuffer[z-2] = *(pbySrc-2);
lUpd = TRUE;
uL = MIN(uL,x);
uT = MIN(uT,y);
uR = MAX(uR,x);
uB = MAX(uB,y);
// }
}
}
if ( lUpd )
{
GT_UPD_RECT(uT,uL,uB,uR);
HB_GT_FUNC(gt_ScreenUpdate());
}
}
}
void HB_GT_FUNC(gt_SetAttribute( USHORT usTop, USHORT usLeft, USHORT usBottom, USHORT usRight, BYTE byAttr ))
{
USHORT x, y, z;
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("gt_SetAttribute(%hu, %hu, %hu, %hu, %d)", usTop, usLeft, usBottom, usRight, (int) byAttr));
#endif
if ( s_pbyScrBuffer == NULL )
{
HB_GT_FUNC(gt_SetMode(_GetScreenHeight(), _GetScreenWidth()));
}
if ( usTop > usBottom )
{
x = usTop;
usTop = usBottom;
usBottom = x;
}
if ( usLeft > usRight )
{
x = usLeft;
usLeft = usRight;
usRight = x;
}
if ( usBottom >= _GetScreenHeight() )
{
usBottom = _GetScreenHeight() - 1;
}
if ( usRight >= _GetScreenWidth() )
{
usRight = _GetScreenWidth() - 1;
}
if ( usTop < _GetScreenHeight() && usLeft < _GetScreenWidth() )
{
for ( y = usTop; y <= usBottom; y++ )
{
z = y * _GetScreenWidth() * 2 + usLeft * 2;
for ( x = usLeft; x <= usRight; x++ )
{
if ( s_pbyScrBuffer[++z] != byAttr )
{
s_pbyScrBuffer[z] = byAttr;
}
}
}
GT_UPD_RECT(usTop,usLeft,usBottom,usRight);
HB_GT_FUNC(gt_ScreenUpdate());
}
}
void HB_GT_FUNC(gt_Scroll( USHORT usTop, USHORT usLeft, USHORT usBottom, USHORT usRight, BYTE byAttr, SHORT iRows, SHORT iCols ))
{
USHORT usT, usL, usB, usR, i;
BYTE *pbyScr;
HB_GT_GOBJECT *gobject;
#ifdef DEBUG
HB_TRACE(HB_TR_DEBUG, ("hb_gt_Scroll(%hu, %hu, %hu, %hu, %d, %hd, %hd)", usTop, usLeft, usBottom, usRight, (int) byAttr, iRows, iCols));
#endif
if ( s_pbyScrBuffer == NULL )
{
HB_GT_FUNC(gt_SetMode(_GetScreenHeight(), _GetScreenWidth()));
}
if ( usTop > usBottom )
{
usT = usTop;
usTop = usBottom;
usBottom = usT;
}
if ( usLeft > usRight )
{