[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog server/button_character_instanc...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog server/button_character_instanc... |
Date: |
Fri, 18 Apr 2008 21:30:55 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 08/04/18 21:30:55
Modified files:
. : ChangeLog
server : button_character_instance.cpp
server/parser : button_character_def.cpp button_character_def.h
Log message:
Abstract access to button actions, now parser-private.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6325&r2=1.6326
http://cvs.savannah.gnu.org/viewcvs/gnash/server/button_character_instance.cpp?cvsroot=gnash&r1=1.93&r2=1.94
http://cvs.savannah.gnu.org/viewcvs/gnash/server/parser/button_character_def.cpp?cvsroot=gnash&r1=1.31&r2=1.32
http://cvs.savannah.gnu.org/viewcvs/gnash/server/parser/button_character_def.h?cvsroot=gnash&r1=1.26&r2=1.27
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6325
retrieving revision 1.6326
diff -u -b -r1.6325 -r1.6326
--- ChangeLog 18 Apr 2008 16:04:33 -0000 1.6325
+++ ChangeLog 18 Apr 2008 21:30:53 -0000 1.6326
@@ -1,5 +1,11 @@
2008-04-18 Sandro Santilli <address@hidden>
+ * server/button_character_instance.cpp,
+ server/parser/button_character_def.{cpp,h}:
+ Abstract access to button actions, now parser-private.
+
+2008-04-18 Sandro Santilli <address@hidden>
+
* testsuite/misc-ming.all/ButtonEventsTest.c: enable a test snippet
that was failing to execute. Add constency checking for the
self-contained tests. Add test showing that unloaded (depth-shifted)
Index: server/button_character_instance.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/button_character_instance.cpp,v
retrieving revision 1.93
retrieving revision 1.94
diff -u -b -r1.93 -r1.94
--- server/button_character_instance.cpp 18 Apr 2008 09:47:54 -0000
1.93
+++ server/button_character_instance.cpp 18 Apr 2008 21:30:54 -0000
1.94
@@ -168,6 +168,48 @@
namespace gnash {
+namespace {
+
+class ButtonActionExecutor {
+public:
+ ButtonActionExecutor(as_environment& env)
+ :
+ _env(env)
+ {}
+
+ void operator() (const action_buffer& ab)
+ {
+ ActionExec exec(ab, _env);
+ exec();
+ }
+private:
+ as_environment& _env;
+};
+
+class ButtonActionPusher {
+public:
+ ButtonActionPusher(movie_root& mr, character* this_ptr)
+ :
+ called(false),
+ _mr(mr),
+ _tp(this_ptr)
+ {}
+
+ void operator() (const action_buffer& ab)
+ {
+ _mr.pushAction(ab, boost::intrusive_ptr<character>(_tp));
+ called = true;
+ }
+
+ bool called;
+
+private:
+ movie_root& _mr;
+ character* _tp;
+};
+
+}
+
// Forward declarations
static as_object* getButtonInterface();
@@ -254,15 +296,9 @@
set_prototype(getButtonInterface());
// check up presence Key events
- // TODO: use a service of button_character_def, not this hard-coded
thing here
- for (size_t i = 0, e = m_def->m_button_actions.size(); i < e; ++i)
- {
- // TODO: use labels, not magic numbers here !!
- if (m_def->m_button_actions[i]->m_conditions & 0xFE00) //
check up on CondKeyPress: UB[7]
+ if ( m_def->hasKeyPressHandler() )
{
_vm.getRoot().add_key_listener(this);
- break;
- }
}
}
@@ -314,34 +350,16 @@
bool
button_character_instance::on_event(const event_id& id)
{
+ // We only respond keypress events
+ if ( id.m_id != event_id::KEY_PRESS ) return false;
- if( (id.m_id==event_id::KEY_PRESS) && (id.keyCode == key::INVALID) )
- {
- // onKeypress only responds to valid key code
- return false;
- }
-
- bool called = false;
-
- // Add appropriate actions to the global action list ...
- // TODO: should we execute immediately instead ?
- for (size_t i = 0, ie=m_def->m_button_actions.size(); i<ie; ++i)
- {
- button_action& ba = *(m_def->m_button_actions[i]);
+ // We only respond to valid key code (should we assert here?)
+ if ( id.keyCode == key::INVALID ) return false;
- int keycode = (ba.m_conditions & 0xFE00) >> 9;
-
- // Test match between button action conditions and the SWF code
- // that maps to id.keyCode (the gnash unique key code).
- if (id.m_id == event_id::KEY_PRESS &&
gnash::key::codeMap[id.keyCode][key::SWF] == keycode)
- {
- // Matching action.
- VM::get().getRoot().pushAction(ba.m_actions,
boost::intrusive_ptr<character>(this));
- called = true;
- }
- }
+ ButtonActionPusher xec(getVM().getRoot(), this);
+ m_def->forEachTrigger(id, xec);
- return called;
+ return xec.called;
}
void
@@ -524,19 +542,6 @@
}
}
-
- // @@ eh, should just be a lookup table.
- int c = 0;
- if (event.m_id == event_id::ROLL_OVER) c |=
(button_action::IDLE_TO_OVER_UP);
- else if (event.m_id == event_id::ROLL_OUT) c |=
(button_action::OVER_UP_TO_IDLE);
- else if (event.m_id == event_id::PRESS) c |=
(button_action::OVER_UP_TO_OVER_DOWN);
- else if (event.m_id == event_id::RELEASE) c |=
(button_action::OVER_DOWN_TO_OVER_UP);
- else if (event.m_id == event_id::DRAG_OUT) c |=
(button_action::OVER_DOWN_TO_OUT_DOWN);
- else if (event.m_id == event_id::DRAG_OVER) c |=
(button_action::OUT_DOWN_TO_OVER_DOWN);
- else if (event.m_id == event_id::RELEASE_OUTSIDE) c |=
(button_action::OUT_DOWN_TO_IDLE);
- //IDLE_TO_OVER_DOWN = 1 << 7,
- //OVER_DOWN_TO_IDLE = 1 << 8,
-
// From: "ActionScript - The Definiteve Guide" by Colin Moock
// (chapter 10: Events and Event Handlers)
@@ -546,22 +551,8 @@
// Immediately execute all events actions (don't append to
// parent's action buffer for later execution!)
- for (size_t i = 0; i < m_def->m_button_actions.size(); i++)
- {
- button_action& ba = *(m_def->m_button_actions[i]);
-
- if (ba.m_conditions & c)
- {
- // Matching action.
- action_buffer& ab = ba.m_actions;
- IF_VERBOSE_ACTION(
- log_action(_("Executing actions for "
- "button condition %d"), c);
- );
- ActionExec exec(ab, get_environment());
- exec();
- }
- }
+ ButtonActionExecutor xec(get_environment());
+ m_def->forEachTrigger(event, xec);
// check for built-in event handler.
std::auto_ptr<ExecutableCode> code ( get_event_handler(event) );
Index: server/parser/button_character_def.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/parser/button_character_def.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- server/parser/button_character_def.cpp 5 Mar 2008 03:56:02 -0000
1.31
+++ server/parser/button_character_def.cpp 18 Apr 2008 21:30:54 -0000
1.32
@@ -27,7 +27,9 @@
#include "movie_definition.h"
#include "action_buffer.h"
#include "filter_factory.h"
+#include "gnash.h" // for gnash::key::codeMap
+#define ONCE(x) { static bool warned=false; if (!warned) { warned=true; x; } }
namespace gnash {
@@ -61,13 +63,35 @@
}
IF_VERBOSE_PARSE (
- log_parse(_("-- actions in button")); // @@ need more info about which
actions
+ log_parse(_(" button actions for conditions %x"), m_conditions); //
@@ need more info about which actions
);
// Read actions.
m_actions.read(in, endPos);
}
+bool
+button_action::triggeredBy(const event_id& ev) const
+{
+ switch ( ev.id() )
+ {
+ case event_id::ROLL_OVER: return m_conditions & IDLE_TO_OVER_UP;
+ case event_id::ROLL_OUT: return m_conditions & OVER_UP_TO_IDLE;
+ case event_id::PRESS: return m_conditions &
OVER_UP_TO_OVER_DOWN;
+ case event_id::RELEASE: return m_conditions &
OVER_DOWN_TO_OVER_UP;
+ case event_id::DRAG_OUT: return m_conditions &
OVER_DOWN_TO_OUT_DOWN;
+ case event_id::DRAG_OVER: return m_conditions &
OUT_DOWN_TO_OVER_DOWN;
+ case event_id::RELEASE_OUTSIDE: return m_conditions &
OUT_DOWN_TO_IDLE;
+ case event_id::KEY_PRESS:
+ {
+ int keycode = getKeyCode();
+ if ( ! keycode ) return false; // not a keypress event
+ return key::codeMap[ev.keyCode][key::SWF] == keycode;
+ }
+ default: return false;
+ }
+}
+
//
// button_record
//
@@ -203,8 +227,6 @@
button_character_definition::button_character_definition(movie_definition* m)
:
- m_min_layer(0),
- m_max_layer(0),
m_sound(NULL),
_movieDef(m)
@@ -321,16 +343,6 @@
// Read actions.
m_button_actions.push_back(new button_action(*in, SWF::DEFINEBUTTON,
endTagPos, *m));
- // detect min/max layer number
- m_min_layer=0;
- m_max_layer=0;
- for (unsigned int i=0; i<m_button_records.size(); i++)
- {
- int this_layer = m_button_records[i].m_button_layer;
-
- if ((i==0) || (this_layer < m_min_layer)) m_min_layer=this_layer;
- if ((i==0) || (this_layer > m_max_layer)) m_max_layer=this_layer;
- }
}
void
@@ -338,11 +350,14 @@
{
// Character ID has been read already
+ in->ensureBytes(1 + 2); // flags + actions offset
+
// Read the menu flag
// (this is a single bit, the other 7 bits are reserved)
- in->ensureBytes(1 + 2);
-
m_menu = in->read_u8() != 0;
+ if ( m_menu ) ONCE(log_unimpl("DEFINEBUTTON2 'menu' flag"));
+
+ // Read the action offset
unsigned button_2_action_offset = in->read_u16();
unsigned long tagEndPosition = in->get_tag_end_position();
@@ -416,17 +431,6 @@
in->set_position(next_action_pos);
}
}
-
- // detect min/max layer number
- m_min_layer=0;
- m_max_layer=0;
- for (unsigned int i=0; i<m_button_records.size(); i++)
- {
- int this_layer = m_button_records[i].m_button_layer;
-
- if ((i==0) || (this_layer < m_min_layer))
m_min_layer=this_layer;
- if ((i==0) || (this_layer > m_max_layer))
m_max_layer=this_layer;
- }
}
void
@@ -516,6 +520,17 @@
return _movieDef->get_version();
}
+bool
+button_character_definition::hasKeyPressHandler() const
+{
+ for (size_t i = 0, e = m_button_actions.size(); i < e; ++i)
+ {
+ const button_action& ba = *(m_button_actions[i]);
+ if ( ba.triggeredByKeyPress() ) return true;
+ }
+ return false;
+}
+
} // namespace gnash
// Local Variables:
Index: server/parser/button_character_def.h
===================================================================
RCS file: /sources/gnash/gnash/server/parser/button_character_def.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- server/parser/button_character_def.h 12 Feb 2008 12:28:08 -0000
1.26
+++ server/parser/button_character_def.h 18 Apr 2008 21:30:55 -0000
1.27
@@ -1,9 +1,22 @@
-// -- Thatcher Ulrich <address@hidden> 2003
+// button_character_def.h: Mouse-sensitive SWF buttons, for Gnash.
+//
+// Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+//
-// This source code has been donated to the Public Domain. Do
-// whatever you want with it.
-
-// SWF buttons. Mouse-sensitive update/display, actions, etc.
#ifndef GNASH_BUTTON_CHARACTER_DEF_H
@@ -29,6 +42,7 @@
namespace gnash {
class sprite_instance;
class movie_definition;
+ class event_id;
}
namespace gnash {
@@ -111,19 +125,6 @@
class button_action
{
public:
- enum condition
- {
- IDLE_TO_OVER_UP = 1 << 0,
- OVER_UP_TO_IDLE = 1 << 1,
- OVER_UP_TO_OVER_DOWN = 1 << 2,
- OVER_DOWN_TO_OVER_UP = 1 << 3,
- OVER_DOWN_TO_OUT_DOWN = 1 << 4,
- OUT_DOWN_TO_OVER_DOWN = 1 << 5,
- OUT_DOWN_TO_IDLE = 1 << 6,
- IDLE_TO_OVER_DOWN = 1 << 7,
- OVER_DOWN_TO_IDLE = 1 << 8
- };
- int m_conditions;
// TODO: define ownership of list elements !!
action_buffer m_actions;
@@ -137,6 +138,41 @@
///
button_action(stream& in, int tag_type, unsigned long endPos,
movie_definition& mdef);
+ /// Return true if this action should be triggered by the given event.
+ bool triggeredBy(const event_id& ev) const;
+
+ /// Return true if this action is triggered by a keypress
+ bool triggeredByKeyPress() const
+ {
+ return m_conditions&KEYPRESS;
+ }
+
+private:
+
+ /// Return the keycode triggering this action
+ //
+ /// Return 0 if no key is supposed to trigger us
+ ///
+ int getKeyCode() const
+ {
+ return (m_conditions&KEYPRESS) >> 9;
+ }
+
+ enum condition
+ {
+ IDLE_TO_OVER_UP = 1 << 0,
+ OVER_UP_TO_IDLE = 1 << 1,
+ OVER_UP_TO_OVER_DOWN = 1 << 2,
+ OVER_DOWN_TO_OVER_UP = 1 << 3,
+ OVER_DOWN_TO_OUT_DOWN = 1 << 4,
+ OUT_DOWN_TO_OVER_DOWN = 1 << 5,
+ OUT_DOWN_TO_IDLE = 1 << 6,
+ IDLE_TO_OVER_DOWN = 1 << 7,
+ OVER_DOWN_TO_IDLE = 1 << 8,
+ KEYPRESS = 0xFE00 // highest 7 bits
+ };
+ int m_conditions;
+
};
@@ -144,12 +180,6 @@
{
public:
- /// Smallest layer number used for button records
- int m_min_layer;
-
- /// Greatest layer number used for button records
- int m_max_layer;
-
struct sound_info
{
void read(stream* in);
@@ -211,17 +241,6 @@
#endif // GNASH_USE_GC
};
-
- bool m_menu;
-
- typedef std::vector<button_record> ButtonRecVect;
- ButtonRecVect m_button_records;
-
- typedef std::vector<button_action*> ButtonActVect;
- ButtonActVect m_button_actions;
-
- boost::scoped_ptr<button_sound_def> m_sound;
-
/// \brief
/// Construct a character definition as read from
/// the given movie_definition (SWF)
@@ -257,16 +276,28 @@
return unused;
}
- const rect& get_button_bound(int id) const {
- UNUSED(id);
- abort(); // not implemented
- }
-
/// \brief
/// Return version of the SWF containing
/// this button definition.
int getSWFVersion() const;
+ bool hasKeyPressHandler() const;
+
+ /// Invoke a functor for each action triggered by given event
+ //
+ /// The functor will be passed a const action_buffer&
+ /// and is not expected to return anything.
+ ///
+ template <class E>
+ void forEachTrigger(const event_id& ev, E& f) const
+ {
+ for (size_t i = 0, e = m_button_actions.size(); i < e; ++i)
+ {
+ const button_action& ba = *(m_button_actions[i]);
+ if ( ba.triggeredBy(ev) ) f(ba.m_actions);
+ }
+ }
+
protected:
#ifdef GNASH_USE_GC
@@ -287,8 +318,22 @@
if ( m_sound ) m_sound->markReachableResources();
}
#endif // GNASH_USE_GC
+
+public: // TODO: make private
+
+ typedef std::vector<button_record> ButtonRecVect;
+ ButtonRecVect m_button_records;
+
+ boost::scoped_ptr<button_sound_def> m_sound;
+
private:
+ typedef std::vector<button_action*> ButtonActVect;
+ ButtonActVect m_button_actions;
+
+ /// Currently set but unused (and also unaccessible)
+ bool m_menu;
+
/// The movie definition containing definition of this button
movie_definition* _movieDef;
};
- [Gnash-commit] gnash ChangeLog server/button_character_instanc..., Sandro Santilli, 2008/04/12
- [Gnash-commit] gnash ChangeLog server/button_character_instanc..., Sandro Santilli, 2008/04/15
- [Gnash-commit] gnash ChangeLog server/button_character_instanc..., Sandro Santilli, 2008/04/15
- [Gnash-commit] gnash ChangeLog server/button_character_instanc..., Sandro Santilli, 2008/04/15
- [Gnash-commit] gnash ChangeLog server/button_character_instanc..., Sandro Santilli, 2008/04/16
- [Gnash-commit] gnash ChangeLog server/button_character_instanc..., Sandro Santilli, 2008/04/18
- [Gnash-commit] gnash ChangeLog server/button_character_instanc...,
Sandro Santilli <=
- [Gnash-commit] gnash ChangeLog server/button_character_instanc..., Sandro Santilli, 2008/04/18
- [Gnash-commit] gnash ChangeLog server/button_character_instanc..., Sandro Santilli, 2008/04/18
- [Gnash-commit] gnash ChangeLog server/button_character_instanc..., Sandro Santilli, 2008/04/19
- [Gnash-commit] gnash ChangeLog server/button_character_instanc..., Sandro Santilli, 2008/04/19
- [Gnash-commit] gnash ChangeLog server/button_character_instanc..., Sandro Santilli, 2008/04/22
- [Gnash-commit] gnash ChangeLog server/button_character_instanc..., Sandro Santilli, 2008/04/22