gnash-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnash-dev] [PATCH] Make mouse events more responsive


From: Ivor Blockley
Subject: Re: [Gnash-dev] [PATCH] Make mouse events more responsive
Date: Wed, 26 Jul 2006 09:11:48 +1000 (EST)

Bastiaan, thanks for reviewing my patch.

> > +    buttons |= mask;
> > +    obj->setMouseButtons(buttons);
>
> Why call setMouseButtons() when you call notify_mouse_state below?

notify_mouse_state, as called from within the GTK GUI code, must be static.
Hence it can't directly set _mouse_buttons.

> Okay. Why not also remove _mouse_buttons?

It is possible. However the value of _mouse_buttons must be stored somewhere so
it can be modified by various "masks" (when a button is pressed for example).
The patch below is a revised patch which does remove _mouse_buttons from the
GUI code (instead m_mouse_buttons from server/movie_root is used along with
some additional interface functions). I believe this patch is an improvement
over the original despite the additional functions required in movie_root.

I welcome further suggestions.

__________________________________________________________

Index: gui/gtk.cpp
===================================================================
RCS file: /sources/gnash/gnash/gui/gtk.cpp,v
retrieving revision 1.13
diff -u -p -r1.13 gtk.cpp
--- gui/gtk.cpp 15 Jul 2006 16:02:23 -0000      1.13
+++ gui/gtk.cpp 25 Jul 2006 22:01:43 -0000
@@ -528,15 +528,10 @@ GtkGui::button_press_event(GtkWidget *co
                            const gpointer data)
 {
     GNASH_REPORT_FUNCTION;
-
     Gui *obj = static_cast<Gui *>(data);
-    int        mask = 1 << (event->button - 1);
-    int buttons = obj->getMouseButtons();
-    obj->setMouseButtons(buttons |= mask);
-    float scale = obj->getScale();
-    obj->setMouseX(int(event->x / scale));
-    obj->setMouseY(int(event->y / scale));
 
+    int        mask = 1 << (event->button - 1);
+    obj->notify_mouse_clicked(true, mask);
     return true;
 }
 
@@ -547,14 +542,9 @@ GtkGui::button_release_event(GtkWidget *
 {
     GNASH_REPORT_FUNCTION;
     Gui *obj = static_cast<Gui *>(data);
-    int        mask = 1 << (event->button - 1);
-    int buttons = obj->getMouseButtons();
-
-    obj->setMouseButtons(buttons &= ~mask);
-    float scale = obj->getScale();
-    obj->setMouseX(int(event->x / scale));
-    obj->setMouseY(int(event->y / scale));
 
+    int        mask = 1 << (event->button - 1);
+    obj->notify_mouse_clicked(false, mask);
     return true;
 }
 
@@ -567,9 +557,7 @@ GtkGui::motion_notify_event(GtkWidget *c
     Gui *obj = static_cast<Gui *>(data);
 
     float scale = obj->getScale();
-    obj->setMouseX(int(event->x / scale));
-    obj->setMouseY(int(event->y / scale));
-
+    obj->notify_mouse_moved(int(event->x / scale), int(event->y / scale));
     return true;
 }
 
Index: gui/gui.cpp
===================================================================
RCS file: /sources/gnash/gnash/gui/gui.cpp,v
retrieving revision 1.10
diff -u -p -r1.10 gui.cpp
--- gui/gui.cpp 15 Jul 2006 16:02:23 -0000      1.10
+++ gui/gui.cpp 25 Jul 2006 22:01:43 -0000
@@ -57,10 +57,7 @@ Gui::Gui() :
     _xid(0),
     _width(0),
     _height(0),
-    _mouse_x(0),
-    _mouse_y(0),
     _scale(1.0f),
-    _mouse_buttons(0),
     _depth(16)
 #if defined(FIX_I810_LOD_BIAS)
    ,_tex_lod_bias(-1.2f)
@@ -74,10 +71,7 @@ Gui::Gui(unsigned long xid, float scale,
     _xid(xid),
     _width(0),
     _height(0),
-    _mouse_x(0),
-    _mouse_y(0),
     _scale(scale),
-    _mouse_buttons(0),
     _depth(depth)
 #if defined(FIX_I810_LOD_BIAS)
    ,_tex_lod_bias(-1.2f)
@@ -191,6 +185,18 @@ Gui::menu_jump_backward()
     m->goto_frame(m->get_current_frame()-10);
 }
 
+void
+Gui::notify_mouse_moved(int x, int y) 
+{
+    get_current_root()->notify_mouse_moved(x, y);
+}
+
+void
+Gui::notify_mouse_clicked(bool mouse_pressed, int mask) 
+{
+    get_current_root()->notify_mouse_clicked(mouse_pressed, mask);
+}
+
 bool
 Gui::advance_movie(void *data)
 {
@@ -199,9 +205,6 @@ Gui::advance_movie(void *data)
     Gui *gui = reinterpret_cast<Gui*> (data);
     gnash::movie_interface* m = gnash::get_current_root();
 
-//     log_msg("Mouse(x,y): %d,%d", gui->getMouseX(), gui->getMouseY());
-    m->notify_mouse_state(gui->getMouseX(), gui->getMouseY(), 
gui->getMouseButtons());
-
     m->advance(1.0);
     m->display();
     
Index: gui/gui.h
===================================================================
RCS file: /sources/gnash/gnash/gui/gui.h,v
retrieving revision 1.7
diff -u -p -r1.7 gui.h
--- gui/gui.h   15 Jul 2006 16:02:23 -0000      1.7
+++ gui/gui.h   25 Jul 2006 22:01:43 -0000
@@ -70,12 +70,6 @@ public:
     virtual bool setupEvents() = 0;
     virtual void renderBuffer() = 0;
 
-    void setMouseX(int x)           { _mouse_x = x; }
-    void setMouseY(int y)           { _mouse_y= y; }
-    void setMouseButtons(int mask)  { _mouse_buttons = mask; }
-    int getMouseX()                 { return _mouse_x; }
-    int getMouseY()                 { return _mouse_y; }
-    int getMouseButtons()           { return _mouse_buttons; }
     float getScale()                { return _scale; }
     bool loops()                    { return _loop; }
 
@@ -92,6 +86,8 @@ public:
     static void menu_step_backward();
     static void menu_jump_forward();
     static void menu_jump_backward();
+    static void notify_mouse_moved(int x, int y);
+    static void notify_mouse_clicked(bool mouse_pressed, int mask);
     static bool advance_movie(void *data);
     static void resize_view(int width, int height);
 
@@ -100,10 +96,7 @@ protected:
     unsigned long   _xid;
     int             _width;
     int             _height;
-    int             _mouse_x;
-    int             _mouse_y;
     float           _scale;
-    int             _mouse_buttons;
     int             _depth;
     std::string     _name;
     callback_t      _mouse_handler;
Index: gui/sdl.cpp
===================================================================
RCS file: /sources/gnash/gnash/gui/sdl.cpp,v
retrieving revision 1.9
diff -u -p -r1.9 sdl.cpp
--- gui/sdl.cpp 15 Jul 2006 16:02:23 -0000      1.9
+++ gui/sdl.cpp 25 Jul 2006 22:01:43 -0000
@@ -84,6 +84,9 @@ bool
 SDLGui::run(void *arg)
 {
     GNASH_REPORT_FUNCTION;
+    int x_old = -1;
+    int y_old = -1;
+    int button_state_old = -1;
 
     SDL_Event  event;
     while (true) {
@@ -97,17 +100,25 @@ SDLGui::run(void *arg)
 
         switch (event.type) {
           case SDL_MOUSEMOTION:
-            _mouse_x = (int) (event.motion.x / _scale);
-            _mouse_y = (int) (event.motion.y / _scale);
+            // SDL can generate MOUSEMOTION events even without mouse movement
+            if (event.motion.x == x_old && event.motion.y == y_old) { break; }
+            x_old = event.motion.x;
+            y_old = event.motion.y;
+            notify_mouse_moved((int) (x_old / _scale), (int) (y_old / _scale));
             break;
           case SDL_MOUSEBUTTONDOWN:
           case SDL_MOUSEBUTTONUP:
           {
             int        mask = 1 << (event.button.button - 1);
             if (event.button.state == SDL_PRESSED) {
-                _mouse_buttons |= mask;
+                // multiple events will be fired while the mouse is held down
+                // we are interested only in a change in the mouse state:
+                if (event.button.button == button_state_old) { break; }
+                notify_mouse_clicked(true, mask);
+                button_state_old = event.button.button;
             } else {
-                _mouse_buttons &= ~mask;
+                notify_mouse_clicked(false, mask);
+                button_state_old = -1;
             }
             break;
           }
Index: server/movie.h
===================================================================
RCS file: /sources/gnash/gnash/server/movie.h,v
retrieving revision 1.11
diff -u -p -r1.11 movie.h
--- server/movie.h      28 Jun 2006 23:27:44 -0000      1.11
+++ server/movie.h      25 Jul 2006 22:01:44 -0000
@@ -226,6 +226,22 @@ struct movie : public movie_interface
        }
 
        /// \brief
+        /// The host app can use this to tell the movie when
+        /// user's mouse pointer has moved.
+        virtual void notify_mouse_moved(int /*x*/, int /*y*/)
+        {
+           GNASH_REPORT_FUNCTION;
+        }
+
+       /// \brief
+        /// The host app can use this to tell the movie when a
+        /// button on the user's mouse has been pressed or released.
+        /// Set mouse_pressed to true on click, false on release.
+        virtual void notify_mouse_clicked(bool /*mouse_pressed*/, int /*mask*/)
+        {
+           GNASH_REPORT_FUNCTION;
+        }
+       /// \brief
        /// The host app uses this to tell the movie where the
        /// user's mouse pointer is.
        virtual void notify_mouse_state(int /*x*/, int /*y*/, int /*buttons*/)
Index: server/movie_interface.h
===================================================================
RCS file: /sources/gnash/gnash/server/movie_interface.h,v
retrieving revision 1.3
diff -u -p -r1.3 movie_interface.h
--- server/movie_interface.h    28 Jun 2006 23:27:44 -0000      1.3
+++ server/movie_interface.h    25 Jul 2006 22:01:44 -0000
@@ -100,6 +100,8 @@ struct movie_interface : public as_objec
        virtual void    set_display_viewport(int x0, int y0, int w, int h) = 0;
        
        /// Input.
+        virtual void    notify_mouse_moved(int x, int y) = 0;
+        virtual void    notify_mouse_clicked(bool mouse_pressed, int mask) = 0;
        virtual void    notify_mouse_state(int x, int y, int buttons) = 0;
        
        /// Set an ActionScript variable within this movie.
Index: server/movie_root.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/movie_root.cpp,v
retrieving revision 1.7
diff -u -p -r1.7 movie_root.cpp
--- server/movie_root.cpp       10 Jul 2006 13:47:12 -0000      1.7
+++ server/movie_root.cpp       25 Jul 2006 22:01:45 -0000
@@ -115,16 +115,46 @@ movie_root::set_display_viewport(int x0,
     m_pixel_scale = fmax(scale_x, scale_y);
 }
 
+void
+movie_root::notify_mouse_moved(int x, int y)
+{
+    m_mouse_x = x;
+    m_mouse_y = y;
+    fire_mouse_event();
+}
+
+void
+movie_root::notify_mouse_clicked(bool mouse_pressed, int button_mask)
+{
+    if (mouse_pressed) {
+        m_mouse_buttons |= button_mask;
+    } else {
+        m_mouse_buttons &= ~button_mask;
+    }
+    fire_mouse_event();
+}
 
 void
 movie_root::notify_mouse_state(int x, int y, int buttons)
 {
-//         GNASH_REPORT_FUNCTION;
-//             dbglogfile << "X is: " << x << " Y is: " << y << " Button is: "
-//                        << buttons << endl;
     m_mouse_x = x;
     m_mouse_y = y;
     m_mouse_buttons = buttons;
+    fire_mouse_event();
+}
+
+void
+movie_root::fire_mouse_event()
+{
+//         GNASH_REPORT_FUNCTION;
+//             dbglogfile << "X is: " << x << " Y is: " << y << " Button is: "
+//                        << buttons << endl;
+
+    // Generate a mouse event
+    m_mouse_button_state.m_topmost_entity =
+        m_movie->get_topmost_mouse_entity(PIXELS_TO_TWIPS(m_mouse_x),
PIXELS_TO_TWIPS(m_mouse_y));
+    m_mouse_button_state.m_mouse_button_state_current = (m_mouse_buttons & 1);
+    generate_mouse_button_events(&m_mouse_button_state);
 }
 
 void
@@ -219,12 +249,6 @@ movie_root::advance(float delta_time)
         }
     }
                        
-    // Handle the mouse.
-    m_mouse_button_state.m_topmost_entity =
-        m_movie->get_topmost_mouse_entity(PIXELS_TO_TWIPS(m_mouse_x),
PIXELS_TO_TWIPS(m_mouse_y));
-    m_mouse_button_state.m_mouse_button_state_current = (m_mouse_buttons & 1);
-    generate_mouse_button_events(&m_mouse_button_state);
-
 // m_movie->advance(delta_time);
 
                // Vitaly:
Index: server/movie_root.h
===================================================================
RCS file: /sources/gnash/gnash/server/movie_root.h,v
retrieving revision 1.6
diff -u -p -r1.6 movie_root.h
--- server/movie_root.h 10 Jul 2006 13:47:12 -0000      1.6
+++ server/movie_root.h 25 Jul 2006 22:01:47 -0000
@@ -112,7 +112,16 @@ public:
 
        void set_display_viewport(int x0, int y0, int w, int h);
 
-       /// The host app uses this to tell the movie where the
+       /// The host app can use this to tell the movie when
+       /// user's mouse pointer has moved.
+        void notify_mouse_moved(int x, int y);
+
+       /// The host app can use this to tell the movie when a
+       /// button on the user's mouse has been pressed or released.
+        /// Set mouse_pressed to true on click, false on release.
+        void notify_mouse_clicked(bool mouse_pressed, int mask);
+
+       /// The host app can use this to tell the movie where the
        /// user's mouse pointer is.
        void notify_mouse_state(int x, int y, int buttons);
 
@@ -251,6 +260,9 @@ public:
        movie* get_active_entity();
        void set_active_entity(movie* ch);
 
+private:
+        void fire_mouse_event();
+
 };
 
__________________________________________________________

Send instant messages to your online friends http://au.messenger.yahoo.com 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]