32 #include "twobutton.h"
35 TwoButton::TwoButton(Image *up_file , Image *down_file, Image *hover_file,
const std::string& caption):
38 m_downImage(down_file),
39 m_hoverImage(hover_file),
42 m_hoverImage = hover_file;
48 TwoButton::~TwoButton() {
51 void TwoButton::setDownOffset(
int x,
int y) {
56 void TwoButton::draw(Graphics *graphics) {
57 Image* img = m_upImage;
64 xoffset = x_downoffset;
65 yoffset = y_downoffset;
67 }
else if(mHasMouse) {
74 graphics->drawImage(img, xoffset, yoffset);
77 graphics->setColor(getForegroundColor());
79 int textY = getHeight() / 2 - getFont()->getHeight() / 2;
80 switch (getAlignment())
85 case Graphics::CENTER:
86 textX = getWidth() / 2;
89 textX = getWidth() - 4;
92 throw GCN_EXCEPTION(
"Unknown alignment.");
95 graphics->setFont(getFont());
96 if (mCaption.size() > 0) {
98 graphics->drawText(getCaption(), textX + 1,
99 textY + 1, getAlignment());
101 graphics->drawText(getCaption(), textX, textY, getAlignment());
104 void TwoButton::adjustSize() {
108 w = m_upImage->getWidth();
109 h = m_upImage->getHeight();
112 w = std::max(m_downImage->getWidth(), w);
113 h = std::max(m_downImage->getHeight(), h);
116 w = std::max(m_hoverImage->getWidth(), w);
117 h = std::max(m_hoverImage->getHeight(), h);
122 void TwoButton::setUpImage(Image* image) {
126 void TwoButton::setDownImage(Image* image) {
130 void TwoButton::setHoverImage(Image* image) {
131 m_hoverImage = image;