glimmer-dsl-libui 0.1.4 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +55 -0
  3. data/README.md +939 -255
  4. data/VERSION +1 -1
  5. data/examples/area_gallery.rb +72 -38
  6. data/examples/area_gallery2.rb +126 -92
  7. data/examples/area_gallery3.rb +74 -40
  8. data/examples/area_gallery4.rb +132 -98
  9. data/examples/basic_area2.rb +1 -1
  10. data/examples/basic_button.rb +2 -2
  11. data/examples/basic_entry.rb +2 -2
  12. data/examples/basic_transform.rb +27 -0
  13. data/examples/control_gallery.rb +3 -3
  14. data/examples/dynamic_area.rb +1 -1
  15. data/examples/form.rb +2 -2
  16. data/examples/histogram.rb +118 -0
  17. data/examples/meta_example.rb +71 -20
  18. data/examples/midi_player.rb +8 -10
  19. data/glimmer-dsl-libui.gemspec +0 -0
  20. data/lib/glimmer/dsl/libui/control_expression.rb +0 -2
  21. data/lib/glimmer/dsl/libui/file_expression.rb +5 -1
  22. data/lib/glimmer/dsl/libui/shape_expression.rb +2 -4
  23. data/lib/glimmer/dsl/libui/tab_item_expression.rb +2 -2
  24. data/lib/glimmer/libui/control_proxy/area_proxy.rb +166 -0
  25. data/lib/glimmer/libui/{menu_item_proxy.rb → control_proxy/box/horizontal_box_proxy.rb} +9 -12
  26. data/lib/glimmer/libui/{horizontal_box_proxy.rb → control_proxy/box/vertical_box_proxy.rb} +10 -6
  27. data/lib/glimmer/libui/{box.rb → control_proxy/box.rb} +31 -27
  28. data/lib/glimmer/libui/{button_proxy.rb → control_proxy/button_proxy.rb} +14 -12
  29. data/lib/glimmer/libui/{checkbox_proxy.rb → control_proxy/checkbox_proxy.rb} +14 -12
  30. data/lib/glimmer/libui/control_proxy/color_button_proxy.rb +118 -0
  31. data/lib/glimmer/libui/control_proxy/column/button_column_proxy.rb +76 -0
  32. data/lib/glimmer/libui/control_proxy/column/checkbox_column_proxy.rb +46 -0
  33. data/lib/glimmer/libui/control_proxy/column/checkbox_text_column_proxy.rb +80 -0
  34. data/lib/glimmer/libui/{radio_buttons_proxy.rb → control_proxy/column/image_column_proxy.rb} +14 -13
  35. data/lib/glimmer/libui/control_proxy/column/image_text_column_proxy.rb +48 -0
  36. data/lib/glimmer/libui/control_proxy/column/progress_bar_column_proxy.rb +44 -0
  37. data/lib/glimmer/libui/{checkbox_column_proxy.rb → control_proxy/column/text_column_proxy.rb} +17 -13
  38. data/lib/glimmer/libui/control_proxy/column.rb +55 -0
  39. data/lib/glimmer/libui/control_proxy/combobox_proxy.rb +45 -0
  40. data/lib/glimmer/libui/control_proxy/date_time_picker_proxy/date_picker_proxy.rb +43 -0
  41. data/lib/glimmer/libui/control_proxy/date_time_picker_proxy/time_picker_proxy.rb +43 -0
  42. data/lib/glimmer/libui/control_proxy/date_time_picker_proxy.rb +72 -0
  43. data/lib/glimmer/libui/control_proxy/dual_column.rb +40 -0
  44. data/lib/glimmer/libui/control_proxy/editable_column.rb +46 -0
  45. data/lib/glimmer/libui/control_proxy/editable_combobox_proxy.rb +45 -0
  46. data/lib/glimmer/libui/{dual_column.rb → control_proxy/enableable_column.rb} +18 -10
  47. data/lib/glimmer/libui/control_proxy/font_button_proxy.rb +70 -0
  48. data/lib/glimmer/libui/{form_proxy.rb → control_proxy/form_proxy.rb} +26 -24
  49. data/lib/glimmer/libui/{grid_proxy.rb → control_proxy/grid_proxy.rb} +29 -27
  50. data/lib/glimmer/libui/{group_proxy.rb → control_proxy/group_proxy.rb} +24 -22
  51. data/lib/glimmer/libui/{image_part_proxy.rb → control_proxy/image_part_proxy.rb} +20 -18
  52. data/lib/glimmer/libui/{image_proxy.rb → control_proxy/image_proxy.rb} +32 -30
  53. data/lib/glimmer/libui/{combobox_proxy.rb → control_proxy/label_proxy.rb} +13 -13
  54. data/lib/glimmer/libui/control_proxy/matrix_proxy.rb +147 -0
  55. data/lib/glimmer/libui/{editable_column.rb → control_proxy/menu_item_proxy/about_menu_item_proxy.rb} +13 -16
  56. data/lib/glimmer/libui/control_proxy/menu_item_proxy/check_menu_item_proxy.rb +41 -0
  57. data/lib/glimmer/libui/{date_picker_proxy.rb → control_proxy/menu_item_proxy/preferences_menu_item_proxy.rb} +10 -10
  58. data/lib/glimmer/libui/{quit_menu_item_proxy.rb → control_proxy/menu_item_proxy/quit_menu_item_proxy.rb} +33 -29
  59. data/lib/glimmer/libui/control_proxy/menu_item_proxy/separator_menu_item_proxy.rb +41 -0
  60. data/lib/glimmer/libui/control_proxy/menu_item_proxy.rb +45 -0
  61. data/lib/glimmer/libui/{editable_combobox_proxy.rb → control_proxy/menu_proxy.rb} +13 -13
  62. data/lib/glimmer/libui/{vertical_box_proxy.rb → control_proxy/message_box/msg_box_error_proxy.rb} +9 -6
  63. data/lib/glimmer/libui/{multiline_entry_proxy.rb → control_proxy/message_box/msg_box_proxy.rb} +8 -6
  64. data/lib/glimmer/libui/{time_picker_proxy.rb → control_proxy/message_box.rb} +9 -10
  65. data/lib/glimmer/libui/{rectangle.rb → control_proxy/multiline_entry_proxy/non_wrapping_multiline_entry_proxy.rb} +6 -8
  66. data/lib/glimmer/libui/{progress_bar_column_proxy.rb → control_proxy/multiline_entry_proxy.rb} +10 -11
  67. data/lib/glimmer/libui/control_proxy/path_proxy.rb +190 -0
  68. data/lib/glimmer/libui/control_proxy/radio_buttons_proxy.rb +45 -0
  69. data/lib/glimmer/libui/{button_column_proxy.rb → control_proxy/tab_item_proxy.rb} +37 -40
  70. data/lib/glimmer/libui/control_proxy/table_proxy.rb +182 -0
  71. data/lib/glimmer/libui/control_proxy/transformable.rb +74 -0
  72. data/lib/glimmer/libui/control_proxy/window_proxy.rb +128 -0
  73. data/lib/glimmer/libui/control_proxy.rb +72 -21
  74. data/lib/glimmer/libui/{enableable_column.rb → parent.rb} +7 -15
  75. data/lib/glimmer/libui/{arc.rb → shape/arc.rb} +13 -11
  76. data/lib/glimmer/libui/shape/bezier.rb +38 -0
  77. data/lib/glimmer/libui/{figure.rb → shape/figure.rb} +23 -21
  78. data/lib/glimmer/libui/{line.rb → shape/line.rb} +9 -7
  79. data/lib/glimmer/libui/{bezier.rb → shape/rectangle.rb} +9 -7
  80. data/lib/glimmer/libui/{square.rb → shape/square.rb} +9 -7
  81. data/lib/glimmer/libui/shape.rb +16 -15
  82. data/lib/glimmer/libui.rb +92 -0
  83. data/lib/glimmer-dsl-libui.rb +3 -0
  84. metadata +76 -53
  85. data/lib/glimmer/libui/about_menu_item_proxy.rb +0 -37
  86. data/lib/glimmer/libui/area_proxy.rb +0 -105
  87. data/lib/glimmer/libui/check_menu_item_proxy.rb +0 -37
  88. data/lib/glimmer/libui/checkbox_text_column_proxy.rb +0 -76
  89. data/lib/glimmer/libui/color_button_proxy.rb +0 -64
  90. data/lib/glimmer/libui/column.rb +0 -51
  91. data/lib/glimmer/libui/date_time_picker_proxy.rb +0 -68
  92. data/lib/glimmer/libui/font_button_proxy.rb +0 -68
  93. data/lib/glimmer/libui/image_column_proxy.rb +0 -40
  94. data/lib/glimmer/libui/image_text_column_proxy.rb +0 -44
  95. data/lib/glimmer/libui/label_proxy.rb +0 -41
  96. data/lib/glimmer/libui/menu_proxy.rb +0 -41
  97. data/lib/glimmer/libui/non_wrapping_multiline_entry_proxy.rb +0 -32
  98. data/lib/glimmer/libui/path_proxy.rb +0 -169
  99. data/lib/glimmer/libui/preferences_menu_item_proxy.rb +0 -37
  100. data/lib/glimmer/libui/separator_menu_item_proxy.rb +0 -37
  101. data/lib/glimmer/libui/tab_item_proxy.rb +0 -67
  102. data/lib/glimmer/libui/table_proxy.rb +0 -180
  103. data/lib/glimmer/libui/text_column_proxy.rb +0 -42
  104. data/lib/glimmer/libui/window_proxy.rb +0 -119
@@ -31,7 +31,7 @@ module Glimmer
31
31
  def can_interpret?(parent, keyword, *args, &block)
32
32
  Glimmer::LibUI::Shape.exists?(keyword) and
33
33
  (
34
- parent.is_a?(Glimmer::LibUI::PathProxy) or
34
+ parent.is_a?(Glimmer::LibUI::ControlProxy::PathProxy) or
35
35
  parent.is_a?(Glimmer::LibUI::Shape)
36
36
  )
37
37
  end
@@ -50,7 +50,5 @@ module Glimmer
50
50
  end
51
51
  end
52
52
 
53
- # TODO Consider moving all shapes underneath Shape namespace
54
- require 'glimmer/libui/path_proxy'
53
+ require 'glimmer/libui/control_proxy/path_proxy'
55
54
  require 'glimmer/libui/shape'
56
- Dir[File.expand_path('../../libui/*.rb', __dir__)].each {|f| require f}
@@ -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,166 @@
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
+ end
38
+
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']
40
+ LISTENER_ALIASES = {
41
+ on_drawn: 'on_draw',
42
+ on_mouse_moved: 'on_mouse_move',
43
+ on_mouse_drag_started: 'on_mouse_drag_start',
44
+ on_mouse_dragged: 'on_mouse_drag',
45
+ on_mouse_dropped: 'on_mouse_drop',
46
+ on_mouse_cross: 'on_mouse_crossed',
47
+ on_mouse_entered: 'on_mouse_enter',
48
+ on_mouse_exited: 'on_mouse_exit',
49
+ on_drag_break: 'on_drag_broken',
50
+ }
51
+
52
+ include Glimmer::FiddleConsumer
53
+ include Parent
54
+ prepend Transformable
55
+
56
+ attr_reader :area_handler
57
+
58
+ def post_add_content
59
+ super
60
+ install_listeners
61
+ end
62
+
63
+ def draw(area_draw_params)
64
+ children.dup.each {|child| child.draw(area_draw_params)}
65
+ on_draw.each {|listener| listener.call(area_draw_params)}
66
+ end
67
+
68
+ def redraw
69
+ queue_redraw_all
70
+ end
71
+
72
+ private
73
+
74
+ def build_control
75
+ @area_handler = ::LibUI::FFI::AreaHandler.malloc
76
+ @libui = ::LibUI.new_area(@area_handler)
77
+ end
78
+
79
+ def install_listeners
80
+ @area_handler.Draw = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_draw_params|
81
+ area_draw_params = ::LibUI::FFI::AreaDrawParams.new(area_draw_params)
82
+ area_draw_params = area_draw_params_hash(area_draw_params)
83
+ AreaProxy.current_area_draw_params = area_draw_params
84
+ draw(area_draw_params)
85
+ AreaProxy.current_area_draw_params = nil
86
+ end
87
+ @area_handler.MouseEvent = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_mouse_event|
88
+ area_mouse_event = ::LibUI::FFI::AreaMouseEvent.new(area_mouse_event)
89
+ area_mouse_event = area_mouse_event_hash(area_mouse_event)
90
+ on_mouse_event.each { |listener| listener.call(area_mouse_event)}
91
+ 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])
92
+ unless @last_area_mouse_event.nil?
93
+ on_mouse_down.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:down] > 0 && @last_area_mouse_event[:down] == 0
94
+ on_mouse_up.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:up] > 0 && @last_area_mouse_event[:up] == 0
95
+ on_mouse_drag_start.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:held] > 0 && @last_area_mouse_event[:held] == 0
96
+ on_mouse_drag.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:held] > 0
97
+ on_mouse_drop.each { |listener| listener.call(area_mouse_event)} if area_mouse_event[:held] == 0 && @last_area_mouse_event[:held] > 0
98
+ end
99
+ @last_area_mouse_event = area_mouse_event
100
+ end
101
+ @area_handler.MouseCrossed = fiddle_closure_block_caller(0, [1, 1, 4]) do |_, _, left|
102
+ left = Glimmer::LibUI.integer_to_boolean(left)
103
+ on_mouse_crossed.each { |listener| listener.call(left) }
104
+ if left
105
+ on_mouse_exit.each { |listener| listener.call(left) }
106
+ else
107
+ on_mouse_enter.each { |listener| listener.call(left) }
108
+ end
109
+ end
110
+ @area_handler.DragBroken = fiddle_closure_block_caller(0, [1, 1]) do |_, _|
111
+ on_drag_broken.each { |listener| listener.call }
112
+ end
113
+ @area_handler.KeyEvent = fiddle_closure_block_caller(0, [0]) {}
114
+ end
115
+
116
+ def area_draw_params_hash(area_draw_params)
117
+ {
118
+ context: area_draw_params.Context,
119
+ area_width: area_draw_params.AreaWidth,
120
+ area_height: area_draw_params.AreaHeight,
121
+ clip_x: area_draw_params.ClipX,
122
+ clip_y: area_draw_params.ClipY,
123
+ clip_width: area_draw_params.ClipWidth,
124
+ clip_height: area_draw_params.ClipHeight,
125
+ }
126
+ end
127
+
128
+ def area_mouse_event_hash(area_mouse_event)
129
+ {
130
+ x: area_mouse_event.X,
131
+ y: area_mouse_event.Y,
132
+ area_width: area_mouse_event.AreaWidth,
133
+ area_height: area_mouse_event.AreaHeight,
134
+ down: area_mouse_event.Down,
135
+ up: area_mouse_event.Up,
136
+ count: area_mouse_event.Count,
137
+ modifers: modifiers_to_symbols(area_mouse_event.Modifiers),
138
+ held: area_mouse_event.Held1To64,
139
+ }
140
+ end
141
+
142
+ def modifiers_to_symbols(modifiers_value)
143
+ symbols = []
144
+ modifiers_value = extract_symbol_from_modifiers_value(modifiers_value, symbols: symbols) while modifiers_value > 0
145
+ symbols
146
+ end
147
+
148
+ def extract_symbol_from_modifiers_value(modifiers_value, symbols: )
149
+ if modifiers_value >= 8
150
+ symbols << :command
151
+ modifiers_value -= 8
152
+ elsif modifiers_value >= 4
153
+ symbols << :shift
154
+ modifiers_value -= 4
155
+ elsif modifiers_value >= 2
156
+ symbols << :alt
157
+ modifiers_value -= 2
158
+ elsif modifiers_value >= 1
159
+ symbols << :control
160
+ modifiers_value -= 1
161
+ end
162
+ end
163
+ end
164
+ end
165
+ end
166
+ 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, ControlProxy.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