glimmer-dsl-libui 0.1.4 → 0.1.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.
@@ -0,0 +1,72 @@
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
+ module Glimmer
23
+ module LibUI
24
+ # This is meant to be prepended (not included) because it changes behavior of instance draw method
25
+ # Adds transform property to controls/shapes
26
+ # Automatically applies transform property at the beginning of draw operation and undoes it at the end
27
+ # Stacks up with Parent module (must include Parent beforehand)
28
+ # Expects transformable to implement redraw method
29
+ module Transformable
30
+ def post_initialize_child(child, add_child: true)
31
+ if child.is_a?(MatrixProxy)
32
+ super(child, add_child: false)
33
+ self.transform = child if child.keyword == 'transform'
34
+ else
35
+ super(child, add_child: add_child)
36
+ end
37
+ end
38
+
39
+ # Returns transform or sets it. Expects transformable to implement redraw method (delegating work to area).
40
+ def transform(matrix = nil)
41
+ if matrix.nil?
42
+ @transform
43
+ else
44
+ @transform = matrix
45
+ redraw
46
+ end
47
+ end
48
+ alias transform= transform
49
+ alias set_transform transform
50
+
51
+ # Apply transform matrix to coordinate system
52
+ def apply_transform(area_draw_params)
53
+ ::LibUI.draw_transform(area_draw_params[:context], @transform.libui) unless @transform.nil?
54
+ end
55
+
56
+ # Inverse of apply_transform (applies inverse transformation to undo initial transformation)
57
+ def undo_transform(area_draw_params)
58
+ unless @transform.nil?
59
+ inverse_transform = @transform.clone
60
+ inverse_transform.invert
61
+ ::LibUI.draw_transform(area_draw_params[:context], inverse_transform.libui)
62
+ end
63
+ end
64
+
65
+ def draw(area_draw_params)
66
+ apply_transform(area_draw_params)
67
+ super(area_draw_params)
68
+ undo_transform(area_draw_params)
69
+ end
70
+ end
71
+ end
72
+ 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/area_proxy'
23
24
 
24
25
  module Glimmer
25
26
  module LibUI
@@ -33,6 +34,12 @@ module Glimmer
33
34
  DEFAULT_HAS_MENUBAR = 1
34
35
 
35
36
  def post_initialize_child(child)
37
+ if child.is_a?(AreaProxy)
38
+ vertical_box_parent = ControlProxy.create('vertical_box', self, [])
39
+ child.instance_variable_set(:@parent_proxy, vertical_box_parent)
40
+ vertical_box_parent.post_initialize_child(child)
41
+ child = vertical_box_parent
42
+ end
36
43
  ::LibUI.window_set_child(@libui, child.libui)
37
44
  end
38
45
 
@@ -104,7 +111,7 @@ module Glimmer
104
111
  construction_args[1] = DEFAULT_WIDTH if construction_args.size == 1
105
112
  construction_args[2] = DEFAULT_HEIGHT if construction_args.size == 2
106
113
  construction_args[3] = DEFAULT_HAS_MENUBAR if construction_args.size == 3
107
- construction_args[3] = ControlProxy.boolean_to_integer(construction_args[3]) if construction_args.size == 4 && (construction_args[3].is_a?(TrueClass) || construction_args[3].is_a?(FalseClass))
114
+ construction_args[3] = Glimmer::LibUI.boolean_to_integer(construction_args[3]) if construction_args.size == 4 && (construction_args[3].is_a?(TrueClass) || construction_args[3].is_a?(FalseClass))
108
115
  @libui = ControlProxy.new_control(@keyword, construction_args)
109
116
  @libui.tap do
110
117
  handle_listener('on_closing') do
@@ -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
+ module Glimmer
23
+ module LibUI
24
+ class << self
25
+ def integer_to_boolean(int, allow_nil: true)
26
+ int.nil? ? (allow_nil ? nil : false) : int == 1
27
+ end
28
+
29
+ def boolean_to_integer(bool, allow_nil: true)
30
+ bool.nil? ? (allow_nil ? nil : 0) : (bool ? 1 : 0)
31
+ end
32
+
33
+ def hex_to_rgb(value)
34
+ if value.is_a?(String)
35
+ value = "0x#{value}" if !value.start_with?('0x')
36
+ value = value.to_i(16)
37
+ end
38
+ if value.is_a?(Integer)
39
+ hex_value = value
40
+ value = {
41
+ r: ((hex_value >> 16) & 0xFF),
42
+ g: ((hex_value >> 8) & 0xFF),
43
+ b: (hex_value & 0xFF),
44
+ }
45
+ end
46
+ value
47
+ end
48
+ end
49
+ end
50
+ end
@@ -34,6 +34,7 @@ require 'libui'
34
34
  # require 'ext/glimmer/config'
35
35
  # require 'ext/glimmer'
36
36
  require 'glimmer/dsl/libui/dsl'
37
+ require 'glimmer/libui'
37
38
  Glimmer::Config.loop_max_count = -1
38
39
  Glimmer::Config.excluded_keyword_checkers << lambda do |method_symbol, *args|
39
40
  method = method_symbol.to_s
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.4
4
+ version: 0.1.5
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-09-29 00:00:00.000000000 Z
11
+ date: 2021-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -209,6 +209,7 @@ files:
209
209
  - examples/basic_table_image.rb
210
210
  - examples/basic_table_image_text.rb
211
211
  - examples/basic_table_progress_bar.rb
212
+ - examples/basic_transform.rb
212
213
  - examples/basic_window.rb
213
214
  - examples/basic_window2.rb
214
215
  - examples/color_button.rb
@@ -222,6 +223,7 @@ files:
222
223
  - examples/form.rb
223
224
  - examples/form_table.rb
224
225
  - examples/grid.rb
226
+ - examples/histogram.rb
225
227
  - examples/meta_example.rb
226
228
  - examples/midi_player.rb
227
229
  - examples/simple_notepad.rb
@@ -237,6 +239,7 @@ files:
237
239
  - lib/glimmer/dsl/libui/shape_expression.rb
238
240
  - lib/glimmer/dsl/libui/tab_item_expression.rb
239
241
  - lib/glimmer/fiddle_consumer.rb
242
+ - lib/glimmer/libui.rb
240
243
  - lib/glimmer/libui/about_menu_item_proxy.rb
241
244
  - lib/glimmer/libui/arc.rb
242
245
  - lib/glimmer/libui/area_proxy.rb
@@ -270,10 +273,12 @@ files:
270
273
  - lib/glimmer/libui/image_text_column_proxy.rb
271
274
  - lib/glimmer/libui/label_proxy.rb
272
275
  - lib/glimmer/libui/line.rb
276
+ - lib/glimmer/libui/matrix_proxy.rb
273
277
  - lib/glimmer/libui/menu_item_proxy.rb
274
278
  - lib/glimmer/libui/menu_proxy.rb
275
279
  - lib/glimmer/libui/multiline_entry_proxy.rb
276
280
  - lib/glimmer/libui/non_wrapping_multiline_entry_proxy.rb
281
+ - lib/glimmer/libui/parent.rb
277
282
  - lib/glimmer/libui/path_proxy.rb
278
283
  - lib/glimmer/libui/preferences_menu_item_proxy.rb
279
284
  - lib/glimmer/libui/progress_bar_column_proxy.rb
@@ -287,6 +292,7 @@ files:
287
292
  - lib/glimmer/libui/table_proxy.rb
288
293
  - lib/glimmer/libui/text_column_proxy.rb
289
294
  - lib/glimmer/libui/time_picker_proxy.rb
295
+ - lib/glimmer/libui/transformable.rb
290
296
  - lib/glimmer/libui/vertical_box_proxy.rb
291
297
  - lib/glimmer/libui/window_proxy.rb
292
298
  homepage: http://github.com/AndyObtiva/glimmer-dsl-libui