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 Class Reference

#include <newbutton.h>

Inheritance diagram for NewButton:
Control EventResponder ScrollerButton

Public Types

enum  {
  NORMAL_STATE =0, DOWN_STATE, HIGHLIGHT_STATE, DISABLED_STATE,
  FINAL_BUTTON_STATE =DISABLED_STATE
}
 

Public Member Functions

virtual int drawingState (void)
 
virtual void setDrawingState (int newState)
 
virtual EventCommandId command (void)
 
virtual void setCommand (EventCommandId id)
 
virtual std::string label (void)
 
virtual void setLabel (std::string l)
 
virtual GFXColor highlightColor (void)
 
virtual void setHighlightColor (const GFXColor &c)
 
virtual GFXColor textHighlightColor (void)
 
virtual void setTextHighlightColor (const GFXColor &c)
 
virtual GFXColor downColor (void)
 
virtual void setDownColor (const GFXColor &c)
 
virtual GFXColor downTextColor (void)
 
virtual void setDownTextColor (const GFXColor &c)
 
virtual float shadowWidth (void)
 
virtual void setShadowWidth (float width)
 
virtual float variableBorderCycleTime (void)
 
virtual void setVariableBorderCycleTime (float cycleTime)
 
virtual GFXColor borderColor (void)
 
virtual void setBorderColor (const GFXColor &c)
 
virtual GFXColor endBorderColor (void)
 
virtual void setEndBorderColor (const GFXColor &c)
 
virtual void draw (void)
 
virtual bool processMouseDown (const InputEvent &event)
 
virtual bool processMouseUp (const InputEvent &event)
 
 NewButton (void)
 
virtual ~NewButton (void)
 
- Public Member Functions inherited from Control
virtual Rect rect (void)
 
virtual void setRect (const Rect &r)
 
virtual bool hitTest (const Point &p)
 
virtual bool hidden (void)
 
virtual void setHidden (bool h=true)
 
virtual const std::string & id (void)
 
virtual void setId (const std::string &newId)
 
virtual GFXColor color (void)
 
virtual void setColor (const GFXColor &c)
 
virtual GFXColor outlineColor (void)
 
virtual void setOutlineColor (const GFXColor &c)
 
virtual GFXColor textColor (void)
 
virtual void setTextColor (const GFXColor &c)
 
virtual Font font (void)
 
virtual void setFont (const Font &f)
 
virtual bool hasGroupChildren (void)
 
 Control (void)
 
virtual ~Control (void)
 
- Public Member Functions inherited from EventResponder
virtual bool processCommand (const EventCommandId &command, Control *control)
 
virtual bool processKeyDown (const InputEvent &event)
 
virtual bool processKeyUp (const InputEvent &event)
 
virtual void processUnfocus (const InputEvent &event)
 
virtual bool processMouseMove (const InputEvent &event)
 
virtual bool processMouseDrag (const InputEvent &event)
 
virtual void sendCommand (const EventCommandId &command, Control *control)
 
virtual void setCommandTarget (EventResponder *responder)
 
virtual void setModal (bool modal)
 
 EventResponder (void)
 
virtual ~EventResponder (void)
 

Protected Member Functions

virtual void sendButtonCommand (void)
 
virtual void drawCycleBorder (float lineWidth)
 
- Protected Member Functions inherited from Control
virtual void drawBackground (void)
 

Protected Attributes

int m_drawingState
 
EventCommandId m_commandId
 
std::string m_label
 
bool m_leftPressed
 
GFXColor m_highlightColor
 
GFXColor m_textHighlightColor
 
GFXColor m_downColor
 
GFXColor m_downTextColor
 
float m_shadowWidth
 
float m_variableBorderCycleTime
 
GFXColor m_borderColor
 
GFXColor m_endBorderColor
 
PaintText m_paintText
 
GFXColor m_currentCycleColor
 
int m_currentCycle
 
int m_cycleStepCount
 
int m_cycleDirection
 
GFXColor m_cycleColorDelta
 
double m_lastStepTime
 
- Protected Attributes inherited from Control
Rect m_rect
 
std::string m_id
 
GFXColor m_color
 
GFXColor m_outlineColor
 
GFXColor m_textColor
 
Font m_font
 
bool m_hidden
 
- Protected Attributes inherited from EventResponder
bool m_modal
 
EventResponderm_commandTarget
 

Detailed Description

Definition at line 34 of file newbutton.h.

Member Enumeration Documentation

anonymous enum
Enumerator
NORMAL_STATE 
DOWN_STATE 
HIGHLIGHT_STATE 
DISABLED_STATE 
FINAL_BUTTON_STATE 

Definition at line 38 of file newbutton.h.

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  };

Constructor & Destructor Documentation

NewButton::NewButton ( void  )

Definition at line 199 of file newbutton.cpp.

199  :
201  , m_commandId()
202  , m_leftPressed( false )
207  , m_shadowWidth( 1.0 )
212  , m_currentCycle( 0 )
213  , m_cycleStepCount( -1 )
214  , m_cycleDirection( 0 )
216  , m_lastStepTime( 0.0 )
217 {}
virtual NewButton::~NewButton ( void  )
inlinevirtual

Definition at line 163 of file newbutton.h.

163 {}

Member Function Documentation

virtual GFXColor NewButton::borderColor ( void  )
inlinevirtual

Definition at line 135 of file newbutton.h.

References m_borderColor.

136  {
137  return m_borderColor;
138  }
virtual EventCommandId NewButton::command ( void  )
inlinevirtual

Definition at line 54 of file newbutton.h.

References m_commandId.

55  {
56  return m_commandId;
57  }
virtual GFXColor NewButton::downColor ( void  )
inlinevirtual

Definition at line 94 of file newbutton.h.

References m_downColor.

Referenced by draw().

95  {
96  return m_downColor;
97  }
virtual GFXColor NewButton::downTextColor ( void  )
inlinevirtual

Definition at line 104 of file newbutton.h.

References m_downTextColor.

Referenced by draw().

105  {
106  return m_downTextColor;
107  }
void NewButton::draw ( void  )
virtual

Implements Control.

Reimplemented in ScrollerButton.

Definition at line 38 of file newbutton.cpp.

References CENTER_JUSTIFY, Control::color(), DISABLED_STATE, DOWN_STATE, downColor(), downTextColor(), PaintText::draw(), drawCycleBorder(), drawLowRightShadow(), drawRect(), drawUpLeftShadow(), Control::font(), GUI_OPAQUE_BLACK(), GUI_OPAQUE_WHITE(), HIGHLIGHT_STATE, highlightColor(), isClear(), label(), m_drawingState, m_paintText, Control::m_rect, m_variableBorderCycleTime, NORMAL_STATE, PaintText::setColor(), PaintText::setFont(), PaintText::setJustification(), PaintText::setRect(), PaintText::setText(), shadowWidth(), Control::textColor(), and textHighlightColor().

Referenced by ScrollerButton::draw(), and setDrawingState().

39 {
40  const float lineWidth = shadowWidth();
41 
42  GFXColor currentTextColor; //Color of label text.
43  switch (m_drawingState)
44  {
45  case NORMAL_STATE:
46  drawRect( m_rect, color() );
47  if (m_variableBorderCycleTime > 0.0) {
48  drawCycleBorder( lineWidth );
49  } else {
51  drawUpLeftShadow( m_rect, GUI_OPAQUE_WHITE(), lineWidth );
52  }
53  currentTextColor = textColor();
54  break;
55  case DOWN_STATE:
56  {
57  GFXColor currentDownColor = downColor();
58  if ( isClear( currentDownColor ) )
59  currentDownColor = color();
60  drawRect( m_rect, currentDownColor );
61 
62  currentTextColor = downTextColor();
63  if ( isClear( currentTextColor ) )
64  currentTextColor = textColor();
65  if (m_variableBorderCycleTime > 0.0) {
66  drawCycleBorder( lineWidth );
67  } else {
68  drawUpLeftShadow( m_rect, GUI_OPAQUE_BLACK(), lineWidth );
70  }
71  break;
72  }
73  case HIGHLIGHT_STATE:
75 
76  currentTextColor = textHighlightColor();
77  if ( isClear( currentTextColor ) )
78  currentTextColor = textColor();
79  if (m_variableBorderCycleTime > 0.0) {
80  drawCycleBorder( lineWidth );
81  } else {
83  drawUpLeftShadow( m_rect, GUI_OPAQUE_WHITE(), lineWidth );
84  }
85  break;
86  case DISABLED_STATE:
87  //Just the button -- no shadows.
88  if (m_variableBorderCycleTime > 0.0)
89  drawCycleBorder( lineWidth );
90  else
91  drawRect( m_rect, color() );
92  currentTextColor = textColor();
93  break;
94  }
95  //Draw the button label.
100  m_paintText.setColor( currentTextColor );
101  m_paintText.draw();
102 }
void NewButton::drawCycleBorder ( float  lineWidth)
protectedvirtual

Definition at line 105 of file newbutton.cpp.

References GFXColor::a, GFXColor::b, CYCLE_STEPS_PER_SECOND, drawRectOutline(), float_to_int(), GFXColor::g, getNewTime(), m_borderColor, m_currentCycle, m_currentCycleColor, m_cycleColorDelta, m_cycleDirection, m_cycleStepCount, m_endBorderColor, m_lastStepTime, Control::m_rect, m_variableBorderCycleTime, and GFXColor::r.

Referenced by draw().

106 {
107  if (m_cycleStepCount <= 0)
108  //We need to figure out how many steps to use.
110  const double elapsedTime = getNewTime();
112  m_lastStepTime = elapsedTime;
113 
114  //It's time. Change the step in the cycle.
116  if (m_currentCycle <= 0) {
117  //At the bottom of the cycle.
119  m_cycleDirection = 1;
124  } else if (m_currentCycle >= m_cycleStepCount) {
125  //At the top of the cycle.
127  m_cycleDirection = (-1);
132  } else {
133  //Somewhere in the middle of the cycle.
138  }
139  }
140  //Whew! Now actually draw it.
142 }
int NewButton::drawingState ( void  )
virtual

Definition at line 153 of file newbutton.cpp.

References m_drawingState.

154 {
155  return m_drawingState;
156 }
virtual GFXColor NewButton::endBorderColor ( void  )
inlinevirtual

Definition at line 145 of file newbutton.h.

References m_endBorderColor.

146  {
147  return m_endBorderColor;
148  }
virtual GFXColor NewButton::highlightColor ( void  )
inlinevirtual

Definition at line 74 of file newbutton.h.

References m_highlightColor.

Referenced by draw().

75  {
76  return m_highlightColor;
77  }
virtual std::string NewButton::label ( void  )
inlinevirtual

Definition at line 64 of file newbutton.h.

References m_label.

Referenced by ScrollerButton::draw(), and draw().

65  {
66  return m_label;
67  }
bool NewButton::processMouseDown ( const InputEvent event)
virtual

Reimplemented from EventResponder.

Definition at line 165 of file newbutton.cpp.

References InputEvent::code, DOWN_STATE, globalEventManager(), LEFT_MOUSE_BUTTON, m_leftPressed, EventResponder::processMouseDown(), EventManager::pushResponder(), setDrawingState(), and EventResponder::setModal().

166 {
167  if (event.code == LEFT_MOUSE_BUTTON) {
168  m_leftPressed = true; //Remember this for mouse-up.
169  setModal( true ); //Make sure we don't miss anything.
170  //Make sure we see mouse events *first* until we get a mouse-up.
173  return true;
174  }
175  return Control::processMouseDown( event );
176 }
bool NewButton::processMouseUp ( const InputEvent event)
virtual

Reimplemented from EventResponder.

Definition at line 178 of file newbutton.cpp.

References InputEvent::code, globalEventManager(), Control::hitTest(), LEFT_MOUSE_BUTTON, InputEvent::loc, m_leftPressed, NORMAL_STATE, EventResponder::processMouseUp(), EventManager::removeResponder(), sendButtonCommand(), setDrawingState(), and EventResponder::setModal().

179 {
180  if (m_leftPressed && event.code == LEFT_MOUSE_BUTTON) {
181  //Send the button command if the button goes up inside the button.
182  //If not, consider the button action cancelled.
183  const bool doCommand = ( hitTest( event.loc ) );
184 
186 
187  //Make sure we get off the event chain.
188  globalEventManager().removeResponder( this, true );
189  setModal( false );
190  m_leftPressed = false;
191  //Send the command now, after we've cleaned up the event handling.
192  if (doCommand) sendButtonCommand();
193  return Control::processMouseUp( event );
194  }
195  return false;
196 }
void NewButton::sendButtonCommand ( void  )
protectedvirtual

Definition at line 160 of file newbutton.cpp.

References m_commandId, and EventResponder::sendCommand().

Referenced by processMouseUp().

161 {
162  sendCommand( m_commandId, this );
163 }
virtual void NewButton::setBorderColor ( const GFXColor c)
inlinevirtual

Definition at line 139 of file newbutton.h.

References c, and m_borderColor.

Referenced by NavComputer::constructControls(), and BaseComputer::constructControls().

140  {
141  m_borderColor = c;
142  }
void NewButton::setDrawingState ( int  newState)
virtual

Definition at line 145 of file newbutton.cpp.

References draw(), and m_drawingState.

Referenced by processMouseDown(), and processMouseUp().

146 {
147  if (m_drawingState != newState) {
148  m_drawingState = newState;
149  draw();
150  }
151 }
virtual void NewButton::setEndBorderColor ( const GFXColor c)
inlinevirtual

Definition at line 149 of file newbutton.h.

References c, and m_endBorderColor.

Referenced by NavComputer::constructControls(), and BaseComputer::constructControls().

150  {
152  }
virtual void NewButton::setShadowWidth ( float  width)
inlinevirtual

Definition at line 118 of file newbutton.h.

References m_shadowWidth, and width.

Referenced by NavComputer::constructControls(), and BaseComputer::constructControls().

119  {
121  }
virtual void NewButton::setTextHighlightColor ( const GFXColor c)
inlinevirtual

Definition at line 88 of file newbutton.h.

References c, and m_textHighlightColor.

89  {
91  }
virtual void NewButton::setVariableBorderCycleTime ( float  cycleTime)
inlinevirtual

Definition at line 128 of file newbutton.h.

References m_cycleStepCount, and m_variableBorderCycleTime.

Referenced by NavComputer::constructControls(), and BaseComputer::constructControls().

129  {
130  m_variableBorderCycleTime = cycleTime;
131  m_cycleStepCount = (-1);
132  }
virtual float NewButton::shadowWidth ( void  )
inlinevirtual

Definition at line 114 of file newbutton.h.

References m_shadowWidth.

Referenced by draw().

115  {
116  return m_shadowWidth;
117  }
virtual GFXColor NewButton::textHighlightColor ( void  )
inlinevirtual

Definition at line 84 of file newbutton.h.

References m_textHighlightColor.

Referenced by draw().

85  {
86  return m_textHighlightColor;
87  }
virtual float NewButton::variableBorderCycleTime ( void  )
inlinevirtual

Definition at line 124 of file newbutton.h.

References m_variableBorderCycleTime.

125  {
127  }

Member Data Documentation

GFXColor NewButton::m_borderColor
protected

Definition at line 187 of file newbutton.h.

Referenced by borderColor(), drawCycleBorder(), and setBorderColor().

EventCommandId NewButton::m_commandId
protected

Definition at line 178 of file newbutton.h.

Referenced by command(), sendButtonCommand(), and setCommand().

int NewButton::m_currentCycle
protected

Definition at line 193 of file newbutton.h.

Referenced by drawCycleBorder().

GFXColor NewButton::m_currentCycleColor
protected

Definition at line 192 of file newbutton.h.

Referenced by drawCycleBorder().

GFXColor NewButton::m_cycleColorDelta
protected

Definition at line 196 of file newbutton.h.

Referenced by drawCycleBorder().

int NewButton::m_cycleDirection
protected

Definition at line 195 of file newbutton.h.

Referenced by drawCycleBorder().

int NewButton::m_cycleStepCount
protected

Definition at line 194 of file newbutton.h.

Referenced by drawCycleBorder(), and setVariableBorderCycleTime().

GFXColor NewButton::m_downColor
protected

Definition at line 183 of file newbutton.h.

Referenced by downColor(), and setDownColor().

GFXColor NewButton::m_downTextColor
protected

Definition at line 184 of file newbutton.h.

Referenced by downTextColor(), and setDownTextColor().

int NewButton::m_drawingState
protected

Definition at line 177 of file newbutton.h.

Referenced by draw(), drawingState(), and setDrawingState().

GFXColor NewButton::m_endBorderColor
protected

Definition at line 188 of file newbutton.h.

Referenced by drawCycleBorder(), endBorderColor(), and setEndBorderColor().

GFXColor NewButton::m_highlightColor
protected

Definition at line 181 of file newbutton.h.

Referenced by highlightColor(), and setHighlightColor().

std::string NewButton::m_label
protected

Definition at line 179 of file newbutton.h.

Referenced by label(), and setLabel().

double NewButton::m_lastStepTime
protected

Definition at line 197 of file newbutton.h.

Referenced by drawCycleBorder().

bool NewButton::m_leftPressed
protected

Definition at line 180 of file newbutton.h.

Referenced by processMouseDown(), and processMouseUp().

PaintText NewButton::m_paintText
protected

Definition at line 189 of file newbutton.h.

Referenced by draw().

float NewButton::m_shadowWidth
protected

Definition at line 185 of file newbutton.h.

Referenced by setShadowWidth(), and shadowWidth().

GFXColor NewButton::m_textHighlightColor
protected

Definition at line 182 of file newbutton.h.

Referenced by setTextHighlightColor(), and textHighlightColor().

float NewButton::m_variableBorderCycleTime
protected

The documentation for this class was generated from the following files: