ruby2d-rpeck-windows 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (289) hide show
  1. checksums.yaml +7 -0
  2. data/assets/README.md +22 -0
  3. data/assets/Rakefile +85 -0
  4. data/assets/app.icns +0 -0
  5. data/assets/include/SDL2/SDL.h +138 -0
  6. data/assets/include/SDL2/SDL_assert.h +293 -0
  7. data/assets/include/SDL2/SDL_atomic.h +295 -0
  8. data/assets/include/SDL2/SDL_audio.h +859 -0
  9. data/assets/include/SDL2/SDL_bits.h +121 -0
  10. data/assets/include/SDL2/SDL_blendmode.h +123 -0
  11. data/assets/include/SDL2/SDL_clipboard.h +71 -0
  12. data/assets/include/SDL2/SDL_config.h +55 -0
  13. data/assets/include/SDL2/SDL_config_android.h +182 -0
  14. data/assets/include/SDL2/SDL_config_iphoneos.h +207 -0
  15. data/assets/include/SDL2/SDL_config_macosx.h +266 -0
  16. data/assets/include/SDL2/SDL_config_minimal.h +85 -0
  17. data/assets/include/SDL2/SDL_config_os2.h +188 -0
  18. data/assets/include/SDL2/SDL_config_pandora.h +135 -0
  19. data/assets/include/SDL2/SDL_config_psp.h +165 -0
  20. data/assets/include/SDL2/SDL_config_windows.h +288 -0
  21. data/assets/include/SDL2/SDL_config_winrt.h +243 -0
  22. data/assets/include/SDL2/SDL_config_wiz.h +149 -0
  23. data/assets/include/SDL2/SDL_copying.h +20 -0
  24. data/assets/include/SDL2/SDL_cpuinfo.h +299 -0
  25. data/assets/include/SDL2/SDL_egl.h +1676 -0
  26. data/assets/include/SDL2/SDL_endian.h +263 -0
  27. data/assets/include/SDL2/SDL_error.h +112 -0
  28. data/assets/include/SDL2/SDL_events.h +827 -0
  29. data/assets/include/SDL2/SDL_filesystem.h +136 -0
  30. data/assets/include/SDL2/SDL_gamecontroller.h +541 -0
  31. data/assets/include/SDL2/SDL_gesture.h +87 -0
  32. data/assets/include/SDL2/SDL_haptic.h +1247 -0
  33. data/assets/include/SDL2/SDL_hints.h +1578 -0
  34. data/assets/include/SDL2/SDL_image.h +161 -0
  35. data/assets/include/SDL2/SDL_joystick.h +499 -0
  36. data/assets/include/SDL2/SDL_keyboard.h +217 -0
  37. data/assets/include/SDL2/SDL_keycode.h +351 -0
  38. data/assets/include/SDL2/SDL_loadso.h +81 -0
  39. data/assets/include/SDL2/SDL_locale.h +101 -0
  40. data/assets/include/SDL2/SDL_log.h +211 -0
  41. data/assets/include/SDL2/SDL_main.h +180 -0
  42. data/assets/include/SDL2/SDL_messagebox.h +146 -0
  43. data/assets/include/SDL2/SDL_metal.h +117 -0
  44. data/assets/include/SDL2/SDL_misc.h +75 -0
  45. data/assets/include/SDL2/SDL_mixer.h +651 -0
  46. data/assets/include/SDL2/SDL_mouse.h +302 -0
  47. data/assets/include/SDL2/SDL_mutex.h +251 -0
  48. data/assets/include/SDL2/SDL_name.h +33 -0
  49. data/assets/include/SDL2/SDL_opengl.h +2183 -0
  50. data/assets/include/SDL2/SDL_opengl_glext.h +11180 -0
  51. data/assets/include/SDL2/SDL_opengles.h +39 -0
  52. data/assets/include/SDL2/SDL_opengles2.h +52 -0
  53. data/assets/include/SDL2/SDL_opengles2_gl2.h +621 -0
  54. data/assets/include/SDL2/SDL_opengles2_gl2ext.h +2050 -0
  55. data/assets/include/SDL2/SDL_opengles2_gl2platform.h +30 -0
  56. data/assets/include/SDL2/SDL_opengles2_khrplatform.h +282 -0
  57. data/assets/include/SDL2/SDL_pixels.h +479 -0
  58. data/assets/include/SDL2/SDL_platform.h +198 -0
  59. data/assets/include/SDL2/SDL_power.h +75 -0
  60. data/assets/include/SDL2/SDL_quit.h +58 -0
  61. data/assets/include/SDL2/SDL_rect.h +174 -0
  62. data/assets/include/SDL2/SDL_render.h +1158 -0
  63. data/assets/include/SDL2/SDL_revision.h +2 -0
  64. data/assets/include/SDL2/SDL_rwops.h +283 -0
  65. data/assets/include/SDL2/SDL_scancode.h +413 -0
  66. data/assets/include/SDL2/SDL_sensor.h +267 -0
  67. data/assets/include/SDL2/SDL_shape.h +144 -0
  68. data/assets/include/SDL2/SDL_stdinc.h +647 -0
  69. data/assets/include/SDL2/SDL_surface.h +563 -0
  70. data/assets/include/SDL2/SDL_system.h +325 -0
  71. data/assets/include/SDL2/SDL_syswm.h +354 -0
  72. data/assets/include/SDL2/SDL_test.h +69 -0
  73. data/assets/include/SDL2/SDL_test_assert.h +105 -0
  74. data/assets/include/SDL2/SDL_test_common.h +218 -0
  75. data/assets/include/SDL2/SDL_test_compare.h +69 -0
  76. data/assets/include/SDL2/SDL_test_crc32.h +124 -0
  77. data/assets/include/SDL2/SDL_test_font.h +81 -0
  78. data/assets/include/SDL2/SDL_test_fuzzer.h +384 -0
  79. data/assets/include/SDL2/SDL_test_harness.h +134 -0
  80. data/assets/include/SDL2/SDL_test_images.h +78 -0
  81. data/assets/include/SDL2/SDL_test_log.h +67 -0
  82. data/assets/include/SDL2/SDL_test_md5.h +129 -0
  83. data/assets/include/SDL2/SDL_test_memory.h +63 -0
  84. data/assets/include/SDL2/SDL_test_random.h +115 -0
  85. data/assets/include/SDL2/SDL_thread.h +366 -0
  86. data/assets/include/SDL2/SDL_timer.h +115 -0
  87. data/assets/include/SDL2/SDL_touch.h +102 -0
  88. data/assets/include/SDL2/SDL_ttf.h +294 -0
  89. data/assets/include/SDL2/SDL_types.h +29 -0
  90. data/assets/include/SDL2/SDL_version.h +162 -0
  91. data/assets/include/SDL2/SDL_video.h +1282 -0
  92. data/assets/include/SDL2/SDL_vulkan.h +276 -0
  93. data/assets/include/SDL2/begin_code.h +166 -0
  94. data/assets/include/SDL2/close_code.h +40 -0
  95. data/assets/include/glew.h +23686 -0
  96. data/assets/ios/Assets.xcassets/AppIcon.appiconset/Contents.json +98 -0
  97. data/assets/ios/Assets.xcassets/Contents.json +6 -0
  98. data/assets/ios/Base.lproj/LaunchScreen.storyboard +27 -0
  99. data/assets/ios/Info.plist +43 -0
  100. data/assets/ios/MRuby.framework/Headers/mrbconf.h +143 -0
  101. data/assets/ios/MRuby.framework/Headers/mruby/array.h +280 -0
  102. data/assets/ios/MRuby.framework/Headers/mruby/boxing_nan.h +102 -0
  103. data/assets/ios/MRuby.framework/Headers/mruby/boxing_no.h +56 -0
  104. data/assets/ios/MRuby.framework/Headers/mruby/boxing_word.h +144 -0
  105. data/assets/ios/MRuby.framework/Headers/mruby/class.h +97 -0
  106. data/assets/ios/MRuby.framework/Headers/mruby/common.h +77 -0
  107. data/assets/ios/MRuby.framework/Headers/mruby/compile.h +195 -0
  108. data/assets/ios/MRuby.framework/Headers/mruby/data.h +75 -0
  109. data/assets/ios/MRuby.framework/Headers/mruby/debug.h +67 -0
  110. data/assets/ios/MRuby.framework/Headers/mruby/dump.h +196 -0
  111. data/assets/ios/MRuby.framework/Headers/mruby/error.h +75 -0
  112. data/assets/ios/MRuby.framework/Headers/mruby/gc.h +91 -0
  113. data/assets/ios/MRuby.framework/Headers/mruby/hash.h +215 -0
  114. data/assets/ios/MRuby.framework/Headers/mruby/irep.h +75 -0
  115. data/assets/ios/MRuby.framework/Headers/mruby/istruct.h +47 -0
  116. data/assets/ios/MRuby.framework/Headers/mruby/khash.h +274 -0
  117. data/assets/ios/MRuby.framework/Headers/mruby/numeric.h +161 -0
  118. data/assets/ios/MRuby.framework/Headers/mruby/object.h +44 -0
  119. data/assets/ios/MRuby.framework/Headers/mruby/opcode.h +69 -0
  120. data/assets/ios/MRuby.framework/Headers/mruby/ops.h +117 -0
  121. data/assets/ios/MRuby.framework/Headers/mruby/proc.h +131 -0
  122. data/assets/ios/MRuby.framework/Headers/mruby/range.h +49 -0
  123. data/assets/ios/MRuby.framework/Headers/mruby/re.h +16 -0
  124. data/assets/ios/MRuby.framework/Headers/mruby/string.h +444 -0
  125. data/assets/ios/MRuby.framework/Headers/mruby/throw.h +55 -0
  126. data/assets/ios/MRuby.framework/Headers/mruby/value.h +309 -0
  127. data/assets/ios/MRuby.framework/Headers/mruby/variable.h +136 -0
  128. data/assets/ios/MRuby.framework/Headers/mruby/version.h +110 -0
  129. data/assets/ios/MRuby.framework/Headers/mruby.h +1282 -0
  130. data/assets/ios/MRuby.framework/Info.plist +20 -0
  131. data/assets/ios/MRuby.framework/MRuby +0 -0
  132. data/assets/ios/MyApp.xcodeproj/project.pbxproj +368 -0
  133. data/assets/ios/MyApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  134. data/assets/ios/MyApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  135. data/assets/ios/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint +30 -0
  136. data/assets/ios/main.c +1 -0
  137. data/assets/macos/lib/libFLAC.a +0 -0
  138. data/assets/macos/lib/libSDL2.a +0 -0
  139. data/assets/macos/lib/libSDL2_image.a +0 -0
  140. data/assets/macos/lib/libSDL2_mixer.a +0 -0
  141. data/assets/macos/lib/libSDL2_ttf.a +0 -0
  142. data/assets/macos/lib/libfreetype.a +0 -0
  143. data/assets/macos/lib/libjpeg.a +0 -0
  144. data/assets/macos/lib/libmodplug.a +0 -0
  145. data/assets/macos/lib/libmpg123.a +0 -0
  146. data/assets/macos/lib/libogg.a +0 -0
  147. data/assets/macos/lib/libpng16.a +0 -0
  148. data/assets/macos/lib/libtiff.a +0 -0
  149. data/assets/macos/lib/libvorbis.a +0 -0
  150. data/assets/macos/lib/libvorbisfile.a +0 -0
  151. data/assets/macos/lib/libwebp.a +0 -0
  152. data/assets/mingw/bin/SDL2.dll +0 -0
  153. data/assets/mingw/bin/SDL2_image.dll +0 -0
  154. data/assets/mingw/bin/SDL2_mixer.dll +0 -0
  155. data/assets/mingw/bin/SDL2_ttf.dll +0 -0
  156. data/assets/mingw/bin/glew32.dll +0 -0
  157. data/assets/mingw/bin/libFLAC-8.dll +0 -0
  158. data/assets/mingw/bin/libfreetype-6.dll +0 -0
  159. data/assets/mingw/bin/libjpeg-9.dll +0 -0
  160. data/assets/mingw/bin/libmodplug-1.dll +0 -0
  161. data/assets/mingw/bin/libmpg123-0.dll +0 -0
  162. data/assets/mingw/bin/libogg-0.dll +0 -0
  163. data/assets/mingw/bin/libopus-0.dll +0 -0
  164. data/assets/mingw/bin/libopusfile-0.dll +0 -0
  165. data/assets/mingw/bin/libpng16-16.dll +0 -0
  166. data/assets/mingw/bin/libtiff-5.dll +0 -0
  167. data/assets/mingw/bin/libvorbis-0.dll +0 -0
  168. data/assets/mingw/bin/libvorbisfile-3.dll +0 -0
  169. data/assets/mingw/bin/libwebp-7.dll +0 -0
  170. data/assets/mingw/bin/libwinpthread-1.dll +0 -0
  171. data/assets/mingw/bin/zlib1.dll +0 -0
  172. data/assets/mingw/lib/libSDL2.a +0 -0
  173. data/assets/mingw/lib/libSDL2.dll.a +0 -0
  174. data/assets/mingw/lib/libSDL2_image.a +0 -0
  175. data/assets/mingw/lib/libSDL2_image.dll.a +0 -0
  176. data/assets/mingw/lib/libSDL2_mixer.a +0 -0
  177. data/assets/mingw/lib/libSDL2_mixer.dll.a +0 -0
  178. data/assets/mingw/lib/libSDL2_test.a +0 -0
  179. data/assets/mingw/lib/libSDL2_ttf.a +0 -0
  180. data/assets/mingw/lib/libSDL2_ttf.dll.a +0 -0
  181. data/assets/mingw/lib/libSDL2main.a +0 -0
  182. data/assets/mingw/lib/libglew32.a +0 -0
  183. data/assets/mingw/lib/libglew32.dll.a +0 -0
  184. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Content.imageset/Contents.json +16 -0
  185. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Contents.json +6 -0
  186. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Contents.json +17 -0
  187. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Content.imageset/Contents.json +16 -0
  188. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Contents.json +6 -0
  189. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json +16 -0
  190. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Contents.json +6 -0
  191. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Content.imageset/Contents.json +16 -0
  192. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Contents.json +6 -0
  193. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Contents.json +17 -0
  194. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Content.imageset/Contents.json +16 -0
  195. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Contents.json +6 -0
  196. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json +16 -0
  197. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Contents.json +6 -0
  198. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Contents.json +32 -0
  199. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image Wide.imageset/Contents.json +16 -0
  200. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image.imageset/Contents.json +16 -0
  201. data/assets/tvos/Assets.xcassets/Contents.json +6 -0
  202. data/assets/tvos/Assets.xcassets/LaunchImage.launchimage/Contents.json +22 -0
  203. data/assets/tvos/Info.plist +30 -0
  204. data/assets/tvos/MRuby.framework/Headers/mrbconf.h +143 -0
  205. data/assets/tvos/MRuby.framework/Headers/mruby/array.h +280 -0
  206. data/assets/tvos/MRuby.framework/Headers/mruby/boxing_nan.h +102 -0
  207. data/assets/tvos/MRuby.framework/Headers/mruby/boxing_no.h +56 -0
  208. data/assets/tvos/MRuby.framework/Headers/mruby/boxing_word.h +144 -0
  209. data/assets/tvos/MRuby.framework/Headers/mruby/class.h +97 -0
  210. data/assets/tvos/MRuby.framework/Headers/mruby/common.h +77 -0
  211. data/assets/tvos/MRuby.framework/Headers/mruby/compile.h +195 -0
  212. data/assets/tvos/MRuby.framework/Headers/mruby/data.h +75 -0
  213. data/assets/tvos/MRuby.framework/Headers/mruby/debug.h +67 -0
  214. data/assets/tvos/MRuby.framework/Headers/mruby/dump.h +196 -0
  215. data/assets/tvos/MRuby.framework/Headers/mruby/error.h +75 -0
  216. data/assets/tvos/MRuby.framework/Headers/mruby/gc.h +91 -0
  217. data/assets/tvos/MRuby.framework/Headers/mruby/hash.h +215 -0
  218. data/assets/tvos/MRuby.framework/Headers/mruby/irep.h +75 -0
  219. data/assets/tvos/MRuby.framework/Headers/mruby/istruct.h +47 -0
  220. data/assets/tvos/MRuby.framework/Headers/mruby/khash.h +274 -0
  221. data/assets/tvos/MRuby.framework/Headers/mruby/numeric.h +161 -0
  222. data/assets/tvos/MRuby.framework/Headers/mruby/object.h +44 -0
  223. data/assets/tvos/MRuby.framework/Headers/mruby/opcode.h +69 -0
  224. data/assets/tvos/MRuby.framework/Headers/mruby/ops.h +117 -0
  225. data/assets/tvos/MRuby.framework/Headers/mruby/proc.h +131 -0
  226. data/assets/tvos/MRuby.framework/Headers/mruby/range.h +49 -0
  227. data/assets/tvos/MRuby.framework/Headers/mruby/re.h +16 -0
  228. data/assets/tvos/MRuby.framework/Headers/mruby/string.h +444 -0
  229. data/assets/tvos/MRuby.framework/Headers/mruby/throw.h +55 -0
  230. data/assets/tvos/MRuby.framework/Headers/mruby/value.h +309 -0
  231. data/assets/tvos/MRuby.framework/Headers/mruby/variable.h +136 -0
  232. data/assets/tvos/MRuby.framework/Headers/mruby/version.h +110 -0
  233. data/assets/tvos/MRuby.framework/Headers/mruby.h +1282 -0
  234. data/assets/tvos/MRuby.framework/Info.plist +20 -0
  235. data/assets/tvos/MRuby.framework/MRuby +0 -0
  236. data/assets/tvos/MyApp.xcodeproj/project.pbxproj +350 -0
  237. data/assets/tvos/MyApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  238. data/assets/tvos/MyApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  239. data/assets/tvos/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint +30 -0
  240. data/assets/tvos/main.c +1 -0
  241. data/bin/ruby2d +142 -0
  242. data/ext/ruby2d/common.c +185 -0
  243. data/ext/ruby2d/controllers.c +110 -0
  244. data/ext/ruby2d/extconf.rb +147 -0
  245. data/ext/ruby2d/font.c +35 -0
  246. data/ext/ruby2d/gl.c +398 -0
  247. data/ext/ruby2d/gl2.c +86 -0
  248. data/ext/ruby2d/gl3.c +305 -0
  249. data/ext/ruby2d/gles.c +249 -0
  250. data/ext/ruby2d/image.c +58 -0
  251. data/ext/ruby2d/input.c +48 -0
  252. data/ext/ruby2d/music.c +127 -0
  253. data/ext/ruby2d/ruby2d.c +1374 -0
  254. data/ext/ruby2d/ruby2d.h +656 -0
  255. data/ext/ruby2d/shapes.c +154 -0
  256. data/ext/ruby2d/sound.c +118 -0
  257. data/ext/ruby2d/text.c +22 -0
  258. data/ext/ruby2d/window.c +414 -0
  259. data/lib/ruby2d/circle.rb +43 -0
  260. data/lib/ruby2d/cli/build.rb +237 -0
  261. data/lib/ruby2d/cli/colorize.rb +10 -0
  262. data/lib/ruby2d/cli/console.rb +65 -0
  263. data/lib/ruby2d/cli/enable_console.rb +5 -0
  264. data/lib/ruby2d/cli/launch.rb +50 -0
  265. data/lib/ruby2d/color.rb +136 -0
  266. data/lib/ruby2d/dsl.rb +46 -0
  267. data/lib/ruby2d/entity.rb +17 -0
  268. data/lib/ruby2d/exceptions.rb +6 -0
  269. data/lib/ruby2d/font.rb +96 -0
  270. data/lib/ruby2d/image.rb +58 -0
  271. data/lib/ruby2d/line.rb +89 -0
  272. data/lib/ruby2d/music.rb +67 -0
  273. data/lib/ruby2d/pixel.rb +17 -0
  274. data/lib/ruby2d/quad.rb +96 -0
  275. data/lib/ruby2d/rectangle.rb +65 -0
  276. data/lib/ruby2d/renderable.rb +40 -0
  277. data/lib/ruby2d/ruby2d.so +0 -0
  278. data/lib/ruby2d/sound.rb +55 -0
  279. data/lib/ruby2d/sprite.rb +232 -0
  280. data/lib/ruby2d/square.rb +37 -0
  281. data/lib/ruby2d/text.rb +76 -0
  282. data/lib/ruby2d/texture.rb +28 -0
  283. data/lib/ruby2d/tileset.rb +87 -0
  284. data/lib/ruby2d/triangle.rb +82 -0
  285. data/lib/ruby2d/version.rb +5 -0
  286. data/lib/ruby2d/vertices.rb +84 -0
  287. data/lib/ruby2d/window.rb +673 -0
  288. data/lib/ruby2d.rb +69 -0
  289. metadata +346 -0
@@ -0,0 +1,673 @@
1
+ # 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
+
5
+ module Ruby2D
6
+ class Window
7
+ @@open_window = false
8
+
9
+ # Event structures
10
+ EventDescriptor = Struct.new(:type, :id)
11
+ MouseEvent = Struct.new(:type, :button, :direction, :x, :y, :delta_x, :delta_y)
12
+ KeyEvent = Struct.new(:type, :key)
13
+ ControllerEvent = Struct.new(:which, :type, :axis, :value, :button)
14
+ ControllerAxisEvent = Struct.new(:which, :axis, :value)
15
+ ControllerButtonEvent = Struct.new(:which, :button)
16
+
17
+ def initialize(args = {})
18
+
19
+ # 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
41
+
42
+ # Total number of frames that have been rendered
43
+ @frames = 0
44
+
45
+ # Frames per second upper limit, and the actual FPS
46
+ @fps_cap = args[:fps_cap] || 60
47
+ @fps = @fps_cap
48
+
49
+ # Vertical synchronization, set to prevent screen tearing (recommended)
50
+ @vsync = args[:vsync] || true
51
+
52
+ # Renderable objects currently in the window, like a linear scene graph
53
+ @objects = []
54
+
55
+ # Entities currently in the window
56
+ @entities = []
57
+
58
+ # Mouse X and Y position in the window
59
+ @mouse_x, @mouse_y = 0, 0
60
+
61
+ # Controller axis and button mappings file
62
+ @controller_mappings = File.expand_path('~') + "/.ruby2d/controllers.txt"
63
+
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 = []
85
+
86
+ # Unique ID for the input event being registered
87
+ @event_key = 0
88
+
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
+ }
105
+
106
+ # The window update block
107
+ @update_proc = Proc.new {}
108
+
109
+ # The window render block
110
+ @render_proc = Proc.new {}
111
+
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?)
114
+
115
+ # Whether diagnostic messages should be printed
116
+ @diagnostics = false
117
+
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
123
+ end
124
+ end
125
+
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
148
+
149
+ def get(sym, opts = nil)
150
+ DSL.window.get(sym, opts)
151
+ end
152
+
153
+ def set(opts)
154
+ DSL.window.set(opts)
155
+ end
156
+
157
+ def on(event, &proc)
158
+ DSL.window.on(event, &proc)
159
+ end
160
+
161
+ def off(event_descriptor)
162
+ DSL.window.off(event_descriptor)
163
+ end
164
+
165
+ def add(o)
166
+ DSL.window.add(o)
167
+ end
168
+
169
+ def remove(o)
170
+ DSL.window.remove(o)
171
+ end
172
+
173
+ def clear
174
+ DSL.window.clear
175
+ end
176
+
177
+ def update(&proc)
178
+ DSL.window.update(&proc)
179
+ end
180
+
181
+ def render(&proc)
182
+ DSL.window.render(&proc)
183
+ end
184
+
185
+ def show
186
+ DSL.window.show
187
+ end
188
+
189
+ def close
190
+ DSL.window.close
191
+ end
192
+
193
+ 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
197
+ end
198
+ end
199
+
200
+ # Public instance methods
201
+
202
+ # Retrieve an attribute of the window
203
+ def get(sym, opts = nil)
204
+ 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
212
+ when :display_width, :display_height
213
+ ext_get_display_dimensions
214
+ if sym == :display_width
215
+ @display_width
216
+ else
217
+ @display_height
218
+ 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
232
+
233
+ # Set a window attribute
234
+ def set(opts)
235
+ # 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
254
+ end
255
+
256
+ # Add an object to the window
257
+ def add(o)
258
+ case o
259
+ when nil
260
+ raise Error, "Cannot add '#{o.class}' to window!"
261
+ #when Ruby2D::Entity
262
+ #@entities.push(o)
263
+ when Array
264
+ o.each { |x| add_object(x) }
265
+ else
266
+ add_object(o)
267
+ end
268
+ end
269
+
270
+ # 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
275
+
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
283
+ end
284
+
285
+ # Clear all objects from the window
286
+ def clear
287
+ @objects.clear
288
+ @entities.clear
289
+ end
290
+
291
+ # Set the update callback
292
+ def update(&proc)
293
+ @update_proc = proc
294
+ true
295
+ end
296
+
297
+ # Set the render callback
298
+ def render(&proc)
299
+ @render_proc = proc
300
+ true
301
+ end
302
+
303
+ # Generate a new event key (ID)
304
+ def new_event_key
305
+ @event_key = @event_key.next
306
+ end
307
+
308
+ # Set an event handler
309
+ def on(event, &proc)
310
+ unless @events.has_key? event
311
+ raise Error, "`#{event}` is not a valid event type"
312
+ end
313
+ event_id = new_event_key
314
+ @events[event][event_id] = proc
315
+ EventDescriptor.new(event, event_id)
316
+ end
317
+
318
+ # Remove an event handler
319
+ def off(event_descriptor)
320
+ @events[event_descriptor.type].delete(event_descriptor.id)
321
+ end
322
+
323
+ # Key down event method for class pattern
324
+ def key_down(key)
325
+ @keys_down.include? key
326
+ end
327
+
328
+ # Key held event method for class pattern
329
+ def key_held(key)
330
+ @keys_held.include? key
331
+ end
332
+
333
+ # Key up event method for class pattern
334
+ def key_up(key)
335
+ @keys_up.include? key
336
+ end
337
+
338
+ # Key callback method, called by the native and web extentions
339
+ def key_callback(type, key)
340
+ key = key.downcase
341
+
342
+ # All key events
343
+ @events[:key].each do |id, e|
344
+ e.call(KeyEvent.new(type, key))
345
+ end
346
+
347
+ case type
348
+ # When key is pressed, fired once
349
+ 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
361
+ # When key is being held down, fired every frame
362
+ 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
374
+ # When key released, fired once
375
+ 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
387
+ end
388
+ end
389
+
390
+ # Mouse down event method for class pattern
391
+ def mouse_down(btn)
392
+ @mouse_buttons_down.include? btn
393
+ end
394
+
395
+ # Mouse up event method for class pattern
396
+ def mouse_up(btn)
397
+ @mouse_buttons_up.include? btn
398
+ end
399
+
400
+ # Mouse scroll event method for class pattern
401
+ def mouse_scroll
402
+ @mouse_scroll_event
403
+ end
404
+
405
+ # Mouse move event method for class pattern
406
+ def mouse_move
407
+ @mouse_move_event
408
+ end
409
+
410
+ # Mouse callback method, called by the native and web extentions
411
+ def mouse_callback(type, button, direction, x, y, delta_x, delta_y)
412
+ # All mouse events
413
+ @events[:mouse].each do |id, e|
414
+ e.call(MouseEvent.new(type, button, direction, x, y, delta_x, delta_y))
415
+ end
416
+
417
+ case type
418
+ # When mouse button pressed
419
+ 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
431
+ # When mouse button released
432
+ 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
444
+ # When mouse motion / movement
445
+ 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
458
+ # When mouse scrolling, wheel or trackpad
459
+ 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
471
+ end
472
+ end
473
+
474
+ # Add controller mappings from file
475
+ def add_controller_mappings
476
+ if File.exist? @controller_mappings
477
+ ext_add_controller_mappings(@controller_mappings)
478
+ end
479
+ end
480
+
481
+ # Controller axis event method for class pattern
482
+ def controller_axis(axis)
483
+ @controller_axes_moved.include? axis
484
+ end
485
+
486
+ # Controller button down event method for class pattern
487
+ def controller_button_down(btn)
488
+ @controller_buttons_down.include? btn
489
+ end
490
+
491
+ # Controller button up event method for class pattern
492
+ def controller_button_up(btn)
493
+ @controller_buttons_up.include? btn
494
+ end
495
+
496
+ # Controller callback method, called by the native and web extentions
497
+ def controller_callback(which, type, axis, value, button)
498
+ # All controller events
499
+ @events[:controller].each do |id, e|
500
+ e.call(ControllerEvent.new(which, type, axis, value, button))
501
+ end
502
+
503
+ case type
504
+ # When controller axis motion, like analog sticks
505
+ 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
531
+ # When controller button is pressed
532
+ 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
545
+ # When controller button is released
546
+ 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
559
+ end
560
+ end
561
+
562
+ # Update callback method, called by the native and web extentions
563
+ def update_callback
564
+ unless @using_dsl
565
+ update
566
+ end
567
+
568
+ @update_proc.call
569
+
570
+ # Run update method on all entities
571
+ @entities.each do |e|
572
+ e.update
573
+ end
574
+
575
+ # 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
592
+
593
+ # 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
606
+ end
607
+
608
+ # Render callback method, called by the native and web extentions
609
+ def render_callback
610
+ unless @using_dsl
611
+ render
612
+ end
613
+
614
+ @render_proc.call
615
+
616
+ # Run render method on all entities
617
+ @entities.each do |e|
618
+ e.render
619
+ end
620
+ end
621
+
622
+ # Show the window
623
+ def show
624
+ if @@open_window
625
+ raise Error, "Window#show called multiple times, Ruby2D only supports a single open window"
626
+ end
627
+
628
+ @@open_window = true
629
+ ext_show
630
+ end
631
+
632
+ # Take screenshot
633
+ def screenshot(path)
634
+ if path
635
+ ext_screenshot(path)
636
+ 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
642
+ ext_screenshot("./screenshot-#{time}.png")
643
+ end
644
+ end
645
+
646
+ # Close the window
647
+ def close
648
+ ext_close
649
+ end
650
+
651
+ # Private instance methods
652
+
653
+ private
654
+
655
+ # 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
660
+ end
661
+ if index
662
+ @objects.insert(index, o)
663
+ else
664
+ @objects.push(o)
665
+ end
666
+ true
667
+ else
668
+ false
669
+ end
670
+ end
671
+
672
+ end
673
+ end