gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash/server Key.cpp Key.h action.cpp action.h ...


From: Vitaly Alexeev
Subject: [Gnash-commit] gnash/server Key.cpp Key.h action.cpp action.h ...
Date: Mon, 19 Jun 2006 14:39:48 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Vitaly Alexeev <alexeev>        06/06/19 14:39:48

Modified files:
        server         : Key.cpp Key.h action.cpp action.h character.h 
                         sprite_instance.cpp sprite_instance.h 

Log message:
        added keypress event handler

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/server/Key.cpp?cvsroot=gnash&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gnash/server/Key.h?cvsroot=gnash&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/gnash/server/action.cpp?cvsroot=gnash&r1=1.84&r2=1.85
http://cvs.savannah.gnu.org/viewcvs/gnash/server/action.h?cvsroot=gnash&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/gnash/server/character.h?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/server/sprite_instance.cpp?cvsroot=gnash&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/gnash/server/sprite_instance.h?cvsroot=gnash&r1=1.6&r2=1.7

Patches:
Index: Key.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/Key.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- Key.cpp     7 Jun 2006 03:03:21 -0000       1.4
+++ Key.cpp     19 Jun 2006 14:39:48 -0000      1.5
@@ -43,6 +43,7 @@
 #include "Key.h"
 #include "action.h" // for action_init
 #include "fn_call.h"
+#include "sprite_instance.h"
 
 namespace gnash {
 
@@ -266,12 +267,14 @@
            cleanup_listeners();
 #endif
 
-    std::vector<weak_ptr<as_object> >::const_iterator end = m_listeners.end();
-    for (std::vector<weak_ptr<as_object> >::iterator iter = 
m_listeners.begin();
-         iter != end; ++iter) {
-      if (*iter == listener) {
-        m_listeners.erase(iter);
+  for (std::vector<weak_ptr<as_object> >::iterator iter = m_listeners.begin(); 
iter != m_listeners.end(); )
+       {
+    if (*iter == listener)
+               {
+      iter = m_listeners.erase(iter);
+                       continue;
       }
+               iter++;
     }
 }
 
@@ -381,6 +384,37 @@
     ko->remove_listener(listener);
 }
 
+static std::vector<weak_ptr<as_object> >       s_keypress_listeners;
+
+void add_keypress_listener(as_object* listener)
+{
+       std::vector<weak_ptr<as_object> >::const_iterator end = 
s_keypress_listeners.end();
+       for (std::vector<weak_ptr<as_object> >::iterator iter = 
s_keypress_listeners.begin();
+                       iter != end; ++iter) 
+       {
+               if (*iter == NULL)
+               {
+                       // Already in the list.
+                       return;
+               }
+       }
+       s_keypress_listeners.push_back(listener);
+}
+
+void remove_keypress_listener(as_object* listener)
+{
+       for (std::vector<weak_ptr<as_object> >::iterator iter = 
s_keypress_listeners.begin();
+                       iter != s_keypress_listeners.end(); )
+       {
+               if (*iter == listener)
+               {
+                       iter = s_keypress_listeners.erase(iter);
+                       continue;
+               }
+               iter++;
+       }
+}
+
 void   notify_key_event(key::code k, bool down)
     // External interface for the host to report key events.
 {
@@ -388,6 +422,24 @@
            
     action_init();     // @@ put this in some global init somewhere else...
 
+       // Notify keypress listeners.
+       if (down) 
+       {
+               for (std::vector<weak_ptr<as_object> >::iterator iter = 
s_keypress_listeners.begin();
+                                iter != s_keypress_listeners.end(); ++iter)
+               {
+                       if (*iter == NULL)
+                       {
+                                       continue;
+                       }
+
+                       smart_ptr<as_object>  listener = *iter; // Hold an 
owning reference.
+
+                       sprite_instance* sprite = (sprite_instance*) 
listener.get_ptr();
+                       sprite->on_event(event_id(event_id::KEY_PRESS, 
(key::code) k));
+               }
+       }
+
     static tu_string   key_obj_name("Key");
 
     as_value   kval;

Index: Key.h
===================================================================
RCS file: /sources/gnash/gnash/server/Key.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- Key.h       7 Jun 2006 03:03:21 -0000       1.6
+++ Key.h       19 Jun 2006 14:39:48 -0000      1.7
@@ -134,6 +134,9 @@
 
 void key_init(as_object* global);
 
+void add_keypress_listener(as_object* listener);
+void remove_keypress_listener(as_object* listener);
+
 } // end of gnash namespace
 
 // __KEY_H__

Index: action.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/action.cpp,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -b -r1.84 -r1.85
--- action.cpp  16 Jun 2006 01:51:43 -0000      1.84
+++ action.cpp  19 Jun 2006 14:39:48 -0000      1.85
@@ -1361,8 +1361,7 @@
            "onXMLData",                 // XML_DATA
            "onTimer",           // setInterval Timer expired
 
-               "onClipKeyPress",
-               "onClipConstruct"
+           "onConstruct"
        };
 
     assert(m_id > INVALID && m_id < EVENT_COUNT);

Index: action.h
===================================================================
RCS file: /sources/gnash/gnash/server/action.h,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- action.h    15 Jun 2006 18:35:49 -0000      1.33
+++ action.h    19 Jun 2006 14:39:48 -0000      1.34
@@ -122,8 +122,7 @@
                        // This is for setInterval
                        TIMER,
 
-                       CLIP_KEY_PRESS,
-                       CLIP_CONSTRUCT,
+                       CONSTRUCT,
 
                        EVENT_COUNT
                };

Index: character.h
===================================================================
RCS file: /sources/gnash/gnash/server/character.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- character.h 8 May 2006 21:12:24 -0000       1.2
+++ character.h 19 Jun 2006 14:39:48 -0000      1.3
@@ -169,8 +169,14 @@
     void       set_event_handler(event_id id, const as_value& method)
        {
            m_event_handlers[id] = method;
+                       if (id.m_id == event_id::KEY_PRESS)
+                       {
+                               has_keypress_event();
+                       }
        }
 
+               virtual void has_keypress_event() {}
+
     // Movie interfaces.  By default do nothing.  sprite_instance and some 
others override these.
     virtual void       display() {}
     virtual float      get_height() { return 0; }

Index: sprite_instance.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/sprite_instance.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- sprite_instance.cpp 15 Jun 2006 11:21:29 -0000      1.10
+++ sprite_instance.cpp 19 Jun 2006 14:39:48 -0000      1.11
@@ -62,6 +62,7 @@
 #include "execute_tag.h"
 #include "fn_call.h"
 #include "tu_random.h"
+#include "Key.h"
 
 using namespace std;
 
@@ -366,7 +367,8 @@
        m_has_looped(false),
        m_accept_anim_moves(true),
        m_on_event_load_called(false),
-       m_frame_time(0.0f)
+       m_frame_time(0.0f),
+       m_has_keypress_event(false)
 {
        assert(m_def != NULL);
        assert(m_root != NULL);
@@ -390,6 +392,12 @@
 
 sprite_instance::~sprite_instance()
 {
+
+       if (m_has_keypress_event)
+       {
+               remove_keypress_listener(this);
+       }
+
        m_display_list.clear();
        //m_root->drop_ref();
 }
@@ -1110,6 +1118,10 @@
            m_as_environment.set_variable(path, val, empty_with_stack);
 }
 
+void sprite_instance::has_keypress_event()
+{
+       m_has_keypress_event = true;
+}
 
 void sprite_instance::advance_sprite(float delta_time)
 {
@@ -1182,6 +1194,12 @@
        if (m_on_event_load_called == false)
        {
                on_event(event_id::LOAD);       // clip onload
+
+               //
+               if (m_has_keypress_event)
+               {
+                       add_keypress_listener(this);
+               }
        }
        
        advance_sprite(delta_time);

Index: sprite_instance.h
===================================================================
RCS file: /sources/gnash/gnash/server/sprite_instance.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- sprite_instance.h   14 Jun 2006 13:02:50 -0000      1.6
+++ sprite_instance.h   19 Jun 2006 14:39:48 -0000      1.7
@@ -79,6 +79,8 @@
                OVER
        };
 
+       virtual void has_keypress_event();
+
        // sprite instance of add_interval_handler()
        virtual int    add_interval_timer(void *timer)
         {
@@ -514,6 +516,7 @@
 
        bool m_on_event_load_called;
        float   m_frame_time;
+       bool m_has_keypress_event;
 
 };
 




reply via email to

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