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
glut_support.h File Reference
#include <stdio.h>
#include <vector>
#include "gfxlib.h"

Go to the source code of this file.

Enumerations

enum  MousePointerStyle { MOUSE_POINTER_NONE, MOUSE_POINTER_NORMAL, MOUSE_POINTER_HOVER }
 

Functions

void ShowColor (float x, float y, float wid, float hei, float red, float green, float blue, float alpha)
 
void ShowText (float x, float y, float wid, int size, const char *string, int no_end)
 
float WidthOfChar (char chr)
 
void SetSoftwareMousePosition (int x, int y)
 
void StartGUIFrame (GFXBOOL clear=GFXTRUE)
 
void DrawGlutMouse (int mousex, int mousey, class VSSprite *spr)
 
void EndGUIFrame (MousePointerStyle pointerStyle)
 

Variables

int HAS_ALPHA
 

Enumeration Type Documentation

Enumerator
MOUSE_POINTER_NONE 
MOUSE_POINTER_NORMAL 
MOUSE_POINTER_HOVER 

Definition at line 29 of file glut_support.h.

Function Documentation

void DrawGlutMouse ( int  mousex,
int  mousey,
class VSSprite spr 
)

Definition at line 162 of file glut_support.cpp.

References DEPTHTEST, VSSprite::Draw(), g_game, VSSprite::GetPosition(), VSSprite::GetSize(), GFXBlendMode(), GFXColor4f(), GFXDisable(), GFXEnable(), INVSRCALPHA, LIGHTING, VSSprite::SetPosition(), SRCALPHA, TEXTURE0, TEXTURE1, game_data_t::x_resolution, and game_data_t::y_resolution.

Referenced by EndGUIFrame().

163 {
165  GFXColor4f( 1, 1, 1, 1 );
166  GFXDisable( TEXTURE1 );
167  GFXEnable( TEXTURE0 );
169  GFXDisable( LIGHTING );
170  float sizex = 0, sizey = 0;
171  spr->GetSize( sizex, sizey );
172  float tempx = 0, tempy = 0;
173  spr->GetPosition( tempx, tempy );
174  spr->SetPosition( tempx+ -1+.5*sizex+float(mousex)
175  /(.5*g_game.x_resolution), tempy+1+.5*sizey-float(mousey)/(.5*g_game.y_resolution) );
176  spr->Draw();
177  GFXDisable( TEXTURE0 );
178  GFXEnable( TEXTURE0 );
179  spr->SetPosition( tempx, tempy );
180 }
void EndGUIFrame ( MousePointerStyle  pointerStyle)

Definition at line 182 of file glut_support.cpp.

References BILINEAR, ConditionalCursorDraw(), CULLFACE, DrawGlutMouse(), GFXDisable(), GFXEnable(), GFXHudMode(), GFXTRUE, Texture::MakeActive(), mmx, mmy, MOUSE_POINTER_HOVER, MOUSE_POINTER_NONE, MOUSE_POINTER_NORMAL, NEAREST, TEXTURE2D, and TEXTURE_2D.

Referenced by BaseInterface::Draw().

183 {
184  static VSSprite MouseOverVSSprite( "mouseover.spr", BILINEAR, GFXTRUE );
185  static VSSprite MouseVSSprite( "mouse.spr", BILINEAR, GFXTRUE );
186  static Texture dummy( "white.bmp", 0, NEAREST, TEXTURE2D, TEXTURE_2D, GFXTRUE );
187 
188  if (pointerStyle != MOUSE_POINTER_NONE) {
189  dummy.MakeActive();
190  GFXDisable( CULLFACE );
191 
192  VSSprite *whichSprite = &MouseVSSprite;
193  switch(pointerStyle) {
194  case MOUSE_POINTER_NORMAL: whichSprite = &MouseVSSprite; break;
195  case MOUSE_POINTER_HOVER: whichSprite = &MouseOverVSSprite; break;
196  }
197 
198  DrawGlutMouse( mmx, mmy, whichSprite );
199 
200  //GFXEndScene();bad things...only call this once
201  GFXHudMode( false );
202  GFXEnable( CULLFACE );
203  ConditionalCursorDraw( true );
204  }
205 }
void SetSoftwareMousePosition ( int  x,
int  y 
)

Definition at line 138 of file glut_support.cpp.

References mmx, mmy, x, and y.

Referenced by BaseInterface::ActiveMouseOverWin(), and BaseInterface::PassiveMouseOverWin().

139 {
140  mmx = x;
141  mmy = y;
142 }
void ShowColor ( float  x,
float  y,
float  wid,
float  hei,
float  red,
float  green,
float  blue,
float  alpha 
)

Definition at line 37 of file glut_support.cpp.

References x, and y.

Referenced by Button::Refresh().

38 {
39  float cols[4] = {red, green, blue, alpha};
40  if (wid < 0 || hei < 0) {
41  printf( "Cannot draw color with negative height or width\n" );
42  return;
43  }
44  //Make sure we don't exceed the program
45  if (x+wid > 1) wid = 1-x;
46  if (y-hei < -1) hei = -1+y;
47 #ifdef DEBUG
48  cout<<"Displaying color at "<<x<<","<<y<<"\n";
49  cout<<"with the dimensions of "<<wid<<","<<hei<<"\n";
50  cout<<"With the color "<<red<<","<<green<<","<<blue<<","<<alpha<<"\n";
51  cout<<"-----------------------------\n";
52 #endif
53  glDisable( GL_TEXTURE_2D );
54  glBegin( GL_QUADS );
55  glColor4fv( cols );
56  glVertex2f( x, y-hei );
57  glColor4fv( cols );
58  glVertex2f( x, y );
59  glColor4fv( cols );
60  glVertex2f( x+wid, y );
61  glColor4fv( cols );
62  glVertex2f( x+wid, y-hei );
63  glEnd();
64  glEnable( GL_TEXTURE_2D );
65 }
void ShowText ( float  x,
float  y,
float  wid,
int  size,
const char *  string,
int  no_end 
)

Definition at line 76 of file glut_support.cpp.

References VegaConfig::getVariable(), gl_options, h, i, XMLSupport::parse_float(), gl_options_t::smooth_lines, vs_config, width, and word_length().

Referenced by Button::Refresh().

77 {
78  static float rescale_font = XMLSupport::parse_float( vs_config->getVariable( "graphics", "gui_font_scale", ".75" ) );
79  float font_size_float = rescale_font*5./100;
80 
81  int cur;
82  float font_size = size*rescale_font;
83  float width = 0;
84  float cur_width = 0;
85  float end = 0;
86  font_size /= 10000;
87 
88  glDisable( GL_TEXTURE_2D );
89  glLoadIdentity();
91  glEnable( GL_LINE_SMOOTH );
92  glLineWidth( wid );
93  float page_wid = wid/rescale_font;
94  glTranslatef( x, y, 0 );
95  glScalef( font_size, font_size, 1 );
96  end = no_end ? 0 : glutStrokeWidth( GLUT_STROKE_ROMAN, 'A' );
97  end /= 2500;
98  //if (no_end == 1) { end = 0; }
99  int h = 0;
100  for (cur = 0; str[cur] != '\0'; cur++) {
101  cur_width = glutStrokeWidth( GLUT_STROKE_ROMAN, str[cur] );
102  cur_width /= 2500;
103  if ( (width+end+word_length( str+cur ) > page_wid || str[cur] == '\\') && str[cur+1] != '\0' ) {
104  if (no_end == 0) {
105  width += cur_width;
106  for (int i = 1; i <= 3; i++)
107  glutStrokeCharacter( GLUT_STROKE_ROMAN, '.' );
108  break;
109  } else {
110  width = 0;
111  glLoadIdentity();
113  glEnable( GL_LINE_SMOOTH );
114  glLineWidth( wid );
115  glTranslatef( x, y-(++h)*font_size_float, 0 );
116  glScalef( font_size, font_size, 1 );
117  }
118  } else {
119  width += cur_width;
120  }
121  if (str[cur] != '\\')
122  glutStrokeCharacter( GLUT_STROKE_ROMAN, str[cur] );
123  }
124  glLoadIdentity();
126  glDisable( GL_LINE_SMOOTH );
127 }
void StartGUIFrame ( GFXBOOL  clr)

Starts a Frame of OpenGL with proper parameters and mouse

Definition at line 145 of file glut_support.cpp.

References CULLFACE, DEPTHTEST, DEPTHWRITE, GFXBlendMode(), GFXClear(), GFXColor4f(), GFXDisable(), GFXEnable(), GFXHudMode(), INVSRCALPHA, LIGHTING, SRCALPHA, TEXTURE0, and TEXTURE1.

Referenced by BaseInterface::Draw().

146 {
147  //glutSetCursor(GLUT_CURSOR_INHERIT);
148  //GFXViewPort (0,0,g_game.x_resolution,g_game.y_resolution);
149  GFXHudMode( true );
150  GFXColor4f( 1, 1, 1, 1 );
151 
154  GFXDisable( LIGHTING );
155  GFXDisable( CULLFACE );
156  GFXClear( clr );
159  GFXDisable( TEXTURE1 );
160  GFXEnable( TEXTURE0 );
161 }
float WidthOfChar ( char  chr)

Definition at line 129 of file glut_support.cpp.

References width.

130 {
131  float width = glutStrokeWidth( GLUT_STROKE_ROMAN, chr );
132  width /= 2500;
133  return width;
134 }

Variable Documentation

int HAS_ALPHA