summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-08-27 12:44:17 -0400
committerJules Laplace <jules@okfoc.us>2015-08-27 12:44:17 -0400
commit464bd3bfe74695955239e176dce8fe885bba8ac3 (patch)
treecab1f79d312abdb4697ad822949597e64b46943d
parent685d5fd7b32ac868a0b2d8ac8a2a1b4120f274cf (diff)
arrow tool can translate walls orthogonally
-rw-r--r--public/assets/javascripts/rectangles/engine/map/tools/arrow.js47
-rw-r--r--public/assets/javascripts/rectangles/engine/shapes/ortho.js16
-rw-r--r--public/assets/javascripts/rectangles/engine/shapes/polyline.js28
-rw-r--r--public/assets/javascripts/ui/blueprint/BlueprintToolbar.js2
-rw-r--r--public/assets/javascripts/ui/blueprint/BlueprintUploader.js3
5 files changed, 89 insertions, 7 deletions
diff --git a/public/assets/javascripts/rectangles/engine/map/tools/arrow.js b/public/assets/javascripts/rectangles/engine/map/tools/arrow.js
index 00478d4..0b0557e 100644
--- a/public/assets/javascripts/rectangles/engine/map/tools/arrow.js
+++ b/public/assets/javascripts/rectangles/engine/map/tools/arrow.js
@@ -3,16 +3,33 @@
var ArrowTool = MapTool.extend(function(base){
var exports = {}
- var selected_point = null, original_point = null, selected_shape = null
+ var selected_point = null, selected_segment = null, original_point = null, selected_shape = null
+ var src_points, dest_points
exports.down = function(e, cursor){
last_point.a = cursor.x.a
last_point.b = cursor.y.a
var p = shapes.findClosestPoint(last_point)
- if (p) {
+ if (p && p.shape.type() !== "ortho") {
selected_shape = p.shape
selected_point = p.point
original_point = selected_point.clone()
+ return
+ }
+ var segment = shapes.findClosestSegment(last_point)
+ if (segment) {
+ document.body.style.cursor = "pointer"
+
+ selected_segment = segment
+ console.log(segment.head, segment.tail)
+ selected_shape = segment.shape
+ src_points = segment.shape.cloneSegment( segment )
+ dest_points = segment.shape.getSegment( segment )
+
+ last_point.a = segment.x
+ last_point.b = segment.y
+ cursor.x.a = cursor.x.b = last_point.a
+ cursor.y.a = cursor.y.b = last_point.b
}
else {
map.ui.set_drag_tool("position")
@@ -28,6 +45,15 @@ var ArrowTool = MapTool.extend(function(base){
last_point.assign(p.point)
cursor.x.a = cursor.x.b = last_point.a
cursor.y.a = cursor.y.b = last_point.b
+ return
+ }
+ var segment = shapes.findClosestSegment(last_point)
+ if (segment) {
+ document.body.style.cursor = "pointer"
+ last_point.a = segment.x
+ last_point.b = segment.y
+ cursor.x.a = cursor.x.b = last_point.a
+ cursor.y.a = cursor.y.b = last_point.b
}
else {
document.body.style.cursor = "crosshair"
@@ -35,13 +61,22 @@ var ArrowTool = MapTool.extend(function(base){
}
exports.drag = function(e, cursor){
- selected_point.a = original_point.a + cursor.x.magnitude()
- selected_point.b = original_point.b + cursor.y.magnitude()
- selected_shape.rebuild()
+ if (selected_point) {
+ selected_point.a = original_point.a + cursor.x.magnitude()
+ selected_point.b = original_point.b + cursor.y.magnitude()
+ selected_shape.rebuild()
+ }
+ else if (selected_segment) {
+ selected_shape.translateSegment(
+ src_points, dest_points,
+ cursor.x.magnitude(), cursor.y.magnitude()
+ )
+ selected_shape.rebuild()
+ }
}
exports.up = function(e, cursor){
- selected_point = selected_shape = original_point = null
+ selected_point = selected_shape = selected_segment = original_point = null
}
return exports
diff --git a/public/assets/javascripts/rectangles/engine/shapes/ortho.js b/public/assets/javascripts/rectangles/engine/shapes/ortho.js
index 8a8f928..c1acae5 100644
--- a/public/assets/javascripts/rectangles/engine/shapes/ortho.js
+++ b/public/assets/javascripts/rectangles/engine/shapes/ortho.js
@@ -33,6 +33,22 @@ var OrthoPolyline = Polyline.extend(function(base){
}
}
}
+ exports.translateSegment = function(src, dest, dx, dy) {
+ if (src[0].a == src[1].a) {
+ dest[0].a = src[0].a + dx
+ dest[1].a = src[1].a + dx
+ if (src.length == 3) {
+ dest[2].a = src[2].a + dx
+ }
+ }
+ else {
+ dest[0].b = src[0].b + dy
+ dest[1].b = src[1].b + dy
+ if (src.length == 3) {
+ dest[2].b = src[2].b + dy
+ }
+ }
+ }
exports.close = function(){
this.points[this.points.length] = this.points[0]
this.closed = true
diff --git a/public/assets/javascripts/rectangles/engine/shapes/polyline.js b/public/assets/javascripts/rectangles/engine/shapes/polyline.js
index 65e22ad..579d0ea 100644
--- a/public/assets/javascripts/rectangles/engine/shapes/polyline.js
+++ b/public/assets/javascripts/rectangles/engine/shapes/polyline.js
@@ -46,6 +46,32 @@ var Polyline = Fiber.extend(function(base){
var clone = this.instantiate()
clone.points = this.points.concat()
}
+ exports.getSegment = function(segment){
+ var seg = [
+ this.points[segment.head],
+ this.points[segment.tail],
+ ]
+ if (segment.head == 0) {
+ seg.push( this.lastPoint() )
+ }
+ else if (segment.tail == this.points.length-1) {
+ seg.push( this.firstPoint() )
+ }
+ return seg
+ }
+ exports.cloneSegment = function(segment){
+ return this.getSegment(segment).map(function(point){ return point.clone() })
+ }
+ exports.translateSegment = function(src, dest, dx, dy){
+ dest[0].a = src[0].a + dx
+ dest[0].b = src[0].b + dy
+ dest[1].a = src[1].a + dx
+ dest[1].b = src[1].b + dy
+ if (src.length == 3) {
+ dest[2].a = src[2].a + dx
+ dest[2].b = src[2].b + dy
+ }
+ }
exports.hasPointNear = function(p){
var point
for (var i = 0; i < this.points.length; i++){
@@ -156,10 +182,12 @@ var Polyline = Fiber.extend(function(base){
exports.serialize = function(){
return {
type: this.type(),
+ closed: this.closed,
points: this.points.map(function(point){ return [point.a, point.b] }),
}
}
exports.deserialize = function(data){
+ this.closed = data.closed || false
this.points = (data.points || data).map(function(point){ return new vec2(point[0], point[1]) })
}
exports.reset = function(){
diff --git a/public/assets/javascripts/ui/blueprint/BlueprintToolbar.js b/public/assets/javascripts/ui/blueprint/BlueprintToolbar.js
index 7721298..8b0a08f 100644
--- a/public/assets/javascripts/ui/blueprint/BlueprintToolbar.js
+++ b/public/assets/javascripts/ui/blueprint/BlueprintToolbar.js
@@ -24,7 +24,7 @@ var BlueprintToolbar = View.extend({
this.$eraserMode = this.$('[data-role=eraser-mode]')
this.$startPositionMode = this.$('[data-role=start-position-mode]')
- this.orthoPolylineMode()
+ this.arrowMode()
},
showUploader: function(){
diff --git a/public/assets/javascripts/ui/blueprint/BlueprintUploader.js b/public/assets/javascripts/ui/blueprint/BlueprintUploader.js
index dc3c281..aa62a4c 100644
--- a/public/assets/javascripts/ui/blueprint/BlueprintUploader.js
+++ b/public/assets/javascripts/ui/blueprint/BlueprintUploader.js
@@ -66,6 +66,9 @@ var BlueprintUploader = UploadView.extend({
var media = $el.data("media")
this.hide()
this.parent.scaler.pick(media)
+ if (media.slug) {
+ window.history.pushState(null, document.title, "/blueprint/" + media.slug)
+ }
},
destroy: function(e){