33 #include <guichan/mouseevent.hpp>
39 #include "util/log/logger.h"
41 #include "togglebutton.h"
46 ToggleButton::GroupMap ToggleButton::m_groupMap;
51 m_downImage(down_file),
52 m_hoverImage(hover_file),
57 m_hoverImage = hover_file;
64 addActionListener(
this);
77 Color faceColor = getBaseColor();
80 int32_t alpha = getBaseColor().a;
86 if (isPressed() || m_toggled) {
87 faceColor = faceColor - 0x303030;
89 highlightColor = faceColor - 0x303030;
90 highlightColor.a = alpha;
91 shadowColor = faceColor + 0x303030;
92 shadowColor.a = alpha;
96 xoffset = x_downoffset;
97 yoffset = y_downoffset;
99 }
else if(mHasMouse) {
100 faceColor = faceColor + 0x303030;
102 highlightColor = faceColor + 0x303030;
103 highlightColor.a = alpha;
104 shadowColor = faceColor - 0x303030;
105 shadowColor.a = alpha;
107 if ( m_hoverImage ) {
111 highlightColor = faceColor + 0x303030;
112 highlightColor.a = alpha;
113 shadowColor = faceColor - 0x303030;
114 shadowColor.a = alpha;
122 graphics->setColor(faceColor);
123 graphics->fillRectangle(Rectangle(1, 1, getDimension().width-1, getHeight() - 1));
125 graphics->setColor(highlightColor);
126 graphics->drawLine(0, 0, getWidth() - 1, 0);
127 graphics->drawLine(0, 1, 0, getHeight() - 1);
129 graphics->setColor(shadowColor);
130 graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1);
131 graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1);
133 graphics->setColor(getForegroundColor());
136 graphics->drawImage(img, xoffset, yoffset);
140 int32_t textY = getHeight() / 2 - getFont()->getHeight() / 2;
141 switch (getAlignment())
146 case Graphics::CENTER:
147 textX = getWidth() / 2;
149 case Graphics::RIGHT:
150 textX = getWidth() - 4;
155 FL_WARN(_log,
FIFE::LMsg(
"ToggleButton::draw() - ") <<
"Unknown alignment: "
156 << getAlignment() <<
". Using the default of Graphics::LEFT");
159 graphics->setFont(getFont());
160 if (mCaption.size() > 0) {
162 graphics->drawText(getCaption(), textX + 1,
163 textY + 1, getAlignment());
165 graphics->drawText(getCaption(), textX, textY, getAlignment());
177 w = m_upImage->getWidth();
178 h = m_upImage->getHeight();
181 w = std::max(m_downImage->getWidth(), w);
182 h = std::max(m_downImage->getHeight(), h);
185 w = std::max(m_hoverImage->getWidth(), w);
186 h = std::max(m_hoverImage->getHeight(), h);
189 if( mCaption.length() > 0 ) {
190 w = std::max(static_cast<int32_t>(getFont()->getWidth(mCaption)+2*mSpacing), w);
191 h = std::max(static_cast<int32_t>(getFont()->getHeight()+2*mSpacing), h);
209 m_hoverImage = image;
218 if (toggled && m_group !=
"") {
220 GroupIterator iter, iterEnd;
221 iterEnd = m_groupMap.upper_bound(m_group);
223 for (iter = m_groupMap.lower_bound(m_group); iter != iterEnd; iter++) {
224 if (iter->second->isToggled()) {
225 iter->second->setToggled(
false);
236 GroupIterator iter, iterEnd;
237 iterEnd = m_groupMap.upper_bound(m_group);
239 for (iter = m_groupMap.lower_bound(m_group); iter != iterEnd; iter++) {
240 if (iter->second ==
this) {
241 m_groupMap.erase(iter);
249 m_groupMap.insert( std::pair<std::string, ToggleButton *>(group,
this));