-
Notifications
You must be signed in to change notification settings - Fork 2
/
of.mouse.pd
37 lines (37 loc) · 1.99 KB
/
of.mouse.pd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#N canvas 0 78 849 700 12;
#X obj 22 -22 inlet;
#X obj 22 689 list split 2;
#X obj 22 735 outlet;
#X obj 129 735 outlet;
#X obj 62 712 route bang;
#X text 709 656 R.I;
#X obj 22 11 ofelia d mouse\$0 \; local log = ofLog("ofMouseMoved")
\; local canvas = ofCanvas(this) \; local order \, normalized = 50
\, false \; local x \, y \, z \; \; function M.new() \; local args
= canvas:getArgs() \; if #args == 1 then order = args[1] end \; if
#args == 2 then order \, normalized = args[1] \, args[2] ~= 0 \; end
\; ofWindow.addListener("mouseMoved" \, this \, order) \; ofWindow.addListener("mousePressed"
\, this \, order) \; ofWindow.addListener("mouseReleased" \, this \,
order) \; ofWindow.addListener("mouseDragged" \, this \, order) \;
end \; \; function M.setOrder(f) \; order = f \; end \; \; function
M.setEnabled(b) \; enabled = b ~= 0 \; end \; \; function M.free()
\; ofWindow.removeListener("mouseMoved" \, this) \; ofWindow.removeListener("mousePressed"
\, this) \; ofWindow.removeListener("mouseReleased" \, this) \; ofWindow.removeListener("mouseDragged"
\, this) \; end \; function M.mouseMoved(e) \; return (M.mapxy(ofTable(e.x
\, e.y))) end \; function M.mouseDragged(e) \; return (M.mapxy(ofTable(e.x
\, e.y))) end \; function M.mousePressed(e) \; return (M.mapxy(ofTable(e.x
\, e.y \, e.button + 1))) end \; function M.mouseReleased(e) \; return
(M.mapxy(ofTable(e.x \, e.y \, 0))) end \; function M.mapxy(l) \; if
not normalized then if order < 0 or order > 1000 then x = math.floor(l[1])
y = math.floor(l[2]) else \; x= (math.floor(ofMap (l[1] \, 0 \, ofGetWidth()
\, -ofGetWidth()*0.5 \, ofGetWidth()*0.5))) \; y= (math.floor(ofMap
(l[2] \, 0 \, ofGetHeight() \, ofGetHeight()*0.5 \, -ofGetHeight()*0.5)))
end \; z = l[3] else \; x=ofClamp(ofMap (l[1] \, 0 \, ofGetWidth()
\, 0 \, 1) \, 0 \, 1) \; y=ofClamp(ofMap (l[2] \, 0 \, ofGetHeight()
\, 0 \, 1) \, 0 \, 1) end \; return ofTable(x \, y \, z)end \;;
#X f 110;
#X connect 0 0 6 0;
#X connect 1 0 2 0;
#X connect 1 1 4 0;
#X connect 4 1 3 0;
#X connect 6 0 1 0;