39 #include <guichan/mouseevent.hpp>
41 #include "togglebutton.h"
45 ToggleButton::GroupMap ToggleButton::m_groupMap;
50 m_downImage(down_file),
51 m_hoverImage(hover_file),
56 m_hoverImage = hover_file;
63 addActionListener(
this);
76 Color faceColor = getBaseColor();
79 int alpha = getBaseColor().a;
85 if (isPressed() || m_toggled) {
86 faceColor = faceColor - 0x303030;
88 highlightColor = faceColor - 0x303030;
89 highlightColor.a = alpha;
90 shadowColor = faceColor + 0x303030;
91 shadowColor.a = alpha;
95 xoffset = x_downoffset;
96 yoffset = y_downoffset;
98 }
else if(mHasMouse) {
99 faceColor = faceColor + 0x303030;
101 highlightColor = faceColor + 0x303030;
102 highlightColor.a = alpha;
103 shadowColor = faceColor - 0x303030;
104 shadowColor.a = alpha;
106 if ( m_hoverImage ) {
110 highlightColor = faceColor + 0x303030;
111 highlightColor.a = alpha;
112 shadowColor = faceColor - 0x303030;
113 shadowColor.a = alpha;
121 graphics->setColor(faceColor);
122 graphics->fillRectangle(Rectangle(1, 1, getDimension().width-1, getHeight() - 1));
124 graphics->setColor(highlightColor);
125 graphics->drawLine(0, 0, getWidth() - 1, 0);
126 graphics->drawLine(0, 1, 0, getHeight() - 1);
128 graphics->setColor(shadowColor);
129 graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1);
130 graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1);
132 graphics->setColor(getForegroundColor());
135 graphics->drawImage(img, xoffset, yoffset);
139 int textY = getHeight() / 2 - getFont()->getHeight() / 2;
140 switch (getAlignment())
145 case Graphics::CENTER:
146 textX = getWidth() / 2;
148 case Graphics::RIGHT:
149 textX = getWidth() - 4;
152 throw GCN_EXCEPTION(
"Unknown alignment.");
155 graphics->setFont(getFont());
156 if (mCaption.size() > 0) {
158 graphics->drawText(getCaption(), textX + 1,
159 textY + 1, getAlignment());
161 graphics->drawText(getCaption(), textX, textY, getAlignment());
173 w = m_upImage->getWidth();
174 h = m_upImage->getHeight();
177 w = std::max(m_downImage->getWidth(), w);
178 h = std::max(m_downImage->getHeight(), h);
181 w = std::max(m_hoverImage->getWidth(), w);
182 h = std::max(m_hoverImage->getHeight(), h);
185 if( mCaption.length() > 0 ) {
186 w = std::max(static_cast<int>(getFont()->getWidth(mCaption)+2*mSpacing), w);
187 h = std::max(static_cast<int>(getFont()->getHeight()+2*mSpacing), h);
205 m_hoverImage = image;
214 if (toggled && m_group !=
"") {
216 GroupIterator iter, iterEnd;
217 iterEnd = m_groupMap.upper_bound(m_group);
219 for (iter = m_groupMap.lower_bound(m_group); iter != iterEnd; iter++) {
220 if (iter->second->isToggled()) {
221 iter->second->setToggled(
false);
232 GroupIterator iter, iterEnd;
233 iterEnd = m_groupMap.upper_bound(m_group);
235 for (iter = m_groupMap.lower_bound(m_group); iter != iterEnd; iter++) {
236 if (iter->second ==
this) {
237 m_groupMap.erase(iter);
245 m_groupMap.insert( std::pair<std::string, ToggleButton *>(group,
this));