-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmgraph.h
1951 lines (1643 loc) · 75.1 KB
/
mgraph.h
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
/****************************************************************************
*
* MegaGraph Graphics Library
*
* Copyright (C) 1996 SciTech Software.
* All rights reserved.
*
* Filename: $Workfile: mgraph.h $
* Version: $Revision: 1.2 $
*
* Language: ANSI C
* Environment: IBM PC (MS DOS)
*
* Description: Header file for the MegaGraph Graphics Library. You can
* defined one of the following to specify which MGL API you
* wish to use.
*
* MGL_LITE - Compile for the MGL/Lite API
* MGL_PRO - Compile for the MGL/Pro API
* MGL_FIX3D - Compile for the MGL/3D API (fixed point)
* MGL_FLT3D - Compile for the MGL/3D API (floating point)
*
* If you do not define any of these, MGL_FIX3D will be defined
* automatically for compatibility with older versions of the
* MGL.
*
* $Date: 2005-07-05 20:01:28 $ $Author: disconn3ct $
*
****************************************************************************/
#ifndef __MGRAPH_H
#define __MGRAPH_H
#include <stdio.h>
#ifndef __DEBUG_H
#include "debug.h"
#endif
#if !defined(MGL_LITE) && !defined(MGL_PRO) && !defined(MGL_FIX3D) \
&& !defined(MGL_FLT3D)
#define MGL_FIX3D
#endif
#if defined(MGL_FIX3D) || defined(MGL_FLT3D)
#define MGL_3D
#endif
/*---------------------- Macros and type definitions ----------------------*/
#pragma pack(1) /* Pack structures to byte granularity */
/* Define the version number for the MGL release */
#define MGL_VERSION_STR "3.1"
/* Define the calling conventions for all public MGL functions. If we
* are compiling the MGL as a DLL, then all public functions are compiled
* and exported with standard C calling conventions, otherwise we use
* the default calling conventions provided by the compiler.
*
* Note that because Watcom C++ uses register based parameter passing
* by default we also provide special DLL's for watcom that are compiled
* with register parameter passing. This is necessary to work with all
* the extra libraries provided as they are all compiled to call MGL
* functions with arguments in registers whenever possible. You can still
* use the standard DLL but if you do you will need to re-compile all
* of the extra libraries with the MGL_DLL #define to change the calling
* conventions for the MGL functions.
*/
#if defined(MGL_DLL)
#define MGLAPI _EXPORT __cdecl
#else
#define MGLAPI _EXPORT _PUBAPI
#endif
#define ASMAPI _EXPORT __cdecl
/* Define a type for integers used in the library. For most environments
* we simply define it as a normal integer (16 or 32 bits), however for
* 16 bit Windows it is defined as a 32 bit integer as all the real code
* lives in a 32 bit DLL that uses 32 bit integers.
*/
#ifndef __M_INT_DEFINED
#if defined(__WINDOWS16__)
typedef long m_int;
typedef unsigned long m_uint;
#else
typedef int m_int;
typedef unsigned int m_uint;
#endif
#define __M_INT_DEFINED
#endif
/* Define the graphics subsystems available */
typedef enum {
grDETECT = -1, /* Auto detect the graphics subsystem */
grNONE = 0, /* No graphics hardware detected */
grVGA, /* Standard VGA */
grVESA, /* VESA VBE compliant SuperVGA */
grSVGA, /* Unaccelerated SuperVGA */
grACCEL, /* Accelerated SuperVGA */
grDDRAW, /* Unaccelerated DirectDraw */
grDDRAWACCEL, /* Accelerated DirectDraw */
grDDRAW3D, /* 3D Accelerated DirectDraw */
grMAXDRIVER, /* Maximum driver number */
} MGL_driverType;
/* Graphics modes supported - the only video modes supported by this
* graphics library are those that support at least 16 colors per pixel.
*/
typedef enum {
/* 16 color VGA video modes */
grVGA_320x200x16,
grVGA_640x200x16,
grVGA_640x350x16,
grVGA_640x400x16,
grVGA_640x480x16,
grSVGA_800x600x16,
/* 256 color VGA ModeX video modes */
grVGAX_320x200x256,
grVGAX_320x240x256,
grVGAX_320x400x256,
grVGAX_320x480x256,
/* 256 color VGA video modes */
grVGA_320x200x256,
/* 256 color VGA/SuperVGA video modes */
grSVGA_320x200x256,
grSVGA_320x240x256,
grSVGA_320x400x256,
grSVGA_320x480x256,
grSVGA_400x300x256,
grSVGA_512x384x256,
grSVGA_640x350x256,
grSVGA_640x400x256,
grSVGA_640x480x256,
grSVGA_800x600x256,
grSVGA_1024x768x256,
grSVGA_1152x864x256,
grSVGA_1280x960x256,
grSVGA_1280x1024x256,
grSVGA_1600x1200x256,
/* 32,768 color Super VGA video modes */
grSVGA_320x200x32k,
grSVGA_320x240x32k,
grSVGA_320x400x32k,
grSVGA_320x480x32k,
grSVGA_400x300x32k,
grSVGA_512x384x32k,
grSVGA_640x350x32k,
grSVGA_640x400x32k,
grSVGA_640x480x32k,
grSVGA_800x600x32k,
grSVGA_1024x768x32k,
grSVGA_1152x864x32k,
grSVGA_1280x960x32k,
grSVGA_1280x1024x32k,
grSVGA_1600x1200x32k,
/* 65,536 color Super VGA video modes */
grSVGA_320x200x64k,
grSVGA_320x240x64k,
grSVGA_320x400x64k,
grSVGA_320x480x64k,
grSVGA_400x300x64k,
grSVGA_512x384x64k,
grSVGA_640x350x64k,
grSVGA_640x400x64k,
grSVGA_640x480x64k,
grSVGA_800x600x64k,
grSVGA_1024x768x64k,
grSVGA_1152x864x64k,
grSVGA_1280x960x64k,
grSVGA_1280x1024x64k,
grSVGA_1600x1200x64k,
/* 16 million color, 24 bits per pixel Super VGA video modes */
grSVGA_320x200x16m,
grSVGA_320x240x16m,
grSVGA_320x400x16m,
grSVGA_320x480x16m,
grSVGA_400x300x16m,
grSVGA_512x384x16m,
grSVGA_640x350x16m,
grSVGA_640x400x16m,
grSVGA_640x480x16m,
grSVGA_800x600x16m,
grSVGA_1024x768x16m,
grSVGA_1152x864x16m,
grSVGA_1280x960x16m,
grSVGA_1280x1024x16m,
grSVGA_1600x1200x16m,
/* 16 million color, 32 bits per pixel Super VGA video modes */
grSVGA_320x200x4G,
grSVGA_320x240x4G,
grSVGA_320x400x4G,
grSVGA_320x480x4G,
grSVGA_400x300x4G,
grSVGA_512x384x4G,
grSVGA_640x350x4G,
grSVGA_640x400x4G,
grSVGA_640x480x4G,
grSVGA_800x600x4G,
grSVGA_1024x768x4G,
grSVGA_1152x864x4G,
grSVGA_1280x960x4G,
grSVGA_1280x1024x4G,
grSVGA_1600x1200x4G,
/* Render into Windowing System DC (Windows, OS/2 PM, X11) */
grWINDOWED,
grMAXMODE, /* Maximum mode number */
} MGL_modeType;
/* MGL_result() error codes */
typedef enum {
grOK = 0, /* No error */
grNoInit = -1, /* Graphics driver has not been installed */
grNotDetected = -2, /* Graphics hardware was not detected */
grDriverNotFound= -3, /* Graphics driver file not found */
grBadDriver = -4, /* File loaded was not a graphics driver */
grLoadMem = -5, /* Not enough memory to load graphics driver*/
grInvalidMode = -6, /* Invalid graphics mode for selected driver*/
grError = -8, /* General graphics error */
grInvalidName = -9, /* Invalid driver name */
grNoMem = -10, /* Not enough memory to perform operation */
grNoModeSupport = -11, /* Select video mode not supported by hard. */
grInvalidFont = -12, /* Invalid font data */
grBadFontFile = -13, /* File loaded was not a font file */
grFontNotFound = -14, /* Font file was not found */
grOldDriver = -15, /* Driver file is an old version */
grInvalidDevice = -16, /* Invalid device for selected operation */
grInvalidDC = -17, /* Invalid device context */
grInvalidCursor = -18, /* Invalid cursor file */
grCursorNotFound= -19, /* Cursor file was not found */
grInvalidIcon = -20, /* Invalid icon file */
grIconNotFound = -21, /* Icon file was not found */
grInvalidBitmap = -22, /* Invalid bitmap file */
grBitmapNotFound= -23, /* Bitmap file was not found */
grZbufferTooBig = -24, /* Zbuffer allocation is too large */
grNewFontFile = -25, /* Only Windows 2.x font files supported */
grNoDoubleBuff = -26, /* Double buffering is not available */
grNoHardwareBlt = -28, /* No hardware bitBlt for OffscreenDC */
grNoOffscreenMem= -29, /* No available offscreen memory */
grInvalidPF = -30, /* Invalid pixel format for memory DC */
grLastError = -31, /* Last error number in list */
} MGL_errorType;
#define MGL_CLIPON true
#define MGL_CLIPOFF false
/* Color mapped modes */
typedef enum {
MGL_CMAP_MODE, /* Normal Color mapped mode */
MGL_DITHER_RGB_MODE, /* 24 bit RGB halftone dithered */
} MGL_colorModes;
/* Standard colors - this is the standard set of colors for the IBM PC. The
* default palette will have been programmed to contain these values when a
* graphics modes is started. If the palette has been changed, they will
* not correspond to the actual colors on the screen. Under a Windowing
* manage environment these colors will also not be setup by default.
*/
enum MGL_COLORS {
MGL_BLACK, /* dark colors */
MGL_BLUE,
MGL_GREEN,
MGL_CYAN,
MGL_RED,
MGL_MAGENTA,
MGL_BROWN,
MGL_LIGHTGRAY,
MGL_DARKGRAY, /* light colors */
MGL_LIGHTBLUE,
MGL_LIGHTGREEN,
MGL_LIGHTCYAN,
MGL_LIGHTRED,
MGL_LIGHTMAGENTA,
MGL_YELLOW,
MGL_WHITE,
};
/* Windows standard color indices for 256 color bitmaps. 8,9,246,247 are
* reserved and you should not count on these colors always being the
* same. For 16 color bitmaps, colors 248-255 map to colors 8-15.
*/
enum MGL_WIN_COLORS {
MGL_WIN_BLACK = 0,
MGL_WIN_DARKRED = 1,
MGL_WIN_DARKGREEN = 2,
MGL_WIN_DARKYELLOW = 3,
MGL_WIN_DARKBLUE = 4,
MGL_WIN_DARKMAGENTA = 5,
MGL_WIN_DARKCYAN = 6,
MGL_WIN_LIGHTGRAY = 7,
MGL_WIN_TURQUOISE = 8, /* Reserved; dont count on this */
MGL_WIN_SKYBLUE = 9, /* Reserved; dont count on this */
MGL_WIN_CREAM = 246, /* Reserved; dont count on this */
MGL_WIN_MEDIUMGRAY = 247, /* Reserved; dont count on this */
MGL_WIN_DARKGRAY = 248,
MGL_WIN_LIGHTRED = 249,
MGL_WIN_LIGHTGREEN = 250,
MGL_WIN_LIGHTYELLOW = 251,
MGL_WIN_LIGHTBLUE = 252,
MGL_WIN_LIGHTMAGENTA = 253,
MGL_WIN_LIGHTCYAN = 254,
MGL_WIN_WHITE = 255,
};
typedef enum {
MGL_MARKER_SQUARE,
MGL_MARKER_CIRCLE,
MGL_MARKER_X,
} MGL_markerStyleType;
typedef enum { /* Write mode operators */
MGL_REPLACE_MODE, /* Replace mode */
MGL_AND_MODE, /* AND mode */
MGL_OR_MODE, /* OR mode */
MGL_XOR_MODE, /* XOR mode */
} MGL_writeModeType;
typedef enum {
MGL_BITMAP_SOLID,
MGL_BITMAP_OPAQUE,
MGL_BITMAP_TRANSPARENT,
MGL_PIXMAP,
} MGL_fillStyleType;
typedef enum {
MGL_LINE_PENSTYLE, /* Line drawn in current pen style */
MGL_LINE_STIPPLE, /* Line drawn with current stipple */
} MGL_lineStyleType;
typedef enum {
MGL_CONVEX_POLYGON, /* Monotone vertical polygon */
MGL_COMPLEX_POLYGON, /* Non-Simple polygons */
MGL_AUTO_POLYGON, /* Auto detect the polygon type */
} MGL_polygonType;
/* Text manipulation defines */
typedef enum {
MGL_LEFT_TEXT = 0, /* Justify from left */
MGL_TOP_TEXT = 0, /* Justify from top */
MGL_CENTER_TEXT = 1, /* Center the text */
MGL_RIGHT_TEXT = 2, /* Justify from right */
MGL_BOTTOM_TEXT = 2, /* Justify from bottom */
MGL_BASELINE_TEXT = 3, /* Justify from the baseline */
} MGL_textJustType;
typedef enum {
MGL_LEFT_DIR = 0, /* Text goes to left */
MGL_UP_DIR = 1, /* Text goes up */
MGL_RIGHT_DIR = 2, /* Text goes right */
MGL_DOWN_DIR = 3, /* Text goes down */
} MGL_textDirType;
/* Font types */
typedef enum {
MGL_VECTORFONT = 1, /* Vector font */
MGL_FIXEDFONT, /* Fixed width bitmap font */
MGL_PROPFONT, /* Proportional width bitmap font */
} MGL_fontType;
/* Palette rotation directions */
typedef enum {
MGL_ROTATE_UP, /* Rotate the palette values up */
MGL_ROTATE_DOWN, /* Rotate the palette values down */
} MGL_palRotateType;
/* Border drawing routine styles */
typedef enum {
MGL_BDR_INSET, /* Interior is inset into screen */
MGL_BDR_OUTSET, /* Interior is outset from screen */
MGL_BDR_OUTLINE, /* Border is 3d outline */
} MGL_bdrStyleType;
/* Standard display driver names */
#define MGL_VGA4NAME "VGA4.DRV" /* Standard VGA drivers */
#define MGL_VGA8NAME "VGA8.DRV"
#define MGL_VGAXNAME "VGAX.DRV"
#define MGL_SVGA4NAME "SVGA4.DRV" /* Generic SuperVGA drivers */
#define MGL_SVGA8NAME "SVGA8.DRV"
#define MGL_SVGA16NAME "SVGA16.DRV"
#define MGL_SVGA24NAME "SVGA24.DRV"
#define MGL_SVGA32NAME "SVGA32.DRV"
#define MGL_LINEAR8NAME "LINEAR8.DRV" /* Linear framebuffer drivers */
#define MGL_LINEAR16NAME "LINEAR16.DRV"
#define MGL_LINEAR24NAME "LINEAR24.DRV"
#define MGL_LINEAR32NAME "LINEAR32.DRV"
#define MGL_ACCEL8NAME "ACCEL8.DRV" /* VBE/AF Accelerated drivers */
#define MGL_ACCEL16NAME "ACCEL16.DRV"
#define MGL_ACCEL24NAME "ACCEL24.DRV"
#define MGL_ACCEL32NAME "ACCEL32.DRV"
#define MGL_DDRAW8NAME "DDRAW8.DRV" /* DirectDraw drivers */
#define MGL_DDRAW16NAME "DDRAW16.DRV"
#define MGL_DDRAW24NAME "DDRAW24.DRV"
#define MGL_DDRAW32NAME "DDRAW32.DRV"
/* Standard memory driver names */
#define MGL_PACKED1NAME "PACK1.DRV"
#define MGL_PACKED4NAME "PACK4.DRV"
#define MGL_PACKED8NAME "PACK8.DRV"
#define MGL_PACKED16NAME "PACK16.DRV"
#define MGL_PACKED24NAME "PACK24.DRV"
#define MGL_PACKED32NAME "PACK32.DRV"
/* Standard bitmap names */
#define MGL_EMPTY_FILL _MGL_getEmptyPat()
#define MGL_GRAY_FILL _MGL_getGrayPat()
#define MGL_SOLID_FILL _MGL_getSolidPat()
/* Event message masks for keyDown events */
#define EVT_ASCIIMASK 0x00FF /* Ascii code of key pressed */
#define EVT_SCANMASK 0xFF00 /* Scan code of key pressed */
#define EVT_COUNTMASK 0x7FFF0000L /* Count for KEYREPEAT's */
#define EVT_asciiCode(m) ( (uchar) (m & EVT_ASCIIMASK) )
#define EVT_scanCode(m) ( (uchar) ( (m & EVT_SCANMASK) >> 8 ) )
#define EVT_repeatCount(m) ( (short) ( (m & EVT_COUNTMASK) >> 16 ) )
/* Event message masks for mouse events */
#define EVT_LEFTBMASK 0x0001 /* Left button is bit 0 */
#define EVT_RIGHTBMASK 0x0004 /* Right button is bit 1 */
#define EVT_BOTHBMASK 0x0005 /* Both left and right together */
#define EVT_ALLBMASK 0x0005 /* All buttons pressed */
/* Modifier masks */
#define EVT_LEFTBUT 0x0001 /* Set if left button was down */
#define EVT_RIGHTBUT 0x0002 /* Set if right button was down */
#define EVT_RIGHTSHIFT 0x0008 /* Set if right shift down */
#define EVT_LEFTSHIFT 0x0010 /* Set if left shift down */
#define EVT_CTRLSTATE 0x0020 /* Set if ctrl key down */
#define EVT_ALTSTATE 0x0040 /* Set if alt key down */
#define EVT_LEFTCTRL 0x0080 /* Set if left ctrl key down */
#define EVT_LEFTALT 0x0100 /* Set if left alt key down */
#define EVT_SHIFTKEY 0x0018 /* Any shift key */
/* Event codes */
#define EVT_NULLEVT 0x0000 /* A null event */
#define EVT_KEYDOWN 0x0001 /* Key down event */
#define EVT_KEYREPEAT 0x0002 /* Key repeat event */
#define EVT_KEYUP 0x0004 /* Key up event */
#define EVT_MOUSEDOWN 0x0008 /* Mouse down event */
#define EVT_MOUSEUP 0x0010 /* Mouse up event */
#define EVT_MOUSEMOVE 0x0020 /* Mouse movement event */
#define EVT_TIMERTICK 0x0040 /* Timer tick event */
#define EVT_USEREVT 0x0080 /* First user event */
/* Event code masks */
#define EVT_KEYEVT (EVT_KEYDOWN | EVT_KEYREPEAT | EVT_KEYUP)
#define EVT_MOUSEEVT (EVT_MOUSEDOWN | EVT_MOUSEUP | EVT_MOUSEMOVE)
#define EVT_MOUSECLICK (EVT_MOUSEDOWN | EVT_MOUSEUP)
#define EVT_EVERYEVT 0xFFFF
/* Suspend Application callback type codes. This callback is called
* when the user presses one of the corresponding keys indicating that
* they wish to change the active application. The MGL will catch these
* events and if you have registered a callback, will call the callback to
* save the state of the application so that it can be properly restored
* when the user switches back to your application. The MGL takes care of
* all the details about saving and restoring the state of the hardware,
* and all your application needs to do is save its own state so that you can
* re-draw the application screen upon re-activation.
*
* NOTE: Your application suspend callback may get called twice with the
* MGL_DEACTIVATE flag in order to test whether the switch should
* occur (under both DirectDraw and WinDirect fullscreen modes).
*
* NOTE: When your callback is called with the MGL_DEACTIVATE flag, you
* cannot assume that you have access to the display memory surfaces
* as they may have been lost by the time your callback has been called.
*/
#define MGL_DEACTIVATE 0x0001 /* Application losing active focus */
#define MGL_REACTIVATE 0x0002 /* Application regaining active focus */
/* Return codes from the suspend application callback. The normal value
* to be returned is MGL_SUSPEND_APP and this will cause the app to be
* suspended while back in GDI mode until the app is re-activated again
* by the user.
*
* MGL_NO_DEACTIVATE signals to WinDirect that the application does not want
* to allow switching to occur, and the switch request will be ignored and
* the app will remain in fullscreen mode.
*
* MGL_NO_SUSPEND_APP can be used to tell WinDirect to switch back to the
* desktop, but not to suspend the application. This must be used with
* care as the suspend application callback is then responsible for setting
* a flag in the application that will stop the application from doing any
* rendering to the framebuffer while the application is in GDI mode. This
* return value is useful for games that need to maintain network
* connectivity while the user has temporarily switched back to GDI mode.
*/
#define MGL_NO_DEACTIVATE 0 /* Dont allow app to be deactivated */
#define MGL_SUSPEND_APP 1 /* Suspend application until restored */
#define MGL_NO_SUSPEND_APP 2 /* Dont suspend, but allow switch */
/* Here we define the structures used to represent points and rectangles */
typedef struct {
m_int x,y;
} point_t;
typedef struct {
m_int left;
m_int top;
m_int right;
m_int bottom;
} rect_t;
/* All colors are represented as longs by the library. This allows
* code to work correctly with up to 24 bit color device drivers. The
* device drivers themselves expect the color to be a color index if in
* a color mapped mode, or a 15/16/24 bit RGB tuple in a hicolor or truecolor
* mode. You can use the appropriate routines to pack and unpack
* colors into the color_t format.
*/
typedef ulong color_t;
/* Define the value used to clear the software ZBuffer. The MGL always uses
* a > operator for the z compare, and the smallest value is 0.
*/
#define MGL_ZCLEARVAL 0
/* Structures for passing vertex information to polygon rendering routines.
* All fixed point coordinates are passed in 16.16 signed fixed point
* format, while zbuffer coordinates are passed in 4.28 signed fixed point
* format. The sign bit is used purely for overflow and arithmetic
* internally, and all user passed zbuffer values should be greater than
* 0. All shaded rendering routines either take a color index in 8.16 fixed
* point format (range 0-255.9) or separate RGB components in 8.16 fixed
* point format (range 0-255.9).
*/
#ifdef __FX_FIXED_H
#define fix32_t FXFixed
#else
typedef long fix32_t;
#endif
typedef fix32_t fxcolor_t;
typedef long zfix32_t;
typedef struct {
fix32_t x,y;
} fxpoint_t;
typedef struct {
fxcolor_t r,g,b;
} fxrgb_t;
typedef struct {
fix32_t w,s,t;
} fxtex_t;
typedef struct {
fxcolor_t c;
fxpoint_t p;
} fxpointc_t;
typedef struct {
fxrgb_t c;
fxpoint_t p;
} fxpointrgb_t;
typedef struct {
fxpoint_t p;
zfix32_t z;
} fxpointz_t;
typedef struct {
fxcolor_t c;
fxpoint_t p;
zfix32_t z;
} fxpointcz_t;
typedef struct {
fxrgb_t c;
fxpoint_t p;
zfix32_t z;
} fxpointrgbz_t;
/* Macros to convert between integer and 32 bit fixed point format */
#define MGL_FIX_1 0x10000L
#define MGL_FIX_2 0x20000L
#define MGL_FIX_HALF 0x08000L
#define MGL_TOFIX(i) ((long)(i) << 16)
#define MGL_FIXTOINT(f) ((m_int)((f) >> 16))
#define MGL_FIXROUND(f) ((m_int)(((f) + MGL_FIX_HALF) >> 16))
#define MGL_ZFIX_1 0x10000000L
#define MGL_ZFIX_HALF 0x08000000L
#define MGL_FIXTOZ(i) ((i) << 12)
#define MGL_ZTOFIX(i) ((i) >> 12)
#define MGL_TOZFIX(i) ((long)(i) << 28)
#define MGL_ZFIXTOINT(f) ((m_int)((f) >> 28))
#define MGL_ZFIXROUND(f) ((m_int)(((f) + MGL_ZFIX_HALF) >> 28))
/* Region structure */
#ifdef BUILD_MGL
struct _span_t;
typedef struct _span_t span_t;
#else
typedef void span_t;
#endif
typedef struct {
rect_t rect; /* Bounding rectangle for region */
span_t *spans; /* Start of span list for region */
} region_t;
/* Palette entry structure */
typedef struct {
uchar blue; /* Blue component of color */
uchar green; /* Green component of color */
uchar red; /* Blue component of color */
uchar alpha; /* Alpha or alignment byte */
} palette_t;
/* Maximum value for each palette entry component */
#define PALMAX 255 /* Max value for palette components */
/* Pixel format structure */
typedef struct {
uchar redMask,greenMask; /* Mask values for pixels */
uchar blueMask,rsvdMask;
m_int redPos,redAdjust; /* Red position and adjustment */
m_int greenPos,greenAdjust; /* Green position and adjustment */
m_int bluePos,blueAdjust; /* Blue position and adjustment */
m_int rsvdPos,rsvdAdjust; /* Reserved position and adjustment */
} pixel_format_t;
/* Structure to hold arc coordinate information */
typedef struct {
m_int x,y; /* Centre point of the arc */
m_int startX,startY; /* Starting point on arc */
m_int endX,endY; /* Ending point on arc */
} arc_coords_t;
/* Mouse cursor structure */
typedef struct {
ulong xorMask[32];
ulong andMask[32];
m_int xHotSpot;
m_int yHotSpot;
} cursor_t;
/* Bitmap structure - always packed pixel DIB format */
typedef struct {
m_int width; /* Width of bitmap in pixels */
m_int height; /* Height of bitmap in pixels */
m_int bitsPerPixel; /* Pixel width */
m_int bytesPerLine; /* Bytes per line value for surface */
uchar *surface; /* Pointer to bitmap surface */
palette_t *pal; /* Palette (NULL if not loaded) */
pixel_format_t *pf; /* Pixel format (NULL if none) */
/* ... palette, pixel format and bitmap data are store contiguously */
} bitmap_t;
/* Icon structure - can be 32x23, 64x64 or in fact any size */
typedef struct {
m_int byteWidth; /* Byte with for AND mask */
uchar *andMask; /* Hold punch mask for icon */
bitmap_t xorMask; /* XOR mask for the icon */
/* ... AND mask and bitmap structure are stored contiguously */
} icon_t;
/* Default cursor name */
#define MGL_DEF_CURSOR _MGL_getDefCursor()
/* Generic Font structure */
#define _MGL_FNAMESIZE 58
typedef struct {
char name[_MGL_FNAMESIZE];/* Name of the font */
short fontType; /* Type of font */
short maxWidth; /* Maximum character width */
short maxKern; /* Maximum character kern */
short fontWidth; /* Font width */
short fontHeight; /* Font height */
short ascent; /* Font ascent value */
short descent; /* Font descent value */
short leading; /* Font leading value */
} font_t;
/* Character and font metrics structure */
typedef struct {
m_int width; /* Width of character or font */
m_int fontWidth; /* Character width (tightest fit) */
m_int fontHeight; /* Height of the font */
m_int ascent; /* Ascent value */
m_int descent; /* Descent value */
m_int leading; /* Leading value */
m_int kern; /* Kern value */
} metrics_t;
/* Text settings structure */
typedef struct {
m_int horizJust; /* Horizontal justfication */
m_int vertJust; /* Vertical justification */
m_int dir; /* Text drawing direction */
m_int szNumerx; /* Text x size numerator */
m_int szNumery; /* Text y size numerator */
m_int szDenomx; /* Text x size denominator */
m_int szDenomy; /* Text y size denominator */
m_int spaceExtra; /* Space extra term */
font_t *font; /* Currently selected font */
} text_settings_t;
/* Macros to access the (left,top) and (right,bottom) points of a
* rectangle.
*/
#define MGL_leftTop(r) (((point_t *) &(r))[0])
#define MGL_rightBottom(r) (((point_t *) &(r))[1])
typedef uchar pattern_t[8];
typedef color_t pixpattern_t[8][8];
/* Attributes structure */
typedef struct {
color_t color; /* Foreground color */
color_t backColor; /* Background color */
m_int colorMode; /* Current color mode */
m_int markerSize; /* Size of markers in pixels */
m_int markerStyle; /* Style of markers */
color_t markerColor; /* Color to draw markers in */
color_t bdrBright; /* Border bright color */
color_t bdrDark; /* Border dark color */
point_t CP; /* Graphics pen position */
m_int writeMode; /* Scan conversion write mode op. */
m_int penStyle; /* Pen style */
m_int penHeight; /* Height of pen */
m_int penWidth; /* Width of pen */
pattern_t penPat; /* Pattern for pen */
pixpattern_t penPixPat; /* Pixmap pattern for pen */
m_int lineStyle; /* Line style */
ushort lineStipple; /* Line stipple */
m_uint stippleCount; /* Current line stipple count */
rect_t viewPort; /* Viewport dimensions */
point_t viewPortOrg; /* Logical viewport origin */
rect_t clipRect; /* Clipping rectangle dimensions */
m_int clip; /* Is clipping on? */
m_int polyType; /* Polygon drawing type */
text_settings_t ts; /* Text drawing attributes */
} attributes_t;
/* Mode specific format information. This structrure can be used by
* the device driver to build tables of values for all supported modes
*/
typedef struct {
m_int xRes; /* Device x resolution - 1 */
m_int yRes; /* Device y resolution - 1 */
m_int bitsPerPixel; /* Number of bits per pixel */
m_int numberOfPlanes; /* Number of planes in image */
color_t maxColor; /* Maximum number of colors - 1 */
m_int maxPage; /* Maximum number of video pages - 1 */
m_int bytesPerLine; /* Number of bytes in a line */
m_int aspectRatio; /* Mode aspect ratio (horiz/vert * 1000) */
long pageSize; /* Number of bytes in a page */
m_int scratch1; /* Scratch pad value 1 */
m_int scratch2; /* Scratch pad value 2 */
char redMaskSize; /* Size of direct color red mask */
char redFieldPosition; /* Bit posn of lsb of red mask */
char greenMaskSize; /* Size of direct color green mask */
char greenFieldPosition; /* Bit posn of lsb of green mask */
char blueMaskSize; /* Size of direct color blue mask */
char blueFieldPosition; /* Bit posn of lsb of blue mask */
char rsvdMaskSize; /* Size of reserved mask */
char rsvdFieldPosition; /* Bit posn of reserved mask */
} gmode_t;
/* Public Device Context Structure. The 'surface' member along with the
* gmode_t information block, provides direct access to the active
* display surface for user applications. The MGL virtualises the surface
* in SuperVGA modes that dont have a real linear framebuffer.
*/
typedef struct {
attributes_t a; /* Active device attributes */
void *surface; /* Pointer to active device surface */
void *zbuffer; /* Pointer to Z-buffer if allocated */
m_int zbits; /* Bits per zbuffer element */
m_int zwidth; /* Width of the zbuffer in pixels */
gmode_t mi; /* Mode specific information block */
pixel_format_t pf; /* Current pixel format for device context */
color_t *colorTab; /* Color lookup table cache */
color_t *shadeTab; /* Currently active shade table */
m_int bankOffset; /* Offset of starting bank number */
/* Remainder of Device Context structure is private and internal */
} publicDevCtx_t;
#ifndef BUILD_MGL
typedef publicDevCtx_t MGLDC;
#else
struct internalDevCtx_t;
typedef struct internalDevCtx_t MGLDC;
#endif
typedef struct {
ulong which; /* Which window for window manager code */
m_uint what; /* Event code */
ulong when; /* Clock ticks since midnight */
m_int where_x; /* Mouse location */
m_int where_y;
ulong message; /* Event specific message */
ulong modifiers; /* Modifier flags */
m_int next; /* Next event in queue */
m_int prev; /* Previous event in queue */
} event_t;
/* Structure containing file I/O functions allowing the user application to
* completely replace the MGL's file I/O functions with their own. This
* allows the app to store all MGL related files in a single large file,
* with encryption or compression is desired. By default normal file I/O
* functions will be used.
*/
typedef struct {
FILE * (*fopen)(const char *filename,const char *mode);
int (*fclose)(FILE *f);
int (*fseek)(FILE *f,long offset,int whence);
long (*ftell)(FILE *f);
size_t (*fread)(void *ptr,size_t size,size_t n,FILE *f);
size_t (*fwrite)(const void *ptr,size_t size,size_t n,FILE *f);
} fileio_t;
/* Define the flags for the types of direct surface access provided */
#define MGL_NO_ACCESS 0x0 /* Surface cannot be accessed */
#define MGL_VIRTUAL_ACCESS 0x1 /* Surface is virtualised */
#define MGL_LINEAR_ACCESS 0x2 /* Surface can be linearly accessed */
#define MGL_SURFACE_FLAGS 0x3
/* Define the flags for the types of direct zbuffer access provided */
#define MGL_NO_ZACCESS 0x0 /* Zbuffer cannot be accessed */
#define MGL_VIRTUAL_ZACCESS 0x4 /* Zbuffer is virtualised in */
#define MGL_LINEAR_ZACCESS 0x8 /* Zbuffer can be linearly accessed */
#define MGL_ZBUFFER_FLAGS 0xC
/* Define the flags for the types of hardware acceleration supported by
* the device context. This will allow the application to tailor the use of
* MGL functions depending upon whether specific hardware support is
* available. Hence applications can use specialised software rendering
* support if the desired hardware support is not available.
*
* NOTE: If the hardware flags are not MGL_HW_NONE, you *must* call
* the MGL_beginDirectAccess() and MGL_endDirectAccess() functions
* before and after any custom code that does direct framebuffer
* rendering!!
*
* This is not necessary for non-accelerated device context, so you
* might want to optimise these calls out if there is no hardware
* acceleration support.
*/
#define MGL_HW_NONE 0x0000 /* No hardware acceleration */
#define MGL_HW_LINE 0x0010 /* Hardware line drawing */
#define MGL_HW_STIPPLE_LINE 0x0020 /* Hardware stippled line drawing */
#define MGL_HW_POLY 0x0040 /* Hardware polygon filling */
#define MGL_HW_RECT 0x0080 /* Hardware rectangle fill */
#define MGL_HW_PATT_RECT 0x0100 /* Hardware pattern rectangle fill */
#define MGL_HW_CLRPATT_RECT 0x0200 /* Hardware color pattern fill */
#define MGL_HW_SCR_BLT 0x0400 /* Hardware screen/screen bitBlt */
#define MGL_HW_SRCTRANS_BLT 0x0800 /* Hardware source transparent blt */
#define MGL_HW_DSTTRANS_BLT 0x1000 /* Hardware dest. transparent blt */
#define MGL_HW_MONO_BLT 0x2000 /* Hardware monochrome blt */
#define MGL_HW_CLIP 0x4000 /* Hardware clipping */
#define MGL_HW_FLAGS 0xFFF0
#ifdef __cplusplus
extern "C" { /* Use "C" linkage when in C++ mode */
#endif
/*------------------------- Function Prototypes ---------------------------*/
/*---------------------------------------------------------------------------
* Routines bound to a specific device context. These routines all take
* an MGLDC as a parmeter for the context to work with and hence dont work
* with the current context. If however the context passed is the currently
* active context, all changes to that context are reflected in the
* currently active context as well.
*-------------------------------------------------------------------------*/
/* Environment detection and initialisation */
m_int MGLAPI MGL_registerDriver(const char *name,void *driver);
void MGLAPI MGL_unregisterAllDrivers(void);
void MGLAPI MGL_registerAllDispDrivers(bool useLinear,bool useDirectDraw,bool useWinDirect);
void MGLAPI MGL_registerAllMemDrivers(void);
void MGLAPI MGL_detectGraph(m_int *driver,m_int *mode);
uchar * MGLAPI MGL_availableModes(void);
m_int MGLAPI MGL_availablePages(m_int mode);
m_int MGLAPI MGL_modeResolution(m_int mode,m_int *xRes,m_int *yRes,m_int *bitsPerPixel);
bool MGLAPI MGL_isDisplayDC(MGLDC *dc);
bool MGLAPI MGL_isWindowedDC(MGLDC *dc);
bool MGLAPI MGL_isMemoryDC(MGLDC *dc);
void MGLAPI MGL_exit(void);
void MGLAPI MGL_setBufSize(unsigned size);
void MGLAPI MGL_fatalError(const char *msg);
m_int MGLAPI MGL_result(void);
void MGLAPI MGL_setResult(m_int result);
const char * MGLAPI MGL_errorMsg(m_int err);
const char * MGLAPI MGL_modeName(m_int mode);
const char * MGLAPI MGL_modeDriverName(m_int mode);
const char * MGLAPI MGL_driverName(m_int driver);
m_int MGLAPI MGL_getDriver(MGLDC *dc);
m_int MGLAPI MGL_getMode(MGLDC *dc);
m_int MGLAPI MGL_surfaceAccessType(MGLDC *dc);
m_int MGLAPI MGL_zbufferAccessType(MGLDC *dc);
long MGLAPI MGL_getHardwareFlags(MGLDC *dc);
void MGLAPI MGL_defaultAttributes(MGLDC *dc);
void MGLAPI MGL_makeSubDC(MGLDC *dc,m_int left,m_int top,m_int right,m_int bottom);
/* Viewport and clip rectangle manipulation bound to a specific DC */
void MGLAPI MGL_setViewportDC(MGLDC *dc,rect_t view);
void MGLAPI MGL_setRelViewportDC(MGLDC *dc,rect_t view);
void MGLAPI MGL_getViewportDC(MGLDC *dc,rect_t *view);
void MGLAPI MGL_setViewportOrgDC(MGLDC *dc,point_t org);
void MGLAPI MGL_getViewportOrgDC(MGLDC *dc,point_t *org);
void MGLAPI MGL_globalToLocalDC(MGLDC *dc,point_t *p);
void MGLAPI MGL_localToGlobalDC(MGLDC *dc,point_t *p);
m_int MGLAPI MGL_maxxDC(MGLDC *dc);
m_int MGLAPI MGL_maxyDC(MGLDC *dc);
void MGLAPI MGL_setClipRectDC(MGLDC *dc,rect_t clip);
void MGLAPI MGL_getClipRectDC(MGLDC *dc,rect_t *clip);
void MGLAPI MGL_setClipModeDC(MGLDC *dc,bool mode);
bool MGLAPI MGL_getClipModeDC(MGLDC *dc);
/* Color and palette manipulation */
color_t MGLAPI MGL_realColor(MGLDC *dc,m_int color);
color_t MGLAPI MGL_rgbColor(MGLDC *dc,uchar R,uchar G,uchar B);
void MGLAPI MGL_setPaletteEntry(MGLDC *dc,m_int entry,uchar red,uchar green,uchar blue);
void MGLAPI MGL_getPaletteEntry(MGLDC *dc,m_int entry,uchar *red,uchar *green,uchar *blue);
void MGLAPI MGL_setPalette(MGLDC *dc,palette_t *pal,m_int numColors,m_int startIndex);
void MGLAPI MGL_getPalette(MGLDC *dc,palette_t *pal,m_int numColors,m_int startIndex);
void ASMAPI MGL_rotatePalette(MGLDC *dc,m_int numColors,m_int startIndex,m_int direction);