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

#include <textinputdisplay.h>

Inheritance diagram for TextInputDisplay:
StaticDisplay Control EventResponder

Public Member Functions

 TextInputDisplay (std::vector< unsigned int > *keyboard_input_queue, const char *disallowed)
 
virtual void processUnfocus (const InputEvent &event)
 
virtual bool processMouseDown (const InputEvent &event)
 
virtual bool processKeypress (unsigned int pressedKey)
 
void setPassword (char passchar)
 
virtual ~TextInputDisplay ()
 
virtual void draw ()
 
- Public Member Functions inherited from StaticDisplay
virtual std::string text (void)
 
virtual void setText (std::string t)
 
virtual Justification justification (void)
 
virtual void setJustification (Justification j)
 
virtual bool multiLine (void)
 
virtual void setMultiLine (bool multi)
 
virtual Size textMargins (void)
 
virtual void setTextMargins (const Size &s)
 
virtual void setScroller (Scroller *s)
 
virtual GFXColor textColor (void)
 
virtual void setTextColor (const GFXColor &c)
 
virtual Font font (void)
 
virtual void setFont (const Font &f)
 
virtual void setRect (const Rect &r)
 
virtual bool processCommand (const EventCommandId &command, Control *control)
 
 StaticDisplay (void)
 
virtual ~StaticDisplay (void)
 
- Public Member Functions inherited from Control
virtual Rect rect (void)
 
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 bool hasGroupChildren (void)
 
 Control (void)
 
virtual ~Control (void)
 
- Public Member Functions inherited from EventResponder
virtual bool processKeyDown (const InputEvent &event)
 
virtual bool processKeyUp (const InputEvent &event)
 
virtual bool processMouseUp (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)
 

Additional Inherited Members

- Protected Member Functions inherited from StaticDisplay
void setPaintTextRect (void)
 
- Protected Attributes inherited from StaticDisplay
PaintText m_paintText
 
Size m_textMargins
 
int m_scrollPosition
 
int m_layoutVersion
 
Scrollerm_scroller
 

Detailed Description

Definition at line 32 of file textinputdisplay.h.

Constructor & Destructor Documentation

TextInputDisplay::TextInputDisplay ( std::vector< unsigned int > *  keyboard_input_queue,
const char *  disallowed 
)

Definition at line 28 of file textinputdisplay.cpp.

29 {
30  isFocused = false;
31  if (keyboard_input_queue)
32  this->keyboard_queue = keyboard_input_queue;
33  else
34  this->keyboard_queue = &local_keyboard_queue;
35  passwordChar = '\0';
36  keyboard_input_queue->clear();
37  this->disallowed = new char[strlen( disallowed )+1];
38  strcpy( this->disallowed, disallowed );
39 }
TextInputDisplay::~TextInputDisplay ( )
virtual

Definition at line 110 of file textinputdisplay.cpp.

111 {
112  delete[] this->disallowed;
113 }

Member Function Documentation

void TextInputDisplay::draw ( void  )
virtual

Reimplemented from StaticDisplay.

Definition at line 62 of file textinputdisplay.cpp.

References c, StaticDisplay::draw(), getNewTime(), i, int, j, processKeypress(), StaticDisplay::setText(), StaticDisplay::text(), and x.

63 {
64  string text = this->text();
65  if (!this->isFocused) {
66  if (passwordChar) {
67  string text1;
68  text1.insert( 0u, text.length(), passwordChar );
69  this->setText( text1 );
70  }
71  this->StaticDisplay::draw();
72  if (passwordChar)
73  this->setText( text );
74  return;
75  }
76  size_t LN = keyboard_queue->size();
77  for (size_t i = 0; i < LN; ++i) {
78  unsigned int c = (*keyboard_queue)[i];
79  if ( !processKeypress( c ) ) continue;
80  if (c == 8 || c == 127) {
81  text = text.substr( 0, text.length()-1 );
82  } else if (c != '\0' && c < 256) {
83  bool allowed = true;
84  for (int j = 0; disallowed[j]; ++j)
85  if ( c == static_cast<unsigned int>(disallowed[j]) ) {
86  allowed = false;
87  break;
88  }
89  if (allowed) {
90  char tmp[2] = {0, 0};
91  tmp[0] = (char) c;
92  text += tmp;
93  }
94  }
95  }
96  keyboard_queue->clear();
97  unsigned int x = (unsigned int) getNewTime();
98  string text1;
99  if (passwordChar)
100  text1.insert( 0u, text.length(), passwordChar );
101  else
102  text1 = text;
103  if (x%2)
104  text1 += "|";
105  this->setText( text1 );
106  this->StaticDisplay::draw();
107  this->setText( text );
108 }
bool TextInputDisplay::processKeypress ( unsigned int  pressedKey)
virtual

Definition at line 57 of file textinputdisplay.cpp.

Referenced by draw().

58 {
59  return true;
60 }
bool TextInputDisplay::processMouseDown ( const InputEvent event)
virtual

Reimplemented from StaticDisplay.

Definition at line 41 of file textinputdisplay.cpp.

References InputEvent::code, Control::hitTest(), InputEvent::loc, StaticDisplay::processMouseDown(), WHEELDOWN_MOUSE_BUTTON, and WHEELUP_MOUSE_BUTTON.

42 {
43  if (event.code != WHEELUP_MOUSE_BUTTON && event.code != WHEELDOWN_MOUSE_BUTTON)
44  //If click is on me, set me focused... otherwise, clear my focus.
45  this->isFocused = ( hitTest( event.loc ) );
46  return StaticDisplay::processMouseDown( event );
47 }
void TextInputDisplay::processUnfocus ( const InputEvent event)
virtual

Reimplemented from EventResponder.

Definition at line 49 of file textinputdisplay.cpp.

References InputEvent::code, EventResponder::processUnfocus(), WHEELDOWN_MOUSE_BUTTON, and WHEELUP_MOUSE_BUTTON.

50 {
51  if (event.code != WHEELUP_MOUSE_BUTTON && event.code != WHEELDOWN_MOUSE_BUTTON)
52  //If click is on me, set me focused... otherwise, clear my focus.
53  this->isFocused = false;
55 }
void TextInputDisplay::setPassword ( char  passchar)
inline

Definition at line 45 of file textinputdisplay.h.

Referenced by GameMenu::createNetworkControls().

46  {
47  passwordChar = passchar;
48  }

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