From 8983c0c5a359e61626590faeabd1c444255a2b68 Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Sat, 10 Dec 2016 11:40:41 +0100 Subject: [PATCH] Changed SDL1 references to SDL2 SDL1 calls to SDL2 ones Changed references to Guichan to Guisan Changed references to renamed paths --- Amiberry/Amiberry/Amiberry.vcxproj | 107 ++- Amiberry/Amiberry/Amiberry.vcxproj.filters | 333 +++++-- src/include/guisan.hpp | 124 +++ src/include/guisan/actionevent.hpp | 105 +++ src/include/guisan/actionlistener.hpp | 98 ++ src/include/guisan/basiccontainer.hpp | 159 ++++ src/include/guisan/cliprectangle.hpp | 111 +++ src/include/guisan/color.hpp | 165 ++++ src/include/guisan/deathlistener.hpp | 96 ++ src/include/guisan/defaultfont.hpp | 107 +++ src/include/guisan/event.hpp | 102 ++ src/include/guisan/exception.hpp | 171 ++++ src/include/guisan/focushandler.hpp | 322 +++++++ src/include/guisan/focuslistener.hpp | 101 ++ src/include/guisan/font.hpp | 125 +++ src/include/guisan/genericinput.hpp | 168 ++++ src/include/guisan/glut.hpp | 72 ++ src/include/guisan/graphics.hpp | 280 ++++++ src/include/guisan/gui.hpp | 402 ++++++++ src/include/guisan/image.hpp | 178 ++++ src/include/guisan/imagefont.hpp | 213 +++++ src/include/guisan/imageloader.hpp | 96 ++ src/include/guisan/input.hpp | 121 +++ src/include/guisan/inputevent.hpp | 140 +++ src/include/guisan/key.hpp | 165 ++++ src/include/guisan/keyevent.hpp | 139 +++ src/include/guisan/keyinput.hpp | 216 +++++ src/include/guisan/keylistener.hpp | 114 +++ src/include/guisan/listmodel.hpp | 98 ++ src/include/guisan/mouseevent.hpp | 178 ++++ src/include/guisan/mouseinput.hpp | 203 ++++ src/include/guisan/mouselistener.hpp | 198 ++++ src/include/guisan/opengl.hpp | 73 ++ src/include/guisan/opengl/openglgraphics.hpp | 141 +++ src/include/guisan/opengl/openglimage.hpp | 171 ++++ .../guisan/opengl/openglsdlimageloader.hpp | 109 +++ src/include/guisan/platform.hpp | 92 ++ src/include/guisan/rectangle.hpp | 118 +++ src/include/guisan/sdl.hpp | 75 ++ src/include/guisan/sdl/sdlgraphics.hpp | 164 ++++ src/include/guisan/sdl/sdlimage.hpp | 120 +++ src/include/guisan/sdl/sdlimageloader.hpp | 86 ++ src/include/guisan/sdl/sdlinput.hpp | 138 +++ src/include/guisan/sdl/sdlpixel.hpp | 274 ++++++ .../guisan/sdl}/sdltruetypefont.hpp | 189 ++-- src/include/guisan/selectionevent.hpp | 91 ++ src/include/guisan/selectionlistener.hpp | 97 ++ src/include/guisan/widget.hpp | 877 ++++++++++++++++++ src/include/guisan/widgetlistener.hpp | 123 +++ src/include/guisan/widgets/button.hpp | 195 ++++ src/include/guisan/widgets/checkbox.hpp | 188 ++++ src/include/guisan/widgets/container.hpp | 177 ++++ src/include/guisan/widgets/dropdown.hpp | 301 ++++++ src/include/guisan/widgets/icon.hpp | 113 +++ src/include/guisan/widgets/imagebutton.hpp | 127 +++ src/include/guisan/widgets/label.hpp | 146 +++ src/include/guisan/widgets/listbox.hpp | 254 +++++ src/include/guisan/widgets/radiobutton.hpp | 225 +++++ src/include/guisan/widgets/scrollarea.hpp | 488 ++++++++++ src/include/guisan/widgets/slider.hpp | 267 ++++++ src/include/guisan/widgets/tab.hpp | 146 +++ src/include/guisan/widgets/tabbedarea.hpp | 226 +++++ src/include/guisan/widgets/textbox.hpp | 264 ++++++ src/include/guisan/widgets/textfield.hpp | 175 ++++ src/include/guisan/widgets/window.hpp | 217 +++++ src/include/guisan/x.hpp | 63 ++ src/osdep/bsdsocket_host.cpp | 2 +- src/osdep/cda_play.cpp | 2 +- src/osdep/gui/CreateFilesysHardfile.cpp | 23 +- src/osdep/gui/EditFilesysHardfile.cpp | 23 +- src/osdep/gui/EditFilesysVirtual.cpp | 34 +- src/osdep/gui/InGameMessage.cpp | 26 +- src/osdep/gui/Navigation.cpp | 8 +- src/osdep/gui/PanelCPU.cpp | 8 +- src/osdep/gui/PanelChipset.cpp | 8 +- src/osdep/gui/PanelConfig.cpp | 10 +- src/osdep/gui/PanelDisplay.cpp | 8 +- src/osdep/gui/PanelFloppy.cpp | 8 +- src/osdep/gui/PanelHD.cpp | 10 +- src/osdep/gui/PanelInput.cpp | 90 +- src/osdep/gui/PanelMisc.cpp | 8 +- src/osdep/gui/PanelPaths.cpp | 8 +- src/osdep/gui/PanelRAM.cpp | 8 +- src/osdep/gui/PanelROM.cpp | 8 +- src/osdep/gui/PanelSavestate.cpp | 10 +- src/osdep/gui/PanelSound.cpp | 10 +- src/osdep/gui/SelectFile.cpp | 25 +- src/osdep/gui/SelectFolder.cpp | 25 +- src/osdep/gui/SelectorEntry.cpp | 8 +- src/osdep/gui/SelectorEntry.hpp | 8 +- src/osdep/gui/ShowMessage.cpp | 23 +- src/osdep/gui/UaeCheckBox.cpp | 10 +- src/osdep/gui/UaeCheckBox.hpp | 10 +- src/osdep/gui/UaeDropDown.cpp | 14 +- src/osdep/gui/UaeDropDown.hpp | 10 +- src/osdep/gui/UaeListBox.cpp | 18 +- src/osdep/gui/UaeListBox.hpp | 12 +- src/osdep/gui/UaeRadioButton.cpp | 10 +- src/osdep/gui/UaeRadioButton.hpp | 10 +- src/osdep/gui/main_window.cpp | 418 ++++++--- src/osdep/gui/sdltruetypefont.cpp | 171 ---- src/osdep/hardfile_pandora.cpp | 2 +- src/osdep/menu/menu_config.cpp | 2 +- src/osdep/pandora.cpp | 2 +- src/osdep/pandora_gfx.cpp | 161 +++- src/osdep/pandora_gfx.h | 10 + src/osdep/pandora_gui.cpp | 35 +- src/osdep/picasso96.cpp | 2 +- src/sounddep/sound_sdl_new.cpp | 2 +- src/threaddep/thread.h | 10 +- 110 files changed, 12236 insertions(+), 791 deletions(-) create mode 100644 src/include/guisan.hpp create mode 100644 src/include/guisan/actionevent.hpp create mode 100644 src/include/guisan/actionlistener.hpp create mode 100644 src/include/guisan/basiccontainer.hpp create mode 100644 src/include/guisan/cliprectangle.hpp create mode 100644 src/include/guisan/color.hpp create mode 100644 src/include/guisan/deathlistener.hpp create mode 100644 src/include/guisan/defaultfont.hpp create mode 100644 src/include/guisan/event.hpp create mode 100644 src/include/guisan/exception.hpp create mode 100644 src/include/guisan/focushandler.hpp create mode 100644 src/include/guisan/focuslistener.hpp create mode 100644 src/include/guisan/font.hpp create mode 100644 src/include/guisan/genericinput.hpp create mode 100644 src/include/guisan/glut.hpp create mode 100644 src/include/guisan/graphics.hpp create mode 100644 src/include/guisan/gui.hpp create mode 100644 src/include/guisan/image.hpp create mode 100644 src/include/guisan/imagefont.hpp create mode 100644 src/include/guisan/imageloader.hpp create mode 100644 src/include/guisan/input.hpp create mode 100644 src/include/guisan/inputevent.hpp create mode 100644 src/include/guisan/key.hpp create mode 100644 src/include/guisan/keyevent.hpp create mode 100644 src/include/guisan/keyinput.hpp create mode 100644 src/include/guisan/keylistener.hpp create mode 100644 src/include/guisan/listmodel.hpp create mode 100644 src/include/guisan/mouseevent.hpp create mode 100644 src/include/guisan/mouseinput.hpp create mode 100644 src/include/guisan/mouselistener.hpp create mode 100644 src/include/guisan/opengl.hpp create mode 100644 src/include/guisan/opengl/openglgraphics.hpp create mode 100644 src/include/guisan/opengl/openglimage.hpp create mode 100644 src/include/guisan/opengl/openglsdlimageloader.hpp create mode 100644 src/include/guisan/platform.hpp create mode 100644 src/include/guisan/rectangle.hpp create mode 100644 src/include/guisan/sdl.hpp create mode 100644 src/include/guisan/sdl/sdlgraphics.hpp create mode 100644 src/include/guisan/sdl/sdlimage.hpp create mode 100644 src/include/guisan/sdl/sdlimageloader.hpp create mode 100644 src/include/guisan/sdl/sdlinput.hpp create mode 100644 src/include/guisan/sdl/sdlpixel.hpp rename src/{osdep/gui => include/guisan/sdl}/sdltruetypefont.hpp (51%) create mode 100644 src/include/guisan/selectionevent.hpp create mode 100644 src/include/guisan/selectionlistener.hpp create mode 100644 src/include/guisan/widget.hpp create mode 100644 src/include/guisan/widgetlistener.hpp create mode 100644 src/include/guisan/widgets/button.hpp create mode 100644 src/include/guisan/widgets/checkbox.hpp create mode 100644 src/include/guisan/widgets/container.hpp create mode 100644 src/include/guisan/widgets/dropdown.hpp create mode 100644 src/include/guisan/widgets/icon.hpp create mode 100644 src/include/guisan/widgets/imagebutton.hpp create mode 100644 src/include/guisan/widgets/label.hpp create mode 100644 src/include/guisan/widgets/listbox.hpp create mode 100644 src/include/guisan/widgets/radiobutton.hpp create mode 100644 src/include/guisan/widgets/scrollarea.hpp create mode 100644 src/include/guisan/widgets/slider.hpp create mode 100644 src/include/guisan/widgets/tab.hpp create mode 100644 src/include/guisan/widgets/tabbedarea.hpp create mode 100644 src/include/guisan/widgets/textbox.hpp create mode 100644 src/include/guisan/widgets/textfield.hpp create mode 100644 src/include/guisan/widgets/window.hpp create mode 100644 src/include/guisan/x.hpp delete mode 100644 src/osdep/gui/sdltruetypefont.cpp create mode 100644 src/osdep/pandora_gfx.h diff --git a/Amiberry/Amiberry/Amiberry.vcxproj b/Amiberry/Amiberry/Amiberry.vcxproj index 4c246898..903b27f9 100644 --- a/Amiberry/Amiberry/Amiberry.vcxproj +++ b/Amiberry/Amiberry/Amiberry.vcxproj @@ -187,8 +187,8 @@ + - @@ -216,7 +216,6 @@ - @@ -243,7 +242,7 @@ - + @@ -371,6 +370,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -401,25 +464,25 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/Amiberry/Amiberry/Amiberry.vcxproj.filters b/Amiberry/Amiberry/Amiberry.vcxproj.filters index 9d0b48d7..f4c7f8f3 100644 --- a/Amiberry/Amiberry/Amiberry.vcxproj.filters +++ b/Amiberry/Amiberry/Amiberry.vcxproj.filters @@ -110,6 +110,18 @@ {08cd7b24-548b-44cc-b832-e5c7a01f2527} + + {b83a0650-3eed-42d1-8fd3-4789521ddc13} + + + {caf30d50-f226-4af8-bd90-ea073cdee161} + + + {0b788fcf-c590-4559-a0eb-a04d50ced350} + + + {f5513d0a-8eab-40b4-b652-48202c4289c1} + @@ -282,12 +294,6 @@ Source files - - Source files\sounddep - - - Source files\machdep - Source files\jit @@ -522,9 +528,6 @@ Source files\osdep\gui - - Source files\osdep\gui - Source files\osdep\gui @@ -555,6 +558,12 @@ Source files\osdep + + Source files\machdep + + + Source files\sounddep + @@ -789,63 +798,6 @@ Header files\include - - Header files\threaddep - - - Header files\sounddep - - - Header files\osdep - - - Header files\osdep - - - Header files\osdep - - - Header files\osdep - - - Header files\osdep - - - Header files\osdep - - - Header files\osdep\gui - - - Header files\osdep\gui - - - Header files\osdep\gui - - - Header files\osdep\gui - - - Header files\osdep\gui - - - Header files\osdep\gui - - - Header files\osdep\gui - - - Header files\machdep - - - Header files\machdep - - - Header files\machdep - - - Header files\machdep - Header files\jit @@ -951,5 +903,254 @@ Header files\archivers\zip + + Header files\include + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan + + + Header files\include\guisan\opengl + + + Header files\include\guisan\opengl + + + Header files\include\guisan\opengl + + + Header files\include\guisan\sdl + + + Header files\include\guisan\sdl + + + Header files\include\guisan\sdl + + + Header files\include\guisan\sdl + + + Header files\include\guisan\sdl + + + Header files\include\guisan\sdl + + + Header files\include\guisan\widgets + + + Header files\include\guisan\widgets + + + Header files\include\guisan\widgets + + + Header files\include\guisan\widgets + + + Header files\include\guisan\widgets + + + Header files\include\guisan\widgets + + + Header files\include\guisan\widgets + + + Header files\include\guisan\widgets + + + Header files\include\guisan\widgets + + + Header files\include\guisan\widgets + + + Header files\include\guisan\widgets + + + Header files\include\guisan\widgets + + + Header files\include\guisan\widgets + + + Header files\include\guisan\widgets + + + Header files\include\guisan\widgets + + + Header files\include\guisan\widgets + + + Header files\osdep\gui + + + Header files\osdep\gui + + + Header files\osdep\gui + + + Header files\osdep\gui + + + Header files\osdep\gui + + + Header files\osdep\gui + + + Header files\osdep + + + Header files\osdep + + + Header files\osdep + + + Header files\osdep + + + Header files\osdep + + + Header files\osdep + + + Header files\osdep + + + Header files\sounddep + + + Header files\threaddep + + + Header files\machdep + + + Header files\machdep + + + Header files\machdep + + + Header files\machdep + \ No newline at end of file diff --git a/src/include/guisan.hpp b/src/include/guisan.hpp new file mode 100644 index 00000000..b6492718 --- /dev/null +++ b/src/include/guisan.hpp @@ -0,0 +1,124 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "guisan/platform.hpp" + +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(); +} + +#endif // end GCN_GUISAN_HPP diff --git a/src/include/guisan/actionevent.hpp b/src/include/guisan/actionevent.hpp new file mode 100644 index 00000000..52a4319c --- /dev/null +++ b/src/include/guisan/actionevent.hpp @@ -0,0 +1,105 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 + +namespace gcn +{ + class Widget; + + /** + * 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); + + /** + * Destructor. + */ + virtual ~ActionEvent(); + + /** + * Gets the id of the event. + * + * @return the id of the event. + */ + const std::string& getId() const; + + protected: + std::string mId; + }; +} + +#endif // GCN_ACTIONEVENT_HPP + diff --git a/src/include/guisan/actionlistener.hpp b/src/include/guisan/actionlistener.hpp new file mode 100644 index 00000000..eff7e9ed --- /dev/null +++ b/src/include/guisan/actionlistener.hpp @@ -0,0 +1,98 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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/actionevent.hpp" +#include "guisan/platform.hpp" + +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: + + /** + * 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; + + }; +} + +#endif // end GCN_ACTIONLISTENER_HPP diff --git a/src/include/guisan/basiccontainer.hpp b/src/include/guisan/basiccontainer.hpp new file mode 100644 index 00000000..6c12c6ba --- /dev/null +++ b/src/include/guisan/basiccontainer.hpp @@ -0,0 +1,159 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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/deathlistener.hpp" +#include "guisan/platform.hpp" +#include "guisan/widget.hpp" + +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(); + + + // Inherited from Widget + + virtual void moveToTop(Widget* widget); + + virtual void moveToBottom(Widget* widget); + + virtual Rectangle getChildrenArea(); + + virtual void focusNext(); + + virtual void focusPrevious(); + + virtual void logic(); + + virtual void _setFocusHandler(FocusHandler* focusHandler); + + void setInternalFocusHandler(FocusHandler* focusHandler); + + virtual void showWidgetPart(Widget* widget, Rectangle area); + + virtual Widget *getWidgetAt(int x, int y); + + + // Inherited from DeathListener + + virtual void death(const Event& event); + + 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); + + /** + * 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); + + /** + * 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); + + typedef std::list WidgetList; + typedef WidgetList::iterator WidgetListIterator; + typedef WidgetList::reverse_iterator WidgetListReverseIterator; + + WidgetList mWidgets; + }; +} + +#endif // end GCN_BASICCONTAINER_HPP diff --git a/src/include/guisan/cliprectangle.hpp b/src/include/guisan/cliprectangle.hpp new file mode 100644 index 00000000..dc1190a5 --- /dev/null +++ b/src/include/guisan/cliprectangle.hpp @@ -0,0 +1,111 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 )\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 )\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/event.hpp" +#include "guisan/platform.hpp" + +namespace gcn +{ + /** + * Listener of death events from Widgets. To be able to + * listen for deaths you must make a class which inherits + * from this class and implements the death function. + * + * @see Widget::addDeathListener + * @author Olof Naessén + * @since 0.6.0 + */ + class GCN_CORE_DECLSPEC DeathListener + { + public: + + /** + * 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; + + }; +} + +#endif // end GCN_DEATHLISTENER_HPP diff --git a/src/include/guisan/defaultfont.hpp b/src/include/guisan/defaultfont.hpp new file mode 100644 index 00000000..544ae0f8 --- /dev/null +++ b/src/include/guisan/defaultfont.hpp @@ -0,0 +1,107 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 )\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 )\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" + + +#ifdef _MSC_VER +#if _MSC_VER <= 1200 +#define __FUNCTION__ "?" +#endif +#endif + +/* + * A macro to be used when throwing exceptions. + * What it basicly does is that it creates a new exception + * and automatically sets the filename and line number where + * the exception occured. + */ +#define GCN_EXCEPTION(mess) gcn::Exception(mess, \ + __FUNCTION__, \ + __FILE__, \ + __LINE__) + +namespace gcn +{ + + /** + * An exception containing a message, a file and a line number. + * Guichan will only throw exceptions of this class. You can use + * this class for your own exceptions. A nifty feature of the + * excpetion class is that it can tell you from which line and + * file it was thrown. To make things easier when throwing + * exceptions there exists a macro for creating exceptions + * which automatically sets the filename and line number. + * + * EXAMPLE: @code + * throw GCN_EXCEPTION("my error message"); + * @endcode + */ + class GCN_CORE_DECLSPEC Exception + { + public: + + /** + * Constructor. + */ + Exception(); + + /** + * Constructor. + * + * @param message the error message. + */ + Exception(const std::string& message); + + /** + * Constructor. + * + * NOTE: Don't use this constructor. Use the GCN_EXCEPTION macro instead. + * + * @param message the error message. + * @param function the function name. + * @param filename the name of the file. + * @param line the line number. + */ + Exception(const std::string& message, + const std::string& function, + const std::string& filename, + int line); + + /** + * Gets the function name in which the exception was thrown. + * + * @return the function name in which the exception was thrown. + */ + const std::string& getFunction() const; + + /** + * Gets the error message of the exception. + * + * @return the error message. + */ + const std::string& getMessage() const; + + /** + * Gets the filename in which the exceptions was thrown. + * + * @return the filename in which the exception was thrown. + */ + const std::string& getFilename() const; + + /** + * Gets the line number of the line where the exception was thrown. + * + * @return the line number of the line where the exception was thrown. + */ + int getLine() const; + + protected: + std::string mFunction; + std::string mMessage; + std::string mFilename; + int mLine; + }; +} + +#endif // end GCN_EXCEPTION_HPP + +/* + * "Final Fantasy XI is the BEST!... It's even better then water!" + * - Astrolite + * I believe it's WoW now days. + */ diff --git a/src/include/guisan/focushandler.hpp b/src/include/guisan/focushandler.hpp new file mode 100644 index 00000000..f9fdd90b --- /dev/null +++ b/src/include/guisan/focushandler.hpp @@ -0,0 +1,322 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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/event.hpp" +#include "guisan/platform.hpp" + +namespace gcn +{ + 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: + + /** + * Constructor. + */ + FocusHandler(); + + /** + * 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 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); + + /** + * 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); + + /** + * 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 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 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; + + /** + * 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); + + /** + * 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 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(); + + /** + * 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(); + + /** + * 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(); + + /** + * 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(); + + /** + * 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(); + + /** + * 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); + + /** + * 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; + + Widget* mFocusedWidget; + Widget* mModalFocusedWidget; + Widget* mModalMouseInputFocusedWidget; + + Widget* mDraggedWidget; + Widget* mLastWidgetWithMouse; + Widget* mLastWidgetWithModalFocus; + Widget* mLastWidgetWithModalMouseInputFocus; + Widget* mLastWidgetPressed; + }; +} + +#endif // end GCN_FOCUSHANDLER_HPP diff --git a/src/include/guisan/focuslistener.hpp b/src/include/guisan/focuslistener.hpp new file mode 100644 index 00000000..e57a8e87 --- /dev/null +++ b/src/include/guisan/focuslistener.hpp @@ -0,0 +1,101 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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/event.hpp" +#include "guisan/platform.hpp" + +namespace gcn +{ + /** + * Listener of focus events from Widgets. To be able to listen for + * focus events you must make a class which inherits from this class + * and implements it's functions. + * + * @see Widget::addFocusListener + * @author Olof Naessén + * @since 0.7.0 + */ + class GCN_CORE_DECLSPEC FocusListener + { + public: + + /** + * Destructor. + */ + virtual ~FocusListener() { } + + /** + * 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) { }; + }; +} + +#endif // end GCN_FOCUSLISTENER_HPP diff --git a/src/include/guisan/font.hpp b/src/include/guisan/font.hpp new file mode 100644 index 00000000..7ea02cd2 --- /dev/null +++ b/src/include/guisan/font.hpp @@ -0,0 +1,125 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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" + +namespace gcn +{ + 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: + + /** + * 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 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); + + /** + * 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/src/include/guisan/genericinput.hpp b/src/include/guisan/genericinput.hpp new file mode 100644 index 00000000..54e28d1a --- /dev/null +++ b/src/include/guisan/genericinput.hpp @@ -0,0 +1,168 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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/input.hpp" +#include "guisan/keyinput.hpp" +#include "guisan/mouseinput.hpp" +#include "guisan/platform.hpp" + +namespace gcn +{ + class Key; + + /** + * Generic input which can be used with any backend. + */ + class GCN_CORE_DECLSPEC GenericInput: public Input + { + public: + + /** + * 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 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 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 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); + + + // Inherited from Input + + virtual bool isKeyQueueEmpty(); + + virtual KeyInput dequeueKeyInput(); + + virtual bool isMouseQueueEmpty(); + + virtual MouseInput dequeueMouseInput(); + + virtual void _pollInput(); + + protected: + std::queue mKeyInputQueue; + std::queue mMouseInputQueue; + }; +} + +#endif // end GCN_INPUT_HPP diff --git a/src/include/guisan/glut.hpp b/src/include/guisan/glut.hpp new file mode 100644 index 00000000..59c5647d --- /dev/null +++ b/src/include/guisan/glut.hpp @@ -0,0 +1,72 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 "platform.hpp" + +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/src/include/guisan/graphics.hpp b/src/include/guisan/graphics.hpp new file mode 100644 index 00000000..b673dbd8 --- /dev/null +++ b/src/include/guisan/graphics.hpp @@ -0,0 +1,280 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 + +#include "guisan/cliprectangle.hpp" +#include "guisan/platform.hpp" + +namespace gcn +{ + 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(); + + 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() { } + + /** + * 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); + + /** + * 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(); + + /** + * 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; + + /** + * 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 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; + + /** + * 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); + + /** + * 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 + }; + + protected: + std::stack mClipStack; + Font* mFont; + }; +} + +#endif // end GCN_GRAPHICS_HPP + +/* + * yakslem - "little cake on cake, but that's the fall" + * finalman - "skall jag skriva det?" + * yakslem - "ja, varfor inte?" + */ + diff --git a/src/include/guisan/gui.hpp b/src/include/guisan/gui.hpp new file mode 100644 index 00000000..5323173e --- /dev/null +++ b/src/include/guisan/gui.hpp @@ -0,0 +1,402 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 + +#include "guisan/keyevent.hpp" +#include "guisan/mouseevent.hpp" +#include "guisan/mouseinput.hpp" +#include "guisan/platform.hpp" + +namespace gcn +{ + 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. + */ + + /** + * 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(); + + /** + * Destructor. + */ + virtual ~Gui(); + + /** + * 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; + + /** + * 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; + + /** + * 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; + + /** + * 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(); + + /** + * 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); + + /** + * 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); + + /** + * 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(); + + /** + * 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 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 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 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 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(); + + /** + * 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. + + * @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); + + /** + * 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 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; + + bool mTabbing; + + typedef std::list KeyListenerList; + typedef KeyListenerList::iterator KeyListenerListIterator; + + KeyListenerList mKeyListeners; + + // 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; + + // Widget with mouse stack + std::deque mWidgetWithMouseQueue; + }; +} + +#endif // end GCN_GUI_HPP + +/* yakslem - "Women, it's a constant struggle." + * finalman - "Yes, but sometimes they succeed with their guesses." + * yaklsem - "...eh...I was talking about love." + * finalman - "Oh...ok..." + * An awkward silence followed. + */ diff --git a/src/include/guisan/image.hpp b/src/include/guisan/image.hpp new file mode 100644 index 00000000..37244130 --- /dev/null +++ b/src/include/guisan/image.hpp @@ -0,0 +1,178 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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" + +namespace gcn +{ + 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: + + /** + * Constructor. + */ + 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); + + /** + * 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); + + /** + * Frees an image. + */ + virtual void free() = 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 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; + + /** + * 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; + }; +} + +#endif // end GCN_IMAGE_HPP diff --git a/src/include/guisan/imagefont.hpp b/src/include/guisan/imagefont.hpp new file mode 100644 index 00000000..fb148b08 --- /dev/null +++ b/src/include/guisan/imagefont.hpp @@ -0,0 +1,213 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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/font.hpp" +#include "guisan/platform.hpp" +#include "guisan/rectangle.hpp" + +namespace gcn +{ + 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\ +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: + + /** + * 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); + + /** + * 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); + + /** + * 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(); + + /** + * 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 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 + + virtual int getWidth(const std::string& text) const; + + virtual void drawString(Graphics* graphics, const std::string& text, + int x, int y); + + virtual int getHeight() const; + + virtual int getStringIndexAt(const std::string& text, int x); + + 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; + }; +} + +#endif // end GCN_IMAGEFONT_HPP diff --git a/src/include/guisan/imageloader.hpp b/src/include/guisan/imageloader.hpp new file mode 100644 index 00000000..a53c9b19 --- /dev/null +++ b/src/include/guisan/imageloader.hpp @@ -0,0 +1,96 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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" + +namespace gcn +{ + 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: + + /** + * 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; + }; +} + +#endif // end GCN_IMAGELOADER_HPP diff --git a/src/include/guisan/input.hpp b/src/include/guisan/input.hpp new file mode 100644 index 00000000..33b15b99 --- /dev/null +++ b/src/include/guisan/input.hpp @@ -0,0 +1,121 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 )\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 )\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 )\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 )\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 )\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 )\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" + +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() { } + + /** + * 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/src/include/guisan/mouseevent.hpp b/src/include/guisan/mouseevent.hpp new file mode 100644 index 00000000..e0ed0db2 --- /dev/null +++ b/src/include/guisan/mouseevent.hpp @@ -0,0 +1,178 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 )\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 )\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 )\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 + +#include "guisan/platform.hpp" + +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/src/include/guisan/opengl/openglgraphics.hpp b/src/include/guisan/opengl/openglgraphics.hpp new file mode 100644 index 00000000..0456234f --- /dev/null +++ b/src/include/guisan/opengl/openglgraphics.hpp @@ -0,0 +1,141 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 )\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 +#if defined (DELETE) +#undef DELETE +#endif +#endif + +#if defined (__APPLE__) +#include +#else +#include +#endif + +#include + +#include "guisan/color.hpp" +#include "guisan/platform.hpp" +#include "guisan/image.hpp" + +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. + * @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 autoFree true if the surface should automatically be deleted. + */ + OpenGLImage(GLuint textureHandle, int width, int height, bool autoFree); + + /** + * Destructor. + */ + virtual ~OpenGLImage(); + + /** + * Gets the OpenGL texture handle for the image. + * + * @return the OpenGL texture handle for the image. + */ + + virtual GLuint getTextureHandle() 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; + + + // Inherited from Image + + virtual void free(); + + virtual int getWidth() const; + + virtual int getHeight() const; + + virtual Color getPixel(int x, int y); + + virtual void putPixel(int x, int y, const Color& color); + + virtual void convertToDisplayFormat(); + + protected: + GLuint mTextureHandle; + unsigned int* mPixels; + bool mAutoFree; + int mWidth; + int mHeight; + int mTextureWidth; + int mTextureHeight; + + }; +} + +#endif // end GCN_OPENGLIMAGE_HPP diff --git a/src/include/guisan/opengl/openglsdlimageloader.hpp b/src/include/guisan/opengl/openglsdlimageloader.hpp new file mode 100644 index 00000000..a4e0dfff --- /dev/null +++ b/src/include/guisan/opengl/openglsdlimageloader.hpp @@ -0,0 +1,109 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 +#include + +namespace gcn +{ + class Image; + + /** + * OpenGL ImageLoader that loads images with SDL. + */ + class OpenGLSDLImageLoader : public SDLImageLoader + { + public: + + // Inherited from ImageLoader + + virtual Image* load(const std::string& filename, + bool convertToDisplayFormat = true) + { + SDL_Surface *loadedSurface = loadSDLSurface(filename); + + if (loadedSurface == NULL) + { + throw GCN_EXCEPTION( + std::string("Unable to load image file: ") + filename); + } + + SDL_Surface *surface = convertToStandardFormat(loadedSurface); + SDL_FreeSurface(loadedSurface); + + 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); + + return image; + } + }; +} + +#endif // end GCN_OPENGLSDLIMAGELOADER_HPP diff --git a/src/include/guisan/platform.hpp b/src/include/guisan/platform.hpp new file mode 100644 index 00000000..b7a7609f --- /dev/null +++ b/src/include/guisan/platform.hpp @@ -0,0 +1,92 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 )\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 )\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 +#include +#include + +#include "platform.hpp" + +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/src/include/guisan/sdl/sdlgraphics.hpp b/src/include/guisan/sdl/sdlgraphics.hpp new file mode 100644 index 00000000..8bd1231e --- /dev/null +++ b/src/include/guisan/sdl/sdlgraphics.hpp @@ -0,0 +1,164 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 )\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/color.hpp" +#include "guisan/platform.hpp" +#include "guisan/image.hpp" + +namespace gcn +{ + /** + * SDL implementation of Image. + */ + class GCN_EXTENSION_DECLSPEC SDLImage : public Image + { + public: + /** + * Constructor. Load an image from an SDL surface. + * + * NOTE: The functions getPixel and putPixel are only guaranteed to work + * before an image has been converted to display format. + * + * @param surface the surface from which to load. + * @param autoFree true if the surface should automatically be deleted. + */ + SDLImage(SDL_Surface* surface, bool autoFree); + + /** + * Destructor. + */ + virtual ~SDLImage(); + + /** + * Gets the SDL surface for the image. + * + * @return the SDL surface for the image. + */ + virtual SDL_Surface* getSurface() const; + + + // Inherited from Image + + virtual void free(); + + virtual int getWidth() const; + + virtual int getHeight() const; + + virtual Color getPixel(int x, int y); + + virtual void putPixel(int x, int y, const Color& color); + + virtual void convertToDisplayFormat(); + + protected: + SDL_Surface* mSurface; + bool mAutoFree; + }; +} + +#endif // end GCN_SDLIMAGE_HPP diff --git a/src/include/guisan/sdl/sdlimageloader.hpp b/src/include/guisan/sdl/sdlimageloader.hpp new file mode 100644 index 00000000..5d4455f1 --- /dev/null +++ b/src/include/guisan/sdl/sdlimageloader.hpp @@ -0,0 +1,86 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 )\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 "SDL.h" + +#include "guisan/input.hpp" +#include "guisan/keyinput.hpp" +#include "guisan/mouseinput.hpp" +#include "guisan/platform.hpp" + +namespace gcn +{ + class Key; + + /** + * SDL implementation of Input. + */ + class GCN_EXTENSION_DECLSPEC SDLInput : public Input + { + public: + + /** + * Constructor. + */ + SDLInput(); + + /** + * Pushes an SDL event. It should be called at least once per frame to + * update input with user input. + * + * @param event an event from SDL. + */ + virtual void pushInput(SDL_Event event); + + /** + * Polls all input. It exists for input driver compatibility. If you + * only use SDL and plan sticking with SDL you can safely ignore this + * function as it in the SDL case does nothing. + */ + virtual void _pollInput() { } + + + // Inherited from Input + + virtual bool isKeyQueueEmpty(); + + virtual KeyInput dequeueKeyInput(); + + virtual bool isMouseQueueEmpty(); + + virtual MouseInput dequeueMouseInput(); + + protected: + /** + * Converts a mouse button from SDL to a Guichan mouse button + * representation. + * + * @param button an SDL mouse button. + * @return a Guichan mouse button. + */ + int convertMouseButton(int button); + + /** + * Converts an SDL event key to a key value. + * + * @param event an SDL event with a key to convert. + * @return a key value. + * @see Key + */ + int convertKeyCharacter(SDL_Event event); + + std::queue mKeyInputQueue; + std::queue mMouseInputQueue; + + bool mMouseDown; + bool mMouseInWindow; + }; +} + +#endif // end GCN_SDLINPUT_HPP diff --git a/src/include/guisan/sdl/sdlpixel.hpp b/src/include/guisan/sdl/sdlpixel.hpp new file mode 100644 index 00000000..0812bc0a --- /dev/null +++ b/src/include/guisan/sdl/sdlpixel.hpp @@ -0,0 +1,274 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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(]1uformat->BytesPerPixel; + + SDL_LockSurface(surface); + + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + + unsigned int color = 0; + + switch(bpp) + { + case 1: + color = *p; + break; + + case 2: + color = *(Uint16 *)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; + + case 4: + color = *(Uint32 *)p; + break; + + } + + unsigned char r,g,b,a; + + SDL_GetRGBA(color, surface->format, &r, &g, &b, &a); + SDL_UnlockSurface(surface); + + return Color(r,g,b,a); + } + + /** + * 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; + + SDL_LockSurface(surface); + + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + + Uint32 pixel = SDL_MapRGB(surface->format, color.r, color.g, color.b); + + switch(bpp) + { + case 1: + *p = pixel; + break; + + case 2: + *(Uint16 *)p = pixel; + break; + + 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; + + case 4: + *(Uint32 *)p = pixel; + break; + } + + SDL_UnlockSurface(surface); + } + + /** + * 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 (b & 0xff) | (g & 0xff00) | (r & 0xff0000); + } + + /** + * 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; + + return (unsigned short)((b & f->Rmask) | (g & f->Gmask) | (r & f->Bmask)); + } + + /* + 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; + */ + + /** + * 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; + + SDL_LockSurface(surface); + + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + + Uint32 pixel = SDL_MapRGB(surface->format, color.r, color.g, color.b); + + switch(bpp) + { + case 1: + *p = pixel; + break; + + case 2: + *(Uint16 *)p = SDLAlpha16(pixel, *(Uint32 *)p, color.a, surface->format); + 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; + + 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; + + 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/src/osdep/gui/sdltruetypefont.hpp b/src/include/guisan/sdl/sdltruetypefont.hpp similarity index 51% rename from src/osdep/gui/sdltruetypefont.hpp rename to src/include/guisan/sdl/sdltruetypefont.hpp index f0ccae20..c2061028 100644 --- a/src/osdep/gui/sdltruetypefont.hpp +++ b/src/include/guisan/sdl/sdltruetypefont.hpp @@ -47,109 +47,106 @@ #include #include -#include +#include -#include "guichan/font.hpp" -#include "guichan/platform.hpp" +#include "guisan/font.hpp" +#include "guisan/platform.hpp" namespace gcn { -class Graphics; -namespace contrib -{ + class Graphics; + + /** + * SDL True Type Font implementation of Font. It uses the SDL_ttf library + * to display True Type Fonts with SDL. + * + * NOTE: You must initialize the SDL_ttf library before using this + * class. Also, remember to call the SDL_ttf libraries quit + * function. + * + * @author Walluce Pinkham + * @author Olof Naessén + */ + class GCN_EXTENSION_DECLSPEC SDLTrueTypeFont: public Font + { + public: -/** - * SDL True Type Font implementation of Font. It uses the SDL_ttf library - * to display True Type Fonts with SDL. - * - * NOTE: You must initialize the SDL_ttf library before using this - * class. Also, remember to call the SDL_ttf libraries quit - * function. - * - * @author Walluce Pinkham - * @author Olof Naessén - */ -class GCN_EXTENSION_DECLSPEC SDLTrueTypeFont: public Font -{ -public: + /** + * Constructor. + * + * @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); - /** - * Constructor. - * - * @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); + /** + * 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); + + /** + * 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); - /** - * 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); - - /** - * 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); - - /** - * Gets the spacing between letters in pixels. - * - * @return the spacing. - */ - virtual int getGlyphSpacing(); - - /** - * Sets the use of anti aliasing.. - * - * @param antaAlias true for use of antia aliasing. - */ - virtual void setAntiAlias(bool antiAlias); - - /** - * Checks if anti aliasing is used. - * - * @return true if anti aliasing is used. - */ - virtual bool isAntiAlias(); - - - // Inherited from Font - - virtual int getWidth(const std::string& text) const; - - virtual int getHeight() const; - - virtual void drawString(Graphics* graphics, const std::string& text, int x, int y); - -protected: - TTF_Font *mFont; - - int mHeight; - int mGlyphSpacing; - int mRowSpacing; - - std::string mFilename; - bool mAntiAlias; -}; -} + /** + * Gets the spacing between letters in pixels. + * + * @return the spacing. + */ + virtual int getGlyphSpacing(); + + /** + * Sets the use of anti aliasing.. + * + * @param antaAlias true for use of antia aliasing. + */ + virtual void setAntiAlias(bool antiAlias); + + /** + * Checks if anti aliasing is used. + * + * @return true if anti aliasing is used. + */ + virtual bool isAntiAlias(); + + + // Inherited from Font + + virtual int getWidth(const std::string& text) const; + + virtual int getHeight() const; + + virtual void drawString(Graphics* graphics, const std::string& text, int x, int y); + + protected: + TTF_Font *mFont; + + int mHeight; + int mGlyphSpacing; + int mRowSpacing; + + std::string mFilename; + bool mAntiAlias; + }; } #endif diff --git a/src/include/guisan/selectionevent.hpp b/src/include/guisan/selectionevent.hpp new file mode 100644 index 00000000..47646084 --- /dev/null +++ b/src/include/guisan/selectionevent.hpp @@ -0,0 +1,91 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 )\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/selectionevent.hpp" +#include "guisan/platform.hpp" + +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: + + /** + * 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) { }; + + }; +} + +#endif // end GCN_SELECTIONLISTENER_HPP diff --git a/src/include/guisan/widget.hpp b/src/include/guisan/widget.hpp new file mode 100644 index 00000000..eb28f596 --- /dev/null +++ b/src/include/guisan/widget.hpp @@ -0,0 +1,877 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 + +#include "guisan/color.hpp" +#include "guisan/rectangle.hpp" + +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. + */ + 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 + +/* + * yakslem - "I have a really great idea! Why not have an + * interesting and funny quote or story at the + * end of every source file." + * finalman - "Yeah - good idea! .... do you know any funny + * quotes?" + * yakslem - "Well.. I guess not. I just thought it would be + * fun to tell funny quotes." + * finalman - "That's not a very funny quote. But i believe + * pointless quotes are funny in their own pointless + * way." + * yakslem - "...eh...ok..." + */ diff --git a/src/include/guisan/widgetlistener.hpp b/src/include/guisan/widgetlistener.hpp new file mode 100644 index 00000000..d63a7f16 --- /dev/null +++ b/src/include/guisan/widgetlistener.hpp @@ -0,0 +1,123 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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/event.hpp" +#include "guisan/platform.hpp" + +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: + + /** + * 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 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 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/src/include/guisan/widgets/button.hpp b/src/include/guisan/widgets/button.hpp new file mode 100644 index 00000000..d120302e --- /dev/null +++ b/src/include/guisan/widgets/button.hpp @@ -0,0 +1,195 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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/focuslistener.hpp" +#include "guisan/keylistener.hpp" +#include "guisan/mouseevent.hpp" +#include "guisan/mouselistener.hpp" +#include "guisan/platform.hpp" +#include "guisan/widget.hpp" + +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(); + + /** + * 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); + + /** + * 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); + + /** + * 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); + + /** + * 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. + */ + void adjustSize(); + + /** + * Checks if the button is pressed down. Useful when drawing. + * + * @return true if the button is pressed down. + */ + bool isPressed() const; + + + //Inherited from Widget + + virtual void draw(Graphics* graphics); + + virtual void drawBorder(Graphics* graphics); + + + // Inherited from FocusListener + + virtual void focusLost(const Event& event); + + + // Inherited from MouseListener + + virtual void mousePressed(MouseEvent& mouseEvent); + + virtual void mouseReleased(MouseEvent& mouseEvent); + + virtual void mouseEntered(MouseEvent& mouseEvent); + + virtual void mouseExited(MouseEvent& mouseEvent); + + virtual void mouseDragged(MouseEvent& mouseEvent); + + + // Inherited from KeyListener + + virtual void keyPressed(KeyEvent& keyEvent); + + virtual void keyReleased(KeyEvent& keyEvent); + + protected: + std::string mCaption; + bool mHasMouse; + bool mKeyPressed; + bool mMousePressed; + unsigned int mAlignment; + unsigned int mSpacing; + }; +} + +#endif // end GCN_BUTTON_HPP diff --git a/src/include/guisan/widgets/checkbox.hpp b/src/include/guisan/widgets/checkbox.hpp new file mode 100644 index 00000000..0820f7d1 --- /dev/null +++ b/src/include/guisan/widgets/checkbox.hpp @@ -0,0 +1,188 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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/keylistener.hpp" +#include "guisan/mouselistener.hpp" +#include "guisan/platform.hpp" +#include "guisan/widget.hpp" + +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: + + /** + * Contructor. + */ + CheckBox(); + + /** + * Constructor. The check box will be automatically resized + * to fit it's caption. + * + * @param caption The caption of the check box. + * @param marked True if the check box is selected, false otherwise. + */ + CheckBox(const std::string &caption, bool selected = false); + + /** + * 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; + + /** + * 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; + + /** + * 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(); + + + // Inherited from Widget + + virtual void draw(Graphics* graphics); + + virtual void drawBorder(Graphics* graphics); + + + // Inherited from KeyListener + + virtual void keyPressed(KeyEvent& keyEvent); + + + // Inherited from MouseListener + + virtual void mouseClicked(MouseEvent& mouseEvent); + + 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); + + /** + * 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; + + /** + * Holds the caption of the check box. + */ + std::string mCaption; + }; +} + +#endif // end GCN_CHECKBOX_HPP diff --git a/src/include/guisan/widgets/container.hpp b/src/include/guisan/widgets/container.hpp new file mode 100644 index 00000000..ad6c0bc9 --- /dev/null +++ b/src/include/guisan/widgets/container.hpp @@ -0,0 +1,177 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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/basiccontainer.hpp" +#include "guisan/graphics.hpp" +#include "guisan/platform.hpp" + +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: + + /** + * Constructor. A container is opauqe as default, if you want a + * none opaque container call setQpaque(false). + * + * @see setOpaque, isOpaque + */ + 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 + */ + void setOpaque(bool opaque); + + /** + * 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 + */ + 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); + + /** + * 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 + */ + 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 + */ + virtual Widget* findWidgetById(const std::string &id); + + + // Inherited from Widget + + virtual void draw(Graphics* graphics); + + virtual void drawBorder(Graphics* graphics); + + protected: + /** + * True if the container is opaque, false otherwise. + */ + bool mOpaque; + }; +} + +#endif // end GCN_CONTAINER_HPP diff --git a/src/include/guisan/widgets/dropdown.hpp b/src/include/guisan/widgets/dropdown.hpp new file mode 100644 index 00000000..89edc525 --- /dev/null +++ b/src/include/guisan/widgets/dropdown.hpp @@ -0,0 +1,301 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 SelectionListenerList; + + /** + * The selection listener's of the drop down. + */ + SelectionListenerList mSelectionListeners; + + /** + * Typedef. + */ + typedef SelectionListenerList::iterator SelectionListenerIterator; + + }; +} + +#endif // end GCN_DROPDOWN_HPP diff --git a/src/include/guisan/widgets/icon.hpp b/src/include/guisan/widgets/icon.hpp new file mode 100644 index 00000000..63604145 --- /dev/null +++ b/src/include/guisan/widgets/icon.hpp @@ -0,0 +1,113 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 )\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 )\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/widget.hpp" + +namespace gcn +{ + /** + * 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. + */ + Label(const std::string& caption); + + /** + * 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 + */ + void setCaption(const std::string& caption); + + /** + * 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 + */ + unsigned int getAlignment() const; + + /** + * Adjusts the label's size to fit the caption size. + */ + void adjustSize(); + + + // Inherited from Widget + + virtual void draw(Graphics* graphics); + + virtual void drawBorder(Graphics* graphics); + + protected: + /** + * Holds the caption of the label. + */ + std::string mCaption; + + /** + * Holds the alignment of the caption. + */ + unsigned int mAlignment; + }; +} + +#endif // end GCN_LABEL_HPP diff --git a/src/include/guisan/widgets/listbox.hpp b/src/include/guisan/widgets/listbox.hpp new file mode 100644 index 00000000..fc0e0f0b --- /dev/null +++ b/src/include/guisan/widgets/listbox.hpp @@ -0,0 +1,254 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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/keylistener.hpp" +#include "guisan/listmodel.hpp" +#include "guisan/mouselistener.hpp" +#include "guisan/platform.hpp" +#include "guisan/widget.hpp" + +namespace gcn +{ + 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(); + + /** + * Constructor. + * + * @param listModel the list model to use. + */ + ListBox(ListModel *listModel); + + /** + * 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; + + /** + * 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); + + /** + * 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(); + + /** + * 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); + + /** + * 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); + + + // Inherited from Widget + + virtual void draw(Graphics* graphics); + + virtual void drawBorder(Graphics* graphics); + + virtual void logic(); + + + // Inherited from KeyListener + + virtual void keyPressed(KeyEvent& keyEvent); + + + // Inherited from MouseListener + + virtual void mousePressed(MouseEvent& mouseEvent); + + virtual void mouseWheelMovedUp(MouseEvent& mouseEvent); + + virtual void mouseWheelMovedDown(MouseEvent& mouseEvent); + + virtual void mouseDragged(MouseEvent& mouseEvent); + + + 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; + + /** + * The selected item as an index in the list model. + */ + int mSelected; + + /** + * 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; + }; +} + +#endif // end GCN_LISTBOX_HPP diff --git a/src/include/guisan/widgets/radiobutton.hpp b/src/include/guisan/widgets/radiobutton.hpp new file mode 100644 index 00000000..0b1e0aca --- /dev/null +++ b/src/include/guisan/widgets/radiobutton.hpp @@ -0,0 +1,225 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 + +#include "guisan/keylistener.hpp" +#include "guisan/mouselistener.hpp" +#include "guisan/platform.hpp" +#include "guisan/widget.hpp" + +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: + + /** + * 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); + + /** + * 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; + + /** + * 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; + + /** + * 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); + + /** + * 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(); + + + // Inherited from Widget + + virtual void draw(Graphics* graphics); + + virtual void drawBorder(Graphics* graphics); + + + // Inherited from KeyListener + + virtual void keyPressed(KeyEvent& keyEvent); + + + // Inherited from MouseListener + + virtual void mouseClicked(MouseEvent& mouseEvent); + + virtual void mouseDragged(MouseEvent& mouseEvent); + + 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; + + /** + * Holds the caption of the radio button. + */ + std::string mCaption; + + /** + * Holds the group of the radio button. + */ + std::string mGroup; + + /** + * Typdef. + */ + typedef std::multimap GroupMap; + + /** + * Typdef. + */ + typedef GroupMap::iterator GroupIterator; + + /** + * Holds all available radio button groups. + */ + static GroupMap mGroupMap; + }; +} + +#endif // end GCN_RADIOBUTTON_HPP diff --git a/src/include/guisan/widgets/scrollarea.hpp b/src/include/guisan/widgets/scrollarea.hpp new file mode 100644 index 00000000..6a723ea8 --- /dev/null +++ b/src/include/guisan/widgets/scrollarea.hpp @@ -0,0 +1,488 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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/basiccontainer.hpp" +#include "guisan/mouselistener.hpp" +#include "guisan/platform.hpp" + +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 + + 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/src/include/guisan/widgets/slider.hpp b/src/include/guisan/widgets/slider.hpp new file mode 100644 index 00000000..99656147 --- /dev/null +++ b/src/include/guisan/widgets/slider.hpp @@ -0,0 +1,267 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 )\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 + +#include "guisan/basiccontainer.hpp" +#include "guisan/mouselistener.hpp" +#include "guisan/platform.hpp" + +namespace gcn +{ + 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: + + /** + * Constructor. + */ + Tab(); + + /** + * Destructor. + */ + virtual ~Tab(); + + /** + * 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); + + /** + * Gets the tabbed are the tab is a part of. + * + * @return The tabbed are the tab is a part of. + */ + TabbedArea* getTabbedArea(); + + /** + * 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; + + + // Inherited from Widget + + virtual void draw(Graphics *graphics); + + virtual void drawBorder(Graphics* graphics); + + + // Inherited from MouseListener + + virtual void mouseEntered(MouseEvent& mouseEvent); + + virtual void mouseExited(MouseEvent& mouseEvent); + + protected: + Label* mLabel; + TabbedArea* mTabbedArea; + std::string mCaption; + bool mHasMouse; + }; +} + +#endif // end GCN_TABBEDAREA_HPP diff --git a/src/include/guisan/widgets/tabbedarea.hpp b/src/include/guisan/widgets/tabbedarea.hpp new file mode 100644 index 00000000..d85498ed --- /dev/null +++ b/src/include/guisan/widgets/tabbedarea.hpp @@ -0,0 +1,226 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 +#include + +#include "guisan/actionlistener.hpp" +#include "guisan/basiccontainer.hpp" +#include "guisan/keylistener.hpp" +#include "guisan/mouselistener.hpp" +#include "guisan/platform.hpp" + +namespace gcn +{ + 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: + + /** + * Constructor. + */ + 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 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); + + /** + * 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); + + /** + * 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 index 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(); + + + // 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 setSize(int width, int height); + + void setDimension(const Rectangle& dimension); + + + // Inherited from ActionListener + + void action(const ActionEvent& actionEvent); + + + // Inherited from DeathListener + + virtual void death(const Event& event); + + + // Inherited from KeyListener + + virtual void keyPressed(KeyEvent& keyEvent); + + + // Inherited from MouseListener + + virtual void mousePressed(MouseEvent& mouseEvent); + + + 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/src/include/guisan/widgets/textbox.hpp b/src/include/guisan/widgets/textbox.hpp new file mode 100644 index 00000000..5a4b5bfc --- /dev/null +++ b/src/include/guisan/widgets/textbox.hpp @@ -0,0 +1,264 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 +#include + +#include "guisan/keylistener.hpp" +#include "guisan/mouselistener.hpp" +#include "guisan/platform.hpp" +#include "guisan/widget.hpp" + +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(); + + /** + * 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); + + /** + * 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; + + /** + * 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 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); + + /** + * 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); + + /** + * 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 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(); + + /** + * 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); + + /** + * 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(); + + /** + * Sets the TextBox to be opaque. + * + * @param opaque true if the TextBox should be opaque. + */ + void setOpaque(bool opaque); + + + // Inherited from Widget + + virtual void draw(Graphics* graphics); + + virtual void drawBorder(Graphics* graphics); + + virtual void fontChanged(); + + + // Inherited from KeyListener + + virtual void keyPressed(KeyEvent& keyEvent); + + + // Inherited from MouseListener + + virtual void mousePressed(MouseEvent& mouseEvent); + + 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); + + /** + * Adjusts the TextBox size to fit the font size. + */ + virtual void adjustSize(); + + std::vector mTextRows; + int mCaretColumn; + int mCaretRow; + bool mEditable; + bool mOpaque; + }; +} + +#endif // end GCN_TEXTBOX_HPP diff --git a/src/include/guisan/widgets/textfield.hpp b/src/include/guisan/widgets/textfield.hpp new file mode 100644 index 00000000..b6c1061e --- /dev/null +++ b/src/include/guisan/widgets/textfield.hpp @@ -0,0 +1,175 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 + +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(); + + /** + * 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); + + /** + * 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); + + /** + * 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(); + + /** + * 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; + + + // Inherited from Widget + + virtual void fontChanged(); + + virtual void draw(Graphics* graphics); + + virtual void drawBorder(Graphics* graphics); + + + // Inherited from MouseListener + + virtual void mousePressed(MouseEvent& mouseEvent); + + virtual void mouseDragged(MouseEvent& mouseEvent); + + + // Inherited from KeyListener + + virtual void keyPressed(KeyEvent& keyEvent); + + protected: + /** + * Scrolls the text horizontally so that the caret shows if needed. + */ + void fixScroll(); + + std::string mText; + unsigned int mCaretPosition; + int mXScroll; + }; +} + +#endif // end GCN_TEXTFIELD_HPP diff --git a/src/include/guisan/widgets/window.hpp b/src/include/guisan/widgets/window.hpp new file mode 100644 index 00000000..72b35fd9 --- /dev/null +++ b/src/include/guisan/widgets/window.hpp @@ -0,0 +1,217 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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/mouselistener.hpp" +#include "guisan/platform.hpp" +#include "guisan/widgets/container.hpp" + +namespace gcn +{ + /** + * 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); + + /** + * Destructor. + */ + virtual ~Window(); + + /** + * 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; + + /** + * 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 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(); + + /** + * 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; + + /** + * 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(); + + /** + * 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 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/src/include/guisan/x.hpp b/src/include/guisan/x.hpp new file mode 100644 index 00000000..6a372168 --- /dev/null +++ b/src/include/guisan/x.hpp @@ -0,0 +1,63 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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 + +#endif // end GCN_X_HPP diff --git a/src/osdep/bsdsocket_host.cpp b/src/osdep/bsdsocket_host.cpp index c9e95f69..a438b622 100644 --- a/src/osdep/bsdsocket_host.cpp +++ b/src/osdep/bsdsocket_host.cpp @@ -32,7 +32,7 @@ #include "custom.h" #include "autoconf.h" #include "traps.h" -#include "../td-sdl/thread.h" +#include "../threaddep/thread.h" #include "bsdsocket.h" #include "native2amiga.h" diff --git a/src/osdep/cda_play.cpp b/src/osdep/cda_play.cpp index 195c2dd9..827efba0 100644 --- a/src/osdep/cda_play.cpp +++ b/src/osdep/cda_play.cpp @@ -2,7 +2,7 @@ #include "sysdeps.h" #include "cda_play.h" -#include "sd-pandora/sound.h" +#include "sounddep/sound.h" #include "uae.h" diff --git a/src/osdep/gui/CreateFilesysHardfile.cpp b/src/osdep/gui/CreateFilesysHardfile.cpp index 373c2168..643e0de4 100644 --- a/src/osdep/gui/CreateFilesysHardfile.cpp +++ b/src/osdep/gui/CreateFilesysHardfile.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "UaeRadioButton.hpp" #include "UaeDropDown.hpp" @@ -17,7 +17,7 @@ #include "filesys.h" #include "gui.h" #include "gui_handling.h" - +#include "pandora_gfx.h" #define DIALOG_WIDTH 620 #define DIALOG_HEIGHT 202 @@ -238,7 +238,7 @@ static void CreateFilesysHardfileLoop(void) } //------------------------------------------------- - // Send event to guichan-controls + // Send event to guisan-controls //------------------------------------------------- gui_input->pushInput(event); } @@ -248,8 +248,15 @@ static void CreateFilesysHardfileLoop(void) // Now we let the Gui object draw itself. uae_gui->draw(); // Finally we update the screen. - wait_for_vsync(); - SDL_Flip(gui_screen); +// wait_for_vsync(); +// SDL_Flip(gui_screen); + + // Update the texture from the surface + SDL_UpdateTexture(texture, NULL, gui_screen->pixels, gui_screen->pitch); + // Copy the texture on the renderer + SDL_RenderCopy(renderer, texture, NULL, NULL); + // Update the window surface (show the renderer) + SDL_RenderPresent(renderer); } } diff --git a/src/osdep/gui/EditFilesysHardfile.cpp b/src/osdep/gui/EditFilesysHardfile.cpp index 87f506d5..28310094 100644 --- a/src/osdep/gui/EditFilesysHardfile.cpp +++ b/src/osdep/gui/EditFilesysHardfile.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "UaeRadioButton.hpp" #include "UaeDropDown.hpp" @@ -17,7 +17,7 @@ #include "filesys.h" #include "gui.h" #include "gui_handling.h" - +#include "pandora_gfx.h" #define DIALOG_WIDTH 620 #define DIALOG_HEIGHT 242 @@ -304,7 +304,7 @@ static void EditFilesysHardfileLoop(void) } //------------------------------------------------- - // Send event to guichan-controls + // Send event to guisan-controls //------------------------------------------------- gui_input->pushInput(event); } @@ -314,8 +314,15 @@ static void EditFilesysHardfileLoop(void) // Now we let the Gui object draw itself. uae_gui->draw(); // Finally we update the screen. - wait_for_vsync(); - SDL_Flip(gui_screen); +// wait_for_vsync(); +// SDL_Flip(gui_screen); + + // Update the texture from the surface + SDL_UpdateTexture(texture, NULL, gui_screen->pixels, gui_screen->pitch); + // Copy the texture on the renderer + SDL_RenderCopy(renderer, texture, NULL, NULL); + // Update the window surface (show the renderer) + SDL_RenderPresent(renderer); } } diff --git a/src/osdep/gui/EditFilesysVirtual.cpp b/src/osdep/gui/EditFilesysVirtual.cpp index c6720c80..aaa6e66d 100644 --- a/src/osdep/gui/EditFilesysVirtual.cpp +++ b/src/osdep/gui/EditFilesysVirtual.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "UaeRadioButton.hpp" #include "UaeDropDown.hpp" @@ -17,11 +17,13 @@ #include "filesys.h" #include "gui.h" #include "gui_handling.h" - +#include "pandora_gfx.h" #define DIALOG_WIDTH 520 #define DIALOG_HEIGHT 202 +extern std::string volName; + static bool dialogResult = false; static bool dialogFinished = false; @@ -48,11 +50,14 @@ class FilesysVirtualActionListener : public gcn::ActionListener { if(actionEvent.getSource() == cmdPath) { - char tmp[MAX_PATH]; + char tmp[MAX_PATH]; strncpy(tmp, txtPath->getText().c_str(), MAX_PATH); wndEditFilesysVirtual->releaseModalFocus(); - if(SelectFolder("Select folder", tmp)) - txtPath->setText(tmp); + if (SelectFolder("Select folder", tmp)) + { + txtPath->setText(tmp); + txtVolume->setText(volName); + } wndEditFilesysVirtual->requestModalFocus(); cmdPath->requestFocus(); } @@ -239,7 +244,7 @@ static void EditFilesysVirtualLoop(void) } //------------------------------------------------- - // Send event to guichan-controls + // Send event to guisan-controls //------------------------------------------------- gui_input->pushInput(event); } @@ -249,8 +254,15 @@ static void EditFilesysVirtualLoop(void) // Now we let the Gui object draw itself. uae_gui->draw(); // Finally we update the screen. - wait_for_vsync(); - SDL_Flip(gui_screen); +// wait_for_vsync(); +// SDL_Flip(gui_screen); + + // Update the texture from the surface + SDL_UpdateTexture(texture, NULL, gui_screen->pixels, gui_screen->pitch); + // Copy the texture on the renderer + SDL_RenderCopy(renderer, texture, NULL, NULL); + // Update the window surface (show the renderer) + SDL_RenderPresent(renderer); } } diff --git a/src/osdep/gui/InGameMessage.cpp b/src/osdep/gui/InGameMessage.cpp index d4b7e871..8008b24e 100644 --- a/src/osdep/gui/InGameMessage.cpp +++ b/src/osdep/gui/InGameMessage.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "sysconfig.h" @@ -11,7 +11,7 @@ #include "uae.h" #include "gui.h" #include "gui_handling.h" - +#include "pandora_gfx.h" extern SDL_Surface *prSDLScreen; extern void flush_screen(); @@ -33,7 +33,7 @@ void InGameMessage(const char *msg) gcn::Gui* msg_gui; gcn::SDLGraphics* msg_graphics; gcn::SDLInput* msg_input; - gcn::contrib::SDLTrueTypeFont* msg_font; + gcn::SDLTrueTypeFont* msg_font; gcn::Color msg_baseCol; gcn::Container* msg_top; @@ -61,7 +61,7 @@ void InGameMessage(const char *msg) msg_gui->setTop(msg_top); TTF_Init(); - msg_font = new gcn::contrib::SDLTrueTypeFont("data/FreeSans.ttf", 10); + msg_font = new gcn::SDLTrueTypeFont("data/FreeSans.ttf", 10); gcn::Widget::setGlobalFont(msg_font); doneActionListener = new DoneActionListener(); @@ -113,7 +113,7 @@ void InGameMessage(const char *msg) } //------------------------------------------------- - // Send event to guichan-controls + // Send event to guisan-controls //------------------------------------------------- msg_input->pushInput(event); } @@ -124,7 +124,15 @@ void InGameMessage(const char *msg) msg_gui->draw(); // Finally we update the screen. if (!drawn) - SDL_Flip(prSDLScreen); +// SDL_Flip(prSDLScreen); + { + // Update the texture from the surface + SDL_UpdateTexture(texture, NULL, gui_screen->pixels, gui_screen->pitch); + // Copy the texture on the renderer + SDL_RenderCopy(renderer, texture, NULL, NULL); + // Update the window surface (show the renderer) + SDL_RenderPresent(renderer); + } drawn = true; } diff --git a/src/osdep/gui/Navigation.cpp b/src/osdep/gui/Navigation.cpp index 1f6d0cf3..42ef2c33 100644 --- a/src/osdep/gui/Navigation.cpp +++ b/src/osdep/gui/Navigation.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "UaeRadioButton.hpp" #include "UaeDropDown.hpp" diff --git a/src/osdep/gui/PanelCPU.cpp b/src/osdep/gui/PanelCPU.cpp index e6f5b9e5..2d3abe0f 100644 --- a/src/osdep/gui/PanelCPU.cpp +++ b/src/osdep/gui/PanelCPU.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "UaeRadioButton.hpp" #include "UaeCheckBox.hpp" diff --git a/src/osdep/gui/PanelChipset.cpp b/src/osdep/gui/PanelChipset.cpp index ec54728b..07f31060 100644 --- a/src/osdep/gui/PanelChipset.cpp +++ b/src/osdep/gui/PanelChipset.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "UaeRadioButton.hpp" #include "UaeCheckBox.hpp" diff --git a/src/osdep/gui/PanelConfig.cpp b/src/osdep/gui/PanelConfig.cpp index 0082bd4b..7c74f1ed 100644 --- a/src/osdep/gui/PanelConfig.cpp +++ b/src/osdep/gui/PanelConfig.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "UaeListBox.hpp" @@ -314,7 +314,7 @@ void InitPanelConfig(const struct _ConfigCategory& category) lstConfigs->addActionListener(configsListActionListener); scrAreaConfigs = new gcn::ScrollArea(lstConfigs); - scrAreaConfigs->setFrameSize(1); + scrAreaConfigs->setBorderSize(1); scrAreaConfigs->setPosition(DISTANCE_BORDER, DISTANCE_BORDER); scrAreaConfigs->setSize(category.panel->getWidth() - 2 * DISTANCE_BORDER - 2, 252); scrAreaConfigs->setScrollbarWidth(20); diff --git a/src/osdep/gui/PanelDisplay.cpp b/src/osdep/gui/PanelDisplay.cpp index b0ec0aa7..122df257 100644 --- a/src/osdep/gui/PanelDisplay.cpp +++ b/src/osdep/gui/PanelDisplay.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "UaeRadioButton.hpp" #include "UaeDropDown.hpp" diff --git a/src/osdep/gui/PanelFloppy.cpp b/src/osdep/gui/PanelFloppy.cpp index 5c134a5d..9296e976 100644 --- a/src/osdep/gui/PanelFloppy.cpp +++ b/src/osdep/gui/PanelFloppy.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "UaeRadioButton.hpp" #include "UaeDropDown.hpp" diff --git a/src/osdep/gui/PanelHD.cpp b/src/osdep/gui/PanelHD.cpp index ebdbd6ef..83885d7f 100644 --- a/src/osdep/gui/PanelHD.cpp +++ b/src/osdep/gui/PanelHD.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "UaeRadioButton.hpp" #include "UaeDropDown.hpp" @@ -329,7 +329,7 @@ void InitPanelHD(const struct _ConfigCategory& category) listEntry[row] = new gcn::Container(); listEntry[row]->setSize(category.panel->getWidth() - 2 * DISTANCE_BORDER, TEXTFIELD_HEIGHT + 4); listEntry[row]->setBaseColor(gui_baseCol); - listEntry[row]->setFrameSize(0); + listEntry[row]->setBorderSize(0); listCmdProps[row] = new gcn::Button("..."); listCmdProps[row]->setBaseColor(gui_baseCol); diff --git a/src/osdep/gui/PanelInput.cpp b/src/osdep/gui/PanelInput.cpp index 0ac5964f..fd513e8f 100644 --- a/src/osdep/gui/PanelInput.cpp +++ b/src/osdep/gui/PanelInput.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "UaeRadioButton.hpp" #include "UaeDropDown.hpp" @@ -150,7 +150,7 @@ static int amigaKey[] = AK_F2, AK_F3, AK_F4, AK_F5, AK_F6, AK_F7, AK_F8, AK_F9, /* 101 - 108 */ AK_F10, 0 }; /* 109 - 110 */ -extern int customControlMap[SDLK_LAST]; +//extern int customControlMap[SDLK_LAST]; static int GetAmigaKeyIndex(int key) { @@ -270,35 +270,36 @@ public: else if (actionEvent.getSource() == chkCustomCtrl) changed_prefs.pandora_customControls = chkCustomCtrl->isSelected() ? 1 : 0; - else if (actionEvent.getSource() == cboA) - customControlMap[VK_A] = amigaKey[cboA->getSelected()]; - - else if (actionEvent.getSource() == cboB) - customControlMap[VK_B] = amigaKey[cboB->getSelected()]; - - else if (actionEvent.getSource() == cboX) - customControlMap[VK_X] = amigaKey[cboX->getSelected()]; - - else if (actionEvent.getSource() == cboY) - customControlMap[VK_Y] = amigaKey[cboY->getSelected()]; - - else if (actionEvent.getSource() == cboL) - customControlMap[VK_L] = amigaKey[cboL->getSelected()]; - - else if (actionEvent.getSource() == cboR) - customControlMap[VK_R] = amigaKey[cboR->getSelected()]; - - else if (actionEvent.getSource() == cboUp) - customControlMap[VK_UP] = amigaKey[cboUp->getSelected()]; - - else if (actionEvent.getSource() == cboDown) - customControlMap[VK_DOWN] = amigaKey[cboDown->getSelected()]; - - else if (actionEvent.getSource() == cboLeft) - customControlMap[VK_LEFT] = amigaKey[cboLeft->getSelected()]; - - else if (actionEvent.getSource() == cboRight) - customControlMap[VK_RIGHT] = amigaKey[cboRight->getSelected()]; + //TODO: Implement this in SDL2 +// else if (actionEvent.getSource() == cboA) +// customControlMap[VK_A] = amigaKey[cboA->getSelected()]; +// +// else if (actionEvent.getSource() == cboB) +// customControlMap[VK_B] = amigaKey[cboB->getSelected()]; +// +// else if (actionEvent.getSource() == cboX) +// customControlMap[VK_X] = amigaKey[cboX->getSelected()]; +// +// else if (actionEvent.getSource() == cboY) +// customControlMap[VK_Y] = amigaKey[cboY->getSelected()]; +// +// else if (actionEvent.getSource() == cboL) +// customControlMap[VK_L] = amigaKey[cboL->getSelected()]; +// +// else if (actionEvent.getSource() == cboR) +// customControlMap[VK_R] = amigaKey[cboR->getSelected()]; +// +// else if (actionEvent.getSource() == cboUp) +// customControlMap[VK_UP] = amigaKey[cboUp->getSelected()]; +// +// else if (actionEvent.getSource() == cboDown) +// customControlMap[VK_DOWN] = amigaKey[cboDown->getSelected()]; +// +// else if (actionEvent.getSource() == cboLeft) +// customControlMap[VK_LEFT] = amigaKey[cboLeft->getSelected()]; +// +// else if (actionEvent.getSource() == cboRight) +// customControlMap[VK_RIGHT] = amigaKey[cboRight->getSelected()]; else if (actionEvent.getSource() == KeyForMenu) changed_prefs.key_for_menu = ControlKey_SDLKeyValues[KeyForMenu->getSelected()] ; @@ -660,16 +661,17 @@ void RefreshPanelInput(void) chkMouseHack->setSelected(changed_prefs.input_tablet == TABLET_MOUSEHACK); #endif chkCustomCtrl->setSelected(changed_prefs.pandora_customControls); - cboA->setSelected(GetAmigaKeyIndex(customControlMap[VK_A])); - cboB->setSelected(GetAmigaKeyIndex(customControlMap[VK_B])); - cboX->setSelected(GetAmigaKeyIndex(customControlMap[VK_X])); - cboY->setSelected(GetAmigaKeyIndex(customControlMap[VK_Y])); - cboL->setSelected(GetAmigaKeyIndex(customControlMap[VK_L])); - cboR->setSelected(GetAmigaKeyIndex(customControlMap[VK_R])); - cboUp->setSelected(GetAmigaKeyIndex(customControlMap[VK_UP])); - cboDown->setSelected(GetAmigaKeyIndex(customControlMap[VK_DOWN])); - cboLeft->setSelected(GetAmigaKeyIndex(customControlMap[VK_LEFT])); - cboRight->setSelected(GetAmigaKeyIndex(customControlMap[VK_RIGHT])); + //TODO: Implement this in SDL2 +// cboA->setSelected(GetAmigaKeyIndex(customControlMap[VK_A])); +// cboB->setSelected(GetAmigaKeyIndex(customControlMap[VK_B])); +// cboX->setSelected(GetAmigaKeyIndex(customControlMap[VK_X])); +// cboY->setSelected(GetAmigaKeyIndex(customControlMap[VK_Y])); +// cboL->setSelected(GetAmigaKeyIndex(customControlMap[VK_L])); +// cboR->setSelected(GetAmigaKeyIndex(customControlMap[VK_R])); +// cboUp->setSelected(GetAmigaKeyIndex(customControlMap[VK_UP])); +// cboDown->setSelected(GetAmigaKeyIndex(customControlMap[VK_DOWN])); +// cboLeft->setSelected(GetAmigaKeyIndex(customControlMap[VK_LEFT])); +// cboRight->setSelected(GetAmigaKeyIndex(customControlMap[VK_RIGHT])); for(i=0; i<4; ++i) { diff --git a/src/osdep/gui/PanelMisc.cpp b/src/osdep/gui/PanelMisc.cpp index 8fabf8d0..e695fab7 100644 --- a/src/osdep/gui/PanelMisc.cpp +++ b/src/osdep/gui/PanelMisc.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "UaeRadioButton.hpp" #include "UaeDropDown.hpp" diff --git a/src/osdep/gui/PanelPaths.cpp b/src/osdep/gui/PanelPaths.cpp index eaab7dd1..fae953a9 100644 --- a/src/osdep/gui/PanelPaths.cpp +++ b/src/osdep/gui/PanelPaths.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "sysconfig.h" diff --git a/src/osdep/gui/PanelRAM.cpp b/src/osdep/gui/PanelRAM.cpp index 35587dad..846f3a37 100644 --- a/src/osdep/gui/PanelRAM.cpp +++ b/src/osdep/gui/PanelRAM.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "UaeRadioButton.hpp" #include "UaeDropDown.hpp" diff --git a/src/osdep/gui/PanelROM.cpp b/src/osdep/gui/PanelROM.cpp index f34ae010..46ef0cdc 100644 --- a/src/osdep/gui/PanelROM.cpp +++ b/src/osdep/gui/PanelROM.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "UaeRadioButton.hpp" #include "UaeDropDown.hpp" diff --git a/src/osdep/gui/PanelSavestate.cpp b/src/osdep/gui/PanelSavestate.cpp index daf6b44b..198fcbb6 100644 --- a/src/osdep/gui/PanelSavestate.cpp +++ b/src/osdep/gui/PanelSavestate.cpp @@ -1,8 +1,8 @@ -#include -#include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "UaeRadioButton.hpp" #include "UaeCheckBox.hpp" diff --git a/src/osdep/gui/PanelSound.cpp b/src/osdep/gui/PanelSound.cpp index 7beb8b0d..049daddc 100644 --- a/src/osdep/gui/PanelSound.cpp +++ b/src/osdep/gui/PanelSound.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "UaeRadioButton.hpp" #include "UaeCheckBox.hpp" @@ -17,7 +17,7 @@ #include "newcpu.h" #include "custom.h" #include "gui_handling.h" -#include "sd-pandora/sound.h" +#include "sounddep/sound.h" static gcn::Window *grpSound; diff --git a/src/osdep/gui/SelectFile.cpp b/src/osdep/gui/SelectFile.cpp index a7621038..05ca03eb 100644 --- a/src/osdep/gui/SelectFile.cpp +++ b/src/osdep/gui/SelectFile.cpp @@ -1,10 +1,10 @@ #include -#include +#include #include #include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "sysconfig.h" @@ -14,7 +14,7 @@ #include "fsdb.h" #include "gui.h" #include "gui_handling.h" - +#include "pandora_gfx.h" #define DIALOG_WIDTH 520 #define DIALOG_HEIGHT 400 @@ -218,7 +218,7 @@ static void InitSelectFile(const char *title) lstFiles->addActionListener(selectFileActionListener); scrAreaFiles = new gcn::ScrollArea(lstFiles); - scrAreaFiles->setFrameSize(1); + scrAreaFiles->setBorderSize(1); scrAreaFiles->setPosition(DISTANCE_BORDER, 10 + TEXTFIELD_HEIGHT + 10); scrAreaFiles->setSize(DIALOG_WIDTH - 2 * DISTANCE_BORDER - 4, 272); scrAreaFiles->setScrollbarWidth(20); @@ -340,7 +340,7 @@ static void SelectFileLoop(void) } //------------------------------------------------- - // Send event to guichan-controls + // Send event to guisan-controls //------------------------------------------------- gui_input->pushInput(event); } @@ -350,8 +350,15 @@ static void SelectFileLoop(void) // Now we let the Gui object draw itself. uae_gui->draw(); // Finally we update the screen. - wait_for_vsync(); - SDL_Flip(gui_screen); +// wait_for_vsync(); +// SDL_Flip(gui_screen); + + // Update the texture from the surface + SDL_UpdateTexture(texture, NULL, gui_screen->pixels, gui_screen->pitch); + // Copy the texture on the renderer + SDL_RenderCopy(renderer, texture, NULL, NULL); + // Update the window surface (show the renderer) + SDL_RenderPresent(renderer); if (!dialogCreated) { diff --git a/src/osdep/gui/SelectFolder.cpp b/src/osdep/gui/SelectFolder.cpp index b24486b3..a628937a 100644 --- a/src/osdep/gui/SelectFolder.cpp +++ b/src/osdep/gui/SelectFolder.cpp @@ -1,10 +1,10 @@ #include -#include +#include #include #include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "sysconfig.h" @@ -12,7 +12,7 @@ #include "config.h" #include "uae.h" #include "gui_handling.h" - +#include "pandora_gfx.h" #define DIALOG_WIDTH 520 #define DIALOG_HEIGHT 400 @@ -152,7 +152,7 @@ static void InitSelectFolder(const char *title) lstFolders->addActionListener(listBoxActionListener); scrAreaFolders = new gcn::ScrollArea(lstFolders); - scrAreaFolders->setFrameSize(1); + scrAreaFolders->setBorderSize(1); scrAreaFolders->setPosition(DISTANCE_BORDER, 10 + TEXTFIELD_HEIGHT + 10); scrAreaFolders->setSize(DIALOG_WIDTH - 2 * DISTANCE_BORDER - 4, 272); scrAreaFolders->setScrollbarWidth(20); @@ -242,7 +242,7 @@ static void SelectFolderLoop(void) } //------------------------------------------------- - // Send event to guichan-controls + // Send event to guisan-controls //------------------------------------------------- gui_input->pushInput(event); } @@ -252,8 +252,15 @@ static void SelectFolderLoop(void) // Now we let the Gui object draw itself. uae_gui->draw(); // Finally we update the screen. - wait_for_vsync(); - SDL_Flip(gui_screen); +// wait_for_vsync(); +// SDL_Flip(gui_screen); + + // Update the texture from the surface + SDL_UpdateTexture(texture, NULL, gui_screen->pixels, gui_screen->pitch); + // Copy the texture on the renderer + SDL_RenderCopy(renderer, texture, NULL, NULL); + // Update the window surface (show the renderer) + SDL_RenderPresent(renderer); } } diff --git a/src/osdep/gui/SelectorEntry.cpp b/src/osdep/gui/SelectorEntry.cpp index 3615a354..7dc4f08a 100644 --- a/src/osdep/gui/SelectorEntry.cpp +++ b/src/osdep/gui/SelectorEntry.cpp @@ -1,8 +1,8 @@ -#include "od-pandora/gui/SelectorEntry.hpp" +#include "osdep/gui/SelectorEntry.hpp" -#include "guichan/widgets/container.hpp" -#include "guichan/widgets/icon.hpp" -#include "guichan/widgets/label.hpp" +#include "guisan/widgets/container.hpp" +#include "guisan/widgets/icon.hpp" +#include "guisan/widgets/label.hpp" namespace gcn diff --git a/src/osdep/gui/SelectorEntry.hpp b/src/osdep/gui/SelectorEntry.hpp index 60207f03..da42458d 100644 --- a/src/osdep/gui/SelectorEntry.hpp +++ b/src/osdep/gui/SelectorEntry.hpp @@ -3,10 +3,10 @@ #include -#include "guichan/basiccontainer.hpp" -#include "guichan/graphics.hpp" -#include "guichan/platform.hpp" -#include "guichan/widgetlistener.hpp" +#include "guisan/basiccontainer.hpp" +#include "guisan/graphics.hpp" +#include "guisan/platform.hpp" +#include "guisan/widgetlistener.hpp" namespace gcn diff --git a/src/osdep/gui/ShowMessage.cpp b/src/osdep/gui/ShowMessage.cpp index 65900e88..4d4c8504 100644 --- a/src/osdep/gui/ShowMessage.cpp +++ b/src/osdep/gui/ShowMessage.cpp @@ -1,10 +1,10 @@ #include -#include +#include #include #include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "sysconfig.h" @@ -12,7 +12,7 @@ #include "config.h" #include "gui.h" #include "gui_handling.h" - +#include "pandora_gfx.h" #define DIALOG_WIDTH 340 #define DIALOG_HEIGHT 140 @@ -133,7 +133,7 @@ static void ShowMessageLoop(void) } //------------------------------------------------- - // Send event to guichan-controls + // Send event to guisan-controls //------------------------------------------------- gui_input->pushInput(event); } @@ -143,8 +143,15 @@ static void ShowMessageLoop(void) // Now we let the Gui object draw itself. uae_gui->draw(); // Finally we update the screen. - wait_for_vsync(); - SDL_Flip(gui_screen); +// wait_for_vsync(); +// SDL_Flip(gui_screen); + + // Update the texture from the surface + SDL_UpdateTexture(texture, NULL, gui_screen->pixels, gui_screen->pitch); + // Copy the texture on the renderer + SDL_RenderCopy(renderer, texture, NULL, NULL); + // Update the window surface (show the renderer) + SDL_RenderPresent(renderer); } } diff --git a/src/osdep/gui/UaeCheckBox.cpp b/src/osdep/gui/UaeCheckBox.cpp index 572b997d..8e41f9db 100644 --- a/src/osdep/gui/UaeCheckBox.cpp +++ b/src/osdep/gui/UaeCheckBox.cpp @@ -1,10 +1,10 @@ #include "UaeCheckBox.hpp" -#include "guichan/widgets/checkbox.hpp" +#include "guisan/widgets/checkbox.hpp" -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" -#include "guichan/key.hpp" -#include "guichan/mouseinput.hpp" +#include "guisan/font.hpp" +#include "guisan/graphics.hpp" +#include "guisan/key.hpp" +#include "guisan/mouseinput.hpp" namespace gcn diff --git a/src/osdep/gui/UaeCheckBox.hpp b/src/osdep/gui/UaeCheckBox.hpp index d8ad9275..5e77ea20 100644 --- a/src/osdep/gui/UaeCheckBox.hpp +++ b/src/osdep/gui/UaeCheckBox.hpp @@ -4,11 +4,11 @@ #include #include -#include "guichan/keylistener.hpp" -#include "guichan/mouselistener.hpp" -#include "guichan/platform.hpp" -#include "guichan/widget.hpp" -#include "guichan/widgets/checkbox.hpp" +#include "guisan/keylistener.hpp" +#include "guisan/mouselistener.hpp" +#include "guisan/platform.hpp" +#include "guisan/widget.hpp" +#include "guisan/widgets/checkbox.hpp" namespace gcn diff --git a/src/osdep/gui/UaeDropDown.cpp b/src/osdep/gui/UaeDropDown.cpp index 0bdc947f..b32216b7 100644 --- a/src/osdep/gui/UaeDropDown.cpp +++ b/src/osdep/gui/UaeDropDown.cpp @@ -1,10 +1,10 @@ #include "UaeDropDown.hpp" -#include "guichan/widgets/dropdown.hpp" +#include "guisan/widgets/dropdown.hpp" -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" -#include "guichan/key.hpp" -#include "guichan/mouseinput.hpp" +#include "guisan/font.hpp" +#include "guisan/graphics.hpp" +#include "guisan/key.hpp" +#include "guisan/mouseinput.hpp" namespace gcn @@ -40,13 +40,13 @@ void UaeDropDown::keyPressed(KeyEvent& keyEvent) { setSelected(getSelected() - 1); keyEvent.consume(); - distributeActionEvent(); + distributeValueChangedEvent(); } else if (key.getValue() == Key::DOWN) { setSelected(getSelected() + 1); keyEvent.consume(); - distributeActionEvent(); + distributeValueChangedEvent(); } } diff --git a/src/osdep/gui/UaeDropDown.hpp b/src/osdep/gui/UaeDropDown.hpp index 93f632eb..2251d6a6 100644 --- a/src/osdep/gui/UaeDropDown.hpp +++ b/src/osdep/gui/UaeDropDown.hpp @@ -4,11 +4,11 @@ #include #include -#include "guichan/keylistener.hpp" -#include "guichan/mouselistener.hpp" -#include "guichan/platform.hpp" -#include "guichan/widget.hpp" -#include "guichan/widgets/dropdown.hpp" +#include "guisan/keylistener.hpp" +#include "guisan/mouselistener.hpp" +#include "guisan/platform.hpp" +#include "guisan/widget.hpp" +#include "guisan/widgets/dropdown.hpp" namespace gcn diff --git a/src/osdep/gui/UaeListBox.cpp b/src/osdep/gui/UaeListBox.cpp index dee69848..cfb74471 100644 --- a/src/osdep/gui/UaeListBox.cpp +++ b/src/osdep/gui/UaeListBox.cpp @@ -1,13 +1,13 @@ #include "UaeListBox.hpp" -#include "guichan/widgets/listbox.hpp" +#include "guisan/widgets/listbox.hpp" -#include "guichan/basiccontainer.hpp" -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" -#include "guichan/key.hpp" -#include "guichan/listmodel.hpp" -#include "guichan/mouseinput.hpp" -#include "guichan/selectionlistener.hpp" +#include "guisan/basiccontainer.hpp" +#include "guisan/font.hpp" +#include "guisan/graphics.hpp" +#include "guisan/key.hpp" +#include "guisan/listmodel.hpp" +#include "guisan/mouseinput.hpp" +#include "guisan/selectionlistener.hpp" namespace gcn @@ -43,7 +43,7 @@ void UaeListBox::draw(Graphics* graphics) // Check the current clip area so we don't draw unnecessary items // that are not visible. const ClipRectangle currentClipArea = graphics->getCurrentClipArea(); - int rowHeight = getRowHeight(); + int rowHeight = getFont()->getHeight(); // Calculate the number of rows to draw by checking the clip area. // The addition of two makes covers a partial visible row at the top diff --git a/src/osdep/gui/UaeListBox.hpp b/src/osdep/gui/UaeListBox.hpp index 1fdae225..7c317a8c 100644 --- a/src/osdep/gui/UaeListBox.hpp +++ b/src/osdep/gui/UaeListBox.hpp @@ -3,12 +3,12 @@ #include -#include "guichan/keylistener.hpp" -#include "guichan/listmodel.hpp" -#include "guichan/mouselistener.hpp" -#include "guichan/platform.hpp" -#include "guichan/widget.hpp" -#include "guichan/widgets/listbox.hpp" +#include "guisan/keylistener.hpp" +#include "guisan/listmodel.hpp" +#include "guisan/mouselistener.hpp" +#include "guisan/platform.hpp" +#include "guisan/widget.hpp" +#include "guisan/widgets/listbox.hpp" namespace gcn diff --git a/src/osdep/gui/UaeRadioButton.cpp b/src/osdep/gui/UaeRadioButton.cpp index e3bf27d9..d1f49f14 100644 --- a/src/osdep/gui/UaeRadioButton.cpp +++ b/src/osdep/gui/UaeRadioButton.cpp @@ -1,10 +1,10 @@ #include "UaeRadioButton.hpp" -#include "guichan/widgets/radiobutton.hpp" +#include "guisan/widgets/radiobutton.hpp" -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" -#include "guichan/key.hpp" -#include "guichan/mouseinput.hpp" +#include "guisan/font.hpp" +#include "guisan/graphics.hpp" +#include "guisan/key.hpp" +#include "guisan/mouseinput.hpp" namespace gcn diff --git a/src/osdep/gui/UaeRadioButton.hpp b/src/osdep/gui/UaeRadioButton.hpp index 6041fa87..d563f53d 100644 --- a/src/osdep/gui/UaeRadioButton.hpp +++ b/src/osdep/gui/UaeRadioButton.hpp @@ -4,11 +4,11 @@ #include #include -#include "guichan/keylistener.hpp" -#include "guichan/mouselistener.hpp" -#include "guichan/platform.hpp" -#include "guichan/widget.hpp" -#include "guichan/widgets/radiobutton.hpp" +#include "guisan/keylistener.hpp" +#include "guisan/mouselistener.hpp" +#include "guisan/platform.hpp" +#include "guisan/widget.hpp" +#include "guisan/widgets/radiobutton.hpp" namespace gcn diff --git a/src/osdep/gui/main_window.cpp b/src/osdep/gui/main_window.cpp index d27b7fe0..aae57df4 100644 --- a/src/osdep/gui/main_window.cpp +++ b/src/osdep/gui/main_window.cpp @@ -1,7 +1,8 @@ -#include -#include -#include -#include "sdltruetypefont.hpp" +#include +#include +#include +#include +#include "guisan/sdl/sdltruetypefont.hpp" #include "SelectorEntry.hpp" #include "sysconfig.h" @@ -13,6 +14,7 @@ #include "gui_handling.h" #include "include/memory.h" #include "autoconf.h" +#include "pandora_gfx.h" bool gui_running = false; static int last_active_panel = 1; @@ -41,18 +43,30 @@ enum { PANEL_PATHS, PANEL_CONFIGURATIONS, PANEL_CPU, PANEL_CHIPSET, PANEL_ROM, P }; +/* + * SDL Stuff we need + */ +SDL_Surface* gui_screen; +SDL_Event event; + +/* + * Guisan SDL stuff we need + */ +gcn::SDLInput* gui_input; +gcn::SDLGraphics* gui_graphics; +gcn::SDLImageLoader* gui_imageLoader; +gcn::SDLTrueTypeFont* gui_font; + +/* + * Guisan stuff we need + */ gcn::Gui* uae_gui; +gcn::Container* gui_top; +gcn::Container* selectors; gcn::Color gui_baseCol; gcn::Color gui_baseColLabel; gcn::Color colSelectorInactive; gcn::Color colSelectorActive; -gcn::Container* gui_top; -gcn::Container* selectors; -gcn::contrib::SDLTrueTypeFont* gui_font; -SDL_Surface* gui_screen; -gcn::SDLGraphics* gui_graphics; -gcn::SDLInput* gui_input; -gcn::SDLImageLoader* gui_imageLoader; namespace widgets { @@ -114,45 +128,72 @@ void RegisterRefreshFunc(void (*func)(void)) namespace sdl { void gui_init() +// { +// //------------------------------------------------- +// // Set layer for GUI screen +// //------------------------------------------------- +// char tmp[20]; +// snprintf(tmp, 20, "%dx%d", GUI_WIDTH, GUI_HEIGHT); +// setenv("SDL_OMAP_LAYER_SIZE", tmp, 1); +// snprintf(tmp, 20, "0,0,0,0"); +// setenv("SDL_OMAP_BORDER_CUT", tmp, 1); +// +// //------------------------------------------------- +// // Create new screen for GUI +// //------------------------------------------------- +// #if defined (RASPBERRY) +// const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo (); +//#ifdef DEBUG +// printf("Current resolution: %d x %d %d bpp\n",videoInfo->current_w, videoInfo->current_h, videoInfo->vfmt->BitsPerPixel); +//#endif +// gui_screen = SDL_SetVideoMode(videoInfo->current_w, videoInfo->current_h, videoInfo->vfmt->BitsPerPixel, SDL_SWSURFACE | SDL_FULLSCREEN); +// #else +// gui_screen = SDL_SetVideoMode(GUI_WIDTH, GUI_HEIGHT, 16, SDL_SWSURFACE); +// #endif +// SDL_EnableUNICODE(1); +// SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); +// SDL_ShowCursor(SDL_ENABLE); +// +// //------------------------------------------------- +// // Create helpers for guisan +// //------------------------------------------------- +// gui_imageLoader = new gcn::SDLImageLoader(); +// gcn::Image::setImageLoader(gui_imageLoader); +// gui_graphics = new gcn::SDLGraphics(); +// gui_graphics->setTarget(gui_screen); +// gui_input = new gcn::SDLInput(); +// uae_gui = new gcn::Gui(); +// uae_gui->setGraphics(gui_graphics); +// uae_gui->setInput(gui_input); +// } { - //------------------------------------------------- - // Set layer for GUI screen - //------------------------------------------------- - char tmp[20]; - snprintf(tmp, 20, "%dx%d", GUI_WIDTH, GUI_HEIGHT); - setenv("SDL_OMAP_LAYER_SIZE", tmp, 1); - snprintf(tmp, 20, "0,0,0,0"); - setenv("SDL_OMAP_BORDER_CUT", tmp, 1); - //------------------------------------------------- // Create new screen for GUI //------------------------------------------------- - #if defined (RASPBERRY) - const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo (); -#ifdef DEBUG - printf("Current resolution: %d x %d %d bpp\n",videoInfo->current_w, videoInfo->current_h, videoInfo->vfmt->BitsPerPixel); -#endif - gui_screen = SDL_SetVideoMode(videoInfo->current_w, videoInfo->current_h, videoInfo->vfmt->BitsPerPixel, SDL_SWSURFACE | SDL_FULLSCREEN); - #else - gui_screen = SDL_SetVideoMode(GUI_WIDTH, GUI_HEIGHT, 16, SDL_SWSURFACE); - #endif - SDL_EnableUNICODE(1); - SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); + gui_screen = SDL_CreateRGBSurface(0, GUI_WIDTH, GUI_HEIGHT, 32, 0, 0, 0, 0); + check_error_sdl(gui_screen == nullptr, "Unable to create a surface"); + SDL_ShowCursor(SDL_ENABLE); //------------------------------------------------- // Create helpers for guichan //------------------------------------------------- gui_imageLoader = new gcn::SDLImageLoader(); + // The ImageLoader in use is static and must be set to be + // able to load images gcn::Image::setImageLoader(gui_imageLoader); gui_graphics = new gcn::SDLGraphics(); + // Set the target for the graphics object to be the screen. + // In other words, we will draw to the screen. + // Note, any surface will do, it doesn't have to be the screen. gui_graphics->setTarget(gui_screen); gui_input = new gcn::SDLInput(); + uae_gui = new gcn::Gui(); uae_gui->setGraphics(gui_graphics); uae_gui->setInput(gui_input); } - + void gui_halt() { delete uae_gui; @@ -164,6 +205,91 @@ namespace sdl gui_screen = NULL; } + void checkInput() + { + while (SDL_PollEvent(&event)) + { + if (event.type == SDL_KEYDOWN) + { + gcn::FocusHandler* focusHdl; + gcn::Widget* activeWidget; + + if (event.key.keysym.sym == currprefs.key_for_menu) + { + if (emulating && widgets::cmdStart->isEnabled()) + { + //------------------------------------------------ + // Continue emulation + //------------------------------------------------ + gui_running = false; + } + else + { + //------------------------------------------------ + // First start of emulator -> reset Amiga + //------------------------------------------------ + uae_reset(0, 1); + gui_running = false; + } + } + else + switch (event.key.keysym.sym) + { + case SDLK_q: + //------------------------------------------------- + // Quit entire program via Q on keyboard + //------------------------------------------------- + focusHdl = gui_top->_getFocusHandler(); + activeWidget = focusHdl->getFocused(); + if (dynamic_cast(activeWidget) == NULL) + { + // ...but only if we are not in a Textfield... + uae_quit(); + gui_running = false; + } + break; + + case SDLK_ESCAPE: + uae_reset(1, 1); + gui_running = false; + break; + + case SDLK_UP: + if (HandleNavigation(DIRECTION_UP)) + continue; // Don't change value when enter ComboBox -> don't send event to control + break; + + case SDLK_DOWN: + if (HandleNavigation(DIRECTION_DOWN)) + continue; // Don't change value when enter ComboBox -> don't send event to control + break; + + case SDLK_LEFT: + if (HandleNavigation(DIRECTION_LEFT)) + continue; // Don't change value when enter Slider -> don't send event to control + break; + + case SDLK_RIGHT: + if (HandleNavigation(DIRECTION_RIGHT)) + continue; // Don't change value when enter Slider -> don't send event to control + break; + } + } + else if (event.type == SDL_QUIT) + { + //------------------------------------------------- + // Quit entire program via SQL-Quit + //------------------------------------------------- + uae_quit(); + gui_running = false; + } + //------------------------------------------------- + // Send event to guichan-controls + //------------------------------------------------- + gui_input->pushInput(event); + } + } + void gui_run() { //------------------------------------------------- @@ -171,110 +297,113 @@ namespace sdl //------------------------------------------------- while(gui_running) { - //------------------------------------------------- - // Check user input - //------------------------------------------------- - SDL_Event event; - while(SDL_PollEvent(&event)) - { - if (event.type == SDL_QUIT) - { - //------------------------------------------------- - // Quit entire program via SQL-Quit - //------------------------------------------------- - uae_quit(); - gui_running = false; - break; - } - - else if (event.type == SDL_KEYDOWN) - { - gcn::FocusHandler* focusHdl; - gcn::Widget* activeWidget; - - - if (event.key.keysym.sym == currprefs.key_for_menu) - { - if(emulating && widgets::cmdStart->isEnabled()) - { - //------------------------------------------------ - // Continue emulation - //------------------------------------------------ - gui_running = false; - } - else - { - //------------------------------------------------ - // First start of emulator -> reset Amiga - //------------------------------------------------ - uae_reset(0,1); - gui_running = false; - } - } - else - switch(event.key.keysym.sym) - { - case SDLK_q: - //------------------------------------------------- - // Quit entire program via Q on keyboard - //------------------------------------------------- - focusHdl = gui_top->_getFocusHandler(); - activeWidget = focusHdl->getFocused(); - if(dynamic_cast(activeWidget) == NULL) - { - // ...but only if we are not in a Textfield... - uae_quit(); - gui_running = false; - } - break; - - case VK_ESCAPE: - case VK_R: - //------------------------------------------------- - // Reset Amiga - //------------------------------------------------- - uae_reset(1,1); - gui_running = false; - break; - - case VK_X: - case VK_A: - //------------------------------------------------ - // Simulate press of enter when 'X' pressed - //------------------------------------------------ - event.key.keysym.sym = SDLK_RETURN; - gui_input->pushInput(event); // Fire key down - event.type = SDL_KEYUP; // and the key up - break; - - case VK_UP: - if(HandleNavigation(DIRECTION_UP)) - continue; // Don't change value when enter ComboBox -> don't send event to control - break; - - case VK_DOWN: - if(HandleNavigation(DIRECTION_DOWN)) - continue; // Don't change value when enter ComboBox -> don't send event to control - break; - - case VK_LEFT: - if(HandleNavigation(DIRECTION_LEFT)) - continue; // Don't change value when enter Slider -> don't send event to control - break; - - case VK_RIGHT: - if(HandleNavigation(DIRECTION_RIGHT)) - continue; // Don't change value when enter Slider -> don't send event to control - break; - } - } - - //------------------------------------------------- - // Send event to guichan-controls - //------------------------------------------------- - gui_input->pushInput(event); - } +// //------------------------------------------------- +// // Check user input +// //------------------------------------------------- +// SDL_Event event; +// while(SDL_PollEvent(&event)) +// { +// if (event.type == SDL_QUIT) +// { +// //------------------------------------------------- +// // Quit entire program via SQL-Quit +// //------------------------------------------------- +// uae_quit(); +// gui_running = false; +// break; +// } +// +// else if (event.type == SDL_KEYDOWN) +// { +// gcn::FocusHandler* focusHdl; +// gcn::Widget* activeWidget; +// +// +// if (event.key.keysym.sym == currprefs.key_for_menu) +// { +// if(emulating && widgets::cmdStart->isEnabled()) +// { +// //------------------------------------------------ +// // Continue emulation +// //------------------------------------------------ +// gui_running = false; +// } +// else +// { +// //------------------------------------------------ +// // First start of emulator -> reset Amiga +// //------------------------------------------------ +// uae_reset(0,1); +// gui_running = false; +// } +// } +// else +// switch(event.key.keysym.sym) +// { +// case SDLK_q: +// //------------------------------------------------- +// // Quit entire program via Q on keyboard +// //------------------------------------------------- +// focusHdl = gui_top->_getFocusHandler(); +// activeWidget = focusHdl->getFocused(); +// if(dynamic_cast(activeWidget) == NULL) +// { +// // ...but only if we are not in a Textfield... +// uae_quit(); +// gui_running = false; +// } +// break; +// +// case VK_ESCAPE: +// case VK_R: +// //------------------------------------------------- +// // Reset Amiga +// //------------------------------------------------- +// uae_reset(1,1); +// gui_running = false; +// break; +// +// case VK_X: +// case VK_A: +// //------------------------------------------------ +// // Simulate press of enter when 'X' pressed +// //------------------------------------------------ +// event.key.keysym.sym = SDLK_RETURN; +// gui_input->pushInput(event); // Fire key down +// event.type = SDL_KEYUP; // and the key up +// break; +// +// case VK_UP: +// if(HandleNavigation(DIRECTION_UP)) +// continue; // Don't change value when enter ComboBox -> don't send event to control +// break; +// +// case VK_DOWN: +// if(HandleNavigation(DIRECTION_DOWN)) +// continue; // Don't change value when enter ComboBox -> don't send event to control +// break; +// +// case VK_LEFT: +// if(HandleNavigation(DIRECTION_LEFT)) +// continue; // Don't change value when enter Slider -> don't send event to control +// break; +// +// case VK_RIGHT: +// if(HandleNavigation(DIRECTION_RIGHT)) +// continue; // Don't change value when enter Slider -> don't send event to control +// break; +// } +// } +// +// //------------------------------------------------- +// // Send event to guisan-controls +// //------------------------------------------------- +// gui_input->pushInput(event); +// } + // Poll input + checkInput(); + if(gui_rtarea_flags_onenter != gui_create_rtarea_flag(&changed_prefs)) DisableResume(); @@ -283,8 +412,15 @@ namespace sdl // Now we let the Gui object draw itself. uae_gui->draw(); // Finally we update the screen. - wait_for_vsync(); - SDL_Flip(gui_screen); +// wait_for_vsync(); +// SDL_Flip(gui_screen); + + // Update the texture from the surface + SDL_UpdateTexture(texture, NULL, gui_screen->pixels, gui_screen->pitch); + // Copy the texture on the renderer + SDL_RenderCopy(renderer, texture, NULL, NULL); + // Update the window surface (show the renderer) + SDL_RenderPresent(renderer); if(refreshFuncAfterDraw != NULL) { @@ -421,7 +557,7 @@ void gui_init() // Initialize fonts //------------------------------------------------- TTF_Init(); - gui_font = new gcn::contrib::SDLTrueTypeFont("data/FreeSans.ttf", 14); + gui_font = new gcn::SDLTrueTypeFont("data/FreeSans.ttf", 14); gcn::Widget::setGlobalFont(gui_font); //-------------------------------------------------- @@ -462,7 +598,7 @@ void gui_init() selectors = new gcn::Container(); selectors->setSize(150, workAreaHeight - 2); selectors->setBaseColor(colSelectorInactive); - selectors->setFrameSize(1); + selectors->setBorderSize(1); int panelStartX = DISTANCE_BORDER + selectors->getWidth() + 2 + 11; panelFocusListener = new PanelFocusListener(); @@ -478,7 +614,7 @@ void gui_init() categories[i].panel->setId(categories[i].category); categories[i].panel->setSize(GUI_WIDTH - panelStartX - DISTANCE_BORDER - 1, workAreaHeight - 2); categories[i].panel->setBaseColor(gui_baseCol); - categories[i].panel->setFrameSize(1); + categories[i].panel->setBorderSize(1); categories[i].panel->setVisible(false); } @@ -580,7 +716,7 @@ void run_gui(void) widgets::gui_halt(); sdl::gui_halt(); } - // Catch all Guichan exceptions. + // Catch all guisan exceptions. catch (gcn::Exception e) { std::cout << e.getMessage() << std::endl; diff --git a/src/osdep/gui/sdltruetypefont.cpp b/src/osdep/gui/sdltruetypefont.cpp deleted file mode 100644 index c317e81a..00000000 --- a/src/osdep/gui/sdltruetypefont.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "sdltruetypefont.hpp" - -#include "guichan/exception.hpp" -#include "guichan/image.hpp" -#include "guichan/graphics.hpp" -#include "guichan/sdl/sdlgraphics.hpp" - -namespace gcn -{ -namespace contrib -{ -SDLTrueTypeFont::SDLTrueTypeFont (const std::string& filename, int size) -{ - mRowSpacing = 0; - mGlyphSpacing = 0; - mAntiAlias = true; - mFilename = filename; - mFont = NULL; - - mFont = TTF_OpenFont(filename.c_str(), size); - - if (mFont == NULL) - { - throw GCN_EXCEPTION("SDLTrueTypeFont::SDLTrueTypeFont. "+std::string(TTF_GetError())); - } -} - -SDLTrueTypeFont::~SDLTrueTypeFont() -{ - TTF_CloseFont(mFont); -} - -int SDLTrueTypeFont::getWidth(const std::string& text) const -{ - int w, h; - TTF_SizeText(mFont, text.c_str(), &w, &h); - - return w; -} - -int SDLTrueTypeFont::getHeight() const -{ - return TTF_FontHeight(mFont) + mRowSpacing; -} - -void SDLTrueTypeFont::drawString(gcn::Graphics* graphics, const std::string& text, const int x, const int y) -{ - if (text == "") - { - return; - } - - gcn::SDLGraphics *sdlGraphics = dynamic_cast(graphics); - - if (sdlGraphics == 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 - int yoffset = getRowSpacing() / 2; - - Color col = sdlGraphics->getColor(); - - SDL_Color sdlCol; - sdlCol.b = col.b; - sdlCol.r = col.r; - sdlCol.g = col.g; - - SDL_Surface *textSurface; - if (mAntiAlias) - { - textSurface = TTF_RenderText_Blended(mFont, text.c_str(), sdlCol); - } - else - { - textSurface = TTF_RenderText_Solid(mFont, text.c_str(), sdlCol); - } - - SDL_Rect dst, src; - dst.x = x; - dst.y = y + yoffset; - src.w = textSurface->w; - src.h = textSurface->h; - src.x = 0; - src.y = 0; - - sdlGraphics->drawSDLSurface(textSurface, src, dst); - SDL_FreeSurface(textSurface); -} - -void SDLTrueTypeFont::setRowSpacing(int spacing) -{ - mRowSpacing = spacing; -} - -int SDLTrueTypeFont::getRowSpacing() -{ - return mRowSpacing; -} - -void SDLTrueTypeFont::setGlyphSpacing(int spacing) -{ - mGlyphSpacing = spacing; -} - -int SDLTrueTypeFont::getGlyphSpacing() -{ - return mGlyphSpacing; -} - -void SDLTrueTypeFont::setAntiAlias(bool antiAlias) -{ - mAntiAlias = antiAlias; -} - -bool SDLTrueTypeFont::isAntiAlias() -{ - return mAntiAlias; -} -} -} - diff --git a/src/osdep/hardfile_pandora.cpp b/src/osdep/hardfile_pandora.cpp index 824b4c20..bef8191e 100644 --- a/src/osdep/hardfile_pandora.cpp +++ b/src/osdep/hardfile_pandora.cpp @@ -1,7 +1,7 @@ #include "sysconfig.h" #include "sysdeps.h" -#include "td-sdl/thread.h" +#include "threaddep/thread.h" #include "options.h" #include "filesys.h" #include "zfile.h" diff --git a/src/osdep/menu/menu_config.cpp b/src/osdep/menu/menu_config.cpp index 7446014e..6c45e348 100644 --- a/src/osdep/menu/menu_config.cpp +++ b/src/osdep/menu/menu_config.cpp @@ -6,7 +6,7 @@ #include "autoconf.h" #include "options.h" #include "gui.h" -#include "sd-pandora/sound.h" +#include "sounddep/sound.h" #include "include/memory.h" #include "newcpu.h" #include "custom.h" diff --git a/src/osdep/pandora.cpp b/src/osdep/pandora.cpp index cc007344..352d32f5 100644 --- a/src/osdep/pandora.cpp +++ b/src/osdep/pandora.cpp @@ -21,7 +21,7 @@ #include "autoconf.h" #include "uae.h" #include "options.h" -#include "td-sdl/thread.h" +#include "threaddep/thread.h" #include "gui.h" #include "include/memory.h" #include "newcpu.h" diff --git a/src/osdep/pandora_gfx.cpp b/src/osdep/pandora_gfx.cpp index d5f3cd81..1251cd24 100644 --- a/src/osdep/pandora_gfx.cpp +++ b/src/osdep/pandora_gfx.cpp @@ -12,14 +12,15 @@ #include "inputdevice.h" #include "savestate.h" #include "picasso96.h" +#include "pandora_gfx.h" #include #include -#include -#ifndef ANDROID -#include -#endif -#include +#include +//#ifndef ANDROID +//#include +//#endif +#include #ifdef ANDROID #include @@ -193,9 +194,7 @@ static void open_screen(struct uae_prefs *p) CalcPandoraWidth(p); snprintf(layersize, 20, "%dx480", p->gfx_size_fs.width); -#ifndef WIN32 setenv("SDL_OMAP_LAYER_SIZE", layersize, 1); -#endif } else { @@ -203,13 +202,9 @@ static void open_screen(struct uae_prefs *p) snprintf(layersize, 20, "%dx480", picasso_vidinfo.width); else snprintf(layersize, 20, "%dx%d", picasso_vidinfo.width, picasso_vidinfo.height); -#ifndef WIN32 setenv("SDL_OMAP_LAYER_SIZE", layersize, 1); -#endif } -#ifndef WIN32 setenv("SDL_OMAP_VSYNC", "0", 1); -#endif #ifdef ANDROIDSDL update_onscreen(); @@ -219,18 +214,49 @@ static void open_screen(struct uae_prefs *p) { if(prSDLScreen == NULL || prSDLScreen->w != p->gfx_size.width || prSDLScreen->h != p->gfx_size.height) { -#if defined(PANDORA) && !defined(WIN32) - prSDLScreen = SDL_SetVideoMode(p->gfx_size.width, p->gfx_size.height, 16, SDL_HWSURFACE|SDL_FULLSCREEN|SDL_DOUBLEBUF); -#elif defined(PANDORA) && defined(WIN32) - prSDLScreen = SDL_SetVideoMode(p->gfx_size.width, p->gfx_size.height, 16, SDL_SWSURFACE|SDL_DOUBLEBUF); -#else - prSDLScreen = SDL_SetVideoMode(p->gfx_size.width, p->gfx_size.height, 16, SDL_HWSURFACE|SDL_FULLSCREEN); -#endif +// prSDLScreen = SDL_SetVideoMode(p->gfx_size.width, p->gfx_size.height, 16, SDL_HWSURFACE|SDL_FULLSCREEN|SDL_DOUBLEBUF); + prSDLScreen = SDL_CreateRGBSurface(0, p->gfx_size.width, p->gfx_size.height, 32, 0, 0, 0, 0); + check_error_sdl(prSDLScreen == nullptr, "Unable to create a surface"); + + // make the scaled rendering look smoother. + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); + SDL_RenderSetLogicalSize(renderer, p->gfx_size.width, p->gfx_size.height); + + // Initialize SDL Texture for the renderer + // if (texture == nullptr) + { + texture = SDL_CreateTexture(renderer, + SDL_PIXELFORMAT_ARGB8888, + SDL_TEXTUREACCESS_STREAMING, + p->gfx_size.width, + p->gfx_size.height); + check_error_sdl(texture == nullptr, "Unable to create texture"); + } } } else { - prSDLScreen = SDL_SetVideoMode(picasso_vidinfo.width, picasso_vidinfo.height, 16, SDL_HWSURFACE|SDL_FULLSCREEN|SDL_DOUBLEBUF); +// prSDLScreen = SDL_SetVideoMode(picasso_vidinfo.width, picasso_vidinfo.height, 16, SDL_HWSURFACE|SDL_FULLSCREEN|SDL_DOUBLEBUF); + if (prSDLScreen == NULL || prSDLScreen->w != picasso_vidinfo.width || prSDLScreen->h != picasso_vidinfo.height) + { + prSDLScreen = SDL_CreateRGBSurface(0, picasso_vidinfo.width, picasso_vidinfo.height, 32, 0, 0, 0, 0); + check_error_sdl(prSDLScreen == nullptr, "Unable to create a surface"); + + // make the scaled rendering look smoother. + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); + SDL_RenderSetLogicalSize(renderer, picasso_vidinfo.width, picasso_vidinfo.height); + + // Initialize SDL Texture for the renderer +// if (texture == nullptr) + { + texture = SDL_CreateTexture(renderer, + SDL_PIXELFORMAT_ARGB8888, + SDL_TEXTUREACCESS_STREAMING, + picasso_vidinfo.width, + picasso_vidinfo.height); + check_error_sdl(texture == nullptr, "Unable to create texture"); + } + } } if(prSDLScreen != NULL) { @@ -238,25 +264,30 @@ static void open_screen(struct uae_prefs *p) init_row_map(); } - current_vsync_frame = 0; - fbdev = open("/dev/fb0", O_RDWR); - if(fbdev != -1) - { - // Check if we have vsync with frame counter... - current_vsync_frame = 0; - ioctl(fbdev, OMAPFB_WAITFORVSYNC_FRAME, ¤t_vsync_frame); - if(current_vsync_frame != 0) - current_vsync_frame += 2; - } + // Update the texture from the surface + SDL_UpdateTexture(texture, NULL, prSDLScreen->pixels, prSDLScreen->pitch); + // Copy the texture on the renderer + SDL_RenderCopy(renderer, texture, NULL, NULL); + // Update the window surface (show the renderer) + SDL_RenderPresent(renderer); + +// current_vsync_frame = 0; +// fbdev = open("/dev/fb0", O_RDWR); +// if(fbdev != -1) +// { +// // Check if we have vsync with frame counter... +// current_vsync_frame = 0; +// ioctl(fbdev, OMAPFB_WAITFORVSYNC_FRAME, ¤t_vsync_frame); +// if(current_vsync_frame != 0) +// current_vsync_frame += 2; +// } } void update_display(struct uae_prefs *p) { open_screen(p); - SDL_ShowCursor(SDL_DISABLE); - framecnt = 1; // Don't draw frame before reset done } @@ -315,11 +346,11 @@ void unlockscr (void) void wait_for_vsync(void) { - if(fbdev != -1) - { - unsigned int dummy; - ioctl(fbdev, OMAPFB_WAITFORVSYNC, &dummy); - } +// if(fbdev != -1) +// { +// unsigned int dummy; +// ioctl(fbdev, OMAPFB_WAITFORVSYNC, &dummy); +// } } @@ -368,7 +399,15 @@ void flush_screen () } // Android swapped SDL_Flip & last_synctime for fixing performance - SDL_Flip(prSDLScreen); +// SDL_Flip(prSDLScreen); + + // Update the texture from the surface + SDL_UpdateTexture(texture, NULL, prSDLScreen->pixels, prSDLScreen->pitch); + // Copy the texture on the renderer + SDL_RenderCopy(renderer, texture, NULL, NULL); + // Update the window surface (show the renderer) + SDL_RenderPresent(renderer); + last_synctime = read_processor_time(); if(!screen_is_picasso) @@ -391,7 +430,13 @@ void flush_screen () void black_screen_now(void) { SDL_FillRect(prSDLScreen,NULL,0); - SDL_Flip(prSDLScreen); +// SDL_Flip(prSDLScreen); + // Update the texture from the surface + SDL_UpdateTexture(texture, NULL, prSDLScreen->pixels, prSDLScreen->pitch); + // Copy the texture on the renderer + SDL_RenderCopy(renderer, texture, NULL, NULL); + // Update the window surface (show the renderer) + SDL_RenderPresent(renderer); } @@ -404,7 +449,14 @@ static void graphics_subinit (void) } else { - SDL_Flip(prSDLScreen); +// SDL_Flip(prSDLScreen); + // Update the texture from the surface + SDL_UpdateTexture(texture, NULL, prSDLScreen->pixels, prSDLScreen->pitch); + // Copy the texture on the renderer + SDL_RenderCopy(renderer, texture, NULL, NULL); + // Update the window surface (show the renderer) + SDL_RenderPresent(renderer); + SDL_ShowCursor(SDL_DISABLE); InitAmigaVidMode(&currprefs); @@ -464,19 +516,22 @@ static int init_colors (void) */ static int get_display_depth (void) { - const SDL_VideoInfo *vid_info; - int depth = 0; +// const SDL_VideoInfo *vid_info; + +// int depth = 0; + int depth = 32; - if ((vid_info = SDL_GetVideoInfo())) - { - depth = vid_info->vfmt->BitsPerPixel; +// if ((vid_info = SDL_GetVideoInfo())) +// { +// depth = vid_info->vfmt->BitsPerPixel; /* Don't trust the answer if it's 16 bits; the display * could actually be 15 bits deep. We'll count the bits * ourselves */ - if (depth == 16) - depth = bitsInMask (vid_info->vfmt->Rmask) + bitsInMask (vid_info->vfmt->Gmask) + bitsInMask (vid_info->vfmt->Bmask); - } +// if (depth == 16) +// depth = bitsInMask (vid_info->vfmt->Rmask) + bitsInMask (vid_info->vfmt->Gmask) + bitsInMask (vid_info->vfmt->Bmask); +// } + return depth; } @@ -508,6 +563,10 @@ int graphics_init (bool mousecapture) void graphics_leave (void) { graphics_subshutdown (); + + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(sdlWindow); + SDL_VideoQuit(); } @@ -789,9 +848,9 @@ void picasso_InitResolutions (void) int rgbFormat = (bitdepth == 8 ? RGBFB_CLUT : (bitdepth == 16 ? RGBFB_R5G6B5 : RGBFB_R8G8B8A8)); int pixelFormat = 1 << rgbFormat; pixelFormat |= RGBFF_CHUNKY; - - if (SDL_VideoModeOK (x_size_table[i], y_size_table[i], 16, SDL_SWSURFACE)) - { +// +// if (SDL_VideoModeOK (x_size_table[i], y_size_table[i], 16, SDL_SWSURFACE)) +// { DisplayModes[count].res.width = x_size_table[i]; DisplayModes[count].res.height = y_size_table[i]; DisplayModes[count].depth = bit_unit >> 3; @@ -803,7 +862,7 @@ void picasso_InitResolutions (void) DisplayModes[count].res.width, DisplayModes[count].res.height, DisplayModes[count].depth * 8); count++; - } +// } } } DisplayModes[count].depth = -1; diff --git a/src/osdep/pandora_gfx.h b/src/osdep/pandora_gfx.h new file mode 100644 index 00000000..042d1e5a --- /dev/null +++ b/src/osdep/pandora_gfx.h @@ -0,0 +1,10 @@ +#ifndef PANDORA_GFX_H +#define PANDORA_GFX_H + +extern SDL_Window* sdlWindow; +extern SDL_Renderer* renderer; +extern SDL_Texture *texture; +extern SDL_Surface *prSDLScreen; + +extern void check_error_sdl(bool check, const char* message); +#endif diff --git a/src/osdep/pandora_gui.cpp b/src/osdep/pandora_gui.cpp index fa0e9881..0548ffd1 100644 --- a/src/osdep/pandora_gui.cpp +++ b/src/osdep/pandora_gui.cpp @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include #include "sysconfig.h" #include "sysdeps.h" #include "config.h" @@ -12,7 +12,7 @@ #include "keybuf.h" #include "zfile.h" #include "gui.h" -#include "od-pandora/gui/SelectorEntry.hpp" +#include "osdep/gui/SelectorEntry.hpp" #include "gui/gui_handling.h" #include "memory.h" #include "rommgr.h" @@ -21,7 +21,7 @@ #include "inputdevice.h" #include "xwin.h" #include "drawing.h" -#include "sd-pandora/sound.h" +#include "sounddep/sound.h" #include "audio.h" #include "keybuf.h" #include "keyboard.h" @@ -31,7 +31,7 @@ #include "autoconf.h" #include "blkdev.h" #include -#include "td-sdl/thread.h" +#include "threaddep/thread.h" #ifdef RASPBERRY #include @@ -591,18 +591,21 @@ extern char keyboard_type; void gui_handle_events (void) { - Uint8 *keystate = SDL_GetKeyState(NULL); - +// Uint8 *keystate = SDL_GetKeyState(NULL); + const Uint8 *keystate = SDL_GetKeyboardState(NULL); + // Strangely in FBCON left window is seen as left alt ?? - if (keyboard_type == 2) // KEYCODE_FBCON - { - if(keystate[SDLK_LCTRL] && (keystate[SDLK_LSUPER] || keystate[SDLK_LALT]) && (keystate[SDLK_RSUPER] ||keystate[SDLK_MENU])) - uae_reset(0,1); - } else - { - if(keystate[SDLK_LCTRL] && keystate[SDLK_LSUPER] && (keystate[SDLK_RSUPER] ||keystate[SDLK_MENU])) - uae_reset(0,1); - } +// if (keyboard_type == 2) // KEYCODE_FBCON +// { +// if(keystate[SDLK_LCTRL] && (keystate[SDLK_LSUPER] || keystate[SDLK_LALT]) && (keystate[SDLK_RSUPER] ||keystate[SDLK_MENU])) +// uae_reset(0,1); +// } else +// { +// if(keystate[SDLK_LCTRL] && keystate[SDLK_LSUPER] && (keystate[SDLK_RSUPER] ||keystate[SDLK_MENU])) +// uae_reset(0,1); +// } + if (keystate[SDLK_LCTRL] && keystate[SDLK_LGUI] && (keystate[SDLK_RGUI] || keystate[SDLK_MENU])) + uae_reset(0, 1); } void gui_disk_image_change (int unitnum, const char *name, bool writeprotected) diff --git a/src/osdep/picasso96.cpp b/src/osdep/picasso96.cpp index 7492219b..ccb65434 100644 --- a/src/osdep/picasso96.cpp +++ b/src/osdep/picasso96.cpp @@ -46,7 +46,7 @@ #include "config.h" #include "options.h" -#include "td-sdl/thread.h" +#include "threaddep/thread.h" #include "memory.h" #include "custom.h" #include "newcpu.h" diff --git a/src/sounddep/sound_sdl_new.cpp b/src/sounddep/sound_sdl_new.cpp index 5167fc14..595e1461 100644 --- a/src/sounddep/sound_sdl_new.cpp +++ b/src/sounddep/sound_sdl_new.cpp @@ -21,7 +21,7 @@ #include "custom.h" #include "audio.h" #include "gensound.h" -#include "sd-pandora/sound.h" +#include "sounddep/sound.h" #include #ifdef ANDROIDSDL diff --git a/src/threaddep/thread.h b/src/threaddep/thread.h index e4a7742c..4d62fb4c 100644 --- a/src/threaddep/thread.h +++ b/src/threaddep/thread.h @@ -6,8 +6,8 @@ * Copyright 1997, 2001 Bernd Schmidt */ -#include "SDL.h" -#include "SDL_thread.h" +#include +#include /* Sempahores. We use POSIX semaphores; if you are porting this to a machine * with different ones, make them look like POSIX semaphores. */ @@ -40,7 +40,8 @@ STATIC_INLINE void uae_set_thread_priority (uae_thread_id *id, int pri) STATIC_INLINE int uae_start_thread (const TCHAR *name, void *(*f) (void *), void *arg, uae_thread_id *foo) { - uae_thread_id id = SDL_CreateThread ((int (*)(void *))f, arg); +// uae_thread_id id = SDL_CreateThread ((int (*)(void *))f, arg); + uae_thread_id id = SDL_CreateThread((int(*)(void *))f, "StartThread", arg); if(foo != NULL) *foo = id; // dbg_add_thread(id, name); @@ -49,7 +50,8 @@ STATIC_INLINE int uae_start_thread (const TCHAR *name, void *(*f) (void *), void STATIC_INLINE int uae_start_thread_fast (void *(*f) (void *), void *arg, uae_thread_id *foo) { - uae_thread_id id = SDL_CreateThread ((int (*)(void *))f, arg); +// uae_thread_id id = SDL_CreateThread ((int (*)(void *))f, arg); + uae_thread_id id = SDL_CreateThread((int(*)(void *))f, "StartThreadFast", arg); if(foo != NULL) *foo = id; // dbg_add_thread(id, "");