gosu 0.11.3.pre1 → 0.11.3

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
  SHA1:
3
- metadata.gz: 360466fc7c2bfb5e35f8b08e0b3e74a0a3e023e5
4
- data.tar.gz: 0573753156f925308b0e33901fc429103570f905
3
+ metadata.gz: c8b68fbdbd0189edbb8b7cbb01493859fa122a0e
4
+ data.tar.gz: 382fb6970aaa117293d78a1276bcb1c95dfeb6af
5
5
  SHA512:
6
- metadata.gz: e98bb797d0e04dd4cbd5a0e16c618528e7f07d1a0338dd7f8046e27e01ef64e9f1065d23d42f4b24af6236d6c402ebcc16f274409dceded78e996f5298e35b80
7
- data.tar.gz: fde462f9acf20b4bf2648c566d33dbe59797c6e3b7e5bdf1a470cee6dc8856d9c4453790894333887f59cfe6b66d9a1a6c9f149575faed6b5dfa403db4f5aa80
6
+ metadata.gz: 064b805c31aa7ada4b62afd6f6ad7f15c25fc4e6ccccb0f7aed8b298befe04470b3ce142fb5eefb95c3dd35a2483346fd3f075e050696ebbcc053d26fd8b23a4
7
+ data.tar.gz: 328be94282b2f6193f64d7957c020b74de6aeada8a82440889ad2d3743debf94ea0a73e4e95c707ae629385d1e21d42028573b50d984e7c4e40de50148f3f219
data/Gosu/Version.hpp CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  #define GOSU_MAJOR_VERSION 0
6
6
  #define GOSU_MINOR_VERSION 11
7
- #define GOSU_POINT_VERSION 2
7
+ #define GOSU_POINT_VERSION 3
8
8
 
9
9
  namespace Gosu
10
10
  {
data/Gosu/Window.hpp CHANGED
@@ -77,7 +77,9 @@ namespace Gosu
77
77
  virtual bool tick();
78
78
 
79
79
  //! Closes the window if it is currently shown.
80
- void close();
80
+ //! If you do not want the window to close immediately, you should override this method and
81
+ //! only call the base implementation (Window::close) when needed.
82
+ virtual void close();
81
83
 
82
84
  //! Called every update_interval milliseconds while the window is being shown.
83
85
  //! Your application's main game logic goes here.
@@ -0,0 +1,183 @@
1
+ # This whole file is about backward compatibility.
2
+
3
+ # Define some helpers to deprecate code.
4
+ module Gosu
5
+ DEPRECATION_STACKTRACE_LINES = 1
6
+
7
+ # Adapted from RubyGems, but without the date part.
8
+ def self.deprecate(klass, name, repl)
9
+ klass.class_eval {
10
+ old = "_deprecated_#{name}"
11
+ alias_method old, name
12
+ define_method name do |*args, &block|
13
+ Gosu.deprecation_message(self, name, repl)
14
+ send old, *args, &block
15
+ end
16
+ }
17
+ end
18
+
19
+ def self.deprecate_const(name, repl)
20
+ send(:remove_const, name) if const_defined?(name)
21
+
22
+ @@_deprecated_constants ||= {}
23
+ @@_deprecated_constants[name] = repl
24
+ end
25
+
26
+ # Constant deprecation works by undefining the original constant and then re-adding it in
27
+ # const_missing, so that each deprecation warning is only printed once.
28
+ def self.const_missing(const_name)
29
+ if @@_deprecated_constants && repl = @@_deprecated_constants[const_name]
30
+ Gosu.deprecation_message(self, const_name, repl)
31
+ const_get(repl)
32
+ else
33
+ super
34
+ end
35
+ end
36
+
37
+ def self.deprecation_message(klass_or_full_message, name=nil, repl=nil)
38
+ @@_deprecations_shown ||= {}
39
+
40
+ msg = if klass_or_full_message.is_a?(String) and name.nil? and repl.nil?
41
+ [ "DEPRECATION WARNING: #{klass_or_full_message},
42
+ \n#Called from #{caller[1, DEPRECATION_STACKTRACE_LINES]}"
43
+ ]
44
+ else
45
+ # Class method deprecation warnings result in something like this:
46
+ # #<Class:Gosu::Window>::button_id_to_char is deprecated
47
+ # Remove the instance-inspect stuff to make it look a bit better:
48
+ if klass_or_full_message.kind_of?(Module)
49
+ target = "#{klass_or_full_message.to_s.gsub(/#<Class:(.*)>/, '\1')}::"
50
+ else
51
+ "#{klass_or_full_message.class}#"
52
+ end
53
+ [ "DEPRECATION WARNING: #{target}#{name} is deprecated",
54
+ repl == :none ? " with no replacement." : "; use #{repl} instead.",
55
+ "\n#{target}#{name} called from #{Gosu.deprecation_caller.join("\n")}",
56
+ ]
57
+ end
58
+ return if @@_deprecations_shown.has_key?(msg[0])
59
+ @@_deprecations_shown[msg[0]] = true
60
+
61
+ warn "#{msg.join}."
62
+ end
63
+
64
+ # This method removes the deprecation methods themselves from the stacktrace.
65
+ def self.deprecation_caller
66
+ caller.delete_if { |trace_line| trace_line =~ /(deprecat|const_missing)/ }
67
+ .first(DEPRECATION_STACKTRACE_LINES)
68
+ end
69
+ end
70
+
71
+ # No need to pass a Window to Image.
72
+ class Gosu::Image
73
+ alias initialize_without_window initialize
74
+
75
+ def initialize(*args)
76
+ if args[0].is_a? Gosu::Window
77
+ Gosu.deprecation_message("Passing a Window to Image#initialize has been deprecated in Gosu 0.9 and this method now uses an options hash, see https://www.libgosu.org/rdoc/Gosu/Image.html.")
78
+ if args.size == 7
79
+ initialize_without_window args[1], :tileable => args[2], :rect => args[3..-1]
80
+ else
81
+ initialize_without_window args[1], :tileable => args[2]
82
+ end
83
+ else
84
+ initialize_without_window(*args)
85
+ end
86
+ end
87
+
88
+ class << self
89
+ alias from_text_without_window from_text
90
+ end
91
+
92
+ def self.from_text(*args)
93
+ if args.size == 4
94
+ Gosu.deprecation_message("Passing a Window to Image.from_text has been deprecated in Gosu 0.9 and this method now uses an options hash, see https://www.libgosu.org/rdoc/Gosu/Image.html.")
95
+ from_text_without_window(args[1], args[3], :font => args[2])
96
+ elsif args.size == 7
97
+ Gosu.deprecation_message("Passing a Window to Image.from_text has been deprecated in Gosu 0.9 and this method now uses an options hash, see https://www.libgosu.org/rdoc/Gosu/Image.html.")
98
+ from_text_without_window(args[1], args[3], :font => args[2],
99
+ :spacing => args[4], :width => args[5], :align => args[6])
100
+ else
101
+ from_text_without_window(*args)
102
+ end
103
+ end
104
+ end
105
+
106
+ # No need to pass a Window to Sample.
107
+ class Gosu::Sample
108
+ alias initialize_without_window initialize
109
+
110
+ def initialize(*args)
111
+ if args.first.is_a? Gosu::Window
112
+ args.shift
113
+ Gosu.deprecation_message("Passing a Window to Sample#initialize has been deprecated in Gosu 0.7.17.")
114
+ end
115
+ initialize_without_window(*args)
116
+ end
117
+ end
118
+
119
+ # No need to pass a Window to Song.
120
+ class Gosu::Song
121
+ alias initialize_without_window initialize
122
+
123
+ def initialize(*args)
124
+ if args.first.is_a? Gosu::Window
125
+ args.shift
126
+ Gosu.deprecation_message("Passing a Window to Song#initialize has been deprecated in Gosu 0.7.17.")
127
+ end
128
+ initialize_without_window(*args)
129
+ end
130
+ end
131
+
132
+ # Moved some Window-methods to the Gosu::Module
133
+ class Gosu::Window
134
+ # Class methods that have been turned into module methods.
135
+ class << self
136
+ def button_id_to_char(id)
137
+ Gosu.button_id_to_char(id)
138
+ end
139
+
140
+ def char_to_button_id(ch)
141
+ Gosu.char_to_button_id(ch)
142
+ end
143
+ end
144
+
145
+ # Instance methods that have been turned into module methods.
146
+ %w(draw_line draw_triangle draw_quad
147
+ flush gl clip_to record
148
+ transform translate rotate scale
149
+ button_id_to_char char_to_button_id button_down?).each do |method|
150
+ define_method method.to_sym do |*args, &block|
151
+ Gosu.send method, *args, &block
152
+ end
153
+ end
154
+ end
155
+
156
+ # Constants
157
+ module Gosu
158
+ Gosu.deprecate Window, :set_mouse_position, "Window#mouse_x= and Window#mouse_y="
159
+ Gosu.deprecate Font, :draw_rot, "Font#draw with Gosu.rotate"
160
+
161
+ # This was renamed because it's not actually a "copyright notice".
162
+ # (https://en.wikipedia.org/wiki/Copyright_notice)
163
+ deprecate_const :GOSU_COPYRIGHT_NOTICE, :LICENSES
164
+
165
+ module Button; end
166
+
167
+ # Support for KbLeft instead of KB_LEFT and Gp3Button2 instead of GP_3_BUTTON_2.
168
+ Gosu.constants.grep(/^KB_|MS_|GP_/).each do |new_name|
169
+ old_name = case new_name
170
+ when :KB_ISO then "KbISO"
171
+ when :KB_NUMPAD_PLUS then "KbNumpadAdd"
172
+ when :KB_NUMPAD_MINUS then "KbNumpadSubtract"
173
+ when :KB_EQUALS then "KbEqual"
174
+ when :KB_LEFT_BRACKET then "KbBracketLeft"
175
+ when :KB_RIGHT_BRACKET then "KbBracketRight"
176
+ else new_name.to_s.capitalize.gsub(/_(.)/) { $1.upcase }
177
+ end
178
+ Gosu.const_set old_name, new_name
179
+
180
+ # Also import old-style constants into Gosu::Button.
181
+ Gosu::Button.const_set old_name, Gosu.const_get(new_name)
182
+ end
183
+ end
data/lib/gosu/patches.rb CHANGED
@@ -18,79 +18,6 @@ class ::Numeric
18
18
  end
19
19
  end
20
20
 
21
- # Backwards compatibility:
22
- # Support for KbLeft instead of KB_LEFT and Gp3Button2 instead of GP_3_BUTTON_2.
23
- # Also import old-style constants into Gosu::Button.
24
- module Gosu::Button; end
25
- Gosu.constants.grep(/^KB_|MS_|GP_/).each do |c|
26
- old_name = case c
27
- when :KB_ISO then "KbISO"
28
- when :KB_NUMPAD_PLUS then "KbNumpadAdd"
29
- when :KB_NUMPAD_MINUS then "KbNumpadSubtract"
30
- when :KB_EQUALS then "KbEqual"
31
- when :KB_LEFT_BRACKET then "KbBracketLeft"
32
- when :KB_RIGHT_BRACKET then "KbBracketRight"
33
- else c.to_s.capitalize.gsub(/_(.)/) { $1.upcase }
34
- end
35
- Gosu.const_set old_name, Gosu.const_get(c)
36
- Gosu::Button.const_set old_name, Gosu.const_get(c)
37
- end
38
-
39
- # Backwards compatibility:
40
- # Passing a Window to initialize and from_text has been deprecated in Gosu 0.9.
41
- class Gosu::Image
42
- alias initialize_without_window initialize
43
-
44
- def initialize(*args)
45
- if args[0].is_a? Gosu::Window
46
- if args.size == 7
47
- initialize_without_window args[1], :tileable => args[2], :rect => args[3..-1]
48
- else
49
- initialize_without_window args[1], :tileable => args[2]
50
- end
51
- else
52
- initialize_without_window(*args)
53
- end
54
- end
55
-
56
- class << self
57
- alias from_text_without_window from_text
58
- end
59
-
60
- def self.from_text(*args)
61
- if args.size == 4
62
- from_text_without_window(args[1], args[3], :font => args[2])
63
- elsif args.size == 7
64
- from_text_without_window(args[1], args[3], :font => args[2],
65
- :spacing => args[4], :width => args[5], :align => args[6])
66
- else
67
- from_text_without_window(*args)
68
- end
69
- end
70
- end
71
-
72
- # Backwards compatibility:
73
- # Passing a Window to Sample#initialize has been deprecated in Gosu 0.7.17.
74
- class Gosu::Sample
75
- alias initialize_without_window initialize
76
-
77
- def initialize(*args)
78
- args.shift if args.first.is_a? Gosu::Window
79
- initialize_without_window(*args)
80
- end
81
- end
82
-
83
- # Backwards compatibility:
84
- # Passing a Window to Song#initialize has been deprecated in Gosu 0.7.17.
85
- class Gosu::Song
86
- alias initialize_without_window initialize
87
-
88
- def initialize(*args)
89
- args.shift if args.first.is_a? Gosu::Window
90
- initialize_without_window(*args)
91
- end
92
- end
93
-
94
21
  # Color constants.
95
22
  # This is cleaner than having SWIG define them.
96
23
  module Gosu
@@ -119,29 +46,6 @@ module Gosu
119
46
  end
120
47
 
121
48
  class Gosu::Window
122
- # Backwards compatibility:
123
- # Class methods that have been turned into module methods.
124
-
125
- def self.button_id_to_char(id)
126
- Gosu.button_id_to_char(id)
127
- end
128
-
129
- def self.char_to_button_id(ch)
130
- Gosu.char_to_button_id(ch)
131
- end
132
-
133
- # Backwards compatibility:
134
- # Instance methods that have been turned into module methods.
135
-
136
- %w(draw_line draw_triangle draw_quad
137
- flush gl clip_to record
138
- transform translate rotate scale
139
- button_id_to_char char_to_button_id button_down?).each do |method|
140
- define_method method.to_sym do |*args, &block|
141
- Gosu.send method, *args, &block
142
- end
143
- end
144
-
145
49
  # Call Thread.pass every tick, which may or may not be necessary for friendly co-existence with
146
50
  # Ruby's Thread class.
147
51
 
@@ -153,10 +57,6 @@ class Gosu::Window
153
57
  end
154
58
  end
155
59
 
156
- # Backwards compatibility:
157
- # This was renamed, because it's not actually a "copyright notice" (Wikipedia: https://en.wikipedia.org/wiki/Copyright_notice).
158
- Gosu::GOSU_COPYRIGHT_NOTICE = Gosu::LICENSES
159
-
160
60
  # Release OpenAL resources during Ruby's shutdown, not Gosu's.
161
61
  at_exit do
162
62
  begin
@@ -28,7 +28,7 @@ class Gosu::Window
28
28
  # Conveniently turn the return value into a boolean result (for needs_cursor? etc).
29
29
  defined?(@_exception) ? false : !!send(callback, *args)
30
30
  rescue Exception => e
31
- # Exit the message loop naturally, then re-throw
31
+ # Exit the message loop naturally, then re-throw during the next tick.
32
32
  @_exception = e
33
33
  close
34
34
  false
data/lib/gosu.rb CHANGED
@@ -1,19 +1,21 @@
1
- require 'rbconfig'
1
+ require "rbconfig"
2
2
 
3
3
  if RUBY_PLATFORM =~ /mswin$|mingw32|mingw64|win32\-|\-win32/
4
4
  binary_path = File.dirname(__FILE__)
5
5
  # 64-bit builds of Windows use "x64-mingw32" as RUBY_PLATFORM
6
- binary_path += '64' if RUBY_PLATFORM =~ /^x64-/
6
+ binary_path += "64" if RUBY_PLATFORM =~ /^x64-/
7
7
 
8
8
  # Add this gem to the PATH on Windows so that bundled DLLs can be found.
9
- ENV['PATH'] = "#{binary_path};#{ENV['PATH']}"
9
+ # When running through Ocra on Windows, we need to be careful to preserve the ENV["PATH"]
10
+ # encoding (see #385).
11
+ ENV["PATH"] = "#{binary_path.encode ENV["PATH"].encoding};#{ENV["PATH"]}"
10
12
 
11
- # Add the correct directory
12
- RUBY_VERSION =~ /(\d+.\d+)/
13
- $LOAD_PATH.unshift "#{binary_path}/#{$1}"
13
+ # Add the correct lib directory for the current version of Ruby (major.minor).
14
+ $LOAD_PATH.unshift File.join(binary_path, RUBY_VERSION[/^\d+.\d+/])
14
15
  end
15
16
 
16
- require "gosu.#{RbConfig::CONFIG['DLEXT']}"
17
+ require "gosu.#{RbConfig::CONFIG["DLEXT"]}"
17
18
 
18
19
  require "gosu/swig_patches"
19
20
  require "gosu/patches"
21
+ require "gosu/compat"
data/rdoc/gosu.rb CHANGED
@@ -17,10 +17,6 @@ module Gosu
17
17
  # A version string of the form "0.1.2", "0.1.2.3" or "0.1.2pre4".
18
18
  VERSION = :a_string
19
19
 
20
- ##
21
- # @deprecated Use LICENSES instead as it's a more appropriate name
22
- GOSU_COPYRIGHT_NOTICE = :a_string
23
-
24
20
  ##
25
21
  # A block of legal copy that your game is obliged to display somewhere.
26
22
  LICENSES = :a_string
@@ -291,13 +287,6 @@ module Gosu
291
287
  # @see https://github.com/gosu/gosu/wiki/Basic-Concepts#z-ordering Z-ordering explained in the Gosu Wiki
292
288
  def draw_rel(text, x, y, z, rel_x, rel_y, scale_x=1, scale_y=1, color=0xff_ffffff, mode=:default); end
293
289
 
294
- ##
295
- # @deprecated Use {#draw} in conjunction with {Gosu.rotate} instead.
296
- #
297
- # @see #draw
298
- # @see Gosu::Window#rotate
299
- def draw_rot(text, x, y, z, angle, scale_x=1, scale_y=1, color=0xff_ffffff, mode=:default); end
300
-
301
290
  # @!endgroup
302
291
 
303
292
  ##
@@ -778,10 +767,10 @@ module Gosu
778
767
  def tick; end
779
768
 
780
769
  ##
781
- # Tells the window to end the current run loop as soon as possible. Calling this method will not prevent execution of lines after it.
770
+ # Tells the window to end the current run loop as soon as possible.
782
771
  #
783
772
  # @return [void]
784
- def close; end
773
+ def close!; end
785
774
 
786
775
  # @!group Callbacks
787
776
 
@@ -813,6 +802,15 @@ module Gosu
813
802
  # @return [true, false] whether the system cursor should be shown.
814
803
  def needs_cursor?; end
815
804
 
805
+ ##
806
+ # This method is called whenever the user tries to close the window, e.g. by clicking the [x]
807
+ # button in the window's title bar.
808
+ # If you do not want the window to close immediately, you should override this method and
809
+ # call the {#close!} when needed.
810
+ #
811
+ # @return [bool]
812
+ def close; end
813
+
816
814
  ##
817
815
  # This method is called before {#update} if a button is pressed while the window has focus.
818
816
  #
@@ -839,10 +837,6 @@ module Gosu
839
837
  def button_up(id); end
840
838
 
841
839
  # @!endgroup
842
-
843
- ##
844
- # @deprecated Use {#mouse_x=} and {#mouse_y=} instead.
845
- def set_mouse_position(x, y); end
846
840
  end
847
841
 
848
842
  ##
data/src/RubyGosu.cxx CHANGED
@@ -3172,6 +3172,9 @@ SWIGINTERN void Gosu_Window_set_mouse_x(Gosu::Window *self,double x){
3172
3172
  SWIGINTERN void Gosu_Window_set_mouse_y(Gosu::Window *self,double y){
3173
3173
  self->input().set_mouse_position(self->input().mouse_x(), y);
3174
3174
  }
3175
+ SWIGINTERN void Gosu_Window_force_close(Gosu::Window *self){
3176
+ self->Gosu::Window::close();
3177
+ }
3175
3178
 
3176
3179
  // Also mark the TextInput instance alive when the window is being marked.
3177
3180
  static void mark_window(void* window)
@@ -3252,6 +3255,13 @@ bool SwigDirector_Window::tick() {
3252
3255
  }
3253
3256
 
3254
3257
 
3258
+ void SwigDirector_Window::close() {
3259
+ VALUE SWIGUNUSED result;
3260
+
3261
+ result = rb_funcall(swig_get_self(), rb_intern("close"), 0, NULL);
3262
+ }
3263
+
3264
+
3255
3265
  void SwigDirector_Window::update() {
3256
3266
  VALUE SWIGUNUSED result;
3257
3267
 
@@ -9183,6 +9193,8 @@ _wrap_Window_close(int argc, VALUE *argv, VALUE self) {
9183
9193
  Gosu::Window *arg1 = (Gosu::Window *) 0 ;
9184
9194
  void *argp1 = 0 ;
9185
9195
  int res1 = 0 ;
9196
+ Swig::Director *director = 0;
9197
+ bool upcall = false;
9186
9198
 
9187
9199
  if ((argc < 0) || (argc > 0)) {
9188
9200
  rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail;
@@ -9192,13 +9204,24 @@ _wrap_Window_close(int argc, VALUE *argv, VALUE self) {
9192
9204
  SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "Gosu::Window *","close", 1, self ));
9193
9205
  }
9194
9206
  arg1 = reinterpret_cast< Gosu::Window * >(argp1);
9195
- {
9196
- try {
9197
- (arg1)->close();
9198
- }
9199
- catch (const std::exception& e) {
9200
- SWIG_exception(SWIG_RuntimeError, e.what());
9207
+ director = dynamic_cast<Swig::Director *>(arg1);
9208
+ upcall = (director && (director->swig_get_self() == self));
9209
+ try {
9210
+ {
9211
+ try {
9212
+ if (upcall) {
9213
+ (arg1)->Gosu::Window::close();
9214
+ } else {
9215
+ (arg1)->close();
9216
+ }
9217
+ }
9218
+ catch (const std::exception& e) {
9219
+ SWIG_exception(SWIG_RuntimeError, e.what());
9220
+ }
9201
9221
  }
9222
+ } catch (Swig::DirectorException& e) {
9223
+ rb_exc_raise(e.getError());
9224
+ SWIG_fail;
9202
9225
  }
9203
9226
  return Qnil;
9204
9227
  fail:
@@ -9907,6 +9930,34 @@ fail:
9907
9930
  }
9908
9931
 
9909
9932
 
9933
+ SWIGINTERN VALUE
9934
+ _wrap_Window_closeN___(int argc, VALUE *argv, VALUE self) {
9935
+ Gosu::Window *arg1 = (Gosu::Window *) 0 ;
9936
+ void *argp1 = 0 ;
9937
+ int res1 = 0 ;
9938
+
9939
+ if ((argc < 0) || (argc > 0)) {
9940
+ rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail;
9941
+ }
9942
+ res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_Gosu__Window, 0 | 0 );
9943
+ if (!SWIG_IsOK(res1)) {
9944
+ SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "Gosu::Window *","force_close", 1, self ));
9945
+ }
9946
+ arg1 = reinterpret_cast< Gosu::Window * >(argp1);
9947
+ {
9948
+ try {
9949
+ Gosu_Window_force_close(arg1);
9950
+ }
9951
+ catch (const std::exception& e) {
9952
+ SWIG_exception(SWIG_RuntimeError, e.what());
9953
+ }
9954
+ }
9955
+ return Qnil;
9956
+ fail:
9957
+ return Qnil;
9958
+ }
9959
+
9960
+
9910
9961
  SWIGINTERN VALUE
9911
9962
  _wrap_disown_Window(int argc, VALUE *argv, VALUE self) {
9912
9963
  Gosu::Window *arg1 = (Gosu::Window *) 0 ;
@@ -11523,7 +11574,7 @@ SWIGEXPORT void Init_gosu(void) {
11523
11574
  rb_define_const(mGosu, "LICENSES", SWIG_From_std_string(static_cast< std::string >(Gosu::LICENSES)));
11524
11575
  rb_define_const(mGosu, "MAJOR_VERSION", SWIG_From_int(static_cast< int >(0)));
11525
11576
  rb_define_const(mGosu, "MINOR_VERSION", SWIG_From_int(static_cast< int >(11)));
11526
- rb_define_const(mGosu, "POINT_VERSION", SWIG_From_int(static_cast< int >(2)));
11577
+ rb_define_const(mGosu, "POINT_VERSION", SWIG_From_int(static_cast< int >(3)));
11527
11578
  rb_define_module_function(mGosu, "milliseconds", VALUEFUNC(_wrap_milliseconds), -1);
11528
11579
  rb_define_module_function(mGosu, "random", VALUEFUNC(_wrap_random), -1);
11529
11580
  rb_define_module_function(mGosu, "degrees_to_radians", VALUEFUNC(_wrap_degrees_to_radians), -1);
@@ -11944,6 +11995,7 @@ SWIGEXPORT void Init_gosu(void) {
11944
11995
  rb_define_method(SwigClassWindow.klass, "set_mouse_position", VALUEFUNC(_wrap_Window_set_mouse_position), -1);
11945
11996
  rb_define_method(SwigClassWindow.klass, "mouse_x=", VALUEFUNC(_wrap_Window_mouse_xe___), -1);
11946
11997
  rb_define_method(SwigClassWindow.klass, "mouse_y=", VALUEFUNC(_wrap_Window_mouse_ye___), -1);
11998
+ rb_define_method(SwigClassWindow.klass, "close!", VALUEFUNC(_wrap_Window_closeN___), -1);
11947
11999
  SwigClassWindow.mark = (void (*)(void *)) mark_window;
11948
12000
  SwigClassWindow.destroy = (void (*)(void *)) free_Gosu_Window;
11949
12001
  SwigClassWindow.trackObjects = 1;
data/src/RubyGosu.h CHANGED
@@ -32,6 +32,7 @@ public:
32
32
  virtual ~SwigDirector_Window();
33
33
  virtual void show();
34
34
  virtual bool tick();
35
+ virtual void close();
35
36
  virtual void update();
36
37
  virtual void draw();
37
38
  virtual bool needs_redraw() const;
data/src/TextTTFWin.cpp CHANGED
@@ -1,6 +1,7 @@
1
1
  #include <Gosu/Platform.hpp>
2
2
  #if defined(GOSU_IS_WIN)
3
3
 
4
+ #include <Gosu/IO.hpp>
4
5
  #include <Gosu/Utility.hpp>
5
6
  #include <cassert>
6
7
  #include <cstdio>
@@ -56,69 +57,18 @@ struct TT_NAME_RECORD
56
57
 
57
58
  namespace Gosu
58
59
  {
59
- std::string get_name_from_ttf_file(const std::wstring& filename)
60
+ std::string get_name_from_ttf_file(const std::string& filename)
60
61
  {
61
62
  FONT_PROPERTIES_ANSI fp;
62
63
  FONT_PROPERTIES_ANSI * lpFontProps = &fp;
63
64
  memset(lpFontProps, 0, sizeof(FONT_PROPERTIES_ANSI));
64
65
 
65
- HANDLE hFile = INVALID_HANDLE_VALUE;
66
- hFile = ::CreateFile(filename.c_str(),
67
- GENERIC_READ,// | GENERIC_WRITE,
68
- FILE_SHARE_READ,
69
- NULL,
70
- OPEN_EXISTING,
71
- FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
72
- NULL);
73
-
74
- if (hFile == INVALID_HANDLE_VALUE)
75
- {
76
- TRACE(_T("ERROR: failed to open '%s'\n"), wstring_to_utf8(filename).c_str());
77
- TRACE(_T("ERROR: %s failed, GetLastError() = 0x%x\n"), _T("CreateFile"), (int)GetLastError());
78
- return wstring_to_utf8(filename);
79
- }
66
+ Buffer buffer;
67
+ load_file(buffer, filename);
80
68
 
81
69
  // get the file size
82
- DWORD dwFileSize = ::GetFileSize(hFile, NULL);
83
-
84
- if (dwFileSize == INVALID_FILE_SIZE)
85
- {
86
- TRACE(_T("ERROR: %s failed\n"), _T("GetFileSize"));
87
- ::CloseHandle(hFile);
88
- return wstring_to_utf8(filename);
89
- }
90
-
91
- //TRACE(_T("dwFileSize = %d\n"), dwFileSize);
92
-
93
- // Create a file mapping object that is the current size of the file
94
- HANDLE hMappedFile = NULL;
95
- hMappedFile = ::CreateFileMapping(hFile,
96
- NULL,
97
- PAGE_READONLY, //PAGE_READWRITE,
98
- 0,
99
- dwFileSize,
100
- NULL);
101
-
102
- if (hMappedFile == NULL)
103
- {
104
- TRACE(_T("ERROR: %s failed\n"), _T("CreateFileMapping"));
105
- ::CloseHandle(hFile);
106
- return wstring_to_utf8(filename);
107
- }
108
-
109
- LPBYTE lpMapAddress = (LPBYTE) ::MapViewOfFile(hMappedFile, // handle to file-mapping object
110
- FILE_MAP_READ,//FILE_MAP_WRITE, // access mode
111
- 0, // high-order DWORD of offset
112
- 0, // low-order DWORD of offset
113
- 0); // number of bytes to map
114
-
115
- if (lpMapAddress == NULL)
116
- {
117
- TRACE(_T("ERROR: %s failed\n"), _T("MapViewOfFile"));
118
- ::CloseHandle(hMappedFile);
119
- ::CloseHandle(hFile);
120
- return wstring_to_utf8(filename);
121
- }
70
+ DWORD dwFileSize = buffer.size();
71
+ LPBYTE lpMapAddress = (LPBYTE) buffer.data();
122
72
 
123
73
  BOOL bRetVal = FALSE;
124
74
  int index = 0;
@@ -132,8 +82,9 @@ std::string get_name_from_ttf_file(const std::wstring& filename)
132
82
  ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
133
83
 
134
84
  //check is this is a true type font and the version is 1.0
135
- if (ttOffsetTable.uMajorVersion != 1 || ttOffsetTable.uMinorVersion != 0)
136
- return wstring_to_utf8(filename);
85
+ if (ttOffsetTable.uMajorVersion != 1 || ttOffsetTable.uMinorVersion != 0) {
86
+ throw std::runtime_error("Only version 1.0 of the TTF file format is supported");
87
+ }
137
88
 
138
89
  TT_TABLE_DIRECTORY tblDir;
139
90
  memset(&tblDir, 0, sizeof(TT_TABLE_DIRECTORY));
@@ -143,7 +94,6 @@ std::string get_name_from_ttf_file(const std::wstring& filename)
143
94
 
144
95
  for (int i = 0; i< ttOffsetTable.uNumOfTables; i++)
145
96
  {
146
- //f.Read(&tblDir, sizeof(TT_TABLE_DIRECTORY));
147
97
  memcpy(&tblDir, &lpMapAddress[index], sizeof(TT_TABLE_DIRECTORY));
148
98
  index += sizeof(TT_TABLE_DIRECTORY);
149
99
 
@@ -191,7 +141,7 @@ std::string get_name_from_ttf_file(const std::wstring& filename)
191
141
 
192
142
  if (ttRecord.uNameID == 1 || ttRecord.uNameID == 0 || ttRecord.uNameID == 7)
193
143
  {
194
- int nPos = index; //f.GetPosition();
144
+ int nPos = index;
195
145
 
196
146
  index = tblDir.uOffset + ttRecord.uStringOffset + ttNTHeader.uStorageOffset;
197
147
 
@@ -240,10 +190,6 @@ std::string get_name_from_ttf_file(const std::wstring& filename)
240
190
  }
241
191
  }
242
192
 
243
- ::UnmapViewOfFile(lpMapAddress);
244
- ::CloseHandle(hMappedFile);
245
- ::CloseHandle(hFile);
246
-
247
193
  return lpFontProps->csName[0] ? lpFontProps->csName : lpFontProps->csFamily;
248
194
  }
249
195
  }
data/src/TextWin.cpp CHANGED
@@ -22,7 +22,7 @@ std::string Gosu::default_font_name()
22
22
 
23
23
  namespace Gosu
24
24
  {
25
- std::string get_name_from_ttf_file(const std::wstring& filename);
25
+ std::string get_name_from_ttf_file(const std::string& filename);
26
26
 
27
27
  namespace
28
28
  {
@@ -93,9 +93,8 @@ namespace Gosu
93
93
 
94
94
  if (font_name.find("/") != font_name.npos) {
95
95
  if (custom_fonts.count(font_name) == 0) {
96
- std::wstring wfont_name = utf8_to_wstring(font_name);
97
- AddFontResourceExW(wfont_name.c_str(), FR_PRIVATE, 0);
98
- font_name = custom_fonts[font_name] = get_name_from_ttf_file(wfont_name);
96
+ AddFontResourceExW(utf8_to_wstring(font_name).c_str(), FR_PRIVATE, 0);
97
+ font_name = custom_fonts[font_name] = get_name_from_ttf_file(font_name);
99
98
  }
100
99
  else {
101
100
  font_name = custom_fonts[font_name];
data/src/Window.cpp CHANGED
@@ -83,6 +83,12 @@ struct Gosu::Window::Impl
83
83
  bool fullscreen;
84
84
  double update_interval;
85
85
 
86
+ // A single `bool open` is not good enough to support the tick() method: When close() is called
87
+ // from outside the window's call graph, the next call to tick() must return false (transition
88
+ // from CLOSING to CLOSED), but the call after that must return show the window again
89
+ // (transition from CLOSED to OPEN).
90
+ enum { CLOSED, OPEN, CLOSING } state = CLOSED;
91
+
86
92
  std::unique_ptr<Graphics> graphics;
87
93
  std::unique_ptr<Input> input;
88
94
  };
@@ -93,10 +99,11 @@ Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen, double up
93
99
  // Even in fullscreen mode, temporarily show the window in windowed mode to centre it.
94
100
  // This ensures that the window will be centred correctly when exiting fullscreen mode.
95
101
  // Fixes https://github.com/gosu/gosu/issues/369
102
+ // (This will implicitly create graphics() and input(), and make the OpenGL context current.)
96
103
  resize(width, height, false);
97
104
  SDL_SetWindowPosition(shared_window(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
98
105
 
99
- // This will implicitly create graphics() and input(), and make the OpenGL context current.
106
+ // Really enable fullscreen if desired.
100
107
  resize(width, height, fullscreen);
101
108
 
102
109
  SDL_GL_SetSwapInterval(1);
@@ -104,7 +111,7 @@ Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen, double up
104
111
  pimpl->update_interval = update_interval;
105
112
 
106
113
  input().on_button_down = [this](Button button) { button_down(button); };
107
- input().on_button_up = [this](Button button) { button_up(button); };
114
+ input().on_button_up = [this](Button button) { button_up(button); };
108
115
  }
109
116
 
110
117
  Gosu::Window::~Window()
@@ -221,12 +228,20 @@ void Gosu::Window::show()
221
228
 
222
229
  time_before_tick = milliseconds();
223
230
  }
231
+
232
+ pimpl->state = Impl::CLOSED;
224
233
  }
225
234
 
226
235
  bool Gosu::Window::tick()
227
236
  {
228
- if (SDL_GetWindowFlags(shared_window()) & SDL_WINDOW_HIDDEN) {
237
+ if (pimpl->state == Impl::CLOSING) {
238
+ pimpl->state = Impl::CLOSED;
239
+ return false;
240
+ }
241
+
242
+ if (pimpl->state == Impl::CLOSED) {
229
243
  SDL_ShowWindow(shared_window());
244
+ pimpl->state = Impl::OPEN;
230
245
 
231
246
  // SDL_GL_GetDrawableSize returns different values before and after showing the window.
232
247
  // -> When first showing the window, update the physical size of Graphics (=glViewport).
@@ -239,8 +254,7 @@ bool Gosu::Window::tick()
239
254
  SDL_Event e;
240
255
  while (SDL_PollEvent(&e)) {
241
256
  if (e.type == SDL_QUIT) {
242
- SDL_HideWindow(shared_window());
243
- return false;
257
+ close();
244
258
  }
245
259
  else {
246
260
  input().feed_sdl_event(&e);
@@ -266,14 +280,17 @@ bool Gosu::Window::tick()
266
280
  SDL_GL_SwapWindow(shared_window());
267
281
  }
268
282
 
269
- return true;
283
+ if (pimpl->state == Impl::CLOSING) {
284
+ pimpl->state = Impl::CLOSED;
285
+ }
286
+
287
+ return pimpl->state == Impl::OPEN;
270
288
  }
271
289
 
272
290
  void Gosu::Window::close()
273
291
  {
274
- SDL_Event e;
275
- e.type = SDL_QUIT;
276
- SDL_PushEvent(&e);
292
+ pimpl->state = Impl::CLOSING;
293
+ SDL_HideWindow(shared_window());
277
294
  }
278
295
 
279
296
  void Gosu::Window::button_down(Button button)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gosu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.3.pre1
4
+ version: 0.11.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Raschke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-23 00:00:00.000000000 Z
11
+ date: 2017-03-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  2D game development library.
@@ -53,6 +53,7 @@ files:
53
53
  - README.md
54
54
  - ext/gosu/extconf.rb
55
55
  - lib/gosu.rb
56
+ - lib/gosu/compat.rb
56
57
  - lib/gosu/patches.rb
57
58
  - lib/gosu/preview.rb
58
59
  - lib/gosu/run.rb
@@ -150,9 +151,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
150
151
  version: 1.8.2
151
152
  required_rubygems_version: !ruby/object:Gem::Requirement
152
153
  requirements:
153
- - - ">"
154
+ - - ">="
154
155
  - !ruby/object:Gem::Version
155
- version: 1.3.1
156
+ version: '0'
156
157
  requirements: []
157
158
  rubyforge_project:
158
159
  rubygems_version: 2.6.8