glimmer-dsl-libui 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/README.md +625 -119
- data/VERSION +1 -1
- data/examples/dynamic_area.rb +77 -90
- data/examples/dynamic_area2.rb +14 -12
- data/examples/dynamic_area3.rb +90 -0
- data/examples/dynamic_area4.rb +95 -0
- data/examples/form_table.rb +0 -2
- data/examples/form_table2.rb +0 -2
- data/examples/histogram.rb +98 -91
- data/examples/histogram2.rb +109 -0
- data/examples/timer.rb +28 -31
- data/examples/timer2.rb +129 -0
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/libui/control_proxy/spinbox_proxy.rb +38 -0
- metadata +7 -2
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.4.
|
|
1
|
+
0.4.5
|
data/examples/dynamic_area.rb
CHANGED
|
@@ -1,97 +1,84 @@
|
|
|
1
1
|
require 'glimmer-dsl-libui'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
window('Dynamic Area', 240, 600) {
|
|
6
|
-
margined true
|
|
3
|
+
class DynamicArea
|
|
4
|
+
include Glimmer
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
@y_spinbox = spinbox(0, 1000) {
|
|
26
|
-
label 'y'
|
|
27
|
-
value 25
|
|
28
|
-
|
|
29
|
-
on_changed do
|
|
30
|
-
@area.queue_redraw_all
|
|
31
|
-
end
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
@width_spinbox = spinbox(0, 1000) {
|
|
35
|
-
label 'width'
|
|
36
|
-
value 150
|
|
37
|
-
|
|
38
|
-
on_changed do
|
|
39
|
-
@area.queue_redraw_all
|
|
40
|
-
end
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
@height_spinbox = spinbox(0, 1000) {
|
|
44
|
-
label 'height'
|
|
45
|
-
value 150
|
|
46
|
-
|
|
47
|
-
on_changed do
|
|
48
|
-
@area.queue_redraw_all
|
|
49
|
-
end
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@red_spinbox = spinbox(0, 255) {
|
|
53
|
-
label 'red'
|
|
54
|
-
value 102
|
|
55
|
-
|
|
56
|
-
on_changed do
|
|
57
|
-
@area.queue_redraw_all
|
|
58
|
-
end
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
@green_spinbox = spinbox(0, 255) {
|
|
62
|
-
label 'green'
|
|
63
|
-
value 102
|
|
64
|
-
|
|
65
|
-
on_changed do
|
|
66
|
-
@area.queue_redraw_all
|
|
67
|
-
end
|
|
68
|
-
}
|
|
6
|
+
attr_accessor :rectangle_x, :rectangle_y, :rectangle_width, :rectangle_height, :rectangle_red, :rectangle_green, :rectangle_blue, :rectangle_alpha
|
|
7
|
+
|
|
8
|
+
def initialize
|
|
9
|
+
@rectangle_x = 25
|
|
10
|
+
@rectangle_y = 25
|
|
11
|
+
@rectangle_width = 150
|
|
12
|
+
@rectangle_height = 150
|
|
13
|
+
@rectangle_red = 102
|
|
14
|
+
@rectangle_green = 102
|
|
15
|
+
@rectangle_blue = 204
|
|
16
|
+
@rectangle_alpha = 100
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def launch
|
|
20
|
+
window('Dynamic Area', 240, 600) {
|
|
21
|
+
margined true
|
|
69
22
|
|
|
70
|
-
|
|
71
|
-
label '
|
|
72
|
-
|
|
23
|
+
vertical_box {
|
|
24
|
+
label('Rectangle Properties') {
|
|
25
|
+
stretchy false
|
|
26
|
+
}
|
|
73
27
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
28
|
+
form {
|
|
29
|
+
stretchy false
|
|
30
|
+
|
|
31
|
+
spinbox(0, 1000) {
|
|
32
|
+
label 'x'
|
|
33
|
+
value <=> [self, :rectangle_x, after_write: -> {@area.queue_redraw_all}]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
spinbox(0, 1000) {
|
|
37
|
+
label 'y'
|
|
38
|
+
value <=> [self, :rectangle_y, after_write: -> {@area.queue_redraw_all}]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
spinbox(0, 1000) {
|
|
42
|
+
label 'width'
|
|
43
|
+
value <=> [self, :rectangle_width, after_write: -> {@area.queue_redraw_all}]
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
spinbox(0, 1000) {
|
|
47
|
+
label 'height'
|
|
48
|
+
value <=> [self, :rectangle_height, after_write: -> {@area.queue_redraw_all}]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
spinbox(0, 255) {
|
|
52
|
+
label 'red'
|
|
53
|
+
value <=> [self, :rectangle_red, after_write: -> {@area.queue_redraw_all}]
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
spinbox(0, 255) {
|
|
57
|
+
label 'green'
|
|
58
|
+
value <=> [self, :rectangle_green, after_write: -> {@area.queue_redraw_all}]
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
spinbox(0, 255) {
|
|
62
|
+
label 'blue'
|
|
63
|
+
value <=> [self, :rectangle_blue, after_write: -> {@area.queue_redraw_all}]
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
spinbox(0, 100) {
|
|
67
|
+
label 'alpha'
|
|
68
|
+
value <=> [self, :rectangle_alpha, after_write: -> {@area.queue_redraw_all}]
|
|
69
|
+
}
|
|
70
|
+
}
|
|
82
71
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
@area = area {
|
|
90
|
-
on_draw do |area_draw_params|
|
|
91
|
-
rectangle(@x_spinbox.value, @y_spinbox.value, @width_spinbox.value, @height_spinbox.value) { # a dynamic path is added semi-declaratively inside on_draw block
|
|
92
|
-
fill r: @red_spinbox.value, g: @green_spinbox.value, b: @blue_spinbox.value, a: @alpha_spinbox.value / 100.0
|
|
72
|
+
@area = area {
|
|
73
|
+
on_draw do |area_draw_params|
|
|
74
|
+
rectangle(rectangle_x, rectangle_y, rectangle_width, rectangle_height) { # a dynamic path is added semi-declaratively inside on_draw block
|
|
75
|
+
fill r: rectangle_red, g: rectangle_green, b: rectangle_blue, a: rectangle_alpha / 100.0
|
|
76
|
+
}
|
|
77
|
+
end
|
|
93
78
|
}
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
79
|
+
}
|
|
80
|
+
}.show
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
DynamicArea.new.launch
|
data/examples/dynamic_area2.rb
CHANGED
|
@@ -18,7 +18,7 @@ window('Dynamic Area', 240, 600) {
|
|
|
18
18
|
value 25
|
|
19
19
|
|
|
20
20
|
on_changed do
|
|
21
|
-
@
|
|
21
|
+
@area.queue_redraw_all
|
|
22
22
|
end
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -27,7 +27,7 @@ window('Dynamic Area', 240, 600) {
|
|
|
27
27
|
value 25
|
|
28
28
|
|
|
29
29
|
on_changed do
|
|
30
|
-
@
|
|
30
|
+
@area.queue_redraw_all
|
|
31
31
|
end
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -36,7 +36,7 @@ window('Dynamic Area', 240, 600) {
|
|
|
36
36
|
value 150
|
|
37
37
|
|
|
38
38
|
on_changed do
|
|
39
|
-
@
|
|
39
|
+
@area.queue_redraw_all
|
|
40
40
|
end
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -45,7 +45,7 @@ window('Dynamic Area', 240, 600) {
|
|
|
45
45
|
value 150
|
|
46
46
|
|
|
47
47
|
on_changed do
|
|
48
|
-
@
|
|
48
|
+
@area.queue_redraw_all
|
|
49
49
|
end
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -54,7 +54,7 @@ window('Dynamic Area', 240, 600) {
|
|
|
54
54
|
value 102
|
|
55
55
|
|
|
56
56
|
on_changed do
|
|
57
|
-
@
|
|
57
|
+
@area.queue_redraw_all
|
|
58
58
|
end
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -63,7 +63,7 @@ window('Dynamic Area', 240, 600) {
|
|
|
63
63
|
value 102
|
|
64
64
|
|
|
65
65
|
on_changed do
|
|
66
|
-
@
|
|
66
|
+
@area.queue_redraw_all
|
|
67
67
|
end
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -72,7 +72,7 @@ window('Dynamic Area', 240, 600) {
|
|
|
72
72
|
value 204
|
|
73
73
|
|
|
74
74
|
on_changed do
|
|
75
|
-
@
|
|
75
|
+
@area.queue_redraw_all
|
|
76
76
|
end
|
|
77
77
|
}
|
|
78
78
|
|
|
@@ -81,15 +81,17 @@ window('Dynamic Area', 240, 600) {
|
|
|
81
81
|
value 100
|
|
82
82
|
|
|
83
83
|
on_changed do
|
|
84
|
-
@
|
|
84
|
+
@area.queue_redraw_all
|
|
85
85
|
end
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
area {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
@area = area {
|
|
90
|
+
on_draw do |area_draw_params|
|
|
91
|
+
rectangle(@x_spinbox.value, @y_spinbox.value, @width_spinbox.value, @height_spinbox.value) { # a dynamic path is added semi-declaratively inside on_draw block
|
|
92
|
+
fill r: @red_spinbox.value, g: @green_spinbox.value, b: @blue_spinbox.value, a: @alpha_spinbox.value / 100.0
|
|
93
|
+
}
|
|
94
|
+
end
|
|
93
95
|
}
|
|
94
96
|
}
|
|
95
97
|
}.show
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
require 'glimmer-dsl-libui'
|
|
2
|
+
|
|
3
|
+
class DynamicArea
|
|
4
|
+
include Glimmer
|
|
5
|
+
|
|
6
|
+
attr_accessor :rectangle_x, :rectangle_y, :rectangle_width, :rectangle_height, :rectangle_red, :rectangle_green, :rectangle_blue, :rectangle_alpha
|
|
7
|
+
|
|
8
|
+
def initialize
|
|
9
|
+
@rectangle_x = 25
|
|
10
|
+
@rectangle_y = 25
|
|
11
|
+
@rectangle_width = 150
|
|
12
|
+
@rectangle_height = 150
|
|
13
|
+
@rectangle_red = 102
|
|
14
|
+
@rectangle_green = 102
|
|
15
|
+
@rectangle_blue = 204
|
|
16
|
+
@rectangle_alpha = 100
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def rectangle_fill
|
|
20
|
+
{ r: rectangle_red, g: rectangle_green, b: rectangle_blue, a: rectangle_alpha / 100.0 }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def launch
|
|
24
|
+
window('Dynamic Area', 240, 600) {
|
|
25
|
+
margined true
|
|
26
|
+
|
|
27
|
+
vertical_box {
|
|
28
|
+
label('Rectangle Properties') {
|
|
29
|
+
stretchy false
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
form {
|
|
33
|
+
stretchy false
|
|
34
|
+
|
|
35
|
+
@x_spinbox = spinbox(0, 1000) {
|
|
36
|
+
label 'x'
|
|
37
|
+
value <=> [self, :rectangle_x]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@y_spinbox = spinbox(0, 1000) {
|
|
41
|
+
label 'y'
|
|
42
|
+
value <=> [self, :rectangle_y]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@width_spinbox = spinbox(0, 1000) {
|
|
46
|
+
label 'width'
|
|
47
|
+
value <=> [self, :rectangle_width]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@height_spinbox = spinbox(0, 1000) {
|
|
51
|
+
label 'height'
|
|
52
|
+
value <=> [self, :rectangle_height]
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@red_spinbox = spinbox(0, 255) {
|
|
56
|
+
label 'red'
|
|
57
|
+
value <=> [self, :rectangle_red]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@green_spinbox = spinbox(0, 255) {
|
|
61
|
+
label 'green'
|
|
62
|
+
value <=> [self, :rectangle_green]
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@blue_spinbox = spinbox(0, 255) {
|
|
66
|
+
label 'blue'
|
|
67
|
+
value <=> [self, :rectangle_blue]
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@alpha_spinbox = spinbox(0, 100) {
|
|
71
|
+
label 'alpha'
|
|
72
|
+
value <=> [self, :rectangle_alpha]
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
area {
|
|
77
|
+
@rectangle = rectangle { # stable implicit path shape
|
|
78
|
+
x <= [self, :rectangle_x]
|
|
79
|
+
y <= [self, :rectangle_y]
|
|
80
|
+
width <= [self, :rectangle_width]
|
|
81
|
+
height <= [self, :rectangle_height]
|
|
82
|
+
fill <= [self, :rectangle_fill, computed_by: [:rectangle_red, :rectangle_green, :rectangle_blue, :rectangle_alpha]]
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}.show
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
DynamicArea.new.launch
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
require 'glimmer-dsl-libui'
|
|
2
|
+
|
|
3
|
+
include Glimmer
|
|
4
|
+
|
|
5
|
+
window('Dynamic Area', 240, 600) {
|
|
6
|
+
margined true
|
|
7
|
+
|
|
8
|
+
vertical_box {
|
|
9
|
+
label('Rectangle Properties') {
|
|
10
|
+
stretchy false
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
form {
|
|
14
|
+
stretchy false
|
|
15
|
+
|
|
16
|
+
@x_spinbox = spinbox(0, 1000) {
|
|
17
|
+
label 'x'
|
|
18
|
+
value 25
|
|
19
|
+
|
|
20
|
+
on_changed do
|
|
21
|
+
@rectangle.x = @x_spinbox.value # updating properties automatically triggers area.queue_redraw_all
|
|
22
|
+
end
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@y_spinbox = spinbox(0, 1000) {
|
|
26
|
+
label 'y'
|
|
27
|
+
value 25
|
|
28
|
+
|
|
29
|
+
on_changed do
|
|
30
|
+
@rectangle.y = @y_spinbox.value # updating properties automatically triggers area.queue_redraw_all
|
|
31
|
+
end
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@width_spinbox = spinbox(0, 1000) {
|
|
35
|
+
label 'width'
|
|
36
|
+
value 150
|
|
37
|
+
|
|
38
|
+
on_changed do
|
|
39
|
+
@rectangle.width = @width_spinbox.value # updating properties automatically triggers area.queue_redraw_all
|
|
40
|
+
end
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@height_spinbox = spinbox(0, 1000) {
|
|
44
|
+
label 'height'
|
|
45
|
+
value 150
|
|
46
|
+
|
|
47
|
+
on_changed do
|
|
48
|
+
@rectangle.height = @height_spinbox.value # updating properties automatically triggers area.queue_redraw_all
|
|
49
|
+
end
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@red_spinbox = spinbox(0, 255) {
|
|
53
|
+
label 'red'
|
|
54
|
+
value 102
|
|
55
|
+
|
|
56
|
+
on_changed do
|
|
57
|
+
@rectangle.fill[:r] = @red_spinbox.value # updating hash properties automatically triggers area.queue_redraw_all
|
|
58
|
+
end
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@green_spinbox = spinbox(0, 255) {
|
|
62
|
+
label 'green'
|
|
63
|
+
value 102
|
|
64
|
+
|
|
65
|
+
on_changed do
|
|
66
|
+
@rectangle.fill[:g] = @green_spinbox.value # updating hash properties automatically triggers area.queue_redraw_all
|
|
67
|
+
end
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@blue_spinbox = spinbox(0, 255) {
|
|
71
|
+
label 'blue'
|
|
72
|
+
value 204
|
|
73
|
+
|
|
74
|
+
on_changed do
|
|
75
|
+
@rectangle.fill[:b] = @blue_spinbox.value # updating hash properties automatically triggers area.queue_redraw_all
|
|
76
|
+
end
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@alpha_spinbox = spinbox(0, 100) {
|
|
80
|
+
label 'alpha'
|
|
81
|
+
value 100
|
|
82
|
+
|
|
83
|
+
on_changed do
|
|
84
|
+
@rectangle.fill[:a] = @alpha_spinbox.value / 100.0 # updating hash properties automatically triggers area.queue_redraw_all
|
|
85
|
+
end
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
area {
|
|
90
|
+
@rectangle = rectangle(@x_spinbox.value, @y_spinbox.value, @width_spinbox.value, @height_spinbox.value) { # stable implicit path shape
|
|
91
|
+
fill r: @red_spinbox.value, g: @green_spinbox.value, b: @blue_spinbox.value, a: @alpha_spinbox.value / 100.0
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}.show
|
data/examples/form_table.rb
CHANGED
data/examples/form_table2.rb
CHANGED
data/examples/histogram.rb
CHANGED
|
@@ -2,106 +2,113 @@
|
|
|
2
2
|
|
|
3
3
|
require 'glimmer-dsl-libui'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def point_locations(width, height)
|
|
23
|
-
xincr = width / 9.0 # 10 - 1 to make the last point be at the end
|
|
24
|
-
yincr = height / 100.0
|
|
25
|
-
|
|
26
|
-
@datapoints.each_with_index.map do |value, i|
|
|
27
|
-
val = 100 - value
|
|
28
|
-
[xincr * i, yincr * val]
|
|
5
|
+
class Histogram
|
|
6
|
+
include Glimmer
|
|
7
|
+
|
|
8
|
+
X_OFF_LEFT = 20
|
|
9
|
+
Y_OFF_TOP = 20
|
|
10
|
+
X_OFF_RIGHT = 20
|
|
11
|
+
Y_OFF_BOTTOM = 20
|
|
12
|
+
POINT_RADIUS = 5
|
|
13
|
+
COLOR_BLUE = Glimmer::LibUI.interpret_color(0x1E90FF)
|
|
14
|
+
|
|
15
|
+
attr_accessor :datapoints, :histogram_color
|
|
16
|
+
|
|
17
|
+
def initialize
|
|
18
|
+
@datapoints = 10.times.map {Random.new.rand(90)}
|
|
19
|
+
@histogram_color = COLOR_BLUE
|
|
29
20
|
end
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
21
|
+
|
|
22
|
+
def graph_size(area_width, area_height)
|
|
23
|
+
graph_width = area_width - X_OFF_LEFT - X_OFF_RIGHT
|
|
24
|
+
graph_height = area_height - Y_OFF_TOP - Y_OFF_BOTTOM
|
|
25
|
+
[graph_width, graph_height]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def point_locations(width, height)
|
|
29
|
+
xincr = width / 9.0 # 10 - 1 to make the last point be at the end
|
|
30
|
+
yincr = height / 100.0
|
|
31
|
+
|
|
32
|
+
@datapoints.each_with_index.map do |value, i|
|
|
33
|
+
val = 100 - value
|
|
34
|
+
[xincr * i, yincr * val]
|
|
40
35
|
end
|
|
41
|
-
|
|
42
|
-
# apply a transform to the coordinate space for this path so (0, 0) is the top-left corner of the graph
|
|
43
|
-
transform {
|
|
44
|
-
translate X_OFF_LEFT, Y_OFF_TOP
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
block.call
|
|
48
|
-
}
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
window('histogram example', 640, 480) {
|
|
52
|
-
margined true
|
|
36
|
+
end
|
|
53
37
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
on_changed do
|
|
64
|
-
@datapoints[i] = sb.value
|
|
65
|
-
@area.queue_redraw_all
|
|
66
|
-
end
|
|
67
|
-
}
|
|
38
|
+
# method-based custom control representing a graph path
|
|
39
|
+
def graph_path(width, height, should_extend, &block)
|
|
40
|
+
locations = point_locations(width, height).flatten
|
|
41
|
+
path {
|
|
42
|
+
if should_extend
|
|
43
|
+
polygon(locations + [width, height, 0, height])
|
|
44
|
+
else
|
|
45
|
+
polyline(locations)
|
|
68
46
|
end
|
|
69
47
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
on_changed do
|
|
75
|
-
@area.queue_redraw_all
|
|
76
|
-
end
|
|
48
|
+
# apply a transform to the coordinate space for this path so (0, 0) is the top-left corner of the graph
|
|
49
|
+
transform {
|
|
50
|
+
translate X_OFF_LEFT, Y_OFF_TOP
|
|
77
51
|
}
|
|
52
|
+
|
|
53
|
+
block.call
|
|
78
54
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
graph_width, graph_height = *graph_size(area_draw_params[:area_width], area_draw_params[:area_height])
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def launch
|
|
58
|
+
window('histogram example', 640, 480) {
|
|
59
|
+
margined true
|
|
87
60
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
61
|
+
horizontal_box {
|
|
62
|
+
vertical_box {
|
|
63
|
+
stretchy false
|
|
91
64
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
65
|
+
10.times do |i|
|
|
66
|
+
spinbox(0, 100) { |sb|
|
|
67
|
+
stretchy false
|
|
68
|
+
value <=> [self, "datapoints[#{i}]", after_write: -> { @area.queue_redraw_all }]
|
|
69
|
+
}
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
color_button { |cb|
|
|
73
|
+
stretchy false
|
|
74
|
+
color COLOR_BLUE
|
|
75
|
+
|
|
76
|
+
on_changed do
|
|
77
|
+
@histogram_color = cb.color
|
|
78
|
+
@area.queue_redraw_all
|
|
79
|
+
end
|
|
80
|
+
}
|
|
98
81
|
}
|
|
99
82
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
83
|
+
@area = area {
|
|
84
|
+
on_draw do |area_draw_params|
|
|
85
|
+
rectangle(0, 0, area_draw_params[:area_width], area_draw_params[:area_height]) {
|
|
86
|
+
fill 0xFFFFFF
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
graph_width, graph_height = *graph_size(area_draw_params[:area_width], area_draw_params[:area_height])
|
|
90
|
+
|
|
91
|
+
figure(X_OFF_LEFT, Y_OFF_TOP) {
|
|
92
|
+
line(X_OFF_LEFT, Y_OFF_TOP + graph_height)
|
|
93
|
+
line(X_OFF_LEFT + graph_width, Y_OFF_TOP + graph_height)
|
|
94
|
+
|
|
95
|
+
stroke 0x000000, thickness: 2, miter_limit: 10
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
# now create the fill for the graph below the graph line
|
|
99
|
+
graph_path(graph_width, graph_height, true) {
|
|
100
|
+
fill @histogram_color.merge(a: 0.5)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
# now draw the histogram line
|
|
104
|
+
graph_path(graph_width, graph_height, false) {
|
|
105
|
+
stroke @histogram_color.merge(thickness: 2, miter_limit: 10)
|
|
106
|
+
}
|
|
107
|
+
end
|
|
103
108
|
}
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
109
|
+
}
|
|
110
|
+
}.show
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
Histogram.new.launch
|