diff --git a/runtime/lib/window.rb b/runtime/lib/window.rb index 6cf382c..c5f2a3c 100644 --- a/runtime/lib/window.rb +++ b/runtime/lib/window.rb @@ -1,7 +1,26 @@ +require "set" + class Window + @windows = Set.new + + class << self + def register(window) + @windows << window + end + + def remove(window) + @windows.delete(window) + end + end + def initialize @programs = {} load_shaders + Window.register(self) + end + + def close + Window.remove(self) end private diff --git a/src/GUI.cc b/src/GUI.cc index f17b04a..5249b11 100644 --- a/src/GUI.cc +++ b/src/GUI.cc @@ -1,8 +1,4 @@ #if 0 -#include "GUI.h" -#include "gl3w.h" -#include - bool GUI::load() { glClearColor (0.0, 0.0, 0.0, 0.0); @@ -40,39 +36,6 @@ bool GUI::load_buffers() return true; } -int GUI::run() -{ - resize(); - draw(); - - SDL_Event event; - while (SDL_WaitEvent(&event)) - { - if (event.type == SDL_QUIT) - break; - else if (event.type == SDL_KEYDOWN) - { - if (event.key.keysym.sym == SDLK_ESCAPE) - break; - } - else if (event.type == SDL_WINDOWEVENT) - { - switch (event.window.event) - { - case SDL_WINDOWEVENT_EXPOSED: - draw(); - break; - case SDL_WINDOWEVENT_RESIZED: - resize(); - draw(); - break; - } - } - } - - return 0; -} - void GUI::resize() { GLint viewport_size[2]; diff --git a/src/Window.cc b/src/Window.cc index bbedd06..26b3396 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -97,8 +97,40 @@ static VALUE Window_new(VALUE klass) return rv; } +static VALUE Window_event_loop(VALUE klass) +{ + SDL_Event event; + + while (SDL_WaitEvent(&event)) + { + if (event.type == SDL_QUIT) + break; + else if (event.type == SDL_KEYDOWN) + { + if (event.key.keysym.sym == SDLK_ESCAPE) + break; + } + else if (event.type == SDL_WINDOWEVENT) + { + switch (event.window.event) + { + case SDL_WINDOWEVENT_EXPOSED: +// draw(); + break; + case SDL_WINDOWEVENT_RESIZED: +// resize(); +// draw(); + break; + } + } + } + + return Qnil; +} + void Window_Init(void) { ruby_class = rb_define_class("Window", rb_cObject); rb_define_singleton_method(ruby_class, "new", (VALUE(*)(...))Window_new, 0); + rb_define_singleton_method(ruby_class, "event_loop", (VALUE(*)(...))Window_event_loop, 0); }