glimmer-dsl-libui 0.2.22 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -0
- data/README.md +685 -103
- data/VERSION +1 -1
- data/bin/girb +0 -0
- data/examples/area_gallery.rb +1 -1
- data/examples/area_gallery2.rb +1 -1
- data/examples/area_gallery3.rb +1 -1
- data/examples/area_gallery4.rb +1 -1
- data/examples/basic_image.rb +19 -0
- data/examples/basic_image2.rb +13 -0
- data/examples/basic_image3.rb +23 -0
- data/examples/basic_image4.rb +17 -0
- data/examples/basic_image5.rb +75 -0
- data/examples/basic_table_color.rb +1 -11
- data/examples/basic_table_color2.rb +39 -0
- data/examples/basic_table_image.rb +2 -14
- data/examples/basic_table_image2.rb +44 -0
- data/examples/basic_table_image_text.rb +2 -13
- data/examples/basic_table_image_text2.rb +44 -0
- data/examples/snake/model/game.rb +0 -1
- data/examples/tetris.rb +23 -3
- data/examples/tic_tac_toe.rb +1 -1
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/dsl/libui/control_expression.rb +1 -1
- data/lib/glimmer/libui/control_proxy/area_proxy.rb +1 -0
- data/lib/glimmer/libui/control_proxy/column.rb +2 -2
- data/lib/glimmer/libui/control_proxy/image_part_proxy.rb +0 -1
- data/lib/glimmer/libui/control_proxy/image_proxy.rb +160 -12
- data/lib/glimmer/libui/control_proxy/table_proxy.rb +15 -2
- data/lib/glimmer/libui/control_proxy/window_proxy.rb +1 -1
- data/lib/glimmer/libui/control_proxy.rb +7 -7
- data/lib/glimmer/libui/image_path_renderer.rb +30 -0
- data/lib/glimmer/libui.rb +6 -5
- metadata +27 -18
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.1
|
data/bin/girb
CHANGED
File without changes
|
data/examples/area_gallery.rb
CHANGED
data/examples/area_gallery2.rb
CHANGED
data/examples/area_gallery3.rb
CHANGED
data/examples/area_gallery4.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'glimmer-dsl-libui'
|
4
|
+
|
5
|
+
include Glimmer
|
6
|
+
|
7
|
+
window('Basic Image', 96, 96) {
|
8
|
+
area {
|
9
|
+
# image is not a real LibUI control. It is built in Glimmer as a custom control that renders
|
10
|
+
# tiny pixels/lines as rectangle paths. As such, it does not have good performance, but can
|
11
|
+
# be used in exceptional circumstances where an image control is really needed.
|
12
|
+
#
|
13
|
+
# Furthermore, adding image directly under area is even slower due to taking up more memory for every
|
14
|
+
# image pixel rendered. Check basic_image2.rb for a faster alternative using on_draw manually.
|
15
|
+
#
|
16
|
+
# It is recommended to pass width/height args to shrink image and achieve faster performance.
|
17
|
+
image(File.expand_path('../icons/glimmer.png', __dir__), 96, 96)
|
18
|
+
}
|
19
|
+
}.show
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'glimmer-dsl-libui'
|
4
|
+
|
5
|
+
include Glimmer
|
6
|
+
|
7
|
+
window('Basic Image', 96, 96) {
|
8
|
+
area {
|
9
|
+
# image is not a real LibUI control. It is built in Glimmer as a custom control that renders
|
10
|
+
# tiny pixels/lines as rectangle paths. As such, it does not have good performance, but can
|
11
|
+
# be used in exceptional circumstances where an image control is really needed.
|
12
|
+
#
|
13
|
+
# Furthermore, adding image directly under area is even slower due to taking up more memory for every
|
14
|
+
# image pixel rendered. Check basic_image4.rb for a faster alternative using on_draw manually.
|
15
|
+
#
|
16
|
+
# It is recommended to pass width/height args to shrink image and achieve faster performance.
|
17
|
+
image {
|
18
|
+
file File.expand_path('../icons/glimmer.png', __dir__)
|
19
|
+
width 96
|
20
|
+
height 96
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}.show
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'glimmer-dsl-libui'
|
4
|
+
|
5
|
+
include Glimmer
|
6
|
+
|
7
|
+
window('Basic Image', 96, 96) {
|
8
|
+
area {
|
9
|
+
on_draw do |area_draw_params|
|
10
|
+
image {
|
11
|
+
file File.expand_path('../icons/glimmer.png', __dir__)
|
12
|
+
width 96
|
13
|
+
height 96
|
14
|
+
}
|
15
|
+
end
|
16
|
+
}
|
17
|
+
}.show
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This is the manual way of rendering an image unto an area control.
|
4
|
+
# It could come in handy in special situations.
|
5
|
+
# Otherwise, it is recommended to simply utilize the `image` control that
|
6
|
+
# can be nested under area or area on_draw listener to automate all this work.
|
7
|
+
|
8
|
+
require 'glimmer-dsl-libui'
|
9
|
+
require 'chunky_png'
|
10
|
+
|
11
|
+
include Glimmer
|
12
|
+
|
13
|
+
puts 'Parsing image...'; $stdout.flush
|
14
|
+
|
15
|
+
f = File.open(File.expand_path('../icons/glimmer.png', __dir__))
|
16
|
+
canvas = ChunkyPNG::Canvas.from_io(f)
|
17
|
+
f.close
|
18
|
+
canvas.resample_nearest_neighbor!(96, 96)
|
19
|
+
data = canvas.to_rgba_stream
|
20
|
+
width = canvas.width
|
21
|
+
height = canvas.height
|
22
|
+
puts "Image width: #{width}"
|
23
|
+
puts "Image height: #{height}"
|
24
|
+
|
25
|
+
puts 'Parsing colors...'; $stdout.flush
|
26
|
+
|
27
|
+
color_maps = height.times.map do |y|
|
28
|
+
width.times.map do |x|
|
29
|
+
r = data[(y*width + x)*4].ord
|
30
|
+
g = data[(y*width + x)*4 + 1].ord
|
31
|
+
b = data[(y*width + x)*4 + 2].ord
|
32
|
+
a = data[(y*width + x)*4 + 3].ord
|
33
|
+
{x: x, y: y, color: {r: r, g: g, b: b, a: a}}
|
34
|
+
end
|
35
|
+
end.flatten
|
36
|
+
puts "#{color_maps.size} pixels to render..."; $stdout.flush
|
37
|
+
|
38
|
+
puts 'Parsing shapes...'; $stdout.flush
|
39
|
+
|
40
|
+
shape_maps = []
|
41
|
+
original_color_maps = color_maps.dup
|
42
|
+
indexed_original_color_maps = Hash[original_color_maps.each_with_index.to_a]
|
43
|
+
color_maps.each do |color_map|
|
44
|
+
index = indexed_original_color_maps[color_map]
|
45
|
+
@rectangle_start_x ||= color_map[:x]
|
46
|
+
@rectangle_width ||= 1
|
47
|
+
if color_map[:x] < width - 1 && color_map[:color] == original_color_maps[index + 1][:color]
|
48
|
+
@rectangle_width += 1
|
49
|
+
else
|
50
|
+
if color_map[:x] > 0 && color_map[:color] == original_color_maps[index - 1][:color]
|
51
|
+
shape_maps << {x: @rectangle_start_x, y: color_map[:y], width: @rectangle_width, height: 1, color: color_map[:color]}
|
52
|
+
else
|
53
|
+
shape_maps << {x: color_map[:x], y: color_map[:y], width: 1, height: 1, color: color_map[:color]}
|
54
|
+
end
|
55
|
+
@rectangle_width = 1
|
56
|
+
@rectangle_start_x = color_map[:x] == width - 1 ? 0 : color_map[:x] + 1
|
57
|
+
end
|
58
|
+
end
|
59
|
+
puts "#{shape_maps.size} shapes to render..."; $stdout.flush
|
60
|
+
|
61
|
+
puts 'Rendering image...'; $stdout.flush
|
62
|
+
|
63
|
+
window('Basic Image', 96, 96) {
|
64
|
+
area {
|
65
|
+
on_draw do |area_draw_params|
|
66
|
+
shape_maps.each do |shape_map|
|
67
|
+
path {
|
68
|
+
rectangle(shape_map[:x], shape_map[:y], shape_map[:width], shape_map[:height])
|
69
|
+
|
70
|
+
fill shape_map[:color]
|
71
|
+
}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
}
|
75
|
+
}.show
|
@@ -1,20 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'glimmer-dsl-libui'
|
4
|
-
require 'chunky_png'
|
5
4
|
|
6
5
|
include Glimmer
|
7
6
|
|
8
|
-
|
9
|
-
canvas = ChunkyPNG::Canvas.from_io(f)
|
10
|
-
f.close
|
11
|
-
canvas.resample_nearest_neighbor!(24, 24)
|
12
|
-
data = canvas.to_rgba_stream
|
13
|
-
width = canvas.width
|
14
|
-
height = canvas.height
|
15
|
-
img = image {
|
16
|
-
image_part(data, width, height, width * 4)
|
17
|
-
}
|
7
|
+
img = image(File.expand_path('../icons/glimmer.png', __dir__), 24, 24)
|
18
8
|
|
19
9
|
data = [
|
20
10
|
[['cat', :red] , ['meow', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], {r: 255, g: 120, b: 0, a: 0.5}],
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'glimmer-dsl-libui'
|
4
|
+
require 'chunky_png'
|
5
|
+
|
6
|
+
include Glimmer
|
7
|
+
|
8
|
+
f = File.open(File.expand_path('../icons/glimmer.png', __dir__))
|
9
|
+
canvas = ChunkyPNG::Canvas.from_io(f)
|
10
|
+
f.close
|
11
|
+
canvas.resample_nearest_neighbor!(24, 24)
|
12
|
+
data = canvas.to_rgba_stream
|
13
|
+
width = canvas.width
|
14
|
+
height = canvas.height
|
15
|
+
img = image {
|
16
|
+
image_part(data, width, height, width * 4)
|
17
|
+
}
|
18
|
+
|
19
|
+
data = [
|
20
|
+
[['cat', :red] , ['meow', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], {r: 255, g: 120, b: 0, a: 0.5}],
|
21
|
+
[['dog', :yellow] , ['woof', {r: 240, g: 32, b: 32}] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], :skyblue],
|
22
|
+
[['chicken', :beige], ['cock-a-doodle-doo', :blue] , [false, 'mammal', :red] , [img, 'Glimmer', :beige], {r: 5, g: 120, b: 110}],
|
23
|
+
[['horse', :purple] , ['neigh', {r: 240, g: 32, b: 32}], [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], '13a1fb'],
|
24
|
+
[['cow', :gray] , ['moo', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :brown], 0x12ff02]
|
25
|
+
]
|
26
|
+
|
27
|
+
window('Animals', 500, 200) {
|
28
|
+
horizontal_box {
|
29
|
+
table {
|
30
|
+
text_color_column('Animal')
|
31
|
+
text_color_column('Sound')
|
32
|
+
checkbox_text_color_column('Description')
|
33
|
+
image_text_color_column('GUI')
|
34
|
+
background_color_column('Mammal')
|
35
|
+
|
36
|
+
cell_rows data
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}.show
|
@@ -4,8 +4,6 @@
|
|
4
4
|
# This example displays images that can be freely downloaded from the Studio Ghibli website.
|
5
5
|
|
6
6
|
require 'glimmer-dsl-libui'
|
7
|
-
require 'chunky_png'
|
8
|
-
require 'open-uri'
|
9
7
|
|
10
8
|
include Glimmer
|
11
9
|
|
@@ -13,18 +11,8 @@ IMAGE_ROWS = []
|
|
13
11
|
|
14
12
|
50.times do |i|
|
15
13
|
url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
|
16
|
-
puts "Processing Image: #{url}"
|
17
|
-
|
18
|
-
f = URI.open(url)
|
19
|
-
canvas = ChunkyPNG::Canvas.from_io(f)
|
20
|
-
f.close
|
21
|
-
data = canvas.to_rgba_stream
|
22
|
-
width = canvas.width
|
23
|
-
height = canvas.height
|
24
|
-
img = image {
|
25
|
-
image_part(data, width, height, width * 4)
|
26
|
-
}
|
27
|
-
IMAGE_ROWS << [img] # array of one column cell
|
14
|
+
puts "Processing Image: #{url}"; $stdout.flush # for Windows
|
15
|
+
IMAGE_ROWS << [image(url)] # array of one column cell
|
28
16
|
rescue StandardError => e
|
29
17
|
warn url, e.message
|
30
18
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# NOTE:
|
4
|
+
# This example displays images that can be freely downloaded from the Studio Ghibli website.
|
5
|
+
|
6
|
+
require 'glimmer-dsl-libui'
|
7
|
+
require 'chunky_png'
|
8
|
+
require 'open-uri'
|
9
|
+
|
10
|
+
include Glimmer
|
11
|
+
|
12
|
+
IMAGE_ROWS = []
|
13
|
+
|
14
|
+
50.times do |i|
|
15
|
+
url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
|
16
|
+
puts "Processing Image: #{url}"
|
17
|
+
$stdout.flush # for Windows
|
18
|
+
f = URI.open(url)
|
19
|
+
canvas = ChunkyPNG::Canvas.from_io(f)
|
20
|
+
f.close
|
21
|
+
data = canvas.to_rgba_stream
|
22
|
+
width = canvas.width
|
23
|
+
height = canvas.height
|
24
|
+
img = image {
|
25
|
+
image_part(data, width, height, width * 4)
|
26
|
+
}
|
27
|
+
IMAGE_ROWS << [img] # array of one column cell
|
28
|
+
rescue StandardError => e
|
29
|
+
warn url, e.message
|
30
|
+
end
|
31
|
+
|
32
|
+
window('The Red Turtle', 310, 350, false) {
|
33
|
+
horizontal_box {
|
34
|
+
table {
|
35
|
+
image_column('www.ghibli.jp/works/red-turtle')
|
36
|
+
|
37
|
+
cell_rows IMAGE_ROWS
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
on_closing do
|
42
|
+
puts 'Bye Bye'
|
43
|
+
end
|
44
|
+
}.show
|
@@ -4,8 +4,6 @@
|
|
4
4
|
# This example displays images that can be freely downloaded from the Studio Ghibli website.
|
5
5
|
|
6
6
|
require 'glimmer-dsl-libui'
|
7
|
-
require 'chunky_png'
|
8
|
-
require 'open-uri'
|
9
7
|
|
10
8
|
include Glimmer
|
11
9
|
|
@@ -13,18 +11,9 @@ IMAGE_ROWS = []
|
|
13
11
|
|
14
12
|
5.times do |i|
|
15
13
|
url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
|
16
|
-
puts "Processing Image: #{url}"
|
17
|
-
$stdout.flush # for Windows
|
18
|
-
f = URI.open(url)
|
19
|
-
canvas = ChunkyPNG::Canvas.from_io(f)
|
20
|
-
f.close
|
21
|
-
data = canvas.to_rgba_stream
|
22
|
-
width = canvas.width
|
23
|
-
height = canvas.height
|
24
|
-
img = image {
|
25
|
-
image_part(data, width, height, width * 4)
|
26
|
-
}
|
14
|
+
puts "Processing Image: #{url}"; $stdout.flush # for Windows
|
27
15
|
text = url.sub('https://www.ghibli.jp/gallery/thumb-redturtle', '').sub('.png', '')
|
16
|
+
img = image(url)
|
28
17
|
IMAGE_ROWS << [[img, text], [img, text]] # cell values are dual-element arrays
|
29
18
|
rescue StandardError => e
|
30
19
|
warn url, e.message
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# NOTE:
|
4
|
+
# This example displays images that can be freely downloaded from the Studio Ghibli website.
|
5
|
+
|
6
|
+
require 'glimmer-dsl-libui'
|
7
|
+
require 'chunky_png'
|
8
|
+
require 'open-uri'
|
9
|
+
|
10
|
+
include Glimmer
|
11
|
+
|
12
|
+
IMAGE_ROWS = []
|
13
|
+
|
14
|
+
5.times do |i|
|
15
|
+
url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
|
16
|
+
puts "Processing Image: #{url}"
|
17
|
+
$stdout.flush # for Windows
|
18
|
+
f = URI.open(url)
|
19
|
+
canvas = ChunkyPNG::Canvas.from_io(f)
|
20
|
+
f.close
|
21
|
+
data = canvas.to_rgba_stream
|
22
|
+
width = canvas.width
|
23
|
+
height = canvas.height
|
24
|
+
img = image {
|
25
|
+
image_part(data, width, height, width * 4)
|
26
|
+
}
|
27
|
+
text = url.sub('https://www.ghibli.jp/gallery/thumb-redturtle', '').sub('.png', '')
|
28
|
+
IMAGE_ROWS << [[img, text], [img, text]] # cell values are dual-element arrays
|
29
|
+
rescue StandardError => e
|
30
|
+
warn url, e.message
|
31
|
+
end
|
32
|
+
|
33
|
+
window('The Red Turtle', 670, 350) {
|
34
|
+
horizontal_box {
|
35
|
+
table {
|
36
|
+
image_text_column('image/number')
|
37
|
+
image_text_column('image/number (editable)') {
|
38
|
+
editable true
|
39
|
+
}
|
40
|
+
|
41
|
+
cell_rows IMAGE_ROWS
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}.show
|
data/examples/tetris.rb
CHANGED
@@ -153,6 +153,8 @@ class Tetris
|
|
153
153
|
end
|
154
154
|
}
|
155
155
|
radio_menu_item('Rotate Left on Up Arrow') {
|
156
|
+
checked true
|
157
|
+
|
156
158
|
on_clicked do
|
157
159
|
@game.rotate_left_on_up = true
|
158
160
|
end
|
@@ -235,7 +237,19 @@ class Tetris
|
|
235
237
|
on_key_down do |key_event|
|
236
238
|
case key_event
|
237
239
|
in ext_key: :down
|
238
|
-
|
240
|
+
if OS.windows?
|
241
|
+
# rate limit downs in Windows as they go too fast when key is held
|
242
|
+
@queued_downs ||= 0
|
243
|
+
if @queued_downs < 2
|
244
|
+
@queued_downs += 1
|
245
|
+
Glimmer::LibUI.timer(0.01, repeat: false) do
|
246
|
+
@game.down! if @queued_downs < 2
|
247
|
+
@queued_downs -= 1
|
248
|
+
end
|
249
|
+
end
|
250
|
+
else
|
251
|
+
@game.down!
|
252
|
+
end
|
239
253
|
in key: ' '
|
240
254
|
@game.down!(instant: true)
|
241
255
|
in ext_key: :up
|
@@ -319,8 +333,11 @@ class Tetris
|
|
319
333
|
end
|
320
334
|
|
321
335
|
def start_moving_tetrominos_down
|
322
|
-
|
323
|
-
@
|
336
|
+
unless @tetrominos_start_moving_down
|
337
|
+
@tetrominos_start_moving_down = true
|
338
|
+
Glimmer::LibUI.timer(@game.delay) do
|
339
|
+
@game.down! if !@game.game_over? && !@game.paused?
|
340
|
+
end
|
324
341
|
end
|
325
342
|
end
|
326
343
|
|
@@ -333,6 +350,8 @@ class Tetris
|
|
333
350
|
|
334
351
|
def show_high_scores
|
335
352
|
Glimmer::LibUI.queue_main do
|
353
|
+
game_paused = !!@game.paused
|
354
|
+
@game.paused = true
|
336
355
|
if @game.high_scores.empty?
|
337
356
|
high_scores_string = "No games have been scored yet."
|
338
357
|
else
|
@@ -341,6 +360,7 @@ class Tetris
|
|
341
360
|
end.join("\n")
|
342
361
|
end
|
343
362
|
msg_box('High Scores', high_scores_string)
|
363
|
+
@game.paused = game_paused
|
344
364
|
end
|
345
365
|
end
|
346
366
|
|
data/examples/tic_tac_toe.rb
CHANGED
data/glimmer-dsl-libui.gemspec
CHANGED
Binary file
|
@@ -218,6 +218,7 @@ module Glimmer
|
|
218
218
|
{
|
219
219
|
key: key_to_char(area_key_event.Key, modifiers),
|
220
220
|
key_value: area_key_event.Key,
|
221
|
+
key_code: area_key_event.Key,
|
221
222
|
ext_key: ext_key_to_symbol(area_key_event.ExtKey),
|
222
223
|
ext_key_value: area_key_event.ExtKey,
|
223
224
|
modifier: modifiers_to_symbols(area_key_event.Modifier).first,
|
@@ -43,9 +43,9 @@ module Glimmer
|
|
43
43
|
@column_index ||= @parent_proxy.send(:next_column_index)
|
44
44
|
end
|
45
45
|
|
46
|
-
# actual index within table columns (disregarding
|
46
|
+
# actual index within table columns (disregarding extra fillings that account for DualColumn instances)
|
47
47
|
def index
|
48
|
-
@parent_proxy.columns.
|
48
|
+
@parent_proxy.columns.select {|c| c.is_a?(Column)}.index(self)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|