Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

Ars::ArsApplication Class Reference

#include <SdlArs.h>

Inheritance diagram for Ars::ArsApplication:

Inheritance graph
[legend]
Collaboration diagram for Ars::ArsApplication:

Collaboration graph
[legend]

Public Member Functions

 ArsApplication (const int argc, char **argv)
virtual ~ArsApplication (void)
 Standard destructor.

virtual void GenDefaultCfg (void)
const int ExitCode (void) const
 The exit code of the app.

const bool IsRunning (void) const
 true while the application is in it's message loop

void SetKeyFocus (MessageClient *pWindow)
MessageClientGetKeyFocus (void) const
 A pointer to the window with keyboard focus.

virtual void Init (void)
virtual void Exec (void)
 The primary message loop.

FontEngineGetFontEngine (std::string sFontFileName, unsigned char iFontSize=12)
void SetDefaultFontEngine (FontEngine *pFontEngine)
FontEngineGetDefaultFontEngine (void) const
 A pointer to the default font engine.

virtual const bool MainLoop (void)
void HandleSDLEvent (SDL_Event event)

Static Public Member Functions

ArsApplicationGetInstance (void)
 A pointer to the one instance of the Application.

string GetCoordStr (void)

Static Public Attributes

XPoint mousexy
int scrW = 1280 Ars::ArsApplication::scrH = 1024
int scrH
map< icstring, void * > lbGetter
map< icstring, unsigned long > Mnemo_f
map< icstring, unsigned long > Mnemo_s
vector< cbObjCreateTypeobjCreate

Protected Member Functions

virtual const bool wmExit (const Message &msg)

Protected Attributes

const int argc
 The argument count from the command line.

char ** argv
 The argument array from the command line.

FontEnginedefaultFontEngine
Viewframe

Private Attributes

int exitCode
bool running
MessageClientkeyFocusWindow
 A pointer to the window with keyboard focus.


Static Private Attributes

ArsApplicationinstance = 0

Constructor & Destructor Documentation

Ars::ArsApplication::ArsApplication const int  argc,
char **  argv
 

Standard constructor

Parameters:
argc The argument count from the command line
argv The argument array from the command line

Definition at line 47 of file SdlArs.cpp.

References cbObjCreate(), cbObjCreateType, F_EDITABLE, F_EXIT, F_FOLLOWMOUSE, F_HIDETREE, F_INDIRECT, F_MULTISELECT, F_NONE, F_PASSWORD, F_SELECTABLE, F_TABSTOP, instance, Mnemo_f, Mnemo_s, objCreate, Ars::rsrcMutex, S_ALIGN_BOTTOM, S_ALIGN_LEFT, S_ALIGN_RIGHT, S_ALIGN_TOP, S_BORDER, S_CHECKED, S_DISABLED, S_FOCUS, S_HIGHLIGHT, S_INVERTONFOLLOW, S_NONE, S_OUTLINED, S_RAISED, S_SELECTED, S_SHADOWED, S_SUNKEN, S_TRANSPARENT, and tron.

00048 : argc( Argc ) , argv( Argv ) , exitCode( EXIT_FAILURE ) , frame( 0 )
00049 , running( false ) , defaultFontEngine( 0 ) , keyFocusWindow( 0 )
00050 {
00051         rsrcMutex = SDL_CreateMutex();
00052 
00053         instance = this;
00054 
00055         if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
00056                 tron << "ArsApplication::ArsApplication : Could not initialize SDL: " << SDL_GetError() << "\n";;
00057 
00058         //Setting the keyboard repeat rate using the SDL Default rates
00059         if(SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL) == -1)
00060                 tron << "ArsApplication::ArsApplication : Error setting SDL keyboard repeat rate.\n";
00061 
00062         Mix_OpenAudio( MIX_DEFAULT_FREQUENCY , MIX_DEFAULT_FORMAT , 2 , 4096 );
00063 
00064         Mnemo_f["F_NONE"] = F_NONE;
00065         Mnemo_f["F_SELECTABLE"] = F_SELECTABLE;
00066         Mnemo_f["F_EXIT"] = F_EXIT;
00067         Mnemo_f["F_EDITABLE"] = F_EDITABLE;
00068         Mnemo_f["F_HIDETREE"] = F_HIDETREE;
00069         Mnemo_f["F_INDIRECT"] = F_INDIRECT;
00070         Mnemo_f["F_PASSWORD"] = F_PASSWORD ;
00071         Mnemo_f["F_MULTISELECT"] = F_MULTISELECT;
00072         Mnemo_f["F_TABSTOP"] = F_TABSTOP;
00073         Mnemo_f["F_FOLLOWMOUSE"] = F_FOLLOWMOUSE;
00074 
00075         Mnemo_s["S_NONE"] = S_NONE;
00076         Mnemo_s["S_SELECTED"] = S_SELECTED;
00077         Mnemo_s["S_DISABLED"] = S_DISABLED;
00078         Mnemo_s["S_CHECKED"] = S_CHECKED;
00079         Mnemo_s["S_OUTLINED"] = S_OUTLINED;
00080         Mnemo_s["S_SHADOWED"] = S_SHADOWED;
00081         Mnemo_s["S_BORDER"] = S_BORDER;
00082         Mnemo_s["S_FOCUS"] = S_FOCUS;
00083 
00084         Mnemo_s["S_ALIGN_LEFT"] = S_ALIGN_LEFT;
00085         Mnemo_s["S_ALIGN_RIGHT"] = S_ALIGN_RIGHT;
00086         Mnemo_s["S_ALIGN_TOP"] = S_ALIGN_TOP;
00087         Mnemo_s["S_ALIGN_BOTTOM"] = S_ALIGN_BOTTOM;
00088 
00089         Mnemo_s["S_RAISED"] = S_RAISED;
00090         Mnemo_s["S_SUNKEN"] = S_SUNKEN;
00091         Mnemo_s["S_TRANSPARENT"] = S_TRANSPARENT;
00092         Mnemo_s["S_HIGHLIGHT"] = S_HIGHLIGHT;
00093         Mnemo_s["S_INVERTONFOLLOW"] = S_INVERTONFOLLOW;
00094 
00095         objCreate.push_back( (cbObjCreateType)::cbObjCreate );
00096 
00097         atexit( SDL_Quit );
00098 }

Ars::ArsApplication::~ArsApplication void   )  [virtual]
 

Standard destructor.

Definition at line 100 of file SdlArs.cpp.

References Cfg::Empty(), frame, Cfg::Pop(), Ars::Graf::ResetCursors(), Ars::Graf::ResetImage(), Ars::rsrcMutex, and Ars::UnloadSounds().

00101 {
00102         SDL_DestroyMutex( rsrcMutex );
00103 
00104         if( frame )
00105                 delete frame;
00106         frame = 0;
00107 
00108         for( std::map<std::pair<std::string, unsigned char>, FontEngine*>::iterator iter = begin() ; iter != end() ; ++iter )
00109         {
00110                 if (iter->second)
00111                 {
00112                         delete iter->second;
00113                         iter->second = 0;
00114                 }
00115         }
00116         clear();
00117 
00118         while( !Cfg::Empty() )
00119         Cfg::Pop();
00120 
00121         Ars::Graf::ResetImage();
00122         Ars::Graf::ResetCursors();
00123         Ars::UnloadSounds();
00124 
00125 }


Member Function Documentation

void Ars::ArsApplication::Exec void   )  [virtual]
 

The primary message loop.

First flush all the messages we have...

Definition at line 173 of file SdlArs.cpp.

References frame, Ars::Window::Init(), Ars::View::MainLoop(), and running.

Referenced by TofMain().

00174 {
00176         frame->Init( EmptyString );
00177         while( !MessageServer::Instance().empty() )
00178                 MessageServer::Instance().ProcessMessage();
00179 
00180         running = true;
00181         frame->MainLoop();
00182 }

const int Ars::ArsApplication::ExitCode void   )  const [inline]
 

The exit code of the app.

Definition at line 144 of file SdlArs.h.

References exitCode.

Referenced by TofMain().

00144 { return exitCode; }

void Ars::ArsApplication::GenDefaultCfg void   )  [virtual]
 

Create a ars.cfg file if not already exists and fills it with some predefined information under the section named "Ars":the ksy names "text_color" for default text color under the section named "Ars":the ksy names "back_color" for default background color under the section named "Paths":the ksy names "Fonts" for default font path under the section named "Paths":the ksy names "Dialogs" for default dialog configuration file under the section named "Paths":the ksy names "Menu" for default menu configuration file under the section named "Paths":the ksy names "Images" for default images path

Reimplemented in Borqueror.

Definition at line 127 of file SdlArs.cpp.

References ArsBack_color, ArsText_color, Cfg::Handler::Flush(), Cfg::GetCfg(), Cfg::Handler::SetCfgColorHex(), and Cfg::Handler::SetCfgFile().

00128 {
00129         Cfg::Handler &h = Cfg::GetCfg();
00130 
00131         h.SetCfgColorHex( "Ars" , "text_color" , ArsText_color );
00132         h.SetCfgColorHex( "Ars" , "back_color" , ArsBack_color );
00133 
00134         h.SetCfgFile( "Paths" , "Fonts" , "./data/Fonts/Fonts.cfg" );
00135         h.SetCfgFile( "Paths" , "Dialogs" , "./data/dialogs.cfg" );
00136         h.SetCfgFile( "Paths" , "Menu" , "./data/menu.cfg" );
00137         h.SetCfgFile( "Paths" , "Images" , "./data/images/images.cfg" );
00138 
00139         h.Flush();
00140 }

string Ars::ArsApplication::GetCoordStr void   )  [static]
 

Definition at line 184 of file SdlArs.cpp.

References itoa(), scrH, and scrW.

00185 {
00186         char    temp[10];
00187         string ans( itoa( scrW , temp , 10 ) );
00188         ans += "x";
00189         ans += itoa( scrH , temp , 10 );
00190         return ans;
00191 }

FontEngine* Ars::ArsApplication::GetDefaultFontEngine void   )  const [inline]
 

A pointer to the default font engine.

Definition at line 180 of file SdlArs.h.

References defaultFontEngine.

00180 { return defaultFontEngine; }

FontEngine * Ars::ArsApplication::GetFontEngine std::string  sFontFileName,
unsigned char  iFontSize = 12
 

Creates a font engine A seperate font engine is created for each font file and font size

Parameters:
sFontFileName The font to use
iFontSize The size (in points) of the font, defaults to 12
Returns:
A pointer to the font engine

Definition at line 210 of file SdlArs.cpp.

Referenced by Init().

00211 {
00212         std::map< std::pair< std::string, unsigned char>, FontEngine *>::iterator iterFontEngine = find(std::make_pair(sFontFileName, iFontSize));
00213         FontEngine* pFontEngine = 0;
00214 
00215         if (iterFontEngine == end())
00216         {
00217                 // Requested font engine doesn't exist, so create one and add it to the map
00218                 pFontEngine = new FontEngine(sFontFileName, iFontSize);
00219                 insert(std::make_pair(std::make_pair(sFontFileName, iFontSize), pFontEngine));
00220         }
00221         else
00222                 pFontEngine = iterFontEngine->second;
00223 
00224         return pFontEngine;
00225 }

ArsApplication* Ars::ArsApplication::GetInstance void   )  [inline, static]
 

A pointer to the one instance of the Application.

Definition at line 141 of file SdlArs.h.

References instance.

00141 { return instance; }

MessageClient* Ars::ArsApplication::GetKeyFocus void   )  const [inline]
 

A pointer to the window with keyboard focus.

Definition at line 155 of file SdlArs.h.

References keyFocusWindow.

Referenced by HandleSDLEvent().

00156         { 
00157                 return keyFocusWindow; 
00158         }

void Ars::ArsApplication::HandleSDLEvent SDL_Event  event  ) 
 

For internal use only.

converts SDL events into wGui messages

Parameters:
event An SDL Event structure

Definition at line 256 of file SdlArs.cpp.

References ArsPostMessage, GetKeyFocus(), and mousexy.

Referenced by MainLoop().

00257 {
00258         // this will turn an SDL event into a wGui message
00259         switch (Event.type)
00260         {
00261         case SDL_VIDEORESIZE:
00262                 ArsPostMessage( ResizeMessage( Message::CTRL_RESIZE, 0, 0, XPoint(Event.resize.w, Event.resize.h ) ) );
00263                 break;
00264         case SDL_KEYDOWN:
00265                 ArsPostMessage( KeyboardMessage( Message::KEYBOARD_KEYDOWN, GetKeyFocus(),Event.key.keysym.scancode, Event.key.keysym.mod,Event.key.keysym.sym, Event.key.keysym.unicode ) );
00266                 break;
00267         case SDL_KEYUP:
00268                 ArsPostMessage( KeyboardMessage( Message::KEYBOARD_KEYUP, GetKeyFocus(),Event.key.keysym.scancode, Event.key.keysym.mod,Event.key.keysym.sym, Event.key.keysym.unicode ) );
00269                 break;
00270         case SDL_MOUSEBUTTONDOWN:
00271                 mousexy = XPoint(Event.button.x, Event.button.y);
00272                 ArsPostMessage( MouseMessage( Message::MOUSE_BUTTONDOWN, 0, XPoint(Event.button.x, Event.button.y), XPoint() , MouseMessage::TranslateSDLButton( Event.button.button ) ) );
00273                 break;
00274         case SDL_MOUSEBUTTONUP:
00275                 mousexy = XPoint(Event.button.x, Event.button.y);
00276                 ArsPostMessage( MouseMessage( Message::MOUSE_BUTTONUP, 0, XPoint(Event.button.x, Event.button.y), XPoint() ,MouseMessage::TranslateSDLButton(Event.button.button) ) );
00277                 break;
00278         case SDL_MOUSEMOTION:
00279                 mousexy = XPoint(Event.motion.x, Event.motion.y);
00280                 ArsPostMessage( MouseMessage( Message::MOUSE_MOVE, 0, XPoint(Event.motion.x, Event.motion.y) , XPoint(Event.motion.xrel, Event.motion.yrel), MouseMessage::TranslateSDLButtonState(Event.motion.state) ) );
00281                 break;
00282         case SDL_QUIT:
00283                 ArsPostMessage( Message( Message::APP_EXIT, 0 ) );
00284                 break;
00285         }
00286 }

void Ars::ArsApplication::Init void   )  [virtual]
 

Init() must be called before Exec() Takes care of initializing SDL and other important stuff

Reimplemented in Borqueror.

Definition at line 142 of file SdlArs.cpp.

References ArsBack_color, ArsText_color, Cfg::GetCfg(), Cfg::Handler::GetCfgColorHex(), Cfg::Handler::GetCfgFile(), Cfg::Handler::GetCfgString(), GetFontEngine(), Cfg::Push(), and SetDefaultFontEngine().

Referenced by TofMain().

00143 {
00144         if( Cfg::GetCfg().GetSize() == 0 )
00145                 ((ArsApplication *)this)->GenDefaultCfg();
00146 
00147         Cfg::Push( "Ars.Cfg" );
00148 
00149         MessageServer::Instance().RegisterMessageClient( this , Message::APP_EXIT );
00150         SDL_EnableUNICODE( 1 );
00151 
00152         Cfg::Handler &h = Cfg::GetCfg();
00153 
00154         ArsText_color = h.GetCfgColorHex( "Ars" , "text_color" , RGBColor(  0,   0,   0) );
00155         ArsBack_color = h.GetCfgColorHex( "Ars" , "back_color" , RGBColor(223, 223, 223) );
00156 
00157         Cfg::Handler    &fnt = Cfg::Push( h.GetCfgString( "Paths" , "Fonts" ) );
00158         SetDefaultFontEngine( GetFontEngine( fnt.GetCfgFile( "" , "Font0" ) , 16 ) );
00159 }

const bool Ars::ArsApplication::IsRunning void   )  const [inline]
 

true while the application is in it's message loop

Definition at line 147 of file SdlArs.h.

References running.

Referenced by MainLoop().

00147 { return running; }

const bool Ars::ArsApplication::MainLoop void   )  [virtual]
 

Definition at line 227 of file SdlArs.cpp.

References frame, HandleSDLEvent(), Ars::View::IdleProcess(), and IsRunning().

00228 {
00229         SDL_Event event;
00230         if( IsRunning() )
00231         {
00232                 while( SDL_PollEvent( &event ) )
00233                         HandleSDLEvent( event );
00234 
00235                 while( MessageServer::Instance().empty() )
00236                 {
00237                         while( SDL_PollEvent( &event ) )
00238                                 HandleSDLEvent( event );
00239                         SDL_Delay( 10 );
00240                 }
00241                 MessageServer::Instance().ProcessMessage();
00242 
00243                 if( !SDL_PollEvent( &event ) )
00244                 {
00245                         if( MessageServer::Instance().empty() )
00246                                 frame->IdleProcess();
00247                 }
00248                 else
00249                         HandleSDLEvent( event );
00250         }
00251         return IsRunning();
00252 }

void Ars::ArsApplication::SetDefaultFontEngine FontEngine pFontEngine  )  [inline]
 

Creates a font engine Sets the default font engine If a default font engine is not set, a valid font engine must be passed to any controls that display text

Definition at line 177 of file SdlArs.h.

References defaultFontEngine.

Referenced by Init().

00177 { defaultFontEngine = pFontEngine; }

void Ars::ArsApplication::SetKeyFocus MessageClient pWindow  ) 
 

This is for setting/getting the window that has the current keyboard focus Any KEYBOARD messages will have this window as their destination

Parameters:
pWindow A pointer to the window that should get focus

Definition at line 161 of file SdlArs.cpp.

References ArsPostMessage, and keyFocusWindow.

00162 {
00163         // notify the window that's losing focus to repaint itself
00164         if( keyFocusWindow != pWindow )
00165         {
00166                 if( keyFocusWindow )
00167                         ArsPostMessage( CtrlMessage( Message::LOST_FOCUS , keyFocusWindow , pWindow ) );
00168                 ArsPostMessage( Message( Message::SET_FOCUS , pWindow ) );
00169         }
00170         keyFocusWindow = pWindow;
00171 }

const bool Ars::ArsApplication::wmExit const Message msg  )  [protected, virtual]
 

This is called just before the application exits

Parameters:
iExitCode The exit code to return, defaults to EXIT_SUCCESS

Reimplemented from Ars::MessageClient.

Definition at line 193 of file SdlArs.cpp.

References exitCode, and running.

00194 {
00195         // push an event into the SDL queue so the SDLEventLoopThread can exit
00196         // the actual contents of the event are not a concern as it serves just to trigger the SDL_WaitEvent
00197         SDL_Event user_event;
00198         user_event.type=SDL_USEREVENT;
00199         user_event.user.code=0;
00200         user_event.user.data1=0;
00201         user_event.user.data2=0;
00202 //      DEBUG_ONLY(int iResult =) SDL_PushEvent(&user_event);
00203 //      TraceIf(EXIT_SUCCESS == -1, "ArsApplication::ApplicationExit - Unable to push SDL user_event.");
00204         exitCode = EXIT_SUCCESS;
00205         running = false;
00206         
00207         return true;
00208 }


Field Documentation

const int Ars::ArsApplication::argc [protected]
 

The argument count from the command line.

Definition at line 107 of file SdlArs.h.

char** Ars::ArsApplication::argv [protected]
 

The argument array from the command line.

Definition at line 108 of file SdlArs.h.

FontEngine* Ars::ArsApplication::defaultFontEngine [protected]
 

Definition at line 110 of file SdlArs.h.

Referenced by GetDefaultFontEngine(), and SetDefaultFontEngine().

int Ars::ArsApplication::exitCode [private]
 

Definition at line 100 of file SdlArs.h.

Referenced by ExitCode(), and wmExit().

View* Ars::ArsApplication::frame [protected]
 

Definition at line 112 of file SdlArs.h.

Referenced by Exec(), Borqueror::Init(), MainLoop(), and ~ArsApplication().

ArsApplication * Ars::ArsApplication::instance = 0 [static, private]
 

Definition at line 45 of file SdlArs.cpp.

Referenced by ArsApplication(), and GetInstance().

MessageClient* Ars::ArsApplication::keyFocusWindow [private]
 

A pointer to the window with keyboard focus.

Definition at line 103 of file SdlArs.h.

Referenced by GetKeyFocus(), and SetKeyFocus().

map< icstring, void * > Ars::ArsApplication::lbGetter [static]
 

Definition at line 41 of file SdlArs.cpp.

map< icstring, unsigned long > Ars::ArsApplication::Mnemo_f [static]
 

Definition at line 42 of file SdlArs.cpp.

Referenced by ArsApplication().

map< icstring, unsigned long > Ars::ArsApplication::Mnemo_s [static]
 

Definition at line 42 of file SdlArs.cpp.

Referenced by ArsApplication().

XPoint Ars::ArsApplication::mousexy [static]
 

Definition at line 254 of file SdlArs.cpp.

Referenced by HandleSDLEvent().

vector< cbObjCreateType > Ars::ArsApplication::objCreate [static]
 

Definition at line 43 of file SdlArs.cpp.

Referenced by ArsApplication().

bool Ars::ArsApplication::running [private]
 

Definition at line 101 of file SdlArs.h.

Referenced by Exec(), IsRunning(), and wmExit().

int Ars::ArsApplication::scrH [static]
 

Definition at line 117 of file SdlArs.h.

Referenced by Borqueror::GenDefaultCfg(), GetCoordStr(), Ars::Thing::Init(), and Ars::View::View().

int Ars::ArsApplication::scrW = 1280 Ars::ArsApplication::scrH = 1024 [static]
 

Definition at line 30 of file SdlArs.cpp.

Referenced by Borqueror::GenDefaultCfg(), GetCoordStr(), Ars::Thing::Init(), and Ars::View::View().


The documentation for this class was generated from the following files:
Generated on Fri Dec 5 04:06:41 2003 for Borqueror by doxygen 1.3.3