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

#include <rendertext.h>

Inheritance diagram for RText:
commandI mmoc

Public Member Functions

 RText ()
 
virtual ~RText ()
 
std::string getcurcommand ()
 
int text_width (char *str)
 
void draw_text (std::string &str, float left, float top, int gl_num)
 
void renderconsole ()
 
void conline (std::string &sf, bool highlight)
 
void conoutf (char *)
 
virtual void conoutf (std::string &s, int a=0, int b=0, int c=0)
 
void saycommand (const char *init)
 
void ConsoleKeyboardI (int code, bool isdown)
 
void conoutn (std::string &in, int a, int b, int c)
 

Detailed Description

Definition at line 5 of file rendertext.h.

Constructor & Destructor Documentation

RText::RText ( )

Definition at line 38 of file rendertext.cpp.

References saycommand().

39 {
40 #ifdef HAVE_SDL
41  //Initialize shared mutex
42  //(creation is always single-threaded, since no aliases are possible yet)
43  _rtextSDLMutex();
44 #endif
45 
46  ndraw = 15;
47  WORDWRAP = 85;
48  conskip = 0;
49  saycommand( "" );
50 }
RText::~RText ( )
virtual

Definition at line 51 of file rendertext.cpp.

51 {}

Member Function Documentation

void RText::conline ( std::string &  sf,
bool  highlight 
)

Definition at line 117 of file rendertext.cpp.

118 {
119  {
120  size_t search = 0;
121  size_t lastsearch = 0;
122  for (; ( search = sf.find( "/r" ) ) != string::npos;) {
123  sf.replace( lastsearch, search-lastsearch, "" );
124  lastsearch = search;
125  }
126  }
127  cline cl;
128  int lastmillis = 0;
129  cl.outtime = lastmillis; //for how long to keep line on screen
130  if (highlight) {
131  //show line in a different colour, for chat etc.
132  cl.cref.append( "\f" );
133  cl.cref.append( sf );
134  } else {
135  cl.cref.append( sf );
136  }
137  conlines.insert( conlines.begin(), cl );
138 }
void RText::conoutf ( char *  in)
virtual void RText::conoutf ( std::string &  s,
int  a = 0,
int  b = 0,
int  c = 0 
)
virtual

Reimplemented in mmoc.

void RText::conoutn ( std::string &  in,
int  a,
int  b,
int  c 
)

Definition at line 191 of file rendertext.cpp.

References conoutf(), and x.

192 {
193  size_t x = s.find( "\n" );
194  size_t xlast = 0;
195  if (x >= string::npos)
196  conoutf( s );
197  string::iterator iter = s.end();
198  if ( iter != s.begin() ) {
199  iter--;
200  if (strcmp( &( *(iter) ), "\n" ) != 0) s.append( "\n" );
201  ;
202  }
203  while (x < string::npos) {
204  string part;
205  part.append( s.substr( xlast, x-xlast ) );
206  xlast = x+1;
207  x = s.find( "\n", x+1 );
208  conoutf( part, a, b, c );
209  }
210 }
void RText::ConsoleKeyboardI ( int  code,
bool  isdown 
)

Definition at line 217 of file rendertext.cpp.

References k, WSK_BACKSPACE, WSK_LEFT, and WSK_RETURN.

Referenced by commandI::keypress().

218 {
219  if (isdown) {
220  switch (code)
221  {
222 //pop teh back of commandbuf
223  case WSK_BACKSPACE:
224  {
225  string::iterator iter = commandbuf.begin();
226  if ( iter < commandbuf.end() ) {
227  iter = commandbuf.end();
228  iter--;
229  commandbuf.erase( iter );
230  }
231  break;
232  }
233  case WSK_LEFT:
234 //this should move a put pointer for commandbuf
235 //right should move it the other way.
236  break;
237 
238  case WSK_RETURN:
239  if (commandbuf[0]) {
240  vector< string >::iterator iter = vhistory.end();
241  bool noSize = false;
242  if ( iter <= vhistory.begin() && iter >= vhistory.end() ) noSize = true;
243  if (!noSize) {
244  iter--;
245  if (commandbuf.compare( ( *(iter) ) ) != 0 && !noSize) {
246 //store what was typed into a vector for a command history
247 //to scroll up and down through what was typed
248 //This "feature" isn't finished
249  vhistory.push_back( commandbuf ); //cap this?
250  }
251  } else if (noSize) {
252  vhistory.push_back( commandbuf );
253  }
254  //commands beginning with / are executed
255  //in localPlayer.cpp just before this is called
256  }
257  if (commandbuf.size() > 0) {
258 //print what was typed - Now done in the command processor
259 //clear the buffer
260  commandbuf.erase();
261  }
262  break;
263  default:
264 //add it to the command buffer
265  if (code > 0 && code < 256) {
266  unsigned char k = (unsigned char) code;
267  commandbuf += k;
268  }
269  break;
270  }
271  }
272 }
void RText::draw_text ( std::string &  str,
float  left,
float  top,
int  gl_num 
)

Definition at line 63 of file rendertext.cpp.

References StarSystemGent::background, TextPlane::Draw(), f, float_to_int(), TextPlane::SetCharSize(), TextPlane::SetPos(), x, and y.

Referenced by renderconsole().

64 {
65  int x = float_to_int( left );
66  int y = float_to_int( top );
67 
68  std::string::iterator iter = str.begin();
69  GFXColor foreground( 1, 1, 1, 1 );
70  GFXColor background( 0.05f, 0.05f, 0.2f, 0.5f );
71  TextPlane newTextPlane( foreground, background );
72  newTextPlane.SetPos( x, y );
73  newTextPlane.SetCharSize( .8, .12 );
74  newTextPlane.Draw( str );
75 }
string RText::getcurcommand ( )

Definition at line 275 of file rendertext.cpp.

Referenced by commandI::keypress(), and renderconsole().

276 {
277  return commandbuf;
278 }
void RText::renderconsole ( )

Definition at line 77 of file rendertext.cpp.

References draw_text(), getcurcommand(), j, x, and y.

78 {
79  int nd = 0;
80  vector< string >refs;
81  bool breaker = false;
82  for (vector< cline >::iterator iter = conlines.begin(); iter < conlines.end(); iter++) {
83  if (nd < ndraw)
84  refs.push_back( ( *(iter) ).cref );
85  else iter = conlines.end();
86  nd++;
87  }
88  size_t j = 0;
89  float x = -1;
90  float y = -0.5;
91  string workIt;
92  workIt.append( "\n" );
93  bool breakout = true;
94  vector< string >::iterator iter = refs.end();
95  if ( iter == refs.begin() ) breakout = false;
96  for (; breakout;) {
97  iter--;
98  if ( iter == refs.begin() ) breakout = false;
99  workIt.append( ( *(iter) ) );
100  workIt.append( "\n" );
101  }
102  y = 1;
103  ostringstream drawCommand;
104  string shorter;
105  shorter.append( getcurcommand() );
106  while (shorter.size() > 80)
107  shorter.erase( shorter.begin() );
108  //erase the front of the current command while it's larger than 80
109  //charactors, as to not draw off the screen
110  drawCommand<<workIt<<"#FF1100> "<<"#FF1100"<<shorter<<"#00000";
111  string Acdraw; //passing .str() straight to draw_text produces an
112  //error with gcc 4, because it's constant I believe
113  Acdraw.append( drawCommand.str() );
114  draw_text( Acdraw, x, y, 2 );
115 }
void RText::saycommand ( const char *  init)

Definition at line 213 of file rendertext.cpp.

Referenced by RText().

214 {
215 }
int RText::text_width ( char *  str)

Definition at line 53 of file rendertext.cpp.

54 {
55  return 0;
56 }

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