summaryrefslogtreecommitdiff
path: root/public/assets/javascripts
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-11-10 16:21:01 -0500
committerJules Laplace <jules@okfoc.us>2014-11-10 16:21:01 -0500
commit2bdfa57b147f461d002865b6e7973033ca9987b7 (patch)
treefd87abf345c2e94e53b955010a7f25f1c1fc54c3 /public/assets/javascripts
parent8e6693f0b98733b7958a33948e8705c42f35c571 (diff)
attempt to place something even if it’s “too big” for the wall
Diffstat (limited to 'public/assets/javascripts')
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/types/_object.js40
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/types/image.js21
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/types/video.js22
-rw-r--r--public/assets/javascripts/ui/builder/BuilderInfo.js1
4 files changed, 44 insertions, 40 deletions
diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/_object.js b/public/assets/javascripts/rectangles/engine/scenery/types/_object.js
index 10ba2b0..c3fd6f3 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/types/_object.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/types/_object.js
@@ -28,6 +28,46 @@ Scenery.types.base = Fiber.extend(function(base){
this.dimensions = this.naturalDimensions.clone().mul(this.scale)
},
+ place: function(opt){
+ console.log(opt)
+ if (opt.data) {
+ if (opt.wall) {
+ var position = opt.wall.mxToPosition(opt.data.position)
+ opt.index = opt.wall.surface.index_for_x( position.a, 0 )
+ }
+ this.set_wall(opt)
+ this.deserialize(opt.data)
+ }
+ else {
+ this.set_wall(opt)
+ if (this.wall && ! this.bounds) {
+ this.find_minimum_scale(opt)
+ if (! this.bounds) return
+ }
+
+ this.recenter()
+ if (opt.position) {
+ this.translateTo(opt.position)
+ }
+ var mx_position = this.wall.positionToMx( this.position, this.dimensions )
+ this.mx.move(mx_position)
+ }
+ },
+
+ find_minimum_scale: function(opt){
+ var bounds = this.wall.surface.bounds_at_index_with_dimensions(opt.index || 0, new vec2(50, 50))
+ var scale = 1
+ if (! bounds || bounds.width() < 50 || bounds.height < 50) return
+ if (this.naturalDimensions.a > bounds.width()) {
+ scale = bounds.width() / (this.naturalDimensions.a + 10)
+ }
+ if (this.naturalDimensions.b > bounds.height()) {
+ scale = Math.min(scale, bounds.height() / (this.naturalDimensions.b + 10))
+ }
+ this.set_scale(scale)
+ this.set_wall(opt)
+ },
+
recenter: function () {
if (! this.bounds) return
var center = this.bounds.center()
diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/image.js b/public/assets/javascripts/rectangles/engine/scenery/types/image.js
index 848f8d4..0e5e77c 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/types/image.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/types/image.js
@@ -13,26 +13,7 @@ Scenery.types.image = Scenery.types.base.extend(function(base){
this.build()
this.bind()
-
- if (opt.data) {
- if (opt.wall) {
- var position = opt.wall.mxToPosition(opt.data.position)
- opt.index = opt.wall.surface.index_for_x( position.a, 0 )
- }
- this.set_wall(opt)
- this.deserialize(opt.data)
- }
- else {
- this.set_wall(opt)
- if (this.bounds) {
- this.recenter()
- if (opt.position) {
- this.translateTo(opt.position)
- }
- var mx_position = this.wall.positionToMx( this.position, this.dimensions )
- this.mx.move(mx_position)
- }
- }
+ this.place(opt)
},
build: function(){
diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/video.js b/public/assets/javascripts/rectangles/engine/scenery/types/video.js
index d83cc63..d1b1763 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/types/video.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/types/video.js
@@ -6,32 +6,14 @@ Scenery.types.video = Scenery.types.base.extend(function(base){
type: 'video',
init: function(opt){
+
opt.scale = opt.scale || (opt.data && opt.data.scale) || DEFAULT_PICTURE_WIDTH / max(DEFAULT_PICTURE_WIDTH, opt.media.width)
base.init.call(this, opt)
this.build()
this.bind()
-
- if (opt.data) {
- if (opt.wall) {
- var position = opt.wall.mxToPosition(opt.data.position)
- opt.index = opt.wall.surface.index_for_x( position.a, 0 )
- }
- this.set_wall(opt)
- this.deserialize(opt.data)
- }
- else {
- this.set_wall(opt)
- if (this.bounds) {
- this.recenter()
- if (opt.position) {
- this.translateTo(opt.position)
- }
- var mx_position = this.wall.positionToMx( this.position, this.dimensions )
- this.mx.move(mx_position)
- }
- }
+ this.place(opt)
},
build: function(){
diff --git a/public/assets/javascripts/ui/builder/BuilderInfo.js b/public/assets/javascripts/ui/builder/BuilderInfo.js
index e1c90c8..7606361 100644
--- a/public/assets/javascripts/ui/builder/BuilderInfo.js
+++ b/public/assets/javascripts/ui/builder/BuilderInfo.js
@@ -47,6 +47,7 @@ var BuilderInfo = View.extend({
this.$noSelection.toggle( ! this.room )
this.$el.toggleClass("active", state)
if (state) {
+ this.$viewHeight.unitVal( window.viewHeight )
this.parent.cursor.message("builder")
}
else {