gui.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. #ifndef __MARIO_GUI
  2. #define __MARIO_GUI
  3. #include <allegro.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. bool checkBit (BYTE tmp_b,int pos) // Returns state of a single bit
  7. { // which is on 'pos' position
  8. if ( tmp_b&(1<<pos) ) // in tmp_b byte
  9. {
  10. return true;
  11. } else {
  12. return false;
  13. }
  14. }
  15. void
  16. draw_SEG_digit
  17. (BITMAP *buf, int x, int y, int color, int size, BYTE segm_code)
  18. {
  19. int darkc,normc;
  20. normc=color;
  21. darkc=makecol( getr(normc)/4,getg(normc)/4,getb(normc)/4);
  22. if (checkBit (segm_code,1))
  23. {
  24. color=normc;
  25. } else
  26. {
  27. color=darkc;
  28. }
  29. vline (buf, x+size, y, y+size,color);
  30. if (checkBit (segm_code,2))
  31. {
  32. color=normc;
  33. } else
  34. {
  35. color=darkc;
  36. }
  37. vline (buf, x+size, y+size, y+2*size,color);
  38. if (checkBit (segm_code,4))
  39. {
  40. color=normc;
  41. } else
  42. {
  43. color=darkc;
  44. }
  45. vline (buf, x, y+2*size, y+size,color);
  46. if (checkBit (segm_code,5))
  47. {
  48. color=normc;
  49. } else
  50. {
  51. color=darkc;
  52. }
  53. vline (buf, x, y+size, y,color);
  54. if (checkBit (segm_code,6))
  55. {
  56. color=normc;
  57. } else
  58. {
  59. color=darkc;
  60. }
  61. hline (buf, x, y+size, x+size,color);
  62. if (checkBit (segm_code,0))
  63. {
  64. color=normc;
  65. } else
  66. {
  67. color=darkc;
  68. }
  69. hline (buf, x, y, x+size,color);
  70. if (checkBit (segm_code,3))
  71. {
  72. color=normc;
  73. } else
  74. {
  75. color=darkc;
  76. }
  77. hline (buf, x+size, y+2*size, x,color);
  78. if (checkBit (segm_code,7))
  79. {
  80. color=normc;
  81. } else
  82. {
  83. color=darkc;
  84. }
  85. putpixel (buf, x+size+2, y+2*size, color);
  86. }
  87. void
  88. draw_LED_bin
  89. (BITMAP *buf, int x, int y, int color, BYTE code)
  90. {
  91. int darkc,normc;
  92. int i;
  93. normc=color;
  94. darkc=makecol( getr(normc)/4,getg(normc)/4,getb(normc)/4);
  95. for (i=0;i<8;i++)
  96. {
  97. if (checkBit (code,7-i))
  98. {
  99. color=normc;
  100. } else
  101. {
  102. color=darkc;
  103. }
  104. circlefill (buf, x+7*i, y, 2,color);
  105. }
  106. }
  107. void change_char (char *string,char ch,int pos)
  108. {
  109. string[pos-1]=ch;
  110. }
  111. void insert_char (char *string,char ch,int pos,int lenght)
  112. {
  113. for (int c=lenght;c>pos;c--)
  114. {
  115. string[c-1]=string[c-2];
  116. }
  117. string[pos-1]=ch;
  118. }
  119. void cut_char (char *string,int pos,int lenght)
  120. {
  121. for (int c=pos;c<lenght;c++)
  122. {
  123. string[c-1]=string[c];
  124. }
  125. string[lenght-1]=(char)(32);
  126. }
  127. void change_ext(char *s)
  128. {
  129. int c;
  130. for (c=254;c>=0;c--)
  131. {
  132. if (s[c]=='.')
  133. {
  134. s[c+1]='h';
  135. s[c+2]='e';
  136. s[c+3]='x';
  137. break;
  138. }
  139. }
  140. return;
  141. }
  142. void
  143. GetText
  144. (char *text, BITMAP* buf, int x, int y, int w, int h, int lenght, char *title)
  145. {
  146. int c;
  147. BITMAP *surface = create_bitmap(w,h);
  148. BITMAP *cache = create_bitmap(w,h);
  149. blit (buf,cache,x,y,0,0,w,h);
  150. clear (surface);
  151. hline (surface,2,surface->h-2,surface->w-2,makecol (255,255,255));
  152. vline (surface,2,2,surface->h-2,makecol (255,255,255));
  153. vline (surface,surface->w-2,2,surface->h-2,makecol (255,255,255));
  154. for (c=2;c<=2+10;c+=2)
  155. {
  156. hline (surface,2,c,surface->w-2,makecol (255,255,255));
  157. }
  158. textprintf_centre (surface,mainf,surface->w/2,4,makecol (255,255,255)," %s ",title);
  159. text[0]=32;
  160. for (c=1;c<=lenght-1;c++)
  161. {
  162. text[c]=32;
  163. }
  164. text[lenght-1]=0;
  165. clear_keybuf();
  166. int pos=1;
  167. WORD key_p;
  168. WORD key_ch;
  169. bool flag;
  170. while (key[KEY_ENTER])
  171. {
  172. }
  173. while (!key[KEY_ENTER])
  174. {
  175. textprintf (surface,mainf,15,surface->h/2,makecol (255,255,255),"%s",text);
  176. hline (surface,15+(pos-1)*8,surface->h/2+8,15+pos*8,makecol (255,255,255));
  177. blit (surface,buf,0,0,x,y,w,h);
  178. hline (surface,15+(pos-1)*8,surface->h/2+8,15+pos*8,makecol (0,0,0));
  179. key_p = readkey();
  180. key_ch = key_p & 0xff;
  181. key_p=key_p>>8;
  182. flag=false;
  183. switch (key_p)
  184. {
  185. case KEY_BACKSPACE:
  186. if (pos>1)
  187. {
  188. pos--;
  189. cut_char (text,pos,lenght);
  190. text[lenght-2]=32;
  191. text[lenght-1]=0;
  192. }
  193. flag=true;
  194. break;
  195. case KEY_DEL:
  196. cut_char (text,pos,lenght);
  197. text[lenght-2]=32;
  198. text[lenght-1]=0;
  199. flag=true;
  200. break;
  201. case KEY_LEFT:
  202. if (pos>1) pos--;
  203. flag=true;
  204. break;
  205. case KEY_RIGHT:
  206. if (pos<lenght) pos++;
  207. flag=true;
  208. break;
  209. }
  210. if ( !key[KEY_ENTER] && key_ch!=0 && pos<lenght && !flag)
  211. {
  212. insert_char ( text, key_ch, pos, lenght );
  213. pos++;
  214. text[lenght-1]=0;
  215. }
  216. }
  217. text[lenght-1]=0;
  218. blit (cache,buf,0,0,x,y,w,h);
  219. destroy_bitmap(cache);
  220. destroy_bitmap(surface);
  221. }
  222. void
  223. ShowMessage
  224. (char *text, BITMAP* buf, int x, int y, int w, int h, char *title)
  225. {
  226. BITMAP *surface = create_bitmap(w,h);
  227. BITMAP *cache = create_bitmap(w,h);
  228. blit (buf,cache,x,y,0,0,w,h);
  229. clear (surface);
  230. hline (surface,2,surface->h-2,surface->w-2,makecol (255,255,255));
  231. vline (surface,2,2,surface->h-2,makecol (255,255,255));
  232. vline (surface,surface->w-2,2,surface->h-2,makecol (255,255,255));
  233. for (int c=2;c<=2+10;c+=2)
  234. {
  235. hline (surface,2,c,surface->w-2,makecol (255,255,255));
  236. }
  237. textprintf_centre (surface,mainf,surface->w/2,4,makecol (255,255,255)," %s ",title);
  238. textprintf (surface,mainf,15,surface->h/2,makecol (255,255,255),"%s",text);
  239. textprintf_centre (surface,mainf,surface->w/2,surface->h-16,makecol (255,0,0),"Press ENTER");
  240. blit (surface,buf,0,0,x,y,w,h);
  241. while (key[KEY_ENTER])
  242. {
  243. }
  244. while (!key[KEY_ENTER])
  245. {
  246. }
  247. blit (cache,buf,0,0,x,y,w,h);
  248. destroy_bitmap(cache);
  249. destroy_bitmap(surface);
  250. }
  251. bool
  252. QuestionBox
  253. (char *text, BITMAP* buf, int x, int y, int w, int h, char *title, int _color)
  254. {
  255. BITMAP *surface = create_bitmap(w,h);
  256. BITMAP *cache = create_bitmap(w,h);
  257. int len,c,line=0,pos=0;
  258. blit (buf,cache,x,y,0,0,w,h);
  259. clear (surface);
  260. hline (surface,2,surface->h-2,surface->w-2,makecol (255,255,255));
  261. vline (surface,2,2,surface->h-2,makecol (255,255,255));
  262. vline (surface,surface->w-2,2,surface->h-2,makecol (255,255,255));
  263. for (c=2;c<=2+10;c+=2)
  264. {
  265. hline (surface,2,c,surface->w-2,makecol (255,255,255));
  266. }
  267. textprintf_centre (surface,mainf,surface->w/2,4,makecol (255,255,255)," %s ",title);
  268. textprintf_centre (surface,mainf,surface->w/2,surface->h-16,makecol (255,0,0),"Press ENTER (OK) or ESC (Cancel)");
  269. len=(int)strlen (text);
  270. for (c=0;c<len;c++)
  271. {
  272. if (text[c]==10)
  273. {
  274. line++;
  275. pos=0;
  276. } else
  277. {
  278. if (text[c]!=13)
  279. {
  280. if (text[c]>126 || text[c]<32 ) break;
  281. textprintf (surface,mainf,15+pos*8,20+line*10, _color,"%c",text[c]);
  282. pos++;
  283. }
  284. }
  285. }
  286. blit (surface,buf,0,0,x,y,w,h);
  287. while (key[KEY_ENTER] || key[KEY_ESC])
  288. {
  289. }
  290. while ( !(key[KEY_ENTER] || key[KEY_ESC]) )
  291. {
  292. }
  293. if (key[KEY_ENTER]) return true;
  294. else return false;
  295. blit (cache,buf,0,0,x,y,w,h);
  296. destroy_bitmap(cache);
  297. destroy_bitmap(surface);
  298. }
  299. void
  300. ShowMsgEx
  301. (char *text, BITMAP* buf, int x, int y, int w, int h, char *title, int _color)
  302. {
  303. BITMAP *surface = create_bitmap(w,h);
  304. BITMAP *cache = create_bitmap(w,h);
  305. int len,c,line=0,pos=0;
  306. blit (buf,cache,x,y,0,0,w,h);
  307. clear (surface);
  308. hline (surface,2,surface->h-2,surface->w-2,makecol (255,255,255));
  309. vline (surface,2,2,surface->h-2,makecol (255,255,255));
  310. vline (surface,surface->w-2,2,surface->h-2,makecol (255,255,255));
  311. for (c=2;c<=2+10;c+=2)
  312. {
  313. hline (surface,2,c,surface->w-2,makecol (255,255,255));
  314. }
  315. textprintf_centre (surface,mainf,surface->w/2,4,makecol (255,255,255)," %s ",title);
  316. textprintf_centre (surface,mainf,surface->w/2,surface->h-16,makecol (255,0,0),"Press ENTER");
  317. len=(int)strlen (text);
  318. for (c=0;c<len;c++)
  319. {
  320. if (text[c]==10)
  321. {
  322. line++;
  323. pos=0;
  324. } else
  325. {
  326. if (text[c]!=13)
  327. {
  328. if (text[c]>126 || text[c]<32 ) break;
  329. textprintf (surface,mainf,15+pos*8,20+line*10, _color,"%c",text[c]);
  330. pos++;
  331. }
  332. }
  333. }
  334. blit (surface,buf,0,0,x,y,w,h);
  335. while (key[KEY_ENTER])
  336. {
  337. }
  338. while (!key[KEY_ENTER])
  339. {
  340. }
  341. blit (cache,buf,0,0,x,y,w,h);
  342. destroy_bitmap(cache);
  343. destroy_bitmap(surface);
  344. }
  345. class code_editor
  346. {
  347. private:
  348. char *text_edit[65536];
  349. int lines;
  350. int cl, cp;
  351. int scl, scp;
  352. int _w,_h;
  353. public:
  354. code_editor(void);
  355. ~code_editor(void);
  356. bool alloc_new_line(void); // ret. true on success
  357. bool insert_new_line(int ln);
  358. void delete_last (void);
  359. void cut_line (int ln);
  360. void insert_char (int ln, char ch);
  361. void replace_char (int ln, char ch);
  362. void backspace (void);
  363. void del_ch (int ln);
  364. void draw_cr (void);
  365. void clear_cr (void);
  366. void load_source (char *filename);
  367. void save_source (char *filename);
  368. int compile (int *err); // out-num errors, in-table of int's
  369. // thet represtents lines with errors
  370. // (automactly allocated)
  371. int left,top;
  372. int tab_size;
  373. BITMAP *surface;
  374. void process(void);
  375. void disp (void);
  376. };
  377. void code_editor::load_source(char *filename)
  378. {
  379. FILE *strin;
  380. int c,i,tp,j=0;
  381. strin=NULL;
  382. strin=fopen(filename,"rb");
  383. lines=0;
  384. if (strin==NULL) ShowMessage("Can't open the file",screen,200,200,200,60,"Message!");
  385. else
  386. {
  387. //for (c=0;c<65535;c++)
  388. //{
  389. // if (text_edit[c]!=NULL) delete[] text_edit[c];
  390. // else break;
  391. //}
  392. while (!feof(strin))
  393. {
  394. alloc_new_line();
  395. for (i=0; (i<256) && !feof(strin); i++)
  396. {
  397. c=fgetc(strin);
  398. if (c==9) //TAB
  399. {
  400. tp=i/tab_size;
  401. tp++;
  402. tp*=8;
  403. for (i;i<=tp;i++) text_edit[j][i]=32;
  404. i--;
  405. } else
  406. {
  407. if ((c==10) || (c==13))
  408. {
  409. if (c==13) fgetc(strin);
  410. for (i;i<256;i++)
  411. text_edit[j][i]=10;
  412. } else text_edit[j][i]= c==-1?10:c ;
  413. }
  414. }
  415. j++;
  416. }
  417. lines=j;
  418. fclose (strin);
  419. }
  420. cp=0; cl=0;
  421. scp=0; scl=0;
  422. disp();
  423. }
  424. void code_editor::disp (void)
  425. {
  426. int i,j,cnti,cntj=0;
  427. for (j=cl-scl;j<cl-scl+_h+1 && cntj<lines;j++)
  428. {
  429. cnti=0;
  430. bool endf=false;
  431. for (i=cp-scp;i<cp-scp+_w && !endf;i++)
  432. {
  433. if (text_edit[j][i]==10 || text_edit[j][i]==0 || text_edit[j][i]==13) endf=true;
  434. else
  435. {
  436. textprintf (surface, mainf,left+cnti*8, top+cntj*10, makecol(255,255,255),"%c",text_edit[j][i]);
  437. cnti++;
  438. }
  439. }
  440. for (i;i<cp-scp+_w+1;i++)
  441. {
  442. textprintf (surface, mainf,left+cnti*8, top+cntj*10, makecol(255,255,255)," ");
  443. cnti++;
  444. }
  445. cntj++;
  446. }
  447. if (cntj<_h) rectfill (surface,left,top+cntj*10,surface->w-left,surface->h-left,0);
  448. }
  449. void code_editor::process(void)
  450. {
  451. BITMAP *cache;
  452. int c,i;
  453. bool exit_ed=false;
  454. char *filen;
  455. filen=new char[256];
  456. cache=create_bitmap(SCREEN_W, SCREEN_H);
  457. blit (screen, cache, 0,0,0,0,SCREEN_W, SCREEN_H);
  458. clear (surface);
  459. hline (surface,2,surface->h-2,surface->w-2,makecol (255,255,255));
  460. vline (surface,2,2,surface->h-2,makecol (255,255,255));
  461. vline (surface,surface->w-2,2,surface->h-2,makecol (255,255,255));
  462. for (c=2;c<=2+10;c+=2)
  463. {
  464. hline (surface,2,c,surface->w-2,makecol (255,255,255));
  465. }
  466. textprintf_centre (surface,mainf,surface->w/2,4,makecol (255,255,255)," Source editor ");
  467. lines=0;
  468. alloc_new_line();
  469. WORD key_p;
  470. WORD key_ch;
  471. while(!exit_ed)
  472. {
  473. key_p = readkey();
  474. key_ch = key_p & 0xff;
  475. key_p=key_p>>8;
  476. switch (key_p)
  477. {
  478. case KEY_BACKSPACE:
  479. if (cp>0)
  480. {
  481. clear_cr();
  482. if (scp>0) scp--;
  483. cp--;
  484. backspace ();
  485. } else
  486. {
  487. if (cl>0)
  488. {
  489. clear_cr();
  490. for (c=0;(c<256) && (text_edit[cl-1][c]!=10);c++)
  491. {
  492. }
  493. cp=c;
  494. scp=cp;
  495. if (scp>=_w) scp=_w-1;
  496. for (c;c<256;c++)
  497. {
  498. text_edit[cl-1][c] = text_edit[cl][c-cp];
  499. if (text_edit[cl][c-cp]==10) break;
  500. }
  501. delete[]text_edit[cl];
  502. for (i=cl;i<lines;i++) text_edit[i]=text_edit[i+1];
  503. lines--;
  504. text_edit[lines]=NULL;
  505. cl--;
  506. if (scl>0) scl--;
  507. }
  508. }
  509. break;
  510. case KEY_DEL:
  511. backspace ();
  512. break;
  513. case KEY_ENTER:
  514. if (cl<65536)
  515. {
  516. clear_cr();
  517. cl++;
  518. if (scl<_h) scl++;
  519. if (!insert_new_line(cl))
  520. {
  521. ShowMessage("Out of memory",surface,200,100,200,60,"Error!");
  522. } else {
  523. for (c=cp;c<256;c++)
  524. {
  525. text_edit[cl][c-cp]=text_edit[cl-1][c];
  526. text_edit[cl-1][c]=10;
  527. }
  528. cp=0;
  529. scp=0;
  530. }
  531. } else ShowMessage("Source can't has more then 65536 lines of code!!!",surface,200,100,200,60,"Error!");
  532. break;
  533. case KEY_END:
  534. clear_cr();
  535. for (cp=0;cp<256 && text_edit[cl][cp]!=10;cp++)
  536. {
  537. }
  538. scp=cp;
  539. if (scp>=_w) scp=_w-1;
  540. break;
  541. case KEY_HOME:
  542. clear_cr();
  543. cp=0;
  544. scp=0;
  545. break;
  546. case KEY_LEFT:
  547. if (cp>0)
  548. {
  549. clear_cr();
  550. cp--;
  551. if (scp>0) scp--;
  552. } else
  553. {
  554. if (cl>0)
  555. {
  556. clear_cr();
  557. for (c=0;(c<256) && (text_edit[cl-1][c]!=10);c++)
  558. {
  559. }
  560. cp=c;
  561. scp=cp;
  562. if (scp>=_w) scp=_w-1;
  563. cl--;
  564. if (scl>0) scl--;
  565. }
  566. }
  567. break;
  568. case KEY_RIGHT:
  569. if (cp<256 && text_edit[cl][cp]!=10)
  570. {
  571. clear_cr();
  572. cp++;
  573. if (scp<_w) scp++;
  574. } else
  575. {
  576. if (cl+1<lines)
  577. {
  578. clear_cr();
  579. cp=0;
  580. scp=cp;
  581. if (scp>=_w) scp=_w-1;
  582. cl++;
  583. if (scl<_h) scl++;
  584. }
  585. }
  586. break;
  587. case KEY_UP:
  588. if (cl>0)
  589. {
  590. clear_cr();
  591. cl--;
  592. if (scl>0) scl--;
  593. for (c=0;c<256 && text_edit[cl][c]!=10;c++)
  594. {
  595. }
  596. if (c-1<cp)
  597. {
  598. cp=c;
  599. scp=cp;
  600. if (scp>=_w) scp=_w-1;
  601. }
  602. }
  603. break;
  604. case KEY_DOWN:
  605. if (cl<65536 && cl<(lines-1))
  606. {
  607. clear_cr();
  608. cl++;
  609. if (scl<_h) scl++;
  610. for (c=0;c<256 && text_edit[cl][c]!=10;c++)
  611. {
  612. }
  613. if (c-1<cp)
  614. {
  615. cp=c;
  616. scp=cp;
  617. if (scp>=_w) scp=_w-1;
  618. }
  619. }
  620. break;
  621. case KEY_ESC:
  622. if (QuestionBox("Are you sure want to EXIT?" ,screen,200,200,400,60,"Confirm!",makecol(255,0,0)))
  623. {
  624. exit_ed=true;
  625. for (c=0;c<lines;c++)
  626. {
  627. if (text_edit[c] != NULL)
  628. {
  629. delete[] text_edit[c];
  630. }
  631. }
  632. lines=0;
  633. }
  634. else
  635. {
  636. rest (500);
  637. clear_keybuf();
  638. }
  639. break;
  640. case KEY_F3:
  641. GetText(filen,screen,100,200,600,60,256," Enter source code file name ");
  642. for (c=254;filen[c]==' ' || filen[c]=='\r';c--)
  643. {
  644. filen[c]=0;
  645. }
  646. load_source(filen);
  647. break;
  648. default:
  649. if (key_ch!=0 && cp<256)
  650. {
  651. insert_char (cl,key_ch);
  652. clear_cr();
  653. cp++;
  654. if (scp<_w) scp++;
  655. key_ch=0;
  656. }
  657. break;
  658. }
  659. if (!exit_ed)
  660. {
  661. disp();
  662. draw_cr();
  663. }
  664. textprintf (surface, mainf, 1, 1, makecol (255,255,255)," p%d l%d sp%d sl%d c%d ln%d",cp,cl,scp,scl, text_edit[cl][cp], lines);
  665. blit (surface,screen,0,0,0,0,surface->w,surface->h);
  666. }
  667. blit (cache, screen, 0,0,0,0,SCREEN_W, SCREEN_H);
  668. destroy_bitmap(cache);
  669. delete[] filen;
  670. return;
  671. }
  672. void code_editor::insert_char (int ln, char ch)
  673. {
  674. int i;
  675. for (i=256;i>cp;i--)
  676. {
  677. text_edit[cl][i]=text_edit[cl][i-1];
  678. }
  679. text_edit[cl][cp]=ch;
  680. }
  681. void code_editor::backspace (void)
  682. {
  683. int i;
  684. for (i=cp;i<256;i++)
  685. {
  686. text_edit[cl][i]=text_edit[cl][i+1];
  687. }
  688. }
  689. void code_editor::draw_cr(void)
  690. {
  691. hline (surface,left+8*scp,top+10*scl+9,left+8*scp+8,makecol(255,255,255));
  692. }
  693. void code_editor::clear_cr(void)
  694. {
  695. hline (surface,left+8*scp,top+10*scl+9,left+8*scp+8,0);
  696. }
  697. code_editor::code_editor(void)
  698. {
  699. int i;
  700. for (i=0;i<65536;i++) text_edit[i]=NULL;
  701. lines=0;
  702. top=24;
  703. left=11;
  704. cl=0; cp=0;
  705. scl=0; scp=0;
  706. surface=create_bitmap(SCREEN_W,SCREEN_H-100);
  707. _w=(surface->w-left*2)/8-1;
  708. _h=(surface->h-top-left)/10-1;
  709. tab_size=8;
  710. }
  711. code_editor::~code_editor(void)
  712. {
  713. }
  714. bool code_editor::alloc_new_line(void)
  715. {
  716. int i;
  717. if (lines < 65536)
  718. {
  719. text_edit[lines]=new char[256];
  720. for (i=0;i<256;i++) text_edit[lines][i]=10;
  721. lines++;
  722. return text_edit[lines]==NULL?false:true;
  723. }
  724. return false;
  725. }
  726. bool code_editor::insert_new_line(int ln)
  727. {
  728. int i;
  729. if (lines < 65536)
  730. {
  731. for (i=lines;i>ln;i--) text_edit[i]=text_edit[i-1];
  732. text_edit[ln]=NULL;
  733. text_edit[ln]=new char[256];
  734. for (i=0;i<256;i++) text_edit[ln][i]=10;
  735. lines++;
  736. if (text_edit[ln]==NULL)
  737. {
  738. for (i=ln;i<lines;i++) text_edit[i]=text_edit[i+1];
  739. lines--;
  740. return false;
  741. } else return true;
  742. }
  743. return false;
  744. }
  745. void code_editor::delete_last(void)
  746. {
  747. lines--;
  748. delete[] text_edit[lines];
  749. text_edit[lines]=NULL;
  750. }
  751. void code_editor::cut_line(int ln)
  752. {
  753. int i;
  754. if (text_edit[ln]!=NULL)
  755. {
  756. for (i=ln;i<lines;i++) text_edit[i]=text_edit[i+1];
  757. lines--;
  758. }
  759. }
  760. #endif // __MARIO_GUI