]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/textedit.cpp
Major refactoring of GUI: Phase I
[virtualjaguar] / src / gui / textedit.cpp
1 //
2 // TextEdit class
3 //
4 // by James L. Hammons
5 //
6
7 #include "textedit.h"
8
9 #include "guimisc.h"
10
11 TextEdit::TextEdit(uint32 x/*= 0*/, uint32 y/*= 0*/, uint32 w/*= 0*/, uint32 h/*= 0*/):
12         Element(x, y, w, h), fgColor(0xFF8484FF), bgColor(0xFF84FF4D), text(""),
13         caretPos(0), maxScreenSize(10)
14 {
15 }
16
17 TextEdit::TextEdit(uint32 x, uint32 y, std::string s, uint32 mss/*= 10*/, uint32 fg/*= 0xFF8484FF*/, uint32 bg/*= 0xFF84FF4D*/):
18         Element(x, y, 0, 0), fgColor(fg), bgColor(bg), text(s), caretPos(0), maxScreenSize(mss)
19 {
20 }
21
22 //Set different filters depending on type passed in on construction, e.g., filename, amount, etc...?
23 void TextEdit::HandleKey(SDLKey key)
24 {
25         if ((key >= SDLK_a && key <= SDLK_z) || (key >= SDLK_0 && key <= SDLK_9) || key == SDLK_PERIOD
26                 || key == SDLK_SLASH)
27         {
28                 //Need to handle shift key as well...
29                 text[caretPos++] = key;
30                 Draw();
31         }
32         else if (key == SDLK_BACKSPACE)
33         {
34
35         }
36         else if (key == SDLK_DELETE)
37         {
38         }
39 //left, right arrow
40 }
41
42 void TextEdit::Draw(uint32 offsetX/*= 0*/, uint32 offsetY/*= 0*/)
43 {
44         if (text.length() > 0)
45         {
46                 FillScreenRectangle(screenBuffer, extents.x + offsetX, extents.y + offsetY, FONT_WIDTH * maxScreenSize, FONT_HEIGHT, bgColor);
47 //              DrawString(screenBuffer, extents.x + offsetX, extents.y + offsetY, false, "%s", text.c_str());
48                 DrawStringOpaque(screenBuffer, extents.x + offsetX, extents.y + offsetY, fgColor, bgColor, "%s", text.c_str());
49         }
50
51         // Draw the caret (underscore? or vertical line?)
52 }