gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r12290: Clean up mouse event handlin


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r12290: Clean up mouse event handling. Add support for onMouseWheel, implemented only
Date: Sat, 10 Jul 2010 12:57:31 +0200
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 12290 [merge]
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Sat 2010-07-10 12:57:31 +0200
message:
  Clean up mouse event handling. Add support for onMouseWheel, implemented only
  in gtk.
modified:
  gui/Kde4Glue.cpp
  gui/aos4.cpp
  gui/fb.cpp
  gui/fltk.cpp
  gui/gtk.cpp
  gui/gui.cpp
  gui/gui.h
  gui/haiku.cpp
  gui/kde.cpp
  gui/pythonmod/gnash-view.cpp
  gui/sdl.cpp
  libcore/DisplayObject.cpp
  libcore/MouseButtonState.h
  libcore/TextField.cpp
  libcore/movie_root.cpp
  libcore/movie_root.h
  testsuite/MovieTester.cpp
  testsuite/MovieTester.h
  testsuite/misc-ming.all/SpriteButtonEventsTest-Runner.cpp
  testsuite/misc-ming.all/SpriteButtonEventsTest.c
=== modified file 'gui/Kde4Glue.cpp'
--- a/gui/Kde4Glue.cpp  2010-03-22 20:48:47 +0000
+++ b/gui/Kde4Glue.cpp  2010-07-10 08:30:45 +0000
@@ -50,7 +50,7 @@
 DrawingWidget::mouseMoveEvent(QMouseEvent *event)
 {
     QPoint position = event->pos();
-    _gui.notify_mouse_moved(position.x(), position.y());
+    _gui.notifyMouseMove(position.x(), position.y());
 }
 
 
@@ -64,14 +64,14 @@
 void
 DrawingWidget::mousePressEvent(QMouseEvent* /* event */)
 {
-    _gui.notify_mouse_clicked(true, 1);
+    _gui.notifyMouseClick(true);
 }
 
 
 void
 DrawingWidget::mouseReleaseEvent(QMouseEvent* /* event */)
 {
-    _gui.notify_mouse_clicked(false, 1);
+    _gui.notifyMouseClick(false);
 }
 
 

=== modified file 'gui/aos4.cpp'
--- a/gui/aos4.cpp      2010-02-23 16:53:29 +0000
+++ b/gui/aos4.cpp      2010-07-10 08:30:45 +0000
@@ -511,7 +511,7 @@
                                        if ( _window->GZZMouseX == x_old && 
_window->GZZMouseY == y_old) { break; }
                                                        x_old = 
_window->GZZMouseX;
                                                        y_old = 
_window->GZZMouseY;
-                                       notify_mouse_moved(x_old, y_old);
+                                       notifyMouseMove(x_old, y_old);
                                    }
                            break;
                            case IDCMP_MOUSEBUTTONS:
@@ -522,11 +522,11 @@
                                                        {
                                                            case SELECTDOWN:
                                                    if (imsg->Code == 
button_state_old) { break; }
-                                               notify_mouse_clicked(true, 1);
+                                               notifyMouseClick(true);
                                                    button_state_old = 
imsg->Code;
                                                        break;
                                                            case SELECTUP:
-                                           notify_mouse_clicked(false, 1);
+                                           notifyMouseClick(false);
                                                            button_state_old = 
-1;
                                                            break;
                                                        }
@@ -877,4 +877,4 @@
 #endif
                                                "\n\nCopyright (C) 2005, 2006, 
2007, "
                                "2008, 2009, 2010 The Free Software Foundation"
-                                               "\n\nAmigaOS4 Version by Andrea 
Palmat
\ No newline at end of file
+                                               "\n\nAmigaOS4 Version by Andrea 
Palmat

=== modified file 'gui/fb.cpp'
--- a/gui/fb.cpp        2010-02-02 09:35:55 +0000
+++ b/gui/fb.cpp        2010-07-10 08:30:45 +0000
@@ -892,13 +892,13 @@
     
     //log_debug(_("mouse @ %d / %d, btn %d"), mouse_x, mouse_y, mouse_btn);
     
-    notify_mouse_moved(mouse_x, mouse_y);
+    notifyMouseMove(mouse_x, mouse_y);
     
     // button
     if (btn != mouse_btn) {
       mouse_btn = btn;
 printf("clicked: %d\n", btn);      
-      notify_mouse_clicked(btn, 1);  // mark=??
+      notifyMouseClick(btn);  // mark=??
       //log_debug(_("mouse click! %d"), btn);
     }    
 
@@ -1001,14 +1001,14 @@
     if ((new_x!=mouse_x) || (new_y!=mouse_y)) {
       mouse_x = new_x;
       mouse_y = new_y;
-      notify_mouse_moved(mouse_x, mouse_y);
+      notifyMouseMove(mouse_x, mouse_y);
       activity = true;
     }
     
     if (new_btn != mouse_btn) {
       mouse_btn = new_btn;      
 printf("clicked: %d\n", mouse_btn);      
-      notify_mouse_clicked(mouse_btn, 1);  // mask=?
+      notifyMouseClick(mouse_btn);  // mask=?
       activity = true;
     }
     
@@ -1157,9 +1157,9 @@
   static int new_mouse_y = 0;
   static int new_mouse_btn = 0;
   
-  int notify_x=0;     // coordinate to be sent via notify_mouse_moved()
+  int notify_x=0;     // coordinate to be sent via notifyMouseMove()
   int notify_y=0;
-  bool move_pending = false;  // true: notify_mouse_moved() should be called
+  bool move_pending = false;  // true: notifyMouseMove() should be called
   
   // this is necessary for our quick'n'dirty touchscreen calibration: 
   static int coordinatedebug = std::getenv("DUMP_RAW")!=NULL;
@@ -1187,9 +1187,9 @@
         else
           { cx=mouse_x; cy=mouse_y; }
               
-        // Don't call notify_mouse_moved() here because this would lead to
+        // Don't call notifyMouseMove() here because this would lead to
         // lots of calls, especially for touchscreens. Instead we save the
-        // coordinate and call notify_mouse_moved() only once.
+        // coordinate and call notifyMouseMove() only once.
         notify_x = cx;
         notify_y = cy;
         move_pending = true;        
@@ -1198,13 +1198,13 @@
       if (new_mouse_btn != mouse_btn) {
       
         if (move_pending) {
-          notify_mouse_moved(notify_x, notify_y);
+          notifyMouseMove(notify_x, notify_y);
           activity = true;
           move_pending = false;
         }
       
         mouse_btn = new_mouse_btn;
-        notify_mouse_clicked(mouse_btn, 1);  // mark=??
+        notifyMouseClick(mouse_btn);  // mark=??
         activity = true;
       }
 
@@ -1240,7 +1240,7 @@
   } 
   
   if (move_pending) {
-    notify_mouse_moved(notify_x, notify_y);
+    notifyMouseMove(notify_x, notify_y);
     activity = true;
   }
   

=== modified file 'gui/fltk.cpp'
--- a/gui/fltk.cpp      2010-01-11 06:41:38 +0000
+++ b/gui/fltk.cpp      2010-07-10 08:30:45 +0000
@@ -106,18 +106,18 @@
         return true;
       case PUSH:
         Window::handle(event);
-        notify_mouse_clicked(true, 1);
+        notifyMouseClick(true);
         return true;
       case RELEASE:
         Window::handle(event);
-        notify_mouse_clicked(false, 1);
+        notifyMouseClick(false);
         return true;
       case MOVE:
       {
         if (!_xid && event_y() < static_cast<int>(_menu_height)) {
           return Window::handle(event);
         }
-        notify_mouse_moved(event_x(), event_y()-_menu_height);
+        notifyMouseMove(event_x(), event_y()-_menu_height);
         return Window::handle(event);
       }
       case SHORTCUT:

=== modified file 'gui/gtk.cpp'
--- a/gui/gtk.cpp       2010-05-21 01:26:20 +0000
+++ b/gui/gtk.cpp       2010-07-10 09:22:49 +0000
@@ -132,6 +132,8 @@
                                        gpointer data);
     gboolean buttonReleaseEvent(GtkWidget *widget, GdkEventButton *event,
                                          gpointer data);
+    gboolean mouseWheelEvent(GtkWidget *widget, GdkEventScroll *event,
+                                       gpointer data);
     gboolean motionNotifyEvent(GtkWidget *widget, GdkEventMotion *event,
                                         gpointer data);
     gint popupHandler(GtkWidget *widget, GdkEvent *event);    
@@ -646,6 +648,8 @@
                    G_CALLBACK(buttonReleaseEvent), this);
     g_signal_connect(_canvas, "motion_notify_event",
                    G_CALLBACK(motionNotifyEvent), this);
+    g_signal_connect(_canvas, "scroll_event",
+                   G_CALLBACK(mouseWheelEvent), this);
   
     g_signal_connect_after(_canvas, "realize",
                          G_CALLBACK (realizeEvent), NULL);
@@ -2513,6 +2517,30 @@
 }
 
 gboolean
+mouseWheelEvent(GtkWidget *const /*widget*/, GdkEventScroll* const event,
+        const gpointer data)
+{
+    assert(event->type == GDK_SCROLL);
+    GtkGui *obj = static_cast<GtkGui*>(data);
+
+    obj->grabFocus();
+
+    switch (event->direction) {
+        case GDK_SCROLL_UP:
+            obj->notifyMouseWheel(1);
+            break;
+        case GDK_SCROLL_DOWN:
+            obj->notifyMouseWheel(-1);
+            break;
+        default:
+            break;
+    }
+
+
+    return true;
+}
+
+gboolean
 buttonPressEvent(GtkWidget *const /*widget*/, GdkEventButton *const event,
         const gpointer data)
 {
@@ -2524,20 +2552,16 @@
     GtkGui *obj = static_cast<GtkGui*>(data);
 
     obj->grabFocus();
-
-    int    mask = 1 << (event->button - 1);
-    obj->notify_mouse_clicked(true, mask);
+    obj->notifyMouseClick(true);
     return true;
 }
 
 gboolean
 buttonReleaseEvent(GtkWidget * const /*widget*/,
-     GdkEventButton * const event, const gpointer data)
+     GdkEventButton* const /*event*/, const gpointer data)
 {
     Gui *obj = static_cast<Gui*>(data);
-
-    int    mask = 1 << (event->button - 1);
-    obj->notify_mouse_clicked(false, mask);
+    obj->notifyMouseClick(false);
     return true;
 }
 
@@ -2547,7 +2571,7 @@
 {
     Gui *obj = static_cast<Gui *>(data);
 
-    obj->notify_mouse_moved(event->x, event->y);
+    obj->notifyMouseMove(event->x, event->y);
     return true;
 }
 

=== modified file 'gui/gui.cpp'
--- a/gui/gui.cpp       2010-06-22 06:15:01 +0000
+++ b/gui/gui.cpp       2010-07-10 09:22:49 +0000
@@ -457,7 +457,7 @@
 
 
 void
-Gui::notify_mouse_moved(int ux, int uy) 
+Gui::notifyMouseMove(int ux, int uy) 
 {
        movie_root* m = _stage;
 
@@ -475,7 +475,7 @@
        log_debug(_("mouse @ %d,%d"), x, y);
 #endif
 
-       if ( m->notify_mouse_moved(x, y) )
+       if ( m->mouseMoved(x, y) )
        {
                // any action triggered by the
                // event required screen refresh
@@ -512,17 +512,31 @@
 }
 
 void
-Gui::notify_mouse_clicked(bool mouse_pressed, int mask) 
-{
-       movie_root* m = _stage;
-       assert(m);
-
-    if ( ! _started ) return;
-
-    if ( _stopped ) return;
-
-       if ( m->notify_mouse_clicked(mouse_pressed, mask) )
-       {
+Gui::notifyMouseWheel(int delta)
+{
+       movie_root* m = _stage;
+       assert(m);
+
+    if (!_started) return;
+    if (_stopped) return;
+
+       if (m->mouseWheel(delta)) {
+               // any action triggered by the
+               // event required screen refresh
+               display(m);
+       }
+} 
+
+void
+Gui::notifyMouseClick(bool mouse_pressed) 
+{
+       movie_root* m = _stage;
+       assert(m);
+
+    if (!_started) return;
+    if (_stopped) return;
+
+       if (m->mouseClick(mouse_pressed)) {
                // any action triggered by the
                // event required screen refresh
                display(m);
@@ -625,7 +639,7 @@
                       int newx = _xpointer;
                       int newy = _ypointer-step;
                       if ( newy < 0 ) newy=0;
-                      notify_mouse_moved(newx, newy);
+                      notifyMouseMove(newx, newy);
                       break;
                   }
                   case gnash::key::DOWN:
@@ -633,7 +647,7 @@
                       int newx = _xpointer;
                       int newy = _ypointer+step;
                       if ( newy >= _height ) newy = _height-1;
-                      notify_mouse_moved(newx, newy);
+                      notifyMouseMove(newx, newy);
                       break;
                   }
                   case gnash::key::LEFT:
@@ -641,7 +655,7 @@
                       int newx = _xpointer-step;
                       int newy = _ypointer;
                       if ( newx < 0 ) newx = 0;
-                      notify_mouse_moved(newx, newy);
+                      notifyMouseMove(newx, newy);
                       break;
                   }
                   case gnash::key::RIGHT:
@@ -649,7 +663,7 @@
                       const int newy = _ypointer;
                       int newx = _xpointer + step;
                       if ( newx >= _width ) newx = _width-1;
-                      notify_mouse_moved(newx, newy);
+                      notifyMouseMove(newx, newy);
                       break;
                   }
                   default:

=== modified file 'gui/gui.h'
--- a/gui/gui.h 2010-04-25 17:49:43 +0000
+++ b/gui/gui.h 2010-07-10 09:22:49 +0000
@@ -286,18 +286,22 @@
 
     /// Mouse notification callback to be called when the mouse is moved.
     //
-    /// @param x The mouse coordinate X component in user/window coordinate 
space (pixels).
-    /// @param y The mouse coordinate Y component in user/window coordinate 
space (pixels).
-    ///
-    void notify_mouse_moved(int x, int y);
+    /// @param x    The mouse coordinate X component in user/window
+    ///             coordinate space (pixels).
+    /// @param y    The mouse coordinate Y component in user/window
+    ///             coordinate space (pixels).
+    void notifyMouseMove(int x, int y);
 
     /// Mouse notification callback to be called when the mouse is clicked.
     //
     /// @param mouse_pressed Determines whether the mouse button is being
     ///                      pressed (true) or being released (false)
-    /// @param mask A binary representation of the buttons currently pressed.
-    ///
-    void notify_mouse_clicked(bool mouse_pressed, int mask);
+    void notifyMouseClick(bool mouse_pressed);
+
+    /// Send a mouse wheel event to the stage.
+    //
+    /// @param delta    A number expressing the extent of the wheel scroll.
+    void notifyMouseWheel(int delta);
 
     /// Key event notification to be called when a key is pressed or depressed
     //

=== modified file 'gui/haiku.cpp'
--- a/gui/haiku.cpp     2010-02-16 20:28:47 +0000
+++ b/gui/haiku.cpp     2010-07-10 08:30:45 +0000
@@ -170,7 +170,7 @@
         {
             case GNASH_PULSE:
                 if (_mouse_moves_this_pulse > 3)
-                    _gui->notify_mouse_moved(_mousemovedx, _mousemovedy);
+                    _gui->notifyMouseMove(_mousemovedx, _mousemovedy);
                 _mouse_moves_this_pulse = 0;
                 _gui->GnashPulse();
                 break;
@@ -208,7 +208,7 @@
                     || B_OK != msg->FindInt32("mask", &mask))
                     QQ(1);
                 else
-                    _gui->notify_mouse_clicked(pressed, mask);
+                    _gui->notifyMouseClick(pressed);
                 break;
             }
             case GNASH_MOUSE_MOVED:
@@ -225,7 +225,7 @@
                         _mousemovedx = x;
                         _mousemovedy = y;
                     } else
-                        _gui->notify_mouse_moved(x, y);
+                        _gui->notifyMouseMove(x, y);
                 }
                 break;
             }

=== modified file 'gui/kde.cpp'
--- a/gui/kde.cpp       2010-02-23 17:40:25 +0000
+++ b/gui/kde.cpp       2010-07-10 08:30:45 +0000
@@ -406,7 +406,7 @@
     assert(_godfather);
     QPoint position = event->pos();
 
-    _godfather->notify_mouse_moved(position.x(), position.y());
+    _godfather->notifyMouseMove(position.x(), position.y());
 }
 
 qwidget::qwidget(KdeGui* godfather)
@@ -454,13 +454,13 @@
 void
 qwidget::mousePressEvent(QMouseEvent* /* event */)
 {
-    _godfather->notify_mouse_clicked(true, 1);
+    _godfather->notifyMouseClick(true);
 }
 
 void
 qwidget::mouseReleaseEvent(QMouseEvent* /* event */)
 {
-    _godfather->notify_mouse_clicked(false, 1);
+    _godfather->notifyMouseClick(false);
 }
 
 void

=== modified file 'gui/pythonmod/gnash-view.cpp'
--- a/gui/pythonmod/gnash-view.cpp      2010-05-27 20:57:35 +0000
+++ b/gui/pythonmod/gnash-view.cpp      2010-07-10 10:57:31 +0000
@@ -361,22 +361,21 @@
 
     gtk_widget_grab_focus(GTK_WIDGET(view->canvas));
 
-    int        mask = 1 << (event->button - 1);
-    view->stage->notify_mouse_clicked(true, mask);
+    view->stage->mouseClick(true);
 
     return TRUE;
 }
 
 static gboolean
-button_release_event_cb(GtkWidget */*widget*/, GdkEventButton *event, gpointer 
data)
+button_release_event_cb(GtkWidget* /*widget*/, GdkEventButton* /*event*/,
+        gpointer data)
 {
     GNASH_REPORT_FUNCTION;
     GnashView *view = GNASH_VIEW(data);
     if (view->stage.get() == NULL)
         return FALSE;
 
-    int        mask = 1 << (event->button - 1);
-    view->stage->notify_mouse_clicked(false, mask);
+    view->stage->mouseClick(false);
 
     return TRUE;
 }
@@ -397,7 +396,7 @@
        // A stage pseudopixel is user pixel / _yscale high
        boost::int32_t y = event->y / yscale;
 
-       if ( view->stage->notify_mouse_moved(x, y) )
+       if ( view->stage->mouseMoved(x, y) )
        {
                // any action triggered by the
                // event required screen refresh

=== modified file 'gui/sdl.cpp'
--- a/gui/sdl.cpp       2010-01-11 06:41:38 +0000
+++ b/gui/sdl.cpp       2010-07-10 08:30:45 +0000
@@ -87,21 +87,20 @@
                 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(x_old, y_old);
+                notifyMouseMove(x_old, y_old);
                 break;
 
             case SDL_MOUSEBUTTONDOWN:
             case SDL_MOUSEBUTTONUP:
             {
-                int     mask = 1 << (event.button.button - 1);
                 if (event.button.state == SDL_PRESSED) {
                     // 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);
+                    notifyMouseClick(true);
                     button_state_old = event.button.button;
                 } else {
-                    notify_mouse_clicked(false, mask);
+                    notifyMouseClick(false);
                     button_state_old = -1;
                 }
                 break;

=== modified file 'libcore/DisplayObject.cpp'
--- a/libcore/DisplayObject.cpp 2010-07-05 08:32:15 +0000
+++ b/libcore/DisplayObject.cpp 2010-07-10 09:22:06 +0000
@@ -1305,8 +1305,8 @@
 getMouseX(DisplayObject& o)
 {
        // Local coord of mouse IN PIXELS.
-       boost::int32_t x, y, buttons;
-       getRoot(*getObject(&o)).get_mouse_state(x, y, buttons);
+       boost::int32_t x, y;
+       getRoot(*getObject(&o)).get_mouse_state(x, y);
 
        SWFMatrix m = o.getWorldMatrix();
     point a(pixelsToTwips(x), pixelsToTwips(y));
@@ -1319,8 +1319,8 @@
 getMouseY(DisplayObject& o)
 {
        // Local coord of mouse IN PIXELS.
-       boost::int32_t x, y, buttons;
-       getRoot(*getObject(&o)).get_mouse_state(x, y, buttons);
+       boost::int32_t x, y;
+       getRoot(*getObject(&o)).get_mouse_state(x, y);
 
        SWFMatrix m = o.getWorldMatrix();
     point a(pixelsToTwips(x), pixelsToTwips(y));

=== modified file 'libcore/MouseButtonState.h'
--- a/libcore/MouseButtonState.h        2009-11-04 12:25:48 +0000
+++ b/libcore/MouseButtonState.h        2010-07-10 08:16:17 +0000
@@ -23,12 +23,6 @@
 
 public:
 
-       /// Possible button states
-       enum State {
-        UP,
-        DOWN
-    };  
-
        /// entity that currently owns the mouse pointer
        InteractiveObject* activeEntity;
 
@@ -36,10 +30,10 @@
        InteractiveObject* topmostEntity;
 
        /// previous state of mouse button
-       bool previousButtonState;       
+       bool wasDown;   
 
        /// current state of mouse button
-       bool currentButtonState;        
+       bool isDown;    
 
        /// whether mouse was inside the active_entity last frame
        bool wasInsideActiveEntity;
@@ -48,8 +42,8 @@
                :
         activeEntity(0),
         topmostEntity(0),
-               previousButtonState(UP),
-               currentButtonState(UP),
+               wasDown(false),
+               isDown(false),
                wasInsideActiveEntity(false)
        {
        }

=== modified file 'libcore/TextField.cpp'
--- a/libcore/TextField.cpp     2010-07-09 07:37:30 +0000
+++ b/libcore/TextField.cpp     2010-07-10 09:22:06 +0000
@@ -525,8 +525,7 @@
                {
                        movie_root& root = stage();
             boost::int32_t x_mouse, y_mouse;
-            boost::int32_t buttons;
-            root.get_mouse_state(x_mouse, y_mouse, buttons);
+            root.get_mouse_state(x_mouse, y_mouse);
                        
                        SWFMatrix m = getMatrix();
                        

=== modified file 'libcore/movie_root.cpp'
--- a/libcore/movie_root.cpp    2010-07-05 06:57:11 +0000
+++ b/libcore/movie_root.cpp    2010-07-10 09:50:05 +0000
@@ -125,9 +125,9 @@
     m_background_color(255, 255, 255, 255),
     m_background_color_set(false),
     m_timer(0.0f),
-    m_mouse_x(0),
-    m_mouse_y(0),
-    m_mouse_buttons(0),
+    _mouseX(0),
+    _mouseY(0),
+    _mouseDown(0),
     _lastTimerId(0),
     _lastKeyEvent(key::INVALID),
     _currentFocus(0),
@@ -568,12 +568,12 @@
 }
 
 bool
-movie_root::notify_mouse_moved(int x, int y)
+movie_root::mouseMoved(boost::int32_t x, boost::int32_t y)
 {
     assert(testInvariant());
 
-    m_mouse_x = x;
-    m_mouse_y = y;
+    _mouseX = x;
+    _mouseY = y;
     notify_mouse_listeners(event_id::MOUSE_MOVE);
     return fire_mouse_event();
 
@@ -622,21 +622,36 @@
     return false; // should return true if needs updatee ...
 }
 
-
-bool
-movie_root::notify_mouse_clicked(bool mouse_pressed, int button_mask)
+bool
+movie_root::mouseWheel(int delta)
+{
+    as_object* mouseObj = getBuiltinObject(*this, NSV::CLASS_MOUSE);
+    if (!mouseObj) return false;
+    
+    const boost::int32_t x = pixelsToTwips(_mouseX);
+    const boost::int32_t y = pixelsToTwips(_mouseY);
+
+    DisplayObject* i = getTopmostMouseEntity(x, y);
+
+    // Always called with two arguments.
+    callMethod(mouseObj, NSV::PROP_BROADCAST_MESSAGE, "onMouseWheel",
+            delta, i ? getObject(i) : as_value());
+
+    return true;
+}
+
+bool
+movie_root::mouseClick(bool mouse_pressed)
 {
     assert(testInvariant());
 
     //log_debug("Mouse click notification");
-    if (mouse_pressed)
-    {
-        m_mouse_buttons |= button_mask;
+    if (mouse_pressed) {
+        _mouseDown = true;
         notify_mouse_listeners(event_id(event_id::MOUSE_DOWN));
     }
-    else
-    {
-        m_mouse_buttons &= ~button_mask;
+    else {
+        _mouseDown = false;
         notify_mouse_listeners(event_id(event_id::MOUSE_UP));
     }
 
@@ -651,24 +666,22 @@
 
     assert(testInvariant());
 
-    boost::int32_t x = pixelsToTwips(m_mouse_x);
-    boost::int32_t y = pixelsToTwips(m_mouse_y);
+    boost::int32_t x = pixelsToTwips(_mouseX);
+    boost::int32_t y = pixelsToTwips(_mouseY);
 
     // Generate a mouse event
     _mouseButtonState.topmostEntity = getTopmostMouseEntity(x, y);
-    _mouseButtonState.currentButtonState = (m_mouse_buttons & 1);
+    _mouseButtonState.isDown = _mouseDown;
 
     // Set _droptarget if dragging a sprite
     MovieClip* dragging = 0;
     DisplayObject* draggingChar = getDraggingCharacter();
     if (draggingChar) dragging = draggingChar->to_movie();
-    if (dragging)
-    {
+    if (dragging) {
         // TODO: optimize making findDropTarget and getTopmostMouseEntity
         //       use a single scan.
         const DisplayObject* dropChar = findDropTarget(x, y, dragging);
-        if (dropChar)
-        {
+        if (dropChar) {
             // Use target of closest script DisplayObject containing this
             dropChar = getNearestObject(dropChar);
             dragging->setDropTarget(dropChar->getTargetPath());
@@ -698,15 +711,13 @@
 }
 
 void
-movie_root::get_mouse_state(boost::int32_t& x, boost::int32_t& y,
-        boost::int32_t& buttons)
+movie_root::get_mouse_state(boost::int32_t& x, boost::int32_t& y)
 {
 
     assert(testInvariant());
 
-    x = m_mouse_x;
-    y = m_mouse_y;
-    buttons = m_mouse_buttons;
+    x = _mouseX;
+    y = _mouseY;
 
     assert(testInvariant());
 }
@@ -735,9 +746,7 @@
         chmat.transform(&world_origin, origin);
 
         // Get current mouse coordinates
-        boost::int32_t x, y, buttons;
-        get_mouse_state(x, y, buttons);
-        point world_mouse(pixelsToTwips(x), pixelsToTwips(y));
+        point world_mouse(pixelsToTwips(_mouseX), pixelsToTwips(_mouseY));
 
         boost::int32_t xoffset = world_mouse.x - world_origin.x;
         boost::int32_t yoffset = world_mouse.y - world_origin.y;
@@ -760,10 +769,7 @@
         return; 
     }
 
-    boost::int32_t x, y, buttons;
-    get_mouse_state(x, y, buttons);
-
-    point world_mouse(pixelsToTwips(x), pixelsToTwips(y));
+    point world_mouse(pixelsToTwips(_mouseX), pixelsToTwips(_mouseY));
 
     SWFMatrix    parent_world_mat;
     DisplayObject* parent = dragChar->get_parent();
@@ -1089,10 +1095,10 @@
     as_object* mouseObj = getBuiltinObject(*this, NSV::CLASS_MOUSE);
     if (mouseObj) {
 
+        // Can throw an action limit exception if the stack limit is 0 or 1.
+        // A stack limit like that is hardly of any use, but could be used
+        // maliciously to crash Gnash.
         try {
-            // Can throw an action limit exception if the stack limit is 0 or 
1.
-            // A stack limit like that is hardly of any use, but could be used
-            // maliciously to crash Gnash.
             callMethod(mouseObj, NSV::PROP_BROADCAST_MESSAGE, 
                     event.functionName());
         }
@@ -1189,9 +1195,10 @@
 const DisplayObject*
 movie_root::getEntityUnderPointer() const
 {
-    boost::int32_t x = pixelsToTwips(m_mouse_x);
-    boost::int32_t y = pixelsToTwips(m_mouse_y);
-    const DisplayObject* dropChar = findDropTarget(x, y, 
getDraggingCharacter()); 
+    const boost::int32_t x = pixelsToTwips(_mouseX);
+    const boost::int32_t y = pixelsToTwips(_mouseY);
+    const DisplayObject* dropChar = 
+        findDropTarget(x, y, getDraggingCharacter()); 
     return dropChar;
 }
 
@@ -2546,100 +2553,95 @@
     // whether the action must trigger
     // a redraw.
 
-    switch (ms.previousButtonState)
-    {
-        case MouseButtonState::DOWN:
-        {
-            // TODO: Handle trackAsMenu dragOver
-            // Handle onDragOut, onDragOver
-            if (!ms.wasInsideActiveEntity) {
-
-                if (ms.topmostEntity == ms.activeEntity) {
-
-                    // onDragOver
-                    if (ms.activeEntity) {
-                        ms.activeEntity->mouseEvent(event_id::DRAG_OVER);
-                        need_redisplay=true;
-                    }
-                    ms.wasInsideActiveEntity = true;
-                }
-            }
-            else if (ms.topmostEntity != ms.activeEntity) {
-                // onDragOut
-                if (ms.activeEntity) {
-                    ms.activeEntity->mouseEvent(event_id::DRAG_OUT);
-                    need_redisplay=true;
-                }
-                ms.wasInsideActiveEntity = false;
-            }
-
-            // Handle onRelease, onReleaseOutside
-            if (ms.currentButtonState == MouseButtonState::UP) {
-                // Mouse button just went up.
-                ms.previousButtonState = MouseButtonState::UP;
-
-                if (ms.activeEntity) {
-                    if (ms.wasInsideActiveEntity) {
-                        // onRelease
-                        ms.activeEntity->mouseEvent(event_id::RELEASE);
-                        need_redisplay = true;
-                    }
-                    else {
-                        // TODO: Handle trackAsMenu 
-                        // onReleaseOutside
-                        ms.activeEntity->mouseEvent(event_id::RELEASE_OUTSIDE);
-                        // We got out of active entity
-                        ms.activeEntity = 0; // so we don't get RollOut next...
-                        need_redisplay = true;
-                    }
-                }
-            }
-            return need_redisplay;
-        }
-
-        case MouseButtonState::UP:
-        {
-            // New active entity is whatever is below the mouse right now.
-            if (ms.topmostEntity != ms.activeEntity)
-            {
-                // onRollOut
-                if (ms.activeEntity) {
-                    ms.activeEntity->mouseEvent(event_id::ROLL_OUT);
-                    need_redisplay=true;
-                }
-
-                ms.activeEntity = ms.topmostEntity;
-
-                // onRollOver
-                if (ms.activeEntity) {
-                    ms.activeEntity->mouseEvent(event_id::ROLL_OVER);
-                    need_redisplay=true;
-                }
-
-                ms.wasInsideActiveEntity = true;
-            }
-
-            // mouse button press
-            if (ms.currentButtonState == MouseButtonState::DOWN) {
-                // onPress
-
-                // Try setting focus on the new DisplayObject. This will handle
-                // all necessary events and removal of current focus.
-                // Do not set focus to NULL.
-                if (ms.activeEntity) {
-                    mr.setFocus(ms.activeEntity);
-
-                    ms.activeEntity->mouseEvent(event_id::PRESS);
-                    need_redisplay=true;
-                }
-
-                ms.wasInsideActiveEntity = true;
-                ms.previousButtonState = MouseButtonState::DOWN;
-            }
-        }
-        default:
-              return need_redisplay;
-    }
+    if (ms.wasDown) {
+        // TODO: Handle trackAsMenu dragOver
+        // Handle onDragOut, onDragOver
+        if (!ms.wasInsideActiveEntity) {
+
+            if (ms.topmostEntity == ms.activeEntity) {
+
+                // onDragOver
+                if (ms.activeEntity) {
+                    ms.activeEntity->mouseEvent(event_id::DRAG_OVER);
+                    need_redisplay=true;
+                }
+                ms.wasInsideActiveEntity = true;
+            }
+        }
+        else if (ms.topmostEntity != ms.activeEntity) {
+            // onDragOut
+            if (ms.activeEntity) {
+                ms.activeEntity->mouseEvent(event_id::DRAG_OUT);
+                need_redisplay=true;
+            }
+            ms.wasInsideActiveEntity = false;
+        }
+
+        // Handle onRelease, onReleaseOutside
+        if (!ms.isDown) {
+            // Mouse button just went up.
+            ms.wasDown = false;
+
+            if (ms.activeEntity) {
+                if (ms.wasInsideActiveEntity) {
+                    // onRelease
+                    ms.activeEntity->mouseEvent(event_id::RELEASE);
+                    need_redisplay = true;
+                }
+                else {
+                    // TODO: Handle trackAsMenu 
+                    // onReleaseOutside
+                    ms.activeEntity->mouseEvent(event_id::RELEASE_OUTSIDE);
+                    // We got out of active entity
+                    ms.activeEntity = 0; // so we don't get RollOut next...
+                    need_redisplay = true;
+                }
+            }
+        }
+        return need_redisplay;
+    }
+
+    else {
+        // New active entity is whatever is below the mouse right now.
+        if (ms.topmostEntity != ms.activeEntity)
+        {
+            // onRollOut
+            if (ms.activeEntity) {
+                ms.activeEntity->mouseEvent(event_id::ROLL_OUT);
+                need_redisplay=true;
+            }
+
+            ms.activeEntity = ms.topmostEntity;
+
+            // onRollOver
+            if (ms.activeEntity) {
+                ms.activeEntity->mouseEvent(event_id::ROLL_OVER);
+                need_redisplay=true;
+            }
+
+            ms.wasInsideActiveEntity = true;
+        }
+
+        // mouse button press
+        if (ms.isDown) {
+            // onPress
+
+            // Try setting focus on the new DisplayObject. This will handle
+            // all necessary events and removal of current focus.
+            // Do not set focus to NULL.
+            if (ms.activeEntity) {
+                mr.setFocus(ms.activeEntity);
+
+                ms.activeEntity->mouseEvent(event_id::PRESS);
+                need_redisplay=true;
+            }
+
+            ms.wasInsideActiveEntity = true;
+            ms.wasDown = true;
+        }
+    
+    }
+    return need_redisplay;
 
 }
 

=== modified file 'libcore/movie_root.h'
--- a/libcore/movie_root.h      2010-06-18 03:29:09 +0000
+++ b/libcore/movie_root.h      2010-07-10 10:57:31 +0000
@@ -280,36 +280,31 @@
     /// on scaleMode
     unsigned getStageHeight() const;
 
-    /// \brief
-    /// The host app can use this to tell the movie when
-    /// user's mouse pointer has moved.
+    /// Inform the Stage that the mouse has moved.
     //
     /// Coordinates are in Stage Coordinate Space (pseudo-pixels units).
     ///
-    /// This function should return TRUE iff any action triggered
-    /// by the event requires redraw, see \ref events_handling for
-    /// more info.
+    /// @param x    The x co-ordinate in pixels.
+    /// @param y    The y co-ordinate in pixels.
+    /// @return     true if any action triggered requires a redraw.
     ///
     /// TODO: take twips (or float pixels), or we won't be able to
     ///       support sub-pixel accuracy in collision detection.
-    ///
-    bool notify_mouse_moved(int x, int y);
-
-    /// \brief
-    /// The host app can use this to tell the movie when the
-    /// user clicked or released the mouse button.
-    //
-    /// @param mouse_pressed
-    /// true if the mouse has been pressed, false if released
-    ///
-    /// @param mask
-    /// ???
-    ///
-    /// This function should return TRUE iff any action triggered
-    /// by the event requires redraw, see \ref events_handling for
-    /// more info.
-    ///
-    bool notify_mouse_clicked(bool mouse_pressed, int mask);
+    bool mouseMoved(boost::int32_t x, boost::int32_t y);
+
+    /// Inform the Stage that a mouse click has occurred.
+    //
+    /// @param press    true for a mouse click, false for a release
+    /// @return         true if any action triggered requires a redraw.
+    bool mouseClick(bool press);
+
+    /// Inform the Stage that a mouse wheel has moved.
+    //
+    /// @param delta    The direction of the scroll: positive for up, negative
+    ///                 for down. Although values from about -3 to 3 are
+    ///                 documented, only -1 and 1 have been observed.
+    /// @return         true if any action triggered requires a redraw.
+    bool mouseWheel(int delta);
 
     /// \brief
     /// The host app can use this to tell the movie when
@@ -321,14 +316,10 @@
     ///
     bool notify_key_event(key::code k, bool down);
 
-    /// \brief
-    /// Use this to retrieve the last state of the mouse, as set via
-    /// notify_mouse_state(). 
+    /// Use this to retrieve the last state of the mouse.
     //
     /// Coordinates are in PIXELS, NOT TWIPS.
-    ///
-    void get_mouse_state(boost::int32_t& x, boost::int32_t& y,
-            boost::int32_t& buttons);
+    void get_mouse_state(boost::int32_t& x, boost::int32_t& y);
 
     void get_drag_state(drag_state& st);
 
@@ -1149,7 +1140,9 @@
     bool m_background_color_set;
 
     float m_timer;
-    int m_mouse_x, m_mouse_y, m_mouse_buttons;
+    boost::int32_t _mouseX;
+    boost::int32_t _mouseY;
+    bool _mouseDown;
 
     MouseButtonState  _mouseButtonState;
 

=== modified file 'testsuite/MovieTester.cpp'
--- a/testsuite/MovieTester.cpp 2010-07-05 08:32:15 +0000
+++ b/testsuite/MovieTester.cpp 2010-07-10 09:23:03 +0000
@@ -333,7 +333,7 @@
 {
     _x = x;
     _y = y;
-    if ( _movie_root->notify_mouse_moved(x, y) ) render();
+    if ( _movie_root->mouseMoved(x, y) ) render();
 }
 
 void
@@ -399,7 +399,7 @@
 void
 MovieTester::pressMouseButton()
 {
-    if ( _movie_root->notify_mouse_clicked(true, 1) ) {
+    if ( _movie_root->mouseClick(true) ) {
        render();
     }
 }
@@ -407,7 +407,7 @@
 void
 MovieTester::depressMouseButton()
 {
-    if ( _movie_root->notify_mouse_clicked(false, 1) ) {
+    if ( _movie_root->mouseClick(false) ) {
        render();
     }
 }
@@ -416,13 +416,19 @@
 MovieTester::click()
 {
     int wantRedraw = 0;
-    if ( _movie_root->notify_mouse_clicked(true, 1) ) ++wantRedraw;
-    if ( _movie_root->notify_mouse_clicked(false, 1) ) ++wantRedraw;
+    if ( _movie_root->mouseClick(true) ) ++wantRedraw;
+    if ( _movie_root->mouseClick(false) ) ++wantRedraw;
     
     if ( wantRedraw ) render();
 }
 
 void
+MovieTester::scrollMouse(int delta)
+{
+    if (_movie_root->mouseWheel(delta)) render();
+}
+
+void
 MovieTester::pressKey(key::code code)
 {
     if ( _movie_root->notify_key_event(code, true) ) {

=== modified file 'testsuite/MovieTester.h'
--- a/testsuite/MovieTester.h   2010-03-11 01:47:08 +0000
+++ b/testsuite/MovieTester.h   2010-07-10 09:23:03 +0000
@@ -216,6 +216,12 @@
        /// Simulate a mouse click (press and depress mouse button)
        void click();
 
+    /// Simulate a mouse scroll.
+    //
+    /// The only values seen so far are -1 and 1, but documented to be
+    /// usually between -3 and 3. 1 is up, -1 is down.
+    void scrollMouse(int delta);
+
        /// Notify key press
        //
        /// See key codes in namespace gnash::key (gnash.h)

=== modified file 'testsuite/misc-ming.all/SpriteButtonEventsTest-Runner.cpp'
--- a/testsuite/misc-ming.all/SpriteButtonEventsTest-Runner.cpp 2010-01-01 
17:48:26 +0000
+++ b/testsuite/misc-ming.all/SpriteButtonEventsTest-Runner.cpp 2010-07-10 
10:06:10 +0000
@@ -273,8 +273,18 @@
 
        }
 
+    tester.scrollMouse(-1);
+    check_equals(text->get_text_value(), "onMouseWheel: -1, , 2");
+    
+    tester.scrollMouse(1);
+    check_equals(text->get_text_value(), "onMouseWheel: 1, , 2");
+
+    tester.movePointerTo(100, 100);
+    tester.scrollMouse(1);
+    check_equals(text->get_text_value(), "onMouseWheel: 1, _level0.textfield2, 
2");
+
        // last advance should not restart the loop (it's in STOP mode)
-        check_equals(root->getPlayState(), MovieClip::PLAYSTATE_STOP);
+    check_equals(root->getPlayState(), MovieClip::PLAYSTATE_STOP);
        check_equals(root->get_current_frame(), 4);
 
 }

=== modified file 'testsuite/misc-ming.all/SpriteButtonEventsTest.c'
--- a/testsuite/misc-ming.all/SpriteButtonEventsTest.c  2010-01-01 17:48:26 
+0000
+++ b/testsuite/misc-ming.all/SpriteButtonEventsTest.c  2010-07-10 10:06:10 
+0000
@@ -138,6 +138,12 @@
                "       _root.msg='ReleaseOutside';"
                "       gotoAndStop(1);"
                "};"
+        "_root.onMouseWheel = function(delta, t) {"
+               "       _root.note('onMouseWheel: ' + delta + ', ' + t + ', ' + 
arguments.length);"
+        "   _root.note('onMouseWheel: ' + delta + ', ' +  t);"
+               "       _root.msg='onMouseWheel: ' + delta + ', ' + t + ', ' + 
arguments.length;"
+        "};"
+        "Mouse.addListener(_root);"
                "stop();"
        ));
 


reply via email to

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