32#include <guichan/exception.hpp>
33#include <guichan/font.hpp>
52 gcn::ActionListener *listener):
56 setActionEventId(actionEventId);
59 addActionListener(listener);
81 const int frameWidth = btnIcons->getWidth() / 4;
82 const int frameHeight = btnIcons->getHeight();
84 if (frameWidth > 0 && frameHeight > 0)
91 btnIcons->getSubImage(mode * frameWidth, 0, frameWidth, frameHeight));
112 setFrameSize(skin.frameSize);
113 setSpacing(skin.padding);
131 skin.
draw(g, widgetState);
133 auto skinState = skin.getState(widgetState.
flags);
134 auto font = (skinState && skinState->textFormat.bold) ?
boldFont : getFont();
149 int textY = getHeight() / 2 - font->
getHeight() / 2;
151 int btnIconY = getHeight() / 2 - (icon ? icon->
getHeight() / 2 : 0);
152 int btnIconWidth = icon ? icon->
getWidth() : 0;
154 switch (getAlignment())
156 case gcn::Graphics::LEFT:
160 textX = btnIconX + icon->
getWidth() + 2;
167 case gcn::Graphics::CENTER:
170 btnIconX = (getWidth() - font->getWidth(mCaption) - icon->
getWidth() - 2) / 2;
171 textX = (getWidth() + icon->
getWidth()) / 2 + 2;
175 textX = getWidth() / 2;
178 case gcn::Graphics::RIGHT:
180 btnIconX = getWidth() - 4 - font->getWidth(mCaption) - 2;
181 textX = getWidth() - 4;
184 throw GCN_EXCEPTION(
"Button::draw(). Unknown alignment.");
190 btnIconX++; btnIconY++;
194 g->drawImage(icon, btnIconX, btnIconY);
196 if (
auto skinState = skin.getState(widgetState.
flags))
198 g->drawText(getCaption(),
203 skinState->textFormat);
210 int iconWidth = 0, iconHeight = 0;
216 iconWidth = std::max(iconWidth, icon->
getWidth() + 2);
217 iconHeight = std::max(iconHeight, icon->
getHeight());
221 setWidth(std::max(getFont()->getWidth(mCaption) + iconWidth + 2, iconWidth)
223 setHeight(std::max(getFont()->getHeight(), iconHeight) + 2 * mSpacing);
234 gcn::Button::mouseMoved(event);
236 int x =
event.getX();
237 int y =
event.getY();
239 if (event.getSource() ==
this && !
mPopupText.empty())
243 x += mParent->getX();
244 y += mParent->getY();
257 gcn::Button::mouseExited(event);
A central point of control for graphics.
Theme * getTheme() const
The global GUI theme.
Defines a class for loading and storing images.
int getHeight() const
Returns the height of the image.
int getWidth() const
Returns the width of the image.
void draw(Graphics *graphics, const WidgetState &state) const
const Skin & getSkin(SkinType skinType) const
static ResourceRef< Image > getImageFromTheme(const std::string &path)
gcn::Font * boldFont
Bolded text font.