2003-12-27 07:26:03 +01:00
|
|
|
/*
|
|
|
|
A GUI ScrollBar
|
|
|
|
|
|
|
|
--Overview--
|
|
|
|
|
|
|
|
A GUI Scrollbar, this class doesn't present all functionality
|
|
|
|
to the scrollbar, it just controls the drawing and a wrapper
|
|
|
|
for interaction with it.
|
|
|
|
|
|
|
|
--Usage--
|
|
|
|
|
|
|
|
Used in everywhere scrollbars are needed, like in a combobox for instance.
|
|
|
|
|
|
|
|
--More info--
|
|
|
|
|
|
|
|
Check GUI.h
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_IGUISCROLLBAR
|
|
|
|
#define INCLUDED_IGUISCROLLBAR
|
2003-12-27 07:26:03 +01:00
|
|
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
// Includes / Compiler directives
|
|
|
|
//--------------------------------------------------------
|
|
|
|
#include "GUI.h"
|
|
|
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
// Declarations
|
|
|
|
//--------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The GUI Scroll-bar style. Tells us how scroll-bars look and feel.
|
|
|
|
*
|
|
|
|
* A scroll-bar style can choose whether to support horizontal, vertical
|
|
|
|
* or both.
|
|
|
|
*
|
|
|
|
* @see IGUIScrollBar
|
|
|
|
*/
|
|
|
|
struct SGUIScrollBarStyle
|
|
|
|
{
|
|
|
|
//--------------------------------------------------------
|
|
|
|
/** @name General Settings */
|
|
|
|
//--------------------------------------------------------
|
|
|
|
//@{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Width of bar, also both sides of the edge buttons.
|
|
|
|
*/
|
2004-09-03 07:48:47 +02:00
|
|
|
float m_Width;
|
2003-12-27 07:26:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Scrollable with the wheel.
|
|
|
|
*/
|
|
|
|
bool m_ScrollWheel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How much (in percent, 0.1f = 10%) to scroll each time
|
|
|
|
* the wheel is admitted, or the buttons are pressed.
|
|
|
|
*/
|
|
|
|
float m_ScrollSpeed;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not the edge buttons should appear or not. Sometimes
|
|
|
|
* you actually don't want them, like perhaps in a combo box.
|
|
|
|
*/
|
|
|
|
bool m_ScrollButtons;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* size.
|
|
|
|
*/
|
2004-09-03 07:48:47 +02:00
|
|
|
float m_MinimumBarSize;
|
2003-12-27 07:26:03 +01:00
|
|
|
|
|
|
|
//@}
|
|
|
|
//--------------------------------------------------------
|
|
|
|
/** @name Horizontal Sprites */
|
|
|
|
//--------------------------------------------------------
|
|
|
|
//@{
|
|
|
|
|
2004-12-15 22:24:46 +01:00
|
|
|
CGUISpriteInstance m_SpriteButtonTop;
|
|
|
|
CGUISpriteInstance m_SpriteButtonTopPressed;
|
|
|
|
CGUISpriteInstance m_SpriteButtonTopDisabled;
|
|
|
|
CGUISpriteInstance m_SpriteButtonTopOver;
|
2003-12-27 07:26:03 +01:00
|
|
|
|
2004-12-15 22:24:46 +01:00
|
|
|
CGUISpriteInstance m_SpriteButtonBottom;
|
|
|
|
CGUISpriteInstance m_SpriteButtonBottomPressed;
|
|
|
|
CGUISpriteInstance m_SpriteButtonBottomDisabled;
|
|
|
|
CGUISpriteInstance m_SpriteButtonBottomOver;
|
2003-12-27 07:26:03 +01:00
|
|
|
|
2004-12-15 22:24:46 +01:00
|
|
|
CGUISpriteInstance m_SpriteBarVertical;
|
|
|
|
CGUISpriteInstance m_SpriteBarVerticalOver;
|
|
|
|
CGUISpriteInstance m_SpriteBarVerticalPressed;
|
2004-05-29 06:06:50 +02:00
|
|
|
|
2004-12-15 22:24:46 +01:00
|
|
|
CGUISpriteInstance m_SpriteBackVertical;
|
2003-12-27 07:26:03 +01:00
|
|
|
|
|
|
|
//@}
|
|
|
|
//--------------------------------------------------------
|
2004-12-15 22:24:46 +01:00
|
|
|
/** @name Vertical Sprites */
|
2003-12-27 07:26:03 +01:00
|
|
|
//--------------------------------------------------------
|
|
|
|
//@{
|
|
|
|
|
2004-12-15 22:24:46 +01:00
|
|
|
CGUISpriteInstance m_SpriteButtonLeft;
|
|
|
|
CGUISpriteInstance m_SpriteButtonLeftPressed;
|
|
|
|
CGUISpriteInstance m_SpriteButtonLeftDisabled;
|
2003-12-27 07:26:03 +01:00
|
|
|
|
2004-12-15 22:24:46 +01:00
|
|
|
CGUISpriteInstance m_SpriteButtonRight;
|
|
|
|
CGUISpriteInstance m_SpriteButtonRightPressed;
|
|
|
|
CGUISpriteInstance m_SpriteButtonRightDisabled;
|
2003-12-27 07:26:03 +01:00
|
|
|
|
2004-12-15 22:24:46 +01:00
|
|
|
CGUISpriteInstance m_SpriteBackHorizontal;
|
|
|
|
CGUISpriteInstance m_SpriteBarHorizontal;
|
2003-12-27 07:26:03 +01:00
|
|
|
|
|
|
|
//@}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The GUI Scroll-bar, used everywhere there is a scroll-bar in the game.
|
|
|
|
*
|
|
|
|
* To include a scroll-bar to an object, inherent the object from
|
|
|
|
* IGUIScrollBarOwner and call AddScrollBar() to add the scroll-bars.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* scroll-bar.
|
|
|
|
*
|
|
|
|
* The class does not provide all functionality to the scroll-bar, many
|
|
|
|
* things the parent of the scroll-bar, must provide. Like a combo-box.
|
|
|
|
*/
|
|
|
|
class IGUIScrollBar
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
IGUIScrollBar();
|
|
|
|
virtual ~IGUIScrollBar();
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Draw the scroll-bar
|
|
|
|
*/
|
|
|
|
virtual void Draw()=0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If an object that contains a scrollbar has got messages, send
|
|
|
|
* them to the scroll-bar and it will see if the message regarded
|
|
|
|
* itself.
|
|
|
|
*
|
|
|
|
* @param Message SGUIMessage
|
|
|
|
* @return true if messages handled the scroll-bar some. False if
|
|
|
|
* the message should be processed by the object.
|
|
|
|
*/
|
2004-05-29 06:06:50 +02:00
|
|
|
virtual void HandleMessage(const SGUIMessage &Message)=0;
|
2003-12-27 07:26:03 +01:00
|
|
|
|
|
|
|
/**
|
2005-01-23 18:35:36 +01:00
|
|
|
* Set m_Pos with g_mouse_x/y input, i.e. when draggin.
|
2003-12-27 07:26:03 +01:00
|
|
|
*/
|
2004-05-29 06:06:50 +02:00
|
|
|
virtual void SetPosFromMousePos(const CPos &mouse)=0;
|
2003-12-27 07:26:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hovering the scroll minus button
|
|
|
|
*
|
|
|
|
* @param m_x mouse x
|
|
|
|
* @param m_y mouse y
|
|
|
|
* @return True if mouse positions are hovering the button
|
|
|
|
*/
|
2005-08-09 17:55:44 +02:00
|
|
|
virtual bool HoveringButtonMinus(const CPos& UNUSED(mouse)) { return false; }
|
2003-12-27 07:26:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hovering the scroll plus button
|
|
|
|
*
|
|
|
|
* @param m_x mouse x
|
|
|
|
* @param m_y mouse y
|
|
|
|
* @return True if mouse positions are hovering the button
|
|
|
|
*/
|
2005-08-09 17:55:44 +02:00
|
|
|
virtual bool HoveringButtonPlus(const CPos& UNUSED(mouse)) { return false; }
|
2004-05-29 06:06:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get scroll-position
|
|
|
|
*/
|
2004-09-03 07:48:47 +02:00
|
|
|
float GetPos() const { return m_Pos; }
|
2003-12-27 07:26:03 +01:00
|
|
|
|
2005-02-05 08:25:16 +01:00
|
|
|
/**
|
|
|
|
* Set scroll-position by hand
|
|
|
|
*/
|
|
|
|
virtual void SetPos(const float &f) { m_Pos = f; UpdatePosBoundaries(); }
|
|
|
|
|
2003-12-27 07:26:03 +01:00
|
|
|
/**
|
|
|
|
* Scroll towards 1.0 one step
|
|
|
|
*/
|
2004-09-03 07:48:47 +02:00
|
|
|
virtual void ScrollPlus() { m_Pos += 30.f; UpdatePosBoundaries(); }
|
2003-12-27 07:26:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Scroll towards 0.0 one step
|
|
|
|
*/
|
2004-09-03 07:48:47 +02:00
|
|
|
virtual void ScrollMinus() { m_Pos -= 30.f; UpdatePosBoundaries(); }
|
2004-05-29 06:06:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Scroll towards 1.0 one step
|
|
|
|
*/
|
2004-09-03 07:48:47 +02:00
|
|
|
virtual void ScrollPlusPlenty() { m_Pos += 90.f; UpdatePosBoundaries(); }
|
2004-05-29 06:06:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Scroll towards 0.0 one step
|
|
|
|
*/
|
2004-09-03 07:48:47 +02:00
|
|
|
virtual void ScrollMinusPlenty() { m_Pos -= 90.f; UpdatePosBoundaries(); }
|
2003-12-27 07:26:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set host object, must be done almost at creation of scroll bar.
|
|
|
|
* @param pOwner Pointer to host object.
|
|
|
|
*/
|
|
|
|
void SetHostObject(IGUIScrollBarOwner * pOwner) { m_pHostObject = pOwner; }
|
|
|
|
|
2004-05-29 06:06:50 +02:00
|
|
|
/**
|
|
|
|
* Get GUI pointer
|
|
|
|
* @return CGUI pointer
|
|
|
|
*/
|
|
|
|
CGUI *GetGUI() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set GUI pointer
|
|
|
|
* @param pGUI pointer to CGUI object.
|
|
|
|
*/
|
|
|
|
void SetGUI(CGUI *pGUI) { m_pGUI = pGUI; }
|
|
|
|
|
2003-12-27 07:26:03 +01:00
|
|
|
/**
|
|
|
|
* Set Width
|
|
|
|
* @param width Width
|
|
|
|
*/
|
2004-09-03 07:48:47 +02:00
|
|
|
void SetWidth(const float &width) { m_Width = width; }
|
2003-12-27 07:26:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set X Position
|
|
|
|
* @param x Position in this axis
|
|
|
|
*/
|
2004-09-03 07:48:47 +02:00
|
|
|
void SetX(const float &x) { m_X = x; }
|
2003-12-27 07:26:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set Y Position
|
|
|
|
* @param y Position in this axis
|
|
|
|
*/
|
2004-09-03 07:48:47 +02:00
|
|
|
void SetY(const float &y) { m_Y = y; }
|
2003-12-27 07:26:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set Z Position
|
|
|
|
* @param z Position in this axis
|
|
|
|
*/
|
2004-05-29 06:06:50 +02:00
|
|
|
void SetZ(const float &z) { m_Z = z; }
|
2003-12-27 07:26:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set Length of scroll bar
|
|
|
|
* @param length Length
|
|
|
|
*/
|
2004-09-03 07:48:47 +02:00
|
|
|
void SetLength(const float &length) { m_Length = length; }
|
2004-05-29 06:06:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set content length
|
|
|
|
* @param range Maximum scrollable range
|
|
|
|
*/
|
2007-05-09 23:01:11 +02:00
|
|
|
void SetScrollRange(const float &range) { m_ScrollRange = std::max(range, 1.f); SetupBarSize(); UpdatePosBoundaries(); }
|
2004-05-29 06:06:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set space that is visible in the scrollable control.
|
|
|
|
* @param space Visible area in the scrollable control.
|
|
|
|
*/
|
2005-07-24 00:27:55 +02:00
|
|
|
void SetScrollSpace(const float &space) { m_ScrollSpace = space; SetupBarSize(); UpdatePosBoundaries(); }
|
2003-12-27 07:26:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set bar pressed
|
|
|
|
* @param pressed True if bar is pressed
|
|
|
|
*/
|
|
|
|
void SetBarPressed(const bool &b) { m_BarPressed = b; }
|
|
|
|
|
2004-05-29 06:06:50 +02:00
|
|
|
/**
|
|
|
|
* Set use edge buttons
|
|
|
|
* @param b True if edge buttons should be used
|
|
|
|
*/
|
|
|
|
void SetUseEdgeButtons(const bool &b) { m_UseEdgeButtons = b; }
|
|
|
|
|
2003-12-27 07:26:03 +01:00
|
|
|
/**
|
|
|
|
* Set Scroll bar style string
|
|
|
|
* @param style String with scroll bar style reference name
|
|
|
|
*/
|
2004-06-18 16:07:06 +02:00
|
|
|
void SetScrollBarStyle(const CStr& style) { m_ScrollBarStyle = style; }
|
2003-12-27 07:26:03 +01:00
|
|
|
|
2004-05-29 06:06:50 +02:00
|
|
|
/**
|
|
|
|
* Get style used by the scrollbar
|
|
|
|
* @return Scroll bar style struct.
|
|
|
|
*/
|
2004-12-15 22:24:46 +01:00
|
|
|
SGUIScrollBarStyle * GetStyle() const;
|
2004-05-29 06:06:50 +02:00
|
|
|
|
2003-12-27 07:26:03 +01:00
|
|
|
/**
|
|
|
|
* Get the rectangle of the actual BAR. not the whole scroll-bar.
|
2004-05-29 06:06:50 +02:00
|
|
|
* @return Rectangle, CRect
|
2003-12-27 07:26:03 +01:00
|
|
|
*/
|
|
|
|
virtual CRect GetBarRect() const = 0;
|
|
|
|
|
|
|
|
/**
|
2004-05-29 06:06:50 +02:00
|
|
|
* Get the rectangle of the outline of the scrollbar, every component of the
|
|
|
|
* scroll-bar should be inside this area.
|
|
|
|
* @return Rectangle, CRect
|
2003-12-27 07:26:03 +01:00
|
|
|
*/
|
2004-05-29 06:06:50 +02:00
|
|
|
virtual CRect GetOuterRect() const = 0;
|
2003-12-27 07:26:03 +01:00
|
|
|
|
2005-04-07 11:13:10 +02:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Sets up bar size
|
|
|
|
*/
|
|
|
|
void SetupBarSize();
|
|
|
|
|
2003-12-27 07:26:03 +01:00
|
|
|
/**
|
|
|
|
* Call every time m_Pos has been updated.
|
|
|
|
*/
|
|
|
|
void UpdatePosBoundaries();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
//@}
|
|
|
|
//--------------------------------------------------------
|
|
|
|
/** @name Settings */
|
|
|
|
//--------------------------------------------------------
|
|
|
|
//@{
|
|
|
|
|
2004-05-29 06:06:50 +02:00
|
|
|
/**
|
|
|
|
* True if you want edge buttons, i.e. buttons that can be pressed in order
|
|
|
|
* to scroll.
|
|
|
|
*/
|
|
|
|
bool m_UseEdgeButtons;
|
|
|
|
|
2003-12-27 07:26:03 +01:00
|
|
|
/**
|
|
|
|
* Width of the scroll bar
|
|
|
|
*/
|
2004-09-03 07:48:47 +02:00
|
|
|
float m_Width;
|
2003-12-27 07:26:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Absolute X Position
|
|
|
|
*/
|
2004-09-03 07:48:47 +02:00
|
|
|
float m_X;
|
2003-12-27 07:26:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Absolute Y Position
|
|
|
|
*/
|
2004-09-03 07:48:47 +02:00
|
|
|
float m_Y;
|
2003-12-27 07:26:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Absolute Z Position
|
|
|
|
*/
|
|
|
|
float m_Z;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Total length of scrollbar, including edge buttons.
|
|
|
|
*/
|
2004-09-03 07:48:47 +02:00
|
|
|
float m_Length;
|
2003-12-27 07:26:03 +01:00
|
|
|
|
2004-05-29 06:06:50 +02:00
|
|
|
/**
|
|
|
|
* Content that can be scrolled, in pixels
|
|
|
|
*/
|
2004-09-03 07:48:47 +02:00
|
|
|
float m_ScrollRange;
|
2004-05-29 06:06:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Content that can be viewed at a time, in pixels
|
|
|
|
*/
|
2004-09-03 07:48:47 +02:00
|
|
|
float m_ScrollSpace;
|
2004-05-29 06:06:50 +02:00
|
|
|
|
2003-12-27 07:26:03 +01:00
|
|
|
/**
|
|
|
|
* Use input from the scroll-wheel? True or false.
|
|
|
|
*/
|
|
|
|
float m_BarSize;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scroll bar style reference name
|
|
|
|
*/
|
|
|
|
CStr m_ScrollBarStyle;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pointer to scroll bar style used.
|
|
|
|
*/
|
|
|
|
SGUIScrollBarStyle *m_pStyle;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Host object, prerequisite!
|
|
|
|
*/
|
|
|
|
IGUIScrollBarOwner *m_pHostObject;
|
|
|
|
|
2004-05-29 06:06:50 +02:00
|
|
|
/**
|
|
|
|
* Reference to CGUI object, these cannot work stand-alone
|
|
|
|
*/
|
|
|
|
CGUI *m_pGUI;
|
|
|
|
|
2003-12-27 07:26:03 +01:00
|
|
|
/**
|
|
|
|
* Mouse position when bar was pressed
|
|
|
|
*/
|
2004-05-29 06:06:50 +02:00
|
|
|
CPos m_BarPressedAtPos;
|
2003-12-27 07:26:03 +01:00
|
|
|
|
|
|
|
//@}
|
|
|
|
//--------------------------------------------------------
|
|
|
|
/** @name States */
|
|
|
|
//--------------------------------------------------------
|
|
|
|
//@{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the bar is currently being pressed and dragged.
|
|
|
|
*/
|
|
|
|
bool m_BarPressed;
|
|
|
|
|
|
|
|
/**
|
2004-05-29 06:06:50 +02:00
|
|
|
* Bar being hovered or not
|
|
|
|
*/
|
|
|
|
bool m_BarHovered;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scroll buttons hovered
|
|
|
|
*/
|
|
|
|
bool m_ButtonMinusHovered, m_ButtonPlusHovered;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scroll buttons pressed
|
|
|
|
*/
|
|
|
|
bool m_ButtonMinusPressed, m_ButtonPlusPressed;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Position of scroll bar, 0 means scrolled all the way to one side.
|
|
|
|
* It is meassured in pixels, it is up to the host to make it actually
|
|
|
|
* apply in pixels.
|
2003-12-27 07:26:03 +01:00
|
|
|
*/
|
2004-09-03 07:48:47 +02:00
|
|
|
float m_Pos;
|
2003-12-27 07:26:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Position from 0.f to 1.f it had when the bar was pressed.
|
|
|
|
*/
|
|
|
|
float m_PosWhenPressed;
|
|
|
|
|
|
|
|
//@}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|