From d5af01cef60230bfdd90dda14944075f896e2a93 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 31 May 2011 03:54:18 +0300 Subject: Allow use system guichan by automake switch --with-internalguichan=no. Cmake always using internal guichan. --- src/CMakeLists.txt | 99 +- src/Makefile.am | 102 +- src/guichan/actionevent.hpp | 114 -- src/guichan/actionlistener.hpp | 93 -- src/guichan/basiccontainer.hpp | 181 --- src/guichan/cliprectangle.hpp | 109 -- src/guichan/color.hpp | 173 --- src/guichan/defaultfont.hpp | 103 -- src/guichan/event.hpp | 94 -- src/guichan/exception.hpp | 177 --- src/guichan/focushandler.hpp | 397 ------- src/guichan/focuslistener.hpp | 101 -- src/guichan/font.hpp | 111 -- src/guichan/graphics.hpp | 291 ----- src/guichan/gui.hpp | 505 -------- src/guichan/image.hpp | 191 ---- src/guichan/imageloader.hpp | 100 -- src/guichan/include/guichan/actionevent.hpp | 114 ++ src/guichan/include/guichan/actionlistener.hpp | 93 ++ src/guichan/include/guichan/basiccontainer.hpp | 181 +++ src/guichan/include/guichan/cliprectangle.hpp | 109 ++ src/guichan/include/guichan/color.hpp | 173 +++ src/guichan/include/guichan/defaultfont.hpp | 103 ++ src/guichan/include/guichan/event.hpp | 94 ++ src/guichan/include/guichan/exception.hpp | 177 +++ src/guichan/include/guichan/focushandler.hpp | 397 +++++++ src/guichan/include/guichan/focuslistener.hpp | 101 ++ src/guichan/include/guichan/font.hpp | 111 ++ src/guichan/include/guichan/graphics.hpp | 291 +++++ src/guichan/include/guichan/gui.hpp | 505 ++++++++ src/guichan/include/guichan/image.hpp | 191 ++++ src/guichan/include/guichan/imageloader.hpp | 100 ++ src/guichan/include/guichan/input.hpp | 115 ++ src/guichan/include/guichan/inputevent.hpp | 159 +++ src/guichan/include/guichan/key.hpp | 182 +++ src/guichan/include/guichan/keyevent.hpp | 138 +++ src/guichan/include/guichan/keyinput.hpp | 270 +++++ src/guichan/include/guichan/keylistener.hpp | 101 ++ src/guichan/include/guichan/listmodel.hpp | 86 ++ src/guichan/include/guichan/mouseevent.hpp | 200 ++++ src/guichan/include/guichan/mouseinput.hpp | 241 ++++ src/guichan/include/guichan/mouselistener.hpp | 189 +++ src/guichan/include/guichan/platform.hpp | 79 ++ src/guichan/include/guichan/rectangle.hpp | 140 +++ src/guichan/include/guichan/sdl/sdlgraphics.hpp | 156 +++ src/guichan/include/guichan/sdl/sdlimage.hpp | 107 ++ src/guichan/include/guichan/sdl/sdlpixel.hpp | 281 +++++ src/guichan/include/guichan/selectionevent.hpp | 78 ++ src/guichan/include/guichan/widget.hpp | 1202 ++++++++++++++++++++ src/guichan/include/guichan/widgetlistener.hpp | 124 ++ src/guichan/include/guichan/widgets/button.hpp | 220 ++++ src/guichan/include/guichan/widgets/checkbox.hpp | 173 +++ src/guichan/include/guichan/widgets/container.hpp | 162 +++ src/guichan/include/guichan/widgets/dropdown.hpp | 325 ++++++ src/guichan/include/guichan/widgets/icon.hpp | 118 ++ .../include/guichan/widgets/imagebutton.hpp | 123 ++ src/guichan/include/guichan/widgets/label.hpp | 133 +++ src/guichan/include/guichan/widgets/listbox.hpp | 253 ++++ .../include/guichan/widgets/radiobutton.hpp | 211 ++++ src/guichan/include/guichan/widgets/scrollarea.hpp | 590 ++++++++++ src/guichan/include/guichan/widgets/slider.hpp | 300 +++++ src/guichan/include/guichan/widgets/tab.hpp | 157 +++ src/guichan/include/guichan/widgets/tabbedarea.hpp | 280 +++++ src/guichan/include/guichan/widgets/textbox.hpp | 289 +++++ src/guichan/include/guichan/widgets/textfield.hpp | 177 +++ src/guichan/include/guichan/widgets/window.hpp | 261 +++++ src/guichan/input.hpp | 115 -- src/guichan/inputevent.hpp | 159 --- src/guichan/key.hpp | 182 --- src/guichan/keyevent.hpp | 138 --- src/guichan/keyinput.hpp | 270 ----- src/guichan/keylistener.hpp | 101 -- src/guichan/listmodel.hpp | 86 -- src/guichan/mouseevent.hpp | 200 ---- src/guichan/mouseinput.hpp | 241 ---- src/guichan/mouselistener.hpp | 189 --- src/guichan/platform.hpp | 79 -- src/guichan/rectangle.hpp | 140 --- src/guichan/sdl/sdlgraphics.hpp | 156 --- src/guichan/sdl/sdlimage.hpp | 107 -- src/guichan/sdl/sdlpixel.hpp | 281 ----- src/guichan/selectionevent.hpp | 78 -- src/guichan/widget.hpp | 1202 -------------------- src/guichan/widgetlistener.hpp | 124 -- src/guichan/widgets/button.hpp | 220 ---- src/guichan/widgets/checkbox.hpp | 173 --- src/guichan/widgets/container.hpp | 162 --- src/guichan/widgets/dropdown.hpp | 325 ------ src/guichan/widgets/icon.hpp | 118 -- src/guichan/widgets/imagebutton.hpp | 123 -- src/guichan/widgets/label.hpp | 133 --- src/guichan/widgets/listbox.hpp | 253 ---- src/guichan/widgets/radiobutton.hpp | 211 ---- src/guichan/widgets/scrollarea.hpp | 590 ---------- src/guichan/widgets/slider.hpp | 300 ----- src/guichan/widgets/tab.hpp | 157 --- src/guichan/widgets/tabbedarea.hpp | 280 ----- src/guichan/widgets/textbox.hpp | 289 ----- src/guichan/widgets/textfield.hpp | 177 --- src/guichan/widgets/window.hpp | 261 ----- 100 files changed, 10463 insertions(+), 10458 deletions(-) delete mode 100644 src/guichan/actionevent.hpp delete mode 100644 src/guichan/actionlistener.hpp delete mode 100644 src/guichan/basiccontainer.hpp delete mode 100644 src/guichan/cliprectangle.hpp delete mode 100644 src/guichan/color.hpp delete mode 100644 src/guichan/defaultfont.hpp delete mode 100644 src/guichan/event.hpp delete mode 100644 src/guichan/exception.hpp delete mode 100644 src/guichan/focushandler.hpp delete mode 100644 src/guichan/focuslistener.hpp delete mode 100644 src/guichan/font.hpp delete mode 100644 src/guichan/graphics.hpp delete mode 100644 src/guichan/gui.hpp delete mode 100644 src/guichan/image.hpp delete mode 100644 src/guichan/imageloader.hpp create mode 100644 src/guichan/include/guichan/actionevent.hpp create mode 100644 src/guichan/include/guichan/actionlistener.hpp create mode 100644 src/guichan/include/guichan/basiccontainer.hpp create mode 100644 src/guichan/include/guichan/cliprectangle.hpp create mode 100644 src/guichan/include/guichan/color.hpp create mode 100644 src/guichan/include/guichan/defaultfont.hpp create mode 100644 src/guichan/include/guichan/event.hpp create mode 100644 src/guichan/include/guichan/exception.hpp create mode 100644 src/guichan/include/guichan/focushandler.hpp create mode 100644 src/guichan/include/guichan/focuslistener.hpp create mode 100644 src/guichan/include/guichan/font.hpp create mode 100644 src/guichan/include/guichan/graphics.hpp create mode 100644 src/guichan/include/guichan/gui.hpp create mode 100644 src/guichan/include/guichan/image.hpp create mode 100644 src/guichan/include/guichan/imageloader.hpp create mode 100644 src/guichan/include/guichan/input.hpp create mode 100644 src/guichan/include/guichan/inputevent.hpp create mode 100644 src/guichan/include/guichan/key.hpp create mode 100644 src/guichan/include/guichan/keyevent.hpp create mode 100644 src/guichan/include/guichan/keyinput.hpp create mode 100644 src/guichan/include/guichan/keylistener.hpp create mode 100644 src/guichan/include/guichan/listmodel.hpp create mode 100644 src/guichan/include/guichan/mouseevent.hpp create mode 100644 src/guichan/include/guichan/mouseinput.hpp create mode 100644 src/guichan/include/guichan/mouselistener.hpp create mode 100644 src/guichan/include/guichan/platform.hpp create mode 100644 src/guichan/include/guichan/rectangle.hpp create mode 100644 src/guichan/include/guichan/sdl/sdlgraphics.hpp create mode 100644 src/guichan/include/guichan/sdl/sdlimage.hpp create mode 100644 src/guichan/include/guichan/sdl/sdlpixel.hpp create mode 100644 src/guichan/include/guichan/selectionevent.hpp create mode 100644 src/guichan/include/guichan/widget.hpp create mode 100644 src/guichan/include/guichan/widgetlistener.hpp create mode 100644 src/guichan/include/guichan/widgets/button.hpp create mode 100644 src/guichan/include/guichan/widgets/checkbox.hpp create mode 100644 src/guichan/include/guichan/widgets/container.hpp create mode 100644 src/guichan/include/guichan/widgets/dropdown.hpp create mode 100644 src/guichan/include/guichan/widgets/icon.hpp create mode 100644 src/guichan/include/guichan/widgets/imagebutton.hpp create mode 100644 src/guichan/include/guichan/widgets/label.hpp create mode 100644 src/guichan/include/guichan/widgets/listbox.hpp create mode 100644 src/guichan/include/guichan/widgets/radiobutton.hpp create mode 100644 src/guichan/include/guichan/widgets/scrollarea.hpp create mode 100644 src/guichan/include/guichan/widgets/slider.hpp create mode 100644 src/guichan/include/guichan/widgets/tab.hpp create mode 100644 src/guichan/include/guichan/widgets/tabbedarea.hpp create mode 100644 src/guichan/include/guichan/widgets/textbox.hpp create mode 100644 src/guichan/include/guichan/widgets/textfield.hpp create mode 100644 src/guichan/include/guichan/widgets/window.hpp delete mode 100644 src/guichan/input.hpp delete mode 100644 src/guichan/inputevent.hpp delete mode 100644 src/guichan/key.hpp delete mode 100644 src/guichan/keyevent.hpp delete mode 100644 src/guichan/keyinput.hpp delete mode 100644 src/guichan/keylistener.hpp delete mode 100644 src/guichan/listmodel.hpp delete mode 100644 src/guichan/mouseevent.hpp delete mode 100644 src/guichan/mouseinput.hpp delete mode 100644 src/guichan/mouselistener.hpp delete mode 100644 src/guichan/platform.hpp delete mode 100644 src/guichan/rectangle.hpp delete mode 100644 src/guichan/sdl/sdlgraphics.hpp delete mode 100644 src/guichan/sdl/sdlimage.hpp delete mode 100644 src/guichan/sdl/sdlpixel.hpp delete mode 100644 src/guichan/selectionevent.hpp delete mode 100644 src/guichan/widget.hpp delete mode 100644 src/guichan/widgetlistener.hpp delete mode 100644 src/guichan/widgets/button.hpp delete mode 100644 src/guichan/widgets/checkbox.hpp delete mode 100644 src/guichan/widgets/container.hpp delete mode 100644 src/guichan/widgets/dropdown.hpp delete mode 100644 src/guichan/widgets/icon.hpp delete mode 100644 src/guichan/widgets/imagebutton.hpp delete mode 100644 src/guichan/widgets/label.hpp delete mode 100644 src/guichan/widgets/listbox.hpp delete mode 100644 src/guichan/widgets/radiobutton.hpp delete mode 100644 src/guichan/widgets/scrollarea.hpp delete mode 100644 src/guichan/widgets/slider.hpp delete mode 100644 src/guichan/widgets/tab.hpp delete mode 100644 src/guichan/widgets/tabbedarea.hpp delete mode 100644 src/guichan/widgets/textbox.hpp delete mode 100644 src/guichan/widgets/textfield.hpp delete mode 100644 src/guichan/widgets/window.hpp (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 29a0c610d..4501f4cca 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -68,6 +68,7 @@ IF (USE_X11) ENDIF (USE_X11) INCLUDE_DIRECTORIES( + "guichan/include" ${CMAKE_CURRENT_SOURCE_DIR} ${SDL_INCLUDE_DIR} ${SDLIMAGE_INCLUDE_DIR} @@ -573,55 +574,55 @@ SET(SRCS ) SET(SRCS_GUICHAN - guichan/actionevent.hpp - guichan/actionlistener.hpp - guichan/basiccontainer.hpp - guichan/cliprectangle.hpp - guichan/color.hpp - guichan/defaultfont.hpp - guichan/event.hpp - guichan/exception.hpp - guichan/focushandler.hpp - guichan/focuslistener.hpp - guichan/font.hpp - guichan/graphics.hpp - guichan/gui.hpp - guichan/image.hpp - guichan/imageloader.hpp - guichan/input.hpp - guichan/inputevent.hpp - guichan/key.hpp - guichan/keyevent.hpp - guichan/keyinput.hpp - guichan/keylistener.hpp - guichan/listmodel.hpp - guichan/mouseevent.hpp - guichan/mouseinput.hpp - guichan/mouselistener.hpp - guichan/platform.hpp - guichan/rectangle.hpp - guichan/selectionevent.hpp - guichan/sdl/sdlgraphics.hpp - guichan/sdl/sdlimage.hpp - guichan/sdl/sdlpixel.hpp - guichan/widget.hpp - guichan/widgetlistener.hpp - guichan/widgets/button.hpp - guichan/widgets/checkbox.hpp - guichan/widgets/container.hpp - guichan/widgets/dropdown.hpp - guichan/widgets/icon.hpp - guichan/widgets/imagebutton.hpp - guichan/widgets/label.hpp - guichan/widgets/listbox.hpp - guichan/widgets/radiobutton.hpp - guichan/widgets/scrollarea.hpp - guichan/widgets/slider.hpp - guichan/widgets/tabbedarea.hpp - guichan/widgets/tab.hpp - guichan/widgets/textbox.hpp - guichan/widgets/textfield.hpp - guichan/widgets/window.hpp + guichan/include/guichan/actionevent.hpp + guichan/include/guichan/actionlistener.hpp + guichan/include/guichan/basiccontainer.hpp + guichan/include/guichan/cliprectangle.hpp + guichan/include/guichan/color.hpp + guichan/include/guichan/defaultfont.hpp + guichan/include/guichan/event.hpp + guichan/include/guichan/exception.hpp + guichan/include/guichan/focushandler.hpp + guichan/include/guichan/focuslistener.hpp + guichan/include/guichan/font.hpp + guichan/include/guichan/graphics.hpp + guichan/include/guichan/gui.hpp + guichan/include/guichan/image.hpp + guichan/include/guichan/imageloader.hpp + guichan/include/guichan/input.hpp + guichan/include/guichan/inputevent.hpp + guichan/include/guichan/key.hpp + guichan/include/guichan/keyevent.hpp + guichan/include/guichan/keyinput.hpp + guichan/include/guichan/keylistener.hpp + guichan/include/guichan/listmodel.hpp + guichan/include/guichan/mouseevent.hpp + guichan/include/guichan/mouseinput.hpp + guichan/include/guichan/mouselistener.hpp + guichan/include/guichan/platform.hpp + guichan/include/guichan/rectangle.hpp + guichan/include/guichan/selectionevent.hpp + guichan/include/guichan/sdl/sdlgraphics.hpp + guichan/include/guichan/sdl/sdlimage.hpp + guichan/include/guichan/sdl/sdlpixel.hpp + guichan/include/guichan/widget.hpp + guichan/include/guichan/widgetlistener.hpp + guichan/include/guichan/widgets/button.hpp + guichan/include/guichan/widgets/checkbox.hpp + guichan/include/guichan/widgets/container.hpp + guichan/include/guichan/widgets/dropdown.hpp + guichan/include/guichan/widgets/icon.hpp + guichan/include/guichan/widgets/imagebutton.hpp + guichan/include/guichan/widgets/label.hpp + guichan/include/guichan/widgets/listbox.hpp + guichan/include/guichan/widgets/radiobutton.hpp + guichan/include/guichan/widgets/scrollarea.hpp + guichan/include/guichan/widgets/slider.hpp + guichan/include/guichan/widgets/tabbedarea.hpp + guichan/include/guichan/widgets/tab.hpp + guichan/include/guichan/widgets/textbox.hpp + guichan/include/guichan/widgets/textfield.hpp + guichan/include/guichan/widgets/window.hpp guichan/actionevent.cpp guichan/basiccontainer.cpp guichan/cliprectangle.cpp diff --git a/src/Makefile.am b/src/Makefile.am index a5894458d..63a5141ab 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,5 @@ AUTOMAKE_OPTIONS = subdir-objects +#AUTOMAKE_OPTIONS = subdir-objects nostdinc bin_PROGRAMS = manaplus @@ -21,55 +22,57 @@ else manaplus_SOURCES = endif -manaplus_SOURCES += guichan/actionevent.hpp \ - guichan/actionlistener.hpp \ - guichan/basiccontainer.hpp \ - guichan/cliprectangle.hpp \ - guichan/color.hpp \ - guichan/defaultfont.hpp \ - guichan/event.hpp \ - guichan/exception.hpp \ - guichan/focushandler.hpp \ - guichan/focuslistener.hpp \ - guichan/font.hpp \ - guichan/graphics.hpp \ - guichan/gui.hpp \ - guichan/image.hpp \ - guichan/imageloader.hpp \ - guichan/input.hpp \ - guichan/inputevent.hpp \ - guichan/key.hpp \ - guichan/keyevent.hpp \ - guichan/keyinput.hpp \ - guichan/keylistener.hpp \ - guichan/listmodel.hpp \ - guichan/mouseevent.hpp \ - guichan/mouseinput.hpp \ - guichan/mouselistener.hpp \ - guichan/platform.hpp \ - guichan/rectangle.hpp \ - guichan/selectionevent.hpp \ - guichan/sdl/sdlgraphics.hpp \ - guichan/sdl/sdlimage.hpp \ - guichan/sdl/sdlpixel.hpp \ - guichan/widget.hpp \ - guichan/widgetlistener.hpp \ - guichan/widgets/button.hpp \ - guichan/widgets/checkbox.hpp \ - guichan/widgets/container.hpp \ - guichan/widgets/dropdown.hpp \ - guichan/widgets/icon.hpp \ - guichan/widgets/imagebutton.hpp \ - guichan/widgets/label.hpp \ - guichan/widgets/listbox.hpp \ - guichan/widgets/radiobutton.hpp \ - guichan/widgets/scrollarea.hpp \ - guichan/widgets/slider.hpp \ - guichan/widgets/tabbedarea.hpp \ - guichan/widgets/tab.hpp \ - guichan/widgets/textbox.hpp \ - guichan/widgets/textfield.hpp \ - guichan/widgets/window.hpp +if USE_INTERNALGUICHAN +manaplus_CXXFLAGS += -DUSE_INTERNALGUICHAN +manaplus_SOURCES += guichan/include/guichan/actionevent.hpp \ + guichan/include/guichan/actionlistener.hpp \ + guichan/include/guichan/basiccontainer.hpp \ + guichan/include/guichan/cliprectangle.hpp \ + guichan/include/guichan/color.hpp \ + guichan/include/guichan/defaultfont.hpp \ + guichan/include/guichan/event.hpp \ + guichan/include/guichan/exception.hpp \ + guichan/include/guichan/focushandler.hpp \ + guichan/include/guichan/focuslistener.hpp \ + guichan/include/guichan/font.hpp \ + guichan/include/guichan/graphics.hpp \ + guichan/include/guichan/gui.hpp \ + guichan/include/guichan/image.hpp \ + guichan/include/guichan/imageloader.hpp \ + guichan/include/guichan/input.hpp \ + guichan/include/guichan/inputevent.hpp \ + guichan/include/guichan/key.hpp \ + guichan/include/guichan/keyevent.hpp \ + guichan/include/guichan/keyinput.hpp \ + guichan/include/guichan/keylistener.hpp \ + guichan/include/guichan/listmodel.hpp \ + guichan/include/guichan/mouseevent.hpp \ + guichan/include/guichan/mouseinput.hpp \ + guichan/include/guichan/mouselistener.hpp \ + guichan/include/guichan/platform.hpp \ + guichan/include/guichan/rectangle.hpp \ + guichan/include/guichan/selectionevent.hpp \ + guichan/include/guichan/sdl/sdlgraphics.hpp \ + guichan/include/guichan/sdl/sdlimage.hpp \ + guichan/include/guichan/sdl/sdlpixel.hpp \ + guichan/include/guichan/widget.hpp \ + guichan/include/guichan/widgetlistener.hpp \ + guichan/include/guichan/widgets/button.hpp \ + guichan/include/guichan/widgets/checkbox.hpp \ + guichan/include/guichan/widgets/container.hpp \ + guichan/include/guichan/widgets/dropdown.hpp \ + guichan/include/guichan/widgets/icon.hpp \ + guichan/include/guichan/widgets/imagebutton.hpp \ + guichan/include/guichan/widgets/label.hpp \ + guichan/include/guichan/widgets/listbox.hpp \ + guichan/include/guichan/widgets/radiobutton.hpp \ + guichan/include/guichan/widgets/scrollarea.hpp \ + guichan/include/guichan/widgets/slider.hpp \ + guichan/include/guichan/widgets/tabbedarea.hpp \ + guichan/include/guichan/widgets/tab.hpp \ + guichan/include/guichan/widgets/textbox.hpp \ + guichan/include/guichan/widgets/textfield.hpp \ + guichan/include/guichan/widgets/window.hpp manaplus_SOURCES += guichan/actionevent.cpp \ guichan/basiccontainer.cpp \ @@ -110,6 +113,7 @@ manaplus_SOURCES += guichan/actionevent.cpp \ guichan/widgets/textbox.cpp \ guichan/widgets/textfield.cpp \ guichan/widgets/window.cpp +endif manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/widgets/avatarlistbox.h \ diff --git a/src/guichan/actionevent.hpp b/src/guichan/actionevent.hpp deleted file mode 100644 index c897e9b4b..000000000 --- a/src/guichan/actionevent.hpp +++ /dev/null @@ -1,114 +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. - */ - -#ifndef GCN_ACTIONEVENT_HPP -#define GCN_ACTIONEVENT_HPP - -#include "guichan/event.hpp" -#include "guichan/platform.hpp" - -#include - -namespace gcn -{ - class Widget; - - /** - * Represents an action event. An action event is an event - * that can be fired by a widget whenever an action has occured. - * What exactly an action is is up to the widget that fires - * the action event. An example is a Button which fires an action - * event as soon as the Button is clicked, another example is - * TextField which fires an action event as soon as the enter - * key is pressed. - * - * Any object can listen for actions from widgets by implementing - * the ActionListener interface. - * - * If you have implement a widget of your own it's a good idea to - * let the widget fire action events whenever you feel an action - * has occured so action listeners of the widget can be informed - * of the state of the widget. - * - * @see Widget::addActionListener, Widget::removeActionListener, - * Widget::distributeActionEvent - * @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 An identifier of the event. - */ - ActionEvent(Widget* source, const std::string& id); - - /** - * Destructor. - */ - virtual ~ActionEvent(); - - /** - * Gets the identifier of the event. An identifier can - * be used to distinguish from two actions from the same - * widget or to let many widgets fire the same widgets - * that should be treated equally. - * - * @return The identifier of the event. - */ - const std::string& getId() const; - - protected: - /** - * Holds the identifier of the event. - */ - std::string mId; - }; -} - -#endif // GCN_ACTIONEVENT_HPP - diff --git a/src/guichan/actionlistener.hpp b/src/guichan/actionlistener.hpp deleted file mode 100644 index 0f750099c..000000000 --- a/src/guichan/actionlistener.hpp +++ /dev/null @@ -1,93 +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. - */ - -#ifndef GCN_ACTIONLISTENER_HPP -#define GCN_ACTIONLISTENER_HPP - -#include - -#include "guichan/actionevent.hpp" -#include "guichan/platform.hpp" - -namespace gcn -{ - /** - * Interface for listening for action events from widgets. - * - * @see Widget::addActionListener, Widget::removeActionListener, - * ActionEvent - * @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; - - protected: - /** - * Constructor. - * - * You should not be able to make an instance of ActionListener, - * therefore its constructor is protected. - */ - ActionListener() { } - - }; -} - -#endif // end GCN_ACTIONLISTENER_HPP diff --git a/src/guichan/basiccontainer.hpp b/src/guichan/basiccontainer.hpp deleted file mode 100644 index 269a5ba44..000000000 --- a/src/guichan/basiccontainer.hpp +++ /dev/null @@ -1,181 +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. - */ - -#ifndef GCN_BASICCONTAINER_HPP -#define GCN_BASICCONTAINER_HPP - -#include - -#include "guichan/deathlistener.hpp" -#include "guichan/platform.hpp" -#include "guichan/widget.hpp" - -namespace gcn -{ - /** - * A base class for containers. The class implements the most - * common things for a container. If you are implementing a - * container, consider inheriting from this class. - * - * @see Container - * @since 0.6.0 - */ - class GCN_CORE_DECLSPEC BasicContainer : public Widget, - public DeathListener - { - public: - /** - * Destructor - */ - virtual ~BasicContainer(); - - /** - * Shows a certain part of a widget in the basic container. - * Used when widgets want a specific part to be visible in - * its parent. An example is a TextArea that wants a specific - * part of its text to be visible when a TextArea is a child - * of a ScrollArea. - * - * @param widget The widget whom wants a specific part of - * itself to be visible. - * @param rectangle The rectangle to be visible. - */ - virtual void showWidgetPart(Widget* widget, Rectangle area); - - - // 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 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. - * @see remove, clear - */ - void add(Widget* widget); - - /** - * Removes a widget from the basic container. - * - * @param widget The widget to remove. - * @see add, clear - */ - virtual void remove(Widget* widget); - - /** - * Clears the basic container from all widgets. - * - * @see remove, clear - */ - virtual void clear(); - - /** - * Draws the children widgets of the basic container. - * - * @param graphics A graphics object to draw with. - */ - virtual void drawChildren(Graphics* graphics); - - /** - * Calls logic for the children widgets of the basic - * container. - */ - virtual void logicChildren(); - - /** - * Finds a widget given an id. This function can be useful - * when implementing a GUI generator for Guichan, such as - * the ability to create a Guichan GUI from an XML file. - * - * @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. - */ - typedef std::list WidgetList; - - /** - * Typedef. - */ - typedef WidgetList::iterator WidgetListIterator; - - /** - * Typedef. - */ - typedef WidgetList::reverse_iterator WidgetListReverseIterator; - - /** - * Holds all widgets of the basic container. - */ - WidgetList mWidgets; - }; -} - -#endif // end GCN_BASICCONTAINER_HPP diff --git a/src/guichan/cliprectangle.hpp b/src/guichan/cliprectangle.hpp deleted file mode 100644 index 792c40bb9..000000000 --- a/src/guichan/cliprectangle.hpp +++ /dev/null @@ -1,109 +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. - */ - -#ifndef GCN_CLIPRECTANGLE_HPP -#define GCN_CLIPRECTANGLE_HPP - -#include "guichan/rectangle.hpp" -#include "guichan/platform.hpp" - -namespace gcn -{ - /** - * A rectangle used when dealing with clipping. A clip rectangle is - * a regular rectangle extended with variables for x offsets and y - * offsets. The offsets are used for calculations from relative - * screen coordinates to actual screen coordinates. - */ - class GCN_CORE_DECLSPEC ClipRectangle : public Rectangle - { - public: - - /** - * Constructor. - */ - ClipRectangle(); - - /** - * Constructor. - * - * @param x The rectangle x coordinate. - * @param y The rectangle y coordinate. - * @param width The rectangle width. - * @param height The rectangle height. - * @param xOffset The offset of the x coordinate. Used to for - * calculating the actual screen coordinate from - * the relative screen coordinate. - * @param yOffset The offset of the y coordinate. Used to for - * calculating the actual screen coordinate from - * the relative screen coordinate. - */ - ClipRectangle(int x, - int y, - int width, - int height, - int xOffset, - int yOffset); - - /** - * Copy constructor. Copies x, y, width and height - * field from a rectangle to a clip rectangle. - * - * @param other The rectangle to copy data from. - * @returns A clip rectangle with data copyied from a rectangle. - */ - const ClipRectangle& operator=(const Rectangle& other); - - /** - * Holds the x offset of the x coordinate. - */ - int xOffset; - - /** - * Holds the y offset of the y coordinate. - */ - int yOffset; - }; -} - -#endif // end GCN_CLIPRECTANGLE_HPP diff --git a/src/guichan/color.hpp b/src/guichan/color.hpp deleted file mode 100644 index b7e324c07..000000000 --- a/src/guichan/color.hpp +++ /dev/null @@ -1,173 +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. - */ - -#ifndef GCN_COLOR_HPP -#define GCN_COLOR_HPP - -#include "guichan/platform.hpp" - -#include - -namespace gcn -{ - /** - * Represents a color with red, green, blue and alpha components. - */ - class GCN_CORE_DECLSPEC Color - { - public: - - /** - * Constructor. Initializes the color to black. - */ - Color(); - - /** - * Constructor. Constructs a color from the bytes in an integer. - * Call it with a hexadecimal constant for HTML-style color representation. - * The alpha component is 255 by default. - * - * EXAMPLE: Color(0xff50a0) constructs a very nice pinkish color. - * - * NOTE: Because of this constructor, integers will be automatically - * casted to a color by your compiler. - * - * @param color The color to initialise the object with. - */ - Color(int color); - - /** - * Constructor. The default alpha value is 255. - * - * @param r Red color component (range 0-255). - * @param g Green color component (range 0-255). - * @param b Blue color component (range 0-255). - * @param a Alpha, used for transparency. A value of 0 means - * totaly transparent, 255 is totaly opaque. - */ - Color(int r, int g, int b, int a = 255); - - /** - * Adds the RGB values of two colors together. The values will be - * clamped if they go out of range. - * - * WARNING: This function will reset the alpha value of the - * returned color to 255. - * - * @param color A color to add to this color. - * @return The added colors with an alpha value set to 255. - */ - Color operator+(const Color& color) const; - - /** - * Subtracts the RGB values of one color from another. - * The values will be clamped if they go out of range. - * - * WARNING: This function will reset the alpha value of the - * returned color to 255. - * - * @param color A color to subtract from this color. - * @return The subtracted colors with an alpha value set to 255. - */ - Color operator-(const Color& color) const; - - /** - * Multiplies the RGB values of a color with a float value. - * The values will be clamped if they go out of range. - * - * @param value The value to multiply the color with. - * @return The multiplied colors. The alpha value will, unlike - * the add and subtract operations, be multiplied as - * well. - */ - Color operator*(float value) const; - - /** - * Compares two colors. - * - * @return True if the two colors have the same RGBA components - * false otherwise. - */ - bool operator==(const Color& color) const; - - /** - * Compares two colors. - * - * @return True if the two colors have different RGBA components, - * false otherwise. - */ - bool operator!=(const Color& color) const; - - /** - * Output operator for output. - * - * @param out The stream to output to. - * @param color The color to output. - */ - friend std::ostream& operator<<(std::ostream& out, - const Color& Color); - - /** - * Holds the red color component (range 0-255). - */ - int r; - - /** - * Holds the green color component (range 0-255). - */ - int g; - - /** - * Holds the blue color component (range 0-255). - */ - int b; - - /** - * Holds the alpha color component. A value of 0 means totally - * transparent while a value of 255 is considered opaque. - */ - int a; - }; -} - -#endif // end GCN_COLOR_HPP diff --git a/src/guichan/defaultfont.hpp b/src/guichan/defaultfont.hpp deleted file mode 100644 index e5a830e4c..000000000 --- a/src/guichan/defaultfont.hpp +++ /dev/null @@ -1,103 +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. - */ - -#ifndef GCN_DEFAULTFONT_HPP -#define GCN_DEFAULTFONT_HPP - -#include "guichan/font.hpp" -#include "guichan/platform.hpp" - -#ifdef __GNUC__ -#define _UNUSED_ __attribute__ ((unused)) -#else -#define _UNUSED_ -#endif - -namespace gcn -{ - /** - * A font only capable of drawing rectangles. It is used by default - * in Guichan if no font has been set merely to show that no font has - * been set. - */ - class GCN_CORE_DECLSPEC DefaultFont : public Font - { - public: - - /** - * Destructor. - */ - virtual ~DefaultFont(){} - - /** - * Draws a glyph as a rectangle. The glyphs will always be drawn as - * rectangles no matter the glyph. - * - * NOTE: You normally won't use this function to draw text since - * the Graphics class contains better functions for drawing - * text. - * - * @param graphics A Graphics object to be used for drawing. - * @param glyph The 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 drawn glyph in pixels. - */ - virtual int drawGlyph(Graphics* graphics, unsigned char glyph, - int x, int y); - - - // Inherited from Font - - virtual void drawString(Graphics* graphics, const std::string& text, - int x, int y); - - virtual int getWidth(const std::string& text) const; - - virtual int getHeight() const; - - virtual int getStringIndexAt(const std::string& text, int x) const; - }; -} - -#endif // end GCN_DEFAULTFONT_HPP diff --git a/src/guichan/event.hpp b/src/guichan/event.hpp deleted file mode 100644 index 107e34fc2..000000000 --- a/src/guichan/event.hpp +++ /dev/null @@ -1,94 +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. - */ - -#ifndef GCN_EVENT_HPP -#define GCN_EVENT_HPP - -#include "guichan/platform.hpp" - -namespace gcn -{ - class Widget; - - /** - * Base class for all events. All events in Guichan should - * inherit from this class. - * - * @author Olof Naessén - * @since 0.6.0 - */ - class GCN_CORE_DECLSPEC Event - { - public: - - /** - * Constructor. - * - * @param source The source widget of the event. - */ - Event(Widget* source); - - /** - * Destructor. - */ - virtual ~Event(); - - /** - * Gets the source widget of the event. The function - * is used to tell which widget fired an event. - * - * @return The source widget of the event. - */ - Widget* getSource() const; - - - protected: - - /** - * Holds the source widget of the event. - */ - Widget* mSource; - }; -} - -#endif // end GCN_EVENT_HPP diff --git a/src/guichan/exception.hpp b/src/guichan/exception.hpp deleted file mode 100644 index 3ccf39e20..000000000 --- a/src/guichan/exception.hpp +++ /dev/null @@ -1,177 +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. - */ - -#ifndef GCN_EXCEPTION_HPP -#define GCN_EXCEPTION_HPP - -#include - -#include "guichan/platform.hpp" - -#ifndef __FUNCTION__ -#define __FUNCTION__ "?" -#endif - -/* - * A macro used to create a standard exception object. - * What it basicly does is that it creates a new exception - * and automatically sets the filename and line number where - * the exception occured by using other compiler macros. - */ -#define GCN_EXCEPTION(mess) gcn::Exception(mess, \ - __FUNCTION__, \ - __FILE__, \ - __LINE__) - -namespace gcn -{ - - /** - * An exception containing a message, a file and a line number - * where the exception occured. Guichan will only throw exceptions - * of this class. - * - * You can use this class for your own exceptions that has - * something to do with a GUI exception. 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 of the exception. - */ - Exception(const std::string& message); - - /** - * Constructor. - * - * NOTE: Don't use this constructor. Use the GCN_EXCEPTION macro instead. - * This constructor merely exists for the GCN_EXCEPTION macro to - * use. - * - * @param message The error message of the exception. - * @param function The function name where the exception occured. - * @param filename The name of the file where the exception occured. - * @param line The line number in the source code where the exception - * occured. - */ - Exception(const std::string& message, - const std::string& function, - const std::string& filename, - unsigned int line); - - /** - * Gets the function name where the exception occured. - * - * @return The function name where the exception occured. - */ - const std::string& getFunction() const; - - /** - * Gets the error message of the exception. - * - * @return The error message of the exception. - */ - const std::string& getMessage() const; - - /** - * Gets the filename where the exception occured. - * - * @return The filename where the exception occured. - */ - const std::string& getFilename() const; - - /** - * Gets the line number where the exception occured. - * - * @return The line number where the exception occured. - */ - unsigned int getLine() const; - - protected: - /** - * Holds the name of the function name where the - * exception occured. - */ - std::string mFunction; - - /** - * Holds the error message of the exception. - */ - std::string mMessage; - - /** - * Holds the filename where the exception occured. - */ - std::string mFilename; - - /** - * Holds the line number where the exception occured. - */ - unsigned 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/guichan/focushandler.hpp b/src/guichan/focushandler.hpp deleted file mode 100644 index 49bb4e2e5..000000000 --- a/src/guichan/focushandler.hpp +++ /dev/null @@ -1,397 +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. - */ - -#ifndef GCN_FOCUSHANDLER_HPP -#define GCN_FOCUSHANDLER_HPP - -#include - -#include "guichan/event.hpp" -#include "guichan/platform.hpp" - -namespace gcn -{ - class Widget; - - /** - * Handles focus for widgets in a Gui. Each Gui has at least one - * focus handler. - - * You will probably not use the focus handler directly as Widget - * has functions that automatically uses the active focus handler. - * - * @see Widget::isFocus, Widget::isModalFocused, - * Widget::isModalMouseInputFocused, Widget::requestFocus, - * Widget::requestModalFocus, Widget::requestModalMouseInputFocus, - * Widget::releaseModalFocus, Widget::relaseModalMouseInputFocus, - * Widget::setFocusable, Widget::isFocusable, FocusListener - * - * @since 0.1.0 - */ - class GCN_CORE_DECLSPEC FocusHandler - { - public: - - /** - * Constructor. - */ - FocusHandler(); - - /** - * Destructor. - */ - virtual ~FocusHandler() { }; - - /** - * Requests focus for a widget. Focus will only be granted to a widget - * if it's focusable and if no other widget has modal focus. - * If a widget receives focus a focus event will be sent to the - * focus listeners of the widget. - * - * @param widget The widget to request focus for. - * @see isFocused, Widget::requestFocus - */ - virtual void requestFocus(Widget* widget); - - /** - * Requests modal focus for a widget. Focus will only be granted - * to a widget if it's focusable and if no other widget has modal - * focus. - * - * @param widget The widget to request modal focus for. - * @throws Exception when another widget already has modal focus. - * @see releaseModalFocus, Widget::requestModalFocus - */ - virtual void requestModalFocus(Widget* widget); - - /** - * Requests modal mouse input focus for a widget. Focus will only - * be granted to a widget if it's focusable and if no other widget - * has modal mouse input focus. - * - * 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. - * @see releaseModalMouseInputFocus, Widget::requestModalMouseInputFocus - */ - virtual void requestModalMouseInputFocus(Widget* widget); - - /** - * Releases modal focus if the widget has modal focus. - * If the widget doesn't have modal focus no relase will occur. - * - * @param widget The widget to release modal focus for. - * @see reuqestModalFocus, Widget::releaseModalFocus - */ - virtual void releaseModalFocus(Widget* widget); - - /** - * Releases modal mouse input focus if the widget has modal mouse input - * focus. If the widget doesn't have modal mouse input focus no relase - * will occur. - * - * @param widget the widget to release modal mouse input focus for. - * @see requestModalMouseInputFocus, Widget::releaseModalMouseInputFocus - */ - virtual void releaseModalMouseInputFocus(Widget* widget); - - /** - * Checks if a widget is focused. - * - * @param widget The widget to check. - * @return True if the widget is focused, false otherwise. - * @see Widget::isFocused - */ - virtual bool isFocused(const Widget* widget) const; - - /** - * Gets the widget with focus. - * - * @return The widget with focus. NULL if no widget has focus. - */ - virtual Widget* getFocused() const; - - /** - * Gets the widget with modal focus. - * - * @return The widget with modal focus. NULL 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 if - * no widget has modal mouse input focus. - */ - virtual Widget* getModalMouseInputFocused() const; - - /** - * Focuses the next widget added to a conainer. - * If no widget has focus the first widget gets focus. The order - * in which the widgets are focused is determined by the order - * they were added to a container. - * - * @see focusPrevious - */ - virtual void focusNext(); - - /** - * Focuses the previous widget added to a contaienr. - * If no widget has focus the first widget gets focus. The order - * in which the widgets are focused is determined by the order - * they were added to a container. - * - * @see focusNext - */ - virtual void focusPrevious(); - - /** - * Adds a widget to by handles by the focus handler. - * - * @param widget The widget to add. - * @see remove - */ - virtual void add(Widget* widget); - - /** - * Removes a widget from the focus handler. - * - * @param widget The widget to remove. - * @see add - */ - 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 tabbing in unless - * the current focused Widget disallows tabbing out. - * - * @see tabPrevious - */ - virtual void tabNext(); - - /** - * Focuses the previous widget which allows tabbing in unless - * current focused widget disallows tabbing out. - * - * @see tabNext - */ - virtual void tabPrevious(); - - /** - * Gets the widget being dragged. Used by the Gui class to - * keep track of the dragged widget. - * - * @return the widget being dragged. - * @see setDraggedWidget - */ - virtual Widget* getDraggedWidget(); - - /** - * Sets the widget being dragged. Used by the Gui class to - * keep track of the dragged widget. - * - * @param draggedWidget The widget being dragged. - * @see getDraggedWidget - */ - virtual void setDraggedWidget(Widget* draggedWidget); - - /** - * Gets the last widget with the mouse. Used by the Gui class - * to keep track the last widget with the mouse. - * - * @return The last widget with the mouse. - * @see setLastWidgetWithMouse - */ - virtual Widget* getLastWidgetWithMouse(); - - /** - * Sets the last widget with the mouse. Used by the Gui class - * to keep track the last widget with the mouse. - * - * @param lastWidgetWithMouse The last widget with the mouse. - * @see getLastWidgetWithMouse - */ - virtual void setLastWidgetWithMouse(Widget* lastWidgetWithMouse); - - /** - * Gets the last widget with modal focus. - * - * @return The last widget with modal focus. - * @see setLastWidgetWithModalFocus - */ - virtual Widget* getLastWidgetWithModalFocus(); - - /** - * Sets the last widget with modal focus. - * - * @param widget The last widget with modal focus. - * @see getLastWidgetWithModalFocus - */ - virtual void setLastWidgetWithModalFocus(Widget* widget); - - /** - * Gets the last widget with modal mouse input focus. - * - * @return The last widget with modal mouse input focus. - * @see setLastWidgetWithModalMouseInputFocus - */ - virtual Widget* getLastWidgetWithModalMouseInputFocus(); - - /** - * Sets the last widget with modal mouse input focus. - * - * @param widget The last widget with modal mouse input focus. - * @see getLastWidgetWithModalMouseInputFocus - */ - virtual void setLastWidgetWithModalMouseInputFocus(Widget* widget); - - /** - * Gets the last widget pressed. Used by the Gui class to keep track - * of pressed widgets. - * - * @return The last widget pressed. - * @see setLastWidgetPressed - */ - virtual Widget* getLastWidgetPressed(); - - /** - * Sets the last widget pressed. Used by the Gui class to keep track - * of pressed widgets. - * - * @param lastWidgetPressed The last widget pressed. - * @see getLastWidgetPressed - */ - virtual void setLastWidgetPressed(Widget* lastWidgetPressed); - - protected: - /** - * Distributes a focus lost event. - * - * @param focusEvent the event to distribute. - * @since 0.7.0 - */ - virtual void distributeFocusLostEvent(const Event& focusEvent); - - /** - * Distributes a focus gained event. - * - * @param focusEvent the event to distribute. - * @since 0.7.0 - */ - virtual void distributeFocusGainedEvent(const Event& focusEvent); - - /** - * Typedef. - */ - typedef std::vector WidgetVector; - - /** - * Typedef. - */ - typedef WidgetVector::iterator WidgetIterator; - - /** - * Holds the widgets currently being handled by the - * focus handler. - */ - WidgetVector mWidgets; - - /** - * Holds the focused widget. NULL if no widget has focus. - */ - Widget* mFocusedWidget; - - /** - * Holds the modal focused widget. NULL if no widget has - * modal focused. - */ - Widget* mModalFocusedWidget; - - /** - * Holds the modal mouse input focused widget. NULL if no widget - * is being dragged. - */ - Widget* mModalMouseInputFocusedWidget; - - /** - * Holds the dragged widget. NULL if no widget is - * being dragged. - */ - Widget* mDraggedWidget; - - /** - * Holds the last widget with the mouse. - */ - Widget* mLastWidgetWithMouse; - - /** - * Holds the last widget with modal focus. - */ - Widget* mLastWidgetWithModalFocus; - - /** - * Holds the last widget with modal mouse input focus. - */ - Widget* mLastWidgetWithModalMouseInputFocus; - - /** - * Holds the last widget pressed. - */ - Widget* mLastWidgetPressed; - }; -} - -#endif // end GCN_FOCUSHANDLER_HPP diff --git a/src/guichan/focuslistener.hpp b/src/guichan/focuslistener.hpp deleted file mode 100644 index 8e3f63d71..000000000 --- a/src/guichan/focuslistener.hpp +++ /dev/null @@ -1,101 +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. - */ - -#ifndef GCN_FOCUSLISTENER_HPP -#define GCN_FOCUSLISTENER_HPP - -#include - -#include "guichan/event.hpp" -#include "guichan/platform.hpp" - -#ifdef __GNUC__ -#define _UNUSED_ __attribute__ ((unused)) -#else -#define _UNUSED_ -#endif - -namespace gcn -{ - /** - * Interface for listening for focus events from widgets. - * - * @see Widget::addFocusListener, Widget::removeFocusListener - * @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 _UNUSED_) { }; - - /** - * Called when a widget loses focus. - * - * @param event Discribes the event. - */ - virtual void focusLost(const Event& event _UNUSED_) { }; - - protected: - /** - * Constructor. - * - * You should not be able to make an instance of FocusListener, - * therefore its constructor is protected. - */ - FocusListener() { } - }; -} - -#endif // end GCN_FOCUSLISTENER_HPP diff --git a/src/guichan/font.hpp b/src/guichan/font.hpp deleted file mode 100644 index cda4028b8..000000000 --- a/src/guichan/font.hpp +++ /dev/null @@ -1,111 +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. - */ - -#ifndef GCN_FONT_HPP -#define GCN_FONT_HPP - -#include -#include "guichan/platform.hpp" - -namespace gcn -{ - class Graphics; - - /** - * Interface for a font. - * - * @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) const; - - /** - * 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/guichan/graphics.hpp b/src/guichan/graphics.hpp deleted file mode 100644 index d21eab24b..000000000 --- a/src/guichan/graphics.hpp +++ /dev/null @@ -1,291 +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. - */ - -#ifndef GCN_GRAPHICS_HPP -#define GCN_GRAPHICS_HPP - -#include -#include - -#include "guichan/cliprectangle.hpp" -#include "guichan/platform.hpp" - -namespace gcn -{ - class Color; - class Font; - class Image; - - /** - * Abstract class for providing drawing primitve functions. - * It contains all vital functions for drawing. - * - * Guichan contains implementations of Graphics for common - * libraries like the Allegro library, the HGE library, - * the OpenGL library, the OpenLayer library, and the SDL library. - * To make Guichan usable with other libraries, 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 top most 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, HGEGraphics, OpenLayerGraphics, OpenGLGraphics, - * SDLGraphics, Image - * @since 0.1.0 - */ - class GCN_CORE_DECLSPEC Graphics - { - public: - /** - * Alignments for text drawing. - */ - enum Alignment - { - LEFT = 0, - CENTER, - RIGHT - }; - - /** - * Constructor. - */ - Graphics(); - - /** - * Destructor. - */ - 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 - * is the OpenGLGraphics. - * - * NOTE: You will never need to call this function yourself, unless - * you use a Graphics object outside of Guichan. - * - * @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, unless - * you use a Graphics object outside of Guichan. - * - * @see _beginDraw, Gui::draw - */ - virtual void _endDraw() { } - - /** - * Pushes a clip area onto the stack. The x and y coordinates in the - * rectangle is relative to the last pushed clip area. - * If the new area falls outside the current clip area, it will be - * clipped as necessary. - * - * If a clip area is outside of the top clip area a clip area with - * zero width and height will be pushed. - * - * @param area The clip area to be pushed onto the stack. - * @return False if the the new area lays outside the current clip - * area. - */ - virtual bool pushClipArea(Rectangle area); - - /** - * Removes the top most 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 The source image x coordinate. - * @param srcY The source image y coordinate. - * @param dstX The destination x coordinate. - * @param dstY The 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 a 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. - * @see getColor - */ - virtual void setColor(const Color& color) = 0; - - /** - * Gets the color to use when drawing. - * - * @return The color used when drawing. - * @see setColor - */ - virtual const Color& getColor() const = 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 The alignemnt to use when drawing. - * @throws Exception when no font has been set. - */ - virtual void drawText(const std::string& text, - int x, - int y, - Alignment alignment = LEFT); - - protected: - /** - * Holds the clip area stack. - */ - std::stack mClipStack; - - /** - * Holds the current font. - */ - Font* mFont; - }; -} - -#endif // end GCN_GRAPHICS_HPP diff --git a/src/guichan/gui.hpp b/src/guichan/gui.hpp deleted file mode 100644 index 17d49c979..000000000 --- a/src/guichan/gui.hpp +++ /dev/null @@ -1,505 +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. - */ - -#ifndef GCN_GUI_HPP -#define GCN_GUI_HPP - -#include -#include - -#include "guichan/keyevent.hpp" -#include "guichan/mouseevent.hpp" -#include "guichan/mouseinput.hpp" -#include "guichan/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. - */ - - /** - * Contains a Guichan GUI. This is the core class of Guichan to which - * implementations of back ends are passed, to make Guichan work with - * a specific library, and to where the top widget (root widget of GUI) - * is added. If you want to be able to have more then one widget in your - * GUI, the top widget should be a container. - * - * A Gui object cannot work properly without passing back end - * implementations to it. A Gui object must have an implementation of a - * Graphics and an implementation of Input. - * - * NOTE: A complete GUI also must have the ability to load images. - * Images are loaded with the Image class, so to make Guichan - * able to load images an implementation of ImageLoader must be - * passed to Image. - * - * @see Graphics, Input, Image - */ - class GCN_CORE_DECLSPEC Gui - { - public: - - /** - * Constructor. - */ - Gui(); - - /** - * Destructor. - */ - virtual ~Gui(); - - /** - * Sets the top widget. The top widget is the root widget - * of the GUI. If you want a GUI to be able to contain more - * than one widget the top widget should be a container. - * - * @param top The top widget. - * @see Container - * @since 0.1.0 - */ - virtual void setTop(Widget* top); - - /** - * Gets the top widget. The top widget is the root widget - * of the GUI. - * - * @return The top widget. NULL if no top widget has been set. - * @since 0.1.0 - */ - virtual Widget* getTop() const; - - /** - * Sets the graphics object to use for drawing. - * - * @param graphics The graphics object to use for drawing. - * @see getGraphics, AllegroGraphics, HGEGraphics, - * OpenLayerGraphics, OpenGLGraphics, SDLGraphics - * @since 0.1.0 - */ - 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. - * @see setGraphics, AllegroGraphics, HGEGraphics, - * OpenLayerGraphics, OpenGLGraphics, SDLGraphics - * @since 0.1.0 - */ - virtual Graphics* getGraphics() const; - - /** - * Sets the input object to use for input handling. - * - * @param input The input object to use for input handling. - * @see getInput, AllegroInput, HGEInput, OpenLayerInput, - * SDLInput - * @since 0.1.0 - */ - 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. - * @see setInput, AllegroInput, HGEInput, OpenLayerInput, - * SDLInput - * @since 0.1.0 - */ - virtual Input* getInput() const; - - /** - * Performs logic of the GUI. By calling this function all logic - * functions down in the GUI heirarchy will be called. When logic - * is called for Gui, user input will be handled. - * - * @see Widget::logic - * @since 0.1.0 - */ - virtual void logic(); - - /** - * Draws the GUI. By calling this funcion all draw functions - * down in the GUI hierarchy will be called. When draw is called - * the used Graphics object will be initialised and drawing of - * the top widget will commence. - * - * @see Widget::draw - * @since 0.1.0 - */ - virtual void draw(); - - /** - * Focuses none of the widgets in the Gui. - * - * @since 0.1.0 - */ - virtual void focusNone(); - - /** - * Sets tabbing enabled, or not. Tabbing is the usage of - * changing focus by utilising the tab key. - * - * @param tabbing True if tabbing should be enabled, false - * otherwise. - * @see isTabbingEnabled - * @since 0.1.0 - */ - virtual void setTabbingEnabled(bool tabbing); - - /** - * Checks if tabbing is enabled. - * - * @return True if tabbing is enabled, false otherwise. - * @see setTabbingEnabled - * @since 0.1.0 - */ - virtual bool isTabbingEnabled(); - - /** - * Adds a global key listener to the Gui. A global key listener - * will receive all key events generated from the GUI and global - * key listeners will receive the events before key listeners - * of widgets. - * - * @param keyListener The key listener to add. - * @see removeGlobalKeyListener - * @since 0.5.0 - */ - virtual void addGlobalKeyListener(KeyListener* keyListener); - - /** - * Removes global key listener from the Gui. - * - * @param keyListener The key listener to remove. - * @throws Exception if the key listener hasn't been added. - * @see addGlobalKeyListener - * @since 0.5.0 - */ - 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 gained 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 - * gained 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(); - - /** - * Holds the top widget. - */ - Widget* mTop; - - /** - * Holds the graphics implementation used. - */ - Graphics* mGraphics; - - /** - * Holds the input implementation used. - */ - Input* mInput; - - /** - * Holds the focus handler for the Gui. - */ - FocusHandler* mFocusHandler; - - /** - * True if tabbing is enabled, false otherwise. - */ - bool mTabbing; - - /** - * Typedef. - */ - typedef std::list KeyListenerList; - - /** - * Typedef. - */ - typedef KeyListenerList::iterator KeyListenerListIterator; - - /** - * Holds the global key listeners of the Gui. - */ - KeyListenerList mKeyListeners; - - /** - * True if shift is pressed, false otherwise. - */ - bool mShiftPressed; - - /** - * True if meta is pressed, false otherwise. - */ - bool mMetaPressed; - - /** - * True if control is pressed, false otherwise. - */ - bool mControlPressed; - - /** - * True if alt is pressed, false otherwise. - */ - bool mAltPressed; - - /** - * Holds the last mouse button pressed. - */ - unsigned int mLastMousePressButton; - - /** - * Holds the last mouse press time stamp. - */ - int mLastMousePressTimeStamp; - - /** - * Holds the last mouse x coordinate. - */ - int mLastMouseX; - - /** - * Holds the last mouse y coordinate. - */ - int mLastMouseY; - - /** - * Holds the current click count. Used to keep track - * of clicks for a the last pressed button. - */ - int mClickCount; - - /** - * Holds the last button used when a drag of a widget - * was initiated. Used to be able to release a drag - * when the same button is released. - */ - int mLastMouseDragButton; - - /** - * Holds a stack with all the widgets with the mouse. - * Used to properly distribute mouse events. - */ - 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/guichan/image.hpp b/src/guichan/image.hpp deleted file mode 100644 index e3bd27f69..000000000 --- a/src/guichan/image.hpp +++ /dev/null @@ -1,191 +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. - */ - -#ifndef GCN_IMAGE_HPP -#define GCN_IMAGE_HPP - -#include - -#include "guichan/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 might crash in a most bizarre way. - * @see AllegroImageLoader, HGEImageLoader, OpenLayerImageLoader, - * OpenGLAllegroImageLoader, OpenGLSDLImageLoader, SDLImageLoader - * @since 0.1.0 - */ - class GCN_CORE_DECLSPEC Image - { - public: - - /** - * Constructor. - */ - Image(); - - /** - * Destructor. - */ - virtual ~Image(); - - /** - * Loads an image by using the class' image loader. All image loaders - * implemented in Guichan return a newly instantiated image which must - * be deleted in order to avoid a memory leak. - * - * 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. - * @since 0.5.0 - */ - static Image* load(const std::string& filename, - bool convertToDisplayFormat = true); - - /** - * Gets the image loader used for loading images. - * - * @return The image loader used for loading images. - * @see setImageLoader, AllegroImageLoader, HGEImageLoader, - * OpenLayerImageLoader, OpenGLAllegroImageLoader, - * OpenGLSDLImageLoader, SDLImageLoader - * @since 0.1.0 - */ - static ImageLoader* getImageLoader(); - - /** - * Sets the ImageLoader to be used for loading images. - * - * IMPORTANT: The image loader is static and MUST be set before - * loading images! - * - * @param imageLoader The image loader to be used for loading images. - * @see getImageLoader, AllegroImageLoader, HGEImageLoader, - * OpenLayerImageLoader, OpenGLAllegroImageLoader, - * OpenGLSDLImageLoader, SDLImageLoader - * @since 0.1.0 - */ - static void setImageLoader(ImageLoader* imageLoader); - - /** - * Frees an image. - * - * @since 0.5.0 - */ - virtual void free() = 0; - - /** - * Gets the width of the image. - * - * @return The width of the image. - * - * @since 0.1.0 - */ - virtual int getWidth() const = 0; - - /** - * Gets the height of the image. - * - * @return The height of the image. - * - * @since 0.1.0 - */ - 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. - * - * @since 0.5.0 - */ - 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. - * @since 0.5.0 - */ - 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. - * @since 0.5.0 - */ - virtual void convertToDisplayFormat() = 0; - - protected: - /** - * Holds the image loader to be used when loading images. - */ - static ImageLoader* mImageLoader; - }; -} - -#endif // end GCN_IMAGE_HPP diff --git a/src/guichan/imageloader.hpp b/src/guichan/imageloader.hpp deleted file mode 100644 index 7c0adb842..000000000 --- a/src/guichan/imageloader.hpp +++ /dev/null @@ -1,100 +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. - */ - -#ifndef GCN_IMAGELOADER_HPP -#define GCN_IMAGELOADER_HPP - -#include - -#include "guichan/platform.hpp" - -namespace gcn -{ - class Image; - - /** - * Abstract class for providing functions for loading images. - * - * Guichan contains implementations of ImageLoader for common - * libraries like the Allegro library, the HGE library, - * he OpenLayer library, and the SDL library. - * To make Guichan usable with other libraries, an ImageLoader - * class must be implemented. - * - * To make Guichan use an image loader, the image loader needs - * to be passed to the Image class using the static method - * Image::setImageLoader. - * - * @see Image::setImageLoader, Image::getImageLoader, - * AllegroImageLoader, HGEImageLoader, OpenLayerImageLoader, - * OpenGLAllegroImageLoader, OpenGLSDLImageLoader, - * SDLImageLoader - * @since 0.1.0 - */ - class GCN_CORE_DECLSPEC ImageLoader - { - public: - - /** - * Destructor. - */ - virtual ~ImageLoader() - { } - - /** - * Loads an image. - * - * NOTE: The functions Image::getPixel and Image::putPixel - * are only guaranteed to work before an image has - * been converted to display format. - * - * @param filename The filename of the image 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/guichan/include/guichan/actionevent.hpp b/src/guichan/include/guichan/actionevent.hpp new file mode 100644 index 000000000..c897e9b4b --- /dev/null +++ b/src/guichan/include/guichan/actionevent.hpp @@ -0,0 +1,114 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_ACTIONEVENT_HPP +#define GCN_ACTIONEVENT_HPP + +#include "guichan/event.hpp" +#include "guichan/platform.hpp" + +#include + +namespace gcn +{ + class Widget; + + /** + * Represents an action event. An action event is an event + * that can be fired by a widget whenever an action has occured. + * What exactly an action is is up to the widget that fires + * the action event. An example is a Button which fires an action + * event as soon as the Button is clicked, another example is + * TextField which fires an action event as soon as the enter + * key is pressed. + * + * Any object can listen for actions from widgets by implementing + * the ActionListener interface. + * + * If you have implement a widget of your own it's a good idea to + * let the widget fire action events whenever you feel an action + * has occured so action listeners of the widget can be informed + * of the state of the widget. + * + * @see Widget::addActionListener, Widget::removeActionListener, + * Widget::distributeActionEvent + * @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 An identifier of the event. + */ + ActionEvent(Widget* source, const std::string& id); + + /** + * Destructor. + */ + virtual ~ActionEvent(); + + /** + * Gets the identifier of the event. An identifier can + * be used to distinguish from two actions from the same + * widget or to let many widgets fire the same widgets + * that should be treated equally. + * + * @return The identifier of the event. + */ + const std::string& getId() const; + + protected: + /** + * Holds the identifier of the event. + */ + std::string mId; + }; +} + +#endif // GCN_ACTIONEVENT_HPP + diff --git a/src/guichan/include/guichan/actionlistener.hpp b/src/guichan/include/guichan/actionlistener.hpp new file mode 100644 index 000000000..0f750099c --- /dev/null +++ b/src/guichan/include/guichan/actionlistener.hpp @@ -0,0 +1,93 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_ACTIONLISTENER_HPP +#define GCN_ACTIONLISTENER_HPP + +#include + +#include "guichan/actionevent.hpp" +#include "guichan/platform.hpp" + +namespace gcn +{ + /** + * Interface for listening for action events from widgets. + * + * @see Widget::addActionListener, Widget::removeActionListener, + * ActionEvent + * @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; + + protected: + /** + * Constructor. + * + * You should not be able to make an instance of ActionListener, + * therefore its constructor is protected. + */ + ActionListener() { } + + }; +} + +#endif // end GCN_ACTIONLISTENER_HPP diff --git a/src/guichan/include/guichan/basiccontainer.hpp b/src/guichan/include/guichan/basiccontainer.hpp new file mode 100644 index 000000000..269a5ba44 --- /dev/null +++ b/src/guichan/include/guichan/basiccontainer.hpp @@ -0,0 +1,181 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_BASICCONTAINER_HPP +#define GCN_BASICCONTAINER_HPP + +#include + +#include "guichan/deathlistener.hpp" +#include "guichan/platform.hpp" +#include "guichan/widget.hpp" + +namespace gcn +{ + /** + * A base class for containers. The class implements the most + * common things for a container. If you are implementing a + * container, consider inheriting from this class. + * + * @see Container + * @since 0.6.0 + */ + class GCN_CORE_DECLSPEC BasicContainer : public Widget, + public DeathListener + { + public: + /** + * Destructor + */ + virtual ~BasicContainer(); + + /** + * Shows a certain part of a widget in the basic container. + * Used when widgets want a specific part to be visible in + * its parent. An example is a TextArea that wants a specific + * part of its text to be visible when a TextArea is a child + * of a ScrollArea. + * + * @param widget The widget whom wants a specific part of + * itself to be visible. + * @param rectangle The rectangle to be visible. + */ + virtual void showWidgetPart(Widget* widget, Rectangle area); + + + // 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 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. + * @see remove, clear + */ + void add(Widget* widget); + + /** + * Removes a widget from the basic container. + * + * @param widget The widget to remove. + * @see add, clear + */ + virtual void remove(Widget* widget); + + /** + * Clears the basic container from all widgets. + * + * @see remove, clear + */ + virtual void clear(); + + /** + * Draws the children widgets of the basic container. + * + * @param graphics A graphics object to draw with. + */ + virtual void drawChildren(Graphics* graphics); + + /** + * Calls logic for the children widgets of the basic + * container. + */ + virtual void logicChildren(); + + /** + * Finds a widget given an id. This function can be useful + * when implementing a GUI generator for Guichan, such as + * the ability to create a Guichan GUI from an XML file. + * + * @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. + */ + typedef std::list WidgetList; + + /** + * Typedef. + */ + typedef WidgetList::iterator WidgetListIterator; + + /** + * Typedef. + */ + typedef WidgetList::reverse_iterator WidgetListReverseIterator; + + /** + * Holds all widgets of the basic container. + */ + WidgetList mWidgets; + }; +} + +#endif // end GCN_BASICCONTAINER_HPP diff --git a/src/guichan/include/guichan/cliprectangle.hpp b/src/guichan/include/guichan/cliprectangle.hpp new file mode 100644 index 000000000..792c40bb9 --- /dev/null +++ b/src/guichan/include/guichan/cliprectangle.hpp @@ -0,0 +1,109 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_CLIPRECTANGLE_HPP +#define GCN_CLIPRECTANGLE_HPP + +#include "guichan/rectangle.hpp" +#include "guichan/platform.hpp" + +namespace gcn +{ + /** + * A rectangle used when dealing with clipping. A clip rectangle is + * a regular rectangle extended with variables for x offsets and y + * offsets. The offsets are used for calculations from relative + * screen coordinates to actual screen coordinates. + */ + class GCN_CORE_DECLSPEC ClipRectangle : public Rectangle + { + public: + + /** + * Constructor. + */ + ClipRectangle(); + + /** + * Constructor. + * + * @param x The rectangle x coordinate. + * @param y The rectangle y coordinate. + * @param width The rectangle width. + * @param height The rectangle height. + * @param xOffset The offset of the x coordinate. Used to for + * calculating the actual screen coordinate from + * the relative screen coordinate. + * @param yOffset The offset of the y coordinate. Used to for + * calculating the actual screen coordinate from + * the relative screen coordinate. + */ + ClipRectangle(int x, + int y, + int width, + int height, + int xOffset, + int yOffset); + + /** + * Copy constructor. Copies x, y, width and height + * field from a rectangle to a clip rectangle. + * + * @param other The rectangle to copy data from. + * @returns A clip rectangle with data copyied from a rectangle. + */ + const ClipRectangle& operator=(const Rectangle& other); + + /** + * Holds the x offset of the x coordinate. + */ + int xOffset; + + /** + * Holds the y offset of the y coordinate. + */ + int yOffset; + }; +} + +#endif // end GCN_CLIPRECTANGLE_HPP diff --git a/src/guichan/include/guichan/color.hpp b/src/guichan/include/guichan/color.hpp new file mode 100644 index 000000000..b7e324c07 --- /dev/null +++ b/src/guichan/include/guichan/color.hpp @@ -0,0 +1,173 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_COLOR_HPP +#define GCN_COLOR_HPP + +#include "guichan/platform.hpp" + +#include + +namespace gcn +{ + /** + * Represents a color with red, green, blue and alpha components. + */ + class GCN_CORE_DECLSPEC Color + { + public: + + /** + * Constructor. Initializes the color to black. + */ + Color(); + + /** + * Constructor. Constructs a color from the bytes in an integer. + * Call it with a hexadecimal constant for HTML-style color representation. + * The alpha component is 255 by default. + * + * EXAMPLE: Color(0xff50a0) constructs a very nice pinkish color. + * + * NOTE: Because of this constructor, integers will be automatically + * casted to a color by your compiler. + * + * @param color The color to initialise the object with. + */ + Color(int color); + + /** + * Constructor. The default alpha value is 255. + * + * @param r Red color component (range 0-255). + * @param g Green color component (range 0-255). + * @param b Blue color component (range 0-255). + * @param a Alpha, used for transparency. A value of 0 means + * totaly transparent, 255 is totaly opaque. + */ + Color(int r, int g, int b, int a = 255); + + /** + * Adds the RGB values of two colors together. The values will be + * clamped if they go out of range. + * + * WARNING: This function will reset the alpha value of the + * returned color to 255. + * + * @param color A color to add to this color. + * @return The added colors with an alpha value set to 255. + */ + Color operator+(const Color& color) const; + + /** + * Subtracts the RGB values of one color from another. + * The values will be clamped if they go out of range. + * + * WARNING: This function will reset the alpha value of the + * returned color to 255. + * + * @param color A color to subtract from this color. + * @return The subtracted colors with an alpha value set to 255. + */ + Color operator-(const Color& color) const; + + /** + * Multiplies the RGB values of a color with a float value. + * The values will be clamped if they go out of range. + * + * @param value The value to multiply the color with. + * @return The multiplied colors. The alpha value will, unlike + * the add and subtract operations, be multiplied as + * well. + */ + Color operator*(float value) const; + + /** + * Compares two colors. + * + * @return True if the two colors have the same RGBA components + * false otherwise. + */ + bool operator==(const Color& color) const; + + /** + * Compares two colors. + * + * @return True if the two colors have different RGBA components, + * false otherwise. + */ + bool operator!=(const Color& color) const; + + /** + * Output operator for output. + * + * @param out The stream to output to. + * @param color The color to output. + */ + friend std::ostream& operator<<(std::ostream& out, + const Color& Color); + + /** + * Holds the red color component (range 0-255). + */ + int r; + + /** + * Holds the green color component (range 0-255). + */ + int g; + + /** + * Holds the blue color component (range 0-255). + */ + int b; + + /** + * Holds the alpha color component. A value of 0 means totally + * transparent while a value of 255 is considered opaque. + */ + int a; + }; +} + +#endif // end GCN_COLOR_HPP diff --git a/src/guichan/include/guichan/defaultfont.hpp b/src/guichan/include/guichan/defaultfont.hpp new file mode 100644 index 000000000..e5a830e4c --- /dev/null +++ b/src/guichan/include/guichan/defaultfont.hpp @@ -0,0 +1,103 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_DEFAULTFONT_HPP +#define GCN_DEFAULTFONT_HPP + +#include "guichan/font.hpp" +#include "guichan/platform.hpp" + +#ifdef __GNUC__ +#define _UNUSED_ __attribute__ ((unused)) +#else +#define _UNUSED_ +#endif + +namespace gcn +{ + /** + * A font only capable of drawing rectangles. It is used by default + * in Guichan if no font has been set merely to show that no font has + * been set. + */ + class GCN_CORE_DECLSPEC DefaultFont : public Font + { + public: + + /** + * Destructor. + */ + virtual ~DefaultFont(){} + + /** + * Draws a glyph as a rectangle. The glyphs will always be drawn as + * rectangles no matter the glyph. + * + * NOTE: You normally won't use this function to draw text since + * the Graphics class contains better functions for drawing + * text. + * + * @param graphics A Graphics object to be used for drawing. + * @param glyph The 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 drawn glyph in pixels. + */ + virtual int drawGlyph(Graphics* graphics, unsigned char glyph, + int x, int y); + + + // Inherited from Font + + virtual void drawString(Graphics* graphics, const std::string& text, + int x, int y); + + virtual int getWidth(const std::string& text) const; + + virtual int getHeight() const; + + virtual int getStringIndexAt(const std::string& text, int x) const; + }; +} + +#endif // end GCN_DEFAULTFONT_HPP diff --git a/src/guichan/include/guichan/event.hpp b/src/guichan/include/guichan/event.hpp new file mode 100644 index 000000000..107e34fc2 --- /dev/null +++ b/src/guichan/include/guichan/event.hpp @@ -0,0 +1,94 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_EVENT_HPP +#define GCN_EVENT_HPP + +#include "guichan/platform.hpp" + +namespace gcn +{ + class Widget; + + /** + * Base class for all events. All events in Guichan should + * inherit from this class. + * + * @author Olof Naessén + * @since 0.6.0 + */ + class GCN_CORE_DECLSPEC Event + { + public: + + /** + * Constructor. + * + * @param source The source widget of the event. + */ + Event(Widget* source); + + /** + * Destructor. + */ + virtual ~Event(); + + /** + * Gets the source widget of the event. The function + * is used to tell which widget fired an event. + * + * @return The source widget of the event. + */ + Widget* getSource() const; + + + protected: + + /** + * Holds the source widget of the event. + */ + Widget* mSource; + }; +} + +#endif // end GCN_EVENT_HPP diff --git a/src/guichan/include/guichan/exception.hpp b/src/guichan/include/guichan/exception.hpp new file mode 100644 index 000000000..3ccf39e20 --- /dev/null +++ b/src/guichan/include/guichan/exception.hpp @@ -0,0 +1,177 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_EXCEPTION_HPP +#define GCN_EXCEPTION_HPP + +#include + +#include "guichan/platform.hpp" + +#ifndef __FUNCTION__ +#define __FUNCTION__ "?" +#endif + +/* + * A macro used to create a standard exception object. + * What it basicly does is that it creates a new exception + * and automatically sets the filename and line number where + * the exception occured by using other compiler macros. + */ +#define GCN_EXCEPTION(mess) gcn::Exception(mess, \ + __FUNCTION__, \ + __FILE__, \ + __LINE__) + +namespace gcn +{ + + /** + * An exception containing a message, a file and a line number + * where the exception occured. Guichan will only throw exceptions + * of this class. + * + * You can use this class for your own exceptions that has + * something to do with a GUI exception. 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 of the exception. + */ + Exception(const std::string& message); + + /** + * Constructor. + * + * NOTE: Don't use this constructor. Use the GCN_EXCEPTION macro instead. + * This constructor merely exists for the GCN_EXCEPTION macro to + * use. + * + * @param message The error message of the exception. + * @param function The function name where the exception occured. + * @param filename The name of the file where the exception occured. + * @param line The line number in the source code where the exception + * occured. + */ + Exception(const std::string& message, + const std::string& function, + const std::string& filename, + unsigned int line); + + /** + * Gets the function name where the exception occured. + * + * @return The function name where the exception occured. + */ + const std::string& getFunction() const; + + /** + * Gets the error message of the exception. + * + * @return The error message of the exception. + */ + const std::string& getMessage() const; + + /** + * Gets the filename where the exception occured. + * + * @return The filename where the exception occured. + */ + const std::string& getFilename() const; + + /** + * Gets the line number where the exception occured. + * + * @return The line number where the exception occured. + */ + unsigned int getLine() const; + + protected: + /** + * Holds the name of the function name where the + * exception occured. + */ + std::string mFunction; + + /** + * Holds the error message of the exception. + */ + std::string mMessage; + + /** + * Holds the filename where the exception occured. + */ + std::string mFilename; + + /** + * Holds the line number where the exception occured. + */ + unsigned 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/guichan/include/guichan/focushandler.hpp b/src/guichan/include/guichan/focushandler.hpp new file mode 100644 index 000000000..49bb4e2e5 --- /dev/null +++ b/src/guichan/include/guichan/focushandler.hpp @@ -0,0 +1,397 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_FOCUSHANDLER_HPP +#define GCN_FOCUSHANDLER_HPP + +#include + +#include "guichan/event.hpp" +#include "guichan/platform.hpp" + +namespace gcn +{ + class Widget; + + /** + * Handles focus for widgets in a Gui. Each Gui has at least one + * focus handler. + + * You will probably not use the focus handler directly as Widget + * has functions that automatically uses the active focus handler. + * + * @see Widget::isFocus, Widget::isModalFocused, + * Widget::isModalMouseInputFocused, Widget::requestFocus, + * Widget::requestModalFocus, Widget::requestModalMouseInputFocus, + * Widget::releaseModalFocus, Widget::relaseModalMouseInputFocus, + * Widget::setFocusable, Widget::isFocusable, FocusListener + * + * @since 0.1.0 + */ + class GCN_CORE_DECLSPEC FocusHandler + { + public: + + /** + * Constructor. + */ + FocusHandler(); + + /** + * Destructor. + */ + virtual ~FocusHandler() { }; + + /** + * Requests focus for a widget. Focus will only be granted to a widget + * if it's focusable and if no other widget has modal focus. + * If a widget receives focus a focus event will be sent to the + * focus listeners of the widget. + * + * @param widget The widget to request focus for. + * @see isFocused, Widget::requestFocus + */ + virtual void requestFocus(Widget* widget); + + /** + * Requests modal focus for a widget. Focus will only be granted + * to a widget if it's focusable and if no other widget has modal + * focus. + * + * @param widget The widget to request modal focus for. + * @throws Exception when another widget already has modal focus. + * @see releaseModalFocus, Widget::requestModalFocus + */ + virtual void requestModalFocus(Widget* widget); + + /** + * Requests modal mouse input focus for a widget. Focus will only + * be granted to a widget if it's focusable and if no other widget + * has modal mouse input focus. + * + * 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. + * @see releaseModalMouseInputFocus, Widget::requestModalMouseInputFocus + */ + virtual void requestModalMouseInputFocus(Widget* widget); + + /** + * Releases modal focus if the widget has modal focus. + * If the widget doesn't have modal focus no relase will occur. + * + * @param widget The widget to release modal focus for. + * @see reuqestModalFocus, Widget::releaseModalFocus + */ + virtual void releaseModalFocus(Widget* widget); + + /** + * Releases modal mouse input focus if the widget has modal mouse input + * focus. If the widget doesn't have modal mouse input focus no relase + * will occur. + * + * @param widget the widget to release modal mouse input focus for. + * @see requestModalMouseInputFocus, Widget::releaseModalMouseInputFocus + */ + virtual void releaseModalMouseInputFocus(Widget* widget); + + /** + * Checks if a widget is focused. + * + * @param widget The widget to check. + * @return True if the widget is focused, false otherwise. + * @see Widget::isFocused + */ + virtual bool isFocused(const Widget* widget) const; + + /** + * Gets the widget with focus. + * + * @return The widget with focus. NULL if no widget has focus. + */ + virtual Widget* getFocused() const; + + /** + * Gets the widget with modal focus. + * + * @return The widget with modal focus. NULL 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 if + * no widget has modal mouse input focus. + */ + virtual Widget* getModalMouseInputFocused() const; + + /** + * Focuses the next widget added to a conainer. + * If no widget has focus the first widget gets focus. The order + * in which the widgets are focused is determined by the order + * they were added to a container. + * + * @see focusPrevious + */ + virtual void focusNext(); + + /** + * Focuses the previous widget added to a contaienr. + * If no widget has focus the first widget gets focus. The order + * in which the widgets are focused is determined by the order + * they were added to a container. + * + * @see focusNext + */ + virtual void focusPrevious(); + + /** + * Adds a widget to by handles by the focus handler. + * + * @param widget The widget to add. + * @see remove + */ + virtual void add(Widget* widget); + + /** + * Removes a widget from the focus handler. + * + * @param widget The widget to remove. + * @see add + */ + 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 tabbing in unless + * the current focused Widget disallows tabbing out. + * + * @see tabPrevious + */ + virtual void tabNext(); + + /** + * Focuses the previous widget which allows tabbing in unless + * current focused widget disallows tabbing out. + * + * @see tabNext + */ + virtual void tabPrevious(); + + /** + * Gets the widget being dragged. Used by the Gui class to + * keep track of the dragged widget. + * + * @return the widget being dragged. + * @see setDraggedWidget + */ + virtual Widget* getDraggedWidget(); + + /** + * Sets the widget being dragged. Used by the Gui class to + * keep track of the dragged widget. + * + * @param draggedWidget The widget being dragged. + * @see getDraggedWidget + */ + virtual void setDraggedWidget(Widget* draggedWidget); + + /** + * Gets the last widget with the mouse. Used by the Gui class + * to keep track the last widget with the mouse. + * + * @return The last widget with the mouse. + * @see setLastWidgetWithMouse + */ + virtual Widget* getLastWidgetWithMouse(); + + /** + * Sets the last widget with the mouse. Used by the Gui class + * to keep track the last widget with the mouse. + * + * @param lastWidgetWithMouse The last widget with the mouse. + * @see getLastWidgetWithMouse + */ + virtual void setLastWidgetWithMouse(Widget* lastWidgetWithMouse); + + /** + * Gets the last widget with modal focus. + * + * @return The last widget with modal focus. + * @see setLastWidgetWithModalFocus + */ + virtual Widget* getLastWidgetWithModalFocus(); + + /** + * Sets the last widget with modal focus. + * + * @param widget The last widget with modal focus. + * @see getLastWidgetWithModalFocus + */ + virtual void setLastWidgetWithModalFocus(Widget* widget); + + /** + * Gets the last widget with modal mouse input focus. + * + * @return The last widget with modal mouse input focus. + * @see setLastWidgetWithModalMouseInputFocus + */ + virtual Widget* getLastWidgetWithModalMouseInputFocus(); + + /** + * Sets the last widget with modal mouse input focus. + * + * @param widget The last widget with modal mouse input focus. + * @see getLastWidgetWithModalMouseInputFocus + */ + virtual void setLastWidgetWithModalMouseInputFocus(Widget* widget); + + /** + * Gets the last widget pressed. Used by the Gui class to keep track + * of pressed widgets. + * + * @return The last widget pressed. + * @see setLastWidgetPressed + */ + virtual Widget* getLastWidgetPressed(); + + /** + * Sets the last widget pressed. Used by the Gui class to keep track + * of pressed widgets. + * + * @param lastWidgetPressed The last widget pressed. + * @see getLastWidgetPressed + */ + virtual void setLastWidgetPressed(Widget* lastWidgetPressed); + + protected: + /** + * Distributes a focus lost event. + * + * @param focusEvent the event to distribute. + * @since 0.7.0 + */ + virtual void distributeFocusLostEvent(const Event& focusEvent); + + /** + * Distributes a focus gained event. + * + * @param focusEvent the event to distribute. + * @since 0.7.0 + */ + virtual void distributeFocusGainedEvent(const Event& focusEvent); + + /** + * Typedef. + */ + typedef std::vector WidgetVector; + + /** + * Typedef. + */ + typedef WidgetVector::iterator WidgetIterator; + + /** + * Holds the widgets currently being handled by the + * focus handler. + */ + WidgetVector mWidgets; + + /** + * Holds the focused widget. NULL if no widget has focus. + */ + Widget* mFocusedWidget; + + /** + * Holds the modal focused widget. NULL if no widget has + * modal focused. + */ + Widget* mModalFocusedWidget; + + /** + * Holds the modal mouse input focused widget. NULL if no widget + * is being dragged. + */ + Widget* mModalMouseInputFocusedWidget; + + /** + * Holds the dragged widget. NULL if no widget is + * being dragged. + */ + Widget* mDraggedWidget; + + /** + * Holds the last widget with the mouse. + */ + Widget* mLastWidgetWithMouse; + + /** + * Holds the last widget with modal focus. + */ + Widget* mLastWidgetWithModalFocus; + + /** + * Holds the last widget with modal mouse input focus. + */ + Widget* mLastWidgetWithModalMouseInputFocus; + + /** + * Holds the last widget pressed. + */ + Widget* mLastWidgetPressed; + }; +} + +#endif // end GCN_FOCUSHANDLER_HPP diff --git a/src/guichan/include/guichan/focuslistener.hpp b/src/guichan/include/guichan/focuslistener.hpp new file mode 100644 index 000000000..8e3f63d71 --- /dev/null +++ b/src/guichan/include/guichan/focuslistener.hpp @@ -0,0 +1,101 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_FOCUSLISTENER_HPP +#define GCN_FOCUSLISTENER_HPP + +#include + +#include "guichan/event.hpp" +#include "guichan/platform.hpp" + +#ifdef __GNUC__ +#define _UNUSED_ __attribute__ ((unused)) +#else +#define _UNUSED_ +#endif + +namespace gcn +{ + /** + * Interface for listening for focus events from widgets. + * + * @see Widget::addFocusListener, Widget::removeFocusListener + * @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 _UNUSED_) { }; + + /** + * Called when a widget loses focus. + * + * @param event Discribes the event. + */ + virtual void focusLost(const Event& event _UNUSED_) { }; + + protected: + /** + * Constructor. + * + * You should not be able to make an instance of FocusListener, + * therefore its constructor is protected. + */ + FocusListener() { } + }; +} + +#endif // end GCN_FOCUSLISTENER_HPP diff --git a/src/guichan/include/guichan/font.hpp b/src/guichan/include/guichan/font.hpp new file mode 100644 index 000000000..cda4028b8 --- /dev/null +++ b/src/guichan/include/guichan/font.hpp @@ -0,0 +1,111 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_FONT_HPP +#define GCN_FONT_HPP + +#include +#include "guichan/platform.hpp" + +namespace gcn +{ + class Graphics; + + /** + * Interface for a font. + * + * @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) const; + + /** + * 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/guichan/include/guichan/graphics.hpp b/src/guichan/include/guichan/graphics.hpp new file mode 100644 index 000000000..d21eab24b --- /dev/null +++ b/src/guichan/include/guichan/graphics.hpp @@ -0,0 +1,291 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_GRAPHICS_HPP +#define GCN_GRAPHICS_HPP + +#include +#include + +#include "guichan/cliprectangle.hpp" +#include "guichan/platform.hpp" + +namespace gcn +{ + class Color; + class Font; + class Image; + + /** + * Abstract class for providing drawing primitve functions. + * It contains all vital functions for drawing. + * + * Guichan contains implementations of Graphics for common + * libraries like the Allegro library, the HGE library, + * the OpenGL library, the OpenLayer library, and the SDL library. + * To make Guichan usable with other libraries, 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 top most 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, HGEGraphics, OpenLayerGraphics, OpenGLGraphics, + * SDLGraphics, Image + * @since 0.1.0 + */ + class GCN_CORE_DECLSPEC Graphics + { + public: + /** + * Alignments for text drawing. + */ + enum Alignment + { + LEFT = 0, + CENTER, + RIGHT + }; + + /** + * Constructor. + */ + Graphics(); + + /** + * Destructor. + */ + 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 + * is the OpenGLGraphics. + * + * NOTE: You will never need to call this function yourself, unless + * you use a Graphics object outside of Guichan. + * + * @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, unless + * you use a Graphics object outside of Guichan. + * + * @see _beginDraw, Gui::draw + */ + virtual void _endDraw() { } + + /** + * Pushes a clip area onto the stack. The x and y coordinates in the + * rectangle is relative to the last pushed clip area. + * If the new area falls outside the current clip area, it will be + * clipped as necessary. + * + * If a clip area is outside of the top clip area a clip area with + * zero width and height will be pushed. + * + * @param area The clip area to be pushed onto the stack. + * @return False if the the new area lays outside the current clip + * area. + */ + virtual bool pushClipArea(Rectangle area); + + /** + * Removes the top most 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 The source image x coordinate. + * @param srcY The source image y coordinate. + * @param dstX The destination x coordinate. + * @param dstY The 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 a 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. + * @see getColor + */ + virtual void setColor(const Color& color) = 0; + + /** + * Gets the color to use when drawing. + * + * @return The color used when drawing. + * @see setColor + */ + virtual const Color& getColor() const = 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 The alignemnt to use when drawing. + * @throws Exception when no font has been set. + */ + virtual void drawText(const std::string& text, + int x, + int y, + Alignment alignment = LEFT); + + protected: + /** + * Holds the clip area stack. + */ + std::stack mClipStack; + + /** + * Holds the current font. + */ + Font* mFont; + }; +} + +#endif // end GCN_GRAPHICS_HPP diff --git a/src/guichan/include/guichan/gui.hpp b/src/guichan/include/guichan/gui.hpp new file mode 100644 index 000000000..17d49c979 --- /dev/null +++ b/src/guichan/include/guichan/gui.hpp @@ -0,0 +1,505 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_GUI_HPP +#define GCN_GUI_HPP + +#include +#include + +#include "guichan/keyevent.hpp" +#include "guichan/mouseevent.hpp" +#include "guichan/mouseinput.hpp" +#include "guichan/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. + */ + + /** + * Contains a Guichan GUI. This is the core class of Guichan to which + * implementations of back ends are passed, to make Guichan work with + * a specific library, and to where the top widget (root widget of GUI) + * is added. If you want to be able to have more then one widget in your + * GUI, the top widget should be a container. + * + * A Gui object cannot work properly without passing back end + * implementations to it. A Gui object must have an implementation of a + * Graphics and an implementation of Input. + * + * NOTE: A complete GUI also must have the ability to load images. + * Images are loaded with the Image class, so to make Guichan + * able to load images an implementation of ImageLoader must be + * passed to Image. + * + * @see Graphics, Input, Image + */ + class GCN_CORE_DECLSPEC Gui + { + public: + + /** + * Constructor. + */ + Gui(); + + /** + * Destructor. + */ + virtual ~Gui(); + + /** + * Sets the top widget. The top widget is the root widget + * of the GUI. If you want a GUI to be able to contain more + * than one widget the top widget should be a container. + * + * @param top The top widget. + * @see Container + * @since 0.1.0 + */ + virtual void setTop(Widget* top); + + /** + * Gets the top widget. The top widget is the root widget + * of the GUI. + * + * @return The top widget. NULL if no top widget has been set. + * @since 0.1.0 + */ + virtual Widget* getTop() const; + + /** + * Sets the graphics object to use for drawing. + * + * @param graphics The graphics object to use for drawing. + * @see getGraphics, AllegroGraphics, HGEGraphics, + * OpenLayerGraphics, OpenGLGraphics, SDLGraphics + * @since 0.1.0 + */ + 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. + * @see setGraphics, AllegroGraphics, HGEGraphics, + * OpenLayerGraphics, OpenGLGraphics, SDLGraphics + * @since 0.1.0 + */ + virtual Graphics* getGraphics() const; + + /** + * Sets the input object to use for input handling. + * + * @param input The input object to use for input handling. + * @see getInput, AllegroInput, HGEInput, OpenLayerInput, + * SDLInput + * @since 0.1.0 + */ + 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. + * @see setInput, AllegroInput, HGEInput, OpenLayerInput, + * SDLInput + * @since 0.1.0 + */ + virtual Input* getInput() const; + + /** + * Performs logic of the GUI. By calling this function all logic + * functions down in the GUI heirarchy will be called. When logic + * is called for Gui, user input will be handled. + * + * @see Widget::logic + * @since 0.1.0 + */ + virtual void logic(); + + /** + * Draws the GUI. By calling this funcion all draw functions + * down in the GUI hierarchy will be called. When draw is called + * the used Graphics object will be initialised and drawing of + * the top widget will commence. + * + * @see Widget::draw + * @since 0.1.0 + */ + virtual void draw(); + + /** + * Focuses none of the widgets in the Gui. + * + * @since 0.1.0 + */ + virtual void focusNone(); + + /** + * Sets tabbing enabled, or not. Tabbing is the usage of + * changing focus by utilising the tab key. + * + * @param tabbing True if tabbing should be enabled, false + * otherwise. + * @see isTabbingEnabled + * @since 0.1.0 + */ + virtual void setTabbingEnabled(bool tabbing); + + /** + * Checks if tabbing is enabled. + * + * @return True if tabbing is enabled, false otherwise. + * @see setTabbingEnabled + * @since 0.1.0 + */ + virtual bool isTabbingEnabled(); + + /** + * Adds a global key listener to the Gui. A global key listener + * will receive all key events generated from the GUI and global + * key listeners will receive the events before key listeners + * of widgets. + * + * @param keyListener The key listener to add. + * @see removeGlobalKeyListener + * @since 0.5.0 + */ + virtual void addGlobalKeyListener(KeyListener* keyListener); + + /** + * Removes global key listener from the Gui. + * + * @param keyListener The key listener to remove. + * @throws Exception if the key listener hasn't been added. + * @see addGlobalKeyListener + * @since 0.5.0 + */ + 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 gained 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 + * gained 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(); + + /** + * Holds the top widget. + */ + Widget* mTop; + + /** + * Holds the graphics implementation used. + */ + Graphics* mGraphics; + + /** + * Holds the input implementation used. + */ + Input* mInput; + + /** + * Holds the focus handler for the Gui. + */ + FocusHandler* mFocusHandler; + + /** + * True if tabbing is enabled, false otherwise. + */ + bool mTabbing; + + /** + * Typedef. + */ + typedef std::list KeyListenerList; + + /** + * Typedef. + */ + typedef KeyListenerList::iterator KeyListenerListIterator; + + /** + * Holds the global key listeners of the Gui. + */ + KeyListenerList mKeyListeners; + + /** + * True if shift is pressed, false otherwise. + */ + bool mShiftPressed; + + /** + * True if meta is pressed, false otherwise. + */ + bool mMetaPressed; + + /** + * True if control is pressed, false otherwise. + */ + bool mControlPressed; + + /** + * True if alt is pressed, false otherwise. + */ + bool mAltPressed; + + /** + * Holds the last mouse button pressed. + */ + unsigned int mLastMousePressButton; + + /** + * Holds the last mouse press time stamp. + */ + int mLastMousePressTimeStamp; + + /** + * Holds the last mouse x coordinate. + */ + int mLastMouseX; + + /** + * Holds the last mouse y coordinate. + */ + int mLastMouseY; + + /** + * Holds the current click count. Used to keep track + * of clicks for a the last pressed button. + */ + int mClickCount; + + /** + * Holds the last button used when a drag of a widget + * was initiated. Used to be able to release a drag + * when the same button is released. + */ + int mLastMouseDragButton; + + /** + * Holds a stack with all the widgets with the mouse. + * Used to properly distribute mouse events. + */ + 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/guichan/include/guichan/image.hpp b/src/guichan/include/guichan/image.hpp new file mode 100644 index 000000000..e3bd27f69 --- /dev/null +++ b/src/guichan/include/guichan/image.hpp @@ -0,0 +1,191 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_IMAGE_HPP +#define GCN_IMAGE_HPP + +#include + +#include "guichan/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 might crash in a most bizarre way. + * @see AllegroImageLoader, HGEImageLoader, OpenLayerImageLoader, + * OpenGLAllegroImageLoader, OpenGLSDLImageLoader, SDLImageLoader + * @since 0.1.0 + */ + class GCN_CORE_DECLSPEC Image + { + public: + + /** + * Constructor. + */ + Image(); + + /** + * Destructor. + */ + virtual ~Image(); + + /** + * Loads an image by using the class' image loader. All image loaders + * implemented in Guichan return a newly instantiated image which must + * be deleted in order to avoid a memory leak. + * + * 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. + * @since 0.5.0 + */ + static Image* load(const std::string& filename, + bool convertToDisplayFormat = true); + + /** + * Gets the image loader used for loading images. + * + * @return The image loader used for loading images. + * @see setImageLoader, AllegroImageLoader, HGEImageLoader, + * OpenLayerImageLoader, OpenGLAllegroImageLoader, + * OpenGLSDLImageLoader, SDLImageLoader + * @since 0.1.0 + */ + static ImageLoader* getImageLoader(); + + /** + * Sets the ImageLoader to be used for loading images. + * + * IMPORTANT: The image loader is static and MUST be set before + * loading images! + * + * @param imageLoader The image loader to be used for loading images. + * @see getImageLoader, AllegroImageLoader, HGEImageLoader, + * OpenLayerImageLoader, OpenGLAllegroImageLoader, + * OpenGLSDLImageLoader, SDLImageLoader + * @since 0.1.0 + */ + static void setImageLoader(ImageLoader* imageLoader); + + /** + * Frees an image. + * + * @since 0.5.0 + */ + virtual void free() = 0; + + /** + * Gets the width of the image. + * + * @return The width of the image. + * + * @since 0.1.0 + */ + virtual int getWidth() const = 0; + + /** + * Gets the height of the image. + * + * @return The height of the image. + * + * @since 0.1.0 + */ + 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. + * + * @since 0.5.0 + */ + 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. + * @since 0.5.0 + */ + 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. + * @since 0.5.0 + */ + virtual void convertToDisplayFormat() = 0; + + protected: + /** + * Holds the image loader to be used when loading images. + */ + static ImageLoader* mImageLoader; + }; +} + +#endif // end GCN_IMAGE_HPP diff --git a/src/guichan/include/guichan/imageloader.hpp b/src/guichan/include/guichan/imageloader.hpp new file mode 100644 index 000000000..7c0adb842 --- /dev/null +++ b/src/guichan/include/guichan/imageloader.hpp @@ -0,0 +1,100 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_IMAGELOADER_HPP +#define GCN_IMAGELOADER_HPP + +#include + +#include "guichan/platform.hpp" + +namespace gcn +{ + class Image; + + /** + * Abstract class for providing functions for loading images. + * + * Guichan contains implementations of ImageLoader for common + * libraries like the Allegro library, the HGE library, + * he OpenLayer library, and the SDL library. + * To make Guichan usable with other libraries, an ImageLoader + * class must be implemented. + * + * To make Guichan use an image loader, the image loader needs + * to be passed to the Image class using the static method + * Image::setImageLoader. + * + * @see Image::setImageLoader, Image::getImageLoader, + * AllegroImageLoader, HGEImageLoader, OpenLayerImageLoader, + * OpenGLAllegroImageLoader, OpenGLSDLImageLoader, + * SDLImageLoader + * @since 0.1.0 + */ + class GCN_CORE_DECLSPEC ImageLoader + { + public: + + /** + * Destructor. + */ + virtual ~ImageLoader() + { } + + /** + * Loads an image. + * + * NOTE: The functions Image::getPixel and Image::putPixel + * are only guaranteed to work before an image has + * been converted to display format. + * + * @param filename The filename of the image 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/guichan/include/guichan/input.hpp b/src/guichan/include/guichan/input.hpp new file mode 100644 index 000000000..7510d3cb2 --- /dev/null +++ b/src/guichan/include/guichan/input.hpp @@ -0,0 +1,115 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_INPUT_HPP +#define GCN_INPUT_HPP + +#include "guichan/platform.hpp" + +namespace gcn +{ + class KeyInput; + class MouseInput; + + /** + * Abstract class for providing functions for user input. + * + * Guichan contains implementations of Input for common + * libraries like the Allegro library, the HGE library, + * and the SDL library. + * To make Guichan usable with other libraries, an Input + * class must be implemented. + * + * @see AllegroInput, HGEInput, OpenLayerInput, + * SDLInput + */ + class GCN_CORE_DECLSPEC Input + { + public: + + /** + * Destructor. + */ + virtual ~Input(){ } + + /** + * Checks if the key queue is empty, or not. + * + * @return True if the key queue is empty, + * false otherwise. + */ + virtual bool isKeyQueueEmpty() = 0; + + /** + * Dequeues the key input queue. + * + * @return The first key input in the key input queue. + */ + virtual KeyInput dequeueKeyInput() = 0; + + /** + * Checks if the mouse queue is empyt, or not. + * + * @return True if the mouse queue is empty, + * false otherwise. + */ + virtual bool isMouseQueueEmpty() = 0; + + /** + * Dequeues the mouse input queue. + * + * @return The first mouse input in the mouse input queue. + */ + virtual MouseInput dequeueMouseInput() = 0; + + /** + * Polls all exsisting input. Called when input should + * be polled. The function exists for compatibility reason + * where some libraries need to poll input at a certain + * logic rate. + */ + virtual void _pollInput() = 0; + }; +} + +#endif // end GCN_INPUT_HPP diff --git a/src/guichan/include/guichan/inputevent.hpp b/src/guichan/include/guichan/inputevent.hpp new file mode 100644 index 000000000..8594d3dae --- /dev/null +++ b/src/guichan/include/guichan/inputevent.hpp @@ -0,0 +1,159 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_INPUTEVENT_HPP +#define GCN_INPUTEVENT_HPP + +#include "guichan/event.hpp" +#include "guichan/platform.hpp" + +namespace gcn +{ + /** + * Base class for all events concerning input. + * + * @author Olof Naessén + * @since 0.6.0 + */ + class GCN_CORE_DECLSPEC InputEvent: public Event + { + public: + + /** + * Constructor. + * + * @param source The source widget of the event. + * @param isShiftPressed True if shift is pressed, false otherwise. + * @param isControlPressed True if control is pressed, false otherwise. + * @param isAltPressed True if alt is pressed, false otherwise. + * @param isMetaPressed True if meta is pressed, false otherwise. + */ + InputEvent(Widget* source, + bool isShiftPressed, + bool isControlPressed, + bool isAltPressed, + bool isMetaPressed); + + /** + * Checks if shift is pressed. + * + * @return True if shift was pressed at the same time as the key, + * false otherwise. + */ + bool isShiftPressed() const; + + /** + * Checks if control is pressed. + * + * @return True if control was pressed at the same time as the key, + * false otherwise. + */ + bool isControlPressed() const; + + /** + * Checks if alt is pressed. + * + * @return True if alt was pressed at the same time as the key, + * false otherwise. + */ + bool isAltPressed() const; + + /** + * Checks whether meta is pressed. + * + * @return True if meta was pressed at the same time as the key, + * false otherwise. + */ + bool isMetaPressed() const; + + /** + * Marks the event as consumed. Input event listeners may discard + * consumed input or act on consumed input. An example of a widget + * that discards consumed input is the ScrollArea widget that + * discards consumed mouse wheel events so the ScrollArea will not + * scroll if for instance a Slider's value inside the ScrollArea was + * changed with the mouse wheel. + * + * @see isConsumed + */ + void consume(); + + /** + * Checks if the input event is consumed. + * + * @return True if the input event is consumed, + * false otherwise. + * @see consume + */ + bool isConsumed() const; + + protected: + /** + * True if shift is pressed, false otherwise. + */ + bool mShiftPressed; + + /** + * True if control is pressed, false otherwise. + */ + bool mControlPressed; + + /** + * True if alt is pressed, false otherwise. + */ + bool mAltPressed; + + /** + * True if meta is pressed, false otherwise. + */ + bool mMetaPressed; + + /** + * True if the input event is consumed, + * false otherwise. + */ + bool mIsConsumed; + }; +} + +#endif // end GCN_INPUTEVENT_HPP diff --git a/src/guichan/include/guichan/key.hpp b/src/guichan/include/guichan/key.hpp new file mode 100644 index 000000000..0b550dcca --- /dev/null +++ b/src/guichan/include/guichan/key.hpp @@ -0,0 +1,182 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_KEY_HPP +#define GCN_KEY_HPP + +#include "guichan/platform.hpp" + +// windows.h defines DELETE which breaks this file as we have a constant named +// DELETE, hence we undefine DELETE if it is defined and hope people don't use +// that windows define with Guichan. +#if defined (_WIN32) && defined(DELETE) +#undef DELETE +#endif + +namespace gcn +{ + /** + * Represents a key or a character. + */ + class GCN_CORE_DECLSPEC Key + { + public: + + /** + * Constructor. + * + * @param value The ascii or enum value for the key. + */ + Key(int value = 0); + + /** + * Checks if a key is a character. + * + * @return True if the key is a letter, number or whitespace, + * false otherwise. + */ + bool isCharacter() const; + + /** + * Checks if a key is a number. + * + * @return True if the key is a number (0-9), + * false otherwise. + */ + bool isNumber() const; + + /** + * Checks if a key is a letter. + * + * @return True if the key is a letter (a-z,A-Z), + * false otherwise. + */ + bool isLetter() const; + + /** + * Gets the value of the key. If an ascii value exists it + * will be returned. Otherwise an enum value will be returned. + * + * @return the value of the key. + */ + int getValue() const; + + /** + * Compares two keys. + * + * @param key The key to compare this key with. + * @return True if the keys are equal, false otherwise. + */ + bool operator==(const Key& key) const; + + /** + * Compares two keys. + * + * @param key The key to compare this key with. + * @return True if the keys are not equal, false otherwise. + */ + bool operator!=(const Key& key) const; + + /** + * An enum with key values. + */ + enum + { + SPACE = ' ', + TAB = '\t', + ENTER = '\n', + LEFT_ALT = 1000, + RIGHT_ALT, + LEFT_SHIFT, + RIGHT_SHIFT, + LEFT_CONTROL, + RIGHT_CONTROL, + LEFT_META, + RIGHT_META, + LEFT_SUPER, + RIGHT_SUPER, + INSERT, + HOME, + PAGE_UP, + DELETE, + END, + PAGE_DOWN, + ESCAPE, + CAPS_LOCK, + BACKSPACE, + F1, + F2, + F3, + F4, + F5, + F6, + F7, + F8, + F9, + F10, + F11, + F12, + F13, + F14, + F15, + PRINT_SCREEN, + SCROLL_LOCK, + PAUSE, + NUM_LOCK, + ALT_GR, + LEFT, + RIGHT, + UP, + DOWN + }; + + protected: + /** + * Holds the value of the key. It may be an ascii value + * or an enum value. + */ + int mValue; + }; +} + +#endif // end GCN_KEY_HPP diff --git a/src/guichan/include/guichan/keyevent.hpp b/src/guichan/include/guichan/keyevent.hpp new file mode 100644 index 000000000..f42601235 --- /dev/null +++ b/src/guichan/include/guichan/keyevent.hpp @@ -0,0 +1,138 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_KEYEVENT_HPP +#define GCN_KEYEVENT_HPP + +#include "guichan/inputevent.hpp" +#include "guichan/key.hpp" +#include "guichan/platform.hpp" + +namespace gcn +{ + class Widget; + + /** + * Represents a key event. + */ + class GCN_CORE_DECLSPEC KeyEvent: public InputEvent + { + public: + /** + * Key event types. + */ + enum + { + PRESSED = 0, + RELEASED + }; + + /** + * Constructor. + * + * @param source The source widget of the event. + * @param isShiftPressed True if shift is pressed, false otherwise. + * @param isControlPressed True if control is pressed, false otherwise. + * @param isAltPressed True if alt is pressed, false otherwise. + * @param isMetaPressed True if meta is pressed, false otherwise. + * @param type The type of the event. A value from KeyEventType. + * @param isNumericPad True if the event occured on the numeric pad, + * false otherwise. + * @param key The key of the event. + */ + KeyEvent(Widget* source, + bool isShiftPressed, + bool isControlPressed, + bool isAltPressed, + bool isMetaPressed, + unsigned int type, + bool isNumericPad, + const Key& key); + + /** + * Destructor. + */ + virtual ~KeyEvent(); + + /** + * Gets the type of the event. + * + * @return The type of the event. + */ + unsigned int getType() const; + + /** + * Checks if the key event occured on the numeric pad. + * + * @return True if key event occured on the numeric pad, + * false otherwise. + * + */ + bool isNumericPad() const; + + /** + * Gets the key of the event. + * + * @return The key of the event. + */ + const Key& getKey() const; + + protected: + /** + * Holds the type of the key event. + */ + unsigned int mType; + + /** + * True if the numeric pad was used, false otherwise. + */ + bool mIsNumericPad; + + /** + * Holds the key of the key event. + */ + Key mKey; + }; +} + +#endif // end GCN_KEYEVENT_HPP diff --git a/src/guichan/include/guichan/keyinput.hpp b/src/guichan/include/guichan/keyinput.hpp new file mode 100644 index 000000000..68c58fa0d --- /dev/null +++ b/src/guichan/include/guichan/keyinput.hpp @@ -0,0 +1,270 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_KEYINPUT_HPP +#define GCN_KEYINPUT_HPP + +#include "guichan/key.hpp" +#include "guichan/platform.hpp" + +namespace gcn +{ + /** + * Internal class that represents key input. Generally you won't have to + * bother using this class unless you implement an Input class for + * a back end. + * + * @since 0.1.0 + */ + class GCN_CORE_DECLSPEC KeyInput + { + public: + + /** + * Constructor. + */ + KeyInput() : + mType(0), + mShiftPressed(false), + mControlPressed(false), + mAltPressed(false), + mMetaPressed(false), + mNumericPad(false) + { }; + + /** + * Constructor. + * + * @param key The key of the key input. + * @param type The type of key input. + */ + KeyInput(const Key& key, unsigned int type); + + /** + * Sets the type of the key input. + * + * @param type The type of key input. + * @see getType + */ + void setType(unsigned int type); + + /** + * Gets the type of the key input. + * + * @return the input type. + * @see setType + */ + int getType() const; + + /** + * Sets the key of the key input. + * + * @param key The key of the key input. + * @see getKey + */ + void setKey(const Key& key); + + /** + * Gets the key of the key input. + * + * @return The key of the key input. + * @see setKey + */ + const Key& getKey() const; + + /** + * Checks if shift is pressed. + * + * @return True if shift was pressed at the same + * time as the key, false otherwise. + * @see setShiftPressed + * @since 0.6.0 + */ + bool isShiftPressed() const; + + /** + * Sets shift to be pressed at the same time as the key, + * or not. + * + * @param pressed True if shift is pressed, false otherwise. + * @see isShiftPressed + * @since 0.6.0 + */ + void setShiftPressed(bool pressed); + + /** + * Checks if control is pressed. + * + * @return True if control was pressed at the same + * time as the key, false otherwise. + * @see setControlPressed + * @since 0.6.0 + */ + bool isControlPressed() const; + + /** + * Sets control to be pressed at the same time as the key, + * or not. + * + * @param pressed True if control is pressed, false otherwise. + * @see isControlPressed + * @since 0.6.0 + */ + void setControlPressed(bool pressed); + + /** + * Checks if alt is pressed. + * + * @return True if alt was pressed at the same + * time as the key, false otherwise. + * @see setAltPressed + * @since 0.6.0 + */ + bool isAltPressed() const; + + /** + * Sets the alt to be pressed at the same time as the key, + * or not. + * + * @param pressed True if alt is pressed at the same + * time as the key, , false otherwise. + * @see isAltPressed + * @since 0.6.0 + */ + void setAltPressed(bool pressed); + + /** + * Checks if meta is pressed. + * + * @return True if meta was pressed at the same + * time as the key, false otherwise. + * @see setMetaPressed + * @since 0.6.0 + */ + bool isMetaPressed() const; + + /** + * Sets meta to be pressed at the same time as the key, + * or not. + * + * @param pressed True if meta is pressed at the same + * time as the key, false otherwise. + * @see isMetaPressed + * @since 0.6.0 + */ + void setMetaPressed(bool pressed); + + /** + * Checks if the key was pressed at the numeric pad. + * + * @return True if key pressed at the numeric pad, + * false otherwise. + * @setNumericPad + * @since 0.6.0 + */ + bool isNumericPad() const; + + /** + * Sets the key to be pressed at the numeric pad. + * + * @param numpad True if the key was pressed at the numeric + * pad, false otherwise. + * @see isNumericPad + * @since 0.6.0 + */ + void setNumericPad(bool numpad); + + /** + * Key input types. This enum corresponds to the enum with event + * types on KeyEvent for easy mapping. + */ + enum + { + PRESSED = 0, + RELEASED + }; + + protected: + /** + * Holds the key of the key input. + */ + Key mKey; + + /** + * Holds the type of the key input. + */ + unsigned int mType; + + /** + * True if shift was pressed at the same time as the key, + * false otherwise. + */ + bool mShiftPressed; + + /** + * True if control was pressed at the same time as the key, + * false otherwise. + */ + bool mControlPressed; + + /** + * True if alt was pressed at the same time as the key, + * false otherwise. + */ + bool mAltPressed; + + /** + * True if meta was pressed at the same time as the key, + * false otherwise. + */ + bool mMetaPressed; + + /** + * True if the numeric pad was used when the key was pressed, + * false otherwise. + */ + bool mNumericPad; + }; +} + +#endif // end GCN_KEYINPUT_HPP diff --git a/src/guichan/include/guichan/keylistener.hpp b/src/guichan/include/guichan/keylistener.hpp new file mode 100644 index 000000000..caeed0da4 --- /dev/null +++ b/src/guichan/include/guichan/keylistener.hpp @@ -0,0 +1,101 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_KEYLISTENER_HPP +#define GCN_KEYLISTENER_HPP + +#include "guichan/keyevent.hpp" +#include "guichan/platform.hpp" + +#ifdef __GNUC__ +#define _UNUSED_ __attribute__ ((unused)) +#else +#define _UNUSED_ +#endif + +namespace gcn +{ + class Key; + + /** + * Interface for listening for key events from widgets. + * + * @see Widget::addKeyListener, Widget::removeKeyListener + */ + class GCN_CORE_DECLSPEC KeyListener + { + public: + + /** + * Destructor. + */ + virtual ~KeyListener() { } + + /** + * Called if a key is pressed when the widget has keyboard focus. + * If a key is held down the widget will generate multiple key + * presses. + * + * @param keyEvent Discribes the event. + */ + virtual void keyPressed(KeyEvent& keyEvent _UNUSED_) { } + + /** + * Called if a key is released when the widget has keyboard focus. + * + * @param keyEvent Discribes the event. + */ + virtual void keyReleased(KeyEvent& keyEvent _UNUSED_) { } + + protected: + /** + * Constructor. + * + * You should not be able to make an instance of KeyListener, + * therefore its constructor is protected. + */ + KeyListener() { } + }; +} + +#endif // end GCN_KEYLISTENER_HPP diff --git a/src/guichan/include/guichan/listmodel.hpp b/src/guichan/include/guichan/listmodel.hpp new file mode 100644 index 000000000..1beae317b --- /dev/null +++ b/src/guichan/include/guichan/listmodel.hpp @@ -0,0 +1,86 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_LISTMODEL_HPP +#define GCN_LISTMODEL_HPP + +#include + +#include "guichan/platform.hpp" + +namespace gcn +{ + /** + * An interface for a model that represents a list. It is + * used in certain widgets, like the ListBox, to handle a + * lists with string elements. If you want to use widgets + * like ListBox, make a derived class from this class that + * represents your list. + */ + class GCN_CORE_DECLSPEC ListModel + { + + public: + /** + * Destructor. + */ + virtual ~ListModel() { } + + /** + * Gets the number of elements in the list. + * + * @return The number of elements in the list + */ + 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 at the a certain index. + */ + virtual std::string getElementAt(int i) = 0; + }; +} + +#endif // end GCN_LISTMODEL_HPP diff --git a/src/guichan/include/guichan/mouseevent.hpp b/src/guichan/include/guichan/mouseevent.hpp new file mode 100644 index 000000000..280d373e6 --- /dev/null +++ b/src/guichan/include/guichan/mouseevent.hpp @@ -0,0 +1,200 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_MOUSEEVENT_HPP +#define GCN_MOUSEEVENT_HPP + +#include "guichan/inputevent.hpp" +#include "guichan/platform.hpp" + +namespace gcn +{ + class Gui; + class Widget; + + /** + * Represents a mouse event. + * + * @author Olof Naessén + * @since 0.6.0 + */ + class GCN_CORE_DECLSPEC MouseEvent: public InputEvent + { + public: + + /** + * Constructor. + * + * @param source The source widget of the mouse event. + * @param isShiftPressed True if shift is pressed, false otherwise. + * @param isControlPressed True if control is pressed, false otherwise. + * @param isAltPressed True if alt is pressed, false otherwise. + * @param isMetaPressed True if meta is pressed, false otherwise. + * @param type The type of the mouse event. + * @param button The button of the mouse event. + * @param x The x coordinate of the event relative to the source widget. + * @param y The y coordinate of the event relative the source widget. + * @param clickCount The number of clicks generated with the same button. + * It's set to zero if another button is used. + */ + MouseEvent(Widget* source, + bool isShiftPressed, + bool isControlPressed, + bool isAltPressed, + bool isMetaPressed, + unsigned int type, + unsigned int button, + int x, + int y, + int clickCount); + + /** + * Gets the button of the mouse event. + * + * @return The button of the mouse event. + */ + unsigned int getButton() const; + + /** + * Gets the x coordinate of the mouse event. + * The coordinate relative to widget the mouse listener + * receiving the events have registered to. + * + * @return The x coordinate of the mouse event. + * @see Widget::addMouseListener, Widget::removeMouseListener + */ + int getX() const; + + /** + * Gets the y coordinate of the mouse event. + * The coordinate relative to widget the mouse listener + * receiving the events have registered to. + * + * @return The y coordinate of the mouse event. + * @see Widget::addMouseListener, Widget::removeMouseListener + */ + int getY() const; + + /** + * Gets the number of clicks generated with the same button. + * It's set to zero if another button is used. + * + * @return The number of clicks generated with the same button. + */ + int getClickCount() const; + + /** + * Gets the type of the event. + * + * @return The type of the event. + */ + unsigned int getType() const; + + /** + * Mouse event types. + */ + enum + { + MOVED = 0, + PRESSED, + RELEASED, + WHEEL_MOVED_DOWN, + WHEEL_MOVED_UP, + CLICKED, + ENTERED, + EXITED, + DRAGGED + + }; + + /** + * Mouse button types. + */ + enum + { + EMPTY = 0, + LEFT, + RIGHT, + MIDDLE + }; + + protected: + /** + * Holds the type of the mouse event. + */ + unsigned int mType; + + /** + * Holds the button of the mouse event. + */ + unsigned int mButton; + + /** + * Holds the x-coordinate of the mouse event. + */ + int mX; + + /** + * Holds the y-coordinate of the mouse event. + */ + int mY; + + /** + * The number of clicks generated with the same button. + * It's set to zero if another button is used. + */ + int mClickCount; + + /** + * Gui is a friend of this class in order to be able to manipulate + * the protected member variables of this class and at the same time + * keep the MouseEvent class as const as possible. Gui needs to + * update the x och y coordinates for the coordinates to be relative + * to widget the mouse listener receiving the events have registered + * to. + */ + friend class Gui; + }; +} + +#endif // GCN_MOUSEEVENT_HPP diff --git a/src/guichan/include/guichan/mouseinput.hpp b/src/guichan/include/guichan/mouseinput.hpp new file mode 100644 index 000000000..3825d5439 --- /dev/null +++ b/src/guichan/include/guichan/mouseinput.hpp @@ -0,0 +1,241 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_MOUSEINPUT_HPP +#define GCN_MOUSEINPUT_HPP + +#include "guichan/platform.hpp" + +namespace gcn +{ + + /** + * Internal class that represents mouse input. Generally you won't have to + * bother using this class unless you implement an Input class for + * a back end. + * + * @author Olof Naessén + * @author Per Larsson + * @since 0.1.0 + */ + class GCN_CORE_DECLSPEC MouseInput + { + public: + + /** + * Constructor. + */ + MouseInput() : + mType(0), + mButton(0), + mTimeStamp(0), + mX(0), + mY(0) + { }; + + /** + * Constructor. + * + * @param button The button pressed. + * @param type The type of mouse input. + * @param x The mouse x coordinate. + * @param y The mouse y coordinate. + * @param timeStamp The timestamp of the mouse input. Used to + * check for double clicks. + */ + MouseInput(unsigned int button, + unsigned int type, + int x, + int y, + int timeStamp); + + /** + * Sets the type of the mouse input. + * + * @param type The type of the mouse input. Should be a value from the + * mouse event type enum + * @see getType + * @since 0.1.0 + */ + void setType(unsigned int type); + + /** + * Gets the type of the mouse input. + * + * @return The type of the mouse input. A value from the mouse event + * type enum. + * @see setType + * @since 0.1.0 + */ + unsigned int getType() const; + + /** + * Sets the button pressed. + * + * @param button The button pressed. Should be one of the values + * in the mouse event button enum. + * @see getButton. + * @since 0.1.0 + */ + void setButton(unsigned int button); + + /** + * Gets the button pressed. + * + * @return The button pressed. A value from the mouse event + * button enum. + * @see setButton + * @since 0.1.0 + */ + unsigned int getButton() const; + + /** + * Sets the timestamp for the mouse input. + * Used to check for double clicks. + * + * @param timeStamp The timestamp of the mouse input. + * @see getTimeStamp + * @since 0.1.0 + */ + void setTimeStamp(int timeStamp); + + /** + * Gets the time stamp of the input. + * Used to check for double clicks. + * + * @return The time stamp of the mouse input. + * @see setTimeStamp + * @since 0.1.0 + */ + int getTimeStamp() const; + + /** + * Sets the x coordinate of the mouse input. + * + * @param x The x coordinate of the mouse input. + * @see getX + * @since 0.6.0 + */ + void setX(int x); + + /** + * Gets the x coordinate of the mouse input. + * + * @return The x coordinate of the mouse input. + * @see setX + * @since 0.6.0 + */ + int getX() const; + + /** + * Sets the y coordinate of the mouse input. + * + * @param y The y coordinate of the mouse input. + * @see getY + * @since 0.6.0 + */ + void setY(int y); + + /** + * Gets the y coordinate of the mouse input. + * + * @return The y coordinate of the mouse input. + * @see setY + * @since 0.6.0 + */ + int getY() const; + + /** + * Mouse input event types. This enum partially corresponds + * to the enum with event types in MouseEvent for easy mapping. + */ + enum + { + MOVED = 0, + PRESSED, + RELEASED, + WHEEL_MOVED_DOWN, + WHEEL_MOVED_UP + }; + + /** + * Mouse button types. + */ + enum + { + EMPTY = 0, + LEFT, + RIGHT, + MIDDLE + }; + + protected: + /** + * Holds the type of the mouse input. + */ + unsigned int mType; + + /** + * Holds the button of the mouse input. + */ + unsigned int mButton; + + /** + * Holds the timestamp of the mouse input. Used to + * check for double clicks. + */ + int mTimeStamp; + + /** + * Holds the x coordinate of the mouse input. + */ + int mX; + + /** + * Holds the y coordinate of the mouse input. + */ + int mY; + }; +} + +#endif // end GCN_MOUSEINPUT_HPP diff --git a/src/guichan/include/guichan/mouselistener.hpp b/src/guichan/include/guichan/mouselistener.hpp new file mode 100644 index 000000000..152d3494e --- /dev/null +++ b/src/guichan/include/guichan/mouselistener.hpp @@ -0,0 +1,189 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_MOUSELISTENER_HPP +#define GCN_MOUSELISTENER_HPP + +#include "guichan/mouseevent.hpp" +#include "guichan/platform.hpp" + +#ifdef __GNUC__ +#define _UNUSED_ __attribute__ ((unused)) +#else +#define _UNUSED_ +#endif + +namespace gcn +{ + /** + * Interface for listening for mouse events from widgets. + * + * @see Widget::addMouseListener, Widget::removeMouseListener + * @since 0.1.0 + */ + class GCN_CORE_DECLSPEC MouseListener + { + public: + + /** + * Destructor. + */ + virtual ~MouseListener() { } + + /** + * Called when the mouse has entered into the widget area. + * + * @param mouseEvent Describes the event. + * @since 0.6.0 + */ + virtual void mouseEntered(MouseEvent& mouseEvent _UNUSED_) + { + + } + + /** + * Called when the mouse has exited the widget area. + * + * @param mouseEvent Describes the event. + * @since 0.6.0 + */ + virtual void mouseExited(MouseEvent& mouseEvent _UNUSED_) + { + + } + + /** + * Called when a mouse button has been pressed on the widget area. + * + * NOTE: A mouse press is NOT equal to a mouse click. + * Use mouseClickMessage to check for mouse clicks. + * + * @param mouseEvent Describes the event. + * @since 0.6.0 + */ + virtual void mousePressed(MouseEvent& mouseEvent _UNUSED_) + { + + } + + /** + * Called when a mouse button has been released on the widget area. + * + * @param mouseEvent Describes the event. + * @since 0.6.0 + */ + virtual void mouseReleased(MouseEvent& mouseEvent _UNUSED_) + { + + } + + /** + * Called when a mouse button is pressed and released (clicked) on + * the widget area. + * + * @param mouseEvent Describes the event. + * @since 0.6.0 + */ + virtual void mouseClicked(MouseEvent& mouseEvent _UNUSED_) + { + + } + + /** + * Called when the mouse wheel has moved up on the widget area. + * + * @param mouseEvent Describes the event. + * @since 0.6.0 + */ + virtual void mouseWheelMovedUp(MouseEvent& mouseEvent _UNUSED_) + { + + } + + /** + * Called when the mouse wheel has moved down on the widget area. + * + * @param mousEvent Describes the event. + * @since 0.6.0 + */ + virtual void mouseWheelMovedDown(MouseEvent& mouseEvent _UNUSED_) + { + + } + + /** + * Called when the mouse has moved in the widget area and no mouse button + * has been pressed (i.e no widget is being dragged). + * + * @param mouseEvent Describes the event. + * @since 0.6.0 + */ + virtual void mouseMoved(MouseEvent& mouseEvent _UNUSED_) + { + + } + + /** + * Called when the mouse has moved and the mouse has previously been + * pressed on the widget. + * + * @param mouseEvent Describes the event. + * @since 0.6.0 + */ + virtual void mouseDragged(MouseEvent& mouseEvent _UNUSED_) + { + + } + + protected: + /** + * Constructor. + * + * You should not be able to make an instance of MouseListener, + * therefore its constructor is protected. + */ + MouseListener() { } + }; +} + +#endif // end GCN_MOUSELISTENER_HPP diff --git a/src/guichan/include/guichan/platform.hpp b/src/guichan/include/guichan/platform.hpp new file mode 100644 index 000000000..e2ea89767 --- /dev/null +++ b/src/guichan/include/guichan/platform.hpp @@ -0,0 +1,79 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_PLATFORM_HPP +#define GCN_PLATFORM_HPP + +#if defined (__MINGW32__) && defined(GUICHAN_BUILD) +#define GCN_CORE_DECLSPEC __declspec(dllexport) + +#elif defined (__MINGW32__) && defined(GUICHAN_EXTENSION_BUILD) +#define GCN_EXTENSION_DECLSPEC __declspec(dllexport) +#define GCN_CORE_DECLSPEC __declspec(dllimport) + +#elif defined (__MINGW32__) && defined(GUICHAN_DLL_IMPORT) +#define GCN_CORE_DECLSPEC __declspec(dllimport) +#define GCN_EXTENSION_DECLSPEC __declspec(dllimport) + +#elif defined(_MSC_VER) && defined(GUICHAN_BUILD) +#define GCN_CORE_DECLSPEC _declspec(dllexport) + +#elif defined(_MSC_VER) && defined(GUICHAN_EXTENSION_BUILD) +#define GCN_CORE_DECLSPEC _declspec(dllimport) +#define GCN_EXTENSION_DECLSPEC _declspec(dllexport) + +#endif + +#ifndef GCN_CORE_DECLSPEC +#define GCN_CORE_DECLSPEC +#endif + +#ifndef GCN_EXTENSION_DECLSPEC +#define GCN_EXTENSION_DECLSPEC +#endif + +#ifndef NULL +#define NULL 0 +#endif + +#endif // end GCN_PLATFORM_HPP diff --git a/src/guichan/include/guichan/rectangle.hpp b/src/guichan/include/guichan/rectangle.hpp new file mode 100644 index 000000000..1d21654df --- /dev/null +++ b/src/guichan/include/guichan/rectangle.hpp @@ -0,0 +1,140 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_RECTANGLE_HPP +#define GCN_RECTANGLE_HPP + +#include "guichan/platform.hpp" + +#include + +namespace gcn +{ + /** + * Represents a rectangle. + * + * @since 0.1.0 + */ + class GCN_CORE_DECLSPEC Rectangle + { + public: + + /** + * Constructor. The default rectangle is an empty rectangle + * at the coordinates (0,0). + */ + Rectangle(); + + /** + * Constructor. + * + * @param x The x coordinate of the rectangle. + * @param y The y coordinate of the rectangle. + * @param width The width of the rectangle. + * @param height The height of the rectangle. + * @since 0.1.0 + */ + Rectangle(int x, int y, int width, int height); + + /** + * Sets the dimension of a rectangle. + * + * @param x The x coordinate of the rectangle. + * @param y The y coordinate of the rectangle. + * @param width The width of the rectangle. + * @param height The height of the rectangle. + * @since 0.1.0 + */ + void setAll(int x, int y, int width, int height); + + /** + * Checks if another rectangle intersects with the rectangle. + * + * @param rectangle Another rectangle to check for intersection. + * @return True if the rectangles intersect, false otherwise. + * @since 0.1.0 + */ + bool isIntersecting(const Rectangle& rectangle) const; + + /** + * Checks if a point is inside the rectangle + * + * @param x The x coordinate of the point. + * @param y The y coordinate of the point. + * @return True if the point is inside the rectangle. + * @since 0.1.0 + */ + bool isPointInRect(int x, int y) const; + + /** + * Output operator for output. + * + * @param out The stream to output to. + * @param rectangle The rectangle to output. + */ + friend std::ostream& operator<<(std::ostream& out, + const Rectangle& rectangle); + + /** + * Holds the x coordinate of the rectangle. + */ + int x; + + /** + * Holds the x coordinate of the rectangle. + */ + int y; + + /** + * Holds the width of the rectangle. + */ + int width; + + /** + * Holds the height of the rectangle. + */ + int height; + }; +} + +#endif // end GCN_RECTANGEL_HPP diff --git a/src/guichan/include/guichan/sdl/sdlgraphics.hpp b/src/guichan/include/guichan/sdl/sdlgraphics.hpp new file mode 100644 index 000000000..70a234d33 --- /dev/null +++ b/src/guichan/include/guichan/sdl/sdlgraphics.hpp @@ -0,0 +1,156 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_SDLGRAPHICS_HPP +#define GCN_SDLGRAPHICS_HPP + +#include "SDL.h" + +#include "guichan/color.hpp" +#include "guichan/graphics.hpp" +#include "guichan/platform.hpp" + +namespace gcn +{ + class Image; + class Rectangle; + + /** + * SDL implementation of the Graphics. + */ + class GCN_EXTENSION_DECLSPEC SDLGraphics : public Graphics + { + public: + + // Needed so that drawImage(gcn::Image *, int, int) is visible. + using Graphics::drawImage; + + /** + * Constructor. + */ + SDLGraphics(); + + /** + * Sets the target SDL_Surface to draw to. The target can be any + * SDL_Surface. This funtion also pushes a clip areas corresponding to + * the dimension of the target. + * + * @param target the target to draw to. + */ + virtual void setTarget(SDL_Surface* target); + + /** + * Gets the target SDL_Surface. + * + * @return the target SDL_Surface. + */ + virtual SDL_Surface* getTarget() const; + + /** + * Draws an SDL_Surface on the target surface. Normaly you'll + * use drawImage, but if you want to write SDL specific code + * this function might come in handy. + * + * NOTE: The clip areas will be taken into account. + */ + virtual void drawSDLSurface(SDL_Surface* surface, + SDL_Rect source, + SDL_Rect destination); + + + // Inherited from Graphics + + virtual void _beginDraw(); + + virtual void _endDraw(); + + virtual bool pushClipArea(Rectangle area); + + virtual void popClipArea(); + + virtual void drawImage(const Image* image, + int srcX, + int srcY, + int dstX, + int dstY, + int width, + int height); + + virtual void drawPoint(int x, int y); + + virtual void drawLine(int x1, int y1, int x2, int y2); + + virtual void drawRectangle(const Rectangle& rectangle); + + virtual void fillRectangle(const Rectangle& rectangle); + + virtual void setColor(const Color& color); + + virtual const Color& getColor() const; + + protected: + /** + * Draws a horizontal line. + * + * @param x1 the start coordinate of the line. + * @param y the y coordinate of the line. + * @param x2 the end coordinate of the line. + */ + virtual void drawHLine(int x1, int y, int x2); + + /** + * Draws a vertical line. + * + * @param x the x coordinate of the line. + * @param y1 the start coordinate of the line. + * @param y2 the end coordinate of the line. + */ + virtual void drawVLine(int x, int y1, int y2); + + SDL_Surface* mTarget; + Color mColor; + bool mAlpha; + }; +} + +#endif // end GCN_SDLGRAPHICS_HPP diff --git a/src/guichan/include/guichan/sdl/sdlimage.hpp b/src/guichan/include/guichan/sdl/sdlimage.hpp new file mode 100644 index 000000000..4d226177e --- /dev/null +++ b/src/guichan/include/guichan/sdl/sdlimage.hpp @@ -0,0 +1,107 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_SDLIMAGE_HPP +#define GCN_SDLIMAGE_HPP + +#include "SDL.h" + +#include + +#include "guichan/color.hpp" +#include "guichan/platform.hpp" +#include "guichan/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/guichan/include/guichan/sdl/sdlpixel.hpp b/src/guichan/include/guichan/sdl/sdlpixel.hpp new file mode 100644 index 000000000..675b10fcd --- /dev/null +++ b/src/guichan/include/guichan/sdl/sdlpixel.hpp @@ -0,0 +1,281 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_SDLPIXEL_HPP +#define GCN_SDLPIXEL_HPP + +#include "SDL.h" +#include "guichan/color.hpp" + +namespace gcn +{ + + /** + * Checks a pixels color of an SDL_Surface. + * + * @param surface an SDL_Surface where to check for a pixel color. + * @param x the x coordinate on the surface. + * @param y the y coordinate on the surface. + * @return a color of a pixel. + */ + inline const Color SDLgetPixel(SDL_Surface* surface, int x, int y) + { + int bpp = surface->format->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; + + default: + color = *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; + + default: + 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: + 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; + default: + break; + } + + SDL_UnlockSurface(surface); + } +} + +#endif // end GCN_SDLPIXEL_HPP diff --git a/src/guichan/include/guichan/selectionevent.hpp b/src/guichan/include/guichan/selectionevent.hpp new file mode 100644 index 000000000..6724fa0d2 --- /dev/null +++ b/src/guichan/include/guichan/selectionevent.hpp @@ -0,0 +1,78 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_SELECTIONEVENT_HPP +#define GCN_SELECTIONEVENT_HPP + +#include "guichan/event.hpp" +#include "guichan/platform.hpp" + +namespace gcn +{ + class Widget; + + /** + * Represents a selection event. + * + * @author Olof Naessén + * @since 0.8.0 + */ + class GCN_CORE_DECLSPEC SelectionEvent: public Event + { + public: + + /** + * Constructor. + * + * @param source source The widget of the selection event. + */ + SelectionEvent(Widget* source); + + /** + * Destructor. + */ + virtual ~SelectionEvent(); + }; +} + +#endif // end GCN_SELECTIONEVENT_HPP diff --git a/src/guichan/include/guichan/widget.hpp b/src/guichan/include/guichan/widget.hpp new file mode 100644 index 000000000..0f8c803ca --- /dev/null +++ b/src/guichan/include/guichan/widget.hpp @@ -0,0 +1,1202 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_WIDGET_HPP +#define GCN_WIDGET_HPP + +#include +#include + +#include "guichan/color.hpp" +#include "guichan/rectangle.hpp" + +#ifdef __GNUC__ +#define _UNUSED_ __attribute__ ((unused)) +#else +#define _UNUSED_ +#endif + +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; + + /** + * Abstract class for widgets of Guichan. It contains basic functions + * every widget should have. + * + * NOTE: Functions begining with underscore "_" should not + * be overloaded unless you know what you are doing + * + * @author Olof Naessén + * @author Per Larsson. + * @since 0.1.0 + */ + 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 widget's dimension. + * + * @param graphics aA graphics object to draw with. + * @since 0.1.0 + */ + virtual void draw(Graphics* graphics) = 0; + + /** + * Called when a widget is given a chance to draw a frame around itself. + * The frame is not considered a part of the widget, it only allows a frame + * to be drawn around the widget, thus a frame will never be included when + * calculating if a widget should receive events from user input. Also + * a widget's frame will never be included when calculating a widget's + * position. + * + * The size of the frame is calculated using the widget's frame size. + * If a widget has a frame size of 10 pixels than the area the drawFrame + * function can draw to will be the size of the widget with an additional + * extension of 10 pixels in each direction. + * + * An example when drawFrame is a useful function is if a widget needs + * a glow around itself. + * + * @param graphics A graphics object to draw with. + * @see setFrameSize, getFrameSize + * @since 0.8.0 + */ + virtual void drawFrame(Graphics* graphics); + + /** + * Sets the size of the widget's frame. The frame is not considered a part of + * the widget, it only allows a frame to be drawn around the widget, thus a frame + * will never be included when calculating if a widget should receive events + * from user input. Also a widget's frame will never be included when calculating + * a widget's position. + * + * A frame size of 0 means that the widget has no frame. The default frame size + * is 0. + * + * @param frameSize The size of the widget's frame. + * @see getFrameSize, drawFrame + * @since 0.8.0 + */ + void setFrameSize(unsigned int frameSize); + + /** + * Gets the size of the widget's frame. The frame is not considered a part of + * the widget, it only allows a frame to be drawn around the widget, thus a frame + * will never be included when calculating if a widget should receive events + * from user input. Also a widget's frame will never be included when calculating + * a widget's position. + * + * A frame size of 0 means that the widget has no frame. The default frame size + * is 0. + * + * @return The size of the widget's frame. + * @see setFrameSize, drawFrame + * @since 0.8.0 + */ + unsigned int getFrameSize() const; + + /** + * 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::logic + * @since 0.1.0 + */ + virtual void logic() { } + + /** + * Gets the widget's parent container. + * + * @return The widget's parent container. NULL if the widget + * has no parent. + * @since 0.1.0 + */ + virtual Widget* getParent() const; + + /** + * Sets the width of the widget. + * + * @param width The width of the widget. + * @see getWidth, setHeight, getHeight, setSize, + * setDimension, getDimensi + * @since 0.1.0 + */ + void setWidth(int width); + + /** + * Gets the width of the widget. + * + * @return The width of the widget. + * @see setWidth, setHeight, getHeight, setSize, + * setDimension, getDimension + * @since 0.1.0 + */ + int getWidth() const; + + /** + * Sets the height of the widget. + * + * @param height The height of the widget. + * @see getHeight, setWidth, getWidth, setSize, + * setDimension, getDimension + * @since 0.1.0 + */ + void setHeight(int height); + + /** + * Gets the height of the widget. + * + * @return The height of the widget. + * @see setHeight, setWidth, getWidth, setSize, + * setDimension, getDimension + * @since 0.1.0 + */ + int getHeight() const; + + /** + * Sets the size of the widget. + * + * @param width The width of the widget. + * @param height The height of the widget. + * @see setWidth, setHeight, getWidth, getHeight, + * setDimension, getDimension + * @since 0.1.0 + */ + void setSize(int width, int height); + + /** + * Sets the x coordinate of the widget. The coordinate is + * relateive to the widget's parent. + * + * @param x The x coordinate of the widget. + * @see getX, setY, getY, setPosition, setDimension, getDimension + * @since 0.1.0 + */ + void setX(int x); + + /** + * Gets the x coordinate of the widget. The coordinate is + * relative to the widget's parent. + * + * @return The x coordinate of the widget. + * @see setX, setY, getY, setPosition, setDimension, getDimension + * @since 0.1.0 + */ + int getX() const; + + /** + * Sets the y coordinate of the widget. The coordinate is + * relative to the widget's parent. + * + * @param y The y coordinate of the widget. + * @see setY, setX, getX, setPosition, setDimension, getDimension + * @since 0.1.0 + */ + void setY(int y); + + /** + * Gets the y coordinate of the widget. The coordinate is + * relative to the widget's parent. + * + * @return The y coordinate of the widget. + * @see setY, setX, getX, setPosition, setDimension, getDimension + * @since 0.1.0 + */ + int getY() const; + + /** + * Sets position of the widget. The position is relative + * to the widget's parent. + * + * @param x The x coordinate of the widget. + * @param y The y coordinate of the widget. + * @see setX, getX, setY, getY, setDimension, getDimension + * @since 0.1.0 + */ + void setPosition(int x, int y); + + /** + * Sets the dimension of the widget. The dimension is + * relative to the widget's parent. + * + * @param dimension The dimension of the widget. + * @see getDimension, setX, getX, setY, getY, setPosition + * @since 0.1.0 + */ + void setDimension(const Rectangle& dimension); + + /** + * Gets the dimension of the widget. The dimension is + * relative to the widget's parent. + * + * @return The dimension of the widget. + * @see getDimension, setX, getX, setY, getY, setPosition + * @since 0.1.0 + */ + const Rectangle& getDimension() const; + + /** + * Sets the widget to be fosusable, or not. + * + * @param focusable True if the widget should be focusable, + * false otherwise. + * @see isFocusable + * @since 0.1.0 + */ + void setFocusable(bool focusable); + + /** + * Checks if a widget is focsable. + * + * @return True if the widget should be focusable, false otherwise. + * @see setFocusable + * @since 0.1.0 + */ + bool isFocusable() const; + + /** + * Checks if the widget is focused. + * + * @return True if the widget is focused, false otherwise. + * @since 0.1.0 + */ + virtual bool isFocused() const; + + /** + * Sets the widget to enabled, or not. A disabled + * widget will never recieve mouse or key events. + * + * @param enabled True if widget should be enabled, + * false otherwise. + * @see isEnabled + * @since 0.1.0 + */ + void setEnabled(bool enabled); + + /** + * Checks if the widget is enabled. A disabled + * widget will never recieve mouse or key events. + * + * @return True if widget is enabled, false otherwise. + * @see setEnabled + * @since 0.1.0 + */ + bool isEnabled() const; + + /** + * Sets the widget to be visible, or not. + * + * @param visible True if widget should be visible, false otherwise. + * @see isVisible + * @since 0.1.0 + */ + void setVisible(bool visible); + + /** + * Checks if the widget is visible. + * + * @return True if widget is be visible, false otherwise. + * @see setVisible + * @since 0.1.0 + */ + bool isVisible() const; + + /** + * Sets the base color of the widget. + * + * @param color The baseground color. + * @see getBaseColor + * @since 0.1.0 + */ + void setBaseColor(const Color& color); + + /** + * Gets the base color. + * + * @return The base color. + * @see setBaseColor + * @since 0.1.0 + */ + const Color& getBaseColor() const; + + /** + * Sets the foreground color. + * + * @param color The foreground color. + * @see getForegroundColor + * @since 0.1.0 + */ + void setForegroundColor(const Color& color); + + /** + * Gets the foreground color. + * + * @see setForegroundColor + * @since 0.1.0 + */ + const Color& getForegroundColor() const; + + /** + * Sets the background color. + * + * @param color The background Color. + * @see setBackgroundColor + * @since 0.1.0 + */ + void setBackgroundColor(const Color& color); + + /** + * Gets the background color. + * + * @see setBackgroundColor + * @since 0.1.0 + */ + const Color& getBackgroundColor() const; + + /** + * Sets the selection color. + * + * @param color The selection color. + * @see getSelectionColor + * @since 0.6.0 + */ + void setSelectionColor(const Color& color); + + /** + * Gets the selection color. + * + * @return The selection color. + * @see setSelectionColor + * @since 0.6.0 + */ + 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 focus handler 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 focus handler to use. + * @see _getFocusHandler + * @since 0.1.0 + */ + virtual void _setFocusHandler(FocusHandler* focusHandler); + + /** + * Gets the focus handler used. + * + * WARNING: This function is used internally and should not + * be called or overloaded unless you know what you + * are doing. + * + * @return The focus handler used. + * @see _setFocusHandler + * @since 0.1.0 + */ + virtual FocusHandler* _getFocusHandler(); + + /** + * Adds an action listener to the widget. When an action event + * is fired by the widget the action listeners of the widget + * will get notified. + * + * @param actionListener The action listener to add. + * @see removeActionListener + * @since 0.1.0 + */ + void addActionListener(ActionListener* actionListener); + + /** + * Removes an added action listener from the widget. + * + * @param actionListener The action listener to remove. + * @see addActionListener + * @since 0.1.0 + */ + void removeActionListener(ActionListener* actionListener); + + /** + * Adds a death listener to the widget. When a death event is + * fired by the widget the death listeners of the widget will + * get notified. + * + * @param deathListener The death listener to add. + * @see removeDeathListener + * @since 0.1.0 + */ + void addDeathListener(DeathListener* deathListener); + + /** + * Removes an added death listener from the widget. + * + * @param deathListener The death listener to remove. + * @see addDeathListener + * @since 0.1.0 + */ + void removeDeathListener(DeathListener* deathListener); + + /** + * Adds a mouse listener to the widget. When a mouse event is + * fired by the widget the mouse listeners of the widget will + * get notified. + * + * @param mouseListener The mouse listener to add. + * @see removeMouseListener + * @since 0.1.0 + */ + void addMouseListener(MouseListener* mouseListener); + + /** + * Removes an added mouse listener from the widget. + * + * @param mouseListener The mouse listener to remove. + * @see addMouseListener + * @since 0.1.0 + */ + void removeMouseListener(MouseListener* mouseListener); + + /** + * Adds a key listener to the widget. When a key event is + * fired by the widget the key listeners of the widget will + * get notified. + * + * @param keyListener The key listener to add. + * @see removeKeyListener + * @since 0.1.0 + */ + void addKeyListener(KeyListener* keyListener); + + /** + * Removes an added key listener from the widget. + * + * @param keyListener The key listener to remove. + * @see addKeyListener + * @since 0.1.0 + */ + void removeKeyListener(KeyListener* keyListener); + + /** + * Adds a focus listener to the widget. When a focus event is + * fired by the widget the key listeners of the widget will + * get notified. + * + * @param focusListener The focus listener to add. + * @see removeFocusListener + * @since 0.7.0 + */ + void addFocusListener(FocusListener* focusListener); + + /** + * Removes an added focus listener from the widget. + * + * @param focusListener The focus listener to remove. + * @see addFocusListener + * @since 0.7.0 + */ + void removeFocusListener(FocusListener* focusListener); + + /** + * Adds a widget listener to the widget. When a widget event is + * fired by the widget the key listeners of the widget will + * get notified. + * + * @param widgetListener The widget listener to add. + * @see removeWidgetListener + * @since 0.8.0 + */ + void addWidgetListener(WidgetListener* widgetListener); + + /** + * Removes an added widget listener from the widget. + * + * @param widgetListener The widget listener to remove. + * @see addWidgetListener + * @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. + * @see getActionEventId + * @since 0.6.0 + */ + void setActionEventId(const std::string& actionEventId); + + /** + * Gets the action event identifier of the widget. + * + * @return The action event identifier of the widget. + * @see setActionEventId + * @since 0.6.0 + */ + const std::string& getActionEventId() const; + + /** + * Gets the absolute position on the screen for the widget. + * + * @param x The absolute x coordinate will be stored in this parameter. + * @param y The absolute y coordinate will be stored in this parameter. + * @since 0.1.0 + */ + 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 of the widget. + * @see getParent + * @since 0.1.0 + */ + virtual void _setParent(Widget* parent); + + /** + * Gets the font set for the widget. If no font has been set, + * the global font will be returned. If no global font has been set, + * the default font will be returend. + * + * @return The font set for the widget. + * @see setFont, setGlobalFont + * @since 0.1.0 + */ + Font *getFont() const; + + /** + * Sets the global font to be used by default for all widgets. + * + * @param font The global font. + * @see getGlobalFont + * @since 0.1.0 + */ + static void setGlobalFont(Font* font); + + /** + * Sets the font for the widget. If NULL is passed, the global font + * will be used. + * + * @param font The font to set for the widget. + * @see getFont + * @since 0.1.0 + */ + void setFont(Font* font); + + /** + * Called when the font has changed. If the change is global, + * this function will only be called if the widget doesn't have a + * font already set. + * + * @since 0.1.0 + */ + virtual void fontChanged() { } + + /** + * Checks if a widget exists or not, that is if it still exists + * an instance of the object. + * + * @param widget The widget to check. + * @return True if an instance of the widget exists, false otherwise. + * @since 0.1.0 + */ + static bool widgetExists(const Widget* widget); + + /** + * Checks 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 focus handler will skip this widget and focus the next + * in its focus order. + * + * @return True if tab in is enabled, false otherwise. + * @see setTabInEnabled + * @since 0.1.0 + */ + bool isTabInEnabled() const; + + /** + * Sets tab in enabled, or not. 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, false otherwise. + * @see isTabInEnabled + * @since 0.1.0 + */ + 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, false otherwise. + * @see setTabOutEnabled + * @since 0.1.0 + */ + 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, false otherwise. + * @see isTabOutEnabled + * @since 0.1.0 + */ + 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. + * @see releaseModalFocus, isModalFocused + * @since 0.4.0 + */ + 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. + * @see releaseModalMouseInputFocus, isModalMouseInputFocused + * @since 0.6.0 + */ + virtual void requestModalMouseInputFocus(); + + /** + * Releases modal focus. Modal focus will only be released if the + * widget has modal focus. + * + * @see requestModalFocus, isModalFocused + * @since 0.4.0 + */ + virtual void releaseModalFocus(); + + /** + * Releases modal mouse input focus. Modal mouse input focus will only + * be released if the widget has modal mouse input focus. + * + * @see requestModalMouseInputFocus, isModalMouseInputFocused + * @since 0.6.0 + */ + virtual void releaseModalMouseInputFocus(); + + /** + * Checks if the widget or it's parent has modal focus. + * + * @return True if the widget has modal focus, false otherwise. + * @see requestModalFocus, releaseModalFocus + * @since 0.8.0 + */ + virtual bool isModalFocused() const; + + /** + * Checks if the widget or it's parent has modal mouse input focus. + * + * @return True if the widget has modal mouse input focus, false + * otherwise. + * @see requestModalMouseInputFocus, releaseModalMouseInputFocus + * @since 0.8.0 + */ + virtual bool isModalMouseInputFocused() 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 of the widget to get. + * @param y The y coordinate of the widget to get. + * @return The widget at the specified coodinate, NULL + * if no widget is found. + * @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 area of the widget occupied by the widget's children. + * By default this method returns an empty rectangle as not all + * widgets are containers. If you want to make a container this + * method should return the area where the children resides. This + * method is used when drawing children of a widget when computing + * clip rectangles for the children. + * + * An example of a widget that overloads this method is ScrollArea. + * A ScrollArea has a view of its contant and that view is the + * children area. The size of a ScrollArea's children area might + * vary depending on if the scroll bars of the ScrollArea is shown + * or not. + * + * @return The area of the widget occupied by the widget's children. + * @see BasicContainer + * @see BasicContainer::getChildrenArea + * @see BasicContainer::drawChildren + * @since 0.1.0 + */ + virtual Rectangle getChildrenArea(); + + /** + * Gets the internal focus handler used. + * + * @return the internalFocusHandler used. If no internal focus handler + * is used, NULL will be returned. + * @see setInternalFocusHandler + * @since 0.1.0 + */ + virtual FocusHandler* _getInternalFocusHandler(); + + /** + * Sets the internal focus handler. An internal focus handler is + * needed if both a widget in the widget and the widget itself + * should be foucsed at the same time. + * + * @param focusHandler The internal focus handler to be used. + * @see getInternalFocusHandler + * @since 0.1.0 + */ + void setInternalFocusHandler(FocusHandler* internalFocusHandler); + + /** + * 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 to the top. + * @see moveToBottom + * @since 0.1.0 + */ + virtual void moveToTop(Widget* widget _UNUSED_) { }; + + /** + * 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 to the bottom. + * @see moveToTop + * @since 0.1.0 + */ + virtual void moveToBottom(Widget* widget _UNUSED_) { }; + + /** + * Focuses the next widget in the widget. + * + * @see moveToBottom + * @since 0.1.0 + */ + virtual void focusNext() { }; + + /** + * Focuses the previous widget in the widget. + * + * @see moveToBottom + * @since 0.1.0 + */ + 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. + * @since 0.1.0 + */ + virtual void showWidgetPart(Widget* widget _UNUSED_, + Rectangle area _UNUSED_) + { }; + + /** + * 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 getId, BasicContainer::findWidgetById + * @since 0.8.0 + */ + 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 setId, BasicContainer::findWidgetById + * @since 0.8.0 + */ + const std::string& getId(); + + /** + * Shows a certain part of a widget in the widget's parent. + * Used when widgets want a specific part to be visible in + * its parent. An example is a TextArea that wants a specific + * part of its text to be visible when a TextArea is a child + * of a ScrollArea. + * + * @param rectangle The rectangle to be shown. + * @since 0.8.0 + */ + virtual void showPart(Rectangle rectangle); + + protected: + /** + * Distributes an action event to all action listeners + * of the widget. + * + * @since 0.8.0 + */ + void distributeActionEvent(); + + /** + * Distributes resized events to all of the widget's listeners. + * + * @since 0.8.0 + */ + void distributeResizedEvent(); + + /** + * Distributes moved events to all of the widget's listeners. + * + * @since 0.8.0 + */ + 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(); + + /** + * Typdef. + */ + typedef std::list MouseListenerList; + + /** + * Typdef. + */ + typedef MouseListenerList::iterator MouseListenerIterator; + + /** + * Holds the mouse listeners of the widget. + */ + MouseListenerList mMouseListeners; + + /** + * Typdef. + */ + typedef std::list KeyListenerList; + + /** + * Holds the key listeners of the widget. + */ + KeyListenerList mKeyListeners; + + /** + * Typdef. + */ + typedef KeyListenerList::iterator KeyListenerIterator; + + /** + * Typdef. + */ + typedef std::list ActionListenerList; + + /** + * Holds the action listeners of the widget. + */ + ActionListenerList mActionListeners; + + /** + * Typdef. + */ + typedef ActionListenerList::iterator ActionListenerIterator; + + /** + * Typdef. + */ + typedef std::list DeathListenerList; + + /** + * Holds the death listeners of the widget. + */ + DeathListenerList mDeathListeners; + + /** + * Typdef. + */ + typedef DeathListenerList::iterator DeathListenerIterator; + + /** + * Typdef. + */ + typedef std::list FocusListenerList; + + /** + * Holds the focus listeners of the widget. + */ + FocusListenerList mFocusListeners; + + /** + * Typdef. + */ + typedef FocusListenerList::iterator FocusListenerIterator; + + typedef std::list WidgetListenerList; + + /** + * Holds the widget listeners of the widget. + */ + WidgetListenerList mWidgetListeners; + + /** + * Typdef. + */ + typedef WidgetListenerList::iterator WidgetListenerIterator; + + /** + * Holds the foreground color of the widget. + */ + Color mForegroundColor; + + /** + * Holds the background color of the widget. + */ + Color mBackgroundColor; + + /** + * Holds the base color of the widget. + */ + Color mBaseColor; + + /** + * Holds the selection color of the widget. + */ + Color mSelectionColor; + + /** + * Holds the focus handler used by the widget. + */ + FocusHandler* mFocusHandler; + + /** + * Holds the focus handler used by the widget. NULL + * if no internal focus handler is used. + */ + FocusHandler* mInternalFocusHandler; + + /** + * Holds the parent of the widget. NULL if the widget + * has no parent. + */ + Widget* mParent; + + /** + * Holds the dimension of the widget. + */ + Rectangle mDimension; + + /** + * Holds the frame size of the widget. + */ + unsigned int mFrameSize; + + /** + * Holds the action event of the widget. + */ + std::string mActionEventId; + + /** + * True if the widget focusable, false otherwise. + */ + bool mFocusable; + + /** + * True if the widget visible, false otherwise. + */ + bool mVisible; + + /** + * True if the widget has tab in enabled, false otherwise. + */ + bool mTabIn; + + /** + * True if the widget has tab in enabled, false otherwise. + */ + bool mTabOut; + + /** + * True if the widget is enabled, false otherwise. + */ + bool mEnabled; + + /** + * Holds the id of the widget. + */ + std::string mId; + + /** + * Holds the font used by the widget. + */ + Font* mCurrentFont; + + /** + * Holds the default font used by the widget. + */ + static DefaultFont mDefaultFont; + + /** + * Holds the global font used by the widget. + */ + static Font* mGlobalFont; + + /** + * Holds a list of all instances of widgets. + */ + static std::list mWidgets; + }; +} + +#endif // end GCN_WIDGET_HPP diff --git a/src/guichan/include/guichan/widgetlistener.hpp b/src/guichan/include/guichan/widgetlistener.hpp new file mode 100644 index 000000000..eb1f838ec --- /dev/null +++ b/src/guichan/include/guichan/widgetlistener.hpp @@ -0,0 +1,124 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_WIDGETLISTENER_HPP +#define GCN_WIDGETLISTENER_HPP + +#include + +#include "guichan/event.hpp" +#include "guichan/platform.hpp" + +#ifdef __GNUC__ +#define _UNUSED_ __attribute__ ((unused)) +#else +#define _UNUSED_ +#endif + +namespace gcn +{ + /** + * Interface for listening for events from widgets. When a widget's size, + * location or visibility changes, the relevant method of the listener is + * invoked. + * + * @see Widget::addWidgetListener, Widget::removeWidgetListener + * @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 _UNUSED_) { } + + /** + * Invoked when a widget is moved. + * + * @param event Describes the event. + * @since 0.8.0 + */ + virtual void widgetMoved(const Event& event _UNUSED_) { } + + /** + * 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 _UNUSED_) { } + + /** + * 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 _UNUSED_) { } + + protected: + /** + * Constructor. + * + * You should not be able to make an instance of WidgetListener, + * therefore its constructor is protected. + */ + WidgetListener() { } + + }; +} + +#endif // end GCN_WIDGETLISTENER_HPP diff --git a/src/guichan/include/guichan/widgets/button.hpp b/src/guichan/include/guichan/widgets/button.hpp new file mode 100644 index 000000000..05b961b1e --- /dev/null +++ b/src/guichan/include/guichan/widgets/button.hpp @@ -0,0 +1,220 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_BUTTON_HPP +#define GCN_BUTTON_HPP + +#include + +#include "guichan/focuslistener.hpp" +#include "guichan/graphics.hpp" +#include "guichan/keylistener.hpp" +#include "guichan/mouseevent.hpp" +#include "guichan/mouselistener.hpp" +#include "guichan/platform.hpp" +#include "guichan/widget.hpp" + +#ifdef __GNUC__ +#define _UNUSED_ __attribute__ ((unused)) +#else +#define _UNUSED_ +#endif + +namespace gcn +{ + /** + * An implementation of a regular clickable button. A button is capable of + * displaying a caption. + * + * If a button is clicked an action event will be sent to all action listener's + * of the button. + * + * @see ImageButton + */ + class GCN_CORE_DECLSPEC Button : public Widget, + public MouseListener, + public KeyListener, + public FocusListener + { + public: + /** + * Constructor. + */ + Button(); + + /** + * Constructor. The button will be automatically resized + * to fit the caption. + * + * @param caption The caption of the button. + */ + Button(const std::string& caption); + + /** + * Sets the caption of the button. It's advisable to call + * adjustSize after setting of the caption to adjust the + * button's size to fit the caption. + * + * @param caption The caption of the button. + * @see getCaption, adjustSize + */ + void setCaption(const std::string& caption); + + /** + * Gets the caption of the button. + * + * @return The caption of the button. + */ + const std::string& getCaption() const; + + /** + * Sets the alignment of the caption. The alignment is relative + * to the center of the button. + * + * @param alignment The alignment of the caption. + * @see getAlignment, Graphics + */ + void setAlignment(Graphics::Alignment alignment); + + /** + * Gets the alignment of the caption. + * + * @return The alignment of the caption. + * @see setAlignment, Graphics + */ + Graphics::Alignment getAlignment() const; + + /** + * Sets the spacing between the border of the button and its caption. + * + * @param spacing The default value for spacing is 4 and can be changed + * using this method. + * @see getSpacing + */ + void setSpacing(unsigned int spacing); + + /** + * Gets the spacing between the border of the button and its caption. + * + * @return spacing. + * @see setSpacing + */ + unsigned int getSpacing() const; + + /** + * Adjusts the button's size to fit the caption. + */ + void adjustSize(); + + + //Inherited from Widget + + virtual void draw(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: + /** + * Checks if the button is pressed. Convenient method to use + * when overloading the draw method of the button. + * + * @return True if the button is pressed, false otherwise. + */ + bool isPressed() const; + + /** + * Holds the caption of the button. + */ + std::string mCaption; + + /** + * True if the mouse is ontop of the button, false otherwise. + */ + bool mHasMouse; + + /** + * True if a key has been pressed, false otherwise. + */ + bool mKeyPressed; + + /** + * True if a mouse has been pressed, false otherwise. + */ + bool mMousePressed; + + /** + * Holds the alignment of the caption. + */ + Graphics::Alignment mAlignment; + + /** + * Holds the spacing between the border and the caption. + */ + unsigned int mSpacing; + }; +} + +#endif // end GCN_BUTTON_HPP diff --git a/src/guichan/include/guichan/widgets/checkbox.hpp b/src/guichan/include/guichan/widgets/checkbox.hpp new file mode 100644 index 000000000..ad43e2896 --- /dev/null +++ b/src/guichan/include/guichan/widgets/checkbox.hpp @@ -0,0 +1,173 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_CHECKBOX_HPP +#define GCN_CHECKBOX_HPP + +#include + +#include "guichan/keylistener.hpp" +#include "guichan/mouselistener.hpp" +#include "guichan/platform.hpp" +#include "guichan/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 the 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 or not. + * + * @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); + + + // 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/guichan/include/guichan/widgets/container.hpp b/src/guichan/include/guichan/widgets/container.hpp new file mode 100644 index 000000000..4946b1f74 --- /dev/null +++ b/src/guichan/include/guichan/widgets/container.hpp @@ -0,0 +1,162 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_CONTAINER_HPP +#define GCN_CONTAINER_HPP + +#include + +#include "guichan/basiccontainer.hpp" +#include "guichan/graphics.hpp" +#include "guichan/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 its background will be drawn, if it's not opaque + * its 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 its 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 specifies the widget's + * position 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 coordinate for the widget. + * @param y The y coordinate 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); + + protected: + /** + * True if the container is opaque, false otherwise. + */ + bool mOpaque; + }; +} + +#endif // end GCN_CONTAINER_HPP diff --git a/src/guichan/include/guichan/widgets/dropdown.hpp b/src/guichan/include/guichan/widgets/dropdown.hpp new file mode 100644 index 000000000..5853783e5 --- /dev/null +++ b/src/guichan/include/guichan/widgets/dropdown.hpp @@ -0,0 +1,325 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_DROPDOWN_HPP +#define GCN_DROPDOWN_HPP + +#include "guichan/actionlistener.hpp" +#include "guichan/basiccontainer.hpp" +#include "guichan/deathlistener.hpp" +#include "guichan/focushandler.hpp" +#include "guichan/focuslistener.hpp" +#include "guichan/keylistener.hpp" +#include "guichan/listmodel.hpp" +#include "guichan/mouselistener.hpp" +#include "guichan/platform.hpp" +#include "guichan/selectionlistener.hpp" +#include "guichan/widgets/listbox.hpp" +#include "guichan/widgets/scrollarea.hpp" + +#ifdef __GNUC__ +#define _UNUSED_ __attribute__ ((unused)) +#else +#define _UNUSED_ +#endif + +namespace gcn +{ + /** + * An implementation of a drop downable list from which an item can be + * selected. The drop down consists of an internal ScrollArea and an + * internal ListBox. The drop down also uses an internal FocusHandler to + * handle the focus of the internal ScollArea and the internal ListBox. The + * scroll area and the list box can be passed to the drop down if a custom + * scroll area and or a custom list box is preferable. + * + * To be able display a list the drop down uses a user provided list model. + * A list model can be any class that implements the ListModel interface. + * + * If an item is selected in the drop down a select event will be sent to + * all selection listeners of the drop down. If an item is selected by + * using a mouse click or by using the enter or space key an action event + * will be sent to all action listeners of the drop down. + */ + class GCN_CORE_DECLSPEC DropDown : + public ActionListener, + public BasicContainer, + public KeyListener, + public MouseListener, + public FocusListener, + public SelectionListener + { + public: + /** + * Contructor. + * + * @param listModel the ListModel to use. + * @param scrollArea the ScrollArea to use. + * @param listBox the listBox to use. + * @see ListModel, ScrollArea, ListBox. + */ + DropDown(ListModel *listModel = NULL, + ScrollArea *scrollArea = NULL, + ListBox *listBox = NULL); + + /** + * Destructor. + */ + virtual ~DropDown(); + + /** + * Gets the selected item as an index in the list model. + * + * @return the selected item as an index in the list model. + * @see setSelected + */ + int getSelected() const; + + /** + * Sets the selected item. The selected item is represented by + * an index from the list model. + * + * @param selected the selected item as an index from the list model. + * @see getSelected + */ + void setSelected(int selected); + + /** + * Sets the list model to use when displaying the list. + * + * @param listModel the list model to use. + * @see getListModel + */ + void setListModel(ListModel *listModel); + + /** + * Gets the list model used. + * + * @return the ListModel used. + * @see setListModel + */ + ListModel *getListModel(); + + /** + * Adjusts the height of the drop down to fit the height of the + * drop down's parent's height. It's used to not make the drop down + * draw itself outside of it's parent if folded down. + */ + void adjustHeight(); + + /** + * Adds a selection listener to the drop down. When the selection + * changes an event will be sent to all selection listeners of the + * drop down. + * + * If you delete your selection listener, be sure to also remove it + * using removeSelectionListener(). + * + * @param listener the selection listener to add. + * @since 0.8.0 + */ + void addSelectionListener(SelectionListener* listener); + + /** + * Removes a selection listener from the drop down. + * + * @param selectionListener the selection listener to remove. + * @since 0.8.0 + */ + void removeSelectionListener(SelectionListener* selectionListener); + + + // Inherited from Widget + + virtual void draw(Graphics* graphics); + + void setBaseColor(const Color& color); + + void setBackgroundColor(const Color& color); + + void setForegroundColor(const Color& color); + + void setFont(Font *font); + + void setSelectionColor(const Color& color); + + + // Inherited from BasicContainer + + virtual Rectangle getChildrenArea(); + + + // Inherited from FocusListener + + virtual void focusLost(const Event& event); + + + // Inherited from ActionListener + + virtual 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); + + virtual void mouseReleased(MouseEvent& mouseEvent); + + virtual void mouseWheelMovedUp(MouseEvent& mouseEvent); + + virtual void mouseWheelMovedDown(MouseEvent& mouseEvent); + + virtual void mouseDragged(MouseEvent& mouseEvent); + + + // Inherited from SelectionListener + + virtual void valueChanged(const SelectionEvent& event); + + protected: + /** + * Draws the button of the drop down. + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawButton(Graphics *graphics); + + /** + * Sets the drop down to be dropped down. + */ + virtual void dropDown(); + + /** + * Sets the drop down to be folded up. + */ + virtual void foldUp(); + + /** + * Distributes a value changed event to all selection listeners + * of the drop down. + * + * @since 0.8.0 + */ + void distributeValueChangedEvent(); + + /** + * True if the drop down is dropped down, false otherwise. + */ + bool mDroppedDown; + + /** + * True if the drop down has been pushed with the mouse, false + * otherwise. + */ + bool mPushed; + + /** + * Holds what the height is if the drop down is folded up. Used when + * checking if the list of the drop down was clicked or if the upper + * part of the drop down was clicked on a mouse click. + */ + int mFoldedUpHeight; + + /** + * The scroll area used. + */ + ScrollArea* mScrollArea; + + /** + * The list box used. + */ + ListBox* mListBox; + + /** + * The internal focus handler used to keep track of focus for the + * internal list box. + */ + FocusHandler mInternalFocusHandler; + + /** + * True if an internal scroll area is used, false if a scroll area + * has been passed to the drop down which the drop down should not + * deleted in it's destructor. + */ + bool mInternalScrollArea; + + /** + * True if an internal list box is used, false if a list box + * has been passed to the drop down which the drop down should not + * deleted in it's destructor. + */ + bool mInternalListBox; + + /** + * True if the drop down is dragged. + */ + bool mIsDragged; + + /** + * Typedef. + */ + typedef std::list SelectionListenerList; + + /** + * The selection listener's of the drop down. + */ + SelectionListenerList mSelectionListeners; + + /** + * Typedef. + */ + typedef SelectionListenerList::iterator SelectionListenerIterator; + }; +} + +#endif // end GCN_DROPDOWN_HPP diff --git a/src/guichan/include/guichan/widgets/icon.hpp b/src/guichan/include/guichan/widgets/icon.hpp new file mode 100644 index 000000000..f0f9ff566 --- /dev/null +++ b/src/guichan/include/guichan/widgets/icon.hpp @@ -0,0 +1,118 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_ICON_HPP +#define GCN_ICON_HPP + +#include "guichan/image.hpp" +#include "guichan/platform.hpp" +#include "guichan/widget.hpp" + +namespace gcn +{ + /** + * Implements an icon capable of displaying an image. + */ + class GCN_CORE_DECLSPEC Icon: public Widget + { + public: + /** + * Default constructor. + */ + Icon(); + + /** + * Constructor. + * + * @param filename The filename of the image to display. + */ + Icon(const std::string& filename); + + /** + * Constructor. + * + * @param image The image to display. + */ + Icon(const Image* image); + + /** + * Descructor. + */ + virtual ~Icon(); + + /** + * Sets the image to display. Existing image is freed automatically + * if it was loaded internally. + * + * @param image The image to display. + */ + void setImage(const Image* image); + + /** + * Gets the current image. + * + * @return The current image. + */ + const Image* getImage() const; + + + // Inherited from Widget + + virtual void draw(Graphics* graphics); + + protected: + /** + * The image to display. + */ + const Image* mImage; + + /** + * True if the image has been loaded internally, false otherwise. + * An image not loaded internally should not be deleted in the + * destructor. + */ + bool mInternalImage; + }; +} + +#endif // end GCN_ICON_HPP diff --git a/src/guichan/include/guichan/widgets/imagebutton.hpp b/src/guichan/include/guichan/widgets/imagebutton.hpp new file mode 100644 index 000000000..1ab285ce9 --- /dev/null +++ b/src/guichan/include/guichan/widgets/imagebutton.hpp @@ -0,0 +1,123 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_IMAGEBUTTON_HPP +#define GCN_IMAGEBUTTON_HPP + +#include "guichan/platform.hpp" +#include "guichan/widgets/button.hpp" + +namespace gcn +{ + class Image; + + /** + * An implementation of a regular clickable button. Unlike a normal button an image + * button is capable of displaying an image instead of a simple text caption. + * Whenever an image button is clicked an action event will be sent to the action + * listener's of the image button. + * + * @see Button + */ + class GCN_CORE_DECLSPEC ImageButton : public gcn::Button + { + public: + /** + * Default constructor. + */ + ImageButton(); + + /** + * Constructor. + * + * @param filename The filename of the image to display. + */ + ImageButton(const std::string& filename); + + /** + * Constructor. + * + * @param image The image to display. + */ + ImageButton(const Image* image); + + /** + * Destructor. + */ + virtual ~ImageButton(); + + /** + * Sets the image to display. Existing Image is freed automatically, + * if it was loaded internally. + * + * @param image The image to display. + */ + void setImage(const Image* image); + + /** + * Gets current image. + * + * @return The current image. + */ + const Image* getImage() const; + + + // Inherited from Widget + + void draw(gcn::Graphics* graphics); + + protected: + /** + * The image to display. + */ + const Image* mImage; + + /** + * True if the image has been loaded internally, false otherwise. + * An image not loaded internally should not be deleted in the + * destructor. + */ + bool mInternalImage; + }; +} +#endif diff --git a/src/guichan/include/guichan/widgets/label.hpp b/src/guichan/include/guichan/widgets/label.hpp new file mode 100644 index 000000000..4d6ea0006 --- /dev/null +++ b/src/guichan/include/guichan/widgets/label.hpp @@ -0,0 +1,133 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_LABEL_HPP +#define GCN_LABEL_HPP + +#include + +#include "guichan/graphics.hpp" +#include "guichan/platform.hpp" +#include "guichan/widget.hpp" + +namespace gcn +{ + /** + * Implementation of a label capable of displaying a caption. + */ + class GCN_CORE_DECLSPEC Label: public Widget + { + public: + /** + * Constructor. + */ + Label(); + + /** + * Constructor. The label will be automatically resized + * to fit the caption. + * + * @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 of the caption. The alignment is relative + * to the center of the label. + * + * @param alignemnt The alignment of the caption of the label. + * @see getAlignment, Graphics + */ + void setAlignment(Graphics::Alignment alignment); + + /** + * Gets the alignment of the caption. The alignment is relative to + * the center of the label. + * + * @return The alignment of caption of the label. + * @see setAlignmentm Graphics + */ + Graphics::Alignment getAlignment() const; + + /** + * Adjusts the label's size to fit the caption. + */ + void adjustSize(); + + + // Inherited from Widget + + virtual void draw(Graphics* graphics); + + protected: + /** + * Holds the caption of the label. + */ + std::string mCaption; + + /** + * Holds the alignment of the caption. + */ + Graphics::Alignment mAlignment; + }; +} + +#endif // end GCN_LABEL_HPP diff --git a/src/guichan/include/guichan/widgets/listbox.hpp b/src/guichan/include/guichan/widgets/listbox.hpp new file mode 100644 index 000000000..b99f84aaa --- /dev/null +++ b/src/guichan/include/guichan/widgets/listbox.hpp @@ -0,0 +1,253 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_LISTBOX_HPP +#define GCN_LISTBOX_HPP + +#include + +#include "guichan/keylistener.hpp" +#include "guichan/listmodel.hpp" +#include "guichan/mouselistener.hpp" +#include "guichan/platform.hpp" +#include "guichan/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. + * + * If you delete your selection listener, be sure to also remove it + * using removeSelectionListener(). + * + * @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); + + /** + * Gets the height of a row. Should be overridden if another row + * height than the font height is preferred. + * + * @return The height of a row. + * @since 0.8.0 + */ + virtual unsigned int getRowHeight() const; + + + // Inherited from Widget + + virtual void draw(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 selected item as an index in the list model. + */ + int mSelected; + + /** + * The list model to use. + */ + ListModel *mListModel; + + /** + * True if wrapping is enabled, false otherwise. + */ + bool mWrappingEnabled; + + /** + * 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/guichan/include/guichan/widgets/radiobutton.hpp b/src/guichan/include/guichan/widgets/radiobutton.hpp new file mode 100644 index 000000000..0fb5b4123 --- /dev/null +++ b/src/guichan/include/guichan/widgets/radiobutton.hpp @@ -0,0 +1,211 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_RADIOBUTTON_HPP +#define GCN_RADIOBUTTON_HPP + +#include +#include + +#include "guichan/keylistener.hpp" +#include "guichan/mouselistener.hpp" +#include "guichan/platform.hpp" +#include "guichan/widget.hpp" + +namespace gcn +{ + /** + * An 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. The radio button will be automatically resized + * to fit the caption. + * + * @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); + + + // 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/guichan/include/guichan/widgets/scrollarea.hpp b/src/guichan/include/guichan/widgets/scrollarea.hpp new file mode 100644 index 000000000..0b2ccad92 --- /dev/null +++ b/src/guichan/include/guichan/widgets/scrollarea.hpp @@ -0,0 +1,590 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_SCROLLAREA_HPP +#define GCN_SCROLLAREA_HPP + +#include + +#include "guichan/basiccontainer.hpp" +#include "guichan/mouselistener.hpp" +#include "guichan/platform.hpp" + +namespace gcn +{ + /** + * Implementation if a scrollable area used to view widgets larger than the scroll area. + * A scroll area can be customized to always show scroll bars or to show them only when + * necessary. + */ + class GCN_CORE_DECLSPEC ScrollArea: + public BasicContainer, + public MouseListener + { + public: + + /** + * 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 ScrollPolicy + { + SHOW_ALWAYS = 0, + SHOW_NEVER, + SHOW_AUTO + }; + + /** + * Constructor. + */ + ScrollArea(); + + /** + * Constructor. + * + * @param content The content of the scroll area. + */ + ScrollArea(Widget *content); + + /** + * Constructor. + * + * @param content The content of the scroll area. + * @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, + ScrollPolicy hPolicy, + ScrollPolicy vPolicy); + + /** + * Destructor. + */ + virtual ~ScrollArea(); + + /** + * Sets the content. + * + * @param widget The content of the scroll area. + */ + void setContent(Widget* widget); + + /** + * Gets the content. + * + * @return The content of the scroll area. + */ + Widget* getContent(); + + /** + * Sets the horizontal scrollbar policy. See enum with policies. + * + * @param hPolicy The policy for the horizontal scrollbar. + * @see getHorizontalScrollPolicy + */ + void setHorizontalScrollPolicy(ScrollPolicy hPolicy); + + /** + * Gets the horizontal scrollbar policy. See enum with policies. + * + * @return The policy for the horizontal scrollbar policy. + * @see setHorizontalScrollPolicy, setScrollPolicy + */ + ScrollPolicy getHorizontalScrollPolicy() const; + + /** + * Sets the vertical scrollbar policy. See enum with policies. + * + * @param vPolicy The policy for the vertical scrollbar. + * @see getVerticalScrollPolicy + */ + void setVerticalScrollPolicy(ScrollPolicy vPolicy); + + /** + * Gets the vertical scrollbar policy. See enum with policies. + * + * @return The policy for the vertical scrollbar. + * @see setVerticalScrollPolicy, setScrollPolicy + */ + ScrollPolicy getVerticalScrollPolicy() const; + + /** + * Sets the horizontal and vertical scrollbar policy. + * + * @param hPolicy The policy for the horizontal scrollbar. + * @param vPolicy The policy for the vertical scrollbar. + * @see getVerticalScrollPolicy, getHorizontalScrollPolicy + */ + void setScrollPolicy(ScrollPolicy hPolicy, ScrollPolicy vPolicy); + + /** + * Sets the amount to scroll vertically. + * + * @param vScroll The amount to scroll. + * @see getVerticalScrollAmount + */ + void setVerticalScrollAmount(int vScroll); + + /** + * Gets the amount that is scrolled vertically. + * + * @return The scroll amount on vertical scroll. + * @see setVerticalScrollAmount, setScrollAmount + */ + int getVerticalScrollAmount() const; + + /** + * Sets the amount to scroll horizontally. + * + * @param hScroll The amount to scroll. + * @see getHorizontalScrollAmount + */ + void setHorizontalScrollAmount(int hScroll); + + /** + * Gets the amount that is scrolled horizontally. + * + * @return The scroll amount on horizontal scroll. + * @see setHorizontalScrollAmount, setScrollAmount + */ + 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. + * @see getHorizontalScrollAmount, getVerticalScrollAmount + */ + 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 of the scroll bars. + * + * @param width The width of the scroll bars. + * @see getScrollbarWidth + */ + void setScrollbarWidth(int width); + + /** + * Gets the width of the scroll bars. + * + * @return the width of the ScrollBar. + * @see setScrollbarWidth + */ + int getScrollbarWidth() const; + + /** + * Sets the amount to scroll in pixels when the left scroll button is + * pushed. + * + * @param amount The amount to scroll in pixels. + * @see getLeftButtonScrollAmount + */ + void setLeftButtonScrollAmount(int amount); + + /** + * Sets the amount to scroll in pixels when the right scroll button is + * pushed. + * + * @param amount The amount to scroll in pixels. + * @see getRightButtonScrollAmount + */ + void setRightButtonScrollAmount(int amount); + + /** + * Sets the amount to scroll in pixels when the up scroll button is + * pushed. + * + * @param amount The amount to scroll in pixels. + * @see getUpButtonScrollAmount + */ + void setUpButtonScrollAmount(int amount); + + /** + * Sets the amount to scroll in pixels when the down scroll button is + * pushed. + * + * @param amount The amount to scroll in pixels. + * @see getDownButtonScrollAmount + */ + void setDownButtonScrollAmount(int amount); + + /** + * Gets the amount to scroll in pixels when the left scroll button is + * pushed. + * + * @return The amount to scroll in pixels. + * @see setLeftButtonScrollAmount + */ + int getLeftButtonScrollAmount() const; + + /** + * Gets the amount to scroll in pixels when the right scroll button is + * pushed. + * + * @return The amount to scroll in pixels. + * @see setRightButtonScrollAmount + */ + int getRightButtonScrollAmount() const; + + /** + * Gets the amount to scroll in pixels when the up scroll button is + * pushed. + * + * @return The amount to scroll in pixels. + * @see setUpButtonScrollAmount + */ + int getUpButtonScrollAmount() const; + + /** + * Gets the amount to scroll in pixels when the down scroll button is + * pushed. + * + * @return The amount to scroll in pixels. + * @see setDownButtonScrollAmount + */ + int getDownButtonScrollAmount() const; + + /** + * Sets the scroll area to be opaque, that is sets the scoll area + * to display its background. + * + * @param opaque True if the scoll area should be opaque, false otherwise. + */ + void setOpaque(bool opaque); + + /** + * Checks if the scroll area is opaque, that is if the scroll area + * displays its background. + * + * @return True if the scroll area is opaque, false otherwise. + */ + bool isOpaque() 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 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); + + protected: + /** + * Draws the background of the scroll area, that is + * 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 scroll bar. + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawVBar(Graphics* graphics); + + /** + * Draws the horizontal scroll bar. + * + * @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 scroll bars. + */ + 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(); + + /** + * Holds the vertical scroll amount. + */ + int mVScroll; + + /** + * Holds the horizontal scroll amount. + */ + int mHScroll; + + /** + * Holds the width of the scroll bars. + */ + int mScrollbarWidth; + + /** + * Holds the horizontal scroll bar policy. + */ + ScrollPolicy mHPolicy; + + /** + * Holds the vertical scroll bar policy. + */ + ScrollPolicy mVPolicy; + + /** + * True if the vertical scroll bar is visible, false otherwise. + */ + bool mVBarVisible; + + /** + * True if the horizontal scroll bar is visible, false otherwise. + */ + bool mHBarVisible; + + /** + * True if the up button is pressed, false otherwise. + */ + bool mUpButtonPressed; + + /** + * True if the down button is pressed, false otherwise. + */ + bool mDownButtonPressed; + + /** + * True if the left button is pressed, false otherwise. + */ + bool mLeftButtonPressed; + + /** + * True if the right button is pressed, false otherwise. + */ + bool mRightButtonPressed; + + /** + * Holds the up button scroll amount. + */ + int mUpButtonScrollAmount; + + /** + * Holds the down button scroll amount. + */ + int mDownButtonScrollAmount; + + /** + * Holds the left button scroll amount. + */ + int mLeftButtonScrollAmount; + + /** + * Holds the right button scroll amount. + */ + int mRightButtonScrollAmount; + + /** + * True if the vertical marked is dragged. + */ + bool mIsVerticalMarkerDragged; + + /** + * True if the horizontal marked is dragged. + */ + bool mIsHorizontalMarkerDragged; + + /** + * Holds the horizontal markers drag offset. + */ + int mHorizontalMarkerDragOffset; + + /** + * Holds the vertical markers drag offset. + */ + int mVerticalMarkerDragOffset; + + /** + * True if the scroll area should be opaque (that is + * display its background), false otherwise. + */ + bool mOpaque; + }; +} + +#endif // end GCN_SCROLLAREA_HPP diff --git a/src/guichan/include/guichan/widgets/slider.hpp b/src/guichan/include/guichan/widgets/slider.hpp new file mode 100644 index 000000000..eddf02c50 --- /dev/null +++ b/src/guichan/include/guichan/widgets/slider.hpp @@ -0,0 +1,300 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_SLIDER_HPP +#define GCN_SLIDER_HPP + +#include "guichan/keylistener.hpp" +#include "guichan/mouselistener.hpp" +#include "guichan/platform.hpp" +#include "guichan/widget.hpp" + +namespace gcn +{ + /** + * An implementation of a slider where a user can select different values by + * sliding between a start value and an end value of a scale. + * + * If the selected value is changed an action event will be sent to all + * action listeners of the slider. + */ + class GCN_CORE_DECLSPEC Slider : + public Widget, + public MouseListener, + public KeyListener + { + public: + + /** + * Draw orientations for the slider. A slider can be drawn vertically or + * horizontally. + */ + enum Orientation + { + HORIZONTAL = 0, + VERTICAL + }; + + /** + * Constructor. The default start value of the slider scale is zero. + * + * @param scaleEnd The end value of the slider scale. + */ + Slider(double scaleEnd = 1.0); + + /** + * Constructor. + * + * @param scaleStart The start value of the slider scale. + * @param scaleEnd The end value of the slider scale. + */ + Slider(double scaleStart, double scaleEnd); + + /** + * Destructor. + */ + virtual ~Slider() { } + + /** + * Sets the scale of the slider. + * + * @param scaleStart The start value of the scale. + * @param scaleEnd tThe end of value the scale. + * @see getScaleStart, getScaleEnd + */ + void setScale(double scaleStart, double scaleEnd); + + /** + * Gets the start value of the scale. + * + * @return The start value of the scale. + * @see setScaleStart, setScale + */ + double getScaleStart() const; + + /** + * Sets the start value of the scale. + * + * @param scaleStart The start value of the scale. + * @see getScaleStart + */ + void setScaleStart(double scaleStart); + + /** + * Gets the end value of the scale. + * + * @return The end value of the scale. + * @see setScaleEnd, setScale + */ + double getScaleEnd() const; + + /** + * Sets the end value of the scale. + * + * @param scaleEnd The end value of the scale. + * @see getScaleEnd + */ + void setScaleEnd(double scaleEnd); + + /** + * Gets the current selected value. + * + * @return The current selected value. + * @see setValue + */ + double getValue() const; + + /** + * Sets the current selected value. + * + * @param value The current selected value. + * @see getValue + */ + void setValue(double value); + + /** + * Sets the length of the marker. + * + * @param length The length for the marker. + * @see getMarkerLength + */ + void setMarkerLength(int length); + + /** + * Gets the length of the marker. + * + * @return The length of the marker. + * @see setMarkerLength + */ + int getMarkerLength() const; + + /** + * Sets the orientation of the slider. A slider can be drawn vertically + * or horizontally. + * + * @param orientation The orientation of the slider. + * @see getOrientation + */ + void setOrientation(Orientation orientation); + + /** + * Gets the orientation of the slider. A slider can be drawn vertically + * or horizontally. + * + * @return The orientation of the slider. + * @see setOrientation + */ + Orientation getOrientation() const; + + /** + * Sets the step length. The step length is used when the keys LEFT + * and RIGHT are pressed to step in the scale. + * + * @param length The step length. + * @see getStepLength + */ + void setStepLength(double length); + + /** + * Gets the step length. The step length is used when the keys LEFT + * and RIGHT are pressed to step in the scale. + * + * @return the step length. + * @see setStepLength + */ + double getStepLength() const; + + + // Inherited from Widget + + virtual void draw(Graphics* graphics); + + + // Inherited from MouseListener. + + virtual void mousePressed(MouseEvent& mouseEvent); + + virtual void mouseDragged(MouseEvent& mouseEvent); + + virtual void mouseWheelMovedUp(MouseEvent& mouseEvent); + + virtual void mouseWheelMovedDown(MouseEvent& mouseEvent); + + + // Inherited from KeyListener + + virtual void keyPressed(KeyEvent& keyEvent); + + protected: + /** + * Draws the marker. + * + * @param graphics A graphics object to draw with. + */ + virtual void drawMarker(gcn::Graphics* graphics); + + /** + * Converts a marker position to a value in the scale. + * + * @param position The position to convert. + * @return A scale value corresponding to the position. + * @see valueToMarkerPosition + */ + virtual double markerPositionToValue(int position) const; + + /** + * Converts a value to a marker position. + * + * @param value The value to convert. + * @return A marker position corresponding to the value. + * @see markerPositionToValue + */ + virtual int valueToMarkerPosition(double value) const; + + /** + * Gets the marker position of the current selected value. + * + * @return The marker position of the current selected value. + */ + virtual int getMarkerPosition() const; + + /** + * True if the slider is dragged, false otherwise. + */ + bool mDragged; + + /** + * Holds the current selected value. + */ + double mValue; + + /** + * Holds the step length. The step length is used when the keys LEFT + * and RIGHT are pressed to step in the scale. + */ + double mStepLength; + + /** + * Holds the length of the marker. + */ + int mMarkerLength; + + /** + * Holds the start value of the scale. + */ + double mScaleStart; + + /** + * Holds the end value of the scale. + */ + double mScaleEnd; + + /** + * Holds the orientation of the slider. A slider can be drawn + * vertically or horizontally. + */ + Orientation mOrientation; + }; +} + +#endif // end GCN_SLIDER_HPP diff --git a/src/guichan/include/guichan/widgets/tab.hpp b/src/guichan/include/guichan/widgets/tab.hpp new file mode 100644 index 000000000..d123bac15 --- /dev/null +++ b/src/guichan/include/guichan/widgets/tab.hpp @@ -0,0 +1,157 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_TAB_HPP +#define GCN_TAB_HPP + +#include +#include + +#include "guichan/basiccontainer.hpp" +#include "guichan/mouselistener.hpp" +#include "guichan/platform.hpp" + +#ifdef __GNUC__ +#define _UNUSED_ __attribute__ ((unused)) +#else +#define _UNUSED_ +#endif + +namespace gcn +{ + class Label; + class TabbedArea; + + /** + * An implementation of a simple tab to be used in a tabbed area. + * + * @see TabbedArea + * @since 0.8.0 + */ + class GCN_CORE_DECLSPEC Tab: + public BasicContainer, + public MouseListener + { + public: + + /** + * Constructor. + */ + Tab(); + + /** + * Destructor. + */ + virtual ~Tab(); + + /** + * Adjusts the size of the tab to fit the caption. If this tab was + * added to a TabbedArea, it will also adjust the tab positions. + */ + 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. + * @see getTabbedArea + */ + void setTabbedArea(TabbedArea* tabbedArea); + + /** + * Gets the tabbed are the tab is a part of. + * + * @return The tabbed are the tab is a part of. + * @see setTabbedArea + */ + TabbedArea* getTabbedArea(); + + /** + * Sets the caption of the tab. It's advisable to call + * adjustSize after setting the caption to make the tab + * fit the caption. + * + * @param caption The caption of the tab. + * @see getCaption, adjustSize + */ + void setCaption(const std::string& caption); + + /** + * Gets the caption of the tab. + * + * @return The caption of the tab. + * @see setCaption + */ + const std::string& getCaption() const; + + + // Inherited from Widget + + virtual void draw(Graphics *graphics); + + + // Inherited from MouseListener + + virtual void mouseEntered(MouseEvent& mouseEvent); + + virtual void mouseExited(MouseEvent& mouseEvent); + + protected: + /** + * Holds the label of the tab. + */ + Label* mLabel; + + /** + * True if the tab has the mouse, false otherwise. + */ + bool mHasMouse; + + /** + * Holds the tabbed area the tab is a part of. + */ + TabbedArea* mTabbedArea; + }; +} + +#endif // end GCN_TABBEDAREA_HPP diff --git a/src/guichan/include/guichan/widgets/tabbedarea.hpp b/src/guichan/include/guichan/widgets/tabbedarea.hpp new file mode 100644 index 000000000..843bbde81 --- /dev/null +++ b/src/guichan/include/guichan/widgets/tabbedarea.hpp @@ -0,0 +1,280 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_TABBEDAREA_HPP +#define GCN_TABBEDAREA_HPP + +#include +#include +#include + +#include "guichan/actionlistener.hpp" +#include "guichan/basiccontainer.hpp" +#include "guichan/keylistener.hpp" +#include "guichan/mouselistener.hpp" +#include "guichan/platform.hpp" + +namespace gcn +{ + class Container; + class Tab; + + /** + * An implementation of a tabbed area where a user can display a widget by + * selecting a tab. + * + * @since 0.8.0 + */ + class GCN_CORE_DECLSPEC TabbedArea: + public ActionListener, + public BasicContainer, + public KeyListener, + public MouseListener + { + friend class Tab; + + public: + /** + * Constructor. + */ + TabbedArea(); + + /** + * Destructor. + */ + virtual ~TabbedArea(); + + /** + * Sets the tabbed area to be opaque or not. If the tabbed area is + * opaque its background will be drawn, if it's not opaque its + * background will not be drawn. By default, a tabbed area is not + * opaque. + * + * The tabbed area's background is normally only visible behind the + * tabs, since the container holding the tab contents is opaque by + * default. + * + * @param opaque True if the tabbed area should be opaque, false + * otherwise. + * @see isOpaque + */ + void setOpaque(bool opaque); + + /** + * Checks if the tabbed area is opaque or not. + * + * @return true if the tabbed area is opaque, false otherwise. + * @see setOpaque + */ + bool isOpaque() const; + + /** + * Adds a tab to the tabbed area. The newly created tab will be + * automatically deleted by the tabbed area when it is removed. + * + * @param caption The caption of the tab to add. + * @param widget The widget to view when the tab is selected. + * @see removeTab, removeTabWithIndex + */ + virtual void addTab(const std::string& caption, Widget* widget); + + /** + * Adds a tab to the tabbed area. The tab will not be deleted by the + * tabbed area when it is removed. + * + * @param tab The tab widget for the tab. + * @param widget The widget to view when the tab is selected. + * @see removeTab, removeTabWithIndex + */ + virtual void addTab(Tab* tab, Widget* widget); + + /** + * Removes a tab from the tabbed area. + * + * @param index The index of the tab to remove. + * @see addTab + */ + virtual void removeTabWithIndex(unsigned int index); + + /** + * Removes a tab from the tabbed area. + * + * @param index The tab to remove. + * @see addTab + */ + virtual void removeTab(Tab* tab); + + /** + * Checks if a tab given an index is selected or not. + * + * @param index The index of the tab to check. + * @return True if the tab is selected, false otherwise. + * @see setSelectedTab + */ + virtual bool isTabSelected(unsigned int index) const; + + /** + * Checks if a tab is selected or not. + * + * @param index The tab to check. + * @return True if the tab is selected, false otherwise. + * @see setSelectedTab + */ + virtual bool isTabSelected(Tab* tab); + + /** + * Sets a tab given an index to be selected. + * + * @param index The index of the tab to be selected. + * @see isTabSelected, getSelectedTab + */ + virtual void setSelectedTab(unsigned int index); + + /** + * Sets a tab to be selected or not. + * + * @param index The tab to be selected. + * @see isTabSelected, getSelectedTab + */ + 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. + * @see isTabSelected, setSelectedTab + */ + virtual int getSelectedTabIndex() const; + + /** + * Gets the selected tab. + * + * @return The selected tab. + * @see isTabSelected, setSelectedTab + */ + Tab* getSelectedTab(); + + + // Inherited from Widget + + virtual void draw(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 tab container and the widget container. + */ + void adjustSize(); + + /** + * Adjusts the positions of the tabs. + */ + void adjustTabPositions(); + + /** + * Holds the selected tab. + */ + Tab* mSelectedTab; + + /** + * Holds the container for the tabs. + */ + Container* mTabContainer; + + /** + * Holds the container for the widgets. + */ + Container* mWidgetContainer; + + /** + * Holds a vector of tabs to delete in the destructor. + * A tab that is to be deleted is a tab that has been + * internally created by the tabbed area. + */ + std::vector mTabsToDelete; + + /** + * A map between a tab and a widget to display when the + * tab is selected. + */ + std::vector > mTabs; + + /** + * True if the tabbed area is opaque, false otherwise. + */ + bool mOpaque; + }; +} + +#endif // end GCN_TABBEDAREA_HPP diff --git a/src/guichan/include/guichan/widgets/textbox.hpp b/src/guichan/include/guichan/widgets/textbox.hpp new file mode 100644 index 000000000..b00dcef20 --- /dev/null +++ b/src/guichan/include/guichan/widgets/textbox.hpp @@ -0,0 +1,289 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_TEXTBOX_HPP +#define GCN_TEXTBOX_HPP + +#include +#include +#include + +#include "guichan/keylistener.hpp" +#include "guichan/mouselistener.hpp" +#include "guichan/platform.hpp" +#include "guichan/widget.hpp" + +namespace gcn +{ + /** + * An implementation of a text box where a user can enter text that contains of many lines. + */ + class GCN_CORE_DECLSPEC TextBox: + public Widget, + public MouseListener, + public KeyListener + { + public: + /** + * Constructor. + */ + TextBox(); + + /** + * Constructor. + * + * @param text The default text of the text box. + */ + TextBox(const std::string& text); + + /** + * Sets the text of the text box. + * + * @param text The text of the text box. + * @see getText + */ + void setText(const std::string& text); + + /** + * Gets the text of the text box. + * + * @return The text of the text box. + * @see setText + */ + std::string getText() const; + + /** + * Gets a certain row from the text. + * + * @param row The number of the row to get from the text. + * @return A row from the text of the text box. + * @see setTextRow + */ + const std::string& getTextRow(int row) const; + + /** + * Sets the text of a certain row of the text. + * + * @param row The number of the row to set in the text. + * @param text The text to set in the given row number. + * @see getTextRow + */ + 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. + * @see setCaretPosition + */ + unsigned int getCaretPosition() const; + + /** + * Sets the position of the caret in the text. + * + * @param position the positon of the caret. + * @see getCaretPosition + */ + void setCaretPosition(unsigned int position); + + /** + * Gets the row number where the caret is currently located. + * + * @return The row number where the caret is currently located. + * @see setCaretRow + */ + unsigned int getCaretRow() const; + + /** + * Sets the row where the caret should be currently located. + * + * @param The row where the caret should be currently located. + * @see getCaretRow + */ + void setCaretRow(int row); + + /** + * Gets the column where the caret is currently located. + * + * @return The column where the caret is currently located. + * @see setCaretColumn + */ + unsigned int getCaretColumn() const; + + /** + * Sets the column where the caret should be currently located. + * + * @param The column where the caret should be currently located. + * @see getCaretColumn + */ + void setCaretColumn(int column); + + /** + * Sets the row and the column where the caret should be curretly + * located. + * + * @param row The row where the caret should be currently located. + * @param column The column where the caret should be currently located. + * @see getCaretRow, getCaretColumn + */ + void setCaretRowColumn(int row, int column); + + /** + * Scrolls the text to the caret if the text box is in a scroll area. + * + * @see ScrollArea + */ + virtual void scrollToCaret(); + + /** + * Checks if the text box is editable. + * + * @return True it the text box is editable, false otherwise. + * @see setEditable + */ + bool isEditable() const; + + /** + * Sets the text box to be editable or not. + * + * @param editable True if the text box should be editable, false otherwise. + */ + void setEditable(bool editable); + + /** + * Adds a row of text to the end of the text. + * + * @param row The row to add. + */ + virtual void addRow(const std::string row); + + /** + * Checks if the text box is opaque. An opaque text box will draw + * it's background and it's text. A non opaque text box only draw it's + * text making it transparent. + * + * @return True if the text box is opaque, false otherwise. + * @see setOpaque + */ + bool isOpaque(); + + /** + * Sets the text box to be opaque or not. An opaque text box will draw + * it's background and it's text. A non opaque text box only draw it's + * text making it transparent. + * + * @param opaque True if the text box should be opaque, false otherwise. + * @see isOpaque + */ + void setOpaque(bool opaque); + + + // Inherited from Widget + + virtual void draw(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. Overloaded this method if you want to + * change the style of 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 text box's size to fit the text. + */ + virtual void adjustSize(); + + /** + * Holds all the rows of the text. + */ + std::vector mTextRows; + + /** + * Holds the current column of the caret. + */ + int mCaretColumn; + + /** + * Holds the current row of the caret. + */ + int mCaretRow; + + /** + * True if the text box is editable, false otherwise. + */ + bool mEditable; + + /** + * True if the text box is editable, false otherwise. + */ + bool mOpaque; + }; +} + +#endif // end GCN_TEXTBOX_HPP diff --git a/src/guichan/include/guichan/widgets/textfield.hpp b/src/guichan/include/guichan/widgets/textfield.hpp new file mode 100644 index 000000000..486660a8a --- /dev/null +++ b/src/guichan/include/guichan/widgets/textfield.hpp @@ -0,0 +1,177 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_TEXTFIELD_HPP +#define GCN_TEXTFIELD_HPP + +#include "guichan/keylistener.hpp" +#include "guichan/mouselistener.hpp" +#include "guichan/platform.hpp" +#include "guichan/widget.hpp" + +#include + +namespace gcn +{ + /** + * An implementation of a text field where a user can enter a line of text. + */ + class GCN_CORE_DECLSPEC TextField: + public Widget, + public MouseListener, + public KeyListener + { + public: + /** + * Constructor. + */ + TextField(); + + /** + * Constructor. The text field will be automatically resized + * to fit the text. + * + * @param text The default text of the text field. + */ + TextField(const std::string& text); + + /** + * Sets the text of the text field. + * + * @param text The text of the text field. + * @see getText + */ + void setText(const std::string& text); + + /** + * Gets the text of the text field. + * + * @return The text of the text field. + * @see setText + */ + const std::string& getText() const; + + /** + * Adjusts the size of the text field to fit the text. + */ + void adjustSize(); + + /** + * Adjusts the height of the text field to fit caption. + */ + void adjustHeight(); + + /** + * Sets the caret position. As there is only one line of text + * in a text field the position is the caret's x coordinate. + * + * @param position The caret position. + * @see getCaretPosition + */ + void setCaretPosition(unsigned int position); + + /** + * Gets the caret position. As there is only one line of text + * in a text field the position is the caret's x coordinate. + * + * @return The caret position. + * @see setCaretPosition + */ + unsigned int getCaretPosition() const; + + + // Inherited from Widget + + virtual void fontChanged(); + + virtual void draw(Graphics* graphics); + + + // Inherited from MouseListener + + virtual void mousePressed(MouseEvent& mouseEvent); + + virtual void mouseDragged(MouseEvent& mouseEvent); + + + // Inherited from KeyListener + + virtual void keyPressed(KeyEvent& keyEvent); + + protected: + /** + * Draws the caret. Overloaded this method 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); + + /** + * Scrolls the text horizontally so that the caret shows if needed. + * The method is used any time a user types in the text field so the + * caret always will be shown. + */ + void fixScroll(); + + /** + * Holds the text of the text box. + */ + std::string mText; + + /** + * Holds the caret position. + */ + unsigned int mCaretPosition; + + /** + * Holds the amount scrolled in x. If a user types more characters than + * the text field can display, due to the text field being to small, the + * text needs to scroll in order to show the last type character. + */ + int mXScroll; + }; +} + +#endif // end GCN_TEXTFIELD_HPP diff --git a/src/guichan/include/guichan/widgets/window.hpp b/src/guichan/include/guichan/widgets/window.hpp new file mode 100644 index 000000000..63685c7fb --- /dev/null +++ b/src/guichan/include/guichan/widgets/window.hpp @@ -0,0 +1,261 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * 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. + */ + +#ifndef GCN_WINDOW_HPP +#define GCN_WINDOW_HPP + +#include + +#include "guichan/mouselistener.hpp" +#include "guichan/platform.hpp" +#include "guichan/widgets/container.hpp" + +#ifdef __GNUC__ +#define _UNUSED_ __attribute__ ((unused)) +#else +#define _UNUSED_ +#endif + +namespace gcn +{ + /** + * An implementation of a movable window that can contain other widgets. + */ + class GCN_CORE_DECLSPEC Window : public Container, + public MouseListener + { + public: + /** + * Constructor. + */ + Window(); + + /** + * Constructor. The window will be automatically resized in height + * to fit the caption. + * + * @param caption the caption of the window. + */ + Window(const std::string& caption); + + /** + * Destructor. + */ + virtual ~Window(); + + /** + * Sets the caption of the window. + * + * @param caption The caption of the window. + * @see getCaption + */ + void setCaption(const std::string& caption); + + /** + * Gets the caption of the window. + * + * @return the caption of the window. + * @see setCaption + */ + const std::string& getCaption() const; + + /** + * Sets the alignment of the caption. + * + * @param alignment The alignment of the caption. + * @see getAlignment, Graphics + */ + void setAlignment(Graphics::Alignment alignment); + + /** + * Gets the alignment of the caption. + * + * @return The alignment of caption. + * @see setAlignment, Graphics + */ + Graphics::Alignment getAlignment() const; + + /** + * Sets the padding of the window. The padding is the distance between the + * window border and the content. + * + * @param padding The padding of the window. + * @see getPadding + */ + void setPadding(unsigned int padding); + + /** + * Gets the padding of the window. The padding is the distance between the + * window border and the content. + * + * @return The padding of the window. + * @see setPadding + */ + unsigned int getPadding() const; + + /** + * Sets the title bar height. + * + * @param height The title height value. + * @see getTitleBarHeight + */ + void setTitleBarHeight(unsigned int height); + + /** + * Gets the title bar height. + * + * @return The title bar height. + * @see setTitleBarHeight + */ + unsigned int getTitleBarHeight(); + + /** + * Sets the window to be moveble or not. + * + * @param movable True if the window should be movable, false otherwise. + * @see isMovable + */ + void setMovable(bool movable); + + /** + * Checks if the window is movable. + * + * @return True if the window is movable, false otherwise. + * @see setMovable + */ + bool isMovable() const; + + /** + * Sets the window to be opaque or not. An opaque window will draw it's background + * and it's content. A non opaque window will only draw it's content. + * + * @param opaque True if the window should be opaque, false otherwise. + * @see isOpaque + */ + void setOpaque(bool opaque); + + /** + * Checks if the window is opaque. + * + * @return True if the window is opaque, false otherwise. + * @see setOpaque + */ + bool isOpaque(); + + /** + * Resizes the window to fit the content. + */ + virtual void resizeToContent(); + + + // Inherited from BasicContainer + + virtual Rectangle getChildrenArea(); + + + // Inherited from Widget + + virtual void draw(Graphics* graphics); + + + // Inherited from MouseListener + + virtual void mousePressed(MouseEvent& mouseEvent); + + virtual void mouseDragged(MouseEvent& mouseEvent); + + virtual void mouseReleased(MouseEvent& mouseEvent); + + protected: + /** + * Holds the caption of the window. + */ + std::string mCaption; + + /** + * Holds the alignment of the caption. + */ + Graphics::Alignment mAlignment; + + /** + * Holds the padding of the window. + */ + unsigned int mPadding; + + /** + * Holds the title bar height of the window. + */ + unsigned int mTitleBarHeight; + + /** + * True if the window is movable, false otherwise. + */ + bool mMovable; + + /** + * True if the window is opaque, false otherwise. + */ + bool mOpaque; + + /** + * Holds a drag offset as an x coordinate where the drag of the window + * started if the window is being dragged. It's used to move the window + * correctly when dragged. + */ + int mDragOffsetX; + + /** + * Holds a drag offset as an y coordinate where the drag of the window + * started if the window is being dragged. It's used to move the window + * correctly when dragged. + */ + int mDragOffsetY; + + /** + * True if the window is being moved, false otherwise. + */ + bool mMoved; + }; +} + +#endif // end GCN_WINDOW_HPP diff --git a/src/guichan/input.hpp b/src/guichan/input.hpp deleted file mode 100644 index 7510d3cb2..000000000 --- a/src/guichan/input.hpp +++ /dev/null @@ -1,115 +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. - */ - -#ifndef GCN_INPUT_HPP -#define GCN_INPUT_HPP - -#include "guichan/platform.hpp" - -namespace gcn -{ - class KeyInput; - class MouseInput; - - /** - * Abstract class for providing functions for user input. - * - * Guichan contains implementations of Input for common - * libraries like the Allegro library, the HGE library, - * and the SDL library. - * To make Guichan usable with other libraries, an Input - * class must be implemented. - * - * @see AllegroInput, HGEInput, OpenLayerInput, - * SDLInput - */ - class GCN_CORE_DECLSPEC Input - { - public: - - /** - * Destructor. - */ - virtual ~Input(){ } - - /** - * Checks if the key queue is empty, or not. - * - * @return True if the key queue is empty, - * false otherwise. - */ - virtual bool isKeyQueueEmpty() = 0; - - /** - * Dequeues the key input queue. - * - * @return The first key input in the key input queue. - */ - virtual KeyInput dequeueKeyInput() = 0; - - /** - * Checks if the mouse queue is empyt, or not. - * - * @return True if the mouse queue is empty, - * false otherwise. - */ - virtual bool isMouseQueueEmpty() = 0; - - /** - * Dequeues the mouse input queue. - * - * @return The first mouse input in the mouse input queue. - */ - virtual MouseInput dequeueMouseInput() = 0; - - /** - * Polls all exsisting input. Called when input should - * be polled. The function exists for compatibility reason - * where some libraries need to poll input at a certain - * logic rate. - */ - virtual void _pollInput() = 0; - }; -} - -#endif // end GCN_INPUT_HPP diff --git a/src/guichan/inputevent.hpp b/src/guichan/inputevent.hpp deleted file mode 100644 index 8594d3dae..000000000 --- a/src/guichan/inputevent.hpp +++ /dev/null @@ -1,159 +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. - */ - -#ifndef GCN_INPUTEVENT_HPP -#define GCN_INPUTEVENT_HPP - -#include "guichan/event.hpp" -#include "guichan/platform.hpp" - -namespace gcn -{ - /** - * Base class for all events concerning input. - * - * @author Olof Naessén - * @since 0.6.0 - */ - class GCN_CORE_DECLSPEC InputEvent: public Event - { - public: - - /** - * Constructor. - * - * @param source The source widget of the event. - * @param isShiftPressed True if shift is pressed, false otherwise. - * @param isControlPressed True if control is pressed, false otherwise. - * @param isAltPressed True if alt is pressed, false otherwise. - * @param isMetaPressed True if meta is pressed, false otherwise. - */ - InputEvent(Widget* source, - bool isShiftPressed, - bool isControlPressed, - bool isAltPressed, - bool isMetaPressed); - - /** - * Checks if shift is pressed. - * - * @return True if shift was pressed at the same time as the key, - * false otherwise. - */ - bool isShiftPressed() const; - - /** - * Checks if control is pressed. - * - * @return True if control was pressed at the same time as the key, - * false otherwise. - */ - bool isControlPressed() const; - - /** - * Checks if alt is pressed. - * - * @return True if alt was pressed at the same time as the key, - * false otherwise. - */ - bool isAltPressed() const; - - /** - * Checks whether meta is pressed. - * - * @return True if meta was pressed at the same time as the key, - * false otherwise. - */ - bool isMetaPressed() const; - - /** - * Marks the event as consumed. Input event listeners may discard - * consumed input or act on consumed input. An example of a widget - * that discards consumed input is the ScrollArea widget that - * discards consumed mouse wheel events so the ScrollArea will not - * scroll if for instance a Slider's value inside the ScrollArea was - * changed with the mouse wheel. - * - * @see isConsumed - */ - void consume(); - - /** - * Checks if the input event is consumed. - * - * @return True if the input event is consumed, - * false otherwise. - * @see consume - */ - bool isConsumed() const; - - protected: - /** - * True if shift is pressed, false otherwise. - */ - bool mShiftPressed; - - /** - * True if control is pressed, false otherwise. - */ - bool mControlPressed; - - /** - * True if alt is pressed, false otherwise. - */ - bool mAltPressed; - - /** - * True if meta is pressed, false otherwise. - */ - bool mMetaPressed; - - /** - * True if the input event is consumed, - * false otherwise. - */ - bool mIsConsumed; - }; -} - -#endif // end GCN_INPUTEVENT_HPP diff --git a/src/guichan/key.hpp b/src/guichan/key.hpp deleted file mode 100644 index 0b550dcca..000000000 --- a/src/guichan/key.hpp +++ /dev/null @@ -1,182 +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. - */ - -#ifndef GCN_KEY_HPP -#define GCN_KEY_HPP - -#include "guichan/platform.hpp" - -// windows.h defines DELETE which breaks this file as we have a constant named -// DELETE, hence we undefine DELETE if it is defined and hope people don't use -// that windows define with Guichan. -#if defined (_WIN32) && defined(DELETE) -#undef DELETE -#endif - -namespace gcn -{ - /** - * Represents a key or a character. - */ - class GCN_CORE_DECLSPEC Key - { - public: - - /** - * Constructor. - * - * @param value The ascii or enum value for the key. - */ - Key(int value = 0); - - /** - * Checks if a key is a character. - * - * @return True if the key is a letter, number or whitespace, - * false otherwise. - */ - bool isCharacter() const; - - /** - * Checks if a key is a number. - * - * @return True if the key is a number (0-9), - * false otherwise. - */ - bool isNumber() const; - - /** - * Checks if a key is a letter. - * - * @return True if the key is a letter (a-z,A-Z), - * false otherwise. - */ - bool isLetter() const; - - /** - * Gets the value of the key. If an ascii value exists it - * will be returned. Otherwise an enum value will be returned. - * - * @return the value of the key. - */ - int getValue() const; - - /** - * Compares two keys. - * - * @param key The key to compare this key with. - * @return True if the keys are equal, false otherwise. - */ - bool operator==(const Key& key) const; - - /** - * Compares two keys. - * - * @param key The key to compare this key with. - * @return True if the keys are not equal, false otherwise. - */ - bool operator!=(const Key& key) const; - - /** - * An enum with key values. - */ - enum - { - SPACE = ' ', - TAB = '\t', - ENTER = '\n', - LEFT_ALT = 1000, - RIGHT_ALT, - LEFT_SHIFT, - RIGHT_SHIFT, - LEFT_CONTROL, - RIGHT_CONTROL, - LEFT_META, - RIGHT_META, - LEFT_SUPER, - RIGHT_SUPER, - INSERT, - HOME, - PAGE_UP, - DELETE, - END, - PAGE_DOWN, - ESCAPE, - CAPS_LOCK, - BACKSPACE, - F1, - F2, - F3, - F4, - F5, - F6, - F7, - F8, - F9, - F10, - F11, - F12, - F13, - F14, - F15, - PRINT_SCREEN, - SCROLL_LOCK, - PAUSE, - NUM_LOCK, - ALT_GR, - LEFT, - RIGHT, - UP, - DOWN - }; - - protected: - /** - * Holds the value of the key. It may be an ascii value - * or an enum value. - */ - int mValue; - }; -} - -#endif // end GCN_KEY_HPP diff --git a/src/guichan/keyevent.hpp b/src/guichan/keyevent.hpp deleted file mode 100644 index f42601235..000000000 --- a/src/guichan/keyevent.hpp +++ /dev/null @@ -1,138 +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. - */ - -#ifndef GCN_KEYEVENT_HPP -#define GCN_KEYEVENT_HPP - -#include "guichan/inputevent.hpp" -#include "guichan/key.hpp" -#include "guichan/platform.hpp" - -namespace gcn -{ - class Widget; - - /** - * Represents a key event. - */ - class GCN_CORE_DECLSPEC KeyEvent: public InputEvent - { - public: - /** - * Key event types. - */ - enum - { - PRESSED = 0, - RELEASED - }; - - /** - * Constructor. - * - * @param source The source widget of the event. - * @param isShiftPressed True if shift is pressed, false otherwise. - * @param isControlPressed True if control is pressed, false otherwise. - * @param isAltPressed True if alt is pressed, false otherwise. - * @param isMetaPressed True if meta is pressed, false otherwise. - * @param type The type of the event. A value from KeyEventType. - * @param isNumericPad True if the event occured on the numeric pad, - * false otherwise. - * @param key The key of the event. - */ - KeyEvent(Widget* source, - bool isShiftPressed, - bool isControlPressed, - bool isAltPressed, - bool isMetaPressed, - unsigned int type, - bool isNumericPad, - const Key& key); - - /** - * Destructor. - */ - virtual ~KeyEvent(); - - /** - * Gets the type of the event. - * - * @return The type of the event. - */ - unsigned int getType() const; - - /** - * Checks if the key event occured on the numeric pad. - * - * @return True if key event occured on the numeric pad, - * false otherwise. - * - */ - bool isNumericPad() const; - - /** - * Gets the key of the event. - * - * @return The key of the event. - */ - const Key& getKey() const; - - protected: - /** - * Holds the type of the key event. - */ - unsigned int mType; - - /** - * True if the numeric pad was used, false otherwise. - */ - bool mIsNumericPad; - - /** - * Holds the key of the key event. - */ - Key mKey; - }; -} - -#endif // end GCN_KEYEVENT_HPP diff --git a/src/guichan/keyinput.hpp b/src/guichan/keyinput.hpp deleted file mode 100644 index 68c58fa0d..000000000 --- a/src/guichan/keyinput.hpp +++ /dev/null @@ -1,270 +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. - */ - -#ifndef GCN_KEYINPUT_HPP -#define GCN_KEYINPUT_HPP - -#include "guichan/key.hpp" -#include "guichan/platform.hpp" - -namespace gcn -{ - /** - * Internal class that represents key input. Generally you won't have to - * bother using this class unless you implement an Input class for - * a back end. - * - * @since 0.1.0 - */ - class GCN_CORE_DECLSPEC KeyInput - { - public: - - /** - * Constructor. - */ - KeyInput() : - mType(0), - mShiftPressed(false), - mControlPressed(false), - mAltPressed(false), - mMetaPressed(false), - mNumericPad(false) - { }; - - /** - * Constructor. - * - * @param key The key of the key input. - * @param type The type of key input. - */ - KeyInput(const Key& key, unsigned int type); - - /** - * Sets the type of the key input. - * - * @param type The type of key input. - * @see getType - */ - void setType(unsigned int type); - - /** - * Gets the type of the key input. - * - * @return the input type. - * @see setType - */ - int getType() const; - - /** - * Sets the key of the key input. - * - * @param key The key of the key input. - * @see getKey - */ - void setKey(const Key& key); - - /** - * Gets the key of the key input. - * - * @return The key of the key input. - * @see setKey - */ - const Key& getKey() const; - - /** - * Checks if shift is pressed. - * - * @return True if shift was pressed at the same - * time as the key, false otherwise. - * @see setShiftPressed - * @since 0.6.0 - */ - bool isShiftPressed() const; - - /** - * Sets shift to be pressed at the same time as the key, - * or not. - * - * @param pressed True if shift is pressed, false otherwise. - * @see isShiftPressed - * @since 0.6.0 - */ - void setShiftPressed(bool pressed); - - /** - * Checks if control is pressed. - * - * @return True if control was pressed at the same - * time as the key, false otherwise. - * @see setControlPressed - * @since 0.6.0 - */ - bool isControlPressed() const; - - /** - * Sets control to be pressed at the same time as the key, - * or not. - * - * @param pressed True if control is pressed, false otherwise. - * @see isControlPressed - * @since 0.6.0 - */ - void setControlPressed(bool pressed); - - /** - * Checks if alt is pressed. - * - * @return True if alt was pressed at the same - * time as the key, false otherwise. - * @see setAltPressed - * @since 0.6.0 - */ - bool isAltPressed() const; - - /** - * Sets the alt to be pressed at the same time as the key, - * or not. - * - * @param pressed True if alt is pressed at the same - * time as the key, , false otherwise. - * @see isAltPressed - * @since 0.6.0 - */ - void setAltPressed(bool pressed); - - /** - * Checks if meta is pressed. - * - * @return True if meta was pressed at the same - * time as the key, false otherwise. - * @see setMetaPressed - * @since 0.6.0 - */ - bool isMetaPressed() const; - - /** - * Sets meta to be pressed at the same time as the key, - * or not. - * - * @param pressed True if meta is pressed at the same - * time as the key, false otherwise. - * @see isMetaPressed - * @since 0.6.0 - */ - void setMetaPressed(bool pressed); - - /** - * Checks if the key was pressed at the numeric pad. - * - * @return True if key pressed at the numeric pad, - * false otherwise. - * @setNumericPad - * @since 0.6.0 - */ - bool isNumericPad() const; - - /** - * Sets the key to be pressed at the numeric pad. - * - * @param numpad True if the key was pressed at the numeric - * pad, false otherwise. - * @see isNumericPad - * @since 0.6.0 - */ - void setNumericPad(bool numpad); - - /** - * Key input types. This enum corresponds to the enum with event - * types on KeyEvent for easy mapping. - */ - enum - { - PRESSED = 0, - RELEASED - }; - - protected: - /** - * Holds the key of the key input. - */ - Key mKey; - - /** - * Holds the type of the key input. - */ - unsigned int mType; - - /** - * True if shift was pressed at the same time as the key, - * false otherwise. - */ - bool mShiftPressed; - - /** - * True if control was pressed at the same time as the key, - * false otherwise. - */ - bool mControlPressed; - - /** - * True if alt was pressed at the same time as the key, - * false otherwise. - */ - bool mAltPressed; - - /** - * True if meta was pressed at the same time as the key, - * false otherwise. - */ - bool mMetaPressed; - - /** - * True if the numeric pad was used when the key was pressed, - * false otherwise. - */ - bool mNumericPad; - }; -} - -#endif // end GCN_KEYINPUT_HPP diff --git a/src/guichan/keylistener.hpp b/src/guichan/keylistener.hpp deleted file mode 100644 index caeed0da4..000000000 --- a/src/guichan/keylistener.hpp +++ /dev/null @@ -1,101 +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. - */ - -#ifndef GCN_KEYLISTENER_HPP -#define GCN_KEYLISTENER_HPP - -#include "guichan/keyevent.hpp" -#include "guichan/platform.hpp" - -#ifdef __GNUC__ -#define _UNUSED_ __attribute__ ((unused)) -#else -#define _UNUSED_ -#endif - -namespace gcn -{ - class Key; - - /** - * Interface for listening for key events from widgets. - * - * @see Widget::addKeyListener, Widget::removeKeyListener - */ - class GCN_CORE_DECLSPEC KeyListener - { - public: - - /** - * Destructor. - */ - virtual ~KeyListener() { } - - /** - * Called if a key is pressed when the widget has keyboard focus. - * If a key is held down the widget will generate multiple key - * presses. - * - * @param keyEvent Discribes the event. - */ - virtual void keyPressed(KeyEvent& keyEvent _UNUSED_) { } - - /** - * Called if a key is released when the widget has keyboard focus. - * - * @param keyEvent Discribes the event. - */ - virtual void keyReleased(KeyEvent& keyEvent _UNUSED_) { } - - protected: - /** - * Constructor. - * - * You should not be able to make an instance of KeyListener, - * therefore its constructor is protected. - */ - KeyListener() { } - }; -} - -#endif // end GCN_KEYLISTENER_HPP diff --git a/src/guichan/listmodel.hpp b/src/guichan/listmodel.hpp deleted file mode 100644 index 1beae317b..000000000 --- a/src/guichan/listmodel.hpp +++ /dev/null @@ -1,86 +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. - */ - -#ifndef GCN_LISTMODEL_HPP -#define GCN_LISTMODEL_HPP - -#include - -#include "guichan/platform.hpp" - -namespace gcn -{ - /** - * An interface for a model that represents a list. It is - * used in certain widgets, like the ListBox, to handle a - * lists with string elements. If you want to use widgets - * like ListBox, make a derived class from this class that - * represents your list. - */ - class GCN_CORE_DECLSPEC ListModel - { - - public: - /** - * Destructor. - */ - virtual ~ListModel() { } - - /** - * Gets the number of elements in the list. - * - * @return The number of elements in the list - */ - 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 at the a certain index. - */ - virtual std::string getElementAt(int i) = 0; - }; -} - -#endif // end GCN_LISTMODEL_HPP diff --git a/src/guichan/mouseevent.hpp b/src/guichan/mouseevent.hpp deleted file mode 100644 index 280d373e6..000000000 --- a/src/guichan/mouseevent.hpp +++ /dev/null @@ -1,200 +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. - */ - -#ifndef GCN_MOUSEEVENT_HPP -#define GCN_MOUSEEVENT_HPP - -#include "guichan/inputevent.hpp" -#include "guichan/platform.hpp" - -namespace gcn -{ - class Gui; - class Widget; - - /** - * Represents a mouse event. - * - * @author Olof Naessén - * @since 0.6.0 - */ - class GCN_CORE_DECLSPEC MouseEvent: public InputEvent - { - public: - - /** - * Constructor. - * - * @param source The source widget of the mouse event. - * @param isShiftPressed True if shift is pressed, false otherwise. - * @param isControlPressed True if control is pressed, false otherwise. - * @param isAltPressed True if alt is pressed, false otherwise. - * @param isMetaPressed True if meta is pressed, false otherwise. - * @param type The type of the mouse event. - * @param button The button of the mouse event. - * @param x The x coordinate of the event relative to the source widget. - * @param y The y coordinate of the event relative the source widget. - * @param clickCount The number of clicks generated with the same button. - * It's set to zero if another button is used. - */ - MouseEvent(Widget* source, - bool isShiftPressed, - bool isControlPressed, - bool isAltPressed, - bool isMetaPressed, - unsigned int type, - unsigned int button, - int x, - int y, - int clickCount); - - /** - * Gets the button of the mouse event. - * - * @return The button of the mouse event. - */ - unsigned int getButton() const; - - /** - * Gets the x coordinate of the mouse event. - * The coordinate relative to widget the mouse listener - * receiving the events have registered to. - * - * @return The x coordinate of the mouse event. - * @see Widget::addMouseListener, Widget::removeMouseListener - */ - int getX() const; - - /** - * Gets the y coordinate of the mouse event. - * The coordinate relative to widget the mouse listener - * receiving the events have registered to. - * - * @return The y coordinate of the mouse event. - * @see Widget::addMouseListener, Widget::removeMouseListener - */ - int getY() const; - - /** - * Gets the number of clicks generated with the same button. - * It's set to zero if another button is used. - * - * @return The number of clicks generated with the same button. - */ - int getClickCount() const; - - /** - * Gets the type of the event. - * - * @return The type of the event. - */ - unsigned int getType() const; - - /** - * Mouse event types. - */ - enum - { - MOVED = 0, - PRESSED, - RELEASED, - WHEEL_MOVED_DOWN, - WHEEL_MOVED_UP, - CLICKED, - ENTERED, - EXITED, - DRAGGED - - }; - - /** - * Mouse button types. - */ - enum - { - EMPTY = 0, - LEFT, - RIGHT, - MIDDLE - }; - - protected: - /** - * Holds the type of the mouse event. - */ - unsigned int mType; - - /** - * Holds the button of the mouse event. - */ - unsigned int mButton; - - /** - * Holds the x-coordinate of the mouse event. - */ - int mX; - - /** - * Holds the y-coordinate of the mouse event. - */ - int mY; - - /** - * The number of clicks generated with the same button. - * It's set to zero if another button is used. - */ - int mClickCount; - - /** - * Gui is a friend of this class in order to be able to manipulate - * the protected member variables of this class and at the same time - * keep the MouseEvent class as const as possible. Gui needs to - * update the x och y coordinates for the coordinates to be relative - * to widget the mouse listener receiving the events have registered - * to. - */ - friend class Gui; - }; -} - -#endif // GCN_MOUSEEVENT_HPP diff --git a/src/guichan/mouseinput.hpp b/src/guichan/mouseinput.hpp deleted file mode 100644 index 3825d5439..000000000 --- a/src/guichan/mouseinput.hpp +++ /dev/null @@ -1,241 +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. - */ - -#ifndef GCN_MOUSEINPUT_HPP -#define GCN_MOUSEINPUT_HPP - -#include "guichan/platform.hpp" - -namespace gcn -{ - - /** - * Internal class that represents mouse input. Generally you won't have to - * bother using this class unless you implement an Input class for - * a back end. - * - * @author Olof Naessén - * @author Per Larsson - * @since 0.1.0 - */ - class GCN_CORE_DECLSPEC MouseInput - { - public: - - /** - * Constructor. - */ - MouseInput() : - mType(0), - mButton(0), - mTimeStamp(0), - mX(0), - mY(0) - { }; - - /** - * Constructor. - * - * @param button The button pressed. - * @param type The type of mouse input. - * @param x The mouse x coordinate. - * @param y The mouse y coordinate. - * @param timeStamp The timestamp of the mouse input. Used to - * check for double clicks. - */ - MouseInput(unsigned int button, - unsigned int type, - int x, - int y, - int timeStamp); - - /** - * Sets the type of the mouse input. - * - * @param type The type of the mouse input. Should be a value from the - * mouse event type enum - * @see getType - * @since 0.1.0 - */ - void setType(unsigned int type); - - /** - * Gets the type of the mouse input. - * - * @return The type of the mouse input. A value from the mouse event - * type enum. - * @see setType - * @since 0.1.0 - */ - unsigned int getType() const; - - /** - * Sets the button pressed. - * - * @param button The button pressed. Should be one of the values - * in the mouse event button enum. - * @see getButton. - * @since 0.1.0 - */ - void setButton(unsigned int button); - - /** - * Gets the button pressed. - * - * @return The button pressed. A value from the mouse event - * button enum. - * @see setButton - * @since 0.1.0 - */ - unsigned int getButton() const; - - /** - * Sets the timestamp for the mouse input. - * Used to check for double clicks. - * - * @param timeStamp The timestamp of the mouse input. - * @see getTimeStamp - * @since 0.1.0 - */ - void setTimeStamp(int timeStamp); - - /** - * Gets the time stamp of the input. - * Used to check for double clicks. - * - * @return The time stamp of the mouse input. - * @see setTimeStamp - * @since 0.1.0 - */ - int getTimeStamp() const; - - /** - * Sets the x coordinate of the mouse input. - * - * @param x The x coordinate of the mouse input. - * @see getX - * @since 0.6.0 - */ - void setX(int x); - - /** - * Gets the x coordinate of the mouse input. - * - * @return The x coordinate of the mouse input. - * @see setX - * @since 0.6.0 - */ - int getX() const; - - /** - * Sets the y coordinate of the mouse input. - * - * @param y The y coordinate of the mouse input. - * @see getY - * @since 0.6.0 - */ - void setY(int y); - - /** - * Gets the y coordinate of the mouse input. - * - * @return The y coordinate of the mouse input. - * @see setY - * @since 0.6.0 - */ - int getY() const; - - /** - * Mouse input event types. This enum partially corresponds - * to the enum with event types in MouseEvent for easy mapping. - */ - enum - { - MOVED = 0, - PRESSED, - RELEASED, - WHEEL_MOVED_DOWN, - WHEEL_MOVED_UP - }; - - /** - * Mouse button types. - */ - enum - { - EMPTY = 0, - LEFT, - RIGHT, - MIDDLE - }; - - protected: - /** - * Holds the type of the mouse input. - */ - unsigned int mType; - - /** - * Holds the button of the mouse input. - */ - unsigned int mButton; - - /** - * Holds the timestamp of the mouse input. Used to - * check for double clicks. - */ - int mTimeStamp; - - /** - * Holds the x coordinate of the mouse input. - */ - int mX; - - /** - * Holds the y coordinate of the mouse input. - */ - int mY; - }; -} - -#endif // end GCN_MOUSEINPUT_HPP diff --git a/src/guichan/mouselistener.hpp b/src/guichan/mouselistener.hpp deleted file mode 100644 index 152d3494e..000000000 --- a/src/guichan/mouselistener.hpp +++ /dev/null @@ -1,189 +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. - */ - -#ifndef GCN_MOUSELISTENER_HPP -#define GCN_MOUSELISTENER_HPP - -#include "guichan/mouseevent.hpp" -#include "guichan/platform.hpp" - -#ifdef __GNUC__ -#define _UNUSED_ __attribute__ ((unused)) -#else -#define _UNUSED_ -#endif - -namespace gcn -{ - /** - * Interface for listening for mouse events from widgets. - * - * @see Widget::addMouseListener, Widget::removeMouseListener - * @since 0.1.0 - */ - class GCN_CORE_DECLSPEC MouseListener - { - public: - - /** - * Destructor. - */ - virtual ~MouseListener() { } - - /** - * Called when the mouse has entered into the widget area. - * - * @param mouseEvent Describes the event. - * @since 0.6.0 - */ - virtual void mouseEntered(MouseEvent& mouseEvent _UNUSED_) - { - - } - - /** - * Called when the mouse has exited the widget area. - * - * @param mouseEvent Describes the event. - * @since 0.6.0 - */ - virtual void mouseExited(MouseEvent& mouseEvent _UNUSED_) - { - - } - - /** - * Called when a mouse button has been pressed on the widget area. - * - * NOTE: A mouse press is NOT equal to a mouse click. - * Use mouseClickMessage to check for mouse clicks. - * - * @param mouseEvent Describes the event. - * @since 0.6.0 - */ - virtual void mousePressed(MouseEvent& mouseEvent _UNUSED_) - { - - } - - /** - * Called when a mouse button has been released on the widget area. - * - * @param mouseEvent Describes the event. - * @since 0.6.0 - */ - virtual void mouseReleased(MouseEvent& mouseEvent _UNUSED_) - { - - } - - /** - * Called when a mouse button is pressed and released (clicked) on - * the widget area. - * - * @param mouseEvent Describes the event. - * @since 0.6.0 - */ - virtual void mouseClicked(MouseEvent& mouseEvent _UNUSED_) - { - - } - - /** - * Called when the mouse wheel has moved up on the widget area. - * - * @param mouseEvent Describes the event. - * @since 0.6.0 - */ - virtual void mouseWheelMovedUp(MouseEvent& mouseEvent _UNUSED_) - { - - } - - /** - * Called when the mouse wheel has moved down on the widget area. - * - * @param mousEvent Describes the event. - * @since 0.6.0 - */ - virtual void mouseWheelMovedDown(MouseEvent& mouseEvent _UNUSED_) - { - - } - - /** - * Called when the mouse has moved in the widget area and no mouse button - * has been pressed (i.e no widget is being dragged). - * - * @param mouseEvent Describes the event. - * @since 0.6.0 - */ - virtual void mouseMoved(MouseEvent& mouseEvent _UNUSED_) - { - - } - - /** - * Called when the mouse has moved and the mouse has previously been - * pressed on the widget. - * - * @param mouseEvent Describes the event. - * @since 0.6.0 - */ - virtual void mouseDragged(MouseEvent& mouseEvent _UNUSED_) - { - - } - - protected: - /** - * Constructor. - * - * You should not be able to make an instance of MouseListener, - * therefore its constructor is protected. - */ - MouseListener() { } - }; -} - -#endif // end GCN_MOUSELISTENER_HPP diff --git a/src/guichan/platform.hpp b/src/guichan/platform.hpp deleted file mode 100644 index e2ea89767..000000000 --- a/src/guichan/platform.hpp +++ /dev/null @@ -1,79 +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. - */ - -#ifndef GCN_PLATFORM_HPP -#define GCN_PLATFORM_HPP - -#if defined (__MINGW32__) && defined(GUICHAN_BUILD) -#define GCN_CORE_DECLSPEC __declspec(dllexport) - -#elif defined (__MINGW32__) && defined(GUICHAN_EXTENSION_BUILD) -#define GCN_EXTENSION_DECLSPEC __declspec(dllexport) -#define GCN_CORE_DECLSPEC __declspec(dllimport) - -#elif defined (__MINGW32__) && defined(GUICHAN_DLL_IMPORT) -#define GCN_CORE_DECLSPEC __declspec(dllimport) -#define GCN_EXTENSION_DECLSPEC __declspec(dllimport) - -#elif defined(_MSC_VER) && defined(GUICHAN_BUILD) -#define GCN_CORE_DECLSPEC _declspec(dllexport) - -#elif defined(_MSC_VER) && defined(GUICHAN_EXTENSION_BUILD) -#define GCN_CORE_DECLSPEC _declspec(dllimport) -#define GCN_EXTENSION_DECLSPEC _declspec(dllexport) - -#endif - -#ifndef GCN_CORE_DECLSPEC -#define GCN_CORE_DECLSPEC -#endif - -#ifndef GCN_EXTENSION_DECLSPEC -#define GCN_EXTENSION_DECLSPEC -#endif - -#ifndef NULL -#define NULL 0 -#endif - -#endif // end GCN_PLATFORM_HPP diff --git a/src/guichan/rectangle.hpp b/src/guichan/rectangle.hpp deleted file mode 100644 index 1d21654df..000000000 --- a/src/guichan/rectangle.hpp +++ /dev/null @@ -1,140 +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. - */ - -#ifndef GCN_RECTANGLE_HPP -#define GCN_RECTANGLE_HPP - -#include "guichan/platform.hpp" - -#include - -namespace gcn -{ - /** - * Represents a rectangle. - * - * @since 0.1.0 - */ - class GCN_CORE_DECLSPEC Rectangle - { - public: - - /** - * Constructor. The default rectangle is an empty rectangle - * at the coordinates (0,0). - */ - Rectangle(); - - /** - * Constructor. - * - * @param x The x coordinate of the rectangle. - * @param y The y coordinate of the rectangle. - * @param width The width of the rectangle. - * @param height The height of the rectangle. - * @since 0.1.0 - */ - Rectangle(int x, int y, int width, int height); - - /** - * Sets the dimension of a rectangle. - * - * @param x The x coordinate of the rectangle. - * @param y The y coordinate of the rectangle. - * @param width The width of the rectangle. - * @param height The height of the rectangle. - * @since 0.1.0 - */ - void setAll(int x, int y, int width, int height); - - /** - * Checks if another rectangle intersects with the rectangle. - * - * @param rectangle Another rectangle to check for intersection. - * @return True if the rectangles intersect, false otherwise. - * @since 0.1.0 - */ - bool isIntersecting(const Rectangle& rectangle) const; - - /** - * Checks if a point is inside the rectangle - * - * @param x The x coordinate of the point. - * @param y The y coordinate of the point. - * @return True if the point is inside the rectangle. - * @since 0.1.0 - */ - bool isPointInRect(int x, int y) const; - - /** - * Output operator for output. - * - * @param out The stream to output to. - * @param rectangle The rectangle to output. - */ - friend std::ostream& operator<<(std::ostream& out, - const Rectangle& rectangle); - - /** - * Holds the x coordinate of the rectangle. - */ - int x; - - /** - * Holds the x coordinate of the rectangle. - */ - int y; - - /** - * Holds the width of the rectangle. - */ - int width; - - /** - * Holds the height of the rectangle. - */ - int height; - }; -} - -#endif // end GCN_RECTANGEL_HPP diff --git a/src/guichan/sdl/sdlgraphics.hpp b/src/guichan/sdl/sdlgraphics.hpp deleted file mode 100644 index 70a234d33..000000000 --- a/src/guichan/sdl/sdlgraphics.hpp +++ /dev/null @@ -1,156 +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. - */ - -#ifndef GCN_SDLGRAPHICS_HPP -#define GCN_SDLGRAPHICS_HPP - -#include "SDL.h" - -#include "guichan/color.hpp" -#include "guichan/graphics.hpp" -#include "guichan/platform.hpp" - -namespace gcn -{ - class Image; - class Rectangle; - - /** - * SDL implementation of the Graphics. - */ - class GCN_EXTENSION_DECLSPEC SDLGraphics : public Graphics - { - public: - - // Needed so that drawImage(gcn::Image *, int, int) is visible. - using Graphics::drawImage; - - /** - * Constructor. - */ - SDLGraphics(); - - /** - * Sets the target SDL_Surface to draw to. The target can be any - * SDL_Surface. This funtion also pushes a clip areas corresponding to - * the dimension of the target. - * - * @param target the target to draw to. - */ - virtual void setTarget(SDL_Surface* target); - - /** - * Gets the target SDL_Surface. - * - * @return the target SDL_Surface. - */ - virtual SDL_Surface* getTarget() const; - - /** - * Draws an SDL_Surface on the target surface. Normaly you'll - * use drawImage, but if you want to write SDL specific code - * this function might come in handy. - * - * NOTE: The clip areas will be taken into account. - */ - virtual void drawSDLSurface(SDL_Surface* surface, - SDL_Rect source, - SDL_Rect destination); - - - // Inherited from Graphics - - virtual void _beginDraw(); - - virtual void _endDraw(); - - virtual bool pushClipArea(Rectangle area); - - virtual void popClipArea(); - - virtual void drawImage(const Image* image, - int srcX, - int srcY, - int dstX, - int dstY, - int width, - int height); - - virtual void drawPoint(int x, int y); - - virtual void drawLine(int x1, int y1, int x2, int y2); - - virtual void drawRectangle(const Rectangle& rectangle); - - virtual void fillRectangle(const Rectangle& rectangle); - - virtual void setColor(const Color& color); - - virtual const Color& getColor() const; - - protected: - /** - * Draws a horizontal line. - * - * @param x1 the start coordinate of the line. - * @param y the y coordinate of the line. - * @param x2 the end coordinate of the line. - */ - virtual void drawHLine(int x1, int y, int x2); - - /** - * Draws a vertical line. - * - * @param x the x coordinate of the line. - * @param y1 the start coordinate of the line. - * @param y2 the end coordinate of the line. - */ - virtual void drawVLine(int x, int y1, int y2); - - SDL_Surface* mTarget; - Color mColor; - bool mAlpha; - }; -} - -#endif // end GCN_SDLGRAPHICS_HPP diff --git a/src/guichan/sdl/sdlimage.hpp b/src/guichan/sdl/sdlimage.hpp deleted file mode 100644 index 4d226177e..000000000 --- a/src/guichan/sdl/sdlimage.hpp +++ /dev/null @@ -1,107 +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. - */ - -#ifndef GCN_SDLIMAGE_HPP -#define GCN_SDLIMAGE_HPP - -#include "SDL.h" - -#include - -#include "guichan/color.hpp" -#include "guichan/platform.hpp" -#include "guichan/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/guichan/sdl/sdlpixel.hpp b/src/guichan/sdl/sdlpixel.hpp deleted file mode 100644 index 675b10fcd..000000000 --- a/src/guichan/sdl/sdlpixel.hpp +++ /dev/null @@ -1,281 +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. - */ - -#ifndef GCN_SDLPIXEL_HPP -#define GCN_SDLPIXEL_HPP - -#include "SDL.h" -#include "guichan/color.hpp" - -namespace gcn -{ - - /** - * Checks a pixels color of an SDL_Surface. - * - * @param surface an SDL_Surface where to check for a pixel color. - * @param x the x coordinate on the surface. - * @param y the y coordinate on the surface. - * @return a color of a pixel. - */ - inline const Color SDLgetPixel(SDL_Surface* surface, int x, int y) - { - int bpp = surface->format->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; - - default: - color = *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; - - default: - 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: - 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; - default: - break; - } - - SDL_UnlockSurface(surface); - } -} - -#endif // end GCN_SDLPIXEL_HPP diff --git a/src/guichan/selectionevent.hpp b/src/guichan/selectionevent.hpp deleted file mode 100644 index 6724fa0d2..000000000 --- a/src/guichan/selectionevent.hpp +++ /dev/null @@ -1,78 +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. - */ - -#ifndef GCN_SELECTIONEVENT_HPP -#define GCN_SELECTIONEVENT_HPP - -#include "guichan/event.hpp" -#include "guichan/platform.hpp" - -namespace gcn -{ - class Widget; - - /** - * Represents a selection event. - * - * @author Olof Naessén - * @since 0.8.0 - */ - class GCN_CORE_DECLSPEC SelectionEvent: public Event - { - public: - - /** - * Constructor. - * - * @param source source The widget of the selection event. - */ - SelectionEvent(Widget* source); - - /** - * Destructor. - */ - virtual ~SelectionEvent(); - }; -} - -#endif // end GCN_SELECTIONEVENT_HPP diff --git a/src/guichan/widget.hpp b/src/guichan/widget.hpp deleted file mode 100644 index 0f8c803ca..000000000 --- a/src/guichan/widget.hpp +++ /dev/null @@ -1,1202 +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. - */ - -#ifndef GCN_WIDGET_HPP -#define GCN_WIDGET_HPP - -#include -#include - -#include "guichan/color.hpp" -#include "guichan/rectangle.hpp" - -#ifdef __GNUC__ -#define _UNUSED_ __attribute__ ((unused)) -#else -#define _UNUSED_ -#endif - -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; - - /** - * Abstract class for widgets of Guichan. It contains basic functions - * every widget should have. - * - * NOTE: Functions begining with underscore "_" should not - * be overloaded unless you know what you are doing - * - * @author Olof Naessén - * @author Per Larsson. - * @since 0.1.0 - */ - 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 widget's dimension. - * - * @param graphics aA graphics object to draw with. - * @since 0.1.0 - */ - virtual void draw(Graphics* graphics) = 0; - - /** - * Called when a widget is given a chance to draw a frame around itself. - * The frame is not considered a part of the widget, it only allows a frame - * to be drawn around the widget, thus a frame will never be included when - * calculating if a widget should receive events from user input. Also - * a widget's frame will never be included when calculating a widget's - * position. - * - * The size of the frame is calculated using the widget's frame size. - * If a widget has a frame size of 10 pixels than the area the drawFrame - * function can draw to will be the size of the widget with an additional - * extension of 10 pixels in each direction. - * - * An example when drawFrame is a useful function is if a widget needs - * a glow around itself. - * - * @param graphics A graphics object to draw with. - * @see setFrameSize, getFrameSize - * @since 0.8.0 - */ - virtual void drawFrame(Graphics* graphics); - - /** - * Sets the size of the widget's frame. The frame is not considered a part of - * the widget, it only allows a frame to be drawn around the widget, thus a frame - * will never be included when calculating if a widget should receive events - * from user input. Also a widget's frame will never be included when calculating - * a widget's position. - * - * A frame size of 0 means that the widget has no frame. The default frame size - * is 0. - * - * @param frameSize The size of the widget's frame. - * @see getFrameSize, drawFrame - * @since 0.8.0 - */ - void setFrameSize(unsigned int frameSize); - - /** - * Gets the size of the widget's frame. The frame is not considered a part of - * the widget, it only allows a frame to be drawn around the widget, thus a frame - * will never be included when calculating if a widget should receive events - * from user input. Also a widget's frame will never be included when calculating - * a widget's position. - * - * A frame size of 0 means that the widget has no frame. The default frame size - * is 0. - * - * @return The size of the widget's frame. - * @see setFrameSize, drawFrame - * @since 0.8.0 - */ - unsigned int getFrameSize() const; - - /** - * 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::logic - * @since 0.1.0 - */ - virtual void logic() { } - - /** - * Gets the widget's parent container. - * - * @return The widget's parent container. NULL if the widget - * has no parent. - * @since 0.1.0 - */ - virtual Widget* getParent() const; - - /** - * Sets the width of the widget. - * - * @param width The width of the widget. - * @see getWidth, setHeight, getHeight, setSize, - * setDimension, getDimensi - * @since 0.1.0 - */ - void setWidth(int width); - - /** - * Gets the width of the widget. - * - * @return The width of the widget. - * @see setWidth, setHeight, getHeight, setSize, - * setDimension, getDimension - * @since 0.1.0 - */ - int getWidth() const; - - /** - * Sets the height of the widget. - * - * @param height The height of the widget. - * @see getHeight, setWidth, getWidth, setSize, - * setDimension, getDimension - * @since 0.1.0 - */ - void setHeight(int height); - - /** - * Gets the height of the widget. - * - * @return The height of the widget. - * @see setHeight, setWidth, getWidth, setSize, - * setDimension, getDimension - * @since 0.1.0 - */ - int getHeight() const; - - /** - * Sets the size of the widget. - * - * @param width The width of the widget. - * @param height The height of the widget. - * @see setWidth, setHeight, getWidth, getHeight, - * setDimension, getDimension - * @since 0.1.0 - */ - void setSize(int width, int height); - - /** - * Sets the x coordinate of the widget. The coordinate is - * relateive to the widget's parent. - * - * @param x The x coordinate of the widget. - * @see getX, setY, getY, setPosition, setDimension, getDimension - * @since 0.1.0 - */ - void setX(int x); - - /** - * Gets the x coordinate of the widget. The coordinate is - * relative to the widget's parent. - * - * @return The x coordinate of the widget. - * @see setX, setY, getY, setPosition, setDimension, getDimension - * @since 0.1.0 - */ - int getX() const; - - /** - * Sets the y coordinate of the widget. The coordinate is - * relative to the widget's parent. - * - * @param y The y coordinate of the widget. - * @see setY, setX, getX, setPosition, setDimension, getDimension - * @since 0.1.0 - */ - void setY(int y); - - /** - * Gets the y coordinate of the widget. The coordinate is - * relative to the widget's parent. - * - * @return The y coordinate of the widget. - * @see setY, setX, getX, setPosition, setDimension, getDimension - * @since 0.1.0 - */ - int getY() const; - - /** - * Sets position of the widget. The position is relative - * to the widget's parent. - * - * @param x The x coordinate of the widget. - * @param y The y coordinate of the widget. - * @see setX, getX, setY, getY, setDimension, getDimension - * @since 0.1.0 - */ - void setPosition(int x, int y); - - /** - * Sets the dimension of the widget. The dimension is - * relative to the widget's parent. - * - * @param dimension The dimension of the widget. - * @see getDimension, setX, getX, setY, getY, setPosition - * @since 0.1.0 - */ - void setDimension(const Rectangle& dimension); - - /** - * Gets the dimension of the widget. The dimension is - * relative to the widget's parent. - * - * @return The dimension of the widget. - * @see getDimension, setX, getX, setY, getY, setPosition - * @since 0.1.0 - */ - const Rectangle& getDimension() const; - - /** - * Sets the widget to be fosusable, or not. - * - * @param focusable True if the widget should be focusable, - * false otherwise. - * @see isFocusable - * @since 0.1.0 - */ - void setFocusable(bool focusable); - - /** - * Checks if a widget is focsable. - * - * @return True if the widget should be focusable, false otherwise. - * @see setFocusable - * @since 0.1.0 - */ - bool isFocusable() const; - - /** - * Checks if the widget is focused. - * - * @return True if the widget is focused, false otherwise. - * @since 0.1.0 - */ - virtual bool isFocused() const; - - /** - * Sets the widget to enabled, or not. A disabled - * widget will never recieve mouse or key events. - * - * @param enabled True if widget should be enabled, - * false otherwise. - * @see isEnabled - * @since 0.1.0 - */ - void setEnabled(bool enabled); - - /** - * Checks if the widget is enabled. A disabled - * widget will never recieve mouse or key events. - * - * @return True if widget is enabled, false otherwise. - * @see setEnabled - * @since 0.1.0 - */ - bool isEnabled() const; - - /** - * Sets the widget to be visible, or not. - * - * @param visible True if widget should be visible, false otherwise. - * @see isVisible - * @since 0.1.0 - */ - void setVisible(bool visible); - - /** - * Checks if the widget is visible. - * - * @return True if widget is be visible, false otherwise. - * @see setVisible - * @since 0.1.0 - */ - bool isVisible() const; - - /** - * Sets the base color of the widget. - * - * @param color The baseground color. - * @see getBaseColor - * @since 0.1.0 - */ - void setBaseColor(const Color& color); - - /** - * Gets the base color. - * - * @return The base color. - * @see setBaseColor - * @since 0.1.0 - */ - const Color& getBaseColor() const; - - /** - * Sets the foreground color. - * - * @param color The foreground color. - * @see getForegroundColor - * @since 0.1.0 - */ - void setForegroundColor(const Color& color); - - /** - * Gets the foreground color. - * - * @see setForegroundColor - * @since 0.1.0 - */ - const Color& getForegroundColor() const; - - /** - * Sets the background color. - * - * @param color The background Color. - * @see setBackgroundColor - * @since 0.1.0 - */ - void setBackgroundColor(const Color& color); - - /** - * Gets the background color. - * - * @see setBackgroundColor - * @since 0.1.0 - */ - const Color& getBackgroundColor() const; - - /** - * Sets the selection color. - * - * @param color The selection color. - * @see getSelectionColor - * @since 0.6.0 - */ - void setSelectionColor(const Color& color); - - /** - * Gets the selection color. - * - * @return The selection color. - * @see setSelectionColor - * @since 0.6.0 - */ - 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 focus handler 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 focus handler to use. - * @see _getFocusHandler - * @since 0.1.0 - */ - virtual void _setFocusHandler(FocusHandler* focusHandler); - - /** - * Gets the focus handler used. - * - * WARNING: This function is used internally and should not - * be called or overloaded unless you know what you - * are doing. - * - * @return The focus handler used. - * @see _setFocusHandler - * @since 0.1.0 - */ - virtual FocusHandler* _getFocusHandler(); - - /** - * Adds an action listener to the widget. When an action event - * is fired by the widget the action listeners of the widget - * will get notified. - * - * @param actionListener The action listener to add. - * @see removeActionListener - * @since 0.1.0 - */ - void addActionListener(ActionListener* actionListener); - - /** - * Removes an added action listener from the widget. - * - * @param actionListener The action listener to remove. - * @see addActionListener - * @since 0.1.0 - */ - void removeActionListener(ActionListener* actionListener); - - /** - * Adds a death listener to the widget. When a death event is - * fired by the widget the death listeners of the widget will - * get notified. - * - * @param deathListener The death listener to add. - * @see removeDeathListener - * @since 0.1.0 - */ - void addDeathListener(DeathListener* deathListener); - - /** - * Removes an added death listener from the widget. - * - * @param deathListener The death listener to remove. - * @see addDeathListener - * @since 0.1.0 - */ - void removeDeathListener(DeathListener* deathListener); - - /** - * Adds a mouse listener to the widget. When a mouse event is - * fired by the widget the mouse listeners of the widget will - * get notified. - * - * @param mouseListener The mouse listener to add. - * @see removeMouseListener - * @since 0.1.0 - */ - void addMouseListener(MouseListener* mouseListener); - - /** - * Removes an added mouse listener from the widget. - * - * @param mouseListener The mouse listener to remove. - * @see addMouseListener - * @since 0.1.0 - */ - void removeMouseListener(MouseListener* mouseListener); - - /** - * Adds a key listener to the widget. When a key event is - * fired by the widget the key listeners of the widget will - * get notified. - * - * @param keyListener The key listener to add. - * @see removeKeyListener - * @since 0.1.0 - */ - void addKeyListener(KeyListener* keyListener); - - /** - * Removes an added key listener from the widget. - * - * @param keyListener The key listener to remove. - * @see addKeyListener - * @since 0.1.0 - */ - void removeKeyListener(KeyListener* keyListener); - - /** - * Adds a focus listener to the widget. When a focus event is - * fired by the widget the key listeners of the widget will - * get notified. - * - * @param focusListener The focus listener to add. - * @see removeFocusListener - * @since 0.7.0 - */ - void addFocusListener(FocusListener* focusListener); - - /** - * Removes an added focus listener from the widget. - * - * @param focusListener The focus listener to remove. - * @see addFocusListener - * @since 0.7.0 - */ - void removeFocusListener(FocusListener* focusListener); - - /** - * Adds a widget listener to the widget. When a widget event is - * fired by the widget the key listeners of the widget will - * get notified. - * - * @param widgetListener The widget listener to add. - * @see removeWidgetListener - * @since 0.8.0 - */ - void addWidgetListener(WidgetListener* widgetListener); - - /** - * Removes an added widget listener from the widget. - * - * @param widgetListener The widget listener to remove. - * @see addWidgetListener - * @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. - * @see getActionEventId - * @since 0.6.0 - */ - void setActionEventId(const std::string& actionEventId); - - /** - * Gets the action event identifier of the widget. - * - * @return The action event identifier of the widget. - * @see setActionEventId - * @since 0.6.0 - */ - const std::string& getActionEventId() const; - - /** - * Gets the absolute position on the screen for the widget. - * - * @param x The absolute x coordinate will be stored in this parameter. - * @param y The absolute y coordinate will be stored in this parameter. - * @since 0.1.0 - */ - 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 of the widget. - * @see getParent - * @since 0.1.0 - */ - virtual void _setParent(Widget* parent); - - /** - * Gets the font set for the widget. If no font has been set, - * the global font will be returned. If no global font has been set, - * the default font will be returend. - * - * @return The font set for the widget. - * @see setFont, setGlobalFont - * @since 0.1.0 - */ - Font *getFont() const; - - /** - * Sets the global font to be used by default for all widgets. - * - * @param font The global font. - * @see getGlobalFont - * @since 0.1.0 - */ - static void setGlobalFont(Font* font); - - /** - * Sets the font for the widget. If NULL is passed, the global font - * will be used. - * - * @param font The font to set for the widget. - * @see getFont - * @since 0.1.0 - */ - void setFont(Font* font); - - /** - * Called when the font has changed. If the change is global, - * this function will only be called if the widget doesn't have a - * font already set. - * - * @since 0.1.0 - */ - virtual void fontChanged() { } - - /** - * Checks if a widget exists or not, that is if it still exists - * an instance of the object. - * - * @param widget The widget to check. - * @return True if an instance of the widget exists, false otherwise. - * @since 0.1.0 - */ - static bool widgetExists(const Widget* widget); - - /** - * Checks 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 focus handler will skip this widget and focus the next - * in its focus order. - * - * @return True if tab in is enabled, false otherwise. - * @see setTabInEnabled - * @since 0.1.0 - */ - bool isTabInEnabled() const; - - /** - * Sets tab in enabled, or not. 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, false otherwise. - * @see isTabInEnabled - * @since 0.1.0 - */ - 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, false otherwise. - * @see setTabOutEnabled - * @since 0.1.0 - */ - 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, false otherwise. - * @see isTabOutEnabled - * @since 0.1.0 - */ - 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. - * @see releaseModalFocus, isModalFocused - * @since 0.4.0 - */ - 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. - * @see releaseModalMouseInputFocus, isModalMouseInputFocused - * @since 0.6.0 - */ - virtual void requestModalMouseInputFocus(); - - /** - * Releases modal focus. Modal focus will only be released if the - * widget has modal focus. - * - * @see requestModalFocus, isModalFocused - * @since 0.4.0 - */ - virtual void releaseModalFocus(); - - /** - * Releases modal mouse input focus. Modal mouse input focus will only - * be released if the widget has modal mouse input focus. - * - * @see requestModalMouseInputFocus, isModalMouseInputFocused - * @since 0.6.0 - */ - virtual void releaseModalMouseInputFocus(); - - /** - * Checks if the widget or it's parent has modal focus. - * - * @return True if the widget has modal focus, false otherwise. - * @see requestModalFocus, releaseModalFocus - * @since 0.8.0 - */ - virtual bool isModalFocused() const; - - /** - * Checks if the widget or it's parent has modal mouse input focus. - * - * @return True if the widget has modal mouse input focus, false - * otherwise. - * @see requestModalMouseInputFocus, releaseModalMouseInputFocus - * @since 0.8.0 - */ - virtual bool isModalMouseInputFocused() 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 of the widget to get. - * @param y The y coordinate of the widget to get. - * @return The widget at the specified coodinate, NULL - * if no widget is found. - * @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 area of the widget occupied by the widget's children. - * By default this method returns an empty rectangle as not all - * widgets are containers. If you want to make a container this - * method should return the area where the children resides. This - * method is used when drawing children of a widget when computing - * clip rectangles for the children. - * - * An example of a widget that overloads this method is ScrollArea. - * A ScrollArea has a view of its contant and that view is the - * children area. The size of a ScrollArea's children area might - * vary depending on if the scroll bars of the ScrollArea is shown - * or not. - * - * @return The area of the widget occupied by the widget's children. - * @see BasicContainer - * @see BasicContainer::getChildrenArea - * @see BasicContainer::drawChildren - * @since 0.1.0 - */ - virtual Rectangle getChildrenArea(); - - /** - * Gets the internal focus handler used. - * - * @return the internalFocusHandler used. If no internal focus handler - * is used, NULL will be returned. - * @see setInternalFocusHandler - * @since 0.1.0 - */ - virtual FocusHandler* _getInternalFocusHandler(); - - /** - * Sets the internal focus handler. An internal focus handler is - * needed if both a widget in the widget and the widget itself - * should be foucsed at the same time. - * - * @param focusHandler The internal focus handler to be used. - * @see getInternalFocusHandler - * @since 0.1.0 - */ - void setInternalFocusHandler(FocusHandler* internalFocusHandler); - - /** - * 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 to the top. - * @see moveToBottom - * @since 0.1.0 - */ - virtual void moveToTop(Widget* widget _UNUSED_) { }; - - /** - * 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 to the bottom. - * @see moveToTop - * @since 0.1.0 - */ - virtual void moveToBottom(Widget* widget _UNUSED_) { }; - - /** - * Focuses the next widget in the widget. - * - * @see moveToBottom - * @since 0.1.0 - */ - virtual void focusNext() { }; - - /** - * Focuses the previous widget in the widget. - * - * @see moveToBottom - * @since 0.1.0 - */ - 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. - * @since 0.1.0 - */ - virtual void showWidgetPart(Widget* widget _UNUSED_, - Rectangle area _UNUSED_) - { }; - - /** - * 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 getId, BasicContainer::findWidgetById - * @since 0.8.0 - */ - 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 setId, BasicContainer::findWidgetById - * @since 0.8.0 - */ - const std::string& getId(); - - /** - * Shows a certain part of a widget in the widget's parent. - * Used when widgets want a specific part to be visible in - * its parent. An example is a TextArea that wants a specific - * part of its text to be visible when a TextArea is a child - * of a ScrollArea. - * - * @param rectangle The rectangle to be shown. - * @since 0.8.0 - */ - virtual void showPart(Rectangle rectangle); - - protected: - /** - * Distributes an action event to all action listeners - * of the widget. - * - * @since 0.8.0 - */ - void distributeActionEvent(); - - /** - * Distributes resized events to all of the widget's listeners. - * - * @since 0.8.0 - */ - void distributeResizedEvent(); - - /** - * Distributes moved events to all of the widget's listeners. - * - * @since 0.8.0 - */ - 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(); - - /** - * Typdef. - */ - typedef std::list MouseListenerList; - - /** - * Typdef. - */ - typedef MouseListenerList::iterator MouseListenerIterator; - - /** - * Holds the mouse listeners of the widget. - */ - MouseListenerList mMouseListeners; - - /** - * Typdef. - */ - typedef std::list KeyListenerList; - - /** - * Holds the key listeners of the widget. - */ - KeyListenerList mKeyListeners; - - /** - * Typdef. - */ - typedef KeyListenerList::iterator KeyListenerIterator; - - /** - * Typdef. - */ - typedef std::list ActionListenerList; - - /** - * Holds the action listeners of the widget. - */ - ActionListenerList mActionListeners; - - /** - * Typdef. - */ - typedef ActionListenerList::iterator ActionListenerIterator; - - /** - * Typdef. - */ - typedef std::list DeathListenerList; - - /** - * Holds the death listeners of the widget. - */ - DeathListenerList mDeathListeners; - - /** - * Typdef. - */ - typedef DeathListenerList::iterator DeathListenerIterator; - - /** - * Typdef. - */ - typedef std::list FocusListenerList; - - /** - * Holds the focus listeners of the widget. - */ - FocusListenerList mFocusListeners; - - /** - * Typdef. - */ - typedef FocusListenerList::iterator FocusListenerIterator; - - typedef std::list WidgetListenerList; - - /** - * Holds the widget listeners of the widget. - */ - WidgetListenerList mWidgetListeners; - - /** - * Typdef. - */ - typedef WidgetListenerList::iterator WidgetListenerIterator; - - /** - * Holds the foreground color of the widget. - */ - Color mForegroundColor; - - /** - * Holds the background color of the widget. - */ - Color mBackgroundColor; - - /** - * Holds the base color of the widget. - */ - Color mBaseColor; - - /** - * Holds the selection color of the widget. - */ - Color mSelectionColor; - - /** - * Holds the focus handler used by the widget. - */ - FocusHandler* mFocusHandler; - - /** - * Holds the focus handler used by the widget. NULL - * if no internal focus handler is used. - */ - FocusHandler* mInternalFocusHandler; - - /** - * Holds the parent of the widget. NULL if the widget - * has no parent. - */ - Widget* mParent; - - /** - * Holds the dimension of the widget. - */ - Rectangle mDimension; - - /** - * Holds the frame size of the widget. - */ - unsigned int mFrameSize; - - /** - * Holds the action event of the widget. - */ - std::string mActionEventId; - - /** - * True if the widget focusable, false otherwise. - */ - bool mFocusable; - - /** - * True if the widget visible, false otherwise. - */ - bool mVisible; - - /** - * True if the widget has tab in enabled, false otherwise. - */ - bool mTabIn; - - /** - * True if the widget has tab in enabled, false otherwise. - */ - bool mTabOut; - - /** - * True if the widget is enabled, false otherwise. - */ - bool mEnabled; - - /** - * Holds the id of the widget. - */ - std::string mId; - - /** - * Holds the font used by the widget. - */ - Font* mCurrentFont; - - /** - * Holds the default font used by the widget. - */ - static DefaultFont mDefaultFont; - - /** - * Holds the global font used by the widget. - */ - static Font* mGlobalFont; - - /** - * Holds a list of all instances of widgets. - */ - static std::list mWidgets; - }; -} - -#endif // end GCN_WIDGET_HPP diff --git a/src/guichan/widgetlistener.hpp b/src/guichan/widgetlistener.hpp deleted file mode 100644 index eb1f838ec..000000000 --- a/src/guichan/widgetlistener.hpp +++ /dev/null @@ -1,124 +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. - */ - -#ifndef GCN_WIDGETLISTENER_HPP -#define GCN_WIDGETLISTENER_HPP - -#include - -#include "guichan/event.hpp" -#include "guichan/platform.hpp" - -#ifdef __GNUC__ -#define _UNUSED_ __attribute__ ((unused)) -#else -#define _UNUSED_ -#endif - -namespace gcn -{ - /** - * Interface for listening for events from widgets. When a widget's size, - * location or visibility changes, the relevant method of the listener is - * invoked. - * - * @see Widget::addWidgetListener, Widget::removeWidgetListener - * @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 _UNUSED_) { } - - /** - * Invoked when a widget is moved. - * - * @param event Describes the event. - * @since 0.8.0 - */ - virtual void widgetMoved(const Event& event _UNUSED_) { } - - /** - * 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 _UNUSED_) { } - - /** - * 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 _UNUSED_) { } - - protected: - /** - * Constructor. - * - * You should not be able to make an instance of WidgetListener, - * therefore its constructor is protected. - */ - WidgetListener() { } - - }; -} - -#endif // end GCN_WIDGETLISTENER_HPP diff --git a/src/guichan/widgets/button.hpp b/src/guichan/widgets/button.hpp deleted file mode 100644 index 05b961b1e..000000000 --- a/src/guichan/widgets/button.hpp +++ /dev/null @@ -1,220 +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. - */ - -#ifndef GCN_BUTTON_HPP -#define GCN_BUTTON_HPP - -#include - -#include "guichan/focuslistener.hpp" -#include "guichan/graphics.hpp" -#include "guichan/keylistener.hpp" -#include "guichan/mouseevent.hpp" -#include "guichan/mouselistener.hpp" -#include "guichan/platform.hpp" -#include "guichan/widget.hpp" - -#ifdef __GNUC__ -#define _UNUSED_ __attribute__ ((unused)) -#else -#define _UNUSED_ -#endif - -namespace gcn -{ - /** - * An implementation of a regular clickable button. A button is capable of - * displaying a caption. - * - * If a button is clicked an action event will be sent to all action listener's - * of the button. - * - * @see ImageButton - */ - class GCN_CORE_DECLSPEC Button : public Widget, - public MouseListener, - public KeyListener, - public FocusListener - { - public: - /** - * Constructor. - */ - Button(); - - /** - * Constructor. The button will be automatically resized - * to fit the caption. - * - * @param caption The caption of the button. - */ - Button(const std::string& caption); - - /** - * Sets the caption of the button. It's advisable to call - * adjustSize after setting of the caption to adjust the - * button's size to fit the caption. - * - * @param caption The caption of the button. - * @see getCaption, adjustSize - */ - void setCaption(const std::string& caption); - - /** - * Gets the caption of the button. - * - * @return The caption of the button. - */ - const std::string& getCaption() const; - - /** - * Sets the alignment of the caption. The alignment is relative - * to the center of the button. - * - * @param alignment The alignment of the caption. - * @see getAlignment, Graphics - */ - void setAlignment(Graphics::Alignment alignment); - - /** - * Gets the alignment of the caption. - * - * @return The alignment of the caption. - * @see setAlignment, Graphics - */ - Graphics::Alignment getAlignment() const; - - /** - * Sets the spacing between the border of the button and its caption. - * - * @param spacing The default value for spacing is 4 and can be changed - * using this method. - * @see getSpacing - */ - void setSpacing(unsigned int spacing); - - /** - * Gets the spacing between the border of the button and its caption. - * - * @return spacing. - * @see setSpacing - */ - unsigned int getSpacing() const; - - /** - * Adjusts the button's size to fit the caption. - */ - void adjustSize(); - - - //Inherited from Widget - - virtual void draw(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: - /** - * Checks if the button is pressed. Convenient method to use - * when overloading the draw method of the button. - * - * @return True if the button is pressed, false otherwise. - */ - bool isPressed() const; - - /** - * Holds the caption of the button. - */ - std::string mCaption; - - /** - * True if the mouse is ontop of the button, false otherwise. - */ - bool mHasMouse; - - /** - * True if a key has been pressed, false otherwise. - */ - bool mKeyPressed; - - /** - * True if a mouse has been pressed, false otherwise. - */ - bool mMousePressed; - - /** - * Holds the alignment of the caption. - */ - Graphics::Alignment mAlignment; - - /** - * Holds the spacing between the border and the caption. - */ - unsigned int mSpacing; - }; -} - -#endif // end GCN_BUTTON_HPP diff --git a/src/guichan/widgets/checkbox.hpp b/src/guichan/widgets/checkbox.hpp deleted file mode 100644 index ad43e2896..000000000 --- a/src/guichan/widgets/checkbox.hpp +++ /dev/null @@ -1,173 +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. - */ - -#ifndef GCN_CHECKBOX_HPP -#define GCN_CHECKBOX_HPP - -#include - -#include "guichan/keylistener.hpp" -#include "guichan/mouselistener.hpp" -#include "guichan/platform.hpp" -#include "guichan/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 the 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 or not. - * - * @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); - - - // 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/guichan/widgets/container.hpp b/src/guichan/widgets/container.hpp deleted file mode 100644 index 4946b1f74..000000000 --- a/src/guichan/widgets/container.hpp +++ /dev/null @@ -1,162 +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. - */ - -#ifndef GCN_CONTAINER_HPP -#define GCN_CONTAINER_HPP - -#include - -#include "guichan/basiccontainer.hpp" -#include "guichan/graphics.hpp" -#include "guichan/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 its background will be drawn, if it's not opaque - * its 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 its 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 specifies the widget's - * position 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 coordinate for the widget. - * @param y The y coordinate 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); - - protected: - /** - * True if the container is opaque, false otherwise. - */ - bool mOpaque; - }; -} - -#endif // end GCN_CONTAINER_HPP diff --git a/src/guichan/widgets/dropdown.hpp b/src/guichan/widgets/dropdown.hpp deleted file mode 100644 index 5853783e5..000000000 --- a/src/guichan/widgets/dropdown.hpp +++ /dev/null @@ -1,325 +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. - */ - -#ifndef GCN_DROPDOWN_HPP -#define GCN_DROPDOWN_HPP - -#include "guichan/actionlistener.hpp" -#include "guichan/basiccontainer.hpp" -#include "guichan/deathlistener.hpp" -#include "guichan/focushandler.hpp" -#include "guichan/focuslistener.hpp" -#include "guichan/keylistener.hpp" -#include "guichan/listmodel.hpp" -#include "guichan/mouselistener.hpp" -#include "guichan/platform.hpp" -#include "guichan/selectionlistener.hpp" -#include "guichan/widgets/listbox.hpp" -#include "guichan/widgets/scrollarea.hpp" - -#ifdef __GNUC__ -#define _UNUSED_ __attribute__ ((unused)) -#else -#define _UNUSED_ -#endif - -namespace gcn -{ - /** - * An implementation of a drop downable list from which an item can be - * selected. The drop down consists of an internal ScrollArea and an - * internal ListBox. The drop down also uses an internal FocusHandler to - * handle the focus of the internal ScollArea and the internal ListBox. The - * scroll area and the list box can be passed to the drop down if a custom - * scroll area and or a custom list box is preferable. - * - * To be able display a list the drop down uses a user provided list model. - * A list model can be any class that implements the ListModel interface. - * - * If an item is selected in the drop down a select event will be sent to - * all selection listeners of the drop down. If an item is selected by - * using a mouse click or by using the enter or space key an action event - * will be sent to all action listeners of the drop down. - */ - class GCN_CORE_DECLSPEC DropDown : - public ActionListener, - public BasicContainer, - public KeyListener, - public MouseListener, - public FocusListener, - public SelectionListener - { - public: - /** - * Contructor. - * - * @param listModel the ListModel to use. - * @param scrollArea the ScrollArea to use. - * @param listBox the listBox to use. - * @see ListModel, ScrollArea, ListBox. - */ - DropDown(ListModel *listModel = NULL, - ScrollArea *scrollArea = NULL, - ListBox *listBox = NULL); - - /** - * Destructor. - */ - virtual ~DropDown(); - - /** - * Gets the selected item as an index in the list model. - * - * @return the selected item as an index in the list model. - * @see setSelected - */ - int getSelected() const; - - /** - * Sets the selected item. The selected item is represented by - * an index from the list model. - * - * @param selected the selected item as an index from the list model. - * @see getSelected - */ - void setSelected(int selected); - - /** - * Sets the list model to use when displaying the list. - * - * @param listModel the list model to use. - * @see getListModel - */ - void setListModel(ListModel *listModel); - - /** - * Gets the list model used. - * - * @return the ListModel used. - * @see setListModel - */ - ListModel *getListModel(); - - /** - * Adjusts the height of the drop down to fit the height of the - * drop down's parent's height. It's used to not make the drop down - * draw itself outside of it's parent if folded down. - */ - void adjustHeight(); - - /** - * Adds a selection listener to the drop down. When the selection - * changes an event will be sent to all selection listeners of the - * drop down. - * - * If you delete your selection listener, be sure to also remove it - * using removeSelectionListener(). - * - * @param listener the selection listener to add. - * @since 0.8.0 - */ - void addSelectionListener(SelectionListener* listener); - - /** - * Removes a selection listener from the drop down. - * - * @param selectionListener the selection listener to remove. - * @since 0.8.0 - */ - void removeSelectionListener(SelectionListener* selectionListener); - - - // Inherited from Widget - - virtual void draw(Graphics* graphics); - - void setBaseColor(const Color& color); - - void setBackgroundColor(const Color& color); - - void setForegroundColor(const Color& color); - - void setFont(Font *font); - - void setSelectionColor(const Color& color); - - - // Inherited from BasicContainer - - virtual Rectangle getChildrenArea(); - - - // Inherited from FocusListener - - virtual void focusLost(const Event& event); - - - // Inherited from ActionListener - - virtual 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); - - virtual void mouseReleased(MouseEvent& mouseEvent); - - virtual void mouseWheelMovedUp(MouseEvent& mouseEvent); - - virtual void mouseWheelMovedDown(MouseEvent& mouseEvent); - - virtual void mouseDragged(MouseEvent& mouseEvent); - - - // Inherited from SelectionListener - - virtual void valueChanged(const SelectionEvent& event); - - protected: - /** - * Draws the button of the drop down. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawButton(Graphics *graphics); - - /** - * Sets the drop down to be dropped down. - */ - virtual void dropDown(); - - /** - * Sets the drop down to be folded up. - */ - virtual void foldUp(); - - /** - * Distributes a value changed event to all selection listeners - * of the drop down. - * - * @since 0.8.0 - */ - void distributeValueChangedEvent(); - - /** - * True if the drop down is dropped down, false otherwise. - */ - bool mDroppedDown; - - /** - * True if the drop down has been pushed with the mouse, false - * otherwise. - */ - bool mPushed; - - /** - * Holds what the height is if the drop down is folded up. Used when - * checking if the list of the drop down was clicked or if the upper - * part of the drop down was clicked on a mouse click. - */ - int mFoldedUpHeight; - - /** - * The scroll area used. - */ - ScrollArea* mScrollArea; - - /** - * The list box used. - */ - ListBox* mListBox; - - /** - * The internal focus handler used to keep track of focus for the - * internal list box. - */ - FocusHandler mInternalFocusHandler; - - /** - * True if an internal scroll area is used, false if a scroll area - * has been passed to the drop down which the drop down should not - * deleted in it's destructor. - */ - bool mInternalScrollArea; - - /** - * True if an internal list box is used, false if a list box - * has been passed to the drop down which the drop down should not - * deleted in it's destructor. - */ - bool mInternalListBox; - - /** - * True if the drop down is dragged. - */ - bool mIsDragged; - - /** - * Typedef. - */ - typedef std::list SelectionListenerList; - - /** - * The selection listener's of the drop down. - */ - SelectionListenerList mSelectionListeners; - - /** - * Typedef. - */ - typedef SelectionListenerList::iterator SelectionListenerIterator; - }; -} - -#endif // end GCN_DROPDOWN_HPP diff --git a/src/guichan/widgets/icon.hpp b/src/guichan/widgets/icon.hpp deleted file mode 100644 index f0f9ff566..000000000 --- a/src/guichan/widgets/icon.hpp +++ /dev/null @@ -1,118 +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. - */ - -#ifndef GCN_ICON_HPP -#define GCN_ICON_HPP - -#include "guichan/image.hpp" -#include "guichan/platform.hpp" -#include "guichan/widget.hpp" - -namespace gcn -{ - /** - * Implements an icon capable of displaying an image. - */ - class GCN_CORE_DECLSPEC Icon: public Widget - { - public: - /** - * Default constructor. - */ - Icon(); - - /** - * Constructor. - * - * @param filename The filename of the image to display. - */ - Icon(const std::string& filename); - - /** - * Constructor. - * - * @param image The image to display. - */ - Icon(const Image* image); - - /** - * Descructor. - */ - virtual ~Icon(); - - /** - * Sets the image to display. Existing image is freed automatically - * if it was loaded internally. - * - * @param image The image to display. - */ - void setImage(const Image* image); - - /** - * Gets the current image. - * - * @return The current image. - */ - const Image* getImage() const; - - - // Inherited from Widget - - virtual void draw(Graphics* graphics); - - protected: - /** - * The image to display. - */ - const Image* mImage; - - /** - * True if the image has been loaded internally, false otherwise. - * An image not loaded internally should not be deleted in the - * destructor. - */ - bool mInternalImage; - }; -} - -#endif // end GCN_ICON_HPP diff --git a/src/guichan/widgets/imagebutton.hpp b/src/guichan/widgets/imagebutton.hpp deleted file mode 100644 index 1ab285ce9..000000000 --- a/src/guichan/widgets/imagebutton.hpp +++ /dev/null @@ -1,123 +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. - */ - -#ifndef GCN_IMAGEBUTTON_HPP -#define GCN_IMAGEBUTTON_HPP - -#include "guichan/platform.hpp" -#include "guichan/widgets/button.hpp" - -namespace gcn -{ - class Image; - - /** - * An implementation of a regular clickable button. Unlike a normal button an image - * button is capable of displaying an image instead of a simple text caption. - * Whenever an image button is clicked an action event will be sent to the action - * listener's of the image button. - * - * @see Button - */ - class GCN_CORE_DECLSPEC ImageButton : public gcn::Button - { - public: - /** - * Default constructor. - */ - ImageButton(); - - /** - * Constructor. - * - * @param filename The filename of the image to display. - */ - ImageButton(const std::string& filename); - - /** - * Constructor. - * - * @param image The image to display. - */ - ImageButton(const Image* image); - - /** - * Destructor. - */ - virtual ~ImageButton(); - - /** - * Sets the image to display. Existing Image is freed automatically, - * if it was loaded internally. - * - * @param image The image to display. - */ - void setImage(const Image* image); - - /** - * Gets current image. - * - * @return The current image. - */ - const Image* getImage() const; - - - // Inherited from Widget - - void draw(gcn::Graphics* graphics); - - protected: - /** - * The image to display. - */ - const Image* mImage; - - /** - * True if the image has been loaded internally, false otherwise. - * An image not loaded internally should not be deleted in the - * destructor. - */ - bool mInternalImage; - }; -} -#endif diff --git a/src/guichan/widgets/label.hpp b/src/guichan/widgets/label.hpp deleted file mode 100644 index 4d6ea0006..000000000 --- a/src/guichan/widgets/label.hpp +++ /dev/null @@ -1,133 +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. - */ - -#ifndef GCN_LABEL_HPP -#define GCN_LABEL_HPP - -#include - -#include "guichan/graphics.hpp" -#include "guichan/platform.hpp" -#include "guichan/widget.hpp" - -namespace gcn -{ - /** - * Implementation of a label capable of displaying a caption. - */ - class GCN_CORE_DECLSPEC Label: public Widget - { - public: - /** - * Constructor. - */ - Label(); - - /** - * Constructor. The label will be automatically resized - * to fit the caption. - * - * @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 of the caption. The alignment is relative - * to the center of the label. - * - * @param alignemnt The alignment of the caption of the label. - * @see getAlignment, Graphics - */ - void setAlignment(Graphics::Alignment alignment); - - /** - * Gets the alignment of the caption. The alignment is relative to - * the center of the label. - * - * @return The alignment of caption of the label. - * @see setAlignmentm Graphics - */ - Graphics::Alignment getAlignment() const; - - /** - * Adjusts the label's size to fit the caption. - */ - void adjustSize(); - - - // Inherited from Widget - - virtual void draw(Graphics* graphics); - - protected: - /** - * Holds the caption of the label. - */ - std::string mCaption; - - /** - * Holds the alignment of the caption. - */ - Graphics::Alignment mAlignment; - }; -} - -#endif // end GCN_LABEL_HPP diff --git a/src/guichan/widgets/listbox.hpp b/src/guichan/widgets/listbox.hpp deleted file mode 100644 index b99f84aaa..000000000 --- a/src/guichan/widgets/listbox.hpp +++ /dev/null @@ -1,253 +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. - */ - -#ifndef GCN_LISTBOX_HPP -#define GCN_LISTBOX_HPP - -#include - -#include "guichan/keylistener.hpp" -#include "guichan/listmodel.hpp" -#include "guichan/mouselistener.hpp" -#include "guichan/platform.hpp" -#include "guichan/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. - * - * If you delete your selection listener, be sure to also remove it - * using removeSelectionListener(). - * - * @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); - - /** - * Gets the height of a row. Should be overridden if another row - * height than the font height is preferred. - * - * @return The height of a row. - * @since 0.8.0 - */ - virtual unsigned int getRowHeight() const; - - - // Inherited from Widget - - virtual void draw(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 selected item as an index in the list model. - */ - int mSelected; - - /** - * The list model to use. - */ - ListModel *mListModel; - - /** - * True if wrapping is enabled, false otherwise. - */ - bool mWrappingEnabled; - - /** - * 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/guichan/widgets/radiobutton.hpp b/src/guichan/widgets/radiobutton.hpp deleted file mode 100644 index 0fb5b4123..000000000 --- a/src/guichan/widgets/radiobutton.hpp +++ /dev/null @@ -1,211 +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. - */ - -#ifndef GCN_RADIOBUTTON_HPP -#define GCN_RADIOBUTTON_HPP - -#include -#include - -#include "guichan/keylistener.hpp" -#include "guichan/mouselistener.hpp" -#include "guichan/platform.hpp" -#include "guichan/widget.hpp" - -namespace gcn -{ - /** - * An 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. The radio button will be automatically resized - * to fit the caption. - * - * @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); - - - // 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/guichan/widgets/scrollarea.hpp b/src/guichan/widgets/scrollarea.hpp deleted file mode 100644 index 0b2ccad92..000000000 --- a/src/guichan/widgets/scrollarea.hpp +++ /dev/null @@ -1,590 +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. - */ - -#ifndef GCN_SCROLLAREA_HPP -#define GCN_SCROLLAREA_HPP - -#include - -#include "guichan/basiccontainer.hpp" -#include "guichan/mouselistener.hpp" -#include "guichan/platform.hpp" - -namespace gcn -{ - /** - * Implementation if a scrollable area used to view widgets larger than the scroll area. - * A scroll area can be customized to always show scroll bars or to show them only when - * necessary. - */ - class GCN_CORE_DECLSPEC ScrollArea: - public BasicContainer, - public MouseListener - { - public: - - /** - * 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 ScrollPolicy - { - SHOW_ALWAYS = 0, - SHOW_NEVER, - SHOW_AUTO - }; - - /** - * Constructor. - */ - ScrollArea(); - - /** - * Constructor. - * - * @param content The content of the scroll area. - */ - ScrollArea(Widget *content); - - /** - * Constructor. - * - * @param content The content of the scroll area. - * @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, - ScrollPolicy hPolicy, - ScrollPolicy vPolicy); - - /** - * Destructor. - */ - virtual ~ScrollArea(); - - /** - * Sets the content. - * - * @param widget The content of the scroll area. - */ - void setContent(Widget* widget); - - /** - * Gets the content. - * - * @return The content of the scroll area. - */ - Widget* getContent(); - - /** - * Sets the horizontal scrollbar policy. See enum with policies. - * - * @param hPolicy The policy for the horizontal scrollbar. - * @see getHorizontalScrollPolicy - */ - void setHorizontalScrollPolicy(ScrollPolicy hPolicy); - - /** - * Gets the horizontal scrollbar policy. See enum with policies. - * - * @return The policy for the horizontal scrollbar policy. - * @see setHorizontalScrollPolicy, setScrollPolicy - */ - ScrollPolicy getHorizontalScrollPolicy() const; - - /** - * Sets the vertical scrollbar policy. See enum with policies. - * - * @param vPolicy The policy for the vertical scrollbar. - * @see getVerticalScrollPolicy - */ - void setVerticalScrollPolicy(ScrollPolicy vPolicy); - - /** - * Gets the vertical scrollbar policy. See enum with policies. - * - * @return The policy for the vertical scrollbar. - * @see setVerticalScrollPolicy, setScrollPolicy - */ - ScrollPolicy getVerticalScrollPolicy() const; - - /** - * Sets the horizontal and vertical scrollbar policy. - * - * @param hPolicy The policy for the horizontal scrollbar. - * @param vPolicy The policy for the vertical scrollbar. - * @see getVerticalScrollPolicy, getHorizontalScrollPolicy - */ - void setScrollPolicy(ScrollPolicy hPolicy, ScrollPolicy vPolicy); - - /** - * Sets the amount to scroll vertically. - * - * @param vScroll The amount to scroll. - * @see getVerticalScrollAmount - */ - void setVerticalScrollAmount(int vScroll); - - /** - * Gets the amount that is scrolled vertically. - * - * @return The scroll amount on vertical scroll. - * @see setVerticalScrollAmount, setScrollAmount - */ - int getVerticalScrollAmount() const; - - /** - * Sets the amount to scroll horizontally. - * - * @param hScroll The amount to scroll. - * @see getHorizontalScrollAmount - */ - void setHorizontalScrollAmount(int hScroll); - - /** - * Gets the amount that is scrolled horizontally. - * - * @return The scroll amount on horizontal scroll. - * @see setHorizontalScrollAmount, setScrollAmount - */ - 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. - * @see getHorizontalScrollAmount, getVerticalScrollAmount - */ - 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 of the scroll bars. - * - * @param width The width of the scroll bars. - * @see getScrollbarWidth - */ - void setScrollbarWidth(int width); - - /** - * Gets the width of the scroll bars. - * - * @return the width of the ScrollBar. - * @see setScrollbarWidth - */ - int getScrollbarWidth() const; - - /** - * Sets the amount to scroll in pixels when the left scroll button is - * pushed. - * - * @param amount The amount to scroll in pixels. - * @see getLeftButtonScrollAmount - */ - void setLeftButtonScrollAmount(int amount); - - /** - * Sets the amount to scroll in pixels when the right scroll button is - * pushed. - * - * @param amount The amount to scroll in pixels. - * @see getRightButtonScrollAmount - */ - void setRightButtonScrollAmount(int amount); - - /** - * Sets the amount to scroll in pixels when the up scroll button is - * pushed. - * - * @param amount The amount to scroll in pixels. - * @see getUpButtonScrollAmount - */ - void setUpButtonScrollAmount(int amount); - - /** - * Sets the amount to scroll in pixels when the down scroll button is - * pushed. - * - * @param amount The amount to scroll in pixels. - * @see getDownButtonScrollAmount - */ - void setDownButtonScrollAmount(int amount); - - /** - * Gets the amount to scroll in pixels when the left scroll button is - * pushed. - * - * @return The amount to scroll in pixels. - * @see setLeftButtonScrollAmount - */ - int getLeftButtonScrollAmount() const; - - /** - * Gets the amount to scroll in pixels when the right scroll button is - * pushed. - * - * @return The amount to scroll in pixels. - * @see setRightButtonScrollAmount - */ - int getRightButtonScrollAmount() const; - - /** - * Gets the amount to scroll in pixels when the up scroll button is - * pushed. - * - * @return The amount to scroll in pixels. - * @see setUpButtonScrollAmount - */ - int getUpButtonScrollAmount() const; - - /** - * Gets the amount to scroll in pixels when the down scroll button is - * pushed. - * - * @return The amount to scroll in pixels. - * @see setDownButtonScrollAmount - */ - int getDownButtonScrollAmount() const; - - /** - * Sets the scroll area to be opaque, that is sets the scoll area - * to display its background. - * - * @param opaque True if the scoll area should be opaque, false otherwise. - */ - void setOpaque(bool opaque); - - /** - * Checks if the scroll area is opaque, that is if the scroll area - * displays its background. - * - * @return True if the scroll area is opaque, false otherwise. - */ - bool isOpaque() 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 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); - - protected: - /** - * Draws the background of the scroll area, that is - * 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 scroll bar. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawVBar(Graphics* graphics); - - /** - * Draws the horizontal scroll bar. - * - * @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 scroll bars. - */ - 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(); - - /** - * Holds the vertical scroll amount. - */ - int mVScroll; - - /** - * Holds the horizontal scroll amount. - */ - int mHScroll; - - /** - * Holds the width of the scroll bars. - */ - int mScrollbarWidth; - - /** - * Holds the horizontal scroll bar policy. - */ - ScrollPolicy mHPolicy; - - /** - * Holds the vertical scroll bar policy. - */ - ScrollPolicy mVPolicy; - - /** - * True if the vertical scroll bar is visible, false otherwise. - */ - bool mVBarVisible; - - /** - * True if the horizontal scroll bar is visible, false otherwise. - */ - bool mHBarVisible; - - /** - * True if the up button is pressed, false otherwise. - */ - bool mUpButtonPressed; - - /** - * True if the down button is pressed, false otherwise. - */ - bool mDownButtonPressed; - - /** - * True if the left button is pressed, false otherwise. - */ - bool mLeftButtonPressed; - - /** - * True if the right button is pressed, false otherwise. - */ - bool mRightButtonPressed; - - /** - * Holds the up button scroll amount. - */ - int mUpButtonScrollAmount; - - /** - * Holds the down button scroll amount. - */ - int mDownButtonScrollAmount; - - /** - * Holds the left button scroll amount. - */ - int mLeftButtonScrollAmount; - - /** - * Holds the right button scroll amount. - */ - int mRightButtonScrollAmount; - - /** - * True if the vertical marked is dragged. - */ - bool mIsVerticalMarkerDragged; - - /** - * True if the horizontal marked is dragged. - */ - bool mIsHorizontalMarkerDragged; - - /** - * Holds the horizontal markers drag offset. - */ - int mHorizontalMarkerDragOffset; - - /** - * Holds the vertical markers drag offset. - */ - int mVerticalMarkerDragOffset; - - /** - * True if the scroll area should be opaque (that is - * display its background), false otherwise. - */ - bool mOpaque; - }; -} - -#endif // end GCN_SCROLLAREA_HPP diff --git a/src/guichan/widgets/slider.hpp b/src/guichan/widgets/slider.hpp deleted file mode 100644 index eddf02c50..000000000 --- a/src/guichan/widgets/slider.hpp +++ /dev/null @@ -1,300 +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. - */ - -#ifndef GCN_SLIDER_HPP -#define GCN_SLIDER_HPP - -#include "guichan/keylistener.hpp" -#include "guichan/mouselistener.hpp" -#include "guichan/platform.hpp" -#include "guichan/widget.hpp" - -namespace gcn -{ - /** - * An implementation of a slider where a user can select different values by - * sliding between a start value and an end value of a scale. - * - * If the selected value is changed an action event will be sent to all - * action listeners of the slider. - */ - class GCN_CORE_DECLSPEC Slider : - public Widget, - public MouseListener, - public KeyListener - { - public: - - /** - * Draw orientations for the slider. A slider can be drawn vertically or - * horizontally. - */ - enum Orientation - { - HORIZONTAL = 0, - VERTICAL - }; - - /** - * Constructor. The default start value of the slider scale is zero. - * - * @param scaleEnd The end value of the slider scale. - */ - Slider(double scaleEnd = 1.0); - - /** - * Constructor. - * - * @param scaleStart The start value of the slider scale. - * @param scaleEnd The end value of the slider scale. - */ - Slider(double scaleStart, double scaleEnd); - - /** - * Destructor. - */ - virtual ~Slider() { } - - /** - * Sets the scale of the slider. - * - * @param scaleStart The start value of the scale. - * @param scaleEnd tThe end of value the scale. - * @see getScaleStart, getScaleEnd - */ - void setScale(double scaleStart, double scaleEnd); - - /** - * Gets the start value of the scale. - * - * @return The start value of the scale. - * @see setScaleStart, setScale - */ - double getScaleStart() const; - - /** - * Sets the start value of the scale. - * - * @param scaleStart The start value of the scale. - * @see getScaleStart - */ - void setScaleStart(double scaleStart); - - /** - * Gets the end value of the scale. - * - * @return The end value of the scale. - * @see setScaleEnd, setScale - */ - double getScaleEnd() const; - - /** - * Sets the end value of the scale. - * - * @param scaleEnd The end value of the scale. - * @see getScaleEnd - */ - void setScaleEnd(double scaleEnd); - - /** - * Gets the current selected value. - * - * @return The current selected value. - * @see setValue - */ - double getValue() const; - - /** - * Sets the current selected value. - * - * @param value The current selected value. - * @see getValue - */ - void setValue(double value); - - /** - * Sets the length of the marker. - * - * @param length The length for the marker. - * @see getMarkerLength - */ - void setMarkerLength(int length); - - /** - * Gets the length of the marker. - * - * @return The length of the marker. - * @see setMarkerLength - */ - int getMarkerLength() const; - - /** - * Sets the orientation of the slider. A slider can be drawn vertically - * or horizontally. - * - * @param orientation The orientation of the slider. - * @see getOrientation - */ - void setOrientation(Orientation orientation); - - /** - * Gets the orientation of the slider. A slider can be drawn vertically - * or horizontally. - * - * @return The orientation of the slider. - * @see setOrientation - */ - Orientation getOrientation() const; - - /** - * Sets the step length. The step length is used when the keys LEFT - * and RIGHT are pressed to step in the scale. - * - * @param length The step length. - * @see getStepLength - */ - void setStepLength(double length); - - /** - * Gets the step length. The step length is used when the keys LEFT - * and RIGHT are pressed to step in the scale. - * - * @return the step length. - * @see setStepLength - */ - double getStepLength() const; - - - // Inherited from Widget - - virtual void draw(Graphics* graphics); - - - // Inherited from MouseListener. - - virtual void mousePressed(MouseEvent& mouseEvent); - - virtual void mouseDragged(MouseEvent& mouseEvent); - - virtual void mouseWheelMovedUp(MouseEvent& mouseEvent); - - virtual void mouseWheelMovedDown(MouseEvent& mouseEvent); - - - // Inherited from KeyListener - - virtual void keyPressed(KeyEvent& keyEvent); - - protected: - /** - * Draws the marker. - * - * @param graphics A graphics object to draw with. - */ - virtual void drawMarker(gcn::Graphics* graphics); - - /** - * Converts a marker position to a value in the scale. - * - * @param position The position to convert. - * @return A scale value corresponding to the position. - * @see valueToMarkerPosition - */ - virtual double markerPositionToValue(int position) const; - - /** - * Converts a value to a marker position. - * - * @param value The value to convert. - * @return A marker position corresponding to the value. - * @see markerPositionToValue - */ - virtual int valueToMarkerPosition(double value) const; - - /** - * Gets the marker position of the current selected value. - * - * @return The marker position of the current selected value. - */ - virtual int getMarkerPosition() const; - - /** - * True if the slider is dragged, false otherwise. - */ - bool mDragged; - - /** - * Holds the current selected value. - */ - double mValue; - - /** - * Holds the step length. The step length is used when the keys LEFT - * and RIGHT are pressed to step in the scale. - */ - double mStepLength; - - /** - * Holds the length of the marker. - */ - int mMarkerLength; - - /** - * Holds the start value of the scale. - */ - double mScaleStart; - - /** - * Holds the end value of the scale. - */ - double mScaleEnd; - - /** - * Holds the orientation of the slider. A slider can be drawn - * vertically or horizontally. - */ - Orientation mOrientation; - }; -} - -#endif // end GCN_SLIDER_HPP diff --git a/src/guichan/widgets/tab.hpp b/src/guichan/widgets/tab.hpp deleted file mode 100644 index d123bac15..000000000 --- a/src/guichan/widgets/tab.hpp +++ /dev/null @@ -1,157 +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. - */ - -#ifndef GCN_TAB_HPP -#define GCN_TAB_HPP - -#include -#include - -#include "guichan/basiccontainer.hpp" -#include "guichan/mouselistener.hpp" -#include "guichan/platform.hpp" - -#ifdef __GNUC__ -#define _UNUSED_ __attribute__ ((unused)) -#else -#define _UNUSED_ -#endif - -namespace gcn -{ - class Label; - class TabbedArea; - - /** - * An implementation of a simple tab to be used in a tabbed area. - * - * @see TabbedArea - * @since 0.8.0 - */ - class GCN_CORE_DECLSPEC Tab: - public BasicContainer, - public MouseListener - { - public: - - /** - * Constructor. - */ - Tab(); - - /** - * Destructor. - */ - virtual ~Tab(); - - /** - * Adjusts the size of the tab to fit the caption. If this tab was - * added to a TabbedArea, it will also adjust the tab positions. - */ - 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. - * @see getTabbedArea - */ - void setTabbedArea(TabbedArea* tabbedArea); - - /** - * Gets the tabbed are the tab is a part of. - * - * @return The tabbed are the tab is a part of. - * @see setTabbedArea - */ - TabbedArea* getTabbedArea(); - - /** - * Sets the caption of the tab. It's advisable to call - * adjustSize after setting the caption to make the tab - * fit the caption. - * - * @param caption The caption of the tab. - * @see getCaption, adjustSize - */ - void setCaption(const std::string& caption); - - /** - * Gets the caption of the tab. - * - * @return The caption of the tab. - * @see setCaption - */ - const std::string& getCaption() const; - - - // Inherited from Widget - - virtual void draw(Graphics *graphics); - - - // Inherited from MouseListener - - virtual void mouseEntered(MouseEvent& mouseEvent); - - virtual void mouseExited(MouseEvent& mouseEvent); - - protected: - /** - * Holds the label of the tab. - */ - Label* mLabel; - - /** - * True if the tab has the mouse, false otherwise. - */ - bool mHasMouse; - - /** - * Holds the tabbed area the tab is a part of. - */ - TabbedArea* mTabbedArea; - }; -} - -#endif // end GCN_TABBEDAREA_HPP diff --git a/src/guichan/widgets/tabbedarea.hpp b/src/guichan/widgets/tabbedarea.hpp deleted file mode 100644 index 843bbde81..000000000 --- a/src/guichan/widgets/tabbedarea.hpp +++ /dev/null @@ -1,280 +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. - */ - -#ifndef GCN_TABBEDAREA_HPP -#define GCN_TABBEDAREA_HPP - -#include -#include -#include - -#include "guichan/actionlistener.hpp" -#include "guichan/basiccontainer.hpp" -#include "guichan/keylistener.hpp" -#include "guichan/mouselistener.hpp" -#include "guichan/platform.hpp" - -namespace gcn -{ - class Container; - class Tab; - - /** - * An implementation of a tabbed area where a user can display a widget by - * selecting a tab. - * - * @since 0.8.0 - */ - class GCN_CORE_DECLSPEC TabbedArea: - public ActionListener, - public BasicContainer, - public KeyListener, - public MouseListener - { - friend class Tab; - - public: - /** - * Constructor. - */ - TabbedArea(); - - /** - * Destructor. - */ - virtual ~TabbedArea(); - - /** - * Sets the tabbed area to be opaque or not. If the tabbed area is - * opaque its background will be drawn, if it's not opaque its - * background will not be drawn. By default, a tabbed area is not - * opaque. - * - * The tabbed area's background is normally only visible behind the - * tabs, since the container holding the tab contents is opaque by - * default. - * - * @param opaque True if the tabbed area should be opaque, false - * otherwise. - * @see isOpaque - */ - void setOpaque(bool opaque); - - /** - * Checks if the tabbed area is opaque or not. - * - * @return true if the tabbed area is opaque, false otherwise. - * @see setOpaque - */ - bool isOpaque() const; - - /** - * Adds a tab to the tabbed area. The newly created tab will be - * automatically deleted by the tabbed area when it is removed. - * - * @param caption The caption of the tab to add. - * @param widget The widget to view when the tab is selected. - * @see removeTab, removeTabWithIndex - */ - virtual void addTab(const std::string& caption, Widget* widget); - - /** - * Adds a tab to the tabbed area. The tab will not be deleted by the - * tabbed area when it is removed. - * - * @param tab The tab widget for the tab. - * @param widget The widget to view when the tab is selected. - * @see removeTab, removeTabWithIndex - */ - virtual void addTab(Tab* tab, Widget* widget); - - /** - * Removes a tab from the tabbed area. - * - * @param index The index of the tab to remove. - * @see addTab - */ - virtual void removeTabWithIndex(unsigned int index); - - /** - * Removes a tab from the tabbed area. - * - * @param index The tab to remove. - * @see addTab - */ - virtual void removeTab(Tab* tab); - - /** - * Checks if a tab given an index is selected or not. - * - * @param index The index of the tab to check. - * @return True if the tab is selected, false otherwise. - * @see setSelectedTab - */ - virtual bool isTabSelected(unsigned int index) const; - - /** - * Checks if a tab is selected or not. - * - * @param index The tab to check. - * @return True if the tab is selected, false otherwise. - * @see setSelectedTab - */ - virtual bool isTabSelected(Tab* tab); - - /** - * Sets a tab given an index to be selected. - * - * @param index The index of the tab to be selected. - * @see isTabSelected, getSelectedTab - */ - virtual void setSelectedTab(unsigned int index); - - /** - * Sets a tab to be selected or not. - * - * @param index The tab to be selected. - * @see isTabSelected, getSelectedTab - */ - 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. - * @see isTabSelected, setSelectedTab - */ - virtual int getSelectedTabIndex() const; - - /** - * Gets the selected tab. - * - * @return The selected tab. - * @see isTabSelected, setSelectedTab - */ - Tab* getSelectedTab(); - - - // Inherited from Widget - - virtual void draw(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 tab container and the widget container. - */ - void adjustSize(); - - /** - * Adjusts the positions of the tabs. - */ - void adjustTabPositions(); - - /** - * Holds the selected tab. - */ - Tab* mSelectedTab; - - /** - * Holds the container for the tabs. - */ - Container* mTabContainer; - - /** - * Holds the container for the widgets. - */ - Container* mWidgetContainer; - - /** - * Holds a vector of tabs to delete in the destructor. - * A tab that is to be deleted is a tab that has been - * internally created by the tabbed area. - */ - std::vector mTabsToDelete; - - /** - * A map between a tab and a widget to display when the - * tab is selected. - */ - std::vector > mTabs; - - /** - * True if the tabbed area is opaque, false otherwise. - */ - bool mOpaque; - }; -} - -#endif // end GCN_TABBEDAREA_HPP diff --git a/src/guichan/widgets/textbox.hpp b/src/guichan/widgets/textbox.hpp deleted file mode 100644 index b00dcef20..000000000 --- a/src/guichan/widgets/textbox.hpp +++ /dev/null @@ -1,289 +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. - */ - -#ifndef GCN_TEXTBOX_HPP -#define GCN_TEXTBOX_HPP - -#include -#include -#include - -#include "guichan/keylistener.hpp" -#include "guichan/mouselistener.hpp" -#include "guichan/platform.hpp" -#include "guichan/widget.hpp" - -namespace gcn -{ - /** - * An implementation of a text box where a user can enter text that contains of many lines. - */ - class GCN_CORE_DECLSPEC TextBox: - public Widget, - public MouseListener, - public KeyListener - { - public: - /** - * Constructor. - */ - TextBox(); - - /** - * Constructor. - * - * @param text The default text of the text box. - */ - TextBox(const std::string& text); - - /** - * Sets the text of the text box. - * - * @param text The text of the text box. - * @see getText - */ - void setText(const std::string& text); - - /** - * Gets the text of the text box. - * - * @return The text of the text box. - * @see setText - */ - std::string getText() const; - - /** - * Gets a certain row from the text. - * - * @param row The number of the row to get from the text. - * @return A row from the text of the text box. - * @see setTextRow - */ - const std::string& getTextRow(int row) const; - - /** - * Sets the text of a certain row of the text. - * - * @param row The number of the row to set in the text. - * @param text The text to set in the given row number. - * @see getTextRow - */ - 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. - * @see setCaretPosition - */ - unsigned int getCaretPosition() const; - - /** - * Sets the position of the caret in the text. - * - * @param position the positon of the caret. - * @see getCaretPosition - */ - void setCaretPosition(unsigned int position); - - /** - * Gets the row number where the caret is currently located. - * - * @return The row number where the caret is currently located. - * @see setCaretRow - */ - unsigned int getCaretRow() const; - - /** - * Sets the row where the caret should be currently located. - * - * @param The row where the caret should be currently located. - * @see getCaretRow - */ - void setCaretRow(int row); - - /** - * Gets the column where the caret is currently located. - * - * @return The column where the caret is currently located. - * @see setCaretColumn - */ - unsigned int getCaretColumn() const; - - /** - * Sets the column where the caret should be currently located. - * - * @param The column where the caret should be currently located. - * @see getCaretColumn - */ - void setCaretColumn(int column); - - /** - * Sets the row and the column where the caret should be curretly - * located. - * - * @param row The row where the caret should be currently located. - * @param column The column where the caret should be currently located. - * @see getCaretRow, getCaretColumn - */ - void setCaretRowColumn(int row, int column); - - /** - * Scrolls the text to the caret if the text box is in a scroll area. - * - * @see ScrollArea - */ - virtual void scrollToCaret(); - - /** - * Checks if the text box is editable. - * - * @return True it the text box is editable, false otherwise. - * @see setEditable - */ - bool isEditable() const; - - /** - * Sets the text box to be editable or not. - * - * @param editable True if the text box should be editable, false otherwise. - */ - void setEditable(bool editable); - - /** - * Adds a row of text to the end of the text. - * - * @param row The row to add. - */ - virtual void addRow(const std::string row); - - /** - * Checks if the text box is opaque. An opaque text box will draw - * it's background and it's text. A non opaque text box only draw it's - * text making it transparent. - * - * @return True if the text box is opaque, false otherwise. - * @see setOpaque - */ - bool isOpaque(); - - /** - * Sets the text box to be opaque or not. An opaque text box will draw - * it's background and it's text. A non opaque text box only draw it's - * text making it transparent. - * - * @param opaque True if the text box should be opaque, false otherwise. - * @see isOpaque - */ - void setOpaque(bool opaque); - - - // Inherited from Widget - - virtual void draw(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. Overloaded this method if you want to - * change the style of 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 text box's size to fit the text. - */ - virtual void adjustSize(); - - /** - * Holds all the rows of the text. - */ - std::vector mTextRows; - - /** - * Holds the current column of the caret. - */ - int mCaretColumn; - - /** - * Holds the current row of the caret. - */ - int mCaretRow; - - /** - * True if the text box is editable, false otherwise. - */ - bool mEditable; - - /** - * True if the text box is editable, false otherwise. - */ - bool mOpaque; - }; -} - -#endif // end GCN_TEXTBOX_HPP diff --git a/src/guichan/widgets/textfield.hpp b/src/guichan/widgets/textfield.hpp deleted file mode 100644 index 486660a8a..000000000 --- a/src/guichan/widgets/textfield.hpp +++ /dev/null @@ -1,177 +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. - */ - -#ifndef GCN_TEXTFIELD_HPP -#define GCN_TEXTFIELD_HPP - -#include "guichan/keylistener.hpp" -#include "guichan/mouselistener.hpp" -#include "guichan/platform.hpp" -#include "guichan/widget.hpp" - -#include - -namespace gcn -{ - /** - * An implementation of a text field where a user can enter a line of text. - */ - class GCN_CORE_DECLSPEC TextField: - public Widget, - public MouseListener, - public KeyListener - { - public: - /** - * Constructor. - */ - TextField(); - - /** - * Constructor. The text field will be automatically resized - * to fit the text. - * - * @param text The default text of the text field. - */ - TextField(const std::string& text); - - /** - * Sets the text of the text field. - * - * @param text The text of the text field. - * @see getText - */ - void setText(const std::string& text); - - /** - * Gets the text of the text field. - * - * @return The text of the text field. - * @see setText - */ - const std::string& getText() const; - - /** - * Adjusts the size of the text field to fit the text. - */ - void adjustSize(); - - /** - * Adjusts the height of the text field to fit caption. - */ - void adjustHeight(); - - /** - * Sets the caret position. As there is only one line of text - * in a text field the position is the caret's x coordinate. - * - * @param position The caret position. - * @see getCaretPosition - */ - void setCaretPosition(unsigned int position); - - /** - * Gets the caret position. As there is only one line of text - * in a text field the position is the caret's x coordinate. - * - * @return The caret position. - * @see setCaretPosition - */ - unsigned int getCaretPosition() const; - - - // Inherited from Widget - - virtual void fontChanged(); - - virtual void draw(Graphics* graphics); - - - // Inherited from MouseListener - - virtual void mousePressed(MouseEvent& mouseEvent); - - virtual void mouseDragged(MouseEvent& mouseEvent); - - - // Inherited from KeyListener - - virtual void keyPressed(KeyEvent& keyEvent); - - protected: - /** - * Draws the caret. Overloaded this method 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); - - /** - * Scrolls the text horizontally so that the caret shows if needed. - * The method is used any time a user types in the text field so the - * caret always will be shown. - */ - void fixScroll(); - - /** - * Holds the text of the text box. - */ - std::string mText; - - /** - * Holds the caret position. - */ - unsigned int mCaretPosition; - - /** - * Holds the amount scrolled in x. If a user types more characters than - * the text field can display, due to the text field being to small, the - * text needs to scroll in order to show the last type character. - */ - int mXScroll; - }; -} - -#endif // end GCN_TEXTFIELD_HPP diff --git a/src/guichan/widgets/window.hpp b/src/guichan/widgets/window.hpp deleted file mode 100644 index 63685c7fb..000000000 --- a/src/guichan/widgets/window.hpp +++ /dev/null @@ -1,261 +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. - */ - -#ifndef GCN_WINDOW_HPP -#define GCN_WINDOW_HPP - -#include - -#include "guichan/mouselistener.hpp" -#include "guichan/platform.hpp" -#include "guichan/widgets/container.hpp" - -#ifdef __GNUC__ -#define _UNUSED_ __attribute__ ((unused)) -#else -#define _UNUSED_ -#endif - -namespace gcn -{ - /** - * An implementation of a movable window that can contain other widgets. - */ - class GCN_CORE_DECLSPEC Window : public Container, - public MouseListener - { - public: - /** - * Constructor. - */ - Window(); - - /** - * Constructor. The window will be automatically resized in height - * to fit the caption. - * - * @param caption the caption of the window. - */ - Window(const std::string& caption); - - /** - * Destructor. - */ - virtual ~Window(); - - /** - * Sets the caption of the window. - * - * @param caption The caption of the window. - * @see getCaption - */ - void setCaption(const std::string& caption); - - /** - * Gets the caption of the window. - * - * @return the caption of the window. - * @see setCaption - */ - const std::string& getCaption() const; - - /** - * Sets the alignment of the caption. - * - * @param alignment The alignment of the caption. - * @see getAlignment, Graphics - */ - void setAlignment(Graphics::Alignment alignment); - - /** - * Gets the alignment of the caption. - * - * @return The alignment of caption. - * @see setAlignment, Graphics - */ - Graphics::Alignment getAlignment() const; - - /** - * Sets the padding of the window. The padding is the distance between the - * window border and the content. - * - * @param padding The padding of the window. - * @see getPadding - */ - void setPadding(unsigned int padding); - - /** - * Gets the padding of the window. The padding is the distance between the - * window border and the content. - * - * @return The padding of the window. - * @see setPadding - */ - unsigned int getPadding() const; - - /** - * Sets the title bar height. - * - * @param height The title height value. - * @see getTitleBarHeight - */ - void setTitleBarHeight(unsigned int height); - - /** - * Gets the title bar height. - * - * @return The title bar height. - * @see setTitleBarHeight - */ - unsigned int getTitleBarHeight(); - - /** - * Sets the window to be moveble or not. - * - * @param movable True if the window should be movable, false otherwise. - * @see isMovable - */ - void setMovable(bool movable); - - /** - * Checks if the window is movable. - * - * @return True if the window is movable, false otherwise. - * @see setMovable - */ - bool isMovable() const; - - /** - * Sets the window to be opaque or not. An opaque window will draw it's background - * and it's content. A non opaque window will only draw it's content. - * - * @param opaque True if the window should be opaque, false otherwise. - * @see isOpaque - */ - void setOpaque(bool opaque); - - /** - * Checks if the window is opaque. - * - * @return True if the window is opaque, false otherwise. - * @see setOpaque - */ - bool isOpaque(); - - /** - * Resizes the window to fit the content. - */ - virtual void resizeToContent(); - - - // Inherited from BasicContainer - - virtual Rectangle getChildrenArea(); - - - // Inherited from Widget - - virtual void draw(Graphics* graphics); - - - // Inherited from MouseListener - - virtual void mousePressed(MouseEvent& mouseEvent); - - virtual void mouseDragged(MouseEvent& mouseEvent); - - virtual void mouseReleased(MouseEvent& mouseEvent); - - protected: - /** - * Holds the caption of the window. - */ - std::string mCaption; - - /** - * Holds the alignment of the caption. - */ - Graphics::Alignment mAlignment; - - /** - * Holds the padding of the window. - */ - unsigned int mPadding; - - /** - * Holds the title bar height of the window. - */ - unsigned int mTitleBarHeight; - - /** - * True if the window is movable, false otherwise. - */ - bool mMovable; - - /** - * True if the window is opaque, false otherwise. - */ - bool mOpaque; - - /** - * Holds a drag offset as an x coordinate where the drag of the window - * started if the window is being dragged. It's used to move the window - * correctly when dragged. - */ - int mDragOffsetX; - - /** - * Holds a drag offset as an y coordinate where the drag of the window - * started if the window is being dragged. It's used to move the window - * correctly when dragged. - */ - int mDragOffsetY; - - /** - * True if the window is being moved, false otherwise. - */ - bool mMoved; - }; -} - -#endif // end GCN_WINDOW_HPP -- cgit v1.2.3-60-g2f50