tigr.def 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. DEFINITION MODULE FOR "C" tigr;
  2. FROM SYSTEM IMPORT ADDRESS,BYTE;
  3. FROM DynamicStrings IMPORT String;
  4. EXPORT UNQUALIFIED tigrWindow, TigrPtr, tigrFree, tigrClosed,
  5. tigrClear,tigrUpdate,TPixelPtr,TPixelType,tigrLine, TK_ESCAPE, tigrKeyDown,
  6. tigrReadChar, tfont, tigrPrint,tigrFill,tigrCircle, tigrRect, tigrFillCircle,
  7. tigrTime, tigrError, tigrClip, tigrFillRect, tigrTextWidth, tigrTextHeight,
  8. tigrLoadImage,tigrReadFile, tigrBitmap, TIGR_2X ,tigrSetPostFX, tigrMouse,
  9. tigrBlit, tigrBlitAlpha ,tigrEncodeUTF8, TK_RIGHT,tigrKeyHeld, TK_SPACE, TK_LEFT;
  10. CONST
  11. TIGR_FIXED = 0; (* window's bitmap is a fixed size (default) *)
  12. TIGR_AUTO = 1; (* window's bitmap is scaled with the window *)
  13. TIGR_2X = 2; (* always enforce (at least) 2X pixel scale *)
  14. TIGR_3X = 4; (* always enforce (at least) 3X pixel scale *)
  15. TIGR_4X = 8; (* always enforce (at least) 4X pixel scale *)
  16. TIGR_RETINA = 16; (* enable retina support on OS X *)
  17. TIGR_NOCURSOR = 32; (* hide cursor *)
  18. TIGR_FULLSCREEN = 64;
  19. TYPE
  20. TPixelPtr = POINTER TO TPixelType;
  21. TPixelType = RECORD
  22. r, g, b, a : BYTE;
  23. END;
  24. TigrPtr = POINTER TO TigrType;
  25. TigrType = RECORD
  26. w,h : CARDINAL;
  27. cx, cy, cw, ch : CARDINAL;
  28. pix : TPixelPtr;
  29. handle : ADDRESS;
  30. blitMode : CARDINAL;
  31. END;
  32. intPtr = POINTER TO INTEGER;
  33. shortRealPtr = POINTER TO SHORTREAL;
  34. VAR Tigr : TigrType;
  35. (* Creates a new empty window with a given bitmap size.
  36. Title is UTF-8.
  37. In TIGR_FIXED mode, the window is made as large as possible to contain an integer-scaled
  38. version of the bitmap while still fitting on the screen. Resizing the window will adapt
  39. the scale in integer steps to fit the bitmap.
  40. In TIGR_AUTO mode, the initial window size is set to the bitmap size times the pixel
  41. scale. Resizing the window will resize the bitmap using the specified scale.
  42. For example, in forced 2X mode, the window will be twice as wide (and high) as the bitmap.
  43. Turning on TIGR_RETINA mode will request full backing resolution on OSX, meaning that
  44. the effective window size might be integer scaled to a larger size. In TIGR_AUTO mode,
  45. this means that the Tigr bitmap will change size if the window is moved between
  46. retina and non-retina screens. *)
  47. PROCEDURE tigrWindow( w, h: CARDINAL; title : String; flags : INTEGER): TigrPtr;
  48. (* Creates an empty off-screen bitmap. *)
  49. PROCEDURE tigrBitmap(w,h : CARDINAL): TigrPtr;
  50. (* Deletes a window/bitmap. *)
  51. PROCEDURE tigrFree(bmp: TigrPtr);
  52. (* Returns non-zero if the user requested to close a window. *)
  53. PROCEDURE tigrClosed(bmp: TigrPtr): INTEGER;
  54. (* Displays a window's contents on-screen and updates input. *)
  55. PROCEDURE tigrUpdate(bmp: TigrPtr);
  56. (* Called before doing direct OpenGL calls and before tigrUpdate.
  57. Returns non-zero if OpenGL is available. *)
  58. PROCEDURE tigrBeginOpenGL(bmp: TigrPtr): INTEGER;
  59. (* Sets post shader for a window.
  60. This replaces the built-in post-FX shader. *)
  61. PROCEDURE tigrSetPostShader(bmp: TigrPtr; code: ARRAY OF CHAR; size: CARDINAL);
  62. (* Sets post-FX properties for a window.
  63. The built-in post-FX shader uses the following parameters:
  64. p1: hblur - use bilinear filtering along the x-axis (pixels)
  65. p2: vblur - use bilinear filtering along the y-axis (pixels)
  66. p3: scanlines - CRT scanlines effect (0-1)
  67. p4: contrast - contrast boost (1 = no change, 2 = 2X contrast, etc) *)
  68. PROCEDURE tigrSetPostFX(bmp: TigrPtr; p1, p2, p3, p4 : SHORTREAL);
  69. (* Drawing ---------------------------------------------------------------- *)
  70. (* Helper for reading pixels.
  71. For high performance, just access bmp->pix directly. *)
  72. PROCEDURE tigrGet(bmp: TigrPtr; x, y: CARDINAL): TPixelType;
  73. (* Plots a pixel.
  74. Clips and blends.
  75. For high performance, just access bmp->pix directly. *)
  76. PROCEDURE tigrPlot(bmp: TigrPtr; x, y: CARDINAL; pix: TPixelType);
  77. (* Clears a bitmap to a color.
  78. No blending, no clipping. *)
  79. PROCEDURE tigrClear(bmp: TigrPtr; color: TPixelType);
  80. (* Fills a rectangular area.
  81. No blending, no clipping. *)
  82. PROCEDURE tigrFill(bmp: TigrPtr; x, y, w, h: CARDINAL; color: TPixelType);
  83. (* Draws a line.
  84. Start pixel is drawn, end pixel is not.
  85. Clips and blends. *)
  86. PROCEDURE tigrLine(bmp: TigrPtr; x0, y0, x1, y1: CARDINAL; color: TPixelType);
  87. (* Draws an empty rectangle.
  88. Drawing a 1x1 rectangle yields the same result as calling tigrPlot.
  89. Clips and blends. *)
  90. PROCEDURE tigrRect(bmp: TigrPtr; x, y, w, h: CARDINAL; color: TPixelType);
  91. (* Fills a rectangle.
  92. Fills the inside of the specified rectangular area.
  93. Calling tigrRect followed by tigrFillRect using the same arguments
  94. causes no overdrawing.
  95. Clips and blends. *)
  96. PROCEDURE tigrFillRect(bmp: TigrPtr; x, y, w, h: CARDINAL; color: TPixelType);
  97. (* Draws a circle.
  98. Drawing a zero radius circle yields the same result as calling tigrPlot.
  99. Drawing a circle with radius one draws a circle three pixels wide.
  100. Clips and blends. *)
  101. PROCEDURE tigrCircle(bmp: TigrPtr; x, y, r: CARDINAL; color: TPixelType);
  102. (* Fills a circle.
  103. Fills the inside of the specified circle.
  104. Calling tigrCircle followed by tigrFillCircle using the same arguments
  105. causes no overdrawing.
  106. Filling a circle with zero radius has no effect.
  107. Clips and blends. *)
  108. PROCEDURE tigrFillCircle(bmp: TigrPtr; x,y,r: CARDINAL; color: TPixelType );
  109. (* Sets clip rect.
  110. Set to (0, 0, -1, -1) to reset clipping to full bitmap. *)
  111. PROCEDURE tigrClip(bmp : TigrPtr; cx,cy,cw,ch: CARDINAL);
  112. (* Heper procedures in a separate file*)
  113. (* Copies bitmap data.
  114. dx/dy = dest co-ordinates
  115. sx/sy = source co-ordinates
  116. w/h = width/height
  117. RGBAdest = RGBAsrc
  118. Clips, does not blend. *)
  119. PROCEDURE tigrBlit(dest: TigrPtr; src: TigrPtr; dx, dy, sx, sy, w, h: CARDINAL);
  120. (*
  121. Same as tigrBlit, but alpha blends the source bitmap with the
  122. target using per pixel alpha and the specified global alpha.
  123. Ablend = Asrc * alpha
  124. RGBdest = RGBsrc * Ablend + RGBdest * (1 - Ablend)
  125. Blit mode == TIGR_KEEP_ALPHA:
  126. Adest = Adest
  127. Blit mode == TIGR_BLEND_ALPHA:
  128. Adest = Asrc * Ablend + Adest * (1 - Ablend)
  129. Clips and blends.
  130. *)
  131. PROCEDURE tigrBlitAlpha(dest, src: TigrPtr; dx, dy, sx, sy, w, h: CARDINAL; alpha: SHORTREAL);
  132. (* Same as tigrBlit, but tints the source bitmap with a color
  133. and alpha blends the resulting source with the destination.
  134. Rblend = Rsrc * Rtint
  135. Gblend = Gsrc * Gtint
  136. Bblend = Bsrc * Btint
  137. Ablend = Asrc * Atint
  138. RGBdest = RGBblend * Ablend + RGBdest * (1 - Ablend)
  139. Blit mode == TIGR_KEEP_ALPHA:
  140. Adest = Adest
  141. Blit mode == TIGR_BLEND_ALPHA:
  142. Adest = Ablend * Ablend + Adest * (1 - Ablend)
  143. Clips and blends. *)
  144. PROCEDURE tigrBlitTint(dest, src: TigrPtr; dx, dy, sx, sy, w, h: CARDINAL; tint: TPixelType);
  145. (*TIGR_KEEP_ALPHA Keep destination alpha value*)
  146. (*TIGR_BLEND_ALPHA Blend destination alpha (default) *)
  147. CONST
  148. TIGR_KEEP_ALPHA = 0;
  149. TIGR_BLEND_ALPHA = -1;
  150. (* Set destination bitmap blend mode for blit operations. *)
  151. PROCEDURE tigrBlitMode(dest : TigrPtr; mode: CARDINAL);
  152. (* Font printing ---------------------------------------------------------- *)
  153. TYPE
  154. TigrGlyphType = RECORD
  155. code: INTEGER;
  156. x, y, w, h: CARDINAL;
  157. END;
  158. TigrFontTypePtr = POINTER TO TigrFontType;
  159. TigrFontType = RECORD
  160. bitmap: TigrPtr;
  161. numGlyphs: CARDINAL;
  162. glyphs: POINTER TO TigrGlyphType;
  163. END;
  164. TCodepageType = (TCP_ASCII, TCP_1252, TCP_UTF32);
  165. VAR
  166. TigrGlyph: TigrGlyphType;
  167. TigrFont: TigrFontType;
  168. TCodepage: TCodepageType;
  169. (* Loads a font from a bitmap font sheet.
  170. The loaded font takes ownership of the provided bitmap.
  171. Codepages:
  172. TCP_ASCII - Regular 7-bit ASCII
  173. TCP_1252 - Windows 1252
  174. TCP_UTF32 - Unicode subset
  175. For ASCII and 1252, the font bitmap should contain all characters
  176. for the given codepage, excluding the first 32 control codes.
  177. For UTF32 - the font bitmap contains a subset of Unicode characters
  178. and must be in the format generated by tigrFont for UTF32. *)
  179. PROCEDURE tigrLoadFont(bitmap: TigrPtr; codepage: CARDINAL): TigrFontTypePtr;
  180. (* Frees a font and associated font sheet. *)
  181. PROCEDURE tigrFreeFont(font: TigrFontTypePtr);
  182. (* Prints UTF-8 text onto a bitmap.
  183. NOTE:
  184. This uses the target bitmap blit mode.
  185. See tigrBlitTint for details. *)
  186. PROCEDURE tigrPrint(dest: TigrPtr; font: TigrFontTypePtr; x, y: CARDINAL; color: TPixelType; text : String; ...);
  187. (* Returns the width/height of a string. *)
  188. PROCEDURE tigrTextWidth(font: TigrFontTypePtr; text: ARRAY OF CHAR): INTEGER;
  189. PROCEDURE tigrTextHeight(font: TigrFontTypePtr; text: ARRAY OF CHAR): INTEGER;
  190. (* The built-in font. *)
  191. VAR tfont: TigrFontTypePtr;
  192. (* User Input -------------------------------------------------------------
  193. Key scancodes. For letters/numbers, use ASCII ('A'-'Z' and '0'-'9'). *)
  194. CONST
  195. TK_PAD0 = 128;
  196. TK_PAD1 = 129;
  197. TK_PAD2 = 130;
  198. TK_PAD3 = 131;
  199. TK_PAD4 = 132;
  200. TK_PAD5 = 133;
  201. TK_PAD6 = 134;
  202. TK_PAD7 = 135;
  203. TK_PAD8 = 136;
  204. TK_PAD9 = 137;
  205. TK_PADMUL = 138;
  206. TK_PADADD = 139;
  207. TK_PADENTER = 140;
  208. TK_PADSUB = 141;
  209. TK_PADDOT = 142;
  210. TK_PADDIV = 143;
  211. TK_F1 = 144;
  212. TK_F2 = 145;
  213. TK_F3 = 146;
  214. TK_F4 = 147;
  215. TK_F5 = 148;
  216. TK_F6 = 149;
  217. TK_F7 = 150;
  218. TK_F8 = 151;
  219. TK_F9 = 152;
  220. TK_F10 = 153;
  221. TK_F11 = 154;
  222. TK_F12 = 155;
  223. TK_BACKSPACE = 156;
  224. TK_TAB = 157;
  225. TK_RETURN = 158;
  226. TK_SHIFT = 159;
  227. TK_CONTROL = 160;
  228. TK_ALT = 161;
  229. TK_PAUSE = 162;
  230. TK_CAPSLOCK = 163;
  231. TK_ESCAPE = 164;
  232. TK_SPACE = 165;
  233. TK_PAGEUP = 166;
  234. TK_PAGEDN = 167;
  235. TK_END = 168;
  236. TK_HOME = 169;
  237. TK_LEFT = 170;
  238. TK_UP = 171;
  239. TK_RIGHT = 172;
  240. TK_DOWN = 173;
  241. TK_INSERT = 174;
  242. TK_DELETE = 175;
  243. TK_LWIN = 176;
  244. TK_RWIN = 177;
  245. TK_NUMLOCK = 178;
  246. TK_SCROLL = 179;
  247. TK_LSHIFT = 180;
  248. TK_RSHIFT = 181;
  249. TK_LCONTROL = 182;
  250. TK_RCONTROL = 183;
  251. TK_LALT = 184;
  252. TK_RALT = 185;
  253. TK_SEMICOLON = 186;
  254. TK_EQUALS = 187;
  255. TK_COMMA = 188;
  256. TK_MINUS = 189;
  257. TK_DOT = 190;
  258. TK_SLASH = 191;
  259. TK_BACKTICK = 192;
  260. TK_LSQUARE = 193;
  261. TK_BACKSLASH = 194;
  262. TK_RSQUARE = 195;
  263. TK_TICK = 196;
  264. (* Returns mouse input for a window.
  265. The value set to "buttons" is a bit set where bits 0, 1 and 2
  266. corresponds to the left, right and middle buttons.
  267. A set bit indicates that a button is held. *)
  268. PROCEDURE tigrMouse(bmp: TigrPtr; VAR x,y,buttons: CARDINAL);
  269. TYPE
  270. TigrTouchPoint = RECORD
  271. x,y : INTEGER;
  272. END;
  273. TigrTouchPointPtr = POINTER TO TigrTouchPoint;
  274. (* Reads touch input for a window.
  275. Returns number of touch points read. *)
  276. PROCEDURE tigrTouch(bmp: TigrPtr; points: TigrTouchPointPtr; maxPoints: CARDINAL): INTEGER;
  277. (* Reads the delta of the scroll "wheel" in somewhat platform neutral
  278. units where 1.0 corresponds to a "notch". The actual correlation between
  279. physical movement and this number varies between platforms, input methods
  280. and settings. *)
  281. PROCEDURE tigrScrollWheel(bmp: TigrPtr; x, y: shortRealPtr);
  282. (* Reads the keyboard for a window.
  283. Returns non-zero if a key is pressed/held.
  284. tigrKeyDown tests for the initial press, tigrKeyHeld repeats each frame. *)
  285. PROCEDURE tigrKeyDown(bmp: TigrPtr; key: CARDINAL): CARDINAL;
  286. PROCEDURE tigrKeyHeld(bmp: TigrPtr; key: CARDINAL): CARDINAL;
  287. (* Reads character input for a window.
  288. Returns the Unicode value of the last key pressed, or 0 if none. *)
  289. PROCEDURE tigrReadChar(bmp: TigrPtr): CARDINAL;
  290. (* Show / hide virtual keyboard.
  291. (Only available on iOS / Android) *)
  292. PROCEDURE tigrShowKeyboard(show: CARDINAL);
  293. (* Bitmap I/O ------------------------------------------------------------- *)
  294. (* Loads a PNG, from either a file or memory. (fileName is UTF-8)
  295. On error, returns NULL and sets errno. *)
  296. PROCEDURE tigrLoadImage(fileName: ARRAY OF CHAR): TigrPtr;
  297. PROCEDURE tigrLoadImageMem(data: ADDRESS; length: CARDINAL): TigrPtr;
  298. (* Saves a PNG to a file. (fileName is UTF-8)
  299. On error, returns zero and sets errno. *)
  300. PROCEDURE tigrSaveImage(fileName: ARRAY OF CHAR; bmp: TigrPtr): INTEGER;
  301. (* Helpers ---------------------------------------------------------------- *)
  302. (* Returns the amount of time elapsed since tigrTime was last called,
  303. or zero on the first call. *)
  304. PROCEDURE tigrTime(): SHORTREAL;
  305. (* Displays an error message and quits. (UTF-8)
  306. 'bmp' can be NULL. *)
  307. PROCEDURE tigrError(bmp: TigrPtr; message: ARRAY OF CHAR; ...);
  308. (* Reads an entire file into memory. (fileName is UTF-8)
  309. Free it yourself after with 'free'.
  310. On error, returns NULL and sets errno.
  311. TIGR will automatically append a NUL terminator byte
  312. to the end (not included in the length) *)
  313. PROCEDURE tigrReadFile(fileName: ARRAY OF CHAR; length: intPtr): String;
  314. (* Decompresses DEFLATEd zip/zlib data into a buffer.
  315. Returns non-zero on success. *)
  316. PROCEDURE tigrInflate(out: ADDRESS; outlen: CARDINAL; in: ADDRESS; inlen: CARDINAL);
  317. (* Decodes a single UTF8 codepoint and returns the next pointer. *)
  318. PROCEDURE tigrDecodeUTF8(text: String; cp: intPtr): String;
  319. (* Encodes a single UTF8 codepoint and returns the next pointer. *)
  320. PROCEDURE tigrEncodeUTF8(text: String; cp: INTEGER): String;
  321. END tigr.