From f0453725350ed0ed911449c96a9450aeb2ed2069 Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Thu, 12 Sep 2024 17:25:15 +0200 Subject: [PATCH 1/8] Use const where possible --- include/guisan/actionevent.hpp | 2 +- include/guisan/exception.hpp | 8 ++++---- include/guisan/imagefont.hpp | 2 +- include/guisan/widgets/button.hpp | 2 +- include/guisan/widgets/dropdown.hpp | 2 +- src/exception.cpp | 17 ++++++++--------- src/focushandler.cpp | 22 +++++++++++----------- src/genericinput.cpp | 8 ++------ src/imagefont.cpp | 4 ++-- src/sdl/sdl2graphics.cpp | 17 +++++++++-------- src/sdl/sdlgraphics.cpp | 29 ++++++++++++++--------------- src/widgets/button.cpp | 8 ++++---- src/widgets/checkbox.cpp | 4 ++-- src/widgets/dropdown.cpp | 6 +++--- src/widgets/imagebutton.cpp | 2 +- src/widgets/listbox.cpp | 2 +- src/widgets/radiobutton.cpp | 12 ++++++------ src/widgets/slider.cpp | 14 +++++++------- src/widgets/textbox.cpp | 2 +- src/widgets/togglebutton.cpp | 6 +++--- 20 files changed, 82 insertions(+), 87 deletions(-) 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) From f880a520a15c51cc3638b362bf580819e05c484c Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Thu, 12 Sep 2024 17:28:00 +0200 Subject: [PATCH 2/8] Updated scrollarea with const improvements --- src/widgets/scrollarea.cpp | 92 ++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 48 deletions(-) diff --git a/src/widgets/scrollarea.cpp b/src/widgets/scrollarea.cpp index 0c98ba2..663479a 100644 --- a/src/widgets/scrollarea.cpp +++ b/src/widgets/scrollarea.cpp @@ -195,7 +195,7 @@ namespace gcn void ScrollArea::setVerticalScrollAmount(int vScroll) { - int max = getVerticalMaxScroll(); + const int max = getVerticalMaxScroll(); mVScroll = vScroll; @@ -217,7 +217,7 @@ namespace gcn void ScrollArea::setHorizontalScrollAmount(int hScroll) { - int max = getHorizontalMaxScroll(); + const int max = getHorizontalMaxScroll(); mHScroll = hScroll; @@ -303,8 +303,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)) { @@ -388,10 +388,10 @@ namespace gcn { if (mIsVerticalMarkerDragged) { - int pos = mouseEvent.getY() - getVerticalBarDimension().y - mVerticalMarkerDragOffset; - int length = getVerticalMarkerDimension().height; + const int pos = mouseEvent.getY() - getVerticalBarDimension().y - mVerticalMarkerDragOffset; + const int length = getVerticalMarkerDimension().height; - Rectangle barDim = getVerticalBarDimension(); + const Rectangle barDim = getVerticalBarDimension(); if ((barDim.height - length) > 0) { @@ -406,10 +406,10 @@ namespace gcn if (mIsHorizontalMarkerDragged) { - int pos = mouseEvent.getX() - getHorizontalBarDimension().x - mHorizontalMarkerDragOffset; - int length = getHorizontalMarkerDimension().width; + const int pos = mouseEvent.getX() - getHorizontalBarDimension().x - mHorizontalMarkerDragOffset; + const int length = getHorizontalMarkerDimension().width; - Rectangle barDim = getHorizontalBarDimension(); + const Rectangle barDim = getHorizontalBarDimension(); if ((barDim.width - length) > 0) { @@ -459,11 +459,11 @@ namespace gcn void ScrollArea::drawHBar(Graphics* graphics) { - Rectangle dim = getHorizontalBarDimension(); + const Rectangle dim = getHorizontalBarDimension(); graphics->pushClipArea(dim); - int alpha = getBaseColor().a; + const int alpha = getBaseColor().a; Color trackColor = getBaseColor() - 0x101010; trackColor.a = alpha; Color shadowColor = getBaseColor() - 0x303030; @@ -480,11 +480,11 @@ namespace gcn void ScrollArea::drawVBar(Graphics* graphics) { - Rectangle dim = getVerticalBarDimension(); + const Rectangle dim = getVerticalBarDimension(); graphics->pushClipArea(dim); - int alpha = getBaseColor().a; + const int alpha = getBaseColor().a; Color trackColor = getBaseColor() - 0x101010; trackColor.a = alpha; Color shadowColor = getBaseColor() - 0x303030; @@ -510,14 +510,14 @@ namespace gcn void ScrollArea::drawUpButton(Graphics* graphics) { - Rectangle dim = getUpButtonDimension(); + const Rectangle dim = getUpButtonDimension(); graphics->pushClipArea(dim); Color highlightColor; Color shadowColor; Color faceColor; int offset; - int alpha = getBaseColor().a; + const int alpha = getBaseColor().a; if (mUpButtonPressed) { @@ -555,10 +555,9 @@ namespace gcn graphics->setColor(getForegroundColor()); - int i; - int w = dim.height / 2; - int h = w / 2 + 2; - for (i = 0; i < w / 2; ++i) + const int w = dim.height / 2; + const int h = w / 2 + 2; + for (int i = 0; i < w / 2; ++i) { graphics->drawLine(w - i + offset, i + h + offset, @@ -571,14 +570,14 @@ namespace gcn void ScrollArea::drawDownButton(Graphics* graphics) { - Rectangle dim = getDownButtonDimension(); + const Rectangle dim = getDownButtonDimension(); graphics->pushClipArea(dim); Color highlightColor; Color shadowColor; Color faceColor; int offset; - int alpha = getBaseColor().a; + const int alpha = getBaseColor().a; if (mDownButtonPressed) { @@ -616,10 +615,9 @@ namespace gcn graphics->setColor(getForegroundColor()); - int i; - int w = dim.height / 2; - int h = w + 1; - for (i = 0; i < w / 2; ++i) + const int w = dim.height / 2; + const int h = w + 1; + for (int i = 0; i < w / 2; ++i) { graphics->drawLine(w - i + offset, -i + h + offset, @@ -632,14 +630,14 @@ namespace gcn void ScrollArea::drawLeftButton(Graphics* graphics) { - Rectangle dim = getLeftButtonDimension(); + const Rectangle dim = getLeftButtonDimension(); graphics->pushClipArea(dim); Color highlightColor; Color shadowColor; Color faceColor; int offset; - int alpha = getBaseColor().a; + const int alpha = getBaseColor().a; if (mLeftButtonPressed) { @@ -677,10 +675,9 @@ namespace gcn graphics->setColor(getForegroundColor()); - int i; - int w = dim.width / 2; - int h = w - 2; - for (i = 0; i < w / 2; ++i) + const int w = dim.width / 2; + const int h = w - 2; + for (int i = 0; i < w / 2; ++i) { graphics->drawLine(i + h + offset, w - i + offset, @@ -693,14 +690,14 @@ namespace gcn void ScrollArea::drawRightButton(Graphics* graphics) { - Rectangle dim = getRightButtonDimension(); + const Rectangle dim = getRightButtonDimension(); graphics->pushClipArea(dim); Color highlightColor; Color shadowColor; Color faceColor; int offset; - int alpha = getBaseColor().a; + const int alpha = getBaseColor().a; if (mRightButtonPressed) { @@ -738,10 +735,9 @@ namespace gcn graphics->setColor(getForegroundColor()); - int i; - int w = dim.width / 2; - int h = w + 1; - for (i = 0; i < w / 2; ++i) + const int w = dim.width / 2; + const int h = w + 1; + for (int i = 0; i < w / 2; ++i) { graphics->drawLine(-i + h + offset, w - i + offset, @@ -754,10 +750,10 @@ namespace gcn void ScrollArea::drawVMarker(Graphics* graphics) { - Rectangle dim = getVerticalMarkerDimension(); + const Rectangle dim = getVerticalMarkerDimension(); graphics->pushClipArea(dim); - int alpha = getBaseColor().a; + const int alpha = getBaseColor().a; Color faceColor = getBaseColor(); faceColor.a = alpha; Color highlightColor = faceColor + 0x303030; @@ -781,10 +777,10 @@ namespace gcn void ScrollArea::drawHMarker(Graphics* graphics) { - Rectangle dim = getHorizontalMarkerDimension(); + const Rectangle dim = getHorizontalMarkerDimension(); graphics->pushClipArea(dim); - int alpha = getBaseColor().a; + const int alpha = getBaseColor().a; Color faceColor = getBaseColor(); faceColor.a = alpha; Color highlightColor = faceColor + 0x303030; @@ -823,8 +819,8 @@ namespace gcn void ScrollArea::checkPolicies() { - int w = getWidth(); - int h = getHeight(); + const int w = getWidth(); + const int h = getHeight(); mHBarVisible = false; mVBarVisible = false; @@ -1057,7 +1053,7 @@ namespace gcn } int length, pos; - Rectangle barDim = getVerticalBarDimension(); + const Rectangle barDim = getVerticalBarDimension(); if (getContent() && getContent()->getHeight() != 0) { @@ -1081,7 +1077,7 @@ namespace gcn if (getVerticalMaxScroll() != 0) { - pos = ((barDim.height - length) * getVerticalScrollAmount()) + pos = (barDim.height - length) * getVerticalScrollAmount() / getVerticalMaxScroll(); } else @@ -1100,7 +1096,7 @@ namespace gcn } int length, pos; - Rectangle barDim = getHorizontalBarDimension(); + const Rectangle barDim = getHorizontalBarDimension(); if (getContent() && getContent()->getWidth() != 0) { @@ -1124,7 +1120,7 @@ namespace gcn if (getHorizontalMaxScroll() != 0) { - pos = ((barDim.width - length) * getHorizontalScrollAmount()) + pos = (barDim.width - length) * getHorizontalScrollAmount() / getHorizontalMaxScroll(); } else From c5ffaf82b54c6d7d0bd22fdc1df89a35f6204b80 Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Thu, 12 Sep 2024 17:29:56 +0200 Subject: [PATCH 3/8] Fixed actionevent.cpp --- src/actionevent.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/actionevent.cpp b/src/actionevent.cpp index b232b06..5821a6a 100644 --- a/src/actionevent.cpp +++ b/src/actionevent.cpp @@ -62,9 +62,9 @@ namespace gcn { - ActionEvent::ActionEvent(Widget* source, const std::string& id) + ActionEvent::ActionEvent(Widget* source, std::string id) :Event(source), - mId(id) + mId(std::move(id)) { } From ff055d02f4561e84c996947020b9876fab7b4d19 Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Thu, 12 Sep 2024 17:32:34 +0200 Subject: [PATCH 4/8] Fixed typo in genericinput.cpp --- src/genericinput.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/genericinput.cpp b/src/genericinput.cpp index cd67c11..9a81c8d 100644 --- a/src/genericinput.cpp +++ b/src/genericinput.cpp @@ -143,7 +143,7 @@ namespace gcn throw GCN_EXCEPTION("The queue is empty."); } - const KeyInputkeyInput = mKeyInputQueue.front(); + const KeyInput keyInput = mKeyInputQueue.front(); mKeyInputQueue.pop(); return keyInput; @@ -164,7 +164,7 @@ namespace gcn const MouseInput mouseInput = mMouseInputQueue.front(); mMouseInputQueue.pop(); - return mouseInput; + return mouseInput; } void GenericInput::_pollInput() From 3a0e9dbea8d76da58108cd118e1a1938ae9c690f Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Thu, 12 Sep 2024 17:34:50 +0200 Subject: [PATCH 5/8] Fixed sdlgraphics.cpp --- src/sdl/sdlgraphics.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sdl/sdlgraphics.cpp b/src/sdl/sdlgraphics.cpp index 630457b..55a6919 100644 --- a/src/sdl/sdlgraphics.cpp +++ b/src/sdl/sdlgraphics.cpp @@ -200,9 +200,9 @@ namespace gcn 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++) + for (int y = y1; y < y2; y++) { - for (x = x1; x < x2; x++) + for (int x = x1; x < x2; x++) { SDLputPixelAlpha(mTarget, x, y, mColor); } From 1bae3311f5bad7516066c4a48371194b6be2e145 Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Thu, 12 Sep 2024 17:40:58 +0200 Subject: [PATCH 6/8] Remove bit that shouldn't be included in the PR --- src/widgets/checkbox.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/checkbox.cpp b/src/widgets/checkbox.cpp index 9d9e0cc..9685ebf 100644 --- a/src/widgets/checkbox.cpp +++ b/src/widgets/checkbox.cpp @@ -198,7 +198,7 @@ namespace gcn void CheckBox::adjustSize() { - const int height = getFont()->getHeight() + 2; + const int height = getFont()->getHeight(); setHeight(height); setWidth(getFont()->getWidth(mCaption) + height + height / 2); From 7139a66d59b6e4513ca00654e2c68838133223ad Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Thu, 12 Sep 2024 17:41:57 +0200 Subject: [PATCH 7/8] Use spaces instead of tab --- src/sdl/sdl2graphics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdl/sdl2graphics.cpp b/src/sdl/sdl2graphics.cpp index 499bddb..f8fdcca 100644 --- a/src/sdl/sdl2graphics.cpp +++ b/src/sdl/sdl2graphics.cpp @@ -385,7 +385,7 @@ namespace gcn 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; + const int y2 = rectangle.y + rectangle.height - 1; drawHLine(x1, y1, x2); drawHLine(x1, y2, x2); From ef2dbb8c782f76d206c6459b2fddb46d776b8f85 Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Thu, 12 Sep 2024 17:47:04 +0200 Subject: [PATCH 8/8] Fixed one more tab -> spaces --- src/sdl/sdlgraphics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdl/sdlgraphics.cpp b/src/sdl/sdlgraphics.cpp index 55a6919..fae40d8 100644 --- a/src/sdl/sdlgraphics.cpp +++ b/src/sdl/sdlgraphics.cpp @@ -474,7 +474,7 @@ namespace gcn 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; + const int y2 = rectangle.y + rectangle.height - 1; drawHLine(x1, y1, x2); drawHLine(x1, y2, x2);