cura 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +45 -21
- data/cura.gemspec +1 -1
- data/examples/hello_world/lib/hello_world.rb +10 -10
- data/examples/mruby-examples/mrbgem.rake +5 -6
- data/examples/todo_list/data.db +0 -0
- data/examples/todo_list/lib/todo_list/application.rb +24 -18
- data/lib/cura/adapter.rb +13 -20
- data/lib/cura/application.rb +47 -51
- data/lib/cura/attributes/has_ancestry.rb +4 -8
- data/lib/cura/attributes/has_application.rb +3 -7
- data/lib/cura/attributes/has_attributes.rb +1 -9
- data/lib/cura/attributes/has_children.rb +14 -20
- data/lib/cura/attributes/has_colors.rb +14 -18
- data/lib/cura/attributes/has_coordinates.rb +9 -15
- data/lib/cura/attributes/has_dimensions.rb +12 -18
- data/lib/cura/attributes/has_events.rb +10 -18
- data/lib/cura/attributes/has_focusability.rb +5 -11
- data/lib/cura/attributes/has_initialize.rb +1 -5
- data/lib/cura/attributes/has_offsets.rb +16 -20
- data/lib/cura/attributes/has_orientation.rb +12 -18
- data/lib/cura/attributes/has_relative_coordinates.rb +4 -8
- data/lib/cura/attributes/has_root.rb +18 -22
- data/lib/cura/attributes/has_side_attributes.rb +18 -24
- data/lib/cura/attributes/has_windows.rb +13 -19
- data/lib/cura/borders.rb +0 -4
- data/lib/cura/color.rb +84 -91
- data/lib/cura/component/base.rb +29 -33
- data/lib/cura/component/button.rb +10 -16
- data/lib/cura/component/group.rb +14 -18
- data/lib/cura/component/label.rb +44 -48
- data/lib/cura/component/listbox.rb +24 -28
- data/lib/cura/component/pack.rb +14 -18
- data/lib/cura/component/scrollbar.rb +41 -45
- data/lib/cura/component/textbox.rb +21 -25
- data/lib/cura/cursor.rb +15 -23
- data/lib/cura/error/base.rb +0 -3
- data/lib/cura/error/invalid_adapter.rb +1 -7
- data/lib/cura/error/invalid_application.rb +1 -7
- data/lib/cura/error/invalid_color.rb +1 -7
- data/lib/cura/error/invalid_component.rb +1 -7
- data/lib/cura/error/invalid_middleware.rb +1 -7
- data/lib/cura/event.rb +4 -8
- data/lib/cura/event/base.rb +17 -24
- data/lib/cura/event/click.rb +1 -6
- data/lib/cura/event/dispatcher.rb +20 -26
- data/lib/cura/event/focus.rb +1 -6
- data/lib/cura/event/handler.rb +16 -24
- data/lib/cura/event/key_down.rb +11 -17
- data/lib/cura/event/middleware/aimer/base.rb +4 -10
- data/lib/cura/event/middleware/aimer/dispatcher_target.rb +2 -8
- data/lib/cura/event/middleware/aimer/mouse_focus.rb +6 -11
- data/lib/cura/event/middleware/aimer/target_option.rb +4 -10
- data/lib/cura/event/middleware/base.rb +0 -4
- data/lib/cura/event/middleware/dispatch.rb +0 -4
- data/lib/cura/event/middleware/translator/base.rb +4 -10
- data/lib/cura/event/middleware/translator/mouse_click.rb +4 -8
- data/lib/cura/event/mouse.rb +5 -11
- data/lib/cura/event/mouse_button.rb +21 -27
- data/lib/cura/event/mouse_wheel_down.rb +1 -6
- data/lib/cura/event/mouse_wheel_up.rb +1 -6
- data/lib/cura/event/resize.rb +0 -4
- data/lib/cura/event/selected.rb +1 -6
- data/lib/cura/event/unfocus.rb +1 -6
- data/lib/cura/focus_controller.rb +19 -23
- data/lib/cura/key.rb +277 -283
- data/lib/cura/margins.rb +0 -4
- data/lib/cura/offsets.rb +14 -18
- data/lib/cura/padding.rb +0 -4
- data/lib/cura/pencil.rb +3 -7
- data/lib/cura/version.rb +1 -3
- data/lib/cura/window.rb +11 -16
- data/spec/cura/attributes/has_ancestry_spec.rb +39 -39
- data/spec/cura/attributes/has_application_spec.rb +20 -20
- data/spec/cura/attributes/has_attributes_spec.rb +26 -26
- data/spec/cura/attributes/has_children_spec.rb +54 -54
- data/spec/cura/attributes/has_colors_spec.rb +4 -4
- data/spec/cura/attributes/has_coordinates_spec.rb +4 -4
- data/spec/cura/attributes/has_dimensions_spec.rb +4 -4
- data/spec/cura/attributes/has_events_spec.rb +4 -4
- data/spec/cura/attributes/has_focusability_spec.rb +18 -18
- data/spec/cura/attributes/has_offsets_spec.rb +4 -4
- data/spec/cura/attributes/has_orientation_spec.rb +38 -38
- data/spec/cura/attributes/has_relative_coordinates_spec.rb +4 -4
- data/spec/cura/attributes/has_side_attributes_spec.rb +4 -4
- data/spec/spec_helper.rb +1 -1
- data/spec/support/shared_examples_for_attributes.rb +41 -41
- metadata +1 -1
@@ -1,35 +1,31 @@
|
|
1
|
-
if Kernel.respond_to?(:require)
|
2
|
-
require "cura/window"
|
3
|
-
end
|
1
|
+
require "cura/window" if Kernel.respond_to?(:require)
|
4
2
|
|
5
3
|
module Cura
|
6
4
|
module Attributes
|
7
|
-
|
8
5
|
# Allows an object to have windows.
|
9
6
|
# TODO: Lots of code is the same as HasChildren
|
10
7
|
module HasWindows
|
11
|
-
|
12
8
|
def initialize(*arguments)
|
13
9
|
@windows = []
|
14
|
-
|
10
|
+
|
15
11
|
super
|
16
12
|
end
|
17
|
-
|
13
|
+
|
18
14
|
# Get the windows of this object.
|
19
15
|
attr_reader :windows
|
20
|
-
|
16
|
+
|
21
17
|
# Add a window to this object.
|
22
18
|
#
|
23
19
|
# @param [Window] window
|
24
20
|
# @return [Window]
|
25
21
|
def add_window(window)
|
26
22
|
raise TypeError, "window must be a Cura::Window" unless window.is_a?(Window)
|
27
|
-
|
23
|
+
|
28
24
|
@windows << window
|
29
|
-
|
25
|
+
|
30
26
|
window
|
31
27
|
end
|
32
|
-
|
28
|
+
|
33
29
|
# Remove a window from this object's windows at the given index.
|
34
30
|
#
|
35
31
|
# @param [#to_i] index
|
@@ -37,7 +33,7 @@ module Cura
|
|
37
33
|
def delete_window_at(index)
|
38
34
|
@windows.delete_at(index.to_i)
|
39
35
|
end
|
40
|
-
|
36
|
+
|
41
37
|
# Remove a window from this object's windows.
|
42
38
|
#
|
43
39
|
# @param [Window] window
|
@@ -45,26 +41,24 @@ module Cura
|
|
45
41
|
def delete_window(window)
|
46
42
|
raise TypeError, "window must be a Cura::Window" unless window.is_a?(Window)
|
47
43
|
index = @windows.index(window)
|
48
|
-
|
44
|
+
|
49
45
|
delete_window_at(index)
|
50
46
|
end
|
51
|
-
|
47
|
+
|
52
48
|
# Remove all windows.
|
53
49
|
def delete_windows
|
54
50
|
(0...@windows.count).to_a.each { |index| delete_window_at(index) }
|
55
51
|
end
|
56
|
-
|
52
|
+
|
57
53
|
protected # TODO: These should be protected?
|
58
|
-
|
54
|
+
|
59
55
|
def update_windows
|
60
56
|
windows.each(&:update)
|
61
57
|
end
|
62
|
-
|
58
|
+
|
63
59
|
def draw_windows
|
64
60
|
windows.each(&:draw)
|
65
61
|
end
|
66
|
-
|
67
62
|
end
|
68
|
-
|
69
63
|
end
|
70
64
|
end
|
data/lib/cura/borders.rb
CHANGED
data/lib/cura/color.rb
CHANGED
@@ -4,44 +4,40 @@ if Kernel.respond_to?(:require)
|
|
4
4
|
end
|
5
5
|
|
6
6
|
module Cura
|
7
|
-
|
8
7
|
# Colors.
|
9
8
|
class Color
|
10
|
-
|
11
9
|
include Attributes::HasInitialize
|
12
10
|
include Attributes::HasAttributes
|
13
|
-
|
11
|
+
|
14
12
|
class << self
|
15
|
-
|
16
13
|
# The default color to be overidden by adapters.
|
17
14
|
# Usually, for TUI's to use the terminal theme's colors.
|
18
15
|
# TODO: Remove.
|
19
16
|
def default
|
20
17
|
super
|
21
18
|
end
|
22
|
-
|
19
|
+
|
23
20
|
def black
|
24
21
|
new
|
25
22
|
end
|
26
|
-
|
23
|
+
|
27
24
|
def white
|
28
25
|
new(255, 255, 255)
|
29
26
|
end
|
30
|
-
|
27
|
+
|
31
28
|
def red
|
32
29
|
new(255, 0, 0)
|
33
30
|
end
|
34
|
-
|
31
|
+
|
35
32
|
def green
|
36
33
|
new(0, 255, 0)
|
37
34
|
end
|
38
|
-
|
35
|
+
|
39
36
|
def blue
|
40
37
|
new(0, 0, 255)
|
41
38
|
end
|
42
|
-
|
43
39
|
end
|
44
|
-
|
40
|
+
|
45
41
|
def initialize(r=0, g=0, b=0, a=255)
|
46
42
|
if r.respond_to?(:to_h)
|
47
43
|
super(r.to_h)
|
@@ -51,68 +47,68 @@ module Cura
|
|
51
47
|
@blue = b
|
52
48
|
@alpha = a
|
53
49
|
end
|
54
|
-
|
50
|
+
|
55
51
|
@lab = rgb_to_lab([@red, @green, @blue]) # TODO: Update on rgb setters?
|
56
52
|
end
|
57
|
-
|
53
|
+
|
58
54
|
# @method red
|
59
55
|
# Get the red channel of this color.
|
60
56
|
#
|
61
57
|
# @return [Integer]
|
62
|
-
|
58
|
+
|
63
59
|
# @method red=(value)
|
64
60
|
# Set the red channel of this color.
|
65
61
|
#
|
66
62
|
# @param [#to_i] value
|
67
63
|
# @return [Integer]
|
68
|
-
|
64
|
+
|
69
65
|
# @method green
|
70
66
|
# Get the green channel of this color.
|
71
67
|
#
|
72
68
|
# @return [Integer]
|
73
|
-
|
69
|
+
|
74
70
|
# @method green=(value)
|
75
71
|
# Set the green channel of this color.
|
76
72
|
#
|
77
73
|
# @param [#to_i] value
|
78
74
|
# @return [Integer]
|
79
|
-
|
75
|
+
|
80
76
|
# @method blue=(value)
|
81
77
|
# Get the blue channel of this color.
|
82
78
|
#
|
83
79
|
# @return [Integer]
|
84
|
-
|
80
|
+
|
85
81
|
# @method blue=(value)
|
86
82
|
# Set the blue channel of this color.
|
87
83
|
#
|
88
84
|
# @param [#to_i] value
|
89
85
|
# @return [Integer]
|
90
|
-
|
86
|
+
|
91
87
|
# @method alpha
|
92
88
|
# Get the alpha channel of this color.
|
93
89
|
#
|
94
90
|
# @return [Integer]
|
95
|
-
|
91
|
+
|
96
92
|
# @method alpha=(value)
|
97
93
|
# Set the alpha channel of this color.
|
98
94
|
#
|
99
95
|
# @param [#to_i] value
|
100
96
|
# @return [Integer]
|
101
|
-
|
97
|
+
|
102
98
|
[:red, :green, :blue, :alpha].each do |channel|
|
103
99
|
attribute(channel) { |value| convert_and_constrain_value(value) }
|
104
100
|
end
|
105
|
-
|
101
|
+
|
106
102
|
attr_reader :lab
|
107
|
-
|
103
|
+
|
108
104
|
def -(other)
|
109
105
|
delta_e_2000(@lab, other.lab)
|
110
106
|
end
|
111
107
|
|
112
108
|
def <=>(other)
|
113
|
-
|
109
|
+
hsl[0] <=> other.hsl[0]
|
114
110
|
end
|
115
|
-
|
111
|
+
|
116
112
|
# Determing if this color is equivalent to another object.
|
117
113
|
#
|
118
114
|
# @param [Object] other
|
@@ -120,7 +116,7 @@ module Cura
|
|
120
116
|
def ==(other)
|
121
117
|
other.is_a?(Color) ? matches_color?(other) : super
|
122
118
|
end
|
123
|
-
|
119
|
+
|
124
120
|
def hsl
|
125
121
|
@hsl ||= rgb_to_hsl(@rgb)
|
126
122
|
end
|
@@ -128,61 +124,61 @@ module Cura
|
|
128
124
|
def yiq
|
129
125
|
@yiq ||= rgb_to_yiq(@rgb)
|
130
126
|
end
|
131
|
-
|
127
|
+
|
132
128
|
def to_a
|
133
129
|
[@red, @green, @blue, @alpha]
|
134
130
|
end
|
135
|
-
|
131
|
+
|
136
132
|
def hex
|
137
133
|
to_a.each_with_object("") { |part, memo| memo << "%02x" % part }
|
138
134
|
end
|
139
|
-
|
135
|
+
|
140
136
|
protected
|
141
|
-
|
137
|
+
|
142
138
|
def matches_color?(other)
|
143
139
|
@alpha == other.alpha && @red == other.red && @green == other.green && @blue && other.blue
|
144
140
|
end
|
145
|
-
|
141
|
+
|
146
142
|
# Convert the input to an Integer and constrain in or between 0 and 255.
|
147
143
|
def convert_and_constrain_value(value)
|
148
144
|
value = value.to_i
|
149
|
-
|
145
|
+
|
150
146
|
[255, [0, value].max].min
|
151
147
|
end
|
152
148
|
|
153
149
|
# source: http://www.easyrgb.com/index.php?X=MATH&H=02#text2
|
154
150
|
def rgb_to_xyz(color)
|
155
151
|
r, g, b = color.map do |v|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
152
|
+
v /= 255.0
|
153
|
+
if v > 0.04045
|
154
|
+
v = ((v + 0.055) / 1.055)**2.4
|
155
|
+
else
|
156
|
+
v /= 12.92
|
157
|
+
end
|
158
|
+
v *= 100
|
163
159
|
end
|
164
160
|
|
165
|
-
#Observer = 2
|
161
|
+
# Observer = 2 degrees, Illuminant = D65
|
166
162
|
x = r * 0.4124 + g * 0.3576 + b * 0.1805
|
167
163
|
y = r * 0.2126 + g * 0.7152 + b * 0.0722
|
168
164
|
z = r * 0.0193 + g * 0.1192 + b * 0.9505
|
169
165
|
|
170
|
-
|
166
|
+
[x, y, z]
|
171
167
|
end
|
172
168
|
|
173
169
|
def xyz_to_lab(color)
|
174
|
-
f = lambda
|
175
|
-
return t**(1.0/3) if t > (6.0 / 29)**3
|
170
|
+
f = lambda do |t|
|
171
|
+
return t**(1.0 / 3) if t > (6.0 / 29)**3
|
176
172
|
return (1.0 / 3) * ((29.0 / 6)**2) * t + (4.0 / 29)
|
177
|
-
|
173
|
+
end
|
178
174
|
|
179
175
|
x, y, z = color
|
180
176
|
xn, yn, zn = rgb_to_xyz([255, 255, 255])
|
181
|
-
l = 116 * f.call(y/yn) - 16
|
182
|
-
a = 500 * (f.call(x/xn) - f.call(y/yn))
|
183
|
-
b = 200 * (f.call(y/yn) - f.call(z/zn))
|
177
|
+
l = 116 * f.call(y / yn) - 16
|
178
|
+
a = 500 * (f.call(x / xn) - f.call(y / yn))
|
179
|
+
b = 200 * (f.call(y / yn) - f.call(z / zn))
|
184
180
|
|
185
|
-
|
181
|
+
[l, a, b]
|
186
182
|
end
|
187
183
|
|
188
184
|
def rgb_to_lab(rgb_val)
|
@@ -198,27 +194,27 @@ module Cura
|
|
198
194
|
lig = (max + min) / 2.0
|
199
195
|
|
200
196
|
if delta == 0
|
201
|
-
|
202
|
-
|
197
|
+
hue = 0
|
198
|
+
sat = 0
|
203
199
|
else
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
200
|
+
sat = if lig < 0.5
|
201
|
+
delta / (0.0 + (max + min))
|
202
|
+
else
|
203
|
+
delta / (2.0 - max - min)
|
204
|
+
end
|
205
|
+
|
206
|
+
delta_r = (((max - r) / 6.0) + (delta / 2.0)) / delta
|
207
|
+
delta_g = (((max - g) / 6.0) + (delta / 2.0)) / delta
|
208
|
+
delta_b = (((max - b) / 6.0) + (delta / 2.0)) / delta
|
209
|
+
|
210
|
+
hue = case max
|
211
|
+
when r then delta_b - delta_g
|
212
|
+
when g then (1.0 / 3) + delta_r - delta_b
|
213
|
+
when b then (2.0 / 3) + delta_g - delta_r
|
214
|
+
end
|
215
|
+
|
216
|
+
hue += 1 if hue < 0
|
217
|
+
hue -= 1 if hue > 1
|
222
218
|
end
|
223
219
|
|
224
220
|
[360 * hue, 100 * sat, 100 * lig]
|
@@ -227,9 +223,9 @@ module Cura
|
|
227
223
|
def rgb_to_yiq(rgb_val)
|
228
224
|
r, g, b = rgb_val
|
229
225
|
|
230
|
-
y = 0.299*r + 0.587*g + 0.114*b
|
231
|
-
i = 0.569*r - 0.275*g - 0.321*b
|
232
|
-
q = 0.212*r - 0.523*g + 0.311*b
|
226
|
+
y = 0.299 * r + 0.587 * g + 0.114 * b
|
227
|
+
i = 0.569 * r - 0.275 * g - 0.321 * b
|
228
|
+
q = 0.212 * r - 0.523 * g + 0.311 * b
|
233
229
|
|
234
230
|
[y, i, q]
|
235
231
|
end
|
@@ -241,27 +237,29 @@ module Cura
|
|
241
237
|
def deg_to_rad(v)
|
242
238
|
(v * Math::PI) / 180
|
243
239
|
end
|
244
|
-
|
240
|
+
|
245
241
|
def lab_to_hue(a, b)
|
246
242
|
bias = 0
|
247
|
-
return 0 if
|
248
|
-
return 180 if
|
249
|
-
return 90 if
|
250
|
-
return 270 if
|
243
|
+
return 0 if a >= 0 && b == 0
|
244
|
+
return 180 if a < 0 && b == 0
|
245
|
+
return 90 if a == 0 && b > 0
|
246
|
+
return 270 if a == 0 && b < 0
|
251
247
|
|
252
248
|
bias = case
|
253
|
-
|
254
|
-
|
255
|
-
|
249
|
+
when a > 0 && b > 0 then 0
|
250
|
+
when a < 0 then 180
|
251
|
+
when a > 0 && b < 0 then 360
|
256
252
|
end
|
257
253
|
|
258
254
|
rad_to_deg(Math.atan(b / a)) + bias
|
259
255
|
end
|
260
|
-
|
256
|
+
|
261
257
|
def delta_e_2000(lab1, lab2)
|
262
258
|
l1, a1, b1 = lab1
|
263
259
|
l2, a2, b2 = lab2
|
264
|
-
kl
|
260
|
+
kl = 1
|
261
|
+
kc = 1
|
262
|
+
kh = 1
|
265
263
|
|
266
264
|
xC1 = Math.sqrt(a1**2 + b1**2)
|
267
265
|
xC2 = Math.sqrt(a2**2 + b2**2)
|
@@ -307,24 +305,19 @@ module Cura
|
|
307
305
|
end
|
308
306
|
xHX /= 2.0
|
309
307
|
end
|
310
|
-
xTX = 1 - 0.17 * Math.cos(deg_to_rad(xHX - 30)) + 0.24 *
|
311
|
-
|
312
|
-
Math.cos(deg_to_rad(3 * xHX + 6)) - 0.20 *
|
313
|
-
Math.cos(deg_to_rad(4 * xHX - 63 ))
|
314
|
-
xPH = 30 * Math.exp(-((xHX - 275) / 25.0) * ((xHX - 275) / 25.0))
|
308
|
+
xTX = 1 - 0.17 * Math.cos(deg_to_rad(xHX - 30)) + 0.24 * Math.cos(deg_to_rad(2 * xHX)) + 0.32 * Math.cos(deg_to_rad(3 * xHX + 6)) - 0.20 * Math.cos(deg_to_rad(4 * xHX - 63))
|
309
|
+
xPH = 30 * Math.exp(-((xHX - 275) / 25.0) * ((xHX - 275) / 25.0))
|
315
310
|
xRC = 2 * Math.sqrt(xCY**7 / (xCY**7 + 25**7))
|
316
311
|
xSL = 1 + ((0.015 * ((xLX - 50) * (xLX - 50))) /
|
317
312
|
Math.sqrt(20 + ((xLX - 50) * (xLX - 50))))
|
318
313
|
xSC = 1 + 0.045 * xCY
|
319
314
|
xSH = 1 + 0.015 * xCY * xTX
|
320
315
|
xRT = -Math.sin(deg_to_rad(2 * xPH)) * xRC
|
321
|
-
xDL
|
322
|
-
xDC
|
323
|
-
xDH
|
316
|
+
xDL /= (kl * xSL)
|
317
|
+
xDC /= (kc * xSC)
|
318
|
+
xDH /= (kh * xSH)
|
324
319
|
|
325
320
|
Math.sqrt(xDL**2 + xDC**2 + xDH**2 + xRT * xDC * xDH)
|
326
321
|
end
|
327
|
-
|
328
322
|
end
|
329
|
-
|
330
323
|
end
|