microui-demo.mod 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. MODULE microuiDemo;
  2. (* A demonstration of the Modula-2 microui port rendered with tigr.
  3. The UI is modelled on microui's C SDL demo but everything is drawn with
  4. the tigr software renderer and its built-in font.
  5. Build (from this directory), after tigr.o, helper.o, microuiHelpers.o and
  6. microui.o have been built in modula2/:
  7. gm2 -fiso -I ../../ ../../tigr.o ../../helper.o \
  8. ../../microuiHelpers.o ../../microui.o \
  9. microui-demo.mod -o microui-demo -lGL -lX11
  10. *)
  11. FROM SYSTEM IMPORT ADDRESS, ADR, CAST, ADDADR, BYTE;
  12. FROM tigr IMPORT TigrPtr, tigrWindow, tigrFree, tigrClosed, tigrClear,
  13. tigrUpdate, TPixelType, tfont, tigrPrint, tigrFillRect,
  14. tigrRect, tigrLine, tigrTextWidth, tigrTextHeight, tigrMouse,
  15. tigrKeyDown, tigrKeyHeld, tigrReadChar, tigrTime,
  16. tigrEncodeUTF8, tigrClip, tigrError,
  17. TK_ESCAPE, TK_LSHIFT, TK_RSHIFT, TK_LCONTROL, TK_RCONTROL,
  18. TK_LALT, TK_RALT, TK_RETURN, TK_BACKSPACE, TIGR_AUTO;
  19. FROM helper IMPORT tigrRGB, tigrRGBA;
  20. FROM microuiHelpers IMPORT BITAND, IntToStr, HexByte;
  21. IMPORT microui;
  22. TYPE
  23. CharArrayPtr = POINTER TO ARRAY [0..0] OF CHAR;
  24. TextCommandPtr = POINTER TO microui.TextCommand;
  25. RectCommandPtr = POINTER TO microui.RectCommand;
  26. IconCommandPtr = POINTER TO microui.IconCommand;
  27. ClipCommandPtr = POINTER TO microui.ClipCommand;
  28. CONST
  29. WIN_W = 800;
  30. WIN_H = 600;
  31. VAR
  32. ctx : microui.Context; (* big: kept at module scope, not on stack *)
  33. ctxPtr : microui.ContextPtr;
  34. bmp : TigrPtr;
  35. bg : ARRAY [0..2] OF SHORTREAL;
  36. logbuf : ARRAY [0..8191] OF CHAR;
  37. logbufUpd : BOOLEAN;
  38. inputBuf : ARRAY [0..127] OF CHAR;
  39. checks : ARRAY [0..2] OF INTEGER;
  40. lastLeft, lastRight, lastMiddle : BOOLEAN;
  41. prevShift, prevCtrl, prevAlt, prevReturn, prevBack : BOOLEAN;
  42. dummyF : SHORTREAL;
  43. (*========================================================================*)
  44. (* Small helpers *)
  45. (*========================================================================*)
  46. PROCEDURE Len(s : ARRAY OF CHAR) : INTEGER;
  47. VAR n : INTEGER;
  48. BEGIN
  49. n := 0;
  50. WHILE (n <= VAL(INTEGER, HIGH(s))) AND (s[n] # 0C) DO n := n + 1 END;
  51. RETURN n
  52. END Len;
  53. PROCEDURE HasBit(v, bit : CARDINAL) : BOOLEAN;
  54. BEGIN
  55. RETURN BITAND(v, bit) # 0
  56. END HasBit;
  57. PROCEDURE ClampByte(v : SHORTREAL) : BYTE;
  58. VAR i : INTEGER;
  59. BEGIN
  60. i := TRUNC(v);
  61. IF i < 0 THEN i := 0 END;
  62. IF i > 255 THEN i := 255 END;
  63. RETURN VAL(BYTE, i)
  64. END ClampByte;
  65. PROCEDURE Pix(c : microui.Color) : TPixelType;
  66. VAR p : TPixelType;
  67. BEGIN
  68. p.r := c.r; p.g := c.g; p.b := c.b; p.a := c.a;
  69. RETURN p
  70. END Pix;
  71. PROCEDURE MaxI(a, b : INTEGER) : INTEGER;
  72. BEGIN IF a > b THEN RETURN a ELSE RETURN b END END MaxI;
  73. PROCEDURE MinI(a, b : INTEGER) : INTEGER;
  74. BEGIN IF a < b THEN RETURN a ELSE RETURN b END END MinI;
  75. (*========================================================================*)
  76. (* microui callbacks *)
  77. (*========================================================================*)
  78. PROCEDURE TextWidthCB(VAR a : microui.TextWidthArgs) : INTEGER;
  79. VAR src : CharArrayPtr;
  80. tmp : ARRAY [0..511] OF CHAR;
  81. n, i : INTEGER;
  82. BEGIN
  83. src := CAST(CharArrayPtr, a.str);
  84. IF a.len < 0 THEN
  85. n := 0;
  86. WHILE (src^[n] # 0C) AND (n < 511) DO
  87. tmp[n] := src^[n];
  88. n := n + 1
  89. END
  90. ELSE
  91. n := a.len;
  92. IF n > 511 THEN n := 511 END;
  93. FOR i := 0 TO n - 1 DO tmp[i] := src^[i] END
  94. END;
  95. tmp[n] := 0C;
  96. RETURN tigrTextWidth(tfont, tmp)
  97. END TextWidthCB;
  98. PROCEDURE TextHeightCB(VAR a : microui.TextHeightArgs) : INTEGER;
  99. BEGIN
  100. RETURN tigrTextHeight(tfont, "")
  101. END TextHeightCB;
  102. (*========================================================================*)
  103. (* tigr rendering of microui commands *)
  104. (*========================================================================*)
  105. PROCEDURE FillRectI(x, y, w, h : INTEGER; c : microui.Color);
  106. VAR x0, y0, x1, y1, bw, bh : INTEGER;
  107. BEGIN
  108. bw := VAL(INTEGER, bmp^.w);
  109. bh := VAL(INTEGER, bmp^.h);
  110. x0 := MaxI(x, 0);
  111. y0 := MaxI(y, 0);
  112. x1 := MinI(x + w, bw);
  113. y1 := MinI(y + h, bh);
  114. IF (x1 > x0) AND (y1 > y0) THEN
  115. (* tigrFillRect only fills the *interior* of a rect (it does
  116. x+1, y+1, w-2, h-2), so pair it with tigrRect to fill the whole
  117. rectangle - and to keep 1px-high/wide rects (microui borders). *)
  118. tigrRect(bmp, VAL(CARDINAL, x0), VAL(CARDINAL, y0),
  119. VAL(CARDINAL, x1 - x0), VAL(CARDINAL, y1 - y0), Pix(c));
  120. tigrFillRect(bmp, VAL(CARDINAL, x0), VAL(CARDINAL, y0),
  121. VAL(CARDINAL, x1 - x0), VAL(CARDINAL, y1 - y0), Pix(c))
  122. END
  123. END FillRectI;
  124. PROCEDURE SetClipI(r : microui.Rect);
  125. VAR x0, y0, x1, y1, bw, bh : INTEGER;
  126. BEGIN
  127. bw := VAL(INTEGER, bmp^.w);
  128. bh := VAL(INTEGER, bmp^.h);
  129. x0 := MaxI(r.x, 0);
  130. y0 := MaxI(r.y, 0);
  131. x1 := MinI(r.x + r.w, bw);
  132. y1 := MinI(r.y + r.h, bh);
  133. IF (x1 <= x0) OR (y1 <= y0) THEN
  134. (* empty clip: use a 1x1 off-screen rect at the top-left *)
  135. tigrClip(bmp, 0, 0, 0, 0)
  136. ELSE
  137. tigrClip(bmp, VAL(CARDINAL, x0), VAL(CARDINAL, y0),
  138. VAL(CARDINAL, x1 - x0), VAL(CARDINAL, y1 - y0))
  139. END
  140. END SetClipI;
  141. PROCEDURE DrawTextCmd(tc : TextCommandPtr);
  142. VAR src : CharArrayPtr;
  143. x, y : INTEGER;
  144. BEGIN
  145. src := CAST(CharArrayPtr,
  146. ADDADR(CAST(ADDRESS, tc), SIZE(microui.TextCommand)));
  147. x := tc^.pos.x;
  148. y := tc^.pos.y;
  149. IF x < 0 THEN x := 0 END;
  150. IF y < 0 THEN y := 0 END;
  151. tigrPrint(bmp, tfont, VAL(CARDINAL, x), VAL(CARDINAL, y),
  152. Pix(tc^.color), src^)
  153. END DrawTextCmd;
  154. PROCEDURE DrawIconCmd(ic : IconCommandPtr);
  155. VAR r : microui.Rect; p : TPixelType;
  156. x0, y0, x1, y1 : CARDINAL;
  157. BEGIN
  158. r := ic^.rect;
  159. p := Pix(ic^.color);
  160. x0 := VAL(CARDINAL, MaxI(r.x, 0));
  161. y0 := VAL(CARDINAL, MaxI(r.y, 0));
  162. x1 := VAL(CARDINAL, MaxI(r.x + r.w - 1, 0));
  163. y1 := VAL(CARDINAL, MaxI(r.y + r.h - 1, 0));
  164. IF ic^.id = microui.ICON_CLOSE THEN
  165. tigrLine(bmp, x0 + 2, y0 + 2, x1 - 2, y1 - 2, p);
  166. tigrLine(bmp, x1 - 2, y0 + 2, x0 + 2, y1 - 2, p)
  167. ELSIF ic^.id = microui.ICON_CHECK THEN
  168. tigrLine(bmp, x0 + 2, y0 + (y1 - y0) DIV 2, x0 + 4, y1 - 3, p);
  169. tigrLine(bmp, x0 + 4, y1 - 3, x1 - 2, y0 + 3, p)
  170. ELSIF ic^.id = microui.ICON_COLLAPSED THEN
  171. tigrLine(bmp, x0 + 2, (y0 + y1) DIV 2, x1 - 2, (y0 + y1) DIV 2, p);
  172. tigrLine(bmp, (x0 + x1) DIV 2, y0 + 2, (x0 + x1) DIV 2, y1 - 2, p)
  173. ELSIF ic^.id = microui.ICON_EXPANDED THEN
  174. tigrLine(bmp, x0 + 2, (y0 + y1) DIV 2, x1 - 2, (y0 + y1) DIV 2, p)
  175. END
  176. END DrawIconCmd;
  177. PROCEDURE Render;
  178. VAR cmd : microui.CommandPtr;
  179. tcp : TextCommandPtr;
  180. rcp : RectCommandPtr;
  181. icp : IconCommandPtr;
  182. ccp : ClipCommandPtr;
  183. BEGIN
  184. tigrClip(bmp, 0, 0, bmp^.w, bmp^.h);
  185. tigrClear(bmp, tigrRGBA(ClampByte(bg[0]), ClampByte(bg[1]),
  186. ClampByte(bg[2]), VAL(BYTE, 255)));
  187. cmd := NIL;
  188. WHILE microui.nextCommand(ctxPtr, cmd) # 0 DO
  189. IF cmd^.type = microui.COMMAND_RECT THEN
  190. rcp := CAST(RectCommandPtr, cmd);
  191. FillRectI(rcp^.rect.x, rcp^.rect.y, rcp^.rect.w, rcp^.rect.h,
  192. rcp^.color)
  193. ELSIF cmd^.type = microui.COMMAND_TEXT THEN
  194. tcp := CAST(TextCommandPtr, cmd);
  195. DrawTextCmd(tcp)
  196. ELSIF cmd^.type = microui.COMMAND_ICON THEN
  197. icp := CAST(IconCommandPtr, cmd);
  198. DrawIconCmd(icp)
  199. ELSIF cmd^.type = microui.COMMAND_CLIP THEN
  200. ccp := CAST(ClipCommandPtr, cmd);
  201. SetClipI(ccp^.rect)
  202. END
  203. END;
  204. tigrClip(bmp, 0, 0, bmp^.w, bmp^.h)
  205. END Render;
  206. (*========================================================================*)
  207. (* Input *)
  208. (*========================================================================*)
  209. PROCEDURE FeedKey(key : CARDINAL; flag : INTEGER; VAR prev : BOOLEAN);
  210. VAR held : BOOLEAN;
  211. BEGIN
  212. held := tigrKeyHeld(bmp, key) # 0;
  213. IF held AND (NOT prev) THEN microui.inputKeydown(ctxPtr, flag) END;
  214. IF (NOT held) AND prev THEN microui.inputKeyup(ctxPtr, flag) END;
  215. prev := held
  216. END FeedKey;
  217. PROCEDURE FeedText;
  218. VAR c : CARDINAL;
  219. buf : ARRAY [0..7] OF CHAR;
  220. discard : ADDRESS;
  221. i : INTEGER;
  222. BEGIN
  223. LOOP
  224. c := tigrReadChar(bmp);
  225. IF c = 0 THEN EXIT END;
  226. FOR i := 0 TO 7 DO buf[i] := 0C END;
  227. discard := tigrEncodeUTF8(ADR(buf), VAL(INTEGER, c));
  228. microui.inputText(ctxPtr, buf)
  229. END
  230. END FeedText;
  231. PROCEDURE FeedInput;
  232. VAR mx, my, buttons : CARDINAL;
  233. x, y : INTEGER;
  234. left, right, middle : BOOLEAN;
  235. BEGIN
  236. tigrMouse(bmp, mx, my, buttons);
  237. x := VAL(INTEGER, mx);
  238. y := VAL(INTEGER, my);
  239. microui.inputMousemove(ctxPtr, x, y);
  240. left := HasBit(buttons, VAL(CARDINAL, microui.MOUSE_LEFT));
  241. right := HasBit(buttons, VAL(CARDINAL, microui.MOUSE_RIGHT));
  242. middle := HasBit(buttons, VAL(CARDINAL, microui.MOUSE_MIDDLE));
  243. IF left AND (NOT lastLeft) THEN
  244. microui.inputMousedown(ctxPtr, x, y, microui.MOUSE_LEFT)
  245. ELSIF (NOT left) AND lastLeft THEN
  246. microui.inputMouseup(ctxPtr, x, y, microui.MOUSE_LEFT)
  247. END;
  248. IF right AND (NOT lastRight) THEN
  249. microui.inputMousedown(ctxPtr, x, y, microui.MOUSE_RIGHT)
  250. ELSIF (NOT right) AND lastRight THEN
  251. microui.inputMouseup(ctxPtr, x, y, microui.MOUSE_RIGHT)
  252. END;
  253. IF middle AND (NOT lastMiddle) THEN
  254. microui.inputMousedown(ctxPtr, x, y, microui.MOUSE_MIDDLE)
  255. ELSIF (NOT middle) AND lastMiddle THEN
  256. microui.inputMouseup(ctxPtr, x, y, microui.MOUSE_MIDDLE)
  257. END;
  258. lastLeft := left; lastRight := right; lastMiddle := middle;
  259. FeedKey(TK_LSHIFT, microui.KEY_SHIFT, prevShift);
  260. FeedKey(TK_RSHIFT, microui.KEY_SHIFT, prevShift);
  261. FeedKey(TK_LCONTROL, microui.KEY_CTRL, prevCtrl);
  262. FeedKey(TK_RCONTROL, microui.KEY_CTRL, prevCtrl);
  263. FeedKey(TK_LALT, microui.KEY_ALT, prevAlt);
  264. FeedKey(TK_RALT, microui.KEY_ALT, prevAlt);
  265. FeedKey(TK_RETURN, microui.KEY_RETURN, prevReturn);
  266. FeedKey(TK_BACKSPACE, microui.KEY_BACKSPACE, prevBack);
  267. FeedText
  268. END FeedInput;
  269. (*========================================================================*)
  270. (* Log helpers *)
  271. (*========================================================================*)
  272. PROCEDURE WriteLog(s : ARRAY OF CHAR);
  273. VAR i, n, l : INTEGER;
  274. BEGIN
  275. l := Len(logbuf);
  276. IF l > 0 THEN
  277. logbuf[l] := CHR(10);
  278. l := l + 1
  279. END;
  280. n := Len(s);
  281. i := 0;
  282. WHILE (i < n) AND (l < VAL(INTEGER, HIGH(logbuf))) DO
  283. logbuf[l] := s[i];
  284. l := l + 1;
  285. i := i + 1
  286. END;
  287. logbuf[l] := 0C;
  288. logbufUpd := TRUE
  289. END WriteLog;
  290. PROCEDURE FmtPair(VAR buf : ARRAY OF CHAR; a, b : INTEGER);
  291. VAR s : ARRAY [0..31] OF CHAR;
  292. n, i, p : INTEGER;
  293. BEGIN
  294. p := IntToStr(buf, a);
  295. buf[p] := ','; p := p + 1;
  296. buf[p] := ' '; p := p + 1;
  297. n := IntToStr(s, b);
  298. FOR i := 0 TO n - 1 DO
  299. buf[p] := s[i];
  300. p := p + 1
  301. END;
  302. buf[p] := 0C
  303. END FmtPair;
  304. PROCEDURE FmtHex(VAR buf : ARRAY OF CHAR; r, g, b : CARDINAL);
  305. VAR s : ARRAY [0..3] OF CHAR;
  306. n : CARDINAL;
  307. BEGIN
  308. buf[0] := '#'; buf[1] := 0C;
  309. n := HexByte(s, r);
  310. buf[1] := s[0]; buf[2] := s[1]; buf[3] := 0C;
  311. n := HexByte(s, g);
  312. buf[3] := s[0]; buf[4] := s[1]; buf[5] := 0C;
  313. n := HexByte(s, b);
  314. buf[5] := s[0]; buf[6] := s[1]; buf[7] := 0C
  315. END FmtHex;
  316. (*========================================================================*)
  317. (* Demo windows *)
  318. (*========================================================================*)
  319. PROCEDURE TestWindow;
  320. VAR win : microui.ContainerPtr;
  321. widths : ARRAY [0..3] OF INTEGER;
  322. buf : ARRAY [0..63] OF CHAR;
  323. hex : ARRAY [0..15] OF CHAR;
  324. preview : microui.Rect;
  325. res : INTEGER;
  326. cptr : microui.IntPtr;
  327. BEGIN
  328. IF microui.beginWindow(ctxPtr, "Demo Window",
  329. microui.rect(40, 40, 340, 480)) # 0 THEN
  330. win := microui.getCurrentContainer(ctxPtr);
  331. IF win^.rect.w < 240 THEN win^.rect.w := 240 END;
  332. IF win^.rect.h < 300 THEN win^.rect.h := 300 END;
  333. (* --- Window Info ------------------------------------------------ *)
  334. IF microui.header(ctxPtr, "Window Info") # 0 THEN
  335. win := microui.getCurrentContainer(ctxPtr);
  336. widths[0] := 64; widths[1] := -1;
  337. microui.layoutRow(ctxPtr, 2, ADR(widths), 0);
  338. microui.label(ctxPtr, "Position:");
  339. FmtPair(buf, win^.rect.x, win^.rect.y);
  340. microui.label(ctxPtr, buf);
  341. microui.label(ctxPtr, "Size:");
  342. FmtPair(buf, win^.rect.w, win^.rect.h);
  343. microui.label(ctxPtr, buf)
  344. END;
  345. (* --- Buttons + popup -------------------------------------------- *)
  346. IF microui.headerEx(ctxPtr, "Test Buttons", microui.OPT_EXPANDED) # 0 THEN
  347. widths[0] := 86; widths[1] := -110; widths[2] := -1;
  348. microui.layoutRow(ctxPtr, 3, ADR(widths), 0);
  349. microui.label(ctxPtr, "Test buttons 1:");
  350. IF microui.button(ctxPtr, "Button 1") # 0 THEN
  351. WriteLog("Pressed button 1")
  352. END;
  353. IF microui.button(ctxPtr, "Button 2") # 0 THEN
  354. WriteLog("Pressed button 2")
  355. END;
  356. microui.label(ctxPtr, "Test buttons 2:");
  357. IF microui.button(ctxPtr, "Button 3") # 0 THEN
  358. WriteLog("Pressed button 3")
  359. END;
  360. IF microui.button(ctxPtr, "Popup") # 0 THEN
  361. microui.openPopup(ctxPtr, "Test Popup")
  362. END;
  363. IF microui.beginPopup(ctxPtr, "Test Popup") # 0 THEN
  364. IF microui.button(ctxPtr, "Hello") # 0 THEN
  365. WriteLog("Pressed Hello")
  366. END;
  367. IF microui.button(ctxPtr, "World") # 0 THEN
  368. WriteLog("Pressed World")
  369. END;
  370. microui.endPopup(ctxPtr)
  371. END
  372. END;
  373. (* --- Tree + text ------------------------------------------------- *)
  374. IF microui.headerEx(ctxPtr, "Tree and Text", microui.OPT_EXPANDED) # 0 THEN
  375. widths[0] := 150; widths[1] := -1;
  376. microui.layoutRow(ctxPtr, 2, ADR(widths), 0);
  377. microui.layoutBeginColumn(ctxPtr);
  378. IF microui.beginTreenode(ctxPtr, "Test 1") # 0 THEN
  379. IF microui.beginTreenode(ctxPtr, "Test 1a") # 0 THEN
  380. microui.label(ctxPtr, "Hello");
  381. microui.label(ctxPtr, "world");
  382. microui.endTreenode(ctxPtr)
  383. END;
  384. IF microui.beginTreenode(ctxPtr, "Test 1b") # 0 THEN
  385. IF microui.button(ctxPtr, "Button 1") # 0 THEN
  386. WriteLog("Pressed button 1")
  387. END;
  388. IF microui.button(ctxPtr, "Button 2") # 0 THEN
  389. WriteLog("Pressed button 2")
  390. END;
  391. microui.endTreenode(ctxPtr)
  392. END;
  393. microui.endTreenode(ctxPtr)
  394. END;
  395. IF microui.beginTreenode(ctxPtr, "Test 2") # 0 THEN
  396. widths[0] := 54; widths[1] := 54;
  397. microui.layoutRow(ctxPtr, 2, ADR(widths), 0);
  398. IF microui.button(ctxPtr, "Button 3") # 0 THEN
  399. WriteLog("Pressed button 3")
  400. END;
  401. IF microui.button(ctxPtr, "Button 4") # 0 THEN
  402. WriteLog("Pressed button 4")
  403. END;
  404. IF microui.button(ctxPtr, "Button 5") # 0 THEN
  405. WriteLog("Pressed button 5")
  406. END;
  407. IF microui.button(ctxPtr, "Button 6") # 0 THEN
  408. WriteLog("Pressed button 6")
  409. END;
  410. microui.endTreenode(ctxPtr)
  411. END;
  412. IF microui.beginTreenode(ctxPtr, "Test 3") # 0 THEN
  413. cptr := CAST(microui.IntPtr, ADR(checks[0]));
  414. res := microui.checkbox(ctxPtr, "Checkbox 1", cptr);
  415. cptr := CAST(microui.IntPtr, ADR(checks[1]));
  416. res := microui.checkbox(ctxPtr, "Checkbox 2", cptr);
  417. cptr := CAST(microui.IntPtr, ADR(checks[2]));
  418. res := microui.checkbox(ctxPtr, "Checkbox 3", cptr);
  419. microui.endTreenode(ctxPtr)
  420. END;
  421. microui.layoutEndColumn(ctxPtr);
  422. microui.layoutBeginColumn(ctxPtr);
  423. widths[0] := -1;
  424. microui.layoutRow(ctxPtr, 1, ADR(widths), 0);
  425. microui.text(ctxPtr, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas lacinia, sem eu lacinia molestie, mi risus faucibus ipsum, eu varius magna felis a nulla.");
  426. microui.layoutEndColumn(ctxPtr)
  427. END;
  428. (* --- Background color -------------------------------------------- *)
  429. IF microui.headerEx(ctxPtr, "Background Color", microui.OPT_EXPANDED) # 0 THEN
  430. widths[0] := -78; widths[1] := -1;
  431. microui.layoutRow(ctxPtr, 2, ADR(widths), 74);
  432. microui.layoutBeginColumn(ctxPtr);
  433. widths[0] := 46; widths[1] := -1;
  434. microui.layoutRow(ctxPtr, 2, ADR(widths), 0);
  435. microui.label(ctxPtr, "Red:");
  436. res := microui.slider(ctxPtr, CAST(microui.RealPtr, ADR(bg[0])),
  437. 0.0, 255.0);
  438. microui.label(ctxPtr, "Green:");
  439. res := microui.slider(ctxPtr, CAST(microui.RealPtr, ADR(bg[1])),
  440. 0.0, 255.0);
  441. microui.label(ctxPtr, "Blue:");
  442. res := microui.slider(ctxPtr, CAST(microui.RealPtr, ADR(bg[2])),
  443. 0.0, 255.0);
  444. microui.layoutEndColumn(ctxPtr);
  445. win := microui.getCurrentContainer(ctxPtr);
  446. preview := microui.layoutNext(ctxPtr);
  447. microui.drawRect(ctxPtr, preview,
  448. microui.color(TRUNC(bg[0]), TRUNC(bg[1]),
  449. TRUNC(bg[2]), 255));
  450. FmtHex(hex, VAL(CARDINAL, TRUNC(bg[0])),
  451. VAL(CARDINAL, TRUNC(bg[1])), VAL(CARDINAL, TRUNC(bg[2])));
  452. microui.drawControlText(ctxPtr, hex, preview, microui.COLOR_TEXT, microui.OPT_ALIGNCENTER)
  453. END;
  454. microui.endWindow(ctxPtr)
  455. END
  456. END TestWindow;
  457. PROCEDURE LogWindow;
  458. VAR widths : ARRAY [0..2] OF INTEGER;
  459. panel : microui.ContainerPtr;
  460. submitted : BOOLEAN;
  461. res : INTEGER;
  462. BEGIN
  463. IF microui.beginWindow(ctxPtr, "Log Window",
  464. microui.rect(400, 40, 360, 240)) # 0 THEN
  465. widths[0] := -1;
  466. microui.layoutRow(ctxPtr, 1, ADR(widths), -25);
  467. microui.beginPanel(ctxPtr, "Log Output");
  468. panel := microui.getCurrentContainer(ctxPtr);
  469. widths[0] := -1;
  470. microui.layoutRow(ctxPtr, 1, ADR(widths), -1);
  471. microui.text(ctxPtr, logbuf);
  472. microui.endPanel(ctxPtr);
  473. IF logbufUpd THEN
  474. panel^.scroll.y := panel^.contentSize.y;
  475. logbufUpd := FALSE
  476. END;
  477. widths[0] := -70; widths[1] := -1;
  478. microui.layoutRow(ctxPtr, 2, ADR(widths), 0);
  479. submitted := FALSE;
  480. res := microui.textbox(ctxPtr, ADR(inputBuf), SIZE(inputBuf));
  481. IF BITAND(VAL(CARDINAL, res), VAL(CARDINAL, microui.RES_SUBMIT)) # 0 THEN
  482. microui.setFocus(ctxPtr, ctxPtr^.lastId);
  483. submitted := TRUE
  484. END;
  485. IF microui.button(ctxPtr, "Submit") # 0 THEN
  486. submitted := TRUE
  487. END;
  488. IF submitted THEN
  489. WriteLog(inputBuf);
  490. inputBuf[0] := 0C
  491. END;
  492. microui.endWindow(ctxPtr)
  493. END
  494. END LogWindow;
  495. (*========================================================================*)
  496. (* Main *)
  497. (*========================================================================*)
  498. BEGIN
  499. bmp := tigrWindow(WIN_W, WIN_H, "microui + tigr (Modula-2)", TIGR_AUTO);
  500. IF bmp = NIL THEN
  501. tigrError(NIL, "Cannot create window")
  502. END;
  503. ctxPtr := CAST(microui.ContextPtr, ADR(ctx));
  504. microui.init(ctxPtr);
  505. ctxPtr^.textWidth := TextWidthCB;
  506. ctxPtr^.textHeight := TextHeightCB;
  507. ctxPtr^.style^.font := CAST(ADDRESS, tfont);
  508. bg[0] := 90.0; bg[1] := 95.0; bg[2] := 100.0;
  509. logbuf[0] := 0C;
  510. inputBuf[0] := 0C;
  511. checks[0] := 1; checks[1] := 0; checks[2] := 1;
  512. lastLeft := FALSE; lastRight := FALSE; lastMiddle := FALSE;
  513. prevShift := FALSE; prevCtrl := FALSE; prevAlt := FALSE;
  514. prevReturn := FALSE; prevBack := FALSE;
  515. WriteLog("microui port running");
  516. WHILE (tigrClosed(bmp) = 0) AND (tigrKeyDown(bmp, TK_ESCAPE) = 0) DO
  517. dummyF := tigrTime();
  518. FeedInput;
  519. microui.begin(ctxPtr);
  520. LogWindow;
  521. TestWindow;
  522. microui.end(ctxPtr);
  523. Render;
  524. tigrUpdate(bmp)
  525. END;
  526. tigrFree(bmp)
  527. END microuiDemo.