Skip to content

Commit

Permalink
Even more const uses, where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
midwan committed Sep 13, 2024
1 parent 582d2db commit f101b52
Show file tree
Hide file tree
Showing 52 changed files with 258 additions and 261 deletions.
2 changes: 1 addition & 1 deletion include/guisan/sdl/sdlinput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ namespace gcn
* @return A Guisan key value.
* @see Key
*/
Key convertSDLEventToGuichanKeyValue(SDL_Event event);
Key convertSDLEventToGuichanKeyValue(const SDL_Event& event);

std::queue<KeyInput> mKeyInputQueue;
std::queue<MouseInput> mMouseInputQueue;
Expand Down
2 changes: 1 addition & 1 deletion include/guisan/widgets/dropdown.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ namespace gcn
* @return the ListModel used.
* @see setListModel
*/
ListModel *getListModel();
ListModel *getListModel() const;

/**
* Adjusts the height of the drop down to fit the height of the
Expand Down
6 changes: 3 additions & 3 deletions include/guisan/widgets/imagetextbutton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ namespace gcn
* @param filename The filename of the image to display.
* @param caption The text to display.
*/
ImageTextButton(const std::string& filename, std::string& caption);
ImageTextButton(const std::string& filename, const std::string& caption);

/**
* Constructor.
*
* @param image The image to display.
* @param caption The text to display.
*/
ImageTextButton(Image* image, std::string& caption);
ImageTextButton(const Image* image, const std::string& caption);

/**
* Destructor.
Expand All @@ -110,7 +110,7 @@ namespace gcn
*
* @return The image of the image button.
*/
Image* getImage();
Image* getImage() const;


// Inherited from Widget
Expand Down
2 changes: 1 addition & 1 deletion include/guisan/widgets/listbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ namespace gcn
* @return the list model used.
* @see setListModel
*/
ListModel *getListModel();
ListModel *getListModel() const;

/**
* Adjusts the size of the list box to fit its list model.
Expand Down
4 changes: 2 additions & 2 deletions include/guisan/widgets/messagebox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ namespace gcn
*
* @return the title bar height.
*/
unsigned int getTitleBarHeight();
unsigned int getTitleBarHeight() const;

/**
* Check if the window is movable.
Expand All @@ -184,7 +184,7 @@ namespace gcn
*
* @return true or false.
*/
bool isOpaque();
bool isOpaque() const;

/**
* Add this MessageBox to a parent container, centered both horizontally and vertically
Expand Down
14 changes: 7 additions & 7 deletions include/guisan/widgets/scrollarea.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ namespace gcn
*
* @return the content of the ScrollArea.
*/
Widget* getContent();
Widget* getContent() const;

/**
* Sets the horizontal scrollbar policy.
Expand Down Expand Up @@ -416,42 +416,42 @@ namespace gcn
*
* @return the dimension of the up button.
*/
Rectangle getUpButtonDimension();
Rectangle getUpButtonDimension() const;

/**
* Gets the down button dimension.
*
* @return the dimension of the down button.
*/
Rectangle getDownButtonDimension();
Rectangle getDownButtonDimension() const;

/**
* Gets the left button dimension.
*
* @return the dimension of the left button.
*/
Rectangle getLeftButtonDimension();
Rectangle getLeftButtonDimension() const;

/**
* Gets the right button dimension.
*
* @return the dimension of the right button.
*/
Rectangle getRightButtonDimension();
Rectangle getRightButtonDimension() const;

/**
* Gets the vertical scrollbar dimension.
*
* @return the dimension of the vertical scrollbar.
*/
Rectangle getVerticalBarDimension();
Rectangle getVerticalBarDimension() const;

/**
* Gets the horizontal scrollbar dimension.
*
* @return the dimension of the horizontal scrollbar.
*/
Rectangle getHorizontalBarDimension();
Rectangle getHorizontalBarDimension() const;

/**
* Gets the vertical marker dimension.
Expand Down
6 changes: 3 additions & 3 deletions include/guisan/widgets/tabbedarea.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ namespace gcn
* @return The selected tab.
* @see isTabSelected, setSelectedTab
*/
Tab* getSelectedTab();
Tab* getSelectedTab() const;


// Inherited from Widget
Expand Down Expand Up @@ -247,12 +247,12 @@ namespace gcn
/**
* Adjusts the size of the tab container and the widget container.
*/
void adjustSize();
void adjustSize() const;

/**
* Adjusts the positions of the tabs.
*/
void adjustTabPositions();
void adjustTabPositions() const;

/**
* Holds the selected tab.
Expand Down
10 changes: 5 additions & 5 deletions include/guisan/widgets/textbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace gcn
* @param position the positon of the caret.
* @see getCaretPosition
*/
void setCaretPosition(unsigned int position);
void setCaretPosition(unsigned int position) const;

/**
* Gets the row number where the caret is currently located.
Expand All @@ -162,7 +162,7 @@ namespace gcn
* @param The row where the caret should be currently located.
* @see getCaretRow
*/
void setCaretRow(int row);
void setCaretRow(int row) const;

/**
* Gets the column where the caret is currently located.
Expand All @@ -178,7 +178,7 @@ namespace gcn
* @param The column where the caret should be currently located.
* @see getCaretColumn
*/
void setCaretColumn(int column);
void setCaretColumn(int column) const;

/**
* Sets the row and the column where the caret should be currently
Expand All @@ -188,7 +188,7 @@ namespace gcn
* @param column The column where the caret should be currently located.
* @see getCaretRow, getCaretColumn
*/
void setCaretRowColumn(int row, int column);
void setCaretRowColumn(int row, int column) const;

/**
* Scrolls the text to the caret if the text box is in a scroll area.
Expand Down Expand Up @@ -227,7 +227,7 @@ namespace gcn
* @return True if the text box is opaque, false otherwise.
* @see setOpaque
*/
bool isOpaque();
bool isOpaque() const;

/**
* Sets the text box to be opaque or not. An opaque text box will draw
Expand Down
4 changes: 2 additions & 2 deletions include/guisan/widgets/textfield.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ namespace gcn
* @param text The text of the text field.
* @see getText
*/
void setText(const std::string& text);
void setText(const std::string& text) const;

/**
* Gets the text of the text field.
Expand Down Expand Up @@ -140,7 +140,7 @@ namespace gcn
* @param position The caret position.
* @see getCaretPosition
*/
void setCaretPosition(unsigned int position);
void setCaretPosition(unsigned int position) const;

/**
* Gets the caret position. As there is only one line of text
Expand Down
4 changes: 2 additions & 2 deletions include/guisan/widgets/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ namespace gcn
* @return The title bar height.
* @see setTitleBarHeight
*/
unsigned int getTitleBarHeight();
unsigned int getTitleBarHeight() const;

/**
* Sets the window to be moveble or not.
Expand Down Expand Up @@ -187,7 +187,7 @@ namespace gcn
* @return True if the window is opaque, false otherwise.
* @see setOpaque
*/
bool isOpaque();
bool isOpaque() const;

/**
* Resizes the window to fit the content.
Expand Down
2 changes: 1 addition & 1 deletion src/cliprectangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace gcn
x = y = width = height = xOffset = yOffset = 0;
}

ClipRectangle::ClipRectangle(int x, int y, int width, int height, int xOffset, int yOffset)
ClipRectangle::ClipRectangle(const int x, const int y, const int width, const int height, const int xOffset, const int yOffset)
{
this->x = x;
this->y = y;
Expand Down
6 changes: 3 additions & 3 deletions src/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace gcn
{
}

Color::Color(int color)
Color::Color(const int color)
:
r((color >> 16) & 0xFF),
g((color >> 8) & 0xFF),
Expand All @@ -80,7 +80,7 @@ namespace gcn
{
}

Color::Color(int ar, int ag, int ab, int aa)
Color::Color(const int ar, const int ag, const int ab, const int aa)
:
r(ar),
g(ag),
Expand Down Expand Up @@ -111,7 +111,7 @@ namespace gcn
return result;
}

Color Color::operator*(float value) const
Color Color::operator*(const float value) const
{
Color result((int)(r * value), (int)(g * value), (int)(b * value), a);

Expand Down
6 changes: 3 additions & 3 deletions src/defaultfont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ namespace gcn
return 8*text.size();
}

int DefaultFont::drawGlyph(Graphics* graphics, unsigned char glyph, int x, int y)
int DefaultFont::drawGlyph(Graphics* graphics, unsigned char glyph, const int x, const int y)
{
graphics->drawRectangle(Rectangle(x, y, 8, 8));

return 8;
}

void DefaultFont::drawString(Graphics* graphics, const std::string& text, int x, int y, bool enabled)
void DefaultFont::drawString(Graphics* graphics, const std::string& text, int x, const int y, bool enabled)
{
unsigned int i;

Expand All @@ -95,7 +95,7 @@ namespace gcn
}
}

int DefaultFont::getStringIndexAt(const std::string& text, int x) const
int DefaultFont::getStringIndexAt(const std::string& text, const int x) const
{
if (x > (int)text.size() * 8)
{
Expand Down
2 changes: 1 addition & 1 deletion src/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace gcn
Exception::Exception(std::string message,
std::string function,
std::string filename,
unsigned int line)
const unsigned int line)
: mFunction(std::move(function)),
mMessage(std::move(message)),
mFilename(std::move(filename)),
Expand Down
4 changes: 2 additions & 2 deletions src/focushandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ namespace gcn
Event focusEvent(oldFocused);
distributeFocusLostEvent(focusEvent);
}
Event focusEvent(mWidgets.at(toBeFocusedIndex));
const Event focusEvent(mWidgets.at(toBeFocusedIndex));
distributeFocusGainedEvent(focusEvent);
}
}
Expand Down Expand Up @@ -185,7 +185,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
Expand Down
2 changes: 1 addition & 1 deletion src/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

namespace gcn
{
int Font::getStringIndexAt(const std::string& text, int x) const
int Font::getStringIndexAt(const std::string& text, const int x) const
{
int size = 0;

Expand Down
10 changes: 5 additions & 5 deletions src/genericinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace gcn
// TODO
}

void GenericInput::pushMouseButtonPressed(int x, int y, int button)
void GenericInput::pushMouseButtonPressed(const int x, const int y, const int button)
{
MouseInput mouseInput;
mouseInput.setX(x);
Expand All @@ -90,7 +90,7 @@ namespace gcn
mMouseInputQueue.push(mouseInput);
}

void GenericInput::pushMouseButtonReleased(int x, int y, int button)
void GenericInput::pushMouseButtonReleased(const int x, const int y, const int button)
{
MouseInput mouseInput;
mouseInput.setX(x);
Expand All @@ -101,7 +101,7 @@ namespace gcn
mMouseInputQueue.push(mouseInput);
}

void GenericInput::pushMouseWheelMovedUp(int x, int y)
void GenericInput::pushMouseWheelMovedUp(const int x, const int y)
{
MouseInput mouseInput;
mouseInput.setX(x);
Expand All @@ -111,7 +111,7 @@ namespace gcn
mMouseInputQueue.push(mouseInput);
}

void GenericInput::pushMouseWheelMovedDown(int x, int y)
void GenericInput::pushMouseWheelMovedDown(const int x, const int y)
{
MouseInput mouseInput;
mouseInput.setX(x);
Expand All @@ -121,7 +121,7 @@ namespace gcn
mMouseInputQueue.push(mouseInput);
}

void GenericInput::pushMouseMoved(int x, int y)
void GenericInput::pushMouseMoved(const int x, const int y)
{
MouseInput mouseInput;
mouseInput.setX(x);
Expand Down
Loading

0 comments on commit f101b52

Please sign in to comment.