summaryrefslogtreecommitdiff
path: root/assets/javascripts/rectangles/map/ui.js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/javascripts/rectangles/map/ui.js')
-rw-r--r--assets/javascripts/rectangles/map/ui.js43
1 files changed, 35 insertions, 8 deletions
diff --git a/assets/javascripts/rectangles/map/ui.js b/assets/javascripts/rectangles/map/ui.js
index caa2a81..d442c99 100644
--- a/assets/javascripts/rectangles/map/ui.js
+++ b/assets/javascripts/rectangles/map/ui.js
@@ -1,11 +1,16 @@
+var height_min = 200,
+ height_max = 2000,
+ side_min = 10,
+ side_max = 5000,
+ resize_margin = 8
map.ui = new function(){
var base = this
- var height_min = 200,
- height_max = 2000
- base.creating = base.dragging = false
+
+
+ base.creating = base.dragging = base.resizing = false
base.mouse = new mouse({
el: map.el,
@@ -44,8 +49,10 @@ map.ui = new function(){
return r.focused = r.rect.contains(cursor.x.a, cursor.y.a)
})
- if (intersects.length){
+ if (intersects.length) {
base.dragging = intersects[0]
+ base.resizing = base.dragging.rect.nearEdge(cursor.x.a, cursor.y.a, resize_margin / map.zoom)
+ base.dragging.rect.translation.sides = base.resizing
}
else {
base.creating = true
@@ -65,7 +72,24 @@ map.ui = new function(){
cursor.x.b = ((cursor.x.b/w)+0.5) * map.bounds.a / map.zoom + map.center.a
cursor.y.b = ((cursor.y.b/h)-0.5) * map.bounds.b / map.zoom - map.center.b
- if (base.dragging) {
+ if (base.resizing) {
+ var x_length = base.dragging.rect.x.length(),
+ y_length = base.dragging.rect.y.length()
+
+ if (base.resizing & LEFT) {
+ base.dragging.rect.translation.a = clamp( cursor.x.magnitude(), x_length - side_max, x_length - side_min )
+ }
+ if (base.resizing & RIGHT) {
+ base.dragging.rect.translation.a = clamp( cursor.x.magnitude(), side_min - x_length, side_max - x_length )
+ }
+ if (base.resizing & FRONT) {
+ base.dragging.rect.translation.b = clamp( cursor.y.magnitude(), y_length - side_max, y_length - side_min )
+ }
+ if (base.resizing & BACK) {
+ base.dragging.rect.translation.b = clamp( cursor.y.magnitude(), side_min - y_length, side_max - y_length )
+ }
+ }
+ else if (base.dragging) {
base.dragging.rect.translation.a = cursor.x.magnitude()
base.dragging.rect.translation.b = cursor.y.magnitude()
}
@@ -76,18 +100,21 @@ map.ui = new function(){
new_cursor.y.div(h).sub(0.5).mul(map.bounds.b / map.zoom).sub(map.center.b)
if (base.creating) {
- if (cursor.height() != 0 && cursor.width() != 0) {
+ if (cursor.height() > side_min && cursor.width() > side_min) {
cursor.x.abs().quantize(1)
cursor.y.abs().quantize(1)
clipper.add_room( cursor )
}
}
- if (base.dragging) {
+ if (base.resizing) {
+ base.dragging.rect.resize()
+ }
+ else if (base.dragging) {
base.dragging.rect.translate()
}
- base.creating = base.dragging = false
+ base.creating = base.dragging = base.resizing = false
}
function mousewheel (e, val, delta){