summaryrefslogtreecommitdiff
path: root/assets/javascripts/rectangles/util
diff options
context:
space:
mode:
Diffstat (limited to 'assets/javascripts/rectangles/util')
-rw-r--r--assets/javascripts/rectangles/util/constants.js46
-rw-r--r--assets/javascripts/rectangles/util/mouse.js13
2 files changed, 58 insertions, 1 deletions
diff --git a/assets/javascripts/rectangles/util/constants.js b/assets/javascripts/rectangles/util/constants.js
new file mode 100644
index 0000000..db4eebf
--- /dev/null
+++ b/assets/javascripts/rectangles/util/constants.js
@@ -0,0 +1,46 @@
+var FRONT = 0x1, BACK = 0x2, LEFT = 0x4, RIGHT = 0x8, FLOOR = 0x10, CEILING = 0x20
+ FRONT_BACK = FRONT | BACK, LEFT_RIGHT = LEFT | RIGHT, FLOOR_CEILING = FLOOR | CEILING
+
+var height_min = 200,
+ height_max = 2000,
+ side_min = 10,
+ side_max = 5000,
+ resize_margin = 8
+
+var painting_distance_from_wall = 8
+
+var wall_rotation = {}
+wall_rotation[FRONT] = PI
+wall_rotation[BACK] = 0
+wall_rotation[LEFT] = HALF_PI
+wall_rotation[RIGHT] = -HALF_PI
+
+
+
+
+
+
+function sidesToString(sides){
+ var s = ""
+ if (sides & FRONT) s += "front "
+ if (sides & BACK) s += "back "
+ if (sides & LEFT) s += "left "
+ if (sides & RIGHT) s += "right "
+ return s
+}
+
+function side_direction (a, b) {
+ if (a === b) return 0
+ if ((a | b) === FRONT_BACK) return 0
+ if ((a | b) === LEFT_RIGHT) return 0
+ switch (a) {
+ case FRONT:
+ return b & LEFT ? -1 : 1
+ case BACK:
+ return b & RIGHT ? -1 : 1
+ case LEFT:
+ return b & FRONT ? -1 : 1
+ case RIGHT:
+ return b & BACK ? -1 : 1
+ }
+}
diff --git a/assets/javascripts/rectangles/util/mouse.js b/assets/javascripts/rectangles/util/mouse.js
index ef6fa0f..16ca101 100644
--- a/assets/javascripts/rectangles/util/mouse.js
+++ b/assets/javascripts/rectangles/util/mouse.js
@@ -58,6 +58,14 @@ function mouse (opt) {
base.bind()
}
+ base.on = function(){
+ base.tube.on.apply(base.tube, arguments)
+ }
+
+ base.off = function(){
+ base.tube.off.apply(base.tube, arguments)
+ }
+
base.bind = function(){
if (opt.el) {
opt.el.addEventListener("mousedown", base.mousedown)
@@ -66,9 +74,12 @@ function mouse (opt) {
window.addEventListener("mousemove", base.mousemove)
window.addEventListener("mouseup", base.mouseup)
}
+
base.bind_el = function(el){
el.addEventListener("mousedown", base.mousedown)
- // todo.. need a way to remove this event potentially?
+ }
+ base.unbind_el = function(el){
+ el.removeEventListener("mousedown", base.mousedown)
}
function positionFromMouse(e) {