Handle application window activation.

This detects the mouse button state upon activation and avoids the
messages regarding missed clicks.
This commit is contained in:
Mark de Wever 2010-12-12 19:09:09 +00:00
parent 525718197a
commit 2d2d9d3384
6 changed files with 84 additions and 4 deletions

View File

@ -10,6 +10,7 @@ Version 1.9.3+svn:
Quit Game/Editor)
* Miscellaneous and bugfixes:
* Fix --data-dir command line option
* Better detect mouse button state when window is activated.
Version 1.9.3:
* Campaigns:

View File

@ -359,6 +359,30 @@ template<
, queue_position);
}
template<
tevent sdl_button_down
, tevent sdl_button_up
, tevent button_down
, tevent button_up
, tevent button_click
, tevent button_double_click
> void tmouse_button<
sdl_button_down
, sdl_button_up
, button_down
, button_up
, button_click
, button_double_click
>::initialize_state(const bool is_down)
{
last_click_stamp_ = 0;
last_clicked_widget_ = NULL;
focus_ = 0;
is_down_ = is_down;
signal_handler_sdl_button_down_entered_ = false;
signal_handler_sdl_button_up_entered_ = false;
}
template<
tevent sdl_button_down
, tevent sdl_button_up
@ -533,9 +557,8 @@ template<
#define LOG_HEADER "distributor mouse motion [" << owner_.id() << "]: "
/**
* @todo At construction we should get the state and from that moment on we
* keep track of the changes ourselves, not yet sure what happens when an input
* blocker is used.
* @todo Test wehether the state is properly tracked when an input blocker is
* used.
*/
tdistributor::tdistributor(twidget& owner
, const tdispatcher::tposition queue_position)
@ -594,6 +617,8 @@ tdistributor::tdistributor(twidget& owner
, this
, _1
, _2));
initialize_state();
}
tdistributor::~tdistributor()
@ -630,6 +655,15 @@ tdistributor::~tdistributor()
, _2));
}
void tdistributor::initialize_state()
{
const Uint8 button_state = SDL_GetMouseState(NULL, NULL);
tmouse_button_left::initialize_state(button_state & SDL_BUTTON(1));
tmouse_button_middle::initialize_state(button_state & SDL_BUTTON(2));
tmouse_button_right::initialize_state(button_state & SDL_BUTTON(3));
}
void tdistributor::keyboard_capture(twidget* widget)
{
if(keyboard_focus_) {

View File

@ -164,6 +164,15 @@ public:
, twidget& owner
, const tdispatcher::tposition queue_position
);
/**
* Initializes the state of the button.
*
* @param is_down The initial state of the button, if true down
* else initialized as up.
*/
void initialize_state(const bool is_down);
protected:
/** The time of the last click used for double clicking. */
Uint32 last_click_stamp_;
@ -243,6 +252,13 @@ public:
~tdistributor();
/**
* Initializes the state of the keyboard and mouse.
*
* Needed after initialization and reactivation.
*/
void initialize_state();
/**
* Captures the keyboard input.
*

View File

@ -148,6 +148,14 @@ public:
private:
/**
* Reinitializes the state of all dispatchers.
*
* This is needed when the application gets activated, to make sure the
* state of mainly the mouse is set properly.
*/
void activate();
/***** Handlers *****/
/** Fires a draw event. */
@ -327,8 +335,11 @@ void thandler::handle_event(const SDL_Event& event)
}
#endif
// Silently ignored events.
case SDL_ACTIVEEVENT:
activate();
break;
// Silently ignored events.
case SDL_KEYUP:
case DOUBLE_CLICK_EVENT:
break;
@ -388,6 +399,15 @@ void thandler::disconnect(tdispatcher* dispatcher)
}
}
void thandler::activate()
{
foreach(tdispatcher* dispatcher, dispatchers_) {
dispatcher->fire(SDL_ACTIVATE
, dynamic_cast<twidget&>(*dispatcher)
, NULL);
}
}
void thandler::draw()
{
// Don't display this event since it floods the screen
@ -711,6 +731,7 @@ std::ostream& operator<<(std::ostream& stream, const tevent event)
case LOSE_KEYBOARD_FOCUS : stream << "lose keyboard focus"; break;
case SHOW_HOVER_TOOLTIP : stream << "show hover tooltip"; break;
case REMOVE_TOOLTIP : stream << "remove tooltip"; break;
case SDL_ACTIVATE : stream << "SDL activate"; break;
}
return stream;

View File

@ -110,6 +110,9 @@ enum tevent {
, LOSE_KEYBOARD_FOCUS /**< Widget loses keyboard focus. */
, SHOW_HOVER_TOOLTIP /**< Request to show the hover tooltip. */
, REMOVE_TOOLTIP /**< Request to remove a tooltip. */
, SDL_ACTIVATE /**<
* The main application window is activated.
*/
};
/**
@ -194,6 +197,7 @@ typedef
, boost::mpl::int_<LOSE_KEYBOARD_FOCUS>
, boost::mpl::int_<SHOW_HOVER_TOOLTIP>
, boost::mpl::int_<REMOVE_TOOLTIP>
, boost::mpl::int_<SDL_ACTIVATE>
>
tset_event_notification;

View File

@ -299,6 +299,10 @@ twindow::twindow(CVideo& video,
boost::bind(&twindow::signal_handler_sdl_video_resize
, this, _2, _3, _5));
connect_signal<event::SDL_ACTIVATE>(
boost::bind(&event::tdistributor::initialize_state
, event_distributor_));
connect_signal<event::SDL_LEFT_BUTTON_DOWN>(
boost::bind(
&twindow::signal_handler_click_dismiss, this, _2, _3, _4)