From ecb56ef5be618b7fde14f334d20a8947e2ba861c Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Fri, 15 May 2020 00:27:51 +0200 Subject: [PATCH] Modernized code in guisan objects, improved GUI layout --- external/libguisan/include/guisan.hpp | 17 +- .../libguisan/include/guisan/actionevent.hpp | 61 +- .../include/guisan/actionlistener.hpp | 8 +- .../include/guisan/basiccontainer.hpp | 4 +- .../include/guisan/cliprectangle.hpp | 78 +- external/libguisan/include/guisan/color.hpp | 174 +- .../include/guisan/deathlistener.hpp | 52 +- .../libguisan/include/guisan/defaultfont.hpp | 65 +- external/libguisan/include/guisan/event.hpp | 60 +- .../libguisan/include/guisan/exception.hpp | 147 +- .../libguisan/include/guisan/focushandler.hpp | 439 ++-- .../include/guisan/focuslistener.hpp | 65 +- external/libguisan/include/guisan/font.hpp | 104 +- .../libguisan/include/guisan/genericinput.hpp | 170 +- external/libguisan/include/guisan/glut.hpp | 11 +- .../libguisan/include/guisan/graphics.hpp | 379 ++-- external/libguisan/include/guisan/gui.hpp | 564 ++--- external/libguisan/include/guisan/image.hpp | 194 +- .../libguisan/include/guisan/imagefont.hpp | 248 +-- .../libguisan/include/guisan/imageloader.hpp | 51 +- external/libguisan/include/guisan/input.hpp | 97 +- .../libguisan/include/guisan/inputevent.hpp | 130 +- external/libguisan/include/guisan/key.hpp | 196 +- .../libguisan/include/guisan/keyevent.hpp | 6 +- .../libguisan/include/guisan/keyinput.hpp | 263 +-- .../libguisan/include/guisan/keylistener.hpp | 90 +- .../libguisan/include/guisan/mouseevent.hpp | 199 +- .../libguisan/include/guisan/mouseinput.hpp | 244 +-- .../include/guisan/mouselistener.hpp | 233 +-- external/libguisan/include/guisan/opengl.hpp | 11 +- .../include/guisan/opengl/openglgraphics.hpp | 76 +- .../include/guisan/opengl/openglimage.hpp | 125 +- .../guisan/opengl/openglsdlimageloader.hpp | 64 +- .../libguisan/include/guisan/rectangle.hpp | 92 +- external/libguisan/include/guisan/sdl.hpp | 11 +- .../include/guisan/sdl/sdl2graphics.hpp | 10 +- .../include/guisan/sdl/sdlgraphics.hpp | 148 +- .../libguisan/include/guisan/sdl/sdlimage.hpp | 88 +- .../libguisan/include/guisan/sdl/sdlinput.hpp | 104 +- .../include/guisan/sdl/sdltruetypefont.hpp | 51 +- .../include/guisan/selectionevent.hpp | 42 +- .../include/guisan/selectionlistener.hpp | 54 +- external/libguisan/include/guisan/widget.hpp | 2 +- .../include/guisan/widgetlistener.hpp | 106 +- .../include/guisan/widgets/button.hpp | 188 +- .../include/guisan/widgets/checkbox.hpp | 187 +- .../include/guisan/widgets/dropdown.hpp | 2 +- .../include/guisan/widgets/scrollarea.hpp | 12 +- external/libguisan/src/actionevent.cpp | 29 +- external/libguisan/src/basiccontainer.cpp | 542 +++-- external/libguisan/src/cliprectangle.cpp | 42 +- external/libguisan/src/color.cpp | 115 +- external/libguisan/src/defaultfont.cpp | 60 +- external/libguisan/src/event.cpp | 24 +- external/libguisan/src/exception.cpp | 86 +- external/libguisan/src/focushandler.cpp | 1051 +++++----- external/libguisan/src/font.cpp | 27 +- external/libguisan/src/genericinput.cpp | 192 +- external/libguisan/src/graphics.cpp | 4 +- external/libguisan/src/gui.cpp | 1845 ++++++++--------- external/libguisan/src/guisan.cpp | 9 +- external/libguisan/src/image.cpp | 45 +- external/libguisan/src/imagefont.cpp | 399 ++-- external/libguisan/src/inputevent.cpp | 75 +- external/libguisan/src/key.cpp | 58 +- external/libguisan/src/keyevent.cpp | 67 +- external/libguisan/src/keyinput.cpp | 134 +- external/libguisan/src/mouseevent.cpp | 85 +- external/libguisan/src/mouseinput.cpp | 104 +- external/libguisan/src/opengl/opengl.cpp | 5 +- .../libguisan/src/opengl/openglgraphics.cpp | 442 ++-- external/libguisan/src/opengl/openglimage.cpp | 273 +-- external/libguisan/src/rectangle.cpp | 122 +- external/libguisan/src/sdl/sdl.cpp | 5 +- external/libguisan/src/sdl/sdl2graphics.cpp | 745 +++---- external/libguisan/src/sdl/sdlgraphics.cpp | 1181 +++++------ external/libguisan/src/sdl/sdlimage.cpp | 199 +- external/libguisan/src/sdl/sdlimageloader.cpp | 108 +- external/libguisan/src/sdl/sdlinput.cpp | 718 ++++--- .../libguisan/src/sdl/sdltruetypefont.cpp | 48 +- external/libguisan/src/selectionevent.cpp | 16 +- external/libguisan/src/widgets/listbox.cpp | 8 +- external/libguisan/src/widgets/scrollarea.cpp | 20 +- external/libguisan/src/widgets/textbox.cpp | 2 +- external/libguisan/src/widgets/window.cpp | 4 +- src/osdep/gui/PanelAbout.cpp | 2 +- src/osdep/gui/PanelCPU.cpp | 9 +- src/osdep/gui/PanelChipset.cpp | 12 +- src/osdep/gui/PanelCustom.cpp | 2 + src/osdep/gui/PanelDisplay.cpp | 12 +- src/osdep/gui/PanelRAM.cpp | 3 +- src/osdep/gui/PanelSavestate.cpp | 6 +- src/osdep/gui/PanelSound.cpp | 12 +- src/osdep/target.h | 4 +- 94 files changed, 7326 insertions(+), 7347 deletions(-) diff --git a/external/libguisan/include/guisan.hpp b/external/libguisan/include/guisan.hpp index a5e068f2..653f66bf 100644 --- a/external/libguisan/include/guisan.hpp +++ b/external/libguisan/include/guisan.hpp @@ -115,15 +115,14 @@ class Widget; -extern "C" -{ - /** - * Gets the the version of Guisan. As it is a C function - * it can be used to check for Guichan with autotools. - * - * @return the version of Guisan. - */ - GCN_CORE_DECLSPEC extern const char* gcnGuisanVersion(); +extern "C" { +/** + * Gets the the version of Guisan. As it is a C function + * it can be used to check for Guichan with autotools. + * + * @return the version of Guisan. + */ +GCN_CORE_DECLSPEC extern const char* gcnGuisanVersion(); } #endif // end GCN_GUISAN_HPP diff --git a/external/libguisan/include/guisan/actionevent.hpp b/external/libguisan/include/guisan/actionevent.hpp index 52a4319c..7725a610 100644 --- a/external/libguisan/include/guisan/actionevent.hpp +++ b/external/libguisan/include/guisan/actionevent.hpp @@ -64,42 +64,41 @@ namespace gcn { - class Widget; + class Widget; - /** - * Represents an action event. - * - * @author Olof Naessén - * @since 0.6.0 - */ - class GCN_CORE_DECLSPEC ActionEvent: public Event - { - public: + /** + * Represents an action event. + * + * @author Olof Naessén + * @since 0.6.0 + */ + class GCN_CORE_DECLSPEC ActionEvent : public Event + { + public: - /** - * Constructor. - * - * @param source the source widget of the event. - * @param id the identifier of the event. - */ - ActionEvent(Widget* source, const std::string& id); + /** + * Constructor. + * + * @param source the source widget of the event. + * @param id the identifier of the event. + */ + ActionEvent(Widget* source, std::string id); - /** - * Destructor. - */ - virtual ~ActionEvent(); + /** + * Destructor. + */ + virtual ~ActionEvent(); - /** - * Gets the id of the event. - * - * @return the id of the event. - */ - const std::string& getId() const; + /** + * Gets the id of the event. + * + * @return the id of the event. + */ + [[nodiscard]] const std::string& getId() const; - protected: - std::string mId; - }; + protected: + std::string mId; + }; } #endif // GCN_ACTIONEVENT_HPP - diff --git a/external/libguisan/include/guisan/actionlistener.hpp b/external/libguisan/include/guisan/actionlistener.hpp index eff7e9ed..6e47a042 100644 --- a/external/libguisan/include/guisan/actionlistener.hpp +++ b/external/libguisan/include/guisan/actionlistener.hpp @@ -57,8 +57,6 @@ #ifndef GCN_ACTIONLISTENER_HPP #define GCN_ACTIONLISTENER_HPP -#include - #include "guisan/actionevent.hpp" #include "guisan/platform.hpp" @@ -80,11 +78,11 @@ namespace gcn /** * Destructor. */ - virtual ~ActionListener() { } + virtual ~ActionListener() = default; /** - * Called when an action is recieved from a Widget. It is used - * to be able to recieve a notification that an action has + * Called when an action is received from a Widget. It is used + * to be able to receive a notification that an action has * occured. * * @param actionEvent the event of the action. diff --git a/external/libguisan/include/guisan/basiccontainer.hpp b/external/libguisan/include/guisan/basiccontainer.hpp index bef368af..605a857b 100644 --- a/external/libguisan/include/guisan/basiccontainer.hpp +++ b/external/libguisan/include/guisan/basiccontainer.hpp @@ -143,8 +143,8 @@ namespace gcn * Finds a widget given an id. * * @param id the id to find a widget by. - * @return the widget with the corrosponding id, - NULL of no widget is found. + * @return the widget with the corresponding id, + NULL of no widget is found. */ virtual Widget* findWidgetById(const std::string& id); diff --git a/external/libguisan/include/guisan/cliprectangle.hpp b/external/libguisan/include/guisan/cliprectangle.hpp index dc1190a5..6cbd2d4e 100644 --- a/external/libguisan/include/guisan/cliprectangle.hpp +++ b/external/libguisan/include/guisan/cliprectangle.hpp @@ -62,50 +62,50 @@ namespace gcn { - /** - * A rectangle used when dealing with clipping. It is a regular - * Rectangle extended with variables for x offsets and y offsets. - */ - class GCN_CORE_DECLSPEC ClipRectangle : public Rectangle - { - public: + /** + * A rectangle used when dealing with clipping. It is a regular + * Rectangle extended with variables for x offsets and y offsets. + */ + class GCN_CORE_DECLSPEC ClipRectangle : public Rectangle + { + public: - /** - * Constructor. - */ - ClipRectangle(); + /** + * Constructor. + */ + ClipRectangle(); - /** - * Constructor. - * - * @param x the rectangle x coordinate. - * @param y the rectangle y coordinate. - * @param width the rectangle width. - * @param height the rectangle height. - * @param xOffset origin of drawing (used by Graphics). - * @param yOffset origin of drawing (used by Graphics) . - */ - ClipRectangle(int x, int y, int width, int height, - int xOffset, int yOffset); + /** + * Constructor. + * + * @param x the rectangle x coordinate. + * @param y the rectangle y coordinate. + * @param width the rectangle width. + * @param height the rectangle height. + * @param xOffset origin of drawing (used by Graphics). + * @param yOffset origin of drawing (used by Graphics) . + */ + ClipRectangle(int x, int y, int width, int height, + int xOffset, int yOffset); - /** - * Copies x, y, width and height field from a Rectangle. - * - * @param other the Rectangle to copy from. - * @returns a ClipRectangle. - */ - const ClipRectangle& operator=(const Rectangle& other); + /** + * Copies x, y, width and height field from a Rectangle. + * + * @param other the Rectangle to copy from. + * @returns a ClipRectangle. + */ + const ClipRectangle& operator=(const Rectangle& other); - /** - * x-origin of drawing (used by Graphics). - */ - int xOffset; + /** + * x-origin of drawing (used by Graphics). + */ + int xOffset; - /** - * y-origin of drawing (used by Graphics). - */ - int yOffset; - }; + /** + * y-origin of drawing (used by Graphics). + */ + int yOffset; + }; } #endif // end GCN_CLIPRECTANGLE_HPP diff --git a/external/libguisan/include/guisan/color.hpp b/external/libguisan/include/guisan/color.hpp index db6bc767..f0a4f91a 100644 --- a/external/libguisan/include/guisan/color.hpp +++ b/external/libguisan/include/guisan/color.hpp @@ -61,105 +61,105 @@ namespace gcn { - /** - * Represents a color with red, green, blue and alpha components. - */ - class GCN_CORE_DECLSPEC Color - { - public: + /** + * Represents a color with red, green, blue and alpha components. + */ + class GCN_CORE_DECLSPEC Color + { + public: - /** - * Constructor. Initializes the color to black. - */ - Color(); + /** + * Constructor. Initializes the color to black. + */ + Color(); - /** - * Constructs a color from the bytes in an integer. Call it with - * a hexadecimal constant for HTML-style color representation. - * The alpha component will be set to 255. - * - * EXAMPLE: Color(0xff50a0) constructs Gui-chan's favourite color. - * - * NOTE: Because of this constructor, integers will be automatically - * casted to a color by your compiler. - * - * @param color the color. - */ - Color(int color); + /** + * Constructs a color from the bytes in an integer. Call it with + * a hexadecimal constant for HTML-style color representation. + * The alpha component will be set to 255. + * + * EXAMPLE: Color(0xff50a0) constructs Gui-chan's favourite color. + * + * NOTE: Because of this constructor, integers will be automatically + * casted to a color by your compiler. + * + * @param color the color. + */ + Color(int color); - /** - * Constructor. - * - * @param r Red color component (range 0-255). - * @param g Green color component (range 0-255). - * @param b Blue color component (range 0-255). - * @param a Color alpha, used for transparency. A value of 0 means - * totaly transparent, 255 is totaly opaque (the default). - */ - Color(int r, int g, int b, int a = 255); + /** + * Constructor. + * + * @param r Red color component (range 0-255). + * @param g Green color component (range 0-255). + * @param b Blue color component (range 0-255). + * @param a Color alpha, used for transparency. A value of 0 means + * totaly transparent, 255 is totaly opaque (the default). + */ + Color(int r, int g, int b, int a = 255); - /** - * Adds the RGB values of two colors together. The values will be - * clamped if they go out of range. - * - * @param color a color to add to this color. - * @return the resulting color with alpha set to 255. - */ - Color operator+(const Color& color) const; + /** + * Adds the RGB values of two colors together. The values will be + * clamped if they go out of range. + * + * @param color a color to add to this color. + * @return the resulting color with alpha set to 255. + */ + Color operator+(const Color& color) const; - /** - * Subtracts the RGB values of one color from another. - * The values will be clamped if they go out of range. - * - * @param color a color to subtract from this color. - * @return the resulting color with alpha set to 255. - */ - Color operator-(const Color& color) const; + /** + * Subtracts the RGB values of one color from another. + * The values will be clamped if they go out of range. + * + * @param color a color to subtract from this color. + * @return the resulting color with alpha set to 255. + */ + Color operator-(const Color& color) const; - /** - * Multiplies the RGB values of a color with a float value. - * The values will be clamped if they go out of range. - * - * @param value the value to multiply the color with. - * @return the resulting color with alpha untouched. - */ - Color operator*(float value) const; + /** + * Multiplies the RGB values of a color with a float value. + * The values will be clamped if they go out of range. + * + * @param value the value to multiply the color with. + * @return the resulting color with alpha untouched. + */ + Color operator*(float value) const; - /** - * Compares two colors. - * - * @return true if the two colors have the same RGBA components. - */ - bool operator==(const Color& color) const; + /** + * Compares two colors. + * + * @return true if the two colors have the same RGBA components. + */ + bool operator==(const Color& color) const; - /** - * Compares two colors. - * - * @return true if the two colors have different RGBA components. - */ - bool operator!=(const Color& color) const; + /** + * Compares two colors. + * + * @return true if the two colors have different RGBA components. + */ + bool operator!=(const Color& color) const; - /** - * Red color component (range 0-255). - */ - int r; + /** + * Red color component (range 0-255). + */ + int r; - /** - * Green color component (range 0-255). - */ - int g; + /** + * Green color component (range 0-255). + */ + int g; - /** - * Blue color component (range 0-255). - */ - int b; + /** + * Blue color component (range 0-255). + */ + int b; - /** - * Color alpha, used for transparency. A value of 0 means totaly - * transparent, 255 is totaly opaque (the default) - */ - int a; - }; + /** + * Color alpha, used for transparency. A value of 0 means totaly + * transparent, 255 is totaly opaque (the default) + */ + int a; + }; } #endif // end GCN_COLOR_HPP diff --git a/external/libguisan/include/guisan/deathlistener.hpp b/external/libguisan/include/guisan/deathlistener.hpp index 8b9bcec9..843c9d40 100644 --- a/external/libguisan/include/guisan/deathlistener.hpp +++ b/external/libguisan/include/guisan/deathlistener.hpp @@ -57,40 +57,38 @@ #ifndef GCN_DEATHLISTENER_HPP #define GCN_DEATHLISTENER_HPP -#include - #include "guisan/event.hpp" #include "guisan/platform.hpp" namespace gcn { - /** - * Listener of death events from Widgets. To be able to - * listen for deaths you must make a class which inherits - * from this class and implements the death function. - * - * @see Widget::addDeathListener - * @author Olof Naessén - * @since 0.6.0 - */ - class GCN_CORE_DECLSPEC DeathListener - { - public: + /** + * Listener of death events from Widgets. To be able to + * listen for deaths you must make a class which inherits + * from this class and implements the death function. + * + * @see Widget::addDeathListener + * @author Olof Naessén + * @since 0.6.0 + */ + class GCN_CORE_DECLSPEC DeathListener + { + public: - /** - * Destructor. - */ - virtual ~DeathListener() { } + /** + * Destructor. + */ + virtual ~DeathListener() + = default; - /** - * Called when a widget dies. It is used to be able to recieve - * a notification when a death of a widget occurs. - * - * @param event the event of the death. - */ - virtual void death(const Event& event) = 0; - - }; + /** + * Called when a widget dies. It is used to be able to receive + * a notification when a death of a widget occurs. + * + * @param event the event of the death. + */ + virtual void death(const Event& event) = 0; + }; } #endif // end GCN_DEATHLISTENER_HPP diff --git a/external/libguisan/include/guisan/defaultfont.hpp b/external/libguisan/include/guisan/defaultfont.hpp index 544ae0f8..ee309187 100644 --- a/external/libguisan/include/guisan/defaultfont.hpp +++ b/external/libguisan/include/guisan/defaultfont.hpp @@ -62,46 +62,47 @@ namespace gcn { - /** - * A font only capable of drawing rectangles. It is used by default - * merely to show that no font have been set. - */ - class GCN_CORE_DECLSPEC DefaultFont : public Font - { - public: + /** + * A font only capable of drawing rectangles. It is used by default + * merely to show that no font have been set. + */ + class GCN_CORE_DECLSPEC DefaultFont : public Font + { + public: - /** - * Destructor. - */ - virtual ~DefaultFont(){} + /** + * Destructor. + */ + virtual ~DefaultFont() + = default; - /** - * Draws a glyph as a rectangle. The glyphs always be drawn as - * rectangles no matter the glyph. - * - * NOTE: You normally won't use this function to draw text since - * the Graphics class contains better functions for drawing - * text. - * - * @param graphics a Graphics object to be used for drawing. - * @param glyph a glyph to draw. - * @param x the x coordinate where to draw the glyph. - * @param y the y coordinate where to draw the glyph. - * @return the width of the glyph in pixels. - */ - virtual int drawGlyph(Graphics* graphics, unsigned char glyph, int x, int y); + /** + * Draws a glyph as a rectangle. The glyphs always be drawn as + * rectangles no matter the glyph. + * + * NOTE: You normally won't use this function to draw text since + * the Graphics class contains better functions for drawing + * text. + * + * @param graphics a Graphics object to be used for drawing. + * @param glyph a glyph to draw. + * @param x the x coordinate where to draw the glyph. + * @param y the y coordinate where to draw the glyph. + * @return the width of the glyph in pixels. + */ + virtual int drawGlyph(Graphics* graphics, unsigned char glyph, int x, int y); - // Inherited from Font + // Inherited from Font - virtual void drawString(Graphics* graphics, const std::string& text, int x, int y); + void drawString(Graphics* graphics, const std::string& text, int x, int y) override; - virtual int getWidth(const std::string& text) const; + [[nodiscard]] int getWidth(const std::string& text) const override; - virtual int getHeight() const; + [[nodiscard]] int getHeight() const override; - virtual int getStringIndexAt(const std::string& text, int x); - }; + int getStringIndexAt(const std::string& text, int x) override; + }; } #endif // end GCN_DEFAULTFONT_HPP diff --git a/external/libguisan/include/guisan/event.hpp b/external/libguisan/include/guisan/event.hpp index 9d4b8ab2..7f9bd7fc 100644 --- a/external/libguisan/include/guisan/event.hpp +++ b/external/libguisan/include/guisan/event.hpp @@ -61,42 +61,42 @@ namespace gcn { - class Widget; + class Widget; - /** - * Base class for all events. - * - * @author Olof Naessén - * @since 0.6.0 - */ - class GCN_CORE_DECLSPEC Event - { - public: + /** + * Base class for all events. + * + * @author Olof Naessén + * @since 0.6.0 + */ + class GCN_CORE_DECLSPEC Event + { + public: - /** - * Constructor. - * - * @param source the source widget of the event. - */ - Event(Widget* source); + /** + * Constructor. + * + * @param source the source widget of the event. + */ + Event(Widget* source); - /** - * Destructor. - */ - virtual ~Event(); + /** + * Destructor. + */ + virtual ~Event(); - /** - * Gets the source widget of the event. - * - * @return the source widget of the event. - */ - Widget* getSource() const; + /** + * Gets the source widget of the event. + * + * @return the source widget of the event. + */ + [[nodiscard]] Widget* getSource() const; - protected: - Widget* mSource; - unsigned int mType; - }; + protected: + Widget* mSource; + unsigned int mType{}; + }; } #endif // end GCN_EVENT_HPP diff --git a/external/libguisan/include/guisan/exception.hpp b/external/libguisan/include/guisan/exception.hpp index 243d8f1d..12c176f9 100644 --- a/external/libguisan/include/guisan/exception.hpp +++ b/external/libguisan/include/guisan/exception.hpp @@ -75,91 +75,90 @@ * the exception occured. */ #define GCN_EXCEPTION(mess) gcn::Exception(mess, \ - __FUNCTION__, \ - __FILE__, \ - __LINE__) + __FUNCTION__, \ + __FILE__, \ + __LINE__) namespace gcn { + /** + * An exception containing a message, a file and a line number. + * Guichan will only throw exceptions of this class. You can use + * this class for your own exceptions. A nifty feature of the + * excpetion class is that it can tell you from which line and + * file it was thrown. To make things easier when throwing + * exceptions there exists a macro for creating exceptions + * which automatically sets the filename and line number. + * + * EXAMPLE: @code + * throw GCN_EXCEPTION("my error message"); + * @endcode + */ + class GCN_CORE_DECLSPEC Exception + { + public: - /** - * An exception containing a message, a file and a line number. - * Guichan will only throw exceptions of this class. You can use - * this class for your own exceptions. A nifty feature of the - * excpetion class is that it can tell you from which line and - * file it was thrown. To make things easier when throwing - * exceptions there exists a macro for creating exceptions - * which automatically sets the filename and line number. - * - * EXAMPLE: @code - * throw GCN_EXCEPTION("my error message"); - * @endcode - */ - class GCN_CORE_DECLSPEC Exception - { - public: + /** + * Constructor. + */ + Exception(); - /** - * Constructor. - */ - Exception(); + /** + * Constructor. + * + * @param message the error message. + */ + Exception(std::string message); - /** - * Constructor. - * - * @param message the error message. - */ - Exception(const std::string& message); + /** + * Constructor. + * + * NOTE: Don't use this constructor. Use the GCN_EXCEPTION macro instead. + * + * @param message the error message. + * @param function the function name. + * @param filename the name of the file. + * @param line the line number. + */ + Exception(std::string message, + std::string function, + std::string filename, + int line); - /** - * Constructor. - * - * NOTE: Don't use this constructor. Use the GCN_EXCEPTION macro instead. - * - * @param message the error message. - * @param function the function name. - * @param filename the name of the file. - * @param line the line number. - */ - Exception(const std::string& message, - const std::string& function, - const std::string& filename, - int line); + /** + * Gets the function name in which the exception was thrown. + * + * @return the function name in which the exception was thrown. + */ + [[nodiscard]] const std::string& getFunction() const; - /** - * Gets the function name in which the exception was thrown. - * - * @return the function name in which the exception was thrown. - */ - const std::string& getFunction() const; + /** + * Gets the error message of the exception. + * + * @return the error message. + */ + [[nodiscard]] const std::string& getMessage() const; - /** - * Gets the error message of the exception. - * - * @return the error message. - */ - const std::string& getMessage() const; + /** + * Gets the filename in which the exceptions was thrown. + * + * @return the filename in which the exception was thrown. + */ + [[nodiscard]] const std::string& getFilename() const; - /** - * Gets the filename in which the exceptions was thrown. - * - * @return the filename in which the exception was thrown. - */ - const std::string& getFilename() const; + /** + * Gets the line number of the line where the exception was thrown. + * + * @return the line number of the line where the exception was thrown. + */ + [[nodiscard]] int getLine() const; - /** - * Gets the line number of the line where the exception was thrown. - * - * @return the line number of the line where the exception was thrown. - */ - int getLine() const; - - protected: - std::string mFunction; - std::string mMessage; - std::string mFilename; - int mLine; - }; + protected: + std::string mFunction; + std::string mMessage; + std::string mFilename; + int mLine; + }; } #endif // end GCN_EXCEPTION_HPP diff --git a/external/libguisan/include/guisan/focushandler.hpp b/external/libguisan/include/guisan/focushandler.hpp index f9fdd90b..aa67b81c 100644 --- a/external/libguisan/include/guisan/focushandler.hpp +++ b/external/libguisan/include/guisan/focushandler.hpp @@ -64,259 +64,260 @@ namespace gcn { - class Widget; + class Widget; - /** - * Used to keep track of widget focus. You will probably not have - * to use the FocusHandler directly to handle focus. Widget has - * functions for handling focus which uses a FocusHandler. Use them - * instead. - * - * @see Widget::isFocused - * @see Widget::requestFocus - * @see Widget::setFocusable - * @see Widget::isFocusable - * @see FocusListener - */ - class GCN_CORE_DECLSPEC FocusHandler - { - public: + /** + * Used to keep track of widget focus. You will probably not have + * to use the FocusHandler directly to handle focus. Widget has + * functions for handling focus which uses a FocusHandler. Use them + * instead. + * + * @see Widget::isFocused + * @see Widget::requestFocus + * @see Widget::setFocusable + * @see Widget::isFocusable + * @see FocusListener + */ + class GCN_CORE_DECLSPEC FocusHandler + { + public: - /** - * Constructor. - */ - FocusHandler(); + /** + * Constructor. + */ + FocusHandler(); - /** - * Destructor. - */ - virtual ~FocusHandler() { }; + /** + * Destructor. + */ + virtual ~FocusHandler() + = default;; - /** - * Sets focus to a widget. A focus event will also be sent to the widget's - * focus listeners. - * - * @param widget the widget to focus. - */ - virtual void requestFocus(Widget* widget); + /** + * Sets focus to a widget. A focus event will also be sent to the widget's + * focus listeners. + * + * @param widget the widget to focus. + */ + virtual void requestFocus(Widget* widget); - /** - * Sets modal focus to a widget. - * - * @param widget the Widget to focus modal. - * @throws Exception when another widget already has modal focus. - */ - virtual void requestModalFocus(Widget* widget); + /** + * Sets modal focus to a widget. + * + * @param widget the Widget to focus modal. + * @throws Exception when another widget already has modal focus. + */ + virtual void requestModalFocus(Widget* widget); - /** - * Releases modal focus if the widget has modal focus. - * Otherwise nothing will be done. - * - * @param widget the Widget to release modal focus for. - */ - virtual void releaseModalFocus(Widget* widget); + /** + * Releases modal focus if the widget has modal focus. + * Otherwise nothing will be done. + * + * @param widget the Widget to release modal focus for. + */ + virtual void releaseModalFocus(Widget* widget); - /** - * Sets modal mouse input focus to a widget. Modal mouse input focus means - * no other widget then the widget with modal mouse input focus will - * receive mouse input.. - * The widget with modal mouse input focus will also receive mouse input no - * matter what the mouse input is or where the mouse input occurs. - * - * @param widget the widget to focus for modal mouse input focus. - * @throws Exception when another widget already has modal mouse input focus. - */ - virtual void requestModalMouseInputFocus(Widget* widget); + /** + * Sets modal mouse input focus to a widget. Modal mouse input focus means + * no other widget then the widget with modal mouse input focus will + * receive mouse input.. + * The widget with modal mouse input focus will also receive mouse input no + * matter what the mouse input is or where the mouse input occurs. + * + * @param widget the widget to focus for modal mouse input focus. + * @throws Exception when another widget already has modal mouse input focus. + */ + virtual void requestModalMouseInputFocus(Widget* widget); - /** - * Releases modal mouse input focus if the widget has modal mouse input - * focus. Otherwise nothing will be done. - * - * @param widget the widget to release modal mouse input focus for. - */ - virtual void releaseModalMouseInputFocus(Widget* widget); + /** + * Releases modal mouse input focus if the widget has modal mouse input + * focus. Otherwise nothing will be done. + * + * @param widget the widget to release modal mouse input focus for. + */ + virtual void releaseModalMouseInputFocus(Widget* widget); - /** - * Gets the widget with focus. - * - * @return the Widget with focus. NULL will be returned if - * no Widget has focus. - */ - virtual Widget* getFocused() const; + /** + * Gets the widget with focus. + * + * @return the Widget with focus. NULL will be returned if + * no Widget has focus. + */ + [[nodiscard]] virtual Widget* getFocused() const; - /** - * Gets the widget with modal focus. - * - * @return the Widget with modal focus. NULL will be returned - * if no Widget has modal focus. - */ - virtual Widget* getModalFocused() const; + /** + * Gets the widget with modal focus. + * + * @return the Widget with modal focus. NULL will be returned + * if no Widget has modal focus. + */ + [[nodiscard]] virtual Widget* getModalFocused() const; - /** - * Gets the widget with modal mouse input focus. - * - * @return the widget with modal mouse input focus. NULL will be returned - * if no widget has modal mouse input focus. - */ - virtual Widget* getModalMouseInputFocused() const; + /** + * Gets the widget with modal mouse input focus. + * + * @return the widget with modal mouse input focus. NULL will be returned + * if no widget has modal mouse input focus. + */ + [[nodiscard]] virtual Widget* getModalMouseInputFocused() const; - /** - * Focuses the next Widget. If no Widget has focus the first - * Widget gets focus. The order in which the Widgets are focused - * depends on the order you add them to the GUI. - */ - virtual void focusNext(); + /** + * Focuses the next Widget. If no Widget has focus the first + * Widget gets focus. The order in which the Widgets are focused + * depends on the order you add them to the GUI. + */ + virtual void focusNext(); - /** - * Focuses the previous Widget. If no Widget has focus the first - * Widget gets focus. The order in which the widgets are focused - * depends on the order you add them to the GUI. - */ - virtual void focusPrevious(); + /** + * Focuses the previous Widget. If no Widget has focus the first + * Widget gets focus. The order in which the widgets are focused + * depends on the order you add them to the GUI. + */ + virtual void focusPrevious(); - /** - * Checks if a Widget is focused. - * - * @param widget widget to check if it is focused. - * @return true if the widget is focused. - */ - virtual bool isFocused(const Widget* widget) const; + /** + * Checks if a Widget is focused. + * + * @param widget widget to check if it is focused. + * @return true if the widget is focused. + */ + virtual bool isFocused(const Widget* widget) const; - /** - * Adds a widget to the FocusHandler. - * - * @param widget the widget to add. - */ - virtual void add(Widget* widget); + /** + * Adds a widget to the FocusHandler. + * + * @param widget the widget to add. + */ + virtual void add(Widget* widget); - /** - * Removes a widget from the FocusHandler. - * - * @param widget the widget to remove. - */ - virtual void remove(Widget* widget); + /** + * Removes a widget from the FocusHandler. + * + * @param widget the widget to remove. + */ + virtual void remove(Widget* widget); - /** - * Focuses nothing. A focus event will also be sent to the focused widget's - * focus listeners if a widget has focus. - */ - virtual void focusNone(); + /** + * Focuses nothing. A focus event will also be sent to the focused widget's + * focus listeners if a widget has focus. + */ + virtual void focusNone(); - /** - * Focuses the next Widget which allows tab in unless current focused - * Widget disallows tab out. - */ - virtual void tabNext(); + /** + * Focuses the next Widget which allows tab in unless current focused + * Widget disallows tab out. + */ + virtual void tabNext(); - /** - * Focuses the previous Widget which allows tab in unless current focused - * Widget disallows tab out. - */ - virtual void tabPrevious(); + /** + * Focuses the previous Widget which allows tab in unless current focused + * Widget disallows tab out. + */ + virtual void tabPrevious(); - /** - * Gets the widget being dragged. - * - * @return the widget being dragged. - */ - virtual Widget* getDraggedWidget(); + /** + * Gets the widget being dragged. + * + * @return the widget being dragged. + */ + virtual Widget* getDraggedWidget(); - /** - * Sets the widget being dragged. - * - * @param draggedWidget the widget being dragged. - */ - virtual void setDraggedWidget(Widget* draggedWidget); + /** + * Sets the widget being dragged. + * + * @param draggedWidget the widget being dragged. + */ + virtual void setDraggedWidget(Widget* draggedWidget); - /** - * Gets the last widget with the mouse. - * - * @return the last widget with the mouse. - */ - virtual Widget* getLastWidgetWithMouse(); + /** + * Gets the last widget with the mouse. + * + * @return the last widget with the mouse. + */ + virtual Widget* getLastWidgetWithMouse(); - /** - * Sets the last widget with the mouse. - * - * @param lastWidgetWithMouse the last widget with the mouse. - */ - virtual void setLastWidgetWithMouse(Widget* lastWidgetWithMouse); + /** + * Sets the last widget with the mouse. + * + * @param lastWidgetWithMouse the last widget with the mouse. + */ + virtual void setLastWidgetWithMouse(Widget* lastWidgetWithMouse); - /** - * Gets the last widget with modal focus. - * - * @return the last widget with modal focus. - */ - virtual Widget* getLastWidgetWithModalFocus(); + /** + * Gets the last widget with modal focus. + * + * @return the last widget with modal focus. + */ + virtual Widget* getLastWidgetWithModalFocus(); - /** - * Sets the last widget with modal focus. - * - * @param lastWidgetWithModalFocus the last widget with modal focus. - */ - virtual void setLastWidgetWithModalFocus(Widget* lastWidgetWithModalFocus); + /** + * Sets the last widget with modal focus. + * + * @param lastWidgetWithModalFocus the last widget with modal focus. + */ + virtual void setLastWidgetWithModalFocus(Widget* lastWidgetWithModalFocus); - /** - * Gets the last widget with modal mouse input focus. - * - * @return the last widget with modal mouse input focus. - */ - virtual Widget* getLastWidgetWithModalMouseInputFocus(); + /** + * Gets the last widget with modal mouse input focus. + * + * @return the last widget with modal mouse input focus. + */ + virtual Widget* getLastWidgetWithModalMouseInputFocus(); - /** - * Sets the last widget with modal mouse input focus. - * - * @param lastMouseWithModalMouseInputFocus the last widget with modal mouse input focus. - */ - virtual void setLastWidgetWithModalMouseInputFocus(Widget* lastWidgetWithModalMouseInputFocus); + /** + * Sets the last widget with modal mouse input focus. + * + * @param lastWidgetWithModalMouseInputFocus the last widget with modal mouse input focus. + */ + virtual void setLastWidgetWithModalMouseInputFocus(Widget* lastWidgetWithModalMouseInputFocus); - /** - * Gets the last widget pressed. - * - * @return the last widget pressed. - */ - virtual Widget* getLastWidgetPressed(); + /** + * Gets the last widget pressed. + * + * @return the last widget pressed. + */ + virtual Widget* getLastWidgetPressed(); - /** - * Sets the last widget pressed. - * - * @param lastWidgetPressed the last widget pressed. - */ - virtual void setLastWidgetPressed(Widget* lastWidgetPressed); + /** + * Sets the last widget pressed. + * + * @param lastWidgetPressed the last widget pressed. + */ + virtual void setLastWidgetPressed(Widget* lastWidgetPressed); - protected: - /** - * Distributes a focus lost event. - * - * @param focusEvent the event to distribute. - * @author Olof Naessén - * @since 0.7.0 - */ - virtual void distributeFocusLostEvent(const Event& focusEvent); + protected: + /** + * Distributes a focus lost event. + * + * @param focusEvent the event to distribute. + * @author Olof Naessén + * @since 0.7.0 + */ + virtual void distributeFocusLostEvent(const Event& focusEvent); - /** - * Distributes a focus gained event. - * - * @param focusEvent the event to distribute. - * @author Olof Naessén - * @since 0.7.0 - */ - virtual void distributeFocusGainedEvent(const Event& focusEvent); + /** + * Distributes a focus gained event. + * + * @param focusEvent the event to distribute. + * @author Olof Naessén + * @since 0.7.0 + */ + virtual void distributeFocusGainedEvent(const Event& focusEvent); - typedef std::vector WidgetVector; - typedef WidgetVector::iterator WidgetIterator; - WidgetVector mWidgets; + typedef std::vector WidgetVector; + typedef WidgetVector::iterator WidgetIterator; + WidgetVector mWidgets; - Widget* mFocusedWidget; - Widget* mModalFocusedWidget; - Widget* mModalMouseInputFocusedWidget; + Widget* mFocusedWidget; + Widget* mModalFocusedWidget; + Widget* mModalMouseInputFocusedWidget; - Widget* mDraggedWidget; - Widget* mLastWidgetWithMouse; - Widget* mLastWidgetWithModalFocus; - Widget* mLastWidgetWithModalMouseInputFocus; - Widget* mLastWidgetPressed; - }; + Widget* mDraggedWidget; + Widget* mLastWidgetWithMouse; + Widget* mLastWidgetWithModalFocus; + Widget* mLastWidgetWithModalMouseInputFocus; + Widget* mLastWidgetPressed; + }; } #endif // end GCN_FOCUSHANDLER_HPP diff --git a/external/libguisan/include/guisan/focuslistener.hpp b/external/libguisan/include/guisan/focuslistener.hpp index e57a8e87..98788e58 100644 --- a/external/libguisan/include/guisan/focuslistener.hpp +++ b/external/libguisan/include/guisan/focuslistener.hpp @@ -57,45 +57,48 @@ #ifndef GCN_FOCUSLISTENER_HPP #define GCN_FOCUSLISTENER_HPP -#include - #include "guisan/event.hpp" #include "guisan/platform.hpp" namespace gcn { - /** - * Listener of focus events from Widgets. To be able to listen for - * focus events you must make a class which inherits from this class - * and implements it's functions. - * - * @see Widget::addFocusListener - * @author Olof Naessén - * @since 0.7.0 - */ - class GCN_CORE_DECLSPEC FocusListener - { - public: + /** + * Listener of focus events from Widgets. To be able to listen for + * focus events you must make a class which inherits from this class + * and implements it's functions. + * + * @see Widget::addFocusListener + * @author Olof Naessén + * @since 0.7.0 + */ + class GCN_CORE_DECLSPEC FocusListener + { + public: - /** - * Destructor. - */ - virtual ~FocusListener() { } + /** + * Destructor. + */ + virtual ~FocusListener() + = default; - /** - * Called when a widget gains focus. - * - * @param event discribes the event. - */ - virtual void focusGained(const Event& event) { }; + /** + * Called when a widget gains focus. + * + * @param event describes the event. + */ + virtual void focusGained(const Event& event) + { + }; - /** - * Called when a widget loses focus. - * - * @param event discribes the event. - */ - virtual void focusLost(const Event& event) { }; - }; + /** + * Called when a widget loses focus. + * + * @param event discribes the event. + */ + virtual void focusLost(const Event& event) + { + }; + }; } #endif // end GCN_FOCUSLISTENER_HPP diff --git a/external/libguisan/include/guisan/font.hpp b/external/libguisan/include/guisan/font.hpp index 7ea02cd2..72492c05 100644 --- a/external/libguisan/include/guisan/font.hpp +++ b/external/libguisan/include/guisan/font.hpp @@ -62,64 +62,64 @@ namespace gcn { - class Graphics; + class Graphics; - /** - * Holder of a font. Fonts should inherit from this class and - * implements it's functions. - * - * @see ImageFont - */ - class GCN_CORE_DECLSPEC Font - { - public: + /** + * Holder of a font. Fonts should inherit from this class and + * implements it's functions. + * + * @see ImageFont + */ + class GCN_CORE_DECLSPEC Font + { + public: - /** - * Destructor. - */ - virtual ~Font(){ } + /** + * Destructor. + */ + virtual ~Font() = default; - /** - * Gets the width of a string. The width of a string is not necesserily - * the sum of all the widths of it's glyphs. - * - * @param text the string to return the width of. - * @return the width of a string. - */ - virtual int getWidth(const std::string& text) const = 0; + /** + * Gets the width of a string. The width of a string is not necesserily + * the sum of all the widths of it's glyphs. + * + * @param text the string to return the width of. + * @return the width of a string. + */ + [[nodiscard]] virtual int getWidth(const std::string& text) const = 0; - /** - * Gets the height of the glyphs in the font. - * - * @return the height of the glyphs int the font. - */ - virtual int getHeight() const = 0; + /** + * Gets the height of the glyphs in the font. + * + * @return the height of the glyphs int the font. + */ + [[nodiscard]] virtual int getHeight() const = 0; - /** - * Gets a string index in a string providing an x coordinate. - * Used to retrive a string index (for a character in a - * string) at a certain x position. It is especially useful - * when a mouse clicks in a TextField and you want to know which - * character was clicked. - * - * @return a string index in a string providing an x coordinate. - */ - virtual int getStringIndexAt(const std::string& text, int x); + /** + * Gets a string index in a string providing an x coordinate. + * Used to retrive a string index (for a character in a + * string) at a certain x position. It is especially useful + * when a mouse clicks in a TextField and you want to know which + * character was clicked. + * + * @return a string index in a string providing an x coordinate. + */ + virtual int getStringIndexAt(const std::string& text, int x); - /** - * Draws a string. - * - * NOTE: You normally won't use this function to draw text since - * Graphics contains better functions for drawing text. - * - * @param graphics a Graphics object to use for drawing. - * @param text the string to draw. - * @param x the x coordinate where to draw the string. - * @param y the y coordinate where to draw the string. - */ - virtual void drawString(Graphics* graphics, const std::string& text, - int x, int y) = 0; - }; + /** + * Draws a string. + * + * NOTE: You normally won't use this function to draw text since + * Graphics contains better functions for drawing text. + * + * @param graphics a Graphics object to use for drawing. + * @param text the string to draw. + * @param x the x coordinate where to draw the string. + * @param y the y coordinate where to draw the string. + */ + virtual void drawString(Graphics* graphics, const std::string& text, + int x, int y) = 0; + }; } #endif // end GCN_FONT_HPP diff --git a/external/libguisan/include/guisan/genericinput.hpp b/external/libguisan/include/guisan/genericinput.hpp index 54e28d1a..04bbca27 100644 --- a/external/libguisan/include/guisan/genericinput.hpp +++ b/external/libguisan/include/guisan/genericinput.hpp @@ -66,103 +66,103 @@ namespace gcn { - class Key; - - /** - * Generic input which can be used with any backend. - */ - class GCN_CORE_DECLSPEC GenericInput: public Input - { - public: + class Key; - /** - * Constructor. - */ - GenericInput(); + /** + * Generic input which can be used with any backend. + */ + class GCN_CORE_DECLSPEC GenericInput : public Input + { + public: - /** - * Pushes a key pressed event. - * - * NOTE: If a special key is pressed, like the F1 key, - * the corresponding Guichan key value found - * in the enum in Key should be pushed as the - * unicode value. - * - * @param unicode the unicode value of the key. - */ - void pushKeyPressed(int unicode); + /** + * Constructor. + */ + GenericInput(); - /** - * Pushes a key released event. - * - * NOTE: If a special key is pressed, like the F1 key, - * the corresponding Guichan key value found - * in the enum in Key should be pushed as the - * unicode value. - * - * @param unicode the unicode value of the key. - */ - void pushKeyReleased(int unicode); - - /** - * Pushes a mouse button pressed event. - * - * @param x the x coordinate of the mouse event. - * @param y the y coordinate of the mouse event. - * @param button the button of the mouse event. - */ - void pushMouseButtonPressed(int x, int y, int button); + /** + * Pushes a key pressed event. + * + * NOTE: If a special key is pressed, like the F1 key, + * the corresponding Guichan key value found + * in the enum in Key should be pushed as the + * unicode value. + * + * @param unicode the unicode value of the key. + */ + void pushKeyPressed(int unicode); - /** - * Pushes a mouse button released event. - * - * @param x the x coordinate of the mouse event. - * @param y the y coordinate of the mouse event. - * @param button the button of the mouse event. - */ - void pushMouseButtonReleased(int x, int y, int button); - - /** - * Pushes a mouse wheel moved up event. - * - * @param x the x coordinate of the mouse event. - * @param y the y coordinate of the mouse event. - */ - void pushMouseWheelMovedUp(int x, int y); - - /** - * Pushes a mouse wheel moved down event. - * - * @param x the x coordinate of the mouse event. - * @param y the y coordinate of the mouse event. - */ - void pushMouseWheelMovedDown(int x, int y); + /** + * Pushes a key released event. + * + * NOTE: If a special key is pressed, like the F1 key, + * the corresponding Guichan key value found + * in the enum in Key should be pushed as the + * unicode value. + * + * @param unicode the unicode value of the key. + */ + void pushKeyReleased(int unicode); - /** - * Pushes a mouse moved event. - * - * @param x the x coordinate of the mouse event. - * @param y the y coordinate of the mouse event. - */ - void pushMouseMoved(int x, int y); + /** + * Pushes a mouse button pressed event. + * + * @param x the x coordinate of the mouse event. + * @param y the y coordinate of the mouse event. + * @param button the button of the mouse event. + */ + void pushMouseButtonPressed(int x, int y, int button); - - // Inherited from Input + /** + * Pushes a mouse button released event. + * + * @param x the x coordinate of the mouse event. + * @param y the y coordinate of the mouse event. + * @param button the button of the mouse event. + */ + void pushMouseButtonReleased(int x, int y, int button); - virtual bool isKeyQueueEmpty(); + /** + * Pushes a mouse wheel moved up event. + * + * @param x the x coordinate of the mouse event. + * @param y the y coordinate of the mouse event. + */ + void pushMouseWheelMovedUp(int x, int y); - virtual KeyInput dequeueKeyInput(); + /** + * Pushes a mouse wheel moved down event. + * + * @param x the x coordinate of the mouse event. + * @param y the y coordinate of the mouse event. + */ + void pushMouseWheelMovedDown(int x, int y); - virtual bool isMouseQueueEmpty(); + /** + * Pushes a mouse moved event. + * + * @param x the x coordinate of the mouse event. + * @param y the y coordinate of the mouse event. + */ + void pushMouseMoved(int x, int y); - virtual MouseInput dequeueMouseInput(); - virtual void _pollInput(); + // Inherited from Input - protected: - std::queue mKeyInputQueue; - std::queue mMouseInputQueue; - }; + bool isKeyQueueEmpty() override; + + KeyInput dequeueKeyInput() override; + + bool isMouseQueueEmpty() override; + + MouseInput dequeueMouseInput() override; + + void _pollInput() override; + + protected: + std::queue mKeyInputQueue; + std::queue mMouseInputQueue; + }; } #endif // end GCN_INPUT_HPP diff --git a/external/libguisan/include/guisan/glut.hpp b/external/libguisan/include/guisan/glut.hpp index 59c5647d..40a9da8e 100644 --- a/external/libguisan/include/guisan/glut.hpp +++ b/external/libguisan/include/guisan/glut.hpp @@ -61,12 +61,11 @@ #include "platform.hpp" -extern "C" -{ - /** - * Exists to be able to check for Guichan GLUT with autotools. - */ - GCN_EXTENSION_DECLSPEC extern void gcnGLUT(); +extern "C" { +/** + * Exists to be able to check for Guichan GLUT with autotools. + */ +GCN_EXTENSION_DECLSPEC extern void gcnGLUT(); } #endif // end GCN_GLUT_HPP diff --git a/external/libguisan/include/guisan/graphics.hpp b/external/libguisan/include/guisan/graphics.hpp index 0e06384f..194d9514 100644 --- a/external/libguisan/include/guisan/graphics.hpp +++ b/external/libguisan/include/guisan/graphics.hpp @@ -66,209 +66,215 @@ namespace gcn { - class Color; - class Font; - class Image; + class Color; + class Font; + class Image; - /** - * Used for drawing graphics. It contains all vital functions for drawing. - * We include implemented Graphics classes for some common platforms like - * the Allegro library, the OpenGL library and the SDL library. To make - * Guichan usable under another platform, a Graphics class must be - * implemented. - * - * In Graphics you can set clip areas to limit drawing to certain - * areas of the screen. Clip areas are put on a stack, which means that you - * can push smaller and smaller clip areas onto the stack. All coordinates - * will be relative to the topmost clip area. In most cases you won't have - * to worry about the clip areas, unless you want to implement some really - * complex widget. Pushing and poping of clip areas are handled - * automatically by container widgets when their child widgets are drawn. - * - * IMPORTANT: Remember to pop each clip area that you pushed on the stack - * after you are done with it. - * - * If you feel that Graphics is to restrictive for your needs, there is - * no one stopping you from using your own code for drawing in Widgets. - * You could for instance use pure SDL in the drawing of Widgets bypassing - * Graphics. This might however hurt portability of your application. - * - * If you implement a Graphics class not present in Guichan we would be very - * happy to add it to Guichan. - * - * @see AllegroGraphics, OpenGLGraphics, SDLGraphics, Image - */ - class GCN_CORE_DECLSPEC Graphics - { - public: - Graphics(); + /** + * Used for drawing graphics. It contains all vital functions for drawing. + * We include implemented Graphics classes for some common platforms like + * the Allegro library, the OpenGL library and the SDL library. To make + * Guichan usable under another platform, a Graphics class must be + * implemented. + * + * In Graphics you can set clip areas to limit drawing to certain + * areas of the screen. Clip areas are put on a stack, which means that you + * can push smaller and smaller clip areas onto the stack. All coordinates + * will be relative to the topmost clip area. In most cases you won't have + * to worry about the clip areas, unless you want to implement some really + * complex widget. Pushing and poping of clip areas are handled + * automatically by container widgets when their child widgets are drawn. + * + * IMPORTANT: Remember to pop each clip area that you pushed on the stack + * after you are done with it. + * + * If you feel that Graphics is to restrictive for your needs, there is + * no one stopping you from using your own code for drawing in Widgets. + * You could for instance use pure SDL in the drawing of Widgets bypassing + * Graphics. This might however hurt portability of your application. + * + * If you implement a Graphics class not present in Guichan we would be very + * happy to add it to Guichan. + * + * @see AllegroGraphics, OpenGLGraphics, SDLGraphics, Image + */ + class GCN_CORE_DECLSPEC Graphics + { + public: + Graphics(); - virtual ~Graphics() { } + virtual ~Graphics() + = default; - /** - * Initializes drawing. Called by the Gui when Gui::draw() is called. - * It is needed by some implementations of Graphics to perform - * preparations before drawing. An example of such an implementation - * would be OpenGLGraphics. - * - * NOTE: You will never need to call this function yourself. - * Gui will do it for you. - * - * @see _endDraw, Gui::draw - */ - virtual void _beginDraw() { } + /** + * Initializes drawing. Called by the Gui when Gui::draw() is called. + * It is needed by some implementations of Graphics to perform + * preparations before drawing. An example of such an implementation + * would be OpenGLGraphics. + * + * NOTE: You will never need to call this function yourself. + * Gui will do it for you. + * + * @see _endDraw, Gui::draw + */ + virtual void _beginDraw() + { + } - /** - * Deinitializes drawing. Called by the Gui when a Gui::draw() is done. - * done. It should reset any state changes made by _beginDraw(). - * - * NOTE: You will never need to call this function yourself. - * Gui will do it for you. - * - * @see _beginDraw, Gui::draw - */ - virtual void _endDraw() { } + /** + * Deinitializes drawing. Called by the Gui when a Gui::draw() is done. + * done. It should reset any state changes made by _beginDraw(). + * + * NOTE: You will never need to call this function yourself. + * Gui will do it for you. + * + * @see _beginDraw, Gui::draw + */ + virtual void _endDraw() + { + } - /** - * Pushes a clip area onto the stack. The x and y coordinates in the - * Rectangle will be relative to the last pushed clip area. - * If the new area falls outside the current clip area, it will be - * clipped as necessary. - * - * @param area the clip area to be pushed onto the stack. - * @return false if the the new area lays totally outside the - * current clip area. Note that an empty clip area - * will be pused in this case. - */ - virtual bool pushClipArea(Rectangle area); + /** + * Pushes a clip area onto the stack. The x and y coordinates in the + * Rectangle will be relative to the last pushed clip area. + * If the new area falls outside the current clip area, it will be + * clipped as necessary. + * + * @param area the clip area to be pushed onto the stack. + * @return false if the the new area lays totally outside the + * current clip area. Note that an empty clip area + * will be pused in this case. + */ + virtual bool pushClipArea(Rectangle area); - /** - * Removes the topmost clip area from the stack. - * - * @throws Exception if the stack is empty. - */ - virtual void popClipArea(); + /** + * Removes the topmost clip area from the stack. + * + * @throws Exception if the stack is empty. + */ + virtual void popClipArea(); - /** - * Gets the current clip area. Usefull if you want to do drawing - * bypassing Graphics. - * - * @return the current clip area. - */ - virtual const ClipRectangle& getCurrentClipArea(); + /** + * Gets the current clip area. Usefull if you want to do drawing + * bypassing Graphics. + * + * @return the current clip area. + */ + virtual const ClipRectangle& getCurrentClipArea(); - /** - * Draws a part of an Image. - * - * NOTE: Width and height arguments will not scale the Image but - * specifies the size of the part to be drawn. If you want - * to draw the whole Image there is a simplified version of - * this function. - * - * EXAMPLE: @code drawImage(myImage, 10, 10, 20, 20, 40, 40); @endcode - * Will draw a rectangular piece of myImage starting at - * coordinate (10, 10) in myImage, with width and height 40. - * The piece will be drawn with it's top left corner at - * coordinate (20, 20). - * - * @param image the Image to draw. - * @param srcX source Image x coordinate. - * @param srcY source Image y coordinate. - * @param dstX destination x coordinate. - * @param dstY destination y coordinate. - * @param width the width of the piece. - * @param height the height of the piece. - */ - virtual void drawImage(const Image* image, int srcX, int srcY, - int dstX, int dstY, int width, - int height) = 0; - /** - * Draws an image. A simplified version of the other drawImage. - * It will draw a whole image at the coordinate you specify. - * It is equivalent to calling: - * @code drawImage(myImage, 0, 0, dstX, dstY, image->getWidth(), \ - image->getHeight()); @endcode - */ - virtual void drawImage(const Image* image, int dstX, int dstY); + /** + * Draws a part of an Image. + * + * NOTE: Width and height arguments will not scale the Image but + * specifies the size of the part to be drawn. If you want + * to draw the whole Image there is a simplified version of + * this function. + * + * EXAMPLE: @code drawImage(myImage, 10, 10, 20, 20, 40, 40); @endcode + * Will draw a rectangular piece of myImage starting at + * coordinate (10, 10) in myImage, with width and height 40. + * The piece will be drawn with it's top left corner at + * coordinate (20, 20). + * + * @param image the Image to draw. + * @param srcX source Image x coordinate. + * @param srcY source Image y coordinate. + * @param dstX destination x coordinate. + * @param dstY destination y coordinate. + * @param width the width of the piece. + * @param height the height of the piece. + */ + virtual void drawImage(const Image* image, int srcX, int srcY, + int dstX, int dstY, int width, + int height) = 0; + /** + * Draws an image. A simplified version of the other drawImage. + * It will draw a whole image at the coordinate you specify. + * It is equivalent to calling: + * @code drawImage(myImage, 0, 0, dstX, dstY, image->getWidth(), \ + image->getHeight()); @endcode + */ + virtual void drawImage(const Image* image, int dstX, int dstY); - /** - * Draws a single point/pixel. - * - * @param x the x coordinate. - * @param y the y coordinate. - */ - virtual void drawPoint(int x, int y) = 0; + /** + * Draws a single point/pixel. + * + * @param x the x coordinate. + * @param y the y coordinate. + */ + virtual void drawPoint(int x, int y) = 0; - /** - * Ddraws a line. - * - * @param x1 the first x coordinate. - * @param y1 the first y coordinate. - * @param x2 the second x coordinate. - * @param y2 the second y coordinate. - */ - virtual void drawLine(int x1, int y1, int x2, int y2) = 0; + /** + * Ddraws a line. + * + * @param x1 the first x coordinate. + * @param y1 the first y coordinate. + * @param x2 the second x coordinate. + * @param y2 the second y coordinate. + */ + virtual void drawLine(int x1, int y1, int x2, int y2) = 0; - /** - * Draws a simple, non-filled, Rectangle with one pixel width. - * - * @param rectangle the Rectangle to draw. - */ - virtual void drawRectangle(const Rectangle& rectangle) = 0; + /** + * Draws a simple, non-filled, Rectangle with one pixel width. + * + * @param rectangle the Rectangle to draw. + */ + virtual void drawRectangle(const Rectangle& rectangle) = 0; - /** - * Draws a filled Rectangle. - * - * @param rectangle the filled Rectangle to draw. - */ - virtual void fillRectangle(const Rectangle& rectangle) = 0; + /** + * Draws a filled Rectangle. + * + * @param rectangle the filled Rectangle to draw. + */ + virtual void fillRectangle(const Rectangle& rectangle) = 0; - /** - * Sets the Color to use when drawing. - * - * @param color a Color. - */ - virtual void setColor(const Color& color) = 0; + /** + * Sets the Color to use when drawing. + * + * @param color a Color. + */ + virtual void setColor(const Color& color) = 0; - /** - * Gets the Color to use when drawing. - * - * @return the Color used when drawing. - */ - virtual const Color& getColor() = 0; + /** + * Gets the Color to use when drawing. + * + * @return the Color used when drawing. + */ + virtual const Color& getColor() = 0; - /** - * Sets the font to use when drawing text. - * - * @param font the Font to use when drawing. - */ - virtual void setFont(Font* font); + /** + * Sets the font to use when drawing text. + * + * @param font the Font to use when drawing. + */ + virtual void setFont(Font* font); - /** - * Draws text. - * - * @param text the text to draw. - * @param x the x coordinate where to draw the text. - * @param y the y coordinate where to draw the text. - * @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. - * @throws Exception when no Font is set. - */ - virtual void drawText(const std::string& text, int x, int y, - unsigned int alignment = LEFT); - /** - * Alignments for text drawing. - */ - enum - { - LEFT = 0, - CENTER, - RIGHT - }; + /** + * Draws text. + * + * @param text the text to draw. + * @param x the x coordinate where to draw the text. + * @param y the y coordinate where to draw the text. + * @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. + * @throws Exception when no Font is set. + */ + virtual void drawText(const std::string& text, int x, int y, + unsigned int alignment = LEFT); - protected: - std::stack mClipStack; - Font* mFont; - }; + /** + * Alignments for text drawing. + */ + enum + { + LEFT = 0, + CENTER, + RIGHT + }; + + protected: + std::stack mClipStack; + Font* mFont; + }; } #endif // end GCN_GRAPHICS_HPP @@ -278,4 +284,3 @@ namespace gcn * finalman - "skall jag skriva det?" * yakslem - "ja, varfor inte?" */ - diff --git a/external/libguisan/include/guisan/gui.hpp b/external/libguisan/include/guisan/gui.hpp index 5323173e..23f91a44 100644 --- a/external/libguisan/include/guisan/gui.hpp +++ b/external/libguisan/include/guisan/gui.hpp @@ -67,329 +67,329 @@ namespace gcn { - class FocusHandler; - class Graphics; - class Input; - class KeyListener; - class Widget; + class FocusHandler; + class Graphics; + class Input; + class KeyListener; + class Widget; - // The following comment will appear in the doxygen main page. - /** - * @mainpage - * @section Introduction - * This documentation is mostly intended as a reference to the API. If you want to get started with Guichan, we suggest you check out the programs in the examples directory of the Guichan release. - * @n - * @n - * This documentation is, and will always be, work in progress. If you find any errors, typos or inconsistencies, or if you feel something needs to be explained in more detail - don't hesitate to tell us. - */ + // The following comment will appear in the doxygen main page. + /** + * @mainpage + * @section Introduction + * This documentation is mostly intended as a reference to the API. If you want to get started with Guichan, we suggest you check out the programs in the examples directory of the Guichan release. + * @n + * @n + * This documentation is, and will always be, work in progress. If you find any errors, typos or inconsistencies, or if you feel something needs to be explained in more detail - don't hesitate to tell us. + */ - /** - * Gui core class. Contains a special widget called the top widget. - * If you want to be able to have more then one Widget in your Gui, - * the top widget should be a Container. - * - * NOTE: For the Gui to function properly you need to set a Graphics - * object to use and an Input object to use. - */ - class GCN_CORE_DECLSPEC Gui - { - public: + /** + * Gui core class. Contains a special widget called the top widget. + * If you want to be able to have more then one Widget in your Gui, + * the top widget should be a Container. + * + * NOTE: For the Gui to function properly you need to set a Graphics + * object to use and an Input object to use. + */ + class GCN_CORE_DECLSPEC Gui + { + public: - /** - * Constructor. - */ - Gui(); + /** + * Constructor. + */ + Gui(); - /** - * Destructor. - */ - virtual ~Gui(); + /** + * Destructor. + */ + virtual ~Gui(); - /** - * Sets the top Widget. - * - * @param top the top Widget. - */ - virtual void setTop(Widget* top); + /** + * Sets the top Widget. + * + * @param top the top Widget. + */ + virtual void setTop(Widget* top); - /** - * Gets the top Widget. - * - * @return the top widget. NULL if no top widget has been set. - */ - virtual Widget* getTop() const; + /** + * Gets the top Widget. + * + * @return the top widget. NULL if no top widget has been set. + */ + [[nodiscard]] virtual Widget* getTop() const; - /** - * Sets the Graphics object to use for drawing. - * - * @param graphics the Graphics object to use for drawing. - * @see SDLGraphics, OpenGLGraphics, AllegroGraphics - */ - virtual void setGraphics(Graphics* graphics); + /** + * Sets the Graphics object to use for drawing. + * + * @param graphics the Graphics object to use for drawing. + * @see SDLGraphics, OpenGLGraphics, AllegroGraphics + */ + virtual void setGraphics(Graphics* graphics); - /** - * Gets the Graphics object used for drawing. - * - * @return the Graphics object used for drawing. NULL if no - * Graphics object has been set. - */ - virtual Graphics* getGraphics() const; + /** + * Gets the Graphics object used for drawing. + * + * @return the Graphics object used for drawing. NULL if no + * Graphics object has been set. + */ + [[nodiscard]] virtual Graphics* getGraphics() const; - /** - * Sets the Input object to use for input handling. - * - * @param input the Input object to use for input handling. - * @see SDLInput, AllegroInput - */ - virtual void setInput(Input* input); + /** + * Sets the Input object to use for input handling. + * + * @param input the Input object to use for input handling. + * @see SDLInput, AllegroInput + */ + virtual void setInput(Input* input); - /** - * Gets the Input object being used for input handling. - * - * @return the Input object used for handling input. NULL if no - * Input object has been set. - */ - virtual Input* getInput() const; + /** + * Gets the Input object being used for input handling. + * + * @return the Input object used for handling input. NULL if no + * Input object has been set. + */ + [[nodiscard]] virtual Input* getInput() const; - /** - * Performs the Gui logic. By calling this function all logic - * functions down in the Gui heirarchy will be called. - * What performs in Logic can be just about anything like - * adjusting a Widgets size or doing some calculations. - * - * NOTE: Logic also deals with user input (Mouse and Keyboard) - * for Widgets. - */ - virtual void logic(); + /** + * Performs the Gui logic. By calling this function all logic + * functions down in the Gui heirarchy will be called. + * What performs in Logic can be just about anything like + * adjusting a Widgets size or doing some calculations. + * + * NOTE: Logic also deals with user input (Mouse and Keyboard) + * for Widgets. + */ + virtual void logic(); - /** - * Draws the Gui. By calling this funcion all draw functions - * down in the Gui hierarchy will be called. - */ - virtual void draw(); + /** + * Draws the Gui. By calling this funcion all draw functions + * down in the Gui hierarchy will be called. + */ + virtual void draw(); - /** - * Focus none of the Widgets in the Gui. - */ - virtual void focusNone(); + /** + * Focus none of the Widgets in the Gui. + */ + virtual void focusNone(); - /** - * Toggles the use of the tab key to focus Widgets. - * By default, tabbing is enabled. - * - * @param tabbing set to false if you want to disable tabbing. - */ - virtual void setTabbingEnabled(bool tabbing); + /** + * Toggles the use of the tab key to focus Widgets. + * By default, tabbing is enabled. + * + * @param tabbing set to false if you want to disable tabbing. + */ + virtual void setTabbingEnabled(bool tabbing); - /** - * Checks if tabbing is enabled. - * - * @return true if tabbing is enabled. - */ - virtual bool isTabbingEnabled(); + /** + * Checks if tabbing is enabled. + * + * @return true if tabbing is enabled. + */ + virtual bool isTabbingEnabled(); - /** - * Adds a global KeyListener to the Gui. - * - * @param keyListener a KeyListener to add. - */ - virtual void addGlobalKeyListener(KeyListener* keyListener); + /** + * Adds a global KeyListener to the Gui. + * + * @param keyListener a KeyListener to add. + */ + virtual void addGlobalKeyListener(KeyListener* keyListener); - /** - * Remove global KeyListener from the Gui. - * - * @param keyListener a KeyListener to remove. - * @throws Exception if the KeyListener hasn't been added. - */ - virtual void removeGlobalKeyListener(KeyListener* keyListener); + /** + * Remove global KeyListener from the Gui. + * + * @param keyListener a KeyListener to remove. + * @throws Exception if the KeyListener hasn't been added. + */ + virtual void removeGlobalKeyListener(KeyListener* keyListener); - protected: - /** - * Handles all mouse input. - * - * @since 0.6.0 - */ - virtual void handleMouseInput(); + protected: + /** + * Handles all mouse input. + * + * @since 0.6.0 + */ + virtual void handleMouseInput(); - /** - * Handles key input. - * - * @since 0.6.0 - */ - virtual void handleKeyInput(); + /** + * Handles key input. + * + * @since 0.6.0 + */ + virtual void handleKeyInput(); - /** - * Handles mouse moved input. - * - * @param mouseInput the mouse input to handle. - * @since 0.6.0 - */ - virtual void handleMouseMoved(const MouseInput& mouseInput); + /** + * Handles mouse moved input. + * + * @param mouseInput the mouse input to handle. + * @since 0.6.0 + */ + virtual void handleMouseMoved(const MouseInput& mouseInput); - /** - * Handles mouse pressed input. - * - * @param mouseInput the mouse input to handle. - * @since 0.6.0 - */ - virtual void handleMousePressed(const MouseInput& mouseInput); + /** + * Handles mouse pressed input. + * + * @param mouseInput the mouse input to handle. + * @since 0.6.0 + */ + virtual void handleMousePressed(const MouseInput& mouseInput); - /** - * - * Handles mouse wheel moved down input. - * - * @param mouseInput the mouse input to handle. - * @since 0.6.0 - */ - virtual void handleMouseWheelMovedDown(const MouseInput& mouseInput); + /** + * + * Handles mouse wheel moved down input. + * + * @param mouseInput the mouse input to handle. + * @since 0.6.0 + */ + virtual void handleMouseWheelMovedDown(const MouseInput& mouseInput); - /** - * Handles mouse wheel moved up input. - * - * @param mouseInput the mouse input to handle. - * @since 0.6.0 - */ - virtual void handleMouseWheelMovedUp(const MouseInput& mouseInput); + /** + * Handles mouse wheel moved up input. + * + * @param mouseInput the mouse input to handle. + * @since 0.6.0 + */ + virtual void handleMouseWheelMovedUp(const MouseInput& mouseInput); - /** - * Handles mouse released input. - * - * @param mouseInput the mouse input to handle. - * @since 0.6.0 - */ - virtual void handleMouseReleased(const MouseInput& mouseInput); + /** + * Handles mouse released input. + * + * @param mouseInput the mouse input to handle. + * @since 0.6.0 + */ + virtual void handleMouseReleased(const MouseInput& mouseInput); - /** - * Handles modal focus. Modal focus needs to be checked at - * each logic iteration as it might be necessary to distribute - * mouse entered or mouse exited events. - * - * @since 0.8.0 - */ - virtual void handleModalFocus(); + /** + * Handles modal focus. Modal focus needs to be checked at + * each logic iteration as it might be necessary to distribute + * mouse entered or mouse exited events. + * + * @since 0.8.0 + */ + virtual void handleModalFocus(); - /** - * Handles modal mouse input focus. Modal mouse input focus needs - * to be checked at each logic iteration as it might be necessary to - * distribute mouse entered or mouse exited events. - * - * @since 0.8.0 - */ - virtual void handleModalMouseInputFocus(); + /** + * Handles modal mouse input focus. Modal mouse input focus needs + * to be checked at each logic iteration as it might be necessary to + * distribute mouse entered or mouse exited events. + * + * @since 0.8.0 + */ + virtual void handleModalMouseInputFocus(); - /** - * Handles modal focus gained. If modal focus has been gaind it might - * be necessary to distribute mouse entered or mouse exited events. - * - * @since 0.8.0 - */ - virtual void handleModalFocusGained(); + /** + * Handles modal focus gained. If modal focus has been gaind it might + * be necessary to distribute mouse entered or mouse exited events. + * + * @since 0.8.0 + */ + virtual void handleModalFocusGained(); - /** - * Handles modal mouse input focus gained. If modal focus has been gaind - * it might be necessary to distribute mouse entered or mouse exited events. - * - * @since 0.8.0 - */ - virtual void handleModalFocusReleased(); + /** + * Handles modal mouse input focus gained. If modal focus has been gaind + * it might be necessary to distribute mouse entered or mouse exited events. + * + * @since 0.8.0 + */ + virtual void handleModalFocusReleased(); - /** - * Distributes a mouse event. - * - * @param type The type of the event to distribute, - * @param button The button of the event (if any used) to distribute. - * @param x The x coordinate of the event. - * @param y The y coordinate of the event. - * @param fource indicates whether the distribution should be forced or not. - * A forced distribution distributes the event even if a widget - * is not enabled, not visible, another widget has modal - * focus or another widget has modal mouse input focus. - * Default value is false. - * @param toSourceOnly indicates whether the distribution should be to the - * source widget only or to it's parent's mouse listeners - * as well. - * - * @since 0.6.0 - */ - virtual void distributeMouseEvent(Widget* source, - int type, - int button, - int x, - int y, - bool force = false, - bool toSourceOnly = false); + /** + * Distributes a mouse event. + * + * @param type The type of the event to distribute, + * @param button The button of the event (if any used) to distribute. + * @param x The x coordinate of the event. + * @param y The y coordinate of the event. + * @param fource indicates whether the distribution should be forced or not. + * A forced distribution distributes the event even if a widget + * is not enabled, not visible, another widget has modal + * focus or another widget has modal mouse input focus. + * Default value is false. + * @param toSourceOnly indicates whether the distribution should be to the + * source widget only or to it's parent's mouse listeners + * as well. + * + * @since 0.6.0 + */ + virtual void distributeMouseEvent(Widget* source, + int type, + int button, + int x, + int y, + bool force = false, + bool toSourceOnly = false); - /** - * Distributes a key event. - * - * @param keyEvent the key event to distribute. + /** + * Distributes a key event. + * + * @param keyEvent the key event to distribute. - * @since 0.6.0 - */ - virtual void distributeKeyEvent(KeyEvent& keyEvent); + * @since 0.6.0 + */ + virtual void distributeKeyEvent(KeyEvent& keyEvent); - /** - * Distributes a key event to the global key listeners. - * - * @param keyEvent the key event to distribute. - * - * @since 0.6.0 - */ - virtual void distributeKeyEventToGlobalKeyListeners(KeyEvent& keyEvent); + /** + * Distributes a key event to the global key listeners. + * + * @param keyEvent the key event to distribute. + * + * @since 0.6.0 + */ + virtual void distributeKeyEventToGlobalKeyListeners(KeyEvent& keyEvent); - /** - * Gets the widget at a certain position. - * - * @return the widget at a certain position. - * @since 0.6.0 - */ - virtual Widget* getWidgetAt(int x, int y); + /** + * Gets the widget at a certain position. + * + * @return the widget at a certain position. + * @since 0.6.0 + */ + virtual Widget* getWidgetAt(int x, int y); - /** - * Gets the source of the mouse event. - * - * @return the source widget of the mouse event. - * @since 0.6.0 - */ - virtual Widget* getMouseEventSource(int x, int y); + /** + * Gets the source of the mouse event. + * + * @return the source widget of the mouse event. + * @since 0.6.0 + */ + virtual Widget* getMouseEventSource(int x, int y); - /** - * Gets the source of the key event. - * - * @return the source widget of the key event. - * @since 0.6.0 - */ - virtual Widget* getKeyEventSource(); + /** + * Gets the source of the key event. + * + * @return the source widget of the key event. + * @since 0.6.0 + */ + virtual Widget* getKeyEventSource(); - Widget* mTop; - Graphics* mGraphics; - Input* mInput; - FocusHandler* mFocusHandler; + Widget* mTop; + Graphics* mGraphics; + Input* mInput; + FocusHandler* mFocusHandler; - bool mTabbing; + bool mTabbing; - typedef std::list KeyListenerList; - typedef KeyListenerList::iterator KeyListenerListIterator; + typedef std::list KeyListenerList; + typedef KeyListenerList::iterator KeyListenerListIterator; - KeyListenerList mKeyListeners; - - // Current input state - bool mShiftPressed; - bool mMetaPressed; - bool mControlPressed; - bool mAltPressed; + KeyListenerList mKeyListeners; - // Last mouse state - unsigned int mLastMousePressButton; - int mLastMousePressTimeStamp; - int mLastMouseX; - int mLastMouseY; - int mClickCount; - int mLastMouseDragButton; + // Current input state + bool mShiftPressed; + bool mMetaPressed; + bool mControlPressed; + bool mAltPressed; - // Widget with mouse stack - std::deque mWidgetWithMouseQueue; - }; + // Last mouse state + unsigned int mLastMousePressButton; + int mLastMousePressTimeStamp; + int mLastMouseX; + int mLastMouseY; + int mClickCount; + int mLastMouseDragButton; + + // Widget with mouse stack + std::deque mWidgetWithMouseQueue; + }; } #endif // end GCN_GUI_HPP diff --git a/external/libguisan/include/guisan/image.hpp b/external/libguisan/include/guisan/image.hpp index 37244130..512b3f76 100644 --- a/external/libguisan/include/guisan/image.hpp +++ b/external/libguisan/include/guisan/image.hpp @@ -63,116 +63,116 @@ namespace gcn { - class Color; - class ImageLoader; + class Color; + class ImageLoader; - /** - * Holds an image. To be able to use this class you must first set an - * ImageLoader in Image by calling - * @code Image::setImageLoader(myImageLoader) @endcode - * The function is static. If this is not done, the constructor taking a - * filename will throw an exception. The ImageLoader you use must be - * compatible with the Graphics object you use. - * - * EXAMPLE: If you use SDLGraphics you should use SDLImageLoader. - * Otherwise your program will crash in a most bizarre way. - */ - class GCN_CORE_DECLSPEC Image - { - public: + /** + * Holds an image. To be able to use this class you must first set an + * ImageLoader in Image by calling + * @code Image::setImageLoader(myImageLoader) @endcode + * The function is static. If this is not done, the constructor taking a + * filename will throw an exception. The ImageLoader you use must be + * compatible with the Graphics object you use. + * + * EXAMPLE: If you use SDLGraphics you should use SDLImageLoader. + * Otherwise your program will crash in a most bizarre way. + */ + class GCN_CORE_DECLSPEC Image + { + public: - /** - * Constructor. - */ - Image(); + /** + * Constructor. + */ + Image(); - /** - * Destructor. - */ - virtual ~Image(); + /** + * Destructor. + */ + virtual ~Image(); - /** - * Loads an image by calling the Image class' ImageLoader. - * - * NOTE: The functions getPixel and putPixel are only guaranteed to work - * before an image has been converted to display format. - * - * @param filename the file to load. - * @param convertToDisplayFormat true if the image should be converted - * to display, false otherwise. - */ - static Image* load(const std::string& filename, bool convertToDisplayFormat = true); + /** + * Loads an image by calling the Image class' ImageLoader. + * + * NOTE: The functions getPixel and putPixel are only guaranteed to work + * before an image has been converted to display format. + * + * @param filename the file to load. + * @param convertToDisplayFormat true if the image should be converted + * to display, false otherwise. + */ + static Image* load(const std::string& filename, bool convertToDisplayFormat = true); - /** - * Gets the ImageLoader used for loading Images. - * - * @return the ImageLoader used for loading Images. - * @see SDLImageLoader, AllegroImageLoader - */ - static ImageLoader* getImageLoader(); + /** + * Gets the ImageLoader used for loading Images. + * + * @return the ImageLoader used for loading Images. + * @see SDLImageLoader, AllegroImageLoader + */ + static ImageLoader* getImageLoader(); - /** - * Sets the ImageLoader to be used for loading images. - * - * IMPORTANT: The ImageLoader is static and MUST be set before loading - * images! - * - * @param imageLoader the ImageLoader to be used for loading images. - * @see SDLImageLoader, AllegroImageLoader - */ - static void setImageLoader(ImageLoader* imageLoader); + /** + * Sets the ImageLoader to be used for loading images. + * + * IMPORTANT: The ImageLoader is static and MUST be set before loading + * images! + * + * @param imageLoader the ImageLoader to be used for loading images. + * @see SDLImageLoader, AllegroImageLoader + */ + static void setImageLoader(ImageLoader* imageLoader); - /** - * Frees an image. - */ - virtual void free() = 0; + /** + * Frees an image. + */ + virtual void free() = 0; - /** - * Gets the width of the Image. - * - * @return the image width - */ - virtual int getWidth() const = 0; + /** + * Gets the width of the Image. + * + * @return the image width + */ + [[nodiscard]] virtual int getWidth() const = 0; - /** - * Gets the height of the Image. - * - * @return the image height - */ - virtual int getHeight() const = 0; + /** + * Gets the height of the Image. + * + * @return the image height + */ + [[nodiscard]] virtual int getHeight() const = 0; - /** - * Gets the color of a pixel at coordinate (x, y) in the image. - * - * IMPORTANT: Only guaranteed to work before the image has been - * converted to display format. - * - * @param x the x coordinate. - * @param y the y coordinate. - * @return the color of the pixel. - */ - virtual Color getPixel(int x, int y) = 0; + /** + * Gets the color of a pixel at coordinate (x, y) in the image. + * + * IMPORTANT: Only guaranteed to work before the image has been + * converted to display format. + * + * @param x the x coordinate. + * @param y the y coordinate. + * @return the color of the pixel. + */ + virtual Color getPixel(int x, int y) = 0; - /** - * Puts a pixel with a certain color at coordinate (x, y). - * - * @param x the x coordinate. - * @param y the y coordinate. - * @param color the color of the pixel to put. - */ - virtual void putPixel(int x, int y, const Color& color) = 0; + /** + * Puts a pixel with a certain color at coordinate (x, y). + * + * @param x the x coordinate. + * @param y the y coordinate. + * @param color the color of the pixel to put. + */ + virtual void putPixel(int x, int y, const Color& color) = 0; - /** - * Converts the image, if possible, to display format. - * - * IMPORTANT: Only guaranteed to work before the image has been - * converted to display format. - */ - virtual void convertToDisplayFormat() = 0; + /** + * Converts the image, if possible, to display format. + * + * IMPORTANT: Only guaranteed to work before the image has been + * converted to display format. + */ + virtual void convertToDisplayFormat() = 0; - protected: - static ImageLoader* mImageLoader; - }; + protected: + static ImageLoader* mImageLoader; + }; } #endif // end GCN_IMAGE_HPP diff --git a/external/libguisan/include/guisan/imagefont.hpp b/external/libguisan/include/guisan/imagefont.hpp index fb148b08..78a32c4d 100644 --- a/external/libguisan/include/guisan/imagefont.hpp +++ b/external/libguisan/include/guisan/imagefont.hpp @@ -65,149 +65,149 @@ namespace gcn { - class Color; - class Graphics; - class Image; + class Color; + class Graphics; + class Image; - /** - * A font using an image containing the font data. It implements the font - * class. You can use any filetype for the font data as long as it can be - * loaded with your ImageLoader. - * - * This are two examples of an image containing a font. - * \image html imagefontexample.bmp - * \image html imagefontexample2.bmp - * - * The Image font format works like this: The first pixel, the pixal at - * coordinate (0,0), tells which color to look for when seperating glyphs. - * You create an image with your glyphs and simple separates them with - * the seperation color. When you create your ImageFont you supply the - * constructor with the glyphs present in your image. When creating an - * ImageFont for the image data in the first example above, the following - * constructor call would be used. - * @code gcn::ImageFont imageFont("fixedfont_big.bmp"," abcdefghijklmno\ + /** + * A font using an image containing the font data. It implements the font + * class. You can use any filetype for the font data as long as it can be + * loaded with your ImageLoader. + * + * This are two examples of an image containing a font. + * \image html imagefontexample.bmp + * \image html imagefontexample2.bmp + * + * The Image font format works like this: The first pixel, the pixal at + * coordinate (0,0), tells which color to look for when seperating glyphs. + * You create an image with your glyphs and simple separates them with + * the seperation color. When you create your ImageFont you supply the + * constructor with the glyphs present in your image. When creating an + * ImageFont for the image data in the first example above, the following + * constructor call would be used. + * @code gcn::ImageFont imageFont("fixedfont_big.bmp"," abcdefghijklmno\ pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); @endcode - * Noteworthy is that the first glyph actually gives the width of space. - * Glyphs can, as seen in the second example above, be seperated with - * horizontal lines making it possible to draw glyphs on more then one - * line in the image. However, these vertical lines must be of one pixel - * size! - */ - class GCN_CORE_DECLSPEC ImageFont: public Font - { - public: + * Noteworthy is that the first glyph actually gives the width of space. + * Glyphs can, as seen in the second example above, be seperated with + * horizontal lines making it possible to draw glyphs on more then one + * line in the image. However, these vertical lines must be of one pixel + * size! + */ + class GCN_CORE_DECLSPEC ImageFont : public Font + { + public: - /** - * Constructor which takes an image file containing the font and - * a string containing the glyphs. The glyphs in the string should - * be in the same order as they appear in the font image. - * - * @param filename the filename of the image. - * @param glyphs the glyphs found in the image. - * @throws Exception when glyph list is incorrect or the font file is - * corrupt or if no ImageLoader exists. - */ - ImageFont(const std::string& filename, const std::string& glyphs); + /** + * Constructor which takes an image file containing the font and + * a string containing the glyphs. The glyphs in the string should + * be in the same order as they appear in the font image. + * + * @param filename the filename of the image. + * @param glyphs the glyphs found in the image. + * @throws Exception when glyph list is incorrect or the font file is + * corrupt or if no ImageLoader exists. + */ + ImageFont(const std::string& filename, const std::string& glyphs); - /** - * Constructor which takes an image file containing the font and - * two boundaries of ASCII values. The font image should include - * all glyphs specified with the boundaries in increasing ASCII - * order. The boundaries are inclusive. - * - * @param filename the filename of the image. - * @param glyphsFrom the ASCII value of the first glyph found in the - * image. - * @param glyphsTo the ASCII value of the last glyph found in the - * image. - * @throws Exception when glyph bondaries are incorrect or the font - * file is corrupt or if no ImageLoader exists. - */ - ImageFont(const std::string& filename, unsigned char glyphsFrom=32, - unsigned char glyphsTo=126); + /** + * Constructor which takes an image file containing the font and + * two boundaries of ASCII values. The font image should include + * all glyphs specified with the boundaries in increasing ASCII + * order. The boundaries are inclusive. + * + * @param filename the filename of the image. + * @param glyphsFrom the ASCII value of the first glyph found in the + * image. + * @param glyphsTo the ASCII value of the last glyph found in the + * image. + * @throws Exception when glyph bondaries are incorrect or the font + * file is corrupt or if no ImageLoader exists. + */ + explicit ImageFont(const std::string& filename, unsigned char glyphsFrom = 32, + unsigned char glyphsTo = 126); - /** - * Destructor. - */ - virtual ~ImageFont(); + /** + * Destructor. + */ + virtual ~ImageFont(); - /** - * Draws a glyph. - * - * NOTE: You normally won't use this function to draw text since - * the Graphics class contains better functions for drawing - * text. - * - * @param graphics a graphics object to be used for drawing. - * @param glyph a glyph to draw. - * @param x the x coordinate where to draw the glyph. - * @param y the y coordinate where to draw the glyph. - * @return the width of the glyph in pixels. - * @see Graphics - */ - virtual int drawGlyph(Graphics* graphics, unsigned char glyph, - int x, int y); + /** + * Draws a glyph. + * + * NOTE: You normally won't use this function to draw text since + * the Graphics class contains better functions for drawing + * text. + * + * @param graphics a graphics object to be used for drawing. + * @param glyph a glyph to draw. + * @param x the x coordinate where to draw the glyph. + * @param y the y coordinate where to draw the glyph. + * @return the width of the glyph in pixels. + * @see Graphics + */ + virtual int drawGlyph(Graphics* graphics, unsigned char glyph, + int x, int y); - /** - * Sets the spacing between rows in pixels. Default is 0 pixels. - * The spacing can be negative. - * - * @param spacing the spacing in pixels. - */ - virtual void setRowSpacing(int spacing); + /** + * Sets the spacing between rows in pixels. Default is 0 pixels. + * The spacing can be negative. + * + * @param spacing the spacing in pixels. + */ + virtual void setRowSpacing(int spacing); - /** - * Gets the spacing between rows in pixels. - * - * @return the spacing. - */ - virtual int getRowSpacing(); + /** + * Gets the spacing between rows in pixels. + * + * @return the spacing. + */ + virtual int getRowSpacing(); - /** - * Sets the spacing between letters in pixels. Default is 0 pixels. - * The spacing can be negative. - * - * @param spacing the spacing in pixels - */ - virtual void setGlyphSpacing(int spacing); + /** + * Sets the spacing between letters in pixels. Default is 0 pixels. + * The spacing can be negative. + * + * @param spacing the spacing in pixels + */ + virtual void setGlyphSpacing(int spacing); - /** - * Gets the spacing between letters in pixels. - * - * @return the spacing. - */ - virtual int getGlyphSpacing(); + /** + * Gets the spacing between letters in pixels. + * + * @return the spacing. + */ + virtual int getGlyphSpacing(); - /** - * Gets a width of a glyph. - * - * @param glyph the glyph which width will be returned - * @return the width of a glyph - */ - virtual int getWidth(unsigned char glyph) const; + /** + * Gets a width of a glyph. + * + * @param glyph the glyph which width will be returned + * @return the width of a glyph + */ + [[nodiscard]] virtual int getWidth(unsigned char glyph) const; - // Inherited from Font + // Inherited from Font - virtual int getWidth(const std::string& text) const; + [[nodiscard]] int getWidth(const std::string& text) const override; - virtual void drawString(Graphics* graphics, const std::string& text, - int x, int y); + void drawString(Graphics* graphics, const std::string& text, + int x, int y) override; - virtual int getHeight() const; + [[nodiscard]] int getHeight() const override; - virtual int getStringIndexAt(const std::string& text, int x); + int getStringIndexAt(const std::string& text, int x) override; - protected: - void addGlyph(unsigned char c, int &x, int &y, const Color& separator); + protected: + void addGlyph(unsigned char c, int& x, int& y, const Color& separator); - Rectangle mGlyph[256]; - int mHeight; - int mGlyphSpacing; - int mRowSpacing; - Image* mImage; - std::string mFilename; - }; + Rectangle mGlyph[256]; + int mHeight; + int mGlyphSpacing; + int mRowSpacing; + Image* mImage; + std::string mFilename; + }; } #endif // end GCN_IMAGEFONT_HPP diff --git a/external/libguisan/include/guisan/imageloader.hpp b/external/libguisan/include/guisan/imageloader.hpp index a53c9b19..95d575c4 100644 --- a/external/libguisan/include/guisan/imageloader.hpp +++ b/external/libguisan/include/guisan/imageloader.hpp @@ -63,34 +63,35 @@ namespace gcn { - class Image; + class Image; - /** - * ImageLoaders base class. Contains basic image loading functions every - * image loader should have. Image loaders should inherit from this - * class and impements it's functions. - */ - class GCN_CORE_DECLSPEC ImageLoader - { - public: + /** + * ImageLoaders base class. Contains basic image loading functions every + * image loader should have. Image loaders should inherit from this + * class and impements it's functions. + */ + class GCN_CORE_DECLSPEC ImageLoader + { + public: - /** - * Destructor. - */ - virtual ~ImageLoader() { } + /** + * Destructor. + */ + virtual ~ImageLoader() + = default; - /** - * Loads an image by calling the image's ImageLoader. - * - * NOTE: The functions getPixel and putPixel in Image are only guaranteed to - * work before an image has been converted to display format. - * - * @param filename the file to load. - * @param convertToDisplayFormat true if the image should be converted - * to display, false otherwise. - */ - virtual Image* load(const std::string& filename, bool convertToDisplayFormat = true) = 0; - }; + /** + * Loads an image by calling the image's ImageLoader. + * + * NOTE: The functions getPixel and putPixel in Image are only guaranteed to + * work before an image has been converted to display format. + * + * @param filename the file to load. + * @param convertToDisplayFormat true if the image should be converted + * to display, false otherwise. + */ + virtual Image* load(const std::string& filename, bool convertToDisplayFormat = true) = 0; + }; } #endif // end GCN_IMAGELOADER_HPP diff --git a/external/libguisan/include/guisan/input.hpp b/external/libguisan/include/guisan/input.hpp index 33b15b99..2554bfec 100644 --- a/external/libguisan/include/guisan/input.hpp +++ b/external/libguisan/include/guisan/input.hpp @@ -61,61 +61,62 @@ namespace gcn { - class KeyInput; - class MouseInput; + class KeyInput; + class MouseInput; - /** - * Used for grabbing user input and heavily used internally by Guichan. - * We include implemented Input classes for some common platforms like - * the Allegro library, the OpenGL library and the SDL library. To make - * Guichan usable under another platform, an Input class must be - * implemented. - * - * @see SDLInput, AllegroInput - */ - class GCN_CORE_DECLSPEC Input - { - public: + /** + * Used for grabbing user input and heavily used internally by Guichan. + * We include implemented Input classes for some common platforms like + * the Allegro library, the OpenGL library and the SDL library. To make + * Guichan usable under another platform, an Input class must be + * implemented. + * + * @see SDLInput, AllegroInput + */ + class GCN_CORE_DECLSPEC Input + { + public: - /** - * Destructor. - */ - virtual ~Input(){ } + /** + * Destructor. + */ + virtual ~Input() + = default; - /** - * Checks whether the key queue is empty or not. - * - * @return true if the key queue is empty. - */ - virtual bool isKeyQueueEmpty() = 0; + /** + * Checks whether the key queue is empty or not. + * + * @return true if the key queue is empty. + */ + virtual bool isKeyQueueEmpty() = 0; - /** - * Dequeues the key input queue. - * - * @return key input. - */ - virtual KeyInput dequeueKeyInput() = 0; + /** + * Dequeues the key input queue. + * + * @return key input. + */ + virtual KeyInput dequeueKeyInput() = 0; - /** - * Checks whether the mouse queue is empyt or not. - * - * @return true if the mouse queue is empty. - */ - virtual bool isMouseQueueEmpty() = 0; + /** + * Checks whether the mouse queue is empyt or not. + * + * @return true if the mouse queue is empty. + */ + virtual bool isMouseQueueEmpty() = 0; - /** - * Dequeues the mouse input queue. - * - * @return mouse input. - */ - virtual MouseInput dequeueMouseInput() = 0; + /** + * Dequeues the mouse input queue. + * + * @return mouse input. + */ + virtual MouseInput dequeueMouseInput() = 0; - /** - * Polls all exsisting input. It exists for Input implementation - * compatibility. It is used internally by the library. - */ - virtual void _pollInput() = 0; - }; + /** + * Polls all exsisting input. It exists for Input implementation + * compatibility. It is used internally by the library. + */ + virtual void _pollInput() = 0; + }; } #endif // end GCN_INPUT_HPP diff --git a/external/libguisan/include/guisan/inputevent.hpp b/external/libguisan/include/guisan/inputevent.hpp index abee29f5..c2df4026 100644 --- a/external/libguisan/include/guisan/inputevent.hpp +++ b/external/libguisan/include/guisan/inputevent.hpp @@ -62,79 +62,79 @@ namespace gcn { - /** - * Base class for all input events. - * - * @author Olof Naessén - * @since 0.6.0 - */ - class GCN_CORE_DECLSPEC InputEvent: public Event - { - public: + /** + * Base class for all input events. + * + * @author Olof Naessén + * @since 0.6.0 + */ + class GCN_CORE_DECLSPEC InputEvent : public Event + { + public: - /** - * Constructor. - * - * @param source the source widget of the event. - * @param isShiftPressed true if shift is pressed, false otherwise. - * @param isControlPressed true if control is pressed, false otherwise. - * @param isAltPressed true if alt is pressed, false otherwise. - * @param isMetaPressed true if meta is pressed, false otherwise. - */ - InputEvent(Widget* source, - bool isShiftPressed, - bool isControlPressed, - bool isAltPressed, - bool isMetaPressed); + /** + * Constructor. + * + * @param source the source widget of the event. + * @param isShiftPressed true if shift is pressed, false otherwise. + * @param isControlPressed true if control is pressed, false otherwise. + * @param isAltPressed true if alt is pressed, false otherwise. + * @param isMetaPressed true if meta is pressed, false otherwise. + */ + InputEvent(Widget* source, + bool isShiftPressed, + bool isControlPressed, + bool isAltPressed, + bool isMetaPressed); - /** - * Checks whether shift is pressed. - * - * @return true if shift was pressed at the same time as the key. - */ - bool isShiftPressed() const; + /** + * Checks whether shift is pressed. + * + * @return true if shift was pressed at the same time as the key. + */ + [[nodiscard]] bool isShiftPressed() const; - /** - * Checks whether control is pressed. - * - * @return true if control was pressed at the same time as the key. - */ - bool isControlPressed() const; + /** + * Checks whether control is pressed. + * + * @return true if control was pressed at the same time as the key. + */ + [[nodiscard]] bool isControlPressed() const; - /** - * Checks whether alt is pressed. - * - * @return true if alt was pressed at the same time as the key. - */ - bool isAltPressed() const; + /** + * Checks whether alt is pressed. + * + * @return true if alt was pressed at the same time as the key. + */ + [[nodiscard]] bool isAltPressed() const; - /** - * Checks whether meta is pressed. - * - * @return true if meta was pressed at the same time as the key. - */ - bool isMetaPressed() const; + /** + * Checks whether meta is pressed. + * + * @return true if meta was pressed at the same time as the key. + */ + [[nodiscard]] bool isMetaPressed() const; - /** - * Marks the event as consumed. How widgets should act on consumed - * events are up to the widgets themselves. - */ - void consume(); + /** + * Marks the event as consumed. How widgets should act on consumed + * events are up to the widgets themselves. + */ + void consume(); - /** - * Checks if the input event is consumed. - * - * @return true if the input event is consumed, false otherwise. - */ - bool isConsumed() const; + /** + * Checks if the input event is consumed. + * + * @return true if the input event is consumed, false otherwise. + */ + [[nodiscard]] bool isConsumed() const; - protected: - bool mShiftPressed; - bool mControlPressed; - bool mAltPressed; - bool mMetaPressed; - bool mIsConsumed; - }; + protected: + bool mShiftPressed; + bool mControlPressed; + bool mAltPressed; + bool mMetaPressed; + bool mIsConsumed; + }; } #endif // end GCN_INPUTEVENT_HPP diff --git a/external/libguisan/include/guisan/key.hpp b/external/libguisan/include/guisan/key.hpp index 1af2ff1f..4ece3738 100644 --- a/external/libguisan/include/guisan/key.hpp +++ b/external/libguisan/include/guisan/key.hpp @@ -61,112 +61,112 @@ namespace gcn { - /** - * Represents a key or a character. - */ - class GCN_CORE_DECLSPEC Key - { - public: + /** + * Represents a key or a character. + */ + class GCN_CORE_DECLSPEC Key + { + public: - /** - * Constructor. - * - * @param value the ascii or enum value for the key. - */ - Key(int value = 0); + /** + * Constructor. + * + * @param value the ascii or enum value for the key. + */ + Key(int value = 0); - /** - * Checks whether a key is a character. - * - * @return true if the key is a letter, number or whitespace. - */ - bool isCharacter() const; + /** + * Checks whether a key is a character. + * + * @return true if the key is a letter, number or whitespace. + */ + [[nodiscard]] bool isCharacter() const; - /** - * Checks whether a key is a number. - * - * @return true if the key is a number (0-9). - */ - bool isNumber() const; + /** + * Checks whether a key is a number. + * + * @return true if the key is a number (0-9). + */ + [[nodiscard]] bool isNumber() const; - /** - * Checks whether a key is a letter. - * - * @return true if the key is a letter (a-z,A-Z). - */ - bool isLetter() const; + /** + * Checks whether a key is a letter. + * + * @return true if the key is a letter (a-z,A-Z). + */ + [[nodiscard]] bool isLetter() const; - /** - * Gets the value of the key. If an ascii value exists it will be - * returned. Otherwise an enum value will be returned. - * - * @return the value of the key. - */ - int getValue() const; + /** + * Gets the value of the key. If an ascii value exists it will be + * returned. Otherwise an enum value will be returned. + * + * @return the value of the key. + */ + [[nodiscard]] int getValue() const; - /** - * Gets the char value of the key if available. - * - * @return the char value of the key, the null character otherwise - */ - char getChar() const; + /** + * Gets the char value of the key if available. + * + * @return the char value of the key, the null character otherwise + */ + [[nodiscard]] char getChar() const; - /** - * An enum with key values. - */ - enum - { - SPACE = ' ', - TAB = '\t', - ENTER = '\n', - LEFT_ALT = 1000, - RIGHT_ALT, - LEFT_SHIFT, - RIGHT_SHIFT, - LEFT_CONTROL, - RIGHT_CONTROL, - LEFT_META, - RIGHT_META, - LEFT_SUPER, - RIGHT_SUPER, - INSERT, - HOME, - PAGE_UP, - DELETE, - END, - PAGE_DOWN, - ESCAPE, - CAPS_LOCK, - BACKSPACE, - F1, - F2, - F3, - F4, - F5, - F6, - F7, - F8, - F9, - F10, - F11, - F12, - F13, - F14, - F15, - PRINT_SCREEN, - SCROLL_LOCK, - PAUSE, - NUM_LOCK, - ALT_GR, - LEFT, - RIGHT, - UP, - DOWN - }; + /** + * An enum with key values. + */ + enum + { + SPACE = ' ', + TAB = '\t', + ENTER = '\n', + LEFT_ALT = 1000, + RIGHT_ALT, + LEFT_SHIFT, + RIGHT_SHIFT, + LEFT_CONTROL, + RIGHT_CONTROL, + LEFT_META, + RIGHT_META, + LEFT_SUPER, + RIGHT_SUPER, + INSERT, + HOME, + PAGE_UP, + DELETE, + END, + PAGE_DOWN, + ESCAPE, + CAPS_LOCK, + BACKSPACE, + F1, + F2, + F3, + F4, + F5, + F6, + F7, + F8, + F9, + F10, + F11, + F12, + F13, + F14, + F15, + PRINT_SCREEN, + SCROLL_LOCK, + PAUSE, + NUM_LOCK, + ALT_GR, + LEFT, + RIGHT, + UP, + DOWN + }; - protected: - int mValue; - }; + protected: + int mValue; + }; } #endif // end GCN_KEY_HPP diff --git a/external/libguisan/include/guisan/keyevent.hpp b/external/libguisan/include/guisan/keyevent.hpp index 2629b2bb..d3f55f41 100644 --- a/external/libguisan/include/guisan/keyevent.hpp +++ b/external/libguisan/include/guisan/keyevent.hpp @@ -104,21 +104,21 @@ namespace gcn * * @return the type of the event. */ - unsigned int getType() const; + [[nodiscard]] unsigned int getType() const; /** * Checks whether the key event occured on the numeric pad. * * @return true if key event occured on the numeric pad. */ - bool isNumericPad() const; + [[nodiscard]] bool isNumericPad() const; /** * Gets the key of the event. * * @return the key of the event. */ - const Key& getKey() const; + [[nodiscard]] const Key& getKey() const; /** * Key event types. diff --git a/external/libguisan/include/guisan/keyinput.hpp b/external/libguisan/include/guisan/keyinput.hpp index 477c3aa8..37b57225 100644 --- a/external/libguisan/include/guisan/keyinput.hpp +++ b/external/libguisan/include/guisan/keyinput.hpp @@ -62,155 +62,156 @@ namespace gcn { - /** - * Internal class representing keyboard input. Generally you won't have to - * bother using this class. - */ - class GCN_CORE_DECLSPEC KeyInput - { - public: + /** + * Internal class representing keyboard input. Generally you won't have to + * bother using this class. + */ + class GCN_CORE_DECLSPEC KeyInput + { + public: - /** - * Constructor. - */ - KeyInput() { }; + /** + * Constructor. + */ + KeyInput() + = default;; - /** - * Constructor. - * - * @param key the Key the input concerns. - * @param type the type of input. - */ - KeyInput(const Key& key, int type); + /** + * Constructor. + * + * @param key the Key the input concerns. + * @param type the type of input. + */ + KeyInput(const Key& key, int type); - /** - * Sets the input type. - * - * @param type the type of input. - */ - void setType(int type); + /** + * Sets the input type. + * + * @param type the type of input. + */ + void setType(int type); - /** - * Gets the input type. - * - * @return the input type. - */ - int getType() const; + /** + * Gets the input type. + * + * @return the input type. + */ + [[nodiscard]] int getType() const; - /** - * Sets the key the input concerns. - * - * @param key the Key the input concerns. - */ - void setKey(const Key& key); + /** + * Sets the key the input concerns. + * + * @param key the Key the input concerns. + */ + void setKey(const Key& key); - /** - * Gets the key the input concerns. - * - * @return the Key the input concerns. - */ - const Key& getKey() const; + /** + * Gets the key the input concerns. + * + * @return the Key the input concerns. + */ + [[nodiscard]] const Key& getKey() const; - /** - * Checks whether shift is pressed. - * - * @return true if shift was pressed at the same time as the key. - * @since 0.6.0 - */ - bool isShiftPressed() const; + /** + * Checks whether shift is pressed. + * + * @return true if shift was pressed at the same time as the key. + * @since 0.6.0 + */ + [[nodiscard]] bool isShiftPressed() const; - /** - * Sets the shift pressed flag. - * - * @param pressed the shift flag value. - * @since 0.6.0 - */ - void setShiftPressed(bool pressed); + /** + * Sets the shift pressed flag. + * + * @param pressed the shift flag value. + * @since 0.6.0 + */ + void setShiftPressed(bool pressed); - /** - * Checks whether control is pressed. - * - * @return true if control was pressed at the same time as the key. - * @since 0.6.0 - */ - bool isControlPressed() const; + /** + * Checks whether control is pressed. + * + * @return true if control was pressed at the same time as the key. + * @since 0.6.0 + */ + [[nodiscard]] bool isControlPressed() const; - /** - * Sets the control pressed flag. - * - * @param pressed the control flag value. - * @since 0.6.0 - */ - void setControlPressed(bool pressed); + /** + * Sets the control pressed flag. + * + * @param pressed the control flag value. + * @since 0.6.0 + */ + void setControlPressed(bool pressed); - /** - * Checks whether alt is pressed. - * - * @return true if alt was pressed at the same time as the key. - * @since 0.6.0 - */ - bool isAltPressed() const; + /** + * Checks whether alt is pressed. + * + * @return true if alt was pressed at the same time as the key. + * @since 0.6.0 + */ + [[nodiscard]] bool isAltPressed() const; - /** - * Sets the alt pressed flag. - * - * @param pressed the alt flag value. - * @since 0.6.0 - */ - void setAltPressed(bool pressed); + /** + * Sets the alt pressed flag. + * + * @param pressed the alt flag value. + * @since 0.6.0 + */ + void setAltPressed(bool pressed); - /** - * Checks whether meta is pressed. - * - * @return true if meta was pressed at the same time as the key. - * @since 0.6.0 - */ - bool isMetaPressed() const; + /** + * Checks whether meta is pressed. + * + * @return true if meta was pressed at the same time as the key. + * @since 0.6.0 + */ + [[nodiscard]] bool isMetaPressed() const; - /** - * Sets the meta pressed flag. - * - * @param pressed the meta flag value. - * @since 0.6.0 - */ - void setMetaPressed(bool pressed); + /** + * Sets the meta pressed flag. + * + * @param pressed the meta flag value. + * @since 0.6.0 + */ + void setMetaPressed(bool pressed); - /** - * Checks whether the key was pressed at the numeric pad. - * - * @return true if key pressed at the numeric pad. - * @since 0.6.0 - */ - bool isNumericPad() const; + /** + * Checks whether the key was pressed at the numeric pad. + * + * @return true if key pressed at the numeric pad. + * @since 0.6.0 + */ + [[nodiscard]] bool isNumericPad() const; - /** - * Sets the numeric pad flag. - * - * @param numpad the numeric pad flag value. - * @since 0.6.0 - */ - void setNumericPad(bool numpad); + /** + * Sets the numeric pad flag. + * + * @param numpad the numeric pad flag value. + * @since 0.6.0 + */ + void setNumericPad(bool numpad); - /** - * Key input types. This enum corresponds to the enum with event - * types on KeyEvent for easy mapping. - */ - enum - { - PRESSED = 0, - RELEASED - }; + /** + * Key input types. This enum corresponds to the enum with event + * types on KeyEvent for easy mapping. + */ + enum + { + PRESSED = 0, + RELEASED + }; - protected: - Key mKey; - int mType; - int mButton; - bool mShiftPressed; - bool mControlPressed; - bool mAltPressed; - bool mMetaPressed; - bool mNumericPad; - }; + protected: + Key mKey; + int mType{}; + int mButton{}; + bool mShiftPressed{}; + bool mControlPressed{}; + bool mAltPressed{}; + bool mMetaPressed{}; + bool mNumericPad{}; + }; } #endif // end GCN_KEYINPUT_HPP diff --git a/external/libguisan/include/guisan/keylistener.hpp b/external/libguisan/include/guisan/keylistener.hpp index 92c5b28e..66084057 100644 --- a/external/libguisan/include/guisan/keylistener.hpp +++ b/external/libguisan/include/guisan/keylistener.hpp @@ -62,53 +62,59 @@ namespace gcn { - class Key; + class Key; - /** - * Key listeners base class. Inorder to use this class you must inherit - * from it and implements it's functions. KeyListeners listen for key - * events on a Widgets. When a Widget recives a key event, the - * corresponding function in all it's key listeners will be called. - * Only focused Widgets will generate key events. - * - * @see Widget::addKeyListener - */ - class GCN_CORE_DECLSPEC KeyListener - { - public: + /** + * Key listeners base class. Inorder to use this class you must inherit + * from it and implements it's functions. KeyListeners listen for key + * events on a Widgets. When a Widget recives a key event, the + * corresponding function in all it's key listeners will be called. + * Only focused Widgets will generate key events. + * + * @see Widget::addKeyListener + */ + class GCN_CORE_DECLSPEC KeyListener + { + public: - /** - * Destructor - */ - virtual ~KeyListener() { } + /** + * Destructor + */ + virtual ~KeyListener() + = default; - /** - * Called if a key is pressed when the widget has keyboard focus. - * If a key is held down the widget will generate multiple key - * presses. - * - * @param keyEvent discribes the event. - */ - virtual void keyPressed(KeyEvent& keyEvent) { } + /** + * Called if a key is pressed when the widget has keyboard focus. + * If a key is held down the widget will generate multiple key + * presses. + * + * @param keyEvent discribes the event. + */ + virtual void keyPressed(KeyEvent& keyEvent) + { + } - /** - * Called if a key is released when the widget has keyboard focus. - * - * @param keyEvent discribes the event. - */ - virtual void keyReleased(KeyEvent& keyEvent) { } + /** + * Called if a key is released when the widget has keyboard focus. + * + * @param keyEvent discribes the event. + */ + virtual void keyReleased(KeyEvent& keyEvent) + { + } - protected: - /** - * Constructor. - * - * You should not be able to make an instance of KeyListener, - * therefore its constructor is protected. To use KeyListener - * you must inherit from this class and implement it's - * functions. - */ - KeyListener() { } - }; + protected: + /** + * Constructor. + * + * You should not be able to make an instance of KeyListener, + * therefore its constructor is protected. To use KeyListener + * you must inherit from this class and implement it's + * functions. + */ + KeyListener() + = default; + }; } #endif // end GCN_KEYLISTENER_HPP diff --git a/external/libguisan/include/guisan/mouseevent.hpp b/external/libguisan/include/guisan/mouseevent.hpp index e0ed0db2..e8642545 100644 --- a/external/libguisan/include/guisan/mouseevent.hpp +++ b/external/libguisan/include/guisan/mouseevent.hpp @@ -62,117 +62,116 @@ namespace gcn { - class Gui; - class Widget; + class Gui; + class Widget; - /** - * Represents a mouse event. - * - * @author Olof Naessén - * @since 0.6.0 - */ - class GCN_CORE_DECLSPEC MouseEvent: public InputEvent - { - public: + /** + * Represents a mouse event. + * + * @author Olof Naessén + * @since 0.6.0 + */ + class GCN_CORE_DECLSPEC MouseEvent : public InputEvent + { + public: - /** - * Constructor. - * - * @param source the source widget of the event. - * @param isShiftPressed true if shift is pressed, false otherwise. - * @param isControlPressed true if control is pressed, false otherwise. - * @param isAltPressed true if alt is pressed, false otherwise. - * @param isMetaPressed true if meta is pressed, false otherwise. - * @param the type of the event. - * @param button the button of the event. - * @param the x coordinate of the event relative to the source widget. - * @param the y coordinate of the event relative the source widget. - */ - MouseEvent(Widget* source, - bool isShiftPressed, - bool isControlPressed, - bool isAltPressed, - bool isMetaPressed, - unsigned int type, - unsigned int button, - int x, - int y, - int clickCount); + /** + * Constructor. + * + * @param source the source widget of the event. + * @param isShiftPressed true if shift is pressed, false otherwise. + * @param isControlPressed true if control is pressed, false otherwise. + * @param isAltPressed true if alt is pressed, false otherwise. + * @param isMetaPressed true if meta is pressed, false otherwise. + * @param the type of the event. + * @param button the button of the event. + * @param the x coordinate of the event relative to the source widget. + * @param the y coordinate of the event relative the source widget. + */ + MouseEvent(Widget* source, + bool isShiftPressed, + bool isControlPressed, + bool isAltPressed, + bool isMetaPressed, + unsigned int type, + unsigned int button, + int x, + int y, + int clickCount); - /** - * Gets the button of the mouse event. - * - * @return the button of the mouse event. - */ - unsigned int getButton() const; + /** + * Gets the button of the mouse event. + * + * @return the button of the mouse event. + */ + [[nodiscard]] unsigned int getButton() const; - /** - * Gets the x coordinate of the mouse event. The coordinate is relative to - * the source Widget. - * - * @return the x coordinate of the mouse event. - */ - int getX() const; + /** + * Gets the x coordinate of the mouse event. The coordinate is relative to + * the source Widget. + * + * @return the x coordinate of the mouse event. + */ + [[nodiscard]] int getX() const; - /** - * Gets the y coordinate of the mouse event. The coordinate is relative to - * the source Widget. - * - * @return the y coordinate of the mouse event. - */ - int getY() const; + /** + * Gets the y coordinate of the mouse event. The coordinate is relative to + * the source Widget. + * + * @return the y coordinate of the mouse event. + */ + [[nodiscard]] int getY() const; - /** - * Gets the click count. - * - * @return the click count of the mouse event. - */ - int getClickCount() const; + /** + * Gets the click count. + * + * @return the click count of the mouse event. + */ + [[nodiscard]] int getClickCount() const; - /** - * Gets the type of the event. - * - * @return the type of the event. - */ - unsigned int getType() const; + /** + * Gets the type of the event. + * + * @return the type of the event. + */ + [[nodiscard]] unsigned int getType() const; - /** - * Mouse event types. - */ - enum - { - MOVED = 0, - PRESSED, - RELEASED, - WHEEL_MOVED_DOWN, - WHEEL_MOVED_UP, - CLICKED, - ENTERED, - EXITED, - DRAGGED + /** + * Mouse event types. + */ + enum + { + MOVED = 0, + PRESSED, + RELEASED, + WHEEL_MOVED_DOWN, + WHEEL_MOVED_UP, + CLICKED, + ENTERED, + EXITED, + DRAGGED + }; - }; + /** + * Mouse button types. + */ + enum + { + EMPTY = 0, + LEFT, + RIGHT, + MIDDLE + }; - /** - * Mouse button types. - */ - enum - { - EMPTY = 0, - LEFT, - RIGHT, - MIDDLE - }; + protected: + unsigned int mType; + unsigned int mButton; + int mX; + int mY; + int mClickCount; - protected: - unsigned int mType; - unsigned int mButton; - int mX; - int mY; - int mClickCount; - - friend class Gui; - }; + friend class Gui; + }; } #endif // GCN_MOUSEEVENT_HPP diff --git a/external/libguisan/include/guisan/mouseinput.hpp b/external/libguisan/include/guisan/mouseinput.hpp index 2d9fef12..b8c1f407 100644 --- a/external/libguisan/include/guisan/mouseinput.hpp +++ b/external/libguisan/include/guisan/mouseinput.hpp @@ -61,143 +61,143 @@ namespace gcn { + /** + * Internal class representing mouse input. Generally you won't have to + * bother using this class as it will get translated into a MouseEvent. + * The class should be seen as a bridge between the low layer backends + * providing input and the higher lever parts of the Gui (such as widgets). + * + * @author Olof Naessén + * @author Per Larsson + */ + class GCN_CORE_DECLSPEC MouseInput + { + public: - /** - * Internal class representing mouse input. Generally you won't have to - * bother using this class as it will get translated into a MouseEvent. - * The class should be seen as a bridge between the low layer backends - * providing input and the higher lever parts of the Gui (such as widgets). - * - * @author Olof Naessén - * @author Per Larsson - */ - class GCN_CORE_DECLSPEC MouseInput - { - public: + /** + * Constructor. + */ + MouseInput() + = default;; - /** - * Constructor. - */ - MouseInput() { }; + /** + * Constructor. + * + * @param button the button pressed. + * @param type the type of input. + * @param x the mouse x coordinate. + * @param y the mouse y coordinate. + * @param timeStamp the mouse inputs time stamp. + */ + MouseInput(unsigned int button, + unsigned int type, + int x, + int y, + int timeStamp); - /** - * Constructor. - * - * @param button the button pressed. - * @param type the type of input. - * @param x the mouse x coordinate. - * @param y the mouse y coordinate. - * @param timeStamp the mouse inputs time stamp. - */ - MouseInput(unsigned int button, - unsigned int type, - int x, - int y, - int timeStamp); + /** + * Sets the input type. + * + * @param type the type of input. + */ + void setType(unsigned int type); - /** - * Sets the input type. - * - * @param type the type of input. - */ - void setType(unsigned int type); + /** + * Gets the input type. + * + * @return the input type. + */ + [[nodiscard]] unsigned int getType() const; - /** - * Gets the input type. - * - * @return the input type. - */ - unsigned int getType() const; + /** + * Sets the button pressed. + * + * @param button the button pressed. + */ + void setButton(unsigned int button); - /** - * Sets the button pressed. - * - * @param button the button pressed. - */ - void setButton(unsigned int button); + /** + * Gets the button pressed. + * + * @return the button pressed. + */ + [[nodiscard]] unsigned int getButton() const; - /** - * Gets the button pressed. - * - * @return the button pressed. - */ - unsigned int getButton() const; + /** + * Sets the timestamp for the input. + * + * @param timeStamp the timestamp of the input. + */ + void setTimeStamp(int timeStamp); - /** - * Sets the timestamp for the input. - * - * @param timeStamp the timestamp of the input. - */ - void setTimeStamp(int timeStamp); + /** + * Gets the time stamp of the input. + * + * @return the time stamp of the input. + */ + [[nodiscard]] int getTimeStamp() const; - /** - * Gets the time stamp of the input. - * - * @return the time stamp of the input. - */ - int getTimeStamp() const; + /** + * Sets the x coordinate of the input. + * + * @param x the x coordinate of the input. + * @since 0.6.0 + */ + void setX(int x); - /** - * Sets the x coordinate of the input. - * - * @param x the x coordinate of the input. - * @since 0.6.0 - */ - void setX(int x); + /** + * Gets the x coordinate of the input. + * + * @return the x coordinate of the input. + * @since 0.6.0 + */ + [[nodiscard]] int getX() const; - /** - * Gets the x coordinate of the input. - * - * @return the x coordinate of the input. - * @since 0.6.0 - */ - int getX() const; + /** + * Sets the y coordinate of the input. + * + * @param y the y coordinate of the input. + * @since 0.6.0 + */ + void setY(int y); - /** - * Sets the y coordinate of the input. - * - * @param y the y coordinate of the input. - * @since 0.6.0 - */ - void setY(int y); + /** + * Gets the y coordinate of the input. + * @since 0.6.0 + */ + [[nodiscard]] int getY() const; - /** - * Gets the y coordinate of the input. - * @since 0.6.0 - */ - int getY() const; + /** + * Mouse input event types. This enum partially corresponds + * to the enum with event types in MouseEvent for easy mapping. + */ + enum + { + MOVED = 0, + PRESSED, + RELEASED, + WHEEL_MOVED_DOWN, + WHEEL_MOVED_UP + }; - /** - * Mouse input event types. This enum partially corresponds - * to the enum with event types in MouseEvent for easy mapping. - */ - enum - { - MOVED = 0, - PRESSED, - RELEASED, - WHEEL_MOVED_DOWN, - WHEEL_MOVED_UP - }; + /** + * Mouse button types. + */ + enum + { + EMPTY = 0, + LEFT, + RIGHT, + MIDDLE + }; - /** - * Mouse button types. - */ - enum - { - EMPTY = 0, - LEFT, - RIGHT, - MIDDLE - }; - - protected: - unsigned int mType; - unsigned int mButton; - int mTimeStamp; - int mX; - int mY; - }; + protected: + unsigned int mType{}; + unsigned int mButton{}; + int mTimeStamp{}; + int mX{}; + int mY{}; + }; } #endif // end GCN_MOUSEINPUT_HPP diff --git a/external/libguisan/include/guisan/mouselistener.hpp b/external/libguisan/include/guisan/mouselistener.hpp index 69bfd821..3843d2b0 100644 --- a/external/libguisan/include/guisan/mouselistener.hpp +++ b/external/libguisan/include/guisan/mouselistener.hpp @@ -62,137 +62,130 @@ namespace gcn { - /** - * Mouse listeners base class. Inorder to use this class you must inherit - * from it and implements it's functions. MouseListeners listen for mouse - * events on a Widgets. When a Widget recives a mouse event, the - * corresponding function in all it's mouse listeners will be called. - * - * @see Widget::addMouseListener - */ - class GCN_CORE_DECLSPEC MouseListener - { - public: + /** + * Mouse listeners base class. Inorder to use this class you must inherit + * from it and implements it's functions. MouseListeners listen for mouse + * events on a Widgets. When a Widget recives a mouse event, the + * corresponding function in all it's mouse listeners will be called. + * + * @see Widget::addMouseListener + */ + class GCN_CORE_DECLSPEC MouseListener + { + public: - /** - * Destructor. - */ - virtual ~MouseListener() { } + /** + * Destructor. + */ + virtual ~MouseListener() + = default; - /** - * Called when the mouse has entered into the widget area. - * - * @param mouseEvent describes the event. - * @since 0.6.0 - */ - virtual void mouseEntered(MouseEvent& mouseEvent) - { + /** + * Called when the mouse has entered into the widget area. + * + * @param mouseEvent describes the event. + * @since 0.6.0 + */ + virtual void mouseEntered(MouseEvent& mouseEvent) + { + } - } + /** + * Called when the mouse has exited the widget area. + * + * @param mouseEvent describes the event. + */ + virtual void mouseExited(MouseEvent& mouseEvent) + { + } - /** - * Called when the mouse has exited the widget area. - * - * @param mouseEvent describes the event. - */ - virtual void mouseExited(MouseEvent& mouseEvent) - { + /** + * Called when a mouse button has been pressed on the widget area. + * + * NOTE: A mouse press is NOT equal to a mouse click. + * Use mouseClickMessage to check for mouse clicks. + * + * @param mouseEvent describes the event. + * @since 0.6.0 + */ + virtual void mousePressed(MouseEvent& mouseEvent) + { + } - } + /** + * Called when a mouse button has been released on the widget area. + * + * @param mouseEvent describes the event. + */ + virtual void mouseReleased(MouseEvent& mouseEvent) + { + } - /** - * Called when a mouse button has been pressed on the widget area. - * - * NOTE: A mouse press is NOT equal to a mouse click. - * Use mouseClickMessage to check for mouse clicks. - * - * @param mouseEvent describes the event. - * @since 0.6.0 - */ - virtual void mousePressed(MouseEvent& mouseEvent) - { + /** + * Called when a mouse button is pressed and released (clicked) on + * the widget area. + * + * @param mouseEvent describes the event. + * @since 0.6.0 + */ + virtual void mouseClicked(MouseEvent& mouseEvent) + { + } - } + /** + * Called when the mouse wheel has moved up on the widget area. + * + * @param mouseEvent describes the event. + * @since 0.6.0 + */ + virtual void mouseWheelMovedUp(MouseEvent& mouseEvent) + { + } - /** - * Called when a mouse button has been released on the widget area. - * - * @param mouseEvent describes the event. - */ - virtual void mouseReleased(MouseEvent& mouseEvent) - { + /** + * Called when the mouse wheel has moved down on the widget area. + * + * @param mouseEvent describes the event. + * @since 0.6.0 + */ + virtual void mouseWheelMovedDown(MouseEvent& mouseEvent) + { + } - } + /** + * Called when the mouse has moved in the widget area and no mouse button + * has been pressed (i.e no widget is being dragged). + * + * @param mouseEvent describes the event. + * @since 0.6.0 + */ + virtual void mouseMoved(MouseEvent& mouseEvent) + { + } - /** - * Called when a mouse button is pressed and released (clicked) on - * the widget area. - * - * @param mouseEvent describes the event. - * @since 0.6.0 - */ - virtual void mouseClicked(MouseEvent& mouseEvent) - { + /** + * Called when the mouse has moved and the mouse has previously been + * pressed on the widget. + * + * @param mouseEvent describes the event. + * @since 0.6.0 + */ + virtual void mouseDragged(MouseEvent& mouseEvent) + { + } - } - - /** - * Called when the mouse wheel has moved up on the widget area. - * - * @param mouseEvent describes the event. - * @since 0.6.0 - */ - virtual void mouseWheelMovedUp(MouseEvent& mouseEvent) - { - - } - - /** - * Called when the mouse wheel has moved down on the widget area. - * - * @param mousEvent describes the event. - * @since 0.6.0 - */ - virtual void mouseWheelMovedDown(MouseEvent& mouseEvent) - { - - } - - /** - * Called when the mouse has moved in the widget area and no mouse button - * has been pressed (i.e no widget is being dragged). - * - * @param mouseEvent describes the event. - * @since 0.6.0 - */ - virtual void mouseMoved(MouseEvent& mouseEvent) - { - - } - - /** - * Called when the mouse has moved and the mouse has previously been - * pressed on the widget. - * - * @param mouseEvent describes the event. - * @since 0.6.0 - */ - virtual void mouseDragged(MouseEvent& mouseEvent) - { - - } - - protected: - /** - * Constructor. - * - * You should not be able to make an instance of MouseListener, - * therefore its constructor is protected. To use MouseListener - * you must inherit from this class and implement it's - * functions. - */ - MouseListener() { } - }; + protected: + /** + * Constructor. + * + * You should not be able to make an instance of MouseListener, + * therefore its constructor is protected. To use MouseListener + * you must inherit from this class and implement it's + * functions. + */ + MouseListener() + = default; + }; } #endif // end GCN_MOUSELISTENER_HPP diff --git a/external/libguisan/include/guisan/opengl.hpp b/external/libguisan/include/guisan/opengl.hpp index d2879dc7..f116958d 100644 --- a/external/libguisan/include/guisan/opengl.hpp +++ b/external/libguisan/include/guisan/opengl.hpp @@ -62,12 +62,11 @@ #include "guisan/platform.hpp" -extern "C" -{ - /** - * Exists to be able to check for Guichan OpenGL with autotools. - */ - GCN_EXTENSION_DECLSPEC extern void gcnOpenGL(); +extern "C" { +/** + * Exists to be able to check for Guichan OpenGL with autotools. + */ +GCN_EXTENSION_DECLSPEC extern void gcnOpenGL(); } #endif // end GCN_OPENGL_HPP diff --git a/external/libguisan/include/guisan/opengl/openglgraphics.hpp b/external/libguisan/include/guisan/opengl/openglgraphics.hpp index 0456234f..c7f9d40e 100644 --- a/external/libguisan/include/guisan/opengl/openglgraphics.hpp +++ b/external/libguisan/include/guisan/opengl/openglgraphics.hpp @@ -63,79 +63,79 @@ namespace gcn { - /** - * OpenGL implementation of the Graphics. - */ - class GCN_EXTENSION_DECLSPEC OpenGLGraphics: public Graphics - { - public: + /** + * OpenGL implementation of the Graphics. + */ + class GCN_EXTENSION_DECLSPEC OpenGLGraphics : public Graphics + { + public: - // Needed so that drawImage(gcn::Image *, int, int) is visible. - using Graphics::drawImage; + // Needed so that drawImage(gcn::Image *, int, int) is visible. + using Graphics::drawImage; - /** - * Constructor. - */ - OpenGLGraphics(); + /** + * Constructor. + */ + OpenGLGraphics(); - /** - * Constructor. + /** + * Constructor. * * @param width the width of the logical drawing surface. Should be the - * same as the screen resolution. + * same as the screen resolution. * * @param height the height ot the logical drawing surface. Should be * the same as the screen resolution. */ - OpenGLGraphics(int width, int height); + OpenGLGraphics(int width, int height); /** * Destructor. */ - virtual ~OpenGLGraphics(); + virtual ~OpenGLGraphics(); - /** - * Sets the target plane on where to draw. + /** + * Sets the target plane on where to draw. * * @param width the width of the logical drawing surface. Should be the * same as the screen resolution. * @param height the height ot the logical drawing surface. Should be * the same as the screen resolution. - */ - virtual void setTargetPlane(int width, int height); + */ + virtual void setTargetPlane(int width, int height); // Inherited from Graphics - virtual void _beginDraw(); + void _beginDraw() override; - virtual void _endDraw(); + void _endDraw() override; - virtual bool pushClipArea(Rectangle area); + bool pushClipArea(Rectangle area) override; - virtual void popClipArea(); + void popClipArea() override; - virtual void drawImage(const Image* image, int srcX, int srcY, - int dstX, int dstY, int width, - int height); + void drawImage(const Image* image, int srcX, int srcY, + int dstX, int dstY, int width, + int height) override; - virtual void drawPoint(int x, int y); + void drawPoint(int x, int y) override; - virtual void drawLine(int x1, int y1, int x2, int y2); + void drawLine(int x1, int y1, int x2, int y2) override; - virtual void drawRectangle(const Rectangle& rectangle); + void drawRectangle(const Rectangle& rectangle) override; - virtual void fillRectangle(const Rectangle& rectangle); + void fillRectangle(const Rectangle& rectangle) override; - virtual void setColor(const Color& color); + void setColor(const Color& color) override; - virtual const Color& getColor(); + const Color& getColor() override; - protected: - int mWidth, mHeight; + protected: + int mWidth, mHeight; bool mAlpha; - Color mColor; - }; + Color mColor; + }; } #endif // end GCN_OPENGLGRAPHICS_HPP diff --git a/external/libguisan/include/guisan/opengl/openglimage.hpp b/external/libguisan/include/guisan/opengl/openglimage.hpp index 2ca9a353..93fbf2aa 100644 --- a/external/libguisan/include/guisan/opengl/openglimage.hpp +++ b/external/libguisan/include/guisan/opengl/openglimage.hpp @@ -79,93 +79,92 @@ namespace gcn { - /** - * OpenGL implementation of Image. - */ - class GCN_EXTENSION_DECLSPEC OpenGLImage : public Image - { - public: - /** - * Constructor. Loads an image from an array of pixels. The pixel array is + /** + * OpenGL implementation of Image. + */ + class GCN_EXTENSION_DECLSPEC OpenGLImage : public Image + { + public: + /** + * Constructor. Loads an image from an array of pixels. The pixel array is * is copied in the constructor and should thus be freed after the constructor * has been called. - * - * NOTE: The functions getPixel and putPixel are only guaranteed to work - * before an image has been converted to display format. - * - * @param pixels to load from. - * @param width the width of the image. - * @param height the height of the image. - * @param convertToDisplayFormat true if the image should be converted - * to display, false otherwise. - */ - OpenGLImage(unsigned int* pixels, int width, int height, bool convertToDisplayFormat = true); + * + * NOTE: The functions getPixel and putPixel are only guaranteed to work + * before an image has been converted to display format. + * + * @param pixels to load from. + * @param width the width of the image. + * @param height the height of the image. + * @param convertToDisplayFormat true if the image should be converted + * to display, false otherwise. + */ + OpenGLImage(unsigned int* pixels, int width, int height, bool convertToDisplayFormat = true); - /** - * Constructor. Load an image from an OpenGL texture handle. The width + /** + * Constructor. Load an image from an OpenGL texture handle. The width * and height specifies the size of the "interesting" part of the * texture, the real width and height of the texture are assumed to * be the closest higher power of two. - * - * @param textureHandle the texture handle from which to load. + * + * @param textureHandle the texture handle from which to load. * @param width the width of the image. * @param height the height of the image. - * @param autoFree true if the surface should automatically be deleted. - */ - OpenGLImage(GLuint textureHandle, int width, int height, bool autoFree); + * @param autoFree true if the surface should automatically be deleted. + */ + OpenGLImage(GLuint textureHandle, int width, int height, bool autoFree); - /** - * Destructor. - */ - virtual ~OpenGLImage(); + /** + * Destructor. + */ + virtual ~OpenGLImage(); - /** - * Gets the OpenGL texture handle for the image. - * - * @return the OpenGL texture handle for the image. - */ + /** + * Gets the OpenGL texture handle for the image. + * + * @return the OpenGL texture handle for the image. + */ - virtual GLuint getTextureHandle() const; + [[nodiscard]] virtual GLuint getTextureHandle() const; - /** - * Gets the width of texture. - * - * @return the width of the texture. - */ - virtual int getTextureWidth() const; + /** + * Gets the width of texture. + * + * @return the width of the texture. + */ + [[nodiscard]] virtual int getTextureWidth() const; - /** - * Gets the height of the texture. - * - * @return the height of the texture. - */ - virtual int getTextureHeight() const; + /** + * Gets the height of the texture. + * + * @return the height of the texture. + */ + [[nodiscard]] virtual int getTextureHeight() const; - // Inherited from Image + // Inherited from Image - virtual void free(); + void free() override; - virtual int getWidth() const; + [[nodiscard]] int getWidth() const override; - virtual int getHeight() const; + [[nodiscard]] int getHeight() const override; - virtual Color getPixel(int x, int y); + Color getPixel(int x, int y) override; - virtual void putPixel(int x, int y, const Color& color); + void putPixel(int x, int y, const Color& color) override; - virtual void convertToDisplayFormat(); + void convertToDisplayFormat() override; - protected: - GLuint mTextureHandle; - unsigned int* mPixels; - bool mAutoFree; - int mWidth; - int mHeight; + protected: + GLuint mTextureHandle; + unsigned int* mPixels; + bool mAutoFree; + int mWidth; + int mHeight; int mTextureWidth; int mTextureHeight; - - }; + }; } #endif // end GCN_OPENGLIMAGE_HPP diff --git a/external/libguisan/include/guisan/opengl/openglsdlimageloader.hpp b/external/libguisan/include/guisan/opengl/openglsdlimageloader.hpp index a4e0dfff..90aee2a0 100644 --- a/external/libguisan/include/guisan/opengl/openglsdlimageloader.hpp +++ b/external/libguisan/include/guisan/opengl/openglsdlimageloader.hpp @@ -64,46 +64,46 @@ namespace gcn { - class Image; + class Image; - /** - * OpenGL ImageLoader that loads images with SDL. - */ - class OpenGLSDLImageLoader : public SDLImageLoader - { - public: + /** + * OpenGL ImageLoader that loads images with SDL. + */ + class OpenGLSDLImageLoader : public SDLImageLoader + { + public: - // Inherited from ImageLoader + // Inherited from ImageLoader - virtual Image* load(const std::string& filename, - bool convertToDisplayFormat = true) - { - SDL_Surface *loadedSurface = loadSDLSurface(filename); + Image* load(const std::string& filename, + bool convertToDisplayFormat = true) override + { + SDL_Surface* loadedSurface = loadSDLSurface(filename); - if (loadedSurface == NULL) - { - throw GCN_EXCEPTION( - std::string("Unable to load image file: ") + filename); - } + if (loadedSurface == nullptr) + { + throw GCN_EXCEPTION( + std::string("Unable to load image file: ") + filename); + } - SDL_Surface *surface = convertToStandardFormat(loadedSurface); - SDL_FreeSurface(loadedSurface); + SDL_Surface* surface = convertToStandardFormat(loadedSurface); + SDL_FreeSurface(loadedSurface); - if (surface == NULL) - { - throw GCN_EXCEPTION( - std::string("Not enough memory to load: ") + filename); - } + if (surface == nullptr) + { + throw GCN_EXCEPTION( + std::string("Not enough memory to load: ") + filename); + } - OpenGLImage *image = new OpenGLImage((unsigned int*)surface->pixels, - surface->w, - surface->h, - convertToDisplayFormat); - SDL_FreeSurface(surface); + OpenGLImage* image = new OpenGLImage(static_cast(surface->pixels), + surface->w, + surface->h, + convertToDisplayFormat); + SDL_FreeSurface(surface); - return image; - } - }; + return image; + } + }; } #endif // end GCN_OPENGLSDLIMAGELOADER_HPP diff --git a/external/libguisan/include/guisan/rectangle.hpp b/external/libguisan/include/guisan/rectangle.hpp index 649ff0e7..1b2a4a9f 100644 --- a/external/libguisan/include/guisan/rectangle.hpp +++ b/external/libguisan/include/guisan/rectangle.hpp @@ -61,58 +61,58 @@ namespace gcn { - /** - * Represents a rectangle. - */ - class GCN_CORE_DECLSPEC Rectangle - { - public: + /** + * Represents a rectangle. + */ + class GCN_CORE_DECLSPEC Rectangle + { + public: - /** - * Constructor. Resets member variables. - */ - Rectangle(); + /** + * Constructor. Resets member variables. + */ + Rectangle(); - /** - * Constructor. - * - * @param x the Rectangle x coordinate. - * @param y the Rectangle y coordinate. - * @param width the Rectangle width. - * @param height the Rectangle height. - */ - Rectangle(int x, int y, int width, int height); + /** + * Constructor. + * + * @param x the Rectangle x coordinate. + * @param y the Rectangle y coordinate. + * @param width the Rectangle width. + * @param height the Rectangle height. + */ + Rectangle(int x, int y, int width, int height); - /** - * Sets the dimension of a rectangle. - * - * @param x the Rectangle x coordinate. - * @param y the Rectangle y coordinate. - * @param width the Rectangle width. - * @param height the Rectangle height. - */ - void setAll(int x, int y, int width, int height); + /** + * Sets the dimension of a rectangle. + * + * @param x the Rectangle x coordinate. + * @param y the Rectangle y coordinate. + * @param width the Rectangle width. + * @param height the Rectangle height. + */ + void setAll(int x, int y, int width, int height); - /** - * Checks if another Rectangle intersects with the Rectangle. - * - * @param rectangle another Rectangle. - */ - bool intersect(const Rectangle& rectangle); + /** + * Checks if another Rectangle intersects with the Rectangle. + * + * @param rectangle another Rectangle. + */ + bool intersect(const Rectangle& rectangle); - /** - * Checks if a point is inside the Rectangle. - * - * @param x the point x coordinate. - * @param y the point y coordinate. - */ - bool isPointInRect(int x, int y) const; + /** + * Checks if a point is inside the Rectangle. + * + * @param x the point x coordinate. + * @param y the point y coordinate. + */ + [[nodiscard]] bool isPointInRect(int x, int y) const; - int x; - int y; - int width; - int height; - }; + int x; + int y; + int width; + int height; + }; } #endif // end GCN_RECTANGEL_HPP diff --git a/external/libguisan/include/guisan/sdl.hpp b/external/libguisan/include/guisan/sdl.hpp index e73f0cfd..852c7e3d 100644 --- a/external/libguisan/include/guisan/sdl.hpp +++ b/external/libguisan/include/guisan/sdl.hpp @@ -66,12 +66,11 @@ #include "platform.hpp" -extern "C" -{ - /** - * Exists to be able to check for Guichan SDL with autotools. - */ - GCN_EXTENSION_DECLSPEC extern void gcnSDL(); +extern "C" { +/** + * Exists to be able to check for Guichan SDL with autotools. + */ +GCN_EXTENSION_DECLSPEC extern void gcnSDL(); } #endif // end GCN_SDL_HPP diff --git a/external/libguisan/include/guisan/sdl/sdl2graphics.hpp b/external/libguisan/include/guisan/sdl/sdl2graphics.hpp index 1d0e1df4..f3476d55 100644 --- a/external/libguisan/include/guisan/sdl/sdl2graphics.hpp +++ b/external/libguisan/include/guisan/sdl/sdl2graphics.hpp @@ -102,7 +102,7 @@ namespace gcn * * @return the target SDL_Renderer. */ - virtual SDL_Renderer* getTarget() const; + [[nodiscard]] virtual SDL_Renderer* getTarget() const; /** * Draws an SDL_Surface on the target surface. Normally you'll @@ -180,11 +180,11 @@ namespace gcn */ virtual void restoreRenderColor(); - SDL_Surface* mTarget; - SDL_Renderer* mRenderTarget; - SDL_Texture* mTexture; + SDL_Surface* mTarget{}; + SDL_Renderer* mRenderTarget{}; + SDL_Texture* mTexture{}; Color mColor; - Uint8 r, g, b, a; //! to store previous color from renderer + Uint8 r{}, g{}, b{}, a{}; //! to store previous color from renderer bool mAlpha; }; } diff --git a/external/libguisan/include/guisan/sdl/sdlgraphics.hpp b/external/libguisan/include/guisan/sdl/sdlgraphics.hpp index 42d18e8b..5f635485 100644 --- a/external/libguisan/include/guisan/sdl/sdlgraphics.hpp +++ b/external/libguisan/include/guisan/sdl/sdlgraphics.hpp @@ -65,105 +65,105 @@ namespace gcn { - class Image; - class Rectangle; + class Image; + class Rectangle; - /** - * SDL implementation of the Graphics. - */ - class GCN_EXTENSION_DECLSPEC SDLGraphics : public Graphics - { - public: + /** + * SDL implementation of the Graphics. + */ + class GCN_EXTENSION_DECLSPEC SDLGraphics : public Graphics + { + public: - // Needed so that drawImage(gcn::Image *, int, int) is visible. - using Graphics::drawImage; + // Needed so that drawImage(gcn::Image *, int, int) is visible. + using Graphics::drawImage; + + /** + * Constructor. + */ + SDLGraphics(); - /** - * Constructor. - */ - SDLGraphics(); - /** * Destructor. */ ~SDLGraphics(); - - /** - * Sets the target SDL_Surface to draw to. The target can be any - * SDL_Surface. This function also pushes a clip areas corresponding to - * the dimension of the target. - * - * @param target the target to draw to. - */ - virtual void setTarget(SDL_Surface* target); - /** - * Gets the target SDL_Surface. - * - * @return the target SDL_Surface. - */ - virtual SDL_Surface* getTarget() const; + /** + * Sets the target SDL_Surface to draw to. The target can be any + * SDL_Surface. This function also pushes a clip areas corresponding to + * the dimension of the target. + * + * @param target the target to draw to. + */ + virtual void setTarget(SDL_Surface* target); - /** - * Draws an SDL_Surface on the target surface. Normally you'll - * use drawImage, but if you want to write SDL specific code - * this function might come in handy. - * - * NOTE: The clip areas will be taken into account. - */ - virtual void drawSDLSurface(SDL_Surface* surface, SDL_Rect source, - SDL_Rect destination); + /** + * Gets the target SDL_Surface. + * + * @return the target SDL_Surface. + */ + [[nodiscard]] virtual SDL_Surface* getTarget() const; + + /** + * Draws an SDL_Surface on the target surface. Normally you'll + * use drawImage, but if you want to write SDL specific code + * this function might come in handy. + * + * NOTE: The clip areas will be taken into account. + */ + virtual void drawSDLSurface(SDL_Surface* surface, SDL_Rect source, + SDL_Rect destination); - // Inherited from Graphics + // Inherited from Graphics - virtual void _beginDraw(); + void _beginDraw() override; - virtual void _endDraw(); + void _endDraw() override; - virtual bool pushClipArea(Rectangle area); + bool pushClipArea(Rectangle area) override; - virtual void popClipArea(); + void popClipArea() override; - virtual void drawImage(const Image* image, int srcX, int srcY, - int dstX, int dstY, int width, - int height); + void drawImage(const Image* image, int srcX, int srcY, + int dstX, int dstY, int width, + int height) override; - virtual void drawPoint(int x, int y); + void drawPoint(int x, int y) override; - virtual void drawLine(int x1, int y1, int x2, int y2); + void drawLine(int x1, int y1, int x2, int y2) override; - virtual void drawRectangle(const Rectangle& rectangle); + void drawRectangle(const Rectangle& rectangle) override; - virtual void fillRectangle(const Rectangle& rectangle); + void fillRectangle(const Rectangle& rectangle) override; - virtual void setColor(const Color& color); + void setColor(const Color& color) override; - virtual const Color& getColor(); + const Color& getColor() override; - protected: - /** - * Draws a horizontal line. - * - * @param x1 the start coordinate of the line. - * @param y the y coordinate of the line. - * @param x2 the end coordinate of the line. - */ - virtual void drawHLine(int x1, int y, int x2); + protected: + /** + * Draws a horizontal line. + * + * @param x1 the start coordinate of the line. + * @param y the y coordinate of the line. + * @param x2 the end coordinate of the line. + */ + virtual void drawHLine(int x1, int y, int x2); - /** - * Draws a vertical line. - * - * @param x the x coordinate of the line. - * @param y1 the start coordinate of the line. - * @param y2 the end coordinate of the line. - */ - virtual void drawVLine(int x, int y1, int y2); + /** + * Draws a vertical line. + * + * @param x the x coordinate of the line. + * @param y1 the start coordinate of the line. + * @param y2 the end coordinate of the line. + */ + virtual void drawVLine(int x, int y1, int y2); - SDL_Surface* mTarget; - Color mColor; - bool mAlpha; - }; + SDL_Surface* mTarget{}; + Color mColor; + bool mAlpha; + }; } #endif // end GCN_SDLGRAPHICS_HPP diff --git a/external/libguisan/include/guisan/sdl/sdlimage.hpp b/external/libguisan/include/guisan/sdl/sdlimage.hpp index 5b9a33a6..30b52fd9 100644 --- a/external/libguisan/include/guisan/sdl/sdlimage.hpp +++ b/external/libguisan/include/guisan/sdl/sdlimage.hpp @@ -67,63 +67,63 @@ namespace gcn { - /** - * SDL implementation of Image. - */ - class GCN_EXTENSION_DECLSPEC SDLImage : public Image - { - public: - /** - * Constructor. Load an image from an SDL surface. - * - * NOTE: The functions getPixel and putPixel are only guaranteed to work - * before an image has been converted to display format. - * - * @param surface the surface from which to load. - * @param autoFree true if the surface should automatically be deleted. - * @param renderer renderer object to create the texture (last parameter to avoid breaking stuff) - */ - SDLImage(SDL_Surface* surface, bool autoFree, SDL_Renderer* renderer = NULL); + /** + * SDL implementation of Image. + */ + class GCN_EXTENSION_DECLSPEC SDLImage : public Image + { + public: + /** + * Constructor. Load an image from an SDL surface. + * + * NOTE: The functions getPixel and putPixel are only guaranteed to work + * before an image has been converted to display format. + * + * @param surface the surface from which to load. + * @param autoFree true if the surface should automatically be deleted. + * @param renderer renderer object to create the texture (last parameter to avoid breaking stuff) + */ + SDLImage(SDL_Surface* surface, bool autoFree, SDL_Renderer* renderer = nullptr); - /** - * Destructor. - */ - virtual ~SDLImage(); + /** + * Destructor. + */ + virtual ~SDLImage(); + + /** + * Gets the SDL surface for the image. + * + * @return the SDL surface for the image. + */ + [[nodiscard]] virtual SDL_Surface* getSurface() const; - /** - * Gets the SDL surface for the image. - * - * @return the SDL surface for the image. - */ - virtual SDL_Surface* getSurface() const; - /** * Gets the SDL texture for the image. - * - * @return the SDL texture for the image. + * + * @return the SDL texture for the image. */ - virtual SDL_Texture* getTexture() const; + [[nodiscard]] virtual SDL_Texture* getTexture() const; - // Inherited from Image + // Inherited from Image - virtual void free(); + void free() override; - virtual int getWidth() const; + [[nodiscard]] int getWidth() const override; - virtual int getHeight() const; + [[nodiscard]] int getHeight() const override; - virtual Color getPixel(int x, int y); + Color getPixel(int x, int y) override; - virtual void putPixel(int x, int y, const Color& color); + void putPixel(int x, int y, const Color& color) override; - virtual void convertToDisplayFormat(); + void convertToDisplayFormat() override; - protected: - SDL_Surface* mSurface; - SDL_Texture* mTexture = NULL; - SDL_Renderer* mRenderer = NULL; - bool mAutoFree; - }; + protected: + SDL_Surface* mSurface; + SDL_Texture* mTexture{}; + SDL_Renderer* mRenderer{}; + bool mAutoFree; + }; } #endif // end GCN_SDLIMAGE_HPP diff --git a/external/libguisan/include/guisan/sdl/sdlinput.hpp b/external/libguisan/include/guisan/sdl/sdlinput.hpp index 37f8701d..033a5bc6 100644 --- a/external/libguisan/include/guisan/sdl/sdlinput.hpp +++ b/external/libguisan/include/guisan/sdl/sdlinput.hpp @@ -68,71 +68,73 @@ namespace gcn { - class Key; + class Key; - /** - * SDL implementation of Input. - */ - class GCN_EXTENSION_DECLSPEC SDLInput : public Input - { - public: + /** + * SDL implementation of Input. + */ + class GCN_EXTENSION_DECLSPEC SDLInput : public Input + { + public: - /** - * Constructor. - */ - SDLInput(); + /** + * Constructor. + */ + SDLInput(); - /** - * Pushes an SDL event. It should be called at least once per frame to - * update input with user input. - * - * @param event an event from SDL. - */ - virtual void pushInput(SDL_Event event); + /** + * Pushes an SDL event. It should be called at least once per frame to + * update input with user input. + * + * @param event an event from SDL. + */ + virtual void pushInput(SDL_Event event); - /** - * Polls all input. It exists for input driver compatibility. If you - * only use SDL and plan sticking with SDL you can safely ignore this - * function as it in the SDL case does nothing. - */ - virtual void _pollInput() { } + /** + * Polls all input. It exists for input driver compatibility. If you + * only use SDL and plan sticking with SDL you can safely ignore this + * function as it in the SDL case does nothing. + */ + void _pollInput() override + { + } - // Inherited from Input + // Inherited from Input - virtual bool isKeyQueueEmpty(); + bool isKeyQueueEmpty() override; - virtual KeyInput dequeueKeyInput(); + KeyInput dequeueKeyInput() override; - virtual bool isMouseQueueEmpty(); + bool isMouseQueueEmpty() override; - virtual MouseInput dequeueMouseInput(); + MouseInput dequeueMouseInput() override; - protected: - /** - * Converts a mouse button from SDL to a Guisan mouse button - * representation. - * - * @param button an SDL mouse button. - * @return a Guisan mouse button. - */ - int convertMouseButton(int button); + protected: + /** + * Converts a mouse button from SDL to a Guisan mouse button + * representation. + * + * @param button an SDL mouse button. + * @return a Guisan mouse button. + */ + static int convertMouseButton(int button); - /** - * Converts an SDL event key to a key value. - * - * @param event an SDL event with a key to convert. - * @return a key value. - * @see Key - */ - int convertKeyCharacter(SDL_Event event); + /** + * Converts an SDL event key to a key value. + * + * @param event an SDL event with a key to convert. + * @return a key value. + * @see Key + */ + static int convertKeyCharacter(SDL_Event event); - std::queue mKeyInputQueue; - std::queue mMouseInputQueue; + std::queue mKeyInputQueue; + std::queue mMouseInputQueue; - bool mMouseDown; - bool mMouseInWindow; - }; + bool mMouseDown; + bool mMouseInWindow; + }; } #endif // end GCN_SDLINPUT_HPP diff --git a/external/libguisan/include/guisan/sdl/sdltruetypefont.hpp b/external/libguisan/include/guisan/sdl/sdltruetypefont.hpp index 3e151cfe..ddf4ae13 100644 --- a/external/libguisan/include/guisan/sdl/sdltruetypefont.hpp +++ b/external/libguisan/include/guisan/sdl/sdltruetypefont.hpp @@ -55,7 +55,7 @@ namespace gcn { class Graphics; - + /** * SDL True Type Font implementation of Font. It uses the SDL_ttf library * to display True Type Fonts with SDL. @@ -67,7 +67,7 @@ namespace gcn * @author Walluce Pinkham * @author Olof NaessĂŠn */ - class GCN_EXTENSION_DECLSPEC SDLTrueTypeFont: public Font + class GCN_EXTENSION_DECLSPEC SDLTrueTypeFont : public Font { public: @@ -77,28 +77,28 @@ namespace gcn * @param filename the filename of the True Type Font. * @param size the size the font should be in. */ - SDLTrueTypeFont (const std::string& filename, int size); + SDLTrueTypeFont(const std::string& filename, int size); /** * Destructor. */ virtual ~SDLTrueTypeFont(); - + /** * Sets the spacing between rows in pixels. Default is 0 pixels. * The spacing can be negative. * * @param spacing the spacing in pixels. */ - virtual void setRowSpacing (int spacing); - + virtual void setRowSpacing(int spacing); + /** * Gets the spacing between rows in pixels. * * @return the spacing. */ virtual int getRowSpacing(); - + /** * Sets the spacing between letters in pixels. Default is 0 pixels. * The spacing can be negative. @@ -113,41 +113,40 @@ namespace gcn * @return the spacing. */ virtual int getGlyphSpacing(); - + /** * Sets the use of anti aliasing.. * - * @param antaAlias true for use of antialiasing. + * @param antiAlias true for use of anti-aliasing. */ virtual void setAntiAlias(bool antiAlias); - + /** * Checks if anti aliasing is used. * * @return true if anti aliasing is used. */ virtual bool isAntiAlias(); - - + + // Inherited from Font - - virtual int getWidth(const std::string& text) const; - - virtual int getHeight() const; - - virtual void drawString(Graphics* graphics, const std::string& text, int x, int y); - + + [[nodiscard]] int getWidth(const std::string& text) const override; + + [[nodiscard]] int getHeight() const override; + + void drawString(Graphics* graphics, const std::string& text, int x, int y) override; + protected: - TTF_Font *mFont; - - int mHeight; + TTF_Font* mFont; + + int mHeight{}; int mGlyphSpacing; int mRowSpacing; - + std::string mFilename; - bool mAntiAlias; - }; + bool mAntiAlias; + }; } #endif - diff --git a/external/libguisan/include/guisan/selectionevent.hpp b/external/libguisan/include/guisan/selectionevent.hpp index 47646084..42401d68 100644 --- a/external/libguisan/include/guisan/selectionevent.hpp +++ b/external/libguisan/include/guisan/selectionevent.hpp @@ -62,30 +62,30 @@ namespace gcn { - class Widget; + class Widget; - /** - * Represents a selection event. - * - * @author Olof Naessén - * @since 0.8.0 - */ - class GCN_CORE_DECLSPEC SelectionEvent: public Event - { - public: + /** + * Represents a selection event. + * + * @author Olof Naessén + * @since 0.8.0 + */ + class GCN_CORE_DECLSPEC SelectionEvent : public Event + { + public: - /** - * Constructor. - * - * @param source the source widget of the event. - */ - SelectionEvent(Widget* source); + /** + * Constructor. + * + * @param source the source widget of the event. + */ + SelectionEvent(Widget* source); - /** - * Destructor. - */ - virtual ~SelectionEvent(); - }; + /** + * Destructor. + */ + virtual ~SelectionEvent(); + }; } #endif // end GCN_SELECTIONEVENT_HPP diff --git a/external/libguisan/include/guisan/selectionlistener.hpp b/external/libguisan/include/guisan/selectionlistener.hpp index e7cfd442..fa072965 100644 --- a/external/libguisan/include/guisan/selectionlistener.hpp +++ b/external/libguisan/include/guisan/selectionlistener.hpp @@ -64,34 +64,36 @@ namespace gcn { - /** - * Listener of value change events from Widgets. To be able to - * listen for value changes you must make a class which inherits - * from this class and implements the valueChanged function. - * - * @see ListBox::addSelectionListener - * @author Olof Naessén - * @since 0.8.0 - */ - class GCN_CORE_DECLSPEC SelectionListener - { - public: + /** + * Listener of value change events from Widgets. To be able to + * listen for value changes you must make a class which inherits + * from this class and implements the valueChanged function. + * + * @see ListBox::addSelectionListener + * @author Olof Naessén + * @since 0.8.0 + */ + class GCN_CORE_DECLSPEC SelectionListener + { + public: - /** - * Destructor. - */ - virtual ~SelectionListener() { } + /** + * Destructor. + */ + virtual ~SelectionListener() + = default; - /** - * Called when a value has been changed in a Widget. It is used - * to be able to recieve a notification that a value has been changed. - * - * @param event the event of the value change. - * @since 0.8.0 - */ - virtual void valueChanged(const SelectionEvent& event) { }; - - }; + /** + * Called when a value has been changed in a Widget. It is used + * to be able to recieve a notification that a value has been changed. + * + * @param event the event of the value change. + * @since 0.8.0 + */ + virtual void valueChanged(const SelectionEvent& event) + { + } + }; } #endif // end GCN_SELECTIONLISTENER_HPP diff --git a/external/libguisan/include/guisan/widget.hpp b/external/libguisan/include/guisan/widget.hpp index b2c5cb05..7706ea1d 100644 --- a/external/libguisan/include/guisan/widget.hpp +++ b/external/libguisan/include/guisan/widget.hpp @@ -119,7 +119,7 @@ namespace gcn /** * Draws the widget border. A border is drawn around a widget. * The width and height of the border is therefore the widgets - * height+2*bordersize. Think of a painting that has a certain size, + * height + 2 * border size. Think of a painting that has a certain size, * the border surrounds the painting. * * @param graphics a Graphics object to draw with. diff --git a/external/libguisan/include/guisan/widgetlistener.hpp b/external/libguisan/include/guisan/widgetlistener.hpp index d63a7f16..8e7daa2d 100644 --- a/external/libguisan/include/guisan/widgetlistener.hpp +++ b/external/libguisan/include/guisan/widgetlistener.hpp @@ -64,60 +64,68 @@ namespace gcn { - /** - * Listener on events from a Widget. Whenever a widget changes it's - * size or position the listener of a widget will get notified. To be able to - * listen for events from a widget you must make a class which inherits - * from this class and implements it's functions. - * - * @see Widget::addWidgetListener - * @author Olof Naessén - * @since 0.8.0 - */ - class GCN_CORE_DECLSPEC WidgetListener - { - public: + /** + * Listener on events from a Widget. Whenever a widget changes it's + * size or position the listener of a widget will get notified. To be able to + * listen for events from a widget you must make a class which inherits + * from this class and implements it's functions. + * + * @see Widget::addWidgetListener + * @author Olof Naessén + * @since 0.8.0 + */ + class GCN_CORE_DECLSPEC WidgetListener + { + public: - /** - * Destructor. - */ - virtual ~WidgetListener() { } + /** + * Destructor. + */ + virtual ~WidgetListener() + = default; - /** - * Invoked when a widget changes its size. - * - * @param event Describes the event. - * @since 0.8.0 - */ - virtual void widgetResized(const Event& event) { } + /** + * Invoked when a widget changes its size. + * + * @param event Describes the event. + * @since 0.8.0 + */ + virtual void widgetResized(const Event& event) + { + } - /** - * Invoked when a widget is moved. - * - * @param event Describes the event. - * @since 0.8.0 - */ - virtual void widgetMoved(const Event& event) { } + /** + * Invoked when a widget is moved. + * + * @param event Describes the event. + * @since 0.8.0 + */ + virtual void widgetMoved(const Event& event) + { + } - /** - * Invoked when a widget is hidden, i.e it's set to be - * not visible. - * - * @param event Describes the event. - * @since 0.8.0 - */ - virtual void widgetHidden(const Event& event) { } + /** + * Invoked when a widget is hidden, i.e it's set to be + * not visible. + * + * @param event Describes the event. + * @since 0.8.0 + */ + virtual void widgetHidden(const Event& event) + { + } - /** - * Invoked when a widget is shown, i.e it's set to be - * visible. - * - * @param event Describes the event. - * @since 0.8.0 - */ - virtual void widgetShown(const Event& event) { } - - }; + /** + * Invoked when a widget is shown, i.e it's set to be + * visible. + * + * @param event Describes the event. + * @since 0.8.0 + */ + virtual void widgetShown(const Event& event) + { + } + }; } #endif // end GCN_WIDGETLISTENER_HPP diff --git a/external/libguisan/include/guisan/widgets/button.hpp b/external/libguisan/include/guisan/widgets/button.hpp index bba0c260..ec214c67 100644 --- a/external/libguisan/include/guisan/widgets/button.hpp +++ b/external/libguisan/include/guisan/widgets/button.hpp @@ -68,128 +68,128 @@ namespace gcn { - /** - * A regular button. Add an ActionListener to it to know when it - * has been clicked. - * - * NOTE: You can only have text (a caption) on the button. If you want it - * to handle, for instance images, you can implement an ImageButton - * of your own and overload member functions from Button. - */ - class GCN_CORE_DECLSPEC Button : public Widget, - public MouseListener, - public KeyListener, - public FocusListener - { - public: - /** - * Constructor. - */ - Button(); + /** + * A regular button. Add an ActionListener to it to know when it + * has been clicked. + * + * NOTE: You can only have text (a caption) on the button. If you want it + * to handle, for instance images, you can implement an ImageButton + * of your own and overload member functions from Button. + */ + class GCN_CORE_DECLSPEC Button : public Widget, + public MouseListener, + public KeyListener, + public FocusListener + { + public: + /** + * Constructor. + */ + Button(); - /** - * Constructor. - * - * @param caption the caption of the Button. - */ - explicit Button(std::string caption); + /** + * Constructor. + * + * @param caption the caption of the Button. + */ + explicit Button(std::string caption); - /** - * Sets the Button caption. - * - * @param caption the Button caption. - */ - void setCaption(const std::string& caption); + /** + * Sets the Button caption. + * + * @param caption the Button caption. + */ + void setCaption(const std::string& caption); - /** - * Gets the Button caption. - * - * @return the Button caption. - */ - [[nodiscard]] const std::string& getCaption() const; + /** + * Gets the Button caption. + * + * @return the Button caption. + */ + [[nodiscard]] const std::string& getCaption() const; - /** - * Sets the alignment for the caption. - * - * @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT - * @see Graphics - */ - virtual void setAlignment(unsigned int alignment); + /** + * Sets the alignment for the caption. + * + * @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT + * @see Graphics + */ + virtual void setAlignment(unsigned int alignment); - /** - * Gets the alignment for the caption. - * - * @return alignment of caption. - */ - [[nodiscard]] virtual unsigned int getAlignment() const; + /** + * Gets the alignment for the caption. + * + * @return alignment of caption. + */ + [[nodiscard]] virtual unsigned int getAlignment() const; - /** - * Sets the spacing between the border of this button and its caption. - * - * @param spacing is a number between 0 and 255. The default value for - spacing is 4 and can be changed using this method. - */ - void setSpacing(unsigned int spacing); + /** + * Sets the spacing between the border of this button and its caption. + * + * @param spacing is a number between 0 and 255. The default value for + spacing is 4 and can be changed using this method. + */ + void setSpacing(unsigned int spacing); - /** - * Gets the spacing between the border of this button and its caption. - * - * @return spacing. - */ - [[nodiscard]] unsigned int getSpacing() const; + /** + * Gets the spacing between the border of this button and its caption. + * + * @return spacing. + */ + [[nodiscard]] unsigned int getSpacing() const; - /** - * Adjusts the buttons size to fit the content. - */ - virtual void adjustSize(); + /** + * Adjusts the buttons size to fit the content. + */ + virtual void adjustSize(); - /** - * Checks if the button is pressed down. Useful when drawing. - * - * @return true if the button is pressed down. - */ - [[nodiscard]] bool isPressed() const; + /** + * Checks if the button is pressed down. Useful when drawing. + * + * @return true if the button is pressed down. + */ + [[nodiscard]] bool isPressed() const; - //Inherited from Widget + //Inherited from Widget - void draw(Graphics* graphics) override; + void draw(Graphics* graphics) override; - void drawBorder(Graphics* graphics) override; + void drawBorder(Graphics* graphics) override; - // Inherited from FocusListener + // Inherited from FocusListener - void focusLost(const Event& event) override; + void focusLost(const Event& event) override; - // Inherited from MouseListener + // Inherited from MouseListener - void mousePressed(MouseEvent& mouseEvent) override; + void mousePressed(MouseEvent& mouseEvent) override; - void mouseReleased(MouseEvent& mouseEvent) override; + void mouseReleased(MouseEvent& mouseEvent) override; - void mouseEntered(MouseEvent& mouseEvent) override; + void mouseEntered(MouseEvent& mouseEvent) override; - void mouseExited(MouseEvent& mouseEvent) override; + void mouseExited(MouseEvent& mouseEvent) override; - void mouseDragged(MouseEvent& mouseEvent) override; + void mouseDragged(MouseEvent& mouseEvent) override; - // Inherited from KeyListener + // Inherited from KeyListener - void keyPressed(KeyEvent& keyEvent) override; + void keyPressed(KeyEvent& keyEvent) override; - void keyReleased(KeyEvent& keyEvent) override; + void keyReleased(KeyEvent& keyEvent) override; - protected: - std::string mCaption; - bool mHasMouse; - bool mKeyPressed; - bool mMousePressed; - unsigned int mAlignment; - unsigned int mSpacing; - }; + protected: + std::string mCaption; + bool mHasMouse; + bool mKeyPressed; + bool mMousePressed; + unsigned int mAlignment; + unsigned int mSpacing; + }; } #endif // end GCN_BUTTON_HPP diff --git a/external/libguisan/include/guisan/widgets/checkbox.hpp b/external/libguisan/include/guisan/widgets/checkbox.hpp index b4270c4b..23748ef5 100644 --- a/external/libguisan/include/guisan/widgets/checkbox.hpp +++ b/external/libguisan/include/guisan/widgets/checkbox.hpp @@ -66,123 +66,124 @@ namespace gcn { - /** - * An implementation of a check box where a user can select or deselect - * the check box and where the status of the check box is displayed to the user. - * A check box is capable of displaying a caption. - * - * If a check box's state changes an action event will be sent to all action - * listeners of the check box. - */ - class GCN_CORE_DECLSPEC CheckBox : - public Widget, - public MouseListener, - public KeyListener - { - public: + /** + * An implementation of a check box where a user can select or deselect + * the check box and where the status of the check box is displayed to the user. + * A check box is capable of displaying a caption. + * + * If a check box's state changes an action event will be sent to all action + * listeners of the check box. + */ + class GCN_CORE_DECLSPEC CheckBox : + public Widget, + public MouseListener, + public KeyListener + { + public: - /** - * Contructor. - */ - CheckBox(); + /** + * Contructor. + */ + CheckBox(); - /** - * Constructor. The check box will be automatically resized - * to fit it's caption. - * - * @param caption The caption of the check box. - * @param marked True if the check box is selected, false otherwise. - */ - CheckBox(const std::string &caption, bool selected = false); + /** + * Constructor. The check box will be automatically resized + * to fit it's caption. + * + * @param caption The caption of the check box. + * @param marked True if the check box is selected, false otherwise. + */ + CheckBox(const std::string& caption, bool selected = false); - /** - * Destructor. - */ - virtual ~CheckBox() { } + /** + * Destructor. + */ + virtual ~CheckBox() + = default; - /** - * Checks if the check box is selected. - * - * @return True if the check box is selected, false otherwise. - * @see setSelected - */ - bool isSelected() const; + /** + * Checks if the check box is selected. + * + * @return True if the check box is selected, false otherwise. + * @see setSelected + */ + [[nodiscard]] bool isSelected() const; - /** - * Sets the check box to be selected. - * - * @param selected True if the check box should be set as selected. - * @see isSelected - */ - void setSelected(bool selected); + /** + * Sets the check box to be selected. + * + * @param selected True if the check box should be set as selected. + * @see isSelected + */ + void setSelected(bool selected); - /** - * Gets the caption of the check box. - * - * @return The caption of the check box. - * @see setCaption - */ - const std::string &getCaption() const; + /** + * Gets the caption of the check box. + * + * @return The caption of the check box. + * @see setCaption + */ + [[nodiscard]] const std::string& getCaption() const; - /** - * Sets the caption of the check box. It's advisable to call - * adjustSize after setting of the caption to adjust the - * check box's size to fit the caption. - * - * @param caption The caption of the check box. - * @see getCaption, adjustSize - */ - void setCaption(const std::string& caption); + /** + * Sets the caption of the check box. It's advisable to call + * adjustSize after setting of the caption to adjust the + * check box's size to fit the caption. + * + * @param caption The caption of the check box. + * @see getCaption, adjustSize + */ + void setCaption(const std::string& caption); - /** - * Adjusts the check box's size to fit the caption. - */ - void adjustSize(); + /** + * Adjusts the check box's size to fit the caption. + */ + void adjustSize(); - // Inherited from Widget + // Inherited from Widget - virtual void draw(Graphics* graphics); + void draw(Graphics* graphics) override; - virtual void drawBorder(Graphics* graphics); + void drawBorder(Graphics* graphics) override; - // Inherited from KeyListener + // Inherited from KeyListener - virtual void keyPressed(KeyEvent& keyEvent); + void keyPressed(KeyEvent& keyEvent) override; - // Inherited from MouseListener + // Inherited from MouseListener - virtual void mouseClicked(MouseEvent& mouseEvent); + void mouseClicked(MouseEvent& mouseEvent) override; - virtual void mouseDragged(MouseEvent& mouseEvent); + void mouseDragged(MouseEvent& mouseEvent) override; - protected: - /** - * Draws the box of the check box. - * - * @param graphics A Graphics object to draw with. - */ - virtual void drawBox(Graphics *graphics); + protected: + /** + * Draws the box of the check box. + * + * @param graphics A Graphics object to draw with. + */ + virtual void drawBox(Graphics* graphics); - /** - * Toggles the check box between being selected and - * not being selected. - */ - virtual void toggleSelected(); + /** + * Toggles the check box between being selected and + * not being selected. + */ + virtual void toggleSelected(); - /** - * True if the check box is selected, false otherwise. - */ - bool mSelected{}; + /** + * True if the check box is selected, false otherwise. + */ + bool mSelected{}; - /** - * Holds the caption of the check box. - */ - std::string mCaption; - }; + /** + * Holds the caption of the check box. + */ + std::string mCaption; + }; } #endif // end GCN_CHECKBOX_HPP diff --git a/external/libguisan/include/guisan/widgets/dropdown.hpp b/external/libguisan/include/guisan/widgets/dropdown.hpp index 8c8ec694..7d902964 100644 --- a/external/libguisan/include/guisan/widgets/dropdown.hpp +++ b/external/libguisan/include/guisan/widgets/dropdown.hpp @@ -181,7 +181,7 @@ namespace gcn * Returns the current Dropdown status */ [[nodiscard]] virtual bool isDroppedDown() const; - + // Inherited from Widget void draw(Graphics* graphics) override; diff --git a/external/libguisan/include/guisan/widgets/scrollarea.hpp b/external/libguisan/include/guisan/widgets/scrollarea.hpp index 126a692c..63661f25 100644 --- a/external/libguisan/include/guisan/widgets/scrollarea.hpp +++ b/external/libguisan/include/guisan/widgets/scrollarea.hpp @@ -410,42 +410,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. diff --git a/external/libguisan/src/actionevent.cpp b/external/libguisan/src/actionevent.cpp index b232b061..938125ef 100644 --- a/external/libguisan/src/actionevent.cpp +++ b/external/libguisan/src/actionevent.cpp @@ -58,25 +58,24 @@ * For comments regarding functions please see the header file. */ +#include + + #include "guisan/actionevent.hpp" namespace gcn { - ActionEvent::ActionEvent(Widget* source, const std::string& id) - :Event(source), - mId(id) - { + ActionEvent::ActionEvent(Widget* source, std::string id) + : Event(source), + mId(std::move(id)) + { + } - } + ActionEvent::~ActionEvent() + = default; - ActionEvent::~ActionEvent() - { - - } - - const std::string& ActionEvent::getId() const - { - return mId; - } + const std::string& ActionEvent::getId() const + { + return mId; + } } - diff --git a/external/libguisan/src/basiccontainer.cpp b/external/libguisan/src/basiccontainer.cpp index 08bd85a6..30d4b866 100644 --- a/external/libguisan/src/basiccontainer.cpp +++ b/external/libguisan/src/basiccontainer.cpp @@ -69,334 +69,322 @@ namespace gcn { - BasicContainer::~BasicContainer() - { - clear(); - } + BasicContainer::~BasicContainer() + { + BasicContainer::clear(); + } - void BasicContainer::moveToTop(Widget* widget) - { - WidgetListIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) - { - if (*iter == widget) - { - mWidgets.erase(iter); - mWidgets.push_back(widget); - return; - } - } + void BasicContainer::moveToTop(Widget* widget) + { + for (auto iter = mWidgets.begin(); iter != mWidgets.end(); ++iter) + { + if (*iter == widget) + { + mWidgets.erase(iter); + mWidgets.push_back(widget); + return; + } + } - throw GCN_EXCEPTION("There is no such widget in this container."); - } + throw GCN_EXCEPTION("There is no such widget in this container."); + } - void BasicContainer::moveToBottom(Widget* widget) - { - WidgetListIterator iter; - iter = find(mWidgets.begin(), mWidgets.end(), widget); + void BasicContainer::moveToBottom(Widget* widget) + { + const auto 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); - } + if (iter == mWidgets.end()) + { + throw GCN_EXCEPTION("There is no such widget in this container."); + } + mWidgets.erase(iter); + mWidgets.push_front(widget); + } - void BasicContainer::death(const Event& event) - { - WidgetListIterator iter; - iter = find(mWidgets.begin(), mWidgets.end(), event.getSource()); + void BasicContainer::death(const Event& event) + { + const auto iter = find(mWidgets.begin(), mWidgets.end(), event.getSource()); - if (iter == mWidgets.end()) - { - throw GCN_EXCEPTION("There is no such widget in this container."); - } + if (iter == mWidgets.end()) + { + throw GCN_EXCEPTION("There is no such widget in this container."); + } - mWidgets.erase(iter); - } + mWidgets.erase(iter); + } - Rectangle BasicContainer::getChildrenArea() - { - return Rectangle(0, 0, getWidth(), getHeight()); - } + Rectangle BasicContainer::getChildrenArea() + { + return Rectangle(0, 0, getWidth(), getHeight()); + } - void BasicContainer::focusNext() - { - WidgetListIterator it; + void BasicContainer::focusNext() + { + WidgetListIterator it; - for (it = mWidgets.begin(); it != mWidgets.end(); it++) - { - if ((*it)->isFocused()) - { - break; - } - } + for (it = mWidgets.begin(); it != mWidgets.end(); ++it) + { + if ((*it)->isFocused()) + { + break; + } + } - WidgetListIterator end = it; + const auto end = it; - if (it == mWidgets.end()) - { - it = mWidgets.begin(); - } + if (it == mWidgets.end()) + { + it = mWidgets.begin(); + } - it++; + ++it; - for ( ; it != end; it++) - { - if (it == mWidgets.end()) - { - it = mWidgets.begin(); - } + for (; it != end; ++it) + { + if (it == mWidgets.end()) + { + it = mWidgets.begin(); + } - if ((*it)->isFocusable()) - { - (*it)->requestFocus(); - return; - } - } - } + if ((*it)->isFocusable()) + { + (*it)->requestFocus(); + return; + } + } + } - void BasicContainer::focusPrevious() - { - WidgetListReverseIterator it; + void BasicContainer::focusPrevious() + { + WidgetListReverseIterator it; - for (it = mWidgets.rbegin(); it != mWidgets.rend(); it++) - { - if ((*it)->isFocused()) - { - break; - } - } + for (it = mWidgets.rbegin(); it != mWidgets.rend(); ++it) + { + if ((*it)->isFocused()) + { + break; + } + } - WidgetListReverseIterator end = it; + const auto end = it; - it++; + ++it; - if (it == mWidgets.rend()) - { - it = mWidgets.rbegin(); - } + if (it == mWidgets.rend()) + { + it = mWidgets.rbegin(); + } - for ( ; it != end; it++) - { - if (it == mWidgets.rend()) - { - it = mWidgets.rbegin(); - } + for (; it != end; ++it) + { + if (it == mWidgets.rend()) + { + it = mWidgets.rbegin(); + } - if ((*it)->isFocusable()) - { - (*it)->requestFocus(); - return; - } - } - } + if ((*it)->isFocusable()) + { + (*it)->requestFocus(); + return; + } + } + } - Widget *BasicContainer::getWidgetAt(int x, int y) - { - Rectangle r = getChildrenArea(); + Widget* BasicContainer::getWidgetAt(int x, int y) + { + const auto r = getChildrenArea(); - if (!r.isPointInRect(x, y)) - { - return NULL; - } + if (!r.isPointInRect(x, y)) + { + return nullptr; + } - x -= r.x; - y -= r.y; + x -= r.x; + y -= r.y; - WidgetListReverseIterator it; - for (it = mWidgets.rbegin(); it != mWidgets.rend(); it++) - { - if ((*it)->isVisible() && (*it)->getDimension().isPointInRect(x, y)) - { - return (*it); - } - } + for (auto it = mWidgets.rbegin(); it != mWidgets.rend(); ++it) + { + if ((*it)->isVisible() && (*it)->getDimension().isPointInRect(x, y)) + { + return (*it); + } + } - return NULL; - } + return nullptr; + } - void BasicContainer::logic() - { - logicChildren(); - } + void BasicContainer::logic() + { + logicChildren(); + } - void BasicContainer::_setFocusHandler(FocusHandler* focusHandler) - { - Widget::_setFocusHandler(focusHandler); + void BasicContainer::_setFocusHandler(FocusHandler* focusHandler) + { + Widget::_setFocusHandler(focusHandler); - if (mInternalFocusHandler != NULL) - { - return; - } + if (mInternalFocusHandler != nullptr) + { + return; + } - WidgetListIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) - { - (*iter)->_setFocusHandler(focusHandler); - } - } + for (auto& mWidget : mWidgets) + { + mWidget->_setFocusHandler(focusHandler); + } + } - void BasicContainer::add(Widget* widget) - { - mWidgets.push_back(widget); + void BasicContainer::add(Widget* widget) + { + mWidgets.push_back(widget); - if (mInternalFocusHandler == NULL) - { - widget->_setFocusHandler(_getFocusHandler()); - } - else - { - widget->_setFocusHandler(mInternalFocusHandler); - } + if (mInternalFocusHandler == nullptr) + { + widget->_setFocusHandler(_getFocusHandler()); + } + else + { + widget->_setFocusHandler(mInternalFocusHandler); + } - widget->_setParent(this); - widget->addDeathListener(this); - } + widget->_setParent(this); + widget->addDeathListener(this); + } - void BasicContainer::remove(Widget* widget) - { - WidgetListIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) - { - if (*iter == widget) - { - mWidgets.erase(iter); - widget->_setFocusHandler(NULL); - widget->_setParent(NULL); - widget->removeDeathListener(this); - return; - } - } + void BasicContainer::remove(Widget* widget) + { + for (auto iter = mWidgets.begin(); iter != mWidgets.end(); ++iter) + { + if (*iter == widget) + { + mWidgets.erase(iter); + widget->_setFocusHandler(nullptr); + widget->_setParent(nullptr); + widget->removeDeathListener(this); + return; + } + } - throw GCN_EXCEPTION("There is no such widget in this container."); - } + throw GCN_EXCEPTION("There is no such widget in this container."); + } - void BasicContainer::clear() - { - WidgetListIterator iter; + void BasicContainer::clear() + { + for (auto& mWidget : mWidgets) + { + mWidget->_setFocusHandler(nullptr); + mWidget->_setParent(nullptr); + mWidget->removeDeathListener(this); + } - for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) - { - (*iter)->_setFocusHandler(NULL); - (*iter)->_setParent(NULL); - (*iter)->removeDeathListener(this); - } + mWidgets.clear(); + } - mWidgets.clear(); - } + void BasicContainer::drawChildren(Graphics* graphics) + { + graphics->pushClipArea(getChildrenArea()); - void BasicContainer::drawChildren(Graphics* graphics) - { - graphics->pushClipArea(getChildrenArea()); + for (auto& mWidget : mWidgets) + { + if (mWidget->isVisible()) + { + // If the widget has a border, + // draw it before drawing the widget + if (mWidget->getBorderSize() > 0) + { + auto rec = mWidget->getDimension(); + rec.x -= static_cast(mWidget->getBorderSize()); + rec.y -= static_cast(mWidget->getBorderSize()); + rec.width += 2 * static_cast(mWidget->getBorderSize()); + rec.height += 2 * static_cast(mWidget->getBorderSize()); + graphics->pushClipArea(rec); + mWidget->drawBorder(graphics); + graphics->popClipArea(); + } - WidgetListIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) - { - if ((*iter)->isVisible()) - { - // If the widget has a border, - // draw it before drawing the widget - if ((*iter)->getBorderSize() > 0) - { - Rectangle rec = (*iter)->getDimension(); - rec.x -= (*iter)->getBorderSize(); - rec.y -= (*iter)->getBorderSize(); - rec.width += 2 * (*iter)->getBorderSize(); - rec.height += 2 * (*iter)->getBorderSize(); - graphics->pushClipArea(rec); - (*iter)->drawBorder(graphics); - graphics->popClipArea(); - } + graphics->pushClipArea(mWidget->getDimension()); + mWidget->draw(graphics); + graphics->popClipArea(); + } + } - graphics->pushClipArea((*iter)->getDimension()); - (*iter)->draw(graphics); - graphics->popClipArea(); - } - } + graphics->popClipArea(); + } - graphics->popClipArea(); - } + void BasicContainer::logicChildren() + { + for (auto& mWidget : mWidgets) + { + mWidget->logic(); + } + } - void BasicContainer::logicChildren() - { - WidgetListIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) - { - (*iter)->logic(); - } - } + void BasicContainer::showWidgetPart(Widget* widget, Rectangle area) + { + const auto widgetArea = getChildrenArea(); + area.x += widget->getX(); + area.y += widget->getY(); - void BasicContainer::showWidgetPart(Widget* widget, Rectangle area) - { - Rectangle widgetArea = getChildrenArea(); - 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); + } - if (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); + } - if (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.x < 0) - { - widget->setX(widget->getX() - area.x); - } - - if (area.y < 0) - { - widget->setY(widget->getY() - area.y); - } - } + if (area.y < 0) + { + widget->setY(widget->getY() - area.y); + } + } - void BasicContainer::setInternalFocusHandler(FocusHandler* focusHandler) - { - Widget::setInternalFocusHandler(focusHandler); + void BasicContainer::setInternalFocusHandler(FocusHandler* focusHandler) + { + Widget::setInternalFocusHandler(focusHandler); - WidgetListIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) - { - if (mInternalFocusHandler == NULL) - { - (*iter)->_setFocusHandler(_getFocusHandler()); - } - else - { - (*iter)->_setFocusHandler(mInternalFocusHandler); - } - } - } + for (auto& mWidget : mWidgets) + { + if (mInternalFocusHandler == nullptr) + { + mWidget->_setFocusHandler(_getFocusHandler()); + } + else + { + mWidget->_setFocusHandler(mInternalFocusHandler); + } + } + } - Widget* BasicContainer::findWidgetById(const std::string& id) - { - WidgetListIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) - { - if ((*iter)->getId() == id) - { - return (*iter); - } - - BasicContainer *basicContainer = dynamic_cast(*iter); - - if (basicContainer != NULL) - { - Widget *widget = basicContainer->findWidgetById(id); - - if (widget != NULL) - { - return widget; - } - } - } + Widget* BasicContainer::findWidgetById(const std::string& id) + { + for (auto& mWidget : mWidgets) + { + if (mWidget->getId() == id) + { + return mWidget; + } - return NULL; - } + auto* basicContainer = dynamic_cast(mWidget); + + if (basicContainer != nullptr) + { + auto* const widget = basicContainer->findWidgetById(id); + + if (widget != nullptr) + { + return widget; + } + } + } + + return nullptr; + } } diff --git a/external/libguisan/src/cliprectangle.cpp b/external/libguisan/src/cliprectangle.cpp index 8c94be5f..54f5fba9 100644 --- a/external/libguisan/src/cliprectangle.cpp +++ b/external/libguisan/src/cliprectangle.cpp @@ -62,28 +62,28 @@ namespace gcn { - ClipRectangle::ClipRectangle() - { - x = y = width = height = xOffset = yOffset = 0; - } + ClipRectangle::ClipRectangle() + { + x = y = width = height = xOffset = yOffset = 0; + } - ClipRectangle::ClipRectangle(int x, int y, int width, int height, int xOffset, int yOffset) - { - this->x = x; - this->y = y; - this->width = width; - this->height = height; - this->xOffset = xOffset; - this->yOffset = yOffset; - } + ClipRectangle::ClipRectangle(int x, int y, int width, int height, int xOffset, int yOffset) + { + this->x = x; + this->y = y; + this->width = width; + this->height = height; + this->xOffset = xOffset; + this->yOffset = yOffset; + } - const ClipRectangle& ClipRectangle::operator=(const Rectangle& other) - { - x = other.x; - y = other.y; - width = other.width; - height = other.height; + const ClipRectangle& ClipRectangle::operator=(const Rectangle& other) + { + x = other.x; + y = other.y; + width = other.width; + height = other.height; - return *this; - } + return *this; + } } diff --git a/external/libguisan/src/color.cpp b/external/libguisan/src/color.cpp index 84a9a955..c5429018 100644 --- a/external/libguisan/src/color.cpp +++ b/external/libguisan/src/color.cpp @@ -62,76 +62,73 @@ 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 >> 8 & 0xFF), + a(255) + { + } - Color::Color(int color) - : - r((color >> 16) & 0xFF), - b((color >> 8) & 0xFF), - g((color >> 8) & 0xFF), - a(255) - { + 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, 255); - Color::Color(int ar, int ag, int ab, int aa) - : - r(ar), - g(ag), - b(ab), - a(aa) - { + result.r = result.r > 255 ? 255 : (result.r < 0 ? 0 : result.r); + result.g = result.g > 255 ? 255 : (result.g < 0 ? 0 : result.g); + result.b = result.b > 255 ? 255 : (result.b < 0 ? 0 : result.b); - } + return result; + } - Color Color::operator+(const Color& color) const - { - Color result(r + color.r, g + color.g, b + color.b, 255); + Color Color::operator-(const Color& color) const + { + Color result(r - color.r, g - color.g, b - color.b, 255); - result.r = (result.r>255?255:(result.r<0?0:result.r)); - result.g = (result.g>255?255:(result.g<0?0:result.g)); - result.b = (result.b>255?255:(result.b<0?0:result.b)); + result.r = result.r > 255 ? 255 : (result.r < 0 ? 0 : result.r); + result.g = result.g > 255 ? 255 : (result.g < 0 ? 0 : result.g); + result.b = result.b > 255 ? 255 : (result.b < 0 ? 0 : result.b); - return result; - } + return result; + } - Color Color::operator-(const Color& color) const - { - Color result(r - color.r, g - color.g, b - color.b, 255); + Color Color::operator*(float value) const + { + Color result(r * static_cast(value), g * static_cast(value), b * static_cast(value), a); - result.r = (result.r>255?255:(result.r<0?0:result.r)); - result.g = (result.g>255?255:(result.g<0?0:result.g)); - result.b = (result.b>255?255:(result.b<0?0:result.b)); + result.r = result.r > 255 ? 255 : (result.r < 0 ? 0 : result.r); + result.g = result.g > 255 ? 255 : (result.g < 0 ? 0 : result.g); + result.b = result.b > 255 ? 255 : (result.b < 0 ? 0 : result.b); - return result; - } + return result; + } - Color Color::operator*(float value) const - { - Color result((int)(r * value), (int)(g * value), (int)(b * value), a); + bool Color::operator==(const Color& color) const + { + return r == color.r && g == color.g && b == color.b && a == color.a; + } - result.r = (result.r>255?255:(result.r<0?0:result.r)); - result.g = (result.g>255?255:(result.g<0?0:result.g)); - result.b = (result.b>255?255:(result.b<0?0:result.b)); - - return result; - } - - bool Color::operator==(const Color& color) const - { - return r == color.r && g == color.g && b == color.b && a == color.a; - } - - bool Color::operator!=(const Color& color) const - { - return !(r == color.r && g == color.g && b == color.b && a == color.a); - } + bool Color::operator!=(const Color& color) const + { + return !(r == color.r && g == color.g && b == color.b && a == color.a); + } } diff --git a/external/libguisan/src/defaultfont.cpp b/external/libguisan/src/defaultfont.cpp index 5218cd80..91b859b4 100644 --- a/external/libguisan/src/defaultfont.cpp +++ b/external/libguisan/src/defaultfont.cpp @@ -67,41 +67,39 @@ namespace gcn { - int DefaultFont::getHeight() const - { - return 8; - } + int DefaultFont::getHeight() const + { + return 8; + } - int DefaultFont::getWidth(const std::string& text) const - { - return 8*text.size(); - } + int DefaultFont::getWidth(const std::string& text) const + { + return 8 * static_cast(text.size()); + } - int DefaultFont::drawGlyph(Graphics* graphics, unsigned char glyph, int x, int y) - { - graphics->drawRectangle( Rectangle(x, y, 8, 8)); + int DefaultFont::drawGlyph(Graphics* graphics, unsigned char glyph, int x, int y) + { + graphics->drawRectangle(Rectangle(x, y, 8, 8)); - return 8; - } + return 8; + } - void DefaultFont::drawString(Graphics* graphics, const std::string& text, int x, int y) - { - unsigned int i; + void DefaultFont::drawString(Graphics* graphics, const std::string& text, int x, int y) + { + for (auto i = 0; i < static_cast(text.size()); ++i) + { + drawGlyph(graphics, text.at(i), x, y); + x += getWidth(text); + } + } - for (i = 0; i< text.size(); ++i) - { - drawGlyph(graphics, text.at(i), x, y); - x += getWidth(text); - } - } + int DefaultFont::getStringIndexAt(const std::string& text, int x) + { + if (x > static_cast(text.size()) * 8) + { + return text.size(); + } - int DefaultFont::getStringIndexAt(const std::string& text, int x) - { - if (x > (int)text.size() * 8) - { - return text.size(); - } - - return x / 8; - } + return x / 8; + } } diff --git a/external/libguisan/src/event.cpp b/external/libguisan/src/event.cpp index ee209b7a..28209336 100644 --- a/external/libguisan/src/event.cpp +++ b/external/libguisan/src/event.cpp @@ -62,20 +62,16 @@ namespace gcn { - Event::Event(Widget* source) - :mSource(source) - { + Event::Event(Widget* source) + : mSource(source) + { + } - } + Event::~Event() + = default; - Event::~Event() - { - - } - - Widget* Event::getSource() const - { - return mSource; - } + Widget* Event::getSource() const + { + return mSource; + } } - diff --git a/external/libguisan/src/exception.cpp b/external/libguisan/src/exception.cpp index 47c8c767..e0ee7ad5 100644 --- a/external/libguisan/src/exception.cpp +++ b/external/libguisan/src/exception.cpp @@ -58,57 +58,57 @@ * For comments regarding functions please see the header file. */ +#include + + #include "guisan/exception.hpp" namespace gcn { - Exception::Exception() - : mFunction("?"), - mMessage(""), - mFilename("?"), - mLine(0) - { + Exception::Exception() + : mFunction("?"), + mMessage(""), + mFilename("?"), + mLine(0) + { + } - } + Exception::Exception(std::string message) + : mFunction("?"), + mMessage(std::move(message)), + mFilename("?"), + mLine(0) + { + } - Exception::Exception(const std::string& message) - : mFunction("?"), - mMessage(message), - mFilename("?"), - mLine(0) - { + Exception::Exception(std::string message, + std::string function, + std::string filename, + int line) + : mFunction(std::move(function)), + mMessage(std::move(message)), + mFilename(std::move(filename)), + mLine(line) + { + } - } + const std::string& Exception::getFunction() const + { + return mFunction; + } - Exception::Exception(const std::string& message, - const std::string& function, - const std::string& filename, - int line) - : mFunction(function), - mMessage(message), - mFilename(filename), - mLine(line) - { + const std::string& Exception::getMessage() const + { + return mMessage; + } - } + const std::string& Exception::getFilename() const + { + return mFilename; + } - const std::string& Exception::getFunction() const - { - return mFunction; - } - - const std::string& Exception::getMessage() const - { - return mMessage; - } - - const std::string& Exception::getFilename() const - { - return mFilename; - } - - int Exception::getLine() const - { - return mLine; - } + int Exception::getLine() const + { + return mLine; + } } diff --git a/external/libguisan/src/focushandler.cpp b/external/libguisan/src/focushandler.cpp index 5fca0732..6b225e4c 100644 --- a/external/libguisan/src/focushandler.cpp +++ b/external/libguisan/src/focushandler.cpp @@ -66,534 +66,525 @@ namespace gcn { - FocusHandler::FocusHandler() - :mFocusedWidget(NULL), - mModalFocusedWidget(NULL), - mModalMouseInputFocusedWidget(NULL), - mDraggedWidget(NULL), - mLastWidgetWithMouse(NULL), - mLastWidgetWithModalFocus(NULL), - mLastWidgetWithModalMouseInputFocus(NULL), - mLastWidgetPressed(NULL) - { - - } - - void FocusHandler::requestFocus(Widget* widget) - { - if (widget == NULL - || widget == mFocusedWidget) - { - return; - } - - unsigned int i = 0; - int toBeFocusedIndex = -1; - for (i = 0; i < mWidgets.size(); ++i) - { - if (mWidgets[i] == widget) - { - toBeFocusedIndex = i; - 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; - - if (mFocusedWidget != NULL && !mFocusedWidget->hasModalFocus()) - { - focusNone(); - } - } - - void FocusHandler::requestModalMouseInputFocus(Widget* widget) - { - if (mModalMouseInputFocusedWidget != NULL - && mModalMouseInputFocusedWidget != widget) - { - throw GCN_EXCEPTION("Another widget already has modal input focus."); - } - - mModalMouseInputFocusedWidget = widget; - } - - void FocusHandler::releaseModalFocus(Widget* widget) - { - if (mModalFocusedWidget == widget) - { - mModalFocusedWidget = NULL; - } - } - - void FocusHandler::releaseModalMouseInputFocus(Widget* widget) - { - if (mModalMouseInputFocusedWidget == widget) - { - mModalMouseInputFocusedWidget = NULL; - } - } - - Widget* FocusHandler::getFocused() const - { - return mFocusedWidget; - } - - Widget* FocusHandler::getModalFocused() const - { - return mModalFocusedWidget; - } - - Widget* FocusHandler::getModalMouseInputFocused() const - { - return mModalMouseInputFocusedWidget; - } - - void FocusHandler::focusNext() - { - int i; - int focusedWidget = -1; - for (i = 0; i < (int)mWidgets.size(); ++i) - { - if (mWidgets[i] == mFocusedWidget) - { - focusedWidget = i; - } - } - int focused = focusedWidget; - - // i is a counter that ensures that the following loop - // won't get stuck in an infinite loop - i = (int)mWidgets.size(); - do - { - ++focusedWidget; - - if (i==0) - { - focusedWidget = -1; - break; - } - - --i; - - if (focusedWidget >= (int)mWidgets.size()) - { - focusedWidget = 0; - } - - if (focusedWidget == focused) - { - return; - } - } - while (!mWidgets.at(focusedWidget)->isFocusable()); - - if (focusedWidget >= 0) - { - mFocusedWidget = mWidgets.at(focusedWidget); - - Event focusEvent(mFocusedWidget); - distributeFocusGainedEvent(focusEvent); - } - - if (focused >= 0) - { - Event focusEvent(mWidgets.at(focused)); - distributeFocusLostEvent(focusEvent); - } - } - - void FocusHandler::focusPrevious() - { - if (mWidgets.size() == 0) - { - mFocusedWidget = NULL; - return; - } - - int i; - int focusedWidget = -1; - for (i = 0; i < (int)mWidgets.size(); ++i) - { - if (mWidgets[i] == mFocusedWidget) - { - focusedWidget = i; - } - } - int focused = focusedWidget; - - // i is a counter that ensures that the following loop - // won't get stuck in an infinite loop - i = (int)mWidgets.size(); - do - { - --focusedWidget; - - if (i==0) - { - focusedWidget = -1; - break; - } - - --i; - - if (focusedWidget <= 0) - { - focusedWidget = mWidgets.size() - 1; - } - - if (focusedWidget == focused) - { - return; - } - } - while (!mWidgets.at(focusedWidget)->isFocusable()); - - if (focusedWidget >= 0) - { - mFocusedWidget = mWidgets.at(focusedWidget); - Event focusEvent(mFocusedWidget); - distributeFocusGainedEvent(focusEvent); - } - - if (focused >= 0) - { - Event focusEvent(mWidgets.at(focused)); - distributeFocusLostEvent(focusEvent); - } - } - - bool FocusHandler::isFocused(const Widget* widget) const - { - return mFocusedWidget == widget; - } - - void FocusHandler::add(Widget* widget) - { - mWidgets.push_back(widget); - } - - void FocusHandler::remove(Widget* widget) - { - if (isFocused(widget)) - { - mFocusedWidget = NULL; - } - - WidgetIterator iter; - - for (iter = mWidgets.begin(); iter != mWidgets.end(); ++iter) - { - if ((*iter) == widget) - { - mWidgets.erase(iter); - break; - } - } - - if (mDraggedWidget == widget) - { - mDraggedWidget = NULL; - return; - } - - if (mLastWidgetWithMouse == widget) - { - mLastWidgetWithMouse = NULL; - return; - } - - if (mLastWidgetWithModalFocus == widget) - { - mLastWidgetWithModalFocus = NULL; - return; - } - - if (mLastWidgetWithModalMouseInputFocus == widget) - { - mLastWidgetWithModalMouseInputFocus = NULL; - return; - } - - if (mLastWidgetPressed == widget) - { - mLastWidgetPressed = NULL; - return; - } - } - - void FocusHandler::focusNone() - { - if (mFocusedWidget != NULL) - { - Widget* focused = mFocusedWidget; - mFocusedWidget = NULL; - - Event focusEvent(focused); - distributeFocusLostEvent(focusEvent); - } - } - - void FocusHandler::tabNext() - { - if (mFocusedWidget != NULL) - { - if (!mFocusedWidget->isTabOutEnabled()) - { - return; - } - } - - if (mWidgets.size() == 0) - { - mFocusedWidget = NULL; - return; - } - - int i; - int focusedWidget = -1; - for (i = 0; i < (int)mWidgets.size(); ++i) - { - if (mWidgets[i] == mFocusedWidget) - { - focusedWidget = i; - } - } - int focused = focusedWidget; - bool done = false; - - // i is a counter that ensures that the following loop - // won't get stuck in an infinite loop - i = (int)mWidgets.size(); - do - { - ++focusedWidget; - - if (i==0) - { - focusedWidget = -1; - break; - } - - --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)->hasModalFocus())) - { - done = true; - } - } - while (!done); - - if (focusedWidget >= 0) - { - mFocusedWidget = mWidgets.at(focusedWidget); - Event focusEvent(mFocusedWidget); - distributeFocusGainedEvent(focusEvent); - } - - if (focused >= 0) - { - Event focusEvent(mWidgets.at(focused)); - distributeFocusLostEvent(focusEvent); - } - } - - void FocusHandler::tabPrevious() - { - if (mFocusedWidget != NULL) - { - if (!mFocusedWidget->isTabOutEnabled()) - { - return; - } - } - - if (mWidgets.size() == 0) - { - mFocusedWidget = NULL; - return; - } - - int i; - int focusedWidget = -1; - for (i = 0; i < (int)mWidgets.size(); ++i) - { - if (mWidgets[i] == mFocusedWidget) - { - focusedWidget = i; - } - } - int focused = focusedWidget; - bool done = false; - - // i is a counter that ensures that the following loop - // won't get stuck in an infinite loop - i = (int)mWidgets.size(); - do - { - --focusedWidget; - - if (i==0) - { - focusedWidget = -1; - break; - } - - --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)->hasModalFocus())) - { - done = true; - } - } - while (!done); - - if (focusedWidget >= 0) - { - mFocusedWidget = mWidgets.at(focusedWidget); - Event focusEvent(mFocusedWidget); - distributeFocusGainedEvent(focusEvent); - } - - if (focused >= 0) - { - Event focusEvent(mWidgets.at(focused)); - distributeFocusLostEvent(focusEvent); - } - } - - void FocusHandler::distributeFocusLostEvent(const Event& focusEvent) - { - Widget* sourceWidget = focusEvent.getSource(); - - std::list focusListeners = sourceWidget->_getFocusListeners(); - - // Send the event to all focus listeners of the widget. - for (std::list::iterator it = focusListeners.begin(); - it != focusListeners.end(); - ++it) - { - (*it)->focusLost(focusEvent); - } - } - - void FocusHandler::distributeFocusGainedEvent(const Event& focusEvent) - { - Widget* sourceWidget = focusEvent.getSource(); - - std::list focusListeners = sourceWidget->_getFocusListeners(); - - // Send the event to all focus listeners of the widget. - for (std::list::iterator it = focusListeners.begin(); - it != focusListeners.end(); - ++it) - { - (*it)->focusGained(focusEvent); - } - } - - Widget* FocusHandler::getDraggedWidget() - { - return mDraggedWidget; - } - - void FocusHandler::setDraggedWidget(Widget* draggedWidget) - { - mDraggedWidget = draggedWidget; - } - - Widget* FocusHandler::getLastWidgetWithMouse() - { - return mLastWidgetWithMouse; - } - - void FocusHandler::setLastWidgetWithMouse(Widget* lastWidgetWithMouse) - { - mLastWidgetWithMouse = lastWidgetWithMouse; - } - - Widget* FocusHandler::getLastWidgetWithModalFocus() - { - return mLastWidgetWithModalFocus; - } - - void FocusHandler::setLastWidgetWithModalFocus(Widget* lastWidgetWithModalFocus) - { - mLastWidgetWithModalFocus = lastWidgetWithModalFocus; - } - - Widget* FocusHandler::getLastWidgetWithModalMouseInputFocus() - { - return mLastWidgetWithModalMouseInputFocus; - } - - void FocusHandler::setLastWidgetWithModalMouseInputFocus(Widget* lastWidgetWithModalMouseInputFocus) - { - mLastWidgetWithModalMouseInputFocus = lastWidgetWithModalMouseInputFocus; - } - - Widget* FocusHandler::getLastWidgetPressed() - { - return mLastWidgetPressed; - } - - void FocusHandler::setLastWidgetPressed(Widget* lastWidgetPressed) - { - mLastWidgetPressed = lastWidgetPressed; - } + FocusHandler::FocusHandler() + : mFocusedWidget(nullptr), + mModalFocusedWidget(nullptr), + mModalMouseInputFocusedWidget(nullptr), + mDraggedWidget(nullptr), + mLastWidgetWithMouse(nullptr), + mLastWidgetWithModalFocus(nullptr), + mLastWidgetWithModalMouseInputFocus(nullptr), + mLastWidgetPressed(nullptr) + { + } + + void FocusHandler::requestFocus(Widget* widget) + { + if (widget == nullptr + || widget == mFocusedWidget) + { + return; + } + + auto toBeFocusedIndex = -1; + for (unsigned int i = 0; i < mWidgets.size(); ++i) + { + if (mWidgets[i] == widget) + { + toBeFocusedIndex = i; + break; + } + } + + if (toBeFocusedIndex < 0) + { + throw GCN_EXCEPTION("Trying to focus a none existing widget."); + } + + auto* oldFocused = mFocusedWidget; + + if (oldFocused != widget) + { + mFocusedWidget = mWidgets.at(toBeFocusedIndex); + + if (oldFocused != nullptr) + { + const Event focusEvent(oldFocused); + distributeFocusLostEvent(focusEvent); + } + + const Event focusEvent(mWidgets.at(toBeFocusedIndex)); + distributeFocusGainedEvent(focusEvent); + } + } + + void FocusHandler::requestModalFocus(Widget* widget) + { + if (mModalFocusedWidget != nullptr && mModalFocusedWidget != widget) + { + throw GCN_EXCEPTION("Another widget already has modal focus."); + } + + mModalFocusedWidget = widget; + + if (mFocusedWidget != nullptr && !mFocusedWidget->hasModalFocus()) + { + focusNone(); + } + } + + void FocusHandler::requestModalMouseInputFocus(Widget* widget) + { + if (mModalMouseInputFocusedWidget != nullptr + && mModalMouseInputFocusedWidget != widget) + { + throw GCN_EXCEPTION("Another widget already has modal input focus."); + } + + mModalMouseInputFocusedWidget = widget; + } + + void FocusHandler::releaseModalFocus(Widget* widget) + { + if (mModalFocusedWidget == widget) + { + mModalFocusedWidget = nullptr; + } + } + + void FocusHandler::releaseModalMouseInputFocus(Widget* widget) + { + if (mModalMouseInputFocusedWidget == widget) + { + mModalMouseInputFocusedWidget = nullptr; + } + } + + Widget* FocusHandler::getFocused() const + { + return mFocusedWidget; + } + + Widget* FocusHandler::getModalFocused() const + { + return mModalFocusedWidget; + } + + Widget* FocusHandler::getModalMouseInputFocused() const + { + return mModalMouseInputFocusedWidget; + } + + void FocusHandler::focusNext() + { + int i; + auto focusedWidget = -1; + for (i = 0; i < static_cast(mWidgets.size()); ++i) + { + if (mWidgets[i] == mFocusedWidget) + { + focusedWidget = i; + } + } + const auto focused = focusedWidget; + + // i is a counter that ensures that the following loop + // won't get stuck in an infinite loop + i = static_cast(mWidgets.size()); + do + { + ++focusedWidget; + + if (i == 0) + { + focusedWidget = -1; + break; + } + + --i; + + if (focusedWidget >= static_cast(mWidgets.size())) + { + focusedWidget = 0; + } + + if (focusedWidget == focused) + { + return; + } + } + while (!mWidgets.at(focusedWidget)->isFocusable()); + + if (focusedWidget >= 0) + { + mFocusedWidget = mWidgets.at(focusedWidget); + + const Event focusEvent(mFocusedWidget); + distributeFocusGainedEvent(focusEvent); + } + + if (focused >= 0) + { + const Event focusEvent(mWidgets.at(focused)); + distributeFocusLostEvent(focusEvent); + } + } + + void FocusHandler::focusPrevious() + { + if (mWidgets.empty()) + { + mFocusedWidget = nullptr; + return; + } + + int i; + auto focusedWidget = -1; + for (i = 0; i < static_cast(mWidgets.size()); ++i) + { + if (mWidgets[i] == mFocusedWidget) + { + focusedWidget = i; + } + } + const auto focused = focusedWidget; + + // i is a counter that ensures that the following loop + // won't get stuck in an infinite loop + i = static_cast(mWidgets.size()); + do + { + --focusedWidget; + + if (i == 0) + { + focusedWidget = -1; + break; + } + + --i; + + if (focusedWidget <= 0) + { + focusedWidget = mWidgets.size() - 1; + } + + if (focusedWidget == focused) + { + return; + } + } + while (!mWidgets.at(focusedWidget)->isFocusable()); + + if (focusedWidget >= 0) + { + mFocusedWidget = mWidgets.at(focusedWidget); + const Event focusEvent(mFocusedWidget); + distributeFocusGainedEvent(focusEvent); + } + + if (focused >= 0) + { + const Event focusEvent(mWidgets.at(focused)); + distributeFocusLostEvent(focusEvent); + } + } + + bool FocusHandler::isFocused(const Widget* widget) const + { + return mFocusedWidget == widget; + } + + void FocusHandler::add(Widget* widget) + { + mWidgets.push_back(widget); + } + + void FocusHandler::remove(Widget* widget) + { + if (isFocused(widget)) + { + mFocusedWidget = nullptr; + } + + for (auto iter = mWidgets.begin(); iter != mWidgets.end(); ++iter) + { + if (*iter == widget) + { + mWidgets.erase(iter); + break; + } + } + + if (mDraggedWidget == widget) + { + mDraggedWidget = nullptr; + return; + } + + if (mLastWidgetWithMouse == widget) + { + mLastWidgetWithMouse = nullptr; + return; + } + + if (mLastWidgetWithModalFocus == widget) + { + mLastWidgetWithModalFocus = nullptr; + return; + } + + if (mLastWidgetWithModalMouseInputFocus == widget) + { + mLastWidgetWithModalMouseInputFocus = nullptr; + return; + } + + if (mLastWidgetPressed == widget) + { + mLastWidgetPressed = nullptr; + } + } + + void FocusHandler::focusNone() + { + if (mFocusedWidget != nullptr) + { + auto* const focused = mFocusedWidget; + mFocusedWidget = nullptr; + + const Event focusEvent(focused); + distributeFocusLostEvent(focusEvent); + } + } + + void FocusHandler::tabNext() + { + if (mFocusedWidget != nullptr) + { + if (!mFocusedWidget->isTabOutEnabled()) + { + return; + } + } + + if (mWidgets.empty()) + { + mFocusedWidget = nullptr; + return; + } + + int i; + auto focusedWidget = -1; + for (i = 0; i < static_cast(mWidgets.size()); ++i) + { + if (mWidgets[i] == mFocusedWidget) + { + focusedWidget = i; + } + } + const auto focused = focusedWidget; + auto done = false; + + // i is a counter that ensures that the following loop + // won't get stuck in an infinite loop + i = static_cast(mWidgets.size()); + do + { + ++focusedWidget; + + if (i == 0) + { + focusedWidget = -1; + break; + } + + --i; + + if (focusedWidget >= static_cast(mWidgets.size())) + { + focusedWidget = 0; + } + + if (focusedWidget == focused) + { + return; + } + + if (mWidgets.at(focusedWidget)->isFocusable() && + mWidgets.at(focusedWidget)->isTabInEnabled() && + (mModalFocusedWidget == nullptr || + mWidgets.at(focusedWidget)->hasModalFocus())) + { + done = true; + } + } + while (!done); + + if (focusedWidget >= 0) + { + mFocusedWidget = mWidgets.at(focusedWidget); + const Event focusEvent(mFocusedWidget); + distributeFocusGainedEvent(focusEvent); + } + + if (focused >= 0) + { + const Event focusEvent(mWidgets.at(focused)); + distributeFocusLostEvent(focusEvent); + } + } + + void FocusHandler::tabPrevious() + { + if (mFocusedWidget != nullptr) + { + if (!mFocusedWidget->isTabOutEnabled()) + { + return; + } + } + + if (mWidgets.empty()) + { + mFocusedWidget = nullptr; + return; + } + + int i; + auto focusedWidget = -1; + for (i = 0; i < static_cast(mWidgets.size()); ++i) + { + if (mWidgets[i] == mFocusedWidget) + { + focusedWidget = i; + } + } + const auto focused = focusedWidget; + auto done = false; + + // i is a counter that ensures that the following loop + // won't get stuck in an infinite loop + i = static_cast(mWidgets.size()); + do + { + --focusedWidget; + + if (i == 0) + { + focusedWidget = -1; + break; + } + + --i; + + if (focusedWidget <= 0) + { + focusedWidget = mWidgets.size() - 1; + } + + if (focusedWidget == focused) + { + return; + } + + if (mWidgets.at(focusedWidget)->isFocusable() && + mWidgets.at(focusedWidget)->isTabInEnabled() && + (mModalFocusedWidget == nullptr || + mWidgets.at(focusedWidget)->hasModalFocus())) + { + done = true; + } + } + while (!done); + + if (focusedWidget >= 0) + { + mFocusedWidget = mWidgets.at(focusedWidget); + const Event focusEvent(mFocusedWidget); + distributeFocusGainedEvent(focusEvent); + } + + if (focused >= 0) + { + const Event focusEvent(mWidgets.at(focused)); + distributeFocusLostEvent(focusEvent); + } + } + + void FocusHandler::distributeFocusLostEvent(const Event& focusEvent) + { + auto* sourceWidget = focusEvent.getSource(); + + auto focusListeners = sourceWidget->_getFocusListeners(); + + // Send the event to all focus listeners of the widget. + for (auto& focusListener : focusListeners) + { + focusListener->focusLost(focusEvent); + } + } + + void FocusHandler::distributeFocusGainedEvent(const Event& focusEvent) + { + auto sourceWidget = focusEvent.getSource(); + + auto focusListeners = sourceWidget->_getFocusListeners(); + + // Send the event to all focus listeners of the widget. + for (auto& focusListener : focusListeners) + { + focusListener->focusGained(focusEvent); + } + } + + Widget* FocusHandler::getDraggedWidget() + { + return mDraggedWidget; + } + + void FocusHandler::setDraggedWidget(Widget* draggedWidget) + { + mDraggedWidget = draggedWidget; + } + + Widget* FocusHandler::getLastWidgetWithMouse() + { + return mLastWidgetWithMouse; + } + + void FocusHandler::setLastWidgetWithMouse(Widget* lastWidgetWithMouse) + { + mLastWidgetWithMouse = lastWidgetWithMouse; + } + + Widget* FocusHandler::getLastWidgetWithModalFocus() + { + return mLastWidgetWithModalFocus; + } + + void FocusHandler::setLastWidgetWithModalFocus(Widget* lastWidgetWithModalFocus) + { + mLastWidgetWithModalFocus = lastWidgetWithModalFocus; + } + + Widget* FocusHandler::getLastWidgetWithModalMouseInputFocus() + { + return mLastWidgetWithModalMouseInputFocus; + } + + void FocusHandler::setLastWidgetWithModalMouseInputFocus(Widget* lastWidgetWithModalMouseInputFocus) + { + mLastWidgetWithModalMouseInputFocus = lastWidgetWithModalMouseInputFocus; + } + + Widget* FocusHandler::getLastWidgetPressed() + { + return mLastWidgetPressed; + } + + void FocusHandler::setLastWidgetPressed(Widget* lastWidgetPressed) + { + mLastWidgetPressed = lastWidgetPressed; + } } diff --git a/external/libguisan/src/font.cpp b/external/libguisan/src/font.cpp index 2f6899f8..fdb99b4b 100644 --- a/external/libguisan/src/font.cpp +++ b/external/libguisan/src/font.cpp @@ -64,21 +64,20 @@ namespace gcn { - int Font::getStringIndexAt(const std::string& text, int x) - { - unsigned int i; - int size = 0; + int Font::getStringIndexAt(const std::string& text, int x) + { + auto size = 0; - for (i = 0; i < text.size(); ++i) - { - size = getWidth(text.substr(0,i)); + for (unsigned int i = 0; i < text.size(); ++i) + { + size = getWidth(text.substr(0, i)); - if (size > x) - { - return i; - } - } + if (size > x) + { + return i; + } + } - return text.size(); - } + return text.size(); + } } diff --git a/external/libguisan/src/genericinput.cpp b/external/libguisan/src/genericinput.cpp index 1e26dfc4..e6424624 100644 --- a/external/libguisan/src/genericinput.cpp +++ b/external/libguisan/src/genericinput.cpp @@ -64,115 +64,109 @@ namespace gcn { - GenericInput::GenericInput() - { + GenericInput::GenericInput() + = default; - } - - void GenericInput::pushKeyPressed(int unicode) - { - // TODO - } - - void GenericInput::pushKeyReleased(int unicode) - { - // TODO - } - - void GenericInput::pushMouseButtonPressed(int x, int y, int button) - { - MouseInput mouseInput; - mouseInput.setX(x); - mouseInput.setY(y); - mouseInput.setButton(button); - mouseInput.setType(MouseInput::PRESSED); + void GenericInput::pushKeyPressed(int unicode) + { + // TODO + } - mMouseInputQueue.push(mouseInput); - } - - void GenericInput::pushMouseButtonReleased(int x, int y, int button) - { - MouseInput mouseInput; - mouseInput.setX(x); - mouseInput.setY(y); - mouseInput.setButton(button); - mouseInput.setType(MouseInput::RELEASED); + void GenericInput::pushKeyReleased(int unicode) + { + // TODO + } - mMouseInputQueue.push(mouseInput); - } - - void GenericInput::pushMouseWheelMovedUp(int x, int y) - { - MouseInput mouseInput; - mouseInput.setX(x); - mouseInput.setY(y); - mouseInput.setType(MouseInput::WHEEL_MOVED_UP); + void GenericInput::pushMouseButtonPressed(int x, int y, int button) + { + MouseInput mouseInput; + mouseInput.setX(x); + mouseInput.setY(y); + mouseInput.setButton(button); + mouseInput.setType(MouseInput::PRESSED); - mMouseInputQueue.push(mouseInput); - } - - void GenericInput::pushMouseWheelMovedDown(int x, int y) - { - MouseInput mouseInput; - mouseInput.setX(x); - mouseInput.setY(y); - mouseInput.setType(MouseInput::WHEEL_MOVED_DOWN); + mMouseInputQueue.push(mouseInput); + } - mMouseInputQueue.push(mouseInput); - } - - void GenericInput::pushMouseMoved(int x, int y) - { - MouseInput mouseInput; - mouseInput.setX(x); - mouseInput.setY(y); - mouseInput.setType(MouseInput::MOVED); + void GenericInput::pushMouseButtonReleased(int x, int y, int button) + { + MouseInput mouseInput; + mouseInput.setX(x); + mouseInput.setY(y); + mouseInput.setButton(button); + mouseInput.setType(MouseInput::RELEASED); - mMouseInputQueue.push(mouseInput); - } + mMouseInputQueue.push(mouseInput); + } - bool GenericInput::isKeyQueueEmpty() - { - return mKeyInputQueue.empty(); - } + void GenericInput::pushMouseWheelMovedUp(int x, int y) + { + MouseInput mouseInput; + mouseInput.setX(x); + mouseInput.setY(y); + mouseInput.setType(MouseInput::WHEEL_MOVED_UP); - KeyInput GenericInput::dequeueKeyInput() - { - KeyInput keyInput; + mMouseInputQueue.push(mouseInput); + } - if (mKeyInputQueue.empty()) - { - throw GCN_EXCEPTION("The queue is empty."); - } + void GenericInput::pushMouseWheelMovedDown(int x, int y) + { + MouseInput mouseInput; + mouseInput.setX(x); + mouseInput.setY(y); + mouseInput.setType(MouseInput::WHEEL_MOVED_DOWN); - keyInput = mKeyInputQueue.front(); - mKeyInputQueue.pop(); + mMouseInputQueue.push(mouseInput); + } - return keyInput; - } - - bool GenericInput::isMouseQueueEmpty() - { - return mMouseInputQueue.empty(); - } + void GenericInput::pushMouseMoved(int x, int y) + { + MouseInput mouseInput; + mouseInput.setX(x); + mouseInput.setY(y); + mouseInput.setType(MouseInput::MOVED); - MouseInput GenericInput::dequeueMouseInput() - { - MouseInput mouseInput; - - if (mMouseInputQueue.empty()) - { - throw GCN_EXCEPTION("The queue is empty."); - } - - mouseInput = mMouseInputQueue.front(); - mMouseInputQueue.pop(); - - return mouseInput; - } - - void GenericInput::_pollInput() - { - // Does nothing. - } + mMouseInputQueue.push(mouseInput); + } + + bool GenericInput::isKeyQueueEmpty() + { + return mKeyInputQueue.empty(); + } + + KeyInput GenericInput::dequeueKeyInput() + { + if (mKeyInputQueue.empty()) + { + throw GCN_EXCEPTION("The queue is empty."); + } + + const auto keyInput = mKeyInputQueue.front(); + mKeyInputQueue.pop(); + + return keyInput; + } + + bool GenericInput::isMouseQueueEmpty() + { + return mMouseInputQueue.empty(); + } + + MouseInput GenericInput::dequeueMouseInput() + { + if (mMouseInputQueue.empty()) + { + throw GCN_EXCEPTION("The queue is empty."); + } + + const auto mouseInput = mMouseInputQueue.front(); + mMouseInputQueue.pop(); + + return mouseInput; + } + + void GenericInput::_pollInput() + { + // Does nothing. + } } diff --git a/external/libguisan/src/graphics.cpp b/external/libguisan/src/graphics.cpp index 7a4a11af..b75cbdde 100644 --- a/external/libguisan/src/graphics.cpp +++ b/external/libguisan/src/graphics.cpp @@ -85,7 +85,7 @@ namespace gcn return true; } - ClipRectangle top = mClipStack.top(); + const auto top = mClipStack.top(); ClipRectangle carea; carea = area; carea.xOffset = top.xOffset + carea.x; @@ -114,7 +114,7 @@ namespace gcn carea.height = top.height; } - bool result = carea.intersect(top); + const auto result = carea.intersect(top); mClipStack.push(carea); diff --git a/external/libguisan/src/gui.cpp b/external/libguisan/src/gui.cpp index d7f04ca2..54ba2d1c 100644 --- a/external/libguisan/src/gui.cpp +++ b/external/libguisan/src/gui.cpp @@ -73,930 +73,923 @@ 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) - { - mFocusHandler = new FocusHandler(); - } - - Gui::~Gui() - { - if (Widget::widgetExists(mTop)) - { - Gui::setTop(NULL); - } - - delete mFocusHandler; - } - - void Gui::setTop(Widget* top) - { - if (mTop != NULL) - { - mTop->_setFocusHandler(NULL); - } - if (top != NULL) - { - top->_setFocusHandler(mFocusHandler); - } - - mTop = top; - } - - Widget* Gui::getTop() const - { - return mTop; - } - - void Gui::setGraphics(Graphics* graphics) - { - mGraphics = graphics; - } - - Graphics* Gui::getGraphics() const - { - return mGraphics; - } - - void Gui::setInput(Input* input) - { - mInput = input; - } - - Input* Gui::getInput() const - { - return mInput; - } - - void Gui::logic() - { - if (mTop == NULL) - { - throw GCN_EXCEPTION("No top widget set"); - } - - handleModalFocus(); - handleModalMouseInputFocus(); - - if (mInput != NULL) - { - mInput->_pollInput(); - - handleKeyInput(); - handleMouseInput(); - - } // end if - - mTop->logic(); - } - - 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(); - - // If top has a border, - // draw it before drawing top - if (mTop->getBorderSize() > 0) - { - Rectangle rec = mTop->getDimension(); - rec.x -= int(mTop->getBorderSize()); - rec.y -= int(mTop->getBorderSize()); - rec.width += 2 * mTop->getBorderSize(); - rec.height += 2 * mTop->getBorderSize(); - mGraphics->pushClipArea(rec); - mTop->drawBorder(mGraphics); - mGraphics->popClipArea(); - } - - mGraphics->pushClipArea(mTop->getDimension()); - mTop->draw(mGraphics); - mGraphics->popClipArea(); - - mGraphics->_endDraw(); - } - - void Gui::focusNone() - { - mFocusHandler->focusNone(); - } - - void Gui::setTabbingEnabled(bool tabbing) - { - mTabbing = tabbing; - } - - bool Gui::isTabbingEnabled() - { - return mTabbing; - } - - void Gui::addGlobalKeyListener(KeyListener* keyListener) - { - mKeyListeners.push_back(keyListener); - } - - void Gui::removeGlobalKeyListener(KeyListener* keyListener) - { - mKeyListeners.remove(keyListener); - } - - void Gui::handleMouseInput() - { - while (!mInput->isMouseQueueEmpty()) - { - MouseInput mouseInput = mInput->dequeueMouseInput(); - - // Save the current mouse state. It will be needed if modal focus - // changes or modal mouse input focus changes. - mLastMouseX = mouseInput.getX(); - mLastMouseY = mouseInput.getY(); - - 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; - } - } - } - - void Gui::handleKeyInput() - { - while (!mInput->isKeyQueueEmpty()) - { - KeyInput keyInput = mInput->dequeueKeyInput(); - - // Save modifiers state - mShiftPressed = keyInput.isShiftPressed(); - mMetaPressed = keyInput.isMetaPressed(); - mControlPressed = keyInput.isControlPressed(); - mAltPressed = keyInput.isAltPressed(); - - KeyEvent keyEventToGlobalKeyListeners(NULL, - mShiftPressed, - mControlPressed, - mAltPressed, - mMetaPressed, - keyInput.getType(), - keyInput.isNumericPad(), - keyInput.getKey()); - - 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) - { - KeyEvent keyEvent(getKeyEventSource(), - mShiftPressed, - mControlPressed, - mAltPressed, - mMetaPressed, - keyInput.getType(), - keyInput.isNumericPad(), - keyInput.getKey()); - - - if (!mFocusHandler->getFocused()->isFocusable()) - { - mFocusHandler->focusNone(); - } - else - { - distributeKeyEvent(keyEvent); - } - - keyEventConsumed = keyEvent.isConsumed(); - } - - // If the key event hasn't been consumed and - // tabbing is enable check for tab press and - // change focus. - 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())) - ) - { - // Distribute an event to all widgets in the "widget with mouse" queue. - while (!mWidgetWithMouseQueue.empty()) - { - Widget* widget = mWidgetWithMouseQueue.front(); - - if (Widget::widgetExists(widget)) - { - distributeMouseEvent(widget, - MouseEvent::EXITED, - int(mouseInput.getButton()), - mouseInput.getX(), - mouseInput.getX(), - true, - true); - } - - mWidgetWithMouseQueue.pop_front(); - } - - return; - } - - // Check if there is a need to send mouse exited events by - // traversing the "widget with mouse" queue. - bool widgetWithMouseQueueCheckDone = mWidgetWithMouseQueue.empty(); - while (!widgetWithMouseQueueCheckDone) - { - unsigned int iterations = 0; - std::deque::iterator iter; - for (iter = mWidgetWithMouseQueue.begin(); - iter != mWidgetWithMouseQueue.end(); - ++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)) - { - mWidgetWithMouseQueue.erase(iter); - break; - } - else - { - int x, y; - widget->getAbsolutePosition(x, y); - - if (x > mouseInput.getX() - || y > mouseInput.getY() - || x + widget->getWidth() <= mouseInput.getX() - || y + widget->getHeight() <= mouseInput.getY() - || !widget->isVisible()) - { - distributeMouseEvent(widget, - MouseEvent::EXITED, - int(mouseInput.getButton()), - mouseInput.getX(), - mouseInput.getX(), - true, - true); - mClickCount = 1; - mLastMousePressTimeStamp = 0; - mWidgetWithMouseQueue.erase(iter); - break; - } - } - - iterations++; - } - - 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* 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. - if (mFocusHandler->getModalMouseInputFocused() != NULL - && widget == mFocusHandler->getModalMouseInputFocused() - && Widget::widgetExists(widget)) - { - int x, y; - widget->getAbsolutePosition(x, y); - - if (x > mouseInput.getX() - || y > mouseInput.getY() - || x + widget->getWidth() <= mouseInput.getX() - || y + widget->getHeight() <= mouseInput.getY()) - { - parent = NULL; - } - } - - while (parent != NULL) - { - parent = (Widget*)widget->getParent(); - - // Check if the widget is present in the "widget with mouse" queue. - bool widgetIsPresentInQueue = false; - std::deque::iterator iter; - for (iter = mWidgetWithMouseQueue.begin(); - iter != mWidgetWithMouseQueue.end(); - ++iter) - { - if (*iter == widget) - { - widgetIsPresentInQueue = true; - break; - } - } - - // Widget is not present, send an entered event and add - // it to the "widget with mouse" queue. - if (!widgetIsPresentInQueue - && Widget::widgetExists(widget)) - { - distributeMouseEvent(widget, - MouseEvent::ENTERED, - int(mouseInput.getButton()), - mouseInput.getX(), - mouseInput.getY(), - true, - true); - mWidgetWithMouseQueue.push_front(widget); - } - - Widget* swap = widget; - widget = parent; - parent = (Widget*)swap->getParent(); - } - - if (mFocusHandler->getDraggedWidget() != NULL) - { - distributeMouseEvent(mFocusHandler->getDraggedWidget(), - MouseEvent::DRAGGED, - mLastMouseDragButton, - mouseInput.getX(), - mouseInput.getY()); - } - else - { - Widget* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY()); - distributeMouseEvent(sourceWidget, - MouseEvent::MOVED, - int(mouseInput.getButton()), - mouseInput.getX(), - mouseInput.getY()); - } - } - - void Gui::handleMousePressed(const MouseInput& mouseInput) - { - Widget* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY()); - - if (mFocusHandler->getDraggedWidget() != NULL) - { - sourceWidget = mFocusHandler->getDraggedWidget(); - } - - int sourceWidgetX, sourceWidgetY; - sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); - - distributeMouseEvent(sourceWidget, - MouseEvent::PRESSED, - int(mouseInput.getButton()), - mouseInput.getX(), - mouseInput.getY()); - - mFocusHandler->setLastWidgetPressed(sourceWidget); - - if ((mFocusHandler->getModalFocused() != NULL - && sourceWidget->hasModalFocus()) - || mFocusHandler->getModalFocused() == NULL) - { - sourceWidget->requestFocus(); - } - - mFocusHandler->setDraggedWidget(sourceWidget); - mLastMouseDragButton = int(mouseInput.getButton()); - - if (mLastMousePressTimeStamp < 300 - && mLastMousePressButton == mouseInput.getButton()) - { - mClickCount++; - } - else - { - mClickCount = 1; - } - - mLastMousePressButton = mouseInput.getButton(); - mLastMousePressTimeStamp = mouseInput.getTimeStamp(); - } - - void Gui::handleMouseWheelMovedDown(const MouseInput& mouseInput) - { - Widget* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY()); - - if (mFocusHandler->getDraggedWidget() != NULL) - { - sourceWidget = mFocusHandler->getDraggedWidget(); - } - - int sourceWidgetX, sourceWidgetY; - sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); - - distributeMouseEvent(sourceWidget, - MouseEvent::WHEEL_MOVED_DOWN, - int(mouseInput.getButton()), - mouseInput.getX(), - mouseInput.getY()); - } - - void Gui::handleMouseWheelMovedUp(const MouseInput& mouseInput) - { - Widget* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY()); - - if (mFocusHandler->getDraggedWidget() != NULL) - { - sourceWidget = mFocusHandler->getDraggedWidget(); - } - - int sourceWidgetX, sourceWidgetY; - sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); - - distributeMouseEvent(sourceWidget, - MouseEvent::WHEEL_MOVED_UP, - int(mouseInput.getButton()), - mouseInput.getX(), - mouseInput.getY()); - } - - void Gui::handleMouseReleased(const MouseInput& mouseInput) - { - 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, - int(mouseInput.getButton()), - mouseInput.getX(), - mouseInput.getY()); - - if (mouseInput.getButton() == mLastMousePressButton - && mFocusHandler->getLastWidgetPressed() == sourceWidget) - { - distributeMouseEvent(sourceWidget, - MouseEvent::CLICKED, - int(mouseInput.getButton()), - mouseInput.getX(), - mouseInput.getY()); - - mFocusHandler->setLastWidgetPressed(NULL); - } - else - { - mLastMousePressButton = 0; - mClickCount = 0; - } - - if (mFocusHandler->getDraggedWidget() != NULL) - { - mFocusHandler->setDraggedWidget(NULL); - } - } - - Widget* Gui::getWidgetAt(int x, int y) - { - // If the widget's parent has no child then we have found the widget.. - Widget* parent = mTop; - Widget* child = mTop; - - while (child != NULL) - { - Widget* swap = child; - int parentX, parentY; - parent->getAbsolutePosition(parentX, parentY); - child = parent->getWidgetAt(x - parentX, y - parentY); - parent = swap; - } - - return parent; - } - - Widget* Gui::getMouseEventSource(int x, int y) - { - Widget* widget = getWidgetAt(x, y); - - if (mFocusHandler->getModalMouseInputFocused() != NULL - && !widget->hasModalMouseInputFocus()) - { - return mFocusHandler->getModalMouseInputFocused(); - } - - return widget; - } - - Widget* Gui::getKeyEventSource() - { - Widget* widget = mFocusHandler->getFocused(); - - while (widget->_getInternalFocusHandler() != NULL - && widget->_getInternalFocusHandler()->getFocused() != NULL) - { - widget = widget->_getInternalFocusHandler()->getFocused(); - } - - return widget; - } - - void Gui::distributeMouseEvent(Widget* source, - int type, - int button, - int x, - int y, - bool force, - bool toSourceOnly) - { - Widget* parent = source; - Widget* widget = source; - - if (mFocusHandler->getModalFocused() != NULL - && !widget->hasModalFocus() - && !force) - { - return; - } - - if (mFocusHandler->getModalMouseInputFocused() != NULL - && !widget->hasModalMouseInputFocus() - && !force) - { - return; - } - - MouseEvent mouseEvent(source, - mShiftPressed, - mControlPressed, - mAltPressed, - mMetaPressed, - type, - button, - x, - y, - mClickCount); - - while (parent != NULL) - { - // If the widget has been removed due to input - // cancel the distribution. - if (!Widget::widgetExists(widget)) - { - break; - } - - parent = (Widget*)widget->getParent(); - - if (widget->isEnabled() || force) - { - int widgetX, widgetY; - widget->getAbsolutePosition(widgetX, widgetY); - - mouseEvent.mX = x - widgetX; - mouseEvent.mY = y - widgetY; - - std::list mouseListeners = widget->_getMouseListeners(); - - // Send the event to all mouse listeners of the widget. - for (auto& mouseListener : mouseListeners) - { - switch (mouseEvent.getType()) - { - case MouseEvent::ENTERED: - mouseListener->mouseEntered(mouseEvent); - break; - case MouseEvent::EXITED: - mouseListener->mouseExited(mouseEvent); - break; - case MouseEvent::MOVED: - mouseListener->mouseMoved(mouseEvent); - break; - case MouseEvent::PRESSED: - mouseListener->mousePressed(mouseEvent); - break; - case MouseEvent::RELEASED: - mouseListener->mouseReleased(mouseEvent); - break; - case MouseEvent::WHEEL_MOVED_UP: - mouseListener->mouseWheelMovedUp(mouseEvent); - break; - case MouseEvent::WHEEL_MOVED_DOWN: - mouseListener->mouseWheelMovedDown(mouseEvent); - break; - case MouseEvent::DRAGGED: - mouseListener->mouseDragged(mouseEvent); - break; - case MouseEvent::CLICKED: - mouseListener->mouseClicked(mouseEvent); - break; - default: - throw GCN_EXCEPTION("Unknown mouse event type."); - } - } - - if (toSourceOnly) - { - break; - } - - } - - Widget* swap = widget; - widget = parent; - parent = (Widget*)swap->getParent(); - - // If a non modal focused widget has been reach - // and we have modal focus cancel the distribution. - if (mFocusHandler->getModalFocused() != NULL - && !widget->hasModalFocus()) - { - break; - } - - // If a non modal mouse input focused widget has been reach - // and we have modal mouse input focus cancel the distribution. - if (mFocusHandler->getModalMouseInputFocused() != NULL - && !widget->hasModalMouseInputFocus()) - { - break; - } - } - } - - void Gui::distributeKeyEvent(KeyEvent& keyEvent) - { - Widget* parent = keyEvent.getSource(); - Widget* widget = keyEvent.getSource(); - - if (mFocusHandler->getModalFocused() != NULL - && !widget->hasModalFocus()) - { - return; - } - - if (mFocusHandler->getModalMouseInputFocused() != NULL - && !widget->hasModalMouseInputFocus()) - { - return; - } - - while (parent != NULL) - { - // If the widget has been removed due to input - // cancel the distribution. - if (!Widget::widgetExists(widget)) - { - break; - } - - parent = (Widget*)widget->getParent(); - - if (widget->isEnabled()) - { - std::list keyListeners = widget->_getKeyListeners(); - - // Send the event to all key listeners of the source widget. - for (auto& keyListener : keyListeners) - { - switch (keyEvent.getType()) - { - case KeyEvent::PRESSED: - keyListener->keyPressed(keyEvent); - break; - case KeyEvent::RELEASED: - keyListener->keyReleased(keyEvent); - break; - default: - throw GCN_EXCEPTION("Unknown key event type."); - } - } - } - - Widget* swap = widget; - widget = parent; - parent = (Widget*)swap->getParent(); - - // If a non modal focused widget has been reach - // and we have modal focus cancel the distribution. - if (mFocusHandler->getModalFocused() != NULL - && !widget->hasModalFocus()) - { - break; - } - } - } - - void Gui::distributeKeyEventToGlobalKeyListeners(KeyEvent& keyEvent) - { - for (auto& mKeyListener : mKeyListeners) - { - switch (keyEvent.getType()) - { - case KeyEvent::PRESSED: - mKeyListener->keyPressed(keyEvent); - break; - case KeyEvent::RELEASED: - mKeyListener->keyReleased(keyEvent); - break; - default: - throw GCN_EXCEPTION("Unknown key event type."); - } - - if (keyEvent.isConsumed()) - { - break; - } - } - } - - void Gui::handleModalMouseInputFocus() - { - // Check if modal mouse input focus has been gained by a widget. - if ((mFocusHandler->getLastWidgetWithModalMouseInputFocus() - != mFocusHandler->getModalMouseInputFocused()) - && (mFocusHandler->getLastWidgetWithModalMouseInputFocus() == NULL)) - { - handleModalFocusGained(); - mFocusHandler->setLastWidgetWithModalMouseInputFocus(mFocusHandler->getModalMouseInputFocused()); - } - // Check if modal mouse input focus has been released. - else if ((mFocusHandler->getLastWidgetWithModalMouseInputFocus() - != mFocusHandler->getModalMouseInputFocused()) - && (mFocusHandler->getLastWidgetWithModalMouseInputFocus() != NULL)) - { - handleModalFocusReleased(); - mFocusHandler->setLastWidgetWithModalMouseInputFocus(NULL); - } - } - - void Gui::handleModalFocus() - { - // Check if modal focus has been gained by a widget. - if ((mFocusHandler->getLastWidgetWithModalFocus() - != mFocusHandler->getModalFocused()) - && (mFocusHandler->getLastWidgetWithModalFocus() == NULL)) - { - handleModalFocusGained(); - mFocusHandler->setLastWidgetWithModalFocus(mFocusHandler->getModalFocused()); - } - // Check if modal focus has been released. - else if ((mFocusHandler->getLastWidgetWithModalFocus() - != mFocusHandler->getModalFocused()) - && (mFocusHandler->getLastWidgetWithModalFocus() != NULL)) - { - handleModalFocusReleased(); - mFocusHandler->setLastWidgetWithModalFocus(NULL); - } - } - - void Gui::handleModalFocusGained() - { - // Distribute an event to all widgets in the "widget with mouse" queue. - while (!mWidgetWithMouseQueue.empty()) - { - Widget* widget = mWidgetWithMouseQueue.front(); - - if (Widget::widgetExists(widget)) - { - distributeMouseEvent(widget, - MouseEvent::EXITED, - int(mLastMousePressButton), - mLastMouseX, - mLastMouseY, - true, - true); - } - - mWidgetWithMouseQueue.pop_front(); - } - - mFocusHandler->setLastWidgetWithModalMouseInputFocus(mFocusHandler->getModalMouseInputFocused()); - } - - void Gui::handleModalFocusReleased() - { - // 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* widget = getMouseEventSource(mLastMouseX, mLastMouseY); - Widget* parent = widget; - - while (parent != NULL) - { - parent = (Widget*)widget->getParent(); - - // Check if the widget is present in the "widget with mouse" queue. - bool widgetIsPresentInQueue = false; - std::deque::iterator iter; - for (iter = mWidgetWithMouseQueue.begin(); - iter != mWidgetWithMouseQueue.end(); - iter++) - { - if (*iter == widget) - { - widgetIsPresentInQueue = true; - break; - } - } - - // Widget is not present, send an entered event and add - // it to the "widget with mouse" queue. - if (!widgetIsPresentInQueue - && Widget::widgetExists(widget)) - { - distributeMouseEvent(widget, - MouseEvent::ENTERED, - int(mLastMousePressButton), - mLastMouseX, - mLastMouseY, - false, - true); - mWidgetWithMouseQueue.push_front(widget); - } - - Widget* swap = widget; - widget = parent; - parent = (Widget*)swap->getParent(); - } - } + Gui::Gui() + : mTop(nullptr), + mGraphics(nullptr), + mInput(nullptr), + 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(); + } + + Gui::~Gui() + { + if (Widget::widgetExists(mTop)) + { + Gui::setTop(nullptr); + } + + delete mFocusHandler; + } + + void Gui::setTop(Widget* top) + { + if (mTop != nullptr) + { + mTop->_setFocusHandler(nullptr); + } + if (top != nullptr) + { + top->_setFocusHandler(mFocusHandler); + } + + mTop = top; + } + + Widget* Gui::getTop() const + { + return mTop; + } + + void Gui::setGraphics(Graphics* graphics) + { + mGraphics = graphics; + } + + Graphics* Gui::getGraphics() const + { + return mGraphics; + } + + void Gui::setInput(Input* input) + { + mInput = input; + } + + Input* Gui::getInput() const + { + return mInput; + } + + void Gui::logic() + { + if (mTop == nullptr) + { + throw GCN_EXCEPTION("No top widget set"); + } + + handleModalFocus(); + handleModalMouseInputFocus(); + + if (mInput != nullptr) + { + mInput->_pollInput(); + + handleKeyInput(); + handleMouseInput(); + } // end if + + mTop->logic(); + } + + void Gui::draw() + { + if (mTop == nullptr) + { + throw GCN_EXCEPTION("No top widget set"); + } + if (mGraphics == nullptr) + { + throw GCN_EXCEPTION("No graphics set"); + } + + if (!mTop->isVisible()) + { + return; + } + + mGraphics->_beginDraw(); + + // If top has a border, + // draw it before drawing top + if (mTop->getBorderSize() > 0) + { + auto rec = mTop->getDimension(); + rec.x -= static_cast(mTop->getBorderSize()); + rec.y -= static_cast(mTop->getBorderSize()); + rec.width += 2 * static_cast(mTop->getBorderSize()); + rec.height += 2 * static_cast(mTop->getBorderSize()); + mGraphics->pushClipArea(rec); + mTop->drawBorder(mGraphics); + mGraphics->popClipArea(); + } + + mGraphics->pushClipArea(mTop->getDimension()); + mTop->draw(mGraphics); + mGraphics->popClipArea(); + + mGraphics->_endDraw(); + } + + void Gui::focusNone() + { + mFocusHandler->focusNone(); + } + + void Gui::setTabbingEnabled(bool tabbing) + { + mTabbing = tabbing; + } + + bool Gui::isTabbingEnabled() + { + return mTabbing; + } + + void Gui::addGlobalKeyListener(KeyListener* keyListener) + { + mKeyListeners.push_back(keyListener); + } + + void Gui::removeGlobalKeyListener(KeyListener* keyListener) + { + mKeyListeners.remove(keyListener); + } + + void Gui::handleMouseInput() + { + while (!mInput->isMouseQueueEmpty()) + { + auto mouseInput = mInput->dequeueMouseInput(); + + // Save the current mouse state. It will be needed if modal focus + // changes or modal mouse input focus changes. + mLastMouseX = mouseInput.getX(); + mLastMouseY = mouseInput.getY(); + + 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."); + } + } + } + + void Gui::handleKeyInput() + { + while (!mInput->isKeyQueueEmpty()) + { + auto keyInput = mInput->dequeueKeyInput(); + + // Save modifiers state + mShiftPressed = keyInput.isShiftPressed(); + mMetaPressed = keyInput.isMetaPressed(); + mControlPressed = keyInput.isControlPressed(); + mAltPressed = keyInput.isAltPressed(); + + KeyEvent keyEventToGlobalKeyListeners(nullptr, + mShiftPressed, + mControlPressed, + mAltPressed, + mMetaPressed, + keyInput.getType(), + keyInput.isNumericPad(), + keyInput.getKey()); + + 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; + } + + auto keyEventConsumed = false; + + // Send key inputs to the focused widgets + if (mFocusHandler->getFocused() != nullptr) + { + KeyEvent keyEvent(getKeyEventSource(), + mShiftPressed, + mControlPressed, + mAltPressed, + mMetaPressed, + keyInput.getType(), + keyInput.isNumericPad(), + keyInput.getKey()); + + + if (!mFocusHandler->getFocused()->isFocusable()) + { + mFocusHandler->focusNone(); + } + else + { + distributeKeyEvent(keyEvent); + } + + keyEventConsumed = keyEvent.isConsumed(); + } + + // If the key event hasn't been consumed and + // tabbing is enable check for tab press and + // change focus. + 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())) + ) + { + // Distribute an event to all widgets in the "widget with mouse" queue. + while (!mWidgetWithMouseQueue.empty()) + { + auto* const widget = mWidgetWithMouseQueue.front(); + + if (Widget::widgetExists(widget)) + { + distributeMouseEvent(widget, + MouseEvent::EXITED, + static_cast(mouseInput.getButton()), + mouseInput.getX(), + mouseInput.getX(), + true, + true); + } + + mWidgetWithMouseQueue.pop_front(); + } + + return; + } + + // Check if there is a need to send mouse exited events by + // traversing the "widget with mouse" queue. + auto widgetWithMouseQueueCheckDone = mWidgetWithMouseQueue.empty(); + while (!widgetWithMouseQueueCheckDone) + { + unsigned int iterations = 0; + std::deque::iterator iter; + for (iter = mWidgetWithMouseQueue.begin(); + iter != mWidgetWithMouseQueue.end(); + ++iter) + { + auto* 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)) + { + mWidgetWithMouseQueue.erase(iter); + break; + } + int x, y; + widget->getAbsolutePosition(x, y); + + if (x > mouseInput.getX() + || y > mouseInput.getY() + || x + widget->getWidth() <= mouseInput.getX() + || y + widget->getHeight() <= mouseInput.getY() + || !widget->isVisible()) + { + distributeMouseEvent(widget, + MouseEvent::EXITED, + static_cast(mouseInput.getButton()), + mouseInput.getX(), + mouseInput.getX(), + true, + true); + mClickCount = 1; + mLastMousePressTimeStamp = 0; + mWidgetWithMouseQueue.erase(iter); + break; + } + + iterations++; + } + + 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. + auto* parent = getMouseEventSource(mouseInput.getX(), mouseInput.getY()); + auto* 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. + if (mFocusHandler->getModalMouseInputFocused() != nullptr + && widget == mFocusHandler->getModalMouseInputFocused() + && Widget::widgetExists(widget)) + { + int x, y; + widget->getAbsolutePosition(x, y); + + if (x > mouseInput.getX() + || y > mouseInput.getY() + || x + widget->getWidth() <= mouseInput.getX() + || y + widget->getHeight() <= mouseInput.getY()) + { + parent = nullptr; + } + } + + while (parent != nullptr) + { + parent = static_cast(widget->getParent()); + + // Check if the widget is present in the "widget with mouse" queue. + auto widgetIsPresentInQueue = false; + std::deque::iterator iter; + for (iter = mWidgetWithMouseQueue.begin(); + iter != mWidgetWithMouseQueue.end(); + ++iter) + { + if (*iter == widget) + { + widgetIsPresentInQueue = true; + break; + } + } + + // Widget is not present, send an entered event and add + // it to the "widget with mouse" queue. + if (!widgetIsPresentInQueue + && Widget::widgetExists(widget)) + { + distributeMouseEvent(widget, + MouseEvent::ENTERED, + static_cast(mouseInput.getButton()), + mouseInput.getX(), + mouseInput.getY(), + true, + true); + mWidgetWithMouseQueue.push_front(widget); + } + + auto* swap = widget; + widget = parent; + parent = static_cast(swap->getParent()); + } + + if (mFocusHandler->getDraggedWidget() != nullptr) + { + distributeMouseEvent(mFocusHandler->getDraggedWidget(), + MouseEvent::DRAGGED, + mLastMouseDragButton, + mouseInput.getX(), + mouseInput.getY()); + } + else + { + auto* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY()); + distributeMouseEvent(sourceWidget, + MouseEvent::MOVED, + static_cast(mouseInput.getButton()), + mouseInput.getX(), + mouseInput.getY()); + } + } + + void Gui::handleMousePressed(const MouseInput& mouseInput) + { + auto* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY()); + + if (mFocusHandler->getDraggedWidget() != nullptr) + { + sourceWidget = mFocusHandler->getDraggedWidget(); + } + + int sourceWidgetX, sourceWidgetY; + sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); + + distributeMouseEvent(sourceWidget, + MouseEvent::PRESSED, + static_cast(mouseInput.getButton()), + mouseInput.getX(), + mouseInput.getY()); + + mFocusHandler->setLastWidgetPressed(sourceWidget); + + if ((mFocusHandler->getModalFocused() != nullptr + && sourceWidget->hasModalFocus()) + || mFocusHandler->getModalFocused() == nullptr) + { + sourceWidget->requestFocus(); + } + + mFocusHandler->setDraggedWidget(sourceWidget); + mLastMouseDragButton = static_cast(mouseInput.getButton()); + + if (mLastMousePressTimeStamp < 300 + && mLastMousePressButton == mouseInput.getButton()) + { + mClickCount++; + } + else + { + mClickCount = 1; + } + + mLastMousePressButton = mouseInput.getButton(); + mLastMousePressTimeStamp = mouseInput.getTimeStamp(); + } + + void Gui::handleMouseWheelMovedDown(const MouseInput& mouseInput) + { + auto* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY()); + + if (mFocusHandler->getDraggedWidget() != nullptr) + { + sourceWidget = mFocusHandler->getDraggedWidget(); + } + + int sourceWidgetX, sourceWidgetY; + sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); + + distributeMouseEvent(sourceWidget, + MouseEvent::WHEEL_MOVED_DOWN, + static_cast(mouseInput.getButton()), + mouseInput.getX(), + mouseInput.getY()); + } + + void Gui::handleMouseWheelMovedUp(const MouseInput& mouseInput) + { + auto* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY()); + + if (mFocusHandler->getDraggedWidget() != nullptr) + { + sourceWidget = mFocusHandler->getDraggedWidget(); + } + + int sourceWidgetX, sourceWidgetY; + sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); + + distributeMouseEvent(sourceWidget, + MouseEvent::WHEEL_MOVED_UP, + static_cast(mouseInput.getButton()), + mouseInput.getX(), + mouseInput.getY()); + } + + void Gui::handleMouseReleased(const MouseInput& mouseInput) + { + auto* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY()); + + if (mFocusHandler->getDraggedWidget() != nullptr) + { + if (sourceWidget != mFocusHandler->getLastWidgetPressed()) + { + mFocusHandler->setLastWidgetPressed(nullptr); + } + + sourceWidget = mFocusHandler->getDraggedWidget(); + } + + int sourceWidgetX, sourceWidgetY; + sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); + + distributeMouseEvent(sourceWidget, + MouseEvent::RELEASED, + static_cast(mouseInput.getButton()), + mouseInput.getX(), + mouseInput.getY()); + + if (mouseInput.getButton() == mLastMousePressButton + && mFocusHandler->getLastWidgetPressed() == sourceWidget) + { + distributeMouseEvent(sourceWidget, + MouseEvent::CLICKED, + static_cast(mouseInput.getButton()), + mouseInput.getX(), + mouseInput.getY()); + + mFocusHandler->setLastWidgetPressed(nullptr); + } + else + { + mLastMousePressButton = 0; + mClickCount = 0; + } + + if (mFocusHandler->getDraggedWidget() != nullptr) + { + mFocusHandler->setDraggedWidget(nullptr); + } + } + + Widget* Gui::getWidgetAt(int x, int y) + { + // If the widget's parent has no child then we have found the widget.. + auto* parent = mTop; + auto* child = mTop; + + while (child != nullptr) + { + auto* swap = child; + int parentX, parentY; + parent->getAbsolutePosition(parentX, parentY); + child = parent->getWidgetAt(x - parentX, y - parentY); + parent = swap; + } + + return parent; + } + + Widget* Gui::getMouseEventSource(int x, int y) + { + auto* widget = getWidgetAt(x, y); + + if (mFocusHandler->getModalMouseInputFocused() != nullptr + && !widget->hasModalMouseInputFocus()) + { + return mFocusHandler->getModalMouseInputFocused(); + } + + return widget; + } + + Widget* Gui::getKeyEventSource() + { + auto* widget = mFocusHandler->getFocused(); + + while (widget->_getInternalFocusHandler() != nullptr + && widget->_getInternalFocusHandler()->getFocused() != nullptr) + { + widget = widget->_getInternalFocusHandler()->getFocused(); + } + + return widget; + } + + void Gui::distributeMouseEvent(Widget* source, + int type, + int button, + int x, + int y, + bool force, + bool toSourceOnly) + { + auto* parent = source; + auto* widget = source; + + if (mFocusHandler->getModalFocused() != nullptr + && !widget->hasModalFocus() + && !force) + { + return; + } + + if (mFocusHandler->getModalMouseInputFocused() != nullptr + && !widget->hasModalMouseInputFocus() + && !force) + { + return; + } + + MouseEvent mouseEvent(source, + mShiftPressed, + mControlPressed, + mAltPressed, + mMetaPressed, + type, + button, + x, + y, + mClickCount); + + while (parent != nullptr) + { + // If the widget has been removed due to input + // cancel the distribution. + if (!Widget::widgetExists(widget)) + { + break; + } + + parent = static_cast(widget->getParent()); + + if (widget->isEnabled() || force) + { + int widgetX, widgetY; + widget->getAbsolutePosition(widgetX, widgetY); + + mouseEvent.mX = x - widgetX; + mouseEvent.mY = y - widgetY; + + auto mouseListeners = widget->_getMouseListeners(); + + // Send the event to all mouse listeners of the widget. + for (auto& mouseListener : mouseListeners) + { + switch (mouseEvent.getType()) + { + case MouseEvent::ENTERED: + mouseListener->mouseEntered(mouseEvent); + break; + case MouseEvent::EXITED: + mouseListener->mouseExited(mouseEvent); + break; + case MouseEvent::MOVED: + mouseListener->mouseMoved(mouseEvent); + break; + case MouseEvent::PRESSED: + mouseListener->mousePressed(mouseEvent); + break; + case MouseEvent::RELEASED: + mouseListener->mouseReleased(mouseEvent); + break; + case MouseEvent::WHEEL_MOVED_UP: + mouseListener->mouseWheelMovedUp(mouseEvent); + break; + case MouseEvent::WHEEL_MOVED_DOWN: + mouseListener->mouseWheelMovedDown(mouseEvent); + break; + case MouseEvent::DRAGGED: + mouseListener->mouseDragged(mouseEvent); + break; + case MouseEvent::CLICKED: + mouseListener->mouseClicked(mouseEvent); + break; + default: + throw GCN_EXCEPTION("Unknown mouse event type."); + } + } + + if (toSourceOnly) + { + break; + } + } + + auto* swap = widget; + widget = parent; + parent = static_cast(swap->getParent()); + + // If a non modal focused widget has been reach + // and we have modal focus cancel the distribution. + if (mFocusHandler->getModalFocused() != nullptr + && !widget->hasModalFocus()) + { + break; + } + + // If a non modal mouse input focused widget has been reach + // and we have modal mouse input focus cancel the distribution. + if (mFocusHandler->getModalMouseInputFocused() != nullptr + && !widget->hasModalMouseInputFocus()) + { + break; + } + } + } + + void Gui::distributeKeyEvent(KeyEvent& keyEvent) + { + auto* parent = keyEvent.getSource(); + auto* widget = keyEvent.getSource(); + + if (mFocusHandler->getModalFocused() != nullptr + && !widget->hasModalFocus()) + { + return; + } + + if (mFocusHandler->getModalMouseInputFocused() != nullptr + && !widget->hasModalMouseInputFocus()) + { + return; + } + + while (parent != nullptr) + { + // If the widget has been removed due to input + // cancel the distribution. + if (!Widget::widgetExists(widget)) + { + break; + } + + parent = static_cast(widget->getParent()); + + if (widget->isEnabled()) + { + auto keyListeners = widget->_getKeyListeners(); + + // Send the event to all key listeners of the source widget. + for (auto& keyListener : keyListeners) + { + switch (keyEvent.getType()) + { + case KeyEvent::PRESSED: + keyListener->keyPressed(keyEvent); + break; + case KeyEvent::RELEASED: + keyListener->keyReleased(keyEvent); + break; + default: + throw GCN_EXCEPTION("Unknown key event type."); + } + } + } + + auto* swap = widget; + widget = parent; + parent = static_cast(swap->getParent()); + + // If a non modal focused widget has been reach + // and we have modal focus cancel the distribution. + if (mFocusHandler->getModalFocused() != nullptr + && !widget->hasModalFocus()) + { + break; + } + } + } + + void Gui::distributeKeyEventToGlobalKeyListeners(KeyEvent& keyEvent) + { + for (auto& mKeyListener : mKeyListeners) + { + switch (keyEvent.getType()) + { + case KeyEvent::PRESSED: + mKeyListener->keyPressed(keyEvent); + break; + case KeyEvent::RELEASED: + mKeyListener->keyReleased(keyEvent); + break; + default: + throw GCN_EXCEPTION("Unknown key event type."); + } + + if (keyEvent.isConsumed()) + { + break; + } + } + } + + void Gui::handleModalMouseInputFocus() + { + // Check if modal mouse input focus has been gained by a widget. + if (mFocusHandler->getLastWidgetWithModalMouseInputFocus() + != mFocusHandler->getModalMouseInputFocused() + && mFocusHandler->getLastWidgetWithModalMouseInputFocus() == nullptr) + { + handleModalFocusGained(); + mFocusHandler->setLastWidgetWithModalMouseInputFocus(mFocusHandler->getModalMouseInputFocused()); + } + // Check if modal mouse input focus has been released. + else if (mFocusHandler->getLastWidgetWithModalMouseInputFocus() + != mFocusHandler->getModalMouseInputFocused() + && mFocusHandler->getLastWidgetWithModalMouseInputFocus() != nullptr) + { + handleModalFocusReleased(); + mFocusHandler->setLastWidgetWithModalMouseInputFocus(nullptr); + } + } + + void Gui::handleModalFocus() + { + // Check if modal focus has been gained by a widget. + if (mFocusHandler->getLastWidgetWithModalFocus() + != mFocusHandler->getModalFocused() + && mFocusHandler->getLastWidgetWithModalFocus() == nullptr) + { + handleModalFocusGained(); + mFocusHandler->setLastWidgetWithModalFocus(mFocusHandler->getModalFocused()); + } + // Check if modal focus has been released. + else if (mFocusHandler->getLastWidgetWithModalFocus() + != mFocusHandler->getModalFocused() + && mFocusHandler->getLastWidgetWithModalFocus() != nullptr) + { + handleModalFocusReleased(); + mFocusHandler->setLastWidgetWithModalFocus(nullptr); + } + } + + void Gui::handleModalFocusGained() + { + // Distribute an event to all widgets in the "widget with mouse" queue. + while (!mWidgetWithMouseQueue.empty()) + { + auto* widget = mWidgetWithMouseQueue.front(); + + if (Widget::widgetExists(widget)) + { + distributeMouseEvent(widget, + MouseEvent::EXITED, + static_cast(mLastMousePressButton), + mLastMouseX, + mLastMouseY, + true, + true); + } + + mWidgetWithMouseQueue.pop_front(); + } + + mFocusHandler->setLastWidgetWithModalMouseInputFocus(mFocusHandler->getModalMouseInputFocused()); + } + + void Gui::handleModalFocusReleased() + { + // 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. + auto* widget = getMouseEventSource(mLastMouseX, mLastMouseY); + auto* parent = widget; + + while (parent != nullptr) + { + parent = static_cast(widget->getParent()); + + // Check if the widget is present in the "widget with mouse" queue. + auto widgetIsPresentInQueue = false; + std::deque::iterator iter; + for (iter = mWidgetWithMouseQueue.begin(); + iter != mWidgetWithMouseQueue.end(); + ++iter) + { + if (*iter == widget) + { + widgetIsPresentInQueue = true; + break; + } + } + + // Widget is not present, send an entered event and add + // it to the "widget with mouse" queue. + if (!widgetIsPresentInQueue + && Widget::widgetExists(widget)) + { + distributeMouseEvent(widget, + MouseEvent::ENTERED, + static_cast(mLastMousePressButton), + mLastMouseX, + mLastMouseY, + false, + true); + mWidgetWithMouseQueue.push_front(widget); + } + + auto* swap = widget; + widget = parent; + parent = static_cast(swap->getParent()); + } + } } diff --git a/external/libguisan/src/guisan.cpp b/external/libguisan/src/guisan.cpp index c8321d12..c67f4c17 100644 --- a/external/libguisan/src/guisan.cpp +++ b/external/libguisan/src/guisan.cpp @@ -59,10 +59,9 @@ * For comments regarding functions please see the header file. */ -extern "C" +extern "C" { +const char* gcnGuisanVersion() { - const char* gcnGuisanVersion() - { - return "0.9.0"; - } + return "0.9.0"; +} } diff --git a/external/libguisan/src/image.cpp b/external/libguisan/src/image.cpp index 58b2ead9..fef0279b 100644 --- a/external/libguisan/src/image.cpp +++ b/external/libguisan/src/image.cpp @@ -65,34 +65,31 @@ namespace gcn { + ImageLoader* Image::mImageLoader = nullptr; - ImageLoader* Image::mImageLoader = NULL; + Image::Image() + = default; - Image::Image() - { - } + Image::~Image() + = default; - Image::~Image() - { - } + void Image::setImageLoader(ImageLoader* imageLoader) + { + mImageLoader = imageLoader; + } - void Image::setImageLoader(ImageLoader* imageLoader) - { - mImageLoader = imageLoader; - } + ImageLoader* Image::getImageLoader() + { + return mImageLoader; + } - ImageLoader* Image::getImageLoader() - { - return mImageLoader; - } + Image* Image::load(const std::string& filename, bool convertToDisplayFormat) + { + if (mImageLoader == nullptr) + { + throw GCN_EXCEPTION("Trying to load an image but no image loader is set."); + } - 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."); - } - - return mImageLoader->load(filename, convertToDisplayFormat); - } + return mImageLoader->load(filename, convertToDisplayFormat); + } } diff --git a/external/libguisan/src/imagefont.cpp b/external/libguisan/src/imagefont.cpp index 9fa996fe..812ca9a8 100644 --- a/external/libguisan/src/imagefont.cpp +++ b/external/libguisan/src/imagefont.cpp @@ -69,255 +69,252 @@ namespace gcn { - ImageFont::ImageFont(const std::string& filename, const std::string& glyphs) - { - mFilename = filename; - mImage = Image::load(filename, false); + ImageFont::ImageFont(const std::string& filename, const std::string& glyphs) + { + mFilename = filename; + mImage = Image::load(filename, false); - Color separator = mImage->getPixel(0, 0); - - int i = 0; - for (i = 0; - i < mImage->getWidth() && separator == mImage->getPixel(i, 0); - ++i) - { - } - - if (i >= mImage->getWidth()) - { - throw GCN_EXCEPTION("Corrupt image."); - } + const auto separator = mImage->getPixel(0, 0); - int j = 0; - for (j = 0; j < mImage->getHeight(); ++j) - { - if (separator == mImage->getPixel(i, j)) - { - break; - } - } + int i; + for (i = 0; + i < mImage->getWidth() && separator == mImage->getPixel(i, 0); + ++i) + { + } - mHeight = j; - int x = 0, y = 0; - unsigned char k; + if (i >= mImage->getWidth()) + { + throw GCN_EXCEPTION("Corrupt image."); + } - for (i=0; i < (int)glyphs.size(); ++i) - { - k = glyphs.at(i); - addGlyph(k, x, y, separator); - } + int j; + for (j = 0; j < mImage->getHeight(); ++j) + { + if (separator == mImage->getPixel(i, j)) + { + break; + } + } - //int w = mImage->getWidth(); - //int h = mImage->getHeight(); - mImage->convertToDisplayFormat(); + mHeight = j; + auto x = 0, y = 0; - mRowSpacing = 0; - mGlyphSpacing = 0; - } + for (i = 0; i < static_cast(glyphs.size()); ++i) + { + const unsigned char k = glyphs.at(i); + addGlyph(k, x, y, separator); + } - ImageFont::ImageFont(const std::string& filename, unsigned char glyphsFrom, - unsigned char glyphsTo) - { - mFilename = filename; - mImage = Image::load(filename, false); + //int w = mImage->getWidth(); + //int h = mImage->getHeight(); + mImage->convertToDisplayFormat(); - Color separator = mImage->getPixel(0, 0); + mRowSpacing = 0; + mGlyphSpacing = 0; + } - int i = 0; - for (i=0; separator == mImage->getPixel(i, 0) - && i < mImage->getWidth(); ++i) - { - } + ImageFont::ImageFont(const std::string& filename, unsigned char glyphsFrom, + unsigned char glyphsTo) + { + mFilename = filename; + mImage = Image::load(filename, false); - if (i >= mImage->getWidth()) - { - throw GCN_EXCEPTION("Corrupt image."); - } + const auto separator = mImage->getPixel(0, 0); - int j = 0; - for (j = 0; j < mImage->getHeight(); ++j) - { - if (separator == mImage->getPixel(i, j)) - { - break; - } - } + int i; + for (i = 0; separator == mImage->getPixel(i, 0) + && i < mImage->getWidth(); ++i) + { + } - mHeight = j; - int x = 0, y = 0; + if (i >= mImage->getWidth()) + { + throw GCN_EXCEPTION("Corrupt image."); + } - for (i=glyphsFrom; igetHeight(); ++j) + { + if (separator == mImage->getPixel(i, j)) + { + break; + } + } - //int w = mImage->getWidth(); - //int h = mImage->getHeight(); - mImage->convertToDisplayFormat(); + mHeight = j; + auto x = 0, y = 0; - mRowSpacing = 0; - mGlyphSpacing = 0; - } + for (i = glyphsFrom; i < glyphsTo + 1; i++) + { + addGlyph(i, x, y, separator); + } - ImageFont::~ImageFont() - { - delete mImage; - } + //int w = mImage->getWidth(); + //int h = mImage->getHeight(); + mImage->convertToDisplayFormat(); - int ImageFont::getWidth(unsigned char glyph) const - { - if (mGlyph[glyph].width == 0) - { - return mGlyph[(int)(' ')].width + mGlyphSpacing; - } + mRowSpacing = 0; + mGlyphSpacing = 0; + } - return mGlyph[glyph].width + mGlyphSpacing; - } + ImageFont::~ImageFont() + { + delete mImage; + } - int ImageFont::getHeight() const - { - return mHeight + mRowSpacing; - } + int ImageFont::getWidth(unsigned char glyph) const + { + if (mGlyph[glyph].width == 0) + { + return mGlyph[static_cast(' ')].width + mGlyphSpacing; + } - int ImageFont::drawGlyph(Graphics* graphics, unsigned char glyph, - int x, int y) - { - // This is needed for drawing the Glyph in the middle if we have spacing - int yoffset = getRowSpacing() >> 1; + return mGlyph[glyph].width + mGlyphSpacing; + } - if (mGlyph[glyph].width == 0) - { - graphics->drawRectangle(Rectangle(x, y + 1 + yoffset, - mGlyph[(int)(' ')].width - 1, - mGlyph[(int)(' ')].height - 2)); + int ImageFont::getHeight() const + { + return mHeight + mRowSpacing; + } - return mGlyph[(int)(' ')].width + mGlyphSpacing; - } + int ImageFont::drawGlyph(Graphics* graphics, unsigned char glyph, + int x, int y) + { + // This is needed for drawing the Glyph in the middle if we have spacing + const auto yoffset = getRowSpacing() >> 1; - graphics->drawImage(mImage, mGlyph[glyph].x, mGlyph[glyph].y, x, - y + yoffset, mGlyph[glyph].width, - mGlyph[glyph].height); + if (mGlyph[glyph].width == 0) + { + graphics->drawRectangle(Rectangle(x, y + 1 + yoffset, + mGlyph[static_cast(' ')].width - 1, + mGlyph[static_cast(' ')].height - 2)); - return mGlyph[glyph].width + mGlyphSpacing; - } + return mGlyph[static_cast(' ')].width + mGlyphSpacing; + } - void ImageFont::drawString(Graphics* graphics, const std::string& text, - int x, int y) - { - unsigned int i; + graphics->drawImage(mImage, mGlyph[glyph].x, mGlyph[glyph].y, x, + y + yoffset, mGlyph[glyph].width, + mGlyph[glyph].height); - for (i = 0; i< text.size(); ++i) - { - drawGlyph(graphics, text.at(i), x, y); - x += getWidth(text.at(i)); - } - } + return mGlyph[glyph].width + mGlyphSpacing; + } - void ImageFont::setRowSpacing(int spacing) - { - mRowSpacing = spacing; - } + void ImageFont::drawString(Graphics* graphics, const std::string& text, + int x, int y) + { + unsigned int i; - int ImageFont::getRowSpacing() - { - return mRowSpacing; - } + for (i = 0; i < text.size(); ++i) + { + drawGlyph(graphics, text.at(i), x, y); + x += getWidth(text.at(i)); + } + } - void ImageFont::setGlyphSpacing(int spacing) - { - mGlyphSpacing = spacing; - } + void ImageFont::setRowSpacing(int spacing) + { + mRowSpacing = spacing; + } - int ImageFont::getGlyphSpacing() - { - return mGlyphSpacing; - } + int ImageFont::getRowSpacing() + { + return mRowSpacing; + } - void ImageFont::addGlyph(unsigned char c, int &x, - int &y, const Color& separator) - { - Color color; - do - { - ++x; + void ImageFont::setGlyphSpacing(int spacing) + { + mGlyphSpacing = spacing; + } - if (x >= mImage->getWidth()) - { - y += mHeight + 1; - x = 0; + int ImageFont::getGlyphSpacing() + { + return mGlyphSpacing; + } - if (y >= mImage->getHeight()) - { - std::string str; - std::ostringstream os(str); - os << "Image "; - os << mFilename; - os << " with font is corrupt near character '"; - os << c; - os << "'"; - throw GCN_EXCEPTION(os.str()); - } - } + void ImageFont::addGlyph(unsigned char c, int& x, + int& y, const Color& separator) + { + Color color; + do + { + ++x; - color = mImage->getPixel(x, y); + if (x >= mImage->getWidth()) + { + y += mHeight + 1; + x = 0; - } while (color == separator); + if (y >= mImage->getHeight()) + { + std::string str; + std::ostringstream os(str); + os << "Image "; + os << mFilename; + os << " with font is corrupt near character '"; + os << c; + os << "'"; + throw GCN_EXCEPTION(os.str()); + } + } - int w = 0; + color = mImage->getPixel(x, y); + } + while (color == separator); - do - { - ++w; + int w = 0; - if (x+w >= mImage->getWidth()) - { - std::string str; - std::ostringstream os(str); - os << "Image "; - os << mFilename; - os << " with font is corrupt near character '"; - os << c; - os << "'"; - throw GCN_EXCEPTION(os.str()); - } + do + { + ++w; - color = mImage->getPixel(x + w, y); + if (x + w >= mImage->getWidth()) + { + std::string str; + std::ostringstream os(str); + os << "Image "; + os << mFilename; + os << " with font is corrupt near character '"; + os << c; + os << "'"; + throw GCN_EXCEPTION(os.str()); + } - } while (color != separator); + color = mImage->getPixel(x + w, y); + } + while (color != separator); - mGlyph[c] = Rectangle(x, y, w, mHeight); + mGlyph[c] = Rectangle(x, y, w, mHeight); - x += w; - } + x += w; + } - int ImageFont::getWidth(const std::string& text) const - { - unsigned int i; - int size = 0; + int ImageFont::getWidth(const std::string& text) const + { + auto size = 0; - for (i = 0; i < text.size(); ++i) - { - size += getWidth(text.at(i)); - } + for (auto i : text) + { + size += getWidth(i); + } return size - mGlyphSpacing; - } + } - int ImageFont::getStringIndexAt(const std::string& text, int x) - { - unsigned int i; - int size = 0; + int ImageFont::getStringIndexAt(const std::string& text, int x) + { + auto size = 0; - for (i = 0; i < text.size(); ++i) - { - size += getWidth(text.at(i)); + for (auto i = 0; i < static_cast(text.size()); ++i) + { + size += getWidth(text.at(i)); - if (size > x) - { - return i; - } - } + if (size > x) + { + return i; + } + } - return text.size(); - } + return text.size(); + } } diff --git a/external/libguisan/src/inputevent.cpp b/external/libguisan/src/inputevent.cpp index 734e9904..91827afd 100644 --- a/external/libguisan/src/inputevent.cpp +++ b/external/libguisan/src/inputevent.cpp @@ -62,48 +62,47 @@ namespace gcn { - InputEvent::InputEvent(Widget* source, - bool isShiftPressed, - bool isControlPressed, - bool isAltPressed, - bool isMetaPressed) - :Event(source), - mShiftPressed(isShiftPressed), - mControlPressed(isControlPressed), - mAltPressed(isAltPressed), - mMetaPressed(isMetaPressed), - mIsConsumed(false) - { + InputEvent::InputEvent(Widget* source, + bool isShiftPressed, + bool isControlPressed, + bool isAltPressed, + bool isMetaPressed) + : Event(source), + mShiftPressed(isShiftPressed), + mControlPressed(isControlPressed), + mAltPressed(isAltPressed), + mMetaPressed(isMetaPressed), + mIsConsumed(false) + { + } - } + bool InputEvent::isShiftPressed() const + { + return mShiftPressed; + } - bool InputEvent::isShiftPressed() const - { - return mShiftPressed; - } + bool InputEvent::isControlPressed() const + { + return mControlPressed; + } - bool InputEvent::isControlPressed() const - { - return mControlPressed; - } + bool InputEvent::isAltPressed() const + { + return mAltPressed; + } - bool InputEvent::isAltPressed() const - { - return mAltPressed; - } + bool InputEvent::isMetaPressed() const + { + return mMetaPressed; + } - bool InputEvent::isMetaPressed() const - { - return mMetaPressed; - } + void InputEvent::consume() + { + mIsConsumed = true; + } - void InputEvent::consume() - { - mIsConsumed = true; - } - - bool InputEvent::isConsumed() const - { - return mIsConsumed; - } + bool InputEvent::isConsumed() const + { + return mIsConsumed; + } } diff --git a/external/libguisan/src/key.cpp b/external/libguisan/src/key.cpp index 7497a088..c3b18626 100644 --- a/external/libguisan/src/key.cpp +++ b/external/libguisan/src/key.cpp @@ -62,41 +62,41 @@ namespace gcn { - Key::Key(int value) - :mValue(value) - { - } + Key::Key(int value) + : mValue(value) + { + } - bool Key::isCharacter() const - { - return (mValue >= 32 && mValue <= 126) - || (mValue >= 162 && mValue <= 255) - || (mValue == 9); - } + bool Key::isCharacter() const + { + return (mValue >= 32 && mValue <= 126) + || (mValue >= 162 && mValue <= 255) + || (mValue == 9); + } - bool Key::isNumber() const - { - return mValue >= 48 && mValue <= 57; - } + bool Key::isNumber() const + { + return mValue >= 48 && mValue <= 57; + } - bool Key::isLetter() const - { - return (((mValue >= 65 && mValue <= 90) - || (mValue >= 97 && mValue <= 122) - || (mValue >= 192 && mValue <= 255)) - && (mValue != 215) && (mValue != 247)); - } + bool Key::isLetter() const + { + return (((mValue >= 65 && mValue <= 90) + || (mValue >= 97 && mValue <= 122) + || (mValue >= 192 && mValue <= 255)) + && (mValue != 215) && (mValue != 247)); + } + + int Key::getValue() const + { + return mValue; + } - int Key::getValue() const - { - return mValue; - } - char Key::getChar() const { - if(mValue == 9 || mValue == 13 || (mValue <= 122 && mValue >= 32)) - return (char)mValue; - + if (mValue == 9 || mValue == 13 || (mValue <= 122 && mValue >= 32)) + return static_cast(mValue); + return '\0'; } } diff --git a/external/libguisan/src/keyevent.cpp b/external/libguisan/src/keyevent.cpp index ff13596d..0ecfb154 100644 --- a/external/libguisan/src/keyevent.cpp +++ b/external/libguisan/src/keyevent.cpp @@ -62,43 +62,40 @@ namespace gcn { - KeyEvent::KeyEvent(Widget* source, - bool isShiftPressed, - bool isControlPressed, - bool isAltPressed, - bool isMetaPressed, - unsigned int type, - bool isNumericPad, - const Key& key) - :InputEvent(source, - isShiftPressed, - isControlPressed, - isAltPressed, - isMetaPressed), - mType(type), - mIsNumericPad(isNumericPad), - mKey(key) - { + KeyEvent::KeyEvent(Widget* source, + bool isShiftPressed, + bool isControlPressed, + bool isAltPressed, + bool isMetaPressed, + unsigned int type, + bool isNumericPad, + const Key& key) + : InputEvent(source, + isShiftPressed, + isControlPressed, + isAltPressed, + isMetaPressed), + mType(type), + mIsNumericPad(isNumericPad), + mKey(key) + { + } - } + KeyEvent::~KeyEvent() + = default; - KeyEvent::~KeyEvent() - { + unsigned int KeyEvent::getType() const + { + return mType; + } - } + bool KeyEvent::isNumericPad() const + { + return mIsNumericPad; + } - unsigned int KeyEvent::getType() const - { - return mType; - } - - bool KeyEvent::isNumericPad() const - { - return mIsNumericPad; - } - - const Key& KeyEvent::getKey() const - { - return mKey; - } + const Key& KeyEvent::getKey() const + { + return mKey; + } } diff --git a/external/libguisan/src/keyinput.cpp b/external/libguisan/src/keyinput.cpp index dc485e58..dbac6f92 100644 --- a/external/libguisan/src/keyinput.cpp +++ b/external/libguisan/src/keyinput.cpp @@ -62,86 +62,84 @@ namespace gcn { - KeyInput::KeyInput(const Key& key, int type) - :mKey(key), - mType(type), - mShiftPressed(false), - mControlPressed(false), - mAltPressed(false), - mMetaPressed(false), - mNumericPad(false) - { + KeyInput::KeyInput(const Key& key, int type) + : mKey(key), + mType(type), + mShiftPressed(false), + mControlPressed(false), + mAltPressed(false), + mMetaPressed(false), + mNumericPad(false) + { + } - } + void KeyInput::setType(int type) + { + mType = type; + } - void KeyInput::setType(int type) - { - mType = type; - } + int KeyInput::getType() const + { + return mType; + } - int KeyInput::getType() const - { - return mType; - } + void KeyInput::setKey(const Key& key) + { + mKey = key; + } - void KeyInput::setKey(const Key& key) - { - mKey = key; - } + const Key& KeyInput::getKey() const + { + return mKey; + } - const Key& KeyInput::getKey() const - { - return mKey; - } + bool KeyInput::isShiftPressed() const + { + return mShiftPressed; + } - bool KeyInput::isShiftPressed() const - { - return mShiftPressed; - } + void KeyInput::setShiftPressed(bool pressed) + { + mShiftPressed = pressed; + } - void KeyInput::setShiftPressed(bool pressed) - { - mShiftPressed = pressed; - } + bool KeyInput::isControlPressed() const + { + return mControlPressed; + } - bool KeyInput::isControlPressed() const - { - return mControlPressed; - } + void KeyInput::setControlPressed(bool pressed) + { + mControlPressed = pressed; + } - void KeyInput::setControlPressed(bool pressed) - { - mControlPressed = pressed; - } + bool KeyInput::isAltPressed() const + { + return mAltPressed; + } - bool KeyInput::isAltPressed() const - { - return mAltPressed; - } + void KeyInput::setAltPressed(bool pressed) + { + mAltPressed = pressed; + } - void KeyInput::setAltPressed(bool pressed) - { - mAltPressed = pressed; - } + bool KeyInput::isMetaPressed() const + { + return mMetaPressed; + } - bool KeyInput::isMetaPressed() const - { - return mMetaPressed; - } + void KeyInput::setMetaPressed(bool pressed) + { + mMetaPressed = pressed; + } - void KeyInput::setMetaPressed(bool pressed) - { - mMetaPressed = pressed; - } + bool KeyInput::isNumericPad() const + { + return mNumericPad; + } - bool KeyInput::isNumericPad() const - { - return mNumericPad; - } - - void KeyInput::setNumericPad(bool numpad) - { - mNumericPad = numpad; - } + void KeyInput::setNumericPad(bool numpad) + { + mNumericPad = numpad; + } } - diff --git a/external/libguisan/src/mouseevent.cpp b/external/libguisan/src/mouseevent.cpp index 6c370569..cd0e09f4 100644 --- a/external/libguisan/src/mouseevent.cpp +++ b/external/libguisan/src/mouseevent.cpp @@ -62,52 +62,51 @@ namespace gcn { - MouseEvent::MouseEvent(Widget* source, - bool isShiftPressed, - bool isControlPressed, - bool isAltPressed, - bool isMetaPressed, - unsigned int type, - unsigned int button, - int x, - int y, - int clickCount) - :InputEvent(source, - isShiftPressed, - isControlPressed, - isAltPressed, - isMetaPressed), - mType(type), - mButton(button), - mX(x), - mY(y), - mClickCount(clickCount) - { + MouseEvent::MouseEvent(Widget* source, + bool isShiftPressed, + bool isControlPressed, + bool isAltPressed, + bool isMetaPressed, + unsigned int type, + unsigned int button, + int x, + int y, + int clickCount) + : InputEvent(source, + isShiftPressed, + isControlPressed, + isAltPressed, + isMetaPressed), + mType(type), + mButton(button), + mX(x), + mY(y), + mClickCount(clickCount) + { + } - } + unsigned int MouseEvent::getButton() const + { + return mButton; + } - unsigned int MouseEvent::getButton() const - { - return mButton; - } + int MouseEvent::getX() const + { + return mX; + } - int MouseEvent::getX() const - { - return mX; - } + int MouseEvent::getY() const + { + return mY; + } - int MouseEvent::getY() const - { - return mY; - } + int MouseEvent::getClickCount() const + { + return mClickCount; + } - int MouseEvent::getClickCount() const - { - return mClickCount; - } - - unsigned int MouseEvent::getType() const - { - return mType; - } + unsigned int MouseEvent::getType() const + { + return mType; + } } diff --git a/external/libguisan/src/mouseinput.cpp b/external/libguisan/src/mouseinput.cpp index 153f536f..4e0ffac6 100644 --- a/external/libguisan/src/mouseinput.cpp +++ b/external/libguisan/src/mouseinput.cpp @@ -62,66 +62,66 @@ namespace gcn { - MouseInput::MouseInput(unsigned int button, - unsigned int type, - int x, - int y, - int timeStamp) - : mType(type), - mButton(button), - mTimeStamp(timeStamp), - mX(x), - mY(y) - { - } + MouseInput::MouseInput(unsigned int button, + unsigned int type, + int x, + int y, + int timeStamp) + : mType(type), + mButton(button), + mTimeStamp(timeStamp), + mX(x), + mY(y) + { + } - void MouseInput::setType(unsigned int type) - { - mType = type; - } + void MouseInput::setType(unsigned int type) + { + mType = type; + } - unsigned int MouseInput::getType() const - { - return mType; - } + unsigned int MouseInput::getType() const + { + return mType; + } - void MouseInput::setButton(unsigned int button) - { - mButton = button; - } + void MouseInput::setButton(unsigned int button) + { + mButton = button; + } - unsigned int MouseInput::getButton() const - { - return mButton; - } + unsigned int MouseInput::getButton() const + { + return mButton; + } - int MouseInput::getTimeStamp() const - { - return mTimeStamp; - } + int MouseInput::getTimeStamp() const + { + return mTimeStamp; + } - void MouseInput::setTimeStamp(int timeStamp) - { - mTimeStamp = timeStamp; - } + void MouseInput::setTimeStamp(int timeStamp) + { + mTimeStamp = timeStamp; + } - void MouseInput::setX(int x) - { - mX = x; - } + void MouseInput::setX(int x) + { + mX = x; + } - int MouseInput::getX() const - { - return mX; - } + int MouseInput::getX() const + { + return mX; + } - void MouseInput::setY(int y) - { - mY = y; - } + void MouseInput::setY(int y) + { + mY = y; + } - int MouseInput::getY() const - { - return mY; - } + int MouseInput::getY() const + { + return mY; + } } diff --git a/external/libguisan/src/opengl/opengl.cpp b/external/libguisan/src/opengl/opengl.cpp index 1e515373..47c6c64a 100644 --- a/external/libguisan/src/opengl/opengl.cpp +++ b/external/libguisan/src/opengl/opengl.cpp @@ -60,7 +60,8 @@ #include "guisan/opengl.hpp" -extern "C" +extern "C" { +void gcnOpenGL() { - void gcnOpenGL() { } +} } diff --git a/external/libguisan/src/opengl/openglgraphics.cpp b/external/libguisan/src/opengl/openglgraphics.cpp index 7c1a31e3..5af6808f 100644 --- a/external/libguisan/src/opengl/openglgraphics.cpp +++ b/external/libguisan/src/opengl/openglgraphics.cpp @@ -77,277 +77,281 @@ namespace gcn { - OpenGLGraphics::OpenGLGraphics() - { - setTargetPlane(640, 480); - mAlpha = false; - } + OpenGLGraphics::OpenGLGraphics() + { + OpenGLGraphics::setTargetPlane(640, 480); + mAlpha = false; + } - OpenGLGraphics::OpenGLGraphics(int width, int height) - { - setTargetPlane(width, height); - } + OpenGLGraphics::OpenGLGraphics(int width, int height) + { + setTargetPlane(width, height); + } - OpenGLGraphics::~OpenGLGraphics() - { + OpenGLGraphics::~OpenGLGraphics() + { + } - } + void OpenGLGraphics::_beginDraw() + { + glPushAttrib( + GL_COLOR_BUFFER_BIT | + GL_CURRENT_BIT | + GL_DEPTH_BUFFER_BIT | + GL_ENABLE_BIT | + GL_FOG_BIT | + GL_LIGHTING_BIT | + GL_LINE_BIT | + GL_POINT_BIT | + GL_POLYGON_BIT | + GL_SCISSOR_BIT | + GL_STENCIL_BUFFER_BIT | + GL_TEXTURE_BIT | + GL_TRANSFORM_BIT | + GL_POINT_BIT | + GL_LINE_BIT + ); - void OpenGLGraphics::_beginDraw() - { - glPushAttrib( - GL_COLOR_BUFFER_BIT | - GL_CURRENT_BIT | - GL_DEPTH_BUFFER_BIT | - GL_ENABLE_BIT | - GL_FOG_BIT | - GL_LIGHTING_BIT | - GL_LINE_BIT | - GL_POINT_BIT | - GL_POLYGON_BIT | - GL_SCISSOR_BIT | - GL_STENCIL_BUFFER_BIT | - GL_TEXTURE_BIT | - GL_TRANSFORM_BIT | - GL_POINT_BIT | - GL_LINE_BIT - ); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + glLoadIdentity(); - glMatrixMode(GL_TEXTURE); - glPushMatrix(); - glLoadIdentity(); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); + glOrtho(0.0, static_cast(mWidth), static_cast(mHeight), 0.0, -1.0, 1.0); - glOrtho(0.0, (double)mWidth, (double)mHeight, 0.0, -1.0, 1.0); + glDisable(GL_LIGHTING); + glDisable(GL_CULL_FACE); + glDisable(GL_DEPTH_TEST); + glDisable(GL_TEXTURE_2D); - glDisable(GL_LIGHTING); - glDisable(GL_CULL_FACE); - glDisable(GL_DEPTH_TEST); - glDisable(GL_TEXTURE_2D); + glEnable(GL_SCISSOR_TEST); + glPointSize(1.0); + glLineWidth(1.0); - glEnable(GL_SCISSOR_TEST); - glPointSize(1.0); - glLineWidth(1.0); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + pushClipArea(Rectangle(0, 0, mWidth, mHeight)); + } - pushClipArea(Rectangle(0, 0, mWidth, mHeight)); - } + void OpenGLGraphics::_endDraw() + { + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); - void OpenGLGraphics::_endDraw() - { - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); + glMatrixMode(GL_TEXTURE); + glPopMatrix(); - glMatrixMode(GL_TEXTURE); - glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); + glPopAttrib(); - glPopAttrib(); + popClipArea(); + } - popClipArea(); - } + bool OpenGLGraphics::pushClipArea(Rectangle area) + { + bool result = Graphics::pushClipArea(area); - bool OpenGLGraphics::pushClipArea(Rectangle area) - { - bool result = Graphics::pushClipArea(area); + glScissor(mClipStack.top().x, + mHeight - mClipStack.top().y - mClipStack.top().height, + mClipStack.top().width, + mClipStack.top().height); - glScissor(mClipStack.top().x, - mHeight - mClipStack.top().y - mClipStack.top().height, - mClipStack.top().width, - mClipStack.top().height); + return result; + } - return result; - } + void OpenGLGraphics::popClipArea() + { + Graphics::popClipArea(); - void OpenGLGraphics::popClipArea() - { - Graphics::popClipArea(); + if (mClipStack.empty()) + { + return; + } - if (mClipStack.empty()) - { - return; - } + glScissor(mClipStack.top().x, + mHeight - mClipStack.top().y - mClipStack.top().height, + mClipStack.top().width, + mClipStack.top().height); + } - glScissor(mClipStack.top().x, - mHeight - mClipStack.top().y - mClipStack.top().height, - mClipStack.top().width, - mClipStack.top().height); - } + void OpenGLGraphics::setTargetPlane(int width, int height) + { + mWidth = width; + mHeight = height; + } - void OpenGLGraphics::setTargetPlane(int width, int height) - { - mWidth = width; - mHeight = height; - } + void OpenGLGraphics::drawImage(const Image* image, int srcX, int srcY, + int dstX, int dstY, int width, + int height) + { + const OpenGLImage* srcImage = dynamic_cast(image); - void OpenGLGraphics::drawImage(const Image* image, int srcX, int srcY, - int dstX, int dstY, int width, - int height) - { - const OpenGLImage* srcImage = dynamic_cast(image); + if (srcImage == nullptr) + { + throw GCN_EXCEPTION("Trying to draw an image of unknown format, must be an OpenGLImage."); + } - if (srcImage == NULL) - { - throw GCN_EXCEPTION("Trying to draw an image of unknown format, must be an OpenGLImage."); - } + if (mClipStack.empty()) + { + throw GCN_EXCEPTION("Clip stack is empty, perhaps you" + "called a draw funtion outside of _beginDraw() and _endDraw()?"); + } - if (mClipStack.empty()) { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you" - "called a draw funtion outside of _beginDraw() and _endDraw()?"); - } + const auto& top = mClipStack.top(); - const ClipRectangle& top = mClipStack.top(); + dstX += top.xOffset; + dstY += top.yOffset; - dstX += top.xOffset; - dstY += top.yOffset; + // Find OpenGL texture coordinates + const auto texX1 = srcX / static_cast(srcImage->getTextureWidth()); + const auto texY1 = srcY / static_cast(srcImage->getTextureHeight()); + const auto texX2 = (srcX + width) / static_cast(srcImage->getTextureWidth()); + const auto texY2 = (srcY + height) / static_cast(srcImage->getTextureHeight()); - // Find OpenGL texture coordinates - float texX1 = srcX / (float)srcImage->getTextureWidth(); - float texY1 = srcY / (float)srcImage->getTextureHeight(); - float texX2 = (srcX+width) / (float)srcImage->getTextureWidth(); - float texY2 = (srcY+height) / (float)srcImage->getTextureHeight(); + glBindTexture(GL_TEXTURE_2D, srcImage->getTextureHandle()); - glBindTexture(GL_TEXTURE_2D, srcImage->getTextureHandle()); + glEnable(GL_TEXTURE_2D); - glEnable(GL_TEXTURE_2D); + // Check if blending already is enabled + if (!mAlpha) + { + glEnable(GL_BLEND); + } - // Check if blending already is enabled - if (!mAlpha) - { - glEnable(GL_BLEND); - } + // Draw a textured quad -- the image + glBegin(GL_QUADS); + glTexCoord2f(texX1, texY1); + glVertex3i(dstX, dstY, 0); - // Draw a textured quad -- the image - glBegin(GL_QUADS); - glTexCoord2f(texX1, texY1); - glVertex3i(dstX, dstY, 0); + glTexCoord2f(texX1, texY2); + glVertex3i(dstX, dstY + height, 0); - glTexCoord2f(texX1, texY2); - glVertex3i(dstX, dstY + height, 0); + glTexCoord2f(texX2, texY2); + glVertex3i(dstX + width, dstY + height, 0); - glTexCoord2f(texX2, texY2); - glVertex3i(dstX + width, dstY + height, 0); + glTexCoord2f(texX2, texY1); + glVertex3i(dstX + width, dstY, 0); + glEnd(); + glDisable(GL_TEXTURE_2D); - glTexCoord2f(texX2, texY1); - glVertex3i(dstX + width, dstY, 0); - glEnd(); - glDisable(GL_TEXTURE_2D); + // Don't disable blending if the color has alpha + if (!mAlpha) + { + glDisable(GL_BLEND); + } + } - // Don't disable blending if the color has alpha - if (!mAlpha) - { - glDisable(GL_BLEND); - } - } + void OpenGLGraphics::drawPoint(int x, int y) + { + if (mClipStack.empty()) + { + throw GCN_EXCEPTION("Clip stack is empty, perhaps you" + "called a draw funtion outside of _beginDraw() and _endDraw()?"); + } + const auto& top = mClipStack.top(); - void OpenGLGraphics::drawPoint(int x, int y) - { - if (mClipStack.empty()) { - 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; - x += top.xOffset; - y += top.yOffset; + glBegin(GL_POINTS); + glVertex2i(x, y); + glEnd(); + } - glBegin(GL_POINTS); - glVertex2i(x, y); - glEnd(); - } + void OpenGLGraphics::drawLine(int x1, int y1, int x2, int y2) + { + if (mClipStack.empty()) + { + throw GCN_EXCEPTION("Clip stack is empty, perhaps you" + "called a draw funtion outside of _beginDraw() and _endDraw()?"); + } + const auto& top = mClipStack.top(); - void OpenGLGraphics::drawLine(int x1, int y1, int x2, int y2) - { - if (mClipStack.empty()) { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you" - "called a draw funtion outside of _beginDraw() and _endDraw()?"); - } - const ClipRectangle& top = mClipStack.top(); + x1 += top.xOffset; + y1 += top.yOffset; + x2 += top.xOffset; + y2 += top.yOffset; - x1 += top.xOffset; - y1 += top.yOffset; - x2 += top.xOffset; - y2 += top.yOffset; + glBegin(GL_LINES); + glVertex2f(x1 + 0.375f, y1 + 0.375f); + glVertex2f(x2 + 1.0f - 0.375f, y2 + 1.0f - 0.375f); + glEnd(); - glBegin(GL_LINES); - glVertex2f(x1 + 0.375f, y1 + 0.375f); - glVertex2f(x2 + 1.0f - 0.375f, y2 + 1.0f - 0.375f); - glEnd(); + glBegin(GL_POINTS); + glVertex2f(x2 + 1.0f - 0.375f, y2 + 1.0f - 0.375f); + glEnd(); - glBegin(GL_POINTS); - glVertex2f(x2 + 1.0f - 0.375f, y2 + 1.0f - 0.375f); - glEnd(); - - glBegin(GL_POINTS); - glVertex2f(x1 + 0.375f, y1 + 0.375f); - glEnd(); - } + glBegin(GL_POINTS); + glVertex2f(x1 + 0.375f, y1 + 0.375f); + glEnd(); + } - void OpenGLGraphics::drawRectangle(const Rectangle& rectangle) - { - if (mClipStack.empty()) { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you" - "called a draw funtion outside of _beginDraw() and _endDraw()?"); - } - const ClipRectangle& top = mClipStack.top(); + void OpenGLGraphics::drawRectangle(const Rectangle& rectangle) + { + if (mClipStack.empty()) + { + throw GCN_EXCEPTION("Clip stack is empty, perhaps you" + "called a draw funtion outside of _beginDraw() and _endDraw()?"); + } + const auto& top = mClipStack.top(); - glBegin(GL_LINE_LOOP); - glVertex2f(rectangle.x + top.xOffset, rectangle.y + top.yOffset); - glVertex2f(rectangle.x + rectangle.width + top.xOffset - 1.0f, - rectangle.y + top.yOffset + 0.375f); - glVertex2f(rectangle.x + rectangle.width + top.xOffset - 1.0f, - rectangle.y + rectangle.height + top.yOffset); - glVertex2f(rectangle.x + top.xOffset, - rectangle.y + rectangle.height + top.yOffset); - glEnd(); - } + glBegin(GL_LINE_LOOP); + glVertex2f(rectangle.x + top.xOffset, rectangle.y + top.yOffset); + glVertex2f(rectangle.x + rectangle.width + top.xOffset - 1.0f, + rectangle.y + top.yOffset + 0.375f); + glVertex2f(rectangle.x + rectangle.width + top.xOffset - 1.0f, + rectangle.y + rectangle.height + top.yOffset); + glVertex2f(rectangle.x + top.xOffset, + rectangle.y + rectangle.height + top.yOffset); + glEnd(); + } - void OpenGLGraphics::fillRectangle(const Rectangle& rectangle) - { - if (mClipStack.empty()) { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you" - "called a draw funtion outside of _beginDraw() and _endDraw()?"); - } - const ClipRectangle& top = mClipStack.top(); + void OpenGLGraphics::fillRectangle(const Rectangle& rectangle) + { + if (mClipStack.empty()) + { + throw GCN_EXCEPTION("Clip stack is empty, perhaps you" + "called a draw funtion outside of _beginDraw() and _endDraw()?"); + } + const auto& top = mClipStack.top(); - glBegin(GL_QUADS); - glVertex2i(rectangle.x + top.xOffset, rectangle.y + top.yOffset); - glVertex2i(rectangle.x + rectangle.width + top.xOffset, - rectangle.y + top.yOffset); - glVertex2i(rectangle.x + rectangle.width + top.xOffset, - rectangle.y + rectangle.height + top.yOffset); - glVertex2i(rectangle.x + top.xOffset, - rectangle.y + rectangle.height + top.yOffset); - glEnd(); - } + glBegin(GL_QUADS); + glVertex2i(rectangle.x + top.xOffset, rectangle.y + top.yOffset); + glVertex2i(rectangle.x + rectangle.width + top.xOffset, + rectangle.y + top.yOffset); + glVertex2i(rectangle.x + rectangle.width + top.xOffset, + rectangle.y + rectangle.height + top.yOffset); + glVertex2i(rectangle.x + top.xOffset, + rectangle.y + rectangle.height + top.yOffset); + glEnd(); + } - void OpenGLGraphics::setColor(const Color& color) - { - mColor = color; - glColor4ub(color.r, color.g, color.b, color.a); + void OpenGLGraphics::setColor(const Color& color) + { + mColor = color; + glColor4ub(color.r, color.g, color.b, color.a); - mAlpha = color.a != 255; + mAlpha = color.a != 255; - if (mAlpha) - { - glEnable(GL_BLEND); - } - } + if (mAlpha) + { + glEnable(GL_BLEND); + } + } - const Color& OpenGLGraphics::getColor() - { - return mColor; - } + const Color& OpenGLGraphics::getColor() + { + return mColor; + } } diff --git a/external/libguisan/src/opengl/openglimage.cpp b/external/libguisan/src/opengl/openglimage.cpp index d6a0d82d..fa635115 100644 --- a/external/libguisan/src/opengl/openglimage.cpp +++ b/external/libguisan/src/opengl/openglimage.cpp @@ -64,41 +64,40 @@ namespace gcn { - OpenGLImage::OpenGLImage(unsigned int* pixels, int width, int height, - bool convertToDisplayFormat) - { - mAutoFree = true; + OpenGLImage::OpenGLImage(unsigned int* pixels, int width, int height, + bool convertToDisplayFormat) + { + mAutoFree = true; - mWidth = width; - mHeight = height; + mWidth = width; + mHeight = height; mTextureWidth = 1, mTextureHeight = 1; - while(mTextureWidth < mWidth) - { - mTextureWidth *= 2; - } + while (mTextureWidth < mWidth) + { + mTextureWidth *= 2; + } - while(mTextureHeight < mHeight) - { - mTextureHeight *= 2; - } + while (mTextureHeight < mHeight) + { + mTextureHeight *= 2; + } // Create a new pixel array and copy the pixels into it mPixels = new unsigned int[mTextureWidth * mTextureHeight]; #ifdef __BIG_ENDIAN__ - const unsigned int magicPink = 0xff00ffff; + const auto int magicPink = 0xff00ffff; #else - const unsigned int magicPink = 0xffff00ff; + const auto magicPink = 0xffff00ff; #endif - int x, y; - for (y = 0; y < mTextureHeight; y++) + for (auto y = 0; y < mTextureHeight; y++) { - for (x = 0; x < mTextureWidth; x++) + for (auto x = 0; x < mTextureWidth; x++) { if (x < mWidth && y < mHeight) { - unsigned int c = pixels[x + y * mWidth]; + auto c = pixels[x + y * mWidth]; // Magic pink to transparent if (c == magicPink) @@ -115,82 +114,82 @@ namespace gcn } } - if (convertToDisplayFormat) - { - OpenGLImage::convertToDisplayFormat(); - } - } + if (convertToDisplayFormat) + { + OpenGLImage::convertToDisplayFormat(); + } + } - OpenGLImage::OpenGLImage(GLuint textureHandle, int width, int height, bool autoFree) - { - mTextureHandle = textureHandle; - mAutoFree = autoFree; - mPixels = NULL; + OpenGLImage::OpenGLImage(GLuint textureHandle, int width, int height, bool autoFree) + { + mTextureHandle = textureHandle; + mAutoFree = autoFree; + mPixels = nullptr; mWidth = width; - mHeight = height; + mHeight = height; mTextureWidth = 1, mTextureHeight = 1; - while(mTextureWidth < mWidth) - { - mTextureWidth *= 2; - } + while (mTextureWidth < mWidth) + { + mTextureWidth *= 2; + } - while(mTextureHeight < mHeight) - { - mTextureHeight *= 2; - } - } + while (mTextureHeight < mHeight) + { + mTextureHeight *= 2; + } + } - OpenGLImage::~OpenGLImage() - { - if (mAutoFree) - { - free(); - } - } + OpenGLImage::~OpenGLImage() + { + if (mAutoFree) + { + OpenGLImage::free(); + } + } - GLuint OpenGLImage::getTextureHandle() const - { - return mTextureHandle; - } + GLuint OpenGLImage::getTextureHandle() const + { + return mTextureHandle; + } - int OpenGLImage::getTextureWidth() const - { + int OpenGLImage::getTextureWidth() const + { return mTextureWidth; - } + } - int OpenGLImage::getTextureHeight() const - { + int OpenGLImage::getTextureHeight() const + { return mTextureHeight; - } + } - void OpenGLImage::free() - { - if (mPixels == NULL) + void OpenGLImage::free() + { + if (mPixels == nullptr) { glDeleteTextures(1, &mTextureHandle); } else { delete[] mPixels; - mPixels = NULL; + mPixels = nullptr; } - } + } - int OpenGLImage::getWidth() const - { - return mWidth; - } + int OpenGLImage::getWidth() const + { + return mWidth; + } - int OpenGLImage::getHeight() const - { - return mHeight; - } + int OpenGLImage::getHeight() const + { + return mHeight; + } - Color OpenGLImage::getPixel(int x, int y) - { - if (mPixels == NULL) + Color OpenGLImage::getPixel(int x, int y) + { + if (mPixels == nullptr) { throw GCN_EXCEPTION("Image has been converted to display format"); } @@ -200,26 +199,26 @@ namespace gcn throw GCN_EXCEPTION("Coordinates outside of the image"); } - unsigned int c = mPixels[x + y * mTextureWidth]; + const auto c = mPixels[x + y * mTextureWidth]; #ifdef __BIG_ENDIAN__ - unsigned char r = (c >> 24) & 0xff; - unsigned char g = (c >> 16) & 0xff; - unsigned char b = (c >> 8) & 0xff; - unsigned char a = c & 0xff; + const unsigned char r = c >> 24 & 0xff; + const unsigned char g = c >> 16 & 0xff; + const unsigned char b = c >> 8 & 0xff; + const unsigned char a = c & 0xff; #else - unsigned char a = (c >> 24) & 0xff; - unsigned char b = (c >> 16) & 0xff; - unsigned char g = (c >> 8) & 0xff; - unsigned char r = c & 0xff; + const unsigned char a = c >> 24 & 0xff; + const unsigned char b = c >> 16 & 0xff; + const unsigned char g = c >> 8 & 0xff; + const unsigned char r = c & 0xff; #endif - return Color(r, g, b, a); - } + return Color(r, g, b, a); + } - void OpenGLImage::putPixel(int x, int y, const Color& color) - { - if (mPixels == NULL) + void OpenGLImage::putPixel(int x, int y, const Color& color) + { + if (mPixels == nullptr) { throw GCN_EXCEPTION("Image has been converted to display format"); } @@ -230,72 +229,74 @@ namespace gcn } #ifdef __BIG_ENDIAN__ - unsigned int c = color.a | color.b << 8 | color.g << 16 | color.r << 24; + const unsigned int c = color.a | color.b << 8 | color.g << 16 | color.r << 24; #else - unsigned int c = color.r | color.g << 8 | color.b << 16 | color.a << 24; + const unsigned int c = color.r | color.g << 8 | color.b << 16 | color.a << 24; #endif mPixels[x + y * mTextureWidth] = c; - } + } - void OpenGLImage::convertToDisplayFormat() - { - if (mPixels == NULL) + void OpenGLImage::convertToDisplayFormat() + { + if (mPixels == nullptr) { throw GCN_EXCEPTION("Image has already been converted to display format"); } - glGenTextures(1, &mTextureHandle); - glBindTexture(GL_TEXTURE_2D, mTextureHandle); + glGenTextures(1, &mTextureHandle); + glBindTexture(GL_TEXTURE_2D, mTextureHandle); - glTexImage2D(GL_TEXTURE_2D, - 0, - 4, - mTextureWidth, - mTextureHeight, - 0, - GL_RGBA, - GL_UNSIGNED_BYTE, - mPixels); + glTexImage2D(GL_TEXTURE_2D, + 0, + 4, + mTextureWidth, + mTextureHeight, + 0, + GL_RGBA, + GL_UNSIGNED_BYTE, + mPixels); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - delete[] mPixels; - mPixels = NULL; + delete[] mPixels; + mPixels = nullptr; - GLenum error = glGetError(); - if (error) - { - std::string errmsg; - switch (error) - { - case GL_INVALID_ENUM: - errmsg = "GL_INVALID_ENUM"; - break; + const auto error = glGetError(); + if (error) + { + std::string errmsg; + switch (error) + { + case GL_INVALID_ENUM: + errmsg = "GL_INVALID_ENUM"; + break; - case GL_INVALID_VALUE: - errmsg = "GL_INVALID_VALUE"; - break; + case GL_INVALID_VALUE: + errmsg = "GL_INVALID_VALUE"; + break; - case GL_INVALID_OPERATION: - errmsg = "GL_INVALID_OPERATION"; - break; + case GL_INVALID_OPERATION: + errmsg = "GL_INVALID_OPERATION"; + break; - case GL_STACK_OVERFLOW: - errmsg = "GL_STACK_OVERFLOW"; - break; + case GL_STACK_OVERFLOW: + errmsg = "GL_STACK_OVERFLOW"; + break; - case GL_STACK_UNDERFLOW: - errmsg = "GL_STACK_UNDERFLOW"; - break; + case GL_STACK_UNDERFLOW: + errmsg = "GL_STACK_UNDERFLOW"; + break; - case GL_OUT_OF_MEMORY: - errmsg = "GL_OUT_OF_MEMORY"; - break; - } + case GL_OUT_OF_MEMORY: + errmsg = "GL_OUT_OF_MEMORY"; + break; + default: + break; + } - throw GCN_EXCEPTION(std::string("Unable to convert to OpenGL display format, glGetError said: ") + errmsg); - } - } + throw GCN_EXCEPTION(std::string("Unable to convert to OpenGL display format, glGetError said: ") + errmsg); + } + } } diff --git a/external/libguisan/src/rectangle.cpp b/external/libguisan/src/rectangle.cpp index ce4b220c..5208046e 100644 --- a/external/libguisan/src/rectangle.cpp +++ b/external/libguisan/src/rectangle.cpp @@ -62,75 +62,75 @@ namespace gcn { - Rectangle::Rectangle() - { - x = 0; - y = 0; - width = 0; - height = 0; - } + Rectangle::Rectangle() + { + x = 0; + y = 0; + width = 0; + height = 0; + } - Rectangle::Rectangle(int x, int y, int width, int height) - { - this->x = x; - this->y = y; - this->width = width; - this->height = height; - } + Rectangle::Rectangle(int x, int y, int width, int height) + { + this->x = x; + this->y = y; + this->width = width; + this->height = height; + } - void Rectangle::setAll(int x, int y, int width, int height) - { - this->x = x; - this->y = y; - this->width = width; - this->height = height; - } + void Rectangle::setAll(int x, int y, int width, int height) + { + this->x = x; + this->y = y; + this->width = width; + this->height = height; + } - bool Rectangle::intersect(const Rectangle& rectangle) - { - x -= rectangle.x; - y -= rectangle.y; + bool Rectangle::intersect(const Rectangle& rectangle) + { + x -= rectangle.x; + y -= rectangle.y; - if (x < 0) - { - width += x; - x = 0; - } + if (x < 0) + { + width += x; + x = 0; + } - if (y < 0) - { - height += y; - y = 0; - } + if (y < 0) + { + height += y; + y = 0; + } - if (x + width > rectangle.width) - { - width = rectangle.width - x; - } + if (x + width > rectangle.width) + { + width = rectangle.width - x; + } - if (y + height > rectangle.height) - { - height = rectangle.height - y; - } + if (y + height > rectangle.height) + { + height = rectangle.height - y; + } - if (width <= 0 || height <= 0) - { - height = 0; - width = 0; - x += rectangle.x; - y += rectangle.y; - return false; - } + if (width <= 0 || height <= 0) + { + height = 0; + width = 0; + x += rectangle.x; + y += rectangle.y; + return false; + } - x += rectangle.x; - y += rectangle.y; - return true; - } + x += rectangle.x; + y += rectangle.y; + return true; + } - bool Rectangle::isPointInRect(int x, int y) const - { - return ((x >= this->x) && (y >= this->y) - && x < (this->x + this->width) - && y < (this->y + this->height)); - } + bool Rectangle::isPointInRect(int x, int y) const + { + return x >= this->x && y >= this->y + && x < this->x + this->width + && y < this->y + this->height; + } } diff --git a/external/libguisan/src/sdl/sdl.cpp b/external/libguisan/src/sdl/sdl.cpp index 28164a75..57af79c1 100644 --- a/external/libguisan/src/sdl/sdl.cpp +++ b/external/libguisan/src/sdl/sdl.cpp @@ -60,7 +60,8 @@ #include "guisan/sdl.hpp" -extern "C" +extern "C" { +void gcnSDL() { - void gcnSDL() { } +} } diff --git a/external/libguisan/src/sdl/sdl2graphics.cpp b/external/libguisan/src/sdl/sdl2graphics.cpp index d7df26c1..8a47c119 100644 --- a/external/libguisan/src/sdl/sdl2graphics.cpp +++ b/external/libguisan/src/sdl/sdl2graphics.cpp @@ -74,406 +74,409 @@ namespace gcn { + SDL2Graphics::SDL2Graphics() + { + mAlpha = false; + } - SDL2Graphics::SDL2Graphics() - { - mAlpha = false; - } - - SDL2Graphics::~SDL2Graphics() - { - if(mRenderTarget != NULL) - { - SDL_DestroyTexture(mTexture); - SDL_FreeSurface(mTarget); - } - } + SDL2Graphics::~SDL2Graphics() + { + if (mRenderTarget != nullptr) + { + SDL_DestroyTexture(mTexture); + SDL_FreeSurface(mTarget); + } + } - void SDL2Graphics::_beginDraw() - { - Rectangle area; - area.x = 0; - area.y = 0; - area.width = mTarget->w; - area.height = mTarget->h; - pushClipArea(area); - } + void SDL2Graphics::_beginDraw() + { + Rectangle area; + area.x = 0; + area.y = 0; + area.width = mTarget->w; + area.height = mTarget->h; + pushClipArea(area); + } - void SDL2Graphics::_endDraw() - { - popClipArea(); - } - - void SDL2Graphics::setTarget(SDL_Renderer* renderer, int width, int height) - { - mRenderTarget = renderer; - // An internal surface is still required to be able to handle surfaces and colorkeys - mTarget = SDL_CreateRGBSurface(0, width, height, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); - SDL_FillRect(mTarget, NULL, SDL_MapRGB(mTarget->format, 0xff, 0, 0xff)); - SDL_SetColorKey(mTarget, SDL_TRUE, SDL_MapRGB(mTarget->format, 0xff, 0, 0xff)); // magenta, Guisan default - SDL_SetSurfaceBlendMode(mTarget, SDL_BLENDMODE_NONE); // needed to cleanup temp data properly - mTexture = SDL_CreateTextureFromSurface(mRenderTarget, mTarget); - SDL_SetTextureBlendMode(mTexture, SDL_BLENDMODE_BLEND); - } + void SDL2Graphics::_endDraw() + { + popClipArea(); + } - bool SDL2Graphics::pushClipArea(Rectangle area) - { - SDL_Rect rect; - bool result = Graphics::pushClipArea(area); + void SDL2Graphics::setTarget(SDL_Renderer* renderer, int width, int height) + { + mRenderTarget = renderer; + // An internal surface is still required to be able to handle surfaces and colorkeys + mTarget = SDL_CreateRGBSurface(0, width, height, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); + SDL_FillRect(mTarget, nullptr, SDL_MapRGB(mTarget->format, 0xff, 0, 0xff)); + SDL_SetColorKey(mTarget, SDL_TRUE, SDL_MapRGB(mTarget->format, 0xff, 0, 0xff)); // magenta, Guisan default + SDL_SetSurfaceBlendMode(mTarget, SDL_BLENDMODE_NONE); // needed to cleanup temp data properly + mTexture = SDL_CreateTextureFromSurface(mRenderTarget, mTarget); + SDL_SetTextureBlendMode(mTexture, SDL_BLENDMODE_BLEND); + } - const ClipRectangle& carea = mClipStack.top(); - rect.x = carea.x; - rect.y = carea.y; - rect.w = carea.width; - rect.h = carea.height; + bool SDL2Graphics::pushClipArea(Rectangle area) + { + SDL_Rect rect; + const auto result = Graphics::pushClipArea(area); - SDL_RenderSetClipRect(mRenderTarget, &rect); + const auto& carea = mClipStack.top(); + rect.x = carea.x; + rect.y = carea.y; + rect.w = carea.width; + rect.h = carea.height; - return result; - } + SDL_RenderSetClipRect(mRenderTarget, &rect); - void SDL2Graphics::popClipArea() - { - Graphics::popClipArea(); + return result; + } - if (mClipStack.empty()) - { - return; - } + void SDL2Graphics::popClipArea() + { + Graphics::popClipArea(); - const ClipRectangle& carea = mClipStack.top(); - SDL_Rect rect; - rect.x = carea.x; - rect.y = carea.y; - rect.w = carea.width; - rect.h = carea.height; + if (mClipStack.empty()) + { + return; + } - SDL_RenderSetClipRect(mRenderTarget, &rect); - } - - SDL_Renderer* SDL2Graphics::getTarget() const - { - return mRenderTarget; - } + const auto& carea = mClipStack.top(); + SDL_Rect rect; + rect.x = carea.x; + rect.y = carea.y; + rect.w = carea.width; + rect.h = carea.height; - void SDL2Graphics::drawImage(const Image* image, int srcX, - int srcY, int dstX, int dstY, - int width, int height) - { - if (mClipStack.empty()) { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you" - "called a draw function outside of _beginDraw() and _endDraw()?"); - } - - const ClipRectangle& top = mClipStack.top(); - SDL_Rect src; - SDL_Rect dst; - SDL_Rect temp; - src.x = srcX; - src.y = srcY; - src.w = width; - src.h = height; - dst.x = dstX + top.xOffset; - dst.y = dstY + top.yOffset; - dst.w = width; - dst.h = height; - temp.x = 0; - temp.y = 0; - temp.w = width; - temp.h = height; + SDL_RenderSetClipRect(mRenderTarget, &rect); + } - const SDLImage* srcImage = dynamic_cast(image); + SDL_Renderer* SDL2Graphics::getTarget() const + { + return mRenderTarget; + } - if (srcImage == NULL) - { - throw GCN_EXCEPTION("Trying to draw an image of unknown format, must be an SDLImage."); - } - - if(srcImage->getTexture() == NULL) - { - SDL_FillRect(mTarget, &temp, SDL_MapRGBA(mTarget->format, 0xff, 0, 0xff, 0)); - SDL_BlitSurface(srcImage->getSurface(), &src, mTarget, &temp); - SDL_UpdateTexture(mTexture, &temp, mTarget->pixels, mTarget->pitch); - SDL_RenderCopy(mRenderTarget, mTexture, &temp, &dst); - } - else - { - SDL_RenderCopy(mRenderTarget, srcImage->getTexture(), &src, &dst); - } - - } + void SDL2Graphics::drawImage(const Image* image, int srcX, + int srcY, int dstX, int dstY, + int width, int height) + { + if (mClipStack.empty()) + { + throw GCN_EXCEPTION("Clip stack is empty, perhaps you" + "called a draw function outside of _beginDraw() and _endDraw()?"); + } - void SDL2Graphics::fillRectangle(const Rectangle& rectangle) - { - if (mClipStack.empty()) { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you" - "called a draw function outside of _beginDraw() and _endDraw()?"); - } + const auto& top = mClipStack.top(); + SDL_Rect src; + SDL_Rect dst; + SDL_Rect temp; + src.x = srcX; + src.y = srcY; + src.w = width; + src.h = height; + dst.x = dstX + top.xOffset; + dst.y = dstY + top.yOffset; + dst.w = width; + dst.h = height; + temp.x = 0; + temp.y = 0; + temp.w = width; + temp.h = height; - const ClipRectangle& top = mClipStack.top(); + const auto* const srcImage = dynamic_cast(image); - Rectangle area = rectangle; - area.x += top.xOffset; - area.y += top.yOffset; + if (srcImage == nullptr) + { + throw GCN_EXCEPTION("Trying to draw an image of unknown format, must be an SDLImage."); + } - if(!area.intersect(top)) - { - return; - } + if (srcImage->getTexture() == nullptr) + { + SDL_FillRect(mTarget, &temp, SDL_MapRGBA(mTarget->format, 0xff, 0, 0xff, 0)); + SDL_BlitSurface(srcImage->getSurface(), &src, mTarget, &temp); + SDL_UpdateTexture(mTexture, &temp, mTarget->pixels, mTarget->pitch); + SDL_RenderCopy(mRenderTarget, mTexture, &temp, &dst); + } + else + { + SDL_RenderCopy(mRenderTarget, srcImage->getTexture(), &src, &dst); + } + } - 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; - SDL_Rect rect; - rect.x = x1; - rect.y = y1; - rect.w = x2 - x1; - rect.h = y2 - y1; - - saveRenderColor(); - SDL_SetRenderDrawColor(mRenderTarget, mColor.r, mColor.g, mColor.b, mColor.a); - SDL_RenderFillRect(mRenderTarget, &rect); - restoreRenderColor(); + void SDL2Graphics::fillRectangle(const Rectangle& rectangle) + { + if (mClipStack.empty()) + { + throw GCN_EXCEPTION("Clip stack is empty, perhaps you" + "called a draw function outside of _beginDraw() and _endDraw()?"); + } - } - else - { - SDL_Rect rect; - rect.x = area.x; - rect.y = area.y; - rect.w = area.width; - rect.h = area.height; + const auto& top = mClipStack.top(); - Uint32 color = SDL_MapRGBA(mTarget->format, mColor.r, mColor.g, mColor.b, mColor.a); - saveRenderColor(); - SDL_SetRenderDrawColor(mRenderTarget, mColor.r, mColor.g, mColor.b, mColor.a); - SDL_RenderFillRect(mRenderTarget, &rect); - restoreRenderColor(); - - } - } + auto area = rectangle; + area.x += top.xOffset; + area.y += top.yOffset; - void SDL2Graphics::drawPoint(int x, int y) - { - if (mClipStack.empty()) { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you" - "called a draw function outside of _beginDraw() and _endDraw()?"); - } + if (!area.intersect(top)) + { + return; + } - const ClipRectangle& top = mClipStack.top(); + if (mAlpha) + { + const auto x1 = area.x > top.x ? area.x : top.x; + const auto y1 = area.y > top.y ? area.y : top.y; + const auto x2 = area.x + area.width < top.x + top.width ? area.x + area.width : top.x + top.width; + const auto 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; + rect.w = x2 - x1; + rect.h = y2 - y1; - x += top.xOffset; - y += top.yOffset; + saveRenderColor(); + SDL_SetRenderDrawColor(mRenderTarget, mColor.r, mColor.g, mColor.b, mColor.a); + SDL_RenderFillRect(mRenderTarget, &rect); + restoreRenderColor(); + } + else + { + SDL_Rect rect; + rect.x = area.x; + rect.y = area.y; + rect.w = area.width; + rect.h = area.height; - if(!top.isPointInRect(x,y)) - return; + auto color = SDL_MapRGBA(mTarget->format, mColor.r, mColor.g, mColor.b, mColor.a); + saveRenderColor(); + SDL_SetRenderDrawColor(mRenderTarget, mColor.r, mColor.g, mColor.b, mColor.a); + SDL_RenderFillRect(mRenderTarget, &rect); + restoreRenderColor(); + } + } - saveRenderColor(); - SDL_SetRenderDrawColor(mRenderTarget, mColor.r, mColor.g, mColor.b, mColor.a); - /*if (mAlpha) - { - SDLputPixelAlpha(mTarget, x, y, mColor); - - } - else - { - SDLputPixel(mTarget, x, y, mColor); - }*/ - SDL_RenderDrawPoint(mRenderTarget, x, y); - restoreRenderColor(); - } + void SDL2Graphics::drawPoint(int x, int y) + { + if (mClipStack.empty()) + { + throw GCN_EXCEPTION("Clip stack is empty, perhaps you" + "called a draw function outside of _beginDraw() and _endDraw()?"); + } - void SDL2Graphics::drawHLine(int x1, int y, int x2) - { - if (mClipStack.empty()) { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you" - "called a draw function outside of _beginDraw() and _endDraw()?"); - } - const ClipRectangle& top = mClipStack.top(); + const auto& top = mClipStack.top(); - x1 += top.xOffset; - y += top.yOffset; - x2 += top.xOffset; + x += top.xOffset; + y += top.yOffset; - if (y < top.y || y >= top.y + top.height) - return; + if (!top.isPointInRect(x, y)) + return; - if (x1 > x2) - { - x1 ^= x2; - x2 ^= x1; - x1 ^= x2; - } + saveRenderColor(); + SDL_SetRenderDrawColor(mRenderTarget, mColor.r, mColor.g, mColor.b, mColor.a); + /*if (mAlpha) +{ +SDLputPixelAlpha(mTarget, x, y, mColor); - if (top.x > x1) - { - if (top.x > x2) - { - return; - } - x1 = top.x; - } - - if (top.x + top.width <= x2) - { - if (top.x + top.width <= x1) - { - return; - } - x2 = top.x + top.width -1; - } - - saveRenderColor(); - SDL_SetRenderDrawColor(mRenderTarget, mColor.r, mColor.g, mColor.b, mColor.a); - SDL_RenderDrawLine(mRenderTarget, x1, y, x2, y); - restoreRenderColor(); - } - - void SDL2Graphics::drawVLine(int x, int y1, int y2) - { - if (mClipStack.empty()) { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you" - "called a draw function outside of _beginDraw() and _endDraw()?"); - } - const ClipRectangle& top = mClipStack.top(); - - x += top.xOffset; - y1 += top.yOffset; - y2 += top.yOffset; - - if (x < top.x || x >= top.x + top.width) - return; - - if (y1 > y2) - { - y1 ^= y2; - y2 ^= y1; - y1 ^= y2; - } - - if (top.y > y1) - { - if (top.y > y2) - { - return; - } - y1 = top.y; - } - - if (top.y + top.height <= y2) - { - if (top.y + top.height <= y1) - { - return; - } - y2 = top.y + top.height - 1; - } - - saveRenderColor(); - SDL_SetRenderDrawColor(mRenderTarget, mColor.r, mColor.g, mColor.b, mColor.a); - SDL_RenderDrawLine(mRenderTarget, x, y1, x, y2); - restoreRenderColor(); - } - - 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; - - drawHLine(x1, y1, x2); - drawHLine(x1, y2, x2); - - drawVLine(x1, y1, y2); - drawVLine(x2, y1, y2); - } - - void SDL2Graphics::drawLine(int x1, int y1, int x2, int y2) - { - - if (mClipStack.empty()) { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you" - "called a draw function outside of _beginDraw() and _endDraw()?"); - } - const ClipRectangle& top = mClipStack.top(); - - x1 += top.xOffset; - y1 += top.yOffset; - x2 += top.xOffset; - y2 += top.yOffset; - - saveRenderColor(); - SDL_SetRenderDrawColor(mRenderTarget, mColor.r, mColor.g, mColor.b, mColor.a); - SDL_RenderDrawLine(mRenderTarget, x1, y1, x2, y2); - restoreRenderColor(); - } - - void SDL2Graphics::setColor(const Color& color) - { - mColor = color; - - mAlpha = color.a != 255; - } - - const Color& SDL2Graphics::getColor() - { - return mColor; - } - - void SDL2Graphics::drawSDLSurface(SDL_Surface* surface, SDL_Rect source, - SDL_Rect destination) - { - if (mClipStack.empty()) { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you" - "called a draw function outside of _beginDraw() and _endDraw()?"); - } - const ClipRectangle& top = mClipStack.top(); - - destination.x += top.xOffset; - destination.y += top.yOffset; - destination.w = source.w; - destination.h = source.h; - SDL_Rect temp; - temp.x = 0; - temp.y = 0; - temp.w = source.w; - temp.h = source.h; - - SDL_FillRect(mTarget, &temp, SDL_MapRGBA(mTarget->format, 0xff, 0, 0xff, 0)); - SDL_BlitSurface(surface, &source, mTarget, &temp); - SDL_UpdateTexture(mTexture, &temp, mTarget->pixels, mTarget->pitch); - SDL_RenderCopy(mRenderTarget, mTexture, &temp, &destination); - } - - void SDL2Graphics::drawSDLTexture(SDL_Texture * texture, SDL_Rect source, - SDL_Rect destination) - { - if (mClipStack.empty()) { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you" - "called a draw function outside of _beginDraw() and _endDraw()?"); - } - const ClipRectangle& top = mClipStack.top(); - - destination.x += top.xOffset; - destination.y += top.yOffset; - destination.w = source.w; - destination.h = source.h; - - SDL_RenderCopy(mRenderTarget, texture, &source, &destination); - } - - void SDL2Graphics::saveRenderColor() - { - SDL_GetRenderDrawColor(mRenderTarget, &r, &g, &b, &a); - } - - void SDL2Graphics::restoreRenderColor() - { - SDL_SetRenderDrawColor(mRenderTarget, r, g, b, a); - } +} +else +{ +SDLputPixel(mTarget, x, y, mColor); +}*/ + SDL_RenderDrawPoint(mRenderTarget, x, y); + restoreRenderColor(); + } + + void SDL2Graphics::drawHLine(int x1, int y, int x2) + { + if (mClipStack.empty()) + { + throw GCN_EXCEPTION("Clip stack is empty, perhaps you" + "called a draw function outside of _beginDraw() and _endDraw()?"); + } + const auto& top = mClipStack.top(); + + x1 += top.xOffset; + y += top.yOffset; + x2 += top.xOffset; + + if (y < top.y || y >= top.y + top.height) + return; + + if (x1 > x2) + { + x1 ^= x2; + x2 ^= x1; + x1 ^= x2; + } + + if (top.x > x1) + { + if (top.x > x2) + { + return; + } + x1 = top.x; + } + + if (top.x + top.width <= x2) + { + if (top.x + top.width <= x1) + { + return; + } + x2 = top.x + top.width - 1; + } + + saveRenderColor(); + SDL_SetRenderDrawColor(mRenderTarget, mColor.r, mColor.g, mColor.b, mColor.a); + SDL_RenderDrawLine(mRenderTarget, x1, y, x2, y); + restoreRenderColor(); + } + + void SDL2Graphics::drawVLine(int x, int y1, int y2) + { + if (mClipStack.empty()) + { + throw GCN_EXCEPTION("Clip stack is empty, perhaps you" + "called a draw function outside of _beginDraw() and _endDraw()?"); + } + const auto& top = mClipStack.top(); + + x += top.xOffset; + y1 += top.yOffset; + y2 += top.yOffset; + + if (x < top.x || x >= top.x + top.width) + return; + + if (y1 > y2) + { + y1 ^= y2; + y2 ^= y1; + y1 ^= y2; + } + + if (top.y > y1) + { + if (top.y > y2) + { + return; + } + y1 = top.y; + } + + if (top.y + top.height <= y2) + { + if (top.y + top.height <= y1) + { + return; + } + y2 = top.y + top.height - 1; + } + + saveRenderColor(); + SDL_SetRenderDrawColor(mRenderTarget, mColor.r, mColor.g, mColor.b, mColor.a); + SDL_RenderDrawLine(mRenderTarget, x, y1, x, y2); + restoreRenderColor(); + } + + void SDL2Graphics::drawRectangle(const Rectangle& rectangle) + { + const auto x1 = rectangle.x; + const auto x2 = rectangle.x + rectangle.width - 1; + const auto y1 = rectangle.y; + const auto y2 = rectangle.y + rectangle.height - 1; + + drawHLine(x1, y1, x2); + drawHLine(x1, y2, x2); + + drawVLine(x1, y1, y2); + drawVLine(x2, y1, y2); + } + + void SDL2Graphics::drawLine(int x1, int y1, int x2, int y2) + { + if (mClipStack.empty()) + { + throw GCN_EXCEPTION("Clip stack is empty, perhaps you" + "called a draw function outside of _beginDraw() and _endDraw()?"); + } + const auto& top = mClipStack.top(); + + x1 += top.xOffset; + y1 += top.yOffset; + x2 += top.xOffset; + y2 += top.yOffset; + + saveRenderColor(); + SDL_SetRenderDrawColor(mRenderTarget, mColor.r, mColor.g, mColor.b, mColor.a); + SDL_RenderDrawLine(mRenderTarget, x1, y1, x2, y2); + restoreRenderColor(); + } + + void SDL2Graphics::setColor(const Color& color) + { + mColor = color; + + mAlpha = color.a != 255; + } + + const Color& SDL2Graphics::getColor() + { + return mColor; + } + + void SDL2Graphics::drawSDLSurface(SDL_Surface* surface, SDL_Rect source, + SDL_Rect destination) + { + if (mClipStack.empty()) + { + throw GCN_EXCEPTION("Clip stack is empty, perhaps you" + "called a draw function outside of _beginDraw() and _endDraw()?"); + } + const auto& top = mClipStack.top(); + + destination.x += top.xOffset; + destination.y += top.yOffset; + destination.w = source.w; + destination.h = source.h; + SDL_Rect temp; + temp.x = 0; + temp.y = 0; + temp.w = source.w; + temp.h = source.h; + + SDL_FillRect(mTarget, &temp, SDL_MapRGBA(mTarget->format, 0xff, 0, 0xff, 0)); + SDL_BlitSurface(surface, &source, mTarget, &temp); + SDL_UpdateTexture(mTexture, &temp, mTarget->pixels, mTarget->pitch); + SDL_RenderCopy(mRenderTarget, mTexture, &temp, &destination); + } + + void SDL2Graphics::drawSDLTexture(SDL_Texture* texture, SDL_Rect source, + SDL_Rect destination) + { + if (mClipStack.empty()) + { + throw GCN_EXCEPTION("Clip stack is empty, perhaps you" + "called a draw function outside of _beginDraw() and _endDraw()?"); + } + const auto& top = mClipStack.top(); + + destination.x += top.xOffset; + destination.y += top.yOffset; + destination.w = source.w; + destination.h = source.h; + + SDL_RenderCopy(mRenderTarget, texture, &source, &destination); + } + + void SDL2Graphics::saveRenderColor() + { + SDL_GetRenderDrawColor(mRenderTarget, &r, &g, &b, &a); + } + + void SDL2Graphics::restoreRenderColor() + { + SDL_SetRenderDrawColor(mRenderTarget, r, g, b, a); + } } diff --git a/external/libguisan/src/sdl/sdlgraphics.cpp b/external/libguisan/src/sdl/sdlgraphics.cpp index 07e396bf..64fec05e 100644 --- a/external/libguisan/src/sdl/sdlgraphics.cpp +++ b/external/libguisan/src/sdl/sdlgraphics.cpp @@ -74,615 +74,628 @@ namespace gcn { - - SDLGraphics::SDLGraphics() - { - mAlpha = false; - } - - SDLGraphics::~SDLGraphics() + SDLGraphics::SDLGraphics() { - + mAlpha = false; } - void SDLGraphics::_beginDraw() - { - Rectangle area; - area.x = 0; - area.y = 0; - area.width = mTarget->w; - area.height = mTarget->h; - pushClipArea(area); - } + SDLGraphics::~SDLGraphics() + = default; - void SDLGraphics::_endDraw() - { - popClipArea(); - } - - void SDLGraphics::setTarget(SDL_Surface* target) - { - mTarget = target; - } - - bool SDLGraphics::pushClipArea(Rectangle area) - { - SDL_Rect rect; - bool result = Graphics::pushClipArea(area); - - const ClipRectangle& carea = mClipStack.top(); - rect.x = carea.x; - rect.y = carea.y; - rect.w = carea.width; - rect.h = carea.height; - - SDL_SetClipRect(mTarget, &rect); - - return result; - } - - void SDLGraphics::popClipArea() - { - Graphics::popClipArea(); - - if (mClipStack.empty()) - { - return; - } - - const ClipRectangle& carea = mClipStack.top(); - SDL_Rect rect; - rect.x = carea.x; - rect.y = carea.y; - rect.w = carea.width; - rect.h = carea.height; - - SDL_SetClipRect(mTarget, &rect); - } - - SDL_Surface* SDLGraphics::getTarget() const - { - return mTarget; - } - - void SDLGraphics::drawImage(const Image* image, int srcX, - int srcY, int dstX, int dstY, - int width, int height) - { - if (mClipStack.empty()) { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you" - "called a draw function outside of _beginDraw() and _endDraw()?"); + void SDLGraphics::_beginDraw() + { + Rectangle area; + area.x = 0; + area.y = 0; + area.width = mTarget->w; + area.height = mTarget->h; + pushClipArea(area); } - const ClipRectangle& top = mClipStack.top(); - SDL_Rect src; - SDL_Rect dst; - src.x = srcX; - src.y = srcY; - src.w = width; - src.h = height; - dst.x = dstX + top.xOffset; - dst.y = dstY + top.yOffset; - - const SDLImage* srcImage = dynamic_cast(image); - - if (srcImage == NULL) - { - throw GCN_EXCEPTION("Trying to draw an image of unknown format, must be an SDLImage."); - } - - SDL_BlitSurface(srcImage->getSurface(), &src, mTarget, &dst); - } - - void SDLGraphics::fillRectangle(const Rectangle& rectangle) - { - if (mClipStack.empty()) { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you" - "called a draw function outside of _beginDraw() and _endDraw()?"); + void SDLGraphics::_endDraw() + { + popClipArea(); } - const ClipRectangle& top = mClipStack.top(); - - Rectangle area = rectangle; - area.x += top.xOffset; - area.y += top.yOffset; - - if(!area.intersect(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 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 - { - SDL_Rect rect; - rect.x = area.x; - rect.y = area.y; - rect.w = area.width; - rect.h = area.height; - - Uint32 color = SDL_MapRGBA(mTarget->format, mColor.r, mColor.g, mColor.b, mColor.a); - SDL_FillRect(mTarget, &rect, color); - } - } - - void SDLGraphics::drawPoint(int x, int y) - { - if (mClipStack.empty()) { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you" - "called a draw function outside of _beginDraw() and _endDraw()?"); + void SDLGraphics::setTarget(SDL_Surface* target) + { + mTarget = target; } - const ClipRectangle& top = mClipStack.top(); + bool SDLGraphics::pushClipArea(Rectangle area) + { + SDL_Rect rect; + const auto result = Graphics::pushClipArea(area); - x += top.xOffset; - y += top.yOffset; + const auto& carea = mClipStack.top(); + rect.x = carea.x; + rect.y = carea.y; + rect.w = carea.width; + rect.h = carea.height; - if(!top.isPointInRect(x,y)) - return; + SDL_SetClipRect(mTarget, &rect); - 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 function outside of _beginDraw() and _endDraw()?"); + return result; } - const ClipRectangle& top = mClipStack.top(); - x1 += top.xOffset; - y += top.yOffset; - x2 += top.xOffset; + void SDLGraphics::popClipArea() + { + Graphics::popClipArea(); - if (y < top.y || y >= top.y + top.height) - return; + if (mClipStack.empty()) + { + return; + } - if (x1 > x2) - { - x1 ^= x2; - x2 ^= x1; - x1 ^= x2; - } + const auto& carea = mClipStack.top(); + SDL_Rect rect; + rect.x = carea.x; + rect.y = carea.y; + rect.w = carea.width; + rect.h = carea.height; - if (top.x > x1) - { - if (top.x > x2) - { - return; - } - x1 = top.x; - } - - if (top.x + top.width <= x2) - { - if (top.x + top.width <= x1) - { - return; - } - x2 = top.x + top.width -1; - } - - int bpp = mTarget->format->BytesPerPixel; - - SDL_LockSurface(mTarget); - - Uint8 *p = (Uint8 *)mTarget->pixels + y * mTarget->pitch + x1 * bpp; - - Uint32 pixel = SDL_MapRGB(mTarget->format, mColor.r, mColor.g, mColor.b); - - switch(bpp) { - case 1: - { - for (;x1 <= x2; ++x1) - { - *(p++) = pixel; - } - } break; - - case 2: - { - Uint16* q = (Uint16*)p; - for (;x1 <= x2; ++x1) - { - *(q++) = pixel; - } - } break; - - case 3: - { - if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { - for (;x1 <= x2; ++x1) - { - p[0] = (pixel >> 16) & 0xff; - p[1] = (pixel >> 8) & 0xff; - p[2] = pixel & 0xff; - p += 3; - } - } - else - { - for (;x1 <= x2; ++x1) - { - p[0] = pixel & 0xff; - p[1] = (pixel >> 8) & 0xff; - p[2] = (pixel >> 16) & 0xff; - p += 3; - } - } - } break; - - case 4: - { - Uint32* q = (Uint32*)p; - for (;x1 <= x2; ++x1) - { - if (mAlpha) - { - *q = SDLAlpha32(pixel,*q,mColor.a); - q++; - } - else - { - *(q++) = pixel; - } - } - } break; - - } // end switch - - SDL_UnlockSurface(mTarget); - } - - void SDLGraphics::drawVLine(int x, int y1, int y2) - { - if (mClipStack.empty()) { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you" - "called a draw function outside of _beginDraw() and _endDraw()?"); + SDL_SetClipRect(mTarget, &rect); } - const ClipRectangle& top = mClipStack.top(); - x += top.xOffset; - y1 += top.yOffset; - y2 += top.yOffset; - - if (x < top.x || x >= top.x + top.width) - return; - - if (y1 > y2) - { - y1 ^= y2; - y2 ^= y1; - y1 ^= y2; - } - - if (top.y > y1) - { - if (top.y > y2) - { - return; - } - y1 = top.y; - } - - if (top.y + top.height <= y2) - { - if (top.y + top.height <= y1) - { - return; - } - y2 = top.y + top.height - 1; - } - - int bpp = mTarget->format->BytesPerPixel; - - SDL_LockSurface(mTarget); - - Uint8 *p = (Uint8 *)mTarget->pixels + y1 * mTarget->pitch + x * bpp; - - 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; - } // end switch - - SDL_UnlockSurface(mTarget); - } - - 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; - - drawHLine(x1, y1, x2); - drawHLine(x1, y2, x2); - - drawVLine(x1, y1, y2); - drawVLine(x2, y1, y2); - } - - void SDLGraphics::drawLine(int x1, int y1, int x2, int y2) - { - if (x1 == x2) - { - drawVLine(x1, y1, y2); - return; - } - if (y1 == y2) - { - drawHLine(x1, y1, x2); - return; - } - - if (mClipStack.empty()) { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you" - "called a draw function outside of _beginDraw() and _endDraw()?"); + SDL_Surface* SDLGraphics::getTarget() const + { + return mTarget; } - const ClipRectangle& top = mClipStack.top(); - x1 += top.xOffset; - y1 += top.yOffset; - x2 += top.xOffset; - y2 += top.yOffset; - - // Draw a line with Bresenham - - int dx = ABS(x2 - x1); - int dy = ABS(y2 - y1); - - if (dx > dy) - { - if (x1 > x2) - { - // swap x1, x2 - x1 ^= x2; - x2 ^= x1; - x1 ^= x2; - - // swap y1, y2 - y1 ^= y2; - y2 ^= y1; - y1 ^= y2; - } - - if (y1 < y2) - { - int y = y1; - int p = 0; - - for (int x = x1; x <= x2; x++) - { - if (top.isPointInRect(x, y)) - { - if (mAlpha) - { - SDLputPixelAlpha(mTarget, x, y, mColor); - } - else - { - SDLputPixel(mTarget, x, y, mColor); - } - } - - p += dy; - - if (p * 2 >= dx) - { - y++; - p -= dx; - } - } - } - else - { - int y = y1; - int p = 0; - - for (int x = x1; x <= x2; x++) - { - if (top.isPointInRect(x, y)) - { - if (mAlpha) - { - SDLputPixelAlpha(mTarget, x, y, mColor); - } - else - { - SDLputPixel(mTarget, x, y, mColor); - } - } - - p += dy; - - if (p * 2 >= dx) - { - y--; - p -= dx; - } - } - } - } - else - { - if (y1 > y2) - { - // swap y1, y2 - y1 ^= y2; - y2 ^= y1; - y1 ^= y2; - - // swap x1, x2 - x1 ^= x2; - x2 ^= x1; - x1 ^= x2; - } - - if (x1 < x2) - { - int x = x1; - int p = 0; - - for (int y = y1; y <= y2; y++) - { - if (top.isPointInRect(x, y)) - { - if (mAlpha) - { - SDLputPixelAlpha(mTarget, x, y, mColor); - } - else - { - SDLputPixel(mTarget, x, y, mColor); - } - } - - p += dx; - - if (p * 2 >= dy) - { - x++; - p -= dy; - } - } - } - else - { - int x = x1; - int p = 0; - - for (int y = y1; y <= y2; y++) - { - if (top.isPointInRect(x, y)) - { - if (mAlpha) - { - SDLputPixelAlpha(mTarget, x, y, mColor); - } - else - { - SDLputPixel(mTarget, x, y, mColor); - } - } - - p += dx; - - if (p * 2 >= dy) - { - x--; - p -= dy; - } - } - } - } - } - - void SDLGraphics::setColor(const Color& color) - { - mColor = color; - - mAlpha = color.a != 255; - } - - const Color& SDLGraphics::getColor() - { - return mColor; - } - - void SDLGraphics::drawSDLSurface(SDL_Surface* surface, SDL_Rect source, - SDL_Rect destination) - { - if (mClipStack.empty()) { + void SDLGraphics::drawImage(const Image* image, int srcX, + int srcY, int dstX, int dstY, + int width, int height) + { + if (mClipStack.empty()) + { throw GCN_EXCEPTION("Clip stack is empty, perhaps you" "called a draw function outside of _beginDraw() and _endDraw()?"); } - const ClipRectangle& top = mClipStack.top(); - destination.x += top.xOffset; - destination.y += top.yOffset; + const auto& top = mClipStack.top(); + SDL_Rect src; + SDL_Rect dst; + src.x = srcX; + src.y = srcY; + src.w = width; + src.h = height; + dst.x = dstX + top.xOffset; + dst.y = dstY + top.yOffset; - SDL_BlitSurface(surface, &source, mTarget, &destination); - } + const auto* srcImage = dynamic_cast(image); + + if (srcImage == nullptr) + { + throw GCN_EXCEPTION("Trying to draw an image of unknown format, must be an SDLImage."); + } + + SDL_BlitSurface(srcImage->getSurface(), &src, mTarget, &dst); + } + + void SDLGraphics::fillRectangle(const Rectangle& rectangle) + { + if (mClipStack.empty()) + { + throw GCN_EXCEPTION("Clip stack is empty, perhaps you" + "called a draw function outside of _beginDraw() and _endDraw()?"); + } + + const auto& top = mClipStack.top(); + + auto area = rectangle; + area.x += top.xOffset; + area.y += top.yOffset; + + if (!area.intersect(top)) + { + return; + } + + if (mAlpha) + { + const auto x1 = area.x > top.x ? area.x : top.x; + const auto y1 = area.y > top.y ? area.y : top.y; + const auto x2 = area.x + area.width < top.x + top.width ? area.x + area.width : top.x + top.width; + const auto y2 = area.y + area.height < top.y + top.height ? area.y + area.height : top.y + top.height; + + SDL_LockSurface(mTarget); + for (auto y = y1; y < y2; y++) + { + for (auto x = x1; x < x2; x++) + { + SDLputPixelAlpha(mTarget, x, y, mColor); + } + } + SDL_UnlockSurface(mTarget); + } + else + { + SDL_Rect rect; + rect.x = area.x; + rect.y = area.y; + rect.w = area.width; + rect.h = area.height; + + const auto color = SDL_MapRGBA(mTarget->format, mColor.r, mColor.g, mColor.b, mColor.a); + SDL_FillRect(mTarget, &rect, color); + } + } + + void SDLGraphics::drawPoint(int x, int y) + { + if (mClipStack.empty()) + { + throw GCN_EXCEPTION("Clip stack is empty, perhaps you" + "called a draw function outside of _beginDraw() and _endDraw()?"); + } + + const auto& top = mClipStack.top(); + + x += top.xOffset; + y += top.yOffset; + + 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 function outside of _beginDraw() and _endDraw()?"); + } + const auto& top = mClipStack.top(); + + x1 += top.xOffset; + y += top.yOffset; + x2 += top.xOffset; + + if (y < top.y || y >= top.y + top.height) + return; + + if (x1 > x2) + { + x1 ^= x2; + x2 ^= x1; + x1 ^= x2; + } + + if (top.x > x1) + { + if (top.x > x2) + { + return; + } + x1 = top.x; + } + + if (top.x + top.width <= x2) + { + if (top.x + top.width <= x1) + { + return; + } + x2 = top.x + top.width - 1; + } + + const int bpp = mTarget->format->BytesPerPixel; + + SDL_LockSurface(mTarget); + + auto p = static_cast(mTarget->pixels) + y * mTarget->pitch + x1 * bpp; + + auto pixel = SDL_MapRGB(mTarget->format, mColor.r, mColor.g, mColor.b); + + switch (bpp) + { + case 1: + { + for (; x1 <= x2; ++x1) + { + *(p++) = pixel; + } + } + break; + + case 2: + { + auto* q = reinterpret_cast(p); + for (; x1 <= x2; ++x1) + { + *(q++) = pixel; + } + } + break; + + case 3: + { + if constexpr (SDL_BYTEORDER == SDL_BIG_ENDIAN) + { + for (; x1 <= x2; ++x1) + { + p[0] = (pixel >> 16) & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = pixel & 0xff; + p += 3; + } + } + else + { + for (; x1 <= x2; ++x1) + { + p[0] = pixel & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = (pixel >> 16) & 0xff; + p += 3; + } + } + } + break; + + case 4: + { + auto* q = reinterpret_cast(p); + for (; x1 <= x2; ++x1) + { + if (mAlpha) + { + *q = SDLAlpha32(pixel, *q, mColor.a); + q++; + } + else + { + *(q++) = pixel; + } + } + } + break; + } // end switch + + SDL_UnlockSurface(mTarget); + } + + void SDLGraphics::drawVLine(int x, int y1, int y2) + { + if (mClipStack.empty()) + { + throw GCN_EXCEPTION("Clip stack is empty, perhaps you" + "called a draw function outside of _beginDraw() and _endDraw()?"); + } + const auto& top = mClipStack.top(); + + x += top.xOffset; + y1 += top.yOffset; + y2 += top.yOffset; + + if (x < top.x || x >= top.x + top.width) + return; + + if (y1 > y2) + { + y1 ^= y2; + y2 ^= y1; + y1 ^= y2; + } + + if (top.y > y1) + { + if (top.y > y2) + { + return; + } + y1 = top.y; + } + + if (top.y + top.height <= y2) + { + if (top.y + top.height <= y1) + { + return; + } + y2 = top.y + top.height - 1; + } + + const int bpp = mTarget->format->BytesPerPixel; + + SDL_LockSurface(mTarget); + + auto* p = static_cast(mTarget->pixels) + y1 * mTarget->pitch + x * bpp; + + auto 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) + { + *reinterpret_cast(p) = pixel; + p += mTarget->pitch; + } + } + break; + + case 3: + { + if constexpr (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) + { + *reinterpret_cast(p) = SDLAlpha32(pixel, *reinterpret_cast(p), mColor.a); + } + else + { + *reinterpret_cast(p) = pixel; + } + p += mTarget->pitch; + } + } + break; + } // end switch + + SDL_UnlockSurface(mTarget); + } + + void SDLGraphics::drawRectangle(const Rectangle& rectangle) + { + const auto x1 = rectangle.x; + const auto x2 = rectangle.x + rectangle.width - 1; + const auto y1 = rectangle.y; + const auto y2 = rectangle.y + rectangle.height - 1; + + drawHLine(x1, y1, x2); + drawHLine(x1, y2, x2); + + drawVLine(x1, y1, y2); + drawVLine(x2, y1, y2); + } + + void SDLGraphics::drawLine(int x1, int y1, int x2, int y2) + { + if (x1 == x2) + { + drawVLine(x1, y1, y2); + return; + } + if (y1 == y2) + { + drawHLine(x1, y1, x2); + return; + } + + if (mClipStack.empty()) + { + throw GCN_EXCEPTION("Clip stack is empty, perhaps you" + "called a draw function outside of _beginDraw() and _endDraw()?"); + } + const auto& top = mClipStack.top(); + + x1 += top.xOffset; + y1 += top.yOffset; + x2 += top.xOffset; + y2 += top.yOffset; + + // Draw a line with Bresenham + + const auto dx = ABS(x2 - x1); + const auto dy = ABS(y2 - y1); + + if (dx > dy) + { + if (x1 > x2) + { + // swap x1, x2 + x1 ^= x2; + x2 ^= x1; + x1 ^= x2; + + // swap y1, y2 + y1 ^= y2; + y2 ^= y1; + y1 ^= y2; + } + + if (y1 < y2) + { + auto y = y1; + auto p = 0; + + for (auto x = x1; x <= x2; x++) + { + if (top.isPointInRect(x, y)) + { + if (mAlpha) + { + SDLputPixelAlpha(mTarget, x, y, mColor); + } + else + { + SDLputPixel(mTarget, x, y, mColor); + } + } + + p += dy; + + if (p * 2 >= dx) + { + y++; + p -= dx; + } + } + } + else + { + auto y = y1; + auto p = 0; + + for (auto x = x1; x <= x2; x++) + { + if (top.isPointInRect(x, y)) + { + if (mAlpha) + { + SDLputPixelAlpha(mTarget, x, y, mColor); + } + else + { + SDLputPixel(mTarget, x, y, mColor); + } + } + + p += dy; + + if (p * 2 >= dx) + { + y--; + p -= dx; + } + } + } + } + else + { + if (y1 > y2) + { + // swap y1, y2 + y1 ^= y2; + y2 ^= y1; + y1 ^= y2; + + // swap x1, x2 + x1 ^= x2; + x2 ^= x1; + x1 ^= x2; + } + + if (x1 < x2) + { + auto x = x1; + auto p = 0; + + for (auto y = y1; y <= y2; y++) + { + if (top.isPointInRect(x, y)) + { + if (mAlpha) + { + SDLputPixelAlpha(mTarget, x, y, mColor); + } + else + { + SDLputPixel(mTarget, x, y, mColor); + } + } + + p += dx; + + if (p * 2 >= dy) + { + x++; + p -= dy; + } + } + } + else + { + auto x = x1; + auto p = 0; + + for (auto y = y1; y <= y2; y++) + { + if (top.isPointInRect(x, y)) + { + if (mAlpha) + { + SDLputPixelAlpha(mTarget, x, y, mColor); + } + else + { + SDLputPixel(mTarget, x, y, mColor); + } + } + + p += dx; + + if (p * 2 >= dy) + { + x--; + p -= dy; + } + } + } + } + } + + void SDLGraphics::setColor(const Color& color) + { + mColor = color; + + mAlpha = color.a != 255; + } + + const Color& SDLGraphics::getColor() + { + return mColor; + } + + void SDLGraphics::drawSDLSurface(SDL_Surface* surface, SDL_Rect source, + SDL_Rect destination) + { + if (mClipStack.empty()) + { + throw GCN_EXCEPTION("Clip stack is empty, perhaps you" + "called a draw function outside of _beginDraw() and _endDraw()?"); + } + const auto& top = mClipStack.top(); + + destination.x += top.xOffset; + destination.y += top.yOffset; + + SDL_BlitSurface(surface, &source, mTarget, &destination); + } } diff --git a/external/libguisan/src/sdl/sdlimage.cpp b/external/libguisan/src/sdl/sdlimage.cpp index 414ec59d..32b866a8 100644 --- a/external/libguisan/src/sdl/sdlimage.cpp +++ b/external/libguisan/src/sdl/sdlimage.cpp @@ -65,140 +65,139 @@ namespace gcn { - SDLImage::SDLImage(SDL_Surface* surface, bool autoFree, SDL_Renderer* renderer) - { - mAutoFree = autoFree; - mSurface = surface; + SDLImage::SDLImage(SDL_Surface* surface, bool autoFree, SDL_Renderer* renderer) + { + mAutoFree = autoFree; + mSurface = surface; mRenderer = renderer; if (renderer) { mTexture = SDL_CreateTextureFromSurface(renderer, surface); SDL_SetTextureBlendMode(mTexture, SDL_BLENDMODE_BLEND); - } - } + } + } - SDLImage::~SDLImage() - { - if (mAutoFree) - { - free(); - } - } + SDLImage::~SDLImage() + { + if (mAutoFree) + { + SDLImage::free(); + } + } - SDL_Surface* SDLImage::getSurface() const - { - return mSurface; - } - - SDL_Texture* SDLImage::getTexture() const - { + SDL_Surface* SDLImage::getSurface() const + { + return mSurface; + } + + SDL_Texture* SDLImage::getTexture() const + { return mTexture; } - int SDLImage::getWidth() const - { - if (mSurface == NULL) - { - throw GCN_EXCEPTION("Trying to get the width of a non loaded image."); - } + int SDLImage::getWidth() const + { + if (mSurface == nullptr) + { + throw GCN_EXCEPTION("Trying to get the width of a non loaded image."); + } - return mSurface->w; - } + return mSurface->w; + } - int SDLImage::getHeight() const - { - if (mSurface == NULL) - { - throw GCN_EXCEPTION("Trying to get the height of a non loaded image."); - } + int SDLImage::getHeight() const + { + if (mSurface == nullptr) + { + throw GCN_EXCEPTION("Trying to get the height of a non loaded image."); + } - return mSurface->h; - } + return mSurface->h; + } - Color SDLImage::getPixel(int x, int y) - { - if (mSurface == NULL) - { - throw GCN_EXCEPTION("Trying to get a pixel from a non loaded image."); - } + Color SDLImage::getPixel(int x, int y) + { + if (mSurface == nullptr) + { + throw GCN_EXCEPTION("Trying to get a pixel from a non loaded image."); + } - return SDLgetPixel(mSurface, x, y); - } + return SDLgetPixel(mSurface, x, y); + } - void SDLImage::putPixel(int x, int y, const Color& color) - { - if (mSurface == NULL) - { - throw GCN_EXCEPTION("Trying to put a pixel in a non loaded image."); - } + void SDLImage::putPixel(int x, int y, const Color& color) + { + if (mSurface == nullptr) + { + throw GCN_EXCEPTION("Trying to put a pixel in a non loaded image."); + } - SDLputPixel(mSurface, x, y, color); - } + SDLputPixel(mSurface, x, y, color); + } - void SDLImage::convertToDisplayFormat() - { - if (mSurface == NULL) - { - throw GCN_EXCEPTION("Trying to convert a non loaded image to display format."); - } + void SDLImage::convertToDisplayFormat() + { + if (mSurface == nullptr) + { + throw GCN_EXCEPTION("Trying to convert a non loaded image to display format."); + } - int i; - bool hasPink = false; - bool hasAlpha = false; + int i; + auto hasPink = false; + auto hasAlpha = false; - unsigned int surfaceMask = SDL_PIXELFORMAT_RGBX8888; + unsigned int surfaceMask = SDL_PIXELFORMAT_RGBX8888; - for (i = 0; i < mSurface->w * mSurface->h; ++i) - { - if (((unsigned int*)mSurface->pixels)[i] == SDL_MapRGB(mSurface->format,255,0,255)) - { - hasPink = true; - break; - } - } + for (i = 0; i < mSurface->w * mSurface->h; ++i) + { + if (static_cast(mSurface->pixels)[i] == SDL_MapRGB(mSurface->format, 255, 0, 255)) + { + hasPink = true; + break; + } + } - for (i = 0; i < mSurface->w * mSurface->h; ++i) - { - Uint8 r, g, b, a; + for (i = 0; i < mSurface->w * mSurface->h; ++i) + { + Uint8 r, g, b, a; - SDL_GetRGBA(((unsigned int*)mSurface->pixels)[i], mSurface->format, - &r, &g, &b, &a); + SDL_GetRGBA(static_cast(mSurface->pixels)[i], mSurface->format, + &r, &g, &b, &a); - if (a != 255) - { - surfaceMask = SDL_PIXELFORMAT_RGBA8888; - break; - } - } + if (a != 255) + { + surfaceMask = SDL_PIXELFORMAT_RGBA8888; + break; + } + } - SDL_Surface* tmp = SDL_ConvertSurfaceFormat(mSurface, surfaceMask, 0); - SDL_FreeSurface(mSurface); - mSurface = NULL; + auto* tmp = SDL_ConvertSurfaceFormat(mSurface, surfaceMask, 0); + SDL_FreeSurface(mSurface); + mSurface = nullptr; - if (hasPink) - { - SDL_SetColorKey(tmp, SDL_TRUE, - SDL_MapRGB(tmp->format,255,0,255)); - } + if (hasPink) + { + SDL_SetColorKey(tmp, SDL_TRUE, + SDL_MapRGB(tmp->format, 255, 0, 255)); + } - if (surfaceMask == SDL_PIXELFORMAT_RGBA8888) - SDL_SetSurfaceAlphaMod(tmp, 255); + if (surfaceMask == SDL_PIXELFORMAT_RGBA8888) + SDL_SetSurfaceAlphaMod(tmp, 255); - mSurface = tmp; + mSurface = tmp; if (mRenderer) { - SDL_Texture *tmpTexture = SDL_CreateTextureFromSurface(mRenderer, tmp); + auto* tmpTexture = SDL_CreateTextureFromSurface(mRenderer, tmp); SDL_SetTextureBlendMode(tmpTexture, SDL_BLENDMODE_BLEND); SDL_DestroyTexture(mTexture); mTexture = tmpTexture; } - - } + } - void SDLImage::free() - { - SDL_FreeSurface(mSurface); - SDL_DestroyTexture(mTexture); - } + void SDLImage::free() + { + SDL_FreeSurface(mSurface); + SDL_DestroyTexture(mTexture); + } } diff --git a/external/libguisan/src/sdl/sdlimageloader.cpp b/external/libguisan/src/sdl/sdlimageloader.cpp index 992d2edf..15ba4319 100644 --- a/external/libguisan/src/sdl/sdlimageloader.cpp +++ b/external/libguisan/src/sdl/sdlimageloader.cpp @@ -67,79 +67,79 @@ namespace gcn { - Image* SDLImageLoader::load(const std::string& filename, - bool convertToDisplayFormat) - { - SDL_Surface *loadedSurface = loadSDLSurface(filename); + Image* SDLImageLoader::load(const std::string& filename, + bool convertToDisplayFormat) + { + auto* loadedSurface = loadSDLSurface(filename); - if (loadedSurface == NULL) - { - throw GCN_EXCEPTION( - std::string("Unable to load image file: ") + filename); - } + if (loadedSurface == nullptr) + { + throw GCN_EXCEPTION( + std::string("Unable to load image file: ") + filename); + } - SDL_Surface *surface = convertToStandardFormat(loadedSurface); - SDL_FreeSurface(loadedSurface); + auto* surface = convertToStandardFormat(loadedSurface); + SDL_FreeSurface(loadedSurface); - if (surface == NULL) - { - throw GCN_EXCEPTION( - std::string("Not enough memory to load: ") + filename); - } + if (surface == nullptr) + { + throw GCN_EXCEPTION( + std::string("Not enough memory to load: ") + filename); + } - Image *image = new SDLImage(surface, true, mRenderer); + Image* image = new SDLImage(surface, true, mRenderer); - if (convertToDisplayFormat) - { - image->convertToDisplayFormat(); - } + if (convertToDisplayFormat) + { + image->convertToDisplayFormat(); + } - return image; - } - - void SDLImageLoader::setRenderer(SDL_Renderer* renderer) - { + return image; + } + + void SDLImageLoader::setRenderer(SDL_Renderer* renderer) + { mRenderer = renderer; } - SDL_Surface* SDLImageLoader::loadSDLSurface(const std::string& filename) - { - return IMG_Load(filename.c_str()); - } - - SDL_Texture* SDLImageLoader::loadSDLTexture(const std::string& filename) - { - return IMG_LoadTexture(mRenderer, filename.c_str()); - } + SDL_Surface* SDLImageLoader::loadSDLSurface(const std::string& filename) + { + return IMG_Load(filename.c_str()); + } - SDL_Surface* SDLImageLoader::convertToStandardFormat(SDL_Surface* surface) - { - Uint32 rmask, gmask, bmask, amask; + SDL_Texture* SDLImageLoader::loadSDLTexture(const std::string& filename) + { + return IMG_LoadTexture(mRenderer, filename.c_str()); + } + + SDL_Surface* SDLImageLoader::convertToStandardFormat(SDL_Surface* surface) + { + Uint32 rmask, gmask, bmask, amask; #if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff; #else - rmask = 0x000000ff; - gmask = 0x0000ff00; - bmask = 0x00ff0000; - amask = 0xff000000; + rmask = 0x000000ff; + gmask = 0x0000ff00; + bmask = 0x00ff0000; + amask = 0xff000000; #endif - SDL_Surface *colorSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, - 0, 0, 32, - rmask, gmask, bmask, amask); + auto* colorSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, + 0, 0, 32, + rmask, gmask, bmask, amask); - SDL_Surface *tmp = NULL; + SDL_Surface* tmp = nullptr; - if (colorSurface != NULL) - { - tmp = SDL_ConvertSurface(surface, colorSurface->format, - SDL_SWSURFACE); - SDL_FreeSurface(colorSurface); - } + if (colorSurface != nullptr) + { + tmp = SDL_ConvertSurface(surface, colorSurface->format, + SDL_SWSURFACE); + SDL_FreeSurface(colorSurface); + } - return tmp; - } + return tmp; + } } diff --git a/external/libguisan/src/sdl/sdlinput.cpp b/external/libguisan/src/sdl/sdlinput.cpp index bcb6c39c..93000697 100644 --- a/external/libguisan/src/sdl/sdlinput.cpp +++ b/external/libguisan/src/sdl/sdlinput.cpp @@ -64,393 +64,385 @@ namespace gcn { - SDLInput::SDLInput() - { - mMouseInWindow = true; - mMouseDown = false; - } + SDLInput::SDLInput() + { + mMouseInWindow = true; + mMouseDown = false; + } - bool SDLInput::isKeyQueueEmpty() - { - return mKeyInputQueue.empty(); - } + bool SDLInput::isKeyQueueEmpty() + { + return mKeyInputQueue.empty(); + } - KeyInput SDLInput::dequeueKeyInput() - { - KeyInput keyInput; + KeyInput SDLInput::dequeueKeyInput() + { + if (mKeyInputQueue.empty()) + { + throw GCN_EXCEPTION("The queue is empty."); + } - if (mKeyInputQueue.empty()) - { - throw GCN_EXCEPTION("The queue is empty."); - } + const auto keyInput = mKeyInputQueue.front(); + mKeyInputQueue.pop(); - keyInput = mKeyInputQueue.front(); - mKeyInputQueue.pop(); + return keyInput; + } - return keyInput; - } + bool SDLInput::isMouseQueueEmpty() + { + return mMouseInputQueue.empty(); + } - bool SDLInput::isMouseQueueEmpty() - { - return mMouseInputQueue.empty(); - } + MouseInput SDLInput::dequeueMouseInput() + { + if (mMouseInputQueue.empty()) + { + throw GCN_EXCEPTION("The queue is empty."); + } - MouseInput SDLInput::dequeueMouseInput() - { - MouseInput mouseInput; + const auto mouseInput = mMouseInputQueue.front(); + mMouseInputQueue.pop(); - if (mMouseInputQueue.empty()) - { - throw GCN_EXCEPTION("The queue is empty."); - } + return mouseInput; + } - mouseInput = mMouseInputQueue.front(); - mMouseInputQueue.pop(); + void SDLInput::pushInput(SDL_Event event) + { + KeyInput keyInput; + MouseInput mouseInput; - return mouseInput; - } + switch (event.type) + { + case SDL_KEYDOWN: + keyInput.setKey(Key(convertKeyCharacter(event))); + keyInput.setType(KeyInput::PRESSED); + keyInput.setShiftPressed(event.key.keysym.mod & KMOD_SHIFT); + keyInput.setControlPressed(event.key.keysym.mod & KMOD_CTRL); + keyInput.setAltPressed(event.key.keysym.mod & KMOD_ALT); + keyInput.setMetaPressed(event.key.keysym.mod & KMOD_GUI); + keyInput.setNumericPad(event.key.keysym.sym >= SDLK_KP_0 + && event.key.keysym.sym <= SDLK_KP_EQUALS); - void SDLInput::pushInput(SDL_Event event) - { - KeyInput keyInput; - MouseInput mouseInput; + mKeyInputQueue.push(keyInput); + break; - switch (event.type) - { - case SDL_KEYDOWN: - keyInput.setKey(Key(convertKeyCharacter(event))); - keyInput.setType(KeyInput::PRESSED); - keyInput.setShiftPressed(event.key.keysym.mod & KMOD_SHIFT); - keyInput.setControlPressed(event.key.keysym.mod & KMOD_CTRL); - keyInput.setAltPressed(event.key.keysym.mod & KMOD_ALT); - keyInput.setMetaPressed(event.key.keysym.mod & KMOD_GUI); - keyInput.setNumericPad(event.key.keysym.sym >= SDLK_KP_0 - && event.key.keysym.sym <= SDLK_KP_EQUALS); + case SDL_KEYUP: + keyInput.setKey(Key(convertKeyCharacter(event))); + keyInput.setType(KeyInput::RELEASED); + keyInput.setShiftPressed(event.key.keysym.mod & KMOD_SHIFT); + keyInput.setControlPressed(event.key.keysym.mod & KMOD_CTRL); + keyInput.setAltPressed(event.key.keysym.mod & KMOD_ALT); + keyInput.setMetaPressed(event.key.keysym.mod & KMOD_GUI); + keyInput.setNumericPad(event.key.keysym.sym >= SDLK_KP_0 + && event.key.keysym.sym <= SDLK_KP_EQUALS); - mKeyInputQueue.push(keyInput); - break; + mKeyInputQueue.push(keyInput); + break; - case SDL_KEYUP: - keyInput.setKey(Key(convertKeyCharacter(event))); - keyInput.setType(KeyInput::RELEASED); - keyInput.setShiftPressed(event.key.keysym.mod & KMOD_SHIFT); - keyInput.setControlPressed(event.key.keysym.mod & KMOD_CTRL); - keyInput.setAltPressed(event.key.keysym.mod & KMOD_ALT); - keyInput.setMetaPressed(event.key.keysym.mod & KMOD_GUI); - keyInput.setNumericPad(event.key.keysym.sym >= SDLK_KP_0 - && event.key.keysym.sym <= SDLK_KP_EQUALS); + case SDL_MOUSEBUTTONDOWN: + mMouseDown = true; + mouseInput.setX(event.button.x); + mouseInput.setY(event.button.y); + mouseInput.setButton(convertMouseButton(event.button.button)); + mouseInput.setType(MouseInput::PRESSED); + mouseInput.setTimeStamp(SDL_GetTicks()); + mMouseInputQueue.push(mouseInput); + break; - mKeyInputQueue.push(keyInput); - break; + case SDL_MOUSEBUTTONUP: + mMouseDown = false; + mouseInput.setX(event.button.x); + mouseInput.setY(event.button.y); + mouseInput.setButton(convertMouseButton(event.button.button)); + mouseInput.setType(MouseInput::RELEASED); + mouseInput.setTimeStamp(SDL_GetTicks()); + mMouseInputQueue.push(mouseInput); + break; - case SDL_MOUSEBUTTONDOWN: - mMouseDown = true; - mouseInput.setX(event.button.x); - mouseInput.setY(event.button.y); - mouseInput.setButton(convertMouseButton(event.button.button)); - mouseInput.setType(MouseInput::PRESSED); - mouseInput.setTimeStamp(SDL_GetTicks()); - mMouseInputQueue.push(mouseInput); - break; + case SDL_MOUSEMOTION: + mouseInput.setX(event.button.x); + mouseInput.setY(event.button.y); + mouseInput.setButton(MouseInput::EMPTY); + mouseInput.setType(MouseInput::MOVED); + mouseInput.setTimeStamp(SDL_GetTicks()); + mMouseInputQueue.push(mouseInput); + break; - case SDL_MOUSEBUTTONUP: - mMouseDown = false; - mouseInput.setX(event.button.x); - mouseInput.setY(event.button.y); - mouseInput.setButton(convertMouseButton(event.button.button)); - mouseInput.setType(MouseInput::RELEASED); - mouseInput.setTimeStamp(SDL_GetTicks()); - mMouseInputQueue.push(mouseInput); - break; + case SDL_MOUSEWHEEL: + if (event.wheel.y > 0) + mouseInput.setType(MouseInput::WHEEL_MOVED_UP); + else + mouseInput.setType(MouseInput::WHEEL_MOVED_DOWN); + break; - case SDL_MOUSEMOTION: - mouseInput.setX(event.button.x); - mouseInput.setY(event.button.y); - mouseInput.setButton(MouseInput::EMPTY); - mouseInput.setType(MouseInput::MOVED); - mouseInput.setTimeStamp(SDL_GetTicks()); - mMouseInputQueue.push(mouseInput); - break; + case SDL_WINDOWEVENT: + /* + * This occurs when the mouse leaves the window and the Gui-chan + * application loses its mousefocus. + */ + if (event.window.event & SDL_WINDOWEVENT_LEAVE) + { + mMouseInWindow = false; - case SDL_MOUSEWHEEL: - if (event.wheel.y > 0) - mouseInput.setType(MouseInput::WHEEL_MOVED_UP); - else - mouseInput.setType(MouseInput::WHEEL_MOVED_DOWN); - break; + if (!mMouseDown) + { + mouseInput.setX(-1); + mouseInput.setY(-1); + mouseInput.setButton(MouseInput::EMPTY); + mouseInput.setType(MouseInput::MOVED); + mMouseInputQueue.push(mouseInput); + } + } - case SDL_WINDOWEVENT: - /* - * This occurs when the mouse leaves the window and the Gui-chan - * application loses its mousefocus. - */ - if (event.window.event & SDL_WINDOWEVENT_LEAVE) - { - mMouseInWindow = false; + if (event.window.event & SDL_WINDOWEVENT_ENTER) + { + mMouseInWindow = true; + } + break; + } // end switch + } - if (!mMouseDown) - { - mouseInput.setX(-1); - mouseInput.setY(-1); - mouseInput.setButton(MouseInput::EMPTY); - mouseInput.setType(MouseInput::MOVED); - mMouseInputQueue.push(mouseInput); - } - } + int SDLInput::convertMouseButton(int button) + { + switch (button) + { + case SDL_BUTTON_LEFT: + return MouseInput::LEFT; + case SDL_BUTTON_RIGHT: + return MouseInput::RIGHT; + case SDL_BUTTON_MIDDLE: + return MouseInput::MIDDLE; + default: + // We have an unknown mouse type which is ignored. + return button; + } + } - if (event.window.event & SDL_WINDOWEVENT_ENTER) - { - mMouseInWindow = true; - } - break; + int SDLInput::convertKeyCharacter(SDL_Event event) + { + const auto keysym = event.key.keysym; - } // end switch - } + int value; + switch (keysym.sym) + { + case SDLK_TAB: + value = Key::TAB; + break; + case SDLK_LALT: + value = Key::LEFT_ALT; + break; + case SDLK_RALT: + value = Key::RIGHT_ALT; + break; + case SDLK_LSHIFT: + value = Key::LEFT_SHIFT; + break; + case SDLK_RSHIFT: + value = Key::RIGHT_SHIFT; + break; + case SDLK_LCTRL: + value = Key::LEFT_CONTROL; + break; + case SDLK_RCTRL: + value = Key::RIGHT_CONTROL; + break; + case SDLK_BACKSPACE: + value = Key::BACKSPACE; + break; + case SDLK_PAUSE: + value = Key::PAUSE; + break; + case SDLK_SPACE: + value = Key::SPACE; + break; + case SDLK_ESCAPE: + value = Key::ESCAPE; + break; + case SDLK_DELETE: + value = Key::DELETE; + break; + case SDLK_INSERT: + value = Key::INSERT; + break; + case SDLK_HOME: + value = Key::HOME; + break; + case SDLK_END: + value = Key::END; + break; + case SDLK_PAGEUP: + value = Key::PAGE_UP; + break; + case SDLK_PRINTSCREEN: + value = Key::PRINT_SCREEN; + break; + case SDLK_PAGEDOWN: + value = Key::PAGE_DOWN; + break; + case SDLK_F1: + value = Key::F1; + break; + case SDLK_F2: + value = Key::F2; + break; + case SDLK_F3: + value = Key::F3; + break; + case SDLK_F4: + value = Key::F4; + break; + case SDLK_F5: + value = Key::F5; + break; + case SDLK_F6: + value = Key::F6; + break; + case SDLK_F7: + value = Key::F7; + break; + case SDLK_F8: + value = Key::F8; + break; + case SDLK_F9: + value = Key::F9; + break; + case SDLK_F10: + value = Key::F10; + break; + case SDLK_F11: + value = Key::F11; + break; + case SDLK_F12: + value = Key::F12; + break; + case SDLK_F13: + value = Key::F13; + break; + case SDLK_F14: + value = Key::F14; + break; + case SDLK_F15: + value = Key::F15; + break; + case SDLK_NUMLOCKCLEAR: + value = Key::NUM_LOCK; + break; + case SDLK_CAPSLOCK: + value = Key::CAPS_LOCK; + break; + case SDLK_SCROLLLOCK: + value = Key::SCROLL_LOCK; + break; + case SDLK_RGUI: + value = Key::RIGHT_META; + break; + case SDLK_LGUI: + value = Key::LEFT_META; + break; + case SDLK_MODE: + value = Key::ALT_GR; + break; + case SDLK_UP: + value = Key::UP; + break; + case SDLK_DOWN: + value = Key::DOWN; + break; + case SDLK_LEFT: + value = Key::LEFT; + break; + case SDLK_RIGHT: + value = Key::RIGHT; + break; + case SDLK_RETURN: + value = Key::ENTER; + break; + case SDLK_KP_ENTER: + value = Key::ENTER; + break; - int SDLInput::convertMouseButton(int button) - { - switch (button) - { - case SDL_BUTTON_LEFT: - return MouseInput::LEFT; - break; - case SDL_BUTTON_RIGHT: - return MouseInput::RIGHT; - break; - case SDL_BUTTON_MIDDLE: - return MouseInput::MIDDLE; - break; - default: - // We have an unknown mouse type which is ignored. - return button; - } - } + default: + value = keysym.sym; + break; + } - int SDLInput::convertKeyCharacter(SDL_Event event) - { - SDL_Keysym keysym = event.key.keysym; - - int value = 0; - switch (keysym.sym) - { - case SDLK_TAB: - value = Key::TAB; - break; - case SDLK_LALT: - value = Key::LEFT_ALT; - break; - case SDLK_RALT: - value = Key::RIGHT_ALT; - break; - case SDLK_LSHIFT: - value = Key::LEFT_SHIFT; - break; - case SDLK_RSHIFT: - value = Key::RIGHT_SHIFT; - break; - case SDLK_LCTRL: - value = Key::LEFT_CONTROL; - break; - case SDLK_RCTRL: - value = Key::RIGHT_CONTROL; - break; - case SDLK_BACKSPACE: - value = Key::BACKSPACE; - break; - case SDLK_PAUSE: - value = Key::PAUSE; - break; - case SDLK_SPACE: - value = Key::SPACE; - break; - case SDLK_ESCAPE: - value = Key::ESCAPE; - break; - case SDLK_DELETE: - value = Key::DELETE; - break; - case SDLK_INSERT: - value = Key::INSERT; - break; - case SDLK_HOME: - value = Key::HOME; - break; - case SDLK_END: - value = Key::END; - break; - case SDLK_PAGEUP: - value = Key::PAGE_UP; - break; - case SDLK_PRINTSCREEN: - value = Key::PRINT_SCREEN; - break; - case SDLK_PAGEDOWN: - value = Key::PAGE_DOWN; - break; - case SDLK_F1: - value = Key::F1; - break; - case SDLK_F2: - value = Key::F2; - break; - case SDLK_F3: - value = Key::F3; - break; - case SDLK_F4: - value = Key::F4; - break; - case SDLK_F5: - value = Key::F5; - break; - case SDLK_F6: - value = Key::F6; - break; - case SDLK_F7: - value = Key::F7; - break; - case SDLK_F8: - value = Key::F8; - break; - case SDLK_F9: - value = Key::F9; - break; - case SDLK_F10: - value = Key::F10; - break; - case SDLK_F11: - value = Key::F11; - break; - case SDLK_F12: - value = Key::F12; - break; - case SDLK_F13: - value = Key::F13; - break; - case SDLK_F14: - value = Key::F14; - break; - case SDLK_F15: - value = Key::F15; - break; - case SDLK_NUMLOCKCLEAR: - value = Key::NUM_LOCK; - break; - case SDLK_CAPSLOCK: - value = Key::CAPS_LOCK; - break; - case SDLK_SCROLLLOCK: - value = Key::SCROLL_LOCK; - break; - case SDLK_RGUI: - value = Key::RIGHT_META; - break; - case SDLK_LGUI: - value = Key::LEFT_META; - break; - case SDLK_MODE: - value = Key::ALT_GR; - break; - case SDLK_UP: - value = Key::UP; - break; - case SDLK_DOWN: - value = Key::DOWN; - break; - case SDLK_LEFT: - value = Key::LEFT; - break; - case SDLK_RIGHT: - value = Key::RIGHT; - break; - case SDLK_RETURN: - value = Key::ENTER; - break; - case SDLK_KP_ENTER: - value = Key::ENTER; - break; + if (!(keysym.mod & KMOD_NUM)) + { + switch (keysym.sym) + { + case SDLK_KP_0: + value = Key::INSERT; + break; + case SDLK_KP_1: + value = Key::END; + break; + case SDLK_KP_2: + value = Key::DOWN; + break; + case SDLK_KP_3: + value = Key::PAGE_DOWN; + break; + case SDLK_KP_4: + value = Key::LEFT; + break; + case SDLK_KP_5: + value = 0; + break; + case SDLK_KP_6: + value = Key::RIGHT; + break; + case SDLK_KP_7: + value = Key::HOME; + break; + case SDLK_KP_8: + value = Key::UP; + break; + case SDLK_KP_9: + value = Key::PAGE_UP; + break; + default: + break; + } + } + else + { + switch (keysym.sym) + { + case SDLK_KP_0: + value = SDLK_0; + break; + case SDLK_KP_1: + value = SDLK_1; + break; + case SDLK_KP_2: + value = SDLK_2; + break; + case SDLK_KP_3: + value = SDLK_3; + break; + case SDLK_KP_4: + value = SDLK_4; + break; + case SDLK_KP_5: + value = SDLK_5; + break; + case SDLK_KP_6: + value = SDLK_6; + break; + case SDLK_KP_7: + value = SDLK_7; + break; + case SDLK_KP_8: + value = SDLK_8; + break; + case SDLK_KP_9: + value = SDLK_9; + break; + default: + break; + } + } - default: - value = keysym.sym; - break; - } - - if (!(keysym.mod & KMOD_NUM)) - { - switch (keysym.sym) - { - case SDLK_KP_0: - value = Key::INSERT; - break; - case SDLK_KP_1: - value = Key::END; - break; - case SDLK_KP_2: - value = Key::DOWN; - break; - case SDLK_KP_3: - value = Key::PAGE_DOWN; - break; - case SDLK_KP_4: - value = Key::LEFT; - break; - case SDLK_KP_5: - value = 0; - break; - case SDLK_KP_6: - value = Key::RIGHT; - break; - case SDLK_KP_7: - value = Key::HOME; - break; - case SDLK_KP_8: - value = Key::UP; - break; - case SDLK_KP_9: - value = Key::PAGE_UP; - break; - default: - break; - } - } - else - { - switch (keysym.sym) - { - case SDLK_KP_0: - value = SDLK_0; - break; - case SDLK_KP_1: - value = SDLK_1; - break; - case SDLK_KP_2: - value = SDLK_2; - break; - case SDLK_KP_3: - value = SDLK_3; - break; - case SDLK_KP_4: - value = SDLK_4; - break; - case SDLK_KP_5: - value = SDLK_5; - break; - case SDLK_KP_6: - value = SDLK_6; - break; - case SDLK_KP_7: - value = SDLK_7; - break; - case SDLK_KP_8: - value = SDLK_8; - break; - case SDLK_KP_9: - value = SDLK_9; - break; - default: - break; - } - } - - return value; - } + return value; + } } diff --git a/external/libguisan/src/sdl/sdltruetypefont.cpp b/external/libguisan/src/sdl/sdltruetypefont.cpp index 48466f3f..1ea49c98 100644 --- a/external/libguisan/src/sdl/sdltruetypefont.cpp +++ b/external/libguisan/src/sdl/sdltruetypefont.cpp @@ -55,17 +55,17 @@ namespace gcn { - SDLTrueTypeFont::SDLTrueTypeFont (const std::string& filename, int size) + SDLTrueTypeFont::SDLTrueTypeFont(const std::string& filename, int size) { mRowSpacing = 0; mGlyphSpacing = 0; - mAntiAlias = true; + mAntiAlias = true; mFilename = filename; - mFont = NULL; - + mFont = nullptr; + mFont = TTF_OpenFont(filename.c_str(), size); - - if (mFont == NULL) + + if (mFont == nullptr) { throw GCN_EXCEPTION("SDLTrueTypeFont::SDLTrueTypeFont. "+std::string(TTF_GetError())); } @@ -80,7 +80,7 @@ namespace gcn { int w, h; TTF_SizeText(mFont, text.c_str(), &w, &h); - + return w; } @@ -89,26 +89,26 @@ namespace gcn return TTF_FontHeight(mFont) + mRowSpacing; } - void SDLTrueTypeFont::drawString(gcn::Graphics* graphics, const std::string& text, const int x, const int y) + void SDLTrueTypeFont::drawString(Graphics* graphics, const std::string& text, const int x, const int y) { if (text == "") { return; } - - gcn::SDLGraphics *sdlGraphics = dynamic_cast(graphics); - gcn::SDL2Graphics *sdl2Graphics = dynamic_cast(graphics); - - if (sdlGraphics == NULL && sdl2Graphics == NULL) + auto* sdlGraphics = dynamic_cast(graphics); + auto* sdl2Graphics = dynamic_cast(graphics); + + + if (sdlGraphics == nullptr && sdl2Graphics == nullptr) { throw GCN_EXCEPTION("SDLTrueTypeFont::drawString. Graphics object not an SDL graphics object!"); return; } - + // This is needed for drawing the Glyph in the middle if we have spacing - int yoffset = getRowSpacing() / 2; - + const auto yoffset = getRowSpacing() / 2; + Color col; if (sdlGraphics) { @@ -124,7 +124,7 @@ namespace gcn sdlCol.r = col.r; sdlCol.g = col.g; - SDL_Surface *textSurface; + SDL_Surface* textSurface; if (mAntiAlias) { textSurface = TTF_RenderText_Blended(mFont, text.c_str(), sdlCol); @@ -133,7 +133,7 @@ namespace gcn { textSurface = TTF_RenderText_Solid(mFont, text.c_str(), sdlCol); } - + SDL_Rect dst, src; dst.x = x; dst.y = y + yoffset; @@ -143,7 +143,7 @@ namespace gcn src.y = 0; dst.w = src.w; dst.h = src.h; - + if (sdlGraphics) { sdlGraphics->drawSDLSurface(textSurface, src, dst); @@ -152,8 +152,8 @@ namespace gcn { sdl2Graphics->drawSDLSurface(textSurface, src, dst); } - - SDL_FreeSurface(textSurface); + + SDL_FreeSurface(textSurface); } void SDLTrueTypeFont::setRowSpacing(int spacing) @@ -183,8 +183,6 @@ namespace gcn bool SDLTrueTypeFont::isAntiAlias() { - return mAntiAlias; - } - + return mAntiAlias; + } } - diff --git a/external/libguisan/src/selectionevent.cpp b/external/libguisan/src/selectionevent.cpp index 81c7970f..cbfd6e02 100644 --- a/external/libguisan/src/selectionevent.cpp +++ b/external/libguisan/src/selectionevent.cpp @@ -62,15 +62,11 @@ namespace gcn { - SelectionEvent::SelectionEvent(Widget* source) - :Event(source) - { + SelectionEvent::SelectionEvent(Widget* source) + : Event(source) + { + } - } - - SelectionEvent::~SelectionEvent() - { - - } + SelectionEvent::~SelectionEvent() + = default; } - diff --git a/external/libguisan/src/widgets/listbox.cpp b/external/libguisan/src/widgets/listbox.cpp index 061f652a..5a6001e4 100644 --- a/external/libguisan/src/widgets/listbox.cpp +++ b/external/libguisan/src/widgets/listbox.cpp @@ -110,7 +110,7 @@ namespace gcn // Check the current clip area so we don't draw unnecessary items // that are not visible. const auto currentClipArea = graphics->getCurrentClipArea(); - const int rowHeight = getFont()->getHeight(); + const int rowHeight = getFont()->getHeight() + 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 @@ -124,7 +124,7 @@ namespace gcn // 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 + // we should drop rows in the beginning 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. @@ -160,11 +160,11 @@ namespace gcn // draw the text with a center vertical alignment. if (rowHeight > getFont()->getHeight()) { - graphics->drawText(mListModel->getElementAt(i), 1, y + rowHeight / 2 - getFont()->getHeight() / 2); + graphics->drawText(mListModel->getElementAt(i), 2, y + rowHeight / 2 - getFont()->getHeight() / 2); } else { - graphics->drawText(mListModel->getElementAt(i), 1, y); + graphics->drawText(mListModel->getElementAt(i), 2, y); } y += rowHeight; diff --git a/external/libguisan/src/widgets/scrollarea.cpp b/external/libguisan/src/widgets/scrollarea.cpp index 1c1a2be0..27c3df12 100644 --- a/external/libguisan/src/widgets/scrollarea.cpp +++ b/external/libguisan/src/widgets/scrollarea.cpp @@ -842,8 +842,8 @@ namespace gcn if (!getContent()) { - mHBarVisible = (mHPolicy == SHOW_ALWAYS); - mVBarVisible = (mVPolicy == SHOW_ALWAYS); + mHBarVisible = mHPolicy == SHOW_ALWAYS; + mVBarVisible = mVPolicy == SHOW_ALWAYS; return; } @@ -926,7 +926,7 @@ namespace gcn } } - Rectangle ScrollArea::getUpButtonDimension() + Rectangle ScrollArea::getUpButtonDimension() const { if (!mVBarVisible) { @@ -939,7 +939,7 @@ namespace gcn mScrollbarWidth); } - Rectangle ScrollArea::getDownButtonDimension() + Rectangle ScrollArea::getDownButtonDimension() const { if (!mVBarVisible) { @@ -960,7 +960,7 @@ namespace gcn mScrollbarWidth); } - Rectangle ScrollArea::getLeftButtonDimension() + Rectangle ScrollArea::getLeftButtonDimension() const { if (!mHBarVisible) { @@ -973,7 +973,7 @@ namespace gcn mScrollbarWidth); } - Rectangle ScrollArea::getRightButtonDimension() + Rectangle ScrollArea::getRightButtonDimension() const { if (!mHBarVisible) { @@ -1015,7 +1015,7 @@ namespace gcn return Rectangle(0, 0, getWidth(), getHeight()); } - Rectangle ScrollArea::getVerticalBarDimension() + Rectangle ScrollArea::getVerticalBarDimension() const { if (!mVBarVisible) { @@ -1041,7 +1041,7 @@ namespace gcn - getDownButtonDimension().height); } - Rectangle ScrollArea::getHorizontalBarDimension() + Rectangle ScrollArea::getHorizontalBarDimension() const { if (!mHBarVisible) { @@ -1099,7 +1099,7 @@ namespace gcn if (getVerticalMaxScroll() != 0) { - pos = ((barDim.height - length) * getVerticalScrollAmount()) + pos = (barDim.height - length) * getVerticalScrollAmount() / getVerticalMaxScroll(); } else @@ -1142,7 +1142,7 @@ namespace gcn if (getHorizontalMaxScroll() != 0) { - pos = ((barDim.width - length) * getHorizontalScrollAmount()) + pos = (barDim.width - length) * getHorizontalScrollAmount() / getHorizontalMaxScroll(); } else diff --git a/external/libguisan/src/widgets/textbox.cpp b/external/libguisan/src/widgets/textbox.cpp index 815aabca..88df4ad6 100644 --- a/external/libguisan/src/widgets/textbox.cpp +++ b/external/libguisan/src/widgets/textbox.cpp @@ -380,7 +380,7 @@ namespace gcn } setWidth(width + 1); - setHeight(getFont()->getHeight() * static_cast(mTextRows.size())); + setHeight((getFont()->getHeight() + 2) * static_cast(mTextRows.size())); } void TextBox::setCaretPosition(unsigned int position) diff --git a/external/libguisan/src/widgets/window.cpp b/external/libguisan/src/widgets/window.cpp index d8f9b520..5047d649 100644 --- a/external/libguisan/src/widgets/window.cpp +++ b/external/libguisan/src/widgets/window.cpp @@ -72,7 +72,7 @@ namespace gcn { setBorderSize(1); Window::setPadding(2); - Window::setTitleBarHeight(16); + Window::setTitleBarHeight(getFont()->getHeight() + 2); Window::setAlignment(Graphics::CENTER); addMouseListener(this); setMovable(true); @@ -85,7 +85,7 @@ namespace gcn Window::setCaption(caption); setBorderSize(1); Window::setPadding(2); - Window::setTitleBarHeight(16); + Window::setTitleBarHeight(getFont()->getHeight() + 2); Window::setAlignment(Graphics::CENTER); addMouseListener(this); setMovable(true); diff --git a/src/osdep/gui/PanelAbout.cpp b/src/osdep/gui/PanelAbout.cpp index 4bc9950f..4cca05c8 100644 --- a/src/osdep/gui/PanelAbout.cpp +++ b/src/osdep/gui/PanelAbout.cpp @@ -40,7 +40,7 @@ void InitPanelAbout(const struct _ConfigCategory& category) textBoxScrollArea->setBackgroundColor(gui_baseCol); textBoxScrollArea->setBaseColor(gui_baseCol); textBoxScrollArea->setWidth(category.panel->getWidth() - DISTANCE_BORDER * 2); - textBoxScrollArea->setHeight(200); + textBoxScrollArea->setHeight(220); textBoxScrollArea->setBorderSize(1); auto pos_y = DISTANCE_BORDER; diff --git a/src/osdep/gui/PanelCPU.cpp b/src/osdep/gui/PanelCPU.cpp index 26e52660..0e858a71 100644 --- a/src/osdep/gui/PanelCPU.cpp +++ b/src/osdep/gui/PanelCPU.cpp @@ -264,7 +264,8 @@ void InitPanelCPU(const struct _ConfigCategory& category) grpCPU->add(chkCPUCompatible, 5, 200); grpCPU->add(chkJIT, 5, 230); grpCPU->setMovable(false); - grpCPU->setSize(175, 275); + grpCPU->setSize(175, 285); + grpCPU->setTitleBarHeight(TITLEBAR_HEIGHT); grpCPU->setBaseColor(gui_baseCol); category.panel->add(grpCPU); @@ -304,7 +305,8 @@ void InitPanelCPU(const struct _ConfigCategory& category) grpFPU->add(chkFPUstrict, 5, 140); grpFPU->add(chkFPUJIT, 5, 170); grpFPU->setMovable(false); - grpFPU->setSize(185, 215); + grpFPU->setSize(185, 225); + grpFPU->setTitleBarHeight(TITLEBAR_HEIGHT); grpFPU->setBaseColor(gui_baseCol); category.panel->add(grpFPU); @@ -339,7 +341,8 @@ void InitPanelCPU(const struct _ConfigCategory& category) grpCPUSpeed->add(optFastest, 5, 100); grpCPUSpeed->add(optTurbo, 5, 130); grpCPUSpeed->setMovable(false); - grpCPUSpeed->setSize(95, 200); + grpCPUSpeed->setSize(100, 200); + grpCPUSpeed->setTitleBarHeight(TITLEBAR_HEIGHT); grpCPUSpeed->setBaseColor(gui_baseCol); category.panel->add(grpCPUSpeed); diff --git a/src/osdep/gui/PanelChipset.cpp b/src/osdep/gui/PanelChipset.cpp index 5bd30bff..fa6279a4 100644 --- a/src/osdep/gui/PanelChipset.cpp +++ b/src/osdep/gui/PanelChipset.cpp @@ -240,7 +240,8 @@ void InitPanelChipset(const struct _ConfigCategory& category) grpChipset->add(cboChipset, 145 + lblChipset->getWidth() + 8, 10); grpChipset->setMovable(false); - grpChipset->setSize(optOCS->getWidth() + 125 + lblChipset->getWidth() + cboChipset->getWidth(), 185); + grpChipset->setSize(optOCS->getWidth() + 125 + lblChipset->getWidth() + cboChipset->getWidth(), 195); + grpChipset->setTitleBarHeight(TITLEBAR_HEIGHT); grpChipset->setBaseColor(gui_baseCol); category.panel->add(grpChipset); @@ -265,7 +266,8 @@ void InitPanelChipset(const struct _ConfigCategory& category) grpBlitter->add(optBlitImmed, 5, 40); grpBlitter->add(optBlitWait, 5, 70); grpBlitter->setMovable(false); - grpBlitter->setSize(optBlitWait->getWidth() + DISTANCE_BORDER, 115); + grpBlitter->setSize(optBlitWait->getWidth() + DISTANCE_BORDER, 125); + grpBlitter->setTitleBarHeight(TITLEBAR_HEIGHT); grpBlitter->setBaseColor(gui_baseCol); category.panel->add(grpBlitter); @@ -281,7 +283,8 @@ void InitPanelChipset(const struct _ConfigCategory& category) grpBlitter->getY() + grpBlitter->getHeight() + DISTANCE_NEXT_Y); grpCopper->add(chkFastCopper, 5, 10); grpCopper->setMovable(false); - grpCopper->setSize(chkFastCopper->getWidth() + DISTANCE_BORDER, 55); + grpCopper->setSize(chkFastCopper->getWidth() + DISTANCE_BORDER, 65); + grpCopper->setTitleBarHeight(TITLEBAR_HEIGHT); grpCopper->setBaseColor(gui_baseCol); category.panel->add(grpCopper); @@ -311,7 +314,8 @@ void InitPanelChipset(const struct _ConfigCategory& category) grpCollisionLevel->add(optCollPlayfield, 5, 70); grpCollisionLevel->add(optCollFull, 5, 100); grpCollisionLevel->setMovable(false); - grpCollisionLevel->setSize(optCollPlayfield->getWidth() + DISTANCE_BORDER, 145); + grpCollisionLevel->setSize(optCollPlayfield->getWidth() + DISTANCE_BORDER, 155); + grpCollisionLevel->setTitleBarHeight(TITLEBAR_HEIGHT); grpCollisionLevel->setBaseColor(gui_baseCol); category.panel->add(grpCollisionLevel); diff --git a/src/osdep/gui/PanelCustom.cpp b/src/osdep/gui/PanelCustom.cpp index c901b642..43568f64 100644 --- a/src/osdep/gui/PanelCustom.cpp +++ b/src/osdep/gui/PanelCustom.cpp @@ -382,6 +382,7 @@ void InitPanelCustom(const struct _ConfigCategory& category) grpPort->add(optPort2, 290, 5); grpPort->add(optPort3, 430, 5); grpPort->setSize(580, 50); + grpPort->setTitleBarHeight(TITLEBAR_HEIGHT); grpPort->setBaseColor(gui_baseCol); category.panel->add(grpPort); @@ -393,6 +394,7 @@ void InitPanelCustom(const struct _ConfigCategory& category) // grpFunction->add(optMultiLeft, 290, 5); // grpFunction->add(optMultiRight, 430, 5); grpFunction->setSize(580, 50); + grpFunction->setTitleBarHeight(TITLEBAR_HEIGHT); grpFunction->setBaseColor(gui_baseCol); category.panel->add(grpFunction); diff --git a/src/osdep/gui/PanelDisplay.cpp b/src/osdep/gui/PanelDisplay.cpp index f56640da..ae159074 100644 --- a/src/osdep/gui/PanelDisplay.cpp +++ b/src/osdep/gui/PanelDisplay.cpp @@ -195,7 +195,8 @@ void InitPanelDisplay(const struct _ConfigCategory& category) grpAmigaScreen->setMovable(false); grpAmigaScreen->setSize( lblAmigaWidth->getX() + lblAmigaWidth->getWidth() + sldAmigaWidth->getWidth() + lblAmigaWidth->getWidth() + ( - DISTANCE_BORDER * 2), posY + DISTANCE_BORDER); + DISTANCE_BORDER * 2), posY + DISTANCE_BORDER * 2); + grpAmigaScreen->setTitleBarHeight(TITLEBAR_HEIGHT); grpAmigaScreen->setBaseColor(gui_baseCol); category.panel->add(grpAmigaScreen); @@ -204,7 +205,8 @@ void InitPanelDisplay(const struct _ConfigCategory& category) grpCentering->add(chkHorizontal, DISTANCE_BORDER, DISTANCE_BORDER); grpCentering->add(chkVertical, DISTANCE_BORDER, chkHorizontal->getY() + chkHorizontal->getHeight() + DISTANCE_NEXT_Y); grpCentering->setMovable(false); - grpCentering->setSize(chkHorizontal->getX() + chkHorizontal->getWidth() + DISTANCE_BORDER * 2, posY + DISTANCE_BORDER); + grpCentering->setSize(chkHorizontal->getX() + chkHorizontal->getWidth() + DISTANCE_BORDER * 2, posY + DISTANCE_BORDER * 2); + grpCentering->setTitleBarHeight(TITLEBAR_HEIGHT); grpCentering->setBaseColor(gui_baseCol); category.panel->add(grpCentering); @@ -231,7 +233,8 @@ void InitPanelDisplay(const struct _ConfigCategory& category) grpScalingMethod->add(optLinear, 5, 70); grpScalingMethod->setMovable(false); grpScalingMethod->setSize(optNearest->getWidth() + DISTANCE_BORDER, - optLinear->getY() + optLinear->getHeight() + 30); + optLinear->getY() + optLinear->getHeight() + DISTANCE_BORDER * 3); + grpScalingMethod->setTitleBarHeight(TITLEBAR_HEIGHT); grpScalingMethod->setBaseColor(gui_baseCol); category.panel->add(grpScalingMethod); @@ -259,7 +262,8 @@ void InitPanelDisplay(const struct _ConfigCategory& category) grpLineMode->add(optScanlines, 5, 70); grpLineMode->setMovable(false); grpLineMode->setSize(optScanlines->getWidth() + DISTANCE_BORDER, - optScanlines->getY() + optScanlines->getHeight() + 30); + optScanlines->getY() + optScanlines->getHeight() + DISTANCE_BORDER * 3); + grpLineMode->setTitleBarHeight(TITLEBAR_HEIGHT); grpLineMode->setBaseColor(gui_baseCol); category.panel->add(grpLineMode); category.panel->add(chkAspect, DISTANCE_BORDER, posY); diff --git a/src/osdep/gui/PanelRAM.cpp b/src/osdep/gui/PanelRAM.cpp index 42182908..f7a9a821 100644 --- a/src/osdep/gui/PanelRAM.cpp +++ b/src/osdep/gui/PanelRAM.cpp @@ -234,7 +234,8 @@ void InitPanelRAM(const struct _ConfigCategory& category) posY += sldA3000Highmem->getHeight() + DISTANCE_NEXT_Y; grpRAM->setMovable(false); - grpRAM->setSize(400, posY + DISTANCE_BORDER); + grpRAM->setSize(400, posY + DISTANCE_BORDER * 2); + grpRAM->setTitleBarHeight(TITLEBAR_HEIGHT); grpRAM->setBaseColor(gui_baseCol); category.panel->add(grpRAM); diff --git a/src/osdep/gui/PanelSavestate.cpp b/src/osdep/gui/PanelSavestate.cpp index 882c83a2..282026f5 100644 --- a/src/osdep/gui/PanelSavestate.cpp +++ b/src/osdep/gui/PanelSavestate.cpp @@ -53,7 +53,7 @@ public: { if (strlen(savestate_fname) > 0) { - const auto f = fopen(savestate_fname, "rbe"); + auto* const f = fopen(savestate_fname, "rbe"); if (f) { fclose(f); @@ -122,12 +122,14 @@ void InitPanelSavestate(const struct _ConfigCategory& category) grpNumber->add(optState2, 5, 70); grpNumber->add(optState3, 5, 100); grpNumber->setMovable(false); - grpNumber->setSize(BUTTON_WIDTH, 145); + grpNumber->setSize(BUTTON_WIDTH, 155); + grpNumber->setTitleBarHeight(TITLEBAR_HEIGHT); grpNumber->setBaseColor(gui_baseCol); wndScreenshot = new gcn::Window("State screen"); wndScreenshot->setMovable(false); wndScreenshot->setSize(300, 300); + wndScreenshot->setTitleBarHeight(TITLEBAR_HEIGHT); wndScreenshot->setBaseColor(gui_baseCol); cmdLoadState = new gcn::Button("Load State"); diff --git a/src/osdep/gui/PanelSound.cpp b/src/osdep/gui/PanelSound.cpp index 2feba6cb..130249ae 100644 --- a/src/osdep/gui/PanelSound.cpp +++ b/src/osdep/gui/PanelSound.cpp @@ -202,20 +202,20 @@ public: else if (actionEvent.getSource() == sldSeparation) { - if (curr_separation_idx != int(sldSeparation->getValue()) + if (curr_separation_idx != static_cast(sldSeparation->getValue()) && changed_prefs.sound_stereo > 0) { - curr_separation_idx = int(sldSeparation->getValue()); + curr_separation_idx = static_cast(sldSeparation->getValue()); changed_prefs.sound_stereo_separation = 10 - curr_separation_idx; } } else if (actionEvent.getSource() == sldStereoDelay) { - if (curr_stereodelay_idx != int(sldStereoDelay->getValue()) + if (curr_stereodelay_idx != static_cast(sldStereoDelay->getValue()) && changed_prefs.sound_stereo > 0) { - curr_stereodelay_idx = int(sldStereoDelay->getValue()); + curr_stereodelay_idx = static_cast(sldStereoDelay->getValue()); if (curr_stereodelay_idx > 0) changed_prefs.sound_mixed_stereo_delay = curr_stereodelay_idx; else @@ -224,7 +224,7 @@ public: } else if (actionEvent.getSource() == sldPaulaVol) { - int newvol = 100 - int(sldPaulaVol->getValue()); + const auto newvol = 100 - static_cast(sldPaulaVol->getValue()); if (changed_prefs.sound_volume_paula != newvol) changed_prefs.sound_volume_paula = newvol; } @@ -263,6 +263,7 @@ void InitPanelSound(const struct _ConfigCategory& category) grpSound->add(optSoundEmulatedBest, 5, 100); grpSound->setMovable(false); grpSound->setSize(optSoundEmulatedBest->getWidth() + DISTANCE_BORDER, 150); + grpSound->setTitleBarHeight(TITLEBAR_HEIGHT); grpSound->setBaseColor(gui_baseCol); lblFrequency = new gcn::Label("Frequency:"); @@ -287,6 +288,7 @@ void InitPanelSound(const struct _ConfigCategory& category) grpMode->add(optStereo, 5, 40); grpMode->setMovable(false); grpMode->setSize(90, 90); + grpMode->setTitleBarHeight(TITLEBAR_HEIGHT); grpMode->setBaseColor(gui_baseCol); lblInterpolation = new gcn::Label("Interpolation:"); diff --git a/src/osdep/target.h b/src/osdep/target.h index 70bc8512..0a7a2110 100644 --- a/src/osdep/target.h +++ b/src/osdep/target.h @@ -22,8 +22,8 @@ #define GETBDM(x) (((x) - (((x) / 10000) * 10000)) / 100) #define GETBDD(x) ((x) % 100) -#define AMIBERRYVERSION _T("Amiberry v3.1.4 beta (2020-05-13)") -#define AMIBERRYDATE MAKEBD(2020, 5, 13) +#define AMIBERRYVERSION _T("Amiberry v3.1.4 beta (2020-05-15)") +#define AMIBERRYDATE MAKEBD(2020, 5, 15) extern std::string get_version_string();