Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
slider.h
Go to the documentation of this file.
1 /*
2  * Vega Strike
3  * Copyright (C) 2003 Mike Byron
4  *
5  * http://vegastrike.sourceforge.net/
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; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */
21 
22 #ifndef __SLIDER_H__
23 #define __SLIDER_H__
24 
25 #include "gui/groupcontrol.h"
26 
27 //See cpp file for detailed descriptions of classes, functions, etc.
28 
29 //The Slider class controls the setting for a simple integer range.
30 
31 class Slider : public Control
32 {
33 public:
34 //Range represented by the slider.
35  void setMaxMin( int max, int min = 0 );
36 
37 //"Thumb" length. 1.0 = Entire range.
38  void setThumbLength( float len );
39 
40 //Set size of a "page" - used when clicked outside the thumb.
41  void setPageSize( int s )
42  {
43  m_pageSize = s;
44  }
45 
46 //Position.
47 //This is some value between min and max.
48  int position( void )
49  {
50  return m_position;
51  }
52  void setPosition( int pos );
53 
54 //Color of thumb.
55  void setThumbColor( const GFXColor &color, const GFXColor &outline )
56  {
58  m_thumbOutlineColor = outline;
59  }
60  void setThumbColorBasedOnColor( const GFXColor &c );
61 
62 //OVERRIDES
63 
64  virtual void draw( void );
65  virtual void setRect( const Rect &r );
66  virtual void setColor( const GFXColor &c );
67 
68  virtual bool processMouseDown( const InputEvent &event );
69  virtual bool processMouseUp( const InputEvent &event );
70  virtual bool processMouseDrag( const InputEvent &event );
71 
72 //CONSTRUCTION
73 public: Slider( void );
74  virtual ~Slider( void ) {}
75 
76 protected:
77 //INTERNAL IMPLEMENTATION
78 
79 //Mouse states
81  {
82  MOUSE_NONE, //Nothing interesting going on.
83  MOUSE_PAGE_UP, //In the middle of a Page Up click.
84  MOUSE_PAGE_DOWN, //In the middle of a Page Down click.
85  MOUSE_THUMB_DRAG //In the middle of dragging the thumb.
86  };
87 
88 //VARIABLES
89 protected:
90  int m_minValue; //The minimum value in the scrolling range.
91  int m_maxValue; //The maximum value in the scrolling range.
92  float m_thumbLength; //The size of the thumb relative to height/width of slider.
93  float m_originalThumbLength; //Original setting for thumb length.
94  int m_pageSize; //The number of units in a "page".
95  GFXColor m_thumbColor; //Color to paint the thumb.
96  GFXColor m_thumbOutlineColor; //Color of outline for thumb.
97 
98  int m_position; //The current position.
99  bool m_vertical; //True = Vertical, false = horizontal.
100  MouseState m_mouseState; //Which state we are in while the mouse button is pressed.
101  float m_buttonDownMouse; //Location where the mouse button was pressed down.
102  int m_buttonDownPosition; //Position of slider when mouse button was pressed down.
103  Rect m_thumbRect; //Remembered position of the thumb.
104 };
105 
106 #endif //__SLIDER_H__
107