summaryrefslogtreecommitdiff
path: root/src/guichan
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-08-26 21:29:59 +0300
committerAndrei Karas <akaras@inbox.ru>2012-08-26 21:29:59 +0300
commita33a8dc48761d7cb2b4c1c468e1e3b188bcbf709 (patch)
tree1b1e98a615e2c03641c99b66cb4667b56f7087c3 /src/guichan
parent012a10fd8153f3ddb775dde1e4dba4456f2aa9de (diff)
downloadmv-a33a8dc48761d7cb2b4c1c468e1e3b188bcbf709.tar.gz
mv-a33a8dc48761d7cb2b4c1c468e1e3b188bcbf709.tar.bz2
mv-a33a8dc48761d7cb2b4c1c468e1e3b188bcbf709.tar.xz
mv-a33a8dc48761d7cb2b4c1c468e1e3b188bcbf709.zip
Add const to some classes.
Diffstat (limited to 'src/guichan')
-rw-r--r--src/guichan/actionevent.cpp2
-rw-r--r--src/guichan/basiccontainer.cpp10
-rw-r--r--src/guichan/focushandler.cpp20
-rw-r--r--src/guichan/font.cpp2
-rw-r--r--src/guichan/graphics.cpp2
-rw-r--r--src/guichan/gui.cpp24
-rw-r--r--src/guichan/include/guichan/actionevent.hpp2
-rw-r--r--src/guichan/include/guichan/font.hpp6
-rw-r--r--src/guichan/sdl/sdlgraphics.cpp22
-rw-r--r--src/guichan/widget.cpp15
-rw-r--r--src/guichan/widgets/checkbox.cpp2
-rw-r--r--src/guichan/widgets/dropdown.cpp6
-rw-r--r--src/guichan/widgets/label.cpp2
-rw-r--r--src/guichan/widgets/radiobutton.cpp2
-rw-r--r--src/guichan/widgets/scrollarea.cpp29
-rw-r--r--src/guichan/widgets/slider.cpp4
-rw-r--r--src/guichan/widgets/tabbedarea.cpp8
-rw-r--r--src/guichan/widgets/textbox.cpp2
-rw-r--r--src/guichan/widgets/textfield.cpp3
19 files changed, 82 insertions, 81 deletions
diff --git a/src/guichan/actionevent.cpp b/src/guichan/actionevent.cpp
index 7348587d7..a2e22abee 100644
--- a/src/guichan/actionevent.cpp
+++ b/src/guichan/actionevent.cpp
@@ -52,7 +52,7 @@
namespace gcn
{
- ActionEvent::ActionEvent(Widget* source, const std::string& id)
+ ActionEvent::ActionEvent(Widget *const source, const std::string &id)
:Event(source),
mId(id)
{
diff --git a/src/guichan/basiccontainer.cpp b/src/guichan/basiccontainer.cpp
index c74748622..232baedb9 100644
--- a/src/guichan/basiccontainer.cpp
+++ b/src/guichan/basiccontainer.cpp
@@ -171,7 +171,7 @@ namespace gcn
Widget *BasicContainer::getWidgetAt(int x, int y)
{
- Rectangle r = getChildrenArea();
+ const Rectangle r = getChildrenArea();
if (!r.isPointInRect(x, y))
return nullptr;
@@ -298,7 +298,7 @@ namespace gcn
void BasicContainer::showWidgetPart(Widget* widget, Rectangle area)
{
- Rectangle widgetArea = getChildrenArea();
+ const Rectangle widgetArea = getChildrenArea();
area.x += widget->getX();
area.y += widget->getY();
@@ -344,12 +344,12 @@ namespace gcn
if ((*iter)->getId() == id)
return (*iter);
- BasicContainer *basicContainer
- = dynamic_cast<BasicContainer*>(*iter);
+ BasicContainer *const basicContainer
+ = dynamic_cast<BasicContainer *const>(*iter);
if (basicContainer)
{
- Widget *widget = basicContainer->findWidgetById(id);
+ Widget *const widget = basicContainer->findWidgetById(id);
if (widget)
return widget;
diff --git a/src/guichan/focushandler.cpp b/src/guichan/focushandler.cpp
index 9be06c582..71f1831ed 100644
--- a/src/guichan/focushandler.cpp
+++ b/src/guichan/focushandler.cpp
@@ -87,7 +87,7 @@ namespace gcn
if (toBeFocusedIndex < 0)
throw GCN_EXCEPTION("Trying to focus a none existing widget.");
- Widget *oldFocused = mFocusedWidget;
+ Widget *const oldFocused = mFocusedWidget;
if (oldFocused != widget)
{
@@ -164,7 +164,7 @@ namespace gcn
if (mWidgets[i] == mFocusedWidget)
focusedWidget = i;
}
- int focused = focusedWidget;
+ const int focused = focusedWidget;
// i is a counter that ensures that the following loop
// won't get stuck in an infinite loop
@@ -220,7 +220,7 @@ namespace gcn
if (mWidgets[i] == mFocusedWidget)
focusedWidget = i;
}
- int focused = focusedWidget;
+ const int focused = focusedWidget;
// i is a counter that ensures that the following loop
// won't get stuck in an infinite loop
@@ -319,7 +319,7 @@ namespace gcn
{
if (mFocusedWidget)
{
- Widget* focused = mFocusedWidget;
+ Widget *const focused = mFocusedWidget;
mFocusedWidget = nullptr;
Event focusEvent(focused);
@@ -349,7 +349,7 @@ namespace gcn
if (mWidgets[i] == mFocusedWidget)
focusedWidget = i;
}
- int focused = focusedWidget;
+ const int focused = focusedWidget;
bool done = false;
// i is a counter that ensures that the following loop
@@ -373,7 +373,7 @@ namespace gcn
if (focusedWidget == focused)
return;
- const Widget *widget = mWidgets.at(focusedWidget);
+ const Widget *const widget = mWidgets.at(focusedWidget);
if (widget->isFocusable() && widget->isTabInEnabled() &&
(!mModalFocusedWidget || widget->isModalFocused()))
{
@@ -418,7 +418,7 @@ namespace gcn
if (mWidgets[i] == mFocusedWidget)
focusedWidget = i;
}
- int focused = focusedWidget;
+ const int focused = focusedWidget;
bool done = false;
// i is a counter that ensures that the following loop
@@ -442,7 +442,7 @@ namespace gcn
if (focusedWidget == focused)
return;
- const Widget *widget = mWidgets.at(focusedWidget);
+ const Widget *const widget = mWidgets.at(focusedWidget);
if (widget->isFocusable() && widget->isTabInEnabled() &&
(!mModalFocusedWidget || widget->isModalFocused()))
{
@@ -467,7 +467,7 @@ namespace gcn
void FocusHandler::distributeFocusLostEvent(const Event& focusEvent)
{
- Widget* sourceWidget = focusEvent.getSource();
+ Widget *const sourceWidget = focusEvent.getSource();
std::list<FocusListener*> focusListeners
= sourceWidget->_getFocusListeners();
@@ -484,7 +484,7 @@ namespace gcn
void FocusHandler::distributeFocusGainedEvent(const Event& focusEvent)
{
- Widget* sourceWidget = focusEvent.getSource();
+ Widget *const sourceWidget = focusEvent.getSource();
std::list<FocusListener*> focusListeners
= sourceWidget->_getFocusListeners();
diff --git a/src/guichan/font.cpp b/src/guichan/font.cpp
index bb8006b95..57d51bfff 100644
--- a/src/guichan/font.cpp
+++ b/src/guichan/font.cpp
@@ -54,7 +54,7 @@
namespace gcn
{
- int Font::getStringIndexAt(const std::string& text, int x) const
+ int Font::getStringIndexAt(const std::string& text, const int x) const
{
for (unsigned int i = 0, sz = static_cast<unsigned int>(text.size());
i < sz; ++i)
diff --git a/src/guichan/graphics.cpp b/src/guichan/graphics.cpp
index 1c99d899e..52e183591 100644
--- a/src/guichan/graphics.cpp
+++ b/src/guichan/graphics.cpp
@@ -118,7 +118,7 @@ namespace gcn
carea.height = 0;
}
- bool result = carea.isIntersecting(top);
+ const bool result = carea.isIntersecting(top);
mClipStack.push(carea);
diff --git a/src/guichan/gui.cpp b/src/guichan/gui.cpp
index 005b3505b..fda5cc1e7 100644
--- a/src/guichan/gui.cpp
+++ b/src/guichan/gui.cpp
@@ -162,8 +162,8 @@ namespace gcn
void Gui::handleMouseInput()
{
while (!mInput->isMouseQueueEmpty())
- {
- MouseInput mouseInput = mInput->dequeueMouseInput();
+ {
+ const MouseInput mouseInput = mInput->dequeueMouseInput();
// Save the current mouse state. It will be needed if modal focus
// changes or modal mouse input focus changes.
@@ -209,7 +209,7 @@ namespace gcn
// "widget with mouse" queue.
while (!mWidgetWithMouseQueue.empty())
{
- Widget* widget = mWidgetWithMouseQueue.front();
+ Widget *const widget = mWidgetWithMouseQueue.front();
if (Widget::widgetExists(widget))
{
@@ -239,7 +239,7 @@ namespace gcn
iter != mWidgetWithMouseQueue.end();
++ iter)
{
- Widget* widget = *iter;
+ Widget *const widget = *iter;
// If a widget in the "widget with mouse queue" doesn't
// exists anymore it should be removed from the queue.
@@ -343,7 +343,7 @@ namespace gcn
mWidgetWithMouseQueue.push_front(widget);
}
- Widget* swap = widget;
+ Widget *const swap = widget;
widget = parent;
parent = swap->getParent();
}
@@ -358,7 +358,7 @@ namespace gcn
}
else
{
- Widget* sourceWidget = getMouseEventSource(
+ Widget *const sourceWidget = getMouseEventSource(
mouseInput.getX(), mouseInput.getY());
distributeMouseEvent(sourceWidget,
@@ -499,7 +499,7 @@ namespace gcn
while (child)
{
- Widget* swap = child;
+ Widget *const swap = child;
int parentX, parentY;
parent->getAbsolutePosition(parentX, parentY);
child = parent->getWidgetAt(x - parentX, y - parentY);
@@ -511,7 +511,7 @@ namespace gcn
Widget* Gui::getMouseEventSource(int x, int y)
{
- Widget* widget = getWidgetAt(x, y);
+ Widget *const widget = getWidgetAt(x, y);
//+++ possible nullpointer
if (mFocusHandler->getModalMouseInputFocused()
@@ -637,7 +637,7 @@ namespace gcn
break;
}
- Widget* swap = widget;
+ Widget *const swap = widget;
widget = parent;
parent = swap->getParent();
@@ -710,7 +710,7 @@ namespace gcn
}
}
- Widget* swap = widget;
+ const Widget *const swap = widget;
widget = parent;
parent = swap->getParent();
@@ -793,7 +793,7 @@ namespace gcn
// Distribute an event to all widgets in the "widget with mouse" queue.
while (!mWidgetWithMouseQueue.empty())
{
- Widget* widget = mWidgetWithMouseQueue.front();
+ Widget *const widget = mWidgetWithMouseQueue.front();
if (Widget::widgetExists(widget))
{
@@ -855,7 +855,7 @@ namespace gcn
mWidgetWithMouseQueue.push_front(widget);
}
- Widget* swap = widget;
+ const Widget *const swap = widget;
widget = parent;
parent = swap->getParent();
}
diff --git a/src/guichan/include/guichan/actionevent.hpp b/src/guichan/include/guichan/actionevent.hpp
index a6c54f516..b8927931c 100644
--- a/src/guichan/include/guichan/actionevent.hpp
+++ b/src/guichan/include/guichan/actionevent.hpp
@@ -86,7 +86,7 @@ namespace gcn
* @param source The source widget of the event.
* @param id An identifier of the event.
*/
- ActionEvent(Widget* source, const std::string& id);
+ ActionEvent(Widget *const source, const std::string &id);
/**
* Destructor.
diff --git a/src/guichan/include/guichan/font.hpp b/src/guichan/include/guichan/font.hpp
index d39630352..cc177928e 100644
--- a/src/guichan/include/guichan/font.hpp
+++ b/src/guichan/include/guichan/font.hpp
@@ -64,7 +64,8 @@ namespace gcn
/**
* Destructor.
*/
- virtual ~Font(){ }
+ virtual ~Font()
+ { }
/**
* Gets the width of a string. The width of a string is not necesserily
@@ -91,7 +92,8 @@ namespace gcn
*
* @return A string index in a string providing an x coordinate.
*/
- virtual int getStringIndexAt(const std::string& text, int x) const;
+ virtual int getStringIndexAt(const std::string& text,
+ const int x) const;
/**
* Draws a string.
diff --git a/src/guichan/sdl/sdlgraphics.cpp b/src/guichan/sdl/sdlgraphics.cpp
index 0be0bfe59..c3afddb74 100644
--- a/src/guichan/sdl/sdlgraphics.cpp
+++ b/src/guichan/sdl/sdlgraphics.cpp
@@ -94,7 +94,7 @@ namespace gcn
bool SDLGraphics::pushClipArea(Rectangle area)
{
SDL_Rect rect;
- bool result = Graphics::pushClipArea(area);
+ const bool result = Graphics::pushClipArea(area);
const ClipRectangle& carea = mClipStack.top();
rect.x = static_cast<int16_t>(carea.x);
@@ -205,14 +205,14 @@ namespace gcn
x2 = top.x + top.width -1;
}
- int bpp = mTarget->format->BytesPerPixel;
+ const int bpp = mTarget->format->BytesPerPixel;
SDL_LockSurface(mTarget);
uint8_t *p = static_cast<uint8_t*>(mTarget->pixels)
+ y * mTarget->pitch + x1 * bpp;
- uint32_t pixel = SDL_MapRGB(mTarget->format,
+ const uint32_t pixel = SDL_MapRGB(mTarget->format,
static_cast<uint8_t>(mColor.r),
static_cast<uint8_t>(mColor.g),
static_cast<uint8_t>(mColor.b));
@@ -319,14 +319,14 @@ namespace gcn
y2 = top.y + top.height - 1;
}
- int bpp = mTarget->format->BytesPerPixel;
+ const int bpp = mTarget->format->BytesPerPixel;
SDL_LockSurface(mTarget);
uint8_t *p = static_cast<uint8_t*>(mTarget->pixels)
+ y1 * mTarget->pitch + x * bpp;
- uint32_t pixel = SDL_MapRGB(mTarget->format,
+ const uint32_t pixel = SDL_MapRGB(mTarget->format,
static_cast<uint8_t>(mColor.r),
static_cast<uint8_t>(mColor.g),
static_cast<uint8_t>(mColor.b));
@@ -399,10 +399,10 @@ namespace gcn
void SDLGraphics::drawRectangle(const Rectangle& rectangle)
{
- int x1 = rectangle.x;
- int x2 = rectangle.x + rectangle.width - 1;
- int y1 = rectangle.y;
- int y2 = rectangle.y + rectangle.height - 1;
+ const int x1 = rectangle.x;
+ const int x2 = rectangle.x + rectangle.width - 1;
+ const int y1 = rectangle.y;
+ const int y2 = rectangle.y + rectangle.height - 1;
drawHLine(x1, y1, x2);
drawHLine(x1, y2, x2);
@@ -439,8 +439,8 @@ namespace gcn
// Draw a line with Bresenham
- int dx = ABS(x2 - x1);
- int dy = ABS(y2 - y1);
+ const int dx = ABS(x2 - x1);
+ const int dy = ABS(y2 - y1);
if (dx > dy)
{
diff --git a/src/guichan/widget.cpp b/src/guichan/widget.cpp
index efeb80486..8b68b8510 100644
--- a/src/guichan/widget.cpp
+++ b/src/guichan/widget.cpp
@@ -110,14 +110,13 @@ namespace gcn
void Widget::drawFrame(Graphics* graphics)
{
- Color faceColor = getBaseColor();
- Color highlightColor, shadowColor;
- int alpha = getBaseColor().a;
- int width = getWidth() + getFrameSize() * 2 - 1;
- int height = getHeight() + getFrameSize() * 2 - 1;
- highlightColor = faceColor + 0x303030;
+ const Color faceColor = getBaseColor();
+ Color highlightColor = faceColor + 0x303030;
+ Color shadowColor = faceColor - 0x303030;
+ const int alpha = getBaseColor().a;
+ const int width = getWidth() + getFrameSize() * 2 - 1;
+ const int height = getHeight() + getFrameSize() * 2 - 1;
highlightColor.a = alpha;
- shadowColor = faceColor - 0x303030;
shadowColor.a = alpha;
for (unsigned int i = 0; i < getFrameSize(); ++i)
@@ -204,7 +203,7 @@ namespace gcn
void Widget::setDimension(const Rectangle& dimension)
{
- Rectangle oldDimension = mDimension;
+ const Rectangle oldDimension = mDimension;
mDimension = dimension;
if (mDimension.width != oldDimension.width
diff --git a/src/guichan/widgets/checkbox.cpp b/src/guichan/widgets/checkbox.cpp
index 413f8e6af..fe0bfbee4 100644
--- a/src/guichan/widgets/checkbox.cpp
+++ b/src/guichan/widgets/checkbox.cpp
@@ -118,7 +118,7 @@ namespace gcn
void CheckBox::adjustSize()
{
- int height = getFont()->getHeight();
+ const int height = getFont()->getHeight();
setHeight(height);
setWidth(getFont()->getWidth(mCaption) + height + height / 2);
diff --git a/src/guichan/widgets/dropdown.cpp b/src/guichan/widgets/dropdown.cpp
index 9f2180a72..0cd979adc 100644
--- a/src/guichan/widgets/dropdown.cpp
+++ b/src/guichan/widgets/dropdown.cpp
@@ -230,10 +230,10 @@ namespace gcn
if (!mListBox)
throw GCN_EXCEPTION("List box has been deleted.");
- int listBoxHeight = mListBox->getHeight();
+ const int listBoxHeight = mListBox->getHeight();
// We add 2 for the border
- int h2 = getFont()->getHeight() + 2;
+ const int h2 = getFont()->getHeight() + 2;
setHeight(h2);
@@ -242,7 +242,7 @@ namespace gcn
if (mDroppedDown && getParent())
{
- int h = getParent()->getChildrenArea().height - getY();
+ const int h = getParent()->getChildrenArea().height - getY();
if (listBoxHeight > h - h2 - 2)
{
diff --git a/src/guichan/widgets/label.cpp b/src/guichan/widgets/label.cpp
index 3e0eecb3c..815bba741 100644
--- a/src/guichan/widgets/label.cpp
+++ b/src/guichan/widgets/label.cpp
@@ -91,7 +91,7 @@ namespace gcn
void Label::draw(Graphics* graphics)
{
int textX;
- int textY = getHeight() / 2 - getFont()->getHeight() / 2;
+ const int textY = getHeight() / 2 - getFont()->getHeight() / 2;
switch (getAlignment())
{
diff --git a/src/guichan/widgets/radiobutton.cpp b/src/guichan/widgets/radiobutton.cpp
index 26bd7e44c..7f8d846d9 100644
--- a/src/guichan/widgets/radiobutton.cpp
+++ b/src/guichan/widgets/radiobutton.cpp
@@ -177,7 +177,7 @@ namespace gcn
void RadioButton::adjustSize()
{
- int height = getFont()->getHeight();
+ const int height = getFont()->getHeight();
setHeight(height);
setWidth(getFont()->getWidth(getCaption()) + height + height / 2);
diff --git a/src/guichan/widgets/scrollarea.cpp b/src/guichan/widgets/scrollarea.cpp
index 9668f9778..1251bc665 100644
--- a/src/guichan/widgets/scrollarea.cpp
+++ b/src/guichan/widgets/scrollarea.cpp
@@ -195,7 +195,7 @@ namespace gcn
void ScrollArea::setVerticalScrollAmount(int vScroll)
{
- int max = getVerticalMaxScroll();
+ const int max = getVerticalMaxScroll();
mVScroll = vScroll;
@@ -213,7 +213,7 @@ namespace gcn
void ScrollArea::setHorizontalScrollAmount(int hScroll)
{
- int max = getHorizontalMaxScroll();
+ const int max = getHorizontalMaxScroll();
mHScroll = hScroll;
@@ -241,7 +241,7 @@ namespace gcn
if (!getContent())
return 0;
- int value = getContent()->getWidth() - getChildrenArea().width +
+ const int value = getContent()->getWidth() - getChildrenArea().width +
2 * getContent()->getFrameSize();
if (value < 0)
@@ -283,8 +283,8 @@ namespace gcn
void ScrollArea::mousePressed(MouseEvent& mouseEvent)
{
- int x = mouseEvent.getX();
- int y = mouseEvent.getY();
+ const int x = mouseEvent.getX();
+ const int y = mouseEvent.getY();
if (getUpButtonDimension().isPointInRect(x, y))
{
@@ -368,11 +368,11 @@ namespace gcn
{
if (mIsVerticalMarkerDragged)
{
- Rectangle barDim = getVerticalBarDimension();
+ const Rectangle barDim = getVerticalBarDimension();
- int pos = mouseEvent.getY() - barDim.y
+ const int pos = mouseEvent.getY() - barDim.y
- mVerticalMarkerDragOffset;
- int length = getVerticalMarkerDimension().height;
+ const int length = getVerticalMarkerDimension().height;
if ((barDim.height - length) > 0)
{
@@ -387,11 +387,11 @@ namespace gcn
if (mIsHorizontalMarkerDragged)
{
- Rectangle barDim = getHorizontalBarDimension();
+ const Rectangle barDim = getHorizontalBarDimension();
- int pos = mouseEvent.getX() - barDim.x
+ const int pos = mouseEvent.getX() - barDim.x
- mHorizontalMarkerDragOffset;
- int length = getHorizontalMarkerDimension().width;
+ const int length = getHorizontalMarkerDimension().width;
if ((barDim.width - length) > 0)
{
@@ -464,13 +464,12 @@ namespace gcn
void ScrollArea::checkPolicies()
{
- int w = getWidth();
- int h = getHeight();
+ const int w = getWidth();
+ const int h = getHeight();
mHBarVisible = false;
mVBarVisible = false;
-
if (!getContent())
{
mHBarVisible = (mHPolicy == SHOW_ALWAYS);
@@ -616,7 +615,7 @@ namespace gcn
Rectangle ScrollArea::getChildrenArea()
{
- Rectangle area = Rectangle(0, 0,
+ const Rectangle area = Rectangle(0, 0,
mVBarVisible ? (getWidth() - mScrollbarWidth) : getWidth(),
mHBarVisible ? (getHeight() - mScrollbarWidth) : getHeight());
diff --git a/src/guichan/widgets/slider.cpp b/src/guichan/widgets/slider.cpp
index 189ee6e7b..ed14f525a 100644
--- a/src/guichan/widgets/slider.cpp
+++ b/src/guichan/widgets/slider.cpp
@@ -209,7 +209,7 @@ namespace gcn
else
w = getHeight();
- double pos = v / (static_cast<double>(w) - getMarkerLength());
+ const double pos = v / (static_cast<double>(w) - getMarkerLength());
return (1.0 - pos) * getScaleStart() + pos * getScaleEnd();
}
@@ -221,7 +221,7 @@ namespace gcn
else
v = getHeight();
- int w = static_cast<int>((v - getMarkerLength())
+ const int w = static_cast<int>((v - getMarkerLength())
* (value - getScaleStart())
/ (getScaleEnd() - getScaleStart()));
diff --git a/src/guichan/widgets/tabbedarea.cpp b/src/guichan/widgets/tabbedarea.cpp
index 6f4c4a2b9..7bd77e7cd 100644
--- a/src/guichan/widgets/tabbedarea.cpp
+++ b/src/guichan/widgets/tabbedarea.cpp
@@ -220,7 +220,7 @@ namespace gcn
int x = 0;
for (i = 0; i < sz; i++)
{
- Tab* tab = mTabs[i].first;
+ Tab *const tab = mTabs[i].first;
tab->setPosition(x, maxTabHeight - tab->getHeight());
x += tab->getWidth();
}
@@ -256,7 +256,7 @@ namespace gcn
void TabbedArea::death(const Event& event)
{
- Tab* tab = dynamic_cast<Tab*>(event.getSource());
+ Tab *const tab = dynamic_cast<Tab*>(event.getSource());
if (tab)
removeTab(tab);
@@ -266,8 +266,8 @@ namespace gcn
void TabbedArea::action(const ActionEvent& actionEvent)
{
- Widget* source = actionEvent.getSource();
- Tab* tab = dynamic_cast<Tab*>(source);
+ Widget *const source = actionEvent.getSource();
+ Tab *const tab = dynamic_cast<Tab*>(source);
if (!tab)
{
diff --git a/src/guichan/widgets/textbox.cpp b/src/guichan/widgets/textbox.cpp
index 97256eb44..0640b6a2c 100644
--- a/src/guichan/widgets/textbox.cpp
+++ b/src/guichan/widgets/textbox.cpp
@@ -172,7 +172,7 @@ namespace gcn
int width = 0;
for (size_t i = 0, sz = mTextRows.size(); i < sz; ++i)
{
- int w = getFont()->getWidth(mTextRows[i]);
+ const int w = getFont()->getWidth(mTextRows[i]);
if (width < w)
width = w;
}
diff --git a/src/guichan/widgets/textfield.cpp b/src/guichan/widgets/textfield.cpp
index b74d2333f..2fffdc5f5 100644
--- a/src/guichan/widgets/textfield.cpp
+++ b/src/guichan/widgets/textfield.cpp
@@ -132,7 +132,8 @@ namespace gcn
{
if (isFocused())
{
- int caretX = getFont()->getWidth(mText.substr(0, mCaretPosition));
+ const int caretX = getFont()->getWidth(
+ mText.substr(0, mCaretPosition));
if (caretX - mXScroll >= getWidth() - 4)
{