diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-08-24 20:27:37 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-08-24 20:27:37 +0300 |
commit | 5c7971dba41580ec0eeb69133b11f717dd5317ac (patch) | |
tree | 662f92518db5393581c7dd9e0444e2ff23e5d017 | |
parent | 3689ea3de59012d8abee08431b802cec81ba76e9 (diff) | |
download | plus-5c7971dba41580ec0eeb69133b11f717dd5317ac.tar.gz plus-5c7971dba41580ec0eeb69133b11f717dd5317ac.tar.bz2 plus-5c7971dba41580ec0eeb69133b11f717dd5317ac.tar.xz plus-5c7971dba41580ec0eeb69133b11f717dd5317ac.zip |
Remove embeded guichan.
Add cmake deps for system wide guichan.
116 files changed, 108 insertions, 27356 deletions
diff --git a/CMake/Modules/FindGuichan.cmake b/CMake/Modules/FindGuichan.cmake new file mode 100644 index 000000000..dbc863e2f --- /dev/null +++ b/CMake/Modules/FindGuichan.cmake @@ -0,0 +1,100 @@ +# - Try to find Guichan +# Once done this will define +# +# GUICHAN_FOUND - system has Guichan +# GUICHAN_INCLUDE_DIR - the Guichan include directory +# GUICHAN_LIBRARIES - the libraries needed to use Guichan +# +# Supported components: SDL OpenGL +# +# TODO: Clean up the components stuff and try to add all known +# components when none are specified. May not bail out for not found +# components then, set some var instead... + +# Be quiet if Guichan was already found +# We need an extra variable to have the check per component + +IF (Guichan_INCLUDE_DIR AND Guichan_LIBRARY) + SET(Guichan_QUIET TRUE) +ENDIF () + +FIND_PATH(Guichan_INCLUDE_DIR + NAMES guichan.hpp + PATHS /usr/include /usr/local/include + ) + +FIND_LIBRARY(Guichan_LIBRARY + NAMES guichan + PATHS /usr/lib /usr/local/lib + ) + +MARK_AS_ADVANCED(Guichan_INCLUDE_DIR Guichan_LIBRARY) + +IF (Guichan_INCLUDE_DIR AND Guichan_LIBRARY) + SET(GUICHAN_FOUND TRUE) + SET(GUICHAN_INCLUDE_DIR ${Guichan_INCLUDE_DIR}) + SET(GUICHAN_LIBRARIES ${Guichan_LIBRARY}) + + IF (NOT Guichan_FIND_QUIETLY AND NOT Guichan_QUIET) + MESSAGE(STATUS "Found Guichan: ${Guichan_LIBRARY}") + ENDIF () +ENDIF () + +# Bail out if Guichan is not found but required +IF (NOT GUICHAN_FOUND AND Guichan_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could NOT find Guichan library ${GUICHAN_INCLUDE_DIR}") +ENDIF () + +# Check for guichan components +FOREACH (COMPONENT ${Guichan_FIND_COMPONENTS}) + SET(COMPONENT_FOUND FALSE) + + IF (COMPONENT STREQUAL "SDL") + SET(COMPONENT_FOUND TRUE) + SET(Guichan_HEADER "guichan/sdl.hpp") + SET(Guichan_LIBRARY "guichan_sdl") + ENDIF () + + IF (COMPONENT STREQUAL "OpenGL") + SET(COMPONENT_FOUND TRUE) + SET(Guichan_HEADER "guichan/opengl.hpp") + SET(Guichan_LIBRARY "guichan_opengl") + ENDIF () + + IF (NOT COMPONENT_FOUND) + MESSAGE(FATAL_ERROR "Invalid Guichan component: ${COMPONENT}") + ENDIF (NOT COMPONENT_FOUND) + + # Check if we already found this component + IF (Guichan_LIBRARY_${COMPONENT}) + SET(Guichan_QUIET TRUE) + ELSE () + SET(Guichan_QUIET FALSE) + ENDIF () + + FIND_LIBRARY(Guichan_LIBRARY_${COMPONENT} + NAMES ${Guichan_LIBRARY} + PATHS /usr/lib /usr/local/lib + ) + + MARK_AS_ADVANCED(Guichan_LIBRARY_${COMPONENT}) + + IF (NOT EXISTS ${Guichan_INCLUDE_DIR}/${Guichan_HEADER} OR + NOT Guichan_LIBRARY_${COMPONENT}) + SET(GUICHAN_FOUND FALSE) + MESSAGE(FATAL_ERROR "Could NOT find Guichan component ${COMPONENT}") + ENDIF () + + # Check guichan >= 0.8.0 by searching for the widgetlistener.hpp file. + SET(Guichan_HEADER "guichan/widgetlistener.hpp") + IF (NOT EXISTS ${Guichan_INCLUDE_DIR}/${Guichan_HEADER}) + SET(GUICHAN_FOUND FALSE) + MESSAGE(FATAL_ERROR "Guichan version is less than 0.8.0") + ENDIF() + + IF (NOT Guichan_FIND_QUIETLY AND NOT Guichan_QUIET) + MESSAGE(STATUS "Found Guichan ${COMPONENT}: ${Guichan_LIBRARY_${COMPONENT}}") + ENDIF () + + SET(GUICHAN_LIBRARIES ${GUICHAN_LIBRARIES} ${Guichan_LIBRARY_${COMPONENT}}) +ENDFOREACH() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 413a72f65..554fcfbf5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,6 +55,9 @@ ELSEIF (CMAKE_SYSTEM_NAME STREQUAL SunOS) SET(EXTRA_LIBRARIES intl) ENDIF() +SET(GUICHAN_COMPONENTS "SDL") +FIND_PACKAGE(Guichan REQUIRED ${GUICHAN_COMPONENTS}) + IF (WITH_OPENGL) FIND_PACKAGE(OpenGL REQUIRED) INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR}) @@ -68,8 +71,6 @@ IF (USE_X11) ENDIF (USE_X11) INCLUDE_DIRECTORIES( - "guichan/include" - "SDL_gfx" ${CMAKE_CURRENT_SOURCE_DIR} ${SDL_INCLUDE_DIR} ${SDLIMAGE_INCLUDE_DIR} @@ -81,6 +82,7 @@ INCLUDE_DIRECTORIES( ${PHYSFS_INCLUDE_DIR} ${CURL_INCLUDE_DIR} ${LIBXML2_INCLUDE_DIR} + ${GUICHAN_INCLUDE_DIR} ) # enable rc-handling with mingw @@ -586,99 +588,6 @@ SET(SRCS mumblemanager.h ) -SET(SRCS_GUICHAN - 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/deathlistener.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/selectionlistener.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 - guichan/color.cpp - guichan/defaultfont.cpp - guichan/event.cpp - guichan/exception.cpp - guichan/focushandler.cpp - guichan/font.cpp - guichan/graphics.cpp - guichan/gui.cpp - guichan/image.cpp - guichan/inputevent.cpp - guichan/key.cpp - guichan/keyevent.cpp - guichan/keyinput.cpp - guichan/mouseevent.cpp - guichan/mouseinput.cpp - guichan/rectangle.cpp - guichan/selectionevent.cpp - guichan/widget.cpp - guichan/sdl/sdlgraphics.cpp - guichan/sdl/sdlimage.cpp - guichan/widgets/button.cpp - guichan/widgets/checkbox.cpp - guichan/widgets/container.cpp - guichan/widgets/dropdown.cpp - guichan/widgets/icon.cpp - guichan/widgets/imagebutton.cpp - guichan/widgets/label.cpp - guichan/widgets/listbox.cpp - guichan/widgets/radiobutton.cpp - guichan/widgets/scrollarea.cpp - guichan/widgets/slider.cpp - guichan/widgets/tabbedarea.cpp - guichan/widgets/tab.cpp - guichan/widgets/textbox.cpp - guichan/widgets/textfield.cpp - guichan/widgets/window.cpp - ) - SET(SRCS_EVOL net/ea/gui/guildtab.cpp net/ea/gui/guildtab.h @@ -767,24 +676,6 @@ SET(SRCS_TMWA ) SET(SRCS_MANASERV - enet/callbacks.c - enet/callbacks.h - enet/compress.c - enet/enet.h - enet/host.c - enet/list.c - enet/list.h - enet/packet.c - enet/peer.c - enet/protocol.c - enet/protocol.h - enet/time.h - enet/types.h - enet/unix.c - enet/unix.h - enet/utility.h - enet/win32.c - enet/win32.h net/manaserv/attributes.cpp net/manaserv/attributes.h net/manaserv/adminhandler.cpp @@ -849,9 +740,9 @@ ENDIF () SET (PROGRAMS manaplus) IF (ENABLE_MANASERV) - ADD_EXECUTABLE(manaplus WIN32 ${SRCS_GUICHAN} ${SRCS} ${SRCS_MANASERV} ${SRCS_TMWA} ${SRCS_EVOL}) + ADD_EXECUTABLE(manaplus WIN32 ${SRCS} ${SRCS_MANASERV} ${SRCS_TMWA} ${SRCS_EVOL}) ELSE(ENABLE_MANASERV) - ADD_EXECUTABLE(manaplus WIN32 ${SRCS_GUICHAN} ${SRCS} ${SRCS_TMWA} ${SRCS_EVOL}) + ADD_EXECUTABLE(manaplus WIN32 ${SRCS} ${SRCS_TMWA} ${SRCS_EVOL}) ENDIF(ENABLE_MANASERV) TARGET_LINK_LIBRARIES(manaplus @@ -865,6 +756,7 @@ TARGET_LINK_LIBRARIES(manaplus ${PHYSFS_LIBRARY} ${CURL_LIBRARIES} ${LIBXML2_LIBRARIES} + ${GUICHAN_LIBRARIES} ${OPENGL_LIBRARIES} ${LIBINTL_LIBRARIES} ${EXTRA_LIBRARIES}) diff --git a/src/Makefile.am b/src/Makefile.am index 57bb4e620..00a6713ad 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -593,25 +593,7 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ if ENABLE_MANASERV manaplus_CXXFLAGS += -DMANASERV_SUPPORT -manaplus_SOURCES += enet/callbacks.c \ - enet/compress.c \ - enet/host.c \ - enet/list.c \ - enet/packet.c \ - enet/peer.c \ - enet/protocol.c \ - enet/unix.c \ - enet/win32.c \ - enet/callbacks.h \ - enet/enet.h \ - enet/list.h \ - enet/protocol.h \ - enet/time.h \ - enet/types.h \ - enet/unix.h \ - enet/utility.h \ - enet/win32.h \ - net/manaserv/attributes.cpp \ +manaplus_SOURCES += net/manaserv/attributes.cpp \ net/manaserv/attributes.h \ net/manaserv/adminhandler.cpp \ net/manaserv/adminhandler.h \ @@ -753,10 +735,6 @@ manaplus_SOURCES += \ EXTRA_DIST = CMakeLists.txt \ winver.h.in \ - enet/ChangeLog \ - enet/design.txt \ - enet/LICENSE \ - enet/README \ manaplus.rc \ SDLMain.h \ SDLMain.m \ diff --git a/src/SDL_gfx/SDL_gfxBlitFunc.h b/src/SDL_gfx/SDL_gfxBlitFunc.h deleted file mode 100644 index f233aa617..000000000 --- a/src/SDL_gfx/SDL_gfxBlitFunc.h +++ /dev/null @@ -1,128 +0,0 @@ -/* - - SDL_gfxBlitFunc: custom blitters (part of SDL_gfx library) - - LGPL (c) A. Schiffler - -*/ - -#ifndef _SDL_gfxBlitFunc_h -#define _SDL_gfxBlitFunc_h - -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -#include <stdio.h> -#include <stdlib.h> - -#include <SDL.h> -#include <SDL_video.h> - -/* -------- Prototypes */ - -#ifdef WIN32 -# ifdef DLL_EXPORT -# define SDL_GFXBLITFUNC_SCOPE __declspec(dllexport) -# else -# ifdef LIBSDL_GFX_DLL_IMPORT -# define SDL_GFXBLITFUNC_SCOPE __declspec(dllimport) -# endif -# endif -#endif -#ifndef SDL_GFXBLITFUNC_SCOPE -# define SDL_GFXBLITFUNC_SCOPE extern -#endif - - -SDL_GFXBLITFUNC_SCOPE int SDL_gfxBlitRGBA(SDL_Surface * src, SDL_Rect * srcrect, SDL_Surface * dst, SDL_Rect * dstrect); - -SDL_GFXBLITFUNC_SCOPE int SDL_gfxSetAlpha(SDL_Surface * src, Uint8 a); - - -/* -------- Macros */ - -/* Define SDL macros locally as a substitute for a #include "SDL_blit.h", */ - -/* which doesn't work since the include file doesn't get installed. */ - -/* The structure passed to the low level blit functions */ - typedef struct { - Uint8 *s_pixels; - int s_width; - int s_height; - int s_skip; - Uint8 *d_pixels; - int d_width; - int d_height; - int d_skip; - void *aux_data; - SDL_PixelFormat *src; - Uint8 *table; - SDL_PixelFormat *dst; - } SDL_gfxBlitInfo; - -#define GFX_RGBA_FROM_PIXEL(pixel, fmt, r, g, b, a) \ -{ \ - r = ((pixel&fmt->Rmask)>>fmt->Rshift)<<fmt->Rloss; \ - g = ((pixel&fmt->Gmask)>>fmt->Gshift)<<fmt->Gloss; \ - b = ((pixel&fmt->Bmask)>>fmt->Bshift)<<fmt->Bloss; \ - a = ((pixel&fmt->Amask)>>fmt->Ashift)<<fmt->Aloss; \ -} - -#define GFX_DISEMBLE_RGBA(buf, bpp, fmt, pixel, r, g, b, a) \ -do { \ - pixel = *((Uint32 *)(buf)); \ - GFX_RGBA_FROM_PIXEL(pixel, fmt, r, g, b, a); \ - pixel &= ~fmt->Amask; \ -} while(0) - -#define GFX_PIXEL_FROM_RGBA(pixel, fmt, r, g, b, a) \ -{ \ - pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \ - ((g>>fmt->Gloss)<<fmt->Gshift)| \ - ((b>>fmt->Bloss)<<fmt->Bshift)| \ - ((a<<fmt->Aloss)<<fmt->Ashift); \ -} - -#define GFX_ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a) \ -{ \ - Uint32 pixel; \ - \ - GFX_PIXEL_FROM_RGBA(pixel, fmt, r, g, b, a); \ - *((Uint32 *)(buf)) = pixel; \ -} - -/* Blend the RGB values of two pixels based on a source alpha value */ -#define GFX_ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB) \ -do { \ - dR = (((sR-dR)*(A))/255)+dR; \ - dG = (((sG-dG)*(A))/255)+dG; \ - dB = (((sB-dB)*(A))/255)+dB; \ -} while(0) - -/* This is a very useful loop for optimizing blitters */ - -/* 4-times unrolled loop */ -#define GFX_DUFFS_LOOP4(pixel_copy_increment, width) \ -{ int n = (width+3)/4; \ - switch (width & 3) { \ - case 0: do { pixel_copy_increment; \ - case 3: pixel_copy_increment; \ - case 2: pixel_copy_increment; \ - case 1: pixel_copy_increment; \ - } while ( --n > 0 ); \ - } \ -} - -//deleted - -/* --- */ - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif - -#endif /* _SDL_gfxBlitFunc_h */ diff --git a/src/enet/ChangeLog b/src/enet/ChangeLog deleted file mode 100644 index 45f14db6a..000000000 --- a/src/enet/ChangeLog +++ /dev/null @@ -1,86 +0,0 @@ -ENet 1.3.0 (June 5, 2010): - -* enet_host_create() now requires the channel limit to be specified as -a parameter -* enet_host_connect() now accepts a data parameter which is supplied -to the receiving receiving host in the event data field for a connect event -* added an adaptive order-2 PPM range coder as a built-in compressor option -which can be set with enet_host_compress_with_range_coder() -* added support for packet compression configurable with a callback -* improved session number handling to not rely on the packet checksum -field, saving 4 bytes per packet unless the checksum option is used -* removed the dependence on the rand callback for session number handling - -Caveats: This version is not protocol compatible with the 1.2 series or -earlier. The enet_host_connect and enet_host_create API functions require -supplying additional parameters. - -ENet 1.2.2 (June 5, 2010): - -* checksum functionality is now enabled by setting a checksum callback -inside ENetHost instead of being a configure script option -* added totalSentData, totalSentPackets, totalReceivedData, and -totalReceivedPackets counters inside ENetHost for getting usage -statistics -* added enet_host_channel_limit() for limiting the maximum number of -channels allowed by connected peers -* now uses dispatch queues for event dispatch rather than potentially -unscalable array walking -* added no_memory callback that is called when a malloc attempt fails, -such that if no_memory returns rather than aborts (the default behavior), -then the error is propagated to the return value of the API calls -* now uses packed attribute for protocol structures on platforms with -strange alignment rules -* improved autoconf build system contributed by Nathan Brink allowing -for easier building as a shared library - -Caveats: If you were using the compile-time option that enabled checksums, -make sure to set the checksum callback inside ENetHost to enet_crc32 to -regain the old behavior. The ENetCallbacks structure has added new fields, -so make sure to clear the structure to zero before use if -using enet_initialize_with_callbacks(). - -ENet 1.2.1 (November 12, 2009): - -* fixed bug that could cause disconnect events to be dropped -* added thin wrapper around select() for portable usage -* added ENET_SOCKOPT_REUSEADDR socket option -* factored enet_socket_bind()/enet_socket_listen() out of enet_socket_create() -* added contributed Code::Blocks build file - -ENet 1.2 (February 12, 2008): - -* fixed bug in VERIFY_CONNECT acknowledgement that could cause connect -attempts to occasionally timeout -* fixed acknowledgements to check both the outgoing and sent queues -when removing acknowledged packets -* fixed accidental bit rot in the MSVC project file -* revised sequence number overflow handling to address some possible -disconnect bugs -* added enet_host_check_events() for getting only local queued events -* factored out socket option setting into enet_socket_set_option() so -that socket options are now set separately from enet_socket_create() - -Caveats: While this release is superficially protocol compatible with 1.1, -differences in the sequence number overflow handling can potentially cause -random disconnects. - -ENet 1.1 (June 6, 2007): - -* optional CRC32 just in case someone needs a stronger checksum than UDP -provides (--enable-crc32 configure option) -* the size of packet headers are half the size they used to be (so less -overhead when sending small packets) -* enet_peer_disconnect_later() that waits till all queued outgoing -packets get sent before issuing an actual disconnect -* freeCallback field in individual packets for notification of when a -packet is about to be freed -* ENET_PACKET_FLAG_NO_ALLOCATE for supplying pre-allocated data to a -packet (can be used in concert with freeCallback to support some custom -allocation schemes that the normal memory allocation callbacks would -normally not allow) -* enet_address_get_host_ip() for printing address numbers -* promoted the enet_socket_*() functions to be part of the API now -* a few stability/crash fixes - - diff --git a/src/enet/LICENSE b/src/enet/LICENSE deleted file mode 100644 index df0f91e98..000000000 --- a/src/enet/LICENSE +++ /dev/null @@ -1,7 +0,0 @@ -Copyright (c) 2002-2010 Lee Salzman - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/src/enet/README b/src/enet/README deleted file mode 100644 index 7f7a0ad01..000000000 --- a/src/enet/README +++ /dev/null @@ -1,15 +0,0 @@ -Please visit the ENet homepage at http://enet.bespin.org for installation -and usage instructions. - -If you obtained this package from CVS, the quick description on how to build -is: - -# Generate the build system. - -autoreconf -vfi - -# Compile and install the library. - -./configure && make && make install - - diff --git a/src/enet/callbacks.c b/src/enet/callbacks.c deleted file mode 100644 index f94128256..000000000 --- a/src/enet/callbacks.c +++ /dev/null @@ -1,47 +0,0 @@ -/** - @file callbacks.c - @brief ENet callback functions -*/ -#define ENET_BUILDING_LIB 1 -#include "enet/enet.h" - -static ENetCallbacks callbacks = { malloc, free, abort }; - -int -enet_initialize_with_callbacks (ENetVersion version, const ENetCallbacks * inits) -{ - if (version < ENET_VERSION_CREATE (1, 3, 0)) - return -1; - - if (inits -> malloc != NULL || inits -> free != NULL) - { - if (inits -> malloc == NULL || inits -> free == NULL) - return -1; - - callbacks.malloc = inits -> malloc; - callbacks.free = inits -> free; - } - - if (inits -> no_memory != NULL) - callbacks.no_memory = inits -> no_memory; - - return enet_initialize (); -} - -void * -enet_malloc (size_t size) -{ - void * memory = callbacks.malloc (size); - - if (memory == NULL) - callbacks.no_memory (); - - return memory; -} - -void -enet_free (void * memory) -{ - callbacks.free (memory); -} - diff --git a/src/enet/callbacks.h b/src/enet/callbacks.h deleted file mode 100644 index 340a4a989..000000000 --- a/src/enet/callbacks.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - @file callbacks.h - @brief ENet callbacks -*/ -#ifndef __ENET_CALLBACKS_H__ -#define __ENET_CALLBACKS_H__ - -#include <stdlib.h> - -typedef struct _ENetCallbacks -{ - void * (ENET_CALLBACK * malloc) (size_t size); - void (ENET_CALLBACK * free) (void * memory); - void (ENET_CALLBACK * no_memory) (void); -} ENetCallbacks; - -/** @defgroup callbacks ENet internal callbacks - @{ - @ingroup private -*/ -extern void * enet_malloc (size_t); -extern void enet_free (void *); - -/** @} */ - -#endif /* __ENET_CALLBACKS_H__ */ - diff --git a/src/enet/compress.c b/src/enet/compress.c deleted file mode 100644 index 784489a78..000000000 --- a/src/enet/compress.c +++ /dev/null @@ -1,654 +0,0 @@ -/** - @file compress.c - @brief An adaptive order-2 PPM range coder -*/ -#define ENET_BUILDING_LIB 1 -#include <string.h> -#include "enet/enet.h" - -typedef struct _ENetSymbol -{ - /* binary indexed tree of symbols */ - enet_uint8 value; - enet_uint8 count; - enet_uint16 under; - enet_uint16 left, right; - - /* context defined by this symbol */ - enet_uint16 symbols; - enet_uint16 escapes; - enet_uint16 total; - enet_uint16 parent; -} ENetSymbol; - -/* adaptation constants tuned aggressively for small packet sizes rather than large file compression */ -enum -{ - ENET_RANGE_CODER_TOP = 1<<24, - ENET_RANGE_CODER_BOTTOM = 1<<16, - - ENET_CONTEXT_SYMBOL_DELTA = 3, - ENET_CONTEXT_SYMBOL_MINIMUM = 1, - ENET_CONTEXT_ESCAPE_MINIMUM = 1, - - ENET_SUBCONTEXT_ORDER = 2, - ENET_SUBCONTEXT_SYMBOL_DELTA = 2, - ENET_SUBCONTEXT_ESCAPE_DELTA = 5 -}; - -/* context exclusion roughly halves compression speed, so disable for now */ -#undef ENET_CONTEXT_EXCLUSION - -typedef struct _ENetRangeCoder -{ - /* only allocate enough symbols for reasonable MTUs, would need to be larger for large file compression */ - ENetSymbol symbols[4096]; -} ENetRangeCoder; - -void * -enet_range_coder_create (void) -{ - ENetRangeCoder * rangeCoder = (ENetRangeCoder *) enet_malloc (sizeof (ENetRangeCoder)); - if (rangeCoder == NULL) - return NULL; - - return rangeCoder; -} - -void -enet_range_coder_destroy (void * context) -{ - ENetRangeCoder * rangeCoder = (ENetRangeCoder *) context; - if (rangeCoder == NULL) - return; - - enet_free (rangeCoder); -} - -#define ENET_SYMBOL_CREATE(symbol, value_, count_) \ -{ \ - symbol = & rangeCoder -> symbols [nextSymbol ++]; \ - symbol -> value = value_; \ - symbol -> count = count_; \ - symbol -> under = count_; \ - symbol -> left = 0; \ - symbol -> right = 0; \ - symbol -> symbols = 0; \ - symbol -> escapes = 0; \ - symbol -> total = 0; \ - symbol -> parent = 0; \ -} - -#define ENET_CONTEXT_CREATE(context, escapes_, minimum) \ -{ \ - ENET_SYMBOL_CREATE (context, 0, 0); \ - (context) -> escapes = escapes_; \ - (context) -> total = escapes_ + 256*minimum; \ - (context) -> symbols = 0; \ -} - -static enet_uint16 -enet_symbol_rescale (ENetSymbol * symbol) -{ - enet_uint16 total = 0; - for (;;) - { - symbol -> count -= symbol->count >> 1; - symbol -> under = symbol -> count; - if (symbol -> left) - symbol -> under += enet_symbol_rescale (symbol + symbol -> left); - total += symbol -> under; - if (! symbol -> right) break; - symbol += symbol -> right; - } - return total; -} - -#define ENET_CONTEXT_RESCALE(context, minimum) \ -{ \ - (context) -> total = (context) -> symbols ? enet_symbol_rescale ((context) + (context) -> symbols) : 0; \ - (context) -> escapes -= (context) -> escapes >> 1; \ - (context) -> total += (context) -> escapes + 256*minimum; \ -} - -#define ENET_RANGE_CODER_OUTPUT(value) \ -{ \ - if (outData >= outEnd) \ - return 0; \ - * outData ++ = value; \ -} - -#define ENET_RANGE_CODER_ENCODE(under, count, total) \ -{ \ - encodeRange /= (total); \ - encodeLow += (under) * encodeRange; \ - encodeRange *= (count); \ - for (;;) \ - { \ - if((encodeLow ^ (encodeLow + encodeRange)) >= ENET_RANGE_CODER_TOP) \ - { \ - if(encodeRange >= ENET_RANGE_CODER_BOTTOM) break; \ - encodeRange = -encodeLow & (ENET_RANGE_CODER_BOTTOM - 1); \ - } \ - ENET_RANGE_CODER_OUTPUT (encodeLow >> 24); \ - encodeRange <<= 8; \ - encodeLow <<= 8; \ - } \ -} - -#define ENET_RANGE_CODER_FLUSH \ -{ \ - while (encodeLow) \ - { \ - ENET_RANGE_CODER_OUTPUT (encodeLow >> 24); \ - encodeLow <<= 8; \ - } \ -} - -#define ENET_RANGE_CODER_FREE_SYMBOLS \ -{ \ - if (nextSymbol >= sizeof (rangeCoder -> symbols) / sizeof (ENetSymbol) - ENET_SUBCONTEXT_ORDER ) \ - { \ - nextSymbol = 0; \ - ENET_CONTEXT_CREATE (root, ENET_CONTEXT_ESCAPE_MINIMUM, ENET_CONTEXT_SYMBOL_MINIMUM); \ - predicted = 0; \ - order = 0; \ - } \ -} - -#define ENET_CONTEXT_ENCODE(context, symbol_, value_, under_, count_, update, minimum) \ -{ \ - under_ = value*minimum; \ - count_ = minimum; \ - if (! (context) -> symbols) \ - { \ - ENET_SYMBOL_CREATE (symbol_, value_, update); \ - (context) -> symbols = symbol_ - (context); \ - } \ - else \ - { \ - ENetSymbol * node = (context) + (context) -> symbols; \ - for (;;) \ - { \ - if (value_ < node -> value) \ - { \ - node -> under += update; \ - if (node -> left) { node += node -> left; continue; } \ - ENET_SYMBOL_CREATE (symbol_, value_, update); \ - node -> left = symbol_ - node; \ - } \ - else \ - if (value_ > node -> value) \ - { \ - under_ += node -> under; \ - if (node -> right) { node += node -> right; continue; } \ - ENET_SYMBOL_CREATE (symbol_, value_, update); \ - node -> right = symbol_ - node; \ - } \ - else \ - { \ - count_ += node -> count; \ - under_ += node -> under - node -> count; \ - node -> under += update; \ - node -> count += update; \ - symbol_ = node; \ - } \ - break; \ - } \ - } \ -} - -#ifdef ENET_CONTEXT_EXCLUSION -static const ENetSymbol emptyContext = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -#define ENET_CONTEXT_WALK(context, body) \ -{ \ - const ENetSymbol * node = (context) + (context) -> symbols; \ - const ENetSymbol * stack [256]; \ - size_t stackSize = 0; \ - while (node -> left) \ - { \ - stack [stackSize ++] = node; \ - node += node -> left; \ - } \ - for (;;) \ - { \ - body; \ - if (node -> right) \ - { \ - node += node -> right; \ - while (node -> left) \ - { \ - stack [stackSize ++] = node; \ - node += node -> left; \ - } \ - } \ - else \ - if (stackSize <= 0) \ - break; \ - else \ - node = stack [-- stackSize]; \ - } \ -} - -#define ENET_CONTEXT_ENCODE_EXCLUDE(context, value_, under, total, minimum) \ -ENET_CONTEXT_WALK(context, { \ - if (node -> value != value_) \ - { \ - enet_uint16 parentCount = rangeCoder -> symbols [node -> parent].count + minimum; \ - if (node -> value < value_) \ - under -= parentCount; \ - total -= parentCount; \ - } \ -}) -#endif - -size_t -enet_range_coder_compress (void * context, const ENetBuffer * inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 * outData, size_t outLimit) -{ - ENetRangeCoder * rangeCoder = (ENetRangeCoder *) context; - enet_uint8 * outStart = outData, * outEnd = & outData [outLimit]; - const enet_uint8 * inData, * inEnd; - enet_uint32 encodeLow = 0, encodeRange = ~0; - ENetSymbol * root; - enet_uint16 predicted = 0; - size_t order = 0, nextSymbol = 0; - - if (rangeCoder == NULL || inBufferCount <= 0 || inLimit <= 0) - return 0; - - inData = (const enet_uint8 *) inBuffers -> data; - inEnd = & inData [inBuffers -> dataLength]; - inBuffers ++; - inBufferCount --; - - ENET_CONTEXT_CREATE (root, ENET_CONTEXT_ESCAPE_MINIMUM, ENET_CONTEXT_SYMBOL_MINIMUM); - - for (;;) - { - ENetSymbol * subcontext, * symbol; -#ifdef ENET_CONTEXT_EXCLUSION - const ENetSymbol * childContext = & emptyContext; -#endif - enet_uint8 value; - enet_uint16 count, under, * parent = & predicted, total; - if (inData >= inEnd) - { - if (inBufferCount <= 0) - break; - inData = (const enet_uint8 *) inBuffers -> data; - inEnd = & inData [inBuffers -> dataLength]; - inBuffers ++; - inBufferCount --; - } - value = * inData ++; - - for (subcontext = & rangeCoder -> symbols [predicted]; - subcontext != root; -#ifdef ENET_CONTEXT_EXCLUSION - childContext = subcontext, -#endif - subcontext = & rangeCoder -> symbols [subcontext -> parent]) - { - ENET_CONTEXT_ENCODE (subcontext, symbol, value, under, count, ENET_SUBCONTEXT_SYMBOL_DELTA, 0); - * parent = symbol - rangeCoder -> symbols; - parent = & symbol -> parent; - total = subcontext -> total; -#ifdef ENET_CONTEXT_EXCLUSION - if (childContext -> total > ENET_SUBCONTEXT_SYMBOL_DELTA + ENET_SUBCONTEXT_ESCAPE_DELTA) - ENET_CONTEXT_ENCODE_EXCLUDE (childContext, value, under, total, 0); -#endif - if (count > 0) - { - ENET_RANGE_CODER_ENCODE (subcontext -> escapes + under, count, total); - } - else - { - if (subcontext -> escapes > 0 && subcontext -> escapes < total) - ENET_RANGE_CODER_ENCODE (0, subcontext -> escapes, total); - subcontext -> escapes += ENET_SUBCONTEXT_ESCAPE_DELTA; - subcontext -> total += ENET_SUBCONTEXT_ESCAPE_DELTA; - } - subcontext -> total += ENET_SUBCONTEXT_SYMBOL_DELTA; - if (count > 0xFF - 2*ENET_SUBCONTEXT_SYMBOL_DELTA || subcontext -> total > ENET_RANGE_CODER_BOTTOM - 0x100) - ENET_CONTEXT_RESCALE (subcontext, 0); - if (count > 0) goto nextInput; - } - - ENET_CONTEXT_ENCODE (root, symbol, value, under, count, ENET_CONTEXT_SYMBOL_DELTA, ENET_CONTEXT_SYMBOL_MINIMUM); - * parent = symbol - rangeCoder -> symbols; - parent = & symbol -> parent; - total = root -> total; -#ifdef ENET_CONTEXT_EXCLUSION - if (childContext -> total > ENET_SUBCONTEXT_SYMBOL_DELTA + ENET_SUBCONTEXT_ESCAPE_DELTA) - ENET_CONTEXT_ENCODE_EXCLUDE (childContext, value, under, total, ENET_CONTEXT_SYMBOL_MINIMUM); -#endif - ENET_RANGE_CODER_ENCODE (root -> escapes + under, count, total); - root -> total += ENET_CONTEXT_SYMBOL_DELTA; - if (count > 0xFF - 2*ENET_CONTEXT_SYMBOL_DELTA + ENET_CONTEXT_SYMBOL_MINIMUM || root -> total > ENET_RANGE_CODER_BOTTOM - 0x100) - ENET_CONTEXT_RESCALE (root, ENET_CONTEXT_SYMBOL_MINIMUM); - - nextInput: - if (order >= ENET_SUBCONTEXT_ORDER) - predicted = rangeCoder -> symbols [predicted].parent; - else - order ++; - ENET_RANGE_CODER_FREE_SYMBOLS; - } - - ENET_RANGE_CODER_FLUSH; - - return (size_t) (outData - outStart); -} - -#define ENET_RANGE_CODER_SEED \ -{ \ - if (inData < inEnd) decodeCode |= * inData ++ << 24; \ - if (inData < inEnd) decodeCode |= * inData ++ << 16; \ - if (inData < inEnd) decodeCode |= * inData ++ << 8; \ - if (inData < inEnd) decodeCode |= * inData ++; \ -} - -#define ENET_RANGE_CODER_READ(total) ((decodeCode - decodeLow) / (decodeRange /= (total))) - -#define ENET_RANGE_CODER_DECODE(under, count, total) \ -{ \ - decodeLow += (under) * decodeRange; \ - decodeRange *= (count); \ - for (;;) \ - { \ - if((decodeLow ^ (decodeLow + decodeRange)) >= ENET_RANGE_CODER_TOP) \ - { \ - if(decodeRange >= ENET_RANGE_CODER_BOTTOM) break; \ - decodeRange = -decodeLow & (ENET_RANGE_CODER_BOTTOM - 1); \ - } \ - decodeCode <<= 8; \ - if (inData < inEnd) \ - decodeCode |= * inData ++; \ - decodeRange <<= 8; \ - decodeLow <<= 8; \ - } \ -} - -#define ENET_CONTEXT_DECODE(context, symbol_, code, value_, under_, count_, update, minimum, createRoot, visitNode, createRight, createLeft) \ -{ \ - under_ = 0; \ - count_ = minimum; \ - if (! (context) -> symbols) \ - { \ - createRoot; \ - } \ - else \ - { \ - ENetSymbol * node = (context) + (context) -> symbols; \ - for (;;) \ - { \ - enet_uint16 after = under_ + node -> under + (node -> value + 1)*minimum, before = node -> count + minimum; \ - visitNode; \ - if (code >= after) \ - { \ - under_ += node -> under; \ - if (node -> right) { node += node -> right; continue; } \ - createRight; \ - } \ - else \ - if (code < after - before) \ - { \ - node -> under += update; \ - if (node -> left) { node += node -> left; continue; } \ - createLeft; \ - } \ - else \ - { \ - value_ = node -> value; \ - count_ += node -> count; \ - under_ = after - before; \ - node -> under += update; \ - node -> count += update; \ - symbol_ = node; \ - } \ - break; \ - } \ - } \ -} - -#define ENET_CONTEXT_TRY_DECODE(context, symbol_, code, value_, under_, count_, update, minimum, exclude) \ -ENET_CONTEXT_DECODE (context, symbol_, code, value_, under_, count_, update, minimum, return 0, exclude (node -> value, after, before), return 0, return 0) - -#define ENET_CONTEXT_ROOT_DECODE(context, symbol_, code, value_, under_, count_, update, minimum, exclude) \ -ENET_CONTEXT_DECODE (context, symbol_, code, value_, under_, count_, update, minimum, \ - { \ - value_ = code / minimum; \ - under_ = code - code%minimum; \ - ENET_SYMBOL_CREATE (symbol_, value_, update); \ - (context) -> symbols = symbol_ - (context); \ - }, \ - exclude (node -> value, after, before), \ - { \ - value_ = node->value + 1 + (code - after)/minimum; \ - under_ = code - (code - after)%minimum; \ - ENET_SYMBOL_CREATE (symbol_, value_, update); \ - node -> right = symbol_ - node; \ - }, \ - { \ - value_ = node->value - 1 - (after - before - code - 1)/minimum; \ - under_ = code - (after - before - code - 1)%minimum; \ - ENET_SYMBOL_CREATE (symbol_, value_, update); \ - node -> left = symbol_ - node; \ - }) \ - -#ifdef ENET_CONTEXT_EXCLUSION -typedef struct _ENetExclude -{ - enet_uint8 value; - enet_uint16 under; -} ENetExclude; - -#define ENET_CONTEXT_DECODE_EXCLUDE(context, total, minimum) \ -{ \ - enet_uint16 under = 0; \ - nextExclude = excludes; \ - ENET_CONTEXT_WALK (context, { \ - under += rangeCoder -> symbols [node -> parent].count + minimum; \ - nextExclude -> value = node -> value; \ - nextExclude -> under = under; \ - nextExclude ++; \ - }); \ - total -= under; \ -} - -#define ENET_CONTEXT_EXCLUDED(value_, after, before) \ -{ \ - size_t low = 0, high = nextExclude - excludes; \ - for(;;) \ - { \ - size_t mid = (low + high) >> 1; \ - const ENetExclude * exclude = & excludes [mid]; \ - if (value_ < exclude -> value) \ - { \ - if (low + 1 < high) \ - { \ - high = mid; \ - continue; \ - } \ - if (exclude > excludes) \ - after -= exclude [-1].under; \ - } \ - else \ - { \ - if (value_ > exclude -> value) \ - { \ - if (low + 1 < high) \ - { \ - low = mid; \ - continue; \ - } \ - } \ - else \ - before = 0; \ - after -= exclude -> under; \ - } \ - break; \ - } \ -} -#endif - -#define ENET_CONTEXT_NOT_EXCLUDED(value_, after, before) - -size_t -enet_range_coder_decompress (void * context, const enet_uint8 * inData, size_t inLimit, enet_uint8 * outData, size_t outLimit) -{ - ENetRangeCoder * rangeCoder = (ENetRangeCoder *) context; - enet_uint8 * outStart = outData, * outEnd = & outData [outLimit]; - const enet_uint8 * inEnd = & inData [inLimit]; - enet_uint32 decodeLow = 0, decodeCode = 0, decodeRange = ~0; - ENetSymbol * root; - enet_uint16 predicted = 0; - size_t order = 0, nextSymbol = 0; -#ifdef ENET_CONTEXT_EXCLUSION - ENetExclude excludes [256]; - ENetExclude * nextExclude = excludes; -#endif - - if (rangeCoder == NULL || inLimit <= 0) - return 0; - - ENET_CONTEXT_CREATE (root, ENET_CONTEXT_ESCAPE_MINIMUM, ENET_CONTEXT_SYMBOL_MINIMUM); - - ENET_RANGE_CODER_SEED; - - for (;;) - { - ENetSymbol * subcontext, * symbol, * patch; -#ifdef ENET_CONTEXT_EXCLUSION - const ENetSymbol * childContext = & emptyContext; -#endif - enet_uint8 value = 0; - enet_uint16 code, under, count, bottom, * parent = & predicted, total; - - for (subcontext = & rangeCoder -> symbols [predicted]; - subcontext != root; -#ifdef ENET_CONTEXT_EXCLUSION - childContext = subcontext, -#endif - subcontext = & rangeCoder -> symbols [subcontext -> parent]) - { - if (subcontext -> escapes <= 0) - continue; - total = subcontext -> total; -#ifdef ENET_CONTEXT_EXCLUSION - if (childContext -> total > 0) - ENET_CONTEXT_DECODE_EXCLUDE (childContext, total, 0); -#endif - if (subcontext -> escapes >= total) - continue; - code = ENET_RANGE_CODER_READ (total); - if (code < subcontext -> escapes) - { - ENET_RANGE_CODER_DECODE (0, subcontext -> escapes, total); - continue; - } - code -= subcontext -> escapes; -#ifdef ENET_CONTEXT_EXCLUSION - if (childContext -> total > 0) - { - ENET_CONTEXT_TRY_DECODE (subcontext, symbol, code, value, under, count, ENET_SUBCONTEXT_SYMBOL_DELTA, 0, ENET_CONTEXT_EXCLUDED); - } - else -#endif - { - ENET_CONTEXT_TRY_DECODE (subcontext, symbol, code, value, under, count, ENET_SUBCONTEXT_SYMBOL_DELTA, 0, ENET_CONTEXT_NOT_EXCLUDED); - } - bottom = symbol - rangeCoder -> symbols; - ENET_RANGE_CODER_DECODE (subcontext -> escapes + under, count, total); - subcontext -> total += ENET_SUBCONTEXT_SYMBOL_DELTA; - if (count > 0xFF - 2*ENET_SUBCONTEXT_SYMBOL_DELTA || subcontext -> total > ENET_RANGE_CODER_BOTTOM - 0x100) - ENET_CONTEXT_RESCALE (subcontext, 0); - goto patchContexts; - } - - total = root -> total; -#ifdef ENET_CONTEXT_EXCLUSION - if (childContext -> total > 0) - ENET_CONTEXT_DECODE_EXCLUDE (childContext, total, ENET_CONTEXT_SYMBOL_MINIMUM); -#endif - code = ENET_RANGE_CODER_READ (total); - if (code < root -> escapes) - { - ENET_RANGE_CODER_DECODE (0, root -> escapes, total); - break; - } - code -= root -> escapes; -#ifdef ENET_CONTEXT_EXCLUSION - if (childContext -> total > 0) - { - ENET_CONTEXT_ROOT_DECODE (root, symbol, code, value, under, count, ENET_CONTEXT_SYMBOL_DELTA, ENET_CONTEXT_SYMBOL_MINIMUM, ENET_CONTEXT_EXCLUDED); - } - else -#endif - { - ENET_CONTEXT_ROOT_DECODE (root, symbol, code, value, under, count, ENET_CONTEXT_SYMBOL_DELTA, ENET_CONTEXT_SYMBOL_MINIMUM, ENET_CONTEXT_NOT_EXCLUDED); - } - bottom = symbol - rangeCoder -> symbols; - ENET_RANGE_CODER_DECODE (root -> escapes + under, count, total); - root -> total += ENET_CONTEXT_SYMBOL_DELTA; - if (count > 0xFF - 2*ENET_CONTEXT_SYMBOL_DELTA + ENET_CONTEXT_SYMBOL_MINIMUM || root -> total > ENET_RANGE_CODER_BOTTOM - 0x100) - ENET_CONTEXT_RESCALE (root, ENET_CONTEXT_SYMBOL_MINIMUM); - - patchContexts: - for (patch = & rangeCoder -> symbols [predicted]; - patch != subcontext; - patch = & rangeCoder -> symbols [patch -> parent]) - { - ENET_CONTEXT_ENCODE (patch, symbol, value, under, count, ENET_SUBCONTEXT_SYMBOL_DELTA, 0); - * parent = symbol - rangeCoder -> symbols; - parent = & symbol -> parent; - if (count <= 0) - { - patch -> escapes += ENET_SUBCONTEXT_ESCAPE_DELTA; - patch -> total += ENET_SUBCONTEXT_ESCAPE_DELTA; - } - patch -> total += ENET_SUBCONTEXT_SYMBOL_DELTA; - if (count > 0xFF - 2*ENET_SUBCONTEXT_SYMBOL_DELTA || patch -> total > ENET_RANGE_CODER_BOTTOM - 0x100) - ENET_CONTEXT_RESCALE (patch, 0); - } - * parent = bottom; - - ENET_RANGE_CODER_OUTPUT (value); - - if (order >= ENET_SUBCONTEXT_ORDER) - predicted = rangeCoder -> symbols [predicted].parent; - else - order ++; - ENET_RANGE_CODER_FREE_SYMBOLS; - } - - return (size_t) (outData - outStart); -} - -/** @defgroup host ENet host functions - @{ -*/ - -/** Sets the packet compressor the host should use to the default range coder. - @param host host to enable the range coder for - @returns 0 on success, < 0 on failure -*/ -int -enet_host_compress_with_range_coder (ENetHost * host) -{ - ENetCompressor compressor; - memset (& compressor, 0, sizeof (compressor)); - compressor.context = enet_range_coder_create(); - if (compressor.context == NULL) - return -1; - compressor.compress = enet_range_coder_compress; - compressor.decompress = enet_range_coder_decompress; - compressor.destroy = enet_range_coder_destroy; - enet_host_compress (host, & compressor); - return 0; -} - -/** @} */ - - diff --git a/src/enet/design.txt b/src/enet/design.txt deleted file mode 100644 index 9a88dba9f..000000000 --- a/src/enet/design.txt +++ /dev/null @@ -1,117 +0,0 @@ -* Why ENet? - - ENet evolved specifically as a UDP networking layer for the multiplayer -first person shooter Cube. Cube necessitated low latency communcation with -data sent out very frequently, so TCP was an unsuitable choice due to its -high latency and stream orientation. UDP, however, lacks many sometimes -necessary features from TCP such as reliability, sequencing, unrestricted -packet sizes, and connection management. So UDP by itself was not suitable -as a network protocol either. No suitable freely available networking -libraries existed at the time of ENet's creation to fill this niche. - - UDP and TCP could have been used together in Cube to benefit somewhat -from both of their features, however, the resulting combinations of protocols -still leaves much to be desired. TCP lacks multiple streams of communication -without resorting to opening many sockets and complicates delineation of -packets due to its buffering behavior. UDP lacks sequencing, connection -management, management of bandwidth resources, and imposes limitations on -the size of packets. A significant investment is required to integrate these -two protocols, and the end result is worse off in features and performance -than the uniform protocol presented by ENet. - - ENet thus attempts to address these issues and provide a single, uniform -protocol layered over UDP to the developer with the best features of UDP and -TCP as well as some useful features neither provide, with a much cleaner -integration than any resulting from a mixture of UDP and TCP. - -* Connection management - - ENet provides a simple connection interface over which to communicate -with a foreign host. The liveness of the connection is actively monitored -by pinging the foreign host at frequent intervals, and also monitors the -network conditions from the local host to the foreign host such as the -mean round trip time and packet loss in this fashion. - -* Sequencing - - Rather than a single byte stream that complicates the delineation -of packets, ENet presents connections as multiple, properly sequenced packet -streams that simplify the transfer of various types of data. - - ENet provides sequencing for all packets by assigning to each sent -packet a sequence number that is incremented as packets are sent. ENet -guarentees that no packet with a higher sequence number will be delivered -before a packet with a lower sequence number, thus ensuring packets are -delivered exactly in the order they are sent. - - For unreliable packets, ENet will simply discard the lower sequence -number packet if a packet with a higher sequence number has already been -delivered. This allows the packets to be dispatched immediately as they -arrive, and reduce latency of unreliable packets to an absolute minimum. -For reliable packets, if a higher sequence number packet arrives, but the -preceding packets in the sequence have not yet arrived, ENet will stall -delivery of the higher sequence number packets until its predecessors -have arrived. - -* Channels - - Since ENet will stall delivery of reliable packets to ensure proper -sequencing, and consequently any packets of higher sequence number whether -reliable or unreliable, in the event the reliable packet's predecessors -have not yet arrived, this can introduce latency into the delivery of other -packets which may not need to be as strictly ordered with respect to the -packet that stalled their delivery. - - To combat this latency and reduce the ordering restrictions on packets, -ENet provides multiple channels of communication over a given connection. -Each channel is independently sequenced, and so the delivery status of -a packet in one channel will not stall the delivery of other packets -in another channel. - -* Reliability - - ENet provides optional reliability of packet delivery by ensuring the -foreign host acknowledges receipt of all reliable packets. ENet will attempt -to resend the packet up to a reasonable amount of times, if no acknowledgement -of the packet's receipt happens within a specified timeout. Retry timeouts -are progressive and become more lenient with every failed attempt to allow -for temporary turbulence in network conditions. - -* Fragmentation and reassembly - - ENet will send and deliver packets regardless of size. Large packets are -fragmented into many smaller packets of suitable size, and reassembled on -the foreign host to recover the original packet for delivery. The process -is entirely transparent to the developer. - -* Aggregation - - ENet aggregates all protocol commands, including acknowledgements and -packet transfer, into larger protocol packets to ensure the proper utilization -of the connection and to limit the opportunities for packet loss that might -otherwise result in further delivery latency. - -* Adaptability - - ENet provides an in-flight data window for reliable packets to ensure -connections are not overwhelmed by volumes of packets. It also provides a -static bandwidth allocation mechanism to ensure the total volume of packets -sent and received to a host don't exceed the host's capabilities. Further, -ENet also provides a dynamic throttle that responds to deviations from normal -network connections to rectify various types of network congestion by further -limiting the volume of packets sent. - -* Portability - - ENet works on Windows and any other Unix or Unix-like platform providing -a BSD sockets interface. The library has a small and stable code base that -can easily be extended to support other platforms and integrates easily. - -* Freedom - - ENet demands no royalties and doesn't carry a viral license that would -restrict you in how you might use it in your programs. ENet is licensed under -a short-and-sweet MIT-style license, which gives you the freedom to do anything -you want with it (well, almost anything). - - diff --git a/src/enet/enet.h b/src/enet/enet.h deleted file mode 100644 index 2f656d6cb..000000000 --- a/src/enet/enet.h +++ /dev/null @@ -1,540 +0,0 @@ -/** - @file enet.h - @brief ENet public header file -*/ -#ifndef __ENET_ENET_H__ -#define __ENET_ENET_H__ - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include <stdlib.h> - -#ifdef WIN32 -#include "enet/win32.h" -#else -#include "enet/unix.h" -#endif - -#include "enet/types.h" -#include "enet/protocol.h" -#include "enet/list.h" -#include "enet/callbacks.h" - -#define ENET_VERSION_MAJOR 1 -#define ENET_VERSION_MINOR 3 -#define ENET_VERSION_PATCH 0 -#define ENET_VERSION_CREATE(major, minor, patch) (((major)<<16) | ((minor)<<8) | (patch)) -#define ENET_VERSION ENET_VERSION_CREATE(ENET_VERSION_MAJOR, ENET_VERSION_MINOR, ENET_VERSION_PATCH) - -typedef enet_uint32 ENetVersion; - -typedef enum _ENetSocketType -{ - ENET_SOCKET_TYPE_STREAM = 1, - ENET_SOCKET_TYPE_DATAGRAM = 2 -} ENetSocketType; - -typedef enum _ENetSocketWait -{ - ENET_SOCKET_WAIT_NONE = 0, - ENET_SOCKET_WAIT_SEND = (1 << 0), - ENET_SOCKET_WAIT_RECEIVE = (1 << 1) -} ENetSocketWait; - -typedef enum _ENetSocketOption -{ - ENET_SOCKOPT_NONBLOCK = 1, - ENET_SOCKOPT_BROADCAST = 2, - ENET_SOCKOPT_RCVBUF = 3, - ENET_SOCKOPT_SNDBUF = 4, - ENET_SOCKOPT_REUSEADDR = 5 -} ENetSocketOption; - -enum -{ - ENET_HOST_ANY = 0, /**< specifies the default server host */ - ENET_HOST_BROADCAST = 0xFFFFFFFF, /**< specifies a subnet-wide broadcast */ - - ENET_PORT_ANY = 0 /**< specifies that a port should be automatically chosen */ -}; - -/** - * Portable internet address structure. - * - * The host must be specified in network byte-order, and the port must be in host - * byte-order. The constant ENET_HOST_ANY may be used to specify the default - * server host. The constant ENET_HOST_BROADCAST may be used to specify the - * broadcast address (255.255.255.255). This makes sense for enet_host_connect, - * but not for enet_host_create. Once a server responds to a broadcast, the - * address is updated from ENET_HOST_BROADCAST to the server's actual IP address. - */ -typedef struct _ENetAddress -{ - enet_uint32 host; - enet_uint16 port; -} ENetAddress; - -/** - * Packet flag bit constants. - * - * The host must be specified in network byte-order, and the port must be in - * host byte-order. The constant ENET_HOST_ANY may be used to specify the - * default server host. - - @sa ENetPacket -*/ -typedef enum _ENetPacketFlag -{ - /** packet must be received by the target peer and resend attempts should be - * made until the packet is delivered */ - ENET_PACKET_FLAG_RELIABLE = (1 << 0), - /** packet will not be sequenced with other packets - * not supported for reliable packets - */ - ENET_PACKET_FLAG_UNSEQUENCED = (1 << 1), - /** packet will not allocate data, and user must supply it instead */ - ENET_PACKET_FLAG_NO_ALLOCATE = (1 << 2) -} ENetPacketFlag; - -struct _ENetPacket; -typedef void (ENET_CALLBACK * ENetPacketFreeCallback) (struct _ENetPacket *); - -/** - * ENet packet structure. - * - * An ENet data packet that may be sent to or received from a peer. The shown - * fields should only be read and never modified. The data field contains the - * allocated data for the packet. The dataLength fields specifies the length - * of the allocated data. The flags field is either 0 (specifying no flags), - * or a bitwise-or of any combination of the following flags: - * - * ENET_PACKET_FLAG_RELIABLE - packet must be received by the target peer - * and resend attempts should be made until the packet is delivered - * - * ENET_PACKET_FLAG_UNSEQUENCED - packet will not be sequenced with other packets - * (not supported for reliable packets) - * - * ENET_PACKET_FLAG_NO_ALLOCATE - packet will not allocate data, and user must supply it instead - - @sa ENetPacketFlag - */ -typedef struct _ENetPacket -{ - size_t referenceCount; /**< internal use only */ - enet_uint32 flags; /**< bitwise-or of ENetPacketFlag constants */ - enet_uint8 * data; /**< allocated data for packet */ - size_t dataLength; /**< length of data */ - ENetPacketFreeCallback freeCallback; /**< function to be called when the packet is no longer in use */ -} ENetPacket; - -typedef struct _ENetAcknowledgement -{ - ENetListNode acknowledgementList; - enet_uint32 sentTime; - ENetProtocol command; -} ENetAcknowledgement; - -typedef struct _ENetOutgoingCommand -{ - ENetListNode outgoingCommandList; - enet_uint16 reliableSequenceNumber; - enet_uint16 unreliableSequenceNumber; - enet_uint32 sentTime; - enet_uint32 roundTripTimeout; - enet_uint32 roundTripTimeoutLimit; - enet_uint32 fragmentOffset; - enet_uint16 fragmentLength; - enet_uint16 sendAttempts; - ENetProtocol command; - ENetPacket * packet; -} ENetOutgoingCommand; - -typedef struct _ENetIncomingCommand -{ - ENetListNode incomingCommandList; - enet_uint16 reliableSequenceNumber; - enet_uint16 unreliableSequenceNumber; - ENetProtocol command; - enet_uint32 fragmentCount; - enet_uint32 fragmentsRemaining; - enet_uint32 * fragments; - ENetPacket * packet; -} ENetIncomingCommand; - -typedef enum _ENetPeerState -{ - ENET_PEER_STATE_DISCONNECTED = 0, - ENET_PEER_STATE_CONNECTING = 1, - ENET_PEER_STATE_ACKNOWLEDGING_CONNECT = 2, - ENET_PEER_STATE_CONNECTION_PENDING = 3, - ENET_PEER_STATE_CONNECTION_SUCCEEDED = 4, - ENET_PEER_STATE_CONNECTED = 5, - ENET_PEER_STATE_DISCONNECT_LATER = 6, - ENET_PEER_STATE_DISCONNECTING = 7, - ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT = 8, - ENET_PEER_STATE_ZOMBIE = 9 -} ENetPeerState; - -#ifndef ENET_BUFFER_MAXIMUM -#define ENET_BUFFER_MAXIMUM (1 + 2 * ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS) -#endif - -enum -{ - ENET_HOST_RECEIVE_BUFFER_SIZE = 256 * 1024, - ENET_HOST_SEND_BUFFER_SIZE = 256 * 1024, - ENET_HOST_BANDWIDTH_THROTTLE_INTERVAL = 1000, - ENET_HOST_DEFAULT_MTU = 1400, - - ENET_PEER_DEFAULT_ROUND_TRIP_TIME = 500, - ENET_PEER_DEFAULT_PACKET_THROTTLE = 32, - ENET_PEER_PACKET_THROTTLE_SCALE = 32, - ENET_PEER_PACKET_THROTTLE_COUNTER = 7, - ENET_PEER_PACKET_THROTTLE_ACCELERATION = 2, - ENET_PEER_PACKET_THROTTLE_DECELERATION = 2, - ENET_PEER_PACKET_THROTTLE_INTERVAL = 5000, - ENET_PEER_PACKET_LOSS_SCALE = (1 << 16), - ENET_PEER_PACKET_LOSS_INTERVAL = 10000, - ENET_PEER_WINDOW_SIZE_SCALE = 64 * 1024, - ENET_PEER_TIMEOUT_LIMIT = 32, - ENET_PEER_TIMEOUT_MINIMUM = 5000, - ENET_PEER_TIMEOUT_MAXIMUM = 30000, - ENET_PEER_PING_INTERVAL = 500, - ENET_PEER_UNSEQUENCED_WINDOWS = 64, - ENET_PEER_UNSEQUENCED_WINDOW_SIZE = 1024, - ENET_PEER_FREE_UNSEQUENCED_WINDOWS = 32, - ENET_PEER_RELIABLE_WINDOWS = 16, - ENET_PEER_RELIABLE_WINDOW_SIZE = 0x1000, - ENET_PEER_FREE_RELIABLE_WINDOWS = 8 -}; - -typedef struct _ENetChannel -{ - enet_uint16 outgoingReliableSequenceNumber; - enet_uint16 outgoingUnreliableSequenceNumber; - enet_uint16 usedReliableWindows; - enet_uint16 reliableWindows [ENET_PEER_RELIABLE_WINDOWS]; - enet_uint16 incomingReliableSequenceNumber; - ENetList incomingReliableCommands; - ENetList incomingUnreliableCommands; -} ENetChannel; - -/** - * An ENet peer which data packets may be sent or received from. - * - * No fields should be modified unless otherwise specified. - */ -typedef struct _ENetPeer -{ - ENetListNode dispatchList; - struct _ENetHost * host; - enet_uint16 outgoingPeerID; - enet_uint16 incomingPeerID; - enet_uint32 connectID; - enet_uint8 outgoingSessionID; - enet_uint8 incomingSessionID; - ENetAddress address; /**< Internet address of the peer */ - void * data; /**< Application private data, may be freely modified */ - ENetPeerState state; - ENetChannel * channels; - size_t channelCount; /**< Number of channels allocated for communication with peer */ - enet_uint32 incomingBandwidth; /**< Downstream bandwidth of the client in bytes/second */ - enet_uint32 outgoingBandwidth; /**< Upstream bandwidth of the client in bytes/second */ - enet_uint32 incomingBandwidthThrottleEpoch; - enet_uint32 outgoingBandwidthThrottleEpoch; - enet_uint32 incomingDataTotal; - enet_uint32 outgoingDataTotal; - enet_uint32 lastSendTime; - enet_uint32 lastReceiveTime; - enet_uint32 nextTimeout; - enet_uint32 earliestTimeout; - enet_uint32 packetLossEpoch; - enet_uint32 packetsSent; - enet_uint32 packetsLost; - enet_uint32 packetLoss; /**< mean packet loss of reliable packets as a ratio with respect to the constant ENET_PEER_PACKET_LOSS_SCALE */ - enet_uint32 packetLossVariance; - enet_uint32 packetThrottle; - enet_uint32 packetThrottleLimit; - enet_uint32 packetThrottleCounter; - enet_uint32 packetThrottleEpoch; - enet_uint32 packetThrottleAcceleration; - enet_uint32 packetThrottleDeceleration; - enet_uint32 packetThrottleInterval; - enet_uint32 lastRoundTripTime; - enet_uint32 lowestRoundTripTime; - enet_uint32 lastRoundTripTimeVariance; - enet_uint32 highestRoundTripTimeVariance; - enet_uint32 roundTripTime; /**< mean round trip time (RTT), in milliseconds, between sending a reliable packet and receiving its acknowledgement */ - enet_uint32 roundTripTimeVariance; - enet_uint32 mtu; - enet_uint32 windowSize; - enet_uint32 reliableDataInTransit; - enet_uint16 outgoingReliableSequenceNumber; - ENetList acknowledgements; - ENetList sentReliableCommands; - ENetList sentUnreliableCommands; - ENetList outgoingReliableCommands; - ENetList outgoingUnreliableCommands; - ENetList dispatchedCommands; - int needsDispatch; - enet_uint16 incomingUnsequencedGroup; - enet_uint16 outgoingUnsequencedGroup; - enet_uint32 unsequencedWindow [ENET_PEER_UNSEQUENCED_WINDOW_SIZE / 32]; - enet_uint32 eventData; -} ENetPeer; - -/** An ENet packet compressor for compressing UDP packets before socket sends or receives. - */ -typedef struct _ENetCompressor -{ - /** Context data for the compressor. Must be non-NULL. */ - void * context; - /** Compresses from inBuffers[0:inBufferCount-1], containing inLimit bytes, to outData, outputting at most outLimit bytes. Should return 0 on failure. */ - size_t (ENET_CALLBACK * compress) (void * context, const ENetBuffer * inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 * outData, size_t outLimit); - /** Decompresses from inData, containing inLimit bytes, to outData, outputting at most outLimit bytes. Should return 0 on failure. */ - size_t (ENET_CALLBACK * decompress) (void * context, const enet_uint8 * inData, size_t inLimit, enet_uint8 * outData, size_t outLimit); - /** Destroys the context when compression is disabled or the host is destroyed. May be NULL. */ - void (ENET_CALLBACK * destroy) (void * context); -} ENetCompressor; - -/** Callback that computes the checksum of the data held in buffers[0:bufferCount-1] */ -typedef enet_uint32 (ENET_CALLBACK * ENetChecksumCallback) (const ENetBuffer * buffers, size_t bufferCount); - -/** An ENet host for communicating with peers. - * - * No fields should be modified unless otherwise stated. - - @sa enet_host_create() - @sa enet_host_destroy() - @sa enet_host_connect() - @sa enet_host_service() - @sa enet_host_flush() - @sa enet_host_broadcast() - @sa enet_host_compress() - @sa enet_host_compress_with_range_coder() - @sa enet_host_channel_limit() - @sa enet_host_bandwidth_limit() - @sa enet_host_bandwidth_throttle() - */ -typedef struct _ENetHost -{ - ENetSocket socket; - ENetAddress address; /**< Internet address of the host */ - enet_uint32 incomingBandwidth; /**< downstream bandwidth of the host */ - enet_uint32 outgoingBandwidth; /**< upstream bandwidth of the host */ - enet_uint32 bandwidthThrottleEpoch; - enet_uint32 mtu; - enet_uint32 randomSeed; - int recalculateBandwidthLimits; - ENetPeer * peers; /**< array of peers allocated for this host */ - size_t peerCount; /**< number of peers allocated for this host */ - size_t channelLimit; /**< maximum number of channels allowed for connected peers */ - enet_uint32 serviceTime; - ENetList dispatchQueue; - int continueSending; - size_t packetSize; - enet_uint16 headerFlags; - ENetProtocol commands [ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS]; - size_t commandCount; - ENetBuffer buffers [ENET_BUFFER_MAXIMUM]; - size_t bufferCount; - ENetChecksumCallback checksum; /**< callback the user can set to enable packet checksums for this host */ - ENetCompressor compressor; - enet_uint8 packetData [2][ENET_PROTOCOL_MAXIMUM_MTU]; - ENetAddress receivedAddress; - enet_uint8 * receivedData; - size_t receivedDataLength; - enet_uint32 totalSentData; /**< total data sent, user should reset to 0 as needed to prevent overflow */ - enet_uint32 totalSentPackets; /**< total UDP packets sent, user should reset to 0 as needed to prevent overflow */ - enet_uint32 totalReceivedData; /**< total data received, user should reset to 0 as needed to prevent overflow */ - enet_uint32 totalReceivedPackets; /**< total UDP packets received, user should reset to 0 as needed to prevent overflow */ -} ENetHost; - -/** - * An ENet event type, as specified in @ref ENetEvent. - */ -typedef enum _ENetEventType -{ - /** no event occurred within the specified time limit */ - ENET_EVENT_TYPE_NONE = 0, - - /** a connection request initiated by enet_host_connect has completed. - * The peer field contains the peer which successfully connected. - */ - ENET_EVENT_TYPE_CONNECT = 1, - - /** a peer has disconnected. This event is generated on a successful - * completion of a disconnect initiated by enet_pper_disconnect, if - * a peer has timed out, or if a connection request intialized by - * enet_host_connect has timed out. The peer field contains the peer - * which disconnected. The data field contains user supplied data - * describing the disconnection, or 0, if none is available. - */ - ENET_EVENT_TYPE_DISCONNECT = 2, - - /** a packet has been received from a peer. The peer field specifies the - * peer which sent the packet. The channelID field specifies the channel - * number upon which the packet was received. The packet field contains - * the packet that was received; this packet must be destroyed with - * enet_packet_destroy after use. - */ - ENET_EVENT_TYPE_RECEIVE = 3 -} ENetEventType; - -/** - * An ENet event as returned by enet_host_service(). - - @sa enet_host_service - */ -typedef struct _ENetEvent -{ - ENetEventType type; /**< type of the event */ - ENetPeer * peer; /**< peer that generated a connect, disconnect or receive event */ - enet_uint8 channelID; /**< channel on the peer that generated the event, if appropriate */ - enet_uint32 data; /**< data associated with the event, if appropriate */ - ENetPacket * packet; /**< packet associated with the event, if appropriate */ -} ENetEvent; - -/** @defgroup global ENet global functions - @{ -*/ - -/** - Initializes ENet globally. Must be called prior to using any functions in - ENet. - @returns 0 on success, < 0 on failure -*/ -ENET_API int enet_initialize (void); - -/** - Initializes ENet globally and supplies user-overridden callbacks. Must be called prior to using any functions in ENet. Do not use enet_initialize() if you use this variant. Make sure the ENetCallbacks structure is zeroed out so that any additional callbacks added in future versions will be properly ignored. - - @param version the constant ENET_VERSION should be supplied so ENet knows which version of ENetCallbacks struct to use - @param inits user-overriden callbacks where any NULL callbacks will use ENet's defaults - @returns 0 on success, < 0 on failure -*/ -ENET_API int enet_initialize_with_callbacks (ENetVersion version, const ENetCallbacks * inits); - -/** - Shuts down ENet globally. Should be called when a program that has - initialized ENet exits. -*/ -ENET_API void enet_deinitialize (void); - -/** @} */ - -/** @defgroup private ENet private implementation functions */ - -/** - Returns the wall-time in milliseconds. Its initial value is unspecified - unless otherwise set. - */ -ENET_API enet_uint32 enet_time_get (void); -/** - Sets the current wall-time in milliseconds. - */ -ENET_API void enet_time_set (enet_uint32); - -/** @defgroup socket ENet socket functions - @{ -*/ -ENET_API ENetSocket enet_socket_create (ENetSocketType); -ENET_API int enet_socket_bind (ENetSocket, const ENetAddress *); -ENET_API int enet_socket_listen (ENetSocket, int); -ENET_API ENetSocket enet_socket_accept (ENetSocket, ENetAddress *); -ENET_API int enet_socket_connect (ENetSocket, const ENetAddress *); -ENET_API int enet_socket_send (ENetSocket, const ENetAddress *, const ENetBuffer *, size_t); -ENET_API int enet_socket_receive (ENetSocket, ENetAddress *, ENetBuffer *, size_t); -ENET_API int enet_socket_wait (ENetSocket, enet_uint32 *, enet_uint32); -ENET_API int enet_socket_set_option (ENetSocket, ENetSocketOption, int); -ENET_API void enet_socket_destroy (ENetSocket); -ENET_API int enet_socketset_select (ENetSocket, ENetSocketSet *, ENetSocketSet *, enet_uint32); - -/** @} */ - -/** @defgroup Address ENet address functions - @{ -*/ -/** Attempts to resolve the host named by the parameter hostName and sets - the host field in the address parameter if successful. - @param address destination to store resolved address - @param hostName host name to lookup - @retval 0 on success - @retval < 0 on failure - @returns the address of the given hostName in address on success -*/ -ENET_API int enet_address_set_host (ENetAddress * address, const char * hostName); - -/** Gives the printable form of the ip address specified in the address parameter. - @param address address printed - @param hostName destination for name, must not be NULL - @param nameLength maximum length of hostName. - @returns the null-terminated name of the host in hostName on success - @retval 0 on success - @retval < 0 on failure -*/ -ENET_API int enet_address_get_host_ip (const ENetAddress * address, char * hostName, size_t nameLength); - -/** Attempts to do a reverse lookup of the host field in the address parameter. - @param address address used for reverse lookup - @param hostName destination for name, must not be NULL - @param nameLength maximum length of hostName. - @returns the null-terminated name of the host in hostName on success - @retval 0 on success - @retval < 0 on failure -*/ -ENET_API int enet_address_get_host (const ENetAddress * address, char * hostName, size_t nameLength); - -/** @} */ - -ENET_API ENetPacket * enet_packet_create (const void *, size_t, enet_uint32); -ENET_API void enet_packet_destroy (ENetPacket *); -ENET_API int enet_packet_resize (ENetPacket *, size_t); -extern enet_uint32 enet_crc32 (const ENetBuffer *, size_t); - -ENET_API ENetHost * enet_host_create (const ENetAddress *, size_t, size_t, enet_uint32, enet_uint32); -ENET_API void enet_host_destroy (ENetHost *); -ENET_API ENetPeer * enet_host_connect (ENetHost *, const ENetAddress *, size_t, enet_uint32); -ENET_API int enet_host_check_events (ENetHost *, ENetEvent *); -ENET_API int enet_host_service (ENetHost *, ENetEvent *, enet_uint32); -ENET_API void enet_host_flush (ENetHost *); -ENET_API void enet_host_broadcast (ENetHost *, enet_uint8, ENetPacket *); -ENET_API void enet_host_compress (ENetHost *, const ENetCompressor *); -ENET_API int enet_host_compress_with_range_coder (ENetHost * host); -ENET_API void enet_host_channel_limit (ENetHost *, size_t); -ENET_API void enet_host_bandwidth_limit (ENetHost *, enet_uint32, enet_uint32); -extern void enet_host_bandwidth_throttle (ENetHost *); - -ENET_API int enet_peer_send (ENetPeer *, enet_uint8, ENetPacket *); -ENET_API ENetPacket * enet_peer_receive (ENetPeer *, enet_uint8 * channelID); -ENET_API void enet_peer_ping (ENetPeer *); -ENET_API void enet_peer_reset (ENetPeer *); -ENET_API void enet_peer_disconnect (ENetPeer *, enet_uint32); -ENET_API void enet_peer_disconnect_now (ENetPeer *, enet_uint32); -ENET_API void enet_peer_disconnect_later (ENetPeer *, enet_uint32); -ENET_API void enet_peer_throttle_configure (ENetPeer *, enet_uint32, enet_uint32, enet_uint32); -extern int enet_peer_throttle (ENetPeer *, enet_uint32); -extern void enet_peer_reset_queues (ENetPeer *); -extern void enet_peer_setup_outgoing_command (ENetPeer *, ENetOutgoingCommand *); -extern ENetOutgoingCommand * enet_peer_queue_outgoing_command (ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32, enet_uint16); -extern ENetIncomingCommand * enet_peer_queue_incoming_command (ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32); -extern ENetAcknowledgement * enet_peer_queue_acknowledgement (ENetPeer *, const ENetProtocol *, enet_uint16); -extern void enet_peer_dispatch_incoming_unreliable_commands (ENetPeer *, ENetChannel *); -extern void enet_peer_dispatch_incoming_reliable_commands (ENetPeer *, ENetChannel *); - -ENET_API void * enet_range_coder_create (void); -ENET_API void enet_range_coder_destroy (void *); -ENET_API size_t enet_range_coder_compress (void *, const ENetBuffer *, size_t, size_t, enet_uint8 *, size_t); -ENET_API size_t enet_range_coder_decompress (void *, const enet_uint8 *, size_t, enet_uint8 *, size_t); - -extern size_t enet_protocol_command_size (enet_uint8); - -#ifdef __cplusplus -} -#endif - -#endif /* __ENET_ENET_H__ */ - diff --git a/src/enet/host.c b/src/enet/host.c deleted file mode 100644 index 8bb2433fe..000000000 --- a/src/enet/host.c +++ /dev/null @@ -1,479 +0,0 @@ -/** - @file host.c - @brief ENet host management functions -*/ -#define ENET_BUILDING_LIB 1 -#include <string.h> -#include <time.h> -#include "enet/enet.h" - -/** @defgroup host ENet host functions - @{ -*/ - -/** Creates a host for communicating to peers. - - @param address the address at which other peers may connect to this host. If NULL, then no peers may connect to the host. - @param peerCount the maximum number of peers that should be allocated for the host. - @param channelLimit the maximum number of channels allowed; if 0, then this is equivalent to ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT - @param incomingBandwidth downstream bandwidth of the host in bytes/second; if 0, ENet will assume unlimited bandwidth. - @param outgoingBandwidth upstream bandwidth of the host in bytes/second; if 0, ENet will assume unlimited bandwidth. - - @returns the host on success and NULL on failure - - @remarks ENet will strategically drop packets on specific sides of a connection between hosts - to ensure the host's bandwidth is not overwhelmed. The bandwidth parameters also determine - the window size of a connection which limits the amount of reliable packets that may be in transit - at any given time. -*/ -ENetHost * -enet_host_create (const ENetAddress * address, size_t peerCount, size_t channelLimit, enet_uint32 incomingBandwidth, enet_uint32 outgoingBandwidth) -{ - ENetHost * host; - ENetPeer * currentPeer; - - if (peerCount > ENET_PROTOCOL_MAXIMUM_PEER_ID) - return NULL; - - host = (ENetHost *) enet_malloc (sizeof (ENetHost)); - if (host == NULL) - return NULL; - - host -> peers = (ENetPeer *) enet_malloc (peerCount * sizeof (ENetPeer)); - if (host -> peers == NULL) - { - enet_free (host); - - return NULL; - } - memset (host -> peers, 0, peerCount * sizeof (ENetPeer)); - - host -> socket = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM); - if (host -> socket == ENET_SOCKET_NULL || (address != NULL && enet_socket_bind (host -> socket, address) < 0)) - { - if (host -> socket != ENET_SOCKET_NULL) - enet_socket_destroy (host -> socket); - - enet_free (host -> peers); - enet_free (host); - - return NULL; - } - - enet_socket_set_option (host -> socket, ENET_SOCKOPT_NONBLOCK, 1); - enet_socket_set_option (host -> socket, ENET_SOCKOPT_BROADCAST, 1); - enet_socket_set_option (host -> socket, ENET_SOCKOPT_RCVBUF, ENET_HOST_RECEIVE_BUFFER_SIZE); - enet_socket_set_option (host -> socket, ENET_SOCKOPT_SNDBUF, ENET_HOST_SEND_BUFFER_SIZE); - - if (address != NULL) - host -> address = * address; - - if (! channelLimit || channelLimit > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT) - channelLimit = ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT; - else - if (channelLimit < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT) - channelLimit = ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT; - - host -> randomSeed = (enet_uint32) time(NULL) + (enet_uint32) (size_t) host; - host -> randomSeed = (host -> randomSeed << 16) | (host -> randomSeed >> 16); - host -> channelLimit = channelLimit; - host -> incomingBandwidth = incomingBandwidth; - host -> outgoingBandwidth = outgoingBandwidth; - host -> bandwidthThrottleEpoch = 0; - host -> recalculateBandwidthLimits = 0; - host -> mtu = ENET_HOST_DEFAULT_MTU; - host -> peerCount = peerCount; - host -> commandCount = 0; - host -> bufferCount = 0; - host -> checksum = NULL; - host -> receivedAddress.host = ENET_HOST_ANY; - host -> receivedAddress.port = 0; - host -> receivedData = NULL; - host -> receivedDataLength = 0; - - host -> totalSentData = 0; - host -> totalSentPackets = 0; - host -> totalReceivedData = 0; - host -> totalReceivedPackets = 0; - - host -> compressor.context = NULL; - host -> compressor.compress = NULL; - host -> compressor.decompress = NULL; - host -> compressor.destroy = NULL; - - enet_list_clear (& host -> dispatchQueue); - - for (currentPeer = host -> peers; - currentPeer < & host -> peers [host -> peerCount]; - ++ currentPeer) - { - currentPeer -> host = host; - currentPeer -> incomingPeerID = currentPeer - host -> peers; - currentPeer -> outgoingSessionID = currentPeer -> incomingSessionID = 0xFF; - currentPeer -> data = NULL; - - enet_list_clear (& currentPeer -> acknowledgements); - enet_list_clear (& currentPeer -> sentReliableCommands); - enet_list_clear (& currentPeer -> sentUnreliableCommands); - enet_list_clear (& currentPeer -> outgoingReliableCommands); - enet_list_clear (& currentPeer -> outgoingUnreliableCommands); - enet_list_clear (& currentPeer -> dispatchedCommands); - - enet_peer_reset (currentPeer); - } - - return host; -} - -/** Destroys the host and all resources associated with it. - @param host pointer to the host to destroy -*/ -void -enet_host_destroy (ENetHost * host) -{ - ENetPeer * currentPeer; - - enet_socket_destroy (host -> socket); - - for (currentPeer = host -> peers; - currentPeer < & host -> peers [host -> peerCount]; - ++ currentPeer) - { - enet_peer_reset (currentPeer); - } - - if (host -> compressor.context != NULL && host -> compressor.destroy) - (* host -> compressor.destroy) (host -> compressor.context); - - enet_free (host -> peers); - enet_free (host); -} - -/** Initiates a connection to a foreign host. - @param host host seeking the connection - @param address destination for the connection - @param channelCount number of channels to allocate - @param data user data supplied to the receiving host - @returns a peer representing the foreign host on success, NULL on failure - @remarks The peer returned will have not completed the connection until enet_host_service() - notifies of an ENET_EVENT_TYPE_CONNECT event for the peer. -*/ -ENetPeer * -enet_host_connect (ENetHost * host, const ENetAddress * address, size_t channelCount, enet_uint32 data) -{ - ENetPeer * currentPeer; - ENetChannel * channel; - ENetProtocol command; - - if (channelCount < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT) - channelCount = ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT; - else - if (channelCount > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT) - channelCount = ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT; - - for (currentPeer = host -> peers; - currentPeer < & host -> peers [host -> peerCount]; - ++ currentPeer) - { - if (currentPeer -> state == ENET_PEER_STATE_DISCONNECTED) - break; - } - - if (currentPeer >= & host -> peers [host -> peerCount]) - return NULL; - - currentPeer -> channels = (ENetChannel *) enet_malloc (channelCount * sizeof (ENetChannel)); - if (currentPeer -> channels == NULL) - return NULL; - currentPeer -> channelCount = channelCount; - currentPeer -> state = ENET_PEER_STATE_CONNECTING; - currentPeer -> address = * address; - currentPeer -> connectID = ++ host -> randomSeed; - - if (host -> outgoingBandwidth == 0) - currentPeer -> windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE; - else - currentPeer -> windowSize = (host -> outgoingBandwidth / - ENET_PEER_WINDOW_SIZE_SCALE) * - ENET_PROTOCOL_MINIMUM_WINDOW_SIZE; - - if (currentPeer -> windowSize < ENET_PROTOCOL_MINIMUM_WINDOW_SIZE) - currentPeer -> windowSize = ENET_PROTOCOL_MINIMUM_WINDOW_SIZE; - else - if (currentPeer -> windowSize > ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE) - currentPeer -> windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE; - - for (channel = currentPeer -> channels; - channel < & currentPeer -> channels [channelCount]; - ++ channel) - { - channel -> outgoingReliableSequenceNumber = 0; - channel -> outgoingUnreliableSequenceNumber = 0; - channel -> incomingReliableSequenceNumber = 0; - - enet_list_clear (& channel -> incomingReliableCommands); - enet_list_clear (& channel -> incomingUnreliableCommands); - - channel -> usedReliableWindows = 0; - memset (channel -> reliableWindows, 0, sizeof (channel -> reliableWindows)); - } - - command.header.command = ENET_PROTOCOL_COMMAND_CONNECT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE; - command.header.channelID = 0xFF; - command.connect.outgoingPeerID = ENET_HOST_TO_NET_16 (currentPeer -> incomingPeerID); - command.connect.incomingSessionID = currentPeer -> incomingSessionID; - command.connect.outgoingSessionID = currentPeer -> outgoingSessionID; - command.connect.mtu = ENET_HOST_TO_NET_32 (currentPeer -> mtu); - command.connect.windowSize = ENET_HOST_TO_NET_32 (currentPeer -> windowSize); - command.connect.channelCount = ENET_HOST_TO_NET_32 (channelCount); - command.connect.incomingBandwidth = ENET_HOST_TO_NET_32 (host -> incomingBandwidth); - command.connect.outgoingBandwidth = ENET_HOST_TO_NET_32 (host -> outgoingBandwidth); - command.connect.packetThrottleInterval = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleInterval); - command.connect.packetThrottleAcceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleAcceleration); - command.connect.packetThrottleDeceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleDeceleration); - command.connect.connectID = currentPeer -> connectID; - command.connect.data = ENET_HOST_TO_NET_32 (data); - - enet_peer_queue_outgoing_command (currentPeer, & command, NULL, 0, 0); - - return currentPeer; -} - -/** Queues a packet to be sent to all peers associated with the host. - @param host host on which to broadcast the packet - @param channelID channel on which to broadcast - @param packet packet to broadcast -*/ -void -enet_host_broadcast (ENetHost * host, enet_uint8 channelID, ENetPacket * packet) -{ - ENetPeer * currentPeer; - - for (currentPeer = host -> peers; - currentPeer < & host -> peers [host -> peerCount]; - ++ currentPeer) - { - if (currentPeer -> state != ENET_PEER_STATE_CONNECTED) - continue; - - enet_peer_send (currentPeer, channelID, packet); - } - - if (packet -> referenceCount == 0) - enet_packet_destroy (packet); -} - -/** Sets the packet compressor the host should use to compress and decompress packets. - @param host host to enable or disable compression for - @param compressor callbacks for for the packet compressor; if NULL, then compression is disabled -*/ -void -enet_host_compress (ENetHost * host, const ENetCompressor * compressor) -{ - if (host -> compressor.context != NULL && host -> compressor.destroy) - (* host -> compressor.destroy) (host -> compressor.context); - - if (compressor) - host -> compressor = * compressor; - else - host -> compressor.context = NULL; -} - -/** Limits the maximum allowed channels of future incoming connections. - @param host host to limit - @param channelLimit the maximum number of channels allowed; if 0, then this is equivalent to ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT -*/ -void -enet_host_channel_limit (ENetHost * host, size_t channelLimit) -{ - if (! channelLimit || channelLimit > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT) - channelLimit = ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT; - else - if (channelLimit < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT) - channelLimit = ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT; - - host -> channelLimit = channelLimit; -} - - -/** Adjusts the bandwidth limits of a host. - @param host host to adjust - @param incomingBandwidth new incoming bandwidth - @param outgoingBandwidth new outgoing bandwidth - @remarks the incoming and outgoing bandwidth parameters are identical in function to those - specified in enet_host_create(). -*/ -void -enet_host_bandwidth_limit (ENetHost * host, enet_uint32 incomingBandwidth, enet_uint32 outgoingBandwidth) -{ - host -> incomingBandwidth = incomingBandwidth; - host -> outgoingBandwidth = outgoingBandwidth; - host -> recalculateBandwidthLimits = 1; -} - -void -enet_host_bandwidth_throttle (ENetHost * host) -{ - enet_uint32 timeCurrent = enet_time_get (), - elapsedTime = timeCurrent - host -> bandwidthThrottleEpoch, - peersTotal = 0, - dataTotal = 0, - peersRemaining, - bandwidth, - throttle = 0, - bandwidthLimit = 0; - int needsAdjustment; - ENetPeer * peer; - ENetProtocol command; - - if (elapsedTime < ENET_HOST_BANDWIDTH_THROTTLE_INTERVAL) - return; - - for (peer = host -> peers; - peer < & host -> peers [host -> peerCount]; - ++ peer) - { - if (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER) - continue; - - ++ peersTotal; - dataTotal += peer -> outgoingDataTotal; - } - - if (peersTotal == 0) - return; - - peersRemaining = peersTotal; - needsAdjustment = 1; - - if (host -> outgoingBandwidth == 0) - bandwidth = ~0; - else - bandwidth = (host -> outgoingBandwidth * elapsedTime) / 1000; - - while (peersRemaining > 0 && needsAdjustment != 0) - { - needsAdjustment = 0; - - if (dataTotal < bandwidth) - throttle = ENET_PEER_PACKET_THROTTLE_SCALE; - else - throttle = (bandwidth * ENET_PEER_PACKET_THROTTLE_SCALE) / dataTotal; - - for (peer = host -> peers; - peer < & host -> peers [host -> peerCount]; - ++ peer) - { - enet_uint32 peerBandwidth; - - if ((peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER) || - peer -> incomingBandwidth == 0 || - peer -> outgoingBandwidthThrottleEpoch == timeCurrent) - continue; - - peerBandwidth = (peer -> incomingBandwidth * elapsedTime) / 1000; - if ((throttle * peer -> outgoingDataTotal) / ENET_PEER_PACKET_THROTTLE_SCALE <= peerBandwidth) - continue; - - peer -> packetThrottleLimit = (peerBandwidth * - ENET_PEER_PACKET_THROTTLE_SCALE) / peer -> outgoingDataTotal; - - if (peer -> packetThrottleLimit == 0) - peer -> packetThrottleLimit = 1; - - if (peer -> packetThrottle > peer -> packetThrottleLimit) - peer -> packetThrottle = peer -> packetThrottleLimit; - - peer -> outgoingBandwidthThrottleEpoch = timeCurrent; - - - needsAdjustment = 1; - -- peersRemaining; - bandwidth -= peerBandwidth; - dataTotal -= peerBandwidth; - } - } - - if (peersRemaining > 0) - for (peer = host -> peers; - peer < & host -> peers [host -> peerCount]; - ++ peer) - { - if ((peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER) || - peer -> outgoingBandwidthThrottleEpoch == timeCurrent) - continue; - - peer -> packetThrottleLimit = throttle; - - if (peer -> packetThrottle > peer -> packetThrottleLimit) - peer -> packetThrottle = peer -> packetThrottleLimit; - } - - if (host -> recalculateBandwidthLimits) - { - host -> recalculateBandwidthLimits = 0; - - peersRemaining = peersTotal; - bandwidth = host -> incomingBandwidth; - needsAdjustment = 1; - - if (bandwidth == 0) - bandwidthLimit = 0; - else - while (peersRemaining > 0 && needsAdjustment != 0) - { - needsAdjustment = 0; - bandwidthLimit = bandwidth / peersRemaining; - - for (peer = host -> peers; - peer < & host -> peers [host -> peerCount]; - ++ peer) - { - if ((peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER) || - peer -> incomingBandwidthThrottleEpoch == timeCurrent) - continue; - - if (peer -> outgoingBandwidth > 0 && - peer -> outgoingBandwidth >= bandwidthLimit) - continue; - - peer -> incomingBandwidthThrottleEpoch = timeCurrent; - - needsAdjustment = 1; - -- peersRemaining; - bandwidth -= peer -> outgoingBandwidth; - } - } - - for (peer = host -> peers; - peer < & host -> peers [host -> peerCount]; - ++ peer) - { - if (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER) - continue; - - command.header.command = ENET_PROTOCOL_COMMAND_BANDWIDTH_LIMIT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE; - command.header.channelID = 0xFF; - command.bandwidthLimit.outgoingBandwidth = ENET_HOST_TO_NET_32 (host -> outgoingBandwidth); - - if (peer -> incomingBandwidthThrottleEpoch == timeCurrent) - command.bandwidthLimit.incomingBandwidth = ENET_HOST_TO_NET_32 (peer -> outgoingBandwidth); - else - command.bandwidthLimit.incomingBandwidth = ENET_HOST_TO_NET_32 (bandwidthLimit); - - enet_peer_queue_outgoing_command (peer, & command, NULL, 0, 0); - } - } - - host -> bandwidthThrottleEpoch = timeCurrent; - - for (peer = host -> peers; - peer < & host -> peers [host -> peerCount]; - ++ peer) - { - peer -> incomingDataTotal = 0; - peer -> outgoingDataTotal = 0; - } -} - -/** @} */ diff --git a/src/enet/list.c b/src/enet/list.c deleted file mode 100644 index 8487200ff..000000000 --- a/src/enet/list.c +++ /dev/null @@ -1,75 +0,0 @@ -/** - @file list.c - @brief ENet linked list functions -*/ -#define ENET_BUILDING_LIB 1 -#include "enet/list.h" - -/** - @defgroup list ENet linked list utility functions - @ingroup private - @{ -*/ -void -enet_list_clear (ENetList * list) -{ - list -> sentinel.next = & list -> sentinel; - list -> sentinel.previous = & list -> sentinel; -} - -ENetListIterator -enet_list_insert (ENetListIterator position, void * data) -{ - ENetListIterator result = (ENetListIterator) data; - - result -> previous = position -> previous; - result -> next = position; - - result -> previous -> next = result; - position -> previous = result; - - return result; -} - -void * -enet_list_remove (ENetListIterator position) -{ - position -> previous -> next = position -> next; - position -> next -> previous = position -> previous; - - return position; -} - -ENetListIterator -enet_list_move (ENetListIterator position, void * dataFirst, void * dataLast) -{ - ENetListIterator first = (ENetListIterator) dataFirst, - last = (ENetListIterator) dataLast; - - first -> previous -> next = last -> next; - last -> next -> previous = first -> previous; - - first -> previous = position -> previous; - last -> next = position; - - first -> previous -> next = first; - position -> previous = last; - - return first; -} - -size_t -enet_list_size (ENetList * list) -{ - size_t size = 0; - ENetListIterator position; - - for (position = enet_list_begin (list); - position != enet_list_end (list); - position = enet_list_next (position)) - ++ size; - - return size; -} - -/** @} */ diff --git a/src/enet/list.h b/src/enet/list.h deleted file mode 100644 index d7b260084..000000000 --- a/src/enet/list.h +++ /dev/null @@ -1,43 +0,0 @@ -/** - @file list.h - @brief ENet list management -*/ -#ifndef __ENET_LIST_H__ -#define __ENET_LIST_H__ - -#include <stdlib.h> - -typedef struct _ENetListNode -{ - struct _ENetListNode * next; - struct _ENetListNode * previous; -} ENetListNode; - -typedef ENetListNode * ENetListIterator; - -typedef struct _ENetList -{ - ENetListNode sentinel; -} ENetList; - -extern void enet_list_clear (ENetList *); - -extern ENetListIterator enet_list_insert (ENetListIterator, void *); -extern void * enet_list_remove (ENetListIterator); -extern ENetListIterator enet_list_move (ENetListIterator, void *, void *); - -extern size_t enet_list_size (ENetList *); - -#define enet_list_begin(list) ((list) -> sentinel.next) -#define enet_list_end(list) (& (list) -> sentinel) - -#define enet_list_empty(list) (enet_list_begin (list) == enet_list_end (list)) - -#define enet_list_next(iterator) ((iterator) -> next) -#define enet_list_previous(iterator) ((iterator) -> previous) - -#define enet_list_front(list) ((void *) (list) -> sentinel.next) -#define enet_list_back(list) ((void *) (list) -> sentinel.previous) - -#endif /* __ENET_LIST_H__ */ - diff --git a/src/enet/packet.c b/src/enet/packet.c deleted file mode 100644 index d6730dd33..000000000 --- a/src/enet/packet.c +++ /dev/null @@ -1,159 +0,0 @@ -/** - @file packet.c - @brief ENet packet management functions -*/ -#include <string.h> -#define ENET_BUILDING_LIB 1 -#include "enet/enet.h" - -/** @defgroup Packet ENet packet functions - @{ -*/ - -/** Creates a packet that may be sent to a peer. - @param dataContents initial contents of the packet's data; the packet's data will remain uninitialized if dataContents is NULL. - @param dataLength size of the data allocated for this packet - @param flags flags for this packet as described for the ENetPacket structure. - @returns the packet on success, NULL on failure -*/ -ENetPacket * -enet_packet_create (const void * data, size_t dataLength, enet_uint32 flags) -{ - ENetPacket * packet = (ENetPacket *) enet_malloc (sizeof (ENetPacket)); - if (packet == NULL) - return NULL; - - if (flags & ENET_PACKET_FLAG_NO_ALLOCATE) - packet -> data = (enet_uint8 *) data; - else - { - packet -> data = (enet_uint8 *) enet_malloc (dataLength); - if (packet -> data == NULL) - { - enet_free (packet); - return NULL; - } - - if (data != NULL) - memcpy (packet -> data, data, dataLength); - } - - packet -> referenceCount = 0; - packet -> flags = flags; - packet -> dataLength = dataLength; - packet -> freeCallback = NULL; - - return packet; -} - -/** Destroys the packet and deallocates its data. - @param packet packet to be destroyed -*/ -void -enet_packet_destroy (ENetPacket * packet) -{ - if (packet -> freeCallback != NULL) - (* packet -> freeCallback) (packet); - if (! (packet -> flags & ENET_PACKET_FLAG_NO_ALLOCATE)) - enet_free (packet -> data); - enet_free (packet); -} - -/** Attempts to resize the data in the packet to length specified in the - dataLength parameter - @param packet packet to resize - @param dataLength new size for the packet data - @returns 0 on success, < 0 on failure -*/ -int -enet_packet_resize (ENetPacket * packet, size_t dataLength) -{ - enet_uint8 * newData; - - if (dataLength <= packet -> dataLength - || (packet -> flags & ENET_PACKET_FLAG_NO_ALLOCATE)) - { - packet -> dataLength = dataLength; - - return 0; - } - - newData = (enet_uint8 *) enet_malloc (dataLength); - if (newData == NULL) - return -1; - - memcpy (newData, packet -> data, packet -> dataLength); - enet_free (packet -> data); - - packet -> data = newData; - packet -> dataLength = dataLength; - - return 0; -} - -static int initializedCRC32 = 0; -static enet_uint32 crcTable [256]; - -static enet_uint32 -reflect_crc (int val, int bits) -{ - int result = 0, bit; - - for (bit = 0; bit < bits; bit ++) - { - if (val & 1) - result |= 1 << (bits - 1 - bit); - val >>= 1; - } - - return result; -} - -static void -initialize_crc32 () -{ - int byte; - - for (byte = 0; byte < 256; ++ byte) - { - enet_uint32 crc = reflect_crc (byte, 8) << 24; - int offset; - - for (offset = 0; offset < 8; ++ offset) - { - if (crc & 0x80000000) - crc = (crc << 1) ^ 0x04c11db7; - else - crc <<= 1; - } - - crcTable [byte] = reflect_crc (crc, 32); - } - - initializedCRC32 = 1; -} - -enet_uint32 -enet_crc32 (const ENetBuffer * buffers, size_t bufferCount) -{ - enet_uint32 crc = 0xFFFFFFFF; - - if (! initializedCRC32) initialize_crc32 (); - - while (bufferCount -- > 0) - { - const enet_uint8 * data = (const enet_uint8 *) buffers -> data, - * dataEnd = & data [buffers -> dataLength]; - - while (data < dataEnd) - { - crc = (crc >> 8) ^ crcTable [(crc & 0xFF) ^ *data++]; - } - - ++ buffers; - } - - return ENET_HOST_TO_NET_32 (~ crc); -} - -/** @} */ diff --git a/src/enet/peer.c b/src/enet/peer.c deleted file mode 100644 index d778ce1d6..000000000 --- a/src/enet/peer.c +++ /dev/null @@ -1,816 +0,0 @@ -/** - @file peer.c - @brief ENet peer management functions -*/ -#include <string.h> -#define ENET_BUILDING_LIB 1 -#include "enet/enet.h" - -/** @defgroup peer ENet peer functions - @{ -*/ - -/** Configures throttle parameter for a peer. - - Unreliable packets are dropped by ENet in response to the varying conditions - of the Internet connection to the peer. The throttle represents a probability - that an unreliable packet should not be dropped and thus sent by ENet to the peer. - The lowest mean round trip time from the sending of a reliable packet to the - receipt of its acknowledgement is measured over an amount of time specified by - the interval parameter in milliseconds. If a measured round trip time happens to - be significantly less than the mean round trip time measured over the interval, - then the throttle probability is increased to allow more traffic by an amount - specified in the acceleration parameter, which is a ratio to the ENET_PEER_PACKET_THROTTLE_SCALE - constant. If a measured round trip time happens to be significantly greater than - the mean round trip time measured over the interval, then the throttle probability - is decreased to limit traffic by an amount specified in the deceleration parameter, which - is a ratio to the ENET_PEER_PACKET_THROTTLE_SCALE constant. When the throttle has - a value of ENET_PEER_PACKET_THROTTLE_SCALE, on unreliable packets are dropped by - ENet, and so 100% of all unreliable packets will be sent. When the throttle has a - value of 0, all unreliable packets are dropped by ENet, and so 0% of all unreliable - packets will be sent. Intermediate values for the throttle represent intermediate - probabilities between 0% and 100% of unreliable packets being sent. The bandwidth - limits of the local and foreign hosts are taken into account to determine a - sensible limit for the throttle probability above which it should not raise even in - the best of conditions. - - @param peer peer to configure - @param interval interval, in milliseconds, over which to measure lowest mean RTT; the default value is ENET_PEER_PACKET_THROTTLE_INTERVAL. - @param acceleration rate at which to increase the throttle probability as mean RTT declines - @param deceleration rate at which to decrease the throttle probability as mean RTT increases -*/ -void -enet_peer_throttle_configure (ENetPeer * peer, enet_uint32 interval, enet_uint32 acceleration, enet_uint32 deceleration) -{ - ENetProtocol command; - - peer -> packetThrottleInterval = interval; - peer -> packetThrottleAcceleration = acceleration; - peer -> packetThrottleDeceleration = deceleration; - - command.header.command = ENET_PROTOCOL_COMMAND_THROTTLE_CONFIGURE | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE; - command.header.channelID = 0xFF; - - command.throttleConfigure.packetThrottleInterval = ENET_HOST_TO_NET_32 (interval); - command.throttleConfigure.packetThrottleAcceleration = ENET_HOST_TO_NET_32 (acceleration); - command.throttleConfigure.packetThrottleDeceleration = ENET_HOST_TO_NET_32 (deceleration); - - enet_peer_queue_outgoing_command (peer, & command, NULL, 0, 0); -} - -int -enet_peer_throttle (ENetPeer * peer, enet_uint32 rtt) -{ - if (peer -> lastRoundTripTime <= peer -> lastRoundTripTimeVariance) - { - peer -> packetThrottle = peer -> packetThrottleLimit; - } - else - if (rtt < peer -> lastRoundTripTime) - { - peer -> packetThrottle += peer -> packetThrottleAcceleration; - - if (peer -> packetThrottle > peer -> packetThrottleLimit) - peer -> packetThrottle = peer -> packetThrottleLimit; - - return 1; - } - else - if (rtt > peer -> lastRoundTripTime + 2 * peer -> lastRoundTripTimeVariance) - { - if (peer -> packetThrottle > peer -> packetThrottleDeceleration) - peer -> packetThrottle -= peer -> packetThrottleDeceleration; - else - peer -> packetThrottle = 0; - - return -1; - } - - return 0; -} - -/** Queues a packet to be sent. - @param peer destination for the packet - @param channelID channel on which to send - @param packet packet to send - @retval 0 on success - @retval < 0 on failure -*/ -int -enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet) -{ - ENetChannel * channel = & peer -> channels [channelID]; - ENetProtocol command; - size_t fragmentLength; - - if (peer -> state != ENET_PEER_STATE_CONNECTED || - channelID >= peer -> channelCount) - return -1; - - fragmentLength = peer -> mtu - sizeof (ENetProtocolHeader) - sizeof (ENetProtocolSendFragment); - - if (packet -> dataLength > fragmentLength) - { - enet_uint16 startSequenceNumber = ENET_HOST_TO_NET_16 (channel -> outgoingReliableSequenceNumber + 1); - enet_uint32 fragmentCount = ENET_HOST_TO_NET_32 ((packet -> dataLength + fragmentLength - 1) / fragmentLength), - fragmentNumber, - fragmentOffset; - ENetList fragments; - ENetOutgoingCommand * fragment; - - enet_list_clear (& fragments); - - for (fragmentNumber = 0, - fragmentOffset = 0; - fragmentOffset < packet -> dataLength; - ++ fragmentNumber, - fragmentOffset += fragmentLength) - { - if (packet -> dataLength - fragmentOffset < fragmentLength) - fragmentLength = packet -> dataLength - fragmentOffset; - - fragment = (ENetOutgoingCommand *) enet_malloc (sizeof (ENetOutgoingCommand)); - if (fragment == NULL) - { - while (! enet_list_empty (& fragments)) - { - fragment = (ENetOutgoingCommand *) enet_list_remove (enet_list_begin (& fragments)); - - enet_free (fragment); - } - - return -1; - } - - fragment -> fragmentOffset = fragmentOffset; - fragment -> fragmentLength = fragmentLength; - fragment -> packet = packet; - fragment -> command.header.command = ENET_PROTOCOL_COMMAND_SEND_FRAGMENT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE; - fragment -> command.header.channelID = channelID; - fragment -> command.sendFragment.startSequenceNumber = startSequenceNumber; - fragment -> command.sendFragment.dataLength = ENET_HOST_TO_NET_16 (fragmentLength); - fragment -> command.sendFragment.fragmentCount = fragmentCount; - fragment -> command.sendFragment.fragmentNumber = ENET_HOST_TO_NET_32 (fragmentNumber); - fragment -> command.sendFragment.totalLength = ENET_HOST_TO_NET_32 (packet -> dataLength); - fragment -> command.sendFragment.fragmentOffset = ENET_NET_TO_HOST_32 (fragmentOffset); - - enet_list_insert (enet_list_end (& fragments), fragment); - } - - packet -> referenceCount += fragmentNumber; - - while (! enet_list_empty (& fragments)) - { - fragment = (ENetOutgoingCommand *) enet_list_remove (enet_list_begin (& fragments)); - - enet_peer_setup_outgoing_command (peer, fragment); - } - - return 0; - } - - command.header.channelID = channelID; - - if (packet -> flags & ENET_PACKET_FLAG_RELIABLE) - { - command.header.command = ENET_PROTOCOL_COMMAND_SEND_RELIABLE | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE; - command.sendReliable.dataLength = ENET_HOST_TO_NET_16 (packet -> dataLength); - } - else - if (packet -> flags & ENET_PACKET_FLAG_UNSEQUENCED) - { - command.header.command = ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED | ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED; - command.sendUnsequenced.unsequencedGroup = ENET_HOST_TO_NET_16 (peer -> outgoingUnsequencedGroup + 1); - command.sendUnsequenced.dataLength = ENET_HOST_TO_NET_16 (packet -> dataLength); - } - else - if (channel -> outgoingUnreliableSequenceNumber >= 0xFFFF) - { - command.header.command = ENET_PROTOCOL_COMMAND_SEND_RELIABLE | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE; - command.sendReliable.dataLength = ENET_HOST_TO_NET_16 (packet -> dataLength); - } - else - { - command.header.command = ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE; - command.sendUnreliable.unreliableSequenceNumber = ENET_HOST_TO_NET_16 (channel -> outgoingUnreliableSequenceNumber + 1); - command.sendUnreliable.dataLength = ENET_HOST_TO_NET_16 (packet -> dataLength); - } - - if (enet_peer_queue_outgoing_command (peer, & command, packet, 0, packet -> dataLength) == NULL) - return -1; - - return 0; -} - -/** Attempts to dequeue any incoming queued packet. - @param peer peer to dequeue packets from - @param channelID holds the channel ID of the channel the packet was received on success - @returns a pointer to the packet, or NULL if there are no available incoming queued packets -*/ -ENetPacket * -enet_peer_receive (ENetPeer * peer, enet_uint8 * channelID) -{ - ENetIncomingCommand * incomingCommand; - ENetPacket * packet; - - if (enet_list_empty (& peer -> dispatchedCommands)) - return NULL; - - incomingCommand = (ENetIncomingCommand *) enet_list_remove (enet_list_begin (& peer -> dispatchedCommands)); - - if (channelID != NULL) - * channelID = incomingCommand -> command.header.channelID; - - packet = incomingCommand -> packet; - - -- packet -> referenceCount; - - if (incomingCommand -> fragments != NULL) - enet_free (incomingCommand -> fragments); - - enet_free (incomingCommand); - - return packet; -} - -static void -enet_peer_reset_outgoing_commands (ENetList * queue) -{ - ENetOutgoingCommand * outgoingCommand; - - while (! enet_list_empty (queue)) - { - outgoingCommand = (ENetOutgoingCommand *) enet_list_remove (enet_list_begin (queue)); - - if (outgoingCommand -> packet != NULL) - { - -- outgoingCommand -> packet -> referenceCount; - - if (outgoingCommand -> packet -> referenceCount == 0) - enet_packet_destroy (outgoingCommand -> packet); - } - - enet_free (outgoingCommand); - } -} - -static void -enet_peer_reset_incoming_commands (ENetList * queue) -{ - ENetIncomingCommand * incomingCommand; - - while (! enet_list_empty (queue)) - { - incomingCommand = (ENetIncomingCommand *) enet_list_remove (enet_list_begin (queue)); - - if (incomingCommand -> packet != NULL) - { - -- incomingCommand -> packet -> referenceCount; - - if (incomingCommand -> packet -> referenceCount == 0) - enet_packet_destroy (incomingCommand -> packet); - } - - if (incomingCommand -> fragments != NULL) - enet_free (incomingCommand -> fragments); - - enet_free (incomingCommand); - } -} - -void -enet_peer_reset_queues (ENetPeer * peer) -{ - ENetChannel * channel; - - if (peer -> needsDispatch) - { - enet_list_remove (& peer -> dispatchList); - - peer -> needsDispatch = 0; - } - - while (! enet_list_empty (& peer -> acknowledgements)) - enet_free (enet_list_remove (enet_list_begin (& peer -> acknowledgements))); - - enet_peer_reset_outgoing_commands (& peer -> sentReliableCommands); - enet_peer_reset_outgoing_commands (& peer -> sentUnreliableCommands); - enet_peer_reset_outgoing_commands (& peer -> outgoingReliableCommands); - enet_peer_reset_outgoing_commands (& peer -> outgoingUnreliableCommands); - enet_peer_reset_incoming_commands (& peer -> dispatchedCommands); - - if (peer -> channels != NULL && peer -> channelCount > 0) - { - for (channel = peer -> channels; - channel < & peer -> channels [peer -> channelCount]; - ++ channel) - { - enet_peer_reset_incoming_commands (& channel -> incomingReliableCommands); - enet_peer_reset_incoming_commands (& channel -> incomingUnreliableCommands); - } - - enet_free (peer -> channels); - } - - peer -> channels = NULL; - peer -> channelCount = 0; -} - -/** Forcefully disconnects a peer. - @param peer peer to forcefully disconnect - @remarks The foreign host represented by the peer is not notified of the disconnection and will timeout - on its connection to the local host. -*/ -void -enet_peer_reset (ENetPeer * peer) -{ - peer -> outgoingPeerID = ENET_PROTOCOL_MAXIMUM_PEER_ID; - peer -> connectID = 0; - - peer -> state = ENET_PEER_STATE_DISCONNECTED; - - peer -> incomingBandwidth = 0; - peer -> outgoingBandwidth = 0; - peer -> incomingBandwidthThrottleEpoch = 0; - peer -> outgoingBandwidthThrottleEpoch = 0; - peer -> incomingDataTotal = 0; - peer -> outgoingDataTotal = 0; - peer -> lastSendTime = 0; - peer -> lastReceiveTime = 0; - peer -> nextTimeout = 0; - peer -> earliestTimeout = 0; - peer -> packetLossEpoch = 0; - peer -> packetsSent = 0; - peer -> packetsLost = 0; - peer -> packetLoss = 0; - peer -> packetLossVariance = 0; - peer -> packetThrottle = ENET_PEER_DEFAULT_PACKET_THROTTLE; - peer -> packetThrottleLimit = ENET_PEER_PACKET_THROTTLE_SCALE; - peer -> packetThrottleCounter = 0; - peer -> packetThrottleEpoch = 0; - peer -> packetThrottleAcceleration = ENET_PEER_PACKET_THROTTLE_ACCELERATION; - peer -> packetThrottleDeceleration = ENET_PEER_PACKET_THROTTLE_DECELERATION; - peer -> packetThrottleInterval = ENET_PEER_PACKET_THROTTLE_INTERVAL; - peer -> lastRoundTripTime = ENET_PEER_DEFAULT_ROUND_TRIP_TIME; - peer -> lowestRoundTripTime = ENET_PEER_DEFAULT_ROUND_TRIP_TIME; - peer -> lastRoundTripTimeVariance = 0; - peer -> highestRoundTripTimeVariance = 0; - peer -> roundTripTime = ENET_PEER_DEFAULT_ROUND_TRIP_TIME; - peer -> roundTripTimeVariance = 0; - peer -> mtu = peer -> host -> mtu; - peer -> reliableDataInTransit = 0; - peer -> outgoingReliableSequenceNumber = 0; - peer -> windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE; - peer -> incomingUnsequencedGroup = 0; - peer -> outgoingUnsequencedGroup = 0; - peer -> eventData = 0; - - memset (peer -> unsequencedWindow, 0, sizeof (peer -> unsequencedWindow)); - - enet_peer_reset_queues (peer); -} - -/** Sends a ping request to a peer. - @param peer destination for the ping request - @remarks ping requests factor into the mean round trip time as designated by the - roundTripTime field in the ENetPeer structure. Enet automatically pings all connected - peers at regular intervals, however, this function may be called to ensure more - frequent ping requests. -*/ -void -enet_peer_ping (ENetPeer * peer) -{ - ENetProtocol command; - - if (peer -> state != ENET_PEER_STATE_CONNECTED) - return; - - command.header.command = ENET_PROTOCOL_COMMAND_PING | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE; - command.header.channelID = 0xFF; - - enet_peer_queue_outgoing_command (peer, & command, NULL, 0, 0); -} - -/** Force an immediate disconnection from a peer. - @param peer peer to disconnect - @param data data describing the disconnection - @remarks No ENET_EVENT_DISCONNECT event will be generated. The foreign peer is not - guarenteed to receive the disconnect notification, and is reset immediately upon - return from this function. -*/ -void -enet_peer_disconnect_now (ENetPeer * peer, enet_uint32 data) -{ - ENetProtocol command; - - if (peer -> state == ENET_PEER_STATE_DISCONNECTED) - return; - - if (peer -> state != ENET_PEER_STATE_ZOMBIE && - peer -> state != ENET_PEER_STATE_DISCONNECTING) - { - enet_peer_reset_queues (peer); - - command.header.command = ENET_PROTOCOL_COMMAND_DISCONNECT | ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED; - command.header.channelID = 0xFF; - command.disconnect.data = ENET_HOST_TO_NET_32 (data); - - enet_peer_queue_outgoing_command (peer, & command, NULL, 0, 0); - - enet_host_flush (peer -> host); - } - - enet_peer_reset (peer); -} - -/** Request a disconnection from a peer. - @param peer peer to request a disconnection - @param data data describing the disconnection - @remarks An ENET_EVENT_DISCONNECT event will be generated by enet_host_service() - once the disconnection is complete. -*/ -void -enet_peer_disconnect (ENetPeer * peer, enet_uint32 data) -{ - ENetProtocol command; - - if (peer -> state == ENET_PEER_STATE_DISCONNECTING || - peer -> state == ENET_PEER_STATE_DISCONNECTED || - peer -> state == ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT || - peer -> state == ENET_PEER_STATE_ZOMBIE) - return; - - enet_peer_reset_queues (peer); - - command.header.command = ENET_PROTOCOL_COMMAND_DISCONNECT; - command.header.channelID = 0xFF; - command.disconnect.data = ENET_HOST_TO_NET_32 (data); - - if (peer -> state == ENET_PEER_STATE_CONNECTED || peer -> state == ENET_PEER_STATE_DISCONNECT_LATER) - command.header.command |= ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE; - else - command.header.command |= ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED; - - enet_peer_queue_outgoing_command (peer, & command, NULL, 0, 0); - - if (peer -> state == ENET_PEER_STATE_CONNECTED || peer -> state == ENET_PEER_STATE_DISCONNECT_LATER) - peer -> state = ENET_PEER_STATE_DISCONNECTING; - else - { - enet_host_flush (peer -> host); - enet_peer_reset (peer); - } -} - -/** Request a disconnection from a peer, but only after all queued outgoing packets are sent. - @param peer peer to request a disconnection - @param data data describing the disconnection - @remarks An ENET_EVENT_DISCONNECT event will be generated by enet_host_service() - once the disconnection is complete. -*/ -void -enet_peer_disconnect_later (ENetPeer * peer, enet_uint32 data) -{ - if ((peer -> state == ENET_PEER_STATE_CONNECTED || peer -> state == ENET_PEER_STATE_DISCONNECT_LATER) && - ! (enet_list_empty (& peer -> outgoingReliableCommands) && - enet_list_empty (& peer -> outgoingUnreliableCommands) && - enet_list_empty (& peer -> sentReliableCommands))) - { - peer -> state = ENET_PEER_STATE_DISCONNECT_LATER; - peer -> eventData = data; - } - else - enet_peer_disconnect (peer, data); -} - -ENetAcknowledgement * -enet_peer_queue_acknowledgement (ENetPeer * peer, const ENetProtocol * command, enet_uint16 sentTime) -{ - ENetAcknowledgement * acknowledgement; - - if (command -> header.channelID < peer -> channelCount) - { - ENetChannel * channel = & peer -> channels [command -> header.channelID]; - enet_uint16 reliableWindow = command -> header.reliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE, - currentWindow = channel -> incomingReliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE; - - if (command -> header.reliableSequenceNumber < channel -> incomingReliableSequenceNumber) - reliableWindow += ENET_PEER_RELIABLE_WINDOWS; - - if (reliableWindow >= currentWindow + ENET_PEER_FREE_RELIABLE_WINDOWS - 1 && reliableWindow <= currentWindow + ENET_PEER_FREE_RELIABLE_WINDOWS) - return NULL; - } - - acknowledgement = (ENetAcknowledgement *) enet_malloc (sizeof (ENetAcknowledgement)); - if (acknowledgement == NULL) - return NULL; - - peer -> outgoingDataTotal += sizeof (ENetProtocolAcknowledge); - - acknowledgement -> sentTime = sentTime; - acknowledgement -> command = * command; - - enet_list_insert (enet_list_end (& peer -> acknowledgements), acknowledgement); - - return acknowledgement; -} - -void -enet_peer_setup_outgoing_command (ENetPeer * peer, ENetOutgoingCommand * outgoingCommand) -{ - ENetChannel * channel = & peer -> channels [outgoingCommand -> command.header.channelID]; - - peer -> outgoingDataTotal += enet_protocol_command_size (outgoingCommand -> command.header.command) + outgoingCommand -> fragmentLength; - - if (outgoingCommand -> command.header.channelID == 0xFF) - { - ++ peer -> outgoingReliableSequenceNumber; - - outgoingCommand -> reliableSequenceNumber = peer -> outgoingReliableSequenceNumber; - outgoingCommand -> unreliableSequenceNumber = 0; - } - else - if (outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE) - { - ++ channel -> outgoingReliableSequenceNumber; - channel -> outgoingUnreliableSequenceNumber = 0; - - outgoingCommand -> reliableSequenceNumber = channel -> outgoingReliableSequenceNumber; - outgoingCommand -> unreliableSequenceNumber = 0; - } - else - if (outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED) - { - ++ peer -> outgoingUnsequencedGroup; - - outgoingCommand -> reliableSequenceNumber = 0; - outgoingCommand -> unreliableSequenceNumber = 0; - } - else - { - ++ channel -> outgoingUnreliableSequenceNumber; - - outgoingCommand -> reliableSequenceNumber = channel -> outgoingReliableSequenceNumber; - outgoingCommand -> unreliableSequenceNumber = channel -> outgoingUnreliableSequenceNumber; - } - - outgoingCommand -> sendAttempts = 0; - outgoingCommand -> sentTime = 0; - outgoingCommand -> roundTripTimeout = 0; - outgoingCommand -> roundTripTimeoutLimit = 0; - outgoingCommand -> command.header.reliableSequenceNumber = ENET_HOST_TO_NET_16 (outgoingCommand -> reliableSequenceNumber); - - if (outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE) - enet_list_insert (enet_list_end (& peer -> outgoingReliableCommands), outgoingCommand); - else - enet_list_insert (enet_list_end (& peer -> outgoingUnreliableCommands), outgoingCommand); -} - -ENetOutgoingCommand * -enet_peer_queue_outgoing_command (ENetPeer * peer, const ENetProtocol * command, ENetPacket * packet, enet_uint32 offset, enet_uint16 length) -{ - ENetOutgoingCommand * outgoingCommand = (ENetOutgoingCommand *) enet_malloc (sizeof (ENetOutgoingCommand)); - if (outgoingCommand == NULL) - return NULL; - - outgoingCommand -> command = * command; - outgoingCommand -> fragmentOffset = offset; - outgoingCommand -> fragmentLength = length; - outgoingCommand -> packet = packet; - if (packet != NULL) - ++ packet -> referenceCount; - - enet_peer_setup_outgoing_command (peer, outgoingCommand); - - return outgoingCommand; -} - -void -enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel * channel) -{ - ENetListIterator currentCommand; - - for (currentCommand = enet_list_begin (& channel -> incomingUnreliableCommands); - currentCommand != enet_list_end (& channel -> incomingUnreliableCommands); - currentCommand = enet_list_next (currentCommand)) - { - ENetIncomingCommand * incomingCommand = (ENetIncomingCommand *) currentCommand; - - if ((incomingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK) == ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE && - incomingCommand -> reliableSequenceNumber != channel -> incomingReliableSequenceNumber) - break; - } - - if (currentCommand == enet_list_begin (& channel -> incomingUnreliableCommands)) - return; - - enet_list_move (enet_list_end (& peer -> dispatchedCommands), enet_list_begin (& channel -> incomingUnreliableCommands), enet_list_previous (currentCommand)); - - if (! peer -> needsDispatch) - { - enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList); - - peer -> needsDispatch = 1; - } -} - -void -enet_peer_dispatch_incoming_reliable_commands (ENetPeer * peer, ENetChannel * channel) -{ - ENetListIterator currentCommand; - - for (currentCommand = enet_list_begin (& channel -> incomingReliableCommands); - currentCommand != enet_list_end (& channel -> incomingReliableCommands); - currentCommand = enet_list_next (currentCommand)) - { - ENetIncomingCommand * incomingCommand = (ENetIncomingCommand *) currentCommand; - - if (incomingCommand -> fragmentsRemaining > 0 || - incomingCommand -> reliableSequenceNumber != (enet_uint16) (channel -> incomingReliableSequenceNumber + 1)) - break; - - channel -> incomingReliableSequenceNumber = incomingCommand -> reliableSequenceNumber; - - if (incomingCommand -> fragmentCount > 0) - channel -> incomingReliableSequenceNumber += incomingCommand -> fragmentCount - 1; - } - - if (currentCommand == enet_list_begin (& channel -> incomingReliableCommands)) - return; - - enet_list_move (enet_list_end (& peer -> dispatchedCommands), enet_list_begin (& channel -> incomingReliableCommands), enet_list_previous (currentCommand)); - - if (! peer -> needsDispatch) - { - enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList); - - peer -> needsDispatch = 1; - } - - enet_peer_dispatch_incoming_unreliable_commands (peer, channel); -} - -ENetIncomingCommand * -enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol * command, ENetPacket * packet, enet_uint32 fragmentCount) -{ - static ENetIncomingCommand dummyCommand; - - ENetChannel * channel = & peer -> channels [command -> header.channelID]; - enet_uint32 unreliableSequenceNumber = 0, reliableSequenceNumber; - enet_uint16 reliableWindow, currentWindow; - ENetIncomingCommand * incomingCommand; - ENetListIterator currentCommand; - - if (peer -> state == ENET_PEER_STATE_DISCONNECT_LATER) - goto freePacket; - - if ((command -> header.command & ENET_PROTOCOL_COMMAND_MASK) != ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED) - { - reliableSequenceNumber = command -> header.reliableSequenceNumber; - reliableWindow = reliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE; - currentWindow = channel -> incomingReliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE; - - if (reliableSequenceNumber < channel -> incomingReliableSequenceNumber) - reliableWindow += ENET_PEER_RELIABLE_WINDOWS; - - if (reliableWindow < currentWindow || reliableWindow >= currentWindow + ENET_PEER_FREE_RELIABLE_WINDOWS - 1) - goto freePacket; - } - - switch (command -> header.command & ENET_PROTOCOL_COMMAND_MASK) - { - case ENET_PROTOCOL_COMMAND_SEND_FRAGMENT: - case ENET_PROTOCOL_COMMAND_SEND_RELIABLE: - if (reliableSequenceNumber == channel -> incomingReliableSequenceNumber) - goto freePacket; - - for (currentCommand = enet_list_previous (enet_list_end (& channel -> incomingReliableCommands)); - currentCommand != enet_list_end (& channel -> incomingReliableCommands); - currentCommand = enet_list_previous (currentCommand)) - { - incomingCommand = (ENetIncomingCommand *) currentCommand; - - if (reliableSequenceNumber >= channel -> incomingReliableSequenceNumber) - { - if (incomingCommand -> reliableSequenceNumber < channel -> incomingReliableSequenceNumber) - continue; - } - else - if (incomingCommand -> reliableSequenceNumber >= channel -> incomingReliableSequenceNumber) - break; - - if (incomingCommand -> reliableSequenceNumber <= reliableSequenceNumber) - { - if (incomingCommand -> reliableSequenceNumber < reliableSequenceNumber) - break; - - goto freePacket; - } - } - break; - - case ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE: - unreliableSequenceNumber = ENET_NET_TO_HOST_16 (command -> sendUnreliable.unreliableSequenceNumber); - - for (currentCommand = enet_list_previous (enet_list_end (& channel -> incomingUnreliableCommands)); - currentCommand != enet_list_end (& channel -> incomingUnreliableCommands); - currentCommand = enet_list_previous (currentCommand)) - { - incomingCommand = (ENetIncomingCommand *) currentCommand; - - if ((incomingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK) != ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE) - continue; - - if (reliableSequenceNumber >= channel -> incomingReliableSequenceNumber) - { - if (incomingCommand -> reliableSequenceNumber < channel -> incomingReliableSequenceNumber) - continue; - } - else - if (incomingCommand -> reliableSequenceNumber >= channel -> incomingReliableSequenceNumber) - break; - - if (incomingCommand -> reliableSequenceNumber < reliableSequenceNumber) - break; - - if (incomingCommand -> reliableSequenceNumber > reliableSequenceNumber) - continue; - - if (incomingCommand -> unreliableSequenceNumber <= unreliableSequenceNumber) - { - if (incomingCommand -> unreliableSequenceNumber < unreliableSequenceNumber) - break; - - goto freePacket; - } - } - break; - - case ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED: - currentCommand = enet_list_end (& channel -> incomingUnreliableCommands); - break; - - default: - goto freePacket; - } - - incomingCommand = (ENetIncomingCommand *) enet_malloc (sizeof (ENetIncomingCommand)); - if (incomingCommand == NULL) - goto notifyError; - - incomingCommand -> reliableSequenceNumber = command -> header.reliableSequenceNumber; - incomingCommand -> unreliableSequenceNumber = unreliableSequenceNumber & 0xFFFF; - incomingCommand -> command = * command; - incomingCommand -> fragmentCount = fragmentCount; - incomingCommand -> fragmentsRemaining = fragmentCount; - incomingCommand -> packet = packet; - incomingCommand -> fragments = NULL; - - if (fragmentCount > 0) - { - incomingCommand -> fragments = (enet_uint32 *) enet_malloc ((fragmentCount + 31) / 32 * sizeof (enet_uint32)); - if (incomingCommand -> fragments == NULL) - { - enet_free (incomingCommand); - - goto notifyError; - } - memset (incomingCommand -> fragments, 0, (fragmentCount + 31) / 32 * sizeof (enet_uint32)); - } - - if (packet != NULL) - ++ packet -> referenceCount; - - enet_list_insert (enet_list_next (currentCommand), incomingCommand); - - switch (command -> header.command & ENET_PROTOCOL_COMMAND_MASK) - { - case ENET_PROTOCOL_COMMAND_SEND_FRAGMENT: - case ENET_PROTOCOL_COMMAND_SEND_RELIABLE: - enet_peer_dispatch_incoming_reliable_commands (peer, channel); - break; - - default: - enet_peer_dispatch_incoming_unreliable_commands (peer, channel); - break; - } - - return incomingCommand; - -freePacket: - if (fragmentCount > 0) - goto notifyError; - - if (packet != NULL && packet -> referenceCount == 0) - enet_packet_destroy (packet); - - return & dummyCommand; - -notifyError: - if (packet != NULL && packet -> referenceCount == 0) - enet_packet_destroy (packet); - - return NULL; -} - -/** @} */ diff --git a/src/enet/protocol.c b/src/enet/protocol.c deleted file mode 100644 index 8e26dfb24..000000000 --- a/src/enet/protocol.c +++ /dev/null @@ -1,1671 +0,0 @@ -/** - @file protocol.c - @brief ENet protocol functions -*/ -#include <stdio.h> -#include <string.h> -#define ENET_BUILDING_LIB 1 -#include "enet/utility.h" -#include "enet/time.h" -#include "enet/enet.h" - -static size_t commandSizes [ENET_PROTOCOL_COMMAND_COUNT] = -{ - 0, - sizeof (ENetProtocolAcknowledge), - sizeof (ENetProtocolConnect), - sizeof (ENetProtocolVerifyConnect), - sizeof (ENetProtocolDisconnect), - sizeof (ENetProtocolPing), - sizeof (ENetProtocolSendReliable), - sizeof (ENetProtocolSendUnreliable), - sizeof (ENetProtocolSendFragment), - sizeof (ENetProtocolSendUnsequenced), - sizeof (ENetProtocolBandwidthLimit), - sizeof (ENetProtocolThrottleConfigure), -}; - -size_t -enet_protocol_command_size (enet_uint8 commandNumber) -{ - return commandSizes [commandNumber & ENET_PROTOCOL_COMMAND_MASK]; -} - -static int -enet_protocol_dispatch_incoming_commands (ENetHost * host, ENetEvent * event) -{ - while (! enet_list_empty (& host -> dispatchQueue)) - { - ENetPeer * peer = (ENetPeer *) enet_list_remove (enet_list_begin (& host -> dispatchQueue)); - - peer -> needsDispatch = 0; - - switch (peer -> state) - { - case ENET_PEER_STATE_CONNECTION_PENDING: - case ENET_PEER_STATE_CONNECTION_SUCCEEDED: - peer -> state = ENET_PEER_STATE_CONNECTED; - - event -> type = ENET_EVENT_TYPE_CONNECT; - event -> peer = peer; - event -> data = peer -> eventData; - - return 1; - - case ENET_PEER_STATE_ZOMBIE: - host -> recalculateBandwidthLimits = 1; - - event -> type = ENET_EVENT_TYPE_DISCONNECT; - event -> peer = peer; - event -> data = peer -> eventData; - - enet_peer_reset (peer); - - return 1; - - case ENET_PEER_STATE_CONNECTED: - if (enet_list_empty (& peer -> dispatchedCommands)) - continue; - - event -> packet = enet_peer_receive (peer, & event -> channelID); - if (event -> packet == NULL) - continue; - - event -> type = ENET_EVENT_TYPE_RECEIVE; - event -> peer = peer; - - if (! enet_list_empty (& peer -> dispatchedCommands)) - { - peer -> needsDispatch = 1; - - enet_list_insert (enet_list_end (& host -> dispatchQueue), & peer -> dispatchList); - } - - return 1; - } - } - - return 0; -} - -static void -enet_protocol_dispatch_state (ENetHost * host, ENetPeer * peer, ENetPeerState state) -{ - peer -> state = state; - - if (! peer -> needsDispatch) - { - enet_list_insert (enet_list_end (& host -> dispatchQueue), & peer -> dispatchList); - - peer -> needsDispatch = 1; - } -} - -static void -enet_protocol_notify_connect (ENetHost * host, ENetPeer * peer, ENetEvent * event) -{ - host -> recalculateBandwidthLimits = 1; - - if (event != NULL) - { - peer -> state = ENET_PEER_STATE_CONNECTED; - - event -> type = ENET_EVENT_TYPE_CONNECT; - event -> peer = peer; - event -> data = peer -> eventData; - } - else - enet_protocol_dispatch_state (host, peer, peer -> state == ENET_PEER_STATE_CONNECTING ? ENET_PEER_STATE_CONNECTION_SUCCEEDED : ENET_PEER_STATE_CONNECTION_PENDING); -} - -static void -enet_protocol_notify_disconnect (ENetHost * host, ENetPeer * peer, ENetEvent * event) -{ - if (peer -> state >= ENET_PEER_STATE_CONNECTION_PENDING) - host -> recalculateBandwidthLimits = 1; - - if (peer -> state != ENET_PEER_STATE_CONNECTING && peer -> state < ENET_PEER_STATE_CONNECTION_SUCCEEDED) - enet_peer_reset (peer); - else - if (event != NULL) - { - event -> type = ENET_EVENT_TYPE_DISCONNECT; - event -> peer = peer; - event -> data = 0; - - enet_peer_reset (peer); - } - else - { - peer -> eventData = 0; - - enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE); - } -} - -static void -enet_protocol_remove_sent_unreliable_commands (ENetPeer * peer) -{ - ENetOutgoingCommand * outgoingCommand; - - while (! enet_list_empty (& peer -> sentUnreliableCommands)) - { - outgoingCommand = (ENetOutgoingCommand *) enet_list_front (& peer -> sentUnreliableCommands); - - enet_list_remove (& outgoingCommand -> outgoingCommandList); - - if (outgoingCommand -> packet != NULL) - { - -- outgoingCommand -> packet -> referenceCount; - - if (outgoingCommand -> packet -> referenceCount == 0) - enet_packet_destroy (outgoingCommand -> packet); - } - - enet_free (outgoingCommand); - } -} - -static ENetProtocolCommand -enet_protocol_remove_sent_reliable_command (ENetPeer * peer, enet_uint16 reliableSequenceNumber, enet_uint8 channelID) -{ - ENetOutgoingCommand * outgoingCommand; - ENetListIterator currentCommand; - ENetProtocolCommand commandNumber; - - for (currentCommand = enet_list_begin (& peer -> sentReliableCommands); - currentCommand != enet_list_end (& peer -> sentReliableCommands); - currentCommand = enet_list_next (currentCommand)) - { - outgoingCommand = (ENetOutgoingCommand *) currentCommand; - - if (outgoingCommand -> reliableSequenceNumber == reliableSequenceNumber && - outgoingCommand -> command.header.channelID == channelID) - break; - } - - if (currentCommand == enet_list_end (& peer -> sentReliableCommands)) - { - for (currentCommand = enet_list_begin (& peer -> outgoingReliableCommands); - currentCommand != enet_list_end (& peer -> outgoingReliableCommands); - currentCommand = enet_list_next (currentCommand)) - { - outgoingCommand = (ENetOutgoingCommand *) currentCommand; - - if (outgoingCommand -> sendAttempts < 1) return ENET_PROTOCOL_COMMAND_NONE; - - if (outgoingCommand -> reliableSequenceNumber == reliableSequenceNumber && - outgoingCommand -> command.header.channelID == channelID) - break; - } - - if (currentCommand == enet_list_end (& peer -> outgoingReliableCommands)) - return ENET_PROTOCOL_COMMAND_NONE; - } - - if (channelID < peer -> channelCount) - { - ENetChannel * channel = & peer -> channels [channelID]; - enet_uint16 reliableWindow = reliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE; - if (channel -> reliableWindows [reliableWindow] > 0) - { - -- channel -> reliableWindows [reliableWindow]; - if (! channel -> reliableWindows [reliableWindow]) - channel -> usedReliableWindows &= ~ (1 << reliableWindow); - } - } - - commandNumber = (ENetProtocolCommand) (outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK); - - enet_list_remove (& outgoingCommand -> outgoingCommandList); - - if (outgoingCommand -> packet != NULL) - { - peer -> reliableDataInTransit -= outgoingCommand -> fragmentLength; - - -- outgoingCommand -> packet -> referenceCount; - - if (outgoingCommand -> packet -> referenceCount == 0) - enet_packet_destroy (outgoingCommand -> packet); - } - - enet_free (outgoingCommand); - - if (enet_list_empty (& peer -> sentReliableCommands)) - return commandNumber; - - outgoingCommand = (ENetOutgoingCommand *) enet_list_front (& peer -> sentReliableCommands); - - peer -> nextTimeout = outgoingCommand -> sentTime + outgoingCommand -> roundTripTimeout; - - return commandNumber; -} - -static ENetPeer * -enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENetProtocol * command) -{ - enet_uint8 incomingSessionID, outgoingSessionID; - enet_uint32 mtu, windowSize; - ENetChannel * channel; - size_t channelCount; - ENetPeer * currentPeer; - ENetProtocol verifyCommand; - - channelCount = ENET_NET_TO_HOST_32 (command -> connect.channelCount); - - if (channelCount < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT || - channelCount > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT) - return NULL; - - for (currentPeer = host -> peers; - currentPeer < & host -> peers [host -> peerCount]; - ++ currentPeer) - { - if (currentPeer -> state != ENET_PEER_STATE_DISCONNECTED && - currentPeer -> address.host == host -> receivedAddress.host && - currentPeer -> address.port == host -> receivedAddress.port && - currentPeer -> connectID == command -> connect.connectID) - return NULL; - } - - for (currentPeer = host -> peers; - currentPeer < & host -> peers [host -> peerCount]; - ++ currentPeer) - { - if (currentPeer -> state == ENET_PEER_STATE_DISCONNECTED) - break; - } - - if (currentPeer >= & host -> peers [host -> peerCount]) - return NULL; - - if (channelCount > host -> channelLimit) - channelCount = host -> channelLimit; - currentPeer -> channels = (ENetChannel *) enet_malloc (channelCount * sizeof (ENetChannel)); - if (currentPeer -> channels == NULL) - return NULL; - currentPeer -> channelCount = channelCount; - currentPeer -> state = ENET_PEER_STATE_ACKNOWLEDGING_CONNECT; - currentPeer -> connectID = command -> connect.connectID; - currentPeer -> address = host -> receivedAddress; - currentPeer -> outgoingPeerID = ENET_NET_TO_HOST_16 (command -> connect.outgoingPeerID); - currentPeer -> incomingBandwidth = ENET_NET_TO_HOST_32 (command -> connect.incomingBandwidth); - currentPeer -> outgoingBandwidth = ENET_NET_TO_HOST_32 (command -> connect.outgoingBandwidth); - currentPeer -> packetThrottleInterval = ENET_NET_TO_HOST_32 (command -> connect.packetThrottleInterval); - currentPeer -> packetThrottleAcceleration = ENET_NET_TO_HOST_32 (command -> connect.packetThrottleAcceleration); - currentPeer -> packetThrottleDeceleration = ENET_NET_TO_HOST_32 (command -> connect.packetThrottleDeceleration); - currentPeer -> eventData = ENET_NET_TO_HOST_32 (command -> connect.data); - - incomingSessionID = command -> connect.incomingSessionID == 0xFF ? currentPeer -> outgoingSessionID : command -> connect.incomingSessionID; - incomingSessionID = (incomingSessionID + 1) & (ENET_PROTOCOL_HEADER_SESSION_MASK >> ENET_PROTOCOL_HEADER_SESSION_SHIFT); - if (incomingSessionID == currentPeer -> outgoingSessionID) - incomingSessionID = (incomingSessionID + 1) & (ENET_PROTOCOL_HEADER_SESSION_MASK >> ENET_PROTOCOL_HEADER_SESSION_SHIFT); - currentPeer -> outgoingSessionID = incomingSessionID; - - outgoingSessionID = command -> connect.outgoingSessionID == 0xFF ? currentPeer -> incomingSessionID : command -> connect.outgoingSessionID; - outgoingSessionID = (outgoingSessionID + 1) & (ENET_PROTOCOL_HEADER_SESSION_MASK >> ENET_PROTOCOL_HEADER_SESSION_SHIFT); - if (outgoingSessionID == currentPeer -> incomingSessionID) - outgoingSessionID = (outgoingSessionID + 1) & (ENET_PROTOCOL_HEADER_SESSION_MASK >> ENET_PROTOCOL_HEADER_SESSION_SHIFT); - currentPeer -> incomingSessionID = outgoingSessionID; - - for (channel = currentPeer -> channels; - channel < & currentPeer -> channels [channelCount]; - ++ channel) - { - channel -> outgoingReliableSequenceNumber = 0; - channel -> outgoingUnreliableSequenceNumber = 0; - channel -> incomingReliableSequenceNumber = 0; - - enet_list_clear (& channel -> incomingReliableCommands); - enet_list_clear (& channel -> incomingUnreliableCommands); - - channel -> usedReliableWindows = 0; - memset (channel -> reliableWindows, 0, sizeof (channel -> reliableWindows)); - } - - mtu = ENET_NET_TO_HOST_32 (command -> connect.mtu); - - if (mtu < ENET_PROTOCOL_MINIMUM_MTU) - mtu = ENET_PROTOCOL_MINIMUM_MTU; - else - if (mtu > ENET_PROTOCOL_MAXIMUM_MTU) - mtu = ENET_PROTOCOL_MAXIMUM_MTU; - - currentPeer -> mtu = mtu; - - if (host -> outgoingBandwidth == 0 && - currentPeer -> incomingBandwidth == 0) - currentPeer -> windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE; - else - if (host -> outgoingBandwidth == 0 || - currentPeer -> incomingBandwidth == 0) - currentPeer -> windowSize = (ENET_MAX (host -> outgoingBandwidth, currentPeer -> incomingBandwidth) / - ENET_PEER_WINDOW_SIZE_SCALE) * - ENET_PROTOCOL_MINIMUM_WINDOW_SIZE; - else - currentPeer -> windowSize = (ENET_MIN (host -> outgoingBandwidth, currentPeer -> incomingBandwidth) / - ENET_PEER_WINDOW_SIZE_SCALE) * - ENET_PROTOCOL_MINIMUM_WINDOW_SIZE; - - if (currentPeer -> windowSize < ENET_PROTOCOL_MINIMUM_WINDOW_SIZE) - currentPeer -> windowSize = ENET_PROTOCOL_MINIMUM_WINDOW_SIZE; - else - if (currentPeer -> windowSize > ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE) - currentPeer -> windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE; - - if (host -> incomingBandwidth == 0) - windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE; - else - windowSize = (host -> incomingBandwidth / ENET_PEER_WINDOW_SIZE_SCALE) * - ENET_PROTOCOL_MINIMUM_WINDOW_SIZE; - - if (windowSize > ENET_NET_TO_HOST_32 (command -> connect.windowSize)) - windowSize = ENET_NET_TO_HOST_32 (command -> connect.windowSize); - - if (windowSize < ENET_PROTOCOL_MINIMUM_WINDOW_SIZE) - windowSize = ENET_PROTOCOL_MINIMUM_WINDOW_SIZE; - else - if (windowSize > ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE) - windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE; - - verifyCommand.header.command = ENET_PROTOCOL_COMMAND_VERIFY_CONNECT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE; - verifyCommand.header.channelID = 0xFF; - verifyCommand.verifyConnect.outgoingPeerID = ENET_HOST_TO_NET_16 (currentPeer -> incomingPeerID); - verifyCommand.verifyConnect.incomingSessionID = incomingSessionID; - verifyCommand.verifyConnect.outgoingSessionID = outgoingSessionID; - verifyCommand.verifyConnect.mtu = ENET_HOST_TO_NET_16 (currentPeer -> mtu); - verifyCommand.verifyConnect.windowSize = ENET_HOST_TO_NET_32 (windowSize); - verifyCommand.verifyConnect.channelCount = ENET_HOST_TO_NET_32 (channelCount); - verifyCommand.verifyConnect.incomingBandwidth = ENET_HOST_TO_NET_32 (host -> incomingBandwidth); - verifyCommand.verifyConnect.outgoingBandwidth = ENET_HOST_TO_NET_32 (host -> outgoingBandwidth); - verifyCommand.verifyConnect.packetThrottleInterval = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleInterval); - verifyCommand.verifyConnect.packetThrottleAcceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleAcceleration); - verifyCommand.verifyConnect.packetThrottleDeceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleDeceleration); - verifyCommand.verifyConnect.connectID = currentPeer -> connectID; - - enet_peer_queue_outgoing_command (currentPeer, & verifyCommand, NULL, 0, 0); - - return currentPeer; -} - -static int -enet_protocol_handle_send_reliable (ENetHost * host, ENetPeer * peer, const ENetProtocol * command, enet_uint8 ** currentData) -{ - ENetPacket * packet; - size_t dataLength; - - if (command -> header.channelID >= peer -> channelCount || - (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER)) - return -1; - - dataLength = ENET_NET_TO_HOST_16 (command -> sendReliable.dataLength); - * currentData += dataLength; - if (* currentData > & host -> receivedData [host -> receivedDataLength]) - return -1; - - packet = enet_packet_create ((const enet_uint8 *) command + sizeof (ENetProtocolSendReliable), - dataLength, - ENET_PACKET_FLAG_RELIABLE); - if (packet == NULL || - enet_peer_queue_incoming_command (peer, command, packet, 0) == NULL) - return -1; - - return 0; -} - -static int -enet_protocol_handle_send_unsequenced (ENetHost * host, ENetPeer * peer, const ENetProtocol * command, enet_uint8 ** currentData) -{ - ENetPacket * packet; - enet_uint32 unsequencedGroup, index; - size_t dataLength; - - if (command -> header.channelID >= peer -> channelCount || - (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER)) - return -1; - - dataLength = ENET_NET_TO_HOST_16 (command -> sendUnsequenced.dataLength); - * currentData += dataLength; - if (* currentData > & host -> receivedData [host -> receivedDataLength]) - return -1; - - unsequencedGroup = ENET_NET_TO_HOST_16 (command -> sendUnsequenced.unsequencedGroup); - index = unsequencedGroup % ENET_PEER_UNSEQUENCED_WINDOW_SIZE; - - if (unsequencedGroup < peer -> incomingUnsequencedGroup) - unsequencedGroup += 0x10000; - - if (unsequencedGroup >= (enet_uint32) peer -> incomingUnsequencedGroup + ENET_PEER_FREE_UNSEQUENCED_WINDOWS * ENET_PEER_UNSEQUENCED_WINDOW_SIZE) - return 0; - - unsequencedGroup &= 0xFFFF; - - if (unsequencedGroup - index != peer -> incomingUnsequencedGroup) - { - peer -> incomingUnsequencedGroup = unsequencedGroup - index; - - memset (peer -> unsequencedWindow, 0, sizeof (peer -> unsequencedWindow)); - } - else - if (peer -> unsequencedWindow [index / 32] & (1 << (index % 32))) - return 0; - - packet = enet_packet_create ((const enet_uint8 *) command + sizeof (ENetProtocolSendUnsequenced), - dataLength, - ENET_PACKET_FLAG_UNSEQUENCED); - if (packet == NULL || - enet_peer_queue_incoming_command (peer, command, packet, 0) == NULL) - return -1; - - peer -> unsequencedWindow [index / 32] |= 1 << (index % 32); - - return 0; -} - -static int -enet_protocol_handle_send_unreliable (ENetHost * host, ENetPeer * peer, const ENetProtocol * command, enet_uint8 ** currentData) -{ - ENetPacket * packet; - size_t dataLength; - - if (command -> header.channelID >= peer -> channelCount || - (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER)) - return -1; - - dataLength = ENET_NET_TO_HOST_16 (command -> sendUnreliable.dataLength); - * currentData += dataLength; - if (* currentData > & host -> receivedData [host -> receivedDataLength]) - return -1; - - packet = enet_packet_create ((const enet_uint8 *) command + sizeof (ENetProtocolSendUnreliable), - dataLength, - 0); - if (packet == NULL || - enet_peer_queue_incoming_command (peer, command, packet, 0) == NULL) - return -1; - - return 0; -} - -static int -enet_protocol_handle_send_fragment (ENetHost * host, ENetPeer * peer, const ENetProtocol * command, enet_uint8 ** currentData) -{ - enet_uint32 fragmentNumber, - fragmentCount, - fragmentOffset, - fragmentLength, - startSequenceNumber, - totalLength; - ENetChannel * channel; - enet_uint16 startWindow, currentWindow; - ENetListIterator currentCommand; - ENetIncomingCommand * startCommand = NULL; - - if (command -> header.channelID >= peer -> channelCount || - (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER)) - return -1; - - fragmentLength = ENET_NET_TO_HOST_16 (command -> sendFragment.dataLength); - * currentData += fragmentLength; - if (* currentData > & host -> receivedData [host -> receivedDataLength]) - return -1; - - channel = & peer -> channels [command -> header.channelID]; - startSequenceNumber = ENET_NET_TO_HOST_16 (command -> sendFragment.startSequenceNumber); - startWindow = startSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE; - currentWindow = channel -> incomingReliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE; - - if (startSequenceNumber < channel -> incomingReliableSequenceNumber) - startWindow += ENET_PEER_RELIABLE_WINDOWS; - - if (startWindow < currentWindow || startWindow >= currentWindow + ENET_PEER_FREE_RELIABLE_WINDOWS - 1) - return 0; - - fragmentNumber = ENET_NET_TO_HOST_32 (command -> sendFragment.fragmentNumber); - fragmentCount = ENET_NET_TO_HOST_32 (command -> sendFragment.fragmentCount); - fragmentOffset = ENET_NET_TO_HOST_32 (command -> sendFragment.fragmentOffset); - totalLength = ENET_NET_TO_HOST_32 (command -> sendFragment.totalLength); - - if (fragmentOffset >= totalLength || - fragmentOffset + fragmentLength > totalLength || - fragmentNumber >= fragmentCount) - return -1; - - for (currentCommand = enet_list_previous (enet_list_end (& channel -> incomingReliableCommands)); - currentCommand != enet_list_end (& channel -> incomingReliableCommands); - currentCommand = enet_list_previous (currentCommand)) - { - ENetIncomingCommand * incomingCommand = (ENetIncomingCommand *) currentCommand; - - if (startSequenceNumber >= channel -> incomingReliableSequenceNumber) - { - if (incomingCommand -> reliableSequenceNumber < channel -> incomingReliableSequenceNumber) - continue; - } - else - if (incomingCommand -> reliableSequenceNumber >= channel -> incomingReliableSequenceNumber) - break; - - if (incomingCommand -> reliableSequenceNumber <= startSequenceNumber) - { - if (incomingCommand -> reliableSequenceNumber < startSequenceNumber) - break; - - if ((incomingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK) != ENET_PROTOCOL_COMMAND_SEND_FRAGMENT || - totalLength != incomingCommand -> packet -> dataLength || - fragmentCount != incomingCommand -> fragmentCount) - return -1; - - startCommand = incomingCommand; - break; - } - } - - if (startCommand == NULL) - { - ENetProtocol hostCommand = * command; - ENetPacket * packet = enet_packet_create (NULL, totalLength, ENET_PACKET_FLAG_RELIABLE); - if (packet == NULL) - return -1; - - hostCommand.header.reliableSequenceNumber = startSequenceNumber; - hostCommand.sendFragment.startSequenceNumber = startSequenceNumber; - hostCommand.sendFragment.dataLength = fragmentLength; - hostCommand.sendFragment.fragmentNumber = fragmentNumber; - hostCommand.sendFragment.fragmentCount = fragmentCount; - hostCommand.sendFragment.fragmentOffset = fragmentOffset; - hostCommand.sendFragment.totalLength = totalLength; - - startCommand = enet_peer_queue_incoming_command (peer, & hostCommand, packet, fragmentCount); - if (startCommand == NULL) - return -1; - } - - if ((startCommand -> fragments [fragmentNumber / 32] & (1 << (fragmentNumber % 32))) == 0) - { - -- startCommand -> fragmentsRemaining; - - startCommand -> fragments [fragmentNumber / 32] |= (1 << (fragmentNumber % 32)); - - if (fragmentOffset + fragmentLength > startCommand -> packet -> dataLength) - fragmentLength = startCommand -> packet -> dataLength - fragmentOffset; - - memcpy (startCommand -> packet -> data + fragmentOffset, - (enet_uint8 *) command + sizeof (ENetProtocolSendFragment), - fragmentLength); - - if (startCommand -> fragmentsRemaining <= 0) - enet_peer_dispatch_incoming_reliable_commands (peer, channel); - } - - return 0; -} - -static int -enet_protocol_handle_ping (ENetHost * host, ENetPeer * peer, const ENetProtocol * command) -{ - return 0; -} - -static int -enet_protocol_handle_bandwidth_limit (ENetHost * host, ENetPeer * peer, const ENetProtocol * command) -{ - peer -> incomingBandwidth = ENET_NET_TO_HOST_32 (command -> bandwidthLimit.incomingBandwidth); - peer -> outgoingBandwidth = ENET_NET_TO_HOST_32 (command -> bandwidthLimit.outgoingBandwidth); - - if (peer -> incomingBandwidth == 0 && host -> outgoingBandwidth == 0) - peer -> windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE; - else - peer -> windowSize = (ENET_MIN (peer -> incomingBandwidth, host -> outgoingBandwidth) / - ENET_PEER_WINDOW_SIZE_SCALE) * ENET_PROTOCOL_MINIMUM_WINDOW_SIZE; - - if (peer -> windowSize < ENET_PROTOCOL_MINIMUM_WINDOW_SIZE) - peer -> windowSize = ENET_PROTOCOL_MINIMUM_WINDOW_SIZE; - else - if (peer -> windowSize > ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE) - peer -> windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE; - - return 0; -} - -static int -enet_protocol_handle_throttle_configure (ENetHost * host, ENetPeer * peer, const ENetProtocol * command) -{ - peer -> packetThrottleInterval = ENET_NET_TO_HOST_32 (command -> throttleConfigure.packetThrottleInterval); - peer -> packetThrottleAcceleration = ENET_NET_TO_HOST_32 (command -> throttleConfigure.packetThrottleAcceleration); - peer -> packetThrottleDeceleration = ENET_NET_TO_HOST_32 (command -> throttleConfigure.packetThrottleDeceleration); - - return 0; -} - -static int -enet_protocol_handle_disconnect (ENetHost * host, ENetPeer * peer, const ENetProtocol * command) -{ - if (peer -> state == ENET_PEER_STATE_ZOMBIE || peer -> state == ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT) - return 0; - - enet_peer_reset_queues (peer); - - if (peer -> state == ENET_PEER_STATE_CONNECTION_SUCCEEDED) - enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE); - else - if (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER) - { - if (peer -> state == ENET_PEER_STATE_CONNECTION_PENDING) host -> recalculateBandwidthLimits = 1; - - enet_peer_reset (peer); - } - else - if (command -> header.command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE) - peer -> state = ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT; - else - enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE); - - if (peer -> state != ENET_PEER_STATE_DISCONNECTED) - peer -> eventData = ENET_NET_TO_HOST_32 (command -> disconnect.data); - - return 0; -} - -static int -enet_protocol_handle_acknowledge (ENetHost * host, ENetEvent * event, ENetPeer * peer, const ENetProtocol * command) -{ - enet_uint32 roundTripTime, - receivedSentTime, - receivedReliableSequenceNumber; - ENetProtocolCommand commandNumber; - - receivedSentTime = ENET_NET_TO_HOST_16 (command -> acknowledge.receivedSentTime); - receivedSentTime |= host -> serviceTime & 0xFFFF0000; - if ((receivedSentTime & 0x8000) > (host -> serviceTime & 0x8000)) - receivedSentTime -= 0x10000; - - if (ENET_TIME_LESS (host -> serviceTime, receivedSentTime)) - return 0; - - peer -> lastReceiveTime = host -> serviceTime; - peer -> earliestTimeout = 0; - - roundTripTime = ENET_TIME_DIFFERENCE (host -> serviceTime, receivedSentTime); - - enet_peer_throttle (peer, roundTripTime); - - peer -> roundTripTimeVariance -= peer -> roundTripTimeVariance / 4; - - if (roundTripTime >= peer -> roundTripTime) - { - peer -> roundTripTime += (roundTripTime - peer -> roundTripTime) / 8; - peer -> roundTripTimeVariance += (roundTripTime - peer -> roundTripTime) / 4; - } - else - { - peer -> roundTripTime -= (peer -> roundTripTime - roundTripTime) / 8; - peer -> roundTripTimeVariance += (peer -> roundTripTime - roundTripTime) / 4; - } - - if (peer -> roundTripTime < peer -> lowestRoundTripTime) - peer -> lowestRoundTripTime = peer -> roundTripTime; - - if (peer -> roundTripTimeVariance > peer -> highestRoundTripTimeVariance) - peer -> highestRoundTripTimeVariance = peer -> roundTripTimeVariance; - - if (peer -> packetThrottleEpoch == 0 || - ENET_TIME_DIFFERENCE (host -> serviceTime, peer -> packetThrottleEpoch) >= peer -> packetThrottleInterval) - { - peer -> lastRoundTripTime = peer -> lowestRoundTripTime; - peer -> lastRoundTripTimeVariance = peer -> highestRoundTripTimeVariance; - peer -> lowestRoundTripTime = peer -> roundTripTime; - peer -> highestRoundTripTimeVariance = peer -> roundTripTimeVariance; - peer -> packetThrottleEpoch = host -> serviceTime; - } - - receivedReliableSequenceNumber = ENET_NET_TO_HOST_16 (command -> acknowledge.receivedReliableSequenceNumber); - - commandNumber = enet_protocol_remove_sent_reliable_command (peer, receivedReliableSequenceNumber, command -> header.channelID); - - switch (peer -> state) - { - case ENET_PEER_STATE_ACKNOWLEDGING_CONNECT: - if (commandNumber != ENET_PROTOCOL_COMMAND_VERIFY_CONNECT) - return -1; - - enet_protocol_notify_connect (host, peer, event); - break; - - case ENET_PEER_STATE_DISCONNECTING: - if (commandNumber != ENET_PROTOCOL_COMMAND_DISCONNECT) - return -1; - - enet_protocol_notify_disconnect (host, peer, event); - break; - - case ENET_PEER_STATE_DISCONNECT_LATER: - if (enet_list_empty (& peer -> outgoingReliableCommands) && - enet_list_empty (& peer -> outgoingUnreliableCommands) && - enet_list_empty (& peer -> sentReliableCommands)) - enet_peer_disconnect (peer, peer -> eventData); - break; - } - - return 0; -} - -static int -enet_protocol_handle_verify_connect (ENetHost * host, ENetEvent * event, ENetPeer * peer, const ENetProtocol * command) -{ - enet_uint32 mtu, windowSize; - size_t channelCount; - - if (peer -> state != ENET_PEER_STATE_CONNECTING) - return 0; - - channelCount = ENET_NET_TO_HOST_32 (command -> verifyConnect.channelCount); - - if (channelCount < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT || channelCount > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT || - ENET_NET_TO_HOST_32 (command -> verifyConnect.packetThrottleInterval) != peer -> packetThrottleInterval || - ENET_NET_TO_HOST_32 (command -> verifyConnect.packetThrottleAcceleration) != peer -> packetThrottleAcceleration || - ENET_NET_TO_HOST_32 (command -> verifyConnect.packetThrottleDeceleration) != peer -> packetThrottleDeceleration || - command -> verifyConnect.connectID != peer -> connectID) - { - peer -> eventData = 0; - - enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE); - - return -1; - } - - enet_protocol_remove_sent_reliable_command (peer, 1, 0xFF); - - if (channelCount < peer -> channelCount) - peer -> channelCount = channelCount; - - peer -> outgoingPeerID = ENET_NET_TO_HOST_16 (command -> verifyConnect.outgoingPeerID); - peer -> incomingSessionID = command -> verifyConnect.incomingSessionID; - peer -> outgoingSessionID = command -> verifyConnect.outgoingSessionID; - - mtu = ENET_NET_TO_HOST_32 (command -> verifyConnect.mtu); - - if (mtu < ENET_PROTOCOL_MINIMUM_MTU) - mtu = ENET_PROTOCOL_MINIMUM_MTU; - else - if (mtu > ENET_PROTOCOL_MAXIMUM_MTU) - mtu = ENET_PROTOCOL_MAXIMUM_MTU; - - if (mtu < peer -> mtu) - peer -> mtu = mtu; - - windowSize = ENET_NET_TO_HOST_32 (command -> verifyConnect.windowSize); - - if (windowSize < ENET_PROTOCOL_MINIMUM_WINDOW_SIZE) - windowSize = ENET_PROTOCOL_MINIMUM_WINDOW_SIZE; - - if (windowSize > ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE) - windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE; - - if (windowSize < peer -> windowSize) - peer -> windowSize = windowSize; - - peer -> incomingBandwidth = ENET_NET_TO_HOST_32 (command -> verifyConnect.incomingBandwidth); - peer -> outgoingBandwidth = ENET_NET_TO_HOST_32 (command -> verifyConnect.outgoingBandwidth); - - enet_protocol_notify_connect (host, peer, event); - return 0; -} - -static int -enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event) -{ - ENetProtocolHeader * header; - ENetProtocol * command; - ENetPeer * peer; - enet_uint8 * currentData; - size_t headerSize; - enet_uint16 peerID, flags; - enet_uint8 sessionID; - - if (host -> receivedDataLength < (size_t) & ((ENetProtocolHeader *) 0) -> sentTime) - return 0; - - header = (ENetProtocolHeader *) host -> receivedData; - - peerID = ENET_NET_TO_HOST_16 (header -> peerID); - sessionID = (peerID & ENET_PROTOCOL_HEADER_SESSION_MASK) >> ENET_PROTOCOL_HEADER_SESSION_SHIFT; - flags = peerID & ENET_PROTOCOL_HEADER_FLAG_MASK; - peerID &= ~ (ENET_PROTOCOL_HEADER_FLAG_MASK | ENET_PROTOCOL_HEADER_SESSION_MASK); - - headerSize = (flags & ENET_PROTOCOL_HEADER_FLAG_SENT_TIME ? sizeof (ENetProtocolHeader) : (size_t) & ((ENetProtocolHeader *) 0) -> sentTime); - if (host -> checksum != NULL) - headerSize += sizeof (enet_uint32); - - if (peerID == ENET_PROTOCOL_MAXIMUM_PEER_ID) - peer = NULL; - else - if (peerID >= host -> peerCount) - return 0; - else - { - peer = & host -> peers [peerID]; - - if (peer -> state == ENET_PEER_STATE_DISCONNECTED || - peer -> state == ENET_PEER_STATE_ZOMBIE || - (host -> receivedAddress.host != peer -> address.host && - peer -> address.host != ENET_HOST_BROADCAST) || - (peer -> outgoingPeerID < ENET_PROTOCOL_MAXIMUM_PEER_ID && - sessionID != peer -> incomingSessionID)) - return 0; - } - - if (flags & ENET_PROTOCOL_HEADER_FLAG_COMPRESSED) - { - size_t originalSize; - if (host -> compressor.context == NULL || host -> compressor.decompress == NULL) - return 0; - - originalSize = host -> compressor.decompress (host -> compressor.context, - host -> receivedData + headerSize, - host -> receivedDataLength - headerSize, - host -> packetData [1] + headerSize, - sizeof (host -> packetData [1]) - headerSize); - if (originalSize <= 0 || originalSize > sizeof (host -> packetData [1]) - headerSize) - return 0; - - memcpy (host -> packetData [1], header, headerSize); - host -> receivedData = host -> packetData [1]; - host -> receivedDataLength = headerSize + originalSize; - } - - if (host -> checksum != NULL) - { - enet_uint32 * checksum = (enet_uint32 *) & host -> receivedData [headerSize - sizeof (enet_uint32)], - desiredChecksum = * checksum; - ENetBuffer buffer; - - * checksum = peer != NULL ? peer -> connectID : 0; - - buffer.data = host -> receivedData; - buffer.dataLength = host -> receivedDataLength; - - if (host -> checksum (& buffer, 1) != desiredChecksum) - return 0; - } - - if (peer != NULL) - { - peer -> address.host = host -> receivedAddress.host; - peer -> address.port = host -> receivedAddress.port; - peer -> incomingDataTotal += host -> receivedDataLength; - } - - currentData = host -> receivedData + headerSize; - - while (currentData < & host -> receivedData [host -> receivedDataLength]) - { - enet_uint8 commandNumber; - size_t commandSize; - - command = (ENetProtocol *) currentData; - - if (currentData + sizeof (ENetProtocolCommandHeader) > & host -> receivedData [host -> receivedDataLength]) - break; - - commandNumber = command -> header.command & ENET_PROTOCOL_COMMAND_MASK; - if (commandNumber >= ENET_PROTOCOL_COMMAND_COUNT) - break; - - commandSize = commandSizes [commandNumber]; - if (commandSize == 0 || currentData + commandSize > & host -> receivedData [host -> receivedDataLength]) - break; - - currentData += commandSize; - - if (peer == NULL && commandNumber != ENET_PROTOCOL_COMMAND_CONNECT) - break; - - command -> header.reliableSequenceNumber = ENET_NET_TO_HOST_16 (command -> header.reliableSequenceNumber); - - switch (command -> header.command & ENET_PROTOCOL_COMMAND_MASK) - { - case ENET_PROTOCOL_COMMAND_ACKNOWLEDGE: - if (enet_protocol_handle_acknowledge (host, event, peer, command)) - goto commandError; - break; - - case ENET_PROTOCOL_COMMAND_CONNECT: - peer = enet_protocol_handle_connect (host, header, command); - if (peer == NULL) - goto commandError; - break; - - case ENET_PROTOCOL_COMMAND_VERIFY_CONNECT: - if (enet_protocol_handle_verify_connect (host, event, peer, command)) - goto commandError; - break; - - case ENET_PROTOCOL_COMMAND_DISCONNECT: - if (enet_protocol_handle_disconnect (host, peer, command)) - goto commandError; - break; - - case ENET_PROTOCOL_COMMAND_PING: - if (enet_protocol_handle_ping (host, peer, command)) - goto commandError; - break; - - case ENET_PROTOCOL_COMMAND_SEND_RELIABLE: - if (enet_protocol_handle_send_reliable (host, peer, command, & currentData)) - goto commandError; - break; - - case ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE: - if (enet_protocol_handle_send_unreliable (host, peer, command, & currentData)) - goto commandError; - break; - - case ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED: - if (enet_protocol_handle_send_unsequenced (host, peer, command, & currentData)) - goto commandError; - break; - - case ENET_PROTOCOL_COMMAND_SEND_FRAGMENT: - if (enet_protocol_handle_send_fragment (host, peer, command, & currentData)) - goto commandError; - break; - - case ENET_PROTOCOL_COMMAND_BANDWIDTH_LIMIT: - if (enet_protocol_handle_bandwidth_limit (host, peer, command)) - goto commandError; - break; - - case ENET_PROTOCOL_COMMAND_THROTTLE_CONFIGURE: - if (enet_protocol_handle_throttle_configure (host, peer, command)) - goto commandError; - break; - - default: - goto commandError; - } - - if (peer != NULL && - (command -> header.command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE) != 0) - { - enet_uint16 sentTime; - - if (! (flags & ENET_PROTOCOL_HEADER_FLAG_SENT_TIME)) - break; - - sentTime = ENET_NET_TO_HOST_16 (header -> sentTime); - - switch (peer -> state) - { - case ENET_PEER_STATE_DISCONNECTING: - case ENET_PEER_STATE_ACKNOWLEDGING_CONNECT: - break; - - case ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT: - if ((command -> header.command & ENET_PROTOCOL_COMMAND_MASK) == ENET_PROTOCOL_COMMAND_DISCONNECT) - enet_peer_queue_acknowledgement (peer, command, sentTime); - break; - - default: - enet_peer_queue_acknowledgement (peer, command, sentTime); - break; - } - } - } - -commandError: - if (event != NULL && event -> type != ENET_EVENT_TYPE_NONE) - return 1; - - return 0; -} - -static int -enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event) -{ - for (;;) - { - int receivedLength; - ENetBuffer buffer; - - buffer.data = host -> packetData [0]; - buffer.dataLength = sizeof (host -> packetData [0]); - - receivedLength = enet_socket_receive (host -> socket, - & host -> receivedAddress, - & buffer, - 1); - - if (receivedLength < 0) - return -1; - - if (receivedLength == 0) - return 0; - - host -> receivedData = host -> packetData [0]; - host -> receivedDataLength = receivedLength; - - host -> totalReceivedData += receivedLength; - host -> totalReceivedPackets ++; - - switch (enet_protocol_handle_incoming_commands (host, event)) - { - case 1: - return 1; - - case -1: - return -1; - - default: - break; - } - } - - return -1; -} - -static void -enet_protocol_send_acknowledgements (ENetHost * host, ENetPeer * peer) -{ - ENetProtocol * command = & host -> commands [host -> commandCount]; - ENetBuffer * buffer = & host -> buffers [host -> bufferCount]; - ENetAcknowledgement * acknowledgement; - ENetListIterator currentAcknowledgement; - - currentAcknowledgement = enet_list_begin (& peer -> acknowledgements); - - while (currentAcknowledgement != enet_list_end (& peer -> acknowledgements)) - { - if (command >= & host -> commands [sizeof (host -> commands) / sizeof (ENetProtocol)] || - buffer >= & host -> buffers [sizeof (host -> buffers) / sizeof (ENetBuffer)] || - peer -> mtu - host -> packetSize < sizeof (ENetProtocolAcknowledge)) - { - host -> continueSending = 1; - - break; - } - - acknowledgement = (ENetAcknowledgement *) currentAcknowledgement; - - currentAcknowledgement = enet_list_next (currentAcknowledgement); - - buffer -> data = command; - buffer -> dataLength = sizeof (ENetProtocolAcknowledge); - - host -> packetSize += buffer -> dataLength; - - command -> header.command = ENET_PROTOCOL_COMMAND_ACKNOWLEDGE; - command -> header.channelID = acknowledgement -> command.header.channelID; - command -> acknowledge.receivedReliableSequenceNumber = ENET_HOST_TO_NET_16 (acknowledgement -> command.header.reliableSequenceNumber); - command -> acknowledge.receivedSentTime = ENET_HOST_TO_NET_16 (acknowledgement -> sentTime); - - if ((acknowledgement -> command.header.command & ENET_PROTOCOL_COMMAND_MASK) == ENET_PROTOCOL_COMMAND_DISCONNECT) - enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE); - - enet_list_remove (& acknowledgement -> acknowledgementList); - enet_free (acknowledgement); - - ++ command; - ++ buffer; - } - - host -> commandCount = command - host -> commands; - host -> bufferCount = buffer - host -> buffers; -} - -static void -enet_protocol_send_unreliable_outgoing_commands (ENetHost * host, ENetPeer * peer) -{ - ENetProtocol * command = & host -> commands [host -> commandCount]; - ENetBuffer * buffer = & host -> buffers [host -> bufferCount]; - ENetOutgoingCommand * outgoingCommand; - ENetListIterator currentCommand; - - currentCommand = enet_list_begin (& peer -> outgoingUnreliableCommands); - - while (currentCommand != enet_list_end (& peer -> outgoingUnreliableCommands)) - { - size_t commandSize; - - outgoingCommand = (ENetOutgoingCommand *) currentCommand; - commandSize = commandSizes [outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK]; - - if (command >= & host -> commands [sizeof (host -> commands) / sizeof (ENetProtocol)] || - buffer + 1 >= & host -> buffers [sizeof (host -> buffers) / sizeof (ENetBuffer)] || - peer -> mtu - host -> packetSize < commandSize || - (outgoingCommand -> packet != NULL && - peer -> mtu - host -> packetSize < commandSize + outgoingCommand -> packet -> dataLength)) - { - host -> continueSending = 1; - - break; - } - - currentCommand = enet_list_next (currentCommand); - - if (outgoingCommand -> packet != NULL) - { - peer -> packetThrottleCounter += ENET_PEER_PACKET_THROTTLE_COUNTER; - peer -> packetThrottleCounter %= ENET_PEER_PACKET_THROTTLE_SCALE; - - if (peer -> packetThrottleCounter > peer -> packetThrottle) - { - -- outgoingCommand -> packet -> referenceCount; - - if (outgoingCommand -> packet -> referenceCount == 0) - enet_packet_destroy (outgoingCommand -> packet); - - enet_list_remove (& outgoingCommand -> outgoingCommandList); - enet_free (outgoingCommand); - - continue; - } - } - - buffer -> data = command; - buffer -> dataLength = commandSize; - - host -> packetSize += buffer -> dataLength; - - * command = outgoingCommand -> command; - - enet_list_remove (& outgoingCommand -> outgoingCommandList); - - if (outgoingCommand -> packet != NULL) - { - ++ buffer; - - buffer -> data = outgoingCommand -> packet -> data; - buffer -> dataLength = outgoingCommand -> packet -> dataLength; - - host -> packetSize += buffer -> dataLength; - - enet_list_insert (enet_list_end (& peer -> sentUnreliableCommands), outgoingCommand); - } - else - enet_free (outgoingCommand); - - ++ command; - ++ buffer; - } - - host -> commandCount = command - host -> commands; - host -> bufferCount = buffer - host -> buffers; - - if (peer -> state == ENET_PEER_STATE_DISCONNECT_LATER && - enet_list_empty (& peer -> outgoingReliableCommands) && - enet_list_empty (& peer -> outgoingUnreliableCommands) && - enet_list_empty (& peer -> sentReliableCommands)) - enet_peer_disconnect (peer, peer -> eventData); -} - -static int -enet_protocol_check_timeouts (ENetHost * host, ENetPeer * peer, ENetEvent * event) -{ - ENetOutgoingCommand * outgoingCommand; - ENetListIterator currentCommand, insertPosition; - - currentCommand = enet_list_begin (& peer -> sentReliableCommands); - insertPosition = enet_list_begin (& peer -> outgoingReliableCommands); - - while (currentCommand != enet_list_end (& peer -> sentReliableCommands)) - { - outgoingCommand = (ENetOutgoingCommand *) currentCommand; - - currentCommand = enet_list_next (currentCommand); - - if (ENET_TIME_DIFFERENCE (host -> serviceTime, outgoingCommand -> sentTime) < outgoingCommand -> roundTripTimeout) - continue; - - if (peer -> earliestTimeout == 0 || - ENET_TIME_LESS (outgoingCommand -> sentTime, peer -> earliestTimeout)) - peer -> earliestTimeout = outgoingCommand -> sentTime; - - if (peer -> earliestTimeout != 0 && - (ENET_TIME_DIFFERENCE (host -> serviceTime, peer -> earliestTimeout) >= ENET_PEER_TIMEOUT_MAXIMUM || - (outgoingCommand -> roundTripTimeout >= outgoingCommand -> roundTripTimeoutLimit && - ENET_TIME_DIFFERENCE (host -> serviceTime, peer -> earliestTimeout) >= ENET_PEER_TIMEOUT_MINIMUM))) - { - enet_protocol_notify_disconnect (host, peer, event); - - return 1; - } - - if (outgoingCommand -> packet != NULL) - peer -> reliableDataInTransit -= outgoingCommand -> fragmentLength; - - ++ peer -> packetsLost; - - outgoingCommand -> roundTripTimeout *= 2; - - enet_list_insert (insertPosition, enet_list_remove (& outgoingCommand -> outgoingCommandList)); - - if (currentCommand == enet_list_begin (& peer -> sentReliableCommands) && - ! enet_list_empty (& peer -> sentReliableCommands)) - { - outgoingCommand = (ENetOutgoingCommand *) currentCommand; - - peer -> nextTimeout = outgoingCommand -> sentTime + outgoingCommand -> roundTripTimeout; - } - } - - return 0; -} - -static void -enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer) -{ - ENetProtocol * command = & host -> commands [host -> commandCount]; - ENetBuffer * buffer = & host -> buffers [host -> bufferCount]; - ENetOutgoingCommand * outgoingCommand; - ENetListIterator currentCommand; - ENetChannel *channel; - enet_uint16 reliableWindow; - size_t commandSize; - - currentCommand = enet_list_begin (& peer -> outgoingReliableCommands); - - while (currentCommand != enet_list_end (& peer -> outgoingReliableCommands)) - { - outgoingCommand = (ENetOutgoingCommand *) currentCommand; - - channel = outgoingCommand -> command.header.channelID < peer -> channelCount ? & peer -> channels [outgoingCommand -> command.header.channelID] : NULL; - reliableWindow = outgoingCommand -> reliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE; - if (channel != NULL && - outgoingCommand -> sendAttempts < 1 && - ! (outgoingCommand -> reliableSequenceNumber % ENET_PEER_RELIABLE_WINDOW_SIZE) && - (channel -> reliableWindows [(reliableWindow + ENET_PEER_RELIABLE_WINDOWS - 1) % ENET_PEER_RELIABLE_WINDOWS] >= ENET_PEER_RELIABLE_WINDOW_SIZE || - channel -> usedReliableWindows & ((((1 << ENET_PEER_FREE_RELIABLE_WINDOWS) - 1) << reliableWindow) | - (((1 << ENET_PEER_FREE_RELIABLE_WINDOWS) - 1) >> (ENET_PEER_RELIABLE_WINDOW_SIZE - reliableWindow))))) - break; - - commandSize = commandSizes [outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK]; - if (command >= & host -> commands [sizeof (host -> commands) / sizeof (ENetProtocol)] || - buffer + 1 >= & host -> buffers [sizeof (host -> buffers) / sizeof (ENetBuffer)] || - peer -> mtu - host -> packetSize < commandSize) - { - host -> continueSending = 1; - - break; - } - - if (outgoingCommand -> packet != NULL) - { - if (peer -> reliableDataInTransit + outgoingCommand -> fragmentLength > peer -> windowSize) - break; - - if ((enet_uint16) (peer -> mtu - host -> packetSize) < (enet_uint16) (commandSize + outgoingCommand -> fragmentLength)) - { - host -> continueSending = 1; - - break; - } - } - - currentCommand = enet_list_next (currentCommand); - - if (channel != NULL && outgoingCommand -> sendAttempts < 1) - { - channel -> usedReliableWindows |= 1 << reliableWindow; - ++ channel -> reliableWindows [reliableWindow]; - } - - ++ outgoingCommand -> sendAttempts; - - if (outgoingCommand -> roundTripTimeout == 0) - { - outgoingCommand -> roundTripTimeout = peer -> roundTripTime + 4 * peer -> roundTripTimeVariance; - outgoingCommand -> roundTripTimeoutLimit = ENET_PEER_TIMEOUT_LIMIT * outgoingCommand -> roundTripTimeout; - } - - if (enet_list_empty (& peer -> sentReliableCommands)) - peer -> nextTimeout = host -> serviceTime + outgoingCommand -> roundTripTimeout; - - enet_list_insert (enet_list_end (& peer -> sentReliableCommands), - enet_list_remove (& outgoingCommand -> outgoingCommandList)); - - outgoingCommand -> sentTime = host -> serviceTime; - - buffer -> data = command; - buffer -> dataLength = commandSize; - - host -> packetSize += buffer -> dataLength; - host -> headerFlags |= ENET_PROTOCOL_HEADER_FLAG_SENT_TIME; - - * command = outgoingCommand -> command; - - if (outgoingCommand -> packet != NULL) - { - ++ buffer; - - buffer -> data = outgoingCommand -> packet -> data + outgoingCommand -> fragmentOffset; - buffer -> dataLength = outgoingCommand -> fragmentLength; - - host -> packetSize += outgoingCommand -> fragmentLength; - - peer -> reliableDataInTransit += outgoingCommand -> fragmentLength; - } - - ++ peer -> packetsSent; - - ++ command; - ++ buffer; - } - - host -> commandCount = command - host -> commands; - host -> bufferCount = buffer - host -> buffers; -} - -static int -enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int checkForTimeouts) -{ - enet_uint8 headerData [sizeof (ENetProtocolHeader) + sizeof (enet_uint32)]; - ENetProtocolHeader * header = (ENetProtocolHeader *) headerData; - ENetPeer * currentPeer; - int sentLength; - size_t shouldCompress = 0; - - host -> continueSending = 1; - - while (host -> continueSending) - for (host -> continueSending = 0, - currentPeer = host -> peers; - currentPeer < & host -> peers [host -> peerCount]; - ++ currentPeer) - { - if (currentPeer -> state == ENET_PEER_STATE_DISCONNECTED || - currentPeer -> state == ENET_PEER_STATE_ZOMBIE) - continue; - - host -> headerFlags = 0; - host -> commandCount = 0; - host -> bufferCount = 1; - host -> packetSize = sizeof (ENetProtocolHeader); - - if (! enet_list_empty (& currentPeer -> acknowledgements)) - enet_protocol_send_acknowledgements (host, currentPeer); - - if (checkForTimeouts != 0 && - ! enet_list_empty (& currentPeer -> sentReliableCommands) && - ENET_TIME_GREATER_EQUAL (host -> serviceTime, currentPeer -> nextTimeout) && - enet_protocol_check_timeouts (host, currentPeer, event) == 1) - return 1; - - if (! enet_list_empty (& currentPeer -> outgoingReliableCommands)) - enet_protocol_send_reliable_outgoing_commands (host, currentPeer); - else - if (enet_list_empty (& currentPeer -> sentReliableCommands) && - ENET_TIME_DIFFERENCE (host -> serviceTime, currentPeer -> lastReceiveTime) >= ENET_PEER_PING_INTERVAL && - currentPeer -> mtu - host -> packetSize >= sizeof (ENetProtocolPing)) - { - enet_peer_ping (currentPeer); - enet_protocol_send_reliable_outgoing_commands (host, currentPeer); - } - - if (! enet_list_empty (& currentPeer -> outgoingUnreliableCommands)) - enet_protocol_send_unreliable_outgoing_commands (host, currentPeer); - - if (host -> commandCount == 0) - continue; - - if (currentPeer -> packetLossEpoch == 0) - currentPeer -> packetLossEpoch = host -> serviceTime; - else - if (ENET_TIME_DIFFERENCE (host -> serviceTime, currentPeer -> packetLossEpoch) >= ENET_PEER_PACKET_LOSS_INTERVAL && - currentPeer -> packetsSent > 0) - { - enet_uint32 packetLoss = currentPeer -> packetsLost * ENET_PEER_PACKET_LOSS_SCALE / currentPeer -> packetsSent; - -#ifdef ENET_DEBUG -#ifdef WIN32 - printf ( -#else - fprintf (stderr, -#endif - "peer %u: %f%%+-%f%% packet loss, %u+-%u ms round trip time, %f%% throttle, %u/%u outgoing, %u/%u incoming\n", currentPeer -> incomingPeerID, currentPeer -> packetLoss / (float) ENET_PEER_PACKET_LOSS_SCALE, currentPeer -> packetLossVariance / (float) ENET_PEER_PACKET_LOSS_SCALE, currentPeer -> roundTripTime, currentPeer -> roundTripTimeVariance, currentPeer -> packetThrottle / (float) ENET_PEER_PACKET_THROTTLE_SCALE, enet_list_size (& currentPeer -> outgoingReliableCommands), enet_list_size (& currentPeer -> outgoingUnreliableCommands), currentPeer -> channels != NULL ? enet_list_size (& currentPeer -> channels -> incomingReliableCommands) : 0, currentPeer -> channels != NULL ? enet_list_size (& currentPeer -> channels -> incomingUnreliableCommands) : 0); -#endif - - currentPeer -> packetLossVariance -= currentPeer -> packetLossVariance / 4; - - if (packetLoss >= currentPeer -> packetLoss) - { - currentPeer -> packetLoss += (packetLoss - currentPeer -> packetLoss) / 8; - currentPeer -> packetLossVariance += (packetLoss - currentPeer -> packetLoss) / 4; - } - else - { - currentPeer -> packetLoss -= (currentPeer -> packetLoss - packetLoss) / 8; - currentPeer -> packetLossVariance += (currentPeer -> packetLoss - packetLoss) / 4; - } - - currentPeer -> packetLossEpoch = host -> serviceTime; - currentPeer -> packetsSent = 0; - currentPeer -> packetsLost = 0; - } - - host -> buffers -> data = headerData; - if (host -> headerFlags & ENET_PROTOCOL_HEADER_FLAG_SENT_TIME) - { - header -> sentTime = ENET_HOST_TO_NET_16 (host -> serviceTime & 0xFFFF); - - host -> buffers -> dataLength = sizeof (ENetProtocolHeader); - } - else - host -> buffers -> dataLength = (size_t) & ((ENetProtocolHeader *) 0) -> sentTime; - - shouldCompress = 0; - if (host -> compressor.context != NULL && host -> compressor.compress != NULL) - { - size_t originalSize = host -> packetSize - sizeof(ENetProtocolHeader), - compressedSize = host -> compressor.compress (host -> compressor.context, - & host -> buffers [1], host -> bufferCount - 1, - originalSize, - host -> packetData [1], - originalSize); - if (compressedSize > 0 && compressedSize < originalSize) - { - host -> headerFlags |= ENET_PROTOCOL_HEADER_FLAG_COMPRESSED; - shouldCompress = compressedSize; -#ifdef ENET_DEBUG_COMPRESS -#ifdef WIN32 - printf ( -#else - fprintf (stderr, -#endif - "peer %u: compressed %u -> %u (%u%%)\n", currentPeer -> incomingPeerID, originalSize, compressedSize, (compressedSize * 100) / originalSize); -#endif - } - } - - if (currentPeer -> outgoingPeerID < ENET_PROTOCOL_MAXIMUM_PEER_ID) - host -> headerFlags |= currentPeer -> outgoingSessionID << ENET_PROTOCOL_HEADER_SESSION_SHIFT; - header -> peerID = ENET_HOST_TO_NET_16 (currentPeer -> outgoingPeerID | host -> headerFlags); - if (host -> checksum != NULL) - { - enet_uint32 * checksum = (enet_uint32 *) & headerData [host -> buffers -> dataLength]; - * checksum = currentPeer -> outgoingPeerID < ENET_PROTOCOL_MAXIMUM_PEER_ID ? currentPeer -> connectID : 0; - host -> buffers -> dataLength += sizeof (enet_uint32); - * checksum = host -> checksum (host -> buffers, host -> bufferCount); - } - - if (shouldCompress > 0) - { - host -> buffers [1].data = host -> packetData [1]; - host -> buffers [1].dataLength = shouldCompress; - host -> bufferCount = 2; - } - - currentPeer -> lastSendTime = host -> serviceTime; - - sentLength = enet_socket_send (host -> socket, & currentPeer -> address, host -> buffers, host -> bufferCount); - - enet_protocol_remove_sent_unreliable_commands (currentPeer); - - if (sentLength < 0) - return -1; - - host -> totalSentData += sentLength; - host -> totalSentPackets ++; - } - - return 0; -} - -/** Sends any queued packets on the host specified to its designated peers. - - @param host host to flush - @remarks this function need only be used in circumstances where one wishes to send queued packets earlier than in a call to enet_host_service(). - @ingroup host -*/ -void -enet_host_flush (ENetHost * host) -{ - host -> serviceTime = enet_time_get (); - - enet_protocol_send_outgoing_commands (host, NULL, 0); -} - -/** Checks for any queued events on the host and dispatches one if available. - - @param host host to check for events - @param event an event structure where event details will be placed if available - @retval > 0 if an event was dispatched - @retval 0 if no events are available - @retval < 0 on failure - @ingroup host -*/ -int -enet_host_check_events (ENetHost * host, ENetEvent * event) -{ - if (event == NULL) return -1; - - event -> type = ENET_EVENT_TYPE_NONE; - event -> peer = NULL; - event -> packet = NULL; - - return enet_protocol_dispatch_incoming_commands (host, event); -} - -/** Waits for events on the host specified and shuttles packets between - the host and its peers. - - @param host host to service - @param event an event structure where event details will be placed if one occurs - if event == NULL then no events will be delivered - @param timeout number of milliseconds that ENet should wait for events - @retval > 0 if an event occurred within the specified time limit - @retval 0 if no event occurred - @retval < 0 on failure - @remarks enet_host_service should be called fairly regularly for adequate performance - @ingroup host -*/ -int -enet_host_service (ENetHost * host, ENetEvent * event, enet_uint32 timeout) -{ - enet_uint32 waitCondition; - - if (event != NULL) - { - event -> type = ENET_EVENT_TYPE_NONE; - event -> peer = NULL; - event -> packet = NULL; - - switch (enet_protocol_dispatch_incoming_commands (host, event)) - { - case 1: - return 1; - - case -1: - perror ("Error dispatching incoming packets"); - - return -1; - - default: - break; - } - } - - host -> serviceTime = enet_time_get (); - - timeout += host -> serviceTime; - - do - { - if (ENET_TIME_DIFFERENCE (host -> serviceTime, host -> bandwidthThrottleEpoch) >= ENET_HOST_BANDWIDTH_THROTTLE_INTERVAL) - enet_host_bandwidth_throttle (host); - - switch (enet_protocol_send_outgoing_commands (host, event, 1)) - { - case 1: - return 1; - - case -1: - perror ("Error sending outgoing packets"); - - return -1; - - default: - break; - } - - switch (enet_protocol_receive_incoming_commands (host, event)) - { - case 1: - return 1; - - case -1: - perror ("Error receiving incoming packets"); - - return -1; - - default: - break; - } - - switch (enet_protocol_send_outgoing_commands (host, event, 1)) - { - case 1: - return 1; - - case -1: - perror ("Error sending outgoing packets"); - - return -1; - - default: - break; - } - - if (event != NULL) - { - switch (enet_protocol_dispatch_incoming_commands (host, event)) - { - case 1: - return 1; - - case -1: - perror ("Error dispatching incoming packets"); - - return -1; - - default: - break; - } - } - - host -> serviceTime = enet_time_get (); - - if (ENET_TIME_GREATER_EQUAL (host -> serviceTime, timeout)) - return 0; - - waitCondition = ENET_SOCKET_WAIT_RECEIVE; - - if (enet_socket_wait (host -> socket, & waitCondition, ENET_TIME_DIFFERENCE (timeout, host -> serviceTime)) != 0) - return -1; - - host -> serviceTime = enet_time_get (); - } while (waitCondition == ENET_SOCKET_WAIT_RECEIVE); - - return 0; -} - diff --git a/src/enet/protocol.h b/src/enet/protocol.h deleted file mode 100644 index 19f7e45de..000000000 --- a/src/enet/protocol.h +++ /dev/null @@ -1,196 +0,0 @@ -/** - @file protocol.h - @brief ENet protocol -*/ -#ifndef __ENET_PROTOCOL_H__ -#define __ENET_PROTOCOL_H__ - -#include "enet/types.h" - -enum -{ - ENET_PROTOCOL_MINIMUM_MTU = 576, - ENET_PROTOCOL_MAXIMUM_MTU = 4096, - ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS = 32, - ENET_PROTOCOL_MINIMUM_WINDOW_SIZE = 4096, - ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE = 32768, - ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT = 1, - ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255, - ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xFFF -}; - -typedef enum _ENetProtocolCommand -{ - ENET_PROTOCOL_COMMAND_NONE = 0, - ENET_PROTOCOL_COMMAND_ACKNOWLEDGE = 1, - ENET_PROTOCOL_COMMAND_CONNECT = 2, - ENET_PROTOCOL_COMMAND_VERIFY_CONNECT = 3, - ENET_PROTOCOL_COMMAND_DISCONNECT = 4, - ENET_PROTOCOL_COMMAND_PING = 5, - ENET_PROTOCOL_COMMAND_SEND_RELIABLE = 6, - ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE = 7, - ENET_PROTOCOL_COMMAND_SEND_FRAGMENT = 8, - ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED = 9, - ENET_PROTOCOL_COMMAND_BANDWIDTH_LIMIT = 10, - ENET_PROTOCOL_COMMAND_THROTTLE_CONFIGURE = 11, - ENET_PROTOCOL_COMMAND_COUNT = 12, - - ENET_PROTOCOL_COMMAND_MASK = 0x0F -} ENetProtocolCommand; - -typedef enum _ENetProtocolFlag -{ - ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE = (1 << 7), - ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED = (1 << 6), - - ENET_PROTOCOL_HEADER_FLAG_COMPRESSED = (1 << 14), - ENET_PROTOCOL_HEADER_FLAG_SENT_TIME = (1 << 15), - ENET_PROTOCOL_HEADER_FLAG_MASK = ENET_PROTOCOL_HEADER_FLAG_COMPRESSED | ENET_PROTOCOL_HEADER_FLAG_SENT_TIME, - - ENET_PROTOCOL_HEADER_SESSION_MASK = (3 << 12), - ENET_PROTOCOL_HEADER_SESSION_SHIFT = 12 -} ENetProtocolFlag; - -#ifdef _MSC_VER_ -#pragma pack(push, 1) -#define ENET_PACKED -#elif defined(__GNUC__) -#define ENET_PACKED __attribute__ ((packed)) -#else -#define ENET_PACKED -#endif - -typedef struct _ENetProtocolHeader -{ - enet_uint16 peerID; - enet_uint16 sentTime; -} ENET_PACKED ENetProtocolHeader; - -typedef struct _ENetProtocolCommandHeader -{ - enet_uint8 command; - enet_uint8 channelID; - enet_uint16 reliableSequenceNumber; -} ENET_PACKED ENetProtocolCommandHeader; - -typedef struct _ENetProtocolAcknowledge -{ - ENetProtocolCommandHeader header; - enet_uint16 receivedReliableSequenceNumber; - enet_uint16 receivedSentTime; -} ENET_PACKED ENetProtocolAcknowledge; - -typedef struct _ENetProtocolConnect -{ - ENetProtocolCommandHeader header; - enet_uint16 outgoingPeerID; - enet_uint8 incomingSessionID; - enet_uint8 outgoingSessionID; - enet_uint32 mtu; - enet_uint32 windowSize; - enet_uint32 channelCount; - enet_uint32 incomingBandwidth; - enet_uint32 outgoingBandwidth; - enet_uint32 packetThrottleInterval; - enet_uint32 packetThrottleAcceleration; - enet_uint32 packetThrottleDeceleration; - enet_uint32 connectID; - enet_uint32 data; -} ENET_PACKED ENetProtocolConnect; - -typedef struct _ENetProtocolVerifyConnect -{ - ENetProtocolCommandHeader header; - enet_uint16 outgoingPeerID; - enet_uint8 incomingSessionID; - enet_uint8 outgoingSessionID; - enet_uint32 mtu; - enet_uint32 windowSize; - enet_uint32 channelCount; - enet_uint32 incomingBandwidth; - enet_uint32 outgoingBandwidth; - enet_uint32 packetThrottleInterval; - enet_uint32 packetThrottleAcceleration; - enet_uint32 packetThrottleDeceleration; - enet_uint32 connectID; -} ENET_PACKED ENetProtocolVerifyConnect; - -typedef struct _ENetProtocolBandwidthLimit -{ - ENetProtocolCommandHeader header; - enet_uint32 incomingBandwidth; - enet_uint32 outgoingBandwidth; -} ENET_PACKED ENetProtocolBandwidthLimit; - -typedef struct _ENetProtocolThrottleConfigure -{ - ENetProtocolCommandHeader header; - enet_uint32 packetThrottleInterval; - enet_uint32 packetThrottleAcceleration; - enet_uint32 packetThrottleDeceleration; -} ENET_PACKED ENetProtocolThrottleConfigure; - -typedef struct _ENetProtocolDisconnect -{ - ENetProtocolCommandHeader header; - enet_uint32 data; -} ENET_PACKED ENetProtocolDisconnect; - -typedef struct _ENetProtocolPing -{ - ENetProtocolCommandHeader header; -} ENET_PACKED ENetProtocolPing; - -typedef struct _ENetProtocolSendReliable -{ - ENetProtocolCommandHeader header; - enet_uint16 dataLength; -} ENET_PACKED ENetProtocolSendReliable; - -typedef struct _ENetProtocolSendUnreliable -{ - ENetProtocolCommandHeader header; - enet_uint16 unreliableSequenceNumber; - enet_uint16 dataLength; -} ENET_PACKED ENetProtocolSendUnreliable; - -typedef struct _ENetProtocolSendUnsequenced -{ - ENetProtocolCommandHeader header; - enet_uint16 unsequencedGroup; - enet_uint16 dataLength; -} ENET_PACKED ENetProtocolSendUnsequenced; - -typedef struct _ENetProtocolSendFragment -{ - ENetProtocolCommandHeader header; - enet_uint16 startSequenceNumber; - enet_uint16 dataLength; - enet_uint32 fragmentCount; - enet_uint32 fragmentNumber; - enet_uint32 totalLength; - enet_uint32 fragmentOffset; -} ENET_PACKED ENetProtocolSendFragment; - -typedef union _ENetProtocol -{ - ENetProtocolCommandHeader header; - ENetProtocolAcknowledge acknowledge; - ENetProtocolConnect connect; - ENetProtocolVerifyConnect verifyConnect; - ENetProtocolDisconnect disconnect; - ENetProtocolPing ping; - ENetProtocolSendReliable sendReliable; - ENetProtocolSendUnreliable sendUnreliable; - ENetProtocolSendUnsequenced sendUnsequenced; - ENetProtocolSendFragment sendFragment; - ENetProtocolBandwidthLimit bandwidthLimit; - ENetProtocolThrottleConfigure throttleConfigure; -} ENET_PACKED ENetProtocol; - -#ifdef _MSC_VER_ -#pragma pack(pop) -#endif - -#endif /* __ENET_PROTOCOL_H__ */ - diff --git a/src/enet/time.h b/src/enet/time.h deleted file mode 100644 index c82a54603..000000000 --- a/src/enet/time.h +++ /dev/null @@ -1,18 +0,0 @@ -/** - @file time.h - @brief ENet time constants and macros -*/ -#ifndef __ENET_TIME_H__ -#define __ENET_TIME_H__ - -#define ENET_TIME_OVERFLOW 86400000 - -#define ENET_TIME_LESS(a, b) ((a) - (b) >= ENET_TIME_OVERFLOW) -#define ENET_TIME_GREATER(a, b) ((b) - (a) >= ENET_TIME_OVERFLOW) -#define ENET_TIME_LESS_EQUAL(a, b) (! ENET_TIME_GREATER (a, b)) -#define ENET_TIME_GREATER_EQUAL(a, b) (! ENET_TIME_LESS (a, b)) - -#define ENET_TIME_DIFFERENCE(a, b) ((a) - (b) >= ENET_TIME_OVERFLOW ? (b) - (a) : (a) - (b)) - -#endif /* __ENET_TIME_H__ */ - diff --git a/src/enet/types.h b/src/enet/types.h deleted file mode 100644 index ab010a4b1..000000000 --- a/src/enet/types.h +++ /dev/null @@ -1,13 +0,0 @@ -/** - @file types.h - @brief type definitions for ENet -*/ -#ifndef __ENET_TYPES_H__ -#define __ENET_TYPES_H__ - -typedef unsigned char enet_uint8; /**< unsigned 8-bit type */ -typedef unsigned short enet_uint16; /**< unsigned 16-bit type */ -typedef unsigned int enet_uint32; /**< unsigned 32-bit type */ - -#endif /* __ENET_TYPES_H__ */ - diff --git a/src/enet/unix.c b/src/enet/unix.c deleted file mode 100644 index 9cb26692f..000000000 --- a/src/enet/unix.c +++ /dev/null @@ -1,443 +0,0 @@ -/** - @file unix.c - @brief ENet Unix system specific functions -*/ -#ifndef WIN32 - -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/ioctl.h> -#include <sys/time.h> -#include <arpa/inet.h> -#include <netdb.h> -#include <unistd.h> -#include <string.h> -#include <errno.h> -#include <time.h> - -#define ENET_BUILDING_LIB 1 -#include "enet/enet.h" - -#ifdef HAS_FCNTL -#include <fcntl.h> -#endif - -#ifdef __APPLE__ -#undef HAS_POLL -#endif - -#ifdef HAS_POLL -#include <sys/poll.h> -#endif - - -#ifndef HAS_SOCKLEN_T -#ifndef __socklen_t_defined -typedef __socklen_t socklen_t; -# define __socklen_t_defined -//typedef int socklen_t; -#endif -#endif - -#ifndef MSG_NOSIGNAL -#define MSG_NOSIGNAL 0 -#endif - -static enet_uint32 timeBase = 0; - -int -enet_initialize (void) -{ - return 0; -} - -void -enet_deinitialize (void) -{ -} - -enet_uint32 -enet_time_get (void) -{ - struct timeval timeVal; - - gettimeofday (& timeVal, NULL); - - return timeVal.tv_sec * 1000 + timeVal.tv_usec / 1000 - timeBase; -} - -void -enet_time_set (enet_uint32 newTimeBase) -{ - struct timeval timeVal; - - gettimeofday (& timeVal, NULL); - - timeBase = timeVal.tv_sec * 1000 + timeVal.tv_usec / 1000 - newTimeBase; -} - -int -enet_address_set_host (ENetAddress * address, const char * name) -{ - struct hostent * hostEntry = NULL; -#ifdef HAS_GETHOSTBYNAME_R - struct hostent hostData; - char buffer [2048]; - int errnum; - -#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum); -#else - hostEntry = gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & errnum); -#endif -#else - hostEntry = gethostbyname (name); -#endif - - if (hostEntry == NULL || - hostEntry -> h_addrtype != AF_INET) - { -#ifdef HAS_INET_PTON - if (! inet_pton (AF_INET, name, & address -> host)) -#else - if (! inet_aton (name, (struct in_addr *) & address -> host)) -#endif - return -1; - return 0; - } - - address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0]; - - return 0; -} - -int -enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength) -{ -#ifdef HAS_INET_NTOP - if (inet_ntop (AF_INET, & address -> host, name, nameLength) == NULL) -#else - char * addr = inet_ntoa (* (struct in_addr *) & address -> host); - if (addr != NULL) - strncpy (name, addr, nameLength); - else -#endif - return -1; - return 0; -} - -int -enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength) -{ - struct in_addr in; - struct hostent * hostEntry = NULL; -#ifdef HAS_GETHOSTBYADDR_R - struct hostent hostData; - char buffer [2048]; - int errnum; - - in.s_addr = address -> host; - -#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - gethostbyaddr_r ((char *) & in, sizeof (struct in_addr), AF_INET, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum); -#else - hostEntry = gethostbyaddr_r ((char *) & in, sizeof (struct in_addr), AF_INET, & hostData, buffer, sizeof (buffer), & errnum); -#endif -#else - in.s_addr = address -> host; - - hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET); -#endif - - if (hostEntry == NULL) - return enet_address_get_host_ip (address, name, nameLength); - - strncpy (name, hostEntry -> h_name, nameLength); - - return 0; -} - -int -enet_socket_bind (ENetSocket socket, const ENetAddress * address) -{ - struct sockaddr_in sin; - - memset (& sin, 0, sizeof (struct sockaddr_in)); - - sin.sin_family = AF_INET; - - if (address != NULL) - { - sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); - sin.sin_addr.s_addr = address -> host; - } - else - { - sin.sin_port = 0; - sin.sin_addr.s_addr = INADDR_ANY; - } - - return bind (socket, - (struct sockaddr *) & sin, - sizeof (struct sockaddr_in)); -} - -int -enet_socket_listen (ENetSocket socket, int backlog) -{ - return listen (socket, backlog < 0 ? SOMAXCONN : backlog); -} - -ENetSocket -enet_socket_create (ENetSocketType type) -{ - return socket (PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0); -} - -int -enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value) -{ - int result = -1; - switch (option) - { - case ENET_SOCKOPT_NONBLOCK: -#ifdef HAS_FCNTL - result = fcntl (socket, F_SETFL, O_NONBLOCK | fcntl (socket, F_GETFL)); -#else - result = ioctl (socket, FIONBIO, & value); -#endif - break; - - case ENET_SOCKOPT_BROADCAST: - result = setsockopt (socket, SOL_SOCKET, SO_BROADCAST, (char *) & value, sizeof (int)); - break; - - case ENET_SOCKOPT_REUSEADDR: - result = setsockopt (socket, SOL_SOCKET, SO_REUSEADDR, (char *) & value, sizeof (int)); - break; - - case ENET_SOCKOPT_RCVBUF: - result = setsockopt (socket, SOL_SOCKET, SO_RCVBUF, (char *) & value, sizeof (int)); - break; - - case ENET_SOCKOPT_SNDBUF: - result = setsockopt (socket, SOL_SOCKET, SO_SNDBUF, (char *) & value, sizeof (int)); - break; - - default: - break; - } - return result == -1 ? -1 : 0; -} - -int -enet_socket_connect (ENetSocket socket, const ENetAddress * address) -{ - struct sockaddr_in sin; - - memset (& sin, 0, sizeof (struct sockaddr_in)); - - sin.sin_family = AF_INET; - sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); - sin.sin_addr.s_addr = address -> host; - - return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in)); -} - -ENetSocket -enet_socket_accept (ENetSocket socket, ENetAddress * address) -{ - int result; - struct sockaddr_in sin; - socklen_t sinLength = sizeof (struct sockaddr_in); - - result = accept (socket, - address != NULL ? (struct sockaddr *) & sin : NULL, - address != NULL ? & sinLength : NULL); - - if (result == -1) - return ENET_SOCKET_NULL; - - if (address != NULL) - { - address -> host = (enet_uint32) sin.sin_addr.s_addr; - address -> port = ENET_NET_TO_HOST_16 (sin.sin_port); - } - - return result; -} - -void -enet_socket_destroy (ENetSocket socket) -{ - close (socket); -} - -int -enet_socket_send (ENetSocket socket, - const ENetAddress * address, - const ENetBuffer * buffers, - size_t bufferCount) -{ - struct msghdr msgHdr; - struct sockaddr_in sin; - int sentLength; - - memset (& msgHdr, 0, sizeof (struct msghdr)); - - if (address != NULL) - { - memset (& sin, 0, sizeof (struct sockaddr_in)); - - sin.sin_family = AF_INET; - sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); - sin.sin_addr.s_addr = address -> host; - - msgHdr.msg_name = & sin; - msgHdr.msg_namelen = sizeof (struct sockaddr_in); - } - - msgHdr.msg_iov = (struct iovec *) buffers; - msgHdr.msg_iovlen = bufferCount; - - sentLength = sendmsg (socket, & msgHdr, MSG_NOSIGNAL); - - if (sentLength == -1) - { - if (errno == EWOULDBLOCK) - return 0; - - return -1; - } - - return sentLength; -} - -int -enet_socket_receive (ENetSocket socket, - ENetAddress * address, - ENetBuffer * buffers, - size_t bufferCount) -{ - struct msghdr msgHdr; - struct sockaddr_in sin; - int recvLength; - - memset (& msgHdr, 0, sizeof (struct msghdr)); - - if (address != NULL) - { - msgHdr.msg_name = & sin; - msgHdr.msg_namelen = sizeof (struct sockaddr_in); - } - - msgHdr.msg_iov = (struct iovec *) buffers; - msgHdr.msg_iovlen = bufferCount; - - recvLength = recvmsg (socket, & msgHdr, MSG_NOSIGNAL); - - if (recvLength == -1) - { - if (errno == EWOULDBLOCK) - return 0; - - return -1; - } - -#ifdef HAS_MSGHDR_FLAGS - if (msgHdr.msg_flags & MSG_TRUNC) - return -1; -#endif - - if (address != NULL) - { - address -> host = (enet_uint32) sin.sin_addr.s_addr; - address -> port = ENET_NET_TO_HOST_16 (sin.sin_port); - } - - return recvLength; -} - -int -enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocketSet * writeSet, enet_uint32 timeout) -{ - struct timeval timeVal; - - timeVal.tv_sec = timeout / 1000; - timeVal.tv_usec = (timeout % 1000) * 1000; - - return select (maxSocket + 1, readSet, writeSet, NULL, & timeVal); -} - -int -enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeout) -{ -#ifdef HAS_POLL - struct pollfd pollSocket; - int pollCount; - - pollSocket.fd = socket; - pollSocket.events = 0; - - if (* condition & ENET_SOCKET_WAIT_SEND) - pollSocket.events |= POLLOUT; - - if (* condition & ENET_SOCKET_WAIT_RECEIVE) - pollSocket.events |= POLLIN; - - pollCount = poll (& pollSocket, 1, timeout); - - if (pollCount < 0) - return -1; - - * condition = ENET_SOCKET_WAIT_NONE; - - if (pollCount == 0) - return 0; - - if (pollSocket.revents & POLLOUT) - * condition |= ENET_SOCKET_WAIT_SEND; - - if (pollSocket.revents & POLLIN) - * condition |= ENET_SOCKET_WAIT_RECEIVE; - - return 0; -#else - fd_set readSet, writeSet; - struct timeval timeVal; - int selectCount; - - timeVal.tv_sec = timeout / 1000; - timeVal.tv_usec = (timeout % 1000) * 1000; - - FD_ZERO (& readSet); - FD_ZERO (& writeSet); - - if (* condition & ENET_SOCKET_WAIT_SEND) - FD_SET (socket, & writeSet); - - if (* condition & ENET_SOCKET_WAIT_RECEIVE) - FD_SET (socket, & readSet); - - selectCount = select (socket + 1, & readSet, & writeSet, NULL, & timeVal); - - if (selectCount < 0) - return -1; - - * condition = ENET_SOCKET_WAIT_NONE; - - if (selectCount == 0) - return 0; - - if (FD_ISSET (socket, & writeSet)) - * condition |= ENET_SOCKET_WAIT_SEND; - - if (FD_ISSET (socket, & readSet)) - * condition |= ENET_SOCKET_WAIT_RECEIVE; - - return 0; -#endif -} - -#endif - diff --git a/src/enet/unix.h b/src/enet/unix.h deleted file mode 100644 index 087015e51..000000000 --- a/src/enet/unix.h +++ /dev/null @@ -1,45 +0,0 @@ -/** - @file unix.h - @brief ENet Unix header -*/ -#ifndef __ENET_UNIX_H__ -#define __ENET_UNIX_H__ - -#include <stdlib.h> -#include <sys/time.h> -#include <sys/types.h> -#include <netinet/in.h> -#include <unistd.h> - -typedef int ENetSocket; - -enum -{ - ENET_SOCKET_NULL = -1 -}; - -#define ENET_HOST_TO_NET_16(value) (htons (value)) /**< macro that converts host to net byte-order of a 16-bit value */ -#define ENET_HOST_TO_NET_32(value) (htonl (value)) /**< macro that converts host to net byte-order of a 32-bit value */ - -#define ENET_NET_TO_HOST_16(value) (ntohs (value)) /**< macro that converts net to host byte-order of a 16-bit value */ -#define ENET_NET_TO_HOST_32(value) (ntohl (value)) /**< macro that converts net to host byte-order of a 32-bit value */ - -typedef struct -{ - void * data; - size_t dataLength; -} ENetBuffer; - -#define ENET_CALLBACK - -#define ENET_API extern - -typedef fd_set ENetSocketSet; - -#define ENET_SOCKETSET_EMPTY(sockset) FD_ZERO (& (sockset)) -#define ENET_SOCKETSET_ADD(sockset, socket) FD_SET (socket, & (sockset)) -#define ENET_SOCKETSET_REMOVE(sockset, socket) FD_CLEAR (socket, & (sockset)) -#define ENET_SOCKETSET_CHECK(sockset, socket) FD_ISSET (socket, & (sockset)) - -#endif /* __ENET_UNIX_H__ */ - diff --git a/src/enet/utility.h b/src/enet/utility.h deleted file mode 100644 index e48a476be..000000000 --- a/src/enet/utility.h +++ /dev/null @@ -1,12 +0,0 @@ -/** - @file utility.h - @brief ENet utility header -*/ -#ifndef __ENET_UTILITY_H__ -#define __ENET_UTILITY_H__ - -#define ENET_MAX(x, y) ((x) > (y) ? (x) : (y)) -#define ENET_MIN(x, y) ((x) < (y) ? (x) : (y)) - -#endif /* __ENET_UTILITY_H__ */ - diff --git a/src/enet/win32.c b/src/enet/win32.c deleted file mode 100644 index e1fae2330..000000000 --- a/src/enet/win32.c +++ /dev/null @@ -1,348 +0,0 @@ -/** - @file win32.c - @brief ENet Win32 system specific functions -*/ -#ifdef WIN32 - -#include <time.h> -#define ENET_BUILDING_LIB 1 -#include "enet/enet.h" - -static enet_uint32 timeBase = 0; - -int -enet_initialize (void) -{ - WORD versionRequested = MAKEWORD (1, 1); - WSADATA wsaData; - - if (WSAStartup (versionRequested, & wsaData)) - return -1; - - if (LOBYTE (wsaData.wVersion) != 1|| - HIBYTE (wsaData.wVersion) != 1) - { - WSACleanup (); - - return -1; - } - - timeBeginPeriod (1); - - return 0; -} - -void -enet_deinitialize (void) -{ - timeEndPeriod (1); - - WSACleanup (); -} - -enet_uint32 -enet_time_get (void) -{ - return (enet_uint32) timeGetTime () - timeBase; -} - -void -enet_time_set (enet_uint32 newTimeBase) -{ - timeBase = (enet_uint32) timeGetTime () - newTimeBase; -} - -int -enet_address_set_host (ENetAddress * address, const char * name) -{ - struct hostent * hostEntry; - - hostEntry = gethostbyname (name); - if (hostEntry == NULL || - hostEntry -> h_addrtype != AF_INET) - { - unsigned long host = inet_addr (name); - if (host == INADDR_NONE) - return -1; - address -> host = host; - return 0; - } - - address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0]; - - return 0; -} - -int -enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength) -{ - char * addr = inet_ntoa (* (struct in_addr *) & address -> host); - if (addr == NULL) - return -1; - strncpy (name, addr, nameLength); - return 0; -} - -int -enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength) -{ - struct in_addr in; - struct hostent * hostEntry; - - in.s_addr = address -> host; - - hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET); - if (hostEntry == NULL) - return enet_address_get_host_ip (address, name, nameLength); - - strncpy (name, hostEntry -> h_name, nameLength); - - return 0; -} - -int -enet_socket_bind (ENetSocket socket, const ENetAddress * address) -{ - struct sockaddr_in sin; - - memset (& sin, 0, sizeof (struct sockaddr_in)); - - sin.sin_family = AF_INET; - - if (address != NULL) - { - sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); - sin.sin_addr.s_addr = address -> host; - } - else - { - sin.sin_port = 0; - sin.sin_addr.s_addr = INADDR_ANY; - } - - return bind (socket, - (struct sockaddr *) & sin, - sizeof (struct sockaddr_in)) == SOCKET_ERROR ? -1 : 0; -} - -int -enet_socket_listen (ENetSocket socket, int backlog) -{ - return listen (socket, backlog < 0 ? SOMAXCONN : backlog) == SOCKET_ERROR ? -1 : 0; -} - -ENetSocket -enet_socket_create (ENetSocketType type) -{ - return socket (PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0); -} - -int -enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value) -{ - int result = SOCKET_ERROR; - switch (option) - { - case ENET_SOCKOPT_NONBLOCK: - { - u_long nonBlocking = (u_long) value; - result = ioctlsocket (socket, FIONBIO, & nonBlocking); - break; - } - - case ENET_SOCKOPT_BROADCAST: - result = setsockopt (socket, SOL_SOCKET, SO_BROADCAST, (char *) & value, sizeof (int)); - break; - - case ENET_SOCKOPT_REUSEADDR: - result = setsockopt (socket, SOL_SOCKET, SO_REUSEADDR, (char *) & value, sizeof (int)); - break; - - case ENET_SOCKOPT_RCVBUF: - result = setsockopt (socket, SOL_SOCKET, SO_RCVBUF, (char *) & value, sizeof (int)); - break; - - case ENET_SOCKOPT_SNDBUF: - result = setsockopt (socket, SOL_SOCKET, SO_SNDBUF, (char *) & value, sizeof (int)); - break; - - default: - break; - } - return result == SOCKET_ERROR ? -1 : 0; -} - -int -enet_socket_connect (ENetSocket socket, const ENetAddress * address) -{ - struct sockaddr_in sin; - - memset (& sin, 0, sizeof (struct sockaddr_in)); - - sin.sin_family = AF_INET; - sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); - sin.sin_addr.s_addr = address -> host; - - return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in)) == SOCKET_ERROR ? -1 : 0; -} - -ENetSocket -enet_socket_accept (ENetSocket socket, ENetAddress * address) -{ - SOCKET result; - struct sockaddr_in sin; - int sinLength = sizeof (struct sockaddr_in); - - result = accept (socket, - address != NULL ? (struct sockaddr *) & sin : NULL, - address != NULL ? & sinLength : NULL); - - if (result == INVALID_SOCKET) - return ENET_SOCKET_NULL; - - if (address != NULL) - { - address -> host = (enet_uint32) sin.sin_addr.s_addr; - address -> port = ENET_NET_TO_HOST_16 (sin.sin_port); - } - - return result; -} - -void -enet_socket_destroy (ENetSocket socket) -{ - closesocket (socket); -} - -int -enet_socket_send (ENetSocket socket, - const ENetAddress * address, - const ENetBuffer * buffers, - size_t bufferCount) -{ - struct sockaddr_in sin; - DWORD sentLength; - - if (address != NULL) - { - memset (& sin, 0, sizeof (struct sockaddr_in)); - - sin.sin_family = AF_INET; - sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); - sin.sin_addr.s_addr = address -> host; - } - - if (WSASendTo (socket, - (LPWSABUF) buffers, - (DWORD) bufferCount, - & sentLength, - 0, - address != NULL ? (struct sockaddr *) & sin : 0, - address != NULL ? sizeof (struct sockaddr_in) : 0, - NULL, - NULL) == SOCKET_ERROR) - { - if (WSAGetLastError () == WSAEWOULDBLOCK) - return 0; - - return -1; - } - - return (int) sentLength; -} - -int -enet_socket_receive (ENetSocket socket, - ENetAddress * address, - ENetBuffer * buffers, - size_t bufferCount) -{ - INT sinLength = sizeof (struct sockaddr_in); - DWORD flags = 0, - recvLength; - struct sockaddr_in sin; - - if (WSARecvFrom (socket, - (LPWSABUF) buffers, - (DWORD) bufferCount, - & recvLength, - & flags, - address != NULL ? (struct sockaddr *) & sin : NULL, - address != NULL ? & sinLength : NULL, - NULL, - NULL) == SOCKET_ERROR) - { - switch (WSAGetLastError ()) - { - case WSAEWOULDBLOCK: - case WSAECONNRESET: - return 0; - } - - return -1; - } - - if (flags & MSG_PARTIAL) - return -1; - - if (address != NULL) - { - address -> host = (enet_uint32) sin.sin_addr.s_addr; - address -> port = ENET_NET_TO_HOST_16 (sin.sin_port); - } - - return (int) recvLength; -} - -int -enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocketSet * writeSet, enet_uint32 timeout) -{ - struct timeval timeVal; - - timeVal.tv_sec = timeout / 1000; - timeVal.tv_usec = (timeout % 1000) * 1000; - - return select (maxSocket + 1, readSet, writeSet, NULL, & timeVal); -} - -int -enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeout) -{ - fd_set readSet, writeSet; - struct timeval timeVal; - int selectCount; - - timeVal.tv_sec = timeout / 1000; - timeVal.tv_usec = (timeout % 1000) * 1000; - - FD_ZERO (& readSet); - FD_ZERO (& writeSet); - - if (* condition & ENET_SOCKET_WAIT_SEND) - FD_SET (socket, & writeSet); - - if (* condition & ENET_SOCKET_WAIT_RECEIVE) - FD_SET (socket, & readSet); - - selectCount = select (socket + 1, & readSet, & writeSet, NULL, & timeVal); - - if (selectCount < 0) - return -1; - - * condition = ENET_SOCKET_WAIT_NONE; - - if (selectCount == 0) - return 0; - - if (FD_ISSET (socket, & writeSet)) - * condition |= ENET_SOCKET_WAIT_SEND; - - if (FD_ISSET (socket, & readSet)) - * condition |= ENET_SOCKET_WAIT_RECEIVE; - - return 0; -} - -#endif - diff --git a/src/enet/win32.h b/src/enet/win32.h deleted file mode 100644 index 0e1cf0c5a..000000000 --- a/src/enet/win32.h +++ /dev/null @@ -1,58 +0,0 @@ -/** - @file win32.h - @brief ENet Win32 header -*/ -#ifndef __ENET_WIN32_H__ -#define __ENET_WIN32_H__ - -#ifdef ENET_BUILDING_LIB -#pragma warning (disable: 4996) // 'strncpy' was declared deprecated -#pragma warning (disable: 4267) // size_t to int conversion -#pragma warning (disable: 4244) // 64bit to 32bit int -#pragma warning (disable: 4018) // signed/unsigned mismatch -#endif - -#include <stdlib.h> -#include <winsock2.h> - -typedef SOCKET ENetSocket; - -enum -{ - ENET_SOCKET_NULL = INVALID_SOCKET -}; - -#define ENET_HOST_TO_NET_16(value) (htons (value)) -#define ENET_HOST_TO_NET_32(value) (htonl (value)) - -#define ENET_NET_TO_HOST_16(value) (ntohs (value)) -#define ENET_NET_TO_HOST_32(value) (ntohl (value)) - -typedef struct -{ - size_t dataLength; - void * data; -} ENetBuffer; - -#define ENET_CALLBACK __cdecl - -#if defined ENET_DLL -#if defined ENET_BUILDING_LIB -#define ENET_API __declspec( dllexport ) -#else -#define ENET_API __declspec( dllimport ) -#endif /* ENET_BUILDING_LIB */ -#else /* !ENET_DLL */ -#define ENET_API extern -#endif /* ENET_DLL */ - -typedef fd_set ENetSocketSet; - -#define ENET_SOCKETSET_EMPTY(sockset) FD_ZERO (& (sockset)) -#define ENET_SOCKETSET_ADD(sockset, socket) FD_SET (socket, & (sockset)) -#define ENET_SOCKETSET_REMOVE(sockset, socket) FD_CLEAR (socket, & (sockset)) -#define ENET_SOCKETSET_CHECK(sockset, socket) FD_ISSET (socket, & (sockset)) - -#endif /* __ENET_WIN32_H__ */ - - diff --git a/src/guichan/actionevent.cpp b/src/guichan/actionevent.cpp deleted file mode 100644 index 17013ddc9..000000000 --- a/src/guichan/actionevent.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/actionevent.hpp" - -#include "debug.h" - -namespace gcn -{ - ActionEvent::ActionEvent(Widget* source, const std::string& id) - :Event(source), - mId(id) - { - - } - - ActionEvent::~ActionEvent() - { - - } - - const std::string& ActionEvent::getId() const - { - return mId; - } -} - diff --git a/src/guichan/basiccontainer.cpp b/src/guichan/basiccontainer.cpp deleted file mode 100644 index d51968eb6..000000000 --- a/src/guichan/basiccontainer.cpp +++ /dev/null @@ -1,359 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/basiccontainer.hpp" - -#include <algorithm> - -#include "guichan/exception.hpp" -#include "guichan/focushandler.hpp" -#include "guichan/graphics.hpp" -#include "guichan/mouseinput.hpp" - -#include "debug.h" - -namespace gcn -{ - BasicContainer::~BasicContainer() - { - clear(); - } - - void BasicContainer::moveToTop(Widget* widget) - { - WidgetListIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter) - { - if (*iter == widget) - { - mWidgets.erase(iter); - mWidgets.push_back(widget); - return; - } - } - - throw GCN_EXCEPTION("There is no such widget in this container."); - } - - void BasicContainer::moveToBottom(Widget* widget) - { - WidgetListIterator iter; - iter = find(mWidgets.begin(), mWidgets.end(), widget); - - if (iter == mWidgets.end()) - throw GCN_EXCEPTION("There is no such widget in this container."); - - mWidgets.erase(iter); - mWidgets.insert(mWidgets.begin(), widget); -// mWidgets.push_front(widget); - } - - void BasicContainer::death(const Event& event) - { - WidgetListIterator iter; - iter = find(mWidgets.begin(), mWidgets.end(), event.getSource()); - - if (iter == mWidgets.end()) - throw GCN_EXCEPTION("There is no such widget in this container."); - - mWidgets.erase(iter); - } - - Rectangle BasicContainer::getChildrenArea() - { - return Rectangle(0, 0, getWidth(), getHeight()); - } - - void BasicContainer::focusNext() - { - WidgetListIterator it; - - for (it = mWidgets.begin(); it != mWidgets.end(); ++ it) - { - if ((*it)->isFocused()) - break; - } - - WidgetListIterator end = it; - - if (it == mWidgets.end()) - it = mWidgets.begin(); - - ++ it; - - for ( ; it != end; ++ it) - { - if (it == mWidgets.end()) - it = mWidgets.begin(); - - if ((*it)->isFocusable()) - { - (*it)->requestFocus(); - return; - } - } - } - - void BasicContainer::focusPrevious() - { - WidgetListReverseIterator it; - - for (it = mWidgets.rbegin(); it != mWidgets.rend(); ++ it) - { - if ((*it)->isFocused()) - break; - } - - WidgetListReverseIterator end = it; - - ++ it; - - if (it == mWidgets.rend()) - it = mWidgets.rbegin(); - - for ( ; it != end; ++ it) - { - if (it == mWidgets.rend()) - it = mWidgets.rbegin(); - - if ((*it)->isFocusable()) - { - (*it)->requestFocus(); - return; - } - } - } - - Widget *BasicContainer::getWidgetAt(int x, int y) - { - Rectangle r = getChildrenArea(); - - if (!r.isPointInRect(x, y)) - return NULL; - - x -= r.x; - y -= r.y; - - WidgetListReverseIterator it; - for (it = mWidgets.rbegin(); it != mWidgets.rend(); ++ it) - { - if ((*it)->isVisible() && (*it)->getDimension() - .isPointInRect(x, y)) - { - return (*it); - } - } - - return NULL; - } - - void BasicContainer::logic() - { - logicChildren(); - } - - void BasicContainer::_setFocusHandler(FocusHandler* focusHandler) - { - Widget::_setFocusHandler(focusHandler); - - if (mInternalFocusHandler != NULL) - return; - - WidgetListIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter) - { - (*iter)->_setFocusHandler(focusHandler); - } - } - - void BasicContainer::add(Widget* widget) - { - mWidgets.push_back(widget); - - if (mInternalFocusHandler == NULL) - widget->_setFocusHandler(_getFocusHandler()); - else - widget->_setFocusHandler(mInternalFocusHandler); - - widget->_setParent(this); - widget->addDeathListener(this); - } - - void BasicContainer::remove(Widget* widget) - { - WidgetListIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter) - { - if (*iter == widget) - { - mWidgets.erase(iter); - widget->_setFocusHandler(NULL); - widget->_setParent(NULL); - widget->removeDeathListener(this); - return; - } - } - - throw GCN_EXCEPTION("There is no such widget in this container."); - } - - void BasicContainer::clear() - { - WidgetListIterator iter; - - for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter) - { - (*iter)->_setFocusHandler(NULL); - (*iter)->_setParent(NULL); - (*iter)->removeDeathListener(this); - } - - mWidgets.clear(); - } - - void BasicContainer::drawChildren(Graphics* graphics) - { - graphics->pushClipArea(getChildrenArea()); - - WidgetListIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter) - { - if ((*iter)->isVisible()) - { - // If the widget has a frame, - // draw it before drawing the widget - if ((*iter)->getFrameSize() > 0) - { - Rectangle rec = (*iter)->getDimension(); - rec.x -= (*iter)->getFrameSize(); - rec.y -= (*iter)->getFrameSize(); - rec.width += 2 * (*iter)->getFrameSize(); - rec.height += 2 * (*iter)->getFrameSize(); - graphics->pushClipArea(rec); - (*iter)->drawFrame(graphics); - graphics->popClipArea(); - } - - graphics->pushClipArea((*iter)->getDimension()); - (*iter)->draw(graphics); - graphics->popClipArea(); - } - } - - graphics->popClipArea(); - } - - void BasicContainer::logicChildren() - { - WidgetListIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter) - (*iter)->logic(); - } - - void BasicContainer::showWidgetPart(Widget* widget, Rectangle area) - { - Rectangle widgetArea = getChildrenArea(); - - area.x += widget->getX(); - area.y += widget->getY(); - - if (area.x + area.width > widgetArea.width) - { - widget->setX(widget->getX() - area.x - - area.width + widgetArea.width); - } - - if (area.y + area.height > widgetArea.height) - { - widget->setY(widget->getY() - area.y - - area.height + widgetArea.height); - } - - if (area.x < 0) - widget->setX(widget->getX() - area.x); - - if (area.y < 0) - widget->setY(widget->getY() - area.y); - } - - void BasicContainer::setInternalFocusHandler(FocusHandler* focusHandler) - { - Widget::setInternalFocusHandler(focusHandler); - - WidgetListIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter) - { - if (mInternalFocusHandler == NULL) - (*iter)->_setFocusHandler(_getFocusHandler()); - else - (*iter)->_setFocusHandler(mInternalFocusHandler); - } - } - - Widget* BasicContainer::findWidgetById(const std::string& id) - { - WidgetListIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter) - { - if ((*iter)->getId() == id) - return (*iter); - - BasicContainer *basicContainer - = dynamic_cast<BasicContainer*>(*iter); - - if (basicContainer != NULL) - { - Widget *widget = basicContainer->findWidgetById(id); - - if (widget != NULL) - return widget; - } - } - - return NULL; - } -} diff --git a/src/guichan/cliprectangle.cpp b/src/guichan/cliprectangle.cpp deleted file mode 100644 index feaa47729..000000000 --- a/src/guichan/cliprectangle.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/cliprectangle.hpp" - -#include "debug.h" - -namespace gcn -{ - ClipRectangle::ClipRectangle() - { - x = 0; - y = 0; - width = 0; - height = 0; - xOffset = 0; - yOffset = 0; - } - - ClipRectangle::ClipRectangle(int x, int y, int width, int height, - int xOffset, int yOffset) - { - this->x = x; - this->y = y; - this->width = width; - this->height = height; - this->xOffset = xOffset; - this->yOffset = yOffset; - } - - const ClipRectangle& ClipRectangle::operator=(const Rectangle& other) - { - x = other.x; - y = other.y; - width = other.width; - height = other.height; - - return *this; - } -} diff --git a/src/guichan/color.cpp b/src/guichan/color.cpp deleted file mode 100644 index d8015fa20..000000000 --- a/src/guichan/color.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/color.hpp" - -#include "debug.h" - -namespace gcn -{ - Color::Color() : - r(0), - g(0), - b(0), - a(255) - { - } - - Color::Color(int color) : - r((color >> 16) & 0xFF), - g((color >> 8) & 0xFF), - b(color & 0xFF), - a(255) - { - } - - Color::Color(int ar, int ag, int ab, int aa) : - r(ar), - g(ag), - b(ab), - a(aa) - { - } - - Color Color::operator+(const Color& color) const - { - Color result(r + color.r, - g + color.g, - b + color.b, - 255); - - result.r = (result.r>255?255:(result.r<0?0:result.r)); - result.g = (result.g>255?255:(result.g<0?0:result.g)); - result.b = (result.b>255?255:(result.b<0?0:result.b)); - - return result; - } - - Color Color::operator-(const Color& color) const - { - Color result(r - color.r, - g - color.g, - b - color.b, - 255); - - result.r = (result.r>255?255:(result.r<0?0:result.r)); - result.g = (result.g>255?255:(result.g<0?0:result.g)); - result.b = (result.b>255?255:(result.b<0?0:result.b)); - - return result; - } - - Color Color::operator*(float value) const - { - Color result((int)(r * value), - (int)(g * value), - (int)(b * value), - a); - - result.r = (result.r>255?255:(result.r<0?0:result.r)); - result.g = (result.g>255?255:(result.g<0?0:result.g)); - result.b = (result.b>255?255:(result.b<0?0:result.b)); - - return result; - } - - bool Color::operator==(const Color& color) const - { - return r == color.r && g == color.g && b == color.b && a == color.a; - } - - bool Color::operator!=(const Color& color) const - { - return !(r == color.r && g == color.g && b == color.b && a == color.a); - } - - std::ostream& operator<<(std::ostream& out, - const Color& color) - { - out << "Color [r = " - << color.r - << ", g = " - << color.g - << ", b = " - << color.b - << ", a = " - << color.a - << "]"; - - return out; - } -} diff --git a/src/guichan/defaultfont.cpp b/src/guichan/defaultfont.cpp deleted file mode 100644 index f67b66495..000000000 --- a/src/guichan/defaultfont.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/defaultfont.hpp" - -#include <string> - -#include "guichan/graphics.hpp" -#include "guichan/rectangle.hpp" - -#include "debug.h" - -namespace gcn -{ - int DefaultFont::getHeight() const - { - return 8; - } - - int DefaultFont::getWidth(const std::string& text) const - { - return 8*text.size(); - } - - int DefaultFont::drawGlyph(Graphics* graphics, - unsigned char glyph A_UNUSED, int x, int y) - { - graphics->drawRectangle( Rectangle(x, y, 8, 8)); - - return 8; - } - - void DefaultFont::drawString(Graphics* graphics, const std::string& text, - int x, int y) - { - unsigned int i; - - for (i = 0; i< text.size(); ++i) - { - drawGlyph(graphics, text.at(i), x, y); - x += getWidth(text); - } - } - - int DefaultFont::getStringIndexAt(const std::string& text, int x) const - { - if (x > (int)text.size() * 8) - return text.size(); - - return x / 8; - } -} diff --git a/src/guichan/event.cpp b/src/guichan/event.cpp deleted file mode 100644 index e8e988b63..000000000 --- a/src/guichan/event.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/event.hpp" - -#include "debug.h" - -namespace gcn -{ - Event::Event(Widget* source) - :mSource(source) - { - - } - - Event::~Event() - { - - } - - Widget* Event::getSource() const - { - return mSource; - } -} - diff --git a/src/guichan/exception.cpp b/src/guichan/exception.cpp deleted file mode 100644 index e32c4f97a..000000000 --- a/src/guichan/exception.cpp +++ /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. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/exception.hpp" - -#include "debug.h" - -namespace gcn -{ - Exception::Exception() - : mFunction("?"), - mMessage(""), - mFilename("?"), - mLine(0) - { - - } - - Exception::Exception(const std::string& message) - : mFunction("?"), - mMessage(message), - mFilename("?"), - mLine(0) - { - - } - - Exception::Exception(const std::string& message, - const std::string& function, - const std::string& filename, - unsigned int line) - : mFunction(function), - mMessage(message), - mFilename(filename), - mLine(line) - { - - } - - const std::string& Exception::getFunction() const - { - return mFunction; - } - - const std::string& Exception::getMessage() const - { - return mMessage; - } - - const std::string& Exception::getFilename() const - { - return mFilename; - } - - unsigned int Exception::getLine() const - { - return mLine; - } -} diff --git a/src/guichan/focushandler.cpp b/src/guichan/focushandler.cpp deleted file mode 100644 index bb0378f59..000000000 --- a/src/guichan/focushandler.cpp +++ /dev/null @@ -1,555 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/focushandler.hpp" - -#include "guichan/focuslistener.hpp" -#include "guichan/exception.hpp" -#include "guichan/widget.hpp" - -#include "debug.h" - -namespace gcn -{ - FocusHandler::FocusHandler() : - mFocusedWidget(NULL), - mModalFocusedWidget(NULL), - mModalMouseInputFocusedWidget(NULL), - mDraggedWidget(NULL), - mLastWidgetWithMouse(NULL), - mLastWidgetWithModalFocus(NULL), - mLastWidgetWithModalMouseInputFocus(NULL), - mLastWidgetPressed(NULL) - { - } - - void FocusHandler::requestFocus(Widget* widget) - { - if (widget == NULL - || widget == mFocusedWidget) - { - return; - } - - unsigned int i = 0; - int toBeFocusedIndex = -1; - for (i = 0; i < mWidgets.size(); ++i) - { - if (mWidgets[i] == widget) - { - toBeFocusedIndex = i; - break; - } - } - - if (toBeFocusedIndex < 0) - throw GCN_EXCEPTION("Trying to focus a none existing widget."); - - Widget *oldFocused = mFocusedWidget; - - if (oldFocused != widget) - { - mFocusedWidget = mWidgets.at(toBeFocusedIndex); - - if (oldFocused != NULL) - { - Event focusEvent(oldFocused); - distributeFocusLostEvent(focusEvent); - } - - Event focusEvent(mWidgets.at(toBeFocusedIndex)); - distributeFocusGainedEvent(focusEvent); - } - } - - void FocusHandler::requestModalFocus(Widget* widget) - { - if (mModalFocusedWidget != NULL && mModalFocusedWidget != widget) - throw GCN_EXCEPTION("Another widget already has modal focus."); - - mModalFocusedWidget = widget; - - if (mFocusedWidget != NULL - && !mFocusedWidget->isModalFocused()) - { - focusNone(); - } - } - - void FocusHandler::requestModalMouseInputFocus(Widget* widget) - { - if (mModalMouseInputFocusedWidget != NULL - && mModalMouseInputFocusedWidget != widget) - { - throw GCN_EXCEPTION("Another widget already has " - "modal input focus."); - } - - mModalMouseInputFocusedWidget = widget; - } - - void FocusHandler::releaseModalFocus(Widget* widget) - { - if (mModalFocusedWidget == widget) - mModalFocusedWidget = NULL; - } - - void FocusHandler::releaseModalMouseInputFocus(Widget* widget) - { - if (mModalMouseInputFocusedWidget == widget) - mModalMouseInputFocusedWidget = NULL; - } - - Widget* FocusHandler::getFocused() const - { - return mFocusedWidget; - } - - Widget* FocusHandler::getModalFocused() const - { - return mModalFocusedWidget; - } - - Widget* FocusHandler::getModalMouseInputFocused() const - { - return mModalMouseInputFocusedWidget; - } - - void FocusHandler::focusNext() - { - int i; - int focusedWidget = -1; - for (i = 0; i < (int)mWidgets.size(); ++i) - { - if (mWidgets[i] == mFocusedWidget) - focusedWidget = i; - } - int focused = focusedWidget; - - // i is a counter that ensures that the following loop - // won't get stuck in an infinite loop - i = (int)mWidgets.size(); - do - { - ++ focusedWidget; - - if (i == 0) - { - focusedWidget = -1; - break; - } - - -- i; - - if (focusedWidget >= (int)mWidgets.size()) - focusedWidget = 0; - - if (focusedWidget == focused) - return; - } - while (!mWidgets.at(focusedWidget)->isFocusable()); - - if (focusedWidget >= 0) - { - mFocusedWidget = mWidgets.at(focusedWidget); - - Event focusEvent(mFocusedWidget); - distributeFocusGainedEvent(focusEvent); - } - - if (focused >= 0) - { - Event focusEvent(mWidgets.at(focused)); - distributeFocusLostEvent(focusEvent); - } - } - - void FocusHandler::focusPrevious() - { - if (mWidgets.empty()) - { - mFocusedWidget = NULL; - return; - } - - int i; - int focusedWidget = -1; - for (i = 0; i < (int)mWidgets.size(); ++ i) - { - if (mWidgets[i] == mFocusedWidget) - focusedWidget = i; - } - int focused = focusedWidget; - - // i is a counter that ensures that the following loop - // won't get stuck in an infinite loop - i = (int)mWidgets.size(); - do - { - -- focusedWidget; - - if (i == 0) - { - focusedWidget = -1; - break; - } - - -- i; - - if (focusedWidget <= 0) - focusedWidget = mWidgets.size() - 1; - - if (focusedWidget == focused) - return; - } - while (!mWidgets.at(focusedWidget)->isFocusable()); - - if (focusedWidget >= 0) - { - mFocusedWidget = mWidgets.at(focusedWidget); - Event focusEvent(mFocusedWidget); - distributeFocusGainedEvent(focusEvent); - } - - if (focused >= 0) - { - Event focusEvent(mWidgets.at(focused)); - distributeFocusLostEvent(focusEvent); - } - } - - bool FocusHandler::isFocused(const Widget* widget) const - { - return mFocusedWidget == widget; - } - - void FocusHandler::add(Widget* widget) - { - mWidgets.push_back(widget); - } - - void FocusHandler::remove(Widget* widget) - { - if (isFocused(widget)) - { - mFocusedWidget = NULL; - } - - WidgetIterator iter; - - for (iter = mWidgets.begin(); iter != mWidgets.end(); ++iter) - { - if ((*iter) == widget) - { - mWidgets.erase(iter); - break; - } - } - - if (mDraggedWidget == widget) - { - mDraggedWidget = NULL; - return; - } - - if (mLastWidgetWithMouse == widget) - { - mLastWidgetWithMouse = NULL; - return; - } - - if (mLastWidgetWithModalFocus == widget) - { - mLastWidgetWithModalFocus = NULL; - return; - } - - if (mLastWidgetWithModalMouseInputFocus == widget) - { - mLastWidgetWithModalMouseInputFocus = NULL; - return; - } - - if (mLastWidgetPressed == widget) - { - mLastWidgetPressed = NULL; - return; - } - } - - void FocusHandler::focusNone() - { - if (mFocusedWidget != NULL) - { - Widget* focused = mFocusedWidget; - mFocusedWidget = NULL; - - Event focusEvent(focused); - distributeFocusLostEvent(focusEvent); - } - } - - void FocusHandler::tabNext() - { - if (mFocusedWidget != NULL) - { - if (!mFocusedWidget->isTabOutEnabled()) - return; - } - - if (mWidgets.empty()) - { - mFocusedWidget = NULL; - return; - } - - int i; - int focusedWidget = -1; - for (i = 0; i < (int)mWidgets.size(); ++i) - { - if (mWidgets[i] == mFocusedWidget) - focusedWidget = i; - } - int focused = focusedWidget; - bool done = false; - - // i is a counter that ensures that the following loop - // won't get stuck in an infinite loop - i = (int)mWidgets.size(); - do - { - ++ focusedWidget; - - if (i == 0) - { - focusedWidget = -1; - break; - } - - -- i; - - if (focusedWidget >= (int)mWidgets.size()) - focusedWidget = 0; - - if (focusedWidget == focused) - return; - - if (mWidgets.at(focusedWidget)->isFocusable() && - mWidgets.at(focusedWidget)->isTabInEnabled() && - (mModalFocusedWidget == NULL || - mWidgets.at(focusedWidget)->isModalFocused())) - { - done = true; - } - } - while (!done); - - if (focusedWidget >= 0) - { - mFocusedWidget = mWidgets.at(focusedWidget); - Event focusEvent(mFocusedWidget); - distributeFocusGainedEvent(focusEvent); - } - - if (focused >= 0) - { - Event focusEvent(mWidgets.at(focused)); - distributeFocusLostEvent(focusEvent); - } - } - - void FocusHandler::tabPrevious() - { - if (mFocusedWidget != NULL) - { - if (!mFocusedWidget->isTabOutEnabled()) - return; - } - - if (mWidgets.empty()) - { - mFocusedWidget = NULL; - return; - } - - int i; - int focusedWidget = -1; - for (i = 0; i < (int)mWidgets.size(); ++i) - { - if (mWidgets[i] == mFocusedWidget) - focusedWidget = i; - } - int focused = focusedWidget; - bool done = false; - - // i is a counter that ensures that the following loop - // won't get stuck in an infinite loop - i = (int)mWidgets.size(); - do - { - -- focusedWidget; - - if (i == 0) - { - focusedWidget = -1; - break; - } - - -- i; - - if (focusedWidget <= 0) - focusedWidget = mWidgets.size() - 1; - - if (focusedWidget == focused) - return; - - if (mWidgets.at(focusedWidget)->isFocusable() && - mWidgets.at(focusedWidget)->isTabInEnabled() && - (mModalFocusedWidget == NULL || - mWidgets.at(focusedWidget)->isModalFocused())) - { - done = true; - } - } - while (!done); - - if (focusedWidget >= 0) - { - mFocusedWidget = mWidgets.at(focusedWidget); - Event focusEvent(mFocusedWidget); - distributeFocusGainedEvent(focusEvent); - } - - if (focused >= 0) - { - Event focusEvent(mWidgets.at(focused)); - distributeFocusLostEvent(focusEvent); - } - } - - void FocusHandler::distributeFocusLostEvent(const Event& focusEvent) - { - Widget* sourceWidget = focusEvent.getSource(); - - std::list<FocusListener*> focusListeners - = sourceWidget->_getFocusListeners(); - - // Send the event to all focus listeners of the widget. - for (std::list<FocusListener*>::iterator it = focusListeners.begin(); - it != focusListeners.end(); - ++ it) - { - (*it)->focusLost(focusEvent); - } - } - - void FocusHandler::distributeFocusGainedEvent(const Event& focusEvent) - { - Widget* sourceWidget = focusEvent.getSource(); - - std::list<FocusListener*> focusListeners - = sourceWidget->_getFocusListeners(); - - // Send the event to all focus listeners of the widget. - for (std::list<FocusListener*>::iterator it = focusListeners.begin(); - it != focusListeners.end(); - ++ it) - { - (*it)->focusGained(focusEvent); - } - } - - Widget* FocusHandler::getDraggedWidget() - { - return mDraggedWidget; - } - - void FocusHandler::setDraggedWidget(Widget* draggedWidget) - { - mDraggedWidget = draggedWidget; - } - - Widget* FocusHandler::getLastWidgetWithMouse() - { - return mLastWidgetWithMouse; - } - - void FocusHandler::setLastWidgetWithMouse(Widget* lastWidgetWithMouse) - { - mLastWidgetWithMouse = lastWidgetWithMouse; - } - - Widget* FocusHandler::getLastWidgetWithModalFocus() - { - return mLastWidgetWithModalFocus; - } - - void FocusHandler::setLastWidgetWithModalFocus(Widget* widget) - { - mLastWidgetWithModalFocus = widget; - } - - Widget* FocusHandler::getLastWidgetWithModalMouseInputFocus() - { - return mLastWidgetWithModalMouseInputFocus; - } - - void FocusHandler::setLastWidgetWithModalMouseInputFocus(Widget* widget) - { - mLastWidgetWithModalMouseInputFocus = widget; - } - - Widget* FocusHandler::getLastWidgetPressed() - { - return mLastWidgetPressed; - } - - void FocusHandler::setLastWidgetPressed(Widget* lastWidgetPressed) - { - mLastWidgetPressed = lastWidgetPressed; - } -} diff --git a/src/guichan/font.cpp b/src/guichan/font.cpp deleted file mode 100644 index 83b3727e3..000000000 --- a/src/guichan/font.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/font.hpp" - -#include <string> - -#include "debug.h" - -namespace gcn -{ - int Font::getStringIndexAt(const std::string& text, int x) const - { - unsigned int i; - int size = 0; - - for (i = 0; i < text.size(); ++i) - { - size = getWidth(text.substr(0, i)); - - if (size > x) - return i; - } - - return text.size(); - } -} diff --git a/src/guichan/graphics.cpp b/src/guichan/graphics.cpp deleted file mode 100644 index d09050a10..000000000 --- a/src/guichan/graphics.cpp +++ /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. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/graphics.hpp" - -#include "guichan/exception.hpp" -#include "guichan/font.hpp" -#include "guichan/image.hpp" - -#include "debug.h" - -namespace gcn -{ - - Graphics::Graphics() : - mFont(NULL) - { - } - - bool Graphics::pushClipArea(Rectangle area) - { - // Ignore area with a negate width or height - // by simple pushing an empty clip area - // to the stack. - if (area.width < 0 || area.height < 0) - { - ClipRectangle carea; - mClipStack.push(carea); - return true; - } - - if (mClipStack.empty()) - { - ClipRectangle carea; - carea.x = area.x; - carea.y = area.y; - carea.width = area.width; - carea.height = area.height; - carea.xOffset = area.x; - carea.yOffset = area.y; - mClipStack.push(carea); - return true; - } - - const ClipRectangle &top = mClipStack.top(); - ClipRectangle carea; - carea = area; - carea.xOffset = top.xOffset + carea.x; - carea.yOffset = top.yOffset + carea.y; - carea.x += top.xOffset; - carea.y += top.yOffset; - - // Clamp the pushed clip rectangle. - if (carea.x < top.x) - carea.x = top.x; - - if (carea.y < top.y) - carea.y = top.y; - - if (carea.x + carea.width > top.x + top.width) - { - carea.width = top.x + top.width - carea.x; - - if (carea.width < 0) - carea.width = 0; - } - - if (carea.y + carea.height > top.y + top.height) - { - carea.height = top.y + top.height - carea.y; - - if (carea.height < 0) - carea.height = 0; - } - - bool result = carea.isIntersecting(top); - - mClipStack.push(carea); - - return result; - } - - void Graphics::popClipArea() - { - - if (mClipStack.empty()) - throw GCN_EXCEPTION("Tried to pop clip area from empty stack."); - - mClipStack.pop(); - } - - const ClipRectangle& Graphics::getCurrentClipArea() - { - if (mClipStack.empty()) - throw GCN_EXCEPTION("The clip area stack is empty."); - - return mClipStack.top(); - } - - void Graphics::drawImage(const Image* image, int dstX, int dstY) - { - drawImage(image, 0, 0, dstX, dstY, - image->getWidth(), image->getHeight()); - } - - void Graphics::setFont(Font* font) - { - mFont = font; - } - - void Graphics::drawText(const std::string& text, int x, int y, - Alignment alignment) - { - if (mFont == NULL) - throw GCN_EXCEPTION("No font set."); - - switch (alignment) - { - case LEFT: - mFont->drawString(this, text, x, y); - break; - case CENTER: - mFont->drawString(this, text, x - - mFont->getWidth(text) / 2, y); - break; - case RIGHT: - mFont->drawString(this, text, x - mFont->getWidth(text), y); - break; - default: - throw GCN_EXCEPTION("Unknown alignment."); - } - } -} diff --git a/src/guichan/gui.cpp b/src/guichan/gui.cpp deleted file mode 100644 index bec4c875f..000000000 --- a/src/guichan/gui.cpp +++ /dev/null @@ -1,970 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/gui.hpp" - -#include "guichan/basiccontainer.hpp" -#include "guichan/exception.hpp" -#include "guichan/focushandler.hpp" -#include "guichan/graphics.hpp" -#include "guichan/input.hpp" -#include "guichan/keyinput.hpp" -#include "guichan/keylistener.hpp" -#include "guichan/mouseinput.hpp" -#include "guichan/mouselistener.hpp" -#include "guichan/widget.hpp" - -#include "debug.h" - -namespace gcn -{ - Gui::Gui() : - mTop(NULL), - mGraphics(NULL), - mInput(NULL), - mTabbing(true), - mShiftPressed(false), - mMetaPressed(false), - mControlPressed(false), - mAltPressed(false), - mLastMousePressButton(0), - mLastMousePressTimeStamp(0), - mLastMouseX(0), - mLastMouseY(0), - mClickCount(1), - mLastMouseDragButton(0) - { - mFocusHandler = new FocusHandler(); - } - - Gui::~Gui() - { - if (Widget::widgetExists(mTop)) - setTop(NULL); - - delete mFocusHandler; - mFocusHandler = 0; - } - - void Gui::setTop(Widget* top) - { - if (mTop != NULL) - mTop->_setFocusHandler(NULL); - if (top != NULL) - top->_setFocusHandler(mFocusHandler); - - mTop = top; - } - - Widget* Gui::getTop() const - { - return mTop; - } - - void Gui::setGraphics(Graphics* graphics) - { - mGraphics = graphics; - } - - Graphics* Gui::getGraphics() const - { - return mGraphics; - } - - void Gui::setInput(Input* input) - { - mInput = input; - } - - Input* Gui::getInput() const - { - return mInput; - } - - void Gui::logic() - { - if (mTop == NULL) - throw GCN_EXCEPTION("No top widget set"); - - handleModalFocus(); - handleModalMouseInputFocus(); - - if (mInput != NULL) - { - mInput->_pollInput(); - - handleKeyInput(); - handleMouseInput(); - - } // end if - - mTop->logic(); - } - - void Gui::draw() - { - if (mTop == NULL) - throw GCN_EXCEPTION("No top widget set"); - if (mGraphics == NULL) - throw GCN_EXCEPTION("No graphics set"); - - if (!mTop->isVisible()) - return; - - mGraphics->_beginDraw(); - - // If top has a frame, - // draw it before drawing top - if (mTop->getFrameSize() > 0) - { - Rectangle rec = mTop->getDimension(); - rec.x -= mTop->getFrameSize(); - rec.y -= mTop->getFrameSize(); - rec.width += 2 * mTop->getFrameSize(); - rec.height += 2 * mTop->getFrameSize(); - mGraphics->pushClipArea(rec); - mTop->drawFrame(mGraphics); - mGraphics->popClipArea(); - } - - mGraphics->pushClipArea(mTop->getDimension()); - mTop->draw(mGraphics); - mGraphics->popClipArea(); - - mGraphics->_endDraw(); - } - - void Gui::focusNone() - { - mFocusHandler->focusNone(); - } - - void Gui::setTabbingEnabled(bool tabbing) - { - mTabbing = tabbing; - } - - bool Gui::isTabbingEnabled() - { - return mTabbing; - } - - void Gui::addGlobalKeyListener(KeyListener* keyListener) - { - mKeyListeners.push_back(keyListener); - } - - void Gui::removeGlobalKeyListener(KeyListener* keyListener) - { - mKeyListeners.remove(keyListener); - } - - void Gui::handleMouseInput() - { - while (!mInput->isMouseQueueEmpty()) - { - MouseInput mouseInput = mInput->dequeueMouseInput(); - - // Save the current mouse state. It will be needed if modal focus - // changes or modal mouse input focus changes. - mLastMouseX = mouseInput.getX(); - mLastMouseY = mouseInput.getY(); - - switch (mouseInput.getType()) - { - case MouseInput::PRESSED: - handleMousePressed(mouseInput); - break; - case MouseInput::RELEASED: - handleMouseReleased(mouseInput); - break; - case MouseInput::MOVED: - handleMouseMoved(mouseInput); - break; - case MouseInput::WHEEL_MOVED_DOWN: - handleMouseWheelMovedDown(mouseInput); - break; - case MouseInput::WHEEL_MOVED_UP: - handleMouseWheelMovedUp(mouseInput); - break; - default: - throw GCN_EXCEPTION("Unknown mouse input type."); - break; - } - } - } - - void Gui::handleKeyInput() - { - while (!mInput->isKeyQueueEmpty()) - { - KeyInput keyInput = mInput->dequeueKeyInput(); - - // Save modifiers state - mShiftPressed = keyInput.isShiftPressed(); - mMetaPressed = keyInput.isMetaPressed(); - mControlPressed = keyInput.isControlPressed(); - mAltPressed = keyInput.isAltPressed(); - - KeyEvent keyEventToGlobalKeyListeners(NULL, - mShiftPressed, - mControlPressed, - mAltPressed, - mMetaPressed, - keyInput.getType(), - keyInput.isNumericPad(), - keyInput.getKey()); - - distributeKeyEventToGlobalKeyListeners( - keyEventToGlobalKeyListeners); - - // If a global key listener consumes the event it will not be - // sent further to the source of the event. - if (keyEventToGlobalKeyListeners.isConsumed()) - continue; - - bool keyEventConsumed = false; - - // Send key inputs to the focused widgets - if (mFocusHandler->getFocused() != NULL) - { - KeyEvent keyEvent(getKeyEventSource(), - mShiftPressed, - mControlPressed, - mAltPressed, - mMetaPressed, - keyInput.getType(), - keyInput.isNumericPad(), - keyInput.getKey()); - - if (!mFocusHandler->getFocused()->isFocusable()) - mFocusHandler->focusNone(); - else - distributeKeyEvent(keyEvent); - - keyEventConsumed = keyEvent.isConsumed(); - } - - // If the key event hasn't been consumed and - // tabbing is enable check for tab press and - // change focus. - if (!keyEventConsumed && mTabbing - && keyInput.getKey().getValue() == Key::TAB - && keyInput.getType() == KeyInput::PRESSED) - { - if (keyInput.isShiftPressed()) - mFocusHandler->tabPrevious(); - else - mFocusHandler->tabNext(); - } - } // end while - } - - void Gui::handleMouseMoved(const MouseInput& mouseInput) - { - // Check if the mouse leaves the application window. - if (!mWidgetWithMouseQueue.empty() && (mouseInput.getX() < 0 - || mouseInput.getY() < 0 || !mTop->getDimension().isPointInRect( - mouseInput.getX(), mouseInput.getY()))) - { - // Distribute an event to all widgets in the - // "widget with mouse" queue. - while (!mWidgetWithMouseQueue.empty()) - { - Widget* widget = mWidgetWithMouseQueue.front(); - - if (Widget::widgetExists(widget)) - { - distributeMouseEvent(widget, - MouseEvent::EXITED, - mouseInput.getButton(), - mouseInput.getX(), - mouseInput.getY(), - true, - true); - } - - mWidgetWithMouseQueue.pop_front(); - } - - return; - } - - // Check if there is a need to send mouse exited events by - // traversing the "widget with mouse" queue. - bool widgetWithMouseQueueCheckDone = mWidgetWithMouseQueue.empty(); - while (!widgetWithMouseQueueCheckDone) - { - unsigned int iterations = 0; - std::deque<Widget*>::iterator iter; - for (iter = mWidgetWithMouseQueue.begin(); - iter != mWidgetWithMouseQueue.end(); - ++ iter) - { - Widget* widget = *iter; - - // If a widget in the "widget with mouse queue" doesn't - // exists anymore it should be removed from the queue. - if (!Widget::widgetExists(widget)) - { - mWidgetWithMouseQueue.erase(iter); - break; - } - else - { - int x, y; - widget->getAbsolutePosition(x, y); - - if (x > mouseInput.getX() - || y > mouseInput.getY() - || x + widget->getWidth() <= mouseInput.getX() - || y + widget->getHeight() <= mouseInput.getY() - || !widget->isVisible()) - { - distributeMouseEvent(widget, - MouseEvent::EXITED, - mouseInput.getButton(), - mouseInput.getX(), - mouseInput.getY(), - true, - true); - mClickCount = 1; - mLastMousePressTimeStamp = 0; - mWidgetWithMouseQueue.erase(iter); - break; - } - } - - iterations++; - } - - widgetWithMouseQueueCheckDone = - (iterations == mWidgetWithMouseQueue.size()); - } - - // Check all widgets below the mouse to see if they are - // present in the "widget with mouse" queue. If a widget - // is not then it should be added and an entered event should - // be sent to it. - Widget* parent = getMouseEventSource( - mouseInput.getX(), mouseInput.getY()); - Widget* widget = parent; - - // If a widget has modal mouse input focus then it will - // always be returned from getMouseEventSource, but we only wan't to - // send mouse entered events if the mouse has actually entered the - // widget with modal mouse input focus, hence we need to check if - // that's the case. If it's not we should simply ignore to send any - // mouse entered events. - if (mFocusHandler->getModalMouseInputFocused() != NULL - && widget == mFocusHandler->getModalMouseInputFocused() - && Widget::widgetExists(widget)) - { - int x, y; - widget->getAbsolutePosition(x, y); - - if (x > mouseInput.getX() || y > mouseInput.getY() - || x + widget->getWidth() <= mouseInput.getX() - || y + widget->getHeight() <= mouseInput.getY()) - { - parent = NULL; - } - } - - while (parent != NULL) - { - parent = (Widget*)widget->getParent(); - - // Check if the widget is present in the "widget with mouse" queue. - bool widgetIsPresentInQueue = false; - std::deque<Widget*>::iterator iter; - for (iter = mWidgetWithMouseQueue.begin(); - iter != mWidgetWithMouseQueue.end(); - ++ iter) - { - if (*iter == widget) - { - widgetIsPresentInQueue = true; - break; - } - } - - // Widget is not present, send an entered event and add - // it to the "widget with mouse" queue. - if (!widgetIsPresentInQueue - && Widget::widgetExists(widget)) - { - distributeMouseEvent(widget, - MouseEvent::ENTERED, - mouseInput.getButton(), - mouseInput.getX(), - mouseInput.getY(), - true, - true); - mWidgetWithMouseQueue.push_front(widget); - } - - Widget* swap = widget; - widget = parent; - parent = (Widget*)swap->getParent(); - } - - if (mFocusHandler->getDraggedWidget() != NULL) - { - distributeMouseEvent(mFocusHandler->getDraggedWidget(), - MouseEvent::DRAGGED, - mLastMouseDragButton, - mouseInput.getX(), - mouseInput.getY()); - } - else - { - Widget* sourceWidget = getMouseEventSource( - mouseInput.getX(), mouseInput.getY()); - - distributeMouseEvent(sourceWidget, - MouseEvent::MOVED, - mouseInput.getButton(), - mouseInput.getX(), - mouseInput.getY()); - } - } - - void Gui::handleMousePressed(const MouseInput& mouseInput) - { - Widget* sourceWidget = getMouseEventSource( - mouseInput.getX(), mouseInput.getY()); - - if (mFocusHandler->getDraggedWidget() != NULL) - sourceWidget = mFocusHandler->getDraggedWidget(); - - int sourceWidgetX, sourceWidgetY; - sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); - - if ((mFocusHandler->getModalFocused() != NULL - && sourceWidget->isModalFocused()) - || mFocusHandler->getModalFocused() == NULL) - { - sourceWidget->requestFocus(); - } - - if (mouseInput.getTimeStamp() - mLastMousePressTimeStamp < 250 - && mLastMousePressButton == mouseInput.getButton()) - { - mClickCount++; - } - else - { - mClickCount = 1; - } - - distributeMouseEvent(sourceWidget, - MouseEvent::PRESSED, - mouseInput.getButton(), - mouseInput.getX(), - mouseInput.getY()); - - mFocusHandler->setLastWidgetPressed(sourceWidget); - - mFocusHandler->setDraggedWidget(sourceWidget); - mLastMouseDragButton = mouseInput.getButton(); - - mLastMousePressButton = mouseInput.getButton(); - mLastMousePressTimeStamp = mouseInput.getTimeStamp(); - } - - void Gui::handleMouseWheelMovedDown(const MouseInput& mouseInput) - { - Widget* sourceWidget = getMouseEventSource( - mouseInput.getX(), mouseInput.getY()); - - if (mFocusHandler->getDraggedWidget() != NULL) - sourceWidget = mFocusHandler->getDraggedWidget(); - - int sourceWidgetX, sourceWidgetY; - sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); - - distributeMouseEvent(sourceWidget, - MouseEvent::WHEEL_MOVED_DOWN, - mouseInput.getButton(), - mouseInput.getX(), - mouseInput.getY()); - } - - void Gui::handleMouseWheelMovedUp(const MouseInput& mouseInput) - { - Widget* sourceWidget = getMouseEventSource( - mouseInput.getX(), mouseInput.getY()); - - if (mFocusHandler->getDraggedWidget() != NULL) - sourceWidget = mFocusHandler->getDraggedWidget(); - - int sourceWidgetX, sourceWidgetY; - sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); - - distributeMouseEvent(sourceWidget, - MouseEvent::WHEEL_MOVED_UP, - mouseInput.getButton(), - mouseInput.getX(), - mouseInput.getY()); - } - - void Gui::handleMouseReleased(const MouseInput& mouseInput) - { - Widget* sourceWidget = getMouseEventSource( - mouseInput.getX(), mouseInput.getY()); - - if (mFocusHandler->getDraggedWidget() != NULL) - { - if (sourceWidget != mFocusHandler->getLastWidgetPressed()) - mFocusHandler->setLastWidgetPressed(NULL); - - sourceWidget = mFocusHandler->getDraggedWidget(); - } - - int sourceWidgetX, sourceWidgetY; - sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); - - distributeMouseEvent(sourceWidget, - MouseEvent::RELEASED, - mouseInput.getButton(), - mouseInput.getX(), - mouseInput.getY()); - - if (mouseInput.getButton() == mLastMousePressButton - && mFocusHandler->getLastWidgetPressed() == sourceWidget) - { - distributeMouseEvent(sourceWidget, - MouseEvent::CLICKED, - mouseInput.getButton(), - mouseInput.getX(), - mouseInput.getY()); - - mFocusHandler->setLastWidgetPressed(NULL); - } - else - { - mLastMousePressButton = 0; - mClickCount = 0; - } - - if (mFocusHandler->getDraggedWidget() != NULL) - mFocusHandler->setDraggedWidget(NULL); - } - - Widget* Gui::getWidgetAt(int x, int y) - { - // If the widget's parent has no child then we have found the widget.. - Widget* parent = mTop; - Widget* child = mTop; - - while (child != NULL) - { - Widget* swap = child; - int parentX, parentY; - parent->getAbsolutePosition(parentX, parentY); - child = parent->getWidgetAt(x - parentX, y - parentY); - parent = swap; - } - - return parent; - } - - Widget* Gui::getMouseEventSource(int x, int y) - { - Widget* widget = getWidgetAt(x, y); - - if (mFocusHandler->getModalMouseInputFocused() != NULL - && !widget->isModalMouseInputFocused()) - { - return mFocusHandler->getModalMouseInputFocused(); - } - - return widget; - } - - Widget* Gui::getKeyEventSource() - { - Widget* widget = mFocusHandler->getFocused(); - - while (widget->_getInternalFocusHandler() != NULL - && widget->_getInternalFocusHandler()->getFocused() != NULL) - { - widget = widget->_getInternalFocusHandler()->getFocused(); - } - - return widget; - } - - void Gui::distributeMouseEvent(Widget* source, - int type, - int button, - int x, - int y, - bool force, - bool toSourceOnly) - { - Widget* parent = source; - Widget* widget = source; - - if (mFocusHandler->getModalFocused() != NULL - && !widget->isModalFocused() - && !force) - { - return; - } - - if (mFocusHandler->getModalMouseInputFocused() != NULL - && !widget->isModalMouseInputFocused() - && !force) - { - return; - } - - MouseEvent mouseEvent(source, - mShiftPressed, - mControlPressed, - mAltPressed, - mMetaPressed, - type, - button, - x, - y, - mClickCount); - - while (parent != NULL) - { - // If the widget has been removed due to input - // cancel the distribution. - if (!Widget::widgetExists(widget)) - break; - - parent = (Widget*)widget->getParent(); - - if (widget->isEnabled() || force) - { - int widgetX, widgetY; - widget->getAbsolutePosition(widgetX, widgetY); - - mouseEvent.mX = x - widgetX; - mouseEvent.mY = y - widgetY; - - std::list<MouseListener*> mouseListeners - = widget->_getMouseListeners(); - - // Send the event to all mouse listeners of the widget. - for (std::list<MouseListener*>::iterator - it = mouseListeners.begin(); - it != mouseListeners.end(); - ++it) - { - switch (mouseEvent.getType()) - { - case MouseEvent::ENTERED: - (*it)->mouseEntered(mouseEvent); - break; - case MouseEvent::EXITED: - (*it)->mouseExited(mouseEvent); - break; - case MouseEvent::MOVED: - (*it)->mouseMoved(mouseEvent); - break; - case MouseEvent::PRESSED: - (*it)->mousePressed(mouseEvent); - break; - case MouseEvent::RELEASED: - (*it)->mouseReleased(mouseEvent); - break; - case MouseEvent::WHEEL_MOVED_UP: - (*it)->mouseWheelMovedUp(mouseEvent); - break; - case MouseEvent::WHEEL_MOVED_DOWN: - (*it)->mouseWheelMovedDown(mouseEvent); - break; - case MouseEvent::DRAGGED: - (*it)->mouseDragged(mouseEvent); - break; - case MouseEvent::CLICKED: - (*it)->mouseClicked(mouseEvent); - break; - default: - throw GCN_EXCEPTION("Unknown mouse event type."); - } - } - - if (toSourceOnly) - break; - } - - Widget* swap = widget; - widget = parent; - parent = (Widget*)swap->getParent(); - - // If a non modal focused widget has been reach - // and we have modal focus cancel the distribution. - if (mFocusHandler->getModalFocused() != NULL - && !widget->isModalFocused()) - { - break; - } - - // If a non modal mouse input focused widget has been reach - // and we have modal mouse input focus cancel the distribution. - if (mFocusHandler->getModalMouseInputFocused() != NULL - && !widget->isModalMouseInputFocused()) - { - break; - } - } - } - - void Gui::distributeKeyEvent(KeyEvent& keyEvent) - { - Widget* parent = keyEvent.getSource(); - Widget* widget = keyEvent.getSource(); - - if (mFocusHandler->getModalFocused() != NULL - && !widget->isModalFocused()) - { - return; - } - - if (mFocusHandler->getModalMouseInputFocused() != NULL - && !widget->isModalMouseInputFocused()) - { - return; - } - - while (parent != NULL) - { - // If the widget has been removed due to input - // cancel the distribution. - if (!Widget::widgetExists(widget)) - { - break; - } - - parent = (Widget*)widget->getParent(); - - if (widget->isEnabled()) - { - std::list<KeyListener*> keyListeners - = widget->_getKeyListeners(); - - // Send the event to all key listeners of the source widget. - for (std::list<KeyListener*>::iterator - it = keyListeners.begin(); - it != keyListeners.end(); - ++it) - { - switch (keyEvent.getType()) - { - case KeyEvent::PRESSED: - (*it)->keyPressed(keyEvent); - break; - case KeyEvent::RELEASED: - (*it)->keyReleased(keyEvent); - break; - default: - throw GCN_EXCEPTION("Unknown key event type."); - } - } - } - - Widget* swap = widget; - widget = parent; - parent = (Widget*)swap->getParent(); - - // If a non modal focused widget has been reach - // and we have modal focus cancel the distribution. - if (mFocusHandler->getModalFocused() != NULL - && !widget->isModalFocused()) - { - break; - } - } - } - - void Gui::distributeKeyEventToGlobalKeyListeners(KeyEvent& keyEvent) - { - KeyListenerListIterator it; - - for (it = mKeyListeners.begin(); it != mKeyListeners.end(); ++ it) - { - switch (keyEvent.getType()) - { - case KeyEvent::PRESSED: - (*it)->keyPressed(keyEvent); - break; - case KeyEvent::RELEASED: - (*it)->keyReleased(keyEvent); - break; - default: - throw GCN_EXCEPTION("Unknown key event type."); - } - - if (keyEvent.isConsumed()) - break; - } - } - - void Gui::handleModalMouseInputFocus() - { - // Check if modal mouse input focus has been gained by a widget. - if ((mFocusHandler->getLastWidgetWithModalMouseInputFocus() - != mFocusHandler->getModalMouseInputFocused()) - && (mFocusHandler->getLastWidgetWithModalMouseInputFocus() - == NULL)) - { - handleModalFocusGained(); - mFocusHandler->setLastWidgetWithModalMouseInputFocus( - mFocusHandler->getModalMouseInputFocused()); - } - // Check if modal mouse input focus has been released. - else if ((mFocusHandler->getLastWidgetWithModalMouseInputFocus() - != mFocusHandler->getModalMouseInputFocused()) - && (mFocusHandler->getLastWidgetWithModalMouseInputFocus() - != NULL)) - { - handleModalFocusReleased(); - mFocusHandler->setLastWidgetWithModalMouseInputFocus(NULL); - } - } - - void Gui::handleModalFocus() - { - // Check if modal focus has been gained by a widget. - if ((mFocusHandler->getLastWidgetWithModalFocus() - != mFocusHandler->getModalFocused()) - && (mFocusHandler->getLastWidgetWithModalFocus() == NULL)) - { - handleModalFocusGained(); - mFocusHandler->setLastWidgetWithModalFocus( - mFocusHandler->getModalFocused()); - } - // Check if modal focus has been released. - else if ((mFocusHandler->getLastWidgetWithModalFocus() - != mFocusHandler->getModalFocused()) - && (mFocusHandler->getLastWidgetWithModalFocus() != NULL)) - { - handleModalFocusReleased(); - mFocusHandler->setLastWidgetWithModalFocus(NULL); - } - } - - void Gui::handleModalFocusGained() - { - // Distribute an event to all widgets in the "widget with mouse" queue. - while (!mWidgetWithMouseQueue.empty()) - { - Widget* widget = mWidgetWithMouseQueue.front(); - - if (Widget::widgetExists(widget)) - { - distributeMouseEvent(widget, - MouseEvent::EXITED, - mLastMousePressButton, - mLastMouseX, - mLastMouseY, - true, - true); - } - - mWidgetWithMouseQueue.pop_front(); - } - - mFocusHandler->setLastWidgetWithModalMouseInputFocus( - mFocusHandler->getModalMouseInputFocused()); - } - - void Gui::handleModalFocusReleased() - { - // Check all widgets below the mouse to see if they are - // present in the "widget with mouse" queue. If a widget - // is not then it should be added and an entered event should - // be sent to it. - Widget* widget = getMouseEventSource(mLastMouseX, mLastMouseY); - Widget* parent = widget; - - while (parent != NULL) - { - parent = (Widget*)widget->getParent(); - - // Check if the widget is present in the "widget with mouse" queue. - bool widgetIsPresentInQueue = false; - std::deque<Widget*>::iterator iter; - for (iter = mWidgetWithMouseQueue.begin(); - iter != mWidgetWithMouseQueue.end(); - ++ iter) - { - if (*iter == widget) - { - widgetIsPresentInQueue = true; - break; - } - } - - // Widget is not present, send an entered event and add - // it to the "widget with mouse" queue. - if (!widgetIsPresentInQueue && Widget::widgetExists(widget)) - { - distributeMouseEvent(widget, - MouseEvent::ENTERED, - mLastMousePressButton, - mLastMouseX, - mLastMouseY, - false, - true); - mWidgetWithMouseQueue.push_front(widget); - } - - Widget* swap = widget; - widget = parent; - parent = (Widget*)swap->getParent(); - } - } -} diff --git a/src/guichan/image.cpp b/src/guichan/image.cpp deleted file mode 100644 index 2c15151a2..000000000 --- a/src/guichan/image.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/image.hpp" - -#include "guichan/exception.hpp" -#include "guichan/imageloader.hpp" - -#include "debug.h" - -namespace gcn -{ - - ImageLoader* Image::mImageLoader = NULL; - - Image::Image() - { - } - - Image::~Image() - { - } - - void Image::setImageLoader(ImageLoader* imageLoader) - { - mImageLoader = imageLoader; - } - - ImageLoader* Image::getImageLoader() - { - return mImageLoader; - } - - Image* Image::load(const std::string& filename, - bool convertToDisplayFormat) - { - if (mImageLoader == NULL) - { - throw GCN_EXCEPTION("Trying to load an image but " - "no image loader is set."); - } - - return mImageLoader->load(filename, convertToDisplayFormat); - } -} diff --git a/src/guichan/include/guichan/actionevent.hpp b/src/guichan/include/guichan/actionevent.hpp deleted file mode 100644 index c897e9b4b..000000000 --- a/src/guichan/include/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 <string> - -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 deleted file mode 100644 index 0f750099c..000000000 --- a/src/guichan/include/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 <string> - -#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 deleted file mode 100644 index 998e1f601..000000000 --- a/src/guichan/include/guichan/basiccontainer.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_BASICCONTAINER_HPP -#define GCN_BASICCONTAINER_HPP - -#include <list> -#include <vector> - -#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::vector<Widget *> 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 deleted file mode 100644 index 792c40bb9..000000000 --- a/src/guichan/include/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/include/guichan/color.hpp b/src/guichan/include/guichan/color.hpp deleted file mode 100644 index b7e324c07..000000000 --- a/src/guichan/include/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 <iostream> - -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/deathlistener.hpp b/src/guichan/include/guichan/deathlistener.hpp deleted file mode 100644 index a8e14a7f8..000000000 --- a/src/guichan/include/guichan/deathlistener.hpp +++ /dev/null @@ -1,90 +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_DEATHLISTENER_HPP -#define GCN_DEATHLISTENER_HPP - -#include <string> - -#include "guichan/event.hpp" -#include "guichan/platform.hpp" - -namespace gcn -{ - /** - * Interface for listening for death events from widgets. - * - * @see Widget::addDeathListener, Widget::removeDeathListener - * @author Olof Naessén - * @since 0.6.0 - */ - class GCN_CORE_DECLSPEC DeathListener - { - public: - - /** - * Destructor. - */ - virtual ~DeathListener() { } - - /** - * Called when a widget dies. It is used to be able to recieve - * a notification when a death of a widget occurs. - * - * @param event The event of the death. - */ - virtual void death(const Event& event) = 0; - - protected: - /** - * Constructor. - * - * You should not be able to make an instance of DeathListener, - * therefore its constructor is protected. - */ - DeathListener() { } - - }; -} - -#endif // end GCN_DEATHLISTENER_HPP diff --git a/src/guichan/include/guichan/defaultfont.hpp b/src/guichan/include/guichan/defaultfont.hpp deleted file mode 100644 index 3f6379cbe..000000000 --- a/src/guichan/include/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 A_UNUSED __attribute__ ((unused)) -#else -#define A_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 deleted file mode 100644 index 107e34fc2..000000000 --- a/src/guichan/include/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/include/guichan/exception.hpp b/src/guichan/include/guichan/exception.hpp deleted file mode 100644 index 3ccf39e20..000000000 --- a/src/guichan/include/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 <string> - -#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 deleted file mode 100644 index f5ac8f044..000000000 --- a/src/guichan/include/guichan/focushandler.hpp +++ /dev/null @@ -1,396 +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 <vector> - -#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<Widget*> 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 deleted file mode 100644 index 548d05f4d..000000000 --- a/src/guichan/include/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 <string> - -#include "guichan/event.hpp" -#include "guichan/platform.hpp" - -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_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 A_UNUSED) { }; - - /** - * Called when a widget loses focus. - * - * @param event Discribes the event. - */ - virtual void focusLost(const Event& event A_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 deleted file mode 100644 index cda4028b8..000000000 --- a/src/guichan/include/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 <string> -#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 deleted file mode 100644 index d21eab24b..000000000 --- a/src/guichan/include/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 <iosfwd> -#include <stack> - -#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<ClipRectangle> 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 deleted file mode 100644 index 17d49c979..000000000 --- a/src/guichan/include/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 <list> -#include <deque> - -#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<KeyListener*> 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<Widget*> 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 deleted file mode 100644 index e3bd27f69..000000000 --- a/src/guichan/include/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 <string> - -#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 deleted file mode 100644 index 7c0adb842..000000000 --- a/src/guichan/include/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 <string> - -#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 deleted file mode 100644 index 7510d3cb2..000000000 --- a/src/guichan/include/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/include/guichan/inputevent.hpp b/src/guichan/include/guichan/inputevent.hpp deleted file mode 100644 index 8594d3dae..000000000 --- a/src/guichan/include/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/include/guichan/key.hpp b/src/guichan/include/guichan/key.hpp deleted file mode 100644 index 0b550dcca..000000000 --- a/src/guichan/include/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/include/guichan/keyevent.hpp b/src/guichan/include/guichan/keyevent.hpp deleted file mode 100644 index f42601235..000000000 --- a/src/guichan/include/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/include/guichan/keyinput.hpp b/src/guichan/include/guichan/keyinput.hpp deleted file mode 100644 index 68c58fa0d..000000000 --- a/src/guichan/include/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/include/guichan/keylistener.hpp b/src/guichan/include/guichan/keylistener.hpp deleted file mode 100644 index 5449f2de4..000000000 --- a/src/guichan/include/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 A_UNUSED __attribute__ ((unused)) -#else -#define A_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 A_UNUSED) { } - - /** - * Called if a key is released when the widget has keyboard focus. - * - * @param keyEvent Discribes the event. - */ - virtual void keyReleased(KeyEvent& keyEvent A_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 deleted file mode 100644 index 1beae317b..000000000 --- a/src/guichan/include/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 <string> - -#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 deleted file mode 100644 index 280d373e6..000000000 --- a/src/guichan/include/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/include/guichan/mouseinput.hpp b/src/guichan/include/guichan/mouseinput.hpp deleted file mode 100644 index 3825d5439..000000000 --- a/src/guichan/include/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/include/guichan/mouselistener.hpp b/src/guichan/include/guichan/mouselistener.hpp deleted file mode 100644 index 1612cc822..000000000 --- a/src/guichan/include/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 A_UNUSED __attribute__ ((unused)) -#else -#define A_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 A_UNUSED) - { - - } - - /** - * Called when the mouse has exited the widget area. - * - * @param mouseEvent Describes the event. - * @since 0.6.0 - */ - virtual void mouseExited(MouseEvent& mouseEvent A_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 A_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 A_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 A_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 A_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 A_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 A_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 A_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 deleted file mode 100644 index e2ea89767..000000000 --- a/src/guichan/include/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/include/guichan/rectangle.hpp b/src/guichan/include/guichan/rectangle.hpp deleted file mode 100644 index 1d21654df..000000000 --- a/src/guichan/include/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 <iostream> - -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 deleted file mode 100644 index 70a234d33..000000000 --- a/src/guichan/include/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/include/guichan/sdl/sdlimage.hpp b/src/guichan/include/guichan/sdl/sdlimage.hpp deleted file mode 100644 index 4d226177e..000000000 --- a/src/guichan/include/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 <string> - -#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 deleted file mode 100644 index 675b10fcd..000000000 --- a/src/guichan/include/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/include/guichan/selectionevent.hpp b/src/guichan/include/guichan/selectionevent.hpp deleted file mode 100644 index 6724fa0d2..000000000 --- a/src/guichan/include/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/include/guichan/selectionlistener.hpp b/src/guichan/include/guichan/selectionlistener.hpp deleted file mode 100644 index 8ea8a579b..000000000 --- a/src/guichan/include/guichan/selectionlistener.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_SELECTIONLISTENER_HPP -#define GCN_SELECTIONLISTENER_HPP - -#include <string> - -#include "guichan/selectionevent.hpp" -#include "guichan/platform.hpp" - -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - -namespace gcn -{ - /** - * Interface for listening for selection events from widgets. - * - * @see ListBox::addSelectionListener, - * ListBox::removeSelectionListener, - * DropDown::addSelectionListener, - * DropDown::removeSelectionListener - * @author Olof Naessén - * @since 0.8.0 - */ - class GCN_CORE_DECLSPEC SelectionListener - { - public: - - /** - * Destructor. - */ - virtual ~SelectionListener() - { } - - /** - * Called when the value of a selection has been changed in a Widget. - * It is used to be able to recieve a notification that a value has - * been changed. - * - * @param event The event of the value change. - * @since 0.8.0 - */ - virtual void valueChanged(const SelectionEvent& event A_UNUSED) - { }; - - protected: - /** - * Constructor. - * - * You should not be able to make an instance of SelectionListener, - * therefore its constructor is protected. - */ - SelectionListener() - { } - }; -} - -#endif // end GCN_SELECTIONLISTENER_HPP diff --git a/src/guichan/include/guichan/widget.hpp b/src/guichan/include/guichan/widget.hpp deleted file mode 100644 index d112022e3..000000000 --- a/src/guichan/include/guichan/widget.hpp +++ /dev/null @@ -1,1205 +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 <list> -#include <set> -#include <string> - -#include "guichan/color.hpp" -#include "guichan/rectangle.hpp" - -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_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<MouseListener*>& _getMouseListeners(); - - /** - * Gets the key listeners of the widget. - * - * @return The key listeners of the widget. - * @since 0.6.0 - */ - virtual const std::list<KeyListener*>& _getKeyListeners(); - - /** - * Gets the focus listeners of the widget. - * - * @return The focus listeners of the widget. - * @since 0.7.0 - */ - virtual const std::list<FocusListener*>& _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 A_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 A_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 A_UNUSED, - Rectangle area A_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<MouseListener*> MouseListenerList; - - /** - * Typdef. - */ - typedef MouseListenerList::iterator MouseListenerIterator; - - /** - * Holds the mouse listeners of the widget. - */ - MouseListenerList mMouseListeners; - - /** - * Typdef. - */ - typedef std::list<KeyListener*> KeyListenerList; - - /** - * Holds the key listeners of the widget. - */ - KeyListenerList mKeyListeners; - - /** - * Typdef. - */ - typedef KeyListenerList::iterator KeyListenerIterator; - - /** - * Typdef. - */ - typedef std::list<ActionListener*> ActionListenerList; - - /** - * Holds the action listeners of the widget. - */ - ActionListenerList mActionListeners; - - /** - * Typdef. - */ - typedef ActionListenerList::iterator ActionListenerIterator; - - /** - * Typdef. - */ - typedef std::list<DeathListener*> DeathListenerList; - - /** - * Holds the death listeners of the widget. - */ - DeathListenerList mDeathListeners; - - /** - * Typdef. - */ - typedef DeathListenerList::iterator DeathListenerIterator; - - /** - * Typdef. - */ - typedef std::list<FocusListener*> FocusListenerList; - - /** - * Holds the focus listeners of the widget. - */ - FocusListenerList mFocusListeners; - - /** - * Typdef. - */ - typedef FocusListenerList::iterator FocusListenerIterator; - - typedef std::list<WidgetListener*> 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<Widget*> mWidgets; - - static std::set<Widget*> mWidgetsSet; - }; -} - -#endif // end GCN_WIDGET_HPP diff --git a/src/guichan/include/guichan/widgetlistener.hpp b/src/guichan/include/guichan/widgetlistener.hpp deleted file mode 100644 index 159549ede..000000000 --- a/src/guichan/include/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 <string> - -#include "guichan/event.hpp" -#include "guichan/platform.hpp" - -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_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 A_UNUSED) { } - - /** - * Invoked when a widget is moved. - * - * @param event Describes the event. - * @since 0.8.0 - */ - virtual void widgetMoved(const Event& event A_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 A_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 A_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 deleted file mode 100644 index c0d0a237d..000000000 --- a/src/guichan/include/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 <string> - -#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 A_UNUSED __attribute__ ((unused)) -#else -#define A_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 deleted file mode 100644 index ad43e2896..000000000 --- a/src/guichan/include/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 <string> - -#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 deleted file mode 100644 index 4946b1f74..000000000 --- a/src/guichan/include/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 <list> - -#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 deleted file mode 100644 index c096bb03f..000000000 --- a/src/guichan/include/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 A_UNUSED __attribute__ ((unused)) -#else -#define A_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<SelectionListener*> 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 deleted file mode 100644 index f0f9ff566..000000000 --- a/src/guichan/include/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/include/guichan/widgets/imagebutton.hpp b/src/guichan/include/guichan/widgets/imagebutton.hpp deleted file mode 100644 index 1ab285ce9..000000000 --- a/src/guichan/include/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/include/guichan/widgets/label.hpp b/src/guichan/include/guichan/widgets/label.hpp deleted file mode 100644 index 4d6ea0006..000000000 --- a/src/guichan/include/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 <string> - -#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 deleted file mode 100644 index b99f84aaa..000000000 --- a/src/guichan/include/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 <list> - -#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<SelectionListener*> 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 deleted file mode 100644 index 0fb5b4123..000000000 --- a/src/guichan/include/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 <map> -#include <string> - -#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<std::string, RadioButton *> 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 deleted file mode 100644 index 29f95ad85..000000000 --- a/src/guichan/include/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 <string> - -#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() const; - - /** - * Gets the down button dimension. - * - * @return the dimension of the down button. - */ - Rectangle getDownButtonDimension() const; - - /** - * Gets the left button dimension. - * - * @return the dimension of the left button. - */ - Rectangle getLeftButtonDimension() const; - - /** - * Gets the right button dimension. - * - * @return the dimension of the right button. - */ - Rectangle getRightButtonDimension() const; - - /** - * Gets the vertical scrollbar dimension. - * - * @return the dimension of the vertical scrollbar. - */ - Rectangle getVerticalBarDimension() const; - - /** - * Gets the horizontal scrollbar dimension. - * - * @return the dimension of the horizontal scrollbar. - */ - Rectangle getHorizontalBarDimension() const; - - /** - * Gets the vertical marker dimension. - * - * @return the dimension of the vertical marker. - */ - Rectangle getVerticalMarkerDimension(); - - /** - * Gets the horizontal marker dimension. - * - * @return the dimension of the horizontal marker. - */ - Rectangle getHorizontalMarkerDimension(); - - /** - * 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 deleted file mode 100644 index eddf02c50..000000000 --- a/src/guichan/include/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/include/guichan/widgets/tab.hpp b/src/guichan/include/guichan/widgets/tab.hpp deleted file mode 100644 index 91c09e270..000000000 --- a/src/guichan/include/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 <map> -#include <string> - -#include "guichan/basiccontainer.hpp" -#include "guichan/mouselistener.hpp" -#include "guichan/platform.hpp" - -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_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 deleted file mode 100644 index 843bbde81..000000000 --- a/src/guichan/include/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 <map> -#include <string> -#include <vector> - -#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<Tab*> mTabsToDelete; - - /** - * A map between a tab and a widget to display when the - * tab is selected. - */ - std::vector<std::pair<Tab*, Widget*> > 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 deleted file mode 100644 index b00dcef20..000000000 --- a/src/guichan/include/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 <ctime> -#include <string> -#include <vector> - -#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<std::string> 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 deleted file mode 100644 index 486660a8a..000000000 --- a/src/guichan/include/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 <string> - -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 deleted file mode 100644 index 3b9c62160..000000000 --- a/src/guichan/include/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 <string> - -#include "guichan/mouselistener.hpp" -#include "guichan/platform.hpp" -#include "guichan/widgets/container.hpp" - -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_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/inputevent.cpp b/src/guichan/inputevent.cpp deleted file mode 100644 index 7a3bdb06d..000000000 --- a/src/guichan/inputevent.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/inputevent.hpp" - -#include "debug.h" - -namespace gcn -{ - InputEvent::InputEvent(Widget* source, - bool isShiftPressed, - bool isControlPressed, - bool isAltPressed, - bool isMetaPressed) - :Event(source), - mShiftPressed(isShiftPressed), - mControlPressed(isControlPressed), - mAltPressed(isAltPressed), - mMetaPressed(isMetaPressed), - mIsConsumed(false) - { - - } - - bool InputEvent::isShiftPressed() const - { - return mShiftPressed; - } - - bool InputEvent::isControlPressed() const - { - return mControlPressed; - } - - bool InputEvent::isAltPressed() const - { - return mAltPressed; - } - - bool InputEvent::isMetaPressed() const - { - return mMetaPressed; - } - - void InputEvent::consume() - { - mIsConsumed = true; - } - - bool InputEvent::isConsumed() const - { - return mIsConsumed; - } -} diff --git a/src/guichan/key.cpp b/src/guichan/key.cpp deleted file mode 100644 index d6c7e2313..000000000 --- a/src/guichan/key.cpp +++ /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. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/key.hpp" - -#include "debug.h" - -namespace gcn -{ - Key::Key(int value) : - mValue(value) - { - } - - bool Key::isCharacter() const - { - return (mValue >= 32 && mValue <= 126) - || (mValue >= 162 && mValue <= 255) - || (mValue == 9); - } - - bool Key::isNumber() const - { - return mValue >= 48 && mValue <= 57; - } - - bool Key::isLetter() const - { - return (((mValue >= 65 && mValue <= 90) - || (mValue >= 97 && mValue <= 122) - || (mValue >= 192 && mValue <= 255)) - && (mValue != 215) && (mValue != 247)); - } - - int Key::getValue() const - { - return mValue; - } - - bool Key::operator==(const Key& key) const - { - return mValue == key.mValue; - } - - bool Key::operator!=(const Key& key) const - { - return (mValue != key.mValue); - } -} diff --git a/src/guichan/keyevent.cpp b/src/guichan/keyevent.cpp deleted file mode 100644 index 1bc8fe9d2..000000000 --- a/src/guichan/keyevent.cpp +++ /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. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/keyevent.hpp" - -#include "debug.h" - -namespace gcn -{ - KeyEvent::KeyEvent(Widget* source, - bool isShiftPressed, - bool isControlPressed, - bool isAltPressed, - bool isMetaPressed, - unsigned int type, - bool isNumericPad, - const Key& key) - :InputEvent(source, - isShiftPressed, - isControlPressed, - isAltPressed, - isMetaPressed), - mType(type), - mIsNumericPad(isNumericPad), - mKey(key) - { - - } - - KeyEvent::~KeyEvent() - { - - } - - unsigned int KeyEvent::getType() const - { - return mType; - } - - bool KeyEvent::isNumericPad() const - { - return mIsNumericPad; - } - - const Key& KeyEvent::getKey() const - { - return mKey; - } -} diff --git a/src/guichan/keyinput.cpp b/src/guichan/keyinput.cpp deleted file mode 100644 index 0a40d7c65..000000000 --- a/src/guichan/keyinput.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/keyinput.hpp" - -#include "debug.h" - -namespace gcn -{ - KeyInput::KeyInput(const Key& key, unsigned int type) - :mKey(key), - mType(type), - mShiftPressed(false), - mControlPressed(false), - mAltPressed(false), - mMetaPressed(false), - mNumericPad(false) - { - - } - - void KeyInput::setType(unsigned int type) - { - mType = type; - } - - int KeyInput::getType() const - { - return mType; - } - - void KeyInput::setKey(const Key& key) - { - mKey = key; - } - - const Key& KeyInput::getKey() const - { - return mKey; - } - - bool KeyInput::isShiftPressed() const - { - return mShiftPressed; - } - - void KeyInput::setShiftPressed(bool pressed) - { - mShiftPressed = pressed; - } - - bool KeyInput::isControlPressed() const - { - return mControlPressed; - } - - void KeyInput::setControlPressed(bool pressed) - { - mControlPressed = pressed; - } - - bool KeyInput::isAltPressed() const - { - return mAltPressed; - } - - void KeyInput::setAltPressed(bool pressed) - { - mAltPressed = pressed; - } - - bool KeyInput::isMetaPressed() const - { - return mMetaPressed; - } - - void KeyInput::setMetaPressed(bool pressed) - { - mMetaPressed = pressed; - } - - bool KeyInput::isNumericPad() const - { - return mNumericPad; - } - - void KeyInput::setNumericPad(bool numpad) - { - mNumericPad = numpad; - } -} - diff --git a/src/guichan/mouseevent.cpp b/src/guichan/mouseevent.cpp deleted file mode 100644 index e5046ed15..000000000 --- a/src/guichan/mouseevent.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/mouseevent.hpp" - -#include "debug.h" - -namespace gcn -{ - MouseEvent::MouseEvent(Widget* source, - bool isShiftPressed, - bool isControlPressed, - bool isAltPressed, - bool isMetaPressed, - unsigned int type, - unsigned int button, - int x, - int y, - int clickCount) - :InputEvent(source, - isShiftPressed, - isControlPressed, - isAltPressed, - isMetaPressed), - mType(type), - mButton(button), - mX(x), - mY(y), - mClickCount(clickCount) - { - - } - - unsigned int MouseEvent::getButton() const - { - return mButton; - } - - int MouseEvent::getX() const - { - return mX; - } - - int MouseEvent::getY() const - { - return mY; - } - - int MouseEvent::getClickCount() const - { - return mClickCount; - } - - unsigned int MouseEvent::getType() const - { - return mType; - } -} diff --git a/src/guichan/mouseinput.cpp b/src/guichan/mouseinput.cpp deleted file mode 100644 index 5ebcfa475..000000000 --- a/src/guichan/mouseinput.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/mouseinput.hpp" - -#include "debug.h" - -namespace gcn -{ - MouseInput::MouseInput(unsigned int button, - unsigned int type, - int x, - int y, - int timeStamp) - : mType(type), - mButton(button), - mTimeStamp(timeStamp), - mX(x), - mY(y) - { - } - - void MouseInput::setType(unsigned int type) - { - mType = type; - } - - unsigned int MouseInput::getType() const - { - return mType; - } - - void MouseInput::setButton(unsigned int button) - { - mButton = button; - } - - unsigned int MouseInput::getButton() const - { - return mButton; - } - - int MouseInput::getTimeStamp() const - { - return mTimeStamp; - } - - void MouseInput::setTimeStamp(int timeStamp) - { - mTimeStamp = timeStamp; - } - - void MouseInput::setX(int x) - { - mX = x; - } - - int MouseInput::getX() const - { - return mX; - } - - void MouseInput::setY(int y) - { - mY = y; - } - - int MouseInput::getY() const - { - return mY; - } -} diff --git a/src/guichan/rectangle.cpp b/src/guichan/rectangle.cpp deleted file mode 100644 index 93e180ae5..000000000 --- a/src/guichan/rectangle.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/rectangle.hpp" - -#include "debug.h" - -namespace gcn -{ - Rectangle::Rectangle() - : x(0), - y(0), - width(0), - height(0) - { - } - - Rectangle::Rectangle(int x_, int y_, int width_, int height_) - : x(x_), - y(y_), - width(width_), - height(height_) - { - } - - void Rectangle::setAll(int x_, int y_, int width_, int height_) - { - x = x_; - y = y_; - width = width_; - height = height_; - } - - bool Rectangle::isIntersecting(const Rectangle& rectangle) const - { - int x_ = x; - int y_ = y; - int width_ = width; - int height_ = height; - - x_ -= rectangle.x; - y_ -= rectangle.y; - - if (x_ < 0) - { - width_ += x_; - x_ = 0; - } - else if (x_ + width_ > rectangle.width) - { - width_ = rectangle.width - x_; - } - - if (y_ < 0) - { - height_ += y_; - y_ = 0; - } - else if (y_ + height_ > rectangle.height) - { - height_ = rectangle.height - y_; - } - - if (width_ <= 0 || height_ <= 0) - { - return false; - } - - return true; - } - - bool Rectangle::isPointInRect(int x_, int y_) const - { - return x_ >= x - && y_ >= y - && x_ < x + width - && y_ < y + height; - } - - std::ostream& operator<<(std::ostream& out, - const Rectangle& rectangle) - { - out << "Rectangle [x = " << rectangle.x - << ", y = " << rectangle.y - << ", width = " << rectangle.width - << ", height = " << rectangle.height - << "]"; - - return out; - } -} diff --git a/src/guichan/sdl/sdlgraphics.cpp b/src/guichan/sdl/sdlgraphics.cpp deleted file mode 100644 index 28aface0e..000000000 --- a/src/guichan/sdl/sdlgraphics.cpp +++ /dev/null @@ -1,665 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/sdl/sdlgraphics.hpp" - -#include "guichan/exception.hpp" -#include "guichan/font.hpp" -#include "guichan/image.hpp" -#include "guichan/sdl/sdlimage.hpp" -#include "guichan/sdl/sdlpixel.hpp" - -#include "debug.h" - -// For some reason an old version of MSVC did not like std::abs, -// so we added this macro. -#ifndef ABS -#define ABS(x) ((x)<0?-(x):(x)) -#endif - -namespace gcn -{ - - SDLGraphics::SDLGraphics() : - mTarget(0), - mAlpha(false) - { - } - - void SDLGraphics::_beginDraw() - { - Rectangle area; - area.x = 0; - area.y = 0; - area.width = mTarget->w; - area.height = mTarget->h; - pushClipArea(area); - } - - void SDLGraphics::_endDraw() - { - popClipArea(); - } - - void SDLGraphics::setTarget(SDL_Surface* target) - { - mTarget = target; - } - - bool SDLGraphics::pushClipArea(Rectangle area) - { - SDL_Rect rect; - bool result = Graphics::pushClipArea(area); - - const ClipRectangle& carea = mClipStack.top(); - rect.x = carea.x; - rect.y = carea.y; - rect.w = carea.width; - rect.h = carea.height; - - SDL_SetClipRect(mTarget, &rect); - - return result; - } - - void SDLGraphics::popClipArea() - { - Graphics::popClipArea(); - - if (mClipStack.empty()) - return; - - const ClipRectangle& carea = mClipStack.top(); - SDL_Rect rect; - rect.x = carea.x; - rect.y = carea.y; - rect.w = carea.width; - rect.h = carea.height; - - SDL_SetClipRect(mTarget, &rect); - } - - SDL_Surface* SDLGraphics::getTarget() const - { - return mTarget; - } - - void SDLGraphics::drawImage(const Image* image, - int srcX, - int srcY, - int dstX, - int dstY, - int width, - int height) - { - if (mClipStack.empty()) - { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a " - "draw funtion outside of _beginDraw() and _endDraw()?"); - } - - const ClipRectangle& top = mClipStack.top(); - - SDL_Rect src; - SDL_Rect dst; - src.x = srcX; - src.y = srcY; - src.w = width; - src.h = height; - dst.x = dstX + top.xOffset; - dst.y = dstY + top.yOffset; - - const SDLImage* srcImage = dynamic_cast<const SDLImage*>(image); - - if (srcImage == NULL) - { - throw GCN_EXCEPTION("Trying to draw an image of unknown format," - " must be an SDLImage."); - } - - SDL_BlitSurface(srcImage->getSurface(), &src, mTarget, &dst); - } - - void SDLGraphics::fillRectangle(const Rectangle& rectangle) - { - if (mClipStack.empty()) - { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a " - "draw funtion outside of _beginDraw() and _endDraw()?"); - } - - const ClipRectangle& top = mClipStack.top(); - - Rectangle area = rectangle; - area.x += top.xOffset; - area.y += top.yOffset; - - if (!area.isIntersecting(top)) - return; - - if (mAlpha) - { - int x1 = area.x > top.x ? area.x : top.x; - int y1 = area.y > top.y ? area.y : top.y; - int x2 = area.x + area.width < top.x + top.width ? - area.x + area.width : top.x + top.width; - int y2 = area.y + area.height < top.y + top.height ? - area.y + area.height : top.y + top.height; - int x, y; - - SDL_LockSurface(mTarget); - for (y = y1; y < y2; y++) - { - for (x = x1; x < x2; x++) - SDLputPixelAlpha(mTarget, x, y, mColor); - } - SDL_UnlockSurface(mTarget); - } - else - { - SDL_Rect rect; - rect.x = area.x; - rect.y = area.y; - rect.w = area.width; - rect.h = area.height; - - Uint32 color = SDL_MapRGBA(mTarget->format, - mColor.r, - mColor.g, - mColor.b, - mColor.a); - SDL_FillRect(mTarget, &rect, color); - } - } - - void SDLGraphics::drawPoint(int x, int y) - { - if (mClipStack.empty()) - { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a " - "draw funtion outside of _beginDraw() and _endDraw()?"); - } - - const ClipRectangle& top = mClipStack.top(); - - x += top.xOffset; - y += top.yOffset; - - if (!top.isPointInRect(x, y)) - return; - - if (mAlpha) - SDLputPixelAlpha(mTarget, x, y, mColor); - else - SDLputPixel(mTarget, x, y, mColor); - } - - void SDLGraphics::drawHLine(int x1, int y, int x2) - { - if (mClipStack.empty()) - { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a " - "draw funtion outside of _beginDraw() and _endDraw()?"); - } - - const ClipRectangle& top = mClipStack.top(); - - x1 += top.xOffset; - y += top.yOffset; - x2 += top.xOffset; - - if (y < top.y || y >= top.y + top.height) - return; - - if (x1 > x2) - { - x1 ^= x2; - x2 ^= x1; - x1 ^= x2; - } - - if (top.x > x1) - { - if (top.x > x2) - return; - - x1 = top.x; - } - - if (top.x + top.width <= x2) - { - if (top.x + top.width <= x1) - return; - - x2 = top.x + top.width -1; - } - - int bpp = mTarget->format->BytesPerPixel; - - SDL_LockSurface(mTarget); - - Uint8 *p = (Uint8 *)mTarget->pixels + y * mTarget->pitch + x1 * bpp; - - Uint32 pixel = SDL_MapRGB(mTarget->format, - mColor.r, - mColor.g, - mColor.b); - switch(bpp) - { - case 1: - for (; x1 <= x2; ++x1) - *(p++) = pixel; - break; - - case 2: - { - Uint16* q = (Uint16*)p; - for (; x1 <= x2; ++x1) - *(q++) = pixel; - break; - } - - case 3: - if (SDL_BYTEORDER == SDL_BIG_ENDIAN) - { - for (; x1 <= x2; ++x1) - { - p[0] = (pixel >> 16) & 0xff; - p[1] = (pixel >> 8) & 0xff; - p[2] = pixel & 0xff; - p += 3; - } - } - else - { - for (; x1 <= x2; ++x1) - { - p[0] = pixel & 0xff; - p[1] = (pixel >> 8) & 0xff; - p[2] = (pixel >> 16) & 0xff; - p += 3; - } - } - break; - - case 4: - { - Uint32* q = (Uint32*)p; - for (; x1 <= x2; ++x1) - { - if (mAlpha) - { - *q = SDLAlpha32(pixel, *q, mColor.a); - q++; - } - else - { - *(q++) = pixel; - } - } - break; - } - default: - break; - } // end switch - - SDL_UnlockSurface(mTarget); - } - - void SDLGraphics::drawVLine(int x, int y1, int y2) - { - if (mClipStack.empty()) - { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a " - "draw funtion outside of _beginDraw() and _endDraw()?"); - } - - const ClipRectangle& top = mClipStack.top(); - - x += top.xOffset; - y1 += top.yOffset; - y2 += top.yOffset; - - if (x < top.x || x >= top.x + top.width) - return; - - if (y1 > y2) - { - y1 ^= y2; - y2 ^= y1; - y1 ^= y2; - } - - if (top.y > y1) - { - if (top.y > y2) - return; - - y1 = top.y; - } - - if (top.y + top.height <= y2) - { - if (top.y + top.height <= y1) - return; - - y2 = top.y + top.height - 1; - } - - int bpp = mTarget->format->BytesPerPixel; - - SDL_LockSurface(mTarget); - - Uint8 *p = (Uint8 *)mTarget->pixels + y1 * mTarget->pitch + x * bpp; - - Uint32 pixel = SDL_MapRGB(mTarget->format, mColor.r, - mColor.g, mColor.b); - - switch(bpp) - { - case 1: - for (; y1 <= y2; ++y1) - { - *p = pixel; - p += mTarget->pitch; - } - break; - - case 2: - for (; y1 <= y2; ++y1) - { - *(Uint16*)p = pixel; - p += mTarget->pitch; - } - break; - - case 3: - if (SDL_BYTEORDER == SDL_BIG_ENDIAN) - { - for (; y1 <= y2; ++y1) - { - p[0] = (pixel >> 16) & 0xff; - p[1] = (pixel >> 8) & 0xff; - p[2] = pixel & 0xff; - p += mTarget->pitch; - } - } - else - { - for (; y1 <= y2; ++y1) - { - p[0] = pixel & 0xff; - p[1] = (pixel >> 8) & 0xff; - p[2] = (pixel >> 16) & 0xff; - p += mTarget->pitch; - } - } - break; - - case 4: - for (; y1 <= y2; ++y1) - { - if (mAlpha) - *(Uint32*)p = SDLAlpha32(pixel, *(Uint32*)p, mColor.a); - else - *(Uint32*)p = pixel; - p += mTarget->pitch; - } - break; - - default: - break; - } // end switch - - SDL_UnlockSurface(mTarget); - } - - void SDLGraphics::drawRectangle(const Rectangle& rectangle) - { - int x1 = rectangle.x; - int x2 = rectangle.x + rectangle.width - 1; - int y1 = rectangle.y; - int y2 = rectangle.y + rectangle.height - 1; - - drawHLine(x1, y1, x2); - drawHLine(x1, y2, x2); - - drawVLine(x1, y1, y2); - drawVLine(x2, y1, y2); - } - - void SDLGraphics::drawLine(int x1, int y1, int x2, int y2) - { - if (x1 == x2) - { - drawVLine(x1, y1, y2); - return; - } - if (y1 == y2) - { - drawHLine(x1, y1, x2); - return; - } - - if (mClipStack.empty()) - { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a " - "draw funtion outside of _beginDraw() and _endDraw()?"); - } - - const ClipRectangle& top = mClipStack.top(); - - x1 += top.xOffset; - y1 += top.yOffset; - x2 += top.xOffset; - y2 += top.yOffset; - - // Draw a line with Bresenham - - int dx = ABS(x2 - x1); - int dy = ABS(y2 - y1); - - if (dx > dy) - { - if (x1 > x2) - { - // swap x1, x2 - x1 ^= x2; - x2 ^= x1; - x1 ^= x2; - - // swap y1, y2 - y1 ^= y2; - y2 ^= y1; - y1 ^= y2; - } - - if (y1 < y2) - { - int y = y1; - int p = 0; - - for (int x = x1; x <= x2; x++) - { - if (top.isPointInRect(x, y)) - { - if (mAlpha) - SDLputPixelAlpha(mTarget, x, y, mColor); - else - SDLputPixel(mTarget, x, y, mColor); - } - - p += dy; - - if (p * 2 >= dx) - { - y++; - p -= dx; - } - } - } - else - { - int y = y1; - int p = 0; - - for (int x = x1; x <= x2; x++) - { - if (top.isPointInRect(x, y)) - { - if (mAlpha) - SDLputPixelAlpha(mTarget, x, y, mColor); - else - SDLputPixel(mTarget, x, y, mColor); - } - - p += dy; - - if (p * 2 >= dx) - { - y--; - p -= dx; - } - } - } - } - else - { - if (y1 > y2) - { - // swap y1, y2 - y1 ^= y2; - y2 ^= y1; - y1 ^= y2; - - // swap x1, x2 - x1 ^= x2; - x2 ^= x1; - x1 ^= x2; - } - - if (x1 < x2) - { - int x = x1; - int p = 0; - - for (int y = y1; y <= y2; y++) - { - if (top.isPointInRect(x, y)) - { - if (mAlpha) - SDLputPixelAlpha(mTarget, x, y, mColor); - else - SDLputPixel(mTarget, x, y, mColor); - } - - p += dx; - - if (p * 2 >= dy) - { - x++; - p -= dy; - } - } - } - else - { - int x = x1; - int p = 0; - - for (int y = y1; y <= y2; y++) - { - if (top.isPointInRect(x, y)) - { - if (mAlpha) - SDLputPixelAlpha(mTarget, x, y, mColor); - else - SDLputPixel(mTarget, x, y, mColor); - } - - p += dx; - - if (p * 2 >= dy) - { - x--; - p -= dy; - } - } - } - } - } - - void SDLGraphics::setColor(const Color& color) - { - mColor = color; - - mAlpha = color.a != 255; - } - - const Color& SDLGraphics::getColor() const - { - return mColor; - } - - void SDLGraphics::drawSDLSurface(SDL_Surface* surface, - SDL_Rect source, - SDL_Rect destination) - { - if (mClipStack.empty()) - { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a " - "draw funtion outside of _beginDraw() and _endDraw()?"); - } - - const ClipRectangle& top = mClipStack.top(); - - destination.x += top.xOffset; - destination.y += top.yOffset; - - SDL_BlitSurface(surface, &source, mTarget, &destination); - } -} diff --git a/src/guichan/sdl/sdlimage.cpp b/src/guichan/sdl/sdlimage.cpp deleted file mode 100644 index 12c5571cf..000000000 --- a/src/guichan/sdl/sdlimage.cpp +++ /dev/null @@ -1,187 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/sdl/sdlimage.hpp" - -#include "guichan/exception.hpp" -#include "guichan/sdl/sdlpixel.hpp" - -namespace gcn -{ - SDLImage::SDLImage(SDL_Surface* surface, bool autoFree) - { - mAutoFree = autoFree; - mSurface = surface; - } - - SDLImage::~SDLImage() - { - if (mAutoFree) - free(); - } - - SDL_Surface* SDLImage::getSurface() const - { - return mSurface; - } - - int SDLImage::getWidth() const - { - if (mSurface == NULL) - { - throw GCN_EXCEPTION("Trying to get the width of " - "a non loaded image."); - } - - return mSurface->w; - } - - int SDLImage::getHeight() const - { - if (mSurface == NULL) - { - throw GCN_EXCEPTION("Trying to get the height of " - "a non loaded image."); - } - - return mSurface->h; - } - - Color SDLImage::getPixel(int x, int y) - { - if (mSurface == NULL) - { - throw GCN_EXCEPTION("Trying to get a pixel from a " - "non loaded image."); - } - - return SDLgetPixel(mSurface, x, y); - } - - void SDLImage::putPixel(int x, int y, const Color& color) - { - if (mSurface == NULL) - { - throw GCN_EXCEPTION("Trying to put a pixel in a " - "non loaded image."); - } - - SDLputPixel(mSurface, x, y, color); - } - - void SDLImage::convertToDisplayFormat() - { - if (mSurface == NULL) - { - throw GCN_EXCEPTION("Trying to convert a non loaded image " - "to display format."); - } - - int i; - bool hasPink = false; - bool hasAlpha = false; - - for (i = 0; i < mSurface->w * mSurface->h; ++i) - { - if (((unsigned int*)mSurface->pixels)[i] == SDL_MapRGB( - mSurface->format, 255, 0, 255)) - { - hasPink = true; - break; - } - } - - for (i = 0; i < mSurface->w * mSurface->h; ++i) - { - Uint8 r, g, b, a; - - SDL_GetRGBA(((unsigned int*)mSurface->pixels)[i], mSurface->format, - &r, &g, &b, &a); - - if (a != 255) - { - hasAlpha = true; - break; - } - } - - SDL_Surface *tmp; - - if (hasAlpha) - { - tmp = SDL_DisplayFormatAlpha(mSurface); - SDL_FreeSurface(mSurface); - mSurface = NULL; - } - else - { - tmp = SDL_DisplayFormat(mSurface); - SDL_FreeSurface(mSurface); - mSurface = NULL; - } - - if (tmp == NULL) - throw GCN_EXCEPTION("Unable to convert image to display format."); - - if (hasPink) - { - SDL_SetColorKey(tmp, SDL_SRCCOLORKEY, - SDL_MapRGB(tmp->format, 255, 0, 255)); - } - if (hasAlpha) - { - SDL_SetAlpha(tmp, SDL_SRCALPHA, 255); - } - - mSurface = tmp; - } - - void SDLImage::free() - { - SDL_FreeSurface(mSurface); - } -} diff --git a/src/guichan/selectionevent.cpp b/src/guichan/selectionevent.cpp deleted file mode 100644 index e707cedf8..000000000 --- a/src/guichan/selectionevent.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/selectionevent.hpp" - -#include "debug.h" - -namespace gcn -{ - SelectionEvent::SelectionEvent(Widget* source) - :Event(source) - { - - } - - SelectionEvent::~SelectionEvent() - { - - } -} - diff --git a/src/guichan/widget.cpp b/src/guichan/widget.cpp deleted file mode 100644 index e2ed26508..000000000 --- a/src/guichan/widget.cpp +++ /dev/null @@ -1,718 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widget.hpp" - -#include "guichan/actionevent.hpp" -#include "guichan/actionlistener.hpp" -#include "guichan/basiccontainer.hpp" -#include "guichan/deathlistener.hpp" -#include "guichan/defaultfont.hpp" -#include "guichan/event.hpp" -#include "guichan/exception.hpp" -#include "guichan/focushandler.hpp" -#include "guichan/graphics.hpp" -#include "guichan/keyinput.hpp" -#include "guichan/keylistener.hpp" -#include "guichan/mouseinput.hpp" -#include "guichan/mouselistener.hpp" -#include "guichan/widgetlistener.hpp" - -#include "debug.h" - -namespace gcn -{ - Font* Widget::mGlobalFont = NULL; - DefaultFont Widget::mDefaultFont; - std::list<Widget*> Widget::mWidgets; - std::set<Widget*> Widget::mWidgetsSet; - - Widget::Widget() : - mForegroundColor(0x000000), - mBackgroundColor(0xffffff), - mBaseColor(0x808090), - mSelectionColor(0xc3d9ff), - mFocusHandler(NULL), - mInternalFocusHandler(NULL), - mParent(NULL), - mFrameSize(0), - mFocusable(false), - mVisible(true), - mTabIn(true), - mTabOut(true), - mEnabled(true), - mCurrentFont(NULL) - { - mWidgets.push_back(this); - mWidgetsSet.insert(this); - } - - Widget::~Widget() - { - DeathListenerIterator iter; - - for (iter = mDeathListeners.begin(); - iter != mDeathListeners.end(); - ++iter) - { - Event event(this); - (*iter)->death(event); - } - - _setFocusHandler(NULL); - - mWidgets.remove(this); - mWidgetsSet.erase(this); - } - - void Widget::drawFrame(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getFrameSize() * 2 - 1; - int height = getHeight() + getFrameSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getFrameSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i, i, width - i, i); - graphics->drawLine(i, i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i, i + 1, width - i, height - i); - graphics->drawLine(i, height - i, width - i - 1, height - i); - } - } - - void Widget::_setParent(Widget* parent) - { - mParent = parent; - } - - Widget* Widget::getParent() const - { - return mParent; - } - - void Widget::setWidth(int width) - { - Rectangle newDimension = mDimension; - newDimension.width = width; - - setDimension(newDimension); - } - - int Widget::getWidth() const - { - return mDimension.width; - } - - void Widget::setHeight(int height) - { - Rectangle newDimension = mDimension; - newDimension.height = height; - - setDimension(newDimension); - } - - int Widget::getHeight() const - { - return mDimension.height; - } - - void Widget::setX(int x) - { - Rectangle newDimension = mDimension; - newDimension.x = x; - - setDimension(newDimension); - } - - int Widget::getX() const - { - return mDimension.x; - } - - void Widget::setY(int y) - { - Rectangle newDimension = mDimension; - newDimension.y = y; - - setDimension(newDimension); - } - - int Widget::getY() const - { - return mDimension.y; - } - - void Widget::setPosition(int x, int y) - { - Rectangle newDimension = mDimension; - newDimension.x = x; - newDimension.y = y; - - setDimension(newDimension); - } - - void Widget::setDimension(const Rectangle& dimension) - { - Rectangle oldDimension = mDimension; - mDimension = dimension; - - if (mDimension.width != oldDimension.width - || mDimension.height != oldDimension.height) - { - distributeResizedEvent(); - } - - if (mDimension.x != oldDimension.x - || mDimension.y != oldDimension.y) - { - distributeMovedEvent(); - } - } - - void Widget::setFrameSize(unsigned int frameSize) - { - mFrameSize = frameSize; - } - - unsigned int Widget::getFrameSize() const - { - return mFrameSize; - } - - const Rectangle& Widget::getDimension() const - { - return mDimension; - } - - const std::string& Widget::getActionEventId() const - { - return mActionEventId; - } - - void Widget::setActionEventId(const std::string& actionEventId) - { - mActionEventId = actionEventId; - } - - bool Widget::isFocused() const - { - if (!mFocusHandler) - return false; - - return (mFocusHandler->isFocused(this)); - } - - void Widget::setFocusable(bool focusable) - { - if (!focusable && isFocused()) - { - mFocusHandler->focusNone(); - } - - mFocusable = focusable; - } - - bool Widget::isFocusable() const - { - return mFocusable && isVisible() && isEnabled(); - } - - void Widget::requestFocus() - { - if (mFocusHandler == NULL) - { - throw GCN_EXCEPTION("No focushandler set (did you add " - "the widget to the gui?)."); - } - - if (isFocusable()) - mFocusHandler->requestFocus(this); - } - - void Widget::requestMoveToTop() - { - if (mParent) - mParent->moveToTop(this); - } - - void Widget::requestMoveToBottom() - { - if (mParent) - mParent->moveToBottom(this); - } - - void Widget::setVisible(bool visible) - { - if (!visible && isFocused()) - mFocusHandler->focusNone(); - - if (visible) - distributeShownEvent(); - else if (!visible) - distributeHiddenEvent(); - - mVisible = visible; - } - - bool Widget::isVisible() const - { - if (!mParent) - return mVisible; - else - return mVisible && mParent->isVisible(); - } - - void Widget::setBaseColor(const Color& color) - { - mBaseColor = color; - } - - const Color& Widget::getBaseColor() const - { - return mBaseColor; - } - - void Widget::setForegroundColor(const Color& color) - { - mForegroundColor = color; - } - - const Color& Widget::getForegroundColor() const - { - return mForegroundColor; - } - - void Widget::setBackgroundColor(const Color& color) - { - mBackgroundColor = color; - } - - const Color& Widget::getBackgroundColor() const - { - return mBackgroundColor; - } - - void Widget::setSelectionColor(const Color& color) - { - mSelectionColor = color; - } - - const Color& Widget::getSelectionColor() const - { - return mSelectionColor; - } - - void Widget::_setFocusHandler(FocusHandler* focusHandler) - { - if (mFocusHandler) - { - releaseModalFocus(); - mFocusHandler->remove(this); - } - - if (focusHandler) - focusHandler->add(this); - - mFocusHandler = focusHandler; - } - - FocusHandler* Widget::_getFocusHandler() - { - return mFocusHandler; - } - - void Widget::addActionListener(ActionListener* actionListener) - { - mActionListeners.push_back(actionListener); - } - - void Widget::removeActionListener(ActionListener* actionListener) - { - mActionListeners.remove(actionListener); - } - - void Widget::addDeathListener(DeathListener* deathListener) - { - mDeathListeners.push_back(deathListener); - } - - void Widget::removeDeathListener(DeathListener* deathListener) - { - mDeathListeners.remove(deathListener); - } - - void Widget::addKeyListener(KeyListener* keyListener) - { - mKeyListeners.push_back(keyListener); - } - - void Widget::removeKeyListener(KeyListener* keyListener) - { - mKeyListeners.remove(keyListener); - } - - void Widget::addFocusListener(FocusListener* focusListener) - { - mFocusListeners.push_back(focusListener); - } - - void Widget::removeFocusListener(FocusListener* focusListener) - { - mFocusListeners.remove(focusListener); - } - - void Widget::addMouseListener(MouseListener* mouseListener) - { - mMouseListeners.push_back(mouseListener); - } - - void Widget::removeMouseListener(MouseListener* mouseListener) - { - mMouseListeners.remove(mouseListener); - } - - void Widget::addWidgetListener(WidgetListener* widgetListener) - { - mWidgetListeners.push_back(widgetListener); - } - - void Widget::removeWidgetListener(WidgetListener* widgetListener) - { - mWidgetListeners.remove(widgetListener); - } - - void Widget::getAbsolutePosition(int& x, int& y) const - { - if (!mParent) - { - x = mDimension.x; - y = mDimension.y; - return; - } - - int parentX; - int parentY; - - mParent->getAbsolutePosition(parentX, parentY); - - const Rectangle &rect = mParent->getChildrenArea(); - x = parentX + mDimension.x + rect.x; - y = parentY + mDimension.y + rect.y; - } - - Font* Widget::getFont() const - { - if (mCurrentFont == NULL) - { - if (mGlobalFont == NULL) - return &mDefaultFont; - - return mGlobalFont; - } - - return mCurrentFont; - } - - void Widget::setGlobalFont(Font* font) - { - mGlobalFont = font; - - std::list<Widget*>::iterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); ++iter) - { - if ((*iter)->mCurrentFont == NULL) - (*iter)->fontChanged(); - } - } - - void Widget::setFont(Font* font) - { - mCurrentFont = font; - fontChanged(); - } - - bool Widget::widgetExists(const Widget* widget) - { - return mWidgetsSet.find(const_cast<Widget*>(widget)) - != mWidgetsSet.end(); - } - - bool Widget::isTabInEnabled() const - { - return mTabIn; - } - - void Widget::setTabInEnabled(bool enabled) - { - mTabIn = enabled; - } - - bool Widget::isTabOutEnabled() const - { - return mTabOut; - } - - void Widget::setTabOutEnabled(bool enabled) - { - mTabOut = enabled; - } - - void Widget::setSize(int width, int height) - { - Rectangle newDimension = mDimension; - newDimension.width = width; - newDimension.height = height; - - setDimension(newDimension); - } - - void Widget::setEnabled(bool enabled) - { - mEnabled = enabled; - } - - bool Widget::isEnabled() const - { - return mEnabled && isVisible(); - } - - void Widget::requestModalFocus() - { - if (mFocusHandler == NULL) - { - throw GCN_EXCEPTION("No focushandler set (did you add " - "the widget to the gui?)."); - } - - mFocusHandler->requestModalFocus(this); - } - - void Widget::requestModalMouseInputFocus() - { - if (mFocusHandler == NULL) - { - throw GCN_EXCEPTION("No focushandler set (did you add " - "the widget to the gui?)."); - } - - mFocusHandler->requestModalMouseInputFocus(this); - } - - void Widget::releaseModalFocus() - { - if (mFocusHandler == NULL) - return; - - mFocusHandler->releaseModalFocus(this); - } - - void Widget::releaseModalMouseInputFocus() - { - if (mFocusHandler == NULL) - return; - - mFocusHandler->releaseModalMouseInputFocus(this); - } - - bool Widget::isModalFocused() const - { - if (mFocusHandler == NULL) - { - throw GCN_EXCEPTION("No focushandler set (did you add " - "the widget to the gui?)."); - } - - if (mParent) - { - return (mFocusHandler->getModalFocused() == this) - || mParent->isModalFocused(); - } - - return mFocusHandler->getModalFocused() == this; - } - - bool Widget::isModalMouseInputFocused() const - { - if (mFocusHandler == NULL) - { - throw GCN_EXCEPTION("No focushandler set (did you add " - "the widget to the gui?)."); - } - - if (mParent) - { - return (mFocusHandler->getModalMouseInputFocused() == this) - || mParent->isModalMouseInputFocused(); - } - - return mFocusHandler->getModalMouseInputFocused() == this; - } - - Widget *Widget::getWidgetAt(int x A_UNUSED, int y A_UNUSED) - { - return NULL; - } - - const std::list<MouseListener*>& Widget::_getMouseListeners() - { - return mMouseListeners; - } - - const std::list<KeyListener*>& Widget::_getKeyListeners() - { - return mKeyListeners; - } - - const std::list<FocusListener*>& Widget::_getFocusListeners() - { - return mFocusListeners; - } - - Rectangle Widget::getChildrenArea() - { - return Rectangle(0, 0, 0, 0); - } - - FocusHandler* Widget::_getInternalFocusHandler() - { - return mInternalFocusHandler; - } - - void Widget::setInternalFocusHandler(FocusHandler* focusHandler) - { - mInternalFocusHandler = focusHandler; - } - - void Widget::setId(const std::string& id) - { - mId = id; - } - - const std::string& Widget::getId() - { - return mId; - } - - void Widget::distributeResizedEvent() - { - WidgetListenerIterator iter; - - for (iter = mWidgetListeners.begin(); - iter != mWidgetListeners.end(); - ++ iter) - { - Event event(this); - (*iter)->widgetResized(event); - } - } - - void Widget::distributeMovedEvent() - { - WidgetListenerIterator iter; - - for (iter = mWidgetListeners.begin(); - iter != mWidgetListeners.end(); - ++ iter) - { - Event event(this); - (*iter)->widgetMoved(event); - } - } - - void Widget::distributeHiddenEvent() - { - WidgetListenerIterator iter; - - for (iter = mWidgetListeners.begin(); - iter != mWidgetListeners.end(); - ++ iter) - { - Event event(this); - (*iter)->widgetHidden(event); - } - } - - void Widget::distributeActionEvent() - { - ActionListenerIterator iter; - for (iter = mActionListeners.begin(); - iter != mActionListeners.end(); - ++iter) - { - ActionEvent actionEvent(this, mActionEventId); - (*iter)->action(actionEvent); - } - } - - void Widget::distributeShownEvent() - { - WidgetListenerIterator iter; - - for (iter = mWidgetListeners.begin(); - iter != mWidgetListeners.end(); - ++iter) - { - Event event(this); - (*iter)->widgetShown(event); - } - } - - void Widget::showPart(Rectangle rectangle) - { - if (mParent != NULL) - mParent->showWidgetPart(this, rectangle); - } -} diff --git a/src/guichan/widgets/button.cpp b/src/guichan/widgets/button.cpp deleted file mode 100644 index 184b6235c..000000000 --- a/src/guichan/widgets/button.cpp +++ /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. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/button.hpp" - -#include "guichan/exception.hpp" -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" -#include "guichan/key.hpp" -#include "guichan/mouseevent.hpp" -#include "guichan/mouseinput.hpp" - -#include "debug.h" - -namespace gcn -{ - Button::Button() - : mHasMouse(false), - mKeyPressed(false), - mMousePressed(false), - mAlignment(Graphics::CENTER), - mSpacing(4) - { - setFocusable(true); - adjustSize(); - setFrameSize(1); - - addMouseListener(this); - addKeyListener(this); - addFocusListener(this); - } - - Button::Button(const std::string& caption) - : mCaption(caption), - mHasMouse(false), - mKeyPressed(false), - mMousePressed(false), - mAlignment(Graphics::CENTER), - mSpacing(4) - { - setFocusable(true); - adjustSize(); - setFrameSize(1); - - addMouseListener(this); - addKeyListener(this); - addFocusListener(this); - } - - void Button::setCaption(const std::string& caption) - { - mCaption = caption; - } - - const std::string& Button::getCaption() const - { - return mCaption; - } - - void Button::setAlignment(Graphics::Alignment alignment) - { - mAlignment = alignment; - } - - Graphics::Alignment Button::getAlignment() const - { - return mAlignment; - } - - void Button::setSpacing(unsigned int spacing) - { - mSpacing = spacing; - } - - unsigned int Button::getSpacing() const - { - return mSpacing; - } - - void Button::draw(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - - if (isPressed()) - { - faceColor = faceColor - 0x303030; - faceColor.a = alpha; - highlightColor = faceColor - 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor + 0x303030; - shadowColor.a = alpha; - } - else - { - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - } - - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(1, 1, - getDimension().width - 1, getHeight() - 1)); - - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, getWidth() - 1, 0); - graphics->drawLine(0, 1, 0, getHeight() - 1); - - graphics->setColor(shadowColor); - graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1); - graphics->drawLine(1, getHeight() - 1, - getWidth() - 1, getHeight() - 1); - - graphics->setColor(getForegroundColor()); - - int textX; - int textY = getHeight() / 2 - getFont()->getHeight() / 2; - - switch (getAlignment()) - { - case Graphics::LEFT: - textX = mSpacing; - break; - case Graphics::CENTER: - textX = getWidth() / 2; - break; - case Graphics::RIGHT: - textX = getWidth() - mSpacing; - break; - default: - throw GCN_EXCEPTION("Unknown alignment."); - } - - graphics->setFont(getFont()); - - if (isPressed()) - { - graphics->drawText(getCaption(), textX + 1, textY + 1, - getAlignment()); - } - else - { - graphics->drawText(getCaption(), textX, textY, getAlignment()); - - if (isFocused()) - { - graphics->drawRectangle(Rectangle(2, 2, getWidth() - 4, - getHeight() - 4)); - } - } - } - - void Button::adjustSize() - { - setWidth(getFont()->getWidth(mCaption) + 2*mSpacing); - setHeight(getFont()->getHeight() + 2*mSpacing); - } - - bool Button::isPressed() const - { - if (mMousePressed) - { - return mHasMouse; - } - else - { - return mKeyPressed; - } - } - - void Button::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mMousePressed = true; - mouseEvent.consume(); - } - } - - void Button::mouseExited(MouseEvent& mouseEvent A_UNUSED) - { - mHasMouse = false; - } - - void Button::mouseEntered(MouseEvent& mouseEvent A_UNUSED) - { - mHasMouse = true; - } - - void Button::mouseReleased(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT - && mMousePressed - && mHasMouse) - { - mMousePressed = false; - distributeActionEvent(); - mouseEvent.consume(); - } - else if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mMousePressed = false; - mouseEvent.consume(); - } - } - - void Button::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } - - void Button::keyPressed(KeyEvent& keyEvent) - { - Key key = keyEvent.getKey(); - - if (key.getValue() == Key::ENTER - || key.getValue() == Key::SPACE) - { - mKeyPressed = true; - keyEvent.consume(); - } - } - - void Button::keyReleased(KeyEvent& keyEvent) - { - Key key = keyEvent.getKey(); - - if ((key.getValue() == Key::ENTER - || key.getValue() == Key::SPACE) - && mKeyPressed) - { - mKeyPressed = false; - distributeActionEvent(); - keyEvent.consume(); - } - } - - void Button::focusLost(const Event& event A_UNUSED) - { - mMousePressed = false; - mKeyPressed = false; - } -} diff --git a/src/guichan/widgets/checkbox.cpp b/src/guichan/widgets/checkbox.cpp deleted file mode 100644 index 04423a6e9..000000000 --- a/src/guichan/widgets/checkbox.cpp +++ /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. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/checkbox.hpp" - -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" -#include "guichan/key.hpp" -#include "guichan/mouseinput.hpp" - -#include "debug.h" - -namespace gcn -{ - - CheckBox::CheckBox() - { - setSelected(false); - - setFocusable(true); - addMouseListener(this); - addKeyListener(this); - } - - CheckBox::CheckBox(const std::string &caption, bool selected) - { - setCaption(caption); - setSelected(selected); - - setFocusable(true); - addMouseListener(this); - addKeyListener(this); - - adjustSize(); - } - - void CheckBox::draw(Graphics* graphics) - { - drawBox(graphics); - - graphics->setFont(getFont()); - graphics->setColor(getForegroundColor()); - - const int h = getHeight() + getHeight() / 2; - - graphics->drawText(getCaption(), h - 2, 0); - } - - void CheckBox::drawBox(Graphics *graphics) - { - const int h = getHeight() - 2; - const int alpha = getBaseColor().a; - Color faceColor = getBaseColor(); - faceColor.a = alpha; - Color highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - Color shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - graphics->setColor(shadowColor); - graphics->drawLine(1, 1, h, 1); - graphics->drawLine(1, 1, 1, h); - - graphics->setColor(highlightColor); - graphics->drawLine(h, 1, h, h); - graphics->drawLine(1, h, h - 1, h); - - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(Rectangle(2, 2, h - 2, h - 2)); - - graphics->setColor(getForegroundColor()); - - if (isFocused()) - { - graphics->drawRectangle(Rectangle(0, 0, h + 2, h + 2)); - } - - if (mSelected) - { - graphics->drawLine(3, 5, 3, h - 2); - graphics->drawLine(4, 5, 4, h - 2); - - graphics->drawLine(5, h - 3, h - 2, 4); - graphics->drawLine(5, h - 4, h - 4, 5); - } - } - - bool CheckBox::isSelected() const - { - return mSelected; - } - - void CheckBox::setSelected(bool selected) - { - mSelected = selected; - } - - const std::string &CheckBox::getCaption() const - { - return mCaption; - } - - void CheckBox::setCaption(const std::string& caption) - { - mCaption = caption; - } - - void CheckBox::keyPressed(KeyEvent& keyEvent) - { - Key key = keyEvent.getKey(); - - if (key.getValue() == Key::ENTER || - key.getValue() == Key::SPACE) - { - toggleSelected(); - keyEvent.consume(); - } - } - - void CheckBox::mouseClicked(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - toggleSelected(); - } - } - - void CheckBox::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } - - void CheckBox::adjustSize() - { - int height = getFont()->getHeight(); - - setHeight(height); - setWidth(getFont()->getWidth(mCaption) + height + height / 2); - } - - void CheckBox::toggleSelected() - { - mSelected = !mSelected; - distributeActionEvent(); - } -} - diff --git a/src/guichan/widgets/container.cpp b/src/guichan/widgets/container.cpp deleted file mode 100644 index 7ab34a93b..000000000 --- a/src/guichan/widgets/container.cpp +++ /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. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/container.hpp" - -#include "guichan/exception.hpp" -#include "guichan/graphics.hpp" - -#include "debug.h" - -namespace gcn -{ - - Container::Container() - { - mOpaque = true; - } - - Container::~Container() - { - - } - - void Container::draw(Graphics* graphics) - { - if (isOpaque()) - { - graphics->setColor(getBaseColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - } - - drawChildren(graphics); - } - - void Container::setOpaque(bool opaque) - { - mOpaque = opaque; - } - - bool Container::isOpaque() const - { - return mOpaque; - } - - void Container::add(Widget* widget) - { - BasicContainer::add(widget); - } - - void Container::add(Widget* widget, int x, int y) - { - widget->setPosition(x, y); - BasicContainer::add(widget); - } - - void Container::remove(Widget* widget) - { - BasicContainer::remove(widget); - } - - void Container::clear() - { - BasicContainer::clear(); - } - - Widget* Container::findWidgetById(const std::string &id) - { - return BasicContainer::findWidgetById(id); - } -} diff --git a/src/guichan/widgets/dropdown.cpp b/src/guichan/widgets/dropdown.cpp deleted file mode 100644 index 7af01e703..000000000 --- a/src/guichan/widgets/dropdown.cpp +++ /dev/null @@ -1,574 +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. - */ - -#include "guichan/widgets/dropdown.hpp" - -#include "guichan/exception.hpp" -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" -#include "guichan/key.hpp" -#include "guichan/listmodel.hpp" -#include "guichan/mouseinput.hpp" -#include "guichan/widgets/listbox.hpp" -#include "guichan/widgets/scrollarea.hpp" - -#include "debug.h" - -namespace gcn -{ - DropDown::DropDown(ListModel *listModel, - ScrollArea *scrollArea, - ListBox *listBox) - { - setWidth(100); - setFocusable(true); - mDroppedDown = false; - mPushed = false; - mIsDragged = false; - - setInternalFocusHandler(&mInternalFocusHandler); - - mInternalScrollArea = (scrollArea == NULL); - mInternalListBox = (listBox == NULL); - - if (mInternalScrollArea) - mScrollArea = new ScrollArea(); - else - mScrollArea = scrollArea; - - if (mInternalListBox) - mListBox = new ListBox(); - else - mListBox = listBox; - - mScrollArea->setContent(mListBox); - add(mScrollArea); - - mListBox->addActionListener(this); - mListBox->addSelectionListener(this); - - setListModel(listModel); - - if (mListBox->getSelected() < 0) - mListBox->setSelected(0); - - addMouseListener(this); - addKeyListener(this); - addFocusListener(this); - - adjustHeight(); - } - - DropDown::~DropDown() - { - if (widgetExists(mListBox)) - { - mListBox->removeActionListener(this); - mListBox->removeSelectionListener(this); - } - - if (mInternalScrollArea) - { - delete mScrollArea; - mScrollArea = 0; - } - - if (mInternalListBox) - { - delete mListBox; - mListBox = 0; - } - - setInternalFocusHandler(NULL); - } - - void DropDown::draw(Graphics* graphics) - { - int h; - - if (mDroppedDown) - h = mFoldedUpHeight; - else - h = getHeight(); - - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - // Draw a border. - graphics->setColor(shadowColor); - graphics->drawLine(0, 0, getWidth() - 1, 0); - graphics->drawLine(0, 1, 0, h - 2); - graphics->setColor(highlightColor); - graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, h - 1); - graphics->drawLine(0, h - 1, getWidth() - 1, h - 1); - - // Push a clip area so the other drawings don't need to worry - // about the border. - graphics->pushClipArea(Rectangle(1, 1, getWidth() - 2, h - 2)); - const Rectangle currentClipArea = graphics->getCurrentClipArea(); - - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(Rectangle(0, 0, - currentClipArea.width, currentClipArea.height)); - - if (isFocused()) - { - graphics->setColor(getSelectionColor()); - graphics->fillRectangle(Rectangle(0, 0, - currentClipArea.width - currentClipArea.height, - currentClipArea.height)); - graphics->setColor(getForegroundColor()); - } - - if (mListBox->getListModel() - && mListBox->getSelected() >= 0) - { - graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); - - graphics->drawText(mListBox->getListModel()->getElementAt( - mListBox->getSelected()), 1, 0); - } - - // Push a clip area before drawing the button. - graphics->pushClipArea(Rectangle( - currentClipArea.width - currentClipArea.height, - 0, currentClipArea.height, currentClipArea.height)); - drawButton(graphics); - graphics->popClipArea(); - graphics->popClipArea(); - - if (mDroppedDown) - { - // Draw a border around the children. - graphics->setColor(shadowColor); - graphics->drawRectangle(Rectangle(0, mFoldedUpHeight, - getWidth(), getHeight() - mFoldedUpHeight)); - drawChildren(graphics); - } - } - - void DropDown::drawButton(Graphics *graphics) - { - Color faceColor, highlightColor, shadowColor; - int offset; - int alpha = getBaseColor().a; - - if (mPushed) - { - faceColor = getBaseColor() - 0x303030; - faceColor.a = alpha; - highlightColor = faceColor - 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor + 0x303030; - shadowColor.a = alpha; - offset = 1; - } - else - { - faceColor = getBaseColor(); - faceColor.a = alpha; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - offset = 0; - } - - const Rectangle currentClipArea = graphics->getCurrentClipArea(); - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, currentClipArea.width - 1, 0); - graphics->drawLine(0, 1, 0, currentClipArea.height - 1); - graphics->setColor(shadowColor); - graphics->drawLine(currentClipArea.width - 1, 1, - currentClipArea.width - 1, currentClipArea.height - 1); - graphics->drawLine(1, currentClipArea.height - 1, - currentClipArea.width - 2, currentClipArea.height - 1); - - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(1, 1, - currentClipArea.width - 2, currentClipArea.height - 2)); - - graphics->setColor(getForegroundColor()); - - int i; - int n = currentClipArea.height / 3; - int dx = currentClipArea.height / 2; - int dy = (currentClipArea.height * 2) / 3; - for (i = 0; i < n; i++) - { - graphics->drawLine(dx - i + offset, dy - i + offset, - dx + i + offset, dy - i + offset); - } - } - - int DropDown::getSelected() const - { - return mListBox->getSelected(); - } - - void DropDown::setSelected(int selected) - { - if (selected >= 0) - mListBox->setSelected(selected); - } - - void DropDown::keyPressed(KeyEvent& keyEvent) - { - if (keyEvent.isConsumed()) - return; - - Key key = keyEvent.getKey(); - - if ((key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) - && !mDroppedDown) - { - dropDown(); - keyEvent.consume(); - } - else if (key.getValue() == Key::UP) - { - setSelected(getSelected() - 1); - keyEvent.consume(); - } - else if (key.getValue() == Key::DOWN) - { - setSelected(getSelected() + 1); - keyEvent.consume(); - } - } - - void DropDown::mousePressed(MouseEvent& mouseEvent) - { - // If we have a mouse press on the widget. - if (0 <= mouseEvent.getY() - && mouseEvent.getY() < getHeight() - && mouseEvent.getX() >= 0 - && mouseEvent.getX() < getWidth() - && mouseEvent.getButton() == MouseEvent::LEFT - && !mDroppedDown - && mouseEvent.getSource() == this) - { - mPushed = true; - dropDown(); - requestModalMouseInputFocus(); - } - // Fold up the listbox if the upper part is clicked after fold down - else if (0 <= mouseEvent.getY() - && mouseEvent.getY() < mFoldedUpHeight - && mouseEvent.getX() >= 0 - && mouseEvent.getX() < getWidth() - && mouseEvent.getButton() == MouseEvent::LEFT - && mDroppedDown - && mouseEvent.getSource() == this) - { - mPushed = false; - foldUp(); - releaseModalMouseInputFocus(); - } - // If we have a mouse press outside the widget - else if (0 > mouseEvent.getY() - || mouseEvent.getY() >= getHeight() - || mouseEvent.getX() < 0 - || mouseEvent.getX() >= getWidth()) - { - mPushed = false; - foldUp(); - } - } - - void DropDown::mouseReleased(MouseEvent& mouseEvent) - { - if (mIsDragged) - mPushed = false; - - // Released outside of widget. Can happen when we have modal - // input focus. - if ((0 > mouseEvent.getY() - || mouseEvent.getY() >= getHeight() - || mouseEvent.getX() < 0 - || mouseEvent.getX() >= getWidth()) - && mouseEvent.getButton() == MouseEvent::LEFT - && isModalMouseInputFocused()) - { - releaseModalMouseInputFocus(); - - if (mIsDragged) - foldUp(); - } - else if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mPushed = false; - } - - mIsDragged = false; - } - - void DropDown::mouseDragged(MouseEvent& mouseEvent) - { - mIsDragged = true; - - mouseEvent.consume(); - } - - void DropDown::setListModel(ListModel *listModel) - { - mListBox->setListModel(listModel); - - if (mListBox->getSelected() < 0) - mListBox->setSelected(0); - - adjustHeight(); - } - - ListModel *DropDown::getListModel() - { - return mListBox->getListModel(); - } - - void DropDown::adjustHeight() - { - if (mScrollArea == NULL) - throw GCN_EXCEPTION("Scroll area has been deleted."); - - if (mListBox == NULL) - throw GCN_EXCEPTION("List box has been deleted."); - - int listBoxHeight = mListBox->getHeight(); - - // We add 2 for the border - int h2 = getFont()->getHeight() + 2; - - setHeight(h2); - - // The addition/subtraction of 2 compensates for the seperation lines - // seperating the selected element view and the scroll area. - - if (mDroppedDown && getParent()) - { - int h = getParent()->getChildrenArea().height - getY(); - - if (listBoxHeight > h - h2 - 2) - { - mScrollArea->setHeight(h - h2 - 2); - setHeight(h); - } - else - { - setHeight(listBoxHeight + h2 + 2); - mScrollArea->setHeight(listBoxHeight); - } - } - - mScrollArea->setWidth(getWidth()); - // Resize the ListBox to exactly fit the ScrollArea. - mListBox->setWidth(mScrollArea->getChildrenArea().width); - mScrollArea->setPosition(0, 0); - } - - void DropDown::dropDown() - { - if (!mDroppedDown) - { - mDroppedDown = true; - mFoldedUpHeight = getHeight(); - adjustHeight(); - - if (getParent()) - getParent()->moveToTop(this); - } - - mListBox->requestFocus(); - } - - void DropDown::foldUp() - { - if (mDroppedDown) - { - mDroppedDown = false; - adjustHeight(); - mInternalFocusHandler.focusNone(); - } - } - - void DropDown::focusLost(const Event& event A_UNUSED) - { - foldUp(); - mInternalFocusHandler.focusNone(); - } - - - void DropDown::death(const Event& event) - { - if (event.getSource() == mScrollArea) - mScrollArea = NULL; - - BasicContainer::death(event); - } - - void DropDown::action(const ActionEvent& actionEvent A_UNUSED) - { - foldUp(); - releaseModalMouseInputFocus(); - distributeActionEvent(); - } - - Rectangle DropDown::getChildrenArea() - { - if (mDroppedDown) - { - // Calculate the children area (with the one pixel border in mind) - return Rectangle(1, mFoldedUpHeight + 1, - getWidth() - 2, getHeight() - mFoldedUpHeight - 2); - } - - return Rectangle(); - } - - void DropDown::setBaseColor(const Color& color) - { - if (mInternalScrollArea) - mScrollArea->setBaseColor(color); - - if (mInternalListBox) - mListBox->setBaseColor(color); - - Widget::setBaseColor(color); - } - - void DropDown::setBackgroundColor(const Color& color) - { - if (mInternalScrollArea) - mScrollArea->setBackgroundColor(color); - - if (mInternalListBox) - mListBox->setBackgroundColor(color); - - Widget::setBackgroundColor(color); - } - - void DropDown::setForegroundColor(const Color& color) - { - if (mInternalScrollArea) - mScrollArea->setForegroundColor(color); - - if (mInternalListBox) - mListBox->setForegroundColor(color); - - Widget::setForegroundColor(color); - } - - void DropDown::setFont(Font *font) - { - if (mInternalScrollArea) - mScrollArea->setFont(font); - - if (mInternalListBox) - mListBox->setFont(font); - - Widget::setFont(font); - } - - void DropDown::mouseWheelMovedUp(MouseEvent& mouseEvent) - { - if (isFocused() && mouseEvent.getSource() == this) - { - mouseEvent.consume(); - - if (mListBox->getSelected() > 0) - mListBox->setSelected(mListBox->getSelected() - 1); - } - } - - void DropDown::mouseWheelMovedDown(MouseEvent& mouseEvent) - { - if (isFocused() && mouseEvent.getSource() == this) - { - mouseEvent.consume(); - - mListBox->setSelected(mListBox->getSelected() + 1); - } - } - - void DropDown::setSelectionColor(const Color& color) - { - Widget::setSelectionColor(color); - - if (mInternalListBox) - mListBox->setSelectionColor(color); - } - - void DropDown::valueChanged(const SelectionEvent& event A_UNUSED) - { - distributeValueChangedEvent(); - } - - void DropDown::addSelectionListener(SelectionListener* selectionListener) - { - mSelectionListeners.push_back(selectionListener); - } - - void DropDown::removeSelectionListener(SelectionListener* listener) - { - mSelectionListeners.remove(listener); - } - - void DropDown::distributeValueChangedEvent() - { - SelectionListenerIterator iter; - - for (iter = mSelectionListeners.begin(); - iter != mSelectionListeners.end(); - ++iter) - { - SelectionEvent event(this); - (*iter)->valueChanged(event); - } - } -} - diff --git a/src/guichan/widgets/icon.cpp b/src/guichan/widgets/icon.cpp deleted file mode 100644 index 2983c7c29..000000000 --- a/src/guichan/widgets/icon.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/icon.hpp" - -#include "guichan/graphics.hpp" -#include "guichan/image.hpp" -#include "guichan/rectangle.hpp" - -#include "debug.h" - -namespace gcn -{ - Icon::Icon() - : mImage(0) - , mInternalImage(false) - { - setSize(0, 0); - } - - Icon::Icon(const std::string& filename) - : mImage(0), - mInternalImage(false) - { - mImage = Image::load(filename); - mInternalImage = true; - setSize(mImage->getWidth(), - mImage->getHeight()); - } - - Icon::Icon(const Image* image) - : mImage(image), - mInternalImage(false) - { - setSize(mImage->getWidth(), - mImage->getHeight()); - } - - Icon::~Icon() - { - if (mInternalImage) - { - delete mImage; - mImage = 0; - } - } - - void Icon::setImage(const Image* image) - { - if (mInternalImage) - delete mImage; - - mImage = image; - mInternalImage = false; - setSize(mImage->getWidth(), - mImage->getHeight()); - } - - const Image* Icon::getImage() const - { - return mImage; - } - - void Icon::draw(Graphics* graphics) - { - if (mImage != NULL) - { - const int x = (getWidth() - mImage->getWidth()) / 2; - const int y = (getHeight() - mImage->getHeight()) / 2; - graphics->drawImage(mImage, x, y); - } - } -} diff --git a/src/guichan/widgets/imagebutton.cpp b/src/guichan/widgets/imagebutton.cpp deleted file mode 100644 index 2f4c5dcde..000000000 --- a/src/guichan/widgets/imagebutton.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/imagebutton.hpp" - -#include "guichan/graphics.hpp" -#include "guichan/image.hpp" - -#include "debug.h" - -namespace gcn -{ - ImageButton::ImageButton() : - mImage(0), - mInternalImage(false) - { - setWidth(0); - setHeight(0); - } - - ImageButton::ImageButton(const std::string& filename) : - mImage(0), - mInternalImage(false) - { - mImage = Image::load(filename); - mInternalImage = true; - setWidth(mImage->getWidth() + mImage->getWidth() / 2); - setHeight(mImage->getHeight() + mImage->getHeight() / 2); - } - - ImageButton::ImageButton(const Image* image) : - mImage(image), - mInternalImage(false) - { - setWidth(mImage->getWidth() + mImage->getWidth() / 2); - setHeight(mImage->getHeight() + mImage->getHeight() / 2); - } - - ImageButton::~ImageButton() - { - if (mInternalImage) - { - delete mImage; - mImage = 0; - } - } - - void ImageButton::setImage(const Image* image) - { - if (mInternalImage) - { - delete mImage; - mImage = 0; - } - - mImage = image; - mInternalImage = false; - } - - const Image* ImageButton::getImage() const - { - return mImage; - } - - void ImageButton::draw(Graphics* graphics) - { - gcn::Color faceColor = getBaseColor(); - gcn::Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - - if (isPressed()) - { - faceColor = faceColor - 0x303030; - faceColor.a = alpha; - highlightColor = faceColor - 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor + 0x303030; - shadowColor.a = alpha; - } - else - { - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - } - - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(1, 1, - getDimension().width - 1, getHeight() - 1)); - - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, getWidth() - 1, 0); - graphics->drawLine(0, 1, 0, getHeight() - 1); - - graphics->setColor(shadowColor); - graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1); - graphics->drawLine(1, getHeight() - 1, - getWidth() - 1, getHeight() - 1); - - graphics->setColor(getForegroundColor()); - - const int textX = (getWidth() - (mImage - ? mImage->getWidth() : 0) ) / 2; - const int textY = (getHeight() - (mImage - ? mImage->getHeight() : 0) ) / 2; - - if (isPressed()) - { - if (mImage) - graphics->drawImage(mImage, textX + 1, textY + 1); - } - else - { - if (mImage) - graphics->drawImage(mImage, textX, textY); - - if (isFocused()) - { - graphics->drawRectangle(Rectangle(2, 2, - getWidth() - 4, getHeight() - 4)); - } - } - } -} diff --git a/src/guichan/widgets/label.cpp b/src/guichan/widgets/label.cpp deleted file mode 100644 index a5c967e2b..000000000 --- a/src/guichan/widgets/label.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/label.hpp" - -#include "guichan/exception.hpp" -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" - -#include "debug.h" - -namespace gcn -{ - Label::Label() - { - mAlignment = Graphics::LEFT; - } - - Label::Label(const std::string& caption) - { - mCaption = caption; - mAlignment = Graphics::LEFT; - - setWidth(getFont()->getWidth(caption)); - setHeight(getFont()->getHeight()); - } - - const std::string &Label::getCaption() const - { - return mCaption; - } - - void Label::setCaption(const std::string& caption) - { - mCaption = caption; - } - - void Label::setAlignment(Graphics::Alignment alignment) - { - mAlignment = alignment; - } - - Graphics::Alignment Label::getAlignment() const - { - return mAlignment; - } - - void Label::draw(Graphics* graphics) - { - int textX; - int textY = getHeight() / 2 - getFont()->getHeight() / 2; - - switch (getAlignment()) - { - case Graphics::LEFT: - textX = 0; - break; - case Graphics::CENTER: - textX = getWidth() / 2; - break; - case Graphics::RIGHT: - textX = getWidth(); - break; - default: - throw GCN_EXCEPTION("Unknown alignment."); - } - - graphics->setFont(getFont()); - graphics->setColor(getForegroundColor()); - graphics->drawText(getCaption(), textX, textY, getAlignment()); - } - - void Label::adjustSize() - { - setWidth(getFont()->getWidth(getCaption())); - setHeight(getFont()->getHeight()); - } -} diff --git a/src/guichan/widgets/listbox.cpp b/src/guichan/widgets/listbox.cpp deleted file mode 100644 index 95f04fc68..000000000 --- a/src/guichan/widgets/listbox.cpp +++ /dev/null @@ -1,330 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/listbox.hpp" - -#include "guichan/basiccontainer.hpp" -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" -#include "guichan/key.hpp" -#include "guichan/listmodel.hpp" -#include "guichan/mouseinput.hpp" -#include "guichan/selectionlistener.hpp" - -#include "debug.h" - -namespace gcn -{ - ListBox::ListBox() : - mSelected(-1), - mListModel(NULL), - mWrappingEnabled(false) - { - setWidth(100); - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - } - - ListBox::ListBox(ListModel *listModel) : - mSelected(-1), - mWrappingEnabled(false) - { - setWidth(100); - setListModel(listModel); - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - } - - void ListBox::draw(Graphics* graphics) - { - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - - if (mListModel == NULL) - return; - - graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); - - // Check the current clip area so we don't draw unnecessary items - // that are not visible. - const ClipRectangle currentClipArea = graphics->getCurrentClipArea(); - int rowHeight = getRowHeight(); - - // Calculate the number of rows to draw by checking the clip area. - // The addition of two makes covers a partial visible row at the top - // and a partial visible row at the bottom. - int numberOfRows = currentClipArea.height / rowHeight + 2; - - if (numberOfRows > mListModel->getNumberOfElements()) - numberOfRows = mListModel->getNumberOfElements(); - - // Calculate which row to start drawing. If the list box - // has a negative y coordinate value we should check if - // we should drop rows in the begining of the list as - // they might not be visible. A negative y value is very - // common if the list box for instance resides in a scroll - // area and the user has scrolled the list box downwards. - int startRow; - if (getY() < 0) - startRow = -1 * (getY() / rowHeight); - else - startRow = 0; - - int i; - // The y coordinate where we start to draw the text is - // simply the y coordinate multiplied with the font height. - int y = rowHeight * startRow; - for (i = startRow; i < startRow + numberOfRows; ++i) - { - if (i == mSelected) - { - graphics->setColor(getSelectionColor()); - graphics->fillRectangle(Rectangle(0, y, - getWidth(), rowHeight)); - graphics->setColor(getForegroundColor()); - } - - // If the row height is greater than the font height we - // draw the text with a center vertical alignment. - if (rowHeight > getFont()->getHeight()) - { - graphics->drawText(mListModel->getElementAt(i), 1, - y + rowHeight / 2 - getFont()->getHeight() / 2); - } - else - { - graphics->drawText(mListModel->getElementAt(i), 1, y); - } - - y += rowHeight; - } - } - - void ListBox::logic() - { - adjustSize(); - } - - int ListBox::getSelected() const - { - return mSelected; - } - - void ListBox::setSelected(int selected) - { - if (mListModel == NULL) - { - mSelected = -1; - } - else - { - if (selected < 0) - mSelected = -1; - else if (selected >= mListModel->getNumberOfElements()) - mSelected = mListModel->getNumberOfElements() - 1; - else - mSelected = selected; - } - - Rectangle scroll; - - if (mSelected < 0) - scroll.y = 0; - else - scroll.y = getRowHeight() * mSelected; - - scroll.height = getRowHeight(); - showPart(scroll); - - distributeValueChangedEvent(); - } - - void ListBox::keyPressed(KeyEvent& keyEvent) - { - Key key = keyEvent.getKey(); - - if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) - { - distributeActionEvent(); - keyEvent.consume(); - } - else if (key.getValue() == Key::UP) - { - setSelected(mSelected - 1); - - if (mSelected == -1) - { - if (mWrappingEnabled) - setSelected(getListModel()->getNumberOfElements() - 1); - else - setSelected(0); - } - - keyEvent.consume(); - } - else if (key.getValue() == Key::DOWN) - { - if (mWrappingEnabled - && getSelected() == getListModel()->getNumberOfElements() - 1) - { - setSelected(0); - } - else - { - setSelected(getSelected() + 1); - } - - keyEvent.consume(); - } - else if (key.getValue() == Key::HOME) - { - setSelected(0); - keyEvent.consume(); - } - else if (key.getValue() == Key::END) - { - setSelected(getListModel()->getNumberOfElements() - 1); - keyEvent.consume(); - } - } - - void ListBox::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - setSelected(mouseEvent.getY() / getRowHeight()); - distributeActionEvent(); - } - } - - void ListBox::mouseWheelMovedUp(MouseEvent& mouseEvent) - { - if (isFocused()) - { - if (getSelected() > 0 ) - setSelected(getSelected() - 1); - - mouseEvent.consume(); - } - } - - void ListBox::mouseWheelMovedDown(MouseEvent& mouseEvent) - { - if (isFocused()) - { - setSelected(getSelected() + 1); - - mouseEvent.consume(); - } - } - - void ListBox::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } - - void ListBox::setListModel(ListModel *listModel) - { - mSelected = -1; - mListModel = listModel; - adjustSize(); - } - - ListModel* ListBox::getListModel() - { - return mListModel; - } - - void ListBox::adjustSize() - { - if (mListModel != NULL) - setHeight(getRowHeight() * mListModel->getNumberOfElements()); - } - - bool ListBox::isWrappingEnabled() const - { - return mWrappingEnabled; - } - - void ListBox::setWrappingEnabled(bool wrappingEnabled) - { - mWrappingEnabled = wrappingEnabled; - } - - void ListBox::addSelectionListener(SelectionListener* selectionListener) - { - mSelectionListeners.push_back(selectionListener); - } - - void ListBox::removeSelectionListener(SelectionListener* selectionListener) - { - mSelectionListeners.remove(selectionListener); - } - - void ListBox::distributeValueChangedEvent() - { - SelectionListenerIterator iter; - - for (iter = mSelectionListeners.begin(); - iter != mSelectionListeners.end(); - ++ iter) - { - SelectionEvent event(this); - (*iter)->valueChanged(event); - } - } - - unsigned int ListBox::getRowHeight() const - { - return getFont()->getHeight(); - } -} diff --git a/src/guichan/widgets/radiobutton.cpp b/src/guichan/widgets/radiobutton.cpp deleted file mode 100644 index 37fd4a0f0..000000000 --- a/src/guichan/widgets/radiobutton.cpp +++ /dev/null @@ -1,278 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/radiobutton.hpp" - -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" -#include "guichan/key.hpp" -#include "guichan/mouseinput.hpp" - -#include "debug.h" - -namespace gcn -{ - RadioButton::GroupMap RadioButton::mGroupMap; - - RadioButton::RadioButton() : - mSelected(false), - mCaption(""), - mGroup("") - { - setSelected(false); - - setFocusable(true); - addMouseListener(this); - addKeyListener(this); - } - - RadioButton::RadioButton(const std::string &caption, - const std::string &group, - bool selected) : - mSelected(false), - mGroup("") - { - setCaption(caption); - setGroup(group); - setSelected(selected); - - setFocusable(true); - addMouseListener(this); - addKeyListener(this); - - adjustSize(); - } - - RadioButton::~RadioButton() - { - // Remove us from the group list - setGroup(""); - } - - void RadioButton::draw(Graphics* graphics) - { - graphics->pushClipArea(Rectangle(1, 1, - getWidth() - 1, getHeight() - 1)); - - drawBox(graphics); - graphics->popClipArea(); - - graphics->setFont(getFont()); - graphics->setColor(getForegroundColor()); - - if (isFocused()) - { - int fh; - - if (getHeight() % 2 == 0) - fh = getHeight() - 4; - else - fh = getHeight() - 3; - - int hh = (fh + 1) / 2; - - graphics->drawLine(0, hh + 1, hh + 1, 0); - graphics->drawLine(hh + 2, 1, fh + 2, hh + 1); - graphics->drawLine(fh + 1, hh + 2, hh + 1, fh + 2); - graphics->drawLine(hh + 1, fh + 2, 1, hh + 2); - } - - int h = getHeight() + getHeight() / 2; - - graphics->drawText(getCaption(), h - 2, 0); - } - - void RadioButton::drawBox(Graphics *graphics) - { - int h; - - if (getHeight() % 2 == 0) - h = getHeight() - 4; - else - h = getHeight() - 3; - - int alpha = getBaseColor().a; - Color faceColor = getBaseColor(); - faceColor.a = alpha; - Color highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - Color shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - graphics->setColor(getBackgroundColor()); - - int i; - int hh = (h + 1) / 2; - - for (i = 1; i <= hh; ++i) - graphics->drawLine(hh - i + 1, i, hh + i - 1, i); - - for (i = 1; i < hh; ++i) - graphics->drawLine(hh - i + 1, h - i, hh + i - 1, h - i); - - graphics->setColor(shadowColor); - graphics->drawLine(hh, 0, 0, hh); - graphics->drawLine(hh + 1, 1, h - 1, hh - 1); - - graphics->setColor(highlightColor); - graphics->drawLine(1, hh + 1, hh, h); - graphics->drawLine(hh + 1, h - 1, h, hh); - - graphics->setColor(getForegroundColor()); - - int hhh = hh - 3; - if (mSelected) - { - for (i = 0; i < hhh; ++i) - graphics->drawLine(hh - i, 4 + i, hh + i, 4 + i); - for (i = 0; i < hhh; ++i) - graphics->drawLine(hh - i, h - 4 - i, hh + i, h - 4 - i); - } - } - - bool RadioButton::isSelected() const - { - return mSelected; - } - - void RadioButton::setSelected(bool selected) - { - if (selected && mGroup != "") - { - GroupIterator iter, iterEnd; - iterEnd = mGroupMap.upper_bound(mGroup); - - for (iter = mGroupMap.lower_bound(mGroup); - iter != iterEnd; - ++ iter) - { - if (iter->second->isSelected()) - iter->second->setSelected(false); - } - } - - mSelected = selected; - } - - const std::string &RadioButton::getCaption() const - { - return mCaption; - } - - void RadioButton::setCaption(const std::string caption) - { - mCaption = caption; - } - - void RadioButton::keyPressed(KeyEvent& keyEvent) - { - Key key = keyEvent.getKey(); - - if (key.getValue() == Key::ENTER || - key.getValue() == Key::SPACE) - { - setSelected(true); - distributeActionEvent(); - keyEvent.consume(); - } - } - - void RadioButton::mouseClicked(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - setSelected(true); - distributeActionEvent(); - } - } - - void RadioButton::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } - - void RadioButton::setGroup(const std::string &group) - { - if (mGroup != "") - { - GroupIterator iter, iterEnd; - iterEnd = mGroupMap.upper_bound(mGroup); - - for (iter = mGroupMap.lower_bound(mGroup); - iter != iterEnd; - ++ iter) - { - if (iter->second == this) - { - mGroupMap.erase(iter); - break; - } - } - } - - if (group != "") - { - mGroupMap.insert( - std::pair<std::string, RadioButton *>(group, this)); - } - - mGroup = group; - } - - const std::string &RadioButton::getGroup() const - { - return mGroup; - } - - void RadioButton::adjustSize() - { - int height = getFont()->getHeight(); - - setHeight(height); - setWidth(getFont()->getWidth(getCaption()) + height + height / 2); - } -} diff --git a/src/guichan/widgets/scrollarea.cpp b/src/guichan/widgets/scrollarea.cpp deleted file mode 100644 index 7dc7566c0..000000000 --- a/src/guichan/widgets/scrollarea.cpp +++ /dev/null @@ -1,1226 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/scrollarea.hpp" - -#include "guichan/exception.hpp" -#include "guichan/graphics.hpp" - -#include "debug.h" - -namespace gcn -{ - ScrollArea::ScrollArea() - { - mVScroll = 0; - mHScroll = 0; - mHPolicy = SHOW_AUTO; - mVPolicy = SHOW_AUTO; - mVBarVisible = false; - mHBarVisible = false; - mScrollbarWidth = 12; - mUpButtonPressed = false; - mDownButtonPressed = false; - mLeftButtonPressed = false; - mRightButtonPressed = false; - mUpButtonScrollAmount = 10; - mDownButtonScrollAmount = 10; - mLeftButtonScrollAmount = 10; - mRightButtonScrollAmount = 10; - mIsVerticalMarkerDragged = false; - mIsHorizontalMarkerDragged = false; - mHorizontalMarkerDragOffset = 0; - mVerticalMarkerDragOffset = 0; - mOpaque = true; - - addMouseListener(this); - } - - ScrollArea::ScrollArea(Widget *content) - { - mVScroll = 0; - mHScroll = 0; - mHPolicy = SHOW_AUTO; - mVPolicy = SHOW_AUTO; - mVBarVisible = false; - mHBarVisible = false; - mScrollbarWidth = 12; - mUpButtonPressed = false; - mDownButtonPressed = false; - mLeftButtonPressed = false; - mRightButtonPressed = false; - mUpButtonScrollAmount = 10; - mDownButtonScrollAmount = 10; - mLeftButtonScrollAmount = 10; - mRightButtonScrollAmount = 10; - mIsVerticalMarkerDragged = false; - mIsHorizontalMarkerDragged = false; - mHorizontalMarkerDragOffset = 0; - mVerticalMarkerDragOffset = 0; - mOpaque = true; - - setContent(content); - addMouseListener(this); - } - - ScrollArea::ScrollArea(Widget *content, - ScrollPolicy hPolicy, - ScrollPolicy vPolicy) - { - mVScroll = 0; - mHScroll = 0; - mHPolicy = hPolicy; - mVPolicy = vPolicy; - mScrollbarWidth = 12; - mVBarVisible = false; - mHBarVisible = false; - mUpButtonPressed = false; - mDownButtonPressed = false; - mLeftButtonPressed = false; - mRightButtonPressed = false; - mUpButtonScrollAmount = 10; - mDownButtonScrollAmount = 10; - mLeftButtonScrollAmount = 10; - mRightButtonScrollAmount = 10; - mIsVerticalMarkerDragged = false; - mIsHorizontalMarkerDragged = false; - mHorizontalMarkerDragOffset = 0; - mVerticalMarkerDragOffset = 0; - mOpaque = true; - - setContent(content); - addMouseListener(this); - } - - ScrollArea::~ScrollArea() - { - setContent(NULL); - } - - void ScrollArea::setContent(Widget* widget) - { - if (widget != NULL) - { - clear(); - add(widget); - widget->setPosition(0, 0); - } - else - { - clear(); - } - - checkPolicies(); - } - - Widget* ScrollArea::getContent() - { - if (!mWidgets.empty()) - return *mWidgets.begin(); - - return NULL; - } - - void ScrollArea::setHorizontalScrollPolicy(ScrollPolicy hPolicy) - { - mHPolicy = hPolicy; - checkPolicies(); - } - - ScrollArea::ScrollPolicy ScrollArea::getHorizontalScrollPolicy() const - { - return mHPolicy; - } - - void ScrollArea::setVerticalScrollPolicy(ScrollPolicy vPolicy) - { - mVPolicy = vPolicy; - checkPolicies(); - } - - ScrollArea::ScrollPolicy ScrollArea::getVerticalScrollPolicy() const - { - return mVPolicy; - } - - void ScrollArea::setScrollPolicy(ScrollPolicy hPolicy, - ScrollPolicy vPolicy) - { - mHPolicy = hPolicy; - mVPolicy = vPolicy; - checkPolicies(); - } - - void ScrollArea::setVerticalScrollAmount(int vScroll) - { - int max = getVerticalMaxScroll(); - - mVScroll = vScroll; - - if (vScroll > max) - mVScroll = max; - - if (vScroll < 0) - mVScroll = 0; - } - - int ScrollArea::getVerticalScrollAmount() const - { - return mVScroll; - } - - void ScrollArea::setHorizontalScrollAmount(int hScroll) - { - int max = getHorizontalMaxScroll(); - - mHScroll = hScroll; - - if (hScroll > max) - mHScroll = max; - else if (hScroll < 0) - mHScroll = 0; - } - - int ScrollArea::getHorizontalScrollAmount() const - { - return mHScroll; - } - - void ScrollArea::setScrollAmount(int hScroll, int vScroll) - { - setHorizontalScrollAmount(hScroll); - setVerticalScrollAmount(vScroll); - } - - int ScrollArea::getHorizontalMaxScroll() - { - checkPolicies(); - - if (getContent() == NULL) - return 0; - - int value = getContent()->getWidth() - getChildrenArea().width + - 2 * getContent()->getFrameSize(); - - if (value < 0) - return 0; - - return value; - } - - int ScrollArea::getVerticalMaxScroll() - { - checkPolicies(); - - if (getContent() == NULL) - return 0; - - int value; - - value = getContent()->getHeight() - getChildrenArea().height + - 2 * getContent()->getFrameSize(); - - if (value < 0) - return 0; - - return value; - } - - void ScrollArea::setScrollbarWidth(int width) - { - if (width > 0) - mScrollbarWidth = width; - else - throw GCN_EXCEPTION("Width should be greater then 0."); - } - - int ScrollArea::getScrollbarWidth() const - { - return mScrollbarWidth; - } - - void ScrollArea::mousePressed(MouseEvent& mouseEvent) - { - int x = mouseEvent.getX(); - int y = mouseEvent.getY(); - - if (getUpButtonDimension().isPointInRect(x, y)) - { - setVerticalScrollAmount(getVerticalScrollAmount() - - mUpButtonScrollAmount); - mUpButtonPressed = true; - } - else if (getDownButtonDimension().isPointInRect(x, y)) - { - setVerticalScrollAmount(getVerticalScrollAmount() - + mDownButtonScrollAmount); - mDownButtonPressed = true; - } - else if (getLeftButtonDimension().isPointInRect(x, y)) - { - setHorizontalScrollAmount(getHorizontalScrollAmount() - - mLeftButtonScrollAmount); - mLeftButtonPressed = true; - } - else if (getRightButtonDimension().isPointInRect(x, y)) - { - setHorizontalScrollAmount(getHorizontalScrollAmount() - + mRightButtonScrollAmount); - mRightButtonPressed = true; - } - else if (getVerticalMarkerDimension().isPointInRect(x, y)) - { - mIsHorizontalMarkerDragged = false; - mIsVerticalMarkerDragged = true; - - mVerticalMarkerDragOffset = y - getVerticalMarkerDimension().y; - } - else if (getVerticalBarDimension().isPointInRect(x, y)) - { - if (y < getVerticalMarkerDimension().y) - { - setVerticalScrollAmount(getVerticalScrollAmount() - - (int)(getChildrenArea().height * 0.95)); - } - else - { - setVerticalScrollAmount(getVerticalScrollAmount() - + (int)(getChildrenArea().height * 0.95)); - } - } - else if (getHorizontalMarkerDimension().isPointInRect(x, y)) - { - mIsHorizontalMarkerDragged = true; - mIsVerticalMarkerDragged = false; - - mHorizontalMarkerDragOffset = x - getHorizontalMarkerDimension().x; - } - else if (getHorizontalBarDimension().isPointInRect(x, y)) - { - if (x < getHorizontalMarkerDimension().x) - { - setHorizontalScrollAmount(getHorizontalScrollAmount() - - (int)(getChildrenArea().width * 0.95)); - } - else - { - setHorizontalScrollAmount(getHorizontalScrollAmount() - + (int)(getChildrenArea().width * 0.95)); - } - } - } - - void ScrollArea::mouseReleased(MouseEvent& mouseEvent) - { - mUpButtonPressed = false; - mDownButtonPressed = false; - mLeftButtonPressed = false; - mRightButtonPressed = false; - mIsHorizontalMarkerDragged = false; - mIsVerticalMarkerDragged = false; - - mouseEvent.consume(); - } - - void ScrollArea::mouseDragged(MouseEvent& mouseEvent) - { - if (mIsVerticalMarkerDragged) - { - Rectangle barDim = getVerticalBarDimension(); - - int pos = mouseEvent.getY() - barDim.y - - mVerticalMarkerDragOffset; - int length = getVerticalMarkerDimension().height; - - if ((barDim.height - length) > 0) - { - setVerticalScrollAmount((getVerticalMaxScroll() * pos) - / (barDim.height - length)); - } - else - { - setVerticalScrollAmount(0); - } - } - - if (mIsHorizontalMarkerDragged) - { - Rectangle barDim = getHorizontalBarDimension(); - - int pos = mouseEvent.getX() - barDim.x - - mHorizontalMarkerDragOffset; - int length = getHorizontalMarkerDimension().width; - - if ((barDim.width - length) > 0) - { - setHorizontalScrollAmount((getHorizontalMaxScroll() * pos) - / (barDim.width - length)); - } - else - { - setHorizontalScrollAmount(0); - } - } - - mouseEvent.consume(); - } - - void ScrollArea::draw(Graphics *graphics) - { - drawBackground(graphics); - - if (mVBarVisible) - { - drawUpButton(graphics); - drawDownButton(graphics); - drawVBar(graphics); - drawVMarker(graphics); - } - - if (mHBarVisible) - { - drawLeftButton(graphics); - drawRightButton(graphics); - drawHBar(graphics); - drawHMarker(graphics); - } - - if (mHBarVisible && mVBarVisible) - { - graphics->setColor(getBaseColor()); - graphics->fillRectangle(Rectangle(getWidth() - mScrollbarWidth, - getHeight() - mScrollbarWidth, - mScrollbarWidth, mScrollbarWidth)); - } - - drawChildren(graphics); - } - - void ScrollArea::drawHBar(Graphics* graphics) - { - Rectangle dim = getHorizontalBarDimension(); - - graphics->pushClipArea(dim); - - int alpha = getBaseColor().a; - Color trackColor = getBaseColor() - 0x101010; - trackColor.a = alpha; - Color shadowColor = getBaseColor() - 0x303030; - shadowColor.a = alpha; - - graphics->setColor(trackColor); - graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); - - graphics->setColor(shadowColor); - graphics->drawLine(0, 0, dim.width, 0); - - graphics->popClipArea(); - } - - void ScrollArea::drawVBar(Graphics* graphics) - { - Rectangle dim = getVerticalBarDimension(); - - graphics->pushClipArea(dim); - - int alpha = getBaseColor().a; - Color trackColor = getBaseColor() - 0x101010; - trackColor.a = alpha; - Color shadowColor = getBaseColor() - 0x303030; - shadowColor.a = alpha; - - graphics->setColor(trackColor); - graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); - - graphics->setColor(shadowColor); - graphics->drawLine(0, 0, 0, dim.height); - - graphics->popClipArea(); - } - - void ScrollArea::drawBackground(Graphics *graphics) - { - if (isOpaque()) - { - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(getChildrenArea()); - } - } - - void ScrollArea::drawUpButton(Graphics* graphics) - { - Rectangle dim = getUpButtonDimension(); - graphics->pushClipArea(dim); - - Color highlightColor; - Color shadowColor; - Color faceColor; - int offset; - int alpha = getBaseColor().a; - - if (mUpButtonPressed) - { - faceColor = getBaseColor() - 0x303030; - faceColor.a = alpha; - highlightColor = faceColor - 0x303030; - highlightColor.a = alpha; - shadowColor = getBaseColor(); - shadowColor.a = alpha; - - offset = 1; - } - else - { - faceColor = getBaseColor(); - faceColor.a = alpha; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - offset = 0; - } - - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); - - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, dim.width - 1, 0); - graphics->drawLine(0, 1, 0, dim.height - 1); - - graphics->setColor(shadowColor); - graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); - graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); - - graphics->setColor(getForegroundColor()); - - int i; - int w = dim.height / 2; - int h = w / 2 + 2; - for (i = 0; i < w / 2; ++i) - { - graphics->drawLine(w - i + offset, i + h + offset, - w + i + offset, i + h + offset); - } - - graphics->popClipArea(); - } - - void ScrollArea::drawDownButton(Graphics* graphics) - { - Rectangle dim = getDownButtonDimension(); - graphics->pushClipArea(dim); - - Color highlightColor; - Color shadowColor; - Color faceColor; - int offset; - int alpha = getBaseColor().a; - - if (mDownButtonPressed) - { - faceColor = getBaseColor() - 0x303030; - faceColor.a = alpha; - highlightColor = faceColor - 0x303030; - highlightColor.a = alpha; - shadowColor = getBaseColor(); - shadowColor.a = alpha; - - offset = 1; - } - else - { - faceColor = getBaseColor(); - faceColor.a = alpha; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - offset = 0; - } - - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); - - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, dim.width - 1, 0); - graphics->drawLine(0, 1, 0, dim.height - 1); - - graphics->setColor(shadowColor); - graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); - graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); - - graphics->setColor(getForegroundColor()); - - int i; - int w = dim.height / 2; - int h = w + 1; - for (i = 0; i < w / 2; ++i) - { - graphics->drawLine(w - i + offset, -i + h + offset, - w + i + offset, -i + h + offset); - } - - graphics->popClipArea(); - } - - void ScrollArea::drawLeftButton(Graphics* graphics) - { - Rectangle dim = getLeftButtonDimension(); - graphics->pushClipArea(dim); - - Color highlightColor; - Color shadowColor; - Color faceColor; - int offset; - int alpha = getBaseColor().a; - - if (mLeftButtonPressed) - { - faceColor = getBaseColor() - 0x303030; - faceColor.a = alpha; - highlightColor = faceColor - 0x303030; - highlightColor.a = alpha; - shadowColor = getBaseColor(); - shadowColor.a = alpha; - - offset = 1; - } - else - { - faceColor = getBaseColor(); - faceColor.a = alpha; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - offset = 0; - } - - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); - - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, dim.width - 1, 0); - graphics->drawLine(0, 1, 0, dim.height - 1); - - graphics->setColor(shadowColor); - graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); - graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); - - graphics->setColor(getForegroundColor()); - - int i; - int w = dim.width / 2; - int h = w - 2; - for (i = 0; i < w / 2; ++i) - { - graphics->drawLine(i + h + offset, w - i + offset, - i + h + offset, w + i + offset); - } - - graphics->popClipArea(); - } - - void ScrollArea::drawRightButton(Graphics* graphics) - { - Rectangle dim = getRightButtonDimension(); - graphics->pushClipArea(dim); - - Color highlightColor; - Color shadowColor; - Color faceColor; - int offset; - int alpha = getBaseColor().a; - - if (mRightButtonPressed) - { - faceColor = getBaseColor() - 0x303030; - faceColor.a = alpha; - highlightColor = faceColor - 0x303030; - highlightColor.a = alpha; - shadowColor = getBaseColor(); - shadowColor.a = alpha; - - offset = 1; - } - else - { - faceColor = getBaseColor(); - faceColor.a = alpha; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - offset = 0; - } - - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); - - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, dim.width - 1, 0); - graphics->drawLine(0, 1, 0, dim.height - 1); - - graphics->setColor(shadowColor); - graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); - graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); - - graphics->setColor(getForegroundColor()); - - int i; - int w = dim.width / 2; - int h = w + 1; - for (i = 0; i < w / 2; ++i) - { - graphics->drawLine(-i + h + offset, w - i + offset, - -i + h + offset, w + i + offset); - } - - graphics->popClipArea(); - } - - void ScrollArea::drawVMarker(Graphics* graphics) - { - Rectangle dim = getVerticalMarkerDimension(); - graphics->pushClipArea(dim); - - int alpha = getBaseColor().a; - Color faceColor = getBaseColor(); - faceColor.a = alpha; - Color highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - Color shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(1, 1, - dim.width - 1, dim.height - 1)); - - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, dim.width - 1, 0); - graphics->drawLine(0, 1, 0, dim.height - 1); - - graphics->setColor(shadowColor); - graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); - graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); - - graphics->popClipArea(); - } - - void ScrollArea::drawHMarker(Graphics* graphics) - { - Rectangle dim = getHorizontalMarkerDimension(); - graphics->pushClipArea(dim); - - int alpha = getBaseColor().a; - Color faceColor = getBaseColor(); - faceColor.a = alpha; - Color highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - Color shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(1, 1, - dim.width - 1, dim.height - 1)); - - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, dim.width - 1, 0); - graphics->drawLine(0, 1, 0, dim.height - 1); - - graphics->setColor(shadowColor); - graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); - graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); - - graphics->popClipArea(); - } - - void ScrollArea::logic() - { - checkPolicies(); - - setVerticalScrollAmount(getVerticalScrollAmount()); - setHorizontalScrollAmount(getHorizontalScrollAmount()); - - if (getContent() != NULL) - { - getContent()->setPosition(-mHScroll + getContent()->getFrameSize(), - -mVScroll + getContent()->getFrameSize()); - getContent()->logic(); - } - } - - void ScrollArea::checkPolicies() - { - int w = getWidth(); - int h = getHeight(); - - mHBarVisible = false; - mVBarVisible = false; - - - if (!getContent()) - { - mHBarVisible = (mHPolicy == SHOW_ALWAYS); - mVBarVisible = (mVPolicy == SHOW_ALWAYS); - return; - } - - if (mHPolicy == SHOW_AUTO && - mVPolicy == SHOW_AUTO) - { - if (getContent()->getWidth() <= w - && getContent()->getHeight() <= h) - { - mHBarVisible = false; - mVBarVisible = false; - } - - if (getContent()->getWidth() > w) - { - mHBarVisible = true; - } - - if ((getContent()->getHeight() > h) - || (mHBarVisible && getContent()->getHeight() - > h - mScrollbarWidth)) - { - mVBarVisible = true; - } - - if (mVBarVisible && getContent()->getWidth() > w - mScrollbarWidth) - mHBarVisible = true; - - return; - } - - switch (mHPolicy) - { - case SHOW_NEVER: - mHBarVisible = false; - break; - - case SHOW_ALWAYS: - mHBarVisible = true; - break; - - case SHOW_AUTO: - if (mVPolicy == SHOW_NEVER) - { - mHBarVisible = (getContent()->getWidth() > w); - } - else // (mVPolicy == SHOW_ALWAYS) - { - mHBarVisible = (getContent()->getWidth() - > w - mScrollbarWidth); - } - break; - - default: - throw GCN_EXCEPTION("Horizontal scroll policy invalid."); - } - - switch (mVPolicy) - { - case SHOW_NEVER: - mVBarVisible = false; - break; - - case SHOW_ALWAYS: - mVBarVisible = true; - break; - - case SHOW_AUTO: - if (mHPolicy == SHOW_NEVER) - { - mVBarVisible = (getContent()->getHeight() > h); - } - else // (mHPolicy == SHOW_ALWAYS) - { - mVBarVisible = (getContent()->getHeight() - > h - mScrollbarWidth); - } - break; - default: - throw GCN_EXCEPTION("Vertical scroll policy invalid."); - } - } - - Rectangle ScrollArea::getUpButtonDimension() const - { - if (!mVBarVisible) - return Rectangle(0, 0, 0, 0); - - return Rectangle(getWidth() - mScrollbarWidth, 0, - mScrollbarWidth, mScrollbarWidth); - } - - Rectangle ScrollArea::getDownButtonDimension() const - { - if (!mVBarVisible) - return Rectangle(0, 0, 0, 0); - - if (mVBarVisible && mHBarVisible) - { - return Rectangle(getWidth() - mScrollbarWidth, - getHeight() - mScrollbarWidth*2, - mScrollbarWidth, - mScrollbarWidth); - } - - return Rectangle(getWidth() - mScrollbarWidth, - getHeight() - mScrollbarWidth, - mScrollbarWidth, - mScrollbarWidth); - } - - Rectangle ScrollArea::getLeftButtonDimension() const - { - if (!mHBarVisible) - return Rectangle(0, 0, 0, 0); - - return Rectangle(0, getHeight() - mScrollbarWidth, - mScrollbarWidth, mScrollbarWidth); - } - - Rectangle ScrollArea::getRightButtonDimension() const - { - if (!mHBarVisible) - return Rectangle(0, 0, 0, 0); - - if (mVBarVisible && mHBarVisible) - { - return Rectangle(getWidth() - mScrollbarWidth*2, - getHeight() - mScrollbarWidth, - mScrollbarWidth, - mScrollbarWidth); - } - - return Rectangle(getWidth() - mScrollbarWidth, - getHeight() - mScrollbarWidth, - mScrollbarWidth, - mScrollbarWidth); - } - - Rectangle ScrollArea::getChildrenArea() - { - Rectangle area = Rectangle(0, 0, - mVBarVisible ? (getWidth() - mScrollbarWidth) : getWidth(), - mHBarVisible ? (getHeight() - mScrollbarWidth) : getHeight()); - - if (area.width < 0 || area.height < 0) - return Rectangle(); - - return area; - } - - Rectangle ScrollArea::getVerticalBarDimension() const - { - if (!mVBarVisible) - return Rectangle(0, 0, 0, 0); - - if (mHBarVisible) - { - return Rectangle(getWidth() - mScrollbarWidth, - getUpButtonDimension().height, - mScrollbarWidth, - getHeight() - - getUpButtonDimension().height - - getDownButtonDimension().height - - mScrollbarWidth); - } - - return Rectangle(getWidth() - mScrollbarWidth, - getUpButtonDimension().height, - mScrollbarWidth, - getHeight() - - getUpButtonDimension().height - - getDownButtonDimension().height); - } - - Rectangle ScrollArea::getHorizontalBarDimension() const - { - if (!mHBarVisible) - return Rectangle(0, 0, 0, 0); - - if (mVBarVisible) - { - return Rectangle(getLeftButtonDimension().width, - getHeight() - mScrollbarWidth, - getWidth() - - getLeftButtonDimension().width - - getRightButtonDimension().width - - mScrollbarWidth, - mScrollbarWidth); - } - - return Rectangle(getLeftButtonDimension().width, - getHeight() - mScrollbarWidth, - getWidth() - - getLeftButtonDimension().width - - getRightButtonDimension().width, - mScrollbarWidth); - } - - Rectangle ScrollArea::getVerticalMarkerDimension() - { - if (!mVBarVisible) - return Rectangle(0, 0, 0, 0); - - int length, pos; - int height; - - if (mHBarVisible) - { - height = getHeight() - getUpButtonDimension().height - - getDownButtonDimension().height - mScrollbarWidth; - } - else - { - height = getHeight() - getUpButtonDimension().height - - getDownButtonDimension().height; - } - - if (getContent() && getContent()->getHeight() != 0) - { - length = (height * getChildrenArea().height) - / getContent()->getHeight(); - } - else - { - length = height; - } - - if (length < mScrollbarWidth) - length = mScrollbarWidth; - - if (length > height) - length = height; - - if (getVerticalMaxScroll() != 0) - { - pos = ((height - length) * getVerticalScrollAmount()) - / getVerticalMaxScroll(); - } - else - { - pos = 0; - } - - return Rectangle(getWidth() - mScrollbarWidth, - getUpButtonDimension().height + pos, mScrollbarWidth, length); - } - - Rectangle ScrollArea::getHorizontalMarkerDimension() - { - if (!mHBarVisible) - return Rectangle(0, 0, 0, 0); - - int length, pos; - int width; - - if (mVBarVisible) - { - width = getWidth() - getLeftButtonDimension().width - - getRightButtonDimension().width - mScrollbarWidth; - } - else - { - width = getWidth() - getLeftButtonDimension().width - - getRightButtonDimension().width; - } - - if (getContent() && getContent()->getWidth() != 0) - { - length = (width * getChildrenArea().width) - / getContent()->getWidth(); - } - else - { - length = width; - } - - if (length < mScrollbarWidth) - length = mScrollbarWidth; - - if (length > width) - length = width; - - if (getHorizontalMaxScroll() != 0) - { - pos = ((width - length) * getHorizontalScrollAmount()) - / getHorizontalMaxScroll(); - } - else - { - pos = 0; - } - - return Rectangle(getLeftButtonDimension().width + pos, - getHeight() - mScrollbarWidth, length, mScrollbarWidth); - } - - void ScrollArea::showWidgetPart(Widget* widget, Rectangle area) - { - if (widget != getContent()) - throw GCN_EXCEPTION("Widget not content widget"); - - BasicContainer::showWidgetPart(widget, area); - - setHorizontalScrollAmount(getContent()->getFrameSize() - - getContent()->getX()); - setVerticalScrollAmount(getContent()->getFrameSize() - - getContent()->getY()); - } - - Widget *ScrollArea::getWidgetAt(int x, int y) - { - if (getChildrenArea().isPointInRect(x, y)) - return getContent(); - - return NULL; - } - - void ScrollArea::mouseWheelMovedUp(MouseEvent& mouseEvent) - { - if (mouseEvent.isConsumed()) - return; - - setVerticalScrollAmount(getVerticalScrollAmount() - - getChildrenArea().height / 8); - - mouseEvent.consume(); - } - - void ScrollArea::mouseWheelMovedDown(MouseEvent& mouseEvent) - { - if (mouseEvent.isConsumed()) - return; - - setVerticalScrollAmount(getVerticalScrollAmount() - + getChildrenArea().height / 8); - - mouseEvent.consume(); - } - - void ScrollArea::setWidth(int width) - { - Widget::setWidth(width); - checkPolicies(); - } - - void ScrollArea::setHeight(int height) - { - Widget::setHeight(height); - checkPolicies(); - } - - void ScrollArea::setDimension(const Rectangle& dimension) - { - Widget::setDimension(dimension); - checkPolicies(); - } - - void ScrollArea::setLeftButtonScrollAmount(int amount) - { - mLeftButtonScrollAmount = amount; - } - - void ScrollArea::setRightButtonScrollAmount(int amount) - { - mRightButtonScrollAmount = amount; - } - - void ScrollArea::setUpButtonScrollAmount(int amount) - { - mUpButtonScrollAmount = amount; - } - - void ScrollArea::setDownButtonScrollAmount(int amount) - { - mDownButtonScrollAmount = amount; - } - - int ScrollArea::getLeftButtonScrollAmount() const - { - return mLeftButtonScrollAmount; - } - - int ScrollArea::getRightButtonScrollAmount() const - { - return mRightButtonScrollAmount; - } - - int ScrollArea::getUpButtonScrollAmount() const - { - return mUpButtonScrollAmount; - } - - int ScrollArea::getDownButtonScrollAmount() const - { - return mDownButtonScrollAmount; - } - - void ScrollArea::setOpaque(bool opaque) - { - mOpaque = opaque; - } - - - bool ScrollArea::isOpaque() const - { - return mOpaque; - } -} - -/* - * Wow! This is a looooong source file. - */ diff --git a/src/guichan/widgets/slider.cpp b/src/guichan/widgets/slider.cpp deleted file mode 100644 index eba88382c..000000000 --- a/src/guichan/widgets/slider.cpp +++ /dev/null @@ -1,370 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/slider.hpp" - -#include "guichan/graphics.hpp" -#include "guichan/key.hpp" -#include "guichan/mouseinput.hpp" - -#include "debug.h" - -namespace gcn -{ - Slider::Slider(double scaleEnd) - { - mDragged = false; - - mScaleStart = 0; - mScaleEnd = scaleEnd; - - setFocusable(true); - setFrameSize(1); - setOrientation(HORIZONTAL); - setValue(0); - setStepLength(scaleEnd / 10); - setMarkerLength(10); - - addMouseListener(this); - addKeyListener(this); - } - - Slider::Slider(double scaleStart, double scaleEnd) - { - mDragged = false; - - mScaleStart = scaleStart; - mScaleEnd = scaleEnd; - - setFocusable(true); - setFrameSize(1); - setOrientation(HORIZONTAL); - setValue(scaleStart); - setStepLength((scaleEnd - scaleStart) / 10); - setMarkerLength(10); - - addMouseListener(this); - addKeyListener(this); - } - - void Slider::setScale(double scaleStart, double scaleEnd) - { - mScaleStart = scaleStart; - mScaleEnd = scaleEnd; - } - - double Slider::getScaleStart() const - { - return mScaleStart; - } - - void Slider::setScaleStart(double scaleStart) - { - mScaleStart = scaleStart; - } - - double Slider::getScaleEnd() const - { - return mScaleEnd; - } - - void Slider::setScaleEnd(double scaleEnd) - { - mScaleEnd = scaleEnd; - } - - void Slider::draw(gcn::Graphics* graphics) - { - Color shadowColor = getBaseColor() - 0x101010; - int alpha = getBaseColor().a; - shadowColor.a = alpha; - - graphics->setColor(shadowColor); - graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); - - drawMarker(graphics); - } - - void Slider::drawMarker(gcn::Graphics* graphics) - { - gcn::Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - graphics->setColor(faceColor); - - if (getOrientation() == HORIZONTAL) - { - int v = getMarkerPosition(); - graphics->fillRectangle(gcn::Rectangle(v + 1, 1, - getMarkerLength() - 2, getHeight() - 2)); - graphics->setColor(highlightColor); - graphics->drawLine(v, 0, v + getMarkerLength() - 1, 0); - graphics->drawLine(v, 0, v, getHeight() - 1); - graphics->setColor(shadowColor); - graphics->drawLine(v + getMarkerLength() - 1, 1, - v + getMarkerLength() - 1, getHeight() - 1); - graphics->drawLine(v + 1, getHeight() - 1, - v + getMarkerLength() - 1, getHeight() - 1); - - if (isFocused()) - { - graphics->setColor(getForegroundColor()); - graphics->drawRectangle(Rectangle(v + 2, 2, - getMarkerLength() - 4, getHeight() - 4)); - } - } - else - { - int v = (getHeight() - getMarkerLength()) - getMarkerPosition(); - graphics->fillRectangle(gcn::Rectangle(1, v + 1, getWidth() - 2, - getMarkerLength() - 2)); - graphics->setColor(highlightColor); - graphics->drawLine(0, v, 0, v + getMarkerLength() - 1); - graphics->drawLine(0, v, getWidth() - 1, v); - graphics->setColor(shadowColor); - graphics->drawLine(1, v + getMarkerLength() - 1, getWidth() - 1, - v + getMarkerLength() - 1); - graphics->drawLine(getWidth() - 1, v + 1, getWidth() - 1, - v + getMarkerLength() - 1); - - if (isFocused()) - { - graphics->setColor(getForegroundColor()); - graphics->drawRectangle(Rectangle(2, v + 2, getWidth() - 4, - getMarkerLength() - 4)); - } - } - } - - void Slider::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == gcn::MouseEvent::LEFT - && mouseEvent.getX() >= 0 - && mouseEvent.getX() <= getWidth() - && mouseEvent.getY() >= 0 - && mouseEvent.getY() <= getHeight()) - { - if (getOrientation() == HORIZONTAL) - { - setValue(markerPositionToValue( - mouseEvent.getX() - getMarkerLength() / 2)); - } - else - { - setValue(markerPositionToValue(getHeight() - - mouseEvent.getY() - getMarkerLength() / 2)); - } - - distributeActionEvent(); - } - } - - void Slider::mouseDragged(MouseEvent& mouseEvent) - { - if (getOrientation() == HORIZONTAL) - { - setValue(markerPositionToValue(mouseEvent.getX() - - getMarkerLength() / 2)); - } - else - { - setValue(markerPositionToValue(getHeight() - - mouseEvent.getY() - getMarkerLength() / 2)); - } - - distributeActionEvent(); - - mouseEvent.consume(); - } - - void Slider::setValue(double value) - { - if (value > getScaleEnd()) - { - mValue = getScaleEnd(); - return; - } - - if (value < getScaleStart()) - { - mValue = getScaleStart(); - return; - } - - mValue = value; - } - - double Slider::getValue() const - { - return mValue; - } - - int Slider::getMarkerLength() const - { - return mMarkerLength; - } - - void Slider::setMarkerLength(int length) - { - mMarkerLength = length; - } - - void Slider::keyPressed(KeyEvent& keyEvent) - { - Key key = keyEvent.getKey(); - - if (getOrientation() == HORIZONTAL) - { - if (key.getValue() == Key::RIGHT) - { - setValue(getValue() + getStepLength()); - distributeActionEvent(); - keyEvent.consume(); - } - else if (key.getValue() == Key::LEFT) - { - setValue(getValue() - getStepLength()); - distributeActionEvent(); - keyEvent.consume(); - } - } - else - { - if (key.getValue() == Key::UP) - { - setValue(getValue() + getStepLength()); - distributeActionEvent(); - keyEvent.consume(); - } - else if (key.getValue() == Key::DOWN) - { - setValue(getValue() - getStepLength()); - distributeActionEvent(); - keyEvent.consume(); - } - } - } - - void Slider::setOrientation(Slider::Orientation orientation) - { - mOrientation = orientation; - } - - Slider::Orientation Slider::getOrientation() const - { - return mOrientation; - } - - double Slider::markerPositionToValue(int v) const - { - int w; - if (getOrientation() == HORIZONTAL) - w = getWidth(); - else - w = getHeight(); - - double pos = v / ((double)w - getMarkerLength()); - return (1.0 - pos) * getScaleStart() + pos * getScaleEnd(); - } - - int Slider::valueToMarkerPosition(double value) const - { - int v; - if (getOrientation() == HORIZONTAL) - v = getWidth(); - else - v = getHeight(); - - int w = (int)((v - getMarkerLength()) - * (value - getScaleStart()) - / (getScaleEnd() - getScaleStart())); - - if (w < 0) - return 0; - - if (w > v - getMarkerLength()) - return v - getMarkerLength(); - - return w; - } - - void Slider::setStepLength(double length) - { - mStepLength = length; - } - - double Slider::getStepLength() const - { - return mStepLength; - } - - int Slider::getMarkerPosition() const - { - return valueToMarkerPosition(getValue()); - } - - void Slider::mouseWheelMovedUp(MouseEvent& mouseEvent) - { - setValue(getValue() + getStepLength()); - distributeActionEvent(); - - mouseEvent.consume(); - } - - void Slider::mouseWheelMovedDown(MouseEvent& mouseEvent) - { - setValue(getValue() - getStepLength()); - distributeActionEvent(); - - mouseEvent.consume(); - } -} diff --git a/src/guichan/widgets/tab.cpp b/src/guichan/widgets/tab.cpp deleted file mode 100644 index 1a3df3ede..000000000 --- a/src/guichan/widgets/tab.cpp +++ /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. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/tab.hpp" - -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" -#include "guichan/widgets/button.hpp" -#include "guichan/widgets/label.hpp" -#include "guichan/widgets/tabbedarea.hpp" - -#include "debug.h" - -namespace gcn -{ - Tab::Tab() : - mHasMouse(false), - mTabbedArea(NULL) - { - mLabel = new Label(); - mLabel->setPosition(4, 4); - add(mLabel); - - addMouseListener(this); - } - - Tab::~Tab() - { - delete mLabel; - mLabel = 0; - } - - void Tab::adjustSize() - { - setSize(mLabel->getWidth() + 8, - mLabel->getHeight() + 8); - - if (mTabbedArea != NULL) - mTabbedArea->adjustTabPositions(); - } - - void Tab::setTabbedArea(TabbedArea* tabbedArea) - { - mTabbedArea = tabbedArea; - } - - TabbedArea* Tab::getTabbedArea() - { - return mTabbedArea; - } - - void Tab::setCaption(const std::string& caption) - { - mLabel->setCaption(caption); - mLabel->adjustSize(); - adjustSize(); - } - - const std::string& Tab::getCaption() const - { - return mLabel->getCaption(); - } - - void Tab::draw(Graphics *graphics) - { - const Color &faceColor = getBaseColor(); - const int alpha = getBaseColor().a; - Color highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - Color shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - Color borderColor; - Color baseColor; - - if ((mTabbedArea != NULL && mTabbedArea->isTabSelected(this)) - || mHasMouse) - { - // Draw a border. - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, getWidth() - 1, 0); - graphics->drawLine(0, 1, 0, getHeight() - 1); - graphics->setColor(shadowColor); - graphics->drawLine(getWidth() - 1, 1, - getWidth() - 1, getHeight() - 1); - - borderColor = highlightColor; - baseColor = getBaseColor(); - } - else - { - // Draw a border. - graphics->setColor(shadowColor); - graphics->drawLine(0, 0, getWidth() - 1, 0); - graphics->drawLine(0, 1, 0, getHeight() - 1); - graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, - getHeight() - 1); - - baseColor = getBaseColor() - 0x151515; - baseColor.a = alpha; - } - - // Push a clip area so the other drawings don't need to worry - // about the border. - graphics->pushClipArea(Rectangle(1, 1, - getWidth() - 2, getHeight() - 1)); - const Rectangle currentClipArea = graphics->getCurrentClipArea(); - - graphics->setColor(baseColor); - graphics->fillRectangle(Rectangle(0, 0, - currentClipArea.width, currentClipArea.height)); - - drawChildren(graphics); - - if (mTabbedArea != NULL - && mTabbedArea->isFocused() - && mTabbedArea->isTabSelected(this)) - { - graphics->setColor(Color(0x000000)); - graphics->drawRectangle(Rectangle(2, 2, - currentClipArea.width - 4, currentClipArea.height - 4)); - } - - graphics->popClipArea(); - } - - void Tab::mouseEntered(MouseEvent& mouseEvent A_UNUSED) - { - mHasMouse = true; - } - - void Tab::mouseExited(MouseEvent& mouseEvent A_UNUSED) - { - mHasMouse = false; - } -} - diff --git a/src/guichan/widgets/tabbedarea.cpp b/src/guichan/widgets/tabbedarea.cpp deleted file mode 100644 index b22d615e9..000000000 --- a/src/guichan/widgets/tabbedarea.cpp +++ /dev/null @@ -1,453 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/tabbedarea.hpp" - -#include "guichan/exception.hpp" -#include "guichan/focushandler.hpp" -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" - -#include "guichan/widgets/container.hpp" -#include "guichan/widgets/tab.hpp" - -#include <algorithm> - -#include "debug.h" - -namespace gcn -{ - TabbedArea::TabbedArea() : - mSelectedTab(NULL), - mOpaque(false) - { - setFocusable(true); - addKeyListener(this); - addMouseListener(this); - - mTabContainer = new Container(); - mTabContainer->setOpaque(false); - mWidgetContainer = new Container(); - - add(mTabContainer); - add(mWidgetContainer); - } - - TabbedArea::~TabbedArea() - { - remove(mTabContainer); - remove(mWidgetContainer); - - delete mTabContainer; - mTabContainer = 0; - delete mWidgetContainer; - mWidgetContainer = 0; - - for (unsigned int i = 0; i < mTabsToDelete.size(); i++) - { - delete mTabsToDelete[i]; - mTabsToDelete[i] = 0; - } - } - - void TabbedArea::addTab(const std::string& caption, Widget* widget) - { - Tab* tab = new Tab(); - tab->setCaption(caption); - mTabsToDelete.push_back(tab); - - addTab(tab, widget); - } - - void TabbedArea::addTab(Tab* tab, Widget* widget) - { - tab->setTabbedArea(this); - tab->addActionListener(this); - - mTabContainer->add(tab); - mTabs.push_back(std::pair<Tab*, Widget*>(tab, widget)); - - if (mSelectedTab == NULL) - setSelectedTab(tab); - - adjustTabPositions(); - adjustSize(); - } - - void TabbedArea::removeTabWithIndex(unsigned int index) - { - if (index >= mTabs.size()) - throw GCN_EXCEPTION("No such tab index."); - - removeTab(mTabs[index].first); - } - - void TabbedArea::removeTab(Tab* tab) - { - int tabIndexToBeSelected = - 1; - - if (tab == mSelectedTab) - { - int index = getSelectedTabIndex(); - - if (index == (int)mTabs.size() - 1 - && mTabs.size() >= 2) - { - tabIndexToBeSelected = index--; - } - else if (index == (int)mTabs.size() - 1 - && mTabs.size() == 1) - { - tabIndexToBeSelected = -1; - } - else - { - tabIndexToBeSelected = index; - } - } - - std::vector<std::pair<Tab*, Widget*> >::iterator iter; - for (iter = mTabs.begin(); iter != mTabs.end(); ++ iter) - { - if (iter->first == tab) - { - mTabContainer->remove(tab); - mTabs.erase(iter); - break; - } - } - - std::vector<Tab*>::iterator iter2; - for (iter2 = mTabsToDelete.begin(); - iter2 != mTabsToDelete.end(); - ++ iter2) - { - if (*iter2 == tab) - { - mTabsToDelete.erase(iter2); - delete tab; - tab = 0; - break; - } - } - - if (tabIndexToBeSelected == -1) - { - mSelectedTab = NULL; - mWidgetContainer->clear(); - } - else - { - setSelectedTab(tabIndexToBeSelected); - } - - adjustSize(); - adjustTabPositions(); - } - - bool TabbedArea::isTabSelected(unsigned int index) const - { - if (index >= mTabs.size()) - throw GCN_EXCEPTION("No such tab index."); - - return mSelectedTab == mTabs[index].first; - } - - bool TabbedArea::isTabSelected(Tab* tab) - { - return mSelectedTab == tab; - } - - void TabbedArea::setSelectedTab(unsigned int index) - { - if (index >= mTabs.size()) - throw GCN_EXCEPTION("No such tab index."); - - setSelectedTab(mTabs[index].first); - } - - void TabbedArea::setSelectedTab(Tab* tab) - { - unsigned int i; - for (i = 0; i < mTabs.size(); i++) - { - if (mTabs[i].first == mSelectedTab) - mWidgetContainer->remove(mTabs[i].second); - } - - for (i = 0; i < mTabs.size(); i++) - { - if (mTabs[i].first == tab) - { - mSelectedTab = tab; - mWidgetContainer->add(mTabs[i].second); - } - } - } - - int TabbedArea::getSelectedTabIndex() const - { - unsigned int i; - for (i = 0; i < mTabs.size(); i++) - { - if (mTabs[i].first == mSelectedTab) - return i; - } - - return -1; - } - - Tab* TabbedArea::getSelectedTab() - { - return mSelectedTab; - } - - void TabbedArea::setOpaque(bool opaque) - { - mOpaque = opaque; - } - - bool TabbedArea::isOpaque() const - { - return mOpaque; - } - - void TabbedArea::draw(Graphics *graphics) - { - const Color &faceColor = getBaseColor(); - const int alpha = getBaseColor().a; - Color highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - Color shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - // Draw a border. - graphics->setColor(highlightColor); - graphics->drawLine(0, - mTabContainer->getHeight(), - 0, - getHeight() - 2); - graphics->setColor(shadowColor); - graphics->drawLine(getWidth() - 1, - mTabContainer->getHeight() + 1, - getWidth() - 1, - getHeight() - 1); - graphics->drawLine(1, - getHeight() - 1, - getWidth() - 1, - getHeight() - 1); - - if (isOpaque()) - { - graphics->setColor(getBaseColor()); - graphics->fillRectangle(Rectangle(1, 1, - getWidth() - 2, - getHeight() - 2)); - } - - // Draw a line underneath the tabs. - graphics->setColor(highlightColor); - graphics->drawLine(1, mTabContainer->getHeight(), - getWidth() - 1, mTabContainer->getHeight()); - - // If a tab is selected, remove the line right underneath - // the selected tab. - if (mSelectedTab != NULL) - { - graphics->setColor(getBaseColor()); - graphics->drawLine(mSelectedTab->getX() + 1, - mTabContainer->getHeight(), - mSelectedTab->getX() + mSelectedTab->getWidth() - 2, - mTabContainer->getHeight()); - - } - - drawChildren(graphics); - } - - void TabbedArea::logic() - { - } - - void TabbedArea::adjustSize() - { - int maxTabHeight = 0; - - for (unsigned int i = 0; i < mTabs.size(); i++) - { - if (mTabs[i].first->getHeight() > maxTabHeight) - maxTabHeight = mTabs[i].first->getHeight(); - } - - mTabContainer->setSize(getWidth() - 2, maxTabHeight); - - mWidgetContainer->setPosition(1, maxTabHeight + 1); - mWidgetContainer->setSize(getWidth() - 2, - getHeight() - maxTabHeight - 2); - } - - void TabbedArea::adjustTabPositions() - { - int maxTabHeight = 0; - unsigned int i; - for (i = 0; i < mTabs.size(); i++) - { - if (mTabs[i].first->getHeight() > maxTabHeight) - maxTabHeight = mTabs[i].first->getHeight(); - } - - int x = 0; - for (i = 0; i < mTabs.size(); i++) - { - Tab* tab = mTabs[i].first; - tab->setPosition(x, maxTabHeight - tab->getHeight()); - x += tab->getWidth(); - } - } - - void TabbedArea::setWidth(int width) - { - Widget::setWidth(width); - adjustSize(); - } - - void TabbedArea::setHeight(int height) - { - Widget::setHeight(height); - adjustSize(); - } - - void TabbedArea::setSize(int width, int height) - { - Widget::setSize(width, height); - adjustSize(); - } - - void TabbedArea::setDimension(const Rectangle& dimension) - { - Widget::setDimension(dimension); - adjustSize(); - } - - void TabbedArea::keyPressed(KeyEvent& keyEvent) - { - if (keyEvent.isConsumed() || !isFocused()) - return; - - if (keyEvent.getKey().getValue() == Key::LEFT) - { - int index = getSelectedTabIndex(); - index--; - - if (index < 0) - return; - else - setSelectedTab(mTabs[index].first); - - keyEvent.consume(); - } - else if (keyEvent.getKey().getValue() == Key::RIGHT) - { - int index = getSelectedTabIndex(); - index++; - - if (index >= (int)mTabs.size()) - return; - else - setSelectedTab(mTabs[index].first); - - keyEvent.consume(); - } - } - - - void TabbedArea::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.isConsumed()) - return; - - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - Widget* widget = mTabContainer->getWidgetAt( - mouseEvent.getX(), mouseEvent.getY()); - Tab* tab = dynamic_cast<Tab*>(widget); - - if (tab != NULL) - setSelectedTab(tab); - } - - // Request focus only if the source of the event - // is not focusble. If the source of the event - // is focused we don't want to steal the focus. - if (!mouseEvent.getSource()->isFocusable()) - requestFocus(); - } - - void TabbedArea::death(const Event& event) - { - Tab* tab = dynamic_cast<Tab*>(event.getSource()); - - if (tab != NULL) - removeTab(tab); - else - BasicContainer::death(event); - } - - void TabbedArea::action(const ActionEvent& actionEvent) - { - Widget* source = actionEvent.getSource(); - Tab* tab = dynamic_cast<Tab*>(source); - - if (tab == NULL) - { - throw GCN_EXCEPTION("Received an action from a " - "widget that's not a tab!"); - } - - setSelectedTab(tab); - } -} diff --git a/src/guichan/widgets/textbox.cpp b/src/guichan/widgets/textbox.cpp deleted file mode 100644 index 35fbf5437..000000000 --- a/src/guichan/widgets/textbox.cpp +++ /dev/null @@ -1,485 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/textbox.hpp" - -#include "guichan/basiccontainer.hpp" -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" -#include "guichan/key.hpp" -#include "guichan/mouseinput.hpp" - -#include "debug.h" - -namespace gcn -{ - TextBox::TextBox() - { - mCaretColumn = 0; - mCaretRow = 0; - mEditable = true; - mOpaque = true; - - setText(""); - - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - adjustSize(); - } - - TextBox::TextBox(const std::string& text) - { - mCaretColumn = 0; - mCaretRow = 0; - mEditable = true; - mOpaque = true; - - setText(text); - - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - adjustSize(); - } - - void TextBox::setText(const std::string& text) - { - mCaretColumn = 0; - mCaretRow = 0; - - mTextRows.clear(); - - std::string::size_type pos, lastPos = 0; - int length; - do - { - pos = text.find("\n", lastPos); - - if (pos != std::string::npos) - length = pos - lastPos; - else - length = text.size() - lastPos; - std::string sub = text.substr(lastPos, length); - mTextRows.push_back(sub); - lastPos = pos + 1; - - } while (pos != std::string::npos); - - adjustSize(); - } - - void TextBox::draw(Graphics* graphics) - { - unsigned int i; - - if (mOpaque) - { - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - } - - if (isFocused() && isEditable()) - { - drawCaret(graphics, getFont()->getWidth( - mTextRows[mCaretRow].substr(0, mCaretColumn)), - mCaretRow * getFont()->getHeight()); - } - - graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); - - for (i = 0; i < mTextRows.size(); i++) - { - // Move the text one pixel so we can have a caret before a letter. - graphics->drawText(mTextRows[i], 1, i * getFont()->getHeight()); - } - } - - void TextBox::drawCaret(Graphics* graphics, int x, int y) - { - graphics->setColor(getForegroundColor()); - graphics->drawLine(x, getFont()->getHeight() + y, x, y); - } - - void TextBox::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mCaretRow = mouseEvent.getY() / getFont()->getHeight(); - - if (mCaretRow >= (int)mTextRows.size()) - mCaretRow = mTextRows.size() - 1; - - mCaretColumn = getFont()->getStringIndexAt( - mTextRows[mCaretRow], mouseEvent.getX()); - } - } - - void TextBox::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } - - void TextBox::keyPressed(KeyEvent& keyEvent) - { - Key key = keyEvent.getKey(); - - if (key.getValue() == Key::LEFT) - { - --mCaretColumn; - if (mCaretColumn < 0) - { - --mCaretRow; - - if (mCaretRow < 0) - { - mCaretRow = 0; - mCaretColumn = 0; - } - else - { - mCaretColumn = mTextRows[mCaretRow].size(); - } - } - } - else if (key.getValue() == Key::RIGHT) - { - ++mCaretColumn; - if (mCaretColumn > (int)mTextRows[mCaretRow].size()) - { - ++mCaretRow; - - if (mCaretRow >= (int)mTextRows.size()) - { - mCaretRow = mTextRows.size() - 1; - if (mCaretRow < 0) - mCaretRow = 0; - - mCaretColumn = mTextRows[mCaretRow].size(); - } - else - { - mCaretColumn = 0; - } - } - } - else if (key.getValue() == Key::DOWN) - { - setCaretRow(mCaretRow + 1); - } - else if (key.getValue() == Key::UP) - { - setCaretRow(mCaretRow - 1); - } - else if (key.getValue() == Key::HOME) - { - mCaretColumn = 0; - } - else if (key.getValue() == Key::END) - { - mCaretColumn = mTextRows[mCaretRow].size(); - } - else if (key.getValue() == Key::ENTER && mEditable) - { - mTextRows.insert(mTextRows.begin() + mCaretRow + 1, - mTextRows[mCaretRow].substr(mCaretColumn, - mTextRows[mCaretRow].size() - mCaretColumn)); - mTextRows[mCaretRow].resize(mCaretColumn); - ++mCaretRow; - mCaretColumn = 0; - } - else if (key.getValue() == Key::BACKSPACE - && mCaretColumn != 0 - && mEditable) - { - mTextRows[mCaretRow].erase(mCaretColumn - 1, 1); - --mCaretColumn; - } - else if (key.getValue() == Key::BACKSPACE - && mCaretColumn == 0 - && mCaretRow != 0 - && mEditable) - { - mCaretColumn = mTextRows[mCaretRow - 1].size(); - mTextRows[mCaretRow - 1] += mTextRows[mCaretRow]; - mTextRows.erase(mTextRows.begin() + mCaretRow); - --mCaretRow; - } - else if (key.getValue() == Key::DELETE - && mCaretColumn < (int)mTextRows[mCaretRow].size() - && mEditable) - { - mTextRows[mCaretRow].erase(mCaretColumn, 1); - } - else if (key.getValue() == Key::DELETE - && mCaretColumn == (int)mTextRows[mCaretRow].size() - && mCaretRow < ((int)mTextRows.size() - 1) - && mEditable) - { - mTextRows[mCaretRow] += mTextRows[mCaretRow + 1]; - mTextRows.erase(mTextRows.begin() + mCaretRow + 1); - } - else if (key.getValue() == Key::PAGE_UP) - { - Widget* par = getParent(); - - if (par != NULL) - { - int rowsPerPage = par->getChildrenArea().height - / getFont()->getHeight(); - mCaretRow -= rowsPerPage; - - if (mCaretRow < 0) - mCaretRow = 0; - } - } - else if (key.getValue() == Key::PAGE_DOWN) - { - Widget* par = getParent(); - - if (par != NULL) - { - int rowsPerPage = par->getChildrenArea().height - / getFont()->getHeight(); - mCaretRow += rowsPerPage; - - if (mCaretRow >= (int)mTextRows.size()) - mCaretRow = mTextRows.size() - 1; - } - } - else if (key.getValue() == Key::TAB - && mEditable) - { - mTextRows[mCaretRow].insert(mCaretColumn, std::string(" ")); - mCaretColumn += 4; - } - else if (key.isCharacter() - && mEditable) - { - mTextRows[mCaretRow].insert(mCaretColumn, - std::string(1, (char)key.getValue())); - ++ mCaretColumn; - } - - adjustSize(); - scrollToCaret(); - - keyEvent.consume(); - } - - void TextBox::adjustSize() - { - unsigned int i; - int width = 0; - for (i = 0; i < mTextRows.size(); ++i) - { - int w = getFont()->getWidth(mTextRows[i]); - if (width < w) - width = w; - } - - setWidth(width + 1); - setHeight(getFont()->getHeight() * mTextRows.size()); - } - - void TextBox::setCaretPosition(unsigned int position) - { - int row; - - for (row = 0; row < (int)mTextRows.size(); row++) - { - if (position <= mTextRows[row].size()) - { - mCaretRow = row; - mCaretColumn = position; - return; // we are done - } - else - { - position--; - } - } - - // position beyond end of text - mCaretRow = mTextRows.size() - 1; - mCaretColumn = mTextRows[mCaretRow].size(); - } - - unsigned int TextBox::getCaretPosition() const - { - int pos = 0, row; - - for (row = 0; row < mCaretRow; row++) - pos += mTextRows[row].size(); - - return pos + mCaretColumn; - } - - void TextBox::setCaretRowColumn(int row, int column) - { - setCaretRow(row); - setCaretColumn(column); - } - - void TextBox::setCaretRow(int row) - { - mCaretRow = row; - - if (mCaretRow >= (int)mTextRows.size()) - mCaretRow = mTextRows.size() - 1; - - if (mCaretRow < 0) - mCaretRow = 0; - - setCaretColumn(mCaretColumn); - } - - unsigned int TextBox::getCaretRow() const - { - return mCaretRow; - } - - void TextBox::setCaretColumn(int column) - { - mCaretColumn = column; - - if (mCaretColumn > (int)mTextRows[mCaretRow].size()) - mCaretColumn = mTextRows[mCaretRow].size(); - - if (mCaretColumn < 0) - mCaretColumn = 0; - } - - unsigned int TextBox::getCaretColumn() const - { - return mCaretColumn; - } - - const std::string& TextBox::getTextRow(int row) const - { - return mTextRows[row]; - } - - void TextBox::setTextRow(int row, const std::string& text) - { - mTextRows[row] = text; - - if (mCaretRow == row) - setCaretColumn(mCaretColumn); - - adjustSize(); - } - - unsigned int TextBox::getNumberOfRows() const - { - return mTextRows.size(); - } - - std::string TextBox::getText() const - { - if (mTextRows.empty()) - return std::string(""); - - int i; - std::string text; - - for (i = 0; i < (int)mTextRows.size() - 1; ++i) - text = text + mTextRows[i] + "\n"; - - text = text + mTextRows[i]; - - return text; - } - - void TextBox::fontChanged() - { - adjustSize(); - } - - void TextBox::scrollToCaret() - { - Rectangle scroll; - scroll.x = getFont()->getWidth( - mTextRows[mCaretRow].substr(0, mCaretColumn)); - scroll.y = getFont()->getHeight() * mCaretRow; - scroll.width = getFont()->getWidth(" "); - - // add 2 for some extra space - scroll.height = getFont()->getHeight() + 2; - - showPart(scroll); - } - - void TextBox::setEditable(bool editable) - { - mEditable = editable; - } - - bool TextBox::isEditable() const - { - return mEditable; - } - - void TextBox::addRow(const std::string row) - { - mTextRows.push_back(row); - adjustSize(); - } - - bool TextBox::isOpaque() - { - return mOpaque; - } - - void TextBox::setOpaque(bool opaque) - { - mOpaque = opaque; - } -} diff --git a/src/guichan/widgets/textfield.cpp b/src/guichan/widgets/textfield.cpp deleted file mode 100644 index af2b9582f..000000000 --- a/src/guichan/widgets/textfield.cpp +++ /dev/null @@ -1,272 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/textfield.hpp" - -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" -#include "guichan/key.hpp" -#include "guichan/mouseinput.hpp" - -#include "debug.h" - -namespace gcn -{ - TextField::TextField() - { - mCaretPosition = 0; - mXScroll = 0; - - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - } - - TextField::TextField(const std::string& text) - { - mCaretPosition = 0; - mXScroll = 0; - - mText = text; - adjustSize(); - - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - } - - void TextField::setText(const std::string& text) - { - if (text.size() < mCaretPosition) - mCaretPosition = text.size(); - - mText = text; - } - - void TextField::draw(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - // Draw a border. - graphics->setColor(shadowColor); - graphics->drawLine(0, 0, getWidth() - 1, 0); - graphics->drawLine(0, 1, 0, getHeight() - 2); - graphics->setColor(highlightColor); - graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1); - graphics->drawLine(0, getHeight() - 1, - getWidth() - 1, getHeight() - 1); - - // Push a clip area so the other drawings don't need to worry - // about the border. - graphics->pushClipArea(Rectangle(1, 1, - getWidth() - 2, getHeight() - 2)); - - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - - if (isFocused()) - { - graphics->setColor(getSelectionColor()); - graphics->drawRectangle(Rectangle(0, 0, - getWidth() - 2, getHeight() - 2)); - graphics->drawRectangle(Rectangle(1, 1, - getWidth() - 4, getHeight() - 4)); - } - - if (isFocused()) - { - drawCaret(graphics, getFont()->getWidth( - mText.substr(0, mCaretPosition)) - mXScroll); - } - - graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); - graphics->drawText(mText, 3 - mXScroll, 1); - - graphics->popClipArea(); - } - - void TextField::drawCaret(Graphics* graphics, int x) - { - // Check the current clip area as a clip area with a different - // size than the widget might have been pushed (which is the - // case in the draw method when we push a clip area after we have - // drawn a border). - const Rectangle clipArea = graphics->getCurrentClipArea(); - - graphics->setColor(getForegroundColor()); - graphics->drawLine(x, clipArea.height - 2, x, 1); - } - - void TextField::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mCaretPosition = getFont()->getStringIndexAt( - mText, mouseEvent.getX() + mXScroll); - fixScroll(); - } - } - - void TextField::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } - - void TextField::keyPressed(KeyEvent& keyEvent) - { - Key key = keyEvent.getKey(); - - if (key.getValue() == Key::LEFT && mCaretPosition > 0) - { - --mCaretPosition; - } - else if (key.getValue() == Key::RIGHT && mCaretPosition < mText.size()) - { - ++mCaretPosition; - } - else if (key.getValue() == Key::DELETE - && mCaretPosition < mText.size()) - { - mText.erase(mCaretPosition, 1); - } - else if (key.getValue() == Key::BACKSPACE && mCaretPosition > 0) - { - mText.erase(mCaretPosition - 1, 1); - --mCaretPosition; - } - else if (key.getValue() == Key::ENTER) - { - distributeActionEvent(); - } - else if (key.getValue() == Key::HOME) - { - mCaretPosition = 0; - } - else if (key.getValue() == Key::END) - { - mCaretPosition = mText.size(); - } - else if (key.isCharacter() - && key.getValue() != Key::TAB) - { - mText.insert(mCaretPosition, std::string(1, (char)key.getValue())); - ++mCaretPosition; - } - - if (key.getValue() != Key::TAB) - keyEvent.consume(); - - fixScroll(); - } - - void TextField::adjustSize() - { - setWidth(getFont()->getWidth(mText) + 7); - adjustHeight(); - - fixScroll(); - } - - void TextField::adjustHeight() - { - setHeight(getFont()->getHeight() + 4); - } - - void TextField::fixScroll() - { - if (isFocused()) - { - int caretX = getFont()->getWidth(mText.substr(0, mCaretPosition)); - - if (caretX - mXScroll >= getWidth() - 4) - { - mXScroll = caretX - getWidth() + 4; - } - else if (caretX - mXScroll <= 0) - { - mXScroll = caretX - getWidth() / 2; - - if (mXScroll < 0) - mXScroll = 0; - } - } - } - - void TextField::setCaretPosition(unsigned int position) - { - if (position > mText.size()) - mCaretPosition = mText.size(); - else - mCaretPosition = position; - - fixScroll(); - } - - unsigned int TextField::getCaretPosition() const - { - return mCaretPosition; - } - - const std::string& TextField::getText() const - { - return mText; - } - - void TextField::fontChanged() - { - fixScroll(); - } -} diff --git a/src/guichan/widgets/window.cpp b/src/guichan/widgets/window.cpp deleted file mode 100644 index 4779fb0ce..000000000 --- a/src/guichan/widgets/window.cpp +++ /dev/null @@ -1,296 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "guichan/widgets/window.hpp" - -#include "guichan/exception.hpp" -#include "guichan/font.hpp" -#include "guichan/graphics.hpp" -#include "guichan/mouseinput.hpp" - -#include "debug.h" - -namespace gcn -{ - Window::Window() : - mMoved(false) - { - setFrameSize(1); - setPadding(2); - setTitleBarHeight(16); - setAlignment(Graphics::CENTER); - addMouseListener(this); - setMovable(true); - setOpaque(true); - } - - Window::Window(const std::string& caption) : - mMoved(false) - { - setCaption(caption); - setFrameSize(1); - setPadding(2); - setTitleBarHeight(16); - setAlignment(Graphics::CENTER); - addMouseListener(this); - setMovable(true); - setOpaque(true); - } - - Window::~Window() - { - } - - void Window::setPadding(unsigned int padding) - { - mPadding = padding; - } - - unsigned int Window::getPadding() const - { - return mPadding; - } - - void Window::setTitleBarHeight(unsigned int height) - { - mTitleBarHeight = height; - } - - unsigned int Window::getTitleBarHeight() - { - return mTitleBarHeight; - } - - void Window::setCaption(const std::string& caption) - { - mCaption = caption; - } - - const std::string& Window::getCaption() const - { - return mCaption; - } - - void Window::setAlignment(Graphics::Alignment alignment) - { - mAlignment = alignment; - } - - Graphics::Alignment Window::getAlignment() const - { - return mAlignment; - } - - void Window::draw(Graphics* graphics) - { - const Color &faceColor = getBaseColor(); - Color highlightColor, shadowColor; - const int alpha = getBaseColor().a; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - Rectangle d = getChildrenArea(); - - // Fill the background around the content - graphics->setColor(faceColor); - // Fill top - graphics->fillRectangle(Rectangle(0, 0, getWidth(), d.y - 1)); - // Fill left - graphics->fillRectangle(Rectangle(0, d.y - 1, d.x - 1, - getHeight() - d.y + 1)); - // Fill right - graphics->fillRectangle(Rectangle(d.x + d.width + 1, d.y - 1, - getWidth() - d.x - d.width - 1, getHeight() - d.y + 1)); - // Fill bottom - graphics->fillRectangle(Rectangle(d.x - 1, d.y + d.height + 1, - d.width + 2, getHeight() - d.height - d.y - 1)); - - if (isOpaque()) - graphics->fillRectangle(d); - - // Construct a rectangle one pixel bigger than the content - d.x -= 1; - d.y -= 1; - d.width += 2; - d.height += 2; - - // Draw a border around the content - graphics->setColor(shadowColor); - // Top line - graphics->drawLine(d.x, - d.y, - d.x + d.width - 2, - d.y); - - // Left line - graphics->drawLine(d.x, - d.y + 1, - d.x, - d.y + d.height - 1); - - graphics->setColor(highlightColor); - // Right line - graphics->drawLine(d.x + d.width - 1, - d.y, - d.x + d.width - 1, - d.y + d.height - 2); - // Bottom line - graphics->drawLine(d.x + 1, - d.y + d.height - 1, - d.x + d.width - 1, - d.y + d.height - 1); - - drawChildren(graphics); - - int textX; - int textY; - - textY = ((int)getTitleBarHeight() - getFont()->getHeight()) / 2; - - switch (getAlignment()) - { - case Graphics::LEFT: - textX = 4; - break; - case Graphics::CENTER: - textX = getWidth() / 2; - break; - case Graphics::RIGHT: - textX = getWidth() - 4; - break; - default: - throw GCN_EXCEPTION("Unknown alignment."); - } - - graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); - graphics->pushClipArea(Rectangle(0, 0, getWidth(), - getTitleBarHeight() - 1)); - graphics->drawText(getCaption(), textX, textY, getAlignment()); - graphics->popClipArea(); - } - - void Window::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getSource() != this) - return; - - if (getParent() != NULL) - getParent()->moveToTop(this); - - mDragOffsetX = mouseEvent.getX(); - mDragOffsetY = mouseEvent.getY(); - - mMoved = mouseEvent.getY() <= (int)mTitleBarHeight; - } - - void Window::mouseReleased(MouseEvent& mouseEvent A_UNUSED) - { - mMoved = false; - } - - void Window::mouseDragged(MouseEvent& mouseEvent) - { - if (mouseEvent.isConsumed() || mouseEvent.getSource() != this) - return; - - if (isMovable() && mMoved) - { - setPosition(mouseEvent.getX() - mDragOffsetX + getX(), - mouseEvent.getY() - mDragOffsetY + getY()); - } - - mouseEvent.consume(); - } - - Rectangle Window::getChildrenArea() - { - return Rectangle(getPadding(), - getTitleBarHeight(), - getWidth() - getPadding() * 2, - getHeight() - getPadding() - getTitleBarHeight()); - } - - void Window::setMovable(bool movable) - { - mMovable = movable; - } - - bool Window::isMovable() const - { - return mMovable; - } - - void Window::setOpaque(bool opaque) - { - mOpaque = opaque; - } - - bool Window::isOpaque() - { - return mOpaque; - } - - void Window::resizeToContent() - { - WidgetListIterator it; - - int w = 0, h = 0; - for (it = mWidgets.begin(); it != mWidgets.end(); it++) - { - if ((*it)->getX() + (*it)->getWidth() > w) - w = (*it)->getX() + (*it)->getWidth(); - - if ((*it)->getY() + (*it)->getHeight() > h) - h = (*it)->getY() + (*it)->getHeight(); - } - - setSize(w + 2* getPadding(), h + getPadding() + getTitleBarHeight()); - } -} |