Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 49 additions & 10 deletions app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ Window = React.createClass({
images = {
boxFront: params.imageBoxFront,
boxBack: params.imageBoxBack,
boxSide: params.imageBoxSide,
boxSideLeft: params.imageBoxSideLeft,
boxSideRight: params.imageBoxSideRight,
boxTop: params.imageBoxTop
};
return makeBox(params.paper,
params.height, params.width, params.depth,
params.inside, params.color, params.title, images);
params.inside, params.color, params.title, images,
params.mirrorBoxTopOnBottom);
},
generatePreview: function(params) {
this.setState({pdfBlob: this.generatePdf(params).buildPdfUriString()});
Expand Down Expand Up @@ -64,8 +66,10 @@ Configurator = React.createClass({
title: this.state.title,
imageBoxFront: this.state.imageBoxFront,
imageBoxBack: this.state.imageBoxBack,
imageBoxSide: this.state.imageBoxSide,
imageBoxTop: this.state.imageBoxTop
imageBoxSideLeft: this.state.imageBoxSideLeft,
imageBoxSideRight: this.state.imageBoxSideRight,
imageBoxTop: this.state.imageBoxTop,
mirrorBoxTopOnBottom: this.state.mirrorBoxTopOnBottom
};
var hasInvalid = false;
props.forEach(function(prop) {
Expand Down Expand Up @@ -169,18 +173,32 @@ Configurator = React.createClass({
this.changeState('imageBoxFront', null);
}
},
imageBoxSideChange: function(e) {
imageBoxSideLeftChange: function(e) {
if (e.target.files) {
var file = e.target.files[0];
var reader = new FileReader();
var _this = this;
reader.onload = function(e) {
var datauri = e.target.result;
_this.changeState('imageBoxSide', datauri);
_this.changeState('imageBoxSideLeft', datauri);
};
reader.readAsDataURL(file);
} else {
this.changeState('imageBoxSide', null);
this.changeState('imageBoxSideLeft', null);
}
},
imageBoxSideRightChange: function(e) {
if (e.target.files) {
var file = e.target.files[0];
var reader = new FileReader();
var _this = this;
reader.onload = function(e) {
var datauri = e.target.result;
_this.changeState('imageBoxSideRight', datauri);
};
reader.readAsDataURL(file);
} else {
this.changeState('imageBoxSideRight', null);
}
},
imageBoxTopChange: function(e) {
Expand All @@ -197,6 +215,9 @@ Configurator = React.createClass({
this.changeState('imageBoxTop', null);
}
},
mirrorBoxTopOnBottomChange: function(e) {
this.changeState('mirrorBoxTopOnBottom', e.target.checked);
},
render: function() {
return (
<form className="configurator form-horizontal" onSubmit={this.handleSubmit}>
Expand Down Expand Up @@ -306,11 +327,20 @@ Configurator = React.createClass({
</div>
</div>
<div className="form-group">
<label className="control-label col-xs-4">Box Side</label>
<label className="control-label col-xs-4">Box Left Side</label>
<div className="col-xs-8">
<input
className="form-control" type="file" ref="imageBoxSide"
onChange={this.imageBoxSideChange}
className="form-control" type="file" ref="imageBoxSideLeft"
onChange={this.imageBoxSideLeftChange}
/>
</div>
</div>
<div className="form-group">
<label className="control-label col-xs-4">Box Right Side</label>
<div className="col-xs-8">
<input
className="form-control" type="file" ref="imageBoxSideRight"
onChange={this.imageBoxSideRightChange}
/>
</div>
</div>
Expand All @@ -323,6 +353,15 @@ Configurator = React.createClass({
/>
</div>
</div>
<div className="form-group">
<label className="control-label col-xs-4">Mirror Top on Bottom</label>

<div className="col-xs-8">
<input
className="form-control" type="checkbox" ref="mirrorBoxTopOnBottom"
onChange={this.mirrorBoxTopOnBottomChange} />
</div>
</div>
<div className="form-group">
<div className="col-xs-offset-4 col-xs-8">
<button className="btn btn-default" type="submit">Preview</button>
Expand Down
24 changes: 16 additions & 8 deletions tuckbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ function drawDrawer(_drawer, _width, _length, _height, _gap, _fill) {
d.trap(d.p(-x_offset, -y_offset), height, flap_length, 1/16, 'up', fill);
}

function drawBox(_drawer, _width, _length, _height, _fill, _title, _imgs) {
function drawBox(_drawer, _width, _length, _height, _fill, _title, _imgs, _mirrorBoxTopOnBottom) {
var d = _drawer;
var depths = {
side_flap: _height * 0.9,
Expand All @@ -299,8 +299,10 @@ function drawBox(_drawer, _width, _length, _height, _fill, _title, _imgs) {
}
var frontImage = _imgs.boxFront;
var backImage = _imgs.boxBack;
var sideImage = _imgs.boxSide;
var leftSideImage = _imgs.boxSideLeft;
var rightSideImage = _imgs.boxSideRight;
var topImage = _imgs.boxTop;
var mirrorBoxTopOnBottom = _mirrorBoxTopOnBottom;
var totalLength = size.main.x * 2 + size.side_panel.x * 2 + size.side_flap.x;
var currCenterX = size.main.x * 1.5 + size.side_panel.x;
var totalHeight = size.main.y + size.bt_flap.y * 2 + size.top_top_flap.y;
Expand Down Expand Up @@ -421,14 +423,19 @@ function drawBox(_drawer, _width, _length, _height, _fill, _title, _imgs) {
//TO DO - display bottom image in flap so visible behind thumb hole
}

if (sideImage) {
imagePanel(sideImage, panels.left.loc, panels.left.size, 0);
imagePanel(sideImage, panels.right.loc, panels.right.size, 0);
if (leftSideImage) {
imagePanel(leftSideImage, panels.left.loc, panels.left.size, 0);
}

if (rightSideImage) {
imagePanel(rightSideImage, panels.right.loc, panels.right.size, 0);
}

if (topImage) {
imagePanel(topImage, flaps.top_top.loc, flaps.top_top.size, 0);
imagePanel(topImage, flaps.top_bot.loc, flaps.top_bot.size, 0);

if(mirrorBoxTopOnBottom)
imagePanel(topImage, flaps.top_bot.loc, flaps.top_bot.size, 0);
}
_.values(panels).forEach(drawPanel);
_.values(flaps).forEach(drawFlap);
Expand Down Expand Up @@ -474,7 +481,8 @@ function makeBox(
inside,
fillColor,
title,
images
images,
mirrorBoxTopOnBottom
) {
images = images || {};
//paper = paper === 'a4' ? 'a4' : 'letter';
Expand All @@ -500,7 +508,7 @@ function makeBox(
cardHeight += 1 / 16;
boxDepth += 1 / 16;
}
drawBox(drawer, cardWidth, cardHeight, boxDepth, fillColor, title, images);
drawBox(drawer, cardWidth, cardHeight, boxDepth, fillColor, title, images, mirrorBoxTopOnBottom);

return drawer;
}