Author: mordante
Date: Mon Mar 24 08:24:25 2008
New Revision: 25049
URL: http://svn.gna.org/viewcvs/wesnoth?rev=25049&view=rev
Log:
Let tevent_handler derive from events::handler and twindow derive from
tevent_handler instead of events::handler. This means that the event
handling is now done in tevent_handler instead of in twindow.
Modified:
trunk/src/gui/widgets/event_handler.cpp
trunk/src/gui/widgets/event_handler.hpp
trunk/src/gui/widgets/window.cpp
trunk/src/gui/widgets/window.hpp
Modified: trunk/src/gui/widgets/event_handler.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/event_handler.cpp?rev=25049&r1=25048&r2=25049&view=diff
==============================================================================
--- trunk/src/gui/widgets/event_handler.cpp (original)
+++ trunk/src/gui/widgets/event_handler.cpp Mon Mar 24 08:24:25 2008
@@ -20,8 +20,8 @@
#include "gui/widgets/event_handler.hpp"
#include "config.hpp"
-#include "events.hpp"
#include "gui/widgets/widget.hpp"
+#include "gui/widgets/window.hpp"
#include "log.hpp"
#include "serialization/parser.hpp"
#include "variable.hpp"
@@ -57,6 +57,8 @@
//! blocker is used.
tevent_handler::tevent_handler() :
// fixme get state at construction
+ events::handler(false), // don't join we haven't created a context yet
+ event_context_(),
mouse_x_(-1),
mouse_y_(-1),
mouse_left_button_down_(false),
@@ -77,23 +79,33 @@
assert(false);
}
}
-}
-
-void tevent_handler::handle_event(const SDL_Event& event, twidget* mouse_over)
-{
+
+ // The event context is created now we join it.
+ join();
+}
+
+void tevent_handler::handle_event(const SDL_Event& event)
+{
+
+ twidget* mouse_over = 0;
switch(event.type) {
case SDL_MOUSEMOTION:
mouse_x_ = event.motion.x;
mouse_y_ = event.motion.y;
+ mouse_over =
+
get_widget(get_window().client_position(tpoint(mouse_x_, mouse_y_)));
mouse_move(event, mouse_over);
+
break;
case SDL_MOUSEBUTTONDOWN:
mouse_x_ = event.button.x;
mouse_y_ = event.button.y;
+ mouse_over =
+
get_widget(get_window().client_position(tpoint(mouse_x_, mouse_y_)));
switch(event.button.button) {
case SDL_BUTTON_LEFT :
@@ -111,6 +123,8 @@
mouse_x_ = event.button.x;
mouse_y_ = event.button.y;
+ mouse_over =
+
get_widget(get_window().client_position(tpoint(mouse_x_, mouse_y_)));
switch(event.button.button) {
@@ -140,7 +154,6 @@
WRN_G_E << "Unhandled event " <<
static_cast<Uint32>(event.type) << ".\n";
break;
}
-
}
void tevent_handler::mouse_capture(const bool capture)
Modified: trunk/src/gui/widgets/event_handler.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/event_handler.hpp?rev=25049&r1=25048&r2=25049&view=diff
==============================================================================
--- trunk/src/gui/widgets/event_handler.hpp (original)
+++ trunk/src/gui/widgets/event_handler.hpp Mon Mar 24 08:24:25 2008
@@ -18,23 +18,39 @@
#ifndef __GUI_WIDGETS_EVENT_INFO_HPP_INCLUDED__
#define __GUI_WIDGETS_EVENT_INFO_HPP_INCLUDED__
+#include "events.hpp"
+
#include "SDL.h"
namespace gui2{
+class tpoint;
class twidget;
+class twindow;
-class tevent_handler
+class tevent_handler : public events::handler
{
public:
tevent_handler();
- void handle_event(const SDL_Event& event, twidget* mouse_over);
+ virtual ~tevent_handler() { leave(); }
+
+ void process_events() { events::pump(); }
+
+ //! Implement events::handler::handle_event().
+ void handle_event(const SDL_Event& event);
+
+ virtual twindow& get_window() = 0;
+
+ virtual twidget* get_widget(const tpoint& coordinate) = 0;
void mouse_capture(const bool capture = true);
private:
+ //! we create a new event context so we're always modal.
+ //! Maybe this has to change, but not sure yet.
+ events::event_context event_context_;
int mouse_x_; //! The current mouse x.
int mouse_y_; //! The current mouse y.
Modified: trunk/src/gui/widgets/window.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window.cpp?rev=25049&r1=25048&r2=25049&view=diff
==============================================================================
--- trunk/src/gui/widgets/window.cpp (original)
+++ trunk/src/gui/widgets/window.cpp Mon Mar 24 08:24:25 2008
@@ -51,11 +51,9 @@
twindow::twindow(CVideo& video,
const int x, const int y, const int w, const int h) :
tpanel(),
- events::handler(false), // don't join we haven't created a context yet
+ tevent_handler(),
video_(video),
status_(NEW),
- event_info_(),
- event_context_(),
need_layout_(true),
restorer_(),
canvas_background_(),
@@ -65,9 +63,6 @@
set_y(y);
set_width(w);
set_height(h);
-
- // The event context is created now we join it.
- join();
}
void twindow::show(const bool restore, void* /*flip_function*/)
@@ -88,7 +83,7 @@
// Start our loop drawing will happen here as well.
for(status_ = SHOWING; status_ != REQUEST_CLOSE; ) {
- events::pump();
+ process_events();
// fixme manual destroy
if(status_ == REQUEST_CLOSE) {
@@ -198,18 +193,6 @@
video_.flip();
}
-//! Implement events::handler::handle_event().
-void twindow::handle_event(const SDL_Event& event)
-{
- if(event.type == SDL_MOUSEBUTTONDOWN || event.type ==
SDL_MOUSEBUTTONUP) {
- event_info_.handle_event(event,
get_widget(tpoint(event.button.x - get_x(), event.button.y - get_y())));
- } else if (event.type == SDL_MOUSEMOTION) {
- event_info_.handle_event(event,
get_widget(tpoint(event.motion.x - get_x(), event.motion.y - get_y())));
- } else {
- event_info_.handle_event(event, 0);
- }
-}
-
void twindow::window_resize(tevent_handler&,
const unsigned new_width, const unsigned new_height)
{
@@ -221,7 +204,7 @@
void twindow::resolve_definition()
{
if(definition_ ==
std::vector<twindow_definition::tresolution>::const_iterator()) {
- definition_ = get_window(definition());
+ definition_ = gui2::get_window(definition());
canvas_background_ = definition_->background.canvas;
canvas_background_.set_width(get_width());
Modified: trunk/src/gui/widgets/window.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window.hpp?rev=25049&r1=25048&r2=25049&view=diff
==============================================================================
--- trunk/src/gui/widgets/window.hpp (original)
+++ trunk/src/gui/widgets/window.hpp Mon Mar 24 08:24:25 2008
@@ -23,6 +23,8 @@
#include "gui/widgets/event_handler.hpp"
#include "gui/widgets/grid.hpp"
#include "gui/widgets/settings.hpp"
+// The following due to tpoint.
+#include "gui/widgets/widget.hpp"
#include "sdl_utils.hpp"
#include "video.hpp"
@@ -47,16 +49,10 @@
// event aan ons te sturen, oftewel een movemove can dit genereren indien
gewenst
//
// mogelijk dit ook gebruiken in de toekomst als aansturing van flip()
-class twindow : public tpanel, public events::handler/*, public virtual
tevent_executor */
+class twindow : public tpanel, public tevent_handler
{
public:
twindow(CVideo& video, const int x, const int y, const int w, const int
h);
-
- ~twindow()
- {
- // We have to leave the event context before it's
destroyed.
- leave();
- }
// show the window
// The flip function is the disp_.flip() if ommitted the video_flip()
is used
@@ -71,6 +67,13 @@
void set_height(const unsigned height);
+ twindow& get_window() { return *this; }
+
+ twidget* get_widget(const tpoint& coordinate) { return
tgrid::get_widget(coordinate); }
+
+ tpoint client_position(const tpoint& screen_position) const
+ { return tpoint(screen_position.x - get_x(), screen_position.y
- get_y()); }
+
protected:
private:
@@ -80,17 +83,6 @@
CVideo& video_;
tstatus status_;
-
- tevent_handler event_info_;
-
- /***** The event processing stuff *****/
-
- //! we create a new event context so we're always modal.
- //! Maybe this has to change, but not sure yet.
- events::event_context event_context_;
-
- //! Implement events::handler::handle_event().
- void handle_event(const SDL_Event& event);
void window_resize(tevent_handler&,
const unsigned new_width, const unsigned new_height);
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits