on master help sign in
Update mouse code.
62d30f2evancz
core/Mouse.elmnew file+37
@@ -0,0 +1,37 @@
1+
2+module Mouse where
3+
4+-- The current mouse position.
5+position : Signal (Int,Int)
6+position = Native.Mouse.position
7+
8+-- The current x-coordinate of the mouse.
9+x : Signal Int
10+x = Native.Mouse.x
11+
12+-- The current y-coordinate of the mouse.
13+y : Signal Int
14+y = Native.Mouse.y
15+
16+
17+-- The current state of the left mouse-button.
18+-- True when the button is down, and false otherwise.
19+isDown : Signal Bool
20+isDown = Native.Mouse.isDown
21+
22+-- True immediately after the left mouse-button has been clicked,
23+-- and false otherwise.
24+isClicked : Signal Bool
25+isClicked = Native.Mouse.isClicked
26+
27+
28+-- Always equal to unit. Event triggers on every mouse click.
29+clicks : Signal ()
30+clicks = Native.Mouse.clicks
31+
32+-- Determine whether an element has been clicked. The resulting pair
33+-- is a signal of booleans that is true when its paired element has
34+-- been clicked. The signal is True immediately after the left
35+-- mouse-button has been clicked, and false otherwise.
36+isClickedOn : Element -> (Element, Signal Bool)
37+isClickedOn = Native.Mouse.isClickedOn
core/Native/Mouse.js+14−47
@@ -1,44 +1,18 @@
1−/*! Mouse
2− !*/
3
1
4−Elm.Mouse = function() {
2+function nativeMouse(elm) {
5− /*[Position]*/
6−
7− /** position : Signal (Int,Int)
8− The current mouse position.
9− **/
10 var position = Elm.Signal.constant(Value.Tuple(0,0));
3 var position = Elm.Signal.constant(Value.Tuple(0,0));
11 position.defaultNumberOfKids = 2;
4 position.defaultNumberOfKids = 2;
12
5
13− /** x : Signal Int
6+ // do not get rid of x and y. By setting their default number
14− The current x-coordinate of the mouse.
7+ // of kids, it is possible to detatch the mouse listeners if
15− **/
8+ // they are not needed.
16− var x = Elm.Signal.lift(function(p){return p[1];})(position);
9+ var x = Elm.Signal.lift(function(p){return p._0})(position);
17 x.defaultNumberOfKids = 0;
10 x.defaultNumberOfKids = 0;
18−
19− /** y : Signal Int
20− The current y-coordinate of the mouse.
21− **/
22− var y = Elm.Signal.lift(function(p){return p[2];})(position);
11+ var y = Elm.Signal.lift(function(p){return p._1})(position);
23 y.defaultNumberOfKids = 0;
12 y.defaultNumberOfKids = 0;
24
13
25− /*[Button Status]*/
26−
27− /** isDown : Signal Bool
28− The current state of the left mouse-button.
29− True when the button is down, and false otherwise.
30− **/
31 var isDown = Elm.Signal.constant(false);
14 var isDown = Elm.Signal.constant(false);
32−
33− /** isClicked : Signal Bool
34− True immediately after the left mouse-button has been clicked,
35− and false otherwise.
36− **/
37 var isClicked = Elm.Signal.constant(false);
15 var isClicked = Elm.Signal.constant(false);
38−
39− /** clicks : Signal ()
40− Always equal to unit. Event triggers on every mouse click.
41− **/
42 var clicks = Elm.Signal.constant(Value.Tuple());
16 var clicks = Elm.Signal.constant(Value.Tuple());
43
17
44 function getXY(e) {
18 function getXY(e) {
@@ -80,12 +54,6 @@ Elm.Mouse = function() {
80 this.removeEventListener('mousemove',arguments.callee,false);
54 this.removeEventListener('mousemove',arguments.callee,false);
81 });
55 });
82
56
83− /** isClickedOn : Element -> (Element, Signal Bool)
84− Determine whether an element has been clicked. The resulting pair
85− is a signal of booleans that is true when its paired element has
86− been clicked. The signal is True immediately after the left
87− mouse-button has been clicked, and false otherwise.
88− **/
89 var clickedOn = function(elem) {
57 var clickedOn = function(elem) {
90 var node = Render.render(elem);
58 var node = Render.render(elem);
91 var click = Elm.Signal.constant(false);
59 var click = Elm.Signal.constant(false);
@@ -95,12 +63,11 @@ Elm.Mouse = function() {
95 });
63 });
96 return Value.Tuple(Value.wrap(node), click);
64 return Value.Tuple(Value.wrap(node), click);
97 };
65 };
98− return {position: position,
66+ elm.Native.Mouse = {position: position,
99− x:x,
67+ x:x,
100− y:y,
68+ y:y,
101− isClicked: isClicked,
69+ isClicked: isClicked,
102− isDown: isDown,
70+ isDown: isDown,
103− clicks: clicks,
71+ clicks: clicks,
104− isClickedOn: clickedOn
72+ isClickedOn: clickedOn};
105− };
106− }();
73+}