- Adaptat exemple a la nova API

- [NEW] viewport.resetClipping()
This commit is contained in:
2025-02-19 06:49:56 +01:00
parent 6c9221cd20
commit 5306e82897
4 changed files with 47 additions and 44 deletions

View File

@@ -1,16 +1,16 @@
--other = require "other"
other = require "other"
x=0
function mini.init()
--text=other.peiv()
--keyRight = tonumber(getconf("keyright")) or KEY_RIGHT
--keyLeft = tonumber(getconf("keyleft")) or KEY_LEFT
--_update=normal_update
text=other.peiv()
keyRight = tonumber(config.getKey("keyright")) or key.RIGHT
keyLeft = tonumber(config.getKey("keyleft")) or key.LEFT
mini.update=normal_update
--turbo(false)
--local perico = "péricòñ"
--print(utf8.len(perico))
Ants = 0xc936;
local perico = "péricòñ"
print(utf8.len(perico))
ants = 0xc936;
s = surface.load("tiles01.gif")
--surface.source(s)
p = palette.load("tiles01.gif")
@@ -30,16 +30,16 @@ function mini.update()
end
if system.isBeat() then
Ants = (Ants >> 12) | ((Ants<<4)&0xffff)
ants = (ants >> 12) | ((ants<<4)&0xffff)
end
surface.cls(5)
draw.surface(s, 0, 0, 64, 64, 10, 10)
draw.rect(10, 10, 73, 73, 8)
draw.setPattern(Ants)
draw.setPattern(ants)
draw.rect(10, 10, 73, 73, 0)
draw.setPattern(0xffff)
--draw.print(#p,0,0,2)
--draw.text(#p,0,0,2)
end
function normal_update()
@@ -60,23 +60,21 @@ function normal_update()
window.setFullscreen(not window.getFullscreen())
end
//if x>160 then x=-strlen(text)*4 end
if x>160 then x=-utf8.len(text)*4 end
viewport.setClippingclip()
origin(0,0)
cls(20)
clip(10,10,140,100)
cls(3)
color(5)
prnt("HOLA",0,0)
origin(-70,-50)
prnt("ORÍGIN",0,0)
prnt(text,x,10)
color(10)
bcolor(15)
fillp(0x5a5a, false);
circfill(20,20,10);
fillp(0xffff,false);
viewport.resetClipping()
viewport.setOrigin(0,0)
surface.cls(20)
viewport.setClipping(10,10,140,100)
surface.cls(3)
draw.text("HOLA",0,0,5)
viewport.setOrigin(-70,-50)
draw.text("ORÍGIN",0,0,5)
draw.text(text,x,10,5)
draw.circFill(20,20,10,15);
draw.setPattern(0x5a5a);
draw.circFill(20,20,10,10);
draw.setPattern(0xffff);
end
redefinekeys = {
@@ -86,21 +84,21 @@ redefinekeys = {
_update=redefinekeys.update
end,
update = function()
cls(20)
surface.cls(20)
if redefinekeys.state == 0 then
prnt("PULSA TECLA PER A DRETA...",0,0)
local key = btnp();
draw.text("PULSA TECLA PER A DRETA...",0,0,10)
local key = keyboard.keyPressed();
if key ~= 0 then
redefinekeys.state = 1
keyRight=key
setconf("keyright", keyRight)
config.setKey("keyright", keyRight)
end
elseif redefinekeys.state == 1 then
prnt("PULSA TECLA PER A ESQUERRA...",0,0)
local key = btnp();
draw.text("PULSA TECLA PER A ESQUERRA...",0,0,10)
local key = keyboard.keyPressed();
if key ~= 0 then
keyLeft=key
setconf("keyleft", keyLeft)
config.setKey("keyleft", keyLeft)
_update=normal_update
end
end

View File

@@ -1,6 +1,6 @@
return {
peiv = function()
palcolor(1, 1, 1, 1)
palette.setColor(1, 1, 1, 1)
return "HOLA OTHER UNIT"
end
}

20
lua.cpp
View File

@@ -315,16 +315,17 @@ extern "C" {
// viewport
// ===============================================
static int cpp_viewport_resetClipping(lua_State *L) {
clip();
return 0;
}
static int cpp_viewport_setClipping(lua_State *L) {
if (lua_gettop(L) == 0) {
clip();
} else {
int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
int w = luaL_checknumber(L, 3);
int h = luaL_checknumber(L, 4);
clip(x, y, w, h);
}
int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
int w = luaL_checknumber(L, 3);
int h = luaL_checknumber(L, 4);
clip(x, y, w, h);
return 0;
}
@@ -857,6 +858,7 @@ void push_lua_funcs() {
lua_setglobal(L, "subpalette");
lua_newtable(L);
lua_pushcfunction(L,cpp_viewport_resetClipping);lua_setfield(L, -2, "resetClipping");
lua_pushcfunction(L,cpp_viewport_setClipping); lua_setfield(L, -2, "setClipping");
lua_pushcfunction(L,cpp_viewport_setOrigin); lua_setfield(L, -2, "setOrigin");
lua_pushcfunction(L,cpp_viewport_getOrigin); lua_setfield(L, -2, "getOrigin");

View File

@@ -161,6 +161,9 @@ viewport = {}
---Set the current clipping region
function viewport.setClipping(x, y, w, h) end
---reset the current clipping region to the entire window
function viewport.resetClipping() end
---@param x number
---@param y number
---Set the current origin position