ruby2d 0.11.2 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (231) hide show
  1. checksums.yaml +4 -4
  2. data/assets/include/GLES2/gl2.h +656 -0
  3. data/assets/include/GLES2/gl2ext.h +3949 -0
  4. data/assets/include/GLES2/gl2ext_angle.h +701 -0
  5. data/assets/include/GLES2/gl2platform.h +27 -0
  6. data/assets/include/GLES3/gl3.h +1192 -0
  7. data/assets/include/GLES3/gl31.h +1507 -0
  8. data/assets/include/GLES3/gl32.h +1808 -0
  9. data/assets/include/GLES3/gl3platform.h +27 -0
  10. data/assets/include/KHR/khrplatform.h +290 -0
  11. data/assets/include/SDL2/SDL.h +1 -0
  12. data/assets/include/SDL2/SDL_assert.h +4 -2
  13. data/assets/include/SDL2/SDL_atomic.h +20 -0
  14. data/assets/include/SDL2/SDL_audio.h +40 -4
  15. data/assets/include/SDL2/SDL_blendmode.h +4 -6
  16. data/assets/include/SDL2/SDL_clipboard.h +47 -0
  17. data/assets/include/SDL2/SDL_config.h +6 -2
  18. data/assets/include/SDL2/SDL_config_android.h +2 -0
  19. data/assets/include/SDL2/SDL_config_emscripten.h +2 -0
  20. data/assets/include/SDL2/SDL_config_iphoneos.h +3 -1
  21. data/assets/include/SDL2/SDL_config_macosx.h +3 -6
  22. data/assets/include/SDL2/SDL_config_minimal.h +18 -11
  23. data/assets/include/SDL2/SDL_config_ngage.h +89 -0
  24. data/assets/include/SDL2/SDL_config_os2.h +5 -3
  25. data/assets/include/SDL2/SDL_config_pandora.h +1 -0
  26. data/assets/include/SDL2/SDL_config_windows.h +71 -45
  27. data/assets/include/SDL2/SDL_config_wingdk.h +253 -0
  28. data/assets/include/SDL2/SDL_config_winrt.h +11 -49
  29. data/assets/include/SDL2/SDL_config_xbox.h +235 -0
  30. data/assets/include/SDL2/SDL_cpuinfo.h +39 -4
  31. data/assets/include/SDL2/SDL_egl.h +59 -9
  32. data/assets/include/SDL2/SDL_endian.h +34 -3
  33. data/assets/include/SDL2/SDL_events.h +32 -1
  34. data/assets/include/SDL2/SDL_filesystem.h +5 -1
  35. data/assets/include/SDL2/SDL_gamecontroller.h +78 -5
  36. data/assets/include/SDL2/SDL_guid.h +100 -0
  37. data/assets/include/SDL2/SDL_hints.h +645 -43
  38. data/assets/include/SDL2/SDL_image.h +2045 -33
  39. data/assets/include/SDL2/SDL_joystick.h +127 -7
  40. data/assets/include/SDL2/SDL_keyboard.h +38 -1
  41. data/assets/include/SDL2/SDL_keycode.h +6 -1
  42. data/assets/include/SDL2/SDL_log.h +2 -2
  43. data/assets/include/SDL2/SDL_main.h +42 -2
  44. data/assets/include/SDL2/SDL_metal.h +2 -1
  45. data/assets/include/SDL2/SDL_mixer.h +2529 -396
  46. data/assets/include/SDL2/SDL_mouse.h +12 -1
  47. data/assets/include/SDL2/SDL_opengl.h +0 -51
  48. data/assets/include/SDL2/SDL_opengl_glext.h +2260 -231
  49. data/assets/include/SDL2/SDL_opengles2_gl2.h +374 -339
  50. data/assets/include/SDL2/SDL_opengles2_gl2ext.h +3479 -1496
  51. data/assets/include/SDL2/SDL_opengles2_gl2platform.h +6 -9
  52. data/assets/include/SDL2/SDL_opengles2_khrplatform.h +43 -14
  53. data/assets/include/SDL2/SDL_platform.h +32 -6
  54. data/assets/include/SDL2/SDL_rect.h +154 -2
  55. data/assets/include/SDL2/SDL_render.h +46 -17
  56. data/assets/include/SDL2/SDL_revision.h +4 -0
  57. data/assets/include/SDL2/SDL_rwops.h +1 -15
  58. data/assets/include/SDL2/SDL_scancode.h +46 -21
  59. data/assets/include/SDL2/SDL_sensor.h +24 -3
  60. data/assets/include/SDL2/SDL_stdinc.h +119 -8
  61. data/assets/include/SDL2/SDL_surface.h +3 -1
  62. data/assets/include/SDL2/SDL_system.h +66 -6
  63. data/assets/include/SDL2/SDL_syswm.h +2 -0
  64. data/assets/include/SDL2/SDL_test_common.h +1 -0
  65. data/assets/include/SDL2/SDL_test_font.h +90 -3
  66. data/assets/include/SDL2/SDL_thread.h +3 -3
  67. data/assets/include/SDL2/SDL_touch.h +8 -0
  68. data/assets/include/SDL2/SDL_ttf.h +2084 -155
  69. data/assets/include/SDL2/SDL_version.h +19 -3
  70. data/assets/include/SDL2/SDL_video.h +71 -9
  71. data/assets/include/SDL2/begin_code.h +4 -4
  72. data/assets/include/mrbconf.h +15 -17
  73. data/assets/include/mruby/array.h +8 -21
  74. data/assets/include/mruby/boxing_nan.h +115 -86
  75. data/assets/include/mruby/boxing_word.h +104 -78
  76. data/assets/include/mruby/common.h +6 -0
  77. data/assets/include/mruby/compile.h +3 -4
  78. data/assets/include/mruby/debug.h +4 -2
  79. data/assets/include/mruby/dump.h +5 -2
  80. data/assets/include/mruby/error.h +12 -2
  81. data/assets/include/mruby/gc.h +2 -0
  82. data/assets/include/mruby/hash.h +1 -3
  83. data/assets/include/mruby/irep.h +4 -4
  84. data/assets/include/mruby/numeric.h +21 -13
  85. data/assets/include/mruby/opcode.h +30 -0
  86. data/assets/include/mruby/ops.h +99 -101
  87. data/assets/include/mruby/presym/scanning.h +15 -9
  88. data/assets/include/mruby/proc.h +4 -2
  89. data/assets/include/mruby/string.h +3 -24
  90. data/assets/include/mruby/value.h +80 -40
  91. data/assets/include/mruby/variable.h +0 -15
  92. data/assets/include/mruby/version.h +5 -5
  93. data/assets/include/mruby.h +86 -16
  94. data/assets/macos/universal/bin/mrbc +0 -0
  95. data/assets/macos/universal/lib/libFLAC.a +0 -0
  96. data/assets/macos/universal/lib/libSDL2.a +0 -0
  97. data/assets/macos/universal/lib/libSDL2_image.a +0 -0
  98. data/assets/macos/universal/lib/libSDL2_mixer.a +0 -0
  99. data/assets/macos/universal/lib/libSDL2_ttf.a +0 -0
  100. data/assets/macos/universal/lib/libavif.a +0 -0
  101. data/assets/macos/universal/lib/libbrotlicommon-static.a +0 -0
  102. data/assets/macos/universal/lib/libbrotlidec-static.a +0 -0
  103. data/assets/macos/universal/lib/libfreetype.a +0 -0
  104. data/assets/macos/universal/lib/libgraphite2.a +0 -0
  105. data/assets/macos/universal/lib/libharfbuzz.a +0 -0
  106. data/assets/macos/universal/lib/libhwy.a +0 -0
  107. data/assets/macos/universal/lib/libjpeg.a +0 -0
  108. data/assets/macos/universal/lib/libjxl.a +0 -0
  109. data/assets/macos/universal/lib/libmodplug.a +0 -0
  110. data/assets/macos/universal/lib/libmpg123.a +0 -0
  111. data/assets/macos/universal/lib/libmruby.a +0 -0
  112. data/assets/macos/universal/lib/libogg.a +0 -0
  113. data/assets/macos/universal/lib/libpng.a +0 -0
  114. data/assets/macos/universal/lib/libtiff.a +0 -0
  115. data/assets/macos/universal/lib/libvorbis.a +0 -0
  116. data/assets/macos/universal/lib/libvorbisfile.a +0 -0
  117. data/assets/macos/universal/lib/libwebp.a +0 -0
  118. data/assets/macos/universal/lib/libzstd.a +0 -0
  119. data/assets/wasm/libmruby.a +0 -0
  120. data/assets/wasm/template.html +52 -4
  121. data/assets/windows/mingw-w64-ucrt-x86_64/bin/mrbc.exe +0 -0
  122. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libFLAC.a +0 -0
  123. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libLerc.a +0 -0
  124. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libSDL2.a +0 -0
  125. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libSDL2_image.a +0 -0
  126. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libSDL2_mixer.a +0 -0
  127. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libSDL2_ttf.a +0 -0
  128. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libbrotlicommon.a +0 -0
  129. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libbrotlidec.a +0 -0
  130. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libbz2.a +0 -0
  131. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libdeflate.a +0 -0
  132. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libfreetype.a +0 -0
  133. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libglew32.a +0 -0
  134. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libgraphite2.a +0 -0
  135. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libharfbuzz.a +0 -0
  136. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libhwy.a +0 -0
  137. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libjbig.a +0 -0
  138. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libjpeg.a +0 -0
  139. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libjxl.a +0 -0
  140. data/assets/windows/mingw-w64-ucrt-x86_64/lib/liblzma.a +0 -0
  141. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libmodplug.a +0 -0
  142. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libmpg123.a +0 -0
  143. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libmruby.a +0 -0
  144. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libogg.a +0 -0
  145. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libopus.a +0 -0
  146. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libopusfile.a +0 -0
  147. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libpng.a +0 -0
  148. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libsndfile.a +0 -0
  149. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libssp.a +1 -0
  150. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libstdc++.a +0 -0
  151. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libtiff.a +0 -0
  152. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libvorbis.a +0 -0
  153. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libvorbisfile.a +0 -0
  154. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libwebp.a +0 -0
  155. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libz.a +0 -0
  156. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libzstd.a +0 -0
  157. data/assets/windows/mingw-w64-x86_64/bin/mrbc.exe +0 -0
  158. data/assets/windows/mingw-w64-x86_64/lib/libFLAC.a +0 -0
  159. data/assets/windows/mingw-w64-x86_64/lib/libLerc.a +0 -0
  160. data/assets/windows/mingw-w64-x86_64/lib/libSDL2.a +0 -0
  161. data/assets/windows/mingw-w64-x86_64/lib/libSDL2_image.a +0 -0
  162. data/assets/windows/mingw-w64-x86_64/lib/libSDL2_mixer.a +0 -0
  163. data/assets/windows/mingw-w64-x86_64/lib/libSDL2_ttf.a +0 -0
  164. data/assets/windows/mingw-w64-x86_64/lib/libbrotlicommon.a +0 -0
  165. data/assets/windows/mingw-w64-x86_64/lib/libbrotlidec.a +0 -0
  166. data/assets/windows/mingw-w64-x86_64/lib/libdeflate.a +0 -0
  167. data/assets/windows/mingw-w64-x86_64/lib/libfreetype.a +0 -0
  168. data/assets/windows/mingw-w64-x86_64/lib/libglew32.a +0 -0
  169. data/assets/windows/mingw-w64-x86_64/lib/libharfbuzz.a +0 -0
  170. data/assets/windows/mingw-w64-x86_64/lib/libhwy.a +0 -0
  171. data/assets/windows/mingw-w64-x86_64/lib/libjpeg.a +0 -0
  172. data/assets/windows/mingw-w64-x86_64/lib/libjxl.a +0 -0
  173. data/assets/windows/mingw-w64-x86_64/lib/liblzma.a +0 -0
  174. data/assets/windows/mingw-w64-x86_64/lib/libmpg123.a +0 -0
  175. data/assets/windows/mingw-w64-x86_64/lib/libmruby.a +0 -0
  176. data/assets/windows/mingw-w64-x86_64/lib/libopus.a +0 -0
  177. data/assets/windows/mingw-w64-x86_64/lib/libpng.a +0 -0
  178. data/assets/windows/mingw-w64-x86_64/lib/libsndfile.a +0 -0
  179. data/assets/windows/mingw-w64-x86_64/lib/libssp.a +0 -0
  180. data/assets/windows/mingw-w64-x86_64/lib/libstdc++.a +0 -0
  181. data/assets/windows/mingw-w64-x86_64/lib/libtiff.a +0 -0
  182. data/assets/windows/mingw-w64-x86_64/lib/libwebp.a +0 -0
  183. data/assets/windows/mingw-w64-x86_64/lib/libz.a +0 -0
  184. data/assets/windows/mingw-w64-x86_64/lib/libzstd.a +0 -0
  185. data/ext/ruby2d/canvas.c +540 -0
  186. data/ext/ruby2d/extconf.rb +39 -21
  187. data/ext/ruby2d/gl.c +3 -3
  188. data/ext/ruby2d/image.c +7 -7
  189. data/ext/ruby2d/ruby2d.c +741 -24
  190. data/ext/ruby2d/ruby2d.h +66 -3
  191. data/ext/ruby2d/sound.c +16 -2
  192. data/lib/ruby2d/canvas.rb +315 -0
  193. data/lib/ruby2d/circle.rb +30 -15
  194. data/lib/ruby2d/cli/build.rb +11 -4
  195. data/lib/ruby2d/cli/enable_console.rb +3 -1
  196. data/lib/ruby2d/color.rb +133 -77
  197. data/lib/ruby2d/core.rb +32 -0
  198. data/lib/ruby2d/dsl.rb +38 -32
  199. data/lib/ruby2d/exceptions.rb +2 -1
  200. data/lib/ruby2d/font.rb +97 -62
  201. data/lib/ruby2d/image.rb +48 -27
  202. data/lib/ruby2d/line.rb +84 -45
  203. data/lib/ruby2d/music.rb +33 -23
  204. data/lib/ruby2d/pixel.rb +10 -9
  205. data/lib/ruby2d/pixmap.rb +39 -0
  206. data/lib/ruby2d/pixmap_atlas.rb +56 -0
  207. data/lib/ruby2d/quad.rb +98 -49
  208. data/lib/ruby2d/rectangle.rb +35 -36
  209. data/lib/ruby2d/renderable.rb +7 -6
  210. data/lib/ruby2d/sound.rb +23 -17
  211. data/lib/ruby2d/sprite.rb +181 -140
  212. data/lib/ruby2d/square.rb +21 -20
  213. data/lib/ruby2d/text.rb +47 -19
  214. data/lib/ruby2d/texture.rb +13 -3
  215. data/lib/ruby2d/tileset.rb +97 -44
  216. data/lib/ruby2d/triangle.rb +91 -42
  217. data/lib/ruby2d/version.rb +3 -1
  218. data/lib/ruby2d/vertices.rb +81 -45
  219. data/lib/ruby2d/window.rb +508 -371
  220. data/lib/ruby2d.rb +11 -29
  221. metadata +84 -16
  222. data/assets/include/SDL2/SDL_config_psp.h +0 -165
  223. data/assets/include/SDL2/SDL_config_wiz.h +0 -154
  224. data/assets/include/glew.h +0 -23686
  225. data/assets/macos/universal/lib/libpng16.a +0 -0
  226. data/assets/wasm/build_config.rb +0 -13
  227. data/assets/windows/glew/README.md +0 -10
  228. data/assets/windows/glew/glew.h +0 -23686
  229. data/assets/windows/glew/libglew32.a +0 -0
  230. data/assets/windows/mingw-w64-x86_64/lib/libpng16.a +0 -0
  231. data/lib/ruby2d/entity.rb +0 -17
data/lib/ruby2d/window.rb CHANGED
@@ -1,11 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Ruby2D::Window
2
- # Represents a window on screen, responsible for storing renderable graphics,
3
- # event handlers, the update loop, showing and closing the window.
4
4
 
5
5
  module Ruby2D
6
- class Window
7
- @@open_window = false
6
+ # Represents a window on screen, responsible for storing renderable graphics,
7
+ # event handlers, the update loop, showing and closing the window.
8
+
9
+ attr_reader :width, :height
8
10
 
11
+ class Window
9
12
  # Event structures
10
13
  EventDescriptor = Struct.new(:type, :id)
11
14
  MouseEvent = Struct.new(:type, :button, :direction, :x, :y, :delta_x, :delta_y)
@@ -14,137 +17,124 @@ module Ruby2D
14
17
  ControllerAxisEvent = Struct.new(:which, :axis, :value)
15
18
  ControllerButtonEvent = Struct.new(:which, :button)
16
19
 
17
- def initialize(args = {})
18
-
20
+ #
21
+ # Create a Window
22
+ # @param title [String] Title for the window
23
+ # @param width [Numeric] In pixels
24
+ # @param height [Numeric] in pixels
25
+ # @param fps_cap [Numeric] Over-ride the default (60fps) frames-per-second
26
+ # @param vsync [Boolean] Enabled by default, use this to override it (Not recommended)
27
+ def initialize(title: 'Ruby 2D', width: 640, height: 480, fps_cap: 60, vsync: true)
19
28
  # Title of the window
20
- @title = args[:title] || "Ruby 2D"
21
-
22
- # Window background color
23
- @background = Color.new([0.0, 0.0, 0.0, 1.0])
24
-
25
- # Window icon
26
- @icon = nil
27
-
28
- # Window size and characteristics
29
- @width = args[:width] || 640
30
- @height = args[:height] || 480
31
- @resizable = false
32
- @borderless = false
33
- @fullscreen = false
34
- @highdpi = false
35
-
36
- # Size of the window's viewport (the drawable area)
37
- @viewport_width, @viewport_height = nil, nil
38
-
39
- # Size of the computer's display
40
- @display_width, @display_height = nil, nil
29
+ @title = title
41
30
 
42
- # Total number of frames that have been rendered
43
- @frames = 0
31
+ # Window size
32
+ @width = width
33
+ @height = height
44
34
 
45
35
  # Frames per second upper limit, and the actual FPS
46
- @fps_cap = args[:fps_cap] || 60
36
+ @fps_cap = fps_cap
47
37
  @fps = @fps_cap
48
38
 
49
39
  # Vertical synchronization, set to prevent screen tearing (recommended)
50
- @vsync = args[:vsync] || true
40
+ @vsync = vsync
41
+
42
+ # Total number of frames that have been rendered
43
+ @frames = 0
51
44
 
52
45
  # Renderable objects currently in the window, like a linear scene graph
53
46
  @objects = []
54
47
 
55
- # Entities currently in the window
56
- @entities = []
48
+ _init_window_defaults
49
+ _init_event_stores
50
+ _init_event_registrations
51
+ _init_procs_dsl_console
52
+ end
57
53
 
58
- # Mouse X and Y position in the window
59
- @mouse_x, @mouse_y = 0, 0
54
+ # Track open window state in a class instance variable
55
+ @open_window = false
60
56
 
61
- # Controller axis and button mappings file
62
- @controller_mappings = File.expand_path('~') + "/.ruby2d/controllers.txt"
57
+ # Class methods for convenient access to properties
58
+ class << self
59
+ def current
60
+ get(:window)
61
+ end
63
62
 
64
- # Event stores for class pattern
65
- @keys_down = []
66
- @keys_held = []
67
- @keys_up = []
68
- @mouse_buttons_down = []
69
- @mouse_buttons_up = []
70
- @mouse_scroll_event = false
71
- @mouse_scroll_direction = nil
72
- @mouse_scroll_delta_x = 0
73
- @mouse_scroll_delta_y = 0
74
- @mouse_move_event = false
75
- @mouse_move_delta_x = 0
76
- @mouse_move_delta_y = 0
77
- @controller_id = nil
78
- @controller_axes_moved = []
79
- @controller_axis_left_x = 0
80
- @controller_axis_left_y = 0
81
- @controller_axis_right_x = 0
82
- @controller_axis_right_y = 0
83
- @controller_buttons_down = []
84
- @controller_buttons_up = []
63
+ def title
64
+ get(:title)
65
+ end
85
66
 
86
- # Unique ID for the input event being registered
87
- @event_key = 0
67
+ def background
68
+ get(:background)
69
+ end
88
70
 
89
- # Registered input events
90
- @events = {
91
- key: {},
92
- key_down: {},
93
- key_held: {},
94
- key_up: {},
95
- mouse: {},
96
- mouse_up: {},
97
- mouse_down: {},
98
- mouse_scroll: {},
99
- mouse_move: {},
100
- controller: {},
101
- controller_axis: {},
102
- controller_button_down: {},
103
- controller_button_up: {}
104
- }
71
+ def width
72
+ get(:width)
73
+ end
105
74
 
106
- # The window update block
107
- @update_proc = Proc.new {}
75
+ def height
76
+ get(:height)
77
+ end
108
78
 
109
- # The window render block
110
- @render_proc = Proc.new {}
79
+ def viewport_width
80
+ get(:viewport_width)
81
+ end
111
82
 
112
- # Detect if window is being used through the DSL or as a class instance
113
- @using_dsl = !(method(:update).parameters.empty? || method(:render).parameters.empty?)
83
+ def viewport_height
84
+ get(:viewport_height)
85
+ end
114
86
 
115
- # Whether diagnostic messages should be printed
116
- @diagnostics = false
87
+ def display_width
88
+ get(:display_width)
89
+ end
117
90
 
118
- # Console mode, enabled at command line
119
- if RUBY_ENGINE == 'ruby'
120
- @console = defined?($ruby2d_console_mode) ? true : false
121
- else
122
- @console = false
91
+ def display_height
92
+ get(:display_height)
123
93
  end
124
- end
125
94
 
126
- # Class methods for convenient access to properties
127
- class << self
128
- def current; get(:window) end
129
- def title; get(:title) end
130
- def background; get(:background) end
131
- def width; get(:width) end
132
- def height; get(:height) end
133
- def viewport_width; get(:viewport_width) end
134
- def viewport_height; get(:viewport_height) end
135
- def display_width; get(:display_width) end
136
- def display_height; get(:display_height) end
137
- def resizable; get(:resizable) end
138
- def borderless; get(:borderless) end
139
- def fullscreen; get(:fullscreen) end
140
- def highdpi; get(:highdpi) end
141
- def frames; get(:frames) end
142
- def fps; get(:fps) end
143
- def fps_cap; get(:fps_cap) end
144
- def mouse_x; get(:mouse_x) end
145
- def mouse_y; get(:mouse_y) end
146
- def diagnostics; get(:diagnostics) end
147
- def screenshot(opts = nil); get(:screenshot, opts) end
95
+ def resizable
96
+ get(:resizable)
97
+ end
98
+
99
+ def borderless
100
+ get(:borderless)
101
+ end
102
+
103
+ def fullscreen
104
+ get(:fullscreen)
105
+ end
106
+
107
+ def highdpi
108
+ get(:highdpi)
109
+ end
110
+
111
+ def frames
112
+ get(:frames)
113
+ end
114
+
115
+ def fps
116
+ get(:fps)
117
+ end
118
+
119
+ def fps_cap
120
+ get(:fps_cap)
121
+ end
122
+
123
+ def mouse_x
124
+ get(:mouse_x)
125
+ end
126
+
127
+ def mouse_y
128
+ get(:mouse_y)
129
+ end
130
+
131
+ def diagnostics
132
+ get(:diagnostics)
133
+ end
134
+
135
+ def screenshot(opts = nil)
136
+ get(:screenshot, opts)
137
+ end
148
138
 
149
139
  def get(sym, opts = nil)
150
140
  DSL.window.get(sym, opts)
@@ -162,12 +152,12 @@ module Ruby2D
162
152
  DSL.window.off(event_descriptor)
163
153
  end
164
154
 
165
- def add(o)
166
- DSL.window.add(o)
155
+ def add(object)
156
+ DSL.window.add(object)
167
157
  end
168
158
 
169
- def remove(o)
170
- DSL.window.remove(o)
159
+ def remove(object)
160
+ DSL.window.remove(object)
171
161
  end
172
162
 
173
163
  def clear
@@ -191,24 +181,42 @@ module Ruby2D
191
181
  end
192
182
 
193
183
  def render_ready_check
194
- unless @@open_window
195
- raise Error, "Attempting to draw before the window is ready. Please put calls to draw() inside of a render block."
196
- end
184
+ return if opened?
185
+
186
+ raise Error,
187
+ 'Attempting to draw before the window is ready. Please put calls to draw() inside of a render block.'
188
+ end
189
+
190
+ def opened?
191
+ @open_window
192
+ end
193
+
194
+ private
195
+
196
+ def opened!
197
+ @open_window = true
197
198
  end
198
199
  end
199
200
 
200
201
  # Public instance methods
201
202
 
203
+ # --- start exception
204
+ # Exception from lint check for the #get method which is what it is. :)
205
+ #
206
+ # rubocop:disable Metrics/CyclomaticComplexity
207
+ # rubocop:disable Metrics/AbcSize
208
+
202
209
  # Retrieve an attribute of the window
210
+ # @param sym [Symbol] The name of an attribute to retrieve.
203
211
  def get(sym, opts = nil)
204
212
  case sym
205
- when :window; self
206
- when :title; @title
207
- when :background; @background
208
- when :width; @width
209
- when :height; @height
210
- when :viewport_width; @viewport_width
211
- when :viewport_height; @viewport_height
213
+ when :window then self
214
+ when :title then @title
215
+ when :background then @background
216
+ when :width then @width
217
+ when :height then @height
218
+ when :viewport_width then @viewport_width
219
+ when :viewport_height then @viewport_height
212
220
  when :display_width, :display_height
213
221
  ext_get_display_dimensions
214
222
  if sym == :display_width
@@ -216,76 +224,75 @@ module Ruby2D
216
224
  else
217
225
  @display_height
218
226
  end
219
- when :resizable; @resizable
220
- when :borderless; @borderless
221
- when :fullscreen; @fullscreen
222
- when :highdpi; @highdpi
223
- when :frames; @frames
224
- when :fps; @fps
225
- when :fps_cap; @fps_cap
226
- when :mouse_x; @mouse_x
227
- when :mouse_y; @mouse_y
228
- when :diagnostics; @diagnostics
229
- when :screenshot; screenshot(opts)
230
- end
231
- end
227
+ when :resizable then @resizable
228
+ when :borderless then @borderless
229
+ when :fullscreen then @fullscreen
230
+ when :highdpi then @highdpi
231
+ when :frames then @frames
232
+ when :fps then @fps
233
+ when :fps_cap then @fps_cap
234
+ when :mouse_x then @mouse_x
235
+ when :mouse_y then @mouse_y
236
+ when :diagnostics then @diagnostics
237
+ when :screenshot then screenshot(opts)
238
+ end
239
+ end
240
+ # rubocop:enable Metrics/CyclomaticComplexity
241
+ # rubocop:enable Metrics/AbcSize
242
+ # --- end exception
232
243
 
233
244
  # Set a window attribute
245
+ # @param opts [Hash] The attributes to set
246
+ # @option opts [Color] :background
247
+ # @option opts [String] :title
248
+ # @option opts [Numeric] :width
249
+ # @option opts [Numeric] :height
250
+ # @option opts [Numeric] :viewport_width
251
+ # @option opts [Numeric] :viewport_height
252
+ # @option opts [Boolean] :highdpi
253
+ # @option opts [Boolean] :resizable
254
+ # @option opts [Boolean] :borderless
255
+ # @option opts [Boolean] :fullscreen
256
+ # @option opts [Numeric] :fps_cap
257
+ # @option opts [Numeric] :diagnostics
234
258
  def set(opts)
235
259
  # Store new window attributes, or ignore if nil
236
- @title = opts[:title] || @title
237
- if Color.is_valid? opts[:background]
238
- @background = Color.new(opts[:background])
239
- end
240
- @icon = opts[:icon] || @icon
241
- @width = opts[:width] || @width
242
- @height = opts[:height] || @height
243
- @fps_cap = opts[:fps_cap] || @fps_cap
244
- @viewport_width = opts[:viewport_width] || @viewport_width
245
- @viewport_height = opts[:viewport_height] || @viewport_height
246
- @resizable = opts[:resizable] || @resizable
247
- @borderless = opts[:borderless] || @borderless
248
- @fullscreen = opts[:fullscreen] || @fullscreen
249
- @highdpi = opts[:highdpi] || @highdpi
250
- unless opts[:diagnostics].nil?
251
- @diagnostics = opts[:diagnostics]
252
- ext_diagnostics(@diagnostics)
253
- end
260
+ _set_any_window_properties opts
261
+ _set_any_window_dimensions opts
262
+
263
+ @fps_cap = opts[:fps_cap] if opts[:fps_cap]
264
+ return if opts[:diagnostics].nil?
265
+
266
+ @diagnostics = opts[:diagnostics]
267
+ ext_diagnostics(@diagnostics)
254
268
  end
255
269
 
256
270
  # Add an object to the window
257
- def add(o)
258
- case o
271
+ def add(object)
272
+ case object
259
273
  when nil
260
- raise Error, "Cannot add '#{o.class}' to window!"
261
- when Entity
262
- @entities.push(o)
274
+ raise Error, "Cannot add '#{object.class}' to window!"
263
275
  when Array
264
- o.each { |x| add_object(x) }
276
+ object.each { |x| add_object(x) }
265
277
  else
266
- add_object(o)
278
+ add_object(object)
267
279
  end
268
280
  end
269
281
 
270
282
  # Remove an object from the window
271
- def remove(o)
272
- if o == nil
273
- raise Error, "Cannot remove '#{o.class}' from window!"
274
- end
283
+ def remove(object)
284
+ raise Error, "Cannot remove '#{object.class}' from window!" if object.nil?
275
285
 
276
- collection = o.class.ancestors.include?(Ruby2D::Entity) ? @entities : @objects
277
- if i = collection.index(o)
278
- collection.delete_at(i)
279
- true
280
- else
281
- false
282
- end
286
+ ix = @objects.index(object)
287
+ return false if ix.nil?
288
+
289
+ @objects.delete_at(ix)
290
+ true
283
291
  end
284
292
 
285
293
  # Clear all objects from the window
286
294
  def clear
287
295
  @objects.clear
288
- @entities.clear
289
296
  end
290
297
 
291
298
  # Set the update callback
@@ -307,9 +314,8 @@ module Ruby2D
307
314
 
308
315
  # Set an event handler
309
316
  def on(event, &proc)
310
- unless @events.has_key? event
311
- raise Error, "`#{event}` is not a valid event type"
312
- end
317
+ raise Error, "`#{event}` is not a valid event type" unless @events.key? event
318
+
313
319
  event_id = new_event_key
314
320
  @events[event][event_id] = proc
315
321
  EventDescriptor.new(event, event_id)
@@ -340,50 +346,20 @@ module Ruby2D
340
346
  key = key.downcase
341
347
 
342
348
  # All key events
343
- @events[:key].each do |id, e|
349
+ @events[:key].each do |_id, e|
344
350
  e.call(KeyEvent.new(type, key))
345
351
  end
346
352
 
347
353
  case type
348
354
  # When key is pressed, fired once
349
355
  when :down
350
- # For class pattern
351
- unless @using_dsl
352
- unless @keys_down.include? key
353
- @keys_down << key
354
- end
355
- end
356
-
357
- # Call event handler
358
- @events[:key_down].each do |id, e|
359
- e.call(KeyEvent.new(type, key))
360
- end
356
+ _handle_key_down type, key
361
357
  # When key is being held down, fired every frame
362
358
  when :held
363
- # For class pattern
364
- unless @using_dsl
365
- unless @keys_held.include? key
366
- @keys_held << key
367
- end
368
- end
369
-
370
- # Call event handler
371
- @events[:key_held].each do |id, e|
372
- e.call(KeyEvent.new(type, key))
373
- end
359
+ _handle_key_held type, key
374
360
  # When key released, fired once
375
361
  when :up
376
- # For class pattern
377
- unless @using_dsl
378
- unless @keys_up.include? key
379
- @keys_up << key
380
- end
381
- end
382
-
383
- # Call event handler
384
- @events[:key_up].each do |id, e|
385
- e.call(KeyEvent.new(type, key))
386
- end
362
+ _handle_key_up type, key
387
363
  end
388
364
  end
389
365
 
@@ -410,72 +386,29 @@ module Ruby2D
410
386
  # Mouse callback method, called by the native and web extentions
411
387
  def mouse_callback(type, button, direction, x, y, delta_x, delta_y)
412
388
  # All mouse events
413
- @events[:mouse].each do |id, e|
389
+ @events[:mouse].each do |_id, e|
414
390
  e.call(MouseEvent.new(type, button, direction, x, y, delta_x, delta_y))
415
391
  end
416
392
 
417
393
  case type
418
394
  # When mouse button pressed
419
395
  when :down
420
- # For class pattern
421
- unless @using_dsl
422
- unless @mouse_buttons_down.include? button
423
- @mouse_buttons_down << button
424
- end
425
- end
426
-
427
- # Call event handler
428
- @events[:mouse_down].each do |id, e|
429
- e.call(MouseEvent.new(type, button, nil, x, y, nil, nil))
430
- end
396
+ _handle_mouse_down type, button, x, y
431
397
  # When mouse button released
432
398
  when :up
433
- # For class pattern
434
- unless @using_dsl
435
- unless @mouse_buttons_up.include? button
436
- @mouse_buttons_up << button
437
- end
438
- end
439
-
440
- # Call event handler
441
- @events[:mouse_up].each do |id, e|
442
- e.call(MouseEvent.new(type, button, nil, x, y, nil, nil))
443
- end
399
+ _handle_mouse_up type, button, x, y
444
400
  # When mouse motion / movement
445
401
  when :scroll
446
- # For class pattern
447
- unless @using_dsl
448
- @mouse_scroll_event = true
449
- @mouse_scroll_direction = direction
450
- @mouse_scroll_delta_x = delta_x
451
- @mouse_scroll_delta_y = delta_y
452
- end
453
-
454
- # Call event handler
455
- @events[:mouse_scroll].each do |id, e|
456
- e.call(MouseEvent.new(type, nil, direction, nil, nil, delta_x, delta_y))
457
- end
402
+ _handle_mouse_scroll type, direction, delta_x, delta_y
458
403
  # When mouse scrolling, wheel or trackpad
459
404
  when :move
460
- # For class pattern
461
- unless @using_dsl
462
- @mouse_move_event = true
463
- @mouse_move_delta_x = delta_x
464
- @mouse_move_delta_y = delta_y
465
- end
466
-
467
- # Call event handler
468
- @events[:mouse_move].each do |id, e|
469
- e.call(MouseEvent.new(type, nil, nil, x, y, delta_x, delta_y))
470
- end
405
+ _handle_mouse_move type, x, y, delta_x, delta_y
471
406
  end
472
407
  end
473
408
 
474
409
  # Add controller mappings from file
475
410
  def add_controller_mappings
476
- if File.exist? @controller_mappings
477
- ext_add_controller_mappings(@controller_mappings)
478
- end
411
+ ext_add_controller_mappings(@controller_mappings) if File.exist? @controller_mappings
479
412
  end
480
413
 
481
414
  # Controller axis event method for class pattern
@@ -496,136 +429,48 @@ module Ruby2D
496
429
  # Controller callback method, called by the native and web extentions
497
430
  def controller_callback(which, type, axis, value, button)
498
431
  # All controller events
499
- @events[:controller].each do |id, e|
432
+ @events[:controller].each do |_id, e|
500
433
  e.call(ControllerEvent.new(which, type, axis, value, button))
501
434
  end
502
435
 
503
436
  case type
504
437
  # When controller axis motion, like analog sticks
505
438
  when :axis
506
-
507
- # For class pattern
508
- unless @using_dsl
509
- @controller_id = which
510
-
511
- unless @controller_axes_moved.include? axis
512
- @controller_axes_moved << axis
513
- end
514
-
515
- case axis
516
- when :left_x
517
- @controller_axis_left_x = value
518
- when :left_y
519
- @controller_axis_left_y = value
520
- when :right_x
521
- @controller_axis_right_x = value
522
- when :right_y
523
- @controller_axis_right_y = value
524
- end
525
- end
526
-
527
- # Call event handler
528
- @events[:controller_axis].each do |id, e|
529
- e.call(ControllerAxisEvent.new(which, axis, value))
530
- end
439
+ _handle_controller_axis which, axis, value
531
440
  # When controller button is pressed
532
441
  when :button_down
533
- # For class pattern
534
- unless @using_dsl
535
- @controller_id = which
536
- unless @controller_buttons_down.include? button
537
- @controller_buttons_down << button
538
- end
539
- end
540
-
541
- # Call event handler
542
- @events[:controller_button_down].each do |id, e|
543
- e.call(ControllerButtonEvent.new(which, button))
544
- end
442
+ _handle_controller_button_down which, button
545
443
  # When controller button is released
546
444
  when :button_up
547
- # For class pattern
548
- unless @using_dsl
549
- @controller_id = which
550
- unless @controller_buttons_up.include? button
551
- @controller_buttons_up << button
552
- end
553
- end
554
-
555
- # Call event handler
556
- @events[:controller_button_up].each do |id, e|
557
- e.call(ControllerButtonEvent.new(which, button))
558
- end
445
+ _handle_controller_button_up which, button
559
446
  end
560
447
  end
561
448
 
562
449
  # Update callback method, called by the native and web extentions
563
450
  def update_callback
564
- unless @using_dsl
565
- update
566
- end
451
+ update unless @using_dsl
567
452
 
568
453
  @update_proc.call
569
454
 
570
- # Run update method on all entities
571
- @entities.each do |e|
572
- e.update
573
- end
574
-
575
455
  # Accept and eval commands if in console mode
576
- if @console
577
- if STDIN.ready?
578
- cmd = STDIN.gets
579
- begin
580
- res = eval(cmd, TOPLEVEL_BINDING)
581
- STDOUT.puts "=> #{res.inspect}"
582
- STDOUT.flush
583
- rescue SyntaxError => se
584
- STDOUT.puts se
585
- STDOUT.flush
586
- rescue Exception => e
587
- STDOUT.puts e
588
- STDOUT.flush
589
- end
590
- end
591
- end
456
+ _handle_console_input if @console && $stdin.ready?
592
457
 
593
458
  # Clear inputs if using class pattern
594
- unless @using_dsl
595
- @keys_down.clear
596
- @keys_held.clear
597
- @keys_up.clear
598
- @mouse_buttons_down.clear
599
- @mouse_buttons_up.clear
600
- @mouse_scroll_event = false
601
- @mouse_move_event = false
602
- @controller_axes_moved.clear
603
- @controller_buttons_down.clear
604
- @controller_buttons_up.clear
605
- end
459
+ _clear_event_stores unless @using_dsl
606
460
  end
607
461
 
608
462
  # Render callback method, called by the native and web extentions
609
463
  def render_callback
610
- unless @using_dsl
611
- render
612
- end
464
+ render unless @using_dsl
613
465
 
614
466
  @render_proc.call
615
-
616
- # Run render method on all entities
617
- @entities.each do |e|
618
- e.render
619
- end
620
467
  end
621
468
 
622
469
  # Show the window
623
470
  def show
624
- if @@open_window
625
- raise Error, "Window#show called multiple times, Ruby2D only supports a single open window"
626
- end
471
+ raise Error, 'Window#show called multiple times, Ruby2D only supports a single open window' if Window.opened?
627
472
 
628
- @@open_window = true
473
+ Window.send(:opened!)
629
474
  ext_show
630
475
  end
631
476
 
@@ -634,11 +479,11 @@ module Ruby2D
634
479
  if path
635
480
  ext_screenshot(path)
636
481
  else
637
- if RUBY_ENGINE == 'ruby'
638
- time = Time.now.utc.strftime '%Y-%m-%d--%H-%M-%S'
639
- else
640
- time = Time.now.utc.to_i
641
- end
482
+ time = if RUBY_ENGINE == 'ruby'
483
+ Time.now.utc.strftime '%Y-%m-%d--%H-%M-%S'
484
+ else
485
+ Time.now.utc.to_i
486
+ end
642
487
  ext_screenshot("./screenshot-#{time}.png")
643
488
  end
644
489
  end
@@ -653,15 +498,15 @@ module Ruby2D
653
498
  private
654
499
 
655
500
  # An an object to the window, used by the public `add` method
656
- def add_object(o)
657
- if !@objects.include?(o)
658
- index = @objects.index do |object|
659
- object.z > o.z
501
+ def add_object(object)
502
+ if !@objects.include?(object)
503
+ index = @objects.index do |obj|
504
+ obj.z > object.z
660
505
  end
661
506
  if index
662
- @objects.insert(index, o)
507
+ @objects.insert(index, object)
663
508
  else
664
- @objects.push(o)
509
+ @objects.push(object)
665
510
  end
666
511
  true
667
512
  else
@@ -669,5 +514,297 @@ module Ruby2D
669
514
  end
670
515
  end
671
516
 
517
+ def _set_any_window_properties(opts)
518
+ @background = Color.new(opts[:background]) if Color.valid? opts[:background]
519
+ @title = opts[:title] if opts[:title]
520
+ @icon = opts[:icon] if opts[:icon]
521
+ @resizable = opts[:resizable] if opts[:resizable]
522
+ @borderless = opts[:borderless] if opts[:borderless]
523
+ @fullscreen = opts[:fullscreen] if opts[:fullscreen]
524
+ end
525
+
526
+ def _set_any_window_dimensions(opts)
527
+ @width = opts[:width] if opts[:width]
528
+ @height = opts[:height] if opts[:height]
529
+ @viewport_width = opts[:viewport_width] if opts[:viewport_width]
530
+ @viewport_height = opts[:viewport_height] if opts[:viewport_height]
531
+ @highdpi = opts[:highdpi] unless opts[:highdpi].nil?
532
+ end
533
+
534
+ def _handle_key_down(type, key)
535
+ # For class pattern
536
+ @keys_down << key if !@using_dsl && !(@keys_down.include? key)
537
+
538
+ # Call event handler
539
+ @events[:key_down].each do |_id, e|
540
+ e.call(KeyEvent.new(type, key))
541
+ end
542
+ end
543
+
544
+ def _handle_key_held(type, key)
545
+ # For class pattern
546
+ @keys_held << key if !@using_dsl && !(@keys_held.include? key)
547
+
548
+ # Call event handler
549
+ @events[:key_held].each do |_id, e|
550
+ e.call(KeyEvent.new(type, key))
551
+ end
552
+ end
553
+
554
+ def _handle_key_up(type, key)
555
+ # For class pattern
556
+ @keys_up << key if !@using_dsl && !(@keys_up.include? key)
557
+
558
+ # Call event handler
559
+ @events[:key_up].each do |_id, e|
560
+ e.call(KeyEvent.new(type, key))
561
+ end
562
+ end
563
+
564
+ def _handle_mouse_down(type, button, x, y)
565
+ # For class pattern
566
+ @mouse_buttons_down << button if !@using_dsl && !(@mouse_buttons_down.include? button)
567
+
568
+ # Call event handler
569
+ @events[:mouse_down].each do |_id, e|
570
+ e.call(MouseEvent.new(type, button, nil, x, y, nil, nil))
571
+ end
572
+ end
573
+
574
+ def _handle_mouse_up(type, button, x, y)
575
+ # For class pattern
576
+ @mouse_buttons_up << button if !@using_dsl && !(@mouse_buttons_up.include? button)
577
+
578
+ # Call event handler
579
+ @events[:mouse_up].each do |_id, e|
580
+ e.call(MouseEvent.new(type, button, nil, x, y, nil, nil))
581
+ end
582
+ end
583
+
584
+ def _handle_mouse_scroll(type, direction, delta_x, delta_y)
585
+ # For class pattern
586
+ unless @using_dsl
587
+ @mouse_scroll_event = true
588
+ @mouse_scroll_direction = direction
589
+ @mouse_scroll_delta_x = delta_x
590
+ @mouse_scroll_delta_y = delta_y
591
+ end
592
+
593
+ # Call event handler
594
+ @events[:mouse_scroll].each do |_id, e|
595
+ e.call(MouseEvent.new(type, nil, direction, nil, nil, delta_x, delta_y))
596
+ end
597
+ end
598
+
599
+ def _handle_mouse_move(type, x, y, delta_x, delta_y)
600
+ # For class pattern
601
+ unless @using_dsl
602
+ @mouse_move_event = true
603
+ @mouse_move_delta_x = delta_x
604
+ @mouse_move_delta_y = delta_y
605
+ end
606
+
607
+ # Call event handler
608
+ @events[:mouse_move].each do |_id, e|
609
+ e.call(MouseEvent.new(type, nil, nil, x, y, delta_x, delta_y))
610
+ end
611
+ end
612
+
613
+ def _handle_controller_axis(which, axis, value)
614
+ # For class pattern
615
+ unless @using_dsl
616
+ @controller_id = which
617
+ @controller_axes_moved << axis unless @controller_axes_moved.include? axis
618
+ _set_controller_axis_value axis, value
619
+ end
620
+
621
+ # Call event handler
622
+ @events[:controller_axis].each do |_id, e|
623
+ e.call(ControllerAxisEvent.new(which, axis, value))
624
+ end
625
+ end
626
+
627
+ def _set_controller_axis_value(axis, value)
628
+ case axis
629
+ when :left_x
630
+ @controller_axis_left_x = value
631
+ when :left_y
632
+ @controller_axis_left_y = value
633
+ when :right_x
634
+ @controller_axis_right_x = value
635
+ when :right_y
636
+ @controller_axis_right_y = value
637
+ end
638
+ end
639
+
640
+ def _handle_controller_button_down(which, button)
641
+ # For class pattern
642
+ unless @using_dsl
643
+ @controller_id = which
644
+ @controller_buttons_down << button unless @controller_buttons_down.include? button
645
+ end
646
+
647
+ # Call event handler
648
+ @events[:controller_button_down].each do |_id, e|
649
+ e.call(ControllerButtonEvent.new(which, button))
650
+ end
651
+ end
652
+
653
+ def _handle_controller_button_up(which, button)
654
+ # For class pattern
655
+ unless @using_dsl
656
+ @controller_id = which
657
+ @controller_buttons_up << button unless @controller_buttons_up.include? button
658
+ end
659
+
660
+ # Call event handler
661
+ @events[:controller_button_up].each do |_id, e|
662
+ e.call(ControllerButtonEvent.new(which, button))
663
+ end
664
+ end
665
+
666
+ # --- start exception
667
+ # Exception from lint check for this method only
668
+ #
669
+ # rubocop:disable Lint/RescueException
670
+ # rubocop:disable Security/Eval
671
+ def _handle_console_input
672
+ cmd = $stdin.gets
673
+ begin
674
+ res = eval(cmd, TOPLEVEL_BINDING)
675
+ $stdout.puts "=> #{res.inspect}"
676
+ $stdout.flush
677
+ rescue SyntaxError => e
678
+ $stdout.puts e
679
+ $stdout.flush
680
+ rescue Exception => e
681
+ $stdout.puts e
682
+ $stdout.flush
683
+ end
684
+ end
685
+ # rubocop:enable Lint/RescueException
686
+ # rubocop:enable Security/Eval
687
+ # ---- end exception
688
+
689
+ def _clear_event_stores
690
+ @keys_down.clear
691
+ @keys_held.clear
692
+ @keys_up.clear
693
+ @mouse_buttons_down.clear
694
+ @mouse_buttons_up.clear
695
+ @mouse_scroll_event = false
696
+ @mouse_move_event = false
697
+ @controller_axes_moved.clear
698
+ @controller_buttons_down.clear
699
+ @controller_buttons_up.clear
700
+ end
701
+
702
+ def _init_window_defaults
703
+ # Window background color
704
+ @background = Color.new([0.0, 0.0, 0.0, 1.0])
705
+
706
+ # Window icon
707
+ @icon = nil
708
+
709
+ # Window characteristics
710
+ @resizable = false
711
+ @borderless = false
712
+ @fullscreen = false
713
+ @highdpi = false
714
+
715
+ # Size of the window's viewport (the drawable area)
716
+ @viewport_width = nil
717
+ @viewport_height = nil
718
+
719
+ # Size of the computer's display
720
+ @display_width = nil
721
+ @display_height = nil
722
+ end
723
+
724
+ def _init_event_stores
725
+ _init_key_event_stores
726
+ _init_mouse_event_stores
727
+ _init_controller_event_stores
728
+ end
729
+
730
+ def _init_key_event_stores
731
+ # Event stores for class pattern
732
+ @keys_down = []
733
+ @keys_held = []
734
+ @keys_up = []
735
+ end
736
+
737
+ def _init_mouse_event_stores
738
+ @mouse_buttons_down = []
739
+ @mouse_buttons_up = []
740
+ @mouse_scroll_event = false
741
+ @mouse_scroll_direction = nil
742
+ @mouse_scroll_delta_x = 0
743
+ @mouse_scroll_delta_y = 0
744
+ @mouse_move_event = false
745
+ @mouse_move_delta_x = 0
746
+ @mouse_move_delta_y = 0
747
+ end
748
+
749
+ def _init_controller_event_stores
750
+ @controller_id = nil
751
+ @controller_axes_moved = []
752
+ @controller_axis_left_x = 0
753
+ @controller_axis_left_y = 0
754
+ @controller_axis_right_x = 0
755
+ @controller_axis_right_y = 0
756
+ @controller_buttons_down = []
757
+ @controller_buttons_up = []
758
+ end
759
+
760
+ def _init_event_registrations
761
+ # Mouse X and Y position in the window
762
+ @mouse_x = 0
763
+ @mouse_y = 0
764
+
765
+ # Controller axis and button mappings file
766
+ @controller_mappings = "#{File.expand_path('~')}/.ruby2d/controllers.txt"
767
+
768
+ # Unique ID for the input event being registered
769
+ @event_key = 0
770
+
771
+ # Registered input events
772
+ @events = {
773
+ key: {},
774
+ key_down: {},
775
+ key_held: {},
776
+ key_up: {},
777
+ mouse: {},
778
+ mouse_up: {},
779
+ mouse_down: {},
780
+ mouse_scroll: {},
781
+ mouse_move: {},
782
+ controller: {},
783
+ controller_axis: {},
784
+ controller_button_down: {},
785
+ controller_button_up: {}
786
+ }
787
+ end
788
+
789
+ def _init_procs_dsl_console
790
+ # The window update block
791
+ @update_proc = proc {}
792
+
793
+ # The window render block
794
+ @render_proc = proc {}
795
+
796
+ # Detect if window is being used through the DSL or as a class instance
797
+ @using_dsl = !(method(:update).parameters.empty? || method(:render).parameters.empty?)
798
+
799
+ # Whether diagnostic messages should be printed
800
+ @diagnostics = false
801
+
802
+ # Console mode, enabled at command line
803
+ @console = if RUBY_ENGINE == 'ruby'
804
+ ENV['RUBY2D_ENABLE_CONSOLE'] == 'true'
805
+ else
806
+ false
807
+ end
808
+ end
672
809
  end
673
810
  end