Google
Web alhem.net
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

gui::Edit Class Reference

#include <Edit.h>

Inheritance diagram for gui::Edit:

Inheritance graph
[legend]
Collaboration diagram for gui::Edit:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Edit (Surface *, coord_t x, coord_t y, coord_t w, coord_t h, SurfaceHelper *=NULL)
 ~Edit ()
void Draw ()
void OnKeyDown (SDL_keysym)
void OnFocus ()
void OnLostFocus ()
void OnHide ()
void SetEcho (char)
void SetLine (const string &)
const char * GetLine ()
void DumpMembers (FILE *)

Private Attributes

string m_line
char m_echo
bool m_bFocus

Constructor & Destructor Documentation

gui::Edit::Edit Surface ,
coord_t  x,
coord_t  y,
coord_t  w,
coord_t  h,
SurfaceHelper = NULL
 

Definition at line 60 of file Edit.cpp.

References gui::coord_t, EDIT_DEFAULT_BG_B, EDIT_DEFAULT_BG_G, EDIT_DEFAULT_BG_R, EDIT_DEFAULT_FC_B, EDIT_DEFAULT_FC_G, EDIT_DEFAULT_FC_R, EDIT_DEFAULT_FG_B, EDIT_DEFAULT_FG_G, EDIT_DEFAULT_FG_R, and EDIT_DEFAULT_FW.

00061 :Surface(s,x,y,w,h,pclHelper) 00062 ,m_line("") 00063 ,m_echo(0) 00064 ,m_bFocus(false) 00065 { 00066 SetBgColor(EDIT_DEFAULT_BG_R,EDIT_DEFAULT_BG_G,EDIT_DEFAULT_BG_B); 00067 SetFgColor(EDIT_DEFAULT_FG_R,EDIT_DEFAULT_FG_G,EDIT_DEFAULT_FG_B); 00068 SetFrameWidth(EDIT_DEFAULT_FW); 00069 SetFrameColor(EDIT_DEFAULT_FC_R,EDIT_DEFAULT_FC_G,EDIT_DEFAULT_FC_B); 00070 }

gui::Edit::~Edit  ) 
 

Definition at line 73 of file Edit.cpp.

00074 { 00075 }


Member Function Documentation

void gui::Edit::Draw  )  [virtual]
 

Reimplemented from gui::Surface.

Definition at line 84 of file Edit.cpp.

References gui::coord_t, gui::Surface::GetBgColor(), gui::Surface::GetClientRectPtr(), gui::Surface::GetFgColor(), gui::Surface::GetH(), gui::Surface::GetTTFont(), m_bFocus, m_echo, and m_line.

00085 { 00086 SDL_Rect *area = GetClientRectPtr(); 00087 Uint32 color; 00088 TTFont *font = GetTTFont(); 00089 SDL_Color fg; 00090 SDL_Color bg; 00091 00092 color = GetFgColor(); 00093 memmove(&fg,&color,4); 00094 color = GetBgColor(); 00095 memmove(&bg,&color,4); 00096 00097 SDL_FillRect(m_screen, area, color ); 00098 if (font && font -> GetFont()) 00099 { 00100 coord_t h = font -> GetH(); 00101 coord_t y = GetH() / 2 + h / 2; 00102 00103 char *s = new char[m_line.size() + 2]; 00104 if (m_echo) 00105 { 00106 int i; 00107 for (i = 0; i < (int)m_line.size(); i++) 00108 s[i] = m_echo; 00109 s[i] = 0; 00110 } 00111 else 00112 { 00113 strcpy(s,m_line.c_str()); 00114 } 00115 if (m_bFocus) 00116 { 00117 strcat(s,"_"); 00118 } 00119 sge_tt_textoutf(m_screen, font -> GetFont(), 00120 10,y, 00121 fg.r,fg.g,fg.b, 00122 bg.r,bg.g,bg.b, 00123 SDL_ALPHA_OPAQUE, 00124 "%s",s); //m_line.c_str()); 00125 delete s; 00126 } 00127 }

void gui::Edit::DumpMembers FILE *   )  [virtual]
 

Reimplemented from gui::Surface.

Definition at line 216 of file Edit.cpp.

References m_echo, m_line, and util::Xml::Write().

00217 { 00218 Xml xml(fil); 00219 00220 Surface::DumpMembers(fil); 00221 00222 xml.Write("LINE",m_line); 00223 xml.Write("ECHO",m_echo); 00224 }

const char * gui::Edit::GetLine  ) 
 

Definition at line 179 of file Edit.cpp.

References m_line.

00180 { 00181 return m_line.c_str(); 00182 }

void gui::Edit::OnFocus  )  [virtual]
 

Reimplemented from gui::Surface.

Definition at line 185 of file Edit.cpp.

References m_bFocus.

00186 { 00187 m_bFocus = true; 00188 SetDirty(true); 00189 }

void gui::Edit::OnHide  )  [virtual]
 

Reimplemented from gui::Surface.

Definition at line 199 of file Edit.cpp.

References m_bFocus, and SDL_USEREVENT_LOSTFOCUS.

00200 { 00201 if (m_bFocus) 00202 { 00203 // m_bFocus = false; 00204 // DrawAll(); 00205 SDL_Event e; 00206 00207 e.type = SDL_USEREVENT; 00208 e.user.code = SDL_USEREVENT_LOSTFOCUS; 00209 e.user.data1 = this; 00210 e.user.data2 = NULL; 00211 SDL_PushEvent(&e); 00212 } 00213 }

void gui::Edit::OnKeyDown SDL_keysym   )  [virtual]
 

Reimplemented from gui::Surface.

Definition at line 130 of file Edit.cpp.

References gui::Surface::GetID(), gui::Surface::GetLocalID(), gui::Surface::GetParent(), GUI_EVENT_EDIT, gui::surface_event_struct::id, gui::surface_event_struct::local_id, m_line, gui::surface_event_struct::ptr, gui::surface_event_t, and gui::surface_event_struct::type.

00131 { 00132 char c = (char)keysym.sym; 00133 00134 if (isprint(c)) 00135 { 00136 m_line += c; 00137 SetDirty(true); 00138 } 00139 else 00140 if (keysym.sym == SDLK_BACKSPACE || keysym.sym == SDLK_DELETE) 00141 { 00142 if (m_line.size()) 00143 { 00144 m_line.erase(m_line.end() - 1); 00145 SetDirty(true); 00146 } 00147 } 00148 else 00149 if (keysym.sym == SDLK_RETURN) 00150 { 00151 Surface *pclParent = GetParent(); 00152 if (pclParent) 00153 { 00154 surface_event_t e; 00155 e.type = GUI_EVENT_EDIT; 00156 e.id = GetID(); 00157 e.local_id = GetLocalID(); 00158 e.ptr = this; 00159 pclParent -> OnEvent(&e); 00160 } 00161 } 00162 else 00163 { 00164 return; 00165 } 00166 // DrawAll(); 00167 // InvalidateEv(); 00168 }

void gui::Edit::OnLostFocus  )  [virtual]
 

Reimplemented from gui::Surface.

Definition at line 192 of file Edit.cpp.

References m_bFocus.

00193 { 00194 m_bFocus = false; 00195 SetDirty(true); 00196 }

void gui::Edit::SetEcho char   ) 
 

Definition at line 78 of file Edit.cpp.

References m_echo.

00079 { 00080 m_echo = c; 00081 }

void gui::Edit::SetLine const string &   ) 
 

Definition at line 171 of file Edit.cpp.

References m_line.

00172 { 00173 m_line = str; 00174 SetDirty(true); 00175 // InvalidateEv(); 00176 }


Member Data Documentation

bool gui::Edit::m_bFocus [private]
 

Definition at line 46 of file Edit.h.

Referenced by Draw(), OnFocus(), OnHide(), and OnLostFocus().

char gui::Edit::m_echo [private]
 

Definition at line 45 of file Edit.h.

Referenced by Draw(), DumpMembers(), and SetEcho().

string gui::Edit::m_line [private]
 

Definition at line 44 of file Edit.h.

Referenced by Draw(), DumpMembers(), GetLine(), OnKeyDown(), and SetLine().


The documentation for this class was generated from the following files:
Generated for My SDL C++ Gui by doxygen 1.3.6

www.TV-friendship.com
The matchmaking service with an all new twist.

Quantum 'Teleportation'
Some thoughts
Page, code, and content Copyright (C) 2004 by Anders Hedström