summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-05-31 01:27:37 +0300
committerAndrei Karas <akaras@inbox.ru>2011-05-31 01:27:37 +0300
commit9d3b975bcb84ad1c61d628de2804751c0d0707dd (patch)
treefe7494b1ecd561a40dc96d088c77d69b6d4ce13e /src
parent1d0044cbc81e547ad688a295288910d58e1a3fb1 (diff)
downloadplus-9d3b975bcb84ad1c61d628de2804751c0d0707dd.tar.gz
plus-9d3b975bcb84ad1c61d628de2804751c0d0707dd.tar.bz2
plus-9d3b975bcb84ad1c61d628de2804751c0d0707dd.tar.xz
plus-9d3b975bcb84ad1c61d628de2804751c0d0707dd.zip
Fix code style and missing members initialisations.
Diffstat (limited to 'src')
-rw-r--r--src/guichan/basiccontainer.cpp90
-rw-r--r--src/guichan/basiccontainer.hpp3
-rw-r--r--src/guichan/cliprectangle.cpp10
-rw-r--r--src/guichan/color.cpp36
-rw-r--r--src/guichan/defaultfont.cpp5
-rw-r--r--src/guichan/defaultfont.hpp6
-rw-r--r--src/guichan/focushandler.cpp130
-rw-r--r--src/guichan/focushandler.hpp9
-rw-r--r--src/guichan/font.cpp4
-rw-r--r--src/guichan/graphics.cpp62
-rw-r--r--src/guichan/gui.cpp332
-rw-r--r--src/guichan/gui.hpp3
-rw-r--r--src/guichan/image.cpp6
-rw-r--r--src/guichan/image.hpp9
-rw-r--r--src/guichan/imageloader.hpp6
-rw-r--r--src/guichan/key.cpp26
-rw-r--r--src/guichan/keyinput.hpp9
-rw-r--r--src/guichan/mouseinput.hpp8
-rw-r--r--src/guichan/sdl/sdlgraphics.cpp225
-rw-r--r--src/guichan/sdl/sdlimage.cpp24
-rw-r--r--src/guichan/sdl/sdlpixel.hpp213
-rw-r--r--src/guichan/widget.cpp113
-rw-r--r--src/guichan/widgets/button.cpp13
-rw-r--r--src/guichan/widgets/dropdown.cpp161
-rw-r--r--src/guichan/widgets/dropdown.hpp7
-rw-r--r--src/guichan/widgets/imagebutton.cpp47
-rw-r--r--src/guichan/widgets/listbox.cpp128
-rw-r--r--src/guichan/widgets/radiobutton.cpp55
-rw-r--r--src/guichan/widgets/scrollarea.cpp236
-rw-r--r--src/guichan/widgets/slider.cpp63
-rw-r--r--src/guichan/widgets/tab.cpp29
-rw-r--r--src/guichan/widgets/tabbedarea.cpp73
-rw-r--r--src/guichan/widgets/textbox.cpp84
-rw-r--r--src/guichan/widgets/textfield.cpp44
-rw-r--r--src/guichan/widgets/window.cpp62
35 files changed, 971 insertions, 1360 deletions
diff --git a/src/guichan/basiccontainer.cpp b/src/guichan/basiccontainer.cpp
index 85f0b1b2f..38dbc44f7 100644
--- a/src/guichan/basiccontainer.cpp
+++ b/src/guichan/basiccontainer.cpp
@@ -64,7 +64,7 @@ namespace gcn
void BasicContainer::moveToTop(Widget* widget)
{
WidgetListIterator iter;
- for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++)
+ for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter)
{
if (*iter == widget)
{
@@ -83,9 +83,8 @@ namespace gcn
iter = find(mWidgets.begin(), mWidgets.end(), widget);
if (iter == mWidgets.end())
- {
throw GCN_EXCEPTION("There is no such widget in this container.");
- }
+
mWidgets.erase(iter);
mWidgets.push_front(widget);
}
@@ -96,9 +95,7 @@ namespace gcn
iter = find(mWidgets.begin(), mWidgets.end(), event.getSource());
if (iter == mWidgets.end())
- {
throw GCN_EXCEPTION("There is no such widget in this container.");
- }
mWidgets.erase(iter);
}
@@ -112,29 +109,23 @@ namespace gcn
{
WidgetListIterator it;
- for (it = mWidgets.begin(); it != mWidgets.end(); it++)
+ for (it = mWidgets.begin(); it != mWidgets.end(); ++ it)
{
if ((*it)->isFocused())
- {
break;
- }
}
WidgetListIterator end = it;
if (it == mWidgets.end())
- {
it = mWidgets.begin();
- }
- it++;
+ ++ it;
- for ( ; it != end; it++)
+ for ( ; it != end; ++ it)
{
if (it == mWidgets.end())
- {
it = mWidgets.begin();
- }
if ((*it)->isFocusable())
{
@@ -148,29 +139,23 @@ namespace gcn
{
WidgetListReverseIterator it;
- for (it = mWidgets.rbegin(); it != mWidgets.rend(); it++)
+ for (it = mWidgets.rbegin(); it != mWidgets.rend(); ++ it)
{
if ((*it)->isFocused())
- {
break;
- }
}
WidgetListReverseIterator end = it;
- it++;
+ ++ it;
if (it == mWidgets.rend())
- {
it = mWidgets.rbegin();
- }
- for ( ; it != end; it++)
+ for ( ; it != end; ++ it)
{
if (it == mWidgets.rend())
- {
it = mWidgets.rbegin();
- }
if ((*it)->isFocusable())
{
@@ -185,17 +170,16 @@ namespace gcn
Rectangle r = getChildrenArea();
if (!r.isPointInRect(x, y))
- {
return NULL;
- }
x -= r.x;
y -= r.y;
WidgetListReverseIterator it;
- for (it = mWidgets.rbegin(); it != mWidgets.rend(); it++)
+ for (it = mWidgets.rbegin(); it != mWidgets.rend(); ++ it)
{
- if ((*it)->isVisible() && (*it)->getDimension().isPointInRect(x, y))
+ if ((*it)->isVisible() && (*it)->getDimension()
+ .isPointInRect(x, y))
{
return (*it);
}
@@ -214,12 +198,10 @@ namespace gcn
Widget::_setFocusHandler(focusHandler);
if (mInternalFocusHandler != NULL)
- {
return;
- }
WidgetListIterator iter;
- for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++)
+ for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter)
{
(*iter)->_setFocusHandler(focusHandler);
}
@@ -230,13 +212,9 @@ namespace gcn
mWidgets.push_back(widget);
if (mInternalFocusHandler == NULL)
- {
widget->_setFocusHandler(_getFocusHandler());
- }
else
- {
widget->_setFocusHandler(mInternalFocusHandler);
- }
widget->_setParent(this);
widget->addDeathListener(this);
@@ -245,7 +223,7 @@ namespace gcn
void BasicContainer::remove(Widget* widget)
{
WidgetListIterator iter;
- for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++)
+ for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter)
{
if (*iter == widget)
{
@@ -264,7 +242,7 @@ namespace gcn
{
WidgetListIterator iter;
- for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++)
+ for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter)
{
(*iter)->_setFocusHandler(NULL);
(*iter)->_setParent(NULL);
@@ -279,7 +257,7 @@ namespace gcn
graphics->pushClipArea(getChildrenArea());
WidgetListIterator iter;
- for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++)
+ for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter)
{
if ((*iter)->isVisible())
{
@@ -309,10 +287,8 @@ namespace gcn
void BasicContainer::logicChildren()
{
WidgetListIterator iter;
- for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++)
- {
+ for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter)
(*iter)->logic();
- }
}
void BasicContainer::showWidgetPart(Widget* widget, Rectangle area)
@@ -321,67 +297,57 @@ namespace gcn
area.x += widget->getX();
area.y += widget->getY();
-
+
if (area.x + area.width > widgetArea.width)
{
- widget->setX(widget->getX() - area.x - area.width + widgetArea.width);
+ widget->setX(widget->getX() - area.x
+ - area.width + widgetArea.width);
}
if (area.y + area.height > widgetArea.height)
{
- widget->setY(widget->getY() - area.y - area.height + widgetArea.height);
+ widget->setY(widget->getY() - area.y
+ - area.height + widgetArea.height);
}
if (area.x < 0)
- {
widget->setX(widget->getX() - area.x);
- }
if (area.y < 0)
- {
widget->setY(widget->getY() - area.y);
- }
}
-
void BasicContainer::setInternalFocusHandler(FocusHandler* focusHandler)
{
Widget::setInternalFocusHandler(focusHandler);
WidgetListIterator iter;
- for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++)
+ for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter)
{
if (mInternalFocusHandler == NULL)
- {
(*iter)->_setFocusHandler(_getFocusHandler());
- }
else
- {
(*iter)->_setFocusHandler(mInternalFocusHandler);
- }
}
}
Widget* BasicContainer::findWidgetById(const std::string& id)
{
WidgetListIterator iter;
- for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++)
+ for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter)
{
if ((*iter)->getId() == id)
- {
return (*iter);
- }
-
- BasicContainer *basicContainer = dynamic_cast<BasicContainer*>(*iter);
-
+
+ BasicContainer *basicContainer
+ = dynamic_cast<BasicContainer*>(*iter);
+
if (basicContainer != NULL)
{
Widget *widget = basicContainer->findWidgetById(id);
-
+
if (widget != NULL)
- {
return widget;
- }
}
}
diff --git a/src/guichan/basiccontainer.hpp b/src/guichan/basiccontainer.hpp
index 7a0b67141..269a5ba44 100644
--- a/src/guichan/basiccontainer.hpp
+++ b/src/guichan/basiccontainer.hpp
@@ -60,7 +60,8 @@ namespace gcn
* @see Container
* @since 0.6.0
*/
- class GCN_CORE_DECLSPEC BasicContainer : public Widget, public DeathListener
+ class GCN_CORE_DECLSPEC BasicContainer : public Widget,
+ public DeathListener
{
public:
/**
diff --git a/src/guichan/cliprectangle.cpp b/src/guichan/cliprectangle.cpp
index f73df1e84..8886bb5e9 100644
--- a/src/guichan/cliprectangle.cpp
+++ b/src/guichan/cliprectangle.cpp
@@ -51,10 +51,16 @@ namespace gcn
{
ClipRectangle::ClipRectangle()
{
- x = y = width = height = xOffset = yOffset = 0;
+ x = 0;
+ y = 0;
+ width = 0;
+ height = 0;
+ xOffset = 0;
+ yOffset = 0;
}
- ClipRectangle::ClipRectangle(int x, int y, int width, int height, int xOffset, int yOffset)
+ ClipRectangle::ClipRectangle(int x, int y, int width, int height,
+ int xOffset, int yOffset)
{
this->x = x;
this->y = y;
diff --git a/src/guichan/color.cpp b/src/guichan/color.cpp
index 15f9ea0ee..5122e94b0 100644
--- a/src/guichan/color.cpp
+++ b/src/guichan/color.cpp
@@ -49,35 +49,35 @@
namespace gcn
{
- Color::Color()
- : r(0),
- g(0),
- b(0),
- a(255)
+ Color::Color() :
+ r(0),
+ g(0),
+ b(0),
+ a(255)
{
}
- Color::Color(int color)
- : r( (color >> 16) & 0xFF),
- g( (color >> 8) & 0xFF),
- b( color & 0xFF),
+ Color::Color(int color) :
+ r((color >> 16) & 0xFF),
+ g((color >> 8) & 0xFF),
+ b(color & 0xFF),
a(255)
{
}
- Color::Color(int ar, int ag, int ab, int aa)
- : r(ar),
- g(ag),
- b(ab),
- a(aa)
+ Color::Color(int ar, int ag, int ab, int aa) :
+ r(ar),
+ g(ag),
+ b(ab),
+ a(aa)
{
}
Color Color::operator+(const Color& color) const
{
- Color result(r + color.r,
- g + color.g,
- b + color.b,
+ Color result(r + color.r,
+ g + color.g,
+ b + color.b,
255);
result.r = (result.r>255?255:(result.r<0?0:result.r));
@@ -125,7 +125,7 @@ namespace gcn
return !(r == color.r && g == color.g && b == color.b && a == color.a);
}
- std::ostream& operator<<(std::ostream& out,
+ std::ostream& operator<<(std::ostream& out,
const Color& color)
{
out << "Color [r = "
diff --git a/src/guichan/defaultfont.cpp b/src/guichan/defaultfont.cpp
index aa8f0c24f..19046c687 100644
--- a/src/guichan/defaultfont.cpp
+++ b/src/guichan/defaultfont.cpp
@@ -72,7 +72,8 @@ namespace gcn
return 8;
}
- void DefaultFont::drawString(Graphics* graphics, const std::string& text, int x, int y)
+ void DefaultFont::drawString(Graphics* graphics, const std::string& text,
+ int x, int y)
{
unsigned int i;
@@ -86,9 +87,7 @@ namespace gcn
int DefaultFont::getStringIndexAt(const std::string& text, int x) const
{
if (x > (int)text.size() * 8)
- {
return text.size();
- }
return x / 8;
}
diff --git a/src/guichan/defaultfont.hpp b/src/guichan/defaultfont.hpp
index 9343e96d3..e5a830e4c 100644
--- a/src/guichan/defaultfont.hpp
+++ b/src/guichan/defaultfont.hpp
@@ -83,12 +83,14 @@ namespace gcn
* @param y The y coordinate where to draw the glyph.
* @return The width of the drawn glyph in pixels.
*/
- virtual int drawGlyph(Graphics* graphics, unsigned char glyph, int x, int y);
+ virtual int drawGlyph(Graphics* graphics, unsigned char glyph,
+ int x, int y);
// Inherited from Font
- virtual void drawString(Graphics* graphics, const std::string& text, int x, int y);
+ virtual void drawString(Graphics* graphics, const std::string& text,
+ int x, int y);
virtual int getWidth(const std::string& text) const;
diff --git a/src/guichan/focushandler.cpp b/src/guichan/focushandler.cpp
index 069a72857..efc76fb43 100644
--- a/src/guichan/focushandler.cpp
+++ b/src/guichan/focushandler.cpp
@@ -53,17 +53,16 @@
namespace gcn
{
- FocusHandler::FocusHandler()
- :mFocusedWidget(NULL),
- mModalFocusedWidget(NULL),
- mModalMouseInputFocusedWidget(NULL),
- mDraggedWidget(NULL),
- mLastWidgetWithMouse(NULL),
- mLastWidgetWithModalFocus(NULL),
- mLastWidgetWithModalMouseInputFocus(NULL),
- mLastWidgetPressed(NULL)
+ FocusHandler::FocusHandler() :
+ mFocusedWidget(NULL),
+ mModalFocusedWidget(NULL),
+ mModalMouseInputFocusedWidget(NULL),
+ mDraggedWidget(NULL),
+ mLastWidgetWithMouse(NULL),
+ mLastWidgetWithModalFocus(NULL),
+ mLastWidgetWithModalMouseInputFocus(NULL),
+ mLastWidgetPressed(NULL)
{
-
}
void FocusHandler::requestFocus(Widget* widget)
@@ -73,7 +72,7 @@ namespace gcn
{
return;
}
-
+
unsigned int i = 0;
int toBeFocusedIndex = -1;
for (i = 0; i < mWidgets.size(); ++i)
@@ -84,35 +83,31 @@ namespace gcn
break;
}
}
-
+
if (toBeFocusedIndex < 0)
- {
throw GCN_EXCEPTION("Trying to focus a none existing widget.");
- }
-
+
Widget *oldFocused = mFocusedWidget;
-
+
if (oldFocused != widget)
{
mFocusedWidget = mWidgets.at(toBeFocusedIndex);
-
+
if (oldFocused != NULL)
{
Event focusEvent(oldFocused);
distributeFocusLostEvent(focusEvent);
}
-
+
Event focusEvent(mWidgets.at(toBeFocusedIndex));
distributeFocusGainedEvent(focusEvent);
- }
+ }
}
void FocusHandler::requestModalFocus(Widget* widget)
{
if (mModalFocusedWidget != NULL && mModalFocusedWidget != widget)
- {
throw GCN_EXCEPTION("Another widget already has modal focus.");
- }
mModalFocusedWidget = widget;
@@ -128,7 +123,8 @@ namespace gcn
if (mModalMouseInputFocusedWidget != NULL
&& mModalMouseInputFocusedWidget != widget)
{
- throw GCN_EXCEPTION("Another widget already has modal input focus.");
+ throw GCN_EXCEPTION("Another widget already has "
+ "modal input focus.");
}
mModalMouseInputFocusedWidget = widget;
@@ -137,17 +133,13 @@ namespace gcn
void FocusHandler::releaseModalFocus(Widget* widget)
{
if (mModalFocusedWidget == widget)
- {
mModalFocusedWidget = NULL;
- }
}
void FocusHandler::releaseModalMouseInputFocus(Widget* widget)
{
if (mModalMouseInputFocusedWidget == widget)
- {
mModalMouseInputFocusedWidget = NULL;
- }
}
Widget* FocusHandler::getFocused() const
@@ -172,9 +164,7 @@ namespace gcn
for (i = 0; i < (int)mWidgets.size(); ++i)
{
if (mWidgets[i] == mFocusedWidget)
- {
focusedWidget = i;
- }
}
int focused = focusedWidget;
@@ -183,25 +173,21 @@ namespace gcn
i = (int)mWidgets.size();
do
{
- ++focusedWidget;
+ ++ focusedWidget;
- if (i==0)
+ if (i == 0)
{
focusedWidget = -1;
break;
}
- --i;
+ -- i;
if (focusedWidget >= (int)mWidgets.size())
- {
focusedWidget = 0;
- }
if (focusedWidget == focused)
- {
return;
- }
}
while (!mWidgets.at(focusedWidget)->isFocusable());
@@ -222,7 +208,7 @@ namespace gcn
void FocusHandler::focusPrevious()
{
- if (mWidgets.size() == 0)
+ if (mWidgets.empty())
{
mFocusedWidget = NULL;
return;
@@ -230,12 +216,10 @@ namespace gcn
int i;
int focusedWidget = -1;
- for (i = 0; i < (int)mWidgets.size(); ++i)
+ for (i = 0; i < (int)mWidgets.size(); ++ i)
{
if (mWidgets[i] == mFocusedWidget)
- {
focusedWidget = i;
- }
}
int focused = focusedWidget;
@@ -244,25 +228,21 @@ namespace gcn
i = (int)mWidgets.size();
do
{
- --focusedWidget;
+ -- focusedWidget;
- if (i==0)
+ if (i == 0)
{
focusedWidget = -1;
break;
}
- --i;
+ -- i;
if (focusedWidget <= 0)
- {
focusedWidget = mWidgets.size() - 1;
- }
if (focusedWidget == focused)
- {
return;
- }
}
while (!mWidgets.at(focusedWidget)->isFocusable());
@@ -312,8 +292,8 @@ namespace gcn
{
mDraggedWidget = NULL;
return;
- }
-
+ }
+
if (mLastWidgetWithMouse == widget)
{
mLastWidgetWithMouse = NULL;
@@ -356,12 +336,10 @@ namespace gcn
if (mFocusedWidget != NULL)
{
if (!mFocusedWidget->isTabOutEnabled())
- {
return;
- }
}
- if (mWidgets.size() == 0)
+ if (mWidgets.empty())
{
mFocusedWidget = NULL;
return;
@@ -372,9 +350,7 @@ namespace gcn
for (i = 0; i < (int)mWidgets.size(); ++i)
{
if (mWidgets[i] == mFocusedWidget)
- {
focusedWidget = i;
- }
}
int focused = focusedWidget;
bool done = false;
@@ -384,30 +360,26 @@ namespace gcn
i = (int)mWidgets.size();
do
{
- ++focusedWidget;
+ ++ focusedWidget;
- if (i==0)
+ if (i == 0)
{
focusedWidget = -1;
break;
}
- --i;
+ -- i;
if (focusedWidget >= (int)mWidgets.size())
- {
focusedWidget = 0;
- }
if (focusedWidget == focused)
- {
return;
- }
if (mWidgets.at(focusedWidget)->isFocusable() &&
mWidgets.at(focusedWidget)->isTabInEnabled() &&
(mModalFocusedWidget == NULL ||
- mWidgets.at(focusedWidget)->isModalFocused()))
+ mWidgets.at(focusedWidget)->isModalFocused()))
{
done = true;
}
@@ -433,12 +405,10 @@ namespace gcn
if (mFocusedWidget != NULL)
{
if (!mFocusedWidget->isTabOutEnabled())
- {
return;
- }
}
- if (mWidgets.size() == 0)
+ if (mWidgets.empty())
{
mFocusedWidget = NULL;
return;
@@ -449,9 +419,7 @@ namespace gcn
for (i = 0; i < (int)mWidgets.size(); ++i)
{
if (mWidgets[i] == mFocusedWidget)
- {
focusedWidget = i;
- }
}
int focused = focusedWidget;
bool done = false;
@@ -461,30 +429,26 @@ namespace gcn
i = (int)mWidgets.size();
do
{
- --focusedWidget;
+ -- focusedWidget;
- if (i==0)
+ if (i == 0)
{
focusedWidget = -1;
break;
}
- --i;
+ -- i;
if (focusedWidget <= 0)
- {
focusedWidget = mWidgets.size() - 1;
- }
if (focusedWidget == focused)
- {
return;
- }
if (mWidgets.at(focusedWidget)->isFocusable() &&
mWidgets.at(focusedWidget)->isTabInEnabled() &&
(mModalFocusedWidget == NULL ||
- mWidgets.at(focusedWidget)->isModalFocused()))
+ mWidgets.at(focusedWidget)->isModalFocused()))
{
done = true;
}
@@ -509,12 +473,13 @@ namespace gcn
{
Widget* sourceWidget = focusEvent.getSource();
- std::list<FocusListener*> focusListeners = sourceWidget->_getFocusListeners();
+ std::list<FocusListener*> focusListeners
+ = sourceWidget->_getFocusListeners();
// Send the event to all focus listeners of the widget.
for (std::list<FocusListener*>::iterator it = focusListeners.begin();
it != focusListeners.end();
- ++it)
+ ++ it)
{
(*it)->focusLost(focusEvent);
}
@@ -524,12 +489,13 @@ namespace gcn
{
Widget* sourceWidget = focusEvent.getSource();
- std::list<FocusListener*> focusListeners = sourceWidget->_getFocusListeners();
+ std::list<FocusListener*> focusListeners
+ = sourceWidget->_getFocusListeners();
// Send the event to all focus listeners of the widget.
for (std::list<FocusListener*>::iterator it = focusListeners.begin();
it != focusListeners.end();
- ++it)
+ ++ it)
{
(*it)->focusGained(focusEvent);
}
@@ -560,9 +526,9 @@ namespace gcn
return mLastWidgetWithModalFocus;
}
- void FocusHandler::setLastWidgetWithModalFocus(Widget* lastWidgetWithModalFocus)
+ void FocusHandler::setLastWidgetWithModalFocus(Widget* widget)
{
- mLastWidgetWithModalFocus = lastWidgetWithModalFocus;
+ mLastWidgetWithModalFocus = widget;
}
Widget* FocusHandler::getLastWidgetWithModalMouseInputFocus()
@@ -570,9 +536,9 @@ namespace gcn
return mLastWidgetWithModalMouseInputFocus;
}
- void FocusHandler::setLastWidgetWithModalMouseInputFocus(Widget* lastWidgetWithModalMouseInputFocus)
+ void FocusHandler::setLastWidgetWithModalMouseInputFocus(Widget* widget)
{
- mLastWidgetWithModalMouseInputFocus = lastWidgetWithModalMouseInputFocus;
+ mLastWidgetWithModalMouseInputFocus = widget;
}
Widget* FocusHandler::getLastWidgetPressed()
diff --git a/src/guichan/focushandler.hpp b/src/guichan/focushandler.hpp
index 0e2d84099..49bb4e2e5 100644
--- a/src/guichan/focushandler.hpp
+++ b/src/guichan/focushandler.hpp
@@ -277,10 +277,10 @@ namespace gcn
/**
* Sets the last widget with modal focus.
*
- * @param lastWidgetWithModalFocus The last widget with modal focus.
+ * @param widget The last widget with modal focus.
* @see getLastWidgetWithModalFocus
*/
- virtual void setLastWidgetWithModalFocus(Widget* lastWidgetWithModalFocus);
+ virtual void setLastWidgetWithModalFocus(Widget* widget);
/**
* Gets the last widget with modal mouse input focus.
@@ -293,11 +293,10 @@ namespace gcn
/**
* Sets the last widget with modal mouse input focus.
*
- * @param lastMouseWithModalMouseInputFocus The last widget with
- * modal mouse input focus.
+ * @param widget The last widget with modal mouse input focus.
* @see getLastWidgetWithModalMouseInputFocus
*/
- virtual void setLastWidgetWithModalMouseInputFocus(Widget* lastWidgetWithModalMouseInputFocus);
+ virtual void setLastWidgetWithModalMouseInputFocus(Widget* widget);
/**
* Gets the last widget pressed. Used by the Gui class to keep track
diff --git a/src/guichan/font.cpp b/src/guichan/font.cpp
index 5583cdb57..aa5924832 100644
--- a/src/guichan/font.cpp
+++ b/src/guichan/font.cpp
@@ -58,12 +58,10 @@ namespace gcn
for (i = 0; i < text.size(); ++i)
{
- size = getWidth(text.substr(0,i));
+ size = getWidth(text.substr(0, i));
if (size > x)
- {
return i;
- }
}
return text.size();
diff --git a/src/guichan/graphics.cpp b/src/guichan/graphics.cpp
index 688362c12..7809223b7 100644
--- a/src/guichan/graphics.cpp
+++ b/src/guichan/graphics.cpp
@@ -54,9 +54,9 @@
namespace gcn
{
- Graphics::Graphics()
+ Graphics::Graphics() :
+ mFont(NULL)
{
- mFont = NULL;
}
bool Graphics::pushClipArea(Rectangle area)
@@ -70,7 +70,7 @@ namespace gcn
mClipStack.push(carea);
return true;
}
-
+
if (mClipStack.empty())
{
ClipRectangle carea;
@@ -94,39 +94,31 @@ namespace gcn
// Clamp the pushed clip rectangle.
if (carea.x < top.x)
- {
carea.x = top.x;
- }
-
+
if (carea.y < top.y)
- {
- carea.y = top.y;
- }
-
+ carea.y = top.y;
+
if (carea.x + carea.width > top.x + top.width)
{
carea.width = top.x + top.width - carea.x;
if (carea.width < 0)
- {
carea.width = 0;
- }
}
-
+
if (carea.y + carea.height > top.y + top.height)
{
carea.height = top.y + top.height - carea.y;
-
+
if (carea.height < 0)
- {
carea.height = 0;
- }
}
-
+
bool result = carea.isIntersecting(top);
-
+
mClipStack.push(carea);
-
+
return result;
}
@@ -134,9 +126,7 @@ namespace gcn
{
if (mClipStack.empty())
- {
throw GCN_EXCEPTION("Tried to pop clip area from empty stack.");
- }
mClipStack.pop();
}
@@ -144,16 +134,15 @@ namespace gcn
const ClipRectangle& Graphics::getCurrentClipArea()
{
if (mClipStack.empty())
- {
throw GCN_EXCEPTION("The clip area stack is empty.");
- }
return mClipStack.top();
}
void Graphics::drawImage(const Image* image, int dstX, int dstY)
{
- drawImage(image, 0, 0, dstX, dstY, image->getWidth(), image->getHeight());
+ drawImage(image, 0, 0, dstX, dstY,
+ image->getWidth(), image->getHeight());
}
void Graphics::setFont(Font* font)
@@ -165,23 +154,22 @@ namespace gcn
Alignment alignment)
{
if (mFont == NULL)
- {
throw GCN_EXCEPTION("No font set.");
- }
switch (alignment)
{
- case LEFT:
- mFont->drawString(this, text, x, y);
- break;
- case CENTER:
- mFont->drawString(this, text, x - mFont->getWidth(text) / 2, y);
- break;
- case RIGHT:
- mFont->drawString(this, text, x - mFont->getWidth(text), y);
- break;
- default:
- throw GCN_EXCEPTION("Unknown alignment.");
+ case LEFT:
+ mFont->drawString(this, text, x, y);
+ break;
+ case CENTER:
+ mFont->drawString(this, text, x
+ - mFont->getWidth(text) / 2, y);
+ break;
+ case RIGHT:
+ mFont->drawString(this, text, x - mFont->getWidth(text), y);
+ break;
+ default:
+ throw GCN_EXCEPTION("Unknown alignment.");
}
}
}
diff --git a/src/guichan/gui.cpp b/src/guichan/gui.cpp
index ae9adea13..f8376646f 100644
--- a/src/guichan/gui.cpp
+++ b/src/guichan/gui.cpp
@@ -60,21 +60,21 @@
namespace gcn
{
- Gui::Gui()
- :mTop(NULL),
- mGraphics(NULL),
- mInput(NULL),
- mTabbing(true),
- mShiftPressed(false),
- mMetaPressed(false),
- mControlPressed(false),
- mAltPressed(false),
- mLastMousePressButton(0),
- mLastMousePressTimeStamp(0),
- mLastMouseX(0),
- mLastMouseY(0),
- mClickCount(1),
- mLastMouseDragButton(0)
+ Gui::Gui() :
+ mTop(NULL),
+ mGraphics(NULL),
+ mInput(NULL),
+ mTabbing(true),
+ mShiftPressed(false),
+ mMetaPressed(false),
+ mControlPressed(false),
+ mAltPressed(false),
+ mLastMousePressButton(0),
+ mLastMousePressTimeStamp(0),
+ mLastMouseX(0),
+ mLastMouseY(0),
+ mClickCount(1),
+ mLastMouseDragButton(0)
{
mFocusHandler = new FocusHandler();
}
@@ -82,9 +82,7 @@ namespace gcn
Gui::~Gui()
{
if (Widget::widgetExists(mTop))
- {
setTop(NULL);
- }
delete mFocusHandler;
}
@@ -92,13 +90,9 @@ namespace gcn
void Gui::setTop(Widget* top)
{
if (mTop != NULL)
- {
mTop->_setFocusHandler(NULL);
- }
if (top != NULL)
- {
top->_setFocusHandler(mFocusHandler);
- }
mTop = top;
}
@@ -131,9 +125,7 @@ namespace gcn
void Gui::logic()
{
if (mTop == NULL)
- {
throw GCN_EXCEPTION("No top widget set");
- }
handleModalFocus();
handleModalMouseInputFocus();
@@ -153,18 +145,12 @@ namespace gcn
void Gui::draw()
{
if (mTop == NULL)
- {
throw GCN_EXCEPTION("No top widget set");
- }
if (mGraphics == NULL)
- {
throw GCN_EXCEPTION("No graphics set");
- }
if (!mTop->isVisible())
- {
return;
- }
mGraphics->_beginDraw();
@@ -227,24 +213,24 @@ namespace gcn
switch (mouseInput.getType())
{
- case MouseInput::PRESSED:
- handleMousePressed(mouseInput);
- break;
- case MouseInput::RELEASED:
- handleMouseReleased(mouseInput);
- break;
- case MouseInput::MOVED:
- handleMouseMoved(mouseInput);
- break;
- case MouseInput::WHEEL_MOVED_DOWN:
- handleMouseWheelMovedDown(mouseInput);
- break;
- case MouseInput::WHEEL_MOVED_UP:
- handleMouseWheelMovedUp(mouseInput);
- break;
- default:
- throw GCN_EXCEPTION("Unknown mouse input type.");
- break;
+ case MouseInput::PRESSED:
+ handleMousePressed(mouseInput);
+ break;
+ case MouseInput::RELEASED:
+ handleMouseReleased(mouseInput);
+ break;
+ case MouseInput::MOVED:
+ handleMouseMoved(mouseInput);
+ break;
+ case MouseInput::WHEEL_MOVED_DOWN:
+ handleMouseWheelMovedDown(mouseInput);
+ break;
+ case MouseInput::WHEEL_MOVED_UP:
+ handleMouseWheelMovedUp(mouseInput);
+ break;
+ default:
+ throw GCN_EXCEPTION("Unknown mouse input type.");
+ break;
}
}
}
@@ -270,17 +256,16 @@ namespace gcn
keyInput.isNumericPad(),
keyInput.getKey());
- distributeKeyEventToGlobalKeyListeners(keyEventToGlobalKeyListeners);
+ distributeKeyEventToGlobalKeyListeners(
+ keyEventToGlobalKeyListeners);
// If a global key listener consumes the event it will not be
// sent further to the source of the event.
if (keyEventToGlobalKeyListeners.isConsumed())
- {
continue;
- }
bool keyEventConsumed = false;
-
+
// Send key inputs to the focused widgets
if (mFocusHandler->getFocused() != NULL)
{
@@ -292,16 +277,11 @@ namespace gcn
keyInput.getType(),
keyInput.isNumericPad(),
keyInput.getKey());
-
if (!mFocusHandler->getFocused()->isFocusable())
- {
mFocusHandler->focusNone();
- }
else
- {
- distributeKeyEvent(keyEvent);
- }
+ distributeKeyEvent(keyEvent);
keyEventConsumed = keyEvent.isConsumed();
}
@@ -309,34 +289,27 @@ namespace gcn
// If the key event hasn't been consumed and
// tabbing is enable check for tab press and
// change focus.
- if (!keyEventConsumed
- && mTabbing
+ if (!keyEventConsumed && mTabbing
&& keyInput.getKey().getValue() == Key::TAB
&& keyInput.getType() == KeyInput::PRESSED)
{
if (keyInput.isShiftPressed())
- {
mFocusHandler->tabPrevious();
- }
else
- {
mFocusHandler->tabNext();
- }
- }
-
+ }
} // end while
}
void Gui::handleMouseMoved(const MouseInput& mouseInput)
{
// Check if the mouse leaves the application window.
- if (!mWidgetWithMouseQueue.empty()
- && (mouseInput.getX() < 0
- || mouseInput.getY() < 0
- || !mTop->getDimension().isPointInRect(mouseInput.getX(), mouseInput.getY()))
- )
+ if (!mWidgetWithMouseQueue.empty() && (mouseInput.getX() < 0
+ || mouseInput.getY() < 0 || !mTop->getDimension().isPointInRect(
+ mouseInput.getX(), mouseInput.getY())))
{
- // Distribute an event to all widgets in the "widget with mouse" queue.
+ // Distribute an event to all widgets in the
+ // "widget with mouse" queue.
while (!mWidgetWithMouseQueue.empty())
{
Widget* widget = mWidgetWithMouseQueue.front();
@@ -367,10 +340,10 @@ namespace gcn
std::deque<Widget*>::iterator iter;
for (iter = mWidgetWithMouseQueue.begin();
iter != mWidgetWithMouseQueue.end();
- iter++)
+ ++ iter)
{
Widget* widget = *iter;
-
+
// If a widget in the "widget with mouse queue" doesn't
// exists anymore it should be removed from the queue.
if (!Widget::widgetExists(widget))
@@ -395,7 +368,7 @@ namespace gcn
mouseInput.getX(),
mouseInput.getY(),
true,
- true);
+ true);
mClickCount = 1;
mLastMousePressTimeStamp = 0;
mWidgetWithMouseQueue.erase(iter);
@@ -406,21 +379,24 @@ namespace gcn
iterations++;
}
- widgetWithMouseQueueCheckDone = iterations == mWidgetWithMouseQueue.size();
+ widgetWithMouseQueueCheckDone =
+ (iterations == mWidgetWithMouseQueue.size());
}
// Check all widgets below the mouse to see if they are
// present in the "widget with mouse" queue. If a widget
// is not then it should be added and an entered event should
// be sent to it.
- Widget* parent = getMouseEventSource(mouseInput.getX(), mouseInput.getY());
+ Widget* parent = getMouseEventSource(
+ mouseInput.getX(), mouseInput.getY());
Widget* widget = parent;
// If a widget has modal mouse input focus then it will
- // always be returned from getMouseEventSource, but we only wan't to send
- // mouse entered events if the mouse has actually entered the widget with
- // modal mouse input focus, hence we need to check if that's the case. If
- // it's not we should simply ignore to send any mouse entered events.
+ // always be returned from getMouseEventSource, but we only wan't to
+ // send mouse entered events if the mouse has actually entered the
+ // widget with modal mouse input focus, hence we need to check if
+ // that's the case. If it's not we should simply ignore to send any
+ // mouse entered events.
if (mFocusHandler->getModalMouseInputFocused() != NULL
&& widget == mFocusHandler->getModalMouseInputFocused()
&& Widget::widgetExists(widget))
@@ -428,9 +404,8 @@ namespace gcn
int x, y;
widget->getAbsolutePosition(x, y);
- if (x > mouseInput.getX()
- || y > mouseInput.getY()
- || x + widget->getWidth() <= mouseInput.getX()
+ if (x > mouseInput.getX() || y > mouseInput.getY()
+ || x + widget->getWidth() <= mouseInput.getX()
|| y + widget->getHeight() <= mouseInput.getY())
{
parent = NULL;
@@ -446,7 +421,7 @@ namespace gcn
std::deque<Widget*>::iterator iter;
for (iter = mWidgetWithMouseQueue.begin();
iter != mWidgetWithMouseQueue.end();
- iter++)
+ ++ iter)
{
if (*iter == widget)
{
@@ -485,7 +460,9 @@ namespace gcn
}
else
{
- Widget* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY());
+ Widget* sourceWidget = getMouseEventSource(
+ mouseInput.getX(), mouseInput.getY());
+
distributeMouseEvent(sourceWidget,
MouseEvent::MOVED,
mouseInput.getButton(),
@@ -496,12 +473,11 @@ namespace gcn
void Gui::handleMousePressed(const MouseInput& mouseInput)
{
- Widget* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY());
+ Widget* sourceWidget = getMouseEventSource(
+ mouseInput.getX(), mouseInput.getY());
if (mFocusHandler->getDraggedWidget() != NULL)
- {
sourceWidget = mFocusHandler->getDraggedWidget();
- }
int sourceWidgetX, sourceWidgetY;
sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
@@ -540,12 +516,11 @@ namespace gcn
void Gui::handleMouseWheelMovedDown(const MouseInput& mouseInput)
{
- Widget* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY());
+ Widget* sourceWidget = getMouseEventSource(
+ mouseInput.getX(), mouseInput.getY());
if (mFocusHandler->getDraggedWidget() != NULL)
- {
sourceWidget = mFocusHandler->getDraggedWidget();
- }
int sourceWidgetX, sourceWidgetY;
sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
@@ -559,12 +534,11 @@ namespace gcn
void Gui::handleMouseWheelMovedUp(const MouseInput& mouseInput)
{
- Widget* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY());
+ Widget* sourceWidget = getMouseEventSource(
+ mouseInput.getX(), mouseInput.getY());
if (mFocusHandler->getDraggedWidget() != NULL)
- {
sourceWidget = mFocusHandler->getDraggedWidget();
- }
int sourceWidgetX, sourceWidgetY;
sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
@@ -578,28 +552,27 @@ namespace gcn
void Gui::handleMouseReleased(const MouseInput& mouseInput)
{
- Widget* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY());
+ Widget* sourceWidget = getMouseEventSource(
+ mouseInput.getX(), mouseInput.getY());
if (mFocusHandler->getDraggedWidget() != NULL)
{
if (sourceWidget != mFocusHandler->getLastWidgetPressed())
- {
mFocusHandler->setLastWidgetPressed(NULL);
- }
-
+
sourceWidget = mFocusHandler->getDraggedWidget();
}
int sourceWidgetX, sourceWidgetY;
sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
-
+
distributeMouseEvent(sourceWidget,
MouseEvent::RELEASED,
mouseInput.getButton(),
mouseInput.getX(),
mouseInput.getY());
- if (mouseInput.getButton() == mLastMousePressButton
+ if (mouseInput.getButton() == mLastMousePressButton
&& mFocusHandler->getLastWidgetPressed() == sourceWidget)
{
distributeMouseEvent(sourceWidget,
@@ -607,7 +580,7 @@ namespace gcn
mouseInput.getButton(),
mouseInput.getX(),
mouseInput.getY());
-
+
mFocusHandler->setLastWidgetPressed(NULL);
}
else
@@ -617,9 +590,7 @@ namespace gcn
}
if (mFocusHandler->getDraggedWidget() != NULL)
- {
mFocusHandler->setDraggedWidget(NULL);
- }
}
Widget* Gui::getWidgetAt(int x, int y)
@@ -707,9 +678,7 @@ namespace gcn
// If the widget has been removed due to input
// cancel the distribution.
if (!Widget::widgetExists(widget))
- {
break;
- }
parent = (Widget*)widget->getParent();
@@ -720,53 +689,52 @@ namespace gcn
mouseEvent.mX = x - widgetX;
mouseEvent.mY = y - widgetY;
-
- std::list<MouseListener*> mouseListeners = widget->_getMouseListeners();
+
+ std::list<MouseListener*> mouseListeners
+ = widget->_getMouseListeners();
// Send the event to all mouse listeners of the widget.
- for (std::list<MouseListener*>::iterator it = mouseListeners.begin();
+ for (std::list<MouseListener*>::iterator
+ it = mouseListeners.begin();
it != mouseListeners.end();
++it)
{
switch (mouseEvent.getType())
{
- case MouseEvent::ENTERED:
- (*it)->mouseEntered(mouseEvent);
- break;
- case MouseEvent::EXITED:
- (*it)->mouseExited(mouseEvent);
- break;
- case MouseEvent::MOVED:
- (*it)->mouseMoved(mouseEvent);
- break;
- case MouseEvent::PRESSED:
- (*it)->mousePressed(mouseEvent);
- break;
- case MouseEvent::RELEASED:
- (*it)->mouseReleased(mouseEvent);
- break;
- case MouseEvent::WHEEL_MOVED_UP:
- (*it)->mouseWheelMovedUp(mouseEvent);
- break;
- case MouseEvent::WHEEL_MOVED_DOWN:
- (*it)->mouseWheelMovedDown(mouseEvent);
- break;
- case MouseEvent::DRAGGED:
- (*it)->mouseDragged(mouseEvent);
- break;
- case MouseEvent::CLICKED:
- (*it)->mouseClicked(mouseEvent);
- break;
- default:
- throw GCN_EXCEPTION("Unknown mouse event type.");
- }
+ case MouseEvent::ENTERED:
+ (*it)->mouseEntered(mouseEvent);
+ break;
+ case MouseEvent::EXITED:
+ (*it)->mouseExited(mouseEvent);
+ break;
+ case MouseEvent::MOVED:
+ (*it)->mouseMoved(mouseEvent);
+ break;
+ case MouseEvent::PRESSED:
+ (*it)->mousePressed(mouseEvent);
+ break;
+ case MouseEvent::RELEASED:
+ (*it)->mouseReleased(mouseEvent);
+ break;
+ case MouseEvent::WHEEL_MOVED_UP:
+ (*it)->mouseWheelMovedUp(mouseEvent);
+ break;
+ case MouseEvent::WHEEL_MOVED_DOWN:
+ (*it)->mouseWheelMovedDown(mouseEvent);
+ break;
+ case MouseEvent::DRAGGED:
+ (*it)->mouseDragged(mouseEvent);
+ break;
+ case MouseEvent::CLICKED:
+ (*it)->mouseClicked(mouseEvent);
+ break;
+ default:
+ throw GCN_EXCEPTION("Unknown mouse event type.");
+ }
}
-
+
if (toSourceOnly)
- {
break;
- }
-
}
Widget* swap = widget;
@@ -821,24 +789,26 @@ namespace gcn
if (widget->isEnabled())
{
- std::list<KeyListener*> keyListeners = widget->_getKeyListeners();
-
+ std::list<KeyListener*> keyListeners
+ = widget->_getKeyListeners();
+
// Send the event to all key listeners of the source widget.
- for (std::list<KeyListener*>::iterator it = keyListeners.begin();
+ for (std::list<KeyListener*>::iterator
+ it = keyListeners.begin();
it != keyListeners.end();
++it)
{
switch (keyEvent.getType())
{
- case KeyEvent::PRESSED:
- (*it)->keyPressed(keyEvent);
- break;
- case KeyEvent::RELEASED:
- (*it)->keyReleased(keyEvent);
- break;
- default:
- throw GCN_EXCEPTION("Unknown key event type.");
- }
+ case KeyEvent::PRESSED:
+ (*it)->keyPressed(keyEvent);
+ break;
+ case KeyEvent::RELEASED:
+ (*it)->keyReleased(keyEvent);
+ break;
+ default:
+ throw GCN_EXCEPTION("Unknown key event type.");
+ }
}
}
@@ -860,24 +830,22 @@ namespace gcn
{
KeyListenerListIterator it;
- for (it = mKeyListeners.begin(); it != mKeyListeners.end(); it++)
+ for (it = mKeyListeners.begin(); it != mKeyListeners.end(); ++ it)
{
switch (keyEvent.getType())
{
- case KeyEvent::PRESSED:
- (*it)->keyPressed(keyEvent);
- break;
- case KeyEvent::RELEASED:
- (*it)->keyReleased(keyEvent);
- break;
- default:
- throw GCN_EXCEPTION("Unknown key event type.");
+ case KeyEvent::PRESSED:
+ (*it)->keyPressed(keyEvent);
+ break;
+ case KeyEvent::RELEASED:
+ (*it)->keyReleased(keyEvent);
+ break;
+ default:
+ throw GCN_EXCEPTION("Unknown key event type.");
}
if (keyEvent.isConsumed())
- {
break;
- }
}
}
@@ -885,36 +853,40 @@ namespace gcn
{
// Check if modal mouse input focus has been gained by a widget.
if ((mFocusHandler->getLastWidgetWithModalMouseInputFocus()
- != mFocusHandler->getModalMouseInputFocused())
- && (mFocusHandler->getLastWidgetWithModalMouseInputFocus() == NULL))
+ != mFocusHandler->getModalMouseInputFocused())
+ && (mFocusHandler->getLastWidgetWithModalMouseInputFocus()
+ == NULL))
{
handleModalFocusGained();
- mFocusHandler->setLastWidgetWithModalMouseInputFocus(mFocusHandler->getModalMouseInputFocused());
+ mFocusHandler->setLastWidgetWithModalMouseInputFocus(
+ mFocusHandler->getModalMouseInputFocused());
}
// Check if modal mouse input focus has been released.
else if ((mFocusHandler->getLastWidgetWithModalMouseInputFocus()
- != mFocusHandler->getModalMouseInputFocused())
- && (mFocusHandler->getLastWidgetWithModalMouseInputFocus() != NULL))
+ != mFocusHandler->getModalMouseInputFocused())
+ && (mFocusHandler->getLastWidgetWithModalMouseInputFocus()
+ != NULL))
{
handleModalFocusReleased();
mFocusHandler->setLastWidgetWithModalMouseInputFocus(NULL);
}
}
- void Gui::handleModalFocus()
+ void Gui::handleModalFocus()
{
// Check if modal focus has been gained by a widget.
if ((mFocusHandler->getLastWidgetWithModalFocus()
- != mFocusHandler->getModalFocused())
- && (mFocusHandler->getLastWidgetWithModalFocus() == NULL))
+ != mFocusHandler->getModalFocused())
+ && (mFocusHandler->getLastWidgetWithModalFocus() == NULL))
{
handleModalFocusGained();
- mFocusHandler->setLastWidgetWithModalFocus(mFocusHandler->getModalFocused());
+ mFocusHandler->setLastWidgetWithModalFocus(
+ mFocusHandler->getModalFocused());
}
// Check if modal focus has been released.
else if ((mFocusHandler->getLastWidgetWithModalFocus()
- != mFocusHandler->getModalFocused())
- && (mFocusHandler->getLastWidgetWithModalFocus() != NULL))
+ != mFocusHandler->getModalFocused())
+ && (mFocusHandler->getLastWidgetWithModalFocus() != NULL))
{
handleModalFocusReleased();
mFocusHandler->setLastWidgetWithModalFocus(NULL);
@@ -942,7 +914,8 @@ namespace gcn
mWidgetWithMouseQueue.pop_front();
}
- mFocusHandler->setLastWidgetWithModalMouseInputFocus(mFocusHandler->getModalMouseInputFocused());
+ mFocusHandler->setLastWidgetWithModalMouseInputFocus(
+ mFocusHandler->getModalMouseInputFocused());
}
void Gui::handleModalFocusReleased()
@@ -963,7 +936,7 @@ namespace gcn
std::deque<Widget*>::iterator iter;
for (iter = mWidgetWithMouseQueue.begin();
iter != mWidgetWithMouseQueue.end();
- iter++)
+ ++ iter)
{
if (*iter == widget)
{
@@ -974,8 +947,7 @@ namespace gcn
// Widget is not present, send an entered event and add
// it to the "widget with mouse" queue.
- if (!widgetIsPresentInQueue
- && Widget::widgetExists(widget))
+ if (!widgetIsPresentInQueue && Widget::widgetExists(widget))
{
distributeMouseEvent(widget,
MouseEvent::ENTERED,
diff --git a/src/guichan/gui.hpp b/src/guichan/gui.hpp
index da5d71250..17d49c979 100644
--- a/src/guichan/gui.hpp
+++ b/src/guichan/gui.hpp
@@ -367,7 +367,8 @@ namespace gcn
*
* @since 0.6.0
*/
- virtual void distributeKeyEventToGlobalKeyListeners(KeyEvent& keyEvent);
+ virtual void distributeKeyEventToGlobalKeyListeners(KeyEvent&
+ keyEvent);
/**
* Gets the widget at a certain position.
diff --git a/src/guichan/image.cpp b/src/guichan/image.cpp
index fa3408a1b..8a9213f9e 100644
--- a/src/guichan/image.cpp
+++ b/src/guichan/image.cpp
@@ -73,11 +73,13 @@ namespace gcn
return mImageLoader;
}
- Image* Image::load(const std::string& filename, bool convertToDisplayFormat)
+ Image* Image::load(const std::string& filename,
+ bool convertToDisplayFormat)
{
if (mImageLoader == NULL)
{
- throw GCN_EXCEPTION("Trying to load an image but no image loader is set.");
+ throw GCN_EXCEPTION("Trying to load an image but "
+ "no image loader is set.");
}
return mImageLoader->load(filename, convertToDisplayFormat);
diff --git a/src/guichan/image.hpp b/src/guichan/image.hpp
index 373a64884..e3bd27f69 100644
--- a/src/guichan/image.hpp
+++ b/src/guichan/image.hpp
@@ -82,9 +82,9 @@ namespace gcn
virtual ~Image();
/**
- * Loads an image by using the class' image laoder. All image loaders implemented
- * in Guichan return a newly instantiated image which must be deleted in
- * order to avoid a memory leak.
+ * Loads an image by using the class' image loader. All image loaders
+ * implemented in Guichan return a newly instantiated image which must
+ * be deleted in order to avoid a memory leak.
*
* NOTE: The functions getPixel and putPixel are only guaranteed to work
* before an image has been converted to display format.
@@ -94,7 +94,8 @@ namespace gcn
* to display, false otherwise.
* @since 0.5.0
*/
- static Image* load(const std::string& filename, bool convertToDisplayFormat = true);
+ static Image* load(const std::string& filename,
+ bool convertToDisplayFormat = true);
/**
* Gets the image loader used for loading images.
diff --git a/src/guichan/imageloader.hpp b/src/guichan/imageloader.hpp
index f939f7244..7c0adb842 100644
--- a/src/guichan/imageloader.hpp
+++ b/src/guichan/imageloader.hpp
@@ -78,7 +78,8 @@ namespace gcn
/**
* Destructor.
*/
- virtual ~ImageLoader() { }
+ virtual ~ImageLoader()
+ { }
/**
* Loads an image.
@@ -91,7 +92,8 @@ namespace gcn
* @param convertToDisplayFormat True if the image should be converted
* to display, false otherwise.
*/
- virtual Image* load(const std::string& filename, bool convertToDisplayFormat = true) = 0;
+ virtual Image* load(const std::string& filename,
+ bool convertToDisplayFormat = true) = 0;
};
}
diff --git a/src/guichan/key.cpp b/src/guichan/key.cpp
index 70e965209..1609a6a3c 100644
--- a/src/guichan/key.cpp
+++ b/src/guichan/key.cpp
@@ -49,8 +49,8 @@
namespace gcn
{
- Key::Key(int value)
- :mValue(value)
+ Key::Key(int value) :
+ mValue(value)
{
}
@@ -69,8 +69,8 @@ namespace gcn
bool Key::isLetter() const
{
return (((mValue >= 65 && mValue <= 90)
- || (mValue >= 97 && mValue <= 122)
- || (mValue >= 192 && mValue <= 255))
+ || (mValue >= 97 && mValue <= 122)
+ || (mValue >= 192 && mValue <= 255))
&& (mValue != 215) && (mValue != 247));
}
@@ -78,14 +78,14 @@ namespace gcn
{
return mValue;
}
-
- bool Key::operator==(const Key& key) const
- {
- return mValue == key.mValue;
- }
- bool Key::operator!=(const Key& key) const
- {
- return (mValue != key.mValue);
- }
+ bool Key::operator==(const Key& key) const
+ {
+ return mValue == key.mValue;
+ }
+
+ bool Key::operator!=(const Key& key) const
+ {
+ return (mValue != key.mValue);
+ }
}
diff --git a/src/guichan/keyinput.hpp b/src/guichan/keyinput.hpp
index d3f85d27b..68c58fa0d 100644
--- a/src/guichan/keyinput.hpp
+++ b/src/guichan/keyinput.hpp
@@ -63,7 +63,14 @@ namespace gcn
/**
* Constructor.
*/
- KeyInput() { };
+ KeyInput() :
+ mType(0),
+ mShiftPressed(false),
+ mControlPressed(false),
+ mAltPressed(false),
+ mMetaPressed(false),
+ mNumericPad(false)
+ { };
/**
* Constructor.
diff --git a/src/guichan/mouseinput.hpp b/src/guichan/mouseinput.hpp
index e441d0160..3825d5439 100644
--- a/src/guichan/mouseinput.hpp
+++ b/src/guichan/mouseinput.hpp
@@ -65,7 +65,13 @@ namespace gcn
/**
* Constructor.
*/
- MouseInput() { };
+ MouseInput() :
+ mType(0),
+ mButton(0),
+ mTimeStamp(0),
+ mX(0),
+ mY(0)
+ { };
/**
* Constructor.
diff --git a/src/guichan/sdl/sdlgraphics.cpp b/src/guichan/sdl/sdlgraphics.cpp
index c64018755..d80c1dd87 100644
--- a/src/guichan/sdl/sdlgraphics.cpp
+++ b/src/guichan/sdl/sdlgraphics.cpp
@@ -62,9 +62,10 @@
namespace gcn
{
- SDLGraphics::SDLGraphics()
+ SDLGraphics::SDLGraphics() :
+ mTarget(0),
+ mAlpha(false)
{
- mAlpha = false;
}
void SDLGraphics::_beginDraw()
@@ -108,9 +109,7 @@ namespace gcn
Graphics::popClipArea();
if (mClipStack.empty())
- {
return;
- }
const ClipRectangle& carea = mClipStack.top();
SDL_Rect rect;
@@ -137,7 +136,8 @@ namespace gcn
{
if (mClipStack.empty())
{
- throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?");
+ throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a "
+ "draw funtion outside of _beginDraw() and _endDraw()?");
}
const ClipRectangle& top = mClipStack.top();
@@ -155,7 +155,8 @@ namespace gcn
if (srcImage == NULL)
{
- throw GCN_EXCEPTION("Trying to draw an image of unknown format, must be an SDLImage.");
+ throw GCN_EXCEPTION("Trying to draw an image of unknown format,"
+ " must be an SDLImage.");
}
SDL_BlitSurface(srcImage->getSurface(), &src, mTarget, &dst);
@@ -165,38 +166,36 @@ namespace gcn
{
if (mClipStack.empty())
{
- throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?");
+ throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a "
+ "draw funtion outside of _beginDraw() and _endDraw()?");
}
const ClipRectangle& top = mClipStack.top();
-
+
Rectangle area = rectangle;
area.x += top.xOffset;
area.y += top.yOffset;
- if(!area.isIntersecting(top))
- {
+ if (!area.isIntersecting(top))
return;
- }
if (mAlpha)
{
int x1 = area.x > top.x ? area.x : top.x;
int y1 = area.y > top.y ? area.y : top.y;
- int x2 = area.x + area.width < top.x + top.width ? area.x + area.width : top.x + top.width;
- int y2 = area.y + area.height < top.y + top.height ? area.y + area.height : top.y + top.height;
+ int x2 = area.x + area.width < top.x + top.width ?
+ area.x + area.width : top.x + top.width;
+ int y2 = area.y + area.height < top.y + top.height ?
+ area.y + area.height : top.y + top.height;
int x, y;
SDL_LockSurface(mTarget);
for (y = y1; y < y2; y++)
{
for (x = x1; x < x2; x++)
- {
SDLputPixelAlpha(mTarget, x, y, mColor);
- }
}
SDL_UnlockSurface(mTarget);
-
}
else
{
@@ -219,32 +218,30 @@ namespace gcn
{
if (mClipStack.empty())
{
- throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?");
+ throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a "
+ "draw funtion outside of _beginDraw() and _endDraw()?");
}
const ClipRectangle& top = mClipStack.top();
-
+
x += top.xOffset;
y += top.yOffset;
- if(!top.isPointInRect(x,y))
+ if (!top.isPointInRect(x, y))
return;
if (mAlpha)
- {
SDLputPixelAlpha(mTarget, x, y, mColor);
- }
else
- {
SDLputPixel(mTarget, x, y, mColor);
- }
}
void SDLGraphics::drawHLine(int x1, int y, int x2)
{
if (mClipStack.empty())
{
- throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?");
+ throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a "
+ "draw funtion outside of _beginDraw() and _endDraw()?");
}
const ClipRectangle& top = mClipStack.top();
@@ -254,9 +251,7 @@ namespace gcn
x2 += top.xOffset;
if (y < top.y || y >= top.y + top.height)
- {
return;
- }
if (x1 > x2)
{
@@ -268,9 +263,7 @@ namespace gcn
if (top.x > x1)
{
if (top.x > x2)
- {
return;
- }
x1 = top.x;
}
@@ -278,10 +271,8 @@ namespace gcn
if (top.x + top.width <= x2)
{
if (top.x + top.width <= x1)
- {
return;
- }
-
+
x2 = top.x + top.width -1;
}
@@ -298,25 +289,22 @@ namespace gcn
switch(bpp)
{
case 1:
- for (;x1 <= x2; ++x1)
- {
+ for (; x1 <= x2; ++x1)
*(p++) = pixel;
- }
break;
-
+
case 2:
{
Uint16* q = (Uint16*)p;
- for (;x1 <= x2; ++x1)
- {
+ for (; x1 <= x2; ++x1)
*(q++) = pixel;
- }
break;
}
+
case 3:
- if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
{
- for (;x1 <= x2; ++x1)
+ for (; x1 <= x2; ++x1)
{
p[0] = (pixel >> 16) & 0xff;
p[1] = (pixel >> 8) & 0xff;
@@ -326,7 +314,7 @@ namespace gcn
}
else
{
- for (;x1 <= x2; ++x1)
+ for (; x1 <= x2; ++x1)
{
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
@@ -336,14 +324,14 @@ namespace gcn
}
break;
- case 4:
- {
+ case 4:
+ {
Uint32* q = (Uint32*)p;
- for (;x1 <= x2; ++x1)
+ for (; x1 <= x2; ++x1)
{
if (mAlpha)
{
- *q = SDLAlpha32(pixel,*q,mColor.a);
+ *q = SDLAlpha32(pixel, *q, mColor.a);
q++;
}
else
@@ -355,7 +343,6 @@ namespace gcn
}
default:
break;
-
} // end switch
SDL_UnlockSurface(mTarget);
@@ -365,7 +352,8 @@ namespace gcn
{
if (mClipStack.empty())
{
- throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?");
+ throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a "
+ "draw funtion outside of _beginDraw() and _endDraw()?");
}
const ClipRectangle& top = mClipStack.top();
@@ -375,10 +363,8 @@ namespace gcn
y2 += top.yOffset;
if (x < top.x || x >= top.x + top.width)
- {
return;
- }
-
+
if (y1 > y2)
{
y1 ^= y2;
@@ -389,9 +375,7 @@ namespace gcn
if (top.y > y1)
{
if (top.y > y2)
- {
return;
- }
y1 = top.y;
}
@@ -399,9 +383,7 @@ namespace gcn
if (top.y + top.height <= y2)
{
if (top.y + top.height <= y1)
- {
return;
- }
y2 = top.y + top.height - 1;
}
@@ -412,68 +394,65 @@ namespace gcn
Uint8 *p = (Uint8 *)mTarget->pixels + y1 * mTarget->pitch + x * bpp;
- Uint32 pixel = SDL_MapRGB(mTarget->format, mColor.r, mColor.g, mColor.b);
+ Uint32 pixel = SDL_MapRGB(mTarget->format, mColor.r,
+ mColor.g, mColor.b);
switch(bpp)
{
- case 1:
- for (;y1 <= y2; ++y1)
- {
- *p = pixel;
- p += mTarget->pitch;
- }
- break;
-
- case 2:
- for (;y1 <= y2; ++y1)
- {
- *(Uint16*)p = pixel;
- p += mTarget->pitch;
- }
- break;
-
- case 3:
- if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
- {
- for (;y1 <= y2; ++y1)
- {
- p[0] = (pixel >> 16) & 0xff;
- p[1] = (pixel >> 8) & 0xff;
- p[2] = pixel & 0xff;
- p += mTarget->pitch;
- }
- }
- else
- {
- for (;y1 <= y2; ++y1)
- {
- p[0] = pixel & 0xff;
- p[1] = (pixel >> 8) & 0xff;
- p[2] = (pixel >> 16) & 0xff;
- p += mTarget->pitch;
- }
- }
- break;
-
- case 4:
- for (;y1 <= y2; ++y1)
- {
- if (mAlpha)
- {
- *(Uint32*)p = SDLAlpha32(pixel,*(Uint32*)p,mColor.a);
- }
- else
- {
- *(Uint32*)p = pixel;
- }
- p += mTarget->pitch;
- }
- break;
-
- default:
- break;
+ case 1:
+ for (; y1 <= y2; ++y1)
+ {
+ *p = pixel;
+ p += mTarget->pitch;
+ }
+ break;
+
+ case 2:
+ for (; y1 <= y2; ++y1)
+ {
+ *(Uint16*)p = pixel;
+ p += mTarget->pitch;
+ }
+ break;
+
+ case 3:
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ {
+ for (; y1 <= y2; ++y1)
+ {
+ p[0] = (pixel >> 16) & 0xff;
+ p[1] = (pixel >> 8) & 0xff;
+ p[2] = pixel & 0xff;
+ p += mTarget->pitch;
+ }
+ }
+ else
+ {
+ for (; y1 <= y2; ++y1)
+ {
+ p[0] = pixel & 0xff;
+ p[1] = (pixel >> 8) & 0xff;
+ p[2] = (pixel >> 16) & 0xff;
+ p += mTarget->pitch;
+ }
+ }
+ break;
+
+ case 4:
+ for (; y1 <= y2; ++y1)
+ {
+ if (mAlpha)
+ *(Uint32*)p = SDLAlpha32(pixel, *(Uint32*)p, mColor.a);
+ else
+ *(Uint32*)p = pixel;
+ p += mTarget->pitch;
+ }
+ break;
+
+ default:
+ break;
} // end switch
-
+
SDL_UnlockSurface(mTarget);
}
@@ -506,7 +485,8 @@ namespace gcn
if (mClipStack.empty())
{
- throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?");
+ throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a "
+ "draw funtion outside of _beginDraw() and _endDraw()?");
}
const ClipRectangle& top = mClipStack.top();
@@ -546,13 +526,9 @@ namespace gcn
if (top.isPointInRect(x, y))
{
if (mAlpha)
- {
SDLputPixelAlpha(mTarget, x, y, mColor);
- }
else
- {
SDLputPixel(mTarget, x, y, mColor);
- }
}
p += dy;
@@ -574,13 +550,9 @@ namespace gcn
if (top.isPointInRect(x, y))
{
if (mAlpha)
- {
SDLputPixelAlpha(mTarget, x, y, mColor);
- }
else
- {
SDLputPixel(mTarget, x, y, mColor);
- }
}
p += dy;
@@ -618,13 +590,9 @@ namespace gcn
if (top.isPointInRect(x, y))
{
if (mAlpha)
- {
SDLputPixelAlpha(mTarget, x, y, mColor);
- }
else
- {
SDLputPixel(mTarget, x, y, mColor);
- }
}
p += dx;
@@ -646,13 +614,9 @@ namespace gcn
if (top.isPointInRect(x, y))
{
if (mAlpha)
- {
SDLputPixelAlpha(mTarget, x, y, mColor);
- }
else
- {
SDLputPixel(mTarget, x, y, mColor);
- }
}
p += dx;
@@ -685,7 +649,8 @@ namespace gcn
{
if (mClipStack.empty())
{
- throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?");
+ throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a "
+ "draw funtion outside of _beginDraw() and _endDraw()?");
}
const ClipRectangle& top = mClipStack.top();
diff --git a/src/guichan/sdl/sdlimage.cpp b/src/guichan/sdl/sdlimage.cpp
index cab5effdb..12c5571cf 100644
--- a/src/guichan/sdl/sdlimage.cpp
+++ b/src/guichan/sdl/sdlimage.cpp
@@ -61,9 +61,7 @@ namespace gcn
SDLImage::~SDLImage()
{
if (mAutoFree)
- {
free();
- }
}
SDL_Surface* SDLImage::getSurface() const
@@ -75,7 +73,8 @@ namespace gcn
{
if (mSurface == NULL)
{
- throw GCN_EXCEPTION("Trying to get the width of a non loaded image.");
+ throw GCN_EXCEPTION("Trying to get the width of "
+ "a non loaded image.");
}
return mSurface->w;
@@ -85,7 +84,8 @@ namespace gcn
{
if (mSurface == NULL)
{
- throw GCN_EXCEPTION("Trying to get the height of a non loaded image.");
+ throw GCN_EXCEPTION("Trying to get the height of "
+ "a non loaded image.");
}
return mSurface->h;
@@ -95,7 +95,8 @@ namespace gcn
{
if (mSurface == NULL)
{
- throw GCN_EXCEPTION("Trying to get a pixel from a non loaded image.");
+ throw GCN_EXCEPTION("Trying to get a pixel from a "
+ "non loaded image.");
}
return SDLgetPixel(mSurface, x, y);
@@ -105,7 +106,8 @@ namespace gcn
{
if (mSurface == NULL)
{
- throw GCN_EXCEPTION("Trying to put a pixel in a non loaded image.");
+ throw GCN_EXCEPTION("Trying to put a pixel in a "
+ "non loaded image.");
}
SDLputPixel(mSurface, x, y, color);
@@ -115,7 +117,8 @@ namespace gcn
{
if (mSurface == NULL)
{
- throw GCN_EXCEPTION("Trying to convert a non loaded image to display format.");
+ throw GCN_EXCEPTION("Trying to convert a non loaded image "
+ "to display format.");
}
int i;
@@ -124,7 +127,8 @@ namespace gcn
for (i = 0; i < mSurface->w * mSurface->h; ++i)
{
- if (((unsigned int*)mSurface->pixels)[i] == SDL_MapRGB(mSurface->format,255,0,255))
+ if (((unsigned int*)mSurface->pixels)[i] == SDL_MapRGB(
+ mSurface->format, 255, 0, 255))
{
hasPink = true;
break;
@@ -161,14 +165,12 @@ namespace gcn
}
if (tmp == NULL)
- {
throw GCN_EXCEPTION("Unable to convert image to display format.");
- }
if (hasPink)
{
SDL_SetColorKey(tmp, SDL_SRCCOLORKEY,
- SDL_MapRGB(tmp->format,255,0,255));
+ SDL_MapRGB(tmp->format, 255, 0, 255));
}
if (hasAlpha)
{
diff --git a/src/guichan/sdl/sdlpixel.hpp b/src/guichan/sdl/sdlpixel.hpp
index a5d9ca5a1..675b10fcd 100644
--- a/src/guichan/sdl/sdlpixel.hpp
+++ b/src/guichan/sdl/sdlpixel.hpp
@@ -70,40 +70,36 @@ namespace gcn
switch(bpp)
{
- case 1:
- color = *p;
- break;
-
- case 2:
- color = *(Uint16 *)p;
- break;
-
- case 3:
- if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
- {
- color = p[0] << 16 | p[1] << 8 | p[2];
- }
- else
- {
- color = p[0] | p[1] << 8 | p[2] << 16;
- }
- break;
+ case 1:
+ color = *p;
+ break;
+
+ case 2:
+ color = *(Uint16 *)p;
+ break;
+
+ case 3:
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ color = p[0] << 16 | p[1] << 8 | p[2];
+ else
+ color = p[0] | p[1] << 8 | p[2] << 16;
+ break;
case 4:
- color = *(Uint32 *)p;
- break;
+ color = *(Uint32 *)p;
+ break;
default:
- color = *p;
- break;
+ color = *p;
+ break;
}
- unsigned char r,g,b,a;
+ unsigned char r, g, b, a;
SDL_GetRGBA(color, surface->format, &r, &g, &b, &a);
SDL_UnlockSurface(surface);
- return Color(r,g,b,a);
+ return Color(r, g, b, a);
}
/**
@@ -113,7 +109,8 @@ namespace gcn
* @param y the y coordinate on the surface.
* @param color the color the pixel should be in.
*/
- inline void SDLputPixel(SDL_Surface* surface, int x, int y, const Color& color)
+ inline void SDLputPixel(SDL_Surface* surface, int x, int y,
+ const Color& color)
{
int bpp = surface->format->BytesPerPixel;
@@ -125,35 +122,35 @@ namespace gcn
switch(bpp)
{
- case 1:
- *p = pixel;
- break;
-
- case 2:
- *(Uint16 *)p = pixel;
- break;
-
- case 3:
- if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
- {
- p[0] = (pixel >> 16) & 0xff;
- p[1] = (pixel >> 8) & 0xff;
- p[2] = pixel & 0xff;
- }
- else
- {
- p[0] = pixel & 0xff;
- p[1] = (pixel >> 8) & 0xff;
- p[2] = (pixel >> 16) & 0xff;
- }
- break;
-
- case 4:
- *(Uint32 *)p = pixel;
- break;
-
- default:
- break;
+ case 1:
+ *p = pixel;
+ break;
+
+ case 2:
+ *(Uint16 *)p = pixel;
+ break;
+
+ case 3:
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ {
+ p[0] = (pixel >> 16) & 0xff;
+ p[1] = (pixel >> 8) & 0xff;
+ p[2] = pixel & 0xff;
+ }
+ else
+ {
+ p[0] = pixel & 0xff;
+ p[1] = (pixel >> 8) & 0xff;
+ p[2] = (pixel >> 16) & 0xff;
+ }
+ break;
+
+ case 4:
+ *(Uint32 *)p = pixel;
+ break;
+
+ default:
+ break;
}
SDL_UnlockSurface(surface);
@@ -166,11 +163,14 @@ namespace gcn
* @param dst the destination color.
* @param a alpha.
*/
- inline unsigned int SDLAlpha32(unsigned int src, unsigned int dst, unsigned char a)
+ inline unsigned int SDLAlpha32(unsigned int src, unsigned int dst,
+ unsigned char a)
{
unsigned int b = ((src & 0xff) * a + (dst & 0xff) * (255 - a)) >> 8;
- unsigned int g = ((src & 0xff00) * a + (dst & 0xff00) * (255 - a)) >> 8;
- unsigned int r = ((src & 0xff0000) * a + (dst & 0xff0000) * (255 - a)) >> 8;
+ unsigned int g = ((src & 0xff00) * a + (dst & 0xff00)
+ * (255 - a)) >> 8;
+ unsigned int r = ((src & 0xff0000) * a + (dst & 0xff0000)
+ * (255 - a)) >> 8;
return (b & 0xff) | (g & 0xff00) | (r & 0xff0000);
}
@@ -182,13 +182,18 @@ namespace gcn
* @param dst the destination color.
* @param a alpha.
*/
- inline unsigned short SDLAlpha16(unsigned short src, unsigned short dst, unsigned char a, const SDL_PixelFormat *f)
+ inline unsigned short SDLAlpha16(unsigned short src, unsigned short dst,
+ unsigned char a, const SDL_PixelFormat *f)
{
- unsigned int b = ((src & f->Rmask) * a + (dst & f->Rmask) * (255 - a)) >> 8;
- unsigned int g = ((src & f->Gmask) * a + (dst & f->Gmask) * (255 - a)) >> 8;
- unsigned int r = ((src & f->Bmask) * a + (dst & f->Bmask) * (255 - a)) >> 8;
-
- return (unsigned short)((b & f->Rmask) | (g & f->Gmask) | (r & f->Bmask));
+ unsigned int b = ((src & f->Rmask) * a + (dst & f->Rmask)
+ * (255 - a)) >> 8;
+ unsigned int g = ((src & f->Gmask) * a + (dst & f->Gmask)
+ * (255 - a)) >> 8;
+ unsigned int r = ((src & f->Bmask) * a + (dst & f->Bmask)
+ * (255 - a)) >> 8;
+
+ return (unsigned short)((b & f->Rmask)
+ | (g & f->Gmask) | (r & f->Bmask));
}
/*
@@ -211,7 +216,8 @@ namespace gcn
* @param y the y coordinate on the surface.
* @param color the color the pixel should be in.
*/
- inline void SDLputPixelAlpha(SDL_Surface* surface, int x, int y, const Color& color)
+ inline void SDLputPixelAlpha(SDL_Surface* surface, int x, int y,
+ const Color& color)
{
int bpp = surface->format->BytesPerPixel;
@@ -223,42 +229,49 @@ namespace gcn
switch(bpp)
{
- case 1:
- *p = pixel;
- break;
-
- case 2:
- *(Uint16 *)p = SDLAlpha16(pixel, *(Uint32 *)p, color.a, surface->format);
- break;
-
- case 3:
- if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
- {
- unsigned int r = (p[0] * (255 - color.a) + color.r * color.a) >> 8;
- unsigned int g = (p[1] * (255 - color.a) + color.g * color.a) >> 8;
- unsigned int b = (p[2] * (255 - color.a) + color.b * color.a) >> 8;
-
- p[2] = b;
- p[1] = g;
- p[0] = r;
- }
- else
- {
- unsigned int r = (p[2] * (255 - color.a) + color.r * color.a) >> 8;
- unsigned int g = (p[1] * (255 - color.a) + color.g * color.a) >> 8;
- unsigned int b = (p[0] * (255 - color.a) + color.b * color.a) >> 8;
-
- p[0] = b;
- p[1] = g;
- p[2] = r;
- }
- break;
-
- case 4:
- *(Uint32 *)p = SDLAlpha32(pixel, *(Uint32 *)p, color.a);
- break;
- default:
- break;
+ case 1:
+ *p = pixel;
+ break;
+
+ case 2:
+ *(Uint16 *)p = SDLAlpha16(pixel, *(Uint32 *)p,
+ color.a, surface->format);
+ break;
+
+ case 3:
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ {
+ unsigned int r = (p[0] * (255 - color.a)
+ + color.r * color.a) >> 8;
+ unsigned int g = (p[1] * (255 - color.a)
+ + color.g * color.a) >> 8;
+ unsigned int b = (p[2] * (255 - color.a)
+ + color.b * color.a) >> 8;
+
+ p[2] = b;
+ p[1] = g;
+ p[0] = r;
+ }
+ else
+ {
+ unsigned int r = (p[2] * (255 - color.a)
+ + color.r * color.a) >> 8;
+ unsigned int g = (p[1] * (255 - color.a)
+ + color.g * color.a) >> 8;
+ unsigned int b = (p[0] * (255 - color.a)
+ + color.b * color.a) >> 8;
+
+ p[0] = b;
+ p[1] = g;
+ p[2] = r;
+ }
+ break;
+
+ case 4:
+ *(Uint32 *)p = SDLAlpha32(pixel, *(Uint32 *)p, color.a);
+ break;
+ default:
+ break;
}
SDL_UnlockSurface(surface);
diff --git a/src/guichan/widget.cpp b/src/guichan/widget.cpp
index f5ccabffe..20cf35f1e 100644
--- a/src/guichan/widget.cpp
+++ b/src/guichan/widget.cpp
@@ -68,21 +68,21 @@ namespace gcn
DefaultFont Widget::mDefaultFont;
std::list<Widget*> Widget::mWidgets;
- Widget::Widget()
- : mForegroundColor(0x000000),
- mBackgroundColor(0xffffff),
- mBaseColor(0x808090),
- mSelectionColor(0xc3d9ff),
- mFocusHandler(NULL),
- mInternalFocusHandler(NULL),
- mParent(NULL),
- mFrameSize(0),
- mFocusable(false),
- mVisible(true),
- mTabIn(true),
- mTabOut(true),
- mEnabled(true),
- mCurrentFont(NULL)
+ Widget::Widget() :
+ mForegroundColor(0x000000),
+ mBackgroundColor(0xffffff),
+ mBaseColor(0x808090),
+ mSelectionColor(0xc3d9ff),
+ mFocusHandler(NULL),
+ mInternalFocusHandler(NULL),
+ mParent(NULL),
+ mFrameSize(0),
+ mFocusable(false),
+ mVisible(true),
+ mTabIn(true),
+ mTabOut(true),
+ mEnabled(true),
+ mCurrentFont(NULL)
{
mWidgets.push_back(this);
}
@@ -91,7 +91,9 @@ namespace gcn
{
DeathListenerIterator iter;
- for (iter = mDeathListeners.begin(); iter != mDeathListeners.end(); ++iter)
+ for (iter = mDeathListeners.begin();
+ iter != mDeathListeners.end();
+ ++iter)
{
Event event(this);
(*iter)->death(event);
@@ -118,11 +120,11 @@ namespace gcn
for (i = 0; i < getFrameSize(); ++i)
{
graphics->setColor(shadowColor);
- graphics->drawLine(i,i, width - i, i);
- graphics->drawLine(i,i + 1, i, height - i - 1);
+ graphics->drawLine(i, i, width - i, i);
+ graphics->drawLine(i, i + 1, i, height - i - 1);
graphics->setColor(highlightColor);
- graphics->drawLine(width - i,i + 1, width - i, height - i);
- graphics->drawLine(i,height - i, width - i - 1, height - i);
+ graphics->drawLine(width - i, i + 1, width - i, height - i);
+ graphics->drawLine(i, height - i, width - i - 1, height - i);
}
}
@@ -243,9 +245,7 @@ namespace gcn
bool Widget::isFocused() const
{
if (!mFocusHandler)
- {
return false;
- }
return (mFocusHandler->isFocused(this));
}
@@ -269,46 +269,35 @@ namespace gcn
{
if (mFocusHandler == NULL)
{
- throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?).");
+ throw GCN_EXCEPTION("No focushandler set (did you add "
+ "the widget to the gui?).");
}
if (isFocusable())
- {
mFocusHandler->requestFocus(this);
- }
}
void Widget::requestMoveToTop()
{
if (mParent)
- {
mParent->moveToTop(this);
- }
}
void Widget::requestMoveToBottom()
{
if (mParent)
- {
mParent->moveToBottom(this);
- }
}
void Widget::setVisible(bool visible)
{
if (!visible && isFocused())
- {
mFocusHandler->focusNone();
- }
-
+
if (visible)
- {
distributeShownEvent();
- }
- else if(!visible)
- {
+ else if (!visible)
distributeHiddenEvent();
- }
mVisible = visible;
}
@@ -316,13 +305,9 @@ namespace gcn
bool Widget::isVisible() const
{
if (getParent() == NULL)
- {
return mVisible;
- }
else
- {
return mVisible && getParent()->isVisible();
- }
}
void Widget::setBaseColor(const Color& color)
@@ -374,9 +359,7 @@ namespace gcn
}
if (focusHandler)
- {
focusHandler->add(this);
- }
mFocusHandler = focusHandler;
}
@@ -469,9 +452,7 @@ namespace gcn
if (mCurrentFont == NULL)
{
if (mGlobalFont == NULL)
- {
return &mDefaultFont;
- }
return mGlobalFont;
}
@@ -487,9 +468,7 @@ namespace gcn
for (iter = mWidgets.begin(); iter != mWidgets.end(); ++iter)
{
if ((*iter)->mCurrentFont == NULL)
- {
(*iter)->fontChanged();
- }
}
}
@@ -507,9 +486,7 @@ namespace gcn
for (iter = mWidgets.begin(); iter != mWidgets.end(); ++iter)
{
if (*iter == widget)
- {
return true;
- }
}
return result;
@@ -558,7 +535,8 @@ namespace gcn
{
if (mFocusHandler == NULL)
{
- throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?).");
+ throw GCN_EXCEPTION("No focushandler set (did you add "
+ "the widget to the gui?).");
}
mFocusHandler->requestModalFocus(this);
@@ -568,7 +546,8 @@ namespace gcn
{
if (mFocusHandler == NULL)
{
- throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?).");
+ throw GCN_EXCEPTION("No focushandler set (did you add "
+ "the widget to the gui?).");
}
mFocusHandler->requestModalMouseInputFocus(this);
@@ -577,9 +556,7 @@ namespace gcn
void Widget::releaseModalFocus()
{
if (mFocusHandler == NULL)
- {
return;
- }
mFocusHandler->releaseModalFocus(this);
}
@@ -587,9 +564,7 @@ namespace gcn
void Widget::releaseModalMouseInputFocus()
{
if (mFocusHandler == NULL)
- {
return;
- }
mFocusHandler->releaseModalMouseInputFocus(this);
}
@@ -598,7 +573,8 @@ namespace gcn
{
if (mFocusHandler == NULL)
{
- throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?).");
+ throw GCN_EXCEPTION("No focushandler set (did you add "
+ "the widget to the gui?).");
}
if (getParent() != NULL)
@@ -614,7 +590,8 @@ namespace gcn
{
if (mFocusHandler == NULL)
{
- throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?).");
+ throw GCN_EXCEPTION("No focushandler set (did you add "
+ "the widget to the gui?).");
}
if (getParent() != NULL)
@@ -675,7 +652,9 @@ namespace gcn
{
WidgetListenerIterator iter;
- for (iter = mWidgetListeners.begin(); iter != mWidgetListeners.end(); ++iter)
+ for (iter = mWidgetListeners.begin();
+ iter != mWidgetListeners.end();
+ ++ iter)
{
Event event(this);
(*iter)->widgetResized(event);
@@ -686,7 +665,9 @@ namespace gcn
{
WidgetListenerIterator iter;
- for (iter = mWidgetListeners.begin(); iter != mWidgetListeners.end(); ++iter)
+ for (iter = mWidgetListeners.begin();
+ iter != mWidgetListeners.end();
+ ++ iter)
{
Event event(this);
(*iter)->widgetMoved(event);
@@ -697,7 +678,9 @@ namespace gcn
{
WidgetListenerIterator iter;
- for (iter = mWidgetListeners.begin(); iter != mWidgetListeners.end(); ++iter)
+ for (iter = mWidgetListeners.begin();
+ iter != mWidgetListeners.end();
+ ++ iter)
{
Event event(this);
(*iter)->widgetHidden(event);
@@ -707,7 +690,9 @@ namespace gcn
void Widget::distributeActionEvent()
{
ActionListenerIterator iter;
- for (iter = mActionListeners.begin(); iter != mActionListeners.end(); ++iter)
+ for (iter = mActionListeners.begin();
+ iter != mActionListeners.end();
+ ++iter)
{
ActionEvent actionEvent(this, mActionEventId);
(*iter)->action(actionEvent);
@@ -718,7 +703,9 @@ namespace gcn
{
WidgetListenerIterator iter;
- for (iter = mWidgetListeners.begin(); iter != mWidgetListeners.end(); ++iter)
+ for (iter = mWidgetListeners.begin();
+ iter != mWidgetListeners.end();
+ ++iter)
{
Event event(this);
(*iter)->widgetShown(event);
@@ -728,8 +715,6 @@ namespace gcn
void Widget::showPart(Rectangle rectangle)
{
if (mParent != NULL)
- {
mParent->showWidgetPart(this, rectangle);
- }
}
}
diff --git a/src/guichan/widgets/button.cpp b/src/guichan/widgets/button.cpp
index 96e64406e..9f18cab40 100644
--- a/src/guichan/widgets/button.cpp
+++ b/src/guichan/widgets/button.cpp
@@ -143,7 +143,8 @@ namespace gcn
}
graphics->setColor(faceColor);
- graphics->fillRectangle(Rectangle(1, 1, getDimension().width-1, getHeight() - 1));
+ graphics->fillRectangle(Rectangle(1, 1,
+ getDimension().width - 1, getHeight() - 1));
graphics->setColor(highlightColor);
graphics->drawLine(0, 0, getWidth() - 1, 0);
@@ -151,7 +152,8 @@ namespace gcn
graphics->setColor(shadowColor);
graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1);
- graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1);
+ graphics->drawLine(1, getHeight() - 1,
+ getWidth() - 1, getHeight() - 1);
graphics->setColor(getForegroundColor());
@@ -177,7 +179,8 @@ namespace gcn
if (isPressed())
{
- graphics->drawText(getCaption(), textX + 1, textY + 1, getAlignment());
+ graphics->drawText(getCaption(), textX + 1, textY + 1,
+ getAlignment());
}
else
{
@@ -186,7 +189,7 @@ namespace gcn
if (isFocused())
{
graphics->drawRectangle(Rectangle(2, 2, getWidth() - 4,
- getHeight() - 4));
+ getHeight() - 4));
}
}
}
@@ -267,7 +270,7 @@ namespace gcn
Key key = keyEvent.getKey();
if ((key.getValue() == Key::ENTER
- || key.getValue() == Key::SPACE)
+ || key.getValue() == Key::SPACE)
&& mKeyPressed)
{
mKeyPressed = false;
diff --git a/src/guichan/widgets/dropdown.cpp b/src/guichan/widgets/dropdown.cpp
index 13feaa1f7..c666b47e4 100644
--- a/src/guichan/widgets/dropdown.cpp
+++ b/src/guichan/widgets/dropdown.cpp
@@ -70,22 +70,14 @@ namespace gcn
mInternalListBox = (listBox == NULL);
if (mInternalScrollArea)
- {
mScrollArea = new ScrollArea();
- }
else
- {
mScrollArea = scrollArea;
- }
if (mInternalListBox)
- {
mListBox = new ListBox();
- }
else
- {
mListBox = listBox;
- }
mScrollArea->setContent(mListBox);
add(mScrollArea);
@@ -96,9 +88,7 @@ namespace gcn
setListModel(listModel);
if (mListBox->getSelected() < 0)
- {
mListBox->setSelected(0);
- }
addMouseListener(this);
addKeyListener(this);
@@ -116,14 +106,10 @@ namespace gcn
}
if (mInternalScrollArea)
- {
delete mScrollArea;
- }
if (mInternalListBox)
- {
delete mListBox;
- }
setInternalFocusHandler(NULL);
}
@@ -133,13 +119,9 @@ namespace gcn
int h;
if (mDroppedDown)
- {
h = mFoldedUpHeight;
- }
else
- {
h = getHeight();
- }
Color faceColor = getBaseColor();
Color highlightColor, shadowColor;
@@ -163,15 +145,15 @@ namespace gcn
const Rectangle currentClipArea = graphics->getCurrentClipArea();
graphics->setColor(getBackgroundColor());
- graphics->fillRectangle(Rectangle(0, 0, currentClipArea.width, currentClipArea.height));
-
+ graphics->fillRectangle(Rectangle(0, 0,
+ currentClipArea.width, currentClipArea.height));
+
if (isFocused())
{
graphics->setColor(getSelectionColor());
- graphics->fillRectangle(Rectangle(0,
- 0,
- currentClipArea.width - currentClipArea.height,
- currentClipArea.height));
+ graphics->fillRectangle(Rectangle(0, 0,
+ currentClipArea.width - currentClipArea.height,
+ currentClipArea.height));
graphics->setColor(getForegroundColor());
}
@@ -181,14 +163,14 @@ namespace gcn
graphics->setColor(getForegroundColor());
graphics->setFont(getFont());
- graphics->drawText(mListBox->getListModel()->getElementAt(mListBox->getSelected()), 1, 0);
+ graphics->drawText(mListBox->getListModel()->getElementAt(
+ mListBox->getSelected()), 1, 0);
}
-
+
// Push a clip area before drawing the button.
- graphics->pushClipArea(Rectangle(currentClipArea.width - currentClipArea.height,
- 0,
- currentClipArea.height,
- currentClipArea.height));
+ graphics->pushClipArea(Rectangle(
+ currentClipArea.width - currentClipArea.height,
+ 0, currentClipArea.height, currentClipArea.height));
drawButton(graphics);
graphics->popClipArea();
graphics->popClipArea();
@@ -197,10 +179,8 @@ namespace gcn
{
// Draw a border around the children.
graphics->setColor(shadowColor);
- graphics->drawRectangle(Rectangle(0,
- mFoldedUpHeight,
- getWidth(),
- getHeight() - mFoldedUpHeight));
+ graphics->drawRectangle(Rectangle(0, mFoldedUpHeight,
+ getWidth(), getHeight() - mFoldedUpHeight));
drawChildren(graphics);
}
}
@@ -234,29 +214,17 @@ namespace gcn
const Rectangle currentClipArea = graphics->getCurrentClipArea();
graphics->setColor(highlightColor);
- graphics->drawLine(0,
- 0,
- currentClipArea.width - 1,
- 0);
- graphics->drawLine(0,
- 1,
- 0,
- currentClipArea.height - 1);
+ graphics->drawLine(0, 0, currentClipArea.width - 1, 0);
+ graphics->drawLine(0, 1, 0, currentClipArea.height - 1);
graphics->setColor(shadowColor);
- graphics->drawLine(currentClipArea.width - 1,
- 1,
- currentClipArea.width - 1,
- currentClipArea.height - 1);
- graphics->drawLine(1,
- currentClipArea.height - 1,
- currentClipArea.width - 2,
- currentClipArea.height - 1);
+ graphics->drawLine(currentClipArea.width - 1, 1,
+ currentClipArea.width - 1, currentClipArea.height - 1);
+ graphics->drawLine(1, currentClipArea.height - 1,
+ currentClipArea.width - 2, currentClipArea.height - 1);
graphics->setColor(faceColor);
- graphics->fillRectangle(Rectangle(1,
- 1,
- currentClipArea.width - 2,
- currentClipArea.height - 2));
+ graphics->fillRectangle(Rectangle(1, 1,
+ currentClipArea.width - 2, currentClipArea.height - 2));
graphics->setColor(getForegroundColor());
@@ -266,10 +234,8 @@ namespace gcn
int dy = (currentClipArea.height * 2) / 3;
for (i = 0; i < n; i++)
{
- graphics->drawLine(dx - i + offset,
- dy - i + offset,
- dx + i + offset,
- dy - i + offset);
+ graphics->drawLine(dx - i + offset, dy - i + offset,
+ dx + i + offset, dy - i + offset);
}
}
@@ -281,16 +247,14 @@ namespace gcn
void DropDown::setSelected(int selected)
{
if (selected >= 0)
- {
mListBox->setSelected(selected);
- }
}
void DropDown::keyPressed(KeyEvent& keyEvent)
{
if (keyEvent.isConsumed())
return;
-
+
Key key = keyEvent.getKey();
if ((key.getValue() == Key::ENTER || key.getValue() == Key::SPACE)
@@ -312,7 +276,7 @@ namespace gcn
}
void DropDown::mousePressed(MouseEvent& mouseEvent)
- {
+ {
// If we have a mouse press on the widget.
if (0 <= mouseEvent.getY()
&& mouseEvent.getY() < getHeight()
@@ -353,11 +317,10 @@ namespace gcn
void DropDown::mouseReleased(MouseEvent& mouseEvent)
{
if (mIsDragged)
- {
mPushed = false;
- }
- // Released outside of widget. Can happen when we have modal input focus.
+ // Released outside of widget. Can happen when we have modal
+ // input focus.
if ((0 > mouseEvent.getY()
|| mouseEvent.getY() >= getHeight()
|| mouseEvent.getX() < 0
@@ -368,9 +331,7 @@ namespace gcn
releaseModalMouseInputFocus();
if (mIsDragged)
- {
foldUp();
- }
}
else if (mouseEvent.getButton() == MouseEvent::LEFT)
{
@@ -392,9 +353,7 @@ namespace gcn
mListBox->setListModel(listModel);
if (mListBox->getSelected() < 0)
- {
mListBox->setSelected(0);
- }
adjustHeight();
}
@@ -407,17 +366,13 @@ namespace gcn
void DropDown::adjustHeight()
{
if (mScrollArea == NULL)
- {
throw GCN_EXCEPTION("Scroll area has been deleted.");
- }
if (mListBox == NULL)
- {
throw GCN_EXCEPTION("List box has been deleted.");
- }
int listBoxHeight = mListBox->getHeight();
-
+
// We add 2 for the border
int h2 = getFont()->getHeight() + 2;
@@ -457,9 +412,7 @@ namespace gcn
adjustHeight();
if (getParent())
- {
getParent()->moveToTop(this);
- }
}
mListBox->requestFocus();
@@ -483,11 +436,9 @@ namespace gcn
void DropDown::death(const Event& event)
- {
+ {
if (event.getSource() == mScrollArea)
- {
mScrollArea = NULL;
- }
BasicContainer::death(event);
}
@@ -504,10 +455,8 @@ namespace gcn
if (mDroppedDown)
{
// Calculate the children area (with the one pixel border in mind)
- return Rectangle(1,
- mFoldedUpHeight + 1,
- getWidth() - 2,
- getHeight() - mFoldedUpHeight - 2);
+ return Rectangle(1, mFoldedUpHeight + 1,
+ getWidth() - 2, getHeight() - mFoldedUpHeight - 2);
}
return Rectangle();
@@ -516,14 +465,10 @@ namespace gcn
void DropDown::setBaseColor(const Color& color)
{
if (mInternalScrollArea)
- {
mScrollArea->setBaseColor(color);
- }
if (mInternalListBox)
- {
mListBox->setBaseColor(color);
- }
Widget::setBaseColor(color);
}
@@ -531,14 +476,10 @@ namespace gcn
void DropDown::setBackgroundColor(const Color& color)
{
if (mInternalScrollArea)
- {
mScrollArea->setBackgroundColor(color);
- }
if (mInternalListBox)
- {
mListBox->setBackgroundColor(color);
- }
Widget::setBackgroundColor(color);
}
@@ -546,50 +487,40 @@ namespace gcn
void DropDown::setForegroundColor(const Color& color)
{
if (mInternalScrollArea)
- {
mScrollArea->setForegroundColor(color);
- }
if (mInternalListBox)
- {
mListBox->setForegroundColor(color);
- }
Widget::setForegroundColor(color);
}
- void DropDown::setFont(Font *font)
- {
- if (mInternalScrollArea)
- {
+ void DropDown::setFont(Font *font)
+ {
+ if (mInternalScrollArea)
mScrollArea->setFont(font);
- }
if (mInternalListBox)
- {
mListBox->setFont(font);
- }
Widget::setFont(font);
- }
+ }
- void DropDown::mouseWheelMovedUp(MouseEvent& mouseEvent)
- {
+ void DropDown::mouseWheelMovedUp(MouseEvent& mouseEvent)
+ {
if (isFocused() && mouseEvent.getSource() == this)
- {
+ {
mouseEvent.consume();
if (mListBox->getSelected() > 0)
- {
mListBox->setSelected(mListBox->getSelected() - 1);
- }
}
}
void DropDown::mouseWheelMovedDown(MouseEvent& mouseEvent)
{
if (isFocused() && mouseEvent.getSource() == this)
- {
+ {
mouseEvent.consume();
mListBox->setSelected(mListBox->getSelected() + 1);
@@ -601,9 +532,7 @@ namespace gcn
Widget::setSelectionColor(color);
if (mInternalListBox)
- {
mListBox->setSelectionColor(color);
- }
}
void DropDown::valueChanged(const SelectionEvent& event _UNUSED_)
@@ -615,17 +544,19 @@ namespace gcn
{
mSelectionListeners.push_back(selectionListener);
}
-
- void DropDown::removeSelectionListener(SelectionListener* selectionListener)
+
+ void DropDown::removeSelectionListener(SelectionListener* listener)
{
- mSelectionListeners.remove(selectionListener);
+ mSelectionListeners.remove(listener);
}
void DropDown::distributeValueChangedEvent()
{
SelectionListenerIterator iter;
- for (iter = mSelectionListeners.begin(); iter != mSelectionListeners.end(); ++iter)
+ for (iter = mSelectionListeners.begin();
+ iter != mSelectionListeners.end();
+ ++iter)
{
SelectionEvent event(this);
(*iter)->valueChanged(event);
diff --git a/src/guichan/widgets/dropdown.hpp b/src/guichan/widgets/dropdown.hpp
index 4a0993b1a..5853783e5 100644
--- a/src/guichan/widgets/dropdown.hpp
+++ b/src/guichan/widgets/dropdown.hpp
@@ -63,7 +63,8 @@
#define _UNUSED_
#endif
-namespace gcn {
+namespace gcn
+{
/**
* An implementation of a drop downable list from which an item can be
* selected. The drop down consists of an internal ScrollArea and an
@@ -154,10 +155,10 @@ namespace gcn {
* If you delete your selection listener, be sure to also remove it
* using removeSelectionListener().
*
- * @param selectionListener the selection listener to add.
+ * @param listener the selection listener to add.
* @since 0.8.0
*/
- void addSelectionListener(SelectionListener* selectionListener);
+ void addSelectionListener(SelectionListener* listener);
/**
* Removes a selection listener from the drop down.
diff --git a/src/guichan/widgets/imagebutton.cpp b/src/guichan/widgets/imagebutton.cpp
index f09bca30d..a340face3 100644
--- a/src/guichan/widgets/imagebutton.cpp
+++ b/src/guichan/widgets/imagebutton.cpp
@@ -52,17 +52,17 @@
namespace gcn
{
- ImageButton::ImageButton()
- : mImage(0),
- mInternalImage(false)
+ ImageButton::ImageButton() :
+ mImage(0),
+ mInternalImage(false)
{
setWidth(0);
setHeight(0);
}
- ImageButton::ImageButton(const std::string& filename)
- : mImage(0),
- mInternalImage(false)
+ ImageButton::ImageButton(const std::string& filename) :
+ mImage(0),
+ mInternalImage(false)
{
mImage = Image::load(filename);
mInternalImage = true;
@@ -70,9 +70,9 @@ namespace gcn
setHeight(mImage->getHeight() + mImage->getHeight() / 2);
}
- ImageButton::ImageButton(const Image* image)
- : mImage(image),
- mInternalImage(false)
+ ImageButton::ImageButton(const Image* image) :
+ mImage(image),
+ mInternalImage(false)
{
setWidth(mImage->getWidth() + mImage->getWidth() / 2);
setHeight(mImage->getHeight() + mImage->getHeight() / 2);
@@ -81,17 +81,13 @@ namespace gcn
ImageButton::~ImageButton()
{
if (mInternalImage)
- {
delete mImage;
- }
}
void ImageButton::setImage(const Image* image)
{
if (mInternalImage)
- {
delete mImage;
- }
mImage = image;
mInternalImage = false;
@@ -126,10 +122,8 @@ namespace gcn
}
graphics->setColor(faceColor);
- graphics->fillRectangle(Rectangle(1,
- 1,
- getDimension().width - 1,
- getHeight() - 1));
+ graphics->fillRectangle(Rectangle(1, 1,
+ getDimension().width - 1, getHeight() - 1));
graphics->setColor(highlightColor);
graphics->drawLine(0, 0, getWidth() - 1, 0);
@@ -137,29 +131,30 @@ namespace gcn
graphics->setColor(shadowColor);
graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1);
- graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1);
+ graphics->drawLine(1, getHeight() - 1,
+ getWidth() - 1, getHeight() - 1);
graphics->setColor(getForegroundColor());
- const int textX = (getWidth() - (mImage ? mImage->getWidth() : 0) ) / 2;
- const int textY = (getHeight() - (mImage ? mImage->getHeight() : 0) ) / 2;
+ const int textX = (getWidth() - (mImage
+ ? mImage->getWidth() : 0) ) / 2;
+ const int textY = (getHeight() - (mImage
+ ? mImage->getHeight() : 0) ) / 2;
if (isPressed())
{
- if(mImage)
+ if (mImage)
graphics->drawImage(mImage, textX + 1, textY + 1);
}
else
{
- if(mImage)
+ if (mImage)
graphics->drawImage(mImage, textX, textY);
if (isFocused())
{
- graphics->drawRectangle(Rectangle(2,
- 2,
- getWidth() - 4,
- getHeight() - 4));
+ graphics->drawRectangle(Rectangle(2, 2,
+ getWidth() - 4, getHeight() - 4));
}
}
}
diff --git a/src/guichan/widgets/listbox.cpp b/src/guichan/widgets/listbox.cpp
index 9b20b8538..b8778e596 100644
--- a/src/guichan/widgets/listbox.cpp
+++ b/src/guichan/widgets/listbox.cpp
@@ -57,10 +57,10 @@
namespace gcn
{
- ListBox::ListBox()
- : mSelected(-1),
- mListModel(NULL),
- mWrappingEnabled(false)
+ ListBox::ListBox() :
+ mSelected(-1),
+ mListModel(NULL),
+ mWrappingEnabled(false)
{
setWidth(100);
setFocusable(true);
@@ -69,9 +69,9 @@ namespace gcn
addKeyListener(this);
}
- ListBox::ListBox(ListModel *listModel)
- : mSelected(-1),
- mWrappingEnabled(false)
+ ListBox::ListBox(ListModel *listModel) :
+ mSelected(-1),
+ mWrappingEnabled(false)
{
setWidth(100);
setListModel(listModel);
@@ -87,67 +87,61 @@ namespace gcn
graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight()));
if (mListModel == NULL)
- {
return;
- }
graphics->setColor(getForegroundColor());
graphics->setFont(getFont());
-
+
// Check the current clip area so we don't draw unnecessary items
// that are not visible.
const ClipRectangle currentClipArea = graphics->getCurrentClipArea();
int rowHeight = getRowHeight();
-
- // Calculate the number of rows to draw by checking the clip area.
- // The addition of two makes covers a partial visible row at the top
- // and a partial visible row at the bottom.
- int numberOfRows = currentClipArea.height / rowHeight + 2;
+
+ // Calculate the number of rows to draw by checking the clip area.
+ // The addition of two makes covers a partial visible row at the top
+ // and a partial visible row at the bottom.
+ int numberOfRows = currentClipArea.height / rowHeight + 2;
if (numberOfRows > mListModel->getNumberOfElements())
- {
numberOfRows = mListModel->getNumberOfElements();
- }
- // Calculate which row to start drawing. If the list box
- // has a negative y coordinate value we should check if
- // we should drop rows in the begining of the list as
- // they might not be visible. A negative y value is very
- // common if the list box for instance resides in a scroll
- // area and the user has scrolled the list box downwards.
- int startRow;
- if (getY() < 0)
- {
- startRow = -1 * (getY() / rowHeight);
- }
- else
- {
- startRow = 0;
- }
-
- int i;
- // The y coordinate where we start to draw the text is
- // simply the y coordinate multiplied with the font height.
- int y = rowHeight * startRow;
+ // Calculate which row to start drawing. If the list box
+ // has a negative y coordinate value we should check if
+ // we should drop rows in the begining of the list as
+ // they might not be visible. A negative y value is very
+ // common if the list box for instance resides in a scroll
+ // area and the user has scrolled the list box downwards.
+ int startRow;
+ if (getY() < 0)
+ startRow = -1 * (getY() / rowHeight);
+ else
+ startRow = 0;
+
+ int i;
+ // The y coordinate where we start to draw the text is
+ // simply the y coordinate multiplied with the font height.
+ int y = rowHeight * startRow;
for (i = startRow; i < startRow + numberOfRows; ++i)
{
if (i == mSelected)
{
graphics->setColor(getSelectionColor());
- graphics->fillRectangle(Rectangle(0, y, getWidth(), rowHeight));
+ graphics->fillRectangle(Rectangle(0, y,
+ getWidth(), rowHeight));
graphics->setColor(getForegroundColor());
}
-
- // If the row height is greater than the font height we
- // draw the text with a center vertical alignment.
- if (rowHeight > getFont()->getHeight())
- {
- graphics->drawText(mListModel->getElementAt(i), 1, y + rowHeight / 2 - getFont()->getHeight() / 2);
- }
- else
- {
- graphics->drawText(mListModel->getElementAt(i), 1, y);
- }
+
+ // If the row height is greater than the font height we
+ // draw the text with a center vertical alignment.
+ if (rowHeight > getFont()->getHeight())
+ {
+ graphics->drawText(mListModel->getElementAt(i), 1,
+ y + rowHeight / 2 - getFont()->getHeight() / 2);
+ }
+ else
+ {
+ graphics->drawText(mListModel->getElementAt(i), 1, y);
+ }
y += rowHeight;
}
@@ -172,29 +166,19 @@ namespace gcn
else
{
if (selected < 0)
- {
mSelected = -1;
- }
else if (selected >= mListModel->getNumberOfElements())
- {
mSelected = mListModel->getNumberOfElements() - 1;
- }
else
- {
mSelected = selected;
- }
}
-
+
Rectangle scroll;
if (mSelected < 0)
- {
scroll.y = 0;
- }
else
- {
scroll.y = getRowHeight() * mSelected;
- }
scroll.height = getRowHeight();
showPart(scroll);
@@ -218,15 +202,11 @@ namespace gcn
if (mSelected == -1)
{
if (mWrappingEnabled)
- {
setSelected(getListModel()->getNumberOfElements() - 1);
- }
else
- {
setSelected(0);
- }
}
-
+
keyEvent.consume();
}
else if (key.getValue() == Key::DOWN)
@@ -240,7 +220,7 @@ namespace gcn
{
setSelected(getSelected() + 1);
}
-
+
keyEvent.consume();
}
else if (key.getValue() == Key::HOME)
@@ -269,9 +249,7 @@ namespace gcn
if (isFocused())
{
if (getSelected() > 0 )
- {
setSelected(getSelected() - 1);
- }
mouseEvent.consume();
}
@@ -307,9 +285,7 @@ namespace gcn
void ListBox::adjustSize()
{
if (mListModel != NULL)
- {
setHeight(getRowHeight() * mListModel->getNumberOfElements());
- }
}
bool ListBox::isWrappingEnabled() const
@@ -336,15 +312,17 @@ namespace gcn
{
SelectionListenerIterator iter;
- for (iter = mSelectionListeners.begin(); iter != mSelectionListeners.end(); ++iter)
+ for (iter = mSelectionListeners.begin();
+ iter != mSelectionListeners.end();
+ ++ iter)
{
SelectionEvent event(this);
(*iter)->valueChanged(event);
}
}
- unsigned int ListBox::getRowHeight() const
- {
- return getFont()->getHeight();
- }
+ unsigned int ListBox::getRowHeight() const
+ {
+ return getFont()->getHeight();
+ }
}
diff --git a/src/guichan/widgets/radiobutton.cpp b/src/guichan/widgets/radiobutton.cpp
index 31fdec94d..2b2ae7315 100644
--- a/src/guichan/widgets/radiobutton.cpp
+++ b/src/guichan/widgets/radiobutton.cpp
@@ -88,38 +88,32 @@ namespace gcn
void RadioButton::draw(Graphics* graphics)
{
- graphics->pushClipArea(Rectangle(1,
- 1,
- getWidth() - 1,
- getHeight() - 1));
+ graphics->pushClipArea(Rectangle(1, 1,
+ getWidth() - 1, getHeight() - 1));
+
drawBox(graphics);
graphics->popClipArea();
-
graphics->setFont(getFont());
graphics->setColor(getForegroundColor());
if (isFocused())
{
int fh;
-
- if (getHeight()%2 == 0)
- {
+
+ if (getHeight() % 2 == 0)
fh = getHeight() - 4;
- }
else
- {
fh = getHeight() - 3;
- }
int hh = (fh + 1) / 2;
-
+
graphics->drawLine(0, hh + 1, hh + 1, 0);
graphics->drawLine(hh + 2, 1, fh + 2, hh + 1);
graphics->drawLine(fh + 1, hh + 2, hh + 1, fh + 2);
- graphics->drawLine(hh + 1, fh + 2, 1, hh + 2);
+ graphics->drawLine(hh + 1, fh + 2, 1, hh + 2);
}
-
+
int h = getHeight() + getHeight() / 2;
graphics->drawText(getCaption(), h - 2, 0);
@@ -129,14 +123,10 @@ namespace gcn
{
int h;
- if (getHeight()%2 == 0)
- {
+ if (getHeight() % 2 == 0)
h = getHeight() - 4;
- }
else
- {
h = getHeight() - 3;
- }
int alpha = getBaseColor().a;
Color faceColor = getBaseColor();
@@ -152,20 +142,10 @@ namespace gcn
int hh = (h + 1) / 2;
for (i = 1; i <= hh; ++i)
- {
- graphics->drawLine(hh - i + 1,
- i,
- hh + i - 1,
- i);
- }
+ graphics->drawLine(hh - i + 1, i, hh + i - 1, i);
for (i = 1; i < hh; ++i)
- {
- graphics->drawLine(hh - i + 1,
- h - i,
- hh + i - 1,
- h - i);
- }
+ graphics->drawLine(hh - i + 1, h - i, hh + i - 1, h - i);
graphics->setColor(shadowColor);
graphics->drawLine(hh, 0, 0, hh);
@@ -181,14 +161,9 @@ namespace gcn
if (mSelected)
{
for (i = 0; i < hhh; ++i)
- {
graphics->drawLine(hh - i, 4 + i, hh + i, 4 + i);
- }
for (i = 0; i < hhh; ++i)
- {
graphics->drawLine(hh - i, h - 4 - i, hh + i, h - 4 - i);
- }
-
}
}
@@ -206,12 +181,10 @@ namespace gcn
for (iter = mGroupMap.lower_bound(mGroup);
iter != iterEnd;
- iter++)
+ ++ iter)
{
if (iter->second->isSelected())
- {
iter->second->setSelected(false);
- }
}
}
@@ -264,7 +237,7 @@ namespace gcn
for (iter = mGroupMap.lower_bound(mGroup);
iter != iterEnd;
- iter++)
+ ++ iter)
{
if (iter->second == this)
{
@@ -293,6 +266,6 @@ namespace gcn
int height = getFont()->getHeight();
setHeight(height);
- setWidth(getFont()->getWidth(getCaption()) + height + height/2);
+ setWidth(getFont()->getWidth(getCaption()) + height + height / 2);
}
}
diff --git a/src/guichan/widgets/scrollarea.cpp b/src/guichan/widgets/scrollarea.cpp
index 8e935fc47..2e853caa4 100644
--- a/src/guichan/widgets/scrollarea.cpp
+++ b/src/guichan/widgets/scrollarea.cpp
@@ -68,7 +68,7 @@ namespace gcn
mLeftButtonScrollAmount = 10;
mRightButtonScrollAmount = 10;
mIsVerticalMarkerDragged = false;
- mIsHorizontalMarkerDragged =false;
+ mIsHorizontalMarkerDragged = false;
mOpaque = true;
addMouseListener(this);
@@ -90,7 +90,7 @@ namespace gcn
mLeftButtonScrollAmount = 10;
mRightButtonScrollAmount = 10;
mIsVerticalMarkerDragged = false;
- mIsHorizontalMarkerDragged =false;
+ mIsHorizontalMarkerDragged = false;
mOpaque = true;
setContent(content);
@@ -115,7 +115,7 @@ namespace gcn
mLeftButtonScrollAmount = 10;
mRightButtonScrollAmount = 10;
mIsVerticalMarkerDragged = false;
- mIsHorizontalMarkerDragged =false;
+ mIsHorizontalMarkerDragged = false;
mOpaque = true;
setContent(content);
@@ -133,7 +133,7 @@ namespace gcn
{
clear();
add(widget);
- widget->setPosition(0,0);
+ widget->setPosition(0, 0);
}
else
{
@@ -175,7 +175,8 @@ namespace gcn
return mVPolicy;
}
- void ScrollArea::setScrollPolicy(ScrollPolicy hPolicy, ScrollPolicy vPolicy)
+ void ScrollArea::setScrollPolicy(ScrollPolicy hPolicy,
+ ScrollPolicy vPolicy)
{
mHPolicy = hPolicy;
mVPolicy = vPolicy;
@@ -189,14 +190,10 @@ namespace gcn
mVScroll = vScroll;
if (vScroll > max)
- {
mVScroll = max;
- }
if (vScroll < 0)
- {
mVScroll = 0;
- }
}
int ScrollArea::getVerticalScrollAmount() const
@@ -211,13 +208,9 @@ namespace gcn
mHScroll = hScroll;
if (hScroll > max)
- {
mHScroll = max;
- }
else if (hScroll < 0)
- {
mHScroll = 0;
- }
}
int ScrollArea::getHorizontalScrollAmount() const
@@ -236,17 +229,13 @@ namespace gcn
checkPolicies();
if (getContent() == NULL)
- {
return 0;
- }
int value = getContent()->getWidth() - getChildrenArea().width +
2 * getContent()->getFrameSize();
if (value < 0)
- {
return 0;
- }
return value;
}
@@ -256,9 +245,7 @@ namespace gcn
checkPolicies();
if (getContent() == NULL)
- {
return 0;
- }
int value;
@@ -266,9 +253,7 @@ namespace gcn
2 * getContent()->getFrameSize();
if (value < 0)
- {
return 0;
- }
return value;
}
@@ -276,13 +261,9 @@ namespace gcn
void ScrollArea::setScrollbarWidth(int width)
{
if (width > 0)
- {
mScrollbarWidth = width;
- }
else
- {
throw GCN_EXCEPTION("Width should be greater then 0.");
- }
}
int ScrollArea::getScrollbarWidth() const
@@ -326,17 +307,17 @@ namespace gcn
mVerticalMarkerDragOffset = y - getVerticalMarkerDimension().y;
}
- else if (getVerticalBarDimension().isPointInRect(x,y))
+ else if (getVerticalBarDimension().isPointInRect(x, y))
{
if (y < getVerticalMarkerDimension().y)
{
setVerticalScrollAmount(getVerticalScrollAmount()
- - (int)(getChildrenArea().height * 0.95));
+ - (int)(getChildrenArea().height * 0.95));
}
else
{
setVerticalScrollAmount(getVerticalScrollAmount()
- + (int)(getChildrenArea().height * 0.95));
+ + (int)(getChildrenArea().height * 0.95));
}
}
else if (getHorizontalMarkerDimension().isPointInRect(x, y))
@@ -346,17 +327,17 @@ namespace gcn
mHorizontalMarkerDragOffset = x - getHorizontalMarkerDimension().x;
}
- else if (getHorizontalBarDimension().isPointInRect(x,y))
+ else if (getHorizontalBarDimension().isPointInRect(x, y))
{
if (x < getHorizontalMarkerDimension().x)
{
setHorizontalScrollAmount(getHorizontalScrollAmount()
- - (int)(getChildrenArea().width * 0.95));
+ - (int)(getChildrenArea().width * 0.95));
}
else
{
setHorizontalScrollAmount(getHorizontalScrollAmount()
- + (int)(getChildrenArea().width * 0.95));
+ + (int)(getChildrenArea().width * 0.95));
}
}
}
@@ -377,7 +358,8 @@ namespace gcn
{
if (mIsVerticalMarkerDragged)
{
- int pos = mouseEvent.getY() - getVerticalBarDimension().y - mVerticalMarkerDragOffset;
+ int pos = mouseEvent.getY() - getVerticalBarDimension().y
+ - mVerticalMarkerDragOffset;
int length = getVerticalMarkerDimension().height;
Rectangle barDim = getVerticalBarDimension();
@@ -395,7 +377,8 @@ namespace gcn
if (mIsHorizontalMarkerDragged)
{
- int pos = mouseEvent.getX() - getHorizontalBarDimension().x - mHorizontalMarkerDragOffset;
+ int pos = mouseEvent.getX() - getHorizontalBarDimension().x
+ - mHorizontalMarkerDragOffset;
int length = getHorizontalMarkerDimension().width;
Rectangle barDim = getHorizontalBarDimension();
@@ -438,9 +421,8 @@ namespace gcn
{
graphics->setColor(getBaseColor());
graphics->fillRectangle(Rectangle(getWidth() - mScrollbarWidth,
- getHeight() - mScrollbarWidth,
- mScrollbarWidth,
- mScrollbarWidth));
+ getHeight() - mScrollbarWidth,
+ mScrollbarWidth, mScrollbarWidth));
}
drawChildren(graphics);
@@ -549,10 +531,8 @@ namespace gcn
int h = w / 2 + 2;
for (i = 0; i < w / 2; ++i)
{
- graphics->drawLine(w - i + offset,
- i + h + offset,
- w + i + offset,
- i + h + offset);
+ graphics->drawLine(w - i + offset, i + h + offset,
+ w + i + offset, i + h + offset);
}
graphics->popClipArea();
@@ -610,10 +590,8 @@ namespace gcn
int h = w + 1;
for (i = 0; i < w / 2; ++i)
{
- graphics->drawLine(w - i + offset,
- -i + h + offset,
- w + i + offset,
- -i + h + offset);
+ graphics->drawLine(w - i + offset, -i + h + offset,
+ w + i + offset, -i + h + offset);
}
graphics->popClipArea();
@@ -671,10 +649,8 @@ namespace gcn
int h = w - 2;
for (i = 0; i < w / 2; ++i)
{
- graphics->drawLine(i + h + offset,
- w - i + offset,
- i + h + offset,
- w + i + offset);
+ graphics->drawLine(i + h + offset, w - i + offset,
+ i + h + offset, w + i + offset);
}
graphics->popClipArea();
@@ -732,10 +708,8 @@ namespace gcn
int h = w + 1;
for (i = 0; i < w / 2; ++i)
{
- graphics->drawLine(-i + h + offset,
- w - i + offset,
- -i + h + offset,
- w + i + offset);
+ graphics->drawLine(-i + h + offset, w - i + offset,
+ -i + h + offset, w + i + offset);
}
graphics->popClipArea();
@@ -755,7 +729,8 @@ namespace gcn
shadowColor.a = alpha;
graphics->setColor(faceColor);
- graphics->fillRectangle(Rectangle(1, 1, dim.width - 1, dim.height - 1));
+ graphics->fillRectangle(Rectangle(1, 1,
+ dim.width - 1, dim.height - 1));
graphics->setColor(highlightColor);
graphics->drawLine(0, 0, dim.width - 1, 0);
@@ -782,7 +757,8 @@ namespace gcn
shadowColor.a = alpha;
graphics->setColor(faceColor);
- graphics->fillRectangle(Rectangle(1, 1, dim.width - 1, dim.height - 1));
+ graphics->fillRectangle(Rectangle(1, 1,
+ dim.width - 1, dim.height - 1));
graphics->setColor(highlightColor);
graphics->drawLine(0, 0, dim.width - 1, 0);
@@ -805,7 +781,7 @@ namespace gcn
if (getContent() != NULL)
{
getContent()->setPosition(-mHScroll + getContent()->getFrameSize(),
- -mVScroll + getContent()->getFrameSize());
+ -mVScroll + getContent()->getFrameSize());
getContent()->logic();
}
}
@@ -842,88 +818,83 @@ namespace gcn
}
if ((getContent()->getHeight() > h)
- || (mHBarVisible && getContent()->getHeight() > h - mScrollbarWidth))
+ || (mHBarVisible && getContent()->getHeight()
+ > h - mScrollbarWidth))
{
mVBarVisible = true;
}
if (mVBarVisible && getContent()->getWidth() > w - mScrollbarWidth)
- {
mHBarVisible = true;
- }
return;
}
switch (mHPolicy)
{
- case SHOW_NEVER:
- mHBarVisible = false;
- break;
-
- case SHOW_ALWAYS:
- mHBarVisible = true;
- break;
-
- case SHOW_AUTO:
- if (mVPolicy == SHOW_NEVER)
- {
- mHBarVisible = getContent()->getWidth() > w;
- }
- else // (mVPolicy == SHOW_ALWAYS)
- {
- mHBarVisible = getContent()->getWidth() > w - mScrollbarWidth;
- }
- break;
-
- default:
- throw GCN_EXCEPTION("Horizontal scroll policy invalid.");
+ case SHOW_NEVER:
+ mHBarVisible = false;
+ break;
+
+ case SHOW_ALWAYS:
+ mHBarVisible = true;
+ break;
+
+ case SHOW_AUTO:
+ if (mVPolicy == SHOW_NEVER)
+ {
+ mHBarVisible = (getContent()->getWidth() > w);
+ }
+ else // (mVPolicy == SHOW_ALWAYS)
+ {
+ mHBarVisible = (getContent()->getWidth()
+ > w - mScrollbarWidth);
+ }
+ break;
+
+ default:
+ throw GCN_EXCEPTION("Horizontal scroll policy invalid.");
}
switch (mVPolicy)
{
- case SHOW_NEVER:
- mVBarVisible = false;
- break;
-
- case SHOW_ALWAYS:
- mVBarVisible = true;
- break;
-
- case SHOW_AUTO:
- if (mHPolicy == SHOW_NEVER)
- {
- mVBarVisible = getContent()->getHeight() > h;
- }
- else // (mHPolicy == SHOW_ALWAYS)
- {
- mVBarVisible = getContent()->getHeight() > h - mScrollbarWidth;
- }
- break;
- default:
- throw GCN_EXCEPTION("Vertical scroll policy invalid.");
+ case SHOW_NEVER:
+ mVBarVisible = false;
+ break;
+
+ case SHOW_ALWAYS:
+ mVBarVisible = true;
+ break;
+
+ case SHOW_AUTO:
+ if (mHPolicy == SHOW_NEVER)
+ {
+ mVBarVisible = (getContent()->getHeight() > h);
+ }
+ else // (mHPolicy == SHOW_ALWAYS)
+ {
+ mVBarVisible = (getContent()->getHeight()
+ > h - mScrollbarWidth);
+ }
+ break;
+ default:
+ throw GCN_EXCEPTION("Vertical scroll policy invalid.");
}
}
Rectangle ScrollArea::getUpButtonDimension()
{
if (!mVBarVisible)
- {
return Rectangle(0, 0, 0, 0);
- }
- return Rectangle(getWidth() - mScrollbarWidth,
- 0,
- mScrollbarWidth,
- mScrollbarWidth);
+ return Rectangle(getWidth() - mScrollbarWidth, 0,
+ mScrollbarWidth, mScrollbarWidth);
}
Rectangle ScrollArea::getDownButtonDimension()
{
if (!mVBarVisible)
- {
return Rectangle(0, 0, 0, 0);
- }
if (mVBarVisible && mHBarVisible)
{
@@ -942,22 +913,16 @@ namespace gcn
Rectangle ScrollArea::getLeftButtonDimension()
{
if (!mHBarVisible)
- {
return Rectangle(0, 0, 0, 0);
- }
- return Rectangle(0,
- getHeight() - mScrollbarWidth,
- mScrollbarWidth,
- mScrollbarWidth);
+ return Rectangle(0, getHeight() - mScrollbarWidth,
+ mScrollbarWidth, mScrollbarWidth);
}
Rectangle ScrollArea::getRightButtonDimension()
{
if (!mHBarVisible)
- {
return Rectangle(0, 0, 0, 0);
- }
if (mVBarVisible && mHBarVisible)
{
@@ -975,11 +940,10 @@ namespace gcn
Rectangle ScrollArea::getChildrenArea()
{
- Rectangle area = Rectangle(0,
- 0,
- mVBarVisible ? getWidth() - mScrollbarWidth : getWidth(),
- mHBarVisible ? getHeight() - mScrollbarWidth : getHeight());
-
+ Rectangle area = Rectangle(0, 0,
+ mVBarVisible ? (getWidth() - mScrollbarWidth) : getWidth(),
+ mHBarVisible ? (getHeight() - mScrollbarWidth) : getHeight());
+
if (area.width < 0 || area.height < 0)
return Rectangle();
@@ -989,9 +953,7 @@ namespace gcn
Rectangle ScrollArea::getVerticalBarDimension()
{
if (!mVBarVisible)
- {
return Rectangle(0, 0, 0, 0);
- }
if (mHBarVisible)
{
@@ -1015,9 +977,7 @@ namespace gcn
Rectangle ScrollArea::getHorizontalBarDimension()
{
if (!mHBarVisible)
- {
return Rectangle(0, 0, 0, 0);
- }
if (mVBarVisible)
{
@@ -1041,9 +1001,7 @@ namespace gcn
Rectangle ScrollArea::getVerticalMarkerDimension()
{
if (!mVBarVisible)
- {
return Rectangle(0, 0, 0, 0);
- }
int length, pos;
Rectangle barDim = getVerticalBarDimension();
@@ -1059,14 +1017,10 @@ namespace gcn
}
if (length < mScrollbarWidth)
- {
length = mScrollbarWidth;
- }
if (length > barDim.height)
- {
length = barDim.height;
- }
if (getVerticalMaxScroll() != 0)
{
@@ -1084,9 +1038,7 @@ namespace gcn
Rectangle ScrollArea::getHorizontalMarkerDimension()
{
if (!mHBarVisible)
- {
return Rectangle(0, 0, 0, 0);
- }
int length, pos;
Rectangle barDim = getHorizontalBarDimension();
@@ -1127,22 +1079,20 @@ namespace gcn
void ScrollArea::showWidgetPart(Widget* widget, Rectangle area)
{
if (widget != getContent())
- {
throw GCN_EXCEPTION("Widget not content widget");
- }
BasicContainer::showWidgetPart(widget, area);
- setHorizontalScrollAmount(getContent()->getFrameSize() - getContent()->getX());
- setVerticalScrollAmount(getContent()->getFrameSize() - getContent()->getY());
+ setHorizontalScrollAmount(getContent()->getFrameSize()
+ - getContent()->getX());
+ setVerticalScrollAmount(getContent()->getFrameSize()
+ - getContent()->getY());
}
Widget *ScrollArea::getWidgetAt(int x, int y)
{
if (getChildrenArea().isPointInRect(x, y))
- {
return getContent();
- }
return NULL;
}
@@ -1150,11 +1100,10 @@ namespace gcn
void ScrollArea::mouseWheelMovedUp(MouseEvent& mouseEvent)
{
if (mouseEvent.isConsumed())
- {
return;
- }
- setVerticalScrollAmount(getVerticalScrollAmount() - getChildrenArea().height / 8);
+ setVerticalScrollAmount(getVerticalScrollAmount()
+ - getChildrenArea().height / 8);
mouseEvent.consume();
}
@@ -1162,11 +1111,10 @@ namespace gcn
void ScrollArea::mouseWheelMovedDown(MouseEvent& mouseEvent)
{
if (mouseEvent.isConsumed())
- {
return;
- }
- setVerticalScrollAmount(getVerticalScrollAmount() + getChildrenArea().height / 8);
+ setVerticalScrollAmount(getVerticalScrollAmount()
+ + getChildrenArea().height / 8);
mouseEvent.consume();
}
diff --git a/src/guichan/widgets/slider.cpp b/src/guichan/widgets/slider.cpp
index a32209124..3bc9d77aa 100644
--- a/src/guichan/widgets/slider.cpp
+++ b/src/guichan/widgets/slider.cpp
@@ -82,7 +82,7 @@ namespace gcn
setFrameSize(1);
setOrientation(HORIZONTAL);
setValue(scaleStart);
- setStepLength((scaleEnd - scaleStart)/ 10);
+ setStepLength((scaleEnd - scaleStart) / 10);
setMarkerLength(10);
addMouseListener(this);
@@ -122,7 +122,7 @@ namespace gcn
shadowColor.a = alpha;
graphics->setColor(shadowColor);
- graphics->fillRectangle(gcn::Rectangle(0,0,getWidth(),getHeight()));
+ graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
drawMarker(graphics);
}
@@ -142,35 +142,43 @@ namespace gcn
if (getOrientation() == HORIZONTAL)
{
int v = getMarkerPosition();
- graphics->fillRectangle(gcn::Rectangle(v + 1, 1, getMarkerLength() - 2, getHeight() - 2));
+ graphics->fillRectangle(gcn::Rectangle(v + 1, 1,
+ getMarkerLength() - 2, getHeight() - 2));
graphics->setColor(highlightColor);
- graphics->drawLine(v, 0, v + getMarkerLength() - 1,0);
+ graphics->drawLine(v, 0, v + getMarkerLength() - 1, 0);
graphics->drawLine(v, 0, v, getHeight() - 1);
graphics->setColor(shadowColor);
- graphics->drawLine(v + getMarkerLength() - 1, 1, v + getMarkerLength() - 1, getHeight() - 1);
- graphics->drawLine(v + 1, getHeight() - 1, v + getMarkerLength() - 1, getHeight() - 1);
+ graphics->drawLine(v + getMarkerLength() - 1, 1,
+ v + getMarkerLength() - 1, getHeight() - 1);
+ graphics->drawLine(v + 1, getHeight() - 1,
+ v + getMarkerLength() - 1, getHeight() - 1);
if (isFocused())
{
graphics->setColor(getForegroundColor());
- graphics->drawRectangle(Rectangle(v + 2, 2, getMarkerLength() - 4, getHeight() - 4));
+ graphics->drawRectangle(Rectangle(v + 2, 2,
+ getMarkerLength() - 4, getHeight() - 4));
}
}
else
{
int v = (getHeight() - getMarkerLength()) - getMarkerPosition();
- graphics->fillRectangle(gcn::Rectangle(1, v + 1, getWidth() - 2, getMarkerLength() - 2));
+ graphics->fillRectangle(gcn::Rectangle(1, v + 1, getWidth() - 2,
+ getMarkerLength() - 2));
graphics->setColor(highlightColor);
graphics->drawLine(0, v, 0, v + getMarkerLength() - 1);
graphics->drawLine(0, v, getWidth() - 1, v);
graphics->setColor(shadowColor);
- graphics->drawLine(1, v + getMarkerLength() - 1, getWidth() - 1, v + getMarkerLength() - 1);
- graphics->drawLine(getWidth() - 1, v + 1, getWidth() - 1, v + getMarkerLength() - 1);
+ graphics->drawLine(1, v + getMarkerLength() - 1, getWidth() - 1,
+ v + getMarkerLength() - 1);
+ graphics->drawLine(getWidth() - 1, v + 1, getWidth() - 1,
+ v + getMarkerLength() - 1);
if (isFocused())
{
graphics->setColor(getForegroundColor());
- graphics->drawRectangle(Rectangle(2, v + 2, getWidth() - 4, getMarkerLength() - 4));
+ graphics->drawRectangle(Rectangle(2, v + 2, getWidth() - 4,
+ getMarkerLength() - 4));
}
}
}
@@ -185,11 +193,13 @@ namespace gcn
{
if (getOrientation() == HORIZONTAL)
{
- setValue(markerPositionToValue(mouseEvent.getX() - getMarkerLength() / 2));
+ setValue(markerPositionToValue(
+ mouseEvent.getX() - getMarkerLength() / 2));
}
else
{
- setValue(markerPositionToValue(getHeight() - mouseEvent.getY() - getMarkerLength() / 2));
+ setValue(markerPositionToValue(getHeight()
+ - mouseEvent.getY() - getMarkerLength() / 2));
}
distributeActionEvent();
@@ -200,11 +210,13 @@ namespace gcn
{
if (getOrientation() == HORIZONTAL)
{
- setValue(markerPositionToValue(mouseEvent.getX() - getMarkerLength() / 2));
+ setValue(markerPositionToValue(mouseEvent.getX()
+ - getMarkerLength() / 2));
}
else
{
- setValue(markerPositionToValue(getHeight() - mouseEvent.getY() - getMarkerLength() / 2));
+ setValue(markerPositionToValue(getHeight()
+ - mouseEvent.getY() - getMarkerLength() / 2));
}
distributeActionEvent();
@@ -261,7 +273,7 @@ namespace gcn
setValue(getValue() - getStepLength());
distributeActionEvent();
keyEvent.consume();
- }
+ }
}
else
{
@@ -294,44 +306,31 @@ namespace gcn
{
int w;
if (getOrientation() == HORIZONTAL)
- {
w = getWidth();
- }
else
- {
w = getHeight();
- }
double pos = v / ((double)w - getMarkerLength());
return (1.0 - pos) * getScaleStart() + pos * getScaleEnd();
-
}
int Slider::valueToMarkerPosition(double value) const
{
int v;
if (getOrientation() == HORIZONTAL)
- {
v = getWidth();
- }
else
- {
v = getHeight();
- }
- int w = (int)((v - getMarkerLength())
- * (value - getScaleStart())
- / (getScaleEnd() - getScaleStart()));
+ int w = (int)((v - getMarkerLength())
+ * (value - getScaleStart())
+ / (getScaleEnd() - getScaleStart()));
if (w < 0)
- {
return 0;
- }
if (w > v - getMarkerLength())
- {
return v - getMarkerLength();
- }
return w;
}
diff --git a/src/guichan/widgets/tab.cpp b/src/guichan/widgets/tab.cpp
index f6283dfe6..760e77a18 100644
--- a/src/guichan/widgets/tab.cpp
+++ b/src/guichan/widgets/tab.cpp
@@ -55,9 +55,9 @@
namespace gcn
{
- Tab::Tab()
- :mHasMouse(false),
- mTabbedArea(NULL)
+ Tab::Tab() :
+ mHasMouse(false),
+ mTabbedArea(NULL)
{
mLabel = new Label();
mLabel->setPosition(4, 4);
@@ -77,9 +77,7 @@ namespace gcn
mLabel->getHeight() + 8);
if (mTabbedArea != NULL)
- {
mTabbedArea->adjustTabPositions();
- }
}
void Tab::setTabbedArea(TabbedArea* tabbedArea)
@@ -124,7 +122,8 @@ namespace gcn
graphics->drawLine(0, 0, getWidth() - 1, 0);
graphics->drawLine(0, 1, 0, getHeight() - 1);
graphics->setColor(shadowColor);
- graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1);
+ graphics->drawLine(getWidth() - 1, 1,
+ getWidth() - 1, getHeight() - 1);
borderColor = highlightColor;
baseColor = getBaseColor();
@@ -135,7 +134,8 @@ namespace gcn
graphics->setColor(shadowColor);
graphics->drawLine(0, 0, getWidth() - 1, 0);
graphics->drawLine(0, 1, 0, getHeight() - 1);
- graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1);
+ graphics->drawLine(getWidth() - 1, 1, getWidth() - 1,
+ getHeight() - 1);
baseColor = getBaseColor() - 0x151515;
baseColor.a = alpha;
@@ -143,14 +143,13 @@ namespace gcn
// Push a clip area so the other drawings don't need to worry
// about the border.
- graphics->pushClipArea(Rectangle(1, 1, getWidth() - 2, getHeight() - 1));
+ graphics->pushClipArea(Rectangle(1, 1,
+ getWidth() - 2, getHeight() - 1));
const Rectangle currentClipArea = graphics->getCurrentClipArea();
graphics->setColor(baseColor);
- graphics->fillRectangle(Rectangle(0,
- 0,
- currentClipArea.width,
- currentClipArea.height));
+ graphics->fillRectangle(Rectangle(0, 0,
+ currentClipArea.width, currentClipArea.height));
drawChildren(graphics);
@@ -159,10 +158,8 @@ namespace gcn
&& mTabbedArea->isTabSelected(this))
{
graphics->setColor(Color(0x000000));
- graphics->drawRectangle(Rectangle(2,
- 2,
- currentClipArea.width - 4,
- currentClipArea.height - 4));
+ graphics->drawRectangle(Rectangle(2, 2,
+ currentClipArea.width - 4, currentClipArea.height - 4));
}
graphics->popClipArea();
diff --git a/src/guichan/widgets/tabbedarea.cpp b/src/guichan/widgets/tabbedarea.cpp
index e07d14c4d..d430a76a3 100644
--- a/src/guichan/widgets/tabbedarea.cpp
+++ b/src/guichan/widgets/tabbedarea.cpp
@@ -59,9 +59,9 @@
namespace gcn
{
- TabbedArea::TabbedArea()
- :mSelectedTab(NULL),
- mOpaque(false)
+ TabbedArea::TabbedArea() :
+ mSelectedTab(NULL),
+ mOpaque(false)
{
setFocusable(true);
addKeyListener(this);
@@ -84,9 +84,7 @@ namespace gcn
delete mWidgetContainer;
for (unsigned int i = 0; i < mTabsToDelete.size(); i++)
- {
delete mTabsToDelete[i];
- }
}
void TabbedArea::addTab(const std::string& caption, Widget* widget)
@@ -107,9 +105,7 @@ namespace gcn
mTabs.push_back(std::pair<Tab*, Widget*>(tab, widget));
if (mSelectedTab == NULL)
- {
setSelectedTab(tab);
- }
adjustTabPositions();
adjustSize();
@@ -118,9 +114,7 @@ namespace gcn
void TabbedArea::removeTabWithIndex(unsigned int index)
{
if (index >= mTabs.size())
- {
throw GCN_EXCEPTION("No such tab index.");
- }
removeTab(mTabs[index].first);
}
@@ -150,7 +144,7 @@ namespace gcn
}
std::vector<std::pair<Tab*, Widget*> >::iterator iter;
- for (iter = mTabs.begin(); iter != mTabs.end(); iter++)
+ for (iter = mTabs.begin(); iter != mTabs.end(); ++ iter)
{
if (iter->first == tab)
{
@@ -161,7 +155,9 @@ namespace gcn
}
std::vector<Tab*>::iterator iter2;
- for (iter2 = mTabsToDelete.begin(); iter2 != mTabsToDelete.end(); iter2++)
+ for (iter2 = mTabsToDelete.begin();
+ iter2 != mTabsToDelete.end();
+ ++ iter2)
{
if (*iter2 == tab)
{
@@ -188,9 +184,7 @@ namespace gcn
bool TabbedArea::isTabSelected(unsigned int index) const
{
if (index >= mTabs.size())
- {
throw GCN_EXCEPTION("No such tab index.");
- }
return mSelectedTab == mTabs[index].first;
}
@@ -203,9 +197,7 @@ namespace gcn
void TabbedArea::setSelectedTab(unsigned int index)
{
if (index >= mTabs.size())
- {
throw GCN_EXCEPTION("No such tab index.");
- }
setSelectedTab(mTabs[index].first);
}
@@ -216,9 +208,7 @@ namespace gcn
for (i = 0; i < mTabs.size(); i++)
{
if (mTabs[i].first == mSelectedTab)
- {
mWidgetContainer->remove(mTabs[i].second);
- }
}
for (i = 0; i < mTabs.size(); i++)
@@ -237,9 +227,7 @@ namespace gcn
for (i = 0; i < mTabs.size(); i++)
{
if (mTabs[i].first == mSelectedTab)
- {
return i;
- }
}
return -1;
@@ -295,10 +283,8 @@ namespace gcn
// Draw a line underneath the tabs.
graphics->setColor(highlightColor);
- graphics->drawLine(1,
- mTabContainer->getHeight(),
- getWidth() - 1,
- mTabContainer->getHeight());
+ graphics->drawLine(1, mTabContainer->getHeight(),
+ getWidth() - 1, mTabContainer->getHeight());
// If a tab is selected, remove the line right underneath
// the selected tab.
@@ -306,9 +292,9 @@ namespace gcn
{
graphics->setColor(getBaseColor());
graphics->drawLine(mSelectedTab->getX() + 1,
- mTabContainer->getHeight(),
- mSelectedTab->getX() + mSelectedTab->getWidth() - 2,
- mTabContainer->getHeight());
+ mTabContainer->getHeight(),
+ mSelectedTab->getX() + mSelectedTab->getWidth() - 2,
+ mTabContainer->getHeight());
}
@@ -326,17 +312,14 @@ namespace gcn
for (unsigned int i = 0; i < mTabs.size(); i++)
{
if (mTabs[i].first->getHeight() > maxTabHeight)
- {
maxTabHeight = mTabs[i].first->getHeight();
- }
}
- mTabContainer->setSize(getWidth() - 2,
- maxTabHeight);
+ mTabContainer->setSize(getWidth() - 2, maxTabHeight);
mWidgetContainer->setPosition(1, maxTabHeight + 1);
mWidgetContainer->setSize(getWidth() - 2,
- getHeight() - maxTabHeight - 2);
+ getHeight() - maxTabHeight - 2);
}
void TabbedArea::adjustTabPositions()
@@ -346,9 +329,7 @@ namespace gcn
for (i = 0; i < mTabs.size(); i++)
{
if (mTabs[i].first->getHeight() > maxTabHeight)
- {
maxTabHeight = mTabs[i].first->getHeight();
- }
}
int x = 0;
@@ -387,9 +368,7 @@ namespace gcn
void TabbedArea::keyPressed(KeyEvent& keyEvent)
{
if (keyEvent.isConsumed() || !isFocused())
- {
return;
- }
if (keyEvent.getKey().getValue() == Key::LEFT)
{
@@ -397,13 +376,9 @@ namespace gcn
index--;
if (index < 0)
- {
return;
- }
else
- {
setSelectedTab(mTabs[index].first);
- }
keyEvent.consume();
}
@@ -413,13 +388,9 @@ namespace gcn
index++;
if (index >= (int)mTabs.size())
- {
return;
- }
else
- {
setSelectedTab(mTabs[index].first);
- }
keyEvent.consume();
}
@@ -429,28 +400,23 @@ namespace gcn
void TabbedArea::mousePressed(MouseEvent& mouseEvent)
{
if (mouseEvent.isConsumed())
- {
return;
- }
if (mouseEvent.getButton() == MouseEvent::LEFT)
{
- Widget* widget = mTabContainer->getWidgetAt(mouseEvent.getX(), mouseEvent.getY());
+ Widget* widget = mTabContainer->getWidgetAt(
+ mouseEvent.getX(), mouseEvent.getY());
Tab* tab = dynamic_cast<Tab*>(widget);
if (tab != NULL)
- {
setSelectedTab(tab);
- }
}
// Request focus only if the source of the event
// is not focusble. If the source of the event
// is focused we don't want to steal the focus.
if (!mouseEvent.getSource()->isFocusable())
- {
requestFocus();
- }
}
void TabbedArea::death(const Event& event)
@@ -458,13 +424,9 @@ namespace gcn
Tab* tab = dynamic_cast<Tab*>(event.getSource());
if (tab != NULL)
- {
removeTab(tab);
- }
else
- {
BasicContainer::death(event);
- }
}
void TabbedArea::action(const ActionEvent& actionEvent)
@@ -474,7 +436,8 @@ namespace gcn
if (tab == NULL)
{
- throw GCN_EXCEPTION("Received an action from a widget that's not a tab!");
+ throw GCN_EXCEPTION("Received an action from a "
+ "widget that's not a tab!");
}
setSelectedTab(tab);
diff --git a/src/guichan/widgets/textbox.cpp b/src/guichan/widgets/textbox.cpp
index c57296f9c..55858f7c5 100644
--- a/src/guichan/widgets/textbox.cpp
+++ b/src/guichan/widgets/textbox.cpp
@@ -101,13 +101,9 @@ namespace gcn
pos = text.find("\n", lastPos);
if (pos != std::string::npos)
- {
length = pos - lastPos;
- }
else
- {
length = text.size() - lastPos;
- }
std::string sub = text.substr(lastPos, length);
mTextRows.push_back(sub);
lastPos = pos + 1;
@@ -129,7 +125,9 @@ namespace gcn
if (isFocused() && isEditable())
{
- drawCaret(graphics, getFont()->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn)), mCaretRow * getFont()->getHeight());
+ drawCaret(graphics, getFont()->getWidth(
+ mTextRows[mCaretRow].substr(0, mCaretColumn)),
+ mCaretRow * getFont()->getHeight());
}
graphics->setColor(getForegroundColor());
@@ -155,11 +153,10 @@ namespace gcn
mCaretRow = mouseEvent.getY() / getFont()->getHeight();
if (mCaretRow >= (int)mTextRows.size())
- {
mCaretRow = mTextRows.size() - 1;
- }
- mCaretColumn = getFont()->getStringIndexAt(mTextRows[mCaretRow], mouseEvent.getX());
+ mCaretColumn = getFont()->getStringIndexAt(
+ mTextRows[mCaretRow], mouseEvent.getX());
}
}
@@ -190,7 +187,6 @@ namespace gcn
}
}
}
-
else if (key.getValue() == Key::RIGHT)
{
++mCaretColumn;
@@ -202,9 +198,7 @@ namespace gcn
{
mCaretRow = mTextRows.size() - 1;
if (mCaretRow < 0)
- {
mCaretRow = 0;
- }
mCaretColumn = mTextRows[mCaretRow].size();
}
@@ -214,36 +208,31 @@ namespace gcn
}
}
}
-
else if (key.getValue() == Key::DOWN)
{
setCaretRow(mCaretRow + 1);
}
-
else if (key.getValue() == Key::UP)
{
setCaretRow(mCaretRow - 1);
}
-
else if (key.getValue() == Key::HOME)
{
mCaretColumn = 0;
}
-
else if (key.getValue() == Key::END)
{
mCaretColumn = mTextRows[mCaretRow].size();
}
-
else if (key.getValue() == Key::ENTER && mEditable)
{
mTextRows.insert(mTextRows.begin() + mCaretRow + 1,
- mTextRows[mCaretRow].substr(mCaretColumn, mTextRows[mCaretRow].size() - mCaretColumn));
+ mTextRows[mCaretRow].substr(mCaretColumn,
+ mTextRows[mCaretRow].size() - mCaretColumn));
mTextRows[mCaretRow].resize(mCaretColumn);
++mCaretRow;
mCaretColumn = 0;
}
-
else if (key.getValue() == Key::BACKSPACE
&& mCaretColumn != 0
&& mEditable)
@@ -251,7 +240,6 @@ namespace gcn
mTextRows[mCaretRow].erase(mCaretColumn - 1, 1);
--mCaretColumn;
}
-
else if (key.getValue() == Key::BACKSPACE
&& mCaretColumn == 0
&& mCaretRow != 0
@@ -262,14 +250,12 @@ namespace gcn
mTextRows.erase(mTextRows.begin() + mCaretRow);
--mCaretRow;
}
-
else if (key.getValue() == Key::DELETE
&& mCaretColumn < (int)mTextRows[mCaretRow].size()
&& mEditable)
{
mTextRows[mCaretRow].erase(mCaretColumn, 1);
}
-
else if (key.getValue() == Key::DELETE
&& mCaretColumn == (int)mTextRows[mCaretRow].size()
&& mCaretRow < ((int)mTextRows.size() - 1)
@@ -278,51 +264,46 @@ namespace gcn
mTextRows[mCaretRow] += mTextRows[mCaretRow + 1];
mTextRows.erase(mTextRows.begin() + mCaretRow + 1);
}
-
- else if(key.getValue() == Key::PAGE_UP)
+ else if (key.getValue() == Key::PAGE_UP)
{
Widget* par = getParent();
if (par != NULL)
{
- int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight();
+ int rowsPerPage = par->getChildrenArea().height
+ / getFont()->getHeight();
mCaretRow -= rowsPerPage;
if (mCaretRow < 0)
- {
mCaretRow = 0;
- }
}
}
-
- else if(key.getValue() == Key::PAGE_DOWN)
+ else if (key.getValue() == Key::PAGE_DOWN)
{
Widget* par = getParent();
if (par != NULL)
{
- int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight();
+ int rowsPerPage = par->getChildrenArea().height
+ / getFont()->getHeight();
mCaretRow += rowsPerPage;
if (mCaretRow >= (int)mTextRows.size())
- {
mCaretRow = mTextRows.size() - 1;
- }
}
}
-
- else if(key.getValue() == Key::TAB
- && mEditable)
+ else if (key.getValue() == Key::TAB
+ && mEditable)
{
- mTextRows[mCaretRow].insert(mCaretColumn,std::string(" "));
+ mTextRows[mCaretRow].insert(mCaretColumn, std::string(" "));
mCaretColumn += 4;
}
-
else if (key.isCharacter()
&& mEditable)
{
- mTextRows[mCaretRow].insert(mCaretColumn,std::string(1,(char)key.getValue()));
- ++mCaretColumn;
+ mTextRows[mCaretRow].insert(mCaretColumn,
+ std::string(1, (char)key.getValue()));
+ ++ mCaretColumn;
}
adjustSize();
@@ -339,9 +320,7 @@ namespace gcn
{
int w = getFont()->getWidth(mTextRows[i]);
if (width < w)
- {
width = w;
- }
}
setWidth(width + 1);
@@ -376,9 +355,7 @@ namespace gcn
int pos = 0, row;
for (row = 0; row < mCaretRow; row++)
- {
pos += mTextRows[row].size();
- }
return pos + mCaretColumn;
}
@@ -394,14 +371,10 @@ namespace gcn
mCaretRow = row;
if (mCaretRow >= (int)mTextRows.size())
- {
mCaretRow = mTextRows.size() - 1;
- }
if (mCaretRow < 0)
- {
mCaretRow = 0;
- }
setCaretColumn(mCaretColumn);
}
@@ -416,14 +389,10 @@ namespace gcn
mCaretColumn = column;
if (mCaretColumn > (int)mTextRows[mCaretRow].size())
- {
mCaretColumn = mTextRows[mCaretRow].size();
- }
if (mCaretColumn < 0)
- {
mCaretColumn = 0;
- }
}
unsigned int TextBox::getCaretColumn() const
@@ -441,9 +410,7 @@ namespace gcn
mTextRows[row] = text;
if (mCaretRow == row)
- {
setCaretColumn(mCaretColumn);
- }
adjustSize();
}
@@ -455,18 +422,14 @@ namespace gcn
std::string TextBox::getText() const
{
- if (mTextRows.size() == 0)
- {
+ if (mTextRows.empty())
return std::string("");
- }
int i;
std::string text;
for (i = 0; i < (int)mTextRows.size() - 1; ++i)
- {
text = text + mTextRows[i] + "\n";
- }
text = text + mTextRows[i];
@@ -481,10 +444,13 @@ namespace gcn
void TextBox::scrollToCaret()
{
Rectangle scroll;
- scroll.x = getFont()->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn));
+ scroll.x = getFont()->getWidth(
+ mTextRows[mCaretRow].substr(0, mCaretColumn));
scroll.y = getFont()->getHeight() * mCaretRow;
scroll.width = getFont()->getWidth(" ");
- scroll.height = getFont()->getHeight() + 2; // add 2 for some extra space
+
+ // add 2 for some extra space
+ scroll.height = getFont()->getHeight() + 2;
showPart(scroll);
}
diff --git a/src/guichan/widgets/textfield.cpp b/src/guichan/widgets/textfield.cpp
index e8fc9c5d6..7f4325529 100644
--- a/src/guichan/widgets/textfield.cpp
+++ b/src/guichan/widgets/textfield.cpp
@@ -81,10 +81,8 @@ namespace gcn
void TextField::setText(const std::string& text)
{
- if(text.size() < mCaretPosition )
- {
+ if (text.size() < mCaretPosition)
mCaretPosition = text.size();
- }
mText = text;
}
@@ -105,11 +103,13 @@ namespace gcn
graphics->drawLine(0, 1, 0, getHeight() - 2);
graphics->setColor(highlightColor);
graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1);
- graphics->drawLine(0, getHeight() - 1, getWidth() - 1, getHeight() - 1);
+ graphics->drawLine(0, getHeight() - 1,
+ getWidth() - 1, getHeight() - 1);
// Push a clip area so the other drawings don't need to worry
// about the border.
- graphics->pushClipArea(Rectangle(1, 1, getWidth() - 2, getHeight() - 2));
+ graphics->pushClipArea(Rectangle(1, 1,
+ getWidth() - 2, getHeight() - 2));
graphics->setColor(getBackgroundColor());
graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight()));
@@ -117,13 +117,16 @@ namespace gcn
if (isFocused())
{
graphics->setColor(getSelectionColor());
- graphics->drawRectangle(Rectangle(0, 0, getWidth() - 2, getHeight() - 2));
- graphics->drawRectangle(Rectangle(1, 1, getWidth() - 4, getHeight() - 4));
+ graphics->drawRectangle(Rectangle(0, 0,
+ getWidth() - 2, getHeight() - 2));
+ graphics->drawRectangle(Rectangle(1, 1,
+ getWidth() - 4, getHeight() - 4));
}
if (isFocused())
{
- drawCaret(graphics, getFont()->getWidth(mText.substr(0, mCaretPosition)) - mXScroll);
+ drawCaret(graphics, getFont()->getWidth(
+ mText.substr(0, mCaretPosition)) - mXScroll);
}
graphics->setColor(getForegroundColor());
@@ -149,7 +152,8 @@ namespace gcn
{
if (mouseEvent.getButton() == MouseEvent::LEFT)
{
- mCaretPosition = getFont()->getStringIndexAt(mText, mouseEvent.getX() + mXScroll);
+ mCaretPosition = getFont()->getStringIndexAt(
+ mText, mouseEvent.getX() + mXScroll);
fixScroll();
}
}
@@ -167,50 +171,42 @@ namespace gcn
{
--mCaretPosition;
}
-
else if (key.getValue() == Key::RIGHT && mCaretPosition < mText.size())
{
++mCaretPosition;
}
-
- else if (key.getValue() == Key::DELETE && mCaretPosition < mText.size())
+ else if (key.getValue() == Key::DELETE
+ && mCaretPosition < mText.size())
{
mText.erase(mCaretPosition, 1);
}
-
else if (key.getValue() == Key::BACKSPACE && mCaretPosition > 0)
{
mText.erase(mCaretPosition - 1, 1);
--mCaretPosition;
}
-
else if (key.getValue() == Key::ENTER)
{
distributeActionEvent();
}
-
else if (key.getValue() == Key::HOME)
{
mCaretPosition = 0;
}
-
else if (key.getValue() == Key::END)
{
mCaretPosition = mText.size();
}
-
else if (key.isCharacter()
&& key.getValue() != Key::TAB)
{
- mText.insert(mCaretPosition, std::string(1,(char)key.getValue()));
+ mText.insert(mCaretPosition, std::string(1, (char)key.getValue()));
++mCaretPosition;
}
if (key.getValue() != Key::TAB)
- {
keyEvent.consume();
- }
-
+
fixScroll();
}
@@ -242,9 +238,7 @@ namespace gcn
mXScroll = caretX - getWidth() / 2;
if (mXScroll < 0)
- {
mXScroll = 0;
- }
}
}
}
@@ -252,13 +246,9 @@ namespace gcn
void TextField::setCaretPosition(unsigned int position)
{
if (position > mText.size())
- {
mCaretPosition = mText.size();
- }
else
- {
mCaretPosition = position;
- }
fixScroll();
}
diff --git a/src/guichan/widgets/window.cpp b/src/guichan/widgets/window.cpp
index d73d2339b..f3aca23d0 100644
--- a/src/guichan/widgets/window.cpp
+++ b/src/guichan/widgets/window.cpp
@@ -54,8 +54,8 @@
namespace gcn
{
- Window::Window()
- :mMoved(false)
+ Window::Window() :
+ mMoved(false)
{
setFrameSize(1);
setPadding(2);
@@ -66,8 +66,8 @@ namespace gcn
setOpaque(true);
}
- Window::Window(const std::string& caption)
- :mMoved(false)
+ Window::Window(const std::string& caption) :
+ mMoved(false)
{
setCaption(caption);
setFrameSize(1);
@@ -138,24 +138,19 @@ namespace gcn
// Fill the background around the content
graphics->setColor(faceColor);
// Fill top
- graphics->fillRectangle(Rectangle(0,0,getWidth(),d.y - 1));
+ graphics->fillRectangle(Rectangle(0, 0, getWidth(), d.y - 1));
// Fill left
- graphics->fillRectangle(Rectangle(0,d.y - 1, d.x - 1, getHeight() - d.y + 1));
+ graphics->fillRectangle(Rectangle(0, d.y - 1, d.x - 1,
+ getHeight() - d.y + 1));
// Fill right
- graphics->fillRectangle(Rectangle(d.x + d.width + 1,
- d.y - 1,
- getWidth() - d.x - d.width - 1,
- getHeight() - d.y + 1));
+ graphics->fillRectangle(Rectangle(d.x + d.width + 1, d.y - 1,
+ getWidth() - d.x - d.width - 1, getHeight() - d.y + 1));
// Fill bottom
- graphics->fillRectangle(Rectangle(d.x - 1,
- d.y + d.height + 1,
- d.width + 2,
- getHeight() - d.height - d.y - 1));
+ graphics->fillRectangle(Rectangle(d.x - 1, d.y + d.height + 1,
+ d.width + 2, getHeight() - d.height - d.y - 1));
if (isOpaque())
- {
graphics->fillRectangle(d);
- }
// Construct a rectangle one pixel bigger than the content
d.x -= 1;
@@ -198,22 +193,23 @@ namespace gcn
switch (getAlignment())
{
- case Graphics::LEFT:
- textX = 4;
- break;
- case Graphics::CENTER:
- textX = getWidth() / 2;
- break;
- case Graphics::RIGHT:
- textX = getWidth() - 4;
- break;
- default:
- throw GCN_EXCEPTION("Unknown alignment.");
+ case Graphics::LEFT:
+ textX = 4;
+ break;
+ case Graphics::CENTER:
+ textX = getWidth() / 2;
+ break;
+ case Graphics::RIGHT:
+ textX = getWidth() - 4;
+ break;
+ default:
+ throw GCN_EXCEPTION("Unknown alignment.");
}
graphics->setColor(getForegroundColor());
graphics->setFont(getFont());
- graphics->pushClipArea(Rectangle(0, 0, getWidth(), getTitleBarHeight() - 1));
+ graphics->pushClipArea(Rectangle(0, 0, getWidth(),
+ getTitleBarHeight() - 1));
graphics->drawText(getCaption(), textX, textY, getAlignment());
graphics->popClipArea();
}
@@ -221,14 +217,10 @@ namespace gcn
void Window::mousePressed(MouseEvent& mouseEvent)
{
if (mouseEvent.getSource() != this)
- {
return;
- }
if (getParent() != NULL)
- {
getParent()->moveToTop(this);
- }
mDragOffsetX = mouseEvent.getX();
mDragOffsetY = mouseEvent.getY();
@@ -244,9 +236,7 @@ namespace gcn
void Window::mouseDragged(MouseEvent& mouseEvent)
{
if (mouseEvent.isConsumed() || mouseEvent.getSource() != this)
- {
return;
- }
if (isMovable() && mMoved)
{
@@ -293,14 +283,10 @@ namespace gcn
for (it = mWidgets.begin(); it != mWidgets.end(); it++)
{
if ((*it)->getX() + (*it)->getWidth() > w)
- {
w = (*it)->getX() + (*it)->getWidth();
- }
if ((*it)->getY() + (*it)->getHeight() > h)
- {
h = (*it)->getY() + (*it)->getHeight();
- }
}
setSize(w + 2* getPadding(), h + getPadding() + getTitleBarHeight());