ManaPlus
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
TextField Class Reference

#include <textfield.h>

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

Public Member Functions

 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)
 

Protected Member Functions

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

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
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
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
 
WidgetmWindow
 
Color mForegroundColor2
 

Static Protected Attributes

static SkinmSkin
 
static int instances = 0
 
static float mAlpha = 1.0
 
static ImageRect skin
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

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
 

Detailed Description

A text field.

Definition at line 87 of file textfield.h.

Constructor & Destructor Documentation

◆ TextField()

TextField::TextField ( const Widget2 *const  widget,
const std::string &  text,
const LoseFocusOnTab  loseFocusOnTab,
ActionListener *const  listener,
const std::string &  eventId,
const bool  sendAlwaysEvents 
)

Constructor, initializes the text field with the given string.

Definition at line 108 of file textfield.cpp.

References Widget::addActionListener(), Widget::addFocusListener(), Widget::addKeyListener(), Widget::addMouseListener(), adjustSize(), Skin::getOption(), Skin::getPadding(), Widget2::getThemeColor(), instances, Theme::loadSkinRect(), Widget::mAllowLogic, Widget::mForegroundColor, Widget2::mForegroundColor2, Widget::mFrameSize, mPadding, mSkin, Widget::setActionEventId(), Widget::setFocusable(), Widget::setFrameSize(), skin, ThemeColorId::TEXTFIELD, ThemeColorId::TEXTFIELD_OUTLINE, and theme.

113  :
114  Widget(widget),
115  FocusListener(),
116  KeyListener(),
117  MouseListener(),
118  WidgetListener(),
119  mText(text),
120  mTextChunk(),
121  mCaretPosition(0),
122  mXScroll(0),
124  mMinimum(0),
125  mMaximum(0),
126  mLastEventPaste(0),
127  mPadding(1),
128  mNumeric(false),
129  mLoseFocusOnTab(loseFocusOnTab),
130  mAllowSpecialActions(true),
131  mSendAlwaysEvents(sendAlwaysEvents),
132  mTextChanged(true)
133 {
134  mAllowLogic = false;
135  setFocusable(true);
136  addMouseListener(this);
137  addKeyListener(this);
138 
139  setFrameSize(2);
142 
143  addFocusListener(this);
144 
145  if (instances == 0)
146  {
147  if (theme != nullptr)
148  {
150  "textfield.xml",
151  "textfield_background.xml",
152  0,
153  8);
154  }
155  }
156 
157  instances++;
158 
159  if (mSkin != nullptr)
160  {
162  mFrameSize = mSkin->getOption("frameSize", 2);
163  }
164 
165  adjustSize();
166  if (!eventId.empty())
167  setActionEventId(eventId);
168 
169  if (listener != nullptr)
170  addActionListener(listener);
171 }
static Skin * mSkin
Definition: textfield.h:257
const Color * mCaretColor
Definition: textfield.h:278
LoseFocusOnTab mLoseFocusOnTab
Definition: textfield.h:287
int mMaximum
Definition: textfield.h:283
void adjustSize()
Definition: textfield.cpp:715
int mXScroll
Definition: textfield.h:276
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
bool mNumeric
Definition: textfield.h:286
void addFocusListener(FocusListener *const focusListener)
Definition: widget.cpp:281
time_t mLastEventPaste
Definition: textfield.h:284
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:595
unsigned int mCaretPosition
Definition: textfield.h:269
Color mForegroundColor
Definition: widget.h:1085
int getOption(const std::string &name) const
Definition: skin.h:105
int getPadding() const
Definition: skin.h:99
std::string mText
Definition: textfield.h:262
Skin * loadSkinRect(ImageRect &image, const std::string &name, const std::string &name2, const int start, const int end)
Definition: theme.cpp:899
unsigned int mFrameSize
Definition: widget.h:1137
void setFrameSize(const unsigned int frameSize)
Definition: widget.h:167
static ImageRect skin
Definition: textfield.h:281
Widget(const Widget2 *const widget)
Definition: widget.cpp:84
bool mAllowLogic
Definition: widget.h:1159
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:291
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:271
Theme * theme
Definition: theme.cpp:61
void setFocusable(const bool focusable)
Definition: widget.cpp:191
Color mForegroundColor2
Definition: widget2.h:112
bool mTextChanged
Definition: textfield.h:290
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44
bool mSendAlwaysEvents
Definition: textfield.h:289
static int instances
Definition: textfield.h:279
TextChunk mTextChunk
Definition: textfield.h:264
int mMinimum
Definition: textfield.h:282
int mPadding
Definition: textfield.h:285
bool mAllowSpecialActions
Definition: textfield.h:288

◆ ~TextField()

TextField::~TextField ( )

Definition at line 173 of file textfield.cpp.

References TextChunk::deleteImage(), gui, instances, mSkin, mTextChunk, Widget2::mWindow, Gui::removeDragged(), Widget::removeWidgetListener(), skin, theme, Theme::unload(), and Theme::unloadRect().

174 {
175  if (mWindow != nullptr)
177 
178  if (gui != nullptr)
179  gui->removeDragged(this);
180 
181  instances--;
182  if (instances == 0)
183  {
184  if (theme != nullptr)
185  {
186  theme->unload(mSkin);
187  Theme::unloadRect(skin, 0, 8);
188  }
189  }
191 }
static Skin * mSkin
Definition: textfield.h:257
void unload(Skin *const skin)
Definition: theme.cpp:249
Gui * gui
Definition: gui.cpp:110
Widget * mWindow
Definition: widget2.h:111
static ImageRect skin
Definition: textfield.h:281
Theme * theme
Definition: theme.cpp:61
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1161
void removeWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:306
static int instances
Definition: textfield.h:279
TextChunk mTextChunk
Definition: textfield.h:264
void deleteImage()
Definition: textchunk.cpp:192
static void unloadRect(const ImageRect &rect, const int start, const int end)
Definition: theme.cpp:914

Member Function Documentation

◆ adjustHeight()

void TextField::adjustHeight ( )

Definition at line 723 of file textfield.cpp.

References Widget::getFont(), Widget::getHeight(), mPadding, and Widget::setHeight().

Referenced by adjustSize(), and setSendAlwaysEvents().

724 {
725  setHeight(getFont()->getHeight() + 2 * mPadding);
726 }
Font * getFont() const
Definition: widget.cpp:330
void setHeight(const int height)
Definition: widget.cpp:139
int getHeight() const
Definition: widget.h:239
int mPadding
Definition: textfield.h:285

◆ adjustSize()

void TextField::adjustSize ( )

Definition at line 715 of file textfield.cpp.

References adjustHeight(), fixScroll(), Widget::getFont(), Widget::getWidth(), mPadding, mText, and Widget::setWidth().

Referenced by LoginDialog::LoginDialog(), setSendAlwaysEvents(), and TextField().

716 {
717  setWidth(getFont()->getWidth(mText) + 2 * mPadding + 1);
718  adjustHeight();
719 
720  fixScroll();
721 }
Font * getFont() const
Definition: widget.cpp:330
int getWidth() const
Definition: widget.h:220
void setWidth(const int width)
Definition: widget.cpp:132
std::string mText
Definition: textfield.h:262
void fixScroll()
Definition: textfield.cpp:728
int mPadding
Definition: textfield.h:285
void adjustHeight()
Definition: textfield.cpp:723

◆ caretDelete()

void TextField::caretDelete ( )

Definition at line 615 of file textfield.cpp.

References CAST_U32, mCaretPosition, mText, and mTextChanged.

Referenced by handleCtrlKeys(), and setSendAlwaysEvents().

616 {
617  unsigned sz = CAST_U32(mText.size());
618  while (mCaretPosition < sz)
619  {
620  --sz;
621  mText.erase(mCaretPosition, 1);
622  if (mCaretPosition == sz || (mText[mCaretPosition] & 192) != 128)
623  break;
624  }
625  mTextChanged = true;
626 }
#define CAST_U32
Definition: cast.h:30
unsigned int mCaretPosition
Definition: textfield.h:269
std::string mText
Definition: textfield.h:262
bool mTextChanged
Definition: textfield.h:290

◆ caretDeleteToStart()

void TextField::caretDeleteToStart ( )

Definition at line 640 of file textfield.cpp.

References mCaretPosition, mText, and mTextChanged.

Referenced by handleCtrlKeys(), and setSendAlwaysEvents().

641 {
642  if (mCaretPosition > 0)
643  {
644  mText = mText.substr(mCaretPosition);
645  mCaretPosition = 0;
646  }
647  mTextChanged = true;
648 }
unsigned int mCaretPosition
Definition: textfield.h:269
std::string mText
Definition: textfield.h:262
bool mTextChanged
Definition: textfield.h:290

◆ caretDeleteWord()

void TextField::caretDeleteWord ( )

Definition at line 689 of file textfield.cpp.

References deleteCharLeft(), isWordSeparator(), mCaretPosition, mText, and mTextChanged.

Referenced by handleCtrlKeys(), and setSendAlwaysEvents().

690 {
691  while (mCaretPosition > 0)
692  {
695  break;
696  }
697  mTextChanged = true;
698 }
unsigned int mCaretPosition
Definition: textfield.h:269
bool isWordSeparator(const signed char chr) A_CONST
Definition: stringutils.h:141
void deleteCharLeft(std::string &str, unsigned *const pos)
std::string mText
Definition: textfield.h:262
bool mTextChanged
Definition: textfield.h:290

◆ draw()

void TextField::draw ( Graphics *const  graphics)
virtual

Draws the text field.

Implements Widget.

Definition at line 209 of file textfield.cpp.

References BLOCK_END, BLOCK_START, TextChunk::color, TextChunk::color2, TextChunk::deleteImage(), drawCaret(), Graphics::drawImage(), ServerCommandType::font, Font::generate(), Widget::getFont(), Font::getWidth(), TextChunk::img, Widget::isFocused(), mCaretPosition, Widget::mForegroundColor, Widget2::mForegroundColor2, mPadding, mText, mTextChanged, mTextChunk, mXScroll, TextChunk::text, TextChunk::textFont, and updateAlpha().

Referenced by PasswordField::draw(), and safeDraw().

210 {
211  BLOCK_START("TextField::draw")
212  updateAlpha();
213 
214  Font *const font = getFont();
215  if (isFocused())
216  {
217  drawCaret(graphics,
218  font->getWidth(mText.substr(0, mCaretPosition)) - mXScroll);
219  }
220 
221  if (mTextChanged)
222  {
228  font->generate(mTextChunk);
229  mTextChanged = false;
230  }
231 
232  const Image *const image = mTextChunk.img;
233  if (image != nullptr)
234  graphics->drawImage(image, mPadding - mXScroll, mPadding);
235 
236  BLOCK_END("TextField::draw")
237 }
Font * getFont() const
Definition: widget.cpp:330
std::string text
Definition: textchunk.h:64
Definition: font.h:88
int mXScroll
Definition: textfield.h:276
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
unsigned int mCaretPosition
Definition: textfield.h:269
void updateAlpha()
Definition: textfield.cpp:193
Color mForegroundColor
Definition: widget.h:1085
Font * textFont
Definition: textchunk.h:63
void drawCaret(Graphics *graphics, int x)
Definition: textfield.cpp:706
virtual bool isFocused() const
Definition: widget.cpp:183
std::string mText
Definition: textfield.h:262
Color mForegroundColor2
Definition: widget2.h:112
Image * img
Definition: textchunk.h:62
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
Definition: image.h:61
Color color
Definition: textchunk.h:65
bool mTextChanged
Definition: textfield.h:290
TextChunk mTextChunk
Definition: textfield.h:264
void deleteImage()
Definition: textchunk.cpp:192
Color color2
Definition: textchunk.h:66
int mPadding
Definition: textfield.h:285

◆ drawCaret()

void TextField::drawCaret ( Graphics graphics,
int  x 
)
protected

Definition at line 706 of file textfield.cpp.

References Graphics::drawLine(), Graphics::getTopClip(), Rect::height, mCaretColor, mPadding, and Graphics::setColor().

Referenced by draw(), and getCaretPosition().

707 {
708  const ClipRect &clipArea = graphics->getTopClip();
709 
710  graphics->setColor(*mCaretColor);
711  graphics->drawLine(x + mPadding, clipArea.height - mPadding,
712  x + mPadding, mPadding);
713 }
const Color * mCaretColor
Definition: textfield.h:278
ClipRect & getTopClip() const
Definition: graphics.h:280
virtual void setColor(const Color &color)
Definition: graphics.h:319
int height
Definition: rect.h:223
virtual void drawLine(int x1, int y1, int x2, int y2)=0
int mPadding
Definition: textfield.h:285

◆ drawFrame()

void TextField::drawFrame ( Graphics *const  graphics)
virtual

Draws the background and border.

Reimplemented from Widget.

Definition at line 244 of file textfield.cpp.

References BLOCK_END, BLOCK_START, Graphics::drawImageRect(), Rect::height, Widget::mDimension, Widget::mFrameSize, skin, and Rect::width.

245 {
246  BLOCK_START("TextField::drawFrame")
247  const int bs = 2 * mFrameSize;
248  graphics->drawImageRect(0,
249  0,
250  mDimension.width + bs,
251  mDimension.height + bs,
252  skin);
254 }
#define BLOCK_START(name)
Definition: perfomance.h:78
#define BLOCK_END(name)
Definition: perfomance.h:79
void drawFrame(Graphics *const graphics)
Definition: textfield.cpp:244
unsigned int mFrameSize
Definition: widget.h:1137
static ImageRect skin
Definition: textfield.h:281
void drawImageRect(int x, int y, int w, int h, const ImageRect &restrict imgRect) restrict2 override final
Rect mDimension
Definition: widget.h:1100

◆ fixScroll()

void TextField::fixScroll ( )
protected

Definition at line 728 of file textfield.cpp.

References Widget::getFont(), Font::getWidth(), Widget::isFocused(), mCaretPosition, Widget::mDimension, mPadding, mText, mXScroll, and Rect::width.

Referenced by adjustSize(), fontChanged(), getCaretPosition(), handleNormalKeys(), keyPressed(), mousePressed(), and setCaretPosition().

729 {
730  if (isFocused())
731  {
732  const int caretX = getFont()->getWidth(
733  mText.substr(0, mCaretPosition));
734 
735  const int width = mDimension.width;
736  const int pad = 2 * mPadding;
737  if (caretX - mXScroll >= width - pad)
738  {
739  mXScroll = caretX - width + pad;
740  }
741  else if (caretX - mXScroll <= 0)
742  {
743  mXScroll = caretX - width / 2;
744 
745  if (mXScroll < 0)
746  mXScroll = 0;
747  }
748  }
749 }
Font * getFont() const
Definition: widget.cpp:330
int width
Definition: rect.h:218
int mXScroll
Definition: textfield.h:276
unsigned int mCaretPosition
Definition: textfield.h:269
virtual bool isFocused() const
Definition: widget.cpp:183
std::string mText
Definition: textfield.h:262
int getWidth(const std::string &text) const
Definition: font.cpp:333
Rect mDimension
Definition: widget.h:1100
int mPadding
Definition: textfield.h:285

◆ focusGained()

void TextField::focusGained ( const Event event)
virtual

Called when a widget gains focus.

Parameters
eventDiscribes the event.

Reimplemented from FocusListener.

Definition at line 790 of file textfield.cpp.

References InputManager::executeAction(), inputManager, WindowManager::isKeyboardVisible(), and InputAction::SHOW_KEYBOARD.

Referenced by setSendAlwaysEvents().

791 {
792 #ifdef ANDROID
795 #endif // ANDROID
796 }
bool isKeyboardVisible()
InputManager inputManager
void executeAction(const InputActionT keyNum)

◆ focusLost()

void TextField::focusLost ( const Event event)
virtual

Called when a widget loses focus.

Parameters
eventDiscribes the event.

Reimplemented from FocusListener.

Definition at line 798 of file textfield.cpp.

Referenced by ChatInput::focusLost(), and setSendAlwaysEvents().

799 {
800 }

◆ fontChanged()

void TextField::fontChanged ( )
protectedvirtual

Called when the font has changed. If the change is global, this function will only be called if the widget doesn't have a font already set.

Reimplemented from Widget.

Definition at line 762 of file textfield.cpp.

References fixScroll().

Referenced by getCaretPosition().

763 {
764  fixScroll();
765 }
void fixScroll()
Definition: textfield.cpp:728

◆ getCaretPosition()

unsigned int TextField::getCaretPosition ( ) const
inline

Gets the caret position. As there is only one line of text in a text field the position is the caret's x coordinate.

Returns
The caret position.
See also
setCaretPosition

Definition at line 233 of file textfield.h.

References A_NONNULL, drawCaret(), fixScroll(), fontChanged(), handleCtrlKeys(), handleNormalKeys(), mCaretPosition, mouseDragged(), setParent(), setWindow(), signalEvent(), widgetHidden(), and x.

Referenced by ChatWindow::addInputText(), ChatWindow::autoComplete(), and handlePaste().

234  { return mCaretPosition; }
unsigned int mCaretPosition
Definition: textfield.h:269

◆ getText()

const std::string& TextField::getText ( ) const
inline

◆ getTextBeforeCaret()

std::string TextField::getTextBeforeCaret ( ) const
inline

Definition at line 206 of file textfield.h.

References mCaretPosition, mText, and setText().

Referenced by ChatWindow::keyPressed().

207  { return mText.substr(0, mCaretPosition); }
unsigned int mCaretPosition
Definition: textfield.h:269
std::string mText
Definition: textfield.h:262

◆ getValue()

int TextField::getValue ( ) const

Return the value for a numeric field

Definition at line 285 of file textfield.cpp.

References mMaximum, mMinimum, mNumeric, and mText.

Referenced by setMaximum(), and Setup_Colors::Setup_Colors().

286 {
287  if (!mNumeric)
288  return 0;
289 
290  const int value = atoi(mText.c_str());
291  if (value < mMinimum)
292  return mMinimum;
293 
294  if (value > mMaximum)
295  return mMaximum;
296 
297  return value;
298 }
int mMaximum
Definition: textfield.h:283
bool mNumeric
Definition: textfield.h:286
std::string mText
Definition: textfield.h:262
int mMinimum
Definition: textfield.h:282

◆ handleCopy()

void TextField::handleCopy ( ) const

Definition at line 700 of file textfield.cpp.

References getText(), and sendBuffer().

Referenced by handleCtrlKeys(), PopupMenu::handleLink(), and setSendAlwaysEvents().

701 {
702  std::string text = getText();
703  sendBuffer(text);
704 }
bool sendBuffer(const std::string &text)
Definition: copynpaste.cpp:517
const std::string & getText() const
Definition: textfield.h:223

◆ handleCtrlKeys()

void TextField::handleCtrlKeys ( const InputActionT  action,
bool consumed 
)
protected

Definition at line 495 of file textfield.cpp.

References caretDelete(), caretDeleteToStart(), caretDeleteWord(), CAST_S32, cur_time, deleteCharLeft(), InputAction::GUI_B, InputAction::GUI_C, InputAction::GUI_D, InputAction::GUI_E, InputAction::GUI_F, InputAction::GUI_H, InputAction::GUI_K, InputAction::GUI_LEFT, InputAction::GUI_RIGHT, InputAction::GUI_U, InputAction::GUI_V, InputAction::GUI_W, handleCopy(), handlePaste(), mAllowSpecialActions, mCaretPosition, mLastEventPaste, moveCaretBack(), moveCaretForward(), moveCaretWordBack(), moveCaretWordForward(), mText, mTextChanged, and PRAGMA45().

Referenced by getCaretPosition(), and keyPressed().

496 {
497  PRAGMA45(GCC diagnostic push)
498  PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
499  switch (action)
500  {
502  {
504  consumed = true;
505  break;
506  }
508  {
510  consumed = true;
511  break;
512  }
513  case InputAction::GUI_B:
514  {
516  {
517  moveCaretBack();
518  consumed = true;
519  }
520  break;
521  }
522  case InputAction::GUI_F:
523  {
525  consumed = true;
526  break;
527  }
528  case InputAction::GUI_D:
529  {
530  caretDelete();
531  consumed = true;
532  break;
533  }
534  case InputAction::GUI_E:
535  {
536  mCaretPosition = CAST_S32(mText.size());
537  consumed = true;
538  break;
539  }
540  case InputAction::GUI_H:
541  {
543  mTextChanged = true;
544  consumed = true;
545  break;
546  }
547  case InputAction::GUI_K:
548  {
549  mText = mText.substr(0, mCaretPosition);
550  mTextChanged = true;
551  consumed = true;
552  break;
553  }
554  case InputAction::GUI_U:
555  {
557  consumed = true;
558  break;
559  }
560  case InputAction::GUI_C:
561  {
562  handleCopy();
563  consumed = true;
564  break;
565  }
566  case InputAction::GUI_V:
567  {
568 #ifdef USE_SDL2
569  handlePaste();
570 #else // USE_SDL2
571 
572  // hack to prevent paste key sticking
573  if ((mLastEventPaste != 0) && mLastEventPaste > cur_time)
574  break;
575  handlePaste();
577 #endif // USE_SDL2
578 
579  consumed = true;
580  break;
581  }
582  case InputAction::GUI_W:
583  {
584  caretDeleteWord();
585  consumed = true;
586  break;
587  }
588  default:
589  break;
590  }
591  PRAGMA45(GCC diagnostic pop)
592 }
void handlePaste()
Definition: textfield.cpp:628
PRAGMA45(GCC diagnostic push) PRAGMA45(GCC diagnostic ignored "-Wunused-result") int TestLauncher
void caretDeleteWord()
Definition: textfield.cpp:689
void moveCaretBack()
Definition: textfield.cpp:594
time_t mLastEventPaste
Definition: textfield.h:284
unsigned int mCaretPosition
Definition: textfield.h:269
void handleCopy() const
Definition: textfield.cpp:700
void moveCaretWordBack()
Definition: textfield.cpp:650
#define CAST_S32
Definition: cast.h:29
void deleteCharLeft(std::string &str, unsigned *const pos)
std::string mText
Definition: textfield.h:262
void caretDelete()
Definition: textfield.cpp:615
volatile time_t cur_time
Definition: timer.cpp:57
void moveCaretWordForward()
Definition: textfield.cpp:669
bool mTextChanged
Definition: textfield.h:290
void caretDeleteToStart()
Definition: textfield.cpp:640
void moveCaretForward()
Definition: textfield.cpp:604
bool mAllowSpecialActions
Definition: textfield.h:288

◆ handleNormalKeys()

bool TextField::handleNormalKeys ( const InputActionT  action,
bool consumed 
)
protected

Definition at line 408 of file textfield.cpp.

References CAST_U32, deleteCharLeft(), Widget::distributeActionEvent(), fixScroll(), InputAction::GUI_BACKSPACE, InputAction::GUI_DELETE, InputAction::GUI_END, InputAction::GUI_HOME, InputAction::GUI_LEFT, InputAction::GUI_RIGHT, InputAction::GUI_SELECT2, InputAction::GUI_TAB, LoseFocusOnTab_true, mCaretPosition, mLoseFocusOnTab, mText, mTextChanged, and PRAGMA45().

Referenced by getCaretPosition(), and keyPressed().

409 {
410  PRAGMA45(GCC diagnostic push)
411  PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
412  switch (action)
413  {
415  {
416  consumed = true;
417  while (mCaretPosition > 0)
418  {
419  --mCaretPosition;
420  if ((mText[mCaretPosition] & 192) != 128)
421  break;
422  }
423  break;
424  }
425 
427  {
428  consumed = true;
429  const unsigned sz = CAST_U32(mText.size());
430  while (mCaretPosition < sz)
431  {
432  ++mCaretPosition;
433  if (mCaretPosition == sz ||
434  (mText[mCaretPosition] & 192) != 128)
435  {
436  break;
437  }
438  }
439  break;
440  }
441 
443  {
444  consumed = true;
445  unsigned sz = CAST_U32(mText.size());
446  while (mCaretPosition < sz)
447  {
448  --sz;
449  mText.erase(mCaretPosition, 1);
450  mTextChanged = true;
451  if (mCaretPosition == sz ||
452  (mText[mCaretPosition] & 192) != 128)
453  {
454  break;
455  }
456  }
457  break;
458  }
459 
461  consumed = true;
463  mTextChanged = true;
464  break;
465 
468  consumed = true;
469  fixScroll();
470  return false;
471 
473  mCaretPosition = 0;
474  consumed = true;
475  break;
476 
478  mCaretPosition = CAST_U32(mText.size());
479  consumed = true;
480  break;
481 
484  return false;
485  consumed = true;
486  break;
487 
488  default:
489  break;
490  }
491  PRAGMA45(GCC diagnostic pop)
492  return true;
493 }
#define CAST_U32
Definition: cast.h:30
LoseFocusOnTab mLoseFocusOnTab
Definition: textfield.h:287
const bool LoseFocusOnTab_true
PRAGMA45(GCC diagnostic push) PRAGMA45(GCC diagnostic ignored "-Wunused-result") int TestLauncher
unsigned int mCaretPosition
Definition: textfield.h:269
void distributeActionEvent()
Definition: widget.cpp:492
void deleteCharLeft(std::string &str, unsigned *const pos)
std::string mText
Definition: textfield.h:262
void fixScroll()
Definition: textfield.cpp:728
bool mTextChanged
Definition: textfield.h:290

◆ handlePaste()

void TextField::handlePaste ( )

Definition at line 628 of file textfield.cpp.

References CAST_SIZE, CAST_U32, getCaretPosition(), getText(), retrieveBuffer(), setCaretPosition(), and setText().

Referenced by handleCtrlKeys(), PopupMenu::handleLink(), and setSendAlwaysEvents().

629 {
630  std::string text = getText();
631  size_t caretPos = CAST_SIZE(getCaretPosition());
632 
633  if (retrieveBuffer(text, caretPos))
634  {
635  setText(text);
636  setCaretPosition(CAST_U32(caretPos));
637  }
638 }
#define CAST_U32
Definition: cast.h:30
void setCaretPosition(unsigned int position)
Definition: textfield.cpp:751
void setText(const std::string &text)
Definition: textfield.cpp:802
unsigned int getCaretPosition() const
Definition: textfield.h:233
bool retrieveBuffer(std::string &text, size_t &pos)
Definition: copynpaste.cpp:512
#define CAST_SIZE
Definition: cast.h:33
const std::string & getText() const
Definition: textfield.h:223

◆ keyPressed()

void TextField::keyPressed ( KeyEvent event)
virtual

Processes one keypress.

Reimplemented from KeyListener.

Definition at line 300 of file textfield.cpp.

References CAST_8, CAST_S32, CAST_U32, Widget::distributeActionEvent(), fixScroll(), InputAction::GUI_CTRL, handleCtrlKeys(), handleNormalKeys(), inputManager, InputManager::isActionActive(), mCaretPosition, mLastEventPaste, mMaximum, mNumeric, mSendAlwaysEvents, mText, mTextChanged, ServerCommandType::str, and KeyValue::TEXTINPUT.

Referenced by IntTextField::keyPressed(), and setRange().

301 {
302  const int val = event.getKey().getValue();
303 
304 #ifdef USE_SDL2
305  if (val == KeyValue::TEXTINPUT)
306  {
307  std::string str = event.getText();
308  mText.insert(mCaretPosition, str);
309  mTextChanged = true;
310  mCaretPosition += CAST_U32(str.size());
311  event.consume();
312  fixScroll();
313  if (mSendAlwaysEvents)
315  return;
316  }
317  bool consumed(false);
318 #else // USE_SDL2
319 
320  if (val >= 32)
321  {
322  if (mNumeric)
323  {
324  if ((val >= '0' && val <= '9') ||
325  (val == '-' && mCaretPosition == 0U))
326  {
327  char buf[2];
328  buf[0] = CAST_8(val);
329  buf[1] = 0;
330  mText.insert(mCaretPosition, std::string(buf));
331  mTextChanged = true;
332  mCaretPosition += 1;
333  event.consume();
334  fixScroll();
335  if (mSendAlwaysEvents)
337  return;
338  }
339  }
340  else if ((mMaximum == 0) ||
341  CAST_S32(mText.size()) < mMaximum)
342  {
343  int len;
344  if (val < 128)
345  len = 1; // 0xxxxxxx
346  else if (val < 0x800)
347  len = 2; // 110xxxxx 10xxxxxx
348  else if (val < 0x10000)
349  len = 3; // 1110xxxx 10xxxxxx 10xxxxxx
350  else
351  len = 4; // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
352 
353  char buf[4];
354  for (int i = 0; i < len; ++ i)
355  {
356  buf[i] = CAST_8(val >> (6 * (len - i - 1)));
357  if (i > 0)
358  buf[i] = CAST_8((buf[i] & 63) | 128);
359  }
360 
361  if (len > 1)
362  buf[0] |= CAST_8(255U << (8 - len));
363 
364  mText.insert(mCaretPosition, std::string(buf, buf + len));
365  mCaretPosition += len;
366  mTextChanged = true;
367  event.consume();
368  fixScroll();
369  if (mSendAlwaysEvents)
371  return;
372  }
373  }
374 
375  /* In UTF-8, 10xxxxxx is only used for inner parts of characters. So skip
376  them when processing key presses. */
377 
378  // unblock past key
379  if (val != 22)
380  mLastEventPaste = 0;
381 
382  bool consumed(false);
383 #endif // USE_SDL2
384 
385  const InputActionT action = event.getActionId();
387  {
388  if (!handleNormalKeys(action, consumed))
389  {
390  if (consumed)
391  event.consume();
392  return;
393  }
394  }
395  else
396  {
397  handleCtrlKeys(action, consumed);
398  }
399 
400  if (mSendAlwaysEvents)
402 
403  if (consumed)
404  event.consume();
405  fixScroll();
406 }
#define CAST_U32
Definition: cast.h:30
int mMaximum
Definition: textfield.h:283
bool mNumeric
Definition: textfield.h:286
time_t mLastEventPaste
Definition: textfield.h:284
unsigned int mCaretPosition
Definition: textfield.h:269
bool isActionActive(const InputActionT index) const
void distributeActionEvent()
Definition: widget.cpp:492
#define CAST_8
Definition: cast.h:24
#define CAST_S32
Definition: cast.h:29
void handleCtrlKeys(const InputActionT action, bool &consumed)
Definition: textfield.cpp:495
std::string mText
Definition: textfield.h:262
InputAction ::T InputActionT
Definition: inputaction.h:715
void fixScroll()
Definition: textfield.cpp:728
bool mTextChanged
Definition: textfield.h:290
InputManager inputManager
bool mSendAlwaysEvents
Definition: textfield.h:289
bool handleNormalKeys(const InputActionT action, bool &consumed)
Definition: textfield.cpp:408

◆ mouseDragged()

void TextField::mouseDragged ( MouseEvent event)
virtual

Called when the mouse has moved and the mouse has previously been pressed on the widget.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 811 of file textfield.cpp.

Referenced by getCaretPosition().

812 {
813  event.consume();
814 }

◆ mousePressed()

void TextField::mousePressed ( MouseEvent event)
virtual

Called when a mouse button has been pressed on the widget area.

NOTE: A mouse press is NOT equal to a mouse click. Use mouseClickMessage to check for mouse clicks.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 767 of file textfield.cpp.

References InputManager::executeAction(), fixScroll(), MouseEvent::getButton(), Widget::getFont(), Font::getStringIndexAt(), MouseEvent::getX(), inputManager, WindowManager::isKeyboardVisible(), MouseButton::LEFT, mCaretPosition, mText, mXScroll, popupMenu, MouseButton::RIGHT, InputAction::SHOW_KEYBOARD, and PopupMenu::showTextFieldPopup().

Referenced by setSendAlwaysEvents().

768 {
769 #ifdef ANDROID
772 #endif // ANDROID
773 
774  event.consume();
775  if (event.getButton() == MouseButton::RIGHT)
776  {
777 #ifndef DYECMD
778  if (popupMenu != nullptr)
780 #endif // DYECMD
781  }
782  else if (event.getButton() == MouseButton::LEFT)
783  {
785  mText, event.getX() + mXScroll);
786  fixScroll();
787  }
788 }
Font * getFont() const
Definition: widget.cpp:330
int mXScroll
Definition: textfield.h:276
void showTextFieldPopup(TextField *const input)
Definition: popupmenu.cpp:2172
MouseButtonT getButton() const
Definition: mouseevent.h:115
unsigned int mCaretPosition
Definition: textfield.h:269
int getStringIndexAt(const std::string &text, const int x) const
Definition: font.cpp:412
std::string mText
Definition: textfield.h:262
PopupMenu * popupMenu
Definition: popupmenu.cpp:102
bool isKeyboardVisible()
void fixScroll()
Definition: textfield.cpp:728
int getX() const
Definition: mouseevent.h:126
InputManager inputManager
void executeAction(const InputActionT keyNum)

◆ moveCaretBack()

void TextField::moveCaretBack ( )

Definition at line 594 of file textfield.cpp.

References mCaretPosition, and mText.

Referenced by handleCtrlKeys(), and setSendAlwaysEvents().

595 {
596  while (mCaretPosition > 0)
597  {
598  --mCaretPosition;
599  if ((mText[mCaretPosition] & 192) != 128)
600  break;
601  }
602 }
unsigned int mCaretPosition
Definition: textfield.h:269
std::string mText
Definition: textfield.h:262

◆ moveCaretForward()

void TextField::moveCaretForward ( )

Definition at line 604 of file textfield.cpp.

References CAST_U32, mCaretPosition, and mText.

Referenced by handleCtrlKeys(), and setSendAlwaysEvents().

605 {
606  const unsigned sz = CAST_U32(mText.size());
607  while (mCaretPosition < sz)
608  {
609  ++mCaretPosition;
610  if (mCaretPosition == sz || (mText[mCaretPosition] & 192) != 128)
611  break;
612  }
613 }
#define CAST_U32
Definition: cast.h:30
unsigned int mCaretPosition
Definition: textfield.h:269
std::string mText
Definition: textfield.h:262

◆ moveCaretWordBack()

void TextField::moveCaretWordBack ( )

Definition at line 650 of file textfield.cpp.

References isWordSeparator(), mCaretPosition, and mText.

Referenced by handleCtrlKeys(), and setSendAlwaysEvents().

651 {
652  const unsigned int oldCaret = mCaretPosition;
653  while (mCaretPosition > 0)
654  {
656  break;
657  mCaretPosition --;
658  }
659  if (oldCaret != mCaretPosition)
660  return;
661  while (mCaretPosition > 0)
662  {
664  break;
665  mCaretPosition --;
666  }
667 }
unsigned int mCaretPosition
Definition: textfield.h:269
bool isWordSeparator(const signed char chr) A_CONST
Definition: stringutils.h:141
std::string mText
Definition: textfield.h:262

◆ moveCaretWordForward()

void TextField::moveCaretWordForward ( )

Definition at line 669 of file textfield.cpp.

References CAST_U32, isWordSeparator(), mCaretPosition, and mText.

Referenced by handleCtrlKeys(), and setSendAlwaysEvents().

670 {
671  const unsigned sz = CAST_U32(mText.size());
672  const unsigned int oldCaret = mCaretPosition;
673  while (mCaretPosition < sz)
674  {
676  break;
677  mCaretPosition ++;
678  }
679  if (oldCaret != mCaretPosition)
680  return;
681  while (mCaretPosition < sz)
682  {
684  break;
685  mCaretPosition ++;
686  }
687 }
#define CAST_U32
Definition: cast.h:30
unsigned int mCaretPosition
Definition: textfield.h:269
bool isWordSeparator(const signed char chr) A_CONST
Definition: stringutils.h:141
std::string mText
Definition: textfield.h:262

◆ safeDraw()

void TextField::safeDraw ( Graphics *const  graphics)
virtual

Implements Widget.

Definition at line 239 of file textfield.cpp.

References draw().

240 {
241  TextField::draw(graphics);
242 }
void draw(Graphics *const graphics)
Definition: textfield.cpp:209

◆ safeDrawFrame()

void TextField::safeDrawFrame ( Graphics *const  graphics)
virtual

Reimplemented from Widget.

Definition at line 256 of file textfield.cpp.

References BLOCK_END, BLOCK_START, Graphics::drawImageRect(), Rect::height, Widget::mDimension, Widget::mFrameSize, skin, and Rect::width.

257 {
258  BLOCK_START("TextField::drawFrame")
259  const int bs = 2 * mFrameSize;
260  graphics->drawImageRect(0,
261  0,
262  mDimension.width + bs,
263  mDimension.height + bs,
264  skin);
266 }
#define BLOCK_START(name)
Definition: perfomance.h:78
#define BLOCK_END(name)
Definition: perfomance.h:79
void drawFrame(Graphics *const graphics)
Definition: textfield.cpp:244
unsigned int mFrameSize
Definition: widget.h:1137
static ImageRect skin
Definition: textfield.h:281
void drawImageRect(int x, int y, int w, int h, const ImageRect &restrict imgRect) restrict2 override final
Rect mDimension
Definition: widget.h:1100

◆ setAllowSpecialActions()

void TextField::setAllowSpecialActions ( const bool  b)
inline

Definition at line 203 of file textfield.h.

References mAllowSpecialActions.

Referenced by ChatWindow::ChatWindow().

204  { mAllowSpecialActions = b; }
bool mAllowSpecialActions
Definition: textfield.h:288

◆ setCaretPosition()

void TextField::setCaretPosition ( unsigned int  position)

Definition at line 751 of file textfield.cpp.

References CAST_S32, CAST_U32, fixScroll(), mCaretPosition, and mText.

Referenced by ChatWindow::addInputText(), ChatWindow::autoComplete(), handlePaste(), ChatWindow::keyPressed(), RegisterDialog::postInit(), setSendAlwaysEvents(), and IntTextField::setValue().

752 {
753  const unsigned int sz = CAST_U32(mText.size());
754  if (position > sz)
755  mCaretPosition = CAST_S32(sz);
756  else
757  mCaretPosition = position;
758 
759  fixScroll();
760 }
#define CAST_U32
Definition: cast.h:30
unsigned int mCaretPosition
Definition: textfield.h:269
#define CAST_S32
Definition: cast.h:29
std::string mText
Definition: textfield.h:262
void fixScroll()
Definition: textfield.cpp:728

◆ setMaximum()

void TextField::setMaximum ( const int  max)
inline

Set the maximum value for a range

Definition at line 157 of file textfield.h.

References A_WARN_UNUSED, getValue(), and mMaximum.

Referenced by CharCreateDialog::CharCreateDialog().

158  { mMaximum = max; }
int mMaximum
Definition: textfield.h:283

◆ setMinimum()

void TextField::setMinimum ( const int  min)
inline

Set the minimum value for a range

Definition at line 151 of file textfield.h.

References mMinimum.

152  { mMinimum = min; }
int mMinimum
Definition: textfield.h:282

◆ setNumeric()

void TextField::setNumeric ( const bool  numeric)

Determine whether the field should be numeric or not

Definition at line 268 of file textfield.cpp.

References mNumeric, mText, and setText().

Referenced by EditServerDialog::EditServerDialog(), and Setup_Colors::Setup_Colors().

269 {
270  mNumeric = numeric;
271  if (!numeric)
272  return;
273 
274  const char *const text = mText.c_str();
275  for (const char *textPtr = text; *textPtr != 0; ++textPtr)
276  {
277  if (*textPtr < '0' || *textPtr > '9')
278  {
279  setText(mText.substr(0, textPtr - text));
280  return;
281  }
282  }
283 }
bool mNumeric
Definition: textfield.h:286
void setText(const std::string &text)
Definition: textfield.cpp:802
std::string mText
Definition: textfield.h:262

◆ setParent()

void TextField::setParent ( Widget parent)
virtual

Sets the parent of the widget. A parent must be a BasicContainer.

WARNING: This function is used internally and should not be called or overloaded unless you know what you are doing.

Parameters
parentThe parent of the widget.
See also
getParent

Reimplemented from Widget.

Definition at line 822 of file textfield.cpp.

References Widget::addWidgetListener(), Widget2::mWindow, and Widget::setParent().

Referenced by getCaretPosition().

823 {
824  if (mWindow != nullptr)
825  mWindow->addWidgetListener(this);
826  Widget::setParent(widget);
827 }
Widget * mWindow
Definition: widget2.h:111
virtual void setParent(Widget *parent)
Definition: widget.h:625
void addWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:301

◆ setRange()

void TextField::setRange ( const int  min,
const int  max 
)
inline

Set the range on the field if it is numeric

Definition at line 136 of file textfield.h.

References keyPressed(), mMaximum, and mMinimum.

Referenced by EditServerDialog::EditServerDialog(), Setup_Colors::Setup_Colors(), and Setup_Colors::valueChanged().

138  {
139  mMinimum = min;
140  mMaximum = max;
141  }
int mMaximum
Definition: textfield.h:283
int mMinimum
Definition: textfield.h:282

◆ setSendAlwaysEvents()

void TextField::setSendAlwaysEvents ( const bool  b)
inline

◆ setText()

void TextField::setText ( const std::string &  text)

◆ setWindow()

void TextField::setWindow ( Widget *const  widget)
virtual

Reimplemented from Widget2.

Definition at line 829 of file textfield.cpp.

References Widget2::mWindow, Widget::removeWidgetListener(), and Widget2::setWindow().

Referenced by getCaretPosition().

830 {
831  if ((widget == nullptr) && (mWindow != nullptr))
832  {
834  mWindow = nullptr;
835  }
836  else
837  {
838  Widget2::setWindow(widget);
839  }
840 }
virtual void setWindow(Widget *const window)
Definition: widget2.h:96
Widget * mWindow
Definition: widget2.h:111
void removeWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:306

◆ signalEvent()

void TextField::signalEvent ( )

Definition at line 842 of file textfield.cpp.

References Widget::distributeActionEvent().

Referenced by Pincode::action(), and getCaretPosition().

843 {
845 }
void distributeActionEvent()
Definition: widget.cpp:492

◆ updateAlpha()

void TextField::updateAlpha ( )

Update the alpha value to the graphic components.

Definition at line 193 of file textfield.cpp.

References Theme::getMinimumOpacity(), ImageRect::grid, Settings::guiAlpha, mAlpha, Image::setAlpha(), settings, skin, and theme.

Referenced by draw().

194 {
195  const float alpha = std::max(settings.guiAlpha,
197 
198  if (alpha != mAlpha)
199  {
200  mAlpha = alpha;
201  for (int a = 0; a < 9; a++)
202  {
203  if (skin.grid[a] != nullptr)
204  skin.grid[a]->setAlpha(mAlpha);
205  }
206  }
207 }
float getMinimumOpacity() const
Definition: theme.h:123
Settings settings
Definition: settings.cpp:31
virtual void setAlpha(const float alpha)
Definition: image.cpp:286
Image * grid[9]
Definition: imagerect.h:41
static ImageRect skin
Definition: textfield.h:281
Theme * theme
Definition: theme.cpp:61
float guiAlpha
Definition: settings.h:129
static float mAlpha
Definition: textfield.h:280

◆ widgetHidden()

void TextField::widgetHidden ( const Event event)
virtual

Invoked when a widget is hidden, i.e it's set to be not visible.

Parameters
eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 816 of file textfield.cpp.

References TextChunk::deleteImage(), mTextChanged, and mTextChunk.

Referenced by getCaretPosition().

817 {
818  mTextChanged = true;
820 }
bool mTextChanged
Definition: textfield.h:290
TextChunk mTextChunk
Definition: textfield.h:264
void deleteImage()
Definition: textchunk.cpp:192

Field Documentation

◆ instances

int TextField::instances = 0
staticprotected

Definition at line 279 of file textfield.h.

Referenced by TextField(), and ~TextField().

◆ mAllowSpecialActions

bool TextField::mAllowSpecialActions
protected

Definition at line 288 of file textfield.h.

Referenced by handleCtrlKeys(), and setAllowSpecialActions().

◆ mAlpha

float TextField::mAlpha = 1.0
staticprotected

Definition at line 280 of file textfield.h.

Referenced by updateAlpha().

◆ mCaretColor

const Color* TextField::mCaretColor
protected

Definition at line 278 of file textfield.h.

Referenced by drawCaret().

◆ mCaretPosition

unsigned int TextField::mCaretPosition
protected

◆ mLastEventPaste

time_t TextField::mLastEventPaste
protected

Definition at line 284 of file textfield.h.

Referenced by handleCtrlKeys(), and keyPressed().

◆ mLoseFocusOnTab

LoseFocusOnTab TextField::mLoseFocusOnTab
protected

Definition at line 287 of file textfield.h.

Referenced by handleNormalKeys().

◆ mMaximum

int TextField::mMaximum
protected

Definition at line 283 of file textfield.h.

Referenced by getValue(), keyPressed(), setMaximum(), and setRange().

◆ mMinimum

int TextField::mMinimum
protected

Definition at line 282 of file textfield.h.

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

◆ mNumeric

bool TextField::mNumeric
protected

Definition at line 286 of file textfield.h.

Referenced by getValue(), keyPressed(), and setNumeric().

◆ mPadding

int TextField::mPadding
protected

Definition at line 285 of file textfield.h.

Referenced by adjustHeight(), adjustSize(), draw(), drawCaret(), fixScroll(), and TextField().

◆ mSendAlwaysEvents

bool TextField::mSendAlwaysEvents
protected

Definition at line 289 of file textfield.h.

Referenced by IntTextField::keyPressed(), keyPressed(), and setSendAlwaysEvents().

◆ mSkin

Skin * TextField::mSkin
staticprotected

Definition at line 257 of file textfield.h.

Referenced by TextField(), and ~TextField().

◆ mText

std::string TextField::mText
protected

◆ mTextChanged

bool TextField::mTextChanged
protected

◆ mTextChunk

TextChunk TextField::mTextChunk
protected

Definition at line 264 of file textfield.h.

Referenced by draw(), widgetHidden(), and ~TextField().

◆ mXScroll

int TextField::mXScroll
protected

Holds the amount scrolled in x. If a user types more characters than the text field can display, due to the text field being to small, the text needs to scroll in order to show the last type character.

Definition at line 276 of file textfield.h.

Referenced by draw(), fixScroll(), and mousePressed().

◆ skin

ImageRect TextField::skin
staticprotected

Definition at line 281 of file textfield.h.

Referenced by drawFrame(), safeDrawFrame(), TextField(), updateAlpha(), and ~TextField().


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