add Widget module
This commit is contained in:
parent
b455fb9e15
commit
f2d3942f8a
33
runtime/lib/widget.rb
Normal file
33
runtime/lib/widget.rb
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
module Widget
|
||||||
|
def initialize
|
||||||
|
@x = 0
|
||||||
|
@y = 0
|
||||||
|
@width = 0
|
||||||
|
@height = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
def children
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
|
||||||
|
def resize(x, y, width, height)
|
||||||
|
@x = x
|
||||||
|
@y = y
|
||||||
|
@width = width
|
||||||
|
@height = height
|
||||||
|
end
|
||||||
|
|
||||||
|
def draw
|
||||||
|
if @x > 0 and @y > 0
|
||||||
|
render_begin
|
||||||
|
render
|
||||||
|
children.each do |child|
|
||||||
|
child.draw
|
||||||
|
end
|
||||||
|
render_end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_end
|
||||||
|
end
|
||||||
|
end
|
@ -1,6 +1,8 @@
|
|||||||
require "set"
|
require "set"
|
||||||
|
|
||||||
class Window
|
class Window
|
||||||
|
include Widget
|
||||||
|
|
||||||
@windows = Set.new
|
@windows = Set.new
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
@ -5,6 +5,7 @@ end
|
|||||||
def load_lib_files
|
def load_lib_files
|
||||||
require "gl_program"
|
require "gl_program"
|
||||||
require "runtime"
|
require "runtime"
|
||||||
|
require "widget"
|
||||||
require "window"
|
require "window"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
23
src/Widget.cc
Normal file
23
src/Widget.cc
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include "Widget.h"
|
||||||
|
#include "ruby.h"
|
||||||
|
#include "gl3w.h"
|
||||||
|
|
||||||
|
static VALUE ruby_class;
|
||||||
|
|
||||||
|
static VALUE Widget_render_begin(VALUE self)
|
||||||
|
{
|
||||||
|
int x = FIX2INT(rb_iv_get(self, "@x"));
|
||||||
|
int y = FIX2INT(rb_iv_get(self, "@y"));
|
||||||
|
int width = FIX2INT(rb_iv_get(self, "@width"));
|
||||||
|
int height = FIX2INT(rb_iv_get(self, "@height"));
|
||||||
|
|
||||||
|
glViewport(x, y, width, height);
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Widget_Init()
|
||||||
|
{
|
||||||
|
ruby_class = rb_define_module("Widget");
|
||||||
|
rb_define_method(ruby_class, "render_begin", (VALUE(*)(...))Widget_render_begin, 0);
|
||||||
|
}
|
6
src/Widget.h
Normal file
6
src/Widget.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef WIDGET_H
|
||||||
|
#define WIDGET_H
|
||||||
|
|
||||||
|
void Widget_Init();
|
||||||
|
|
||||||
|
#endif
|
@ -4,6 +4,7 @@
|
|||||||
#include "Font.h"
|
#include "Font.h"
|
||||||
#include "GLProgram.h"
|
#include "GLProgram.h"
|
||||||
#include "GLShader.h"
|
#include "GLShader.h"
|
||||||
|
#include "Widget.h"
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -55,6 +56,7 @@ static int bootstrap()
|
|||||||
Font_Init();
|
Font_Init();
|
||||||
GLProgram_Init();
|
GLProgram_Init();
|
||||||
GLShader_Init();
|
GLShader_Init();
|
||||||
|
Widget_Init();
|
||||||
Window_Init();
|
Window_Init();
|
||||||
|
|
||||||
rb_eval_string_protect(
|
rb_eval_string_protect(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user