Refactored (yes, already) the lua API to allow also generating pictures directly.
Updated doc, and added sample script. git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1099 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
06892015ea
commit
2a67c9bdce
2
errors.h
2
errors.h
@ -21,7 +21,7 @@
|
||||
/// Functions and macros for tracing and error reporting.
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __func__
|
||||
#ifdef __VBCC__
|
||||
#define __func__ "stupid compiler !"
|
||||
#endif
|
||||
|
||||
|
||||
117
factory.c
117
factory.c
@ -25,7 +25,9 @@
|
||||
#include "brush.h"
|
||||
#include "buttons.h"
|
||||
#include "engine.h"
|
||||
#include "errors.h"
|
||||
#include "global.h"
|
||||
#include "graph.h"
|
||||
#include "misc.h"
|
||||
#include "readline.h"
|
||||
#include "sdlscreen.h"
|
||||
@ -37,19 +39,62 @@
|
||||
#include <lua5.1/lauxlib.h>
|
||||
|
||||
// Wrapper functions to call C from Lua
|
||||
int L_PutPixel(lua_State* L)
|
||||
|
||||
int L_SetBrushSize(lua_State* L)
|
||||
{
|
||||
Realloc_brush(lua_tonumber(L, 1), lua_tonumber(L, 2));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int L_GetBrushSize(lua_State* L)
|
||||
{
|
||||
DEBUG("GBS",Brush_width);
|
||||
lua_pushinteger(L, Brush_width);
|
||||
lua_pushinteger(L, Brush_height);
|
||||
return 2;
|
||||
}
|
||||
|
||||
int L_PutBrushPixel(lua_State* L)
|
||||
{
|
||||
Pixel_in_brush(lua_tonumber(L, 1), lua_tonumber(L, 2), lua_tonumber(L, 3));
|
||||
return 0; // no values returned for lua
|
||||
}
|
||||
|
||||
int L_GetPixel(lua_State* L)
|
||||
int L_GetBrushPixel(lua_State* L)
|
||||
{
|
||||
uint8_t c = Read_pixel_from_brush(lua_tonumber(L, 1), lua_tonumber(L, 2));
|
||||
lua_pushinteger(L, c);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int L_SetPictureSize(lua_State* L)
|
||||
{
|
||||
Resize_image(lua_tonumber(L, 1), lua_tonumber(L, 2));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int L_GetPictureSize(lua_State* L)
|
||||
{
|
||||
lua_pushinteger(L, Main_image_width);
|
||||
lua_pushinteger(L, Main_image_height);
|
||||
return 2;
|
||||
}
|
||||
|
||||
int L_PutPicturePixel(lua_State* L)
|
||||
{
|
||||
Pixel_in_current_screen(lua_tonumber(L, 1), lua_tonumber(L, 2),
|
||||
lua_tonumber(L, 3));
|
||||
return 0; // no values returned for lua
|
||||
}
|
||||
|
||||
int L_GetPicturePixel(lua_State* L)
|
||||
{
|
||||
uint8_t c = Read_pixel_from_current_screen(lua_tonumber(L, 1),
|
||||
lua_tonumber(L, 2));
|
||||
lua_pushinteger(L, c);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int L_SetColor(lua_State* L)
|
||||
{
|
||||
Set_color(lua_tonumber(L, 1), lua_tonumber(L, 2), lua_tonumber(L, 3),
|
||||
@ -60,29 +105,11 @@ int L_SetColor(lua_State* L)
|
||||
void Button_Brush_Factory(void)
|
||||
{
|
||||
short clicked_button;
|
||||
word height;
|
||||
word width;
|
||||
char str[5];
|
||||
|
||||
T_Special_button* width_button;
|
||||
T_Special_button* height_button;
|
||||
|
||||
Open_window(154, 162, "Brush Factory");
|
||||
|
||||
Window_set_normal_button(77, 141, 67, 14, "Cancel", 0, 1, KEY_ESC); // 1
|
||||
Window_set_normal_button(10, 141, 67, 14, "Run", 0, 1, 0); // 2
|
||||
Print_in_window(10, 17, "Width:", MC_Black, MC_Light);
|
||||
width_button = Window_set_input_button(64, 15, 4); // 3
|
||||
Print_in_window(10, 30, "Height:", MC_Black, MC_Light);
|
||||
height_button = Window_set_input_button(64, 28, 4); // 4
|
||||
|
||||
width = Paintbrush_width;
|
||||
Num2str(width, str, 4);
|
||||
Window_input_content(width_button, str);
|
||||
|
||||
height = Paintbrush_height;
|
||||
Num2str(height, str, 4);
|
||||
Window_input_content(height_button, str);
|
||||
|
||||
Update_window_area(0, 0, Window_width, Window_height);
|
||||
Display_cursor();
|
||||
@ -92,34 +119,6 @@ void Button_Brush_Factory(void)
|
||||
|
||||
switch (clicked_button)
|
||||
{
|
||||
case 3 : // Largeur
|
||||
Num2str(width, str, 4);
|
||||
Readline(65, 16, str, 4, 1);
|
||||
width = atoi(str);
|
||||
// On corrige les dimensions
|
||||
if (width == 0)
|
||||
{
|
||||
width = 1;
|
||||
Num2str(width, str, 4);
|
||||
Window_input_content(width_button, str);
|
||||
}
|
||||
Display_cursor();
|
||||
break;
|
||||
|
||||
case 4 : // Height
|
||||
Num2str(height, str, 4);
|
||||
Readline(65, 29, str, 4, 1);
|
||||
height = atoi(str);
|
||||
// On corrige les dimensions
|
||||
if (height == 0)
|
||||
{
|
||||
height = 1;
|
||||
Num2str(height, str, 4);
|
||||
Window_input_content(height_button, str);
|
||||
}
|
||||
Display_cursor();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -130,23 +129,25 @@ void Button_Brush_Factory(void)
|
||||
{
|
||||
lua_State* L = lua_open();
|
||||
|
||||
Realloc_brush(width, height);
|
||||
|
||||
lua_register(L,"putpixel",L_PutPixel);
|
||||
lua_register(L,"getpixel",L_GetPixel);
|
||||
lua_register(L,"putbrushpixel",L_PutBrushPixel);
|
||||
lua_register(L,"getbrushpixel",L_GetBrushPixel);
|
||||
lua_register(L,"putpicturepixel",L_PutPicturePixel);
|
||||
lua_register(L,"getpicturepixel",L_GetPicturePixel);
|
||||
lua_register(L,"setbrushsize",L_SetBrushSize);
|
||||
lua_register(L,"setpicturesize",L_SetPictureSize);
|
||||
lua_register(L,"getbrushsize",L_GetBrushSize);
|
||||
lua_register(L,"getpicturesize",L_GetPictureSize);
|
||||
lua_register(L,"setcolor",L_SetColor);
|
||||
|
||||
// For debug only
|
||||
// luaL_openlibs(L);
|
||||
|
||||
if (luaL_loadfile(L,"./test.lua") != 0)
|
||||
Verbose_error_message(lua_tostring(L, 1));
|
||||
|
||||
lua_pushinteger(L, width);
|
||||
lua_pushinteger(L, height);
|
||||
if (lua_pcall(L, 2, 0, 0) != 0)
|
||||
else if (lua_pcall(L, 0, 0, 0) != 0)
|
||||
Verbose_error_message(lua_tostring(L, 1));
|
||||
|
||||
lua_close(L);
|
||||
|
||||
Change_paintbrush_shape(PAINTBRUSH_SHAPE_COLOR_BRUSH);
|
||||
}
|
||||
|
||||
Close_window();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user