glimmer-dsl-libui 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -0
  3. data/README.md +63 -55
  4. data/VERSION +1 -1
  5. data/examples/basic_button.rb +2 -2
  6. data/examples/basic_entry.rb +2 -2
  7. data/examples/basic_transform.rb +1 -1
  8. data/examples/control_gallery.rb +3 -3
  9. data/examples/form.rb +2 -2
  10. data/examples/histogram.rb +18 -19
  11. data/examples/meta_example.rb +71 -20
  12. data/examples/midi_player.rb +8 -10
  13. data/glimmer-dsl-libui.gemspec +0 -0
  14. data/lib/glimmer/dsl/libui/control_expression.rb +0 -2
  15. data/lib/glimmer/dsl/libui/file_expression.rb +5 -1
  16. data/lib/glimmer/dsl/libui/shape_expression.rb +2 -4
  17. data/lib/glimmer/dsl/libui/tab_item_expression.rb +2 -2
  18. data/lib/glimmer/libui/control_proxy/area_proxy.rb +117 -0
  19. data/lib/glimmer/libui/{menu_item_proxy.rb → control_proxy/box/horizontal_box_proxy.rb} +9 -12
  20. data/lib/glimmer/libui/{horizontal_box_proxy.rb → control_proxy/box/vertical_box_proxy.rb} +10 -6
  21. data/lib/glimmer/libui/{box.rb → control_proxy/box.rb} +31 -27
  22. data/lib/glimmer/libui/{button_proxy.rb → control_proxy/button_proxy.rb} +14 -12
  23. data/lib/glimmer/libui/{checkbox_proxy.rb → control_proxy/checkbox_proxy.rb} +14 -12
  24. data/lib/glimmer/libui/control_proxy/color_button_proxy.rb +118 -0
  25. data/lib/glimmer/libui/control_proxy/column/button_column_proxy.rb +76 -0
  26. data/lib/glimmer/libui/control_proxy/column/checkbox_column_proxy.rb +46 -0
  27. data/lib/glimmer/libui/control_proxy/column/checkbox_text_column_proxy.rb +80 -0
  28. data/lib/glimmer/libui/{radio_buttons_proxy.rb → control_proxy/column/image_column_proxy.rb} +14 -13
  29. data/lib/glimmer/libui/control_proxy/column/image_text_column_proxy.rb +48 -0
  30. data/lib/glimmer/libui/control_proxy/column/progress_bar_column_proxy.rb +44 -0
  31. data/lib/glimmer/libui/{checkbox_column_proxy.rb → control_proxy/column/text_column_proxy.rb} +17 -13
  32. data/lib/glimmer/libui/control_proxy/column.rb +55 -0
  33. data/lib/glimmer/libui/control_proxy/combobox_proxy.rb +45 -0
  34. data/lib/glimmer/libui/control_proxy/date_time_picker_proxy/date_picker_proxy.rb +43 -0
  35. data/lib/glimmer/libui/control_proxy/date_time_picker_proxy/time_picker_proxy.rb +43 -0
  36. data/lib/glimmer/libui/control_proxy/date_time_picker_proxy.rb +72 -0
  37. data/lib/glimmer/libui/control_proxy/dual_column.rb +40 -0
  38. data/lib/glimmer/libui/control_proxy/editable_column.rb +46 -0
  39. data/lib/glimmer/libui/control_proxy/editable_combobox_proxy.rb +45 -0
  40. data/lib/glimmer/libui/{dual_column.rb → control_proxy/enableable_column.rb} +18 -10
  41. data/lib/glimmer/libui/control_proxy/font_button_proxy.rb +70 -0
  42. data/lib/glimmer/libui/{form_proxy.rb → control_proxy/form_proxy.rb} +26 -24
  43. data/lib/glimmer/libui/{grid_proxy.rb → control_proxy/grid_proxy.rb} +29 -27
  44. data/lib/glimmer/libui/{group_proxy.rb → control_proxy/group_proxy.rb} +24 -22
  45. data/lib/glimmer/libui/{image_part_proxy.rb → control_proxy/image_part_proxy.rb} +20 -18
  46. data/lib/glimmer/libui/{image_proxy.rb → control_proxy/image_proxy.rb} +32 -30
  47. data/lib/glimmer/libui/{combobox_proxy.rb → control_proxy/label_proxy.rb} +13 -13
  48. data/lib/glimmer/libui/control_proxy/matrix_proxy.rb +147 -0
  49. data/lib/glimmer/libui/{editable_column.rb → control_proxy/menu_item_proxy/about_menu_item_proxy.rb} +13 -16
  50. data/lib/glimmer/libui/{enableable_column.rb → control_proxy/menu_item_proxy/check_menu_item_proxy.rb} +13 -16
  51. data/lib/glimmer/libui/{date_picker_proxy.rb → control_proxy/menu_item_proxy/preferences_menu_item_proxy.rb} +10 -10
  52. data/lib/glimmer/libui/{quit_menu_item_proxy.rb → control_proxy/menu_item_proxy/quit_menu_item_proxy.rb} +33 -29
  53. data/lib/glimmer/libui/control_proxy/menu_item_proxy/separator_menu_item_proxy.rb +41 -0
  54. data/lib/glimmer/libui/control_proxy/menu_item_proxy.rb +45 -0
  55. data/lib/glimmer/libui/{editable_combobox_proxy.rb → control_proxy/menu_proxy.rb} +13 -13
  56. data/lib/glimmer/libui/{vertical_box_proxy.rb → control_proxy/message_box/msg_box_error_proxy.rb} +9 -6
  57. data/lib/glimmer/libui/{multiline_entry_proxy.rb → control_proxy/message_box/msg_box_proxy.rb} +8 -6
  58. data/lib/glimmer/libui/{time_picker_proxy.rb → control_proxy/message_box.rb} +9 -10
  59. data/lib/glimmer/libui/{rectangle.rb → control_proxy/multiline_entry_proxy/non_wrapping_multiline_entry_proxy.rb} +6 -8
  60. data/lib/glimmer/libui/{progress_bar_column_proxy.rb → control_proxy/multiline_entry_proxy.rb} +10 -11
  61. data/lib/glimmer/libui/control_proxy/path_proxy.rb +169 -0
  62. data/lib/glimmer/libui/control_proxy/radio_buttons_proxy.rb +45 -0
  63. data/lib/glimmer/libui/{button_column_proxy.rb → control_proxy/tab_item_proxy.rb} +37 -40
  64. data/lib/glimmer/libui/control_proxy/table_proxy.rb +182 -0
  65. data/lib/glimmer/libui/{transformable.rb → control_proxy/transformable.rb} +3 -1
  66. data/lib/glimmer/libui/control_proxy/window_proxy.rb +128 -0
  67. data/lib/glimmer/libui/control_proxy.rb +35 -8
  68. data/lib/glimmer/libui/{arc.rb → shape/arc.rb} +13 -11
  69. data/lib/glimmer/libui/shape/bezier.rb +38 -0
  70. data/lib/glimmer/libui/{figure.rb → shape/figure.rb} +23 -21
  71. data/lib/glimmer/libui/{line.rb → shape/line.rb} +9 -7
  72. data/lib/glimmer/libui/{bezier.rb → shape/rectangle.rb} +9 -7
  73. data/lib/glimmer/libui/{square.rb → shape/square.rb} +9 -7
  74. data/lib/glimmer/libui/shape.rb +8 -6
  75. data/lib/glimmer/libui.rb +43 -1
  76. data/lib/glimmer-dsl-libui.rb +1 -0
  77. metadata +72 -55
  78. data/lib/glimmer/libui/about_menu_item_proxy.rb +0 -37
  79. data/lib/glimmer/libui/area_proxy.rb +0 -115
  80. data/lib/glimmer/libui/check_menu_item_proxy.rb +0 -37
  81. data/lib/glimmer/libui/checkbox_text_column_proxy.rb +0 -76
  82. data/lib/glimmer/libui/color_button_proxy.rb +0 -116
  83. data/lib/glimmer/libui/column.rb +0 -51
  84. data/lib/glimmer/libui/date_time_picker_proxy.rb +0 -68
  85. data/lib/glimmer/libui/font_button_proxy.rb +0 -68
  86. data/lib/glimmer/libui/image_column_proxy.rb +0 -40
  87. data/lib/glimmer/libui/image_text_column_proxy.rb +0 -44
  88. data/lib/glimmer/libui/label_proxy.rb +0 -41
  89. data/lib/glimmer/libui/matrix_proxy.rb +0 -145
  90. data/lib/glimmer/libui/menu_proxy.rb +0 -41
  91. data/lib/glimmer/libui/non_wrapping_multiline_entry_proxy.rb +0 -32
  92. data/lib/glimmer/libui/path_proxy.rb +0 -166
  93. data/lib/glimmer/libui/preferences_menu_item_proxy.rb +0 -37
  94. data/lib/glimmer/libui/separator_menu_item_proxy.rb +0 -37
  95. data/lib/glimmer/libui/tab_item_proxy.rb +0 -67
  96. data/lib/glimmer/libui/table_proxy.rb +0 -180
  97. data/lib/glimmer/libui/text_column_proxy.rb +0 -42
  98. data/lib/glimmer/libui/window_proxy.rb +0 -126
@@ -19,26 +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/libui/control_proxy/menu_item_proxy'
23
+
22
24
  module Glimmer
23
25
  module LibUI
24
- module EditableColumn
25
- def editable(value = nil)
26
- if value.nil?
27
- @editable = false if @editable.nil?
28
- @editable
29
- else
30
- @editable = !!value
26
+ class ControlProxy
27
+ class MenuItemProxy < ControlProxy
28
+ # Proxy for LibUI about menu item object
29
+ #
30
+ # Follows the Proxy Design Pattern
31
+ class AboutMenuItemProxy < MenuItemProxy
32
+ private
33
+
34
+ def build_control
35
+ @libui = @parent_proxy.append_about_item(*@args)
36
+ end
31
37
  end
32
38
  end
33
- alias editable= editable
34
- alias set_editable editable
35
- alias editable? editable
36
-
37
- private
38
-
39
- def editable_value
40
- (@parent_proxy.editable? || editable?) ? -2 : -1
41
- end
42
39
  end
43
40
  end
44
41
  end
@@ -19,26 +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/libui/control_proxy/menu_item_proxy'
23
+
22
24
  module Glimmer
23
25
  module LibUI
24
- module EnableableColumn
25
- def enabled(value = nil)
26
- if value.nil?
27
- @enabled = true if @enabled.nil?
28
- @enabled
29
- else
30
- @enabled = !!value
26
+ class ControlProxy
27
+ class MenuItemProxy < ControlProxy
28
+ # Proxy for LibUI check menu item object
29
+ #
30
+ # Follows the Proxy Design Pattern
31
+ class CheckMenuItemProxy < MenuItemProxy
32
+ private
33
+
34
+ def build_control
35
+ @libui = @parent_proxy.append_check_item(*@args)
36
+ end
31
37
  end
32
38
  end
33
- alias enabled= enabled
34
- alias set_enabled enabled
35
- alias enabled? enabled
36
-
37
- private
38
-
39
- def enabled_value
40
- enabled? ? -2 : -1
41
- end
42
39
  end
43
40
  end
44
41
  end
@@ -19,19 +19,19 @@
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/libui/date_time_picker_proxy'
22
+ require 'glimmer/libui/control_proxy/menu_item_proxy'
23
23
 
24
24
  module Glimmer
25
25
  module LibUI
26
- # Proxy for LibUI date picker objects
27
- #
28
- # Follows the Proxy Design Pattern
29
- class DatePickerProxy < DateTimePickerProxy
30
- def time(value = nil)
31
- if value.nil?
32
- super.slice(:mday, :mon, :year, :wday, :yday)
33
- else
34
- super
26
+ class ControlProxy
27
+ # Proxy for LibUI preferences menu item object
28
+ #
29
+ # Follows the Proxy Design Pattern
30
+ class PreferencesMenuItemProxy < MenuItemProxy
31
+ private
32
+
33
+ def build_control
34
+ @libui = @parent_proxy.append_preferences_item(*@args)
35
35
  end
36
36
  end
37
37
  end
@@ -19,42 +19,46 @@
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/libui/menu_item_proxy'
22
+ require 'glimmer/libui/control_proxy/menu_item_proxy'
23
23
 
24
24
  module Glimmer
25
25
  module LibUI
26
- # Proxy for LibUI quit menu item object
27
- #
28
- # Follows the Proxy Design Pattern
29
- class QuitMenuItemProxy < MenuItemProxy
30
- def can_handle_listener?(listener_name)
31
- listener_name == 'on_clicked' || super
32
- end
33
-
34
- def handle_listener(listener_name, &listener)
35
- if listener_name == 'on_clicked'
36
- @default_behavior_listener = Proc.new do
37
- return_value = listener.call(self)
38
- if return_value.is_a?(Numeric)
39
- return_value
40
- else
41
- destroy
26
+ class ControlProxy
27
+ class MenuItemProxy < ControlProxy
28
+ # Proxy for LibUI quit menu item object
29
+ #
30
+ # Follows the Proxy Design Pattern
31
+ class QuitMenuItemProxy < MenuItemProxy
32
+ def can_handle_listener?(listener_name)
33
+ listener_name == 'on_clicked' || super
34
+ end
35
+
36
+ def handle_listener(listener_name, &listener)
37
+ if listener_name == 'on_clicked'
38
+ @default_behavior_listener = Proc.new do
39
+ return_value = listener.call(self)
40
+ if return_value.is_a?(Numeric)
41
+ return_value
42
+ else
43
+ destroy
44
+ ::LibUI.quit
45
+ 0
46
+ end
47
+ end
48
+ ::LibUI.on_should_quit(&@default_behavior_listener)
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def build_control
55
+ @libui = @parent_proxy.append_quit_item(*@args)
56
+ handle_listener('on_clicked') do
57
+ ControlProxy.main_window_proxy&.destroy
42
58
  ::LibUI.quit
43
59
  0
44
60
  end
45
61
  end
46
- ::LibUI.on_should_quit(&@default_behavior_listener)
47
- end
48
- end
49
-
50
- private
51
-
52
- def build_control
53
- @libui = @parent_proxy.append_quit_item(*@args)
54
- handle_listener('on_clicked') do
55
- ControlProxy.main_window_proxy&.destroy
56
- ::LibUI.quit
57
- 0
58
62
  end
59
63
  end
60
64
  end
@@ -0,0 +1,41 @@
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 separator menu item object
29
+ #
30
+ # Follows the Proxy Design Pattern
31
+ class SeparatorMenuItemProxy < MenuItemProxy
32
+ private
33
+
34
+ def build_control
35
+ @libui = @parent_proxy.append_separator(*@args)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,45 @@
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 menu item objects
28
+ #
29
+ # Follows the Proxy Design Pattern
30
+ class MenuItemProxy < ControlProxy
31
+ def libui_api_keyword
32
+ 'menu_item'
33
+ end
34
+
35
+ private
36
+
37
+ def build_control
38
+ @libui = @parent_proxy.append_item(*@args)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ Dir[File.expand_path("./#{File.basename(__FILE__, '.rb')}/*.rb", __dir__)].each {|f| require f}
@@ -23,21 +23,21 @@ require 'glimmer/libui/control_proxy'
23
23
 
24
24
  module Glimmer
25
25
  module LibUI
26
- # Proxy for LibUI editable combobox objects
27
- #
28
- # Follows the Proxy Design Pattern
29
- class EditableComboboxProxy < ControlProxy
30
- def items(*values)
31
- values = values.first if values.first.is_a?(Array)
32
- if values.empty?
33
- @values
34
- else
35
- @values = values
36
- @values.each { |value| append value }
26
+ class ControlProxy
27
+ # Proxy for LibUI menu objects
28
+ #
29
+ # Follows the Proxy Design Pattern
30
+ class MenuProxy < 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)
37
39
  end
38
40
  end
39
- alias set_items items
40
- alias items= items
41
41
  end
42
42
  end
43
43
  end
@@ -20,15 +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/box'
24
23
 
25
24
  module Glimmer
26
25
  module LibUI
27
- # Proxy for LibUI vertical box objects
28
- #
29
- # Follows the Proxy Design Pattern
30
- class VerticalBoxProxy < ControlProxy
31
- include Box
26
+ class ControlProxy
27
+ module MessageBox
28
+ # Proxy for LibUI msg_box_error objects
29
+ #
30
+ # Follows the Proxy Design Pattern
31
+ class MsgBoxErrorProxy < ControlProxy
32
+ include MessageBox
33
+ end
34
+ end
32
35
  end
33
36
  end
34
37
  end
@@ -23,12 +23,14 @@ require 'glimmer/libui/control_proxy'
23
23
 
24
24
  module Glimmer
25
25
  module LibUI
26
- # Proxy for LibUI multiline entry objects
27
- #
28
- # Follows the Proxy Design Pattern
29
- class MultilineEntryProxy < ControlProxy
30
- def libui_api_keyword
31
- 'multiline_entry'
26
+ class ControlProxy
27
+ module MessageBox
28
+ # Proxy for LibUI msg_box objects
29
+ #
30
+ # Follows the Proxy Design Pattern
31
+ class MsgBoxProxy < ControlProxy
32
+ include MessageBox
33
+ end
32
34
  end
33
35
  end
34
36
  end
@@ -19,21 +19,20 @@
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/libui/date_time_picker_proxy'
23
-
24
22
  module Glimmer
25
23
  module LibUI
26
- # Proxy for LibUI time picker objects
27
- #
28
- # Follows the Proxy Design Pattern
29
- class TimePickerProxy < DateTimePickerProxy
30
- def time(value = nil)
31
- if value.nil?
32
- super.slice(:sec, :min, :hour)
33
- else
24
+ class ControlProxy
25
+ # Represents LibUI message box objects
26
+ module MessageBox
27
+ def build_control
28
+ @args.prepend ControlProxy.main_window_proxy if @args[0].nil? || @args[0].is_a?(String)
29
+ @args[1] ||= ''
30
+ @args[2] ||= ''
34
31
  super
35
32
  end
36
33
  end
37
34
  end
38
35
  end
39
36
  end
37
+
38
+ Dir[File.expand_path("./#{File.basename(__FILE__, '.rb')}/*.rb", __dir__)].each {|f| require f}
@@ -19,17 +19,15 @@
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/libui/shape'
22
+ require 'glimmer/libui/control_proxy/multiline_entry_proxy'
23
23
 
24
24
  module Glimmer
25
25
  module LibUI
26
- class Rectangle < Shape
27
- parameters :x, :y, :width, :height
28
- parameter_defaults 0, 0, 0, 0
29
-
30
- def draw(area_draw_params)
31
- ::LibUI.draw_path_add_rectangle(path_proxy.libui, *@args)
32
- super
26
+ class ControlProxy
27
+ # Proxy for LibUI non wrapping multiline entry objects
28
+ #
29
+ # Follows the Proxy Design Pattern
30
+ class NonWrappingMultilineEntryProxy < MultilineEntryProxy
33
31
  end
34
32
  end
35
33
  end
@@ -20,21 +20,20 @@
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/column'
24
23
 
25
24
  module Glimmer
26
25
  module LibUI
27
- # Proxy for LibUI progress bar column objects
28
- #
29
- # Follows the Proxy Design Pattern
30
- class ProgressBarColumnProxy < ControlProxy
31
- include Column
32
-
33
- private
34
-
35
- def build_control
36
- @parent_proxy.append_progress_bar_column(name, column_index)
26
+ class ControlProxy
27
+ # Proxy for LibUI multiline entry objects
28
+ #
29
+ # Follows the Proxy Design Pattern
30
+ class MultilineEntryProxy < ControlProxy
31
+ def libui_api_keyword
32
+ 'multiline_entry'
33
+ end
37
34
  end
38
35
  end
39
36
  end
40
37
  end
38
+
39
+ Dir[File.expand_path("./#{File.basename(__FILE__, '.rb')}/*.rb", __dir__)].each {|f| require f}
@@ -0,0 +1,169 @@
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/area_proxy'
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 path objects
31
+ #
32
+ # Follows the Proxy Design Pattern
33
+ class PathProxy < ControlProxy
34
+ include Parent
35
+ prepend Transformable
36
+
37
+ # TODO support mode without parent proxy
38
+ def initialize(keyword, parent, args, &block)
39
+ @keyword = keyword
40
+ @parent_proxy = parent
41
+ @args = args
42
+ @block = block
43
+ @enabled = true
44
+ post_add_content if @block.nil?
45
+ end
46
+
47
+ def post_add_content
48
+ super
49
+ if @parent_proxy.nil? && AreaProxy.current_area_draw_params
50
+ draw(AreaProxy.current_area_draw_params)
51
+ destroy
52
+ end
53
+ end
54
+
55
+ def draw(area_draw_params)
56
+ build_control
57
+ children.dup.each {|child| child.draw(area_draw_params)}
58
+ ::LibUI.draw_path_end(@libui)
59
+ ::LibUI.draw_fill(area_draw_params[:context], @libui, fill_draw_brush.to_ptr) unless fill.empty?
60
+ ::LibUI.draw_stroke(area_draw_params[:context], @libui, stroke_draw_brush, draw_stroke_params) unless stroke.empty?
61
+ ::LibUI.draw_free_path(@libui)
62
+ end
63
+
64
+ def draw_fill_mode
65
+ @args[0].is_a?(Integer) ? @args[0] : @args[0].to_s == 'alternate' ? 1 : 0
66
+ end
67
+
68
+ def fill(*args)
69
+ args = args.first if args.size == 1 && (args.first.is_a?(Array) || args.first.is_a?(Hash) || args.first.is_a?(String) || args.first.is_a?(Symbol))
70
+ if args.empty?
71
+ @fill ||= {}
72
+ else
73
+ @fill = Glimmer::LibUI.interpret_color(args)
74
+ @fill[:a] = 1.0 if @fill.is_a?(Hash) && @fill[:a].nil?
75
+ @parent_proxy&.queue_redraw_all
76
+ end
77
+ @fill.tap do
78
+ @fill_observer ||= Glimmer::DataBinding::Observer.proc do
79
+ @parent_proxy&.queue_redraw_all
80
+ end
81
+ @fill_observer.observe(@fill)
82
+ end
83
+ end
84
+ alias fill= fill
85
+ alias set_fill fill
86
+
87
+ def fill_draw_brush
88
+ @fill_draw_brush ||= ::LibUI::FFI::DrawBrush.malloc
89
+ init_draw_brush(@fill_draw_brush, @fill)
90
+ @fill_draw_brush
91
+ end
92
+
93
+ def stroke(*args)
94
+ args = args.first if args.size == 1 && (args.first.is_a?(Array) || args.first.is_a?(Hash) || args.first.is_a?(String) || args.first.is_a?(Symbol))
95
+ if args.empty?
96
+ @stroke ||= {}
97
+ else
98
+ @stroke = Glimmer::LibUI.interpret_color(args)
99
+ @stroke[:a] = 1.0 if @stroke.is_a?(Hash) && @stroke[:a].nil?
100
+ @parent_proxy&.queue_redraw_all
101
+ end
102
+ @stroke.tap do
103
+ @stroke_observer ||= Glimmer::DataBinding::Observer.proc do
104
+ @parent_proxy&.queue_redraw_all
105
+ end
106
+ @stroke_observer.observe(@stroke)
107
+ end
108
+ end
109
+ alias stroke= stroke
110
+ alias set_stroke stroke
111
+
112
+ def stroke_draw_brush
113
+ @stroke_draw_brush ||= ::LibUI::FFI::DrawBrush.malloc
114
+ init_draw_brush(@stroke_draw_brush, @stroke)
115
+ @stroke_draw_brush
116
+ end
117
+
118
+ def draw_stroke_params
119
+ @draw_stroke_params ||= ::LibUI::FFI::DrawStrokeParams.malloc
120
+ @draw_stroke_params.Cap = @stroke[:cap] || 0 # flat
121
+ @draw_stroke_params.Join = @stroke[:join] || 0 # miter
122
+ @draw_stroke_params.Thickness = @stroke[:thickness] || 1
123
+ @draw_stroke_params.MiterLimit = @stroke[:miter_limit] || 10 # DEFAULT_MITER_LIMIT
124
+ @draw_stroke_params_dashes ||= Fiddle::Pointer.malloc(8)
125
+ @draw_stroke_params.Dashes = @draw_stroke_params_dashes
126
+ @draw_stroke_params.NumDashes = @stroke[:num_dashes] || 0 # TODO reimplement this line correctly (perhaps no need to pass num dashes, yet dashes themselves and use their count here)
127
+ @draw_stroke_params.DashPhase = @stroke[:dash_phase] || 0
128
+ @draw_stroke_params
129
+ end
130
+
131
+ def destroy
132
+ @parent_proxy&.children&.delete(self)
133
+ ControlProxy.control_proxies.delete(self)
134
+ end
135
+
136
+ def redraw
137
+ @parent_proxy&.queue_redraw_all
138
+ end
139
+
140
+ private
141
+
142
+ def build_control
143
+ @libui = ::LibUI.draw_new_path(draw_fill_mode)
144
+ end
145
+
146
+ def init_draw_brush(draw_brush, draw_brush_args)
147
+ case draw_brush_args[:type]
148
+ when Integer
149
+ draw_brush.Type = draw_brush_args[:type]
150
+ when :solid, 'solid'
151
+ draw_brush.Type = 0
152
+ when :linear_gradient, 'linear_gradient'
153
+ draw_brush.Type = 1
154
+ when :radial_gradient, 'radial_gradient'
155
+ draw_brush.Type = 2
156
+ when :image, 'image'
157
+ draw_brush.Type = 3
158
+ else
159
+ draw_brush.Type = 0
160
+ end
161
+ draw_brush.R = (draw_brush_args[:r] || draw_brush_args[:red]).to_f / 255.0
162
+ draw_brush.G = (draw_brush_args[:g] || draw_brush_args[:green]).to_f / 255.0
163
+ draw_brush.B = (draw_brush_args[:b] || draw_brush_args[:blue]).to_f / 255.0
164
+ draw_brush.A = (draw_brush_args[:a] || draw_brush_args[:alpha])
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,45 @@
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 radio buttons objects
28
+ #
29
+ # Follows the Proxy Design Pattern
30
+ class RadioButtonsProxy < ControlProxy
31
+ def items(*values)
32
+ values = values.first if values.first.is_a?(Array)
33
+ if values.empty?
34
+ @values
35
+ else
36
+ @values = values
37
+ @values.each { |value| append value }
38
+ end
39
+ end
40
+ alias set_items items
41
+ alias items= items
42
+ end
43
+ end
44
+ end
45
+ end