char_ed.cpp 8.5 KB

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