COLORPAL.MOD 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. (******************************************************************************)
  2. (* COLORPAL.MOD *)
  3. (* *)
  4. (* MetaWINDOW HOWTO: program series. Demonstrates usage of Read / Write / *)
  5. (* LoadPalette. *)
  6. (* Transcribed from COLORPAL.C METAGRAPHICS SOFTWARE CORPORATION (c) 1987-1989*)
  7. (* *)
  8. (* PSW 06/28/91 08:30am *)
  9. (******************************************************************************)
  10. MODULE ColorPal;
  11. (*
  12. * Graphix
  13. * Release 3.7
  14. * (c) Copyright 1986-1992 PMI
  15. * Green Bay, Wisconsin
  16. * (414) 468-6040
  17. * All rights reserved
  18. *
  19. *)
  20. IMPORT GrConst;
  21. IMPORT GrPorts;
  22. IMPORT GrFonts;
  23. IMPORT Meta;
  24. IMPORT GrQry;
  25. IMPORT IO;
  26. IMPORT Str;
  27. IMPORT Lib;
  28. FROM GrConst IMPORT rect, point, event, palData;
  29. FROM GrPorts IMPORT adsPort;
  30. FROM GrFonts IMPORT adsFont;
  31. FROM Storage IMPORT ALLOCATE, DEALLOCATE;
  32. CONST
  33. MOUSE_RIGHT = 0100H;
  34. MOUSE_LEFT = 0400H;
  35. EGAADJUST = 4000H;
  36. VAR
  37. GrafixCard,
  38. CommPort: INTEGER;
  39. control: ARRAY [0..3] OF LONGINT;
  40. paltype: INTEGER;
  41. palColors: ARRAY[0..1] OF palData;
  42. max_colors,
  43. colors: INTEGER;
  44. OK: BOOLEAN;
  45. i,
  46. selPalEntry,
  47. curs, buttons,
  48. x, y, speed: INTEGER;
  49. scrnR: rect;
  50. myevent: event;
  51. cursor_pt: point;
  52. thePort: adsPort; (* pointer to default MetaWINDOW port *)
  53. buf, fntpath: ARRAY [0..25] OF CHAR;
  54. val: ARRAY[0..10] OF CHAR;
  55. fontbuf: adsFont;
  56. (* default EGA style palette *)
  57. palette: ARRAY [0..15] OF WORD;
  58. (*** Draw a screen full of boxes, one for each color combination. ***)
  59. PROCEDURE draw_palette();
  60. VAR
  61. color: INTEGER;
  62. r: rect;
  63. BEGIN
  64. Meta.MoveTo(0, 0);
  65. IF max_colors > 16 THEN
  66. Meta.SetRect(r, 0, 0, 30, 40);
  67. FOR color := 0 TO max_colors DO
  68. Meta.PenColor(color);
  69. Meta.PaintRect(r);
  70. Meta.PenColor(GrConst.White);
  71. Meta.FrameRect(r);
  72. Meta.OffsetRect(r, 40, 0);
  73. IF r.Xmax > 640 THEN
  74. r.Xmin := 0;
  75. r.Xmax := 30;
  76. Meta.OffsetRect(r, 0, 50);
  77. END;
  78. END;
  79. ELSE
  80. Meta.SetRect(r, 0, 0, 100, 100);
  81. FOR color := 0 TO max_colors DO
  82. Meta.PenColor(color);
  83. Meta.PaintRect(r);
  84. Meta.PenColor(GrConst.White);
  85. Meta.FrameRect(r);
  86. Meta.MoveTo(r.Xmin + 49, r.Ymax + 35);
  87. Str.IntToStr(LONGINT(color), val, 10, OK);
  88. Meta.DrawString(val);
  89. Meta.OffsetRect(r, 150, 0);
  90. IF r.Xmax > 599 THEN
  91. r.Xmin := 0;
  92. r.Xmax := 100;
  93. Meta.OffsetRect(r, 0, 200);
  94. END
  95. END
  96. END
  97. END draw_palette;
  98. (*** Check to see if thepoint is in one of the palette display boxes. ***)
  99. (*** Returns the palette entry corresponding to that box, or -1 if not ***)
  100. (*** in any box ***)
  101. PROCEDURE check_palette(VAR thepoint: point): INTEGER;
  102. VAR
  103. color: INTEGER;
  104. r: rect;
  105. BEGIN
  106. Meta.MoveTo(0, 0);
  107. IF max_colors > 16 THEN
  108. Meta.SetRect(r, 0, 0, 30, 40);
  109. FOR color := 0 TO max_colors DO
  110. IF Meta.PtInRect(thepoint, r) THEN
  111. RETURN color;
  112. END;
  113. Meta.OffsetRect(r, 40, 0);
  114. IF r.Xmax > 640 THEN
  115. r.Xmin := 0;
  116. r.Xmax := 30;
  117. Meta.OffsetRect(r, 0, 50);
  118. END
  119. END
  120. ELSE
  121. Meta.SetRect(r, 0, 0, 100, 100);
  122. FOR color := 0 TO max_colors DO
  123. IF Meta.PtInRect(thepoint, r) THEN
  124. RETURN color;
  125. END;
  126. Meta.OffsetRect(r, 150, 0);
  127. IF r.Xmax > 599 THEN
  128. r.Xmin := 0;
  129. r.Xmax := 100;
  130. Meta.OffsetRect(r, 0, 200);
  131. END
  132. END
  133. END;
  134. RETURN -1;
  135. END check_palette;
  136. PROCEDURE Insert(VAR S1: ARRAY OF CHAR; S2: ARRAY OF CHAR; Pos, Width: CARDINAL);
  137. VAR
  138. L1, L2, i: CARDINAL;
  139. BEGIN
  140. L1 := HIGH(S1);
  141. L2 := Str.Length(S2);
  142. IF (Pos + Width) > L1 THEN
  143. RETURN
  144. END;
  145. IF L2 > Width THEN
  146. RETURN
  147. END;
  148. FOR i := 0 TO L2 DO
  149. S1[Pos + i] := S2[i];
  150. END;
  151. FOR i := Pos + L2 TO Pos + Width DO
  152. S1[i] := ' ';
  153. END;
  154. END Insert;
  155. (*** Fill the color mixing rectangle with color 'palval'. ***)
  156. PROCEDURE draw_clr_rect(palval: CARDINAL);
  157. VAR
  158. color_rect: rect;
  159. BEGIN
  160. Meta.SetRect(color_rect, 0, 0, 100, 100);
  161. Meta.OffsetRect(color_rect, 725, 100);
  162. Meta.PenColor(palval);
  163. Meta.ProtectRect(color_rect);
  164. Meta.PaintRect(color_rect);
  165. Meta.PenColor(GrConst.White);
  166. Meta.FrameRect(color_rect);
  167. Meta.ProtectOff();
  168. Str.IntToStr(LONGINT(palval), val, 16, OK);
  169. Str.Append(val, ':');
  170. Insert(buf, val, 0, 24);
  171. IF paltype = 1 THEN (* analog palette *)
  172. Str.IntToStr(LONGINT(palColors[0].palRed), val, 16, OK);
  173. Insert(buf, val, 6, 6);
  174. Str.IntToStr(LONGINT(palColors[0].palGreen), val, 16, OK);
  175. Insert(buf, val, 12, 6);
  176. Str.IntToStr(LONGINT(palColors[0].palBlue), val, 16, OK);
  177. Insert(buf, val, 18, 6);
  178. ELSE
  179. Insert(buf, val, 0, 6);
  180. Str.IntToStr(LONGINT(palette[palval]), val, 16, OK);
  181. Insert(buf, val, 6, 6);
  182. END;
  183. buf[24] := CHR(0);
  184. Meta.MoveTo(650, 100 - 40);
  185. Meta.DrawString(buf);
  186. END draw_clr_rect;
  187. PROCEDURE draw_control(num:INTEGER);
  188. VAR
  189. r: rect;
  190. i, x, y: INTEGER;
  191. color: CHAR;
  192. BEGIN
  193. CASE num OF
  194. | 0: x := 670; color := 'R';
  195. | 1: x := 770; color := 'G';
  196. | 2: x := 870; color := 'B';
  197. ELSE
  198. RETURN;
  199. END;
  200. y := 300;
  201. (* draw scale *)
  202. Meta.PenColor(GrConst.White);
  203. Meta.MoveTo(x, y);
  204. Meta.LineRel(0, 500);
  205. Meta.MoveTo(x, y);
  206. Meta.LineTo(x - 20, y);
  207. Meta.MoveTo(x, y + 500);
  208. Meta.LineTo(x - 20, y + 500);
  209. FOR i := y TO y + 500 BY 20 DO
  210. Meta.MoveTo(x, i);
  211. Meta.LineTo(x - 10, i);
  212. END;
  213. (* draw 'R' 'G' or 'B' *)
  214. Meta.MoveTo(x, y - 30);
  215. Meta.DrawChar(color);
  216. (* draw '+/-' control *)
  217. INC(y, 520);
  218. Meta.SetRect(r, x - 30, y, x + 30, y + 50);
  219. Meta.FrameRect(r);
  220. Meta.MoveTo(x, y);
  221. Meta.LineTo(x, y + 50);
  222. Meta.MoveTo(r.Xmin + 5, y + 40);
  223. Meta.DrawChar('+');
  224. Meta.MoveTo(x + 5, y + 40);
  225. Meta.DrawChar('-');
  226. END draw_control;
  227. (*** Draw the control panel ***)
  228. PROCEDURE draw_panel();
  229. BEGIN
  230. Meta.PenColor(GrConst.White);
  231. draw_control(0);
  232. draw_control(1);
  233. draw_control(2);
  234. draw_clr_rect(0);
  235. END draw_panel;
  236. (*** Draw a thermometer type indicator bar for control 'num'. ***)
  237. PROCEDURE draw_indicator(num: CARDINAL);
  238. VAR
  239. x, y, i: CARDINAL;
  240. r: rect;
  241. BEGIN
  242. x := 670 + 100 * num;
  243. y := 300;
  244. (* compute scale factor *)
  245. i := CARDINAL(control[num] DIV 131); (* 0xFFFF / 500 appx := 131 *)
  246. (* fill on part *)
  247. Meta.SetRect(r, x + 1, y + 500 - i, x + 10, y + 500);
  248. Meta.ProtectRect(r);
  249. Meta.PaintRect(r);
  250. Meta.ProtectOff();
  251. (* erase off part *)
  252. Meta.SetRect(r, x + 1, y, x + 10, y + 500 - i);
  253. Meta.ProtectRect(r);
  254. Meta.EraseRect(r);
  255. Meta.ProtectOff();
  256. END draw_indicator;
  257. (*** Check to see if thepoint is in one of the control knobs. Returns knob ***)
  258. (*** number or -1 if not in any knob. ***)
  259. PROCEDURE check_panel(VAR thepoint: point): INTEGER;
  260. VAR
  261. knob, x, y: INTEGER;
  262. r: rect;
  263. BEGIN
  264. y := 300 + 520;
  265. FOR knob := 0 TO 2 DO
  266. x := 670 + 100 * knob;
  267. Meta.SetRect(r, x - 30, y, x + 30, y + 50);
  268. IF (Meta.PtInRect(thepoint, r)) THEN
  269. r.Xmin := (r.Xmax + r.Xmin) DIV 2;
  270. IF Meta.PtInRect(thepoint, r) THEN
  271. RETURN (knob * 2 + 1);
  272. END;
  273. RETURN (knob * 2);
  274. END;
  275. END;
  276. RETURN -1;
  277. END check_panel;
  278. (*** Analog palette version ***)
  279. (*** For color number entry 'palval' change color register entry. ***)
  280. PROCEDURE ANmix_color(palval: CARDINAL);
  281. VAR
  282. BEGIN
  283. palColors[0].palRed := WORD(control[0]);
  284. palColors[0].palGreen := WORD(control[1]);
  285. palColors[0].palBlue := WORD(control[2]);
  286. Meta.WritePalette(0, palval, palval, palColors);
  287. Str.IntToStr(LONGINT(palval), val, 16, OK);
  288. Str.Append(val, ':');
  289. Insert(buf, val, 0, 24);
  290. Str.IntToStr(LONGINT(palColors[0].palRed), val, 16, OK);
  291. Insert(buf, val, 6, 6);
  292. Str.IntToStr(LONGINT(palColors[0].palGreen), val, 16, OK);
  293. Insert(buf, val, 12, 6);
  294. Str.IntToStr(LONGINT(palColors[0].palBlue), val, 16, OK);
  295. Insert(buf, val, 18, 6);
  296. buf[24] := CHR(0);
  297. Meta.MoveTo(650, 100 - 40);
  298. Meta.DrawString(buf);
  299. END ANmix_color;
  300. (*** Get color value of palval and set controls. ***)
  301. PROCEDURE ANunmix_color(palval: CARDINAL);
  302. BEGIN
  303. Meta.ReadPalette(0, palval, palval, palColors);
  304. control[0] := LONGINT(palColors[0].palRed);
  305. control[1] := LONGINT(palColors[0].palGreen);
  306. control[2] := LONGINT(palColors[0].palBlue);
  307. END ANunmix_color;
  308. (* digital palette version *)
  309. (*** For palette entry 'palval', mix the current control values per EGA, ***)
  310. (*** store in palette array, and change hardware palette entry. ***)
  311. PROCEDURE EGAmix_color(palval: CARDINAL);
  312. VAR
  313. red, green, blue, mix: WORD;
  314. paletteVals: ARRAY [0..0] OF WORD;
  315. BEGIN
  316. red := WORD(control[0] DIV EGAADJUST);
  317. green := WORD(control[1] DIV EGAADJUST);
  318. blue := WORD(control[2] DIV EGAADJUST);
  319. mix := 0;
  320. IF INTEGER(BITSET(blue) * BITSET(0001H)) # 0 THEN
  321. mix := BITSET(mix) + BITSET(0008H);
  322. END;
  323. IF INTEGER(BITSET(blue) * BITSET(0002H)) # 0 THEN
  324. mix := BITSET(mix) + BITSET(0001H);
  325. END;
  326. IF INTEGER(BITSET(green) * BITSET(0001H)) # 0 THEN
  327. mix := BITSET(mix) + BITSET(0010H);
  328. END;
  329. IF INTEGER(BITSET(green) * BITSET(0002H)) # 0 THEN
  330. mix := BITSET(mix) + BITSET(0002H);
  331. END;
  332. IF INTEGER(BITSET(red) * BITSET(0001H)) # 0 THEN
  333. mix := BITSET(mix) + BITSET(0020H);
  334. END;
  335. IF INTEGER(BITSET(red) * BITSET(0002H)) # 0 THEN
  336. mix := BITSET(mix) + BITSET(0004H);
  337. END;
  338. Str.IntToStr(LONGINT(palval), val, 16, OK);
  339. Str.Append(val, ':');
  340. Insert(buf, val, 0, 24);
  341. Str.IntToStr(LONGINT(mix), val, 16, OK);
  342. Insert(buf, val, 6, 6);
  343. buf[24] := CHR(0);
  344. Meta.MoveTo(650, 100 - 40);
  345. Meta.DrawString(buf);
  346. paletteVals[0] := mix;
  347. Meta.LoadPalette(palval, palval, paletteVals);
  348. END EGAmix_color;
  349. (*** Take color value of palval apart per EGA and set global control array ***)
  350. (*** to its components. ***)
  351. PROCEDURE EGAunmix_color(palval: CARDINAL);
  352. VAR
  353. red, green, blue, mix: WORD;
  354. BEGIN
  355. red := 0;
  356. green := 0;
  357. blue := 0;
  358. mix := WORD(palette[palval]);
  359. IF INTEGER(BITSET(mix) * BITSET(0008H)) # 0 THEN
  360. blue := BITSET(blue) + BITSET(0001H);
  361. END;
  362. IF INTEGER(BITSET(mix) * BITSET(0001H)) # 0 THEN
  363. blue := BITSET(blue) + BITSET(0002H);
  364. END;
  365. IF INTEGER(BITSET(mix) * BITSET(0010H)) # 0 THEN
  366. green := BITSET(green) + BITSET(0001H);
  367. END;
  368. IF INTEGER(BITSET(mix) * BITSET(0002H)) # 0 THEN
  369. green := BITSET(green) + BITSET(0002H);
  370. END;
  371. IF INTEGER(BITSET(mix) * BITSET(0020H)) # 0 THEN
  372. red := BITSET(red) + BITSET(0001H);
  373. END;
  374. IF INTEGER(BITSET(mix) * BITSET(0004H)) # 0 THEN
  375. red := BITSET(red) + BITSET(0002H);
  376. END;
  377. control[0] := LONGINT(red) * EGAADJUST;
  378. control[1] := LONGINT(green) * EGAADJUST;
  379. control[2] := LONGINT(blue) * EGAADJUST;
  380. END EGAunmix_color;
  381. PROCEDURE mix_color(palval: CARDINAL);
  382. BEGIN
  383. CASE paltype OF
  384. | 1: ANmix_color(palval);
  385. | 2: EGAmix_color(palval);
  386. ELSE
  387. GrQry.GrQuit('Device does not support a changeable color set', 1);
  388. END;
  389. END mix_color;
  390. PROCEDURE unmix_color(palval: CARDINAL);
  391. BEGIN
  392. CASE paltype OF
  393. | 1: ANunmix_color(palval);
  394. | 2: EGAunmix_color(palval);
  395. ELSE
  396. GrQry.GrQuit('Device does not support a changeable color set', 1);
  397. END;
  398. END unmix_color;
  399. (*** Load the specified font. ***)
  400. PROCEDURE LoadFont(VAR fontName: ARRAY OF CHAR);
  401. VAR
  402. Dir: GrConst.dirRec;
  403. qErr,
  404. loadErr: INTEGER;
  405. path: ARRAY[0..80] OF CHAR;
  406. fontBuf: GrFonts.adsFont;
  407. BEGIN
  408. Str.Copy(path, fontName);
  409. loadErr := -1; (* Preempt Error *)
  410. qErr := Meta.FileQuery(path, Dir, 1);
  411. IF (qErr # 1) THEN
  412. (* No font file in default dir, try environment variable *)
  413. Lib.EnvironmentFind("METAPATH", path);
  414. IF (path[0] # CHR(0)) THEN
  415. (* found the env parm, try using the path listed there *)
  416. IF (path[Str.Length(path)] # '\') THEN
  417. (* If no trailing slash, add one *)
  418. Str.Append(path, '\');
  419. END;
  420. Str.Append(path, fontName);
  421. qErr := Meta.FileQuery(path, Dir, 1);
  422. END;
  423. END;
  424. IF (qErr = 1) THEN
  425. (* we got our file *)
  426. ALLOCATE(ADDRESS(fontBuf), VAL(CARDINAL, Dir.fileSize + 1));
  427. IF (fontBuf # NIL) THEN
  428. (* We got our memory *)
  429. loadErr := Meta.FileLoad(path, ADDRESS(fontBuf), VAL(CARDINAL, Dir.fileSize+1));
  430. IF loadErr <= 0 THEN
  431. DEALLOCATE(ADDRESS(fontBuf), VAL(CARDINAL, Dir.fileSize + 1));
  432. END;
  433. Meta.SetFont(ADDRESS(fontBuf));
  434. END;
  435. END;
  436. IF (loadErr > 0) THEN
  437. (* clear out system load error *)
  438. qErr := Meta.QueryError();
  439. ELSE
  440. (* beep if font load probs *)
  441. IO.WrChar(CHR(7));
  442. Str.Copy(fontName, 'Using internal SYSTEM08.FNT');
  443. END;
  444. END LoadFont;
  445. BEGIN
  446. (* init the system *)
  447. GrQry.GrQuery(GrafixCard, CommPort);
  448. i := Meta.InitGrafix(-GrafixCard);
  449. IF (i # 0) THEN
  450. (* Display reason for no go *)
  451. GrQry.GrInitErr(GrafixCard, CommPort, i);
  452. END;
  453. (* Default EGA palette. *)
  454. palette[0] := 0;
  455. palette[1] := 1;
  456. palette[2] := 2;
  457. palette[3] := 3;
  458. palette[4] := 4;
  459. palette[5] := 5;
  460. palette[6] := 14H;
  461. palette[7] := 7;
  462. palette[8] := 38H;
  463. palette[9] := 39H;
  464. palette[10] := 3AH;
  465. palette[11] := 3BH;
  466. palette[12] := 3CH;
  467. palette[13] := 3DH;
  468. palette[14] := 3EH;
  469. palette[15] := 3FH;
  470. Meta.SetDisplay(GrConst.GrafPg0);
  471. Meta.InitMouse(CommPort);
  472. Meta.ScreenRect(scrnR);
  473. Meta.LimitMouse(scrnR.Xmin, scrnR.Ymin, scrnR.Xmax, scrnR.Ymax);
  474. Meta.SetRect(scrnR, 0, 0, 1000, 1000);
  475. Meta.VirtualRect(scrnR);
  476. Meta.EraseRect(scrnR);
  477. (* load the font *)
  478. Meta.GetPort(thePort);
  479. i := thePort^.portBMap^.devClass;
  480. IF thePort^.portBMap^.pixPlanes > 1 THEN
  481. i := INTEGER(BITSET(i) * BITSET(0FFF8H));
  482. END;
  483. Str.Copy(fntpath, 'SYSTEM');
  484. Str.IntToStr(LONGINT(i), val, 10, OK);
  485. Str.Append(fntpath, val);
  486. Str.Append(fntpath, '.FNT');
  487. LoadFont(fntpath);
  488. max_colors := Meta.QueryColors();
  489. paltype := 0;
  490. IF max_colors = 255 THEN
  491. paltype := 1; (* Use analog palette routines *)
  492. ELSIF GrafixCard = GrConst.EGA640x480 THEN (* this is a vga in 16 color modes *)
  493. (* Use VGA 640x480 in analog mode *)
  494. FOR i := 0 TO 15 DO
  495. palette[i] := i; (* set array for vga stuff *)
  496. END;
  497. Meta.LoadPalette(0, 15, palette); (* set digital palette *)
  498. palColors[0].palRed := 0FFFFH;
  499. palColors[0].palGreen := 0FFFFH;
  500. palColors[0].palBlue := 0FFFFH;
  501. Meta.WritePalette(0, 0FH, 0FH, palColors[0]); (* make sure white is set *)
  502. paltype := 1; (* Use anlog palette routines *)
  503. ELSIF thePort^.portBMap^.devType = 1 THEN (* EGA ?, not 640x480 *)
  504. paltype := 2; (* Use EGA palette routines *)
  505. END;
  506. (* draw the palette *)
  507. draw_palette();
  508. (* draw the control panel *)
  509. draw_panel();
  510. (* turn on cursor tracking *)
  511. Meta.TrackCursor(TRUE);
  512. Meta.ShowCursor();
  513. (* turn on event system *)
  514. Meta.EventQueue(TRUE);
  515. (* start with palette entry 0 *)
  516. selPalEntry := 0;
  517. unmix_color(selPalEntry);
  518. draw_indicator(0);
  519. draw_indicator(1);
  520. draw_indicator(2);
  521. draw_clr_rect(selPalEntry);
  522. speed := 1; (* initialize the control speed *)
  523. (* process events *)
  524. LOOP
  525. (* get an event *)
  526. OK := Meta.KeyEvent(FALSE, myevent);
  527. cursor_pt.X := myevent.CursorX;
  528. cursor_pt.Y := myevent.CursorY;
  529. (* if we had a mouse event *)
  530. IF OK & (myevent.ASCII = CHR(0)) & (myevent.ScanCode = BYTE(0)) THEN
  531. (* right button is exit *)
  532. IF INTEGER(BITSET(myevent.State) * BITSET(MOUSE_RIGHT)) # 0 THEN
  533. EXIT;
  534. END;
  535. (* left button is select *)
  536. IF INTEGER(BITSET(myevent.State) * BITSET(MOUSE_LEFT)) # 0 THEN
  537. (* clicked a palette box ? *)
  538. i := check_palette(cursor_pt);
  539. IF (i >= 0) THEN
  540. (* select palette entry for editing *)
  541. selPalEntry := i;
  542. unmix_color(selPalEntry);
  543. draw_indicator(0);
  544. draw_indicator(1);
  545. draw_indicator(2);
  546. draw_clr_rect(selPalEntry);
  547. ELSE
  548. (* clicked a control ? *)
  549. buttons := 1;
  550. LOOP
  551. i := check_panel(cursor_pt);
  552. IF (i < 0) OR (buttons = 0) THEN
  553. EXIT;
  554. END;
  555. (* adjust selected control *)
  556. CASE i OF
  557. | 0: INC(control[0], LONGINT(speed)); i := 0;
  558. | 1: DEC(control[0], LONGINT(speed)); i := 0;
  559. | 2: INC(control[1], LONGINT(speed)); i := 1;
  560. | 3: DEC(control[1], LONGINT(speed)); i := 1;
  561. | 4: INC(control[2], LONGINT(speed)); i := 2;
  562. | 5: DEC(control[2], LONGINT(speed)); i := 2;
  563. ELSE
  564. i := 0;
  565. END;
  566. (* move fast or slow *)
  567. IF speed < 7FFH THEN
  568. INC(speed, 3FH);
  569. ELSE
  570. speed := 7FFH; (* fast slow move *)
  571. END;
  572. (* keep in range *)
  573. IF (control[i] > 0FFFFH) THEN
  574. control[i] := 0FFFFH;
  575. END;
  576. IF (control[i] < 0) THEN
  577. control[i] := 0H;
  578. END;
  579. (* update control indicator *)
  580. draw_indicator(i);
  581. (* update the palette *)
  582. mix_color(selPalEntry);
  583. (* read current cursor position *)
  584. Meta.QueryCursor(x, y, curs, buttons);
  585. cursor_pt.X := x;
  586. cursor_pt.Y := y;
  587. END; (* end of while on a control *)
  588. END;
  589. END; (* end of if left button *)
  590. END; (* end of if mouse event *)
  591. IF (speed > 80H) THEN
  592. DEC(speed, 7FH);
  593. ELSE
  594. speed := 1; (* slow move *)
  595. END;
  596. END; (* end of while(True) *)
  597. GrQry.GrQuit('', 0);
  598. END ColorPal.