-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathlutro_window.c
288 lines (234 loc) · 6.09 KB
/
lutro_window.c
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#include <stdlib.h>
#include <string.h>
#include <libretro.h>
#include "lutro_window.h"
#include "lutro.h"
#include "graphics.h"
int lutro_window_preload(lua_State *L)
{
static const luaL_Reg win_funcs[] = {
{ "close", win_close },
{ "setTitle", win_setTitle },
{ "setMode", win_setMode },
{ "setIcon", win_setIcon },
{ "isCreated", win_isCreated },
{ "maximize", win_maximize },
{ "minimize", win_minimize },
{ "getTitle", win_getTitle },
{ "setPosition", win_setPosition },
{ "getPosition", win_getPosition },
{ "requestAttention", win_requestAttention },
{ "getDisplayName", win_getDisplayName },
{ "setDisplaySleepEnabled", win_setDisplaySleepEnabled },
{ "isDisplaySleepEnabled", win_isDisplaySleepEnabled },
{ "showMessageBox", win_showMessageBox },
{NULL, NULL}
};
lutro_newlib(L, win_funcs, "window");
return 1;
}
void lutro_window_init(void)
{
}
/**
* lutro.window.setTitle
*
* https://love2d.org/wiki/love.window.setTitle
*/
int win_setTitle(lua_State *L)
{
int n = lua_gettop(L);
if (n != 1)
return luaL_error(L, "lutro.window.setTitle expects 1 arguments, %d given.", n);
// Setting the title is ignored in Lutro.
return 0;
}
/**
* lutro.window.close()
*
* https://love2d.org/wiki/love.window.close
*/
int win_close(lua_State *L)
{
lutro_shutdown_game();
return 0;
}
/**
* lutro.window.setIcon
*
* https://love2d.org/wiki/love.window.setIcon
*/
int win_setIcon(lua_State *L)
{
// Pretend that we successfully set the window icon.
lua_pushboolean(L, true);
return 1;
}
int win_setMode(lua_State *L)
{
int n = lua_gettop(L);
if (n < 2)
return luaL_error(L, "lutro.window.setMode at least 2 arguments, %d given.", n);
settings.width = luaL_checknumber(L, 1);
settings.height = luaL_checknumber(L, 2);
lutro_graphics_reinit(L);
lua_pop(L, n);
lua_pushboolean(L, true);
return 1;
}
/**
* lutro.window.isCreated
*
* https://love2d.org/wiki/love.window.isCreated
*/
int win_isCreated(lua_State *L)
{
int n = lua_gettop(L);
if (n > 0)
return luaL_error(L, "lutro.window.isCreated expects 0 arguments, %d given.", n);
// The window will always be created in libretro.
lua_pushboolean(L, true);
return 1;
}
/**
* lutro.window.maximize
*
* https://love2d.org/wiki/love.window.maximize
*/
int win_maximize(lua_State *L)
{
int n = lua_gettop(L);
if (n > 0)
return luaL_error(L, "lutro.window.maximize expects 0 arguments, %d given.", n);
// Lutro does not support maximizing the window.
return 0;
}
/**
* lutro.window.minimize
*
* https://love2d.org/wiki/love.window.minimize
*/
int win_minimize(lua_State *L)
{
int n = lua_gettop(L);
if (n > 0)
return luaL_error(L, "lutro.window.minimize expects 0 arguments, %d given.", n);
// Lutro does not support minimizing the window.
return 0;
}
/**
* lutro.window.getTitle
*
* https://love2d.org/wiki/love.window.getTitle
*/
int win_getTitle(lua_State *L)
{
int n = lua_gettop(L);
if (n > 0)
return luaL_error(L, "lutro.window.getTitle expects 0 arguments, %d given.", n);
// Return a standard title.
lua_pushstring(L, "Lutro");
return 1;
}
/**
* lutro.window.setPosition
*
* https://love2d.org/wiki/love.window.setPosition
*/
int win_setPosition(lua_State *L)
{
int n = lua_gettop(L);
if (n < 2 || n > 3)
return luaL_error(L, "lutro.window.setPosition expects 2-3 arguments, %d given.", n);
// Setting position in Lutro is ignored.
return 0;
}
/**
* lutro.window.getPosition
*
* https://love2d.org/wiki/love.window.getPosition
*/
int win_getPosition(lua_State *L)
{
int n = lua_gettop(L);
if (n > 0)
return luaL_error(L, "lutro.window.getPosition expects 0 arguments, %d given.", n);
// The position is a fixed point.
lua_pushnumber(L, 0); // x
lua_pushnumber(L, 0); // y
lua_pushnumber(L, 1); // display
return 3;
}
/**
* lutro.window.requestAttention
*
* https://love2d.org/wiki/love.window.requestAttention
*/
int win_requestAttention(lua_State *L)
{
int n = lua_gettop(L);
if (n < 0 || n > 1)
return luaL_error(L, "lutro.window.requestAttention expects 0 or 1 arguments, %d given.", n);
return 0;
}
/**
* lutro.window.getDisplayName
*
* https://love2d.org/wiki/love.window.getDisplayName
*/
int win_getDisplayName(lua_State *L)
{
int n = lua_gettop(L);
if (n < 0 || n > 1)
return luaL_error(L, "lutro.window.getDisplayName expects 0 or 1 arguments, %d given.", n);
// Lutro does not support multiple displays.
lua_pushstring(L, "libretro");
return 1;
}
/**
* lutro.window.setDisplaySleepEnabled
*
* https://love2d.org/wiki/love.window.setDisplaySleepEnabled
*/
int win_setDisplaySleepEnabled(lua_State *L)
{
int n = lua_gettop(L);
if (n != 1)
return luaL_error(L, "lutro.window.win_setDisplaySleepEnabled expects 1 argument, %d given.", n);
// Ignore setting the display sleep.
return 0;
}
/**
* lutro.window.isDisplaySleepEnabled
*
* https://love2d.org/wiki/love.window.isDisplaySleepEnabled
*/
int win_isDisplaySleepEnabled(lua_State *L)
{
int n = lua_gettop(L);
if (n != 0)
return luaL_error(L, "lutro.window.isDisplaySleepEnabled expects 1 arguments, %d given.", n);
// Lutro does not support sleeping displays.
lua_pushboolean(L, 0);
return 1;
}
/**
* lutro.window.showMessageBox
*
* https://love2d.org/wiki/love.window.showMessageBox
*/
int win_showMessageBox(lua_State *L)
{
int n = lua_gettop(L);
if (n < 2)
return luaL_error(L, "lutro.window.win_showMessageBox expects at least 2 arguments, %d given.", n);
if (n > 5)
return luaL_error(L, "lutro.window.win_showMessageBox expects at most 5 arguments, %d given.", n);
// TODO: lutro.window.showMessageBox() - Prepend the title to the message... "title: message"
// const char* title = luaL_checkstring(L, 1);
const char* message = luaL_checkstring(L, 2);
struct retro_message msg = { message, 600 };
(*settings.environ_cb)(RETRO_ENVIRONMENT_SET_MESSAGE, &msg);
lua_pushboolean(L, 1); // success
return 1;
}