|
| 1 | +#include "ext_rgss.h" |
| 2 | +#include "graphics.h" |
| 3 | +#include "window.h" |
| 4 | +#include "rect.h" |
| 5 | +#include "bitmap.h" |
| 6 | + |
| 7 | +static void Window__mark(void *ptr) { |
| 8 | +} |
| 9 | + |
| 10 | +static void Window__free(void *ptr) { |
| 11 | + if(ptr) free(ptr); |
| 12 | +} |
| 13 | + |
| 14 | +static size_t Window__memsize(const void *ptr) { |
| 15 | + return ptr ? sizeof(Window) : 0; |
| 16 | +} |
| 17 | + |
| 18 | +const rb_data_type_t Window_data_type = { |
| 19 | + "window", {Window__mark, Window__free, Window__memsize,}, |
| 20 | +}; |
| 21 | + |
| 22 | +static VALUE Window_s_alloc(VALUE klass) { |
| 23 | + VALUE obj; |
| 24 | + Window *window; |
| 25 | + |
| 26 | + obj = TypedData_Make_Struct(klass, Window, &Window_data_type, window); |
| 27 | + |
| 28 | + return obj; |
| 29 | +} |
| 30 | + |
| 31 | +static VALUE Window_initialize(int argc, VALUE *argv, VALUE self) { |
| 32 | + VALUE windows = rb_ivar_get(mGraphics, rb_intern("@windows")); |
| 33 | + VALUE bmp_argv[2] = {INT2FIX(1), INT2FIX(1)}; |
| 34 | + VALUE contents = rb_class_new_instance(2, bmp_argv, cBitmap); |
| 35 | + VALUE cursor_rect = rb_class_new_instance(0, NULL, cRect); |
| 36 | + Window *window = EXT_WINDOW(self); |
| 37 | + |
| 38 | + rb_ary_push(windows, self); |
| 39 | + old_call(self, rb_intern("initialize"), argc, argv); |
| 40 | + |
| 41 | + contents = old_call(self, rb_intern("contents"), 0, NULL); /* TODO */ |
| 42 | + rb_ivar_set(self, rb_intern("@contents"), contents); |
| 43 | + |
| 44 | + cursor_rect = old_call(self, rb_intern("cursor_rect"), 0, NULL); /* TODO */ |
| 45 | + rb_ivar_set(self, rb_intern("@cursor_rect"), cursor_rect); |
| 46 | + Rect__add_ref(cursor_rect, self); |
| 47 | + window->cursor_rect = cursor_rect; |
| 48 | + |
| 49 | + window->x = window->y = 0; |
| 50 | + window->ox = window->oy = 0; |
| 51 | + window->disposed = 0; |
| 52 | + window->visible = 1; |
| 53 | + |
| 54 | + return self; |
| 55 | +} |
| 56 | + |
| 57 | +void Init_ExtWindow() { |
| 58 | + VALUE cOldWindow = rb_const_get(rb_cObject, rb_intern("Window")); |
| 59 | + VALUE cWindow = rb_define_class_under(mExtRgss, "Window", rb_cObject); |
| 60 | + rb_const_set(rb_cObject, rb_intern("OldWindow"), cOldWindow); |
| 61 | + rb_const_set(rb_cObject, rb_intern("Window"), cWindow); |
| 62 | + |
| 63 | + rb_define_alloc_func(cWindow, Window_s_alloc); |
| 64 | + rb_define_method(cWindow, "initialize", Window_initialize, -1); |
| 65 | +} |
0 commit comments