glimmer-dsl-libui 0.1.5 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -0
  3. data/README.md +352 -67
  4. data/VERSION +1 -1
  5. data/examples/area_gallery.rb +50 -2
  6. data/examples/area_gallery2.rb +50 -2
  7. data/examples/area_gallery3.rb +50 -2
  8. data/examples/area_gallery4.rb +50 -2
  9. data/examples/basic_button.rb +2 -2
  10. data/examples/basic_entry.rb +2 -2
  11. data/examples/basic_transform.rb +1 -1
  12. data/examples/control_gallery.rb +3 -3
  13. data/examples/form.rb +2 -2
  14. data/examples/histogram.rb +18 -19
  15. data/examples/meta_example.rb +71 -20
  16. data/examples/midi_player.rb +8 -10
  17. data/glimmer-dsl-libui.gemspec +0 -0
  18. data/lib/glimmer/dsl/libui/control_expression.rb +0 -2
  19. data/lib/glimmer/dsl/libui/file_expression.rb +5 -1
  20. data/lib/glimmer/dsl/libui/shape_expression.rb +2 -4
  21. data/lib/glimmer/dsl/libui/tab_item_expression.rb +2 -2
  22. data/lib/glimmer/libui/control_proxy/area_proxy.rb +197 -0
  23. data/lib/glimmer/libui/{menu_item_proxy.rb → control_proxy/box/horizontal_box_proxy.rb} +9 -12
  24. data/lib/glimmer/libui/{horizontal_box_proxy.rb → control_proxy/box/vertical_box_proxy.rb} +10 -6
  25. data/lib/glimmer/libui/{box.rb → control_proxy/box.rb} +31 -27
  26. data/lib/glimmer/libui/{button_proxy.rb → control_proxy/button_proxy.rb} +14 -12
  27. data/lib/glimmer/libui/{checkbox_proxy.rb → control_proxy/checkbox_proxy.rb} +14 -12
  28. data/lib/glimmer/libui/control_proxy/color_button_proxy.rb +118 -0
  29. data/lib/glimmer/libui/control_proxy/column/button_column_proxy.rb +76 -0
  30. data/lib/glimmer/libui/control_proxy/column/checkbox_column_proxy.rb +46 -0
  31. data/lib/glimmer/libui/control_proxy/column/checkbox_text_column_proxy.rb +80 -0
  32. data/lib/glimmer/libui/{radio_buttons_proxy.rb → control_proxy/column/image_column_proxy.rb} +14 -13
  33. data/lib/glimmer/libui/control_proxy/column/image_text_column_proxy.rb +48 -0
  34. data/lib/glimmer/libui/control_proxy/column/progress_bar_column_proxy.rb +44 -0
  35. data/lib/glimmer/libui/{checkbox_column_proxy.rb → control_proxy/column/text_column_proxy.rb} +17 -13
  36. data/lib/glimmer/libui/control_proxy/column.rb +55 -0
  37. data/lib/glimmer/libui/control_proxy/combobox_proxy.rb +45 -0
  38. data/lib/glimmer/libui/control_proxy/date_time_picker_proxy/date_picker_proxy.rb +43 -0
  39. data/lib/glimmer/libui/control_proxy/date_time_picker_proxy/time_picker_proxy.rb +43 -0
  40. data/lib/glimmer/libui/control_proxy/date_time_picker_proxy.rb +72 -0
  41. data/lib/glimmer/libui/control_proxy/dual_column.rb +40 -0
  42. data/lib/glimmer/libui/control_proxy/editable_column.rb +46 -0
  43. data/lib/glimmer/libui/control_proxy/editable_combobox_proxy.rb +45 -0
  44. data/lib/glimmer/libui/{dual_column.rb → control_proxy/enableable_column.rb} +18 -10
  45. data/lib/glimmer/libui/control_proxy/font_button_proxy.rb +70 -0
  46. data/lib/glimmer/libui/{form_proxy.rb → control_proxy/form_proxy.rb} +26 -24
  47. data/lib/glimmer/libui/{grid_proxy.rb → control_proxy/grid_proxy.rb} +29 -27
  48. data/lib/glimmer/libui/{group_proxy.rb → control_proxy/group_proxy.rb} +24 -22
  49. data/lib/glimmer/libui/{image_part_proxy.rb → control_proxy/image_part_proxy.rb} +20 -18
  50. data/lib/glimmer/libui/{image_proxy.rb → control_proxy/image_proxy.rb} +32 -30
  51. data/lib/glimmer/libui/{combobox_proxy.rb → control_proxy/label_proxy.rb} +13 -13
  52. data/lib/glimmer/libui/control_proxy/matrix_proxy.rb +147 -0
  53. data/lib/glimmer/libui/{editable_column.rb → control_proxy/menu_item_proxy/about_menu_item_proxy.rb} +13 -16
  54. data/lib/glimmer/libui/{enableable_column.rb → control_proxy/menu_item_proxy/check_menu_item_proxy.rb} +13 -16
  55. data/lib/glimmer/libui/{date_picker_proxy.rb → control_proxy/menu_item_proxy/preferences_menu_item_proxy.rb} +10 -10
  56. data/lib/glimmer/libui/{quit_menu_item_proxy.rb → control_proxy/menu_item_proxy/quit_menu_item_proxy.rb} +33 -29
  57. data/lib/glimmer/libui/control_proxy/menu_item_proxy/separator_menu_item_proxy.rb +41 -0
  58. data/lib/glimmer/libui/control_proxy/menu_item_proxy.rb +45 -0
  59. data/lib/glimmer/libui/{editable_combobox_proxy.rb → control_proxy/menu_proxy.rb} +13 -13
  60. data/lib/glimmer/libui/{vertical_box_proxy.rb → control_proxy/message_box/msg_box_error_proxy.rb} +9 -6
  61. data/lib/glimmer/libui/{multiline_entry_proxy.rb → control_proxy/message_box/msg_box_proxy.rb} +8 -6
  62. data/lib/glimmer/libui/{time_picker_proxy.rb → control_proxy/message_box.rb} +9 -10
  63. data/lib/glimmer/libui/{rectangle.rb → control_proxy/multiline_entry_proxy/non_wrapping_multiline_entry_proxy.rb} +6 -8
  64. data/lib/glimmer/libui/{progress_bar_column_proxy.rb → control_proxy/multiline_entry_proxy.rb} +10 -11
  65. data/lib/glimmer/libui/control_proxy/path_proxy.rb +190 -0
  66. data/lib/glimmer/libui/control_proxy/radio_buttons_proxy.rb +45 -0
  67. data/lib/glimmer/libui/{button_column_proxy.rb → control_proxy/tab_item_proxy.rb} +37 -40
  68. data/lib/glimmer/libui/control_proxy/table_proxy.rb +182 -0
  69. data/lib/glimmer/libui/{transformable.rb → control_proxy/transformable.rb} +3 -1
  70. data/lib/glimmer/libui/control_proxy/window_proxy.rb +128 -0
  71. data/lib/glimmer/libui/control_proxy.rb +68 -9
  72. data/lib/glimmer/libui/{arc.rb → shape/arc.rb} +13 -11
  73. data/lib/glimmer/libui/shape/bezier.rb +38 -0
  74. data/lib/glimmer/libui/{figure.rb → shape/figure.rb} +23 -21
  75. data/lib/glimmer/libui/{line.rb → shape/line.rb} +9 -7
  76. data/lib/glimmer/libui/{bezier.rb → shape/rectangle.rb} +9 -7
  77. data/lib/glimmer/libui/{square.rb → shape/square.rb} +9 -7
  78. data/lib/glimmer/libui/shape.rb +8 -6
  79. data/lib/glimmer/libui.rb +43 -1
  80. data/lib/glimmer-dsl-libui.rb +2 -0
  81. metadata +74 -57
  82. data/lib/glimmer/libui/about_menu_item_proxy.rb +0 -37
  83. data/lib/glimmer/libui/area_proxy.rb +0 -115
  84. data/lib/glimmer/libui/check_menu_item_proxy.rb +0 -37
  85. data/lib/glimmer/libui/checkbox_text_column_proxy.rb +0 -76
  86. data/lib/glimmer/libui/color_button_proxy.rb +0 -116
  87. data/lib/glimmer/libui/column.rb +0 -51
  88. data/lib/glimmer/libui/date_time_picker_proxy.rb +0 -68
  89. data/lib/glimmer/libui/font_button_proxy.rb +0 -68
  90. data/lib/glimmer/libui/image_column_proxy.rb +0 -40
  91. data/lib/glimmer/libui/image_text_column_proxy.rb +0 -44
  92. data/lib/glimmer/libui/label_proxy.rb +0 -41
  93. data/lib/glimmer/libui/matrix_proxy.rb +0 -145
  94. data/lib/glimmer/libui/menu_proxy.rb +0 -41
  95. data/lib/glimmer/libui/non_wrapping_multiline_entry_proxy.rb +0 -32
  96. data/lib/glimmer/libui/path_proxy.rb +0 -166
  97. data/lib/glimmer/libui/preferences_menu_item_proxy.rb +0 -37
  98. data/lib/glimmer/libui/separator_menu_item_proxy.rb +0 -37
  99. data/lib/glimmer/libui/tab_item_proxy.rb +0 -67
  100. data/lib/glimmer/libui/table_proxy.rb +0 -180
  101. data/lib/glimmer/libui/text_column_proxy.rb +0 -42
  102. data/lib/glimmer/libui/window_proxy.rb +0 -126
@@ -20,14 +20,14 @@
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
22
  require 'glimmer/dsl/static_expression'
23
- require 'glimmer/libui/tab_item_proxy'
23
+ require 'glimmer/libui/control_proxy/tab_item_proxy'
24
24
 
25
25
  module Glimmer
26
26
  module DSL
27
27
  module Libui
28
28
  class TabItemExpression < StaticExpression
29
29
  def interpret(parent, keyword, *args, &block)
30
- Glimmer::LibUI::TabItemProxy.create(keyword, parent, args, &block)
30
+ Glimmer::LibUI::ControlProxy::TabItemProxy.create(keyword, parent, args, &block)
31
31
  end
32
32
  end
33
33
  end
@@ -0,0 +1,197 @@
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
+ require 'glimmer/fiddle_consumer'
24
+ require 'glimmer/libui/parent'
25
+ require 'glimmer/libui/control_proxy/transformable'
26
+
27
+ module Glimmer
28
+ module LibUI
29
+ class ControlProxy
30
+ # Proxy for LibUI area objects
31
+ #
32
+ # Follows the Proxy Design Pattern
33
+ class AreaProxy < ControlProxy
34
+ class << self
35
+ # this attribute is only populated during on_draw call
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
+ end
42
+
43
+ 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']
44
+ LISTENER_ALIASES = {
45
+ on_drawn: 'on_draw',
46
+ on_mouse_moved: 'on_mouse_move',
47
+ on_mouse_drag_started: 'on_mouse_drag_start',
48
+ on_mouse_dragged: 'on_mouse_drag',
49
+ on_mouse_dropped: 'on_mouse_drop',
50
+ on_mouse_cross: 'on_mouse_crossed',
51
+ on_mouse_entered: 'on_mouse_enter',
52
+ on_mouse_exited: 'on_mouse_exit',
53
+ on_drag_break: 'on_drag_broken',
54
+ }
55
+
56
+ include Glimmer::FiddleConsumer
57
+ include Parent
58
+ prepend Transformable
59
+
60
+ attr_reader :area_handler
61
+
62
+ def post_add_content
63
+ super
64
+ install_listeners
65
+ end
66
+
67
+ def draw(area_draw_params)
68
+ children.dup.each {|child| child.draw(area_draw_params)}
69
+ on_draw.each {|listener| listener.call(area_draw_params)}
70
+ end
71
+
72
+ def redraw
73
+ queue_redraw_all
74
+ end
75
+
76
+ private
77
+
78
+ def build_control
79
+ @area_handler = ::LibUI::FFI::AreaHandler.malloc
80
+ @libui = ::LibUI.new_area(@area_handler)
81
+ end
82
+
83
+ def install_listeners
84
+ @area_handler.Draw = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_draw_params|
85
+ area_draw_params = ::LibUI::FFI::AreaDrawParams.new(area_draw_params)
86
+ area_draw_params = area_draw_params_hash(area_draw_params)
87
+ AreaProxy.current_area_draw_params = area_draw_params
88
+ draw(area_draw_params)
89
+ AreaProxy.current_area_draw_params = nil
90
+ end
91
+ @area_handler.MouseEvent = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_mouse_event|
92
+ area_mouse_event = ::LibUI::FFI::AreaMouseEvent.new(area_mouse_event)
93
+ area_mouse_event = area_mouse_event_hash(area_mouse_event)
94
+ on_mouse_event.each { |listener| listener.call(area_mouse_event)}
95
+ on_mouse_move.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:x].between?(0, area_mouse_event[:area_width]) && area_mouse_event[:y].between?(0, area_mouse_event[:area_height])
96
+ unless @last_area_mouse_event.nil?
97
+ on_mouse_down.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:down] > 0 && @last_area_mouse_event[:down] == 0
98
+ on_mouse_up.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:up] > 0 && @last_area_mouse_event[:up] == 0
99
+ on_mouse_drag_start.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:held] > 0 && @last_area_mouse_event[:held] == 0
100
+ on_mouse_drag.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:held] > 0
101
+ on_mouse_drop.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:held] == 0 && @last_area_mouse_event[:held] > 0
102
+ end
103
+ @last_area_mouse_event = area_mouse_event
104
+ end
105
+ @area_handler.MouseCrossed = fiddle_closure_block_caller(0, [1, 1, 4]) do |_, _, left|
106
+ left = Glimmer::LibUI.integer_to_boolean(left)
107
+ on_mouse_crossed.each { |listener| listener.call(left) }
108
+ if left
109
+ on_mouse_exit.each { |listener| listener.call(left) }
110
+ else
111
+ on_mouse_enter.each { |listener| listener.call(left) }
112
+ end
113
+ end
114
+ @area_handler.DragBroken = fiddle_closure_block_caller(0, [1, 1]) do |_, _|
115
+ on_drag_broken.each { |listener| listener.call }
116
+ end
117
+ @area_handler.KeyEvent = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_key_event|
118
+ area_key_event = ::LibUI::FFI::AreaKeyEvent.new(area_key_event)
119
+ area_key_event = area_key_event_hash(area_key_event)
120
+ on_key_event.each { |listener| listener.call(area_key_event) }
121
+ if area_key_event[:up]
122
+ on_key_up.each { |listener| listener.call(area_key_event) }
123
+ else
124
+ on_key_down.each { |listener| listener.call(area_key_event) }
125
+ end
126
+ end
127
+ end
128
+
129
+ def area_draw_params_hash(area_draw_params)
130
+ {
131
+ context: area_draw_params.Context,
132
+ area_width: area_draw_params.AreaWidth,
133
+ area_height: area_draw_params.AreaHeight,
134
+ clip_x: area_draw_params.ClipX,
135
+ clip_y: area_draw_params.ClipY,
136
+ clip_width: area_draw_params.ClipWidth,
137
+ clip_height: area_draw_params.ClipHeight,
138
+ }
139
+ end
140
+
141
+ def area_mouse_event_hash(area_mouse_event)
142
+ {
143
+ x: area_mouse_event.X,
144
+ y: area_mouse_event.Y,
145
+ area_width: area_mouse_event.AreaWidth,
146
+ area_height: area_mouse_event.AreaHeight,
147
+ down: area_mouse_event.Down,
148
+ up: area_mouse_event.Up,
149
+ count: area_mouse_event.Count,
150
+ modifers: modifiers_to_symbols(area_mouse_event.Modifiers),
151
+ held: area_mouse_event.Held1To64,
152
+ }
153
+ end
154
+
155
+ def area_key_event_hash(area_key_event)
156
+ {
157
+ key: key_to_char(area_key_event.Key),
158
+ ext_key: ext_key_to_symbol(area_key_event.ExtKey),
159
+ modifier: modifiers_to_symbols(area_key_event.Modifier).first,
160
+ modifiers: modifiers_to_symbols(area_key_event.Modifiers),
161
+ up: Glimmer::LibUI.integer_to_boolean(area_key_event.Up),
162
+ }
163
+ end
164
+
165
+ def key_to_char(key)
166
+ key.chr if key > 0
167
+ end
168
+
169
+ 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
171
+ end
172
+
173
+ def modifiers_to_symbols(modifiers_value)
174
+ symbols = []
175
+ modifiers_value = extract_symbol_from_modifiers_value(modifiers_value, symbols: symbols) while modifiers_value > 0
176
+ symbols
177
+ end
178
+
179
+ def extract_symbol_from_modifiers_value(modifiers_value, symbols: )
180
+ if modifiers_value >= 8
181
+ symbols << :command
182
+ modifiers_value -= 8
183
+ elsif modifiers_value >= 4
184
+ symbols << :shift
185
+ modifiers_value -= 4
186
+ elsif modifiers_value >= 2
187
+ symbols << :alt
188
+ modifiers_value -= 2
189
+ elsif modifiers_value >= 1
190
+ symbols << :control
191
+ modifiers_value -= 1
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end
@@ -20,21 +20,18 @@
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/control_proxy/box'
23
24
 
24
25
  module Glimmer
25
26
  module LibUI
26
- # Proxy for LibUI menu item objects
27
- #
28
- # Follows the Proxy Design Pattern
29
- class MenuItemProxy < ControlProxy
30
- def libui_api_keyword
31
- 'menu_item'
32
- end
33
-
34
- private
35
-
36
- def build_control
37
- @libui = @parent_proxy.append_item(*@args)
27
+ class ControlProxy
28
+ module Box
29
+ # Proxy for LibUI horizontal box objects
30
+ #
31
+ # Follows the Proxy Design Pattern
32
+ class HorizontalBoxProxy < ControlProxy
33
+ include Box
34
+ end
38
35
  end
39
36
  end
40
37
  end
@@ -20,15 +20,19 @@
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/box'
23
+ require 'glimmer/libui/control_proxy/box'
24
24
 
25
25
  module Glimmer
26
26
  module LibUI
27
- # Proxy for LibUI horizontal box objects
28
- #
29
- # Follows the Proxy Design Pattern
30
- class HorizontalBoxProxy < ControlProxy
31
- include Box
27
+ class ControlProxy
28
+ module Box
29
+ # Proxy for LibUI vertical box objects
30
+ #
31
+ # Follows the Proxy Design Pattern
32
+ class VerticalBoxProxy < ControlProxy
33
+ include Box
34
+ end
35
+ end
32
36
  end
33
37
  end
34
38
  end
@@ -23,35 +23,39 @@ require 'glimmer/libui/control_proxy'
23
23
 
24
24
  module Glimmer
25
25
  module LibUI
26
- module Box
27
- APPEND_PROPERTIES = %w[stretchy]
28
-
29
- def post_initialize_child(child)
30
- child.stretchy = true if child.stretchy.nil?
31
- ::LibUI.box_append(@libui, child.libui, Glimmer::LibUI.boolean_to_integer(child.stretchy))
32
- children << child
33
- end
34
-
35
- def libui_api_keyword
36
- 'box'
37
- end
38
-
39
- def children
40
- @children ||= []
41
- end
42
-
43
- def destroy_child(child)
44
- ::LibUI.send("box_delete", @libui, children.index(child))
45
- ControlProxy.control_proxies.delete(child)
46
- end
47
-
48
- private
49
-
50
- def build_control
51
- super.tap do
52
- self.padded = true
26
+ class ControlProxy
27
+ module Box
28
+ APPEND_PROPERTIES = %w[stretchy]
29
+
30
+ def post_initialize_child(child)
31
+ child.stretchy = true if child.stretchy.nil?
32
+ ::LibUI.box_append(@libui, child.libui, Glimmer::LibUI.boolean_to_integer(child.stretchy))
33
+ children << child
34
+ end
35
+
36
+ def libui_api_keyword
37
+ 'box'
38
+ end
39
+
40
+ def children
41
+ @children ||= []
42
+ end
43
+
44
+ def destroy_child(child)
45
+ ::LibUI.send("box_delete", @libui, children.index(child))
46
+ ControlProxy.control_proxies.delete(child)
47
+ end
48
+
49
+ private
50
+
51
+ def build_control
52
+ super.tap do
53
+ self.padded = true
54
+ end
53
55
  end
54
56
  end
55
57
  end
56
58
  end
57
59
  end
60
+
61
+ Dir[File.expand_path("./#{File.basename(__FILE__, '.rb')}/*.rb", __dir__)].each {|f| require f}
@@ -23,18 +23,20 @@ require 'glimmer/libui/control_proxy'
23
23
 
24
24
  module Glimmer
25
25
  module LibUI
26
- # Proxy for LibUI button objects
27
- #
28
- # Follows the Proxy Design Pattern
29
- class ButtonProxy < ControlProxy
30
- DEFAULT_TEXT = ''
31
-
32
- private
33
-
34
- def build_control
35
- construction_args = @args.dup
36
- construction_args[0] = DEFAULT_TEXT if construction_args.size == 0
37
- @libui = ControlProxy.new_control(@keyword, construction_args)
26
+ class ControlProxy
27
+ # Proxy for LibUI button objects
28
+ #
29
+ # Follows the Proxy Design Pattern
30
+ class ButtonProxy < ControlProxy
31
+ DEFAULT_TEXT = ''
32
+
33
+ private
34
+
35
+ def build_control
36
+ construction_args = @args.dup
37
+ construction_args[0] = DEFAULT_TEXT if construction_args.size == 0
38
+ @libui = ControlProxy.new_control(@keyword, construction_args)
39
+ end
38
40
  end
39
41
  end
40
42
  end
@@ -23,18 +23,20 @@ require 'glimmer/libui/control_proxy'
23
23
 
24
24
  module Glimmer
25
25
  module LibUI
26
- # Proxy for LibUI checkbox objects
27
- #
28
- # Follows the Proxy Design Pattern
29
- class CheckboxProxy < ControlProxy
30
- DEFAULT_TEXT = ''
31
-
32
- private
33
-
34
- def build_control
35
- construction_args = @args.dup
36
- construction_args[0] = DEFAULT_TEXT if construction_args.size == 0
37
- @libui = ControlProxy.new_control(@keyword, construction_args)
26
+ class ControlProxy
27
+ # Proxy for LibUI checkbox objects
28
+ #
29
+ # Follows the Proxy Design Pattern
30
+ class CheckboxProxy < ControlProxy
31
+ DEFAULT_TEXT = ''
32
+
33
+ private
34
+
35
+ def build_control
36
+ construction_args = @args.dup
37
+ construction_args[0] = DEFAULT_TEXT if construction_args.size == 0
38
+ @libui = ControlProxy.new_control(@keyword, construction_args)
39
+ end
38
40
  end
39
41
  end
40
42
  end
@@ -0,0 +1,118 @@
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 color button objects
28
+ #
29
+ # Follows the Proxy Design Pattern
30
+ class ColorButtonProxy < ControlProxy
31
+ def color(value = nil)
32
+ # TODO support hex color value
33
+ if value.nil?
34
+ @red ||= Fiddle::Pointer.malloc(8) # double
35
+ @green ||= Fiddle::Pointer.malloc(8) # double
36
+ @blue ||= Fiddle::Pointer.malloc(8) # double
37
+ @alpha ||= Fiddle::Pointer.malloc(8) # double
38
+ ::LibUI.color_button_color(@libui, @red, @green, @blue, @alpha)
39
+ {
40
+ r: @red[0, 8].unpack1('d') * 255.0,
41
+ g: @green[0, 8].unpack1('d') * 255.0,
42
+ b: @blue[0, 8].unpack1('d') * 255.0,
43
+ a: @alpha[0, 8].unpack1('d')
44
+ }
45
+ else
46
+ current_color = color
47
+ value = Glimmer::LibUI.interpret_color(value)
48
+ value[:r] ||= current_color[:r]
49
+ value[:g] ||= current_color[:g]
50
+ value[:b] ||= current_color[:b]
51
+ value[:a] ||= current_color[:a]
52
+ ::LibUI.color_button_set_color(@libui, value[:r].to_f / 255.0, value[:g].to_f / 255.0, value[:b].to_f / 255.0, value[:a])
53
+ end
54
+ end
55
+
56
+ def red(value = nil)
57
+ if value.nil?
58
+ color[:r]
59
+ else
60
+ self.color = {r: value}
61
+ end
62
+ end
63
+ alias red= red
64
+ alias set_red red
65
+ alias r red
66
+ alias r= red
67
+ alias set_r red
68
+
69
+ def green(value = nil)
70
+ if value.nil?
71
+ color[:g]
72
+ else
73
+ self.color = {g: value}
74
+ end
75
+ end
76
+ alias green= green
77
+ alias set_green green
78
+ alias g green
79
+ alias g= green
80
+ alias set_g green
81
+
82
+ def blue(value = nil)
83
+ if value.nil?
84
+ color[:b]
85
+ else
86
+ self.color = {b: value}
87
+ end
88
+ end
89
+ alias blue= blue
90
+ alias set_blue blue
91
+ alias b blue
92
+ alias b= blue
93
+ alias set_b blue
94
+
95
+ def alpha(value = nil)
96
+ if value.nil?
97
+ color[:a]
98
+ else
99
+ self.color = {a: value}
100
+ end
101
+ end
102
+ alias alpha= alpha
103
+ alias set_alpha alpha
104
+ alias a alpha
105
+ alias a= alpha
106
+ alias set_a alpha
107
+
108
+ def destroy
109
+ Fiddle.free @red unless @red.nil?
110
+ Fiddle.free @green unless @green.nil?
111
+ Fiddle.free @blue unless @blue.nil?
112
+ Fiddle.free @alpha unless @alpha.nil?
113
+ super
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,76 @@
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
+ require 'glimmer/libui/control_proxy/column'
24
+ require 'glimmer/libui/control_proxy/enableable_column'
25
+
26
+ module Glimmer
27
+ module LibUI
28
+ class ControlProxy
29
+ module Column
30
+ # Proxy for LibUI button column objects
31
+ #
32
+ # Follows the Proxy Design Pattern
33
+ class ButtonColumnProxy < ControlProxy
34
+ include Column
35
+ include EnableableColumn
36
+
37
+ def on_clicked(&block)
38
+ # TODO consider generalizing into custom listeners and moving to ControlProxy
39
+ @on_clicked_procs ||= []
40
+ if block.nil?
41
+ @on_clicked_procs
42
+ else
43
+ @on_clicked_procs << block
44
+ block
45
+ end
46
+ end
47
+
48
+ def can_handle_listener?(listener_name)
49
+ listener_name == 'on_clicked' || super
50
+ end
51
+
52
+ def handle_listener(listener_name, &listener)
53
+ case listener_name
54
+ when 'on_clicked'
55
+ on_clicked(&listener)
56
+ else
57
+ super
58
+ end
59
+ end
60
+
61
+ def notify_listeners(listener_name, *args)
62
+ @on_clicked_procs&.each do |on_clicked_proc|
63
+ on_clicked_proc.call(*args)
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ def build_control
70
+ @parent_proxy.append_button_column(name, column_index, enabled_value)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,46 @@
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
+ require 'glimmer/libui/control_proxy/column'
24
+ require 'glimmer/libui/control_proxy/editable_column'
25
+
26
+ module Glimmer
27
+ module LibUI
28
+ class ControlProxy
29
+ module Column
30
+ # Proxy for LibUI checkbox column objects
31
+ #
32
+ # Follows the Proxy Design Pattern
33
+ class CheckboxColumnProxy < ControlProxy
34
+ include Column
35
+ include EditableColumn
36
+
37
+ private
38
+
39
+ def build_control
40
+ @parent_proxy.append_checkbox_column(name, column_index, editable_value)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end