From b756077a7d1e95b1147ba29dcf483d9337e03010 Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Wed, 7 Aug 2024 19:23:11 +0200 Subject: [PATCH 1/6] Apply Guichan's changes from 9a2ff887fe263f5a6954123b596f0201526315f7 (Jan 20th 2008) Output operator has been added. --- TODO | 2 +- include/guisan/rectangle.hpp | 10 ++++++++++ src/rectangle.cpp | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index 1e58a65..14d4a47 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -* Continue rebasing from 4c1d9a0bb1393dafb8efe28849c09914261a8ad8 +* Continue rebasing from 869e0ce38da05623c040b063ac612de2be60e5e5 * Add a focus listener interface. * Make focus apply synchronously. * Graphics and input objects for DirectX. diff --git a/include/guisan/rectangle.hpp b/include/guisan/rectangle.hpp index 7746f13..e4853cb 100644 --- a/include/guisan/rectangle.hpp +++ b/include/guisan/rectangle.hpp @@ -59,6 +59,8 @@ #include "guisan/platform.hpp" +#include + namespace gcn { /** @@ -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/src/rectangle.cpp b/src/rectangle.cpp index 90e56a1..0343d9c 100644 --- a/src/rectangle.cpp +++ b/src/rectangle.cpp @@ -133,4 +133,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 << "]"; + } } From b1e3217678db9a94c262632e6dbf1223ec682ceb Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Wed, 7 Aug 2024 19:36:53 +0200 Subject: [PATCH 2/6] Apply Guichan's changes from 869e0ce38da05623c040b063ac612de2be60e5e5 (Jan 20th 2008) Widget::showPart has been added to simplify showing a specific part of a widget if a widget is larger than its container. This function utilises the BasicContianer::showWidgetPart function. --- ChangeLog | 4 ++++ TODO | 2 +- include/guisan/basiccontainer.hpp | 16 +++++++++++++--- include/guisan/widget.hpp | 12 ++++++++++++ src/widget.cpp | 8 ++++++++ src/widgets/listbox.cpp | 8 +------- src/widgets/textbox.cpp | 8 +------- 7 files changed, 40 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 05c27d6..8f1473c 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. diff --git a/TODO b/TODO index 14d4a47..3e2197f 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -* Continue rebasing from 869e0ce38da05623c040b063ac612de2be60e5e5 +* Continue rebasing from 3a75046d763099215a96be741a884385f2bb98c3 * 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/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/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) From 12c5849650c0e805bc815e0e1f6433dbdf591276 Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Wed, 7 Aug 2024 19:42:40 +0200 Subject: [PATCH 3/6] Apply Guichan's changes from 4f31cb074edcc134e87b444a3ea1466f29ebe310 (Jan 21th 2008) Output operator has been added. --- TODO | 2 +- include/guisan/color.hpp | 10 ++++++++++ src/color.cpp | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index 3e2197f..e25601e 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -* Continue rebasing from 3a75046d763099215a96be741a884385f2bb98c3 +* Continue rebasing from af86ee2b8a77ea318fbf1fd9e16592afb9279d8c * Add a focus listener interface. * Make focus apply synchronously. * Graphics and input objects for DirectX. 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/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 << "]"; + } } From 6b080bc1fc8c8a9c2fab5e757ef50ed743e23fee Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Wed, 7 Aug 2024 19:51:48 +0200 Subject: [PATCH 4/6] Apply Guichan's changes from af86ee2b8a77ea318fbf1fd9e16592afb9279d8c (Jan 21th 2008) `isIntersecting` is now a `const` function. --- TODO | 2 +- include/guisan/rectangle.hpp | 2 +- src/rectangle.cpp | 41 +++++++++++++++++------------------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/TODO b/TODO index e25601e..55bf576 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -* Continue rebasing from af86ee2b8a77ea318fbf1fd9e16592afb9279d8c +* Continue rebasing from 21896b57ad7651168c3c534df17b57d612bf98f4 * Add a focus listener interface. * Make focus apply synchronously. * Graphics and input objects for DirectX. diff --git a/include/guisan/rectangle.hpp b/include/guisan/rectangle.hpp index e4853cb..8a175a4 100644 --- a/include/guisan/rectangle.hpp +++ b/include/guisan/rectangle.hpp @@ -107,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 diff --git a/src/rectangle.cpp b/src/rectangle.cpp index 0343d9c..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; } From 2348b150f120b8aa66182e447b37e0e89c49eee9 Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Wed, 7 Aug 2024 19:59:16 +0200 Subject: [PATCH 5/6] Apply Guichan's changes from 21896b57ad7651168c3c534df17b57d612bf98f4 (Jan 23th 2008) Fixed documentation of WidgetListener class and removed trailing whitespace in ChangeLog file. --- ChangeLog | 72 +++++++++++++++---------------- TODO | 2 +- include/guisan/widgetlistener.hpp | 4 +- 3 files changed, 40 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8f1473c..61df639 100644 --- a/ChangeLog +++ b/ChangeLog @@ -35,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. @@ -50,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 @@ -63,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 @@ -83,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 @@ -106,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 @@ -118,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. @@ -126,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 @@ -162,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, @@ -209,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 55bf576..8cb2c96 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -* Continue rebasing from 21896b57ad7651168c3c534df17b57d612bf98f4 +* Continue rebasing from 5b96b96c855a7a731b31fd42ffd2d460ca0b42d5 * Add a focus listener interface. * Make focus apply synchronously. * Graphics and input objects for DirectX. 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 From 32a9214127fcba6726d79ea055e8cb5ef3e299c7 Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Wed, 7 Aug 2024 20:08:00 +0200 Subject: [PATCH 6/6] Apply Guichan's changes from 5b96b96c855a7a731b31fd42ffd2d460ca0b42d5 (Jan 23th 2008) Fixed reference to `DropDown::addSelectionListener` and tweaked docs for `valueChanged` a little. --- TODO | 2 +- include/guisan/selectionlistener.hpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/TODO b/TODO index 8cb2c96..7db1bc3 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -* Continue rebasing from 5b96b96c855a7a731b31fd42ffd2d460ca0b42d5 +* Continue rebasing from e5271f1ad79923ffa1810e2bc62435117d49ce9f * Add a focus listener interface. * Make focus apply synchronously. * Graphics and input objects for DirectX. 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