pal_ed.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /* $Id$
  2. * MegaZeux
  3. *
  4. * Copyright (C) 1996 Greg Janson
  5. * Copyright (C) 1998 Matthew D. Williams - dbwilli@scsn.net
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. /* Palette editor */
  22. #include "timer.h"
  23. #include "helpsys.h"
  24. #include "palette.h"
  25. #include "pal_ed.h"
  26. #include "window.h"
  27. #include "getkey.h"
  28. #include "data.h"
  29. #include "graphics.h"
  30. #include "beep.h"
  31. #include "hexchar.h"
  32. //---------------------------------------------
  33. //
  34. // ##..##..##..##..##..##..##..##.. Color #00-
  35. // ##..##..##..##..##..#1.1#1.1#1.1 Red 00/63
  36. // #0.1#2.3#4.5#6.7#8.9#0.1#2.3#4.5 Grn 00/63
  37. // ##..##..##..##..##..##..##..##.. Blu 00/63
  38. // ^^
  39. //
  40. // %- Select color Alt+D- Default palette
  41. // R- Increase Red Alt+R- Decrease Red
  42. // G- Increase Grn Alt+G- Decrease Grn
  43. // B- Increase Blu Alt+B- Decrease Blu
  44. // A- Increase All Alt+A- Decrease All
  45. // 0- Blacken color F2- Store color
  46. // Q- Quit editing F3- Retrieve color
  47. //
  48. //---------------------------------------------
  49. //Mouse- Color=Change color
  50. // Menu=Do command
  51. // RGB #'s=Raise/Lower R/G/B
  52. //2 columns 7 rows
  53. int menu_cmds[2][7]={
  54. { 0,'R','G','B','A','0','Q' },
  55. { -32,-19,-34,-48,-30,-60,-61 } };
  56. void palette_editor(void) {
  57. int t1,t2,key,chr,col;
  58. int curcol=0;
  59. char r,g,b,mouse_held=0;
  60. static char sr=-1,sg=-1,sb=-1;
  61. set_context(93);
  62. m_hide();
  63. save_screen(current_pg_seg);
  64. //Draw window
  65. draw_window_box(17,3,63,19,current_pg_seg,128,143,135);
  66. //Draw palette bars
  67. for(t1=0;t1<32;t1++) {
  68. for(t2=0;t2<4;t2++) {
  69. chr=' ';
  70. if((t1&1)&&(t2==1)&&(t1>19)) chr='1';
  71. if((t1&1)&&(t2==2)) chr='0'+((t1>>1)%10);
  72. col=((t1&30)<<3);
  73. if(t1<20) col+=15;
  74. draw_char(chr,col,19+t1,5+t2,current_pg_seg);
  75. }
  76. }
  77. //Write rgb info stuff
  78. write_string("Color #00-\n Red 00/63\n Grn 00/63\n Blu 00/63",
  79. 52,5,143,current_pg_seg);
  80. //Write menu
  81. write_string("- Select color Alt+D- Default palette\n\
  82. R- Increase Red Alt+R- Decrease Red\n\
  83. G- Increase Grn Alt+G- Decrease Grn\n\
  84. B- Increase Blu Alt+B- Decrease Blu\n\
  85. A- Increase All Alt+A- Decrease All\n\
  86. 0- Blacken colorF2- Store color\n\
  87. Q- Quit editing F3- Retrieve color",19,11,143,current_pg_seg);
  88. m_show();
  89. do {
  90. //Write rgb and color #
  91. get_rgb(curcol,r,g,b);
  92. m_hide();
  93. write_number(curcol,143,59,5,current_pg_seg,2);
  94. write_number(r,143,57,6,current_pg_seg,2);
  95. write_number(g,143,57,7,current_pg_seg,2);
  96. write_number(b,143,57,8,current_pg_seg,2);
  97. //Draw '^^', get key, erase '^^'
  98. write_string("",19+(curcol<<1),9,143,current_pg_seg);
  99. m_show();
  100. key=getkey();
  101. if((key>='a')&&(key<='z')) key-=32;
  102. m_hide();
  103. write_string(" ",19+(curcol<<1),9,143,current_pg_seg);
  104. m_show();
  105. //Process
  106. re_evaul_key:
  107. switch(key) {
  108. case MOUSE_EVENT:
  109. //Menu?
  110. if((mouse_event.cx>18)&&(mouse_event.cx<62)&&
  111. (mouse_event.cy>10)&&(mouse_event.cy<18)) {
  112. if(mouse_event.cx<36) key=menu_cmds[0][mouse_event.cy-11];
  113. else key=menu_cmds[1][mouse_event.cy-11];
  114. goto re_evaul_key;
  115. }
  116. //Color?
  117. if((mouse_event.cx>18)&&(mouse_event.cx<51)&&
  118. (mouse_event.cy>4)&&(mouse_event.cy<9)) {
  119. curcol=(mouse_event.cx-19)>>1;
  120. mouse_held=2;
  121. break;
  122. }
  123. //R/G/B +/-?
  124. if((mouse_event.cx>52)&&(mouse_event.cx<62)&&
  125. (mouse_event.cy>5)&&(mouse_event.cy<9)) {
  126. //Determine plus/minus (by 21!)
  127. if(mouse_event.cx<59) {
  128. //Minus
  129. if(mouse_event.cy==6) {
  130. r-=21;
  131. if(r<0) r=0;
  132. }
  133. else if(mouse_event.cy==7) {
  134. g-=21;
  135. if(g<0) g=0;
  136. }
  137. else {
  138. b-=21;
  139. if(b<0) b=0;
  140. }
  141. }
  142. else {
  143. //Plus
  144. if(mouse_event.cy==6) {
  145. r+=21;
  146. if(r>63) r=63;
  147. }
  148. else if(mouse_event.cy==7) {
  149. g+=21;
  150. if(g>63) g=63;
  151. }
  152. else {
  153. b+=21;
  154. if(b>63) b=63;
  155. }
  156. }
  157. set_rgb(curcol,r,g,b);
  158. update_palette();
  159. mouse_held=2;
  160. break;
  161. }
  162. //Nothing
  163. default:
  164. beep();
  165. mouse_held=2;
  166. break;
  167. case -75:
  168. case '-':
  169. case '_':
  170. if(curcol>0) curcol--;
  171. break;
  172. case -77:
  173. case '=':
  174. case '+':
  175. if(curcol<15) curcol++;
  176. break;
  177. case 'Q':
  178. key=27;
  179. mouse_held=2;
  180. break;
  181. case 'R':
  182. if(r<63) {
  183. r++;
  184. set_rgb(curcol,r,g,b);
  185. update_palette();
  186. }
  187. break;
  188. case 'G':
  189. if(g<63) {
  190. g++;
  191. set_rgb(curcol,r,g,b);
  192. update_palette();
  193. }
  194. break;
  195. case 'B':
  196. if(b<63) {
  197. b++;
  198. set_rgb(curcol,r,g,b);
  199. update_palette();
  200. }
  201. break;
  202. case 'A':
  203. if(r<63) r++;
  204. if(g<63) g++;
  205. if(b<63) b++;
  206. set_rgb(curcol,r,g,b);
  207. update_palette();
  208. break;
  209. case -19://AltR
  210. if(r>0) {
  211. r--;
  212. set_rgb(curcol,r,g,b);
  213. update_palette();
  214. }
  215. break;
  216. case -34://AltG
  217. if(g>0) {
  218. g--;
  219. set_rgb(curcol,r,g,b);
  220. update_palette();
  221. }
  222. break;
  223. case -48://AltB
  224. if(b>0) {
  225. b--;
  226. set_rgb(curcol,r,g,b);
  227. update_palette();
  228. }
  229. break;
  230. case -30://AltA
  231. if(r>0) r--;
  232. if(g>0) g--;
  233. if(b>0) b--;
  234. set_rgb(curcol,r,g,b);
  235. update_palette();
  236. break;
  237. case '0':
  238. r=g=b=0;
  239. set_rgb(curcol,r,g,b);
  240. update_palette();
  241. mouse_held=2;
  242. break;
  243. case -32://AltD
  244. default_palette();
  245. mouse_held=2;
  246. break;
  247. case -60://F2
  248. sr=r; sg=g; sb=b;
  249. mouse_held=2;
  250. break;
  251. case -61://F3
  252. if(sr==-1) break;
  253. r=sr; g=sg; b=sb;
  254. set_rgb(curcol,r,g,b);
  255. update_palette();
  256. case 27:
  257. case 0:
  258. mouse_held=2;
  259. break;
  260. }
  261. if(mouse_held==2) mouse_held=0;//Prevent multiples of dumb cmds
  262. else if(m_buttonstatus()&LEFTBDOWN) {
  263. //Holding down button
  264. //Update RGB codes
  265. write_number(curcol,143,59,5,current_pg_seg,2);
  266. write_number(r,143,57,6,current_pg_seg,2);
  267. write_number(g,143,57,7,current_pg_seg,2);
  268. write_number(b,143,57,8,current_pg_seg,2);
  269. if(mouse_held==0) {
  270. delay_time(100);
  271. if(m_buttonstatus()&LEFTBDOWN) mouse_held=1;
  272. }
  273. else {
  274. delay_time(5);
  275. if(!m_buttonstatus()&LEFTBDOWN) mouse_held=0;
  276. }
  277. }
  278. else mouse_held=0;
  279. if(mouse_held) goto re_evaul_key;//Repeat last key;
  280. } while(key!=27);
  281. restore_screen(current_pg_seg);
  282. pop_context();
  283. }