summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui
diff options
context:
space:
mode:
authorJulie Lala <jules@okfoc.us>2014-07-17 03:04:28 -0400
committerJulie Lala <jules@okfoc.us>2014-07-17 03:04:28 -0400
commitf20841988ccd27780d3801e4a6c32bf9afcc9368 (patch)
tree43d4db07f0dfc44ac1e41db25397a9982db8850f /public/assets/javascripts/ui
parentd81c96616859a57d5d5d63a6ae7b1492a5c4974a (diff)
conversions between feet/meters/pixels
Diffstat (limited to 'public/assets/javascripts/ui')
-rw-r--r--public/assets/javascripts/ui/builder/BuilderInfo.js112
-rw-r--r--public/assets/javascripts/ui/builder/BuilderView.js1
2 files changed, 102 insertions, 11 deletions
diff --git a/public/assets/javascripts/ui/builder/BuilderInfo.js b/public/assets/javascripts/ui/builder/BuilderInfo.js
index 53a122d..9bbd385 100644
--- a/public/assets/javascripts/ui/builder/BuilderInfo.js
+++ b/public/assets/javascripts/ui/builder/BuilderInfo.js
@@ -5,28 +5,35 @@ var BuilderInfo = View.extend({
events: {
"keydown": 'stopPropagation',
"change [name=x]": 'changePosition',
- "change [name=z]": 'changePosition',
+ "change [name=y]": 'changePosition',
"change [name=width]": 'changeDimensions',
"change [name=depth]": 'changeDimensions',
"change [name=height]": 'changeDimensions',
"change [name=units]": 'changeUnits',
"change [name=resolution]": 'changeResolution',
- "change [name=camera-height]": 'changeCameraHeight',
+ "change [name=viewHeight]": 'changeViewHeight',
},
initialize: function(opt){
this.parent = opt.parent
this.$x = this.$("[name=x]")
- this.$z = this.$("[name=z]")
+ this.$y = this.$("[name=y]")
this.$width = this.$("[name=width]")
this.$depth = this.$("[name=depth]")
this.$height = this.$("[name=height]")
this.$units = this.$("[name=units]")
- this.$resolution = this.$("[name=resolution]")
- this.$cameraHeight = this.$("[name=camera-height]")
+ this.$viewHeight = this.$("[name=viewHeight]")
+ this.$unitName = this.$(".unitName")
app.on("builder-pick-room", this.pick.bind(this))
app.on("builder-destroy-room", this.destroy.bind(this))
},
+
+ load: function(data){
+ this.$viewHeight.unitVal( data.viewHeight || app.defaults.viewHeight )
+ this.$units.val( "ft" )
+ this.$unitName.html( "ft" )
+ this.$resolution.val( app.defaults.footResolution )
+ },
toggle: function(state){
this.$el.toggleClass("active", state)
@@ -44,11 +51,11 @@ var BuilderInfo = View.extend({
pick: function(room){
this.room = room
- this.$width.val( room.rect.x.length() )
- this.$depth.val( room.rect.y.length() )
- this.$height.val( room.height )
- this.$x.val( room.rect.x.a )
- this.$z.val( room.rect.y.a )
+ this.$width.unitVal( room.rect.x.length() )
+ this.$depth.unitVal( room.rect.y.length() )
+ this.$height.unitVal( room.height )
+ this.$x.unitVal( room.rect.x.a )
+ this.$y.unitVal( room.rect.y.a )
console.log(room)
},
@@ -59,12 +66,95 @@ var BuilderInfo = View.extend({
},
changeDimensions: function(){
+// this.$width.unitVal( room.rect.x.length() )
+// this.$depth.unitVal( room.rect.y.length() )
+// this.$height.unitVal( room.height )
},
changeUnits: function(){
+ app.units = this.$units.val()
+ this.$('.units').resetUnitVal()
},
- changeCameraHeight: function(){
+ changeViewHeight: function(){
+ window.viewHeight = this.$viewHeight.unitVal( )
},
})
+
+$.fn.resetUnitVal = function(){
+ this.each(function(){
+ var n = $(this).data("px")
+ $(this).unitVal(n)
+ });
+}
+
+$.fn.unitVal = function(n){
+ var s
+ if (typeof n === "undefined") {
+ s = $(this).val()
+ n = stringToMeasurement( s )
+ }
+ s = measurementToString( n )
+ $(this).val( s ).data("px", n)
+ return n
+}
+
+function measurementToString( n ) {
+ var s, ft, inch
+ switch (app.units) {
+ case 'm':
+ s = round(n/36 * 0.3048 * 100) / 100 + " m"
+ break
+ case 'ft':
+ ft = floor(n / 36)
+ inch = abs(round((n % 36) / 3))
+ s = ft + "'"
+ if (inch > 0) {
+ s += " " + inch + '"'
+ }
+ break
+ case 'px':
+ default:
+ s = round(n) + " px"
+ break
+ }
+ return s
+}
+function stringToMeasurement( s ) {
+ var ft, inch, ft_in, type
+ if (s.indexOf("'") !== -1 || s.indexOf('"') !== -1 || s.indexOf('ft') !== -1) {
+ ft_in = s.match(/[0-9.]+/g)
+ if (ft_in.length >= 2) {
+ ft = parseFloat( ft_in[0] )
+ inch = parseFloat( ft_in[1] )
+ }
+ else if (ft_in.length == 1) {
+ if (s.indexOf('"') !== -1) {
+ ft = 0
+ inch = parseFloat( ft_in[0] )
+ }
+ else {
+ ft = parseFloat( ft_in[0] )
+ inch = 0
+ }
+ }
+ else {
+ ft = inch = 0
+ }
+ n = ft * 36 + inch * 3
+ }
+ else if (type === "m") {
+ n = parseFloat(s.match(/[0-9.]+/)) * 36 / 0.3048
+ }
+ else if (s.indexOf("px") !== -1) {
+ n = parseFloat(s.match(/[0-9.]+/))
+ }
+ else {
+ n = abs( stringToMeasurement( s + app.units ) )
+ }
+ if (s.indexOf('-') !== -1) {
+ n *= -1
+ }
+ return n
+} \ No newline at end of file
diff --git a/public/assets/javascripts/ui/builder/BuilderView.js b/public/assets/javascripts/ui/builder/BuilderView.js
index 7a92738..555cd58 100644
--- a/public/assets/javascripts/ui/builder/BuilderView.js
+++ b/public/assets/javascripts/ui/builder/BuilderView.js
@@ -26,6 +26,7 @@ var BuilderView = View.extend({
ready: function(data){
this.settings.load(data)
+ this.info.load(data)
},
hideExtras: function(){