changeset 7:104dff305563

Added App::on_InputFocus and app::on_InputBlur to make sure the program does not receive mouse clicks when not in foreground. Added option in CmakeLists.txt to support compiling for gprof.
author Eris Caffee <discordia@eldalin.com>
date Mon, 15 Nov 2010 21:55:46 -0600
parents 6fe9214af151
children 4a0062095c37
files CMakeLists.txt include/App.h include/EventHandler.h src/App.cpp src/EventHandler.cpp
diffstat 5 files changed, 36 insertions(+), 4 deletions(-) [+]
line diff
     1.1 --- a/CMakeLists.txt	Sat Nov 13 00:39:47 2010 -0600
     1.2 +++ b/CMakeLists.txt	Mon Nov 15 21:55:46 2010 -0600
     1.3 @@ -118,6 +118,15 @@
     1.4  
     1.5  
     1.6  ################################################################################
     1.7 +
     1.8 +option(Option_Profile_Program "Build for gprof profiling." OFF)
     1.9 +if (Option_Profile_Program)
    1.10 +  add_definitions(-pg)
    1.11 +  set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
    1.12 +endif ()
    1.13 +
    1.14 +
    1.15 +################################################################################
    1.16  # The core project files 
    1.17  
    1.18  file (GLOB SRCS src/*.c src/*.cpp)
     2.1 --- a/include/App.h	Sat Nov 13 00:39:47 2010 -0600
     2.2 +++ b/include/App.h	Mon Nov 15 21:55:46 2010 -0600
     2.3 @@ -58,6 +58,8 @@
     2.4  
     2.5  
     2.6     // Overrides of EventHandler:
     2.7 +   void on_InputFocus();
     2.8 +   void on_InputBlur();
     2.9     void on_KeyDown(SDL_KeyboardEvent key);
    2.10     void on_KeyUp(SDL_KeyboardEvent key);
    2.11     void on_MouseMove(SDL_MouseMotionEvent motion);
     3.1 --- a/include/EventHandler.h	Sat Nov 13 00:39:47 2010 -0600
     3.2 +++ b/include/EventHandler.h	Mon Nov 15 21:55:46 2010 -0600
     3.3 @@ -38,9 +38,9 @@
     3.4     public:
     3.5  
     3.6     EventHandler();
     3.7 -   virtual ~EventHandler();
     3.8 +   virtual ~EventHandler() = 0;
     3.9  
    3.10 -   virtual void on_event(SDL_Event * event);
    3.11 +   virtual void on_Event(SDL_Event * event);
    3.12  
    3.13     // Active events
    3.14     virtual void on_MouseFocus();
     4.1 --- a/src/App.cpp	Sat Nov 13 00:39:47 2010 -0600
     4.2 +++ b/src/App.cpp	Mon Nov 15 21:55:46 2010 -0600
     4.3 @@ -96,7 +96,7 @@
     4.4        SDL_WaitEvent(&event);
     4.5        do
     4.6  	 {
     4.7 -	 on_event(&event);
     4.8 +	 on_Event(&event);
     4.9  	 }
    4.10        while (SDL_PollEvent(&event));
    4.11  
    4.12 @@ -113,6 +113,7 @@
    4.13  
    4.14  
    4.15  ////////////////////////////////////////////////////////////////////////////////
    4.16 +
    4.17  bool App::init()
    4.18     {
    4.19     if ((SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER)) == -1)
    4.20 @@ -222,6 +223,26 @@
    4.21  
    4.22  ////////////////////////////////////////////////////////////////////////////////
    4.23  
    4.24 +void App::on_InputFocus()
    4.25 +   {
    4.26 +   SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
    4.27 +   SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_ENABLE);
    4.28 +   SDL_EventState(SDL_MOUSEBUTTONUP, SDL_ENABLE);
    4.29 +   }
    4.30 +
    4.31 +
    4.32 +////////////////////////////////////////////////////////////////////////////////
    4.33 +
    4.34 +void App::on_InputBlur()
    4.35 +   {
    4.36 +   SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
    4.37 +   SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_IGNORE);
    4.38 +   SDL_EventState(SDL_MOUSEBUTTONUP, SDL_IGNORE);
    4.39 +   }
    4.40 +
    4.41 +
    4.42 +////////////////////////////////////////////////////////////////////////////////
    4.43 +
    4.44  void App::on_KeyDown(SDL_KeyboardEvent key)
    4.45     {
    4.46     switch (key.keysym.sym)
     5.1 --- a/src/EventHandler.cpp	Sat Nov 13 00:39:47 2010 -0600
     5.2 +++ b/src/EventHandler.cpp	Mon Nov 15 21:55:46 2010 -0600
     5.3 @@ -41,7 +41,7 @@
     5.4  
     5.5  
     5.6  ////////////////////////////////////////////////////////////////////////////////
     5.7 -void EventHandler::on_event(SDL_Event * event)
     5.8 +void EventHandler::on_Event(SDL_Event * event)
     5.9     {
    5.10     switch(event->type)
    5.11        {