mirror of
https://github.com/google/blockly.git
synced 2026-01-05 08:00:09 +01:00
118 lines
3.4 KiB
JavaScript
118 lines
3.4 KiB
JavaScript
/**
|
|
* @license
|
|
* Visual Blocks Editor
|
|
*
|
|
* Copyright 2012 Google Inc.
|
|
* https://developers.google.com/blockly/
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
/**
|
|
* @fileoverview Colour blocks for Blockly.
|
|
* @author fraser@google.com (Neil Fraser)
|
|
*/
|
|
'use strict';
|
|
|
|
goog.provide('Blockly.Blocks.colour');
|
|
|
|
goog.require('Blockly.Blocks');
|
|
|
|
|
|
/**
|
|
* Common HSV hue for all blocks in this category.
|
|
*/
|
|
Blockly.Blocks.colour.HUE = 20;
|
|
|
|
Blockly.Blocks['colour_picker'] = {
|
|
/**
|
|
* Block for colour picker.
|
|
* @this Blockly.Block
|
|
*/
|
|
init: function() {
|
|
this.setHelpUrl(Blockly.Msg.COLOUR_PICKER_HELPURL);
|
|
this.setColour(Blockly.Blocks.colour.HUE);
|
|
this.appendDummyInput()
|
|
.appendField(new Blockly.FieldColour('#ff0000'), 'COLOUR');
|
|
this.setOutput(true, 'Colour');
|
|
this.setTooltip(Blockly.Msg.COLOUR_PICKER_TOOLTIP);
|
|
}
|
|
};
|
|
|
|
Blockly.Blocks['colour_random'] = {
|
|
/**
|
|
* Block for random colour.
|
|
* @this Blockly.Block
|
|
*/
|
|
init: function() {
|
|
this.setHelpUrl(Blockly.Msg.COLOUR_RANDOM_HELPURL);
|
|
this.setColour(Blockly.Blocks.colour.HUE);
|
|
this.appendDummyInput()
|
|
.appendField(Blockly.Msg.COLOUR_RANDOM_TITLE);
|
|
this.setOutput(true, 'Colour');
|
|
this.setTooltip(Blockly.Msg.COLOUR_RANDOM_TOOLTIP);
|
|
}
|
|
};
|
|
|
|
Blockly.Blocks['colour_rgb'] = {
|
|
/**
|
|
* Block for composing a colour from RGB components.
|
|
* @this Blockly.Block
|
|
*/
|
|
init: function() {
|
|
this.setHelpUrl(Blockly.Msg.COLOUR_RGB_HELPURL);
|
|
this.setColour(Blockly.Blocks.colour.HUE);
|
|
this.appendValueInput('RED')
|
|
.setCheck('Number')
|
|
.setAlign(Blockly.ALIGN_RIGHT)
|
|
.appendField(Blockly.Msg.COLOUR_RGB_TITLE)
|
|
.appendField(Blockly.Msg.COLOUR_RGB_RED);
|
|
this.appendValueInput('GREEN')
|
|
.setCheck('Number')
|
|
.setAlign(Blockly.ALIGN_RIGHT)
|
|
.appendField(Blockly.Msg.COLOUR_RGB_GREEN);
|
|
this.appendValueInput('BLUE')
|
|
.setCheck('Number')
|
|
.setAlign(Blockly.ALIGN_RIGHT)
|
|
.appendField(Blockly.Msg.COLOUR_RGB_BLUE);
|
|
this.setOutput(true, 'Colour');
|
|
this.setTooltip(Blockly.Msg.COLOUR_RGB_TOOLTIP);
|
|
}
|
|
};
|
|
|
|
Blockly.Blocks['colour_blend'] = {
|
|
/**
|
|
* Block for blending two colours together.
|
|
* @this Blockly.Block
|
|
*/
|
|
init: function() {
|
|
this.setHelpUrl(Blockly.Msg.COLOUR_BLEND_HELPURL);
|
|
this.setColour(Blockly.Blocks.colour.HUE);
|
|
this.appendValueInput('COLOUR1')
|
|
.setCheck('Colour')
|
|
.setAlign(Blockly.ALIGN_RIGHT)
|
|
.appendField(Blockly.Msg.COLOUR_BLEND_TITLE)
|
|
.appendField(Blockly.Msg.COLOUR_BLEND_COLOUR1);
|
|
this.appendValueInput('COLOUR2')
|
|
.setCheck('Colour')
|
|
.setAlign(Blockly.ALIGN_RIGHT)
|
|
.appendField(Blockly.Msg.COLOUR_BLEND_COLOUR2);
|
|
this.appendValueInput('RATIO')
|
|
.setCheck('Number')
|
|
.setAlign(Blockly.ALIGN_RIGHT)
|
|
.appendField(Blockly.Msg.COLOUR_BLEND_RATIO);
|
|
this.setOutput(true, 'Colour');
|
|
this.setTooltip(Blockly.Msg.COLOUR_BLEND_TOOLTIP);
|
|
}
|
|
};
|