char_ed.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. //Character editor
  22. #include "helpsys.h"
  23. #include "mouse.h"
  24. #include "beep.h"
  25. #include "egacode.h"
  26. #include "char_ed.h"
  27. #include "window.h"
  28. #include "graphics.h"
  29. #include "getkey.h"
  30. #include "hexchar.h"
  31. #include "data.h"
  32. #include "charset.h"
  33. //-------------------------------------------------
  34. // +----------------+ Current char- (#000)
  35. // 000 |................| ..........0..........
  36. // 000 |................| %% Move cursor
  37. // 000 |................| -+ Change char
  38. // 000 |................| Space Toggle pixel
  39. // 000 |................| Enter Select char
  40. // 000 |................| Del Clear char
  41. // 000 |................| N 'Negative'
  42. // 000 |................| Alt+%% Shift char
  43. // 000 |................| M 'Mirror'
  44. // 000 |................| F 'Flip'
  45. // 000 |................| F2 Copy to buffer
  46. // 000 |................| F3 Copy from buffer
  47. // 000 |................| Tab Draw (off)
  48. // 000 |................| F4 Revert to Ascii
  49. // +----------------+ F5 Revert to MZX
  50. //-------------------------------------------------
  51. //Mouse- Menu=Command
  52. // Grid=Toggle
  53. // "Current Char-"=Enter
  54. // "..0.."=Change char
  55. int ce_menu_cmds[14]={ 0,0,' ',13,-83,'N',0,'M','F',-60,-61,9,-62,-63 };
  56. int char_editor(void) {
  57. unsigned char matrix[14];
  58. static unsigned char buffer[14];
  59. char x=3,y=6,draw=0,bit;
  60. int t1,t2,t3,t4,key;
  61. static unsigned char chr=1;
  62. set_context(79);
  63. m_hide();
  64. save_screen(current_pg_seg);
  65. draw_window_box(15,3,65,20,current_pg_seg,143,128,135);
  66. //Draw in static elements
  67. draw_window_box(21,4,38,19,current_pg_seg,128,143,135,0,0);
  68. write_string("Current char-(#000)\n\n\
  69.  Move cursor\n\
  70. -+ Change char\n\
  71. Space Toggle pixel\n\
  72. Enter Select char\n\
  73. DelClear char\n\
  74. N 'Negative'\n\
  75. Alt+ Shift char\n\
  76. M 'Mirror'\n\
  77. F 'Flip'\n\
  78. F2 Copy to buffer\n\
  79. F3 Copy from buffer\n\
  80. TabDraw\n\
  81. F4 Revert to Ascii\n\
  82. F5 Revert to MZX",40,4,143,current_pg_seg);
  83. m_show();
  84. //Get char
  85. ec_read_char(chr,matrix);
  86. do {
  87. //Update char
  88. m_hide();
  89. for(t1=0;t1<8;t1++) {
  90. for(t2=0;t2<14;t2++) {
  91. bit=matrix[t2]&(128>>t1);
  92. if(bit) write_string("ÛÛ",22+(t1<<1),5+t2,135,
  93. current_pg_seg);
  94. else write_string("úú",22+(t1<<1),5+t2,135,current_pg_seg);
  95. }
  96. }
  97. for(t2=0;t2<14;t2++)
  98. write_number(matrix[t2],135,17,5+t2,current_pg_seg,3);
  99. //Update draw status
  100. if(draw==1) write_string("(set) ",53,17,143,current_pg_seg);
  101. else if(draw==2) write_string("(clear) ",53,17,143,current_pg_seg);
  102. else if(draw==3) write_string("(toggle)",53,17,143,current_pg_seg);
  103. else write_string("(off) ",53,17,135,current_pg_seg);
  104. //Highlight cursor
  105. color_line(2,22+(x<<1),5+y,27,current_pg_seg);
  106. //Current character
  107. write_number(chr,143,60,4,current_pg_seg,3);
  108. for(t1=-10;t1<11;t1++)
  109. draw_char((unsigned char)(chr+t1),128+(t1==0)*15,53+t1,5,
  110. current_pg_seg);
  111. //Key
  112. m_show();
  113. key=getkey();
  114. if((key>='a')&&(key<='z')) key-=32;
  115. re_evaul_key:
  116. switch(key) {
  117. case MOUSE_EVENT:
  118. //Mouse- check area
  119. if((mouse_event.cx>21)&&(mouse_event.cx<38)&&
  120. (mouse_event.cy>4)&&(mouse_event.cy<19)) {
  121. //Grid.
  122. x=(mouse_event.cx-22)>>1;
  123. y=mouse_event.cy-5;
  124. goto place;
  125. }
  126. if((mouse_event.cx>38)&&(mouse_event.cx<64)) {
  127. if((mouse_event.cy>5)&&(mouse_event.cy<20)) {
  128. //Menu.
  129. key=ce_menu_cmds[mouse_event.cy-6];
  130. goto re_evaul_key;
  131. }
  132. else if(mouse_event.cy==4) //Choose char.
  133. goto select_char;
  134. else if(mouse_event.cy==5) {
  135. //Change char
  136. if(mouse_event.cx<43) {
  137. beep();//Too far left
  138. break;
  139. }
  140. //Become...
  141. chr+=mouse_event.cx-53;
  142. ec_read_char(chr,matrix);
  143. break;
  144. }
  145. }
  146. default:
  147. //Bad mouse/key
  148. beep();
  149. break;
  150. case -75://Left
  151. if((--x)<0) x=7;
  152. if(draw==1) goto set;
  153. if(draw==2) goto reset;
  154. if(draw==3) goto place;
  155. break;
  156. case -77://Right
  157. if((++x)>7) x=0;
  158. if(draw==1) goto set;
  159. if(draw==2) goto reset;
  160. if(draw==3) goto place;
  161. break;
  162. case -72://Up
  163. if((--y)<0) y=13;
  164. if(draw==1) goto set;
  165. if(draw==2) goto reset;
  166. if(draw==3) goto place;
  167. break;
  168. case -80://Down
  169. if((++y)>13) y=0;
  170. if(draw==1) goto set;
  171. if(draw==2) goto reset;
  172. if(draw==3) goto place;
  173. break;
  174. case '-':
  175. case '_':
  176. chr--;
  177. ec_read_char(chr,matrix);
  178. break;
  179. case '+':
  180. case '=':
  181. chr++;
  182. ec_read_char(chr,matrix);
  183. break;
  184. case ' ':
  185. place:
  186. matrix[y]^=(128>>x);
  187. ec_change_char(chr,matrix);
  188. break;
  189. set:
  190. matrix[y]|=(128>>x);
  191. ec_change_char(chr,matrix);
  192. break;
  193. reset:
  194. matrix[y]&=~(128>>x);
  195. ec_change_char(chr,matrix);
  196. break;
  197. case 13:
  198. select_char:
  199. t1=char_selection(chr,current_pg_seg);
  200. if(t1>=0) chr=t1;
  201. ec_read_char(chr,matrix);
  202. break;
  203. case 'Q':
  204. key=27;
  205. break;
  206. case -83://Delete
  207. for(t1=0;t1<14;t1++) matrix[t1]=0;
  208. ec_change_char(chr,matrix);
  209. break;
  210. case -60://F2
  211. for(t1=0;t1<14;t1++) buffer[t1]=matrix[t1];
  212. break;
  213. case -61://F3
  214. for(t1=0;t1<14;t1++) matrix[t1]=buffer[t1];
  215. ec_change_char(chr,matrix);
  216. break;
  217. case 'M':
  218. for(t1=0;t1<14;t1++) {
  219. t3=128;
  220. t4=1;
  221. for(t2=0;t2<4;t2++) {
  222. if((matrix[t1]&t3)&&(matrix[t1]&t4)) ;/* Both on */
  223. else if((matrix[t1]&t3)||(matrix[t1]&t4)) matrix[t1]^=t3+t4;
  224. t3>>=1;
  225. t4<<=1;
  226. }
  227. }
  228. ec_change_char(chr,matrix);
  229. break;
  230. case 'F':
  231. for(t1=0;t1<7;t1++) {
  232. t2=matrix[t1];
  233. matrix[t1]=matrix[13-t1];
  234. matrix[13-t1]=t2;
  235. }
  236. ec_change_char(chr,matrix);
  237. break;
  238. case 9://Tab
  239. if((++draw)>3) draw=0;
  240. if(draw==1) goto set;
  241. if(draw==2) goto reset;
  242. if(draw==3) goto place;
  243. break;
  244. case 'N':
  245. for(t1=0;t1<14;t1++)
  246. matrix[t1]^=255;
  247. ec_change_char(chr,matrix);
  248. break;
  249. case -62:
  250. //Revert to ascii
  251. for(t1=0;t1<14;t1++)
  252. matrix[t1]=ascii_set[chr*14+t1];
  253. ec_change_char(chr,matrix);
  254. break;
  255. case -63:
  256. //Revert to megazeux
  257. for(t1=0;t1<14;t1++)
  258. matrix[t1]=default_mzx_char_set[chr*14+t1];
  259. ec_change_char(chr,matrix);
  260. break;
  261. case -152:/* Alt Up */
  262. t1=matrix[0];
  263. for(t2=0;t2<13;t2++) matrix[t2]=matrix[t2+1];
  264. matrix[13]=t1;
  265. ec_change_char(chr,matrix);
  266. break;
  267. case -160:/* Alt Down */
  268. t1=matrix[13];
  269. for(t2=14;t2>0;t2--) matrix[t2]=matrix[t2-1];
  270. matrix[0]=t1;
  271. ec_change_char(chr,matrix);
  272. break;
  273. case -155:/* Alt Left */
  274. for(t1=0;t1<14;t1++) {
  275. t2=matrix[t1]&128;
  276. matrix[t1]<<=1;
  277. if(t2) matrix[t1]|=1;
  278. }
  279. ec_change_char(chr,matrix);
  280. break;
  281. case -157:/* Alt Right */
  282. for(t1=0;t1<14;t1++) {
  283. t2=matrix[t1]&1;
  284. matrix[t1]>>=1;
  285. if(t2) matrix[t1]|=128;
  286. }
  287. ec_change_char(chr,matrix);
  288. case 27:
  289. case 0:
  290. break;
  291. }
  292. } while(key!=27);
  293. restore_screen(current_pg_seg);
  294. pop_context();
  295. return chr;
  296. }