ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

edittext.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "common/system.h"
00024 #include "gui/widgets/edittext.h"
00025 #include "gui/gui-manager.h"
00026 
00027 #include "gui/ThemeEval.h"
00028 
00029 namespace GUI {
00030 
00031 EditTextWidget::EditTextWidget(GuiObject *boss, int x, int y, int w, int h, const String &text, const char *tooltip, uint32 cmd, uint32 finishCmd)
00032     : EditableWidget(boss, x, y - 1, w, h + 2, tooltip, cmd) {
00033     setFlags(WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE);
00034     _type = kEditTextWidget;
00035     _finishCmd = finishCmd;
00036 
00037     setEditString(text);
00038     setFontStyle(ThemeEngine::kFontStyleNormal);
00039 
00040     _leftPadding = _rightPadding = 0;
00041 }
00042 
00043 EditTextWidget::EditTextWidget(GuiObject *boss, const String &name, const String &text, const char *tooltip, uint32 cmd, uint32 finishCmd)
00044     : EditableWidget(boss, name, tooltip, cmd) {
00045     setFlags(WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE);
00046     _type = kEditTextWidget;
00047     _finishCmd = finishCmd;
00048 
00049     setEditString(text);
00050     setFontStyle(ThemeEngine::kFontStyleNormal);
00051 
00052     _leftPadding = _rightPadding = 0;
00053 }
00054 
00055 void EditTextWidget::setEditString(const String &str) {
00056     EditableWidget::setEditString(str);
00057     _backupString = str;
00058 }
00059 
00060 void EditTextWidget::reflowLayout() {
00061     _leftPadding = g_gui.xmlEval()->getVar("Globals.EditTextWidget.Padding.Left", 0);
00062     _rightPadding = g_gui.xmlEval()->getVar("Globals.EditTextWidget.Padding.Right", 0);
00063 
00064     EditableWidget::reflowLayout();
00065 }
00066 
00067 void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount) {
00068     if (!isEnabled())
00069         return;
00070 
00071     // First remove caret
00072     if (_caretVisible)
00073         drawCaret(true);
00074 
00075     x += _editScrollOffset;
00076 
00077     int width = 0;
00078     uint i;
00079 
00080     uint last = 0;
00081     for (i = 0; i < _editString.size(); ++i) {
00082         const uint cur = _editString[i];
00083         width += g_gui.getCharWidth(cur, _font) + g_gui.getKerningOffset(last, cur, _font);
00084         if (width >= x)
00085             break;
00086         last = cur;
00087     }
00088     if (setCaretPos(i))
00089         markAsDirty();
00090 }
00091 
00092 void EditTextWidget::drawWidget() {
00093     g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), 0,
00094                                         ThemeEngine::kWidgetBackgroundEditText);
00095 
00096     // Draw the text
00097     adjustOffset();
00098 
00099     const Common::Rect &r = Common::Rect(_x + 2 + _leftPadding, _y + 2, _x + _leftPadding + getEditRect().width() + 8, _y + _h);
00100     setTextDrawableArea(r);
00101 
00102     g_gui.theme()->drawText(
00103             Common::Rect(_x + 2 + _leftPadding, _y + 2, _x + _leftPadding + getEditRect().width() + 2, _y + _h),
00104             _editString, _state, Graphics::kTextAlignLeft, ThemeEngine::kTextInversionNone,
00105             -_editScrollOffset, false, _font, ThemeEngine::kFontColorNormal, true, _textDrawableArea);
00106 }
00107 
00108 Common::Rect EditTextWidget::getEditRect() const {
00109     Common::Rect r(2 + _leftPadding, 2, _w - 2 - _leftPadding - _rightPadding, _h);
00110 
00111     return r;
00112 }
00113 
00114 void EditTextWidget::receivedFocusWidget() {
00115     g_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, true);
00116 }
00117 
00118 void EditTextWidget::lostFocusWidget() {
00119     // If we loose focus, 'commit' the user changes
00120     _backupString = _editString;
00121     drawCaret(true);
00122 
00123     g_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);
00124 }
00125 
00126 void EditTextWidget::startEditMode() {
00127 }
00128 
00129 void EditTextWidget::endEditMode() {
00130     releaseFocus();
00131 
00132     sendCommand(_finishCmd, 0);
00133 }
00134 
00135 void EditTextWidget::abortEditMode() {
00136     setEditString(_backupString);
00137     sendCommand(_cmd, 0);
00138 
00139     releaseFocus();
00140 }
00141 
00142 } // End of namespace GUI


Generated on Sat Sep 14 2019 05:01:33 for ResidualVM by doxygen 1.7.1
curved edge   curved edge