From c08ab76ed11f3a520d18d9b513c186e14f2ddc6e Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Sat, 17 Aug 2019 19:26:31 +0200 Subject: [PATCH 1/4] Updated toolchain to gcc 8 --- .../Amiberry/Amiberry-Debug-dispmanx.vgdbsettings | 6 +++--- VisualGDB/Amiberry/Amiberry-Debug.vgdbsettings | 10 +++++----- .../Amiberry/Amiberry-Release-dispmanx.vgdbsettings | 6 +++--- VisualGDB/Amiberry/Amiberry-Release.vgdbsettings | 7 +++---- VisualGDB/Amiberry/Amiberry.vcxproj | 8 ++++---- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/VisualGDB/Amiberry/Amiberry-Debug-dispmanx.vgdbsettings b/VisualGDB/Amiberry/Amiberry-Debug-dispmanx.vgdbsettings index 23f4719c..2b80eae7 100644 --- a/VisualGDB/Amiberry/Amiberry-Debug-dispmanx.vgdbsettings +++ b/VisualGDB/Amiberry/Amiberry-Debug-dispmanx.vgdbsettings @@ -47,9 +47,9 @@ com.visualgdb.raspberry_pi - 6.3.0 - 7.12 - 3 + 8.3.0 + 8.2.1 + 1 Amiberry.vcxproj diff --git a/VisualGDB/Amiberry/Amiberry-Debug.vgdbsettings b/VisualGDB/Amiberry/Amiberry-Debug.vgdbsettings index 66d80145..8a2ebfb6 100644 --- a/VisualGDB/Amiberry/Amiberry-Debug.vgdbsettings +++ b/VisualGDB/Amiberry/Amiberry-Debug.vgdbsettings @@ -7,7 +7,7 @@ MinGWUnixSlash - 192.168.1.216 + 192.168.1.142 SSH pi @@ -47,9 +47,9 @@ com.visualgdb.raspberry_pi - 6.3.0 - 7.12 - 4 + 8.3.0 + 8.2.1 + 1 Amiberry.vcxproj @@ -184,7 +184,7 @@ false /home/pi/projects/amiberry/$(TargetFileName) - Remote + Local false false Auto diff --git a/VisualGDB/Amiberry/Amiberry-Release-dispmanx.vgdbsettings b/VisualGDB/Amiberry/Amiberry-Release-dispmanx.vgdbsettings index fba730e5..f2309377 100644 --- a/VisualGDB/Amiberry/Amiberry-Release-dispmanx.vgdbsettings +++ b/VisualGDB/Amiberry/Amiberry-Release-dispmanx.vgdbsettings @@ -50,9 +50,9 @@ com.visualgdb.raspberry_pi - 6.3.0 - 7.12 - 3 + 8.3.0 + 8.2.1 + 1 Amiberry.vcxproj diff --git a/VisualGDB/Amiberry/Amiberry-Release.vgdbsettings b/VisualGDB/Amiberry/Amiberry-Release.vgdbsettings index 4429cfcc..444403de 100644 --- a/VisualGDB/Amiberry/Amiberry-Release.vgdbsettings +++ b/VisualGDB/Amiberry/Amiberry-Release.vgdbsettings @@ -47,15 +47,14 @@ com.visualgdb.raspberry_pi - 6.3.0 - 7.12 - 4 + 8.3.0 + 8.2.1 + 1 Amiberry.vcxproj - 1 true diff --git a/VisualGDB/Amiberry/Amiberry.vcxproj b/VisualGDB/Amiberry/Amiberry.vcxproj index a0558f5d..5dee1b2a 100644 --- a/VisualGDB/Amiberry/Amiberry.vcxproj +++ b/VisualGDB/Amiberry/Amiberry.vcxproj @@ -38,23 +38,23 @@ Debug com.visualgdb.raspberry_pi - 6.3.0/7.12/r4 + 8.3.0/8.2.1/r1 $(ProjectName)-sdl2 Debug com.visualgdb.raspberry_pi - 6.3.0/7.12/r4 + 8.3.0/8.2.1/r1 $(ProjectName)-sdl2 com.visualgdb.raspberry_pi - 6.3.0/7.12/r4 + 8.3.0/8.2.1/r1 $(ProjectName)-sdl2 com.visualgdb.raspberry_pi - 6.3.0/7.12/r4 + 8.3.0/8.2.1/r1 $(ProjectName)-sdl2 From 40baf6ffac20801d93e3c0bf7dbb81d6a85615d4 Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Sat, 17 Aug 2019 21:20:39 +0200 Subject: [PATCH 2/4] Updated Guisan to latest version --- .../Amiberry/Amiberry-Debug.vgdbsettings | 1 - VisualGDB/Amiberry/Amiberry.vcxproj | 8 +- VisualGDB/guisan/guisan.vcxproj | 5 + VisualGDB/guisan/guisan.vcxproj.filters | 15 + guisan-dev/include/guisan.hpp | 24 +- guisan-dev/include/guisan/actionevent.hpp | 61 +- guisan-dev/include/guisan/actionlistener.hpp | 54 +- guisan-dev/include/guisan/basiccontainer.hpp | 134 +- guisan-dev/include/guisan/cliprectangle.hpp | 78 +- guisan-dev/include/guisan/color.hpp | 174 +- guisan-dev/include/guisan/deathlistener.hpp | 50 +- guisan-dev/include/guisan/defaultfont.hpp | 65 +- guisan-dev/include/guisan/event.hpp | 60 +- guisan-dev/include/guisan/exception.hpp | 145 +- guisan-dev/include/guisan/focushandler.hpp | 439 ++- guisan-dev/include/guisan/focuslistener.hpp | 63 +- guisan-dev/include/guisan/font.hpp | 105 +- guisan-dev/include/guisan/genericinput.hpp | 170 +- guisan-dev/include/guisan/glut.hpp | 11 +- guisan-dev/include/guisan/graphics.hpp | 379 ++- guisan-dev/include/guisan/gui.hpp | 565 ++-- guisan-dev/include/guisan/image.hpp | 194 +- guisan-dev/include/guisan/imagefont.hpp | 248 +- guisan-dev/include/guisan/imageloader.hpp | 51 +- guisan-dev/include/guisan/input.hpp | 97 +- guisan-dev/include/guisan/inputevent.hpp | 130 +- guisan-dev/include/guisan/key.hpp | 191 +- guisan-dev/include/guisan/keyevent.hpp | 126 +- guisan-dev/include/guisan/keyinput.hpp | 266 +- guisan-dev/include/guisan/keylistener.hpp | 90 +- guisan-dev/include/guisan/listmodel.hpp | 56 +- guisan-dev/include/guisan/mouseevent.hpp | 200 +- guisan-dev/include/guisan/mouseinput.hpp | 246 +- guisan-dev/include/guisan/mouselistener.hpp | 233 +- guisan-dev/include/guisan/opengl.hpp | 11 +- .../include/guisan/opengl/openglgraphics.hpp | 100 +- .../include/guisan/opengl/openglimage.hpp | 139 +- .../guisan/opengl/openglsdlimageloader.hpp | 65 +- guisan-dev/include/guisan/platform.hpp | 4 +- guisan-dev/include/guisan/rectangle.hpp | 92 +- guisan-dev/include/guisan/sdl.hpp | 12 +- .../include/guisan/sdl/sdl2graphics.hpp | 192 ++ guisan-dev/include/guisan/sdl/sdlgraphics.hpp | 147 +- guisan-dev/include/guisan/sdl/sdlimage.hpp | 85 +- .../include/guisan/sdl/sdlimageloader.hpp | 29 +- guisan-dev/include/guisan/sdl/sdlinput.hpp | 104 +- guisan-dev/include/guisan/sdl/sdlpixel.hpp | 342 +-- .../include/guisan/sdl/sdltruetypefont.hpp | 57 +- guisan-dev/include/guisan/selectionevent.hpp | 42 +- .../include/guisan/selectionlistener.hpp | 54 +- guisan-dev/include/guisan/widget.hpp | 1602 ++++++----- guisan-dev/include/guisan/widgetlistener.hpp | 106 +- guisan-dev/include/guisan/widgets/button.hpp | 188 +- .../include/guisan/widgets/checkbox.hpp | 187 +- .../include/guisan/widgets/container.hpp | 186 +- .../include/guisan/widgets/dropdown.hpp | 343 +-- guisan-dev/include/guisan/widgets/icon.hpp | 74 +- .../include/guisan/widgets/imagebutton.hpp | 100 +- .../guisan/widgets/imagetextbutton.hpp | 156 ++ .../include/guisan/widgets/inputbox.hpp | 144 + guisan-dev/include/guisan/widgets/label.hpp | 130 +- guisan-dev/include/guisan/widgets/listbox.hpp | 303 +-- .../include/guisan/widgets/messagebox.hpp | 247 ++ .../include/guisan/widgets/progressbar.hpp | 260 +- .../include/guisan/widgets/radiobutton.hpp | 250 +- .../include/guisan/widgets/scrollarea.hpp | 836 +++--- guisan-dev/include/guisan/widgets/slider.hpp | 327 ++- guisan-dev/include/guisan/widgets/tab.hpp | 124 +- .../include/guisan/widgets/tabbedarea.hpp | 255 +- guisan-dev/include/guisan/widgets/textbox.hpp | 314 +-- .../include/guisan/widgets/textfield.hpp | 166 +- guisan-dev/include/guisan/widgets/window.hpp | 238 +- guisan-dev/src/actionevent.cpp | 26 +- guisan-dev/src/basiccontainer.cpp | 542 ++-- guisan-dev/src/cliprectangle.cpp | 42 +- guisan-dev/src/color.cpp | 115 +- guisan-dev/src/defaultfont.cpp | 60 +- guisan-dev/src/event.cpp | 24 +- guisan-dev/src/exception.cpp | 83 +- guisan-dev/src/focushandler.cpp | 1052 +++---- guisan-dev/src/font.cpp | 27 +- guisan-dev/src/genericinput.cpp | 192 +- guisan-dev/src/graphics.cpp | 184 +- guisan-dev/src/gui.cpp | 1844 ++++++------- guisan-dev/src/guisan.cpp | 9 +- guisan-dev/src/image.cpp | 45 +- guisan-dev/src/imagefont.cpp | 400 +-- guisan-dev/src/inputevent.cpp | 75 +- guisan-dev/src/key.cpp | 54 +- guisan-dev/src/keyevent.cpp | 67 +- guisan-dev/src/keyinput.cpp | 134 +- guisan-dev/src/mouseevent.cpp | 85 +- guisan-dev/src/mouseinput.cpp | 104 +- guisan-dev/src/opengl/opengl.cpp | 5 +- guisan-dev/src/opengl/openglgraphics.cpp | 443 ++- guisan-dev/src/opengl/openglimage.cpp | 249 +- guisan-dev/src/rectangle.cpp | 122 +- guisan-dev/src/sdl/sdl.cpp | 5 +- guisan-dev/src/sdl/sdl2graphics.cpp | 479 ++++ guisan-dev/src/sdl/sdlgraphics.cpp | 1181 ++++---- guisan-dev/src/sdl/sdlimage.cpp | 241 +- guisan-dev/src/sdl/sdlimageloader.cpp | 100 +- guisan-dev/src/sdl/sdlinput.cpp | 721 ++--- guisan-dev/src/sdl/sdltruetypefont.cpp | 69 +- guisan-dev/src/selectionevent.cpp | 16 +- guisan-dev/src/widget.cpp | 1252 ++++----- guisan-dev/src/widgets/button.cpp | 425 +-- guisan-dev/src/widgets/checkbox.cpp | 250 +- guisan-dev/src/widgets/container.cpp | 134 +- guisan-dev/src/widgets/dropdown.cpp | 1112 ++++---- guisan-dev/src/widgets/icon.cpp | 92 +- guisan-dev/src/widgets/imagebutton.cpp | 172 +- guisan-dev/src/widgets/imagetextbutton.cpp | 229 ++ guisan-dev/src/widgets/inputbox.cpp | 332 +++ guisan-dev/src/widgets/label.cpp | 151 +- guisan-dev/src/widgets/listbox.cpp | 480 ++-- guisan-dev/src/widgets/messagebox.cpp | 485 ++++ guisan-dev/src/widgets/progressbar.cpp | 368 +-- guisan-dev/src/widgets/radiobutton.cpp | 441 +-- guisan-dev/src/widgets/scrollarea.cpp | 2418 ++++++++--------- guisan-dev/src/widgets/slider.cpp | 569 ++-- guisan-dev/src/widgets/tab.cpp | 181 +- guisan-dev/src/widgets/tabbedarea.cpp | 844 +++--- guisan-dev/src/widgets/textbox.cpp | 970 +++---- guisan-dev/src/widgets/textfield.cpp | 372 +-- guisan-dev/src/widgets/window.cpp | 471 ++-- 126 files changed, 17879 insertions(+), 15409 deletions(-) create mode 100644 guisan-dev/include/guisan/sdl/sdl2graphics.hpp create mode 100644 guisan-dev/include/guisan/widgets/imagetextbutton.hpp create mode 100644 guisan-dev/include/guisan/widgets/inputbox.hpp create mode 100644 guisan-dev/include/guisan/widgets/messagebox.hpp create mode 100644 guisan-dev/src/sdl/sdl2graphics.cpp create mode 100644 guisan-dev/src/widgets/imagetextbutton.cpp create mode 100644 guisan-dev/src/widgets/inputbox.cpp create mode 100644 guisan-dev/src/widgets/messagebox.cpp diff --git a/VisualGDB/Amiberry/Amiberry-Debug.vgdbsettings b/VisualGDB/Amiberry/Amiberry-Debug.vgdbsettings index 8a2ebfb6..aff9e3ff 100644 --- a/VisualGDB/Amiberry/Amiberry-Debug.vgdbsettings +++ b/VisualGDB/Amiberry/Amiberry-Debug.vgdbsettings @@ -55,7 +55,6 @@ Amiberry.vcxproj - 1 true diff --git a/VisualGDB/Amiberry/Amiberry.vcxproj b/VisualGDB/Amiberry/Amiberry.vcxproj index 5dee1b2a..2e110765 100644 --- a/VisualGDB/Amiberry/Amiberry.vcxproj +++ b/VisualGDB/Amiberry/Amiberry.vcxproj @@ -60,7 +60,7 @@ GNUPP14 - =/usr/local/include/SDL2;=/usr/include/libxml2;../../src;../../src/osdep;../../src/threaddep;../../src/include;../../guisan-dev/include;../../src/archivers;%(ClCompile.AdditionalIncludeDirectories) + =/usr/local/include/SDL2;=/usr/include/libxml2;../../src;../../src/osdep;../../src/threaddep;../../src/include;../../guisan-dev/include;../../src/archivers;=/usr/include/SDL2;%(ClCompile.AdditionalIncludeDirectories) DEBUG=1;ARMV6T2;USE_ARMNEON;ARM_HAS_DIV;_REENTRANT;AMIBERRY;CPU_arm;ARMV6_ASSEMBLY;USE_SDL2;_FILE_OFFSET_BITS=64;%(ClCompile.PreprocessorDefinitions) -march=armv8-a -mfpu=neon-fp-armv8 -mfloat-abi=hard -march=armv8-a -mfpu=neon-fp-armv8 -mfloat-abi=hard @@ -75,7 +75,7 @@ GNUPP14 - =/usr/local/include/SDL2;=/usr/include/libxml2;../../src;../../src/osdep;../../src/threaddep;../../src/include;../../guisan-dev/include;../../src/archivers;=/opt/vc/include;=/opt/vc/include/interface/vmcs_host/linux;=/opt/vc/include/interface/vcos/pthreads;%(ClCompile.AdditionalIncludeDirectories) + =/usr/local/include/SDL2;=/usr/include/libxml2;../../src;../../src/osdep;../../src/threaddep;../../src/include;../../guisan-dev/include;../../src/archivers;=/opt/vc/include;=/opt/vc/include/interface/vmcs_host/linux;=/opt/vc/include/interface/vcos/pthreads;=/usr/include/SDL2;%(ClCompile.AdditionalIncludeDirectories) DEBUG=1;ARMV6T2;USE_ARMNEON;ARM_HAS_DIV;_REENTRANT;AMIBERRY;CPU_arm;ARMV6_ASSEMBLY;USE_SDL2;USE_DISPMANX;_FILE_OFFSET_BITS=64;%(ClCompile.PreprocessorDefinitions) -march=armv8-a -mfpu=neon-fp-armv8 -mfloat-abi=hard -march=armv8-a -mfpu=neon-fp-armv8 -mfloat-abi=hard @@ -91,7 +91,7 @@ GNUPP14 - =/usr/local/include/SDL2;=/usr/include/libxml2;../../src;../../src/osdep;../../src/threaddep;../../src/include;../../guisan-dev/include;../../src/archivers;%(ClCompile.AdditionalIncludeDirectories) + =/usr/local/include/SDL2;=/usr/include/libxml2;../../src;../../src/osdep;../../src/threaddep;../../src/include;../../guisan-dev/include;../../src/archivers;=/usr/include/SDL2;%(ClCompile.AdditionalIncludeDirectories) NDEBUG=1;RELEASE=1;ARMV6T2;USE_ARMNEON;ARM_HAS_DIV;_REENTRANT;AMIBERRY;CPU_arm;ARMV6_ASSEMBLY;USE_SDL2;_FILE_OFFSET_BITS=64;%(ClCompile.PreprocessorDefinitions) -march=armv8-a -mfpu=neon-fp-armv8 -mfloat-abi=hard -march=armv8-a -mfpu=neon-fp-armv8 -mfloat-abi=hard @@ -108,7 +108,7 @@ GNUPP14 - =/usr/local/include/SDL2;=/usr/include/libxml2;../../src;../../src/osdep;../../src/threaddep;../../src/include;../../guisan-dev/include;../../src/archivers;=/opt/vc/include;=/opt/vc/include/interface/vmcs_host/linux;=/opt/vc/include/interface/vcos/pthreads;%(ClCompile.AdditionalIncludeDirectories) + =/usr/include/libxml2;../../src;../../src/osdep;../../src/threaddep;../../src/include;../../guisan-dev/include;../../src/archivers;=/opt/vc/include;=/opt/vc/include/interface/vmcs_host/linux;=/usr/local/include/SDL2;=/opt/vc/include/interface/vcos/pthreads;=/usr/include/SDL2;%(ClCompile.AdditionalIncludeDirectories) NDEBUG=1;RELEASE=1;ARMV6T2;USE_ARMNEON;ARM_HAS_DIV;_REENTRANT;AMIBERRY;CPU_arm;ARMV6_ASSEMBLY;USE_SDL2;USE_DISPMANX;_FILE_OFFSET_BITS=64;%(ClCompile.PreprocessorDefinitions) -march=armv8-a -mfpu=neon-fp-armv8 -mfloat-abi=hard -march=armv8-a -mfpu=neon-fp-armv8 -mfloat-abi=hard diff --git a/VisualGDB/guisan/guisan.vcxproj b/VisualGDB/guisan/guisan.vcxproj index 3da864b2..c41d52f2 100644 --- a/VisualGDB/guisan/guisan.vcxproj +++ b/VisualGDB/guisan/guisan.vcxproj @@ -95,6 +95,7 @@ + @@ -165,6 +166,7 @@ + @@ -181,8 +183,11 @@ + + + diff --git a/VisualGDB/guisan/guisan.vcxproj.filters b/VisualGDB/guisan/guisan.vcxproj.filters index aad1f869..c65b9cfa 100644 --- a/VisualGDB/guisan/guisan.vcxproj.filters +++ b/VisualGDB/guisan/guisan.vcxproj.filters @@ -196,6 +196,9 @@ Source files\widgets + + Source files\sdl + @@ -393,5 +396,17 @@ Header files\guisan\widgets + + Header files\guisan\sdl + + + Header files\guisan\widgets + + + Header files\guisan\widgets + + + Header files\guisan\widgets + \ No newline at end of file diff --git a/guisan-dev/include/guisan.hpp b/guisan-dev/include/guisan.hpp index d446fafe..6d560028 100644 --- a/guisan-dev/include/guisan.hpp +++ b/guisan-dev/include/guisan.hpp @@ -6,11 +6,11 @@ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * - * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson + * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson * * Js_./ * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// + * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// * _Qhm`] _f "'c 1!5m * Visit: http://guichan.darkbits.org )Qk

#include #include +#include +#include #include #include +#include #include #include #include @@ -111,14 +114,15 @@ 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/guisan-dev/include/guisan/actionevent.hpp b/guisan-dev/include/guisan/actionevent.hpp index 3c8ee075..52a4319c 100644 --- a/guisan-dev/include/guisan/actionevent.hpp +++ b/guisan-dev/include/guisan/actionevent.hpp @@ -64,41 +64,42 @@ 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, const 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. + */ + const std::string& getId() const; - protected: - std::string mId; - }; + protected: + std::string mId; + }; } #endif // GCN_ACTIONEVENT_HPP + diff --git a/guisan-dev/include/guisan/actionlistener.hpp b/guisan-dev/include/guisan/actionlistener.hpp index 0eaee1a7..eff7e9ed 100644 --- a/guisan-dev/include/guisan/actionlistener.hpp +++ b/guisan-dev/include/guisan/actionlistener.hpp @@ -64,35 +64,35 @@ namespace gcn { - /** - * Listener of action events from Widgets. To be able to - * listen for actions you must make a class which inherits - * from this class and implements the action function. - * - * @see Widget::addActionListener - * @author Olof Naessén - * @author Per Larsson - */ - class GCN_CORE_DECLSPEC ActionListener - { - public: + /** + * Listener of action events from Widgets. To be able to + * listen for actions you must make a class which inherits + * from this class and implements the action function. + * + * @see Widget::addActionListener + * @author Olof Naessén + * @author Per Larsson + */ + class GCN_CORE_DECLSPEC ActionListener + { + public: - /** - * Destructor. - */ - virtual ~ActionListener() - = default; + /** + * Destructor. + */ + virtual ~ActionListener() { } - /** - * Called when an action is recieved from a Widget. It is used - * to be able to recieve a notification that an action has - * occured. - * - * @param actionEvent the event of the action. - * @since 0.6.0 - */ - virtual void action(const ActionEvent& actionEvent) = 0; - }; + /** + * Called when an action is recieved from a Widget. It is used + * to be able to recieve a notification that an action has + * occured. + * + * @param actionEvent the event of the action. + * @since 0.6.0 + */ + virtual void action(const ActionEvent& actionEvent) = 0; + + }; } #endif // end GCN_ACTIONLISTENER_HPP diff --git a/guisan-dev/include/guisan/basiccontainer.hpp b/guisan-dev/include/guisan/basiccontainer.hpp index 166d29e8..6c12c6ba 100644 --- a/guisan-dev/include/guisan/basiccontainer.hpp +++ b/guisan-dev/include/guisan/basiccontainer.hpp @@ -65,95 +65,95 @@ namespace gcn { - /** - * Implements basic container behaviour. Most container will suffice by - * inheriting from this class. - * - * @see Container - */ - class GCN_CORE_DECLSPEC BasicContainer : public Widget, public DeathListener - { - public: - /** - * Destructor - */ - virtual ~BasicContainer(); + /** + * Implements basic container behaviour. Most container will suffice by + * inheriting from this class. + * + * @see Container + */ + class GCN_CORE_DECLSPEC BasicContainer : public Widget, public DeathListener + { + public: + /** + * Destructor + */ + virtual ~BasicContainer(); - // Inherited from Widget + // Inherited from Widget - void moveToTop(Widget* widget) override; + virtual void moveToTop(Widget* widget); - void moveToBottom(Widget* widget) override; + virtual void moveToBottom(Widget* widget); - Rectangle getChildrenArea() override; + virtual Rectangle getChildrenArea(); - void focusNext() override; + virtual void focusNext(); - void focusPrevious() override; + virtual void focusPrevious(); - void logic() override; + virtual void logic(); - void _setFocusHandler(FocusHandler* focusHandler) override; + virtual void _setFocusHandler(FocusHandler* focusHandler); - void setInternalFocusHandler(FocusHandler* focusHandler) override; + void setInternalFocusHandler(FocusHandler* focusHandler); - void showWidgetPart(Widget* widget, Rectangle area) override; + virtual void showWidgetPart(Widget* widget, Rectangle area); - Widget* getWidgetAt(int x, int y) override; + virtual Widget *getWidgetAt(int x, int y); - // Inherited from DeathListener + // Inherited from DeathListener - void death(const Event& event) override; + virtual void death(const Event& event); - protected: - /** - * Adds a widget to the basic container. - * - * @param widget the widget to add. - */ - virtual void add(Widget* widget); + protected: + /** + * Adds a widget to the basic container. + * + * @param widget the widget to add. + */ + void add(Widget* widget); - /** - * Removes a widget from the basic container. - * - * @param widget the widget to remove. - */ - virtual void remove(Widget* widget); + /** + * Removes a widget from the basic container. + * + * @param widget the widget to remove. + */ + virtual void remove(Widget* widget); - /** - * Clears the basic container from all widgets. - */ - virtual void clear(); + /** + * Clears the basic container from all widgets. + */ + virtual void clear(); + + /** + * Draws children widgets. + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawChildren(Graphics* graphics); - /** - * Draws children widgets. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawChildren(Graphics* graphics); + /** + * Calls logic for children widgets. + */ + virtual void logicChildren(); - /** - * Calls logic for children widgets. - */ - virtual void logicChildren(); + /** + * 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. + */ + virtual Widget* findWidgetById(const std::string& id); - /** - * 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. - */ - virtual Widget* findWidgetById(const std::string& id); + typedef std::list WidgetList; + typedef WidgetList::iterator WidgetListIterator; + typedef WidgetList::reverse_iterator WidgetListReverseIterator; - typedef std::list WidgetList; - typedef WidgetList::iterator WidgetListIterator; - typedef WidgetList::reverse_iterator WidgetListReverseIterator; - - WidgetList mWidgets; - }; + WidgetList mWidgets; + }; } #endif // end GCN_BASICCONTAINER_HPP diff --git a/guisan-dev/include/guisan/cliprectangle.hpp b/guisan-dev/include/guisan/cliprectangle.hpp index 421bbfa8..dc1190a5 100644 --- a/guisan-dev/include/guisan/cliprectangle.hpp +++ b/guisan-dev/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/guisan-dev/include/guisan/color.hpp b/guisan-dev/include/guisan/color.hpp index ae80e281..db6bc767 100644 --- a/guisan-dev/include/guisan/color.hpp +++ b/guisan-dev/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 ar, int ag, int ab, int aa = 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/guisan-dev/include/guisan/deathlistener.hpp b/guisan-dev/include/guisan/deathlistener.hpp index 34dc879e..8b9bcec9 100644 --- a/guisan-dev/include/guisan/deathlistener.hpp +++ b/guisan-dev/include/guisan/deathlistener.hpp @@ -64,33 +64,33 @@ 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() - = default; + /** + * Destructor. + */ + virtual ~DeathListener() { } - /** - * 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 recieve + * 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/guisan-dev/include/guisan/defaultfont.hpp b/guisan-dev/include/guisan/defaultfont.hpp index 71638967..544ae0f8 100644 --- a/guisan-dev/include/guisan/defaultfont.hpp +++ b/guisan-dev/include/guisan/defaultfont.hpp @@ -62,47 +62,46 @@ 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() - = default; + /** + * Destructor. + */ + virtual ~DefaultFont(){} - /** - * 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 - void drawString(Graphics* graphics, const std::string& text, int x, int y) override; + virtual void drawString(Graphics* graphics, const std::string& text, int x, int y); - int getWidth(const std::string& text) const override; + virtual int getWidth(const std::string& text) const; - int getHeight() const override; + virtual int getHeight() const; - int getStringIndexAt(const std::string& text, int x) override; - }; + virtual int getStringIndexAt(const std::string& text, int x); + }; } #endif // end GCN_DEFAULTFONT_HPP diff --git a/guisan-dev/include/guisan/event.hpp b/guisan-dev/include/guisan/event.hpp index 095583b3..9d4b8ab2 100644 --- a/guisan-dev/include/guisan/event.hpp +++ b/guisan-dev/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. + */ + Widget* getSource() const; - protected: - Widget* mSource; - unsigned int mType; - }; + protected: + Widget* mSource; + unsigned int mType; + }; } #endif // end GCN_EVENT_HPP diff --git a/guisan-dev/include/guisan/exception.hpp b/guisan-dev/include/guisan/exception.hpp index e931d2b5..243d8f1d 100644 --- a/guisan-dev/include/guisan/exception.hpp +++ b/guisan-dev/include/guisan/exception.hpp @@ -62,8 +62,8 @@ #include "guisan/platform.hpp" -#ifdef _MSC_VER_ -#if _MSC_VER_ <= 1200 +#ifdef _MSC_VER +#if _MSC_VER <= 1200 #define __FUNCTION__ "?" #endif #endif @@ -81,84 +81,85 @@ 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: - /** - * Constructor. - */ - Exception(); + /** + * 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. - * - * @param message the error message. - */ - Exception(const std::string& message); + /** + * Constructor. + */ + Exception(); - /** - * 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); + /** + * Constructor. + * + * @param message the error message. + */ + Exception(const std::string& message); - /** - * 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; + /** + * 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 error message of the exception. - * - * @return the error message. - */ - const std::string& getMessage() 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 filename in which the exceptions was thrown. - * - * @return the filename in which the exception was thrown. - */ - const std::string& getFilename() const; + /** + * Gets the error message of the exception. + * + * @return the error message. + */ + const std::string& getMessage() 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; + /** + * Gets the filename in which the exceptions was thrown. + * + * @return the filename in which the exception was thrown. + */ + const std::string& getFilename() const; - protected: - std::string mFunction; - std::string mMessage; - std::string mFilename; - int mLine; - }; + /** + * 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; + }; } #endif // end GCN_EXCEPTION_HPP diff --git a/guisan-dev/include/guisan/focushandler.hpp b/guisan-dev/include/guisan/focushandler.hpp index 407fe195..f9fdd90b 100644 --- a/guisan-dev/include/guisan/focushandler.hpp +++ b/guisan-dev/include/guisan/focushandler.hpp @@ -64,260 +64,259 @@ 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() - = default;; + /** + * Destructor. + */ + virtual ~FocusHandler() { }; - /** - * 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. + */ + 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. + */ + 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. + */ + 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 lastWidgetWithModalMouseInputFocus the last widget with modal mouse input focus. - */ - virtual void setLastWidgetWithModalMouseInputFocus(Widget* lastWidgetWithModalMouseInputFocus); + /** + * Sets the last widget with modal mouse input focus. + * + * @param lastMouseWithModalMouseInputFocus 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/guisan-dev/include/guisan/focuslistener.hpp b/guisan-dev/include/guisan/focuslistener.hpp index 7c23c239..e57a8e87 100644 --- a/guisan-dev/include/guisan/focuslistener.hpp +++ b/guisan-dev/include/guisan/focuslistener.hpp @@ -64,43 +64,38 @@ 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() - = default; + /** + * Destructor. + */ + virtual ~FocusListener() { } - /** - * 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 discribes 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/guisan-dev/include/guisan/font.hpp b/guisan-dev/include/guisan/font.hpp index 96728ac5..7ea02cd2 100644 --- a/guisan-dev/include/guisan/font.hpp +++ b/guisan-dev/include/guisan/font.hpp @@ -62,65 +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() - = default; + /** + * Destructor. + */ + virtual ~Font(){ } - /** - * 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. + */ + 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. + */ + 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/guisan-dev/include/guisan/genericinput.hpp b/guisan-dev/include/guisan/genericinput.hpp index 04bbca27..54e28d1a 100644 --- a/guisan-dev/include/guisan/genericinput.hpp +++ b/guisan-dev/include/guisan/genericinput.hpp @@ -66,103 +66,103 @@ namespace gcn { - class Key; + class Key; + + /** + * Generic input which can be used with any backend. + */ + class GCN_CORE_DECLSPEC GenericInput: public Input + { + public: - /** - * Generic input which can be used with any backend. - */ - class GCN_CORE_DECLSPEC GenericInput : public Input - { - public: + /** + * Constructor. + */ + GenericInput(); - /** - * Constructor. - */ - GenericInput(); + /** + * 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 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 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 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 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 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 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 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); + + // Inherited from Input - /** - * 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 bool isKeyQueueEmpty(); - /** - * 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 KeyInput dequeueKeyInput(); - /** - * 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 bool isMouseQueueEmpty(); + virtual MouseInput dequeueMouseInput(); - // Inherited from Input + virtual void _pollInput(); - bool isKeyQueueEmpty() override; - - KeyInput dequeueKeyInput() override; - - bool isMouseQueueEmpty() override; - - MouseInput dequeueMouseInput() override; - - void _pollInput() override; - - protected: - std::queue mKeyInputQueue; - std::queue mMouseInputQueue; - }; + protected: + std::queue mKeyInputQueue; + std::queue mMouseInputQueue; + }; } #endif // end GCN_INPUT_HPP diff --git a/guisan-dev/include/guisan/glut.hpp b/guisan-dev/include/guisan/glut.hpp index 40a9da8e..59c5647d 100644 --- a/guisan-dev/include/guisan/glut.hpp +++ b/guisan-dev/include/guisan/glut.hpp @@ -61,11 +61,12 @@ #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/guisan-dev/include/guisan/graphics.hpp b/guisan-dev/include/guisan/graphics.hpp index e6866f31..b673dbd8 100644 --- a/guisan-dev/include/guisan/graphics.hpp +++ b/guisan-dev/include/guisan/graphics.hpp @@ -65,215 +65,209 @@ 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() - = default; + virtual ~Graphics() { } - /** - * 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); + /** + * 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 + }; - /** - * Alignments for text drawing. - */ - enum - { - LEFT = 0, - CENTER, - RIGHT - }; - - protected: - std::stack mClipStack; - Font* mFont; - }; + protected: + std::stack mClipStack; + Font* mFont; + }; } #endif // end GCN_GRAPHICS_HPP @@ -283,3 +277,4 @@ namespace gcn * finalman - "skall jag skriva det?" * yakslem - "ja, varfor inte?" */ + diff --git a/guisan-dev/include/guisan/gui.hpp b/guisan-dev/include/guisan/gui.hpp index bc620eb3..5323173e 100644 --- a/guisan-dev/include/guisan/gui.hpp +++ b/guisan-dev/include/guisan/gui.hpp @@ -67,330 +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. + */ + 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. + */ + 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. + */ + 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 source - * @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 force 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; + KeyListenerList mKeyListeners; + + // Current input state + bool mShiftPressed; + bool mMetaPressed; + bool mControlPressed; + bool mAltPressed; - // Current input state - bool mShiftPressed; - bool mMetaPressed; - bool mControlPressed; - bool mAltPressed; + // Last mouse state + unsigned int mLastMousePressButton; + int mLastMousePressTimeStamp; + int mLastMouseX; + int mLastMouseY; + int mClickCount; + int mLastMouseDragButton; - // Last mouse state - unsigned int mLastMousePressButton; - int mLastMousePressTimeStamp; - int mLastMouseX; - int mLastMouseY; - int mClickCount; - int mLastMouseDragButton; - - // Widget with mouse stack - std::deque mWidgetWithMouseQueue; - }; + // Widget with mouse stack + std::deque mWidgetWithMouseQueue; + }; } #endif // end GCN_GUI_HPP diff --git a/guisan-dev/include/guisan/image.hpp b/guisan-dev/include/guisan/image.hpp index 34fed249..37244130 100644 --- a/guisan-dev/include/guisan/image.hpp +++ b/guisan-dev/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 + */ + 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 + */ + 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/guisan-dev/include/guisan/imagefont.hpp b/guisan-dev/include/guisan/imagefont.hpp index e04d88b8..fb148b08 100644 --- a/guisan-dev/include/guisan/imagefont.hpp +++ b/guisan-dev/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. + */ + 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 + */ + virtual int getWidth(unsigned char glyph) const; - // Inherited from Font + // Inherited from Font - int getWidth(const std::string& text) const override; + virtual int getWidth(const std::string& text) const; - void drawString(Graphics* graphics, const std::string& text, - int x, int y) override; + virtual void drawString(Graphics* graphics, const std::string& text, + int x, int y); - int getHeight() const override; + virtual int getHeight() const; - int getStringIndexAt(const std::string& text, int x) override; + virtual int getStringIndexAt(const std::string& text, int x); - 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/guisan-dev/include/guisan/imageloader.hpp b/guisan-dev/include/guisan/imageloader.hpp index 95d575c4..a53c9b19 100644 --- a/guisan-dev/include/guisan/imageloader.hpp +++ b/guisan-dev/include/guisan/imageloader.hpp @@ -63,35 +63,34 @@ 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() - = default; + /** + * Destructor. + */ + virtual ~ImageLoader() { } - /** - * 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/guisan-dev/include/guisan/input.hpp b/guisan-dev/include/guisan/input.hpp index 2554bfec..33b15b99 100644 --- a/guisan-dev/include/guisan/input.hpp +++ b/guisan-dev/include/guisan/input.hpp @@ -61,62 +61,61 @@ 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() - = default; + /** + * Destructor. + */ + virtual ~Input(){ } - /** - * 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/guisan-dev/include/guisan/inputevent.hpp b/guisan-dev/include/guisan/inputevent.hpp index a66eb1dd..abee29f5 100644 --- a/guisan-dev/include/guisan/inputevent.hpp +++ b/guisan-dev/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. + */ + 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. + */ + 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. + */ + 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. + */ + 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. + */ + 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/guisan-dev/include/guisan/key.hpp b/guisan-dev/include/guisan/key.hpp index 28067ebd..1af2ff1f 100644 --- a/guisan-dev/include/guisan/key.hpp +++ b/guisan-dev/include/guisan/key.hpp @@ -61,105 +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. + */ + 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). + */ + 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). + */ + 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. + */ + int getValue() 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 - }; + /** + * Gets the char value of the key if available. + * + * @return the char value of the key, the null character otherwise + */ + char getChar() const; - protected: - int mValue; - }; + /** + * 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; + }; } #endif // end GCN_KEY_HPP diff --git a/guisan-dev/include/guisan/keyevent.hpp b/guisan-dev/include/guisan/keyevent.hpp index 71590c44..2629b2bb 100644 --- a/guisan-dev/include/guisan/keyevent.hpp +++ b/guisan-dev/include/guisan/keyevent.hpp @@ -63,77 +63,77 @@ namespace gcn { - class Widget; + class Widget; - /** - * Key event. - */ - class GCN_CORE_DECLSPEC KeyEvent : public InputEvent - { - public: + /** + * Key event. + */ + class GCN_CORE_DECLSPEC KeyEvent: 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 type the type of the event. - * @param isNumericPad true if the event occured on the numeric pad, - * false otherwise. - * @param key represents the key of the event. - */ - KeyEvent(Widget* source, - bool isShiftPressed, - bool isControlPressed, - bool isAltPressed, - bool isMetaPressed, - unsigned int type, - bool isNumericPad, - const Key& key); + /** + * 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 type the type of the event. + * @param isNumericPad true if the event occured on the numeric pad, + * false otherwise. + * @param key represents the key of the event. + */ + KeyEvent(Widget* source, + bool isShiftPressed, + bool isControlPressed, + bool isAltPressed, + bool isMetaPressed, + unsigned int type, + bool isNumericPad, + const Key& key); - /** - * Destructor. - */ - virtual ~KeyEvent(); + /** + * Destructor. + */ + virtual ~KeyEvent(); - /** - * 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. + */ + 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; + /** + * Checks whether the key event occured on the numeric pad. + * + * @return true if key event occured on the numeric pad. + */ + bool isNumericPad() const; - /** - * Gets the key of the event. - * - * @return the key of the event. - */ - const Key& getKey() const; + /** + * Gets the key of the event. + * + * @return the key of the event. + */ + const Key& getKey() const; - /** - * Key event types. - */ - enum - { - PRESSED = 0, - RELEASED - }; + /** + * Key event types. + */ + enum + { + PRESSED = 0, + RELEASED + }; - protected: - unsigned int mType; - bool mIsNumericPad; - Key mKey; - }; + protected: + unsigned int mType; + bool mIsNumericPad; + Key mKey; + }; } #endif // end GCN_KEYEVENT_HPP diff --git a/guisan-dev/include/guisan/keyinput.hpp b/guisan-dev/include/guisan/keyinput.hpp index 182d590d..477c3aa8 100644 --- a/guisan-dev/include/guisan/keyinput.hpp +++ b/guisan-dev/include/guisan/keyinput.hpp @@ -62,159 +62,155 @@ 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(): mType(0), mButton(0), mShiftPressed(false), mControlPressed(false), mAltPressed(false), - mMetaPressed(false), mNumericPad(false) - { - } - ; + /** + * Constructor. + */ + KeyInput() { }; - /** - * 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. + */ + 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. + */ + 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 + */ + 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 + */ + 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 + */ + 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 + */ + 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 + */ + 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/guisan-dev/include/guisan/keylistener.hpp b/guisan-dev/include/guisan/keylistener.hpp index 66084057..92c5b28e 100644 --- a/guisan-dev/include/guisan/keylistener.hpp +++ b/guisan-dev/include/guisan/keylistener.hpp @@ -62,59 +62,53 @@ 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() - = default; + /** + * Destructor + */ + virtual ~KeyListener() { } - /** - * 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() - = default; - }; + 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() { } + }; } #endif // end GCN_KEYLISTENER_HPP diff --git a/guisan-dev/include/guisan/listmodel.hpp b/guisan-dev/include/guisan/listmodel.hpp index be6478e7..ebedfff7 100644 --- a/guisan-dev/include/guisan/listmodel.hpp +++ b/guisan-dev/include/guisan/listmodel.hpp @@ -63,36 +63,36 @@ namespace gcn { - /** - * Represents a list. It is used in certain Widgets, like the ListBox, to - * handle a list with string elements. If you want to use Widgets like - * ListBox, you should inherit from this class and implement it's - * functions. - */ - class GCN_CORE_DECLSPEC ListModel - { - public: - /** - * Destructor. - */ - virtual ~ListModel() - = default; + /** + * Represents a list. It is used in certain Widgets, like the ListBox, to + * handle a list with string elements. If you want to use Widgets like + * ListBox, you should inherit from this class and implement it's + * functions. + */ + class GCN_CORE_DECLSPEC ListModel + { - /** - * Gets the number of elements in the ListModel. - * - * @return the number of elements in the ListModel - */ - virtual int getNumberOfElements() = 0; + public: + /** + * Destructor. + */ + virtual ~ListModel() { } - /** - * Gets an element at a certain index in the list. - * - * @param i an index in the list. - * @return an element as a string. - */ - virtual std::string getElementAt(int i) = 0; - }; + /** + * Gets the number of elements in the ListModel. + * + * @return the number of elements in the ListModel + */ + virtual int getNumberOfElements() = 0; + + /** + * Gets an element at a certain index in the list. + * + * @param i an index in the list. + * @return an element as a string. + */ + virtual std::string getElementAt(int i) = 0; + }; } #endif // end GCN_LISTMODEL_HPP diff --git a/guisan-dev/include/guisan/mouseevent.hpp b/guisan-dev/include/guisan/mouseevent.hpp index 238a9af0..e0ed0db2 100644 --- a/guisan-dev/include/guisan/mouseevent.hpp +++ b/guisan-dev/include/guisan/mouseevent.hpp @@ -62,117 +62,117 @@ 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 type the type of the event. - * @param button the button of the event. - * @param clickCount - * @param x the x coordinate of the event relative to the source widget. - * @param y 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. + */ + 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. + */ + 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. + */ + 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. + */ + 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. + */ + 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 - }; + }; - protected: - unsigned int mType; - unsigned int mButton; - int mX; - int mY; - int mClickCount; + /** + * Mouse button types. + */ + enum + { + EMPTY = 0, + LEFT, + RIGHT, + MIDDLE + }; - friend class Gui; - }; + protected: + unsigned int mType; + unsigned int mButton; + int mX; + int mY; + int mClickCount; + + friend class Gui; + }; } #endif // GCN_MOUSEEVENT_HPP diff --git a/guisan-dev/include/guisan/mouseinput.hpp b/guisan-dev/include/guisan/mouseinput.hpp index 68289516..2d9fef12 100644 --- a/guisan-dev/include/guisan/mouseinput.hpp +++ b/guisan-dev/include/guisan/mouseinput.hpp @@ -61,145 +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: - /** - * Constructor. - */ - MouseInput(): mType(0), mButton(0), mTimeStamp(0), mX(0), mY(0) - { - } - ; + /** + * 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. - * - * @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. + */ + MouseInput() { }; - /** - * Sets the input type. - * - * @param type the type of input. - */ - void setType(unsigned int type); + /** + * 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); - /** - * Gets the input type. - * - * @return the input type. - */ - unsigned int getType() const; + /** + * Sets the input type. + * + * @param type the type of input. + */ + void setType(unsigned int type); - /** - * Sets the button pressed. - * - * @param button the button pressed. - */ - void setButton(unsigned int button); + /** + * Gets the input type. + * + * @return the input type. + */ + unsigned int getType() const; - /** - * Gets the button pressed. - * - * @return the button pressed. - */ - unsigned int getButton() const; + /** + * Sets the button pressed. + * + * @param button the button pressed. + */ + void setButton(unsigned int button); - /** - * Sets the timestamp for the input. - * - * @param timeStamp the timestamp of the input. - */ - void setTimeStamp(int timeStamp); + /** + * Gets the button pressed. + * + * @return the button pressed. + */ + unsigned int getButton() const; - /** - * Gets the time stamp of the input. - * - * @return the time stamp of the input. - */ - int getTimeStamp() const; + /** + * Sets the timestamp for the input. + * + * @param timeStamp the timestamp of the input. + */ + void setTimeStamp(int timeStamp); - /** - * 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 time stamp of the input. + * + * @return the time stamp of the input. + */ + int getTimeStamp() const; - /** - * Gets the x coordinate of the input. - * - * @return the x coordinate of the input. - * @since 0.6.0 - */ - int getX() 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 y coordinate of the input. - * - * @param y the y coordinate of the input. - * @since 0.6.0 - */ - void setY(int y); + /** + * Gets the x coordinate of the input. + * + * @return the x coordinate of the input. + * @since 0.6.0 + */ + int getX() const; - /** - * Gets the y coordinate of the input. - * @since 0.6.0 - */ - int getY() const; + /** + * Sets the y coordinate of the input. + * + * @param y the y coordinate of the input. + * @since 0.6.0 + */ + void setY(int y); - /** - * 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 - }; + /** + * Gets the y coordinate of the input. + * @since 0.6.0 + */ + int getY() const; - /** - * Mouse button types. - */ - enum - { - EMPTY = 0, - LEFT, - RIGHT, - MIDDLE - }; + /** + * 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 + }; - protected: - unsigned int mType; - unsigned int mButton; - int mTimeStamp; - int mX; - int mY; - }; + /** + * Mouse button types. + */ + enum + { + EMPTY = 0, + LEFT, + RIGHT, + MIDDLE + }; + + protected: + unsigned int mType; + unsigned int mButton; + int mTimeStamp; + int mX; + int mY; + }; } #endif // end GCN_MOUSEINPUT_HPP diff --git a/guisan-dev/include/guisan/mouselistener.hpp b/guisan-dev/include/guisan/mouselistener.hpp index 42c547a0..69bfd821 100644 --- a/guisan-dev/include/guisan/mouselistener.hpp +++ b/guisan-dev/include/guisan/mouselistener.hpp @@ -62,130 +62,137 @@ 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() - = default; + /** + * Destructor. + */ + virtual ~MouseListener() { } - /** - * 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 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 the mouse has exited the widget area. + * + * @param mouseEvent describes the event. + */ + virtual void mouseExited(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 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 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 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 a mouse button has been released on the widget area. + * + * @param mouseEvent describes the event. + */ + virtual void mouseReleased(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) - { - } + /** + * 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) + { - 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; - }; + } + + /** + * 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() { } + }; } #endif // end GCN_MOUSELISTENER_HPP diff --git a/guisan-dev/include/guisan/opengl.hpp b/guisan-dev/include/guisan/opengl.hpp index f116958d..d2879dc7 100644 --- a/guisan-dev/include/guisan/opengl.hpp +++ b/guisan-dev/include/guisan/opengl.hpp @@ -62,11 +62,12 @@ #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/guisan-dev/include/guisan/opengl/openglgraphics.hpp b/guisan-dev/include/guisan/opengl/openglgraphics.hpp index a1305481..0456234f 100644 --- a/guisan-dev/include/guisan/opengl/openglgraphics.hpp +++ b/guisan-dev/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. + /** + * Constructor. + */ + OpenGLGraphics(); + + /** + * Constructor. + * + * @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. */ - OpenGLGraphics(); - - /** - * Constructor. - * - * @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. - */ - OpenGLGraphics(int width, int height); + OpenGLGraphics(int width, int height); /** * Destructor. */ - virtual ~OpenGLGraphics(); + virtual ~OpenGLGraphics(); - /** - * 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); + /** + * 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); // Inherited from Graphics - void _beginDraw() override; + virtual void _beginDraw(); - void _endDraw() override; + virtual void _endDraw(); - bool pushClipArea(Rectangle area) override; + virtual bool pushClipArea(Rectangle area); - void popClipArea() override; + virtual void popClipArea(); - void drawImage(const Image* image, int srcX, int srcY, - int dstX, int dstY, int width, - int height) override; + virtual void drawImage(const Image* image, int srcX, int srcY, + int dstX, int dstY, int width, + int height); - void drawPoint(int x, int y) override; + virtual void drawPoint(int x, int y); - void drawLine(int x1, int y1, int x2, int y2) override; + virtual void drawLine(int x1, int y1, int x2, int y2); - void drawRectangle(const Rectangle& rectangle) override; + virtual void drawRectangle(const Rectangle& rectangle); - void fillRectangle(const Rectangle& rectangle) override; + virtual void fillRectangle(const Rectangle& rectangle); - void setColor(const Color& color) override; + virtual void setColor(const Color& color); - const Color& getColor() override; + virtual const Color& getColor(); - protected: - int mWidth{}, mHeight{}; - bool mAlpha{}; - Color mColor; - }; + protected: + int mWidth, mHeight; + bool mAlpha; + Color mColor; + }; } #endif // end GCN_OPENGLGRAPHICS_HPP diff --git a/guisan-dev/include/guisan/opengl/openglimage.hpp b/guisan-dev/include/guisan/opengl/openglimage.hpp index 91cedf0c..19a1a7f1 100644 --- a/guisan-dev/include/guisan/opengl/openglimage.hpp +++ b/guisan-dev/include/guisan/opengl/openglimage.hpp @@ -68,7 +68,7 @@ #if defined (__APPLE__) #include #else -#include +#include #endif #include @@ -79,92 +79,93 @@ 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 - * 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. + /** + * 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); + + /** + * 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 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); + * @param autoFree true if the surface should automatically be deleted. + */ + OpenGLImage(GLuint textureHandle, int width, int height, bool autoFree); - /** - * 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 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); + /** + * 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; - 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. - */ - 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. + */ + virtual int getTextureHeight() const; - // Inherited from Image + // Inherited from Image - void free() override; + virtual void free(); - int getWidth() const override; + virtual int getWidth() const; - int getHeight() const override; + virtual int getHeight() const; - Color getPixel(int x, int y) override; + virtual Color getPixel(int x, int y); - void putPixel(int x, int y, const Color& color) override; + virtual void putPixel(int x, int y, const Color& color); - void convertToDisplayFormat() override; + virtual void convertToDisplayFormat(); - 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/guisan-dev/include/guisan/opengl/openglsdlimageloader.hpp b/guisan-dev/include/guisan/opengl/openglsdlimageloader.hpp index b752c1bb..a4e0dfff 100644 --- a/guisan-dev/include/guisan/opengl/openglsdlimageloader.hpp +++ b/guisan-dev/include/guisan/opengl/openglsdlimageloader.hpp @@ -61,50 +61,49 @@ #include #include -#include "SDL.h" 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 - Image* load(const std::string& filename, - bool convertToDisplayFormat = true) override - { - SDL_Surface* loadedSurface = loadSDLSurface(filename); + virtual Image* load(const std::string& filename, + bool convertToDisplayFormat = true) + { + SDL_Surface *loadedSurface = loadSDLSurface(filename); - if (loadedSurface == nullptr) - { - throw GCN_EXCEPTION( - std::string("Unable to load image file: ") + filename); - } + if (loadedSurface == NULL) + { + 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 == nullptr) - { - throw GCN_EXCEPTION( - std::string("Not enough memory to load: ") + filename); - } + if (surface == NULL) + { + 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((unsigned int*)surface->pixels, + surface->w, + surface->h, + convertToDisplayFormat); + SDL_FreeSurface(surface); - return image; - } - }; + return image; + } + }; } #endif // end GCN_OPENGLSDLIMAGELOADER_HPP diff --git a/guisan-dev/include/guisan/platform.hpp b/guisan-dev/include/guisan/platform.hpp index 5eb29905..b7a7609f 100644 --- a/guisan-dev/include/guisan/platform.hpp +++ b/guisan-dev/include/guisan/platform.hpp @@ -68,10 +68,10 @@ #define GCN_CORE_DECLSPEC __declspec(dllimport) #define GCN_EXTENSION_DECLSPEC __declspec(dllimport) -#elif defined(_MSC_VER_) && defined(GUICHAN_BUILD) +#elif defined(_MSC_VER) && defined(GUICHAN_BUILD) #define GCN_CORE_DECLSPEC _declspec(dllexport) -#elif defined(_MSC_VER_) && defined(GUICHAN_EXTENSION_BUILD) +#elif defined(_MSC_VER) && defined(GUICHAN_EXTENSION_BUILD) #define GCN_CORE_DECLSPEC _declspec(dllimport) #define GCN_EXTENSION_DECLSPEC _declspec(dllexport) diff --git a/guisan-dev/include/guisan/rectangle.hpp b/guisan-dev/include/guisan/rectangle.hpp index 92556bb7..649ff0e7 100644 --- a/guisan-dev/include/guisan/rectangle.hpp +++ b/guisan-dev/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. + */ + 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/guisan-dev/include/guisan/sdl.hpp b/guisan-dev/include/guisan/sdl.hpp index 2de992b7..e73f0cfd 100644 --- a/guisan-dev/include/guisan/sdl.hpp +++ b/guisan-dev/include/guisan/sdl.hpp @@ -58,6 +58,7 @@ #define GCN_SDL_HPP #include +#include #include #include #include @@ -65,11 +66,12 @@ #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/guisan-dev/include/guisan/sdl/sdl2graphics.hpp b/guisan-dev/include/guisan/sdl/sdl2graphics.hpp new file mode 100644 index 00000000..1d0e1df4 --- /dev/null +++ b/guisan-dev/include/guisan/sdl/sdl2graphics.hpp @@ -0,0 +1,192 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson + * Copyright (c) 2016, 2018, 2019 Gwilherm Baudic + * Js_./ + * Per Larsson a.k.a finalman _RqZ{a<^_aa + * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// + * _Qhm`] _f "'c 1!5m + * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' + * binary forms, with or without )4d[#7r, . ' )d`)[ + * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' + * that the following conditions are met: j<. a J@\ + * this list of conditions and the j(]1u 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/guisan-dev/include/guisan/sdl/sdlpixel.hpp b/guisan-dev/include/guisan/sdl/sdlpixel.hpp index 244820d3..de1f9c87 100644 --- a/guisan-dev/include/guisan/sdl/sdlpixel.hpp +++ b/guisan-dev/include/guisan/sdl/sdlpixel.hpp @@ -62,211 +62,213 @@ namespace gcn { - /** - * Checks a pixels color of an SDL_Surface. - * - * @param surface an SDL_Surface where to check for a pixel color. - * @param x the x coordinate on the surface. - * @param y the y coordinate on the surface. - * @return a color of a pixel. - */ - inline Color SDLgetPixel(SDL_Surface* surface, int x, int y) - { - int bpp = surface->format->BytesPerPixel; - SDL_LockSurface(surface); + /** + * Checks a pixel color of an SDL_Surface. + * + * @param surface an SDL_Surface where to check for a pixel color. + * @param x the x coordinate on the surface. + * @param y the y coordinate on the surface. + * @return a color of a pixel. + */ + inline const Color SDLgetPixel(SDL_Surface* surface, int x, int y) + { + int bpp = surface->format->BytesPerPixel; - Uint8* p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + SDL_LockSurface(surface); - unsigned int color = 0; + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; - switch (bpp) - { - case 1: - color = *p; - break; + unsigned int color = 0; - case 2: - color = *(Uint16 *)p; - break; + switch(bpp) + { + case 1: + color = *p; + break; - case 3: - { - if (SDL_BYTEORDER == SDL_BIG_ENDIAN) - { - color = p[0] << 16 | p[1] << 8 | p[2]; - } - color = p[0] | p[1] << 8 | p[2] << 16; - } - break; + case 2: + color = *(Uint16 *)p; + break; - case 4: - color = *(Uint32 *)p; - break; - } + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) + { + color = p[0] << 16 | p[1] << 8 | p[2]; + } + else + { + color = p[0] | p[1] << 8 | p[2] << 16; + } + break; - unsigned char r, g, b, a; + case 4: + color = *(Uint32 *)p; + break; - SDL_GetRGBA(color, surface->format, &r, &g, &b, &a); - SDL_UnlockSurface(surface); + } - return {r, g, b, a}; - } + unsigned char r,g,b,a; - /** - * Puts a pixel on an SDL_Surface. - * - * @param surface - * @param x the x coordinate on the surface. - * @param y the y coordinate on the surface. - * @param color the color the pixel should be in. - */ - inline void SDLputPixel(SDL_Surface* surface, int x, int y, const Color& color) - { - int bpp = surface->format->BytesPerPixel; + SDL_GetRGBA(color, surface->format, &r, &g, &b, &a); + SDL_UnlockSurface(surface); - SDL_LockSurface(surface); + return Color(r,g,b,a); + } - Uint8* p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + /** + * Puts a pixel on an SDL_Surface. + * + * @param x the x coordinate on the surface. + * @param y the y coordinate on the surface. + * @param color the color the pixel should be in. + */ + inline void SDLputPixel(SDL_Surface* surface, int x, int y, const Color& color) + { + int bpp = surface->format->BytesPerPixel; - Uint32 pixel = SDL_MapRGB(surface->format, color.r, color.g, color.b); + SDL_LockSurface(surface); - switch (bpp) - { - case 1: - *p = pixel; - break; + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; - case 2: - *(Uint16 *)p = pixel; - break; + Uint32 pixel = SDL_MapRGB(surface->format, color.r, color.g, color.b); - case 3: - { - if (SDL_BYTEORDER == SDL_BIG_ENDIAN) - { - p[0] = (pixel >> 16) & 0xff; - p[1] = (pixel >> 8) & 0xff; - p[2] = pixel & 0xff; - } - p[0] = pixel & 0xff; - p[1] = (pixel >> 8) & 0xff; - p[2] = (pixel >> 16) & 0xff; - } - break; + switch(bpp) + { + case 1: + *p = pixel; + break; - case 4: - *(Uint32 *)p = pixel; - break; - } + case 2: + *(Uint16 *)p = pixel; + break; - SDL_UnlockSurface(surface); - } + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) + { + p[0] = (pixel >> 16) & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = pixel & 0xff; + } + else + { + p[0] = pixel & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = (pixel >> 16) & 0xff; + } + break; - /** - * Blends two 32 bit colors together. - * - * @param src the source color. - * @param dst the destination color. - * @param a alpha. - */ - inline unsigned int SDLAlpha32(unsigned int src, unsigned int dst, unsigned char a) - { - auto b = ((src & 0xff) * a + (dst & 0xff) * (255 - a)) >> 8; - auto g = ((src & 0xff00) * a + (dst & 0xff00) * (255 - a)) >> 8; - auto r = ((src & 0xff0000) * a + (dst & 0xff0000) * (255 - a)) >> 8; + case 4: + *(Uint32 *)p = pixel; + break; + } - return (b & 0xff) | (g & 0xff00) | (r & 0xff0000); - } + SDL_UnlockSurface(surface); + } - /** - * Blends two 16 bit colors together. - * - * @param src the source color. - * @param dst the destination color. - * @param a alpha. - */ - inline unsigned short SDLAlpha16(unsigned short src, unsigned short dst, unsigned char a, const SDL_PixelFormat* f) - { - unsigned int b = ((src & f->Rmask) * a + (dst & f->Rmask) * (255 - a)) >> 8; - unsigned int g = ((src & f->Gmask) * a + (dst & f->Gmask) * (255 - a)) >> 8; - unsigned int r = ((src & f->Bmask) * a + (dst & f->Bmask) * (255 - a)) >> 8; + /** + * Blends two 32 bit colors together. + * + * @param src the source color. + * @param dst the destination color. + * @param a alpha. + */ + inline unsigned int SDLAlpha32(unsigned int src, unsigned int dst, unsigned char a) + { + unsigned int b = ((src & 0xff) * a + (dst & 0xff) * (255 - a)) >> 8; + unsigned int g = ((src & 0xff00) * a + (dst & 0xff00) * (255 - a)) >> 8; + unsigned int r = ((src & 0xff0000) * a + (dst & 0xff0000) * (255 - a)) >> 8; - return (unsigned short)((b & f->Rmask) | (g & f->Gmask) | (r & f->Bmask)); - } + return (b & 0xff) | (g & 0xff00) | (r & 0xff0000); + } - /* - typedef struct{ - SDL_Palette *palette; - Uint8 BitsPerPixel; - Uint8 BytesPerPixel; - Uint32 Rmask, Gmask, Bmask, Amask; - Uint8 Rshift, Gshift, Bshift, Ashift; - Uint8 Rloss, Gloss, Bloss, Aloss; - Uint32 colorkey; - Uint8 alpha; - } SDL_PixelFormat; - */ + /** + * Blends two 16 bit colors together. + * + * @param src the source color. + * @param dst the destination color. + * @param a alpha. + */ + inline unsigned short SDLAlpha16(unsigned short src, unsigned short dst, unsigned char a, const SDL_PixelFormat *f) + { + unsigned int b = ((src & f->Rmask) * a + (dst & f->Rmask) * (255 - a)) >> 8; + unsigned int g = ((src & f->Gmask) * a + (dst & f->Gmask) * (255 - a)) >> 8; + unsigned int r = ((src & f->Bmask) * a + (dst & f->Bmask) * (255 - a)) >> 8; - /** - * Puts a pixel on an SDL_Surface with alpha - * - * @param surface - * @param x the x coordinate on the surface. - * @param y the y coordinate on the surface. - * @param color the color the pixel should be in. - */ - inline void SDLputPixelAlpha(SDL_Surface* surface, int x, int y, const Color& color) - { - int bpp = surface->format->BytesPerPixel; + return (unsigned short)((b & f->Rmask) | (g & f->Gmask) | (r & f->Bmask)); + } - SDL_LockSurface(surface); + /* + typedef struct{ + SDL_Palette *palette; + Uint8 BitsPerPixel; + Uint8 BytesPerPixel; + Uint32 Rmask, Gmask, Bmask, Amask; + Uint8 Rshift, Gshift, Bshift, Ashift; + Uint8 Rloss, Gloss, Bloss, Aloss; + Uint32 colorkey; + Uint8 alpha; + } SDL_PixelFormat; + */ - Uint8* p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + /** + * Puts a pixel on an SDL_Surface with alpha + * + * @param x the x coordinate on the surface. + * @param y the y coordinate on the surface. + * @param color the color the pixel should be in. + */ + inline void SDLputPixelAlpha(SDL_Surface* surface, int x, int y, const Color& color) + { + int bpp = surface->format->BytesPerPixel; - Uint32 pixel = SDL_MapRGB(surface->format, color.r, color.g, color.b); + SDL_LockSurface(surface); - switch (bpp) - { - case 1: - *p = pixel; - break; + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; - case 2: - *(Uint16 *)p = SDLAlpha16(pixel, *(Uint32 *)p, color.a, surface->format); - break; + Uint32 pixel = SDL_MapRGB(surface->format, color.r, color.g, color.b); - case 3: - unsigned int c; - if (SDL_BYTEORDER == SDL_BIG_ENDIAN) - { - unsigned int r = (p[0] * (255 - color.a) + color.r * color.a) >> 8; - unsigned int g = (p[1] * (255 - color.a) + color.g * color.a) >> 8; - unsigned int b = (p[2] * (255 - color.a) + color.b * color.a) >> 8; + switch(bpp) + { + case 1: + *p = pixel; + break; - p[2] = b; - p[1] = g; - p[0] = r; - } - else - { - unsigned int r = (p[2] * (255 - color.a) + color.r * color.a) >> 8; - unsigned int g = (p[1] * (255 - color.a) + color.g * color.a) >> 8; - unsigned int b = (p[0] * (255 - color.a) + color.b * color.a) >> 8; + case 2: + *(Uint16 *)p = SDLAlpha16(pixel, *(Uint32 *)p, color.a, surface->format); + break; - p[0] = b; - p[1] = g; - p[2] = r; - } - break; + case 3: + unsigned int c; + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) + { + unsigned int r = (p[0] * (255 - color.a) + color.r * color.a) >> 8; + unsigned int g = (p[1] * (255 - color.a) + color.g * color.a) >> 8; + unsigned int b = (p[2] * (255 - color.a) + color.b * color.a) >> 8; - case 4: - *(Uint32 *)p = SDLAlpha32(pixel, *(Uint32 *)p, color.a); - break; - } + p[2] = b; + p[1] = g; + p[0] = r; + } + else + { + unsigned int r = (p[2] * (255 - color.a) + color.r * color.a) >> 8; + unsigned int g = (p[1] * (255 - color.a) + color.g * color.a) >> 8; + unsigned int b = (p[0] * (255 - color.a) + color.b * color.a) >> 8; - SDL_UnlockSurface(surface); - } + p[0] = b; + p[1] = g; + p[2] = r; + } + break; + + case 4: + *(Uint32 *)p = SDLAlpha32(pixel, *(Uint32 *)p, color.a); + break; + } + + SDL_UnlockSurface(surface); + } } #endif // end GCN_SDLPIXEL_HPP diff --git a/guisan-dev/include/guisan/sdl/sdltruetypefont.hpp b/guisan-dev/include/guisan/sdl/sdltruetypefont.hpp index f6be1c17..3e151cfe 100644 --- a/guisan-dev/include/guisan/sdl/sdltruetypefont.hpp +++ b/guisan-dev/include/guisan/sdl/sdltruetypefont.hpp @@ -6,11 +6,11 @@ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson * * * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem + * Olof Naessén a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * @@ -47,7 +47,7 @@ #include #include -#include +#include "SDL_ttf.h" #include "guisan/font.hpp" #include "guisan/platform.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. @@ -65,9 +65,9 @@ namespace gcn * function. * * @author Walluce Pinkham - * @author Olof Naessén + * @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,40 +113,41 @@ namespace gcn * @return the spacing. */ virtual int getGlyphSpacing(); - + /** * Sets the use of anti aliasing.. * - * @param antiAlias true for use of antia aliasing. + * @param antaAlias true for use of antialiasing. */ virtual void setAntiAlias(bool antiAlias); - + /** * Checks if anti aliasing is used. * * @return true if anti aliasing is used. */ virtual bool isAntiAlias(); - - + + // Inherited from Font - - int getWidth(const std::string& text) const override; - - int getHeight() const override; - - void drawString(Graphics* graphics, const std::string& text, int x, int y) override; - + + 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); + protected: - TTF_Font* mFont; - + TTF_Font *mFont; + int mHeight; int mGlyphSpacing; int mRowSpacing; - + std::string mFilename; - bool mAntiAlias; - }; + bool mAntiAlias; + }; } #endif + diff --git a/guisan-dev/include/guisan/selectionevent.hpp b/guisan-dev/include/guisan/selectionevent.hpp index 42401d68..47646084 100644 --- a/guisan-dev/include/guisan/selectionevent.hpp +++ b/guisan-dev/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/guisan-dev/include/guisan/selectionlistener.hpp b/guisan-dev/include/guisan/selectionlistener.hpp index 09997c4e..e7cfd442 100644 --- a/guisan-dev/include/guisan/selectionlistener.hpp +++ b/guisan-dev/include/guisan/selectionlistener.hpp @@ -64,36 +64,34 @@ 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() - = default; + /** + * Destructor. + */ + virtual ~SelectionListener() { } - /** - * 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/guisan-dev/include/guisan/widget.hpp b/guisan-dev/include/guisan/widget.hpp index 090b5b61..eb28f596 100644 --- a/guisan-dev/include/guisan/widget.hpp +++ b/guisan-dev/include/guisan/widget.hpp @@ -65,815 +65,799 @@ namespace gcn { - class ActionListener; - class BasicContainer; - class DeathListener; - class DefaultFont; - class FocusHandler; - class FocusListener; - class Font; - class Graphics; - class KeyInput; - class KeyListener; - class MouseInput; - class MouseListener; - class WidgetListener; - - /** - * Widget base class. Contains basic widget functions every widget should - * have. Widgets should inherit from this class and implements it's - * functions. - * - * NOTE: Functions begining with underscore "_" should not - * be overloaded unless you know what you are doing - * - * @author Olof Naessén - * @author Per Larsson. - */ - class GCN_CORE_DECLSPEC Widget - { - public: - /** - * Constructor. Resets member variables. Noteable, a widget is not - * focusable as default, therefore, widgets that are supposed to be - * focusable should overide this default in their own constructor. - */ - Widget(); - - /** - * Default destructor. - */ - virtual ~Widget(); - - /** - * Draws the widget. It is called by the parent widget when it is time - * for the widget to draw itself. The graphics object is set up so - * that all drawing is relative to the widget, i.e coordinate (0,0) is - * the top-left corner of the widget. It is not possible to draw - * outside of a widgets dimension. - * - * @param graphics a Graphics object to draw with. - */ - virtual void draw(Graphics* graphics) = 0; - - /** - * 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, - * the border surrounds the painting. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawBorder(Graphics* graphics) - { - } - - /** - * Called for all widgets in the gui each time Gui::logic is called. - * You can do logic stuff here like playing an animation. - * - * @see Gui - */ - virtual void logic() - { - } - - /** - * Gets the widget parent container. - * - * @return the widget parent container. Returns NULL if the widget - * has no parent. - */ - virtual Widget* getParent() const; - - /** - * Sets the width of the widget in pixels. - * - * @param width the widget width in pixels. - */ - virtual void setWidth(int width); - - /** - * Gets the width of the widget in pixels. - * - * @return the widget with in pixels. - */ - int getWidth() const; - - /** - * Sets the height of the widget in pixels. - * - * @param height the widget height in pixels. - */ - virtual void setHeight(int height); - - /** - * Gets the height of the widget in pixels. - * - * @return the widget height in pixels. - */ - int getHeight() const; - - /** - * Sets the size of the widget. - * - * @param width the width. - * @param height the height. - */ - virtual void setSize(int width, int height); - - /** - * Set the widget x coordinate. It is relateive to it's parent. - * - * @param x the widget x coordinate. - */ - void setX(int x); - - /** - * Gets the widget x coordinate. It is relative to it's parent. - * - * @return the widget x coordinate. - */ - int getX() const; - - /** - * Set the widget y coordinate. It is relative to it's parent. - * - * @param y the widget y coordinate. - */ - void setY(int y); - - /** - * Gets the widget y coordinate. It is relative to it's parent. - * - * @return the widget y coordinate. - */ - int getY() const; - - /** - * Sets the widget position. It is relative to it's parent. - * - * @param x the widget x coordinate. - * @param y the widgets y coordinate. - */ - void setPosition(int x, int y); - - /** - * Sets the dimension of the widget. It is relative to it's parent. - * - * @param dimension the widget dimension. - */ - virtual void setDimension(const Rectangle& dimension); - - /** - * Sets the size of the border, or the width if you so like. The size - * is the number of pixels that the border extends outside the widget. - * Border size = 0 means no border. - * - * @param borderSize the size of the border. - * @see drawBorder - */ - void setBorderSize(unsigned int borderSize); - - /** - * Gets the size of the border, or the width if you so like. The size - * is the number of pixels that the border extends outside the widget. - * Border size = 0 means no border. - * - * @return the size of the border. - * @see drawBorder - */ - unsigned int getBorderSize() const; - - /** - * Gets the dimension of the widget. It is relative to it's parent. - * - * @return the widget dimension. - */ - const Rectangle& getDimension() const; - - /** - * Sets a widgets focusability. - * - * @param focusable true if the widget should be focusable. - */ - void setFocusable(bool focusable); - - /** - * Checks whether the widget is focusable. - * - * @return true if the widget is focusable. - */ - bool isFocusable() const; - - /** - * Checks if the widget is focused. - * - * @return true if the widget currently has focus. - */ - virtual bool isFocused() const; - - /** - * Sets the widget to be disabled or enabled. A disabled - * widget will never recieve mouse or key input. - * - * @param enabled true if widget is enabled. - */ - void setEnabled(bool enabled); - - /** - * Checks if a widget is disabled or not. - * - * @return true if the widget should be enabled. - */ - bool isEnabled() const; - - /** - * Sets the widget to be visible. - * - * @param visible true if the widget should be visiable. - */ - void setVisible(bool visible); - - /** - * Checks if the widget is visible. - * - * @return true if the widget is visible. - */ - bool isVisible() const; - - /** - * Sets the base color. The base color is the background - * color for many widgets like the Button and Contianer widgets. - * - * @param color the baseground color. - */ - virtual void setBaseColor(const Color& color); - - /** - * Gets the base color. - * - * @return the foreground color. - */ - const Color& getBaseColor() const; - - /** - * Sets the foreground color. - * - * @param color the foreground color. - */ - virtual void setForegroundColor(const Color& color); - - /** - * Gets the foreground color. - * - * @return the foreground color. - */ - const Color& getForegroundColor() const; - - /** - * Sets the background color. - * - * @param color the background Color. - */ - virtual void setBackgroundColor(const Color& color); - - /** - * Gets the background color. - * - * @return the background color. - */ - const Color& getBackgroundColor() const; - - /** - * Sets the selection color. - * - * @param color the selection color. - */ - virtual void setSelectionColor(const Color& color); - - /** - * Gets the selection color. - * - * @return the selection color. - */ - const Color& getSelectionColor() const; - - /** - * Requests focus for the widget. A widget will only recieve focus - * if it is focusable. - */ - virtual void requestFocus(); - - /** - * Requests a move to the top in the parent widget. - */ - virtual void requestMoveToTop(); - - /** - * Requests a move to the bottom in the parent widget. - */ - virtual void requestMoveToBottom(); - - /** - * Sets the FocusHandler to be used. - * - * WARNING: This function is used internally and should not - * be called or overloaded unless you know what you - * are doing. - * - * @param focusHandler the FocusHandler to use. - */ - virtual void _setFocusHandler(FocusHandler* focusHandler); - - /** - * Gets the FocusHandler used. - * - * WARNING: This function is used internally and should not - * be called or overloaded unless you know what you - * are doing. - * - * @return the FocusHandler used. - */ - virtual FocusHandler* _getFocusHandler(); - - /** - * Adds an ActionListener to the widget. When an action is triggered - * by the widget, the action function in all the widget's - * ActionListeners will be called. - * - * @param actionListener the ActionListener to add. - */ - void addActionListener(ActionListener* actionListener); - - /** - * Removes an added ActionListener from the widget. - * - * @param actionListener the ActionListener to remove. - */ - void removeActionListener(ActionListener* actionListener); - - /** - * Adds a DeathListener to the widget. When the widget dies - * the death function in all the widget's DeathListeners will be called. - * - * @param deathListener the DeathListener to add. - */ - void addDeathListener(DeathListener* deathListener); - - /** - * Removes an added DeathListener from the widget. - * - * @param deathListener the DeathListener to remove. - */ - void removeDeathListener(DeathListener* deathListener); - - /** - * Adds a MouseListener to the widget. When a mouse message is - * recieved, it will be sent to the widget's MouseListeners. - * - * @param mouseListener the MouseListener to add. - */ - void addMouseListener(MouseListener* mouseListener); - - /** - * Removes an added MouseListener from the widget. - * - * @param mouseListener the MouseListener to remove. - */ - void removeMouseListener(MouseListener* mouseListener); - - /** - * Adds a KeyListener to the widget. When a key message is recieved, - * it will be sent to the widget's KeyListeners. - * - * @param keyListener the KeyListener to add. - */ - void addKeyListener(KeyListener* keyListener); - - /** - * Removes an added KeyListener from the widget. - * - * @param keyListener the KeyListener to remove. - */ - void removeKeyListener(KeyListener* keyListener); - - /** - * Adds a FocusListener to the widget. When a focus event is recieved, - * it will be sent to the widget's FocusListeners. - * - * @param focusListener the FocusListener to add. - * @author Olof Naessén - * @since 0.7.0 - */ - void addFocusListener(FocusListener* focusListener); - - /** - * Removes an added FocusListener from the widget. - * - * @param focusListener the FocusListener to remove. - * @author Olof Naessén - * @since 0.7.0 - */ - void removeFocusListener(FocusListener* focusListener); - - /** - * Adds a WidgetListener to the widget. - * - * @param widgetListener the WidgetListener to add. - * @author Olof Naessén - * @since 0.8.0 - */ - void addWidgetListener(WidgetListener* widgetListener); - - /** - * Removes an added WidgetListener from the widget. - * - * @param widgetListener the WidgetListener to remove. - * @author Olof Naessén - * @since 0.8.0 - */ - void removeWidgetListener(WidgetListener* widgetListener); - - /** - * Sets the action event identifier of the widget. The identifier is - * used to be able to identify which action has occured. - * - * NOTE: An action event identifier should not be used to identify a - * certain widget but rather a certain event in your application. - * Several widgets can have the same action event identifer. - * - * @param actionEventId the action event identifier. - * @since 0.6.0 - */ - void setActionEventId(const std::string& actionEventId); - - /** - * Gets the action event identifier. - * - * @return the action event identifier. - */ - const std::string& getActionEventId() const; - - /** - * Gets the absolute position on the screen for the widget. - * - * @param x absolute x coordinate will be stored in this parameter. - * @param y absolute y coordinate will be stored in this parameter. - */ - virtual void getAbsolutePosition(int& x, int& y) const; - - /** - * Sets the parent of the widget. A parent must be a BasicContainer. - * - * WARNING: This function is used internally and should not - * be called or overloaded unless you know what you - * are doing. - * - * @param parent the parent BasicContainer.. - */ - virtual void _setParent(Widget* parent); - - /** - * Gets the font used. If no font has been set, the global font will - * be returned instead. If no global font has been set, the default - * font will be returend. - * ugly default. - * - * @return the used Font. - */ - Font* getFont() const; - - /** - * Sets the global font to be used by default for all widgets. - * - * @param font the global Font. - */ - static void setGlobalFont(Font* font); - - /** - * Sets the font. If font is NULL, the global font will be used. - * - * @param font the Font. - */ - virtual void setFont(Font* font); - - /** - * Called when the font has changed. If the change is global, - * this function will only be called if the widget don't have a - * font already set. - */ - virtual void fontChanged() - { - } - - /** - * Checks whether a widget exists or not, that is if it still exists - * an instance of the object. - * - * @param widget the widget to check. - */ - static bool widgetExists(const Widget* widget); - - /** - * Check if tab in is enabled. Tab in means that you can set focus - * to this widget by pressing the tab button. If tab in is disabled - * then the FocusHandler will skip this widget and focus the next - * in its focus order. - * - * @return true if tab in is enabled. - */ - bool isTabInEnabled() const; - - /** - * Sets tab in enabled. Tab in means that you can set focus - * to this widget by pressing the tab button. If tab in is disabled - * then the FocusHandler will skip this widget and focus the next - * in its focus order. - * - * @param enabled true if tab in should be enabled. - */ - void setTabInEnabled(bool enabled); - - /** - * Checks if tab out is enabled. Tab out means that you can lose - * focus to this widget by pressing the tab button. If tab out is - * disabled then the FocusHandler ignores tabbing and focus will - * stay with this widget. - * - * @return true if tab out is enabled. - */ - bool isTabOutEnabled() const; - - /** - * Sets tab out enabled. Tab out means that you can lose - * focus to this widget by pressing the tab button. If tab out is - * disabled then the FocusHandler ignores tabbing and focus will - * stay with this widget. - * - * @param enabled true if tab out should be enabled. - */ - void setTabOutEnabled(bool enabled); - - /** - * Requests modal focus. When a widget has modal focus, only that - * widget and it's children may recieve input. - * - * @throws Exception if another widget already has modal focus. - */ - virtual void requestModalFocus(); - - /** - * Requests modal mouse input focus. When a widget has modal input focus - * that widget will be the only widget receiving input even if the input - * occurs outside of the widget and no matter what the input is. - * - * @throws Exception if another widget already has modal focus. - * @since 0.6.0 - */ - virtual void requestModalMouseInputFocus(); - - /** - * Releases modal focus. Modal focus will only be released if the - * widget has modal focus. - */ - virtual void releaseModalFocus(); - - /** - * Releases modal mouse input focus. Modal mouse input focus will only - * be released if the widget has modal mouse input focus. - * - * @since 0.6.0 - */ - virtual void releaseModalMouseInputFocus(); - - /** - * Checks if the widget or it's parent has modal focus. - */ - virtual bool hasModalFocus() const; - - /** - * Checks if the widget or it's parent has modal mouse input focus. - * - * @since 0.6.0 - */ - virtual bool hasModalMouseInputFocus() const; - - /** - * Gets a widget from a certain position in the widget. - * This function is used to decide which gets mouse input, - * thus it can be overloaded to change that behaviour. - * - * NOTE: This always returns NULL if the widget is not - * a container. - * - * @param x the x coordinate. - * @param y the y coordinate. - * @return the widget at the specified coodinate, or NULL - * if no such widget exists. - * @since 0.6.0 - */ - virtual Widget* getWidgetAt(int x, int y); - - /** - * Gets the mouse listeners of the widget. - * - * @return the mouse listeners of the widget. - * @since 0.6.0 - */ - virtual const std::list& _getMouseListeners(); - - /** - * Gets the key listeners of the widget. - * - * @return the key listeners of the widget. - * @since 0.6.0 - */ - virtual const std::list& _getKeyListeners(); - - /** - * Gets the focus listeners of the widget. - * - * @return the focus listeners of the widget. - * @since 0.7.0 - */ - virtual const std::list& _getFocusListeners(); - - /** - * Gets the subarea of the widget that the children occupy. - * - * @return the subarea as a Rectangle. - */ - virtual Rectangle getChildrenArea(); - - /** - * Gets the internal FocusHandler used. - * - * @return the internalFocusHandler used. If no internal FocusHandler - * is used, NULL will be returned. - */ - virtual FocusHandler* _getInternalFocusHandler(); - - /** - * Sets the internal FocusHandler. An internal focushandler is - * needed if both a widget in the widget and the widget itself - * should be foucsed at the same time. - * - * @param focusHandler the FocusHandler to be used. - */ - virtual void setInternalFocusHandler(FocusHandler* focusHandler); - - /** - * Moves a widget to the top of this widget. The moved widget will be - * drawn above all other widgets in this widget. - * - * @param widget the widget to move. - */ - virtual void moveToTop(Widget* widget) - { - }; - - /** - * Moves a widget in this widget to the bottom of this widget. - * The moved widget will be drawn below all other widgets in this widget. - * - * @param widget the widget to move. - */ - virtual void moveToBottom(Widget* widget) - { - }; - - /** - * Focuses the next widget in the widget. - */ - virtual void focusNext() - { - }; - - /** - * Focuses the previous widget in the widget. - */ - virtual void focusPrevious() - { - }; - - /** - * Tries to show a specific part of a widget by moving it. Used if the - * widget should act as a container. - * - * @param widget the target widget. - * @param area the area to show. - */ - virtual void showWidgetPart(Widget* widget, Rectangle area) - { - }; - - /** - * Sets an id of a widget. An id can be useful if a widget needs to be - * identified in a container. For example, if widgets are created by an - * XML document, a certain widget can be retrieved given that the widget - * has an id. - * - * @param id the id to set to the widget. - * @see BasicContainer::findWidgetById - */ - void setId(const std::string& id); - - /** - * Gets the id of a widget. An id can be useful if a widget needs to be - * identified in a container. For example, if widgets are created by an - * XML document, a certain widget can be retrieved given that the widget - * has an id. - * - * @param id the id to set to the widget. - * @see BasicContainer::findWidgetById - */ - const std::string& getId(); - - protected: - /** - * Generates an action to the widget's ActionListeners. - */ - void generateAction(); - - /** - * Distributes resized events to all of the widget's listeners. - * - * @since 0.8.0 - * @author Olof Naessén - */ - void distributeResizedEvent(); - - /** - * Distributes moved events to all of the widget's listeners. - * - * @since 0.8.0 - * @author Olof Naessén - */ - void distributeMovedEvent(); - - /** - * Distributes hidden events to all of the widget's listeners. - * - * @since 0.8.0 - * @author Olof Naessén - */ - void distributeHiddenEvent(); - - /** - * Distributes shown events to all of the widget's listeners. - * - * @since 0.8.0 - * @author Olof Naessén - */ - void distributeShownEvent(); - - typedef std::list MouseListenerList; - typedef MouseListenerList::iterator MouseListenerIterator; - MouseListenerList mMouseListeners; - - typedef std::list KeyListenerList; - KeyListenerList mKeyListeners; - typedef KeyListenerList::iterator KeyListenerIterator; - - typedef std::list ActionListenerList; - ActionListenerList mActionListeners; - typedef ActionListenerList::iterator ActionListenerIterator; - - typedef std::list DeathListenerList; - DeathListenerList mDeathListeners; - typedef DeathListenerList::iterator DeathListenerIterator; - - typedef std::list FocusListenerList; - FocusListenerList mFocusListeners; - typedef FocusListenerList::iterator FocusListenerIterator; - - typedef std::list WidgetListenerList; - WidgetListenerList mWidgetListeners; - typedef WidgetListenerList::iterator WidgetListenerIterator; - - Color mForegroundColor; - Color mBackgroundColor; - Color mBaseColor; - Color mSelectionColor; - FocusHandler* mFocusHandler; - FocusHandler* mInternalFocusHandler; - Widget* mParent; - Rectangle mDimension; - unsigned int mBorderSize; - std::string mActionEventId; - bool mFocusable; - bool mVisible; - bool mTabIn; - bool mTabOut; - bool mEnabled; - std::string mId; - - Font* mCurrentFont; - static DefaultFont mDefaultFont; - static Font* mGlobalFont; - static std::list mWidgets; - }; + class ActionListener; + class BasicContainer; + class DeathListener; + class DefaultFont; + class FocusHandler; + class FocusListener; + class Font; + class Graphics; + class KeyInput; + class KeyListener; + class MouseInput; + class MouseListener; + class WidgetListener; + + /** + * Widget base class. Contains basic widget functions every widget should + * have. Widgets should inherit from this class and implements it's + * functions. + * + * NOTE: Functions begining with underscore "_" should not + * be overloaded unless you know what you are doing + * + * @author Olof Naessén + * @author Per Larsson. + */ + class GCN_CORE_DECLSPEC Widget + { + public: + /** + * Constructor. Resets member variables. Noteable, a widget is not + * focusable as default, therefore, widgets that are supposed to be + * focusable should overide this default in their own constructor. + */ + Widget(); + + /** + * Default destructor. + */ + virtual ~Widget(); + + /** + * Draws the widget. It is called by the parent widget when it is time + * for the widget to draw itself. The graphics object is set up so + * that all drawing is relative to the widget, i.e coordinate (0,0) is + * the top-left corner of the widget. It is not possible to draw + * outside of a widgets dimension. + * + * @param graphics a Graphics object to draw with. + */ + virtual void draw(Graphics* graphics) = 0; + + /** + * 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, + * the border surrounds the painting. + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawBorder(Graphics* graphics) { } + + /** + * Called for all widgets in the gui each time Gui::logic is called. + * You can do logic stuff here like playing an animation. + * + * @see Gui + */ + virtual void logic() { } + + /** + * Gets the widget parent container. + * + * @return the widget parent container. Returns NULL if the widget + * has no parent. + */ + virtual Widget* getParent() const; + + /** + * Sets the width of the widget in pixels. + * + * @param width the widget width in pixels. + */ + void setWidth(int width); + + /** + * Gets the width of the widget in pixels. + * + * @return the widget with in pixels. + */ + int getWidth() const; + + /** + * Sets the height of the widget in pixels. + * + * @param height the widget height in pixels. + */ + void setHeight(int height); + + /** + * Gets the height of the widget in pixels. + * + * @return the widget height in pixels. + */ + int getHeight() const; + + /** + * Sets the size of the widget. + * + * @param width the width. + * @param height the height. + */ + void setSize(int width, int height); + + /** + * Set the widget x coordinate. It is relateive to it's parent. + * + * @param x the widget x coordinate. + */ + void setX(int x); + + /** + * Gets the widget x coordinate. It is relative to it's parent. + * + * @return the widget x coordinate. + */ + int getX() const; + + /** + * Set the widget y coordinate. It is relative to it's parent. + * + * @param y the widget y coordinate. + */ + void setY(int y); + + /** + * Gets the widget y coordinate. It is relative to it's parent. + * + * @return the widget y coordinate. + */ + int getY() const; + + /** + * Sets the widget position. It is relative to it's parent. + * + * @param x the widget x coordinate. + * @param y the widgets y coordinate. + */ + void setPosition(int x, int y); + + /** + * Sets the dimension of the widget. It is relative to it's parent. + * + * @param dimension the widget dimension. + */ + void setDimension(const Rectangle& dimension); + + /** + * Sets the size of the border, or the width if you so like. The size + * is the number of pixels that the border extends outside the widget. + * Border size = 0 means no border. + * + * @param borderSize the size of the border. + * @see drawBorder + */ + void setBorderSize(unsigned int borderSize); + + /** + * Gets the size of the border, or the width if you so like. The size + * is the number of pixels that the border extends outside the widget. + * Border size = 0 means no border. + * + * @return the size of the border. + * @see drawBorder + */ + unsigned int getBorderSize() const; + + /** + * Gets the dimension of the widget. It is relative to it's parent. + * + * @return the widget dimension. + */ + const Rectangle& getDimension() const; + + /** + * Sets a widgets focusability. + * + * @param focusable true if the widget should be focusable. + */ + void setFocusable(bool focusable); + + /** + * Checks whether the widget is focusable. + * + * @return true if the widget is focusable. + */ + bool isFocusable() const; + + /** + * Checks if the widget is focused. + * + * @return true if the widget currently has focus. + */ + virtual bool isFocused() const; + + /** + * Sets the widget to be disabled or enabled. A disabled + * widget will never recieve mouse or key input. + * + * @param enabled true if widget is enabled. + */ + void setEnabled(bool enabled); + + /** + * Checks if a widget is disabled or not. + * + * @return true if the widget should be enabled. + */ + bool isEnabled() const; + + /** + * Sets the widget to be visible. + * + * @param visible true if the widget should be visiable. + */ + void setVisible(bool visible); + + /** + * Checks if the widget is visible. + * + * @return true if the widget is visible. + */ + bool isVisible() const; + + /** + * Sets the base color. The base color is the background + * color for many widgets like the Button and Contianer widgets. + * + * @param color the baseground color. + */ + void setBaseColor(const Color& color); + + /** + * Gets the base color. + * + * @return the foreground color. + */ + const Color& getBaseColor() const; + + /** + * Sets the foreground color. + * + * @param color the foreground color. + */ + void setForegroundColor(const Color& color); + + /** + * Gets the foreground color. + * + * @return the foreground color. + */ + const Color& getForegroundColor() const; + + /** + * Sets the background color. + * + * @param color the background Color. + */ + void setBackgroundColor(const Color& color); + + /** + * Gets the background color. + * + * @return the background color. + */ + const Color& getBackgroundColor() const; + + /** + * Sets the selection color. + * + * @param color the selection color. + */ + void setSelectionColor(const Color& color); + + /** + * Gets the selection color. + * + * @return the selection color. + */ + const Color& getSelectionColor() const; + + /** + * Requests focus for the widget. A widget will only recieve focus + * if it is focusable. + */ + virtual void requestFocus(); + + /** + * Requests a move to the top in the parent widget. + */ + virtual void requestMoveToTop(); + + /** + * Requests a move to the bottom in the parent widget. + */ + virtual void requestMoveToBottom(); + + /** + * Sets the FocusHandler to be used. + * + * WARNING: This function is used internally and should not + * be called or overloaded unless you know what you + * are doing. + * + * @param focusHandler the FocusHandler to use. + */ + virtual void _setFocusHandler(FocusHandler* focusHandler); + + /** + * Gets the FocusHandler used. + * + * WARNING: This function is used internally and should not + * be called or overloaded unless you know what you + * are doing. + * + * @return the FocusHandler used. + */ + virtual FocusHandler* _getFocusHandler(); + + /** + * Adds an ActionListener to the widget. When an action is triggered + * by the widget, the action function in all the widget's + * ActionListeners will be called. + * + * @param actionListener the ActionListener to add. + */ + void addActionListener(ActionListener* actionListener); + + /** + * Removes an added ActionListener from the widget. + * + * @param actionListener the ActionListener to remove. + */ + void removeActionListener(ActionListener* actionListener); + + /** + * Adds a DeathListener to the widget. When the widget dies + * the death function in all the widget's DeathListeners will be called. + * + * @param actionListener the DeathListener to add. + */ + void addDeathListener(DeathListener* deathListener); + + /** + * Removes an added DeathListener from the widget. + * + * @param deathListener the DeathListener to remove. + */ + void removeDeathListener(DeathListener* deathListener); + + /** + * Adds a MouseListener to the widget. When a mouse message is + * recieved, it will be sent to the widget's MouseListeners. + * + * @param mouseListener the MouseListener to add. + */ + void addMouseListener(MouseListener* mouseListener); + + /** + * Removes an added MouseListener from the widget. + * + * @param mouseListener the MouseListener to remove. + */ + void removeMouseListener(MouseListener* mouseListener); + + /** + * Adds a KeyListener to the widget. When a key message is recieved, + * it will be sent to the widget's KeyListeners. + * + * @param keyListener the KeyListener to add. + */ + void addKeyListener(KeyListener* keyListener); + + /** + * Removes an added KeyListener from the widget. + * + * @param keyListener the KeyListener to remove. + */ + void removeKeyListener(KeyListener* keyListener); + + /** + * Adds a FocusListener to the widget. When a focus event is recieved, + * it will be sent to the widget's FocusListeners. + * + * @param focusListener the FocusListener to add. + * @author Olof Naessén + * @since 0.7.0 + */ + void addFocusListener(FocusListener* focusListener); + + /** + * Removes an added FocusListener from the widget. + * + * @param focusListener the FocusListener to remove. + * @author Olof Naessén + * @since 0.7.0 + */ + void removeFocusListener(FocusListener* focusListener); + + /** + * Adds a WidgetListener to the widget. + * + * @param widgetListener the WidgetListener to add. + * @author Olof Naessén + * @since 0.8.0 + */ + void addWidgetListener(WidgetListener* widgetListener); + + /** + * Removes an added WidgetListener from the widget. + * + * @param widgetListener the WidgetListener to remove. + * @author Olof Naessén + * @since 0.8.0 + */ + void removeWidgetListener(WidgetListener* widgetListener); + + /** + * Sets the action event identifier of the widget. The identifier is + * used to be able to identify which action has occured. + * + * NOTE: An action event identifier should not be used to identify a + * certain widget but rather a certain event in your application. + * Several widgets can have the same action event identifer. + * + * @param actionEventId the action event identifier. + * @since 0.6.0 + */ + void setActionEventId(const std::string& actionEventId); + + /** + * Gets the action event identifier. + * + * @return the action event identifier. + */ + const std::string& getActionEventId() const; + + /** + * Gets the absolute position on the screen for the widget. + * + * @param x absolute x coordinate will be stored in this parameter. + * @param y absolute y coordinate will be stored in this parameter. + */ + virtual void getAbsolutePosition(int& x, int& y) const; + + /** + * Sets the parent of the widget. A parent must be a BasicContainer. + * + * WARNING: This function is used internally and should not + * be called or overloaded unless you know what you + * are doing. + * + * @param parent the parent BasicContainer.. + */ + virtual void _setParent(Widget* parent); + + /** + * Gets the font used. If no font has been set, the global font will + * be returned instead. If no global font has been set, the default + * font will be returend. + * ugly default. + * + * @return the used Font. + */ + Font *getFont() const; + + /** + * Sets the global font to be used by default for all widgets. + * + * @param font the global Font. + */ + static void setGlobalFont(Font* font); + + /** + * Sets the font. If font is NULL, the global font will be used. + * + * @param font the Font. + */ + void setFont(Font* font); + + /** + * Called when the font has changed. If the change is global, + * this function will only be called if the widget don't have a + * font already set. + */ + virtual void fontChanged() { } + + /** + * Checks whether a widget exists or not, that is if it still exists + * an instance of the object. + * + * @param widget the widget to check. + */ + static bool widgetExists(const Widget* widget); + + /** + * Check if tab in is enabled. Tab in means that you can set focus + * to this widget by pressing the tab button. If tab in is disabled + * then the FocusHandler will skip this widget and focus the next + * in its focus order. + * + * @return true if tab in is enabled. + */ + bool isTabInEnabled() const; + + /** + * Sets tab in enabled. Tab in means that you can set focus + * to this widget by pressing the tab button. If tab in is disabled + * then the FocusHandler will skip this widget and focus the next + * in its focus order. + * + * @param enabled true if tab in should be enabled. + */ + void setTabInEnabled(bool enabled); + + /** + * Checks if tab out is enabled. Tab out means that you can lose + * focus to this widget by pressing the tab button. If tab out is + * disabled then the FocusHandler ignores tabbing and focus will + * stay with this widget. + * + * @return true if tab out is enabled. + */ + bool isTabOutEnabled() const; + + /** + * Sets tab out enabled. Tab out means that you can lose + * focus to this widget by pressing the tab button. If tab out is + * disabled then the FocusHandler ignores tabbing and focus will + * stay with this widget. + * + * @param enabled true if tab out should be enabled. + */ + void setTabOutEnabled(bool enabled); + + /** + * Requests modal focus. When a widget has modal focus, only that + * widget and it's children may recieve input. + * + * @throws Exception if another widget already has modal focus. + */ + virtual void requestModalFocus(); + + /** + * Requests modal mouse input focus. When a widget has modal input focus + * that widget will be the only widget receiving input even if the input + * occurs outside of the widget and no matter what the input is. + * + * @throws Exception if another widget already has modal focus. + * @since 0.6.0 + */ + virtual void requestModalMouseInputFocus(); + + /** + * Releases modal focus. Modal focus will only be released if the + * widget has modal focus. + */ + virtual void releaseModalFocus(); + + /** + * Releases modal mouse input focus. Modal mouse input focus will only + * be released if the widget has modal mouse input focus. + * + * @since 0.6.0 + */ + virtual void releaseModalMouseInputFocus(); + + /** + * Checks if the widget or it's parent has modal focus. + */ + virtual bool hasModalFocus() const; + + /** + * Checks if the widget or it's parent has modal mouse input focus. + * + * @since 0.6.0 + */ + virtual bool hasModalMouseInputFocus() const; + + /** + * Gets a widget from a certain position in the widget. + * This function is used to decide which gets mouse input, + * thus it can be overloaded to change that behaviour. + * + * NOTE: This always returns NULL if the widget is not + * a container. + * + * @param x the x coordinate. + * @param y the y coordinate. + * @return the widget at the specified coodinate, or NULL + * if no such widget exists. + * @since 0.6.0 + */ + virtual Widget *getWidgetAt(int x, int y); + + /** + * Gets the mouse listeners of the widget. + * + * @return the mouse listeners of the widget. + * @since 0.6.0 + */ + virtual const std::list& _getMouseListeners(); + + /** + * Gets the key listeners of the widget. + * + * @return the key listeners of the widget. + * @since 0.6.0 + */ + virtual const std::list& _getKeyListeners(); + + /** + * Gets the focus listeners of the widget. + * + * @return the focus listeners of the widget. + * @since 0.7.0 + */ + virtual const std::list& _getFocusListeners(); + + /** + * Gets the subarea of the widget that the children occupy. + * + * @return the subarea as a Rectangle. + */ + virtual Rectangle getChildrenArea(); + + /** + * Gets the internal FocusHandler used. + * + * @return the internalFocusHandler used. If no internal FocusHandler + * is used, NULL will be returned. + */ + virtual FocusHandler* _getInternalFocusHandler(); + + /** + * Sets the internal FocusHandler. An internal focushandler is + * needed if both a widget in the widget and the widget itself + * should be foucsed at the same time. + * + * @param focusHandler the FocusHandler to be used. + */ + void setInternalFocusHandler(FocusHandler* focusHandler); + + /** + * Moves a widget to the top of this widget. The moved widget will be + * drawn above all other widgets in this widget. + * + * @param widget the widget to move. + */ + virtual void moveToTop(Widget* widget) { }; + + /** + * Moves a widget in this widget to the bottom of this widget. + * The moved widget will be drawn below all other widgets in this widget. + * + * @param widget the widget to move. + */ + virtual void moveToBottom(Widget* widget) { }; + + /** + * Focuses the next widget in the widget. + */ + virtual void focusNext() { }; + + /** + * Focuses the previous widget in the widget. + */ + virtual void focusPrevious() { }; + + /** + * Tries to show a specific part of a widget by moving it. Used if the + * widget should act as a container. + * + * @param widget the target widget. + * @param area the area to show. + */ + virtual void showWidgetPart(Widget* widget, Rectangle area) { }; + + /** + * Sets an id of a widget. An id can be useful if a widget needs to be + * identified in a container. For example, if widgets are created by an + * XML document, a certain widget can be retrieved given that the widget + * has an id. + * + * @param id the id to set to the widget. + * @see BasicContainer::findWidgetById + */ + void setId(const std::string& id); + + /** + * Gets the id of a widget. An id can be useful if a widget needs to be + * identified in a container. For example, if widgets are created by an + * XML document, a certain widget can be retrieved given that the widget + * has an id. + * + * @param id the id to set to the widget. + * @see BasicContainer::findWidgetById + */ + const std::string& getId(); + + protected: + /** + * Generates an action to the widget's ActionListeners. + */ + void generateAction(); + + /** + * Distributes resized events to all of the widget's listeners. + * + * @since 0.8.0 + * @author Olof Naessén + */ + void distributeResizedEvent(); + + /** + * Distributes moved events to all of the widget's listeners. + * + * @since 0.8.0 + * @author Olof Naessén + */ + void distributeMovedEvent(); + + /** + * Distributes hidden events to all of the widget's listeners. + * + * @since 0.8.0 + * @author Olof Naessén + */ + void distributeHiddenEvent(); + + /** + * Distributes shown events to all of the widget's listeners. + * + * @since 0.8.0 + * @author Olof Naessén + */ + void distributeShownEvent(); + + typedef std::list MouseListenerList; + typedef MouseListenerList::iterator MouseListenerIterator; + MouseListenerList mMouseListeners; + + typedef std::list KeyListenerList; + KeyListenerList mKeyListeners; + typedef KeyListenerList::iterator KeyListenerIterator; + + typedef std::list ActionListenerList; + ActionListenerList mActionListeners; + typedef ActionListenerList::iterator ActionListenerIterator; + + typedef std::list DeathListenerList; + DeathListenerList mDeathListeners; + typedef DeathListenerList::iterator DeathListenerIterator; + + typedef std::list FocusListenerList; + FocusListenerList mFocusListeners; + typedef FocusListenerList::iterator FocusListenerIterator; + + typedef std::list WidgetListenerList; + WidgetListenerList mWidgetListeners; + typedef WidgetListenerList::iterator WidgetListenerIterator; + + Color mForegroundColor; + Color mBackgroundColor; + Color mBaseColor; + Color mSelectionColor; + FocusHandler* mFocusHandler; + FocusHandler* mInternalFocusHandler; + Widget* mParent; + Rectangle mDimension; + unsigned int mBorderSize; + std::string mActionEventId; + bool mFocusable; + bool mVisible; + bool mTabIn; + bool mTabOut; + bool mEnabled; + std::string mId; + + Font* mCurrentFont; + static DefaultFont mDefaultFont; + static Font* mGlobalFont; + static std::list mWidgets; + }; } #endif // end GCN_WIDGET_HPP diff --git a/guisan-dev/include/guisan/widgetlistener.hpp b/guisan-dev/include/guisan/widgetlistener.hpp index 8e7daa2d..d63a7f16 100644 --- a/guisan-dev/include/guisan/widgetlistener.hpp +++ b/guisan-dev/include/guisan/widgetlistener.hpp @@ -64,68 +64,60 @@ 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() - = default; + /** + * Destructor. + */ + virtual ~WidgetListener() { } - /** - * 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/guisan-dev/include/guisan/widgets/button.hpp b/guisan-dev/include/guisan/widgets/button.hpp index 32bcfab4..d120302e 100644 --- a/guisan-dev/include/guisan/widgets/button.hpp +++ b/guisan-dev/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. - */ - Button(const std::string& caption); + /** + * Constructor. + * + * @param caption the caption of the Button. + */ + Button(const 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. - */ - const std::string& getCaption() const; + /** + * Gets the Button caption. + * + * @return the Button caption. + */ + const std::string& getCaption() const; - /** - * Sets the alignment for the caption. - * - * @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT - * @see Graphics - */ - void setAlignment(unsigned int alignment); + /** + * Sets the alignment for the caption. + * + * @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT + * @see Graphics + */ + void setAlignment(unsigned int alignment); - /** - * Gets the alignment for the caption. - * - * @return alignment of caption. - */ - unsigned int getAlignment() const; + /** + * Gets the alignment for the caption. + * + * @return alignment of caption. + */ + 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. - */ - unsigned int getSpacing() const; + /** + * Gets the spacing between the border of this button and its caption. + * + * @return spacing. + */ + unsigned int getSpacing() const; - /** - * Adjusts the buttons size to fit the content. - */ - virtual void adjustSize(); + /** + * Adjusts the buttons size to fit the content. + */ + void adjustSize(); - /** - * Checks if the button is pressed down. Useful when drawing. - * - * @return true if the button is pressed down. - */ - bool isPressed() const; + /** + * Checks if the button is pressed down. Useful when drawing. + * + * @return true if the button is pressed down. + */ + bool isPressed() const; - //Inherited from Widget + //Inherited from Widget - void draw(Graphics* graphics) override; + virtual void draw(Graphics* graphics); - void drawBorder(Graphics* graphics) override; + virtual void drawBorder(Graphics* graphics); - // Inherited from FocusListener + // Inherited from FocusListener - void focusLost(const Event& event) override; + virtual void focusLost(const Event& event); - // Inherited from MouseListener + // Inherited from MouseListener - void mousePressed(MouseEvent& mouseEvent) override; + virtual void mousePressed(MouseEvent& mouseEvent); - void mouseReleased(MouseEvent& mouseEvent) override; + virtual void mouseReleased(MouseEvent& mouseEvent); - void mouseEntered(MouseEvent& mouseEvent) override; + virtual void mouseEntered(MouseEvent& mouseEvent); - void mouseExited(MouseEvent& mouseEvent) override; + virtual void mouseExited(MouseEvent& mouseEvent); - void mouseDragged(MouseEvent& mouseEvent) override; + virtual void mouseDragged(MouseEvent& mouseEvent); - // Inherited from KeyListener + // Inherited from KeyListener - void keyPressed(KeyEvent& keyEvent) override; + virtual void keyPressed(KeyEvent& keyEvent); - void keyReleased(KeyEvent& keyEvent) override; + virtual void keyReleased(KeyEvent& keyEvent); - 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/guisan-dev/include/guisan/widgets/checkbox.hpp b/guisan-dev/include/guisan/widgets/checkbox.hpp index 14545537..0820f7d1 100644 --- a/guisan-dev/include/guisan/widgets/checkbox.hpp +++ b/guisan-dev/include/guisan/widgets/checkbox.hpp @@ -66,124 +66,123 @@ 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 selected 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() - = default; + /** + * Destructor. + */ + virtual ~CheckBox() { } - /** - * 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 + */ + 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 + */ + 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 - void draw(Graphics* graphics) override; + virtual void draw(Graphics* graphics); - void drawBorder(Graphics* graphics) override; + virtual void drawBorder(Graphics* graphics); - // Inherited from KeyListener + // Inherited from KeyListener - void keyPressed(KeyEvent& keyEvent) override; + virtual void keyPressed(KeyEvent& keyEvent); - // Inherited from MouseListener + // Inherited from MouseListener - void mouseClicked(MouseEvent& mouseEvent) override; + virtual void mouseClicked(MouseEvent& mouseEvent); - void mouseDragged(MouseEvent& mouseEvent) override; + virtual void mouseDragged(MouseEvent& mouseEvent); - 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/guisan-dev/include/guisan/widgets/container.hpp b/guisan-dev/include/guisan/widgets/container.hpp index 26fffd0e..ad6c0bc9 100644 --- a/guisan-dev/include/guisan/widgets/container.hpp +++ b/guisan-dev/include/guisan/widgets/container.hpp @@ -65,113 +65,113 @@ namespace gcn { - /** - * An implementation of a container able to contain other widgets. A widget's - * position in the container is relative to the container itself and not the screen. - * A container is the most common widget to use as the Gui's top widget as makes the Gui - * able to contain more than one widget. - * - * @see Gui::setTop - */ - class GCN_CORE_DECLSPEC Container : public BasicContainer - { - public: + /** + * An implementation of a container able to contain other widgets. A widget's + * position in the container is relative to the container itself and not the screen. + * A container is the most common widget to use as the Gui's top widget as makes the Gui + * able to contain more than one widget. + * + * @see Gui::setTop + */ + class GCN_CORE_DECLSPEC Container: public BasicContainer + { + public: - /** - * Constructor. A container is opauqe as default, if you want a - * none opaque container call setQpaque(false). - * - * @see setOpaque, isOpaque - */ - Container(); + /** + * Constructor. A container is opauqe as default, if you want a + * none opaque container call setQpaque(false). + * + * @see setOpaque, isOpaque + */ + Container(); - /** - * Destructor. - */ - virtual ~Container(); + /** + * Destructor. + */ + virtual ~Container(); - /** - * Sets the container to be opaque or not. If the container - * is opaque it's background will be drawn, if it's not opaque - * it's background will not be drawn, and thus making the container - * completely transparent. - * - * NOTE: This is not the same as to set visibility. A non visible - * container will not itself nor will it draw it's content. - * - * @param opaque True if the container should be opaque, false otherwise. - * @see isOpaque - */ - virtual void setOpaque(bool opaque); + /** + * Sets the container to be opaque or not. If the container + * is opaque it's background will be drawn, if it's not opaque + * it's background will not be drawn, and thus making the container + * completely transparent. + * + * NOTE: This is not the same as to set visibility. A non visible + * container will not itself nor will it draw it's content. + * + * @param opaque True if the container should be opaque, false otherwise. + * @see isOpaque + */ + void setOpaque(bool opaque); - /** - * Checks if the container is opaque or not. - * - * @return true if the container is opaque, false otherwise. - * @see setOpaque - */ - virtual bool isOpaque() const; + /** + * Checks if the container is opaque or not. + * + * @return true if the container is opaque, false otherwise. + * @see setOpaque + */ + bool isOpaque() const; - /** - * Adds a widget to the container. - * - * @param widget The widget to add. - * @see remove, clear - */ - void add(Widget* widget) override; + /** + * Adds a widget to the container. + * + * @param widget The widget to add. + * @see remove, clear + */ + virtual void add(Widget* widget); - /** - * Adds a widget to the container and also specifices the widget's - * postion in the container. The position is relative to the container - * and not relative to the screen. - * - * @param widget The widget to add. - * @param x The x coordinat for the widget. - * @param y The y coordinat for the widget. - * @see remove, clear - */ - virtual void add(Widget* widget, int x, int y); + /** + * Adds a widget to the container and also specifices the widget's + * postion in the container. The position is relative to the container + * and not relative to the screen. + * + * @param widget The widget to add. + * @param x The x coordinat for the widget. + * @param y The y coordinat for the widget. + * @see remove, clear + */ + virtual void add(Widget* widget, int x, int y); - /** - * Removes a widget from the Container. - * - * @param widget The widget to remove. - * @throws Exception when the widget has not been added to the - * container. - * @see add, clear - */ - void remove(Widget* widget) override; + /** + * Removes a widget from the Container. + * + * @param widget The widget to remove. + * @throws Exception when the widget has not been added to the + * container. + * @see add, clear + */ + virtual void remove(Widget* widget); - /** - * Clears the container of all widgets. - * - * @see add, remove - */ - void clear() override; + /** + * Clears the container of all widgets. + * + * @see add, remove + */ + virtual void clear(); - /** - * Finds a widget given an id. - * - * @param id The id to find a widget by. - * @return A widget with a corrosponding id, NULL if no widget - * is found. - * @see Widget::setId - */ - Widget* findWidgetById(const std::string& id) override; + /** + * Finds a widget given an id. + * + * @param id The id to find a widget by. + * @return A widget with a corrosponding id, NULL if no widget + * is found. + * @see Widget::setId + */ + virtual Widget* findWidgetById(const std::string &id); - // Inherited from Widget + // Inherited from Widget - void draw(Graphics* graphics) override; + virtual void draw(Graphics* graphics); - void drawBorder(Graphics* graphics) override; + virtual void drawBorder(Graphics* graphics); - protected: - /** - * True if the container is opaque, false otherwise. - */ - bool mOpaque; - }; + protected: + /** + * True if the container is opaque, false otherwise. + */ + bool mOpaque; + }; } #endif // end GCN_CONTAINER_HPP diff --git a/guisan-dev/include/guisan/widgets/dropdown.hpp b/guisan-dev/include/guisan/widgets/dropdown.hpp index 3e35c4e9..89edc525 100644 --- a/guisan-dev/include/guisan/widgets/dropdown.hpp +++ b/guisan-dev/include/guisan/widgets/dropdown.hpp @@ -72,229 +72,230 @@ namespace gcn { - /** - * An implementation of a drop downable list from which an item can be selected. - * The drop down consists of an internal ScrollArea and an internal ListBox. - * The drop down also uses an internal FocusHandler to handle the focus of the - * internal ScollArea and the internal ListBox. The scroll area and the list box - * can be passed to the drop down if a custom scroll area and or a custom list box - * is preferable. - * - * To be able display a list the drop down uses a user provided list model. - * A list model can be any class that implements the ListModel interface. - * - * If an item is selected in the drop down a select event will be sent to all selection - * listeners of the drop down. If an item is selected by using a mouse click or by using - * the enter or space key an action event will be sent to all action listeners of the - * drop down. - */ - class GCN_CORE_DECLSPEC DropDown : - public ActionListener, - public BasicContainer, - public KeyListener, - public MouseListener, - public FocusListener, - public SelectionListener - { - public: - /** - * Contructor. - * - * @param listModel the ListModel to use. - * @param scrollArea the ScrollArea to use. - * @param listBox the listBox to use. - * @see ListModel, ScrollArea, ListBox. - */ - explicit DropDown(ListModel* listModel = nullptr, - ScrollArea* scrollArea = nullptr, - ListBox* listBox = nullptr); + /** + * An implementation of a drop downable list from which an item can be selected. + * The drop down consists of an internal ScrollArea and an internal ListBox. + * The drop down also uses an internal FocusHandler to handle the focus of the + * internal ScollArea and the internal ListBox. The scroll area and the list box + * can be passed to the drop down if a custom scroll area and or a custom list box + * is preferable. + * + * To be able display a list the drop down uses a user provided list model. + * A list model can be any class that implements the ListModel interface. + * + * If an item is selected in the drop down a select event will be sent to all selection + * listeners of the drop down. If an item is selected by using a mouse click or by using + * the enter or space key an action event will be sent to all action listeners of the + * drop down. + */ + class GCN_CORE_DECLSPEC DropDown : + public ActionListener, + public BasicContainer, + public KeyListener, + public MouseListener, + public FocusListener, + public SelectionListener + { + public: + /** + * Contructor. + * + * @param listModel the ListModel to use. + * @param scrollArea the ScrollArea to use. + * @param listBox the listBox to use. + * @see ListModel, ScrollArea, ListBox. + */ + DropDown(ListModel *listModel = NULL, + ScrollArea *scrollArea = NULL, + ListBox *listBox = NULL); - /** -* Destructor. -*/ - virtual ~DropDown(); + /** + * Destructor. + */ + virtual ~DropDown(); - /** -* Gets the selected item as an index in the list model. -* -* @return the selected item as an index in the list model. -* @see setSelected -*/ - int getSelected() const; + /** + * Gets the selected item as an index in the list model. + * + * @return the selected item as an index in the list model. + * @see setSelected + */ + int getSelected() const; - /** -* Sets the selected item. The selected item is represented by -* an index from the list model. -* -* @param selected the selected item as an index from the list model. -* @see getSelected -*/ - void setSelected(int selected); + /** + * Sets the selected item. The selected item is represented by + * an index from the list model. + * + * @param selected the selected item as an index from the list model. + * @see getSelected + */ + void setSelected(int selected); - /** -* Sets the list model to use when displaying the list. -* -* @param listModel the list model to use. -* @see getListModel -*/ - void setListModel(ListModel* listModel); + /** + * Sets the list model to use when displaying the list. + * + * @param listModel the list model to use. + * @see getListModel + */ + void setListModel(ListModel *listModel); - /** -* Gets the list model used. -* -* @return the ListModel used. -* @see setListModel -*/ - ListModel* getListModel(); + /** + * Gets the list model used. + * + * @return the ListModel used. + * @see setListModel + */ + ListModel *getListModel(); - /** -* Adjusts the height of the drop down to fit the height of the -* drop down's parent's height. It's used to not make the drop down -* draw itself outside of it's parent if folded down. -*/ - void adjustHeight(); + /** + * Adjusts the height of the drop down to fit the height of the + * drop down's parent's height. It's used to not make the drop down + * draw itself outside of it's parent if folded down. + */ + void adjustHeight(); - /** -* Adds a selection listener to the drop down. When the selection -* changes an event will be sent to all selection listeners of the -* drop down. -* -* @param selectionListener the selection listener to add. -* @since 0.8.0 -*/ - void addSelectionListener(SelectionListener* selectionListener); + /** + * Adds a selection listener to the drop down. When the selection + * changes an event will be sent to all selection listeners of the + * drop down. + * + * @param selectionListener the selection listener to add. + * @since 0.8.0 + */ + void addSelectionListener(SelectionListener* selectionListener); - /** -* Removes a selection listener from the drop down. -* -* @param selectionListener the selection listener to remove. -* @since 0.8.0 -*/ - void removeSelectionListener(SelectionListener* selectionListener); + /** + * Removes a selection listener from the drop down. + * + * @param selectionListener the selection listener to remove. + * @since 0.8.0 + */ + void removeSelectionListener(SelectionListener* selectionListener); - // Inherited from Widget + // Inherited from Widget - void draw(Graphics* graphics) override; + virtual void draw(Graphics* graphics); - void drawBorder(Graphics* graphics) override; + virtual void drawBorder(Graphics* graphics); - void setBaseColor(const Color& color) override; + void setBaseColor(const Color& color); - void setBackgroundColor(const Color& color) override; + void setBackgroundColor(const Color& color); - void setForegroundColor(const Color& color) override; + void setForegroundColor(const Color& color); - void setFont(Font* font) override; + void setFont(Font *font); - void setSelectionColor(const Color& color) override; + void setSelectionColor(const Color& color); - // Inherited from BasicContainer + // Inherited from BasicContainer - Rectangle getChildrenArea() override; + virtual Rectangle getChildrenArea(); - // Inherited from FocusListener + // Inherited from FocusListener - void focusLost(const Event& event) override; + virtual void focusLost(const Event& event); - // Inherited from ActionListener + // Inherited from ActionListener - void action(const ActionEvent& actionEvent) override; + virtual void action(const ActionEvent& actionEvent); - // Inherited from DeathListener + // Inherited from DeathListener - void death(const Event& event) override; + virtual void death(const Event& event); - // Inherited from KeyListener + // Inherited from KeyListener - void keyPressed(KeyEvent& keyEvent) override; + virtual void keyPressed(KeyEvent& keyEvent); - // Inherited from MouseListener + // Inherited from MouseListener - void mousePressed(MouseEvent& mouseEvent) override; + virtual void mousePressed(MouseEvent& mouseEvent); - void mouseReleased(MouseEvent& mouseEvent) override; + virtual void mouseReleased(MouseEvent& mouseEvent); - void mouseWheelMovedUp(MouseEvent& mouseEvent) override; + virtual void mouseWheelMovedUp(MouseEvent& mouseEvent); - void mouseWheelMovedDown(MouseEvent& mouseEvent) override; + virtual void mouseWheelMovedDown(MouseEvent& mouseEvent); - void mouseDragged(MouseEvent& mouseEvent) override; + virtual void mouseDragged(MouseEvent& mouseEvent); - // Inherited from SelectionListener + // Inherited from SelectionListener - void valueChanged(const SelectionEvent& event) override; + virtual void valueChanged(const SelectionEvent& event); - protected: - /** -* Draws the button with the little down arrow. -* -* @param graphics a Graphics object to draw with. -*/ - virtual void drawButton(Graphics* graphics); + protected: + /** + * Draws the button with the little down arrow. + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawButton(Graphics *graphics); - /** -* Sets the DropDown Widget to dropped-down mode. -*/ - virtual void dropDown(); + /** + * Sets the DropDown Widget to dropped-down mode. + */ + virtual void dropDown(); - /** -* Sets the DropDown Widget to folded-up mode. -*/ - virtual void foldUp(); + /** + * Sets the DropDown Widget to folded-up mode. + */ + virtual void foldUp(); - bool mDroppedDown; + bool mDroppedDown; - /** -* Distributes a value changed event to all selection listeners -* of the drop down. -* -* @since 0.8.0 -*/ - void distributeValueChangedEvent(); + /** + * Distributes a value changed event to all selection listeners + * of the drop down. + * + * @since 0.8.0 + */ + void distributeValueChangedEvent(); - bool mPushed; + bool mPushed; - /** -* Holds what the height is if the drop down is folded up. Used when -* checking if the list of the drop down was clicked or if the upper part -* of the drop down was clicked on a mouse click -*/ - int mFoldedUpHeight{}; + /** + * Holds what the height is if the drop down is folded up. Used when + * checking if the list of the drop down was clicked or if the upper part + * of the drop down was clicked on a mouse click + */ + int mFoldedUpHeight; + + /** + * The scroll area used. + */ + ScrollArea* mScrollArea; + ListBox* mListBox; + FocusHandler mInternalFocusHandler; + bool mInternalScrollArea; + bool mInternalListBox; + bool mIsDragged; - /** -* The scroll area used. -*/ - ScrollArea* mScrollArea; - ListBox* mListBox; - FocusHandler mInternalFocusHandler; - bool mInternalScrollArea; - bool mInternalListBox; - bool mIsDragged; + /** + * Typedef. + */ + typedef std::list SelectionListenerList; + + /** + * The selection listener's of the drop down. + */ + SelectionListenerList mSelectionListeners; + + /** + * Typedef. + */ + typedef SelectionListenerList::iterator SelectionListenerIterator; - /** -* Typedef. -*/ - typedef std::list SelectionListenerList; - - /** -* The selection listener's of the drop down. -*/ - SelectionListenerList mSelectionListeners; - - /** -* Typedef. -*/ - typedef SelectionListenerList::iterator SelectionListenerIterator; - }; + }; } #endif // end GCN_DROPDOWN_HPP diff --git a/guisan-dev/include/guisan/widgets/icon.hpp b/guisan-dev/include/guisan/widgets/icon.hpp index 3f88f7b1..63604145 100644 --- a/guisan-dev/include/guisan/widgets/icon.hpp +++ b/guisan-dev/include/guisan/widgets/icon.hpp @@ -63,51 +63,51 @@ namespace gcn { - /** - * Implements an icon capable of displaying an image. - */ - class GCN_CORE_DECLSPEC Icon : public Widget - { - public: - /** - * Constructor. - * - * @param filename The filename of the image to display. - */ - Icon(const std::string& filename); + /** + * Implements an icon capable of displaying an image. + */ + class GCN_CORE_DECLSPEC Icon: public Widget + { + public: + /** + * Constructor. + * + * @param filename The filename of the image to display. + */ + Icon(const std::string& filename); - /** - * Constructor. - * - * @param image The image to display. - */ - Icon(Image* image); + /** + * Constructor. + * + * @param image The image to display. + */ + Icon(Image* image); - /** - * Descructor. - */ - virtual ~Icon(); + /** + * Descructor. + */ + virtual ~Icon(); - // Inherited from Widget + // Inherited from Widget - void draw(Graphics* graphics) override; + virtual void draw(Graphics* graphics); - void drawBorder(Graphics* graphics) override; + virtual void drawBorder(Graphics* graphics); - protected: - /** - * The image to display. - */ - Image* mImage; + protected: + /** + * The image to display. + */ + Image* mImage; - /** - * True if the image has been loaded internally, false otherwise. - * An image not loaded internally should not be deleted in the - * destructor. - */ - bool mInternalImage; - }; + /** + * True if the image has been loaded internally, false otherwise. + * An image not loaded internally should not be deleted in the + * destructor. + */ + bool mInternalImage; + }; } #endif // end GCN_ICON_HPP diff --git a/guisan-dev/include/guisan/widgets/imagebutton.hpp b/guisan-dev/include/guisan/widgets/imagebutton.hpp index 16083af4..8029e38b 100644 --- a/guisan-dev/include/guisan/widgets/imagebutton.hpp +++ b/guisan-dev/include/guisan/widgets/imagebutton.hpp @@ -62,66 +62,66 @@ namespace gcn { - class Image; + class Image; - /** - * A simple button that displays an image instead of a caption. - */ - class GCN_CORE_DECLSPEC ImageButton : public Button - { - public: - /** - * Constructor. - * - * @param filename The filename of the image to display. - */ - ImageButton(const std::string& filename); + /** + * A simple button that displays an image instead of a caption. + */ + class GCN_CORE_DECLSPEC ImageButton : public gcn::Button + { + public: + /** + * Constructor. + * + * @param filename The filename of the image to display. + */ + ImageButton(const std::string& filename); - /** - * Constructor. - * - * @param image The image to display. - */ - ImageButton(Image* image); + /** + * Constructor. + * + * @param image The image to display. + */ + ImageButton(Image* image); - /** - * Destructor. - */ - virtual ~ImageButton(); + /** + * Destructor. + */ + virtual ~ImageButton(); - /** - * Adjusts the size of the image button to fit the image. - */ - void adjustSize() override; + /** + * Adjusts the size of the image button to fit the image. + */ + void adjustSize(); - /** - * Sets the image to display. - * - * @param image The image to display. - */ - void setImage(Image* image); + /** + * Sets the image to display. + * + * @param image The image to display. + */ + void setImage(Image* image); - /** - * Gets the image of the image button. - * - * @return The image of the image button. - */ - Image* getImage(); + /** + * Gets the image of the image button. + * + * @return The image of the image button. + */ + Image* getImage(); - // Inherited from Widget + // Inherited from Widget - void draw(Graphics* graphics) override; + void draw(gcn::Graphics* graphics); - protected: - Image* mImage; + protected: + gcn::Image* mImage; - /** - * True if the image has been loaded internally, false otherwise. - * An image not loaded internally should not be deleted in the - * destructor. - */ - bool mInternalImage; - }; + /** + * True if the image has been loaded internally, false otherwise. + * An image not loaded internally should not be deleted in the + * destructor. + */ + bool mInternalImage; + }; } #endif diff --git a/guisan-dev/include/guisan/widgets/imagetextbutton.hpp b/guisan-dev/include/guisan/widgets/imagetextbutton.hpp new file mode 100644 index 00000000..816c58d7 --- /dev/null +++ b/guisan-dev/include/guisan/widgets/imagetextbutton.hpp @@ -0,0 +1,156 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson + * + * Js_./ + * Per Larsson a.k.a finalman _RqZ{a<^_aa + * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// + * _Qhm`] _f "'c 1!5m + * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' + * binary forms, with or without )4d[#7r, . ' )d`)[ + * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' + * that the following conditions are met: j<. a J@\ + * this list of conditions and the j(]1u + +#include "guisan/platform.hpp" +#include "guisan/widgets/imagebutton.hpp" + +namespace gcn +{ + class Image; + + /** + * A simple button that displays an image and a caption. + */ + class GCN_CORE_DECLSPEC ImageTextButton : public gcn::ImageButton + { + public: + /** + * Constructor. + * + * @param filename The filename of the image to display. + * @param caption The text to display. + */ + ImageTextButton(const std::string& filename, std::string& caption); + + /** + * Constructor. + * + * @param image The image to display. + * @param caption The text to display. + */ + ImageTextButton(Image* image, std::string& caption); + + /** + * Destructor. + */ + virtual ~ImageTextButton(); + + /** + * Adjusts the size of the image button to fit the image. + */ + void adjustSize(); + + /** + * Sets the image to display. + * + * @param image The image to display. + */ + void setImage(Image* image); + + /** + * Gets the image of the image button. + * + * @return The image of the image button. + */ + Image* getImage(); + + + // Inherited from Widget + + void draw(gcn::Graphics* graphics); + + /** + * Sets the alignment for the caption. The alignment is relative + * to the center of the button. + * + * @param alignment ImageTextButton::TOP, ImageTextButton::RIGHT, ImageTextButton::BOTTOM or ImageTextButton::LEFT. + */ + void setAlignment(unsigned int alignment); + + /** + * Gets the alignment for the caption. The alignment is relative to + * the center of the button. + * + * @return alignment of caption. ImageTextButton::TOP, ImageTextButton::RIGHT, ImageTextButton::BOTTOM or ImageTextButton::LEFT. + */ + unsigned int getAlignment() const; + + enum + { + TOP, + RIGHT, + BOTTOM, + LEFT + }; + + protected: + gcn::Image* mImage; + + /** + * True if the image has been loaded internally, false otherwise. + * An image not loaded internally should not be deleted in the + * destructor. + */ + bool mInternalImage; + unsigned int mAlignment; + }; +} +#endif diff --git a/guisan-dev/include/guisan/widgets/inputbox.hpp b/guisan-dev/include/guisan/widgets/inputbox.hpp new file mode 100644 index 00000000..df4ec60c --- /dev/null +++ b/guisan-dev/include/guisan/widgets/inputbox.hpp @@ -0,0 +1,144 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson + * Copyright (c) 2017, 2018, 2019 Gwilherm Baudic + * Js_./ + * Per Larsson a.k.a finalman _RqZ{a<^_aa + * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// + * _Qhm`] _f "'c 1!5m + * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' + * binary forms, with or without )4d[#7r, . ' )d`)[ + * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' + * that the following conditions are met: j<. a J@\ + * this list of conditions and the j(]1u + +#include "guisan/mouselistener.hpp" +#include "guisan/actionlistener.hpp" +#include "guisan/platform.hpp" +#include "guisan/widgets/window.hpp" +#include "guisan/widgets/button.hpp" +#include "guisan/widgets/label.hpp" +#include "guisan/widgets/textfield.hpp" +#include "guisan/widgets/icon.hpp" + +namespace gcn +{ + /** + * A non-movable window to get a short string from the user. + */ + class GCN_CORE_DECLSPEC InputBox : public Window + { + public: + + /** + * Constructor. + * + * @param caption the InputBox caption. + * @param message the message to display in the InputBox + * @param ok the string corresponding to the "OK" button + * @param cancel the string corresponding to the "Cancel" button + */ + InputBox(const std::string& caption, const std::string& message, const std::string &ok = "OK", const std::string &cancel = "Cancel"); + + /** + * Destructor. + */ + virtual ~InputBox(); + + /** + * Add this InputBox to a parent container, centered both horizontally and vertically + * If instead, you want to place it somewhere else, use Container::add(). + * + * @param container parent container + */ + void addToContainer(Container* container); + + /** + * Get the text that was input by the user + * Use in conjunction with getClickedButton() to tell an empty string from a cancel operation. + * + * @return the text which was typed by the user + */ + std::string getText() const; + + /** + * Get the number of the button that was clicked + * @return 0 for OK, 1 for Cancel + */ + int getClickedButton() const; + + + // Inherited from Widget + + virtual void draw(Graphics* graphics); + + virtual void drawBorder(Graphics* graphics); + + + // Inherited from MouseListener + + virtual void mousePressed(MouseEvent& mouseEvent); + + virtual void mouseDragged(MouseEvent& mouseEvent); + + virtual void mouseReleased(MouseEvent& mouseEvent); + + protected: + std::string mMessage; + int mClickedButton; + + Button *mButtonOK; + Button *mButtonCancel; + Label *mLabel; + TextField *mText; + }; +} + +#endif // end GCN_INPUTBOX_HPP diff --git a/guisan-dev/include/guisan/widgets/label.hpp b/guisan-dev/include/guisan/widgets/label.hpp index b51f3a65..d07fe07d 100644 --- a/guisan-dev/include/guisan/widgets/label.hpp +++ b/guisan-dev/include/guisan/widgets/label.hpp @@ -64,83 +64,83 @@ namespace gcn { - /** - * Implementation of a label capable of displaying a caption. - */ - class GCN_CORE_DECLSPEC Label : public Widget - { - public: - /** - * Constructor. - */ - Label(); + /** + * Implementation of a label capable of displaying a caption. + */ + class GCN_CORE_DECLSPEC Label: public Widget + { + public: + /** + * Constructor. + */ + Label(); - /** - * Constructor. - * - * @param caption The caption of the label. - */ - explicit Label(const std::string& caption); + /** + * Constructor. + * + * @param caption The caption of the label. + */ + Label(const std::string& caption); - /** - * Gets the caption of the label. - * - * @return The caption of the label. - * @see setCaption - */ - virtual const std::string& getCaption() const; + /** + * Gets the caption of the label. + * + * @return The caption of the label. + * @see setCaption + */ + const std::string &getCaption() const; - /** - * Sets the caption of the label. It's advisable to call - * adjustSize after setting of the caption to adjust the - * label's size to fit the caption. - * - * @param caption The caption of the label. - * @see getCaption, adjustSize - */ - virtual void setCaption(const std::string& caption); + /** + * Sets the caption of the label. It's advisable to call + * adjustSize after setting of the caption to adjust the + * label's size to fit the caption. + * + * @param caption The caption of the label. + * @see getCaption, adjustSize + */ + void setCaption(const std::string& caption); - /** - * Sets the alignment for the caption. The alignment is relative - * to the center of the label. - * - * @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. - * @see getAlignment, Graphics - */ - virtual void setAlignment(unsigned int alignment); + /** + * Sets the alignment for the caption. The alignment is relative + * to the center of the label. + * + * @param alignemnt Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. + * @see getAlignment, Graphics + */ + void setAlignment(unsigned int alignment); - /** - * Gets the alignment for the caption. The alignment is relative to - * the center of the label. - * - * @return alignment of caption. Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. - * @see setAlignmentm Graphics - */ - virtual unsigned int getAlignment() const; + /** + * Gets the alignment for the caption. The alignment is relative to + * the center of the label. + * + * @return alignment of caption. Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. + * @see setAlignment, Graphics + */ + unsigned int getAlignment() const; - /** - * Adjusts the label's size to fit the caption size. - */ - virtual void adjustSize(); + /** + * Adjusts the label's size to fit the caption size. + */ + void adjustSize(); - // Inherited from Widget + // Inherited from Widget - void draw(Graphics* graphics) override; + virtual void draw(Graphics* graphics); - void drawBorder(Graphics* graphics) override; + virtual void drawBorder(Graphics* graphics); - protected: - /** - * Holds the caption of the label. - */ - std::string mCaption; + protected: + /** + * Holds the caption of the label. + */ + std::string mCaption; - /** - * Holds the alignment of the caption. - */ - unsigned int mAlignment; - }; + /** + * Holds the alignment of the caption. + */ + unsigned int mAlignment; + }; } #endif // end GCN_LABEL_HPP diff --git a/guisan-dev/include/guisan/widgets/listbox.hpp b/guisan-dev/include/guisan/widgets/listbox.hpp index 0d6f2c00..fc0e0f0b 100644 --- a/guisan-dev/include/guisan/widgets/listbox.hpp +++ b/guisan-dev/include/guisan/widgets/listbox.hpp @@ -67,189 +67,188 @@ namespace gcn { - class SelectionListener; + class SelectionListener; - /** - * An implementation of a list box where an item can be selected. - * - * To be able display a list the list box uses a user provided list model. - * A list model can be any class that implements the ListModel interface. - * - * If an item is selected in the list box a select event will be sent to all selection - * listeners of the list box. If an item is selected by using a mouse click or by using - * the enter or space key an action event will be sent to all action listeners of the - * list box. - */ - class GCN_CORE_DECLSPEC ListBox : - public Widget, - public MouseListener, - public KeyListener - { - public: - /** - * Constructor. - */ - ListBox(); + /** + * An implementation of a list box where an item can be selected. + * + * To be able display a list the list box uses a user provided list model. + * A list model can be any class that implements the ListModel interface. + * + * If an item is selected in the list box a select event will be sent to all selection + * listeners of the list box. If an item is selected by using a mouse click or by using + * the enter or space key an action event will be sent to all action listeners of the + * list box. + */ + class GCN_CORE_DECLSPEC ListBox : + public Widget, + public MouseListener, + public KeyListener + { + public: + /** + * Constructor. + */ + ListBox(); - /** - * Constructor. - * - * @param listModel the list model to use. - */ - ListBox(ListModel* listModel); + /** + * Constructor. + * + * @param listModel the list model to use. + */ + ListBox(ListModel *listModel); - /** - * Destructor. - */ - virtual ~ListBox() - = default; + /** + * Destructor. + */ + virtual ~ListBox() { } - /** - * Gets the selected item as an index in the list model. - * - * @return the selected item as an index in the list model. - * @see setSelected - */ - int getSelected() const; + /** + * Gets the selected item as an index in the list model. + * + * @return the selected item as an index in the list model. + * @see setSelected + */ + int getSelected() const; - /** - * Sets the selected item. The selected item is represented by - * an index from the list model. - * - * @param selected the selected item as an index from the list model. - * @see getSelected - */ - void setSelected(int selected); + /** + * Sets the selected item. The selected item is represented by + * an index from the list model. + * + * @param selected the selected item as an index from the list model. + * @see getSelected + */ + void setSelected(int selected); - /** - * Sets the list model to use. - * - * @param listModel the list model to use. - * @see getListModel - */ - void setListModel(ListModel* listModel); + /** + * Sets the list model to use. + * + * @param listModel the list model to use. + * @see getListModel + */ + void setListModel(ListModel *listModel); - /** - * Gets the list model used. - * - * @return the list model used. - * @see setListModel - */ - ListModel* getListModel(); + /** + * Gets the list model used. + * + * @return the list model used. + * @see setListModel + */ + ListModel *getListModel(); - /** - * Adjusts the size of the list box to fit it's list model. - */ - void adjustSize(); + /** + * Adjusts the size of the list box to fit it's list model. + */ + void adjustSize(); - /** - * Checks whether the list box wraps when selecting items with a keyboard. - * - * Wrapping means that the selection of items will be wrapped. That is, if - * the first item is selected and up is pressed, the last item will get - * selected. If the last item is selected and down is pressed, the first item - * will get selected. - * - * @return true if wrapping is enabled, fasle otherwise. - * @see setWrappingEnabled - */ - bool isWrappingEnabled() const; + /** + * Checks whether the list box wraps when selecting items with a keyboard. + * + * Wrapping means that the selection of items will be wrapped. That is, if + * the first item is selected and up is pressed, the last item will get + * selected. If the last item is selected and down is pressed, the first item + * will get selected. + * + * @return true if wrapping is enabled, fasle otherwise. + * @see setWrappingEnabled + */ + bool isWrappingEnabled() const; - /** - * Sets the list box to wrap or not when selecting items with a keyboard. - * - * Wrapping means that the selection of items will be wrapped. That is, if - * the first item is selected and up is pressed, the last item will get - * selected. If the last item is selected and down is pressed, the first item - * will get selected. - * - * @see isWrappingEnabled - */ - void setWrappingEnabled(bool wrappingEnabled); + /** + * Sets the list box to wrap or not when selecting items with a keyboard. + * + * Wrapping means that the selection of items will be wrapped. That is, if + * the first item is selected and up is pressed, the last item will get + * selected. If the last item is selected and down is pressed, the first item + * will get selected. + * + * @see isWrappingEnabled + */ + void setWrappingEnabled(bool wrappingEnabled); - /** - * Adds a selection listener to the list box. When the selection - * changes an event will be sent to all selection listeners of the - * list box. - * - * @param selectionListener The selection listener to add. - * @since 0.8.0 - */ - void addSelectionListener(SelectionListener* selectionListener); + /** + * Adds a selection listener to the list box. When the selection + * changes an event will be sent to all selection listeners of the + * list box. + * + * @param selectionListener The selection listener to add. + * @since 0.8.0 + */ + void addSelectionListener(SelectionListener* selectionListener); - /** - * Removes a selection listener from the list box. - * - * @param selectionListener The selection listener to remove. - * @since 0.8.0 - */ - void removeSelectionListener(SelectionListener* selectionListener); + /** + * Removes a selection listener from the list box. + * + * @param selectionListener The selection listener to remove. + * @since 0.8.0 + */ + void removeSelectionListener(SelectionListener* selectionListener); - // Inherited from Widget + // Inherited from Widget - void draw(Graphics* graphics) override; + virtual void draw(Graphics* graphics); - void drawBorder(Graphics* graphics) override; + virtual void drawBorder(Graphics* graphics); - void logic() override; + virtual void logic(); - // Inherited from KeyListener + // Inherited from KeyListener - void keyPressed(KeyEvent& keyEvent) override; + virtual void keyPressed(KeyEvent& keyEvent); - // Inherited from MouseListener + // Inherited from MouseListener - void mousePressed(MouseEvent& mouseEvent) override; + virtual void mousePressed(MouseEvent& mouseEvent); - void mouseWheelMovedUp(MouseEvent& mouseEvent) override; + virtual void mouseWheelMovedUp(MouseEvent& mouseEvent); - void mouseWheelMovedDown(MouseEvent& mouseEvent) override; + virtual void mouseWheelMovedDown(MouseEvent& mouseEvent); + + virtual void mouseDragged(MouseEvent& mouseEvent); - void mouseDragged(MouseEvent& mouseEvent) override; + + protected: + /** + * Distributes a value changed event to all selection listeners + * of the list box. + * + * @since 0.8.0 + */ + void distributeValueChangedEvent(); + /** + * The list model to use. + */ + ListModel *mListModel; - protected: - /** - * Distributes a value changed event to all selection listeners - * of the list box. - * - * @since 0.8.0 - */ - void distributeValueChangedEvent(); + /** + * The selected item as an index in the list model. + */ + int mSelected; - /** - * The list model to use. - */ - ListModel* mListModel{}; + /** + * True if wrapping is enabled, false otherwise. + */ + bool mWrappingEnabled; - /** - * The selected item as an index in the list model. - */ - int mSelected; + /** + * Typdef. + */ + typedef std::list SelectionListenerList; + + /** + * The selection listeners of the list box. + */ + SelectionListenerList mSelectionListeners; - /** - * True if wrapping is enabled, false otherwise. - */ - bool mWrappingEnabled; - - /** - * Typdef. - */ - typedef std::list SelectionListenerList; - - /** - * The selection listeners of the list box. - */ - SelectionListenerList mSelectionListeners; - - /** - * Typedef. - */ - typedef SelectionListenerList::iterator SelectionListenerIterator; - }; + /** + * Typedef. + */ + typedef SelectionListenerList::iterator SelectionListenerIterator; + }; } #endif // end GCN_LISTBOX_HPP diff --git a/guisan-dev/include/guisan/widgets/messagebox.hpp b/guisan-dev/include/guisan/widgets/messagebox.hpp new file mode 100644 index 00000000..35655e5c --- /dev/null +++ b/guisan-dev/include/guisan/widgets/messagebox.hpp @@ -0,0 +1,247 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson + * Copyright (c) 2017 Gwilherm Baudic + * Js_./ + * Per Larsson a.k.a finalman _RqZ{a<^_aa + * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// + * _Qhm`] _f "'c 1!5m + * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' + * binary forms, with or without )4d[#7r, . ' )d`)[ + * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' + * that the following conditions are met: j<. a J@\ + * this list of conditions and the j(]1u + +#include "guisan/mouselistener.hpp" +#include "guisan/platform.hpp" +#include "guisan/widgets/window.hpp" +#include "guisan/widgets/button.hpp" +#include "guisan/widgets/label.hpp" +#include "guisan/widgets/icon.hpp" + +namespace gcn +{ + /** + * A non-movable window to display a message with some buttons. + */ + class GCN_CORE_DECLSPEC MessageBox : public Window + { + public: + + /** + * Constructor. + * This version only has a single button labeled "OK". + * + * @param caption the MessageBox caption. + * @param message the message to display in the MessageBox + */ + MessageBox(const std::string& caption, const std::string& message); + + /** + * Constructor. + * + * @param caption the MessageBox caption. + * @param message the message to display in the MessageBox + * @param buttons strings to display as button captions + * @param size length of the buttons array + */ + MessageBox(const std::string& caption, const std::string& message, const std::string *buttons, int size); + + /** + * Destructor. + */ + virtual ~MessageBox(); + + /** + * Gets the index of the clicked button + * + * @return index of clicked button, starting at 0. -1 if not set (i.e., no button clicked yet) + */ + int getClickedButton() const; + + /** + * Sets the MessageBox caption. + * + * @param caption the MessageBox caption. + */ + void setCaption(const std::string& caption); + + /** + * Gets the MessageBox caption. + * + * @return the MessageBox caption. + */ + const std::string& getCaption() const; + + /** + * Sets the alignment for the caption. + * + * @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. + */ + void setAlignment(unsigned int alignment); + + /** + * Gets the alignment for the caption. + * + * @return alignment of caption. + */ + unsigned int getAlignment() const; + + /** + * Sets the position for the button(s) in the MessageBox. + * + * @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. + */ + void setButtonAlignment(unsigned int alignment); + + /** + * Gets the position for the button(s) in the MessageBox. + * + * @return alignment of buttons. + */ + unsigned int getButtonAlignment() const; + + /** + * Sets the padding of the window which is the distance between the + * window border and the content. + * + * @param padding the padding value. + */ + void setPadding(unsigned int padding); + + /** + * Gets the padding. + * + * @return the padding value. + */ + unsigned int getPadding() const; + + /** + * Sets the title bar height. + * + * @param height the title height value. + */ + void setTitleBarHeight(unsigned int height); + + /** + * Gets the title bar height. + * + * @return the title bar height. + */ + unsigned int getTitleBarHeight(); + + /** + * Check if the window is movable. + * + * @return true or false. + */ + bool isMovable() const; + + /** + * Sets the MessageBox to be opaque. If it's not opaque, the content area + * will not be filled with a color. + * + * @param opaque true or false. + */ + void setOpaque(bool opaque); + + /** + * Checks if the MessageBox is opaque. + * + * @return true or false. + */ + bool isOpaque(); + + /** + * Add this MessageBox to a parent container, centered both horizontally and vertically + * If instead, you want to place it somewhere else, use Container::add(). + * + * @param container parent container + */ + void addToContainer(Container* container); + + /** + * Resizes the container to fit the content exactly. + */ + virtual void resizeToContent(); + + + // Inherited from BasicContainer + + virtual Rectangle getChildrenArea(); + + + // Inherited from Widget + + virtual void draw(Graphics* graphics); + + virtual void drawBorder(Graphics* graphics); + + + // Inherited from MouseListener + + virtual void mousePressed(MouseEvent& mouseEvent); + + virtual void mouseDragged(MouseEvent& mouseEvent); + + virtual void mouseReleased(MouseEvent& mouseEvent); + + protected: + std::string mMessage; + int mNbButtons; + unsigned int mButtonAlignment; + int mClickedButton; + + Button **mButtons; + Label *mLabel; + }; +} + +#endif // end GCN_MESSAGEBOX_HPP diff --git a/guisan-dev/include/guisan/widgets/progressbar.hpp b/guisan-dev/include/guisan/widgets/progressbar.hpp index 6e852858..ef3e6100 100644 --- a/guisan-dev/include/guisan/widgets/progressbar.hpp +++ b/guisan-dev/include/guisan/widgets/progressbar.hpp @@ -65,147 +65,147 @@ namespace gcn { - /** - * Implementation of a label capable of displaying a caption and a progress bar. - * - * Setting both start and end to 0 creates an "infinite" progressbar with a small rectangle - * moving forward and disappearing. In this mode, it is up to the caller to set the progressbar - * value in the range 0-100 (which indicates the start of the rectangle) - * regularly to achieve animation. - */ - class GCN_CORE_DECLSPEC ProgressBar : public Label - { - public: - /** - * Constructor. - */ - ProgressBar(); + /** + * Implementation of a label capable of displaying a caption and a progress bar. + * + * Setting both start and end to 0 creates an "infinite" progressbar with a small rectangle + * moving forward and disappearing. In this mode, it is up to the caller to set the progressbar + * value in the range 0-100 (which indicates the start of the rectangle) + * regularly to achieve animation. + */ + class GCN_CORE_DECLSPEC ProgressBar: public Label + { + public: + /** + * Constructor. + */ + ProgressBar(); + + /** + * Constructor. + * + * @param start minimum value + * @param end maximum value + * @param value current value + */ + ProgressBar(const unsigned int start, const unsigned int end, const unsigned int value); - /** - * Constructor. - * - * @param start minimum value - * @param end maximum value - * @param value current value - */ - ProgressBar(unsigned int start, unsigned int end, unsigned int value); + /** + * Constructor. + * + * @param caption The caption of the label. + */ + ProgressBar(const std::string& caption); - /** - * Constructor. - * - * @param caption The caption of the label. - */ - explicit ProgressBar(const std::string& caption); + /** + * Gets the caption of the label. + * + * @return The caption of the label. + * @see setCaption + */ + const std::string &getCaption() const; - /** - * Gets the caption of the label. - * - * @return The caption of the label. - * @see setCaption - */ - const std::string& getCaption() const override; + /** + * Sets the caption of the label. + * + * @param caption The caption of the label. + * @see getCaption, adjustSize + */ + void setCaption(const std::string& caption); - /** - * Sets the caption of the label. - * - * @param caption The caption of the label. - * @see getCaption, adjustSize - */ - void setCaption(const std::string& caption) override; + /** + * Sets the alignment for the caption. The alignment is relative + * to the center of the label. + * + * @param alignemnt Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. + * @see getAlignment, Graphics + */ + void setAlignment(unsigned int alignment); - /** - * Sets the alignment for the caption. The alignment is relative - * to the center of the label. - * - * @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. - * @see getAlignment, Graphics - */ - void setAlignment(unsigned int alignment) override; - - /** - * Gets the alignment for the caption. The alignment is relative to - * the center of the label. - * - * @return alignment of caption. Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. - * @see setAlignment, Graphics - */ - unsigned int getAlignment() const override; - - /** - * Sets the minimum value. - * - * @param start the minimum value - * @see getStart - */ - void setStart(unsigned int start); - - /** - * Gets the minimum value. - * - * @return the minimum value - * @see setStart - */ - unsigned int getStart() const; - - /** - * Sets the maximum value. - * - * @param end the maximum value - * @see getEnd - */ - void setEnd(unsigned int end); - - /** - * Gets the maximum value. - * - * @return the maximum value - * @see setEnd - */ - unsigned int getEnd() const; - - /** - * Sets the current progress value. - * - * @param value the current value - * @see getStart - */ - void setValue(unsigned int value); - - /** - * Gets the current progress value. - * - * @return progress value - * @see setValue - */ - unsigned int getValue() const; - - /** - * Adjusts the size of the widget. - */ - void adjustSize() override; + /** + * Gets the alignment for the caption. The alignment is relative to + * the center of the label. + * + * @return alignment of caption. Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. + * @see setAlignment, Graphics + */ + unsigned int getAlignment() const; + + /** + * Sets the minimum value. + * + * @param start the minimum value + * @see getStart + */ + void setStart(const unsigned int start); + + /** + * Gets the minimum value. + * + * @return the minimum value + * @see setStart + */ + unsigned int getStart() const; + + /** + * Sets the maximum value. + * + * @param end the maximum value + * @see getEnd + */ + void setEnd(const unsigned int end); + + /** + * Gets the maximum value. + * + * @return the maximum value + * @see setEnd + */ + unsigned int getEnd() const; + + /** + * Sets the current progress value. + * + * @param value the current value + * @see getStart + */ + void setValue(const unsigned int value); + + /** + * Gets the current progress value. + * + * @return progress value + * @see setValue + */ + unsigned int getValue() const; + + /** + * Adjusts the size of the widget. + */ + void adjustSize(); - // Inherited from Widget + // Inherited from Widget - void draw(Graphics* graphics) override; + virtual void draw(Graphics* graphics); - void drawBorder(Graphics* graphics) override; + virtual void drawBorder(Graphics* graphics); - protected: - /** - * Holds the caption of the label. - */ - std::string mCaption; + protected: + /** + * Holds the caption of the label. + */ + std::string mCaption; - /** - * Holds the alignment of the caption. - */ - unsigned int mAlignment; - - unsigned int mStart{}; //! minimum value of the progressbar - unsigned int mEnd{}; //! maximum value of the progressbar - unsigned int mValue{}; //! current value of the progressbar - }; + /** + * Holds the alignment of the caption. + */ + unsigned int mAlignment; + + unsigned int mStart; //! minimum value of the progressbar + unsigned int mEnd; //! maximum value of the progressbar + unsigned int mValue; //! current value of the progressbar + }; } #endif // end GCN_PROGRESSBAR_HPP diff --git a/guisan-dev/include/guisan/widgets/radiobutton.hpp b/guisan-dev/include/guisan/widgets/radiobutton.hpp index adbd34ce..0b1e0aca 100644 --- a/guisan-dev/include/guisan/widgets/radiobutton.hpp +++ b/guisan-dev/include/guisan/widgets/radiobutton.hpp @@ -67,159 +67,159 @@ namespace gcn { - /** - * Implementation of a radio button where a user can select or deselect - * the radio button and where the status of the radio button is displayed to the user. - * A radio button can belong to a group and when a radio button belongs to a - * group only one radio button can be selected in the group. A radio button is - * capable of displaying a caption. - * - * If a radio button's state changes an action event will be sent to all action - * listeners of the check box. - */ - class GCN_CORE_DECLSPEC RadioButton : - public Widget, - public MouseListener, - public KeyListener - { - public: + /** + * Implementation of a radio button where a user can select or deselect + * the radio button and where the status of the radio button is displayed to the user. + * A radio button can belong to a group and when a radio button belongs to a + * group only one radio button can be selected in the group. A radio button is + * capable of displaying a caption. + * + * If a radio button's state changes an action event will be sent to all action + * listeners of the check box. + */ + class GCN_CORE_DECLSPEC RadioButton : + public Widget, + public MouseListener, + public KeyListener + { + public: - /** - * Constructor. - */ - RadioButton(); + /** + * Constructor. + */ + RadioButton(); - /** - * Constructor. - * - * @param caption The caption of the radio button. - * @param group The group the radio button should belong to. - * @param selected True if the radio button should be selected. - */ - RadioButton(const std::string& caption, - const std::string& group, - bool selected = false); + /** + * Constructor. + * + * @param caption The caption of the radio button. + * @param group The group the radio button should belong to. + * @param selected True if the radio button should be selected. + */ + RadioButton(const std::string &caption, + const std::string &group, + bool selected = false); - /** - * Destructor. - */ - virtual ~RadioButton(); + /** + * Destructor. + */ + virtual ~RadioButton(); - /** - * Checks if the radio button is selected. - * - * @return True if the radio button is selecte, false otherwise. - * @see setSelected - */ - bool isSelected() const; + /** + * Checks if the radio button is selected. + * + * @return True if the radio button is selecte, false otherwise. + * @see setSelected + */ + bool isSelected() const; - /** - * Sets the radio button to selected or not. - * - * @param selected True if the radio button should be selected, - * false otherwise. - * @see isSelected - */ - void setSelected(bool selected); + /** + * Sets the radio button to selected or not. + * + * @param selected True if the radio button should be selected, + * false otherwise. + * @see isSelected + */ + void setSelected(bool selected); - /** - * Gets the caption of the radio button. - * - * @return The caption of the radio button. - * @see setCaption - */ - const std::string& getCaption() const; + /** + * Gets the caption of the radio button. + * + * @return The caption of the radio button. + * @see setCaption + */ + const std::string &getCaption() const; - /** - * Sets the caption of the radio button. It's advisable to call - * adjustSize after setting of the caption to adjust the - * radio button's size to fit the caption. - * - * @param caption The caption of the radio button. - * @see getCaption, adjustSize - */ - void setCaption(const std::string& caption); + /** + * Sets the caption of the radio button. It's advisable to call + * adjustSize after setting of the caption to adjust the + * radio button's size to fit the caption. + * + * @param caption The caption of the radio button. + * @see getCaption, adjustSize + */ + void setCaption(const std::string caption); - /** - * Sets the group the radio button should belong to. Note that - * a radio button group is unique per application, not per Gui object - * as the group is stored in a static map. - * - * @param group The name of the group. - * @see getGroup - */ - void setGroup(const std::string& group); + /** + * Sets the group the radio button should belong to. Note that + * a radio button group is unique per application, not per Gui object + * as the group is stored in a static map. + * + * @param group The name of the group. + * @see getGroup + */ + void setGroup(const std::string &group); - /** - * Gets the group the radio button belongs to. - * - * @return The group the radio button belongs to. - * @see setGroup - */ - const std::string& getGroup() const; + /** + * Gets the group the radio button belongs to. + * + * @return The group the radio button belongs to. + * @see setGroup + */ + const std::string &getGroup() const; - /** - * Adjusts the radio button's size to fit the caption. - */ - void adjustSize(); + /** + * Adjusts the radio button's size to fit the caption. + */ + void adjustSize(); - // Inherited from Widget + // Inherited from Widget - void draw(Graphics* graphics) override; + virtual void draw(Graphics* graphics); - void drawBorder(Graphics* graphics) override; + virtual void drawBorder(Graphics* graphics); - // Inherited from KeyListener + // Inherited from KeyListener - void keyPressed(KeyEvent& keyEvent) override; + virtual void keyPressed(KeyEvent& keyEvent); - // Inherited from MouseListener + // Inherited from MouseListener - void mouseClicked(MouseEvent& mouseEvent) override; + virtual void mouseClicked(MouseEvent& mouseEvent); - void mouseDragged(MouseEvent& mouseEvent) override; + virtual void mouseDragged(MouseEvent& mouseEvent); - protected: - /** - * Draws the box. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawBox(Graphics* graphics); + protected: + /** + * Draws the box. + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawBox(Graphics *graphics); - /** - * True if the radio button is selected, false otherwise. - */ - bool mSelected{}; + /** + * True if the radio button is selected, false otherwise. + */ + bool mSelected; - /** - * Holds the caption of the radio button. - */ - std::string mCaption; + /** + * Holds the caption of the radio button. + */ + std::string mCaption; - /** - * Holds the group of the radio button. - */ - std::string mGroup; + /** + * Holds the group of the radio button. + */ + std::string mGroup; - /** - * Typdef. - */ - typedef std::multimap GroupMap; + /** + * Typdef. + */ + typedef std::multimap GroupMap; - /** - * Typdef. - */ - typedef GroupMap::iterator GroupIterator; + /** + * Typdef. + */ + typedef GroupMap::iterator GroupIterator; - /** - * Holds all available radio button groups. - */ - static GroupMap mGroupMap; - }; + /** + * Holds all available radio button groups. + */ + static GroupMap mGroupMap; + }; } #endif // end GCN_RADIOBUTTON_HPP diff --git a/guisan-dev/include/guisan/widgets/scrollarea.hpp b/guisan-dev/include/guisan/widgets/scrollarea.hpp index fe1bf403..6a723ea8 100644 --- a/guisan-dev/include/guisan/widgets/scrollarea.hpp +++ b/guisan-dev/include/guisan/widgets/scrollarea.hpp @@ -65,424 +65,424 @@ namespace gcn { - /** - * A ScrollArea in which another Widget can be added. It the other Widget - * is bigger then the ScrollArea, the ScrollArea will only display the part - * of the Widget that fits the ScrollArea and make it possible to scroll - * to the other areas of the Widget. - * - * NOTE: A TextBox or a ListBox looks really ugly unless they exist in a - * ScrollArea. - */ - class GCN_CORE_DECLSPEC ScrollArea : - public BasicContainer, - public MouseListener - { - public: - - /** - * Constructor. - */ - ScrollArea(); - - /** - * Constructor. - * - * @param content the content of the ScrollArea. - */ - ScrollArea(Widget* content); - - /** - * Constructor. - * - * @param content the content of the ScrollArea. - * @param hPolicy the policy for the horizontal scrollbar. See enum with - * policies. - * @param vPolicy the policy for the vertical scrollbar. See enum with - * policies. - */ - ScrollArea(Widget* content, unsigned int hPolicy, unsigned int vPolicy); - - /** - * Destructor. - */ - virtual ~ScrollArea(); - - /** - * Sets the content. - * - * @param widget the content of the ScrollArea. - */ - void setContent(Widget* widget); - - /** - * Gets the content. - * - * @return the content of the ScrollArea. - */ - Widget* getContent(); - - /** - * Sets the horizontal scrollbar policy. See enum with policies. - * - * @param hPolicy the policy for the horizontal scrollbar. See enum with - * policies. - */ - void setHorizontalScrollPolicy(unsigned int hPolicy); - - /** - * Gets the horizontal scrollbar policy. See enum with policies. - * - * @return the policy for the horizontal scrollbar policy. See enum with - * policies. - */ - unsigned int getHorizontalScrollPolicy() const; - - /** - * Sets the vertical scrollbar policy. See enum with policies. - * - * @param vPolicy the policy for the vertical scrollbar. See enum with - * policies. - */ - void setVerticalScrollPolicy(unsigned int vPolicy); - - /** - * Gets the vertical scrollbar policy. See enum with policies. - * - * @return the policy for the vertical scrollbar. See enum with - * policies. - */ - unsigned int getVerticalScrollPolicy() const; - - /** - * Sets the horizontal and vertical scrollbar policy. See enum with policies. - * - * @param hPolicy the policy for the horizontal scrollbar. See enum with - * policies. - * @param vPolicy the policy for the vertical scrollbar. See enum with - * policies. - */ - void setScrollPolicy(unsigned int hPolicy, unsigned int vPolicy); - - /** - * Sets the amount to scroll vertically. - * - * @param vScroll the amount to scroll. - */ - void setVerticalScrollAmount(int vScroll); - - /** - * Gets the amount that is scrolled vertically. - * @return the scroll amount on vertical scroll. - */ - int getVerticalScrollAmount() const; - - /** - * Sets the amount to scroll horizontally. - * - * @param hScroll the amount to scroll. - */ - void setHorizontalScrollAmount(int hScroll); - - /** - * Gets the amount that is scrolled horizontally. - * - * @return the scroll amount on horizontal scroll. - */ - int getHorizontalScrollAmount() const; - - /** - * Sets the amount to scroll horizontally and vertically. - * - * @param hScroll the amount to scroll on horizontal scroll. - * @param vScroll the amount to scroll on vertical scroll. - */ - void setScrollAmount(int hScroll, int vScroll); - - /** - * Gets the maximum amount of horizontal scroll. - * - * @return the horizontal max scroll. - */ - int getHorizontalMaxScroll(); - - /** - * Gets the maximum amount of vertical scroll. - * - * @return the vertical max scroll. - */ - int getVerticalMaxScroll(); - - /** - * Sets the width. - * - * @param width the width of the ScrollBar. - */ - void setScrollbarWidth(int width); - - /** - * Gets the width. - - * @return the width of the ScrollBar. - */ - int getScrollbarWidth() const; - - /** - * Sets the amount to scroll in pixels when the left scroll button is - * pushed. - */ - void setLeftButtonScrollAmount(int amount); - - /** - * Sets the amount to scroll in pixels when the right scroll button is - * pushed. - */ - void setRightButtonScrollAmount(int amount); - - /** - * Sets the amount to scroll in pixels when the up scroll button is - * pushed. - */ - void setUpButtonScrollAmount(int amount); - - /** - * Sets the amount to scroll in pixels when the down scroll button is - * pushed. - */ - void setDownButtonScrollAmount(int amount); - - /** - * Gets the amount to scroll in pixels when the left scroll button is - * pushed. - * - * @return the amount to scroll when the left scroll button is pushed. - */ - int getLeftButtonScrollAmount() const; - - /** - * Gets the amount to scroll in pixels when the right scroll button is - * pushed. - * - * @return the amount to scroll when the right scroll button is pushed. - */ - int getRightButtonScrollAmount() const; - - /** - * Gets the amount to scroll in pixels when the up scroll button is - * pushed. - * - * @return the amount to scroll when the up scroll button is pushed. - */ - int getUpButtonScrollAmount() const; - - /** - * Gets the amount to scroll in pixels when the down scroll button is - * pushed. - * - * @return the amount to scroll when the down scroll button is pushed. - */ - int getDownButtonScrollAmount() const; - - - // Inherited from BasicContainer - - void showWidgetPart(Widget* widget, Rectangle area) override; - - Rectangle getChildrenArea() override; - - Widget* getWidgetAt(int x, int y) override; - - - // Inherited from Widget - - void draw(Graphics* graphics) override; - - void drawBorder(Graphics* graphics) override; - - void logic() override; - - void setWidth(int width) override; - - void setHeight(int height) override; - - void setDimension(const Rectangle& dimension) override; - - - // Inherited from MouseListener - - void mousePressed(MouseEvent& mouseEvent) override; - - void mouseReleased(MouseEvent& mouseEvent) override; - - void mouseDragged(MouseEvent& mouseEvent) override; - - void mouseWheelMovedUp(MouseEvent& mouseEvent) override; - - void mouseWheelMovedDown(MouseEvent& mouseEvent) override; - - - /** - * Scrollpolicies for the horizontal and vertical scrollbar. - * The policies are: - * - * SHOW_ALWAYS - Always show the scrollbars no matter what. - * SHOW_NEVER - Never show the scrollbars no matter waht. - * SHOW_AUTO - Show the scrollbars only when needed. That is if the - * content grows larger then the ScrollArea. - */ - enum - { - SHOW_ALWAYS, - SHOW_NEVER, - SHOW_AUTO - }; - - protected: - /** - * Draws the background of the ScrollArea - * (the area behind the content). - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawBackground(Graphics* graphics); - - /** - * Draws the up button. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawUpButton(Graphics* graphics); - - /** - * Draws the down button. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawDownButton(Graphics* graphics); - - /** - * Draws the left button. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawLeftButton(Graphics* graphics); - - /** - * Draws the right button. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawRightButton(Graphics* graphics); - - /** - * Draws the vertical scrollbar. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawVBar(Graphics* graphics); - - /** - * Draws the horizontal scrollbar. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawHBar(Graphics* graphics); - - /** - * Draws the vertical marker. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawVMarker(Graphics* graphics); - - /** - * Draws the horizontal marker. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawHMarker(Graphics* graphics); - - /** - * Checks the policies for the scrollbars. - */ - virtual void checkPolicies(); - - /** - * Gets the up button dimension. - * - * @return the dimension of the up button. - */ - Rectangle getUpButtonDimension() const; - - /** - * Gets the down button dimension. - * - * @return the dimension of the down button. - */ - Rectangle getDownButtonDimension() const; - - /** - * Gets the left button dimension. - * - * @return the dimension of the left button. - */ - Rectangle getLeftButtonDimension() const; - - /** - * Gets the right button dimension. - * - * @return the dimension of the right button. - */ - Rectangle getRightButtonDimension() const; - - /** - * Gets the vertical scrollbar dimension. - * - * @return the dimension of the vertical scrollbar. - */ - Rectangle getVerticalBarDimension() const; - - /** - * Gets the horizontal scrollbar dimension. - * - * @return the dimension of the horizontal scrollbar. - */ - Rectangle getHorizontalBarDimension() const; - - /** - * Gets the vertical marker dimension. - * - * @return the dimension of the vertical marker. - */ - Rectangle getVerticalMarkerDimension(); - - /** - * Gets the horizontal marker dimension. - * - * @return the dimension of the horizontal marker. - */ - Rectangle getHorizontalMarkerDimension(); - - int mVScroll; - int mHScroll; - int mScrollbarWidth; - unsigned int mHPolicy; - unsigned int mVPolicy; - bool mVBarVisible{}; - bool mHBarVisible{}; - bool mUpButtonPressed; - bool mDownButtonPressed; - bool mLeftButtonPressed; - bool mRightButtonPressed; - int mUpButtonScrollAmount; - int mDownButtonScrollAmount; - int mLeftButtonScrollAmount; - int mRightButtonScrollAmount; - bool mIsVerticalMarkerDragged; - bool mIsHorizontalMarkerDragged; - int mHorizontalMarkerDragOffset{}; - int mVerticalMarkerDragOffset{}; - }; + /** + * A ScrollArea in which another Widget can be added. It the other Widget + * is bigger then the ScrollArea, the ScrollArea will only display the part + * of the Widget that fits the ScrollArea and make it possible to scroll + * to the other areas of the Widget. + * + * NOTE: A TextBox or a ListBox looks really ugly unless they exist in a + * ScrollArea. + */ + class GCN_CORE_DECLSPEC ScrollArea: + public BasicContainer, + public MouseListener + { + public: + + /** + * Constructor. + */ + ScrollArea(); + + /** + * Constructor. + * + * @param content the content of the ScrollArea. + */ + ScrollArea(Widget *content); + + /** + * Constructor. + * + * @param content the content of the ScrollArea. + * @param hPolicy the policy for the horizontal scrollbar. See enum with + * policies. + * @param vPolicy the policy for the vertical scrollbar. See enum with + * policies. + */ + ScrollArea(Widget *content, unsigned int hPolicy, unsigned int vPolicy); + + /** + * Destructor. + */ + virtual ~ScrollArea(); + + /** + * Sets the content. + * + * @param widget the content of the ScrollArea. + */ + void setContent(Widget* widget); + + /** + * Gets the content. + * + * @return the content of the ScrollArea. + */ + Widget* getContent(); + + /** + * Sets the horizontal scrollbar policy. See enum with policies. + * + * @param hPolicy the policy for the horizontal scrollbar. See enum with + * policies. + */ + void setHorizontalScrollPolicy(unsigned int hPolicy); + + /** + * Gets the horizontal scrollbar policy. See enum with policies. + * + * @return the policy for the horizontal scrollbar policy. See enum with + * policies. + */ + unsigned int getHorizontalScrollPolicy() const; + + /** + * Sets the vertical scrollbar policy. See enum with policies. + * + * @param vPolicy the policy for the vertical scrollbar. See enum with + * policies. + */ + void setVerticalScrollPolicy(unsigned int vPolicy); + + /** + * Gets the vertical scrollbar policy. See enum with policies. + * + * @return the policy for the vertical scrollbar. See enum with + * policies. + */ + unsigned int getVerticalScrollPolicy() const; + + /** + * Sets the horizontal and vertical scrollbar policy. See enum with policies. + * + * @param hPolicy the policy for the horizontal scrollbar. See enum with + * policies. + * @param vPolicy the policy for the vertical scrollbar. See enum with + * policies. + */ + void setScrollPolicy(unsigned int hPolicy, unsigned int vPolicy); + + /** + * Sets the amount to scroll vertically. + * + * @param vScroll the amount to scroll. + */ + void setVerticalScrollAmount(int vScroll); + + /** + * Gets the amount that is scrolled vertically. + * @return the scroll amount on vertical scroll. + */ + int getVerticalScrollAmount() const; + + /** + * Sets the amount to scroll horizontally. + * + * @param hScroll the amount to scroll. + */ + void setHorizontalScrollAmount(int hScroll); + + /** + * Gets the amount that is scrolled horizontally. + * + * @return the scroll amount on horizontal scroll. + */ + int getHorizontalScrollAmount() const; + + /** + * Sets the amount to scroll horizontally and vertically. + * + * @param hScroll the amount to scroll on horizontal scroll. + * @param vScroll the amount to scroll on vertical scroll. + */ + void setScrollAmount(int hScroll, int vScroll); + + /** + * Gets the maximum amount of horizontal scroll. + * + * @return the horizontal max scroll. + */ + int getHorizontalMaxScroll(); + + /** + * Gets the maximum amount of vertical scroll. + * + * @return the vertical max scroll. + */ + int getVerticalMaxScroll(); + + /** + * Sets the width. + * + * @param width the width of the ScrollBar. + */ + void setScrollbarWidth(int width); + + /** + * Gets the width. + + * @return the width of the ScrollBar. + */ + int getScrollbarWidth() const; + + /** + * Sets the amount to scroll in pixels when the left scroll button is + * pushed. + */ + void setLeftButtonScrollAmount(int amount); + + /** + * Sets the amount to scroll in pixels when the right scroll button is + * pushed. + */ + void setRightButtonScrollAmount(int amount); + + /** + * Sets the amount to scroll in pixels when the up scroll button is + * pushed. + */ + void setUpButtonScrollAmount(int amount); + + /** + * Sets the amount to scroll in pixels when the down scroll button is + * pushed. + */ + void setDownButtonScrollAmount(int amount); + + /** + * Gets the amount to scroll in pixels when the left scroll button is + * pushed. + * + * @return the amount to scroll when the left scroll button is pushed. + */ + int getLeftButtonScrollAmount() const; + + /** + * Gets the amount to scroll in pixels when the right scroll button is + * pushed. + * + * @return the amount to scroll when the right scroll button is pushed. + */ + int getRightButtonScrollAmount() const; + + /** + * Gets the amount to scroll in pixels when the up scroll button is + * pushed. + * + * @return the amount to scroll when the up scroll button is pushed. + */ + int getUpButtonScrollAmount() const; + + /** + * Gets the amount to scroll in pixels when the down scroll button is + * pushed. + * + * @return the amount to scroll when the down scroll button is pushed. + */ + int getDownButtonScrollAmount() const; + + + // Inherited from BasicContainer + + virtual void showWidgetPart(Widget* widget, Rectangle area); + + virtual Rectangle getChildrenArea(); + + virtual Widget *getWidgetAt(int x, int y); + + + // Inherited from Widget + + virtual void draw(Graphics *graphics); + + virtual void drawBorder(Graphics* graphics); + + virtual void logic(); + + void setWidth(int width); + + void setHeight(int height); + + void setDimension(const Rectangle& dimension); + + + // Inherited from MouseListener + + virtual void mousePressed(MouseEvent& mouseEvent); + + virtual void mouseReleased(MouseEvent& mouseEvent); + + virtual void mouseDragged(MouseEvent& mouseEvent); + + virtual void mouseWheelMovedUp(MouseEvent& mouseEvent); + + virtual void mouseWheelMovedDown(MouseEvent& mouseEvent); + + + /** + * Scrollpolicies for the horizontal and vertical scrollbar. + * The policies are: + * + * SHOW_ALWAYS - Always show the scrollbars no matter what. + * SHOW_NEVER - Never show the scrollbars no matter waht. + * SHOW_AUTO - Show the scrollbars only when needed. That is if the + * content grows larger then the ScrollArea. + */ + enum + { + SHOW_ALWAYS, + SHOW_NEVER, + SHOW_AUTO + }; + + protected: + /** + * Draws the background of the ScrollArea + * (the area behind the content). + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawBackground(Graphics *graphics); + + /** + * Draws the up button. + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawUpButton(Graphics *graphics); + + /** + * Draws the down button. + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawDownButton(Graphics *graphics); + + /** + * Draws the left button. + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawLeftButton(Graphics *graphics); + + /** + * Draws the right button. + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawRightButton(Graphics *graphics); + + /** + * Draws the vertical scrollbar. + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawVBar(Graphics* graphics); + + /** + * Draws the horizontal scrollbar. + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawHBar(Graphics* graphics); + + /** + * Draws the vertical marker. + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawVMarker(Graphics* graphics); + + /** + * Draws the horizontal marker. + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawHMarker(Graphics* graphics); + + /** + * Checks the policies for the scrollbars. + */ + virtual void checkPolicies(); + + /** + * Gets the up button dimension. + * + * @return the dimension of the up button. + */ + Rectangle getUpButtonDimension(); + + /** + * Gets the down button dimension. + * + * @return the dimension of the down button. + */ + Rectangle getDownButtonDimension(); + + /** + * Gets the left button dimension. + * + * @return the dimension of the left button. + */ + Rectangle getLeftButtonDimension(); + + /** + * Gets the right button dimension. + * + * @return the dimension of the right button. + */ + Rectangle getRightButtonDimension(); + + /** + * Gets the vertical scrollbar dimension. + * + * @return the dimension of the vertical scrollbar. + */ + Rectangle getVerticalBarDimension(); + + /** + * Gets the horizontal scrollbar dimension. + * + * @return the dimension of the horizontal scrollbar. + */ + Rectangle getHorizontalBarDimension(); + + /** + * Gets the vertical marker dimension. + * + * @return the dimension of the vertical marker. + */ + Rectangle getVerticalMarkerDimension(); + + /** + * Gets the horizontal marker dimension. + * + * @return the dimension of the horizontal marker. + */ + Rectangle getHorizontalMarkerDimension(); + + int mVScroll; + int mHScroll; + int mScrollbarWidth; + unsigned int mHPolicy; + unsigned int mVPolicy; + bool mVBarVisible; + bool mHBarVisible; + bool mUpButtonPressed; + bool mDownButtonPressed; + bool mLeftButtonPressed; + bool mRightButtonPressed; + int mUpButtonScrollAmount; + int mDownButtonScrollAmount; + int mLeftButtonScrollAmount; + int mRightButtonScrollAmount; + bool mIsVerticalMarkerDragged; + bool mIsHorizontalMarkerDragged; + int mHorizontalMarkerDragOffset; + int mVerticalMarkerDragOffset; + }; } #endif // end GCN_SCROLLAREA_HPP diff --git a/guisan-dev/include/guisan/widgets/slider.hpp b/guisan-dev/include/guisan/widgets/slider.hpp index 500966bc..99656147 100644 --- a/guisan-dev/include/guisan/widgets/slider.hpp +++ b/guisan-dev/include/guisan/widgets/slider.hpp @@ -64,205 +64,204 @@ namespace gcn { - /** - * A slider able to slide between different values. You can set the scale - * of the slider yourself so that it ranges between, for example, -1.0 and - * 2.0. - */ - class GCN_CORE_DECLSPEC Slider : - public Widget, - public MouseListener, - public KeyListener - { - public: + /** + * A slider able to slide between different values. You can set the scale + * of the slider yourself so that it ranges between, for example, -1.0 and + * 2.0. + */ + class GCN_CORE_DECLSPEC Slider : + public Widget, + public MouseListener, + public KeyListener + { + public: - /** - * Constructor. Scale start is 0. - * - * @param scaleEnd the end of the slider scale. - */ - explicit Slider(double scaleEnd = 1.0); + /** + * Constructor. Scale start is 0. + * + * @param scaleEnd the end of the slider scale. + */ + Slider(double scaleEnd = 1.0); - /** - * Constructor. - * - * @param scaleStart the start of the scale. - * @param scaleEnd the end of the scale. - */ - Slider(double scaleStart, double scaleEnd); + /** + * Constructor. + * + * @param scaleStart the start of the scale. + * @param scaleEnd the end of the scale. + */ + Slider(double scaleStart, double scaleEnd); - /** - * Destructor. - */ - virtual ~Slider() - = default; + /** + * Destructor. + */ + virtual ~Slider() { } - /** - * Sets the scale. - * - * @param scaleStart the start of the scale. - * @param scaleEnd the end of the scale. - */ - void setScale(double scaleStart, double scaleEnd); + /** + * Sets the scale. + * + * @param scaleStart the start of the scale. + * @param scaleEnd the end of the scale. + */ + void setScale(double scaleStart, double scaleEnd); - /** - * Gets the scale start. - * - * @return the scale start. - */ - double getScaleStart() const; + /** + * Gets the scale start. + * + * @return the scale start. + */ + double getScaleStart() const; - /** - * Sets the scale start. - * - * @param scaleStart the start of the scale. - */ - void setScaleStart(double scaleStart); + /** + * Sets the scale start. + * + * @param scaleStart the start of the scale. + */ + void setScaleStart(double scaleStart); - /** - * Gets the scale end. - * - * @return the scale end. - */ - double getScaleEnd() const; + /** + * Gets the scale end. + * + * @return the scale end. + */ + double getScaleEnd() const; - /** - * Sets the scale end. - * - * @param scaleEnd the end of the scale. - */ - void setScaleEnd(double scaleEnd); + /** + * Sets the scale end. + * + * @param scaleEnd the end of the scale. + */ + void setScaleEnd(double scaleEnd); - /** - * Gets the current value. - * - * @return the current value. - */ - double getValue() const; + /** + * Gets the current value. + * + * @return the current value. + */ + double getValue() const; - /** - * Sets the current value. - * - * @param value a scale value. - */ - void setValue(double value); + /** + * Sets the current value. + * + * @param value a scale value. + */ + void setValue(double value); - /** - * Draws the marker. - * - * @param graphics a graphics object to draw with. - */ - virtual void drawMarker(Graphics* graphics); + /** + * Draws the marker. + * + * @param graphics a graphics object to draw with. + */ + virtual void drawMarker(gcn::Graphics* graphics); - /** - * Sets the length of the marker. - * - * @param length new length for the marker. - */ - void setMarkerLength(int length); + /** + * Sets the length of the marker. + * + * @param length new length for the marker. + */ + void setMarkerLength(int length); - /** - * Gets the length of the marker. - * - * @return the length of the marker. - */ - int getMarkerLength() const; + /** + * Gets the length of the marker. + * + * @return the length of the marker. + */ + int getMarkerLength() const; - /** - * Sets the orientation of the slider. A slider can be drawn verticaly - * or horizontaly. For orientation, see the enum in this class. - * - * @param orientation the orientation. - */ - void setOrientation(unsigned int orientation); + /** + * Sets the orientation of the slider. A slider can be drawn verticaly + * or horizontaly. For orientation, see the enum in this class. + * + * @param orientation the orientation. + */ + void setOrientation(unsigned int orientation); - /** - * Gets the orientation of the slider. Se the enum in this class. - * - * @return the orientation of the slider. - */ - unsigned int getOrientation() const; + /** + * Gets the orientation of the slider. Se the enum in this class. + * + * @return the orientation of the slider. + */ + unsigned int getOrientation() const; - /** - * Sets the step length. Step length is used when the keys left and - * right are pressed. - * - * @param length the step length. - */ - void setStepLength(double length); + /** + * Sets the step length. Step length is used when the keys left and + * right are pressed. + * + * @param length the step length. + */ + void setStepLength(double length); - /** - * Gets the step length. - * - * @return the step length. - */ - double getStepLength() const; + /** + * Gets the step length. + * + * @return the step length. + */ + double getStepLength() const; - // Inherited from Widget + // Inherited from Widget - void draw(Graphics* graphics) override; + virtual void draw(gcn::Graphics* graphics); - void drawBorder(Graphics* graphics) override; + virtual void drawBorder(gcn::Graphics* graphics); - // Inherited from MouseListener. + // Inherited from MouseListener. - void mousePressed(MouseEvent& mouseEvent) override; + virtual void mousePressed(MouseEvent& mouseEvent); - void mouseDragged(MouseEvent& mouseEvent) override; + virtual void mouseDragged(MouseEvent& mouseEvent); - void mouseWheelMovedUp(MouseEvent& mouseEvent) override; + virtual void mouseWheelMovedUp(MouseEvent& mouseEvent); - void mouseWheelMovedDown(MouseEvent& mouseEvent) override; + virtual void mouseWheelMovedDown(MouseEvent& mouseEvent); - // Inherited from KeyListener + // Inherited from KeyListener - void keyPressed(KeyEvent& keyEvent) override; + virtual void keyPressed(KeyEvent& keyEvent); - /** - * Draw orientations for the slider. It can be drawn verticaly or - * horizontaly. - */ - enum - { - HORIZONTAL = 0, - VERTICAL - }; + /** + * Draw orientations for the slider. It can be drawn verticaly or + * horizontaly. + */ + enum + { + HORIZONTAL = 0, + VERTICAL + }; - protected: - /** - * Converts a marker position to a value. - * - * @param v the position to convert. - * @return the value corresponding to the position. - */ - virtual double markerPositionToValue(int v) const; + protected: + /** + * Converts a marker position to a value. + * + * @param v the position to convert. + * @return the value corresponding to the position. + */ + virtual double markerPositionToValue(int v) const; - /** - * Converts a value to a marker position. - * - * @param value the value to convert. - * @return the position corresponding to the value. - */ - virtual int valueToMarkerPosition(double value) const; + /** + * Converts a value to a marker position. + * + * @param value the value to convert. + * @return the position corresponding to the value. + */ + virtual int valueToMarkerPosition(double value) const; - /** - * Gets the marker position for the current value. - * - * @return the marker position for the current value. - */ - virtual int getMarkerPosition() const; + /** + * Gets the marker position for the current value. + * + * @return the marker position for the current value. + */ + virtual int getMarkerPosition() const; - bool mMouseDrag; - double mValue{}; - double mStepLength{}; - int mMarkerLength{}; - double mScaleStart; - double mScaleEnd; - unsigned int mOrientation{}; - }; + bool mMouseDrag; + double mValue; + double mStepLength; + int mMarkerLength; + double mScaleStart; + double mScaleEnd; + unsigned int mOrientation; + }; } #endif // end GCN_SLIDER_HPP diff --git a/guisan-dev/include/guisan/widgets/tab.hpp b/guisan-dev/include/guisan/widgets/tab.hpp index e351f1e7..9f6993c4 100644 --- a/guisan-dev/include/guisan/widgets/tab.hpp +++ b/guisan-dev/include/guisan/widgets/tab.hpp @@ -66,81 +66,81 @@ namespace gcn { - class Label; - class TabbedArea; + class Label; + class TabbedArea; + + /** + * A simple tab widget used as the default tab in the TabbedArea widget. + */ + class GCN_CORE_DECLSPEC Tab: + public BasicContainer, + public MouseListener + { + public: - /** - * A simple tab widget used as the default tab in the TabbedArea widget. - */ - class GCN_CORE_DECLSPEC Tab : - public BasicContainer, - public MouseListener - { - public: + /** + * Constructor. + */ + Tab(); - /** - * Constructor. - */ - Tab(); + /** + * Destructor. + */ + virtual ~Tab(); - /** - * Destructor. - */ - virtual ~Tab(); + /** + * Adjusts the tab size to fit the label. + */ + void adjustSize(); - /** - * Adjusts the tab size to fit the label. - */ - void adjustSize(); + /** + * Sets the tabbed area the tab should be a part of. + * + * @param tabbedArea The tabbed area the tab should be a part of. + */ + void setTabbedArea(TabbedArea* tabbedArea); - /** - * Sets the tabbed area the tab should be a part of. - * - * @param tabbedArea The tabbed area the tab should be a part of. - */ - void setTabbedArea(TabbedArea* tabbedArea); + /** + * Gets the tabbed are the tab is a part of. + * + * @return The tabbed are the tab is a part of. + */ + TabbedArea* getTabbedArea(); - /** - * Gets the tabbed are the tab is a part of. - * - * @return The tabbed are the tab is a part of. - */ - TabbedArea* getTabbedArea() const; + /** + * Sets the caption of the tab. + * + * @param caption The caption of the tab. + */ + void setCaption(const std::string& caption); - /** - * Sets the caption of the tab. - * - * @param caption The caption of the tab. - */ - void setCaption(const std::string& caption); + /** + * Gets the caption of the tab. + * + * @return The caption of the tab. + */ + const std::string& getCaption() const; - /** - * Gets the caption of the tab. - * - * @return The caption of the tab. - */ - const std::string& getCaption() const; + + // Inherited from Widget + virtual void draw(Graphics *graphics); - // Inherited from Widget + virtual void drawBorder(Graphics* graphics); + - void draw(Graphics* graphics) override; + // Inherited from MouseListener - void drawBorder(Graphics* graphics) override; + virtual void mouseEntered(MouseEvent& mouseEvent); - - // Inherited from MouseListener - - void mouseEntered(MouseEvent& mouseEvent) override; - - void mouseExited(MouseEvent& mouseEvent) override; - - protected: - Label* mLabel; - TabbedArea* mTabbedArea{}; - std::string mCaption; - bool mHasMouse; - }; + virtual void mouseExited(MouseEvent& mouseEvent); + + protected: + Label* mLabel; + TabbedArea* mTabbedArea; + std::string mCaption; + bool mHasMouse; + }; } #endif // end GCN_TABBEDAREA_HPP diff --git a/guisan-dev/include/guisan/widgets/tabbedarea.hpp b/guisan-dev/include/guisan/widgets/tabbedarea.hpp index 503e9fe7..d85498ed 100644 --- a/guisan-dev/include/guisan/widgets/tabbedarea.hpp +++ b/guisan-dev/include/guisan/widgets/tabbedarea.hpp @@ -69,157 +69,158 @@ namespace gcn { - class Container; - class Tab; + class Container; + class Tab; + + /** + * With the tabbed area widget several widgets can share the same + * space. The widget to view is selected by the user by using tabs. + */ + class GCN_CORE_DECLSPEC TabbedArea: + public ActionListener, + public BasicContainer, + public KeyListener, + public MouseListener + { + public: - /** - * With the tabbed area widget several widgets can share the same - * space. The widget to view is selected by the user by using tabs. - */ - class GCN_CORE_DECLSPEC TabbedArea : - public ActionListener, - public BasicContainer, - public KeyListener, - public MouseListener - { - public: + /** + * Constructor. + */ + TabbedArea(); - /** - * Constructor. - */ - TabbedArea(); + /** + * Destructor. + */ + virtual ~TabbedArea(); - /** - * Destructor. - */ - virtual ~TabbedArea(); + /** + * Adds a tab to the tabbed area. + * + * @param caption The caption of the tab. + * @param widget The widget to view when the tab is selected. + */ + virtual void addTab(const std::string& caption, Widget* widget); - /** - * Adds a tab to the tabbed area. - * - * @param caption The caption of the tab. - * @param widget The widget to view when the tab is selected. - */ - virtual void addTab(const std::string& caption, Widget* widget); + /** + * Adds a tab to the tabbed area. + * + * @param tab The tab widget for the tab. + * @param widget The widget to view when the tab is selected. + */ + virtual void addTab(Tab* tab, Widget* widget); - /** - * Adds a tab to the tabbed area. - * - * @param tab The tab widget for the tab. - * @param widget The widget to view when the tab is selected. - */ - virtual void addTab(Tab* tab, Widget* widget); + /** + * Removes a tab from the tabbed area. + * + * @param index The index of the tab to remove. + */ + virtual void removeTabWithIndex(unsigned int index); + + /** + * Removes a tab from the tabbed area. + * + * @param index The tab to remove. + */ + virtual void removeTab(Tab* tab); - /** - * Removes a tab from the tabbed area. - * - * @param index The index of the tab to remove. - */ - virtual void removeTabWithIndex(unsigned int index); + /** + * Checks whether a tab given an index is selected. + * + * @param index The index of the tab to check. + * @return True if the tab is selected, false otherwise. + */ + virtual bool isTabSelected(unsigned int index) const; + + /** + * Checks whether a tab is selected or not. + * + * @param index The tab to check. + * @return True if the tab is selected, false otherwise. + */ + virtual bool isTabSelected(Tab* tab); - /** - * Removes a tab from the tabbed area. - * - * @param tab The tab to remove. - */ - virtual void removeTab(Tab* tab); + /** + * Sets a tab given an index to be selected. + * + * @param index The index of the tab to be selected. + */ + virtual void setSelectedTabWithIndex(unsigned int index); - /** - * Checks whether a tab given an index is selected. - * - * @param index The index of the tab to check. - * @return True if the tab is selected, false otherwise. - */ - virtual bool isTabSelected(unsigned int index) const; + /** + * Sets a tab to be selected or not. + * + * @param index The tab to be selected. + */ + virtual void setSelectedTab(Tab* tab); - /** - * Checks whether a tab is selected or not. - * - * @param tab The tab to check. - * @return True if the tab is selected, false otherwise. - */ - virtual bool isTabSelected(Tab* tab); - - /** - * Sets a tab given an index to be selected. - * - * @param index The index of the tab to be selected. - */ - virtual void setSelectedTabWithIndex(unsigned int index); - - /** - * Sets a tab to be selected or not. - * - * @param tab The tab to be selected. - */ - virtual void setSelectedTab(Tab* tab); - - /** - * Gets the index of the selected tab. - * - * @return The undex of the selected tab. - * If no tab is selected -1 will be returned. - */ - virtual int getSelectedTabIndex() const; - - /** - * Gets the selected tab. - * - * @return The selected tab. - */ - Tab* getSelectedTab() const; + /** + * Gets the index of the selected tab. + * + * @return The undex of the selected tab. + * If no tab is selected -1 will be returned. + */ + virtual int getSelectedTabIndex() const; + + /** + * Gets the selected tab. + * + * @return The selected tab. + */ + Tab* getSelectedTab(); - // Inherited from Widget + // Inherited from Widget - void draw(Graphics* graphics) override; + virtual void draw(Graphics *graphics); - void drawBorder(Graphics* graphics) override; + virtual void drawBorder(Graphics* graphics); - void logic() override; + virtual void logic(); - void setWidth(int width) override; + void setWidth(int width); - void setHeight(int height) override; + void setHeight(int height); - void setSize(int width, int height) override; + void setSize(int width, int height); - void setDimension(const Rectangle& dimension) override; + void setDimension(const Rectangle& dimension); + + + // Inherited from ActionListener + + void action(const ActionEvent& actionEvent); + + + // Inherited from DeathListener + + virtual void death(const Event& event); - // Inherited from ActionListener + // Inherited from KeyListener - void action(const ActionEvent& actionEvent) override; + virtual void keyPressed(KeyEvent& keyEvent); - // Inherited from DeathListener + // Inherited from MouseListener + + virtual void mousePressed(MouseEvent& mouseEvent); - void death(const Event& event) override; - - - // Inherited from KeyListener - - void keyPressed(KeyEvent& keyEvent) override; - - - // Inherited from MouseListener - - void mousePressed(MouseEvent& mouseEvent) override; - - - protected: - /** - * Adjusts the size of the tabbed area. - */ - void adjustSize(); - void adjustTabPositions(); - - Tab* mSelectedTab; - Container* mTabContainer; - Container* mWidgetContainer; - std::vector mTabsToCleanUp; - std::vector> mTabs; - }; + + protected: + /** + * Adjusts the size of the tabbed area. + */ + void adjustSize(); + void adjustTabPositions(); + + Tab* mSelectedTab; + Container* mTabContainer; + Container* mWidgetContainer; + std::vector mTabsToCleanUp; + std::vector > mTabs; + + }; } #endif // end GCN_TABBEDAREA_HPP diff --git a/guisan-dev/include/guisan/widgets/textbox.hpp b/guisan-dev/include/guisan/widgets/textbox.hpp index 827b1a3c..5a4b5bfc 100644 --- a/guisan-dev/include/guisan/widgets/textbox.hpp +++ b/guisan-dev/include/guisan/widgets/textbox.hpp @@ -68,197 +68,197 @@ namespace gcn { - /** - * A TextBox in which you can write and/or display a lines of text. - * - * NOTE: A plain TextBox is really uggly and looks much better inside a - * ScrollArea. - */ - class GCN_CORE_DECLSPEC TextBox : - public Widget, - public MouseListener, - public KeyListener - { - public: - /** - * Constructor. - */ - TextBox(); + /** + * A TextBox in which you can write and/or display a lines of text. + * + * NOTE: A plain TextBox is really uggly and looks much better inside a + * ScrollArea. + */ + class GCN_CORE_DECLSPEC TextBox: + public Widget, + public MouseListener, + public KeyListener + { + public: + /** + * Constructor. + */ + TextBox(); - /** - * Constructor. - * - * @param text the text of the TextBox. - */ - TextBox(const std::string& text); + /** + * Constructor. + * + * @param text the text of the TextBox. + */ + TextBox(const std::string& text); - /** - * Sets the text. - * - * @param text the text of the TextBox. - */ - void setText(const std::string& text); + /** + * Sets the text. + * + * @param text the text of the TextBox. + */ + void setText(const std::string& text); - /** - * Gets the text. - * @return the text of the TextBox. - */ - std::string getText() const; + /** + * Gets the text. + * @return the text of the TextBox. + */ + std::string getText() const; - /** - * Gets the row of a text. - * - * @return the text of a certain row in the TextBox. - */ - const std::string& getTextRow(int row) const; + /** + * Gets the row of a text. + * + * @return the text of a certain row in the TextBox. + */ + const std::string& getTextRow(int row) const; - /** - * Sets the text of a certain row in a TextBox. - * - * @param row the row number. - * @param text the text of a certain row in the TextBox. - */ - void setTextRow(int row, const std::string& text); + /** + * Sets the text of a certain row in a TextBox. + * + * @param row the row number. + * @param text the text of a certain row in the TextBox. + */ + void setTextRow(int row, const std::string& text); - /** - * Gets the number of rows in the text. - * - * @return the number of rows in the text. - */ - unsigned int getNumberOfRows() const; + /** + * Gets the number of rows in the text. + * + * @return the number of rows in the text. + */ + unsigned int getNumberOfRows() const; - /** - * Gets the caret position in the text. - * - * @return the caret position in the text. - */ - unsigned int getCaretPosition() const; + /** + * Gets the caret position in the text. + * + * @return the caret position in the text. + */ + unsigned int getCaretPosition() const; - /** - * Sets the position of the caret in the text. - * - * @param position the positon of the caret. - */ - void setCaretPosition(unsigned int position); + /** + * Sets the position of the caret in the text. + * + * @param position the positon of the caret. + */ + void setCaretPosition(unsigned int position); - /** - * Gets the row the caret is in in the text. - * - * @return the row the caret is in in the text. - */ - unsigned int getCaretRow() const; + /** + * Gets the row the caret is in in the text. + * + * @return the row the caret is in in the text. + */ + unsigned int getCaretRow() const; - /** - * Sets the row the caret should be in in the text. - * - * @param row the row number. - */ - void setCaretRow(int row); + /** + * Sets the row the caret should be in in the text. + * + * @param row the row number. + */ + void setCaretRow(int row); - /** - * Gets the column the caret is in in the text. - * - * @return the column the caret is in in the text. - */ - unsigned int getCaretColumn() const; + /** + * Gets the column the caret is in in the text. + * + * @return the column the caret is in in the text. + */ + unsigned int getCaretColumn() const; - /** - * Sets the column the caret should be in in the text. - * - * @param column the column number. - */ - void setCaretColumn(int column); + /** + * Sets the column the caret should be in in the text. + * + * @param column the column number. + */ + void setCaretColumn(int column); - /** - * Sets the row and the column the caret should be in in the text. - * - * @param row the row number. - * @param column the column number. - */ - void setCaretRowColumn(int row, int column); + /** + * Sets the row and the column the caret should be in in the text. + * + * @param row the row number. + * @param column the column number. + */ + void setCaretRowColumn(int row, int column); - /** - * Scrolls the text to the caret if the TextBox is in a ScrollArea. - */ - virtual void scrollToCaret(); + /** + * Scrolls the text to the caret if the TextBox is in a ScrollArea. + */ + virtual void scrollToCaret(); - /** - * Checks if the TextBox is editable. - * - * @return true it the TextBox is editable. - */ - bool isEditable() const; + /** + * Checks if the TextBox is editable. + * + * @return true it the TextBox is editable. + */ + bool isEditable() const; - /** - * Sets if the TextBox should be editable or not. - * - * @param editable true if the TextBox should be editable. - */ - void setEditable(bool editable); + /** + * Sets if the TextBox should be editable or not. + * + * @param editable true if the TextBox should be editable. + */ + void setEditable(bool editable); - /** - * Adds a text row to the text. - * - * @param row a row. - */ - virtual void addRow(std::string row); + /** + * Adds a text row to the text. + * + * @param row a row. + */ + virtual void addRow(const std::string row); - /** - * Checks if the TextBox is opaque - * - * @return true if the TextBox is opaque - */ - bool isOpaque() const; + /** + * Checks if the TextBox is opaque + * + * @return true if the TextBox is opaque + */ + bool isOpaque(); - /** - * Sets the TextBox to be opaque. - * - * @param opaque true if the TextBox should be opaque. - */ - void setOpaque(bool opaque); + /** + * Sets the TextBox to be opaque. + * + * @param opaque true if the TextBox should be opaque. + */ + void setOpaque(bool opaque); - // Inherited from Widget + // Inherited from Widget - void draw(Graphics* graphics) override; + virtual void draw(Graphics* graphics); - void drawBorder(Graphics* graphics) override; + virtual void drawBorder(Graphics* graphics); - void fontChanged() override; + virtual void fontChanged(); - // Inherited from KeyListener + // Inherited from KeyListener - void keyPressed(KeyEvent& keyEvent) override; + virtual void keyPressed(KeyEvent& keyEvent); - // Inherited from MouseListener + // Inherited from MouseListener - void mousePressed(MouseEvent& mouseEvent) override; + virtual void mousePressed(MouseEvent& mouseEvent); - void mouseDragged(MouseEvent& mouseEvent) override; + virtual void mouseDragged(MouseEvent& mouseEvent); - protected: - /** - * Draws the caret. - * - * @param graphics a Graphics object to draw with. - * @param x the x position. - * @param y the y position. - */ - virtual void drawCaret(Graphics* graphics, int x, int y); + protected: + /** + * Draws the caret. + * + * @param graphics a Graphics object to draw with. + * @param x the x position. + * @param y the y position. + */ + virtual void drawCaret(Graphics* graphics, int x, int y); - /** - * Adjusts the TextBox size to fit the font size. - */ - virtual void adjustSize(); + /** + * Adjusts the TextBox size to fit the font size. + */ + virtual void adjustSize(); - std::vector mTextRows; - int mCaretColumn; - int mCaretRow; - bool mEditable; - bool mOpaque; - }; + std::vector mTextRows; + int mCaretColumn; + int mCaretRow; + bool mEditable; + bool mOpaque; + }; } #endif // end GCN_TEXTBOX_HPP diff --git a/guisan-dev/include/guisan/widgets/textfield.hpp b/guisan-dev/include/guisan/widgets/textfield.hpp index 764b548f..b6c1061e 100644 --- a/guisan-dev/include/guisan/widgets/textfield.hpp +++ b/guisan-dev/include/guisan/widgets/textfield.hpp @@ -66,110 +66,110 @@ namespace gcn { - /** - * A text field in which you can write or display a line of text. - */ - class GCN_CORE_DECLSPEC TextField : - public Widget, - public MouseListener, - public KeyListener - { - public: - /** - * Default constructor. - */ - TextField(); + /** + * A text field in which you can write or display a line of text. + */ + class GCN_CORE_DECLSPEC TextField: + public Widget, + public MouseListener, + public KeyListener + { + public: + /** + * Default constructor. + */ + TextField(); - /** - * Constructor. Initializes the textfield with a given string. - * - * @param text the initial text. - */ - TextField(const std::string& text); + /** + * Constructor. Initializes the textfield with a given string. + * + * @param text the initial text. + */ + TextField(const std::string& text); - /** - * Sets the text. - * - * @param text the new text in the TextField. - */ - void setText(const std::string& text); + /** + * Sets the text. + * + * @param text the new text in the TextField. + */ + void setText(const std::string& text); - /** - * Gets the text. - * - * @return the text of the TextField. - */ - const std::string& getText() const; + /** + * Gets the text. + * + * @return the text of the TextField. + */ + const std::string& getText() const; - /** - * Draws the caret (the little marker in the text that shows where the - * letters you type will appear). Easily overloaded if you want to - * change the style of the caret. - * - * @param graphics the Graphics object to draw with. - * @param x the caret's x-position. - */ - virtual void drawCaret(Graphics* graphics, int x); + /** + * Draws the caret (the little marker in the text that shows where the + * letters you type will appear). Easily overloaded if you want to + * change the style of the caret. + * + * @param graphics the Graphics object to draw with. + * @param x the caret's x-position. + */ + virtual void drawCaret(Graphics* graphics, int x); - /** - * Adjusts the size of the TextField to fit the font size. The - * constructor taking a string uses this function to initialize the - * size of the TextField. - */ - void adjustSize(); + /** + * Adjusts the size of the TextField to fit the font size. The + * constructor taking a string uses this function to initialize the + * size of the TextField. + */ + void adjustSize(); - /** - * Adjusts the height of the text field to fit the font size. The - * height of the TextField is initialized with this function by the - * constructors. - */ - void adjustHeight(); + /** + * Adjusts the height of the text field to fit the font size. The + * height of the TextField is initialized with this function by the + * constructors. + */ + void adjustHeight(); - /** - * Sets the caret position. - * - * @param position the caret position. - */ - void setCaretPosition(unsigned int position); + /** + * Sets the caret position. + * + * @param position the caret position. + */ + void setCaretPosition(unsigned int position); - /** - * Gets the caret position. - * - * @return the caret position. - */ - unsigned int getCaretPosition() const; + /** + * Gets the caret position. + * + * @return the caret position. + */ + unsigned int getCaretPosition() const; - // Inherited from Widget + // Inherited from Widget - void fontChanged() override; + virtual void fontChanged(); - void draw(Graphics* graphics) override; + virtual void draw(Graphics* graphics); - void drawBorder(Graphics* graphics) override; + virtual void drawBorder(Graphics* graphics); - // Inherited from MouseListener + // Inherited from MouseListener - void mousePressed(MouseEvent& mouseEvent) override; + virtual void mousePressed(MouseEvent& mouseEvent); - void mouseDragged(MouseEvent& mouseEvent) override; + virtual void mouseDragged(MouseEvent& mouseEvent); + + // Inherited from KeyListener - // Inherited from KeyListener + virtual void keyPressed(KeyEvent& keyEvent); - void keyPressed(KeyEvent& keyEvent) override; + protected: + /** + * Scrolls the text horizontally so that the caret shows if needed. + */ + void fixScroll(); - protected: - /** - * Scrolls the text horizontally so that the caret shows if needed. - */ - void fixScroll(); - - std::string mText; - unsigned int mCaretPosition; - int mXScroll; - }; + std::string mText; + unsigned int mCaretPosition; + int mXScroll; + }; } #endif // end GCN_TEXTFIELD_HPP diff --git a/guisan-dev/include/guisan/widgets/window.hpp b/guisan-dev/include/guisan/widgets/window.hpp index 1f05f7a9..72b35fd9 100644 --- a/guisan-dev/include/guisan/widgets/window.hpp +++ b/guisan-dev/include/guisan/widgets/window.hpp @@ -65,153 +65,153 @@ namespace gcn { - /** - * A movable window which can contain another Widgets. - */ - class GCN_CORE_DECLSPEC Window : public Container, - public MouseListener - { - public: - /** - * Constructor. - */ - Window(); + /** + * A movable window which can contain another Widgets. + */ + class GCN_CORE_DECLSPEC Window : public Container, + public MouseListener + { + public: + /** + * Constructor. + */ + Window(); - /** - * Constructor. - * - * @param caption the Window caption. - */ - Window(const std::string& caption); + /** + * Constructor. + * + * @param caption the Window caption. + */ + Window(const std::string& caption); - /** - * Destructor. - */ - virtual ~Window(); + /** + * Destructor. + */ + virtual ~Window(); - /** - * Sets the Window caption. - * - * @param caption the Window caption. - */ - void setCaption(const std::string& caption); + /** + * Sets the Window caption. + * + * @param caption the Window caption. + */ + void setCaption(const std::string& caption); - /** - * Gets the Window caption. - * - * @return the Window caption. - */ - const std::string& getCaption() const; + /** + * Gets the Window caption. + * + * @return the Window caption. + */ + const std::string& getCaption() const; - /** - * Sets the alignment for the caption. - * - * @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. - */ - void setAlignment(unsigned int alignment); + /** + * Sets the alignment for the caption. + * + * @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. + */ + void setAlignment(unsigned int alignment); - /** - * Gets the alignment for the caption. - * - * @return alignment of caption. - */ - int getAlignment() const; + /** + * Gets the alignment for the caption. + * + * @return alignment of caption. + */ + unsigned int getAlignment() const; - /** - * Sets the padding of the window which is the distance between the - * window border and the content. - * - * @param padding the padding value. - */ - void setPadding(unsigned int padding); + /** + * Sets the padding of the window which is the distance between the + * window border and the content. + * + * @param padding the padding value. + */ + void setPadding(unsigned int padding); - /** - * Gets the padding. - * - * @return the padding value. - */ - int getPadding() const; + /** + * Gets the padding. + * + * @return the padding value. + */ + unsigned int getPadding() const; - /** - * Sets the title bar height. - * - * @param height the title height value. - */ - void setTitleBarHeight(unsigned int height); + /** + * Sets the title bar height. + * + * @param height the title height value. + */ + void setTitleBarHeight(unsigned int height); - /** - * Gets the title bar height. - * - * @return the title bar height. - */ - int getTitleBarHeight() const; + /** + * Gets the title bar height. + * + * @return the title bar height. + */ + unsigned int getTitleBarHeight(); - /** - * Sets the Window to be moveble. - * - * @param movable true or false. - */ - void setMovable(bool movable); + /** + * Sets the Window to be moveble. + * + * @param movable true or false. + */ + void setMovable(bool movable); - /** - * Check if the window is movable. - * - * @return true or false. - */ - bool isMovable() const; + /** + * Check if the window is movable. + * + * @return true or false. + */ + bool isMovable() const; - /** - * Sets the Window to be opaque. If it's not opaque, the content area - * will not be filled with a color. - * - * @param opaque true or false. - */ - void setOpaque(bool opaque) override; + /** + * Sets the Window to be opaque. If it's not opaque, the content area + * will not be filled with a color. + * + * @param opaque true or false. + */ + void setOpaque(bool opaque); - /** - * Checks if the Window is opaque. - * - * @return true or false. - */ - bool isOpaque() const override; + /** + * Checks if the Window is opaque. + * + * @return true or false. + */ + bool isOpaque(); - /** - * Resizes the container to fit the content exactly. - */ - virtual void resizeToContent(); + /** + * Resizes the container to fit the content exactly. + */ + virtual void resizeToContent(); - // Inherited from BasicContainer + // Inherited from BasicContainer - Rectangle getChildrenArea() override; + virtual Rectangle getChildrenArea(); - // Inherited from Widget + // Inherited from Widget - void draw(Graphics* graphics) override; + virtual void draw(Graphics* graphics); - void drawBorder(Graphics* graphics) override; + virtual void drawBorder(Graphics* graphics); - // Inherited from MouseListener + // Inherited from MouseListener - void mousePressed(MouseEvent& mouseEvent) override; + virtual void mousePressed(MouseEvent& mouseEvent); - void mouseDragged(MouseEvent& mouseEvent) override; + virtual void mouseDragged(MouseEvent& mouseEvent); - void mouseReleased(MouseEvent& mouseEvent) override; + virtual void mouseReleased(MouseEvent& mouseEvent); - protected: - std::string mCaption; - unsigned int mAlignment{}; - unsigned int mPadding{}; - unsigned int mTitleBarHeight{}; - bool mMovable{}; - bool mOpaque{}; - int mDragOffsetX{}; - int mDragOffsetY{}; - bool mIsMoving; - }; + protected: + std::string mCaption; + unsigned int mAlignment; + unsigned int mPadding; + unsigned int mTitleBarHeight; + bool mMovable; + bool mOpaque; + int mDragOffsetX; + int mDragOffsetY; + bool mIsMoving; + }; } #endif // end GCN_WINDOW_HPP diff --git a/guisan-dev/src/actionevent.cpp b/guisan-dev/src/actionevent.cpp index 175ef3be..b232b061 100644 --- a/guisan-dev/src/actionevent.cpp +++ b/guisan-dev/src/actionevent.cpp @@ -62,17 +62,21 @@ namespace gcn { - ActionEvent::ActionEvent(Widget* source, const std::string& id) - : Event(source), - mId(id) - { - } + ActionEvent::ActionEvent(Widget* source, const std::string& id) + :Event(source), + mId(id) + { - ActionEvent::~ActionEvent() - = default; + } - const std::string& ActionEvent::getId() const - { - return mId; - } + ActionEvent::~ActionEvent() + { + + } + + const std::string& ActionEvent::getId() const + { + return mId; + } } + diff --git a/guisan-dev/src/basiccontainer.cpp b/guisan-dev/src/basiccontainer.cpp index 877ed5eb..08bd85a6 100644 --- a/guisan-dev/src/basiccontainer.cpp +++ b/guisan-dev/src/basiccontainer.cpp @@ -69,322 +69,334 @@ namespace gcn { - BasicContainer::~BasicContainer() - { - BasicContainer::clear(); - } + BasicContainer::~BasicContainer() + { + clear(); + } - 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; - } - } + 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; + } + } - 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) - { - auto iter = find(mWidgets.begin(), mWidgets.end(), widget); + void BasicContainer::moveToBottom(Widget* widget) + { + WidgetListIterator iter; + 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) - { - auto iter = find(mWidgets.begin(), mWidgets.end(), event.getSource()); + void BasicContainer::death(const Event& event) + { + WidgetListIterator iter; + 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 {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; + } + } - auto end = it; + WidgetListIterator 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; + } + } - auto end = it; + WidgetListReverseIterator 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) - { - auto r = getChildrenArea(); + Widget *BasicContainer::getWidgetAt(int x, int y) + { + Rectangle r = getChildrenArea(); - if (!r.isPointInRect(x, y)) - { - return nullptr; - } + if (!r.isPointInRect(x, y)) + { + return NULL; + } - x -= r.x; - y -= r.y; + x -= r.x; + y -= r.y; - for (auto it = mWidgets.rbegin(); it != mWidgets.rend(); ++it) - { - if ((*it)->isVisible() && (*it)->getDimension().isPointInRect(x, y)) - { - return (*it); - } - } + WidgetListReverseIterator it; + for (it = mWidgets.rbegin(); it != mWidgets.rend(); it++) + { + if ((*it)->isVisible() && (*it)->getDimension().isPointInRect(x, y)) + { + return (*it); + } + } - return nullptr; - } + return NULL; + } - 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 != nullptr) - { - return; - } + if (mInternalFocusHandler != NULL) + { + return; + } - for (auto& mWidget : mWidgets) - { - mWidget->_setFocusHandler(focusHandler); - } - } + WidgetListIterator iter; + for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) + { + (*iter)->_setFocusHandler(focusHandler); + } + } - void BasicContainer::add(Widget* widget) - { - mWidgets.push_back(widget); + void BasicContainer::add(Widget* widget) + { + mWidgets.push_back(widget); - if (mInternalFocusHandler == nullptr) - { - widget->_setFocusHandler(_getFocusHandler()); - } - else - { - widget->_setFocusHandler(mInternalFocusHandler); - } + if (mInternalFocusHandler == NULL) + { + widget->_setFocusHandler(_getFocusHandler()); + } + else + { + widget->_setFocusHandler(mInternalFocusHandler); + } - widget->_setParent(this); - widget->addDeathListener(this); - } + widget->_setParent(this); + widget->addDeathListener(this); + } - 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; - } - } + 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; + } + } - 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() - { - for (auto& mWidget : mWidgets) - { - mWidget->_setFocusHandler(nullptr); - mWidget->_setParent(nullptr); - mWidget->removeDeathListener(this); - } + void BasicContainer::clear() + { + WidgetListIterator iter; - mWidgets.clear(); - } + for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) + { + (*iter)->_setFocusHandler(NULL); + (*iter)->_setParent(NULL); + (*iter)->removeDeathListener(this); + } - void BasicContainer::drawChildren(Graphics* graphics) - { - graphics->pushClipArea(getChildrenArea()); + mWidgets.clear(); + } - for (auto& mWidget : mWidgets) - { - if (mWidget->isVisible()) - { - // If the widget has a border, - // draw it before drawing the widget - if (mWidget->getBorderSize() > 0) - { - Rectangle rec = mWidget->getDimension(); - rec.x -= mWidget->getBorderSize(); - rec.y -= mWidget->getBorderSize(); - rec.width += 2 * mWidget->getBorderSize(); - rec.height += 2 * mWidget->getBorderSize(); - graphics->pushClipArea(rec); - mWidget->drawBorder(graphics); - graphics->popClipArea(); - } + void BasicContainer::drawChildren(Graphics* graphics) + { + graphics->pushClipArea(getChildrenArea()); - graphics->pushClipArea(mWidget->getDimension()); - mWidget->draw(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->popClipArea(); - } + graphics->pushClipArea((*iter)->getDimension()); + (*iter)->draw(graphics); + graphics->popClipArea(); + } + } - void BasicContainer::logicChildren() - { - for (auto& mWidget : mWidgets) - { - mWidget->logic(); - } - } + graphics->popClipArea(); + } - void BasicContainer::showWidgetPart(Widget* widget, Rectangle area) - { - auto widgetArea = getChildrenArea(); - area.x += widget->getX(); - area.y += widget->getY(); + void BasicContainer::logicChildren() + { + WidgetListIterator iter; + for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) + { + (*iter)->logic(); + } + } - if (area.x + area.width > widgetArea.width) - { - widget->setX(widget->getX() - area.x - area.width + widgetArea.width); - } + void BasicContainer::showWidgetPart(Widget* widget, Rectangle area) + { + Rectangle widgetArea = getChildrenArea(); + area.x += widget->getX(); + area.y += widget->getY(); - if (area.y + area.height > widgetArea.height) - { - widget->setY(widget->getY() - area.y - area.height + widgetArea.height); - } + if (area.x + area.width > widgetArea.width) + { + widget->setX(widget->getX() - area.x - area.width + widgetArea.width); + } - if (area.x < 0) - { - widget->setX(widget->getX() - area.x); - } + if (area.y + area.height > widgetArea.height) + { + widget->setY(widget->getY() - area.y - area.height + widgetArea.height); + } - if (area.y < 0) - { - widget->setY(widget->getY() - area.y); - } - } + if (area.x < 0) + { + widget->setX(widget->getX() - area.x); + } + + 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); - for (auto& mWidget : mWidgets) - { - if (mInternalFocusHandler == nullptr) - { - mWidget->_setFocusHandler(_getFocusHandler()); - } - else - { - mWidget->_setFocusHandler(mInternalFocusHandler); - } - } - } + WidgetListIterator iter; + for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) + { + if (mInternalFocusHandler == NULL) + { + (*iter)->_setFocusHandler(_getFocusHandler()); + } + else + { + (*iter)->_setFocusHandler(mInternalFocusHandler); + } + } + } - Widget* BasicContainer::findWidgetById(const std::string& id) - { - for (auto& mWidget : mWidgets) - { - if (mWidget->getId() == id) - { - return mWidget; - } + 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; + } + } + } - auto basicContainer = dynamic_cast(mWidget); - - if (basicContainer != nullptr) - { - auto widget = basicContainer->findWidgetById(id); - - if (widget != nullptr) - { - return widget; - } - } - } - - return nullptr; - } + return NULL; + } } diff --git a/guisan-dev/src/cliprectangle.cpp b/guisan-dev/src/cliprectangle.cpp index 54f5fba9..8c94be5f 100644 --- a/guisan-dev/src/cliprectangle.cpp +++ b/guisan-dev/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/guisan-dev/src/color.cpp b/guisan-dev/src/color.cpp index 34404d3e..84a9a955 100644 --- a/guisan-dev/src/color.cpp +++ b/guisan-dev/src/color.cpp @@ -62,73 +62,76 @@ 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 ar, int ag, int ab, int aa) - : - r(ar), - g(ag), - b(ab), - a(aa) - { - } + Color::Color(int color) + : + r((color >> 16) & 0xFF), + b((color >> 8) & 0xFF), + g((color >> 8) & 0xFF), + a(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)); + Color::Color(int ar, int ag, int ab, int aa) + : + r(ar), + g(ag), + b(ab), + a(aa) + { - 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*(float value) const - { - Color result(int(r * value), int(g * value), int(b * value), a); + 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; + } - bool Color::operator==(const Color& color) const - { - return r == color.r && g == color.g && b == color.b && a == color.a; - } + 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); + } } diff --git a/guisan-dev/src/defaultfont.cpp b/guisan-dev/src/defaultfont.cpp index 931508b8..5218cd80 100644 --- a/guisan-dev/src/defaultfont.cpp +++ b/guisan-dev/src/defaultfont.cpp @@ -67,39 +67,41 @@ 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*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) - { - for (unsigned int i = 0; i < text.size(); ++i) - { - drawGlyph(graphics, text.at(i), x, y); - x += getWidth(text); - } - } + void DefaultFont::drawString(Graphics* graphics, const std::string& text, int x, int y) + { + unsigned int i; - int DefaultFont::getStringIndexAt(const std::string& text, int x) - { - if (x > int(text.size()) * 8) - { - return text.size(); - } + for (i = 0; i< text.size(); ++i) + { + drawGlyph(graphics, text.at(i), x, y); + x += getWidth(text); + } + } - return x / 8; - } + int DefaultFont::getStringIndexAt(const std::string& text, int x) + { + if (x > (int)text.size() * 8) + { + return text.size(); + } + + return x / 8; + } } diff --git a/guisan-dev/src/event.cpp b/guisan-dev/src/event.cpp index 724babec..ee209b7a 100644 --- a/guisan-dev/src/event.cpp +++ b/guisan-dev/src/event.cpp @@ -62,16 +62,20 @@ namespace gcn { - Event::Event(Widget* source) - : mSource(source), mType(0) - { - } + Event::Event(Widget* source) + :mSource(source) + { - Event::~Event() - = default; + } - Widget* Event::getSource() const - { - return mSource; - } + Event::~Event() + { + + } + + Widget* Event::getSource() const + { + return mSource; + } } + diff --git a/guisan-dev/src/exception.cpp b/guisan-dev/src/exception.cpp index 62ebdae7..47c8c767 100644 --- a/guisan-dev/src/exception.cpp +++ b/guisan-dev/src/exception.cpp @@ -62,50 +62,53 @@ namespace gcn { - Exception::Exception() - : mFunction("?"), - mMessage(""), - mFilename("?"), - mLine(0) - { - } + Exception::Exception() + : mFunction("?"), + mMessage(""), + mFilename("?"), + mLine(0) + { - Exception::Exception(const std::string& message) - : mFunction("?"), - mMessage(message), - mFilename("?"), - mLine(0) - { - } + } - Exception::Exception(const std::string& message, - const std::string& function, - const std::string& filename, - int line) - : mFunction(function), - mMessage(message), - mFilename(filename), - mLine(line) - { - } + Exception::Exception(const std::string& message) + : mFunction("?"), + mMessage(message), + mFilename("?"), + mLine(0) + { - const std::string& Exception::getFunction() const - { - return mFunction; - } + } - const std::string& Exception::getMessage() const - { - return mMessage; - } + 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::getFilename() const - { - return mFilename; - } + } - int Exception::getLine() const - { - return mLine; - } + 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; + } } diff --git a/guisan-dev/src/focushandler.cpp b/guisan-dev/src/focushandler.cpp index d2c02cbd..5fca0732 100644 --- a/guisan-dev/src/focushandler.cpp +++ b/guisan-dev/src/focushandler.cpp @@ -66,526 +66,534 @@ namespace gcn { - 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; - } - - unsigned int i = 0; - auto 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."); - } - - auto oldFocused = mFocusedWidget; - - if (oldFocused != widget) - { - mFocusedWidget = mWidgets.at(toBeFocusedIndex); - - if (oldFocused != nullptr) - { - Event focusEvent(oldFocused); - distributeFocusLostEvent(focusEvent); - } - - 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 < int(mWidgets.size()); ++i) - { - if (mWidgets[i] == mFocusedWidget) - { - focusedWidget = i; - } - } - auto 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.empty()) - { - mFocusedWidget = nullptr; - return; - } - - int i; - auto focusedWidget = -1; - for (i = 0; i < int(mWidgets.size()); ++i) - { - if (mWidgets[i] == mFocusedWidget) - { - focusedWidget = i; - } - } - auto 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 = 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 focused = mFocusedWidget; - mFocusedWidget = nullptr; - - 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 < int(mWidgets.size()); ++i) - { - if (mWidgets[i] == mFocusedWidget) - { - focusedWidget = i; - } - } - 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 = 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 == nullptr || - 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 != nullptr) - { - if (!mFocusedWidget->isTabOutEnabled()) - { - return; - } - } - - if (mWidgets.empty()) - { - mFocusedWidget = nullptr; - return; - } - - int i; - auto focusedWidget = -1; - for (i = 0; i < int(mWidgets.size()); ++i) - { - if (mWidgets[i] == mFocusedWidget) - { - focusedWidget = i; - } - } - 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 = 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 == nullptr || - 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) - { - 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; - } + 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; + } } diff --git a/guisan-dev/src/font.cpp b/guisan-dev/src/font.cpp index fdb99b4b..2f6899f8 100644 --- a/guisan-dev/src/font.cpp +++ b/guisan-dev/src/font.cpp @@ -64,20 +64,21 @@ namespace gcn { - int Font::getStringIndexAt(const std::string& text, int x) - { - auto size = 0; + int Font::getStringIndexAt(const std::string& text, int x) + { + unsigned int i; + int size = 0; - for (unsigned int i = 0; i < text.size(); ++i) - { - size = getWidth(text.substr(0, i)); + for (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/guisan-dev/src/genericinput.cpp b/guisan-dev/src/genericinput.cpp index a05c091d..1e26dfc4 100644 --- a/guisan-dev/src/genericinput.cpp +++ b/guisan-dev/src/genericinput.cpp @@ -64,109 +64,115 @@ namespace gcn { - GenericInput::GenericInput() - = default; + GenericInput::GenericInput() + { - void GenericInput::pushKeyPressed(int unicode) - { - // TODO - } + } + + 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::pushKeyReleased(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::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::pushMouseWheelMovedUp(int x, int y) + { + MouseInput mouseInput; + mouseInput.setX(x); + mouseInput.setY(y); + mouseInput.setType(MouseInput::WHEEL_MOVED_UP); - mMouseInputQueue.push(mouseInput); - } + mMouseInputQueue.push(mouseInput); + } + + void GenericInput::pushMouseWheelMovedDown(int x, int y) + { + MouseInput mouseInput; + mouseInput.setX(x); + mouseInput.setY(y); + mouseInput.setType(MouseInput::WHEEL_MOVED_DOWN); - 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); + } + + void GenericInput::pushMouseMoved(int x, int y) + { + MouseInput mouseInput; + mouseInput.setX(x); + mouseInput.setY(y); + mouseInput.setType(MouseInput::MOVED); - mMouseInputQueue.push(mouseInput); - } + mMouseInputQueue.push(mouseInput); + } - void GenericInput::pushMouseWheelMovedUp(int x, int y) - { - MouseInput mouseInput; - mouseInput.setX(x); - mouseInput.setY(y); - mouseInput.setType(MouseInput::WHEEL_MOVED_UP); + bool GenericInput::isKeyQueueEmpty() + { + return mKeyInputQueue.empty(); + } - mMouseInputQueue.push(mouseInput); - } + KeyInput GenericInput::dequeueKeyInput() + { + KeyInput keyInput; - void GenericInput::pushMouseWheelMovedDown(int x, int y) - { - MouseInput mouseInput; - mouseInput.setX(x); - mouseInput.setY(y); - mouseInput.setType(MouseInput::WHEEL_MOVED_DOWN); + if (mKeyInputQueue.empty()) + { + throw GCN_EXCEPTION("The queue is empty."); + } - mMouseInputQueue.push(mouseInput); - } + keyInput = mKeyInputQueue.front(); + mKeyInputQueue.pop(); - void GenericInput::pushMouseMoved(int x, int y) - { - MouseInput mouseInput; - mouseInput.setX(x); - mouseInput.setY(y); - mouseInput.setType(MouseInput::MOVED); + return keyInput; + } + + bool GenericInput::isMouseQueueEmpty() + { + return mMouseInputQueue.empty(); + } - mMouseInputQueue.push(mouseInput); - } - - bool GenericInput::isKeyQueueEmpty() - { - return mKeyInputQueue.empty(); - } - - KeyInput GenericInput::dequeueKeyInput() - { - if (mKeyInputQueue.empty()) - { - throw GCN_EXCEPTION("The queue is empty."); - } - - 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."); - } - - auto mouseInput = mMouseInputQueue.front(); - mMouseInputQueue.pop(); - - return mouseInput; - } - - void GenericInput::_pollInput() - { - // Does nothing. - } + 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. + } } diff --git a/guisan-dev/src/graphics.cpp b/guisan-dev/src/graphics.cpp index ce9f8bf4..7a4a11af 100644 --- a/guisan-dev/src/graphics.cpp +++ b/guisan-dev/src/graphics.cpp @@ -66,111 +66,113 @@ namespace gcn { - Graphics::Graphics() - { - mFont = nullptr; - } - bool Graphics::pushClipArea(Rectangle area) - { - if (mClipStack.empty()) - { - ClipRectangle carea; - carea.x = area.x; - carea.y = area.y; - carea.width = area.width; - carea.height = area.height; - mClipStack.push(carea); - return true; - } + Graphics::Graphics() + { + mFont = NULL; + } - ClipRectangle top = mClipStack.top(); - ClipRectangle carea; - carea = area; - carea.xOffset = top.xOffset + carea.x; - carea.yOffset = top.yOffset + carea.y; - carea.x += top.xOffset; - carea.y += top.yOffset; + bool Graphics::pushClipArea(Rectangle area) + { + if (mClipStack.empty()) + { + ClipRectangle carea; + carea.x = area.x; + carea.y = area.y; + carea.width = area.width; + carea.height = area.height; + mClipStack.push(carea); + return true; + } - // Clamp the pushed clip rectangle. - if (carea.x < top.x) - { - carea.x = top.x; - } + ClipRectangle top = mClipStack.top(); + ClipRectangle carea; + carea = area; + carea.xOffset = top.xOffset + carea.x; + carea.yOffset = top.yOffset + carea.y; + carea.x += top.xOffset; + carea.y += top.yOffset; - if (carea.y < top.y) - { - carea.y = top.y; - } + // Clamp the pushed clip rectangle. + if (carea.x < top.x) + { + carea.x = top.x; + } + + if (carea.y < top.y) + { + carea.y = top.y; + } + + if (carea.width > top.width) + { + carea.width = top.width; + } + + if (carea.height > top.height) + { + carea.height = top.height; + } - if (carea.width > top.width) - { - carea.width = top.width; - } + bool result = carea.intersect(top); - if (carea.height > top.height) - { - carea.height = top.height; - } + mClipStack.push(carea); - bool result = carea.intersect(top); + return result; + } - mClipStack.push(carea); + void Graphics::popClipArea() + { - return result; - } + if (mClipStack.empty()) + { + throw GCN_EXCEPTION("Tried to pop clip area from empty stack."); + } - void Graphics::popClipArea() - { - if (mClipStack.empty()) - { - throw GCN_EXCEPTION("Tried to pop clip area from empty stack."); - } + mClipStack.pop(); + } - mClipStack.pop(); - } + const ClipRectangle& Graphics::getCurrentClipArea() + { + if (mClipStack.empty()) + { + throw GCN_EXCEPTION("The clip area stack is empty."); + } - const ClipRectangle& Graphics::getCurrentClipArea() - { - if (mClipStack.empty()) - { - throw GCN_EXCEPTION("The clip area stack is empty."); - } + return mClipStack.top(); + } - return mClipStack.top(); - } + void Graphics::drawImage(const Image* image, int dstX, int dstY) + { + drawImage(image, 0, 0, dstX, dstY, image->getWidth(), image->getHeight()); + } - void Graphics::drawImage(const Image* image, int dstX, int dstY) - { - drawImage(image, 0, 0, dstX, dstY, image->getWidth(), image->getHeight()); - } + void Graphics::setFont(Font* font) + { + mFont = font; + } - void Graphics::setFont(Font* font) - { - mFont = font; - } + void Graphics::drawText(const std::string& text, int x, int y, + unsigned int alignment) + { + if (mFont == NULL) + { + throw GCN_EXCEPTION("No font set."); + } - void Graphics::drawText(const std::string& text, int x, int y, - unsigned int alignment) - { - if (mFont == nullptr) - { - throw GCN_EXCEPTION("No font set."); - } - - switch (alignment) - { - case LEFT: - mFont->drawString(this, text, x, y); - break; - case CENTER: - mFont->drawString(this, text, x - mFont->getWidth(text) / 2, y); - break; - case RIGHT: - mFont->drawString(this, text, x - mFont->getWidth(text), y); - break; - default: - throw GCN_EXCEPTION("Unknown alignment."); - } - } + switch (alignment) + { + case LEFT: + mFont->drawString(this, text, x, y); + break; + case CENTER: + mFont->drawString(this, text, x - mFont->getWidth(text) / 2, y); + break; + case RIGHT: + mFont->drawString(this, text, x - mFont->getWidth(text), y); + break; + default: + throw GCN_EXCEPTION("Unknown alignment."); + } + } } diff --git a/guisan-dev/src/gui.cpp b/guisan-dev/src/gui.cpp index 68e6fa44..cd7bdc26 100644 --- a/guisan-dev/src/gui.cpp +++ b/guisan-dev/src/gui.cpp @@ -73,916 +73,936 @@ namespace gcn { - 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 -= mTop->getBorderSize(); - rec.y -= 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()) - { - 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; - } - - bool 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 widget = mWidgetWithMouseQueue.front(); - - if (Widget::widgetExists(widget)) - { - distributeMouseEvent(widget, - MouseEvent::EXITED, - 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; - for (auto 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, - 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; - for (auto& iter : mWidgetWithMouseQueue) - { - 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, - 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, - 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, - mouseInput.getButton(), - mouseInput.getX(), - mouseInput.getY()); - - mFocusHandler->setLastWidgetPressed(sourceWidget); - - if ((mFocusHandler->getModalFocused() != nullptr - && sourceWidget->hasModalFocus()) - || mFocusHandler->getModalFocused() == nullptr) - { - sourceWidget->requestFocus(); - } - - mFocusHandler->setDraggedWidget(sourceWidget); - mLastMouseDragButton = 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, - 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, - 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, - mouseInput.getButton(), - mouseInput.getX(), - mouseInput.getY()); - - if (mouseInput.getButton() == mLastMousePressButton - && mFocusHandler->getLastWidgetPressed() == sourceWidget) - { - distributeMouseEvent(sourceWidget, - MouseEvent::CLICKED, - 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, - 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; - for (auto& iter : mWidgetWithMouseQueue) - { - 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, - mLastMousePressButton, - mLastMouseX, - mLastMouseY, - false, - true); - mWidgetWithMouseQueue.push_front(widget); - } - - auto swap = widget; - widget = parent; - parent = static_cast(swap->getParent()); - } - } + 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)) + { + 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 -= mTop->getBorderSize(); + rec.y -= 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, + 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, + 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, + 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, + 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, + mouseInput.getButton(), + mouseInput.getX(), + mouseInput.getY()); + + mFocusHandler->setLastWidgetPressed(sourceWidget); + + if (mFocusHandler->getModalFocused() != NULL + && sourceWidget->hasModalFocus() + || mFocusHandler->getModalFocused() == NULL) + { + sourceWidget->requestFocus(); + } + + mFocusHandler->setDraggedWidget(sourceWidget); + mLastMouseDragButton = 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, + 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, + 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, + mouseInput.getButton(), + mouseInput.getX(), + mouseInput.getY()); + + if (mouseInput.getButton() == mLastMousePressButton + && mFocusHandler->getLastWidgetPressed() == sourceWidget) + { + distributeMouseEvent(sourceWidget, + MouseEvent::CLICKED, + 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 (std::list::iterator it = mouseListeners.begin(); + it != mouseListeners.end(); + ++it) + { + switch (mouseEvent.getType()) + { + case MouseEvent::ENTERED: + (*it)->mouseEntered(mouseEvent); + break; + case MouseEvent::EXITED: + (*it)->mouseExited(mouseEvent); + break; + case MouseEvent::MOVED: + (*it)->mouseMoved(mouseEvent); + break; + case MouseEvent::PRESSED: + (*it)->mousePressed(mouseEvent); + break; + case MouseEvent::RELEASED: + (*it)->mouseReleased(mouseEvent); + break; + case MouseEvent::WHEEL_MOVED_UP: + (*it)->mouseWheelMovedUp(mouseEvent); + break; + case MouseEvent::WHEEL_MOVED_DOWN: + (*it)->mouseWheelMovedDown(mouseEvent); + break; + case MouseEvent::DRAGGED: + (*it)->mouseDragged(mouseEvent); + break; + case MouseEvent::CLICKED: + (*it)->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 (std::list::iterator it = keyListeners.begin(); + it != keyListeners.end(); + ++it) + { + switch (keyEvent.getType()) + { + case KeyEvent::PRESSED: + (*it)->keyPressed(keyEvent); + break; + case KeyEvent::RELEASED: + (*it)->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) + { + KeyListenerListIterator it; + + for (it = mKeyListeners.begin(); it != mKeyListeners.end(); it++) + { + switch (keyEvent.getType()) + { + case KeyEvent::PRESSED: + (*it)->keyPressed(keyEvent); + break; + case KeyEvent::RELEASED: + (*it)->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, + 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, + mLastMousePressButton, + mLastMouseX, + mLastMouseY, + false, + true); + mWidgetWithMouseQueue.push_front(widget); + } + + Widget* swap = widget; + widget = parent; + parent = (Widget*)swap->getParent(); + } + } } diff --git a/guisan-dev/src/guisan.cpp b/guisan-dev/src/guisan.cpp index c67f4c17..c8321d12 100644 --- a/guisan-dev/src/guisan.cpp +++ b/guisan-dev/src/guisan.cpp @@ -59,9 +59,10 @@ * For comments regarding functions please see the header file. */ -extern "C" { -const char* gcnGuisanVersion() +extern "C" { - return "0.9.0"; -} + const char* gcnGuisanVersion() + { + return "0.9.0"; + } } diff --git a/guisan-dev/src/image.cpp b/guisan-dev/src/image.cpp index fef0279b..58b2ead9 100644 --- a/guisan-dev/src/image.cpp +++ b/guisan-dev/src/image.cpp @@ -65,31 +65,34 @@ namespace gcn { - ImageLoader* Image::mImageLoader = nullptr; - Image::Image() - = default; + ImageLoader* Image::mImageLoader = NULL; - Image::~Image() - = default; + Image::Image() + { + } - void Image::setImageLoader(ImageLoader* imageLoader) - { - mImageLoader = imageLoader; - } + Image::~Image() + { + } - ImageLoader* Image::getImageLoader() - { - return mImageLoader; - } + void Image::setImageLoader(ImageLoader* imageLoader) + { + mImageLoader = imageLoader; + } - 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."); - } + ImageLoader* Image::getImageLoader() + { + return mImageLoader; + } - return mImageLoader->load(filename, convertToDisplayFormat); - } + 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); + } } diff --git a/guisan-dev/src/imagefont.cpp b/guisan-dev/src/imagefont.cpp index e2f55560..9fa996fe 100644 --- a/guisan-dev/src/imagefont.cpp +++ b/guisan-dev/src/imagefont.cpp @@ -69,251 +69,255 @@ 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); - auto separator = mImage->getPixel(0, 0); + 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."); + } - int i = 0; - for (i = 0; - i < mImage->getWidth() && separator == mImage->getPixel(i, 0); - ++i) - { - } + int j = 0; + for (j = 0; j < mImage->getHeight(); ++j) + { + if (separator == mImage->getPixel(i, j)) + { + break; + } + } - if (i >= mImage->getWidth()) - { - throw GCN_EXCEPTION("Corrupt image."); - } + mHeight = j; + int x = 0, y = 0; + unsigned char k; - auto j = 0; - for (j = 0; j < mImage->getHeight(); ++j) - { - if (separator == mImage->getPixel(i, j)) - { - break; - } - } + for (i=0; i < (int)glyphs.size(); ++i) + { + k = glyphs.at(i); + addGlyph(k, x, y, separator); + } - mHeight = j; - auto x = 0, y = 0; - unsigned char k; + //int w = mImage->getWidth(); + //int h = mImage->getHeight(); + mImage->convertToDisplayFormat(); - for (i = 0; i < int(glyphs.size()); ++i) - { - k = glyphs.at(i); - addGlyph(k, x, y, separator); - } + mRowSpacing = 0; + mGlyphSpacing = 0; + } - //int w = mImage->getWidth(); - //int h = mImage->getHeight(); - mImage->convertToDisplayFormat(); + ImageFont::ImageFont(const std::string& filename, unsigned char glyphsFrom, + unsigned char glyphsTo) + { + mFilename = filename; + mImage = Image::load(filename, false); - mRowSpacing = 0; - mGlyphSpacing = 0; - } + Color separator = mImage->getPixel(0, 0); - ImageFont::ImageFont(const std::string& filename, unsigned char glyphsFrom, - unsigned char glyphsTo) - { - mFilename = filename; - mImage = Image::load(filename, false); + int i = 0; + for (i=0; separator == mImage->getPixel(i, 0) + && i < mImage->getWidth(); ++i) + { + } - auto separator = mImage->getPixel(0, 0); + if (i >= mImage->getWidth()) + { + throw GCN_EXCEPTION("Corrupt image."); + } - int i = 0; - for (i = 0; separator == mImage->getPixel(i, 0) - && i < mImage->getWidth(); ++i) - { - } + int j = 0; + for (j = 0; j < mImage->getHeight(); ++j) + { + if (separator == mImage->getPixel(i, j)) + { + break; + } + } - if (i >= mImage->getWidth()) - { - throw GCN_EXCEPTION("Corrupt image."); - } + mHeight = j; + int x = 0, y = 0; - auto j = 0; - for (j = 0; j < mImage->getHeight(); ++j) - { - if (separator == mImage->getPixel(i, j)) - { - break; - } - } + for (i=glyphsFrom; igetWidth(); + //int h = mImage->getHeight(); + mImage->convertToDisplayFormat(); - for (i = glyphsFrom; i < glyphsTo + 1; i++) - { - addGlyph(i, x, y, separator); - } + mRowSpacing = 0; + mGlyphSpacing = 0; + } - //int w = mImage->getWidth(); - //int h = mImage->getHeight(); - mImage->convertToDisplayFormat(); + ImageFont::~ImageFont() + { + delete mImage; + } - mRowSpacing = 0; - mGlyphSpacing = 0; - } + int ImageFont::getWidth(unsigned char glyph) const + { + if (mGlyph[glyph].width == 0) + { + return mGlyph[(int)(' ')].width + mGlyphSpacing; + } - ImageFont::~ImageFont() - { - delete mImage; - } + return mGlyph[glyph].width + mGlyphSpacing; + } - int ImageFont::getWidth(unsigned char glyph) const - { - if (mGlyph[glyph].width == 0) - { - return mGlyph[int(' ')].width + mGlyphSpacing; - } + int ImageFont::getHeight() const + { + return mHeight + mRowSpacing; + } - return mGlyph[glyph].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; - int ImageFont::getHeight() const - { - return mHeight + mRowSpacing; - } + if (mGlyph[glyph].width == 0) + { + graphics->drawRectangle(Rectangle(x, y + 1 + yoffset, + mGlyph[(int)(' ')].width - 1, + mGlyph[(int)(' ')].height - 2)); - 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 - auto yoffset = getRowSpacing() >> 1; + return mGlyph[(int)(' ')].width + mGlyphSpacing; + } - if (mGlyph[glyph].width == 0) - { - graphics->drawRectangle(Rectangle(x, y + 1 + yoffset, - mGlyph[int(' ')].width - 1, - mGlyph[int(' ')].height - 2)); + graphics->drawImage(mImage, mGlyph[glyph].x, mGlyph[glyph].y, x, + y + yoffset, mGlyph[glyph].width, + mGlyph[glyph].height); - return mGlyph[int(' ')].width + mGlyphSpacing; - } + return mGlyph[glyph].width + mGlyphSpacing; + } - graphics->drawImage(mImage, mGlyph[glyph].x, mGlyph[glyph].y, x, - y + yoffset, mGlyph[glyph].width, - mGlyph[glyph].height); + void ImageFont::drawString(Graphics* graphics, const std::string& text, + int x, int y) + { + unsigned int i; - return mGlyph[glyph].width + mGlyphSpacing; - } + for (i = 0; i< text.size(); ++i) + { + drawGlyph(graphics, text.at(i), x, y); + x += getWidth(text.at(i)); + } + } - void ImageFont::drawString(Graphics* graphics, const std::string& text, - int x, int y) - { - for (auto i : text) - { - drawGlyph(graphics, i, x, y); - x += getWidth(i); - } - } + void ImageFont::setRowSpacing(int spacing) + { + mRowSpacing = spacing; + } - void ImageFont::setRowSpacing(int spacing) - { - mRowSpacing = spacing; - } + int ImageFont::getRowSpacing() + { + return mRowSpacing; + } - int ImageFont::getRowSpacing() - { - return mRowSpacing; - } + void ImageFont::setGlyphSpacing(int spacing) + { + mGlyphSpacing = spacing; + } - void ImageFont::setGlyphSpacing(int spacing) - { - mGlyphSpacing = spacing; - } + int ImageFont::getGlyphSpacing() + { + return mGlyphSpacing; + } - int ImageFont::getGlyphSpacing() - { - return mGlyphSpacing; - } + void ImageFont::addGlyph(unsigned char c, int &x, + int &y, const Color& separator) + { + Color color; + do + { + ++x; - void ImageFont::addGlyph(unsigned char c, int& x, - int& y, const Color& separator) - { - Color color; - do - { - ++x; + if (x >= mImage->getWidth()) + { + y += mHeight + 1; + x = 0; - if (x >= mImage->getWidth()) - { - y += mHeight + 1; - x = 0; + 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()); + } + } - 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()); - } - } + color = mImage->getPixel(x, y); - color = mImage->getPixel(x, y); - } - while (color == separator); + } while (color == separator); - auto w = 0; + int w = 0; - do - { - ++w; + do + { + ++w; - 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()); - } + 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()); + } - color = mImage->getPixel(x + w, y); - } - while (color != separator); + color = mImage->getPixel(x + w, y); - mGlyph[c] = Rectangle(x, y, w, mHeight); + } while (color != separator); - x += w; - } + mGlyph[c] = Rectangle(x, y, w, mHeight); - int ImageFont::getWidth(const std::string& text) const - { - auto size = 0; + x += w; + } - for (auto i : text) - { - size += getWidth(i); - } + int ImageFont::getWidth(const std::string& text) const + { + unsigned int i; + int size = 0; + + for (i = 0; i < text.size(); ++i) + { + size += getWidth(text.at(i)); + } return size - mGlyphSpacing; - } + } - int ImageFont::getStringIndexAt(const std::string& text, int x) - { - auto size = 0; + int ImageFont::getStringIndexAt(const std::string& text, int x) + { + unsigned int i; + int size = 0; - for (unsigned int i = 0; i < text.size(); ++i) - { - size += getWidth(text.at(i)); + for (i = 0; i < 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/guisan-dev/src/inputevent.cpp b/guisan-dev/src/inputevent.cpp index 16bd4c52..734e9904 100644 --- a/guisan-dev/src/inputevent.cpp +++ b/guisan-dev/src/inputevent.cpp @@ -62,47 +62,48 @@ 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::isControlPressed() const - { - return mControlPressed; - } + bool InputEvent::isShiftPressed() const + { + return mShiftPressed; + } - bool InputEvent::isAltPressed() const - { - return mAltPressed; - } + bool InputEvent::isControlPressed() const + { + return mControlPressed; + } - bool InputEvent::isMetaPressed() const - { - return mMetaPressed; - } + bool InputEvent::isAltPressed() const + { + return mAltPressed; + } - void InputEvent::consume() - { - mIsConsumed = true; - } + bool InputEvent::isMetaPressed() const + { + return mMetaPressed; + } - bool InputEvent::isConsumed() const - { - return mIsConsumed; - } + void InputEvent::consume() + { + mIsConsumed = true; + } + + bool InputEvent::isConsumed() const + { + return mIsConsumed; + } } diff --git a/guisan-dev/src/key.cpp b/guisan-dev/src/key.cpp index dd8d7588..7497a088 100644 --- a/guisan-dev/src/key.cpp +++ b/guisan-dev/src/key.cpp @@ -62,33 +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 + int Key::getValue() const + { + return mValue; + } + + char Key::getChar() const { - return mValue; + if(mValue == 9 || mValue == 13 || (mValue <= 122 && mValue >= 32)) + return (char)mValue; + + return '\0'; } } diff --git a/guisan-dev/src/keyevent.cpp b/guisan-dev/src/keyevent.cpp index d2e945ce..ff13596d 100644 --- a/guisan-dev/src/keyevent.cpp +++ b/guisan-dev/src/keyevent.cpp @@ -62,40 +62,43 @@ 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; + } - unsigned int KeyEvent::getType() const - { - return mType; - } + KeyEvent::~KeyEvent() + { - bool KeyEvent::isNumericPad() const - { - return mIsNumericPad; - } + } - const Key& KeyEvent::getKey() const - { - return mKey; - } + unsigned int KeyEvent::getType() const + { + return mType; + } + + bool KeyEvent::isNumericPad() const + { + return mIsNumericPad; + } + + const Key& KeyEvent::getKey() const + { + return mKey; + } } diff --git a/guisan-dev/src/keyinput.cpp b/guisan-dev/src/keyinput.cpp index d99c5024..dc485e58 100644 --- a/guisan-dev/src/keyinput.cpp +++ b/guisan-dev/src/keyinput.cpp @@ -62,84 +62,86 @@ namespace gcn { - KeyInput::KeyInput(const Key& key, int type) - : mKey(key), - mType(type), mButton(0), - 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; - } + } - int KeyInput::getType() const - { - return mType; - } + void KeyInput::setType(int type) + { + mType = type; + } - void KeyInput::setKey(const Key& key) - { - mKey = key; - } + int KeyInput::getType() const + { + return mType; + } - const Key& KeyInput::getKey() const - { - return mKey; - } + void KeyInput::setKey(const Key& key) + { + mKey = key; + } - bool KeyInput::isShiftPressed() const - { - return mShiftPressed; - } + const Key& KeyInput::getKey() const + { + return mKey; + } - void KeyInput::setShiftPressed(bool pressed) - { - mShiftPressed = pressed; - } + bool KeyInput::isShiftPressed() const + { + return mShiftPressed; + } - bool KeyInput::isControlPressed() const - { - return mControlPressed; - } + void KeyInput::setShiftPressed(bool pressed) + { + mShiftPressed = pressed; + } - void KeyInput::setControlPressed(bool pressed) - { - mControlPressed = pressed; - } + bool KeyInput::isControlPressed() const + { + return mControlPressed; + } - bool KeyInput::isAltPressed() const - { - return mAltPressed; - } + void KeyInput::setControlPressed(bool pressed) + { + mControlPressed = pressed; + } - void KeyInput::setAltPressed(bool pressed) - { - mAltPressed = pressed; - } + bool KeyInput::isAltPressed() const + { + return mAltPressed; + } - bool KeyInput::isMetaPressed() const - { - return mMetaPressed; - } + void KeyInput::setAltPressed(bool pressed) + { + mAltPressed = pressed; + } - void KeyInput::setMetaPressed(bool pressed) - { - mMetaPressed = pressed; - } + bool KeyInput::isMetaPressed() const + { + return mMetaPressed; + } - bool KeyInput::isNumericPad() const - { - return mNumericPad; - } + void KeyInput::setMetaPressed(bool pressed) + { + mMetaPressed = pressed; + } - void KeyInput::setNumericPad(bool numpad) - { - mNumericPad = numpad; - } + bool KeyInput::isNumericPad() const + { + return mNumericPad; + } + + void KeyInput::setNumericPad(bool numpad) + { + mNumericPad = numpad; + } } + diff --git a/guisan-dev/src/mouseevent.cpp b/guisan-dev/src/mouseevent.cpp index 289f025e..6c370569 100644 --- a/guisan-dev/src/mouseevent.cpp +++ b/guisan-dev/src/mouseevent.cpp @@ -62,51 +62,52 @@ 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; - } + } - int MouseEvent::getX() const - { - return mX; - } + unsigned int MouseEvent::getButton() const + { + return mButton; + } - int MouseEvent::getY() const - { - return mY; - } + int MouseEvent::getX() const + { + return mX; + } - int MouseEvent::getClickCount() const - { - return mClickCount; - } + int MouseEvent::getY() const + { + return mY; + } - unsigned int MouseEvent::getType() const - { - return mType; - } + int MouseEvent::getClickCount() const + { + return mClickCount; + } + + unsigned int MouseEvent::getType() const + { + return mType; + } } diff --git a/guisan-dev/src/mouseinput.cpp b/guisan-dev/src/mouseinput.cpp index f45dbbc7..153f536f 100644 --- a/guisan-dev/src/mouseinput.cpp +++ b/guisan-dev/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/guisan-dev/src/opengl/opengl.cpp b/guisan-dev/src/opengl/opengl.cpp index 47c6c64a..1e515373 100644 --- a/guisan-dev/src/opengl/opengl.cpp +++ b/guisan-dev/src/opengl/opengl.cpp @@ -60,8 +60,7 @@ #include "guisan/opengl.hpp" -extern "C" { -void gcnOpenGL() +extern "C" { -} + void gcnOpenGL() { } } diff --git a/guisan-dev/src/opengl/openglgraphics.cpp b/guisan-dev/src/opengl/openglgraphics.cpp index 87b95e7a..f2bfaede 100644 --- a/guisan-dev/src/opengl/openglgraphics.cpp +++ b/guisan-dev/src/opengl/openglgraphics.cpp @@ -68,7 +68,7 @@ #if defined(__APPLE__) #include #else -#include +#include #endif #include "guisan/exception.hpp" @@ -77,280 +77,277 @@ namespace gcn { - OpenGLGraphics::OpenGLGraphics() - { - OpenGLGraphics::setTargetPlane(640, 480); - mAlpha = false; - } + OpenGLGraphics::OpenGLGraphics() + { + setTargetPlane(640, 480); + mAlpha = false; + } - OpenGLGraphics::OpenGLGraphics(int width, int height) - { - OpenGLGraphics::setTargetPlane(width, height); - } + OpenGLGraphics::OpenGLGraphics(int width, int height) + { + setTargetPlane(width, height); + } - OpenGLGraphics::~OpenGLGraphics() - = default; + 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 - ); + } - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); + 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_TEXTURE); - glPushMatrix(); - glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + glLoadIdentity(); - glOrtho(0.0, double(mWidth), double(mHeight), 0.0, -1.0, 1.0); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); - glDisable(GL_LIGHTING); - glDisable(GL_CULL_FACE); - glDisable(GL_DEPTH_TEST); - glDisable(GL_TEXTURE_2D); + glOrtho(0.0, (double)mWidth, (double)mHeight, 0.0, -1.0, 1.0); - glEnable(GL_SCISSOR_TEST); - glPointSize(1.0); - glLineWidth(1.0); + glDisable(GL_LIGHTING); + glDisable(GL_CULL_FACE); + glDisable(GL_DEPTH_TEST); + glDisable(GL_TEXTURE_2D); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_SCISSOR_TEST); + glPointSize(1.0); + glLineWidth(1.0); - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - pushClipArea(Rectangle(0, 0, mWidth, mHeight)); - } + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - void OpenGLGraphics::_endDraw() - { - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); + pushClipArea(Rectangle(0, 0, mWidth, mHeight)); + } - glMatrixMode(GL_TEXTURE); - glPopMatrix(); + void OpenGLGraphics::_endDraw() + { + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); + glMatrixMode(GL_TEXTURE); + glPopMatrix(); - glPopAttrib(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); - popClipArea(); - } + glPopAttrib(); - bool OpenGLGraphics::pushClipArea(Rectangle area) - { - auto result = Graphics::pushClipArea(area); + popClipArea(); + } - glScissor(mClipStack.top().x, - mHeight - mClipStack.top().y - mClipStack.top().height, - mClipStack.top().width, - mClipStack.top().height); + bool OpenGLGraphics::pushClipArea(Rectangle area) + { + bool result = Graphics::pushClipArea(area); - return result; - } + glScissor(mClipStack.top().x, + mHeight - mClipStack.top().y - mClipStack.top().height, + mClipStack.top().width, + mClipStack.top().height); - void OpenGLGraphics::popClipArea() - { - Graphics::popClipArea(); + return result; + } - if (mClipStack.empty()) - { - return; - } + void OpenGLGraphics::popClipArea() + { + Graphics::popClipArea(); - glScissor(mClipStack.top().x, - mHeight - mClipStack.top().y - mClipStack.top().height, - mClipStack.top().width, - mClipStack.top().height); - } + if (mClipStack.empty()) + { + return; + } - void OpenGLGraphics::setTargetPlane(int width, int height) - { - mWidth = width; - mHeight = height; - } + glScissor(mClipStack.top().x, + mHeight - mClipStack.top().y - mClipStack.top().height, + mClipStack.top().width, + mClipStack.top().height); + } - void OpenGLGraphics::drawImage(const Image* image, int srcX, int srcY, - int dstX, int dstY, int width, - int height) - { - const auto* srcImage = dynamic_cast(image); + void OpenGLGraphics::setTargetPlane(int width, int height) + { + mWidth = width; + mHeight = height; + } - if (srcImage == nullptr) - { - throw GCN_EXCEPTION("Trying to draw an image of unknown format, must be an OpenGLImage."); - } + 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 (mClipStack.empty()) - { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you" - "called a draw funtion outside of _beginDraw() and _endDraw()?"); - } + if (srcImage == NULL) + { + throw GCN_EXCEPTION("Trying to draw an image of unknown format, must be an OpenGLImage."); + } - const auto& top = mClipStack.top(); + if (mClipStack.empty()) { + throw GCN_EXCEPTION("Clip stack is empty, perhaps you" + "called a draw funtion outside of _beginDraw() and _endDraw()?"); + } - dstX += top.xOffset; - dstY += top.yOffset; + const ClipRectangle& top = mClipStack.top(); - // Find OpenGL texture coordinates - auto texX1 = srcX / (float)srcImage->getTextureWidth(); - auto texY1 = srcY / (float)srcImage->getTextureHeight(); - auto texX2 = (srcX + width) / (float)srcImage->getTextureWidth(); - auto texY2 = (srcY + height) / (float)srcImage->getTextureHeight(); + dstX += top.xOffset; + dstY += top.yOffset; - glBindTexture(GL_TEXTURE_2D, srcImage->getTextureHandle()); + // 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(); - glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, srcImage->getTextureHandle()); - // Check if blending already is enabled - if (!mAlpha) - { - glEnable(GL_BLEND); - } + glEnable(GL_TEXTURE_2D); - // Draw a textured quad -- the image - glBegin(GL_QUADS); - glTexCoord2f(texX1, texY1); - glVertex3i(dstX, dstY, 0); + // Check if blending already is enabled + if (!mAlpha) + { + glEnable(GL_BLEND); + } - glTexCoord2f(texX1, texY2); - glVertex3i(dstX, dstY + height, 0); + // Draw a textured quad -- the image + glBegin(GL_QUADS); + glTexCoord2f(texX1, texY1); + glVertex3i(dstX, dstY, 0); - glTexCoord2f(texX2, texY2); - glVertex3i(dstX + width, dstY + height, 0); + glTexCoord2f(texX1, texY2); + glVertex3i(dstX, dstY + height, 0); - glTexCoord2f(texX2, texY1); - glVertex3i(dstX + width, dstY, 0); - glEnd(); - glDisable(GL_TEXTURE_2D); + glTexCoord2f(texX2, texY2); + glVertex3i(dstX + width, dstY + height, 0); - // Don't disable blending if the color has alpha - if (!mAlpha) - { - glDisable(GL_BLEND); - } - } + glTexCoord2f(texX2, texY1); + glVertex3i(dstX + width, dstY, 0); + glEnd(); + glDisable(GL_TEXTURE_2D); - 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(); + // Don't disable blending if the color has alpha + if (!mAlpha) + { + glDisable(GL_BLEND); + } + } - x += top.xOffset; - y += top.yOffset; + 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(); - glBegin(GL_POINTS); - glVertex2i(x, y); - glEnd(); - } + x += top.xOffset; + y += top.yOffset; - 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(); + glBegin(GL_POINTS); + glVertex2i(x, y); + glEnd(); + } - x1 += top.xOffset; - y1 += top.yOffset; - x2 += top.xOffset; - y2 += top.yOffset; + 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(); - glBegin(GL_LINES); - glVertex2f(x1 + 0.375f, y1 + 0.375f); - glVertex2f(x2 + 1.0f - 0.375f, y2 + 1.0f - 0.375f); - glEnd(); + x1 += top.xOffset; + y1 += top.yOffset; + x2 += top.xOffset; + y2 += top.yOffset; - glBegin(GL_POINTS); - 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(x1 + 0.375f, y1 + 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(); + } - 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(); + 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(); - 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 auto& 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 ClipRectangle& 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/guisan-dev/src/opengl/openglimage.cpp b/guisan-dev/src/opengl/openglimage.cpp index 71037195..d6a0d82d 100644 --- a/guisan-dev/src/opengl/openglimage.cpp +++ b/guisan-dev/src/opengl/openglimage.cpp @@ -64,40 +64,41 @@ 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 auto magicPink = 0xff00ffff; + const unsigned int magicPink = 0xff00ffff; #else - const auto magicPink = 0xffff00ff; + const unsigned int magicPink = 0xffff00ff; #endif - for (auto y = 0; y < mTextureHeight; y++) + int x, y; + for (y = 0; y < mTextureHeight; y++) { - for (auto x = 0; x < mTextureWidth; x++) + for (x = 0; x < mTextureWidth; x++) { if (x < mWidth && y < mHeight) { - auto c = pixels[x + y * mWidth]; + unsigned int c = pixels[x + y * mWidth]; // Magic pink to transparent if (c == magicPink) @@ -114,82 +115,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 = nullptr; + OpenGLImage::OpenGLImage(GLuint textureHandle, int width, int height, bool autoFree) + { + mTextureHandle = textureHandle; + mAutoFree = autoFree; + mPixels = NULL; 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) - { - OpenGLImage::free(); - } - } + OpenGLImage::~OpenGLImage() + { + if (mAutoFree) + { + 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 == nullptr) + void OpenGLImage::free() + { + if (mPixels == NULL) { glDeleteTextures(1, &mTextureHandle); } else { delete[] mPixels; - mPixels = nullptr; + mPixels = NULL; } - } + } - 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 == nullptr) + Color OpenGLImage::getPixel(int x, int y) + { + if (mPixels == NULL) { throw GCN_EXCEPTION("Image has been converted to display format"); } @@ -213,12 +214,12 @@ namespace gcn 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 == nullptr) + void OpenGLImage::putPixel(int x, int y, const Color& color) + { + if (mPixels == NULL) { throw GCN_EXCEPTION("Image has been converted to display format"); } @@ -235,66 +236,66 @@ namespace gcn #endif mPixels[x + y * mTextureWidth] = c; - } + } - void OpenGLImage::convertToDisplayFormat() - { - if (mPixels == nullptr) + void OpenGLImage::convertToDisplayFormat() + { + if (mPixels == NULL) { 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 = nullptr; + delete[] mPixels; + mPixels = NULL; - auto error = glGetError(); - if (error) - { - std::string errmsg; - switch (error) - { - case GL_INVALID_ENUM: - errmsg = "GL_INVALID_ENUM"; - break; + GLenum 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; + } - 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/guisan-dev/src/rectangle.cpp b/guisan-dev/src/rectangle.cpp index c01c876a..ce4b220c 100644 --- a/guisan-dev/src/rectangle.cpp +++ b/guisan-dev/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/guisan-dev/src/sdl/sdl.cpp b/guisan-dev/src/sdl/sdl.cpp index 57af79c1..28164a75 100644 --- a/guisan-dev/src/sdl/sdl.cpp +++ b/guisan-dev/src/sdl/sdl.cpp @@ -60,8 +60,7 @@ #include "guisan/sdl.hpp" -extern "C" { -void gcnSDL() +extern "C" { -} + void gcnSDL() { } } diff --git a/guisan-dev/src/sdl/sdl2graphics.cpp b/guisan-dev/src/sdl/sdl2graphics.cpp new file mode 100644 index 00000000..d7df26c1 --- /dev/null +++ b/guisan-dev/src/sdl/sdl2graphics.cpp @@ -0,0 +1,479 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson + * Copyright (c) 2016, 2018, 2019 Gwilherm Baudic + * Js_./ + * Per Larsson a.k.a finalman _RqZ{a<^_aa + * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// + * _Qhm`] _f "'c 1!5m + * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' + * binary forms, with or without )4d[#7r, . ' )d`)[ + * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' + * that the following conditions are met: j<. a J@\ + * this list of conditions and the j(]1uw; + 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); + } + + bool SDL2Graphics::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_RenderSetClipRect(mRenderTarget, &rect); + + return result; + } + + void SDL2Graphics::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_RenderSetClipRect(mRenderTarget, &rect); + } + + SDL_Renderer* SDL2Graphics::getTarget() const + { + return mRenderTarget; + } + + 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; + + const SDLImage* srcImage = dynamic_cast(image); + + 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::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 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_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(); + + } + 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); + saveRenderColor(); + SDL_SetRenderDrawColor(mRenderTarget, mColor.r, mColor.g, mColor.b, mColor.a); + SDL_RenderFillRect(mRenderTarget, &rect); + 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()?"); + } + + const ClipRectangle& top = mClipStack.top(); + + x += top.xOffset; + y += top.yOffset; + + if(!top.isPointInRect(x,y)) + return; + + 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::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(); + + 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 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); + } +} diff --git a/guisan-dev/src/sdl/sdlgraphics.cpp b/guisan-dev/src/sdl/sdlgraphics.cpp index 49498748..07e396bf 100644 --- a/guisan-dev/src/sdl/sdlgraphics.cpp +++ b/guisan-dev/src/sdl/sdlgraphics.cpp @@ -74,628 +74,615 @@ namespace gcn { - SDLGraphics::SDLGraphics() + + SDLGraphics::SDLGraphics() + { + mAlpha = false; + } + + SDLGraphics::~SDLGraphics() { - mAlpha = false; - mTarget = nullptr; + } - void clearTransparentSurface(SDL_Surface* s) - { - SDL_FillRect(s, nullptr, SDL_MapRGBA(s->format, 0, 0, 0, 0)); + void SDLGraphics::_beginDraw() + { + Rectangle area; + area.x = 0; + area.y = 0; + area.width = mTarget->w; + area.height = mTarget->h; + pushClipArea(area); + } + + 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; - clearTransparentSurface(mTarget); + 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(); + + 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 ClipRectangle& top = mClipStack.top(); - bool SDLGraphics::pushClipArea(Rectangle area) - { - SDL_Rect rect; - auto result = Graphics::pushClipArea(area); + x1 += top.xOffset; + y += top.yOffset; + x2 += top.xOffset; - const ClipRectangle& carea = mClipStack.top(); - rect.x = carea.x; - rect.y = carea.y; - rect.w = carea.width; - rect.h = carea.height; + if (y < top.y || y >= top.y + top.height) + return; - SDL_SetClipRect(mTarget, &rect); + if (x1 > x2) + { + x1 ^= x2; + x2 ^= x1; + x1 ^= x2; + } - return result; + 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()?"); } + const ClipRectangle& top = mClipStack.top(); - void SDLGraphics::popClipArea() - { - Graphics::popClipArea(); + x += top.xOffset; + y1 += top.yOffset; + y2 += top.yOffset; - if (mClipStack.empty()) - { - return; - } + if (x < top.x || x >= top.x + top.width) + return; - 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 (y1 > y2) + { + y1 ^= y2; + y2 ^= y1; + y1 ^= y2; + } - SDL_SetClipRect(mTarget, &rect); + 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()?"); } + const ClipRectangle& top = mClipStack.top(); - SDL_Surface* SDLGraphics::getTarget() const - { - return mTarget; - } + x1 += top.xOffset; + y1 += top.yOffset; + x2 += top.xOffset; + y2 += top.yOffset; - void SDLGraphics::drawImage(const Image* image, int srcX, - int srcY, int dstX, int dstY, - int width, int height) - { - if (mClipStack.empty()) - { + // 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()) { throw GCN_EXCEPTION("Clip stack is empty, perhaps you" - "called a draw funtion outside of _beginDraw() and _endDraw()?"); + "called a draw function outside of _beginDraw() and _endDraw()?"); } + const ClipRectangle& top = mClipStack.top(); - 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; + destination.x += top.xOffset; + destination.y += top.yOffset; - 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 funtion 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) - { - auto x1 = area.x > top.x ? area.x : top.x; - auto y1 = area.y > top.y ? area.y : top.y; - auto x2 = area.x + area.width < top.x + top.width ? area.x + area.width : top.x + top.width; - auto 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 funtion 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 funtion 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; - } - - 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; - } - } - 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 = (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 funtion 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; - } - - 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; - } - } - 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 funtion 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 - - auto dx = ABS(x2 - x1); - 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 (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) - { - 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 (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()) - { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you" - "called a draw funtion outside of _beginDraw() and _endDraw()?"); - } - const auto& top = mClipStack.top(); - - destination.x += top.xOffset; - destination.y += top.yOffset; - - SDL_BlitSurface(surface, &source, mTarget, &destination); - } + SDL_BlitSurface(surface, &source, mTarget, &destination); + } } diff --git a/guisan-dev/src/sdl/sdlimage.cpp b/guisan-dev/src/sdl/sdlimage.cpp index 8102e716..414ec59d 100644 --- a/guisan-dev/src/sdl/sdlimage.cpp +++ b/guisan-dev/src/sdl/sdlimage.cpp @@ -65,119 +65,140 @@ namespace gcn { - SDLImage::SDLImage(SDL_Surface* surface, bool autoFree) - { - 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(); + } + } + + SDL_Surface* SDLImage::getSurface() const + { + return mSurface; + } + + SDL_Texture* SDLImage::getTexture() const + { + return mTexture; } - SDLImage::~SDLImage() - { - if (mAutoFree) + int SDLImage::getWidth() const + { + if (mSurface == NULL) + { + throw GCN_EXCEPTION("Trying to get the width of a non loaded image."); + } + + return mSurface->w; + } + + int SDLImage::getHeight() const + { + if (mSurface == NULL) + { + throw GCN_EXCEPTION("Trying to get the height of a non loaded image."); + } + + 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."); + } + + 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."); + } + + SDLputPixel(mSurface, x, y, color); + } + + void SDLImage::convertToDisplayFormat() + { + if (mSurface == NULL) + { + throw GCN_EXCEPTION("Trying to convert a non loaded image to display format."); + } + + int i; + bool hasPink = false; + bool hasAlpha = false; + + 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) + { + Uint8 r, g, b, a; + + SDL_GetRGBA(((unsigned int*)mSurface->pixels)[i], mSurface->format, + &r, &g, &b, &a); + + if (a != 255) + { + surfaceMask = SDL_PIXELFORMAT_RGBA8888; + break; + } + } + + SDL_Surface* tmp = SDL_ConvertSurfaceFormat(mSurface, surfaceMask, 0); + SDL_FreeSurface(mSurface); + mSurface = NULL; + + if (hasPink) + { + SDL_SetColorKey(tmp, SDL_TRUE, + SDL_MapRGB(tmp->format,255,0,255)); + } + + if (surfaceMask == SDL_PIXELFORMAT_RGBA8888) + SDL_SetSurfaceAlphaMod(tmp, 255); + + mSurface = tmp; + + if (mRenderer) { - SDLImage::free(); + SDL_Texture *tmpTexture = SDL_CreateTextureFromSurface(mRenderer, tmp); + SDL_SetTextureBlendMode(tmpTexture, SDL_BLENDMODE_BLEND); + SDL_DestroyTexture(mTexture); + mTexture = tmpTexture; } - } + + } - SDL_Surface* SDLImage::getSurface() const - { - return mSurface; - } - - int SDLImage::getWidth() const - { - if (mSurface == nullptr) - { - throw GCN_EXCEPTION("Trying to get the width of a non loaded image."); - } - - return mSurface->w; - } - - int SDLImage::getHeight() const - { - if (mSurface == nullptr) - { - throw GCN_EXCEPTION("Trying to get the height of a non loaded image."); - } - - return mSurface->h; - } - - 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); - } - - 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); - } - - void SDLImage::convertToDisplayFormat() - { - if (mSurface == nullptr) - { - throw GCN_EXCEPTION("Trying to convert a non loaded image to display format."); - } - - int i; - auto hasPink = false; - auto hasAlpha = false; - - //unsigned int surfaceMask = SDL_PIXELFORMAT_RGBX8888; - - 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; - - SDL_GetRGBA(static_cast(mSurface->pixels)[i], mSurface->format, - &r, &g, &b, &a); - - if (a != 255) - { - hasAlpha = true; - break; - } - } - - SDL_Surface* tmp = mSurface; - - if (tmp == nullptr) - { - throw GCN_EXCEPTION("Unable to convert image to display format."); - } - - if (hasPink) - { - SDL_SetColorKey(tmp, SDL_TRUE, - SDL_MapRGB(tmp->format, 255, 0, 255)); - } - - mSurface = tmp; - } - - void SDLImage::free() - { - SDL_FreeSurface(mSurface); - } + void SDLImage::free() + { + SDL_FreeSurface(mSurface); + SDL_DestroyTexture(mTexture); + } } diff --git a/guisan-dev/src/sdl/sdlimageloader.cpp b/guisan-dev/src/sdl/sdlimageloader.cpp index 2bfebdbf..992d2edf 100644 --- a/guisan-dev/src/sdl/sdlimageloader.cpp +++ b/guisan-dev/src/sdl/sdlimageloader.cpp @@ -67,69 +67,79 @@ namespace gcn { - Image* SDLImageLoader::load(const std::string& filename, - bool convertToDisplayFormat) - { - auto loadedSurface = loadSDLSurface(filename); + Image* SDLImageLoader::load(const std::string& filename, + bool convertToDisplayFormat) + { + SDL_Surface *loadedSurface = loadSDLSurface(filename); - if (loadedSurface == nullptr) - { - throw GCN_EXCEPTION( - std::string("Unable to load image file: ") + filename); - } + if (loadedSurface == NULL) + { + throw GCN_EXCEPTION( + std::string("Unable to load image file: ") + filename); + } - auto surface = convertToStandardFormat(loadedSurface); - SDL_FreeSurface(loadedSurface); + SDL_Surface *surface = convertToStandardFormat(loadedSurface); + SDL_FreeSurface(loadedSurface); - if (surface == nullptr) - { - throw GCN_EXCEPTION( - std::string("Not enough memory to load: ") + filename); - } + if (surface == NULL) + { + throw GCN_EXCEPTION( + std::string("Not enough memory to load: ") + filename); + } - Image* image = new SDLImage(surface, true); + Image *image = new SDLImage(surface, true, mRenderer); - if (convertToDisplayFormat) - { - image->convertToDisplayFormat(); - } + if (convertToDisplayFormat) + { + image->convertToDisplayFormat(); + } - return image; + 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_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::convertToStandardFormat(SDL_Surface* surface) - { - Uint32 rmask, gmask, bmask, amask; + 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); + SDL_Surface *colorSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, + 0, 0, 32, + rmask, gmask, bmask, amask); - SDL_Surface* tmp = nullptr; + SDL_Surface *tmp = NULL; - if (colorSurface != nullptr) - { - tmp = SDL_ConvertSurface(surface, colorSurface->format, - SDL_SWSURFACE); - SDL_FreeSurface(colorSurface); - } + if (colorSurface != NULL) + { + tmp = SDL_ConvertSurface(surface, colorSurface->format, + SDL_SWSURFACE); + SDL_FreeSurface(colorSurface); + } - return tmp; - } + return tmp; + } } diff --git a/guisan-dev/src/sdl/sdlinput.cpp b/guisan-dev/src/sdl/sdlinput.cpp index 36ca9cd6..bcb6c39c 100644 --- a/guisan-dev/src/sdl/sdlinput.cpp +++ b/guisan-dev/src/sdl/sdlinput.cpp @@ -64,388 +64,393 @@ 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() - { - if (mKeyInputQueue.empty()) - { - throw GCN_EXCEPTION("The queue is empty."); - } + KeyInput SDLInput::dequeueKeyInput() + { + KeyInput keyInput; - auto keyInput = mKeyInputQueue.front(); - mKeyInputQueue.pop(); + if (mKeyInputQueue.empty()) + { + throw GCN_EXCEPTION("The queue is empty."); + } - return keyInput; - } + keyInput = mKeyInputQueue.front(); + mKeyInputQueue.pop(); - bool SDLInput::isMouseQueueEmpty() - { - return mMouseInputQueue.empty(); - } + return keyInput; + } - MouseInput SDLInput::dequeueMouseInput() - { - if (mMouseInputQueue.empty()) - { - throw GCN_EXCEPTION("The queue is empty."); - } + bool SDLInput::isMouseQueueEmpty() + { + return mMouseInputQueue.empty(); + } - auto mouseInput = mMouseInputQueue.front(); - mMouseInputQueue.pop(); + MouseInput SDLInput::dequeueMouseInput() + { + MouseInput mouseInput; - return mouseInput; - } + if (mMouseInputQueue.empty()) + { + throw GCN_EXCEPTION("The queue is empty."); + } - void SDLInput::pushInput(SDL_Event event) - { - KeyInput keyInput; - MouseInput mouseInput; + mouseInput = mMouseInputQueue.front(); + mMouseInputQueue.pop(); - 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); + return mouseInput; + } - mKeyInputQueue.push(keyInput); - break; + void SDLInput::pushInput(SDL_Event event) + { + KeyInput keyInput; + MouseInput mouseInput; - 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); + 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); - mKeyInputQueue.push(keyInput); - break; + mKeyInputQueue.push(keyInput); + 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_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_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; + mKeyInputQueue.push(keyInput); + 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_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_MOUSEWHEEL: - if (event.wheel.y > 0) - mouseInput.setType(MouseInput::WHEEL_MOVED_UP); - else - mouseInput.setType(MouseInput::WHEEL_MOVED_DOWN); - 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_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_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; - if (!mMouseDown) - { - mouseInput.setX(-1); - mouseInput.setY(-1); - mouseInput.setButton(MouseInput::EMPTY); - mouseInput.setType(MouseInput::MOVED); - mMouseInputQueue.push(mouseInput); - } - } + case SDL_MOUSEWHEEL: + if (event.wheel.y > 0) + mouseInput.setType(MouseInput::WHEEL_MOVED_UP); + else + mouseInput.setType(MouseInput::WHEEL_MOVED_DOWN); + break; - if (event.window.event & SDL_WINDOWEVENT_ENTER) - { - mMouseInWindow = true; - } - break; - } // end switch - } + 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; - 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; - } - } + if (!mMouseDown) + { + mouseInput.setX(-1); + mouseInput.setY(-1); + mouseInput.setButton(MouseInput::EMPTY); + mouseInput.setType(MouseInput::MOVED); + mMouseInputQueue.push(mouseInput); + } + } - int SDLInput::convertKeyCharacter(SDL_Event event) - { - SDL_Keysym keysym = event.key.keysym; + if (event.window.event & SDL_WINDOWEVENT_ENTER) + { + mMouseInWindow = true; + } + break; - 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; + } // end switch + } - default: - value = keysym.sym; - 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; + } + } - 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; - } - } + 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; - return value; - } + 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; + } } diff --git a/guisan-dev/src/sdl/sdltruetypefont.cpp b/guisan-dev/src/sdl/sdltruetypefont.cpp index 5fa50ffc..48466f3f 100644 --- a/guisan-dev/src/sdl/sdltruetypefont.cpp +++ b/guisan-dev/src/sdl/sdltruetypefont.cpp @@ -51,20 +51,21 @@ #include "guisan/image.hpp" #include "guisan/graphics.hpp" #include "guisan/sdl/sdlgraphics.hpp" +#include "guisan/sdl/sdl2graphics.hpp" namespace gcn { - SDLTrueTypeFont::SDLTrueTypeFont(const std::string& filename, int size): mHeight(0) + SDLTrueTypeFont::SDLTrueTypeFont (const std::string& filename, int size) { mRowSpacing = 0; mGlyphSpacing = 0; - mAntiAlias = true; + mAntiAlias = true; mFilename = filename; - mFont = nullptr; - + mFont = NULL; + mFont = TTF_OpenFont(filename.c_str(), size); - - if (mFont == nullptr) + + if (mFont == NULL) { throw GCN_EXCEPTION("SDLTrueTypeFont::SDLTrueTypeFont. "+std::string(TTF_GetError())); } @@ -79,7 +80,7 @@ namespace gcn { int w, h; TTF_SizeText(mFont, text.c_str(), &w, &h); - + return w; } @@ -88,32 +89,42 @@ namespace gcn return TTF_FontHeight(mFont) + mRowSpacing; } - void SDLTrueTypeFont::drawString(Graphics* graphics, const std::string& text, const int x, const int y) + void SDLTrueTypeFont::drawString(gcn::Graphics* graphics, const std::string& text, const int x, const int y) { - if (text.empty()) + if (text == "") { return; } + + gcn::SDLGraphics *sdlGraphics = dynamic_cast(graphics); + gcn::SDL2Graphics *sdl2Graphics = dynamic_cast(graphics); + - SDLGraphics* sdlGraphics = dynamic_cast(graphics); - - if (sdlGraphics == nullptr) + if (sdlGraphics == NULL && sdl2Graphics == NULL) { 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 - auto yoffset = getRowSpacing() / 2; - - auto col = sdlGraphics->getColor(); + int yoffset = getRowSpacing() / 2; + + Color col; + if (sdlGraphics) + { + col = sdlGraphics->getColor(); + } + else + { + col = sdl2Graphics->getColor(); + } SDL_Color sdlCol; sdlCol.b = col.b; 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); @@ -122,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; @@ -130,9 +141,19 @@ namespace gcn src.h = textSurface->h; src.x = 0; src.y = 0; - - sdlGraphics->drawSDLSurface(textSurface, src, dst); - SDL_FreeSurface(textSurface); + dst.w = src.w; + dst.h = src.h; + + if (sdlGraphics) + { + sdlGraphics->drawSDLSurface(textSurface, src, dst); + } + else + { + sdl2Graphics->drawSDLSurface(textSurface, src, dst); + } + + SDL_FreeSurface(textSurface); } void SDLTrueTypeFont::setRowSpacing(int spacing) @@ -162,6 +183,8 @@ namespace gcn bool SDLTrueTypeFont::isAntiAlias() { - return mAntiAlias; - } + return mAntiAlias; + } + } + diff --git a/guisan-dev/src/selectionevent.cpp b/guisan-dev/src/selectionevent.cpp index cbfd6e02..81c7970f 100644 --- a/guisan-dev/src/selectionevent.cpp +++ b/guisan-dev/src/selectionevent.cpp @@ -62,11 +62,15 @@ namespace gcn { - SelectionEvent::SelectionEvent(Widget* source) - : Event(source) - { - } + SelectionEvent::SelectionEvent(Widget* source) + :Event(source) + { - SelectionEvent::~SelectionEvent() - = default; + } + + SelectionEvent::~SelectionEvent() + { + + } } + diff --git a/guisan-dev/src/widget.cpp b/guisan-dev/src/widget.cpp index f1793422..43baca62 100644 --- a/guisan-dev/src/widget.cpp +++ b/guisan-dev/src/widget.cpp @@ -76,622 +76,638 @@ namespace gcn { - Font* Widget::mGlobalFont = nullptr; - DefaultFont Widget::mDefaultFont; - std::list Widget::mWidgets; - - Widget::Widget() - : mForegroundColor(0x000000), - mBackgroundColor(0xffffff), - mBaseColor(0xDDDDE3), - mSelectionColor(0xc3d9ff), - mFocusHandler(nullptr), - mInternalFocusHandler(nullptr), - mParent(nullptr), - mBorderSize(0), - mFocusable(false), - mVisible(true), - mTabIn(true), - mTabOut(true), - mEnabled(true), - mCurrentFont(nullptr) - { - mWidgets.push_back(this); - } - - Widget::~Widget() - { - for (auto& mDeathListener : mDeathListeners) - { - Event event(this); - mDeathListener->death(event); - } - - Widget::_setFocusHandler(nullptr); - - mWidgets.remove(this); - } - - void Widget::_setParent(Widget* parent) - { - mParent = parent; - } - - Widget* Widget::getParent() const - { - return mParent; - } - - void Widget::setWidth(int width) - { - auto newDimension = mDimension; - newDimension.width = width; - - setDimension(newDimension); - } - - int Widget::getWidth() const - { - return mDimension.width; - } - - void Widget::setHeight(int height) - { - auto newDimension = mDimension; - newDimension.height = height; - - setDimension(newDimension); - } - - int Widget::getHeight() const - { - return mDimension.height; - } - - void Widget::setX(int x) - { - auto newDimension = mDimension; - newDimension.x = x; - - setDimension(newDimension); - } - - int Widget::getX() const - { - return mDimension.x; - } - - void Widget::setY(int y) - { - auto newDimension = mDimension; - newDimension.y = y; - - setDimension(newDimension); - } - - int Widget::getY() const - { - return mDimension.y; - } - - void Widget::setPosition(int x, int y) - { - auto newDimension = mDimension; - newDimension.x = x; - newDimension.y = y; - - setDimension(newDimension); - } - - void Widget::setDimension(const Rectangle& dimension) - { - auto oldDimension = mDimension; - mDimension = dimension; - - if (mDimension.width != oldDimension.width - || mDimension.height != oldDimension.height) - { - distributeResizedEvent(); - } - - if (mDimension.x != oldDimension.x - || mDimension.y != oldDimension.y) - { - distributeMovedEvent(); - } - } - - void Widget::setBorderSize(unsigned int borderSize) - { - mBorderSize = borderSize; - } - - unsigned int Widget::getBorderSize() const - { - return mBorderSize; - } - - const Rectangle& Widget::getDimension() const - { - return mDimension; - } - - const std::string& Widget::getActionEventId() const - { - return mActionEventId; - } - - void Widget::setActionEventId(const std::string& actionEventId) - { - mActionEventId = actionEventId; - } - - bool Widget::isFocused() const - { - if (!mFocusHandler) - { - return false; - } - - return (mFocusHandler->isFocused(this)); - } - - void Widget::setFocusable(bool focusable) - { - if (!focusable && isFocused()) - { - mFocusHandler->focusNone(); - } - - mFocusable = focusable; - } - - bool Widget::isFocusable() const - { - return mFocusable && isVisible() && isEnabled(); - } - - void Widget::requestFocus() - { - if (mFocusHandler == nullptr) - { - throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); - } - - if (isFocusable()) - { - mFocusHandler->requestFocus(this); - } - } - - void Widget::requestMoveToTop() - { - if (mParent) - { - mParent->moveToTop(this); - } - } - - void Widget::requestMoveToBottom() - { - if (mParent) - { - mParent->moveToBottom(this); - } - } - - void Widget::setVisible(bool visible) - { - if (!visible && isFocused()) - { - mFocusHandler->focusNone(); - } - - if (visible) - { - distributeShownEvent(); - } - else if (!visible) - { - distributeHiddenEvent(); - } - - mVisible = visible; - } - - bool Widget::isVisible() const - { - if (getParent() == nullptr) - { - return mVisible; - } - return mVisible && getParent()->isVisible(); - } - - void Widget::setBaseColor(const Color& color) - { - mBaseColor = color; - } - - const Color& Widget::getBaseColor() const - { - return mBaseColor; - } - - void Widget::setForegroundColor(const Color& color) - { - mForegroundColor = color; - } - - const Color& Widget::getForegroundColor() const - { - return mForegroundColor; - } - - void Widget::setBackgroundColor(const Color& color) - { - mBackgroundColor = color; - } - - const Color& Widget::getBackgroundColor() const - { - return mBackgroundColor; - } - - void Widget::setSelectionColor(const Color& color) - { - mSelectionColor = color; - } - - const Color& Widget::getSelectionColor() const - { - return mSelectionColor; - } - - void Widget::_setFocusHandler(FocusHandler* focusHandler) - { - if (mFocusHandler) - { - releaseModalFocus(); - mFocusHandler->remove(this); - } - - if (focusHandler) - { - focusHandler->add(this); - } - - mFocusHandler = focusHandler; - } - - FocusHandler* Widget::_getFocusHandler() - { - return mFocusHandler; - } - - void Widget::addActionListener(ActionListener* actionListener) - { - mActionListeners.push_back(actionListener); - } - - void Widget::removeActionListener(ActionListener* actionListener) - { - mActionListeners.remove(actionListener); - } - - void Widget::addDeathListener(DeathListener* deathListener) - { - mDeathListeners.push_back(deathListener); - } - - void Widget::removeDeathListener(DeathListener* deathListener) - { - mDeathListeners.remove(deathListener); - } - - void Widget::addKeyListener(KeyListener* keyListener) - { - mKeyListeners.push_back(keyListener); - } - - void Widget::removeKeyListener(KeyListener* keyListener) - { - mKeyListeners.remove(keyListener); - } - - void Widget::addFocusListener(FocusListener* focusListener) - { - mFocusListeners.push_back(focusListener); - } - - void Widget::removeFocusListener(FocusListener* focusListener) - { - mFocusListeners.remove(focusListener); - } - - void Widget::addMouseListener(MouseListener* mouseListener) - { - mMouseListeners.push_back(mouseListener); - } - - void Widget::removeMouseListener(MouseListener* mouseListener) - { - mMouseListeners.remove(mouseListener); - } - - void Widget::addWidgetListener(WidgetListener* widgetListener) - { - mWidgetListeners.push_back(widgetListener); - } - - void Widget::removeWidgetListener(WidgetListener* widgetListener) - { - mWidgetListeners.remove(widgetListener); - } - - void Widget::getAbsolutePosition(int& x, int& y) const - { - if (getParent() == nullptr) - { - x = mDimension.x; - y = mDimension.y; - return; - } - - int parentX; - int parentY; - - getParent()->getAbsolutePosition(parentX, parentY); - - x = parentX + mDimension.x + getParent()->getChildrenArea().x; - y = parentY + mDimension.y + getParent()->getChildrenArea().y; - } - - void Widget::generateAction() - { - for (auto& mActionListener : mActionListeners) - { - ActionEvent actionEvent(this, mActionEventId); - mActionListener->action(actionEvent); - } - } - - Font* Widget::getFont() const - { - if (mCurrentFont == nullptr) - { - if (mGlobalFont == nullptr) - { - return &mDefaultFont; - } - - return mGlobalFont; - } - - return mCurrentFont; - } - - void Widget::setGlobalFont(Font* font) - { - mGlobalFont = font; - - for (auto& mWidget : mWidgets) - { - if (mWidget->mCurrentFont == nullptr) - { - mWidget->fontChanged(); - } - } - } - - void Widget::setFont(Font* font) - { - mCurrentFont = font; - fontChanged(); - } - - bool Widget::widgetExists(const Widget* widget) - { - auto result = false; - - for (auto& mWidget : mWidgets) - { - if (mWidget == widget) - { - return true; - } - } - - return result; - } - - bool Widget::isTabInEnabled() const - { - return mTabIn; - } - - void Widget::setTabInEnabled(bool enabled) - { - mTabIn = enabled; - } - - bool Widget::isTabOutEnabled() const - { - return mTabOut; - } - - void Widget::setTabOutEnabled(bool enabled) - { - mTabOut = enabled; - } - - void Widget::setSize(int width, int height) - { - auto newDimension = mDimension; - newDimension.width = width; - newDimension.height = height; - - setDimension(newDimension); - } - - void Widget::setEnabled(bool enabled) - { - mEnabled = enabled; - } - - bool Widget::isEnabled() const - { - return mEnabled && isVisible(); - } - - void Widget::requestModalFocus() - { - if (mFocusHandler == nullptr) - { - throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); - } - - mFocusHandler->requestModalFocus(this); - } - - void Widget::requestModalMouseInputFocus() - { - if (mFocusHandler == nullptr) - { - throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); - } - - mFocusHandler->requestModalMouseInputFocus(this); - } - - void Widget::releaseModalFocus() - { - if (mFocusHandler == nullptr) - { - return; - } - - mFocusHandler->releaseModalFocus(this); - } - - void Widget::releaseModalMouseInputFocus() - { - if (mFocusHandler == nullptr) - { - return; - } - - mFocusHandler->releaseModalMouseInputFocus(this); - } - - bool Widget::hasModalFocus() const - { - if (mFocusHandler == nullptr) - { - throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); - } - - if (getParent() != nullptr) - { - return (mFocusHandler->getModalFocused() == this) || getParent()->hasModalFocus(); - } - - return mFocusHandler->getModalFocused() == this; - } - - bool Widget::hasModalMouseInputFocus() const - { - if (mFocusHandler == nullptr) - { - throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); - } - - if (getParent() != nullptr) - { - return (mFocusHandler->getModalMouseInputFocused() == this) || getParent()->hasModalMouseInputFocus(); - } - - return mFocusHandler->getModalMouseInputFocused() == this; - } - - Widget* Widget::getWidgetAt(int x, int y) - { - return nullptr; - } - - const std::list& Widget::_getMouseListeners() - { - return mMouseListeners; - } - - const std::list& Widget::_getKeyListeners() - { - return mKeyListeners; - } - - const std::list& Widget::_getFocusListeners() - { - return mFocusListeners; - } - - Rectangle Widget::getChildrenArea() - { - return Rectangle(0, 0, 0, 0); - } - - FocusHandler* Widget::_getInternalFocusHandler() - { - return mInternalFocusHandler; - } - - void Widget::setInternalFocusHandler(FocusHandler* focusHandler) - { - mInternalFocusHandler = focusHandler; - } - - void Widget::setId(const std::string& id) - { - mId = id; - } - - const std::string& Widget::getId() - { - return mId; - } - - void Widget::distributeResizedEvent() - { - for (auto& mWidgetListener : mWidgetListeners) - { - Event event(this); - mWidgetListener->widgetResized(event); - } - } - - void Widget::distributeMovedEvent() - { - for (auto& mWidgetListener : mWidgetListeners) - { - Event event(this); - mWidgetListener->widgetMoved(event); - } - } - - void Widget::distributeHiddenEvent() - { - for (auto& mWidgetListener : mWidgetListeners) - { - Event event(this); - mWidgetListener->widgetHidden(event); - } - } - - void Widget::distributeShownEvent() - { - for (auto& mWidgetListener : mWidgetListeners) - { - Event event(this); - mWidgetListener->widgetShown(event); - } - } + Font* Widget::mGlobalFont = NULL; + DefaultFont Widget::mDefaultFont; + std::list Widget::mWidgets; + + Widget::Widget() + : mForegroundColor(0x000000), + mBackgroundColor(0xffffff), + mBaseColor(0xDDDDE3), + mSelectionColor(0xc3d9ff), + mFocusHandler(NULL), + mInternalFocusHandler(NULL), + mParent(NULL), + mBorderSize(0), + mFocusable(false), + mVisible(true), + mTabIn(true), + mTabOut(true), + mEnabled(true), + mCurrentFont(NULL) + { + mWidgets.push_back(this); + } + + Widget::~Widget() + { + DeathListenerIterator iter; + + for (iter = mDeathListeners.begin(); iter != mDeathListeners.end(); ++iter) + { + Event event(this); + (*iter)->death(event); + } + + _setFocusHandler(NULL); + + mWidgets.remove(this); + } + + void Widget::_setParent(Widget* parent) + { + mParent = parent; + } + + Widget* Widget::getParent() const + { + return mParent; + } + + void Widget::setWidth(int width) + { + Rectangle newDimension = mDimension; + newDimension.width = width; + + setDimension(newDimension); + } + + int Widget::getWidth() const + { + return mDimension.width; + } + + void Widget::setHeight(int height) + { + Rectangle newDimension = mDimension; + newDimension.height = height; + + setDimension(newDimension); + } + + int Widget::getHeight() const + { + return mDimension.height; + } + + void Widget::setX(int x) + { + Rectangle newDimension = mDimension; + newDimension.x = x; + + setDimension(newDimension); + } + + int Widget::getX() const + { + return mDimension.x; + } + + void Widget::setY(int y) + { + Rectangle newDimension = mDimension; + newDimension.y = y; + + setDimension(newDimension); + } + + int Widget::getY() const + { + return mDimension.y; + } + + void Widget::setPosition(int x, int y) + { + Rectangle newDimension = mDimension; + newDimension.x = x; + newDimension.y = y; + + setDimension(newDimension); + } + + void Widget::setDimension(const Rectangle& dimension) + { + Rectangle oldDimension = mDimension; + mDimension = dimension; + + if (mDimension.width != oldDimension.width + || mDimension.height != oldDimension.height) + { + distributeResizedEvent(); + } + + if (mDimension.x != oldDimension.x + || mDimension.y != oldDimension.y) + { + distributeMovedEvent(); + } + } + + void Widget::setBorderSize(unsigned int borderSize) + { + mBorderSize = borderSize; + } + + unsigned int Widget::getBorderSize() const + { + return mBorderSize; + } + + const Rectangle& Widget::getDimension() const + { + return mDimension; + } + + const std::string& Widget::getActionEventId() const + { + return mActionEventId; + } + + void Widget::setActionEventId(const std::string& actionEventId) + { + mActionEventId = actionEventId; + } + + bool Widget::isFocused() const + { + if (!mFocusHandler) + { + return false; + } + + return (mFocusHandler->isFocused(this)); + } + + void Widget::setFocusable(bool focusable) + { + if (!focusable && isFocused()) + { + mFocusHandler->focusNone(); + } + + mFocusable = focusable; + } + + bool Widget::isFocusable() const + { + return mFocusable && isVisible() && isEnabled(); + } + + void Widget::requestFocus() + { + if (mFocusHandler == NULL) + { + throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); + } + + if (isFocusable()) + { + mFocusHandler->requestFocus(this); + } + } + + void Widget::requestMoveToTop() + { + if (mParent) + { + mParent->moveToTop(this); + } + } + + void Widget::requestMoveToBottom() + { + if (mParent) + { + mParent->moveToBottom(this); + } + } + + void Widget::setVisible(bool visible) + { + if (!visible && isFocused()) + { + mFocusHandler->focusNone(); + } + + if (visible) + { + distributeShownEvent(); + } + else if(!visible) + { + distributeHiddenEvent(); + } + + mVisible = visible; + } + + bool Widget::isVisible() const + { + if (getParent() == NULL) + { + return mVisible; + } + else + { + return mVisible && getParent()->isVisible(); + } + } + + void Widget::setBaseColor(const Color& color) + { + mBaseColor = color; + } + + const Color& Widget::getBaseColor() const + { + return mBaseColor; + } + + void Widget::setForegroundColor(const Color& color) + { + mForegroundColor = color; + } + + const Color& Widget::getForegroundColor() const + { + return mForegroundColor; + } + + void Widget::setBackgroundColor(const Color& color) + { + mBackgroundColor = color; + } + + const Color& Widget::getBackgroundColor() const + { + return mBackgroundColor; + } + + void Widget::setSelectionColor(const Color& color) + { + mSelectionColor = color; + } + + const Color& Widget::getSelectionColor() const + { + return mSelectionColor; + } + + void Widget::_setFocusHandler(FocusHandler* focusHandler) + { + if (mFocusHandler) + { + releaseModalFocus(); + mFocusHandler->remove(this); + } + + if (focusHandler) + { + focusHandler->add(this); + } + + mFocusHandler = focusHandler; + } + + FocusHandler* Widget::_getFocusHandler() + { + return mFocusHandler; + } + + void Widget::addActionListener(ActionListener* actionListener) + { + mActionListeners.push_back(actionListener); + } + + void Widget::removeActionListener(ActionListener* actionListener) + { + mActionListeners.remove(actionListener); + } + + void Widget::addDeathListener(DeathListener* deathListener) + { + mDeathListeners.push_back(deathListener); + } + + void Widget::removeDeathListener(DeathListener* deathListener) + { + mDeathListeners.remove(deathListener); + } + + void Widget::addKeyListener(KeyListener* keyListener) + { + mKeyListeners.push_back(keyListener); + } + + void Widget::removeKeyListener(KeyListener* keyListener) + { + mKeyListeners.remove(keyListener); + } + + void Widget::addFocusListener(FocusListener* focusListener) + { + mFocusListeners.push_back(focusListener); + } + + void Widget::removeFocusListener(FocusListener* focusListener) + { + mFocusListeners.remove(focusListener); + } + + void Widget::addMouseListener(MouseListener* mouseListener) + { + mMouseListeners.push_back(mouseListener); + } + + void Widget::removeMouseListener(MouseListener* mouseListener) + { + mMouseListeners.remove(mouseListener); + } + + void Widget::addWidgetListener(WidgetListener* widgetListener) + { + mWidgetListeners.push_back(widgetListener); + } + + void Widget::removeWidgetListener(WidgetListener* widgetListener) + { + mWidgetListeners.remove(widgetListener); + } + + void Widget::getAbsolutePosition(int& x, int& y) const + { + if (getParent() == NULL) + { + x = mDimension.x; + y = mDimension.y; + return; + } + + int parentX; + int parentY; + + getParent()->getAbsolutePosition(parentX, parentY); + + x = parentX + mDimension.x + getParent()->getChildrenArea().x; + y = parentY + mDimension.y + getParent()->getChildrenArea().y; + } + + void Widget::generateAction() + { + ActionListenerIterator iter; + for (iter = mActionListeners.begin(); iter != mActionListeners.end(); ++iter) + { + ActionEvent actionEvent(this, mActionEventId); + (*iter)->action(actionEvent); + } + } + + Font* Widget::getFont() const + { + if (mCurrentFont == NULL) + { + if (mGlobalFont == NULL) + { + return &mDefaultFont; + } + + return mGlobalFont; + } + + return mCurrentFont; + } + + void Widget::setGlobalFont(Font* font) + { + mGlobalFont = font; + + std::list::iterator iter; + for (iter = mWidgets.begin(); iter != mWidgets.end(); ++iter) + { + if ((*iter)->mCurrentFont == NULL) + { + (*iter)->fontChanged(); + } + } + } + + void Widget::setFont(Font* font) + { + mCurrentFont = font; + fontChanged(); + } + + bool Widget::widgetExists(const Widget* widget) + { + bool result = false; + + std::list::iterator iter; + for (iter = mWidgets.begin(); iter != mWidgets.end(); ++iter) + { + if (*iter == widget) + { + return true; + } + } + + return result; + } + + bool Widget::isTabInEnabled() const + { + return mTabIn; + } + + void Widget::setTabInEnabled(bool enabled) + { + mTabIn = enabled; + } + + bool Widget::isTabOutEnabled() const + { + return mTabOut; + } + + void Widget::setTabOutEnabled(bool enabled) + { + mTabOut = enabled; + } + + void Widget::setSize(int width, int height) + { + Rectangle newDimension = mDimension; + newDimension.width = width; + newDimension.height = height; + + setDimension(newDimension); + } + + void Widget::setEnabled(bool enabled) + { + mEnabled = enabled; + } + + bool Widget::isEnabled() const + { + return mEnabled && isVisible(); + } + + void Widget::requestModalFocus() + { + if (mFocusHandler == NULL) + { + throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); + } + + mFocusHandler->requestModalFocus(this); + } + + void Widget::requestModalMouseInputFocus() + { + if (mFocusHandler == NULL) + { + throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); + } + + mFocusHandler->requestModalMouseInputFocus(this); + } + + void Widget::releaseModalFocus() + { + if (mFocusHandler == NULL) + { + return; + } + + mFocusHandler->releaseModalFocus(this); + } + + void Widget::releaseModalMouseInputFocus() + { + if (mFocusHandler == NULL) + { + return; + } + + mFocusHandler->releaseModalMouseInputFocus(this); + } + + bool Widget::hasModalFocus() const + { + if (mFocusHandler == NULL) + { + throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); + } + + if (getParent() != NULL) + { + return (mFocusHandler->getModalFocused() == this) || getParent()->hasModalFocus(); + } + + return mFocusHandler->getModalFocused() == this; + } + + bool Widget::hasModalMouseInputFocus() const + { + if (mFocusHandler == NULL) + { + throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); + } + + if (getParent() != NULL) + { + return (mFocusHandler->getModalMouseInputFocused() == this) || getParent()->hasModalMouseInputFocus(); + } + + return mFocusHandler->getModalMouseInputFocused() == this; + } + + Widget *Widget::getWidgetAt(int x, int y) + { + return NULL; + } + + const std::list& Widget::_getMouseListeners() + { + return mMouseListeners; + } + + const std::list& Widget::_getKeyListeners() + { + return mKeyListeners; + } + + const std::list& Widget::_getFocusListeners() + { + return mFocusListeners; + } + + Rectangle Widget::getChildrenArea() + { + return Rectangle(0, 0, 0, 0); + } + + FocusHandler* Widget::_getInternalFocusHandler() + { + return mInternalFocusHandler; + } + + void Widget::setInternalFocusHandler(FocusHandler* focusHandler) + { + mInternalFocusHandler = focusHandler; + } + + void Widget::setId(const std::string& id) + { + mId = id; + } + + const std::string& Widget::getId() + { + return mId; + } + + void Widget::distributeResizedEvent() + { + WidgetListenerIterator iter; + + for (iter = mWidgetListeners.begin(); iter != mWidgetListeners.end(); ++iter) + { + Event event(this); + (*iter)->widgetResized(event); + } + } + + void Widget::distributeMovedEvent() + { + WidgetListenerIterator iter; + + for (iter = mWidgetListeners.begin(); iter != mWidgetListeners.end(); ++iter) + { + Event event(this); + (*iter)->widgetMoved(event); + } + } + + void Widget::distributeHiddenEvent() + { + WidgetListenerIterator iter; + + for (iter = mWidgetListeners.begin(); iter != mWidgetListeners.end(); ++iter) + { + Event event(this); + (*iter)->widgetHidden(event); + } + } + + void Widget::distributeShownEvent() + { + WidgetListenerIterator iter; + + for (iter = mWidgetListeners.begin(); iter != mWidgetListeners.end(); ++iter) + { + Event event(this); + (*iter)->widgetShown(event); + } + } } diff --git a/guisan-dev/src/widgets/button.cpp b/guisan-dev/src/widgets/button.cpp index ea98a90d..0fca164e 100644 --- a/guisan-dev/src/widgets/button.cpp +++ b/guisan-dev/src/widgets/button.cpp @@ -69,248 +69,253 @@ namespace gcn { - Button::Button() - : mHasMouse(false), - mKeyPressed(false), - mMousePressed(false), - mAlignment(Graphics::CENTER), - mSpacing(4) - { - setFocusable(true); - adjustSize(); - setBorderSize(1); + Button::Button() + : mHasMouse(false), + mKeyPressed(false), + mMousePressed(false), + mAlignment(Graphics::CENTER), + mSpacing(4) + { + setFocusable(true); + adjustSize(); + setBorderSize(1); - addMouseListener(this); - addKeyListener(this); - addFocusListener(this); - } + addMouseListener(this); + addKeyListener(this); + addFocusListener(this); + } - Button::Button(const std::string& caption) - : mCaption(caption), - mHasMouse(false), - mKeyPressed(false), - mMousePressed(false), - mAlignment(Graphics::CENTER), - mSpacing(4) - { - setFocusable(true); - adjustSize(); - setBorderSize(1); + Button::Button(const std::string& caption) + : mCaption(caption), + mHasMouse(false), + mKeyPressed(false), + mMousePressed(false), + mAlignment(Graphics::CENTER), + mSpacing(4) + { + setFocusable(true); + adjustSize(); + setBorderSize(1); - addMouseListener(this); - addKeyListener(this); - addFocusListener(this); - } + addMouseListener(this); + addKeyListener(this); + addFocusListener(this); + } - void Button::setCaption(const std::string& caption) - { - mCaption = caption; - } + void Button::setCaption(const std::string& caption) + { + mCaption = caption; + } - const std::string& Button::getCaption() const - { - return mCaption; - } + const std::string& Button::getCaption() const + { + return mCaption; + } - void Button::setAlignment(unsigned int alignment) - { - mAlignment = alignment; - } + void Button::setAlignment(unsigned int alignment) + { + mAlignment = alignment; + } - unsigned int Button::getAlignment() const - { - return mAlignment; - } + unsigned int Button::getAlignment() const + { + return mAlignment; + } - void Button::setSpacing(unsigned int spacing) - { - mSpacing = spacing; - } + void Button::setSpacing(unsigned int spacing) + { + mSpacing = spacing; + } - unsigned int Button::getSpacing() const - { - return mSpacing; - } + unsigned int Button::getSpacing() const + { + return mSpacing; + } - void Button::draw(Graphics* graphics) - { - auto faceColor = getBaseColor(); - Color highlightColor, shadowColor; - auto alpha = getBaseColor().a; + void Button::draw(Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; - if (isPressed()) - { - faceColor = faceColor - 0x303030; - faceColor.a = alpha; - highlightColor = faceColor - 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor + 0x303030; - shadowColor.a = alpha; - } - else - { - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - } + if (isPressed()) + { + faceColor = faceColor - 0x303030; + faceColor.a = alpha; + highlightColor = faceColor - 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor + 0x303030; + shadowColor.a = alpha; + } + else + { + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + } - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(1, 1, getDimension().width - 1, getHeight() - 1)); + graphics->setColor(faceColor); + graphics->fillRectangle(Rectangle(1, 1, getDimension().width-1, getHeight() - 1)); - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, getWidth() - 1, 0); - graphics->drawLine(0, 1, 0, getHeight() - 1); + graphics->setColor(highlightColor); + graphics->drawLine(0, 0, getWidth() - 1, 0); + graphics->drawLine(0, 1, 0, getHeight() - 1); - graphics->setColor(shadowColor); - graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1); - graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1); + graphics->setColor(shadowColor); + graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1); + graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1); - graphics->setColor(getForegroundColor()); + graphics->setColor(getForegroundColor()); - int textX; - auto textY = getHeight() / 2 - getFont()->getHeight() / 2; + int textX; + int textY = getHeight() / 2 - getFont()->getHeight() / 2; - switch (getAlignment()) - { - case Graphics::LEFT: - textX = mSpacing; - break; - case Graphics::CENTER: - textX = getWidth() / 2; - break; - case Graphics::RIGHT: - textX = getWidth() - mSpacing; - break; - default: - throw GCN_EXCEPTION("Unknown alignment."); - } + switch (getAlignment()) + { + case Graphics::LEFT: + textX = mSpacing; + break; + case Graphics::CENTER: + textX = getWidth() / 2; + break; + case Graphics::RIGHT: + textX = getWidth() - mSpacing; + break; + default: + throw GCN_EXCEPTION("Unknown alignment."); + } - graphics->setFont(getFont()); + graphics->setFont(getFont()); - if (isPressed()) - { - graphics->drawText(getCaption(), textX + 1, textY + 1, getAlignment()); - } - else - { - graphics->drawText(getCaption(), textX, textY, getAlignment()); + if (isPressed()) + { + graphics->drawText(getCaption(), textX + 1, textY + 1, getAlignment()); + } + else + { + graphics->drawText(getCaption(), textX, textY, getAlignment()); - if (isFocused()) - { - graphics->drawRectangle(Rectangle(2, 2, getWidth() - 4, - getHeight() - 4)); - } - } - } + if (isFocused()) + { + graphics->drawRectangle(Rectangle(2, 2, getWidth() - 4, + getHeight() - 4)); + } + } + } - void Button::drawBorder(Graphics* graphics) - { - auto faceColor = getBaseColor(); - auto alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + void Button::drawBorder(Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + int width = getWidth() + getBorderSize() * 2 - 1; + int height = getHeight() + getBorderSize() * 2 - 1; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - for (unsigned int i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i, i, width - i, i); - graphics->drawLine(i, i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i, i + 1, width - i, height - i); - graphics->drawLine(i, height - i, width - i - 1, height - i); - } - } + unsigned int i; + for (i = 0; i < getBorderSize(); ++i) + { + graphics->setColor(shadowColor); + graphics->drawLine(i,i, width - i, i); + graphics->drawLine(i,i + 1, i, height - i - 1); + graphics->setColor(highlightColor); + graphics->drawLine(width - i,i + 1, width - i, height - i); + graphics->drawLine(i,height - i, width - i - 1, height - i); + } + } - void Button::adjustSize() - { - setWidth(getFont()->getWidth(mCaption) + 2 * mSpacing); - setHeight(getFont()->getHeight() + 2 * mSpacing); - } + void Button::adjustSize() + { + setWidth(getFont()->getWidth(mCaption) + 2*mSpacing); + setHeight(getFont()->getHeight() + 2*mSpacing); + } - bool Button::isPressed() const - { - if (mMousePressed) - { - return mHasMouse; - } - return mKeyPressed; - } + bool Button::isPressed() const + { + if (mMousePressed) + { + return mHasMouse; + } + else + { + return mKeyPressed; + } + } - void Button::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mMousePressed = true; - mouseEvent.consume(); - } - } + void Button::mousePressed(MouseEvent& mouseEvent) + { + if (mouseEvent.getButton() == MouseEvent::LEFT) + { + mMousePressed = true; + mouseEvent.consume(); + } + } - void Button::mouseExited(MouseEvent& mouseEvent) - { - mHasMouse = false; - } + void Button::mouseExited(MouseEvent& mouseEvent) + { + mHasMouse = false; + } - void Button::mouseEntered(MouseEvent& mouseEvent) - { - mHasMouse = true; - } + void Button::mouseEntered(MouseEvent& mouseEvent) + { + mHasMouse = true; + } - void Button::mouseReleased(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT - && mMousePressed - && mHasMouse) - { - mMousePressed = false; - generateAction(); - mouseEvent.consume(); - } - else if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mMousePressed = false; - mouseEvent.consume(); - } - } + void Button::mouseReleased(MouseEvent& mouseEvent) + { + if (mouseEvent.getButton() == MouseEvent::LEFT + && mMousePressed + && mHasMouse) + { + mMousePressed = false; + generateAction(); + mouseEvent.consume(); + } + else if (mouseEvent.getButton() == MouseEvent::LEFT) + { + mMousePressed = false; + mouseEvent.consume(); + } + } - void Button::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } + void Button::mouseDragged(MouseEvent& mouseEvent) + { + mouseEvent.consume(); + } - void Button::keyPressed(KeyEvent& keyEvent) - { - auto key = keyEvent.getKey(); + void Button::keyPressed(KeyEvent& keyEvent) + { + Key key = keyEvent.getKey(); - if (key.getValue() == Key::ENTER - || key.getValue() == Key::SPACE) - { - mKeyPressed = true; - keyEvent.consume(); - } - } + if (key.getValue() == Key::ENTER + || key.getValue() == Key::SPACE) + { + mKeyPressed = true; + keyEvent.consume(); + } + } - void Button::keyReleased(KeyEvent& keyEvent) - { - auto key = keyEvent.getKey(); + void Button::keyReleased(KeyEvent& keyEvent) + { + Key key = keyEvent.getKey(); - if ((key.getValue() == Key::ENTER - || key.getValue() == Key::SPACE) - && mKeyPressed) - { - mKeyPressed = false; - generateAction(); - keyEvent.consume(); - } - } + if ((key.getValue() == Key::ENTER + || key.getValue() == Key::SPACE) + && mKeyPressed) + { + mKeyPressed = false; + generateAction(); + keyEvent.consume(); + } + } - void Button::focusLost(const Event& event) - { - mMousePressed = false; - mKeyPressed = false; - } + void Button::focusLost(const Event& event) + { + mMousePressed = false; + mKeyPressed = false; + } } diff --git a/guisan-dev/src/widgets/checkbox.cpp b/guisan-dev/src/widgets/checkbox.cpp index 071c7650..29ada9b2 100644 --- a/guisan-dev/src/widgets/checkbox.cpp +++ b/guisan-dev/src/widgets/checkbox.cpp @@ -67,157 +67,161 @@ namespace gcn { - CheckBox::CheckBox() - { - setSelected(false); - setFocusable(true); - addMouseListener(this); - addKeyListener(this); - } + CheckBox::CheckBox() + { + setSelected(false); - CheckBox::CheckBox(const std::string& caption, bool selected) - { - setCaption(caption); - setSelected(selected); + setFocusable(true); + addMouseListener(this); + addKeyListener(this); + } - setFocusable(true); - addMouseListener(this); - addKeyListener(this); + CheckBox::CheckBox(const std::string &caption, bool selected) + { + setCaption(caption); + setSelected(selected); - adjustSize(); - } + setFocusable(true); + addMouseListener(this); + addKeyListener(this); - void CheckBox::draw(Graphics* graphics) - { - drawBox(graphics); + adjustSize(); + } - graphics->setFont(getFont()); - graphics->setColor(getForegroundColor()); + void CheckBox::draw(Graphics* graphics) + { + drawBox(graphics); - int h = getHeight() + getHeight() / 2; + graphics->setFont(getFont()); + graphics->setColor(getForegroundColor()); - graphics->drawText(getCaption(), h - 2, 0); - } + int h = getHeight() + getHeight() / 2; - void CheckBox::drawBorder(Graphics* graphics) - { - auto faceColor = getBaseColor(); - auto alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + graphics->drawText(getCaption(), h - 2, 0); + } - for (unsigned int i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i, i, width - i, i); - graphics->drawLine(i, i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i, i + 1, width - i, height - i); - graphics->drawLine(i, height - i, width - i - 1, height - i); - } - } + void CheckBox::drawBorder(Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + int width = getWidth() + getBorderSize() * 2 - 1; + int height = getHeight() + getBorderSize() * 2 - 1; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - void CheckBox::drawBox(Graphics* graphics) - { - auto h = getHeight() - 2; + unsigned int i; + for (i = 0; i < getBorderSize(); ++i) + { + graphics->setColor(shadowColor); + graphics->drawLine(i,i, width - i, i); + graphics->drawLine(i,i + 1, i, height - i - 1); + graphics->setColor(highlightColor); + graphics->drawLine(width - i,i + 1, width - i, height - i); + graphics->drawLine(i,height - i, width - i - 1, height - i); + } + } - auto alpha = getBaseColor().a; - auto faceColor = getBaseColor(); - faceColor.a = alpha; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + void CheckBox::drawBox(Graphics *graphics) + { + int h = getHeight() - 2; - graphics->setColor(shadowColor); - graphics->drawLine(1, 1, h, 1); - graphics->drawLine(1, 1, 1, h); + int alpha = getBaseColor().a; + Color faceColor = getBaseColor(); + faceColor.a = alpha; + Color highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + Color shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - graphics->setColor(highlightColor); - graphics->drawLine(h, 1, h, h); - graphics->drawLine(1, h, h - 1, h); + graphics->setColor(shadowColor); + graphics->drawLine(1, 1, h, 1); + graphics->drawLine(1, 1, 1, h); - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(Rectangle(2, 2, h - 2, h - 2)); + graphics->setColor(highlightColor); + graphics->drawLine(h, 1, h, h); + graphics->drawLine(1, h, h - 1, h); - graphics->setColor(getForegroundColor()); + graphics->setColor(getBackgroundColor()); + graphics->fillRectangle(Rectangle(2, 2, h - 2, h - 2)); - if (isFocused()) - { - graphics->drawRectangle(Rectangle(0, 0, h + 2, h + 2)); - } + graphics->setColor(getForegroundColor()); - if (mSelected) - { - graphics->drawLine(3, 5, 3, h - 2); - graphics->drawLine(4, 5, 4, h - 2); + if (isFocused()) + { + graphics->drawRectangle(Rectangle(0, 0, h + 2, h + 2)); + } + + if (mSelected) + { + graphics->drawLine(3, 5, 3, h - 2); + graphics->drawLine(4, 5, 4, h - 2); - graphics->drawLine(5, h - 3, h - 2, 4); - graphics->drawLine(5, h - 4, h - 4, 5); - } - } + graphics->drawLine(5, h - 3, h - 2, 4); + graphics->drawLine(5, h - 4, h - 4, 5); + } + } - bool CheckBox::isSelected() const - { - return mSelected; - } + bool CheckBox::isSelected() const + { + return mSelected; + } - void CheckBox::setSelected(bool selected) - { - mSelected = selected; - } + void CheckBox::setSelected(bool selected) + { + mSelected = selected; + } - const std::string& CheckBox::getCaption() const - { - return mCaption; - } + const std::string &CheckBox::getCaption() const + { + return mCaption; + } - void CheckBox::setCaption(const std::string& caption) - { - mCaption = caption; - } + void CheckBox::setCaption(const std::string& caption) + { + mCaption = caption; + } - void CheckBox::keyPressed(KeyEvent& keyEvent) - { - auto key = keyEvent.getKey(); + void CheckBox::keyPressed(KeyEvent& keyEvent) + { + Key key = keyEvent.getKey(); - if (key.getValue() == Key::ENTER || - key.getValue() == Key::SPACE) - { - toggleSelected(); - keyEvent.consume(); - } - } + if (key.getValue() == Key::ENTER || + key.getValue() == Key::SPACE) + { + toggleSelected(); + keyEvent.consume(); + } + } - void CheckBox::mouseClicked(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - toggleSelected(); - } - } + void CheckBox::mouseClicked(MouseEvent& mouseEvent) + { + if (mouseEvent.getButton() == MouseEvent::LEFT) + { + toggleSelected(); + } + } - void CheckBox::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } + void CheckBox::mouseDragged(MouseEvent& mouseEvent) + { + mouseEvent.consume(); + } - void CheckBox::adjustSize() - { - auto height = getFont()->getHeight(); + void CheckBox::adjustSize() + { + int height = getFont()->getHeight(); - setHeight(height); - setWidth(getFont()->getWidth(mCaption) + height + height / 2); - } + setHeight(height); + setWidth(getFont()->getWidth(mCaption) + height + height / 2); + } - void CheckBox::toggleSelected() - { - mSelected = !mSelected; - generateAction(); - } + void CheckBox::toggleSelected() + { + mSelected = !mSelected; + generateAction(); + } } + diff --git a/guisan-dev/src/widgets/container.cpp b/guisan-dev/src/widgets/container.cpp index 47cb1218..5cc51a95 100644 --- a/guisan-dev/src/widgets/container.cpp +++ b/guisan-dev/src/widgets/container.cpp @@ -65,81 +65,85 @@ namespace gcn { - Container::Container() - { - mOpaque = true; - } - Container::~Container() - = default; + Container::Container() + { + mOpaque = true; + } - void Container::draw(Graphics* graphics) - { - if (isOpaque()) - { - graphics->setColor(getBaseColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - } + Container::~Container() + { - drawChildren(graphics); - } + } - void Container::drawBorder(Graphics* graphics) - { - auto faceColor = getBaseColor(); - auto alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + void Container::draw(Graphics* graphics) + { + if (isOpaque()) + { + graphics->setColor(getBaseColor()); + graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); + } - unsigned int i; - for (i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i, i, width - i, i); - graphics->drawLine(i, i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i, i + 1, width - i, height - i); - graphics->drawLine(i, height - i, width - i - 1, height - i); - } - } + drawChildren(graphics); + } - void Container::setOpaque(bool opaque) - { - mOpaque = opaque; - } + void Container::drawBorder(Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + int width = getWidth() + getBorderSize() * 2 - 1; + int height = getHeight() + getBorderSize() * 2 - 1; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - bool Container::isOpaque() const - { - return mOpaque; - } + unsigned int i; + for (i = 0; i < getBorderSize(); ++i) + { + graphics->setColor(shadowColor); + graphics->drawLine(i,i, width - i, i); + graphics->drawLine(i,i + 1, i, height - i - 1); + graphics->setColor(highlightColor); + graphics->drawLine(width - i,i + 1, width - i, height - i); + graphics->drawLine(i,height - i, width - i - 1, height - i); + } + } - void Container::add(Widget* widget) - { - BasicContainer::add(widget); - } + void Container::setOpaque(bool opaque) + { + mOpaque = opaque; + } - void Container::add(Widget* widget, int x, int y) - { - widget->setPosition(x, y); - BasicContainer::add(widget); - } + bool Container::isOpaque() const + { + return mOpaque; + } - void Container::remove(Widget* widget) - { - BasicContainer::remove(widget); - } + void Container::add(Widget* widget) + { + BasicContainer::add(widget); + } - void Container::clear() - { - BasicContainer::clear(); - } + void Container::add(Widget* widget, int x, int y) + { + widget->setPosition(x, y); + BasicContainer::add(widget); + } - Widget* Container::findWidgetById(const std::string& id) - { - return BasicContainer::findWidgetById(id); - } + void Container::remove(Widget* widget) + { + BasicContainer::remove(widget); + } + + void Container::clear() + { + BasicContainer::clear(); + } + + Widget* Container::findWidgetById(const std::string &id) + { + return BasicContainer::findWidgetById(id); + } } diff --git a/guisan-dev/src/widgets/dropdown.cpp b/guisan-dev/src/widgets/dropdown.cpp index 1d4e688e..ddd51d2b 100644 --- a/guisan-dev/src/widgets/dropdown.cpp +++ b/guisan-dev/src/widgets/dropdown.cpp @@ -67,574 +67,578 @@ namespace gcn { - DropDown::DropDown(ListModel* listModel, - ScrollArea* scrollArea, - ListBox* listBox) - { - setWidth(100); - setFocusable(true); - mDroppedDown = false; - mPushed = false; - mIsDragged = false; - - setInternalFocusHandler(&mInternalFocusHandler); - - mInternalScrollArea = (scrollArea == nullptr); - mInternalListBox = (listBox == nullptr); - - if (mInternalScrollArea) - { - mScrollArea = new ScrollArea(); - } - else - { - mScrollArea = scrollArea; - } - - if (mInternalListBox) - { - mListBox = new ListBox(); - } - else - { - mListBox = listBox; - } - - mScrollArea->setContent(mListBox); - add(mScrollArea); - - mListBox->addActionListener(this); - mListBox->addSelectionListener(this); - - setListModel(listModel); - - if (mListBox->getSelected() < 0) - { - mListBox->setSelected(0); - } - - addMouseListener(this); - addKeyListener(this); - addFocusListener(this); - - adjustHeight(); - setBorderSize(1); - } - - DropDown::~DropDown() - { - if (widgetExists(mListBox)) - mListBox->removeSelectionListener(this); - - if (mInternalScrollArea) - delete mScrollArea; - - if (mInternalListBox) - delete mListBox; - - setInternalFocusHandler(nullptr); - } - - void DropDown::draw(Graphics* graphics) - { - int h; - - if (mDroppedDown) - { - h = mFoldedUpHeight; - } - else - { - h = getHeight(); - } - - auto alpha = getBaseColor().a; - auto faceColor = getBaseColor(); - faceColor.a = alpha; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), h)); - - graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); - - if (isFocused()) - { - graphics->setColor(getSelectionColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth() - h, h)); - graphics->setColor(getForegroundColor()); - } - - if (mListBox->getListModel() && mListBox->getSelected() >= 0) - { - graphics->drawText(mListBox->getListModel()->getElementAt(mListBox->getSelected()), 1, 0); - } - - drawButton(graphics); - - if (mDroppedDown) - { - drawChildren(graphics); - - // Draw two lines separating the ListBox with se selected - // element view. - graphics->setColor(highlightColor); - graphics->drawLine(0, h, getWidth(), h); - graphics->setColor(shadowColor); - graphics->drawLine(0, h + 1, getWidth(), h + 1); - } - } - - void DropDown::drawBorder(Graphics* graphics) - { - auto faceColor = getBaseColor(); - auto alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - for (unsigned int i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i, i, width - i, i); - graphics->drawLine(i, i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i, i + 1, width - i, height - i); - graphics->drawLine(i, height - i, width - i - 1, height - i); - } - } - - void DropDown::drawButton(Graphics* graphics) - { - Color faceColor, highlightColor, shadowColor; - int offset; - auto alpha = getBaseColor().a; - - if (mPushed) - { - faceColor = getBaseColor() - 0x303030; - faceColor.a = alpha; - highlightColor = faceColor - 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor + 0x303030; - shadowColor.a = alpha; - offset = 1; - } - else - { - faceColor = getBaseColor(); - faceColor.a = alpha; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - offset = 0; - } - - int h; - if (mDroppedDown) - { - h = mFoldedUpHeight; - } - else - { - h = getHeight(); - } - auto x = getWidth() - h; - auto y = 0; - - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(x + 1, - y + 1, - h - 2, - h - 2)); - - graphics->setColor(highlightColor); - graphics->drawLine(x, - y, - x + h - 1, - y); - graphics->drawLine(x, - y + 1, - x, - y + h - 1); - - graphics->setColor(shadowColor); - graphics->drawLine(x + h - 1, - y + 1, - x + h - 1, - y + h - 1); - graphics->drawLine(x + 1, - y + h - 1, - x + h - 2, - y + h - 1); - graphics->setColor(getForegroundColor()); - - auto hh = h / 3; - auto hx = x + h / 2; - auto hy = y + (h * 2) / 3; - for (auto i = 0; i < hh; i++) - { - graphics->drawLine(hx - i + offset, - hy - i + offset, - hx + i + offset, - hy - i + offset); - } - } - - int DropDown::getSelected() const - { - return mListBox->getSelected(); - } - - void DropDown::setSelected(int selected) - { - if (selected >= 0) - { - mListBox->setSelected(selected); - } - } - - void DropDown::keyPressed(KeyEvent& keyEvent) - { - auto key = keyEvent.getKey(); - - if ((key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) - && !mDroppedDown) - { - dropDown(); - keyEvent.consume(); - } - else if (key.getValue() == Key::UP) - { - setSelected(getSelected() - 1); - keyEvent.consume(); - } - else if (key.getValue() == Key::DOWN) - { - setSelected(getSelected() + 1); - keyEvent.consume(); - } - } - - void DropDown::mousePressed(MouseEvent& mouseEvent) - { - // If we have a mouse press on the widget. - if (0 <= mouseEvent.getY() - && mouseEvent.getY() < getHeight() - && mouseEvent.getX() >= 0 - && mouseEvent.getX() < getWidth() - && mouseEvent.getButton() == MouseEvent::LEFT - && !mDroppedDown - && mouseEvent.getSource() == this) - { - mPushed = true; - dropDown(); - requestModalMouseInputFocus(); - } - // Fold up the listbox if the upper part is clicked after fold down - else if (0 <= mouseEvent.getY() - && mouseEvent.getY() < mFoldedUpHeight - && mouseEvent.getX() >= 0 - && mouseEvent.getX() < getWidth() - && mouseEvent.getButton() == MouseEvent::LEFT - && mDroppedDown - && mouseEvent.getSource() == this) - { - mPushed = false; - foldUp(); - releaseModalMouseInputFocus(); - } - // If we have a mouse press outside the widget - else if (0 > mouseEvent.getY() - || mouseEvent.getY() >= getHeight() - || mouseEvent.getX() < 0 - || mouseEvent.getX() >= getWidth()) - { - mPushed = false; - foldUp(); - } - } - - void DropDown::mouseReleased(MouseEvent& mouseEvent) - { - if (mIsDragged) - { - mPushed = false; - } - - // Released outside of widget. Can happen when we have modal input focus. - if (0 > mouseEvent.getY() - || mouseEvent.getY() >= getHeight() - || mouseEvent.getX() < 0 - || mouseEvent.getX() >= getWidth() - && mouseEvent.getButton() == MouseEvent::LEFT - && hasModalMouseInputFocus()) - { - releaseModalMouseInputFocus(); - - if (mIsDragged) - { - foldUp(); - } - } - else if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mPushed = false; - } - - mIsDragged = false; - } - - void DropDown::mouseDragged(MouseEvent& mouseEvent) - { - mIsDragged = true; - - mouseEvent.consume(); - } - - void DropDown::setListModel(ListModel* listModel) - { - mListBox->setListModel(listModel); - - if (mListBox->getSelected() < 0) - { - mListBox->setSelected(0); - } - - adjustHeight(); - } - - ListModel* DropDown::getListModel() - { - return mListBox->getListModel(); - } - - void DropDown::adjustHeight() - { - if (mScrollArea == nullptr) - throw GCN_EXCEPTION("Scroll Area has been deleted."); - - if (mListBox == nullptr) - throw GCN_EXCEPTION("List box has been deleted."); - - int listBoxHeight = mListBox->getHeight(); - int h2 = getFont()->getHeight(); - - setHeight(h2); - - // The addition/subtraction of 2 compensates for the seperation lines - // seperating the selected element view and the scroll area. - - if (mDroppedDown && getParent()) - { - int h = getParent()->getChildrenArea().height - getY(); - - if (listBoxHeight > h - h2 - 2) - { - mScrollArea->setHeight(h - h2 - 2); - setHeight(h); - } - else - { - setHeight(listBoxHeight + h2 + 2); - mScrollArea->setHeight(listBoxHeight); - } - } - - mScrollArea->setWidth(getWidth()); - // Resize the ListBox to exactly fit the ScrollArea. - mListBox->setWidth(mScrollArea->getChildrenArea().width); - mScrollArea->setPosition(0, 0); - } - - void DropDown::dropDown() - { - if (!mDroppedDown) - { - mDroppedDown = true; - mFoldedUpHeight = getHeight(); - adjustHeight(); - - if (getParent()) - { - getParent()->moveToTop(this); - } - } - - mListBox->requestFocus(); - } - - void DropDown::foldUp() - { - if (mDroppedDown) - { - mDroppedDown = false; - adjustHeight(); - mInternalFocusHandler.focusNone(); - } - } - - void DropDown::focusLost(const Event& event) - { - foldUp(); - mInternalFocusHandler.focusNone(); - } - - - void DropDown::death(const Event& event) - { - if (event.getSource() == mScrollArea) - { - mScrollArea = nullptr; - } - BasicContainer::death(event); - } - - void DropDown::action(const ActionEvent& actionEvent) - { - foldUp(); - releaseModalMouseInputFocus(); - generateAction(); - } - - Rectangle DropDown::getChildrenArea() - { - if (mDroppedDown) - { - return { - 0, - mFoldedUpHeight + 2, - getWidth(), - getHeight() - mFoldedUpHeight - }; - } - - return Rectangle(); - } - - void DropDown::setBaseColor(const Color& color) + DropDown::DropDown(ListModel *listModel, + ScrollArea *scrollArea, + ListBox *listBox) + { + setWidth(100); + setFocusable(true); + mDroppedDown = false; + mPushed = false; + mIsDragged = false; + + setInternalFocusHandler(&mInternalFocusHandler); + + mInternalScrollArea = (scrollArea == NULL); + mInternalListBox = (listBox == NULL); + + if (mInternalScrollArea) + { + mScrollArea = new ScrollArea(); + } + else + { + mScrollArea = scrollArea; + } + + if (mInternalListBox) + { + mListBox = new ListBox(); + } + else + { + mListBox = listBox; + } + + mScrollArea->setContent(mListBox); + add(mScrollArea); + + mListBox->addActionListener(this); + mListBox->addSelectionListener(this); + + setListModel(listModel); + + if (mListBox->getSelected() < 0) + { + mListBox->setSelected(0); + } + + addMouseListener(this); + addKeyListener(this); + addFocusListener(this); + + adjustHeight(); + setBorderSize(1); + } + + DropDown::~DropDown() + { + if (widgetExists(mListBox)) + mListBox->removeSelectionListener(this); + + if (mInternalScrollArea) + delete mScrollArea; + + if (mInternalListBox) + delete mListBox; + + setInternalFocusHandler(NULL); + } + + void DropDown::draw(Graphics* graphics) + { + int h; + + if (mDroppedDown) + { + h = mFoldedUpHeight; + } + else + { + h = getHeight(); + } + + int alpha = getBaseColor().a; + Color faceColor = getBaseColor(); + faceColor.a = alpha; + Color highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + Color shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + + graphics->setColor(getBackgroundColor()); + graphics->fillRectangle(Rectangle(0, 0, getWidth(), h)); + + graphics->setColor(getForegroundColor()); + graphics->setFont(getFont()); + + if (isFocused()) + { + graphics->setColor(getSelectionColor()); + graphics->fillRectangle(Rectangle(0, 0, getWidth() - h, h)); + graphics->setColor(getForegroundColor()); + } + + if (mListBox->getListModel() && mListBox->getSelected() >= 0) + { + graphics->drawText(mListBox->getListModel()->getElementAt(mListBox->getSelected()), 1, 0); + } + + drawButton(graphics); + + if (mDroppedDown) + { + drawChildren(graphics); + + // Draw two lines separating the ListBox with se selected + // element view. + graphics->setColor(highlightColor); + graphics->drawLine(0, h, getWidth(), h); + graphics->setColor(shadowColor); + graphics->drawLine(0, h + 1,getWidth(),h + 1); + } + } + + void DropDown::drawBorder(Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + int width = getWidth() + getBorderSize() * 2 - 1; + int height = getHeight() + getBorderSize() * 2 - 1; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + unsigned int i; + for (i = 0; i < getBorderSize(); ++i) + { + graphics->setColor(shadowColor); + graphics->drawLine(i,i, width - i, i); + graphics->drawLine(i,i + 1, i, height - i - 1); + graphics->setColor(highlightColor); + graphics->drawLine(width - i,i + 1, width - i, height - i); + graphics->drawLine(i,height - i, width - i - 1, height - i); + } + } + + void DropDown::drawButton(Graphics *graphics) + { + Color faceColor, highlightColor, shadowColor; + int offset; + int alpha = getBaseColor().a; + + if (mPushed) + { + faceColor = getBaseColor() - 0x303030; + faceColor.a = alpha; + highlightColor = faceColor - 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor + 0x303030; + shadowColor.a = alpha; + offset = 1; + } + else + { + faceColor = getBaseColor(); + faceColor.a = alpha; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + offset = 0; + } + + int h; + if (mDroppedDown) + { + h = mFoldedUpHeight; + } + else + { + h = getHeight(); + } + int x = getWidth() - h; + int y = 0; + + graphics->setColor(faceColor); + graphics->fillRectangle(Rectangle(x + 1, + y + 1, + h - 2, + h - 2)); + + graphics->setColor(highlightColor); + graphics->drawLine(x, + y, + x + h - 1, + y); + graphics->drawLine(x, + y + 1, + x, + y + h - 1); + + graphics->setColor(shadowColor); + graphics->drawLine(x + h - 1, + y + 1, + x + h - 1, + y + h - 1); + graphics->drawLine(x + 1, + y + h - 1, + x + h - 2, + y + h - 1); + graphics->setColor(getForegroundColor()); + + int i; + int hh = h / 3; + int hx = x + h / 2; + int hy = y + (h * 2) / 3; + for (i = 0; i < hh; i++) + { + graphics->drawLine(hx - i + offset, + hy - i + offset, + hx + i + offset, + hy - i + offset); + } + } + + int DropDown::getSelected() const + { + return mListBox->getSelected(); + } + + void DropDown::setSelected(int selected) + { + if (selected >= 0) + { + mListBox->setSelected(selected); + } + } + + void DropDown::keyPressed(KeyEvent& keyEvent) + { + Key key = keyEvent.getKey(); + + if ((key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) + && !mDroppedDown) + { + dropDown(); + keyEvent.consume(); + } + else if (key.getValue() == Key::UP) + { + setSelected(getSelected() - 1); + keyEvent.consume(); + } + else if (key.getValue() == Key::DOWN) + { + setSelected(getSelected() + 1); + keyEvent.consume(); + } + } + + void DropDown::mousePressed(MouseEvent& mouseEvent) + { + // If we have a mouse press on the widget. + if (0 <= mouseEvent.getY() + && mouseEvent.getY() < getHeight() + && mouseEvent.getX() >= 0 + && mouseEvent.getX() < getWidth() + && mouseEvent.getButton() == MouseEvent::LEFT + && !mDroppedDown + && mouseEvent.getSource() == this) + { + mPushed = true; + dropDown(); + requestModalMouseInputFocus(); + } + // Fold up the listbox if the upper part is clicked after fold down + else if (0 <= mouseEvent.getY() + && mouseEvent.getY() < mFoldedUpHeight + && mouseEvent.getX() >= 0 + && mouseEvent.getX() < getWidth() + && mouseEvent.getButton() == MouseEvent::LEFT + && mDroppedDown + && mouseEvent.getSource() == this) + { + mPushed = false; + foldUp(); + releaseModalMouseInputFocus(); + } + // If we have a mouse press outside the widget + else if (0 > mouseEvent.getY() + || mouseEvent.getY() >= getHeight() + || mouseEvent.getX() < 0 + || mouseEvent.getX() >= getWidth()) + { + mPushed = false; + foldUp(); + } + } + + void DropDown::mouseReleased(MouseEvent& mouseEvent) + { + if (mIsDragged) + { + mPushed = false; + } + + // Released outside of widget. Can happen when we have modal input focus. + if (0 > mouseEvent.getY() + || mouseEvent.getY() >= getHeight() + || mouseEvent.getX() < 0 + || mouseEvent.getX() >= getWidth() + && mouseEvent.getButton() == MouseEvent::LEFT + && hasModalMouseInputFocus()) + { + releaseModalMouseInputFocus(); + + if (mIsDragged) + { + foldUp(); + } + } + else if (mouseEvent.getButton() == MouseEvent::LEFT) + { + mPushed = false; + } + + mIsDragged = false; + } + + void DropDown::mouseDragged(MouseEvent& mouseEvent) + { + mIsDragged = true; + + mouseEvent.consume(); + } + + void DropDown::setListModel(ListModel *listModel) + { + mListBox->setListModel(listModel); + + if (mListBox->getSelected() < 0) + { + mListBox->setSelected(0); + } + + adjustHeight(); + } + + ListModel *DropDown::getListModel() + { + return mListBox->getListModel(); + } + + void DropDown::adjustHeight() + { + if (mScrollArea == NULL) + throw GCN_EXCEPTION("Scroll Area has been deleted."); + + if (mListBox == NULL) + throw GCN_EXCEPTION("List box has been deleted."); + + int listBoxHeight = mListBox->getHeight(); + int h2 = getFont()->getHeight(); + + setHeight(h2); + + // The addition/subtraction of 2 compensates for the seperation lines + // seperating the selected element view and the scroll area. + + if (mDroppedDown && getParent()) + { + int h = getParent()->getChildrenArea().height - getY(); + + if (listBoxHeight > h - h2 - 2) + { + mScrollArea->setHeight(h - h2 - 2); + setHeight(h); + } + else + { + setHeight(listBoxHeight + h2 + 2); + mScrollArea->setHeight(listBoxHeight); + } + } + + mScrollArea->setWidth(getWidth()); + // Resize the ListBox to exactly fit the ScrollArea. + mListBox->setWidth(mScrollArea->getChildrenArea().width); + mScrollArea->setPosition(0, 0); + } + + void DropDown::dropDown() + { + if (!mDroppedDown) + { + mDroppedDown = true; + mFoldedUpHeight = getHeight(); + adjustHeight(); + + if (getParent()) + { + getParent()->moveToTop(this); + } + } + + mListBox->requestFocus(); + } + + void DropDown::foldUp() + { + if (mDroppedDown) + { + mDroppedDown = false; + adjustHeight(); + mInternalFocusHandler.focusNone(); + } + } + + void DropDown::focusLost(const Event& event) + { + foldUp(); + mInternalFocusHandler.focusNone(); + } + + + void DropDown::death(const Event& event) + { + if (event.getSource() == mScrollArea) + { + mScrollArea = NULL; + } + BasicContainer::death(event); + } + + void DropDown::action(const ActionEvent& actionEvent) + { + foldUp(); + releaseModalMouseInputFocus(); + generateAction(); + } + + Rectangle DropDown::getChildrenArea() + { + if (mDroppedDown) + { + return Rectangle(0, + mFoldedUpHeight + 2, + getWidth(), + getHeight() - mFoldedUpHeight); + } + + return Rectangle(); + } + + void DropDown::setBaseColor(const Color& color) + { + if (mInternalScrollArea) + { + mScrollArea->setBaseColor(color); + } + + if (mInternalListBox) + { + mListBox->setBaseColor(color); + } + + Widget::setBaseColor(color); + } + + void DropDown::setBackgroundColor(const Color& color) + { + if (mInternalScrollArea) + { + mScrollArea->setBackgroundColor(color); + } + + if (mInternalListBox) + { + mListBox->setBackgroundColor(color); + } + + Widget::setBackgroundColor(color); + } + + void DropDown::setForegroundColor(const Color& color) + { + if (mInternalScrollArea) + { + mScrollArea->setForegroundColor(color); + } + + if (mInternalListBox) + { + mListBox->setForegroundColor(color); + } + + Widget::setForegroundColor(color); + } + + void DropDown::setFont(Font *font) { if (mInternalScrollArea) - { - mScrollArea->setBaseColor(color); - } + { + mScrollArea->setFont(font); + } - if (mInternalListBox) - { - mListBox->setBaseColor(color); - } + if (mInternalListBox) + { + mListBox->setFont(font); + } - Widget::setBaseColor(color); - } - - void DropDown::setBackgroundColor(const Color& color) - { - if (mInternalScrollArea) - { - mScrollArea->setBackgroundColor(color); - } - - if (mInternalListBox) - { - mListBox->setBackgroundColor(color); - } - - Widget::setBackgroundColor(color); - } - - void DropDown::setForegroundColor(const Color& color) - { - if (mInternalScrollArea) - { - mScrollArea->setForegroundColor(color); - } - - if (mInternalListBox) - { - mListBox->setForegroundColor(color); - } - - Widget::setForegroundColor(color); - } - - void DropDown::setFont(Font* font) - { - if (mInternalScrollArea) - { - mScrollArea->setFont(font); - } - - if (mInternalListBox) - { - mListBox->setFont(font); - } - - Widget::setFont(font); + Widget::setFont(font); } void DropDown::mouseWheelMovedUp(MouseEvent& mouseEvent) { - if (isFocused() && mouseEvent.getSource() == this) - { - mouseEvent.consume(); + if (isFocused() && mouseEvent.getSource() == this) + { + mouseEvent.consume(); - if (mListBox->getSelected() > 0) - { - mListBox->setSelected(mListBox->getSelected() - 1); - } - } - } + if (mListBox->getSelected() > 0) + { + mListBox->setSelected(mListBox->getSelected() - 1); + } + } + } - void DropDown::mouseWheelMovedDown(MouseEvent& mouseEvent) - { - if (isFocused() && mouseEvent.getSource() == this) - { - mouseEvent.consume(); + void DropDown::mouseWheelMovedDown(MouseEvent& mouseEvent) + { + if (isFocused() && mouseEvent.getSource() == this) + { + mouseEvent.consume(); - mListBox->setSelected(mListBox->getSelected() + 1); - } - } + mListBox->setSelected(mListBox->getSelected() + 1); + } + } - void DropDown::setSelectionColor(const Color& color) - { - Widget::setSelectionColor(color); + void DropDown::setSelectionColor(const Color& color) + { + Widget::setSelectionColor(color); + + if (mInternalListBox) + { + mListBox->setSelectionColor(color); + } + } - if (mInternalListBox) - { - mListBox->setSelectionColor(color); - } - } + void DropDown::valueChanged(const SelectionEvent& event) + { + distributeValueChangedEvent(); + } - void DropDown::valueChanged(const SelectionEvent& event) - { - distributeValueChangedEvent(); - } + void DropDown::addSelectionListener(SelectionListener* selectionListener) + { + mSelectionListeners.push_back(selectionListener); + } + + void DropDown::removeSelectionListener(SelectionListener* selectionListener) + { + mSelectionListeners.remove(selectionListener); + } - void DropDown::addSelectionListener(SelectionListener* selectionListener) - { - mSelectionListeners.push_back(selectionListener); - } + void DropDown::distributeValueChangedEvent() + { + SelectionListenerIterator iter; - void DropDown::removeSelectionListener(SelectionListener* selectionListener) - { - mSelectionListeners.remove(selectionListener); - } - - void DropDown::distributeValueChangedEvent() - { - for (auto& mSelectionListener : mSelectionListeners) - { - SelectionEvent event(this); - mSelectionListener->valueChanged(event); - } - } + for (iter = mSelectionListeners.begin(); iter != mSelectionListeners.end(); ++iter) + { + SelectionEvent event(this); + (*iter)->valueChanged(event); + } + } } + diff --git a/guisan-dev/src/widgets/icon.cpp b/guisan-dev/src/widgets/icon.cpp index 44cb770d..30919836 100644 --- a/guisan-dev/src/widgets/icon.cpp +++ b/guisan-dev/src/widgets/icon.cpp @@ -66,54 +66,56 @@ namespace gcn { - Icon::Icon(const std::string& filename) - { - mImage = Image::load(filename); - mInternalImage = true; - setHeight(mImage->getHeight()); - setWidth(mImage->getWidth()); - } + Icon::Icon(const std::string& filename) + { + mImage = Image::load(filename); + mInternalImage = true; + setHeight(mImage->getHeight()); + setWidth(mImage->getWidth()); + } - Icon::Icon(Image* image) - { - mImage = image; - mInternalImage = false; - setHeight(mImage->getHeight()); - setWidth(mImage->getWidth()); - } + Icon::Icon(Image* image) + { + mImage = image; + mInternalImage = false; + setHeight(mImage->getHeight()); + setWidth(mImage->getWidth()); + } - Icon::~Icon() - { - if (mInternalImage) - { - delete mImage; - } - } + Icon::~Icon() + { + if (mInternalImage) + { + delete mImage; + } + } - void Icon::draw(Graphics* graphics) - { - graphics->drawImage(mImage, 0, 0); - } + void Icon::draw(Graphics* graphics) + { + graphics->drawImage(mImage, 0, 0); + } - void Icon::drawBorder(Graphics* graphics) - { - auto faceColor = getBaseColor(); - auto alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + void Icon::drawBorder(Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + int width = getWidth() + getBorderSize() * 2 - 1; + int height = getHeight() + getBorderSize() * 2 - 1; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - for (unsigned int i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i, i, width - i, i); - graphics->drawLine(i, i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i, i + 1, width - i, height - i); - graphics->drawLine(i, height - i, width - i - 1, height - i); - } - } + unsigned int i; + for (i = 0; i < getBorderSize(); ++i) + { + graphics->setColor(shadowColor); + graphics->drawLine(i,i, width - i, i); + graphics->drawLine(i,i + 1, i, height - i - 1); + graphics->setColor(highlightColor); + graphics->drawLine(width - i,i + 1, width - i, height - i); + graphics->drawLine(i,height - i, width - i - 1, height - i); + } + } } diff --git a/guisan-dev/src/widgets/imagebutton.cpp b/guisan-dev/src/widgets/imagebutton.cpp index 017d3bb1..1cf760e7 100644 --- a/guisan-dev/src/widgets/imagebutton.cpp +++ b/guisan-dev/src/widgets/imagebutton.cpp @@ -6,11 +6,11 @@ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * - * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson + * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson * * Js_./ * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// + * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// * _Qhm`] _f "'c 1!5m * Visit: http://guichan.darkbits.org )Qk

getWidth() + mImage->getWidth() / 2); - setHeight(mImage->getHeight() + mImage->getHeight() / 2); - } + ImageButton::ImageButton(const std::string& filename) + { + mImage = Image::load(filename); + mInternalImage = true; + setWidth(mImage->getWidth() + mImage->getWidth() / 2); + setHeight(mImage->getHeight() + mImage->getHeight() / 2); + } - ImageButton::ImageButton(Image* image) - { - mImage = image; - mInternalImage = false; - setWidth(mImage->getWidth() + mImage->getWidth() / 2); - setHeight(mImage->getHeight() + mImage->getHeight() / 2); - } + ImageButton::ImageButton(Image* image) + { + mImage = image; + mInternalImage = false; + setWidth(mImage->getWidth() + mImage->getWidth() / 2); + setHeight(mImage->getHeight() + mImage->getHeight() / 2); + } - ImageButton::~ImageButton() - { - if (mInternalImage) - delete mImage; - } + ImageButton::~ImageButton() + { + if (mInternalImage) + delete mImage; + } - void ImageButton::adjustSize() - { - setWidth(mImage->getWidth()); - setHeight(mImage->getHeight()); - } + void ImageButton::adjustSize() + { + setWidth(mImage->getWidth()); + setHeight(mImage->getHeight()); + } - void ImageButton::setImage(Image* image) - { - if (mInternalImage) - delete mImage; - mImage = image; - mInternalImage = false; - } + void ImageButton::setImage(Image* image) + { + if (mInternalImage) + delete mImage; + mImage = image; + mInternalImage = false; + } - Image* ImageButton::getImage() - { - return mImage; - } + Image* ImageButton::getImage() + { + return mImage; + } - void ImageButton::draw(Graphics* graphics) - { - auto faceColor = getBaseColor(); - Color highlightColor, shadowColor; - auto alpha = getBaseColor().a; + void ImageButton::draw(Graphics* graphics) + { + gcn::Color faceColor = getBaseColor(); + gcn::Color highlightColor, shadowColor; + int alpha = getBaseColor().a; - if (isPressed()) - { - faceColor = faceColor - 0x303030; - faceColor.a = alpha; - highlightColor = faceColor - 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor + 0x303030; - shadowColor.a = alpha; - } - else - { - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - } + if (isPressed()) + { + faceColor = faceColor - 0x303030; + faceColor.a = alpha; + highlightColor = faceColor - 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor + 0x303030; + shadowColor.a = alpha; + } + else + { + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + } - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(1, 1, getDimension().width - 1, getHeight() - 1)); + graphics->setColor(faceColor); + graphics->fillRectangle(Rectangle(1, 1, getDimension().width-1, getHeight() - 1)); - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, getWidth() - 1, 0); - graphics->drawLine(0, 1, 0, getHeight() - 1); + graphics->setColor(highlightColor); + graphics->drawLine(0, 0, getWidth() - 1, 0); + graphics->drawLine(0, 1, 0, getHeight() - 1); - graphics->setColor(shadowColor); - graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1); - graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1); + graphics->setColor(shadowColor); + graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1); + graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1); - graphics->setColor(getForegroundColor()); + graphics->setColor(getForegroundColor()); - auto textX = getWidth() / 2 - mImage->getWidth() / 2; - auto textY = getHeight() / 2 - mImage->getHeight() / 2; + int textX = getWidth() / 2 - mImage->getWidth() / 2; + int textY = getHeight() / 2 - mImage->getHeight() / 2; - if (isPressed()) - { - graphics->drawImage(mImage, textX + 1, textY + 1); - } - else - { - graphics->drawImage(mImage, textX, textY); - - if (isFocused()) - { - graphics->drawRectangle(Rectangle(2, - 2, - getWidth() - 4, - getHeight() - 4)); - } - } - } + if (isPressed()) + { + graphics->drawImage(mImage, textX + 1, textY + 1); + } + else + { + graphics->drawImage(mImage, textX, textY); + + if (isFocused()) + { + graphics->drawRectangle(Rectangle(2, + 2, + getWidth() - 4, + getHeight() - 4)); + } + } + } } diff --git a/guisan-dev/src/widgets/imagetextbutton.cpp b/guisan-dev/src/widgets/imagetextbutton.cpp new file mode 100644 index 00000000..d2e5a2f2 --- /dev/null +++ b/guisan-dev/src/widgets/imagetextbutton.cpp @@ -0,0 +1,229 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson + * + * Js_./ + * Per Larsson a.k.a finalman _RqZ{a<^_aa + * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// + * _Qhm`] _f "'c 1!5m + * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' + * binary forms, with or without )4d[#7r, . ' )d`)[ + * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' + * that the following conditions are met: j<. a J@\ + * this list of conditions and the j(]1ugetWidth() + mImage->getWidth() / 2); + setHeight(mImage->getHeight() + mImage->getHeight() / 2); + mAlignment = ImageTextButton::BOTTOM; + } + + ImageTextButton::ImageTextButton(Image* image, std::string& caption) : ImageButton(image) + { + setCaption(caption); + setWidth(mImage->getWidth() + mImage->getWidth() / 2); + setHeight(mImage->getHeight() + mImage->getHeight() / 2); + mAlignment = ImageTextButton::BOTTOM; + } + + ImageTextButton::~ImageTextButton() + { + if (mInternalImage) + delete mImage; + } + + void ImageTextButton::adjustSize() + { + switch(getAlignment()) + { + case LEFT: //fallthrough + case RIGHT: + setWidth(mImage->getWidth() + getFont()->getWidth(mCaption) + 2*mSpacing); + setHeight(mImage->getHeight() + 2*mSpacing); + break; + case TOP: //fallthrough + case BOTTOM: + if(mImage->getWidth() > getFont()->getWidth(mCaption)) + { + setWidth(mImage->getWidth() + 2*mSpacing); + } + else + { + setWidth(getFont()->getWidth(mCaption) + 2*mSpacing); + } + setHeight(mImage->getHeight() + getFont()->getHeight() + 2*mSpacing); + break; + default: + throw GCN_EXCEPTION("Unknown alignment."); + } + } + + void ImageTextButton::setImage(Image* image) + { + if (mInternalImage) + delete mImage; + mImage = image; + mInternalImage = false; + } + + Image* ImageTextButton::getImage() + { + return mImage; + } + + void ImageTextButton::draw(Graphics* graphics) + { + gcn::Color faceColor = getBaseColor(); + gcn::Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + + if (isPressed()) + { + faceColor = faceColor - 0x303030; + faceColor.a = alpha; + highlightColor = faceColor - 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor + 0x303030; + shadowColor.a = alpha; + } + else + { + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + } + + graphics->setColor(faceColor); + graphics->fillRectangle(Rectangle(1, 1, getDimension().width-1, getHeight() - 1)); + + graphics->setColor(highlightColor); + graphics->drawLine(0, 0, getWidth() - 1, 0); + graphics->drawLine(0, 1, 0, getHeight() - 1); + + graphics->setColor(shadowColor); + graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1); + graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1); + + graphics->setColor(getForegroundColor()); + + int imageX, imageY; + int textX, textY; + + switch(getAlignment()) + { + case LEFT: + imageX = mSpacing + getFont()->getWidth(mCaption); + textX = mSpacing; + imageY = mSpacing; + textY = getHeight() / 2 - getFont()->getHeight() / 2; + break; + case RIGHT: + imageX = mSpacing; + textX = mSpacing + mImage->getWidth(); + imageY = mSpacing; + textY = getHeight() / 2 - getFont()->getHeight() / 2; + break; + case TOP: + imageY = mSpacing + getFont()->getHeight(); + textY = mSpacing; + imageX = getWidth() / 2 - mImage->getWidth() / 2; + textX = getWidth() / 2 - getFont()->getWidth(mCaption) / 2; + break; + case BOTTOM: + imageY = mSpacing; + textY = mSpacing + mImage->getHeight(); + imageX = getWidth() / 2 - mImage->getWidth() / 2; + textX = getWidth() / 2 - getFont()->getWidth(mCaption) / 2; + break; + default: + throw GCN_EXCEPTION("Unknown alignment."); + } + + if (isPressed()) + { + graphics->drawImage(mImage, imageX + 1, imageY + 1); + graphics->drawText(mCaption, textX + 1, textY + 1, Graphics::LEFT); + } + else + { + graphics->drawImage(mImage, imageX, imageY); + graphics->drawText(mCaption, textX, textY, Graphics::LEFT); + + if (isFocused()) + { + graphics->drawRectangle(Rectangle(2, + 2, + getWidth() - 4, + getHeight() - 4)); + } + } + } + + void ImageTextButton::setAlignment(unsigned int alignment) + { + mAlignment = alignment; + } + + unsigned int ImageTextButton::getAlignment() const + { + return mAlignment; + } +} diff --git a/guisan-dev/src/widgets/inputbox.cpp b/guisan-dev/src/widgets/inputbox.cpp new file mode 100644 index 00000000..188b9e19 --- /dev/null +++ b/guisan-dev/src/widgets/inputbox.cpp @@ -0,0 +1,332 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson + * Copyright (c) 2017, 2018, 2019 Gwilherm Baudic + * Js_./ + * Per Larsson a.k.a finalman _RqZ{a<^_aa + * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// + * _Qhm`] _f "'c 1!5m + * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' + * binary forms, with or without )4d[#7r, . ' )d`)[ + * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' + * that the following conditions are met: j<. a J@\ + * this list of conditions and the j(]1usetAlignment(Graphics::LEFT); + mLabel->adjustSize(); + + mText = new TextField(); + + mButtonOK = new Button(ok); + mButtonOK->setAlignment(Graphics::CENTER); + mButtonOK->addMouseListener(this); + mButtonOK->adjustSize(); + + mButtonCancel = new Button(cancel); + mButtonCancel->setAlignment(Graphics::CENTER); + mButtonCancel->addMouseListener(this); + mButtonCancel->adjustSize(); + + // Look-and-feel: make both buttons the same width + if(mButtonCancel->getWidth() > mButtonOK->getWidth()) + { + mButtonOK->setWidth(mButtonCancel->getWidth()); + } + else + { + mButtonCancel->setWidth(mButtonOK->getWidth()); + } + + setHeight((int)getTitleBarHeight() + mLabel->getHeight() + mText->getHeight() + 6 * mPadding + mButtonOK->getHeight() + 2 * getBorderSize()); + setWidth(mLabel->getWidth() + 2 * mPadding + 2 * getBorderSize()); + if(2 * mButtonOK->getWidth() + 4 * mPadding + 2 * getBorderSize() > getWidth()) + { + setWidth(2 * mButtonOK->getWidth() + 4*mPadding + 2 * getBorderSize()); + } + mText->setWidth(getWidth() - 2 * getBorderSize() - 5 * mPadding); + + this->add(mLabel, (getWidth() - mLabel->getWidth())/2 - mPadding, mPadding); + this->add(mText, 2*mPadding, 2 * mPadding + mLabel->getHeight()); + int yButtons = getHeight() - (int)getTitleBarHeight() - getBorderSize() - 2*mPadding - mButtonOK->getHeight(); + this->add(mButtonOK, (getWidth() - 2 * mButtonOK->getWidth())/4, yButtons); + this->add(mButtonCancel, getWidth() - 2*getBorderSize() - mButtonOK->getWidth() - mPadding, yButtons); + + try + { + requestModalFocus(); + } + catch (Exception e) + { + // Not having modal focus is not critical + } + } + + InputBox::~InputBox() + { + releaseModalFocus(); + + delete mLabel; + delete mButtonOK; + delete mButtonCancel; + delete mText; + } + + void InputBox::draw(Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + //int width = getWidth() + getBorderSize() * 2 - 1; + //int height = getHeight() + getBorderSize() * 2 - 1; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + Rectangle d = getChildrenArea(); + + // Fill the background around the content + graphics->setColor(faceColor); + // Fill top + graphics->fillRectangle(Rectangle(0,0,getWidth(),d.y - 1)); + // Fill left + graphics->fillRectangle(Rectangle(0,d.y - 1, d.x - 1, getHeight() - d.y + 1)); + // Fill right + graphics->fillRectangle(Rectangle(d.x + d.width + 1, + d.y - 1, + getWidth() - d.x - d.width - 1, + getHeight() - d.y + 1)); + // Fill bottom + graphics->fillRectangle(Rectangle(d.x - 1, + d.y + d.height + 1, + d.width + 2, + getHeight() - d.height - d.y - 1)); + + if (isOpaque()) + { + graphics->fillRectangle(d); + } + + // Construct a rectangle one pixel bigger than the content + d.x -= 1; + d.y -= 1; + d.width += 2; + d.height += 2; + + // Draw a border around the content + graphics->setColor(shadowColor); + // Top line + graphics->drawLine(d.x, + d.y, + d.x + d.width - 2, + d.y); + + // Left line + graphics->drawLine(d.x, + d.y + 1, + d.x, + d.y + d.height - 1); + + graphics->setColor(highlightColor); + // Right line + graphics->drawLine(d.x + d.width - 1, + d.y, + d.x + d.width - 1, + d.y + d.height - 2); + // Bottom line + graphics->drawLine(d.x + 1, + d.y + d.height - 1, + d.x + d.width - 1, + d.y + d.height - 1); + + drawChildren(graphics); + + int textX; + int textY; + + textY = ((int)getTitleBarHeight() - getFont()->getHeight()) / 2; + + switch (getAlignment()) + { + case Graphics::LEFT: + textX = 4; + break; + case Graphics::CENTER: + textX = getWidth() / 2; + break; + case Graphics::RIGHT: + textX = getWidth() - 4; + break; + default: + throw GCN_EXCEPTION("Unknown alignment."); + } + + graphics->setColor(getForegroundColor()); + graphics->setFont(getFont()); + graphics->pushClipArea(Rectangle(0, 0, getWidth(), getTitleBarHeight() - 1)); + graphics->drawText(getCaption(), textX, textY, getAlignment()); + graphics->popClipArea(); + } + + void InputBox::drawBorder(Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + int width = getWidth() + getBorderSize() * 2 - 1; + int height = getHeight() + getBorderSize() * 2 - 1; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + unsigned int i; + for (i = 0; i < getBorderSize(); ++i) + { + graphics->setColor(highlightColor); + graphics->drawLine(i,i, width - i, i); + graphics->drawLine(i,i + 1, i, height - i - 1); + graphics->setColor(shadowColor); + graphics->drawLine(width - i,i + 1, width - i, height - i); + graphics->drawLine(i,height - i, width - i - 1, height - i); + } + } + + void InputBox::mousePressed(MouseEvent& mouseEvent) + { + if (mouseEvent.getSource() != this) + { + return; + } + + if (getParent() != NULL) + { + getParent()->moveToTop(this); + } + + mDragOffsetX = mouseEvent.getX(); + mDragOffsetY = mouseEvent.getY(); + + mIsMoving = mouseEvent.getY() <= (int)mTitleBarHeight; + } + + void InputBox::mouseReleased(MouseEvent& mouseEvent) + { + if (mouseEvent.getSource() != this) + { + if(mouseEvent.getSource() == mButtonOK) + { + mClickedButton = 0; + generateAction(); + } + if(mouseEvent.getSource() == mButtonCancel) + { + mClickedButton = 1; + setVisible(false); + generateAction(); + } + + } + else + { + mIsMoving = false; + } + } + + void InputBox::mouseDragged(MouseEvent& mouseEvent) + { + if (mouseEvent.isConsumed() || mouseEvent.getSource() != this) + { + return; + } + + if (isMovable() && mIsMoving) + { + setPosition(mouseEvent.getX() - mDragOffsetX + getX(), + mouseEvent.getY() - mDragOffsetY + getY()); + } + + mouseEvent.consume(); + } + + int InputBox::getClickedButton() const + { + return mClickedButton; + } + + std::string InputBox::getText() const + { + return mText->getText(); + } + + void InputBox::addToContainer(Container* container) + { + int x = container->getWidth() - getWidth(); + int y = container->getHeight() - getHeight(); + container->add(this, x/2, y/2); + } +} diff --git a/guisan-dev/src/widgets/label.cpp b/guisan-dev/src/widgets/label.cpp index cb07739a..cdac823f 100644 --- a/guisan-dev/src/widgets/label.cpp +++ b/guisan-dev/src/widgets/label.cpp @@ -66,91 +66,92 @@ namespace gcn { - Label::Label() - { - mAlignment = Graphics::LEFT; - } + Label::Label() + { + mAlignment = Graphics::LEFT; + } - Label::Label(const std::string& caption) - { - mCaption = caption; - mAlignment = Graphics::LEFT; + Label::Label(const std::string& caption) + { + mCaption = caption; + mAlignment = Graphics::LEFT; - setWidth(getFont()->getWidth(caption)); - setHeight(getFont()->getHeight()); - } + setWidth(getFont()->getWidth(caption)); + setHeight(getFont()->getHeight()); + } - const std::string& Label::getCaption() const - { - return mCaption; - } + const std::string &Label::getCaption() const + { + return mCaption; + } - void Label::setCaption(const std::string& caption) - { - mCaption = caption; - } + void Label::setCaption(const std::string& caption) + { + mCaption = caption; + } - void Label::setAlignment(unsigned int alignment) - { - mAlignment = alignment; - } + void Label::setAlignment(unsigned int alignment) + { + mAlignment = alignment; + } - unsigned int Label::getAlignment() const - { - return mAlignment; - } + unsigned int Label::getAlignment() const + { + return mAlignment; + } - void Label::draw(Graphics* graphics) - { - int textX; - auto textY = getHeight() / 2 - getFont()->getHeight() / 2; + void Label::draw(Graphics* graphics) + { + int textX; + int textY = getHeight() / 2 - getFont()->getHeight() / 2; - switch (getAlignment()) - { - case Graphics::LEFT: - textX = 0; - break; - case Graphics::CENTER: - textX = getWidth() / 2; - break; - case Graphics::RIGHT: - textX = getWidth(); - break; - default: - throw GCN_EXCEPTION("Unknown alignment."); - } + switch (getAlignment()) + { + case Graphics::LEFT: + textX = 0; + break; + case Graphics::CENTER: + textX = getWidth() / 2; + break; + case Graphics::RIGHT: + textX = getWidth(); + break; + default: + throw GCN_EXCEPTION("Unknown alignment."); + } - graphics->setFont(getFont()); - graphics->setColor(getForegroundColor()); - graphics->drawText(getCaption(), textX, textY, getAlignment()); - } + graphics->setFont(getFont()); + graphics->setColor(getForegroundColor()); + graphics->drawText(getCaption(), textX, textY, getAlignment()); + } - void Label::drawBorder(Graphics* graphics) - { - auto faceColor = getBaseColor(); - auto alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + void Label::drawBorder(Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + int width = getWidth() + getBorderSize() * 2 - 1; + int height = getHeight() + getBorderSize() * 2 - 1; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - unsigned int i; - for (i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i, i, width - i, i); - graphics->drawLine(i, i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i, i + 1, width - i, height - i); - graphics->drawLine(i, height - i, width - i - 1, height - i); - } - } + unsigned int i; + for (i = 0; i < getBorderSize(); ++i) + { + graphics->setColor(shadowColor); + graphics->drawLine(i,i, width - i, i); + graphics->drawLine(i,i + 1, i, height - i - 1); + graphics->setColor(highlightColor); + graphics->drawLine(width - i,i + 1, width - i, height - i); + graphics->drawLine(i,height - i, width - i - 1, height - i); + } + } - void Label::adjustSize() - { - setWidth(getFont()->getWidth(getCaption())); - setHeight(getFont()->getHeight()); - } + void Label::adjustSize() + { + setWidth(getFont()->getWidth(getCaption())); + setHeight(getFont()->getHeight()); + } } diff --git a/guisan-dev/src/widgets/listbox.cpp b/guisan-dev/src/widgets/listbox.cpp index 373aaaad..e1ef8249 100644 --- a/guisan-dev/src/widgets/listbox.cpp +++ b/guisan-dev/src/widgets/listbox.cpp @@ -70,279 +70,283 @@ namespace gcn { - ListBox::ListBox() - { - mSelected = -1; - mListModel = nullptr; - mWrappingEnabled = false; - setWidth(100); - setFocusable(true); + ListBox::ListBox() + { + mSelected = -1; + mListModel = NULL; + mWrappingEnabled = false; + setWidth(100); + setFocusable(true); - addMouseListener(this); - addKeyListener(this); - } + addMouseListener(this); + addKeyListener(this); + } - ListBox::ListBox(ListModel* listModel) - { - mSelected = -1; - mWrappingEnabled = false; - setWidth(100); - setListModel(listModel); - setFocusable(true); + ListBox::ListBox(ListModel *listModel) + { + mSelected = -1; + mWrappingEnabled = false; + setWidth(100); + setListModel(listModel); + setFocusable(true); - addMouseListener(this); - addKeyListener(this); - } + addMouseListener(this); + addKeyListener(this); + } - void ListBox::draw(Graphics* graphics) - { - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); + void ListBox::draw(Graphics* graphics) + { + graphics->setColor(getBackgroundColor()); + graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - if (mListModel == nullptr) - { - return; - } + if (mListModel == NULL) + { + return; + } - graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); + graphics->setColor(getForegroundColor()); + graphics->setFont(getFont()); - auto y = 0; + int i, fontHeight; + int y = 0; - auto fontHeight = getFont()->getHeight(); + fontHeight = getFont()->getHeight(); - /** - * @todo Check cliprects so we do not have to iterate over elements in the list model - */ - for (auto i = 0; i < mListModel->getNumberOfElements(); ++i) - { - if (i == mSelected) - { - graphics->setColor(getSelectionColor()); - graphics->fillRectangle(Rectangle(0, y, getWidth(), fontHeight)); - graphics->setColor(getForegroundColor()); - } + /** + * @todo Check cliprects so we do not have to iterate over elements in the list model + */ + for (i = 0; i < mListModel->getNumberOfElements(); ++i) + { + if (i == mSelected) + { + graphics->setColor(getSelectionColor()); + graphics->fillRectangle(Rectangle(0, y, getWidth(), fontHeight)); + graphics->setColor(getForegroundColor()); + } - graphics->drawText(mListModel->getElementAt(i), 1, y); + graphics->drawText(mListModel->getElementAt(i), 1, y); - y += fontHeight; - } - } + y += fontHeight; + } + } - void ListBox::drawBorder(Graphics* graphics) - { - auto faceColor = getBaseColor(); - auto alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + void ListBox::drawBorder(Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + int width = getWidth() + getBorderSize() * 2 - 1; + int height = getHeight() + getBorderSize() * 2 - 1; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - unsigned int i; - for (i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i, i, width - i, i); - graphics->drawLine(i, i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i, i + 1, width - i, height - i); - graphics->drawLine(i, height - i, width - i - 1, height - i); - } - } + unsigned int i; + for (i = 0; i < getBorderSize(); ++i) + { + graphics->setColor(shadowColor); + graphics->drawLine(i,i, width - i, i); + graphics->drawLine(i,i + 1, i, height - i - 1); + graphics->setColor(highlightColor); + graphics->drawLine(width - i,i + 1, width - i, height - i); + graphics->drawLine(i,height - i, width - i - 1, height - i); + } + } - void ListBox::logic() - { - adjustSize(); - } + void ListBox::logic() + { + adjustSize(); + } - int ListBox::getSelected() const - { - return mSelected; - } + int ListBox::getSelected() const + { + return mSelected; + } - void ListBox::setSelected(int selected) - { - if (mListModel == nullptr) - { - mSelected = -1; - } - else - { - if (selected < 0) - { - mSelected = -1; - } - else if (selected >= mListModel->getNumberOfElements()) - { - mSelected = mListModel->getNumberOfElements() - 1; - } - else - { - mSelected = selected; - } + void ListBox::setSelected(int selected) + { + if (mListModel == NULL) + { + mSelected = -1; + } + else + { + if (selected < 0) + { + mSelected = -1; + } + else if (selected >= mListModel->getNumberOfElements()) + { + mSelected = mListModel->getNumberOfElements() - 1; + } + else + { + mSelected = selected; + } - auto par = getParent(); - if (par == nullptr) - { - return; - } + Widget *par = getParent(); + if (par == NULL) + { + return; + } - Rectangle scroll; + Rectangle scroll; - if (mSelected < 0) - { - scroll.y = 0; - } - else - { - scroll.y = getFont()->getHeight() * mSelected; - } + if (mSelected < 0) + { + scroll.y = 0; + } + else + { + scroll.y = getFont()->getHeight() * mSelected; + } - scroll.height = getFont()->getHeight(); - par->showWidgetPart(this, scroll); - } + scroll.height = getFont()->getHeight(); + par->showWidgetPart(this, scroll); + } - distributeValueChangedEvent(); - } + distributeValueChangedEvent(); + } - void ListBox::keyPressed(KeyEvent& keyEvent) - { - auto key = keyEvent.getKey(); + void ListBox::keyPressed(KeyEvent& keyEvent) + { + Key key = keyEvent.getKey(); - if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) - { - generateAction(); - keyEvent.consume(); - } - else if (key.getValue() == Key::UP) - { - setSelected(mSelected - 1); + if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) + { + generateAction(); + keyEvent.consume(); + } + else if (key.getValue() == Key::UP) + { + setSelected(mSelected - 1); - if (mSelected == -1) - { - if (mWrappingEnabled) - { - setSelected(getListModel()->getNumberOfElements() - 1); - } - else - { - setSelected(0); - } - } + if (mSelected == -1) + { + if (mWrappingEnabled) + { + setSelected(getListModel()->getNumberOfElements() - 1); + } + else + { + setSelected(0); + } + } + + keyEvent.consume(); + } + else if (key.getValue() == Key::DOWN) + { + if (mWrappingEnabled + && getSelected() == getListModel()->getNumberOfElements() - 1) + { + setSelected(0); + } + else + { + setSelected(getSelected() + 1); + } + + keyEvent.consume(); + } + else if (key.getValue() == Key::HOME) + { + setSelected(0); + keyEvent.consume(); + } + else if (key.getValue() == Key::END) + { + setSelected(getListModel()->getNumberOfElements() - 1); + keyEvent.consume(); + } + } - keyEvent.consume(); - } - else if (key.getValue() == Key::DOWN) - { - if (mWrappingEnabled - && getSelected() == getListModel()->getNumberOfElements() - 1) - { - setSelected(0); - } - else - { - setSelected(getSelected() + 1); - } + void ListBox::mousePressed(MouseEvent& mouseEvent) + { + if (mouseEvent.getButton() == MouseEvent::LEFT) + { + setSelected(mouseEvent.getY() / getFont()->getHeight()); + generateAction(); + } + } - keyEvent.consume(); - } - else if (key.getValue() == Key::HOME) - { - setSelected(0); - keyEvent.consume(); - } - else if (key.getValue() == Key::END) - { - setSelected(getListModel()->getNumberOfElements() - 1); - keyEvent.consume(); - } - } + void ListBox::mouseWheelMovedUp(MouseEvent& mouseEvent) + { + if (isFocused()) + { + if (getSelected() > 0 ) + { + setSelected(getSelected() - 1); + } - void ListBox::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - setSelected(mouseEvent.getY() / getFont()->getHeight()); - generateAction(); - } - } + mouseEvent.consume(); + } + } - void ListBox::mouseWheelMovedUp(MouseEvent& mouseEvent) - { - if (isFocused()) - { - if (getSelected() > 0) - { - setSelected(getSelected() - 1); - } + void ListBox::mouseWheelMovedDown(MouseEvent& mouseEvent) + { + if (isFocused()) + { + setSelected(getSelected() + 1); - mouseEvent.consume(); - } - } + mouseEvent.consume(); + } + } - void ListBox::mouseWheelMovedDown(MouseEvent& mouseEvent) - { - if (isFocused()) - { - setSelected(getSelected() + 1); + void ListBox::mouseDragged(MouseEvent& mouseEvent) + { + mouseEvent.consume(); + } - mouseEvent.consume(); - } - } + void ListBox::setListModel(ListModel *listModel) + { + mSelected = -1; + mListModel = listModel; + adjustSize(); + } - void ListBox::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } + ListModel* ListBox::getListModel() + { + return mListModel; + } - void ListBox::setListModel(ListModel* listModel) - { - mSelected = -1; - mListModel = listModel; - adjustSize(); - } + void ListBox::adjustSize() + { + if (mListModel != NULL) + { + setHeight(getFont()->getHeight() * mListModel->getNumberOfElements()); + } + } - ListModel* ListBox::getListModel() - { - return mListModel; - } + bool ListBox::isWrappingEnabled() const + { + return mWrappingEnabled; + } - void ListBox::adjustSize() - { - if (mListModel != nullptr) - { - setHeight(getFont()->getHeight() * mListModel->getNumberOfElements()); - } - } + void ListBox::setWrappingEnabled(bool wrappingEnabled) + { + mWrappingEnabled = wrappingEnabled; + } + + void ListBox::addSelectionListener(SelectionListener* selectionListener) + { + mSelectionListeners.push_back(selectionListener); + } + + void ListBox::removeSelectionListener(SelectionListener* selectionListener) + { + mSelectionListeners.remove(selectionListener); + } - bool ListBox::isWrappingEnabled() const - { - return mWrappingEnabled; - } + void ListBox::distributeValueChangedEvent() + { + SelectionListenerIterator iter; - void ListBox::setWrappingEnabled(bool wrappingEnabled) - { - mWrappingEnabled = wrappingEnabled; - } - - void ListBox::addSelectionListener(SelectionListener* selectionListener) - { - mSelectionListeners.push_back(selectionListener); - } - - void ListBox::removeSelectionListener(SelectionListener* selectionListener) - { - mSelectionListeners.remove(selectionListener); - } - - void ListBox::distributeValueChangedEvent() - { - for (auto& mSelectionListener : mSelectionListeners) - { - SelectionEvent event(this); - mSelectionListener->valueChanged(event); - } - } + for (iter = mSelectionListeners.begin(); iter != mSelectionListeners.end(); ++iter) + { + SelectionEvent event(this); + (*iter)->valueChanged(event); + } + } } diff --git a/guisan-dev/src/widgets/messagebox.cpp b/guisan-dev/src/widgets/messagebox.cpp new file mode 100644 index 00000000..dfaf4bb1 --- /dev/null +++ b/guisan-dev/src/widgets/messagebox.cpp @@ -0,0 +1,485 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson + * Copyright (c) 2017 Gwilherm Baudic + * Js_./ + * Per Larsson a.k.a finalman _RqZ{a<^_aa + * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// + * _Qhm`] _f "'c 1!5m + * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' + * binary forms, with or without )4d[#7r, . ' )d`)[ + * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' + * that the following conditions are met: j<. a J@\ + * this list of conditions and the j(]1usetAlignment(Graphics::LEFT); + mLabel->adjustSize(); + + mNbButtons = 1; + mButtons = new Button*[1]; + mButtons[0] = new Button("OK"); + mButtons[0]->setAlignment(Graphics::CENTER); + mButtons[0]->addMouseListener(this); + + setHeight((int)getTitleBarHeight() + mLabel->getHeight() + 4*mPadding + mButtons[0]->getHeight()); + setWidth(mLabel->getWidth() + 4*mPadding); + if(mButtons[0]->getWidth() + 4*mPadding > getWidth()) + { + setWidth(mButtons[0]->getWidth() + 4*mPadding); + } + + this->add(mLabel, (getWidth() - mLabel->getWidth())/2 - mPadding, mPadding); + this->add(mButtons[0], (getWidth() - mButtons[0]->getWidth())/2, getHeight() - (int)getTitleBarHeight() - mPadding - mButtons[0]->getHeight()); + + try + { + requestModalFocus(); + } + catch (Exception e) + { + // Not having modal focus is not critical + } + } + + MessageBox::MessageBox(const std::string& caption, const std::string& message, + const std::string *buttons, int size) + :Window(caption),mMessage(message),mClickedButton(-1) + { + setCaption(caption); + addMouseListener(this); + setMovable(false); + + mLabel = new Label(message); + mLabel->setAlignment(Graphics::LEFT); + mLabel->adjustSize(); + setWidth(mLabel->getWidth() + 4*mPadding); + + //Create buttons and label + if(size > 0) + { + mNbButtons = size; + mButtons = new Button*[size]; + int maxBtnWidth = 0; + + for(int i = 0 ; i < size ; i++) + { + mButtons[i] = new Button(*(buttons+i)); + mButtons[i]->setAlignment(Graphics::CENTER); + mButtons[i]->addMouseListener(this); + maxBtnWidth = maxBtnWidth > mButtons[i]->getWidth() ? maxBtnWidth : mButtons[i]->getWidth(); + } + //Find the widest button, apply same width to all + for(int i = 0 ; i < size ; i++) + { + mButtons[i]->setWidth(maxBtnWidth); + } + + //Make sure everything fits into the window + int padding = mPadding; + if(mButtons[0]->getWidth()*size + 4*mPadding + mPadding*(size-1) > getWidth()) + { + setWidth(mButtons[0]->getWidth()*size + 4*mPadding + mPadding*(size-1)); + } + else + { + padding += (getWidth() - (mButtons[0]->getWidth()*size + 4*mPadding + mPadding*(size-1)))/2; + } + add(mLabel, (getWidth() - mLabel->getWidth())/2 - mPadding, mPadding); + + setHeight((int)getTitleBarHeight() + mLabel->getHeight() + 4*mPadding + mButtons[0]->getHeight()); + for(int i = 0 ; i < size ; i++) + { + add(mButtons[i], padding + (maxBtnWidth + mPadding)*i, getHeight() - (int)getTitleBarHeight() - mPadding - mButtons[0]->getHeight()); + } + } + + try + { + requestModalFocus(); + } + catch (Exception e) + { + // Not having modal focus is not critical + } + } + + MessageBox::~MessageBox() + { + releaseModalFocus(); + + delete mLabel; + for(int i = 0 ; i < mNbButtons ; i++) + { + delete mButtons[i]; + } + delete mButtons; + } + + void MessageBox::setPadding(unsigned int padding) + { + mPadding = padding; + } + + unsigned int MessageBox::getPadding() const + { + return mPadding; + } + + void MessageBox::setTitleBarHeight(unsigned int height) + { + mTitleBarHeight = height; + } + + unsigned int MessageBox::getTitleBarHeight() + { + return mTitleBarHeight; + } + + void MessageBox::setCaption(const std::string& caption) + { + mCaption = caption; + } + + const std::string& MessageBox::getCaption() const + { + return mCaption; + } + + void MessageBox::setAlignment(unsigned int alignment) + { + mAlignment = alignment; + } + + unsigned int MessageBox::getAlignment() const + { + return mAlignment; + } + + void MessageBox::setButtonAlignment(unsigned int alignment) + { + mButtonAlignment = alignment; + + int leftPadding = mPadding; + if(mNbButtons > 0) + { + switch (alignment) + { + case Graphics::LEFT: + // Nothing to do + break; + case Graphics::CENTER: + leftPadding += (getWidth() - (mButtons[0]->getWidth()*mNbButtons + 2*mPadding + mPadding*(mNbButtons-1)))/2; + break; + case Graphics::RIGHT: + leftPadding += (getWidth() - (mButtons[0]->getWidth()*mNbButtons + 2*mPadding + mPadding*(mNbButtons-1))); + break; + default: + throw GCN_EXCEPTION("Unknown alignment."); + } + for(int i = 0 ; i < mNbButtons ; i++) + { + mButtons[i]->setX(leftPadding + (mButtons[0]->getWidth() + mPadding)*i); + } + } + } + + unsigned int MessageBox::getButtonAlignment() const + { + return mButtonAlignment; + } + + void MessageBox::draw(Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + //int width = getWidth() + getBorderSize() * 2 - 1; + //int height = getHeight() + getBorderSize() * 2 - 1; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + Rectangle d = getChildrenArea(); + + // Fill the background around the content + graphics->setColor(faceColor); + // Fill top + graphics->fillRectangle(Rectangle(0,0,getWidth(),d.y - 1)); + // Fill left + graphics->fillRectangle(Rectangle(0,d.y - 1, d.x - 1, getHeight() - d.y + 1)); + // Fill right + graphics->fillRectangle(Rectangle(d.x + d.width + 1, + d.y - 1, + getWidth() - d.x - d.width - 1, + getHeight() - d.y + 1)); + // Fill bottom + graphics->fillRectangle(Rectangle(d.x - 1, + d.y + d.height + 1, + d.width + 2, + getHeight() - d.height - d.y - 1)); + + if (isOpaque()) + { + graphics->fillRectangle(d); + } + + // Construct a rectangle one pixel bigger than the content + d.x -= 1; + d.y -= 1; + d.width += 2; + d.height += 2; + + // Draw a border around the content + graphics->setColor(shadowColor); + // Top line + graphics->drawLine(d.x, + d.y, + d.x + d.width - 2, + d.y); + + // Left line + graphics->drawLine(d.x, + d.y + 1, + d.x, + d.y + d.height - 1); + + graphics->setColor(highlightColor); + // Right line + graphics->drawLine(d.x + d.width - 1, + d.y, + d.x + d.width - 1, + d.y + d.height - 2); + // Bottom line + graphics->drawLine(d.x + 1, + d.y + d.height - 1, + d.x + d.width - 1, + d.y + d.height - 1); + + drawChildren(graphics); + + int textX; + int textY; + + textY = ((int)getTitleBarHeight() - getFont()->getHeight()) / 2; + + switch (getAlignment()) + { + case Graphics::LEFT: + textX = 4; + break; + case Graphics::CENTER: + textX = getWidth() / 2; + break; + case Graphics::RIGHT: + textX = getWidth() - 4; + break; + default: + throw GCN_EXCEPTION("Unknown alignment."); + } + + graphics->setColor(getForegroundColor()); + graphics->setFont(getFont()); + graphics->pushClipArea(Rectangle(0, 0, getWidth(), getTitleBarHeight() - 1)); + graphics->drawText(getCaption(), textX, textY, getAlignment()); + graphics->popClipArea(); + } + + void MessageBox::drawBorder(Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + int width = getWidth() + getBorderSize() * 2 - 1; + int height = getHeight() + getBorderSize() * 2 - 1; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + unsigned int i; + for (i = 0; i < getBorderSize(); ++i) + { + graphics->setColor(highlightColor); + graphics->drawLine(i,i, width - i, i); + graphics->drawLine(i,i + 1, i, height - i - 1); + graphics->setColor(shadowColor); + graphics->drawLine(width - i,i + 1, width - i, height - i); + graphics->drawLine(i,height - i, width - i - 1, height - i); + } + } + + void MessageBox::mousePressed(MouseEvent& mouseEvent) + { + if (mouseEvent.getSource() != this) + { + return; + } + + if (getParent() != NULL) + { + getParent()->moveToTop(this); + } + + mDragOffsetX = mouseEvent.getX(); + mDragOffsetY = mouseEvent.getY(); + + mIsMoving = mouseEvent.getY() <= (int)mTitleBarHeight; + } + + void MessageBox::mouseReleased(MouseEvent& mouseEvent) + { + if (mouseEvent.getSource() != this) + { + for(int i = 0 ; i < mNbButtons ; i++) + { + if(mouseEvent.getSource() == mButtons[i]) + { + mClickedButton = i; + generateAction(); + break; + } + } + } + else + { + mIsMoving = false; + } + } + + void MessageBox::mouseDragged(MouseEvent& mouseEvent) + { + if (mouseEvent.isConsumed() || mouseEvent.getSource() != this) + { + return; + } + + if (isMovable() && mIsMoving) + { + setPosition(mouseEvent.getX() - mDragOffsetX + getX(), + mouseEvent.getY() - mDragOffsetY + getY()); + } + + mouseEvent.consume(); + } + + Rectangle MessageBox::getChildrenArea() + { + return Rectangle(getPadding(), + getTitleBarHeight(), + getWidth() - getPadding() * 2, + getHeight() - getPadding() - getTitleBarHeight()); + } + + bool MessageBox::isMovable() const + { + return mMovable; + } + + void MessageBox::setOpaque(bool opaque) + { + mOpaque = opaque; + } + + bool MessageBox::isOpaque() + { + return mOpaque; + } + + void MessageBox::resizeToContent() + { + WidgetListIterator it; + + int w = 0, h = 0; + for (it = mWidgets.begin(); it != mWidgets.end(); it++) + { + if ((*it)->getX() + (*it)->getWidth() > w) + { + w = (*it)->getX() + (*it)->getWidth(); + } + + if ((*it)->getY() + (*it)->getHeight() > h) + { + h = (*it)->getY() + (*it)->getHeight(); + } + } + + setSize(w + 2* getPadding(), h + getPadding() + getTitleBarHeight()); + } + + int MessageBox::getClickedButton() const + { + return mClickedButton; + } + + void MessageBox::addToContainer(Container* container) + { + int x = container->getWidth() - getWidth(); + int y = container->getHeight() - getHeight(); + container->add(this, x/2, y/2); + } +} diff --git a/guisan-dev/src/widgets/progressbar.cpp b/guisan-dev/src/widgets/progressbar.cpp index aa07734c..d78ca711 100644 --- a/guisan-dev/src/widgets/progressbar.cpp +++ b/guisan-dev/src/widgets/progressbar.cpp @@ -66,200 +66,200 @@ namespace gcn { - ProgressBar::ProgressBar() : Label() - { - mAlignment = Graphics::CENTER; - mStart = 0; - mValue = 0; - mEnd = 100; + ProgressBar::ProgressBar() : Label() + { + mAlignment = Graphics::CENTER; + mStart = 0; + mValue = 0; + mEnd = 100; + + setHeight(getFont()->getHeight()); + setBorderSize(1); + } + + ProgressBar::ProgressBar(const unsigned int start, + const unsigned int end, const unsigned int value) : Label() + { + mAlignment = Graphics::CENTER; + + if(start > end) + { + mStart = end; + mEnd = start; + } + else + { + mStart = start; + mEnd = end; + } + + if((value >= start && value <= end) || (start == 0 && end == 0)) + { + mValue = value; + } + else + { + mValue = start; + } + + setHeight(getFont()->getHeight()); + setBorderSize(1); + } - setHeight(getFont()->getHeight()); - setBorderSize(1); - } + ProgressBar::ProgressBar(const std::string& caption) : Label(caption) + { + mCaption = caption; + mAlignment = Graphics::CENTER; - ProgressBar::ProgressBar(const unsigned int start, - const unsigned int end, const unsigned int value) : Label() - { - mAlignment = Graphics::CENTER; + setHeight(getFont()->getHeight()); + setBorderSize(1); + } - if (start > end) - { - mStart = end; - mEnd = start; - } - else - { - mStart = start; - mEnd = end; - } + const std::string &ProgressBar::getCaption() const + { + return mCaption; + } - if ((value >= start && value <= end) || (start == 0 && end == 0)) - { - mValue = value; - } - else - { - mValue = start; - } + void ProgressBar::setCaption(const std::string& caption) + { + mCaption = caption; + } - setHeight(getFont()->getHeight()); - setBorderSize(1); - } + void ProgressBar::setAlignment(unsigned int alignment) + { + mAlignment = alignment; + } - ProgressBar::ProgressBar(const std::string& caption) : Label(caption) - { - mCaption = caption; - mAlignment = Graphics::CENTER; + unsigned int ProgressBar::getAlignment() const + { + return mAlignment; + } - setHeight(getFont()->getHeight()); - setBorderSize(1); - } + void ProgressBar::draw(Graphics* graphics) + { + graphics->setColor(getBackgroundColor()); + graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); + + int textX; + int textY = getHeight() / 2 - getFont()->getHeight() / 2; + + graphics->setColor(getSelectionColor()); + int progressWidth; + if(mStart == 0 && mEnd == 0) + { + // Infinite scrollbar + progressWidth = getWidth() / 5; + int barX = getWidth() * mValue / 100; + + if(barX + progressWidth > getWidth()) + { + graphics->fillRectangle(Rectangle(barX, 0, getWidth() - barX, getHeight())); + graphics->fillRectangle(Rectangle(0, 0, progressWidth - (getWidth() - barX), getHeight())); + } + else + { + graphics->fillRectangle(Rectangle(barX,0,progressWidth,getHeight())); + } + } + else + { + // Standard scrollbar + progressWidth = getWidth() * mValue / (mEnd - mStart); + graphics->fillRectangle(Rectangle(0,0,progressWidth,getHeight())); + } - const std::string& ProgressBar::getCaption() const - { - return mCaption; - } + switch (getAlignment()) + { + case Graphics::LEFT: + textX = 0; + break; + case Graphics::CENTER: + textX = getWidth() / 2; + break; + case Graphics::RIGHT: + textX = getWidth(); + break; + default: + throw GCN_EXCEPTION("Unknown alignment."); + } - void ProgressBar::setCaption(const std::string& caption) - { - mCaption = caption; - } + graphics->setFont(getFont()); + graphics->setColor(getForegroundColor()); + graphics->drawText(getCaption(), textX, textY, getAlignment()); + } - void ProgressBar::setAlignment(unsigned int alignment) - { - mAlignment = alignment; - } + void ProgressBar::drawBorder(Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + int width = getWidth() + getBorderSize() * 2 - 1; + int height = getHeight() + getBorderSize() * 2 - 1; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - unsigned int ProgressBar::getAlignment() const - { - return mAlignment; - } + unsigned int i; + for (i = 0; i < getBorderSize(); ++i) + { + graphics->setColor(shadowColor); + graphics->drawLine(i,i, width - i, i); + graphics->drawLine(i,i + 1, i, height - i - 1); + graphics->setColor(highlightColor); + graphics->drawLine(width - i,i + 1, width - i, height - i); + graphics->drawLine(i,height - i, width - i - 1, height - i); + } + } - void ProgressBar::draw(Graphics* graphics) - { - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - - int textX; - int textY = getHeight() / 2 - getFont()->getHeight() / 2; - - graphics->setColor(getSelectionColor()); - int progressWidth; - if (mStart == 0 && mEnd == 0) - { - // Infinite scrollbar - progressWidth = getWidth() / 5; - int barX = getWidth() * mValue / 100; - - if (barX + progressWidth > getWidth()) - { - graphics->fillRectangle(Rectangle(barX, 0, getWidth() - barX, getHeight())); - graphics->fillRectangle(Rectangle(0, 0, progressWidth - (getWidth() - barX), getHeight())); - } - else - { - graphics->fillRectangle(Rectangle(barX, 0, progressWidth, getHeight())); - } - } - else - { - // Standard scrollbar - progressWidth = getWidth() * mValue / (mEnd - mStart); - graphics->fillRectangle(Rectangle(0, 0, progressWidth, getHeight())); - } - - switch (getAlignment()) - { - case Graphics::LEFT: - textX = 0; - break; - case Graphics::CENTER: - textX = getWidth() / 2; - break; - case Graphics::RIGHT: - textX = getWidth(); - break; - default: - throw GCN_EXCEPTION("Unknown alignment."); - } - - graphics->setFont(getFont()); - graphics->setColor(getForegroundColor()); - graphics->drawText(getCaption(), textX, textY, getAlignment()); - } - - void ProgressBar::drawBorder(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i, i, width - i, i); - graphics->drawLine(i, i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i, i + 1, width - i, height - i); - graphics->drawLine(i, height - i, width - i - 1, height - i); - } - } - - void ProgressBar::adjustSize() - { - setHeight(getFont()->getHeight()); - } - - void ProgressBar::setStart(const unsigned int start) - { - if (start <= mEnd) - { - mStart = start; - } - } - - unsigned int ProgressBar::getStart() const - { - return mStart; - } - - void ProgressBar::setEnd(const unsigned int end) - { - if (end >= mStart) - { - mEnd = end; - } - } - - unsigned int ProgressBar::getEnd() const - { - return mEnd; - } - - void ProgressBar::setValue(const unsigned int value) - { - if (value >= mStart && value <= mEnd) - { - mValue = value; - } - else - { - if (mStart == 0 && mEnd == 0) - { - mValue = value % 100; - } - } - } - - unsigned int ProgressBar::getValue() const - { - return mValue; - } + void ProgressBar::adjustSize() + { + setHeight(getFont()->getHeight()); + } + + void ProgressBar::setStart(const unsigned int start) + { + if(start <= mEnd) + { + mStart = start; + } + } + + unsigned int ProgressBar::getStart() const + { + return mStart; + } + + void ProgressBar::setEnd(const unsigned int end) + { + if(end >= mStart) + { + mEnd = end; + } + } + + unsigned int ProgressBar::getEnd() const + { + return mEnd; + } + + void ProgressBar::setValue(const unsigned int value) + { + if(value >= mStart && value <= mEnd) + { + mValue = value; + } + else + { + if(mStart == 0 && mEnd == 0) + { + mValue = value % 100; + } + } + } + + unsigned int ProgressBar::getValue() const + { + return mValue; + } } diff --git a/guisan-dev/src/widgets/radiobutton.cpp b/guisan-dev/src/widgets/radiobutton.cpp index d8020067..9007abf4 100644 --- a/guisan-dev/src/widgets/radiobutton.cpp +++ b/guisan-dev/src/widgets/radiobutton.cpp @@ -67,264 +67,269 @@ namespace gcn { - RadioButton::GroupMap RadioButton::mGroupMap; + RadioButton::GroupMap RadioButton::mGroupMap; - RadioButton::RadioButton() - { - setSelected(false); + RadioButton::RadioButton() + { + setSelected(false); - setFocusable(true); - addMouseListener(this); - addKeyListener(this); - } + setFocusable(true); + addMouseListener(this); + addKeyListener(this); + } - RadioButton::RadioButton(const std::string& caption, - const std::string& group, - bool selected) - { - setCaption(caption); - setGroup(group); - setSelected(selected); + RadioButton::RadioButton(const std::string &caption, + const std::string &group, + bool selected) + { + setCaption(caption); + setGroup(group); + setSelected(selected); - setFocusable(true); - addMouseListener(this); - addKeyListener(this); + setFocusable(true); + addMouseListener(this); + addKeyListener(this); - adjustSize(); - } + adjustSize(); + } - RadioButton::~RadioButton() - { - // Remove us from the group list - setGroup(""); - } + RadioButton::~RadioButton() + { + // Remove us from the group list + setGroup(""); + } - void RadioButton::draw(Graphics* graphics) - { - graphics->pushClipArea(Rectangle(1, - 1, - getWidth() - 1, - getHeight() - 1)); - drawBox(graphics); - graphics->popClipArea(); + void RadioButton::draw(Graphics* graphics) + { + graphics->pushClipArea(Rectangle(1, + 1, + getWidth() - 1, + getHeight() - 1)); + drawBox(graphics); + graphics->popClipArea(); + + graphics->setFont(getFont()); + graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); - graphics->setColor(getForegroundColor()); + if (isFocused()) + { + int fh; + + if (getHeight()%2 == 0) + { + fh = getHeight() - 4; + } + else + { + fh = getHeight() - 3; + } - if (isFocused()) - { - int fh; + int hh = (fh + 1) / 2; + + graphics->drawLine(0, hh + 1, hh + 1, 0); + graphics->drawLine(hh + 2, 1, fh + 2, hh + 1); + graphics->drawLine(fh + 1, hh + 2, hh + 1, fh + 2); + graphics->drawLine(hh + 1, fh + 2, 1, hh + 2); + } + + int h = getHeight() + getHeight() / 2; - if (getHeight() % 2 == 0) - { - fh = getHeight() - 4; - } - else - { - fh = getHeight() - 3; - } + graphics->drawText(getCaption(), h - 2, 0); + } - auto hh = (fh + 1) / 2; + void RadioButton::drawBorder(Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + int width = getWidth() + getBorderSize() * 2 - 1; + int height = getHeight() + getBorderSize() * 2 - 1; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - graphics->drawLine(0, hh + 1, hh + 1, 0); - graphics->drawLine(hh + 2, 1, fh + 2, hh + 1); - graphics->drawLine(fh + 1, hh + 2, hh + 1, fh + 2); - graphics->drawLine(hh + 1, fh + 2, 1, hh + 2); - } + unsigned int i; + for (i = 0; i < getBorderSize(); ++i) + { + graphics->setColor(shadowColor); + graphics->drawLine(i,i, width - i, i); + graphics->drawLine(i,i + 1, i, height - i - 1); + graphics->setColor(highlightColor); + graphics->drawLine(width - i,i + 1, width - i, height - i); + graphics->drawLine(i,height - i, width - i - 1, height - i); + } + } - auto h = getHeight() + getHeight() / 2; + void RadioButton::drawBox(Graphics *graphics) + { + int h; - graphics->drawText(getCaption(), h - 2, 0); - } + if (getHeight()%2 == 0) + { + h = getHeight() - 4; + } + else + { + h = getHeight() - 3; + } - void RadioButton::drawBorder(Graphics* graphics) - { - auto faceColor = getBaseColor(); - auto alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + int alpha = getBaseColor().a; + Color faceColor = getBaseColor(); + faceColor.a = alpha; + Color highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + Color shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - for (unsigned int i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i, i, width - i, i); - graphics->drawLine(i, i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i, i + 1, width - i, height - i); - graphics->drawLine(i, height - i, width - i - 1, height - i); - } - } + graphics->setColor(getBackgroundColor()); - void RadioButton::drawBox(Graphics* graphics) - { - int h; + int i; + int hh = (h + 1) / 2; - if (getHeight() % 2 == 0) - { - h = getHeight() - 4; - } - else - { - h = getHeight() - 3; - } + for (i = 1; i <= hh; ++i) + { + graphics->drawLine(hh - i + 1, + i, + hh + i - 1, + i); + } - auto alpha = getBaseColor().a; - auto faceColor = getBaseColor(); - faceColor.a = alpha; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + for (i = 1; i < hh; ++i) + { + graphics->drawLine(hh - i + 1, + h - i, + hh + i - 1, + h - i); + } - graphics->setColor(getBackgroundColor()); + graphics->setColor(shadowColor); + graphics->drawLine(hh, 0, 0, hh); + graphics->drawLine(hh + 1, 1, h - 1, hh - 1); - int i; - auto hh = (h + 1) / 2; + graphics->setColor(highlightColor); + graphics->drawLine(1, hh + 1, hh, h); + graphics->drawLine(hh + 1, h - 1, h, hh); - for (i = 1; i <= hh; ++i) - { - graphics->drawLine(hh - i + 1, - i, - hh + i - 1, - i); - } + graphics->setColor(getForegroundColor()); - for (i = 1; i < hh; ++i) - { - graphics->drawLine(hh - i + 1, - h - i, - hh + i - 1, - h - i); - } + int hhh = hh - 3; + if (mSelected) + { + for (i = 0; i < hhh; ++i) + { + graphics->drawLine(hh - i, 4 + i, hh + i, 4 + i); + } + for (i = 0; i < hhh; ++i) + { + graphics->drawLine(hh - i, h - 4 - i, hh + i, h - 4 - i); + } - graphics->setColor(shadowColor); - graphics->drawLine(hh, 0, 0, hh); - graphics->drawLine(hh + 1, 1, h - 1, hh - 1); + } + } - graphics->setColor(highlightColor); - graphics->drawLine(1, hh + 1, hh, h); - graphics->drawLine(hh + 1, h - 1, h, hh); + bool RadioButton::isSelected() const + { + return mSelected; + } - graphics->setColor(getForegroundColor()); + void RadioButton::setSelected(bool selected) + { + if (selected && mGroup != "") + { + GroupIterator iter, iterEnd; + iterEnd = mGroupMap.upper_bound(mGroup); - auto hhh = hh - 3; - if (mSelected) - { - for (i = 0; i < hhh; ++i) - { - graphics->drawLine(hh - i, 4 + i, hh + i, 4 + i); - } - for (i = 0; i < hhh; ++i) - { - graphics->drawLine(hh - i, h - 4 - i, hh + i, h - 4 - i); - } - } - } + for (iter = mGroupMap.lower_bound(mGroup); + iter != iterEnd; + iter++) + { + if (iter->second->isSelected()) + { + iter->second->setSelected(false); + } + } + } - bool RadioButton::isSelected() const - { - return mSelected; - } + mSelected = selected; + } - void RadioButton::setSelected(bool selected) - { - if (selected && !mGroup.empty()) - { - auto iterEnd = mGroupMap.upper_bound(mGroup); + const std::string &RadioButton::getCaption() const + { + return mCaption; + } - for (auto iter = mGroupMap.lower_bound(mGroup); - iter != iterEnd; - ++iter) - { - if (iter->second->isSelected()) - { - iter->second->setSelected(false); - } - } - } + void RadioButton::setCaption(const std::string caption) + { + mCaption = caption; + } - mSelected = selected; - } + void RadioButton::keyPressed(KeyEvent& keyEvent) + { + Key key = keyEvent.getKey(); - const std::string& RadioButton::getCaption() const - { - return mCaption; - } + if (key.getValue() == Key::ENTER || + key.getValue() == Key::SPACE) + { + setSelected(true); + generateAction(); + keyEvent.consume(); + } + } - void RadioButton::setCaption(const std::string& caption) - { - mCaption = caption; - } + void RadioButton::mouseClicked(MouseEvent& mouseEvent) + { + if (mouseEvent.getButton() == MouseEvent::LEFT) + { + setSelected(true); + generateAction(); + } + } - void RadioButton::keyPressed(KeyEvent& keyEvent) - { - auto key = keyEvent.getKey(); + void RadioButton::mouseDragged(MouseEvent& mouseEvent) + { + mouseEvent.consume(); + } - if (key.getValue() == Key::ENTER || - key.getValue() == Key::SPACE) - { - setSelected(true); - generateAction(); - keyEvent.consume(); - } - } + void RadioButton::setGroup(const std::string &group) + { + if (mGroup != "") + { + GroupIterator iter, iterEnd; + iterEnd = mGroupMap.upper_bound(mGroup); - void RadioButton::mouseClicked(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - setSelected(true); - generateAction(); - } - } + for (iter = mGroupMap.lower_bound(mGroup); + iter != iterEnd; + iter++) + { + if (iter->second == this) + { + mGroupMap.erase(iter); + break; + } + } + } - void RadioButton::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } + if (group != "") + { + mGroupMap.insert( + std::pair(group, this)); + } - void RadioButton::setGroup(const std::string& group) - { - if (!mGroup.empty()) - { - auto iterEnd = mGroupMap.upper_bound(mGroup); + mGroup = group; + } - for (auto iter = mGroupMap.lower_bound(mGroup); - iter != iterEnd; - ++iter) - { - if (iter->second == this) - { - mGroupMap.erase(iter); - break; - } - } - } + const std::string &RadioButton::getGroup() const + { + return mGroup; + } - if (!group.empty()) - { - mGroupMap.insert( - std::pair(group, this)); - } + void RadioButton::adjustSize() + { + int height = getFont()->getHeight(); - mGroup = group; - } - - const std::string& RadioButton::getGroup() const - { - return mGroup; - } - - void RadioButton::adjustSize() - { - auto height = getFont()->getHeight(); - - setHeight(height); - setWidth(getFont()->getWidth(getCaption()) + height + height / 2); - } + setHeight(height); + setWidth(getFont()->getWidth(getCaption()) + height + height/2); + } } diff --git a/guisan-dev/src/widgets/scrollarea.cpp b/guisan-dev/src/widgets/scrollarea.cpp index c91f1b65..b90b27ab 100644 --- a/guisan-dev/src/widgets/scrollarea.cpp +++ b/guisan-dev/src/widgets/scrollarea.cpp @@ -65,1222 +65,1208 @@ namespace gcn { - ScrollArea::ScrollArea() - { - mVScroll = 0; - mHScroll = 0; - mHPolicy = SHOW_AUTO; - mVPolicy = SHOW_AUTO; - mScrollbarWidth = 12; - mUpButtonPressed = false; - mDownButtonPressed = false; - mLeftButtonPressed = false; - mRightButtonPressed = false; - mUpButtonScrollAmount = 10; - mDownButtonScrollAmount = 10; - mLeftButtonScrollAmount = 10; - mRightButtonScrollAmount = 10; - mIsVerticalMarkerDragged = false; - mIsHorizontalMarkerDragged = false; - - addMouseListener(this); - } - - ScrollArea::ScrollArea(Widget* content) - { - mVScroll = 0; - mHScroll = 0; - mHPolicy = SHOW_AUTO; - mVPolicy = SHOW_AUTO; - mScrollbarWidth = 12; - mUpButtonPressed = false; - mDownButtonPressed = false; - mLeftButtonPressed = false; - mRightButtonPressed = false; - mUpButtonScrollAmount = 10; - mDownButtonScrollAmount = 10; - mLeftButtonScrollAmount = 10; - mRightButtonScrollAmount = 10; - mIsVerticalMarkerDragged = false; - mIsHorizontalMarkerDragged = false; - - setContent(content); - addMouseListener(this); - } - - ScrollArea::ScrollArea(Widget* content, unsigned int hPolicy, unsigned int vPolicy) - { - mVScroll = 0; - mHScroll = 0; - mHPolicy = hPolicy; - mVPolicy = vPolicy; - mScrollbarWidth = 12; - mUpButtonPressed = false; - mDownButtonPressed = false; - mLeftButtonPressed = false; - mRightButtonPressed = false; - mUpButtonScrollAmount = 10; - mDownButtonScrollAmount = 10; - mLeftButtonScrollAmount = 10; - mRightButtonScrollAmount = 10; - mIsVerticalMarkerDragged = false; - mIsHorizontalMarkerDragged = false; - - setContent(content); - addMouseListener(this); - } - - ScrollArea::~ScrollArea() - { - setContent(nullptr); - } - - void ScrollArea::setContent(Widget* widget) - { - if (widget != nullptr) - { - clear(); - add(widget); - widget->setPosition(0, 0); - } - else - { - clear(); - } - - checkPolicies(); - } - - Widget* ScrollArea::getContent() - { - if (!mWidgets.empty()) - { - return *mWidgets.begin(); - } - - return nullptr; - } - - void ScrollArea::setHorizontalScrollPolicy(unsigned int hPolicy) - { - mHPolicy = hPolicy; - checkPolicies(); - } - - unsigned int ScrollArea::getHorizontalScrollPolicy() const - { - return mHPolicy; - } - - void ScrollArea::setVerticalScrollPolicy(unsigned int vPolicy) - { - mVPolicy = vPolicy; - checkPolicies(); - } - - unsigned int ScrollArea::getVerticalScrollPolicy() const - { - return mVPolicy; - } - - void ScrollArea::setScrollPolicy(unsigned int hPolicy, unsigned int vPolicy) - { - mHPolicy = hPolicy; - mVPolicy = vPolicy; - checkPolicies(); - } - - void ScrollArea::setVerticalScrollAmount(int vScroll) - { - auto max = getVerticalMaxScroll(); - - mVScroll = vScroll; - - if (vScroll > max) - { - mVScroll = max; - } - - if (vScroll < 0) - { - mVScroll = 0; - } - } - - int ScrollArea::getVerticalScrollAmount() const - { - return mVScroll; - } - - void ScrollArea::setHorizontalScrollAmount(int hScroll) - { - auto max = getHorizontalMaxScroll(); - - mHScroll = hScroll; - - if (hScroll > max) - { - mHScroll = max; - } - else if (hScroll < 0) - { - mHScroll = 0; - } - } - - int ScrollArea::getHorizontalScrollAmount() const - { - return mHScroll; - } - - void ScrollArea::setScrollAmount(int hScroll, int vScroll) - { - setHorizontalScrollAmount(hScroll); - setVerticalScrollAmount(vScroll); - } - - int ScrollArea::getHorizontalMaxScroll() - { - checkPolicies(); - - if (getContent() == nullptr) - { - return 0; - } - - int value = getContent()->getWidth() - getChildrenArea().width + - 2 * getContent()->getBorderSize(); - - if (value < 0) - { - return 0; - } - - return value; - } - - int ScrollArea::getVerticalMaxScroll() - { - checkPolicies(); - - if (getContent() == nullptr) - { - return 0; - } - - int value = getContent()->getHeight() - getChildrenArea().height + - 2 * getContent()->getBorderSize(); - - if (value < 0) - { - return 0; - } - - return value; - } - - void ScrollArea::setScrollbarWidth(int width) - { - if (width > 0) - { - mScrollbarWidth = width; - } - else - { - throw GCN_EXCEPTION("Width should be greater then 0."); - } - } - - int ScrollArea::getScrollbarWidth() const - { - return mScrollbarWidth; - } - - void ScrollArea::mousePressed(MouseEvent& mouseEvent) - { - auto x = mouseEvent.getX(); - auto y = mouseEvent.getY(); - - if (getUpButtonDimension().isPointInRect(x, y)) - { - setVerticalScrollAmount(getVerticalScrollAmount() - - mUpButtonScrollAmount); - mUpButtonPressed = true; - } - else if (getDownButtonDimension().isPointInRect(x, y)) - { - setVerticalScrollAmount(getVerticalScrollAmount() - + mDownButtonScrollAmount); - mDownButtonPressed = true; - } - else if (getLeftButtonDimension().isPointInRect(x, y)) - { - setHorizontalScrollAmount(getHorizontalScrollAmount() - - mLeftButtonScrollAmount); - mLeftButtonPressed = true; - } - else if (getRightButtonDimension().isPointInRect(x, y)) - { - setHorizontalScrollAmount(getHorizontalScrollAmount() - + mRightButtonScrollAmount); - mRightButtonPressed = true; - } - else if (getVerticalMarkerDimension().isPointInRect(x, y)) - { - mIsHorizontalMarkerDragged = false; - mIsVerticalMarkerDragged = true; - - mVerticalMarkerDragOffset = y - getVerticalMarkerDimension().y; - } - else if (getVerticalBarDimension().isPointInRect(x, y)) - { - if (y < getVerticalMarkerDimension().y) - { - setVerticalScrollAmount(getVerticalScrollAmount() - - int(getChildrenArea().height * 0.95)); - } - else - { - setVerticalScrollAmount(getVerticalScrollAmount() - + int(getChildrenArea().height * 0.95)); - } - } - else if (getHorizontalMarkerDimension().isPointInRect(x, y)) - { - mIsHorizontalMarkerDragged = true; - mIsVerticalMarkerDragged = false; - - mHorizontalMarkerDragOffset = x - getHorizontalMarkerDimension().x; - } - else if (getHorizontalBarDimension().isPointInRect(x, y)) - { - if (x < getHorizontalMarkerDimension().x) - { - setHorizontalScrollAmount(getHorizontalScrollAmount() - - int(getChildrenArea().width * 0.95)); - } - else - { - setHorizontalScrollAmount(getHorizontalScrollAmount() - + int(getChildrenArea().width * 0.95)); - } - } - } - - void ScrollArea::mouseReleased(MouseEvent& mouseEvent) - { - mUpButtonPressed = false; - mDownButtonPressed = false; - mLeftButtonPressed = false; - mRightButtonPressed = false; - mIsHorizontalMarkerDragged = false; - mIsVerticalMarkerDragged = false; - - mouseEvent.consume(); - } - - void ScrollArea::mouseDragged(MouseEvent& mouseEvent) - { - if (mIsVerticalMarkerDragged) - { - auto pos = mouseEvent.getY() - getVerticalBarDimension().y - mVerticalMarkerDragOffset; - auto length = getVerticalMarkerDimension().height; - - auto barDim = getVerticalBarDimension(); - - if (barDim.height - length > 0) - { - setVerticalScrollAmount((getVerticalMaxScroll() * pos) - / (barDim.height - length)); - } - else - { - setVerticalScrollAmount(0); - } - } - - if (mIsHorizontalMarkerDragged) - { - auto pos = mouseEvent.getX() - getHorizontalBarDimension().x - mHorizontalMarkerDragOffset; - auto length = getHorizontalMarkerDimension().width; - - auto barDim = getHorizontalBarDimension(); - - if (barDim.width - length > 0) - { - setHorizontalScrollAmount((getHorizontalMaxScroll() * pos) - / (barDim.width - length)); - } - else - { - setHorizontalScrollAmount(0); - } - } - - mouseEvent.consume(); - } - - void ScrollArea::draw(Graphics* graphics) - { - drawBackground(graphics); - - if (mVBarVisible) - { - drawUpButton(graphics); - drawDownButton(graphics); - drawVBar(graphics); - drawVMarker(graphics); - } - - if (mHBarVisible) - { - drawLeftButton(graphics); - drawRightButton(graphics); - drawHBar(graphics); - drawHMarker(graphics); - } - - if (mHBarVisible && mVBarVisible) - { - graphics->setColor(getBaseColor()); - graphics->fillRectangle(Rectangle(getWidth() - mScrollbarWidth, - getHeight() - mScrollbarWidth, - mScrollbarWidth, - mScrollbarWidth)); - } - - drawChildren(graphics); - } - - void ScrollArea::drawBorder(Graphics* graphics) - { - auto faceColor = getBaseColor(); - auto alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - for (unsigned int i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i, i, width - i, i); - graphics->drawLine(i, i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i, i + 1, width - i, height - i); - graphics->drawLine(i, height - i, width - i - 1, height - i); - } - } - - void ScrollArea::drawHBar(Graphics* graphics) - { - auto dim = getHorizontalBarDimension(); - - graphics->pushClipArea(dim); - - auto alpha = getBaseColor().a; - auto trackColor = getBaseColor() - 0x101010; - trackColor.a = alpha; - auto shadowColor = getBaseColor() - 0x303030; - shadowColor.a = alpha; - - graphics->setColor(trackColor); - graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); - - graphics->setColor(shadowColor); - graphics->drawLine(0, 0, dim.width, 0); - - graphics->popClipArea(); - } - - void ScrollArea::drawVBar(Graphics* graphics) - { - auto dim = getVerticalBarDimension(); - - graphics->pushClipArea(dim); - - auto alpha = getBaseColor().a; - auto trackColor = getBaseColor() - 0x101010; - trackColor.a = alpha; - auto shadowColor = getBaseColor() - 0x303030; - shadowColor.a = alpha; - - graphics->setColor(trackColor); - graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); - - graphics->setColor(shadowColor); - graphics->drawLine(0, 0, 0, dim.height); - - graphics->popClipArea(); - } - - void ScrollArea::drawBackground(Graphics* graphics) - { - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(getChildrenArea()); - } - - void ScrollArea::drawUpButton(Graphics* graphics) - { - auto dim = getUpButtonDimension(); - graphics->pushClipArea(dim); - - Color highlightColor; - Color shadowColor; - Color faceColor; - int offset; - auto alpha = getBaseColor().a; - - if (mUpButtonPressed) - { - faceColor = getBaseColor() - 0x303030; - faceColor.a = alpha; - highlightColor = faceColor - 0x303030; - highlightColor.a = alpha; - shadowColor = getBaseColor(); - shadowColor.a = alpha; - - offset = 1; - } - else - { - faceColor = getBaseColor(); - faceColor.a = alpha; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - offset = 0; - } - - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); - - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, dim.width - 1, 0); - graphics->drawLine(0, 1, 0, dim.height - 1); - - graphics->setColor(shadowColor); - graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); - graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); - - graphics->setColor(getForegroundColor()); - - auto w = dim.height / 2; - auto h = w / 2 + 2; - for (auto i = 0; i < w / 2; ++i) - { - graphics->drawLine(w - i + offset, - i + h + offset, - w + i + offset, - i + h + offset); - } - - graphics->popClipArea(); - } - - void ScrollArea::drawDownButton(Graphics* graphics) - { - auto dim = getDownButtonDimension(); - graphics->pushClipArea(dim); - - Color highlightColor; - Color shadowColor; - Color faceColor; - int offset; - auto alpha = getBaseColor().a; - - if (mDownButtonPressed) - { - faceColor = getBaseColor() - 0x303030; - faceColor.a = alpha; - highlightColor = faceColor - 0x303030; - highlightColor.a = alpha; - shadowColor = getBaseColor(); - shadowColor.a = alpha; - - offset = 1; - } - else - { - faceColor = getBaseColor(); - faceColor.a = alpha; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - offset = 0; - } - - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); - - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, dim.width - 1, 0); - graphics->drawLine(0, 1, 0, dim.height - 1); - - graphics->setColor(shadowColor); - graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); - graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); - - graphics->setColor(getForegroundColor()); - - auto w = dim.height / 2; - auto h = w + 1; - for (auto i = 0; i < w / 2; ++i) - { - graphics->drawLine(w - i + offset, - -i + h + offset, - w + i + offset, - -i + h + offset); - } - - graphics->popClipArea(); - } - - void ScrollArea::drawLeftButton(Graphics* graphics) - { - Rectangle dim = getLeftButtonDimension(); - graphics->pushClipArea(dim); - - Color highlightColor; - Color shadowColor; - Color faceColor; - int offset; - auto alpha = getBaseColor().a; - - if (mLeftButtonPressed) - { - faceColor = getBaseColor() - 0x303030; - faceColor.a = alpha; - highlightColor = faceColor - 0x303030; - highlightColor.a = alpha; - shadowColor = getBaseColor(); - shadowColor.a = alpha; - - offset = 1; - } - else - { - faceColor = getBaseColor(); - faceColor.a = alpha; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - offset = 0; - } - - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); - - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, dim.width - 1, 0); - graphics->drawLine(0, 1, 0, dim.height - 1); - - graphics->setColor(shadowColor); - graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); - graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); - - graphics->setColor(getForegroundColor()); - - auto w = dim.width / 2; - auto h = w - 2; - for (auto i = 0; i < w / 2; ++i) - { - graphics->drawLine(i + h + offset, - w - i + offset, - i + h + offset, - w + i + offset); - } - - graphics->popClipArea(); - } - - void ScrollArea::drawRightButton(Graphics* graphics) - { - auto dim = getRightButtonDimension(); - graphics->pushClipArea(dim); - - Color highlightColor; - Color shadowColor; - Color faceColor; - int offset; - auto alpha = getBaseColor().a; - - if (mRightButtonPressed) - { - faceColor = getBaseColor() - 0x303030; - faceColor.a = alpha; - highlightColor = faceColor - 0x303030; - highlightColor.a = alpha; - shadowColor = getBaseColor(); - shadowColor.a = alpha; - - offset = 1; - } - else - { - faceColor = getBaseColor(); - faceColor.a = alpha; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - offset = 0; - } - - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); - - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, dim.width - 1, 0); - graphics->drawLine(0, 1, 0, dim.height - 1); - - graphics->setColor(shadowColor); - graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); - graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); - - graphics->setColor(getForegroundColor()); - - auto w = dim.width / 2; - auto h = w + 1; - for (auto i = 0; i < w / 2; ++i) - { - graphics->drawLine(-i + h + offset, - w - i + offset, - -i + h + offset, - w + i + offset); - } - - graphics->popClipArea(); - } - - void ScrollArea::drawVMarker(Graphics* graphics) - { - auto dim = getVerticalMarkerDimension(); - graphics->pushClipArea(dim); - - auto alpha = getBaseColor().a; - auto faceColor = getBaseColor(); - faceColor.a = alpha; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(1, 1, dim.width - 1, dim.height - 1)); - - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, dim.width - 1, 0); - graphics->drawLine(0, 1, 0, dim.height - 1); - - graphics->setColor(shadowColor); - graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); - graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); - - graphics->popClipArea(); - } - - void ScrollArea::drawHMarker(Graphics* graphics) - { - auto dim = getHorizontalMarkerDimension(); - graphics->pushClipArea(dim); - - auto alpha = getBaseColor().a; - auto faceColor = getBaseColor(); - faceColor.a = alpha; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(1, 1, dim.width - 1, dim.height - 1)); - - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, dim.width - 1, 0); - graphics->drawLine(0, 1, 0, dim.height - 1); - - graphics->setColor(shadowColor); - graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); - graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); - - graphics->popClipArea(); - } - - void ScrollArea::logic() - { - checkPolicies(); - - setVerticalScrollAmount(getVerticalScrollAmount()); - setHorizontalScrollAmount(getHorizontalScrollAmount()); - - if (getContent() != nullptr) - { - getContent()->setPosition(-mHScroll + getContent()->getBorderSize(), - -mVScroll + getContent()->getBorderSize()); - getContent()->logic(); - } - } - - void ScrollArea::checkPolicies() - { - auto w = getWidth(); - auto h = getHeight(); - - mHBarVisible = false; - mVBarVisible = false; - - - if (!getContent()) - { - mHBarVisible = (mHPolicy == SHOW_ALWAYS); - mVBarVisible = (mVPolicy == SHOW_ALWAYS); - return; - } - - if (mHPolicy == SHOW_AUTO && - mVPolicy == SHOW_AUTO) - { - if (getContent()->getWidth() <= w - && getContent()->getHeight() <= h) - { - mHBarVisible = false; - mVBarVisible = false; - } - - if (getContent()->getWidth() > w) - { - mHBarVisible = true; - } - - if ((getContent()->getHeight() > h) - || (mHBarVisible && getContent()->getHeight() > h - mScrollbarWidth)) - { - mVBarVisible = true; - } - - if (mVBarVisible && getContent()->getWidth() > w - mScrollbarWidth) - { - mHBarVisible = true; - } - - return; - } - - switch (mHPolicy) - { - case SHOW_NEVER: - mHBarVisible = false; - break; - - case SHOW_ALWAYS: - mHBarVisible = true; - break; - - case SHOW_AUTO: - if (mVPolicy == SHOW_NEVER) - { - mHBarVisible = getContent()->getWidth() > w; - } - else // (mVPolicy == SHOW_ALWAYS) - { - mHBarVisible = getContent()->getWidth() > w - mScrollbarWidth; - } - break; - - default: - throw GCN_EXCEPTION("Horizontal scroll policy invalid."); - } - - switch (mVPolicy) - { - case SHOW_NEVER: - mVBarVisible = false; - break; - - case SHOW_ALWAYS: - mVBarVisible = true; - break; - - case SHOW_AUTO: - if (mHPolicy == SHOW_NEVER) - { - mVBarVisible = getContent()->getHeight() > h; - } - else // (mHPolicy == SHOW_ALWAYS) - { - mVBarVisible = getContent()->getHeight() > h - mScrollbarWidth; - } - break; - default: - throw GCN_EXCEPTION("Vertical scroll policy invalid."); - } - } - - Rectangle ScrollArea::getUpButtonDimension() const - { - if (!mVBarVisible) - { - return {0, 0, 0, 0}; - } - - return { - getWidth() - mScrollbarWidth, - 0, - mScrollbarWidth, - mScrollbarWidth - }; - } - - Rectangle ScrollArea::getDownButtonDimension() const - { - if (!mVBarVisible) - { - return {0, 0, 0, 0}; - } - - if (mVBarVisible && mHBarVisible) - { - return { - getWidth() - mScrollbarWidth, - getHeight() - mScrollbarWidth * 2, - mScrollbarWidth, - mScrollbarWidth - }; - } - - return { - getWidth() - mScrollbarWidth, - getHeight() - mScrollbarWidth, - mScrollbarWidth, - mScrollbarWidth - }; - } - - Rectangle ScrollArea::getLeftButtonDimension() const - { - if (!mHBarVisible) - { - return {0, 0, 0, 0}; - } - - return { - 0, - getHeight() - mScrollbarWidth, - mScrollbarWidth, - mScrollbarWidth - }; - } - - Rectangle ScrollArea::getRightButtonDimension() const - { - if (!mHBarVisible) - { - return {0, 0, 0, 0}; - } - - if (mVBarVisible && mHBarVisible) - { - return { - getWidth() - mScrollbarWidth * 2, - getHeight() - mScrollbarWidth, - mScrollbarWidth, - mScrollbarWidth - }; - } - - return { - getWidth() - mScrollbarWidth, - getHeight() - mScrollbarWidth, - mScrollbarWidth, - mScrollbarWidth - }; - } - - Rectangle ScrollArea::getChildrenArea() - { - if (mVBarVisible && mHBarVisible) - { - return { - 0, 0, getWidth() - mScrollbarWidth, - getHeight() - mScrollbarWidth - }; - } - - if (mVBarVisible) - { - return {0, 0, getWidth() - mScrollbarWidth, getHeight()}; - } - - if (mHBarVisible) - { - return {0, 0, getWidth(), getHeight() - mScrollbarWidth}; - } - - return {0, 0, getWidth(), getHeight()}; - } - - Rectangle ScrollArea::getVerticalBarDimension() const - { - if (!mVBarVisible) - { - return {0, 0, 0, 0}; - } - - if (mHBarVisible) - { - return { - getWidth() - mScrollbarWidth, - getUpButtonDimension().height, - mScrollbarWidth, - getHeight() - - getUpButtonDimension().height - - getDownButtonDimension().height - - mScrollbarWidth - }; - } - - return { - getWidth() - mScrollbarWidth, - getUpButtonDimension().height, - mScrollbarWidth, - getHeight() - - getUpButtonDimension().height - - getDownButtonDimension().height - }; - } - - Rectangle ScrollArea::getHorizontalBarDimension() const - { - if (!mHBarVisible) - { - return {0, 0, 0, 0}; - } - - if (mVBarVisible) - { - return { - getLeftButtonDimension().width, - getHeight() - mScrollbarWidth, - getWidth() - - getLeftButtonDimension().width - - getRightButtonDimension().width - - mScrollbarWidth, - mScrollbarWidth - }; - } - - return { - getLeftButtonDimension().width, - getHeight() - mScrollbarWidth, - getWidth() - - getLeftButtonDimension().width - - getRightButtonDimension().width, - mScrollbarWidth - }; - } - - Rectangle ScrollArea::getVerticalMarkerDimension() - { - if (!mVBarVisible) - { - return {0, 0, 0, 0}; - } - - int length, pos; - auto barDim = getVerticalBarDimension(); - - if (getContent() && getContent()->getHeight() != 0) - { - length = (barDim.height * getChildrenArea().height) - / getContent()->getHeight(); - } - else - { - length = barDim.height; - } - - if (length < mScrollbarWidth) - { - length = mScrollbarWidth; - } - - if (length > barDim.height) - { - length = barDim.height; - } - - if (getVerticalMaxScroll() != 0) - { - pos = ((barDim.height - length) * getVerticalScrollAmount()) - / getVerticalMaxScroll(); - } - else - { - pos = 0; - } - - return {barDim.x, barDim.y + pos, mScrollbarWidth, length}; - } - - Rectangle ScrollArea::getHorizontalMarkerDimension() - { - if (!mHBarVisible) - { - return {0, 0, 0, 0}; - } - - int length, pos; - auto barDim = getHorizontalBarDimension(); - - if (getContent() && getContent()->getWidth() != 0) - { - length = (barDim.width * getChildrenArea().width) - / getContent()->getWidth(); - } - else - { - length = barDim.width; - } - - if (length < mScrollbarWidth) - { - length = mScrollbarWidth; - } - - if (length > barDim.width) - { - length = barDim.width; - } - - if (getHorizontalMaxScroll() != 0) - { - pos = (barDim.width - length) * getHorizontalScrollAmount() - / getHorizontalMaxScroll(); - } - else - { - pos = 0; - } - - return {barDim.x + pos, barDim.y, length, mScrollbarWidth}; - } - - void ScrollArea::showWidgetPart(Widget* widget, Rectangle area) - { - if (widget != getContent()) - { - throw GCN_EXCEPTION("Widget not content widget"); - } - - BasicContainer::showWidgetPart(widget, area); - - setHorizontalScrollAmount(getContent()->getBorderSize() - getContent()->getX()); - setVerticalScrollAmount(getContent()->getBorderSize() - getContent()->getY()); - } - - Widget* ScrollArea::getWidgetAt(int x, int y) - { - if (getChildrenArea().isPointInRect(x, y)) - { - return getContent(); - } - - return nullptr; - } - - void ScrollArea::mouseWheelMovedUp(MouseEvent& mouseEvent) - { - if (mouseEvent.isConsumed()) - { - return; - } - - setVerticalScrollAmount(getVerticalScrollAmount() - getChildrenArea().height / 8); - - mouseEvent.consume(); - } - - void ScrollArea::mouseWheelMovedDown(MouseEvent& mouseEvent) - { - if (mouseEvent.isConsumed()) - { - return; - } - - setVerticalScrollAmount(getVerticalScrollAmount() + getChildrenArea().height / 8); - - mouseEvent.consume(); - } - - void ScrollArea::setWidth(int width) - { - Widget::setWidth(width); - checkPolicies(); - } - - void ScrollArea::setHeight(int height) - { - Widget::setHeight(height); - checkPolicies(); - } - - void ScrollArea::setDimension(const Rectangle& dimension) - { - Widget::setDimension(dimension); - checkPolicies(); - } - - void ScrollArea::setLeftButtonScrollAmount(int amount) - { - mLeftButtonScrollAmount = amount; - } - - void ScrollArea::setRightButtonScrollAmount(int amount) - { - mRightButtonScrollAmount = amount; - } - - void ScrollArea::setUpButtonScrollAmount(int amount) - { - mUpButtonScrollAmount = amount; - } - - void ScrollArea::setDownButtonScrollAmount(int amount) - { - mDownButtonScrollAmount = amount; - } - - int ScrollArea::getLeftButtonScrollAmount() const - { - return mLeftButtonScrollAmount; - } - - int ScrollArea::getRightButtonScrollAmount() const - { - return mRightButtonScrollAmount; - } - - int ScrollArea::getUpButtonScrollAmount() const - { - return mUpButtonScrollAmount; - } - - int ScrollArea::getDownButtonScrollAmount() const - { - return mDownButtonScrollAmount; - } + ScrollArea::ScrollArea() + { + mVScroll = 0; + mHScroll = 0; + mHPolicy = SHOW_AUTO; + mVPolicy = SHOW_AUTO; + mScrollbarWidth = 12; + mUpButtonPressed = false; + mDownButtonPressed = false; + mLeftButtonPressed = false; + mRightButtonPressed = false; + mUpButtonScrollAmount = 10; + mDownButtonScrollAmount = 10; + mLeftButtonScrollAmount = 10; + mRightButtonScrollAmount = 10; + mIsVerticalMarkerDragged = false; + mIsHorizontalMarkerDragged =false; + + addMouseListener(this); + } + + ScrollArea::ScrollArea(Widget *content) + { + mVScroll = 0; + mHScroll = 0; + mHPolicy = SHOW_AUTO; + mVPolicy = SHOW_AUTO; + mScrollbarWidth = 12; + mUpButtonPressed = false; + mDownButtonPressed = false; + mLeftButtonPressed = false; + mRightButtonPressed = false; + mUpButtonScrollAmount = 10; + mDownButtonScrollAmount = 10; + mLeftButtonScrollAmount = 10; + mRightButtonScrollAmount = 10; + mIsVerticalMarkerDragged = false; + mIsHorizontalMarkerDragged =false; + + setContent(content); + addMouseListener(this); + } + + ScrollArea::ScrollArea(Widget *content, unsigned int hPolicy, unsigned int vPolicy) + { + mVScroll = 0; + mHScroll = 0; + mHPolicy = hPolicy; + mVPolicy = vPolicy; + mScrollbarWidth = 12; + mUpButtonPressed = false; + mDownButtonPressed = false; + mLeftButtonPressed = false; + mRightButtonPressed = false; + mUpButtonScrollAmount = 10; + mDownButtonScrollAmount = 10; + mLeftButtonScrollAmount = 10; + mRightButtonScrollAmount = 10; + mIsVerticalMarkerDragged = false; + mIsHorizontalMarkerDragged =false; + + setContent(content); + addMouseListener(this); + } + + ScrollArea::~ScrollArea() + { + setContent(NULL); + } + + void ScrollArea::setContent(Widget* widget) + { + if (widget != NULL) + { + clear(); + add(widget); + widget->setPosition(0,0); + } + else + { + clear(); + } + + checkPolicies(); + } + + Widget* ScrollArea::getContent() + { + if (mWidgets.size() > 0) + { + return *mWidgets.begin(); + } + + return NULL; + } + + void ScrollArea::setHorizontalScrollPolicy(unsigned int hPolicy) + { + mHPolicy = hPolicy; + checkPolicies(); + } + + unsigned int ScrollArea::getHorizontalScrollPolicy() const + { + return mHPolicy; + } + + void ScrollArea::setVerticalScrollPolicy(unsigned int vPolicy) + { + mVPolicy = vPolicy; + checkPolicies(); + } + + unsigned int ScrollArea::getVerticalScrollPolicy() const + { + return mVPolicy; + } + + void ScrollArea::setScrollPolicy(unsigned int hPolicy, unsigned int vPolicy) + { + mHPolicy = hPolicy; + mVPolicy = vPolicy; + checkPolicies(); + } + + void ScrollArea::setVerticalScrollAmount(int vScroll) + { + int max = getVerticalMaxScroll(); + + mVScroll = vScroll; + + if (vScroll > max) + { + mVScroll = max; + } + + if (vScroll < 0) + { + mVScroll = 0; + } + } + + int ScrollArea::getVerticalScrollAmount() const + { + return mVScroll; + } + + void ScrollArea::setHorizontalScrollAmount(int hScroll) + { + int max = getHorizontalMaxScroll(); + + mHScroll = hScroll; + + if (hScroll > max) + { + mHScroll = max; + } + else if (hScroll < 0) + { + mHScroll = 0; + } + } + + int ScrollArea::getHorizontalScrollAmount() const + { + return mHScroll; + } + + void ScrollArea::setScrollAmount(int hScroll, int vScroll) + { + setHorizontalScrollAmount(hScroll); + setVerticalScrollAmount(vScroll); + } + + int ScrollArea::getHorizontalMaxScroll() + { + checkPolicies(); + + if (getContent() == NULL) + { + return 0; + } + + int value = getContent()->getWidth() - getChildrenArea().width + + 2 * getContent()->getBorderSize(); + + if (value < 0) + { + return 0; + } + + return value; + } + + int ScrollArea::getVerticalMaxScroll() + { + checkPolicies(); + + if (getContent() == NULL) + { + return 0; + } + + int value; + + value = getContent()->getHeight() - getChildrenArea().height + + 2 * getContent()->getBorderSize(); + + if (value < 0) + { + return 0; + } + + return value; + } + + void ScrollArea::setScrollbarWidth(int width) + { + if (width > 0) + { + mScrollbarWidth = width; + } + else + { + throw GCN_EXCEPTION("Width should be greater then 0."); + } + } + + int ScrollArea::getScrollbarWidth() const + { + return mScrollbarWidth; + } + + void ScrollArea::mousePressed(MouseEvent& mouseEvent) + { + int x = mouseEvent.getX(); + int y = mouseEvent.getY(); + + if (getUpButtonDimension().isPointInRect(x, y)) + { + setVerticalScrollAmount(getVerticalScrollAmount() + - mUpButtonScrollAmount); + mUpButtonPressed = true; + } + else if (getDownButtonDimension().isPointInRect(x, y)) + { + setVerticalScrollAmount(getVerticalScrollAmount() + + mDownButtonScrollAmount); + mDownButtonPressed = true; + } + else if (getLeftButtonDimension().isPointInRect(x, y)) + { + setHorizontalScrollAmount(getHorizontalScrollAmount() + - mLeftButtonScrollAmount); + mLeftButtonPressed = true; + } + else if (getRightButtonDimension().isPointInRect(x, y)) + { + setHorizontalScrollAmount(getHorizontalScrollAmount() + + mRightButtonScrollAmount); + mRightButtonPressed = true; + } + else if (getVerticalMarkerDimension().isPointInRect(x, y)) + { + mIsHorizontalMarkerDragged = false; + mIsVerticalMarkerDragged = true; + + mVerticalMarkerDragOffset = y - getVerticalMarkerDimension().y; + } + else if (getVerticalBarDimension().isPointInRect(x,y)) + { + if (y < getVerticalMarkerDimension().y) + { + setVerticalScrollAmount(getVerticalScrollAmount() + - (int)(getChildrenArea().height * 0.95)); + } + else + { + setVerticalScrollAmount(getVerticalScrollAmount() + + (int)(getChildrenArea().height * 0.95)); + } + } + else if (getHorizontalMarkerDimension().isPointInRect(x, y)) + { + mIsHorizontalMarkerDragged = true; + mIsVerticalMarkerDragged = false; + + mHorizontalMarkerDragOffset = x - getHorizontalMarkerDimension().x; + } + else if (getHorizontalBarDimension().isPointInRect(x,y)) + { + if (x < getHorizontalMarkerDimension().x) + { + setHorizontalScrollAmount(getHorizontalScrollAmount() + - (int)(getChildrenArea().width * 0.95)); + } + else + { + setHorizontalScrollAmount(getHorizontalScrollAmount() + + (int)(getChildrenArea().width * 0.95)); + } + } + } + + void ScrollArea::mouseReleased(MouseEvent& mouseEvent) + { + mUpButtonPressed = false; + mDownButtonPressed = false; + mLeftButtonPressed = false; + mRightButtonPressed = false; + mIsHorizontalMarkerDragged = false; + mIsVerticalMarkerDragged = false; + + mouseEvent.consume(); + } + + void ScrollArea::mouseDragged(MouseEvent& mouseEvent) + { + if (mIsVerticalMarkerDragged) + { + int pos = mouseEvent.getY() - getVerticalBarDimension().y - mVerticalMarkerDragOffset; + int length = getVerticalMarkerDimension().height; + + Rectangle barDim = getVerticalBarDimension(); + + if ((barDim.height - length) > 0) + { + setVerticalScrollAmount((getVerticalMaxScroll() * pos) + / (barDim.height - length)); + } + else + { + setVerticalScrollAmount(0); + } + } + + if (mIsHorizontalMarkerDragged) + { + int pos = mouseEvent.getX() - getHorizontalBarDimension().x - mHorizontalMarkerDragOffset; + int length = getHorizontalMarkerDimension().width; + + Rectangle barDim = getHorizontalBarDimension(); + + if ((barDim.width - length) > 0) + { + setHorizontalScrollAmount((getHorizontalMaxScroll() * pos) + / (barDim.width - length)); + } + else + { + setHorizontalScrollAmount(0); + } + } + + mouseEvent.consume(); + } + + void ScrollArea::draw(Graphics *graphics) + { + drawBackground(graphics); + + if (mVBarVisible) + { + drawUpButton(graphics); + drawDownButton(graphics); + drawVBar(graphics); + drawVMarker(graphics); + } + + if (mHBarVisible) + { + drawLeftButton(graphics); + drawRightButton(graphics); + drawHBar(graphics); + drawHMarker(graphics); + } + + if (mHBarVisible && mVBarVisible) + { + graphics->setColor(getBaseColor()); + graphics->fillRectangle(Rectangle(getWidth() - mScrollbarWidth, + getHeight() - mScrollbarWidth, + mScrollbarWidth, + mScrollbarWidth)); + } + + drawChildren(graphics); + } + + void ScrollArea::drawBorder(Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + int width = getWidth() + getBorderSize() * 2 - 1; + int height = getHeight() + getBorderSize() * 2 - 1; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + unsigned int i; + for (i = 0; i < getBorderSize(); ++i) + { + graphics->setColor(shadowColor); + graphics->drawLine(i,i, width - i, i); + graphics->drawLine(i,i + 1, i, height - i - 1); + graphics->setColor(highlightColor); + graphics->drawLine(width - i,i + 1, width - i, height - i); + graphics->drawLine(i,height - i, width - i - 1, height - i); + } + } + + void ScrollArea::drawHBar(Graphics* graphics) + { + Rectangle dim = getHorizontalBarDimension(); + + graphics->pushClipArea(dim); + + int alpha = getBaseColor().a; + Color trackColor = getBaseColor() - 0x101010; + trackColor.a = alpha; + Color shadowColor = getBaseColor() - 0x303030; + shadowColor.a = alpha; + + graphics->setColor(trackColor); + graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); + + graphics->setColor(shadowColor); + graphics->drawLine(0, 0, dim.width, 0); + + graphics->popClipArea(); + } + + void ScrollArea::drawVBar(Graphics* graphics) + { + Rectangle dim = getVerticalBarDimension(); + + graphics->pushClipArea(dim); + + int alpha = getBaseColor().a; + Color trackColor = getBaseColor() - 0x101010; + trackColor.a = alpha; + Color shadowColor = getBaseColor() - 0x303030; + shadowColor.a = alpha; + + graphics->setColor(trackColor); + graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); + + graphics->setColor(shadowColor); + graphics->drawLine(0, 0, 0, dim.height); + + graphics->popClipArea(); + } + + void ScrollArea::drawBackground(Graphics *graphics) + { + graphics->setColor(getBackgroundColor()); + graphics->fillRectangle(getChildrenArea()); + } + + void ScrollArea::drawUpButton(Graphics* graphics) + { + Rectangle dim = getUpButtonDimension(); + graphics->pushClipArea(dim); + + Color highlightColor; + Color shadowColor; + Color faceColor; + int offset; + int alpha = getBaseColor().a; + + if (mUpButtonPressed) + { + faceColor = getBaseColor() - 0x303030; + faceColor.a = alpha; + highlightColor = faceColor - 0x303030; + highlightColor.a = alpha; + shadowColor = getBaseColor(); + shadowColor.a = alpha; + + offset = 1; + } + else + { + faceColor = getBaseColor(); + faceColor.a = alpha; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + offset = 0; + } + + graphics->setColor(faceColor); + graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); + + graphics->setColor(highlightColor); + graphics->drawLine(0, 0, dim.width - 1, 0); + graphics->drawLine(0, 1, 0, dim.height - 1); + + graphics->setColor(shadowColor); + graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); + graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); + + graphics->setColor(getForegroundColor()); + + int i; + int w = dim.height / 2; + int h = w / 2 + 2; + for (i = 0; i < w / 2; ++i) + { + graphics->drawLine(w - i + offset, + i + h + offset, + w + i + offset, + i + h + offset); + } + + graphics->popClipArea(); + } + + void ScrollArea::drawDownButton(Graphics* graphics) + { + Rectangle dim = getDownButtonDimension(); + graphics->pushClipArea(dim); + + Color highlightColor; + Color shadowColor; + Color faceColor; + int offset; + int alpha = getBaseColor().a; + + if (mDownButtonPressed) + { + faceColor = getBaseColor() - 0x303030; + faceColor.a = alpha; + highlightColor = faceColor - 0x303030; + highlightColor.a = alpha; + shadowColor = getBaseColor(); + shadowColor.a = alpha; + + offset = 1; + } + else + { + faceColor = getBaseColor(); + faceColor.a = alpha; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + offset = 0; + } + + graphics->setColor(faceColor); + graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); + + graphics->setColor(highlightColor); + graphics->drawLine(0, 0, dim.width - 1, 0); + graphics->drawLine(0, 1, 0, dim.height - 1); + + graphics->setColor(shadowColor); + graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); + graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); + + graphics->setColor(getForegroundColor()); + + int i; + int w = dim.height / 2; + int h = w + 1; + for (i = 0; i < w / 2; ++i) + { + graphics->drawLine(w - i + offset, + -i + h + offset, + w + i + offset, + -i + h + offset); + } + + graphics->popClipArea(); + } + + void ScrollArea::drawLeftButton(Graphics* graphics) + { + Rectangle dim = getLeftButtonDimension(); + graphics->pushClipArea(dim); + + Color highlightColor; + Color shadowColor; + Color faceColor; + int offset; + int alpha = getBaseColor().a; + + if (mLeftButtonPressed) + { + faceColor = getBaseColor() - 0x303030; + faceColor.a = alpha; + highlightColor = faceColor - 0x303030; + highlightColor.a = alpha; + shadowColor = getBaseColor(); + shadowColor.a = alpha; + + offset = 1; + } + else + { + faceColor = getBaseColor(); + faceColor.a = alpha; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + offset = 0; + } + + graphics->setColor(faceColor); + graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); + + graphics->setColor(highlightColor); + graphics->drawLine(0, 0, dim.width - 1, 0); + graphics->drawLine(0, 1, 0, dim.height - 1); + + graphics->setColor(shadowColor); + graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); + graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); + + graphics->setColor(getForegroundColor()); + + int i; + int w = dim.width / 2; + int h = w - 2; + for (i = 0; i < w / 2; ++i) + { + graphics->drawLine(i + h + offset, + w - i + offset, + i + h + offset, + w + i + offset); + } + + graphics->popClipArea(); + } + + void ScrollArea::drawRightButton(Graphics* graphics) + { + Rectangle dim = getRightButtonDimension(); + graphics->pushClipArea(dim); + + Color highlightColor; + Color shadowColor; + Color faceColor; + int offset; + int alpha = getBaseColor().a; + + if (mRightButtonPressed) + { + faceColor = getBaseColor() - 0x303030; + faceColor.a = alpha; + highlightColor = faceColor - 0x303030; + highlightColor.a = alpha; + shadowColor = getBaseColor(); + shadowColor.a = alpha; + + offset = 1; + } + else + { + faceColor = getBaseColor(); + faceColor.a = alpha; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + offset = 0; + } + + graphics->setColor(faceColor); + graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); + + graphics->setColor(highlightColor); + graphics->drawLine(0, 0, dim.width - 1, 0); + graphics->drawLine(0, 1, 0, dim.height - 1); + + graphics->setColor(shadowColor); + graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); + graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); + + graphics->setColor(getForegroundColor()); + + int i; + int w = dim.width / 2; + int h = w + 1; + for (i = 0; i < w / 2; ++i) + { + graphics->drawLine(-i + h + offset, + w - i + offset, + -i + h + offset, + w + i + offset); + } + + graphics->popClipArea(); + } + + void ScrollArea::drawVMarker(Graphics* graphics) + { + Rectangle dim = getVerticalMarkerDimension(); + graphics->pushClipArea(dim); + + int alpha = getBaseColor().a; + Color faceColor = getBaseColor(); + faceColor.a = alpha; + Color highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + Color shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + graphics->setColor(faceColor); + graphics->fillRectangle(Rectangle(1, 1, dim.width - 1, dim.height - 1)); + + graphics->setColor(highlightColor); + graphics->drawLine(0, 0, dim.width - 1, 0); + graphics->drawLine(0, 1, 0, dim.height - 1); + + graphics->setColor(shadowColor); + graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); + graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); + + graphics->popClipArea(); + } + + void ScrollArea::drawHMarker(Graphics* graphics) + { + Rectangle dim = getHorizontalMarkerDimension(); + graphics->pushClipArea(dim); + + int alpha = getBaseColor().a; + Color faceColor = getBaseColor(); + faceColor.a = alpha; + Color highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + Color shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + graphics->setColor(faceColor); + graphics->fillRectangle(Rectangle(1, 1, dim.width - 1, dim.height - 1)); + + graphics->setColor(highlightColor); + graphics->drawLine(0, 0, dim.width - 1, 0); + graphics->drawLine(0, 1, 0, dim.height - 1); + + graphics->setColor(shadowColor); + graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); + graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); + + graphics->popClipArea(); + } + + void ScrollArea::logic() + { + checkPolicies(); + + setVerticalScrollAmount(getVerticalScrollAmount()); + setHorizontalScrollAmount(getHorizontalScrollAmount()); + + if (getContent() != NULL) + { + getContent()->setPosition(-mHScroll + getContent()->getBorderSize(), + -mVScroll + getContent()->getBorderSize()); + getContent()->logic(); + } + } + + void ScrollArea::checkPolicies() + { + int w = getWidth(); + int h = getHeight(); + + mHBarVisible = false; + mVBarVisible = false; + + + if (!getContent()) + { + mHBarVisible = (mHPolicy == SHOW_ALWAYS); + mVBarVisible = (mVPolicy == SHOW_ALWAYS); + return; + } + + if (mHPolicy == SHOW_AUTO && + mVPolicy == SHOW_AUTO) + { + if (getContent()->getWidth() <= w + && getContent()->getHeight() <= h) + { + mHBarVisible = false; + mVBarVisible = false; + } + + if (getContent()->getWidth() > w) + { + mHBarVisible = true; + } + + if ((getContent()->getHeight() > h) + || (mHBarVisible && getContent()->getHeight() > h - mScrollbarWidth)) + { + mVBarVisible = true; + } + + if (mVBarVisible && getContent()->getWidth() > w - mScrollbarWidth) + { + mHBarVisible = true; + } + + return; + } + + switch (mHPolicy) + { + case SHOW_NEVER: + mHBarVisible = false; + break; + + case SHOW_ALWAYS: + mHBarVisible = true; + break; + + case SHOW_AUTO: + if (mVPolicy == SHOW_NEVER) + { + mHBarVisible = getContent()->getWidth() > w; + } + else // (mVPolicy == SHOW_ALWAYS) + { + mHBarVisible = getContent()->getWidth() > w - mScrollbarWidth; + } + break; + + default: + throw GCN_EXCEPTION("Horizontal scroll policy invalid."); + } + + switch (mVPolicy) + { + case SHOW_NEVER: + mVBarVisible = false; + break; + + case SHOW_ALWAYS: + mVBarVisible = true; + break; + + case SHOW_AUTO: + if (mHPolicy == SHOW_NEVER) + { + mVBarVisible = getContent()->getHeight() > h; + } + else // (mHPolicy == SHOW_ALWAYS) + { + mVBarVisible = getContent()->getHeight() > h - mScrollbarWidth; + } + break; + default: + throw GCN_EXCEPTION("Vertical scroll policy invalid."); + } + } + + Rectangle ScrollArea::getUpButtonDimension() + { + if (!mVBarVisible) + { + return Rectangle(0, 0, 0, 0); + } + + return Rectangle(getWidth() - mScrollbarWidth, + 0, + mScrollbarWidth, + mScrollbarWidth); + } + + Rectangle ScrollArea::getDownButtonDimension() + { + if (!mVBarVisible) + { + return Rectangle(0, 0, 0, 0); + } + + if (mVBarVisible && mHBarVisible) + { + return Rectangle(getWidth() - mScrollbarWidth, + getHeight() - mScrollbarWidth*2, + mScrollbarWidth, + mScrollbarWidth); + } + + return Rectangle(getWidth() - mScrollbarWidth, + getHeight() - mScrollbarWidth, + mScrollbarWidth, + mScrollbarWidth); + } + + Rectangle ScrollArea::getLeftButtonDimension() + { + if (!mHBarVisible) + { + return Rectangle(0, 0, 0, 0); + } + + return Rectangle(0, + getHeight() - mScrollbarWidth, + mScrollbarWidth, + mScrollbarWidth); + } + + Rectangle ScrollArea::getRightButtonDimension() + { + if (!mHBarVisible) + { + return Rectangle(0, 0, 0, 0); + } + + if (mVBarVisible && mHBarVisible) + { + return Rectangle(getWidth() - mScrollbarWidth*2, + getHeight() - mScrollbarWidth, + mScrollbarWidth, + mScrollbarWidth); + } + + return Rectangle(getWidth() - mScrollbarWidth, + getHeight() - mScrollbarWidth, + mScrollbarWidth, + mScrollbarWidth); + } + + Rectangle ScrollArea::getChildrenArea() + { + if (mVBarVisible && mHBarVisible) + { + return Rectangle(0, 0, getWidth() - mScrollbarWidth, + getHeight() - mScrollbarWidth); + } + + if (mVBarVisible) + { + return Rectangle(0, 0, getWidth() - mScrollbarWidth, getHeight()); + } + + if (mHBarVisible) + { + return Rectangle(0, 0, getWidth(), getHeight() - mScrollbarWidth); + } + + return Rectangle(0, 0, getWidth(), getHeight()); + } + + Rectangle ScrollArea::getVerticalBarDimension() + { + if (!mVBarVisible) + { + return Rectangle(0, 0, 0, 0); + } + + if (mHBarVisible) + { + return Rectangle(getWidth() - mScrollbarWidth, + getUpButtonDimension().height, + mScrollbarWidth, + getHeight() + - getUpButtonDimension().height + - getDownButtonDimension().height + - mScrollbarWidth); + } + + return Rectangle(getWidth() - mScrollbarWidth, + getUpButtonDimension().height, + mScrollbarWidth, + getHeight() + - getUpButtonDimension().height + - getDownButtonDimension().height); + } + + Rectangle ScrollArea::getHorizontalBarDimension() + { + if (!mHBarVisible) + { + return Rectangle(0, 0, 0, 0); + } + + if (mVBarVisible) + { + return Rectangle(getLeftButtonDimension().width, + getHeight() - mScrollbarWidth, + getWidth() + - getLeftButtonDimension().width + - getRightButtonDimension().width + - mScrollbarWidth, + mScrollbarWidth); + } + + return Rectangle(getLeftButtonDimension().width, + getHeight() - mScrollbarWidth, + getWidth() + - getLeftButtonDimension().width + - getRightButtonDimension().width, + mScrollbarWidth); + } + + Rectangle ScrollArea::getVerticalMarkerDimension() + { + if (!mVBarVisible) + { + return Rectangle(0, 0, 0, 0); + } + + int length, pos; + Rectangle barDim = getVerticalBarDimension(); + + if (getContent() && getContent()->getHeight() != 0) + { + length = (barDim.height * getChildrenArea().height) + / getContent()->getHeight(); + } + else + { + length = barDim.height; + } + + if (length < mScrollbarWidth) + { + length = mScrollbarWidth; + } + + if (length > barDim.height) + { + length = barDim.height; + } + + if (getVerticalMaxScroll() != 0) + { + pos = ((barDim.height - length) * getVerticalScrollAmount()) + / getVerticalMaxScroll(); + } + else + { + pos = 0; + } + + return Rectangle(barDim.x, barDim.y + pos, mScrollbarWidth, length); + } + + Rectangle ScrollArea::getHorizontalMarkerDimension() + { + if (!mHBarVisible) + { + return Rectangle(0, 0, 0, 0); + } + + int length, pos; + Rectangle barDim = getHorizontalBarDimension(); + + if (getContent() && getContent()->getWidth() != 0) + { + length = (barDim.width * getChildrenArea().width) + / getContent()->getWidth(); + } + else + { + length = barDim.width; + } + + if (length < mScrollbarWidth) + { + length = mScrollbarWidth; + } + + if (length > barDim.width) + { + length = barDim.width; + } + + if (getHorizontalMaxScroll() != 0) + { + pos = ((barDim.width - length) * getHorizontalScrollAmount()) + / getHorizontalMaxScroll(); + } + else + { + pos = 0; + } + + return Rectangle(barDim.x + pos, barDim.y, length, mScrollbarWidth); + } + + void ScrollArea::showWidgetPart(Widget* widget, Rectangle area) + { + if (widget != getContent()) + { + throw GCN_EXCEPTION("Widget not content widget"); + } + + BasicContainer::showWidgetPart(widget, area); + + setHorizontalScrollAmount(getContent()->getBorderSize() - getContent()->getX()); + setVerticalScrollAmount(getContent()->getBorderSize() - getContent()->getY()); + } + + Widget *ScrollArea::getWidgetAt(int x, int y) + { + if (getChildrenArea().isPointInRect(x, y)) + { + return getContent(); + } + + return NULL; + } + + void ScrollArea::mouseWheelMovedUp(MouseEvent& mouseEvent) + { + if (mouseEvent.isConsumed()) + { + return; + } + + setVerticalScrollAmount(getVerticalScrollAmount() - getChildrenArea().height / 8); + + mouseEvent.consume(); + } + + void ScrollArea::mouseWheelMovedDown(MouseEvent& mouseEvent) + { + if (mouseEvent.isConsumed()) + { + return; + } + + setVerticalScrollAmount(getVerticalScrollAmount() + getChildrenArea().height / 8); + + mouseEvent.consume(); + } + + void ScrollArea::setWidth(int width) + { + Widget::setWidth(width); + checkPolicies(); + } + + void ScrollArea::setHeight(int height) + { + Widget::setHeight(height); + checkPolicies(); + } + + void ScrollArea::setDimension(const Rectangle& dimension) + { + Widget::setDimension(dimension); + checkPolicies(); + } + + void ScrollArea::setLeftButtonScrollAmount(int amount) + { + mLeftButtonScrollAmount = amount; + } + + void ScrollArea::setRightButtonScrollAmount(int amount) + { + mRightButtonScrollAmount = amount; + } + + void ScrollArea::setUpButtonScrollAmount(int amount) + { + mUpButtonScrollAmount = amount; + } + + void ScrollArea::setDownButtonScrollAmount(int amount) + { + mDownButtonScrollAmount = amount; + } + + int ScrollArea::getLeftButtonScrollAmount() const + { + return mLeftButtonScrollAmount; + } + + int ScrollArea::getRightButtonScrollAmount() const + { + return mRightButtonScrollAmount; + } + + int ScrollArea::getUpButtonScrollAmount() const + { + return mUpButtonScrollAmount; + } + + int ScrollArea::getDownButtonScrollAmount() const + { + return mDownButtonScrollAmount; + } } /* -* Wow! This is a looooong source file. -*/ + * Wow! This is a looooong source file. + */ diff --git a/guisan-dev/src/widgets/slider.cpp b/guisan-dev/src/widgets/slider.cpp index 969e09ee..943ad77c 100644 --- a/guisan-dev/src/widgets/slider.cpp +++ b/guisan-dev/src/widgets/slider.cpp @@ -66,339 +66,342 @@ namespace gcn { - Slider::Slider(double scaleEnd) - { - mMouseDrag = false; + Slider::Slider(double scaleEnd) + { + mMouseDrag = false; - mScaleStart = 0; - mScaleEnd = scaleEnd; + mScaleStart = 0; + mScaleEnd = scaleEnd; - setFocusable(true); - setBorderSize(1); - setOrientation(HORIZONTAL); - setValue(0); - setStepLength(scaleEnd / 10); - setMarkerLength(10); + setFocusable(true); + setBorderSize(1); + setOrientation(HORIZONTAL); + setValue(0); + setStepLength(scaleEnd / 10); + setMarkerLength(10); - addMouseListener(this); - addKeyListener(this); - } + addMouseListener(this); + addKeyListener(this); + } - Slider::Slider(double scaleStart, double scaleEnd) - { - mMouseDrag = false; + Slider::Slider(double scaleStart, double scaleEnd) + { + mMouseDrag = false; - mScaleStart = scaleStart; - mScaleEnd = scaleEnd; + mScaleStart = scaleStart; + mScaleEnd = scaleEnd; - setFocusable(true); - setBorderSize(1); - setOrientation(HORIZONTAL); - setValue(scaleStart); - setStepLength((scaleEnd - scaleStart) / 10); - setMarkerLength(10); + setFocusable(true); + setBorderSize(1); + setOrientation(HORIZONTAL); + setValue(scaleStart); + setStepLength((scaleEnd - scaleStart)/ 10); + setMarkerLength(10); - addMouseListener(this); - addKeyListener(this); - } + addMouseListener(this); + addKeyListener(this); + } - void Slider::setScale(double scaleStart, double scaleEnd) - { - mScaleStart = scaleStart; - mScaleEnd = scaleEnd; - } + void Slider::setScale(double scaleStart, double scaleEnd) + { + mScaleStart = scaleStart; + mScaleEnd = scaleEnd; + } - double Slider::getScaleStart() const - { - return mScaleStart; - } + double Slider::getScaleStart() const + { + return mScaleStart; + } - void Slider::setScaleStart(double scaleStart) - { - mScaleStart = scaleStart; - } + void Slider::setScaleStart(double scaleStart) + { + mScaleStart = scaleStart; + } - double Slider::getScaleEnd() const - { - return mScaleEnd; - } + double Slider::getScaleEnd() const + { + return mScaleEnd; + } - void Slider::setScaleEnd(double scaleEnd) - { - mScaleEnd = scaleEnd; - } + void Slider::setScaleEnd(double scaleEnd) + { + mScaleEnd = scaleEnd; + } - void Slider::draw(Graphics* graphics) - { - auto shadowColor = getBaseColor() - 0x101010; - auto alpha = getBaseColor().a; - shadowColor.a = alpha; + void Slider::draw(gcn::Graphics* graphics) + { + Color shadowColor = getBaseColor() - 0x101010; + int alpha = getBaseColor().a; + shadowColor.a = alpha; - graphics->setColor(shadowColor); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); + graphics->setColor(shadowColor); + graphics->fillRectangle(gcn::Rectangle(0,0,getWidth(),getHeight())); - drawMarker(graphics); - } + drawMarker(graphics); + } - void Slider::drawBorder(Graphics* graphics) - { - auto faceColor = getBaseColor(); - auto alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + void Slider::drawBorder(gcn::Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + int width = getWidth() + getBorderSize() * 2 - 1; + int height = getHeight() + getBorderSize() * 2 - 1; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - unsigned int i; - for (i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i, i, width - i, i); - graphics->drawLine(i, i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i, i + 1, width - i, height - i); - graphics->drawLine(i, height - i, width - i - 1, height - i); - } - } + unsigned int i; + for (i = 0; i < getBorderSize(); ++i) + { + graphics->setColor(shadowColor); + graphics->drawLine(i,i, width - i, i); + graphics->drawLine(i,i + 1, i, height - i - 1); + graphics->setColor(highlightColor); + graphics->drawLine(width - i,i + 1, width - i, height - i); + graphics->drawLine(i,height - i, width - i - 1, height - i); + } + } - void Slider::drawMarker(Graphics* graphics) - { - auto faceColor = getBaseColor(); - auto alpha = getBaseColor().a; - Color highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - Color shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + void Slider::drawMarker(gcn::Graphics* graphics) + { + gcn::Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - graphics->setColor(faceColor); + graphics->setColor(faceColor); - if (getOrientation() == HORIZONTAL) - { - auto v = getMarkerPosition(); - graphics->fillRectangle(Rectangle(v + 1, 1, getMarkerLength() - 2, getHeight() - 2)); - graphics->setColor(highlightColor); - graphics->drawLine(v, 0, v + getMarkerLength() - 1, 0); - graphics->drawLine(v, 0, v, getHeight() - 1); - graphics->setColor(shadowColor); - graphics->drawLine(v + getMarkerLength() - 1, 1, v + getMarkerLength() - 1, getHeight() - 1); - graphics->drawLine(v + 1, getHeight() - 1, v + getMarkerLength() - 1, getHeight() - 1); + if (getOrientation() == HORIZONTAL) + { + int v = getMarkerPosition(); + graphics->fillRectangle(gcn::Rectangle(v + 1, 1, getMarkerLength() - 2, getHeight() - 2)); + graphics->setColor(highlightColor); + graphics->drawLine(v, 0, v + getMarkerLength() - 1,0); + graphics->drawLine(v, 0, v, getHeight() - 1); + graphics->setColor(shadowColor); + graphics->drawLine(v + getMarkerLength() - 1, 1, v + getMarkerLength() - 1, getHeight() - 1); + graphics->drawLine(v + 1, getHeight() - 1, v + getMarkerLength() - 1, getHeight() - 1); - if (isFocused()) - { - graphics->setColor(getForegroundColor()); - graphics->drawRectangle(Rectangle(v + 2, 2, getMarkerLength() - 4, getHeight() - 4)); - } - } - else - { - auto v = (getHeight() - getMarkerLength()) - getMarkerPosition(); - graphics->fillRectangle(Rectangle(1, v + 1, getWidth() - 2, getMarkerLength() - 2)); - graphics->setColor(highlightColor); - graphics->drawLine(0, v, 0, v + getMarkerLength() - 1); - graphics->drawLine(0, v, getWidth() - 1, v); - graphics->setColor(shadowColor); - graphics->drawLine(1, v + getMarkerLength() - 1, getWidth() - 1, v + getMarkerLength() - 1); - graphics->drawLine(getWidth() - 1, v + 1, getWidth() - 1, v + getMarkerLength() - 1); + if (isFocused()) + { + graphics->setColor(getForegroundColor()); + graphics->drawRectangle(Rectangle(v + 2, 2, getMarkerLength() - 4, getHeight() - 4)); + } + } + else + { + int v = (getHeight() - getMarkerLength()) - getMarkerPosition(); + graphics->fillRectangle(gcn::Rectangle(1, v + 1, getWidth() - 2, getMarkerLength() - 2)); + graphics->setColor(highlightColor); + graphics->drawLine(0, v, 0, v + getMarkerLength() - 1); + graphics->drawLine(0, v, getWidth() - 1, v); + graphics->setColor(shadowColor); + graphics->drawLine(1, v + getMarkerLength() - 1, getWidth() - 1, v + getMarkerLength() - 1); + graphics->drawLine(getWidth() - 1, v + 1, getWidth() - 1, v + getMarkerLength() - 1); - if (isFocused()) - { - graphics->setColor(getForegroundColor()); - graphics->drawRectangle(Rectangle(2, v + 2, getWidth() - 4, getMarkerLength() - 4)); - } - } - } + if (isFocused()) + { + graphics->setColor(getForegroundColor()); + graphics->drawRectangle(Rectangle(2, v + 2, getWidth() - 4, getMarkerLength() - 4)); + } + } + } - void Slider::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT - && mouseEvent.getX() >= 0 - && mouseEvent.getX() <= getWidth() - && mouseEvent.getY() >= 0 - && mouseEvent.getY() <= getHeight()) - { - if (getOrientation() == HORIZONTAL) - { - setValue(markerPositionToValue(mouseEvent.getX() - getMarkerLength() / 2)); - } - else - { - setValue(markerPositionToValue(getHeight() - mouseEvent.getY() - getMarkerLength() / 2)); - } + void Slider::mousePressed(MouseEvent& mouseEvent) + { + if (mouseEvent.getButton() == gcn::MouseEvent::LEFT + && mouseEvent.getX() >= 0 + && mouseEvent.getX() <= getWidth() + && mouseEvent.getY() >= 0 + && mouseEvent.getY() <= getHeight()) + { + if (getOrientation() == HORIZONTAL) + { + setValue(markerPositionToValue(mouseEvent.getX() - getMarkerLength() / 2)); + } + else + { + setValue(markerPositionToValue(getHeight() - mouseEvent.getY() - getMarkerLength() / 2)); + } - generateAction(); - } - } + generateAction(); + } + } - void Slider::mouseDragged(MouseEvent& mouseEvent) - { - if (getOrientation() == HORIZONTAL) - { - setValue(markerPositionToValue(mouseEvent.getX() - getMarkerLength() / 2)); - } - else - { - setValue(markerPositionToValue(getHeight() - mouseEvent.getY() - getMarkerLength() / 2)); - } + void Slider::mouseDragged(MouseEvent& mouseEvent) + { + if (getOrientation() == HORIZONTAL) + { + setValue(markerPositionToValue(mouseEvent.getX() - getMarkerLength() / 2)); + } + else + { + setValue(markerPositionToValue(getHeight() - mouseEvent.getY() - getMarkerLength() / 2)); + } - generateAction(); + generateAction(); - mouseEvent.consume(); - } + mouseEvent.consume(); + } - void Slider::setValue(double value) - { - if (value > getScaleEnd()) - { - mValue = getScaleEnd(); - return; - } + void Slider::setValue(double value) + { + if (value > getScaleEnd()) + { + mValue = getScaleEnd(); + return; + } - if (value < getScaleStart()) - { - mValue = getScaleStart(); - return; - } + if (value < getScaleStart()) + { + mValue = getScaleStart(); + return; + } - mValue = value; - } + mValue = value; + } - double Slider::getValue() const - { - return mValue; - } + double Slider::getValue() const + { + return mValue; + } - int Slider::getMarkerLength() const - { - return mMarkerLength; - } + int Slider::getMarkerLength() const + { + return mMarkerLength; + } - void Slider::setMarkerLength(int length) - { - mMarkerLength = length; - } + void Slider::setMarkerLength(int length) + { + mMarkerLength = length; + } - void Slider::keyPressed(KeyEvent& keyEvent) - { - auto key = keyEvent.getKey(); + void Slider::keyPressed(KeyEvent& keyEvent) + { + Key key = keyEvent.getKey(); - if (getOrientation() == HORIZONTAL) - { - if (key.getValue() == Key::RIGHT) - { - setValue(getValue() + getStepLength()); - generateAction(); - keyEvent.consume(); - } - else if (key.getValue() == Key::LEFT) - { - setValue(getValue() - getStepLength()); - generateAction(); - keyEvent.consume(); - } - } - else - { - if (key.getValue() == Key::UP) - { - setValue(getValue() + getStepLength()); - generateAction(); - keyEvent.consume(); - } - else if (key.getValue() == Key::DOWN) - { - setValue(getValue() - getStepLength()); - generateAction(); - keyEvent.consume(); - } - } - } + if (getOrientation() == HORIZONTAL) + { + if (key.getValue() == Key::RIGHT) + { + setValue(getValue() + getStepLength()); + generateAction(); + keyEvent.consume(); + } + else if (key.getValue() == Key::LEFT) + { + setValue(getValue() - getStepLength()); + generateAction(); + keyEvent.consume(); + } + } + else + { + if (key.getValue() == Key::UP) + { + setValue(getValue() + getStepLength()); + generateAction(); + keyEvent.consume(); + } + else if (key.getValue() == Key::DOWN) + { + setValue(getValue() - getStepLength()); + generateAction(); + keyEvent.consume(); + } + } + } - void Slider::setOrientation(unsigned int orientation) - { - mOrientation = orientation; - } + void Slider::setOrientation(unsigned int orientation) + { + mOrientation = orientation; + } - unsigned int Slider::getOrientation() const - { - return mOrientation; - } + unsigned int Slider::getOrientation() const + { + return mOrientation; + } - double Slider::markerPositionToValue(int v) const - { - int w; - if (getOrientation() == HORIZONTAL) - { - w = getWidth(); - } - else - { - w = getHeight(); - } + double Slider::markerPositionToValue(int v) const + { + int w; + if (getOrientation() == HORIZONTAL) + { + w = getWidth(); + } + else + { + w = getHeight(); + } - auto pos = v / (double(w) - getMarkerLength()); - return (1.0 - pos) * getScaleStart() + pos * getScaleEnd(); - } + double pos = v / ((double)w - getMarkerLength()); + return (1.0 - pos) * getScaleStart() + pos * getScaleEnd(); - int Slider::valueToMarkerPosition(double value) const - { - int v; - if (getOrientation() == HORIZONTAL) - { - v = getWidth(); - } - else - { - v = getHeight(); - } + } - auto w = int((v - getMarkerLength()) - * (value - getScaleStart()) - / (getScaleEnd() - getScaleStart())); + int Slider::valueToMarkerPosition(double value) const + { + int v; + if (getOrientation() == HORIZONTAL) + { + v = getWidth(); + } + else + { + v = getHeight(); + } - if (w < 0) - { - return 0; - } + int w = (int)((v - getMarkerLength()) + * (value - getScaleStart()) + / (getScaleEnd() - getScaleStart())); - if (w > v - getMarkerLength()) - { - return v - getMarkerLength(); - } + if (w < 0) + { + return 0; + } - return w; - } + if (w > v - getMarkerLength()) + { + return v - getMarkerLength(); + } - void Slider::setStepLength(double length) - { - mStepLength = length; - } + return w; + } - double Slider::getStepLength() const - { - return mStepLength; - } + void Slider::setStepLength(double length) + { + mStepLength = length; + } - int Slider::getMarkerPosition() const - { - return valueToMarkerPosition(getValue()); - } + double Slider::getStepLength() const + { + return mStepLength; + } - void Slider::mouseWheelMovedUp(MouseEvent& mouseEvent) - { - setValue(getValue() + getStepLength()); - generateAction(); + int Slider::getMarkerPosition() const + { + return valueToMarkerPosition(getValue()); + } - mouseEvent.consume(); - } + void Slider::mouseWheelMovedUp(MouseEvent& mouseEvent) + { + setValue(getValue() + getStepLength()); + generateAction(); - void Slider::mouseWheelMovedDown(MouseEvent& mouseEvent) - { - setValue(getValue() - getStepLength()); - generateAction(); + mouseEvent.consume(); + } - mouseEvent.consume(); - } + void Slider::mouseWheelMovedDown(MouseEvent& mouseEvent) + { + setValue(getValue() - getStepLength()); + generateAction(); + + mouseEvent.consume(); + } } diff --git a/guisan-dev/src/widgets/tab.cpp b/guisan-dev/src/widgets/tab.cpp index 287e3e24..dde493b5 100644 --- a/guisan-dev/src/widgets/tab.cpp +++ b/guisan-dev/src/widgets/tab.cpp @@ -68,101 +68,104 @@ namespace gcn { - Tab::Tab() - : mHasMouse(false) - { - mLabel = new Label(); - mLabel->setPosition(4, 4); - add(mLabel); - setBorderSize(1); + Tab::Tab() + :mHasMouse(false) + { + mLabel = new Label(); + mLabel->setPosition(4, 4); + add(mLabel); + setBorderSize(1); - addMouseListener(this); - } + addMouseListener(this); + } + + Tab::~Tab() + { + delete mLabel; + } + + void Tab::adjustSize() + { + setHeight(mLabel->getHeight() + 8); + } - Tab::~Tab() - { - delete mLabel; - } + void Tab::setTabbedArea(TabbedArea* tabbedArea) + { + mTabbedArea = tabbedArea; + } - void Tab::adjustSize() - { - setHeight(mLabel->getHeight() + 8); - } + TabbedArea* Tab::getTabbedArea() + { + return mTabbedArea; + } - void Tab::setTabbedArea(TabbedArea* tabbedArea) - { - mTabbedArea = tabbedArea; - } + void Tab::setCaption(const std::string& caption) + { + mCaption = caption; + mLabel->setCaption(caption); + mLabel->adjustSize(); + } + + const std::string& Tab::getCaption() const + { + return mCaption; + } + + void Tab::draw(Graphics *graphics) + { + if (mTabbedArea->isTabSelected(this) || mHasMouse) + { + graphics->setColor(getBaseColor()); + } + else + { + graphics->setColor(getBaseColor() - 0x151515); + } - TabbedArea* Tab::getTabbedArea() const - { - return mTabbedArea; - } + graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); + + drawChildren(graphics); - void Tab::setCaption(const std::string& caption) - { - mCaption = caption; - mLabel->setCaption(caption); - mLabel->adjustSize(); - } + if (mTabbedArea->isFocused() + && mTabbedArea->isTabSelected(this)) + { + graphics->setColor(Color(0x000000)); + graphics->drawRectangle(Rectangle(2, 2, getWidth() - 4, getHeight() - 4)); + } + } + + void Tab::drawBorder(Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + int width = getWidth() + getBorderSize() * 2 - 1; + int height = getHeight() + getBorderSize() * 2 - 1; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - const std::string& Tab::getCaption() const - { - return mCaption; - } + unsigned int i; + for (i = 0; i < getBorderSize(); ++i) + { + graphics->setColor(highlightColor); + graphics->drawLine(i,i, width - i, i); + graphics->drawLine(i,i + 1, i, height - i - 1); + graphics->setColor(shadowColor); + graphics->drawLine(width - i,i + 1, width - i, height - i); + graphics->drawLine(i,height - i, width - i - 1, height - i); + } + } + + void Tab::mouseEntered(MouseEvent& mouseEvent) + { + mHasMouse = true; + } - void Tab::draw(Graphics* graphics) - { - if (mTabbedArea->isTabSelected(this) || mHasMouse) - { - graphics->setColor(getBaseColor()); - } - else - { - graphics->setColor(getBaseColor() - 0x151515); - } - - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - - drawChildren(graphics); - - if (mTabbedArea->isFocused() - && mTabbedArea->isTabSelected(this)) - { - graphics->setColor(Color(0x000000)); - graphics->drawRectangle(Rectangle(2, 2, getWidth() - 4, getHeight() - 4)); - } - } - - void Tab::drawBorder(Graphics* graphics) - { - auto faceColor = getBaseColor(); - int alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - for (unsigned int i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(highlightColor); - graphics->drawLine(i, i, width - i, i); - graphics->drawLine(i, i + 1, i, height - i - 1); - graphics->setColor(shadowColor); - graphics->drawLine(width - i, i + 1, width - i, height - i); - graphics->drawLine(i, height - i, width - i - 1, height - i); - } - } - - void Tab::mouseEntered(MouseEvent& mouseEvent) - { - mHasMouse = true; - } - - void Tab::mouseExited(MouseEvent& mouseEvent) - { - mHasMouse = false; - } + void Tab::mouseExited(MouseEvent& mouseEvent) + { + mHasMouse = false; + } } + diff --git a/guisan-dev/src/widgets/tabbedarea.cpp b/guisan-dev/src/widgets/tabbedarea.cpp index 428b6c47..4f52fe90 100644 --- a/guisan-dev/src/widgets/tabbedarea.cpp +++ b/guisan-dev/src/widgets/tabbedarea.cpp @@ -72,419 +72,433 @@ namespace gcn { - TabbedArea::TabbedArea() - : mSelectedTab(nullptr) - { - setBorderSize(1); - setFocusable(true); - addKeyListener(this); - addMouseListener(this); - - mTabContainer = new Container(); - mTabContainer->setOpaque(false); - mWidgetContainer = new Container(); - - add(mTabContainer); - add(mWidgetContainer); - } - - TabbedArea::~TabbedArea() - { - BasicContainer::remove(mTabContainer); - BasicContainer::remove(mWidgetContainer); - - delete mTabContainer; - delete mWidgetContainer; - - unsigned int i; - for (i = 0; i < mTabsToCleanUp.size(); i++) - { - delete mTabsToCleanUp[i]; - } - } - - void TabbedArea::addTab(const std::string& caption, Widget* widget) - { - auto tab = new Tab(); - tab->setSize(70, 20); - tab->setCaption(caption); - mTabsToCleanUp.push_back(tab); - - addTab(tab, widget); - } - - void TabbedArea::addTab(Tab* tab, Widget* widget) - { - tab->setTabbedArea(this); - tab->addActionListener(this); - - mTabContainer->add(tab); - mTabs.emplace_back(tab, widget); - - - if (mSelectedTab == nullptr) - { - setSelectedTab(tab); - } - - adjustTabPositions(); - adjustSize(); - } - - void TabbedArea::removeTabWithIndex(unsigned int index) - { - if (index >= mTabs.size()) - { - throw GCN_EXCEPTION("No such tab index."); - } - - removeTab(mTabs[index].first); - } - - void TabbedArea::removeTab(Tab* tab) - { - auto tabIndexToBeSelected = - 1; - - if (tab == mSelectedTab) - { - auto index = getSelectedTabIndex(); - - if (index == int(mTabs.size()) - 1 - && mTabs.size() >= 2) - { - tabIndexToBeSelected = index--; - } - else if (index == int(mTabs.size()) - 1 - && mTabs.size() == 1) - { - tabIndexToBeSelected = -1; - } - else - { - tabIndexToBeSelected = index; - } - } - - for (auto iter = mTabs.begin(); iter != mTabs.end(); ++iter) - { - if (iter->first == tab) - { - mTabContainer->remove(tab); - mTabs.erase(iter); - break; - } - } - - for (auto iter2 = mTabsToCleanUp.begin(); iter2 != mTabsToCleanUp.end(); ++iter2) - { - if (*iter2 == tab) - { - mTabsToCleanUp.erase(iter2); - delete tab; - break; - } - } - - if (tabIndexToBeSelected == -1) - { - mSelectedTab = nullptr; - mWidgetContainer->clear(); - } - else - { - setSelectedTabWithIndex(tabIndexToBeSelected); - } - - adjustSize(); - adjustTabPositions(); - } - - bool TabbedArea::isTabSelected(unsigned int index) const - { - if (index >= mTabs.size()) - { - throw GCN_EXCEPTION("No such tab index."); - } - - return mSelectedTab == mTabs[index].first; - } - - bool TabbedArea::isTabSelected(Tab* tab) - { - return mSelectedTab == tab; - } - - void TabbedArea::setSelectedTabWithIndex(unsigned int index) - { - if (index >= mTabs.size()) - { - throw GCN_EXCEPTION("No such tab index."); - } - - setSelectedTab(mTabs[index].first); - } - - void TabbedArea::setSelectedTab(Tab* tab) - { - unsigned int i; - for (i = 0; i < mTabs.size(); i++) - { - if (mTabs[i].first == mSelectedTab) - { - mWidgetContainer->remove(mTabs[i].second); - } - } - - for (i = 0; i < mTabs.size(); i++) - { - if (mTabs[i].first == tab) - { - mSelectedTab = tab; - mWidgetContainer->add(mTabs[i].second); - } - } - } - - int TabbedArea::getSelectedTabIndex() const - { - for (unsigned int i = 0; i < mTabs.size(); i++) - { - if (mTabs[i].first == mSelectedTab) - { - return i; - } - } - - return -1; - } - - Tab* TabbedArea::getSelectedTab() const - { - return mSelectedTab; - } - - - void TabbedArea::draw(Graphics* graphics) - { - graphics->setColor(getBaseColor() + 0x303030); - graphics->drawLine(0, - mTabContainer->getHeight(), - getWidth(), - mTabContainer->getHeight()); - - if (mSelectedTab != nullptr) - { - graphics->setColor(getBaseColor()); - graphics->drawLine(mSelectedTab->getX(), - mTabContainer->getHeight(), - mSelectedTab->getX() + mSelectedTab->getWidth(), - mTabContainer->getHeight()); - } - - drawChildren(graphics); - } - - void TabbedArea::drawBorder(Graphics* graphics) - { - auto faceColor = getBaseColor(); - auto alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - for (unsigned int i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(highlightColor); - graphics->drawLine(i, i + mWidgetContainer->getY(), i, height - i - 1); - graphics->setColor(shadowColor); - graphics->drawLine(width - i, i + 1 + mWidgetContainer->getY(), width - i, height - i); - graphics->drawLine(i, height - i, width - i - 1, height - i); - } - } - - - void TabbedArea::logic() - { - } - - void TabbedArea::adjustSize() - { - auto maxTabHeight = 0; - for (auto& mTab : mTabs) - { - if (mTab.first->getHeight() > maxTabHeight) - { - maxTabHeight = mTab.first->getHeight(); - } - } - - if (getHeight() < maxTabHeight) - { - mTabContainer->setHeight(maxTabHeight); - } - else - { - mTabContainer->setHeight(maxTabHeight); - mWidgetContainer->setHeight(getHeight() - maxTabHeight - 1); - mWidgetContainer->setY(maxTabHeight + 1); - } - - mTabContainer->setWidth(getWidth()); - mWidgetContainer->setWidth(getWidth()); - } - - void TabbedArea::adjustTabPositions() - { - auto maxTabHeight = 0; - unsigned int i; - for (i = 0; i < mTabs.size(); i++) - { - if (mTabs[i].first->getHeight() > maxTabHeight) - { - maxTabHeight = mTabs[i].first->getHeight(); - } - } - - auto x = 0; - for (i = 0; i < mTabs.size(); i++) - { - auto tab = mTabs[i].first; - - if (x == 0) - { - x = tab->getBorderSize() + 2; - } - - tab->setX(x); - - if (tab->getHeight() < maxTabHeight) - { - tab->setY(maxTabHeight - - tab->getHeight() - + tab->getBorderSize()); - } - else - { - tab->setY(mTabs[i].first->getBorderSize()); - } - - x += tab->getWidth() + tab->getBorderSize() * 2; - } - } - - void TabbedArea::setWidth(int width) - { - Widget::setWidth(width); - adjustSize(); - } - - - void TabbedArea::setHeight(int height) - { - Widget::setHeight(height); - adjustSize(); - } - - void TabbedArea::setSize(int width, int height) - { - setWidth(width); - setHeight(height); - } - - void TabbedArea::setDimension(const Rectangle& dimension) - { - setX(dimension.x); - setY(dimension.y); - setWidth(dimension.width); - setHeight(dimension.height); - } - - void TabbedArea::keyPressed(KeyEvent& keyEvent) - { - if (keyEvent.isConsumed() || !isFocused()) - { - return; - } - - if (keyEvent.getKey().getValue() == Key::LEFT) - { - int index = getSelectedTabIndex(); - index--; - - if (index < 0) - { - return; - } - setSelectedTab(mTabs[index].first); - - keyEvent.consume(); - } - else if (keyEvent.getKey().getValue() == Key::RIGHT) - { - int index = getSelectedTabIndex(); - index++; - - if (index >= int(mTabs.size())) - { - return; - } - setSelectedTab(mTabs[index].first); - - keyEvent.consume(); - } - } - - - void TabbedArea::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.isConsumed() - && mouseEvent.getSource()->isFocusable()) - { - return; - } - - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - auto widget = mTabContainer->getWidgetAt(mouseEvent.getX(), mouseEvent.getY()); - auto tab = dynamic_cast(widget); - - if (tab != nullptr) - { - setSelectedTab(tab); - } - } - - requestFocus(); - } - - void TabbedArea::death(const Event& event) - { - auto source = event.getSource(); - auto tab = dynamic_cast(source); - - if (tab != nullptr) - { - removeTab(tab); - } - else - { - BasicContainer::death(event); - } - } - - void TabbedArea::action(const ActionEvent& actionEvent) - { - auto source = actionEvent.getSource(); - auto tab = dynamic_cast(source); - - if (tab == nullptr) - { - throw GCN_EXCEPTION("Received an action from a widget that's not a tab!"); - } - - setSelectedTab(tab); - } + TabbedArea::TabbedArea() + :mSelectedTab(NULL) + { + setBorderSize(1); + setFocusable(true); + addKeyListener(this); + addMouseListener(this); + + mTabContainer = new Container(); + mTabContainer->setOpaque(false); + mWidgetContainer = new Container(); + + add(mTabContainer); + add(mWidgetContainer); + } + + TabbedArea::~TabbedArea() + { + remove(mTabContainer); + remove(mWidgetContainer); + + delete mTabContainer; + delete mWidgetContainer; + + unsigned int i; + for (i = 0; i < mTabsToCleanUp.size(); i++) + { + delete mTabsToCleanUp[i]; + } + } + + void TabbedArea::addTab(const std::string& caption, Widget* widget) + { + Tab* tab = new Tab(); + tab->setSize(70, 20); + tab->setCaption(caption); + mTabsToCleanUp.push_back(tab); + + addTab(tab, widget); + } + + void TabbedArea::addTab(Tab* tab, Widget* widget) + { + tab->setTabbedArea(this); + tab->addActionListener(this); + + mTabContainer->add(tab); + mTabs.push_back(std::pair(tab, widget)); + + + if (mSelectedTab == NULL) + { + setSelectedTab(tab); + } + + adjustTabPositions(); + adjustSize(); + } + + void TabbedArea::removeTabWithIndex(unsigned int index) + { + if (index >= mTabs.size()) + { + throw GCN_EXCEPTION("No such tab index."); + } + + removeTab(mTabs[index].first); + } + + void TabbedArea::removeTab(Tab* tab) + { + int tabIndexToBeSelected = - 1; + + if (tab == mSelectedTab) + { + int index = getSelectedTabIndex(); + + if (index == (int)mTabs.size() - 1 + && mTabs.size() >= 2) + { + tabIndexToBeSelected = index--; + } + else if (index == (int)mTabs.size() - 1 + && mTabs.size() == 1) + { + tabIndexToBeSelected = -1; + } + else + { + tabIndexToBeSelected = index; + } + } + + std::vector >::iterator iter; + for (iter = mTabs.begin(); iter != mTabs.end(); iter++) + { + if (iter->first == tab) + { + mTabContainer->remove(tab); + mTabs.erase(iter); + break; + } + } + + std::vector::iterator iter2; + for (iter2 = mTabsToCleanUp.begin(); iter2 != mTabsToCleanUp.end(); iter2++) + { + if (*iter2 == tab) + { + mTabsToCleanUp.erase(iter2); + delete tab; + break; + } + } + + if (tabIndexToBeSelected == -1) + { + mSelectedTab = NULL; + mWidgetContainer->clear(); + } + else + { + setSelectedTabWithIndex(tabIndexToBeSelected); + } + + adjustSize(); + adjustTabPositions(); + } + + bool TabbedArea::isTabSelected(unsigned int index) const + { + if (index >= mTabs.size()) + { + throw GCN_EXCEPTION("No such tab index."); + } + + return mSelectedTab == mTabs[index].first; + } + + bool TabbedArea::isTabSelected(Tab* tab) + { + return mSelectedTab == tab; + } + + void TabbedArea::setSelectedTabWithIndex(unsigned int index) + { + if (index >= mTabs.size()) + { + throw GCN_EXCEPTION("No such tab index."); + } + + setSelectedTab(mTabs[index].first); + } + + void TabbedArea::setSelectedTab(Tab* tab) + { + unsigned int i; + for (i = 0; i < mTabs.size(); i++) + { + if (mTabs[i].first == mSelectedTab) + { + mWidgetContainer->remove(mTabs[i].second); + } + } + + for (i = 0; i < mTabs.size(); i++) + { + if (mTabs[i].first == tab) + { + mSelectedTab = tab; + mWidgetContainer->add(mTabs[i].second); + } + } + } + + int TabbedArea::getSelectedTabIndex() const + { + unsigned int i; + for (i = 0; i < mTabs.size(); i++) + { + if (mTabs[i].first == mSelectedTab) + { + return i; + } + } + + return -1; + } + + Tab* TabbedArea::getSelectedTab() + { + return mSelectedTab; + } + + + void TabbedArea::draw(Graphics *graphics) + { + graphics->setColor(getBaseColor() + 0x303030); + graphics->drawLine(0, + mTabContainer->getHeight(), + getWidth(), + mTabContainer->getHeight()); + + if (mSelectedTab != NULL) + { + graphics->setColor(getBaseColor()); + graphics->drawLine(mSelectedTab->getX(), + mTabContainer->getHeight(), + mSelectedTab->getX() + mSelectedTab->getWidth(), + mTabContainer->getHeight()); + + } + + drawChildren(graphics); + } + + void TabbedArea::drawBorder(Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + int width = getWidth() + getBorderSize() * 2 - 1; + int height = getHeight() + getBorderSize() * 2 - 1; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + unsigned int i; + for (i = 0; i < getBorderSize(); ++i) + { + graphics->setColor(highlightColor); + graphics->drawLine(i,i + mWidgetContainer->getY(), i, height - i - 1); + graphics->setColor(shadowColor); + graphics->drawLine(width - i,i + 1 + mWidgetContainer->getY(), width - i, height - i); + graphics->drawLine(i,height - i, width - i - 1, height - i); + } + } + + + void TabbedArea::logic() + { + + } + + void TabbedArea::adjustSize() + { + int maxTabHeight = 0; + unsigned int i; + for (i = 0; i < mTabs.size(); i++) + { + if (mTabs[i].first->getHeight() > maxTabHeight) + { + maxTabHeight = mTabs[i].first->getHeight(); + } + } + + if (getHeight() < maxTabHeight) + { + mTabContainer->setHeight(maxTabHeight); + } + else + { + mTabContainer->setHeight(maxTabHeight); + mWidgetContainer->setHeight(getHeight() - maxTabHeight - 1); + mWidgetContainer->setY(maxTabHeight + 1); + } + + mTabContainer->setWidth(getWidth()); + mWidgetContainer->setWidth(getWidth()); + } + + void TabbedArea::adjustTabPositions() + { + int maxTabHeight = 0; + unsigned int i; + for (i = 0; i < mTabs.size(); i++) + { + if (mTabs[i].first->getHeight() > maxTabHeight) + { + maxTabHeight = mTabs[i].first->getHeight(); + } + } + + int x = 0; + for (i = 0; i < mTabs.size(); i++) + { + Tab* tab = mTabs[i].first; + + if (x == 0) + { + x = tab->getBorderSize() + 2; + } + + tab->setX(x); + + if (tab->getHeight() < maxTabHeight) + { + tab->setY(maxTabHeight + - tab->getHeight() + + tab->getBorderSize()); + } + else + { + tab->setY(mTabs[i].first->getBorderSize()); + } + + x += tab->getWidth() + tab->getBorderSize() * 2; + } + } + + void TabbedArea::setWidth(int width) + { + Widget::setWidth(width); + adjustSize(); + } + + + void TabbedArea::setHeight(int height) + { + Widget::setHeight(height); + adjustSize(); + } + + void TabbedArea::setSize(int width, int height) + { + setWidth(width); + setHeight(height); + } + + void TabbedArea::setDimension(const Rectangle& dimension) + { + setX(dimension.x); + setY(dimension.y); + setWidth(dimension.width); + setHeight(dimension.height); + } + + void TabbedArea::keyPressed(KeyEvent& keyEvent) + { + if (keyEvent.isConsumed() || !isFocused()) + { + return; + } + + if (keyEvent.getKey().getValue() == Key::LEFT) + { + int index = getSelectedTabIndex(); + index--; + + if (index < 0) + { + return; + } + else + { + setSelectedTab(mTabs[index].first); + } + + keyEvent.consume(); + } + else if (keyEvent.getKey().getValue() == Key::RIGHT) + { + int index = getSelectedTabIndex(); + index++; + + if (index >= (int)mTabs.size()) + { + return; + } + else + { + setSelectedTab(mTabs[index].first); + } + + keyEvent.consume(); + } + } + + + void TabbedArea::mousePressed(MouseEvent& mouseEvent) + { + if (mouseEvent.isConsumed() + && mouseEvent.getSource()->isFocusable()) + { + return; + } + + if (mouseEvent.getButton() == MouseEvent::LEFT) + { + Widget* widget = mTabContainer->getWidgetAt(mouseEvent.getX(), mouseEvent.getY()); + Tab* tab = dynamic_cast(widget); + + if (tab != NULL) + { + setSelectedTab(tab); + } + } + + requestFocus(); + } + + void TabbedArea::death(const Event& event) + { + Widget* source = event.getSource(); + Tab* tab = dynamic_cast(source); + + if (tab != NULL) + { + removeTab(tab); + } + else + { + BasicContainer::death(event); + } + } + + void TabbedArea::action(const ActionEvent& actionEvent) + { + Widget* source = actionEvent.getSource(); + Tab* tab = dynamic_cast(source); + + if (tab == NULL) + { + throw GCN_EXCEPTION("Received an action from a widget that's not a tab!"); + } + + setSelectedTab(tab); + } } diff --git a/guisan-dev/src/widgets/textbox.cpp b/guisan-dev/src/widgets/textbox.cpp index 09702a13..3242fc94 100644 --- a/guisan-dev/src/widgets/textbox.cpp +++ b/guisan-dev/src/widgets/textbox.cpp @@ -68,485 +68,493 @@ namespace gcn { - TextBox::TextBox() - { - mCaretColumn = 0; - mCaretRow = 0; - mEditable = true; - mOpaque = true; - - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - TextBox::adjustSize(); - setBorderSize(1); - setText(""); - } - - TextBox::TextBox(const std::string& text) - { - mCaretColumn = 0; - mCaretRow = 0; - mEditable = true; - mOpaque = true; - - setText(text); - - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - TextBox::adjustSize(); - setBorderSize(1); - } - - void TextBox::setText(const std::string& text) - { - mCaretColumn = 0; - mCaretRow = 0; - - mTextRows.clear(); - - std::string::size_type pos, lastPos = 0; - int length; - do - { - pos = text.find('\n', lastPos); - - if (pos != std::string::npos) - { - length = pos - lastPos; - } - else - { - length = text.size() - lastPos; - } - auto sub = text.substr(lastPos, length); - mTextRows.push_back(sub); - lastPos = pos + 1; - } - while (pos != std::string::npos); - - adjustSize(); - } - - void TextBox::draw(Graphics* graphics) - { - if (mOpaque) - { - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - } - - if (isFocused() && isEditable()) - { - drawCaret(graphics, getFont()->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn)), - mCaretRow * getFont()->getHeight()); - } - - graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); - - for (unsigned int i = 0; i < mTextRows.size(); i++) - { - // Move the text one pixel so we can have a caret before a letter. - graphics->drawText(mTextRows[i], 1, i * getFont()->getHeight()); - } - } - - void TextBox::drawBorder(Graphics* graphics) - { - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - - graphics->setColor(getBackgroundColor()); - - for (unsigned int i = 0; i < getBorderSize(); ++i) - { - graphics->drawLine(i, i, width - i, i); - graphics->drawLine(i, i + 1, i, height - i - 1); - graphics->drawLine(width - i, i + 1, width - i, height - i); - graphics->drawLine(i, height - i, width - i - 1, height - i); - } - } - - void TextBox::drawCaret(Graphics* graphics, int x, int y) - { - graphics->setColor(getForegroundColor()); - graphics->drawLine(x, getFont()->getHeight() + y, x, y); - } - - void TextBox::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mCaretRow = mouseEvent.getY() / getFont()->getHeight(); - - if (mCaretRow >= int(mTextRows.size())) - { - mCaretRow = mTextRows.size() - 1; - } - - mCaretColumn = getFont()->getStringIndexAt(mTextRows[mCaretRow], mouseEvent.getX()); - } - } - - void TextBox::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } - - void TextBox::keyPressed(KeyEvent& keyEvent) - { - auto key = keyEvent.getKey(); - - if (key.getValue() == Key::LEFT) - { - --mCaretColumn; - if (mCaretColumn < 0) - { - --mCaretRow; - - if (mCaretRow < 0) - { - mCaretRow = 0; - mCaretColumn = 0; - } - else - { - mCaretColumn = mTextRows[mCaretRow].size(); - } - } - } - - else if (key.getValue() == Key::RIGHT) - { - ++mCaretColumn; - if (mCaretColumn > int(mTextRows[mCaretRow].size())) - { - ++mCaretRow; - - if (mCaretRow >= int(mTextRows.size())) - { - mCaretRow = mTextRows.size() - 1; - if (mCaretRow < 0) - { - mCaretRow = 0; - } - - mCaretColumn = mTextRows[mCaretRow].size(); - } - else - { - mCaretColumn = 0; - } - } - } - - else if (key.getValue() == Key::DOWN) - { - setCaretRow(mCaretRow + 1); - } - - else if (key.getValue() == Key::UP) - { - setCaretRow(mCaretRow - 1); - } - - else if (key.getValue() == Key::HOME) - { - mCaretColumn = 0; - } - - else if (key.getValue() == Key::END) - { - mCaretColumn = mTextRows[mCaretRow].size(); - } - - else if (key.getValue() == Key::ENTER && mEditable) - { - mTextRows.insert(mTextRows.begin() + mCaretRow + 1, - mTextRows[mCaretRow].substr(mCaretColumn, mTextRows[mCaretRow].size() - mCaretColumn)); - mTextRows[mCaretRow].resize(mCaretColumn); - ++mCaretRow; - mCaretColumn = 0; - } - - else if (key.getValue() == Key::BACKSPACE - && mCaretColumn != 0 - && mEditable) - { - mTextRows[mCaretRow].erase(mCaretColumn - 1, 1); - --mCaretColumn; - } - - else if (key.getValue() == Key::BACKSPACE - && mCaretColumn == 0 - && mCaretRow != 0 - && mEditable) - { - mCaretColumn = mTextRows[mCaretRow - 1].size(); - mTextRows[mCaretRow - 1] += mTextRows[mCaretRow]; - mTextRows.erase(mTextRows.begin() + mCaretRow); - --mCaretRow; - } - - else if (key.getValue() == Key::DELETE - && mCaretColumn < int(mTextRows[mCaretRow].size()) - && mEditable) - { - mTextRows[mCaretRow].erase(mCaretColumn, 1); - } - - else if (key.getValue() == Key::DELETE - && mCaretColumn == int(mTextRows[mCaretRow].size()) - && mCaretRow < int(mTextRows.size()) - 1 - && mEditable) - { - mTextRows[mCaretRow] += mTextRows[mCaretRow + 1]; - mTextRows.erase(mTextRows.begin() + mCaretRow + 1); - } - - else if (key.getValue() == Key::PAGE_UP) - { - auto par = getParent(); - - if (par != nullptr) - { - auto rowsPerPage = par->getChildrenArea().height / getFont()->getHeight(); - mCaretRow -= rowsPerPage; - - if (mCaretRow < 0) - { - mCaretRow = 0; - } - } - } - - else if (key.getValue() == Key::PAGE_DOWN) - { - auto par = getParent(); - - if (par != nullptr) - { - auto rowsPerPage = par->getChildrenArea().height / getFont()->getHeight(); - mCaretRow += rowsPerPage; - - if (mCaretRow >= int(mTextRows.size())) - { - mCaretRow = mTextRows.size() - 1; - } - } - } - - else if (key.getValue() == Key::TAB - && mEditable) - { - mTextRows[mCaretRow].insert(mCaretColumn, std::string(" ")); - mCaretColumn += 4; - } - - else if (key.isCharacter() - && mEditable) - { - if (keyEvent.isShiftPressed() && key.isLetter()) - { - mTextRows[mCaretRow].insert(mCaretColumn, std::string(1, char(key.getValue() - 32))); - } - else - { - mTextRows[mCaretRow].insert(mCaretColumn, std::string(1, char(key.getValue()))); - } - ++mCaretColumn; - } - - adjustSize(); - scrollToCaret(); - - keyEvent.consume(); - } - - void TextBox::adjustSize() - { - auto width = 0; - for (const auto& mTextRow : mTextRows) - { - auto w = getFont()->getWidth(mTextRow); - if (width < w) - { - width = w; - } - } - - setWidth(width + 1); - setHeight(getFont()->getHeight() * mTextRows.size()); - } - - void TextBox::setCaretPosition(unsigned int position) - { - for (auto row = 0; row < int(mTextRows.size()); row++) - { - if (position <= mTextRows[row].size()) - { - mCaretRow = row; - mCaretColumn = position; - return; // we are done - } - position--; - } - - // position beyond end of text - mCaretRow = mTextRows.size() - 1; - mCaretColumn = mTextRows[mCaretRow].size(); - } - - unsigned int TextBox::getCaretPosition() const - { - auto pos = 0; - - for (auto row = 0; row < mCaretRow; row++) - { - pos += mTextRows[row].size(); - } - - return pos + mCaretColumn; - } - - void TextBox::setCaretRowColumn(int row, int column) - { - setCaretRow(row); - setCaretColumn(column); - } - - void TextBox::setCaretRow(int row) - { - mCaretRow = row; - - if (mCaretRow >= int(mTextRows.size())) - { - mCaretRow = mTextRows.size() - 1; - } - - if (mCaretRow < 0) - { - mCaretRow = 0; - } - - setCaretColumn(mCaretColumn); - } - - unsigned int TextBox::getCaretRow() const - { - return mCaretRow; - } - - void TextBox::setCaretColumn(int column) - { - mCaretColumn = column; - - if (mCaretColumn > int(mTextRows[mCaretRow].size())) - { - mCaretColumn = mTextRows[mCaretRow].size(); - } - - if (mCaretColumn < 0) - { - mCaretColumn = 0; - } - } - - unsigned int TextBox::getCaretColumn() const - { - return mCaretColumn; - } - - const std::string& TextBox::getTextRow(int row) const - { - return mTextRows[row]; - } - - void TextBox::setTextRow(int row, const std::string& text) - { - mTextRows[row] = text; - - if (mCaretRow == row) - { - setCaretColumn(mCaretColumn); - } - - adjustSize(); - } - - unsigned int TextBox::getNumberOfRows() const - { - return mTextRows.size(); - } - - std::string TextBox::getText() const - { - if (mTextRows.empty()) - { - return std::string(""); - } - - int i; - std::string text; - - for (i = 0; i < int(mTextRows.size()) - 1; ++i) - { - text = text + mTextRows[i] + "\n"; - } - - text = text + mTextRows[i]; - - return text; - } - - void TextBox::fontChanged() - { - adjustSize(); - } - - void TextBox::scrollToCaret() - { - auto par = getParent(); - if (par == nullptr) - { - return; - } - - Rectangle scroll; - scroll.x = getFont()->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn)); - scroll.y = getFont()->getHeight() * mCaretRow; - scroll.width = getFont()->getWidth(" "); - scroll.height = getFont()->getHeight() + 2; // add 2 for some extra space - par->showWidgetPart(this, scroll); - } - - void TextBox::setEditable(bool editable) - { - mEditable = editable; - } - - bool TextBox::isEditable() const - { - return mEditable; - } - - void TextBox::addRow(const std::string row) - { - mTextRows.push_back(row); - adjustSize(); - } - - bool TextBox::isOpaque() const - { - return mOpaque; - } - - void TextBox::setOpaque(bool opaque) - { - mOpaque = opaque; - } + TextBox::TextBox() + { + mCaretColumn = 0; + mCaretRow = 0; + mEditable = true; + mOpaque = true; + + setFocusable(true); + + addMouseListener(this); + addKeyListener(this); + adjustSize(); + setBorderSize(1); + setText(""); + } + + TextBox::TextBox(const std::string& text) + { + mCaretColumn = 0; + mCaretRow = 0; + mEditable = true; + mOpaque = true; + + setText(text); + + setFocusable(true); + + addMouseListener(this); + addKeyListener(this); + adjustSize(); + setBorderSize(1); + } + + void TextBox::setText(const std::string& text) + { + mCaretColumn = 0; + mCaretRow = 0; + + mTextRows.clear(); + + std::string::size_type pos, lastPos = 0; + int length; + do + { + pos = text.find("\n", lastPos); + + if (pos != std::string::npos) + { + length = pos - lastPos; + } + else + { + length = text.size() - lastPos; + } + std::string sub = text.substr(lastPos, length); + mTextRows.push_back(sub); + lastPos = pos + 1; + + } while (pos != std::string::npos); + + adjustSize(); + } + + void TextBox::draw(Graphics* graphics) + { + unsigned int i; + + if (mOpaque) + { + graphics->setColor(getBackgroundColor()); + graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); + } + + if (isFocused() && isEditable()) + { + drawCaret(graphics, getFont()->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn)), mCaretRow * getFont()->getHeight()); + } + + graphics->setColor(getForegroundColor()); + graphics->setFont(getFont()); + + for (i = 0; i < mTextRows.size(); i++) + { + // Move the text one pixel so we can have a caret before a letter. + graphics->drawText(mTextRows[i], 1, i * getFont()->getHeight()); + } + } + + void TextBox::drawBorder(Graphics* graphics) + { + int width = getWidth() + getBorderSize() * 2 - 1; + int height = getHeight() + getBorderSize() * 2 - 1; + + graphics->setColor(getBackgroundColor()); + + unsigned int i; + for (i = 0; i < getBorderSize(); ++i) + { + graphics->drawLine(i,i, width - i, i); + graphics->drawLine(i,i + 1, i, height - i - 1); + graphics->drawLine(width - i,i + 1, width - i, height - i); + graphics->drawLine(i,height - i, width - i - 1, height - i); + } + } + + void TextBox::drawCaret(Graphics* graphics, int x, int y) + { + graphics->setColor(getForegroundColor()); + graphics->drawLine(x, getFont()->getHeight() + y, x, y); + } + + void TextBox::mousePressed(MouseEvent& mouseEvent) + { + if (mouseEvent.getButton() == MouseEvent::LEFT) + { + mCaretRow = mouseEvent.getY() / getFont()->getHeight(); + + if (mCaretRow >= (int)mTextRows.size()) + { + mCaretRow = mTextRows.size() - 1; + } + + mCaretColumn = getFont()->getStringIndexAt(mTextRows[mCaretRow], mouseEvent.getX()); + } + } + + void TextBox::mouseDragged(MouseEvent& mouseEvent) + { + mouseEvent.consume(); + } + + void TextBox::keyPressed(KeyEvent& keyEvent) + { + Key key = keyEvent.getKey(); + + if (key.getValue() == Key::LEFT) + { + --mCaretColumn; + if (mCaretColumn < 0) + { + --mCaretRow; + + if (mCaretRow < 0) + { + mCaretRow = 0; + mCaretColumn = 0; + } + else + { + mCaretColumn = mTextRows[mCaretRow].size(); + } + } + } + + else if (key.getValue() == Key::RIGHT) + { + ++mCaretColumn; + if (mCaretColumn > (int)mTextRows[mCaretRow].size()) + { + ++mCaretRow; + + if (mCaretRow >= (int)mTextRows.size()) + { + mCaretRow = mTextRows.size() - 1; + if (mCaretRow < 0) + { + mCaretRow = 0; + } + + mCaretColumn = mTextRows[mCaretRow].size(); + } + else + { + mCaretColumn = 0; + } + } + } + + else if (key.getValue() == Key::DOWN) + { + setCaretRow(mCaretRow + 1); + } + + else if (key.getValue() == Key::UP) + { + setCaretRow(mCaretRow - 1); + } + + else if (key.getValue() == Key::HOME) + { + mCaretColumn = 0; + } + + else if (key.getValue() == Key::END) + { + mCaretColumn = mTextRows[mCaretRow].size(); + } + + else if (key.getValue() == Key::ENTER && mEditable) + { + mTextRows.insert(mTextRows.begin() + mCaretRow + 1, + mTextRows[mCaretRow].substr(mCaretColumn, mTextRows[mCaretRow].size() - mCaretColumn)); + mTextRows[mCaretRow].resize(mCaretColumn); + ++mCaretRow; + mCaretColumn = 0; + } + + else if (key.getValue() == Key::BACKSPACE + && mCaretColumn != 0 + && mEditable) + { + mTextRows[mCaretRow].erase(mCaretColumn - 1, 1); + --mCaretColumn; + } + + else if (key.getValue() == Key::BACKSPACE + && mCaretColumn == 0 + && mCaretRow != 0 + && mEditable) + { + mCaretColumn = mTextRows[mCaretRow - 1].size(); + mTextRows[mCaretRow - 1] += mTextRows[mCaretRow]; + mTextRows.erase(mTextRows.begin() + mCaretRow); + --mCaretRow; + } + + else if (key.getValue() == Key::DELETE + && mCaretColumn < (int)mTextRows[mCaretRow].size() + && mEditable) + { + mTextRows[mCaretRow].erase(mCaretColumn, 1); + } + + else if (key.getValue() == Key::DELETE + && mCaretColumn == (int)mTextRows[mCaretRow].size() + && mCaretRow < ((int)mTextRows.size() - 1) + && mEditable) + { + mTextRows[mCaretRow] += mTextRows[mCaretRow + 1]; + mTextRows.erase(mTextRows.begin() + mCaretRow + 1); + } + + else if(key.getValue() == Key::PAGE_UP) + { + Widget* par = getParent(); + + if (par != NULL) + { + int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight(); + mCaretRow -= rowsPerPage; + + if (mCaretRow < 0) + { + mCaretRow = 0; + } + } + } + + else if(key.getValue() == Key::PAGE_DOWN) + { + Widget* par = getParent(); + + if (par != NULL) + { + int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight(); + mCaretRow += rowsPerPage; + + if (mCaretRow >= (int)mTextRows.size()) + { + mCaretRow = mTextRows.size() - 1; + } + } + } + + else if(key.getValue() == Key::TAB + && mEditable) + { + mTextRows[mCaretRow].insert(mCaretColumn,std::string(" ")); + mCaretColumn += 4; + } + + else if (key.isCharacter() + && mEditable) + { + if(keyEvent.isShiftPressed() && key.isLetter()) + { + mTextRows[mCaretRow].insert(mCaretColumn,std::string(1,(char)(key.getValue() - 32))); + } + else + { + mTextRows[mCaretRow].insert(mCaretColumn,std::string(1,key.getChar())); + } + ++mCaretColumn; + } + + adjustSize(); + scrollToCaret(); + + keyEvent.consume(); + } + + void TextBox::adjustSize() + { + unsigned int i; + int width = 0; + for (i = 0; i < mTextRows.size(); ++i) + { + int w = getFont()->getWidth(mTextRows[i]); + if (width < w) + { + width = w; + } + } + + setWidth(width + 1); + setHeight(getFont()->getHeight() * mTextRows.size()); + } + + void TextBox::setCaretPosition(unsigned int position) + { + int row; + + for (row = 0; row < (int)mTextRows.size(); row++) + { + if (position <= mTextRows[row].size()) + { + mCaretRow = row; + mCaretColumn = position; + return; // we are done + } + else + { + position--; + } + } + + // position beyond end of text + mCaretRow = mTextRows.size() - 1; + mCaretColumn = mTextRows[mCaretRow].size(); + } + + unsigned int TextBox::getCaretPosition() const + { + int pos = 0, row; + + for (row = 0; row < mCaretRow; row++) + { + pos += mTextRows[row].size(); + } + + return pos + mCaretColumn; + } + + void TextBox::setCaretRowColumn(int row, int column) + { + setCaretRow(row); + setCaretColumn(column); + } + + void TextBox::setCaretRow(int row) + { + mCaretRow = row; + + if (mCaretRow >= (int)mTextRows.size()) + { + mCaretRow = mTextRows.size() - 1; + } + + if (mCaretRow < 0) + { + mCaretRow = 0; + } + + setCaretColumn(mCaretColumn); + } + + unsigned int TextBox::getCaretRow() const + { + return mCaretRow; + } + + void TextBox::setCaretColumn(int column) + { + mCaretColumn = column; + + if (mCaretColumn > (int)mTextRows[mCaretRow].size()) + { + mCaretColumn = mTextRows[mCaretRow].size(); + } + + if (mCaretColumn < 0) + { + mCaretColumn = 0; + } + } + + unsigned int TextBox::getCaretColumn() const + { + return mCaretColumn; + } + + const std::string& TextBox::getTextRow(int row) const + { + return mTextRows[row]; + } + + void TextBox::setTextRow(int row, const std::string& text) + { + mTextRows[row] = text; + + if (mCaretRow == row) + { + setCaretColumn(mCaretColumn); + } + + adjustSize(); + } + + unsigned int TextBox::getNumberOfRows() const + { + return mTextRows.size(); + } + + std::string TextBox::getText() const + { + if (mTextRows.size() == 0) + { + return std::string(""); + } + + int i; + std::string text; + + for (i = 0; i < (int)mTextRows.size() - 1; ++i) + { + text = text + mTextRows[i] + "\n"; + } + + text = text + mTextRows[i]; + + return text; + } + + void TextBox::fontChanged() + { + adjustSize(); + } + + void TextBox::scrollToCaret() + { + Widget *par = getParent(); + if (par == NULL) + { + return; + } + + Rectangle scroll; + scroll.x = getFont()->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn)); + scroll.y = getFont()->getHeight() * mCaretRow; + scroll.width = getFont()->getWidth(" "); + scroll.height = getFont()->getHeight() + 2; // add 2 for some extra space + par->showWidgetPart(this,scroll); + } + + void TextBox::setEditable(bool editable) + { + mEditable = editable; + } + + bool TextBox::isEditable() const + { + return mEditable; + } + + void TextBox::addRow(const std::string row) + { + mTextRows.push_back(row); + adjustSize(); + } + + bool TextBox::isOpaque() + { + return mOpaque; + } + + void TextBox::setOpaque(bool opaque) + { + mOpaque = opaque; + } } diff --git a/guisan-dev/src/widgets/textfield.cpp b/guisan-dev/src/widgets/textfield.cpp index 0b9e6516..c87d3486 100644 --- a/guisan-dev/src/widgets/textfield.cpp +++ b/guisan-dev/src/widgets/textfield.cpp @@ -67,225 +67,227 @@ namespace gcn { - TextField::TextField() - { - mCaretPosition = 0; - mXScroll = 0; + TextField::TextField() + { + mCaretPosition = 0; + mXScroll = 0; - setFocusable(true); + setFocusable(true); - addMouseListener(this); - addKeyListener(this); - adjustHeight(); - setBorderSize(1); - } + addMouseListener(this); + addKeyListener(this); + adjustHeight(); + setBorderSize(1); + } - TextField::TextField(const std::string& text) - { - mCaretPosition = 0; - mXScroll = 0; + TextField::TextField(const std::string& text) + { + mCaretPosition = 0; + mXScroll = 0; - mText = text; - adjustSize(); - setBorderSize(1); + mText = text; + adjustSize(); + setBorderSize(1); - setFocusable(true); + setFocusable(true); - addMouseListener(this); - addKeyListener(this); - } + addMouseListener(this); + addKeyListener(this); + } - void TextField::setText(const std::string& text) - { - if (text.size() < mCaretPosition) - { - mCaretPosition = text.size(); - } + void TextField::setText(const std::string& text) + { + if(text.size() < mCaretPosition ) + { + mCaretPosition = text.size(); + } - mText = text; - } + mText = text; + } - void TextField::draw(Graphics* graphics) - { - auto faceColor = getBackgroundColor(); - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); + void TextField::draw(Graphics* graphics) + { + Color faceColor = getBackgroundColor(); + graphics->setColor(faceColor); + graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - if (isFocused()) - { - drawCaret(graphics, getFont()->getWidth(mText.substr(0, mCaretPosition)) - mXScroll); - } + if (isFocused()) + { + drawCaret(graphics, getFont()->getWidth(mText.substr(0, mCaretPosition)) - mXScroll); + } - graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); - graphics->drawText(mText, 1 - mXScroll, 1); - } + graphics->setColor(getForegroundColor()); + graphics->setFont(getFont()); + graphics->drawText(mText, 1 - mXScroll, 1); + } - void TextField::drawBorder(Graphics* graphics) - { - auto faceColor = getBaseColor(); - auto alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + void TextField::drawBorder(Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + int width = getWidth() + getBorderSize() * 2 - 1; + int height = getHeight() + getBorderSize() * 2 - 1; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - for (unsigned int i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i, i, width - i, i); - graphics->drawLine(i, i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i, i + 1, width - i, height - i); - graphics->drawLine(i, height - i, width - i - 1, height - i); - } - } + unsigned int i; + for (i = 0; i < getBorderSize(); ++i) + { + graphics->setColor(shadowColor); + graphics->drawLine(i,i, width - i, i); + graphics->drawLine(i,i + 1, i, height - i - 1); + graphics->setColor(highlightColor); + graphics->drawLine(width - i,i + 1, width - i, height - i); + graphics->drawLine(i,height - i, width - i - 1, height - i); + } + } - void TextField::drawCaret(Graphics* graphics, int x) - { - graphics->setColor(getForegroundColor()); - graphics->drawLine(x, getHeight() - 2, x, 1); - } + void TextField::drawCaret(Graphics* graphics, int x) + { + graphics->setColor(getForegroundColor()); + graphics->drawLine(x, getHeight() - 2, x, 1); + } - void TextField::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mCaretPosition = getFont()->getStringIndexAt(mText, mouseEvent.getX() + mXScroll); - fixScroll(); - } - } + void TextField::mousePressed(MouseEvent& mouseEvent) + { + if (mouseEvent.getButton() == MouseEvent::LEFT) + { + mCaretPosition = getFont()->getStringIndexAt(mText, mouseEvent.getX() + mXScroll); + fixScroll(); + } + } - void TextField::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } + void TextField::mouseDragged(MouseEvent& mouseEvent) + { + mouseEvent.consume(); + } + + void TextField::keyPressed(KeyEvent& keyEvent) + { + Key key = keyEvent.getKey(); - void TextField::keyPressed(KeyEvent& keyEvent) - { - auto key = keyEvent.getKey(); + if (key.getValue() == Key::LEFT && mCaretPosition > 0) + { + --mCaretPosition; + } - if (key.getValue() == Key::LEFT && mCaretPosition > 0) - { - --mCaretPosition; - } + else if (key.getValue() == Key::RIGHT && mCaretPosition < mText.size()) + { + ++mCaretPosition; + } - else if (key.getValue() == Key::RIGHT && mCaretPosition < mText.size()) - { - ++mCaretPosition; - } + else if (key.getValue() == Key::DELETE && mCaretPosition < mText.size()) + { + mText.erase(mCaretPosition, 1); + } - else if (key.getValue() == Key::DELETE && mCaretPosition < mText.size()) - { - mText.erase(mCaretPosition, 1); - } + else if (key.getValue() == Key::BACKSPACE && mCaretPosition > 0) + { + mText.erase(mCaretPosition - 1, 1); + --mCaretPosition; + } - else if (key.getValue() == Key::BACKSPACE && mCaretPosition > 0) - { - mText.erase(mCaretPosition - 1, 1); - --mCaretPosition; - } + else if (key.getValue() == Key::ENTER) + { + generateAction(); + } - else if (key.getValue() == Key::ENTER) - { - generateAction(); - } + else if (key.getValue() == Key::HOME) + { + mCaretPosition = 0; + } - else if (key.getValue() == Key::HOME) - { - mCaretPosition = 0; - } + else if (key.getValue() == Key::END) + { + mCaretPosition = mText.size(); + } - else if (key.getValue() == Key::END) - { - mCaretPosition = mText.size(); - } + else if (key.isCharacter() + && key.getValue() != Key::TAB) + { + if(keyEvent.isShiftPressed() && key.isLetter()) + { + mText.insert(mCaretPosition, std::string(1,(char)(key.getValue() - 32))); + } + else + { + mText.insert(mCaretPosition, std::string(1,(char)key.getValue())); + } + ++mCaretPosition; + } - else if (key.isCharacter() - && key.getValue() != Key::TAB) - { - if (keyEvent.isShiftPressed() && key.isLetter()) - { - mText.insert(mCaretPosition, std::string(1, (char)(key.getValue() - 32))); - } - else - { - mText.insert(mCaretPosition, std::string(1, (char)key.getValue())); - } - ++mCaretPosition; - } + if (key.getValue() != Key::TAB) + { + keyEvent.consume(); + } + + fixScroll(); + } - if (key.getValue() != Key::TAB) - { - keyEvent.consume(); - } + void TextField::adjustSize() + { + setWidth(getFont()->getWidth(mText) + 4); + adjustHeight(); - fixScroll(); - } + fixScroll(); + } - void TextField::adjustSize() - { - setWidth(getFont()->getWidth(mText) + 4); - adjustHeight(); + void TextField::adjustHeight() + { + setHeight(getFont()->getHeight() + 2); + } - fixScroll(); - } + void TextField::fixScroll() + { + if (isFocused()) + { + int caretX = getFont()->getWidth(mText.substr(0, mCaretPosition)); - void TextField::adjustHeight() - { - setHeight(getFont()->getHeight() + 2); - } + if (caretX - mXScroll > getWidth() - 4) + { + mXScroll = caretX - getWidth() + 4; + } + else if (caretX - mXScroll < getFont()->getWidth(" ")) + { + mXScroll = caretX - getFont()->getWidth(" "); - void TextField::fixScroll() - { - if (isFocused()) - { - auto caretX = getFont()->getWidth(mText.substr(0, mCaretPosition)); + if (mXScroll < 0) + { + mXScroll = 0; + } + } + } + } - if (caretX - mXScroll > getWidth() - 4) - { - mXScroll = caretX - getWidth() + 4; - } - else if (caretX - mXScroll < getFont()->getWidth(" ")) - { - mXScroll = caretX - getFont()->getWidth(" "); + void TextField::setCaretPosition(unsigned int position) + { + if (position > mText.size()) + { + mCaretPosition = mText.size(); + } + else + { + mCaretPosition = position; + } - if (mXScroll < 0) - { - mXScroll = 0; - } - } - } - } + fixScroll(); + } - void TextField::setCaretPosition(unsigned int position) - { - if (position > mText.size()) - { - mCaretPosition = mText.size(); - } - else - { - mCaretPosition = position; - } + unsigned int TextField::getCaretPosition() const + { + return mCaretPosition; + } - fixScroll(); - } + const std::string& TextField::getText() const + { + return mText; + } - unsigned int TextField::getCaretPosition() const - { - return mCaretPosition; - } - - const std::string& TextField::getText() const - { - return mText; - } - - void TextField::fontChanged() - { - fixScroll(); - } + void TextField::fontChanged() + { + fixScroll(); + } } diff --git a/guisan-dev/src/widgets/window.cpp b/guisan-dev/src/widgets/window.cpp index 59d134c3..ed796c06 100644 --- a/guisan-dev/src/widgets/window.cpp +++ b/guisan-dev/src/widgets/window.cpp @@ -67,276 +67,281 @@ namespace gcn { - Window::Window() - : mIsMoving(false) - { - setBorderSize(1); - setPadding(2); - setTitleBarHeight(16); - setAlignment(Graphics::CENTER); - addMouseListener(this); - setMovable(true); - Window::setOpaque(true); - } + Window::Window() + :mIsMoving(false) + { + setBorderSize(1); + setPadding(2); + setTitleBarHeight(16); + setAlignment(Graphics::CENTER); + addMouseListener(this); + setMovable(true); + setOpaque(true); + } - Window::Window(const std::string& caption) - : mIsMoving(false) - { - setCaption(caption); - setBorderSize(1); - setPadding(2); - setTitleBarHeight(16); - setAlignment(Graphics::CENTER); - addMouseListener(this); - setMovable(true); - Window::setOpaque(true); - } + Window::Window(const std::string& caption) + :mIsMoving(false) + { + setCaption(caption); + setBorderSize(1); + setPadding(2); + setTitleBarHeight(16); + setAlignment(Graphics::CENTER); + addMouseListener(this); + setMovable(true); + setOpaque(true); + } - Window::~Window() - = default; + Window::~Window() + { + } - void Window::setPadding(unsigned int padding) - { - mPadding = padding; - } + void Window::setPadding(unsigned int padding) + { + mPadding = padding; + } - int Window::getPadding() const - { - return mPadding; - } + unsigned int Window::getPadding() const + { + return mPadding; + } - void Window::setTitleBarHeight(unsigned int height) - { - mTitleBarHeight = height; - } + void Window::setTitleBarHeight(unsigned int height) + { + mTitleBarHeight = height; + } - int Window::getTitleBarHeight() const - { - return mTitleBarHeight; - } + unsigned int Window::getTitleBarHeight() + { + return mTitleBarHeight; + } - void Window::setCaption(const std::string& caption) - { - mCaption = caption; - } + void Window::setCaption(const std::string& caption) + { + mCaption = caption; + } - const std::string& Window::getCaption() const - { - return mCaption; - } + const std::string& Window::getCaption() const + { + return mCaption; + } - void Window::setAlignment(unsigned int alignment) - { - mAlignment = alignment; - } + void Window::setAlignment(unsigned int alignment) + { + mAlignment = alignment; + } - int Window::getAlignment() const - { - return mAlignment; - } + unsigned int Window::getAlignment() const + { + return mAlignment; + } - void Window::draw(Graphics* graphics) - { - auto faceColor = getBaseColor(); - auto alpha = getBaseColor().a; - //int width = getWidth() + getBorderSize() * 2 - 1; - //int height = getHeight() + getBorderSize() * 2 - 1; - Color highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - Color shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + void Window::draw(Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + //int width = getWidth() + getBorderSize() * 2 - 1; + //int height = getHeight() + getBorderSize() * 2 - 1; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - Rectangle d = getChildrenArea(); + Rectangle d = getChildrenArea(); - // Fill the background around the content - graphics->setColor(faceColor); - // Fill top - graphics->fillRectangle(Rectangle(0, 0, getWidth(), d.y - 1)); - // Fill left - graphics->fillRectangle(Rectangle(0, d.y - 1, d.x - 1, getHeight() - d.y + 1)); - // Fill right - graphics->fillRectangle(Rectangle(d.x + d.width + 1, - d.y - 1, - getWidth() - d.x - d.width - 1, - getHeight() - d.y + 1)); - // Fill bottom - graphics->fillRectangle(Rectangle(d.x - 1, - d.y + d.height + 1, - d.width + 2, - getHeight() - d.height - d.y - 1)); + // Fill the background around the content + graphics->setColor(faceColor); + // Fill top + graphics->fillRectangle(Rectangle(0,0,getWidth(),d.y - 1)); + // Fill left + graphics->fillRectangle(Rectangle(0,d.y - 1, d.x - 1, getHeight() - d.y + 1)); + // Fill right + graphics->fillRectangle(Rectangle(d.x + d.width + 1, + d.y - 1, + getWidth() - d.x - d.width - 1, + getHeight() - d.y + 1)); + // Fill bottom + graphics->fillRectangle(Rectangle(d.x - 1, + d.y + d.height + 1, + d.width + 2, + getHeight() - d.height - d.y - 1)); - if (isOpaque()) - { - graphics->fillRectangle(d); - } + if (isOpaque()) + { + graphics->fillRectangle(d); + } - // Construct a rectangle one pixel bigger than the content - d.x -= 1; - d.y -= 1; - d.width += 2; - d.height += 2; + // Construct a rectangle one pixel bigger than the content + d.x -= 1; + d.y -= 1; + d.width += 2; + d.height += 2; - // Draw a border around the content - graphics->setColor(shadowColor); - // Top line - graphics->drawLine(d.x, - d.y, - d.x + d.width - 2, - d.y); + // Draw a border around the content + graphics->setColor(shadowColor); + // Top line + graphics->drawLine(d.x, + d.y, + d.x + d.width - 2, + d.y); - // Left line - graphics->drawLine(d.x, - d.y + 1, - d.x, - d.y + d.height - 1); + // Left line + graphics->drawLine(d.x, + d.y + 1, + d.x, + d.y + d.height - 1); - graphics->setColor(highlightColor); - // Right line - graphics->drawLine(d.x + d.width - 1, - d.y, - d.x + d.width - 1, - d.y + d.height - 2); - // Bottom line - graphics->drawLine(d.x + 1, - d.y + d.height - 1, - d.x + d.width - 1, - d.y + d.height - 1); + graphics->setColor(highlightColor); + // Right line + graphics->drawLine(d.x + d.width - 1, + d.y, + d.x + d.width - 1, + d.y + d.height - 2); + // Bottom line + graphics->drawLine(d.x + 1, + d.y + d.height - 1, + d.x + d.width - 1, + d.y + d.height - 1); - drawChildren(graphics); + drawChildren(graphics); - int textX; + int textX; + int textY; - auto textY = (int(getTitleBarHeight()) - getFont()->getHeight()) / 2; + textY = ((int)getTitleBarHeight() - getFont()->getHeight()) / 2; - switch (getAlignment()) - { - case Graphics::LEFT: - textX = 4; - break; - case Graphics::CENTER: - textX = getWidth() / 2; - break; - case Graphics::RIGHT: - textX = getWidth() - 4; - break; - default: - throw GCN_EXCEPTION("Unknown alignment."); - } + switch (getAlignment()) + { + case Graphics::LEFT: + textX = 4; + break; + case Graphics::CENTER: + textX = getWidth() / 2; + break; + case Graphics::RIGHT: + textX = getWidth() - 4; + break; + default: + throw GCN_EXCEPTION("Unknown alignment."); + } - graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); - graphics->pushClipArea(Rectangle(0, 0, getWidth(), getTitleBarHeight() - 1)); - graphics->drawText(getCaption(), textX, textY, getAlignment()); - graphics->popClipArea(); - } + graphics->setColor(getForegroundColor()); + graphics->setFont(getFont()); + graphics->pushClipArea(Rectangle(0, 0, getWidth(), getTitleBarHeight() - 1)); + graphics->drawText(getCaption(), textX, textY, getAlignment()); + graphics->popClipArea(); + } - void Window::drawBorder(Graphics* graphics) - { - auto faceColor = getBaseColor(); - auto alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + void Window::drawBorder(Graphics* graphics) + { + Color faceColor = getBaseColor(); + Color highlightColor, shadowColor; + int alpha = getBaseColor().a; + int width = getWidth() + getBorderSize() * 2 - 1; + int height = getHeight() + getBorderSize() * 2 - 1; + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - for (unsigned int i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(highlightColor); - graphics->drawLine(i, i, width - i, i); - graphics->drawLine(i, i + 1, i, height - i - 1); - graphics->setColor(shadowColor); - graphics->drawLine(width - i, i + 1, width - i, height - i); - graphics->drawLine(i, height - i, width - i - 1, height - i); - } - } + unsigned int i; + for (i = 0; i < getBorderSize(); ++i) + { + graphics->setColor(highlightColor); + graphics->drawLine(i,i, width - i, i); + graphics->drawLine(i,i + 1, i, height - i - 1); + graphics->setColor(shadowColor); + graphics->drawLine(width - i,i + 1, width - i, height - i); + graphics->drawLine(i,height - i, width - i - 1, height - i); + } + } - void Window::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getSource() != this) - { - return; - } + void Window::mousePressed(MouseEvent& mouseEvent) + { + if (mouseEvent.getSource() != this) + { + return; + } + + if (getParent() != NULL) + { + getParent()->moveToTop(this); + } - if (getParent() != nullptr) - { - getParent()->moveToTop(this); - } + mDragOffsetX = mouseEvent.getX(); + mDragOffsetY = mouseEvent.getY(); + + mIsMoving = mouseEvent.getY() <= (int)mTitleBarHeight; + } - mDragOffsetX = mouseEvent.getX(); - mDragOffsetY = mouseEvent.getY(); + void Window::mouseReleased(MouseEvent& mouseEvent) + { + mIsMoving = false; + } - mIsMoving = mouseEvent.getY() <= (int)mTitleBarHeight; - } + void Window::mouseDragged(MouseEvent& mouseEvent) + { + if (mouseEvent.isConsumed() || mouseEvent.getSource() != this) + { + return; + } + + if (isMovable() && mIsMoving) + { + setPosition(mouseEvent.getX() - mDragOffsetX + getX(), + mouseEvent.getY() - mDragOffsetY + getY()); + } - void Window::mouseReleased(MouseEvent& mouseEvent) - { - mIsMoving = false; - } + mouseEvent.consume(); + } - void Window::mouseDragged(MouseEvent& mouseEvent) - { - if (mouseEvent.isConsumed() || mouseEvent.getSource() != this) - { - return; - } + Rectangle Window::getChildrenArea() + { + return Rectangle(getPadding(), + getTitleBarHeight(), + getWidth() - getPadding() * 2, + getHeight() - getPadding() - getTitleBarHeight()); + } - if (isMovable() && mIsMoving) - { - setPosition(mouseEvent.getX() - mDragOffsetX + getX(), - mouseEvent.getY() - mDragOffsetY + getY()); - } + void Window::setMovable(bool movable) + { + mMovable = movable; + } - mouseEvent.consume(); - } + bool Window::isMovable() const + { + return mMovable; + } - Rectangle Window::getChildrenArea() - { - return { - getPadding(), - getTitleBarHeight(), - getWidth() - getPadding() * 2, - getHeight() - getPadding() - getTitleBarHeight() - }; - } + void Window::setOpaque(bool opaque) + { + mOpaque = opaque; + } - void Window::setMovable(bool movable) - { - mMovable = movable; - } + bool Window::isOpaque() + { + return mOpaque; + } - bool Window::isMovable() const - { - return mMovable; - } + void Window::resizeToContent() + { + WidgetListIterator it; - void Window::setOpaque(bool opaque) - { - mOpaque = opaque; - } + int w = 0, h = 0; + for (it = mWidgets.begin(); it != mWidgets.end(); it++) + { + if ((*it)->getX() + (*it)->getWidth() > w) + { + w = (*it)->getX() + (*it)->getWidth(); + } - bool Window::isOpaque() const - { - return mOpaque; - } + if ((*it)->getY() + (*it)->getHeight() > h) + { + h = (*it)->getY() + (*it)->getHeight(); + } + } - void Window::resizeToContent() - { - auto w = 0, h = 0; - for (auto& mWidget : mWidgets) - { - if (mWidget->getX() + mWidget->getWidth() > w) - { - w = mWidget->getX() + mWidget->getWidth(); - } - - if (mWidget->getY() + mWidget->getHeight() > h) - { - h = mWidget->getY() + mWidget->getHeight(); - } - } - - setSize(w + 2 * getPadding(), h + getPadding() + getTitleBarHeight()); - } + setSize(w + 2* getPadding(), h + getPadding() + getTitleBarHeight()); + } } From 955e03cefc0ac477b89d5772ba59cd59a02ca2a9 Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Sun, 18 Aug 2019 00:05:21 +0200 Subject: [PATCH 3/4] Moved SDL2 initialization to main --- src/main.cpp | 3 +-- src/osdep/amiberry_gfx.cpp | 6 ------ 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 46403486..b0bde388 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -732,8 +732,7 @@ static int real_main2 (int argc, TCHAR **argv) #ifdef USE_SDL1 int ret = SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK); #elif USE_SDL2 - // Some gamepads need this extra time to come up or they wont be detected - int ret = SDL_Init(SDL_INIT_JOYSTICK); // Init everything else later when we need it + int ret = SDL_Init(SDL_INIT_EVERYTHING) != 0; #endif #if defined (USE_SDL1) || defined (USE_SDL2) if (ret < 0) diff --git a/src/osdep/amiberry_gfx.cpp b/src/osdep/amiberry_gfx.cpp index 7b3fdac8..80db21cc 100644 --- a/src/osdep/amiberry_gfx.cpp +++ b/src/osdep/amiberry_gfx.cpp @@ -341,12 +341,6 @@ int graphics_setup(void) } } #elif USE_SDL2 - if (SDL_Init(SDL_INIT_EVERYTHING & ~SDL_INIT_JOYSTICK) != 0) // Everything except joystick, which was initialised earlier - { - SDL_Log("SDL could not initialize! SDL_Error: %s\n", SDL_GetError()); - abort(); - } - sdl_video_driver = SDL_GetCurrentVideoDriver(); Uint32 sdl_window_mode; From 1aafa45e232fbaf174e78ccf3d59c7a9e4ba048e Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Sun, 18 Aug 2019 20:56:42 +0200 Subject: [PATCH 4/4] Fix for incorrect text rendering in some areas of the GUI #496 --- src/osdep/gui/main_window.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/osdep/gui/main_window.cpp b/src/osdep/gui/main_window.cpp index 306b5a31..89492a5a 100644 --- a/src/osdep/gui/main_window.cpp +++ b/src/osdep/gui/main_window.cpp @@ -914,6 +914,7 @@ namespace widgets } #endif gcn::Widget::setGlobalFont(gui_font); + gui_font->setAntiAlias(false); //-------------------------------------------------- // Create main buttons