glimmer-dsl-libui 0.2.17 → 0.2.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -109,6 +109,31 @@ module Glimmer
109
109
  queue_redraw_all
110
110
  end
111
111
 
112
+ def request_auto_redraw
113
+ # TODO implement functionality to delay queuing area redraws until post_add_content has been called (area definition is done). Maybe offer an option to enable redrawing before area is closed too.
114
+ queue_redraw_all if auto_redraw_enabled?
115
+ end
116
+
117
+ def auto_redraw_enabled(value = nil)
118
+ if value.nil?
119
+ @auto_redraw_enabled = true if @auto_redraw_enabled.nil?
120
+ @auto_redraw_enabled
121
+ else
122
+ @auto_redraw_enabled = !!value
123
+ end
124
+ end
125
+ alias auto_redraw_enabled? auto_redraw_enabled
126
+ alias auto_redraw_enabled= auto_redraw_enabled
127
+ alias set_auto_redraw_enabled auto_redraw_enabled
128
+
129
+ def pause_auto_redraw
130
+ self.auto_redraw_enabled = false
131
+ end
132
+
133
+ def resume_auto_redraw
134
+ self.auto_redraw_enabled = true
135
+ end
136
+
112
137
  private
113
138
 
114
139
  def build_control
@@ -68,12 +68,16 @@ module Glimmer
68
68
  if args.empty?
69
69
  @fill ||= {}
70
70
  else
71
- @fill = Glimmer::LibUI.interpret_color(args)
72
- @parent_proxy&.queue_redraw_all
71
+ new_color = Glimmer::LibUI.interpret_color(args)
72
+ if new_color != @fill
73
+ @fill_observer&.unobserve(@fill) if @fill
74
+ @fill = new_color
75
+ request_auto_redraw
76
+ end
73
77
  end
74
78
  @fill.tap do
75
79
  @fill_observer ||= Glimmer::DataBinding::Observer.proc do
76
- @parent_proxy&.queue_redraw_all
80
+ request_auto_redraw
77
81
  end
78
82
  @fill_observer.observe(@fill)
79
83
  end
@@ -92,12 +96,16 @@ module Glimmer
92
96
  if args.empty?
93
97
  @stroke ||= {}
94
98
  else
95
- @stroke = Glimmer::LibUI.interpret_color(args)
96
- @parent_proxy&.queue_redraw_all
99
+ new_color = Glimmer::LibUI.interpret_color(args)
100
+ if new_color != @stroke
101
+ @stroke_observer&.unobserve(@stroke) if @stroke
102
+ @stroke = Glimmer::LibUI.interpret_color(args)
103
+ request_auto_redraw
104
+ end
97
105
  end
98
106
  @stroke.tap do
99
107
  @stroke_observer ||= Glimmer::DataBinding::Observer.proc do
100
- @parent_proxy&.queue_redraw_all
108
+ request_auto_redraw
101
109
  end
102
110
  @stroke_observer.observe(@stroke)
103
111
  end
@@ -137,7 +145,11 @@ module Glimmer
137
145
  end
138
146
 
139
147
  def redraw
140
- @parent_proxy&.queue_redraw_all
148
+ @parent_proxy&.redraw
149
+ end
150
+
151
+ def request_auto_redraw
152
+ @parent_proxy&.request_auto_redraw
141
153
  end
142
154
 
143
155
  private
@@ -78,6 +78,7 @@ module Glimmer
78
78
  when 'on_destroy'
79
79
  on_destroy(&listener)
80
80
  else
81
+ default_behavior_listener = nil
81
82
  if listener_name == 'on_closing'
82
83
  default_behavior_listener = Proc.new do
83
84
  return_value = listener.call(self)
@@ -90,9 +91,45 @@ module Glimmer
90
91
  end
91
92
  end
92
93
  end
93
- super(listener_name, &default_behavior_listener)
94
+ super(listener_name, &(default_behavior_listener || listener))
94
95
  end
95
96
  end
97
+
98
+ def content_size(*args)
99
+ if args.empty?
100
+ width = Fiddle::Pointer.malloc(8)
101
+ height = Fiddle::Pointer.malloc(8)
102
+ ::LibUI.window_content_size(@libui, width, height)
103
+ width = width[0, 8].unpack1('i')
104
+ height = height[0, 8].unpack1('i')
105
+ [width, height]
106
+ else
107
+ args = args.first if args.size == 1 && args.first.is_a?(Array)
108
+ super
109
+ @width = args[0]
110
+ @height = args[1]
111
+ end
112
+ end
113
+ alias content_size= content_size
114
+ alias set_content_size content_size
115
+
116
+ def resizable(value = nil)
117
+ if value.nil?
118
+ @resizable = true if @resizable.nil?
119
+ @resizable
120
+ else
121
+ @resizable = value
122
+ if !@resizable && !@resizable_listener_registered
123
+ handle_listener('on_content_size_changed') do
124
+ set_content_size(@width, @height) unless @resizable
125
+ end
126
+ @resizable_listener_registered = true
127
+ end
128
+ end
129
+ end
130
+ alias resizable? resizable
131
+ alias resizable= resizable
132
+ alias set_resizable resizable
96
133
 
97
134
  private
98
135
 
@@ -107,6 +144,8 @@ module Glimmer
107
144
  construction_args[2] = DEFAULT_HEIGHT if construction_args.size == 2
108
145
  construction_args[3] = DEFAULT_HAS_MENUBAR if construction_args.size == 3
109
146
  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))
147
+ @width = construction_args[1]
148
+ @height = construction_args[2]
110
149
  @libui = ControlProxy.new_control(@keyword, construction_args)
111
150
  @libui.tap do
112
151
  handle_listener('on_closing') do
@@ -41,8 +41,10 @@ module Glimmer
41
41
  if value.nil?
42
42
  @closed
43
43
  else
44
- @closed = value
45
- area_proxy&.queue_redraw_all
44
+ if !!value != !!@closed
45
+ @closed = value
46
+ request_auto_redraw
47
+ end
46
48
  end
47
49
  end
48
50
  alias closed= closed
@@ -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/shape'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ class Shape
27
+ class Polybezier < Shape
28
+ parameters :point_array
29
+ parameter_defaults []
30
+
31
+ def draw(area_draw_params)
32
+ alternating_x_y_array = point_array.to_a.compact.flatten
33
+ unless alternating_x_y_array.empty?
34
+ ::LibUI.draw_path_new_figure(path_proxy.libui, alternating_x_y_array[0], alternating_x_y_array[1])
35
+ ((alternating_x_y_array.size - 2) / 6).times do |n|
36
+ point_alternating_x_y_index = n * 6
37
+ ::LibUI.draw_path_bezier_to(path_proxy.libui, alternating_x_y_array[point_alternating_x_y_index + 2], alternating_x_y_array[point_alternating_x_y_index + 3], alternating_x_y_array[point_alternating_x_y_index + 4], alternating_x_y_array[point_alternating_x_y_index + 5], alternating_x_y_array[point_alternating_x_y_index + 6], alternating_x_y_array[point_alternating_x_y_index + 7])
38
+ end
39
+ end
40
+ super
41
+ end
42
+ end
43
+ end
44
+ end
45
+ 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/shape'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ class Shape
27
+ class Polygon < Shape
28
+ parameters :point_array
29
+ parameter_defaults []
30
+
31
+ def draw(area_draw_params)
32
+ alternating_x_y_array = point_array.to_a.compact.flatten
33
+ unless alternating_x_y_array.empty?
34
+ ::LibUI.draw_path_new_figure(path_proxy.libui, alternating_x_y_array[0], alternating_x_y_array[1])
35
+ ((alternating_x_y_array.size - 2) / 2).times do |n|
36
+ point_alternating_x_y_index = n * 2
37
+ ::LibUI.draw_path_line_to(path_proxy.libui, alternating_x_y_array[point_alternating_x_y_index + 2], alternating_x_y_array[point_alternating_x_y_index + 3])
38
+ end
39
+ ::LibUI.draw_path_close_figure(path_proxy.libui)
40
+ end
41
+ super
42
+ end
43
+ end
44
+ end
45
+ end
46
+ 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/shape'
23
+
24
+ module Glimmer
25
+ module LibUI
26
+ class Shape
27
+ class Polyline < Shape
28
+ parameters :point_array
29
+ parameter_defaults []
30
+
31
+ def draw(area_draw_params)
32
+ alternating_x_y_array = point_array.to_a.compact.flatten
33
+ unless alternating_x_y_array.empty?
34
+ ::LibUI.draw_path_new_figure(path_proxy.libui, alternating_x_y_array[0], alternating_x_y_array[1])
35
+ ((alternating_x_y_array.size - 2) / 2).times do |n|
36
+ point_alternating_x_y_index = n * 2
37
+ ::LibUI.draw_path_line_to(path_proxy.libui, alternating_x_y_array[point_alternating_x_y_index + 2], alternating_x_y_array[point_alternating_x_y_index + 3])
38
+ end
39
+ end
40
+ super
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -87,7 +87,11 @@ module Glimmer
87
87
  end
88
88
 
89
89
  def redraw
90
- area_proxy&.queue_redraw_all
90
+ area_proxy&.auto_redraw
91
+ end
92
+
93
+ def request_auto_redraw
94
+ area_proxy&.request_auto_redraw
91
95
  end
92
96
 
93
97
  def destroy
@@ -113,8 +117,10 @@ module Glimmer
113
117
  method_name = method_name.to_s
114
118
  parameter_index = self.class.parameters.index(method_name_parameter)
115
119
  if method_name.start_with?('set_') || method_name.end_with?('=') || !args.empty?
116
- @args[parameter_index] = args.first
117
- area_proxy&.queue_redraw_all
120
+ if args.first != @args[parameter_index]
121
+ @args[parameter_index] = args.first
122
+ request_auto_redraw
123
+ end
118
124
  else
119
125
  @args[parameter_index]
120
126
  end
data/lib/glimmer/libui.rb CHANGED
@@ -100,11 +100,39 @@ module Glimmer
100
100
  enum_symbol_values(enum_name).keys
101
101
  end
102
102
 
103
+ def enum_names
104
+ [
105
+ :align,
106
+ :at,
107
+ :attribute_type,
108
+ :draw_brush_type,
109
+ :draw_fill_mode,
110
+ :draw_line_cap,
111
+ :draw_line_join,
112
+ :draw_text_align,
113
+ :ext_key,
114
+ :modifier,
115
+ :table_model_column,
116
+ :table_value_type,
117
+ :text_italic,
118
+ :text_stretch,
119
+ :text_weight,
120
+ :underline,
121
+ :underline_color
122
+ ]
123
+ end
124
+
103
125
  # Returns ruby underscored symbols for enum values starting with enum name (camelcase, e.g. 'ext_key')
104
126
  def enum_symbol_values(enum_name)
105
127
  enum_name = enum_name.to_s.underscore.to_sym
106
128
  @enum_symbols ||= {}
107
- @enum_symbols[enum_name] ||= ::LibUI.constants.select { |c| c.to_s.start_with?(enum_name.to_s.camelcase(:upper)) }.map { |c| [c.to_s.underscore.sub("#{enum_name}_", '').to_sym, ::LibUI.const_get(c)] }.to_h
129
+ @enum_symbols[enum_name] ||= ::LibUI.constants.select do |c|
130
+ c.to_s.match(/#{enum_name.to_s.camelcase(:upper)}[A-Z]/)
131
+ end.map do |c|
132
+ [c.to_s.underscore.sub("#{enum_name}_", '').to_sym, ::LibUI.const_get(c)]
133
+ end.reject do |key, value|
134
+ enum_name == :underline && key.to_s.start_with?('color')
135
+ end.to_h
108
136
  end
109
137
 
110
138
  def enum_value_to_symbol(enum_name, enum_value)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-libui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.17
4
+ version: 0.2.21
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-11-03 00:00:00.000000000 Z
11
+ date: 2021-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -257,6 +257,9 @@ files:
257
257
  - examples/tetris/model/game.rb
258
258
  - examples/tetris/model/past_game.rb
259
259
  - examples/tetris/model/tetromino.rb
260
+ - examples/tic_tac_toe.rb
261
+ - examples/tic_tac_toe/board.rb
262
+ - examples/tic_tac_toe/cell.rb
260
263
  - examples/timer.rb
261
264
  - glimmer-dsl-libui.gemspec
262
265
  - icons/glimmer.png
@@ -344,6 +347,9 @@ files:
344
347
  - lib/glimmer/libui/shape/circle.rb
345
348
  - lib/glimmer/libui/shape/figure.rb
346
349
  - lib/glimmer/libui/shape/line.rb
350
+ - lib/glimmer/libui/shape/polybezier.rb
351
+ - lib/glimmer/libui/shape/polygon.rb
352
+ - lib/glimmer/libui/shape/polyline.rb
347
353
  - lib/glimmer/libui/shape/rectangle.rb
348
354
  - lib/glimmer/libui/shape/square.rb
349
355
  - sounds/AlanWalker-Faded.mid