summaryrefslogtreecommitdiffhomepage
path: root/src/raylib.c
blob: 23d75ac6e506feca0abeeb82597123feb6badfcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <raylib.h>
#include <mruby.h>
#include <mruby/array.h>
#if defined(PLATFORM_WEB)
#include <emscripten/emscripten.h>
#endif

void call_main_loop();

	static mrb_value
mrb_init_window(mrb_state *mrb, mrb_value self)
{
	mrb_int screenWidth = 800;
	mrb_int screenHeight = 600;
	char* title = "Hello World from FelFlame!";
	mrb_get_args(mrb, "|iiz", &screenWidth, &screenHeight, &title);

	InitWindow(screenWidth, screenHeight, title);

	return mrb_nil_value();
}

	static mrb_value
mrb_platform(mrb_state *mrb, mrb_value self)
{
#ifdef defined(PLATFORM_WEB)
	return mrb_str_new_lit(mrb, "web");
#else
	return mrb_str_new_lit(mrb, "desktop");
#endif
}

//void DrawText(const char *text, int posX, int posY, int fontSize, Color color);
	static mrb_value
mrb_draw_text(mrb_state *mrb, mrb_value self)
{
	char* text = "Default Text";
	mrb_int x = 0;
	mrb_int y = 0;
	mrb_int fontSize = 16;
	//mrb_value color = mrb_ary_new(mrb);
	//mrb_int temp = 200;
	//mrb_int temp2 = 255;
    //mrb_ary_push(mrb, color, temp);
	//mrb_ary_push(mrb, color, temp);
	//mrb_ary_push(mrb, color, temp);
	//mrb_ary_push(mrb, color, temp2);
	mrb_get_args(mrb, "|ziii", &text, &x, &y, &fontSize);
	//mrb_value mrb_ary_ref(mrb_state *, mrb_value, mrb_int)
	//Color result_color = (Color){mrb_ary_ref(mrb,color,0),mrb_ary_ref(mrb,color,1),mrb_ary_ref(mrb,color,2),mrb_ary_ref(mrb,color,3),};
	DrawText(text, x, y, fontSize, RED);
	return mrb_nil_value();
}

	static mrb_value
mrb_begin_drawing(mrb_state *mrb, mrb_value self)
{
	BeginDrawing();
	return mrb_nil_value();
}

	static mrb_value
mrb_end_drawing(mrb_state *mrb, mrb_value self)
{
	EndDrawing();
	return mrb_nil_value();
}

    static mrb_value
mrb_clear_background(mrb_state *mrb, mrb_value self)
{
	ClearBackground(RAYWHITE);
	return mrb_nil_value();
}

    void
call_main_loop()
{
    mrb_state *mrb = mrb_open();
    if (!mrb) {}
    printf("test");
    struct RClass *c = mrb_class_get(mrb, "Raylib");
    printf("test2");
    mrb_value main_loop = mrb_funcall(mrb, mrb_obj_value(c), "main_loop", 0);
    mrb_funcall(mrb, main_loop, "call", 0);
}

    static mrb_value
mrb_execute_main_loop(mrb_state *mrb, mrb_value self)
{
#if defined(PLATFORM_WEB)
    emscripten_set_main_loop(call_main_loop, 0, 1);
#else
    SetTargetFPS(60);   // Set our game to run at 60 frames-per-second
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        call_main_loop();
    }
#endif 
    return mrb_nil_value();
}

void
mrb_mruby_raylib_gem_init(mrb_state* mrb) {
	struct RClass *raylib = mrb_define_module(mrb, "Raylib");
	mrb_define_class_method(mrb, raylib, "init_window", mrb_init_window, MRB_ARGS_REQ(3));
	mrb_define_class_method(mrb, raylib, "platform", mrb_platform, MRB_ARGS_NONE());
	mrb_define_class_method(mrb, raylib, "draw_text", mrb_draw_text, MRB_ARGS_REQ(4));
	mrb_define_class_method(mrb, raylib, "begin_drawing", mrb_begin_drawing, MRB_ARGS_NONE());
	mrb_define_class_method(mrb, raylib, "end_drawing", mrb_end_drawing, MRB_ARGS_NONE());
	mrb_define_class_method(mrb, raylib, "clear_background", mrb_clear_background, MRB_ARGS_NONE());
	mrb_define_class_method(mrb, raylib, "execute_main_loop", mrb_execute_main_loop, MRB_ARGS_NONE());
}

void
mrb_mruby_raylib_gem_final(mrb_state* mrb) {
	/* finalizer */
}