My Project
GUIScrollBar.h
1 #pragma once
2 #include "GUIBase.h"
3 
4 // Minimum scroll bar thumb size
5 #define SCROLLBAR_MINTHUMBSIZE 8
6 
7 namespace ParaEngine
8 {
9  enum GUI_SCROLL_TYPE{
10  NONE = 0,
11  HSCROLL = 1,
12  VSCROLL = 2
13  };
14 
21  class CGUIScrollBar : public CGUIBase
22  {
23  public:
24  CGUIScrollBar();
25  virtual ~CGUIScrollBar();
26 
27  //virtual bool MsgProc(CGUIEvent *event=NULL);
28  virtual bool MsgProc(MSG *event);
29 
30  virtual HRESULT Render(GUIState* pGUIState, float fElapsedTime);
31  virtual void UpdateRects();
32  virtual void InitObject(const char * strObjectName, const char * alignment, int x, int y, int width, int height);
33  virtual bool OnMouseLeave();
34  virtual bool OnChange(const char* code = NULL);
35 
41  void SetTrackRange(int nStart, int nEnd);
42 
47  int GetTrackPos() { return m_nPosition; }
48 
53  int GetTrackStart(){ return m_nStart; };
58  int GetTrackEnd(){ return m_nEnd; };
59 
61  void SetValue(int nValue) { SetTrackPos(nValue); };
62 
64  int GetValue() const { return m_nPosition; };
65 
70  void SetTrackPos(int nPosition) { m_nPosition = nPosition; Cap(); UpdateThumbRect(); }
71 
77  int GetPageSize() { return m_nPageSize; }
78 
84  void SetPageSize(int nPageSize) { m_nPageSize = nPageSize; Cap(); UpdateThumbRect(); }
85 
87  void SetStep(int nDelta){ m_nDelta = nDelta; }
88 
90  int GetStep(){ return m_nDelta; }
91 
96  void Scroll(int nDelta);
97 
102  void ShowItem(int nIndex);
103 
104  void SetFixedThumb(bool bFixed);
105  bool GetFixedThumb()const{ return m_bFixedThumb; }
106 
107  void SetThumbSize(int size){ m_nThumbSize = SCROLLBAR_MINTHUMBSIZE > size ? SCROLLBAR_MINTHUMBSIZE : size; m_bNeedUpdate = true; }
108  int GetThumbSize()const { return m_nThumbSize; }
109 
110  void SetLinkedObject(CGUIBase* obj){ m_Linked = obj; }
111 
112  void SetScrollbarWidth(int width);
113  int GetScrollbarWidth()const;
114  // virtual void SetSize(int width, int height );
115  // virtual void SetWidth(int width );
116  // virtual void SetHeight(int height );
117 
118  static void StaticInit();
119  virtual void Clone(IObject* pobj)const;
120  virtual IObject *Clone()const;
121  virtual const IType* GetType()const{ return m_type; }
122 
123  protected:
124  static const IType* m_type;
125  // ARROWSTATE indicates the state of the arrow buttons.
126  // CLEAR No arrow is down.
127  // CLICKED_UP Up arrow is clicked.
128  // CLICKED_DOWN Down arrow is clicked.
129  // HELD_UP Up arrow is held down for sustained period.
130  // HELD_DOWN Down arrow is held down for sustained period.
131  enum ARROWSTATE { CLEAR, CLICKED_UP, CLICKED_DOWN, HELD_UP, HELD_DOWN, CLICKED, HELD };
132 
134  void UpdateThumbRect();
135 
138 
139  void Cap(); // Clips position at boundaries. Ensures it stays within legal range.
140 
141  bool m_bShowThumb;
142  int m_nPosition; // Position of the first displayed item
143  int m_nOldPosition;
144  int m_nPageSize; // How many items are displayable in one page
145  int m_nStart; // First item
146  int m_nEnd; // The index after the last item
147  int m_nDelta; // How many items are scrolled in one click
148  // POINT m_LastMouse;// Last mouse position
149  ARROWSTATE m_Arrow; // State of the arrows
150  DWORD m_dArrowTS; // Timestamp of last arrow event.
151  int m_ScrollType;
152  bool m_bFixedThumb;//if the thumb has fixed size, default is true
153  CGUIBase* m_Linked;
154  int m_nThumbSize;//thumb size if m_bFixedThumb=true, default is 20;
155  };
156 }
void Scroll(int nDelta)
Scroll the scroll bar.
Definition: GUIScrollBar.cpp:451
void UpdateThumbRect()
update thumb rect
Definition: GUIScrollBar.cpp:396
IType is for type information and validating It contains type information of an object.
Definition: Type.h:75
int GetPageSize()
Get the page size of the scroll bar Page size is the size of how many items a page contains...
Definition: GUIScrollBar.h:77
int GetValue() const
track position
Definition: GUIScrollBar.h:64
mostly associated with a CGUIContainer m_objResource->m_objArtwork->DrawingRects[0]: track rectangle;...
Definition: GUIScrollBar.h:21
Definition: EventBinding.h:22
void UpdateThumbRectNineElement()
update nine element thumb rects (4, 4+8) according to original calcuated thumb rect at index 3 ...
Definition: GUIContainer.cpp:1653
void SetPageSize(int nPageSize)
Set the page size of the scroll bar Page size is the size of how many items a page contains...
Definition: GUIScrollBar.h:84
void SetTrackPos(int nPosition)
Set the track position of the scroll bar.
Definition: GUIScrollBar.h:70
different physics engine has different winding order.
Definition: EventBinding.h:32
void SetTrackRange(int nStart, int nEnd)
Set the track range of the scroll bar.
Definition: GUIScrollBar.cpp:892
base object for all 2D GUI objects (1) 2D GUI object are not tested against view frustum, instead it is controlled by visibility tag automatically or through user input.
Definition: GUIBase.h:54
base class for object, such as CBaseObject, IAttributeObject, GUI object.
Definition: PERef.h:287
int GetStep()
how many pixels to scroll each step
Definition: GUIScrollBar.h:90
void SetStep(int nDelta)
how many pixels to scroll each step
Definition: GUIScrollBar.h:87
It's used as parameter to Render method of each GUI object.
Definition: GUIState.h:16
void ShowItem(int nIndex)
Ensure that an item is displayed, scroll if necessary.
Definition: GUIScrollBar.cpp:477
Definition: inftrees.h:24
virtual bool MsgProc(MSG *event)
the procedure that handles all the events.
Definition: GUIScrollBar.cpp:505
void SetValue(int nValue)
track position
Definition: GUIScrollBar.h:61
int GetTrackStart()
Get the track start value of the scroll bar.
Definition: GUIScrollBar.h:53
virtual IObject * Clone() const
Clone the object's contains and return a pointer to the newly created object.
Definition: GUIScrollBar.cpp:76
int GetTrackEnd()
Get the track end value of the scroll bar.
Definition: GUIScrollBar.h:58
int GetTrackPos()
Get the track position of the scroll bar.
Definition: GUIScrollBar.h:47