diff --git a/Android.mk b/Android.mk index 1ed73e4b..ee2df16a 100644 --- a/Android.mk +++ b/Android.mk @@ -154,10 +154,6 @@ LOCAL_SRC_FILES := src/archivers/7z/BraIA64.c \ src/osdep/amiberry_whdbooter.cpp \ src/osdep/sigsegv_handler.cpp \ src/sounddep/sound.cpp \ - src/osdep/gui/UaeRadioButton.cpp \ - src/osdep/gui/UaeDropDown.cpp \ - src/osdep/gui/UaeCheckBox.cpp \ - src/osdep/gui/UaeListBox.cpp \ src/osdep/gui/InGameMessage.cpp \ src/osdep/gui/SelectorEntry.cpp \ src/osdep/gui/ShowHelp.cpp \ diff --git a/CMakeLists.txt b/CMakeLists.txt index 330864fd..cae89519 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,10 +168,6 @@ set(SRC_FILES src/osdep/amiberry_whdbooter.cpp src/osdep/sigsegv_handler.cpp src/sounddep/sound.cpp - src/osdep/gui/UaeRadioButton.cpp - src/osdep/gui/UaeDropDown.cpp - src/osdep/gui/UaeCheckBox.cpp - src/osdep/gui/UaeListBox.cpp src/osdep/gui/InGameMessage.cpp src/osdep/gui/SelectorEntry.cpp src/osdep/gui/ShowHelp.cpp diff --git a/Makefile b/Makefile index a4af6ede..8d5c29c2 100644 --- a/Makefile +++ b/Makefile @@ -397,10 +397,6 @@ OBJS = \ src/osdep/amiberry_whdbooter.o \ src/osdep/sigsegv_handler.o \ src/sounddep/sound.o \ - src/osdep/gui/UaeRadioButton.o \ - src/osdep/gui/UaeDropDown.o \ - src/osdep/gui/UaeCheckBox.o \ - src/osdep/gui/UaeListBox.o \ src/osdep/gui/InGameMessage.o \ src/osdep/gui/SelectorEntry.o \ src/osdep/gui/ShowHelp.o \ diff --git a/VisualGDB/Amiberry/Amiberry.vcxproj b/VisualGDB/Amiberry/Amiberry.vcxproj index f323b33a..0b7460c3 100644 --- a/VisualGDB/Amiberry/Amiberry.vcxproj +++ b/VisualGDB/Amiberry/Amiberry.vcxproj @@ -283,10 +283,6 @@ - - - - @@ -438,10 +434,6 @@ - - - - diff --git a/VisualGDB/Amiberry/Amiberry.vcxproj.filters b/VisualGDB/Amiberry/Amiberry.vcxproj.filters index 96f0fa9a..1873ed45 100644 --- a/VisualGDB/Amiberry/Amiberry.vcxproj.filters +++ b/VisualGDB/Amiberry/Amiberry.vcxproj.filters @@ -403,18 +403,6 @@ Source files\osdep\gui - - Source files\osdep\gui - - - Source files\osdep\gui - - - Source files\osdep\gui - - - Source files\osdep\gui - Source files\jit @@ -642,18 +630,6 @@ Source files\osdep\gui - - Source files\osdep\gui - - - Source files\osdep\gui - - - Source files\osdep\gui - - - Source files\osdep\gui - Source files\include diff --git a/external/libguisan/include/guisan/basiccontainer.hpp b/external/libguisan/include/guisan/basiccontainer.hpp index 6c12c6ba..bef368af 100644 --- a/external/libguisan/include/guisan/basiccontainer.hpp +++ b/external/libguisan/include/guisan/basiccontainer.hpp @@ -65,95 +65,95 @@ namespace gcn { - /** - * Implements basic container behaviour. Most container will suffice by - * inheriting from this class. - * - * @see Container - */ - class GCN_CORE_DECLSPEC BasicContainer : public Widget, public DeathListener - { - public: - /** - * Destructor - */ - virtual ~BasicContainer(); + /** + * Implements basic container behaviour. Most container will suffice by + * inheriting from this class. + * + * @see Container + */ + class GCN_CORE_DECLSPEC BasicContainer : public Widget, public DeathListener + { + public: + /** + * Destructor + */ + virtual ~BasicContainer(); - // Inherited from Widget + // Inherited from Widget - virtual void moveToTop(Widget* widget); + void moveToTop(Widget* widget) override; - virtual void moveToBottom(Widget* widget); + void moveToBottom(Widget* widget) override; - virtual Rectangle getChildrenArea(); + Rectangle getChildrenArea() override; - virtual void focusNext(); + void focusNext() override; - virtual void focusPrevious(); + void focusPrevious() override; - virtual void logic(); + void logic() override; - virtual void _setFocusHandler(FocusHandler* focusHandler); + void _setFocusHandler(FocusHandler* focusHandler) override; - void setInternalFocusHandler(FocusHandler* focusHandler); + void setInternalFocusHandler(FocusHandler* focusHandler) override; - virtual void showWidgetPart(Widget* widget, Rectangle area); + void showWidgetPart(Widget* widget, Rectangle area) override; - virtual Widget *getWidgetAt(int x, int y); + Widget* getWidgetAt(int x, int y) override; - // Inherited from DeathListener + // Inherited from DeathListener - virtual void death(const Event& event); + void death(const Event& event) override; - protected: - /** - * Adds a widget to the basic container. - * - * @param widget the widget to add. - */ - void add(Widget* widget); + protected: + /** + * Adds a widget to the basic container. + * + * @param widget the widget to add. + */ + virtual void add(Widget* widget); - /** - * Removes a widget from the basic container. - * - * @param widget the widget to remove. - */ - virtual void remove(Widget* widget); + /** + * Removes a widget from the basic container. + * + * @param widget the widget to remove. + */ + virtual void remove(Widget* widget); - /** - * Clears the basic container from all widgets. - */ - virtual void clear(); - - /** - * Draws children widgets. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawChildren(Graphics* graphics); + /** + * Clears the basic container from all widgets. + */ + virtual void clear(); - /** - * Calls logic for children widgets. - */ - virtual void logicChildren(); + /** + * Draws children widgets. + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawChildren(Graphics* graphics); - /** - * Finds a widget given an id. - * - * @param id the id to find a widget by. - * @return the widget with the corrosponding id, - NULL of no widget is found. - */ - virtual Widget* findWidgetById(const std::string& id); + /** + * Calls logic for children widgets. + */ + virtual void logicChildren(); - typedef std::list WidgetList; - typedef WidgetList::iterator WidgetListIterator; - typedef WidgetList::reverse_iterator WidgetListReverseIterator; + /** + * Finds a widget given an id. + * + * @param id the id to find a widget by. + * @return the widget with the corrosponding id, + NULL of no widget is found. + */ + virtual Widget* findWidgetById(const std::string& id); - WidgetList mWidgets; - }; + typedef std::list WidgetList; + typedef WidgetList::iterator WidgetListIterator; + typedef WidgetList::reverse_iterator WidgetListReverseIterator; + + WidgetList mWidgets; + }; } #endif // end GCN_BASICCONTAINER_HPP diff --git a/external/libguisan/include/guisan/listmodel.hpp b/external/libguisan/include/guisan/listmodel.hpp index ebedfff7..be6478e7 100644 --- a/external/libguisan/include/guisan/listmodel.hpp +++ b/external/libguisan/include/guisan/listmodel.hpp @@ -63,36 +63,36 @@ 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 class and implement it's - * functions. - */ - class GCN_CORE_DECLSPEC ListModel - { + /** + * 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 class and implement it's + * functions. + */ + class GCN_CORE_DECLSPEC ListModel + { + public: + /** + * Destructor. + */ + virtual ~ListModel() + = default; - public: - /** - * Destructor. - */ - virtual ~ListModel() { } + /** + * Gets the number of elements in the ListModel. + * + * @return the number of elements in the ListModel + */ + virtual int getNumberOfElements() = 0; - /** - * 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; - }; + /** + * 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; + }; } #endif // end GCN_LISTMODEL_HPP diff --git a/external/libguisan/include/guisan/widget.hpp b/external/libguisan/include/guisan/widget.hpp index eb28f596..b2c5cb05 100644 --- a/external/libguisan/include/guisan/widget.hpp +++ b/external/libguisan/include/guisan/widget.hpp @@ -65,813 +65,815 @@ namespace gcn { - class ActionListener; - class BasicContainer; - class DeathListener; - class DefaultFont; - class FocusHandler; - class FocusListener; - class Font; - class Graphics; - class KeyInput; - class KeyListener; - class MouseInput; - class MouseListener; - class WidgetListener; - - /** - * 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 - * - * @author Olof Naessén - * @author Per Larsson. - */ - class GCN_CORE_DECLSPEC Widget - { - public: - /** - * Constructor. Resets member variables. Noteable, a widget is not - * focusable as default, therefore, widgets that are supposed to be - * focusable should overide this default in their own constructor. - */ - Widget(); - - /** - * Default destructor. - */ - virtual ~Widget(); - - /** - * Draws the widget. It is called by the parent widget when it is time - * for the widget to draw itself. The graphics object is set up so - * that all drawing is relative to the widget, i.e coordinate (0,0) is - * the top-left corner of the widget. It is not possible to draw - * outside of a widgets dimension. - * - * @param graphics a Graphics object to draw with. - */ - virtual void draw(Graphics* graphics) = 0; - - /** - * Draws 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* 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 Widget* getParent() const; - - /** - * Sets the width of the widget in pixels. - * - * @param width the widget width in pixels. - */ - void setWidth(int width); - - /** - * Gets the width of the widget in pixels. - * - * @return the widget with in pixels. - */ - int getWidth() const; - - /** - * Sets the height of the widget in pixels. - * - * @param height the widget height in pixels. - */ - void setHeight(int height); - - /** - * Gets the height of the widget in pixels. - * - * @return the widget height in pixels. - */ - int getHeight() const; - - /** - * Sets the size of the widget. - * - * @param width the width. - * @param height the height. - */ - void setSize(int width, int height); - - /** - * Set the widget x coordinate. It is relateive to it's parent. - * - * @param x the widget x coordinate. - */ - void setX(int x); - - /** - * Gets the widget x coordinate. It is relative to it's parent. - * - * @return the widget x coordinate. - */ - int getX() const; - - /** - * Set the widget y coordinate. It is relative to it's parent. - * - * @param y the widget y coordinate. - */ - void setY(int y); - - /** - * Gets the widget y coordinate. It is relative to it's parent. - * - * @return the widget y coordinate. - */ - 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. - */ - void setPosition(int x, int y); - - /** - * Sets the dimension of the widget. It is relative to it's parent. - * - * @param dimension the widget dimension. - */ - 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 - */ - 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 - */ - unsigned int getBorderSize() const; - - /** - * Gets the dimension of the widget. It is relative to it's parent. - * - * @return the widget dimension. - */ - const Rectangle& getDimension() const; - - /** - * Sets a widgets focusability. - * - * @param focusable true if the widget should be focusable. - */ - void setFocusable(bool focusable); - - /** - * Checks whether the widget is focusable. - * - * @return true if the widget is focusable. - */ - bool isFocusable() const; - - /** - * Checks if the widget is focused. - * - * @return true if the widget currently has focus. - */ - virtual bool isFocused() 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. - */ - void setEnabled(bool enabled); - - /** - * Checks if a widget is disabled or not. - * - * @return true if the widget should be enabled. - */ - bool isEnabled() const; - - /** - * Sets the widget to be visible. - * - * @param visible true if the widget should be visiable. - */ - void setVisible(bool visible); - - /** - * Checks if the widget is visible. - * - * @return true if the widget is visible. - */ - 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. - */ - void setBaseColor(const Color& color); - - /** - * Gets the base color. - * - * @return the foreground color. - */ - const Color& getBaseColor() const; - - /** - * Sets the foreground color. - * - * @param color the foreground color. - */ - void setForegroundColor(const Color& color); - - /** - * Gets the foreground color. - * - * @return the foreground color. - */ - const Color& getForegroundColor() const; - - /** - * Sets the background color. - * - * @param color the background Color. - */ - void setBackgroundColor(const Color& color); - - /** - * Gets the background color. - * - * @return the background color. - */ - const Color& getBackgroundColor() const; - - /** - * Sets the selection color. - * - * @param color the selection color. - */ - void setSelectionColor(const Color& color); - - /** - * Gets the selection color. - * - * @return the selection color. - */ - const Color& getSelectionColor() const; - - /** - * Requests focus for the widget. A widget will only recieve focus - * if it is focusable. - */ - virtual void requestFocus(); - - /** - * Requests a move to the top in the parent widget. - */ - virtual void requestMoveToTop(); - - /** - * Requests a move to the bottom in the parent widget. - */ - virtual void requestMoveToBottom(); - - /** - * Sets the 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. - */ - void addActionListener(ActionListener* actionListener); - - /** - * Removes an added ActionListener from the widget. - * - * @param actionListener the ActionListener to remove. - */ - void removeActionListener(ActionListener* actionListener); - - /** - * Adds a DeathListener to the widget. When the widget dies - * the death function in all the widget's DeathListeners will be called. - * - * @param actionListener the DeathListener to add. - */ - void addDeathListener(DeathListener* deathListener); - - /** - * Removes an added DeathListener from the widget. - * - * @param deathListener the DeathListener to remove. - */ - void removeDeathListener(DeathListener* deathListener); - - /** - * 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. - */ - void addMouseListener(MouseListener* mouseListener); - - /** - * Removes an added MouseListener from the widget. - * - * @param mouseListener the MouseListener to remove. - */ - 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. - */ - void addKeyListener(KeyListener* keyListener); - - /** - * Removes an added KeyListener from the widget. - * - * @param keyListener the KeyListener to remove. - */ - void removeKeyListener(KeyListener* keyListener); - - /** - * Adds a FocusListener to the widget. When a focus event is recieved, - * it will be sent to the widget's FocusListeners. - * - * @param focusListener the FocusListener to add. - * @author Olof Naessén - * @since 0.7.0 - */ - void addFocusListener(FocusListener* focusListener); - - /** - * Removes an added FocusListener from the widget. - * - * @param focusListener the FocusListener to remove. - * @author Olof Naessén - * @since 0.7.0 - */ - void removeFocusListener(FocusListener* focusListener); - - /** - * Adds a WidgetListener to the widget. - * - * @param widgetListener the WidgetListener to add. - * @author Olof Naessén - * @since 0.8.0 - */ - void addWidgetListener(WidgetListener* widgetListener); - - /** - * Removes an added WidgetListener from the widget. - * - * @param widgetListener the WidgetListener to remove. - * @author Olof Naessén - * @since 0.8.0 - */ - void removeWidgetListener(WidgetListener* widgetListener); - - /** - * Sets the action event identifier of the widget. The identifier is - * used to be able to identify which action has occured. - * - * NOTE: An action event identifier should not be used to identify a - * certain widget but rather a certain event in your application. - * Several widgets can have the same action event identifer. - * - * @param actionEventId the action event identifier. - * @since 0.6.0 - */ - void setActionEventId(const std::string& actionEventId); - - /** - * Gets the action event identifier. - * - * @return the action event identifier. - */ - const std::string& getActionEventId() 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(Widget* 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. - */ - 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() { } - - /** - * 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. - */ - 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. - */ - 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. - */ - 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. - */ - void setTabOutEnabled(bool enabled); - - /** - * Requests modal focus. When a widget has modal focus, only that - * widget and it's children may recieve input. - * - * @throws Exception if another widget already has modal focus. - */ - virtual void requestModalFocus(); - - /** - * Requests modal mouse input focus. When a widget has modal input focus - * that widget will be the only widget receiving input even if the input - * occurs outside of the widget and no matter what the input is. - * - * @throws Exception if another widget already has modal focus. - * @since 0.6.0 - */ - virtual void requestModalMouseInputFocus(); - - /** - * Releases modal focus. Modal focus will only be released if the - * widget has modal focus. - */ - virtual void releaseModalFocus(); - - /** - * Releases modal mouse input focus. Modal mouse input focus will only - * be released if the widget has modal mouse input focus. - * - * @since 0.6.0 - */ - virtual void releaseModalMouseInputFocus(); - - /** - * Checks if the widget or it's parent has modal focus. - */ - virtual bool hasModalFocus() const; - - /** - * Checks if the widget or it's parent has modal mouse input focus. - * - * @since 0.6.0 - */ - virtual bool hasModalMouseInputFocus() const; - - /** - * Gets a widget from a certain position in the widget. - * This function is used to decide which gets mouse input, - * thus it can be overloaded to change that behaviour. - * - * NOTE: This always returns NULL if the widget is not - * a container. - * - * @param x the x coordinate. - * @param y the y coordinate. - * @return the widget at the specified coodinate, or NULL - * if no such widget exists. - * @since 0.6.0 - */ - virtual Widget *getWidgetAt(int x, int y); - - /** - * Gets the mouse listeners of the widget. - * - * @return the mouse listeners of the widget. - * @since 0.6.0 - */ - virtual const std::list& _getMouseListeners(); - - /** - * Gets the key listeners of the widget. - * - * @return the key listeners of the widget. - * @since 0.6.0 - */ - virtual const std::list& _getKeyListeners(); - - /** - * Gets the focus listeners of the widget. - * - * @return the focus listeners of the widget. - * @since 0.7.0 - */ - virtual const std::list& _getFocusListeners(); - - /** - * Gets the subarea of the widget that the children occupy. - * - * @return the subarea as a Rectangle. - */ - virtual Rectangle getChildrenArea(); - - /** - * Gets the internal FocusHandler used. - * - * @return the internalFocusHandler used. If no internal FocusHandler - * is used, NULL will be returned. - */ - virtual FocusHandler* _getInternalFocusHandler(); - - /** - * Sets the internal FocusHandler. An internal focushandler is - * needed if both a widget in the widget and the widget itself - * should be foucsed at the same time. - * - * @param focusHandler the FocusHandler to be used. - */ - void setInternalFocusHandler(FocusHandler* focusHandler); - - /** - * Moves a widget to the top of this widget. The moved widget will be - * drawn above all other widgets in this widget. - * - * @param widget the widget to move. - */ - virtual void moveToTop(Widget* widget) { }; - - /** - * Moves a widget in this widget to the bottom of this widget. - * The moved widget will be drawn below all other widgets in this widget. - * - * @param widget the widget to move. - */ - virtual void moveToBottom(Widget* widget) { }; - - /** - * Focuses the next widget in the widget. - */ - virtual void focusNext() { }; - - /** - * Focuses the previous widget in the widget. - */ - virtual void focusPrevious() { }; - - /** - * Tries to show a specific part of a widget by moving it. Used if the - * widget should act as a container. - * - * @param widget the target widget. - * @param area the area to show. - */ - virtual void showWidgetPart(Widget* widget, Rectangle area) { }; - - /** - * Sets an id of a widget. An id can be useful if a widget needs to be - * identified in a container. For example, if widgets are created by an - * XML document, a certain widget can be retrieved given that the widget - * has an id. - * - * @param id the id to set to the widget. - * @see BasicContainer::findWidgetById - */ - void setId(const std::string& id); - - /** - * Gets the id of a widget. An id can be useful if a widget needs to be - * identified in a container. For example, if widgets are created by an - * XML document, a certain widget can be retrieved given that the widget - * has an id. - * - * @param id the id to set to the widget. - * @see BasicContainer::findWidgetById - */ - const std::string& getId(); - - protected: - /** - * Generates an action to the widget's ActionListeners. - */ - void generateAction(); - - /** - * Distributes resized events to all of the widget's listeners. - * - * @since 0.8.0 - * @author Olof Naessén - */ - void distributeResizedEvent(); - - /** - * Distributes moved events to all of the widget's listeners. - * - * @since 0.8.0 - * @author Olof Naessén - */ - void distributeMovedEvent(); - - /** - * Distributes hidden events to all of the widget's listeners. - * - * @since 0.8.0 - * @author Olof Naessén - */ - void distributeHiddenEvent(); - - /** - * Distributes shown events to all of the widget's listeners. - * - * @since 0.8.0 - * @author Olof Naessén - */ - void distributeShownEvent(); - - typedef std::list MouseListenerList; - typedef MouseListenerList::iterator MouseListenerIterator; - MouseListenerList mMouseListeners; - - typedef std::list KeyListenerList; - KeyListenerList mKeyListeners; - typedef KeyListenerList::iterator KeyListenerIterator; - - typedef std::list ActionListenerList; - ActionListenerList mActionListeners; - typedef ActionListenerList::iterator ActionListenerIterator; - - typedef std::list DeathListenerList; - DeathListenerList mDeathListeners; - typedef DeathListenerList::iterator DeathListenerIterator; - - typedef std::list FocusListenerList; - FocusListenerList mFocusListeners; - typedef FocusListenerList::iterator FocusListenerIterator; - - typedef std::list WidgetListenerList; - WidgetListenerList mWidgetListeners; - typedef WidgetListenerList::iterator WidgetListenerIterator; - - Color mForegroundColor; - Color mBackgroundColor; - Color mBaseColor; - Color mSelectionColor; - FocusHandler* mFocusHandler; - FocusHandler* mInternalFocusHandler; - Widget* mParent; - Rectangle mDimension; - unsigned int mBorderSize; - std::string mActionEventId; - bool mFocusable; - bool mVisible; - bool mTabIn; - bool mTabOut; - bool mEnabled; - std::string mId; - - Font* mCurrentFont; - static DefaultFont mDefaultFont; - static Font* mGlobalFont; - static std::list mWidgets; - }; + class ActionListener; + class BasicContainer; + class DeathListener; + class DefaultFont; + class FocusHandler; + class FocusListener; + class Font; + class Graphics; + class KeyInput; + class KeyListener; + class MouseInput; + class MouseListener; + class WidgetListener; + + /** + * 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 + * + * @author Olof Naessén + * @author Per Larsson. + */ + class GCN_CORE_DECLSPEC Widget + { + public: + /** + * Constructor. Resets member variables. Noteable, a widget is not + * focusable as default, therefore, widgets that are supposed to be + * focusable should overide this default in their own constructor. + */ + Widget(); + + /** + * Default destructor. + */ + virtual ~Widget(); + + /** + * Draws the widget. It is called by the parent widget when it is time + * for the widget to draw itself. The graphics object is set up so + * that all drawing is relative to the widget, i.e coordinate (0,0) is + * the top-left corner of the widget. It is not possible to draw + * outside of a widgets dimension. + * + * @param graphics a Graphics object to draw with. + */ + virtual void draw(Graphics* graphics) = 0; + + /** + * Draws 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* 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. + */ + [[nodiscard]] virtual Widget* 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. + */ + [[nodiscard]] 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. + */ + auto getHeight() const -> int; + + /** + * 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. + */ + void setX(int x); + + /** + * Gets the widget x coordinate. It is relative to it's parent. + * + * @return the widget x coordinate. + */ + [[nodiscard]] int getX() const; + + /** + * Set the widget y coordinate. It is relative to it's parent. + * + * @param y the widget y coordinate. + */ + void setY(int y); + + /** + * Gets the widget y coordinate. It is relative to it's parent. + * + * @return the widget y coordinate. + */ + [[nodiscard]] 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. + */ + 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 + */ + 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 + */ + [[nodiscard]] unsigned int getBorderSize() const; + + /** + * Gets the dimension of the widget. It is relative to it's parent. + * + * @return the widget dimension. + */ + [[nodiscard]] const Rectangle& getDimension() const; + + /** + * Sets a widgets focusability. + * + * @param focusable true if the widget should be focusable. + */ + void setFocusable(bool focusable); + + /** + * Checks whether the widget is focusable. + * + * @return true if the widget is focusable. + */ + [[nodiscard]] bool isFocusable() const; + + /** + * Checks if the widget is focused. + * + * @return true if the widget currently has focus. + */ + [[nodiscard]] virtual bool isFocused() 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. + */ + [[nodiscard]] bool isEnabled() const; + + /** + * Sets the widget to be visible. + * + * @param visible true if the widget should be visiable. + */ + void setVisible(bool visible); + + /** + * Checks if the widget is visible. + * + * @return true if the widget is visible. + */ + [[nodiscard]] 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. + */ + [[nodiscard]] 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. + */ + [[nodiscard]] 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. + */ + [[nodiscard]] const Color& getBackgroundColor() const; + + /** + * Sets the selection color. + * + * @param color the selection color. + */ + virtual void setSelectionColor(const Color& color); + + /** + * Gets the selection color. + * + * @return the selection color. + */ + [[nodiscard]] const Color& getSelectionColor() const; + + /** + * Requests focus for the widget. A widget will only recieve focus + * if it is focusable. + */ + virtual void requestFocus(); + + /** + * Requests a move to the top in the parent widget. + */ + virtual void requestMoveToTop(); + + /** + * Requests a move to the bottom in the parent widget. + */ + virtual void requestMoveToBottom(); + + /** + * Sets the 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. + */ + void addActionListener(ActionListener* actionListener); + + /** + * Removes an added ActionListener from the widget. + * + * @param actionListener the ActionListener to remove. + */ + void removeActionListener(ActionListener* actionListener); + + /** + * Adds a DeathListener to the widget. When the widget dies + * the death function in all the widget's DeathListeners will be called. + * + * @param deathListener the DeathListener to add. + */ + void addDeathListener(DeathListener* deathListener); + + /** + * Removes an added DeathListener from the widget. + * + * @param deathListener the DeathListener to remove. + */ + void removeDeathListener(DeathListener* deathListener); + + /** + * 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. + */ + void addMouseListener(MouseListener* mouseListener); + + /** + * Removes an added MouseListener from the widget. + * + * @param mouseListener the MouseListener to remove. + */ + 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. + */ + void addKeyListener(KeyListener* keyListener); + + /** + * Removes an added KeyListener from the widget. + * + * @param keyListener the KeyListener to remove. + */ + void removeKeyListener(KeyListener* keyListener); + + /** + * Adds a FocusListener to the widget. When a focus event is recieved, + * it will be sent to the widget's FocusListeners. + * + * @param focusListener the FocusListener to add. + * @author Olof Naessén + * @since 0.7.0 + */ + void addFocusListener(FocusListener* focusListener); + + /** + * Removes an added FocusListener from the widget. + * + * @param focusListener the FocusListener to remove. + * @author Olof Naessén + * @since 0.7.0 + */ + void removeFocusListener(FocusListener* focusListener); + + /** + * Adds a WidgetListener to the widget. + * + * @param widgetListener the WidgetListener to add. + * @author Olof Naessén + * @since 0.8.0 + */ + void addWidgetListener(WidgetListener* widgetListener); + + /** + * Removes an added WidgetListener from the widget. + * + * @param widgetListener the WidgetListener to remove. + * @author Olof Naessén + * @since 0.8.0 + */ + void removeWidgetListener(WidgetListener* widgetListener); + + /** + * Sets the action event identifier of the widget. The identifier is + * used to be able to identify which action has occured. + * + * NOTE: An action event identifier should not be used to identify a + * certain widget but rather a certain event in your application. + * Several widgets can have the same action event identifer. + * + * @param actionEventId the action event identifier. + * @since 0.6.0 + */ + void setActionEventId(const std::string& actionEventId); + + /** + * Gets the action event identifier. + * + * @return the action event identifier. + */ + [[nodiscard]] const std::string& getActionEventId() 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(Widget* 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. + */ + [[nodiscard]] 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() + { + } + + /** + * 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. + */ + [[nodiscard]] 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. + */ + 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. + */ + [[nodiscard]] 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. + */ + void setTabOutEnabled(bool enabled); + + /** + * Requests modal focus. When a widget has modal focus, only that + * widget and it's children may recieve input. + * + * @throws Exception if another widget already has modal focus. + */ + virtual void requestModalFocus(); + + /** + * Requests modal mouse input focus. When a widget has modal input focus + * that widget will be the only widget receiving input even if the input + * occurs outside of the widget and no matter what the input is. + * + * @throws Exception if another widget already has modal focus. + * @since 0.6.0 + */ + virtual void requestModalMouseInputFocus(); + + /** + * Releases modal focus. Modal focus will only be released if the + * widget has modal focus. + */ + virtual void releaseModalFocus(); + + /** + * Releases modal mouse input focus. Modal mouse input focus will only + * be released if the widget has modal mouse input focus. + * + * @since 0.6.0 + */ + virtual void releaseModalMouseInputFocus(); + + /** + * Checks if the widget or it's parent has modal focus. + */ + [[nodiscard]] virtual bool hasModalFocus() const; + + /** + * Checks if the widget or it's parent has modal mouse input focus. + * + * @since 0.6.0 + */ + [[nodiscard]] virtual bool hasModalMouseInputFocus() const; + + /** + * Gets a widget from a certain position in the widget. + * This function is used to decide which gets mouse input, + * thus it can be overloaded to change that behaviour. + * + * NOTE: This always returns NULL if the widget is not + * a container. + * + * @param x the x coordinate. + * @param y the y coordinate. + * @return the widget at the specified coodinate, or NULL + * if no such widget exists. + * @since 0.6.0 + */ + virtual Widget* getWidgetAt(int x, int y); + + /** + * Gets the mouse listeners of the widget. + * + * @return the mouse listeners of the widget. + * @since 0.6.0 + */ + virtual const std::list& _getMouseListeners(); + + /** + * Gets the key listeners of the widget. + * + * @return the key listeners of the widget. + * @since 0.6.0 + */ + virtual const std::list& _getKeyListeners(); + + /** + * Gets the focus listeners of the widget. + * + * @return the focus listeners of the widget. + * @since 0.7.0 + */ + virtual const std::list& _getFocusListeners(); + + /** + * Gets the subarea of the widget that the children occupy. + * + * @return the subarea as a Rectangle. + */ + virtual Rectangle getChildrenArea(); + + /** + * Gets the internal FocusHandler used. + * + * @return the internalFocusHandler used. If no internal FocusHandler + * is used, NULL will be returned. + */ + virtual FocusHandler* _getInternalFocusHandler(); + + /** + * Sets the internal FocusHandler. An internal focushandler is + * needed if both a widget in the widget and the widget itself + * should be foucsed at the same time. + * + * @param focusHandler the FocusHandler to be used. + */ + virtual void setInternalFocusHandler(FocusHandler* focusHandler); + + /** + * Moves a widget to the top of this widget. The moved widget will be + * drawn above all other widgets in this widget. + * + * @param widget the widget to move. + */ + virtual void moveToTop(Widget* widget) + { + }; + + /** + * Moves a widget in this widget to the bottom of this widget. + * The moved widget will be drawn below all other widgets in this widget. + * + * @param widget the widget to move. + */ + virtual void moveToBottom(Widget* widget) + { + }; + + /** + * Focuses the next widget in the widget. + */ + virtual void focusNext() + { + }; + + /** + * Focuses the previous widget in the widget. + */ + virtual void focusPrevious() + { + }; + + /** + * Tries to show a specific part of a widget by moving it. Used if the + * widget should act as a container. + * + * @param widget the target widget. + * @param area the area to show. + */ + virtual void showWidgetPart(Widget* widget, Rectangle area) + { + }; + + /** + * Sets an id of a widget. An id can be useful if a widget needs to be + * identified in a container. For example, if widgets are created by an + * XML document, a certain widget can be retrieved given that the widget + * has an id. + * + * @param id the id to set to the widget. + * @see BasicContainer::findWidgetById + */ + void setId(const std::string& id); + + /** + * Gets the id of a widget. An id can be useful if a widget needs to be + * identified in a container. For example, if widgets are created by an + * XML document, a certain widget can be retrieved given that the widget + * has an id. + * + * @param id the id to set to the widget. + * @see BasicContainer::findWidgetById + */ + const std::string& getId() const; + + protected: + /** + * Generates an action to the widget's ActionListeners. + */ + void generateAction(); + + /** + * Distributes resized events to all of the widget's listeners. + * + * @since 0.8.0 + * @author Olof Naessén + */ + void distributeResizedEvent(); + + /** + * Distributes moved events to all of the widget's listeners. + * + * @since 0.8.0 + * @author Olof Naessén + */ + void distributeMovedEvent(); + + /** + * Distributes hidden events to all of the widget's listeners. + * + * @since 0.8.0 + * @author Olof Naessén + */ + void distributeHiddenEvent(); + + /** + * Distributes shown events to all of the widget's listeners. + * + * @since 0.8.0 + * @author Olof Naessén + */ + void distributeShownEvent(); + + typedef std::list MouseListenerList; + typedef MouseListenerList::iterator MouseListenerIterator; + MouseListenerList mMouseListeners; + + typedef std::list KeyListenerList; + KeyListenerList mKeyListeners; + typedef KeyListenerList::iterator KeyListenerIterator; + + typedef std::list ActionListenerList; + ActionListenerList mActionListeners; + typedef ActionListenerList::iterator ActionListenerIterator; + + typedef std::list DeathListenerList; + DeathListenerList mDeathListeners; + typedef DeathListenerList::iterator DeathListenerIterator; + + typedef std::list FocusListenerList; + FocusListenerList mFocusListeners; + typedef FocusListenerList::iterator FocusListenerIterator; + + typedef std::list WidgetListenerList; + WidgetListenerList mWidgetListeners; + typedef WidgetListenerList::iterator WidgetListenerIterator; + + Color mForegroundColor; + Color mBackgroundColor; + Color mBaseColor; + Color mSelectionColor; + FocusHandler* mFocusHandler; + FocusHandler* mInternalFocusHandler; + Widget* mParent; + Rectangle mDimension; + unsigned int mBorderSize; + std::string mActionEventId; + bool mFocusable; + bool mVisible; + bool mTabIn; + bool mTabOut; + bool mEnabled; + std::string mId; + + Font* mCurrentFont; + static DefaultFont mDefaultFont; + static Font* mGlobalFont; + static std::list mWidgets; + }; } #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/external/libguisan/include/guisan/widgets/button.hpp b/external/libguisan/include/guisan/widgets/button.hpp index d120302e..bba0c260 100644 --- a/external/libguisan/include/guisan/widgets/button.hpp +++ b/external/libguisan/include/guisan/widgets/button.hpp @@ -92,7 +92,7 @@ namespace gcn * * @param caption the caption of the Button. */ - Button(const std::string& caption); + explicit Button(std::string caption); /** * Sets the Button caption. @@ -106,7 +106,7 @@ namespace gcn * * @return the Button caption. */ - const std::string& getCaption() const; + [[nodiscard]] const std::string& getCaption() const; /** * Sets the alignment for the caption. @@ -114,14 +114,14 @@ namespace gcn * @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT * @see Graphics */ - void setAlignment(unsigned int alignment); + virtual void setAlignment(unsigned int alignment); /** * Gets the alignment for the caption. * * @return alignment of caption. */ - unsigned int getAlignment() const; + [[nodiscard]] virtual unsigned int getAlignment() const; /** * Sets the spacing between the border of this button and its caption. @@ -136,51 +136,51 @@ namespace gcn * * @return spacing. */ - unsigned int getSpacing() const; + [[nodiscard]] unsigned int getSpacing() const; /** * Adjusts the buttons size to fit the content. */ - void adjustSize(); + virtual void adjustSize(); /** * Checks if the button is pressed down. Useful when drawing. * * @return true if the button is pressed down. */ - bool isPressed() const; + [[nodiscard]] bool isPressed() const; //Inherited from Widget - virtual void draw(Graphics* graphics); + void draw(Graphics* graphics) override; - virtual void drawBorder(Graphics* graphics); + void drawBorder(Graphics* graphics) override; // Inherited from FocusListener - virtual void focusLost(const Event& event); + void focusLost(const Event& event) override; // Inherited from MouseListener - virtual void mousePressed(MouseEvent& mouseEvent); + void mousePressed(MouseEvent& mouseEvent) override; - virtual void mouseReleased(MouseEvent& mouseEvent); + void mouseReleased(MouseEvent& mouseEvent) override; - virtual void mouseEntered(MouseEvent& mouseEvent); + void mouseEntered(MouseEvent& mouseEvent) override; - virtual void mouseExited(MouseEvent& mouseEvent); + void mouseExited(MouseEvent& mouseEvent) override; - virtual void mouseDragged(MouseEvent& mouseEvent); + void mouseDragged(MouseEvent& mouseEvent) override; // Inherited from KeyListener - virtual void keyPressed(KeyEvent& keyEvent); + void keyPressed(KeyEvent& keyEvent) override; - virtual void keyReleased(KeyEvent& keyEvent); + void keyReleased(KeyEvent& keyEvent) override; protected: std::string mCaption; diff --git a/external/libguisan/include/guisan/widgets/container.hpp b/external/libguisan/include/guisan/widgets/container.hpp index ad6c0bc9..a5ce787f 100644 --- a/external/libguisan/include/guisan/widgets/container.hpp +++ b/external/libguisan/include/guisan/widgets/container.hpp @@ -65,113 +65,113 @@ namespace gcn { - /** - * An implementation of a container able to contain other widgets. A widget's - * position in the container is relative to the container itself and not the screen. - * A container is the most common widget to use as the Gui's top widget as makes the Gui - * able to contain more than one widget. - * - * @see Gui::setTop - */ - class GCN_CORE_DECLSPEC Container: public BasicContainer - { - public: + /** + * An implementation of a container able to contain other widgets. A widget's + * position in the container is relative to the container itself and not the screen. + * A container is the most common widget to use as the Gui's top widget as makes the Gui + * able to contain more than one widget. + * + * @see Gui::setTop + */ + class GCN_CORE_DECLSPEC Container : public BasicContainer + { + public: - /** - * Constructor. A container is opauqe as default, if you want a - * none opaque container call setQpaque(false). - * - * @see setOpaque, isOpaque - */ - Container(); + /** + * Constructor. A container is opauqe as default, if you want a + * none opaque container call setQpaque(false). + * + * @see setOpaque, isOpaque + */ + Container(); - /** - * Destructor. - */ - virtual ~Container(); + /** + * Destructor. + */ + virtual ~Container(); - /** - * Sets the container to be opaque or not. If the container - * is opaque it's background will be drawn, if it's not opaque - * it's background will not be drawn, and thus making the container - * completely transparent. - * - * NOTE: This is not the same as to set visibility. A non visible - * container will not itself nor will it draw it's content. - * - * @param opaque True if the container should be opaque, false otherwise. - * @see isOpaque - */ - void setOpaque(bool opaque); + /** + * Sets the container to be opaque or not. If the container + * is opaque it's background will be drawn, if it's not opaque + * it's background will not be drawn, and thus making the container + * completely transparent. + * + * NOTE: This is not the same as to set visibility. A non visible + * container will not itself nor will it draw it's content. + * + * @param opaque True if the container should be opaque, false otherwise. + * @see isOpaque + */ + virtual void setOpaque(bool opaque); - /** - * Checks if the container is opaque or not. - * - * @return true if the container is opaque, false otherwise. - * @see setOpaque - */ - bool isOpaque() const; + /** + * Checks if the container is opaque or not. + * + * @return true if the container is opaque, false otherwise. + * @see setOpaque + */ + [[nodiscard]] bool isOpaque() const; - /** - * Adds a widget to the container. - * - * @param widget The widget to add. - * @see remove, clear - */ - virtual void add(Widget* widget); + /** + * Adds a widget to the container. + * + * @param widget The widget to add. + * @see remove, clear + */ + void add(Widget* widget) override; - /** - * Adds a widget to the container and also specifices the widget's - * postion in the container. The position is relative to the container - * and not relative to the screen. - * - * @param widget The widget to add. - * @param x The x coordinat for the widget. - * @param y The y coordinat for the widget. - * @see remove, clear - */ - virtual void add(Widget* widget, int x, int y); + /** + * Adds a widget to the container and also specifies the widget's + * position in the container. The position is relative to the container + * and not relative to the screen. + * + * @param widget The widget to add. + * @param x The x coordinat for the widget. + * @param y The y coordinat for the widget. + * @see remove, clear + */ + virtual void add(Widget* widget, int x, int y); - /** - * Removes a widget from the Container. - * - * @param widget The widget to remove. - * @throws Exception when the widget has not been added to the - * container. - * @see add, clear - */ - virtual void remove(Widget* widget); + /** + * 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 + */ + void remove(Widget* widget) override; - /** - * Clears the container of all widgets. - * - * @see add, remove - */ - virtual void clear(); + /** + * Clears the container of all widgets. + * + * @see add, remove + */ + void clear() override; - /** - * Finds a widget given an id. - * - * @param id The id to find a widget by. - * @return A widget with a corrosponding id, NULL if no widget - * is found. - * @see Widget::setId - */ - virtual Widget* findWidgetById(const std::string &id); + /** + * Finds a widget given an id. + * + * @param id The id to find a widget by. + * @return A widget with a corrosponding id, NULL if no widget + * is found. + * @see Widget::setId + */ + Widget* findWidgetById(const std::string& id) override; - // Inherited from Widget + // Inherited from Widget - virtual void draw(Graphics* graphics); + void draw(Graphics* graphics) override; - virtual void drawBorder(Graphics* graphics); + void drawBorder(Graphics* graphics) override; - protected: - /** - * True if the container is opaque, false otherwise. - */ - bool mOpaque; - }; + protected: + /** + * True if the container is opaque, false otherwise. + */ + bool mOpaque; + }; } #endif // end GCN_CONTAINER_HPP diff --git a/external/libguisan/include/guisan/widgets/dropdown.hpp b/external/libguisan/include/guisan/widgets/dropdown.hpp index d100daea..8c8ec694 100644 --- a/external/libguisan/include/guisan/widgets/dropdown.hpp +++ b/external/libguisan/include/guisan/widgets/dropdown.hpp @@ -72,230 +72,238 @@ namespace gcn { - /** - * An implementation of a drop downable list from which an item can be selected. - * The drop down consists of an internal ScrollArea and an internal ListBox. - * The drop down also uses an internal FocusHandler to handle the focus of the - * internal ScollArea and the internal ListBox. The scroll area and the list box - * can be passed to the drop down if a custom scroll area and or a custom list box - * is preferable. - * - * To be able display a list the drop down uses a user provided list model. - * A list model can be any class that implements the ListModel interface. - * - * If an item is selected in the drop down a select event will be sent to all selection - * listeners of the drop down. If an item is selected by using a mouse click or by using - * the enter or space key an action event will be sent to all action listeners of the - * drop down. - */ - class GCN_CORE_DECLSPEC DropDown : - public ActionListener, - public BasicContainer, - public KeyListener, - public MouseListener, - public FocusListener, - public SelectionListener - { - public: - /** - * Contructor. - * - * @param listModel the ListModel to use. - * @param scrollArea the ScrollArea to use. - * @param listBox the listBox to use. - * @see ListModel, ScrollArea, ListBox. - */ - DropDown(ListModel *listModel = NULL, - ScrollArea *scrollArea = NULL, - ListBox *listBox = NULL); + /** + * An implementation of a drop downable list from which an item can be selected. + * The drop down consists of an internal ScrollArea and an internal ListBox. + * The drop down also uses an internal FocusHandler to handle the focus of the + * internal ScrollArea and the internal ListBox. The scroll area and the list box + * can be passed to the drop down if a custom scroll area and or a custom list box + * is preferable. + * + * To be able display a list the drop down uses a user provided list model. + * A list model can be any class that implements the ListModel interface. + * + * If an item is selected in the drop down a select event will be sent to all selection + * listeners of the drop down. If an item is selected by using a mouse click or by using + * the enter or space key an action event will be sent to all action listeners of the + * drop down. + */ + class GCN_CORE_DECLSPEC DropDown : + public ActionListener, + public BasicContainer, + public KeyListener, + public MouseListener, + public FocusListener, + public SelectionListener + { + public: + /** + * Constructor. + * + * @param listModel the ListModel to use. + * @param scrollArea the ScrollArea to use. + * @param listBox the listBox to use. + * @see ListModel, ScrollArea, ListBox. + */ + DropDown(ListModel* listModel = nullptr, + ScrollArea* scrollArea = nullptr, + ListBox* listBox = nullptr); - /** - * Destructor. - */ - virtual ~DropDown(); + /** + * Destructor. + */ + virtual ~DropDown(); - /** - * Gets the selected item as an index in the list model. - * - * @return the selected item as an index in the list model. - * @see setSelected - */ - int getSelected() const; + /** + * Gets the selected item as an index in the list model. + * + * @return the selected item as an index in the list model. + * @see setSelected + */ + [[nodiscard]] int getSelected() const; - /** - * Sets the selected item. The selected item is represented by - * an index from the list model. - * - * @param selected the selected item as an index from the list model. - * @see getSelected - */ - void setSelected(int selected); + /** + * Sets the selected item. The selected item is represented by + * an index from the list model. + * + * @param selected the selected item as an index from the list model. + * @see getSelected + */ + void setSelected(int selected) const; - /** - * Sets the list model to use when displaying the list. - * - * @param listModel the list model to use. - * @see getListModel - */ - void setListModel(ListModel *listModel); + /* + * Clears any selected item + */ + virtual void clearSelected(void) const; - /** - * Gets the list model used. - * - * @return the ListModel used. - * @see setListModel - */ - ListModel *getListModel(); + /** + * Sets the list model to use when displaying the list. + * + * @param listModel the list model to use. + * @see getListModel + */ + void setListModel(ListModel* listModel); - /** - * Adjusts the height of the drop down to fit the height of the - * drop down's parent's height. It's used to not make the drop down - * draw itself outside of it's parent if folded down. - */ - void adjustHeight(); + /** + * Gets the list model used. + * + * @return the ListModel used. + * @see setListModel + */ + [[nodiscard]] ListModel* getListModel() const; - /** - * Adds a selection listener to the drop down. When the selection - * changes an event will be sent to all selection listeners of the - * drop down. - * - * @param selectionListener the selection listener to add. - * @since 0.8.0 - */ - void addSelectionListener(SelectionListener* selectionListener); + /** + * Adjusts the height of the drop down to fit the height of the + * drop down's parent's height. It's used to not make the drop down + * draw itself outside of it's parent if folded down. + */ + void adjustHeight(); - /** - * Removes a selection listener from the drop down. - * - * @param selectionListener the selection listener to remove. - * @since 0.8.0 - */ - void removeSelectionListener(SelectionListener* selectionListener); + /** + * Adds a selection listener to the drop down. When the selection + * changes an event will be sent to all selection listeners of the + * drop down. + * + * @param selectionListener the selection listener to add. + * @since 0.8.0 + */ + void addSelectionListener(SelectionListener* selectionListener); + + /** + * Removes a selection listener from the drop down. + * + * @param selectionListener the selection listener to remove. + * @since 0.8.0 + */ + void removeSelectionListener(SelectionListener* selectionListener); + + /* + * Returns the current Dropdown status + */ + [[nodiscard]] virtual bool isDroppedDown() const; + + // Inherited from Widget + + void draw(Graphics* graphics) override; + + void drawBorder(Graphics* graphics) override; + + void setBaseColor(const Color& color) override; + + void setBackgroundColor(const Color& color) override; + + void setForegroundColor(const Color& color) override; + + void setFont(Font* font) override; + + void setSelectionColor(const Color& color) override; - // Inherited from Widget + // Inherited from BasicContainer - virtual void draw(Graphics* graphics); - - virtual void drawBorder(Graphics* graphics); - - void setBaseColor(const Color& color); - - void setBackgroundColor(const Color& color); - - void setForegroundColor(const Color& color); - - void setFont(Font *font); - - void setSelectionColor(const Color& color); + Rectangle getChildrenArea() override; - // Inherited from BasicContainer + // Inherited from FocusListener - virtual Rectangle getChildrenArea(); + void focusLost(const Event& event) override; - // Inherited from FocusListener + // Inherited from ActionListener - virtual void focusLost(const Event& event); + void action(const ActionEvent& actionEvent) override; - // Inherited from ActionListener + // Inherited from DeathListener - virtual void action(const ActionEvent& actionEvent); + void death(const Event& event) override; - // Inherited from DeathListener + // Inherited from KeyListener - virtual void death(const Event& event); + void keyPressed(KeyEvent& keyEvent) override; - // Inherited from KeyListener + // Inherited from MouseListener - virtual void keyPressed(KeyEvent& keyEvent); + void mousePressed(MouseEvent& mouseEvent) override; + + void mouseReleased(MouseEvent& mouseEvent) override; + + void mouseWheelMovedUp(MouseEvent& mouseEvent) override; + + void mouseWheelMovedDown(MouseEvent& mouseEvent) override; + + void mouseDragged(MouseEvent& mouseEvent) override; - // Inherited from MouseListener + // Inherited from SelectionListener - virtual void mousePressed(MouseEvent& mouseEvent); - - virtual void mouseReleased(MouseEvent& mouseEvent); - - virtual void mouseWheelMovedUp(MouseEvent& mouseEvent); - - virtual void mouseWheelMovedDown(MouseEvent& mouseEvent); - - virtual void mouseDragged(MouseEvent& mouseEvent); + void valueChanged(const SelectionEvent& event) override; - // Inherited from SelectionListener + protected: + /** + * Draws the button with the little down arrow. + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawButton(Graphics* graphics); - virtual void valueChanged(const SelectionEvent& event); + /** + * Sets the DropDown Widget to dropped-down mode. + */ + virtual void dropDown(); + /** + * Sets the DropDown Widget to folded-up mode. + */ + virtual void foldUp(); - protected: - /** - * Draws the button with the little down arrow. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawButton(Graphics *graphics); + bool mDroppedDown; - /** - * Sets the DropDown Widget to dropped-down mode. - */ - virtual void dropDown(); + /** + * Distributes a value changed event to all selection listeners + * of the drop down. + * + * @since 0.8.0 + */ + void distributeValueChangedEvent(); - /** - * Sets the DropDown Widget to folded-up mode. - */ - virtual void foldUp(); + bool mPushed; - bool mDroppedDown; + /** + * Holds what the height is if the drop down is folded up. Used when + * checking if the list of the drop down was clicked or if the upper part + * of the drop down was clicked on a mouse click + */ + int mFoldedUpHeight{}; - /** - * Distributes a value changed event to all selection listeners - * of the drop down. - * - * @since 0.8.0 - */ - void distributeValueChangedEvent(); + /** + * The scroll area used. + */ + ScrollArea* mScrollArea; + ListBox* mListBox; + FocusHandler mInternalFocusHandler; + bool mInternalScrollArea; + bool mInternalListBox; + bool mIsDragged; - bool mPushed; + /** + * Typedef. + */ + typedef std::list SelectionListenerList; - /** - * Holds what the height is if the drop down is folded up. Used when - * checking if the list of the drop down was clicked or if the upper part - * of the drop down was clicked on a mouse click - */ - int mFoldedUpHeight{}; - - /** - * The scroll area used. - */ - ScrollArea* mScrollArea; - ListBox* mListBox; - FocusHandler mInternalFocusHandler; - bool mInternalScrollArea; - bool mInternalListBox; - bool mIsDragged; + /** + * The selection listener's of the drop down. + */ + SelectionListenerList mSelectionListeners; - /** - * Typedef. - */ - typedef std::list SelectionListenerList; - - /** - * The selection listener's of the drop down. - */ - SelectionListenerList mSelectionListeners; - - /** - * Typedef. - */ - typedef SelectionListenerList::iterator SelectionListenerIterator; - - }; + /** + * Typedef. + */ + typedef SelectionListenerList::iterator SelectionListenerIterator; + }; } #endif // end GCN_DROPDOWN_HPP diff --git a/external/libguisan/include/guisan/widgets/icon.hpp b/external/libguisan/include/guisan/widgets/icon.hpp index 63604145..3f88f7b1 100644 --- a/external/libguisan/include/guisan/widgets/icon.hpp +++ b/external/libguisan/include/guisan/widgets/icon.hpp @@ -63,51 +63,51 @@ namespace gcn { - /** - * Implements an icon capable of displaying an image. - */ - class GCN_CORE_DECLSPEC Icon: public Widget - { - public: - /** - * Constructor. - * - * @param filename The filename of the image to display. - */ - Icon(const std::string& filename); + /** + * Implements an icon capable of displaying an image. + */ + class GCN_CORE_DECLSPEC Icon : public Widget + { + public: + /** + * Constructor. + * + * @param filename The filename of the image to display. + */ + Icon(const std::string& filename); - /** - * Constructor. - * - * @param image The image to display. - */ - Icon(Image* image); + /** + * Constructor. + * + * @param image The image to display. + */ + Icon(Image* image); - /** - * Descructor. - */ - virtual ~Icon(); + /** + * Descructor. + */ + virtual ~Icon(); - // Inherited from Widget + // Inherited from Widget - virtual void draw(Graphics* graphics); + void draw(Graphics* graphics) override; - virtual void drawBorder(Graphics* graphics); + void drawBorder(Graphics* graphics) override; - protected: - /** - * The image to display. - */ - Image* mImage; + protected: + /** + * The image to display. + */ + Image* mImage; - /** - * True if the image has been loaded internally, false otherwise. - * An image not loaded internally should not be deleted in the - * destructor. - */ - bool mInternalImage; - }; + /** + * True if the image has been loaded internally, false otherwise. + * An image not loaded internally should not be deleted in the + * destructor. + */ + bool mInternalImage; + }; } #endif // end GCN_ICON_HPP diff --git a/external/libguisan/include/guisan/widgets/imagebutton.hpp b/external/libguisan/include/guisan/widgets/imagebutton.hpp index 8029e38b..2080fabb 100644 --- a/external/libguisan/include/guisan/widgets/imagebutton.hpp +++ b/external/libguisan/include/guisan/widgets/imagebutton.hpp @@ -62,66 +62,66 @@ namespace gcn { - class Image; + class Image; - /** - * A simple button that displays an image instead of a caption. - */ - class GCN_CORE_DECLSPEC ImageButton : public gcn::Button - { - public: - /** - * Constructor. - * - * @param filename The filename of the image to display. - */ - ImageButton(const std::string& filename); + /** + * A simple button that displays an image instead of a caption. + */ + class GCN_CORE_DECLSPEC ImageButton : public Button + { + public: + /** + * Constructor. + * + * @param filename The filename of the image to display. + */ + ImageButton(const std::string& filename); - /** - * Constructor. - * - * @param image The image to display. - */ - ImageButton(Image* image); + /** + * Constructor. + * + * @param image The image to display. + */ + ImageButton(Image* image); - /** - * Destructor. - */ - virtual ~ImageButton(); + /** + * Destructor. + */ + virtual ~ImageButton(); - /** - * Adjusts the size of the image button to fit the image. - */ - void adjustSize(); + /** + * Adjusts the size of the image button to fit the image. + */ + void adjustSize() override; - /** - * Sets the image to display. - * - * @param image The image to display. - */ - void setImage(Image* image); + /** + * Sets the image to display. + * + * @param image The image to display. + */ + virtual void setImage(Image* image); - /** - * Gets the image of the image button. - * - * @return The image of the image button. - */ - Image* getImage(); + /** + * Gets the image of the image button. + * + * @return The image of the image button. + */ + virtual Image* getImage(); - // Inherited from Widget + // Inherited from Widget - void draw(gcn::Graphics* graphics); + void draw(Graphics* graphics) override; - protected: - gcn::Image* mImage; + protected: + Image* mImage; - /** - * True if the image has been loaded internally, false otherwise. - * An image not loaded internally should not be deleted in the - * destructor. - */ - bool mInternalImage; - }; + /** + * True if the image has been loaded internally, false otherwise. + * An image not loaded internally should not be deleted in the + * destructor. + */ + bool mInternalImage; + }; } #endif diff --git a/external/libguisan/include/guisan/widgets/label.hpp b/external/libguisan/include/guisan/widgets/label.hpp index d07fe07d..cf2360c8 100644 --- a/external/libguisan/include/guisan/widgets/label.hpp +++ b/external/libguisan/include/guisan/widgets/label.hpp @@ -64,83 +64,83 @@ namespace gcn { - /** - * Implementation of a label capable of displaying a caption. - */ - class GCN_CORE_DECLSPEC Label: public Widget - { - public: - /** - * Constructor. - */ - Label(); + /** + * Implementation of a label capable of displaying a caption. + */ + class GCN_CORE_DECLSPEC Label : public Widget + { + public: + /** + * Constructor. + */ + Label(); - /** - * Constructor. - * - * @param caption The caption of the label. - */ - Label(const std::string& caption); + /** + * Constructor. + * + * @param caption The caption of the label. + */ + Label(const std::string& caption); - /** - * Gets the caption of the label. - * - * @return The caption of the label. - * @see setCaption - */ - const std::string &getCaption() const; + /** + * Gets the caption of the label. + * + * @return The caption of the label. + * @see setCaption + */ + [[nodiscard]] virtual const std::string& getCaption() const; - /** - * Sets the caption of the label. It's advisable to call - * adjustSize after setting of the caption to adjust the - * label's size to fit the caption. - * - * @param caption The caption of the label. - * @see getCaption, adjustSize - */ - void setCaption(const std::string& caption); + /** + * Sets the caption of the label. It's advisable to call + * adjustSize after setting of the caption to adjust the + * label's size to fit the caption. + * + * @param caption The caption of the label. + * @see getCaption, adjustSize + */ + virtual void setCaption(const std::string& caption); - /** - * Sets the alignment for the caption. The alignment is relative - * to the center of the label. - * - * @param alignemnt Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. - * @see getAlignment, Graphics - */ - void setAlignment(unsigned int alignment); + /** + * Sets the alignment for the caption. The alignment is relative + * to the center of the label. + * + * @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. + * @see getAlignment, Graphics + */ + virtual void setAlignment(unsigned int alignment); - /** - * Gets the alignment for the caption. The alignment is relative to - * the center of the label. - * - * @return alignment of caption. Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. - * @see setAlignment, Graphics - */ - unsigned int getAlignment() const; + /** + * Gets the alignment for the caption. The alignment is relative to + * the center of the label. + * + * @return alignment of caption. Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. + * @see setAlignment, Graphics + */ + [[nodiscard]] virtual unsigned int getAlignment() const; - /** - * Adjusts the label's size to fit the caption size. - */ - void adjustSize(); + /** + * Adjusts the label's size to fit the caption size. + */ + virtual void adjustSize(); - // Inherited from Widget + // Inherited from Widget - virtual void draw(Graphics* graphics); + void draw(Graphics* graphics) override; - virtual void drawBorder(Graphics* graphics); + void drawBorder(Graphics* graphics) override; - protected: - /** - * Holds the caption of the label. - */ - std::string mCaption; + protected: + /** + * Holds the caption of the label. + */ + std::string mCaption; - /** - * Holds the alignment of the caption. - */ - unsigned int mAlignment; - }; + /** + * Holds the alignment of the caption. + */ + unsigned int mAlignment; + }; } #endif // end GCN_LABEL_HPP diff --git a/external/libguisan/include/guisan/widgets/listbox.hpp b/external/libguisan/include/guisan/widgets/listbox.hpp index 4e58d8f1..328162a4 100644 --- a/external/libguisan/include/guisan/widgets/listbox.hpp +++ b/external/libguisan/include/guisan/widgets/listbox.hpp @@ -67,188 +67,189 @@ namespace gcn { - class SelectionListener; + class SelectionListener; - /** - * An implementation of a list box where an item can be selected. - * - * To be able display a list the list box uses a user provided list model. - * A list model can be any class that implements the ListModel interface. - * - * If an item is selected in the list box a select event will be sent to all selection - * listeners of the list box. If an item is selected by using a mouse click or by using - * the enter or space key an action event will be sent to all action listeners of the - * list box. - */ - class GCN_CORE_DECLSPEC ListBox : - public Widget, - public MouseListener, - public KeyListener - { - public: - /** - * Constructor. - */ - ListBox(); + /** + * An implementation of a list box where an item can be selected. + * + * To be able display a list the list box uses a user provided list model. + * A list model can be any class that implements the ListModel interface. + * + * If an item is selected in the list box a select event will be sent to all selection + * listeners of the list box. If an item is selected by using a mouse click or by using + * the enter or space key an action event will be sent to all action listeners of the + * list box. + */ + class GCN_CORE_DECLSPEC ListBox : + public Widget, + public MouseListener, + public KeyListener + { + public: + /** + * Constructor. + */ + ListBox(); - /** - * Constructor. - * - * @param listModel the list model to use. - */ - ListBox(ListModel *listModel); + /** + * Constructor. + * + * @param listModel the list model to use. + */ + ListBox(ListModel* listModel); - /** - * Destructor. - */ - virtual ~ListBox() { } + /** + * Destructor. + */ + virtual ~ListBox() + = default; - /** - * Gets the selected item as an index in the list model. - * - * @return the selected item as an index in the list model. - * @see setSelected - */ - int getSelected() const; + /** + * Gets the selected item as an index in the list model. + * + * @return the selected item as an index in the list model. + * @see setSelected + */ + [[nodiscard]] int getSelected() const; - /** - * Sets the selected item. The selected item is represented by - * an index from the list model. - * - * @param selected the selected item as an index from the list model. - * @see getSelected - */ - void setSelected(int selected); + /** + * Sets the selected item. The selected item is represented by + * an index from the list model. + * + * @param selected the selected item as an index from the list model. + * @see getSelected + */ + void setSelected(int selected); - /** - * Sets the list model to use. - * - * @param listModel the list model to use. - * @see getListModel - */ - void setListModel(ListModel *listModel); + /** + * Sets the list model to use. + * + * @param listModel the list model to use. + * @see getListModel + */ + void setListModel(ListModel* listModel); - /** - * Gets the list model used. - * - * @return the list model used. - * @see setListModel - */ - ListModel *getListModel(); + /** + * Gets the list model used. + * + * @return the list model used. + * @see setListModel + */ + [[nodiscard]] ListModel* getListModel() const; - /** - * Adjusts the size of the list box to fit it's list model. - */ - void adjustSize(); + /** + * Adjusts the size of the list box to fit it's list model. + */ + void adjustSize(); - /** - * Checks whether the list box wraps when selecting items with a keyboard. - * - * Wrapping means that the selection of items will be wrapped. That is, if - * the first item is selected and up is pressed, the last item will get - * selected. If the last item is selected and down is pressed, the first item - * will get selected. - * - * @return true if wrapping is enabled, fasle otherwise. - * @see setWrappingEnabled - */ - bool isWrappingEnabled() const; + /** + * Checks whether the list box wraps when selecting items with a keyboard. + * + * Wrapping means that the selection of items will be wrapped. That is, if + * the first item is selected and up is pressed, the last item will get + * selected. If the last item is selected and down is pressed, the first item + * will get selected. + * + * @return true if wrapping is enabled, false otherwise. + * @see setWrappingEnabled + */ + [[nodiscard]] bool isWrappingEnabled() const; - /** - * Sets the list box to wrap or not when selecting items with a keyboard. - * - * Wrapping means that the selection of items will be wrapped. That is, if - * the first item is selected and up is pressed, the last item will get - * selected. If the last item is selected and down is pressed, the first item - * will get selected. - * - * @see isWrappingEnabled - */ - void setWrappingEnabled(bool wrappingEnabled); + /** + * Sets the list box to wrap or not when selecting items with a keyboard. + * + * Wrapping means that the selection of items will be wrapped. That is, if + * the first item is selected and up is pressed, the last item will get + * selected. If the last item is selected and down is pressed, the first item + * will get selected. + * + * @see isWrappingEnabled + */ + void setWrappingEnabled(bool wrappingEnabled); - /** - * Adds a selection listener to the list box. When the selection - * changes an event will be sent to all selection listeners of the - * list box. - * - * @param selectionListener The selection listener to add. - * @since 0.8.0 - */ - void addSelectionListener(SelectionListener* selectionListener); + /** + * Adds a selection listener to the list box. When the selection + * changes an event will be sent to all selection listeners of the + * list box. + * + * @param selectionListener The selection listener to add. + * @since 0.8.0 + */ + void addSelectionListener(SelectionListener* selectionListener); - /** - * Removes a selection listener from the list box. - * - * @param selectionListener The selection listener to remove. - * @since 0.8.0 - */ - void removeSelectionListener(SelectionListener* selectionListener); + /** + * Removes a selection listener from the list box. + * + * @param selectionListener The selection listener to remove. + * @since 0.8.0 + */ + void removeSelectionListener(SelectionListener* selectionListener); - // Inherited from Widget + // Inherited from Widget - virtual void draw(Graphics* graphics); + void draw(Graphics* graphics) override; - virtual void drawBorder(Graphics* graphics); + void drawBorder(Graphics* graphics) override; - virtual void logic(); + void logic() override; - // Inherited from KeyListener + // Inherited from KeyListener - virtual void keyPressed(KeyEvent& keyEvent); + void keyPressed(KeyEvent& keyEvent) override; - // Inherited from MouseListener + // Inherited from MouseListener - virtual void mousePressed(MouseEvent& mouseEvent); + void mousePressed(MouseEvent& mouseEvent) override; - virtual void mouseWheelMovedUp(MouseEvent& mouseEvent); + void mouseWheelMovedUp(MouseEvent& mouseEvent) override; - virtual void mouseWheelMovedDown(MouseEvent& mouseEvent); - - virtual void mouseDragged(MouseEvent& mouseEvent); + void mouseWheelMovedDown(MouseEvent& mouseEvent) override; - - protected: - /** - * Distributes a value changed event to all selection listeners - * of the list box. - * - * @since 0.8.0 - */ - void distributeValueChangedEvent(); + void mouseDragged(MouseEvent& mouseEvent) override; - /** - * The list model to use. - */ - ListModel *mListModel{}; - /** - * The selected item as an index in the list model. - */ - int mSelected; + protected: + /** + * Distributes a value changed event to all selection listeners + * of the list box. + * + * @since 0.8.0 + */ + void distributeValueChangedEvent(); - /** - * True if wrapping is enabled, false otherwise. - */ - bool mWrappingEnabled; + /** + * The list model to use. + */ + ListModel* mListModel{}; - /** - * Typdef. - */ - typedef std::list SelectionListenerList; - - /** - * The selection listeners of the list box. - */ - SelectionListenerList mSelectionListeners; + /** + * The selected item as an index in the list model. + */ + int mSelected; - /** - * Typedef. - */ - typedef SelectionListenerList::iterator SelectionListenerIterator; - }; + /** + * True if wrapping is enabled, false otherwise. + */ + bool mWrappingEnabled; + + /** + * Typedef. + */ + typedef std::list SelectionListenerList; + + /** + * The selection listeners of the list box. + */ + SelectionListenerList mSelectionListeners; + + /** + * Typedef. + */ + typedef SelectionListenerList::iterator SelectionListenerIterator; + }; } #endif // end GCN_LISTBOX_HPP diff --git a/external/libguisan/include/guisan/widgets/radiobutton.hpp b/external/libguisan/include/guisan/widgets/radiobutton.hpp index 570d227e..40edae23 100644 --- a/external/libguisan/include/guisan/widgets/radiobutton.hpp +++ b/external/libguisan/include/guisan/widgets/radiobutton.hpp @@ -67,159 +67,159 @@ namespace gcn { - /** - * Implementation of a radio button where a user can select or deselect - * the radio button and where the status of the radio button is displayed to the user. - * A radio button can belong to a group and when a radio button belongs to a - * group only one radio button can be selected in the group. A radio button is - * capable of displaying a caption. - * - * If a radio button's state changes an action event will be sent to all action - * listeners of the check box. - */ - class GCN_CORE_DECLSPEC RadioButton : - public Widget, - public MouseListener, - public KeyListener - { - public: + /** + * Implementation of a radio button where a user can select or deselect + * the radio button and where the status of the radio button is displayed to the user. + * A radio button can belong to a group and when a radio button belongs to a + * group only one radio button can be selected in the group. A radio button is + * capable of displaying a caption. + * + * If a radio button's state changes an action event will be sent to all action + * listeners of the check box. + */ + class GCN_CORE_DECLSPEC RadioButton : + public Widget, + public MouseListener, + public KeyListener + { + public: - /** - * Constructor. - */ - RadioButton(); + /** + * Constructor. + */ + RadioButton(); - /** - * Constructor. - * - * @param caption The caption of the radio button. - * @param group The group the radio button should belong to. - * @param selected True if the radio button should be selected. - */ - RadioButton(const std::string &caption, - const std::string &group, - bool selected = false); + /** + * Constructor. + * + * @param caption The caption of the radio button. + * @param group The group the radio button should belong to. + * @param selected True if the radio button should be selected. + */ + RadioButton(const std::string& caption, + const std::string& group, + bool selected = false); - /** - * Destructor. - */ - virtual ~RadioButton(); + /** + * Destructor. + */ + virtual ~RadioButton(); - /** - * Checks if the radio button is selected. - * - * @return True if the radio button is selecte, false otherwise. - * @see setSelected - */ - bool isSelected() const; + /** + * Checks if the radio button is selected. + * + * @return True if the radio button is selecte, false otherwise. + * @see setSelected + */ + [[nodiscard]] bool isSelected() const; - /** - * Sets the radio button to selected or not. - * - * @param selected True if the radio button should be selected, - * false otherwise. - * @see isSelected - */ - void setSelected(bool selected); + /** + * Sets the radio button to selected or not. + * + * @param selected True if the radio button should be selected, + * false otherwise. + * @see isSelected + */ + void setSelected(bool selected); - /** - * Gets the caption of the radio button. - * - * @return The caption of the radio button. - * @see setCaption - */ - const std::string &getCaption() const; + /** + * Gets the caption of the radio button. + * + * @return The caption of the radio button. + * @see setCaption + */ + [[nodiscard]] const std::string& getCaption() const; - /** - * Sets the caption of the radio button. It's advisable to call - * adjustSize after setting of the caption to adjust the - * radio button's size to fit the caption. - * - * @param caption The caption of the radio button. - * @see getCaption, adjustSize - */ - void setCaption(const std::string caption); + /** + * Sets the caption of the radio button. It's advisable to call + * adjustSize after setting of the caption to adjust the + * radio button's size to fit the caption. + * + * @param caption The caption of the radio button. + * @see getCaption, adjustSize + */ + void setCaption(std::string caption); - /** - * Sets the group the radio button should belong to. Note that - * a radio button group is unique per application, not per Gui object - * as the group is stored in a static map. - * - * @param group The name of the group. - * @see getGroup - */ - void setGroup(const std::string &group); + /** + * Sets the group the radio button should belong to. Note that + * a radio button group is unique per application, not per Gui object + * as the group is stored in a static map. + * + * @param group The name of the group. + * @see getGroup + */ + void setGroup(const std::string& group); - /** - * Gets the group the radio button belongs to. - * - * @return The group the radio button belongs to. - * @see setGroup - */ - const std::string &getGroup() const; + /** + * Gets the group the radio button belongs to. + * + * @return The group the radio button belongs to. + * @see setGroup + */ + [[nodiscard]] const std::string& getGroup() const; - /** - * Adjusts the radio button's size to fit the caption. - */ - void adjustSize(); + /** + * Adjusts the radio button's size to fit the caption. + */ + void adjustSize(); - // Inherited from Widget + // Inherited from Widget - virtual void draw(Graphics* graphics); + void draw(Graphics* graphics) override; - virtual void drawBorder(Graphics* graphics); + void drawBorder(Graphics* graphics) override; - // Inherited from KeyListener + // Inherited from KeyListener - virtual void keyPressed(KeyEvent& keyEvent); + void keyPressed(KeyEvent& keyEvent) override; - // Inherited from MouseListener + // Inherited from MouseListener - virtual void mouseClicked(MouseEvent& mouseEvent); + void mouseClicked(MouseEvent& mouseEvent) override; - virtual void mouseDragged(MouseEvent& mouseEvent); + void mouseDragged(MouseEvent& mouseEvent) override; - protected: - /** - * Draws the box. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawBox(Graphics *graphics); + protected: + /** + * Draws the box. + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawBox(Graphics* graphics); - /** - * True if the radio button is selected, false otherwise. - */ - bool mSelected{}; + /** + * True if the radio button is selected, false otherwise. + */ + bool mSelected{}; - /** - * Holds the caption of the radio button. - */ - std::string mCaption; + /** + * Holds the caption of the radio button. + */ + std::string mCaption; - /** - * Holds the group of the radio button. - */ - std::string mGroup; + /** + * Holds the group of the radio button. + */ + std::string mGroup; - /** - * Typdef. - */ - typedef std::multimap GroupMap; + /** + * Typdef. + */ + typedef std::multimap GroupMap; - /** - * Typdef. - */ - typedef GroupMap::iterator GroupIterator; + /** + * Typdef. + */ + typedef GroupMap::iterator GroupIterator; - /** - * Holds all available radio button groups. - */ - static GroupMap mGroupMap; - }; + /** + * Holds all available radio button groups. + */ + static GroupMap mGroupMap; + }; } #endif // end GCN_RADIOBUTTON_HPP diff --git a/external/libguisan/include/guisan/widgets/scrollarea.hpp b/external/libguisan/include/guisan/widgets/scrollarea.hpp index c8ce7cb2..126a692c 100644 --- a/external/libguisan/include/guisan/widgets/scrollarea.hpp +++ b/external/libguisan/include/guisan/widgets/scrollarea.hpp @@ -57,432 +57,430 @@ #ifndef GCN_SCROLLAREA_HPP #define GCN_SCROLLAREA_HPP -#include - #include "guisan/basiccontainer.hpp" #include "guisan/mouselistener.hpp" #include "guisan/platform.hpp" 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. - */ - void setContent(Widget* widget); - - /** - * Gets the content. - * - * @return the content of the ScrollArea. - */ - Widget* getContent(); - - /** - * Sets the horizontal scrollbar policy. See enum with policies. - * - * @param hPolicy the policy for the horizontal scrollbar. See enum with - * policies. - */ - 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. - */ - unsigned int getHorizontalScrollPolicy() const; - - /** - * Sets the vertical scrollbar policy. See enum with policies. - * - * @param vPolicy the policy for the vertical scrollbar. See enum with - * policies. - */ - 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. - */ - unsigned int getVerticalScrollPolicy() const; - - /** - * 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. - */ - void setScrollPolicy(unsigned int hPolicy, unsigned int vPolicy); - - /** - * Sets the amount to scroll vertically. - * - * @param vScroll the amount to scroll. - */ - void setVerticalScrollAmount(int vScroll); - - /** - * Gets the amount that is scrolled vertically. - * @return the scroll amount on vertical scroll. - */ - int getVerticalScrollAmount() const; - - /** - * Sets the amount to scroll horizontally. - * - * @param hScroll the amount to scroll. - */ - void setHorizontalScrollAmount(int hScroll); - - /** - * Gets the amount that is scrolled horizontally. - * - * @return the scroll amount on horizontal scroll. - */ - int getHorizontalScrollAmount() const; - - /** - * Sets the amount to scroll horizontally and vertically. - * - * @param hScroll the amount to scroll on horizontal scroll. - * @param vScroll the amount to scroll on vertical scroll. - */ - void setScrollAmount(int hScroll, int vScroll); - - /** - * Gets the maximum amount of horizontal scroll. - * - * @return the horizontal max scroll. - */ - int getHorizontalMaxScroll(); - - /** - * Gets the maximum amount of vertical scroll. - * - * @return the vertical max scroll. - */ - int getVerticalMaxScroll(); - - /** - * Sets the width. - * - * @param width the width of the ScrollBar. - */ - void setScrollbarWidth(int width); - - /** - * Gets the width. - - * @return the width of the ScrollBar. - */ - int getScrollbarWidth() const; - - /** - * Sets the amount to scroll in pixels when the left scroll button is - * pushed. - */ - void setLeftButtonScrollAmount(int amount); - - /** - * Sets the amount to scroll in pixels when the right scroll button is - * pushed. - */ - void setRightButtonScrollAmount(int amount); - - /** - * Sets the amount to scroll in pixels when the up scroll button is - * pushed. - */ - void setUpButtonScrollAmount(int amount); - - /** - * Sets the amount to scroll in pixels when the down scroll button is - * pushed. - */ - void setDownButtonScrollAmount(int amount); - - /** - * Gets the amount to scroll in pixels when the left scroll button is - * pushed. - * - * @return the amount to scroll when the left scroll button is pushed. - */ - int getLeftButtonScrollAmount() const; - - /** - * Gets the amount to scroll in pixels when the right scroll button is - * pushed. - * - * @return the amount to scroll when the right scroll button is pushed. - */ - int getRightButtonScrollAmount() const; - - /** - * Gets the amount to scroll in pixels when the up scroll button is - * pushed. - * - * @return the amount to scroll when the up scroll button is pushed. - */ - int getUpButtonScrollAmount() const; - - /** - * Gets the amount to scroll in pixels when the down scroll button is - * pushed. - * - * @return the amount to scroll when the down scroll button is pushed. - */ - int getDownButtonScrollAmount() const; - - - // Inherited from BasicContainer - - virtual void showWidgetPart(Widget* widget, Rectangle area); - - virtual Rectangle getChildrenArea(); - - virtual Widget *getWidgetAt(int x, int y); - - - // Inherited from Widget - - virtual void draw(Graphics *graphics); - - virtual void drawBorder(Graphics* graphics); - - virtual void logic(); - - void setWidth(int width); - - void setHeight(int height); - - void setDimension(const Rectangle& dimension); - - - // Inherited from MouseListener - - virtual void mousePressed(MouseEvent& mouseEvent); - - virtual void mouseReleased(MouseEvent& mouseEvent); - - virtual void mouseDragged(MouseEvent& mouseEvent); - - virtual void mouseWheelMovedUp(MouseEvent& mouseEvent); - - virtual void mouseWheelMovedDown(MouseEvent& mouseEvent); - - - /** - * 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 background of the ScrollArea - * (the area behind the content). - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawBackground(Graphics *graphics); - - /** - * Draws the up button. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawUpButton(Graphics *graphics); - - /** - * Draws the down button. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawDownButton(Graphics *graphics); - - /** - * Draws the left button. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawLeftButton(Graphics *graphics); - - /** - * Draws the right button. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawRightButton(Graphics *graphics); - - /** - * Draws the vertical 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. - */ - Rectangle getUpButtonDimension(); - - /** - * Gets the down button dimension. - * - * @return the dimension of the down button. - */ - Rectangle getDownButtonDimension(); - - /** - * Gets the left button dimension. - * - * @return the dimension of the left button. - */ - Rectangle getLeftButtonDimension(); - - /** - * Gets the right button dimension. - * - * @return the dimension of the right button. - */ - Rectangle getRightButtonDimension(); - - /** - * Gets the vertical scrollbar dimension. - * - * @return the dimension of the vertical scrollbar. - */ - Rectangle getVerticalBarDimension(); - - /** - * Gets the horizontal scrollbar dimension. - * - * @return the dimension of the horizontal scrollbar. - */ - Rectangle getHorizontalBarDimension(); - - /** - * Gets the vertical marker dimension. - * - * @return the dimension of the vertical marker. - */ - Rectangle getVerticalMarkerDimension(); - - /** - * Gets the horizontal marker dimension. - * - * @return the dimension of the horizontal marker. - */ - Rectangle getHorizontalMarkerDimension(); - - int mVScroll; - int mHScroll; - int mScrollbarWidth; - unsigned int mHPolicy; - unsigned int mVPolicy; - bool mVBarVisible{}; - bool mHBarVisible{}; - bool mUpButtonPressed; - bool mDownButtonPressed; - bool mLeftButtonPressed; - bool mRightButtonPressed; - int mUpButtonScrollAmount; - int mDownButtonScrollAmount; - int mLeftButtonScrollAmount; - int mRightButtonScrollAmount; - bool mIsVerticalMarkerDragged; - bool mIsHorizontalMarkerDragged; - int mHorizontalMarkerDragOffset{}; - int mVerticalMarkerDragOffset{}; - }; + /** + * 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. + */ + void setContent(Widget* widget); + + /** + * Gets the content. + * + * @return the content of the ScrollArea. + */ + Widget* getContent(); + + /** + * Sets the horizontal scrollbar policy. See enum with policies. + * + * @param hPolicy the policy for the horizontal scrollbar. See enum with + * policies. + */ + 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. + */ + [[nodiscard]] unsigned int getHorizontalScrollPolicy() const; + + /** + * Sets the vertical scrollbar policy. See enum with policies. + * + * @param vPolicy the policy for the vertical scrollbar. See enum with + * policies. + */ + 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. + */ + [[nodiscard]] unsigned int getVerticalScrollPolicy() const; + + /** + * 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. + */ + void setScrollPolicy(unsigned int hPolicy, unsigned int vPolicy); + + /** + * Sets the amount to scroll vertically. + * + * @param vScroll the amount to scroll. + */ + void setVerticalScrollAmount(int vScroll); + + /** + * Gets the amount that is scrolled vertically. + * @return the scroll amount on vertical scroll. + */ + [[nodiscard]] int getVerticalScrollAmount() const; + + /** + * Sets the amount to scroll horizontally. + * + * @param hScroll the amount to scroll. + */ + void setHorizontalScrollAmount(int hScroll); + + /** + * Gets the amount that is scrolled horizontally. + * + * @return the scroll amount on horizontal scroll. + */ + [[nodiscard]] int getHorizontalScrollAmount() const; + + /** + * Sets the amount to scroll horizontally and vertically. + * + * @param hScroll the amount to scroll on horizontal scroll. + * @param vScroll the amount to scroll on vertical scroll. + */ + void setScrollAmount(int hScroll, int vScroll); + + /** + * Gets the maximum amount of horizontal scroll. + * + * @return the horizontal max scroll. + */ + int getHorizontalMaxScroll(); + + /** + * Gets the maximum amount of vertical scroll. + * + * @return the vertical max scroll. + */ + int getVerticalMaxScroll(); + + /** + * Sets the width. + * + * @param width the width of the ScrollBar. + */ + void setScrollbarWidth(int width); + + /** + * Gets the width. + + * @return the width of the ScrollBar. + */ + [[nodiscard]] int getScrollbarWidth() const; + + /** + * Sets the amount to scroll in pixels when the left scroll button is + * pushed. + */ + void setLeftButtonScrollAmount(int amount); + + /** + * Sets the amount to scroll in pixels when the right scroll button is + * pushed. + */ + void setRightButtonScrollAmount(int amount); + + /** + * Sets the amount to scroll in pixels when the up scroll button is + * pushed. + */ + void setUpButtonScrollAmount(int amount); + + /** + * Sets the amount to scroll in pixels when the down scroll button is + * pushed. + */ + void setDownButtonScrollAmount(int amount); + + /** + * Gets the amount to scroll in pixels when the left scroll button is + * pushed. + * + * @return the amount to scroll when the left scroll button is pushed. + */ + [[nodiscard]] int getLeftButtonScrollAmount() const; + + /** + * Gets the amount to scroll in pixels when the right scroll button is + * pushed. + * + * @return the amount to scroll when the right scroll button is pushed. + */ + [[nodiscard]] int getRightButtonScrollAmount() const; + + /** + * Gets the amount to scroll in pixels when the up scroll button is + * pushed. + * + * @return the amount to scroll when the up scroll button is pushed. + */ + [[nodiscard]] int getUpButtonScrollAmount() const; + + /** + * Gets the amount to scroll in pixels when the down scroll button is + * pushed. + * + * @return the amount to scroll when the down scroll button is pushed. + */ + [[nodiscard]] int getDownButtonScrollAmount() const; + + + // Inherited from BasicContainer + + void showWidgetPart(Widget* widget, Rectangle area) override; + + Rectangle getChildrenArea() override; + + Widget* getWidgetAt(int x, int y) override; + + + // Inherited from Widget + + void draw(Graphics* graphics) override; + + void drawBorder(Graphics* graphics) override; + + void logic() override; + + void setWidth(int width) override; + + void setHeight(int height) override; + + void setDimension(const Rectangle& dimension) override; + + + // Inherited from MouseListener + + void mousePressed(MouseEvent& mouseEvent) override; + + void mouseReleased(MouseEvent& mouseEvent) override; + + void mouseDragged(MouseEvent& mouseEvent) override; + + void mouseWheelMovedUp(MouseEvent& mouseEvent) override; + + void mouseWheelMovedDown(MouseEvent& mouseEvent) override; + + + /** + * Scroll policies 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 what. + * 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 background of the ScrollArea + * (the area behind the content). + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawBackground(Graphics* graphics); + + /** + * Draws the up button. + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawUpButton(Graphics* graphics); + + /** + * Draws the down button. + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawDownButton(Graphics* graphics); + + /** + * Draws the left button. + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawLeftButton(Graphics* graphics); + + /** + * Draws the right button. + * + * @param graphics a Graphics object to draw with. + */ + virtual void drawRightButton(Graphics* graphics); + + /** + * Draws the vertical 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. + */ + Rectangle getUpButtonDimension(); + + /** + * Gets the down button dimension. + * + * @return the dimension of the down button. + */ + Rectangle getDownButtonDimension(); + + /** + * Gets the left button dimension. + * + * @return the dimension of the left button. + */ + Rectangle getLeftButtonDimension(); + + /** + * Gets the right button dimension. + * + * @return the dimension of the right button. + */ + Rectangle getRightButtonDimension(); + + /** + * Gets the vertical scrollbar dimension. + * + * @return the dimension of the vertical scrollbar. + */ + Rectangle getVerticalBarDimension(); + + /** + * Gets the horizontal scrollbar dimension. + * + * @return the dimension of the horizontal scrollbar. + */ + Rectangle getHorizontalBarDimension(); + + /** + * Gets the vertical marker dimension. + * + * @return the dimension of the vertical marker. + */ + Rectangle getVerticalMarkerDimension(); + + /** + * Gets the horizontal marker dimension. + * + * @return the dimension of the horizontal marker. + */ + Rectangle getHorizontalMarkerDimension(); + + int mVScroll; + int mHScroll; + int mScrollbarWidth; + unsigned int mHPolicy; + unsigned int mVPolicy; + bool mVBarVisible{}; + bool mHBarVisible{}; + bool mUpButtonPressed; + bool mDownButtonPressed; + bool mLeftButtonPressed; + bool mRightButtonPressed; + int mUpButtonScrollAmount; + int mDownButtonScrollAmount; + int mLeftButtonScrollAmount; + int mRightButtonScrollAmount; + bool mIsVerticalMarkerDragged; + bool mIsHorizontalMarkerDragged; + int mHorizontalMarkerDragOffset{}; + int mVerticalMarkerDragOffset{}; + }; } #endif // end GCN_SCROLLAREA_HPP diff --git a/external/libguisan/include/guisan/widgets/slider.hpp b/external/libguisan/include/guisan/widgets/slider.hpp index bc201052..02a817a5 100644 --- a/external/libguisan/include/guisan/widgets/slider.hpp +++ b/external/libguisan/include/guisan/widgets/slider.hpp @@ -64,204 +64,205 @@ namespace gcn { - /** - * A slider able to slide between different values. You can set the scale - * of the slider yourself so that it ranges between, for example, -1.0 and - * 2.0. - */ - class GCN_CORE_DECLSPEC Slider : - public Widget, - public MouseListener, - public KeyListener - { - public: + /** + * A slider able to slide between different values. You can set the scale + * of the slider yourself so that it ranges between, for example, -1.0 and + * 2.0. + */ + class GCN_CORE_DECLSPEC Slider : + public Widget, + public MouseListener, + public KeyListener + { + public: - /** - * Constructor. Scale start is 0. - * - * @param scaleEnd the end of the slider scale. - */ - Slider(double scaleEnd = 1.0); + /** + * Constructor. Scale start is 0. + * + * @param scaleEnd the end of the slider scale. + */ + Slider(double scaleEnd = 1.0); - /** - * Constructor. - * - * @param scaleStart the start of the scale. - * @param scaleEnd the end of the scale. - */ - Slider(double scaleStart, double scaleEnd); + /** + * Constructor. + * + * @param scaleStart the start of the scale. + * @param scaleEnd the end of the scale. + */ + Slider(double scaleStart, double scaleEnd); - /** - * Destructor. - */ - virtual ~Slider() { } + /** + * Destructor. + */ + virtual ~Slider() + = default; - /** - * Sets the scale. - * - * @param scaleStart the start of the scale. - * @param scaleEnd the end of the scale. - */ - void setScale(double scaleStart, double scaleEnd); + /** + * Sets the scale. + * + * @param scaleStart the start of the scale. + * @param scaleEnd the end of the scale. + */ + void setScale(double scaleStart, double scaleEnd); - /** - * Gets the scale start. - * - * @return the scale start. - */ - double getScaleStart() const; + /** + * Gets the scale start. + * + * @return the scale start. + */ + [[nodiscard]] double getScaleStart() const; - /** - * Sets the scale start. - * - * @param scaleStart the start of the scale. - */ - void setScaleStart(double scaleStart); + /** + * Sets the scale start. + * + * @param scaleStart the start of the scale. + */ + void setScaleStart(double scaleStart); - /** - * Gets the scale end. - * - * @return the scale end. - */ - double getScaleEnd() const; + /** + * Gets the scale end. + * + * @return the scale end. + */ + [[nodiscard]] double getScaleEnd() const; - /** - * Sets the scale end. - * - * @param scaleEnd the end of the scale. - */ - void setScaleEnd(double scaleEnd); + /** + * Sets the scale end. + * + * @param scaleEnd the end of the scale. + */ + void setScaleEnd(double scaleEnd); - /** - * Gets the current value. - * - * @return the current value. - */ - double getValue() const; + /** + * Gets the current value. + * + * @return the current value. + */ + [[nodiscard]] double getValue() const; - /** - * Sets the current value. - * - * @param value a scale value. - */ - void setValue(double value); + /** + * Sets the current value. + * + * @param value a scale value. + */ + void setValue(double value); - /** - * Draws the marker. - * - * @param graphics a graphics object to draw with. - */ - virtual void drawMarker(gcn::Graphics* graphics); + /** + * Draws the marker. + * + * @param graphics a graphics object to draw with. + */ + virtual void drawMarker(Graphics* graphics); - /** - * Sets the length of the marker. - * - * @param length new length for the marker. - */ - void setMarkerLength(int length); + /** + * Sets the length of the marker. + * + * @param length new length for the marker. + */ + void setMarkerLength(int length); - /** - * Gets the length of the marker. - * - * @return the length of the marker. - */ - int getMarkerLength() const; + /** + * Gets the length of the marker. + * + * @return the length of the marker. + */ + [[nodiscard]] int getMarkerLength() const; - /** - * Sets the orientation of the slider. A slider can be drawn verticaly - * or horizontaly. For orientation, see the enum in this class. - * - * @param orientation the orientation. - */ - void setOrientation(unsigned int orientation); + /** + * Sets the orientation of the slider. A slider can be drawn verticaly + * or horizontaly. For orientation, see the enum in this class. + * + * @param orientation the orientation. + */ + void setOrientation(unsigned int orientation); - /** - * Gets the orientation of the slider. Se the enum in this class. - * - * @return the orientation of the slider. - */ - unsigned int getOrientation() const; + /** + * Gets the orientation of the slider. Se the enum in this class. + * + * @return the orientation of the slider. + */ + [[nodiscard]] unsigned int getOrientation() const; - /** - * Sets the step length. Step length is used when the keys left and - * right are pressed. - * - * @param length the step length. - */ - void setStepLength(double length); + /** + * Sets the step length. Step length is used when the keys left and + * right are pressed. + * + * @param length the step length. + */ + void setStepLength(double length); - /** - * Gets the step length. - * - * @return the step length. - */ - double getStepLength() const; + /** + * Gets the step length. + * + * @return the step length. + */ + [[nodiscard]] double getStepLength() const; - // Inherited from Widget + // Inherited from Widget - virtual void draw(gcn::Graphics* graphics); + void draw(Graphics* graphics) override; - virtual void drawBorder(gcn::Graphics* graphics); + void drawBorder(Graphics* graphics) override; - // Inherited from MouseListener. + // Inherited from MouseListener. - virtual void mousePressed(MouseEvent& mouseEvent); + void mousePressed(MouseEvent& mouseEvent) override; - virtual void mouseDragged(MouseEvent& mouseEvent); + void mouseDragged(MouseEvent& mouseEvent) override; - virtual void mouseWheelMovedUp(MouseEvent& mouseEvent); + void mouseWheelMovedUp(MouseEvent& mouseEvent) override; - virtual void mouseWheelMovedDown(MouseEvent& mouseEvent); + void mouseWheelMovedDown(MouseEvent& mouseEvent) override; - // Inherited from KeyListener + // Inherited from KeyListener - virtual void keyPressed(KeyEvent& keyEvent); + void keyPressed(KeyEvent& keyEvent) override; - /** - * Draw orientations for the slider. It can be drawn verticaly or - * horizontaly. - */ - enum - { - HORIZONTAL = 0, - VERTICAL - }; + /** + * Draw orientations for the slider. It can be drawn vertically or + * horizontally. + */ + enum + { + HORIZONTAL = 0, + VERTICAL + }; - protected: - /** - * Converts a marker position to a value. - * - * @param v the position to convert. - * @return the value corresponding to the position. - */ - virtual double markerPositionToValue(int v) const; + protected: + /** + * Converts a marker position to a value. + * + * @param v the position to convert. + * @return the value corresponding to the position. + */ + [[nodiscard]] virtual double markerPositionToValue(int v) const; - /** - * Converts a value to a marker position. - * - * @param value the value to convert. - * @return the position corresponding to the value. - */ - virtual int valueToMarkerPosition(double value) const; + /** + * Converts a value to a marker position. + * + * @param value the value to convert. + * @return the position corresponding to the value. + */ + [[nodiscard]] virtual int valueToMarkerPosition(double value) const; - /** - * Gets the marker position for the current value. - * - * @return the marker position for the current value. - */ - virtual int getMarkerPosition() const; + /** + * Gets the marker position for the current value. + * + * @return the marker position for the current value. + */ + [[nodiscard]] virtual int getMarkerPosition() const; - bool mMouseDrag; - double mValue{}; - double mStepLength{}; - int mMarkerLength{}; - double mScaleStart; - double mScaleEnd; - unsigned int mOrientation{}; - }; + bool mMouseDrag; + double mValue{}; + double mStepLength{}; + int mMarkerLength{}; + double mScaleStart; + double mScaleEnd; + unsigned int mOrientation{}; + }; } #endif // end GCN_SLIDER_HPP diff --git a/external/libguisan/include/guisan/widgets/tab.hpp b/external/libguisan/include/guisan/widgets/tab.hpp index f3908938..b20f4712 100644 --- a/external/libguisan/include/guisan/widgets/tab.hpp +++ b/external/libguisan/include/guisan/widgets/tab.hpp @@ -66,81 +66,81 @@ namespace gcn { - class Label; - class TabbedArea; - - /** - * A simple tab widget used as the default tab in the TabbedArea widget. - */ - class GCN_CORE_DECLSPEC Tab: - public BasicContainer, - public MouseListener - { - public: + class Label; + class TabbedArea; - /** - * Constructor. - */ - Tab(); + /** + * A simple tab widget used as the default tab in the TabbedArea widget. + */ + class GCN_CORE_DECLSPEC Tab : + public BasicContainer, + public MouseListener + { + public: - /** - * Destructor. - */ - virtual ~Tab(); + /** + * Constructor. + */ + Tab(); - /** - * Adjusts the tab size to fit the label. - */ - void adjustSize(); + /** + * Destructor. + */ + virtual ~Tab(); - /** - * Sets the tabbed area the tab should be a part of. - * - * @param tabbedArea The tabbed area the tab should be a part of. - */ - void setTabbedArea(TabbedArea* tabbedArea); + /** + * Adjusts the tab size to fit the label. + */ + void adjustSize(); - /** - * Gets the tabbed are the tab is a part of. - * - * @return The tabbed are the tab is a part of. - */ - TabbedArea* getTabbedArea(); + /** + * Sets the tabbed area the tab should be a part of. + * + * @param tabbedArea The tabbed area the tab should be a part of. + */ + void setTabbedArea(TabbedArea* tabbedArea); - /** - * Sets the caption of the tab. - * - * @param caption The caption of the tab. - */ - void setCaption(const std::string& caption); + /** + * Gets the tabbed are the tab is a part of. + * + * @return The tabbed are the tab is a part of. + */ + [[nodiscard]] TabbedArea* getTabbedArea() const; - /** - * Gets the caption of the tab. - * - * @return The caption of the tab. - */ - const std::string& getCaption() const; + /** + * Sets the caption of the tab. + * + * @param caption The caption of the tab. + */ + void setCaption(const std::string& caption); - - // Inherited from Widget + /** + * Gets the caption of the tab. + * + * @return The caption of the tab. + */ + [[nodiscard]] const std::string& getCaption() const; - virtual void draw(Graphics *graphics); - virtual void drawBorder(Graphics* graphics); - + // Inherited from Widget - // Inherited from MouseListener + void draw(Graphics* graphics) override; - virtual void mouseEntered(MouseEvent& mouseEvent); + void drawBorder(Graphics* graphics) override; - virtual void mouseExited(MouseEvent& mouseEvent); - - protected: - Label* mLabel; - TabbedArea* mTabbedArea{}; - std::string mCaption; - bool mHasMouse; - }; + + // Inherited from MouseListener + + void mouseEntered(MouseEvent& mouseEvent) override; + + void mouseExited(MouseEvent& mouseEvent) override; + + protected: + Label* mLabel; + TabbedArea* mTabbedArea{}; + std::string mCaption; + bool mHasMouse; + }; } #endif // end GCN_TABBEDAREA_HPP diff --git a/external/libguisan/include/guisan/widgets/tabbedarea.hpp b/external/libguisan/include/guisan/widgets/tabbedarea.hpp index d85498ed..30610157 100644 --- a/external/libguisan/include/guisan/widgets/tabbedarea.hpp +++ b/external/libguisan/include/guisan/widgets/tabbedarea.hpp @@ -69,158 +69,157 @@ namespace gcn { - class Container; - class Tab; - - /** - * With the tabbed area widget several widgets can share the same - * space. The widget to view is selected by the user by using tabs. - */ - class GCN_CORE_DECLSPEC TabbedArea: - public ActionListener, - public BasicContainer, - public KeyListener, - public MouseListener - { - public: + class Container; + class Tab; - /** - * Constructor. - */ - TabbedArea(); + /** + * With the tabbed area widget several widgets can share the same + * space. The widget to view is selected by the user by using tabs. + */ + class GCN_CORE_DECLSPEC TabbedArea : + public ActionListener, + public BasicContainer, + public KeyListener, + public MouseListener + { + public: - /** - * Destructor. - */ - virtual ~TabbedArea(); + /** + * Constructor. + */ + TabbedArea(); - /** - * Adds a tab to the tabbed area. - * - * @param caption The caption of the tab. - * @param widget The widget to view when the tab is selected. - */ - virtual void addTab(const std::string& caption, Widget* widget); + /** + * Destructor. + */ + virtual ~TabbedArea(); - /** - * Adds a tab to the tabbed area. - * - * @param tab The tab widget for the tab. - * @param widget The widget to view when the tab is selected. - */ - virtual void addTab(Tab* tab, Widget* widget); + /** + * Adds a tab to the tabbed area. + * + * @param caption The caption of the tab. + * @param widget The widget to view when the tab is selected. + */ + virtual void addTab(const std::string& caption, Widget* widget); - /** - * Removes a tab from the tabbed area. - * - * @param index The index of the tab to remove. - */ - virtual void removeTabWithIndex(unsigned int index); - - /** - * Removes a tab from the tabbed area. - * - * @param index The tab to remove. - */ - virtual void removeTab(Tab* tab); + /** + * Adds a tab to the tabbed area. + * + * @param tab The tab widget for the tab. + * @param widget The widget to view when the tab is selected. + */ + virtual void addTab(Tab* tab, Widget* widget); - /** - * Checks whether a tab given an index is selected. - * - * @param index The index of the tab to check. - * @return True if the tab is selected, false otherwise. - */ - virtual bool isTabSelected(unsigned int index) const; - - /** - * Checks whether a tab is selected or not. - * - * @param index The tab to check. - * @return True if the tab is selected, false otherwise. - */ - virtual bool isTabSelected(Tab* tab); + /** + * Removes a tab from the tabbed area. + * + * @param index The index of the tab to remove. + */ + virtual void removeTabWithIndex(unsigned int index); - /** - * Sets a tab given an index to be selected. - * - * @param index The index of the tab to be selected. - */ - virtual void setSelectedTabWithIndex(unsigned int index); + /** + * Removes a tab from the tabbed area. + * + * @param tab The tab to remove. + */ + virtual void removeTab(Tab* tab); - /** - * Sets a tab to be selected or not. - * - * @param index The tab to be selected. - */ - virtual void setSelectedTab(Tab* tab); + /** + * Checks whether a tab given an index is selected. + * + * @param index The index of the tab to check. + * @return True if the tab is selected, false otherwise. + */ + virtual auto isTabSelected(unsigned int index) const -> bool; - /** - * Gets the index of the selected tab. - * - * @return The undex of the selected tab. - * If no tab is selected -1 will be returned. - */ - virtual int getSelectedTabIndex() const; - - /** - * Gets the selected tab. - * - * @return The selected tab. - */ - Tab* getSelectedTab(); + /** + * Checks whether a tab is selected or not. + * + * @param tab The tab to check. + * @return True if the tab is selected, false otherwise. + */ + virtual bool isTabSelected(Tab* tab); + + /** + * Sets a tab given an index to be selected. + * + * @param index The index of the tab to be selected. + */ + virtual void setSelectedTabWithIndex(unsigned int index); + + /** + * Sets a tab to be selected or not. + * + * @param tab The tab to be selected. + */ + virtual void setSelectedTab(Tab* tab); + + /** + * Gets the index of the selected tab. + * + * @return The index of the selected tab. + * If no tab is selected -1 will be returned. + */ + [[nodiscard]] virtual int getSelectedTabIndex() const; + + /** + * Gets the selected tab. + * + * @return The selected tab. + */ + Tab* getSelectedTab(); - // Inherited from Widget + // Inherited from Widget - virtual void draw(Graphics *graphics); + void draw(Graphics* graphics) override; - virtual void drawBorder(Graphics* graphics); + void drawBorder(Graphics* graphics) override; - virtual void logic(); + void logic() override; - void setWidth(int width); + void setWidth(int width) override; - void setHeight(int height); + void setHeight(int height) override; - void setSize(int width, int height); + void setSize(int width, int height) override; - void setDimension(const Rectangle& dimension); - - - // Inherited from ActionListener - - void action(const ActionEvent& actionEvent); - - - // Inherited from DeathListener - - virtual void death(const Event& event); + void setDimension(const Rectangle& dimension) override; - // Inherited from KeyListener + // Inherited from ActionListener - virtual void keyPressed(KeyEvent& keyEvent); + void action(const ActionEvent& actionEvent) override; - // Inherited from MouseListener - - virtual void mousePressed(MouseEvent& mouseEvent); + // Inherited from DeathListener - - protected: - /** - * Adjusts the size of the tabbed area. - */ - void adjustSize(); - void adjustTabPositions(); - - Tab* mSelectedTab; - Container* mTabContainer; - Container* mWidgetContainer; - std::vector mTabsToCleanUp; - std::vector > mTabs; - - }; + void death(const Event& event) override; + + + // Inherited from KeyListener + + void keyPressed(KeyEvent& keyEvent) override; + + + // Inherited from MouseListener + + void mousePressed(MouseEvent& mouseEvent) override; + + + protected: + /** + * Adjusts the size of the tabbed area. + */ + void adjustSize(); + void adjustTabPositions(); + + Tab* mSelectedTab; + Container* mTabContainer; + Container* mWidgetContainer; + std::vector mTabsToCleanUp; + std::vector> mTabs; + }; } #endif // end GCN_TABBEDAREA_HPP diff --git a/external/libguisan/include/guisan/widgets/textbox.hpp b/external/libguisan/include/guisan/widgets/textbox.hpp index 5a4b5bfc..4c62ac94 100644 --- a/external/libguisan/include/guisan/widgets/textbox.hpp +++ b/external/libguisan/include/guisan/widgets/textbox.hpp @@ -68,197 +68,197 @@ 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(); + /** + * 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); + /** + * Constructor. + * + * @param text the text of the TextBox. + */ + TextBox(const std::string& text); - /** - * Sets the text. - * - * @param text the text of the TextBox. - */ - void setText(const std::string& text); + /** + * Sets the text. + * + * @param text the text of the TextBox. + */ + void setText(const std::string& text); - /** - * Gets the text. - * @return the text of the TextBox. - */ - std::string getText() const; + /** + * Gets the text. + * @return the text of the TextBox. + */ + [[nodiscard]] std::string getText() const; - /** - * Gets the row of a text. - * - * @return the text of a certain row in the TextBox. - */ - const std::string& getTextRow(int row) const; + /** + * Gets the row of a text. + * + * @return the text of a certain row in the TextBox. + */ + [[nodiscard]] 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. - */ - void setTextRow(int row, const std::string& text); + /** + * 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. + */ + void setTextRow(int row, const std::string& text); - /** - * Gets the number of rows in the text. - * - * @return the number of rows in the text. - */ - unsigned int getNumberOfRows() const; + /** + * Gets the number of rows in the text. + * + * @return the number of rows in the text. + */ + [[nodiscard]] unsigned int getNumberOfRows() const; - /** - * Gets the caret position in the text. - * - * @return the caret position in the text. - */ - unsigned int getCaretPosition() const; + /** + * Gets the caret position in the text. + * + * @return the caret position in the text. + */ + [[nodiscard]] unsigned int getCaretPosition() const; - /** - * Sets the position of the caret in the text. - * - * @param position the positon of the caret. - */ - void setCaretPosition(unsigned int position); + /** + * Sets the position of the caret in the text. + * + * @param position the position of the caret. + */ + 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. - */ - unsigned int getCaretRow() const; + /** + * Gets the row the caret is in in the text. + * + * @return the row the caret is in in the text. + */ + [[nodiscard]] unsigned int getCaretRow() const; - /** - * Sets the row the caret should be in in the text. - * - * @param row the row number. - */ - void setCaretRow(int row); + /** + * Sets the row the caret should be in in the text. + * + * @param row the row number. + */ + void setCaretRow(int row); - /** - * Gets the column the caret is in in the text. - * - * @return the column the caret is in in the text. - */ - unsigned int getCaretColumn() const; + /** + * Gets the column the caret is in in the text. + * + * @return the column the caret is in in the text. + */ + [[nodiscard]] unsigned int getCaretColumn() const; - /** - * Sets the column the caret should be in in the text. - * - * @param column the column number. - */ - void setCaretColumn(int column); + /** + * Sets the column the caret should be in in the text. + * + * @param column the column number. + */ + 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. - */ - void setCaretRowColumn(int row, 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. + */ + void setCaretRowColumn(int row, int column); - /** - * Scrolls the text to the caret if the TextBox is in a ScrollArea. - */ - virtual void scrollToCaret(); + /** + * 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. - */ - bool isEditable() const; + /** + * Checks if the TextBox is editable. + * + * @return true it the TextBox is editable. + */ + [[nodiscard]] bool isEditable() const; - /** - * Sets if the TextBox should be editable or not. - * - * @param editable true if the TextBox should be editable. - */ - void setEditable(bool editable); + /** + * Sets if the TextBox should be editable or not. + * + * @param editable true if the TextBox should be editable. + */ + void setEditable(bool editable); - /** - * Adds a text row to the text. - * - * @param row a row. - */ - virtual void addRow(const std::string row); + /** + * Adds a text row to the text. + * + * @param row a row. + */ + virtual void addRow(std::string row); - /** - * Checks if the TextBox is opaque - * - * @return true if the TextBox is opaque - */ - bool isOpaque(); + /** + * Checks if the TextBox is opaque + * + * @return true if the TextBox is opaque + */ + [[nodiscard]] bool isOpaque() const; - /** - * Sets the TextBox to be opaque. - * - * @param opaque true if the TextBox should be opaque. - */ - void setOpaque(bool opaque); + /** + * Sets the TextBox to be opaque. + * + * @param opaque true if the TextBox should be opaque. + */ + void setOpaque(bool opaque); - // Inherited from Widget + // Inherited from Widget - virtual void draw(Graphics* graphics); + void draw(Graphics* graphics) override; - virtual void drawBorder(Graphics* graphics); + void drawBorder(Graphics* graphics) override; - virtual void fontChanged(); + void fontChanged() override; - // Inherited from KeyListener + // Inherited from KeyListener - virtual void keyPressed(KeyEvent& keyEvent); + void keyPressed(KeyEvent& keyEvent) override; - // Inherited from MouseListener + // Inherited from MouseListener - virtual void mousePressed(MouseEvent& mouseEvent); + void mousePressed(MouseEvent& mouseEvent) override; - virtual void mouseDragged(MouseEvent& mouseEvent); + void mouseDragged(MouseEvent& mouseEvent) override; - 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); + 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(); + /** + * Adjusts the TextBox size to fit the font size. + */ + virtual void adjustSize(); - std::vector mTextRows; - int mCaretColumn; - int mCaretRow; - bool mEditable; - bool mOpaque; - }; + std::vector mTextRows; + int mCaretColumn; + int mCaretRow; + bool mEditable; + bool mOpaque; + }; } #endif // end GCN_TEXTBOX_HPP diff --git a/external/libguisan/include/guisan/widgets/textfield.hpp b/external/libguisan/include/guisan/widgets/textfield.hpp index b6c1061e..6c6635d2 100644 --- a/external/libguisan/include/guisan/widgets/textfield.hpp +++ b/external/libguisan/include/guisan/widgets/textfield.hpp @@ -66,110 +66,110 @@ 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(); + /** + * 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); + /** + * 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. - */ - void setText(const std::string& text); + /** + * Sets the text. + * + * @param text the new text in the TextField. + */ + void setText(const std::string& text); - /** - * Gets the text. - * - * @return the text of the TextField. - */ - const std::string& getText() const; + /** + * Gets the text. + * + * @return the text of the TextField. + */ + [[nodiscard]] 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); + /** + * 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. - */ - void adjustSize(); + /** + * 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. + */ + 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. - */ - void adjustHeight(); + /** + * 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. + */ + void adjustHeight(); - /** - * Sets the caret position. - * - * @param position the caret position. - */ - void setCaretPosition(unsigned int position); + /** + * Sets the caret position. + * + * @param position the caret position. + */ + void setCaretPosition(unsigned int position); - /** - * Gets the caret position. - * - * @return the caret position. - */ - unsigned int getCaretPosition() const; + /** + * Gets the caret position. + * + * @return the caret position. + */ + [[nodiscard]] unsigned int getCaretPosition() const; - // Inherited from Widget + // Inherited from Widget - virtual void fontChanged(); + void fontChanged() override; - virtual void draw(Graphics* graphics); + void draw(Graphics* graphics) override; - virtual void drawBorder(Graphics* graphics); + void drawBorder(Graphics* graphics) override; - // Inherited from MouseListener + // Inherited from MouseListener - virtual void mousePressed(MouseEvent& mouseEvent); + void mousePressed(MouseEvent& mouseEvent) override; - virtual void mouseDragged(MouseEvent& mouseEvent); - + void mouseDragged(MouseEvent& mouseEvent) override; - // Inherited from KeyListener - virtual void keyPressed(KeyEvent& keyEvent); + // Inherited from KeyListener - protected: - /** - * Scrolls the text horizontally so that the caret shows if needed. - */ - void fixScroll(); + void keyPressed(KeyEvent& keyEvent) override; - std::string mText; - unsigned int mCaretPosition; - int mXScroll; - }; + 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/external/libguisan/include/guisan/widgets/togglebutton.hpp b/external/libguisan/include/guisan/widgets/togglebutton.hpp index 272d97f5..476862bf 100644 --- a/external/libguisan/include/guisan/widgets/togglebutton.hpp +++ b/external/libguisan/include/guisan/widgets/togglebutton.hpp @@ -69,70 +69,70 @@ namespace gcn { - /** - * A toggle button, which can stay selected. Think of it as a checkbox, - * but dressed as a regular button. Add an ActionListener to it to know when it - * has been clicked. - * - */ - class GCN_CORE_DECLSPEC ToggleButton : public Button - { - public: - /** - * Constructor. - */ - ToggleButton(); + /** + * A toggle button, which can stay selected. Think of it as a checkbox, + * but dressed as a regular button. Add an ActionListener to it to know when it + * has been clicked. + * + */ + class GCN_CORE_DECLSPEC ToggleButton : public Button + { + public: + /** + * Constructor. + */ + ToggleButton(); - /** - * Constructor. - * - * @param caption the caption of the ToggleButton. - */ - ToggleButton(const std::string& caption); - - /** - * Checks if the button is selected. - * - * @return True if the button is selected, false otherwise. - * @see setSelected - */ - bool isSelected() const; + /** + * Constructor. + * + * @param caption the caption of the ToggleButton. + */ + ToggleButton(const std::string& caption); - /** - * Sets the button to be selected. - * - * @param selected True if the button should be set as selected. - * @see isSelected - */ - void setSelected(bool selected); + /** + * Checks if the button is selected. + * + * @return True if the button is selected, false otherwise. + * @see setSelected + */ + [[nodiscard]] bool isSelected() const; + + /** + * Sets the button to be selected. + * + * @param selected True if the button should be set as selected. + * @see isSelected + */ + void setSelected(bool selected); - //Inherited from Widget + //Inherited from Widget - virtual void draw(Graphics* graphics); + void draw(Graphics* graphics) override; - // Inherited from MouseListener + // Inherited from MouseListener - virtual void mouseReleased(MouseEvent& mouseEvent); + void mouseReleased(MouseEvent& mouseEvent) override; - // Inherited from KeyListener + // Inherited from KeyListener - virtual void keyReleased(KeyEvent& keyEvent); + void keyReleased(KeyEvent& keyEvent) override; - protected: - /** - * Toggles the button between being selected and - * not being selected. - */ - virtual void toggleSelected(); - - /** - * True if the button is selected, false otherwise. - */ - bool mSelected; - }; + protected: + /** + * Toggles the button between being selected and + * not being selected. + */ + virtual void toggleSelected(); + + /** + * True if the button is selected, false otherwise. + */ + bool mSelected; + }; } #endif // end GCN_TOGGLEBUTTON_HPP diff --git a/external/libguisan/include/guisan/widgets/window.hpp b/external/libguisan/include/guisan/widgets/window.hpp index 02c37f13..be5e901e 100644 --- a/external/libguisan/include/guisan/widgets/window.hpp +++ b/external/libguisan/include/guisan/widgets/window.hpp @@ -65,153 +65,153 @@ namespace gcn { - /** - * A movable window which can contain another Widgets. - */ - class GCN_CORE_DECLSPEC Window : public Container, - public MouseListener - { - public: - /** - * Constructor. - */ - Window(); + /** + * A movable window which can contain another Widgets. + */ + class GCN_CORE_DECLSPEC Window : public Container, + public MouseListener + { + public: + /** + * Constructor. + */ + Window(); - /** - * Constructor. - * - * @param caption the Window caption. - */ - Window(const std::string& caption); + /** + * Constructor. + * + * @param caption the Window caption. + */ + Window(const std::string& caption); - /** - * Destructor. - */ - virtual ~Window(); + /** + * Destructor. + */ + virtual ~Window(); - /** - * Sets the Window caption. - * - * @param caption the Window caption. - */ - void setCaption(const std::string& caption); + /** + * Sets the Window caption. + * + * @param caption the Window caption. + */ + virtual void setCaption(const std::string& caption); - /** - * Gets the Window caption. - * - * @return the Window caption. - */ - const std::string& getCaption() const; + /** + * Gets the Window caption. + * + * @return the Window caption. + */ + [[nodiscard]] virtual const std::string& getCaption() const; - /** - * Sets the alignment for the caption. - * - * @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. - */ - void setAlignment(unsigned int alignment); + /** + * 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. - */ - unsigned int getAlignment() const; + /** + * Gets the alignment for the caption. + * + * @return alignment of caption. + */ + [[nodiscard]] virtual unsigned int getAlignment() const; - /** - * Sets the padding of the window which is the distance between the - * window border and the content. - * - * @param padding the padding value. - */ - void setPadding(unsigned int padding); + /** + * 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. - */ - unsigned int getPadding() const; + /** + * Gets the padding. + * + * @return the padding value. + */ + [[nodiscard]] virtual unsigned int getPadding() const; - /** - * Sets the title bar height. - * - * @param height the title height value. - */ - void setTitleBarHeight(unsigned int height); + /** + * 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. - */ - unsigned int getTitleBarHeight(); + /** + * 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. - */ - void setMovable(bool movable); + /** + * Sets the Window to be moveable. + * + * @param movable true or false. + */ + void setMovable(bool movable); - /** - * Check if the window is movable. - * - * @return true or false. - */ - bool isMovable() const; + /** + * Check if the window is movable. + * + * @return true or false. + */ + [[nodiscard]] virtual bool isMovable() const; - /** - * 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. - */ - void setOpaque(bool opaque); + /** + * 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. + */ + void setOpaque(bool opaque) override; - /** - * Checks if the Window is opaque. - * - * @return true or false. - */ - bool isOpaque(); + /** + * Checks if the Window is opaque. + * + * @return true or false. + */ + virtual bool isOpaque(); - /** - * Resizes the container to fit the content exactly. - */ - virtual void resizeToContent(); + /** + * Resizes the container to fit the content exactly. + */ + virtual void resizeToContent(); - // Inherited from BasicContainer + // Inherited from BasicContainer - virtual Rectangle getChildrenArea(); + Rectangle getChildrenArea() override; - // Inherited from Widget + // Inherited from Widget - virtual void draw(Graphics* graphics); + void draw(Graphics* graphics) override; - virtual void drawBorder(Graphics* graphics); + void drawBorder(Graphics* graphics) override; - // Inherited from MouseListener + // Inherited from MouseListener - virtual void mousePressed(MouseEvent& mouseEvent); + void mousePressed(MouseEvent& mouseEvent) override; - virtual void mouseDragged(MouseEvent& mouseEvent); + void mouseDragged(MouseEvent& mouseEvent) override; - virtual void mouseReleased(MouseEvent& mouseEvent); + void mouseReleased(MouseEvent& mouseEvent) override; - protected: - std::string mCaption; - unsigned int mAlignment{}; - unsigned int mPadding{}; - unsigned int mTitleBarHeight{}; - bool mMovable{}; - bool mOpaque{}; - int mDragOffsetX{}; - int mDragOffsetY{}; - bool mIsMoving; - }; + protected: + std::string mCaption; + unsigned int mAlignment{}; + unsigned int mPadding{}; + unsigned int mTitleBarHeight{}; + bool mMovable{}; + bool mOpaque{}; + int mDragOffsetX{}; + int mDragOffsetY{}; + bool mIsMoving; + }; } #endif // end GCN_WINDOW_HPP diff --git a/external/libguisan/src/widget.cpp b/external/libguisan/src/widget.cpp index 43baca62..afda0ac6 100644 --- a/external/libguisan/src/widget.cpp +++ b/external/libguisan/src/widget.cpp @@ -76,638 +76,620 @@ namespace gcn { - Font* Widget::mGlobalFont = NULL; - DefaultFont Widget::mDefaultFont; - std::list Widget::mWidgets; - - Widget::Widget() - : mForegroundColor(0x000000), - mBackgroundColor(0xffffff), - mBaseColor(0xDDDDE3), - mSelectionColor(0xc3d9ff), - mFocusHandler(NULL), - mInternalFocusHandler(NULL), - mParent(NULL), - mBorderSize(0), - mFocusable(false), - mVisible(true), - mTabIn(true), - mTabOut(true), - mEnabled(true), - mCurrentFont(NULL) - { - mWidgets.push_back(this); - } - - Widget::~Widget() - { - DeathListenerIterator iter; - - for (iter = mDeathListeners.begin(); iter != mDeathListeners.end(); ++iter) - { - Event event(this); - (*iter)->death(event); - } - - _setFocusHandler(NULL); - - mWidgets.remove(this); - } - - void Widget::_setParent(Widget* parent) - { - mParent = parent; - } - - Widget* Widget::getParent() const - { - return mParent; - } - - void Widget::setWidth(int width) - { - Rectangle newDimension = mDimension; - newDimension.width = width; - - setDimension(newDimension); - } - - int Widget::getWidth() const - { - return mDimension.width; - } - - void Widget::setHeight(int height) - { - Rectangle newDimension = mDimension; - newDimension.height = height; - - setDimension(newDimension); - } - - int Widget::getHeight() const - { - return mDimension.height; - } - - void Widget::setX(int x) - { - Rectangle newDimension = mDimension; - newDimension.x = x; - - setDimension(newDimension); - } - - int Widget::getX() const - { - return mDimension.x; - } - - void Widget::setY(int y) - { - Rectangle newDimension = mDimension; - newDimension.y = y; - - setDimension(newDimension); - } - - int Widget::getY() const - { - return mDimension.y; - } - - void Widget::setPosition(int x, int y) - { - Rectangle newDimension = mDimension; - newDimension.x = x; - newDimension.y = y; - - setDimension(newDimension); - } - - void Widget::setDimension(const Rectangle& dimension) - { - Rectangle oldDimension = mDimension; - mDimension = dimension; - - if (mDimension.width != oldDimension.width - || mDimension.height != oldDimension.height) - { - distributeResizedEvent(); - } - - if (mDimension.x != oldDimension.x - || mDimension.y != oldDimension.y) - { - distributeMovedEvent(); - } - } - - void Widget::setBorderSize(unsigned int borderSize) - { - mBorderSize = borderSize; - } - - unsigned int Widget::getBorderSize() const - { - return mBorderSize; - } - - const Rectangle& Widget::getDimension() const - { - return mDimension; - } - - const std::string& Widget::getActionEventId() const - { - return mActionEventId; - } - - void Widget::setActionEventId(const std::string& actionEventId) - { - mActionEventId = actionEventId; - } - - bool Widget::isFocused() const - { - if (!mFocusHandler) - { - return false; - } - - return (mFocusHandler->isFocused(this)); - } - - void Widget::setFocusable(bool focusable) - { - if (!focusable && isFocused()) - { - mFocusHandler->focusNone(); - } - - mFocusable = focusable; - } - - bool Widget::isFocusable() const - { - return mFocusable && isVisible() && isEnabled(); - } - - void Widget::requestFocus() - { - if (mFocusHandler == NULL) - { - throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); - } - - if (isFocusable()) - { - mFocusHandler->requestFocus(this); - } - } - - void Widget::requestMoveToTop() - { - if (mParent) - { - mParent->moveToTop(this); - } - } - - void Widget::requestMoveToBottom() - { - if (mParent) - { - mParent->moveToBottom(this); - } - } - - void Widget::setVisible(bool visible) - { - if (!visible && isFocused()) - { - mFocusHandler->focusNone(); - } - - if (visible) - { - distributeShownEvent(); - } - else if(!visible) - { - distributeHiddenEvent(); - } - - mVisible = visible; - } - - bool Widget::isVisible() const - { - if (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::setSelectionColor(const Color& color) - { - mSelectionColor = color; - } - - const Color& Widget::getSelectionColor() const - { - return mSelectionColor; - } - - void Widget::_setFocusHandler(FocusHandler* focusHandler) - { - if (mFocusHandler) - { - releaseModalFocus(); - mFocusHandler->remove(this); - } - - if (focusHandler) - { - focusHandler->add(this); - } - - mFocusHandler = focusHandler; - } - - FocusHandler* Widget::_getFocusHandler() - { - return mFocusHandler; - } - - void Widget::addActionListener(ActionListener* actionListener) - { - mActionListeners.push_back(actionListener); - } - - void Widget::removeActionListener(ActionListener* actionListener) - { - mActionListeners.remove(actionListener); - } - - void Widget::addDeathListener(DeathListener* deathListener) - { - mDeathListeners.push_back(deathListener); - } - - void Widget::removeDeathListener(DeathListener* deathListener) - { - mDeathListeners.remove(deathListener); - } - - void Widget::addKeyListener(KeyListener* keyListener) - { - mKeyListeners.push_back(keyListener); - } - - void Widget::removeKeyListener(KeyListener* keyListener) - { - mKeyListeners.remove(keyListener); - } - - void Widget::addFocusListener(FocusListener* focusListener) - { - mFocusListeners.push_back(focusListener); - } - - void Widget::removeFocusListener(FocusListener* focusListener) - { - mFocusListeners.remove(focusListener); - } - - void Widget::addMouseListener(MouseListener* mouseListener) - { - mMouseListeners.push_back(mouseListener); - } - - void Widget::removeMouseListener(MouseListener* mouseListener) - { - mMouseListeners.remove(mouseListener); - } - - void Widget::addWidgetListener(WidgetListener* widgetListener) - { - mWidgetListeners.push_back(widgetListener); - } - - void Widget::removeWidgetListener(WidgetListener* widgetListener) - { - mWidgetListeners.remove(widgetListener); - } - - void Widget::getAbsolutePosition(int& x, int& y) const - { - if (getParent() == NULL) - { - x = mDimension.x; - y = mDimension.y; - return; - } - - int parentX; - int parentY; - - getParent()->getAbsolutePosition(parentX, parentY); - - x = parentX + mDimension.x + getParent()->getChildrenArea().x; - y = parentY + mDimension.y + getParent()->getChildrenArea().y; - } - - void Widget::generateAction() - { - ActionListenerIterator iter; - for (iter = mActionListeners.begin(); iter != mActionListeners.end(); ++iter) - { - ActionEvent actionEvent(this, mActionEventId); - (*iter)->action(actionEvent); - } - } - - 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(); - } - - 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) - { - Rectangle newDimension = mDimension; - newDimension.width = width; - newDimension.height = height; - - setDimension(newDimension); - } - - void Widget::setEnabled(bool enabled) - { - mEnabled = enabled; - } - - bool Widget::isEnabled() const - { - return mEnabled && isVisible(); - } - - void Widget::requestModalFocus() - { - if (mFocusHandler == NULL) - { - throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); - } - - mFocusHandler->requestModalFocus(this); - } - - void Widget::requestModalMouseInputFocus() - { - if (mFocusHandler == NULL) - { - throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); - } - - mFocusHandler->requestModalMouseInputFocus(this); - } - - void Widget::releaseModalFocus() - { - if (mFocusHandler == NULL) - { - return; - } - - mFocusHandler->releaseModalFocus(this); - } - - void Widget::releaseModalMouseInputFocus() - { - if (mFocusHandler == NULL) - { - return; - } - - mFocusHandler->releaseModalMouseInputFocus(this); - } - - bool Widget::hasModalFocus() const - { - if (mFocusHandler == NULL) - { - throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); - } - - if (getParent() != NULL) - { - return (mFocusHandler->getModalFocused() == this) || getParent()->hasModalFocus(); - } - - return mFocusHandler->getModalFocused() == this; - } - - bool Widget::hasModalMouseInputFocus() const - { - if (mFocusHandler == NULL) - { - throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); - } - - if (getParent() != NULL) - { - return (mFocusHandler->getModalMouseInputFocused() == this) || getParent()->hasModalMouseInputFocus(); - } - - return mFocusHandler->getModalMouseInputFocused() == this; - } - - Widget *Widget::getWidgetAt(int x, int y) - { - return NULL; - } - - const std::list& Widget::_getMouseListeners() - { - return mMouseListeners; - } - - const std::list& Widget::_getKeyListeners() - { - return mKeyListeners; - } - - const std::list& Widget::_getFocusListeners() - { - return mFocusListeners; - } - - Rectangle Widget::getChildrenArea() - { - return Rectangle(0, 0, 0, 0); - } - - FocusHandler* Widget::_getInternalFocusHandler() - { - return mInternalFocusHandler; - } - - void Widget::setInternalFocusHandler(FocusHandler* focusHandler) - { - mInternalFocusHandler = focusHandler; - } - - void Widget::setId(const std::string& id) - { - mId = id; - } - - const std::string& Widget::getId() - { - return mId; - } - - void Widget::distributeResizedEvent() - { - WidgetListenerIterator iter; - - for (iter = mWidgetListeners.begin(); iter != mWidgetListeners.end(); ++iter) - { - Event event(this); - (*iter)->widgetResized(event); - } - } - - void Widget::distributeMovedEvent() - { - WidgetListenerIterator iter; - - for (iter = mWidgetListeners.begin(); iter != mWidgetListeners.end(); ++iter) - { - Event event(this); - (*iter)->widgetMoved(event); - } - } - - void Widget::distributeHiddenEvent() - { - WidgetListenerIterator iter; - - for (iter = mWidgetListeners.begin(); iter != mWidgetListeners.end(); ++iter) - { - Event event(this); - (*iter)->widgetHidden(event); - } - } - - void Widget::distributeShownEvent() - { - WidgetListenerIterator iter; - - for (iter = mWidgetListeners.begin(); iter != mWidgetListeners.end(); ++iter) - { - Event event(this); - (*iter)->widgetShown(event); - } - } + Font* Widget::mGlobalFont = nullptr; + DefaultFont Widget::mDefaultFont; + std::list Widget::mWidgets; + + Widget::Widget() + : mForegroundColor(0x000000), + mBackgroundColor(0xffffff), + mBaseColor(0xDDDDE3), + mSelectionColor(0xc3d9ff), + mFocusHandler(nullptr), + mInternalFocusHandler(nullptr), + mParent(nullptr), + mBorderSize(0), + mFocusable(false), + mVisible(true), + mTabIn(true), + mTabOut(true), + mEnabled(true), + mCurrentFont(nullptr) + { + mWidgets.push_back(this); + } + + Widget::~Widget() + { + for (auto& mDeathListener : mDeathListeners) + { + Event event(this); + mDeathListener->death(event); + } + + Widget::_setFocusHandler(nullptr); + + mWidgets.remove(this); + } + + void Widget::_setParent(Widget* parent) + { + mParent = parent; + } + + Widget* Widget::getParent() const + { + return mParent; + } + + void Widget::setWidth(int width) + { + auto newDimension = mDimension; + newDimension.width = width; + + setDimension(newDimension); + } + + int Widget::getWidth() const + { + return mDimension.width; + } + + void Widget::setHeight(int height) + { + auto newDimension = mDimension; + newDimension.height = height; + + setDimension(newDimension); + } + + int Widget::getHeight() const + { + return mDimension.height; + } + + void Widget::setX(int x) + { + auto newDimension = mDimension; + newDimension.x = x; + + setDimension(newDimension); + } + + int Widget::getX() const + { + return mDimension.x; + } + + void Widget::setY(int y) + { + auto newDimension = mDimension; + newDimension.y = y; + + setDimension(newDimension); + } + + int Widget::getY() const + { + return mDimension.y; + } + + void Widget::setPosition(int x, int y) + { + auto newDimension = mDimension; + newDimension.x = x; + newDimension.y = y; + + setDimension(newDimension); + } + + void Widget::setDimension(const Rectangle& dimension) + { + const auto oldDimension = mDimension; + mDimension = dimension; + + if (mDimension.width != oldDimension.width + || mDimension.height != oldDimension.height) + { + distributeResizedEvent(); + } + + if (mDimension.x != oldDimension.x + || mDimension.y != oldDimension.y) + { + distributeMovedEvent(); + } + } + + void Widget::setBorderSize(unsigned int borderSize) + { + mBorderSize = borderSize; + } + + unsigned int Widget::getBorderSize() const + { + return mBorderSize; + } + + const Rectangle& Widget::getDimension() const + { + return mDimension; + } + + const std::string& Widget::getActionEventId() const + { + return mActionEventId; + } + + void Widget::setActionEventId(const std::string& actionEventId) + { + mActionEventId = actionEventId; + } + + bool Widget::isFocused() const + { + if (!mFocusHandler) + { + return false; + } + + return mFocusHandler->isFocused(this); + } + + void Widget::setFocusable(bool focusable) + { + if (!focusable && isFocused()) + { + mFocusHandler->focusNone(); + } + + mFocusable = focusable; + } + + bool Widget::isFocusable() const + { + return mFocusable && isVisible() && isEnabled(); + } + + void Widget::requestFocus() + { + if (mFocusHandler == nullptr) + { + throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); + } + + if (isFocusable()) + { + mFocusHandler->requestFocus(this); + } + } + + void Widget::requestMoveToTop() + { + if (mParent) + { + mParent->moveToTop(this); + } + } + + void Widget::requestMoveToBottom() + { + if (mParent) + { + mParent->moveToBottom(this); + } + } + + void Widget::setVisible(bool visible) + { + if (!visible && isFocused()) + { + mFocusHandler->focusNone(); + } + + if (visible) + { + distributeShownEvent(); + } + else if (!visible) + { + distributeHiddenEvent(); + } + + mVisible = visible; + } + + bool Widget::isVisible() const + { + if (getParent() == nullptr) + { + return mVisible; + } + 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::setSelectionColor(const Color& color) + { + mSelectionColor = color; + } + + const Color& Widget::getSelectionColor() const + { + return mSelectionColor; + } + + void Widget::_setFocusHandler(FocusHandler* focusHandler) + { + if (mFocusHandler) + { + releaseModalFocus(); + mFocusHandler->remove(this); + } + + if (focusHandler) + { + focusHandler->add(this); + } + + mFocusHandler = focusHandler; + } + + FocusHandler* Widget::_getFocusHandler() + { + return mFocusHandler; + } + + void Widget::addActionListener(ActionListener* actionListener) + { + mActionListeners.push_back(actionListener); + } + + void Widget::removeActionListener(ActionListener* actionListener) + { + mActionListeners.remove(actionListener); + } + + void Widget::addDeathListener(DeathListener* deathListener) + { + mDeathListeners.push_back(deathListener); + } + + void Widget::removeDeathListener(DeathListener* deathListener) + { + mDeathListeners.remove(deathListener); + } + + void Widget::addKeyListener(KeyListener* keyListener) + { + mKeyListeners.push_back(keyListener); + } + + void Widget::removeKeyListener(KeyListener* keyListener) + { + mKeyListeners.remove(keyListener); + } + + void Widget::addFocusListener(FocusListener* focusListener) + { + mFocusListeners.push_back(focusListener); + } + + void Widget::removeFocusListener(FocusListener* focusListener) + { + mFocusListeners.remove(focusListener); + } + + void Widget::addMouseListener(MouseListener* mouseListener) + { + mMouseListeners.push_back(mouseListener); + } + + void Widget::removeMouseListener(MouseListener* mouseListener) + { + mMouseListeners.remove(mouseListener); + } + + void Widget::addWidgetListener(WidgetListener* widgetListener) + { + mWidgetListeners.push_back(widgetListener); + } + + void Widget::removeWidgetListener(WidgetListener* widgetListener) + { + mWidgetListeners.remove(widgetListener); + } + + void Widget::getAbsolutePosition(int& x, int& y) const + { + if (getParent() == nullptr) + { + x = mDimension.x; + y = mDimension.y; + return; + } + + int parentX; + int parentY; + + getParent()->getAbsolutePosition(parentX, parentY); + + x = parentX + mDimension.x + getParent()->getChildrenArea().x; + y = parentY + mDimension.y + getParent()->getChildrenArea().y; + } + + void Widget::generateAction() + { + for (auto& mActionListener : mActionListeners) + { + ActionEvent actionEvent(this, mActionEventId); + mActionListener->action(actionEvent); + } + } + + Font* Widget::getFont() const + { + if (mCurrentFont == nullptr) + { + if (mGlobalFont == nullptr) + { + return &mDefaultFont; + } + + return mGlobalFont; + } + + return mCurrentFont; + } + + void Widget::setGlobalFont(Font* font) + { + mGlobalFont = font; + + for (auto& mWidget : mWidgets) + { + if (mWidget->mCurrentFont == nullptr) + { + mWidget->fontChanged(); + } + } + } + + void Widget::setFont(Font* font) + { + mCurrentFont = font; + fontChanged(); + } + + bool Widget::widgetExists(const Widget* widget) + { + for (auto& mWidget : mWidgets) + { + if (mWidget == widget) + { + return true; + } + } + + return false; + } + + 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) + { + auto newDimension = mDimension; + newDimension.width = width; + newDimension.height = height; + + setDimension(newDimension); + } + + void Widget::setEnabled(bool enabled) + { + mEnabled = enabled; + } + + bool Widget::isEnabled() const + { + return mEnabled && isVisible(); + } + + void Widget::requestModalFocus() + { + if (mFocusHandler == nullptr) + { + throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); + } + + mFocusHandler->requestModalFocus(this); + } + + void Widget::requestModalMouseInputFocus() + { + if (mFocusHandler == nullptr) + { + throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); + } + + mFocusHandler->requestModalMouseInputFocus(this); + } + + void Widget::releaseModalFocus() + { + if (mFocusHandler == nullptr) + { + return; + } + + mFocusHandler->releaseModalFocus(this); + } + + void Widget::releaseModalMouseInputFocus() + { + if (mFocusHandler == nullptr) + { + return; + } + + mFocusHandler->releaseModalMouseInputFocus(this); + } + + bool Widget::hasModalFocus() const + { + if (mFocusHandler == nullptr) + { + throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); + } + + if (getParent() != nullptr) + { + return (mFocusHandler->getModalFocused() == this) || getParent()->hasModalFocus(); + } + + return mFocusHandler->getModalFocused() == this; + } + + bool Widget::hasModalMouseInputFocus() const + { + if (mFocusHandler == nullptr) + { + throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); + } + + if (getParent() != nullptr) + { + return (mFocusHandler->getModalMouseInputFocused() == this) || getParent()->hasModalMouseInputFocus(); + } + + return mFocusHandler->getModalMouseInputFocused() == this; + } + + Widget* Widget::getWidgetAt(int x, int y) + { + return nullptr; + } + + const std::list& Widget::_getMouseListeners() + { + return mMouseListeners; + } + + const std::list& Widget::_getKeyListeners() + { + return mKeyListeners; + } + + const std::list& Widget::_getFocusListeners() + { + return mFocusListeners; + } + + Rectangle Widget::getChildrenArea() + { + return Rectangle(0, 0, 0, 0); + } + + FocusHandler* Widget::_getInternalFocusHandler() + { + return mInternalFocusHandler; + } + + void Widget::setInternalFocusHandler(FocusHandler* focusHandler) + { + mInternalFocusHandler = focusHandler; + } + + void Widget::setId(const std::string& id) + { + mId = id; + } + + const std::string& Widget::getId() const + { + return mId; + } + + void Widget::distributeResizedEvent() + { + for (auto& mWidgetListener : mWidgetListeners) + { + Event event(this); + mWidgetListener->widgetResized(event); + } + } + + void Widget::distributeMovedEvent() + { + for (auto& mWidgetListener : mWidgetListeners) + { + Event event(this); + mWidgetListener->widgetMoved(event); + } + } + + void Widget::distributeHiddenEvent() + { + for (auto& mWidgetListener : mWidgetListeners) + { + Event event(this); + mWidgetListener->widgetHidden(event); + } + } + + void Widget::distributeShownEvent() + { + for (auto& mWidgetListener : mWidgetListeners) + { + Event event(this); + mWidgetListener->widgetShown(event); + } + } } diff --git a/external/libguisan/src/widgets/button.cpp b/external/libguisan/src/widgets/button.cpp index ca305a38..fcf05187 100644 --- a/external/libguisan/src/widgets/button.cpp +++ b/external/libguisan/src/widgets/button.cpp @@ -58,6 +58,9 @@ * For comments regarding functions please see the header file. */ +#include + + #include "guisan/widgets/button.hpp" #include "guisan/exception.hpp" @@ -69,247 +72,247 @@ namespace gcn { - Button::Button() - : mHasMouse(false), - mKeyPressed(false), - mMousePressed(false), - mAlignment(Graphics::CENTER), - mSpacing(4) - { - setFocusable(true); - adjustSize(); - setBorderSize(1); + Button::Button() + : mHasMouse(false), + mKeyPressed(false), + mMousePressed(false), + mAlignment(Graphics::CENTER), + mSpacing(4) + { + setFocusable(true); + adjustSize(); + setBorderSize(1); - addMouseListener(this); - addKeyListener(this); - addFocusListener(this); - } + addMouseListener(this); + addKeyListener(this); + addFocusListener(this); + } - Button::Button(const std::string& caption) - : mCaption(caption), - mHasMouse(false), - mKeyPressed(false), - mMousePressed(false), - mAlignment(Graphics::CENTER), - mSpacing(4) - { - setFocusable(true); - adjustSize(); - setBorderSize(1); + Button::Button(std::string caption) + : mCaption(std::move(caption)), + mHasMouse(false), + mKeyPressed(false), + mMousePressed(false), + mAlignment(Graphics::CENTER), + mSpacing(4) + { + setFocusable(true); + adjustSize(); + setBorderSize(1); - addMouseListener(this); - addKeyListener(this); - addFocusListener(this); - } + addMouseListener(this); + addKeyListener(this); + addFocusListener(this); + } - void Button::setCaption(const std::string& caption) - { - mCaption = caption; - } + void Button::setCaption(const std::string& caption) + { + mCaption = caption; + } - const std::string& Button::getCaption() const - { - return mCaption; - } + const std::string& Button::getCaption() const + { + return mCaption; + } - void Button::setAlignment(unsigned int alignment) - { - mAlignment = alignment; - } + void Button::setAlignment(unsigned int alignment) + { + mAlignment = alignment; + } - unsigned int Button::getAlignment() const - { - return mAlignment; - } + unsigned int Button::getAlignment() const + { + return mAlignment; + } - void Button::setSpacing(unsigned int spacing) - { - mSpacing = spacing; - } + void Button::setSpacing(unsigned int spacing) + { + mSpacing = spacing; + } - unsigned int Button::getSpacing() const - { - return mSpacing; - } + unsigned int Button::getSpacing() const + { + return mSpacing; + } - void Button::draw(Graphics* graphics) - { - auto faceColor = getBaseColor(); - Color highlightColor, shadowColor; - const auto alpha = getBaseColor().a; + void Button::draw(Graphics* graphics) + { + auto faceColor = getBaseColor(); + Color highlightColor, shadowColor; + const auto alpha = getBaseColor().a; - if (isPressed()) - { - faceColor = faceColor - 0x303030; - faceColor.a = alpha; - highlightColor = faceColor - 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor + 0x303030; - shadowColor.a = alpha; - } - else - { - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - } + if (isPressed()) + { + faceColor = faceColor - 0x303030; + faceColor.a = alpha; + highlightColor = faceColor - 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor + 0x303030; + shadowColor.a = alpha; + } + else + { + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + } - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(1, 1, getDimension().width-1, getHeight() - 1)); + graphics->setColor(faceColor); + graphics->fillRectangle(Rectangle(1, 1, getDimension().width - 1, getHeight() - 1)); - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, getWidth() - 1, 0); - graphics->drawLine(0, 1, 0, getHeight() - 1); + graphics->setColor(highlightColor); + graphics->drawLine(0, 0, getWidth() - 1, 0); + graphics->drawLine(0, 1, 0, getHeight() - 1); - graphics->setColor(shadowColor); - graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1); - graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1); + graphics->setColor(shadowColor); + graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1); + graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1); - graphics->setColor(getForegroundColor()); + graphics->setColor(getForegroundColor()); - int text_x; - const auto text_y = getHeight() / 2 - getFont()->getHeight() / 2; + int text_x; + const auto text_y = getHeight() / 2 - getFont()->getHeight() / 2; - switch (getAlignment()) - { - case Graphics::LEFT: - text_x = int(mSpacing); - break; - case Graphics::CENTER: - text_x = getWidth() / 2; - break; - case Graphics::RIGHT: - text_x = getWidth() - int(mSpacing); - break; - default: - throw GCN_EXCEPTION("Unknown alignment."); - } + switch (getAlignment()) + { + case Graphics::LEFT: + text_x = static_cast(mSpacing); + break; + case Graphics::CENTER: + text_x = getWidth() / 2; + break; + case Graphics::RIGHT: + text_x = getWidth() - static_cast(mSpacing); + break; + default: + throw GCN_EXCEPTION("Unknown alignment."); + } - graphics->setFont(getFont()); + graphics->setFont(getFont()); - if (isPressed()) - { - graphics->drawText(getCaption(), text_x + 1, text_y + 1, getAlignment()); - } - else - { - graphics->drawText(getCaption(), text_x, text_y, getAlignment()); + if (isPressed()) + { + graphics->drawText(getCaption(), text_x + 1, text_y + 1, getAlignment()); + } + else + { + graphics->drawText(getCaption(), text_x, text_y, getAlignment()); - if (isFocused()) - { - graphics->drawRectangle(Rectangle(2, 2, getWidth() - 4, - getHeight() - 4)); - } - } - } + if (isFocused()) + { + graphics->drawRectangle(Rectangle(2, 2, getWidth() - 4, + getHeight() - 4)); + } + } + } - void Button::drawBorder(Graphics* graphics) - { - const auto faceColor = getBaseColor(); - const auto alpha = getBaseColor().a; - const auto width = getWidth() + int(getBorderSize()) * 2 - 1; - const auto height = getHeight() + int(getBorderSize()) * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + void Button::drawBorder(Graphics* graphics) + { + const auto faceColor = getBaseColor(); + const auto alpha = getBaseColor().a; + const auto width = getWidth() + static_cast(getBorderSize()) * 2 - 1; + const auto height = getHeight() + static_cast(getBorderSize()) * 2 - 1; + auto highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + auto shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - for (auto i = 0; i < int(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); - } - } + for (auto i = 0; i < static_cast(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) + 2* int(mSpacing)); - setHeight(getFont()->getHeight() + 2* int(mSpacing)); - } + void Button::adjustSize() + { + setWidth(getFont()->getWidth(mCaption) + 2 * static_cast(mSpacing)); + setHeight(getFont()->getHeight() + 2 * static_cast(mSpacing)); + } - bool Button::isPressed() const - { - if (mMousePressed) - { - return true; - } - return mKeyPressed; - } + bool Button::isPressed() const + { + if (mMousePressed) + { + return true; + } + return mKeyPressed; + } - void Button::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mMousePressed = true; - mouseEvent.consume(); - } - } + void Button::mousePressed(MouseEvent& mouseEvent) + { + if (mouseEvent.getButton() == MouseEvent::LEFT) + { + mMousePressed = true; + mouseEvent.consume(); + } + } - void Button::mouseExited(MouseEvent& mouseEvent) - { - mHasMouse = false; - } + void Button::mouseExited(MouseEvent& mouseEvent) + { + mHasMouse = false; + } - void Button::mouseEntered(MouseEvent& mouseEvent) - { - mHasMouse = true; - } + void Button::mouseEntered(MouseEvent& mouseEvent) + { + mHasMouse = true; + } - void Button::mouseReleased(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT - && mMousePressed) - { - mMousePressed = false; - generateAction(); - mouseEvent.consume(); - } - else if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mMousePressed = false; - mouseEvent.consume(); - } - } + void Button::mouseReleased(MouseEvent& mouseEvent) + { + if (mouseEvent.getButton() == MouseEvent::LEFT + && mMousePressed) + { + mMousePressed = false; + generateAction(); + mouseEvent.consume(); + } + else if (mouseEvent.getButton() == MouseEvent::LEFT) + { + mMousePressed = false; + mouseEvent.consume(); + } + } - void Button::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } + void Button::mouseDragged(MouseEvent& mouseEvent) + { + mouseEvent.consume(); + } - void Button::keyPressed(KeyEvent& keyEvent) - { - const auto key = keyEvent.getKey(); + void Button::keyPressed(KeyEvent& keyEvent) + { + const auto key = keyEvent.getKey(); - if (key.getValue() == Key::ENTER - || key.getValue() == Key::SPACE) - { - mKeyPressed = true; - keyEvent.consume(); - } - } + if (key.getValue() == Key::ENTER + || key.getValue() == Key::SPACE) + { + mKeyPressed = true; + keyEvent.consume(); + } + } - void Button::keyReleased(KeyEvent& keyEvent) - { - const auto key = keyEvent.getKey(); + void Button::keyReleased(KeyEvent& keyEvent) + { + const auto key = keyEvent.getKey(); - if ((key.getValue() == Key::ENTER - || key.getValue() == Key::SPACE) - && mKeyPressed) - { - mKeyPressed = false; - generateAction(); - keyEvent.consume(); - } - } + if ((key.getValue() == Key::ENTER + || key.getValue() == Key::SPACE) + && mKeyPressed) + { + mKeyPressed = false; + generateAction(); + keyEvent.consume(); + } + } - void Button::focusLost(const Event& event) - { - mMousePressed = false; - mKeyPressed = false; - } + void Button::focusLost(const Event& event) + { + mMousePressed = false; + mKeyPressed = false; + } } diff --git a/external/libguisan/src/widgets/checkbox.cpp b/external/libguisan/src/widgets/checkbox.cpp index a7dc04c9..21024af3 100644 --- a/external/libguisan/src/widgets/checkbox.cpp +++ b/external/libguisan/src/widgets/checkbox.cpp @@ -67,159 +67,159 @@ namespace gcn { + CheckBox::CheckBox() + { + setSelected(false); - CheckBox::CheckBox() - { - setSelected(false); + setFocusable(true); + addMouseListener(this); + addKeyListener(this); + } - setFocusable(true); - addMouseListener(this); - addKeyListener(this); - } + CheckBox::CheckBox(const std::string& caption, bool selected) + { + setCaption(caption); + setSelected(selected); - CheckBox::CheckBox(const std::string &caption, bool selected) - { - setCaption(caption); - setSelected(selected); + setFocusable(true); + addMouseListener(this); + addKeyListener(this); - setFocusable(true); - addMouseListener(this); - addKeyListener(this); + adjustSize(); + } - adjustSize(); - } + void CheckBox::draw(Graphics* graphics) + { + drawBox(graphics); - void CheckBox::draw(Graphics* graphics) - { - drawBox(graphics); + graphics->setFont(getFont()); + graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); - graphics->setColor(getForegroundColor()); + const auto h = getHeight() + getHeight() / 2; - const auto h = getHeight() + getHeight() / 2; + graphics->drawText(getCaption(), h - 2, 0); + } - graphics->drawText(getCaption(), h - 2, 0); - } + void CheckBox::drawBorder(Graphics* graphics) + { + const auto faceColor = getBaseColor(); + const auto alpha = getBaseColor().a; + const auto width = getWidth() + static_cast(getBorderSize()) * 2 - 1; + const auto height = getHeight() + static_cast(getBorderSize()) * 2 - 1; + auto highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + auto shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - void CheckBox::drawBorder(Graphics* graphics) - { - const auto faceColor = getBaseColor(); - const auto alpha = getBaseColor().a; - const auto width = getWidth() + int(getBorderSize()) * 2 - 1; - const auto height = getHeight() + int(getBorderSize()) * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + for (auto i = 0; i < static_cast(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); + } + } - for (auto i = 0; i < int(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) + { + const auto h = getHeight() - 2; + const auto alpha = getBaseColor().a; + auto faceColor = getBaseColor(); + faceColor.a = alpha; + auto highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + auto shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - void CheckBox::drawBox(Graphics *graphics) - { - const auto h = getHeight() - 2; + graphics->setColor(shadowColor); + graphics->drawLine(1, 1, h, 1); + graphics->drawLine(1, 1, 1, h); - const auto alpha = getBaseColor().a; - auto faceColor = getBaseColor(); - faceColor.a = alpha; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + graphics->setColor(highlightColor); + graphics->drawLine(h, 1, h, h); + graphics->drawLine(1, h, h - 1, h); - graphics->setColor(shadowColor); - graphics->drawLine(1, 1, h, 1); - graphics->drawLine(1, 1, 1, h); + auto backCol = getBackgroundColor(); + if (!isEnabled()) + backCol = backCol - 0x303030; + graphics->setColor(backCol); + graphics->fillRectangle(Rectangle(2, 2, h - 2, h - 2)); - graphics->setColor(highlightColor); - graphics->drawLine(h, 1, h, h); - graphics->drawLine(1, h, h - 1, h); + graphics->setColor(getForegroundColor()); - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(Rectangle(2, 2, h - 2, h - 2)); + if (isFocused()) + { + graphics->drawRectangle(Rectangle(0, 0, getWidth(), getHeight())); + } - graphics->setColor(getForegroundColor()); + if (mSelected) + { + graphics->drawLine(3, 5, 3, h - 2); + graphics->drawLine(4, 5, 4, h - 2); - if (isFocused()) - { - graphics->drawRectangle(Rectangle(0, 0, h + 2, h + 2)); - } - - if (mSelected) - { - graphics->drawLine(3, 5, 3, h - 2); - graphics->drawLine(4, 5, 4, h - 2); + graphics->drawLine(5, h - 3, h - 2, 4); + graphics->drawLine(5, h - 4, h - 4, 5); + } + } - graphics->drawLine(5, h - 3, h - 2, 4); - graphics->drawLine(5, h - 4, h - 4, 5); - } - } + bool CheckBox::isSelected() const + { + return mSelected; + } - bool CheckBox::isSelected() const - { - return mSelected; - } + void CheckBox::setSelected(bool selected) + { + mSelected = selected; + } - void CheckBox::setSelected(bool selected) - { - mSelected = selected; - } + const std::string& CheckBox::getCaption() const + { + return mCaption; + } - const std::string &CheckBox::getCaption() const - { - return mCaption; - } + void CheckBox::setCaption(const std::string& caption) + { + mCaption = caption; + } - void CheckBox::setCaption(const std::string& caption) - { - mCaption = caption; - } + void CheckBox::keyPressed(KeyEvent& keyEvent) + { + const auto key = keyEvent.getKey(); - void CheckBox::keyPressed(KeyEvent& keyEvent) - { - const auto key = keyEvent.getKey(); + if (key.getValue() == Key::ENTER || + key.getValue() == Key::SPACE) + { + toggleSelected(); + keyEvent.consume(); + } + } - if (key.getValue() == Key::ENTER || - key.getValue() == Key::SPACE) - { - toggleSelected(); - keyEvent.consume(); - } - } + void CheckBox::mouseClicked(MouseEvent& mouseEvent) + { + if (mouseEvent.getButton() == MouseEvent::LEFT) + { + toggleSelected(); + } + } - void CheckBox::mouseClicked(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - toggleSelected(); - } - } + void CheckBox::mouseDragged(MouseEvent& mouseEvent) + { + mouseEvent.consume(); + } - void CheckBox::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } + void CheckBox::adjustSize() + { + const auto height = getFont()->getHeight(); - void CheckBox::adjustSize() - { - const auto height = getFont()->getHeight(); + setHeight(height); + setWidth(getFont()->getWidth(mCaption) + height + height / 2); + } - setHeight(height); - setWidth(getFont()->getWidth(mCaption) + height + height / 2); - } - - void CheckBox::toggleSelected() - { - mSelected = !mSelected; - generateAction(); - } + void CheckBox::toggleSelected() + { + mSelected = !mSelected; + generateAction(); + } } - diff --git a/external/libguisan/src/widgets/container.cpp b/external/libguisan/src/widgets/container.cpp index d6c15a32..2a31d66a 100644 --- a/external/libguisan/src/widgets/container.cpp +++ b/external/libguisan/src/widgets/container.cpp @@ -65,81 +65,80 @@ namespace gcn { + Container::Container() + { + mOpaque = true; + } - Container::Container() - { - mOpaque = true; - } + Container::~Container() + = default; - Container::~Container() - = default; + void Container::draw(Graphics* graphics) + { + if (isOpaque()) + { + graphics->setColor(getBaseColor()); + graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); + } - void Container::draw(Graphics* graphics) - { - if (isOpaque()) - { - graphics->setColor(getBaseColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - } + drawChildren(graphics); + } - drawChildren(graphics); - } + void Container::drawBorder(Graphics* graphics) + { + const auto faceColor = getBaseColor(); + const auto alpha = getBaseColor().a; + const auto width = getWidth() + static_cast(getBorderSize()) * 2 - 1; + const auto height = getHeight() + static_cast(getBorderSize()) * 2 - 1; + auto highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + auto shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - void Container::drawBorder(Graphics* graphics) - { - const auto faceColor = getBaseColor(); - const auto alpha = getBaseColor().a; - const auto width = getWidth() + int(getBorderSize()) * 2 - 1; - const auto height = getHeight() + int(getBorderSize()) * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + for (auto i = 0; i < static_cast(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); + } + } - for (auto i = 0; i < int(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::setOpaque(bool opaque) + { + mOpaque = opaque; + } - void Container::setOpaque(bool opaque) - { - mOpaque = opaque; - } + bool Container::isOpaque() const + { + return mOpaque; + } - bool Container::isOpaque() const - { - return mOpaque; - } + void Container::add(Widget* widget) + { + BasicContainer::add(widget); + } - void Container::add(Widget* widget) - { - BasicContainer::add(widget); - } + void Container::add(Widget* widget, int x, int y) + { + widget->setPosition(x, y); + BasicContainer::add(widget); + } - void Container::add(Widget* widget, int x, int y) - { - widget->setPosition(x, y); - BasicContainer::add(widget); - } + void Container::remove(Widget* widget) + { + BasicContainer::remove(widget); + } - void Container::remove(Widget* widget) - { - BasicContainer::remove(widget); - } + void Container::clear() + { + BasicContainer::clear(); + } - void Container::clear() - { - BasicContainer::clear(); - } - - Widget* Container::findWidgetById(const std::string &id) - { - return BasicContainer::findWidgetById(id); - } + Widget* Container::findWidgetById(const std::string& id) + { + return BasicContainer::findWidgetById(id); + } } diff --git a/external/libguisan/src/widgets/dropdown.cpp b/external/libguisan/src/widgets/dropdown.cpp index 791ba69c..a2ff51c1 100644 --- a/external/libguisan/src/widgets/dropdown.cpp +++ b/external/libguisan/src/widgets/dropdown.cpp @@ -67,574 +67,587 @@ namespace gcn { - DropDown::DropDown(ListModel *listModel, - ScrollArea *scrollArea, - ListBox *listBox) - { - setWidth(100); - setFocusable(true); - mDroppedDown = false; - mPushed = false; - mIsDragged = false; - - setInternalFocusHandler(&mInternalFocusHandler); - - mInternalScrollArea = (scrollArea == NULL); - mInternalListBox = (listBox == NULL); - - if (mInternalScrollArea) - { - mScrollArea = new ScrollArea(); - } - else - { - mScrollArea = scrollArea; - } - - if (mInternalListBox) - { - mListBox = new ListBox(); - } - else - { - mListBox = listBox; - } - - mScrollArea->setContent(mListBox); - add(mScrollArea); - - mListBox->addActionListener(this); - mListBox->addSelectionListener(this); - - setListModel(listModel); - - if (mListBox->getSelected() < 0) - { - mListBox->setSelected(0); - } - - addMouseListener(this); - addKeyListener(this); - addFocusListener(this); - - adjustHeight(); - setBorderSize(1); - } - - DropDown::~DropDown() - { - if (widgetExists(mListBox)) - mListBox->removeSelectionListener(this); - - if (mInternalScrollArea) - delete mScrollArea; - - if (mInternalListBox) - delete mListBox; - - setInternalFocusHandler(NULL); - } - - void DropDown::draw(Graphics* graphics) - { - int h; - - if (mDroppedDown) - { - h = mFoldedUpHeight; - } - else - { - h = getHeight(); - } - - const auto alpha = getBaseColor().a; - auto faceColor = getBaseColor(); - faceColor.a = alpha; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), h)); - - graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); - - if (isFocused()) - { - graphics->setColor(getSelectionColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth() - h, h)); - graphics->setColor(getForegroundColor()); - } - - if (mListBox->getListModel() && mListBox->getSelected() >= 0) - { - graphics->drawText(mListBox->getListModel()->getElementAt(mListBox->getSelected()), 1, 0); - } - - drawButton(graphics); - - if (mDroppedDown) - { - drawChildren(graphics); - - // 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) - { - const auto faceColor = getBaseColor(); - const auto alpha = getBaseColor().a; - const auto width = getWidth() + int(getBorderSize()) * 2 - 1; - const auto height = getHeight() + int(getBorderSize()) * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto 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; - const auto 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 = mFoldedUpHeight; - } - else - { - h = getHeight(); - } - const auto x = getWidth() - h; - const auto 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()); - - const auto hh = h / 3; - const auto hx = x + h / 2; - const auto hy = y + (h * 2) / 3; - for (auto i = 0; i < hh; i++) - { - graphics->drawLine(hx - i + offset, - hy - i + offset, - hx + i + offset, - hy - i + offset); - } - } - - int DropDown::getSelected() const - { - return mListBox->getSelected(); - } - - void DropDown::setSelected(int selected) - { - if (selected >= 0) - { - mListBox->setSelected(selected); - } - } - - void DropDown::keyPressed(KeyEvent& keyEvent) - { - const auto key = keyEvent.getKey(); - - if ((key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) - && !mDroppedDown) - { - dropDown(); - keyEvent.consume(); - } - else if (key.getValue() == Key::UP) - { - setSelected(getSelected() - 1); - keyEvent.consume(); - } - else if (key.getValue() == Key::DOWN) - { - setSelected(getSelected() + 1); - keyEvent.consume(); - } - } - - void DropDown::mousePressed(MouseEvent& mouseEvent) - { - // If we have a mouse press on the widget. - if (0 <= mouseEvent.getY() - && mouseEvent.getY() < getHeight() - && mouseEvent.getX() >= 0 - && mouseEvent.getX() < getWidth() - && mouseEvent.getButton() == MouseEvent::LEFT - && !mDroppedDown - && mouseEvent.getSource() == this) - { - mPushed = true; - dropDown(); - requestModalMouseInputFocus(); - } - // Fold up the listbox if the upper part is clicked after fold down - else if (0 <= mouseEvent.getY() - && mouseEvent.getY() < mFoldedUpHeight - && mouseEvent.getX() >= 0 - && mouseEvent.getX() < getWidth() - && mouseEvent.getButton() == MouseEvent::LEFT - && mDroppedDown - && mouseEvent.getSource() == this) - { - mPushed = false; - foldUp(); - releaseModalMouseInputFocus(); - } - // If we have a mouse press outside the widget - else if (0 > mouseEvent.getY() - || mouseEvent.getY() >= getHeight() - || mouseEvent.getX() < 0 - || mouseEvent.getX() >= getWidth()) - { - mPushed = false; - foldUp(); - } - } - - void DropDown::mouseReleased(MouseEvent& mouseEvent) - { - if (mIsDragged) - { - mPushed = false; - } - - // Released outside of widget. Can happen when we have modal input focus. - if ((0 > mouseEvent.getY() - || mouseEvent.getY() >= getHeight() - || mouseEvent.getX() < 0 - || mouseEvent.getX() >= getWidth()) - && mouseEvent.getButton() == MouseEvent::LEFT - && hasModalMouseInputFocus()) - { - releaseModalMouseInputFocus(); - - if (mIsDragged) - { - foldUp(); - } - } - else if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mPushed = false; - } - - mIsDragged = false; - } - - void DropDown::mouseDragged(MouseEvent& mouseEvent) - { - mIsDragged = true; - - mouseEvent.consume(); - } - - void DropDown::setListModel(ListModel *listModel) - { - mListBox->setListModel(listModel); - - if (mListBox->getSelected() < 0) - { - mListBox->setSelected(0); - } - - adjustHeight(); - } - - ListModel *DropDown::getListModel() - { - return mListBox->getListModel(); - } - - void DropDown::adjustHeight() - { - if (mScrollArea == NULL) - throw GCN_EXCEPTION("Scroll Area has been deleted."); - - if (mListBox == NULL) - throw GCN_EXCEPTION("List box has been deleted."); - - const auto listBoxHeight = mListBox->getHeight(); - const auto h2 = getFont()->getHeight(); - - setHeight(h2); - - // The addition/subtraction of 2 compensates for the separation lines - // separating the selected element view and the scroll area. - - if (mDroppedDown && getParent()) - { - const auto h = getParent()->getChildrenArea().height - getY(); - - if (listBoxHeight > h - h2 - 2) - { - mScrollArea->setHeight(h - h2 - 2); - setHeight(h); - } - else - { - setHeight(listBoxHeight + h2 + 2); - mScrollArea->setHeight(listBoxHeight); - } - } - - mScrollArea->setWidth(getWidth()); - // Resize the ListBox to exactly fit the ScrollArea. - mListBox->setWidth(mScrollArea->getChildrenArea().width); - mScrollArea->setPosition(0, 0); - } - - void DropDown::dropDown() - { - if (!mDroppedDown) - { - mDroppedDown = true; - mFoldedUpHeight = getHeight(); - adjustHeight(); - - if (getParent()) - { - getParent()->moveToTop(this); - } - } - - mListBox->requestFocus(); - } - - void DropDown::foldUp() - { - if (mDroppedDown) - { - mDroppedDown = false; - adjustHeight(); - mInternalFocusHandler.focusNone(); - } - } - - void DropDown::focusLost(const Event& event) - { - foldUp(); - mInternalFocusHandler.focusNone(); - } - - - void DropDown::death(const Event& event) - { - if (event.getSource() == mScrollArea) - { - mScrollArea = NULL; - } - BasicContainer::death(event); - } - - void DropDown::action(const ActionEvent& actionEvent) - { - foldUp(); - releaseModalMouseInputFocus(); - generateAction(); - } - - Rectangle DropDown::getChildrenArea() - { - if (mDroppedDown) - { - return Rectangle(0, - mFoldedUpHeight + 2, - getWidth(), - getHeight() - mFoldedUpHeight); - } - - return Rectangle(); - } - - void DropDown::setBaseColor(const Color& color) - { - if (mInternalScrollArea) - { - mScrollArea->setBaseColor(color); - } - - if (mInternalListBox) - { - mListBox->setBaseColor(color); - } - - Widget::setBaseColor(color); - } - - void DropDown::setBackgroundColor(const Color& color) - { - if (mInternalScrollArea) - { - mScrollArea->setBackgroundColor(color); - } - - if (mInternalListBox) - { - mListBox->setBackgroundColor(color); - } - - Widget::setBackgroundColor(color); - } - - void DropDown::setForegroundColor(const Color& color) - { - if (mInternalScrollArea) - { - mScrollArea->setForegroundColor(color); - } - - if (mInternalListBox) - { - mListBox->setForegroundColor(color); - } - - Widget::setForegroundColor(color); - } - - void DropDown::setFont(Font *font) + DropDown::DropDown(ListModel* listModel, + ScrollArea* scrollArea, + ListBox* listBox) + { + Widget::setWidth(100); + setFocusable(true); + mDroppedDown = false; + mPushed = false; + mIsDragged = false; + + BasicContainer::setInternalFocusHandler(&mInternalFocusHandler); + + mInternalScrollArea = (scrollArea == nullptr); + mInternalListBox = (listBox == nullptr); + + if (mInternalScrollArea) + { + mScrollArea = new ScrollArea(); + } + else + { + mScrollArea = scrollArea; + } + + if (mInternalListBox) + { + mListBox = new ListBox(); + } + else + { + mListBox = listBox; + } + + mScrollArea->setContent(mListBox); + add(mScrollArea); + + mListBox->addActionListener(this); + mListBox->addSelectionListener(this); + + setListModel(listModel); + + if (mListBox->getSelected() < 0) + { + mListBox->setSelected(0); + } + + addMouseListener(this); + addKeyListener(this); + addFocusListener(this); + + adjustHeight(); + setBorderSize(1); + } + + DropDown::~DropDown() + { + if (widgetExists(mListBox)) + mListBox->removeSelectionListener(this); + + if (mInternalScrollArea) + delete mScrollArea; + + if (mInternalListBox) + delete mListBox; + + BasicContainer::setInternalFocusHandler(nullptr); + } + + void DropDown::draw(Graphics* graphics) + { + int h; + + if (mDroppedDown) + { + h = mFoldedUpHeight; + } + else + { + h = getHeight(); + } + + const auto alpha = getBaseColor().a; + auto faceColor = getBaseColor(); + faceColor.a = alpha; + auto highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + auto shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + auto backCol = getBackgroundColor(); + if (!isEnabled()) + backCol = backCol - 0x303030; + graphics->setColor(backCol); + graphics->fillRectangle(Rectangle(0, 0, getWidth(), h)); + + graphics->setColor(getForegroundColor()); + graphics->setFont(getFont()); + + if (isFocused()) + { + graphics->setColor(getSelectionColor()); + graphics->fillRectangle(Rectangle(0, 0, getWidth() - h, h)); + graphics->setColor(getForegroundColor()); + } + + if (mListBox->getListModel() && mListBox->getSelected() >= 0) + { + graphics->drawText(mListBox->getListModel()->getElementAt(mListBox->getSelected()), 1, 0); + } + + drawButton(graphics); + + if (mDroppedDown) + { + drawChildren(graphics); + + // 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) + { + const auto faceColor = getBaseColor(); + const auto alpha = getBaseColor().a; + const auto width = getWidth() + static_cast(getBorderSize()) * 2 - 1; + const auto height = getHeight() + static_cast(getBorderSize()) * 2 - 1; + auto highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + auto shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + for (auto i = 0; i < static_cast(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; + const auto 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 = mFoldedUpHeight; + } + else + { + h = getHeight(); + } + const auto x = getWidth() - h; + const auto 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()); + + const auto hh = h / 3; + const auto hx = x + h / 2; + const auto hy = y + (h * 2) / 3; + for (auto i = 0; i < hh; i++) + { + graphics->drawLine(hx - i + offset, + hy - i + offset, + hx + i + offset, + hy - i + offset); + } + } + + int DropDown::getSelected() const + { + return mListBox->getSelected(); + } + + void DropDown::setSelected(int selected) const + { + if (selected >= 0) + { + mListBox->setSelected(selected); + } + } + + void DropDown::clearSelected() const + { + mListBox->setSelected(-1); + } + + void DropDown::keyPressed(KeyEvent& keyEvent) + { + if (keyEvent.isConsumed()) + return; + + const auto key = keyEvent.getKey(); + + if ((key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) + && !mDroppedDown) + { + dropDown(); + keyEvent.consume(); + } + else if (key.getValue() == Key::UP) + { + setSelected(getSelected() - 1); + keyEvent.consume(); + } + else if (key.getValue() == Key::DOWN) + { + setSelected(getSelected() + 1); + keyEvent.consume(); + } + } + + void DropDown::mousePressed(MouseEvent& mouseEvent) + { + // If we have a mouse press on the widget. + if (0 <= mouseEvent.getY() + && mouseEvent.getY() < getHeight() + && mouseEvent.getX() >= 0 + && mouseEvent.getX() < getWidth() + && mouseEvent.getButton() == MouseEvent::LEFT + && !mDroppedDown + && mouseEvent.getSource() == this) + { + mPushed = true; + dropDown(); + requestModalMouseInputFocus(); + } + // Fold up the listbox if the upper part is clicked after fold down + else if (0 <= mouseEvent.getY() + && mouseEvent.getY() < mFoldedUpHeight + && mouseEvent.getX() >= 0 + && mouseEvent.getX() < getWidth() + && mouseEvent.getButton() == MouseEvent::LEFT + && mDroppedDown + && mouseEvent.getSource() == this) + { + mPushed = false; + foldUp(); + releaseModalMouseInputFocus(); + } + // If we have a mouse press outside the widget + else if (0 > mouseEvent.getY() + || mouseEvent.getY() >= getHeight() + || mouseEvent.getX() < 0 + || mouseEvent.getX() >= getWidth()) + { + mPushed = false; + foldUp(); + } + } + + void DropDown::mouseReleased(MouseEvent& mouseEvent) + { + if (mIsDragged) + { + mPushed = false; + } + + // Released outside of widget. Can happen when we have modal input focus. + if ((0 > mouseEvent.getY() + || mouseEvent.getY() >= getHeight() + || mouseEvent.getX() < 0 + || mouseEvent.getX() >= getWidth()) + && mouseEvent.getButton() == MouseEvent::LEFT + && hasModalMouseInputFocus()) + { + releaseModalMouseInputFocus(); + + if (mIsDragged) + { + foldUp(); + } + } + else if (mouseEvent.getButton() == MouseEvent::LEFT) + { + mPushed = false; + } + + mIsDragged = false; + } + + void DropDown::mouseDragged(MouseEvent& mouseEvent) + { + mIsDragged = true; + + mouseEvent.consume(); + } + + void DropDown::setListModel(ListModel* listModel) + { + mListBox->setListModel(listModel); + + if (mListBox->getSelected() < 0) + { + mListBox->setSelected(0); + } + + adjustHeight(); + } + + ListModel* DropDown::getListModel() const + { + return mListBox->getListModel(); + } + + void DropDown::adjustHeight() + { + if (mScrollArea == nullptr) + throw GCN_EXCEPTION("Scroll Area has been deleted."); + + if (mListBox == nullptr) + throw GCN_EXCEPTION("List box has been deleted."); + + const auto listBoxHeight = mListBox->getHeight(); + const auto h2 = getFont()->getHeight(); + + setHeight(h2); + + // The addition/subtraction of 2 compensates for the separation lines + // separating the selected element view and the scroll area. + + if (mDroppedDown && getParent()) + { + const auto h = getParent()->getChildrenArea().height - getY(); + + if (listBoxHeight > h - h2 - 2) + { + mScrollArea->setHeight(h - h2 - 2); + setHeight(h); + } + else + { + setHeight(listBoxHeight + h2 + 2); + mScrollArea->setHeight(listBoxHeight); + } + } + + mScrollArea->setWidth(getWidth()); + // Resize the ListBox to exactly fit the ScrollArea. + mListBox->setWidth(mScrollArea->getChildrenArea().width); + mScrollArea->setPosition(0, 0); + } + + void DropDown::dropDown() + { + if (!mDroppedDown) + { + mDroppedDown = true; + mFoldedUpHeight = getHeight(); + adjustHeight(); + + if (getParent()) + { + getParent()->moveToTop(this); + } + } + + mListBox->requestFocus(); + } + + bool DropDown::isDroppedDown() const + { + return mDroppedDown; + } + + void DropDown::foldUp() + { + if (mDroppedDown) + { + mDroppedDown = false; + adjustHeight(); + mInternalFocusHandler.focusNone(); + } + } + + void DropDown::focusLost(const Event& event) + { + foldUp(); + mInternalFocusHandler.focusNone(); + } + + + void DropDown::death(const Event& event) + { + if (event.getSource() == mScrollArea) + { + mScrollArea = nullptr; + } + BasicContainer::death(event); + } + + void DropDown::action(const ActionEvent& actionEvent) + { + foldUp(); + releaseModalMouseInputFocus(); + generateAction(); + } + + Rectangle DropDown::getChildrenArea() + { + if (mDroppedDown) + { + return Rectangle(0, + mFoldedUpHeight + 2, + getWidth(), + getHeight() - mFoldedUpHeight); + } + + return Rectangle(); + } + + void DropDown::setBaseColor(const Color& color) { if (mInternalScrollArea) - { - mScrollArea->setFont(font); - } + { + mScrollArea->setBaseColor(color); + } - if (mInternalListBox) - { - mListBox->setFont(font); - } + if (mInternalListBox) + { + mListBox->setBaseColor(color); + } - Widget::setFont(font); + Widget::setBaseColor(color); + } + + void DropDown::setBackgroundColor(const Color& color) + { + if (mInternalScrollArea) + { + mScrollArea->setBackgroundColor(color); + } + + if (mInternalListBox) + { + mListBox->setBackgroundColor(color); + } + + Widget::setBackgroundColor(color); + } + + void DropDown::setForegroundColor(const Color& color) + { + if (mInternalScrollArea) + { + mScrollArea->setForegroundColor(color); + } + + if (mInternalListBox) + { + mListBox->setForegroundColor(color); + } + + Widget::setForegroundColor(color); + } + + void DropDown::setFont(Font* font) + { + if (mInternalScrollArea) + { + mScrollArea->setFont(font); + } + + if (mInternalListBox) + { + mListBox->setFont(font); + } + + Widget::setFont(font); } void DropDown::mouseWheelMovedUp(MouseEvent& mouseEvent) { - if (isFocused() && mouseEvent.getSource() == this) - { - mouseEvent.consume(); + if (isFocused() && mouseEvent.getSource() == this) + { + mouseEvent.consume(); - if (mListBox->getSelected() > 0) - { - mListBox->setSelected(mListBox->getSelected() - 1); - } - } - } + if (mListBox->getSelected() > 0) + { + mListBox->setSelected(mListBox->getSelected() - 1); + } + } + } - void DropDown::mouseWheelMovedDown(MouseEvent& mouseEvent) - { - if (isFocused() && mouseEvent.getSource() == this) - { - mouseEvent.consume(); + void DropDown::mouseWheelMovedDown(MouseEvent& mouseEvent) + { + if (isFocused() && mouseEvent.getSource() == this) + { + mouseEvent.consume(); - mListBox->setSelected(mListBox->getSelected() + 1); - } - } + mListBox->setSelected(mListBox->getSelected() + 1); + } + } - void DropDown::setSelectionColor(const Color& color) - { - Widget::setSelectionColor(color); - - if (mInternalListBox) - { - mListBox->setSelectionColor(color); - } - } + void DropDown::setSelectionColor(const Color& color) + { + Widget::setSelectionColor(color); - void DropDown::valueChanged(const SelectionEvent& event) - { - distributeValueChangedEvent(); - } + if (mInternalListBox) + { + mListBox->setSelectionColor(color); + } + } - void DropDown::addSelectionListener(SelectionListener* selectionListener) - { - mSelectionListeners.push_back(selectionListener); - } - - void DropDown::removeSelectionListener(SelectionListener* selectionListener) - { - mSelectionListeners.remove(selectionListener); - } + void DropDown::valueChanged(const SelectionEvent& event) + { + distributeValueChangedEvent(); + } - void DropDown::distributeValueChangedEvent() - { - for (auto& mSelectionListener : mSelectionListeners) - { - SelectionEvent event(this); - mSelectionListener->valueChanged(event); - } - } + void DropDown::addSelectionListener(SelectionListener* selectionListener) + { + mSelectionListeners.push_back(selectionListener); + } + + void DropDown::removeSelectionListener(SelectionListener* selectionListener) + { + mSelectionListeners.remove(selectionListener); + } + + void DropDown::distributeValueChangedEvent() + { + for (auto& mSelectionListener : mSelectionListeners) + { + SelectionEvent event(this); + mSelectionListener->valueChanged(event); + } + } } - diff --git a/external/libguisan/src/widgets/icon.cpp b/external/libguisan/src/widgets/icon.cpp index 7fe2fb7b..310d95e9 100644 --- a/external/libguisan/src/widgets/icon.cpp +++ b/external/libguisan/src/widgets/icon.cpp @@ -66,54 +66,54 @@ namespace gcn { - Icon::Icon(const std::string& filename) - { - mImage = Image::load(filename); - mInternalImage = true; - setHeight(mImage->getHeight()); - setWidth(mImage->getWidth()); - } + Icon::Icon(const std::string& filename) + { + mImage = Image::load(filename); + mInternalImage = true; + Widget::setHeight(mImage->getHeight()); + Widget::setWidth(mImage->getWidth()); + } - Icon::Icon(Image* image) - { - mImage = image; - mInternalImage = false; - setHeight(mImage->getHeight()); - setWidth(mImage->getWidth()); - } + Icon::Icon(Image* image) + { + mImage = image; + mInternalImage = false; + Widget::setHeight(mImage->getHeight()); + Widget::setWidth(mImage->getWidth()); + } - Icon::~Icon() - { - if (mInternalImage) - { - delete mImage; - } - } + Icon::~Icon() + { + if (mInternalImage) + { + delete mImage; + } + } - void Icon::draw(Graphics* graphics) - { - graphics->drawImage(mImage, 0, 0); - } + void Icon::draw(Graphics* graphics) + { + graphics->drawImage(mImage, 0, 0); + } - void Icon::drawBorder(Graphics* graphics) - { - const auto faceColor = getBaseColor(); - const auto alpha = getBaseColor().a; - const auto width = getWidth() + int(getBorderSize()) * 2 - 1; - const auto height = getHeight() + int(getBorderSize()) * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + void Icon::drawBorder(Graphics* graphics) + { + const auto faceColor = getBaseColor(); + const auto alpha = getBaseColor().a; + const auto width = getWidth() + static_cast(getBorderSize()) * 2 - 1; + const auto height = getHeight() + static_cast(getBorderSize()) * 2 - 1; + auto highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + auto shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - for (auto i = 0; i < int(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); - } - } + for (auto i = 0; i < static_cast(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); + } + } } diff --git a/external/libguisan/src/widgets/imagebutton.cpp b/external/libguisan/src/widgets/imagebutton.cpp index 678d8383..ddba9231 100644 --- a/external/libguisan/src/widgets/imagebutton.cpp +++ b/external/libguisan/src/widgets/imagebutton.cpp @@ -65,101 +65,98 @@ namespace gcn { - ImageButton::ImageButton(const std::string& filename) - { - mImage = Image::load(filename); - mInternalImage = true; - setWidth(mImage->getWidth() + mImage->getWidth() / 2); - setHeight(mImage->getHeight() + mImage->getHeight() / 2); - } + ImageButton::ImageButton(const std::string& filename) + { + mImage = Image::load(filename); + mInternalImage = true; + Widget::setWidth(mImage->getWidth() + mImage->getWidth() / 2); + Widget::setHeight(mImage->getHeight() + mImage->getHeight() / 2); + } - ImageButton::ImageButton(Image* image) - { - mImage = image; - mInternalImage = false; - setWidth(mImage->getWidth() + mImage->getWidth() / 2); - setHeight(mImage->getHeight() + mImage->getHeight() / 2); - } + ImageButton::ImageButton(Image* image) + { + mImage = image; + mInternalImage = false; + Widget::setWidth(mImage->getWidth() + mImage->getWidth() / 2); + Widget::setHeight(mImage->getHeight() + mImage->getHeight() / 2); + } - ImageButton::~ImageButton() - { - if (mInternalImage) - delete mImage; - } + ImageButton::~ImageButton() + { + if (mInternalImage) + delete mImage; + } - void ImageButton::adjustSize() - { - setWidth(mImage->getWidth()); - setHeight(mImage->getHeight()); - } + void ImageButton::adjustSize() + { + setWidth(mImage->getWidth()); + setHeight(mImage->getHeight()); + } - void ImageButton::setImage(Image* image) - { - if (mInternalImage) - delete mImage; - mImage = image; - mInternalImage = false; - } + void ImageButton::setImage(Image* image) + { + if (mInternalImage) + delete mImage; + mImage = image; + mInternalImage = false; + } - Image* ImageButton::getImage() - { - return mImage; - } + Image* ImageButton::getImage() + { + return mImage; + } - void ImageButton::draw(Graphics* graphics) - { - auto faceColor = getBaseColor(); - Color highlightColor, shadowColor; - const auto alpha = getBaseColor().a; + void ImageButton::draw(Graphics* graphics) + { + auto faceColor = getBaseColor(); + Color highlightColor, shadowColor; + const auto alpha = getBaseColor().a; - if (isPressed()) - { - faceColor = faceColor - 0x303030; - faceColor.a = alpha; - highlightColor = faceColor - 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor + 0x303030; - shadowColor.a = alpha; - } - else - { - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - } + if (isPressed()) + { + faceColor = faceColor - 0x303030; + faceColor.a = alpha; + highlightColor = faceColor - 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor + 0x303030; + shadowColor.a = alpha; + } + else + { + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + } - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(1, 1, getDimension().width-1, getHeight() - 1)); + graphics->setColor(faceColor); + graphics->fillRectangle(Rectangle(1, 1, getDimension().width - 1, getHeight() - 1)); - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, getWidth() - 1, 0); - graphics->drawLine(0, 1, 0, getHeight() - 1); + graphics->setColor(highlightColor); + graphics->drawLine(0, 0, getWidth() - 1, 0); + graphics->drawLine(0, 1, 0, getHeight() - 1); - graphics->setColor(shadowColor); - graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1); - graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1); + graphics->setColor(shadowColor); + graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1); + graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1); - graphics->setColor(getForegroundColor()); + graphics->setColor(getForegroundColor()); - const auto text_x = getWidth() / 2 - mImage->getWidth() / 2; - const auto text_y = getHeight() / 2 - mImage->getHeight() / 2; + const auto text_x = getWidth() / 2 - mImage->getWidth() / 2; + const auto text_y = getHeight() / 2 - mImage->getHeight() / 2; - if (isPressed()) - { - graphics->drawImage(mImage, text_x + 1, text_y + 1); - } - else - { - graphics->drawImage(mImage, text_x, text_y); - - if (isFocused()) - { - graphics->drawRectangle(Rectangle(2, - 2, - getWidth() - 4, - getHeight() - 4)); - } - } - } + if (isPressed()) + { + graphics->drawImage(mImage, text_x + 1, text_y + 1); + } + else + { + graphics->drawImage(mImage, text_x, text_y); + + if (isFocused()) + { + graphics->drawRectangle(Rectangle(2, 2, getWidth() - 4, getHeight() - 4)); + } + } + } } diff --git a/external/libguisan/src/widgets/label.cpp b/external/libguisan/src/widgets/label.cpp index a30e034e..8ed76734 100644 --- a/external/libguisan/src/widgets/label.cpp +++ b/external/libguisan/src/widgets/label.cpp @@ -66,90 +66,93 @@ namespace gcn { - Label::Label() - { - mAlignment = Graphics::LEFT; - } + Label::Label() + { + mAlignment = Graphics::LEFT; + } - Label::Label(const std::string& caption) - { - mCaption = caption; - mAlignment = Graphics::LEFT; + Label::Label(const std::string& caption) + { + mCaption = caption; + mAlignment = Graphics::LEFT; - setWidth(getFont()->getWidth(caption)); - setHeight(getFont()->getHeight()); - } + setWidth(getFont()->getWidth(caption)); + setHeight(getFont()->getHeight()); + } - const std::string &Label::getCaption() const - { - return mCaption; - } + const std::string& Label::getCaption() const + { + return mCaption; + } - void Label::setCaption(const std::string& caption) - { - mCaption = caption; - } + void Label::setCaption(const std::string& caption) + { + mCaption = caption; + } - void Label::setAlignment(unsigned int alignment) - { - mAlignment = alignment; - } + void Label::setAlignment(unsigned int alignment) + { + mAlignment = alignment; + } - unsigned int Label::getAlignment() const - { - return mAlignment; - } + unsigned int Label::getAlignment() const + { + return mAlignment; + } - void Label::draw(Graphics* graphics) - { - int text_x; - const auto text_y = getHeight() / 2 - getFont()->getHeight() / 2; + void Label::draw(Graphics* graphics) + { + int text_x; + const auto text_y = getHeight() / 2 - getFont()->getHeight() / 2; - switch (getAlignment()) - { - case Graphics::LEFT: - text_x = 0; - break; - case Graphics::CENTER: - text_x = getWidth() / 2; - break; - case Graphics::RIGHT: - text_x = getWidth(); - break; - default: - throw GCN_EXCEPTION("Unknown alignment."); - } + switch (getAlignment()) + { + case Graphics::LEFT: + text_x = 0; + break; + case Graphics::CENTER: + text_x = getWidth() / 2; + break; + case Graphics::RIGHT: + text_x = getWidth(); + break; + default: + throw GCN_EXCEPTION("Unknown alignment."); + } - graphics->setFont(getFont()); - graphics->setColor(getForegroundColor()); - graphics->drawText(getCaption(), text_x, text_y, getAlignment()); - } + graphics->setFont(getFont()); + auto color = getForegroundColor(); + if (!isEnabled()) + color = color - 0x303030; + graphics->setColor(color); + graphics->drawText(getCaption(), text_x, text_y, getAlignment()); + } - void Label::drawBorder(Graphics* graphics) - { - const auto faceColor = getBaseColor(); - const auto alpha = getBaseColor().a; - const int width = getWidth() + getBorderSize() * 2 - 1; - const int height = getHeight() + getBorderSize() * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + void Label::drawBorder(Graphics* graphics) + { + const auto faceColor = getBaseColor(); + const auto alpha = getBaseColor().a; + const auto width = getWidth() + static_cast(getBorderSize()) * 2 - 1; + const auto height = getHeight() + static_cast(getBorderSize()) * 2 - 1; + auto highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + auto shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - for (int i = 0; i < int(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); - } - } + for (auto i = 0; i < static_cast(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()); - } + void Label::adjustSize() + { + setWidth(getFont()->getWidth(getCaption())); + setHeight(getFont()->getHeight()); + } } diff --git a/external/libguisan/src/widgets/listbox.cpp b/external/libguisan/src/widgets/listbox.cpp index 0b9e644f..061f652a 100644 --- a/external/libguisan/src/widgets/listbox.cpp +++ b/external/libguisan/src/widgets/listbox.cpp @@ -70,278 +70,320 @@ namespace gcn { - ListBox::ListBox() - { - mSelected = -1; - mListModel = NULL; - mWrappingEnabled = false; - setWidth(100); - setFocusable(true); + ListBox::ListBox() + { + mSelected = -1; + mListModel = nullptr; + mWrappingEnabled = false; + Widget::setWidth(100); + setFocusable(true); - addMouseListener(this); - addKeyListener(this); - } + addMouseListener(this); + addKeyListener(this); + } - ListBox::ListBox(ListModel *listModel) - { - mSelected = -1; - mWrappingEnabled = false; - setWidth(100); - setListModel(listModel); - setFocusable(true); + ListBox::ListBox(ListModel* listModel) + { + mSelected = -1; + mWrappingEnabled = false; + Widget::setWidth(100); + setListModel(listModel); + setFocusable(true); - addMouseListener(this); - addKeyListener(this); - } + addMouseListener(this); + addKeyListener(this); + } - void ListBox::draw(Graphics* graphics) - { - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); + void ListBox::draw(Graphics* graphics) + { + graphics->setColor(getBackgroundColor()); + graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - if (mListModel == NULL) - { - return; - } + if (mListModel == nullptr) + { + return; + } - graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); + graphics->setColor(getForegroundColor()); + graphics->setFont(getFont()); - auto y = 0; + // Check the current clip area so we don't draw unnecessary items + // that are not visible. + const auto currentClipArea = graphics->getCurrentClipArea(); + const int rowHeight = getFont()->getHeight(); - const auto fontHeight = getFont()->getHeight(); + // Calculate the number of rows to draw by checking the clip area. + // The addition of two makes covers a partial visible row at the top + // and a partial visible row at the bottom. + auto numberOfRows = currentClipArea.height / rowHeight + 2; - /** - * @todo Check cliprects so we do not have to iterate over elements in the list model - */ - for (auto i = 0; i < mListModel->getNumberOfElements(); ++i) - { - if (i == mSelected) - { - graphics->setColor(getSelectionColor()); - graphics->fillRectangle(Rectangle(0, y, getWidth(), fontHeight)); - graphics->setColor(getForegroundColor()); - } + if (numberOfRows > mListModel->getNumberOfElements()) + { + numberOfRows = mListModel->getNumberOfElements(); + } - graphics->drawText(mListModel->getElementAt(i), 1, y); + // Calculate which row to start drawing. If the list box + // has a negative y coordinate value we should check if + // we should drop rows in the begining of the list as + // they might not be visible. A negative y value is very + // common if the list box for instance resides in a scroll + // area and the user has scrolled the list box downwards. + int startRow; + if (getY() < 0) + { + startRow = -1 * (getY() / rowHeight); + } + else + { + startRow = 0; + } - y += fontHeight; - } - } + const auto inactive_color = Color(170, 170, 170); + + // The y coordinate where we start to draw the text is + // simply the y coordinate multiplied with the font height. + auto y = rowHeight * startRow; + + for (auto i = startRow; i < startRow + numberOfRows; ++i) + { + if (i == mSelected) + { + if (isFocused()) + graphics->setColor(getSelectionColor()); + else + graphics->setColor(inactive_color); + graphics->fillRectangle(Rectangle(0, y, getWidth(), rowHeight)); + graphics->setColor(getForegroundColor()); + } - void ListBox::drawBorder(Graphics* graphics) - { - const auto faceColor = getBaseColor(); - const auto alpha = getBaseColor().a; - const auto width = getWidth() + int(getBorderSize()) * 2 - 1; - const auto height = getHeight() + int(getBorderSize()) * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + // If the row height is greater than the font height we + // draw the text with a center vertical alignment. + if (rowHeight > getFont()->getHeight()) + { + graphics->drawText(mListModel->getElementAt(i), 1, y + rowHeight / 2 - getFont()->getHeight() / 2); + } + else + { + graphics->drawText(mListModel->getElementAt(i), 1, y); + } - for (auto i = 0; i < int(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); - } - } + y += rowHeight; + } + } - void ListBox::logic() - { - adjustSize(); - } + void ListBox::drawBorder(Graphics* graphics) + { + const auto faceColor = getBaseColor(); + const auto alpha = getBaseColor().a; + const auto width = getWidth() + static_cast(getBorderSize()) * 2 - 1; + const auto height = getHeight() + static_cast(getBorderSize()) * 2 - 1; + auto highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + auto shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - int ListBox::getSelected() const - { - return mSelected; - } + for (auto i = 0; i < static_cast(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::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; - } + void ListBox::logic() + { + adjustSize(); + } - auto par = getParent(); - if (par == NULL) - { - return; - } + int ListBox::getSelected() const + { + return mSelected; + } - Rectangle scroll; + void ListBox::setSelected(int selected) + { + if (mListModel == nullptr) + { + mSelected = -1; + } + else + { + if (selected < 0) + { + mSelected = -1; + } + else if (selected >= mListModel->getNumberOfElements()) + { + mSelected = mListModel->getNumberOfElements() - 1; + } + else + { + mSelected = selected; + } - if (mSelected < 0) - { - scroll.y = 0; - } - else - { - scroll.y = getFont()->getHeight() * mSelected; - } + auto* par = getParent(); + if (par == nullptr) + { + return; + } - scroll.height = getFont()->getHeight(); - par->showWidgetPart(this, scroll); - } + Rectangle scroll; - distributeValueChangedEvent(); - } + if (mSelected < 0) + { + scroll.y = 0; + } + else + { + scroll.y = getFont()->getHeight() * mSelected; + } - void ListBox::keyPressed(KeyEvent& keyEvent) - { - Key key = keyEvent.getKey(); + scroll.height = getFont()->getHeight(); + par->showWidgetPart(this, scroll); + } - if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) - { - generateAction(); - keyEvent.consume(); - } - else if (key.getValue() == Key::UP) - { - setSelected(mSelected - 1); + distributeValueChangedEvent(); + } - if (mSelected == -1) - { - if (mWrappingEnabled) - { - setSelected(getListModel()->getNumberOfElements() - 1); - } - else - { - setSelected(0); - } - } - - keyEvent.consume(); - } - else if (key.getValue() == Key::DOWN) - { - if (mWrappingEnabled - && getSelected() == getListModel()->getNumberOfElements() - 1) - { - setSelected(0); - } - else - { - setSelected(getSelected() + 1); - } - - keyEvent.consume(); - } - else if (key.getValue() == Key::HOME) - { - setSelected(0); - keyEvent.consume(); - } - else if (key.getValue() == Key::END) - { - setSelected(getListModel()->getNumberOfElements() - 1); - keyEvent.consume(); - } - } + void ListBox::keyPressed(KeyEvent& keyEvent) + { + const auto key = keyEvent.getKey(); - void ListBox::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - setSelected(mouseEvent.getY() / getFont()->getHeight()); - generateAction(); - } - } + if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) + { + generateAction(); + keyEvent.consume(); + } + else if (key.getValue() == Key::UP) + { + setSelected(mSelected - 1); - void ListBox::mouseWheelMovedUp(MouseEvent& mouseEvent) - { - if (isFocused()) - { - if (getSelected() > 0 ) - { - setSelected(getSelected() - 1); - } + if (mSelected == -1) + { + if (mWrappingEnabled) + { + setSelected(getListModel()->getNumberOfElements() - 1); + } + else + { + setSelected(0); + } + } - mouseEvent.consume(); - } - } + keyEvent.consume(); + } + else if (key.getValue() == Key::DOWN) + { + if (mWrappingEnabled + && getSelected() == getListModel()->getNumberOfElements() - 1) + { + setSelected(0); + } + else + { + setSelected(getSelected() + 1); + } - void ListBox::mouseWheelMovedDown(MouseEvent& mouseEvent) - { - if (isFocused()) - { - setSelected(getSelected() + 1); + keyEvent.consume(); + } + else if (key.getValue() == Key::HOME) + { + setSelected(0); + keyEvent.consume(); + } + else if (key.getValue() == Key::END) + { + setSelected(getListModel()->getNumberOfElements() - 1); + keyEvent.consume(); + } + } - mouseEvent.consume(); - } - } + void ListBox::mousePressed(MouseEvent& mouseEvent) + { + if (mouseEvent.getButton() == MouseEvent::LEFT) + { + setSelected(mouseEvent.getY() / getFont()->getHeight()); + generateAction(); + } + } - void ListBox::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } + void ListBox::mouseWheelMovedUp(MouseEvent& mouseEvent) + { + if (isFocused()) + { + if (getSelected() > 0) + { + setSelected(getSelected() - 1); + } - void ListBox::setListModel(ListModel *listModel) - { - mSelected = -1; - mListModel = listModel; - adjustSize(); - } + mouseEvent.consume(); + } + } - ListModel* ListBox::getListModel() - { - return mListModel; - } + void ListBox::mouseWheelMovedDown(MouseEvent& mouseEvent) + { + if (isFocused()) + { + setSelected(getSelected() + 1); - void ListBox::adjustSize() - { - if (mListModel != NULL) - { - setHeight(getFont()->getHeight() * mListModel->getNumberOfElements()); - } - } + mouseEvent.consume(); + } + } - bool ListBox::isWrappingEnabled() const - { - return mWrappingEnabled; - } + void ListBox::mouseDragged(MouseEvent& mouseEvent) + { + mouseEvent.consume(); + } - void ListBox::setWrappingEnabled(bool wrappingEnabled) - { - mWrappingEnabled = wrappingEnabled; - } - - void ListBox::addSelectionListener(SelectionListener* selectionListener) - { - mSelectionListeners.push_back(selectionListener); - } - - void ListBox::removeSelectionListener(SelectionListener* selectionListener) - { - mSelectionListeners.remove(selectionListener); - } + void ListBox::setListModel(ListModel* listModel) + { + mSelected = -1; + mListModel = listModel; + adjustSize(); + } - void ListBox::distributeValueChangedEvent() - { - for (auto& mSelectionListener : mSelectionListeners) - { - SelectionEvent event(this); - mSelectionListener->valueChanged(event); - } - } + ListModel* ListBox::getListModel() const + { + return mListModel; + } + + void ListBox::adjustSize() + { + if (mListModel != nullptr) + { + setHeight(getFont()->getHeight() * mListModel->getNumberOfElements()); + } + } + + bool ListBox::isWrappingEnabled() const + { + return mWrappingEnabled; + } + + void ListBox::setWrappingEnabled(bool wrappingEnabled) + { + mWrappingEnabled = wrappingEnabled; + } + + void ListBox::addSelectionListener(SelectionListener* selectionListener) + { + mSelectionListeners.push_back(selectionListener); + } + + void ListBox::removeSelectionListener(SelectionListener* selectionListener) + { + mSelectionListeners.remove(selectionListener); + } + + void ListBox::distributeValueChangedEvent() + { + for (auto& mSelectionListener : mSelectionListeners) + { + SelectionEvent event(this); + mSelectionListener->valueChanged(event); + } + } } diff --git a/external/libguisan/src/widgets/progressbar.cpp b/external/libguisan/src/widgets/progressbar.cpp index ee026473..26b07308 100644 --- a/external/libguisan/src/widgets/progressbar.cpp +++ b/external/libguisan/src/widgets/progressbar.cpp @@ -66,198 +66,201 @@ namespace gcn { - ProgressBar::ProgressBar() : Label() - { - mAlignment = Graphics::CENTER; - mStart = 0; - mValue = 0; - mEnd = 100; - - setHeight(getFont()->getHeight()); - setBorderSize(1); - } - - ProgressBar::ProgressBar(const unsigned int start, - const unsigned int end, const unsigned int value) : Label() - { - mAlignment = Graphics::CENTER; - - if(start > end) - { - mStart = end; - mEnd = start; - } - else - { - mStart = start; - mEnd = end; - } - - if((value >= start && value <= end) || (start == 0 && end == 0)) - { - mValue = value; - } - else - { - mValue = start; - } - - setHeight(getFont()->getHeight()); - setBorderSize(1); - } + ProgressBar::ProgressBar() : Label() + { + mAlignment = Graphics::CENTER; + mStart = 0; + mValue = 0; + mEnd = 100; - ProgressBar::ProgressBar(const std::string& caption) : Label(caption) - { - mCaption = caption; - mAlignment = Graphics::CENTER; + setHeight(getFont()->getHeight()); + setBorderSize(1); + } - setHeight(getFont()->getHeight()); - setBorderSize(1); - } + ProgressBar::ProgressBar(const unsigned int start, + const unsigned int end, const unsigned int value) : Label() + { + mAlignment = Graphics::CENTER; - const std::string &ProgressBar::getCaption() const - { - return mCaption; - } + if (start > end) + { + mStart = end; + mEnd = start; + } + else + { + mStart = start; + mEnd = end; + } - void ProgressBar::setCaption(const std::string& caption) - { - mCaption = caption; - } + if ((value >= start && value <= end) || (start == 0 && end == 0)) + { + mValue = value; + } + else + { + mValue = start; + } - void ProgressBar::setAlignment(unsigned int alignment) - { - mAlignment = alignment; - } + setHeight(getFont()->getHeight()); + setBorderSize(1); + } - unsigned int ProgressBar::getAlignment() const - { - return mAlignment; - } + ProgressBar::ProgressBar(const std::string& caption) : Label(caption) + { + mCaption = caption; + mAlignment = Graphics::CENTER; - void ProgressBar::draw(Graphics* graphics) - { - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - - int text_x; - const auto text_y = getHeight() / 2 - getFont()->getHeight() / 2; - - graphics->setColor(getSelectionColor()); - int progress_width; - if(mStart == 0 && mEnd == 0) - { - // Infinite scrollbar - progress_width = getWidth() / 5; - const auto bar_x = getWidth() * int(mValue) / 100; - - if(bar_x + progress_width > getWidth()) - { - graphics->fillRectangle(Rectangle(bar_x, 0, getWidth() - bar_x, getHeight())); - graphics->fillRectangle(Rectangle(0, 0, progress_width - (getWidth() - bar_x), getHeight())); - } - else - { - graphics->fillRectangle(Rectangle(bar_x,0,progress_width,getHeight())); - } - } - else - { - // Standard scrollbar - progress_width = getWidth() * int(mValue) / int(mEnd - mStart); - graphics->fillRectangle(Rectangle(0,0,progress_width,getHeight())); - } + setHeight(getFont()->getHeight()); + setBorderSize(1); + } - switch (getAlignment()) - { - case Graphics::LEFT: - text_x = 0; - break; - case Graphics::CENTER: - text_x = getWidth() / 2; - break; - case Graphics::RIGHT: - text_x = getWidth(); - break; - default: - throw GCN_EXCEPTION("Unknown alignment."); - } + const std::string& ProgressBar::getCaption() const + { + return mCaption; + } - graphics->setFont(getFont()); - graphics->setColor(getForegroundColor()); - graphics->drawText(getCaption(), text_x, text_y, getAlignment()); - } + void ProgressBar::setCaption(const std::string& caption) + { + mCaption = caption; + } - void ProgressBar::drawBorder(Graphics* graphics) - { - const auto faceColor = getBaseColor(); - const auto alpha = getBaseColor().a; - const auto width = getWidth() + int(getBorderSize()) * 2 - 1; - const auto height = getHeight() + int(getBorderSize()) * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + void ProgressBar::setAlignment(unsigned int alignment) + { + mAlignment = alignment; + } - for (int i = 0; i < int(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); - } - } + unsigned int ProgressBar::getAlignment() const + { + return mAlignment; + } - void ProgressBar::adjustSize() - { - setHeight(getFont()->getHeight()); - } - - void ProgressBar::setStart(const unsigned int start) - { - if(start <= mEnd) - { - mStart = start; - } - } - - unsigned int ProgressBar::getStart() const - { - return mStart; - } - - void ProgressBar::setEnd(const unsigned int end) - { - if(end >= mStart) - { - mEnd = end; - } - } - - unsigned int ProgressBar::getEnd() const - { - return mEnd; - } - - void ProgressBar::setValue(const unsigned int value) - { - if(value >= mStart && value <= mEnd) - { - mValue = value; - } - else - { - if(mStart == 0 && mEnd == 0) - { - mValue = value % 100; - } - } - } - - unsigned int ProgressBar::getValue() const - { - return mValue; - } + void ProgressBar::draw(Graphics* graphics) + { + graphics->setColor(getBackgroundColor()); + graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); + + int text_x; + const auto text_y = getHeight() / 2 - getFont()->getHeight() / 2; + + graphics->setColor(getSelectionColor()); + int progress_width; + if (mStart == 0 && mEnd == 0) + { + // Infinite scrollbar + progress_width = getWidth() / 5; + const auto bar_x = getWidth() * static_cast(mValue) / 100; + + if (bar_x + progress_width > getWidth()) + { + graphics->fillRectangle(Rectangle(bar_x, 0, getWidth() - bar_x, getHeight())); + graphics->fillRectangle(Rectangle(0, 0, progress_width - (getWidth() - bar_x), getHeight())); + } + else + { + graphics->fillRectangle(Rectangle(bar_x, 0, progress_width, getHeight())); + } + } + else + { + // Standard scrollbar + progress_width = getWidth() * static_cast(mValue) / static_cast(mEnd - mStart); + graphics->fillRectangle(Rectangle(0, 0, progress_width, getHeight())); + } + + switch (getAlignment()) + { + case Graphics::LEFT: + text_x = 0; + break; + case Graphics::CENTER: + text_x = getWidth() / 2; + break; + case Graphics::RIGHT: + text_x = getWidth(); + break; + default: + throw GCN_EXCEPTION("Unknown alignment."); + } + + graphics->setFont(getFont()); + auto color = getForegroundColor(); + if (!isEnabled()) + color = color - 0x303030; + graphics->setColor(color); + graphics->drawText(getCaption(), text_x, text_y, getAlignment()); + } + + void ProgressBar::drawBorder(Graphics* graphics) + { + const auto faceColor = getBaseColor(); + const auto alpha = getBaseColor().a; + const auto width = getWidth() + static_cast(getBorderSize()) * 2 - 1; + const auto height = getHeight() + static_cast(getBorderSize()) * 2 - 1; + auto highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + auto shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + for (int i = 0; i < static_cast(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 ProgressBar::adjustSize() + { + setHeight(getFont()->getHeight()); + } + + void ProgressBar::setStart(const unsigned int start) + { + if (start <= mEnd) + { + mStart = start; + } + } + + unsigned int ProgressBar::getStart() const + { + return mStart; + } + + void ProgressBar::setEnd(const unsigned int end) + { + if (end >= mStart) + { + mEnd = end; + } + } + + unsigned int ProgressBar::getEnd() const + { + return mEnd; + } + + void ProgressBar::setValue(const unsigned int value) + { + if (value >= mStart && value <= mEnd) + { + mValue = value; + } + else + { + if (mStart == 0 && mEnd == 0) + { + mValue = value % 100; + } + } + } + + unsigned int ProgressBar::getValue() const + { + return mValue; + } } diff --git a/external/libguisan/src/widgets/radiobutton.cpp b/external/libguisan/src/widgets/radiobutton.cpp index a64a3546..73f14072 100644 --- a/external/libguisan/src/widgets/radiobutton.cpp +++ b/external/libguisan/src/widgets/radiobutton.cpp @@ -67,265 +67,248 @@ namespace gcn { - RadioButton::GroupMap RadioButton::mGroupMap; + RadioButton::GroupMap RadioButton::mGroupMap; - RadioButton::RadioButton() - { - setSelected(false); + RadioButton::RadioButton() + { + setSelected(false); - setFocusable(true); - addMouseListener(this); - addKeyListener(this); - } + setFocusable(true); + addMouseListener(this); + addKeyListener(this); + } - RadioButton::RadioButton(const std::string &caption, - const std::string &group, - bool selected) - { - setCaption(caption); - setGroup(group); - setSelected(selected); + RadioButton::RadioButton(const std::string& caption, + const std::string& group, + bool selected) + { + setCaption(caption); + setGroup(group); + setSelected(selected); - setFocusable(true); - addMouseListener(this); - addKeyListener(this); + setFocusable(true); + addMouseListener(this); + addKeyListener(this); - adjustSize(); - } + adjustSize(); + } - RadioButton::~RadioButton() - { - // Remove us from the group list - setGroup(""); - } + RadioButton::~RadioButton() + { + // Remove us from the group list + setGroup(""); + } - void RadioButton::draw(Graphics* graphics) - { - graphics->pushClipArea(Rectangle(1, - 1, - getWidth() - 1, - getHeight() - 1)); - drawBox(graphics); - graphics->popClipArea(); + void RadioButton::draw(Graphics* graphics) + { + graphics->pushClipArea(Rectangle(1, + 1, + getWidth() - 1, + getHeight() - 1)); + drawBox(graphics); + graphics->popClipArea(); - - graphics->setFont(getFont()); - graphics->setColor(getForegroundColor()); - if (isFocused()) - { - int fh; - - if (getHeight()%2 == 0) - { - fh = getHeight() - 4; - } - else - { - fh = getHeight() - 3; - } + graphics->setFont(getFont()); + graphics->setColor(getForegroundColor()); - const auto hh = (fh + 1) / 2; - - graphics->drawLine(0, hh + 1, hh + 1, 0); - graphics->drawLine(hh + 2, 1, fh + 2, hh + 1); - graphics->drawLine(fh + 1, hh + 2, hh + 1, fh + 2); - graphics->drawLine(hh + 1, fh + 2, 1, hh + 2); - } + if (isFocused()) + { + graphics->drawRectangle(Rectangle(0,0, getWidth(), getHeight())); + } - const auto h = getHeight() + getHeight() / 2; + const auto h = getHeight() + getHeight() / 2; - graphics->drawText(getCaption(), h - 2, 0); - } + graphics->drawText(getCaption(), h - 2, 0); + } - void RadioButton::drawBorder(Graphics* graphics) - { - const auto faceColor = getBaseColor(); - const auto alpha = getBaseColor().a; - const auto width = getWidth() + int(getBorderSize()) * 2 - 1; - const auto height = getHeight() + int(getBorderSize()) * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + void RadioButton::drawBorder(Graphics* graphics) + { + const auto faceColor = getBaseColor(); + const auto alpha = getBaseColor().a; + const auto width = getWidth() + static_cast(getBorderSize()) * 2 - 1; + const auto height = getHeight() + static_cast(getBorderSize()) * 2 - 1; + auto highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + auto shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - for (int i = 0; i < int(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); - } - } + for (int i = 0; i < static_cast(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; + void RadioButton::drawBox(Graphics* graphics) + { + int h; - if (getHeight()%2 == 0) - { - h = getHeight() - 4; - } - else - { - h = getHeight() - 3; - } + if (getHeight() % 2 == 0) + { + h = getHeight() - 4; + } + else + { + h = getHeight() - 3; + } - const auto alpha = getBaseColor().a; - auto faceColor = getBaseColor(); - faceColor.a = alpha; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + const auto alpha = getBaseColor().a; + auto faceColor = getBaseColor(); + faceColor.a = alpha; + auto highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + auto shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - graphics->setColor(getBackgroundColor()); + graphics->setColor(getBackgroundColor()); - int i; - const auto hh = (h + 1) / 2; + int i; + const auto 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, + i, + hh + i - 1, + i); + } - for (i = 1; i < hh; ++i) - { - graphics->drawLine(hh - i + 1, - h - i, - hh + i - 1, - h - 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(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(highlightColor); + graphics->drawLine(1, hh + 1, hh, h); + graphics->drawLine(hh + 1, h - 1, h, hh); - graphics->setColor(getForegroundColor()); + graphics->setColor(getForegroundColor()); - const auto hhh = hh - 3; - if (mSelected) - { - for (i = 0; i < hhh; ++i) - { - graphics->drawLine(hh - i, 4 + i, hh + i, 4 + i); - } - for (i = 0; i < hhh; ++i) - { - graphics->drawLine(hh - i, h - 4 - i, hh + i, h - 4 - i); - } + const auto hhh = hh - 3; + if (mSelected) + { + for (i = 0; i < hhh; ++i) + { + graphics->drawLine(hh - i, 4 + i, hh + i, 4 + i); + } + for (i = 0; i < hhh; ++i) + { + graphics->drawLine(hh - i, h - 4 - i, hh + i, h - 4 - i); + } + } + } - } - } + bool RadioButton::isSelected() const + { + return mSelected; + } - bool RadioButton::isSelected() const - { - return mSelected; - } + void RadioButton::setSelected(bool selected) + { + if (selected && !mGroup.empty()) + { + const auto iterEnd = mGroupMap.upper_bound(mGroup); - void RadioButton::setSelected(bool selected) - { - if (selected && !mGroup.empty()) - { - const auto iterEnd = mGroupMap.upper_bound(mGroup); + for (auto iter = mGroupMap.lower_bound(mGroup); + iter != iterEnd; + ++iter) + { + if (iter->second->isSelected()) + { + iter->second->setSelected(false); + } + } + } - for (auto iter = mGroupMap.lower_bound(mGroup); - iter != iterEnd; - ++iter) - { - if (iter->second->isSelected()) - { - iter->second->setSelected(false); - } - } - } + mSelected = selected; + } - mSelected = selected; - } + const std::string& RadioButton::getCaption() const + { + return mCaption; + } - const std::string &RadioButton::getCaption() const - { - return mCaption; - } + void RadioButton::setCaption(const std::string caption) + { + mCaption = caption; + } - void RadioButton::setCaption(const std::string caption) - { - mCaption = caption; - } + void RadioButton::keyPressed(KeyEvent& keyEvent) + { + const auto key = keyEvent.getKey(); - void RadioButton::keyPressed(KeyEvent& keyEvent) - { - const auto key = keyEvent.getKey(); + if (key.getValue() == Key::ENTER || + key.getValue() == Key::SPACE) + { + setSelected(true); + generateAction(); + keyEvent.consume(); + } + } - if (key.getValue() == Key::ENTER || - key.getValue() == Key::SPACE) - { - setSelected(true); - generateAction(); - keyEvent.consume(); - } - } + void RadioButton::mouseClicked(MouseEvent& mouseEvent) + { + if (mouseEvent.getButton() == MouseEvent::LEFT) + { + setSelected(true); + generateAction(); + } + } - void RadioButton::mouseClicked(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - setSelected(true); - generateAction(); - } - } + void RadioButton::mouseDragged(MouseEvent& mouseEvent) + { + mouseEvent.consume(); + } - void RadioButton::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } + void RadioButton::setGroup(const std::string& group) + { + if (!mGroup.empty()) + { + const auto iterEnd = mGroupMap.upper_bound(mGroup); - void RadioButton::setGroup(const std::string &group) - { - if (!mGroup.empty()) - { - const auto iterEnd = mGroupMap.upper_bound(mGroup); + for (auto iter = mGroupMap.lower_bound(mGroup); + iter != iterEnd; + ++iter) + { + if (iter->second == this) + { + mGroupMap.erase(iter); + break; + } + } + } - for (auto iter = mGroupMap.lower_bound(mGroup); - iter != iterEnd; - ++iter) - { - if (iter->second == this) - { - mGroupMap.erase(iter); - break; - } - } - } + if (!group.empty()) + { + mGroupMap.insert( + std::pair(group, this)); + } - if (!group.empty()) - { - mGroupMap.insert( - std::pair(group, this)); - } + mGroup = group; + } - mGroup = group; - } + const std::string& RadioButton::getGroup() const + { + return mGroup; + } - const std::string &RadioButton::getGroup() const - { - return mGroup; - } + void RadioButton::adjustSize() + { + const auto height = getFont()->getHeight(); - void RadioButton::adjustSize() - { - const auto height = getFont()->getHeight(); - - setHeight(height); - setWidth(getFont()->getWidth(getCaption()) + height + height/2); - } + setHeight(height); + setWidth(getFont()->getWidth(getCaption()) + height + height / 2); + } } diff --git a/external/libguisan/src/widgets/scrollarea.cpp b/external/libguisan/src/widgets/scrollarea.cpp index 2ec233d9..1c1a2be0 100644 --- a/external/libguisan/src/widgets/scrollarea.cpp +++ b/external/libguisan/src/widgets/scrollarea.cpp @@ -65,1200 +65,1200 @@ namespace gcn { - ScrollArea::ScrollArea() - { - mVScroll = 0; - mHScroll = 0; - mHPolicy = SHOW_AUTO; - mVPolicy = SHOW_AUTO; - mScrollbarWidth = 12; - mUpButtonPressed = false; - mDownButtonPressed = false; - mLeftButtonPressed = false; - mRightButtonPressed = false; - mUpButtonScrollAmount = 10; - mDownButtonScrollAmount = 10; - mLeftButtonScrollAmount = 10; - mRightButtonScrollAmount = 10; - mIsVerticalMarkerDragged = false; - mIsHorizontalMarkerDragged =false; - - addMouseListener(this); - } - - ScrollArea::ScrollArea(Widget *content) - { - mVScroll = 0; - mHScroll = 0; - mHPolicy = SHOW_AUTO; - mVPolicy = SHOW_AUTO; - mScrollbarWidth = 12; - mUpButtonPressed = false; - mDownButtonPressed = false; - mLeftButtonPressed = false; - mRightButtonPressed = false; - mUpButtonScrollAmount = 10; - mDownButtonScrollAmount = 10; - mLeftButtonScrollAmount = 10; - mRightButtonScrollAmount = 10; - mIsVerticalMarkerDragged = false; - mIsHorizontalMarkerDragged =false; - - setContent(content); - addMouseListener(this); - } - - ScrollArea::ScrollArea(Widget *content, unsigned int hPolicy, unsigned int vPolicy) - { - mVScroll = 0; - mHScroll = 0; - mHPolicy = hPolicy; - mVPolicy = vPolicy; - mScrollbarWidth = 12; - mUpButtonPressed = false; - mDownButtonPressed = false; - mLeftButtonPressed = false; - mRightButtonPressed = false; - mUpButtonScrollAmount = 10; - mDownButtonScrollAmount = 10; - mLeftButtonScrollAmount = 10; - mRightButtonScrollAmount = 10; - mIsVerticalMarkerDragged = false; - mIsHorizontalMarkerDragged =false; - - setContent(content); - addMouseListener(this); - } - - ScrollArea::~ScrollArea() - { - setContent(NULL); - } - - void ScrollArea::setContent(Widget* widget) - { - if (widget != NULL) - { - clear(); - add(widget); - widget->setPosition(0,0); - } - else - { - clear(); - } - - checkPolicies(); - } - - Widget* ScrollArea::getContent() - { - if (!mWidgets.empty()) - { - return *mWidgets.begin(); - } - - return NULL; - } - - void ScrollArea::setHorizontalScrollPolicy(unsigned int hPolicy) - { - mHPolicy = hPolicy; - checkPolicies(); - } - - unsigned int ScrollArea::getHorizontalScrollPolicy() const - { - return mHPolicy; - } - - void ScrollArea::setVerticalScrollPolicy(unsigned int vPolicy) - { - mVPolicy = vPolicy; - checkPolicies(); - } - - unsigned int ScrollArea::getVerticalScrollPolicy() const - { - return mVPolicy; - } - - void ScrollArea::setScrollPolicy(unsigned int hPolicy, unsigned int vPolicy) - { - mHPolicy = hPolicy; - mVPolicy = vPolicy; - checkPolicies(); - } - - void ScrollArea::setVerticalScrollAmount(int vScroll) - { - const auto max = getVerticalMaxScroll(); - - mVScroll = vScroll; - - if (vScroll > max) - { - mVScroll = max; - } - - if (vScroll < 0) - { - mVScroll = 0; - } - } - - int ScrollArea::getVerticalScrollAmount() const - { - return mVScroll; - } - - void ScrollArea::setHorizontalScrollAmount(int hScroll) - { - const auto max = getHorizontalMaxScroll(); - - mHScroll = hScroll; - - if (hScroll > max) - { - mHScroll = max; - } - else if (hScroll < 0) - { - mHScroll = 0; - } - } - - int ScrollArea::getHorizontalScrollAmount() const - { - return mHScroll; - } - - void ScrollArea::setScrollAmount(int hScroll, int vScroll) - { - setHorizontalScrollAmount(hScroll); - setVerticalScrollAmount(vScroll); - } - - int ScrollArea::getHorizontalMaxScroll() - { - checkPolicies(); - - if (getContent() == NULL) - { - return 0; - } - - const auto value = getContent()->getWidth() - getChildrenArea().width + - 2 * int(getContent()->getBorderSize()); - - if (value < 0) - { - return 0; - } - - return value; - } - - int ScrollArea::getVerticalMaxScroll() - { - checkPolicies(); - - if (getContent() == NULL) - { - return 0; - } - - const auto value = getContent()->getHeight() - getChildrenArea().height + - 2 * int(getContent()->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."); - } - } - - int ScrollArea::getScrollbarWidth() const - { - return mScrollbarWidth; - } - - void ScrollArea::mousePressed(MouseEvent& mouseEvent) - { - const auto x = mouseEvent.getX(); - const auto y = mouseEvent.getY(); - - if (getUpButtonDimension().isPointInRect(x, y)) - { - setVerticalScrollAmount(getVerticalScrollAmount() - - mUpButtonScrollAmount); - mUpButtonPressed = true; - } - else if (getDownButtonDimension().isPointInRect(x, y)) - { - setVerticalScrollAmount(getVerticalScrollAmount() - + mDownButtonScrollAmount); - mDownButtonPressed = true; - } - else if (getLeftButtonDimension().isPointInRect(x, y)) - { - setHorizontalScrollAmount(getHorizontalScrollAmount() - - mLeftButtonScrollAmount); - mLeftButtonPressed = true; - } - else if (getRightButtonDimension().isPointInRect(x, y)) - { - setHorizontalScrollAmount(getHorizontalScrollAmount() - + mRightButtonScrollAmount); - mRightButtonPressed = true; - } - else if (getVerticalMarkerDimension().isPointInRect(x, y)) - { - mIsHorizontalMarkerDragged = false; - mIsVerticalMarkerDragged = true; - - mVerticalMarkerDragOffset = y - getVerticalMarkerDimension().y; - } - else if (getVerticalBarDimension().isPointInRect(x,y)) - { - if (y < getVerticalMarkerDimension().y) - { - setVerticalScrollAmount(getVerticalScrollAmount() - - int(getChildrenArea().height * 0.95)); - } - else - { - setVerticalScrollAmount(getVerticalScrollAmount() - + int(getChildrenArea().height * 0.95)); - } - } - else if (getHorizontalMarkerDimension().isPointInRect(x, y)) - { - mIsHorizontalMarkerDragged = true; - mIsVerticalMarkerDragged = false; - - mHorizontalMarkerDragOffset = x - getHorizontalMarkerDimension().x; - } - else if (getHorizontalBarDimension().isPointInRect(x,y)) - { - if (x < getHorizontalMarkerDimension().x) - { - setHorizontalScrollAmount(getHorizontalScrollAmount() - - int(getChildrenArea().width * 0.95)); - } - else - { - setHorizontalScrollAmount(getHorizontalScrollAmount() - + int(getChildrenArea().width * 0.95)); - } - } - } - - void ScrollArea::mouseReleased(MouseEvent& mouseEvent) - { - mUpButtonPressed = false; - mDownButtonPressed = false; - mLeftButtonPressed = false; - mRightButtonPressed = false; - mIsHorizontalMarkerDragged = false; - mIsVerticalMarkerDragged = false; - - mouseEvent.consume(); - } - - void ScrollArea::mouseDragged(MouseEvent& mouseEvent) - { - if (mIsVerticalMarkerDragged) - { - const auto pos = mouseEvent.getY() - getVerticalBarDimension().y - mVerticalMarkerDragOffset; - const auto length = getVerticalMarkerDimension().height; - - const auto barDim = getVerticalBarDimension(); - - if ((barDim.height - length) > 0) - { - setVerticalScrollAmount((getVerticalMaxScroll() * pos) - / (barDim.height - length)); - } - else - { - setVerticalScrollAmount(0); - } - } - - if (mIsHorizontalMarkerDragged) - { - const auto pos = mouseEvent.getX() - getHorizontalBarDimension().x - mHorizontalMarkerDragOffset; - const auto length = getHorizontalMarkerDimension().width; - - const auto barDim = getHorizontalBarDimension(); - - if ((barDim.width - length) > 0) - { - setHorizontalScrollAmount((getHorizontalMaxScroll() * pos) - / (barDim.width - length)); - } - else - { - setHorizontalScrollAmount(0); - } - } - - mouseEvent.consume(); - } - - void ScrollArea::draw(Graphics *graphics) - { - drawBackground(graphics); - - if (mVBarVisible) - { - drawUpButton(graphics); - drawDownButton(graphics); - drawVBar(graphics); - drawVMarker(graphics); - } - - if (mHBarVisible) - { - drawLeftButton(graphics); - drawRightButton(graphics); - drawHBar(graphics); - drawHMarker(graphics); - } - - if (mHBarVisible && mVBarVisible) - { - graphics->setColor(getBaseColor()); - graphics->fillRectangle(Rectangle(getWidth() - mScrollbarWidth, - getHeight() - mScrollbarWidth, - mScrollbarWidth, - mScrollbarWidth)); - } - - drawChildren(graphics); - } - - void ScrollArea::drawBorder(Graphics* graphics) - { - const auto faceColor = getBaseColor(); - const auto alpha = getBaseColor().a; - const auto width = getWidth() + int(getBorderSize()) * 2 - 1; - const auto height = getHeight() + int(getBorderSize()) * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - for (auto i = 0; i < int(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) - { - const auto dim = getHorizontalBarDimension(); - - graphics->pushClipArea(dim); - - const auto alpha = getBaseColor().a; - auto trackColor = getBaseColor() - 0x101010; - trackColor.a = alpha; - auto 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) - { - const auto dim = getVerticalBarDimension(); - - graphics->pushClipArea(dim); - - const auto alpha = getBaseColor().a; - auto trackColor = getBaseColor() - 0x101010; - trackColor.a = alpha; - auto shadowColor = getBaseColor() - 0x303030; - shadowColor.a = alpha; - - graphics->setColor(trackColor); - graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); - - graphics->setColor(shadowColor); - graphics->drawLine(0, 0, 0, dim.height); - - graphics->popClipArea(); - } - - void ScrollArea::drawBackground(Graphics *graphics) - { - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(getChildrenArea()); - } - - void ScrollArea::drawUpButton(Graphics* graphics) - { - const auto dim = getUpButtonDimension(); - graphics->pushClipArea(dim); - - Color highlightColor; - Color shadowColor; - Color faceColor; - int offset; - const auto 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()); - - const auto w = dim.height / 2; - const auto h = w / 2 + 2; - for (auto 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) - { - const auto dim = getDownButtonDimension(); - graphics->pushClipArea(dim); - - Color highlightColor; - Color shadowColor; - Color faceColor; - int offset; - const auto 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()); - - const auto w = dim.height / 2; - const auto h = w + 1; - for (auto 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) - { - const auto dim = getLeftButtonDimension(); - graphics->pushClipArea(dim); - - Color highlightColor; - Color shadowColor; - Color faceColor; - int offset; - const auto 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()); - - const auto w = dim.width / 2; - const auto h = w - 2; - for (auto 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) - { - const auto dim = getRightButtonDimension(); - graphics->pushClipArea(dim); - - Color highlightColor; - Color shadowColor; - Color faceColor; - int offset; - const auto 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()); - - const auto w = dim.width / 2; - const auto h = w + 1; - for (auto 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) - { - const auto dim = getVerticalMarkerDimension(); - graphics->pushClipArea(dim); - - const auto alpha = getBaseColor().a; - auto faceColor = getBaseColor(); - faceColor.a = alpha; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto 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) - { - const auto dim = getHorizontalMarkerDimension(); - graphics->pushClipArea(dim); - - const auto alpha = getBaseColor().a; - auto faceColor = getBaseColor(); - faceColor.a = alpha; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(1, 1, dim.width - 1, dim.height - 1)); - - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, dim.width - 1, 0); - graphics->drawLine(0, 1, 0, dim.height - 1); - - graphics->setColor(shadowColor); - graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); - graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); - - graphics->popClipArea(); - } - - void ScrollArea::logic() - { - checkPolicies(); - - setVerticalScrollAmount(getVerticalScrollAmount()); - setHorizontalScrollAmount(getHorizontalScrollAmount()); - - if (getContent() != NULL) - { - getContent()->setPosition(-mHScroll + int(getContent()->getBorderSize()), - -mVScroll + int(getContent()->getBorderSize())); - getContent()->logic(); - } - } - - void ScrollArea::checkPolicies() - { - const auto w = getWidth(); - const auto h = getHeight(); - - mHBarVisible = false; - mVBarVisible = false; - - - if (!getContent()) - { - mHBarVisible = (mHPolicy == SHOW_ALWAYS); - mVBarVisible = (mVPolicy == SHOW_ALWAYS); - return; - } - - if (mHPolicy == SHOW_AUTO && - mVPolicy == SHOW_AUTO) - { - if (getContent()->getWidth() <= w - && getContent()->getHeight() <= h) - { - mHBarVisible = false; - mVBarVisible = false; - } - - if (getContent()->getWidth() > w) - { - mHBarVisible = true; - } - - if ((getContent()->getHeight() > h) - || (mHBarVisible && getContent()->getHeight() > h - mScrollbarWidth)) - { - mVBarVisible = true; - } - - if (mVBarVisible && getContent()->getWidth() > w - mScrollbarWidth) - { - mHBarVisible = true; - } - - return; - } - - switch (mHPolicy) - { - case SHOW_NEVER: - mHBarVisible = false; - break; - - case SHOW_ALWAYS: - mHBarVisible = true; - break; - - case SHOW_AUTO: - if (mVPolicy == SHOW_NEVER) - { - mHBarVisible = getContent()->getWidth() > w; - } - else // (mVPolicy == SHOW_ALWAYS) - { - mHBarVisible = getContent()->getWidth() > w - mScrollbarWidth; - } - break; - - default: - throw GCN_EXCEPTION("Horizontal scroll policy invalid."); - } - - switch (mVPolicy) - { - case SHOW_NEVER: - mVBarVisible = false; - break; - - case SHOW_ALWAYS: - mVBarVisible = true; - break; - - case SHOW_AUTO: - if (mHPolicy == SHOW_NEVER) - { - mVBarVisible = getContent()->getHeight() > h; - } - else // (mHPolicy == SHOW_ALWAYS) - { - mVBarVisible = getContent()->getHeight() > h - mScrollbarWidth; - } - break; - default: - throw GCN_EXCEPTION("Vertical scroll policy invalid."); - } - } - - Rectangle ScrollArea::getUpButtonDimension() - { - 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::getChildrenArea() - { - 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; - const auto barDim = getVerticalBarDimension(); - - if (getContent() && getContent()->getHeight() != 0) - { - length = (barDim.height * getChildrenArea().height) - / getContent()->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; - const auto barDim = getHorizontalBarDimension(); - - if (getContent() && getContent()->getWidth() != 0) - { - length = (barDim.width * getChildrenArea().width) - / getContent()->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::showWidgetPart(Widget* widget, Rectangle area) - { - if (widget != getContent()) - { - throw GCN_EXCEPTION("Widget not content widget"); - } - - BasicContainer::showWidgetPart(widget, area); - - setHorizontalScrollAmount(int(getContent()->getBorderSize() - getContent()->getX())); - setVerticalScrollAmount(int(getContent()->getBorderSize() - getContent()->getY())); - } - - Widget *ScrollArea::getWidgetAt(int x, int y) - { - if (getChildrenArea().isPointInRect(x, y)) - { - return getContent(); - } - - return NULL; - } - - void ScrollArea::mouseWheelMovedUp(MouseEvent& mouseEvent) - { - if (mouseEvent.isConsumed()) - { - return; - } - - setVerticalScrollAmount(getVerticalScrollAmount() - getChildrenArea().height / 8); - - mouseEvent.consume(); - } - - void ScrollArea::mouseWheelMovedDown(MouseEvent& mouseEvent) - { - if (mouseEvent.isConsumed()) - { - return; - } - - setVerticalScrollAmount(getVerticalScrollAmount() + getChildrenArea().height / 8); - - mouseEvent.consume(); - } - - void ScrollArea::setWidth(int width) - { - Widget::setWidth(width); - checkPolicies(); - } - - void ScrollArea::setHeight(int height) - { - Widget::setHeight(height); - checkPolicies(); - } - - void ScrollArea::setDimension(const Rectangle& dimension) - { - Widget::setDimension(dimension); - checkPolicies(); - } - - void ScrollArea::setLeftButtonScrollAmount(int amount) - { - mLeftButtonScrollAmount = amount; - } - - void ScrollArea::setRightButtonScrollAmount(int amount) - { - mRightButtonScrollAmount = amount; - } - - void ScrollArea::setUpButtonScrollAmount(int amount) - { - mUpButtonScrollAmount = amount; - } - - void ScrollArea::setDownButtonScrollAmount(int amount) - { - mDownButtonScrollAmount = amount; - } - - int ScrollArea::getLeftButtonScrollAmount() const - { - return mLeftButtonScrollAmount; - } - - int ScrollArea::getRightButtonScrollAmount() const - { - return mRightButtonScrollAmount; - } - - int ScrollArea::getUpButtonScrollAmount() const - { - return mUpButtonScrollAmount; - } - - int ScrollArea::getDownButtonScrollAmount() const - { - return mDownButtonScrollAmount; - } + ScrollArea::ScrollArea() + { + mVScroll = 0; + mHScroll = 0; + mHPolicy = SHOW_AUTO; + mVPolicy = SHOW_AUTO; + mScrollbarWidth = 12; + mUpButtonPressed = false; + mDownButtonPressed = false; + mLeftButtonPressed = false; + mRightButtonPressed = false; + mUpButtonScrollAmount = 10; + mDownButtonScrollAmount = 10; + mLeftButtonScrollAmount = 10; + mRightButtonScrollAmount = 10; + mIsVerticalMarkerDragged = false; + mIsHorizontalMarkerDragged = false; + + addMouseListener(this); + } + + ScrollArea::ScrollArea(Widget* content) + { + mVScroll = 0; + mHScroll = 0; + mHPolicy = SHOW_AUTO; + mVPolicy = SHOW_AUTO; + mScrollbarWidth = 12; + mUpButtonPressed = false; + mDownButtonPressed = false; + mLeftButtonPressed = false; + mRightButtonPressed = false; + mUpButtonScrollAmount = 10; + mDownButtonScrollAmount = 10; + mLeftButtonScrollAmount = 10; + mRightButtonScrollAmount = 10; + mIsVerticalMarkerDragged = false; + mIsHorizontalMarkerDragged = false; + + setContent(content); + addMouseListener(this); + } + + ScrollArea::ScrollArea(Widget* content, unsigned int hPolicy, unsigned int vPolicy) + { + mVScroll = 0; + mHScroll = 0; + mHPolicy = hPolicy; + mVPolicy = vPolicy; + mScrollbarWidth = 12; + mUpButtonPressed = false; + mDownButtonPressed = false; + mLeftButtonPressed = false; + mRightButtonPressed = false; + mUpButtonScrollAmount = 10; + mDownButtonScrollAmount = 10; + mLeftButtonScrollAmount = 10; + mRightButtonScrollAmount = 10; + mIsVerticalMarkerDragged = false; + mIsHorizontalMarkerDragged = false; + + setContent(content); + addMouseListener(this); + } + + ScrollArea::~ScrollArea() + { + setContent(nullptr); + } + + void ScrollArea::setContent(Widget* widget) + { + if (widget != nullptr) + { + clear(); + add(widget); + widget->setPosition(0, 0); + } + else + { + clear(); + } + + checkPolicies(); + } + + Widget* ScrollArea::getContent() + { + if (!mWidgets.empty()) + { + return *mWidgets.begin(); + } + + return nullptr; + } + + void ScrollArea::setHorizontalScrollPolicy(unsigned int hPolicy) + { + mHPolicy = hPolicy; + checkPolicies(); + } + + unsigned int ScrollArea::getHorizontalScrollPolicy() const + { + return mHPolicy; + } + + void ScrollArea::setVerticalScrollPolicy(unsigned int vPolicy) + { + mVPolicy = vPolicy; + checkPolicies(); + } + + unsigned int ScrollArea::getVerticalScrollPolicy() const + { + return mVPolicy; + } + + void ScrollArea::setScrollPolicy(unsigned int hPolicy, unsigned int vPolicy) + { + mHPolicy = hPolicy; + mVPolicy = vPolicy; + checkPolicies(); + } + + void ScrollArea::setVerticalScrollAmount(int vScroll) + { + const auto max = getVerticalMaxScroll(); + + mVScroll = vScroll; + + if (vScroll > max) + { + mVScroll = max; + } + + if (vScroll < 0) + { + mVScroll = 0; + } + } + + int ScrollArea::getVerticalScrollAmount() const + { + return mVScroll; + } + + void ScrollArea::setHorizontalScrollAmount(int hScroll) + { + const auto max = getHorizontalMaxScroll(); + + mHScroll = hScroll; + + if (hScroll > max) + { + mHScroll = max; + } + else if (hScroll < 0) + { + mHScroll = 0; + } + } + + int ScrollArea::getHorizontalScrollAmount() const + { + return mHScroll; + } + + void ScrollArea::setScrollAmount(int hScroll, int vScroll) + { + setHorizontalScrollAmount(hScroll); + setVerticalScrollAmount(vScroll); + } + + int ScrollArea::getHorizontalMaxScroll() + { + checkPolicies(); + + if (getContent() == nullptr) + { + return 0; + } + + const auto value = getContent()->getWidth() - getChildrenArea().width + + 2 * static_cast(getContent()->getBorderSize()); + + if (value < 0) + { + return 0; + } + + return value; + } + + int ScrollArea::getVerticalMaxScroll() + { + checkPolicies(); + + if (getContent() == nullptr) + { + return 0; + } + + const auto value = getContent()->getHeight() - getChildrenArea().height + + 2 * static_cast(getContent()->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."); + } + } + + int ScrollArea::getScrollbarWidth() const + { + return mScrollbarWidth; + } + + void ScrollArea::mousePressed(MouseEvent& mouseEvent) + { + const auto x = mouseEvent.getX(); + const auto y = mouseEvent.getY(); + + if (getUpButtonDimension().isPointInRect(x, y)) + { + setVerticalScrollAmount(getVerticalScrollAmount() + - mUpButtonScrollAmount); + mUpButtonPressed = true; + } + else if (getDownButtonDimension().isPointInRect(x, y)) + { + setVerticalScrollAmount(getVerticalScrollAmount() + + mDownButtonScrollAmount); + mDownButtonPressed = true; + } + else if (getLeftButtonDimension().isPointInRect(x, y)) + { + setHorizontalScrollAmount(getHorizontalScrollAmount() + - mLeftButtonScrollAmount); + mLeftButtonPressed = true; + } + else if (getRightButtonDimension().isPointInRect(x, y)) + { + setHorizontalScrollAmount(getHorizontalScrollAmount() + + mRightButtonScrollAmount); + mRightButtonPressed = true; + } + else if (getVerticalMarkerDimension().isPointInRect(x, y)) + { + mIsHorizontalMarkerDragged = false; + mIsVerticalMarkerDragged = true; + + mVerticalMarkerDragOffset = y - getVerticalMarkerDimension().y; + } + else if (getVerticalBarDimension().isPointInRect(x, y)) + { + if (y < getVerticalMarkerDimension().y) + { + setVerticalScrollAmount(getVerticalScrollAmount() + - static_cast(getChildrenArea().height * 0.95)); + } + else + { + setVerticalScrollAmount(getVerticalScrollAmount() + + static_cast(getChildrenArea().height * 0.95)); + } + } + else if (getHorizontalMarkerDimension().isPointInRect(x, y)) + { + mIsHorizontalMarkerDragged = true; + mIsVerticalMarkerDragged = false; + + mHorizontalMarkerDragOffset = x - getHorizontalMarkerDimension().x; + } + else if (getHorizontalBarDimension().isPointInRect(x, y)) + { + if (x < getHorizontalMarkerDimension().x) + { + setHorizontalScrollAmount(getHorizontalScrollAmount() + - static_cast(getChildrenArea().width * 0.95)); + } + else + { + setHorizontalScrollAmount(getHorizontalScrollAmount() + + static_cast(getChildrenArea().width * 0.95)); + } + } + } + + void ScrollArea::mouseReleased(MouseEvent& mouseEvent) + { + mUpButtonPressed = false; + mDownButtonPressed = false; + mLeftButtonPressed = false; + mRightButtonPressed = false; + mIsHorizontalMarkerDragged = false; + mIsVerticalMarkerDragged = false; + + mouseEvent.consume(); + } + + void ScrollArea::mouseDragged(MouseEvent& mouseEvent) + { + if (mIsVerticalMarkerDragged) + { + const auto pos = mouseEvent.getY() - getVerticalBarDimension().y - mVerticalMarkerDragOffset; + const auto length = getVerticalMarkerDimension().height; + + const auto barDim = getVerticalBarDimension(); + + if ((barDim.height - length) > 0) + { + setVerticalScrollAmount((getVerticalMaxScroll() * pos) + / (barDim.height - length)); + } + else + { + setVerticalScrollAmount(0); + } + } + + if (mIsHorizontalMarkerDragged) + { + const auto pos = mouseEvent.getX() - getHorizontalBarDimension().x - mHorizontalMarkerDragOffset; + const auto length = getHorizontalMarkerDimension().width; + + const auto barDim = getHorizontalBarDimension(); + + if ((barDim.width - length) > 0) + { + setHorizontalScrollAmount((getHorizontalMaxScroll() * pos) + / (barDim.width - length)); + } + else + { + setHorizontalScrollAmount(0); + } + } + + mouseEvent.consume(); + } + + void ScrollArea::draw(Graphics* graphics) + { + drawBackground(graphics); + + if (mVBarVisible) + { + drawUpButton(graphics); + drawDownButton(graphics); + drawVBar(graphics); + drawVMarker(graphics); + } + + if (mHBarVisible) + { + drawLeftButton(graphics); + drawRightButton(graphics); + drawHBar(graphics); + drawHMarker(graphics); + } + + if (mHBarVisible && mVBarVisible) + { + graphics->setColor(getBaseColor()); + graphics->fillRectangle(Rectangle(getWidth() - mScrollbarWidth, + getHeight() - mScrollbarWidth, + mScrollbarWidth, + mScrollbarWidth)); + } + + drawChildren(graphics); + } + + void ScrollArea::drawBorder(Graphics* graphics) + { + const auto faceColor = getBaseColor(); + const auto alpha = getBaseColor().a; + const auto width = getWidth() + static_cast(getBorderSize()) * 2 - 1; + const auto height = getHeight() + static_cast(getBorderSize()) * 2 - 1; + auto highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + auto shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + for (auto i = 0; i < static_cast(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) + { + const auto dim = getHorizontalBarDimension(); + + graphics->pushClipArea(dim); + + const auto alpha = getBaseColor().a; + auto trackColor = getBaseColor() - 0x101010; + trackColor.a = alpha; + auto 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) + { + const auto dim = getVerticalBarDimension(); + + graphics->pushClipArea(dim); + + const auto alpha = getBaseColor().a; + auto trackColor = getBaseColor() - 0x101010; + trackColor.a = alpha; + auto shadowColor = getBaseColor() - 0x303030; + shadowColor.a = alpha; + + graphics->setColor(trackColor); + graphics->fillRectangle(Rectangle(0, 0, dim.width, dim.height)); + + graphics->setColor(shadowColor); + graphics->drawLine(0, 0, 0, dim.height); + + graphics->popClipArea(); + } + + void ScrollArea::drawBackground(Graphics* graphics) + { + graphics->setColor(getBackgroundColor()); + graphics->fillRectangle(getChildrenArea()); + } + + void ScrollArea::drawUpButton(Graphics* graphics) + { + const auto dim = getUpButtonDimension(); + graphics->pushClipArea(dim); + + Color highlightColor; + Color shadowColor; + Color faceColor; + int offset; + const auto 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()); + + const auto w = dim.height / 2; + const auto h = w / 2 + 2; + for (auto 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) + { + const auto dim = getDownButtonDimension(); + graphics->pushClipArea(dim); + + Color highlightColor; + Color shadowColor; + Color faceColor; + int offset; + const auto 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()); + + const auto w = dim.height / 2; + const auto h = w + 1; + for (auto 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) + { + const auto dim = getLeftButtonDimension(); + graphics->pushClipArea(dim); + + Color highlightColor; + Color shadowColor; + Color faceColor; + int offset; + const auto 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()); + + const auto w = dim.width / 2; + const auto h = w - 2; + for (auto 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) + { + const auto dim = getRightButtonDimension(); + graphics->pushClipArea(dim); + + Color highlightColor; + Color shadowColor; + Color faceColor; + int offset; + const auto 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()); + + const auto w = dim.width / 2; + const auto h = w + 1; + for (auto 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) + { + const auto dim = getVerticalMarkerDimension(); + graphics->pushClipArea(dim); + + const auto alpha = getBaseColor().a; + auto faceColor = getBaseColor(); + faceColor.a = alpha; + auto highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + auto 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) + { + const auto dim = getHorizontalMarkerDimension(); + graphics->pushClipArea(dim); + + const auto alpha = getBaseColor().a; + auto faceColor = getBaseColor(); + faceColor.a = alpha; + auto highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + auto shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + graphics->setColor(faceColor); + graphics->fillRectangle(Rectangle(1, 1, dim.width - 1, dim.height - 1)); + + graphics->setColor(highlightColor); + graphics->drawLine(0, 0, dim.width - 1, 0); + graphics->drawLine(0, 1, 0, dim.height - 1); + + graphics->setColor(shadowColor); + graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); + graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); + + graphics->popClipArea(); + } + + void ScrollArea::logic() + { + checkPolicies(); + + setVerticalScrollAmount(getVerticalScrollAmount()); + setHorizontalScrollAmount(getHorizontalScrollAmount()); + + if (getContent() != nullptr) + { + getContent()->setPosition(-mHScroll + static_cast(getContent()->getBorderSize()), + -mVScroll + static_cast(getContent()->getBorderSize())); + getContent()->logic(); + } + } + + void ScrollArea::checkPolicies() + { + const auto w = getWidth(); + const auto h = getHeight(); + + mHBarVisible = false; + mVBarVisible = false; + + + if (!getContent()) + { + mHBarVisible = (mHPolicy == SHOW_ALWAYS); + mVBarVisible = (mVPolicy == SHOW_ALWAYS); + return; + } + + if (mHPolicy == SHOW_AUTO && + mVPolicy == SHOW_AUTO) + { + if (getContent()->getWidth() <= w + && getContent()->getHeight() <= h) + { + mHBarVisible = false; + mVBarVisible = false; + } + + if (getContent()->getWidth() > w) + { + mHBarVisible = true; + } + + if ((getContent()->getHeight() > h) + || (mHBarVisible && getContent()->getHeight() > h - mScrollbarWidth)) + { + mVBarVisible = true; + } + + if (mVBarVisible && getContent()->getWidth() > w - mScrollbarWidth) + { + mHBarVisible = true; + } + + return; + } + + switch (mHPolicy) + { + case SHOW_NEVER: + mHBarVisible = false; + break; + + case SHOW_ALWAYS: + mHBarVisible = true; + break; + + case SHOW_AUTO: + if (mVPolicy == SHOW_NEVER) + { + mHBarVisible = getContent()->getWidth() > w; + } + else // (mVPolicy == SHOW_ALWAYS) + { + mHBarVisible = getContent()->getWidth() > w - mScrollbarWidth; + } + break; + + default: + throw GCN_EXCEPTION("Horizontal scroll policy invalid."); + } + + switch (mVPolicy) + { + case SHOW_NEVER: + mVBarVisible = false; + break; + + case SHOW_ALWAYS: + mVBarVisible = true; + break; + + case SHOW_AUTO: + if (mHPolicy == SHOW_NEVER) + { + mVBarVisible = getContent()->getHeight() > h; + } + else // (mHPolicy == SHOW_ALWAYS) + { + mVBarVisible = getContent()->getHeight() > h - mScrollbarWidth; + } + break; + default: + throw GCN_EXCEPTION("Vertical scroll policy invalid."); + } + } + + Rectangle ScrollArea::getUpButtonDimension() + { + 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::getChildrenArea() + { + 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; + const auto barDim = getVerticalBarDimension(); + + if (getContent() && getContent()->getHeight() != 0) + { + length = (barDim.height * getChildrenArea().height) + / getContent()->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; + const auto barDim = getHorizontalBarDimension(); + + if (getContent() && getContent()->getWidth() != 0) + { + length = (barDim.width * getChildrenArea().width) + / getContent()->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::showWidgetPart(Widget* widget, Rectangle area) + { + if (widget != getContent()) + { + throw GCN_EXCEPTION("Widget not content widget"); + } + + BasicContainer::showWidgetPart(widget, area); + + setHorizontalScrollAmount(static_cast(getContent()->getBorderSize() - getContent()->getX())); + setVerticalScrollAmount(static_cast(getContent()->getBorderSize() - getContent()->getY())); + } + + Widget* ScrollArea::getWidgetAt(int x, int y) + { + if (getChildrenArea().isPointInRect(x, y)) + { + return getContent(); + } + + return nullptr; + } + + void ScrollArea::mouseWheelMovedUp(MouseEvent& mouseEvent) + { + if (mouseEvent.isConsumed()) + { + return; + } + + setVerticalScrollAmount(getVerticalScrollAmount() - getChildrenArea().height / 8); + + mouseEvent.consume(); + } + + void ScrollArea::mouseWheelMovedDown(MouseEvent& mouseEvent) + { + if (mouseEvent.isConsumed()) + { + return; + } + + setVerticalScrollAmount(getVerticalScrollAmount() + getChildrenArea().height / 8); + + mouseEvent.consume(); + } + + void ScrollArea::setWidth(int width) + { + Widget::setWidth(width); + checkPolicies(); + } + + void ScrollArea::setHeight(int height) + { + Widget::setHeight(height); + checkPolicies(); + } + + void ScrollArea::setDimension(const Rectangle& dimension) + { + Widget::setDimension(dimension); + checkPolicies(); + } + + void ScrollArea::setLeftButtonScrollAmount(int amount) + { + mLeftButtonScrollAmount = amount; + } + + void ScrollArea::setRightButtonScrollAmount(int amount) + { + mRightButtonScrollAmount = amount; + } + + void ScrollArea::setUpButtonScrollAmount(int amount) + { + mUpButtonScrollAmount = amount; + } + + void ScrollArea::setDownButtonScrollAmount(int amount) + { + mDownButtonScrollAmount = amount; + } + + int ScrollArea::getLeftButtonScrollAmount() const + { + return mLeftButtonScrollAmount; + } + + int ScrollArea::getRightButtonScrollAmount() const + { + return mRightButtonScrollAmount; + } + + int ScrollArea::getUpButtonScrollAmount() const + { + return mUpButtonScrollAmount; + } + + int ScrollArea::getDownButtonScrollAmount() const + { + return mDownButtonScrollAmount; + } } /* - * Wow! This is a looooong source file. - */ +* Wow! This is a looooong source file. +*/ \ No newline at end of file diff --git a/external/libguisan/src/widgets/slider.cpp b/external/libguisan/src/widgets/slider.cpp index e0b3ff1f..7a908c54 100644 --- a/external/libguisan/src/widgets/slider.cpp +++ b/external/libguisan/src/widgets/slider.cpp @@ -66,339 +66,347 @@ namespace gcn { - Slider::Slider(double scaleEnd) - { - mMouseDrag = false; + Slider::Slider(double scaleEnd) + { + mMouseDrag = false; + mScaleStart = 0; + mScaleEnd = scaleEnd; - mScaleStart = 0; - mScaleEnd = scaleEnd; + setFocusable(true); + setBorderSize(1); + setOrientation(HORIZONTAL); + setValue(0); + setStepLength(scaleEnd / 10); + setMarkerLength(10); - setFocusable(true); - setBorderSize(1); - setOrientation(HORIZONTAL); - setValue(0); - setStepLength(scaleEnd / 10); - setMarkerLength(10); + addMouseListener(this); + addKeyListener(this); + } - addMouseListener(this); - addKeyListener(this); - } + Slider::Slider(double scaleStart, double scaleEnd) + { + mMouseDrag = false; - Slider::Slider(double scaleStart, double scaleEnd) - { - mMouseDrag = false; + mScaleStart = scaleStart; + mScaleEnd = scaleEnd; - mScaleStart = scaleStart; - mScaleEnd = scaleEnd; + setFocusable(true); + setBorderSize(1); + setOrientation(HORIZONTAL); + setValue(scaleStart); + setStepLength((scaleEnd - scaleStart) / 10); + setMarkerLength(10); - setFocusable(true); - setBorderSize(1); - setOrientation(HORIZONTAL); - setValue(scaleStart); - setStepLength((scaleEnd - scaleStart)/ 10); - setMarkerLength(10); + addMouseListener(this); + addKeyListener(this); + } - addMouseListener(this); - addKeyListener(this); - } + void Slider::setScale(double scaleStart, double scaleEnd) + { + mScaleStart = scaleStart; + mScaleEnd = scaleEnd; + } - void Slider::setScale(double scaleStart, double scaleEnd) - { - mScaleStart = scaleStart; - mScaleEnd = scaleEnd; - } + double Slider::getScaleStart() const + { + return mScaleStart; + } - double Slider::getScaleStart() const - { - return mScaleStart; - } + void Slider::setScaleStart(double scaleStart) + { + mScaleStart = scaleStart; + } - void Slider::setScaleStart(double scaleStart) - { - mScaleStart = scaleStart; - } + double Slider::getScaleEnd() const + { + return mScaleEnd; + } - double Slider::getScaleEnd() const - { - return mScaleEnd; - } + void Slider::setScaleEnd(double scaleEnd) + { + mScaleEnd = scaleEnd; + } - void Slider::setScaleEnd(double scaleEnd) - { - mScaleEnd = scaleEnd; - } + void Slider::draw(Graphics* graphics) + { + auto shadowColor = getBaseColor() - 0x101010; + const auto alpha = getBaseColor().a; + shadowColor.a = alpha; - void Slider::draw(gcn::Graphics* graphics) - { - auto shadowColor = getBaseColor() - 0x101010; - const auto alpha = getBaseColor().a; - shadowColor.a = alpha; + graphics->setColor(shadowColor); + graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - graphics->setColor(shadowColor); - graphics->fillRectangle(gcn::Rectangle(0,0,getWidth(),getHeight())); + drawMarker(graphics); + } - drawMarker(graphics); - } + void Slider::drawBorder(Graphics* graphics) + { + const auto faceColor = getBaseColor(); + const auto alpha = getBaseColor().a; + const auto width = getWidth() + static_cast(getBorderSize()) * 2 - 1; + const auto height = getHeight() + static_cast(getBorderSize()) * 2 - 1; + auto highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + auto shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - void Slider::drawBorder(gcn::Graphics* graphics) - { - const auto faceColor = getBaseColor(); - const auto alpha = getBaseColor().a; - const auto width = getWidth() + int(getBorderSize()) * 2 - 1; - const auto height = getHeight() + int(getBorderSize()) * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + for (auto i = 0; i < static_cast(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); + } + } - for (auto i = 0; i < int(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(Graphics* graphics) + { + const auto faceColor = getBaseColor(); + const auto alpha = getBaseColor().a; + Color highlightColor; + Color shadowColor; + if (isEnabled()) + { + highlightColor = faceColor + 0x303030; + shadowColor = faceColor - 0x303030; + } + else + { + highlightColor = faceColor + 0x151515; + shadowColor = faceColor - 0x151515; + } + highlightColor.a = alpha; + shadowColor.a = alpha; - void Slider::drawMarker(gcn::Graphics* graphics) - { - const auto faceColor = getBaseColor(); - const auto alpha = getBaseColor().a; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + graphics->setColor(faceColor); - graphics->setColor(faceColor); + if (getOrientation() == HORIZONTAL) + { + const auto v = getMarkerPosition(); + graphics->fillRectangle(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 (getOrientation() == HORIZONTAL) - { - const auto v = getMarkerPosition(); - graphics->fillRectangle(gcn::Rectangle(v + 1, 1, getMarkerLength() - 2, getHeight() - 2)); - graphics->setColor(highlightColor); - graphics->drawLine(v, 0, v + getMarkerLength() - 1,0); - graphics->drawLine(v, 0, v, getHeight() - 1); - graphics->setColor(shadowColor); - graphics->drawLine(v + getMarkerLength() - 1, 1, v + getMarkerLength() - 1, getHeight() - 1); - graphics->drawLine(v + 1, getHeight() - 1, v + getMarkerLength() - 1, getHeight() - 1); + if (isFocused()) + { + graphics->setColor(getForegroundColor()); + graphics->drawRectangle(Rectangle(v + 2, 2, getMarkerLength() - 4, getHeight() - 4)); + } + } + else + { + const auto v = (getHeight() - getMarkerLength()) - getMarkerPosition(); + graphics->fillRectangle(Rectangle(1, v + 1, getWidth() - 2, getMarkerLength() - 2)); + graphics->setColor(highlightColor); + graphics->drawLine(0, v, 0, v + getMarkerLength() - 1); + graphics->drawLine(0, v, getWidth() - 1, v); + graphics->setColor(shadowColor); + graphics->drawLine(1, v + getMarkerLength() - 1, getWidth() - 1, v + getMarkerLength() - 1); + graphics->drawLine(getWidth() - 1, v + 1, getWidth() - 1, v + getMarkerLength() - 1); - if (isFocused()) - { - graphics->setColor(getForegroundColor()); - graphics->drawRectangle(Rectangle(v + 2, 2, getMarkerLength() - 4, getHeight() - 4)); - } - } - else - { - const auto v = (getHeight() - getMarkerLength()) - getMarkerPosition(); - graphics->fillRectangle(gcn::Rectangle(1, v + 1, getWidth() - 2, getMarkerLength() - 2)); - graphics->setColor(highlightColor); - graphics->drawLine(0, v, 0, v + getMarkerLength() - 1); - graphics->drawLine(0, v, getWidth() - 1, v); - graphics->setColor(shadowColor); - graphics->drawLine(1, v + getMarkerLength() - 1, getWidth() - 1, v + getMarkerLength() - 1); - graphics->drawLine(getWidth() - 1, v + 1, getWidth() - 1, v + getMarkerLength() - 1); + if (isFocused()) + { + graphics->setColor(getForegroundColor()); + graphics->drawRectangle(Rectangle(2, v + 2, getWidth() - 4, getMarkerLength() - 4)); + } + } + } - if (isFocused()) - { - graphics->setColor(getForegroundColor()); - graphics->drawRectangle(Rectangle(2, v + 2, getWidth() - 4, getMarkerLength() - 4)); - } - } - } + void Slider::mousePressed(MouseEvent& mouseEvent) + { + if (mouseEvent.getButton() == MouseEvent::LEFT + && mouseEvent.getX() >= 0 + && mouseEvent.getX() <= getWidth() + && mouseEvent.getY() >= 0 + && mouseEvent.getY() <= getHeight()) + { + if (getOrientation() == HORIZONTAL) + { + setValue(markerPositionToValue(mouseEvent.getX() - getMarkerLength() / 2)); + } + else + { + setValue(markerPositionToValue(getHeight() - mouseEvent.getY() - getMarkerLength() / 2)); + } - void Slider::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == gcn::MouseEvent::LEFT - && mouseEvent.getX() >= 0 - && mouseEvent.getX() <= getWidth() - && mouseEvent.getY() >= 0 - && mouseEvent.getY() <= getHeight()) - { - if (getOrientation() == HORIZONTAL) - { - setValue(markerPositionToValue(mouseEvent.getX() - getMarkerLength() / 2)); - } - else - { - setValue(markerPositionToValue(getHeight() - mouseEvent.getY() - getMarkerLength() / 2)); - } + generateAction(); + } + } - generateAction(); - } - } + void Slider::mouseDragged(MouseEvent& mouseEvent) + { + if (getOrientation() == HORIZONTAL) + { + setValue(markerPositionToValue(mouseEvent.getX() - getMarkerLength() / 2)); + } + else + { + setValue(markerPositionToValue(getHeight() - mouseEvent.getY() - getMarkerLength() / 2)); + } - void Slider::mouseDragged(MouseEvent& mouseEvent) - { - if (getOrientation() == HORIZONTAL) - { - setValue(markerPositionToValue(mouseEvent.getX() - getMarkerLength() / 2)); - } - else - { - setValue(markerPositionToValue(getHeight() - mouseEvent.getY() - getMarkerLength() / 2)); - } + generateAction(); - generateAction(); + mouseEvent.consume(); + } - mouseEvent.consume(); - } + void Slider::setValue(double value) + { + if (value > getScaleEnd()) + { + mValue = getScaleEnd(); + return; + } - void Slider::setValue(double value) - { - if (value > getScaleEnd()) - { - mValue = getScaleEnd(); - return; - } + if (value < getScaleStart()) + { + mValue = getScaleStart(); + return; + } - if (value < getScaleStart()) - { - mValue = getScaleStart(); - return; - } + mValue = value; + } - mValue = value; - } + double Slider::getValue() const + { + return mValue; + } - double Slider::getValue() const - { - return mValue; - } + int Slider::getMarkerLength() const + { + return mMarkerLength; + } - int Slider::getMarkerLength() const - { - return mMarkerLength; - } + void Slider::setMarkerLength(int length) + { + mMarkerLength = length; + } - void Slider::setMarkerLength(int length) - { - mMarkerLength = length; - } + void Slider::keyPressed(KeyEvent& keyEvent) + { + const auto key = keyEvent.getKey(); - void Slider::keyPressed(KeyEvent& keyEvent) - { - const auto key = keyEvent.getKey(); + if (getOrientation() == HORIZONTAL) + { + if (key.getValue() == Key::RIGHT) + { + setValue(getValue() + getStepLength()); + generateAction(); + keyEvent.consume(); + } + else if (key.getValue() == Key::LEFT) + { + setValue(getValue() - getStepLength()); + generateAction(); + keyEvent.consume(); + } + } + else + { + if (key.getValue() == Key::UP) + { + setValue(getValue() + getStepLength()); + generateAction(); + keyEvent.consume(); + } + else if (key.getValue() == Key::DOWN) + { + setValue(getValue() - getStepLength()); + generateAction(); + keyEvent.consume(); + } + } + } - if (getOrientation() == HORIZONTAL) - { - if (key.getValue() == Key::RIGHT) - { - setValue(getValue() + getStepLength()); - generateAction(); - keyEvent.consume(); - } - else if (key.getValue() == Key::LEFT) - { - setValue(getValue() - getStepLength()); - generateAction(); - keyEvent.consume(); - } - } - else - { - if (key.getValue() == Key::UP) - { - setValue(getValue() + getStepLength()); - generateAction(); - keyEvent.consume(); - } - else if (key.getValue() == Key::DOWN) - { - setValue(getValue() - getStepLength()); - generateAction(); - keyEvent.consume(); - } - } - } + void Slider::setOrientation(unsigned int orientation) + { + mOrientation = orientation; + } - void Slider::setOrientation(unsigned int orientation) - { - mOrientation = orientation; - } + unsigned int Slider::getOrientation() const + { + return mOrientation; + } - unsigned int Slider::getOrientation() const - { - return mOrientation; - } + double Slider::markerPositionToValue(int v) const + { + int w; + if (getOrientation() == HORIZONTAL) + { + w = getWidth(); + } + else + { + w = getHeight(); + } - double Slider::markerPositionToValue(int v) const - { - int w; - if (getOrientation() == HORIZONTAL) - { - w = getWidth(); - } - else - { - w = getHeight(); - } + const auto pos = v / (static_cast(w) - getMarkerLength()); + return (1.0 - pos) * getScaleStart() + pos * getScaleEnd(); + } - const auto 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(); + } - } + const auto w = static_cast((v - getMarkerLength()) + * (value - getScaleStart()) + / (getScaleEnd() - getScaleStart())); - int Slider::valueToMarkerPosition(double value) const - { - int v; - if (getOrientation() == HORIZONTAL) - { - v = getWidth(); - } - else - { - v = getHeight(); - } + if (w < 0) + { + return 0; + } - const auto w = int((v - getMarkerLength()) - * (value - getScaleStart()) - / (getScaleEnd() - getScaleStart())); + if (w > v - getMarkerLength()) + { + return v - getMarkerLength(); + } - if (w < 0) - { - return 0; - } + return w; + } - if (w > v - getMarkerLength()) - { - return v - getMarkerLength(); - } + void Slider::setStepLength(double length) + { + mStepLength = length; + } - return w; - } + double Slider::getStepLength() const + { + return mStepLength; + } - void Slider::setStepLength(double length) - { - mStepLength = length; - } + int Slider::getMarkerPosition() const + { + return valueToMarkerPosition(getValue()); + } - double Slider::getStepLength() const - { - return mStepLength; - } + void Slider::mouseWheelMovedUp(MouseEvent& mouseEvent) + { + setValue(getValue() + getStepLength()); + generateAction(); - int Slider::getMarkerPosition() const - { - return valueToMarkerPosition(getValue()); - } + mouseEvent.consume(); + } - void Slider::mouseWheelMovedUp(MouseEvent& mouseEvent) - { - setValue(getValue() + getStepLength()); - generateAction(); + void Slider::mouseWheelMovedDown(MouseEvent& mouseEvent) + { + setValue(getValue() - getStepLength()); + generateAction(); - mouseEvent.consume(); - } - - void Slider::mouseWheelMovedDown(MouseEvent& mouseEvent) - { - setValue(getValue() - getStepLength()); - generateAction(); - - mouseEvent.consume(); - } + mouseEvent.consume(); + } } diff --git a/external/libguisan/src/widgets/tab.cpp b/external/libguisan/src/widgets/tab.cpp index 2821cf54..a3a42a0c 100644 --- a/external/libguisan/src/widgets/tab.cpp +++ b/external/libguisan/src/widgets/tab.cpp @@ -68,102 +68,101 @@ namespace gcn { - Tab::Tab() - :mHasMouse(false) - { - mLabel = new Label(); - mLabel->setPosition(4, 4); - add(mLabel); - setBorderSize(1); + Tab::Tab() + : mHasMouse(false) + { + mLabel = new Label(); + mLabel->setPosition(4, 4); + BasicContainer::add(mLabel); + setBorderSize(1); - addMouseListener(this); - } - - Tab::~Tab() - { - delete mLabel; - } - - void Tab::adjustSize() - { - setHeight(mLabel->getHeight() + 8); - } + addMouseListener(this); + } - void Tab::setTabbedArea(TabbedArea* tabbedArea) - { - mTabbedArea = tabbedArea; - } + Tab::~Tab() + { + delete mLabel; + } - TabbedArea* Tab::getTabbedArea() - { - return mTabbedArea; - } + void Tab::adjustSize() + { + setHeight(mLabel->getHeight() + 8); + } - void Tab::setCaption(const std::string& caption) - { - mCaption = caption; - mLabel->setCaption(caption); - mLabel->adjustSize(); - } - - const std::string& Tab::getCaption() const - { - return mCaption; - } - - void Tab::draw(Graphics *graphics) - { - if (mTabbedArea->isTabSelected(this) || mHasMouse) - { - graphics->setColor(getBaseColor()); - } - else - { - graphics->setColor(getBaseColor() - 0x151515); - } + void Tab::setTabbedArea(TabbedArea* tabbedArea) + { + mTabbedArea = tabbedArea; + } - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - - drawChildren(graphics); + TabbedArea* Tab::getTabbedArea() const + { + return mTabbedArea; + } - if (mTabbedArea->isFocused() - && mTabbedArea->isTabSelected(this)) - { - graphics->setColor(Color(0x000000)); - graphics->drawRectangle(Rectangle(2, 2, getWidth() - 4, getHeight() - 4)); - } - } - - void Tab::drawBorder(Graphics* graphics) - { - const auto faceColor = getBaseColor(); - const auto alpha = getBaseColor().a; - const auto width = getWidth() + int(getBorderSize()) * 2 - 1; - const auto height = getHeight() + int(getBorderSize()) * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + void Tab::setCaption(const std::string& caption) + { + mCaption = caption; + mLabel->setCaption(caption); + mLabel->adjustSize(); + } - for (auto i = 0; i < int(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 Tab::mouseEntered(MouseEvent& mouseEvent) - { - mHasMouse = true; - } + const std::string& Tab::getCaption() const + { + return mCaption; + } - void Tab::mouseExited(MouseEvent& mouseEvent) - { - mHasMouse = false; - } + void Tab::draw(Graphics* graphics) + { + if (mTabbedArea->isTabSelected(this) || mHasMouse) + { + graphics->setColor(getBaseColor()); + } + else + { + graphics->setColor(getBaseColor() - 0x151515); + } + + graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); + + drawChildren(graphics); + + if (mTabbedArea->isFocused() + && mTabbedArea->isTabSelected(this)) + { + graphics->setColor(Color(0x000000)); + graphics->drawRectangle(Rectangle(2, 2, getWidth() - 4, getHeight() - 4)); + } + } + + void Tab::drawBorder(Graphics* graphics) + { + const auto faceColor = getBaseColor(); + const auto alpha = getBaseColor().a; + const auto width = getWidth() + static_cast(getBorderSize()) * 2 - 1; + const auto height = getHeight() + static_cast(getBorderSize()) * 2 - 1; + auto highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + auto shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + + for (auto i = 0; i < static_cast(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 Tab::mouseEntered(MouseEvent& mouseEvent) + { + mHasMouse = true; + } + + void Tab::mouseExited(MouseEvent& mouseEvent) + { + mHasMouse = false; + } } - diff --git a/external/libguisan/src/widgets/tabbedarea.cpp b/external/libguisan/src/widgets/tabbedarea.cpp index 46545a65..4d784351 100644 --- a/external/libguisan/src/widgets/tabbedarea.cpp +++ b/external/libguisan/src/widgets/tabbedarea.cpp @@ -72,426 +72,418 @@ namespace gcn { - TabbedArea::TabbedArea() - :mSelectedTab(NULL) - { - setBorderSize(1); - setFocusable(true); - addKeyListener(this); - addMouseListener(this); - - mTabContainer = new Container(); - mTabContainer->setOpaque(false); - mWidgetContainer = new Container(); + TabbedArea::TabbedArea() + : mSelectedTab(nullptr) + { + setBorderSize(1); + setFocusable(true); + addKeyListener(this); + addMouseListener(this); - add(mTabContainer); - add(mWidgetContainer); - } + mTabContainer = new Container(); + mTabContainer->setOpaque(false); + mWidgetContainer = new Container(); - TabbedArea::~TabbedArea() - { - BasicContainer::remove(mTabContainer); - BasicContainer::remove(mWidgetContainer); - - delete mTabContainer; - delete mWidgetContainer; + BasicContainer::add(mTabContainer); + BasicContainer::add(mWidgetContainer); + } - for (auto& i : mTabsToCleanUp) - { - delete i; - } - } + TabbedArea::~TabbedArea() + { + BasicContainer::remove(mTabContainer); + BasicContainer::remove(mWidgetContainer); - void TabbedArea::addTab(const std::string& caption, Widget* widget) - { - auto tab = new Tab(); - tab->setSize(70, 20); - tab->setCaption(caption); - mTabsToCleanUp.push_back(tab); - - addTab(tab, widget); - } + delete mTabContainer; + delete mWidgetContainer; - void TabbedArea::addTab(Tab* tab, Widget* widget) - { - tab->setTabbedArea(this); - tab->addActionListener(this); + for (auto& i : mTabsToCleanUp) + { + delete i; + } + } - mTabContainer->add(tab); - mTabs.emplace_back(tab, widget); + void TabbedArea::addTab(const std::string& caption, Widget* widget) + { + auto* tab = new Tab(); + tab->setSize(70, 20); + tab->setCaption(caption); + mTabsToCleanUp.push_back(tab); + + addTab(tab, widget); + } + + void TabbedArea::addTab(Tab* tab, Widget* widget) + { + tab->setTabbedArea(this); + tab->addActionListener(this); + + mTabContainer->add(tab); + mTabs.emplace_back(tab, widget); - if (mSelectedTab == NULL) - { - setSelectedTab(tab); - } + if (mSelectedTab == nullptr) + { + setSelectedTab(tab); + } - adjustTabPositions(); - adjustSize(); - } + adjustTabPositions(); + adjustSize(); + } - void TabbedArea::removeTabWithIndex(unsigned int index) - { - if (index >= mTabs.size()) - { - throw GCN_EXCEPTION("No such tab index."); - } + void TabbedArea::removeTabWithIndex(unsigned int index) + { + if (index >= mTabs.size()) + { + throw GCN_EXCEPTION("No such tab index."); + } - removeTab(mTabs[index].first); - } + removeTab(mTabs[index].first); + } - void TabbedArea::removeTab(Tab* tab) - { - auto tabIndexToBeSelected = - 1; - - if (tab == mSelectedTab) - { - auto index = getSelectedTabIndex(); - - if (index == int(mTabs.size()) - 1 - && mTabs.size() >= 2) - { - tabIndexToBeSelected = index--; - } - else if (index == int(mTabs.size()) - 1 - && mTabs.size() == 1) - { - tabIndexToBeSelected = -1; - } - else - { - tabIndexToBeSelected = index; - } - } + void TabbedArea::removeTab(Tab* tab) + { + auto tabIndexToBeSelected = - 1; - for (auto iter = mTabs.begin(); iter != mTabs.end(); ++iter) - { - if (iter->first == tab) - { - mTabContainer->remove(tab); - mTabs.erase(iter); - break; - } - } + if (tab == mSelectedTab) + { + auto index = getSelectedTabIndex(); - for (auto iter2 = mTabsToCleanUp.begin(); iter2 != mTabsToCleanUp.end(); ++iter2) - { - if (*iter2 == tab) - { - mTabsToCleanUp.erase(iter2); - delete tab; - break; - } - } + if (index == static_cast(mTabs.size()) - 1 + && mTabs.size() >= 2) + { + tabIndexToBeSelected = index--; + } + else if (index == static_cast(mTabs.size()) - 1 + && mTabs.size() == 1) + { + tabIndexToBeSelected = -1; + } + else + { + tabIndexToBeSelected = index; + } + } - if (tabIndexToBeSelected == -1) - { - mSelectedTab = NULL; - mWidgetContainer->clear(); - } - else - { - setSelectedTabWithIndex(tabIndexToBeSelected); - } - - adjustSize(); - adjustTabPositions(); - } + for (auto iter = mTabs.begin(); iter != mTabs.end(); ++iter) + { + if (iter->first == tab) + { + mTabContainer->remove(tab); + mTabs.erase(iter); + break; + } + } - bool TabbedArea::isTabSelected(unsigned int index) const - { - if (index >= mTabs.size()) - { - throw GCN_EXCEPTION("No such tab index."); - } + for (auto iter2 = mTabsToCleanUp.begin(); iter2 != mTabsToCleanUp.end(); ++iter2) + { + if (*iter2 == tab) + { + mTabsToCleanUp.erase(iter2); + delete tab; + break; + } + } - return mSelectedTab == mTabs[index].first; - } + if (tabIndexToBeSelected == -1) + { + mSelectedTab = nullptr; + mWidgetContainer->clear(); + } + else + { + setSelectedTabWithIndex(tabIndexToBeSelected); + } - bool TabbedArea::isTabSelected(Tab* tab) - { - return mSelectedTab == tab; - } + adjustSize(); + adjustTabPositions(); + } - void TabbedArea::setSelectedTabWithIndex(unsigned int index) - { - if (index >= mTabs.size()) - { - throw GCN_EXCEPTION("No such tab index."); - } - - setSelectedTab(mTabs[index].first); - } + bool TabbedArea::isTabSelected(unsigned int index) const + { + if (index >= mTabs.size()) + { + throw GCN_EXCEPTION("No such tab index."); + } - void TabbedArea::setSelectedTab(Tab* tab) - { - unsigned int i; - for (i = 0; i < mTabs.size(); i++) - { - if (mTabs[i].first == mSelectedTab) - { - mWidgetContainer->remove(mTabs[i].second); - } - } + return mSelectedTab == mTabs[index].first; + } - for (i = 0; i < mTabs.size(); i++) - { - if (mTabs[i].first == tab) - { - mSelectedTab = tab; - mWidgetContainer->add(mTabs[i].second); - } - } - } + bool TabbedArea::isTabSelected(Tab* tab) + { + return mSelectedTab == tab; + } - int TabbedArea::getSelectedTabIndex() const - { - for (auto i = 0; i < int(mTabs.size()); i++) - { - if (mTabs[i].first == mSelectedTab) - { - return i; - } - } + void TabbedArea::setSelectedTabWithIndex(unsigned int index) + { + if (index >= mTabs.size()) + { + throw GCN_EXCEPTION("No such tab index."); + } - return -1; - } + setSelectedTab(mTabs[index].first); + } - Tab* TabbedArea::getSelectedTab() - { - return mSelectedTab; - } - - - void TabbedArea::draw(Graphics *graphics) - { - graphics->setColor(getBaseColor() + 0x303030); - graphics->drawLine(0, - mTabContainer->getHeight(), - getWidth(), - mTabContainer->getHeight()); + void TabbedArea::setSelectedTab(Tab* tab) + { + unsigned int i; + for (i = 0; i < mTabs.size(); i++) + { + if (mTabs[i].first == mSelectedTab) + { + mWidgetContainer->remove(mTabs[i].second); + } + } - if (mSelectedTab != NULL) - { - graphics->setColor(getBaseColor()); - graphics->drawLine(mSelectedTab->getX(), - mTabContainer->getHeight(), - mSelectedTab->getX() + mSelectedTab->getWidth(), - mTabContainer->getHeight()); + for (i = 0; i < mTabs.size(); i++) + { + if (mTabs[i].first == tab) + { + mSelectedTab = tab; + mWidgetContainer->add(mTabs[i].second); + } + } + } - } + int TabbedArea::getSelectedTabIndex() const + { + for (auto i = 0; i < static_cast(mTabs.size()); i++) + { + if (mTabs[i].first == mSelectedTab) + { + return i; + } + } - drawChildren(graphics); - } - - void TabbedArea::drawBorder(Graphics* graphics) - { - const auto faceColor = getBaseColor(); - const auto alpha = getBaseColor().a; - const auto width = getWidth() + int(getBorderSize()) * 2 - 1; - const auto height = getHeight() + int(getBorderSize()) * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + return -1; + } - for (auto i = 0; i < int(getBorderSize()); ++i) - { - graphics->setColor(highlightColor); - graphics->drawLine(i,i + mWidgetContainer->getY(), i, height - i - 1); - graphics->setColor(shadowColor); - graphics->drawLine(width - i,i + 1 + mWidgetContainer->getY(), width - i, height - i); - graphics->drawLine(i,height - i, width - i - 1, height - i); - } - } + Tab* TabbedArea::getSelectedTab() + { + return mSelectedTab; + } - - void TabbedArea::logic() - { - } + void TabbedArea::draw(Graphics* graphics) + { + graphics->setColor(getBaseColor() + 0x303030); + graphics->drawLine(0, + mTabContainer->getHeight(), + getWidth(), + mTabContainer->getHeight()); - void TabbedArea::adjustSize() - { - auto max_tab_height = 0; - for (auto& mTab : mTabs) - { - if (mTab.first->getHeight() > max_tab_height) - { - max_tab_height = mTab.first->getHeight(); - } - } - - if (getHeight() < max_tab_height) - { - mTabContainer->setHeight(max_tab_height); - } - else - { - mTabContainer->setHeight(max_tab_height); - mWidgetContainer->setHeight(getHeight() - max_tab_height - 1); - mWidgetContainer->setY(max_tab_height + 1); - } + if (mSelectedTab != nullptr) + { + graphics->setColor(getBaseColor()); + graphics->drawLine(mSelectedTab->getX(), + mTabContainer->getHeight(), + mSelectedTab->getX() + mSelectedTab->getWidth(), + mTabContainer->getHeight()); + } - mTabContainer->setWidth(getWidth()); - mWidgetContainer->setWidth(getWidth()); - } + drawChildren(graphics); + } - void TabbedArea::adjustTabPositions() - { - auto max_tab_height = 0; - unsigned int i; - for (i = 0; i < mTabs.size(); i++) - { - if (mTabs[i].first->getHeight() > max_tab_height) - { - max_tab_height = mTabs[i].first->getHeight(); - } - } + void TabbedArea::drawBorder(Graphics* graphics) + { + const auto faceColor = getBaseColor(); + const auto alpha = getBaseColor().a; + const auto width = getWidth() + static_cast(getBorderSize()) * 2 - 1; + const auto height = getHeight() + static_cast(getBorderSize()) * 2 - 1; + auto highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + auto shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - auto x = 0; - for (i = 0; i < mTabs.size(); i++) - { - auto tab = mTabs[i].first; + for (auto i = 0; i < static_cast(getBorderSize()); ++i) + { + graphics->setColor(highlightColor); + graphics->drawLine(i, i + mWidgetContainer->getY(), i, height - i - 1); + graphics->setColor(shadowColor); + graphics->drawLine(width - i, i + 1 + mWidgetContainer->getY(), width - i, height - i); + graphics->drawLine(i, height - i, width - i - 1, height - i); + } + } - if (x == 0) - { - x = tab->getBorderSize() + 2; - } - - tab->setX(x); - if (tab->getHeight() < max_tab_height) - { - tab->setY(max_tab_height - - tab->getHeight() - + int(tab->getBorderSize())); - } - else - { - tab->setY(int(mTabs[i].first->getBorderSize())); - } - - x += tab->getWidth() + tab->getBorderSize() * 2; - } - } - - void TabbedArea::setWidth(int width) - { - Widget::setWidth(width); - adjustSize(); - } + void TabbedArea::logic() + { + } - - void TabbedArea::setHeight(int height) - { - Widget::setHeight(height); - adjustSize(); - } + void TabbedArea::adjustSize() + { + auto max_tab_height = 0; + for (auto& mTab : mTabs) + { + if (mTab.first->getHeight() > max_tab_height) + { + max_tab_height = mTab.first->getHeight(); + } + } - void TabbedArea::setSize(int width, int height) - { - setWidth(width); - setHeight(height); - } - - void TabbedArea::setDimension(const Rectangle& dimension) - { - setX(dimension.x); - setY(dimension.y); - setWidth(dimension.width); - setHeight(dimension.height); - } + if (getHeight() < max_tab_height) + { + mTabContainer->setHeight(max_tab_height); + } + else + { + mTabContainer->setHeight(max_tab_height); + mWidgetContainer->setHeight(getHeight() - max_tab_height - 1); + mWidgetContainer->setY(max_tab_height + 1); + } - void TabbedArea::keyPressed(KeyEvent& keyEvent) - { - if (keyEvent.isConsumed() || !isFocused()) - { - return; - } - - if (keyEvent.getKey().getValue() == Key::LEFT) - { - auto index = getSelectedTabIndex(); - index--; - - if (index < 0) - { - return; - } - else - { - setSelectedTab(mTabs[index].first); - } - - keyEvent.consume(); - } - else if (keyEvent.getKey().getValue() == Key::RIGHT) - { - auto index = getSelectedTabIndex(); - index++; - - if (index >= int(mTabs.size())) - { - return; - } - else - { - setSelectedTab(mTabs[index].first); - } - - keyEvent.consume(); - } - } - + mTabContainer->setWidth(getWidth()); + mWidgetContainer->setWidth(getWidth()); + } - void TabbedArea::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.isConsumed() - && mouseEvent.getSource()->isFocusable()) - { - return; - } - - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - const auto widget = mTabContainer->getWidgetAt(mouseEvent.getX(), mouseEvent.getY()); - const auto tab = dynamic_cast(widget); + void TabbedArea::adjustTabPositions() + { + auto max_tab_height = 0; + unsigned int i; + for (i = 0; i < mTabs.size(); i++) + { + if (mTabs[i].first->getHeight() > max_tab_height) + { + max_tab_height = mTabs[i].first->getHeight(); + } + } - if (tab != NULL) - { - setSelectedTab(tab); - } - } + auto x = 0; + for (i = 0; i < mTabs.size(); i++) + { + auto* tab = mTabs[i].first; - requestFocus(); - } + if (x == 0) + { + x = tab->getBorderSize() + 2; + } - void TabbedArea::death(const Event& event) - { - const auto source = event.getSource(); - const auto tab = dynamic_cast(source); + tab->setX(x); - if (tab != NULL) - { - removeTab(tab); - } - else - { - BasicContainer::death(event); - } - } + if (tab->getHeight() < max_tab_height) + { + tab->setY(max_tab_height + - tab->getHeight() + + static_cast(tab->getBorderSize())); + } + else + { + tab->setY(static_cast(mTabs[i].first->getBorderSize())); + } - void TabbedArea::action(const ActionEvent& actionEvent) - { - const auto source = actionEvent.getSource(); - const auto tab = dynamic_cast(source); + x += tab->getWidth() + tab->getBorderSize() * 2; + } + } - if (tab == NULL) - { - throw GCN_EXCEPTION("Received an action from a widget that's not a tab!"); - } + void TabbedArea::setWidth(int width) + { + Widget::setWidth(width); + adjustSize(); + } - setSelectedTab(tab); - } + + void TabbedArea::setHeight(int height) + { + Widget::setHeight(height); + adjustSize(); + } + + void TabbedArea::setSize(int width, int height) + { + setWidth(width); + setHeight(height); + } + + void TabbedArea::setDimension(const Rectangle& dimension) + { + setX(dimension.x); + setY(dimension.y); + setWidth(dimension.width); + setHeight(dimension.height); + } + + void TabbedArea::keyPressed(KeyEvent& keyEvent) + { + if (keyEvent.isConsumed() || !isFocused()) + { + return; + } + + if (keyEvent.getKey().getValue() == Key::LEFT) + { + auto index = getSelectedTabIndex(); + index--; + + if (index < 0) + { + return; + } + setSelectedTab(mTabs[index].first); + + keyEvent.consume(); + } + else if (keyEvent.getKey().getValue() == Key::RIGHT) + { + auto index = getSelectedTabIndex(); + index++; + + if (index >= static_cast(mTabs.size())) + { + return; + } + setSelectedTab(mTabs[index].first); + + keyEvent.consume(); + } + } + + + void TabbedArea::mousePressed(MouseEvent& mouseEvent) + { + if (mouseEvent.isConsumed() + && mouseEvent.getSource()->isFocusable()) + { + return; + } + + if (mouseEvent.getButton() == MouseEvent::LEFT) + { + auto* const widget = mTabContainer->getWidgetAt(mouseEvent.getX(), mouseEvent.getY()); + auto* const tab = dynamic_cast(widget); + + if (tab != nullptr) + { + setSelectedTab(tab); + } + } + + requestFocus(); + } + + void TabbedArea::death(const Event& event) + { + auto* const source = event.getSource(); + auto* const tab = dynamic_cast(source); + + if (tab != nullptr) + { + removeTab(tab); + } + else + { + BasicContainer::death(event); + } + } + + void TabbedArea::action(const ActionEvent& actionEvent) + { + auto* const source = actionEvent.getSource(); + auto* const tab = dynamic_cast(source); + + if (tab == nullptr) + { + throw GCN_EXCEPTION("Received an action from a widget that's not a tab!"); + } + + setSelectedTab(tab); + } } diff --git a/external/libguisan/src/widgets/textbox.cpp b/external/libguisan/src/widgets/textbox.cpp index 7f279c93..fdf5624f 100644 --- a/external/libguisan/src/widgets/textbox.cpp +++ b/external/libguisan/src/widgets/textbox.cpp @@ -68,484 +68,485 @@ namespace gcn { - TextBox::TextBox() - { - mCaretColumn = 0; - mCaretRow = 0; - mEditable = true; - mOpaque = true; - - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - TextBox::adjustSize(); - setBorderSize(1); - setText(""); - } - - TextBox::TextBox(const std::string& text) - { - mCaretColumn = 0; - mCaretRow = 0; - mEditable = true; - mOpaque = true; - - setText(text); - - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - TextBox::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 = int(pos - lastPos); - } - else - { - length = int(text.size() - lastPos); - } - auto sub = text.substr(lastPos, length); - mTextRows.push_back(sub); - lastPos = pos + 1; - - } while (pos != std::string::npos); - - adjustSize(); - } - - void TextBox::draw(Graphics* graphics) - { - if (mOpaque) - { - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - } - - if (isFocused() && isEditable()) - { - drawCaret(graphics, getFont()->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn)), mCaretRow * getFont()->getHeight()); - } - - graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); - - for (auto i = 0; i < int(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) - { - const auto width = getWidth() + int(getBorderSize()) * 2 - 1; - const auto height = getHeight() + int(getBorderSize()) * 2 - 1; - - graphics->setColor(getBackgroundColor()); - - for (auto i = 0; i < int(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::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mCaretRow = mouseEvent.getY() / getFont()->getHeight(); - - if (mCaretRow >= int(mTextRows.size())) - { - mCaretRow = int(mTextRows.size()) - 1; - } - - mCaretColumn = getFont()->getStringIndexAt(mTextRows[mCaretRow], mouseEvent.getX()); - } - } - - void TextBox::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } - - void TextBox::keyPressed(KeyEvent& keyEvent) - { - const auto key = keyEvent.getKey(); - - if (key.getValue() == Key::LEFT) - { - --mCaretColumn; - if (mCaretColumn < 0) - { - --mCaretRow; - - if (mCaretRow < 0) - { - mCaretRow = 0; - mCaretColumn = 0; - } - else - { - mCaretColumn = mTextRows[mCaretRow].size(); - } - } - } - - else if (key.getValue() == Key::RIGHT) - { - ++mCaretColumn; - if (mCaretColumn > int(mTextRows[mCaretRow].size())) - { - ++mCaretRow; - - if (mCaretRow >= int(mTextRows.size())) - { - mCaretRow = int(mTextRows.size()) - 1; - if (mCaretRow < 0) - { - mCaretRow = 0; - } - - mCaretColumn = mTextRows[mCaretRow].size(); - } - else - { - mCaretColumn = 0; - } - } - } - - else if (key.getValue() == Key::DOWN) - { - setCaretRow(mCaretRow + 1); - } - - else if (key.getValue() == Key::UP) - { - setCaretRow(mCaretRow - 1); - } - - else if (key.getValue() == Key::HOME) - { - mCaretColumn = 0; - } - - else if (key.getValue() == Key::END) - { - mCaretColumn = mTextRows[mCaretRow].size(); - } - - else if (key.getValue() == Key::ENTER && mEditable) - { - mTextRows.insert(mTextRows.begin() + mCaretRow + 1, - mTextRows[mCaretRow].substr(mCaretColumn, mTextRows[mCaretRow].size() - mCaretColumn)); - mTextRows[mCaretRow].resize(mCaretColumn); - ++mCaretRow; - mCaretColumn = 0; - } - - else if (key.getValue() == Key::BACKSPACE - && mCaretColumn != 0 - && mEditable) - { - mTextRows[mCaretRow].erase(mCaretColumn - 1, 1); - --mCaretColumn; - } - - else if (key.getValue() == Key::BACKSPACE - && mCaretColumn == 0 - && mCaretRow != 0 - && mEditable) - { - mCaretColumn = mTextRows[mCaretRow - 1].size(); - mTextRows[mCaretRow - 1] += mTextRows[mCaretRow]; - mTextRows.erase(mTextRows.begin() + mCaretRow); - --mCaretRow; - } - - else if (key.getValue() == Key::DELETE - && mCaretColumn < int(mTextRows[mCaretRow].size()) - && mEditable) - { - mTextRows[mCaretRow].erase(mCaretColumn, 1); - } - - else if (key.getValue() == Key::DELETE - && mCaretColumn == int(mTextRows[mCaretRow].size()) - && mCaretRow < int(mTextRows.size()) - 1 - && mEditable) - { - mTextRows[mCaretRow] += mTextRows[mCaretRow + 1]; - mTextRows.erase(mTextRows.begin() + mCaretRow + 1); - } - - else if(key.getValue() == Key::PAGE_UP) - { - auto par = getParent(); - - if (par != NULL) - { - const auto rowsPerPage = par->getChildrenArea().height / getFont()->getHeight(); - mCaretRow -= rowsPerPage; - - if (mCaretRow < 0) - { - mCaretRow = 0; - } - } - } - - else if(key.getValue() == Key::PAGE_DOWN) - { - auto par = getParent(); - - if (par != NULL) - { - const auto rowsPerPage = par->getChildrenArea().height / getFont()->getHeight(); - mCaretRow += rowsPerPage; - - if (mCaretRow >= int(mTextRows.size())) - { - mCaretRow = int(mTextRows.size()) - 1; - } - } - } - - else if(key.getValue() == Key::TAB - && mEditable) - { - mTextRows[mCaretRow].insert(mCaretColumn,std::string(" ")); - mCaretColumn += 4; - } - - else if (key.isCharacter() - && mEditable) - { - if(keyEvent.isShiftPressed() && key.isLetter()) - { - mTextRows[mCaretRow].insert(mCaretColumn,std::string(1,char(key.getValue() - 32))); - } - else - { - mTextRows[mCaretRow].insert(mCaretColumn,std::string(1,key.getChar())); - } - ++mCaretColumn; - } - - adjustSize(); - scrollToCaret(); - - keyEvent.consume(); - } - - void TextBox::adjustSize() - { - auto width = 0; - for (const auto& mTextRow : mTextRows) - { - const auto w = getFont()->getWidth(mTextRow); - if (width < w) - { - width = w; - } - } - - setWidth(width + 1); - setHeight(getFont()->getHeight() * int(mTextRows.size())); - } - - void TextBox::setCaretPosition(unsigned int position) - { - for (auto row = 0; row < int(mTextRows.size()); row++) - { - if (position <= mTextRows[row].size()) - { - mCaretRow = row; - mCaretColumn = int(position); - return; // we are done - } - position--; - } - - // position beyond end of text - mCaretRow = int(mTextRows.size()) - 1; - mCaretColumn = mTextRows[mCaretRow].size(); - } - - unsigned int TextBox::getCaretPosition() const - { - auto pos = 0; - - for (auto 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 = int(mTextRows.size()) - 1; - } - - if (mCaretRow < 0) - { - mCaretRow = 0; - } - - setCaretColumn(mCaretColumn); - } - - unsigned int TextBox::getCaretRow() const - { - return mCaretRow; - } - - void TextBox::setCaretColumn(int column) - { - mCaretColumn = column; - - if (mCaretColumn > int(mTextRows[mCaretRow].size())) - { - mCaretColumn = mTextRows[mCaretRow].size(); - } - - if (mCaretColumn < 0) - { - mCaretColumn = 0; - } - } - - unsigned int TextBox::getCaretColumn() const - { - return mCaretColumn; - } - - const std::string& TextBox::getTextRow(int row) const - { - return mTextRows[row]; - } - - void TextBox::setTextRow(int row, const std::string& text) - { - mTextRows[row] = text; - - if (mCaretRow == row) - { - setCaretColumn(mCaretColumn); - } - - adjustSize(); - } - - unsigned int TextBox::getNumberOfRows() const - { - return mTextRows.size(); - } - - std::string TextBox::getText() const - { - if (mTextRows.empty()) - { - return std::string(""); - } - - int i; - std::string text; - - for (i = 0; i < int(mTextRows.size()) - 1; ++i) - { - text = text.append(mTextRows[i]).append("\n"); - } - - text += mTextRows[i]; - - return text; - } - - void TextBox::fontChanged() - { - adjustSize(); - } - - void TextBox::scrollToCaret() - { - auto 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); - } - - 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; - } + TextBox::TextBox() + { + mCaretColumn = 0; + mCaretRow = 0; + mEditable = true; + mOpaque = true; + + setFocusable(true); + + addMouseListener(this); + addKeyListener(this); + TextBox::adjustSize(); + setBorderSize(1); + setText(""); + } + + TextBox::TextBox(const std::string& text) + { + mCaretColumn = 0; + mCaretRow = 0; + mEditable = true; + mOpaque = true; + + setText(text); + + setFocusable(true); + + addMouseListener(this); + addKeyListener(this); + TextBox::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 = static_cast(pos - lastPos); + } + else + { + length = static_cast(text.size() - lastPos); + } + auto sub = text.substr(lastPos, length); + mTextRows.push_back(sub); + lastPos = pos + 1; + } + while (pos != std::string::npos); + + adjustSize(); + } + + void TextBox::draw(Graphics* graphics) + { + if (mOpaque) + { + graphics->setColor(getBackgroundColor()); + graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); + } + + if (isFocused() && isEditable()) + { + drawCaret(graphics, getFont()->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn)), + mCaretRow * getFont()->getHeight()); + } + + graphics->setColor(getForegroundColor()); + graphics->setFont(getFont()); + + for (auto i = 0; i < static_cast(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) + { + const auto width = getWidth() + static_cast(getBorderSize()) * 2 - 1; + const auto height = getHeight() + static_cast(getBorderSize()) * 2 - 1; + + graphics->setColor(getBackgroundColor()); + + for (auto i = 0; i < static_cast(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::mousePressed(MouseEvent& mouseEvent) + { + if (mouseEvent.getButton() == MouseEvent::LEFT) + { + mCaretRow = mouseEvent.getY() / getFont()->getHeight(); + + if (mCaretRow >= static_cast(mTextRows.size())) + { + mCaretRow = static_cast(mTextRows.size()) - 1; + } + + mCaretColumn = getFont()->getStringIndexAt(mTextRows[mCaretRow], mouseEvent.getX()); + } + } + + void TextBox::mouseDragged(MouseEvent& mouseEvent) + { + mouseEvent.consume(); + } + + void TextBox::keyPressed(KeyEvent& keyEvent) + { + const auto key = keyEvent.getKey(); + + if (key.getValue() == Key::LEFT) + { + --mCaretColumn; + if (mCaretColumn < 0) + { + --mCaretRow; + + if (mCaretRow < 0) + { + mCaretRow = 0; + mCaretColumn = 0; + } + else + { + mCaretColumn = mTextRows[mCaretRow].size(); + } + } + } + + else if (key.getValue() == Key::RIGHT) + { + ++mCaretColumn; + if (mCaretColumn > static_cast(mTextRows[mCaretRow].size())) + { + ++mCaretRow; + + if (mCaretRow >= static_cast(mTextRows.size())) + { + mCaretRow = static_cast(mTextRows.size()) - 1; + if (mCaretRow < 0) + { + mCaretRow = 0; + } + + mCaretColumn = mTextRows[mCaretRow].size(); + } + else + { + mCaretColumn = 0; + } + } + } + + else if (key.getValue() == Key::DOWN) + { + setCaretRow(mCaretRow + 1); + } + + else if (key.getValue() == Key::UP) + { + setCaretRow(mCaretRow - 1); + } + + else if (key.getValue() == Key::HOME) + { + mCaretColumn = 0; + } + + else if (key.getValue() == Key::END) + { + mCaretColumn = mTextRows[mCaretRow].size(); + } + + else if (key.getValue() == Key::ENTER && mEditable) + { + mTextRows.insert(mTextRows.begin() + mCaretRow + 1, + mTextRows[mCaretRow].substr(mCaretColumn, mTextRows[mCaretRow].size() - mCaretColumn)); + mTextRows[mCaretRow].resize(mCaretColumn); + ++mCaretRow; + mCaretColumn = 0; + } + + else if (key.getValue() == Key::BACKSPACE + && mCaretColumn != 0 + && mEditable) + { + mTextRows[mCaretRow].erase(mCaretColumn - 1, 1); + --mCaretColumn; + } + + else if (key.getValue() == Key::BACKSPACE + && mCaretColumn == 0 + && mCaretRow != 0 + && mEditable) + { + mCaretColumn = mTextRows[mCaretRow - 1].size(); + mTextRows[mCaretRow - 1] += mTextRows[mCaretRow]; + mTextRows.erase(mTextRows.begin() + mCaretRow); + --mCaretRow; + } + + else if (key.getValue() == Key::DELETE + && mCaretColumn < static_cast(mTextRows[mCaretRow].size()) + && mEditable) + { + mTextRows[mCaretRow].erase(mCaretColumn, 1); + } + + else if (key.getValue() == Key::DELETE + && mCaretColumn == static_cast(mTextRows[mCaretRow].size()) + && mCaretRow < static_cast(mTextRows.size()) - 1 + && mEditable) + { + mTextRows[mCaretRow] += mTextRows[mCaretRow + 1]; + mTextRows.erase(mTextRows.begin() + mCaretRow + 1); + } + + else if (key.getValue() == Key::PAGE_UP) + { + auto* par = getParent(); + + if (par != nullptr) + { + const auto rowsPerPage = par->getChildrenArea().height / getFont()->getHeight(); + mCaretRow -= rowsPerPage; + + if (mCaretRow < 0) + { + mCaretRow = 0; + } + } + } + + else if (key.getValue() == Key::PAGE_DOWN) + { + auto* par = getParent(); + + if (par != nullptr) + { + const auto rowsPerPage = par->getChildrenArea().height / getFont()->getHeight(); + mCaretRow += rowsPerPage; + + if (mCaretRow >= static_cast(mTextRows.size())) + { + mCaretRow = static_cast(mTextRows.size()) - 1; + } + } + } + + else if (key.getValue() == Key::TAB + && mEditable) + { + mTextRows[mCaretRow].insert(mCaretColumn, std::string(" ")); + mCaretColumn += 4; + } + + else if (key.isCharacter() + && mEditable) + { + if (keyEvent.isShiftPressed() && key.isLetter()) + { + mTextRows[mCaretRow].insert(mCaretColumn, std::string(1, static_cast(key.getValue() - 32))); + } + else + { + mTextRows[mCaretRow].insert(mCaretColumn, std::string(1, key.getChar())); + } + ++mCaretColumn; + } + + adjustSize(); + scrollToCaret(); + + keyEvent.consume(); + } + + void TextBox::adjustSize() + { + auto width = 0; + for (const auto& mTextRow : mTextRows) + { + const auto w = getFont()->getWidth(mTextRow); + if (width < w) + { + width = w; + } + } + + setWidth(width + 1); + setHeight(getFont()->getHeight() * static_cast(mTextRows.size())); + } + + void TextBox::setCaretPosition(unsigned int position) + { + for (auto row = 0; row < static_cast(mTextRows.size()); row++) + { + if (position <= mTextRows[row].size()) + { + mCaretRow = row; + mCaretColumn = static_cast(position); + return; // we are done + } + position--; + } + + // position beyond end of text + mCaretRow = static_cast(mTextRows.size()) - 1; + mCaretColumn = mTextRows[mCaretRow].size(); + } + + unsigned int TextBox::getCaretPosition() const + { + auto pos = 0; + + for (auto 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 >= static_cast(mTextRows.size())) + { + mCaretRow = static_cast(mTextRows.size()) - 1; + } + + if (mCaretRow < 0) + { + mCaretRow = 0; + } + + setCaretColumn(mCaretColumn); + } + + unsigned int TextBox::getCaretRow() const + { + return mCaretRow; + } + + void TextBox::setCaretColumn(int column) + { + mCaretColumn = column; + + if (mCaretColumn > static_cast(mTextRows[mCaretRow].size())) + { + mCaretColumn = mTextRows[mCaretRow].size(); + } + + if (mCaretColumn < 0) + { + mCaretColumn = 0; + } + } + + unsigned int TextBox::getCaretColumn() const + { + return mCaretColumn; + } + + const std::string& TextBox::getTextRow(int row) const + { + return mTextRows[row]; + } + + void TextBox::setTextRow(int row, const std::string& text) + { + mTextRows[row] = text; + + if (mCaretRow == row) + { + setCaretColumn(mCaretColumn); + } + + adjustSize(); + } + + unsigned int TextBox::getNumberOfRows() const + { + return mTextRows.size(); + } + + std::string TextBox::getText() const + { + if (mTextRows.empty()) + { + return std::string(""); + } + + int i; + std::string text; + + for (i = 0; i < static_cast(mTextRows.size()) - 1; ++i) + { + text = text.append(mTextRows[i]).append("\n"); + } + + text += mTextRows[i]; + + return text; + } + + void TextBox::fontChanged() + { + adjustSize(); + } + + void TextBox::scrollToCaret() + { + auto* par = getParent(); + if (par == nullptr) + { + 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); + } + + 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() const + { + return mOpaque; + } + + void TextBox::setOpaque(bool opaque) + { + mOpaque = opaque; + } } diff --git a/external/libguisan/src/widgets/textfield.cpp b/external/libguisan/src/widgets/textfield.cpp index 14b3790d..58bb37e1 100644 --- a/external/libguisan/src/widgets/textfield.cpp +++ b/external/libguisan/src/widgets/textfield.cpp @@ -67,225 +67,225 @@ namespace gcn { - TextField::TextField() - { - mCaretPosition = 0; - mXScroll = 0; + TextField::TextField() + { + mCaretPosition = 0; + mXScroll = 0; - setFocusable(true); + setFocusable(true); - addMouseListener(this); - addKeyListener(this); - adjustHeight(); - setBorderSize(1); - } + addMouseListener(this); + addKeyListener(this); + adjustHeight(); + setBorderSize(1); + } - TextField::TextField(const std::string& text) - { - mCaretPosition = 0; - mXScroll = 0; + TextField::TextField(const std::string& text) + { + mCaretPosition = 0; + mXScroll = 0; - mText = text; - adjustSize(); - setBorderSize(1); + mText = text; + adjustSize(); + setBorderSize(1); - setFocusable(true); + setFocusable(true); - addMouseListener(this); - addKeyListener(this); - } + addMouseListener(this); + addKeyListener(this); + } - void TextField::setText(const std::string& text) - { - if(text.size() < mCaretPosition ) - { - mCaretPosition = text.size(); - } + void TextField::setText(const std::string& text) + { + if (text.size() < mCaretPosition) + { + mCaretPosition = text.size(); + } - mText = text; - } + mText = text; + } - void TextField::draw(Graphics* graphics) - { - const auto faceColor = getBackgroundColor(); - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); + void TextField::draw(Graphics* graphics) + { + const auto faceColor = getBackgroundColor(); + graphics->setColor(faceColor); + graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - if (isFocused()) - { - drawCaret(graphics, getFont()->getWidth(mText.substr(0, mCaretPosition)) - mXScroll); - } + if (isFocused()) + { + drawCaret(graphics, getFont()->getWidth(mText.substr(0, mCaretPosition)) - mXScroll); + } - graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); - graphics->drawText(mText, 1 - mXScroll, 1); - } + graphics->setColor(getForegroundColor()); + graphics->setFont(getFont()); + graphics->drawText(mText, 1 - mXScroll, 1); + } - void TextField::drawBorder(Graphics* graphics) - { - const auto faceColor = getBaseColor(); - const auto alpha = getBaseColor().a; - const auto width = getWidth() + int(getBorderSize()) * 2 - 1; - const auto height = getHeight() + int(getBorderSize()) * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + void TextField::drawBorder(Graphics* graphics) + { + const auto faceColor = getBaseColor(); + const auto alpha = getBaseColor().a; + const auto width = getWidth() + static_cast(getBorderSize()) * 2 - 1; + const auto height = getHeight() + static_cast(getBorderSize()) * 2 - 1; + auto highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + auto shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - for (auto i = 0; i < int(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); - } - } + for (auto i = 0; i < static_cast(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::drawCaret(Graphics* graphics, int x) + { + graphics->setColor(getForegroundColor()); + graphics->drawLine(x, getHeight() - 2, x, 1); + } - void TextField::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mCaretPosition = getFont()->getStringIndexAt(mText, mouseEvent.getX() + mXScroll); - fixScroll(); - } - } + void TextField::mousePressed(MouseEvent& mouseEvent) + { + if (mouseEvent.getButton() == MouseEvent::LEFT) + { + mCaretPosition = getFont()->getStringIndexAt(mText, mouseEvent.getX() + mXScroll); + fixScroll(); + } + } - void TextField::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } - - void TextField::keyPressed(KeyEvent& keyEvent) - { - const auto key = keyEvent.getKey(); + void TextField::mouseDragged(MouseEvent& mouseEvent) + { + mouseEvent.consume(); + } - if (key.getValue() == Key::LEFT && mCaretPosition > 0) - { - --mCaretPosition; - } + void TextField::keyPressed(KeyEvent& keyEvent) + { + const auto key = keyEvent.getKey(); - else if (key.getValue() == Key::RIGHT && mCaretPosition < mText.size()) - { - ++mCaretPosition; - } + if (key.getValue() == Key::LEFT && mCaretPosition > 0) + { + --mCaretPosition; + } - else if (key.getValue() == Key::DELETE && mCaretPosition < mText.size()) - { - mText.erase(mCaretPosition, 1); - } + else if (key.getValue() == Key::RIGHT && mCaretPosition < mText.size()) + { + ++mCaretPosition; + } - else if (key.getValue() == Key::BACKSPACE && mCaretPosition > 0) - { - mText.erase(mCaretPosition - 1, 1); - --mCaretPosition; - } + else if (key.getValue() == Key::DELETE && mCaretPosition < mText.size()) + { + mText.erase(mCaretPosition, 1); + } - else if (key.getValue() == Key::ENTER) - { - generateAction(); - } + else if (key.getValue() == Key::BACKSPACE && mCaretPosition > 0) + { + mText.erase(mCaretPosition - 1, 1); + --mCaretPosition; + } - else if (key.getValue() == Key::HOME) - { - mCaretPosition = 0; - } + else if (key.getValue() == Key::ENTER) + { + generateAction(); + } - else if (key.getValue() == Key::END) - { - mCaretPosition = mText.size(); - } + else if (key.getValue() == Key::HOME) + { + mCaretPosition = 0; + } - else if (key.isCharacter() - && key.getValue() != Key::TAB) - { - if(keyEvent.isShiftPressed() && key.isLetter()) - { - mText.insert(mCaretPosition, std::string(1,char(key.getValue() - 32))); - } - else - { - mText.insert(mCaretPosition, std::string(1,char(key.getValue()))); - } - ++mCaretPosition; - } + else if (key.getValue() == Key::END) + { + mCaretPosition = mText.size(); + } - if (key.getValue() != Key::TAB) - { - keyEvent.consume(); - } - - fixScroll(); - } + else if (key.isCharacter() + && key.getValue() != Key::TAB) + { + if (keyEvent.isShiftPressed() && key.isLetter()) + { + mText.insert(mCaretPosition, std::string(1, static_cast(key.getValue() - 32))); + } + else + { + mText.insert(mCaretPosition, std::string(1, static_cast(key.getValue()))); + } + ++mCaretPosition; + } - void TextField::adjustSize() - { - setWidth(getFont()->getWidth(mText) + 4); - adjustHeight(); + if (key.getValue() != Key::TAB) + { + keyEvent.consume(); + } - fixScroll(); - } + fixScroll(); + } - void TextField::adjustHeight() - { - setHeight(getFont()->getHeight() + 2); - } + void TextField::adjustSize() + { + setWidth(getFont()->getWidth(mText) + 4); + adjustHeight(); - void TextField::fixScroll() - { - if (isFocused()) - { - const auto caretX = getFont()->getWidth(mText.substr(0, mCaretPosition)); + fixScroll(); + } - if (caretX - mXScroll > getWidth() - 4) - { - mXScroll = caretX - getWidth() + 4; - } - else if (caretX - mXScroll < getFont()->getWidth(" ")) - { - mXScroll = caretX - getFont()->getWidth(" "); + void TextField::adjustHeight() + { + setHeight(getFont()->getHeight() + 2); + } - if (mXScroll < 0) - { - mXScroll = 0; - } - } - } - } + void TextField::fixScroll() + { + if (isFocused()) + { + const auto caretX = getFont()->getWidth(mText.substr(0, mCaretPosition)); - void TextField::setCaretPosition(unsigned int position) - { - if (position > mText.size()) - { - mCaretPosition = mText.size(); - } - else - { - mCaretPosition = position; - } + if (caretX - mXScroll > getWidth() - 4) + { + mXScroll = caretX - getWidth() + 4; + } + else if (caretX - mXScroll < getFont()->getWidth(" ")) + { + mXScroll = caretX - getFont()->getWidth(" "); - fixScroll(); - } + if (mXScroll < 0) + { + mXScroll = 0; + } + } + } + } - unsigned int TextField::getCaretPosition() const - { - return mCaretPosition; - } + void TextField::setCaretPosition(unsigned int position) + { + if (position > mText.size()) + { + mCaretPosition = mText.size(); + } + else + { + mCaretPosition = position; + } - const std::string& TextField::getText() const - { - return mText; - } + fixScroll(); + } - void TextField::fontChanged() - { - fixScroll(); - } + unsigned int TextField::getCaretPosition() const + { + return mCaretPosition; + } + + const std::string& TextField::getText() const + { + return mText; + } + + void TextField::fontChanged() + { + fixScroll(); + } } diff --git a/external/libguisan/src/widgets/togglebutton.cpp b/external/libguisan/src/widgets/togglebutton.cpp index d2943b78..68f5aa81 100644 --- a/external/libguisan/src/widgets/togglebutton.cpp +++ b/external/libguisan/src/widgets/togglebutton.cpp @@ -69,135 +69,133 @@ namespace gcn { - ToggleButton::ToggleButton() - : Button(), mSelected(false) - { - - } + ToggleButton::ToggleButton() + : Button(), mSelected(false) + { + } - ToggleButton::ToggleButton(const std::string& caption) - : Button(caption), mSelected(false) - { - - } + ToggleButton::ToggleButton(const std::string& caption) + : Button(caption), mSelected(false) + { + } - void ToggleButton::draw(Graphics* graphics) - { - auto faceColor = getBaseColor(); - Color highlightColor, shadowColor; - const auto alpha = getBaseColor().a; + void ToggleButton::draw(Graphics* graphics) + { + auto faceColor = getBaseColor(); + Color highlightColor, shadowColor; + const auto alpha = getBaseColor().a; - if (isPressed() || isSelected()) - { - faceColor = faceColor - 0x303030; - faceColor.a = alpha; - highlightColor = faceColor - 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor + 0x303030; - shadowColor.a = alpha; - } - else - { - highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - } + if (isPressed() || isSelected()) + { + faceColor = faceColor - 0x303030; + faceColor.a = alpha; + highlightColor = faceColor - 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor + 0x303030; + shadowColor.a = alpha; + } + else + { + highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; + } - graphics->setColor(faceColor); - graphics->fillRectangle(Rectangle(1, 1, getDimension().width-1, getHeight() - 1)); + graphics->setColor(faceColor); + graphics->fillRectangle(Rectangle(1, 1, getDimension().width - 1, getHeight() - 1)); - graphics->setColor(highlightColor); - graphics->drawLine(0, 0, getWidth() - 1, 0); - graphics->drawLine(0, 1, 0, getHeight() - 1); + graphics->setColor(highlightColor); + graphics->drawLine(0, 0, getWidth() - 1, 0); + graphics->drawLine(0, 1, 0, getHeight() - 1); - graphics->setColor(shadowColor); - graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1); - graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1); + graphics->setColor(shadowColor); + graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1); + graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1); - graphics->setColor(getForegroundColor()); + graphics->setColor(getForegroundColor()); - int text_x; - const auto text_y = getHeight() / 2 - getFont()->getHeight() / 2; + int text_x; + const auto text_y = getHeight() / 2 - getFont()->getHeight() / 2; - switch (getAlignment()) - { - case Graphics::LEFT: - text_x = int(mSpacing); - break; - case Graphics::CENTER: - text_x = getWidth() / 2; - break; - case Graphics::RIGHT: - text_x = getWidth() - int(mSpacing); - break; - default: - throw GCN_EXCEPTION("Unknown alignment."); - } + switch (getAlignment()) + { + case Graphics::LEFT: + text_x = static_cast(mSpacing); + break; + case Graphics::CENTER: + text_x = getWidth() / 2; + break; + case Graphics::RIGHT: + text_x = getWidth() - static_cast(mSpacing); + break; + default: + throw GCN_EXCEPTION("Unknown alignment."); + } - graphics->setFont(getFont()); + graphics->setFont(getFont()); - if (isPressed() || isSelected()) - { - graphics->drawText(getCaption(), text_x + 1, text_y + 1, getAlignment()); - } - else - { - graphics->drawText(getCaption(), text_x, text_y, getAlignment()); + if (isPressed() || isSelected()) + { + graphics->drawText(getCaption(), text_x + 1, text_y + 1, getAlignment()); + } + else + { + graphics->drawText(getCaption(), text_x, text_y, getAlignment()); - if (isFocused()) - { - graphics->drawRectangle(Rectangle(2, 2, getWidth() - 4, - getHeight() - 4)); - } - } - } - - bool ToggleButton::isSelected() const - { - return mSelected; - } + if (isFocused()) + { + graphics->drawRectangle(Rectangle(2, 2, getWidth() - 4, + getHeight() - 4)); + } + } + } - void ToggleButton::setSelected(bool selected) - { - mSelected = selected; - } + bool ToggleButton::isSelected() const + { + return mSelected; + } - void ToggleButton::mouseReleased(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT - && mMousePressed - && mHasMouse) - { - mMousePressed = false; - toggleSelected(); - generateAction(); - mouseEvent.consume(); - } - else if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mMousePressed = false; - mouseEvent.consume(); - } - } + void ToggleButton::setSelected(bool selected) + { + mSelected = selected; + } - void ToggleButton::keyReleased(KeyEvent& keyEvent) - { - const auto key = keyEvent.getKey(); + void ToggleButton::mouseReleased(MouseEvent& mouseEvent) + { + if (mouseEvent.getButton() == MouseEvent::LEFT + && mMousePressed + && mHasMouse) + { + mMousePressed = false; + toggleSelected(); + generateAction(); + mouseEvent.consume(); + } + else if (mouseEvent.getButton() == MouseEvent::LEFT) + { + mMousePressed = false; + mouseEvent.consume(); + } + } - if ((key.getValue() == Key::ENTER - || key.getValue() == Key::SPACE) - && mKeyPressed) - { - mKeyPressed = false; - toggleSelected(); - generateAction(); - keyEvent.consume(); - } - } - - void ToggleButton::toggleSelected() - { - mSelected = !mSelected; - } + void ToggleButton::keyReleased(KeyEvent& keyEvent) + { + const auto key = keyEvent.getKey(); + + if ((key.getValue() == Key::ENTER + || key.getValue() == Key::SPACE) + && mKeyPressed) + { + mKeyPressed = false; + toggleSelected(); + generateAction(); + keyEvent.consume(); + } + } + + void ToggleButton::toggleSelected() + { + mSelected = !mSelected; + } } diff --git a/external/libguisan/src/widgets/window.cpp b/external/libguisan/src/widgets/window.cpp index 0890e532..d8f9b520 100644 --- a/external/libguisan/src/widgets/window.cpp +++ b/external/libguisan/src/widgets/window.cpp @@ -67,274 +67,275 @@ namespace gcn { - Window::Window() - :mIsMoving(false) - { - setBorderSize(1); - setPadding(2); - setTitleBarHeight(16); - setAlignment(Graphics::CENTER); - addMouseListener(this); - setMovable(true); - setOpaque(true); - } + Window::Window() + : mIsMoving(false) + { + setBorderSize(1); + Window::setPadding(2); + Window::setTitleBarHeight(16); + Window::setAlignment(Graphics::CENTER); + addMouseListener(this); + setMovable(true); + Window::setOpaque(true); + } - Window::Window(const std::string& caption) - :mIsMoving(false) - { - setCaption(caption); - setBorderSize(1); - setPadding(2); - setTitleBarHeight(16); - setAlignment(Graphics::CENTER); - addMouseListener(this); - setMovable(true); - setOpaque(true); - } + Window::Window(const std::string& caption) + : mIsMoving(false) + { + Window::setCaption(caption); + setBorderSize(1); + Window::setPadding(2); + Window::setTitleBarHeight(16); + Window::setAlignment(Graphics::CENTER); + addMouseListener(this); + setMovable(true); + Window::setOpaque(true); + } - Window::~Window() - = default; + Window::~Window() + = default; - void Window::setPadding(unsigned int padding) - { - mPadding = padding; - } + void Window::setPadding(unsigned int padding) + { + mPadding = padding; + } - unsigned int Window::getPadding() const - { - return mPadding; - } + unsigned int Window::getPadding() const + { + return mPadding; + } - void Window::setTitleBarHeight(unsigned int height) - { - mTitleBarHeight = height; - } + void Window::setTitleBarHeight(unsigned int height) + { + mTitleBarHeight = height; + } - unsigned int Window::getTitleBarHeight() - { - return mTitleBarHeight; - } + unsigned int Window::getTitleBarHeight() + { + return mTitleBarHeight; + } - void Window::setCaption(const std::string& caption) - { - mCaption = caption; - } + void Window::setCaption(const std::string& caption) + { + mCaption = caption; + } - const std::string& Window::getCaption() const - { - return mCaption; - } + const std::string& Window::getCaption() const + { + return mCaption; + } - void Window::setAlignment(unsigned int alignment) - { - mAlignment = alignment; - } + void Window::setAlignment(unsigned int alignment) + { + mAlignment = alignment; + } - unsigned int Window::getAlignment() const - { - return mAlignment; - } + unsigned int Window::getAlignment() const + { + return mAlignment; + } - void Window::draw(Graphics* graphics) - { - const auto faceColor = getBaseColor(); - const auto alpha = getBaseColor().a; - //int width = getWidth() + getBorderSize() * 2 - 1; - //int height = getHeight() + getBorderSize() * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + void Window::draw(Graphics* graphics) + { + const auto faceColor = getBaseColor(); + const auto alpha = getBaseColor().a; + //int width = getWidth() + getBorderSize() * 2 - 1; + //int height = getHeight() + getBorderSize() * 2 - 1; + auto highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + auto shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - auto d = getChildrenArea(); + auto d = getChildrenArea(); - // Fill the background around the content - graphics->setColor(faceColor); - // Fill top - graphics->fillRectangle(Rectangle(0,0,getWidth(),d.y - 1)); - // Fill left - graphics->fillRectangle(Rectangle(0,d.y - 1, d.x - 1, getHeight() - d.y + 1)); - // Fill right - graphics->fillRectangle(Rectangle(d.x + d.width + 1, - d.y - 1, - getWidth() - d.x - d.width - 1, - getHeight() - d.y + 1)); - // Fill bottom - graphics->fillRectangle(Rectangle(d.x - 1, - d.y + d.height + 1, - d.width + 2, - getHeight() - d.height - d.y - 1)); + // 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); - } + 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; + // 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); + // 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); + // 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); + graphics->setColor(highlightColor); + // Right line + graphics->drawLine(d.x + d.width - 1, + d.y, + d.x + d.width - 1, + d.y + d.height - 2); + // Bottom line + graphics->drawLine(d.x + 1, + d.y + d.height - 1, + d.x + d.width - 1, + d.y + d.height - 1); - drawChildren(graphics); + drawChildren(graphics); - int text_x; + int text_x; - const auto text_y = (int(getTitleBarHeight()) - getFont()->getHeight()) / 2; + const auto text_y = (static_cast(getTitleBarHeight()) - getFont()->getHeight()) / 2; - switch (getAlignment()) - { - case Graphics::LEFT: - text_x = 4; - break; - case Graphics::CENTER: - text_x = getWidth() / 2; - break; - case Graphics::RIGHT: - text_x = getWidth() - 4; - break; - default: - throw GCN_EXCEPTION("Unknown alignment."); - } + switch (getAlignment()) + { + case Graphics::LEFT: + text_x = 4; + break; + case Graphics::CENTER: + text_x = getWidth() / 2; + break; + case Graphics::RIGHT: + text_x = getWidth() - 4; + break; + default: + throw GCN_EXCEPTION("Unknown alignment."); + } - graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); - graphics->pushClipArea(Rectangle(0, 0, getWidth(), int(getTitleBarHeight() - 1))); - graphics->drawText(getCaption(), text_x, text_y, getAlignment()); - graphics->popClipArea(); - } + graphics->setColor(getForegroundColor()); + graphics->setFont(getFont()); + graphics->pushClipArea(Rectangle(0, 0, getWidth(), static_cast(getTitleBarHeight() - 1))); + graphics->drawText(getCaption(), text_x, text_y, getAlignment()); + graphics->popClipArea(); + } - void Window::drawBorder(Graphics* graphics) - { - const auto faceColor = getBaseColor(); - const auto alpha = getBaseColor().a; - const auto width = getWidth() + int(getBorderSize()) * 2 - 1; - const auto height = getHeight() + int(getBorderSize()) * 2 - 1; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + void Window::drawBorder(Graphics* graphics) + { + const auto faceColor = getBaseColor(); + const auto alpha = getBaseColor().a; + const auto width = getWidth() + static_cast(getBorderSize()) * 2 - 1; + const auto height = getHeight() + static_cast(getBorderSize()) * 2 - 1; + auto highlightColor = faceColor + 0x303030; + highlightColor.a = alpha; + auto shadowColor = faceColor - 0x303030; + shadowColor.a = alpha; - for (auto i = 0; i < int(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); - } - } + for (auto i = 0; i < static_cast(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::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getSource() != this) - { - return; - } - - if (getParent() != NULL) - { - getParent()->moveToTop(this); - } + void Window::mousePressed(MouseEvent& mouseEvent) + { + if (mouseEvent.getSource() != this) + { + return; + } - mDragOffsetX = mouseEvent.getX(); - mDragOffsetY = mouseEvent.getY(); - - mIsMoving = mouseEvent.getY() <= int(mTitleBarHeight); - } + if (getParent() != nullptr) + { + getParent()->moveToTop(this); + } - void Window::mouseReleased(MouseEvent& mouseEvent) - { - mIsMoving = false; - } + mDragOffsetX = mouseEvent.getX(); + mDragOffsetY = mouseEvent.getY(); - void Window::mouseDragged(MouseEvent& mouseEvent) - { - if (mouseEvent.isConsumed() || mouseEvent.getSource() != this) - { - return; - } - - if (isMovable() && mIsMoving) - { - setPosition(mouseEvent.getX() - mDragOffsetX + getX(), - mouseEvent.getY() - mDragOffsetY + getY()); - } + mIsMoving = mouseEvent.getY() <= static_cast(mTitleBarHeight); + } - mouseEvent.consume(); - } + void Window::mouseReleased(MouseEvent& mouseEvent) + { + mIsMoving = false; + } - Rectangle Window::getChildrenArea() - { - return Rectangle(int(getPadding()), - int(getTitleBarHeight()), - int(getWidth() - getPadding() * 2), - int(getHeight() - getPadding() - getTitleBarHeight())); - } + void Window::mouseDragged(MouseEvent& mouseEvent) + { + if (mouseEvent.isConsumed() || mouseEvent.getSource() != this) + { + return; + } - void Window::setMovable(bool movable) - { - mMovable = movable; - } + if (isMovable() && mIsMoving) + { + setPosition(mouseEvent.getX() - mDragOffsetX + getX(), + mouseEvent.getY() - mDragOffsetY + getY()); + } - bool Window::isMovable() const - { - return mMovable; - } + mouseEvent.consume(); + } - void Window::setOpaque(bool opaque) - { - mOpaque = opaque; - } + Rectangle Window::getChildrenArea() + { + return Rectangle(static_cast(getPadding()), + static_cast(getTitleBarHeight()), + static_cast(getWidth() - getPadding() * 2), + static_cast(getHeight() - getPadding() - getTitleBarHeight())); + } - bool Window::isOpaque() - { - return mOpaque; - } + void Window::setMovable(bool movable) + { + mMovable = movable; + } - void Window::resizeToContent() - { - auto w = 0, h = 0; - for (auto& mWidget : mWidgets) - { - if (mWidget->getX() + mWidget->getWidth() > w) - { - w = mWidget->getX() + mWidget->getWidth(); - } + bool Window::isMovable() const + { + return mMovable; + } - if (mWidget->getY() + mWidget->getHeight() > h) - { - h = mWidget->getY() + mWidget->getHeight(); - } - } + void Window::setOpaque(bool opaque) + { + mOpaque = opaque; + } - setSize(w + 2* int(getPadding()), h + int(getPadding()) + int(getTitleBarHeight())); - } + bool Window::isOpaque() + { + return mOpaque; + } + + void Window::resizeToContent() + { + auto w = 0, h = 0; + for (auto& mWidget : mWidgets) + { + if (mWidget->getX() + mWidget->getWidth() > w) + { + w = mWidget->getX() + mWidget->getWidth(); + } + + if (mWidget->getY() + mWidget->getHeight() > h) + { + h = mWidget->getY() + mWidget->getHeight(); + } + } + + setSize(w + 2 * static_cast(getPadding()), + h + static_cast(getPadding()) + static_cast(getTitleBarHeight())); + } } diff --git a/src/osdep/gui/CreateFilesysHardfile.cpp b/src/osdep/gui/CreateFilesysHardfile.cpp index 51ae15db..cb7add3f 100644 --- a/src/osdep/gui/CreateFilesysHardfile.cpp +++ b/src/osdep/gui/CreateFilesysHardfile.cpp @@ -7,7 +7,6 @@ #include #include "SelectorEntry.hpp" -#include "UaeCheckBox.hpp" #include "sysdeps.h" #include "config.h" @@ -35,7 +34,7 @@ static gcn::Button *cmdOK; static gcn::Button *cmdCancel; static gcn::Label *lblDevice; static gcn::TextField *txtDevice; -static gcn::UaeCheckBox *chkAutoboot; +static gcn::CheckBox *chkAutoboot; static gcn::Label *lblBootPri; static gcn::TextField *txtBootPri; static gcn::Label *lblPath; @@ -117,7 +116,7 @@ static void InitCreateFilesysHardfile() txtDevice = new gcn::TextField(); txtDevice->setSize(80, TEXTFIELD_HEIGHT); - chkAutoboot = new gcn::UaeCheckBox("Bootable", true); + chkAutoboot = new gcn::CheckBox("Bootable", true); chkAutoboot->setId("createHdfAutoboot"); lblBootPri = new gcn::Label("Boot priority:"); diff --git a/src/osdep/gui/EditFilesysHardfile.cpp b/src/osdep/gui/EditFilesysHardfile.cpp index fdbf21f8..a6113da9 100644 --- a/src/osdep/gui/EditFilesysHardfile.cpp +++ b/src/osdep/gui/EditFilesysHardfile.cpp @@ -7,8 +7,6 @@ #include #include #include "SelectorEntry.hpp" -#include "UaeDropDown.hpp" -#include "UaeCheckBox.hpp" #include "sysdeps.h" #include "config.h" @@ -50,8 +48,8 @@ static gcn::Button *cmdOK; static gcn::Button *cmdCancel; static gcn::Label *lblDevice; static gcn::TextField *txtDevice; -static gcn::UaeCheckBox *chkReadWrite; -static gcn::UaeCheckBox *chkAutoboot; +static gcn::CheckBox *chkReadWrite; +static gcn::CheckBox *chkAutoboot; static gcn::Label *lblBootPri; static gcn::TextField *txtBootPri; static gcn::Label *lblPath; @@ -66,8 +64,8 @@ static gcn::TextField *txtSectors; static gcn::Label *lblBlocksize; static gcn::TextField *txtBlocksize; static gcn::Label *lblController; -static gcn::UaeDropDown *cboController; -static gcn::UaeDropDown *cboUnit; +static gcn::DropDown *cboController; +static gcn::DropDown *cboUnit; static void check_rdb(const TCHAR *filename) { @@ -231,10 +229,10 @@ static void InitEditFilesysHardfile() txtDevice = new gcn::TextField(); txtDevice->setSize(60, TEXTFIELD_HEIGHT); - chkReadWrite = new gcn::UaeCheckBox("Read/Write", true); + chkReadWrite = new gcn::CheckBox("Read/Write", true); chkReadWrite->setId("hdfRW"); - chkAutoboot = new gcn::UaeCheckBox("Bootable", true); + chkAutoboot = new gcn::CheckBox("Bootable", true); chkAutoboot->setId("hdfAutoboot"); lblBootPri = new gcn::Label("Boot priority:"); @@ -275,13 +273,13 @@ static void InitEditFilesysHardfile() lblController = new gcn::Label("Controller:"); lblController->setAlignment(gcn::Graphics::RIGHT); - cboController = new gcn::UaeDropDown(&controllerListModel); + cboController = new gcn::DropDown(&controllerListModel); cboController->setSize(180, DROPDOWN_HEIGHT); cboController->setBaseColor(gui_baseCol); cboController->setId("hdfController"); cboController->addActionListener(filesysHardfileActionListener); - cboUnit = new gcn::UaeDropDown(&unitListModel); + cboUnit = new gcn::DropDown(&unitListModel); cboUnit->setSize(60, DROPDOWN_HEIGHT); cboUnit->setBaseColor(gui_baseCol); cboUnit->setId("hdfUnit"); diff --git a/src/osdep/gui/EditFilesysVirtual.cpp b/src/osdep/gui/EditFilesysVirtual.cpp index fdae723a..bc791b70 100644 --- a/src/osdep/gui/EditFilesysVirtual.cpp +++ b/src/osdep/gui/EditFilesysVirtual.cpp @@ -7,7 +7,6 @@ #include #include #include "SelectorEntry.hpp" -#include "UaeCheckBox.hpp" #include "sysdeps.h" #include "config.h" @@ -41,8 +40,8 @@ static gcn::TextField* txtVolume; static gcn::Label* lblPath; static gcn::TextField* txtPath; static gcn::Button* cmdPath; -static gcn::UaeCheckBox* chkReadWrite; -static gcn::UaeCheckBox* chkAutoboot; +static gcn::CheckBox* chkReadWrite; +static gcn::CheckBox* chkAutoboot; static gcn::Label* lblBootPri; static gcn::TextField* txtBootPri; @@ -137,10 +136,10 @@ static void InitEditFilesysVirtual() cmdPath->setId("virtPath"); cmdPath->addActionListener(filesysVirtualActionListener); - chkReadWrite = new gcn::UaeCheckBox("Read/Write", true); + chkReadWrite = new gcn::CheckBox("Read/Write", true); chkReadWrite->setId("virtRW"); - chkAutoboot = new gcn::UaeCheckBox("Bootable", true); + chkAutoboot = new gcn::CheckBox("Bootable", true); chkAutoboot->setId("virtAutoboot"); lblBootPri = new gcn::Label("Boot priority:"); diff --git a/src/osdep/gui/Navigation.cpp b/src/osdep/gui/Navigation.cpp index ad6d340c..08a7666c 100644 --- a/src/osdep/gui/Navigation.cpp +++ b/src/osdep/gui/Navigation.cpp @@ -4,7 +4,6 @@ #include #include #include "SelectorEntry.hpp" -#include "UaeDropDown.hpp" #include "sysdeps.h" #include "gui_handling.h" @@ -24,7 +23,7 @@ static NavigationMap navMap[] = // main_window {"About", "", "", "Shutdown", "Paths"}, {"Paths", "SystemROMs", "SystemROMs", "About", "Quickstart"}, - {"Quickstart", "qsNTSC", "qscboAModel", "Paths", "Configurations"}, + {"Quickstart", "qsNTSC", "cboAModel", "Paths", "Configurations"}, {"Configurations", "ConfigList", "ConfigList", "Quickstart", "CPU and FPU"}, {"CPU and FPU", "7 Mhz", "68000", "Configurations", "Chipset"}, {"Chipset", "Fast copper", "OCS", "CPU and FPU", "ROM"}, @@ -63,27 +62,27 @@ static NavigationMap navMap[] = // active move left move right move up move down // PanelQuickstart - {"qscboAModel", "Quickstart", "qsNTSC", "cmdSetConfig", "qscboAConfig"}, - {"qsNTSC", "qscboAModel", "Quickstart", "qsMode", "qscboAConfig"}, - {"qscboAConfig", "Quickstart", "Quickstart", "qscboAModel", "qscmdSel0"}, - {"qsDF0", "Quickstart", "qsWP0", "qscboAConfig", "qscboDisk0"}, - {"qsWP0", "qsDF0", "qscmdEject0", "qscboAConfig", "qscboDisk0"}, + {"cboAModel", "Quickstart", "qsNTSC", "cmdSetConfig", "cboAConfig"}, + {"qsNTSC", "cboAModel", "Quickstart", "qsMode", "cboAConfig"}, + {"cboAConfig", "Quickstart", "Quickstart", "cboAModel", "qscmdSel0"}, + {"qsDF0", "Quickstart", "qsWP0", "cboAConfig", "cboDisk0"}, + {"qsWP0", "qsDF0", "qscmdEject0", "cboAConfig", "cboDisk0"}, // { "qsInfo0", "Quickstart", "", "", "" }, - {"qscmdEject0", "qsWP0", "qscmdSel0", "qscboAConfig", "qscboDisk0"}, - {"qscmdSel0", "qscmdEject0", "Quickstart", "qscboAConfig", "qscboDisk0"}, - {"qscboDisk0", "Quickstart", "Quickstart", "qscmdSel0", "qscmdSel1"}, - {"qsDF1", "Quickstart", "qsWP1", "qscboDisk0", "qscboDisk1"}, - {"qsWP1", "qsDF1", "qscmdEject1", "qscboDisk0", "qscboDisk1"}, + {"qscmdEject0", "qsWP0", "qscmdSel0", "cboAConfig", "cboDisk0"}, + {"qscmdSel0", "qscmdEject0", "Quickstart", "cboAConfig", "cboDisk0"}, + {"cboDisk0", "Quickstart", "Quickstart", "qscmdSel0", "qscmdSel1"}, + {"qsDF1", "Quickstart", "qsWP1", "cboDisk0", "cboDisk1"}, + {"qsWP1", "qsDF1", "qscmdEject1", "cboDisk0", "cboDisk1"}, // { "qsInfo1", "Quickstart", "", "", "" }, - {"qscmdEject1", "qsWP1", "qscmdSel1", "qscboDisk0", "qscboDisk1"}, - {"qscmdSel1", "qscmdEject1", "Quickstart", "qscboDisk0", "qscboDisk1"}, - {"qscboDisk1", "Quickstart", "Quickstart", "qsDF1", "qsCDSelect"}, - {"qsCD drive", "Quickstart", "qscdEject", "qscboDisk1", "qscboCD"}, - {"qscdEject", "qsCD drive", "qsCDSelect", "qscboDisk1", "qscboCD"}, - {"qsCDSelect", "qscdEject", "Quickstart", "qscboDisk1", "qscboCD"}, - {"qscboCD", "Quickstart", "Quickstart", "qsCDSelect", "qsMode"}, - {"qsMode", "Quickstart", "Quickstart", "qscboCD", "cmdSetConfig"}, - {"cmdSetConfig", "Quickstart", "Quickstart", "qsMode", "qscboAModel"}, + {"qscmdEject1", "qsWP1", "qscmdSel1", "cboDisk0", "cboDisk1"}, + {"qscmdSel1", "qscmdEject1", "Quickstart", "cboDisk0", "cboDisk1"}, + {"cboDisk1", "Quickstart", "Quickstart", "qsDF1", "qsCDSelect"}, + {"qsCD drive", "Quickstart", "qscdEject", "cboDisk1", "cboCD"}, + {"qscdEject", "qsCD drive", "qsCDSelect", "cboDisk1", "cboCD"}, + {"qsCDSelect", "qscdEject", "Quickstart", "cboDisk1", "cboCD"}, + {"cboCD", "Quickstart", "Quickstart", "qsCDSelect", "qsMode"}, + {"qsMode", "Quickstart", "Quickstart", "cboCD", "cmdSetConfig"}, + {"cmdSetConfig", "Quickstart", "Quickstart", "qsMode", "cboAModel"}, // PanelConfig {"ConfigList", "Configurations", "ConfigLoad", "", ""}, @@ -409,10 +408,9 @@ bool HandleNavigation(int direction) if (focusTarget != nullptr) { - if (activeWidget->getId().substr(0, 3) == "cbo" - || activeWidget->getId().substr(0, 5) == "qscbo") + if (activeWidget->getId().substr(0, 3) == "cbo") { - auto dropdown = dynamic_cast(activeWidget); + auto* dropdown = dynamic_cast(activeWidget); if (dropdown->isDroppedDown() && (direction == DIRECTION_UP || direction == DIRECTION_DOWN)) focusTarget = nullptr; // Up/down navigates in list if dropped down } diff --git a/src/osdep/gui/PanelCPU.cpp b/src/osdep/gui/PanelCPU.cpp index afdfe7e6..c02bea44 100644 --- a/src/osdep/gui/PanelCPU.cpp +++ b/src/osdep/gui/PanelCPU.cpp @@ -5,8 +5,6 @@ #include #include #include "SelectorEntry.hpp" -#include "UaeRadioButton.hpp" -#include "UaeCheckBox.hpp" #include "sysdeps.h" #include "options.h" @@ -15,27 +13,27 @@ #include "gui_handling.h" static gcn::Window* grpCPU; -static gcn::UaeRadioButton* optCPU68000; -static gcn::UaeRadioButton* optCPU68010; -static gcn::UaeRadioButton* optCPU68020; -static gcn::UaeRadioButton* optCPU68030; -static gcn::UaeRadioButton* optCPU68040; -static gcn::UaeCheckBox* chk24Bit; -static gcn::UaeCheckBox* chkCPUCompatible; -static gcn::UaeCheckBox* chkJIT; +static gcn::RadioButton* optCPU68000; +static gcn::RadioButton* optCPU68010; +static gcn::RadioButton* optCPU68020; +static gcn::RadioButton* optCPU68030; +static gcn::RadioButton* optCPU68040; +static gcn::CheckBox* chk24Bit; +static gcn::CheckBox* chkCPUCompatible; +static gcn::CheckBox* chkJIT; static gcn::Window* grpFPU; -static gcn::UaeRadioButton* optFPUnone; -static gcn::UaeRadioButton* optFPU68881; -static gcn::UaeRadioButton* optFPU68882; -static gcn::UaeRadioButton* optFPUinternal; -static gcn::UaeCheckBox* chkFPUstrict; -static gcn::UaeCheckBox* chkFPUJIT; +static gcn::RadioButton* optFPUnone; +static gcn::RadioButton* optFPU68881; +static gcn::RadioButton* optFPU68882; +static gcn::RadioButton* optFPUinternal; +static gcn::CheckBox* chkFPUstrict; +static gcn::CheckBox* chkFPUJIT; static gcn::Window* grpCPUSpeed; -static gcn::UaeRadioButton* opt7Mhz; -static gcn::UaeRadioButton* opt14Mhz; -static gcn::UaeRadioButton* opt28Mhz; -static gcn::UaeRadioButton* optFastest; -static gcn::UaeRadioButton* optTurbo; +static gcn::RadioButton* opt7Mhz; +static gcn::RadioButton* opt14Mhz; +static gcn::RadioButton* opt28Mhz; +static gcn::RadioButton* optFastest; +static gcn::RadioButton* optTurbo; class CPUButtonActionListener : public gcn::ActionListener { @@ -227,26 +225,26 @@ void InitPanelCPU(const struct _ConfigCategory& category) jitActionListener = new JITActionListener(); fpuActionListener = new FPUActionListener(); - optCPU68000 = new gcn::UaeRadioButton("68000", "radiocpugroup"); + optCPU68000 = new gcn::RadioButton("68000", "radiocpugroup"); optCPU68000->addActionListener(cpuButtonActionListener); - optCPU68010 = new gcn::UaeRadioButton("68010", "radiocpugroup"); + optCPU68010 = new gcn::RadioButton("68010", "radiocpugroup"); optCPU68010->addActionListener(cpuButtonActionListener); - optCPU68020 = new gcn::UaeRadioButton("68020", "radiocpugroup"); + optCPU68020 = new gcn::RadioButton("68020", "radiocpugroup"); optCPU68020->addActionListener(cpuButtonActionListener); - optCPU68030 = new gcn::UaeRadioButton("68030", "radiocpugroup"); + optCPU68030 = new gcn::RadioButton("68030", "radiocpugroup"); optCPU68030->addActionListener(cpuButtonActionListener); - optCPU68040 = new gcn::UaeRadioButton("68040", "radiocpugroup"); + optCPU68040 = new gcn::RadioButton("68040", "radiocpugroup"); optCPU68040->addActionListener(cpuButtonActionListener); - chk24Bit = new gcn::UaeCheckBox("24-bit addressing", true); + chk24Bit = new gcn::CheckBox("24-bit addressing", true); chk24Bit->setId("CPU24Bit"); chk24Bit->addActionListener(cpu24BitActionListener); - chkCPUCompatible = new gcn::UaeCheckBox("More compatible", true); + chkCPUCompatible = new gcn::CheckBox("More compatible", true); chkCPUCompatible->setId("CPUComp"); chkCPUCompatible->addActionListener(cpuCompActionListener); - chkJIT = new gcn::UaeCheckBox("JIT", true); + chkJIT = new gcn::CheckBox("JIT", true); chkJIT->setId("JIT"); chkJIT->addActionListener(jitActionListener); @@ -268,24 +266,24 @@ void InitPanelCPU(const struct _ConfigCategory& category) fpuButtonActionListener = new FPUButtonActionListener(); - optFPUnone = new gcn::UaeRadioButton("None", "radiofpugroup"); + optFPUnone = new gcn::RadioButton("None", "radiofpugroup"); optFPUnone->setId("FPUnone"); optFPUnone->addActionListener(fpuButtonActionListener); - optFPU68881 = new gcn::UaeRadioButton("68881", "radiofpugroup"); + optFPU68881 = new gcn::RadioButton("68881", "radiofpugroup"); optFPU68881->addActionListener(fpuButtonActionListener); - optFPU68882 = new gcn::UaeRadioButton("68882", "radiofpugroup"); + optFPU68882 = new gcn::RadioButton("68882", "radiofpugroup"); optFPU68882->addActionListener(fpuButtonActionListener); - optFPUinternal = new gcn::UaeRadioButton("CPU internal", "radiofpugroup"); + optFPUinternal = new gcn::RadioButton("CPU internal", "radiofpugroup"); optFPUinternal->addActionListener(fpuButtonActionListener); - chkFPUstrict = new gcn::UaeCheckBox("More compatible", true); + chkFPUstrict = new gcn::CheckBox("More compatible", true); chkFPUstrict->setId("FPUstrict"); chkFPUstrict->addActionListener(fpuActionListener); - chkFPUJIT = new gcn::UaeCheckBox("FPU JIT", true); + chkFPUJIT = new gcn::CheckBox("FPU JIT", true); chkFPUJIT->setId("FPUJIT"); chkFPUJIT->addActionListener(jitActionListener); @@ -305,19 +303,19 @@ void InitPanelCPU(const struct _ConfigCategory& category) cpuSpeedButtonActionListener = new CPUSpeedButtonActionListener(); - opt7Mhz = new gcn::UaeRadioButton("7 Mhz", "radiocpuspeedgroup"); + opt7Mhz = new gcn::RadioButton("7 Mhz", "radiocpuspeedgroup"); opt7Mhz->addActionListener(cpuSpeedButtonActionListener); - opt14Mhz = new gcn::UaeRadioButton("14 Mhz", "radiocpuspeedgroup"); + opt14Mhz = new gcn::RadioButton("14 Mhz", "radiocpuspeedgroup"); opt14Mhz->addActionListener(cpuSpeedButtonActionListener); - opt28Mhz = new gcn::UaeRadioButton("25 Mhz", "radiocpuspeedgroup"); + opt28Mhz = new gcn::RadioButton("25 Mhz", "radiocpuspeedgroup"); opt28Mhz->addActionListener(cpuSpeedButtonActionListener); - optFastest = new gcn::UaeRadioButton("Fastest", "radiocpuspeedgroup"); + optFastest = new gcn::RadioButton("Fastest", "radiocpuspeedgroup"); optFastest->addActionListener(cpuSpeedButtonActionListener); - optTurbo = new gcn::UaeRadioButton("Turbo", "radiocpuspeedgroup"); + optTurbo = new gcn::RadioButton("Turbo", "radiocpuspeedgroup"); optTurbo->addActionListener(cpuSpeedButtonActionListener); grpCPUSpeed = new gcn::Window("CPU Speed"); diff --git a/src/osdep/gui/PanelChipset.cpp b/src/osdep/gui/PanelChipset.cpp index d156abcd..52e8233c 100644 --- a/src/osdep/gui/PanelChipset.cpp +++ b/src/osdep/gui/PanelChipset.cpp @@ -5,9 +5,6 @@ #include #include #include "SelectorEntry.hpp" -#include "UaeRadioButton.hpp" -#include "UaeCheckBox.hpp" -#include "UaeDropDown.hpp" #include "sysdeps.h" #include "options.h" @@ -15,24 +12,24 @@ #include "gui_handling.h" static gcn::Window* grpChipset; -static gcn::UaeRadioButton* optOCS; -static gcn::UaeRadioButton* optECSAgnus; -static gcn::UaeRadioButton* optECS; -static gcn::UaeRadioButton* optAGA; -static gcn::UaeCheckBox* chkNTSC; +static gcn::RadioButton* optOCS; +static gcn::RadioButton* optECSAgnus; +static gcn::RadioButton* optECS; +static gcn::RadioButton* optAGA; +static gcn::CheckBox* chkNTSC; static gcn::Label* lblChipset; -static gcn::UaeDropDown* cboChipset; +static gcn::DropDown* cboChipset; static gcn::Window* grpBlitter; -static gcn::UaeRadioButton* optBlitNormal; -static gcn::UaeRadioButton* optBlitImmed; -static gcn::UaeRadioButton* optBlitWait; +static gcn::RadioButton* optBlitNormal; +static gcn::RadioButton* optBlitImmed; +static gcn::RadioButton* optBlitWait; static gcn::Window* grpCopper; -static gcn::UaeCheckBox* chkFastCopper; +static gcn::CheckBox* chkFastCopper; static gcn::Window* grpCollisionLevel; -static gcn::UaeRadioButton* optCollNone; -static gcn::UaeRadioButton* optCollSprites; -static gcn::UaeRadioButton* optCollPlayfield; -static gcn::UaeRadioButton* optCollFull; +static gcn::RadioButton* optCollNone; +static gcn::RadioButton* optCollSprites; +static gcn::RadioButton* optCollPlayfield; +static gcn::RadioButton* optCollFull; struct chipset { @@ -203,24 +200,24 @@ void InitPanelChipset(const struct _ConfigCategory& category) chipsetButtonActionListener = new ChipsetButtonActionListener(); ntscButtonActionListener = new NTSCButtonActionListener(); - optOCS = new gcn::UaeRadioButton("OCS", "radiochipsetgroup"); + optOCS = new gcn::RadioButton("OCS", "radiochipsetgroup"); optOCS->addActionListener(chipsetButtonActionListener); - optECSAgnus = new gcn::UaeRadioButton("ECS Agnus", "radiochipsetgroup"); + optECSAgnus = new gcn::RadioButton("ECS Agnus", "radiochipsetgroup"); optECSAgnus->addActionListener(chipsetButtonActionListener); - optECS = new gcn::UaeRadioButton("Full ECS", "radiochipsetgroup"); + optECS = new gcn::RadioButton("Full ECS", "radiochipsetgroup"); optECS->addActionListener(chipsetButtonActionListener); - optAGA = new gcn::UaeRadioButton("AGA", "radiochipsetgroup"); + optAGA = new gcn::RadioButton("AGA", "radiochipsetgroup"); optAGA->addActionListener(chipsetButtonActionListener); - chkNTSC = new gcn::UaeCheckBox("NTSC"); + chkNTSC = new gcn::CheckBox("NTSC"); chkNTSC->addActionListener(ntscButtonActionListener); lblChipset = new gcn::Label("Extra:"); lblChipset->setAlignment(gcn::Graphics::RIGHT); - cboChipset = new gcn::UaeDropDown(&chipsetList); + cboChipset = new gcn::DropDown(&chipsetList); cboChipset->setSize(75, cboChipset->getHeight()); cboChipset->setBaseColor(gui_baseCol); cboChipset->setBackgroundColor(colTextboxBackground); @@ -245,14 +242,14 @@ void InitPanelChipset(const struct _ConfigCategory& category) blitterButtonActionListener = new BlitterButtonActionListener(); - optBlitNormal = new gcn::UaeRadioButton("Normal", "radiocblittergroup"); + optBlitNormal = new gcn::RadioButton("Normal", "radiocblittergroup"); optBlitNormal->setId("BlitNormal"); optBlitNormal->addActionListener(blitterButtonActionListener); - optBlitImmed = new gcn::UaeRadioButton("Immediate", "radiocblittergroup"); + optBlitImmed = new gcn::RadioButton("Immediate", "radiocblittergroup"); optBlitImmed->addActionListener(blitterButtonActionListener); - optBlitWait = new gcn::UaeRadioButton("Wait for blit.", "radiocblittergroup"); + optBlitWait = new gcn::RadioButton("Wait for blit.", "radiocblittergroup"); optBlitWait->setId("BlitWait"); optBlitWait->addActionListener(blitterButtonActionListener); @@ -269,7 +266,7 @@ void InitPanelChipset(const struct _ConfigCategory& category) fastCopperActionListener = new FastCopperActionListener(); - chkFastCopper = new gcn::UaeCheckBox("Fast copper"); + chkFastCopper = new gcn::CheckBox("Fast copper"); chkFastCopper->addActionListener(fastCopperActionListener); grpCopper = new gcn::Window("Copper"); @@ -284,18 +281,18 @@ void InitPanelChipset(const struct _ConfigCategory& category) collisionButtonActionListener = new CollisionButtonActionListener(); - optCollNone = new gcn::UaeRadioButton("None", "radioccollisiongroup"); + optCollNone = new gcn::RadioButton("None", "radioccollisiongroup"); optCollNone->setId("CollNone"); optCollNone->addActionListener(collisionButtonActionListener); - optCollSprites = new gcn::UaeRadioButton("Sprites only", "radioccollisiongroup"); + optCollSprites = new gcn::RadioButton("Sprites only", "radioccollisiongroup"); optCollSprites->addActionListener(collisionButtonActionListener); - optCollPlayfield = new gcn::UaeRadioButton("Sprites and Sprites vs. Playfield", "radioccollisiongroup"); + optCollPlayfield = new gcn::RadioButton("Sprites and Sprites vs. Playfield", "radioccollisiongroup"); optCollPlayfield->setId("CollPlay"); optCollPlayfield->addActionListener(collisionButtonActionListener); - optCollFull = new gcn::UaeRadioButton("Full (rarely needed)", "radioccollisiongroup"); + optCollFull = new gcn::RadioButton("Full (rarely needed)", "radioccollisiongroup"); optCollFull->setId("CollFull"); optCollFull->addActionListener(collisionButtonActionListener); diff --git a/src/osdep/gui/PanelConfig.cpp b/src/osdep/gui/PanelConfig.cpp index 9c14149e..0495949b 100644 --- a/src/osdep/gui/PanelConfig.cpp +++ b/src/osdep/gui/PanelConfig.cpp @@ -7,7 +7,6 @@ #include #include #include "SelectorEntry.hpp" -#include "UaeListBox.hpp" #include "sysdeps.h" #include "options.h" @@ -24,7 +23,7 @@ static gcn::Label* lblName; static gcn::TextField* txtName; static gcn::Label* lblDesc; static gcn::TextField* txtDesc; -static gcn::UaeListBox* lstConfigs; +static gcn::ListBox* lstConfigs; static gcn::ScrollArea* scrAreaConfigs; bool LoadConfigByName(const char* name) @@ -71,7 +70,7 @@ public: std::string getElementAt(int i) override { - if (i >= int(configs.size()) || i < 0) + if (i >= static_cast(configs.size()) || i < 0) return "---"; return configs[i]; } @@ -215,10 +214,11 @@ void InitPanelConfig(const struct _ConfigCategory& category) configsList->InitConfigsList(); configsListActionListener = new ConfigsListActionListener(); - lstConfigs = new gcn::UaeListBox(configsList); + lstConfigs = new gcn::ListBox(configsList); lstConfigs->setSize(category.panel->getWidth() - 2 * DISTANCE_BORDER - 22, 232); lstConfigs->setBaseColor(colTextboxBackground); lstConfigs->setBackgroundColor(colTextboxBackground); + lstConfigs->setSelectionColor(colSelectorActive); lstConfigs->setWrappingEnabled(true); lstConfigs->setId("ConfigList"); lstConfigs->addActionListener(configsListActionListener); diff --git a/src/osdep/gui/PanelCustom.cpp b/src/osdep/gui/PanelCustom.cpp index dc888058..02bb950b 100644 --- a/src/osdep/gui/PanelCustom.cpp +++ b/src/osdep/gui/PanelCustom.cpp @@ -7,9 +7,6 @@ #include #include #include "SelectorEntry.hpp" -#include "UaeRadioButton.hpp" -#include "UaeDropDown.hpp" -#include "UaeCheckBox.hpp" #include "sysdeps.h" #include "options.h" @@ -17,25 +14,25 @@ #include "inputdevice.h" static gcn::Window* grpPort; -static gcn::UaeRadioButton* optPort0; -static gcn::UaeRadioButton* optPort1; -static gcn::UaeRadioButton* optPort2; -static gcn::UaeRadioButton* optPort3; +static gcn::RadioButton* optPort0; +static gcn::RadioButton* optPort1; +static gcn::RadioButton* optPort2; +static gcn::RadioButton* optPort3; static gcn::Window* grpFunction; -static gcn::UaeRadioButton* optMultiNone; -static gcn::UaeRadioButton* optMultiSelect; -static gcn::UaeRadioButton* optMultiLeft; -static gcn::UaeRadioButton* optMultiRight; +static gcn::RadioButton* optMultiNone; +static gcn::RadioButton* optMultiSelect; +static gcn::RadioButton* optMultiLeft; +static gcn::RadioButton* optMultiRight; static gcn::Label* lblCustomAction[14]; -static gcn::UaeDropDown* cboCustomAction[14]; +static gcn::DropDown* cboCustomAction[14]; static gcn::Label* lblPortInput; static gcn::TextField* txtPortInput; static gcn::Label* lblRetroarch; -static gcn::UaeCheckBox* chkAnalogRemap; +static gcn::CheckBox* chkAnalogRemap; static int SelectedPort = 1; static int SelectedFunction = 0; @@ -347,25 +344,25 @@ void InitPanelCustom(const struct _ConfigCategory& category) customActionListener = new CustomActionListener(); grpActionListener = new GroupActionListener(); - optPort0 = new gcn::UaeRadioButton("0: Mouse", "radioportgroup"); + optPort0 = new gcn::RadioButton("0: Mouse", "radioportgroup"); optPort0->addActionListener(grpActionListener); - optPort1 = new gcn::UaeRadioButton("1: Joystick", "radioportgroup"); + optPort1 = new gcn::RadioButton("1: Joystick", "radioportgroup"); optPort1->addActionListener(grpActionListener); - optPort2 = new gcn::UaeRadioButton("2: Parallel 1", "radioportgroup"); + optPort2 = new gcn::RadioButton("2: Parallel 1", "radioportgroup"); optPort2->addActionListener(grpActionListener); - optPort3 = new gcn::UaeRadioButton("3: Parallel 2", "radioportgroup"); + optPort3 = new gcn::RadioButton("3: Parallel 2", "radioportgroup"); optPort3->addActionListener(grpActionListener); - optMultiNone = new gcn::UaeRadioButton("None", "radiomultigroup"); + optMultiNone = new gcn::RadioButton("None", "radiomultigroup"); optMultiNone->addActionListener(grpActionListener); - optMultiSelect = new gcn::UaeRadioButton("HotKey", "radiomultigroup"); + optMultiSelect = new gcn::RadioButton("HotKey", "radiomultigroup"); optMultiSelect->addActionListener(grpActionListener); - // optMultiLeft = new gcn::UaeRadioButton("Left Trigger", "radiomultigroup"); + // optMultiLeft = new gcn::RadioButton("Left Trigger", "radiomultigroup"); // optMultiLeft->addActionListener(grpActionListener); - // optMultiRight = new gcn::UaeRadioButton("Right Trigger", "radiomultigroup"); + // optMultiRight = new gcn::RadioButton("Right Trigger", "radiomultigroup"); // optMultiRight->addActionListener(grpActionListener); - chkAnalogRemap = new gcn::UaeCheckBox("Remap DPad to left axis"); + chkAnalogRemap = new gcn::CheckBox("Remap DPad to left axis"); chkAnalogRemap->setId("chkAnalogRemap"); chkAnalogRemap->addActionListener(grpActionListener); chkAnalogRemap->setEnabled(true); @@ -429,7 +426,7 @@ void InitPanelCustom(const struct _ConfigCategory& category) lblCustomAction[i]->setSize(lblCustomAction[12]->getWidth(), lblCustomAction[12]->getHeight()); lblCustomAction[i]->setAlignment(gcn::Graphics::RIGHT); - cboCustomAction[i] = new gcn::UaeDropDown(&CustomEventList); + cboCustomAction[i] = new gcn::DropDown(&CustomEventList); cboCustomAction[i]->setSize(cboCustomAction[i]->getWidth() * 2, cboCustomAction[i]->getHeight()); cboCustomAction[i]->setBaseColor(gui_baseCol); cboCustomAction[i]->setBackgroundColor(colTextboxBackground); @@ -776,7 +773,7 @@ void RefreshPanelCustom(void) break; } const auto x = find_in_array(RemapEventList, RemapEventListSize, eventnum); - if (cboCustomAction[z]->getEnabled()) + if (cboCustomAction[z]->isEnabled()) { cboCustomAction[z]->setSelected(x + 1); } diff --git a/src/osdep/gui/PanelDisplay.cpp b/src/osdep/gui/PanelDisplay.cpp index e7d787dc..035520bb 100644 --- a/src/osdep/gui/PanelDisplay.cpp +++ b/src/osdep/gui/PanelDisplay.cpp @@ -5,8 +5,6 @@ #include #include #include "SelectorEntry.hpp" -#include "UaeRadioButton.hpp" -#include "UaeCheckBox.hpp" #include "sysdeps.h" #include "options.h" @@ -17,14 +15,14 @@ const int amigawidth_values[] = {320, 362, 384, 640, 704, 720}; const int amigaheight_values[] = {200, 216, 240, 256, 262, 270, 284}; static gcn::Window* grpScalingMethod; -static gcn::UaeRadioButton* optAuto; -static gcn::UaeRadioButton* optNearest; -static gcn::UaeRadioButton* optLinear; +static gcn::RadioButton* optAuto; +static gcn::RadioButton* optNearest; +static gcn::RadioButton* optLinear; static gcn::Window* grpLineMode; -static gcn::UaeRadioButton* optSingle; -static gcn::UaeRadioButton* optDouble; -static gcn::UaeRadioButton* optScanlines; +static gcn::RadioButton* optSingle; +static gcn::RadioButton* optDouble; +static gcn::RadioButton* optScanlines; static gcn::Window* grpAmigaScreen; static gcn::Label* lblAmigaWidth; @@ -34,13 +32,13 @@ static gcn::Label* lblAmigaHeight; static gcn::Label* lblAmigaHeightInfo; static gcn::Slider* sldAmigaHeight; -static gcn::UaeCheckBox* chkFrameskip; -static gcn::UaeCheckBox* chkAspect; -static gcn::UaeCheckBox* chkFullscreen; +static gcn::CheckBox* chkFrameskip; +static gcn::CheckBox* chkAspect; +static gcn::CheckBox* chkFullscreen; static gcn::Window* grpCentering; -static gcn::UaeCheckBox* chkHorizontal; -static gcn::UaeCheckBox* chkVertical; +static gcn::CheckBox* chkHorizontal; +static gcn::CheckBox* chkVertical; class AmigaScreenActionListener : public gcn::ActionListener { @@ -161,19 +159,19 @@ void InitPanelDisplay(const struct _ConfigCategory& category) sldAmigaHeight->addActionListener(amigaScreenActionListener); lblAmigaHeightInfo = new gcn::Label("200"); - chkHorizontal = new gcn::UaeCheckBox("Horizontal"); + chkHorizontal = new gcn::CheckBox("Horizontal"); chkHorizontal->addActionListener(amigaScreenActionListener); - chkVertical = new gcn::UaeCheckBox("Vertical"); + chkVertical = new gcn::CheckBox("Vertical"); chkVertical->addActionListener(amigaScreenActionListener); - chkAspect = new gcn::UaeCheckBox("Correct Aspect Ratio"); + chkAspect = new gcn::CheckBox("Correct Aspect Ratio"); chkAspect->setId("CorrectAR"); chkAspect->addActionListener(amigaScreenActionListener); - chkFrameskip = new gcn::UaeCheckBox("Frameskip"); + chkFrameskip = new gcn::CheckBox("Frameskip"); chkFrameskip->addActionListener(amigaScreenActionListener); - chkFullscreen = new gcn::UaeCheckBox("Fullscreen"); + chkFullscreen = new gcn::CheckBox("Fullscreen"); chkFullscreen->addActionListener(amigaScreenActionListener); grpAmigaScreen = new gcn::Window("Amiga Screen"); @@ -210,13 +208,13 @@ void InitPanelDisplay(const struct _ConfigCategory& category) scalingMethodActionListener = new ScalingMethodActionListener(); - optAuto = new gcn::UaeRadioButton("Auto", "radioscalingmethodgroup"); + optAuto = new gcn::RadioButton("Auto", "radioscalingmethodgroup"); optAuto->addActionListener(scalingMethodActionListener); - optNearest = new gcn::UaeRadioButton("Nearest Neighbor (pixelated)", "radioscalingmethodgroup"); + optNearest = new gcn::RadioButton("Nearest Neighbor (pixelated)", "radioscalingmethodgroup"); optNearest->addActionListener(scalingMethodActionListener); - optLinear = new gcn::UaeRadioButton("Linear (smooth)", "radioscalingmethodgroup"); + optLinear = new gcn::RadioButton("Linear (smooth)", "radioscalingmethodgroup"); optLinear->addActionListener(scalingMethodActionListener); grpScalingMethod = new gcn::Window("Scaling method"); @@ -233,13 +231,13 @@ void InitPanelDisplay(const struct _ConfigCategory& category) posY += DISTANCE_BORDER + grpScalingMethod->getHeight() + DISTANCE_NEXT_Y; lineModeActionListener = new LineModeActionListener(); - optSingle = new gcn::UaeRadioButton("Single", "linemodegroup"); + optSingle = new gcn::RadioButton("Single", "linemodegroup"); optSingle->addActionListener(lineModeActionListener); - optDouble = new gcn::UaeRadioButton("Double", "linemodegroup"); + optDouble = new gcn::RadioButton("Double", "linemodegroup"); optDouble->addActionListener(lineModeActionListener); - optScanlines = new gcn::UaeRadioButton("Scanlines", "linemodegroup"); + optScanlines = new gcn::RadioButton("Scanlines", "linemodegroup"); optScanlines->addActionListener(lineModeActionListener); grpLineMode = new gcn::Window("Line mode"); diff --git a/src/osdep/gui/PanelFloppy.cpp b/src/osdep/gui/PanelFloppy.cpp index bd21cc07..c2b63637 100644 --- a/src/osdep/gui/PanelFloppy.cpp +++ b/src/osdep/gui/PanelFloppy.cpp @@ -7,32 +7,30 @@ #include #include #include "SelectorEntry.hpp" -#include "UaeDropDown.hpp" -#include "UaeCheckBox.hpp" #include "sysdeps.h" #include "options.h" #include "disk.h" #include "gui_handling.h" -static gcn::UaeCheckBox* chkDFx[4]; -static gcn::UaeDropDown* cboDFxType[4]; -static gcn::UaeCheckBox* chkDFxWriteProtect[4]; +static gcn::CheckBox* chkDFx[4]; +static gcn::DropDown* cboDFxType[4]; +static gcn::CheckBox* chkDFxWriteProtect[4]; static gcn::Button* cmdDFxInfo[4]; static gcn::Button* cmdDFxEject[4]; static gcn::Button* cmdDFxSelect[4]; -static gcn::UaeDropDown* cboDFxFile[4]; +static gcn::DropDown* cboDFxFile[4]; static gcn::Label* lblDriveSpeed; static gcn::Label* lblDriveSpeedInfo; static gcn::Slider* sldDriveSpeed; -static gcn::UaeCheckBox* chkLoadConfig; +static gcn::CheckBox* chkLoadConfig; static gcn::Button* cmdSaveForDisk; static gcn::Button* cmdCreateDDDisk; static gcn::Button* cmdCreateHDDisk; static const char* diskfile_filter[] = {".adf", ".adz", ".fdi", ".ipf", ".zip", ".dms", ".gz", ".xz", "\0"}; -static const char* drivespeedlist[] = {"100% (compatible)", "200%", "400%", "800%"}; -static const int drivespeedvalues[] = {100, 200, 400, 800}; +static const char* drive_speed_list[] = {"100% (compatible)", "200%", "400%", "800%"}; +static const int drive_speed_values[] = {100, 200, 400, 800}; static void AdjustDropDownControls(); static bool bLoadConfigForDisk = false; @@ -60,7 +58,7 @@ public: std::string getElementAt(int i) override { - if (i < 0 || i >= types.size()) + if (i < 0 || i >= static_cast(types.size())) return "---"; return types[i]; } @@ -81,7 +79,7 @@ public: std::string getElementAt(int i) override { - if (i < 0 || i >= lstMRUDiskList.size()) + if (i < 0 || i >= static_cast(lstMRUDiskList.size())) return "---"; return lstMRUDiskList[i]; } @@ -234,7 +232,7 @@ public: if (actionEvent.getSource() == cboDFxFile[i]) { //--------------------------------------- - // Diskimage from list selected + // Disk image from list selected //--------------------------------------- if (!bIgnoreListChange) { @@ -285,7 +283,7 @@ class DriveSpeedSliderActionListener : public gcn::ActionListener public: void action(const gcn::ActionEvent& actionEvent) override { - changed_prefs.floppy_speed = drivespeedvalues[int(sldDriveSpeed->getValue())]; + changed_prefs.floppy_speed = drive_speed_values[int(sldDriveSpeed->getValue())]; RefreshPanelFloppy(); } }; @@ -387,17 +385,17 @@ void InitPanelFloppy(const struct _ConfigCategory& category) { char tmp[20]; snprintf(tmp, 20, "DF%d:", i); - chkDFx[i] = new gcn::UaeCheckBox(tmp); + chkDFx[i] = new gcn::CheckBox(tmp); chkDFx[i]->addActionListener(dfxCheckActionListener); - cboDFxType[i] = new gcn::UaeDropDown(&driveTypeList); + cboDFxType[i] = new gcn::DropDown(&driveTypeList); cboDFxType[i]->setBaseColor(gui_baseCol); cboDFxType[i]->setBackgroundColor(colTextboxBackground); snprintf(tmp, 20, "cboType%d", i); cboDFxType[i]->setId(tmp); cboDFxType[i]->addActionListener(driveTypeActionListener); - chkDFxWriteProtect[i] = new gcn::UaeCheckBox("Write-protected"); + chkDFxWriteProtect[i] = new gcn::CheckBox("Write-protected"); chkDFxWriteProtect[i]->addActionListener(dfxCheckActionListener); snprintf(tmp, 20, "chkWP%d", i); chkDFxWriteProtect[i]->setId(tmp); @@ -421,7 +419,7 @@ void InitPanelFloppy(const struct _ConfigCategory& category) cmdDFxSelect[i]->setId(tmp); cmdDFxSelect[i]->addActionListener(dfxButtonActionListener); - cboDFxFile[i] = new gcn::UaeDropDown(&diskfileList); + cboDFxFile[i] = new gcn::DropDown(&diskfileList); cboDFxFile[i]->setSize(textFieldWidth, cboDFxFile[i]->getHeight()); cboDFxFile[i]->setBaseColor(gui_baseCol); cboDFxFile[i]->setBackgroundColor(colTextboxBackground); @@ -431,7 +429,7 @@ void InitPanelFloppy(const struct _ConfigCategory& category) if (i == 0) { - chkLoadConfig = new gcn::UaeCheckBox("Load config with same name as disk"); + chkLoadConfig = new gcn::CheckBox("Load config with same name as disk"); chkLoadConfig->setId("LoadDiskCfg"); chkLoadConfig->addActionListener(dfxCheckActionListener); } @@ -445,7 +443,7 @@ void InitPanelFloppy(const struct _ConfigCategory& category) sldDriveSpeed->setStepLength(1); sldDriveSpeed->setId("DriveSpeed"); sldDriveSpeed->addActionListener(driveSpeedSliderActionListener); - lblDriveSpeedInfo = new gcn::Label(drivespeedlist[0]); + lblDriveSpeedInfo = new gcn::Label(drive_speed_list[0]); cmdSaveForDisk = new gcn::Button("Save config for disk"); cmdSaveForDisk->setSize(cmdSaveForDisk->getWidth(), BUTTON_HEIGHT); @@ -547,7 +545,7 @@ static void AdjustDropDownControls() if (changed_prefs.floppyslots[i].dfxtype != DRV_NONE && strlen(changed_prefs.floppyslots[i].df) > 0) { - for (unsigned int j = 0; j < lstMRUDiskList.size(); ++j) + for (auto j = 0; j < static_cast(lstMRUDiskList.size()); ++j) { if (strcmp(lstMRUDiskList[j].c_str(), changed_prefs.floppyslots[i].df) == 0) { @@ -594,10 +592,10 @@ void RefreshPanelFloppy() for (i = 0; i < 4; ++i) { - if (changed_prefs.floppy_speed == drivespeedvalues[i]) + if (changed_prefs.floppy_speed == drive_speed_values[i]) { sldDriveSpeed->setValue(i); - lblDriveSpeedInfo->setCaption(drivespeedlist[i]); + lblDriveSpeedInfo->setCaption(drive_speed_list[i]); break; } } diff --git a/src/osdep/gui/PanelHD.cpp b/src/osdep/gui/PanelHD.cpp index 75f2276e..121ec0ff 100644 --- a/src/osdep/gui/PanelHD.cpp +++ b/src/osdep/gui/PanelHD.cpp @@ -6,8 +6,6 @@ #include #include #include "SelectorEntry.hpp" -#include "UaeDropDown.hpp" -#include "UaeCheckBox.hpp" #include "sysdeps.h" #include "options.h" @@ -54,9 +52,9 @@ static gcn::ImageButton* listCmdDelete[MAX_HD_DEVICES]; static gcn::Button* cmdAddDirectory; static gcn::Button* cmdAddHardfile; static gcn::Button* cmdCreateHardfile; -static gcn::UaeCheckBox* chkHDReadOnly; -static gcn::UaeCheckBox* chkCD; -static gcn::UaeDropDown* cboCDFile; +static gcn::CheckBox* chkHDReadOnly; +static gcn::CheckBox* chkCD; +static gcn::DropDown* cboCDFile; static gcn::Button* cmdCDEject; static gcn::Button* cmdCDSelect; static gcn::Label* lblCDVol; @@ -410,11 +408,11 @@ void InitPanelHD(const struct _ConfigCategory& category) cdFileActionListener = new CDFileActionListener(); genericActionListener = new GenericActionListener(); - chkHDReadOnly = new gcn::UaeCheckBox("Master harddrive write protection"); + chkHDReadOnly = new gcn::CheckBox("Master harddrive write protection"); chkHDReadOnly->setId("chkHDRO"); chkHDReadOnly->addActionListener(genericActionListener); - chkCD = new gcn::UaeCheckBox("CD drive"); + chkCD = new gcn::CheckBox("CD drive"); chkCD->addActionListener(cdCheckActionListener); cmdCDEject = new gcn::Button("Eject"); @@ -429,7 +427,7 @@ void InitPanelHD(const struct _ConfigCategory& category) cmdCDSelect->setId("CDSelect"); cmdCDSelect->addActionListener(cdButtonActionListener); - cboCDFile = new gcn::UaeDropDown(&cdfileList); + cboCDFile = new gcn::DropDown(&cdfileList); cboCDFile->setSize(category.panel->getWidth() - 2 * DISTANCE_BORDER, cboCDFile->getHeight()); cboCDFile->setBaseColor(gui_baseCol); cboCDFile->setBackgroundColor(colTextboxBackground); diff --git a/src/osdep/gui/PanelInput.cpp b/src/osdep/gui/PanelInput.cpp index 46744493..bca64692 100644 --- a/src/osdep/gui/PanelInput.cpp +++ b/src/osdep/gui/PanelInput.cpp @@ -3,8 +3,6 @@ #include #include #include "SelectorEntry.hpp" -#include "UaeDropDown.hpp" -#include "UaeCheckBox.hpp" #include "sysdeps.h" #include "options.h" @@ -21,32 +19,32 @@ static const char* mousespeed_list[] = {".25", ".5", "1x", "2x", "4x"}; static const int mousespeed_values[] = {2, 5, 10, 20, 40}; static gcn::Label* lblPort0; -static gcn::UaeDropDown* cboPort0; +static gcn::DropDown* cboPort0; static gcn::Label* lblPort1; -static gcn::UaeDropDown* cboPort1; +static gcn::DropDown* cboPort1; -static gcn::UaeDropDown* cboPort0mode; -static gcn::UaeDropDown* cboPort1mode; +static gcn::DropDown* cboPort0mode; +static gcn::DropDown* cboPort1mode; static gcn::Label* lblPort0mousemode; -static gcn::UaeDropDown* cboPort0mousemode; +static gcn::DropDown* cboPort0mousemode; static gcn::Label* lblPort1mousemode; -static gcn::UaeDropDown* cboPort1mousemode; +static gcn::DropDown* cboPort1mousemode; static gcn::Label* lblPort2; -static gcn::UaeDropDown* cboPort2; +static gcn::DropDown* cboPort2; static gcn::Label* lblPort3; -static gcn::UaeDropDown* cboPort3; +static gcn::DropDown* cboPort3; -static gcn::UaeDropDown* cboPort2mode; -static gcn::UaeDropDown* cboPort3mode; +static gcn::DropDown* cboPort2mode; +static gcn::DropDown* cboPort3mode; static gcn::Label* lblAutofire; -static gcn::UaeDropDown* cboAutofire; +static gcn::DropDown* cboAutofire; static gcn::Label* lblMouseSpeed; static gcn::Label* lblMouseSpeedInfo; static gcn::Slider* sldMouseSpeed; -static gcn::UaeCheckBox* chkMouseHack; +static gcn::CheckBox* chkMouseHack; class StringListModel : public gcn::ListModel { @@ -290,14 +288,14 @@ void InitPanelInput(const struct _ConfigCategory& category) lblPort0 = new gcn::Label("Port 0 [Mouse]:"); lblPort0->setAlignment(gcn::Graphics::RIGHT); - cboPort0 = new gcn::UaeDropDown(&ctrlPortList); + cboPort0 = new gcn::DropDown(&ctrlPortList); cboPort0->setSize(textFieldWidth / 2, cboPort0->getHeight()); cboPort0->setBaseColor(gui_baseCol); cboPort0->setBackgroundColor(colTextboxBackground); cboPort0->setId("cboPort0"); cboPort0->addActionListener(inputActionListener); - cboPort0mode = new gcn::UaeDropDown(&ctrlPortModeList); + cboPort0mode = new gcn::DropDown(&ctrlPortModeList); cboPort0mode->setSize(cboPort0mode->getWidth(), cboPort0mode->getHeight()); cboPort0mode->setBaseColor(gui_baseCol); cboPort0mode->setBackgroundColor(colTextboxBackground); @@ -307,14 +305,14 @@ void InitPanelInput(const struct _ConfigCategory& category) lblPort1 = new gcn::Label("Port 1 [Joystick]:"); lblPort1->setAlignment(gcn::Graphics::RIGHT); lblPort0->setSize(lblPort1->getWidth(), lblPort0->getHeight()); - cboPort1 = new gcn::UaeDropDown(&ctrlPortList); + cboPort1 = new gcn::DropDown(&ctrlPortList); cboPort1->setSize(textFieldWidth / 2, cboPort1->getHeight()); cboPort1->setBaseColor(gui_baseCol); cboPort1->setBackgroundColor(colTextboxBackground); cboPort1->setId("cboPort1"); cboPort1->addActionListener(inputActionListener); - cboPort1mode = new gcn::UaeDropDown(&ctrlPortModeList); + cboPort1mode = new gcn::DropDown(&ctrlPortModeList); cboPort1mode->setSize(cboPort1mode->getWidth(), cboPort1mode->getHeight()); cboPort1mode->setBaseColor(gui_baseCol); cboPort1mode->setBackgroundColor(colTextboxBackground); @@ -323,7 +321,7 @@ void InitPanelInput(const struct _ConfigCategory& category) lblPort2 = new gcn::Label("Port 2 [Parallel 1]:"); lblPort2->setAlignment(gcn::Graphics::LEFT); - cboPort2 = new gcn::UaeDropDown(&ctrlPortList); + cboPort2 = new gcn::DropDown(&ctrlPortList); cboPort2->setSize(textFieldWidth / 2, cboPort2->getHeight()); cboPort2->setBaseColor(gui_baseCol); cboPort2->setBackgroundColor(colTextboxBackground); @@ -332,7 +330,7 @@ void InitPanelInput(const struct _ConfigCategory& category) lblPort3 = new gcn::Label("Port 3 [Parallel 2]:"); lblPort3->setAlignment(gcn::Graphics::LEFT); - cboPort3 = new gcn::UaeDropDown(&ctrlPortList); + cboPort3 = new gcn::DropDown(&ctrlPortList); cboPort3->setSize(textFieldWidth / 2, cboPort3->getHeight()); cboPort3->setBaseColor(gui_baseCol); cboPort3->setBackgroundColor(colTextboxBackground); @@ -341,7 +339,7 @@ void InitPanelInput(const struct _ConfigCategory& category) lblPort0mousemode = new gcn::Label("Mouse Stick 0:"); lblPort0mousemode->setAlignment(gcn::Graphics::RIGHT); - cboPort0mousemode = new gcn::UaeDropDown(&ctrlPortMouseModeList); + cboPort0mousemode = new gcn::DropDown(&ctrlPortMouseModeList); cboPort0mousemode->setSize(68, cboPort0mousemode->getHeight()); cboPort0mousemode->setBaseColor(gui_baseCol); cboPort0mousemode->setBackgroundColor(colTextboxBackground); @@ -350,7 +348,7 @@ void InitPanelInput(const struct _ConfigCategory& category) lblPort1mousemode = new gcn::Label("Mouse Stick 1:"); lblPort1mousemode->setAlignment(gcn::Graphics::RIGHT); - cboPort1mousemode = new gcn::UaeDropDown(&ctrlPortMouseModeList); + cboPort1mousemode = new gcn::DropDown(&ctrlPortMouseModeList); cboPort1mousemode->setSize(68, cboPort1mousemode->getHeight()); cboPort1mousemode->setBaseColor(gui_baseCol); cboPort1mousemode->setBackgroundColor(colTextboxBackground); @@ -359,7 +357,7 @@ void InitPanelInput(const struct _ConfigCategory& category) lblAutofire = new gcn::Label("Autofire Rate:"); lblAutofire->setAlignment(gcn::Graphics::RIGHT); - cboAutofire = new gcn::UaeDropDown(&autofireList); + cboAutofire = new gcn::DropDown(&autofireList); cboAutofire->setSize(80, cboAutofire->getHeight()); cboAutofire->setBaseColor(gui_baseCol); cboAutofire->setBackgroundColor(colTextboxBackground); @@ -377,7 +375,7 @@ void InitPanelInput(const struct _ConfigCategory& category) sldMouseSpeed->addActionListener(inputActionListener); lblMouseSpeedInfo = new gcn::Label(".25"); - chkMouseHack = new gcn::UaeCheckBox("Enable mousehack"); + chkMouseHack = new gcn::CheckBox("Enable mousehack"); chkMouseHack->setId("MouseHack"); chkMouseHack->addActionListener(inputActionListener); diff --git a/src/osdep/gui/PanelMisc.cpp b/src/osdep/gui/PanelMisc.cpp index 2b2519b8..e8ba6d84 100644 --- a/src/osdep/gui/PanelMisc.cpp +++ b/src/osdep/gui/PanelMisc.cpp @@ -5,28 +5,26 @@ #include #include #include "SelectorEntry.hpp" -#include "UaeDropDown.hpp" -#include "UaeCheckBox.hpp" #include "sysdeps.h" #include "options.h" #include "gui_handling.h" -static gcn::UaeCheckBox* chkRetroArchQuit; -static gcn::UaeCheckBox* chkRetroArchMenu; -static gcn::UaeCheckBox* chkRetroArchReset; -//static gcn::UaeCheckBox* chkRetroArchSaveState; +static gcn::CheckBox* chkRetroArchQuit; +static gcn::CheckBox* chkRetroArchMenu; +static gcn::CheckBox* chkRetroArchReset; +//static gcn::CheckBox* chkRetroArchSaveState; -static gcn::UaeCheckBox* chkStatusLine; -static gcn::UaeCheckBox* chkShowGUI; +static gcn::CheckBox* chkStatusLine; +static gcn::CheckBox* chkShowGUI; -static gcn::UaeCheckBox* chkBSDSocket; -static gcn::UaeCheckBox* chkMasterWP; +static gcn::CheckBox* chkBSDSocket; +static gcn::CheckBox* chkMasterWP; static gcn::Label* lblNumLock; -static gcn::UaeDropDown* cboKBDLed_num; +static gcn::DropDown* cboKBDLed_num; static gcn::Label* lblScrLock; -static gcn::UaeDropDown* cboKBDLed_scr; +static gcn::DropDown* cboKBDLed_scr; static gcn::Label* lblOpenGUI; static gcn::TextField* txtOpenGUI; @@ -167,41 +165,41 @@ void InitPanelMisc(const struct _ConfigCategory& category) { miscActionListener = new MiscActionListener(); - chkStatusLine = new gcn::UaeCheckBox("Status Line"); + chkStatusLine = new gcn::CheckBox("Status Line"); chkStatusLine->setId("StatusLine"); chkStatusLine->addActionListener(miscActionListener); - chkShowGUI = new gcn::UaeCheckBox("Show GUI on startup"); + chkShowGUI = new gcn::CheckBox("Show GUI on startup"); chkShowGUI->setId("ShowGUI"); chkShowGUI->addActionListener(miscActionListener); - chkRetroArchQuit = new gcn::UaeCheckBox("Use RetroArch Quit Button"); + chkRetroArchQuit = new gcn::CheckBox("Use RetroArch Quit Button"); chkRetroArchQuit->setId("RetroArchQuit"); chkRetroArchQuit->addActionListener(miscActionListener); - chkRetroArchMenu = new gcn::UaeCheckBox("Use RetroArch Menu Button"); + chkRetroArchMenu = new gcn::CheckBox("Use RetroArch Menu Button"); chkRetroArchMenu->setId("RetroArchMenu"); chkRetroArchMenu->addActionListener(miscActionListener); - chkRetroArchReset = new gcn::UaeCheckBox("Use RetroArch Reset Button"); + chkRetroArchReset = new gcn::CheckBox("Use RetroArch Reset Button"); chkRetroArchReset->setId("RetroArchReset"); chkRetroArchReset->addActionListener(miscActionListener); - //chkRetroArchSavestate = new gcn::UaeCheckBox("Use RetroArch State Controls"); + //chkRetroArchSavestate = new gcn::CheckBox("Use RetroArch State Controls"); //chkRetroArchSavestate->setId("RetroArchState"); //chkRetroArchSavestate->addActionListener(miscActionListener); - chkBSDSocket = new gcn::UaeCheckBox("bsdsocket.library"); + chkBSDSocket = new gcn::CheckBox("bsdsocket.library"); chkBSDSocket->setId("BSDSocket"); chkBSDSocket->addActionListener(miscActionListener); - chkMasterWP = new gcn::UaeCheckBox("Master floppy write protection"); + chkMasterWP = new gcn::CheckBox("Master floppy write protection"); chkMasterWP->setId("MasterWP"); chkMasterWP->addActionListener(miscActionListener); lblNumLock = new gcn::Label("NumLock:"); lblNumLock->setAlignment(gcn::Graphics::RIGHT); - cboKBDLed_num = new gcn::UaeDropDown(&KBDLedList); + cboKBDLed_num = new gcn::DropDown(&KBDLedList); cboKBDLed_num->setBaseColor(gui_baseCol); cboKBDLed_num->setBackgroundColor(colTextboxBackground); cboKBDLed_num->setId("cboNumlock"); @@ -209,7 +207,7 @@ void InitPanelMisc(const struct _ConfigCategory& category) lblScrLock = new gcn::Label("ScrollLock:"); lblScrLock->setAlignment(gcn::Graphics::RIGHT); - cboKBDLed_scr = new gcn::UaeDropDown(&KBDLedList); + cboKBDLed_scr = new gcn::DropDown(&KBDLedList); cboKBDLed_scr->setBaseColor(gui_baseCol); cboKBDLed_scr->setBackgroundColor(colTextboxBackground); cboKBDLed_scr->setId("cboScrolllock"); diff --git a/src/osdep/gui/PanelQuickstart.cpp b/src/osdep/gui/PanelQuickstart.cpp index 6bc49b3e..c76b46ab 100644 --- a/src/osdep/gui/PanelQuickstart.cpp +++ b/src/osdep/gui/PanelQuickstart.cpp @@ -7,8 +7,6 @@ #include #include #include "SelectorEntry.hpp" -#include "UaeDropDown.hpp" -#include "UaeCheckBox.hpp" #include "sysdeps.h" #include "options.h" @@ -17,24 +15,24 @@ #include "gui_handling.h" static gcn::Label* lblModel; -static gcn::UaeDropDown* cboModel; +static gcn::DropDown* cboModel; static gcn::Label* lblConfig; -static gcn::UaeDropDown* cboConfig; -static gcn::UaeCheckBox* chkNTSC; +static gcn::DropDown* cboConfig; +static gcn::CheckBox* chkNTSC; -static gcn::UaeCheckBox* chkDFx[2]; -static gcn::UaeCheckBox* chkDFxWriteProtect[2]; +static gcn::CheckBox* chkDFx[2]; +static gcn::CheckBox* chkDFxWriteProtect[2]; static gcn::Button* cmdDFxInfo[2]; static gcn::Button* cmdDFxEject[2]; static gcn::Button* cmdDFxSelect[2]; -static gcn::UaeDropDown* cboDFxFile[2]; +static gcn::DropDown* cboDFxFile[2]; -static gcn::UaeCheckBox* chkCD; +static gcn::CheckBox* chkCD; static gcn::Button* cmdCDEject; static gcn::Button* cmdCDSelect; -static gcn::UaeDropDown* cboCDFile; +static gcn::DropDown* cboCDFile; -static gcn::UaeCheckBox* chkQuickstartMode; +static gcn::CheckBox* chkQuickstartMode; static gcn::Button* cmdSetConfiguration; struct amigamodels @@ -306,7 +304,7 @@ public: std::string getElementAt(const int i) override { - if (i < 0 || i >= lstMRUDiskList.size()) + if (i < 0 || i >= static_cast(lstMRUDiskList.size())) return "---"; return lstMRUDiskList[i]; } @@ -328,7 +326,7 @@ public: std::string getElementAt(const int i) override { - if (i < 0 || i >= lstMRUCDList.size()) + if (i < 0 || i >= static_cast(lstMRUCDList.size())) return "---"; return lstMRUCDList[i]; } @@ -517,6 +515,8 @@ public: //--------------------------------------- // Write-protect changed //--------------------------------------- + if (strlen(changed_prefs.floppyslots[i].df) <= 0) + return; disk_setwriteprotect(&changed_prefs, i, changed_prefs.floppyslots[i].df, chkDFxWriteProtect[i]->isSelected()); if (disk_getwriteprotect(&changed_prefs, changed_prefs.floppyslots[i].df) != chkDFxWriteProtect[i]-> @@ -608,7 +608,7 @@ public: if (actionEvent.getSource() == cboDFxFile[i]) { //--------------------------------------- - // Diskimage from list selected + // Disk image from list selected //--------------------------------------- if (!bIgnoreListChange) { @@ -671,24 +671,24 @@ void InitPanelQuickstart(const struct _ConfigCategory& category) lblModel = new gcn::Label("Amiga model:"); lblModel->setAlignment(gcn::Graphics::RIGHT); - cboModel = new gcn::UaeDropDown(&amigaModelList); + cboModel = new gcn::DropDown(&amigaModelList); cboModel->setSize(160, cboModel->getHeight()); cboModel->setBaseColor(gui_baseCol); cboModel->setBackgroundColor(colTextboxBackground); - cboModel->setId("qscboAModel"); + cboModel->setId("cboAModel"); cboModel->addActionListener(amigaModelActionListener); lblConfig = new gcn::Label("Config:"); lblConfig->setAlignment(gcn::Graphics::RIGHT); - cboConfig = new gcn::UaeDropDown(&amigaConfigList); + cboConfig = new gcn::DropDown(&amigaConfigList); cboConfig->setSize(category.panel->getWidth() - lblConfig->getWidth() - 8 - 2 * DISTANCE_BORDER, cboConfig->getHeight()); cboConfig->setBaseColor(gui_baseCol); cboConfig->setBackgroundColor(colTextboxBackground); - cboConfig->setId("qscboAConfig"); + cboConfig->setId("cboAConfig"); cboConfig->addActionListener(amigaModelActionListener); - chkNTSC = new gcn::UaeCheckBox("NTSC"); + chkNTSC = new gcn::CheckBox("NTSC"); chkNTSC->setId("qsNTSC"); chkNTSC->addActionListener(ntscButtonActionListener); @@ -696,12 +696,12 @@ void InitPanelQuickstart(const struct _ConfigCategory& category) { char tmp[20]; snprintf(tmp, 20, "DF%d:", i); - chkDFx[i] = new gcn::UaeCheckBox(tmp); + chkDFx[i] = new gcn::CheckBox(tmp); chkDFx[i]->addActionListener(dfxCheckActionListener); snprintf(tmp, 20, "qsDF%d", i); chkDFx[i]->setId(tmp); - chkDFxWriteProtect[i] = new gcn::UaeCheckBox("Write-protected"); + chkDFxWriteProtect[i] = new gcn::CheckBox("Write-protected"); chkDFxWriteProtect[i]->addActionListener(dfxCheckActionListener); snprintf(tmp, 20, "qsWP%d", i); chkDFxWriteProtect[i]->setId(tmp); @@ -727,16 +727,16 @@ void InitPanelQuickstart(const struct _ConfigCategory& category) cmdDFxSelect[i]->setId(tmp); cmdDFxSelect[i]->addActionListener(dfxButtonActionListener); - cboDFxFile[i] = new gcn::UaeDropDown(&diskfileList); + cboDFxFile[i] = new gcn::DropDown(&diskfileList); cboDFxFile[i]->setSize(category.panel->getWidth() - 2 * DISTANCE_BORDER, cboDFxFile[i]->getHeight()); cboDFxFile[i]->setBaseColor(gui_baseCol); cboDFxFile[i]->setBackgroundColor(colTextboxBackground); - snprintf(tmp, 20, "qscboDisk%d", i); + snprintf(tmp, 20, "cboDisk%d", i); cboDFxFile[i]->setId(tmp); cboDFxFile[i]->addActionListener(diskFileActionListener); } - chkCD = new gcn::UaeCheckBox("CD drive"); + chkCD = new gcn::CheckBox("CD drive"); chkCD->setId("qsCD drive"); chkCD->setEnabled(false); @@ -752,14 +752,14 @@ void InitPanelQuickstart(const struct _ConfigCategory& category) cmdCDSelect->setId("qsCDSelect"); cmdCDSelect->addActionListener(cdButtonActionListener); - cboCDFile = new gcn::UaeDropDown(&cdfileList); + cboCDFile = new gcn::DropDown(&cdfileList); cboCDFile->setSize(category.panel->getWidth() - 2 * DISTANCE_BORDER, cboCDFile->getHeight()); cboCDFile->setBaseColor(gui_baseCol); cboCDFile->setBackgroundColor(colTextboxBackground); - cboCDFile->setId("qscboCD"); + cboCDFile->setId("cboCD"); cboCDFile->addActionListener(cdFileActionListener); - chkQuickstartMode = new gcn::UaeCheckBox("Start in Quickstart mode"); + chkQuickstartMode = new gcn::CheckBox("Start in Quickstart mode"); chkQuickstartMode->setId("qsMode"); chkQuickstartMode->addActionListener(quickstartModeActionListener); @@ -870,7 +870,7 @@ static void AdjustDropDownControls(void) if (changed_prefs.floppyslots[i].dfxtype != DRV_NONE && strlen(changed_prefs.floppyslots[i].df) > 0) { - for (unsigned int j = 0; j < lstMRUDiskList.size(); ++j) + for (auto j = 0; j < static_cast(lstMRUDiskList.size()); ++j) { if (strcmp(lstMRUDiskList[j].c_str(), changed_prefs.floppyslots[i].df) == 0) { @@ -884,7 +884,7 @@ static void AdjustDropDownControls(void) cboCDFile->clearSelected(); if (changed_prefs.cdslots[0].inuse && strlen(changed_prefs.cdslots[0].name) > 0) { - for (unsigned int i = 0; i < lstMRUCDList.size(); ++i) + for (auto i = 0; i < static_cast(lstMRUCDList.size()); ++i) { if (lstMRUCDList[i].c_str() != changed_prefs.cdslots[0].name) { diff --git a/src/osdep/gui/PanelROM.cpp b/src/osdep/gui/PanelROM.cpp index 9bcba370..0285a5a9 100644 --- a/src/osdep/gui/PanelROM.cpp +++ b/src/osdep/gui/PanelROM.cpp @@ -5,7 +5,6 @@ #include #include #include "SelectorEntry.hpp" -#include "UaeDropDown.hpp" #include "sysdeps.h" #include "options.h" @@ -13,16 +12,16 @@ #include "gui_handling.h" static gcn::Label* lblMainROM; -static gcn::UaeDropDown* cboMainROM; +static gcn::DropDown* cboMainROM; static gcn::Button* cmdMainROM; static gcn::Label* lblExtROM; -static gcn::UaeDropDown* cboExtROM; +static gcn::DropDown* cboExtROM; static gcn::Button* cmdExtROM; static gcn::Label* lblCartROM; -static gcn::UaeDropDown* cboCartROM; +static gcn::DropDown* cboCartROM; static gcn::Button* cmdCartROM; static gcn::Label* lblUAEROM; -static gcn::UaeDropDown* cboUAEROM; +static gcn::DropDown* cboUAEROM; class ROMListModel : public gcn::ListModel { @@ -240,7 +239,7 @@ void InitPanelROM(const struct _ConfigCategory& category) cartROMList = new ROMListModel(ROMTYPE_ALL_CART); lblMainROM = new gcn::Label("Main ROM File:"); - cboMainROM = new gcn::UaeDropDown(mainROMList); + cboMainROM = new gcn::DropDown(mainROMList); cboMainROM->setSize(textFieldWidth, cboMainROM->getHeight()); cboMainROM->setBaseColor(gui_baseCol); cboMainROM->setBackgroundColor(colTextboxBackground); @@ -253,7 +252,7 @@ void InitPanelROM(const struct _ConfigCategory& category) cmdMainROM->addActionListener(romButtonActionListener); lblExtROM = new gcn::Label("Extended ROM File:"); - cboExtROM = new gcn::UaeDropDown(extROMList); + cboExtROM = new gcn::DropDown(extROMList); cboExtROM->setSize(textFieldWidth, cboExtROM->getHeight()); cboExtROM->setBaseColor(gui_baseCol); cboExtROM->setBackgroundColor(colTextboxBackground); @@ -266,7 +265,7 @@ void InitPanelROM(const struct _ConfigCategory& category) cmdExtROM->addActionListener(romButtonActionListener); lblCartROM = new gcn::Label("Cartridge ROM File:"); - cboCartROM = new gcn::UaeDropDown(cartROMList); + cboCartROM = new gcn::DropDown(cartROMList); cboCartROM->setSize(textFieldWidth, cboCartROM->getHeight()); cboCartROM->setBaseColor(gui_baseCol); cboCartROM->setBackgroundColor(colTextboxBackground); @@ -279,7 +278,7 @@ void InitPanelROM(const struct _ConfigCategory& category) cmdCartROM->addActionListener(romButtonActionListener); lblUAEROM = new gcn::Label("Advanced UAE expansion board/Boot ROM:"); - cboUAEROM = new gcn::UaeDropDown(&uaeROMList); + cboUAEROM = new gcn::DropDown(&uaeROMList); cboUAEROM->setSize(textFieldWidth, cboUAEROM->getHeight()); cboUAEROM->setBaseColor(gui_baseCol); cboUAEROM->setBackgroundColor(colTextboxBackground); diff --git a/src/osdep/gui/PanelSavestate.cpp b/src/osdep/gui/PanelSavestate.cpp index 896f466d..882c83a2 100644 --- a/src/osdep/gui/PanelSavestate.cpp +++ b/src/osdep/gui/PanelSavestate.cpp @@ -8,7 +8,6 @@ #include #include #include "SelectorEntry.hpp" -#include "UaeRadioButton.hpp" #include "sysdeps.h" #include "xwin.h" @@ -20,10 +19,10 @@ int currentStateNum = 0; static gcn::Window* grpNumber; -static gcn::UaeRadioButton* optState0; -static gcn::UaeRadioButton* optState1; -static gcn::UaeRadioButton* optState2; -static gcn::UaeRadioButton* optState3; +static gcn::RadioButton* optState0; +static gcn::RadioButton* optState1; +static gcn::RadioButton* optState2; +static gcn::RadioButton* optState3; static gcn::Window* wndScreenshot; static gcn::Icon* icoSavestate = nullptr; static gcn::Image* imgSavestate = nullptr; @@ -101,19 +100,19 @@ void InitPanelSavestate(const struct _ConfigCategory& category) { savestateActionListener = new SavestateActionListener(); - optState0 = new gcn::UaeRadioButton("0", "radiostategroup"); + optState0 = new gcn::RadioButton("0", "radiostategroup"); optState0->setId("State0"); optState0->addActionListener(savestateActionListener); - optState1 = new gcn::UaeRadioButton("1", "radiostategroup"); + optState1 = new gcn::RadioButton("1", "radiostategroup"); optState1->setId("State1"); optState1->addActionListener(savestateActionListener); - optState2 = new gcn::UaeRadioButton("2", "radiostategroup"); + optState2 = new gcn::RadioButton("2", "radiostategroup"); optState2->setId("State2"); optState2->addActionListener(savestateActionListener); - optState3 = new gcn::UaeRadioButton("3", "radiostategroup"); + optState3 = new gcn::RadioButton("3", "radiostategroup"); optState3->setId("State3"); optState3->addActionListener(savestateActionListener); diff --git a/src/osdep/gui/PanelSound.cpp b/src/osdep/gui/PanelSound.cpp index 7cb293e9..5240cbf8 100644 --- a/src/osdep/gui/PanelSound.cpp +++ b/src/osdep/gui/PanelSound.cpp @@ -5,8 +5,6 @@ #include #include #include "SelectorEntry.hpp" -#include "UaeRadioButton.hpp" -#include "UaeDropDown.hpp" #include "sysdeps.h" #include "options.h" @@ -15,19 +13,19 @@ static gcn::Window* grpSound; -static gcn::UaeRadioButton* optSoundDisabled; -static gcn::UaeRadioButton* optSoundDisabledEmu; -static gcn::UaeRadioButton* optSoundEmulated; -static gcn::UaeRadioButton* optSoundEmulatedBest; +static gcn::RadioButton* optSoundDisabled; +static gcn::RadioButton* optSoundDisabledEmu; +static gcn::RadioButton* optSoundEmulated; +static gcn::RadioButton* optSoundEmulatedBest; static gcn::Window* grpMode; -static gcn::UaeRadioButton* optMono; -static gcn::UaeRadioButton* optStereo; +static gcn::RadioButton* optMono; +static gcn::RadioButton* optStereo; static gcn::Label* lblFrequency; -static gcn::UaeDropDown* cboFrequency; +static gcn::DropDown* cboFrequency; static gcn::Label* lblInterpolation; -static gcn::UaeDropDown* cboInterpolation; +static gcn::DropDown* cboInterpolation; static gcn::Label* lblFilter; -static gcn::UaeDropDown* cboFilter; +static gcn::DropDown* cboFilter; static gcn::Label* lblSeparation; static gcn::Label* lblSeparationInfo; static gcn::Slider* sldSeparation; @@ -242,19 +240,19 @@ void InitPanelSound(const struct _ConfigCategory& category) { soundActionListener = new SoundActionListener(); - optSoundDisabled = new gcn::UaeRadioButton("Disabled", "radiosoundgroup"); + optSoundDisabled = new gcn::RadioButton("Disabled", "radiosoundgroup"); optSoundDisabled->setId("sndDisable"); optSoundDisabled->addActionListener(soundActionListener); - optSoundDisabledEmu = new gcn::UaeRadioButton("Disabled, but emulated", "radiosoundgroup"); + optSoundDisabledEmu = new gcn::RadioButton("Disabled, but emulated", "radiosoundgroup"); optSoundDisabledEmu->setId("sndDisEmu"); optSoundDisabledEmu->addActionListener(soundActionListener); - optSoundEmulated = new gcn::UaeRadioButton("Enabled", "radiosoundgroup"); + optSoundEmulated = new gcn::RadioButton("Enabled", "radiosoundgroup"); optSoundEmulated->setId("sndEmulate"); optSoundEmulated->addActionListener(soundActionListener); - optSoundEmulatedBest = new gcn::UaeRadioButton("Enabled, most accurate", "radiosoundgroup"); + optSoundEmulatedBest = new gcn::RadioButton("Enabled, most accurate", "radiosoundgroup"); optSoundEmulatedBest->setId("sndEmuBest"); optSoundEmulatedBest->addActionListener(soundActionListener); @@ -269,17 +267,17 @@ void InitPanelSound(const struct _ConfigCategory& category) lblFrequency = new gcn::Label("Frequency:"); lblFrequency->setAlignment(gcn::Graphics::RIGHT); - cboFrequency = new gcn::UaeDropDown(&frequencyTypeList); + cboFrequency = new gcn::DropDown(&frequencyTypeList); cboFrequency->setSize(160, cboFrequency->getHeight()); cboFrequency->setBaseColor(gui_baseCol); cboFrequency->setBackgroundColor(colTextboxBackground); cboFrequency->setId("cboFrequency"); cboFrequency->addActionListener(soundActionListener); - optMono = new gcn::UaeRadioButton("Mono", "radiosoundmodegroup"); + optMono = new gcn::RadioButton("Mono", "radiosoundmodegroup"); optMono->addActionListener(soundActionListener); - optStereo = new gcn::UaeRadioButton("Stereo", "radiosoundmodegroup"); + optStereo = new gcn::RadioButton("Stereo", "radiosoundmodegroup"); optStereo->addActionListener(soundActionListener); grpMode = new gcn::Window("Mode"); @@ -291,7 +289,7 @@ void InitPanelSound(const struct _ConfigCategory& category) lblInterpolation = new gcn::Label("Interpolation:"); lblInterpolation->setAlignment(gcn::Graphics::RIGHT); - cboInterpolation = new gcn::UaeDropDown(&interpolationTypeList); + cboInterpolation = new gcn::DropDown(&interpolationTypeList); cboInterpolation->setSize(160, cboInterpolation->getHeight()); cboInterpolation->setBaseColor(gui_baseCol); cboInterpolation->setBackgroundColor(colTextboxBackground); @@ -300,7 +298,7 @@ void InitPanelSound(const struct _ConfigCategory& category) lblFilter = new gcn::Label("Filter:"); lblFilter->setAlignment(gcn::Graphics::RIGHT); - cboFilter = new gcn::UaeDropDown(&filterTypeList); + cboFilter = new gcn::DropDown(&filterTypeList); cboFilter->setSize(160, cboFilter->getHeight()); cboFilter->setBaseColor(gui_baseCol); cboFilter->setBackgroundColor(colTextboxBackground); diff --git a/src/osdep/gui/UaeCheckBox.cpp b/src/osdep/gui/UaeCheckBox.cpp deleted file mode 100644 index 18c12f02..00000000 --- a/src/osdep/gui/UaeCheckBox.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "UaeCheckBox.hpp" -#include -#include - -namespace gcn -{ - UaeCheckBox::UaeCheckBox() - = default; - - UaeCheckBox::UaeCheckBox(const std::string& caption, - const bool selected) - : CheckBox(caption, selected) - { - setId(caption); - } - - UaeCheckBox::~UaeCheckBox() - = default; - - void UaeCheckBox::draw(Graphics* graphics) - { - drawBox(graphics); - - graphics->setFont(getFont()); - graphics->setColor(getForegroundColor()); - - const auto h = getHeight() + getHeight() / 2; - - graphics->drawText(getCaption(), h - 2, 0); - - if (isFocused()) - { - graphics->setColor(Color(0x000000)); - graphics->drawRectangle(Rectangle(0, - 0, - getWidth(), - getHeight())); - } - } - - void UaeCheckBox::drawBox(Graphics* graphics) - { - const auto h = getHeight() - 2; - const auto alpha = getBaseColor().a; - auto faceColor = getBaseColor(); - faceColor.a = alpha; - auto highlightColor = faceColor + 0x303030; - highlightColor.a = alpha; - auto shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; - - graphics->setColor(shadowColor); - graphics->drawLine(1, 1, h, 1); - graphics->drawLine(1, 1, 1, h); - - graphics->setColor(highlightColor); - graphics->drawLine(h, 1, h, h); - graphics->drawLine(1, h, h - 1, h); - - auto backCol = getBackgroundColor(); - if (!isEnabled()) - backCol = backCol - 0x303030; - graphics->setColor(backCol); - graphics->fillRectangle(Rectangle(2, 2, h - 2, h - 2)); - - graphics->setColor(getForegroundColor()); - - if (mSelected) - { - graphics->drawLine(3, 9, 6, h - 2); - graphics->drawLine(4, 9, 7, h - 2); - - graphics->drawLine(6, h - 2, h - 3, 4); - graphics->drawLine(7, h - 2, h - 2, 4); - } - } -} diff --git a/src/osdep/gui/UaeCheckBox.hpp b/src/osdep/gui/UaeCheckBox.hpp deleted file mode 100644 index 92042d88..00000000 --- a/src/osdep/gui/UaeCheckBox.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef GCN_UAECHECKBOX_HPP -#define GCN_UAECHECKBOX_HPP - -#include -#include - -#include -#include -#include - -namespace gcn -{ - class GCN_CORE_DECLSPEC UaeCheckBox : public CheckBox - { - public: - UaeCheckBox(); - - UaeCheckBox(const std::string& caption, - bool selected = false); - - virtual ~UaeCheckBox(); - - void draw(Graphics* graphics) override; - - protected: - void drawBox(Graphics* graphics) override; - }; -} - - -#endif // end GCN_UAECHECKBOX_HPP diff --git a/src/osdep/gui/UaeDropDown.cpp b/src/osdep/gui/UaeDropDown.cpp deleted file mode 100644 index 85029bd7..00000000 --- a/src/osdep/gui/UaeDropDown.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include "UaeDropDown.hpp" -#include -#include - -namespace gcn -{ - UaeDropDown::UaeDropDown(ListModel* listModel, - ScrollArea* scrollArea, - ListBox* listBox) - : DropDown(listModel, scrollArea, listBox) - { -#ifdef ANDROID - mScrollArea->setScrollbarWidth(30); -#else - mScrollArea->setScrollbarWidth(20); -#endif - } - - - UaeDropDown::~UaeDropDown() - = default; - - - void UaeDropDown::keyPressed(KeyEvent& keyEvent) - { - if (keyEvent.isConsumed()) - return; - - auto key = keyEvent.getKey(); - - if ((key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) - && !mDroppedDown) - { - dropDown(); - keyEvent.consume(); - } - else if (key.getValue() == Key::UP) - { - setSelected(getSelected() - 1); - keyEvent.consume(); - distributeValueChangedEvent(); - } - else if (key.getValue() == Key::DOWN) - { - setSelected(getSelected() + 1); - keyEvent.consume(); - distributeValueChangedEvent(); - } - } - - void UaeDropDown::clearSelected() const - { - mListBox->setSelected(-1); - } - - bool UaeDropDown::isDroppedDown() const - { - return mDroppedDown; - } - - bool UaeDropDown::getEnabled() const - { - return mEnabled; - } - - void UaeDropDown::setEnabled(bool enabled) - { - if (mEnabled != enabled) - { - mEnabled = enabled; - if (mEnabled) - mBackgroundColor = mBackgroundColorBackup; - else - { - mBackgroundColorBackup = mBackgroundColor; - mBackgroundColor = mBackgroundColor - 0x303030; - } - } - } -} diff --git a/src/osdep/gui/UaeDropDown.hpp b/src/osdep/gui/UaeDropDown.hpp deleted file mode 100644 index e66dcc23..00000000 --- a/src/osdep/gui/UaeDropDown.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef GCN_UAEDROPDOWN_HPP -#define GCN_UAEDROPDOWN_HPP - -#include -#include -#include -#include - -namespace gcn -{ - class GCN_CORE_DECLSPEC UaeDropDown : public DropDown - { - public: - UaeDropDown(ListModel* listModel = nullptr, - ScrollArea* scrollArea = nullptr, - ListBox* listBox = nullptr); - - virtual ~UaeDropDown(); - - void keyPressed(KeyEvent& keyEvent) override; - - void setEnabled(bool enabled); - - bool getEnabled(void) const; - - void clearSelected(void) const; - - bool isDroppedDown(void) const; - - protected: - Color mBackgroundColorBackup; - }; -} - - -#endif // end GCN_UAEDROPDOWN_HPP diff --git a/src/osdep/gui/UaeListBox.cpp b/src/osdep/gui/UaeListBox.cpp deleted file mode 100644 index bcd7a390..00000000 --- a/src/osdep/gui/UaeListBox.cpp +++ /dev/null @@ -1,105 +0,0 @@ -#include "UaeListBox.hpp" - -#include -#include -#include -#include -#include - -namespace gcn -{ - Color colSelectorInactive; - Color colSelectorActive; - - UaeListBox::UaeListBox() - = default; - - UaeListBox::UaeListBox(ListModel* listModel) - : ListBox(listModel) - { - } - - UaeListBox::~UaeListBox() - = default; - - void UaeListBox::draw(Graphics* graphics) - { - graphics->setColor(getBaseColor()); - graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); - - if (mListModel == nullptr) - { - return; - } - - graphics->setColor(getForegroundColor()); - graphics->setFont(getFont()); - - // Check the current clip area so we don't draw unnecessary items - // that are not visible. - const auto currentClipArea = graphics->getCurrentClipArea(); - const int rowHeight = getFont()->getHeight(); - - // Calculate the number of rows to draw by checking the clip area. - // The addition of two makes covers a partial visible row at the top - // and a partial visible row at the bottom. - auto numberOfRows = currentClipArea.height / rowHeight + 2; - - if (numberOfRows > mListModel->getNumberOfElements()) - { - numberOfRows = mListModel->getNumberOfElements(); - } - - // Calculate which row to start drawing. If the list box - // has a negative y coordinate value we should check if - // we should drop rows in the begining of the list as - // they might not be visible. A negative y value is very - // common if the list box for instance resides in a scroll - // area and the user has scrolled the list box downwards. - int startRow; - if (getY() < 0) - { - startRow = -1 * (getY() / rowHeight); - } - else - { - startRow = 0; - } - - colSelectorInactive.r = 170; - colSelectorInactive.g = 170; - colSelectorInactive.b = 170; - colSelectorActive.r = 103; - colSelectorActive.g = 136; - colSelectorActive.b = 187; - - // The y coordinate where we start to draw the text is - // simply the y coordinate multiplied with the font height. - auto y = rowHeight * startRow; - for (auto i = startRow; i < startRow + numberOfRows; ++i) - { - if (i == mSelected) - { - if (isFocused()) - graphics->setColor(colSelectorActive); - else - graphics->setColor(colSelectorInactive); - graphics->fillRectangle(Rectangle(0, y, getWidth(), rowHeight)); - graphics->setColor(getForegroundColor()); - } - - // If the row height is greater than the font height we - // draw the text with a center vertical alignment. - if (rowHeight > getFont()->getHeight()) - { - graphics->drawText(mListModel->getElementAt(i), 1, y + rowHeight / 2 - getFont()->getHeight() / 2); - } - else - { - graphics->drawText(mListModel->getElementAt(i), 1, y); - } - - y += rowHeight; - } - } -} diff --git a/src/osdep/gui/UaeListBox.hpp b/src/osdep/gui/UaeListBox.hpp deleted file mode 100644 index b20257e8..00000000 --- a/src/osdep/gui/UaeListBox.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef GCN_UAELISTBOX_HPP -#define GCN_UAELISTBOX_HPP - -#include - -#include -#include -#include -#include - -namespace gcn -{ - class GCN_CORE_DECLSPEC UaeListBox : public ListBox - { - public: - UaeListBox(); - - explicit UaeListBox(ListModel* listModel); - - virtual ~UaeListBox(); - - void draw(Graphics* graphics) override; - }; -} - - -#endif // end GCN_UAELISTBOX_HPP diff --git a/src/osdep/gui/UaeRadioButton.cpp b/src/osdep/gui/UaeRadioButton.cpp deleted file mode 100644 index 3dfab7f5..00000000 --- a/src/osdep/gui/UaeRadioButton.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "UaeRadioButton.hpp" -#include -#include - -namespace gcn -{ - UaeRadioButton::UaeRadioButton() - : RadioButton() - { - } - - UaeRadioButton::UaeRadioButton(const std::string& caption, - const std::string& group, - const bool selected) - : RadioButton(caption, group, selected) - { - setId(caption); - } - - UaeRadioButton::~UaeRadioButton() - { - // Remove us from the group list - setGroup(""); - } - - void UaeRadioButton::draw(Graphics* graphics) - { - graphics->pushClipArea(Rectangle(1, - 1, - getWidth() - 1, - getHeight() - 1)); - drawBox(graphics); - graphics->popClipArea(); - - - graphics->setFont(getFont()); - graphics->setColor(getForegroundColor()); - - if (isFocused()) - { - graphics->setColor(Color(0x000000)); - graphics->drawRectangle(Rectangle(0, - 0, - getWidth(), - getHeight())); - } - - const int h = getHeight() + getHeight() / 2; - - graphics->drawText(getCaption(), h - 2, 0); - } -} diff --git a/src/osdep/gui/UaeRadioButton.hpp b/src/osdep/gui/UaeRadioButton.hpp deleted file mode 100644 index 9b1600a8..00000000 --- a/src/osdep/gui/UaeRadioButton.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef GCN_UAERADIOBUTTON_HPP -#define GCN_UAERADIOBUTTON_HPP - -#include -#include - -#include -#include -#include - -namespace gcn -{ - class GCN_CORE_DECLSPEC UaeRadioButton : public RadioButton - { - public: - UaeRadioButton(); - - UaeRadioButton(const std::string& caption, - const std::string& group, - bool selected = false); - - virtual ~UaeRadioButton(); - - void draw(Graphics* graphics) override; - }; -} - - -#endif // end GCN_UAERADIOBUTTON_HPP diff --git a/src/osdep/gui/gui_handling.h b/src/osdep/gui/gui_handling.h index 96503167..73586fa5 100644 --- a/src/osdep/gui/gui_handling.h +++ b/src/osdep/gui/gui_handling.h @@ -35,6 +35,7 @@ extern gcn::Gui* uae_gui; extern gcn::Container* gui_top; extern gcn::Color gui_baseCol; extern gcn::Color colTextboxBackground; +extern gcn::Color colSelectorActive; extern gcn::SDLInput* gui_input; extern SDL_Surface* gui_screen; extern SDL_Joystick* gui_joystick; diff --git a/src/osdep/gui/main_window.cpp b/src/osdep/gui/main_window.cpp index be8dbd02..fe4f6e1d 100644 --- a/src/osdep/gui/main_window.cpp +++ b/src/osdep/gui/main_window.cpp @@ -417,7 +417,7 @@ void amiberry_gui_init() SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); gui_texture = SDL_CreateTexture(renderer, gui_screen->format->format, SDL_TEXTUREACCESS_STREAMING, gui_screen->w, - gui_screen->h); + gui_screen->h); check_error_sdl(gui_texture == nullptr, "Unable to create GUI texture:"); #endif @@ -1120,13 +1120,13 @@ void gui_widgets_init() gui_top->add(cmdShutdown, DISTANCE_BORDER, GUI_HEIGHT - DISTANCE_BORDER - BUTTON_HEIGHT); #endif gui_top->add(cmdQuit, DISTANCE_BORDER + BUTTON_WIDTH + DISTANCE_NEXT_X, - GUI_HEIGHT - DISTANCE_BORDER - BUTTON_HEIGHT); + GUI_HEIGHT - DISTANCE_BORDER - BUTTON_HEIGHT); gui_top->add(cmdRestart, DISTANCE_BORDER + 2 * BUTTON_WIDTH + 2 * DISTANCE_NEXT_X, - GUI_HEIGHT - DISTANCE_BORDER - BUTTON_HEIGHT); + GUI_HEIGHT - DISTANCE_BORDER - BUTTON_HEIGHT); gui_top->add(cmdHelp, DISTANCE_BORDER + 3 * BUTTON_WIDTH + 3 * DISTANCE_NEXT_X, - GUI_HEIGHT - DISTANCE_BORDER - BUTTON_HEIGHT); + GUI_HEIGHT - DISTANCE_BORDER - BUTTON_HEIGHT); gui_top->add(cmdReset, DISTANCE_BORDER + 5 * BUTTON_WIDTH + 5 * DISTANCE_NEXT_X, - GUI_HEIGHT - DISTANCE_BORDER - BUTTON_HEIGHT); + GUI_HEIGHT - DISTANCE_BORDER - BUTTON_HEIGHT); gui_top->add(cmdStart, GUI_WIDTH - DISTANCE_BORDER - BUTTON_WIDTH, GUI_HEIGHT - DISTANCE_BORDER - BUTTON_HEIGHT); gui_top->add(selectors, DISTANCE_BORDER + 1, DISTANCE_BORDER + 1);