record all Windows, add Window.event_loop
This commit is contained in:
parent
8604d6d5ad
commit
b908c98c8c
@ -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
|
||||
|
37
src/GUI.cc
37
src/GUI.cc
@ -1,8 +1,4 @@
|
||||
#if 0
|
||||
#include "GUI.h"
|
||||
#include "gl3w.h"
|
||||
#include <iostream>
|
||||
|
||||
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];
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user