Core Native GBA 0.0.17
create your own game-engine with just lua for nitendo game boy advance console.
Loading...
Searching...
No Matches
draw.c
Go to the documentation of this file.
1#include "zeebo.h"
2
3static int native_draw_start(lua_State *L)
4{
5 return 0;
6}
7
8static int native_draw_flush(lua_State *L)
9{
10 return 0;
11}
12
13/**
14 * @param[in] color @c int
15 */
16static int native_draw_clear(lua_State *L)
17{
18 color_t t = { .pixel2 = luaL_checkinteger(L, 1) };
19 draw_queue_push(48, 3, 0, 1, 0);
20 draw_queue_push(49, t.c32.color.r, t.c32.color.g, t.c32.color.b, 0);
21 lua_settop(L, 0);
22 return 0;
23}
24
25/**
26 * @param[in] color @c int
27 */
28static int native_draw_color(lua_State *L)
29{
30 color_t t = { .pixel2 = luaL_checkinteger(L, 1) };
31 draw_queue_push(48, 0, 0, 1, 0);
32 draw_queue_push(49, t.c32.color.r, t.c32.color.g, t.c32.color.b, 0);
33 lua_settop(L, 0);
34 return 0;
35}
36
37/**
38 * @param[in] mode @c int
39 * @param[in] x @c double
40 * @param[in] y @c double
41 * @param[in] width @c double
42 * @param[in] height @c double
43 */
44static int native_draw_rect(lua_State *L)
45{
46 uint8_t mode = luaL_checkinteger(L, 1);
47 int32_t posx = luaL_checknumber(L, 2);
48 int32_t posy = luaL_checknumber(L, 3);
49 int32_t width = luaL_checknumber(L, 4);
50 int32_t height = luaL_checknumber(L, 5);
51
52 if (geoclip_rect(&posx, &posy, &width, &height)) {
53 draw_queue_push(48, mode, 0, 1, 0);
54 draw_queue_push(50, (uint8_t) posx, (uint8_t) posy, (uint8_t) width, (uint8_t) height);
55 }
56
57 lua_settop(L, 0);
58 return 0;
59}
60
61/**
62 * @param[in] x1 @c double
63 * @param[in] y1 @c double
64 * @param[in] x2 @c double
65 * @param[in] y2 @c double
66 */
67static int native_draw_line(lua_State *L)
68{
69 int32_t x1 = luaL_checknumber(L, 1);
70 int32_t y1 = luaL_checknumber(L, 2);
71 int32_t x2 = luaL_checknumber(L, 3);
72 int32_t y2 = luaL_checknumber(L, 4);
73
74 if (geoclip_line(&x1, &y1, &x2, &y2)) {
75 draw_queue_push(51, (uint8_t) x1, (uint8_t) y1, (uint8_t) x2, (uint8_t) y2);
76 }
77
78 lua_settop(L, 0);
79 return 0;
80}
81
82
83/**
84 * @param[in] source @c string
85 * @param[in] x @c double
86 * @param[in] y @c double
87 */
88static int native_draw_image(lua_State *L) {
89 uint8_t x = luaL_checknumber(L, 2);
90 uint8_t y = luaL_checknumber(L, 3);
91 draw_queue_push(48, 0, 0, 1, 0);
92 draw_queue_push(49, 0XFF, 0xFF, 0xFF, 0);
93 draw_queue_push(50, x, y, 1, 1);
94 lua_settop(L, 0);
95 return 0;
96}
97
98void draw_callback_update(lua_State* L, int callback)
99{
100 lua_rawgeti(L, LUA_REGISTRYINDEX, callback);
101 lua_pcall(L, 0, 0, 0);
102}
103
104void draw_library_install(lua_State* L)
105{
106 int i = 0;
107 static const luaL_Reg lib[] = {
108 {"native_draw_start", native_draw_start},
109 {"native_draw_flush", native_draw_flush},
110 {"native_draw_clear", native_draw_clear},
111 {"native_draw_color", native_draw_color},
112 {"native_draw_rect", native_draw_rect},
113 {"native_draw_line", native_draw_line},
114 {"native_draw_image", native_draw_image}
115 };
116
117 while(i < sizeof(lib)/sizeof(luaL_Reg)) {
118 lua_pushcfunction(L, lib[i].func);
119 lua_setglobal(L, lib[i].name);
120 i = i + 1;
121 }
122
123 lua_newtable(L);
124 lua_pushstring(L, "repeats");
125 lua_newtable(L);
126 lua_pushboolean(L, 1);
127 lua_seti(L, -2, 1);
128 lua_pushboolean(L, 1);
129 lua_seti(L, -2, 2);
130 lua_settable(L, -3);
131 lua_pushstring(L, "line");
132 lua_pushcfunction(L, native_draw_line);
133 lua_settable(L, -3);
134 lua_setglobal(L, "native_dict_poly");
135}
void draw_library_install(lua_State *L)
Definition draw.c:104
void draw_callback_update(lua_State *L, int callback)
Definition draw.c:98
static int native_draw_flush(lua_State *L)
Definition draw.c:8
static int native_draw_start(lua_State *L)
Definition draw.c:3
static int native_draw_rect(lua_State *L)
Definition draw.c:44
static int native_draw_image(lua_State *L)
Definition draw.c:88
static int native_draw_color(lua_State *L)
Definition draw.c:28
static int native_draw_clear(lua_State *L)
Definition draw.c:16
static int native_draw_line(lua_State *L)
Definition draw.c:67
void draw_queue_push(uint8_t cmd, uint8_t a, uint8_t b, uint8_t c, uint8_t d)
Definition draw_queue.c:25
uint8_t geoclip_rect(int32_t *posx, int32_t *posy, int32_t *width, int32_t *height)
adjusts a rectangle within the screen
Definition geoclip.c:11
uint8_t geoclip_line(int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2)
adjusts a line within the screen
Definition geoclip.c:51
struct color_t::@1 c32