diff --git a/CMakeLists.txt b/CMakeLists.txt index 99ccb56af5..bb8e521f3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,8 +83,6 @@ endif() include_directories( src/include - src/guichan/include - src/guichan/include/guichan src/third_party/ ${CMAKE_CURRENT_BINARY_DIR} ) @@ -174,40 +172,39 @@ set(game_SRCS source_group(game FILES ${game_SRCS}) set(guichan_SRCS - src/guichan/cliprectangle.cpp - src/guichan/color.cpp - src/guichan/defaultfont.cpp - src/guichan/exception.cpp - src/guichan/focushandler.cpp - src/guichan/gfont.cpp - src/guichan/graphics.cpp - src/guichan/gui.cpp - src/guichan/guichan.cpp - src/guichan/image.cpp - src/guichan/imagefont.cpp - src/guichan/key.cpp - src/guichan/keyinput.cpp - src/guichan/mouseinput.cpp - src/guichan/rectangle.cpp - src/guichan/sdl/gsdl.cpp - src/guichan/sdl/sdlgraphics.cpp - src/guichan/sdl/sdlinput.cpp - src/guichan/widget.cpp - src/guichan/widgets/button.cpp - src/guichan/widgets/container.cpp - src/guichan/widgets/dropdown.cpp - src/guichan/widgets/checkbox.cpp - src/guichan/widgets/icon.cpp - src/guichan/widgets/label.cpp - src/guichan/widgets/listbox.cpp - src/guichan/widgets/radiobutton.cpp - src/guichan/widgets/scrollarea.cpp - src/guichan/widgets/slider.cpp - src/guichan/widgets/textbox.cpp - src/guichan/widgets/textfield.cpp - src/guichan/widgets/window.cpp + third-party/guichan/src/cliprectangle.cpp + third-party/guichan/src/color.cpp + third-party/guichan/src/defaultfont.cpp + third-party/guichan/src/exception.cpp + third-party/guichan/src/focushandler.cpp + third-party/guichan/src/font.cpp + third-party/guichan/src/graphics.cpp + third-party/guichan/src/gui.cpp + third-party/guichan/src/guichan.cpp + third-party/guichan/src/image.cpp + third-party/guichan/src/imagefont.cpp + third-party/guichan/src/key.cpp + third-party/guichan/src/keyinput.cpp + third-party/guichan/src/mouseinput.cpp + third-party/guichan/src/rectangle.cpp + third-party/guichan/src/sdl/sdl.cpp + third-party/guichan/src/sdl/sdlgraphics.cpp + third-party/guichan/src/sdl/sdlinput.cpp + third-party/guichan/src/widget.cpp + third-party/guichan/src/widgets/button.cpp + third-party/guichan/src/widgets/container.cpp + third-party/guichan/src/widgets/dropdown.cpp + third-party/guichan/src/widgets/checkbox.cpp + third-party/guichan/src/widgets/icon.cpp + third-party/guichan/src/widgets/label.cpp + third-party/guichan/src/widgets/listbox.cpp + third-party/guichan/src/widgets/radiobutton.cpp + third-party/guichan/src/widgets/scrollarea.cpp + third-party/guichan/src/widgets/slider.cpp + third-party/guichan/src/widgets/textbox.cpp + third-party/guichan/src/widgets/textfield.cpp + third-party/guichan/src/widgets/window.cpp ) -source_group(guichan FILES ${guichan_SRCS}) set(map_SRCS src/map/fov.cpp @@ -411,7 +408,6 @@ set(stratagus_SRCS ${ai_SRCS} ${editor_SRCS} ${game_SRCS} - ${guichan_SRCS} ${map_SRCS} ${missile_SRCS} ${network_SRCS} @@ -428,51 +424,51 @@ set(stratagus_SRCS ${CMAKE_CURRENT_BINARY_DIR}/tolua.cpp ) -set(stratagus_guichan_HDRS - src/guichan/include/guichan/actionlistener.h - src/guichan/include/guichan/allegro.h - src/guichan/include/guichan/basiccontainer.h - src/guichan/include/guichan/cliprectangle.h - src/guichan/include/guichan/color.h - src/guichan/include/guichan/defaultfont.h - src/guichan/include/guichan/exception.h - src/guichan/include/guichan/focushandler.h - src/guichan/include/guichan/font.h - src/guichan/include/guichan/graphics.h - src/guichan/include/guichan/gsdl.h - src/guichan/include/guichan/gui.h - src/guichan/include/guichan.h - src/guichan/include/guichan/imagefont.h - src/guichan/include/guichan/image.h - src/guichan/include/guichan/imageloader.h - src/guichan/include/guichan/input.h - src/guichan/include/guichan/key.h - src/guichan/include/guichan/keyinput.h - src/guichan/include/guichan/keylistener.h - src/guichan/include/guichan/listmodel.h - src/guichan/include/guichan/mouseinput.h - src/guichan/include/guichan/mouselistener.h - src/guichan/include/guichan/platform.h - src/guichan/include/guichan/rectangle.h - src/guichan/include/guichan/sdl/sdlgraphics.h - src/guichan/include/guichan/sdl/sdlimageloader.h - src/guichan/include/guichan/sdl/sdlinput.h - src/guichan/include/guichan/sdl/sdlpixel.h - src/guichan/include/guichan/widget.h - src/guichan/include/guichan/widgets/button.h - src/guichan/include/guichan/widgets/container.h - src/guichan/include/guichan/widgets/dropdown.h - src/guichan/include/guichan/widgets/checkbox.h - src/guichan/include/guichan/widgets/icon.h - src/guichan/include/guichan/widgets/label.h - src/guichan/include/guichan/widgets/listbox.h - src/guichan/include/guichan/widgets/radiobutton.h - src/guichan/include/guichan/widgets/scrollarea.h - src/guichan/include/guichan/widgets/slider.h - src/guichan/include/guichan/widgets/textbox.h - src/guichan/include/guichan/widgets/textfield.h - src/guichan/include/guichan/widgets/window.h - src/guichan/include/guichan/x.h +set(guichan_HDRS + third-party/guichan/include/guichan/actionlistener.hpp + third-party/guichan/include/guichan/allegro.hpp + third-party/guichan/include/guichan/basiccontainer.hpp + third-party/guichan/include/guichan/cliprectangle.hpp + third-party/guichan/include/guichan/color.hpp + third-party/guichan/include/guichan/defaultfont.hpp + third-party/guichan/include/guichan/exception.hpp + third-party/guichan/include/guichan/focushandler.hpp + third-party/guichan/include/guichan/font.hpp + third-party/guichan/include/guichan/graphics.hpp + third-party/guichan/include/guichan/sdl.hpp + third-party/guichan/include/guichan/gui.hpp + third-party/guichan/include/guichan.hpp + third-party/guichan/include/guichan/imagefont.hpp + third-party/guichan/include/guichan/image.hpp + third-party/guichan/include/guichan/imageloader.hpp + third-party/guichan/include/guichan/input.hpp + third-party/guichan/include/guichan/key.hpp + third-party/guichan/include/guichan/keyinput.hpp + third-party/guichan/include/guichan/keylistener.hpp + third-party/guichan/include/guichan/listmodel.hpp + third-party/guichan/include/guichan/mouseinput.hpp + third-party/guichan/include/guichan/mouselistener.hpp + third-party/guichan/include/guichan/platform.hpp + third-party/guichan/include/guichan/rectangle.hpp + third-party/guichan/include/guichan/sdl/sdlgraphics.hpp + third-party/guichan/include/guichan/sdl/sdlimageloader.hpp + third-party/guichan/include/guichan/sdl/sdlinput.hpp + third-party/guichan/include/guichan/sdl/sdlpixel.hpp + third-party/guichan/include/guichan/widget.hpp + third-party/guichan/include/guichan/widgets/button.hpp + third-party/guichan/include/guichan/widgets/container.hpp + third-party/guichan/include/guichan/widgets/dropdown.hpp + third-party/guichan/include/guichan/widgets/checkbox.hpp + third-party/guichan/include/guichan/widgets/icon.hpp + third-party/guichan/include/guichan/widgets/label.hpp + third-party/guichan/include/guichan/widgets/listbox.hpp + third-party/guichan/include/guichan/widgets/radiobutton.hpp + third-party/guichan/include/guichan/widgets/scrollarea.hpp + third-party/guichan/include/guichan/widgets/slider.hpp + third-party/guichan/include/guichan/widgets/textbox.hpp + third-party/guichan/include/guichan/widgets/textfield.hpp + third-party/guichan/include/guichan/widgets/window.hpp + third-party/guichan/include/guichan/x.hpp ) set(stratagus_action_HDRS @@ -627,7 +623,6 @@ set(stratagus_tests_SRCS source_group(include FILES ${stratagus_generic_HDRS}) source_group(include\\action FILES ${stratagus_action_HDRS}) source_group(include\\animation FILES ${stratagus_animation_HDRS}) -source_group(include\\guichan FILES ${stratagus_guichan_HDRS}) source_group(include\\spell FILES ${stratagus_spell_HDRS}) @@ -635,7 +630,6 @@ set(stratagus_HDRS ${stratagus_generic_HDRS} ${stratagus_action_HDRS} ${stratagus_animation_HDRS} - ${stratagus_guichan_HDRS} ${stratagus_spell_HDRS} ${CMAKE_CURRENT_BINARY_DIR}/version-generated.h version-generated.h # This line is needed for CMake when generating Doxygen documentation @@ -777,6 +771,13 @@ include(CheckTypeSize) include(CheckFunctionExists) include(CheckSymbolExists) +add_library(guichan_lib ${guichan_SRCS} ${guichan_HDRS}) +target_include_directories(guichan_lib PUBLIC third-party/guichan/include) +if(BUILD_VENDORED_SDL) + add_dependencies(guichan_lib SDL2-static) +endif() + + # Windows RC compiler definitions if(WIN32) @@ -1196,7 +1197,7 @@ if (ENABLE_STDIO_REDIRECT) else () add_executable(stratagus src/stratagus/main.cpp) endif () -target_link_libraries(stratagus_lib PUBLIC ${stratagus_LIBS} ${CMAKE_DL_LIBS}) +target_link_libraries(stratagus_lib PUBLIC ${stratagus_LIBS} ${CMAKE_DL_LIBS} guichan_lib) target_link_libraries(stratagus PUBLIC stratagus_lib) target_include_directories(stratagus_lib PRIVATE third-party/mdns third-party/spiritless_po/include) diff --git a/src/editor/editloop.cpp b/src/editor/editloop.cpp index a82274af3a..5580829d86 100644 --- a/src/editor/editloop.cpp +++ b/src/editor/editloop.cpp @@ -64,7 +64,7 @@ #include "video.h" #include "widgets.h" -#include +#include extern void DoScrollArea(int state, bool fast, bool isKeyboard); extern void DrawGuichanWidgets(); diff --git a/src/guichan/cliprectangle.cpp b/src/guichan/cliprectangle.cpp deleted file mode 100644 index d064be9171..0000000000 --- a/src/guichan/cliprectangle.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1ux = 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 08e82eecd5..0000000000 --- a/src/guichan/color.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u> 16) & 0xFF; - g = (color >> 8) & 0xFF; - b = color & 0xFF; - } - - Color::Color(int r, int g, int b, int a) - { - this->r = r; - this->g = g; - this->b = b; - this->a = a; - } - - Color Color::operator+(const Color& color) const - { - Color result; - result.r = r + color.r; - result.g = g + color.g; - result.b = b + color.b; - result.a = 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; - result.r = r - color.r; - result.g = g - color.g; - result.b = b - color.b; - result.a = 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; - result.r = (int)(r * value); - result.g = (int)(g * value); - result.b = (int)(b * value); - result.a = a; - - result.r = (result.r>255?255:(result.r<0?0:result.r)); - result.g = (result.g>255?255:(result.g<0?0:result.g)); - result.b = (result.b>255?255:(result.b<0?0:result.b)); - - return result; - } - - bool Color::operator==(const Color& color) const - { - return r == color.r && g == color.g && b == color.b && a == color.a; - } - - bool Color::operator!=(const Color& color) const - { - return !(r == color.r && g == color.g && b == color.b && a == color.a); - } -} diff --git a/src/guichan/defaultfont.cpp b/src/guichan/defaultfont.cpp deleted file mode 100644 index 22babe3e4a..0000000000 --- a/src/guichan/defaultfont.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1udrawRectangle( 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) - { - if (x > (int)text.size() * 8) - { - return text.size(); - } - - return x / 8; - } -} diff --git a/src/guichan/exception.cpp b/src/guichan/exception.cpp deleted file mode 100644 index 09caf32b95..0000000000 --- a/src/guichan/exception.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u // for isascii -#include -#include "guichan/focushandler.h" -#include "guichan/exception.h" - -namespace gcn -{ - FocusHandler::FocusHandler() - { - mFocusedWidget = NULL; - mDraggedWidget = NULL; - mToBeFocused = NULL; - mToBeDragged = NULL; - mModalFocusedWidget = NULL; - } - - void FocusHandler::requestFocus(Widget* widget) - { - mToBeFocused = widget; - } - - void FocusHandler::setFocus(Widget* widget) - { - mFocusedWidget = widget; - } - - void FocusHandler::requestDrag(Widget* widget) - { - mToBeDragged = widget; - } - - void FocusHandler::requestModalFocus(Widget* widget) - { - if (mModalFocusedWidget != NULL && mModalFocusedWidget != widget) - { - assert(!"Another widget allready has modal focus."); - //throw GCN_EXCEPTION("Another widget allready has modal focus."); - } - - mModalFocusedWidget = widget; - - if (mFocusedWidget != NULL && !mFocusedWidget->hasModalFocus()) - { - focusNone(); - } - - if (mDraggedWidget != NULL && !mDraggedWidget->hasModalFocus()) - { - dragNone(); - } - } - - void FocusHandler::releaseModalFocus(Widget* widget) - { - if (mModalFocusedWidget == widget) - { - mModalFocusedWidget = NULL; - } - } - - Widget* FocusHandler::getFocused() const - { - return mFocusedWidget; - } - - Widget* FocusHandler::getDragged() const - { - return mDraggedWidget; - } - - Widget* FocusHandler::getModalFocused() const - { - return mModalFocusedWidget; - } - - 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); - mWidgets.at(focusedWidget)->gotFocus(); - } - - if (focused >= 0) - { - mWidgets.at(focused)->lostFocus(); - } - } - - void FocusHandler::focusPrevious() - { - if (mWidgets.size() == 0) - { - mFocusedWidget = NULL; - return; - } - - int i; - int focusedWidget = -1; - for (i = 0; i < (int)mWidgets.size(); ++i) - { - if (mWidgets[i] == mFocusedWidget) - { - focusedWidget = i; - } - } - int focused = focusedWidget; - - // i is a counter that ensures that the following loop - // won't get stuck in an infinite loop - i = (int)mWidgets.size(); - do - { - --focusedWidget; - - if (i==0) - { - focusedWidget = -1; - break; - } - - --i; - - if (focusedWidget <= 0) - { - focusedWidget = mWidgets.size() - 1; - } - - if (focusedWidget == focused) - { - return; - } - } - while (!mWidgets.at(focusedWidget)->isFocusable()); - - if (focusedWidget >= 0) - { - mFocusedWidget = mWidgets.at(focusedWidget); - mWidgets.at(focusedWidget)->gotFocus(); - } - - if (focused >= 0) - { - mWidgets.at(focused)->lostFocus(); - } - } - - bool FocusHandler::hasFocus(const Widget* widget) const - { - return mFocusedWidget == widget; - } - - bool FocusHandler::isDragged(const Widget* widget) const - { - return mDraggedWidget == widget; - } - - void FocusHandler::add(Widget* widget) - { - mWidgets.push_back(widget); - } - - void FocusHandler::remove(Widget* widget) - { - if (widget == mFocusedWidget) - { - mFocusedWidget = NULL; - } - if (widget == mDraggedWidget) - { - mDraggedWidget = NULL; - } - if (widget == mToBeFocused) - { - mToBeFocused = NULL; - } - if (widget == mToBeDragged) - { - mToBeDragged = NULL; - } - - if (hasFocus(widget)) - { - mFocusedWidget = NULL; - mToBeFocused = NULL; - } - - int i = 0; - WidgetIterator iter; - - for (iter = mWidgets.begin(); iter != mWidgets.end(); ++iter) - { - ++i; - - if ((*iter) == widget) - { - mWidgets.erase(iter); - return; - } - } - } - - void FocusHandler::focusNone() - { - - if (mFocusedWidget != NULL) - { - Widget* focused = mFocusedWidget; - mFocusedWidget = NULL; - focused->lostFocus(); - } - - mToBeFocused = NULL; - } - - void FocusHandler::dragNone() - { - mDraggedWidget = NULL; - } - - void FocusHandler::checkHotKey(const KeyInput &keyInput) - { - int keyin = keyInput.getKey().getValue(); - - for (int i = 0; i < (int)mWidgets.size(); ++i) - { - int hotKey = mWidgets[i]->getHotKey(); - - if (hotKey == 0) - { - continue; - } - - if ((isascii(keyin) && tolower(keyin) == hotKey) || keyin == hotKey) - { - if (keyInput.getType() == KeyInput::PRESS) - { - mWidgets[i]->hotKeyPress(); - if (mWidgets[i]->isFocusable()) - { - this->requestFocus(mWidgets[i]); - } - } - else - { - mWidgets[i]->hotKeyRelease(); - } - break; - } - } - } - - void FocusHandler::tabNext() - { - if (mFocusedWidget != NULL) - { - if (!mFocusedWidget->isTabOutEnabled()) - { - return; - } - } - - if (mWidgets.size() == 0) - { - mFocusedWidget = NULL; - return; - } - - int i; - int focusedWidget = -1; - for (i = 0; i < (int)mWidgets.size(); ++i) - { - if (mWidgets[i] == mFocusedWidget) - { - focusedWidget = i; - } - } - int focused = focusedWidget; - bool done = false; - - // i is a counter that ensures that the following loop - // won't get stuck in an infinite loop - i = (int)mWidgets.size(); - do - { - ++focusedWidget; - - if (i==0) - { - focusedWidget = -1; - break; - } - - --i; - - if (focusedWidget >= (int)mWidgets.size()) - { - focusedWidget = 0; - } - - if (focusedWidget == focused) - { - return; - } - - if (mWidgets.at(focusedWidget)->isFocusable() && - mWidgets.at(focusedWidget)->isTabInEnabled() && - (mModalFocusedWidget == NULL || - mWidgets.at(focusedWidget)->hasModalFocus())) - { - done = true; - } - } - while (!done); - - if (focusedWidget >= 0) - { - mFocusedWidget = mWidgets.at(focusedWidget); - mWidgets.at(focusedWidget)->gotFocus(); - } - - if (focused >= 0) - { - mWidgets.at(focused)->lostFocus(); - } - } - - void FocusHandler::tabPrevious() - { - if (mFocusedWidget != NULL) - { - if (!mFocusedWidget->isTabOutEnabled()) - { - return; - } - } - - if (mWidgets.size() == 0) - { - mFocusedWidget = NULL; - return; - } - - int i; - int focusedWidget = -1; - for (i = 0; i < (int)mWidgets.size(); ++i) - { - if (mWidgets[i] == mFocusedWidget) - { - focusedWidget = i; - } - } - int focused = focusedWidget; - bool done = false; - - // i is a counter that ensures that the following loop - // won't get stuck in an infinite loop - i = (int)mWidgets.size(); - do - { - --focusedWidget; - - if (i==0) - { - focusedWidget = -1; - break; - } - - --i; - - if (focusedWidget <= 0) - { - focusedWidget = mWidgets.size() - 1; - } - - if (focusedWidget == focused) - { - return; - } - - if (mWidgets.at(focusedWidget)->isFocusable() && - mWidgets.at(focusedWidget)->isTabInEnabled() && - (mModalFocusedWidget == NULL || - mWidgets.at(focusedWidget)->hasModalFocus())) - { - done = true; - } - } - while (!done); - - if (focusedWidget >= 0) - { - mFocusedWidget = mWidgets.at(focusedWidget); - mWidgets.at(focusedWidget)->gotFocus(); - } - - if (focused >= 0) - { - mWidgets.at(focused)->lostFocus(); - } - } - - void FocusHandler::applyChanges() - { - if (mToBeFocused != NULL) - { - unsigned int i = 0; - int toBeFocusedIndex = -1; - for (i = 0; i < mWidgets.size(); ++i) - { - if (mWidgets[i] == mToBeFocused) - { - toBeFocusedIndex = i; - break; - } - } - - if (toBeFocusedIndex < 0) - { - assert(!"Trying to focus a none existing widget."); - //throw GCN_EXCEPTION("Trying to focus a none existing widget."); - } - - Widget *oldFocused = mFocusedWidget; - - if (oldFocused != mToBeFocused) - { - mFocusedWidget = mWidgets.at(toBeFocusedIndex); - - if (oldFocused != NULL) - { - oldFocused->lostFocus(); - } - - mWidgets.at(toBeFocusedIndex)->gotFocus(); - } - mToBeFocused = NULL; - } - - if (mToBeDragged != NULL) - { - unsigned int i = 0; - int toBeDraggedIndex = -1; - for (i = 0; i < mWidgets.size(); ++i) - { - if (mWidgets[i] == mToBeDragged) - { - toBeDraggedIndex = i; - break; - } - } - - if (toBeDraggedIndex < 0) - { - assert(!"Trying to give drag to a none existing widget."); - //throw GCN_EXCEPTION("Trying to give drag to a none existing widget"); - } - - mDraggedWidget = mWidgets.at(toBeDraggedIndex); - mToBeDragged = NULL; - } - } -} diff --git a/src/guichan/gfont.cpp b/src/guichan/gfont.cpp deleted file mode 100644 index 4d662648ba..0000000000 --- a/src/guichan/gfont.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u x) - { - return i; - } - } - - return text.size(); - } -} diff --git a/src/guichan/graphics.cpp b/src/guichan/graphics.cpp deleted file mode 100644 index 53dd25e744..0000000000 --- a/src/guichan/graphics.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include "guichan/graphics.h" -#include "guichan/exception.h" -#include "guichan/font.h" - -namespace gcn -{ - - Graphics::Graphics() - { - mFont = NULL; - } - - bool Graphics::pushClipArea(Rectangle area) - { - if (mClipStack.empty()) - { - ClipRectangle carea; - carea.x = area.x; - carea.y = area.y; - carea.width = area.width; - carea.height = area.height; - mClipStack.push(carea); - return true; - } - - ClipRectangle top = mClipStack.top(); - ClipRectangle carea; - carea = area; - carea.xOffset = top.xOffset + carea.x; - carea.yOffset = top.yOffset + carea.y; - carea.x += top.xOffset; - carea.y += top.yOffset; - - bool result = carea.intersect(top); - - mClipStack.push(carea); - - return result; - } - - void Graphics::popClipArea() - { - - if (mClipStack.empty()) - { - assert(!"Tried to pop clip area from empty stack."); - //throw GCN_EXCEPTION("Tried to pop clip area from empty stack."); - } - - mClipStack.pop(); - } - - const ClipRectangle& Graphics::getCurrentClipArea() - { - if (mClipStack.empty()) - { - assert(!"The clip area stack is 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, unsigned int alignment) - { - if (mFont == NULL) - { - assert(!"No font set."); - //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: - assert(!"Unknown alignment."); - //throw GCN_EXCEPTION("Unknown alignment."); - } - } -} diff --git a/src/guichan/gui.cpp b/src/guichan/gui.cpp deleted file mode 100644 index 828147331a..0000000000 --- a/src/guichan/gui.cpp +++ /dev/null @@ -1,305 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include "guichan/exception.h" -#include "guichan/focushandler.h" -#include "guichan/gui.h" -#include "guichan/key.h" - -namespace gcn -{ - Gui::Gui() - { - mTop = NULL; - mInput = NULL; - mGraphics = NULL; - mFocusHandler = new FocusHandler(); - mTopHasMouse = false; - mTabbing = true; - mUseDirtyDrawing = true; - } - - Gui::~Gui() - { - if (Widget::widgetExists(mTop)) - { - setTop(NULL); - } - - delete mFocusHandler; - } - - void Gui::setTop(Widget* top) - { - if (mTop) - { - mTop->_setFocusHandler(NULL); - } - if (top) - { - top->_setFocusHandler(mFocusHandler); - top->setDirty(true); - } - - 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) - { - assert(!"No top widget set"); - //throw GCN_EXCEPTION("No top widget set"); - } - - if (mInput) - { - mInput->_pollInput(); - - while (!mInput->isMouseQueueEmpty()) - { - MouseInput mi = mInput->dequeueMouseInput(); - - // Send mouse input to every widget that has the mouse. - if (mi.x > 0 && mi.y > 0 - && mTop->getDimension().isPointInRect(mi.x, mi.y)) - { - if (!mTop->hasMouse()) - { - mTop->_mouseInMessage(); - } - - MouseInput mio = mi; - mio.x -= mTop->getX(); - mio.y -= mTop->getY(); - mTop->_mouseInputMessage(mio); - } - else if (mTop->hasMouse()) - { - mTop->_mouseOutMessage(); - } - - Widget* f = mFocusHandler->getFocused(); - Widget* d = mFocusHandler->getDragged(); - - // If the focused widget doesn't have the mouse, - // send the mouse input to the focused widget. - if (f != NULL && !f->hasMouse()) - { - int xOffset, yOffset; - f->getAbsolutePosition(xOffset, yOffset); - - MouseInput mio = mi; - mio.x -= xOffset; - mio.y -= yOffset; - - f->_mouseInputMessage(mio); - } - - // If the dragged widget is different from the focused - // widget, send the mouse input to the dragged widget. - if (d != NULL && d != f && !d->hasMouse()) - { - int xOffset, yOffset; - d->getAbsolutePosition(xOffset, yOffset); - - MouseInput mio = mi; - mio.x -= xOffset; - mio.y -= yOffset; - - d->_mouseInputMessage(mio); - } - - mFocusHandler->applyChanges(); - - } // end while - - while (!mInput->isKeyQueueEmpty()) - { - KeyInput ki = mInput->dequeueKeyInput(); - - if (mTabbing - && ki.getKey().getValue() == Key::TAB - && ki.getType() == KeyInput::PRESS) - { - if (ki.getKey().isShiftPressed()) - { - mFocusHandler->tabPrevious(); - } - else - { - mFocusHandler->tabNext(); - } - } - else - { - bool keyProcessed = false; - - // Send key inputs to the focused widgets - if (mFocusHandler->getFocused()) - { - if (mFocusHandler->getFocused()->isFocusable()) - { - keyProcessed = mFocusHandler->getFocused()->_keyInputMessage(ki); - } - else - { - mFocusHandler->focusNone(); - } - } - - if (!keyProcessed) - { - mFocusHandler->checkHotKey(ki); - } - } - - mFocusHandler->applyChanges(); - - } // end while - - } // end if - - mTop->logic(); - } - - void Gui::draw() - { - if (!mTop) - { - assert(!"No top widget set"); - //throw GCN_EXCEPTION("No top widget set"); - } - if (!mGraphics) - { - assert(!"No graphics set"); - //throw GCN_EXCEPTION("No graphics set"); - } - - if (!mUseDirtyDrawing || mTop->getDirty()) - { - mGraphics->_beginDraw(); - - // If top has a border, - // draw it before drawing top - if (mTop->getBorderSize() > 0) - { - Rectangle rec = mTop->getDimension(); - rec.x -= mTop->getBorderSize(); - rec.y -= mTop->getBorderSize(); - rec.width += 2 * mTop->getBorderSize(); - rec.height += 2 * mTop->getBorderSize(); - mGraphics->pushClipArea(rec); - mTop->drawBorder(mGraphics); - mGraphics->popClipArea(); - } - - mGraphics->pushClipArea(mTop->getDimension()); - mTop->draw(mGraphics); - mTop->setDirty(false); - mGraphics->popClipArea(); - - mGraphics->_endDraw(); - } - } - - void Gui::focusNone() - { - mFocusHandler->focusNone(); - } - - void Gui::setTabbingEnabled(bool tabbing) - { - mTabbing = tabbing; - } - - bool Gui::isTabbingEnabled() - { - return mTabbing; - } - - void Gui::setUseDirtyDrawing(bool useDirtyDrawing) - { - mUseDirtyDrawing = useDirtyDrawing; - } -} diff --git a/src/guichan/guichan.cpp b/src/guichan/guichan.cpp deleted file mode 100644 index 1665dbda70..0000000000 --- a/src/guichan/guichan.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include "guichan/image.h" -#include "guichan/exception.h" - -namespace gcn -{ - - ImageLoader* Image::mImageLoader = NULL; - - Image::Image() - { - mLoadedWithImageLoader = false; - } - - Image::Image(void* data, int width, int height) - { - mData = data; - mWidth = width; - mHeight = height; - mLoadedWithImageLoader = false; - } - - Image::Image(const std::string& filename) - { - if (mImageLoader == NULL) - { - assert(!"I have no ImageLoader!"); - //throw GCN_EXCEPTION("I have no ImageLoader!"); - } - - mLoadedWithImageLoader = true; - mImageLoader->prepare(filename); - mWidth = mImageLoader->getWidth(); - mHeight = mImageLoader->getHeight(); - mData = mImageLoader->finalize(); - } - - Image::~Image() - { - if (mLoadedWithImageLoader) - { - mImageLoader->free(this); - } - } - - int Image::getWidth() const - { - return mWidth; - } - - int Image::getHeight() const - { - return mHeight; - } - - void* Image::_getData() const - { - return mData; - } - - void Image::setImageLoader(ImageLoader* imageLoader) - { - mImageLoader = imageLoader; - } - - ImageLoader* Image::_getImageLoader() - { - return mImageLoader; - } -} diff --git a/src/guichan/imagefont.cpp b/src/guichan/imagefont.cpp deleted file mode 100644 index d4c2f2117f..0000000000 --- a/src/guichan/imagefont.cpp +++ /dev/null @@ -1,333 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include -#include "guichan/exception.h" -#include "guichan/imagefont.h" -#include "guichan/image.h" - -namespace gcn -{ - ImageFont::ImageFont(const std::string& filename, const std::string& glyphs) - { - if (Image::_getImageLoader() == NULL) - { - assert(!"I have no ImageLoader!"); - //throw GCN_EXCEPTION("I have no ImageLoader!"); - } - - ImageLoader* imageLoader = Image::_getImageLoader(); - mFilename = filename; - Image::_getImageLoader()->prepare(filename); - Color separator = Image::_getImageLoader()->getPixel(0, 0); - - int i = 0; - for (i=0; separator == imageLoader->getPixel(i, 0) - && i < imageLoader->getWidth(); ++i) - { - } - - if (i >= imageLoader->getWidth()) - { - assert(!"Corrupt image."); - //throw GCN_EXCEPTION("Corrupt image."); - } - - int j = 0; - for (j = 0; j < imageLoader->getHeight(); ++j) - { - if (separator == imageLoader->getPixel(i, j)) - { - break; - } - } - - mHeight = j; - int x = 0, y = 0; - unsigned char k; - - for (i=0; i < (int)glyphs.size(); ++i) - { - k = glyphs.at(i); - addGlyph(k, x, y, separator); - } - - int w = imageLoader->getWidth(); - int h = imageLoader->getHeight(); - void* data = imageLoader->finalize(); - - mImage = new Image(data, w, h); - mRowSpacing = 0; - mGlyphSpacing = 0; - } - - ImageFont::ImageFont(const std::string& filename, unsigned char glyphsFrom, unsigned char glyphsTo) - { - if (Image::_getImageLoader() == NULL) - { - assert(!"I have no ImageLoader!"); - //throw GCN_EXCEPTION("I have no ImageLoader!"); - } - - ImageLoader* imageLoader = Image::_getImageLoader(); - mFilename = filename; - Image::_getImageLoader()->prepare(filename); - Color separator = Image::_getImageLoader()->getPixel(0, 0); - - int i = 0; - for (i=0; separator == imageLoader->getPixel(i, 0) - && i < imageLoader->getWidth(); ++i) - { - } - - if (i >= imageLoader->getWidth()) - { - assert(!"Corrupt image."); - //throw GCN_EXCEPTION("Corrupt image."); - } - - int j = 0; - for (j = 0; j < imageLoader->getHeight(); ++j) - { - if (separator == imageLoader->getPixel(i, j)) - { - break; - } - } - - mHeight = j; - int x = 0, y = 0; - - for (i=glyphsFrom; igetWidth(); - int h = imageLoader->getHeight(); - void* data = imageLoader->finalize(); - - mImage = new Image(data, w, h); - mRowSpacing = 0; - mGlyphSpacing = 0; - } - - ImageFont::~ImageFont() - { - Image::_getImageLoader()->free(mImage); - delete mImage; - } - - int ImageFont::getWidth(unsigned char glyph) const - { - if (mGlyph[glyph].width == 0) - { - return mGlyph[(int)(' ')].width + mGlyphSpacing; - } - - return mGlyph[glyph].width + mGlyphSpacing; - } - - int ImageFont::getHeight() const - { - return mHeight + mRowSpacing; - } - - int ImageFont::drawGlyph(Graphics* graphics, unsigned char glyph, int x, int y) - { - // This is needed for drawing the Glyph in the middle if we have spacing - int yoffset = getRowSpacing() >> 1; - - if (mGlyph[glyph].width == 0) - { - graphics->drawRectangle(Rectangle(x, y + 1 + yoffset, mGlyph[(int)(' ')].width - 1, - mGlyph[(int)(' ')].height - 2)); - - return mGlyph[(int)(' ')].width + mGlyphSpacing; - } - - graphics->drawImage(mImage, mGlyph[glyph].x, mGlyph[glyph].y, x, - y + yoffset, mGlyph[glyph].width, mGlyph[glyph].height); - - return mGlyph[glyph].width + mGlyphSpacing; - } - - void ImageFont::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.at(i)); - } - } - - void ImageFont::setRowSpacing(int spacing) - { - mRowSpacing = spacing; - } - - int ImageFont::getRowSpacing() - { - return mRowSpacing; - } - - void ImageFont::setGlyphSpacing(int spacing) - { - mGlyphSpacing = spacing; - } - - int ImageFont::getGlyphSpacing() - { - return mGlyphSpacing; - } - - void ImageFont::addGlyph(unsigned char c, int &x, - int &y, const Color& separator) - { - ImageLoader* il = Image::_getImageLoader(); - - Color color; - do - { - ++x; - - if (x >= il->getWidth()) - { - y += mHeight + 1; - x = 0; - - if (y >= il->getHeight()) - { - std::string str; - std::ostringstream os(str); - os << "Image "; - os << mFilename; - os << " with font is corrupt near character '"; - os << c; - os << "'"; - //throw GCN_EXCEPTION(os.str()); - assert(0); - } - } - - color = il->getPixel(x, y); - - } while (color == separator); - - int w = 0; - - do - { - ++w; - - if (x+w >= il->getWidth()) - { - std::string str; - std::ostringstream os(str); - os << "Image "; - os << mFilename; - os << " with font is corrupt near character '"; - os << c; - os << "'"; - //throw GCN_EXCEPTION(os.str()); - assert(0); - } - - color = il->getPixel(x + w, y); - - } while (color != separator); - - mGlyph[c] = Rectangle(x, y, w, mHeight); - - x += w; - } - - int ImageFont::getWidth(const std::string& text) const - { - unsigned int i; - int size = 0; - - for (i = 0; i < text.size(); ++i) - { - size += getWidth(text.at(i)); - } - - return size; - } - - int ImageFont::getStringIndexAt(const std::string& text, int x) - { - unsigned int i; - int size = 0; - - for (i = 0; i < text.size(); ++i) - { - size += getWidth(text.at(i)); - - if (size > x) - { - return i; - } - } - - return text.size(); - } -} diff --git a/src/guichan/include/guichan.h b/src/guichan/include/guichan.h deleted file mode 100644 index 595222a12b..0000000000 --- a/src/guichan/include/guichan.h +++ /dev/null @@ -1,107 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "guichan/platform.h" - -extern "C" -{ - /** - * Gets the the version of Guichan. As it is a C function - * it can be used to check for Guichan with autotools. - * - * @return the version of Guichan. - */ - GCN_CORE_DECLSPEC extern const char* gcnGuichanVersion(); -} - -#endif // end GCN_GUICHAN_HPP diff --git a/src/guichan/include/guichan/actionlistener.h b/src/guichan/include/guichan/actionlistener.h deleted file mode 100644 index eed54f35bb..0000000000 --- a/src/guichan/include/guichan/actionlistener.h +++ /dev/null @@ -1,92 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -#include "guichan/platform.h" - -namespace gcn -{ - /** - * Listener of action events from Widgets. To be able to - * listen for actions you must make a class which inherits - * from this class and implements the action function. - * - * @see Widget::addActionListener - */ - class GCN_CORE_DECLSPEC ActionListener - { - public: - - /** - * Destructor. - */ - virtual ~ActionListener() { } - - /** - * Called whan an action is recieved from a Widget. It is used - * to be able to recieve a notification that an action has - * occured. - * - * @param eventId the identifier of the Widget. - */ - virtual void action(const std::string& eventId) = 0; - - }; -} - -#endif // end GCN_ACTIONLISTENER_HPP diff --git a/src/guichan/include/guichan/allegro.h b/src/guichan/include/guichan/allegro.h deleted file mode 100644 index 8e3bdc18e8..0000000000 --- a/src/guichan/include/guichan/allegro.h +++ /dev/null @@ -1,72 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include -#include - -extern "C" -{ - /** - * Exists to be able to check for Guichan Allegro with autotools. - * - * @bug Autotools is incapable of finding this function. - */ - extern void gcnAllegro(); -} - -#endif // end GCN_ALLEGRO_HPP diff --git a/src/guichan/include/guichan/basiccontainer.h b/src/guichan/include/guichan/basiccontainer.h deleted file mode 100644 index 6316fc04d9..0000000000 --- a/src/guichan/include/guichan/basiccontainer.h +++ /dev/null @@ -1,132 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naess�n a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -#include "guichan/platform.h" -#include "guichan/graphics.h" -#include "guichan/widget.h" - -namespace gcn -{ - /** - * Containers base class. Contains basic container functions every - * container should have. Containers should inherit from this class and - * implement it's functions. - * - * @see Container - */ - class GCN_CORE_DECLSPEC BasicContainer: public Widget - { - public: - - virtual ~BasicContainer() { } - - /** - * Moves a Widget to the top of the BasicContainer. The widget will be - * drawn above all other Widgets in the BasicContainer. - * - * @param widget the Widget to move. - */ - virtual void moveToTop(Widget* widget) = 0; - - /** - * Moves a widget to the bottom of the BasicContainer. The Widget will - * be drawn below all other Widgets in the BasicContainer. - * - * @param widget the Widget to move. - */ - virtual void moveToBottom(Widget* widget) = 0; - - /** - * Gets the drawing space size a Widget has in the BasicContainer. - * It may not be the same size as the Widgets width and height. - * - * NOTE: Size is not checked recursively all the way back to the - * top Widget. If the BasicContainer itself is clipped, - * the size may be inaccurate. - * - * @param width the width the Widget's draw space has. - * @param height the height the Widget's draw space has. - * @param widget the Widget calling the function. - */ - virtual void getDrawSize(int& width, int& height, Widget* widget) = 0; - - /** - * Called when a child of the BasicContainer gets destroyed. - * - * @param widget the destroyed Widget. - */ - virtual void _announceDeath(Widget *widget) = 0; - - /** - * Function to check if a widget regards this container as parent. This - * avoids using function calls so it can work with garbage collected widgets - * from Lua. - * - * @param widget - * @return true if the parent pointer of the widget points to this container - * @return false if the parent pointer of the widget points to something else - */ - bool isParentOfWidget(Widget *widget) { - return widget->mParent == this; - } - - }; -} - -#endif // end GCN_BASICCONTAINER_HPP diff --git a/src/guichan/include/guichan/cliprectangle.h b/src/guichan/include/guichan/cliprectangle.h deleted file mode 100644 index aebab98388..0000000000 --- a/src/guichan/include/guichan/cliprectangle.h +++ /dev/null @@ -1,108 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -#include "guichan/platform.h" - - -#if _MSC_VER <= 1200 -#define __FUNCTION__ "?" -#endif - -/* - * A macro to be used when throwing exceptions. - * What it basicly does is that it creates a new exception - * and automatically sets the filename and line number where - * the exception occured. - */ -#define GCN_EXCEPTION(mess) gcn::Exception(mess, \ - __FUNCTION__, \ - __FILE__, \ - __LINE__) - -namespace gcn -{ - - /** - * An exception containing a message, a file and a line number. - * Guichan will only throw exceptions of this class. You can use - * this class for your own exceptions. A nifty feature of the - * excpetion class is that it can tell you from which line and - * file it was thrown. To make things easier when throwing - * exceptions there exists a macro for creating exceptions - * which automatically sets the filename and line number. - * - * EXAMPLE: @code - * throw GCN_EXCEPTION("my error message"); - * @endcode - */ - class GCN_CORE_DECLSPEC Exception - { - public: - - /** - * Constructor. - */ - Exception(); - - /** - * Constructor. - * - * @param message the error message. - */ - Exception(const std::string& message); - - /** - * Constructor. - * - * NOTE: Don't use this constructor. Use the GCN_EXCEPTION macro instead. - * - * @param message the error message. - * @param function the function name. - * @param filename the name of the file. - * @param line the line number. - */ - Exception(const std::string& message, - const std::string& function, - const std::string& filename, - int line); - - /** - * Gets the function name in which the exception was thrown. - * - * @return the function name in which the exception was thrown. - */ - const std::string& getFunction() const; - - /** - * Gets the error message of the exception. - * - * @return the error message. - */ - const std::string& getMessage() const; - - /** - * Gets the filename in which the exceptions was thrown. - * - * @return the filename in which the exception was thrown. - */ - const std::string& getFilename() const; - - /** - * Gets the line number of the line where the exception was thrown. - * - * @return the line number of the line where the exception was thrown. - */ - int getLine() const; - - protected: - std::string mFunction; - std::string mMessage; - std::string mFilename; - int mLine; - }; -} - -#endif // end GCN_EXCEPTION_HPP - -/* - * "Final Fantasy XI is the BEST!... It's even better then water!" - * - Astrolite - * I believe it's WoW now days. - */ diff --git a/src/guichan/include/guichan/focushandler.h b/src/guichan/include/guichan/focushandler.h deleted file mode 100644 index add308b1e5..0000000000 --- a/src/guichan/include/guichan/focushandler.h +++ /dev/null @@ -1,244 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -#include "guichan/platform.h" -#include "guichan/widget.h" - -namespace gcn -{ - class Widget; - - /** - * Used to keep track of widget focus. You will probably not have - * to use the FocusHandler directly to handle focus. Widget has - * functions for handling focus which uses a FocusHandler. Use them - * instead. - * - * @see Widget::hasFocus - * @see Widget::requestFocus - * @see Widget::setFocusable - * @see Widget::isFocusable - * @see Widget::gotFocus - * @see Widget::lostFocus - */ - class GCN_CORE_DECLSPEC FocusHandler - { - public: - - /** - * Constructor. - */ - FocusHandler(); - - /** - * Destructor. - */ - virtual ~FocusHandler() { }; - - /** - * Sets focus to a Widget. Widget::lostFocus and - * Widget::gotFocus will be called. - * - * @param widget the Widget to focus. - */ - virtual void requestFocus(Widget* widget); - - /** - * Sets focus immediately. - */ - virtual void setFocus(Widget* widget); - - /** - * Sets drag to a Widget. - * - * @param widget the Widget to drag. - */ - virtual void requestDrag(Widget* widget); - - /** - * Sets modal focus to a Widget. If another Widget already - * has modal focus will an exception be thrown. - * - * @param widget the Widget to focus modal. - * @throws Exception when another widget already has modal focus. - */ - virtual void requestModalFocus(Widget* widget); - - /** - * Releases modal focus if the Widget has modal focus. - * Otherwise nothing will be done. - * - * @param widget the Widget to release modal focus for. - */ - virtual void releaseModalFocus(Widget* widget); - - /** - * Gets the Widget with focus. - * - * @return the Widget with focus. NULL will be returned if - * no Widget has focus. - */ - virtual Widget* getFocused() const; - - /** - * Gets the widget that is dragged. - * - * @return the widget that is dragged. NULL will be returned - * if no Widget is dragged. - */ - virtual Widget* getDragged() const; - - /** - * Gets the Widget with modal focus. - * - * @return the Widget with modal focus. NULL will be returned - * if no Widget has modal focus. - */ - virtual Widget* getModalFocused() const; - - /** - * Focuses the next Widget. If no Widget has focus the first - * Widget gets focus. The order in which the Widgets are focused - * depends on the order you add them to the GUI. - */ - virtual void focusNext(); - - /** - * Focuses the previous Widget. If no Widget has focus the first - * Widget gets focus. The order in which the widgets are focused - * depends on the order you add them to the GUI. - */ - virtual void focusPrevious(); - - /** - * Checks if a Widget has focus. - * - * @param widget widget to check if it has focus.. - * @return true if the widget has focus. - */ - virtual bool hasFocus(const Widget* widget) const; - - /** - * Checks if a widget is being dragged - * - * @param widget the Widget to check if it is being dragged. - * @return true if the widget is being dragged. - */ - virtual bool isDragged(const Widget* widget) const; - - /** - * Adds a widget to the FocusHandler. - * - * @param widget the widget to add. - */ - virtual void add(Widget* widget); - - /** - * Removes a widget from the FocusHandler. - * - * @param widget the widget to remove. - */ - virtual void remove(Widget* widget); - - /** - * Focuses nothing. - */ - virtual void focusNone(); - - /** - * Focuses the next Widget which allows tab in unless current focused - * Widget disallows tab out. - */ - virtual void tabNext(); - - /** - * Focuses the previous Widget which allows tab in unless current focused - * Widget disallows tab out. - */ - virtual void tabPrevious(); - - /** - * Applies the changes. - */ - virtual void applyChanges(); - - /** - * Drag nothing. - */ - virtual void dragNone(); - - /** - * Check if a hot key was pressed. - */ - virtual void checkHotKey(const KeyInput &keyInput); - - protected: - typedef std::vector WidgetVector; - typedef WidgetVector::iterator WidgetIterator; - WidgetVector mWidgets; - - Widget* mFocusedWidget; - Widget* mDraggedWidget; - Widget* mToBeFocused; - Widget* mToBeDragged; - Widget* mModalFocusedWidget; - }; -} - -#endif // end GCN_FOCUSHANDLER_HPP diff --git a/src/guichan/include/guichan/font.h b/src/guichan/include/guichan/font.h deleted file mode 100644 index 319625d625..0000000000 --- a/src/guichan/include/guichan/font.h +++ /dev/null @@ -1,120 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include - -#include "guichan/cliprectangle.h" -#include "guichan/color.h" -#include "guichan/image.h" -#include "guichan/platform.h" - -namespace gcn -{ - class Font; - - /** - * Used for drawing graphics. It contains all vital functions for drawing. - * We include implemented Graphics classes for some common platforms like the - * Allegro library, the OpenGL library and the SDL library. To make Guichan - * usable under another platform, a Graphics class must be implemented. - * - * In Graphics you can set clip areas to limit drawing to certain - * areas of the screen. Clip areas are put on a stack, which means that you - * can push smaller and smaller clip areas onto the stack. All coordinates - * will be relative to the topmost clip area. In most cases you won't have - * to worry about the clip areas, unless you want to implement some really - * complex widget. Pushing and poping of clip areas are handled automatically - * by container widgets when their child widgets are drawn. - * - * IMPORTANT: Remember to pop each clip area that you pushed on the stack - * after you are done with it. - * - * If you feel that Graphics is to restrictive for your needs, there is - * no one stopping you from using your own code for drawing in Widgets. - * You could for instance use pure SDL in the drawing of Widgets bypassing - * Graphics. This might however hurt portability of your application. - * - * If you implement a Graphics class not present in Guichan we would be very - * happy to add it to Guichan. - * - * @see AllegroGraphics, OpenGLGraphics, SDLGraphics, Image - */ - class GCN_CORE_DECLSPEC Graphics - { - public: - Graphics(); - - virtual ~Graphics() { } - - /** - * Initializes drawing. Called by the Gui when Gui::draw() is called. - * It is needed by some implementations of Graphics to perform - * preparations before drawing. An example of such an implementation - * would be OpenGLGraphics. - * - * NOTE: You will never need to call this function yourself. - * Gui will do it for you. - * - * @see _endDraw, Gui::draw - */ - virtual void _beginDraw() { } - - /** - * Deinitializes drawing. Called by the Gui when a Gui::draw() is done. - * done. It should reset any state changes made by _beginDraw(). - * - * NOTE: You will never need to call this function yourself. - * Gui will do it for you. - * - * @see _beginDraw, Gui::draw - */ - virtual void _endDraw() { } - - /** - * Pushes a clip area onto the stack. The x and y coordinates in the - * Rectangle will be relative to the last pushed clip area. - * If the new area falls outside the current clip area, it will be - * clipped as necessary. - * - * @param area the clip area to be pushed onto the stack. - * @return false if the the new area lays totally outside the - * current clip area. Note that an empty clip area - * will be pused in this case. - */ - virtual bool pushClipArea(Rectangle area); - - /** - * Removes the topmost clip area from the stack. - * - * @throws Exception if the stack is empty. - */ - virtual void popClipArea(); - - /** - * Gets the current ClipArea. Usefull if you want to do drawing - * bypassing Graphics. - * - * @return the current ClipArea. - */ - virtual const ClipRectangle& getCurrentClipArea(); - - /** - * Draws a part of an Image. - * - * NOTE: Width and height arguments will not scale the Image but - * specifies the size of the part to be drawn. If you want - * to draw the whole Image there is a simplified version of - * this function. - * - * EXAMPLE: @code drawImage(myImage, 10, 10, 20, 20, 40, 40); @endcode - * Will draw a rectangular piece of myImage starting at coordinate - * (10, 10) in myImage, with width and height 40. The piece will be - * drawn with it's top left corner at coordinate (20, 20). - * - * @param image the Image to draw. - * @param srcX source Image x coordinate. - * @param srcY source Image y coordinate. - * @param dstX destination x coordinate. - * @param dstY destination y coordinate. - * @param width the width of the piece. - * @param height the height of the piece. - */ - virtual void drawImage(const Image* image, int srcX, int srcY, - int dstX, int dstY, int width, - int height) = 0; - /** - * Draws an image. A simplified version of the other drawImage. - * It will draw a whole image at the coordinate you specify. - * It is equivalent to calling: - * @code drawImage(myImage, 0, 0, dstX, dstY, image->getWidth(), image->getHeight()); @endcode - */ - virtual void drawImage(const Image* image, int dstX, int dstY); - - /** - * Draws a single point/pixel. - * - * @param x the x coordinate. - * @param y the y coordinate. - */ - virtual void drawPoint(int x, int y) = 0; - - /** - * Ddraws a line. - * - * @param x1 the first x coordinate. - * @param y1 the first y coordinate. - * @param x2 the second x coordinate. - * @param y2 the second y coordinate. - */ - virtual void drawLine(int x1, int y1, int x2, int y2) = 0; - - /** - * Draws a simple, non-filled, Rectangle with one pixel width. - * - * @param rectangle the Rectangle to draw. - */ - virtual void drawRectangle(const Rectangle& rectangle) = 0; - - /** - * Draws a filled Rectangle. - * - * @param rectangle the filled Rectangle to draw. - */ - virtual void fillRectangle(const Rectangle& rectangle) = 0; - - /** - * Sets the Color to use when drawing. - * - * @param color a Color. - */ - virtual void setColor(const Color& color) = 0; - - /** - * Gets the Color to use when drawing. - * - * @return the Color used when drawing. - */ - virtual const Color& getColor() = 0; - - /** - * Sets the font to use when drawing text. - * - * @param font the Font to use when drawing. - */ - virtual void setFont(Font* font); - - /** - * Draws text. - * - * @param text the text to draw. - * @param x the x coordinate where to draw the text. - * @param y the y coordinate where to draw the text. - * @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. - * @throws Exception when no Font is set. - */ - virtual void drawText(const std::string& text, int x, int y, unsigned int alignment = LEFT); - /** - * Alignments for text drawing. - */ - enum - { - LEFT = 0, - CENTER, - RIGHT - }; - - protected: - std::stack mClipStack; - Font* mFont; - }; -} - -#endif // end GCN_GRAPHICS_HPP - -/* - * yakslem - "little cake on cake, but that's the fall" - * finalman - "skall jag skriva det?" - * yakslem - "ja, varfor inte?" - */ - diff --git a/src/guichan/include/guichan/gsdl.h b/src/guichan/include/guichan/gsdl.h deleted file mode 100644 index 14bead611e..0000000000 --- a/src/guichan/include/guichan/gsdl.h +++ /dev/null @@ -1,71 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include - -#include "platform.h" - -extern "C" -{ - /** - * Exists to be able to check for Guichan SDL with autotools. - */ - GCN_EXTENSION_DECLSPEC extern void gcnSDL(); -} - -#endif // end GCN_SDL_HPP diff --git a/src/guichan/include/guichan/gui.h b/src/guichan/include/guichan/gui.h deleted file mode 100644 index d359460ce2..0000000000 --- a/src/guichan/include/guichan/gui.h +++ /dev/null @@ -1,201 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -#include "guichan/input.h" -#include "guichan/platform.h" -#include "guichan/widget.h" - -namespace gcn -{ - // The following comment will appear in the doxygen main page. - /** - * @section Introduction - * This documentation is mostly intended as a reference to the API. If you want to get started with Guichan, we suggest you check out the programs in the examples directory of the Guichan release. - * @n - * @n - * This documentation is, and will always be, work in progress. If you find any errors, typos or inconsistencies, or if you feel something needs to be explained in more detail - don't hesitate to tell us. - */ - - /** - * Gui core class. Contains a special widget called the top widget. - * If you want to be able to have more then one Widget in your Gui, - * the top widget should be a Container. - * - * NOTE: For the Gui to function properly you need to set a Graphics - * object to use and an Input object to use. - */ - class GCN_CORE_DECLSPEC Gui - { - public: - - /** - * Constructor. - */ - Gui(); - - /** - * Destructor. - */ - virtual ~Gui(); - - /** - * Sets the top Widget. - * - * @param top the top Widget. - */ - virtual void setTop(Widget* top); - - /** - * Gets the top Widget. - * - * @return the top widget. NULL if no top widget has been set. - */ - virtual Widget* getTop() const; - - /** - * Sets the Graphics object to use for drawing. - * - * @param graphics the Graphics object to use for drawing. - * @see SDLGraphics, OpenGLGraphics, AllegroGraphics - */ - virtual void setGraphics(Graphics* graphics); - - /** - * Gets the Graphics object used for drawing. - * - * @return the Graphics object used for drawing. NULL if no - * Graphics object has been set. - */ - virtual Graphics* getGraphics() const; - - /** - * Sets the Input object to use for input handling. - * - * @param input the Input object to use for input handling. - * @see SDLInput, AllegroInput - */ - virtual void setInput(Input* input); - - /** - * Gets the Input object being used for input handling. - * - * @return the Input object used for handling input. NULL if no - * Input object has been set. - */ - virtual Input* getInput() const; - - /** - * Performs the Gui logic. By calling this function all logic - * functions down in the Gui heirarchy will be called. - * What performs in Logic can be just about anything like - * adjusting a Widgets size or doing some calculations. - * - * NOTE: Logic also deals with user input (Mouse and Keyboard) - * for Widgets. - */ - virtual void logic(); - - /** - * Draws the Gui. By calling this funcion all draw functions - * down in the Gui hierarchy will be called. - */ - virtual void draw(); - - /** - * Focus none of the Widgets in the Gui. - */ - virtual void focusNone(); - - /** - * Toggles the use of the tab key to focus Widgets. - * By default, tabbing is enabled. - * - * @param tabbing set to false if you want to disable tabbing. - */ - virtual void setTabbingEnabled(bool tabbing); - - /** - * Checks if tabbing is enabled. - * - * @return true if tabbing is enabled. - */ - virtual bool isTabbingEnabled(); - - virtual void setUseDirtyDrawing(bool useDirtyDrawing); - - protected: - bool mTopHasMouse; - bool mTabbing; - - Widget* mTop; - Graphics* mGraphics; - Input* mInput; - FocusHandler* mFocusHandler; - bool mUseDirtyDrawing; - }; -} - -#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.h b/src/guichan/include/guichan/image.h deleted file mode 100644 index 2137e5e1ad..0000000000 --- a/src/guichan/include/guichan/image.h +++ /dev/null @@ -1,162 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -#include "guichan/imageloader.h" -#include "guichan/platform.h" - -namespace gcn -{ - /** - * Holds an image. To be able to use this class you must first set an - * ImageLoader in Image by calling - * @code Image::setImageLoader(myImageLoader) @endcode - * The function is static. If this is not done, the constructor taking a - * filename will throw an exception. The ImageLoader you use must be - * compatible with the Graphics object you use. - * - * EXAMPLE: If you use SDLGraphics you should use SDLImageLoader. - * Otherwise your program will crash in a most bizarre way. - */ - class GCN_CORE_DECLSPEC Image - { - public: - - /** - * Constructor. - * - * @param data the data of the image. - * @param width the width of the image. - * @param height the height of the image. - */ - Image(void* data, int width, int height); - - /** - * Constructor. - * - * @param filename the filename of the image. - * @throws Exception when no ImageLoader exists. - */ - Image(const std::string& filename); - - /** - * Destructor. Unloads the image with the ImageLoader, - * if it was loaded with it. - */ - virtual ~Image(); - - /** - * Gets the width of the Image. - * - * @return the image width - */ - virtual int getWidth() const; - - /** - * Gets the height of the Image. - * - * @return the image height - */ - virtual int getHeight() const; - - /** - * Gets the data of the Image. Image data can be different things - * depending on what ImageLoader you use. If you for instance use the - * SDLImageLoader then an SDL_Surface will be returned. - * - * @return a void pointer to the Image data. - * @see SDLImageLoader, AllegroImageLoader - */ - virtual void* _getData() const; - - virtual bool isDirty() const { return false; }; - - /** - * Gets the ImageLoader used for loading Images. - * - * @return the ImageLoader used for loading Images. - * @see SDLImageLoader, AllegroImageLoader - */ - static ImageLoader* _getImageLoader(); - - /** - * Sets the ImageLoader to be used for loading images. - * - * IMPORTANT: The ImageLoader is static and MUST be set before loading - * images! - * - * @param imageLoader the ImageLoader to be used for loading images. - * @see SDLImageLoader, AllegroImageLoader - */ - static void setImageLoader(ImageLoader* imageLoader); - - protected: - /** - * Default constructor. It is protected so you can inherit - * from this class. - */ - Image(); - void* mData; - int mWidth; - int mHeight; - bool mLoadedWithImageLoader; - static ImageLoader* mImageLoader; - }; -} - -#endif // end GCN_IMAGE_HPP diff --git a/src/guichan/include/guichan/imagefont.h b/src/guichan/include/guichan/imagefont.h deleted file mode 100644 index 1b5d00d87b..0000000000 --- a/src/guichan/include/guichan/imagefont.h +++ /dev/null @@ -1,206 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include - -#include "guichan/font.h" -#include "guichan/graphics.h" -#include "guichan/image.h" -#include "guichan/platform.h" - -namespace gcn -{ - /** - * A font using an image containing the font data. It implements the font - * class. You can use any filetype for the font data as long as it can be - * loaded with your ImageLoader. - * - * This are two examples of an image containing a font. - * \image html imagefontexample.bmp - * \image html imagefontexample2.bmp - * - * The Image font format works like this: The first pixel, the pixal at - * coordinate (0,0), tells which color to look for when seperating glyphs. - * You create an image with your glyphs and simple separates them with - * the seperation color. When you create your ImageFont you supply the - * constructor with the glyphs present in your image. When creating an - * ImageFont for the image data in the first example above, the following - * constructor call would be used. - * @code gcn::ImageFont imageFont("fixedfont_big.bmp"," abcdefghijklmno\ -pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); @endcode - * Noteworthy is that the first glyph actually gives the width of space. - * Glyphs can, as seen in the second example above, be seperated with - * horizontal lines making it possible to draw glyphs on more then one - * line in the image. However, these vertical lines must be of one pixel - * size! - */ - class GCN_CORE_DECLSPEC ImageFont: public Font - { - public: - - /** - * Constructor which takes an image file containing the font and - * a string containing the glyphs. The glyphs in the string should - * be in the same order as they appear in the font image. - * - * @param filename the filename of the image. - * @param glyphs the glyphs found in the image. - * @throws Exception when glyph list is incorrect or the font file is - * corrupt or if no ImageLoader exists. - */ - ImageFont(const std::string& filename, const std::string& glyphs); - - /** - * Constructor which takes an image file containing the font and - * two boundaries of ASCII values. The font image should include - * all glyphs specified with the boundaries in increasing ASCII - * order. The boundaries are inclusive. - * - * @param filename the filename of the image. - * @param glyphsFrom the ASCII value of the first glyph found in the - * image. - * @param glyphsTo the ASCII value of the last glyph found in the - * image. - * @throws Exception when glyph bondaries are incorrect or the font - * file is corrupt or if no ImageLoader exists. - */ - ImageFont(const std::string& filename, unsigned char glyphsFrom=32, unsigned char glyphsTo=126); - - /** - * Destructor. - */ - virtual ~ImageFont(); - - /** - * Draws a glyph. - * - * NOTE: You normally won't use this function to draw text since - * the Graphics class contains better functions for drawing - * text. - * - * @param graphics a graphics object to be used for drawing. - * @param glyph a glyph to draw. - * @param x the x coordinate where to draw the glyph. - * @param y the y coordinate where to draw the glyph. - * @return the width of the glyph in pixels. - * @see Graphics - */ - virtual int drawGlyph(Graphics* graphics, unsigned char glyph, int x, int y); - - /** - * Sets the spacing between rows in pixels. Default is 0 pixels. - * The spacing can be negative. - * - * @param spacing the spacing in pixels. - */ - virtual void setRowSpacing(int spacing); - - /** - * Gets the spacing between rows in pixels. - * - * @return the spacing. - */ - virtual int getRowSpacing(); - - /** - * Sets the spacing between letters in pixels. Default is 0 pixels. - * The spacing can be negative. - * - * @param spacing the spacing in pixels - */ - virtual void setGlyphSpacing(int spacing); - - /** - * Gets the spacing between letters in pixels. - * - * @return the spacing. - */ - virtual int getGlyphSpacing(); - - /** - * Gets a width of a glyph. - * - * @param glyph the glyph which width will be returned - * @return the width of a glyph - */ - virtual int getWidth(unsigned char glyph) const; - - - // Inherited from Font - - virtual int getWidth(const std::string& text) const; - - virtual void drawString(Graphics* graphics, const std::string& text, int x, int y); - - virtual int getHeight() const; - - virtual int getStringIndexAt(const std::string& text, int x); - - protected: - void addGlyph(unsigned char c, int &x, int &y, const Color& separator); - - Rectangle mGlyph[256]; - int mHeight; - int mGlyphSpacing; - int mRowSpacing; - Image* mImage; - std::string mFilename; - }; -} - -#endif // end GCN_IMAGEFONT_HPP diff --git a/src/guichan/include/guichan/imageloader.h b/src/guichan/include/guichan/imageloader.h deleted file mode 100644 index ee80dc56ba..0000000000 --- a/src/guichan/include/guichan/imageloader.h +++ /dev/null @@ -1,164 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -#include "guichan/color.h" -#include "guichan/platform.h" - -namespace gcn -{ - class Image; - - /** - * ImageLoaders base class. Contains basic image loading functions every - * image loader should have. Image loaders should inherit from this - * class and impements it's functions. - */ - class GCN_CORE_DECLSPEC ImageLoader - { - public: - - /** - * Destructor. - */ - virtual ~ImageLoader() { } - - /** - * Prepares an image for reading. After you have called this function - * you can retrieve information about it and edit it. - * - * @param filename the image file to prepare. - * @throws Exception when called without having finalized or disposed to - * last image or when unable to load the image. - */ - virtual void prepare(const std::string& filename) = 0; - - /** - * This function frees an image. - * - * NOTE: There is generally no reason to call this function as - * it is called upon by the Image object when destroying an Image. - * - * @param image the image to be freed and removed. - * @throws Exception when image points to NULL. - */ - virtual void free(Image* image) = 0; - - /** - * Rreturns a pointer of raw data of an image. The raw data is in 32 - * bit RGBA format. The funcion will not free a prepared image, so - * finalize or discard should be used afterwards. - * - * @return a pointer to the raw image data. - */ - virtual void* getRawData() = 0; - - /** - * Finalizes an image meaning it will return the image data. If the - * image contains pixels with "magic pink" (0xff00ff) they will be - * treated as transparent pixels. - * - * @return a pointer to the image data. - * @throws Exception when no image has been prepared. - */ - virtual void* finalize() = 0; - - /** - * Discards a prepared image. - * - * @throws Exception when no image has been prepared. - */ - virtual void discard() = 0; - - /** - * Gets the height if the image. - * - * @return the height of the image. - * @throws Exception if no image have been prepared. - */ - virtual int getHeight() const = 0; - - /** - * Gets the width of an image. - * - * @return the width of the image. - * @throws Exception if no image have been prepared. - */ - virtual int getWidth() const = 0; - - /** - * Gets the color of a pixel at coordinate x and y. - * - * @param x the x coordinate. - * @param y the y coordinate. - * @return the color of the pixel. - */ - virtual Color getPixel(int x, int y) = 0; - - /** - * Puts a pixel with a certain color at coordinate x and y. - * - * @param x the x coordinate. - * @param y the y coordinate. - * @param color the color of the pixel to put. - */ - virtual void putPixel(int x, int y, const Color& color) = 0; - }; -} - -#endif // end GCN_IMAGELOADER_HPP diff --git a/src/guichan/include/guichan/input.h b/src/guichan/include/guichan/input.h deleted file mode 100644 index f1725bb9d3..0000000000 --- a/src/guichan/include/guichan/input.h +++ /dev/null @@ -1,118 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -#include "guichan/platform.h" - -namespace gcn -{ - /** - * Represents a key or a character. - */ - class GCN_CORE_DECLSPEC Key - { - public: - /** - * Constructor. - */ - Key(); - - /** - * Constructor. - * - * @param value the ascii or enum value for the key. - */ - Key(int value); - - /** - * Checks whether a key is a character. - * - * @return true if the key is a letter, number or whitespace. - */ - bool isCharacter() const; - - /** - * Checks whether a key is a number. - * - * @return true if the key is a number (0-9). - */ - bool isNumber() const; - - /** - * Checks whether a key is a letter. - * - * @return true if the key is a letter (a-z,A-Z). - */ - bool isLetter() const; - - /** - * Checks whether shift is pressed. - * - * @return true if shift was pressed at the same time as the key. - */ - bool isShiftPressed() const; - - /** - * Sets the shift pressed flag. - * - * @param pressed the shift flag value. - */ - void setShiftPressed(bool pressed); - - /** - * Checks whether control is pressed. - * @return true if control was pressed at the same time as the key. - */ - bool isControlPressed() const; - - /** - * Sets the control pressed flag. - * - * @param pressed the control flag value. - */ - void setControlPressed(bool pressed); - - /** - * Checks whether alt is pressed. - * - * @return true if alt was pressed at the same time as the key. - */ - bool isAltPressed() const; - - /** - * Sets the alt pressed flag. - * - * @param pressed the alt flag value. - */ - void setAltPressed(bool pressed); - - /** - * Checks whether meta is pressed. - * - * @return true if meta was pressed at the same time as the key. - */ - bool isMetaPressed() const; - - /** - * Sets the meta pressed flag. - * - * @param pressed the meta flag value. - */ - void setMetaPressed(bool pressed); - - /** - * Checks whether the key was pressed at the numeric pad. - * - * @return true if key pressed at the numeric pad. - */ - bool isNumericPad() const; - - /** - * Sets the numeric pad flag. - * - * @param numpad the numeric pad flag value. - */ - void setNumericPad(bool numpad); - - /** - * 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; - - /** - * Sets the value of the key. An ascii value or an enum value. - * - * @param value the key value. - */ - void setValue(int value); - - /** - * An enum with key values. - */ - enum - { - SPACE = ' ', - TAB = '\t', - ENTER = '\n', - LEFT_ALT = 1000, - RIGHT_ALT, - LEFT_SHIFT, - RIGHT_SHIFT, - LEFT_CONTROL, - RIGHT_CONTROL, - LEFT_META, - RIGHT_META, - LEFT_SUPER, - RIGHT_SUPER, - INSERT, - HOME, - PAGE_UP, - DELETE, - END, - PAGE_DOWN, - ESCAPE, - CAPS_LOCK, - BACKSPACE, - F1, - F2, - F3, - F4, - F5, - F6, - F7, - F8, - F9, - F10, - F11, - F12, - F13, - F14, - F15, - PRINT_SCREEN, - SCROLL_LOCK, - PAUSE, - NUM_LOCK, - ALT_GR, - LEFT, - RIGHT, - UP, - DOWN - }; - - protected: - int mValue; - bool mShiftPressed; - bool mControlPressed; - bool mAltPressed; - bool mMetaPressed; - bool mNumericPad; - }; -} - -#endif // end GCN_KEY_HPP diff --git a/src/guichan/include/guichan/keyinput.h b/src/guichan/include/guichan/keyinput.h deleted file mode 100644 index 608c7c013c..0000000000 --- a/src/guichan/include/guichan/keyinput.h +++ /dev/null @@ -1,130 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -#include "guichan/key.h" -#include "guichan/platform.h" - -namespace gcn -{ - /** - * Key listeners base class. Inorder to use this class you must inherit - * from it and implements it's functions. KeyListeners listen for key - * events on a Widgets. When a Widget recives a key event, the - * corresponding function in all it's key listeners will be called. - * Only focused Widgets will generate key events. - * - * @see Widget::addKeyListener - */ - class GCN_CORE_DECLSPEC KeyListener - { - public: - - /** - * Destructor - */ - virtual ~KeyListener() { } - - /** - * 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 key the key pressed. - */ - virtual bool keyPress(const Key&) { return false; } - - /** - * Called if a key is released when the widget has keyboard focus. - * - * @param key the key released. - */ - virtual bool keyRelease(const Key&) { return false; } - - virtual void hotKeyPress(const Key&) { } - virtual void hotKeyRelease(const Key&) { } - - protected: - /** - * Constructor. - * - * You should not be able to make an instance of KeyListener, - * therefore its constructor is protected. To use KeyListener - * you must inherit from this class and implement it's - * functions. - */ - KeyListener() { } - }; -} - -#endif // end GCN_KEYLISTENER_HPP diff --git a/src/guichan/include/guichan/listmodel.h b/src/guichan/include/guichan/listmodel.h deleted file mode 100644 index 44a8673c48..0000000000 --- a/src/guichan/include/guichan/listmodel.h +++ /dev/null @@ -1,93 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -#include "guichan/platform.h" - -namespace gcn -{ - /** - * Represents a list. It is used in certain Widgets, like the ListBox, to - * handle a list with string elements. If you want to use Widgets like - * ListBox, you should inherit from this calss and implement it's - * functions. - */ - class GCN_CORE_DECLSPEC ListModel - { - - public: - /** - * Gets the number of elements in the ListModel. - * - * @return the number of elements in the ListModel - */ - virtual int getNumberOfElements() = 0; - - /** - * Gets an element at a certain index in the list. - * - * @param i an index in the list. - * @return an element as a string. - */ - virtual std::string getElementAt(int i) = 0; - - virtual ~ListModel() {} - }; -} - -#endif // end GCN_LISTMODEL_HPP diff --git a/src/guichan/include/guichan/mouseinput.h b/src/guichan/include/guichan/mouseinput.h deleted file mode 100644 index ff1566a4b0..0000000000 --- a/src/guichan/include/guichan/mouseinput.h +++ /dev/null @@ -1,154 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -#include "guichan/platform.h" - -namespace gcn -{ - /** - * Mouse listeners base class. Inorder to use this class you must inherit - * from it and implements it's functions. MouseListeners listen for mouse - * events on a Widgets. When a Widget recives a mouse event, the - * corresponding function in all it's mouse listeners will be - * - * @see Widget::addMouseListener - */ - class GCN_CORE_DECLSPEC MouseListener - { - public: - - /** - * Destructor. - */ - virtual ~MouseListener() { } - - /** - * Called when the mouse enters into the widget area. - */ - virtual void mouseIn() { } - - /** - * Called when the mouse leaves the Widget area. - */ - virtual void mouseOut() { } - - /** - * Called when a mouse button is pressed when the mouse is in the - * Widget area or if the Widget has focus. - * - * NOTE: A mouse press is NOT equal to a mouse click. - * Use mouseClickMessage to check for mouse clicks. - * - * @param x the x coordinate of the mouse relative to the Widget - * itself. - * @param y the y coordinate of the mouse relative to the Widget - * itself. - * @param button the button pressed. - */ - virtual void mousePress(int, int, int) { } - - /** - * Called when a mouse button is released when the mouse is in the - * Widget area or if the Widget has focus. - * - * @param x the x coordinate of the mouse relative to the Widget - * itself. - * - * @param y the y coordinate of the mouse relative to the Widget - * itself. - * @param button the button released. - */ - virtual void mouseRelease(int, int, int) { } - - - /** - * Called when a mouse button is pressed and released (clicked) - * when the mouse is in the Widget area or if the Widget has - * focus. - * - * @param x the x coordinate of the mouse relative to the Widget - * itself. - * @param y the y coordinate of the mouse relative to the Widget - * itself. - * @param button the button clicked. - * @param count the number of clicks. - */ - virtual void mouseClick(int, int, int, int) { } - - /** - * Called on a mouse wheel up when the mouse is in the Widget - * area or if the Widget has focus. - * - * @param x the x coordinate of the mouse relative to the Widget - * itself. - * @param y the y coordinate of the mouse relative to the Widget - * itself. - */ - virtual void mouseWheelUp(int, int) { } - - /** - * Called on a mouse wheel down when the mouse is in the Widget - * area or if the Widget has focus. - * - * @param x the x coordinate of the mouse relative to the Widget - * itself. - * @param y the y coordinate of the mouse relative to the Widget - * itself. - */ - virtual void mouseWheelDown(int, int) { } - - /** - * Called when the mouse moves and the mouse is in the Widget - * area or if the Widget has focus. - * - * @param x the x coordinate of the mouse relative to the Widget - * itself. - * @param y the y coordinate of the mouse relative to the Widget - * itself. - */ - virtual void mouseMotion(int, int) { } - - protected: - /** - * Constructor. - * - * You should not be able to make an instance of MouseListener, - * therefore its constructor is protected. To use MouseListener - * you must inherit from this class and implement it's - * functions. - */ - MouseListener() { } - }; -} - -#endif // end GCN_MOUSELISTENER_HPP diff --git a/src/guichan/include/guichan/platform.h b/src/guichan/include/guichan/platform.h deleted file mode 100644 index cfa4c22438..0000000000 --- a/src/guichan/include/guichan/platform.h +++ /dev/null @@ -1,67 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u x + width || - rectangle.y > y + height || - x > rectangle.x + rectangle.width || - y > rectangle.y + rectangle.height); - } - - /** - * Checks if a point is inside the Rectangle. - * - * @param x the point x coordinate - * @param y the point y coordinate - */ - bool isPointInRect(int x, int y) const; - - int x; - int y; - int width; - int height; - }; -} - -#endif // end GCN_RECTANGEL_HPP diff --git a/src/guichan/include/guichan/sdl/sdlgraphics.h b/src/guichan/include/guichan/sdl/sdlgraphics.h deleted file mode 100644 index 42d32139f9..0000000000 --- a/src/guichan/include/guichan/sdl/sdlgraphics.h +++ /dev/null @@ -1,163 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include - -#include "SDL.h" - -#include "guichan/graphics.h" -#include "guichan/image.h" -#include "guichan/platform.h" -#include "guichan/rectangle.h" - -namespace gcn -{ - /** - * 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* surface); - - /** - * 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(); - - 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/sdlimageloader.h b/src/guichan/include/guichan/sdl/sdlimageloader.h deleted file mode 100644 index dd7f95fd8d..0000000000 --- a/src/guichan/include/guichan/sdl/sdlimageloader.h +++ /dev/null @@ -1,106 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -#include "SDL.h" - -#include "guichan/image.h" -#include "guichan/imageloader.h" -#include "guichan/platform.h" - -namespace gcn -{ - /** - * SDL implementation of ImageLoader. - */ - class GCN_EXTENSION_DECLSPEC SDLImageLoader : public ImageLoader - { - public: - - /** - * Constructor. - */ - SDLImageLoader(); - - - // Inherited from ImageLoader - - virtual void prepare(const std::string& filename); - - virtual void free(Image* image); - - virtual void* getRawData(); - - virtual void* finalize(); - - virtual void discard(); - - virtual int getHeight() const; - - virtual int getWidth() const; - - virtual Color getPixel(int x, int y); - - virtual void putPixel(int x, int y, const Color& color); - - protected: - SDL_Surface* mCurrentImage; - }; -} - -#endif // end GCN_SDLIMAGELOADER_HPP diff --git a/src/guichan/include/guichan/sdl/sdlinput.h b/src/guichan/include/guichan/sdl/sdlinput.h deleted file mode 100644 index c65b5f167d..0000000000 --- a/src/guichan/include/guichan/sdl/sdlinput.h +++ /dev/null @@ -1,138 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -#include "SDL.h" - -#include "guichan/input.h" -#include "guichan/key.h" -#include "guichan/keyinput.h" -#include "guichan/mouseinput.h" -#include "guichan/platform.h" - -namespace gcn -{ - /** - * SDL implementation of Input. - */ - class GCN_EXTENSION_DECLSPEC SDLInput : public Input - { - public: - - /** - * Constructor. - */ - SDLInput(); - - /** - * Pushes an SDL event. It should be called at least once per frame to - * update input with user input. - * - * @param event an event from SDL. - */ - virtual void pushInput(SDL_Event event); - - /** - * Polls all input. It exists for input driver compatibility. If you - * only use SDL and plan sticking with SDL you can safely ignore this - * function as it in the SDL case does nothing. - */ - virtual void _pollInput() { } - - - // Inherited from Input - - virtual bool isKeyQueueEmpty(); - - virtual KeyInput dequeueKeyInput(); - - virtual bool isMouseQueueEmpty(); - - virtual MouseInput dequeueMouseInput(); - - virtual void processKeyRepeat(); - - /** - * Converts an SDL keysym to a Key object. - * - * @param key an SDL keysym - * @return a Key object. - */ - static Key convertKeyCharacter(SDL_Keysym key); - - protected: - /** - * Converts a mouse button from SDL to a Guichan mouse button - * representation. - * - * @param button an SDL mouse button. - * @return a Guichan button. - */ - int convertMouseButton(int button); - - std::queue mKeyInputQueue; - std::queue mMouseInputQueue; - - bool mMouseDown; - bool mMouseInWindow; - Key mLastKey; - bool mIsRepeating; - }; -} - -#endif // end GCN_SDLINPUT_HPP diff --git a/src/guichan/include/guichan/sdl/sdlpixel.h b/src/guichan/include/guichan/sdl/sdlpixel.h deleted file mode 100644 index bf41884cd7..0000000000 --- a/src/guichan/include/guichan/sdl/sdlpixel.h +++ /dev/null @@ -1,261 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1uformat->BytesPerPixel; - - SDL_LockSurface(surface); - - Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; - - unsigned int color = 0; - - switch(bpp) - { - case 1: - color = *p; - break; - - case 2: - color = *(Uint16 *)p; - break; - - case 3: - if(SDL_BYTEORDER == SDL_BIG_ENDIAN) - { - color = p[0] << 16 | p[1] << 8 | p[2]; - } - else - { - color = p[0] | p[1] << 8 | p[2] << 16; - } - break; - - case 4: - color = *(Uint32 *)p; - break; - - } - - Uint8 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 surface an SDL_Surface to put the pixel on - * @param x the x coordinate on the surface. - * @param y the y coordinate on the surface. - * @param color the color the pixel should be in. - */ - inline void SDLputPixel(SDL_Surface* surface, int x, int y, const Color& color) - { - int bpp = surface->format->BytesPerPixel; - - SDL_LockSurface(surface); - - Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; - - Uint32 pixel = SDL_MapRGB(surface->format, color.r, color.g, color.b); - - switch(bpp) - { - case 1: - *p = pixel; - break; - - case 2: - *(Uint16 *)p = pixel; - break; - - case 3: - if(SDL_BYTEORDER == SDL_BIG_ENDIAN) - { - p[0] = (pixel >> 16) & 0xff; - p[1] = (pixel >> 8) & 0xff; - p[2] = pixel & 0xff; - } - else - { - p[0] = pixel & 0xff; - p[1] = (pixel >> 8) & 0xff; - p[2] = (pixel >> 16) & 0xff; - } - break; - - case 4: - *(Uint32 *)p = pixel; - break; - } - - SDL_UnlockSurface(surface); - } - - /** - * Blends two 16 bit colors together. - * - * @param src the source color. - * @param dst the destination color. - * @param a alpha. - */ - inline unsigned int SDLAlpha16(unsigned int src, unsigned int dst, unsigned char a) - { - // Loses precision for speed - a = (255 - a) >> 3; - - src = (((src << 16) | src) & 0x07E0F81F); - dst = ((dst << 16) | dst) & 0x07E0F81F; - dst = ((((dst - src) * a) >> 5) + src) & 0x07E0F81F; - return (dst >> 16) | dst; - } - - /** - * 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) - { - a = 255 - a; - - unsigned int src2 = (src & 0xFF00FF00) >> 8; - src &= 0x00FF00FF; - - unsigned int dst2 = (dst & 0xFF00FF00) >> 8; - dst &= 0x00FF00FF; - - dst = ((((dst - src) * a) >> 8) + src) & 0x00FF00FF; - dst2 = ((((dst2 - src2) * a) >> 8) + src2) & 0x00FF00FF; - return dst | (dst2 << 8); - } - - /** - * Puts a pixel on an SDL_Surface with alpha - * - * @param surface an SDL_Surface to put the pixel on - * @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, *(Uint16 *)p, color.a); - 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 = SDLAlpha32(pixel, *(Uint32 *)p, color.a); - break; - } - - SDL_UnlockSurface(surface); - } -} - -#endif // end GCN_SDLPIXEL_HPP diff --git a/src/guichan/include/guichan/widget.h b/src/guichan/include/guichan/widget.h deleted file mode 100644 index a2180b17f8..0000000000 --- a/src/guichan/include/guichan/widget.h +++ /dev/null @@ -1,731 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naess�n a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include - -#include "guichan/actionlistener.h" -#include "guichan/color.h" -#include "guichan/defaultfont.h" -#include "guichan/font.h" -#include "guichan/graphics.h" -#include "guichan/keyinput.h" -#include "guichan/keylistener.h" -#include "guichan/mouseinput.h" -#include "guichan/mouselistener.h" -#include "guichan/rectangle.h" -#include "guichan/platform.h" - -namespace gcn -{ - /* - * Exists for the widget class to compile. - */ - class FocusHandler; - - /* - * Exists for the widget class to compile. - */ - class BasicContainer; - - /** - * Widget base class. Contains basic widget functions every widget should - * have. Widgets should inherit from this class and implements it's - * functions. - * - * NOTE: Functions begining with underscore "_" should not - * be overloaded unless you know what you are doing. - */ - class GCN_CORE_DECLSPEC Widget - { - friend class BasicContainer; - public: - /** - * Constructor. Resets member variables. Noteable, a widget is not - * focusable as default, therefore, Widgets that are supposed to be - * focusable should overide this default in their own constructor. - */ - Widget(); - - /** - * Default destructor. - */ - virtual ~Widget(); - - /** - * Draws the Widget. It is called by the parent widget when it is time - * for the Widget to draw itself. The graphics object is set up so - * that all drawing is relative to the Widget, i.e coordinate (0,0) is - * the top-left corner of the Widget. It is not possible to draw - * outside of a Widgets dimension. - * - * @param graphics a Graphics object to draw with. - */ - virtual void draw(Graphics* graphics) = 0; - - /** - * Draws a the Widget border. A border is drawn around a Widget. - * The width and height of the border is therefore the Widgets - * height+2*bordersize. Think of a painting that has a certain size, - * the border surrounds the painting. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawBorder(Graphics*) { } - - /** - * Called for all Widgets in the gui each time Gui::logic is called. - * You can do logic stuff here like playing an animation. - * - * @see Gui - */ - virtual void logic() { } - - /** - * Gets the Widget parent container. - * - * @return the Widget parent container. Returns NULL if the Widget - * has no parent. - */ - virtual BasicContainer* getParent() const; - - /** - * Sets the width of the Widget in pixels. - * - * @param width the Widget width in pixels. - */ - virtual void setWidth(int width); - - /** - * Gets the width of the Widget in pixels. - * - * @return the Widget with in pixels. - */ - virtual int getWidth() const; - - /** - * Sets the height of the Widget in pixels. - * - * @param height the Widget height in pixels. - */ - virtual void setHeight(int height); - - /** - * Gets the height of the Widget in pixels. - * - * @return the Widget height in pixels. - */ - virtual int getHeight() const; - - /** - * Sets the size of the Widget. - * - * @param width the width. - * @param height the height. - */ - virtual void setSize(int width, int height); - - /** - * Set the Widget x coordinate. It is relateive to it's parent. - * - * @param x the Widget x coordinate. - */ - virtual void setX(int x); - - /** - * Gets the Widget x coordinate. It is relative to it's parent. - * - * @return the Widget x coordinate. - */ - virtual int getX() const; - - /** - * Set the Widget y coordinate. It is relative to it's parent. - * - * @param y the Widget y coordinate. - */ - virtual void setY(int y); - - /** - * Gets the Widget y coordinate. It is relative to it's parent. - * - * @return the Widget y coordinate. - */ - virtual int getY() const; - - /** - * Sets the Widget position. It is relative to it's parent. - * - * @param x the Widget x coordinate. - * @param y the Widgets y coordinate. - */ - virtual void setPosition(int x, int y); - - /** - * Sets the dimension of the Widget. It is relative to it's parent. - * - * @param dimension the Widget dimension. - */ - virtual void setDimension(const Rectangle& dimension); - - /** - * Sets the size of the border, or the width if you so like. The size - * is the number of pixels that the border extends outside the Widget. - * Border size = 0 means no border. - * - * @param borderSize the size of the border. - * @see drawBorder - */ - virtual void setBorderSize(unsigned int borderSize); - - /** - * Gets the size of the border, or the width if you so like. The size - * is the number of pixels that the border extends outside the Widget. - * Border size = 0 means no border. - * - * @return the size of the border. - * @see drawBorder - */ - virtual unsigned int getBorderSize() const; - - /** - * Gets the dimension of the Widget. It is relative to it's parent. - * - * @return the widget dimension. - */ - virtual const Rectangle& getDimension() const; - - /** - * Sets a Widgets focusability. - * - * @param focusable true if the Widget should be focusable. - */ - virtual void setFocusable(bool focusable); - - /** - * Checks whether the Widget is focusable. - * - * @return true if the widget is focusable. - */ - virtual bool isFocusable() const; - - /** - * Checks if the Widget has focus. - * - * @return true if the widget currently has focus. - */ - virtual bool hasFocus() const; - - /** - * Sets the Widget to be disabled or enabled. A disabled - * Widget will never recieve mouse or key input. - * - * @param enabled true if Widget is enabled. - */ - virtual void setEnabled(bool enabled); - - /** - * Checks if a Widget is disabled or not. - * - * @return true if the Widget should be enabled. - */ - virtual bool isEnabled() const; - - /** - * Called if the Widget loses focus. - */ - virtual void lostFocus() { setDirty(true); }; - - /** - * Called if the Widget recieves focus. - */ - virtual void gotFocus() { setDirty(true); }; - - /** - * Checks if the Widget has the mouse. - * - * @return true if the Widget has the mouse. - */ - virtual bool hasMouse() const; - - /** - * Sets the Widget to be visible. - * - * @param visible true if the Widget should be visiable. - */ - virtual void setVisible(bool visible); - - /** - * Checks if the Widget is visible. - * - * @return true if the Widget is visible. - */ - virtual bool isVisible() const; - - /** - * Sets the base color. The base color is the background - * color for many Widgets like the Button and Contianer Widgets. - * - * @param color the baseground Color. - */ - virtual void setBaseColor(const Color& color); - - /** - * Gets the base color. - * - * @return the foreground Color. - */ - virtual const Color& getBaseColor() const; - - /** - * Sets the foreground color. - * - * @param color the foreground Color. - */ - virtual void setForegroundColor(const Color& color); - - /** - * Gets the foreground color. - * - * @return the foreground Color. - */ - virtual const Color& getForegroundColor() const; - - /** - * Sets the background color. - * - * @param color the background Color. - */ - virtual void setBackgroundColor(const Color& color); - - /** - * Gets the background color. - * - * @return the background Color. - */ - virtual const Color& getBackgroundColor() const; - - /** - * Sets the disabled color. - * - * @param color the disabled Color. - */ - virtual void setDisabledColor(const Color& color); - - /** - * Gets the disabled color. - * - * @return the disabled Color. - */ - virtual const Color& getDisabledColor() const; - - /** - * Called when a Widget recieves a MouseInput. - * - * WARNING: This function is used internally to handle all mouse - * messages. Don't call or overload it unless you know what - * you are doing. - * - * @param mouseInput the MouseInput message. - */ - virtual void _mouseInputMessage(const MouseInput& mouseInput); - - /** - * Called when a Widget recieves a KeyInput. - * - * WARNING: This function is used internally to handle all key - * messages. Don't call or overload it unless you know what - * you are doing. - * - * @param keyInput the KeyInput message. - */ - virtual bool _keyInputMessage(const KeyInput& keyInput); - - /** - * Called when a Widget's hot key is pressed - */ - virtual void hotKeyPress() {} - - /** - * Called when a Widget's hot key is released - */ - virtual void hotKeyRelease() {} - - /** - * Called when the mouse enters the Widget area. - * - * WARNING: This function is used internally to handle mouse in - * messages. Don't call or overload this function unless - * you know what you are doing. - */ - virtual void _mouseInMessage(); - - /** - * Called when the mouse leaves the Widget area. - * - * WARNING: This function is used internally be to handle mouse - * out messages. Don't call or overload this function - * unless you know what you are doing. - */ - virtual void _mouseOutMessage(); - - /** - * Requests focus for the Widget. A Widget will only recieve focus - * if it is focusable. - */ - virtual void requestFocus(); - - /** - * Requests a move to the top in the parent Widget. - */ - virtual void requestMoveToTop(); - - /** - * Requests a move to the bottom in the parent Widget. - */ - virtual void requestMoveToBottom(); - - /** - * Sets the FocusHandler to be used. - * - * WARNING: This function is used internally and should not - * be called or overloaded unless you know what you - * are doing. - * - * @param focusHandler the FocusHandler to use. - */ - virtual void _setFocusHandler(FocusHandler* focusHandler); - - /** - * Gets the FocusHandler used. - * - * WARNING: This function is used internally and should not - * be called or overloaded unless you know what you - * are doing. - * - * @return the FocusHandler used. - */ - virtual FocusHandler* _getFocusHandler(); - - /** - * Adds an ActionListener to the Widget. When an action is triggered - * by the Widget, the action function in all the Widget's - * ActionListeners will be called. - * - * @param actionListener the ActionListener to add. - */ - virtual void addActionListener(ActionListener* actionListener); - - /** - * Removes an added ActionListener from the Widget. - * - * @param actionListener the ActionListener to remove. - */ - virtual void removeActionListener(ActionListener* actionListener); - - /** - * Adds a MouseListener to the Widget. When a mouse message is - * recieved, it will be sent to the Widget's MouseListeners. - * - * @param mouseListener the MouseListener to add. - */ - virtual void addMouseListener(MouseListener* mouseListener); - - /** - * Removes an added MouseListener from the Widget. - * - * @param mouseListener the MouseListener to remove. - */ - virtual void removeMouseListener(MouseListener* mouseListener); - - /** - * Adds a KeyListener to the Widget. When a key message is recieved, - * it will be sent to the Widget's KeyListeners. - * - * @param keyListener the KeyListener to add. - */ - virtual void addKeyListener(KeyListener* keyListener); - - /** - * Removes an added KeyListener from the Widget. - * - * @param keyListener the KeyListener to remove. - */ - virtual void removeKeyListener(KeyListener* keyListener); - - /** - * Sets the event identifier of the Widget. The event identifier is - * used to be able to identify which Widget generated an action when - * an action has occured. - * - * NOTE: An 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 event identifer. - * - * @param eventId the event identifier. - */ - virtual void setEventId(const std::string& eventId); - - /** - * Gets the event identifier. - * - * @return the event identifier. - */ - virtual const std::string& getEventId() const; - - /** - * Gets the absolute position on the screen for the Widget. - * - * @param x absolute x coordinate will be stored in this parameter. - * @param y absolute y coordinate will be stored in this parameter. - */ - virtual void getAbsolutePosition(int& x, int& y) const; - - /** - * Sets the parent of the Widget. A parent must be a BasicContainer. - * - * WARNING: This function is used internally and should not - * be called or overloaded unless you know what you - * are doing. - * - * @param parent the parent BasicContainer.. - */ - virtual void _setParent(BasicContainer* parent); - - /** - * Gets the font used. If no font has been set, the global font will - * be returned instead. If no global font has been set, the default - * font will be returend. - * ugly default. - * - * @return the used Font. - */ - Font *getFont() const; - - /** - * Sets the global font to be used by default for all Widgets. - * - * @param font the global Font. - */ - static void setGlobalFont(Font* font); - - /** - * Sets the font. If font is NULL, the global font will be used. - * - * @param font the Font. - */ - virtual void setFont(Font* font); - - /** - * Called when the font has changed. If the change is global, - * this function will only be called if the Widget don't have a - * font already set. - */ - virtual void fontChanged() { } - - /** - * Get the hot key - */ - virtual int getHotKey() const { return mHotKey; } - - /** - * Set the hot key - */ - virtual void setHotKey(const int key); - - /** - * Checks whether a Widget exists or not, that is if it still exists - * an instance of the object. - * - * @param widget the Widget to check. - */ - static bool widgetExists(const Widget* widget); - - /** - * Check if tab in is enabled. Tab in means that you can set focus - * to this Widget by pressing the tab button. If tab in is disabled - * then the FocusHandler will skip this widget and focus the next - * in its focus order. - * - * @return true if tab in is enabled. - */ - virtual bool isTabInEnabled() const; - - /** - * Sets tab in enabled. Tab in means that you can set focus - * to this Widget by pressing the tab button. If tab in is disabled - * then the FocusHandler will skip this widget and focus the next - * in its focus order. - * - * @param enabled true if tab in should be enabled. - */ - virtual 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. - */ - virtual 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. - */ - virtual void setTabOutEnabled(bool enabled); - - /** - * Checks if the Widget is dragged. Dragged means that the mouse - * button has been pressed down over the Widget and the mouse has - * been moved. - * - * @return true if the widget is dragged. - */ - virtual bool isDragged() const; - - /** - * Requests modal focus. When a widget has modal focus, only that - * Widget and it's children may recieve input. If some other Widget - * already has modal focus, an exception will be thrown. - * - * @throws Exception if another Widget already has modal focus. - */ - virtual void requestModalFocus(); - - /** - * Releases modal focus. Modal focus will only be released if the - * Widget has the modal focus. - */ - virtual void releaseModalFocus(); - - /** - * Checks if the Widget or it's parent has modal focus. - */ - virtual bool hasModalFocus() const; - - virtual void setDirty(bool dirty); - virtual bool getDirty() const; - - - protected: - /** - * Generates an action to the Widget's ActionListeners. - */ - void generateAction(); - - typedef std::list MouseListenerList; - MouseListenerList mMouseListeners; - typedef MouseListenerList::iterator MouseListenerIterator; - - typedef std::list KeyListenerList; - KeyListenerList mKeyListeners; - typedef KeyListenerList::iterator KeyListenerIterator; - - typedef std::list ActionListenerList; - ActionListenerList mActionListeners; - typedef ActionListenerList::iterator ActionListenerIterator; - - Color mForegroundColor; - Color mBackgroundColor; - Color mBaseColor; - Color mDisabledColor; - FocusHandler* mFocusHandler; - BasicContainer* mParent; - Rectangle mDimension; - unsigned int mBorderSize; - std::string mEventId; - int mClickTimeStamp; - int mClickCount; - int mClickButton; - bool mHasMouse; - bool mFocusable; - bool mVisible; - bool mTabIn; - bool mTabOut; - bool mEnabled; - - Font* mCurrentFont; - int mHotKey; - static DefaultFont mDefaultFont; - static Font* mGlobalFont; - static std::list mWidgets; - bool mDirty; - }; -} - -#endif // end GCN_WIDGET_HPP - -/* - * yakslem - "I have a really great idea! Why not have an - * interesting and funny quote or story at the - * end of every source file." - * finalman - "Yeah - good idea! .... do you know any funny - * quotes?" - * yakslem - "Well.. I guess not. I just thought it would be - * fun to tell funny quotes." - * finalman - "That's not a very funny quote. But i believe - * pointless quotes are funny in their own pointless - * way." - * yakslem - "...eh...ok..." - */ diff --git a/src/guichan/include/guichan/widgets/button.h b/src/guichan/include/guichan/widgets/button.h deleted file mode 100644 index c11b7a9b0a..0000000000 --- a/src/guichan/include/guichan/widgets/button.h +++ /dev/null @@ -1,165 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -#include "guichan/platform.h" -#include "guichan/widget.h" - -namespace gcn -{ - /** - * A regular button. Add an ActionListener to it to know when it - * has been clicked. - * - * NOTE: You can only have text (a caption) on the button. If you want it - * to handle, for instance images, you can implement an ImageButton - * of your own and overload member functions from Button. - */ - class GCN_CORE_DECLSPEC Button : public Widget, - public MouseListener, - public KeyListener - { - public: - /** - * Constructor. - */ - Button(); - - /** - * Constructor. - * - * @param caption the caption of the Button. - */ - Button(const std::string& caption); - - /** - * Sets the Button caption. - * - * @param caption the Button caption. - */ - virtual void setCaption(const std::string& caption); - - /** - * Gets the Button caption. - * - * @return the Button caption. - */ - virtual const std::string& getCaption() const; - - /** - * Sets the alignment for the caption. - * - * @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT - * @see Graphics - */ - virtual void setAlignment(unsigned int alignment); - - /** - * Gets the alignment for the caption. - * - * @return alignment of caption. - */ - virtual unsigned int getAlignment() const; - - /** - * Adjusts the buttons size to fit the content. - */ - virtual void adjustSize(); - - /** - * Checks if the button is pressed down. Useful when drawing. - * - * @return true if the button is pressed down. - */ - virtual bool isPressed() const; - - - //Inherited from Widget - - virtual void draw(Graphics* graphics); - - virtual void drawBorder(Graphics* graphics); - - virtual void lostFocus(); - - virtual void hotKeyPress(); - virtual void hotKeyRelease(); - - // Inherited from MouseListener - - virtual void mouseClick(int x, int y, int button, int count); - - virtual void mousePress(int x, int y, int button); - - virtual void mouseRelease(int x, int y, int button); - - - // Inherited from KeyListener - - virtual bool keyPress(const Key& key); - - virtual bool keyRelease(const Key& key); - - protected: - std::string mCaption; - bool mMouseDown, mKeyDown, mHotKeyDown; - unsigned int mAlignment; - }; -} - -#endif // end GCN_BUTTON_HPP diff --git a/src/guichan/include/guichan/widgets/checkbox.h b/src/guichan/include/guichan/widgets/checkbox.h deleted file mode 100644 index 72502a32d2..0000000000 --- a/src/guichan/include/guichan/widgets/checkbox.h +++ /dev/null @@ -1,164 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -#include "guichan/keylistener.h" -#include "guichan/mouselistener.h" -#include "guichan/platform.h" -#include "guichan/widget.h" - -namespace gcn -{ - /** - * A regular CheckBox. It can be checked and unchecked. - */ - class GCN_CORE_DECLSPEC CheckBox : - public Widget, - public MouseListener, - public KeyListener - { - public: - - /** - * Contructor. - */ - CheckBox(); - - /** - * Constructor. - * - * @param caption the CheckBox caption. - * @param marked true if the CheckBox should be marked. - */ - CheckBox(const std::string &caption, bool marked=false); - - /** - * Destructor. - */ - virtual ~CheckBox() { } - - /** - * Draws the box i.a not the caption. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawBox(Graphics *graphics); - - /** - * Checks if the CheckBox is marked. - * - * @return true if the CheckBox is marked. - */ - virtual bool isMarked() const; - - /** - * Sets the CheckBox to be marked. - * - * @param marked true if the CheckBox should be marked. - */ - virtual void setMarked(bool marked); - - /** - * Gets the CheckBox caption. - * - * @return the CheckBox caption. - */ - virtual const std::string &getCaption() const; - - /** - * Sets the CheckBox caption. - * - * @param caption the CheckBox caption. - */ - virtual void setCaption(const std::string &caption); - - /** - * Adjusts the CheckBox size to fit the font size. - */ - virtual void adjustSize(); - - - // Inherited from Widget - - virtual void draw(Graphics* graphics); - - virtual void drawBorder(Graphics* graphics); - - - // Inherited from KeyListener - - virtual bool keyPress(const Key& key); - - - // Inherited from MouseListener - - virtual void mouseClick(int x, int y, int button, int count); - - - protected: - /** - * Toggles between marked and unmarked. - */ - virtual void toggle(); - - bool mMarked; - std::string mCaption; - }; -} - -#endif // end GCN_CHECKBOX_HPP diff --git a/src/guichan/include/guichan/widgets/container.h b/src/guichan/include/guichan/widgets/container.h deleted file mode 100644 index 9d4889f971..0000000000 --- a/src/guichan/include/guichan/widgets/container.h +++ /dev/null @@ -1,199 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -#include "guichan/basiccontainer.h" -#include "guichan/graphics.h" -#include "guichan/platform.h" - -namespace gcn -{ - /** - * A container able to contain other Widgets. It is in other words a - * Widget that holds other Widgets. A Widgets position in the container is - * always relativ to the Container itself, not the screen. Using a - * Container as the top Widget in Gui is the only way to use more then one - * Widget in your Gui. - */ - class GCN_CORE_DECLSPEC Container: public BasicContainer - { - public: - - /** - * Constructor. A container is opauqe as default. - * - * @see setOpaque, isOpaque - */ - Container(); - - /** - * Destructor. - */ - virtual ~Container(); - - /** - * Sets whether the background should be drawn or not. If the - * Container is not opaque it will be completely transparent. - * - * NOTE: This is not the same as to set visibility. A nonvisible - * Container will not draw it's content. - * - * @param opaque true if the Container should be opaque. - * @see isOpaque - */ - virtual void setOpaque(bool opaque); - - /** - * Checks if the Container is opaque. - * - * @return true if the Container is opaque. - * @see setOpaque - */ - virtual bool isOpaque() const; - - /** - * Adds a Widget to the Container. - * - * @param widget the Widget to add. - * @see remove - */ - virtual void add(Widget* widget); - - /** - * Adds a Widget to the container and also specifices it's postion - * - * @param widget the Widget to add. - * @param x the x coordinat for the Widget in the Container. - * @param y the y coordinat for the Widget in the Container. - * @see remove - */ - 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(); - - - // Inherited from Widget - - virtual void draw(Graphics* graphics); - - virtual void drawBorder(Graphics* graphics); - - virtual void logic(); - - virtual void _setFocusHandler(FocusHandler* focusHandler); - - virtual void _mouseInputMessage(const MouseInput &mouseInput); - - virtual void _mouseOutMessage(); - - - // Inherited from BasicContainer - - virtual void moveToTop(Widget* widget); - - virtual void moveToBottom(Widget* widget); - - virtual void _announceDeath(Widget *widget); - - virtual void getDrawSize(int& width, int& height, Widget* widget); - - virtual void setDirty(bool dirty); - virtual bool getDirty() const; - - protected: - - /** - * Draws all children of the Container. The Widgets will bedrawn in - * the order the Widgets were added to the Container. - * - * @param graphics the Graphics object to draw with. - */ - virtual void drawChildren(Graphics* graphics); - - /** - * Calls the logic function for all children of Container. The Widgets - * logic function will be called in the order the Widgets were added - * to the Container. - */ - virtual void logicChildren(); - - Widget* mWidgetWithMouse; - typedef std::list WidgetList; - typedef WidgetList::iterator WidgetIterator; - typedef WidgetList::const_iterator WidgetConstIterator; - WidgetList mWidgets; - bool mOpaque; - }; -} - -#endif // end GCN_CONTAINER_HPP diff --git a/src/guichan/include/guichan/widgets/dropdown.h b/src/guichan/include/guichan/widgets/dropdown.h deleted file mode 100644 index 8cccd0e8fe..0000000000 --- a/src/guichan/include/guichan/widgets/dropdown.h +++ /dev/null @@ -1,258 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -#include "guichan/platform.h" -#include "guichan/widget.h" - -namespace gcn -{ - /** - * A label for displaying text. - */ - class GCN_CORE_DECLSPEC Label: public Widget - { - public: - /** - * Constructor. - */ - Label(); - - /** - * Constructor. - * - * @param caption the Label caption. - */ - Label(const std::string& caption); - - /** - * Gets the Label caption. - * - * @return the Label caption. - */ - virtual const std::string &getCaption() const; - - /** - * Sets the Label caption. - * - * @param caption the Label caption. - */ - virtual void setCaption(const std::string& caption); - - /** - * Sets the alignment for the caption. - * - * @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. - * @see Graphics - */ - virtual void setAlignment(unsigned int alignment); - - /** - * Gets the alignment for the caption. - * - * @return alignment of caption. - */ - virtual unsigned int getAlignment(); - - /** - * Adjusts the Label size to fit the font size. - */ - virtual void adjustSize(); - - - // Inherited from Widget - - virtual void draw(Graphics* graphics); - - virtual void drawBorder(Graphics* graphics); - - private: - std::string mCaption; - unsigned int mAlignment; - }; -} - -#endif // end GCN_LABEL_HPP diff --git a/src/guichan/include/guichan/widgets/listbox.h b/src/guichan/include/guichan/widgets/listbox.h deleted file mode 100644 index 7241d496aa..0000000000 --- a/src/guichan/include/guichan/widgets/listbox.h +++ /dev/null @@ -1,153 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include - -#include "guichan/keylistener.h" -#include "guichan/mouselistener.h" -#include "guichan/platform.h" -#include "guichan/widget.h" - -namespace gcn -{ - /** - * A RadioButton which can be grouped into RadioButtons groups. In a - * RadioButton group, only one of the RadioButtons can be selected. - */ - class GCN_CORE_DECLSPEC RadioButton : - public Widget, - public MouseListener, - public KeyListener - { - public: - - /** - * Constructor. - */ - RadioButton(); - - /** - * Constructor. - * - * @param caption the Radiobutton caption. - * @param group the group the RadioButton belongs to. - * @param marked true if the RadioButton should be marked. - */ - RadioButton(const std::string &caption, - const std::string &group, - bool marked=false); - - /** - * Destructor. - */ - virtual ~RadioButton(); - - /** - * Draws the box i.a not the caption. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawBox(Graphics *graphics); - - /** - * Checks if the RadioButton is marked. - * - * @return true if the RadioButton is marked. - */ - virtual bool isMarked() const; - - /** - * Sets the RadioButton to be marked. - * - * @param marked true if the RadioButton should be marked. - */ - virtual void setMarked(bool marked); - - /** - * Gets the RadioButton caption. - * - * @return the RadioButton caption. - */ - virtual const std::string &getCaption() const; - - /** - * Sets the RadioButton caption. - * - * @param caption the RadioButton caption. - */ - virtual void setCaption(const std::string &caption); - - /** - * Sets the group the RadioButton should belong to. - * - * @param group the name of the group. - */ - virtual void setGroup(const std::string &group); - - /** - * Gets the group the RadioButton belongs to. - * - * @return the group the RadioButton belongs to. - */ - virtual const std::string &getGroup() const; - - /** - * Adjusts the RadioButtons size to fit the font size. - */ - virtual void adjustSize(); - - - // Inherited from Widget - - virtual void draw(Graphics* graphics); - - virtual void drawBorder(Graphics* graphics); - - - // Inherited from KeyListener - - virtual bool keyPress(const Key& key); - - - // Inherited from MouseListener - - virtual void mouseClick(int x, int y, int button, int count); - - protected: - bool mMarked; - std::string mCaption; - std::string mGroup; - - typedef std::multimap GroupMap; - typedef GroupMap::iterator GroupIterator; - - static GroupMap mGroupMap; - }; -} - -#endif // end GCN_RADIOBUTTON_HPP diff --git a/src/guichan/include/guichan/widgets/scrollarea.h b/src/guichan/include/guichan/widgets/scrollarea.h deleted file mode 100644 index 4d15c2880c..0000000000 --- a/src/guichan/include/guichan/widgets/scrollarea.h +++ /dev/null @@ -1,444 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -#include "guichan/basiccontainer.h" -#include "guichan/mouselistener.h" -#include "guichan/platform.h" - -namespace gcn -{ - /** - * A ScrollArea in which another Widget can be added. It the other Widget - * is bigger then the ScrollArea, the ScrollArea will only display the part - * of the Widget that fits the ScrollArea and make it possible to scroll - * to the other areas of the Widget. - * - * NOTE: A TextBox or a ListBox looks really ugly unless they exist in a - * ScrollArea. - */ - class GCN_CORE_DECLSPEC ScrollArea: - public BasicContainer, - public MouseListener - { - public: - - /** - * Constructor. - */ - ScrollArea(); - - /** - * Constructor. - * - * @param content the content of the ScrollArea. - */ - ScrollArea(Widget *content); - - /** - * Constructor. - * - * @param content the content of the ScrollArea. - * @param hPolicy the policy for the horizontal scrollbar. See enum with - * policies. - * @param vPolicy the policy for the vertical scrollbar. See enum with - * policies. - */ - ScrollArea(Widget *content, unsigned int hPolicy, unsigned int vPolicy); - - /** - * Destructor. - */ - virtual ~ScrollArea(); - - /** - * Sets the content. - * - * @param widget the content of the ScrollArea. - */ - virtual void setContent(Widget* widget); - - /** - * Gets the content. - * - * @return the content of the ScrollArea. - */ - virtual Widget* getContent(); - - /** - * Sets the horizontal scrollbar policy. See enum with policies. - * - * @param hPolicy the policy for the horizontal scrollbar. See enum with - * policies. - */ - virtual void setHorizontalScrollPolicy(unsigned int hPolicy); - - /** - * Gets the horizontal scrollbar policy. See enum with policies. - * - * @return the policy for the horizontal scrollbar policy. See enum with - * policies. - */ - virtual unsigned int getHorizontalScrollPolicy(); - - /** - * Sets the vertical scrollbar policy. See enum with policies. - * - * @param vPolicy the policy for the vertical scrollbar. See enum with - * policies. - */ - virtual void setVerticalScrollPolicy(unsigned int vPolicy); - - /** - * Gets the vertical scrollbar policy. See enum with policies. - * - * @return the policy for the vertical scrollbar. See enum with - * policies. - */ - virtual unsigned int getVerticalScrollPolicy(); - - /** - * Sets the horizontal and vertical scrollbar policy. See enum with policies. - * - * @param hPolicy the policy for the horizontal scrollbar. See enum with - * policies. - * @param vPolicy the policy for the vertical scrollbar. See enum with - * policies. - */ - virtual void setScrollPolicy(unsigned int hPolicy, unsigned int vPolicy); - - /** - * Sets the amount to scroll verticaly. - * - * @param vScroll the amount to scroll. - */ - virtual void setVerticalScrollAmount(int vScroll); - - /** - * Gets the amount that is scrolled verticaly. - * @return the scroll amount on vertical scroll. - */ - virtual int getVerticalScrollAmount(); - - /** - * Sets the amount to scroll horizontaly. - * - * @param hScroll the amount to scroll. - */ - virtual void setHorizontalScrollAmount(int hScroll); - - /** - * Gets the amount that is scrolled horizontaly. - * - * @return the scroll amount on horizontal scroll. - */ - virtual int getHorizontalScrollAmount(); - - /** - * Sets the amount to scroll horizontaly and verticaly. - * - * @param hScroll the amount to scroll on horizontal scroll. - * @param vScroll the amount to scroll on vertical scroll. - */ - virtual void setScrollAmount(int hScroll, int vScroll); - - /** - * Gets the maximum amount of horizontal scroll. - * - * @return the horizontal max scroll. - */ - virtual int getHorizontalMaxScroll(); - - /** - * Gets the maximum amount of vertical scroll. - * - * @return the vertical max scroll. - */ - virtual int getVerticalMaxScroll(); - - /** - * Sets the width. - * - * @param width the width of the ScrollBar. - */ - virtual void setScrollbarWidth(int width); - - /** - * Gets the width. - - * @return the width of the ScrollBar. - */ - virtual int getScrollbarWidth(); - - /** - * Tries to scroll to a specific rectangle. If the rectangle is to - * large to be visible as much as possibly, begining in the rectangles - * upper corner, will be visible. - * - * @param rectangle the Rectangle to scroll to. - */ - virtual void scrollToRectangle(const Rectangle& rectangle); - - - // Inherited from Widget - - virtual void draw(Graphics *graphics); - - virtual void drawBorder(Graphics* graphics); - - virtual void logic(); - - virtual void _mouseInputMessage(const MouseInput &mouseInput); - - virtual void _mouseOutMessage(); - - virtual void _setFocusHandler(FocusHandler* focusHandler); - - - // Inherited from BasicContainer - - virtual void _announceDeath(Widget *widget); - - virtual void getDrawSize(int& width, int& height, Widget* widget); - - virtual void moveToBottom(Widget* widget); - - virtual void moveToTop(Widget* widget); - - - // Inherited from MouseListener - - virtual void mousePress(int x, int y, int button); - - virtual void mouseRelease(int x, int y, int button); - - virtual void mouseMotion(int x, int y); - - virtual void mouseWheelUp(int x, int y); - - virtual void mouseWheelDown(int x, int y); - - - /** - * Scrollpolicies for the horizontal and vertical scrollbar. - * The policies are: - * - * SHOW_ALWAYS - Always show the scrollbars no matter what. - * SHOW_NEVER - Never show the scrollbars no matter waht. - * SHOW_AUTO - Show the scrollbars only when needed. That is if the - * content grows larger then the ScrollArea. - */ - enum - { - SHOW_ALWAYS, - SHOW_NEVER, - SHOW_AUTO - }; - - protected: - /** - * Draws the 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 content in the ScrollArea. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawContent(Graphics* graphics); - - /** - * Draws the vertical scrollbar. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawVBar(Graphics* graphics); - - /** - * Draws the horizontal scrollbar. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawHBar(Graphics* graphics); - - /** - * Draws the vertical marker. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawVMarker(Graphics* graphics); - - /** - * Draws the horizontal marker. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawHMarker(Graphics* graphics); - - /** - * Checks the policies for the scrollbars. - */ - virtual void checkPolicies(); - - /** - * Gets the up button dimension. - * - * @return the dimension of the up button. - */ - virtual Rectangle getUpButtonDimension(); - - /** - * Gets the down button dimension. - * - * @return the dimension of the down button. - */ - virtual Rectangle getDownButtonDimension(); - - /** - * Gets the left button dimension. - * - * @return the dimension of the left button. - */ - virtual Rectangle getLeftButtonDimension(); - - /** - * Gets the right button dimension. - * - * @return the dimension of the right button. - */ - virtual Rectangle getRightButtonDimension(); - - /** - * Gets the content dimension. - * - * @return the dimension of the content. - */ - virtual Rectangle getContentDimension(); - - /** - * Gets the vertical scrollbar dimension. - * - * @return the dimension of the vertical scrollbar. - */ - virtual Rectangle getVerticalBarDimension(); - - /** - * Gets the horizontal scrollbar dimension. - * - * @return the dimension of the horizontal scrollbar. - */ - virtual Rectangle getHorizontalBarDimension(); - - /** - * Gets the vertical marker dimension. - * - * @return the dimension of the vertical marker. - */ - virtual Rectangle getVerticalMarkerDimension(); - - /** - * Gets the horizontal marker dimension. - * - * @return the dimension of the horizontal marker. - */ - virtual Rectangle getHorizontalMarkerDimension(); - - Widget *mContent; - int mVScroll; - int mHScroll; - int mScrollbarWidth; - unsigned int mHPolicy; - unsigned int mVPolicy; - bool mVBarVisible; - bool mHBarVisible; - bool mUpButtonPressed; - bool mDownButtonPressed; - bool mLeftButtonPressed; - bool mRightButtonPressed; - bool mVerticalMarkerPressed; - int mVerticalMarkerMousePosition; - bool mHorizontalMarkerPressed; - int mHorizontalMarkerMousePosition; - }; -} - -#endif // end GCN_SCROLLAREA_HPP diff --git a/src/guichan/include/guichan/widgets/slider.h b/src/guichan/include/guichan/widgets/slider.h deleted file mode 100644 index 55c1af0039..0000000000 --- a/src/guichan/include/guichan/widgets/slider.h +++ /dev/null @@ -1,263 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include -#include - -#include "guichan/platform.h" -#include "guichan/widget.h" - -namespace gcn -{ - /** - * A TextBox in which you can write and/or display a lines of text. - * - * NOTE: A plain TextBox is really uggly and looks much better inside a - * ScrollArea. - */ - class GCN_CORE_DECLSPEC TextBox: - public Widget, - public MouseListener, - public KeyListener - { - public: - /** - * Constructor. - */ - TextBox(); - - /** - * Constructor. - * - * @param text the text of the TextBox. - */ - TextBox(const std::string& text); - - /** - * Sets the text. - * - * @param text the text of the TextBox. - */ - virtual void setText(const std::string& text); - - /** - * Gets the text. - * @return the text of the TextBox. - */ - virtual std::string getText() const; - - /** - * Gets the row of a text. - * - * @return the text of a certain row in the TextBox. - */ - virtual const std::string& getTextRow(int row) const; - - /** - * Sets the text of a certain row in a TextBox. - * - * @param row the row number. - * @param text the text of a certain row in the TextBox. - */ - virtual void setTextRow(int row, const std::string& text); - - /** - * Gets the number of rows in the text. - * - * @return the number of rows in the text. - */ - virtual unsigned int getNumberOfRows() const; - - /** - * Gets the caret position in the text. - * - * @return the caret position in the text. - */ - virtual unsigned int getCaretPosition() const; - - /** - * Sets the position of the caret in the text. - * - * @param position the positon of the caret. - */ - virtual void setCaretPosition(unsigned int position); - - /** - * Gets the row the caret is in in the text. - * - * @return the row the caret is in in the text. - */ - virtual unsigned int getCaretRow() const; - - /** - * Sets the row the caret should be in in the text. - * - * @param row the row number. - */ - virtual void setCaretRow(int row); - - /** - * Gets the column the caret is in in the text. - * - * @return the column the caret is in in the text. - */ - virtual unsigned int getCaretColumn() const; - - /** - * Sets the column the caret should be in in the text. - * - * @param column the column number. - */ - virtual void setCaretColumn(int column); - - /** - * Sets the row and the column the caret should be in in the text. - * - * @param row the row number. - * @param column the column number. - */ - virtual void setCaretRowColumn(int row, int column); - - /** - * Scrolls the text to the caret if the TextBox is in a ScrollArea. - */ - virtual void scrollToCaret(); - - /** - * Checks if the TextBox is editable. - * - * @return true it the TextBox is editable. - */ - virtual bool isEditable() const; - - /** - * Sets if the TextBox should be editable or not. - * - * @param editable true if the TextBox should be editable. - */ - virtual void setEditable(bool editable); - - /** - * Adds a text row to the text. - * - * @param row a row. - */ - virtual void addRow(const std::string row); - - /** - * Checks if the TextBox is opaque - * - * @return true if the TextBox is opaque - */ - virtual bool isOpaque(); - - /** - * Sets the TextBox to be opaque. - * - * @param opaque true if the TextBox should be opaque. - */ - virtual void setOpaque(bool opaque); - - - // Inherited from Widget - - virtual void draw(Graphics* graphics); - - virtual void drawBorder(Graphics* graphics); - - virtual void fontChanged(); - - - // Inherited from KeyListener - - virtual bool keyPress(const Key& key); - - - // Inherited from MouseListener - - virtual void mousePress(int x, int y, int button); - - - protected: - /** - * Draws the caret. - * - * @param graphics a Graphics object to draw with. - * @param x the x position. - * @param y the y position. - */ - virtual void drawCaret(Graphics* graphics, int x, int y); - - /** - * Adjusts the TextBox size to fit the font size. - */ - virtual void adjustSize(); - - std::vector mTextRows; - int mCaretColumn; - int mCaretRow; - bool mEditable; - bool mOpaque; - }; -} - -#endif // end GCN_TEXTBOX_HPP diff --git a/src/guichan/include/guichan/widgets/textfield.h b/src/guichan/include/guichan/widgets/textfield.h deleted file mode 100644 index 461ee27b47..0000000000 --- a/src/guichan/include/guichan/widgets/textfield.h +++ /dev/null @@ -1,169 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naess�n a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -namespace gcn -{ - /** - * A text field in which you can write or display a line of text. - */ - class GCN_CORE_DECLSPEC TextField: - public Widget, - public MouseListener, - public KeyListener - { - public: - /** - * Default constructor. - */ - TextField(); - - /** - * Constructor. Initializes the textfield with a given string. - * - * @param text the initial text. - */ - TextField(const std::string& text); - - /** - * Sets the text. - * - * @param text the new text in the TextField. - */ - virtual void setText(const std::string& text); - - /** - * Gets the text. - * - * @return the text of the TextField. - */ - virtual const std::string& getText() const; - - /** - * Draws the caret (the little marker in the text that shows where the - * letters you type will appear). Easily overloaded if you want to - * change the style of the caret. - * - * @param graphics the Graphics object to draw with. - * @param x the caret's x-position. - */ - virtual void drawCaret(Graphics* graphics, int x); - - /** - * Adjusts the size of the TextField to fit the font size. The - * constructor taking a string uses this function to initialize the - * size of the TextField. - */ - virtual void adjustSize(); - - /** - * Adjusts the height of the text field to fit the font size. The - * height of the TextField is initialized with this function by the - * constructors. - */ - virtual void adjustHeight(); - - /** - * Sets the caret position. - * - * @param position the caret position. - */ - virtual void setCaretPosition(unsigned int position); - - /** - * Gets the caret position. - * - * @return the caret position. - */ - virtual unsigned int getCaretPosition() const; - - // Inherited from Widget - - virtual void fontChanged(); - - virtual void draw(Graphics* graphics); - - virtual void drawBorder(Graphics* graphics); - - - // Inherited from MouseListener - - virtual void mousePress(int x, int y, int button); - - virtual void mouseMotion(int x, int y); - - // Inherited from KeyListener - - virtual bool keyPress(const Key& key); - - protected: - /** - * Scrolls the text horizontally so that the caret shows if needed. - */ - void fixScroll(); - - std::string mText; - unsigned int mCaretPosition; - int mXScroll; - }; -} - -#endif // end GCN_TEXTFIELD_HPP diff --git a/src/guichan/include/guichan/widgets/window.h b/src/guichan/include/guichan/widgets/window.h deleted file mode 100644 index c3ad5cd024..0000000000 --- a/src/guichan/include/guichan/widgets/window.h +++ /dev/null @@ -1,273 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -#include "guichan/platform.h" -#include "guichan/basiccontainer.h" - -namespace gcn -{ - /** - * A movable window which can conatin another Widget. - */ - class GCN_CORE_DECLSPEC Window : public BasicContainer, - public MouseListener - { - public: - /** - * Constructor. - */ - Window(); - - /** - * Constructor. - * - * @param caption the Window caption. - */ - Window(const std::string& caption); - - /** - * Constructor. - * - * @param content the content Widget. - * @param caption the Window caption. - */ - Window(Widget* content, const std::string& caption = ""); - - /** - * Destructor. - */ - virtual ~Window(); - - /** - * Sets the Window caption. - * - * @param caption the Window caption. - */ - virtual void setCaption(const std::string& caption); - - /** - * Gets the Window caption. - * - * @return the Window caption. - */ - virtual const std::string& getCaption() const; - - /** - * Sets the alignment for the caption. - * - * @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. - */ - virtual void setAlignment(unsigned int alignment); - - /** - * Gets the alignment for the caption. - * - * @return alignment of caption. - */ - virtual unsigned int getAlignment() const; - - /** - * Sets the content Widget. - * - * @param widget the contant Widget. - */ - virtual void setContent(Widget* widget); - - /** - * Gets the content Widget. - * - * @return the contant Widget. - */ - virtual Widget* getContent() const; - - /** - * Sets the padding of the window which is the distance between the - * window border and the content. - * - * @param padding the padding value. - */ - virtual void setPadding(unsigned int padding); - - /** - * Gets the padding. - * - * @return the padding value. - */ - virtual unsigned int getPadding() const; - - /** - * Sets the title bar height. - * - * @param height the title height value. - */ - virtual void setTitleBarHeight(unsigned int height); - - /** - * Gets the title bar height. - * - * @return the title bar height. - */ - virtual unsigned int getTitleBarHeight(); - - /** - * Sets the Window to be moveble. - * - * @param movable true or false. - */ - virtual void setMovable(bool movable); - - /** - * Check if the window is movable. - * - * @return true or false. - */ - virtual bool isMovable() const; - - /** - * Resizes the window to fit the content. - */ - virtual void resizeToContent(); - - /** - * Sets the Window to be opaque. If it's not opaque, the content area - * will not be filled with a color. - * - * @param opaque true or false. - */ - virtual void setOpaque(bool opaque); - - /** - * Checks if the Window is opaque. - * - * @return true or false. - */ - virtual bool isOpaque(); - - /** - * Draws the content of the Window. This functions uses the - * getContentDimension to determin where to draw the content. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawContent(Graphics* graphics); - - - // Inherited from BasicContainer - - virtual void moveToTop(Widget* widget); - - virtual void moveToBottom(Widget* widget); - - virtual void getDrawSize(int& width, int& height, Widget* widget); - - virtual void _announceDeath(Widget *widget); - - - // Inherited from Widget - - virtual void draw(Graphics* graphics); - - virtual void drawBorder(Graphics* graphics); - - virtual void logic(); - - virtual void _mouseInputMessage(const MouseInput &mouseInput); - - virtual void _mouseOutMessage(); - - virtual void _setFocusHandler(FocusHandler* focusHandler); - - - // Inherited from MouseListener - - virtual void mousePress(int x, int y, int button); - - virtual void mouseRelease(int x, int y, int button); - - virtual void mouseMotion(int x, int y); - - virtual void setDirty(bool dirty); - virtual bool getDirty() const; - - protected: - /** - * Moves the content to the top left corner of the window, - * uses getContentDimension to get the offset - */ - virtual void repositionContent(); - - /** - * Gets the area in the window that the content occupies. - */ - virtual Rectangle getContentDimension(); - - std::string mCaption; - unsigned int mAlignment; - Widget* mContent; - unsigned int mPadding; - unsigned int mTitleBarHeight; - bool mMouseDrag; - int mMouseXOffset; - int mMouseYOffset; - bool mMovable; - bool mOpaque; - }; -} - -#endif // end GCN_WINDOW_HPP diff --git a/src/guichan/include/guichan/x.h b/src/guichan/include/guichan/x.h deleted file mode 100644 index 25c3b57ad5..0000000000 --- a/src/guichan/include/guichan/x.h +++ /dev/null @@ -1,61 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include - -#endif // end GCN_X_HPP diff --git a/src/guichan/key.cpp b/src/guichan/key.cpp deleted file mode 100644 index a74b5a4ca9..0000000000 --- a/src/guichan/key.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u= 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)); - } - - bool Key::isShiftPressed() const - { - return mShiftPressed; - } - - void Key::setShiftPressed(bool pressed) - { - mShiftPressed = pressed; - } - - bool Key::isControlPressed() const - { - return mControlPressed; - } - - void Key::setControlPressed(bool pressed) - { - mControlPressed = pressed; - } - - bool Key::isAltPressed() const - { - return mAltPressed; - } - - void Key::setAltPressed(bool pressed) - { - mAltPressed = pressed; - } - - bool Key::isMetaPressed() const - { - return mMetaPressed; - } - - void Key::setMetaPressed(bool pressed) - { - mMetaPressed = pressed; - } - - bool Key::isNumericPad() const - { - return mNumericPad; - } - - void Key::setNumericPad(bool numpad) - { - mNumericPad = numpad; - } - - void Key::setValue(int value) - { - mValue = value; - } - - int Key::getValue() const - { - return mValue; - } - -} diff --git a/src/guichan/keyinput.cpp b/src/guichan/keyinput.cpp deleted file mode 100644 index 40f838071c..0000000000 --- a/src/guichan/keyinput.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1ux = x; - this->y = y; - this->width = width; - this->height = height; - } - - void Rectangle::setAll(int x, int y, int width, int height) - { - this->x = x; - this->y = y; - this->width = width; - this->height = height; - } - - bool Rectangle::intersect(const Rectangle& rectangle) - { - x -= rectangle.x; - y -= rectangle.y; - - if (x < 0) - { - width += x; - x = 0; - } - - if (y < 0) - { - height += y; - y = 0; - } - - if (x + width > rectangle.width) - { - width = rectangle.width - x; - } - - if (y + height > rectangle.height) - { - height = rectangle.height - y; - } - - if (width <= 0 || height <= 0) - { - height = 0; - width = 0; - x += rectangle.x; - y += rectangle.y; - return false; - } - - x += rectangle.x; - y += rectangle.y; - return true; - } - - bool Rectangle::isPointInRect(int x, int y) const - { - return ((x >= this->x) && (y >= this->y) - && x < (this->x + this->width) - && y < (this->y + this->height)); - } -} diff --git a/src/guichan/sdl/gsdl.cpp b/src/guichan/sdl/gsdl.cpp deleted file mode 100644 index 89ac49c74d..0000000000 --- a/src/guichan/sdl/gsdl.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1uw; - 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); - - 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() - { - SDL_Rect rect; - Graphics::popClipArea(); - - if (mClipStack.empty()) - { - return; - } - - ClipRectangle carea = mClipStack.top(); - 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) - { - 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; - - SDL_Surface* srcImage = (SDL_Surface*)image->_getData(); - - Color c = getColor(); - if (!SDL_SetSurfaceColorMod(srcImage, c.r, c.g, c.b)) { - SDL_SetSurfaceColorMod(srcImage, 255, 255, 255); - } - if (!SDL_SetSurfaceAlphaMod(srcImage, c.a)) { - SDL_SetSurfaceAlphaMod(srcImage, 255); - } - SDL_BlitSurface(srcImage, &src, mTarget, &dst); - } - - void SDLGraphics::fillRectangle(const Rectangle& rectangle) - { - Rectangle area = rectangle; - ClipRectangle top = mClipStack.top(); - - area.x += top.xOffset; - area.y += top.yOffset; - - if(!area.intersect(top) || mColor.a == 0) - { - return; - } - - if (mAlpha) - { - int x1 = std::max(area.x, top.x); - int y1 = std::max(area.y, top.y); - int x2 = std::min(area.x + area.width, top.x + top.width); - int y2 = std::min(area.y + area.height, top.y + top.height); - int x, y; - for (y = y1; y < y2; y++) - { - for (x = x1; x < x2; x++) - { - SDLputPixelAlpha(mTarget, x, y, mColor); - } - } - } - 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) - { - 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) - { - 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; - } - Uint32 color = - SDL_MapRGB(mTarget->format, mColor.r, mColor.g, mColor.b); - if (mAlpha) { - Video.DrawTransHLine(color, x1, y, x2 - x1, mColor.a); - } else { - Video.DrawHLine(color, x1, y, x2 - x1); - } - } - - void SDLGraphics::drawVLine(int x, int y1, int y2) - { - 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; - } - Uint32 color = - SDL_MapRGB(mTarget->format, mColor.r, mColor.g, mColor.b); - if (mAlpha) { - Video.DrawTransVLine(color, x, y1,y2 - y1, mColor.a); - } else { - Video.DrawVLine(color, x, y1, y2 - y1); - } - } - - 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; - } - - ClipRectangle top = mClipStack.top(); - x1 += top.xOffset; - y1 += top.yOffset; - x2 += top.xOffset; - y2 += top.yOffset; - - // Draw a line with Bresenham - - int dx = ABS(x2 - x1); - int dy = ABS(y2 - y1); - - if (dx > dy) - { - if (x1 > x2) - { - // swap x1, x2 - x1 ^= x2; - x2 ^= x1; - x1 ^= x2; - - // swap y1, y2 - y1 ^= y2; - y2 ^= y1; - y1 ^= y2; - } - - if (y1 < y2) - { - int y = y1; - int p = 0; - - for (int x = x1; x <= x2; x++) - { - if (top.isPointInRect(x, y)) - { - if (mAlpha) - { - SDLputPixelAlpha(mTarget, x, y, mColor); - } - else - { - SDLputPixel(mTarget, x, y, mColor); - } - } - - p += dy; - - if (p * 2 >= dx) - { - y++; - p -= dx; - } - } - } - else - { - int y = y1; - int p = 0; - - for (int x = x1; x <= x2; x++) - { - if (top.isPointInRect(x, y)) - { - if (mAlpha) - { - SDLputPixelAlpha(mTarget, x, y, mColor); - } - else - { - SDLputPixel(mTarget, x, y, mColor); - } - } - - p += dy; - - if (p * 2 >= dx) - { - y--; - p -= dx; - } - } - } - } - else - { - if (y1 > y2) - { - // swap y1, y2 - y1 ^= y2; - y2 ^= y1; - y1 ^= y2; - - // swap x1, x2 - x1 ^= x2; - x2 ^= x1; - x1 ^= x2; - } - - if (x1 < x2) - { - int x = x1; - int p = 0; - - for (int y = y1; y <= y2; y++) - { - if (top.isPointInRect(x, y)) - { - if (mAlpha) - { - SDLputPixelAlpha(mTarget, x, y, mColor); - } - else - { - SDLputPixel(mTarget, x, y, mColor); - } - } - - p += dx; - - if (p * 2 >= dy) - { - x++; - p -= dy; - } - } - } - else - { - int x = x1; - int p = 0; - - for (int y = y1; y <= y2; y++) - { - if (top.isPointInRect(x, y)) - { - if (mAlpha) - { - SDLputPixelAlpha(mTarget, x, y, mColor); - } - else - { - SDLputPixel(mTarget, x, y, mColor); - } - } - - p += dx; - - if (p * 2 >= dy) - { - x--; - p -= dy; - } - } - } - } - } - - void SDLGraphics::setColor(const Color& color) - { - mColor = color; - - mAlpha = color.a != 255; - } - - const Color& SDLGraphics::getColor() - { - return mColor; - } - - void SDLGraphics::drawSDLSurface(SDL_Surface* surface, SDL_Rect source, - SDL_Rect destination) - { - ClipRectangle top = mClipStack.top(); - destination.x += top.xOffset; - destination.y += top.yOffset; - - SDL_BlitSurface(surface, &source, mTarget, &destination); - } -} diff --git a/src/guichan/sdl/sdlinput.cpp b/src/guichan/sdl/sdlinput.cpp deleted file mode 100644 index b7d0e8a470..0000000000 --- a/src/guichan/sdl/sdlinput.cpp +++ /dev/null @@ -1,491 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naess�n a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include "guichan/sdl/sdlinput.h" -#include "guichan/exception.h" - -extern uint32_t SDL_CUSTOM_KEY_UP; - -// Ugh... This entire file is so redundant with sdl.cpp - but I don't feel like refactoring the entire guichan mess... -// So... more mess!! -static char ControlIsDown = 0; - -static bool isTextInput(int key) { - return key >= 32 && key < 128 && !ControlIsDown; -} - -namespace gcn -{ - SDLInput::SDLInput() - { - mMouseInWindow = true; - mMouseDown = false; - mIsRepeating = false; - } - - bool SDLInput::isKeyQueueEmpty() - { - return mKeyInputQueue.empty(); - } - - KeyInput SDLInput::dequeueKeyInput() - { - KeyInput keyInput; - - if (mKeyInputQueue.empty()) - { - assert(!"The queue is empty."); - //throw GCN_EXCEPTION("The queue is empty."); - } - - keyInput = mKeyInputQueue.front(); - mKeyInputQueue.pop(); - - return keyInput; - } - - bool SDLInput::isMouseQueueEmpty() - { - return mMouseInputQueue.empty(); - } - - MouseInput SDLInput::dequeueMouseInput() - { - MouseInput mouseInput; - - if (mMouseInputQueue.empty()) - { - assert(!"The queue is empty."); - //throw GCN_EXCEPTION("The queue is empty."); - } - - mouseInput = mMouseInputQueue.front(); - mMouseInputQueue.pop(); - - return mouseInput; - } - - void SDLInput::processKeyRepeat() - { - KeyInput keyInput; - - if (mIsRepeating) { - keyInput.setKey(mLastKey); - keyInput.setType(KeyInput::PRESS); - mKeyInputQueue.push(keyInput); - } - } - - void SDLInput::pushInput(SDL_Event event) - { - KeyInput keyInput; - MouseInput mouseInput; - - switch (event.type) - { - case SDL_TEXTINPUT: - { - char* text = event.text.text; - if (isTextInput((uint8_t)text[0])) { - mLastKey = text[0]; - mIsRepeating = true; - keyInput.setKey(mLastKey); - keyInput.setType(KeyInput::PRESS); - mKeyInputQueue.push(keyInput); - } - } - break; - - case SDL_KEYDOWN: - if (!isTextInput(event.key.keysym.sym)) { - switch (event.key.keysym.sym) { - case SDLK_LCTRL: - ControlIsDown |= 0b01; - break; - case SDLK_RCTRL: - ControlIsDown |= 0b10; - } - mLastKey = convertKeyCharacter(event.key.keysym); - mIsRepeating = true; - keyInput.setKey(mLastKey); - keyInput.setType(KeyInput::PRESS); - mKeyInputQueue.push(keyInput); - } - break; - - case SDL_KEYUP: - if (!isTextInput(event.key.keysym.sym)) { - switch (event.key.keysym.sym) { - case SDLK_LCTRL: - ControlIsDown &= 0b10; - break; - case SDLK_RCTRL: - ControlIsDown &= 0b01; - } - mIsRepeating = false; - keyInput.setKey(convertKeyCharacter(event.key.keysym)); - keyInput.setType(KeyInput::RELEASE); - mKeyInputQueue.push(keyInput); - } - break; - - case SDL_MOUSEBUTTONDOWN: - mMouseDown = true; - mouseInput.x = event.button.x; - mouseInput.y = event.button.y; - mouseInput.setButton(convertMouseButton(event.button.button)); - mouseInput.setType(MouseInput::PRESS); - mouseInput.setTimeStamp(SDL_GetTicks()); - mMouseInputQueue.push(mouseInput); - break; - - case SDL_MOUSEBUTTONUP: - mMouseDown = false; - mouseInput.x = event.button.x; - mouseInput.y = event.button.y; - mouseInput.setButton(convertMouseButton(event.button.button)); - mouseInput.setType(MouseInput::RELEASE); - mouseInput.setTimeStamp(SDL_GetTicks()); - mMouseInputQueue.push(mouseInput); - break; - - case SDL_MOUSEWHEEL: - if (event.wheel.y != 0) { - SDL_GetMouseState(&mouseInput.x, &mouseInput.y); - if (event.wheel.y > 0) - mouseInput.setType(MouseInput::WHEEL_UP); - else - mouseInput.setType(MouseInput::WHEEL_DOWN); - mouseInput.setButton(MouseInput::EMPTY); - mouseInput.setTimeStamp(event.wheel.timestamp); - mMouseInputQueue.push(mouseInput); - } - break; - - case SDL_MOUSEMOTION: - mouseInput.x = event.button.x; - mouseInput.y = event.button.y; - mouseInput.setButton(MouseInput::EMPTY); - mouseInput.setType(MouseInput::MOTION); - mouseInput.setTimeStamp(SDL_GetTicks()); - mMouseInputQueue.push(mouseInput); - break; - - case SDL_WINDOWEVENT: - /* - * This occurs when the mouse leaves the window and the Gui-chan - * application loses its mousefocus. - */ - switch (event.window.event) - { - case SDL_WINDOWEVENT_LEAVE: - { - mMouseInWindow = false; - - if (!mMouseDown) - { - mouseInput.x = -1; - mouseInput.y = -1; - mouseInput.setButton(MouseInput::EMPTY); - mouseInput.setType(MouseInput::MOTION); - mMouseInputQueue.push(mouseInput); - } - } - break; - - case SDL_WINDOWEVENT_ENTER: - mMouseInWindow = true; - break; - } - break; - - default: - if (event.type == SDL_CUSTOM_KEY_UP) { - mIsRepeating = false; - keyInput.setKey(static_cast(event.user.code)); - keyInput.setType(KeyInput::RELEASE); - mKeyInputQueue.push(keyInput); - } - break; - - } // end switch - } - - int SDLInput::convertMouseButton(int button) - { - switch (button) - { - case SDL_BUTTON_LEFT: - return MouseInput::LEFT; - break; - case SDL_BUTTON_RIGHT: - return MouseInput::RIGHT; - break; - case SDL_BUTTON_MIDDLE: - return MouseInput::MIDDLE; - break; - } - -#ifdef DEBUG - fprintf(stderr,"Unknown SDL mouse button.\n"); -#endif - - return 0; - } - - Key SDLInput::convertKeyCharacter(SDL_Keysym keysym) - { - int value = 0; - Key key; - - switch (keysym.sym) - { - case SDLK_TAB: - value = Key::TAB; - break; - case SDLK_LALT: - value = Key::LEFT_ALT; - break; - case SDLK_RALT: - value = Key::RIGHT_ALT; - break; - case SDLK_LSHIFT: - value = Key::LEFT_SHIFT; - break; - case SDLK_RSHIFT: - value = Key::RIGHT_SHIFT; - break; - case SDLK_LCTRL: - value = Key::LEFT_CONTROL; - break; - case SDLK_RCTRL: - value = Key::RIGHT_CONTROL; - break; - case SDLK_BACKSPACE: - value = Key::BACKSPACE; - break; - case SDLK_PAUSE: - value = Key::PAUSE; - break; - case SDLK_SPACE: - value = Key::SPACE; - break; - case SDLK_ESCAPE: - value = Key::ESCAPE; - break; - case SDLK_DELETE: - value = Key::DELETE; - break; - case SDLK_INSERT: - value = Key::INSERT; - break; - case SDLK_HOME: - value = Key::HOME; - break; - case SDLK_END: - value = Key::END; - break; - case SDLK_PAGEUP: - value = Key::PAGE_UP; - break; - case SDLK_PRINTSCREEN: - value = Key::PRINT_SCREEN; - break; - case SDLK_PAGEDOWN: - value = Key::PAGE_DOWN; - break; - case SDLK_F1: - value = Key::F1; - break; - case SDLK_F2: - value = Key::F2; - break; - case SDLK_F3: - value = Key::F3; - break; - case SDLK_F4: - value = Key::F4; - break; - case SDLK_F5: - value = Key::F5; - break; - case SDLK_F6: - value = Key::F6; - break; - case SDLK_F7: - value = Key::F7; - break; - case SDLK_F8: - value = Key::F8; - break; - case SDLK_F9: - value = Key::F9; - break; - case SDLK_F10: - value = Key::F10; - break; - case SDLK_F11: - value = Key::F11; - break; - case SDLK_F12: - value = Key::F12; - break; - case SDLK_F13: - value = Key::F13; - break; - case SDLK_F14: - value = Key::F14; - break; - case SDLK_F15: - value = Key::F15; - break; - case SDLK_NUMLOCKCLEAR: - value = Key::NUM_LOCK; - break; - case SDLK_CAPSLOCK: - value = Key::CAPS_LOCK; - break; - case SDLK_SCROLLLOCK: - value = Key::SCROLL_LOCK; - break; - case SDLK_LGUI: - value = Key::LEFT_SUPER; - break; - case SDLK_RGUI: - value = Key::RIGHT_SUPER; - break; - case SDLK_MODE: - value = Key::ALT_GR; - break; - case SDLK_UP: - value = Key::UP; - break; - case SDLK_DOWN: - value = Key::DOWN; - break; - case SDLK_LEFT: - value = Key::LEFT; - break; - case SDLK_RIGHT: - value = Key::RIGHT; - break; - case SDLK_RETURN: - value = Key::ENTER; - break; - case SDLK_KP_ENTER: - value = Key::ENTER; - break; - - default: - value = keysym.sym; - break; - } - - if (!(keysym.mod & KMOD_NUM)) - { - switch (keysym.sym) - { - case SDLK_KP_0: - value = Key::INSERT; - break; - case SDLK_KP_1: - value = Key::END; - break; - case SDLK_KP_2: - value = Key::DOWN; - break; - case SDLK_KP_3: - value = Key::PAGE_DOWN; - break; - case SDLK_KP_4: - value = Key::LEFT; - break; - case SDLK_KP_5: - value = 0; - break; - case SDLK_KP_6: - value = Key::RIGHT; - break; - case SDLK_KP_7: - value = Key::HOME; - break; - case SDLK_KP_8: - value = Key::UP; - break; - case SDLK_KP_9: - value = Key::PAGE_UP; - break; - default: - break; - } - } - - key.setValue(value); - key.setShiftPressed((keysym.mod & KMOD_SHIFT) != 0); - key.setControlPressed((keysym.mod & KMOD_CTRL) != 0); - key.setAltPressed((keysym.mod & KMOD_ALT) != 0); - key.setMetaPressed((keysym.mod & KMOD_GUI) != 0); - - if (keysym.sym >= SDLK_KP_0 && keysym.sym <= SDLK_KP_EQUALS) - { - key.setNumericPad(true); - } - - return key; - } -} diff --git a/src/guichan/widget.cpp b/src/guichan/widget.cpp deleted file mode 100644 index 9f32766a9f..0000000000 --- a/src/guichan/widget.cpp +++ /dev/null @@ -1,747 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naess�n a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include - -namespace gcn -{ - Font* Widget::mGlobalFont = NULL; - DefaultFont Widget::mDefaultFont; - std::list Widget::mWidgets; - - Widget::Widget() - { - mParent = NULL; - mForegroundColor = Color(0x000000); - mBackgroundColor = Color(0xffffff); - mBaseColor = Color(0x808090); - mBorderSize = 0; - mFocusHandler = NULL; - mFocusable = false; - mClickTimeStamp = 0; - mClickCount = 0; - mHasMouse = false; - mVisible = true; - mTabIn = true; - mTabOut = true; - mEnabled = true; - mClickButton = 0; - mHotKey = 0; - - mCurrentFont = NULL; - mWidgets.push_back(this); - mDirty = true; - } - - Widget::~Widget() - { - setEnabled(false); - if (getParent() != NULL) - { - getParent()->_announceDeath(this); - } - _setParent(NULL); - _setFocusHandler(NULL); - - mWidgets.remove(this); - } - - void Widget::_setParent(BasicContainer* parent) - { - mParent = parent; - } - - BasicContainer* Widget::getParent() const - { - return mParent; - } - - void Widget::setWidth(int width) - { - mDimension.width = width; - } - - int Widget::getWidth() const - { - return mDimension.width; - } - - void Widget::setHeight(int height) - { - mDimension.height = height; - } - - int Widget::getHeight() const - { - return mDimension.height; - } - - void Widget::setX(int x) - { - mDimension.x = x; - } - - int Widget::getX() const - { - return mDimension.x; - } - - void Widget::setY(int y) - { - mDimension.y = y; - } - - int Widget::getY() const - { - return mDimension.y; - } - - void Widget::setPosition(int x, int y) - { - mDimension.x = x; - mDimension.y = y; - } - - void Widget::setDimension(const Rectangle& dimension) - { - mDimension = dimension; - } - - void Widget::setBorderSize(unsigned int borderSize) - { - mBorderSize = borderSize; - } - - unsigned int Widget::getBorderSize() const - { - return mBorderSize; - } - - const Rectangle& Widget::getDimension() const - { - return mDimension; - } - - const std::string& Widget::getEventId() const - { - return mEventId; - } - - void Widget::setEventId(const std::string& eventId) - { - mEventId = eventId; - } - - bool Widget::hasFocus() const - { - if (!mFocusHandler) - { - return false; - } - - return (mFocusHandler->hasFocus(this)); - } - - bool Widget::hasMouse() const - { - return mHasMouse; - } - - void Widget::setFocusable(bool focusable) - { - if (!focusable && hasFocus()) - { - 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?)."); - assert(!"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 && hasFocus()) - { - mFocusHandler->focusNone(); - } - mVisible = visible; - } - - bool Widget::isVisible() const - { - if (getParent() == NULL) - { - return mVisible; - } - else - { - return mVisible && getParent()->isVisible(); - } - } - - void Widget::setBaseColor(const Color& color) - { - mBaseColor = color; - } - - const Color& Widget::getBaseColor() const - { - return mBaseColor; - } - - void Widget::setForegroundColor(const Color& color) - { - mForegroundColor = color; - } - - const Color& Widget::getForegroundColor() const - { - return mForegroundColor; - } - - void Widget::setBackgroundColor(const Color& color) - { - mBackgroundColor = color; - } - - const Color& Widget::getBackgroundColor() const - { - return mBackgroundColor; - } - - void Widget::setDisabledColor(const Color& color) - { - mDisabledColor = color; - } - - const Color& Widget::getDisabledColor() const - { - return mDisabledColor; - } - - 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::addKeyListener(KeyListener* keyListener) - { - mKeyListeners.push_back(keyListener); - } - - void Widget::removeKeyListener(KeyListener* keyListener) - { - mKeyListeners.remove(keyListener); - } - - void Widget::addMouseListener(MouseListener* mouseListener) - { - mMouseListeners.push_back(mouseListener); - } - - void Widget::removeMouseListener(MouseListener* mouseListener) - { - mMouseListeners.remove(mouseListener); - } - - void Widget::_mouseInputMessage(const MouseInput& mouseInput) - { - if (mFocusHandler == NULL) - { - //throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); - // assert(!"No focushandler set (did you add the widget to the gui?)."); - return; - } - - if (!mEnabled || (mFocusHandler->getModalFocused() != NULL && - !hasModalFocus())) - { - return; - } - - int x = mouseInput.x; - int y = mouseInput.y; - int b = mouseInput.getButton(); - int ts = mouseInput.getTimeStamp(); - - MouseListenerIterator iter; - - switch(mouseInput.getType()) - { - case MouseInput::MOTION: - for (iter = mMouseListeners.begin(); iter != mMouseListeners.end(); ++iter) - { - (*iter)->mouseMotion(x, y); - } - break; - - case MouseInput::PRESS: - if (hasMouse()) - { - requestFocus(); - if (b != MouseInput::WHEEL_UP && b != MouseInput::WHEEL_DOWN) - mFocusHandler->requestDrag(this); - } - - if (b != MouseInput::WHEEL_UP && b != MouseInput::WHEEL_DOWN) - { - - for (iter = mMouseListeners.begin(); iter != mMouseListeners.end(); ++iter) - { - (*iter)->mousePress(x, y, b); - } - - if (hasMouse()) - { - if (ts - mClickTimeStamp < 300 && mClickButton == b) - { - mClickCount++; - } - else - { - mClickCount = 0; - } - mClickButton = b; - mClickTimeStamp = ts; - } - else - { - mClickButton = 0; - } - } - setDirty(true); - break; - - case MouseInput::RELEASE: - if (isDragged()) - { - mFocusHandler->dragNone(); - } - - if (b != MouseInput::WHEEL_UP && b != MouseInput::WHEEL_DOWN) - { - for (iter = mMouseListeners.begin(); iter != mMouseListeners.end(); ++iter) - { - (*iter)->mouseRelease(x, y, b); - } - } - - if (mHasMouse) - { - if (b == mClickButton) - { - for (iter = mMouseListeners.begin(); iter != mMouseListeners.end(); ++iter) - { - (*iter)->mouseClick(x, y, b, mClickCount + 1); - } - } - else - { - mClickButton = 0; - mClickCount = 0; - } - } - else - { - mClickCount = 0; - mClickTimeStamp = 0; - } - setDirty(true); - break; - - case MouseInput::WHEEL_UP: - for (iter = mMouseListeners.begin(); iter != mMouseListeners.end(); ++iter) - { - (*iter)->mouseWheelUp(x, y); - } - setDirty(true); - break; - - case MouseInput::WHEEL_DOWN: - for (iter = mMouseListeners.begin(); iter != mMouseListeners.end(); ++iter) - { - (*iter)->mouseWheelDown(x, y); - } - setDirty(true); - break; - } - } - - bool Widget::_keyInputMessage(const KeyInput& keyInput) - { - if (mFocusHandler == NULL) - { - //throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); - assert(!"No focushandler set (did you add the widget to the gui?)."); - } - - if (!mEnabled || (mFocusHandler->getModalFocused() != NULL && - !hasModalFocus())) - { - return false; - } - - KeyListenerIterator iter; - bool keyProcessed = false; - - switch(keyInput.getType()) - { - case KeyInput::PRESS: - for (iter = mKeyListeners.begin(); iter != mKeyListeners.end(); ++iter) - { - if ((*iter)->keyPress(keyInput.getKey())) - { - keyProcessed = true; - } - } - break; - - case KeyInput::RELEASE: - for (iter = mKeyListeners.begin(); iter != mKeyListeners.end(); ++iter) - { - if ((*iter)->keyRelease(keyInput.getKey())) - { - keyProcessed = true; - } - } - break; - } - - return keyProcessed; - } - - void Widget::_mouseInMessage() - { - if (!mEnabled) - { - return; - } - - mHasMouse = true; - setDirty(true); - - MouseListenerIterator iter; - for (iter = mMouseListeners.begin(); iter != mMouseListeners.end(); ++iter) - { - (*iter)->mouseIn(); - } - } - - void Widget::_mouseOutMessage() - { - mHasMouse = false; - setDirty(true); - - MouseListenerIterator iter; - for (iter = mMouseListeners.begin(); iter != mMouseListeners.end(); ++iter) - { - (*iter)->mouseOut(); - } - } - - void Widget::getAbsolutePosition(int& x, int& y) const - { - if (getParent() == NULL) - { - x = mDimension.x; - y = mDimension.y; - return; - } - - int parentX; - int parentY; - - getParent()->getAbsolutePosition(parentX, parentY); - - x = parentX + mDimension.x; - y = parentY + mDimension.y; - } - - void Widget::generateAction() - { - ActionListenerIterator iter; - for (iter = mActionListeners.begin(); iter != mActionListeners.end(); ++iter) - { - (*iter)->action(mEventId); - } - } - - Font* Widget::getFont() const - { - if (mCurrentFont == NULL) - { - if (mGlobalFont == NULL) - { - return &mDefaultFont; - } - - return mGlobalFont; - } - - return mCurrentFont; - } - - void Widget::setGlobalFont(Font* font) - { - mGlobalFont = font; - - std::list::iterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); ++iter) - { - if ((*iter)->mCurrentFont == NULL) - { - (*iter)->fontChanged(); - } - } - } - - void Widget::setFont(Font* font) - { - mCurrentFont = font; - fontChanged(); - } - - void Widget::setHotKey(const int key) - { - if (isascii(key)) - { - mHotKey = tolower(key); - } - else - { - mHotKey = key; - } - } - - bool Widget::widgetExists(const Widget* widget) - { - bool result = false; - - std::list::iterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); ++iter) - { - if (*iter == widget) - { - return true; - } - } - - return result; - } - - bool Widget::isTabInEnabled() const - { - return mTabIn; - } - - void Widget::setTabInEnabled(bool enabled) - { - mTabIn = enabled; - } - - bool Widget::isTabOutEnabled() const - { - return mTabOut; - } - - void Widget::setTabOutEnabled(bool enabled) - { - mTabOut = enabled; - } - - void Widget::setSize(int width, int height) - { - setWidth(width); - setHeight(height); - } - - void Widget::setEnabled(bool enabled) - { - mEnabled = enabled; - } - - bool Widget::isEnabled() const - { - return mEnabled && isVisible(); - } - - bool Widget::isDragged() const - { - if (mFocusHandler == NULL) - { - assert(!"No focushandler set (did you add the widget to the gui?)."); - //throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); - } - - return mFocusHandler->isDragged(this); - } - - void Widget::requestModalFocus() - { - if (mFocusHandler == NULL) - { - assert(!"No focushandler set (did you add the widget to the gui?)."); - //throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); - } - - mFocusHandler->requestModalFocus(this); - } - - void Widget::releaseModalFocus() - { - if (mFocusHandler == NULL) - { - return; - } - - mFocusHandler->releaseModalFocus(this); - } - - bool Widget::hasModalFocus() const - { - if (mFocusHandler == NULL) - { - //throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); - assert(!"No focushandler set (did you add the widget to the gui?)."); - } - - if (getParent() != NULL) - { - return (mFocusHandler->getModalFocused() == this) || getParent()->hasModalFocus(); - } - - return mFocusHandler->getModalFocused() == this; - } - - void Widget::setDirty(bool dirty) - { - mDirty = dirty; - } - - bool Widget::getDirty() const - { - return mDirty; - } -} - diff --git a/src/guichan/widgets/button.cpp b/src/guichan/widgets/button.cpp deleted file mode 100644 index 3b07045b57..0000000000 --- a/src/guichan/widgets/button.cpp +++ /dev/null @@ -1,305 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include "guichan/widgets/button.h" -#include "guichan/exception.h" -#include "guichan/mouseinput.h" - -namespace gcn -{ - Button::Button() - { - mAlignment = Graphics::CENTER; - addMouseListener(this); - addKeyListener(this); - adjustSize(); - setBorderSize(1); - } - - Button::Button(const std::string& caption) - { - mCaption = caption; - mAlignment = Graphics::CENTER; - setFocusable(true); - adjustSize(); - setBorderSize(1); - - mMouseDown = false; - mKeyDown = false; - mHotKeyDown = false; - - addMouseListener(this); - addKeyListener(this); - } - - void Button::setCaption(const std::string& caption) - { - mCaption = caption; - setDirty(true); - } - - const std::string& Button::getCaption() const - { - return mCaption; - } - - void Button::setAlignment(unsigned int alignment) - { - mAlignment = alignment; - } - - unsigned int Button::getAlignment() const - { - return mAlignment; - } - - 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 if (isEnabled()) - { - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - } - else - { - faceColor = getDisabledColor(); - 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->drawHLine(0, 0, getWidth() - 1); - //graphics->drawVLine(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->drawVLine(getWidth() - 1, 1 , getHeight() - 1); - //graphics->drawHLine(1, getHeight() - 1, getWidth() - 1); - - graphics->setColor(getForegroundColor()); - - int textX; - int textY = getHeight() / 2 - 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: - //textX = 0; - //throw GCN_EXCEPTION("Unknown alignment."); - assert(!"Unknown alignment."); - } - - graphics->setFont(getFont()); - - if (isPressed()) - { - graphics->drawText(getCaption(), textX + 1, textY + 1, getAlignment()); - } - else - { - graphics->drawText(getCaption(), textX, textY, getAlignment()); - - if (hasFocus()) - { - graphics->drawRectangle(Rectangle(2, 2, getWidth() - 4, - getHeight() - 4)); - } - } - } - - void Button::drawBorder(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i,i, width - i, i); - graphics->drawLine(i,i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i,i + 1, width - i, height - i); - graphics->drawLine(i,height - i, width - i - 1, height - i); - } - } - - void Button::adjustSize() - { - setWidth(getFont()->getWidth(mCaption) + 8); - setHeight(getFont()->getHeight() + 8); - } - - bool Button::isPressed() const - { - return (hasMouse() && mMouseDown) || mKeyDown || mHotKeyDown; - } - - void Button::mouseClick(int, int, int button, int) - { - if (button == MouseInput::LEFT) - { - generateAction(); - } - } - - void Button::mousePress(int, int, int button) - { - if (button == MouseInput::LEFT && hasMouse()) - { - mMouseDown = true; - } - } - - void Button::mouseRelease(int, int, int button) - { - if (button == MouseInput::LEFT) - { - mMouseDown = false; - } - } - - bool Button::keyPress(const Key& key) - { - bool ret = false; - - if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) - { - mKeyDown = true; - ret = true; - } - - mHotKeyDown = false; - mMouseDown = false; - return ret; - } - - bool Button::keyRelease(const Key& key) - { - bool ret = false; - - if ((key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) && mKeyDown) - { - mKeyDown = false; - generateAction(); - ret = true; - } - return ret; - } - - void Button::hotKeyPress() - { - mHotKeyDown = true; - mMouseDown = false; - } - - void Button::hotKeyRelease() - { - if (mHotKeyDown) - { - mHotKeyDown = false; - generateAction(); - } - } - - void Button::lostFocus() - { - mMouseDown = false; - mKeyDown = false; - mHotKeyDown = false; - } -} diff --git a/src/guichan/widgets/checkbox.cpp b/src/guichan/widgets/checkbox.cpp deleted file mode 100644 index 1e92043e99..0000000000 --- a/src/guichan/widgets/checkbox.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1usetFont(getFont()); - graphics->setColor(getForegroundColor()); - - int h = getHeight() + getHeight() / 2; - - graphics->drawText(getCaption(), h - 2, 0); - - if (hasFocus() && !getCaption().empty()) - { - graphics->drawRectangle(Rectangle(h - 4, 0, getWidth() - h + 3, getHeight())); - } - } - - void CheckBox::drawBorder(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i,i, width - i, i); - graphics->drawLine(i,i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i,i + 1, width - i, height - i); - graphics->drawLine(i,height - i, width - i - 1, height - i); - } - } - - void CheckBox::drawBox(Graphics *graphics) - { - int h = getHeight() - 1; - - 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(0, 0, h, 0); - graphics->drawLine(0, 1, 0, h); - - graphics->setColor(highlightColor); - graphics->drawLine(h, 1, h, h); - graphics->drawLine(1, h, h - 1, h); - - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(Rectangle(1, 1, h - 1, h - 1)); - - graphics->setColor(getForegroundColor()); - - if (mMarked) - { - graphics->drawLine(3, 5, 3, h - 3); - graphics->drawLine(4, 5, 4, h - 3); - - graphics->drawLine(5, h - 4, h - 2, 3); - graphics->drawLine(5, h - 5, h - 4, 4); - } - } - - bool CheckBox::isMarked() const - { - return mMarked; - } - - void CheckBox::setMarked(bool marked) - { - mMarked = marked; - } - - const std::string &CheckBox::getCaption() const - { - return mCaption; - } - - void CheckBox::setCaption(const std::string &caption) - { - mCaption = caption; - setDirty(true); - } - - bool CheckBox::keyPress(const Key& key) - { - if (key.getValue() == Key::ENTER || - key.getValue() == Key::SPACE) - { - toggle(); - return true; - } - return false; - } - - void CheckBox::mouseClick(int, int, int button, int) - { - if (button == MouseInput::LEFT) - { - toggle(); - } - } - - void CheckBox::adjustSize() - { - int height = getFont()->getHeight(); - - setHeight(height); - setWidth(getFont()->getWidth(mCaption) + height + height / 2); - } - - void CheckBox::toggle() - { - mMarked = !mMarked; - generateAction(); - } -} - diff --git a/src/guichan/widgets/container.cpp b/src/guichan/widgets/container.cpp deleted file mode 100644 index e3586f353c..0000000000 --- a/src/guichan/widgets/container.cpp +++ /dev/null @@ -1,421 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naess�n a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include "guichan/exception.h" -#include "guichan/widgets/container.h" - -namespace gcn -{ - - Container::Container() - { - mWidgetWithMouse = NULL; - mOpaque = true; - } - - Container::~Container() - { - clear(); - } - - void Container::logic() - { - logicChildren(); - } - - void Container::draw(Graphics* graphics) - { - if (isOpaque()) - { - graphics->setColor(getBaseColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - } - - drawChildren(graphics); - } - - void Container::drawBorder(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i,i, width - i, i); - graphics->drawLine(i,i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i,i + 1, width - i, height - i); - graphics->drawLine(i,height - i, width - i - 1, height - i); - } - } - - void Container::logicChildren() - { - WidgetIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) - { - (*iter)->logic(); - } - } - - void Container::drawChildren(Graphics* graphics) - { - WidgetIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) - { - if ((*iter)->isVisible()) - { - // If the widget has a border, - // draw it before drawing the widget - if ((*iter)->getBorderSize() > 0) - { - Rectangle rec = (*iter)->getDimension(); - rec.x -= (*iter)->getBorderSize(); - rec.y -= (*iter)->getBorderSize(); - rec.width += 2 * (*iter)->getBorderSize(); - rec.height += 2 * (*iter)->getBorderSize(); - graphics->pushClipArea(rec); - (*iter)->drawBorder(graphics); - graphics->popClipArea(); - } - - graphics->pushClipArea((*iter)->getDimension()); - (*iter)->draw(graphics); - graphics->popClipArea(); - } - } - } - - void Container::setOpaque(bool opaque) - { - mOpaque = opaque; - } - - bool Container::isOpaque() const - { - return mOpaque; - } - - void Container::moveToTop(Widget* widget) - { - WidgetIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) - { - if (*iter == widget) - { - mWidgets.erase(iter); - mWidgets.push_back(widget); - return; - } - } - assert(!"There is no such widget in this container."); - //throw GCN_EXCEPTION("There is no such widget in this container."); - } - - void Container::moveToBottom(Widget* widget) - { - WidgetIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) - { - if (*iter == widget) - { - mWidgets.erase(iter); - mWidgets.push_front(widget); - return; - } - } - assert(!"There is no such widget in this container."); - //throw GCN_EXCEPTION("There is no such widget in this container."); - } - - void Container::_announceDeath(Widget *widget) - { - if (mWidgetWithMouse == widget) - { - mWidgetWithMouse = NULL; - } - - WidgetIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) - { - if (*iter == widget) - { - mWidgets.erase(iter); - return; - } - } - assert(!"There is no such widget in this container."); - //throw GCN_EXCEPTION("There is no such widget in this container."); - } - - void Container::getDrawSize(int& width, int& height, Widget* widget) - { - WidgetIterator iter; - bool contains = false; - - for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) - { - if (widget == *iter) - { - contains = true; - break; - } - } - - if (contains) - { - Rectangle widgetDim = widget->getDimension(); - Rectangle dim = getDimension(); - - width = widgetDim.width; - height = widgetDim.height; - - if (widgetDim.x < 0) - { - width += widgetDim.x; - } - - if (widgetDim.y < 0) - { - height += widgetDim.y; - } - - if (widgetDim.x + widgetDim.width > dim.width) - { - width -= (widgetDim.x + widgetDim.width) - dim.width; - } - - if (widgetDim.y + widgetDim.height > dim.height) - { - height -= (widgetDim.y + widgetDim.height) - dim.height; - } - - if (width < 0) - { - width = 0; - } - - if (height < 0) - { - height = 0; - } - } - else - { - assert(!"Widget not in container."); - //throw GCN_EXCEPTION("Widget not in container."); - } - } - - void Container::add(Widget* widget) - { - mWidgets.push_back(widget); - widget->_setFocusHandler(_getFocusHandler()); - widget->_setParent(this); - } - - void Container::add(Widget* widget, int x, int y) - { - widget->setPosition(x, y); - add(widget); - } - - void Container::remove(Widget* widget) - { - if (mWidgetWithMouse == widget) - { - mWidgetWithMouse = NULL; - } - - WidgetIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) - { - if (*iter == widget) - { - mWidgets.erase(iter); - if (this->isParentOfWidget(widget)) { - widget->_setFocusHandler(NULL); - widget->_setParent(NULL); - } - return; - } - } - assert(!"There is no such widget in this container."); - //throw GCN_EXCEPTION("There is no such widget in this container."); - } - - void Container::clear() - { - mWidgetWithMouse = NULL; - - WidgetIterator iter; - - for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) - { - if (this->isParentOfWidget(*iter)) { - (*iter)->_setFocusHandler(NULL); - (*iter)->_setParent(NULL); - } - } - - mWidgets.clear(); - } - - void Container::_setFocusHandler(FocusHandler* focusHandler) - { - Widget::_setFocusHandler(focusHandler); - - WidgetIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) - { - (*iter)->_setFocusHandler(focusHandler); - } - } - - void Container::_mouseInputMessage(const MouseInput &mouseInput) - { - Widget* tempWidgetWithMouse = NULL; - - WidgetIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) - { - if ((*iter)->getDimension().isPointInRect(mouseInput.x, mouseInput.y) - && (*iter)->isVisible()) - { - tempWidgetWithMouse = (*iter); - } - } - - if (tempWidgetWithMouse != mWidgetWithMouse) - { - if (mWidgetWithMouse) - { - mWidgetWithMouse->_mouseOutMessage(); - } - - if (tempWidgetWithMouse) - { - tempWidgetWithMouse->_mouseInMessage(); - } - - mWidgetWithMouse = tempWidgetWithMouse; - } - - if (mWidgetWithMouse != NULL) - { - MouseInput mi = mouseInput; - mi.x -= mWidgetWithMouse->getX(); - mi.y -= mWidgetWithMouse->getY(); - mWidgetWithMouse->_mouseInputMessage(mi); - } - - if (mWidgetWithMouse == NULL) - { - BasicContainer::_mouseInputMessage(mouseInput); - } - } - - void Container::_mouseOutMessage() - { - if (mWidgetWithMouse) - { - mWidgetWithMouse->_mouseOutMessage(); - mWidgetWithMouse = NULL; - } - - Widget::_mouseOutMessage(); - } - - void Container::setDirty(bool dirty) - { - WidgetConstIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) - { - (*iter)->setDirty(dirty); - } - mDirty = dirty; - } - - bool Container::getDirty() const - { - if (mDirty == true) - { - return true; - } - - WidgetConstIterator iter; - for (iter = mWidgets.begin(); iter != mWidgets.end(); iter++) - { - if ((*iter)->getDirty()) - { - return true; - } - } - - return false; - } -} diff --git a/src/guichan/widgets/dropdown.cpp b/src/guichan/widgets/dropdown.cpp deleted file mode 100644 index 19a4fe5707..0000000000 --- a/src/guichan/widgets/dropdown.cpp +++ /dev/null @@ -1,718 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include "guichan/exception.h" -#include "guichan/widgets/dropdown.h" - -namespace gcn -{ - DropDown::DropDown() - { - mDroppedDown = false; - mPushed = false; - mOldH = 0; - - setWidth(100); - setFocusable(true); - - mDefaultScrollArea = new ScrollArea(); - mDefaultScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); - mDefaultListBox = new ListBox(); - - mScrollArea = mDefaultScrollArea; - mScrollArea->_setFocusHandler(&mFocusHandler); - mScrollArea->_setParent(this); - - mListBox = mDefaultListBox; - mListBox->addActionListener(this); - mScrollArea->setContent(mListBox); - - addMouseListener(this); - addKeyListener(this); - adjustHeight(); - setBorderSize(1); - } - - DropDown::DropDown(ListModel *listModel) - { - setWidth(100); - setFocusable(true); - mDroppedDown = false; - mPushed = false; - mOldH = 0; - - mDefaultScrollArea = new ScrollArea(); - mDefaultScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); - mDefaultListBox = new ListBox(); - - mScrollArea = mDefaultScrollArea; - mScrollArea->_setParent(this); - mListBox = mDefaultListBox; - mListBox->addActionListener(this); - - mScrollArea->setContent(mListBox); - mScrollArea->_setFocusHandler(&mFocusHandler); - mScrollArea->_setParent(this); - - setListModel(listModel); - - if (mListBox->getSelected() < 0) - { - mListBox->setSelected(0); - } - - addMouseListener(this); - addKeyListener(this); - adjustHeight(); - setBorderSize(1); - } - - DropDown::DropDown(ListModel *listModel, - ScrollArea *scrollArea, - ListBox *listBox) - { - setWidth(100); - setFocusable(true); - mDroppedDown = false; - mPushed = false; - mOldH = 0; - - mDefaultScrollArea = NULL; - mDefaultListBox = NULL; - - mScrollArea = scrollArea; - mScrollArea->_setFocusHandler(&mFocusHandler); - - mListBox = listBox; - mListBox->addActionListener(this); - mScrollArea->setContent(mListBox); - mScrollArea->_setParent(this); - - setListModel(listModel); - - if (mListBox->getSelected() < 0) - { - mListBox->setSelected(0); - } - - addMouseListener(this); - addKeyListener(this); - adjustHeight(); - setBorderSize(1); - } - - DropDown::~DropDown() - { - if (mScrollArea != NULL) - { - mScrollArea->_setFocusHandler(NULL); - } - - if (mDefaultScrollArea != NULL) - { - delete mDefaultScrollArea; - } - - if (mDefaultListBox != NULL) - { - delete mDefaultListBox; - } - - if (widgetExists(mListBox)) - { - mListBox->removeActionListener(this); - } - } - - void DropDown::logic() - { - if (mScrollArea == NULL || mScrollArea->getContent() == NULL) - { - //throw GCN_EXCEPTION("ScrollArea or ListBox is NULL."); - assert(!"ScrollArea or ListBox is NULL."); - } - - mScrollArea->logic(); - mFocusHandler.applyChanges(); - } - - void DropDown::draw(Graphics* graphics) - { - if (mScrollArea == NULL || mScrollArea->getContent() == NULL) - { - //throw GCN_EXCEPTION("ScrollArea or ListBox is NULL."); - assert(!"ScrollArea or ListBox is NULL."); - } - - int h; - - if (mDroppedDown) - { - h = mOldH; - } - else - { - h = getHeight(); - } - - int alpha = getBaseColor().a; - Color faceColor = getBaseColor(); - faceColor.a = alpha; - Color highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - Color shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), h)); - - graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); - - if (mListBox->getListModel() && mListBox->getSelected() >= 0) - { - graphics->drawText(mListBox->getListModel()->getElementAt(mListBox->getSelected()), - 1, (h - getFont()->getHeight()) / 2); - } - - if (hasFocus()) - { - graphics->drawRectangle(Rectangle(0, 0, getWidth() - h, h)); - } - - drawButton(graphics); - - if (mDroppedDown) - { - graphics->pushClipArea(mScrollArea->getDimension()); - mScrollArea->draw(graphics); - graphics->popClipArea(); - - // Draw two lines separating the ListBox with se selected - // element view. - graphics->setColor(highlightColor); - graphics->drawLine(0, h, getWidth(), h); - graphics->setColor(shadowColor); - graphics->drawLine(0, h + 1,getWidth(),h + 1); - } - } - - void DropDown::drawBorder(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i,i, width - i, i); - graphics->drawLine(i,i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i,i + 1, width - i, height - i); - graphics->drawLine(i,height - i, width - i - 1, height - i); - } - } - - void DropDown::drawButton(Graphics *graphics) - { - Color faceColor, highlightColor, shadowColor; - int offset; - int alpha = getBaseColor().a; - - if (mPushed) - { - faceColor = getBaseColor() - 0x303030; - faceColor.a = alpha; - highlightColor = faceColor - 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor + 0x303030; - shadowColor.a = alpha; - offset = 1; - } - else - { - faceColor = getBaseColor(); - faceColor.a = alpha; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - offset = 0; - } - - int h; - if (mDroppedDown) - { - h = mOldH; - } - else - { - h = getHeight(); - } - int x = getWidth() - h; - int y = 0; - - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(x+1, y+1, h-2, h-2)); - - graphics->setColor(highlightColor); - graphics->drawLine(x, y, x+h-1, y); - graphics->drawLine(x, y+1, x, y+h-1); - - graphics->setColor(shadowColor); - graphics->drawLine(x+h-1, y+1, x+h-1, y+h-1); - graphics->drawLine(x+1, y+h-1, x+h-2, y+h-1); - - graphics->setColor(getForegroundColor()); - - int i; - int hh = h / 3; - int hx = x + h / 2; - int hy = y + (h * 2) / 3; - for (i=0; idrawLine(hx - i + offset, - hy - i + offset, - hx + i + offset, - hy - i + offset); - } - } - - int DropDown::getSelected() - { - if (mScrollArea == NULL || mScrollArea->getContent() == NULL) - { - assert(!"ScrollArea or ListBox is NULL."); - //throw GCN_EXCEPTION("ScrollArea or ListBox is NULL."); - } - - return mListBox->getSelected(); - } - - void DropDown::setSelected(int selected) - { - if (mScrollArea == NULL || mScrollArea->getContent() == NULL) - { - assert(!"ScrollArea or ListBox is NULL."); - //throw GCN_EXCEPTION("ScrollArea or ListBox is NULL."); - } - - if (selected >= 0) - { - mListBox->setSelected(selected); - } - } - - bool DropDown::keyPress(const Key& key) - { - if (mScrollArea == NULL || mScrollArea->getContent() == NULL) - { - //throw GCN_EXCEPTION("ScrollArea or ListBox is NULL."); - assert(!"ScrollArea or ListBox is NULL."); - } - - if ((key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) - && !mDroppedDown) - { - dropDown(); - return true; - } - return false; - } - - void DropDown::mousePress(int, int y, int button) - { - if (button == MouseInput::LEFT && hasMouse() && !mDroppedDown) - { - mPushed = true; - dropDown(); - } - // Fold up the listbox if the upper part is clicked after fold down - else if (button == MouseInput::LEFT && hasMouse() && mDroppedDown - && y < mOldH) - { - foldUp(); - } - else if (!hasMouse()) - { - foldUp(); - } - } - - void DropDown::mouseRelease(int, int, int button) - { - if (button == MouseInput::LEFT) - { - mPushed = false; - } - } - - void DropDown::setListModel(ListModel *listModel) - { - if (mScrollArea == NULL || mScrollArea->getContent() == NULL) - { - //throw GCN_EXCEPTION("ScrollArea or ListBox is NULL."); - assert(!"ScrollArea or ListBox is NULL."); - } - - mListBox->setListModel(listModel); - - if (mListBox->getSelected() < 0) - { - mListBox->setSelected(0); - } - - adjustHeight(); - } - - ListModel *DropDown::getListModel() - { - if (mScrollArea == NULL || mScrollArea->getContent() == NULL) - { - //throw GCN_EXCEPTION("ScrollArea or ListBox is NULL."); - assert(!"ScrollArea or ListBox is NULL."); - } - - return mListBox->getListModel(); - } - - void DropDown::setScrollArea(ScrollArea *scrollArea) - { - mScrollArea->_setFocusHandler(NULL); - mScrollArea->_setParent(NULL); - mScrollArea = scrollArea; - mScrollArea->_setFocusHandler(&mFocusHandler); - mScrollArea->setContent(mListBox); - mScrollArea->_setParent(this); - adjustHeight(); - } - - ScrollArea *DropDown::getScrollArea() - { - return mScrollArea; - } - - void DropDown::setListBox(ListBox *listBox) - { - listBox->setSelected(mListBox->getSelected()); - listBox->setListModel(mListBox->getListModel()); - listBox->addActionListener(this); - - if (mScrollArea->getContent() != NULL) - { - mListBox->removeActionListener(this); - } - - mListBox = listBox; - - mScrollArea->setContent(mListBox); - - if (mListBox->getSelected() < 0) - { - mListBox->setSelected(0); - } - } - - ListBox *DropDown::getListBox() - { - return mListBox; - } - - void DropDown::adjustHeight() - { - if (mScrollArea == NULL || mScrollArea->getContent() == NULL) - { - //throw GCN_EXCEPTION("ScrollArea or ListBox is NULL."); - assert(!"ScrollArea or ListBox is NULL."); - } - - int listBoxHeight = mListBox->getHeight(); - int h2 = mOldH ? mOldH : getFont()->getHeight(); - - setHeight(h2); - - // The addition/subtraction of 2 compensates for the seperation lines - // seperating the selected element view and the scroll area. - - if (mDroppedDown && getParent()) - { - int h = getParent()->getHeight() - getY(); - - if (listBoxHeight > h - h2 - 2) - { - mScrollArea->setHeight(h - h2 - 2); - setHeight(h); - } - else - { - setHeight(listBoxHeight + h2 + 2); - mScrollArea->setHeight(listBoxHeight); - } - } - - mScrollArea->setWidth(getWidth()); - mScrollArea->setPosition(0, h2 + 2); - } - - void DropDown::dropDown() - { - if (!mDroppedDown) - { - mDroppedDown = true; - mOldH = getHeight(); - adjustHeight(); - - if (getParent()) - { - getParent()->moveToTop(this); - } - } - - mFocusHandler.requestFocus(mScrollArea->getContent()); - } - - void DropDown::foldUp() - { - if (mDroppedDown) - { - mDroppedDown = false; - mFocusHandler.focusNone(); - adjustHeight(); - } - } - - bool DropDown::_keyInputMessage(const KeyInput& keyInput) - { - if (mDroppedDown) - { - if (mScrollArea == NULL || mScrollArea->getContent() == NULL) - { - //throw GCN_EXCEPTION("ScrollArea or ListBox is NULL."); - assert(!"ScrollArea or ListBox is NULL."); - } - - if (mFocusHandler.getFocused() != NULL) - { - return mFocusHandler.getFocused()->_keyInputMessage(keyInput); - } - else - { - return false; - } - } - else - { - return BasicContainer::_keyInputMessage(keyInput); - } - } - - void DropDown::_mouseInputMessage(const MouseInput &mouseInput) - { - BasicContainer::_mouseInputMessage(mouseInput); - - if (mDroppedDown) - { - if (mScrollArea == NULL || mScrollArea->getContent() == NULL) - { - //throw GCN_EXCEPTION("ScrollArea or ListBox is NULL."); - assert(!"ScrollArea or ListBox is NULL."); - } - - if (mouseInput.y >= mOldH) - { - MouseInput mi = mouseInput; - mi.y -= mScrollArea->getY(); - mScrollArea->_mouseInputMessage(mi); - - if (mListBox->hasFocus()) - { - mi.y -= mListBox->getY(); - mListBox->_mouseInputMessage(mi); - } - } - } - } - - void DropDown::lostFocus() - { - foldUp(); - } - - void DropDown::moveToTop(Widget*) - { - if (getParent()) - { - getParent()->moveToTop(this); - } - } - - void DropDown::moveToBottom(Widget*) - { - if (getParent()) - { - getParent()->moveToBottom(this); - } - } - - void DropDown::_announceDeath(Widget* widget) - { - if (widget == mScrollArea) - { - mScrollArea = NULL; - } - else - { - assert(!"Death announced for unknown widget.."); - //throw GCN_EXCEPTION("Death announced for unknown widget.."); - } - } - - void DropDown::action(const std::string&) - { - foldUp(); - generateAction(); - } - - void DropDown::getDrawSize(int& width, int& height, Widget* widget) - { - if (widget == mScrollArea) - { - if (mDroppedDown) - { - height = getHeight() - mOldH; - width = getWidth(); - } - else - { - width = height = 0; - } - } - else - { - assert(!"DropDown::getDrawSize. widget is not the ScrollArea (wieeerd...)"); - //throw GCN_EXCEPTION("DropDown::getDrawSize. widget is not the ScrollArea (wieeerd...)"); - } - } - - void DropDown::setBaseColor(const Color& color) - { - if (mDefaultScrollArea == mScrollArea && mScrollArea != NULL) - { - mScrollArea->setBaseColor(color); - } - - if (mDefaultListBox == mListBox && mListBox != NULL) - { - mListBox->setBaseColor(color); - } - - Widget::setBaseColor(color); - } - - void DropDown::setBackgroundColor(const Color& color) - { - if (mDefaultScrollArea == mScrollArea && mScrollArea != NULL) - { - mScrollArea->setBackgroundColor(color); - } - - if (mDefaultListBox == mListBox && mListBox != NULL) - { - mListBox->setBackgroundColor(color); - } - - Widget::setBackgroundColor(color); - } - - void DropDown::setForegroundColor(const Color& color) - { - if (mDefaultScrollArea == mScrollArea && mScrollArea != NULL) - { - mScrollArea->setForegroundColor(color); - } - - if (mDefaultListBox == mListBox && mListBox != NULL) - { - mListBox->setForegroundColor(color); - } - - Widget::setForegroundColor(color); - } - - void DropDown::setFont(Font *font) - { - Widget::setFont(font); - mListBox->setFont(font); - } - - bool DropDown::getDirty() const - { - if (mDroppedDown) - { - return mScrollArea->getDirty(); - } - return mDirty; - } -} - diff --git a/src/guichan/widgets/icon.cpp b/src/guichan/widgets/icon.cpp deleted file mode 100644 index f6c103141b..0000000000 --- a/src/guichan/widgets/icon.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1ugetHeight()); - setWidth(image->getWidth()); - Widget::setDirty(true); - } - - void Icon::draw(Graphics* graphics) - { - graphics->setColor(mColor); - graphics->drawImage(mImage, 0, 0); - } - - bool Icon::getDirty() const - { - return Widget::getDirty() || mImage->isDirty(); - } - - void Icon::drawBorder(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i,i, width - i, i); - graphics->drawLine(i,i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i,i + 1, width - i, height - i); - graphics->drawLine(i,height - i, width - i - 1, height - i); - } - } - - void Icon::setBaseColor(const Color& color) - { - Widget::setDirty(true); - mColor = color; - } -} diff --git a/src/guichan/widgets/label.cpp b/src/guichan/widgets/label.cpp deleted file mode 100644 index 905b23e4f3..0000000000 --- a/src/guichan/widgets/label.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include "guichan/widgets/label.h" -#include "guichan/exception.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; - setDirty(true); - } - - void Label::setAlignment(unsigned int alignment) - { - mAlignment = alignment; - } - - unsigned int Label::getAlignment() - { - return mAlignment; - } - - void Label::draw(Graphics* graphics) - { - int textX = 0; - 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."); - assert(!"Unknown alignment."); - } - - graphics->setFont(getFont()); - graphics->setColor(getForegroundColor()); - graphics->drawText(getCaption(), textX, textY, getAlignment()); - } - - void Label::drawBorder(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i,i, width - i, i); - graphics->drawLine(i,i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i,i + 1, width - i, height - i); - graphics->drawLine(i,height - i, width - i - 1, height - i); - } - } - - 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 9ddeef4be8..0000000000 --- a/src/guichan/widgets/listbox.cpp +++ /dev/null @@ -1,253 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naess� a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -#include "guichan/basiccontainer.h" -#include "guichan/widgets/listbox.h" -#include "guichan/widgets/scrollarea.h" - -namespace gcn -{ - ListBox::ListBox() - { - mSelected = -1; - mListModel = NULL; - setWidth(100); - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - } - - ListBox::ListBox(ListModel *listModel) - { - mSelected = -1; - setWidth(100); - setListModel(listModel); - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - } - - void ListBox::draw(Graphics* graphics) - { - if (mListModel == NULL) - { - return; - } - - graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); - - int i, fontHeight; - int y = 0; - - fontHeight = getFont()->getHeight(); - - /** - * @todo Check cliprects so we do not have to iterate over elements in the list model - */ - for (i = 0; i < mListModel->getNumberOfElements(); ++i) - { - if (i == mSelected) - { - graphics->drawRectangle(Rectangle(0, y, getWidth(), fontHeight)); - graphics->setColor(Color(40, 60, 120)); - graphics->fillRectangle(Rectangle(1, y + 1, getWidth() - 2, fontHeight - 2)); - } - - graphics->drawText(mListModel->getElementAt(i), 1, y); - - y += fontHeight; - } - } - - void ListBox::drawBorder(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i,i, width - i, i); - graphics->drawLine(i,i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i,i + 1, width - i, height - i); - graphics->drawLine(i,height - i, width - i - 1, height - i); - } - } - - void ListBox::logic() - { - adjustSize(); - } - - int ListBox::getSelected() - { - 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; - } - - Widget *par = getParent(); - if (par == NULL) - { - return; - } - - ScrollArea* scrollArea = dynamic_cast(par); - if (scrollArea != NULL) - { - Rectangle scroll; - scroll.y = getFont()->getHeight() * mSelected; - scroll.height = getFont()->getHeight(); - scrollArea->scrollToRectangle(scroll); - } - } - } - - bool ListBox::keyPress(const Key& key) - { - bool ret = false; - - if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) - { - generateAction(); - ret = true; - } - else if (key.getValue() == Key::UP) - { - setSelected(mSelected - 1); - - if (mSelected == -1) - { - setSelected(0); - } - ret = true; - } - else if (key.getValue() == Key::DOWN) - { - setSelected(mSelected + 1); - ret = true; - } - - return ret; - } - - void ListBox::mousePress(int, int y, int button) - { - if (button == MouseInput::LEFT && hasMouse()) - { - setSelected(y / getFont()->getHeight()); - generateAction(); - } else if (button == MouseInput::RIGHT && hasMouse()) { - setSelected(-1); - generateAction(); - } - } - - void ListBox::setListModel(ListModel *listModel) - { - mSelected = -1; - mListModel = listModel; - adjustSize(); - } - - ListModel* ListBox::getListModel() - { - return mListModel; - } - - void ListBox::adjustSize() - { - if (mListModel != NULL) - { - setHeight(getFont()->getHeight() * mListModel->getNumberOfElements()); - } - } -} diff --git a/src/guichan/widgets/radiobutton.cpp b/src/guichan/widgets/radiobutton.cpp deleted file mode 100644 index a49c8d32d4..0000000000 --- a/src/guichan/widgets/radiobutton.cpp +++ /dev/null @@ -1,301 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1usetFont(getFont()); - graphics->setColor(getForegroundColor()); - - int h = getHeight() + getHeight() / 2; - - graphics->drawText(getCaption(), h - 2, 0); - - if (hasFocus()) - { - graphics->drawRectangle(Rectangle(h - 4, 0, getWidth() - h + 3, getHeight())); - } - } - - void RadioButton::drawBorder(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i,i, width - i, i); - graphics->drawLine(i,i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i,i + 1, width - i, height - i); - graphics->drawLine(i,height - i, width - i - 1, height - i); - } - } - - void RadioButton::drawBox(Graphics *graphics) - { - int h; - - if (getHeight()%2 == 0) - { - h = getHeight() - 2; - } - else - { - h = getHeight() - 1; - } - - 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 (isMarked()) - { - 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::isMarked() const - { - return mMarked; - } - - void RadioButton::setMarked(bool marked) - { - if (marked && mGroup != "") - { - GroupIterator iter, iterEnd; - iterEnd = mGroupMap.upper_bound(mGroup); - - for (iter = mGroupMap.lower_bound(mGroup); - iter != iterEnd; - iter++) - { - if (iter->second->isMarked()) - { - iter->second->setMarked(false); - } - } - } - - mMarked = marked; - } - - const std::string &RadioButton::getCaption() const - { - return mCaption; - } - - void RadioButton::setCaption(const std::string &caption) - { - mCaption = caption; - setDirty(true); - } - - bool RadioButton::keyPress(const Key& key) - { - if (key.getValue() == Key::ENTER || - key.getValue() == Key::SPACE) - { - setMarked(true); - generateAction(); - return true; - } - return false; - } - - void RadioButton::mouseClick(int, int, int button, int) - { - if (button == MouseInput::LEFT) - { - setMarked(true); - generateAction(); - } - } - - 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(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 f5b4f222de..0000000000 --- a/src/guichan/widgets/scrollarea.cpp +++ /dev/null @@ -1,1300 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include "guichan/exception.h" -#include "guichan/widgets/scrollarea.h" - -namespace gcn -{ - ScrollArea::ScrollArea() - { - mVScroll = 0; - mHScroll = 0; - mHPolicy = SHOW_AUTO; - mVPolicy = SHOW_AUTO; - mScrollbarWidth = 12; - mContent = NULL; - mUpButtonPressed = false; - mDownButtonPressed = false; - mLeftButtonPressed = false; - mRightButtonPressed = false; - mVerticalMarkerPressed = false; - mVerticalMarkerMousePosition = 0; - mHorizontalMarkerPressed = false; - mHorizontalMarkerMousePosition = 0; - - addMouseListener(this); - } - - ScrollArea::ScrollArea(Widget *content) - { - mVScroll = 0; - mHScroll = 0; - mHPolicy = SHOW_AUTO; - mVPolicy = SHOW_AUTO; - mScrollbarWidth = 12; - mContent = NULL; - mUpButtonPressed = false; - mDownButtonPressed = false; - mLeftButtonPressed = false; - mRightButtonPressed = false; - mVerticalMarkerPressed = false; - mVerticalMarkerMousePosition = 0; - mHorizontalMarkerPressed = false; - mHorizontalMarkerMousePosition = 0; - - setContent(content); - addMouseListener(this); - } - - ScrollArea::ScrollArea(Widget *content, unsigned int hPolicy, unsigned int vPolicy) - { - mVScroll = 0; - mHScroll = 0; - mHPolicy = hPolicy; - mVPolicy = vPolicy; - mScrollbarWidth = 12; - mContent = NULL; - mUpButtonPressed = false; - mDownButtonPressed = false; - mLeftButtonPressed = false; - mRightButtonPressed = false; - mVerticalMarkerPressed = false; - mVerticalMarkerMousePosition = 0; - mHorizontalMarkerPressed = false; - mHorizontalMarkerMousePosition = 0; - - setContent(content); - addMouseListener(this); - } - - ScrollArea::~ScrollArea() - { - setContent(NULL); - } - - void ScrollArea::setContent(Widget* widget) - { - if (mContent != NULL) - { - mContent->_setFocusHandler(NULL); - mContent->_setParent(NULL); - } - - mContent = widget; - - if (mContent != NULL) - { - mContent->_setFocusHandler(_getFocusHandler()); - mContent->_setParent(this); - } - - checkPolicies(); - } - - Widget* ScrollArea::getContent() - { - return mContent; - } - - void ScrollArea::setHorizontalScrollPolicy(unsigned int hPolicy) - { - mHPolicy = hPolicy; - checkPolicies(); - } - - unsigned int ScrollArea::getHorizontalScrollPolicy() - { - return mHPolicy; - } - - void ScrollArea::setVerticalScrollPolicy(unsigned int vPolicy) - { - mVPolicy = vPolicy; - checkPolicies(); - } - - unsigned int ScrollArea::getVerticalScrollPolicy() - { - return mVPolicy; - } - - void ScrollArea::setScrollPolicy(unsigned int hPolicy, unsigned int vPolicy) - { - mHPolicy = hPolicy; - mVPolicy = vPolicy; - checkPolicies(); - } - - void ScrollArea::setVerticalScrollAmount(int vScroll) - { - int max = getVerticalMaxScroll(); - - mVScroll = vScroll; - - if (vScroll > max) - { - mVScroll = max; - } - - if (vScroll < 0) - { - mVScroll = 0; - } - } - - int ScrollArea::getVerticalScrollAmount() - { - 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() - { - return mHScroll; - } - - void ScrollArea::setScrollAmount(int hScroll, int vScroll) - { - setHorizontalScrollAmount(hScroll); - setVerticalScrollAmount(vScroll); - } - - int ScrollArea::getHorizontalMaxScroll() - { - checkPolicies(); - - if (mContent == NULL) - { - return 0; - } - - int value = mContent->getWidth() - getContentDimension().width + 2 * mContent->getBorderSize(); - - if (value < 0) - { - return 0; - } - - return value; - } - - int ScrollArea::getVerticalMaxScroll() - { - checkPolicies(); - - if (mContent == NULL) - { - return 0; - } - - int value; - - value = mContent->getHeight() - getContentDimension().height + 2 * mContent->getBorderSize(); - - if (value < 0) - { - return 0; - } - - return value; - } - - void ScrollArea::setScrollbarWidth(int width) - { - if (width > 0) - { - mScrollbarWidth = width; - } - else - { - //throw GCN_EXCEPTION("Width should be greater then 0."); - assert(!"Width should be greater then 0."); - } - } - - int ScrollArea::getScrollbarWidth() - { - return mScrollbarWidth; - } - - void ScrollArea::_setFocusHandler(FocusHandler* focusHandler) - { - BasicContainer::_setFocusHandler(focusHandler); - - if (mContent) - { - mContent->_setFocusHandler(focusHandler); - } - } - - void ScrollArea::_mouseInputMessage(const MouseInput &mouseInput) - { - BasicContainer::_mouseInputMessage(mouseInput); - - if (getContentDimension().isPointInRect(mouseInput.x, mouseInput.y)) - { - if (mContent != NULL) - { - if (!mContent->hasMouse()) - { - mContent->_mouseInMessage(); - } - - MouseInput mi = mouseInput; - - mi.x -= mContent->getX(); - mi.y -= mContent->getY(); - - mContent->_mouseInputMessage(mi); - } - } - else if (mContent && mContent->hasMouse()) - { - mContent->_mouseOutMessage(); - } - } - - void ScrollArea::_mouseOutMessage() - { - if (mContent && mContent->hasMouse()) - { - mContent->_mouseOutMessage(); - } - - BasicContainer::_mouseOutMessage(); - } - - void ScrollArea::mousePress(int x, int y, int) - { - if (getUpButtonDimension().isPointInRect(x, y)) - { - setVerticalScrollAmount(getVerticalScrollAmount() - 10); - mUpButtonPressed = true; - } - else if (getDownButtonDimension().isPointInRect(x, y)) - { - setVerticalScrollAmount(getVerticalScrollAmount() + 10); - mDownButtonPressed = true; - } - else if (getLeftButtonDimension().isPointInRect(x, y)) - { - setHorizontalScrollAmount(getHorizontalScrollAmount() - 10); - mLeftButtonPressed = true; - } - else if (getRightButtonDimension().isPointInRect(x, y)) - { - setHorizontalScrollAmount(getHorizontalScrollAmount() + 10); - mRightButtonPressed = true; - } - else if (getVerticalMarkerDimension().isPointInRect(x, y)) - { - mVerticalMarkerPressed = true; - mVerticalMarkerMousePosition = y - getVerticalMarkerDimension().y; - } - else if (getHorizontalMarkerDimension().isPointInRect(x, y)) - { - mHorizontalMarkerPressed = true; - mHorizontalMarkerMousePosition = x - getHorizontalMarkerDimension().x; - } - } - - void ScrollArea::mouseRelease(int, int, int) - { - mUpButtonPressed = false; - mDownButtonPressed = false; - mLeftButtonPressed = false; - mRightButtonPressed = false; - mVerticalMarkerPressed = false; - mHorizontalMarkerPressed = false; - } - - void ScrollArea::mouseMotion(int x, int y) - { - if (mVerticalMarkerPressed) - { - int pos = y - getVerticalBarDimension().y - mVerticalMarkerMousePosition; - int length = getVerticalMarkerDimension().height; - - Rectangle barDim = getVerticalBarDimension(); - - if ((barDim.height - length) > 0) - { - setVerticalScrollAmount((getVerticalMaxScroll() * pos) - / (barDim.height - length)); - } - else - { - setVerticalScrollAmount(0); - } - setDirty(true); - } - if (mHorizontalMarkerPressed) - { - int pos = x - getHorizontalBarDimension().x - mHorizontalMarkerMousePosition; - int length = getHorizontalMarkerDimension().width; - - Rectangle barDim = getHorizontalBarDimension(); - - if ((barDim.width - length) > 0) - { - setHorizontalScrollAmount((getHorizontalMaxScroll() * pos) - / (barDim.width - length)); - } - else - { - setHorizontalScrollAmount(0); - } - setDirty(true); - } - } - - void ScrollArea::draw(Graphics *graphics) - { - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(getContentDimension()); -#if 0 - int alpha = getBaseColor().a; - Color highlightColor = getBaseColor() + 0x303030; - highlightColor.a = alpha; - Color shadowColor = getBaseColor() - 0x303030; - shadowColor.a = alpha; -#endif - 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)); - } - - if (mContent) - { - Rectangle contdim = mContent->getDimension(); - graphics->pushClipArea(getContentDimension()); - - if (mContent->getBorderSize() > 0) - { - Rectangle rec = mContent->getDimension(); - rec.x -= mContent->getBorderSize(); - rec.y -= mContent->getBorderSize(); - rec.width += 2 * mContent->getBorderSize(); - rec.height += 2 * mContent->getBorderSize(); - graphics->pushClipArea(rec); - mContent->drawBorder(graphics); - graphics->popClipArea(); - } - - graphics->pushClipArea(contdim); - mContent->draw(graphics); - graphics->popClipArea(); - graphics->popClipArea(); - } - } - - void ScrollArea::drawBorder(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i,i, width - i, i); - graphics->drawLine(i,i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i,i + 1, width - i, height - i); - graphics->drawLine(i,height - i, width - i - 1, height - i); - } - } - - void ScrollArea::drawHBar(Graphics* graphics) - { - Rectangle dim = getHorizontalBarDimension(); - - graphics->pushClipArea(dim); - - int alpha = getBaseColor().a; - Color trackColor = getBaseColor() - 0x101010; - trackColor.a = alpha; - Color shadowColor = getBaseColor() - 0x303030; - shadowColor.a = alpha; - - graphics->setColor(trackColor); - graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); - - graphics->setColor(shadowColor); - graphics->drawLine(0, 0, dim.width, 0); - - graphics->popClipArea(); - } - - void ScrollArea::drawVBar(Graphics* graphics) - { - Rectangle dim = getVerticalBarDimension(); - - graphics->pushClipArea(dim); - - int alpha = getBaseColor().a; - Color trackColor = getBaseColor() - 0x101010; - trackColor.a = alpha; - Color shadowColor = getBaseColor() - 0x303030; - shadowColor.a = alpha; - - graphics->setColor(trackColor); - graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); - - graphics->setColor(shadowColor); - graphics->drawLine(0, 0, 0, dim.height); - - graphics->popClipArea(); - } - - void ScrollArea::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 (mContent != NULL) - { - mContent->setPosition(-mHScroll + getContentDimension().x + mContent->getBorderSize(), - -mVScroll + getContentDimension().y + mContent->getBorderSize()); - - mContent->logic(); - } - } - - void ScrollArea::moveToTop(Widget* widget) - { - if (widget == mContent) - { - if (getParent()) - { - getParent()->moveToTop(this); - } - } - else - { - //throw GCN_EXCEPTION("Only a ScrollArea's content may be moved to top."); - assert(!"Only a ScrollArea's content may be moved to top."); - } - } - - void ScrollArea::moveToBottom(Widget* widget) - { - if (widget == mContent) - { - if (getParent()) - { - getParent()->moveToBottom(this); - } - } - else - { - //throw GCN_EXCEPTION("Only a ScrollArea's content may be moved to bottom."); - assert(!"Only a ScrollArea's content may be moved to bottom."); - } - } - - void ScrollArea::_announceDeath(Widget *widget) - { - if (widget == mContent) - { - mContent = NULL; - checkPolicies(); - } - else - { - //throw GCN_EXCEPTION("Called by not-child."); - assert(!"Called by not-child."); - } - } - - void ScrollArea::getDrawSize(int& width, int& height, Widget* widget) - { - if (mContent == widget) - { - width = getContentDimension().width; - height = getContentDimension().height; - } - else - { - //throw GCN_EXCEPTION("Widget not in scrollarea."); - assert(!"Widget not in scrollarea."); - } - } - - void ScrollArea::drawContent(Graphics* graphics) - { - if (mContent) - { - mContent->draw(graphics); - } - } - - void ScrollArea::checkPolicies() - { - int w = getWidth(); - int h = getHeight(); - - mHBarVisible = false; - mVBarVisible = false; - - - if (!mContent) - { - mHBarVisible = (mHPolicy == SHOW_ALWAYS); - mVBarVisible = (mVPolicy == SHOW_ALWAYS); - return; - } - - if (mHPolicy == SHOW_AUTO && - mVPolicy == SHOW_AUTO) - { - if (mContent->getWidth() <= w - && mContent->getHeight() <= h) - { - mHBarVisible = false; - mVBarVisible = false; - } - - if (mContent->getWidth() > w) - { - mHBarVisible = true; - } - - if ((mContent->getHeight() > h) - || (mHBarVisible && mContent->getHeight() > h - mScrollbarWidth)) - { - mVBarVisible = true; - } - - if (mVBarVisible && mContent->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 = mContent->getWidth() > w; - } - else // (mVPolicy == SHOW_ALWAYS) - { - mHBarVisible = mContent->getWidth() > w - mScrollbarWidth; - } - break; - - default: - //throw GCN_EXCEPTION("Horizontal scroll policy invalid."); - assert(!"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 = mContent->getHeight() > h; - } - else // (mHPolicy == SHOW_ALWAYS) - { - mVBarVisible = mContent->getHeight() > h - mScrollbarWidth; - } - break; - default: - //throw GCN_EXCEPTION("Vertical scroll policy invalid."); - assert(!"Vertical scroll policy invalid."); - } - } - - Rectangle ScrollArea::getUpButtonDimension() - { - if (!mVBarVisible) - { - return Rectangle(0, 0, 0, 0); - } - - return Rectangle(getWidth() - mScrollbarWidth, - 0, - mScrollbarWidth, - mScrollbarWidth); - } - - Rectangle ScrollArea::getDownButtonDimension() - { - if (!mVBarVisible) - { - return Rectangle(0, 0, 0, 0); - } - - if (mVBarVisible && mHBarVisible) - { - return Rectangle(getWidth() - mScrollbarWidth, - getHeight() - mScrollbarWidth*2, - mScrollbarWidth, - mScrollbarWidth); - } - - return Rectangle(getWidth() - mScrollbarWidth, - getHeight() - mScrollbarWidth, - mScrollbarWidth, - mScrollbarWidth); - } - - Rectangle ScrollArea::getLeftButtonDimension() - { - if (!mHBarVisible) - { - return Rectangle(0, 0, 0, 0); - } - - return Rectangle(0, - getHeight() - mScrollbarWidth, - mScrollbarWidth, - mScrollbarWidth); - } - - Rectangle ScrollArea::getRightButtonDimension() - { - if (!mHBarVisible) - { - return Rectangle(0, 0, 0, 0); - } - - if (mVBarVisible && mHBarVisible) - { - return Rectangle(getWidth() - mScrollbarWidth*2, - getHeight() - mScrollbarWidth, - mScrollbarWidth, - mScrollbarWidth); - } - - return Rectangle(getWidth() - mScrollbarWidth, - getHeight() - mScrollbarWidth, - mScrollbarWidth, - mScrollbarWidth); - } - - Rectangle ScrollArea::getContentDimension() - { - if (mVBarVisible && mHBarVisible) - { - return Rectangle(0, 0, getWidth() - mScrollbarWidth, - getHeight() - mScrollbarWidth); - } - - if (mVBarVisible) - { - return Rectangle(0, 0, getWidth() - mScrollbarWidth, getHeight()); - } - - if (mHBarVisible) - { - return Rectangle(0, 0, getWidth(), getHeight() - mScrollbarWidth); - } - - return Rectangle(0, 0, getWidth(), getHeight()); - } - - Rectangle ScrollArea::getVerticalBarDimension() - { - if (!mVBarVisible) - { - return Rectangle(0, 0, 0, 0); - } - - if (mHBarVisible) - { - return Rectangle(getWidth() - mScrollbarWidth, - getUpButtonDimension().height, - mScrollbarWidth, - getHeight() - - getUpButtonDimension().height - - getDownButtonDimension().height - - mScrollbarWidth); - } - - return Rectangle(getWidth() - mScrollbarWidth, - getUpButtonDimension().height, - mScrollbarWidth, - getHeight() - - getUpButtonDimension().height - - getDownButtonDimension().height); - } - - Rectangle ScrollArea::getHorizontalBarDimension() - { - if (!mHBarVisible) - { - return Rectangle(0, 0, 0, 0); - } - - if (mVBarVisible) - { - return Rectangle(getLeftButtonDimension().width, - getHeight() - mScrollbarWidth, - getWidth() - - getLeftButtonDimension().width - - getRightButtonDimension().width - - mScrollbarWidth, - mScrollbarWidth); - } - - return Rectangle(getLeftButtonDimension().width, - getHeight() - mScrollbarWidth, - getWidth() - - getLeftButtonDimension().width - - getRightButtonDimension().width, - mScrollbarWidth); - } - - Rectangle ScrollArea::getVerticalMarkerDimension() - { - if (!mVBarVisible) - { - return Rectangle(0, 0, 0, 0); - } - - int length, pos; - Rectangle barDim = getVerticalBarDimension(); - - if (mContent && mContent->getHeight() != 0) - { - length = (barDim.height * getContentDimension().height) - / mContent->getHeight(); - } - else - { - length = barDim.height; - } - - if (length < mScrollbarWidth) - { - length = mScrollbarWidth; - } - - if (length > barDim.height) - { - length = barDim.height; - } - - if (getVerticalMaxScroll() != 0) - { - pos = ((barDim.height - length) * getVerticalScrollAmount()) - / getVerticalMaxScroll(); - } - else - { - pos = 0; - } - - return Rectangle(barDim.x, barDim.y + pos, mScrollbarWidth, length); - } - - Rectangle ScrollArea::getHorizontalMarkerDimension() - { - if (!mHBarVisible) - { - return Rectangle(0, 0, 0, 0); - } - - int length, pos; - Rectangle barDim = getHorizontalBarDimension(); - - if (mContent && mContent->getWidth() != 0) - { - length = (barDim.width * getContentDimension().width) - / mContent->getWidth(); - } - else - { - length = barDim.width; - } - - if (length < mScrollbarWidth) - { - length = mScrollbarWidth; - } - - if (length > barDim.width) - { - length = barDim.width; - } - - if (getHorizontalMaxScroll() != 0) - { - pos = ((barDim.width - length) * getHorizontalScrollAmount()) - / getHorizontalMaxScroll(); - } - else - { - pos = 0; - } - - return Rectangle(barDim.x + pos, barDim.y, length, mScrollbarWidth); - } - - void ScrollArea::scrollToRectangle(const Rectangle& rectangle) - { - Rectangle contentDim = getContentDimension(); - - if (rectangle.x + rectangle.width - > getHorizontalScrollAmount() + contentDim.width) - { - setHorizontalScrollAmount(rectangle.x + rectangle.width - contentDim.width); - } - - if (rectangle.y + rectangle.height - > getVerticalScrollAmount() + contentDim.height) - { - setVerticalScrollAmount(rectangle.y + rectangle.height - contentDim.height); - } - - if (rectangle.x < getHorizontalScrollAmount()) - { - setHorizontalScrollAmount(rectangle.x); - } - - if (rectangle.y < getVerticalScrollAmount()) - { - setVerticalScrollAmount(rectangle.y); - } - } - - void ScrollArea::mouseWheelUp(int, int) - { - if (hasMouse()) - { - setVerticalScrollAmount(getVerticalScrollAmount() - getContentDimension().height / 8); - } - } - - void ScrollArea::mouseWheelDown(int, int) - { - if (hasMouse()) - { - setVerticalScrollAmount(getVerticalScrollAmount() + getContentDimension().height / 8); - } - } -} - -/* - * Wow! This is a looooong source file. 1291 lines! - */ diff --git a/src/guichan/widgets/slider.cpp b/src/guichan/widgets/slider.cpp deleted file mode 100644 index c561a12dd2..0000000000 --- a/src/guichan/widgets/slider.cpp +++ /dev/null @@ -1,402 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1usetColor(shadowColor); - graphics->fillRectangle(gcn::Rectangle(0,0,getWidth(),getHeight())); - - drawMarker(graphics); - } - - void Slider::drawBorder(gcn::Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i,i, width - i, i); - graphics->drawLine(i,i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i,i + 1, width - i, height - i); - graphics->drawLine(i,height - i, width - i - 1, height - i); - } - } - - 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 (hasFocus()) - { - 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 (hasFocus()) - { - graphics->setColor(getForegroundColor()); - graphics->drawRectangle(Rectangle(2, v + 2, getWidth() - 4, getMarkerLength() - 4)); - } - } - } - - void Slider::mousePress(int x, int y, int button) - { - if (button == gcn::MouseInput::LEFT - && x >= 0 && x <= getWidth() - && y >= 0 && y <= getHeight()) - { - if (getOrientation() == HORIZONTAL) - { - setValue(markerPositionToValue(x - getMarkerLength() / 2)); - } - else - { - setValue(markerPositionToValue(getHeight() - y - getMarkerLength() / 2)); - } - - mMouseDrag = true; - generateAction(); - } - else - { - mMouseDrag = false; - } - } - - void Slider::mouseRelease(int, int, int) - { - mMouseDrag = false; - } - - void Slider::lostFocus() - { - mMouseDrag = false; - } - - void Slider::mouseMotion(int x, int y) - { - if (mMouseDrag) - { - if (getOrientation() == HORIZONTAL) - { - setValue(markerPositionToValue(x - getMarkerLength() / 2)); - } - else - { - setValue(markerPositionToValue(getHeight() - y - getMarkerLength() / 2)); - } - - generateAction(); - setDirty(true); - } - } - - 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; - } - - bool Slider::keyPress(const Key& key) - { - bool ret = false; - - if (getOrientation() == HORIZONTAL) - { - if (key.getValue() == Key::RIGHT) - { - setValue(getValue() + getStepLength()); - generateAction(); - ret = true; - } - else if (key.getValue() == Key::LEFT) - { - setValue(getValue() - getStepLength()); - generateAction(); - ret = true; - } - } - else - { - if (key.getValue() == Key::UP) - { - setValue(getValue() + getStepLength()); - generateAction(); - ret = true; - } - else if (key.getValue() == Key::DOWN) - { - setValue(getValue() - getStepLength()); - generateAction(); - ret = true; - } - } - return ret; - } - - void Slider::setOrientation(unsigned int orientation) - { - mOrientation = orientation; - } - - unsigned int 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()); - } -} diff --git a/src/guichan/widgets/textbox.cpp b/src/guichan/widgets/textbox.cpp deleted file mode 100644 index 554aab9341..0000000000 --- a/src/guichan/widgets/textbox.cpp +++ /dev/null @@ -1,556 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naess�n a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u - -#include "guichan/basiccontainer.h" -#include "guichan/keyinput.h" -#include "guichan/mouseinput.h" -#include "guichan/widgets/scrollarea.h" -#include "guichan/widgets/textbox.h" -#include "guichan/exception.h" - -namespace gcn -{ - TextBox::TextBox() - { - mCaretColumn = 0; - mCaretRow = 0; - mEditable = true; - mOpaque = true; - - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - adjustSize(); - setBorderSize(1); - } - - TextBox::TextBox(const std::string& text) - { - mCaretColumn = 0; - mCaretRow = 0; - mEditable = true; - mOpaque = true; - - setText(text); - - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - adjustSize(); - setBorderSize(1); - } - - void TextBox::setText(const std::string& text) - { - mCaretColumn = 0; - mCaretRow = 0; - - mTextRows.clear(); - - std::string::size_type pos, lastPos = 0; - int length; - do - { - pos = text.find("\n", lastPos); - - if (pos != std::string::npos) - { - length = pos - lastPos; - } - else - { - length = text.size() - lastPos; - } - std::string sub = text.substr(lastPos, length); - mTextRows.push_back(sub); - lastPos = pos + 1; - - } while (pos != std::string::npos); - - adjustSize(); - } - - void TextBox::draw(Graphics* graphics) - { - unsigned int i; - - if (mOpaque) - { - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - } - - if (hasFocus() && isEditable()) - { - drawCaret(graphics, getFont()->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn)), mCaretRow * getFont()->getHeight()); - } - - graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); - - for (i = 0; i < mTextRows.size(); i++) - { - // Move the text one pixel so we can have a caret before a letter. - graphics->drawText(mTextRows[i], 1, i * getFont()->getHeight()); - } - } - - void TextBox::drawBorder(Graphics* graphics) - { - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - - graphics->setColor(getBackgroundColor()); - - unsigned int i; - for (i = 0; i < getBorderSize(); ++i) - { - graphics->drawLine(i,i, width - i, i); - graphics->drawLine(i,i + 1, i, height - i - 1); - graphics->drawLine(width - i,i + 1, width - i, height - i); - graphics->drawLine(i,height - i, width - i - 1, height - i); - } - } - - void TextBox::drawCaret(Graphics* graphics, int x, int y) - { - graphics->setColor(getForegroundColor()); - graphics->drawLine(x, getFont()->getHeight() + y, x, y); - } - - void TextBox::mousePress(int x, int y, int button) - { - if (hasMouse() && button == MouseInput::LEFT) - { - mCaretRow = y / getFont()->getHeight(); - - if (mCaretRow >= (int)mTextRows.size()) - { - mCaretRow = mTextRows.size() - 1; - } - - mCaretColumn = getFont()->getStringIndexAt(mTextRows[mCaretRow], x); - } - } - - bool TextBox::keyPress(const Key& key) - { - bool ret = false; - - if (key.getValue() == Key::LEFT) - { - --mCaretColumn; - if (mCaretColumn < 0) - { - --mCaretRow; - - if (mCaretRow < 0) - { - mCaretRow = 0; - mCaretColumn = 0; - } - else - { - mCaretColumn = mTextRows[mCaretRow].size(); - } - } - ret = true; - } - - 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; - } - } - ret = true; - } - - else if (key.getValue() == Key::DOWN) - { - setCaretRow(mCaretRow + 1); - ret = true; - } - - else if (key.getValue() == Key::UP) - { - setCaretRow(mCaretRow - 1); - ret = true; - } - - else if (key.getValue() == Key::HOME) - { - mCaretColumn = 0; - ret = true; - } - - else if (key.getValue() == Key::END) - { - mCaretColumn = mTextRows[mCaretRow].size(); - ret = true; - } - - 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; - ret = true; - } - - else if (key.getValue() == Key::BACKSPACE - && mCaretColumn != 0 - && mEditable) - { - mTextRows[mCaretRow].erase(mCaretColumn - 1, 1); - --mCaretColumn; - ret = true; - } - - 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; - ret = true; - } - - else if (key.getValue() == Key::DELETE - && mCaretColumn < (int)mTextRows[mCaretRow].size() - && mEditable) - { - mTextRows[mCaretRow].erase(mCaretColumn, 1); - ret = true; - } - - 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); - ret = true; - } - - else if(key.getValue() == Key::PAGE_UP) - { - int w, h, rowsPerPage; - getParent()->getDrawSize(w, h, this); - rowsPerPage = h / getFont()->getHeight(); - mCaretRow -= rowsPerPage; - - if (mCaretRow < 0) - { - mCaretRow = 0; - } - ret = true; - } - - else if(key.getValue() == Key::PAGE_DOWN) - { - int w, h, rowsPerPage; - getParent()->getDrawSize(w, h, this); - rowsPerPage = h / getFont()->getHeight(); - mCaretRow += rowsPerPage; - - if (mCaretRow >= (int)mTextRows.size()) - { - mCaretRow = mTextRows.size() - 1; - } - ret = true; - } - - else if(key.getValue() == Key::TAB - && mEditable) - { - mTextRows[mCaretRow].insert(mCaretColumn,std::string(" ")); - mCaretColumn += 4; - ret = true; - } - - else if (key.isCharacter() - && mEditable) - { - mTextRows[mCaretRow].insert(mCaretColumn,std::string(1,(char)key.getValue())); - ++mCaretColumn; - ret = true; - } - - adjustSize(); - scrollToCaret(); - return ret; - } - - 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; - } - } - - unsigned int TextBox::getCaretRow() const - { - return mCaretRow; - } - - void TextBox::setCaretColumn(int column) - { - mCaretColumn = column; - - if (mCaretColumn > (int)mTextRows[mCaretRow].size()) - { - mCaretColumn = mTextRows[mCaretRow].size(); - } - - if (mCaretColumn < 0) - { - mCaretColumn = 0; - } - } - - unsigned int TextBox::getCaretColumn() const - { - return mCaretColumn; - } - - const std::string& TextBox::getTextRow(int row) const - { - return mTextRows[row]; - } - - void TextBox::setTextRow(int row, const std::string& text) - { - mTextRows[row] = text; - - if (mCaretRow == row) - { - setCaretColumn(mCaretColumn); - } - - adjustSize(); - } - - unsigned int TextBox::getNumberOfRows() const - { - return mTextRows.size(); - } - - std::string TextBox::getText() const - { - if (mTextRows.size() == 0) - { - return std::string(""); - } - - int i; - std::string text; - - for (i = 0; i < (int)mTextRows.size() - 1; ++i) - { - text = text + mTextRows[i] + "\n"; - } - - text = text + mTextRows[i]; - - return text; - } - - void TextBox::fontChanged() - { - adjustSize(); - } - - void TextBox::scrollToCaret() - { - Widget *par = getParent(); - if (par == NULL) - { - return; - } - - ScrollArea* scrollArea = dynamic_cast(par); - if (scrollArea != NULL) - { - Rectangle scroll; - scroll.x = getFont()->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn)); - scroll.y = getFont()->getHeight() * mCaretRow; - scroll.width = 6; - scroll.height = getFont()->getHeight() + 2; // add 2 for some extra space - scrollArea->scrollToRectangle(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 de0a0dbbe7..0000000000 --- a/src/guichan/widgets/textfield.cpp +++ /dev/null @@ -1,288 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naess�n a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1usetColor(faceColor); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - - if (hasFocus()) - { - drawCaret(graphics, getFont()->getWidth(mText.substr(0, mCaretPosition)) - mXScroll); - } - - graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); - graphics->drawText(mText, 1 - mXScroll, 1); - } - - void TextField::drawBorder(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(shadowColor); - graphics->drawLine(i,i, width - i, i); - graphics->drawLine(i,i + 1, i, height - i - 1); - graphics->setColor(highlightColor); - graphics->drawLine(width - i,i + 1, width - i, height - i); - graphics->drawLine(i,height - i, width - i - 1, height - i); - } - } - - void TextField::drawCaret(Graphics* graphics, int x) - { - graphics->setColor(getForegroundColor()); - graphics->drawLine(x, getHeight() - 2, x, 1); - } - - void TextField::mousePress(int x, int, int button) - { - if (hasMouse() && button == MouseInput::LEFT) - { - mCaretPosition = getFont()->getStringIndexAt(mText, x + mXScroll); - fixScroll(); - } - } - - void TextField::mouseMotion(int x, int) - { - if (isDragged() && mClickButton == MouseInput::LEFT) - { - mCaretPosition = getFont()->getStringIndexAt(mText, x + mXScroll); - setDirty(true); - } - } - - bool TextField::keyPress(const Key& key) - { - bool ret = false; - - if (key.getValue() == Key::LEFT && mCaretPosition > 0) - { - --mCaretPosition; - ret = true; - } - - else if (key.getValue() == Key::RIGHT && mCaretPosition < mText.size()) - { - ++mCaretPosition; - ret = true; - } - - else if (key.getValue() == Key::DELETE && mCaretPosition < mText.size()) - { - mText.erase(mCaretPosition, 1); - ret = true; - } - - else if (key.getValue() == Key::BACKSPACE && mCaretPosition > 0) - { - mText.erase(mCaretPosition - 1, 1); - --mCaretPosition; - ret = true; - } - - else if (key.getValue() == Key::ENTER) - { - generateAction(); - ret = true; - } - - else if (key.getValue() == Key::HOME) - { - mCaretPosition = 0; - ret = true; - } - - else if (key.getValue() == Key::END) - { - mCaretPosition = mText.size(); - ret = true; - } - - else if (key.isCharacter()) - { - mText.insert(mCaretPosition, std::string(1,(char)key.getValue())); - ++mCaretPosition; - ret = true; } - - fixScroll(); - setDirty(true); - return ret; - } - - void TextField::adjustSize() - { - setWidth(getFont()->getWidth(mText) + 4); - adjustHeight(); - - fixScroll(); - } - - void TextField::adjustHeight() - { - setHeight(getFont()->getHeight() + 2); - } - - void TextField::fixScroll() - { - if (hasFocus()) - { - int caretX = getFont()->getWidth(mText.substr(0, mCaretPosition)); - - if (caretX - mXScroll > getWidth() - 4) - { - mXScroll = caretX - getWidth() + 4; - } - else if (caretX - mXScroll < getFont()->getWidth(" ")) - { - mXScroll = caretX - getFont()->getWidth(" "); - - 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 518328783e..0000000000 --- a/src/guichan/widgets/window.cpp +++ /dev/null @@ -1,504 +0,0 @@ -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004, 2005 darkbits Js_./ - * Per Larsson a.k.a finalman _RqZ{a<^_aa - * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// - * _Qhm`] _f "'c 1!5m - * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' - * binary forms, with or without )4d[#7r, . ' )d`)[ - * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' - * that the following conditions are met: j<. a J@\ - * this list of conditions and the j(]1u -#include "guichan/widgets/window.h" -#include "guichan/exception.h" -#include "guichan/mouseinput.h" - -namespace gcn -{ - Window::Window() - { - mContent = NULL; - mMouseDrag = false; - setBorderSize(1); - setPadding(2); - setTitleBarHeight(16); - setAlignment(Graphics::CENTER); - addMouseListener(this); - setMovable(true); - setOpaque(true); - } - - Window::Window(const std::string& caption) - { - mContent = NULL; - mMouseDrag = false; - setCaption(caption); - setBorderSize(1); - setPadding(2); - setTitleBarHeight(16); - setAlignment(Graphics::CENTER); - addMouseListener(this); - setMovable(true); - setOpaque(true); - } - - Window::Window(Widget* content, const std::string& caption) - { - mContent = NULL; - mMouseDrag = false; - setContent(content); - setCaption(caption); - setBorderSize(1); - setPadding(2); - setTitleBarHeight(16); - setAlignment(Graphics::CENTER); - addMouseListener(this); - setMovable(true); - setOpaque(true); - } - - Window::~Window() - { - setContent(NULL); - } - - void Window::setPadding(unsigned int padding) - { - mPadding = padding; - repositionContent(); - } - - unsigned int Window::getPadding() const - { - return mPadding; - } - - void Window::setTitleBarHeight(unsigned int height) - { - mTitleBarHeight = height; - repositionContent(); - } - - unsigned int Window::getTitleBarHeight() - { - return mTitleBarHeight; - } - - void Window:: _announceDeath(Widget *) - { - mContent = NULL; - } - - void Window::setContent(Widget* widget) - { - if (getContent() != NULL) - { - getContent()->_setParent(NULL); - getContent()->_setFocusHandler(NULL); - } - - if (widget != NULL) - { - widget->_setParent(this); - widget->_setFocusHandler(_getFocusHandler()); - } - - mContent = widget; - repositionContent(); - } - - Widget* Window::getContent() const - { - return mContent; - } - - void Window::setCaption(const std::string& caption) - { - mCaption = caption; - setDirty(true); - } - - const std::string& Window::getCaption() const - { - return mCaption; - } - - void Window::setAlignment(unsigned int alignment) - { - mAlignment = alignment; - } - - unsigned int Window::getAlignment() const - { - return mAlignment; - } - - void Window::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; - - Rectangle d = getContentDimension(); - - // 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); - - drawContent(graphics); - - int textX = 0; - 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."); - assert(!"Unknown alignment."); - } - - graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); - graphics->drawText(getCaption(), textX, textY, getAlignment()); - } - - void Window::drawBorder(Graphics* graphics) - { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - int width = getWidth() + getBorderSize() * 2 - 1; - int height = getHeight() + getBorderSize() * 2 - 1; - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - unsigned int i; - for (i = 0; i < getBorderSize(); ++i) - { - graphics->setColor(highlightColor); - graphics->drawLine(i,i, width - i, i); - graphics->drawLine(i,i + 1, i, height - i - 1); - graphics->setColor(shadowColor); - graphics->drawLine(width - i,i + 1, width - i, height - i); - graphics->drawLine(i,height - i, width - i - 1, height - i); - } - } - - void Window::drawContent(Graphics* graphics) - { - if (getContent() != NULL) - { - graphics->pushClipArea(getContentDimension()); - graphics->pushClipArea(Rectangle(0, 0, getContent()->getWidth(), - getContent()->getHeight())); - getContent()->draw(graphics); - graphics->popClipArea(); - graphics->popClipArea(); - } - } - - void Window::mousePress(int x, int y, int button) - { - if (getParent() != NULL) - { - getParent()->moveToTop(this); - } - - if (isMovable() && hasMouse() - && y < (int)(getTitleBarHeight() + getPadding()) && button == 1) - { - mMouseDrag = true; - mMouseXOffset = x; - mMouseYOffset = y; - } - } - - void Window::mouseRelease(int, int, int button) - { - if (button == 1) - { - mMouseDrag = false; - } - } - - void Window::mouseMotion(int x, int y) - { - if (mMouseDrag && isMovable()) - { - setPosition(x - mMouseXOffset + getX(), - y - mMouseYOffset + getY()); - setDirty(true); - } - } - - void Window::moveToTop(Widget* widget) - { - if (widget != getContent()) - { - //throw GCN_EXCEPTION("Widget is not content of window."); - assert(!"Widget is not content of window."); - } - } - - void Window::moveToBottom(Widget* widget) - { - if (widget != getContent()) - { - //throw GCN_EXCEPTION("Widget is not content of window"); - assert(!"Widget is not content of window."); - } - } - - void Window::getDrawSize(int& width, int& height, Widget* widget) - { - if (widget != getContent()) - { - //throw GCN_EXCEPTION("Widget is not content of window"); - assert(!"Widget is not content of window."); - } - - Rectangle d = getContentDimension(); - width = d.width; - height = d.height; - } - - void Window::repositionContent() - { - if (getContent() == NULL) - { - return; - } - - Rectangle d = getContentDimension(); - mContent->setPosition(d.x, d.y); - } - - Rectangle Window::getContentDimension() - { - 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::resizeToContent() - { - if (getContent() != NULL) - { - setSize(getContent()->getWidth() + 2*getPadding(), - getContent()->getHeight() + getPadding() - + getTitleBarHeight()); - } - } - - void Window::_mouseInputMessage(const MouseInput &mouseInput) - { - BasicContainer::_mouseInputMessage(mouseInput); - - if (getContent() != NULL) - { - if (getContentDimension().isPointInRect(mouseInput.x, mouseInput.y) && - getContent()->getDimension().isPointInRect(mouseInput.x, mouseInput.y)) - { - if (!getContent()->hasMouse()) - { - getContent()->_mouseInMessage(); - } - - MouseInput mi = mouseInput; - mi.x -= getContent()->getX(); - mi.y -= getContent()->getY(); - getContent()->_mouseInputMessage(mi); - } - else if (getContent()->hasMouse()) - { - getContent()->_mouseOutMessage(); - } - } - } - - void Window::_mouseOutMessage() - { - BasicContainer::_mouseOutMessage(); - - if (getContent() != NULL && getContent()->hasMouse()) - { - getContent()->_mouseOutMessage(); - } - } - - void Window::_setFocusHandler(FocusHandler *focusHandler) - { - if (getContent() != NULL) - { - getContent()->_setFocusHandler(focusHandler); - } - - BasicContainer::_setFocusHandler(focusHandler); - } - - void Window::setOpaque(bool opaque) - { - mOpaque = opaque; - } - - bool Window::isOpaque() - { - return mOpaque; - } - - void Window::logic() - { - if (getContent() != NULL) - { - getContent()->logic(); - } - } - - void Window::setDirty(bool dirty) - { - if (mContent != NULL) - { - mContent->setDirty(dirty); - } - mDirty = dirty; - } - - bool Window::getDirty() const - { - if (mDirty == true) - { - return true; - } - - if (mContent != NULL && mContent->getDirty()) - { - return true; - } - - return false; - } -} diff --git a/src/include/font.h b/src/include/font.h index 8e3ca2a114..f2e8613711 100644 --- a/src/include/font.h +++ b/src/include/font.h @@ -62,7 +62,7 @@ #include "color.h" #include -#include +#include #include #include diff --git a/src/include/movie.h b/src/include/movie.h index 1413a19b81..942e20a6ac 100644 --- a/src/include/movie.h +++ b/src/include/movie.h @@ -33,7 +33,7 @@ //@{ #include -#include +#include #ifdef USE_VORBIS diff --git a/src/include/video.h b/src/include/video.h index afbaab4ee4..acd0bf6269 100644 --- a/src/include/video.h +++ b/src/include/video.h @@ -40,7 +40,7 @@ #include "vec2i.h" #include -#include +#include #include #include diff --git a/src/include/widgets.h b/src/include/widgets.h index a0552c7dc1..c96f8bdf7e 100644 --- a/src/include/widgets.h +++ b/src/include/widgets.h @@ -34,10 +34,10 @@ #include "luacallback.h" #include -#include -#include -#include -#include +#include +#include +#include +#include extern bool GuichanActive; diff --git a/src/stratagus/mainloop.cpp b/src/stratagus/mainloop.cpp index 150b2dffb4..6c101156ff 100644 --- a/src/stratagus/mainloop.cpp +++ b/src/stratagus/mainloop.cpp @@ -58,7 +58,7 @@ # include #endif -#include +#include void DrawGuichanWidgets(); diff --git a/src/stratagus/stratagus.cpp b/src/stratagus/stratagus.cpp index a54290f5a9..5b8a79dc90 100644 --- a/src/stratagus/stratagus.cpp +++ b/src/stratagus/stratagus.cpp @@ -210,7 +210,7 @@ extern void beos_init(int argc, char **argv); #include "missile.h" //for FreeBurningBuildingFrames #include -#include +#include #ifdef USE_STACKTRACE #include diff --git a/src/ui/botpanel.cpp b/src/ui/botpanel.cpp index 4e2e781925..122455d174 100644 --- a/src/ui/botpanel.cpp +++ b/src/ui/botpanel.cpp @@ -57,8 +57,8 @@ #include "video.h" #include -#include -#include +#include +#include #include #include diff --git a/src/video/font.cpp b/src/video/font.cpp index 720f4e8fea..2f70d763ab 100644 --- a/src/video/font.cpp +++ b/src/video/font.cpp @@ -40,7 +40,7 @@ #include "intern_video.h" #include "video.h" -#include +#include #include #include diff --git a/third-party b/third-party index 8b9aa5aa20..722884c4ad 160000 --- a/third-party +++ b/third-party @@ -1 +1 @@ -Subproject commit 8b9aa5aa205741d13584e07cf9fc06fbb1f4b753 +Subproject commit 722884c4add0c479af506fa6bed9fc2c9d840489