Skip to content

Commit

Permalink
rasterimage
Browse files Browse the repository at this point in the history
  • Loading branch information
cheatengine@gmail.com committed Jan 5, 2013
1 parent 76def7b commit 51c276b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 92 deletions.
1 change: 1 addition & 0 deletions Cheat Engine/LuaGraphic.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface
Classes, SysUtils, Graphics,lua, lualib, lauxlib,LuaHandler;

procedure initializeLuaGraphic;
procedure graphic_addMetaData(L: PLua_state; metatable: integer; userdata: integer );

implementation

Expand Down
129 changes: 46 additions & 83 deletions Cheat Engine/LuaRasterImage.pas
Original file line number Diff line number Diff line change
Expand Up @@ -11,132 +11,91 @@ procedure initializeLuaRasterImage;

implementation

uses LuaHandler;
uses LuaHandler, luaclass, LuaGraphic;

function rasterImage_getCanvas(L: PLua_State): integer; cdecl;
var
parameters: integer;
c: TrasterImage;
begin
result:=0;
parameters:=lua_gettop(L);
if parameters=1 then
begin
c:=lua_touserdata(L,-1);
lua_pop(L, parameters);

lua_pushlightuserdata(L, c.Canvas);
result:=1;

end else lua_pop(L, parameters);
c:=luaclass_getClassObject(L);
luaclass_newClass(L, c.Canvas);
result:=1;
end;

function rasterimage_getPixelFormat(L: PLua_State): integer; cdecl;
var
parameters: integer;
c: TrasterImage;
begin
result:=0;
parameters:=lua_gettop(L);
if parameters=1 then
begin
c:=lua_touserdata(L,-1);
lua_pop(L, parameters);

lua_pushinteger(L, integer(c.PixelFormat));
result:=1;

end else lua_pop(L, parameters);
c:=luaclass_getClassObject(L);
lua_pushinteger(L, integer(c.PixelFormat));
result:=1;
end;


function rasterimage_setPixelFormat(L: PLua_State): integer; cdecl;
var
parameters: integer;
c: TrasterImage;
a: integer;
begin
result:=0;
parameters:=lua_gettop(L);
if parameters=2 then
begin
c:=lua_touserdata(L,-2);
c:=luaclass_getClassObject(L);
if lua_gettop(L)>=1 then
c.PixelFormat:=TPixelFormat(lua_tointeger(L,-1));
end;

lua_pop(L, parameters);
end;

function rasterimage_getTransparent(L: PLua_State): integer; cdecl;
function rasterimage_getTransparent(L: PLua_State): integer; cdecl; //obsolete
var
parameters: integer;
c: TrasterImage;
rasterimage: Trasterimage;
begin
result:=0;
parameters:=lua_gettop(L);
if parameters=1 then
begin
c:=lua_touserdata(L,-1);
lua_pop(L, parameters);

lua_pushboolean(L, c.Transparent);
result:=1;

end else lua_pop(L, parameters);
rasterimage:=luaclass_getClassObject(L);
lua_pushboolean(L, rasterimage.Transparent);
result:=1;
end;


function rasterimage_setTransparent(L: PLua_State): integer; cdecl;
var
parameters: integer;
c: TrasterImage;
a: integer;
rasterimage: Trasterimage;
begin
result:=0;
parameters:=lua_gettop(L);
if parameters=2 then
begin
c:=lua_touserdata(L,-2);
c.Transparent:=lua_toboolean(L,-1);
end;

lua_pop(L, parameters);
rasterimage:=luaclass_getClassObject(L);
if lua_gettop(L)=1 then
rasterimage.Transparent:=lua_toboolean(L, -1);
end;

function rasterimage_getTransparentColor(L: PLua_State): integer; cdecl;

function rasterimage_gettransparentColor(L: PLua_State): integer; cdecl;
var
parameters: integer;
c: TrasterImage;
begin
result:=0;
parameters:=lua_gettop(L);
if parameters=1 then
begin
c:=lua_touserdata(L,-1);
lua_pop(L, parameters);

lua_pushinteger(L, integer(c.TransparentColor));
result:=1;

end else lua_pop(L, parameters);
c:=luaclass_getClassObject(L);
lua_pushinteger(L, c.transparentColor);
result:=1;
end;


function rasterimage_setTransparentColor(L: PLua_State): integer; cdecl;
function rasterimage_settransparentColor(L: PLua_State): integer; cdecl;
var
parameters: integer;
c: TrasterImage;
a: integer;
begin
result:=0;
parameters:=lua_gettop(L);
if parameters=2 then
begin
c:=lua_touserdata(L,-2);
c.TransparentColor:=TColor(lua_tointeger(L,-1));
end;

lua_pop(L, parameters);
c:=luaclass_getClassObject(L);
if lua_gettop(L)>=1 then
c.transparentColor:=lua_tointeger(L,-1);
end;

procedure rasterimage_addMetaData(L: PLua_state; metatable: integer; userdata: integer );
begin
graphic_addMetaData(L, metatable, userdata);
luaclass_addClassFunctionToTable(L, metatable, userdata, 'getCanvas', rasterImage_getCanvas);
luaclass_addClassFunctionToTable(L, metatable, userdata, 'getPixelFormat', rasterimage_getPixelFormat);
luaclass_addClassFunctionToTable(L, metatable, userdata, 'setPixelFormat', rasterimage_setPixelFormat);
luaclass_addClassFunctionToTable(L, metatable, userdata, 'getTransparentColor', rasterimage_getTransparentColor);
luaclass_addClassFunctionToTable(L, metatable, userdata, 'setTransparentColor', rasterimage_setTransparentColor);

Luaclass_addPropertyToTable(L, metatable, userdata, 'Canvas', rasterImage_getCanvas, nil);
Luaclass_addPropertyToTable(L, metatable, userdata, 'PixelFormat', rasterimage_getPixelFormat, rasterimage_setPixelFormat);
Luaclass_addPropertyToTable(L, metatable, userdata, 'TransparentColor', rasterimage_getTransparentColor, rasterimage_setTransparentColor);
end;


Expand All @@ -145,12 +104,16 @@ procedure initializeLuaRasterImage;
lua_register(LuaVM, 'rasterimage_getCanvas', rasterImage_getCanvas);
lua_register(LuaVM, 'rasterimage_getPixelFormat', rasterimage_getPixelFormat);
lua_register(LuaVM, 'rasterimage_setPixelFormat', rasterimage_setPixelFormat);
lua_register(LuaVM, 'rasterimage_getTransparent', rasterimage_getTransparent);
lua_register(LuaVM, 'rasterimage_getTransparent', rasterimage_getTransparent); //should be graphic_
lua_register(LuaVM, 'rasterimage_setTransparent', rasterimage_setTransparent);
lua_register(LuaVM, 'rasterimage_getTransparentColor', rasterimage_getTransparentColor);
lua_register(LuaVM, 'rasterimage_setTransparentColor', rasterimage_setTransparentColor);
end;

initialization
luaclass_register(TrasterImage, rasterImage_addMetaData);



end.

21 changes: 12 additions & 9 deletions Cheat Engine/bin/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -945,19 +945,22 @@ methods
setHeight(graphic, height)
RasterImage class: (Inheritance: Graphic->Object) : Base class for some graphical controls
rasterimage_getCanvas(RasterImage): Returns the Canvas object for this image
rasterimage_getPixelFormat((rasterimage): Returns the current pixelformat
rasterimage_setPixelFormat(rasterimage, pixelformat): Sets the pixelformat for this image. Will clear the current image if it had one. Supported pixelformats: pf1bit, pf4bit, pf8bit, pf15bit, pf16bit, pf24bit, pf32bit (recommended)
properties
Canvas: Canvas
PixelFormat: PixelFormat - the pixelformat for this image. Will clear the current image if it had one. Supported pixelformats: pf1bit, pf4bit, pf8bit, pf15bit, pf16bit, pf24bit, pf32bit (recommended)
TransparentColor: integer
rasterimage_setTransparent(rasterimage,state): Will set the image to support transparency or not
rasterimage_getTransparent(rasterimage): Returns true if the image supports transparency
rasterimage_setTransparentColor(rasterimage, color): Sets the color that will be rendered as transparent when drawn
rasterimage_getTransparentColor(rasterimage): Returns the color set to be transparent
methods
getCanvas(): Returns the Canvas object for this image
getPixelFormat(): Returns the current pixelformat
getPixelFormat(pixelformat): Sets the pixelformat for this image. Will clear the current image if it had one. Supported pixelformats: pf1bit, pf4bit, pf8bit, pf15bit, pf16bit, pf24bit, pf32bit (recommended)
setTransparentColor(integer): Sets the color that will be rendered as transparent when drawn
getTransparentColor(): Returns the color set to be transparent
Bitmap class: (Inheritance: CustomBitmap->RasterImage->Graphic->Object) : Bitmap based Graphic object
PortableNetworkGraphic Class: (Inheritence: TCustomBitmap->RasterImage->Graphic->Object)
JpegImage Class: (Inheritence: TCustomBitmap->RasterImage->Graphic->Object)
PortableNetworkGraphic Class: (Inheritence: CustomBitmap->RasterImage->Graphic->Object)
JpegImage Class: (Inheritence: CustomBitmap->RasterImage->Graphic->Object)
Expand Down

0 comments on commit 51c276b

Please sign in to comment.