ehb_game_lib 0.2.0 → 0.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: ccf628fabf12bc43a3d54ba850cf6d084490cc06e23b33be631a4ea364257704
4
- data.tar.gz: 78d473bffc23e2083334ef7700bedd2a9e3b56addd97c0b68e0a6efcce8cbda8
3
+ metadata.gz: 132b08deabd26d18b4242dba90532c59eb76e3891045b198445303427fc8ebe2
4
+ data.tar.gz: 4a844b5f294d5a3a6978fc02ee4471dd16f350a2a2828afc1512181a1485eaf7
5
5
  SHA512:
6
- metadata.gz: 99d6c8ec7b605262ff2c587f1320028dbb870c406a4cac19499eaabb1b04b4c73533491ed935834532c73a6853b20f65d36df95925603a6a888dc01cd604732e
7
- data.tar.gz: 369d89f071d2d39dbe038fd8bc4f4d473a9256a1b417d32de18bb17129c91d7b86743a5d2df97b5d95b82423a0a2a7ba02d9998ab63620cdcb8c8eeee0008b01
6
+ metadata.gz: db52172a94bc5a43df09e623f966b830f7716bda2f5b872526934e500f13e5ab453cab8113c4f56d38284b0ba0e6d77c6e98f783e8fff7f7a01e78662645be3e
7
+ data.tar.gz: 06fd17ee33206fd65d16ad2486e23f07d6a0cfb73157013058f01950da57aace27220976b7f655f05b08e71d4b6bf16b2ad3473f459a9be68505fb23b8e82b19
@@ -2,32 +2,5 @@
2
2
 
3
3
  module EhbGameLib
4
4
  class BaseState < ::Chingu::GameState
5
- class << self
6
- attr_writer :resize_enabled
7
-
8
- def resize_enabled
9
- @resize_enabled = true if @resize_enabled.nil?
10
- @resize_enabled
11
- end
12
-
13
- def on_resize_enabled(enabled)
14
- old_value = resize_enabled
15
- begin
16
- self.resize_enabled = enabled
17
- yield
18
- ensure
19
- self.resize_enabled = old_value
20
- end
21
- end
22
- end
23
-
24
- def draw
25
- super
26
- ::EhbGameLib::Globals.window.draw_resized if resize_enabled?
27
- end
28
-
29
- def resize_enabled?
30
- ::EhbGameLib::BaseState.resize_enabled
31
- end
32
5
  end
33
6
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EhbGameLib
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/require_sub'
4
5
  require 'ehb_game_lib/canvas'
6
+ ::EacRubyUtils.require_sub(__FILE__)
5
7
 
6
8
  module EhbGameLib
7
9
  class Window < ::Chingu::Window
@@ -14,6 +16,7 @@ module EhbGameLib
14
16
  self.fit_canvas_to_window = true
15
17
  self.draw_retro = true
16
18
  super calculated_width, calculated_height
19
+ dimensions_reset
17
20
  end
18
21
 
19
22
  def calculated_width
@@ -26,52 +29,44 @@ module EhbGameLib
26
29
 
27
30
  def canvas_factor=(factor)
28
31
  @canvas_factor = factor
29
- self.width = calculated_width
30
- self.height = calculated_height
32
+ dimensions_reset
33
+ end
34
+
35
+ def fullscreen=(value)
36
+ super(value)
37
+ dimensions_reset
31
38
  end
32
39
 
33
40
  def draw
34
41
  super if ::EhbGameLib::Globals.window
42
+ draw_resized
43
+ end
44
+
45
+ private
46
+
47
+ def dimensions_reset
48
+ if fullscreen?
49
+ self.width = canvas.width
50
+ self.height = canvas.height
51
+ else
52
+ self.width = calculated_width
53
+ self.height = calculated_height
54
+ end
35
55
  end
36
56
 
37
57
  def draw_resized
38
- return unless fit_canvas_to_window
58
+ return unless fit_canvas_to_window && !fullscreen?
39
59
 
40
60
  ::Gosu::Image.new(canvas_image_source, retro: draw_retro)
41
61
  .draw(0, 0, 100, canvas_factor, canvas_factor)
42
62
  end
43
63
 
44
- private
45
-
46
64
  def canvas_image_source
47
65
  image_source(0, height - canvas.height, canvas.width, canvas.height)
48
66
  end
49
67
 
50
- def canvas_rect_uncached
51
- ::EhbGameLib::Math::Rect.new(0, 0, canvas.width, canvas.height)
52
- end
53
-
54
68
  def image_source(x, y, w, h)
55
69
  GlReadPixelsImage.new(x, y, w, h)
56
70
  end
57
-
58
- class GlReadPixelsImage
59
- attr_reader :columns, :rows
60
-
61
- DEPTH = 4
62
-
63
- def initialize(x, y, width, height)
64
- @columns = width
65
- @rows = height
66
- Gosu.flush
67
- Gosu.gl do
68
- @blob = ::Gl.glReadPixels(x, y, width, height, Gl::GL_RGBA, Gl::GL_UNSIGNED_BYTE)
69
- end
70
- end
71
-
72
- def to_blob
73
- @blob.force_encoding('binary').scan(/.{#{columns * 4}}/m).reverse.join
74
- end
75
- end
76
71
  end
77
72
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EhbGameLib
4
+ class Window < ::Chingu::Window
5
+ class GlReadPixelsImage
6
+ attr_reader :columns, :rows
7
+
8
+ DEPTH = 4
9
+
10
+ def initialize(x, y, width, height)
11
+ @columns = width
12
+ @rows = height
13
+ Gosu.flush
14
+ Gosu.gl do
15
+ @blob = ::Gl.glReadPixels(x, y, width, height, Gl::GL_RGBA, Gl::GL_UNSIGNED_BYTE)
16
+ end
17
+ end
18
+
19
+ def to_blob
20
+ @blob.force_encoding('binary').scan(/.{#{columns * 4}}/m).reverse.join
21
+ end
22
+ end
23
+ end
24
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ehb_game_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo H. Bogoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-25 00:00:00.000000000 Z
11
+ date: 2020-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -153,6 +153,7 @@ files:
153
153
  - lib/ehb_game_lib/utils/cursor.rb
154
154
  - lib/ehb_game_lib/version.rb
155
155
  - lib/ehb_game_lib/window.rb
156
+ - lib/ehb_game_lib/window/gl_read_pixels_image.rb
156
157
  - test/lib/ehb_game_lib/math/circle_test.rb
157
158
  - test/lib/ehb_game_lib/math/intersection/circle_line_segment_test.rb
158
159
  - test/lib/ehb_game_lib/math/intersection/circle_line_test.rb