tigr.def 14 KB

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