From: <js...@us...> - 2004-12-27 08:03:09
|
Update of /cvsroot/exult/exult/gumps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19651/gumps Modified Files: Notebook_gump.cc Notebook_gump.h Log Message: Starting to insert chars. in notebook Index: Notebook_gump.cc =================================================================== RCS file: /cvsroot/exult/exult/gumps/Notebook_gump.cc,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- Notebook_gump.cc 27 Dec 2004 01:25:07 -0000 1.8 +++ Notebook_gump.cc 27 Dec 2004 08:02:49 -0000 1.9 @@ -29,7 +29,7 @@ vector<One_note *> Notebook_gump::notes; bool Notebook_gump::initialized = false; // Set when read in. -vector<Notebook_top_left> Notebook_gump::page_info; +vector<Notebook_top> Notebook_gump::page_info; /* * Defines in 'gumps.vga': @@ -59,6 +59,37 @@ delete text; text = txt; textlen = text ? strlen(text) : 0; + textmax = text ? textlen + 1 : 0; + } + +/* + * Insert one character. + */ + +void One_note::insert + ( + int chr, + int offset + ) + { + if (textlen + 1 >= textmax) + { // Need more space. + textmax = textmax ? (textmax + textmax/4 + 1) : 16; + char *newtext = new char[textmax]; + memcpy(newtext, text, offset); + newtext[offset] = chr; + memcpy(newtext + offset + 1, text + offset, + textlen + 1 - offset); + delete [] text; + text = newtext; + } + else + { + memmove(text + offset + 1, text + offset, + textlen + 1 - offset); + text[offset] = chr; + } + ++textlen; } /* @@ -116,7 +147,7 @@ cursor.offset = 0; // (Obj. area doesn't matter.) set_object_area(Rectangle(36, 10, 100, 100), 7, 40); - page_info.push_back(Notebook_top_left(0, 0)); + page_info.push_back(Notebook_top(0, 0)); // Where to paint page marks: const int lpagex = 35, rpagex = 300, lrpagey = 12; leftpage = new Notebook_page_button(this, lpagex, lrpagey, 0); @@ -201,10 +232,10 @@ int topleft = curpage & ~1; if (delta > 0) { - int nxt = curpage/2 + 1; + int nxt = topleft + 2; if (nxt >= page_info.size()) return; - curpage = topleft + 2; + curpage = nxt; cursor.offset = 0; } else if (delta < 0) @@ -236,17 +267,18 @@ return leftpage; else if (rightpage->on_button(mx, my)) return rightpage; - int curnote = page_info[curpage/2].notenum; + int topleft = curpage & ~1; + int curnote = page_info[topleft].notenum; if (curnote < 0) return 0; - int offset = page_info[curpage/2].offset; + int offset = page_info[topleft].offset; Rectangle box = Get_text_area(false, offset == 0); // Left page. One_note *note = notes[curnote]; int coff = sman->find_cursor(font, note->text + offset, x + box.x, y + box.y, box.w, box.h, mx, my, vlead); if (coff >= 0) // Found it? { - curpage = curpage & ~1; + curpage = topleft; cursor.offset = offset + coff; paint(); } @@ -284,12 +316,12 @@ Gump::paint(); if (curpage > 0) // Not the first? leftpage->paint(); - int curnote = page_info[curpage/2].notenum; + int topleft = curpage & ~1; + int curnote = page_info[topleft].notenum; if (curnote < 0) return; - int offset = page_info[curpage/2].offset; + int offset = page_info[topleft].offset; One_note *note = notes[curnote]; - int topleft = curpage & ~1; // Paint left page. offset = paint_page(Get_text_area(false, offset == 0), note, offset, topleft); @@ -301,6 +333,10 @@ note = notes[curnote]; offset = 0; } + if (topleft + 1 >= page_info.size()) // Store right-page info. + page_info.resize(topleft + 2); + page_info[topleft + 1].notenum = curnote; + page_info[topleft + 1].offset = offset; // Paint right page. offset = paint_page(Get_text_area(true, offset == 0), note, offset, topleft + 1); @@ -312,7 +348,7 @@ offset = 0; } rightpage->paint(); - int nxt = curpage/2 + 1; // For next pair of pages. + int nxt = topleft + 2; // For next pair of pages. if (nxt >= page_info.size()) page_info.resize(nxt + 1); page_info[nxt].notenum = curnote; @@ -328,10 +364,46 @@ ) { SDL_Event& ev = *(SDL_Event *)vev; - int chr = ev.key.keysym.sym, uchr = ev.key.keysym.unicode; + int chr = ev.key.keysym.sym, unicode = ev.key.keysym.unicode; - if (ev.type != SDL_KEYDOWN && ev.type != SDL_KEYUP) + if (ev.type == SDL_KEYUP) + return true; // Ignoring key-up at present. + if (ev.type != SDL_KEYDOWN) return false; + if (curpage >= page_info.size()) + return false; // Shouldn't happen. + One_note *note = notes[page_info[curpage].notenum]; + switch (chr) { + case SDLK_RETURN: // If only 'Save', do it. + case SDLK_BACKSPACE: + case SDLK_DELETE: + case SDLK_LEFT: + case SDLK_RIGHT: + case SDLK_UP: + case SDLK_DOWN: + case SDLK_HOME: + case SDLK_END: + // ++++++Finish. + break; + default: +#if 0 /* +++++Got to enable unicode for this. */ + if ((unicode & 0xFF80) == 0 ) + chr = unicode & 0x7F; + else + chr = 0; +#else + if (ev.key.keysym.mod & KMOD_SHIFT) + chr = toupper(chr); +#endif + if (chr < ' ') + return false; // Ignore other special chars. + if (chr >= 256 || !isascii(chr)) + return false; + note->insert(chr, cursor.offset); + ++cursor.offset; + paint(); // (Not very efficient...) + break; + } // ++++++Finish. std::cout << "Notebook chr: " << chr << std::endl; return true; Index: Notebook_gump.h =================================================================== RCS file: /cvsroot/exult/exult/gumps/Notebook_gump.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Notebook_gump.h 27 Dec 2004 01:25:07 -0000 1.6 +++ Notebook_gump.h 27 Dec 2004 08:02:50 -0000 1.7 @@ -31,28 +31,30 @@ int lat, lng; // Latitute, longitude where written. char *text; // Text, 0-delimited. int textlen; // Length, not counting ending NULL. + int textmax; // Max. space. public: friend class Notebook_gump; One_note() : day(0), hour(0), minute(0), lat(0), lng(0), - text(0), textlen(0) + text(0), textlen(0), textmax(0) { } void set(int d, int h, int m, int la, int ln, char *txt = 0); One_note(int d, int h, int m, int la, int ln, char *txt = 0) : text(0) { set(d, h, m, la, ln, txt); } ~One_note() { delete [] text; } + void insert(int chr, int offset); // Insert text. }; /* - * Info. for top left page. + * Info. for top of a page. */ -class Notebook_top_left +class Notebook_top { int notenum; int offset; public: friend class Notebook_gump; - Notebook_top_left(int n = 0, int o = 0) : notenum(n), offset(o) + Notebook_top(int n = 0, int o = 0) : notenum(n), offset(o) { } }; @@ -63,8 +65,8 @@ { UNREPLICATABLE_CLASS(Notebook_gump); static vector<One_note *> notes;// The text. - // Indexed by page#/2: - static vector<Notebook_top_left> page_info; + // Indexed by page#. + static vector<Notebook_top> page_info; static bool initialized; int curpage; // Current page # (from 0). Cursor_info cursor; // Cursor loc. within current page. |