diff --git a/include/guisan/actionevent.hpp b/include/guisan/actionevent.hpp index c971bca..11aa15c 100644 --- a/include/guisan/actionevent.hpp +++ b/include/guisan/actionevent.hpp @@ -98,7 +98,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* source, std::string id); /** * Destructor. diff --git a/include/guisan/exception.hpp b/include/guisan/exception.hpp index 2365026..7dc9b5b 100644 --- a/include/guisan/exception.hpp +++ b/include/guisan/exception.hpp @@ -109,7 +109,7 @@ namespace gcn * * @param message The error message of the exception. */ - Exception(const std::string& message); + Exception(std::string message); /** * Constructor. @@ -124,9 +124,9 @@ namespace gcn * @param line The line number in the source code where the exception * occured. */ - Exception(const std::string& message, - const std::string& function, - const std::string& filename, + Exception(std::string message, + std::string function, + std::string filename, unsigned int line); /** diff --git a/include/guisan/imagefont.hpp b/include/guisan/imagefont.hpp index 0dadc3f..5991dc9 100644 --- a/include/guisan/imagefont.hpp +++ b/include/guisan/imagefont.hpp @@ -230,7 +230,7 @@ pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); @endcode * with the font. * @throws Exception when no glyph is found. */ - Rectangle scanForGlyph(unsigned char glyph, int x, int y, const Color& separator); + Rectangle scanForGlyph(unsigned char glyph, int x, int y, const Color& separator) const; /** * Holds the glyphs areas in the image. diff --git a/include/guisan/widgets/button.hpp b/include/guisan/widgets/button.hpp index 63307c0..cad9fe8 100644 --- a/include/guisan/widgets/button.hpp +++ b/include/guisan/widgets/button.hpp @@ -93,7 +93,7 @@ namespace gcn * * @param caption the caption of the Button. */ - Button(const std::string& caption); + Button(std::string caption); /** * Sets the Button caption. diff --git a/include/guisan/widgets/dropdown.hpp b/include/guisan/widgets/dropdown.hpp index 58e4574..4f905ad 100644 --- a/include/guisan/widgets/dropdown.hpp +++ b/include/guisan/widgets/dropdown.hpp @@ -129,7 +129,7 @@ namespace gcn * @param selected the selected item as an index from the list model. * @see getSelected */ - void setSelected(int selected); + void setSelected(int selected) const; /** * Sets the list model to use when displaying the list. diff --git a/src/exception.cpp b/src/exception.cpp index f63d0dd..8d9af3a 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -71,22 +71,21 @@ namespace gcn } - Exception::Exception(const std::string& message) + Exception::Exception(std::string message) : mFunction("?"), - mMessage(message), + mMessage(std::move(message)), mFilename("?"), mLine(0) { - } - Exception::Exception(const std::string& message, - const std::string& function, - const std::string& filename, + Exception::Exception(std::string message, + std::string function, + std::string filename, unsigned int line) - : mFunction(function), - mMessage(message), - mFilename(filename), + : mFunction(std::move(function)), + mMessage(std::move(message)), + mFilename(std::move(filename)), mLine(line) { diff --git a/src/focushandler.cpp b/src/focushandler.cpp index 506bf7c..6eaac93 100644 --- a/src/focushandler.cpp +++ b/src/focushandler.cpp @@ -221,13 +221,13 @@ namespace gcn { mFocusedWidget = mWidgets.at(focusedWidget); - Event focusEvent(mFocusedWidget); + const Event focusEvent(mFocusedWidget); distributeFocusGainedEvent(focusEvent); } if (focused >= 0) { - Event focusEvent(mWidgets.at(focused)); + const Event focusEvent(mWidgets.at(focused)); distributeFocusLostEvent(focusEvent); } } @@ -249,7 +249,7 @@ namespace gcn 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 @@ -281,13 +281,13 @@ namespace gcn if (focusedWidget >= 0) { mFocusedWidget = mWidgets.at(focusedWidget); - Event focusEvent(mFocusedWidget); + const Event focusEvent(mFocusedWidget); distributeFocusGainedEvent(focusEvent); } if (focused >= 0) { - Event focusEvent(mWidgets.at(focused)); + const Event focusEvent(mWidgets.at(focused)); distributeFocusLostEvent(focusEvent); } } @@ -388,7 +388,7 @@ namespace gcn focusedWidget = i; } } - int focused = focusedWidget; + const int focused = focusedWidget; bool done = false; // i is a counter that ensures that the following loop @@ -429,13 +429,13 @@ namespace gcn if (focusedWidget >= 0) { mFocusedWidget = mWidgets.at(focusedWidget); - Event focusEvent(mFocusedWidget); + const Event focusEvent(mFocusedWidget); distributeFocusGainedEvent(focusEvent); } if (focused >= 0) { - Event focusEvent(mWidgets.at(focused)); + const Event focusEvent(mWidgets.at(focused)); distributeFocusLostEvent(focusEvent); } } @@ -465,7 +465,7 @@ namespace gcn focusedWidget = i; } } - int focused = focusedWidget; + const int focused = focusedWidget; bool done = false; // i is a counter that ensures that the following loop @@ -506,13 +506,13 @@ namespace gcn if (focusedWidget >= 0) { mFocusedWidget = mWidgets.at(focusedWidget); - Event focusEvent(mFocusedWidget); + const Event focusEvent(mFocusedWidget); distributeFocusGainedEvent(focusEvent); } if (focused >= 0) { - Event focusEvent(mWidgets.at(focused)); + const Event focusEvent(mWidgets.at(focused)); distributeFocusLostEvent(focusEvent); } } diff --git a/src/genericinput.cpp b/src/genericinput.cpp index e4722a3..cd67c11 100644 --- a/src/genericinput.cpp +++ b/src/genericinput.cpp @@ -138,14 +138,12 @@ namespace gcn KeyInput GenericInput::dequeueKeyInput() { - KeyInput keyInput; - if (mKeyInputQueue.empty()) { throw GCN_EXCEPTION("The queue is empty."); } - keyInput = mKeyInputQueue.front(); + const KeyInputkeyInput = mKeyInputQueue.front(); mKeyInputQueue.pop(); return keyInput; @@ -158,14 +156,12 @@ namespace gcn MouseInput GenericInput::dequeueMouseInput() { - MouseInput mouseInput; - if (mMouseInputQueue.empty()) { throw GCN_EXCEPTION("The queue is empty."); } - mouseInput = mMouseInputQueue.front(); + const MouseInput mouseInput = mMouseInputQueue.front(); mMouseInputQueue.pop(); return mouseInput; diff --git a/src/imagefont.cpp b/src/imagefont.cpp index 6b6fb81..7b9e0c3 100644 --- a/src/imagefont.cpp +++ b/src/imagefont.cpp @@ -170,7 +170,7 @@ namespace gcn mFilename = filename; mImage = Image::load(filename, false); - Color separator = mImage->getPixel(0, 0); + const Color separator = mImage->getPixel(0, 0); int i = 0; for (i=0; separator == mImage->getPixel(i, 0) @@ -284,7 +284,7 @@ namespace gcn return mGlyphSpacing; } - Rectangle ImageFont::scanForGlyph(unsigned char glyph, int x, int y, const Color& separator) + Rectangle ImageFont::scanForGlyph(unsigned char glyph, int x, int y, const Color& separator) const { Color color; do diff --git a/src/sdl/sdl2graphics.cpp b/src/sdl/sdl2graphics.cpp index ca9c521..499bddb 100644 --- a/src/sdl/sdl2graphics.cpp +++ b/src/sdl/sdl2graphics.cpp @@ -225,10 +225,11 @@ namespace gcn 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; + const int x1 = area.x > top.x ? area.x : top.x; + const int y1 = area.y > top.y ? area.y : top.y; + const int x2 = area.x + area.width < top.x + top.width ? area.x + area.width : top.x + top.width; + const int y2 = area.y + area.height < top.y + top.height ? area.y + area.height : top.y + top.height; + SDL_Rect rect; rect.x = x1; rect.y = y1; @@ -381,10 +382,10 @@ namespace gcn void SDL2Graphics::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); diff --git a/src/sdl/sdlgraphics.cpp b/src/sdl/sdlgraphics.cpp index d18406a..630457b 100644 --- a/src/sdl/sdlgraphics.cpp +++ b/src/sdl/sdlgraphics.cpp @@ -108,7 +108,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 = carea.x; @@ -194,11 +194,10 @@ namespace gcn 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 x, y; + const int x1 = area.x > top.x ? area.x : top.x; + const int y1 = area.y > top.y ? area.y : top.y; + const int x2 = area.x + area.width < top.x + top.width ? area.x + area.width : top.x + top.width; + const int y2 = area.y + area.height < top.y + top.height ? area.y + area.height : top.y + top.height; SDL_LockSurface(mTarget); for (y = y1; y < y2; y++) @@ -219,7 +218,7 @@ namespace gcn rect.w = area.width; rect.h = area.height; - Uint32 color = SDL_MapRGBA(mTarget->format, mColor.r, mColor.g, mColor.b, mColor.a); + const Uint32 color = SDL_MapRGBA(mTarget->format, mColor.r, mColor.g, mColor.b, mColor.a); SDL_FillRect(mTarget, &rect, color); } } @@ -289,7 +288,7 @@ namespace gcn x2 = top.x + top.width -1; } - int bpp = mTarget->format->BytesPerPixel; + const int bpp = mTarget->format->BytesPerPixel; SDL_LockSurface(mTarget); @@ -400,7 +399,7 @@ namespace gcn y2 = top.y + top.height - 1; } - int bpp = mTarget->format->BytesPerPixel; + const int bpp = mTarget->format->BytesPerPixel; SDL_LockSurface(mTarget); @@ -472,10 +471,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); @@ -510,8 +509,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/widgets/button.cpp b/src/widgets/button.cpp index 229f216..5e9869b 100644 --- a/src/widgets/button.cpp +++ b/src/widgets/button.cpp @@ -85,8 +85,8 @@ namespace gcn addFocusListener(this); } - Button::Button(const std::string& caption) - : mCaption(caption), + Button::Button(std::string caption) + : mCaption(std::move(caption)), mHasMouse(false), mKeyPressed(false), mMousePressed(false), @@ -264,7 +264,7 @@ namespace gcn void Button::keyPressed(KeyEvent& keyEvent) { - Key key = keyEvent.getKey(); + const Key key = keyEvent.getKey(); if (key.getValue() == Key::Enter || key.getValue() == Key::Space) @@ -276,7 +276,7 @@ namespace gcn void Button::keyReleased(KeyEvent& keyEvent) { - Key key = keyEvent.getKey(); + const Key key = keyEvent.getKey(); if ((key.getValue() == Key::Enter || key.getValue() == Key::Space) diff --git a/src/widgets/checkbox.cpp b/src/widgets/checkbox.cpp index a65a30a..9d9e0cc 100644 --- a/src/widgets/checkbox.cpp +++ b/src/widgets/checkbox.cpp @@ -173,7 +173,7 @@ namespace gcn void CheckBox::keyPressed(KeyEvent& keyEvent) { - Key key = keyEvent.getKey(); + const Key key = keyEvent.getKey(); if (key.getValue() == Key::Enter || key.getValue() == Key::Space) @@ -198,7 +198,7 @@ namespace gcn void CheckBox::adjustSize() { - int height = getFont()->getHeight(); + const int height = getFont()->getHeight() + 2; setHeight(height); setWidth(getFont()->getWidth(mCaption) + height + height / 2); diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index 653e33b..217988f 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -219,7 +219,7 @@ namespace gcn { Color faceColor, highlightColor, shadowColor; int offset; - int alpha = getBaseColor().a; + const int alpha = getBaseColor().a; if (mPushed) { @@ -276,7 +276,7 @@ namespace gcn return mListBox->getSelected(); } - void DropDown::setSelected(int selected) + void DropDown::setSelected(int selected) const { if (selected >= 0) { @@ -419,7 +419,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/widgets/imagebutton.cpp b/src/widgets/imagebutton.cpp index 68d11bd..e01ea10 100644 --- a/src/widgets/imagebutton.cpp +++ b/src/widgets/imagebutton.cpp @@ -123,7 +123,7 @@ namespace gcn { gcn::Color faceColor = getBaseColor(); gcn::Color highlightColor, shadowColor; - int alpha = getBaseColor().a; + const int alpha = getBaseColor().a; if (isPressed()) { diff --git a/src/widgets/listbox.cpp b/src/widgets/listbox.cpp index 8f96759..213d42c 100644 --- a/src/widgets/listbox.cpp +++ b/src/widgets/listbox.cpp @@ -216,7 +216,7 @@ namespace gcn void ListBox::keyPressed(KeyEvent& keyEvent) { - Key key = keyEvent.getKey(); + const Key key = keyEvent.getKey(); if (key.getValue() == Key::Enter || key.getValue() == Key::Space) { diff --git a/src/widgets/radiobutton.cpp b/src/widgets/radiobutton.cpp index 1c87d76..29a5c0c 100644 --- a/src/widgets/radiobutton.cpp +++ b/src/widgets/radiobutton.cpp @@ -117,7 +117,7 @@ namespace gcn graphics->drawRectangle(Rectangle(0, 0, getWidth(), getHeight())); } - int h = getHeight() + getHeight() / 2; + const int h = getHeight() + getHeight() / 2; graphics->drawText(getCaption(), h - 2, 0); } @@ -135,7 +135,7 @@ namespace gcn h = getHeight() - 3; } - int alpha = getBaseColor().a; + const int alpha = getBaseColor().a; Color faceColor = getBaseColor(); faceColor.a = alpha; Color highlightColor = faceColor + 0x303030; @@ -149,7 +149,7 @@ namespace gcn graphics->setColor(backCol); int i; - int hh = (h + 1) / 2; + const int hh = (h + 1) / 2; for (i = 1; i <= hh; ++i) { @@ -177,7 +177,7 @@ namespace gcn graphics->setColor(getForegroundColor()); - int hhh = hh - 3; + const int hhh = hh - 3; if (mSelected) { for (i = 0; i < hhh; ++i) @@ -230,7 +230,7 @@ namespace gcn void RadioButton::keyPressed(KeyEvent& keyEvent) { - Key key = keyEvent.getKey(); + const Key key = keyEvent.getKey(); if (key.getValue() == Key::Enter || key.getValue() == Key::Space) @@ -290,7 +290,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/widgets/slider.cpp b/src/widgets/slider.cpp index 7e9c9c7..9e21b2c 100644 --- a/src/widgets/slider.cpp +++ b/src/widgets/slider.cpp @@ -146,9 +146,9 @@ namespace gcn void Slider::drawMarker(gcn::Graphics* graphics) { - gcn::Color faceColor = getBaseColor(); + const gcn::Color faceColor = getBaseColor(); Color highlightColor, shadowColor; - int alpha = getBaseColor().a; + const int alpha = getBaseColor().a; if (isEnabled()) { highlightColor = faceColor + 0x303030; @@ -166,7 +166,7 @@ namespace gcn if (getOrientation() == Horizontal) { - int v = getMarkerPosition(); + const int v = getMarkerPosition(); graphics->fillRectangle(gcn::Rectangle(v + 1, 1, getMarkerLength() - 2, getHeight() - 2)); graphics->setColor(highlightColor); graphics->drawLine(v, 0, v + getMarkerLength() - 1, 0); @@ -183,7 +183,7 @@ namespace gcn } else { - int v = (getHeight() - getMarkerLength()) - getMarkerPosition(); + const int v = (getHeight() - getMarkerLength()) - getMarkerPosition(); graphics->fillRectangle(gcn::Rectangle(1, v + 1, getWidth() - 2, getMarkerLength() - 2)); graphics->setColor(highlightColor); graphics->drawLine(0, v, 0, v + getMarkerLength() - 1); @@ -271,7 +271,7 @@ namespace gcn void Slider::keyPressed(KeyEvent& keyEvent) { - Key key = keyEvent.getKey(); + const Key key = keyEvent.getKey(); if (getOrientation() == Horizontal) { @@ -327,7 +327,7 @@ namespace gcn w = getHeight(); } - double pos = v / ((double)w - getMarkerLength()); + const double pos = v / ((double)w - getMarkerLength()); return (1.0 - pos) * getScaleStart() + pos * getScaleEnd(); } @@ -343,7 +343,7 @@ namespace gcn v = getHeight(); } - int w = (int)((v - getMarkerLength()) + const int w = (int)((v - getMarkerLength()) * (value - getScaleStart()) / (getScaleEnd() - getScaleStart())); diff --git a/src/widgets/textbox.cpp b/src/widgets/textbox.cpp index f6a3b8b..4e8618b 100644 --- a/src/widgets/textbox.cpp +++ b/src/widgets/textbox.cpp @@ -145,7 +145,7 @@ namespace gcn void TextBox::keyPressed(KeyEvent& keyEvent) { - Key key = keyEvent.getKey(); + const Key key = keyEvent.getKey(); if (key.getValue() == Key::Left) { diff --git a/src/widgets/togglebutton.cpp b/src/widgets/togglebutton.cpp index 0f5a737..a9042d4 100644 --- a/src/widgets/togglebutton.cpp +++ b/src/widgets/togglebutton.cpp @@ -85,7 +85,7 @@ namespace gcn { Color faceColor = getBaseColor(); Color highlightColor, shadowColor; - int alpha = getBaseColor().a; + const int alpha = getBaseColor().a; if (isPressed() || isSelected()) { @@ -118,7 +118,7 @@ namespace gcn graphics->setColor(getForegroundColor()); int textX; - int textY = getHeight() / 2 - getFont()->getHeight() / 2; + const int textY = getHeight() / 2 - getFont()->getHeight() / 2; switch (getAlignment()) { @@ -183,7 +183,7 @@ namespace gcn void ToggleButton::keyReleased(KeyEvent& keyEvent) { - Key key = keyEvent.getKey(); + const Key key = keyEvent.getKey(); if ((key.getValue() == Key::Enter || key.getValue() == Key::Space)