Skip to content

Commit 33375f2

Browse files
committed
add Window.
1 parent af0f676 commit 33375f2

8 files changed

Lines changed: 91 additions & 3 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LOADSO_DIR=LoadSo
55
LDFLAGS=$(LIBDIRS) -shared
66
EXT=ExtRgss.so
77
CFLAGS=$(INCDIRS) -Wall -DDLL_NAME="\"$(EXT)\""
8-
OBJS=ext_rgss.o ext_rgss.def graphics.o bitmap.o sprite.o rect.o
8+
OBJS=ext_rgss.o ext_rgss.def graphics.o bitmap.o sprite.o rect.o window.o
99
LIBS=d3dx9.lib -ld3d9 -lloadso
1010
GAME=./Game.exe
1111
HEADERS=ext_rgss.h

bitmap.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "ext_rgss.h"
22
#include "bitmap.h"
33

4+
VALUE cBitmap;
5+
46
static void BitmapData__update(RgssBitmapData *bmpdata) {
57
BitmapExtData *extdata;
68

@@ -35,7 +37,7 @@ static VALUE Bitmap_initialize(int argc, VALUE *argv, VALUE self) {
3537
}
3638

3739
void Init_ExtBitmap() {
38-
VALUE cBitmap = rb_const_get(rb_cObject, rb_intern("Bitmap"));
40+
cBitmap = rb_const_get(rb_cObject, rb_intern("Bitmap"));
3941
rb_define_alias(cBitmap, "old_initialize", "initialize");
4042
rb_define_method(cBitmap, "initialize", Bitmap_initialize, -1);
4143
}

bitmap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ typedef struct {
66
} BitmapExtData;
77
#define BITMAP_EXTDATA(bmpdata) ((BitmapExtData*)((bmpdata)->info->biClrImportant))
88

9+
extern VALUE cBitmap;
10+
911
extern void Bitmap__init_extdata(VALUE bmp);
1012
extern void Init_ExtBitmap();

ext_rgss.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "ext_rgss.h"
22
#include "graphics.h"
33
#include "bitmap.h"
4+
#include "rect.h"
5+
#include "window.h"
46

57
VALUE mExtRgss;
68

@@ -14,4 +16,5 @@ void Init_ExtRgss() {
1416
Init_ExtBitmap();
1517
Init_ExtSprite();
1618
Init_ExtRect();
19+
Init_ExtWindow();
1720
}

ext_rgss.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# encoding: utf-8
2+
#__END__
23
require_so "ExtRgss"
34
Graphics.init
45

56
# generate stub and show TODO
6-
[:Graphics, :Sprite].each do |name|
7+
[:Graphics, :Sprite, :Window].each do |name|
78
old_name = "Old#{name}".intern
89
method_list = Object.const_get(old_name).methods(false) - Object.const_get(name).methods(false)
910
method_list.sort!

graphics.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ void Init_ExtGraphics() {
149149
mGraphics = rb_define_module_under(mExtRgss, "Graphics");
150150
VALUE sprites = rb_ary_new();
151151
rb_ivar_set(mGraphics, rb_intern("@sprites"), sprites);
152+
VALUE windows = rb_ary_new();
153+
rb_ivar_set(mGraphics, rb_intern("@windows"), windows);
152154
rb_const_set(rb_cObject, rb_intern("OldGraphics"), mOldGraphics);
153155
rb_const_set(rb_cObject, rb_intern("Graphics"), mGraphics);
154156
rb_define_singleton_method(mGraphics, "init", Graphics_s_init, 0);

window.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
}

window.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
typedef struct {
2+
VALUE content;
3+
VALUE cursor_rect;
4+
VERTEX vertex_data[8];
5+
int x, y, ox, oy;
6+
int disposed, visible;
7+
} Window;
8+
#define EXT_WINDOW(val) ((Window*)(DATA_PTR(val)))
9+
10+
extern const rb_data_type_t Window_data_type;
11+
12+
void Init_ExtWindow();
13+
//void Window__update_rect(Window *window);

0 commit comments

Comments
 (0)