Skip to content

Commit 6fe83ab

Browse files
uauakjarosh
authored andcommitted
avm2: Dispatch hover events while dragging
1 parent 558a0bc commit 6fe83ab

File tree

11 files changed

+148
-3
lines changed

11 files changed

+148
-3
lines changed

core/src/player.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,15 +1628,15 @@ impl Player {
16281628
&& !InteractiveObject::option_ptr_eq(cur_over_object, new_over_object)
16291629
{
16301630
// If the mouse button is down, the object the user clicked on grabs the focus
1631-
// and fires "drag" events. Other objects are ignored.
1631+
// and fires "drag" events.
16321632
if context.input.is_mouse_down(MouseButton::Left) {
16331633
context.mouse_data.hovered = new_over_object;
16341634
if let Some(down_object) = context.mouse_data.pressed {
16351635
if InteractiveObject::option_ptr_eq(
16361636
context.mouse_data.pressed,
16371637
cur_over_object,
16381638
) {
1639-
// Dragged from outside the clicked object to the inside.
1639+
// Dragged from inside the clicked object to the outside.
16401640
events.push((
16411641
down_object,
16421642
ClipEvent::DragOut {
@@ -1647,7 +1647,7 @@ impl Player {
16471647
context.mouse_data.pressed,
16481648
new_over_object,
16491649
) {
1650-
// Dragged from inside the clicked object to the outside.
1650+
// Dragged from outside the clicked object to the inside.
16511651
events.push((
16521652
down_object,
16531653
ClipEvent::DragOver {
@@ -1656,6 +1656,36 @@ impl Player {
16561656
));
16571657
}
16581658
}
1659+
1660+
// While dragging, dispatch hover roll events only for AVM2 targets.
1661+
if let Some(cur_over_object) = cur_over_object {
1662+
if cur_over_object
1663+
.as_displayobject()
1664+
.movie()
1665+
.is_action_script_3()
1666+
{
1667+
events.push((
1668+
cur_over_object,
1669+
ClipEvent::RollOut {
1670+
to: new_over_object,
1671+
},
1672+
));
1673+
}
1674+
}
1675+
if let Some(new_over_object) = new_over_object {
1676+
if new_over_object
1677+
.as_displayobject()
1678+
.movie()
1679+
.is_action_script_3()
1680+
{
1681+
events.push((
1682+
new_over_object,
1683+
ClipEvent::RollOver {
1684+
from: cur_over_object,
1685+
},
1686+
));
1687+
}
1688+
}
16591689
} else {
16601690
// The mouse button is up, so fire rollover states for the object we are hovering over.
16611691
// Rolled out of the previous object.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{ "type": "MouseMove", "pos": [20, 20] },
3+
{ "type": "MouseDown", "pos": [20, 20], "btn": "Left" },
4+
{ "type": "MouseMove", "pos": [120, 40] },
5+
{ "type": "MouseMove", "pos": [195, 20] },
6+
{ "type": "MouseUp", "pos": [195, 20], "btn": "Left" },
7+
{ "type": "Wait" }
8+
]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
startDrag
2+
stopDrag
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Test {
2+
static function main() {
3+
var dragger:MovieClip = _root.createEmptyMovieClip("dragger", 1);
4+
dragger.beginFill(0xCC3333, 100);
5+
dragger.moveTo(0, 0);
6+
dragger.lineTo(60, 0);
7+
dragger.lineTo(60, 60);
8+
dragger.lineTo(0, 60);
9+
dragger.lineTo(0, 0);
10+
dragger.endFill();
11+
dragger._x = 10; dragger._y = 10;
12+
13+
var target:MovieClip = _root.createEmptyMovieClip("target", 2);
14+
target.beginFill(0x33CC66, 100);
15+
target.moveTo(0, 0);
16+
target.lineTo(80, 0);
17+
target.lineTo(80, 80);
18+
target.lineTo(0, 80);
19+
target.lineTo(0, 0);
20+
target.endFill();
21+
target._x = 110; target._y = 30;
22+
23+
target.onRollOver = function() { trace("OVER"); };
24+
target.onRollOut = function() { trace("OUT"); };
25+
26+
dragger.onPress = function() {
27+
this.startDrag(false);
28+
trace("startDrag");
29+
};
30+
dragger.onRelease = dragger.onReleaseOutside = function() {
31+
this.stopDrag();
32+
trace("stopDrag");
33+
};
34+
}
35+
}
541 Bytes
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
num_ticks = 1
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package {
2+
import flash.display.MovieClip;
3+
import flash.display.Sprite;
4+
import flash.events.Event;
5+
import flash.events.MouseEvent;
6+
import flash.system.fscommand;
7+
8+
public class Test extends MovieClip {
9+
private var dragger:MovieClip;
10+
private var target:MovieClip;
11+
private var sawOver:Boolean = false;
12+
13+
public function Test() {
14+
addEventListener(Event.ADDED_TO_STAGE, onAdded);
15+
}
16+
17+
private function onAdded(_:Event):void {
18+
removeEventListener(Event.ADDED_TO_STAGE, onAdded);
19+
20+
dragger = new MovieClip();
21+
dragger.graphics.beginFill(0xCC3333);
22+
dragger.graphics.drawRect(0, 0, 100, 100);
23+
dragger.graphics.endFill();
24+
dragger.x = 0;
25+
dragger.y = 0;
26+
dragger.buttonMode = true;
27+
addChild(dragger);
28+
29+
target = new MovieClip();
30+
target.graphics.beginFill(0x33CC66);
31+
target.graphics.drawRect(0, 0, 120, 120);
32+
target.graphics.endFill();
33+
target.x = 200;
34+
target.y = 200;
35+
addChild(target);
36+
37+
target.buttonMode = true;
38+
target.mouseChildren = false;
39+
40+
target.addEventListener(MouseEvent.MOUSE_OVER, function(e:MouseEvent):void {
41+
trace("OVER buttonDown=" + e.buttonDown);
42+
sawOver = true;
43+
});
44+
target.addEventListener(MouseEvent.MOUSE_OUT, function(e:MouseEvent):void {
45+
trace("OUT buttonDown=" + e.buttonDown);
46+
if (sawOver) {
47+
fscommand("quit");
48+
}
49+
});
50+
51+
dragger.addEventListener(MouseEvent.MOUSE_DOWN, function(_:MouseEvent):void {
52+
dragger.startDrag(false);
53+
trace("startDrag");
54+
});
55+
}
56+
}
57+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{ "type": "MouseMove", "pos": [10, 10] },
3+
{ "type": "MouseDown", "pos": [10, 10], "btn": "Left" },
4+
{ "type": "MouseMove", "pos": [210, 210] },
5+
{ "type": "MouseMove", "pos": [360, 40] },
6+
{ "type": "MouseUp", "pos": [360, 40], "btn": "Left" },
7+
{ "type": "Wait" }
8+
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
startDrag
2+
OVER buttonDown=true
3+
OUT buttonDown=true
1.37 KB
Binary file not shown.

0 commit comments

Comments
 (0)