colour.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. * @license
  3. * Visual Blocks Editor
  4. *
  5. * Copyright 2012 Google Inc.
  6. * https://developers.google.com/blockly/
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. /**
  21. * @fileoverview Colour blocks for Blockly.
  22. * @author fraser@google.com (Neil Fraser)
  23. */
  24. 'use strict';
  25. goog.provide('Blockly.Blocks.colour');
  26. goog.require('Blockly.Blocks');
  27. /**
  28. * Common HSV hue for all blocks in this category.
  29. */
  30. Blockly.Blocks.colour.HUE = 20;
  31. Blockly.Blocks['colour_picker'] = {
  32. /**
  33. * Block for colour picker.
  34. * @this Blockly.Block
  35. */
  36. init: function() {
  37. this.jsonInit({
  38. "message0": "%1",
  39. "args0": [
  40. {
  41. "type": "field_colour",
  42. "name": "COLOUR",
  43. "colour": "#ff0000"
  44. }
  45. ],
  46. "output": "Colour",
  47. "colour": Blockly.Blocks.colour.HUE,
  48. "helpUrl": Blockly.Msg.COLOUR_PICKER_HELPURL
  49. });
  50. // Assign 'this' to a variable for use in the tooltip closure below.
  51. var thisBlock = this;
  52. // Colour block is trivial. Use tooltip of parent block if it exists.
  53. this.setTooltip(function() {
  54. var parent = thisBlock.getParent();
  55. return (parent && parent.getInputsInline() && parent.tooltip) ||
  56. Blockly.Msg.COLOUR_PICKER_TOOLTIP;
  57. });
  58. }
  59. };
  60. Blockly.Blocks['colour_random'] = {
  61. /**
  62. * Block for random colour.
  63. * @this Blockly.Block
  64. */
  65. init: function() {
  66. this.jsonInit({
  67. "message0": Blockly.Msg.COLOUR_RANDOM_TITLE,
  68. "output": "Colour",
  69. "colour": Blockly.Blocks.colour.HUE,
  70. "tooltip": Blockly.Msg.COLOUR_RANDOM_TOOLTIP,
  71. "helpUrl": Blockly.Msg.COLOUR_RANDOM_HELPURL
  72. });
  73. }
  74. };
  75. Blockly.Blocks['colour_rgb'] = {
  76. /**
  77. * Block for composing a colour from RGB components.
  78. * @this Blockly.Block
  79. */
  80. init: function() {
  81. this.setHelpUrl(Blockly.Msg.COLOUR_RGB_HELPURL);
  82. this.setColour(Blockly.Blocks.colour.HUE);
  83. this.appendValueInput('RED')
  84. .setCheck('Number')
  85. .setAlign(Blockly.ALIGN_RIGHT)
  86. .appendField(Blockly.Msg.COLOUR_RGB_TITLE)
  87. .appendField(Blockly.Msg.COLOUR_RGB_RED);
  88. this.appendValueInput('GREEN')
  89. .setCheck('Number')
  90. .setAlign(Blockly.ALIGN_RIGHT)
  91. .appendField(Blockly.Msg.COLOUR_RGB_GREEN);
  92. this.appendValueInput('BLUE')
  93. .setCheck('Number')
  94. .setAlign(Blockly.ALIGN_RIGHT)
  95. .appendField(Blockly.Msg.COLOUR_RGB_BLUE);
  96. this.setOutput(true, 'Colour');
  97. this.setTooltip(Blockly.Msg.COLOUR_RGB_TOOLTIP);
  98. }
  99. };
  100. Blockly.Blocks['colour_blend'] = {
  101. /**
  102. * Block for blending two colours together.
  103. * @this Blockly.Block
  104. */
  105. init: function() {
  106. this.setHelpUrl(Blockly.Msg.COLOUR_BLEND_HELPURL);
  107. this.setColour(Blockly.Blocks.colour.HUE);
  108. this.appendValueInput('COLOUR1')
  109. .setCheck('Colour')
  110. .setAlign(Blockly.ALIGN_RIGHT)
  111. .appendField(Blockly.Msg.COLOUR_BLEND_TITLE)
  112. .appendField(Blockly.Msg.COLOUR_BLEND_COLOUR1);
  113. this.appendValueInput('COLOUR2')
  114. .setCheck('Colour')
  115. .setAlign(Blockly.ALIGN_RIGHT)
  116. .appendField(Blockly.Msg.COLOUR_BLEND_COLOUR2);
  117. this.appendValueInput('RATIO')
  118. .setCheck('Number')
  119. .setAlign(Blockly.ALIGN_RIGHT)
  120. .appendField(Blockly.Msg.COLOUR_BLEND_RATIO);
  121. this.setOutput(true, 'Colour');
  122. this.setTooltip(Blockly.Msg.COLOUR_BLEND_TOOLTIP);
  123. }
  124. };