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.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 * button.cpp - description
3 * --------------------------
4 * begin : January 10, 2002
5 * copyright : (C) 2002 by David Ranger
6 * email : ussreliant@users.sourceforge.net
7 ***************************************************************************/
8 
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * any later version. *
15 * *
16 ***************************************************************************/
17 
18 #include "button.h"
19 #include "gldrv/winsys.h"
20 #include <cstdlib>
21 #include <cstring>
22 
23 //Button::Button(float x, float y, float wid, float hei, char *name) { ; }
24 Button::Button( float x, float y, float wid, float hei, const char *name )
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 }
36 void Button::ModifyName( const char *newname )
37 {
38  if (label && newname)
39  free( label );
40  if (newname)
41  label = strdup( newname );
42 }
44 {
45  if (label)
46  free( label );
47 }
48 
49 void Button::Refresh( void )
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 }
57 
58 int Button::MouseClick( int button, int state, float x, float y )
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 }
65 
66 int Button::MouseMove( float x, float y )
67 {
68  if (Inside( x, y ) == 0) {
69  highlight = 0;
70  return 0;
71  }
72  highlight = 1;
73  return 1;
74 }
75 
76 int Button::MouseMoveClick( float x, float y )
77 {
78  //Nothing to do
79  return 0;
80 }
81 
82 int Button::DoMouse( int type, float x, float y, int button, int state )
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 }
89 
90 int Button::Inside( float x, float y )
91 {
92  if (x < xcoord || y > ycoord) return 0;
93  if ( x > (xcoord+width) ) return 0;
94  if ( y < (ycoord-height) ) return 0;
95  return 1;
96 }
97