ManaPlus
Public Member Functions | Private Types | Private Attributes | Static Private Attributes
RadioButton Class Reference

#include <radiobutton.h>

Inheritance diagram for RadioButton:
Widget MouseListener KeyListener WidgetListener Widget2

Public Member Functions

 RadioButton (const Widget2 *const widget, const std::string &caption, const std::string &group, const bool marked)
 
 ~RadioButton ()
 
void drawBox (Graphics *const graphics)
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void mouseEntered (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
void keyPressed (KeyEvent &event)
 
void updateAlpha ()
 
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 setGroup (const std::string &group)
 
const std::string & getGroup () const
 
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 MouseListener
virtual ~MouseListener ()
 
virtual void mousePressed (MouseEvent &event)
 
virtual void mouseReleased (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 ()
 
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 Types

typedef std::multimap< std::string, RadioButton * > GroupMap
 
typedef GroupMap::iterator GroupIterator
 

Private Attributes

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

Static Private Attributes

static int instances = 0
 
static SkinmSkin = 0
 
static float mAlpha = 1.0
 
static GroupMap mGroupMap
 

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
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

Guichan based RadioButton with custom look

Definition at line 84 of file radiobutton.h.

Member Typedef Documentation

◆ GroupIterator

typedef GroupMap::iterator RadioButton::GroupIterator
private

Typdef.

Definition at line 231 of file radiobutton.h.

◆ GroupMap

typedef std::multimap<std::string, RadioButton *> RadioButton::GroupMap
private

Typdef.

Definition at line 226 of file radiobutton.h.

Constructor & Destructor Documentation

◆ RadioButton()

RadioButton::RadioButton ( const Widget2 *const  widget,
const std::string &  caption,
const std::string &  group,
const bool  marked 
)

Constructor.

Definition at line 89 of file radiobutton.cpp.

References Widget::addKeyListener(), Widget::addMouseListener(), adjustSize(), Skin::getOption(), Skin::getPadding(), Widget2::getThemeColor(), Theme::getThemePath(), instances, Theme::load(), Widget::mAllowLogic, Widget::mForegroundColor, Widget2::mForegroundColor2, mImagePadding, mImageSize, mPadding, mSkin, mSpacing, mTextX, ThemeColorId::RADIOBUTTON, ThemeColorId::RADIOBUTTON_OUTLINE, setCaption(), Widget::setFocusable(), setGroup(), setSelected(), theme, and updateAlpha().

92  :
93  Widget(widget),
94  MouseListener(),
95  KeyListener(),
97  mSelected(false),
98  mCaption(),
99  mGroup(),
100  mTextChunk(),
101  mPadding(0),
102  mImagePadding(0),
103  mImageSize(9),
104  mSpacing(2),
105  mTextX(0 + 9 + 2),
106  mHasMouse(false),
107  mTextChanged(true)
108 {
109  mAllowLogic = false;
110  setCaption(caption);
111  setGroup(group);
112  setSelected(marked);
113 
114  setFocusable(true);
115  addMouseListener(this);
116  addKeyListener(this);
117 
120  if (instances == 0)
121  {
122  if (theme != nullptr)
123  {
124  mSkin = theme->load("radio.xml",
125  "",
126  true,
128  updateAlpha();
129  }
130  }
131 
132  instances++;
133 
134  if (mSkin != nullptr)
135  {
137  mImagePadding = mSkin->getOption("imagePadding");
138  mImageSize = mSkin->getOption("imageSize");
139  mSpacing = mSkin->getOption("spacing");
141  }
142 
143  adjustSize();
144 }
void updateAlpha()
bool mHasMouse
Definition: radiobutton.h:243
static Skin * mSkin
Definition: radiobutton.h:203
void setCaption(const std::string &caption)
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
Color mForegroundColor
Definition: widget.h:1085
int getOption(const std::string &name) const
Definition: skin.h:105
int getPadding() const
Definition: skin.h:99
static int instances
Definition: radiobutton.h:202
Widget(const Widget2 *const widget)
Definition: widget.cpp:84
std::string mGroup
Definition: radiobutton.h:219
bool mAllowLogic
Definition: widget.h:1159
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:291
bool mTextChanged
Definition: radiobutton.h:244
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:271
bool mSelected
Definition: radiobutton.h:209
Theme * theme
Definition: theme.cpp:61
void setFocusable(const bool focusable)
Definition: widget.cpp:191
Color mForegroundColor2
Definition: widget2.h:112
TextChunk mTextChunk
Definition: radiobutton.h:221
void setSelected(const bool selected)
int mImagePadding
Definition: radiobutton.h:239
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44
void setGroup(const std::string &group)
void adjustSize()
std::string mCaption
Definition: radiobutton.h:214

◆ ~RadioButton()

RadioButton::~RadioButton ( )

Destructor.

Definition at line 146 of file radiobutton.cpp.

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

147 {
148  if (mWindow != nullptr)
150 
151  setGroup(std::string());
152 
153  if (gui != nullptr)
154  gui->removeDragged(this);
155 
156  instances--;
157 
158  if (instances == 0)
159  {
160  if (theme != nullptr)
161  theme->unload(mSkin);
162  }
163 }
static Skin * mSkin
Definition: radiobutton.h:203
void unload(Skin *const skin)
Definition: theme.cpp:249
Gui * gui
Definition: gui.cpp:110
static int instances
Definition: radiobutton.h:202
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
void setGroup(const std::string &group)

Member Function Documentation

◆ adjustSize()

void RadioButton::adjustSize ( )

Definition at line 282 of file radiobutton.cpp.

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

Referenced by RadioGroup::createWidget(), and RadioButton().

283 {
284  Font *const font = getFont();
285  setHeight(font->getHeight() + 2 * mPadding);
287  + font->getWidth(mCaption) + mPadding);
288 }
Font * getFont() const
Definition: widget.cpp:330
void setWidth(const int width)
Definition: widget.cpp:132
Definition: font.h:88
void setHeight(const int height)
Definition: widget.cpp:139
int getWidth(const std::string &text) const
Definition: font.cpp:333
int mImagePadding
Definition: radiobutton.h:239
int getHeight() const
Definition: font.cpp:360
std::string mCaption
Definition: radiobutton.h:214

◆ draw()

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

Implementation of the draw methods. Thus, avoiding the rhomb around the radio button.

Implements Widget.

Definition at line 231 of file radiobutton.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().

232 {
233  BLOCK_START("RadioButton::draw")
234  drawBox(graphics);
235 
236  Font *const font = getFont();
237 
238  if (mTextChanged)
239  {
245  font->generate(mTextChunk);
246  mTextChanged = false;
247  }
248 
249  const Image *const image = mTextChunk.img;
250  if (image != nullptr)
251  graphics->drawImage(image, mTextX, mPadding);
252 
253  BLOCK_END("RadioButton::draw")
254 }
Font * getFont() const
Definition: widget.cpp:330
std::string text
Definition: textchunk.h:64
Definition: font.h:88
#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: radiobutton.h:244
void drawBox(Graphics *const graphics)
Color mForegroundColor2
Definition: widget2.h:112
Image * img
Definition: textchunk.h:62
Definition: image.h:61
TextChunk mTextChunk
Definition: radiobutton.h:221
Color color
Definition: textchunk.h:65
void deleteImage()
Definition: textchunk.cpp:192
Color color2
Definition: textchunk.h:66
std::string mCaption
Definition: radiobutton.h:214

◆ drawBox()

void RadioButton::drawBox ( Graphics *const  graphics)

Draws the radiobutton, not the caption.

Definition at line 186 of file radiobutton.cpp.

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

Referenced by draw().

187 {
188  if (mSkin == nullptr)
189  return;
190 
191  const ImageRect &rect = mSkin->getBorder();
192  int index = 0;
193 
194  if (mEnabled && mVisible == Visible_true)
195  {
196  if (mSelected)
197  {
198  if (mHasMouse)
199  index = 1;
200  else
201  index = 0;
202  }
203  else
204  {
205  if (mHasMouse)
206  index = 3;
207  else
208  index = 2;
209  }
210  }
211  else
212  {
213  if (mSelected)
214  index = 0;
215  else
216  index = 2;
217  }
218 
219  const Image *const box = rect.grid[index];
220 
221  updateAlpha();
222 
223  if (box != nullptr)
224  {
225  graphics->drawImage(box,
227  (getHeight() - mImageSize) / 2);
228  }
229 }
void updateAlpha()
bool mHasMouse
Definition: radiobutton.h:243
static Skin * mSkin
Definition: radiobutton.h:203
const bool Visible_true
Definition: visible.h:29
Visible mVisible
Definition: widget.h:962
const ImageRect & getBorder() const
Definition: skin.h:67
Image * grid[9]
Definition: imagerect.h:41
bool mSelected
Definition: radiobutton.h:209
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
bool mEnabled
Definition: widget.h:1157
Definition: image.h:61
int getHeight() const
Definition: widget.h:239
int mImagePadding
Definition: radiobutton.h:239

◆ getCaption()

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

Gets the caption of the radio button.

Returns
The caption of the radio button.
See also
setCaption

Definition at line 159 of file radiobutton.h.

References mCaption, mouseClicked(), mouseDragged(), setCaption(), and setGroup().

160  { return mCaption; }
std::string mCaption
Definition: radiobutton.h:214

◆ getGroup()

const std::string& RadioButton::getGroup ( ) const
inline

Gets the group the radio button belongs to.

Returns
The group the radio button belongs to.
See also
setGroup

Definition at line 192 of file radiobutton.h.

References mGroup, setParent(), setWindow(), and widgetHidden().

193  { return mGroup; }
std::string mGroup
Definition: radiobutton.h:219

◆ isSelected()

bool RadioButton::isSelected ( ) const
inline

Checks if the radio button is selected.

Returns
True if the radio button is selecte, false otherwise.
See also
setSelected

Definition at line 141 of file radiobutton.h.

References mSelected, and setSelected().

Referenced by QuitDialog::action(), and RegisterDialog::action().

142  { return mSelected; }
bool mSelected
Definition: radiobutton.h:209

◆ keyPressed()

void RadioButton::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 271 of file radiobutton.cpp.

References Widget::distributeActionEvent(), InputAction::GUI_SELECT, and setSelected().

272 {
273  const InputActionT action = event.getActionId();
274  if (action == InputAction::GUI_SELECT)
275  {
276  setSelected(true);
278  event.consume();
279  }
280 }
void distributeActionEvent()
Definition: widget.cpp:492
InputAction ::T InputActionT
Definition: inputaction.h:714
void setSelected(const bool selected)

◆ mouseClicked()

void RadioButton::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 307 of file radiobutton.cpp.

References Widget::distributeActionEvent(), MouseEvent::getButton(), MouseButton::LEFT, and setSelected().

Referenced by getCaption().

308 {
309  if (event.getButton() == MouseButton::LEFT)
310  {
311  setSelected(true);
312  event.consume();
314  }
315 }
MouseButtonT getButton() const
Definition: mouseevent.h:115
void distributeActionEvent()
Definition: widget.cpp:492
void setSelected(const bool selected)

◆ mouseDragged()

void RadioButton::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 317 of file radiobutton.cpp.

Referenced by getCaption().

318 {
319  event.consume();
320 }

◆ mouseEntered()

void RadioButton::mouseEntered ( MouseEvent event)
virtual

Called when the mouse enteres the widget area.

Reimplemented from MouseListener.

Definition at line 261 of file radiobutton.cpp.

References mHasMouse.

262 {
263  mHasMouse = true;
264 }
bool mHasMouse
Definition: radiobutton.h:243

◆ mouseExited()

void RadioButton::mouseExited ( MouseEvent event)
virtual

Called when the mouse leaves the widget area.

Reimplemented from MouseListener.

Definition at line 266 of file radiobutton.cpp.

References mHasMouse.

267 {
268  mHasMouse = false;
269 }
bool mHasMouse
Definition: radiobutton.h:243

◆ safeDraw()

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

Implements Widget.

Definition at line 256 of file radiobutton.cpp.

References draw().

257 {
258  RadioButton::draw(graphics);
259 }
void draw(Graphics *const graphics)

◆ setCaption()

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

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

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

Definition at line 345 of file radiobutton.cpp.

References mCaption, and mTextChanged.

Referenced by getCaption(), and RadioButton().

346 {
347  if (caption != mCaption)
348  mTextChanged = true;
349  mCaption = caption;
350 }
bool mTextChanged
Definition: radiobutton.h:244
std::string mCaption
Definition: radiobutton.h:214

◆ setGroup()

void RadioButton::setGroup ( const std::string &  group)

Sets the group the radio button should belong to. Note that a radio button group is unique per application, not per Gui object as the group is stored in a static map.

Parameters
groupThe name of the group.
See also
getGroup

Definition at line 322 of file radiobutton.cpp.

References mGroup, and mGroupMap.

Referenced by getCaption(), RadioButton(), and ~RadioButton().

323 {
324  if (!mGroup.empty())
325  {
326  for (GroupIterator iter = mGroupMap.lower_bound(mGroup),
327  iterEnd = mGroupMap.upper_bound(mGroup);
328  iter != iterEnd;
329  ++ iter)
330  {
331  if (iter->second == this)
332  {
333  mGroupMap.erase(iter);
334  break;
335  }
336  }
337  }
338 
339  if (!group.empty())
340  mGroupMap.insert(std::pair<std::string, RadioButton *>(group, this));
341 
342  mGroup = group;
343 }
GroupMap::iterator GroupIterator
Definition: radiobutton.h:231
std::string mGroup
Definition: radiobutton.h:219
static GroupMap mGroupMap
Definition: radiobutton.h:236

◆ setParent()

void RadioButton::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 352 of file radiobutton.cpp.

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

Referenced by getGroup().

353 {
354  if (mWindow != nullptr)
355  mWindow->addWidgetListener(this);
356  Widget::setParent(widget);
357 }
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 RadioButton::setSelected ( const bool  selected)

Sets the radio button to selected or not.

Parameters
selectedTrue if the radio button should be selected, false otherwise.
See also
isSelected

Definition at line 290 of file radiobutton.cpp.

References mGroup, mGroupMap, and mSelected.

Referenced by isSelected(), keyPressed(), mouseClicked(), and RadioButton().

291 {
292  if (selected && !mGroup.empty())
293  {
294  for (GroupIterator iter = mGroupMap.lower_bound(mGroup),
295  iterEnd = mGroupMap.upper_bound(mGroup);
296  iter != iterEnd;
297  ++ iter)
298  {
299  if ((iter->second != nullptr) && iter->second->isSelected())
300  iter->second->setSelected(false);
301  }
302  }
303 
304  mSelected = selected;
305 }
GroupMap::iterator GroupIterator
Definition: radiobutton.h:231
std::string mGroup
Definition: radiobutton.h:219
bool mSelected
Definition: radiobutton.h:209
static GroupMap mGroupMap
Definition: radiobutton.h:236

◆ setWindow()

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

Reimplemented from Widget2.

Definition at line 365 of file radiobutton.cpp.

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

Referenced by getGroup().

366 {
367  if ((widget == nullptr) && (mWindow != nullptr))
368  {
370  mWindow = nullptr;
371  }
372  else
373  {
374  Widget2::setWindow(widget);
375  }
376 }
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

◆ updateAlpha()

void RadioButton::updateAlpha ( )

Definition at line 165 of file radiobutton.cpp.

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

Referenced by drawBox(), and RadioButton().

166 {
167  const float alpha = std::max(settings.guiAlpha,
169 
170  if (mAlpha != alpha)
171  {
172  mAlpha = alpha;
173  if (mSkin != nullptr)
174  {
175  const ImageRect &rect = mSkin->getBorder();
176  for (int a = 0; a < 4; a ++)
177  {
178  Image *const image = rect.grid[a];
179  if (image != nullptr)
180  image->setAlpha(mAlpha);
181  }
182  }
183  }
184 }
static Skin * mSkin
Definition: radiobutton.h:203
static float mAlpha
Definition: radiobutton.h:204
float getMinimumOpacity() const
Definition: theme.h:123
Settings settings
Definition: settings.cpp:31
virtual void setAlpha(const float alpha)
Definition: image.cpp:285
const ImageRect & getBorder() const
Definition: skin.h:67
Image * grid[9]
Definition: imagerect.h:41
Theme * theme
Definition: theme.cpp:61
Definition: image.h:61
float guiAlpha
Definition: settings.h:129

◆ widgetHidden()

void RadioButton::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 359 of file radiobutton.cpp.

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

Referenced by getGroup().

360 {
361  mTextChanged = true;
363 }
bool mTextChanged
Definition: radiobutton.h:244
TextChunk mTextChunk
Definition: radiobutton.h:221
void deleteImage()
Definition: textchunk.cpp:192

Field Documentation

◆ instances

int RadioButton::instances = 0
staticprivate

Definition at line 202 of file radiobutton.h.

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

◆ mAlpha

float RadioButton::mAlpha = 1.0
staticprivate

Definition at line 204 of file radiobutton.h.

Referenced by updateAlpha().

◆ mCaption

std::string RadioButton::mCaption
private

Holds the caption of the radio button.

Definition at line 214 of file radiobutton.h.

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

◆ mGroup

std::string RadioButton::mGroup
private

Holds the group of the radio button.

Definition at line 219 of file radiobutton.h.

Referenced by getGroup(), setGroup(), and setSelected().

◆ mGroupMap

RadioButton::GroupMap RadioButton::mGroupMap
staticprivate

Holds all available radio button groups.

Definition at line 236 of file radiobutton.h.

Referenced by setGroup(), and setSelected().

◆ mHasMouse

bool RadioButton::mHasMouse
private

Definition at line 243 of file radiobutton.h.

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

◆ mImagePadding

int RadioButton::mImagePadding
private

Definition at line 239 of file radiobutton.h.

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

◆ mImageSize

int RadioButton::mImageSize
private

Definition at line 240 of file radiobutton.h.

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

◆ mPadding

int RadioButton::mPadding
private

Definition at line 238 of file radiobutton.h.

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

◆ mSelected

bool RadioButton::mSelected
private

True if the radio button is selected, false otherwise.

Definition at line 209 of file radiobutton.h.

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

◆ mSkin

Skin * RadioButton::mSkin = 0
staticprivate

Definition at line 203 of file radiobutton.h.

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

◆ mSpacing

int RadioButton::mSpacing
private

Definition at line 241 of file radiobutton.h.

Referenced by adjustSize(), and RadioButton().

◆ mTextChanged

bool RadioButton::mTextChanged
private

Definition at line 244 of file radiobutton.h.

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

◆ mTextChunk

TextChunk RadioButton::mTextChunk
private

Definition at line 221 of file radiobutton.h.

Referenced by draw(), and widgetHidden().

◆ mTextX

int RadioButton::mTextX
private

Definition at line 242 of file radiobutton.h.

Referenced by draw(), and RadioButton().


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