Public Member Functions | Private Attributes
IntTextField Class Reference

#include <inttextfield.h>

Inheritance diagram for IntTextField:
TextField Widget FocusListener KeyListener MouseListener WidgetListener Widget2

Public Member Functions

 IntTextField (const Widget2 *const widget, const int def, const int min, const int max, const Enable enabled, const int width)
void setRange (const int minimum, const int maximum)
int getValue () const
void reset ()
void setValue (const int value)
void setDefaultValue (const int value)
void keyPressed (KeyEvent &event)
- Public Member Functions inherited from TextField
 TextField (const Widget2 *const widget, const std::string &text, const LoseFocusOnTab loseFocusOnTab, ActionListener *const listener, const std::string &eventId, const bool sendAlwaysEvents)
 ~TextField ()
void draw (Graphics *const graphics)
void safeDraw (Graphics *const graphics)
void updateAlpha ()
void drawFrame (Graphics *const graphics)
void safeDrawFrame (Graphics *const graphics)
void setNumeric (const bool numeric)
void setRange (const int min, const int max)
void keyPressed (KeyEvent &event)
void setMinimum (const int min)
void setMaximum (const int max)
int getValue () const
void setSendAlwaysEvents (const bool b)
void adjustSize ()
void adjustHeight ()
void setCaretPosition (unsigned int position)
void mousePressed (MouseEvent &event)
void handlePaste ()
void handleCopy () const
void focusGained (const Event &event)
void focusLost (const Event &event)
void moveCaretBack ()
void moveCaretForward ()
void moveCaretWordBack ()
void moveCaretWordForward ()
void caretDelete ()
void caretDeleteToStart ()
void caretDeleteWord ()
void setAllowSpecialActions (const bool b)
std::string getTextBeforeCaret () const
void setText (const std::string &text)
const std::string & getText () const
unsigned int getCaretPosition () const
void mouseDragged (MouseEvent &event)
void widgetHidden (const Event &event)
void setParent (Widget *widget)
void setWindow (Widget *const widget)
void signalEvent ()
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 ~Widget ()
void setFrameSize (const unsigned int frameSize)
unsigned int getFrameSize () const
virtual void logic ()
WidgetgetParent () const
void setWidth (const int width)
int getWidth () const
void setHeight (const int height)
int getHeight () const
void setSize (const int width, const int height)
void setX (const int x)
int getX () const
void setY (const int y)
int getY () const
void setPosition (const int x, const int y)
void setDimension (const Rect &dimension)
const RectgetDimension () const
void setFocusable (const bool focusable)
bool isFocusable () const
virtual bool isFocused () const
void setEnabled (const bool enabled)
bool isEnabled () const
void setVisible (Visible visible)
bool isVisible () const
void setBaseColor (const Color &color)
const ColorgetBaseColor () const
void setForegroundColor (const Color &color)
const ColorgetForegroundColor () const
void setBackgroundColor (const Color &color)
const ColorgetBackgroundColor () const
virtual void requestFocus ()
virtual void requestMoveToTop ()
virtual void requestMoveToBottom ()
virtual void setFocusHandler (FocusHandler *const focusHandler)
FocusHandlergetFocusHandler ()
void addActionListener (ActionListener *const actionListener)
void removeActionListener (ActionListener *const actionListener)
void addDeathListener (WidgetDeathListener *const deathListener)
void removeDeathListener (WidgetDeathListener *const deathListener)
void addMouseListener (MouseListener *const mouseListener)
void removeMouseListener (MouseListener *const mouseListener)
void addKeyListener (KeyListener *const keyListener)
void removeKeyListener (KeyListener *const keyListener)
void addFocusListener (FocusListener *const focusListener)
void removeFocusListener (FocusListener *const focusListener)
void addWidgetListener (WidgetListener *const widgetListener)
void removeWidgetListener (WidgetListener *const widgetListener)
void setActionEventId (const std::string &actionEventId)
const std::string & getActionEventId () const
virtual void getAbsolutePosition (int &x, int &y) const
FontgetFont () const
void setFont (Font *const font)
bool isTabInEnabled () const
void setTabInEnabled (const bool enabled)
bool isTabOutEnabled () const
void setTabOutEnabled (const bool enabled)
void requestModalFocus ()
virtual void requestModalMouseInputFocus ()
virtual void releaseModalFocus ()
virtual void releaseModalMouseInputFocus ()
virtual bool isModalFocused () const
virtual bool isModalMouseInputFocused () const
virtual WidgetgetWidgetAt (int x, int y)
const std::list< MouseListener * > & getMouseListeners () const A_CONST
const std::list< KeyListener * > & getKeyListeners () const A_CONST
const std::list< FocusListener * > & getFocusListeners () const A_CONST
virtual Rect getChildrenArea ()
virtual FocusHandlergetInternalFocusHandler ()
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
virtual void moveToTop (Widget *widget)
virtual void moveToBottom (Widget *widget)
virtual void focusNext ()
virtual void focusPrevious ()
virtual void showWidgetPart (Widget *const widget, const Rect &area)
void setId (const std::string &id)
const std::string & getId () const
virtual void showPart (const Rect &rectangle)
bool isAllowLogic () const
void setMouseConsume (const bool b)
bool isMouseConsume () const
void setRedraw (const bool b)
virtual bool isSelectable () const
void setSelectable (const bool selectable)
void windowResized ()
virtual void postInit ()
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
virtual void setWidget2 (const Widget2 *const widget)
void setPalette (int palette)
void checkPalette ()
void setForegroundColor2 (const Color &color)
WidgetgetWindow () const
- Public Member Functions inherited from FocusListener
virtual ~FocusListener ()
- Public Member Functions inherited from KeyListener
virtual ~KeyListener ()
virtual void keyReleased (KeyEvent &event)
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
virtual void mouseEntered (MouseEvent &event)
virtual void mouseExited (MouseEvent &event)
virtual void mouseReleased (MouseEvent &event)
virtual void mouseClicked (MouseEvent &event)
virtual void mouseWheelMovedUp (MouseEvent &event)
virtual void mouseWheelMovedDown (MouseEvent &event)
virtual void mouseMoved (MouseEvent &event)
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
virtual void widgetResized (const Event &event)
virtual void widgetMoved (const Event &event)
virtual void widgetShown (const Event &event)

Private Attributes

int mMin
int mMax
int mDefault
int mValue

Additional Inherited Members

- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
static FontgetGloablFont ()
static void cleanGlobalFont ()
static bool widgetExists (const Widget *const widget)
static void distributeWindowResizeEvent ()
static WidgetcallPostInit (Widget *const widget)
- Data Fields inherited from Widget
Visible mVisible
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
typedef MouseListenerList::iterator MouseListenerIterator
typedef std::list< KeyListener * > KeyListenerList
typedef KeyListenerList::iterator KeyListenerIterator
typedef std::list< ActionListener * > ActionListenerList
typedef ActionListenerList::iterator ActionListenerIterator
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
typedef std::list< FocusListener * > FocusListenerList
typedef FocusListenerList::iterator FocusListenerIterator
typedef std::list< WidgetListener * > WidgetListenerList
typedef WidgetListenerList::iterator WidgetListenerIterator
- Protected Member Functions inherited from TextField
void drawCaret (Graphics *graphics, int x)
void fixScroll ()
void fontChanged ()
bool handleNormalKeys (const InputActionT action, bool &consumed)
void handleCtrlKeys (const InputActionT action, bool &consumed)
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
void distributeResizedEvent ()
void distributeMovedEvent ()
void distributeHiddenEvent ()
void distributeShownEvent ()
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
- Protected Member Functions inherited from FocusListener
 FocusListener ()
- Protected Member Functions inherited from KeyListener
 KeyListener ()
- Protected Member Functions inherited from MouseListener
 MouseListener ()
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
- Protected Attributes inherited from TextField
std::string mText
TextChunk mTextChunk
unsigned int mCaretPosition
int mXScroll
const ColormCaretColor
int mMinimum
int mMaximum
time_t mLastEventPaste
int mPadding
bool mNumeric
LoseFocusOnTab mLoseFocusOnTab
bool mAllowSpecialActions
bool mSendAlwaysEvents
bool mTextChanged
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
KeyListenerList mKeyListeners
ActionListenerList mActionListeners
WidgetDeathListenerList mDeathListeners
FocusListenerList mFocusListeners
WidgetListenerList mWidgetListeners
Color mForegroundColor
Color mBackgroundColor
Color mBaseColor
Rect mDimension
std::string mActionEventId
std::string mId
unsigned int mFrameSize
bool mFocusable
bool mTabIn
bool mTabOut
bool mEnabled
bool mAllowLogic
bool mMouseConsume
bool mRedraw
bool mSelectable
- Protected Attributes inherited from Widget2
int mPaletteOffset
Color mForegroundColor2
- Static Protected Attributes inherited from TextField
static SkinmSkin
static int instances = 0
static float mAlpha = 1.0
static ImageRect skin
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0

Detailed Description

TextBox which only accepts numbers as input.

Definition at line 34 of file inttextfield.h.

Constructor & Destructor Documentation

◆ IntTextField()

IntTextField::IntTextField ( const Widget2 *const  widget,
const int  def,
const int  min,
const int  max,
const Enable  enabled,
const int  width 

Constructor, sets default value.

Definition at line 36 of file inttextfield.cpp.

41  :
42  TextField(widget, toString(def),
43  LoseFocusOnTab_true, nullptr, std::string(), false),
44  mMin(0),
45  mMax(0),
46  mDefault(def),
47  mValue(def)
48 {
49  if (min != 0 || max != 0)
50  setRange(min, max);
52  setEnabled(enabled == Enable_true);
53  if (width != 0)
54  setWidth(width);
55 }
void setRange(const int minimum, const int maximum)
TextField(const Widget2 *const widget, const std::string &text, const LoseFocusOnTab loseFocusOnTab, ActionListener *const listener, const std::string &eventId, const bool sendAlwaysEvents)
Definition: textfield.cpp:109
void setWidth(const int width)
Definition: widget.cpp:133
void setEnabled(const bool enabled)
Definition: widget.h:352
const bool Enable_true
Definition: enable.h:30
const bool LoseFocusOnTab_true
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774

References Enable_true, Widget::setEnabled(), setRange(), and Widget::setWidth().

Member Function Documentation

◆ getValue()

int IntTextField::getValue ( ) const

Returns the value in the text box.

Definition at line 118 of file inttextfield.cpp.

119 {
120  return getText().empty() ? mMin : mValue;
121 }
const std::string & getText() const
Definition: textfield.h:224

References TextField::getText(), mMin, and mValue.

Referenced by BankWindow::action(), BuyDialog::action(), EditServerDialog::action(), ItemAmountWindow::action(), NpcDialog::action(), ItemAmountWindow::keyReleased(), NpcDialog::move(), TextCommandEditor::save(), and MailEditWindow::sendMail().

◆ keyPressed()

void IntTextField::keyPressed ( KeyEvent event)

Responds to key presses.

Reimplemented from KeyListener.

Definition at line 57 of file inttextfield.cpp.

58 {
59  const InputActionT action = event.getActionId();
61  if (action == InputAction::GUI_DELETE
62  || action == InputAction::GUI_BACKSPACE)
63  {
64  setText(std::string());
68  event.consume();
69  }
71 #ifdef USE_SDL2
72  const int val = event.getKey().getValue();
73  if (val != KeyValue::TEXTINPUT)
74  return;
76  const std::string str = event.getText();
77  if (str.empty())
78  return;
79  const size_t sz = str.size();
80  for (size_t f = 0; f < sz; f ++)
81  {
82  const char chr = str[f];
83  if (chr < '0' || chr > '9')
84  return;
85  }
86 #else // USE_SDL2
88  if (!event.getKey().isNumber())
89  return;
90 #endif // USE_SDL2
92  TextField::keyPressed(event);
94  std::istringstream s(getText());
95  int i;
96  s >> i;
97  setValue(i);
100 }
void setValue(const int value)
const Key & getKey() const
Definition: keyevent.h:124
bool isNumber() const
Definition: key.cpp:85
void keyPressed(KeyEvent &event)
Definition: textfield.cpp:301
bool mSendAlwaysEvents
Definition: textfield.h:290
void setText(const std::string &text)
Definition: textfield.cpp:803
void distributeActionEvent()
Definition: widget.cpp:493
InputAction ::T InputActionT
Definition: inputaction.h:717
Definition: keyvalue.h:128

References Widget::distributeActionEvent(), KeyEvent::getKey(), TextField::getText(), InputAction::GUI_BACKSPACE, InputAction::GUI_DELETE, Key::isNumber(), TextField::keyPressed(), TextField::mSendAlwaysEvents, TextField::setText(), setValue(), and KeyValue::TEXTINPUT.

◆ reset()

void IntTextField::reset ( )

Reset the field to the default value.

Definition at line 147 of file inttextfield.cpp.

148 {
150 }

References mDefault, and setValue().

◆ setDefaultValue()

void IntTextField::setDefaultValue ( const int  value)

Set the default value of the text box to the specified value.

Definition at line 137 of file inttextfield.cpp.

138 {
139  if (value < mMin)
140  mDefault = mMin;
141  else if (value > mMax)
142  mDefault = mMax;
143  else
144  mDefault = value;
145 }

References mDefault, mMax, and mMin.

◆ setRange()

void IntTextField::setRange ( const int  minimum,
const int  maximum 

Sets the minimum and maximum values of the text box.

Definition at line 102 of file inttextfield.cpp.

103 {
104  mMin = min;
105  mMax = max;
107  if (mValue < mMin)
108  mValue = mMin;
109  else if (mValue > mMax)
110  mValue = mMax;
112  if (mDefault < mMin)
113  mDefault = mMin;
114  else if (mDefault > mMax)
115  mDefault = mMax;
116 }

References mDefault, mMax, mMin, and mValue.

Referenced by NpcDialog::integerRequest(), IntTextField(), ItemAmountWindow::ItemAmountWindow(), TextCommandEditor::TextCommandEditor(), and BuyDialog::valueChanged().

◆ setValue()

void IntTextField::setValue ( const int  value)

Set the value of the text box to the specified value.

Definition at line 123 of file inttextfield.cpp.

124 {
125  if (i < mMin)
126  mValue = mMin;
127  else if (i > mMax)
128  mValue = mMax;
129  else
130  mValue = i;
132  const std::string valStr = toString(mValue);
133  setText(valStr);
134  setCaretPosition(CAST_U32(valStr.length()) + 1);
135 }
#define CAST_U32
Definition: cast.h:31
void setCaretPosition(unsigned int position)
Definition: textfield.cpp:752

References CAST_U32, mMax, mMin, mValue, TextField::setCaretPosition(), TextField::setText(), and Catch::toString().

Referenced by SetupItemIntTextField::action(), BuyDialog::action(), ItemAmountWindow::action(), NpcDialog::action(), EditServerDialog::EditServerDialog(), NpcDialog::integerRequest(), keyPressed(), NpcDialog::move(), reset(), ItemAmountWindow::resetAmount(), TextCommandEditor::TextCommandEditor(), and BuyDialog::valueChanged().

Field Documentation

◆ mDefault

int IntTextField::mDefault

Default value

Definition at line 82 of file inttextfield.h.

Referenced by reset(), setDefaultValue(), and setRange().

◆ mMax

int IntTextField::mMax

Maximum value

Definition at line 81 of file inttextfield.h.

Referenced by setDefaultValue(), setRange(), and setValue().

◆ mMin

int IntTextField::mMin

Minimum value

Definition at line 80 of file inttextfield.h.

Referenced by getValue(), setDefaultValue(), setRange(), and setValue().

◆ mValue

int IntTextField::mValue

Current value

Definition at line 83 of file inttextfield.h.

Referenced by getValue(), setRange(), and setValue().

The documentation for this class was generated from the following files: