glimmer-dsl-libui 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
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)
@@ -104,6 +112,55 @@ module Glimmer
104
112
  enum_symbol_to_value(enum_name, enum_symbols(enum_name)[default_index])
105
113
  end
106
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
107
164
  end
108
165
  end
109
166
  end
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.2.0
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-04 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
@@ -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
@@ -242,6 +243,7 @@ files:
242
243
  - examples/meta_example.rb
243
244
  - examples/midi_player.rb
244
245
  - examples/simple_notepad.rb
246
+ - examples/timer.rb
245
247
  - glimmer-dsl-libui.gemspec
246
248
  - lib/glimmer-dsl-libui.rb
247
249
  - lib/glimmer/dsl/libui/control_expression.rb
@@ -296,6 +298,7 @@ files:
296
298
  - lib/glimmer/libui/control_proxy/menu_item_proxy/check_menu_item_proxy.rb
297
299
  - lib/glimmer/libui/control_proxy/menu_item_proxy/preferences_menu_item_proxy.rb
298
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
299
302
  - lib/glimmer/libui/control_proxy/menu_item_proxy/separator_menu_item_proxy.rb
300
303
  - lib/glimmer/libui/control_proxy/menu_proxy.rb
301
304
  - lib/glimmer/libui/control_proxy/message_box.rb
@@ -313,6 +316,7 @@ files:
313
316
  - lib/glimmer/libui/shape.rb
314
317
  - lib/glimmer/libui/shape/arc.rb
315
318
  - lib/glimmer/libui/shape/bezier.rb
319
+ - lib/glimmer/libui/shape/circle.rb
316
320
  - lib/glimmer/libui/shape/figure.rb
317
321
  - lib/glimmer/libui/shape/line.rb
318
322
  - lib/glimmer/libui/shape/rectangle.rb