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 | /**
|
---|
22 | * @fileoverview Colour blocks for Blockly.
|
---|
23 | * @author fraser@google.com (Neil Fraser)
|
---|
24 | */
|
---|
25 | using System;
|
---|
26 | using System.Linq;
|
---|
27 | using System.Text;
|
---|
28 | using Bridge;
|
---|
29 | using Bridge.Html5;
|
---|
30 | using Bridge.jQuery2;
|
---|
31 |
|
---|
32 | namespace WebMrbc
|
---|
33 | {
|
---|
34 | public class Colour
|
---|
35 | {
|
---|
36 | /**
|
---|
37 | * Common HSV hue for all blocks in this category.
|
---|
38 | */
|
---|
39 | public static int HUE = 20;
|
---|
40 | }
|
---|
41 |
|
---|
42 | public class ColourPickerBlock : Block
|
---|
43 | {
|
---|
44 | public const string type_name = "colour_picker";
|
---|
45 |
|
---|
46 | public ColourPickerBlock()
|
---|
47 | : base(type_name)
|
---|
48 | {
|
---|
49 | }
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Block for colour picker.
|
---|
53 | * @this Blockly.Block
|
---|
54 | */
|
---|
55 | public void init()
|
---|
56 | {
|
---|
57 | this.jsonInit(new {
|
---|
58 | message0 = "%1",
|
---|
59 | args0 = new object[] {
|
---|
60 | new {
|
---|
61 | type = "field_colour",
|
---|
62 | name = "COLOUR",
|
---|
63 | colour = "#ff0000"
|
---|
64 | }
|
---|
65 | },
|
---|
66 | output = "Colour",
|
---|
67 | colour = Colour.HUE,
|
---|
68 | helpUrl = Msg.COLOUR_PICKER_HELPURL
|
---|
69 | });
|
---|
70 | // Assign "this" to a variable for use in the tooltip closure below.
|
---|
71 | var thisBlock = this;
|
---|
72 | // Colour block is trivial. Use tooltip of parent block if it exists.
|
---|
73 | this.setTooltip(new Func<string>(() => {
|
---|
74 | var parent = thisBlock.getParent();
|
---|
75 | return (parent != null && parent.getInputsInline() && !String.IsNullOrEmpty(parent.tooltip)) ? parent.tooltip :
|
---|
76 | Msg.COLOUR_PICKER_TOOLTIP;
|
---|
77 | }));
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | public class ColourRandomBlock : Block
|
---|
82 | {
|
---|
83 | public const string type_name = "colour_random";
|
---|
84 |
|
---|
85 | public ColourRandomBlock()
|
---|
86 | : base(type_name)
|
---|
87 | {
|
---|
88 | }
|
---|
89 |
|
---|
90 | /**
|
---|
91 | * Block for random colour.
|
---|
92 | * @this Blockly.Block
|
---|
93 | */
|
---|
94 | public void init()
|
---|
95 | {
|
---|
96 | this.jsonInit(new {
|
---|
97 | message0 = Msg.COLOUR_RANDOM_TITLE,
|
---|
98 | output = "Colour",
|
---|
99 | colour = Colour.HUE,
|
---|
100 | tooltip = Msg.COLOUR_RANDOM_TOOLTIP,
|
---|
101 | helpUrl = Msg.COLOUR_RANDOM_HELPURL
|
---|
102 | });
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | public class ColourRGBBlock : Block
|
---|
107 | {
|
---|
108 | public const string type_name = "colour_rgb";
|
---|
109 |
|
---|
110 | public ColourRGBBlock()
|
---|
111 | : base(type_name)
|
---|
112 | {
|
---|
113 | }
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * Block for composing a colour from RGB components.
|
---|
117 | * @this Blockly.Block
|
---|
118 | */
|
---|
119 | public void init()
|
---|
120 | {
|
---|
121 | this.setHelpUrl(Msg.COLOUR_RGB_HELPURL);
|
---|
122 | this.setColour(Colour.HUE);
|
---|
123 | this.appendValueInput("RED")
|
---|
124 | .setCheck("Number")
|
---|
125 | .setAlign(Blockly.ALIGN_RIGHT)
|
---|
126 | .appendField(Msg.COLOUR_RGB_TITLE)
|
---|
127 | .appendField(Msg.COLOUR_RGB_RED);
|
---|
128 | this.appendValueInput("GREEN")
|
---|
129 | .setCheck("Number")
|
---|
130 | .setAlign(Blockly.ALIGN_RIGHT)
|
---|
131 | .appendField(Msg.COLOUR_RGB_GREEN);
|
---|
132 | this.appendValueInput("BLUE")
|
---|
133 | .setCheck("Number")
|
---|
134 | .setAlign(Blockly.ALIGN_RIGHT)
|
---|
135 | .appendField(Msg.COLOUR_RGB_BLUE);
|
---|
136 | this.setOutput(true, "Colour");
|
---|
137 | this.setTooltip(Msg.COLOUR_RGB_TOOLTIP);
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 | public class ColourBlendBlock : Block
|
---|
142 | {
|
---|
143 | public const string type_name = "colour_blend";
|
---|
144 |
|
---|
145 | public ColourBlendBlock()
|
---|
146 | : base(type_name)
|
---|
147 | {
|
---|
148 | }
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * Block for blending two colours together.
|
---|
152 | * @this Blockly.Block
|
---|
153 | */
|
---|
154 | public void init()
|
---|
155 | {
|
---|
156 | this.setHelpUrl(Msg.COLOUR_BLEND_HELPURL);
|
---|
157 | this.setColour(Colour.HUE);
|
---|
158 | this.appendValueInput("COLOUR1")
|
---|
159 | .setCheck("Colour")
|
---|
160 | .setAlign(Blockly.ALIGN_RIGHT)
|
---|
161 | .appendField(Msg.COLOUR_BLEND_TITLE)
|
---|
162 | .appendField(Msg.COLOUR_BLEND_COLOUR1);
|
---|
163 | this.appendValueInput("COLOUR2")
|
---|
164 | .setCheck("Colour")
|
---|
165 | .setAlign(Blockly.ALIGN_RIGHT)
|
---|
166 | .appendField(Msg.COLOUR_BLEND_COLOUR2);
|
---|
167 | this.appendValueInput("RATIO")
|
---|
168 | .setCheck("Number")
|
---|
169 | .setAlign(Blockly.ALIGN_RIGHT)
|
---|
170 | .appendField(Msg.COLOUR_BLEND_RATIO);
|
---|
171 | this.setOutput(true, "Colour");
|
---|
172 | this.setTooltip(Msg.COLOUR_BLEND_TOOLTIP);
|
---|
173 | }
|
---|
174 | }
|
---|
175 | }
|
---|