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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
|
%
% $Id: graph.tex,v 1.1 2000/07/13 06:30:51 michael Exp $
% This file is part of the FPC documentation.
% Copyright (C) 1997,1999-2000 by the Free Pascal Development team
%
% The FPC documentation is free text; you can redistribute it and/or
% modify it under the terms of the GNU Library General Public License as
% published by the Free Software Foundation; either version 2 of the
% License, or (at your option) any later version.
%
% The FPC Documentation 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
% Library General Public License for more details.
%
% You should have received a copy of the GNU Library General Public
% License along with the FPC documentation; see the file COPYING.LIB. If not,
% write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
% Boston, MA 02111-1307, USA.
%
% Documentation for the 'Graph' unit of Free Pascal.
% Michael Van Canneyt, July 1997
% Carl Eric Codere, April 1999
\chapter{The GRAPH unit.}
This document describes the \textbf{GRAPH} unit for Free Pascal. This unit includes
more then 50 graphics routines, that range from low-level calls such as putpixel
to high level calls like Circle and Bar3D. Different fill styles and line
patterns are supported in most of the routines.
\section{Overview}
\label{se:Overview}
\subsection{Compatibility}
Since the graph unit included with \var{fpc} is a portable implementation of
the Turbo Pascal unit, there are some slight differences between the video
modes and features.
\subsubsection{Initialization}
Each graph unit implementation, will have a 320x200 resolution refered to
\textit{LowResolution}. If the hardware for the specific platform does
not support that resolution, then it will have to be emulated. Apart
from that requirement, all other resolutions will be dependant on the
target platform.
The correct way and portable way to initialize to graphics subsystem, is
to first query the hardware, and then from that, decide which mode you
wish to support. The routine which does this is called \textit{QueryAdapterInfo}.
This routine returns a linked list of modes availables, and their
mode number as well as driver numbers. It is to note that this list is
initialized only once during the lifetime of the application (that is,
even if CloseGraph is called, the list will still be valid). The memory
allocated for this list is automatically freed as part as the graph
unit's exit procedure.
You can always use Detect as a parameter to \textit{InitGraph}
which will initialize the graphics to the highest resolution possible.
The following constants are also defined for compatiblity with older
applications written with Turbo Pascal, they should no longer be used:
\begin{tabular}{|c|c|c|}
\hline
Driver Name & Constant Name & Column x Row & Colors \\ \hline
VGA & VGAHi & 640x480 & 16 \\
VGA & VGALo & 640x200 & 16 \\
VGA & VGAMed & 640x350 & 16 \\
VGA & VGA256 & 320x200 & 256 \\
\hline
\end{tabular}
\subsubsection{Other differences}
Some notable differences with the Turbo Pascal graph unit are noted
below:
\begin{itemize}
\item \textit{Rectangle} do not write
the end points twice, which permits the XORPut write mode to be used
effectively for erasing these forms on the screen.
\item \textit{RegisterBGIDriver} and \textit{InstallUserDriver} always
return errors, as they are not directly supported.
\item \textit{DrawPoly} XORPut write mode does not have the same behaviour
as the one in the Turbo Pascal graph unit.
\item XORPut write mode is not supported by \textit{Bar3d}.
\item Passing invalid parameters to \textit{SetTextStyle} will not
result in the same visual appearance. Make sure your input is valid.
\item All routines using sines/cosines (e.g: \textit{circle}), don't
exactly have the same radii, because the aspect ratio correction is
different.
\item PutImage supports clipping.
\item \textit{SetRGBPalette} use the LSB's of the RGB components to
set the color values of the palette. This makes the unit more portable.
\item \textit{PaletteType} is different then the Turbo Pascal version,
it uses RGB Values for the palettes.
\item \textit{SetAllPalette} is different then the Turbo Pascal version,
it uses the PaletteType as a parameter.
\item \textit{GetDefaultPalette} only returns only at most the 256 first
default entries of a palette, even if the mode supports more then
256 colors.
\end{itemize}
\subsection{Coordinate system}
The upper left of the graphics screen is located at position (0,0). The x
value, which represents the column, increments to the right. The y values,
or rows, increment downward. The maximum value which can be set for an x
value, for the graphics screen is given by the \textit{GetMaxX} routine.
The same is true for the y coordinate, except a call to \textit{GetMaxY}
is required.
\subsection{Current pointer}
Some graphics routines support the concept of the current pointer (CP). The
current pointer is similar in concept to a text cursor, except that it is
invisible.
When you write in text mode, the text cursor is automatically incremented
by the number of characters written. The same is true with the graphics
current pointer, which is instead incremented on a pixel basis.
For example, the following:
\begin{verbatim}
MoveTo(0,0);
LineTo(100,100);
\end{verbatim}
will leave the current pointer to the (100,100) coordinate pair. The
pixels might not be drawn depending on your clipping settings, but the
CP is never clipped to clipping boundaries.
The following routines set the CP to the new position:
\begin{itemize}
\item \textit{ClearDevice}
\item \textit{ClearViewPort}
\item \textit{GraphDefaults}
\item \textit{InitGraph}
\item \textit{LineRel}
\item \textit{LineTo}
\item \textit{MoveRel}
\item \textit{MoveTo}
\item \textit{OutText}
\item \textit{SetGraphMode}
\item \textit{SetViewPort}
\end{itemize}
\subsection{Error handling}
There is only basic error checking in the graph unit. To get the value of
the last error returned by a graphics driver call, call the
\textit{GraphResult} routine. The following routines can set error codes,
others don't :
\begin{itemize}
\item \textit{Bar} --- ok
\item \textit{Bar3D} --- ok
\item \textit{ClearViewPort}
\item \textit{CloseGraph} --- ok
\item \textit{DetectGraph} --- ok
\item \textit{DrawPoly} --- ok
\item \textit{FillPoly} --- ok
\item \textit{FloodFill} --- ok
\item \textit{GetModeName} --- ok
\item \textit{GetRGBPalette} --- ok
\item \textit{InitGraph} --- ok
\item \textit{InstallUserDriver} --- ok
\item \textit{InstallUserFont} --- ok
\item \textit{PieSlice}
\item \textit{RegisterBGIDriver} --- ok
\item \textit{RegisterBGIFont} --- ok
\item \textit{SetAllPalette} --- ok
\item \textit{SetFillPattern} --- ok
\item \textit{SetFillStyle} --- ok
\item \textit{SetGraphBufSize}
\item \textit{SetGraphMode}
\item \textit{SetLineStyle} --- ok
\item \textit{SetPalette} --- ok
\item \textit{SetRGBPalette} --- ok
\item \textit{SetTextJustify} --- ok
\item \textit{SetTextStyle} --- ok
\item \textit{SetViewPort} --- ok
\end{itemize}
\textit{GraphResult} is reset to zero after it has been called. Therefore
the user should store the value returned by this function into a temporary
variable and then use it.
\subsection{Write modes}
Write modes permits combining colors with already existing on-screen colors,
\textit{PutImage} supports several write modes, while most other routines
support only CopyPut/NormalPut and XORPut modes.
The following routines support XORPut write modes (all routines support
CopyPut modes):
\begin{itemize}
\item \textit{FillEllipse}
\item \textit{FillPoly}
\item \textit{Arc} with ThickWidth line styles only
\item \textit{Circle} with ThickWidth line styles only
\item \textit{Line}
\item \textit{LineRel}
\item \textit{LineTo}
\item \textit{Rectangle}
\item \textit{DrawPoly}
\end{itemize}
\subsection{Text}
An internal bitmap font is included with this implementation of the graph
unit. It also possible to load and use standard Borland CHR external
vectorized font files. A bitmapped font is defined in this case by
a matrix of 8x8 pixels. A vector font (also referred to as a stroked font)
is defined by a series of vectors that tell the graphics system how to draw
the font.
\subsection{Clipping and Viewports}
\textit{SetViewPort} makes all output commands operate in a rectangular
region of the screen. Most output routines are viewport relative until
the viewport is changed. If clipping is active, all graphics is output
is clipped to the current region.
There is always clipping to the screen boundaries, whatever the clipping
setting is.
\subsection{Internals}
To make porting to a new platform easier, some of the graph unit routines
have been designed using procedural variables. Some of the routines have
default hooks, while others must absolutely be implemented for every new
platform to make the graph unit work.
The following routines must be created for every new platform supported:
\begin{itemize}
\item \textit{CloseGraph}
\item \textit{DirectPutPixel}
\item \textit{PutPixel}
\item \textit{GetPixel}
\item \textit{InitMode}
\item \textit{SaveVideoState}
\item \textit{RestoreVideoState}
\item \textit{QueryAdapterInfo}
\item \textit{SetRGBPalette}
\item \textit{GetRGBPalette}
\end{itemize}
The following global variables must be setup for every new platform
supported:
InternalDriverName
\var{InternalDriverName}
This variable should be set to a string describing the platform driver
name. It is returned by the user function GetDriverName. Some examples
of driver names are 'DosGX', 'DirectX', 'QuickDrw','CyberGFX', 'Dive'.
\var{CloseGraph}
The CloseGraph routine is called directly by the user and must
do the necessary cleanup by freeing up all platform specific
memory allocations, and by calling RestoreVideoState.
\var{DirectPutPixel}
This routine is one of the most important callback routines with
PutPixel, it is called by most of the routines in the graph unit. It
is about the same as PutPixel except that the coordinates passed to
it are already in global (screen) coordinates, and that clipping has
already been performed. Note that the current WriteMode has to be taken
into account in this procedure.
\var{InitMode}
This callback routine is called by SetGraphMode to actualliy change to
the correct video mode. (SetGraphMode is called by InitGraph).
\var{SaveVideoState}
This routine is called by InitGraph before changing to the graphics video
mode, it should save the old video mode, save any internal video state
such as the palette entries.
\var{RestoreVideoState}
This routine should be called by CloseGraph, it should restore the video
mode to the one saved in SaveVideoState, and restore all appropriate video
information, so that the video is in the same state as it was when
SaveVideoState was called.
\var{QueryAdapterInfo}
This routine might be called by the user BEFORE we are in graphics
mode. It is called by the initialization code of the graph unit. It
creates a linked list of video capabilities and procedural hooks for
all supported video modes on the platform. Look at the DOS version,
to see how it works. This linked list can be read by the user before a
call to InitGraph to determine which mode to use.
The linked list is composed of mode information, as well to pointers
to the callback routines cited above. Some additional optional hooks
are also possible for those who wish to optimize the speed of the unit.
-------------------------------------------------------------
\begin{function}{GetModeName}
\Declaration
Function GetModeName (ModeNumber : smallint) : String;
\Description
Returns a string with the name of the specified graphics mode. The
return values are in the form, XRes x YRes NAME. This function is
useful for building menus, display status, and so forth.
\Errors
If the specified \var{ModeNumber} is invalid, the function returns an
empty string and sets GraphResult to grInvalidMode.
\SeeAlso
\seef{GetDriverName}, \seep{GetModeRange}, \seep{GetMaxMode}
\end{function}
------------------------
\begin{procedure}{SetAllPalette}
\Declaration
Procedure SetAllPalette(var Palette: PaletteType) ;
\Description
\var{Palette} is of type PaletteType. The first field in Palette
contains the length of the palette. The next \textit{n} fields of
type \var{RGBRec} contains the Red-Green-Blue components to replace
that specific color with. A value of -1 will not change the previous
entry's value.
Note that valid colors depend on the current graphics mode.
If the number of palette entries to replace is greater then the
number of colors possible on the screen, \var{GraphResult} returns
a value of \var{grError} and no changes to the palette settings will
occur.
Changes to the palette take effect immediately on the screen. Each time
a palette color is changed, that color will be changed to the new color
value.
This routine returns \var{grError} if called in a direct color mode.
\Errors
None.
\SeeAlso
\seep{SetRGBPalette}, \seep{SetPalette}
\end{procedure}
------------------------
------------------------
\begin{procedure}{GetDefaultPalette}
\Declaration
Procedure GetDefaultPalette (Var Palette : PaletteType);
\Description
Returns a \var{PaletteType} record containing the default RGB color
values when the graphics mode is initialized. These values are based
on the IBM-PC VGA hardware adapter, but do not change from platform
to platform.
On other platforms the colors may not exactly match those
on the IBM-PC, but the match should be close enough for most uses. This
value is static and does never change.
Even if the modes can support more then 256 color entries, only the
256 first colors can be considered as having default values. Therefore,
at most this function will return 256 entries. To query all colors over
256 yourself, use \var{GetRGBPalette} for the entire palette range.
\Errors
None.
\SeeAlso
\seef{GetColor}, \seef{GetBkColor}, \seep{GetRGBPalette}
\end{procedure}
------------------------
\begin{procedure}{GetPalette}
\Declaration
Procedure GetPalette (Var Palette : PaletteType);
\Description
\var{GetPalette} returns in \var{Palette} the current palette. The palette
is in LSB RGB format.
This routine returns \var{grError} if called in a direct color mode.
\Errors
None.
\SeeAlso
\seef{GetPaletteSize}, \seep{SetPalette}
\end{procedure}
---------------------------
---------------------------
\begin{function}{GetBkColor}
\Declaration
Function GetBkColor : Word;
\Description
\var{GetBkColor} returns the current background color. If in non direct color
mode, this returns the palette entry, otherwise it returns the direct
RGB value of the current drawing color.
\Errors
None.
\SeeAlso
\seef{GetColor},\seep{SetBkColor}
\end{function}
---------------------------
\begin{function}{GetColor}
\Declaration
Function GetColor : Word;
\Description
\var{GetColor} returns the current drawing color. If in non direct color
mode, this returns the palette entry, otherwise it returns the direct
RGB value of the current drawing color.
\Errors
None.
\SeeAlso
\seef{GetColor},\seep{SetBkColor}
\end{function}
---------------------------
\begin{procedure}{GetRGBPalette}
\Declaration
Procedure GetRGBPalette (ColorNum: intege; var Red,Green,Blue : smallint);
\Description
\var{GetRGBPalette} gets the \var{ColorNum}-th entry in the palette.
The Red , Green and Blue values returned arein LSB format.
If the palette entry could not be read for a reason,
the routine returns \var{grError}.
This routine returns \var{grError} if called in a direct color mode.
\Errors
None.
\SeeAlso
\seep{SetAllPallette},
\seep{SetPalette}
\seep{SetRGBPalette}
\end{procedure}
----------------------------
----------------------------
\begin{procedure}{SetDirectVideo}
\Declaration
Procedure SetDirectVideo (DirectAccess : boolean);
\Description
Determines how the video access should be done, if DirectAccess
is set to TRUE then access will be done directly to video memory, if
it is supported, otherwise Operating systems calls will be done to
access the video memory.
The behaviour of this routine depends on the platform, and is required
for example to use the graph unit under older multitaskers such as
Desqview (DOS platform). Certain modes re simply not supported
via Operating system calls, while others are only supported by the
operating system. In those cases this routine is simply ignored.
Using operating system calls to plot pixels is much slower then using
the direct mode, but it provides more compatibility.
\textbf{Platform specific}
Windows NT, OS/2, Windows '9x, Windows 3.x, Linux DOSEMU support
all \textit{standard} video DOS modes, even in DirectVideo mode.
Others, like Desqview, Topview, DoubleDOS and MultiDOS might not.
In that case, \vaR{SetDirectVideo} should be called and set to FALSE.
VESA modes are not considered as standard DOS video modes,
and should simply not be used under such multitaskers/emulators.
Mode-X is not considered a standard DOS mode, but is supported in
most modern operating systems, since it uses only standard VGA
I/O ports and memory. (Exception: older multitaskers such as Desqview).
NOT IMPLEMENTED YET.
\Errors
None.
\SeeAlso
\seef{GetDirectVideo}
\end{procedure}
----------------------------
\begin{function}{GetDirectVideo}
\Declaration
Function GetDirectVideo : boolean;
\Description
Returns the state of the of DirectAccess flag. If this value returns
TRUE, then in the case where it is possible, the video memory is directly
accessed to plot graphics points, otherwise operating system calls
are used.
\Errors
None.
\SeeAlso
\seep{SetDirectVideo}
\end{procedure}
----------------------------
\section{Reference}
\section{Constants, Types and Variables}
\subsection{Types}
\begin{verbatim}
ArcCoordsType = record
X,Y,Xstart,Ystart,Xend,Yend : smallint;
end;
FillPatternType = Array [1..8] of Byte;
FillSettingsType = Record
Pattern,Color : Word
end;
LineSettingsType = Record
LineStyle,Pattern, Width : Word;
end;
PointType = Record
X,Y : smallint;
end;
TextSettingsType = Record
Font,Direction, CharSize, Horiz, Vert : Word
end;
ViewPortType = Record
X1,Y1,X2,Y2 : smallint;
Clip : Boolean
end;
\end{verbatim}
\begin{verbatim}
PaletteType = Record
Size : longint;
Colors : array[0..MaxColors] of RGBRec;
end;
\end{verbatim}
This record is used by \textit{SetAllPalette} , \textit{GetPalette} and
\textit{GetDefaultPalette}. \textit{Size} indicated the number of RGB
entries in this record, followed by the RGB records for each color. It
is to note, that contrary to Turbo Pascal, the RGB components are in
the LSB's of the RGB component records. This makes easier compatibility
across different hardware platforms.
\section{Functions and procedures}
\begin{procedure}{Arc}
\Declaration
Procedure Arc (X,Y : smallint; stAngle,Endangle, radius : Word);
\Description
\var{Arc} draws part of a circle with center at \var{(X,Y)}, radius
\var{radius}, starting from angle \var{stAngle}, stopping at angle \var{EndAngle}.
These angles are measured counterclockwise. Information about the last call
to \var{Arc} can be retrieved by \var{GetArcCoords}.
\Errors
None.
\SeeAlso
\seep{Circle},\seep{Ellipse}
\seep{GetArcCoords},\seep{PieSlice}, \seep{Sector}
\end{procedure}
\begin{procedure}{Bar}
\Declaration
Procedure Bar (X1,Y1,X2,Y2 : smallint);
\Description
Draws a rectangle with corners at \var{(X1,Y1)} and \var{(X2,Y2)}
and fills it with the current color and fill-style.
\Errors
None.
\SeeAlso
\seep{Bar3D},
\seep{Rectangle}
\end{procedure}
\begin{procedure}{Bar3D}
\Declaration
Procedure Bar3D (X1,Y1,X2,Y2 : smallint; depth : Word; Top : Boolean);
\Description
Draws a 3-dimensional Bar with corners at \var{(X1,Y1)} and \var{(X2,Y2)}
and fills it with the current color and fill-style.
\var{Depth} specifies the number of pixels used to show the depth of the
bar.
If \var{Top} is true; then a 3-dimensional top is drawn.
\Errors
None.
\SeeAlso
\seep{Bar}, \seep{Rectangle}
\end{procedure}
\begin{procedure}{Circle}
\Declaration
Procedure Circle (X,Y : smallint; Radius : Word);
\Description
\var{Circle} draws part of a circle with center at \var{(X,Y)}, radius
\var{radius} in the current color. Each graphics driver contains an
aspect ratio used by \var{Circle}, \var{Arc} and \var{PieSlice}.
\Errors
None.
\SeeAlso
\seep{Ellipse},\seep{Arc}
\seep{GetArcCoords},\seep{PieSlice}, \seep{Sector}
\end{procedure}
\begin{procedure}{ClearDevice}
\Declaration
Procedure ClearDevice ;
\Description
Clears the graphical screen (with the current
background color), and sets the pointer at \var{(0,0)}
\Errors
None.
\SeeAlso
\seep{ClearViewPort}, \seep{SetBkColor}
\end{procedure}
\begin{procedure}{ClearViewPort}
\Declaration
Procedure ClearViewPort ;
\Description
Clears the current viewport. The current background color is used as filling
color. The pointer is set at \var{(0,0)}
\Errors
None.
\SeeAlso
\seep{ClearDevice},\seep{SetViewPort}, \seep{SetBkColor}
\end{procedure}
\begin{procedure}{CloseGraph}
\Declaration
Procedure CloseGraph ;
\Description
Closes the graphical system, restores the
screen mode which was active before the graphical mode was
activated and frees up any memory allocated in InitGraph.
\Errors
None.
\SeeAlso
\seep{InitGraph}
\end{procedure}
\begin{procedure}{DetectGraph}
\Declaration
Procedure DetectGraph (Var Driver, Modus : smallint);
\Description
Checks the hardware in the PC and determines the driver and screen-modus to
be used. These are returned in \var{Driver} and \var{Modus}, and can be fed
to \var{InitGraph}.
See the \var{InitGraph} for a list of drivers and modi.
\Errors
None.
\SeeAlso
\seep{InitGraph}
\end{procedure}
\begin{procedure}{DrawPoly}
\Declaration
Procedure DrawPoly (NumPoints : Word; Var PolyPoints);
\Description
Draws a polygon with \var{NumPoints} corner points, using the
current color and linestyle. PolyPoints is an array of type \var{PointType}.
If there are less the two points in \var{PolyPoints}, this routine
returns \var{grError}.
\Errors
None.
\SeeAlso
\seep{Bar}, seep{Bar3D}, \seep{Rectangle}
\end{procedure}
\begin{procedure}{Ellipse}
\Declaration
Procedure Ellipse (X,Y : smallint; StAngle,EndAngle,XRadius,YRadius : Word);
\Description
\var{Ellipse} draws part of an ellipse with center at \var{(X,Y)}.
\var{XRadius} and \var{Yradius} are the horizontal and vertical radii of the
ellipse. \var{StAngle} and \var{EndAngle} are the starting and stopping angles of
the part of the ellipse. They are measured counterclockwise from the X-axis.
Information about the last call to \var{Ellipse} can be retrieved by
\var{GetArcCoords}.
\Errors
None.
\SeeAlso
\seep{Arc} \seep{Circle}, \seep{FillEllipse}
\end{procedure}
\begin{procedure}{FillEllipse}
\Declaration
Procedure FillEllipse (X,Y : smallint; Xradius,YRadius: Word);
\Description
\var{Ellipse} draws an ellipse with center at \var{(X,Y)}.
\var{XRadius} and \var{Yradius} are the horizontal and vertical radii of the
ellipse. The ellipse is filled with the current color and fill style.
\Errors
None.
\SeeAlso
\seep{Arc} \seep{Circle},
\seep{GetArcCoords},\seep{PieSlice}, \seep{Sector}
\end{procedure}
\begin{procedure}{FillPoly}
\Declaration
Procedure FillPoly (NumberPoints : Word; Var PolyPoints);
\Description
Draws a polygon with \var{NumPoints} corner points and fills it
using the current color and fill style. The outline of the polygon
is drawn in the current line style and color as set by \var{SetLineStyle}.
PolyPoints is an array of type \var{PointType}.
\Errors
None.
\SeeAlso
\seep{Bar}, seep{Bar3D}, \seep{Rectangle}
\end{procedure}
\begin{procedure}{FloodFill}
\Declaration
Procedure FloodFill (X,Y : smallint; BorderColor : Word);
\Description
Fills the area containing the point \var{(X,Y)}, bounded by the color
\var{BorderColor}. The flooding is done using the current fill style
and fill color, as set by \var{SetFillStyle} or \var{SetFillPattern}.
This routine is here for compatibility only, \var{FillPoly} should be
used instead, since it is much faster.
\Errors
None
\SeeAlso
\seep{FillPoly},
\end{procedure}
\begin{procedure}{GetArcCoords}
\Declaration
Procedure GetArcCoords (Var ArcCoords : ArcCoordsType);
\Description
\var{GetArcCoords} returns the coordinates of the last \var{Arc} or
\var{Ellipse} call. The values are useful for connecting a line to
the end of an ellipse.
\Errors
None.
\SeeAlso
\seep{Arc}, \seep{Ellipse}
\end{procedure}
\begin{procedure}{GetAspectRatio}
\Declaration
Procedure GetAspectRatio (Var Xasp,Yasp : Word);
\Description
\var{GetAspectRatio} determines the effective resolution of the screen. The aspect ration can
the be calculated as \var{Xasp/Yasp}.
Each graphics driver uses this aspect ratio to make circles and any circular
shape look round on the screen.
\Errors
None.
\SeeAlso
\seep{InitGraph},\seep{SetAspectRatio}
\end{procedure}
\begin{function}{GetDriverName}
\Declaration
Function GetDriverName : String;
\Description
\var{GetDriverName} returns a string containing the name of the
current driver. This name can be anything under FPC, but it is
usually indicative of the API and/or platform used to perform the
graphics call.
\Errors
None.
\SeeAlso
\seef{GetModeName}, \seep{InitGraph}
\end{function}
\begin{procedure}{GetFillPattern}
\Declaration
Procedure GetFillPattern (Var FillPattern : FillPatternType);
\Description
\var{GetFillPattern} returns an array with the current fill pattern in \var{FillPattern}.
If no user call has been made to \var{SetFillPattern}, the pattern will be
filled with \var{$FF}.
It is to note that the user fill pattern is reset to \var{$FF} each time
\var{GraphDefaults} is called.
\Errors
None
\SeeAlso
\seep{SetFillPattern}, \seep{GraphDefaults}
\end{procedure}
\begin{procedure}{GetFillSettings}
\Declaration
Procedure GetFillSettings (Var FillInfo : FillSettingsType);
\Description
\var{GetFillSettings} returns the current fill-settings in
\var{FillInfo}
\Errors
None.
\SeeAlso
\seep{SetFillPattern}
\end{procedure}
\begin{function}{GetGraphMode}
\Declaration
Function GetGraphMode : smallint;
\Description
\var{GetGraphMode} returns the current graphical mode. This value is
entirely dependant on the hardware platform. To look up what this
mode number represents from a capabilities standpoint, you should
call either \var{QueryAdapterInfo} or \var{GetModeName} with the
value returned by this function.
\Errors
None.
\SeeAlso
\seep{InitGraph}, \seep{QueryAdapterInfo}, \seep{GetModeName}
\end{function}
\begin{procedure}{GetImage}
\Declaration
Procedure GetImage (X1,Y1,X2,Y2 : smallint, Var Bitmap);
\Description
\var{GetImage}
Places a copy of the screen area \var{(X1,Y1)} to \var{X2,Y2} in \var{BitMap}.
\var{Bitmap} is an untyped parameter that must be equal to 12 plus the size
of the screen area to save. The first two longints of \var{Bitmap} store
the width and height of the region. The third longint is reserved and should
not be modified.
To make access to the screen faster, it is recommended that the starting
points and ending point coordinates be modulo 4 and that the width to
save be also modulo 4.
To get the size of the bitmap required to save the area, you should call
\var{ImageSize}.
\Errors
Bitmap must have enough room to contain the image.
\SeeAlso
\seef{ImageSize},
\seep{PutImage}
\end{procedure}
\begin{procedure}{GetLineSettings}
\Declaration
Procedure GetLineSettings (Var LineInfo : LineSettingsType);
\Description
\var{GetLineSettings} returns the current Line settings in
\var{LineInfo}
\Errors
None.
\SeeAlso
\seep{SetLineStyle}
\end{procedure}
\begin{function}{GetMaxColor}
\Declaration
Function GetMaxColor : Word;
\Description
\var{GetMaxColor} returns the maximum color-number which can
be set with \var{SetColor}. This value is zero based, so a screen
which supports 16 colors, would return 15.
\Errors
None.
\SeeAlso
\seep{SetColor},
\seef{GetPaletteSize}
\end{function}
\begin{function}{GetMaxMode}
\Declaration
Function GetMaxMode : Word;
\Description
\var{GetMaxMode} returns the highest mode for the current driver. Normally
the higher the mode number, the resolution it will be, but this might not
always be the case.
\Errors
None.
\SeeAlso
\seep{InitGraph}
\end{function}
\begin{function}{GetMaxX}
\Declaration
Function GetMaxX : Word;
\Description
\var{GetMaxX} returns the maximum horizontal screen
length (zero based from 0..\var{MaxX}).
\Errors
None.
\SeeAlso
\seef{GetMaxY}
\end{function}
\begin{function}{GetMaxY}
\Declaration
Function GetMaxY : Word;
\Description
\var{GetMaxY} returns the maximum number of screen
lines. (zero based from 0..\var{MaxY}).
\Errors
None.
\SeeAlso
\seef{GetMaxY}
\end{function}
\begin{procedure}{GetModeRange}
\Declaration
Procedure GetModeRange (GraphDriver : smallint; var LoMode, HiMode: smallint);
\Description
\var{GetModeRange} returns the Lowest and Highest mode of the currently
installed driver. If the value of \var{GraphDriver} is invalid, \var{LoMode}
and var{HiMode} are set to -1.
\Errors
None.
\SeeAlso
\seep{InitGraph}, \seep{GetModeName}
\end{procedure}
\begin{function}{GetPaletteSize}
\Declaration
Function GetPaletteSize : Word;
\Description
\var{GetPaletteSize} returns the maximum number of entries which
can be set in the current palette. In direct color mode, this simply
returns the maximum possible of colors on screen.
Usually this has the value \var{GetMaxColor} + 1.
\Errors
None.
\SeeAlso
\seep{GetPalette},
\seep{SetPalette}
\seep{GetMaxColor}
\end{function}
\begin{function}{GetPixel}
\Declaration
Function GetPixel (X,Y : smallint) : Word;
\Description
\var{GetPixel} returns the color
of the point at \var{(X,Y)} The coordinates, as all coordinates
are viewport relative.
In direct color mode, the value returned is the direct RGB components of
the color. In palette based modes, this indicates the palette entry number.
\Errors
None.
\SeeAlso
\end{function}
\begin{procedure}{GetTextSettings}
\Declaration
Procedure GetTextSettings (Var TextInfo : TextSettingsType);
\Description
\var{GetTextSettings} returns the current text style settings : The font,
direction, size and placement as set with \var{SetTextStyle} and
\var{SetTextJustify}.
\Errors
None.
\SeeAlso
\seep{SetTextStyle}, \seep{SetTextJustify}
\end{procedure}
\begin{procedure}{GetViewSettings}
\Declaration
Procedure GetViewSettings (Var ViewPort : ViewPortType);
\Description
\var{GetViewSettings} returns the current view-port and clipping settings in
\var{ViewPort}.
\Errors
None.
\SeeAlso
\seep{SetViewPort}
\end{procedure}
\begin{function}{GetX}
\Declaration
Function GetX : smallint;
\Description
\var{GetX} returns the X-coordinate of the current pointer. This value is
viewport relative.
\Errors
None.
\SeeAlso
\seef{GetY}
\end{function}
\begin{function}{GetY}
\Declaration
Function GetY : smallint;
\Description
\var{GetY} returns the Y-coordinate of the current pointer. This value is
viewport relative.
\Errors
None.
\SeeAlso
\seef{GetX}
\end{function}
\begin{procedure}{GraphDefaults}
\Declaration
Procedure GraphDefaults ;
\Description
\var{GraphDefaults} homes the current pointer, and resets the graphics
system to the default values for:
\begin{itemize}
\item Active Line style is reset to normal width and filled line.
\item The current fill color is set to the maximum palette color.
\item The current fill style is set to \var{solidfill}.
\item The user fill pattern is reset to \var{$FF}.
\item The current drawing color is set to white.
\item The current background color is reset to black.
\item The viewport is reset to (0,0,\var{GetMaxX},\var{GetMaxY}).
\item Clipping is enabled.
\item The active write mode is set to normalput.
\item Text settings are reset to : default font, \var{HorizDir},
\var{LeftText} and \var{TopText}.
\end{itemize}
This routine is called by \var{SetGraphMode}.
\Errors
None.
\SeeAlso
\seep{SetViewPort}, \seep{SetFillStyle}, \seep{SetColor},
\seep{SetBkColor}, \seep{SetLineStyle}, \seep{SetGraphMode}
\end{procedure}
\begin{function}{GraphErrorMsg}
\Declaration
Function GraphErrorMsg (ErrorCode : smallint) : String;
\Description
\var{GraphErrorMsg}
returns a string describing the error \var{Errorcode}. This string can be
used to let the user know what went wrong.
\Errors
None.
\SeeAlso
\seef{GraphResult}
\end{function}
\begin{function}{GraphResult}
\Declaration
Function GraphResult : smallint;
\Description
\var{GraphResult} returns an error-code for
the last graphical operation. If the returned value is zero, all went well.
A value different from zero means an error has occurred.
Note that \var{GraphResult} is reset to zero after it has been called.
Therefore the value should be saved into a temporary location if you wish
to use it later.
To see which routine might return errors, see the introduction section at
the start of this reference.
\Errors
None.
\SeeAlso
\seef{GraphErrorMsg}
\end{function}
\begin{function}{ImageSize}
\Declaration
Function ImageSize (X1,Y1,X2,Y2 : smallint) : longint;
\Description
\var{ImageSize} returns the number of bytes needed to store the image
by \var{GetImage} in the rectangle defined by \var{(X1,Y1)} and \var{(X2,Y2)}.
The image size includes space for several words. The first three longints
are reserved for use by \var{GetImage}, the first longint containing the
width of the region, the second containing the height, and the third being
reserved,the following words contains the bitmap itself.
\textit{Compatibility:}
The value returned by this function is a 32-bit value,
and not a 16-bit value.
\Errors
None.
\SeeAlso
\seep{GetImage}
\end{function}
\begin{procedure}{InitGraph}
\Declaration
Procedure InitGraph (var GraphDriver,GraphModus : smallint;\\
const PathToDriver : string);
\Description
\var{InitGraph} initializes the \var{graph} package.
\var{GraphDriver} has two valid values: \var{GraphDriver=Detect} which
performs an auto detect and initializes the highest possible mode with the most
colors. This is dependant on the platform, and many of the non-standard
modes amy not be detected automatically. \var{graphMode} is the mode you
wish to use.
\var{PathToDriver} is only needed, if you use the BGI fonts from
Borland, which are fully supported under FPC.
The exact rundown of \var{InitGraph} is as follows: First it calls
\var{QueryAdapterInfo} to get the possible modes supported by the hardware.
It then saves the video state, initalizes some global variables, then if
auto-detection was requested, calls \var{GetModeRange} to get the highest
possible mode available and supported, otherwise it searches if the requested
mode is available in the database. Finally , in either case it calls
\var{SetGraphMode}.
If the requested driver or mode is invalid, this function returns either
\var{grError} or \var{grInvalidMode}.
Before calling this function, you should call QueryAdapterInfo, and
go through the list of supported modes to determine which mode suites
your needs. As stated in the introduction, each graph unit implementation
should support a 320x200 color mode.
\Errors
None.
\SeeAlso
Introduction, (page \pageref{se:Introduction}),
\seep{DetectGraph}, \seep{CloseGraph}, \seef{GraphResult},
\seef{QueryAdapterInfo}
\end{procedure}
Example:
\begin{verbatim}
var
gd,gm : smallint;
PathToDriver : string;
begin
gd:=detect; { highest possible resolution }
gm:=0; { not needed, auto detection }
PathToDriver:='C:\PP\BGI'; { path to BGI fonts,
drivers aren't needed }
InitGraph(gd,gm,PathToDriver);
if GraphResult<>grok then
halt; ..... { whatever you need }
CloseGraph; { restores the old graphics mode }
end.
\end{verbatim}
\begin{function}{InstallUserDriver}
\Declaration
Function InstallUserDriver (DriverPath : String; AutoDetectPtr: Pointer) : smallint;
\Description
This routine is not supported in FPC, it is here only for compatiblity and
always returns \var{grError}.
\Errors
None.
\SeeAlso
\seep{InitGraph}, \seef{InstallUserFont}
\end{function}
\begin{function}{InstallUserFont}
\Declaration
Function InstallUserFont (FontPath : String) : smallint;
\Description
\var{InstallUserFont} adds the font in \var{FontPath} to the list of fonts
available to the text system. If the maximum number of allocated fonts has
been reached, this routine sets \var{GraphResult} to \var{grError}.
\Errors
None.
\SeeAlso
\seep{InitGraph}, \seef{InstallUserDriver}
\end{function}
\begin{procedure}{Line}
\Declaration
Procedure Line (X1,Y1,X2,Y2 : smallint);
\Description
\var{Line} draws a line starting from
\var{(X1,Y1} to \var{(X2,Y2)}, in the current line style and color.
The current pointer is not updated after this call.
This is the base routine which is called by several other routines
in this unit. This routine is somewhat faster then the other
LineXXX routines contained herein.
\Errors
None.
\SeeAlso
\seep{LineRel},\seep{LineTo}
\end{procedure}
\begin{procedure}{LineRel}
\Declaration
Procedure LineRel (DX,DY : smallint);
\Description
\var{LineRel} draws a line starting from
the current pointer position to the point\var{(DX,DY}, \textbf{relative} to the
current position, in the current line style and color. The Current Position
is set to the endpoint of the line.
\Errors
None.
\SeeAlso
\seep{Line}, \seep{LineTo}
\end{procedure}
\begin{procedure}{LineTo}
\Declaration
Procedure LineTo (DX,DY : smallint);
\Description
\var{LineTo} draws a line starting from
the current pointer position to the point\var{(DX,DY}, \textbf{relative} to the
current position, in the current line style and color. The Current position
is set to the end of the line.
\Errors
None.
\SeeAlso
\seep{LineRel},\seep{Line}
\end{procedure}
\begin{procedure}{MoveRel}
\Declaration
Procedure MoveRel (DX,DY : smallint;
\Description
\var{MoveRel} moves the current pointer to the
point \var{(DX,DY)}, relative to the current pointer
position
\Errors
None.
\SeeAlso
\seep{MoveTo}
\end{procedure}
\begin{procedure}{MoveTo}
\Declaration
Procedure MoveTo (X,Y : smallint);
\Description
\var{MoveTo} moves the current pointer to the
point \var{(X,Y)}.
\Errors
None.
\SeeAlso
\seep{MoveRel}
\end{procedure}
\begin{procedure}{OutText}
\Declaration
Procedure OutText (Const TextString : String);
\Description
\var{OutText} puts \var{TextString} on the screen, at the current pointer
position, using the current font and text settings. The current pointer is
updated only if the text justification is set to left and is horizontal.
The text is truncated according to the current viewport settings if it
cannot fit.
In order to maintain compatibility when using several fonts, use \var{TextWidth}
and \var{TextHeight} calls to determine the dimensions of the string.
\Errors
None.
\SeeAlso
\seep{OutTextXY}
\end{procedure}
\begin{procedure}{OutTextXY}
\Declaration
Procedure OutTextXY (X,Y : smallint; Const TextString : String);
\Description
\var{OutText} puts \var{TextString} on the screen, at position \var{(X,Y)},
using the current font and text settings.
Contrary to \var{OutText} , this routine does not update the current pointer.
In order to maintain compatibility when using several fonts, use \var{TextWidth}
and \var{TextHeight} calls to determine the dimensions of the string.
\Errors
None.
\SeeAlso
\seep{OutText}
\end{procedure}
\begin{procedure}{PieSlice}
\Declaration
Procedure PieSlice (X,Y,stangle,endAngle:smallint;Radius: Word);
\Description
\var{PieSlice}
draws and fills a sector of a circle with center \var{(X,Y)} and radius
\var{Radius}, starting at angle \var{StAngle} and ending at angle \var{EndAngle}
using the current fill style and fill pattern. The pie slice is outlined
with the current line style and current active color.
\Errors
None.
\SeeAlso
\seep{Arc}, \seep{Circle}, \seep{Sector}
\end{procedure}
\begin{procedure}{PutImage}
\Declaration
Procedure PutImage (X,Y: smallint; var Bitmap; BitBlt: Word);
\Description
\var{PutImage}
Places the bitmap in \var{Bitmap} on the screen at upper left
corner \var{(X, Y)}. \var{BitBlt} determines how the bitmap
will be placed on the screen. Possible values are :
\begin{itemize}
\item CopyPut
\item XORPut
\item ORPut
\item AndPut
\item NotPut
\end{itemize}
\textit{Compatibility}
Contrary to the Borland graph unit, putimage \textit{is} clipped to the
viewport boundaries.
\Errors
None
\SeeAlso
\seef{ImageSize},\seep{GetImage}
\end{procedure}
\begin{procedure}{PutPixel}
\Declaration
Procedure PutPixel (X,Y : smallint; Color : Word);
\Description
Puts a point at
\var{(X,Y)} using color \var{Color}. This routine is viewport
relative.
\Errors
None.
\SeeAlso
\seef{GetPixel}
\end{procedure}
\begin{procedure}{Rectangle}
\Declaration
Procedure Rectangle (X1,Y1,X2,Y2 : smallint);
\Description
Draws a rectangle with
corners at \var{(X1,Y1)} and \var{(X2,Y2)}, using the current color and
the current line style.
\Errors
None.
\SeeAlso
\seep{Bar}, \seep{Bar3D}
\end{procedure}
\begin{function}{RegisterBGIDriver}
\Declaration
Function RegisterBGIDriver (Driver : Pointer) : smallint;
\Description
This routine is not supported in FPC. It is here for compatibility and it
always returns \var{grError}.
\Errors
None.
\SeeAlso
\seef{InstallUserDriver},
\seef{RegisterBGIFont}
\end{function}
\begin{function}{RegisterBGIFont}
\Declaration
Function RegisterBGIFont (Font : Pointer) : smallint;
\Description
This routine permits the user to add a font to the list of known fonts
by the graph unit. \var{Font} is a pointer to image of the loaded font.
The value returned is either a negative error number (\var{grInvalidFont}),
or the font number you need to use when accessing it via \var{SetTextStyle}.
This routine may be called before \var{InitGraph}.
\textit{Compatibility}
Watch out for the byte endian when using this routine. This might work
on little endian machines, and not on big endian machines and vice-versa.
\Errors
None.
\SeeAlso
\seef{InstallUserFont},
\seef{RegisterBGIDriver}
\end{function}
\begin{procedure}{RestoreCRTMode}
\Declaration
Procedure RestoreCRTMode ;
\Description
Restores the screen mode which was active before
the graphical mode was started. Can be used to switch back and forth
between text and graphics mode.
\Errors
None.
\SeeAlso
\seep{InitGraph}
\end{procedure}
Example:
\begin{verbatim}
uses Graph;
var
Gd, Gm: smallint;
Mode: smallint;
begin
Gd := Detect;
InitGraph(Gd, Gm, ' ');
if GraphResult <> grOk then
Halt(1);
OutText('<ENTER> to leave graphics:');
Readln;
RestoreCrtMode;
Writeln('Now in text mode');
Write('<ENTER> to enter graphics mode:');
Readln;
SetGraphMode(GetGraphMode);
OutTextXY(0, 0, 'Back in graphics mode');
OutTextXY(0, TextHeight('H'), '<ENTER> to quit:');
Readln;
CloseGraph;
end.
\end{verbatim}
\begin{procedure}{Sector}
\Declaration
Procedure Sector (X,Y : smallint; StAngle,EndAngle,XRadius,YRadius : Word);
\Description
\var{Sector}
draws and fills a sector of an ellipse with center \var{(X,Y)} and radii
\var{XRadius} and \var{YRadius}, starting at angle \var{StAngle} and ending at angle
\var{EndAngle}. The sector is outlined in the current color and filled with
the pattern and color defined by \var{SetFillStyle} or \var{SetFillPattern}.
\Errors
None.
\SeeAlso
\seep{Arc}, \seep{Circle}, \seep{PieSlice}
\end{procedure}
\begin{procedure}{SetActivePage}
\Declaration
Procedure SetActivePage (Page : Word);
\Description
Sets \var{Page} as the active page
for all graphical output. This means that all drawing will be done on this
graphics, be it visible or not.
The usual way to make fast animation, is to draw to a non visible active page
and the simply call make that active page the visible page by calling
\var{SetVisualPage}.
\textit{Compatibility}:
Not all systems and graphics mode support multiple graphics pages, to
determine how many pages are available see \var{QueryAdapterInfo}.
Multiple pages are currently not supported with DOS VESA modes.
\Errors
None.
\SeeAlso
\seep{SetVisualPage}, \seep{QueryAdapterInfo}
\end{procedure}
\begin{procedure}{SetAllPallette}
\Declaration
Procedure SetAllPallette (Var Palette);
\Description
Sets the current palette to
\var{Palette}. \var{Palette} is an untyped variable, usually pointing to a
record of type \var{PaletteType} which contains the Red, Green and Blue
components of the RGB components to change for each color entry. If
the Red, Green and Blue components are equal to -1 for a specific color
entry, then that palette entry will not be changed. The size should
contain the size of the palette to change (indexed at zero).
\textit{Compatibility}:
This call is not the same as in Turbo Pascal. RGB components should be
set in LSB if each of the components has less then 16-bits resolution.
This call is not supported in direct color modes.
\Errors
None.
\SeeAlso
\seep{GetPalette}
\end{procedure}
\begin{procedure}{SetAspectRatio}
\Declaration
Procedure SetAspectRatio (Xasp,Yasp : Word);
\Description
Sets the aspect ratio of the
current screen to \var{Xasp/Yasp}. The value of the aspect ratio is used
by certain routines herein to draw circles which will actually appear round
depending on the screen mode.
\Errors
None
\SeeAlso
\seep{InitGraph}, \seep{GetAspectRatio}
\end{procedure}
\begin{procedure}{SetBkColor}
\Declaration
Procedure SetBkColor (Color : Word);
\Description
Sets the background color to
\var{Color}.
The behaviour of this routine depends if we are in a direct color
mode or not. In direct color mode, this value represents the direct
RGB values to plot to the screen. In non direct color mode, the value
represents an index to the color palette entry on the hardware.
\Errors
None.
\SeeAlso
\seef{GetBkColor}, \seep{SetColor}
\end{procedure}
\begin{procedure}{SetColor}
\Declaration
Procedure SetColor (Color : Word);
\Description
Sets the foreground color to
\var{Color}.
The behaviour of this routine depends if we are in a direct color
mode or not. In direct color mode, this value represents the direct
RGB values to plot to the screen. In non direct color mode, the value
represents an index to the color palette entry on the hardware.
\Errors
None.
\SeeAlso
\seef{GetColor}, \seep{SetBkColor}
\end{procedure}
\begin{procedure}{SetFillPattern}
\Declaration
Procedure SetFillPattern (Pattern : FillPatternType, Color : Word);
\Description
\var{SetFillPattern} sets the current fill-pattern to \var{Pattern}, and
the filling color to \var{Color}. If invalid input is passed to
\var{SetFillPattern}, \var{GraphResult} will return \var{grError}.
The pattern is an 8x8 raster, corresponding to the 64 bits in
\var{FillPattern}. Whenever a bit in a pattern byte is valued at 1,
a pixel will be plotted. The pattern and color is used by \var{Bar},
\var{FillPoly}, \var{FloodFill}, \var{bar3d}, \var{FillEllipse},
\var{Sector}, and \var{PieSlice}.
\Errors
None
\SeeAlso
\seep{GetFillPattern}, \seep{SetFillStyle}
\end{procedure}
\begin{procedure}{SetFillStyle}
\Declaration
Procedure SetFillStyle (Pattern, Color : word);
\Description
\var{SetFillStyle} sets the filling pattern and color to one of the
predefined filling patterns. \var{Pattern} can be one of the following predefined
constants :
\begin{itemize}
\item \var{EmptyFill } Uses backgroundcolor.
\item \var{SolidFill } Uses filling color
\item \var{LineFill } Fills with horizontal lines.
\item \var{ltSlashFill} Fills with lines from left-under to top-right.
\item \var{SlashFill } Idem as previous, thick lines.
\item \var{BkSlashFill} Fills with thick lines from left-Top to bottom-right.
\item \var{LtBkSlashFill} Idem as previous, normal lines.
\item \var{HatchFill} Fills with a hatch-like pattern.
\item \var{XHatchFill} Fills with a hatch pattern, rotated 45 degrees.
\item \var{InterLeaveFill}
\item \var{WideDotFill} Fills with dots, wide spacing.
\item \var{CloseDotFill} Fills with dots, narrow spacing.
\item \var{UserFill} Fills with a user-defined pattern.
\end{itemize}
If invalid input is passed to \var{SetFillStyle},
\var{GraphResult} will return \var{grError}.
\Errors
None.
\SeeAlso
\seep{SetFillPattern}
\end{procedure}
\begin{procedure}{SetGraphBufSize}
\Declaration
Procedure SetGraphBufSize (BufSize : Word);
\Description
This routine does nothing in FPC, and is here for compatibility.
\Errors
None.
\SeeAlso
\end{procedure}
\begin{procedure}{SetGraphMode}
\Declaration
Procedure SetGraphMode (Mode : smallint);
\Description
\var{SetGraphMode} sets the
graphical mode and clears the screen. \var{Mode} must be a valid mode,
which can be queried by \var{QueryAdapterInfo}.
If invalid input is passed to \var{SetGraphMode}, or if the mode cannot
be set for a reason, \var{GraphResult} returns \var{grInvalidMode}.
\var{SetGraphMode} resets all graphics variables to their default
settings (such as if \var{GraphDefaults} was called, the active page
is reset to page zero, the visual page is reset to page zero, and the viewport
is set to the entire screen.
\Errors
None.
\SeeAlso
\seep{InitGraph}, \seep{QueryAdapterInfo}
\end{procedure}
\begin{procedure}{SetLineStyle}
\Declaration
Procedure SetLineStyle (LineStyle, Pattern, Thickness : Word);
\Description
\var{SetLineStyle}
sets the drawing style for lines. You can specify a \var{LineStyle} which is
one of the following pre-defined constants:
\begin{itemize}
\item \var{Solidln=0;} draws a solid line.
\item \var{Dottedln=1;} Draws a dotted line.
\item \var{Centerln=2;} draws a non-broken centered line.
\item \var{Dashedln=3;} draws a dashed line.
\item \var{UserBitln=4;} Draws a User-defined bit pattern.
\end{itemize}
If \var{UserBitln} is specified then \var{Pattern} contains the bit pattern to
use for drawing the line. A bit of 1 specified a pixel which is on.
In all another cases, \var{Pattern} is ignored. The parameter \var{Thickness}
indicates how thick the line should be. You can specify one of the following
pre-defined constants:
\begin{itemize}
\item \var{NormWidth=1}
\item \var{ThickWidth=3}
\end{itemize}
If invalid input is passed to \var{SetLineStyle} , \var{GraphResult} will
return \var{grError}.
\Errors
None.
\SeeAlso
\seep{GetLineSettings}
\end{procedure}
\begin{procedure}{SetPalette}
\Declaration
Procedure SetPalette (ColorNum : Word; Color : Shortint);
\Description
\var{SetPalette} changes the \var{ColorNum}-th entry in the palette to
\var{Color}. For examples, \var{SetPalette(0, LightCyan)} makes the first
color in the palette light cyan. \var{Color} only accepts certain default
colors, as specified in the \var{Color constants} section. If invalid
input is passed to \var{SetPalette}, \var{GraphResult} returns a value
of \var{grError} and the palette remains intact.
Changes made to the palette are immediately visible on the screen.
This routine returns \var{grError} if called in a direct color mode.
\Errors
None.
\SeeAlso
\seep{SetAllPallette},\seep{SetRGBPalette}
\end{procedure}
\begin{procedure}{SetRGBPalette}
\Declaration
Procedure SetRGBPalette (ColorNum,Red,Green,Blue : smallint);
\Description
\var{SetRGBPalette} sets the \var{ColorNum}-th entry in the palette to the
color with RGB values \var{Red, Green Blue}. The Red , Green and Blue values
must be in LSB format. If the palette entry could not be changed for a
reason, the routine returns \var{grError}.
This routine returns \var{grError} if called in a direct color mode.
\Errors
None.
\SeeAlso
\seep{SetAllPallette},
\seep{SetPalette}
\seep{GetRGBPalette}
\end{procedure}
\begin{procedure}{SetTextJustify}
\Declaration
Procedure SetTextJustify (Horiz, Vert : Word);
\Description
\var{SetTextJustify} controls the placement of new text, relative to the
(graphical) cursor position. \var{Horiz} controls horizontal placement, and can be
one of the following pre-defined constants:
\begin{itemize}
\item \var{LeftText=0;} Text is set left of the current pointer.
\item \var{CenterText=1;} Text is set centered horizontally on the current pointer.
\item \var{RightText=2;} Text is set to the right of the current pointer.
\end{itemize}
\var{Vertical} controls the vertical placement of the text, relative to the
(graphical) cursor position. Its value can be one of the following
pre-defined constants :
\begin{itemize}
\item \var{BottomText=0;} Text is placed under the current pointer.
\item \var{CenterText=1;} Text is placed centered vertically on the current pointer.
\item \var{TopText=2;}Text is placed above the current pointer.
\end{itemize}
If invalid input is passed \var{SetTextJustify} , \var{GraphResult} returns
\var{grError}.
\Errors
None.
\SeeAlso
\seep{OutText}, \seep{OutTextXY}
\end{procedure}
\begin{procedure}{SetTextStyle}
\Declaration
Procedure SetTextStyle (Font,Direction,Magnitude : Word);
\Description
\var{SetTextStyle} controls the style of text to be put on the screen.
pre-defined constants for \var{Font} are:
\begin{itemize}
\item \var{DefaultFont=0;}
\item \var{TriplexFont=2;}
\item \var{SmallFont=2;}
\item \var{SansSerifFont=3;}
\item \var{GothicFont=4;}
\end{itemize}
Pre-defined constants for \var{Direction} are :
\begin{itemize}
\item \var{HorizDir=0;}
\item \var{VertDir=1;}
\end{itemize}
Charsize indicated the magnification factor to use when drawing the fonts
to the screen. When using the default internal font, this value can be
any value equal or greater to one. In the case of stroked fonts, the
value should always be equal or greater then 4.
Stroked fonts are usually loaded from disk once onto the heap when a call
is made to \var{SetTextStyle}.
If there is an error when using this routine, \var{GraphResult} might return
\var{grFontNotFound}, \var{grNoFontMem}, \var{grError}, \var{grIoError},
\var{grInvalidFont}, or \var{grInvalidFontNum}.
\Errors
None.
\SeeAlso
\seep{GetTextSettings}
\end{procedure}
\begin{procedure}{SetUserCharSize}
\Declaration
Procedure SetUserCharSize (Xasp1,Xasp2,Yasp1,Yasp2 : Word);
\Description
Sets the width and height of vector-fonts. The horizontal size is given
by \var{Xasp1/Xasp2}, and the vertical size by \var{Yasp1/Yasp2}.
\Errors
None.
\SeeAlso
\seep{SetTextStyle}
\end{procedure}
\begin{procedure}{SetViewPort}
\Declaration
Procedure SetViewPort (X1,Y1,X2,Y2 : smallint; Clip : Boolean);
\Description
Sets the current graphical view-port (window) to the rectangle defined by
the top-left corner \var{(X1,Y1)} and the bottom-right corner \var{(X2,Y2)}.
If \var{Clip} is true, anything drawn outside the view-port (window) will be
clipped (i.e. not drawn). Coordinates specified after this call are relative
to the top-left corner of the view-port.
\Errors
None.
\SeeAlso
\seep{GetViewSettings}
\end{procedure}
\begin{procedure}{SetVisualPage}
\Declaration
Procedure SetVisualPage (Page : Word);
\Description
\var{SetVisualPage} sets the video page to page number \var{Page}.
\Errors
None
\SeeAlso
\seep{SetActivePage}
\end{procedure}
\begin{procedure}{SetWriteMode}
\Declaration
Procedure SetWriteMode (Mode : smallint);
\Description
\var{SetWriteMode} controls the drawing of lines on the screen. It controls
the binary operation used when drawing lines on the screen. \var{Mode} can
be one of the following pre-defined constants:
\begin{itemize}
\item CopyPut=0;
\item XORPut=1;
\end{itemize}
If you specify another mode, it is mapped to one of the above acoording to
the following table (for TP compatibility, may be changed in the future):
\begin{itemize}
\item Notput, Orput: CopyPut
\item AndPut: XorPut
\end{itemize}
\Errors
None.
\SeeAlso
\end{procedure}
\begin{function}{TextHeight}
\Declaration
Function TextHeight (S : String) : Word;
\Description
\var{TextHeight} returns the height (in pixels) of the string \var{S} in
the current font and text-size.
\Errors
None.
\SeeAlso
\seef{TextWidth}
\end{function}
\begin{function}{TextWidth}
\Declaration
Function TextWidth (S : String) : Word;
\Description
\var{TextHeight} returns the width (in pixels) of the string \var{S} in
the current font and text-size.
\Errors
None.
\SeeAlso
\seef{TextHeight}
\end{function}
|