Planeshift
pawscrollbar.h
Go to the documentation of this file.
1 /*
2  * pawscrollbar.h - Author: Andrew Craig
3  *
4  * Copyright (C) 2003 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 // pawscrollbar.h: interface for the pawscrollbar class.
20 //
22 
23 #ifndef PAWS_SCROLLBAR_HEADER
24 #define PAWS_SCROLLBAR_HEADER
25 
26 #include "pawswidget.h"
27 
28 struct iVirtualClock;
29 class pawsButton;
30 
35 class pawsThumb : public pawsWidget
36 {
37 public:
39  {
40  factory = "pawsThumb";
41  };
42  pawsThumb(const pawsThumb &origin): pawsWidget(origin)
43  {
44 
45  }
46  bool OnMouseUp(int button, int modifiers, int x, int y)
47  {
48  if(parent)
49  return parent->OnMouseUp(button, modifiers, x, y);
50  else
51  return false;
52  }
53 
54  void OnLostFocus()
55  {
56  OnMouseUp(0,0,0,0);
58  }
59 
60 };
64 class pawsScrollBar : public pawsWidget
65 {
66 public:
67  pawsScrollBar();
68  pawsScrollBar(const pawsScrollBar &origin);
69  virtual ~pawsScrollBar();
70 
71  virtual bool Setup(iDocumentNode* node);
72  virtual bool PostSetup();
73  virtual bool OnMouseDown(int button, int modifiers, int x, int y);
74  virtual bool OnMouseUp(int button, int modifiers, int x, int y);
75 
76  /* This is used to register child button presses.
77  * In the scroll bar case it will catch the up and down arrows.
78  * @param button The mouse button that was pressed.
79  * @param widget The child Widget that was pressed.
80  * @return true if the scroll bar handled the button.
81  */
82  virtual bool OnButtonPressed(int button, int keyModifier, pawsWidget* widget);
83 
84  virtual bool OnButtonReleased(int button, int keyModifier, pawsWidget* widget);
85 
89  virtual void SetMaxValue(float value);
90  virtual float GetMaxValue()
91  {
92  return maxValue;
93  }
94 
98  virtual void SetMinValue(float value);
99  virtual float GetMinValue()
100  {
101  return minValue;
102  }
103 
107  virtual void EnableValueLimit(bool limited);
108 
116  virtual void SetCurrentValue(float value, bool triggerEvent = true, bool publish=true);
117 
121  virtual float GetCurrentValue();
122 
126  virtual void SetTickValue(float tick);
127 
132  virtual float GetTickValue()
133  {
134  return tickValue;
135  }
136 
137  virtual void Draw();
138 
139  virtual void SetHorizontal(bool value);
140 
144  virtual void SetReversed(bool reversed)
145  {
146  this->reversed = reversed;
147  }
148 
149  // Scroll bars should not be focused.
150  virtual bool OnGainFocus(bool /*notifyParent*/ = true)
151  {
152  return false;
153  }
154 
155  virtual void OnResize();
156 
157  virtual bool OnMouseExit();
158 
159  virtual void OnUpdateData(const char* dataname,PAWSData &data);
160 
164  bool ScrollUp();
168  bool ScrollDown();
169 protected:
171  void SetThumbLayout();
172 
174  void MoveThumbToMouse();
175 
177  void LimitCurrentValue();
178 
179  int GetScrollBarSize();
180 
181  int GetThumbScaleLength();
182 
184  void SetButtonLayout();
185 
186  void SetThumbVisibility();
187 
189  float maxValue;
190  float minValue;
191 
193  float tickValue;
194 
195  csRef<iVirtualClock> clock;
196 
198  csTicks scrollTicks;
199  bool mouseDown;
200  bool reversed;
201 
205 
206  pawsButton* upButton, * downButton;
207 
209  bool mouseIsDraggingThumb; // is the user currently dragging the thumb with mouse ?
210  int thumbDragPoint; // coordinate of the point where mouse button was pressed down
211  // when the user began drag'n'drop of thumb (relative to thumb position)
212 
213  csString upGrey;
214  csString upUnpressed;
215  csString upPressed;
218  int upWidth;
219  int upHeight;
220 
221  csString downGrey;
222  csString downUnpressed;
223  csString downPressed;
228 
229  csString thumbStopped;
230  csString thumbMoving;
231 
233  bool limited;
234 };
235 
236 //--------------------------------------------------------------------------------
238 
239 
242 #endif
The main base widget that all other widgets should inherit from.
Definition: pawswidget.h:116
csString downPressed
Definition: pawscrollbar.h:223
virtual bool OnButtonReleased(int button, int keyModifier, pawsWidget *widget)
Called whenever a button is released.
Definition: pawswidget.h:1205
pawsWidget * lastWidget
Definition: pawscrollbar.h:204
float tickValue
This is how much value should change on a scroll.
Definition: pawscrollbar.h:193
pawsButton * upButton
Definition: pawscrollbar.h:206
pawsThumb(const pawsThumb &origin)
Definition: pawscrollbar.h:42
virtual bool OnGainFocus(bool=true)
Changes hasFocus to TRUE and reports status to parent.
Definition: pawscrollbar.h:150
virtual bool PostSetup()
This is called after the widget and all of it&#39;s children have been created.
Definition: pawswidget.h:709
csString thumbStopped
Definition: pawscrollbar.h:229
csString upUnpressed
Definition: pawscrollbar.h:214
void OnLostFocus()
Sets hasFocus false and notifys parent.
Definition: pawscrollbar.h:54
pawsWidget * parent
This widget&#39;s parent.
Definition: pawswidget.h:130
csString factory
factory name
Definition: pawswidget.h:124
virtual bool OnMouseUp(int button, int modifiers, int x, int y)
Manage mouse up event.
virtual float GetTickValue()
Returns the tick value of this scroll bar.
Definition: pawscrollbar.h:132
float currentValue
Definition: pawscrollbar.h:188
CREATE_PAWS_FACTORY(pawsThumb)
csString downGrey
Definition: pawscrollbar.h:221
csString downUnpressed
Definition: pawscrollbar.h:222
csString upGrey
Definition: pawscrollbar.h:213
bool mouseIsDraggingThumb
Definition: pawscrollbar.h:209
virtual void OnResize()
Sets the new position of the close button.
virtual void Draw()
Draws the widget and all of it&#39;s children.
A simple scroll bar widget.
Definition: pawscrollbar.h:64
csString thumbMoving
Definition: pawscrollbar.h:230
csString upPressed
Definition: pawscrollbar.h:215
virtual float GetMaxValue()
Definition: pawscrollbar.h:90
pawsWidget * thumb
Definition: pawscrollbar.h:208
virtual float GetMinValue()
Definition: pawscrollbar.h:99
csTicks scrollTicks
Keep track of ticks for scrolling.
Definition: pawscrollbar.h:198
csRef< iVirtualClock > clock
Definition: pawscrollbar.h:195
virtual bool OnMouseDown(int button, int modifiers, int x, int y)
Manage mouse down event to test for and apply window changes.
A simple button widget.
Definition: pawsbutton.h:43
bool OnMouseUp(int button, int modifiers, int x, int y)
Manage mouse up event.
Definition: pawscrollbar.h:46
virtual bool OnMouseExit()
Called whenever the mouse leaves this widget.
virtual bool OnButtonPressed(int button, int keyModifier, pawsWidget *widget)
Called whenever a button is pressed.
Definition: pawswidget.h:1190
virtual void OnLostFocus()
Sets hasFocus false and notifys parent.
Definition: pawswidget.h:834
virtual void OnUpdateData(const char *, PAWSData &)
Definition: pawswidget.h:1837
virtual void SetReversed(bool reversed)
Sets if scrollbar should return reversed scroll value: left/top=maxValue, right/bottom=minValue.
Definition: pawscrollbar.h:144
virtual bool Setup(iDocumentNode *)
Setup this widget.
Definition: pawswidget.h:697