Changeset View
Changeset View
Standalone View
Standalone View
source/gui/IGUIScrollBar.h
/* Copyright (C) 2015 Wildfire Games. | /* Copyright (C) 2017 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 25 Lines | |||||
*/ | */ | ||||
#ifndef INCLUDED_IGUISCROLLBAR | #ifndef INCLUDED_IGUISCROLLBAR | ||||
#define INCLUDED_IGUISCROLLBAR | #define INCLUDED_IGUISCROLLBAR | ||||
#include "GUI.h" | #include "GUI.h" | ||||
/** | /** | ||||
* The GUI Scroll-bar style. Tells us how scroll-bars look and feel. | * The GUI Scrollbar style. Tells us how scrollbars look and feel. | ||||
* | * | ||||
* A scroll-bar style can choose whether to support horizontal, vertical | * A scrollbar style can choose whether to support horizontal, vertical | ||||
* or both. | * or both. | ||||
* | * | ||||
* @see IGUIScrollBar | * @see IGUIScrollBar | ||||
*/ | */ | ||||
struct SGUIScrollBarStyle | struct SGUIScrollBarStyle | ||||
{ | { | ||||
//-------------------------------------------------------- | //-------------------------------------------------------- | ||||
/** @name General Settings */ | /** @name General Settings */ | ||||
//-------------------------------------------------------- | //-------------------------------------------------------- | ||||
//@{ | //@{ | ||||
/** | /** | ||||
* Width of bar, also both sides of the edge buttons. | * Breadth of bar, from side to side. It is the width of a vertical bar | ||||
* and the height of a horizontal bar. It is also used as the dimensions | |||||
* of both sides of the edge buttons. | |||||
*/ | */ | ||||
float m_Width; | float m_Breadth; | ||||
/** | /** | ||||
* Scrollable with the wheel. | * Scrollable with the wheel. | ||||
*/ | */ | ||||
bool m_ScrollWheel; | bool m_ScrollWheel; | ||||
/** | /** | ||||
* How much (in percent, 0.1f = 10%) to scroll each time | * How much (in percent, 0.1f = 10%) to scroll each time | ||||
Show All 10 Lines | struct SGUIScrollBarStyle | ||||
/** | /** | ||||
* Sometimes there is *a lot* to scroll, but to prevent the scroll "bar" | * Sometimes there is *a lot* to scroll, but to prevent the scroll "bar" | ||||
* from being almost invisible (or ugly), you can set a minimum in pixel | * from being almost invisible (or ugly), you can set a minimum in pixel | ||||
* size. | * size. | ||||
*/ | */ | ||||
float m_MinimumBarSize; | float m_MinimumBarSize; | ||||
/** | /** | ||||
* Sometimes you would like your scroll bar to have a fixed maximum size | * Sometimes you would like your scrollbar to have a fixed maximum size | ||||
* so that the texture does not get too stretched, you can set a maximum | * so that the texture does not get too stretched, you can set a maximum | ||||
* in pixels. | * in pixels. | ||||
*/ | */ | ||||
float m_MaximumBarSize; | float m_MaximumBarSize; | ||||
/** | /** | ||||
* True if you want edge buttons, i.e. buttons that can be pressed in order | * True if you want edge buttons, i.e. buttons that can be pressed in order | ||||
* to scroll. | * to scroll. | ||||
Show All 39 Lines | struct SGUIScrollBarStyle | ||||
CGUISpriteInstance m_SpriteBackHorizontal; | CGUISpriteInstance m_SpriteBackHorizontal; | ||||
CGUISpriteInstance m_SpriteBarHorizontal; | CGUISpriteInstance m_SpriteBarHorizontal; | ||||
//@} | //@} | ||||
}; | }; | ||||
/** | /** | ||||
* The GUI Scroll-bar, used everywhere there is a scroll-bar in the game. | * The GUI Scrollbar, used everywhere there is a scrollbar in the game. | ||||
* | * | ||||
* To include a scroll-bar to an object, inherent the object from | * To include a scrollbar to an object, inherit the object from | ||||
* IGUIScrollBarOwner and call AddScrollBar() to add the scroll-bars. | * IGUIScrollBarOwner and call AddScrollBar() to add the scrollbars. | ||||
* | * | ||||
* It's also important that the scrollbar is located within the parent | * It's also important that the scrollbar is located within the parent | ||||
* object's mouse over area. Otherwise the input won't be sent to the | * object's mouse over area. Otherwise the input won't be sent to the | ||||
* scroll-bar. | * scrollbar. | ||||
* | * | ||||
* The class does not provide all functionality to the scroll-bar, many | * The class does not provide all functionality to the scrollbar, many | ||||
* things the parent of the scroll-bar, must provide. Like a combo-box. | * things the parent of the scrollbar, must provide. Like a combo-box. | ||||
*/ | */ | ||||
class IGUIScrollBar | class IGUIScrollBar | ||||
{ | { | ||||
public: | public: | ||||
IGUIScrollBar(); | IGUIScrollBar(); | ||||
virtual ~IGUIScrollBar(); | virtual ~IGUIScrollBar(); | ||||
public: | public: | ||||
/** | /** | ||||
* Draw the scroll-bar | * Draw the scrollbar | ||||
*/ | */ | ||||
virtual void Draw() = 0; | virtual void Draw() = 0; | ||||
/** | /** | ||||
* If an object that contains a scrollbar has got messages, send | * If an object that contains a scrollbar has got messages, send | ||||
* them to the scroll-bar and it will see if the message regarded | * them to the scrollbar and it will see if the message regarded | ||||
* itself. | * itself. | ||||
* | * | ||||
* @see IGUIObject#HandleMessage() | * @see IGUIObject#HandleMessage() | ||||
*/ | */ | ||||
virtual void HandleMessage(SGUIMessage& Message) = 0; | virtual void HandleMessage(SGUIMessage& Message) = 0; | ||||
/** | /** | ||||
* These are overridden by the *Vertical subclass | |||||
* and are not actually implemented within this class. | |||||
*/ | |||||
virtual void Setup() = 0; | |||||
virtual void Setup(const CRect& content) = 0; | |||||
/** | |||||
* Set m_Pos with g_mouse_x/y input, i.e. when draggin. | * Set m_Pos with g_mouse_x/y input, i.e. when draggin. | ||||
*/ | */ | ||||
virtual void SetPosFromMousePos(const CPos& mouse) = 0; | virtual void SetPosFromMousePos(const CPos& mouse) = 0; | ||||
vladislavbelov: Why not:
```lang=cpp
virtual void Setup() = 0;
virtual void Setup(const CRect content) = 0;
```… | |||||
Not Done Inline ActionsI don't fully understand what the = 0 signifies to the compiler, but it works. s0600204: I don't fully understand what the `= 0` signifies to the compiler, but it works. | |||||
Not Done Inline ActionsThe = 0 makes the method pure virtual. This is a c++ concept. https://stackoverflow.com/questions/1306778/c-virtual-pure-virtual-explained Stan: The = 0 makes the method pure virtual. This is a c++ concept. https://stackoverflow. | |||||
/** | /** | ||||
* Hovering the scroll minus button | * Hovering the scroll minus button | ||||
* | * | ||||
* @param mouse current mouse position | * @param mouse current mouse position | ||||
* @return True if mouse positions are hovering the button | * @return True if mouse positions are hovering the button | ||||
*/ | */ | ||||
virtual bool HoveringButtonMinus(const CPos& UNUSED(mouse)) { return false; } | virtual bool HoveringButtonMinus(const CPos& UNUSED(mouse)) { return false; } | ||||
Show All 16 Lines | public: | ||||
virtual void SetPos(float f) { m_Pos = f; UpdatePosBoundaries(); } | virtual void SetPos(float f) { m_Pos = f; UpdatePosBoundaries(); } | ||||
/** | /** | ||||
* Get the value of m_Pos that corresponds to the bottom of the scrollable region | * Get the value of m_Pos that corresponds to the bottom of the scrollable region | ||||
*/ | */ | ||||
float GetMaxPos() const { return std::max(1.f, m_ScrollRange - m_ScrollSpace); } | float GetMaxPos() const { return std::max(1.f, m_ScrollRange - m_ScrollSpace); } | ||||
/** | /** | ||||
* Get the value of m_Pos that corresponds to the bottom of the scrollable region | * Gets whether a scrollbar is actually needed, based on whether the | ||||
* scroll range is large enough to warrant one. | |||||
*/ | */ | ||||
float IsVisible() const { return GetMaxPos() != 1.f; } | bool IsNeeded() const { return GetMaxPos() != 1.f; } | ||||
Done Inline ActionsIt should return bool. vladislavbelov: It should return `bool`. | |||||
/** | /** | ||||
* Increase scroll one step | * Increase scroll one step | ||||
*/ | */ | ||||
virtual void ScrollPlus() { m_Pos += 30.f; UpdatePosBoundaries(); } | virtual void ScrollPlus() { m_Pos += 30.f; UpdatePosBoundaries(); } | ||||
/** | /** | ||||
* Decrease scroll one step | * Decrease scroll one step | ||||
*/ | */ | ||||
virtual void ScrollMinus() { m_Pos -= 30.f; UpdatePosBoundaries(); } | virtual void ScrollMinus() { m_Pos -= 30.f; UpdatePosBoundaries(); } | ||||
/** | /** | ||||
* Increase scroll three steps | * Increase scroll three steps | ||||
*/ | */ | ||||
virtual void ScrollPlusPlenty() { m_Pos += 90.f; UpdatePosBoundaries(); } | virtual void ScrollPlusPlenty() { m_Pos += 90.f; UpdatePosBoundaries(); } | ||||
/** | /** | ||||
* Decrease scroll three steps | * Decrease scroll three steps | ||||
*/ | */ | ||||
virtual void ScrollMinusPlenty() { m_Pos -= 90.f; UpdatePosBoundaries(); } | virtual void ScrollMinusPlenty() { m_Pos -= 90.f; UpdatePosBoundaries(); } | ||||
/** | /** | ||||
* Set host object, must be done almost at creation of scroll bar. | * Set host object, must be done almost at creation of the scrollbar. | ||||
* @param pOwner Pointer to host object. | * @param pOwner Pointer to host object. | ||||
*/ | */ | ||||
void SetHostObject(IGUIScrollBarOwner* pOwner) { m_pHostObject = pOwner; } | void SetHostObject(IGUIScrollBarOwner* pOwner) { m_pHostObject = pOwner; } | ||||
/** | /** | ||||
* Get GUI pointer | * Get GUI pointer | ||||
* @return CGUI pointer | * @return CGUI pointer | ||||
*/ | */ | ||||
CGUI* GetGUI() const; | CGUI* GetGUI() const; | ||||
/** | /** | ||||
* Set GUI pointer | * Set GUI pointer | ||||
* @param pGUI pointer to CGUI object. | * @param pGUI pointer to CGUI object. | ||||
*/ | */ | ||||
void SetGUI(CGUI* pGUI) { m_pGUI = pGUI; } | void SetGUI(CGUI* pGUI) { m_pGUI = pGUI; } | ||||
/** | /** | ||||
* Set Width | * Set the Breadth of the scrollbar | ||||
* @param width Width | * @param breadth Breadth | ||||
*/ | */ | ||||
void SetWidth(float width) { m_Width = width; } | void SetBreadth(float breadth) { m_Breadth = breadth; } | ||||
/** | /** | ||||
* Set X Position | * Set X Position | ||||
* @param x Position in this axis | * @param x Position in this axis | ||||
*/ | */ | ||||
void SetX(float x) { m_X = x; } | void SetX(float x) { m_X = x; } | ||||
/** | /** | ||||
* Set Y Position | * Set Y Position | ||||
* @param y Position in this axis | * @param y Position in this axis | ||||
*/ | */ | ||||
void SetY(float y) { m_Y = y; } | void SetY(float y) { m_Y = y; } | ||||
/** | /** | ||||
* Set Z Position | * Set Z Position | ||||
* @param z Position in this axis | * @param z Position in this axis | ||||
*/ | */ | ||||
void SetZ(float z) { m_Z = z; } | void SetZ(float z) { m_Z = z; } | ||||
/** | /** | ||||
* Set Length of scroll bar | * Set the length of the scrollbar | ||||
* @param length Length | * @param length Length | ||||
*/ | */ | ||||
void SetLength(float length) { m_Length = length; } | void SetLength(float length) { m_Length = length; } | ||||
/** | /** | ||||
* Set content length | * Set content length | ||||
* @param range Maximum scrollable range | * @param range Maximum scrollable range | ||||
*/ | */ | ||||
void SetScrollRange(float range) { m_ScrollRange = std::max(range, 1.f); SetupBarSize(); UpdatePosBoundaries(); } | void SetScrollRange(float range) { m_ScrollRange = std::max(range, 1.f); SetupBarSize(); UpdatePosBoundaries(); } | ||||
/** | /** | ||||
* Set space that is visible in the scrollable control. | * Set space that is visible in the scrollable control. | ||||
* @param space Visible area in the scrollable control. | * @param space Visible area in the scrollable control. | ||||
*/ | */ | ||||
void SetScrollSpace(float space) { m_ScrollSpace = space; SetupBarSize(); UpdatePosBoundaries(); } | void SetScrollSpace(float space) { m_ScrollSpace = space; SetupBarSize(); UpdatePosBoundaries(); } | ||||
/** | /** | ||||
* Set bar pressed | * Set bar pressed | ||||
* @param b True if bar is pressed | * @param b True if bar is pressed | ||||
*/ | */ | ||||
void SetBarPressed(bool b) { m_BarPressed = b; } | void SetBarPressed(bool b) { m_BarPressed = b; } | ||||
/** | /** | ||||
* Set Scroll bar style string | * Set the Scrollbar style | ||||
* @param style String with scroll bar style reference name | * @param style String consisting of the name of the scrollbar style | ||||
*/ | */ | ||||
void SetScrollBarStyle(const CStr& style) { m_ScrollBarStyle = style; } | void SetScrollBarStyle(const CStr& style) { m_ScrollBarStyle = style; } | ||||
/** | /** | ||||
* Get style used by the scrollbar | * Get style used by the scrollbar | ||||
* @return Scroll bar style struct. | * @return Scrollbar style struct. | ||||
*/ | */ | ||||
const SGUIScrollBarStyle* GetStyle() const; | const SGUIScrollBarStyle* GetStyle() const; | ||||
/** | /** | ||||
* Get the rectangle of the actual BAR. not the whole scroll-bar. | * Get the rectangle of the actual BAR. not the whole scrollbar. | ||||
* @return Rectangle, CRect | * @return Rectangle, CRect | ||||
*/ | */ | ||||
virtual CRect GetBarRect() const = 0; | virtual CRect GetBarRect() const = 0; | ||||
/** | /** | ||||
* Get the rectangle of the outline of the scrollbar, every component of the | * Get the rectangle of the outline of the scrollbar, every component of the | ||||
* scroll-bar should be inside this area. | * scrollbar should be inside this area. | ||||
* @return Rectangle, CRect | * @return Rectangle, CRect | ||||
*/ | */ | ||||
virtual CRect GetOuterRect() const = 0; | virtual CRect GetOuterRect() const = 0; | ||||
protected: | protected: | ||||
/** | /** | ||||
* Sets up bar size | * Sets up bar size | ||||
*/ | */ | ||||
void SetupBarSize(); | void SetupBarSize(); | ||||
/** | /** | ||||
* Call every time m_Pos has been updated. | * Call every time m_Pos has been updated. | ||||
*/ | */ | ||||
void UpdatePosBoundaries(); | void UpdatePosBoundaries(); | ||||
protected: | protected: | ||||
//@} | //@} | ||||
//-------------------------------------------------------- | //-------------------------------------------------------- | ||||
/** @name Settings */ | /** @name Settings */ | ||||
//-------------------------------------------------------- | //-------------------------------------------------------- | ||||
//@{ | //@{ | ||||
/** | /** | ||||
* Width of the scroll bar | * Breadth of the scrollbar | ||||
*/ | */ | ||||
float m_Width; | float m_Breadth; | ||||
/** | /** | ||||
* Absolute X Position | * Absolute X Position | ||||
*/ | */ | ||||
float m_X; | float m_X; | ||||
/** | /** | ||||
* Absolute Y Position | * Absolute Y Position | ||||
Show All 21 Lines | protected: | ||||
float m_ScrollSpace; | float m_ScrollSpace; | ||||
/** | /** | ||||
* Use input from the scroll-wheel? True or false. | * Use input from the scroll-wheel? True or false. | ||||
*/ | */ | ||||
float m_BarSize; | float m_BarSize; | ||||
/** | /** | ||||
* Scroll bar style reference name | * Scrollbar style reference name | ||||
*/ | */ | ||||
CStr m_ScrollBarStyle; | CStr m_ScrollBarStyle; | ||||
/** | /** | ||||
* Pointer to scroll bar style used. | * Pointer to the scrollbar style used. | ||||
*/ | */ | ||||
SGUIScrollBarStyle *m_pStyle; | SGUIScrollBarStyle *m_pStyle; | ||||
/** | /** | ||||
* Host object, prerequisite! | * Host object, prerequisite! | ||||
*/ | */ | ||||
IGUIScrollBarOwner *m_pHostObject; | IGUIScrollBarOwner *m_pHostObject; | ||||
Show All 29 Lines | protected: | ||||
bool m_ButtonMinusHovered, m_ButtonPlusHovered; | bool m_ButtonMinusHovered, m_ButtonPlusHovered; | ||||
/** | /** | ||||
* Scroll buttons pressed | * Scroll buttons pressed | ||||
*/ | */ | ||||
bool m_ButtonMinusPressed, m_ButtonPlusPressed; | bool m_ButtonMinusPressed, m_ButtonPlusPressed; | ||||
/** | /** | ||||
* Position of scroll bar, 0 means scrolled all the way to one side. | * Position of scrollbar, 0 means scrolled all the way to one side. | ||||
* It is measured in pixels, it is up to the host to make it actually | * It is measured in pixels, it is up to the host to make it actually | ||||
* apply in pixels. | * apply in pixels. | ||||
*/ | */ | ||||
float m_Pos; | float m_Pos; | ||||
/** | /** | ||||
* Position from 0.f to 1.f it had when the bar was pressed. | * Position from 0.f to 1.f it had when the bar was pressed. | ||||
*/ | */ | ||||
float m_PosWhenPressed; | float m_PosWhenPressed; | ||||
//@} | //@} | ||||
}; | }; | ||||
#endif // INCLUDED_IGUISCROLLBAR | #endif // INCLUDED_IGUISCROLLBAR |
Wildfire Games · Phabricator
Why not:
Since we always use it.