gfvgraph.pas 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. {********[ SOURCE FILE OF GRAPHICAL FREE VISION ]**********}
  2. { }
  3. { System independent GFV GRAPHICS UNIT }
  4. { }
  5. { Copyright (c) 1999 by Leon de Boer }
  6. { [email protected] - primary e-mail address }
  7. { [email protected] - backup e-mail address }
  8. { }
  9. { This unit provides the interlink between the graphics }
  10. { used in GFV and the graphics API for the different }
  11. { operating systems. }
  12. { }
  13. {****************[ THIS CODE IS FREEWARE ]*****************}
  14. { }
  15. { This sourcecode is released for the purpose to }
  16. { promote the pascal language on all platforms. You may }
  17. { redistribute it and/or modify with the following }
  18. { DISCLAIMER. }
  19. { }
  20. { This SOURCE CODE is distributed "AS IS" WITHOUT }
  21. { WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR }
  22. { ANY OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED. }
  23. { }
  24. {*****************[ SUPPORTED PLATFORMS ]******************}
  25. { 16 and 32 Bit compilers }
  26. { DOS - Turbo Pascal 7.0 + (16 Bit) }
  27. { DPMI - Turbo Pascal 7.0 + (16 Bit) }
  28. { - FPC 0.9912+ (GO32V2) (32 Bit) }
  29. { WINDOWS - Turbo Pascal 7.0 + (16 Bit) }
  30. { - Delphi 1.0+ (16 Bit) }
  31. { WIN95/NT - Delphi 2.0+ (32 Bit) }
  32. { - Virtual Pascal 2.0+ (32 Bit) }
  33. { - Speedsoft Sybil 2.0+ (32 Bit) }
  34. { - FPC 0.9912+ (32 Bit) }
  35. { OS2 - Virtual Pascal 1.0+ (32 Bit) }
  36. { - Speed Pascal 1.0+ (32 Bit) }
  37. { }
  38. {*****************[ REVISION HISTORY ]*********************}
  39. { Version Date Fix }
  40. { ------- --------- ---------------------------------- }
  41. { 1.00 26 Nov 99 Unit started from relocated code }
  42. { originally from views.pas }
  43. {**********************************************************}
  44. UNIT GFVGraph;
  45. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  46. INTERFACE
  47. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  48. {====Include file to sort compiler platform out =====================}
  49. {$I Platform.inc}
  50. {====================================================================}
  51. {==== Compiler directives ===========================================}
  52. {$IFNDEF PPC_FPC} { FPC doesn't support these switches }
  53. {$F-} { Near far calls are okay }
  54. {$A+} { Word Align Data }
  55. {$B-} { Allow short circuit boolean evaluations }
  56. {$O+} { This unit may be overlaid }
  57. {$G+} { 286 Code optimization - if you're on an 8088 get a real computer }
  58. {$E+} { Emulation is on }
  59. {$N-} { No 80x87 code generation }
  60. {$ENDIF}
  61. {$X+} { Extended syntax is ok }
  62. {$R-} { Disable range checking }
  63. {$S-} { Disable Stack Checking }
  64. {$I-} { Disable IO Checking }
  65. {$Q-} { Disable Overflow Checking }
  66. {$V-} { Turn off strict VAR strings }
  67. {====================================================================}
  68. {***************************************************************************}
  69. { PUBLIC CONSTANTS }
  70. {***************************************************************************}
  71. {---------------------------------------------------------------------------}
  72. { STANDARD COLOUR CONSTANTS }
  73. {---------------------------------------------------------------------------}
  74. CONST
  75. Black = 0; { Black }
  76. Blue = 1; { Blue }
  77. Green = 2; { Green }
  78. Cyan = 3; { Cyan }
  79. Red = 4; { Red }
  80. Magenta = 5; { Magenta }
  81. Brown = 6; { Brown }
  82. LightGray = 7; { Light grey }
  83. DarkGray = 8; { Dark grey }
  84. LightBlue = 9; { Light blue }
  85. LightGreen = 10; { Light green }
  86. LightCyan = 11; { Light cyan }
  87. LightRed = 12; { Light red }
  88. LightMagenta = 13; { Light magenta }
  89. Yellow = 14; { Yellow }
  90. White = 15; { White }
  91. {---------------------------------------------------------------------------}
  92. { WRITE MODE CONSTANTS }
  93. {---------------------------------------------------------------------------}
  94. CONST
  95. NormalPut = 0; { Normal overwrite }
  96. CopyPut = 0; { Normal put image }
  97. AndPut = 1; { AND colour write }
  98. OrPut = 2; { OR colour write }
  99. XorPut = 3; { XOR colour write }
  100. NotPut = 4; { NOT colour write }
  101. {---------------------------------------------------------------------------}
  102. { CLIP CONTROL CONSTANTS }
  103. {---------------------------------------------------------------------------}
  104. CONST
  105. ClipOn = True; { Clipping on }
  106. ClipOff = False; { Clipping off }
  107. {---------------------------------------------------------------------------}
  108. { VIDEO CARD DETECTION CONSTANTS }
  109. {---------------------------------------------------------------------------}
  110. CONST
  111. Detect = 0; { Detect video }
  112. {---------------------------------------------------------------------------}
  113. { TEXT JUSTIFICATION CONSTANTS }
  114. {---------------------------------------------------------------------------}
  115. CONST
  116. LeftText = 0; { Left justify }
  117. CenterText = 1; { Centre justify }
  118. RightText = 2; { Right justify }
  119. BottomText = 0; { Bottom justify }
  120. TopText = 2; { Top justify }
  121. {---------------------------------------------------------------------------}
  122. { FILL PATTERN CONSTANTS }
  123. {---------------------------------------------------------------------------}
  124. CONST
  125. EmptyFill = 0; { No fill pattern }
  126. SolidFill = 1; { Solid colour }
  127. LineFill = 2; { Line fill }
  128. LtSlashFill = 3; { Fwd slash line type }
  129. SlashFill = 4; { Fwd slash pattern }
  130. BkSlashFill = 5; { Back slash pattern }
  131. LtBkSlashFill = 6; { Back slash line type }
  132. HatchFill = 7; { Hatch pattern }
  133. XHatchFill = 8; { Cross hatch pattern }
  134. InterleaveFill = 9; { Interleaved pattern }
  135. WideDotFill = 10; { Wide dot pattern }
  136. CloseDotFill = 11; { Close dot pattern }
  137. UserFill = 12; { User defined fill }
  138. {$IFDEF OS_WINDOWS} { WIN/NT CODE }
  139. {---------------------------------------------------------------------------}
  140. { WIN/NT STANDARD TColorRef CONSTANTS TO MATCH COLOUR CONSTANTS }
  141. {---------------------------------------------------------------------------}
  142. CONST
  143. rgb_Black = $00000000; { 0 = Black }
  144. rgb_Blue = $007F0000; { 1 = Blue }
  145. rgb_Green = $00007F00; { 2 = Green }
  146. rgb_Cyan = $007F7F00; { 3 = Cyan }
  147. rgb_Red = $0000007F; { 4 = Red }
  148. rgb_Magenta = $007F7F00; { 5 = Magenta }
  149. rgb_Brown = $00007F7F; { 6 = Brown }
  150. rgb_LightGray = $00AFAFAF; { 7 = LightGray }
  151. rgb_DarkGray = $004F4F4F; { 8 = DarkGray }
  152. rgb_LightBlue = $00FF0000; { 9 = Light Blue }
  153. rgb_LightGreen = $0000FF00; { 10 = Light Green }
  154. rgb_LightCyan = $00FFFF00; { 11 = Light Cyan }
  155. rgb_LightRed = $000000FF; { 12 = Light Red }
  156. rgb_LightMagenta = $00FFFF00; { 13 = Light Magenta }
  157. rgb_Yellow = $0000FFFF; { 14 = Yellow }
  158. rgb_White = $00FFFFFF; { 15 = White }
  159. {$ENDIF}
  160. {***************************************************************************}
  161. { PUBLIC TYPE DEFINITIONS }
  162. {***************************************************************************}
  163. {---------------------------------------------------------------------------}
  164. { ViewPortType RECORD DEFINITION }
  165. {---------------------------------------------------------------------------}
  166. TYPE
  167. ViewPortType = PACKED RECORD
  168. X1, Y1, X2, Y2: Integer; { Corners of viewport }
  169. Clip : Boolean; { Clip status }
  170. END;
  171. {***************************************************************************}
  172. { INTERFACE ROUTINES }
  173. {***************************************************************************}
  174. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  175. { GRAPHICS MODE CONTROL ROUTINES }
  176. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  177. {-SetWriteMode-------------------------------------------------------
  178. Sets the current write mode constant all subsequent draws etc. are
  179. then via the set mode.
  180. 26Nov99 LdB
  181. ---------------------------------------------------------------------}
  182. PROCEDURE SetWriteMode (Mode: Byte);
  183. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  184. { VIEWPORT CONTROL ROUTINES }
  185. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  186. {-GetViewSettings----------------------------------------------------
  187. Returns the current viewport and clip parameters in the variable.
  188. 26Nov99 LdB
  189. ---------------------------------------------------------------------}
  190. PROCEDURE GetViewSettings (Var CurrentViewPort: ViewPortType);
  191. {-SetViewPort--------------------------------------------------------
  192. Set the current viewport and clip parameters to that requested.
  193. 26Nov99 LdB
  194. ---------------------------------------------------------------------}
  195. PROCEDURE SetViewPort (X1, Y1, X2, Y2: Integer; Clip: Boolean);
  196. {***************************************************************************}
  197. { INITIALIZED PUBLIC VARIABLES }
  198. {***************************************************************************}
  199. {---------------------------------------------------------------------------}
  200. { INITIALIZED DOS/DPMI/WIN/NT/OS2 VARIABLES }
  201. {---------------------------------------------------------------------------}
  202. CONST
  203. WriteMode : Byte = 0; { Current write mode }
  204. SysScreenWidth : Integer = 640; { Default screen width }
  205. SysScreenHeight: Integer = 480; { Default screen height}
  206. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  207. IMPLEMENTATION
  208. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  209. {***************************************************************************}
  210. { PRIVATE INITIALIZED VARIABLES }
  211. {***************************************************************************}
  212. {---------------------------------------------------------------------------}
  213. { DOS/DPMI/WIN/NT/OS2 INITIALIZED VARIABLES }
  214. {---------------------------------------------------------------------------}
  215. CONST
  216. Cxp : Integer = 0; { Current x position }
  217. Cyp : Integer = 0; { Current y position }
  218. ViewPort: ViewPortType = (X1:0; Y1:0; X2: 639;
  219. Y2: 479; Clip: True); { Default viewport }
  220. {***************************************************************************}
  221. { INTERFACE ROUTINES }
  222. {***************************************************************************}
  223. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  224. { GRAPHICS MODE CONTROL ROUTINES }
  225. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  226. {---------------------------------------------------------------------------}
  227. { SetWriteMode -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 09Aug99 LdB }
  228. {---------------------------------------------------------------------------}
  229. PROCEDURE SetWriteMode (Mode: Byte);
  230. BEGIN
  231. WriteMode := Mode; { Hold writemode value }
  232. END;
  233. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  234. { VIEW PORT CONTROL ROUTINES }
  235. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  236. {---------------------------------------------------------------------------}
  237. { GetViewSettings -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 09Aug99 LdB }
  238. {---------------------------------------------------------------------------}
  239. PROCEDURE GetViewSettings (Var CurrentViewPort: ViewPortType);
  240. BEGIN
  241. CurrentViewPort := ViewPort; { Return view port }
  242. END;
  243. {---------------------------------------------------------------------------}
  244. { SetViewPort -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 09Aug99 LdB }
  245. {---------------------------------------------------------------------------}
  246. PROCEDURE SetViewPort (X1, Y1, X2, Y2: Integer; Clip: Boolean);
  247. BEGIN
  248. If (X1 < 0) Then X1 := 0; { X1 negative fix }
  249. If (X1 > SysScreenWidth) Then
  250. X1 := SysScreenWidth; { X1 off screen fix }
  251. If (Y1 < 0) Then Y1 := 0; { Y1 negative fix }
  252. If (Y1 > SysScreenHeight) Then
  253. Y1 := SysScreenHeight; { Y1 off screen fix }
  254. If (X2 < 0) Then X2 := 0; { X2 negative fix }
  255. If (X2 > SysScreenWidth) Then X2 := SysScreenWidth;{ X2 off screen fix }
  256. If (Y2 < 0) Then Y2 := 0; { Y2 negative fix }
  257. If (Y2 > SysScreenHeight) Then
  258. Y2 := SysScreenHeight; { Y2 off screen fix }
  259. ViewPort.X1 := X1; { Set X1 port value }
  260. ViewPort.Y1 := Y1; { Set Y1 port value }
  261. ViewPort.X2 := X2; { Set X2 port value }
  262. ViewPort.Y2 := Y2; { Set Y2 port value }
  263. ViewPort.Clip := Clip; { Set port clip value }
  264. Cxp := X1; { Set current x pos }
  265. Cyp := Y1; { Set current y pos }
  266. END;
  267. END.