X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fgui%2Ftextedit.cpp;fp=src%2Fgui%2Ftextedit.cpp;h=301dd3e1937ad8d0d328849151ed2c361c2d9fa8;hb=f9098d0570ae6462781e8189518085cb1c8c00ef;hp=0000000000000000000000000000000000000000;hpb=836c7fa1f3e2dc3ec9849cac2584d4544bf2fba4;p=virtualjaguar diff --git a/src/gui/textedit.cpp b/src/gui/textedit.cpp new file mode 100644 index 0000000..301dd3e --- /dev/null +++ b/src/gui/textedit.cpp @@ -0,0 +1,52 @@ +// +// TextEdit class +// +// by James L. Hammons +// + +#include "textedit.h" + +#include "guimisc.h" + +TextEdit::TextEdit(uint32 x/*= 0*/, uint32 y/*= 0*/, uint32 w/*= 0*/, uint32 h/*= 0*/): + Element(x, y, w, h), fgColor(0xFF8484FF), bgColor(0xFF84FF4D), text(""), + caretPos(0), maxScreenSize(10) +{ +} + +TextEdit::TextEdit(uint32 x, uint32 y, std::string s, uint32 mss/*= 10*/, uint32 fg/*= 0xFF8484FF*/, uint32 bg/*= 0xFF84FF4D*/): + Element(x, y, 0, 0), fgColor(fg), bgColor(bg), text(s), caretPos(0), maxScreenSize(mss) +{ +} + +//Set different filters depending on type passed in on construction, e.g., filename, amount, etc...? +void TextEdit::HandleKey(SDLKey key) +{ + if ((key >= SDLK_a && key <= SDLK_z) || (key >= SDLK_0 && key <= SDLK_9) || key == SDLK_PERIOD + || key == SDLK_SLASH) + { + //Need to handle shift key as well... + text[caretPos++] = key; + Draw(); + } + else if (key == SDLK_BACKSPACE) + { + + } + else if (key == SDLK_DELETE) + { + } +//left, right arrow +} + +void TextEdit::Draw(uint32 offsetX/*= 0*/, uint32 offsetY/*= 0*/) +{ + if (text.length() > 0) + { + FillScreenRectangle(screenBuffer, extents.x + offsetX, extents.y + offsetY, FONT_WIDTH * maxScreenSize, FONT_HEIGHT, bgColor); +// DrawString(screenBuffer, extents.x + offsetX, extents.y + offsetY, false, "%s", text.c_str()); + DrawStringOpaque(screenBuffer, extents.x + offsetX, extents.y + offsetY, fgColor, bgColor, "%s", text.c_str()); + } + + // Draw the caret (underscore? or vertical line?) +}