ManaPlus
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes

#include <button.h>

Inheritance diagram for Button:
Widget MouseListener KeyListener FocusListener WidgetListener Widget2

Public Types

enum  {
  BUTTON_STANDARD = 0 , BUTTON_HIGHLIGHTED , BUTTON_PRESSED , BUTTON_DISABLED ,
  BUTTON_COUNT
}
 

Public Member Functions

 Button (const Widget2 *const widget, const std::string &skinName)
 
 Button (const Widget2 *const widget, const std::string &caption, const std::string &actionEventId, const std::string &skinName, ActionListener *const listener)
 
 Button (const Widget2 *const widget, const std::string &caption, const std::string &imageName, const int imageWidth, const int imageHeight, const std::string &actionEventId, const std::string &skinName, ActionListener *const listener)
 
 Button (const Widget2 *const widget, const std::string &imageName, const int imageWidth, const int imageHeight, const std::string &actionEventId, const std::string &skinName, ActionListener *const listener)
 
 ~Button ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void updateAlpha ()
 
void mouseReleased (MouseEvent &event)
 
void setDescription (const std::string &text)
 
std::string getDescription () const
 
int getClickCount () const
 
void setTag (int tag)
 
int getTag () const
 
void setStick (bool b)
 
void setPressed (bool b)
 
void widgetResized (const Event &event)
 
void widgetMoved (const Event &event)
 
void widgetHidden (const Event &event)
 
void loadImage (const std::string &imageName)
 
void loadImageSet (const std::string &imageName)
 
void setImage (Image *const image)
 
void adjustSize ()
 
void keyPressed (KeyEvent &event)
 
void keyReleased (KeyEvent &event)
 
bool isPressed2 () const
 
void setCaption (const std::string &caption)
 
const std::string & getCaption () const
 
void setAlignment (Graphics::Alignment alignment)
 
Graphics::Alignment getAlignment () const
 
void focusLost (const Event &event)
 
void mousePressed (MouseEvent &event)
 
void mouseEntered (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
void mouseDragged (MouseEvent &event)
 
void setParent (Widget *widget)
 
void setWindow (Widget *const widget)
 
void setImageWidth (const int width)
 
void setImageHeight (const int height)
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
virtual void drawFrame (Graphics *graphics)
 
virtual void safeDrawFrame (Graphics *graphics)
 
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)
 
virtual void fontChanged ()
 
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 MouseListener
virtual ~MouseListener ()
 
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 KeyListener
virtual ~KeyListener ()
 
- Public Member Functions inherited from FocusListener
virtual ~FocusListener ()
 
virtual void focusGained (const Event &event)
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetShown (const Event &event)
 

Private Member Functions

bool isPressed () const
 
void init ()
 

Private Attributes

SkinmSkin [BUTTON_COUNT]
 
std::string mCaption
 
std::string mDescription
 
std::string mSkinName
 
TextChunk mTextChunk
 
ImageCollectionmVertexes2
 
Color mEnabledColor
 
Color mEnabledColor2
 
Color mDisabledColor
 
Color mDisabledColor2
 
Color mHighlightedColor
 
Color mHighlightedColor2
 
Color mPressedColor
 
Color mPressedColor2
 
Image ** mImages
 
ImageSetmImageSet
 
Graphics::Alignment mAlignment
 
int mClickCount
 
int mSpacing [BUTTON_COUNT]
 
int mTag
 
int mMode
 
int mXOffset
 
int mYOffset
 
int mImageWidth
 
int mImageHeight
 
bool mHasMouse
 
bool mKeyPressed
 
bool mMousePressed
 
bool mStick
 
bool mPressed
 
bool mTextChanged
 

Static Private Attributes

static float mAlpha = 1.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
 
- 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 MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from KeyListener
 KeyListener ()
 
- Protected Member Functions inherited from FocusListener
 FocusListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 
- 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 inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

Button widget. Same as the Guichan button but with custom look.

Definition at line 97 of file button.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
BUTTON_STANDARD 
BUTTON_HIGHLIGHTED 
BUTTON_PRESSED 
BUTTON_DISABLED 
BUTTON_COUNT 

Definition at line 264 of file button.h.

265  {
266  BUTTON_STANDARD = 0, // 0
267  BUTTON_HIGHLIGHTED, // 1
268  BUTTON_PRESSED, // 2
269  BUTTON_DISABLED, // 3
270  BUTTON_COUNT // 4 - Must be last.
271  };
@ BUTTON_DISABLED
Definition: button.h:269
@ BUTTON_COUNT
Definition: button.h:270
@ BUTTON_HIGHLIGHTED
Definition: button.h:267
@ BUTTON_STANDARD
Definition: button.h:266
@ BUTTON_PRESSED
Definition: button.h:268

Constructor & Destructor Documentation

◆ Button() [1/4]

Button::Button ( const Widget2 *const  widget,
const std::string &  skinName 
)

Default constructor.

Definition at line 99 of file button.cpp.

100  :
101  Widget(widget),
102  MouseListener(),
103  KeyListener(),
104  FocusListener(),
105  WidgetListener(),
106  mSkin(),
107  mCaption(),
108  mDescription(),
109  mSkinName(skinName),
110  mTextChunk(),
112  mEnabledColor(getThemeColor(ThemeColorId::BUTTON, 255U)),
113  mEnabledColor2(getThemeColor(ThemeColorId::BUTTON_OUTLINE, 255U)),
114  mDisabledColor(getThemeColor(ThemeColorId::BUTTON_DISABLED, 255U)),
115  mDisabledColor2(getThemeColor(ThemeColorId::BUTTON_DISABLED_OUTLINE,
116  255U)),
117  mHighlightedColor(getThemeColor(ThemeColorId::BUTTON_HIGHLIGHTED, 255U)),
119  ThemeColorId::BUTTON_HIGHLIGHTED_OUTLINE, 255U)),
120  mPressedColor(getThemeColor(ThemeColorId::BUTTON_PRESSED, 255U)),
121  mPressedColor2(getThemeColor(ThemeColorId::BUTTON_PRESSED_OUTLINE, 255U)),
122  mImages(nullptr),
123  mImageSet(nullptr),
125  mClickCount(0),
126  mSpacing(),
127  mTag(0),
128  mMode(0),
129  mXOffset(0),
130  mYOffset(0),
131  mImageWidth(0),
132  mImageHeight(0),
133  mHasMouse(false),
134  mKeyPressed(false),
135  mMousePressed(false),
136  mStick(false),
137  mPressed(false),
138  mTextChanged(true)
139 {
140  init();
141  adjustSize();
142 }
int mSpacing[BUTTON_COUNT]
Definition: button.h:320
bool mStick
Definition: button.h:343
bool mHasMouse
Definition: button.h:331
int mImageHeight
Definition: button.h:327
Color mEnabledColor
Definition: button.h:299
bool mTextChanged
Definition: button.h:345
void init()
Definition: button.cpp:307
ImageCollection * mVertexes2
Definition: button.h:298
std::string mCaption
Definition: button.h:290
int mTag
Definition: button.h:322
int mMode
Definition: button.h:323
Color mPressedColor
Definition: button.h:305
void adjustSize()
Definition: button.cpp:799
ImageSet * mImageSet
Definition: button.h:308
Color mHighlightedColor2
Definition: button.h:304
TextChunk mTextChunk
Definition: button.h:296
int mImageWidth
Definition: button.h:326
Skin * mSkin[BUTTON_COUNT]
Definition: button.h:286
Color mDisabledColor2
Definition: button.h:302
std::string mSkinName
Definition: button.h:294
Color mPressedColor2
Definition: button.h:306
Color mHighlightedColor
Definition: button.h:303
Color mDisabledColor
Definition: button.h:301
bool mKeyPressed
Definition: button.h:336
Color mEnabledColor2
Definition: button.h:300
int mClickCount
Definition: button.h:315
Graphics::Alignment mAlignment
Definition: button.h:313
int mYOffset
Definition: button.h:325
std::string mDescription
Definition: button.h:292
Image ** mImages
Definition: button.h:307
int mXOffset
Definition: button.h:324
bool mPressed
Definition: button.h:344
bool mMousePressed
Definition: button.h:341
@ CENTER
Definition: graphics.h:132
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:45
Widget(const Widget2 *const widget)
Definition: widget.cpp:85

References adjustSize(), and init().

◆ Button() [2/4]

Button::Button ( const Widget2 *const  widget,
const std::string &  caption,
const std::string &  actionEventId,
const std::string &  skinName,
ActionListener *const  listener 
)

Constructor, sets the caption of the button to the given string and adds the given action listener.

Definition at line 144 of file button.cpp.

148  :
149  Widget(widget),
150  MouseListener(),
151  KeyListener(),
152  FocusListener(),
153  WidgetListener(),
154  mSkin(),
155  mCaption(caption),
156  mDescription(),
157  mSkinName(skinName),
158  mTextChunk(),
160  mEnabledColor(getThemeColor(ThemeColorId::BUTTON, 255U)),
161  mEnabledColor2(getThemeColor(ThemeColorId::BUTTON_OUTLINE, 255U)),
162  mDisabledColor(getThemeColor(ThemeColorId::BUTTON_DISABLED, 255U)),
163  mDisabledColor2(getThemeColor(ThemeColorId::BUTTON_DISABLED_OUTLINE,
164  255U)),
165  mHighlightedColor(getThemeColor(ThemeColorId::BUTTON_HIGHLIGHTED, 255U)),
167  ThemeColorId::BUTTON_HIGHLIGHTED_OUTLINE, 255U)),
168  mPressedColor(getThemeColor(ThemeColorId::BUTTON_PRESSED, 255U)),
169  mPressedColor2(getThemeColor(ThemeColorId::BUTTON_PRESSED_OUTLINE, 255U)),
170  mImages(nullptr),
171  mImageSet(nullptr),
173  mClickCount(0),
174  mSpacing(),
175  mTag(0),
176  mMode(0),
177  mXOffset(0),
178  mYOffset(0),
179  mImageWidth(0),
180  mImageHeight(0),
181  mHasMouse(false),
182  mKeyPressed(false),
183  mMousePressed(false),
184  mStick(false),
185  mPressed(false),
186  mTextChanged(true)
187 {
188  init();
189  adjustSize();
190  setActionEventId(actionEventId);
191 
192  if (listener != nullptr)
194 }
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:596
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:252

References Widget::addActionListener(), adjustSize(), init(), anonymous_namespace{itemlinkhandler.cpp}::listener, and Widget::setActionEventId().

◆ Button() [3/4]

Button::Button ( const Widget2 *const  widget,
const std::string &  caption,
const std::string &  imageName,
const int  imageWidth,
const int  imageHeight,
const std::string &  actionEventId,
const std::string &  skinName,
ActionListener *const  listener 
)

Constructor, sets the caption of the button to the given string and adds the given action listener.

Definition at line 196 of file button.cpp.

203  :
204  Widget(widget),
205  MouseListener(),
206  KeyListener(),
207  FocusListener(),
208  WidgetListener(),
209  mSkin(),
210  mCaption(caption),
211  mDescription(),
212  mSkinName(skinName),
213  mTextChunk(),
215  mEnabledColor(getThemeColor(ThemeColorId::BUTTON, 255U)),
216  mEnabledColor2(getThemeColor(ThemeColorId::BUTTON_OUTLINE, 255U)),
217  mDisabledColor(getThemeColor(ThemeColorId::BUTTON_DISABLED, 255U)),
218  mDisabledColor2(getThemeColor(ThemeColorId::BUTTON_DISABLED_OUTLINE,
219  255U)),
220  mHighlightedColor(getThemeColor(ThemeColorId::BUTTON_HIGHLIGHTED, 255U)),
222  ThemeColorId::BUTTON_HIGHLIGHTED_OUTLINE, 255U)),
223  mPressedColor(getThemeColor(ThemeColorId::BUTTON_PRESSED, 255U)),
224  mPressedColor2(getThemeColor(ThemeColorId::BUTTON_PRESSED_OUTLINE, 255U)),
225  mImages(nullptr),
226  mImageSet(nullptr),
228  mClickCount(0),
229  mSpacing(),
230  mTag(0),
231  mMode(0),
232  mXOffset(0),
233  mYOffset(0),
234  mImageWidth(imageWidth),
235  mImageHeight(imageHeight),
236  mHasMouse(false),
237  mKeyPressed(false),
238  mMousePressed(false),
239  mStick(false),
240  mPressed(false),
241  mTextChanged(true)
242 {
243  init();
244  loadImageSet(imageName);
245  adjustSize();
246  setActionEventId(actionEventId);
247 
248  if (listener != nullptr)
250 }
void loadImageSet(const std::string &imageName)
Definition: button.cpp:395

References Widget::addActionListener(), adjustSize(), init(), anonymous_namespace{itemlinkhandler.cpp}::listener, loadImageSet(), and Widget::setActionEventId().

◆ Button() [4/4]

Button::Button ( const Widget2 *const  widget,
const std::string &  imageName,
const int  imageWidth,
const int  imageHeight,
const std::string &  actionEventId,
const std::string &  skinName,
ActionListener *const  listener 
)

Constructor, sets the caption of the button to the given string and adds the given action listener.

Definition at line 252 of file button.cpp.

258  :
259  Widget(widget),
260  MouseListener(),
261  KeyListener(),
262  FocusListener(),
263  WidgetListener(),
264  mSkin(),
265  mCaption(),
266  mDescription(),
267  mSkinName(skinName),
268  mTextChunk(),
270  mEnabledColor(getThemeColor(ThemeColorId::BUTTON, 255U)),
271  mEnabledColor2(getThemeColor(ThemeColorId::BUTTON_OUTLINE, 255U)),
272  mDisabledColor(getThemeColor(ThemeColorId::BUTTON_DISABLED, 255U)),
273  mDisabledColor2(getThemeColor(ThemeColorId::BUTTON_DISABLED_OUTLINE,
274  255U)),
275  mHighlightedColor(getThemeColor(ThemeColorId::BUTTON_HIGHLIGHTED, 255U)),
277  ThemeColorId::BUTTON_HIGHLIGHTED_OUTLINE, 255U)),
278  mPressedColor(getThemeColor(ThemeColorId::BUTTON_PRESSED, 255U)),
279  mPressedColor2(getThemeColor(ThemeColorId::BUTTON_PRESSED_OUTLINE, 255U)),
280  mImages(nullptr),
281  mImageSet(nullptr),
283  mClickCount(0),
284  mSpacing(),
285  mTag(0),
286  mMode(0),
287  mXOffset(0),
288  mYOffset(0),
289  mImageWidth(imageWidth),
290  mImageHeight(imageHeight),
291  mHasMouse(false),
292  mKeyPressed(false),
293  mMousePressed(false),
294  mStick(false),
295  mPressed(false),
296  mTextChanged(true)
297 {
298  init();
299  loadImageSet(imageName);
300  adjustSize();
301  setActionEventId(actionEventId);
302 
303  if (listener != nullptr)
305 }

References Widget::addActionListener(), adjustSize(), init(), anonymous_namespace{itemlinkhandler.cpp}::listener, loadImageSet(), and Widget::setActionEventId().

◆ ~Button()

Button::~Button ( )

Destructor.

Definition at line 337 of file button.cpp.

338 {
339  if (mWindow != nullptr)
341 
342  if (gui != nullptr)
343  gui->removeDragged(this);
344 
345  if (theme != nullptr)
346  {
347  for (int mode = 0; mode < BUTTON_COUNT; mode ++)
348  theme->unload(mSkin[mode]);
349  }
351  if (mImageSet != nullptr)
352  {
353  mImageSet->decRef();
354  mImageSet = nullptr;
355  }
356  if (mImages != nullptr)
357  {
358  for (int f = 0; f < BUTTON_COUNT; f ++)
359  mImages[f] = nullptr;
360  delete [] mImages;
361  mImages = nullptr;
362  }
364 }
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1162
virtual void decRef()
Definition: resource.cpp:50
void deleteImage()
Definition: textchunk.cpp:193
void unload(Skin *const skin)
Definition: theme.cpp:250
Widget * mWindow
Definition: widget2.h:112
void removeWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:307
#define delete2(var)
Definition: delete2.h:25
Gui * gui
Definition: gui.cpp:111
Theme * theme
Definition: theme.cpp:62

References BUTTON_COUNT, Resource::decRef(), delete2, TextChunk::deleteImage(), gui, mImages, mImageSet, mSkin, mTextChunk, mVertexes2, Widget2::mWindow, Gui::removeDragged(), Widget::removeWidgetListener(), theme, and Theme::unload().

Member Function Documentation

◆ adjustSize()

void Button::adjustSize ( )

Definition at line 799 of file button.cpp.

800 {
801  const Font *const font = getFont();
802  const Skin *const skin = mSkin[BUTTON_STANDARD];
803  if (skin == nullptr)
804  return;
805  const int padding = skin->getPadding();
806 
807  if (mImages != nullptr)
808  {
809  const int width = font->getWidth(mCaption);
810  if (width != 0)
811  {
812  const int spacing = mSpacing[BUTTON_STANDARD];
813  setWidth(width + mImageWidth + spacing + 2 * padding);
814  }
815  else
816  {
817  setWidth(mImageWidth + 2 * padding);
818  }
819  int height = font->getHeight();
820  if (height < mImageHeight)
821  height = mImageHeight;
822  setHeight(height + 2 * padding);
823  }
824  else
825  {
826  setWidth(font->getWidth(mCaption) + 2 * padding);
827  setHeight(font->getHeight() + 2 * padding);
828  }
829 }
Definition: font.h:90
int getHeight() const
Definition: font.cpp:362
int getWidth(const std::string &text) const
Definition: font.cpp:334
Definition: skin.h:37
int getPadding() const
Definition: skin.h:100
void setWidth(const int width)
Definition: widget.cpp:133
void setHeight(const int height)
Definition: widget.cpp:140
Font * getFont() const
Definition: widget.cpp:331

References BUTTON_STANDARD, Widget::getFont(), Font::getHeight(), Skin::getPadding(), Font::getWidth(), mCaption, mImageHeight, mImages, mImageWidth, mSkin, mSpacing, Widget::setHeight(), and Widget::setWidth().

Referenced by WindowMenu::addButton(), Pincode::addButtons(), Button(), ChatWindow::ChatWindow(), NpcDialog::createSkinControls(), TabStrip::createWidget(), BuyDialog::init(), EggSelectionDialog::initButtons(), InsertCardDialog::initButtons(), ItemAmountWindow::ItemAmountWindow(), SellDialog::postInit(), StatDebugTab::StatDebugTab(), TextCommandEditor::TextCommandEditor(), and ShopWindow::updateButtonsAndLabels().

◆ draw()

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

Draws the button.

Implements Widget.

Definition at line 443 of file button.cpp.

444 {
445  BLOCK_START("Button::draw")
446  int mode;
447 
448  if (!isEnabled())
449  mode = BUTTON_DISABLED;
450  else if (isPressed2())
451  mode = BUTTON_PRESSED;
452  else if (mHasMouse)
453  mode = BUTTON_HIGHLIGHTED;
454  else
455  mode = BUTTON_STANDARD;
456 
457  const Skin *const skin = mSkin[mode];
458  if (skin == nullptr)
459  {
460  BLOCK_END("Button::draw")
461  return;
462  }
463 
464  updateAlpha();
465 
466  bool recalc = false;
467  if (mRedraw)
468  {
469  recalc = true;
470  }
471  else
472  {
473  // because we don't know where parent windows was moved,
474  // need recalc vertexes
475  ClipRect &rect = graphics->getTopClip();
476  if (rect.xOffset != mXOffset || rect.yOffset != mYOffset)
477  {
478  recalc = true;
479  mXOffset = rect.xOffset;
480  mYOffset = rect.yOffset;
481  }
482  else if (mMode != mode)
483  {
484  recalc = true;
485  mMode = mode;
486  }
487  else if (graphics->getRedraw())
488  {
489  recalc = true;
490  }
491  }
492 
493  const int padding = skin->getPadding();
494  const int spacing = mSpacing[mode];
495 
496  if (recalc)
497  mTextChanged = true;
498 
499  int imageX = 0;
500  int imageY = 0;
501  int textX = 0;
502  const Rect &rect = mDimension;
503  const int width = rect.width;
504  const int height = rect.height;
505  Font *const font = getFont();
506  int textY = height / 2 - font->getHeight() / 2;
507  if (mImages != nullptr)
508  imageY = height / 2 - mImageHeight / 2;
509 
510 // need move calculation from draw!!!
511 
512  switch (mAlignment)
513  {
514  default:
515  case Graphics::LEFT:
516  {
517  if (mImages != nullptr)
518  {
519  imageX = padding;
520  textX = padding + mImageWidth + spacing;
521  }
522  else
523  {
524  textX = padding;
525  }
526  break;
527  }
528  case Graphics::CENTER:
529  {
530  const int width1 = font->getWidth(mCaption);
531  if (mImages != nullptr)
532  {
533  const int w = width1 + mImageWidth + spacing;
534  imageX = (width - w) / 2;
535  textX = imageX + mImageWidth + spacing - width1 / 2;
536  }
537  else
538  {
539  textX = (width - width1) / 2;
540  }
541  break;
542  }
543  case Graphics::RIGHT:
544  {
545  const int width1 = font->getWidth(mCaption);
546  textX = width - width1 - padding;
547  imageX = textX - width1 - spacing;
548  break;
549  }
550  }
551 
552  if (recalc)
553  {
554  mRedraw = false;
555  mMode = mode;
556  mVertexes2->clear();
557  graphics->calcWindow(mVertexes2,
558  0, 0,
559  width, height,
560  skin->getBorder());
561 
562  if (mImages != nullptr)
563  {
564  if (isPressed())
565  {
566  graphics->calcTileCollection(mVertexes2,
567  mImages[mode],
568  imageX + 1, imageY + 1);
569  }
570  else
571  {
572  graphics->calcTileCollection(mVertexes2,
573  mImages[mode],
574  imageX, imageY);
575  }
576  }
577  graphics->finalize(mVertexes2);
578  }
579  graphics->drawTileCollection(mVertexes2);
580 
581  if (isPressed())
582  {
583  textX ++;
584  textY ++;
585  }
586 
587  if (mTextChanged)
588  {
589  mTextChunk.textFont = font;
592  switch (mode)
593  {
594  case BUTTON_DISABLED:
597  break;
598  case BUTTON_PRESSED:
601  break;
602  case BUTTON_HIGHLIGHTED:
605  break;
606  default:
609  break;
610  }
611  font->generate(mTextChunk);
612  mTextChanged = false;
613  }
614 
615  const Image *const image = mTextChunk.img;
616  if (image != nullptr)
617  graphics->drawImage(image, textX, textY);
618 
619  BLOCK_END("Button::draw")
620 }
void updateAlpha()
Definition: button.cpp:418
bool isPressed() const
Definition: button.cpp:861
bool isPressed2() const
Definition: button.cpp:856
int yOffset
Definition: cliprect.h:127
int xOffset
Definition: cliprect.h:122
void generate(TextChunk &chunk)
Definition: font.cpp:430
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
virtual void drawTileCollection(const ImageCollection *const vertCol)=0
bool getRedraw() const
Definition: graphics.h:287
virtual void calcTileCollection(ImageCollection *const vertCol, const Image *const image, int x, int y)=0
virtual void finalize(ImageCollection *const col)
Definition: graphics.h:465
virtual void calcWindow(ImageCollection *const vertCol, const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0
ClipRect & getTopClip() const
Definition: graphics.h:281
Definition: rect.h:74
int width
Definition: rect.h:219
int height
Definition: rect.h:224
Font * textFont
Definition: textchunk.h:64
Image * img
Definition: textchunk.h:63
Color color
Definition: textchunk.h:66
Color color2
Definition: textchunk.h:67
std::string text
Definition: textchunk.h:65
Rect mDimension
Definition: widget.h:1101
bool mRedraw
Definition: widget.h:1164
bool isEnabled() const
Definition: widget.cpp:375
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79

References BLOCK_END, BLOCK_START, BUTTON_DISABLED, BUTTON_HIGHLIGHTED, BUTTON_PRESSED, BUTTON_STANDARD, Graphics::calcTileCollection(), Graphics::calcWindow(), Graphics::CENTER, ImageCollection::clear(), TextChunk::color, TextChunk::color2, TextChunk::deleteImage(), Graphics::drawImage(), Graphics::drawTileCollection(), Graphics::finalize(), Font::generate(), Skin::getBorder(), Widget::getFont(), Font::getHeight(), Skin::getPadding(), Graphics::getRedraw(), Graphics::getTopClip(), Font::getWidth(), Rect::height, TextChunk::img, Widget::isEnabled(), isPressed(), isPressed2(), Graphics::LEFT, mAlignment, mCaption, Widget::mDimension, mDisabledColor, mDisabledColor2, mEnabledColor, mEnabledColor2, mHasMouse, mHighlightedColor, mHighlightedColor2, mImageHeight, mImages, mImageWidth, mMode, mPressedColor, mPressedColor2, Widget::mRedraw, mSkin, mSpacing, mTextChanged, mTextChunk, mVertexes2, mXOffset, mYOffset, Graphics::RIGHT, TextChunk::text, TextChunk::textFont, updateAlpha(), Rect::width, ClipRect::xOffset, and ClipRect::yOffset.

◆ focusLost()

void Button::focusLost ( const Event event)
virtual

Called when a widget loses focus.

Parameters
eventDiscribes the event.

Reimplemented from FocusListener.

Definition at line 868 of file button.cpp.

869 {
870  mMousePressed = false;
871  mKeyPressed = false;
872 }

References mKeyPressed, and mMousePressed.

◆ getAlignment()

Graphics::Alignment Button::getAlignment ( ) const
inline

Gets the alignment of the caption.

Returns
The alignment of the caption.
See also
setAlignment, Graphics

Definition at line 241 of file button.h.

242  { return mAlignment; }

References mAlignment.

◆ getCaption()

const std::string& Button::getCaption ( ) const
inline

Gets the caption of the button.

Returns
The caption of the button.

Definition at line 222 of file button.h.

223  { return mCaption; }

References mCaption.

Referenced by PopupMenu::showPopup().

◆ getClickCount()

int Button::getClickCount ( ) const
inline

Definition at line 171 of file button.h.

172  { return mClickCount; }

References mClickCount.

Referenced by ChangeDisplay::action().

◆ getDescription()

std::string Button::getDescription ( ) const
inline

Definition at line 168 of file button.h.

169  { return mDescription; }

References mDescription.

Referenced by WindowMenu::mouseMoved(), InventoryWindow::mouseMoved(), and PopupMenu::showPopup().

◆ getTag()

int Button::getTag ( ) const
inline

Definition at line 177 of file button.h.

178  { return mTag; }

References mTag.

Referenced by EquipmentWindow::action(), and WindowMenu::mouseMoved().

◆ init()

void Button::init ( )
private

Definition at line 307 of file button.cpp.

308 {
309  mAllowLogic = false;
310  addMouseListener(this);
311  addKeyListener(this);
312  addFocusListener(this);
313  addWidgetListener(this);
314 
315  setFocusable(true);
316  setFrameSize(0);
317 
318  if (theme != nullptr)
319  {
320  for (int mode = 0; mode < BUTTON_COUNT; mode ++)
321  {
322  Skin *const skin = theme->load(mSkinName + data[mode],
323  "button.xml",
324  true,
326  if (skin != nullptr)
327  {
328  mSkin[mode] = skin;
329  mSpacing[mode] = skin->getOption("spacing");
330  }
331  }
332  }
333 
334  updateAlpha();
335 }
static std::string const data[Button::BUTTON_COUNT]
Definition: button.cpp:91
int getOption(const std::string &name) const
Definition: skin.h:106
static std::string getThemePath()
Definition: theme.h:67
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:179
void setFrameSize(const unsigned int frameSize)
Definition: widget.h:168
void setFocusable(const bool focusable)
Definition: widget.cpp:192
bool mAllowLogic
Definition: widget.h:1160
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:292
void addWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:302
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:272
void addFocusListener(FocusListener *const focusListener)
Definition: widget.cpp:282

References Widget::addFocusListener(), Widget::addKeyListener(), Widget::addMouseListener(), Widget::addWidgetListener(), BUTTON_COUNT, data, Skin::getOption(), Theme::getThemePath(), Theme::load(), Widget::mAllowLogic, mSkin, mSkinName, mSpacing, Widget::setFocusable(), Widget::setFrameSize(), theme, and updateAlpha().

Referenced by Button().

◆ isPressed()

bool Button::isPressed ( ) const
private

Checks if the button is pressed. Convenient method to use when overloading the draw method of the button.

Returns
True if the button is pressed, false otherwise.

Definition at line 861 of file button.cpp.

862 {
863  if (mMousePressed)
864  return mHasMouse;
865  return mKeyPressed;
866 }

References mHasMouse, mKeyPressed, and mMousePressed.

Referenced by draw(), isPressed2(), and safeDraw().

◆ isPressed2()

bool Button::isPressed2 ( ) const

Definition at line 856 of file button.cpp.

857 {
858  return mPressed || isPressed();
859 }

References isPressed(), and mPressed.

Referenced by TabStrip::action(), draw(), TabStrip::nextTab(), TabStrip::prevTab(), and safeDraw().

◆ keyPressed()

void Button::keyPressed ( KeyEvent event)
virtual

Called if a key is pressed when the widget has keyboard focus. If a key is held down the widget will generate multiple key presses.

Parameters
eventDiscribes the event.

Reimplemented from KeyListener.

Definition at line 831 of file button.cpp.

832 {
833  const InputActionT action = event.getActionId();
834 
835  if (action == InputAction::GUI_SELECT)
836  {
837  mKeyPressed = true;
838  event.consume();
839  }
840 }
InputAction ::T InputActionT
Definition: inputaction.h:717

References InputAction::GUI_SELECT, and mKeyPressed.

◆ keyReleased()

void Button::keyReleased ( KeyEvent event)
virtual

Called if a key is released when the widget has keyboard focus.

Parameters
eventDiscribes the event.

Reimplemented from KeyListener.

Definition at line 842 of file button.cpp.

843 {
844  const InputActionT action = event.getActionId();
845 
846  if (action == InputAction::GUI_SELECT && mKeyPressed)
847  {
848  mKeyPressed = false;
849  if (mStick)
850  mPressed = !mPressed;
852  event.consume();
853  }
854 }
void distributeActionEvent()
Definition: widget.cpp:493

References Widget::distributeActionEvent(), InputAction::GUI_SELECT, mKeyPressed, mPressed, and mStick.

◆ loadImage()

void Button::loadImage ( const std::string &  imageName)

Definition at line 366 of file button.cpp.

367 {
368  if (mImageSet != nullptr)
369  {
370  mImageSet->decRef();
371  mImageSet = nullptr;
372  }
373  Image *const image = Theme::getImageFromThemeXml(imageName, "");
374  mImages = new Image*[BUTTON_COUNT];
375  for (int f = 0; f < BUTTON_COUNT; f ++)
376  mImages[f] = image;
377 }
static Image * getImageFromThemeXml(const std::string &name, const std::string &name2)
Definition: theme.cpp:926

References BUTTON_COUNT, Resource::decRef(), Theme::getImageFromThemeXml(), mImages, and mImageSet.

◆ loadImageSet()

void Button::loadImageSet ( const std::string &  imageName)

Definition at line 395 of file button.cpp.

396 {
397  if (mImageSet != nullptr)
398  {
399  mImageSet->decRef();
400  mImageSet = nullptr;
401  }
404  if (mImageSet == nullptr)
405  return;
406  mImages = new Image*[BUTTON_COUNT];
407  mImages[0] = nullptr;
408  for (size_t f = 0; f < BUTTON_COUNT; f ++)
409  {
410  Image *const img = mImageSet->get(f);
411  if (img != nullptr)
412  mImages[f] = img;
413  else
414  mImages[f] = mImages[0];
415  }
416 }
Image * get(const size_type i) const
Definition: imageset.cpp:67
static ImageSet * getImageSetFromTheme(const std::string &path, const int w, const int h)
Definition: theme.cpp:660

References BUTTON_COUNT, Resource::decRef(), ImageSet::get(), Theme::getImageSetFromTheme(), mImageHeight, mImages, mImageSet, and mImageWidth.

Referenced by Button(), and NpcDialog::createSkinControls().

◆ mouseDragged()

void Button::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 893 of file button.cpp.

894 {
895  event.consume();
896 }

◆ mouseEntered()

void Button::mouseEntered ( MouseEvent event)
virtual

Called when the mouse has entered into the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 883 of file button.cpp.

884 {
885  mHasMouse = true;
886 }

References mHasMouse.

◆ mouseExited()

void Button::mouseExited ( MouseEvent event)
virtual

Called when the mouse has exited the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 888 of file button.cpp.

889 {
890  mHasMouse = false;
891 }

References mHasMouse.

◆ mousePressed()

void Button::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 874 of file button.cpp.

875 {
876  if (event.getButton() == MouseButton::LEFT)
877  {
878  mMousePressed = true;
879  event.consume();
880  }
881 }
MouseButtonT getButton() const
Definition: mouseevent.h:116

References MouseEvent::getButton(), MouseButton::LEFT, and mMousePressed.

◆ mouseReleased()

void Button::mouseReleased ( MouseEvent event)
virtual

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

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 758 of file button.cpp.

759 {
760  if (event.getButton() == MouseButton::LEFT)
761  {
762  if (mStick)
763  mPressed = !mPressed;
764 
765  if (mMousePressed && mHasMouse)
766  {
767  mMousePressed = false;
768  mClickCount = event.getClickCount();
770  }
771  else
772  {
773  mMousePressed = false;
774  mClickCount = 0;
775  }
776  event.consume();
777  }
778 }

References Widget::distributeActionEvent(), MouseEvent::getButton(), MouseButton::LEFT, mClickCount, mHasMouse, mMousePressed, mPressed, and mStick.

◆ safeDraw()

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

Implements Widget.

Definition at line 622 of file button.cpp.

623 {
624  BLOCK_START("Button::safeDraw")
625  int mode;
626 
627  if (!isEnabled())
628  mode = BUTTON_DISABLED;
629  else if (isPressed2())
630  mode = BUTTON_PRESSED;
631  else if (mHasMouse || isFocused())
632  mode = BUTTON_HIGHLIGHTED;
633  else
634  mode = BUTTON_STANDARD;
635 
636  const Skin *const skin = mSkin[mode];
637  if (skin == nullptr)
638  {
639  BLOCK_END("Button::safeDraw")
640  return;
641  }
642 
643  updateAlpha();
644 
645  if (mMode != mode)
646  {
647  mTextChanged = true;
648  mMode = mode;
649  }
650 
651  const int padding = skin->getPadding();
652  const int spacing = mSpacing[mode];
653 
654  int imageX = 0;
655  int imageY = 0;
656  int textX = 0;
657  const Rect &rect = mDimension;
658  const int width = rect.width;
659  const int height = rect.height;
660  Font *const font = getFont();
661  int textY = height / 2 - font->getHeight() / 2;
662  if (mImages != nullptr)
663  imageY = height / 2 - mImageHeight / 2;
664 
665 // need move calculation from draw!!!
666 
667  switch (mAlignment)
668  {
669  default:
670  case Graphics::LEFT:
671  {
672  if (mImages != nullptr)
673  {
674  imageX = padding;
675  textX = padding + mImageWidth + spacing;
676  }
677  else
678  {
679  textX = padding;
680  }
681  break;
682  }
683  case Graphics::CENTER:
684  {
685  const int width1 = font->getWidth(mCaption);
686  if (mImages != nullptr)
687  {
688  const int w = width1 + mImageWidth + spacing;
689  imageX = (width - w) / 2;
690  textX = imageX + mImageWidth + spacing - width1 / 2;
691  }
692  else
693  {
694  textX = (width - width1) / 2;
695  }
696  break;
697  }
698  case Graphics::RIGHT:
699  {
700  const int width1 = font->getWidth(mCaption);
701  textX = width - width1 - padding;
702  imageX = textX - width1 - spacing;
703  break;
704  }
705  }
706 
707  graphics->drawImageRect(0, 0, width, height, skin->getBorder());
708 
709  if (mImages != nullptr)
710  {
711  if (isPressed())
712  graphics->drawImage(mImages[mode], imageX + 1, imageY + 1);
713  else
714  graphics->drawImage(mImages[mode], imageX, imageY);
715  }
716 
717  if (isPressed())
718  {
719  textX ++;
720  textY ++;
721  }
722 
723  if (mTextChanged)
724  {
725  mTextChunk.textFont = font;
728  switch (mode)
729  {
730  case BUTTON_DISABLED:
733  break;
734  case BUTTON_PRESSED:
737  break;
738  case BUTTON_HIGHLIGHTED:
741  break;
742  default:
745  break;
746  }
747  font->generate(mTextChunk);
748  mTextChanged = false;
749  }
750 
751  const Image *const image = mTextChunk.img;
752  if (image != nullptr)
753  graphics->drawImage(image, textX, textY);
754 
755  BLOCK_END("Button::safeDraw")
756 }
virtual void drawImageRect(const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0
virtual bool isFocused() const
Definition: widget.cpp:184

References BLOCK_END, BLOCK_START, BUTTON_DISABLED, BUTTON_HIGHLIGHTED, BUTTON_PRESSED, BUTTON_STANDARD, Graphics::CENTER, TextChunk::color, TextChunk::color2, TextChunk::deleteImage(), Graphics::drawImage(), Graphics::drawImageRect(), Font::generate(), Skin::getBorder(), Widget::getFont(), Font::getHeight(), Skin::getPadding(), Font::getWidth(), Rect::height, TextChunk::img, Widget::isEnabled(), Widget::isFocused(), isPressed(), isPressed2(), Graphics::LEFT, mAlignment, mCaption, Widget::mDimension, mDisabledColor, mDisabledColor2, mEnabledColor, mEnabledColor2, mHasMouse, mHighlightedColor, mHighlightedColor2, mImageHeight, mImages, mImageWidth, mMode, mPressedColor, mPressedColor2, mSkin, mSpacing, mTextChanged, mTextChunk, Graphics::RIGHT, TextChunk::text, TextChunk::textFont, updateAlpha(), and Rect::width.

◆ setAlignment()

void Button::setAlignment ( Graphics::Alignment  alignment)
inline

Sets the alignment of the caption. The alignment is relative to the center of the button.

Parameters
alignmentThe alignment of the caption.
See also
getAlignment, Graphics

Definition at line 232 of file button.h.

233  { mAlignment = alignment; }

References mAlignment.

◆ setCaption()

void Button::setCaption ( const std::string &  caption)
inline

Sets the caption of the button. It's advisable to call adjustSize after setting of the caption to adjust the button's size to fit the caption.

Parameters
captionThe caption of the button.
See also
getCaption, adjustSize

Definition at line 214 of file button.h.

215  { mCaption = caption; mTextChanged = true; }

References mCaption, and mTextChanged.

Referenced by Setup_Joystick::action(), SkillDialog::action(), NpcDialog::buildLayout(), NpcDialog::createSkinControls(), TabStrip::createWidget(), EggSelectionDialog::initButtons(), InsertCardDialog::initButtons(), TradeWindow::setStatus(), Pincode::shuffle(), InventoryWindow::updateButtons(), ShopWindow::updateButtonsAndLabels(), InventoryWindow::updateDropButton(), CharSelectDialog::updateState(), and SkillDialog::updateTabSelection().

◆ setDescription()

void Button::setDescription ( const std::string &  text)
inline

Definition at line 165 of file button.h.

166  { mDescription = text; }

References mDescription.

Referenced by WindowMenu::addButton(), and InventoryWindow::InventoryWindow().

◆ setImage()

void Button::setImage ( Image *const  image)

Definition at line 379 of file button.cpp.

380 {
381  if (image == nullptr)
382  return;
383  if (mImageSet != nullptr)
384  {
385  mImageSet->decRef();
386  mImageSet = nullptr;
387  }
388  mImageWidth = image->getWidth();
389  mImageHeight = image->getHeight();
390  mImages = new Image*[BUTTON_COUNT];
391  for (int f = 0; f < BUTTON_COUNT; f ++)
392  mImages[f] = image;
393 }

References BUTTON_COUNT, Resource::decRef(), mImageHeight, mImages, mImageSet, and mImageWidth.

Referenced by WindowMenu::addButton().

◆ setImageHeight()

void Button::setImageHeight ( const int  height)
inline

Definition at line 261 of file button.h.

262  { mImageHeight = height; }

References mImageHeight.

Referenced by NpcDialog::createSkinControls().

◆ setImageWidth()

void Button::setImageWidth ( const int  width)
inline

Definition at line 258 of file button.h.

259  { mImageWidth = width; }

References mImageWidth.

Referenced by NpcDialog::createSkinControls().

◆ setParent()

void Button::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 898 of file button.cpp.

899 {
900  if (mWindow != nullptr)
901  mWindow->addWidgetListener(this);
902  Widget::setParent(widget);
903 }
virtual void setParent(Widget *parent)
Definition: widget.h:626

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

◆ setPressed()

void Button::setPressed ( bool  b)
inline

Definition at line 183 of file button.h.

184  { mPressed = b; }

References mPressed.

Referenced by TabStrip::action(), TabStrip::createWidget(), TabStrip::nextTab(), and TabStrip::prevTab().

◆ setStick()

void Button::setStick ( bool  b)
inline

Definition at line 180 of file button.h.

181  { mStick = b; }

References mStick.

Referenced by TabStrip::createWidget().

◆ setTag()

void Button::setTag ( int  tag)
inline

Definition at line 174 of file button.h.

175  { mTag = tag; }

References mTag.

Referenced by WindowMenu::addButton(), and TabStrip::createWidget().

◆ setWindow()

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

Reimplemented from Widget2.

Definition at line 905 of file button.cpp.

906 {
907  if ((widget == nullptr) && (mWindow != nullptr))
908  {
910  mWindow = nullptr;
911  }
912  else
913  {
914  Widget2::setWindow(widget);
915  }
916 }
virtual void setWindow(Widget *const window)
Definition: widget2.h:97

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

◆ updateAlpha()

void Button::updateAlpha ( )

Update the alpha value to the button components.

Definition at line 418 of file button.cpp.

419 {
420  const float alpha = std::max(settings.guiAlpha,
422 
423  if (mAlpha != alpha)
424  {
425  mAlpha = alpha;
426  for (int mode = 0; mode < BUTTON_COUNT; mode ++)
427  {
428  for (int a = 0; a < 9; a ++)
429  {
430  Skin *const skin = mSkin[mode];
431  if (skin != nullptr)
432  {
433  const ImageRect &rect = skin->getBorder();
434  Image *const image = rect.grid[a];
435  if (image != nullptr)
436  image->setAlpha(mAlpha);
437  }
438  }
439  }
440  }
441 }
static float mAlpha
Definition: button.h:284
Image * grid[9]
Definition: imagerect.h:42
float guiAlpha
Definition: settings.h:131
const ImageRect & getBorder() const
Definition: skin.h:68
float getMinimumOpacity() const
Definition: theme.h:124
Settings settings
Definition: settings.cpp:32

References BUTTON_COUNT, Skin::getBorder(), Theme::getMinimumOpacity(), ImageRect::grid, Settings::guiAlpha, mAlpha, mSkin, settings, and theme.

Referenced by draw(), init(), safeDraw(), and SliderList::updateAlpha().

◆ widgetHidden()

void Button::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 790 of file button.cpp.

791 {
793  mVertexes2->clear();
795  mRedraw = true;
796  mTextChanged = true;
797 }
RenderType openGLMode
#define isBatchDrawRenders(val)
Definition: renderers.h:31

References ImageCollection::clear(), TextChunk::deleteImage(), isBatchDrawRenders, Widget::mRedraw, mTextChanged, mTextChunk, mVertexes2, and openGLMode.

◆ widgetMoved()

void Button::widgetMoved ( const Event event)
virtual

Invoked when a widget is moved.

Parameters
eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 785 of file button.cpp.

786 {
787  mRedraw = true;
788 }

References Widget::mRedraw.

◆ widgetResized()

void Button::widgetResized ( const Event event)
virtual

Invoked when a widget changes its size.

Parameters
eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 780 of file button.cpp.

781 {
782  mRedraw = true;
783 }

References Widget::mRedraw.

Field Documentation

◆ mAlignment

Graphics::Alignment Button::mAlignment
private

Holds the alignment of the caption.

Definition at line 313 of file button.h.

Referenced by draw(), getAlignment(), safeDraw(), and setAlignment().

◆ mAlpha

float Button::mAlpha = 1.0
staticprivate

Definition at line 284 of file button.h.

Referenced by updateAlpha().

◆ mCaption

std::string Button::mCaption
private

Holds the caption of the button.

Definition at line 290 of file button.h.

Referenced by adjustSize(), draw(), getCaption(), safeDraw(), and setCaption().

◆ mClickCount

int Button::mClickCount
private

Definition at line 315 of file button.h.

Referenced by getClickCount(), and mouseReleased().

◆ mDescription

std::string Button::mDescription
private

Definition at line 292 of file button.h.

Referenced by getDescription(), and setDescription().

◆ mDisabledColor

Color Button::mDisabledColor
private

Definition at line 301 of file button.h.

Referenced by draw(), and safeDraw().

◆ mDisabledColor2

Color Button::mDisabledColor2
private

Definition at line 302 of file button.h.

Referenced by draw(), and safeDraw().

◆ mEnabledColor

Color Button::mEnabledColor
private

Definition at line 299 of file button.h.

Referenced by draw(), and safeDraw().

◆ mEnabledColor2

Color Button::mEnabledColor2
private

Definition at line 300 of file button.h.

Referenced by draw(), and safeDraw().

◆ mHasMouse

bool Button::mHasMouse
private

True if the mouse is ontop of the button, false otherwise.

Definition at line 331 of file button.h.

Referenced by draw(), isPressed(), mouseEntered(), mouseExited(), mouseReleased(), and safeDraw().

◆ mHighlightedColor

Color Button::mHighlightedColor
private

Definition at line 303 of file button.h.

Referenced by draw(), and safeDraw().

◆ mHighlightedColor2

Color Button::mHighlightedColor2
private

Definition at line 304 of file button.h.

Referenced by draw(), and safeDraw().

◆ mImageHeight

int Button::mImageHeight
private

Definition at line 327 of file button.h.

Referenced by adjustSize(), draw(), loadImageSet(), safeDraw(), setImage(), and setImageHeight().

◆ mImages

Image** Button::mImages
private

Definition at line 307 of file button.h.

Referenced by adjustSize(), draw(), loadImage(), loadImageSet(), safeDraw(), setImage(), and ~Button().

◆ mImageSet

ImageSet* Button::mImageSet
private

Definition at line 308 of file button.h.

Referenced by loadImage(), loadImageSet(), setImage(), and ~Button().

◆ mImageWidth

int Button::mImageWidth
private

Definition at line 326 of file button.h.

Referenced by adjustSize(), draw(), loadImageSet(), safeDraw(), setImage(), and setImageWidth().

◆ mKeyPressed

bool Button::mKeyPressed
private

True if a key has been pressed, false otherwise.

Definition at line 336 of file button.h.

Referenced by focusLost(), isPressed(), keyPressed(), and keyReleased().

◆ mMode

int Button::mMode
private

Definition at line 323 of file button.h.

Referenced by draw(), and safeDraw().

◆ mMousePressed

bool Button::mMousePressed
private

True if a mouse has been pressed, false otherwise.

Definition at line 341 of file button.h.

Referenced by focusLost(), isPressed(), mousePressed(), and mouseReleased().

◆ mPressed

bool Button::mPressed
private

Definition at line 344 of file button.h.

Referenced by isPressed2(), keyReleased(), mouseReleased(), and setPressed().

◆ mPressedColor

Color Button::mPressedColor
private

Definition at line 305 of file button.h.

Referenced by draw(), and safeDraw().

◆ mPressedColor2

Color Button::mPressedColor2
private

Definition at line 306 of file button.h.

Referenced by draw(), and safeDraw().

◆ mSkin

Skin* Button::mSkin[BUTTON_COUNT]
private

Button state graphics

Definition at line 286 of file button.h.

Referenced by adjustSize(), draw(), init(), safeDraw(), updateAlpha(), and ~Button().

◆ mSkinName

std::string Button::mSkinName
private

Definition at line 294 of file button.h.

Referenced by init().

◆ mSpacing

int Button::mSpacing[BUTTON_COUNT]
private

Holds the spacing between the border and the caption.

Definition at line 320 of file button.h.

Referenced by adjustSize(), draw(), init(), and safeDraw().

◆ mStick

bool Button::mStick
private

Definition at line 343 of file button.h.

Referenced by keyReleased(), mouseReleased(), and setStick().

◆ mTag

int Button::mTag
private

Definition at line 322 of file button.h.

Referenced by getTag(), and setTag().

◆ mTextChanged

bool Button::mTextChanged
private

Definition at line 345 of file button.h.

Referenced by draw(), safeDraw(), setCaption(), and widgetHidden().

◆ mTextChunk

TextChunk Button::mTextChunk
private

Definition at line 296 of file button.h.

Referenced by draw(), safeDraw(), widgetHidden(), and ~Button().

◆ mVertexes2

ImageCollection* Button::mVertexes2
private

Definition at line 298 of file button.h.

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

◆ mXOffset

int Button::mXOffset
private

Definition at line 324 of file button.h.

Referenced by draw().

◆ mYOffset

int Button::mYOffset
private

Definition at line 325 of file button.h.

Referenced by draw().


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