diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-05-01 12:52:55 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-05-01 15:09:41 -0400 |
| commit | b9f007562712688612269fad9c71df2d4981acaa (patch) | |
| tree | 968eddddbceb8d54fe5abe54b6b287cc77a5cc46 /assets/javascripts/rectangles/map/ui.js | |
| parent | e1369a3cd91a7512b1aa643388fd21435b6c76fd (diff) | |
resize rooms
Diffstat (limited to 'assets/javascripts/rectangles/map/ui.js')
| -rw-r--r-- | assets/javascripts/rectangles/map/ui.js | 43 |
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){ |
