glimmer-dsl-libui 0.1.9 → 0.2.1

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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +34 -0
  3. data/README.md +624 -29
  4. data/VERSION +1 -1
  5. data/examples/area_gallery.rb +7 -1
  6. data/examples/area_gallery2.rb +14 -4
  7. data/examples/area_gallery3.rb +8 -2
  8. data/examples/area_gallery4.rb +15 -5
  9. data/examples/color_the_circles.rb +223 -0
  10. data/examples/control_gallery.rb +1 -1
  11. data/examples/form_table.rb +20 -0
  12. data/examples/grid.rb +38 -2
  13. data/examples/login.rb +45 -0
  14. data/examples/midi_player.rb +1 -1
  15. data/examples/timer.rb +135 -0
  16. data/glimmer-dsl-libui.gemspec +0 -0
  17. data/lib/glimmer/libui/control_proxy/area_proxy/scrolling_area_proxy.rb +40 -0
  18. data/lib/glimmer/libui/control_proxy/area_proxy.rb +9 -5
  19. data/lib/glimmer/libui/control_proxy/entry_proxy/password_entry_proxy.rb +36 -0
  20. data/lib/glimmer/libui/control_proxy/entry_proxy/search_entry_proxy.rb +36 -0
  21. data/lib/glimmer/libui/control_proxy/entry_proxy.rb +39 -0
  22. data/lib/glimmer/libui/control_proxy/grid_proxy.rb +12 -1
  23. data/lib/glimmer/libui/control_proxy/menu_item_proxy/radio_menu_item_proxy.rb +69 -0
  24. data/lib/glimmer/libui/control_proxy/menu_proxy.rb +3 -0
  25. data/lib/glimmer/libui/control_proxy/path_proxy.rb +3 -30
  26. data/lib/glimmer/libui/control_proxy.rb +8 -1
  27. data/lib/glimmer/libui/shape/arc.rb +6 -3
  28. data/lib/glimmer/libui/shape/circle.rb +50 -0
  29. data/lib/glimmer/libui/shape/rectangle.rb +4 -0
  30. data/lib/glimmer/libui/shape/square.rb +4 -0
  31. data/lib/glimmer/libui.rb +76 -2
  32. data/sounds/AlanWalker-Faded.mid +0 -0
  33. data/sounds/AlanWalker-SingMeToSleep.mid +0 -0
  34. data/sounds/CalvinHarris-Blame.mid +0 -0
  35. data/sounds/CalvinHarris-MyWay.mid +0 -0
  36. data/sounds/deadmau5-2448.mid +0 -0
  37. data/sounds/deadmau5-SoThereIWas.mid +0 -0
  38. metadata +19 -4
@@ -34,10 +34,6 @@ module Glimmer
34
34
  class << self
35
35
  # this attribute is only populated during on_draw call
36
36
  attr_accessor :current_area_draw_params
37
-
38
- def ext_key_symbols
39
- @ext_key_symbols ||= ::LibUI.constants.select { |c| c.to_s.start_with?('ExtKey') }.map { |c| c.to_s.underscore.sub('ext_key_', '') }
40
- end
41
37
  end
42
38
 
43
39
  LISTENERS = ['on_draw', 'on_mouse_event', 'on_mouse_move', 'on_mouse_down', 'on_mouse_up', 'on_mouse_drag_start', 'on_mouse_drag', 'on_mouse_drop', 'on_mouse_crossed', 'on_mouse_enter', 'on_mouse_exit', 'on_drag_broken', 'on_key_event', 'on_key_down', 'on_key_up']
@@ -59,6 +55,10 @@ module Glimmer
59
55
 
60
56
  attr_reader :area_handler
61
57
 
58
+ def libui_api_keyword
59
+ 'area'
60
+ end
61
+
62
62
  def post_add_content
63
63
  super
64
64
  install_listeners
@@ -155,7 +155,9 @@ module Glimmer
155
155
  def area_key_event_hash(area_key_event)
156
156
  {
157
157
  key: key_to_char(area_key_event.Key),
158
+ key_value: area_key_event.Key,
158
159
  ext_key: ext_key_to_symbol(area_key_event.ExtKey),
160
+ ext_key_value: area_key_event.ExtKey,
159
161
  modifier: modifiers_to_symbols(area_key_event.Modifier).first,
160
162
  modifiers: modifiers_to_symbols(area_key_event.Modifiers),
161
163
  up: Glimmer::LibUI.integer_to_boolean(area_key_event.Up),
@@ -167,7 +169,7 @@ module Glimmer
167
169
  end
168
170
 
169
171
  def ext_key_to_symbol(ext_key_value)
170
- AreaProxy.ext_key_symbols[ext_key_value - 1].to_s.to_sym if ext_key_value > 0
172
+ Glimmer::LibUI.enum_symbols(:ext_key)[ext_key_value - 1].to_s.to_sym if ext_key_value > 0
171
173
  end
172
174
 
173
175
  def modifiers_to_symbols(modifiers_value)
@@ -195,3 +197,5 @@ module Glimmer
195
197
  end
196
198
  end
197
199
  end
200
+
201
+ Dir[File.expand_path("./#{File.basename(__FILE__, '.rb')}/*.rb", __dir__)].each {|f| require f}
@@ -0,0 +1,36 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/libui/control_proxy/entry_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ class ControlProxy
27
+ class EntryProxy < ControlProxy
28
+ # Proxy for LibUI password entry objects
29
+ #
30
+ # Follows the Proxy Design Pattern
31
+ class PasswordEntryProxy < EntryProxy
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/libui/control_proxy/entry_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ class ControlProxy
27
+ class EntryProxy < ControlProxy
28
+ # Proxy for LibUI search entry objects
29
+ #
30
+ # Follows the Proxy Design Pattern
31
+ class SearchEntryProxy < EntryProxy
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,39 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/libui/control_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ class ControlProxy
27
+ # Proxy for LibUI entry objects
28
+ #
29
+ # Follows the Proxy Design Pattern
30
+ class EntryProxy < ControlProxy
31
+ def libui_api_keyword
32
+ 'entry'
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ Dir[File.expand_path("./#{File.basename(__FILE__, '.rb')}/*.rb", __dir__)].each {|f| require f}
@@ -36,7 +36,18 @@ module Glimmer
36
36
  child.halign = 0 if child.halign.nil?
37
37
  child.vexpand = false if child.vexpand.nil?
38
38
  child.valign = 0 if child.valign.nil?
39
- ::LibUI.grid_append(@libui, child.libui, child.left, child.top, child.xspan, child.yspan, Glimmer::LibUI.boolean_to_integer(child.hexpand), child.halign, Glimmer::LibUI.boolean_to_integer(child.vexpand), child.valign)
39
+ ::LibUI.grid_append(
40
+ @libui,
41
+ child.libui,
42
+ child.left,
43
+ child.top,
44
+ child.xspan,
45
+ child.yspan,
46
+ Glimmer::LibUI.boolean_to_integer(child.hexpand),
47
+ Glimmer::LibUI.enum_symbol_to_value(:align, child.halign),
48
+ Glimmer::LibUI.boolean_to_integer(child.vexpand),
49
+ Glimmer::LibUI.enum_symbol_to_value(:align, child.valign)
50
+ )
40
51
  children << child
41
52
  end
42
53
 
@@ -0,0 +1,69 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/libui/control_proxy/menu_item_proxy'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ class ControlProxy
27
+ class MenuItemProxy < ControlProxy
28
+ # Proxy for LibUI radio menu item object
29
+ #
30
+ # Follows the Proxy Design Pattern
31
+ class RadioMenuItemProxy < MenuItemProxy
32
+ def checked(value = nil)
33
+ if !value.nil?
34
+ if Glimmer::LibUI.integer_to_boolean(value) != checked?
35
+ super
36
+ if Glimmer::LibUI.integer_to_boolean(value)
37
+ (@parent_proxy.children - [self]).select {|c| c.is_a?(MenuItemProxy)}.each do |menu_item|
38
+ menu_item.checked = false
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ alias checked? checked
45
+ alias set_checked checked
46
+ alias checked= checked
47
+
48
+ def handle_listener(listener_name, &listener)
49
+ if listener_name.to_s == 'on_clicked'
50
+ radio_listener = Proc.new do
51
+ self.checked = true if !checked?
52
+ listener.call(self)
53
+ end
54
+ super(listener_name, &radio_listener)
55
+ else
56
+ super
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def build_control
63
+ @libui = @parent_proxy.append_check_item(*@args)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -20,6 +20,7 @@
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
22
  require 'glimmer/libui/control_proxy'
23
+ require 'glimmer/libui/parent'
23
24
 
24
25
  module Glimmer
25
26
  module LibUI
@@ -28,6 +29,8 @@ module Glimmer
28
29
  #
29
30
  # Follows the Proxy Design Pattern
30
31
  class MenuProxy < ControlProxy
32
+ include Parent
33
+
31
34
  DEFAULT_TEXT = ''
32
35
 
33
36
  private
@@ -128,25 +128,11 @@ module Glimmer
128
128
  end
129
129
 
130
130
  def draw_line_cap
131
- case @stroke && @stroke[:cap].to_s
132
- when 'round'
133
- 1
134
- when 'square'
135
- 2
136
- else # 'flat'
137
- 0
138
- end
131
+ Glimmer::LibUI.enum_symbol_to_value(:draw_line_cap, @stroke && @stroke[:cap])
139
132
  end
140
133
 
141
134
  def draw_line_join
142
- case @stroke && @stroke[:join].to_s
143
- when 'round'
144
- 1
145
- when 'bevel'
146
- 2
147
- else # 'miter'
148
- 0
149
- end
135
+ Glimmer::LibUI.enum_symbol_to_value(:draw_line_join, @stroke && @stroke[:join])
150
136
  end
151
137
 
152
138
  def destroy
@@ -165,20 +151,7 @@ module Glimmer
165
151
  end
166
152
 
167
153
  def init_draw_brush(draw_brush, draw_brush_args)
168
- case draw_brush_args[:type]
169
- when Integer
170
- draw_brush.Type = draw_brush_args[:type]
171
- when :solid, 'solid'
172
- draw_brush.Type = 0
173
- when :linear_gradient, 'linear_gradient'
174
- draw_brush.Type = 1
175
- when :radial_gradient, 'radial_gradient'
176
- draw_brush.Type = 2
177
- when :image, 'image'
178
- draw_brush.Type = 3
179
- else
180
- draw_brush.Type = 0
181
- end
154
+ draw_brush.Type = Glimmer::LibUI.enum_symbol_to_value(:draw_brush_type, draw_brush_args[:type])
182
155
  draw_brush.R = (draw_brush_args[:r] || draw_brush_args[:red]).to_f / 255.0
183
156
  draw_brush.G = (draw_brush_args[:g] || draw_brush_args[:green]).to_f / 255.0
184
157
  draw_brush.B = (draw_brush_args[:b] || draw_brush_args[:blue]).to_f / 255.0
@@ -223,7 +223,13 @@ module Glimmer
223
223
  elsif ::LibUI.respond_to?("#{libui_api_keyword}_set_#{method_name.to_s.sub(/=$/, '')}") && !args.empty?
224
224
  property = method_name.to_s.sub(/=$/, '')
225
225
  args[0] = Glimmer::LibUI.boolean_to_integer(args.first) if BOOLEAN_PROPERTIES.include?(property) && (args.first.is_a?(TrueClass) || args.first.is_a?(FalseClass))
226
- ::LibUI.send("#{libui_api_keyword}_set_#{property}", @libui, *args)
226
+ if property.to_s == 'checked'
227
+ current_value = Glimmer::LibUI.integer_to_boolean(::LibUI.send("#{libui_api_keyword}_checked", @libui))
228
+ new_value = Glimmer::LibUI.integer_to_boolean(args[0])
229
+ ::LibUI.send("#{libui_api_keyword}_set_#{property}", @libui, *args) if new_value != current_value
230
+ else
231
+ ::LibUI.send("#{libui_api_keyword}_set_#{property}", @libui, *args)
232
+ end
227
233
  elsif ::LibUI.respond_to?("#{libui_api_keyword}_#{method_name}") && !args.empty?
228
234
  ::LibUI.send("#{libui_api_keyword}_#{method_name}", @libui, *args)
229
235
  elsif ::LibUI.respond_to?("control_#{method_name.to_s.sub(/\?$/, '')}") && args.empty?
@@ -280,6 +286,7 @@ module Glimmer
280
286
  if value.nil?
281
287
  @enabled
282
288
  elsif value != @enabled
289
+ @enabled = value == 1 || value
283
290
  if value == 1 || value
284
291
  send_to_libui('enable')
285
292
  else
@@ -29,11 +29,14 @@ module Glimmer
29
29
  parameter_defaults 0, 0, 0, 0, 360, false
30
30
 
31
31
  def draw(area_draw_params)
32
- @args[5] ||= Glimmer::LibUI.boolean_to_integer(@args[5], allow_nil: false)
32
+ arc_args = @args.dup
33
+ arc_args[3] = Glimmer::LibUI.degrees_to_radians(arc_args[3])
34
+ arc_args[4] = Glimmer::LibUI.degrees_to_radians(arc_args[4])
35
+ arc_args[5] = Glimmer::LibUI.boolean_to_integer(arc_args[5], allow_nil: false)
33
36
  if parent.is_a?(Figure) && parent.x.nil? && parent.y.nil?
34
- ::LibUI.draw_path_new_figure_with_arc(path_proxy.libui, *@args)
37
+ ::LibUI.draw_path_new_figure_with_arc(path_proxy.libui, *arc_args)
35
38
  else
36
- ::LibUI.draw_path_arc_to(path_proxy.libui, *@args)
39
+ ::LibUI.draw_path_arc_to(path_proxy.libui, *arc_args)
37
40
  end
38
41
  super
39
42
  end
@@ -0,0 +1,50 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/libui/shape'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ class Shape
27
+ class Circle < Shape
28
+ parameters :x_center, :y_center, :radius
29
+ parameter_defaults 0, 0, 0
30
+
31
+ def draw(area_draw_params)
32
+ arc_args = @args.dup
33
+ arc_args[3] = 0
34
+ arc_args[4] = Math::PI * 2.0
35
+ arc_args[5] = 0
36
+ if parent.is_a?(Figure) && parent.x.nil? && parent.y.nil?
37
+ ::LibUI.draw_path_new_figure_with_arc(path_proxy.libui, *arc_args)
38
+ else
39
+ ::LibUI.draw_path_arc_to(path_proxy.libui, *arc_args)
40
+ end
41
+ super
42
+ end
43
+
44
+ def include?(x, y)
45
+ (x - x_center)**2 + (y - y_center)**2 < radius**2
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -32,6 +32,10 @@ module Glimmer
32
32
  ::LibUI.draw_path_add_rectangle(path_proxy.libui, *@args)
33
33
  super
34
34
  end
35
+
36
+ def include?(x, y)
37
+ x.between?(self.x, self.x + width) && y.between?(self.y, self.y + height)
38
+ end
35
39
  end
36
40
  end
37
41
  end
@@ -32,6 +32,10 @@ module Glimmer
32
32
  ::LibUI.draw_path_add_rectangle(path_proxy.libui, *@args, length)
33
33
  super
34
34
  end
35
+
36
+ def include?(x, y)
37
+ x.between?(self.x, self.x + length) && y.between?(self.y, self.y + length)
38
+ end
35
39
  end
36
40
  end
37
41
  end
data/lib/glimmer/libui.rb CHANGED
@@ -19,15 +19,23 @@
19
19
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
+ require 'glimmer/fiddle_consumer'
23
+
22
24
  module Glimmer
23
25
  module LibUI
24
26
  class << self
27
+ include Glimmer::FiddleConsumer
28
+
25
29
  def integer_to_boolean(int, allow_nil: true)
26
- int.nil? ? (allow_nil ? nil : false) : int == 1
30
+ int.nil? ? (allow_nil ? nil : false) : ((int.is_a?(TrueClass) || int.is_a?(FalseClass)) ? int : int == 1)
27
31
  end
28
32
 
29
33
  def boolean_to_integer(bool, allow_nil: true)
30
- bool.nil? ? (allow_nil ? nil : 0) : (bool ? 1 : 0)
34
+ bool.nil? ? (allow_nil ? nil : 0) : (bool.is_a?(Integer) ? bool : (bool == true ? 1 : 0))
35
+ end
36
+
37
+ def degrees_to_radians(degrees)
38
+ ((Math::PI * 2.0) / 360.00) * degrees.to_f
31
39
  end
32
40
 
33
41
  def interpret_color(value)
@@ -87,6 +95,72 @@ module Glimmer
87
95
  end
88
96
  value
89
97
  end
98
+
99
+ # Returns ruby underscored symbols for enum values starting with enum name (camelcase, e.g. 'ext_key')
100
+ def enum_symbols(enum_name)
101
+ enum_name = enum_name.to_s.underscore.to_sym
102
+ @enum_symbols ||= {}
103
+ @enum_symbols[enum_name] ||= ::LibUI.constants.select { |c| c.to_s.start_with?(enum_name.to_s.camelcase(:upper)) }.map { |c| c.to_s.underscore.sub("#{enum_name}_", '').to_sym }
104
+ end
105
+
106
+ def enum_symbol_to_value(enum_name, enum_symbol, default_index: 0)
107
+ if enum_symbol.is_a?(Integer)
108
+ enum_symbol
109
+ elsif enum_symbols(enum_name).include?(enum_symbol.to_s.to_sym)
110
+ ::LibUI.const_get("#{enum_name}_#{enum_symbol}".camelcase(:upper))
111
+ else
112
+ enum_symbol_to_value(enum_name, enum_symbols(enum_name)[default_index])
113
+ end
114
+ end
115
+
116
+ def x11_colors
117
+ Color::RGB.constants.reject {|c| c.to_s.upcase == c.to_s}.map(&:to_s).map(&:underscore).map(&:to_sym)
118
+ end
119
+
120
+ # Queues block to execute at the nearest opportunity possible on the main GUI event loop
121
+ def queue_main(&block)
122
+ closure = fiddle_closure_block_caller(4, [0]) do
123
+ result = boolean_to_integer(block.call)
124
+ result = 1 if result.nil?
125
+ result
126
+ end
127
+ ::LibUI.queue_main(closure)
128
+ closure
129
+ end
130
+
131
+ # Calls block on the main GUI event loop after time_in_seconds delay, repeating indefinitely by default
132
+ # If `repeat:` keyword arg is passed with an Integer value, it repeats for that number of times
133
+ # If `repeat:` keyword arg is passed with false or 0, then the block is only called onces
134
+ # If block returns false at any point, the timer is stopped from further repetitions regardless of `repeat:` keyword arg value
135
+ # If block returns true at any point, the timer continues for another repetition regardless of `repeat:` keyword arg value
136
+ def timer(time_in_seconds = 0.1, repeat: true, &block)
137
+ closure = fiddle_closure_block_caller(4, [0]) do
138
+ result = boolean_to_integer(block.call)
139
+ repeat -= 1 if repeat.is_a?(Integer)
140
+ if result.nil?
141
+ if (repeat == true || (repeat.is_a?(Integer) && repeat > 0))
142
+ result = 1
143
+ else
144
+ result = 0
145
+ end
146
+ end
147
+ result
148
+ end
149
+ ::LibUI.timer(time_in_seconds * 1000.0, closure)
150
+ closure
151
+ end
152
+
153
+ def respond_to?(method_name, *args)
154
+ super || ::LibUI.respond_to?(method_name, *args)
155
+ end
156
+
157
+ def method_missing(method_name, *args, &block)
158
+ if ::LibUI.respond_to?(method_name, true)
159
+ ::LibUI.send(method_name, *args, &block)
160
+ else
161
+ super
162
+ end
163
+ end
90
164
  end
91
165
  end
92
166
  end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-libui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-03 00:00:00.000000000 Z
11
+ date: 2021-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.2.0
19
+ version: 2.2.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.2.0
26
+ version: 2.2.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: os
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -227,6 +227,7 @@ files:
227
227
  - examples/basic_window.rb
228
228
  - examples/basic_window2.rb
229
229
  - examples/color_button.rb
230
+ - examples/color_the_circles.rb
230
231
  - examples/control_gallery.rb
231
232
  - examples/date_time_picker.rb
232
233
  - examples/dynamic_area.rb
@@ -238,9 +239,11 @@ files:
238
239
  - examples/form_table.rb
239
240
  - examples/grid.rb
240
241
  - examples/histogram.rb
242
+ - examples/login.rb
241
243
  - examples/meta_example.rb
242
244
  - examples/midi_player.rb
243
245
  - examples/simple_notepad.rb
246
+ - examples/timer.rb
244
247
  - glimmer-dsl-libui.gemspec
245
248
  - lib/glimmer-dsl-libui.rb
246
249
  - lib/glimmer/dsl/libui/control_expression.rb
@@ -256,6 +259,7 @@ files:
256
259
  - lib/glimmer/libui.rb
257
260
  - lib/glimmer/libui/control_proxy.rb
258
261
  - lib/glimmer/libui/control_proxy/area_proxy.rb
262
+ - lib/glimmer/libui/control_proxy/area_proxy/scrolling_area_proxy.rb
259
263
  - lib/glimmer/libui/control_proxy/box.rb
260
264
  - lib/glimmer/libui/control_proxy/box/horizontal_box_proxy.rb
261
265
  - lib/glimmer/libui/control_proxy/box/vertical_box_proxy.rb
@@ -278,6 +282,9 @@ files:
278
282
  - lib/glimmer/libui/control_proxy/editable_column.rb
279
283
  - lib/glimmer/libui/control_proxy/editable_combobox_proxy.rb
280
284
  - lib/glimmer/libui/control_proxy/enableable_column.rb
285
+ - lib/glimmer/libui/control_proxy/entry_proxy.rb
286
+ - lib/glimmer/libui/control_proxy/entry_proxy/password_entry_proxy.rb
287
+ - lib/glimmer/libui/control_proxy/entry_proxy/search_entry_proxy.rb
281
288
  - lib/glimmer/libui/control_proxy/font_button_proxy.rb
282
289
  - lib/glimmer/libui/control_proxy/form_proxy.rb
283
290
  - lib/glimmer/libui/control_proxy/grid_proxy.rb
@@ -291,6 +298,7 @@ files:
291
298
  - lib/glimmer/libui/control_proxy/menu_item_proxy/check_menu_item_proxy.rb
292
299
  - lib/glimmer/libui/control_proxy/menu_item_proxy/preferences_menu_item_proxy.rb
293
300
  - lib/glimmer/libui/control_proxy/menu_item_proxy/quit_menu_item_proxy.rb
301
+ - lib/glimmer/libui/control_proxy/menu_item_proxy/radio_menu_item_proxy.rb
294
302
  - lib/glimmer/libui/control_proxy/menu_item_proxy/separator_menu_item_proxy.rb
295
303
  - lib/glimmer/libui/control_proxy/menu_proxy.rb
296
304
  - lib/glimmer/libui/control_proxy/message_box.rb
@@ -308,10 +316,17 @@ files:
308
316
  - lib/glimmer/libui/shape.rb
309
317
  - lib/glimmer/libui/shape/arc.rb
310
318
  - lib/glimmer/libui/shape/bezier.rb
319
+ - lib/glimmer/libui/shape/circle.rb
311
320
  - lib/glimmer/libui/shape/figure.rb
312
321
  - lib/glimmer/libui/shape/line.rb
313
322
  - lib/glimmer/libui/shape/rectangle.rb
314
323
  - lib/glimmer/libui/shape/square.rb
324
+ - sounds/AlanWalker-Faded.mid
325
+ - sounds/AlanWalker-SingMeToSleep.mid
326
+ - sounds/CalvinHarris-Blame.mid
327
+ - sounds/CalvinHarris-MyWay.mid
328
+ - sounds/deadmau5-2448.mid
329
+ - sounds/deadmau5-SoThereIWas.mid
315
330
  homepage: http://github.com/AndyObtiva/glimmer-dsl-libui
316
331
  licenses:
317
332
  - MIT