diff --git a/ChangeLog b/ChangeLog index 05c27d6..61df639 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ Version 1.1.0 ============= +* Widget::showPart has been added to be used when a specific + part of a widget should be visible. An example is when a text + area wants a specific text part to be visible in a scroll area. + This function uses BasicContainer::showWidgetPart. * Rectangle::intersect has been renamed to Rectangle::isIntersecting. * Widget::hasModalFocus has been renamed to Widget::isModalFocused. * Widget::hasModalMouseInputFocus has been renamed to Widget::isModalMouseInputFocused. @@ -31,10 +35,10 @@ Version 0.6.0 ============= * A lot of function definitions from BasicContainer have been moved down to Widget, but Widget doesn't provide any useful implementations of these - functions. Useful implementations still reside in BasicContainer. - For container widget implementations inheriting from BasicContainer, as before, - should work just fine. The reason for the move of definitions is to be able to - consider a widget a container for the sake of simplicity when it comes to + functions. Useful implementations still reside in BasicContainer. + For container widget implementations inheriting from BasicContainer, as before, + should work just fine. The reason for the move of definitions is to be able to + consider a widget a container for the sake of simplicity when it comes to distribution of input. * The functions Widget::lostFocus andWidget::gotFocus have been renamed to Widget::focusLost and Widget::focusGained. @@ -46,12 +50,12 @@ Version 0.6.0 * All distribution of input is now handled by the Gui class. Because of this all functions regarding input have been removed from the classes Widget and BasicContainer. -* All functions of KeyListener and MouseListener have been renamed. The reason - for this is that the functions now bear the names of the well known Java +* All functions of KeyListener and MouseListener have been renamed. The reason + for this is that the functions now bear the names of the well known Java listeners which will hopefully be more intuitive for most people. * All input events can now be consumed making it easier to implement hot key bindings. -* Mouse input (now called mouse events) are now distributed bottom up starting +* Mouse input (now called mouse events) are now distributed bottom up starting from the widget directly under the mouse. * Widgets can now ask for modal mouse input focus. A widget with modal mouse input focus will be the only widget recieving mouse input, no matter where the mouse @@ -59,18 +63,18 @@ Version 0.6.0 acquires modal mouse input focus when folded down to be able to fold back up as soon as the mouse is pressed outside of the drop down. * Events are now present in Guichan. All listener classes now take event classes - as parameters which is a very big API change. The presence of events has propagated - changes to all input classes to better reflect the new usage of events. + as parameters which is a very big API change. The presence of events has propagated + changes to all input classes to better reflect the new usage of events. * DropDown now acts on mouse wheel up and mouse wheel down when having focus. * ListBox now acts on mouse wheel up and mouse wheel down when having focus. -* Widgets will no longer acquire focus if a mouse wheel up or a mouse wheel down +* Widgets will no longer acquire focus if a mouse wheel up or a mouse wheel down occurs over a widget. -* The header exception.hpp is now included properly in openglsdlimageloader.hpp. +* The header exception.hpp is now included properly in openglsdlimageloader.hpp. * Many small fixes. - + Version 0.5.0 ============= -* Slider now acts on the mouse wheel moving the slider to the left on +* Slider now acts on the mouse wheel moving the slider to the left on mouse wheel down and to the right on mouse wheen up. * ListBox now has the ability to wrap keyboard selection. Wrapping means that if the key up is pressed and the first item is selected, then @@ -79,19 +83,19 @@ Version 0.5.0 * Redesign of the Image class. Image now has different subclasses for different Graphics objects. The static method load in the Image class loads the appropiate type of image if an ImageLoader is set. -* The function action in ActionListener now takes a pointer to the +* The function action in ActionListener now takes a pointer to the Widget who called the function, it makes handling of action events, hopefully, cleaner. -* ScrollArea now scrolls if the open space around the markers is clicked. +* ScrollArea now scrolls if the open space around the markers is clicked. * ScrollArea now has functions to set the amount to scroll when ScrollArea's - buttons are pushed, each button can have it's own amount. + buttons are pushed, each button can have it's own amount. * Changed the function name of Widget::hasFocus and FocusHandler::hasFocus to isFocused. * Moved a lot of common container functionality into BasicContainer. This made the code and API a lot cleaner. Affected classes are: BasicContainer - now holds a lot of common functionality for containers. Container - implementation is now a lot smaller. - Window - window now inherits from Container and can have several child + Window - window now inherits from Container and can have several child widgets. ScrollArea - smaller, nicer code. TextBox & ListBox - Takes advantage of the new Container API to get rid @@ -102,7 +106,7 @@ Version 0.5.0 * Fixed an offset by one error in AllegroGraphics::_beginDraw. The initial clip area is now correct. * Added alpha blending with SDL for 16bpp and 24 bpp mode. - + Version 0.4.0 ============= * The GCN_EXCEPTION macro is now capable of determine the function in @@ -114,7 +118,7 @@ Version 0.4.0 * Optimized fillRect in SDLGraphics slightly when using alpha blending. However, SDLGraphics still needs a lot of optimizing in other parts. -* Removed the filename from the Image class, as it wasn't really +* Removed the filename from the Image class, as it wasn't really used for anything. * Updated ImageFont with support for font images with several rows of glyphs. @@ -122,14 +126,14 @@ Version 0.4.0 stealing all input from other widgets. Can be useful when making dialog windows. * Many small fixes. - + Version 0.3.0 -============= -* Every Guichan library now contains a C function which can be +============= +* Every Guichan library now contains a C function which can be used with autotools check, for instance the Guichan SDL library contains the function gcnSDL wich can be used when struggling - with autoconf. Other functions are gcnAllegro in Guichan Allegro, - gcnOpenGL in Guichan OpenGL and gcnGuichanVersion in the Guichan + with autoconf. Other functions are gcnAllegro in Guichan Allegro, + gcnOpenGL in Guichan OpenGL and gcnGuichanVersion in the Guichan core. * Slider now stores only the current selected value and calculates everything from that value. It should take care of some resizing @@ -158,46 +162,46 @@ Version 0.2.0 to the configure script which forces Guichan to compile with the forced support. * Updated platform.hpp to be able to handle compilation with MinGW. -* Splited DECLSPEC define into GCN_CORE_DECLSPEC and +* Splited DECLSPEC define into GCN_CORE_DECLSPEC and GCN_EXTENSION_DECLSPEC. * Fixed bugs in ScrollArea and DropDown involving focus and mouse input, -* Changed the look when CheckBox is marked. +* Changed the look when CheckBox is marked. * Changed the look when CheckBox and RadioButton are focused. They now draw a rectangle around their captions (common behaivour in Guis). * Removed unaccesary logic functions (which didn't do anything) in - widget RadioButton and CheckBox. + widget RadioButton and CheckBox. * Added a new widget called Slider, and it is a... slider! * Removed getWidth for glyphs in Font. -* Removed function drawGlyph in Font and in addon SDLTrueTypeFont. +* Removed function drawGlyph in Font and in addon SDLTrueTypeFont. Added drawGlyph function in ImageFont and DefaultFont. - drawGlyph in Font is easy to missunderstand and could lead to + drawGlyph in Font is easy to missunderstand and could lead to strange implementations of Font. * Added getCurrentClipArea function in Graphics. * All functions in container are now virtual (thanks to Garo pointing this out). * Added function setSize in Widget. * Added an "addons" directory in the distrobution. It will contain usefull classes with Guichan that are not compiled into the library. - They are not compiled because they need dependencies other then + They are not compiled because they need dependencies other then Guichans or are to specific. For now, "addons" only contain one class, SDLTrueTypeFont giving True Type Font abilities to Guichan through the SDL_ttf library and hence will only work with SDLGraphics. SDLTrueTypeFont was contributed by Walluce Pinkham (and edited by us). Thank you Walluce! -* Added getColor function in Graphics. Implemented in SDLGraphics, +* Added getColor function in Graphics. Implemented in SDLGraphics, AllegroGraphics and OpenGLGraphics. * Fixed a problem with the DropDown widget. When the widget was focused with a mouse press, you couldn't select elements with up and down keys. * Merged drawText, drawTextCenter and drawTextRight into one function drawText which takes an alignment parameter (thanks Ted!). Widgets taking advantage of this are Button and Label. -* As a result of the added border support, almost every widget have +* As a result of the added border support, almost every widget have been changed for the better, e.g removal of offsets. * Added support for borders. This is a major API change introducing - some new functions to Widget. + some new functions to Widget. * Lots of small bugfixes - + Version 0.1.0 -============= +============= * Guichan_allegro MSVC 6 compatibility fix. * TextBox doesn't draw its caret if its not editable. * Better exception with more information in ImageFont, @@ -205,7 +209,7 @@ Version 0.1.0 * Fixed problem in ImageFont when loading a corrupt file. It will now throw an exception (thanks Terin!). * Implemented _getRawData() in AllegroImageLoader. -* Fixed Image. It is now overloadable. +* Fixed Image. It is now overloadable. * DropDown sets the colors for its internal widgets if they are not custom widgets (not given to the DropDown by the user). * Now all default widgets respect the alpha channel in the colors. diff --git a/TODO b/TODO index 1e58a65..7db1bc3 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -* Continue rebasing from 4c1d9a0bb1393dafb8efe28849c09914261a8ad8 +* Continue rebasing from e5271f1ad79923ffa1810e2bc62435117d49ce9f * Add a focus listener interface. * Make focus apply synchronously. * Graphics and input objects for DirectX. diff --git a/include/guisan/basiccontainer.hpp b/include/guisan/basiccontainer.hpp index ae77d60..a844569 100644 --- a/include/guisan/basiccontainer.hpp +++ b/include/guisan/basiccontainer.hpp @@ -81,9 +81,21 @@ namespace gcn */ virtual ~BasicContainer(); - // Inherited from Widget + /** + * Shows a certain part of a widget in the basic container. + * Used when widgets want a specific part to be visible in + * its parent. An example is a TextArea that wants a specific + * part of its text to be visible when a TextArea is a child + * of a ScrollArea. + * + * @param widget The widget whom wants a specific part of + * itself to be visible. + * @param rectangle The rectangle to be visible. + */ + virtual void showWidgetPart(Widget* widget, Rectangle area); + virtual void moveToTop(Widget* widget); virtual void moveToBottom(Widget* widget); @@ -100,8 +112,6 @@ namespace gcn void setInternalFocusHandler(FocusHandler* focusHandler); - virtual void showWidgetPart(Widget* widget, Rectangle area); - virtual Widget *getWidgetAt(int x, int y); diff --git a/include/guisan/color.hpp b/include/guisan/color.hpp index 3d077ba..ed4ce00 100644 --- a/include/guisan/color.hpp +++ b/include/guisan/color.hpp @@ -59,6 +59,8 @@ #include "guisan/platform.hpp" +#include + namespace gcn { /** @@ -149,6 +151,14 @@ namespace gcn */ bool operator!=(const Color& color) const; + /** + * Output operator for output. + * + * @param out The stream to output to. + * @param color The color to output. + */ + friend std::ostream& operator<<(std::ostream& out, const Color& Color); + /** * Holds the red color component (range 0-255). */ diff --git a/include/guisan/rectangle.hpp b/include/guisan/rectangle.hpp index 7746f13..8a175a4 100644 --- a/include/guisan/rectangle.hpp +++ b/include/guisan/rectangle.hpp @@ -59,6 +59,8 @@ #include "guisan/platform.hpp" +#include + namespace gcn { /** @@ -105,7 +107,7 @@ namespace gcn * @return True if the rectangles intersect, false otherwise. * @since 1.1.0 */ - bool isIntersecting(const Rectangle& rectangle); + bool isIntersecting(const Rectangle& rectangle) const; /** * Checks if a point is inside the rectangle @@ -117,6 +119,14 @@ namespace gcn */ bool isPointInRect(int x, int y) const; + /** + * Output operator for output. + * + * @param out The stream to output to. + * @param rectangle The rectangle to output. + */ + friend std::ostream& operator<<(std::ostream& out, const Rectangle& rectangle); + /** * Holds the x coordinate of the rectangle. */ diff --git a/include/guisan/selectionlistener.hpp b/include/guisan/selectionlistener.hpp index eba8a49..46087c4 100644 --- a/include/guisan/selectionlistener.hpp +++ b/include/guisan/selectionlistener.hpp @@ -69,7 +69,7 @@ namespace gcn * * @see ListBox::addSelectionListener, * ListBox::removeSelectionListener, - * DropDown:addSelectionListener, + * DropDown::addSelectionListener, * DropDown::removeSelectionListener * @author Olof Naessén * @since 0.8.0 @@ -84,8 +84,9 @@ namespace gcn virtual ~SelectionListener() { } /** - * Called when a value has been changed in a Widget. It is used - * to be able to recieve a notification that a value has been changed. + * Called when the value of a selection has been changed in a Widget. + * It is used to be able to receive a notification that a value has + * been changed. * * @param event The event of the value change. * @since 0.8.0 diff --git a/include/guisan/widget.hpp b/include/guisan/widget.hpp index 6c852cd..7414a33 100644 --- a/include/guisan/widget.hpp +++ b/include/guisan/widget.hpp @@ -949,6 +949,18 @@ namespace gcn */ const std::string& getId(); + /** + * Shows a certain part of a widget in the widget's parent. + * Used when widgets want a specific part to be visible in + * its parent. An example is a TextArea that wants a specific + * part of its text to be visible when a TextArea is a child + * of a ScrollArea. + * + * @param rectangle The rectangle to be shown. + * @since 1.1.0 + */ + virtual void showPart(Rectangle rectangle); + protected: /** * Distributes an action event to all action listeners diff --git a/include/guisan/widgetlistener.hpp b/include/guisan/widgetlistener.hpp index dfc50f7..c70ab22 100644 --- a/include/guisan/widgetlistener.hpp +++ b/include/guisan/widgetlistener.hpp @@ -65,7 +65,9 @@ namespace gcn { /** - * Interface for listening for selection events from widgets. + * Interface for listening for events from widgets. When a widget's size, + * location or visibility changes, the relevant method of the listener is + * invoked. * * @see Widget::addWidgetListener, Widget::removeWidgetListener * @author Olof Naessén diff --git a/src/color.cpp b/src/color.cpp index 84a9a95..b9c28c5 100644 --- a/src/color.cpp +++ b/src/color.cpp @@ -134,4 +134,10 @@ namespace gcn { return !(r == color.r && g == color.g && b == color.b && a == color.a); } + + std::ostream& operator<<(std::ostream& out, const Color& color) + { + return out << "Color [r = " << color.r << ", g = " << color.g << ", b = " << color.b + << ", a = " << color.a << "]"; + } } diff --git a/src/rectangle.cpp b/src/rectangle.cpp index 90e56a1..666fafd 100644 --- a/src/rectangle.cpp +++ b/src/rectangle.cpp @@ -86,44 +86,41 @@ namespace gcn this->height = height; } - bool Rectangle::isIntersecting(const Rectangle& rectangle) + bool Rectangle::isIntersecting(const Rectangle& rectangle) const { - x -= rectangle.x; - y -= rectangle.y; + int x_ = x; + int y_ = y; + int width_ = width; + int height_ = height; - if (x < 0) + x_ -= rectangle.x; + y_ -= rectangle.y; + + if (x_ < 0) { - width += x; - x = 0; + width_ += x_; + x_ = 0; } - - if (y < 0) + else if (x_ + width_ > rectangle.width) { - height += y; - y = 0; + width_ = rectangle.width - x_; } - if (x + width > rectangle.width) + if (y_ < 0) { - width = rectangle.width - x; + height_ += y_; + y_ = 0; } - - if (y + height > rectangle.height) + else if (y_ + height_ > rectangle.height) { - height = rectangle.height - y; + height_ = rectangle.height - y_; } - if (width <= 0 || height <= 0) + 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; } @@ -133,4 +130,10 @@ namespace gcn && x < (this->x + this->width) && y < (this->y + this->height)); } + + std::ostream& operator<<(std::ostream& out, const Rectangle& rectangle) + { + return out << "Rectangle [x = " << rectangle.x << ", y = " << rectangle.y + << ", width = " << rectangle.width << ", height = " << rectangle.height << "]"; + } } diff --git a/src/widget.cpp b/src/widget.cpp index 54f105f..73c17d2 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -735,4 +735,12 @@ namespace gcn (*iter)->widgetShown(event); } } + + void Widget::showPart(Rectangle rectangle) + { + if (mParent != NULL) + { + mParent->showWidgetPart(this, rectangle); + } + } } diff --git a/src/widgets/listbox.cpp b/src/widgets/listbox.cpp index 3861275..8fa123f 100644 --- a/src/widgets/listbox.cpp +++ b/src/widgets/listbox.cpp @@ -197,12 +197,6 @@ namespace gcn mSelected = selected; } - Widget* par = getParent(); - if (par == NULL) - { - return; - } - Rectangle scroll; if (mSelected < 0) @@ -215,7 +209,7 @@ namespace gcn } scroll.height = getFont()->getHeight(); - par->showWidgetPart(this, scroll); + showPart(scroll); } distributeValueChangedEvent(); diff --git a/src/widgets/textbox.cpp b/src/widgets/textbox.cpp index c33eeef..e8872c3 100644 --- a/src/widgets/textbox.cpp +++ b/src/widgets/textbox.cpp @@ -517,18 +517,12 @@ namespace gcn void TextBox::scrollToCaret() { - Widget *par = getParent(); - if (par == NULL) - { - return; - } - Rectangle scroll; scroll.x = getFont()->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn)); scroll.y = getFont()->getHeight() * mCaretRow; scroll.width = getFont()->getWidth(" "); scroll.height = getFont()->getHeight() + 2; // add 2 for some extra space - par->showWidgetPart(this,scroll); + showPart(scroll); } void TextBox::setEditable(bool editable)