123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905 |
- #ifndef __MARIO_GUI
- #define __MARIO_GUI
- #include <allegro.h>
- #include <stdio.h>
- #include <stdlib.h>
- // Returns state of a single bit which is on 'pos' position in tmp_b byte
- bool checkBit(BYTE tmp_b, int pos)
- {
- if ( tmp_b & ( 1 << pos ))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- void draw_SEG_digit(BITMAP *buf, int x, int y, int color, int size, BYTE segm_code)
- {
- int darkc, normc;
- normc = color;
- darkc = makecol(getr(normc) / 4, getg(normc) / 4, getb(normc) / 4);
- if ( checkBit(segm_code, 1))
- {
- color = normc;
- }
- else
- {
- color = darkc;
- }
- vline(buf, x + size, y, y + size, color);
- if ( checkBit(segm_code, 2))
- {
- color = normc;
- }
- else
- {
- color = darkc;
- }
- vline(buf, x + size, y + size, y + 2 * size, color);
- if ( checkBit(segm_code, 4))
- {
- color = normc;
- }
- else
- {
- color = darkc;
- }
- vline(buf, x, y + 2 * size, y + size, color);
- if ( checkBit(segm_code, 5))
- {
- color = normc;
- }
- else
- {
- color = darkc;
- }
- vline(buf, x, y + size, y, color);
- if ( checkBit(segm_code, 6))
- {
- color = normc;
- }
- else
- {
- color = darkc;
- }
- hline(buf, x, y + size, x + size, color);
- if ( checkBit(segm_code, 0))
- {
- color = normc;
- }
- else
- {
- color = darkc;
- }
- hline(buf, x, y, x + size, color);
- if ( checkBit(segm_code, 3))
- {
- color = normc;
- }
- else
- {
- color = darkc;
- }
- hline(buf, x + size, y + 2 * size, x, color);
- if ( checkBit(segm_code, 7))
- {
- color = normc;
- }
- else
- {
- color = darkc;
- }
- putpixel(buf, x + size + 2, y + 2 * size, color);
- }
- void draw_LED_bin(BITMAP *buf, int x, int y, int color, BYTE code)
- {
- int darkc, normc;
- int i;
- normc = color;
- darkc = makecol(getr(normc) / 4, getg(normc) / 4, getb(normc) / 4);
- for ( i = 0 ; i < 8 ; i++ )
- {
- if ( checkBit(code, 7 - i))
- {
- color = normc;
- }
- else
- {
- color = darkc;
- }
- circlefill(buf, x + 7 * i, y, 2, color);
- }
- }
- void change_char(char *string, char ch, int pos)
- {
- string[pos - 1] = ch;
- }
- void insert_char(char *string, char ch, int pos, int lenght)
- {
- for ( int c = lenght ; c > pos ; c-- )
- {
- string[c - 1] = string[c - 2];
- }
- string[pos - 1] = ch;
- }
- void cut_char(char *string, int pos, int lenght)
- {
- for ( int c = pos ; c < lenght ; c++ )
- {
- string[c - 1] = string[c];
- }
- string[lenght - 1] = (char) ( 32 );
- }
- void change_ext(char *s)
- {
- int c;
- for ( c = 254 ; c >= 0 ; c-- )
- {
- if ( s[c] == '.' )
- {
- s[c + 1] = 'h';
- s[c + 2] = 'e';
- s[c + 3] = 'x';
- break;
- }
- }
- return;
- }
- void GetText(char *text, BITMAP *buf, int x, int y, int w, int h, int lenght, char *title)
- {
- int c;
- BITMAP *surface = create_bitmap(w, h);
- BITMAP *cache = create_bitmap(w, h);
- blit(buf, cache, x, y, 0, 0, w, h);
- clear(surface);
- hline(surface, 2, surface->h - 2, surface->w - 2, makecol(255, 255, 255));
- vline(surface, 2, 2, surface->h - 2, makecol(255, 255, 255));
- vline(surface, surface->w - 2, 2, surface->h - 2, makecol(255, 255, 255));
- for ( c = 2 ; c <= 2 + 10 ; c += 2 )
- {
- hline(surface, 2, c, surface->w - 2, makecol(255, 255, 255));
- }
- textprintf_centre(surface, mainf, surface->w / 2, 4, makecol(255, 255, 255), " %s ", title);
- text[0] = 32;
- for ( c = 1 ; c <= lenght - 1 ; c++ )
- {
- text[c] = 32;
- }
- text[lenght - 1] = 0;
- clear_keybuf();
- int pos = 1;
- WORD key_p;
- WORD key_ch;
- bool flag;
- while ( key[KEY_ENTER] )
- {
- }
- while ( !key[KEY_ENTER] )
- {
- textprintf(surface, mainf, 15, surface->h / 2, makecol(255, 255, 255), "%s", text);
- hline(surface, 15 + ( pos - 1 ) * 8, surface->h / 2 + 8, 15 + pos * 8, makecol(255, 255, 255));
- blit(surface, buf, 0, 0, x, y, w, h);
- hline(surface, 15 + ( pos - 1 ) * 8, surface->h / 2 + 8, 15 + pos * 8, makecol(0, 0, 0));
- key_p = readkey();
- key_ch = key_p & 0xff;
- key_p = key_p >> 8;
- flag = false;
- switch ( key_p )
- {
- case KEY_BACKSPACE:
- if ( pos > 1 )
- {
- pos--;
- cut_char(text, pos, lenght);
- text[lenght - 2] = 32;
- text[lenght - 1] = 0;
- }
- flag = true;
- break;
- case KEY_DEL:
- cut_char(text, pos, lenght);
- text[lenght - 2] = 32;
- text[lenght - 1] = 0;
- flag = true;
- break;
- case KEY_LEFT:
- if ( pos > 1 )
- { pos--; }
- flag = true;
- break;
- case KEY_RIGHT:
- if ( pos < lenght )
- { pos++; }
- flag = true;
- break;
- }
- if ( !key[KEY_ENTER] && key_ch != 0 && pos < lenght && !flag )
- {
- insert_char(text, key_ch, pos, lenght);
- pos++;
- text[lenght - 1] = 0;
- }
- }
- text[lenght - 1] = 0;
- blit(cache, buf, 0, 0, x, y, w, h);
- destroy_bitmap(cache);
- destroy_bitmap(surface);
- }
- void ShowMessage(char *text, BITMAP *buf, int x, int y, int w, int h, char *title)
- {
- BITMAP *surface = create_bitmap(w, h);
- BITMAP *cache = create_bitmap(w, h);
- blit(buf, cache, x, y, 0, 0, w, h);
- clear(surface);
- hline(surface, 2, surface->h - 2, surface->w - 2, makecol(255, 255, 255));
- vline(surface, 2, 2, surface->h - 2, makecol(255, 255, 255));
- vline(surface, surface->w - 2, 2, surface->h - 2, makecol(255, 255, 255));
- for ( int c = 2 ; c <= 2 + 10 ; c += 2 )
- {
- hline(surface, 2, c, surface->w - 2, makecol(255, 255, 255));
- }
- textprintf_centre(surface, mainf, surface->w / 2, 4, makecol(255, 255, 255), " %s ", title);
- textprintf(surface, mainf, 15, surface->h / 2, makecol(255, 255, 255), "%s", text);
- textprintf_centre(surface, mainf, surface->w / 2, surface->h - 16, makecol(255, 0, 0), "Press ENTER");
- blit(surface, buf, 0, 0, x, y, w, h);
- while ( key[KEY_ENTER] )
- {
- }
- while ( !key[KEY_ENTER] )
- {
- }
- blit(cache, buf, 0, 0, x, y, w, h);
- destroy_bitmap(cache);
- destroy_bitmap(surface);
- }
- bool QuestionBox(char *text, BITMAP *buf, int x, int y, int w, int h, char *title, int _color)
- {
- BITMAP *surface = create_bitmap(w, h);
- BITMAP *cache = create_bitmap(w, h);
- int len, c, line = 0, pos = 0;
- blit(buf, cache, x, y, 0, 0, w, h);
- clear(surface);
- hline(surface, 2, surface->h - 2, surface->w - 2, makecol(255, 255, 255));
- vline(surface, 2, 2, surface->h - 2, makecol(255, 255, 255));
- vline(surface, surface->w - 2, 2, surface->h - 2, makecol(255, 255, 255));
- for ( c = 2 ; c <= 2 + 10 ; c += 2 )
- {
- hline(surface, 2, c, surface->w - 2, makecol(255, 255, 255));
- }
- textprintf_centre(surface, mainf, surface->w / 2, 4, makecol(255, 255, 255), " %s ", title);
- textprintf_centre(surface, mainf, surface->w / 2, surface->h - 16, makecol(255, 0, 0),
- "Press ENTER (OK) or ESC (Cancel)");
- len = (int) strlen(text);
- for ( c = 0 ; c < len ; c++ )
- {
- if ( text[c] == 10 )
- {
- line++;
- pos = 0;
- }
- else
- {
- if ( text[c] != 13 )
- {
- if ( text[c] > 126 || text[c] < 32 )
- { break; }
- textprintf(surface, mainf, 15 + pos * 8, 20 + line * 10, _color, "%c", text[c]);
- pos++;
- }
- }
- }
- blit(surface, buf, 0, 0, x, y, w, h);
- while ( key[KEY_ENTER] || key[KEY_ESC] )
- {
- }
- while ( !( key[KEY_ENTER] || key[KEY_ESC] ))
- {
- }
- if ( key[KEY_ENTER] )
- {
- return true;
- }
- else
- {
- return false;
- }
- blit(cache, buf, 0, 0, x, y, w, h);
- destroy_bitmap(cache);
- destroy_bitmap(surface);
- }
- void ShowMsgEx(char *text, BITMAP *buf, int x, int y, int w, int h, char *title, int _color)
- {
- BITMAP *surface = create_bitmap(w, h);
- BITMAP *cache = create_bitmap(w, h);
- int len, c, line = 0, pos = 0;
- blit(buf, cache, x, y, 0, 0, w, h);
- clear(surface);
- hline(surface, 2, surface->h - 2, surface->w - 2, makecol(255, 255, 255));
- vline(surface, 2, 2, surface->h - 2, makecol(255, 255, 255));
- vline(surface, surface->w - 2, 2, surface->h - 2, makecol(255, 255, 255));
- for ( c = 2 ; c <= 2 + 10 ; c += 2 )
- {
- hline(surface, 2, c, surface->w - 2, makecol(255, 255, 255));
- }
- textprintf_centre(surface, mainf, surface->w / 2, 4, makecol(255, 255, 255), " %s ", title);
- textprintf_centre(surface, mainf, surface->w / 2, surface->h - 16, makecol(255, 0, 0), "Press ENTER");
- len = (int) strlen(text);
- for ( c = 0 ; c < len ; c++ )
- {
- if ( text[c] == 10 )
- {
- line++;
- pos = 0;
- }
- else
- {
- if ( text[c] != 13 )
- {
- if ( text[c] > 126 || text[c] < 32 )
- { break; }
- textprintf(surface, mainf, 15 + pos * 8, 20 + line * 10, _color, "%c", text[c]);
- pos++;
- }
- }
- }
- blit(surface, buf, 0, 0, x, y, w, h);
- while ( key[KEY_ENTER] )
- {
- }
- while ( !key[KEY_ENTER] )
- {
- }
- blit(cache, buf, 0, 0, x, y, w, h);
- destroy_bitmap(cache);
- destroy_bitmap(surface);
- }
- class code_editor
- {
- private:
- char *text_edit[65536];
- int lines;
- int cl, cp;
- int scl, scp;
- int _w, _h;
- public:
- code_editor(void);
- ~code_editor(void);
- bool alloc_new_line(void); // ret. true on success
- bool insert_new_line(int ln);
- void delete_last(void);
- void cut_line(int ln);
- void insert_char(int ln, char ch);
- void replace_char(int ln, char ch);
- void backspace(void);
- void del_ch(int ln);
- void draw_cr(void);
- void clear_cr(void);
- void load_source(char *filename);
- void save_source(char *filename);
- int compile(int *err); // out-num errors, in-table of int's
- // thet represtents lines with errors
- // (automactly allocated)
- int left, top;
- int tab_size;
- BITMAP *surface;
- void process(void);
- void disp(void);
- };
- void code_editor::load_source(char *filename)
- {
- FILE *strin;
- int c, i, tp, j = 0;
- strin = NULL;
- strin = fopen(filename, "rb");
- lines = 0;
- if ( strin == NULL )
- { ShowMessage("Can't open the file", screen, 200, 200, 200, 60, "Message!"); }
- else
- {
- //for (c=0;c<65535;c++)
- //{
- // if (text_edit[c]!=NULL) delete[] text_edit[c];
- // else break;
- //}
- while ( !feof(strin))
- {
- alloc_new_line();
- for ( i = 0 ; ( i < 256 ) && !feof(strin) ; i++ )
- {
- c = fgetc(strin);
- if ( c == 9 ) //TAB
- {
- tp = i / tab_size;
- tp++;
- tp *= 8;
- for ( i ; i <= tp ; i++ )
- { text_edit[j][i] = 32; }
- i--;
- }
- else
- {
- if (( c == 10 ) || ( c == 13 ))
- {
- if ( c == 13 )
- { fgetc(strin); }
- for ( i ; i < 256 ; i++ )
- {
- text_edit[j][i] = 10;
- }
- }
- else
- { text_edit[j][i] = c == -1 ? 10 : c; }
- }
- }
- j++;
- }
- lines = j;
- fclose(strin);
- }
- cp = 0;
- cl = 0;
- scp = 0;
- scl = 0;
- disp();
- }
- void code_editor::disp(void)
- {
- int i, j, cnti, cntj = 0;
- for ( j = cl - scl ; j < cl - scl + _h + 1 && cntj < lines ; j++ )
- {
- cnti = 0;
- bool endf = false;
- for ( i = cp - scp ; i < cp - scp + _w && !endf ; i++ )
- {
- if ( text_edit[j][i] == 10 || text_edit[j][i] == 0 || text_edit[j][i] == 13 )
- { endf = true; }
- else
- {
- textprintf(surface, mainf, left + cnti * 8, top + cntj * 10, makecol(255, 255, 255), "%c",
- text_edit[j][i]);
- cnti++;
- }
- }
- for ( i ; i < cp - scp + _w + 1 ; i++ )
- {
- textprintf(surface, mainf, left + cnti * 8, top + cntj * 10, makecol(255, 255, 255), " ");
- cnti++;
- }
- cntj++;
- }
- if ( cntj < _h )
- { rectfill(surface, left, top + cntj * 10, surface->w - left, surface->h - left, 0); }
- }
- void code_editor::process(void)
- {
- BITMAP *cache;
- int c, i;
- bool exit_ed = false;
- char *filen;
- filen = new char[256];
- cache = create_bitmap(SCREEN_W, SCREEN_H);
- blit(screen, cache, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
- clear(surface);
- hline(surface, 2, surface->h - 2, surface->w - 2, makecol(255, 255, 255));
- vline(surface, 2, 2, surface->h - 2, makecol(255, 255, 255));
- vline(surface, surface->w - 2, 2, surface->h - 2, makecol(255, 255, 255));
- for ( c = 2 ; c <= 2 + 10 ; c += 2 )
- {
- hline(surface, 2, c, surface->w - 2, makecol(255, 255, 255));
- }
- textprintf_centre(surface, mainf, surface->w / 2, 4, makecol(255, 255, 255), " Source editor ");
- lines = 0;
- alloc_new_line();
- WORD key_p;
- WORD key_ch;
- while ( !exit_ed )
- {
- key_p = readkey();
- key_ch = key_p & 0xff;
- key_p = key_p >> 8;
- switch ( key_p )
- {
- case KEY_BACKSPACE:
- if ( cp > 0 )
- {
- clear_cr();
- if ( scp > 0 )
- { scp--; }
- cp--;
- backspace();
- }
- else
- {
- if ( cl > 0 )
- {
- clear_cr();
- for ( c = 0 ; ( c < 256 ) && ( text_edit[cl - 1][c] != 10 ) ; c++ )
- {
- }
- cp = c;
- scp = cp;
- if ( scp >= _w )
- { scp = _w - 1; }
- for ( c ; c < 256 ; c++ )
- {
- text_edit[cl - 1][c] = text_edit[cl][c - cp];
- if ( text_edit[cl][c - cp] == 10 )
- { break; }
- }
- delete[]text_edit[cl];
- for ( i = cl ; i < lines ; i++ )
- { text_edit[i] = text_edit[i + 1]; }
- lines--;
- text_edit[lines] = NULL;
- cl--;
- if ( scl > 0 )
- { scl--; }
- }
- }
- break;
- case KEY_DEL:
- backspace();
- break;
- case KEY_ENTER:
- if ( cl < 65536 )
- {
- clear_cr();
- cl++;
- if ( scl < _h )
- { scl++; }
- if ( !insert_new_line(cl))
- {
- ShowMessage("Out of memory", surface, 200, 100, 200, 60, "Error!");
- }
- else
- {
- for ( c = cp ; c < 256 ; c++ )
- {
- text_edit[cl][c - cp] = text_edit[cl - 1][c];
- text_edit[cl - 1][c] = 10;
- }
- cp = 0;
- scp = 0;
- }
- }
- else
- { ShowMessage("Source can't has more then 65536 lines of code!!!", surface, 200, 100, 200, 60, "Error!"); }
- break;
- case KEY_END:
- clear_cr();
- for ( cp = 0 ; cp < 256 && text_edit[cl][cp] != 10 ; cp++ )
- {
- }
- scp = cp;
- if ( scp >= _w )
- { scp = _w - 1; }
- break;
- case KEY_HOME:
- clear_cr();
- cp = 0;
- scp = 0;
- break;
- case KEY_LEFT:
- if ( cp > 0 )
- {
- clear_cr();
- cp--;
- if ( scp > 0 )
- { scp--; }
- }
- else
- {
- if ( cl > 0 )
- {
- clear_cr();
- for ( c = 0 ; ( c < 256 ) && ( text_edit[cl - 1][c] != 10 ) ; c++ )
- {
- }
- cp = c;
- scp = cp;
- if ( scp >= _w )
- { scp = _w - 1; }
- cl--;
- if ( scl > 0 )
- { scl--; }
- }
- }
- break;
- case KEY_RIGHT:
- if ( cp < 256 && text_edit[cl][cp] != 10 )
- {
- clear_cr();
- cp++;
- if ( scp < _w )
- { scp++; }
- }
- else
- {
- if ( cl + 1 < lines )
- {
- clear_cr();
- cp = 0;
- scp = cp;
- if ( scp >= _w )
- { scp = _w - 1; }
- cl++;
- if ( scl < _h )
- { scl++; }
- }
- }
- break;
- case KEY_UP:
- if ( cl > 0 )
- {
- clear_cr();
- cl--;
- if ( scl > 0 )
- { scl--; }
- for ( c = 0 ; c < 256 && text_edit[cl][c] != 10 ; c++ )
- {
- }
- if ( c - 1 < cp )
- {
- cp = c;
- scp = cp;
- if ( scp >= _w )
- { scp = _w - 1; }
- }
- }
- break;
- case KEY_DOWN:
- if ( cl < 65536 && cl < ( lines - 1 ))
- {
- clear_cr();
- cl++;
- if ( scl < _h )
- { scl++; }
- for ( c = 0 ; c < 256 && text_edit[cl][c] != 10 ; c++ )
- {
- }
- if ( c - 1 < cp )
- {
- cp = c;
- scp = cp;
- if ( scp >= _w )
- { scp = _w - 1; }
- }
- }
- break;
- case KEY_ESC:
- if ( QuestionBox("Are you sure want to EXIT?", screen, 200, 200, 400, 60, "Confirm!", makecol(255, 0, 0)))
- {
- exit_ed = true;
- for ( c = 0 ; c < lines ; c++ )
- {
- if ( text_edit[c] != NULL )
- {
- delete[] text_edit[c];
- }
- }
- lines = 0;
- }
- else
- {
- rest(500);
- clear_keybuf();
- }
- break;
- case KEY_F3:
- GetText(filen, screen, 100, 200, 600, 60, 256, " Enter source code file name ");
- for ( c = 254 ; filen[c] == ' ' || filen[c] == '\r' ; c-- )
- {
- filen[c] = 0;
- }
- load_source(filen);
- break;
- default:
- if ( key_ch != 0 && cp < 256 )
- {
- insert_char(cl, key_ch);
- clear_cr();
- cp++;
- if ( scp < _w )
- { scp++; }
- key_ch = 0;
- }
- break;
- }
- if ( !exit_ed )
- {
- disp();
- draw_cr();
- }
- 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);
- blit(surface, screen, 0, 0, 0, 0, surface->w, surface->h);
- }
- blit(cache, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
- destroy_bitmap(cache);
- delete[] filen;
- return;
- }
- void code_editor::insert_char(int ln, char ch)
- {
- int i;
- for ( i = 256 ; i > cp ; i-- )
- {
- text_edit[cl][i] = text_edit[cl][i - 1];
- }
- text_edit[cl][cp] = ch;
- }
- void code_editor::backspace(void)
- {
- int i;
- for ( i = cp ; i < 256 ; i++ )
- {
- text_edit[cl][i] = text_edit[cl][i + 1];
- }
- }
- void code_editor::draw_cr(void)
- {
- hline(surface, left + 8 * scp, top + 10 * scl + 9, left + 8 * scp + 8, makecol(255, 255, 255));
- }
- void code_editor::clear_cr(void)
- {
- hline(surface, left + 8 * scp, top + 10 * scl + 9, left + 8 * scp + 8, 0);
- }
- code_editor::code_editor(void)
- {
- int i;
- for ( i = 0 ; i < 65536 ; i++ )
- {
- text_edit[i] = NULL;
- }
- lines = 0;
- top = 24;
- left = 11;
- cl = 0;
- cp = 0;
- scl = 0;
- scp = 0;
- surface = create_bitmap(SCREEN_W, SCREEN_H - 100);
- _w = ( surface->w - left * 2 ) / 8 - 1;
- _h = ( surface->h - top - left ) / 10 - 1;
- tab_size = 8;
- }
- code_editor::~code_editor(void)
- {
- }
- bool code_editor::alloc_new_line(void)
- {
- int i;
- if ( lines < 65536 )
- {
- text_edit[lines] = new char[256];
- for ( i = 0 ; i < 256 ; i++ )
- { text_edit[lines][i] = 10; }
- lines++;
- return text_edit[lines] == NULL ? false : true;
- }
- return false;
- }
- bool code_editor::insert_new_line(int ln)
- {
- int i;
- if ( lines < 65536 )
- {
- for ( i = lines ; i > ln ; i-- )
- { text_edit[i] = text_edit[i - 1]; }
- text_edit[ln] = NULL;
- text_edit[ln] = new char[256];
- for ( i = 0 ; i < 256 ; i++ )
- { text_edit[ln][i] = 10; }
- lines++;
- if ( text_edit[ln] == NULL )
- {
- for ( i = ln ; i < lines ; i++ )
- { text_edit[i] = text_edit[i + 1]; }
- lines--;
- return false;
- }
- else
- { return true; }
- }
- return false;
- }
- void code_editor::delete_last(void)
- {
- lines--;
- delete[] text_edit[lines];
- text_edit[lines] = NULL;
- }
- void code_editor::cut_line(int ln)
- {
- int i;
- if ( text_edit[ln] != NULL )
- {
- for ( i = ln ; i < lines ; i++ )
- { text_edit[i] = text_edit[i + 1]; }
- lines--;
- }
- }
- #endif // __MARIO_GUI
|