ggi.pp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. {******************************************************************************
  2. Free Pascal conversion (c) 1999 Sebastian Guenther
  3. LibGGI API interface
  4. Copyright (C) 1997 Jason McMullan [[email protected]]
  5. Copyright (C) 1997 Steffen Seeger [[email protected]]
  6. Copyright (C) 1998 Andrew Apted [[email protected]]
  7. Copyright (C) 1998 Andreas Beck [[email protected]]
  8. Copyright (C) 1998-1999 Marcus Sundberg [[email protected]]
  9. Permission is hereby granted, free of charge, to any person obtaining a
  10. copy of this software and associated documentation files (the "Software"),
  11. to deal in the Software without restriction, including without limitation
  12. the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13. and/or sell copies of the Software, and to permit persons to whom the
  14. Software is furnished to do so, subject to the following conditions:
  15. The above copyright notice and this permission notice shall be included in
  16. all copies or substantial portions of the Software.
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. ******************************************************************************
  24. *}
  25. {$MODE objfpc}
  26. {$PACKRECORDS C}
  27. {$LINKLIB c}
  28. {$IFNDEF FPC_DOTTEDUNITS}
  29. unit GGI;
  30. {$ENDIF FPC_DOTTEDUNITS}
  31. interface
  32. {$IFDEF FPC_DOTTEDUNITS}
  33. uses Api.Gii;
  34. {$ELSE FPC_DOTTEDUNITS}
  35. uses GII;
  36. {$ENDIF FPC_DOTTEDUNITS}
  37. const
  38. libggi = 'ggi';
  39. {******************************************************************************
  40. LibGGI datatypes and structures
  41. ******************************************************************************}
  42. GGI_AUTO = 0;
  43. type
  44. TGGICoord = record
  45. x, y: SmallInt;
  46. end;
  47. TGGIPixel = LongWord;
  48. TGGIAttr = LongWord;
  49. const
  50. ATTR_FGCOLOR = $0000FF00; // fgcolor clut index
  51. ATTR_BGCOLOR = $000000FF; // bgcolor clut index
  52. ATTR_NORMAL = $00000000; // normal style
  53. ATTR_HALF = $00010000; // half intensity
  54. ATTR_BRIGHT = $00020000; // high intensity
  55. ATTR_INTENSITY = $00030000; // mask to get intensity
  56. ATTR_UNDERLINE = $00040000; // underline attribute
  57. ATTR_BOLD = $00080000; // bold style
  58. ATTR_ITALIC = $00100000; // italic style
  59. ATTR_REVERSE = $00200000; // reverse fg/bg
  60. ATTR_BLINK = $00800000; // enable blinking
  61. ATTR_FONT = $FF000000; // font table
  62. function ATTR_COLOR(fg, bg: Integer): Integer;
  63. type
  64. PGGIColor = ^TGGIColor;
  65. TGGIColor = record
  66. r, g, b, a: Word;
  67. end;
  68. PGGIClut = ^TGGIClut;
  69. TGGIClut = record
  70. size: Word;
  71. data: PGGIColor;
  72. end;
  73. const GGI_COLOR_PRECISION = 16; // 16 bit per R,G, B value
  74. // Graphtypes
  75. type TGGIGraphType = LongWord;
  76. const
  77. GT_DEPTH_SHIFT = 0;
  78. GT_SIZE_SHIFT = 8;
  79. GT_SUBSCHEME_SHIFT = 16;
  80. GT_SCHEME_SHIFT = 24;
  81. GT_DEPTH_MASK = $ff shl GT_DEPTH_SHIFT;
  82. GT_SIZE_MASK = $ff shl GT_SIZE_SHIFT;
  83. GT_SUBSCHEME_MASK = $ff shl GT_SUBSCHEME_SHIFT;
  84. GT_SCHEME_MASK = $ff shl GT_SCHEME_SHIFT;
  85. // Macros to extract info from a ggi_graphtype.
  86. function GT_DEPTH(x: Integer): Integer;
  87. function GT_SIZE(x: Integer): Integer;
  88. function GT_SUBSCHEME(x: Integer): Integer;
  89. function GT_SCHEME(x: Integer): Integer;
  90. {procedure GT_SETDEPTH(gt, x: Integer);
  91. procedure GT_SETSIZE(gt, x: Integer);
  92. procedure GT_SETSUBSCHEME(gt, x: Integer);
  93. procedure GT_SETSCHEME(gt, x: Integer);}
  94. const
  95. // Enumerated schemes
  96. GT_TEXT = 1 shl GT_SCHEME_SHIFT;
  97. GT_TRUECOLOR = 2 shl GT_SCHEME_SHIFT;
  98. GT_GREYSCALE = 3 shl GT_SCHEME_SHIFT;
  99. GT_PALETTE = 4 shl GT_SCHEME_SHIFT;
  100. GT_STATIC_PALETTE = 5 shl GT_SCHEME_SHIFT;
  101. // Subschemes
  102. GT_SUB_REVERSE_ENDIAN = 1 shl GT_SUBSCHEME_SHIFT;
  103. GT_SUB_HIGHBIT_RIGHT = 2 shl GT_SUBSCHEME_SHIFT;
  104. GT_SUB_PACKED_GETPUT = 4 shl GT_SUBSCHEME_SHIFT;
  105. // Macro that constructs a graphtype
  106. function GT_CONSTRUCT(depth, scheme, size: Integer): Integer;
  107. const
  108. // Common graphtypes
  109. GT_TEXT16 = 4 or GT_TEXT or (16 shl GT_SIZE_SHIFT);
  110. GT_TEXT32 = 8 or GT_TEXT or (32 shl GT_SIZE_SHIFT);
  111. GT_1BIT = 1 or GT_PALETTE or (1 shl GT_SIZE_SHIFT);
  112. GT_2BIT = 2 or GT_PALETTE or (2 shl GT_SIZE_SHIFT);
  113. GT_4BIT = 4 or GT_PALETTE or (4 shl GT_SIZE_SHIFT);
  114. GT_8BIT = 8 or GT_PALETTE or (8 shl GT_SIZE_SHIFT);
  115. GT_15BIT = 15 or GT_TRUECOLOR or (16 shl GT_SIZE_SHIFT);
  116. GT_16BIT = 16 or GT_TRUECOLOR or (16 shl GT_SIZE_SHIFT);
  117. GT_24BIT = 24 or GT_TRUECOLOR or (24 shl GT_SIZE_SHIFT);
  118. GT_32BIT = 24 or GT_TRUECOLOR or (32 shl GT_SIZE_SHIFT);
  119. GT_AUTO = 0;
  120. GT_INVALID = $ffffffff;
  121. // ggi_mode structure
  122. type
  123. TGGIMode = record // requested by user and changed by driver
  124. Frames: LongInt; // frames needed
  125. Visible: TGGICoord; // vis. pixels, may change slightly
  126. Virt: TGGICoord; // virtual pixels, may change
  127. Size: TGGICoord; // size of visible in mm
  128. GraphType: TGGIGraphType; // which mode ?
  129. dpp: TGGICoord; // dots per pixel
  130. end;
  131. {******************************************************************************
  132. LibGGI specific events
  133. ******************************************************************************}
  134. const
  135. GGI_CMDFLAG_LIBGGI = GII_CMDFLAG_EXTERNAL shr 1;
  136. { Tell target that the application should not/should be halted when the
  137. display is unmapped. The default is to halt the application.}
  138. GGICMD_NOHALT_ON_UNMAP = GII_CMDFLAG_EXTERNAL or GGI_CMDFLAG_LIBGGI or GII_CMDFLAG_NODATA or 1;
  139. GGICMD_HALT_ON_UNMAP = GII_CMDFLAG_EXTERNAL or GGI_CMDFLAG_LIBGGI or GII_CMDFLAG_NODATA or 2;
  140. { Requests the application to switch target/mode, or to stop drawing on
  141. the visual.
  142. The latter is only sent if the application has explicitly requested
  143. GGICMD_NOHALT_ON_UNMAP. When a GGI_REQSW_UNMAP request is sent the
  144. application should respond by sending a GGICMD_ACKNOWLEDGE_SWITCH event
  145. as quickly as possible. After the acknowledge event is sent the
  146. application must not draw onto the visual until it recieves an evExpose
  147. event, which tells the application that the visual is mapped back again.
  148. }
  149. GGICMD_REQUEST_SWITCH = GII_CMDFLAG_EXTERNAL or GGI_CMDFLAG_LIBGGI or 1;
  150. // Used for 'request' field in ggi_cmddata_switchrequest
  151. GGI_REQSW_UNMAP = 1;
  152. GGI_REQSW_MODE = 2;
  153. GGI_REQSW_TARGET = 4;
  154. type
  155. TGGICmdDataSwitchRequest = record
  156. Request: LongWord;
  157. Mode: TGGIMode;
  158. target: array[0..63] of AnsiChar;
  159. end;
  160. const
  161. GGICMD_ACKNOWLEDGE_SWITCH = GII_CMDFLAG_EXTERNAL or GGI_CMDFLAG_LIBGGI or GII_CMDFLAG_NODATA or 3;
  162. type
  163. TGGIVisual = Pointer;
  164. TGGIResource = Pointer;
  165. // Flags and frames
  166. TGGIFlags = LongWord;
  167. const
  168. GGIFLAG_ASYNC = 1;
  169. {******************************************************************************
  170. Misc macros
  171. ******************************************************************************}
  172. // Swap the bytes in a 16 respective 32 bit unsigned number
  173. function GGI_BYTEREV16(x: Integer): Integer;
  174. function GGI_BYTEREV32(x: LongWord): LongWord;
  175. // Swap the bitgroups in an 8 bit unsigned number
  176. function GGI_BITREV4(x: Integer): Integer;
  177. function GGI_BITREV2(x: Integer): Integer;
  178. function GGI_BITREV1(x: Integer): Integer;
  179. {******************************************************************************
  180. Information that can be returned to user apps
  181. ******************************************************************************}
  182. // Bitmeaning defines
  183. const
  184. GGI_BM_TYPE_NONE = 0; // This bit is not in use
  185. // Bit influences color of displayed pixel
  186. GGI_BM_TYPE_COLOR = $010000;
  187. GGI_BM_SUB_RED = $0100;
  188. GGI_BM_SUB_GREEN = $0200;
  189. GGI_BM_SUB_BLUE = $0300;
  190. GGI_BM_SUB_CYAN = $1000;
  191. GGI_BM_SUB_MAGENTA = $1100;
  192. GGI_BM_SUB_YELLOW = $1200;
  193. GGI_BM_SUB_K = $1300;
  194. GGI_BM_SUB_Y = $2000;
  195. GGI_BM_SUB_U = $2100;
  196. GGI_BM_SUB_V = $2200;
  197. GGI_BM_SUB_CLUT = $f000; // This bit Color or attrib ?
  198. // Bit changes appearance of pixel/glyph
  199. GGI_BM_TYPE_ATTRIB = $020000;
  200. GGI_BM_SUB_ALPHA = $0100;
  201. GGI_BM_SUB_BLINK = $1000;
  202. GGI_BM_SUB_INTENSITY = $1100;
  203. GGI_BM_SUB_UNDERLINE = $1200;
  204. GGI_BM_SUB_BOLD = $1300;
  205. GGI_BM_SUB_ITALIC = $1400;
  206. GGI_BM_SUB_FGCOL = $2000;
  207. GGI_BM_SUB_BGCOL = $2100;
  208. GGI_BM_SUB_TEXNUM = $3000;
  209. GGI_BM_SUB_FONTSEL = $3100; // select different font banks
  210. GGI_BM_SUB_PALSEL = $3200; // select different palettes
  211. GGI_BM_SUB_MODESEL = $3300; // select different palettes
  212. // Bit that influence drawing logic
  213. GGI_BM_TYPE_LOGIC = $030000;
  214. GGI_BM_SUB_ZBUFFER = $0100;
  215. GGI_BM_SUB_WRITEPROT = $1000;
  216. GGI_BM_SUB_WINDOWID = $2000;
  217. // Pixelformat for ggiGet/Put* buffers and pixellinearbuffers */
  218. type
  219. PGGIPixelFormat = ^TGGIPixelFormat;
  220. TGGIPixelFormat = record
  221. depth: Integer; // Number of significant bits
  222. size: Integer; // Physical size in bits
  223. {* Simple and common things first :
  224. *
  225. * Usage of the mask/shift pairs:
  226. * If new_value is the _sizeof(ggi_pixel)*8bit_ value of the thing
  227. * you want to set, you do
  228. *
  229. * *pointer &= ~???_mask; // Mask out old bits
  230. * *pointer |= (new_value>>shift) & ???_mask;
  231. *
  232. * The reason to use 32 bit and "downshifting" is alignment
  233. * and extensibility. You can easily adjust to other datasizes
  234. * with a simple addition ...
  235. *}
  236. // Simple colors:
  237. red_mask: TGGIPixel; // Bitmask of red bits
  238. red_shift: Integer; // Shift for red bits
  239. green_mask: TGGIPixel; // Bitmask of green bits
  240. green_shift: Integer; // Shift for green bits
  241. blue_mask: TGGIPixel; // Bitmask of blue bits
  242. blue_shift: Integer; // Shift for blue bits
  243. // A few common attributes:
  244. alpha_mask: TGGIPixel; // Bitmask of alphachannel bits
  245. alpha_shift: Integer; // Shift for alpha bits
  246. clut_mask: TGGIPixel; // Bitmask of bits for the clut
  247. clut_shift: Integer; // Shift for bits for the clut
  248. fg_mask: TGGIPixel; // Bitmask of foreground color
  249. fg_shift: Integer; // Shift for foreground color
  250. bg_mask: TGGIPixel; // Bitmask of background color
  251. bg_shift: Integer; // Shift for background color
  252. texture_mask: TGGIPixel; // Bitmask of the texture (for
  253. // textmodes - the actual character)
  254. texture_shift: Integer; // Shift for texture
  255. // Now if this does not suffice you might want to parse the following
  256. // to find out what each bit does:
  257. bitmeaning: array[0..SizeOf(TGGIPixel) * 8 - 1] of LongWord;
  258. // Shall we keep those?
  259. flags: LongWord; // Pixelformat flags
  260. stdformat: LongWord; // Standard format identifier
  261. {* This one has only one use for the usermode application:
  262. * To quickly check, if two buffers are identical. If both
  263. * stdformats are the same and _NOT_ 0 (which means "WEIRD"),
  264. * you may use things like memcpy between them which will have
  265. * the desired effect ...
  266. *}
  267. end;
  268. const
  269. // Pixelformat flags
  270. GGI_PF_REVERSE_ENDIAN = 1;
  271. GGI_PF_HIGHBIT_RIGHT = 2;
  272. GGI_PF_HAM = 4;
  273. GGI_PF_EXTENDED = 8;
  274. {******************************************************************************
  275. DirectBuffer
  276. ******************************************************************************}
  277. type
  278. TGGIBufferLayout = (
  279. blPixelLinearBuffer,
  280. blPixelPlanarBuffer,
  281. blExtended,
  282. blLastBufferLayout
  283. );
  284. PGGIPixelLinearBuffer = ^TGGIPixelLinearBuffer;
  285. TGGIPixelLinearBuffer = record
  286. stride: Integer; // bytes per row
  287. pixelformat: PGGIPixelFormat; // format of the pixels
  288. end;
  289. PGGIPixelPlanarBuffer = ^TGGIPixelPlanarBuffer;
  290. TGGIPixelPlanarBuffer = record
  291. next_line: Integer; // bytes until next line
  292. next_plane: Integer; // bytes until next plane
  293. pixelformat: PGGIPixelFormat; // format of the pixels
  294. end;
  295. // Buffer types
  296. const
  297. GGI_DB_NORMAL = 1; // "frame" is valid when set
  298. GGI_DB_EXTENDED = 2;
  299. GGI_DB_MULTI_LEFT = 4;
  300. GGI_DB_MULTI_RIGHT = 8;
  301. // Flags that may be 'or'ed with the buffer type
  302. GGI_DB_SIMPLE_PLB = $01000000;
  303. { GGI_DB_SIMPLE_PLB means that the buffer has the following properties:
  304. type = GGI_DB_NORMAL
  305. read = write
  306. noaccess = 0
  307. align = 0
  308. layout = blPixelLinearBuffer
  309. }
  310. type
  311. PGGIDirectBuffer = ^TGGIDirectBuffer;
  312. TGGIDirectBuffer = record
  313. BufferType: LongWord; // buffer type
  314. frame: Integer; // framenumber (GGI_DB_NORMAL)
  315. // access info
  316. resource: TGGIResource; // If non-NULL you must acquire the
  317. // buffer before using it
  318. read: Pointer; // buffer address for reads
  319. write:Pointer; // buffer address for writes
  320. page_size: LongWord; // zero for true linear buffers
  321. noaccess: LongWord;
  322. {bitfield. bit x set means you may _not_ access this DB at the
  323. width of 2^x bytes. Usually 0, but _check_ it.}
  324. align: LongWord;
  325. {bitfield. bit x set means you may only access this DB at the
  326. width of 2^x bytes, when the access is aligned to a multiple
  327. of 2^x. Note that bit 0 is a bit bogus here, but it should
  328. be always 0, as then ((noaccess|align)==0) is a quick check
  329. for "no restrictions". }
  330. layout: TGGIBufferLayout;
  331. // The actual buffer info. Depends on layout.
  332. buffer: record
  333. case Integer of
  334. 0: (plb: TGGIPixelLinearBuffer);
  335. 1: (plan: TGGIPixelPlanarBuffer);
  336. 2: (extended: Pointer);
  337. end;
  338. end;
  339. {******************************************************************************
  340. Resource management
  341. ******************************************************************************}
  342. // Access types
  343. const
  344. GGI_ACTYPE_READ = 1 shl 0;
  345. GGI_ACTYPE_WRITE = 1 shl 1;
  346. {******************************************************************************
  347. LibGGI function definitions
  348. ******************************************************************************}
  349. // Enter and leave the library
  350. function ggiInit: Integer; cdecl; external libggi;
  351. procedure ggiExit; cdecl; external libggi;
  352. procedure ggiPanic(format: PAnsiChar; args: array of const); cdecl; external libggi;
  353. // Open a new visual - use display 'NULL' for the default visual
  354. function ggiOpen(display: PAnsiChar; args: array of const): TGGIVisual; cdecl; external libggi;
  355. function ggiClose(vis: TGGIVisual): Integer; cdecl; external libggi;
  356. // Get/Set info
  357. function ggiSetFlags(vis: TGGIVisual; flags: TGGIFlags): Integer; cdecl; external libggi;
  358. function ggiGetFlags(vis: TGGIVisual): TGGIFlags; cdecl; external libggi;
  359. function ggiAddFlags(vis: TGGIVisual; flags: TGGIFlags): Integer;
  360. function ggiRemoveFlags(vis: TGGIVisual; flags: TGGIFlags): Integer;
  361. function ggiGetPixelFormat(vis: TGGIVisual): PGGIPixelFormat; cdecl; external libggi;
  362. // DirectBuffer (DB) functions
  363. function ggiDBGetNumBuffers(vis: TGGIVisual): Integer; cdecl; external libggi;
  364. function ggiDBGetBuffer(vis: TGGIVisual; bufnum: Integer): PGGIDirectBuffer; cdecl; external libggi;
  365. // Resource functions
  366. function ggiResourceAcquire(res: TGGIResource; actype: LongWord): Integer;
  367. function ggiResourceRelease(res: TGGIResource): Integer;
  368. function ggiResourceFastAcquire(res: TGGIResource; actype: LongWord): Integer; cdecl; external libggi;
  369. function ggiResourceFastRelease(res: TGGIResource): Integer; cdecl; external libggi;
  370. // Library management
  371. const GGI_MAX_APILEN = 1024;
  372. function ggiGetAPI(vis: TGGIVisual; num: Integer; APIName, arguments: PAnsiChar): Integer; cdecl; external libggi;
  373. const GGI_CHG_APILIST = 1;
  374. function ggiIndicateChange(vis: TGGIVisual; WhatChanged: Integer): Integer; cdecl; external libggi;
  375. // Mode management
  376. function ggiSetMode(visual: TGGIVisual; var tm: TGGIMode): Integer; cdecl; external libggi;
  377. function ggiGetMode(visual: TGGIVisual; var tm: TGGIMode): Integer; cdecl; external libggi;
  378. function ggiCheckMode(visual: TGGIVisual; var tm: TGGIMode): Integer; cdecl; external libggi;
  379. function ggiSetTextMode(visual: TGGIVisual; cols, rows, vcols, vrows, fontx, fonty: Integer; AType: TGGIGraphType): Integer; cdecl; external libggi;
  380. function ggiCheckTextMode(visual: TGGIVisual; cols, rows, vcols, vrows, fontx, fonty: Integer; var SuggestedMode: TGGIMode): Integer; cdecl; external libggi;
  381. function ggiSetGraphMode(visual: TGGIVisual; x, y, xv, yv: Integer; AType: TGGIGraphType): Integer; cdecl; external libggi;
  382. function ggiCheckGraphMode(visual: TGGIVisual; x, y, xv, yv: Integer; AType: TGGIGraphType; var SuggestedMode: TGGIMode): Integer; cdecl; external libggi;
  383. function ggiSetSimpleMode(visual: TGGIVisual; xsize, ysize, frames: Integer; AType: TGGIGraphType): Integer; cdecl; external libggi;
  384. function ggiCheckSimpleMode(visual: TGGIVisual; xsize, ysize, frames: Integer; AType: TGGIGraphType; var md: TGGIMode): Integer; cdecl; external libggi;
  385. // Print all members of the mode struct
  386. function ggiSPrintMode(s: PAnsiChar; var m: TGGIMode): Integer; cdecl; external libggi;
  387. // function ggiFPrintMode(s: PFile; var m: TGGIMode): Integer; cdecl; external libggi;
  388. // #define ggiPrintMode(m) ggiFPrintMode(stdout,(m))
  389. // Fill a mode struct from the text string s
  390. function ggiParseMode(s: PAnsiChar; var m: TGGIMode): Integer; cdecl; external libggi;
  391. // Flush all pending operations to the display device
  392. // Normal flush
  393. function ggiFlush(vis: TGGIVisual): Integer; cdecl; external libggi;
  394. // Flush only the specified region if it would improve performance
  395. function ggiFlushRegion(vis: TGGIVisual; x, y, w, h: Integer): Integer; cdecl; external libggi;
  396. // Graphics context
  397. function ggiSetGCForeground(vis: TGGIVisual; const Color: TGGIPixel): Integer; cdecl; external libggi;
  398. function ggiGetGCForeground(vis: TGGIVisual; var Color: TGGIPixel): Integer; cdecl; external libggi;
  399. function ggiSetGCBackground(vis: TGGIVisual; const Color: TGGIPixel): Integer; cdecl; external libggi;
  400. function ggiGetGCBackground(vis: TGGIVisual; var Color: TGGIPixel): Integer; cdecl; external libggi;
  401. function ggiSetGCClipping(vis: TGGIVisual; left, top, right, bottom: Integer): Integer; cdecl; external libggi;
  402. function ggiGetGCClipping(vis: TGGIVisual; var left, top, right, bottom: Integer): Integer; cdecl; external libggi;
  403. // Color palette manipulation
  404. function ggiMapColor(vis: TGGIVisual; var Color: TGGIColor): TGGIPixel; cdecl; external libggi;
  405. function ggiUnmapPixel(vis: TGGIVisual; pixel: TGGIPixel; var Color: TGGIColor): Integer; cdecl; external libggi;
  406. function ggiPackColors(vis: TGGIVisual; var buf; var cols: TGGIColor; len: Integer): Integer; cdecl; external libggi;
  407. function ggiUnpackPixels(vis: TGGIVisual; var buf; var cols: TGGIColor; len: Integer): Integer; cdecl; external libggi;
  408. function ggiGetPalette(vis: TGGIVisual; s, len: Integer; var cmap: TGGIColor): Integer; cdecl; external libggi;
  409. function ggiSetPalette(vis: TGGIVisual; s, len: Integer; var cmap: TGGIColor): Integer; cdecl; external libggi;
  410. function ggiSetColorfulPalette(vis: TGGIVisual): Integer; cdecl; external libggi;
  411. const GGI_PALETTE_DONTCARE = -1;
  412. // Gamma map manipulation
  413. function ggiGetGamma(vis: TGGIVisual; var r, g, b: Double): Integer; cdecl; external libggi;
  414. function ggiSetGamma(vis: TGGIVisual; r, g, b: Double): Integer; cdecl; external libggi;
  415. function ggiGetGammaMap(vis: TGGIVisual; s, len: Integer; var gammamap: TGGIColor): Integer; cdecl; external libggi;
  416. function ggiSetGammaMap(vis: TGGIVisual; s, len: Integer; var gammamap: TGGIColor): Integer; cdecl; external libggi;
  417. // Origin handling
  418. function ggiSetOrigin(vis: TGGIVisual; x, y: Integer): Integer; cdecl; external libggi;
  419. function ggiGetOrigin(vis: TGGIVisual; var x, y: Integer): Integer; cdecl; external libggi;
  420. // Frame handling
  421. function ggiSetDisplayFrame(vis: TGGIVisual; FrameNo: Integer): Integer; cdecl; external libggi;
  422. function ggiSetReadFrame(vis: TGGIVisual; FrameNo: Integer): Integer; cdecl; external libggi;
  423. function ggiSetWriteFrame(vis: TGGIVisual; FrameNo: Integer): Integer; cdecl; external libggi;
  424. function ggiGetDisplayFrame(vis: TGGIVisual): Integer; cdecl; external libggi;
  425. function ggiGetReadFrame(vis: TGGIVisual): Integer; cdecl; external libggi;
  426. function ggiGetWriteFrame(vis: TGGIVisual): Integer; cdecl; external libggi;
  427. // Generic drawing routines
  428. function ggiFillscreen(vis: TGGIVisual): Integer; cdecl; external libggi;
  429. function ggiDrawPixel(vis: TGGIVisual; x, y: Integer): Integer; cdecl; external libggi;
  430. function ggiPutPixel(vis: TGGIVisual; x, y: Integer; pixel: TGGIPixel): Integer; cdecl; external libggi;
  431. function ggiGetPixel(vis: TGGIVisual; x, y: Integer; var pixel: TGGIPixel): Integer; cdecl; external libggi;
  432. function ggiDrawLine(vis: TGGIVisual; x, y, xe, ye: Integer): Integer; cdecl; external libggi;
  433. function ggiDrawHLine(vis: TGGIVisual; x, y, w: Integer): Integer; cdecl; external libggi;
  434. function ggiPutHLine(vis: TGGIVisual; x, y, w: Integer; var buf): Integer; cdecl; external libggi;
  435. function ggiGetHLine(vis: TGGIVisual; x, y, w: Integer; var buf): Integer; cdecl; external libggi;
  436. function ggiDrawVLine(vis: TGGIVisual; x, y, h: Integer): Integer; cdecl; external libggi;
  437. function ggiPutVLine(vis: TGGIVisual; x, y, h: Integer; var buf): Integer; cdecl; external libggi;
  438. function ggiGetVLine(vis: TGGIVisual; x, y, h: Integer; var buf): Integer; cdecl; external libggi;
  439. function ggiDrawBox(vis: TGGIVisual; x, y, w, h: Integer): Integer; cdecl; external libggi;
  440. function ggiPutBox(vis: TGGIVisual; x, y, w, h: Integer; var buffer): Integer; cdecl; external libggi;
  441. function ggiGetBox(vis: TGGIVisual; x, y, w, h: Integer; var buffer): Integer; cdecl; external libggi;
  442. function ggiCopyBox(vis: TGGIVisual; x, y, w, h, nx, ny: Integer): Integer; cdecl; external libggi;
  443. function ggiCrossBlit(src: TGGIVisual; sx, sy, w, h: Integer; dst: TGGIVisual; dx, dy: Integer): Integer; cdecl; external libggi;
  444. // Text drawing routines
  445. function ggiPutc(vis: TGGIVisual; x, y: Integer; c: AnsiChar): Integer; cdecl; external libggi;
  446. function ggiPuts(vis: TGGIVisual; x, y: Integer; str: PAnsiChar): Integer; cdecl; external libggi;
  447. function ggiGetCharSize(vis: TGGIVisual; var width, height: Integer): Integer; cdecl; external libggi;
  448. // Event handling
  449. //###function ggiEventPoll(vis: TGGIVisual; mask: TGIIEventMask; var t: TTimeVal): TGIIEventMask; cdecl; external libggi;
  450. function ggiEventsQueued(vis: TGGIVisual; mask: TGIIEventMask): Integer; cdecl; external libggi;
  451. function ggiEventRead(vis: TGGIVisual; var Event: TGIIEvent; mask: TGIIEventMask): Integer; cdecl; external libggi;
  452. function ggiSetEventMask(vis: TGGIVisual; EventMask: TGIIEventMask): Integer; cdecl; external libggi;
  453. function ggiGetEventMask(vis: TGGIVisual): TGIIEventMask; cdecl; external libggi;
  454. function ggiEventSend(vis: TGGIVisual; var Event: TGIIEvent): Integer; cdecl; external libggi;
  455. function ggiJoinInputs(vis: TGGIVisual; Input: TGIIInput): TGIIInput; cdecl; external libggi;
  456. function ggiAddEventMask(vis: TGGIVisual; Mask: TGIIEventMask): Integer;
  457. function ggiRemoveEventMask(vis: TGGIVisual; Mask: TGIIEventMask): Integer;
  458. // Convenience functions
  459. function ggiKbhit(vis: TGGIVisual): Integer; cdecl; external libggi;
  460. function ggiGetc(vis: TGGIVisual): Integer; cdecl; external libggi;
  461. // Extension handling
  462. type
  463. TGGILibID = Pointer;
  464. TGGIExtID = Integer; {Don't rely on that !}
  465. TGGIParamChangeProc = function(Visual: TGGIVisual; WhatChanged: Integer): Integer;
  466. function ggiExtensionRegister(name: PAnsiChar; size: Integer;
  467. ParamChange: TGGIParamChangeProc): TGGIExtID; cdecl; external libggi;
  468. function ggiExtensionUnregister(id: TGGIExtID): Integer; cdecl; external libggi;
  469. function ggiExtensionAttach(Visual: TGGIVisual; id: TGGIExtID): Integer; cdecl; external libggi;
  470. function ggiExtensionDetach(Visual: TGGIVisual; id: TGGIExtID): Integer; cdecl; external libggi;
  471. function ggiExtensionLoadDL(Visual: TGGIVisual; filename, args: PAnsiChar; ArgPtr: Pointer): TGGILibID; cdecl; external libggi;
  472. // ===================================================================
  473. // ===================================================================
  474. implementation
  475. function ATTR_COLOR(fg, bg: Integer): Integer;
  476. begin
  477. Result := (bg and $ff) or ((fg and $ff) shl 8);
  478. end;
  479. function GT_DEPTH(x: Integer): Integer;
  480. begin
  481. Result := (x and GT_DEPTH_MASK) shr GT_DEPTH_SHIFT;
  482. end;
  483. function GT_SIZE(x: Integer): Integer;
  484. begin
  485. Result := (x and GT_SIZE_MASK) shr GT_SIZE_SHIFT;
  486. end;
  487. function GT_SUBSCHEME(x: Integer): Integer;
  488. begin
  489. Result := x and GT_SUBSCHEME_MASK;
  490. end;
  491. function GT_SCHEME(x: Integer): Integer;
  492. begin
  493. Result := x and GT_SCHEME_MASK;
  494. end;
  495. function GT_CONSTRUCT(depth, scheme, size: Integer): Integer;
  496. begin
  497. Result := depth or scheme or (size shl GT_SIZE_SHIFT);
  498. end;
  499. function GGI_BYTEREV16(x: Integer): Integer;
  500. begin
  501. Result := (x shl 8) or (x shr 8);
  502. end;
  503. function GGI_BYTEREV32(x: LongWord): LongWord;
  504. begin
  505. Result := (x shl 24) or ((x and $ff00) shl 8) or
  506. ((x and $ff0000) shr 8) or (x shr 24);
  507. end;
  508. function GGI_BITREV4(x: Integer): Integer;
  509. begin
  510. Result := (x shr 4) or (x shl 4);
  511. end;
  512. function GGI_BITREV2(x: Integer): Integer;
  513. begin
  514. Result := (x shr 6) or ((x and $30) shr 2) or ((x and $0c) shl 2) or (x shl 6);
  515. end;
  516. function GGI_BITREV1(x: Integer): Integer;
  517. begin
  518. Result := (x shr 7) or ((x and $40) shr 5) or ((x and $20) shr 3) or
  519. ((x and $10) shr 1) or ((x and 8) shl 1) or ((x and 4) shl 3) or
  520. ((x and 2) shl 4) or (x shl 7);
  521. end;
  522. function ggiAddFlags(vis: TGGIVisual; flags: TGGIFlags): Integer;
  523. begin
  524. Result := ggiSetFlags(vis, ggiGetFlags(vis) or flags);
  525. end;
  526. function ggiRemoveFlags(vis: TGGIVisual; flags: TGGIFlags): Integer;
  527. begin
  528. Result := ggiSetFlags(vis, ggiGetFlags(vis) and not flags);
  529. end;
  530. function ggiResourceAcquire(res: TGGIResource; actype: LongWord): Integer;
  531. begin
  532. if res = nil then Result := 0
  533. else Result := ggiResourceFastAcquire(res, actype);
  534. end;
  535. function ggiResourceRelease(res: TGGIResource): Integer;
  536. begin
  537. if res = nil then Result := 0
  538. else Result := ggiResourceFastRelease(res);
  539. end;
  540. function ggiAddEventMask(vis: TGGIVisual; Mask: TGIIEventMask): Integer;
  541. begin
  542. Result := ggiSetEventMask(vis, ggiGetEventMask(vis) or mask);
  543. end;
  544. function ggiRemoveEventMask(vis: TGGIVisual; Mask: TGIIEventMask): Integer;
  545. begin
  546. Result := ggiSetEventMask(vis, ggiGetEventMask(vis) and not mask);
  547. end;
  548. end.