ManaPlus
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
CheckBox Class Reference

#include <checkbox.h>

Inheritance diagram for CheckBox:
Widget ToolTipListener KeyListener WidgetListener Widget2 MouseListener

Public Member Functions

 CheckBox (const Widget2 *const widget, const std::string &caption, const bool selected, ActionListener *const listener, const std::string &eventId)
 
 ~CheckBox ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void updateAlpha ()
 
void drawBox (Graphics *const graphics)
 
void mouseEntered (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
void keyPressed (KeyEvent &event)
 
void adjustSize ()
 
bool isSelected () const
 
void setSelected (const bool selected)
 
const std::string & getCaption () const
 
void setCaption (const std::string &caption)
 
void mouseClicked (MouseEvent &event)
 
void mouseDragged (MouseEvent &event)
 
void setParent (Widget *widget)
 
void widgetHidden (const Event &event)
 
void setWindow (Widget *const widget)
 
- 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 ToolTipListener
 ToolTipListener ()
 
void setToolTip (const std::string &str)
 
std::string getToolTip () const
 
void mouseMoved (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mousePressed (MouseEvent &event)
 
virtual void mouseReleased (MouseEvent &event)
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 
- Public Member Functions inherited from KeyListener
virtual ~KeyListener ()
 
virtual void keyReleased (KeyEvent &event)
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetResized (const Event &event)
 
virtual void widgetMoved (const Event &event)
 
virtual void widgetShown (const Event &event)
 

Private Member Functions

void toggleSelected ()
 

Private Attributes

bool mSelected
 
std::string mCaption
 
TextChunk mTextChunk
 
int mPadding
 
int mImagePadding
 
int mImageSize
 
int mSpacing
 
int mTextX
 
bool mHasMouse
 
bool mDrawBox
 
bool mTextChanged
 

Static Private Attributes

static int instances = 0
 
static SkinmSkin = 0
 
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 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
 
- Protected Attributes inherited from ToolTipListener
std::string mToolTip
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

Check box widget. Same as the Guichan check box but with custom look.

Definition at line 87 of file checkbox.h.

Constructor & Destructor Documentation

◆ CheckBox()

CheckBox::CheckBox ( const Widget2 *const  widget,
const std::string &  caption,
const bool  selected,
ActionListener *const  listener,
const std::string &  eventId 
)

Constructor.

Definition at line 87 of file checkbox.cpp.

References Widget::addActionListener(), Widget::addKeyListener(), Widget::addMouseListener(), adjustSize(), ThemeColorId::CHECKBOX, ThemeColorId::CHECKBOX_OUTLINE, Skin::getOption(), Skin::getPadding(), Widget2::getThemeColor(), Theme::getThemePath(), instances, Theme::load(), Widget::mAllowLogic, mDrawBox, Widget::mForegroundColor, Widget2::mForegroundColor2, mImagePadding, mImageSize, mPadding, mSkin, mSpacing, mTextX, Widget::setActionEventId(), setCaption(), Widget::setFocusable(), theme, and updateAlpha().

91  :
92  Widget(widget),
94  KeyListener(),
96  mSelected(selected),
97  mCaption(),
98  mTextChunk(),
99  mPadding(0),
100  mImagePadding(0),
101  mImageSize(9),
102  mSpacing(2),
103  mTextX(0 + 9 + 2),
104  mHasMouse(false),
105  mDrawBox(true),
106  mTextChanged(true)
107 {
108  setCaption(caption);
109  mAllowLogic = false;
110 
111  setFocusable(true);
112  addMouseListener(this);
113  addKeyListener(this);
114 
116  if (instances == 0)
117  {
118  if (theme != nullptr)
119  {
120  mSkin = theme->load("checkbox.xml",
121  "",
122  true,
124  updateAlpha();
125  }
126  }
127 
128  instances++;
129 
130  if (!eventId.empty())
131  setActionEventId(eventId);
132 
133  if (listener != nullptr)
134  addActionListener(listener);
135 
137  if (mSkin != nullptr)
138  {
140  mImagePadding = mSkin->getOption("imagePadding");
141  mImageSize = mSkin->getOption("imageSize");
142  mSpacing = mSkin->getOption("spacing");
143  mDrawBox = (mSkin->getOption("drawBox", 1) != 0);
145  }
146  adjustSize();
147 }
int mTextX
Definition: checkbox.h:206
int mSpacing
Definition: checkbox.h:205
int mPadding
Definition: checkbox.h:202
TextChunk mTextChunk
Definition: checkbox.h:200
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
int mImageSize
Definition: checkbox.h:204
static std::string getThemePath()
Definition: theme.h:66
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:178
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:595
static Skin * mSkin
Definition: checkbox.h:212
Color mForegroundColor
Definition: widget.h:1085
bool mDrawBox
Definition: checkbox.h:208
int getOption(const std::string &name) const
Definition: skin.h:105
void updateAlpha()
Definition: checkbox.cpp:196
int getPadding() const
Definition: skin.h:99
void adjustSize()
Definition: checkbox.cpp:283
void setCaption(const std::string &caption)
Definition: checkbox.cpp:310
int mImagePadding
Definition: checkbox.h:203
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
bool mTextChanged
Definition: checkbox.h:209
Theme * theme
Definition: theme.cpp:61
void setFocusable(const bool focusable)
Definition: widget.cpp:191
Color mForegroundColor2
Definition: widget2.h:112
bool mHasMouse
Definition: checkbox.h:207
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44
bool mSelected
Definition: checkbox.h:193
std::string mCaption
Definition: checkbox.h:198
static int instances
Definition: checkbox.h:211

◆ ~CheckBox()

CheckBox::~CheckBox ( )

Destructor.

Definition at line 149 of file checkbox.cpp.

References gui, instances, mSkin, Widget2::mWindow, Gui::removeDragged(), Widget::removeWidgetListener(), theme, and Theme::unload().

150 {
151  if (mWindow != nullptr)
153 
154  if (gui != nullptr)
155  gui->removeDragged(this);
156 
157  instances--;
158 
159  if (instances == 0)
160  {
161  if (theme != nullptr)
162  theme->unload(mSkin);
163  }
164 }
void unload(Skin *const skin)
Definition: theme.cpp:249
Gui * gui
Definition: gui.cpp:110
static Skin * mSkin
Definition: checkbox.h:212
Widget * mWindow
Definition: widget2.h:111
Theme * theme
Definition: theme.cpp:61
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1160
void removeWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:306
static int instances
Definition: checkbox.h:211

Member Function Documentation

◆ adjustSize()

void CheckBox::adjustSize ( )

Definition at line 283 of file checkbox.cpp.

References Widget::getFont(), Widget::getHeight(), Widget::getWidth(), mCaption, mImagePadding, mImageSize, mPadding, mSpacing, Widget::setHeight(), and Widget::setWidth().

Referenced by CheckBox().

284 {
285  setHeight(getFont()->getHeight() + 2 * mPadding);
288 }
Font * getFont() const
Definition: widget.cpp:330
int getWidth() const
Definition: widget.h:220
int mSpacing
Definition: checkbox.h:205
void setWidth(const int width)
Definition: widget.cpp:132
int mPadding
Definition: checkbox.h:202
int mImageSize
Definition: checkbox.h:204
int mImagePadding
Definition: checkbox.h:203
void setHeight(const int height)
Definition: widget.cpp:139
int getHeight() const
Definition: widget.h:239
std::string mCaption
Definition: checkbox.h:198

◆ draw()

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

Draws the caption, then calls drawBox to draw the check box.

Implements Widget.

Definition at line 166 of file checkbox.cpp.

References BLOCK_END, BLOCK_START, TextChunk::color, TextChunk::color2, TextChunk::deleteImage(), drawBox(), Graphics::drawImage(), ServerCommandType::font, Font::generate(), Widget::getFont(), TextChunk::img, mCaption, Widget::mForegroundColor, Widget2::mForegroundColor2, mPadding, mTextChanged, mTextChunk, mTextX, TextChunk::text, and TextChunk::textFont.

Referenced by safeDraw().

167 {
168  BLOCK_START("CheckBox::draw")
169  drawBox(graphics);
170 
171  Font *const font = getFont();
172 
173  if (mTextChanged)
174  {
180  font->generate(mTextChunk);
181  mTextChanged = false;
182  }
183 
184  const Image *const image = mTextChunk.img;
185  if (image != nullptr)
186  graphics->drawImage(image, mTextX, mPadding);
187 
188  BLOCK_END("CheckBox::draw")
189 }
int mTextX
Definition: checkbox.h:206
Font * getFont() const
Definition: widget.cpp:330
void drawBox(Graphics *const graphics)
Definition: checkbox.cpp:217
std::string text
Definition: textchunk.h:64
Definition: font.h:88
int mPadding
Definition: checkbox.h:202
TextChunk mTextChunk
Definition: checkbox.h:200
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
Color mForegroundColor
Definition: widget.h:1085
Font * textFont
Definition: textchunk.h:63
bool mTextChanged
Definition: checkbox.h:209
Color mForegroundColor2
Definition: widget2.h:112
Image * img
Definition: textchunk.h:62
Definition: image.h:61
Color color
Definition: textchunk.h:65
void deleteImage()
Definition: textchunk.cpp:192
Color color2
Definition: textchunk.h:66
std::string mCaption
Definition: checkbox.h:198

◆ drawBox()

void CheckBox::drawBox ( Graphics *const  graphics)

Draws the check box, not the caption.

Definition at line 217 of file checkbox.cpp.

References Graphics::drawImage(), Skin::getBorder(), Widget::getHeight(), ImageRect::grid, mDrawBox, Widget::mEnabled, mHasMouse, mImagePadding, mImageSize, mSelected, mSkin, Widget::mVisible, updateAlpha(), and Visible_true.

Referenced by draw().

218 {
219  if ((mSkin == nullptr) || !mDrawBox)
220  return;
221 
222  const ImageRect &rect = mSkin->getBorder();
223  int index = 0;
224 
225  if (mEnabled && mVisible == Visible_true)
226  {
227  if (mSelected)
228  {
229  if (mHasMouse)
230  index = 5;
231  else
232  index = 1;
233  }
234  else
235  {
236  if (mHasMouse)
237  index = 4;
238  else
239  index = 0;
240  }
241  }
242  else
243  {
244  if (mSelected)
245  index = 3;
246  else
247  index = 2;
248  }
249  const Image *const box = rect.grid[index];
250 
251  updateAlpha();
252 
253  if (box != nullptr)
254  {
255  graphics->drawImage(box,
257  (getHeight() - mImageSize) / 2);
258  }
259 }
const bool Visible_true
Definition: visible.h:29
int mImageSize
Definition: checkbox.h:204
static Skin * mSkin
Definition: checkbox.h:212
bool mDrawBox
Definition: checkbox.h:208
void updateAlpha()
Definition: checkbox.cpp:196
Visible mVisible
Definition: widget.h:962
const ImageRect & getBorder() const
Definition: skin.h:67
Image * grid[9]
Definition: imagerect.h:41
int mImagePadding
Definition: checkbox.h:203
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
bool mHasMouse
Definition: checkbox.h:207
bool mEnabled
Definition: widget.h:1157
Definition: image.h:61
int getHeight() const
Definition: widget.h:239
bool mSelected
Definition: checkbox.h:193

◆ getCaption()

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

Gets the caption of the check box.

Returns
The caption of the check box.
See also
setCaption

Definition at line 164 of file checkbox.h.

References mCaption, mouseClicked(), mouseDragged(), setCaption(), setParent(), setWindow(), toggleSelected(), and widgetHidden().

165  { return mCaption; }
std::string mCaption
Definition: checkbox.h:198

◆ isSelected()

bool CheckBox::isSelected ( ) const
inline

◆ keyPressed()

void CheckBox::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 272 of file checkbox.cpp.

References InputAction::GUI_SELECT, and toggleSelected().

273 {
274  const InputActionT action = event.getActionId();
275 
276  if (action == InputAction::GUI_SELECT)
277  {
278  toggleSelected();
279  event.consume();
280  }
281 }
void toggleSelected()
Definition: checkbox.cpp:304
InputAction ::T InputActionT
Definition: inputaction.h:715

◆ mouseClicked()

void CheckBox::mouseClicked ( MouseEvent event)
virtual

Called when a mouse button is pressed and released (clicked) on the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 290 of file checkbox.cpp.

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

Referenced by getCaption().

291 {
292  if (event.getButton() == MouseButton::LEFT)
293  {
294  toggleSelected();
295  event.consume();
296  }
297 }
void toggleSelected()
Definition: checkbox.cpp:304
MouseButtonT getButton() const
Definition: mouseevent.h:115

◆ mouseDragged()

void CheckBox::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 299 of file checkbox.cpp.

Referenced by getCaption().

300 {
301  event.consume();
302 }

◆ mouseEntered()

void CheckBox::mouseEntered ( MouseEvent event)
virtual

Called when the mouse enteres the widget area.

Reimplemented from MouseListener.

Definition at line 261 of file checkbox.cpp.

References mHasMouse.

262 {
263  mHasMouse = true;
264 }
bool mHasMouse
Definition: checkbox.h:207

◆ mouseExited()

void CheckBox::mouseExited ( MouseEvent event)
virtual

Called when the mouse leaves the widget area.

Reimplemented from MouseListener.

Definition at line 266 of file checkbox.cpp.

References mHasMouse, and ToolTipListener::mouseExited().

267 {
268  mHasMouse = false;
270 }
void mouseExited(MouseEvent &event)
bool mHasMouse
Definition: checkbox.h:207

◆ safeDraw()

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

Implements Widget.

Definition at line 191 of file checkbox.cpp.

References draw().

192 {
193  CheckBox::draw(graphics);
194 }
void draw(Graphics *const graphics)
Definition: checkbox.cpp:166

◆ setCaption()

void CheckBox::setCaption ( const std::string &  caption)

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

Parameters
captionThe caption of the check box.
See also
getCaption, adjustSize

Definition at line 310 of file checkbox.cpp.

References mCaption, and mTextChanged.

Referenced by CheckBox(), and getCaption().

311 {
312  if (caption != mCaption)
313  mTextChanged = true;
314  mCaption = caption;
315 }
bool mTextChanged
Definition: checkbox.h:209
std::string mCaption
Definition: checkbox.h:198

◆ setParent()

void CheckBox::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 317 of file checkbox.cpp.

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

Referenced by getCaption().

318 {
319  if (mWindow != nullptr)
320  mWindow->addWidgetListener(this);
321  Widget::setParent(widget);
322 }
Widget * mWindow
Definition: widget2.h:111
virtual void setParent(Widget *parent)
Definition: widget.h:625
void addWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:301

◆ setSelected()

void CheckBox::setSelected ( const bool  selected)
inline

◆ setWindow()

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

Reimplemented from Widget2.

Definition at line 330 of file checkbox.cpp.

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

Referenced by getCaption().

331 {
332  if ((widget == nullptr) && (mWindow != nullptr))
333  {
335  mWindow = nullptr;
336  }
337  else
338  {
339  Widget2::setWindow(widget);
340  }
341 }
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

◆ toggleSelected()

void CheckBox::toggleSelected ( )
private

Definition at line 304 of file checkbox.cpp.

References Widget::distributeActionEvent(), and mSelected.

Referenced by getCaption(), keyPressed(), and mouseClicked().

305 {
306  mSelected = !mSelected;
308 }
void distributeActionEvent()
Definition: widget.cpp:492
bool mSelected
Definition: checkbox.h:193

◆ updateAlpha()

void CheckBox::updateAlpha ( )

Update the alpha value to the checkbox components.

Definition at line 196 of file checkbox.cpp.

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

Referenced by CheckBox(), and drawBox().

197 {
198  const float alpha = std::max(settings.guiAlpha,
200 
201  if (mAlpha != alpha)
202  {
203  mAlpha = alpha;
204  if (mSkin != nullptr)
205  {
206  const ImageRect &rect = mSkin->getBorder();
207  for (int a = 0; a < 6; a ++)
208  {
209  Image *const image = rect.grid[a];
210  if (image != nullptr)
211  image->setAlpha(mAlpha);
212  }
213  }
214  }
215 }
float getMinimumOpacity() const
Definition: theme.h:123
static Skin * mSkin
Definition: checkbox.h:212
Settings settings
Definition: settings.cpp:31
virtual void setAlpha(const float alpha)
Definition: image.cpp:286
const ImageRect & getBorder() const
Definition: skin.h:67
Image * grid[9]
Definition: imagerect.h:41
static float mAlpha
Definition: checkbox.h:213
Theme * theme
Definition: theme.cpp:61
Definition: image.h:61
float guiAlpha
Definition: settings.h:129

◆ widgetHidden()

void CheckBox::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 324 of file checkbox.cpp.

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

Referenced by getCaption().

325 {
326  mTextChanged = true;
328 }
TextChunk mTextChunk
Definition: checkbox.h:200
bool mTextChanged
Definition: checkbox.h:209
void deleteImage()
Definition: textchunk.cpp:192

Field Documentation

◆ instances

int CheckBox::instances = 0
staticprivate

Definition at line 211 of file checkbox.h.

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

◆ mAlpha

float CheckBox::mAlpha = 1.0
staticprivate

Definition at line 213 of file checkbox.h.

Referenced by updateAlpha().

◆ mCaption

std::string CheckBox::mCaption
private

Holds the caption of the check box.

Definition at line 198 of file checkbox.h.

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

◆ mDrawBox

bool CheckBox::mDrawBox
private

Definition at line 208 of file checkbox.h.

Referenced by CheckBox(), and drawBox().

◆ mHasMouse

bool CheckBox::mHasMouse
private

Definition at line 207 of file checkbox.h.

Referenced by drawBox(), mouseEntered(), and mouseExited().

◆ mImagePadding

int CheckBox::mImagePadding
private

Definition at line 203 of file checkbox.h.

Referenced by adjustSize(), CheckBox(), and drawBox().

◆ mImageSize

int CheckBox::mImageSize
private

Definition at line 204 of file checkbox.h.

Referenced by adjustSize(), CheckBox(), and drawBox().

◆ mPadding

int CheckBox::mPadding
private

Definition at line 202 of file checkbox.h.

Referenced by adjustSize(), CheckBox(), and draw().

◆ mSelected

bool CheckBox::mSelected
private

True if the check box is selected, false otherwise.

Definition at line 193 of file checkbox.h.

Referenced by drawBox(), isSelected(), setSelected(), and toggleSelected().

◆ mSkin

Skin * CheckBox::mSkin = 0
staticprivate

Definition at line 212 of file checkbox.h.

Referenced by CheckBox(), drawBox(), updateAlpha(), and ~CheckBox().

◆ mSpacing

int CheckBox::mSpacing
private

Definition at line 205 of file checkbox.h.

Referenced by adjustSize(), and CheckBox().

◆ mTextChanged

bool CheckBox::mTextChanged
private

Definition at line 209 of file checkbox.h.

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

◆ mTextChunk

TextChunk CheckBox::mTextChunk
private

Definition at line 200 of file checkbox.h.

Referenced by draw(), and widgetHidden().

◆ mTextX

int CheckBox::mTextX
private

Definition at line 206 of file checkbox.h.

Referenced by CheckBox(), and draw().


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