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
newbutton.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 __BUTTON_H__
23 #define __BUTTON_H__
24 
25 #include "control.h"
26 #include "painttext.h"
27 
28 //See cpp file for detailed descriptions of classes, functions, etc.
29 
30 //The NewButton class supports the normal button control. It can be
31 //pressed by the mouse, and, by default, send a command out when
32 //it is pressed.
33 
34 class NewButton : public Control
35 {
36 public:
37 //"Look" of the button. Useful in drawing.
38  enum
39  {
40  NORMAL_STATE=0, //Normal state of a button.
41  DOWN_STATE, //Pressed down.
42  HIGHLIGHT_STATE, //Mouse is over button, but not pressed.
43  DISABLED_STATE, //Pressing the button does nothing.
44  FINAL_BUTTON_STATE=DISABLED_STATE //Last value *we've* defined.
45  };
46 
47 //Set the button state. If the state changes, it will redraw.
48 //The button state is an "int" so that derived classes can add new
49 //values. Use pre-existing enum values if possible.
50  virtual int drawingState( void );
51  virtual void setDrawingState( int newState );
52 
53 //The command ID generated by a button when it is pressed.
54  virtual EventCommandId command( void )
55  {
56  return m_commandId;
57  }
58  virtual void setCommand( EventCommandId id )
59  {
60  m_commandId = id;
61  }
62 
63 //Label that appears on the button.
64  virtual std::string label( void )
65  {
66  return m_label;
67  }
68  virtual void setLabel( std::string l )
69  {
70  m_label = l;
71  }
72 
73 //Background color when mouse is over button.
74  virtual GFXColor highlightColor( void )
75  {
76  return m_highlightColor;
77  }
78  virtual void setHighlightColor( const GFXColor &c )
79  {
81  }
82 
83 //Text color when mouse is over button.
84  virtual GFXColor textHighlightColor( void )
85  {
86  return m_textHighlightColor;
87  }
88  virtual void setTextHighlightColor( const GFXColor &c )
89  {
91  }
92 
93 //Background color when button is pressed down.
94  virtual GFXColor downColor( void )
95  {
96  return m_downColor;
97  }
98  virtual void setDownColor( const GFXColor &c )
99  {
100  m_downColor = c;
101  }
102 
103 //Text color when button is pressed down.
104  virtual GFXColor downTextColor( void )
105  {
106  return m_downTextColor;
107  }
108  virtual void setDownTextColor( const GFXColor &c )
109  {
110  m_downTextColor = c;
111  }
112 
113 //Width of shadow lines in pixels.
114  virtual float shadowWidth( void )
115  {
116  return m_shadowWidth;
117  }
118  virtual void setShadowWidth( float width )
119  {
121  }
122 
123 //Variable-color border cycle time in seconds. Substitutes for shadows.
124  virtual float variableBorderCycleTime( void )
125  {
127  }
128  virtual void setVariableBorderCycleTime( float cycleTime )
129  {
130  m_variableBorderCycleTime = cycleTime;
131  m_cycleStepCount = (-1);
132  }
133 
134 //Set the border color of the button. This overrides the shadow color.
135  virtual GFXColor borderColor( void )
136  {
137  return m_borderColor;
138  }
139  virtual void setBorderColor( const GFXColor &c )
140  {
141  m_borderColor = c;
142  }
143 
144 //Border color at end of cycle. Only used with variable border.
145  virtual GFXColor endBorderColor( void )
146  {
147  return m_endBorderColor;
148  }
149  virtual void setEndBorderColor( const GFXColor &c )
150  {
152  }
153 
154 //Draw the button.
155  virtual void draw( void );
156 
157 //OVERRIDES
158  virtual bool processMouseDown( const InputEvent &event );
159  virtual bool processMouseUp( const InputEvent &event );
160 
161 //CONSTRUCTION
162 public: NewButton( void );
163  virtual ~NewButton( void ) {}
164 
165 protected:
166 //INTERNAL IMPLEMENTATION
167 
168 //This function is called when the button is pressed.
169 //Override to change the behavior.
170  virtual void sendButtonCommand( void );
171 
172 //Draw the cycled border. Checks time to change colors, etc.
173  virtual void drawCycleBorder( float lineWidth );
174 
175 //VARIABLES
176 protected:
177  int m_drawingState; //How the button looks.
178  EventCommandId m_commandId; //The command to send when pressed.
179  std::string m_label; //The text on this button.
180  bool m_leftPressed; //True = Mouse-down and no mouse-up yet.
181  GFXColor m_highlightColor; //Highlighted button color.
182  GFXColor m_textHighlightColor; //Text color when mouse is highlighted.
183  GFXColor m_downColor; //Background color when button is pressed down.
184  GFXColor m_downTextColor; //Text color when button is pressed down.
185  float m_shadowWidth; //Line width of shadows in pixels.
186  float m_variableBorderCycleTime; //Variable border cycle time (in seconds).
187  GFXColor m_borderColor; //Color of border.
188  GFXColor m_endBorderColor; //End color of border if cycling.
189  PaintText m_paintText; //Object that displays label.
190 
191 //State for painting a cycling border.
192  GFXColor m_currentCycleColor; //The current color of the cycling border.
193  int m_currentCycle; //The "step" in the cycle we are currently painting.
194  int m_cycleStepCount; //Number of steps from one color to the other (1/2 cycle).
195  int m_cycleDirection; //1 or -1 depending on which color we are heading toward.
196  GFXColor m_cycleColorDelta; //Change in each color for one cycle.
197  double m_lastStepTime; //Last time we changed steps.
198 };
199 
200 #endif //__BUTTON_H__
201