nomlib
Loading...
Searching...
No Matches
nom::SDLApp Class Reference

Convenience template class for video games. More...

#include <SDLApp.hpp>

Public Types

enum  Hints { OSX_DISABLE_MINIMIZE_ON_LOSS_FOCUS = 0x1 , OSX_DISABLE_FULLSCREEN_SPACES = 0x2 }
 An enumeration of platform or application scope features available for explicit request of enabling or disabling. More...
typedef SDLApp self_type
typedef self_type * raw_ptr
typedef std::shared_ptr< self_type > shared_ptr

Public Member Functions

 SDLApp (void)
 Default constructor; initialize with the default set of hints.
 SDLApp (uint32 flags)
bool app_state (void) const
virtual bool on_init (void)
virtual sint Run (void)
virtual void on_update (float)
 The application-level handler for logic.
virtual void on_draw (RenderWindow &)
 The application-level handler for rendering.
virtual bool running (void)
 Query status of the application state.
uint32 ticks (void)
 Obtain the current timestamp.
virtual void quit (void)
 End program execution.
void set_app_state (bool state)
bool show_fps (void) const
void set_show_fps (bool toggle)
bool toggle_fps (void)
StateMachinestate (void) const
void set_state_machine (StateMachine *mech)
void set_event_handler (EventHandler &evt_handler)
 Install the event handler used by the interface.

Protected Member Functions

virtual void on_input_event (const Event &ev)
 Default event handler for input events.
virtual void on_app_quit (const Event &ev)
 The event handler for when a request for halting program execution occurs.
virtual void on_window_shown (const Event &ev)
virtual void on_window_hidden (const Event &ev)
virtual void on_window_exposed (const Event &ev)
virtual void on_window_moved (const Event &ev)
virtual void on_window_resized (const Event &ev)
virtual void on_window_size_changed (const Event &ev)
virtual void on_window_minimized (const Event &ev)
virtual void on_window_maximized (const Event &ev)
virtual void on_window_restored (const Event &ev)
virtual void on_window_mouse_focus (const Event &ev)
virtual void on_window_mouse_focus_lost (const Event &ev)
virtual void on_window_keyboard_focus (const Event &ev)
virtual void on_window_keyboard_focus_lost (const Event &ev)
virtual void on_window_close (const Event &ev)
 The event handler for when a request for closing a window occurs.
virtual void on_drag_drop (const Event &ev)
virtual void on_render_targets_reset (const Event &ev)
virtual void on_user_event (const Event &ev)
 The default event handler for user-defined events.

Private Member Functions

bool initialize (uint32 flags)
void on_app_event (const Event &ev)
void process_event (const Event &ev)

Private Attributes

EventHandlerevent_handler_ = nullptr
std::unique_ptr< StateMachinestate_
 State machine manager.
bool app_state_
 Global application state.
bool show_fps_
 FPS counter.
Timer app_timer_
 Global application timer.

Detailed Description

Convenience template class for video games.

Note
http://docs.wxwidgets.org/trunk/classwx_app.html
http://doc.qt.digia.com/4.6/qapplication.html

Definition at line 51 of file SDLApp.hpp.

Member Typedef Documentation

◆ raw_ptr

typedef self_type* nom::SDLApp::raw_ptr

Definition at line 56 of file SDLApp.hpp.

◆ self_type

typedef SDLApp nom::SDLApp::self_type

Definition at line 54 of file SDLApp.hpp.

◆ shared_ptr

typedef std::shared_ptr<self_type> nom::SDLApp::shared_ptr

Definition at line 57 of file SDLApp.hpp.

Member Enumeration Documentation

◆ Hints

An enumeration of platform or application scope features available for explicit request of enabling or disabling.

Enumerator
OSX_DISABLE_MINIMIZE_ON_LOSS_FOCUS 

SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS.

OSX_DISABLE_FULLSCREEN_SPACES 

SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES.

Definition at line 61 of file SDLApp.hpp.

Constructor & Destructor Documentation

◆ SDLApp() [1/2]

nom::SDLApp::SDLApp ( void )

Default constructor; initialize with the default set of hints.

Remarks
The hints OSX_DISABLE_MINIMIZE_ON_LOSS_FOCUS and OSX_DISABLE_FULLSCREEN_SPACES are passed.

◆ SDLApp() [2/2]

nom::SDLApp::SDLApp ( uint32 flags)
See also
SDLApp::Hints enumeration.

Member Function Documentation

◆ on_app_quit()

virtual void nom::SDLApp::on_app_quit ( const Event & ev)
protectedvirtual

The event handler for when a request for halting program execution occurs.

Remarks
The default implementation calls nom::SDLApp::quit.
Note
This event handles the system's default quit handler, i.e.: COMMAND + Q on Mac OS X and ALT + F4 on Windows.

◆ on_drag_drop()

virtual void nom::SDLApp::on_drag_drop ( const Event & ev)
protectedvirtual

Drag 'N' Drop events

Remarks
To enable drag and drop events on Mac OS X, you must add the appropriate keys in your application bundle's Info.plist, like so:

<key>CFBundleDocumentTypes</key> <array> <dict> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleTypeName</key> <string>TTcards</string> <key>CFBundleTypeExtensions</key> <array> <string>json</string> </array> <key>CFBundleTypeIconFile</key> <string>TTcards</string> </dict> </array>

◆ on_draw()

virtual void nom::SDLApp::on_draw ( RenderWindow & )
virtual

The application-level handler for rendering.

Remarks
This method is called once every frame from within the main loop.
Todo
Consider removing RenderTarget argument; I think we can get away with this!

◆ on_render_targets_reset()

virtual void nom::SDLApp::on_render_targets_reset ( const Event & ev)
protectedvirtual
Remarks
This is applicable only to Direct3D renderers.

◆ on_update()

virtual void nom::SDLApp::on_update ( float )
virtual

The application-level handler for logic.

Remarks
This method is called once every frame from within the main loop.

◆ on_user_event()

virtual void nom::SDLApp::on_user_event ( const Event & ev)
protectedvirtual

The default event handler for user-defined events.

Remarks
This is applicable only to Direct3D renderers.

◆ on_window_close()

virtual void nom::SDLApp::on_window_close ( const Event & ev)
protectedvirtual

The event handler for when a request for closing a window occurs.

Remarks
The default implementation calls nom::SDLApp::on_app_quit.

◆ quit()

virtual void nom::SDLApp::quit ( void )
virtual

End program execution.

Note
Sets the internal class variable app_state_ to false.

◆ Run()

virtual sint nom::SDLApp::Run ( void )
virtual
Todo
Rename to exec..?

◆ running()

virtual bool nom::SDLApp::running ( void )
virtual

Query status of the application state.

Returns
Boolean true or false.
Remarks
The default handling of the application state is to end program execution upon a false result from this method.

◆ set_event_handler()

void nom::SDLApp::set_event_handler ( EventHandler & evt_handler)

Install the event handler used by the interface.

Remarks
The application's events will not be processed until a call is made to the event handler's ::poll_event method.
Note
The installed event handler must outlive the destruction of this interface!

◆ ticks()

uint32 nom::SDLApp::ticks ( void )

Obtain the current timestamp.

Returns
Number of ticks from the start of class construction.

◆ toggle_fps()

bool nom::SDLApp::toggle_fps ( void )

Helper method for toggling the state of nom::SDLApp::show_fps

Returns
State of nom::SDLApp::show_fps_ after call to nom::SDLApp::set_show_fps

Member Data Documentation

◆ app_state_

bool nom::SDLApp::app_state_
private

Global application state.

Definition at line 250 of file SDLApp.hpp.

◆ app_timer_

Timer nom::SDLApp::app_timer_
private

Global application timer.

Definition at line 256 of file SDLApp.hpp.

◆ event_handler_

EventHandler* nom::SDLApp::event_handler_ = nullptr
private

Definition at line 240 of file SDLApp.hpp.

◆ show_fps_

bool nom::SDLApp::show_fps_
private

FPS counter.

Definition at line 253 of file SDLApp.hpp.

◆ state_

std::unique_ptr<StateMachine> nom::SDLApp::state_
private

State machine manager.

Remarks
This object pointer must be initialized prior to use.
See also
SDLApp::set_state_machine

Definition at line 247 of file SDLApp.hpp.


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