Modernized code in guisan objects, improved GUI layout

This commit is contained in:
Dimitris Panokostas 2020-05-15 00:27:51 +02:00
parent ed31f6849d
commit ecb56ef5be
94 changed files with 7326 additions and 7347 deletions

View file

@ -68,128 +68,128 @@
namespace gcn
{
/**
* A regular button. Add an ActionListener to it to know when it
* has been clicked.
*
* NOTE: You can only have text (a caption) on the button. If you want it
* to handle, for instance images, you can implement an ImageButton
* of your own and overload member functions from Button.
*/
class GCN_CORE_DECLSPEC Button : public Widget,
public MouseListener,
public KeyListener,
public FocusListener
{
public:
/**
* Constructor.
*/
Button();
/**
* A regular button. Add an ActionListener to it to know when it
* has been clicked.
*
* NOTE: You can only have text (a caption) on the button. If you want it
* to handle, for instance images, you can implement an ImageButton
* of your own and overload member functions from Button.
*/
class GCN_CORE_DECLSPEC Button : public Widget,
public MouseListener,
public KeyListener,
public FocusListener
{
public:
/**
* Constructor.
*/
Button();
/**
* Constructor.
*
* @param caption the caption of the Button.
*/
explicit Button(std::string caption);
/**
* Constructor.
*
* @param caption the caption of the Button.
*/
explicit Button(std::string caption);
/**
* Sets the Button caption.
*
* @param caption the Button caption.
*/
void setCaption(const std::string& caption);
/**
* Sets the Button caption.
*
* @param caption the Button caption.
*/
void setCaption(const std::string& caption);
/**
* Gets the Button caption.
*
* @return the Button caption.
*/
[[nodiscard]] const std::string& getCaption() const;
/**
* Gets the Button caption.
*
* @return the Button caption.
*/
[[nodiscard]] const std::string& getCaption() const;
/**
* Sets the alignment for the caption.
*
* @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT
* @see Graphics
*/
virtual void setAlignment(unsigned int alignment);
/**
* Sets the alignment for the caption.
*
* @param alignment Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT
* @see Graphics
*/
virtual void setAlignment(unsigned int alignment);
/**
* Gets the alignment for the caption.
*
* @return alignment of caption.
*/
[[nodiscard]] virtual unsigned int getAlignment() const;
/**
* Gets the alignment for the caption.
*
* @return alignment of caption.
*/
[[nodiscard]] virtual unsigned int getAlignment() const;
/**
* Sets the spacing between the border of this button and its caption.
*
* @param spacing is a number between 0 and 255. The default value for
spacing is 4 and can be changed using this method.
*/
void setSpacing(unsigned int spacing);
/**
* Sets the spacing between the border of this button and its caption.
*
* @param spacing is a number between 0 and 255. The default value for
spacing is 4 and can be changed using this method.
*/
void setSpacing(unsigned int spacing);
/**
* Gets the spacing between the border of this button and its caption.
*
* @return spacing.
*/
[[nodiscard]] unsigned int getSpacing() const;
/**
* Gets the spacing between the border of this button and its caption.
*
* @return spacing.
*/
[[nodiscard]] unsigned int getSpacing() const;
/**
* Adjusts the buttons size to fit the content.
*/
virtual void adjustSize();
/**
* Adjusts the buttons size to fit the content.
*/
virtual void adjustSize();
/**
* Checks if the button is pressed down. Useful when drawing.
*
* @return true if the button is pressed down.
*/
[[nodiscard]] bool isPressed() const;
/**
* Checks if the button is pressed down. Useful when drawing.
*
* @return true if the button is pressed down.
*/
[[nodiscard]] bool isPressed() const;
//Inherited from Widget
//Inherited from Widget
void draw(Graphics* graphics) override;
void draw(Graphics* graphics) override;
void drawBorder(Graphics* graphics) override;
void drawBorder(Graphics* graphics) override;
// Inherited from FocusListener
// Inherited from FocusListener
void focusLost(const Event& event) override;
void focusLost(const Event& event) override;
// Inherited from MouseListener
// Inherited from MouseListener
void mousePressed(MouseEvent& mouseEvent) override;
void mousePressed(MouseEvent& mouseEvent) override;
void mouseReleased(MouseEvent& mouseEvent) override;
void mouseReleased(MouseEvent& mouseEvent) override;
void mouseEntered(MouseEvent& mouseEvent) override;
void mouseEntered(MouseEvent& mouseEvent) override;
void mouseExited(MouseEvent& mouseEvent) override;
void mouseExited(MouseEvent& mouseEvent) override;
void mouseDragged(MouseEvent& mouseEvent) override;
void mouseDragged(MouseEvent& mouseEvent) override;
// Inherited from KeyListener
// Inherited from KeyListener
void keyPressed(KeyEvent& keyEvent) override;
void keyPressed(KeyEvent& keyEvent) override;
void keyReleased(KeyEvent& keyEvent) override;
void keyReleased(KeyEvent& keyEvent) override;
protected:
std::string mCaption;
bool mHasMouse;
bool mKeyPressed;
bool mMousePressed;
unsigned int mAlignment;
unsigned int mSpacing;
};
protected:
std::string mCaption;
bool mHasMouse;
bool mKeyPressed;
bool mMousePressed;
unsigned int mAlignment;
unsigned int mSpacing;
};
}
#endif // end GCN_BUTTON_HPP

View file

@ -66,123 +66,124 @@
namespace gcn
{
/**
* An implementation of a check box where a user can select or deselect
* the check box and where the status of the check box is displayed to the user.
* A check box is capable of displaying a caption.
*
* If a check box's state changes an action event will be sent to all action
* listeners of the check box.
*/
class GCN_CORE_DECLSPEC CheckBox :
public Widget,
public MouseListener,
public KeyListener
{
public:
/**
* An implementation of a check box where a user can select or deselect
* the check box and where the status of the check box is displayed to the user.
* A check box is capable of displaying a caption.
*
* If a check box's state changes an action event will be sent to all action
* listeners of the check box.
*/
class GCN_CORE_DECLSPEC CheckBox :
public Widget,
public MouseListener,
public KeyListener
{
public:
/**
* Contructor.
*/
CheckBox();
/**
* Contructor.
*/
CheckBox();
/**
* Constructor. The check box will be automatically resized
* to fit it's caption.
*
* @param caption The caption of the check box.
* @param marked True if the check box is selected, false otherwise.
*/
CheckBox(const std::string &caption, bool selected = false);
/**
* Constructor. The check box will be automatically resized
* to fit it's caption.
*
* @param caption The caption of the check box.
* @param marked True if the check box is selected, false otherwise.
*/
CheckBox(const std::string& caption, bool selected = false);
/**
* Destructor.
*/
virtual ~CheckBox() { }
/**
* Destructor.
*/
virtual ~CheckBox()
= default;
/**
* Checks if the check box is selected.
*
* @return True if the check box is selected, false otherwise.
* @see setSelected
*/
bool isSelected() const;
/**
* Checks if the check box is selected.
*
* @return True if the check box is selected, false otherwise.
* @see setSelected
*/
[[nodiscard]] bool isSelected() const;
/**
* Sets the check box to be selected.
*
* @param selected True if the check box should be set as selected.
* @see isSelected
*/
void setSelected(bool selected);
/**
* Sets the check box to be selected.
*
* @param selected True if the check box should be set as selected.
* @see isSelected
*/
void setSelected(bool selected);
/**
* Gets the caption of the check box.
*
* @return The caption of the check box.
* @see setCaption
*/
const std::string &getCaption() const;
/**
* Gets the caption of the check box.
*
* @return The caption of the check box.
* @see setCaption
*/
[[nodiscard]] const std::string& getCaption() const;
/**
* Sets the caption of the check box. It's advisable to call
* adjustSize after setting of the caption to adjust the
* check box's size to fit the caption.
*
* @param caption The caption of the check box.
* @see getCaption, adjustSize
*/
void setCaption(const std::string& caption);
/**
* Sets the caption of the check box. It's advisable to call
* adjustSize after setting of the caption to adjust the
* check box's size to fit the caption.
*
* @param caption The caption of the check box.
* @see getCaption, adjustSize
*/
void setCaption(const std::string& caption);
/**
* Adjusts the check box's size to fit the caption.
*/
void adjustSize();
/**
* Adjusts the check box'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 of the check box.
*
* @param graphics A Graphics object to draw with.
*/
virtual void drawBox(Graphics *graphics);
protected:
/**
* Draws the box of the check box.
*
* @param graphics A Graphics object to draw with.
*/
virtual void drawBox(Graphics* graphics);
/**
* Toggles the check box between being selected and
* not being selected.
*/
virtual void toggleSelected();
/**
* Toggles the check box between being selected and
* not being selected.
*/
virtual void toggleSelected();
/**
* True if the check box is selected, false otherwise.
*/
bool mSelected{};
/**
* True if the check box is selected, false otherwise.
*/
bool mSelected{};
/**
* Holds the caption of the check box.
*/
std::string mCaption;
};
/**
* Holds the caption of the check box.
*/
std::string mCaption;
};
}
#endif // end GCN_CHECKBOX_HPP

View file

@ -181,7 +181,7 @@ namespace gcn
* Returns the current Dropdown status
*/
[[nodiscard]] virtual bool isDroppedDown() const;
// Inherited from Widget
void draw(Graphics* graphics) override;

View file

@ -410,42 +410,42 @@ namespace gcn
*
* @return the dimension of the up button.
*/
Rectangle getUpButtonDimension();
Rectangle getUpButtonDimension() const;
/**
* Gets the down button dimension.
*
* @return the dimension of the down button.
*/
Rectangle getDownButtonDimension();
Rectangle getDownButtonDimension() const;
/**
* Gets the left button dimension.
*
* @return the dimension of the left button.
*/
Rectangle getLeftButtonDimension();
Rectangle getLeftButtonDimension() const;
/**
* Gets the right button dimension.
*
* @return the dimension of the right button.
*/
Rectangle getRightButtonDimension();
Rectangle getRightButtonDimension() const;
/**
* Gets the vertical scrollbar dimension.
*
* @return the dimension of the vertical scrollbar.
*/
Rectangle getVerticalBarDimension();
Rectangle getVerticalBarDimension() const;
/**
* Gets the horizontal scrollbar dimension.
*
* @return the dimension of the horizontal scrollbar.
*/
Rectangle getHorizontalBarDimension();
Rectangle getHorizontalBarDimension() const;
/**
* Gets the vertical marker dimension.