wxruby3 1.1.1 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '079f38ae02dfcba5a96738f73c678e0d9a5396920739cb370c47d79b6bb81adf'
4
- data.tar.gz: 510b7637e541b981deb048d4b0aa3898ea8152900b570ead984dcb9c6daee534
3
+ metadata.gz: c44502717c4bc43863f96c826432224a7cc81063d3768dcffa8a92c7bbead181
4
+ data.tar.gz: c002fc5f501cba71fa127585102916daca951424e986a265e740e7ca9cbc6e9e
5
5
  SHA512:
6
- metadata.gz: 4b3c4ad6e1c31636d658cd9f0d986c57caf6bc6f72af19af449b7d371c3b9af45b229533f1ae3593b7c23b2b29bf74dfaac8e88740fcca0699dc093f40b29d8f
7
- data.tar.gz: 827044bb4256d7afc741e77209096cd527f2c77688c0b619fd72cf1ad0bf03992de4e3c60ec93e17795835345b15932ae2773381de85177d941d8b205ab120f7
6
+ metadata.gz: bdd8149612a7ef5637362c5e27a821afe3cd6f1f03c92c00529ab3df12e427a73af97aa1ffa6f89281e7ff259861aed925f3b737ff49bc7564f92b6369b97550
7
+ data.tar.gz: dcce12022c263d4b5955b2417ab415460f38e5d0418e0c53d64d677c9c9352de5e1ff3b53a7318066b8e8c0b4ff47bf6fefb27ae194e0955801aac0edf99cd59
data/lib/wx/core/enum.rb CHANGED
@@ -8,6 +8,23 @@
8
8
 
9
9
  class Wx::Enum
10
10
 
11
+ class << self
12
+
13
+ def enumerators
14
+ self.constants(false).inject({}) do |tbl, cn|
15
+ cv = self.const_get(cn)
16
+ tbl[cv.to_i] = cn if self === cv
17
+ tbl
18
+ end
19
+ end
20
+
21
+ def [](enum_name)
22
+ return self.const_get(enum_name) if self.const_defined?(enum_name)
23
+ nil
24
+ end
25
+
26
+ end
27
+
11
28
  def |(other)
12
29
  if other.instance_of?(self.class)
13
30
  self.class.new(to_i | other.to_i)
@@ -52,10 +69,10 @@ class Wx::Enum
52
69
  return '' if to_i == 0
53
70
  enums = []
54
71
  mask = to_i
55
- self.class.values.each_value do |enum|
56
- if enum != 0 && mask.allbits?(enum)
57
- enums << enum.to_s
58
- mask &= ~enum
72
+ self.class.enumerators.each_pair do |eval, ename|
73
+ if eval != 0 && mask.allbits?(eval)
74
+ enums << ename
75
+ mask &= ~eval
59
76
  break if mask == 0
60
77
  end
61
78
  end
@@ -65,7 +82,7 @@ class Wx::Enum
65
82
  private :bitmask_to_s
66
83
 
67
84
  def to_s
68
- self.class.values.has_key?(to_i) ? "#{self.class.name}::#{self.class.names_by_value[self]}" : bitmask_to_s
85
+ self.class.enumerators.has_key?(to_i) ? "#{self.class.name}::#{self.class.enumerators[to_i]}" : bitmask_to_s
69
86
  end
70
87
 
71
88
  end
@@ -13,20 +13,14 @@ module Wx
13
13
  # Allow this to be called with keyword parameters, and avoid
14
14
  # segfaults on OS X with bad params
15
15
  wx_about_box = self.instance_method(:about_box)
16
- define_method(:about_box) do | info |
17
- # If AboutDialogInfo has no version, it segfaults on OS X 10.5
18
- no_version = ArgumentError.new("Must supply a version for AboutDialog")
16
+ define_method(:about_box) do | info, parent=nil |
19
17
  case info
20
18
  when Wx::AboutDialogInfo
21
- unless info.has_version
22
- Kernel.raise no_version
23
- end
24
-
25
19
  ab_info = info
26
20
  when Hash
27
21
  ab_info = Wx::AboutDialogInfo.new
28
22
  ab_info.name = info[:name] || 'wxRuby application'
29
- ab_info.version = info[:version] || Kernel.raise(no_version)
23
+ ab_info.version = info[:version] if info[:version]
30
24
 
31
25
  ab_info.description = info[:description] || ''
32
26
  ab_info.copyright = info[:copyright] || ''
@@ -36,7 +30,7 @@ module Wx
36
30
  ab_info.artists = info[:artists] || []
37
31
  ab_info.translators = info[:translators] || []
38
32
  if info.key?(:website)
39
- ab_info.set_website(*info[:website])
33
+ ab_info.set_web_site(*info[:website])
40
34
  end
41
35
  if info.key?(:icon)
42
36
  ab_info.icon = info[:icon]
@@ -46,7 +40,7 @@ module Wx
46
40
  Kernel.raise ArgumentError,
47
41
  "Can't use #{info.inspect} for AboutDialogInfo"
48
42
  end
49
- wx_about_box.bind(self).call(ab_info)
43
+ wx_about_box.bind(self).call(ab_info, parent)
50
44
  end
51
45
  end
52
46
  end
@@ -0,0 +1,18 @@
1
+ # :stopdoc:
2
+ # This file is automatically generated by the WXRuby3 documentation
3
+ # generator. Do not alter this file.
4
+ # :startdoc:
5
+
6
+
7
+ module Wx
8
+
9
+ class GenericAnimationCtrl < AnimationCtrl
10
+
11
+ # This override of {Wx::AnimationCtrl#play} lets you specify if the animation must loop or not.
12
+ # @param looped [Boolean] default true
13
+ # @return [Boolean]
14
+ def play(looped = true) end
15
+
16
+ end
17
+
18
+ end
data/lib/wx/doc/enum.rb CHANGED
@@ -100,17 +100,6 @@ module Wx
100
100
  # of a bitwise **or** expression is returned matching the mask.
101
101
  def to_s; end
102
102
 
103
- # Create a new class and associated enum values.
104
- # @param [String,Symbol] name name of new enum class
105
- # @param [Hash] enum_values hash with enum value name and enum integer value pairs
106
- # @return [Class] new enum class
107
- def self.create(name, enum_values) end
108
-
109
- # Returns enum class matching name or nil.
110
- # @param [String,Symbol] name name of enum class
111
- # @return [Class,nil] enum class
112
- def self.[](name) end
113
-
114
103
  end
115
104
 
116
105
  end
@@ -530,7 +530,13 @@ Wx::define_keyword_ctors(Wx::SearchCtrl) do
530
530
  end
531
531
 
532
532
  Wx::define_keyword_ctors(Wx::AnimationCtrl) do
533
- wx_ctor_params :id, :anim
533
+ wx_ctor_params :id, :anim => Wx::NULL_ANIMATION
534
+ wx_ctor_params :pos, :size, :style => Wx::AC_DEFAULT_STYLE
535
+ wx_ctor_params :name => Wx::ANIMATION_CTRL_NAME_STR
536
+ end
537
+
538
+ Wx::define_keyword_ctors(Wx::GenericAnimationCtrl) do
539
+ wx_ctor_params :id, :anim => Wx::NULL_ANIMATION
534
540
  wx_ctor_params :pos, :size, :style => Wx::AC_DEFAULT_STYLE
535
541
  wx_ctor_params :name => Wx::ANIMATION_CTRL_NAME_STR
536
542
  end
data/lib/wx/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  # This software is released under the MIT license.
4
4
 
5
5
  module Wx
6
- WXRUBY_VERSION = '1.1.1'
6
+ WXRUBY_VERSION = '1.2.1'
7
7
  end
@@ -218,10 +218,6 @@ module WXRuby3
218
218
  @ruby_libs << "-L#{RB_CONFIG['libdir']}" # add ruby lib dir
219
219
  # add ruby defined shared ruby lib(s); not any other flags
220
220
  @ruby_libs.concat RB_CONFIG['LIBRUBYARG_SHARED'].split(' ').select { |s| s.start_with?('-l')}
221
-
222
- # maintain minimum compatibility with ABI 3.0.1
223
- @wx_abi_version = [ @wx_version, "3.0.1" ].min
224
- @wx_cppflags << "-DwxABI_VERSION=%s" % @wx_abi_version.tr(".", "0")
225
221
  end
226
222
  end
227
223
  end
@@ -728,10 +728,6 @@ module WXRuby3
728
728
  @wx_version || ''
729
729
  end
730
730
 
731
- def wx_abi_version
732
- @wx_abi_version || ''
733
- end
734
-
735
731
  def mingw?
736
732
  @platform == :mingw
737
733
  end
@@ -16,7 +16,6 @@ static const char * __iv_Enum_sc_enums = "@enums";
16
16
 
17
17
  // instance variables for derived Enum class singleton classes
18
18
  static const char * __iv_enum_klass_values = "@values"; // hash map of all value instances of derived Enum (by integer value)
19
- static const char * __iv_enum_klass_values_by_name = "@values_by_name"; // hash map of all value instances of derived Enum
20
19
  static const char * __iv_enum_klass_name = "@name"; // unscoped name of derived Enum
21
20
 
22
21
  static VALUE wx_Enum_initialize(int argc, VALUE *argv, VALUE self)
@@ -149,55 +148,10 @@ static VALUE wx_Enum_to_int(int argc, VALUE *argv, VALUE self)
149
148
  return rb_iv_get(self, __iv_cEnum_value);
150
149
  }
151
150
 
152
- static VALUE wx_Enum_sc_get_enum_class(int argc, VALUE *argv, VALUE self)
153
- {
154
- if ((argc < 1) || (argc > 1))
155
- {
156
- rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)", argc); return Qnil;
157
- }
158
- return rb_hash_aref(rb_iv_get(cEnum_Singleton, __iv_Enum_sc_enums), rb_to_symbol(argv[0]));
159
- }
160
-
161
- static VALUE wx_Enum_sc_create_enum_class(int argc, VALUE *argv, VALUE self)
162
- {
163
- if ((argc < 2) || (argc > 2))
164
- {
165
- rb_raise(rb_eArgError, "wrong # of arguments(%d for 2)", argc); return Qnil;
166
- }
167
- VALUE enum_name = rb_to_symbol(argv[0]);
168
- if (TYPE(argv[1]) != T_HASH)
169
- {
170
- VALUE str = rb_inspect(argv[1]);
171
- rb_raise(rb_eArgError,
172
- "Invalid enum_values; expected Hash but got %s.",
173
- StringValuePtr(str));
174
- return Qnil;
175
- }
176
- ID id_new = rb_intern("new");
177
- ID id_to_i = rb_intern("to_i");
178
- ID id_const_set = rb_intern("const_set");
179
- VALUE enum_klass = rb_funcall(rb_cClass, id_new, 1, cWxEnum, 0);
180
- VALUE enum_singleton_klass = rb_funcall(enum_klass, rb_intern("singleton_class"), 0, 0);
181
- VALUE enum_values = rb_funcall(argv[1], rb_intern("keys"), 0, 0);
182
- for (int i=0; i<RARRAY_LEN(enum_values) ;++i)
183
- {
184
- VALUE enum_value_name = rb_ary_entry(enum_values, i);
185
- VALUE enum_value_num = rb_funcall(rb_hash_aref(argv[1], enum_value_name), id_to_i, 0, 0);
186
- VALUE enum_value = rb_funcall(enum_klass, id_new, 1, enum_value_num, 0);
187
- rb_funcall(enum_klass, id_const_set, 2, enum_value_name, enum_value, 0);
188
- rb_hash_aset(rb_iv_get(enum_singleton_klass, __iv_enum_klass_values), enum_value_num, enum_value);
189
- rb_hash_aset(rb_iv_get(enum_singleton_klass, __iv_enum_klass_values_by_name), rb_to_symbol(enum_value_name), enum_value);
190
- }
191
- rb_hash_aset(rb_iv_get(cEnum_Singleton, __iv_Enum_sc_enums), enum_name, enum_klass);
192
- return enum_klass;
193
- }
194
-
195
151
  static void wx_setup_Enum_singleton_class()
196
152
  {
197
153
  cEnum_Singleton = rb_funcall(cWxEnum, rb_intern("singleton_class"), 0, 0);
198
154
  rb_iv_set(cEnum_Singleton, __iv_Enum_sc_enums, rb_hash_new());
199
- rb_define_method(cEnum_Singleton, "create", VALUEFUNC(wx_Enum_sc_create_enum_class), -1);
200
- rb_define_singleton_method(cWxEnum, "[]", VALUEFUNC(wx_Enum_sc_get_enum_class), -1);
201
155
  }
202
156
 
203
157
  static void wx_define_Enum_class()
@@ -223,44 +177,11 @@ WXRB_EXPORT_FLAG VALUE wxRuby_GetEnumClass(const char* enum_class_name_cstr)
223
177
  return rb_hash_aref(enum_hash, rb_str_new2(enum_class_name_cstr));
224
178
  }
225
179
 
226
- static VALUE wx_Enum_sc_get_enum_value(int argc, VALUE *argv, VALUE self)
227
- {
228
- if ((argc < 1) || (argc > 1))
229
- {
230
- rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)", argc); return Qnil;
231
- }
232
- VALUE enum_singleton_klass = rb_funcall(self, rb_intern("singleton_class"), 0, 0);
233
- return rb_hash_aref(rb_iv_get(enum_singleton_klass, __iv_enum_klass_values_by_name), rb_to_symbol(argv[0]));
234
- }
235
-
236
- static VALUE wx_Enum_sc_get_enum_values(VALUE self)
237
- {
238
- VALUE enum_singleton_klass = rb_funcall(self, rb_intern("singleton_class"), 0, 0);
239
- return rb_iv_get(enum_singleton_klass, __iv_enum_klass_values);
240
- }
241
-
242
- static VALUE wx_Enum_sc_get_enum_values_by_name(VALUE self)
243
- {
244
- VALUE enum_singleton_klass = rb_funcall(self, rb_intern("singleton_class"), 0, 0);
245
- return rb_iv_get(enum_singleton_klass, __iv_enum_klass_values_by_name);
246
- }
247
-
248
- static VALUE wx_Enum_sc_get_enum_names_by_value(VALUE self)
249
- {
250
- VALUE enum_singleton_klass = rb_funcall(self, rb_intern("singleton_class"), 0, 0);
251
- return rb_funcall(rb_iv_get(enum_singleton_klass, __iv_enum_klass_values_by_name), rb_intern("invert"), 0);
252
- }
253
-
254
180
  WXRB_EXPORT_FLAG VALUE wxRuby_CreateEnumClass(const char* enum_class_name_cstr)
255
181
  {
256
182
  VALUE enum_klass = rb_funcall(rb_cClass, rb_intern("new"), 1, cWxEnum, 0);
257
- rb_define_singleton_method(enum_klass, "[]", VALUEFUNC(wx_Enum_sc_get_enum_value), -1);
258
- rb_define_singleton_method(enum_klass, "values", VALUEFUNC(wx_Enum_sc_get_enum_values), 0);
259
- rb_define_singleton_method(enum_klass, "values_by_name", VALUEFUNC(wx_Enum_sc_get_enum_values_by_name), 0);
260
- rb_define_singleton_method(enum_klass, "names_by_value", VALUEFUNC(wx_Enum_sc_get_enum_names_by_value), 0);
261
183
  VALUE enum_singleton_klass = rb_funcall(enum_klass, rb_intern("singleton_class"), 0, 0);
262
184
  rb_iv_set(enum_singleton_klass, __iv_enum_klass_values, rb_hash_new());
263
- rb_iv_set(enum_singleton_klass, __iv_enum_klass_values_by_name, rb_hash_new());
264
185
  rb_iv_set(enum_singleton_klass, __iv_enum_klass_name, rb_str_new2(enum_class_name_cstr));
265
186
  rb_hash_aset(rb_iv_get(cEnum_Singleton, __iv_Enum_sc_enums),
266
187
  ID2SYM(rb_intern(enum_class_name_cstr)),
@@ -274,7 +195,6 @@ WXRB_EXPORT_FLAG VALUE wxRuby_AddEnumValue(VALUE enum_klass, const char* enum_va
274
195
  VALUE enum_value = rb_funcall(enum_klass, rb_intern("new"), 1, enum_value_num, 0);
275
196
  VALUE enum_singleton_klass = rb_funcall(enum_klass, rb_intern("singleton_class"), 0, 0);
276
197
  rb_hash_aset(rb_iv_get(enum_singleton_klass, __iv_enum_klass_values), enum_value_num, enum_value);
277
- rb_hash_aset(rb_iv_get(enum_singleton_klass, __iv_enum_klass_values_by_name), enum_value_name, enum_value);
278
198
  rb_funcall(enum_klass, rb_intern("const_set"), 2, enum_value_name, enum_value, 0);
279
199
  return enum_value;
280
200
  }
@@ -114,11 +114,20 @@ module WXRuby3
114
114
  directors.select { |dir| Package.full_docs? || !Config.instance.excluded_module?(dir.spec) }
115
115
  end
116
116
 
117
- def director_for_class(class_name)
118
- dir = included_directors.detect { |dir| dir.spec.module_name == class_name || dir.spec.items.include?(class_name) }
119
- subpackages.each_value.detect { |spkg| dir = spkg.director_for_class(class_name) } if dir.nil?
120
- dependencies.detect { |pkgdep| dir = pkgdep.director_for_class(class_name) } if dir.nil?
121
- dir = parent.director_for_class(class_name) if dir.nil? && parent
117
+ def director_for_class(class_name, pkg_stack=[])
118
+ dir = included_directors.detect { |dir| dir.spec.module_name == class_name || dir.spec.items.include?(dir.spec.classdef_name(class_name)) }
119
+ pkg_stack << self
120
+ subpackages.each_value.detect do |spkg|
121
+ unless pkg_stack.include?(spkg) # should never happen
122
+ dir = spkg.director_for_class(class_name, pkg_stack)
123
+ end
124
+ end if dir.nil?
125
+ dependencies.detect do |pkgdep|
126
+ unless pkg_stack.include?(pkgdep)
127
+ dir = pkgdep.director_for_class(class_name)
128
+ end
129
+ end if dir.nil?
130
+ dir = parent.director_for_class(class_name) if dir.nil? && parent && !pkg_stack.include?(parent)
122
131
  dir
123
132
  end
124
133
 
@@ -18,6 +18,9 @@ module WXRuby3
18
18
 
19
19
  def setup
20
20
  super
21
+ spec.items << 'wxGenericAnimationCtrl'
22
+ spec.include 'wx/animate.h'
23
+ spec.include 'wx/generic/animate.h'
21
24
  if Config.instance.wx_version >= '3.3.0'
22
25
  spec.items << 'wxAnimationBundle'
23
26
  spec.ignore 'wxAnimationBundle::GetAll', ignore_doc: false
@@ -38,6 +41,8 @@ module WXRuby3
38
41
  map_out code: ''
39
42
  end
40
43
  end
44
+ spec.ignore 'wxGenericAnimationCtrl::Play'
45
+ spec.extend_interface 'wxGenericAnimationCtrl', 'bool Play(bool looped=true)'
41
46
  spec.do_not_generate :variables, :enums, :defines, :functions
42
47
  end
43
48
  end # class AnimationCtrl
@@ -69,7 +69,7 @@ module WXRuby3
69
69
  wxExit
70
70
  }
71
71
  spec.ignore 'wxApp::GetGUIInstance'
72
- unless Config.instance.wx_abi_version >= '3.2.1' || Config.instance.wx_version < '3.2.1'
72
+ unless Config.instance.wx_version < '3.2.1'
73
73
  spec.ignore 'wxApp::GTKAllowDiagnosticsControl'
74
74
  end
75
75
  spec.add_extend_code 'wxApp', <<~__HEREDOC
@@ -43,6 +43,55 @@ module WXRuby3
43
43
  spec.add_swig_code '%markfunc wxDropSource "mark_wxDropSource";',
44
44
  '%markfunc wxDropTarget "mark_wxDropTarget";'
45
45
  spec.extend_interface 'wxDropSource', 'virtual ~wxDropSource()' # correct interface omission
46
+ # make Ruby director and wrappers use custom implementation
47
+ spec.use_class_implementation('wxDropTarget', 'wxRubyDropTarget')
48
+ spec.make_concrete('wxDropTarget')
49
+ spec.no_proxy %w[wxDropTarget::OnData] # prevent director overload; custom impl handles this
50
+ spec.add_header_code <<~__HEREDOC
51
+ class wxRubyDropTarget : public wxDropTarget
52
+ {
53
+ public:
54
+ wxRubyDropTarget(wxDataObject *dataObject = nullptr ) : wxDropTarget(dataObject) {}
55
+
56
+ virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult dflt) override
57
+ {
58
+ static WxRuby_ID on_data_id("on_data");
59
+ wxDragResult c_result = wxDragError;
60
+ VALUE SWIGUNUSED result;
61
+
62
+ VALUE rb_x = INT2NUM(static_cast< int >(x));
63
+ VALUE rb_y = INT2NUM(static_cast< int >(y));
64
+ VALUE rb_dflt = wxRuby_GetEnumValueObject("DragResult", static_cast<int>(dflt));
65
+ if (rb_dflt == Qnil)
66
+ {
67
+ std::cerr << "Unexpected argument error: invalid value for Wx::DragResult in wxDropTarget::OnData [" << dflt << "]" << std::endl;
68
+ }
69
+ else
70
+ {
71
+ VALUE self = SWIG_RubyInstanceFor(this);
72
+ bool ex = false;
73
+ result = wxRuby_Funcall(ex, self, rb_intern("on_data"), 3,rb_x, rb_y, rb_dflt);
74
+ if (ex)
75
+ {
76
+ wxRuby_PrintException(result);
77
+ }
78
+ else
79
+ {
80
+ int eval;
81
+ if (!wxRuby_GetEnumValue("DragResult", result, eval))
82
+ {
83
+ std::cerr << "Type Error: invalid value for Wx::DragResult returned from Wx::DropTarget#on_data" << std::endl;
84
+ }
85
+ else
86
+ {
87
+ c_result = static_cast<wxDragResult>(eval);
88
+ }
89
+ }
90
+ }
91
+ return (wxDragResult) c_result;
92
+ }
93
+ };
94
+ __HEREDOC
46
95
  spec.ignore %w[wxFileDropTarget::OnDrop wxTextDropTarget::OnDrop]
47
96
  spec.no_proxy %w[wxFileDropTarget::OnDrop wxFileDropTarget::OnData]
48
97
  spec.no_proxy %w[wxTextDropTarget::OnDrop wxTextDropTarget::OnData]
@@ -61,6 +61,9 @@ module WXRuby3
61
61
  spec.ignore 'wxGetEmailAddress(char *,int)',
62
62
  'wxGetUserId(char *,int)',
63
63
  'wxGetUserName(char *,int)'
64
+ if Config.instance.wx_version >= '3.3.0'
65
+ spec.ignore_unless('WXMSW', 'wxMSWIsOnSecureScreen')
66
+ end
64
67
  spec.map 'wxMemorySize' => 'Integer' do
65
68
  map_out code: <<~__CODE
66
69
  $result = LL2NUM(wxLongLongNative($1).GetValue());
@@ -703,7 +703,7 @@ module WXRuby3
703
703
  fdoc.puts
704
704
  mod_indent = 0
705
705
  package.all_modules.each do |modnm|
706
- fdoc.iputs("module #{package.fullname}", mod_indent)
706
+ fdoc.iputs("module #{modnm}", mod_indent)
707
707
  fdoc.puts
708
708
  mod_indent += 1
709
709
  end
@@ -628,7 +628,12 @@ module WXRuby3
628
628
  end
629
629
 
630
630
  def run
631
- member_map = collect_methods rescue $!
631
+ begin
632
+ member_map = collect_methods
633
+ rescue Exception
634
+ STDERR.puts "#{$!}\n#{$!.backtrace.join("\n")}"
635
+ exit(1)
636
+ end
632
637
  return if member_map.empty?
633
638
 
634
639
  # create re match list for class names
@@ -0,0 +1,284 @@
1
+ # Copyright (c) 2023 M.J.N. Corino, The Netherlands
2
+ #
3
+ # This software is released under the MIT license.
4
+ #
5
+ # Adapted for wxRuby from wxWidgets widgets sample
6
+ # Copyright (c) 2001 Julian Smart
7
+
8
+ require 'wx'
9
+
10
+ module AniTest
11
+
12
+ # Define a new frame
13
+ class MyFrame < Wx::Frame
14
+
15
+ module ID
16
+ include Wx::IDHelper
17
+
18
+ PLAY = self.next_id
19
+ SET_NULL_ANIMATION = self.next_id
20
+ SET_INACTIVE_BITMAP = self.next_id
21
+ SET_NO_AUTO_RESIZE = self.next_id
22
+ SET_BGCOLOR = self.next_id
23
+ USE_GENERIC = self.next_id
24
+
25
+ end
26
+
27
+ def initialize(title)
28
+ super(nil, :title => title, :size => [500, 400], style: Wx::DEFAULT_FRAME_STYLE)
29
+
30
+ set_icon(Wx.Icon(:sample, art_path: File.dirname(__dir__)))
31
+
32
+ # Make a menubar
33
+ file_menu = Wx::Menu.new
34
+
35
+ if Wx.has_feature?(:USE_FILEDLG)
36
+ file_menu.append(Wx::ID_OPEN, "&Open Animation...\tCtrl+O", 'Loads an animation')
37
+ end # USE_FILEDLG
38
+ file_menu.append(Wx::ID_EXIT)
39
+
40
+ play_menu = Wx::Menu.new
41
+ play_menu.append(ID::PLAY, "Play\tCtrl+P", "Play the animation")
42
+ play_menu.append(Wx::ID_STOP, "Stop\tCtrl+S", "Stop the animation")
43
+ play_menu.append_separator
44
+ play_menu.append(ID::SET_NULL_ANIMATION, "Set null animation",
45
+ "Sets the empty animation in the control")
46
+ play_menu.append_check_item(ID::SET_INACTIVE_BITMAP, "Set inactive bitmap",
47
+ "Sets an inactive bitmap for the control")
48
+ play_menu.append_check_item(ID::SET_NO_AUTO_RESIZE, "Set no autoresize",
49
+ "Tells the control not to resize automatically")
50
+ play_menu.append(ID::SET_BGCOLOR, "Set background colour...",
51
+ "Sets the background colour of the control")
52
+
53
+ if Wx::PLATFORM == 'WXGTK'
54
+ play_menu.append_separator
55
+ play_menu.append_check_item(ID::USE_GENERIC, "Use &generic animation\tCtrl+G",
56
+ "Selects whether native or generic version is used")
57
+ end
58
+
59
+ help_menu = Wx::Menu.new
60
+ help_menu.append(Wx::ID_ABOUT)
61
+
62
+ menu_bar = Wx::MenuBar.new
63
+
64
+ menu_bar.append(file_menu, "&File")
65
+ menu_bar.append(play_menu, "&Animation")
66
+ menu_bar.append(help_menu, "&Help")
67
+
68
+ # Associate the menu bar with this frame
69
+ set_menu_bar(menu_bar)
70
+
71
+ if Wx.has_feature?(:USE_STATUSBAR)
72
+ create_status_bar
73
+ end # USE_STATUSBAR
74
+
75
+ # use a Wx::BoxSizer otherwise Wx::Frame will automatically
76
+ # resize the @animation_ctrl to fill its client area on
77
+ # user resizes
78
+ sz = Wx::VBoxSizer.new
79
+ sz.add(Wx::StaticText.new(self, Wx::ID_ANY, "wxAnimationCtrl:"),
80
+ Wx::SizerFlags.new.centre.border)
81
+
82
+ @animation_ctrl = Wx::AnimationCtrl.new(self, Wx::ID_ANY)
83
+
84
+ animations = Wx::AnimationBundle.new
85
+
86
+ throbber = Wx::Animation.new(File.join(__dir__, 'throbber.gif'))
87
+ animations.add(throbber) if throbber.ok?
88
+
89
+ throbber2x = Wx::Animation.new(File.join(__dir__, 'throbber_2x.gif'))
90
+ animations.add(throbber2x) if throbber2x.ok?
91
+
92
+ if animations.ok?
93
+ @animation_ctrl.set_animation(animations)
94
+ @animation_ctrl.play
95
+ end
96
+
97
+ sz.add(@animation_ctrl, Wx::SizerFlags.new.centre.border)
98
+ set_sizer(sz)
99
+
100
+ evt_menu(ID::PLAY, :on_play)
101
+ evt_menu(ID::SET_NULL_ANIMATION, :on_set_null_animation)
102
+ evt_menu(ID::SET_INACTIVE_BITMAP, :on_set_inactive_bitmap)
103
+ evt_menu(ID::SET_NO_AUTO_RESIZE, :on_set_no_auto_resize)
104
+ evt_menu(ID::SET_BGCOLOR, :on_set_bg_color)
105
+ if Wx::PLATFORM == 'WXGTK'
106
+ evt_menu(ID::USE_GENERIC, :on_use_generic)
107
+ end
108
+
109
+ evt_menu(Wx::ID_STOP, :on_stop)
110
+ evt_menu(Wx::ID_ABOUT, :on_about)
111
+ evt_menu(Wx::ID_EXIT, :on_quit)
112
+ if Wx.has_feature?(:USE_FILEDLG)
113
+ evt_menu(Wx::ID_OPEN, :on_open)
114
+ end # USE_FILEDLG
115
+
116
+ evt_size { self.layout }
117
+ evt_update_ui(Wx::ID_ANY, :on_update_ui)
118
+ end
119
+
120
+ def on_about(_event)
121
+ info = Wx::AboutDialogInfo.new
122
+ info.set_name("Wx::AnimationCtrl and Wx::Animation sample")
123
+ info.set_description("This sample program demonstrates the usage of Wx::AnimationCtrl")
124
+ info.set_copyright("(C) 2024 Martin Corino (original (C) 2006 Julian Smart)")
125
+
126
+ info.add_developer("Martin Corino")
127
+
128
+ Wx.about_box(info, self)
129
+ end
130
+
131
+ def on_quit(_event)
132
+ close
133
+ end
134
+
135
+ def on_play(_event)
136
+ Wx.log_error('Invalid animation') unless @animation_ctrl.play
137
+ end
138
+
139
+ def on_set_null_animation(_event)
140
+ @animation_ctrl.set_animation(Wx::AnimationBundle.new(Wx::NULL_ANIMATION))
141
+ end
142
+
143
+ def on_set_inactive_bitmap(event)
144
+ if event.checked?
145
+ # set a dummy bitmap as the inactive bitmap
146
+ bmp = Wx::ArtProvider.get_bitmap(Wx::ART_MISSING_IMAGE)
147
+ @animation_ctrl.set_inactive_bitmap(bmp)
148
+ else
149
+ @animation_ctrl.set_inactive_bitmap(Wx::NULL_BITMAP)
150
+ end
151
+ end
152
+
153
+ def on_set_no_auto_resize(event)
154
+ # recreate the control with the new flag if necessary
155
+ style = Wx::AC_DEFAULT_STYLE | (event.checked? ? Wx::AC_NO_AUTORESIZE : 0)
156
+
157
+ recreate_animation(style) if style != @animation_ctrl.get_window_style
158
+ end
159
+
160
+ def on_set_bg_color(_event)
161
+ clr = Wx.get_colour_from_user(self, @animation_ctrl.get_background_colour,
162
+ 'Choose the background colour')
163
+
164
+ @animation_ctrl.set_background_colour(clr) if clr.ok?
165
+ end
166
+
167
+ def on_stop(_event)
168
+ @animation_ctrl.stop
169
+ end
170
+
171
+ if Wx::PLATFORM == 'WXGTK'
172
+
173
+ def on_use_generic(_event)
174
+ recreate_animation(@animation_ctrl.get_window_style)
175
+ end
176
+
177
+ end
178
+
179
+ def on_update_ui(_event)
180
+ get_menu_bar.find_item(Wx::ID_STOP).first.enable(@animation_ctrl.playing?)
181
+ get_menu_bar.find_item(ID::PLAY).first.enable(!@animation_ctrl.playing?)
182
+ get_menu_bar.find_item(ID::SET_NO_AUTO_RESIZE).first.enable(!@animation_ctrl.playing?)
183
+ end
184
+
185
+ if Wx.has_feature?(:USE_FILEDLG)
186
+
187
+ def on_open(_event)
188
+ Wx.FileDialog(self, "Please choose an animation", '', '', '*.gif;*.ani', Wx::FD_OPEN) do |dialog|
189
+ if dialog.show_modal == Wx::ID_OK
190
+ filename = dialog.get_path
191
+
192
+ temp = @animation_ctrl.create_animation
193
+ unless temp.load_file(filename)
194
+ Wx.log_error("Sorry, this animation is not a valid format for Wx::Animation.")
195
+ return
196
+ end
197
+
198
+ @animation_ctrl.set_animation(Wx::AnimationBundle.new(temp))
199
+ @animation_ctrl.play
200
+
201
+ get_sizer.layout
202
+ end
203
+ end
204
+ end
205
+
206
+ end # USE_FILEDLG
207
+
208
+ private
209
+
210
+ def recreate_animation(style)
211
+ # save status of the control before destroying it
212
+
213
+ # We can't reuse the existing animation if we're switching from native to
214
+ # generic control or vice versa (as indicated by the absence of change in
215
+ # the style, which is the only other reason we can get called). We could
216
+ # save the file name we loaded it from and recreate it, of course, but for
217
+ # now, for simplicity, just start without any animation in this case.
218
+ curr = Wx::Animation.new
219
+ if Wx::PLATFORM == 'WXGTK'
220
+ curr = @animation_ctrl.get_animation if style != @animation_ctrl.get_window_style
221
+ end
222
+
223
+ inactive = @animation_ctrl.get_inactive_bitmap
224
+ bg = @animation_ctrl.get_background_colour
225
+
226
+ # destroy & rebuild
227
+ old = @animation_ctrl
228
+
229
+ if Wx::PLATFORM == 'WXGTK' && get_menu_bar.is_checked(ID::USE_GENERIC)
230
+ @animation_ctrl = Wx::GenericAnimationCtrl.new(self, Wx::ID_ANY, curr, style: style)
231
+ else
232
+ @animation_ctrl = Wx::AnimationCtrl.new(self, Wx::ID_ANY, curr, style: style)
233
+ end
234
+
235
+ get_sizer.replace(old, @animation_ctrl)
236
+
237
+ # load old status in new control
238
+ @animation_ctrl.set_inactive_bitmap(inactive)
239
+ @animation_ctrl.set_background_colour(bg)
240
+
241
+ get_sizer.layout
242
+ end
243
+
244
+ end
245
+
246
+
247
+ class App < Wx::App
248
+
249
+ # this one is called on application startup and is a good place for the app
250
+ # initialization (doing it here and not in the ctor allows to have an error
251
+ # return: if OnInit() returns false, the application terminates)
252
+ def on_init
253
+ # Create the main frame window
254
+ frame = MyFrame.new('Animation Demo')
255
+ frame.show
256
+ end
257
+
258
+ end
259
+
260
+ end
261
+
262
+ module AniTestSample
263
+
264
+ include WxRuby::Sample if defined? WxRuby::Sample
265
+
266
+ def self.describe
267
+ { file: __FILE__,
268
+ summary: 'wxRuby AnimationCtrl example.',
269
+ description: <<~__DESC
270
+ A Ruby port of the wxWidgets anitest sample which showcases
271
+ animation controls.
272
+ __DESC
273
+ }
274
+ end
275
+
276
+ def self.run
277
+ execute(__FILE__)
278
+ end
279
+
280
+ if $0 == __FILE__
281
+ AniTest::App.run
282
+ end
283
+
284
+ end
Binary file
Binary file
Binary file
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wxruby3
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Corino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-13 00:00:00.000000000 Z
11
+ date: 2024-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -239,6 +239,7 @@ files:
239
239
  - lib/wx/core/window.rb
240
240
  - lib/wx/core/window_update_locker.rb
241
241
  - lib/wx/core/xmlresource.rb
242
+ - lib/wx/doc/animation_ctrl.rb
242
243
  - lib/wx/doc/app.rb
243
244
  - lib/wx/doc/array_ext.rb
244
245
  - lib/wx/doc/art_locator.rb
@@ -826,6 +827,11 @@ files:
826
827
  - rakelib/yard/yard-relative_markdown_links.rb
827
828
  - rakelib/yard/yard/relative_markdown_links.rb
828
829
  - rakelib/yard/yard/relative_markdown_links/version.rb
830
+ - samples/animate/anitest.rb
831
+ - samples/animate/hourglass.ani
832
+ - samples/animate/throbber.gif
833
+ - samples/animate/throbber_2x.gif
834
+ - samples/animate/tn_anitest.png
829
835
  - samples/art/wxruby-128x128.png
830
836
  - samples/art/wxruby-256x256.png
831
837
  - samples/art/wxruby-64x64.png
@@ -1191,7 +1197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1191
1197
  - !ruby/object:Gem::Version
1192
1198
  version: '0'
1193
1199
  requirements: []
1194
- rubygems_version: 3.5.11
1200
+ rubygems_version: 3.5.16
1195
1201
  signing_key:
1196
1202
  specification_version: 4
1197
1203
  summary: wxWidgets extension for Ruby