@@ -5,11 +5,8 @@ use crate::avm2::names::{Namespace, QName};
55use crate :: avm2:: object:: { Object , TObject } ;
66use crate :: avm2:: value:: Value ;
77use crate :: avm2:: Error ;
8- use crate :: context:: UpdateContext ;
9- use crate :: display_object:: { DisplayObject , InteractiveObject , TDisplayObject } ;
10- use crate :: events:: KeyCode ;
8+ use crate :: display_object:: TDisplayObject ;
119use crate :: string:: AvmString ;
12- use bitflags:: bitflags;
1310use fnv:: FnvHashMap ;
1411use gc_arena:: Collect ;
1512use std:: collections:: BTreeMap ;
@@ -45,101 +42,6 @@ pub enum PropagationMode {
4542 StopImmediate ,
4643}
4744
48- bitflags ! {
49- /// Keyboard modifiers.
50- #[ derive( Collect , Default ) ]
51- #[ collect( require_static) ]
52- pub struct KeyModifiers : u8 {
53- const CTRL = 0b00000001 ;
54- const ALT = 0b00000010 ;
55- const SHIFT = 0b00000100 ;
56- const COMMAND = 0b00001000 ;
57- }
58- }
59-
60- impl KeyModifiers {
61- fn from_current_keys < ' gc > ( context : & mut UpdateContext < ' _ , ' gc , ' _ > ) -> Self {
62- let mut keymods = KeyModifiers :: default ( ) ;
63-
64- if context. input . is_key_down ( KeyCode :: Control ) {
65- keymods. insert ( KeyModifiers :: CTRL ) ;
66- }
67-
68- if context. input . is_key_down ( KeyCode :: Alt ) {
69- keymods. insert ( KeyModifiers :: ALT ) ;
70- }
71-
72- if context. input . is_key_down ( KeyCode :: Shift ) {
73- keymods. insert ( KeyModifiers :: SHIFT ) ;
74- }
75-
76- //TODO: We don't have a UI keycode for ⌘.
77-
78- keymods
79- }
80- }
81-
82- /// The data for a dispatched event.
83- ///
84- /// This roughly corresponds to properties provided on specific AS3 `Event`
85- /// subclasses.
86- #[ derive( Clone , Collect , Debug ) ]
87- #[ collect( no_drop) ]
88- pub enum EventData < ' gc > {
89- Empty ,
90- Error {
91- text : AvmString < ' gc > ,
92- error_id : i32 ,
93- } ,
94- FullScreen {
95- full_screen : bool ,
96- interactive : bool ,
97- } ,
98- IOError {
99- text : AvmString < ' gc > ,
100- error_id : i32 ,
101- } ,
102- Mouse {
103- local_x : f64 ,
104- local_y : f64 ,
105- movement_x : f64 ,
106- movement_y : f64 ,
107- related_object : Option < InteractiveObject < ' gc > > ,
108- modifiers : KeyModifiers ,
109- button_down : bool ,
110- delta : i32 ,
111- } ,
112- SecurityError {
113- text : AvmString < ' gc > ,
114- error_id : i32 ,
115- } ,
116- Text {
117- text : AvmString < ' gc > ,
118- } ,
119- }
120-
121- impl < ' gc > EventData < ' gc > {
122- pub fn mouse_event (
123- context : & mut UpdateContext < ' _ , ' gc , ' _ > ,
124- target : DisplayObject < ' gc > ,
125- related_object : Option < InteractiveObject < ' gc > > ,
126- delta : i32 ,
127- ) -> Self {
128- let local_pos = target. global_to_local ( * context. mouse_position ) ;
129-
130- Self :: Mouse {
131- local_x : local_pos. 0 . to_pixels ( ) ,
132- local_y : local_pos. 1 . to_pixels ( ) ,
133- movement_x : 0.0 , //TODO: Implement mouselocking.
134- movement_y : 0.0 ,
135- related_object,
136- modifiers : KeyModifiers :: from_current_keys ( context) ,
137- button_down : context. input . is_mouse_down ( ) ,
138- delta,
139- }
140- }
141- }
142-
14345/// Represents data fields of an event that can be fired on an object that
14446/// implements `IEventDispatcher`.
14547#[ derive( Clone , Collect , Debug ) ]
@@ -170,14 +72,11 @@ pub struct Event<'gc> {
17072
17173 /// The name of the event being triggered.
17274 event_type : AvmString < ' gc > ,
173-
174- /// The event's data set.
175- event_data : EventData < ' gc > ,
17675}
17776
17877impl < ' gc > Event < ' gc > {
17978 /// Construct a new event of a given type.
180- pub fn new < S > ( event_type : S , event_data : EventData < ' gc > ) -> Self
79+ pub fn new < S > ( event_type : S ) -> Self
18180 where
18281 S : Into < AvmString < ' gc > > ,
18382 {
@@ -190,7 +89,6 @@ impl<'gc> Event<'gc> {
19089 event_phase : EventPhase :: AtTarget ,
19190 target : None ,
19291 event_type : event_type. into ( ) ,
193- event_data,
19492 }
19593 }
19694
@@ -272,18 +170,6 @@ impl<'gc> Event<'gc> {
272170 pub fn set_current_target ( & mut self , current_target : Object < ' gc > ) {
273171 self . current_target = Some ( current_target)
274172 }
275-
276- pub fn event_data ( & self ) -> & EventData < ' gc > {
277- & self . event_data
278- }
279-
280- pub fn event_data_mut ( & mut self ) -> & mut EventData < ' gc > {
281- & mut self . event_data
282- }
283-
284- pub fn set_event_data ( & mut self , event_data : EventData < ' gc > ) {
285- self . event_data = event_data;
286- }
287173}
288174
289175/// A set of handlers organized by event type, priority, and order added.
0 commit comments