ggi.pp 26 KB

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