1 /** @file lineeditwidget.h UI widget for an editable line of text. 2 * 3 * @authors Copyright © 2005-2017 Jaakko Keränen <jaakko.keranen@iki.fi> 4 * @authors Copyright © 2005-2014 Daniel Swanson <danij@dengine.net> 5 * 6 * @par License 7 * GPL: http://www.gnu.org/licenses/gpl.html 8 * 9 * <small>This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by the 11 * Free Software Foundation; either version 2 of the License, or (at your 12 * option) any later version. This program is distributed in the hope that it 13 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 15 * Public License for more details. You should have received a copy of the GNU 16 * General Public License along with this program; if not, write to the Free 17 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 18 * 02110-1301 USA</small> 19 */ 20 21 #ifndef LIBCOMMON_UI_LINEEDITWIDGET 22 #define LIBCOMMON_UI_LINEEDITWIDGET 23 24 #include <de/String> 25 #include "widget.h" 26 27 namespace common { 28 namespace menu { 29 30 #if __JDOOM__ || __JDOOM64__ 31 # define MNDATA_EDIT_TEXT_COLORIDX (0) 32 # define MNDATA_EDIT_OFFSET_X (0) 33 # define MNDATA_EDIT_OFFSET_Y (0) 34 # define MNDATA_EDIT_BACKGROUND_OFFSET_X (-11) 35 # define MNDATA_EDIT_BACKGROUND_OFFSET_Y (-4) 36 # define MNDATA_EDIT_BACKGROUND_PATCH_LEFT ("M_LSLEFT") 37 # define MNDATA_EDIT_BACKGROUND_PATCH_RIGHT ("M_LSRGHT") 38 # define MNDATA_EDIT_BACKGROUND_PATCH_MIDDLE ("M_LSCNTR") 39 #elif __JHERETIC__ || __JHEXEN__ 40 # define MNDATA_EDIT_TEXT_COLORIDX (2) 41 # define MNDATA_EDIT_OFFSET_X (13) 42 # define MNDATA_EDIT_OFFSET_Y (5) 43 # define MNDATA_EDIT_BACKGROUND_OFFSET_X (-13) 44 # define MNDATA_EDIT_BACKGROUND_OFFSET_Y (-5) 45 //# define MNDATA_EDIT_BACKGROUND_PATCH_LEFT ("") 46 //# define MNDATA_EDIT_BACKGROUND_PATCH_RIGHT ("") 47 # define MNDATA_EDIT_BACKGROUND_PATCH_MIDDLE ("M_FSLOT") 48 #endif 49 50 /** 51 * @defgroup mneditSetTextFlags MNEdit Set Text Flags 52 * @{ 53 */ 54 #define MNEDIT_STF_NO_ACTION 0x1 /// Do not call any linked action function. 55 #define MNEDIT_STF_REPLACEOLD 0x2 /// Replace the "old" copy (used for canceled edits). 56 /**@}*/ 57 58 /** 59 * UI widget for an editable line of text. 60 * 61 * @ingroup menu 62 */ 63 class LineEditWidget : public Widget 64 { 65 public: 66 LineEditWidget(); 67 virtual ~LineEditWidget(); 68 69 void draw() const; 70 void updateGeometry(); 71 int handleEvent(event_t const &ev); 72 int handleCommand(menucommand_e command); 73 74 LineEditWidget &setMaxLength(int newMaxLength); 75 int maxLength() const; 76 77 /** 78 * Change the current contents of the edit field. 79 * @param newText New text value. 80 * @param flags @ref mneditSetTextFlags 81 */ 82 LineEditWidget &setText(de::String const &newText, int flags = MNEDIT_STF_NO_ACTION); 83 84 /** 85 * Returns a copy of the current editable value. 86 */ 87 de::String text() const; 88 89 LineEditWidget &setEmptyText(de::String const &newEmptyText); 90 de::String emptyText() const; 91 92 public: 93 static void loadResources(); 94 95 private: 96 DENG2_PRIVATE(d) 97 }; 98 99 } // namespace menu 100 } // namespace common 101 102 #endif // LIBCOMMON_UI_LINEEDITWIDGET 103