Commit 0de301dc authored by Jennie Yoder's avatar Jennie Yoder

incremental commit, non-functional

parent 4f3de14e
...@@ -47,13 +47,19 @@ Blockly.Blocks['cylinder'] = { ...@@ -47,13 +47,19 @@ Blockly.Blocks['cylinder'] = {
this.appendDummyInput() this.appendDummyInput()
.setAlign(Blockly.ALIGN_RIGHT) .setAlign(Blockly.ALIGN_RIGHT)
.appendField(new Blockly.FieldImage("lock_icon.png", 15, 15, "*")) .appendField(new Blockly.FieldImage("lock_icon.png", 15, 15, "*"))
.appendField(new Blockly.FieldCheckbox("FALSE"), "LOCKED"); .appendField(new Blockly.FieldCheckbox("FALSE", function(newState) {
if (newState) console.log("I'm checked");
else console.log("I'm not checked");
}), "LOCKED");
} }
else { else {
this.appendDummyInput() this.appendDummyInput()
.setAlign(Blockly.ALIGN_RIGHT) .setAlign(Blockly.ALIGN_RIGHT)
.appendField(new Blockly.FieldImage("lock_icon.png", 15, 15, "*")) .appendField(new Blockly.FieldImage("lock_icon.png", 15, 15, "*"))
.appendField(new Blockly.FieldCheckbox("TRUE"), "LOCKED"); .appendField(new Blockly.FieldCheckbox("TRUE", function(newState) {
if (newState) console.log("I'm checked");
else console.log("I'm not checked");
}), "LOCKED");
} }
this.appendValueInput('RAD2') this.appendValueInput('RAD2')
.setCheck('Number') .setCheck('Number')
......
...@@ -39,9 +39,13 @@ goog.require('Blockly.Field'); ...@@ -39,9 +39,13 @@ goog.require('Blockly.Field');
* @extends {Blockly.Field} * @extends {Blockly.Field}
* @constructor * @constructor
*/ */
Blockly.FieldCheckbox = function(state, opt_changeHandler) { Blockly.FieldCheckbox = function(state, opt_changeHandler,img1,img2) {
Blockly.FieldCheckbox.superClass_.constructor.call(this, ''); Blockly.FieldCheckbox.superClass_.constructor.call(this, '');
// do I have two images?
if (img1 && img2) {
this.img1 = img1;
this.img2 = img2;
}
this.setChangeHandler(opt_changeHandler); this.setChangeHandler(opt_changeHandler);
// Set the initial state. // Set the initial state.
this.setValue(state); this.setValue(state);
...@@ -65,11 +69,33 @@ Blockly.FieldCheckbox.prototype.init = function(block) { ...@@ -65,11 +69,33 @@ Blockly.FieldCheckbox.prototype.init = function(block) {
Blockly.FieldCheckbox.superClass_.init.call(this, block); Blockly.FieldCheckbox.superClass_.init.call(this, block);
// The checkbox doesn't use the inherited text element. // The checkbox doesn't use the inherited text element.
// Instead it uses a custom checkmark element that is either visible or not. // Instead it uses a custom checkmark element that is either visible or not.
if (this.img1 && this.img2) {
this.checkElement_ = Blockly.createSvgElement('text', this.checkElement_ = Blockly.createSvgElement('text',
{'class': 'blocklyText', 'x': -3}, this.fieldGroup_); {'class': 'blocklyText', 'x': -3}, this.fieldGroup_);
var textNode = document.createTextNode('\u2713'); var textNode = document.createTextNode('\u2713');
this.checkElement_.appendChild(textNode); this.checkElement_.appendChild(textNode);
this.checkElement_.style.display = this.state_ ? 'block' : 'none'; this.checkElement_.style.display = this.state_ ? 'block' : 'none';
}
else {
// code from field_image
var offsetY = 6 - Blockly.BlockSvg.FIELD_HEIGHT;
this.fieldGroup_ = Blockly.createSvgElement('g', {}, null);
this.imageElement_ = Blockly.createSvgElement('image',
{'height': 15 + 'px',
'width': 15 + 'px',
'y': offsetY}, this.fieldGroup_);
this.setValue(this.img1);
if (goog.userAgent.GECKO) {
// Due to a Firefox bug which eats mouse events on image elements,
// a transparent rectangle needs to be placed on top of the image.
this.rectElement_ = Blockly.createSvgElement('rect',
{'height': 15 + 'px',
'width': 15 + 'px',
'y': offsetY,
'fill-opacity': 0}, this.fieldGroup_);
}
block.getSvgRoot().appendChild(this.fieldGroup_);
}
}; };
/** /**
...@@ -82,6 +108,7 @@ Blockly.FieldCheckbox.prototype.getValue = function() { ...@@ -82,6 +108,7 @@ Blockly.FieldCheckbox.prototype.getValue = function() {
/** /**
* Set the checkbox to be checked if strBool is 'TRUE', unchecks otherwise. * Set the checkbox to be checked if strBool is 'TRUE', unchecks otherwise.
* Can also toggle between two images if they exist.
* @param {string} strBool New state. * @param {string} strBool New state.
*/ */
Blockly.FieldCheckbox.prototype.setValue = function(strBool) { Blockly.FieldCheckbox.prototype.setValue = function(strBool) {
...@@ -91,6 +118,10 @@ Blockly.FieldCheckbox.prototype.setValue = function(strBool) { ...@@ -91,6 +118,10 @@ Blockly.FieldCheckbox.prototype.setValue = function(strBool) {
if (this.checkElement_) { if (this.checkElement_) {
this.checkElement_.style.display = newState ? 'block' : 'none'; this.checkElement_.style.display = newState ? 'block' : 'none';
} }
else if (this.imageElement_) {
this.imageElement_.setAttributeNS('http://www.w3.org/1999/xlink',
'xlink:href', newState ? this.img1 : this.img2);
}
if (this.sourceBlock_ && this.sourceBlock_.rendered) { if (this.sourceBlock_ && this.sourceBlock_.rendered) {
this.sourceBlock_.workspace.fireChangeEvent(); this.sourceBlock_.workspace.fireChangeEvent();
} }
......
...@@ -79,7 +79,7 @@ Blockly.Xml.blockToDom_ = function(block) { ...@@ -79,7 +79,7 @@ Blockly.Xml.blockToDom_ = function(block) {
} }
} }
function fieldToDom(field) { function fieldToDom(field) {
// for BlocksCAD, I want to save un-editable fields in the xml for stl import. // for BlocksCAD STL import, I want to save un-editable fields in the xml for stl import.
if (field.name && (field.EDITABLE || field.name == 'STL_FILENAME' || field.name == 'STL_CONTENTS')) { if (field.name && (field.EDITABLE || field.name == 'STL_FILENAME' || field.name == 'STL_CONTENTS')) {
var container = goog.dom.createDom('field', null, field.getValue()); var container = goog.dom.createDom('field', null, field.getValue());
container.setAttribute('name', field.name); container.setAttribute('name', field.name);
...@@ -233,7 +233,7 @@ Blockly.Xml.domToWorkspace = function(workspace, xml) { ...@@ -233,7 +233,7 @@ Blockly.Xml.domToWorkspace = function(workspace, xml) {
if (workspace.RTL) { if (workspace.RTL) {
width = workspace.getWidth(); width = workspace.getWidth();
} }
// FOR BLOCKSCAD: set version of input file to null // FOR BLOCKSCAD: set version of input file to null so we can read the input xml version.
Blockscad.inputVersion = null; Blockscad.inputVersion = null;
// Safari 7.1.3 is known to provide node lists with extra references to // Safari 7.1.3 is known to provide node lists with extra references to
// children beyond the lists' length. Trust the length, do not use the // children beyond the lists' length. Trust the length, do not use the
...@@ -241,9 +241,8 @@ Blockly.Xml.domToWorkspace = function(workspace, xml) { ...@@ -241,9 +241,8 @@ Blockly.Xml.domToWorkspace = function(workspace, xml) {
var childCount = xml.childNodes.length; var childCount = xml.childNodes.length;
for (var i = 0; i < childCount; i++) { for (var i = 0; i < childCount; i++) {
var xmlChild = xml.childNodes[i]; var xmlChild = xml.childNodes[i];
// Read in Blockscad file version information. // Read in Blockscad input xml version information.
if (xmlChild.nodeName.toLowerCase() == 'version') { if (xmlChild.nodeName.toLowerCase() == 'version') {
// console.log("xmlChild read was: ", xmlChild.getAttribute('num'));
Blockscad.inputVersion = xmlChild.getAttribute('num'); Blockscad.inputVersion = xmlChild.getAttribute('num');
// console.log("inputVersion is:",Blockscad.inputVersion); // console.log("inputVersion is:",Blockscad.inputVersion);
} }
...@@ -256,7 +255,7 @@ Blockly.Xml.domToWorkspace = function(workspace, xml) { ...@@ -256,7 +255,7 @@ Blockly.Xml.domToWorkspace = function(workspace, xml) {
} }
} }
} }
// Set blockscad version back to current tool version // Set blockscad version back to current tool version now that the input file is done
Blockscad.inputVersion = Blockscad.version; Blockscad.inputVersion = Blockscad.version;
// console.log("resetting inputversion to current: ",Blockscad.inputVersion); // console.log("resetting inputversion to current: ",Blockscad.inputVersion);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment