diff options
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/macgui/mactextwindow.cpp | 54 | ||||
-rw-r--r-- | graphics/macgui/mactextwindow.h | 15 | ||||
-rw-r--r-- | graphics/macgui/macwindowmanager.cpp | 19 | ||||
-rw-r--r-- | graphics/macgui/macwindowmanager.h | 6 |
4 files changed, 86 insertions, 8 deletions
diff --git a/graphics/macgui/mactextwindow.cpp b/graphics/macgui/mactextwindow.cpp index 19ed9a8398..c34f428611 100644 --- a/graphics/macgui/mactextwindow.cpp +++ b/graphics/macgui/mactextwindow.cpp @@ -27,14 +27,18 @@ namespace Graphics { -MacTextWindow::MacTextWindow(MacWindowManager *wm, const MacFont *font, int fgcolor, - int bgcolor, int maxWidth, TextAlign textAlignment) : +MacTextWindow::MacTextWindow(MacWindowManager *wm, const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment) : MacWindow(wm->getNextId(), true, true, true, wm) { wm->addWindowInitialized(this); _font = font; _mactext = new MacText("", _wm, font, fgcolor, bgcolor, maxWidth, textAlignment); + + _fontRef = wm->_fontMan->getFont(*font); + + _inputTextHeight = 0; + _maxWidth = maxWidth; } void MacTextWindow::drawText(ManagedSurface *g, int x, int y, int w, int h, int xoff, int yoff) { @@ -67,4 +71,50 @@ const MacFont *MacTextWindow::getTextWindowFont() { return _font; } +bool MacTextWindow::processEvent(Common::Event &event) { + WindowClick click = isInBorder(event.mouse.x, event.mouse.y); + + if (event.type == Common::EVENT_KEYDOWN) { + switch (event.kbd.keycode) { + case Common::KEYCODE_BACKSPACE: + if (!_inputText.empty()) { + _inputText.deleteLastChar(); + drawInput(); + } + break; + + case Common::KEYCODE_RETURN: + return false; // Pass it to the higher level for processing + + default: + if (event.kbd.ascii == '~') + return false; + + if (event.kbd.ascii >= 0x20 && event.kbd.ascii <= 0x7f) { + _inputText += (char)event.kbd.ascii; + drawInput(); + } + + break; + } + } + + return false; +} + +void MacTextWindow::drawInput() { + // First, we kill previous input text + for (uint i = 0; i < _inputTextHeight; i++) + _mactext->removeLastLine(); + + Common::Array<Common::String> text; + + // Now recalc new text height + _fontRef->wordWrapText(_inputText, _maxWidth, text); + _inputTextHeight = text.size(); + + // And add new input line to the text + appendText(_inputText, _font); +} + } // End of namespace Graphics diff --git a/graphics/macgui/mactextwindow.h b/graphics/macgui/mactextwindow.h index 11b845f840..dcefa005f2 100644 --- a/graphics/macgui/mactextwindow.h +++ b/graphics/macgui/mactextwindow.h @@ -44,9 +44,10 @@ struct SelectedText { class MacTextWindow : public MacWindow { public: - MacTextWindow(MacWindowManager *wm, const MacFont *font, int fgcolor, - int bgcolor, int maxWidth, TextAlign textAlignment); - ~MacTextWindow(); + MacTextWindow(MacWindowManager *wm, const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment); + virtual ~MacTextWindow(); + + virtual bool processEvent(Common::Event &event); const MacFont *getTextWindowFont(); @@ -58,10 +59,18 @@ public: void setSelection(int selStartX, int selStartY, int selEndX, int selEndY); private: + void drawInput(); + +private: MacText *_mactext; const MacFont *_font; + const Font *_fontRef; SelectedText _selectedText; + + int _maxWidth; + Common::String _inputText; + uint _inputTextHeight; }; } // End of namespace Graphics diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp index b64ff1048f..1e4c49fa76 100644 --- a/graphics/macgui/macwindowmanager.cpp +++ b/graphics/macgui/macwindowmanager.cpp @@ -31,6 +31,7 @@ #include "graphics/macgui/macwindowmanager.h" #include "graphics/macgui/macfontmanager.h" #include "graphics/macgui/macwindow.h" +#include "graphics/macgui/mactextwindow.h" #include "graphics/macgui/macmenu.h" namespace Graphics { @@ -183,6 +184,18 @@ MacWindow *MacWindowManager::addWindow(bool scrollable, bool resizable, bool edi return w; } +MacTextWindow *MacWindowManager::addTextWindow(const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment) { + MacTextWindow *w = new MacTextWindow(this, font, fgcolor, bgcolor, maxWidth, textAlignment); + + _windows.push_back(w); + _windowStack.push_back(w); + + setActive(getNextId()); + + return w; +} + + void MacWindowManager::addWindowInitialized(MacWindow *macwindow) { _windows.push_back(macwindow); _windowStack.push_back(macwindow); @@ -300,7 +313,7 @@ bool MacWindowManager::processEvent(Common::Event &event) { return true; if (event.type != Common::EVENT_MOUSEMOVE && event.type != Common::EVENT_LBUTTONDOWN && - event.type != Common::EVENT_LBUTTONUP) + event.type != Common::EVENT_LBUTTONUP && event.type != Common::EVENT_KEYDOWN) return false; if (_windows[_activeWindow]->isEditable() && _windows[_activeWindow]->getType() == kWindowWindow && @@ -320,8 +333,8 @@ bool MacWindowManager::processEvent(Common::Event &event) { it--; BaseMacWindow *w = *it; - - if (w->hasAllFocus() || w->getDimensions().contains(event.mouse.x, event.mouse.y)) { + if (w->hasAllFocus() || (w->isEditable() && event.type == Common::EVENT_KEYDOWN) || + w->getDimensions().contains(event.mouse.x, event.mouse.y)) { if (event.type == Common::EVENT_LBUTTONDOWN || event.type == Common::EVENT_LBUTTONUP) setActive(w->getId()); diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h index ec7f4f1341..61f4899481 100644 --- a/graphics/macgui/macwindowmanager.h +++ b/graphics/macgui/macwindowmanager.h @@ -27,6 +27,7 @@ #include "common/list.h" #include "common/events.h" +#include "graphics/font.h" #include "graphics/fontman.h" #include "graphics/macgui/macwindow.h" @@ -60,6 +61,9 @@ using namespace MacGUIConstants; class ManagedSurface; class MacMenu; +class MacTextWindow; + +class MacFont; class MacFontManager; @@ -103,6 +107,8 @@ public: * @return Pointer to the newly created window. */ MacWindow *addWindow(bool scrollable, bool resizable, bool editable); + MacTextWindow *addTextWindow(const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment); + /** * Adds a window that has already been initialized to the registry. * Like addWindow, but this doesn't create/allocate the Window. |