-
Notifications
You must be signed in to change notification settings - Fork 4
/
image.c
112 lines (87 loc) · 2.02 KB
/
image.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
#include "image.h"
#include "object.h"
#include <stdlib.h>
#include <lauxlib.h>
#define uiImageSignature 0x45363456
static luaL_Reg image_members[];
int is_image( lua_State* L, int index )
{
return is_object( L, index, uiImageSignature );
}
uiImage* check_image( lua_State* L, int index )
{
return (uiImage*) check_object( L, index, uiImageSignature );
}
static int l_Load( lua_State* L )
{
uiImage* i = (uiImage*) check_object( L, 1, uiImageSignature );
if( uiImageLoad( i, luaL_checkstring( L, 2 ) ) )
{
lua_pushvalue( L, 1 );
return 1;
}
luaL_error( L, "libui: image could not be loaded." );
return 0;
}
static int l_Valid( lua_State* L )
{
uiImage *i = (uiImage*) check_object( L, 1, uiImageSignature );
lua_pushboolean( L, uiImageValid( i ) );
return 1;
}
static int l_Size( lua_State* L )
{
uiImage *i = (uiImage*) check_object( L, 1, uiImageSignature );
int width = -1, height = -1;
uiImageSize( i, &width, &height );
lua_pushinteger( L, width );
lua_pushinteger( L, height );
return 2;
}
static int l_Resize( lua_State* L )
{
uiImage *i = (uiImage*) check_object( L, 1, uiImageSignature );
uiImage *n = uiImageResize( i, luaL_checkinteger( L, 2 ), luaL_checkinteger( L, 3 ) );
object_create( L, n, uiImageSignature, image_members, 0 );
return 1;
}
static int l_Destroy( lua_State* L )
{
uiImage *i = (uiImage*) check_object( L, 1, uiImageSignature );
uiImageDestroy( i );
return 0;
}
static luaL_Reg image_members[] =
{
{ "Load", l_Load },
{ "Valid", l_Valid },
{ "Size", l_Size },
{ "Resize", l_Resize },
{ "__gc", l_Destroy },
{ 0, 0 }
};
int new_image( lua_State* L )
{
uiImage* maybecopy = 0;
if( lua_isuserdata( L, 1 ) )
{
int s;
void* p = get_object( L, 1, &s );
if( s == uiImageSignature )
{
maybecopy = p;
}
}
uiImage* i = uiNewImage( maybecopy );
if( lua_isstring( L, 1 ) )
{
uiImageLoad( i, lua_tostring( L, 1 ) );
}
object_create( L, i, uiImageSignature, image_members, 0 );
return 1;
}
luaL_Reg image_functions[] =
{
{ "NewImage", new_image },
{ 0, 0 }
};