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

#include <button.h>

Public Member Functions

 Button (float x, float y, float wid, float hei, const char *name)
 
 ~Button (void)
 
void Refresh (void)
 
int MouseClick (int button, int state, float x, float)
 
int MouseMove (float x, float y)
 
int MouseMoveClick (float x, float y)
 
int DoMouse (int type, float x, float y, int button, int state)
 
void ModifyName (const char *newname)
 

Detailed Description

Definition at line 44 of file button.h.

Constructor & Destructor Documentation

Button::Button ( float  x,
float  y,
float  wid,
float  hei,
const char *  name 
)

Definition at line 24 of file button.cpp.

References Refresh(), x, and y.

25 {
26  //Initialize the variables
27  xcoord = x;
28  ycoord = y;
29  width = wid;
30  height = hei;
31  label = strdup( name );
32  highlight = 0;
33 
34  Refresh();
35 }
Button::~Button ( void  )

Definition at line 43 of file button.cpp.

44 {
45  if (label)
46  free( label );
47 }

Member Function Documentation

int Button::DoMouse ( int  type,
float  x,
float  y,
int  button,
int  state 
)

Definition at line 82 of file button.cpp.

References MouseClick(), MouseMove(), and MouseMoveClick().

83 {
84  if (type == 1) return MouseClick( button, state, x, y );
85  if (type == 2) return MouseMoveClick( x, y );
86  if (type == 3) return MouseMove( x, y );
87  return 0;
88 }
void Button::ModifyName ( const char *  newname)

Definition at line 36 of file button.cpp.

37 {
38  if (label && newname)
39  free( label );
40  if (newname)
41  label = strdup( newname );
42 }
int Button::MouseClick ( int  button,
int  state,
float  x,
float  y 
)

Definition at line 58 of file button.cpp.

References WS_MOUSE_UP.

Referenced by DoMouse().

59 {
60  if (Inside( x, y ) == 0) return 0;
61  if (state != WS_MOUSE_UP) return 0; //Returning the 1 says it's been clicked
62 
63  return 1;
64 }
int Button::MouseMove ( float  x,
float  y 
)

Definition at line 66 of file button.cpp.

Referenced by DoMouse().

67 {
68  if (Inside( x, y ) == 0) {
69  highlight = 0;
70  return 0;
71  }
72  highlight = 1;
73  return 1;
74 }
int Button::MouseMoveClick ( float  x,
float  y 
)

Definition at line 76 of file button.cpp.

Referenced by DoMouse().

77 {
78  //Nothing to do
79  return 0;
80 }
void Button::Refresh ( void  )

Definition at line 49 of file button.cpp.

References ShowColor(), and ShowText().

Referenced by Button().

50 {
51  if (highlight == 0) ShowColor( xcoord, ycoord, width, height, 0.51, 0.47, 0.79, 1 );
52 
53  else ShowColor( xcoord, ycoord, width, height, 0.66, 0.6, 1, 1 );
54  ShowColor( 0, 0, 0, 0, 0, 0, 0, 1 );
55  ShowText( xcoord+0.01, ycoord-height+( (height-0.04)/2 ), width, 4, label, 0 );
56 }

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