mirror of
https://github.com/ctruLua/uCompat.git
synced 2025-10-28 17:19:31 +00:00
Fixed a lot of things, "screen" should now work
This commit is contained in:
parent
22619d8871
commit
d35173fc70
5 changed files with 42 additions and 25 deletions
|
|
@ -9,6 +9,7 @@ Actually done:
|
||||||
* dsUser
|
* dsUser
|
||||||
* Font
|
* Font
|
||||||
* Image
|
* Image
|
||||||
|
* ini
|
||||||
* Motion
|
* Motion
|
||||||
* Rumble
|
* Rumble
|
||||||
* screen
|
* screen
|
||||||
|
|
|
||||||
|
|
@ -59,3 +59,6 @@ end
|
||||||
function Controls.setStylusDblcFreq(freq)
|
function Controls.setStylusDblcFreq(freq)
|
||||||
dblcFreq = freq
|
dblcFreq = freq
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Initialize the thing
|
||||||
|
Controls.read()
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ function Image.mirrorH(img, activate)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Image.mirrorV(img. activate)
|
function Image.mirrorV(img, activate)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ Nobody actually used this module. So please use directly the ctrµLua functions.
|
||||||
|
|
||||||
-- Local
|
-- Local
|
||||||
|
|
||||||
local hid = require("hid")
|
local hid = require("ctr.hid")
|
||||||
|
|
||||||
calX, calY, calZ = 0,0,0 -- for Motion.calibrate
|
calX, calY, calZ = 0,0,0 -- for Motion.calibrate
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ local gfx = require("ctr.gfx")
|
||||||
|
|
||||||
-- As the µLua and ctrµLua drawing systems are very differents, we have to use a
|
-- As the µLua and ctrµLua drawing systems are very differents, we have to use a
|
||||||
-- stack. That's bad, but it's the only solution.
|
-- stack. That's bad, but it's the only solution.
|
||||||
local videoStack = {}
|
local videoStack = {[0] = {}, [1] = {}}
|
||||||
|
|
||||||
local alpha = ALPHA_RESET
|
local alpha = ALPHA_RESET
|
||||||
|
|
||||||
|
|
@ -45,7 +45,16 @@ local fpscount = 0
|
||||||
local fpstime = ctr.time()
|
local fpstime = ctr.time()
|
||||||
|
|
||||||
local function RGB2RGBA(c)
|
local function RGB2RGBA(c)
|
||||||
return (c*256)+alpha)
|
if not c then return nil end
|
||||||
|
return (c*256)+(alpha*2.55)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function checkBuffer(scr)
|
||||||
|
if scr == drawScreen then
|
||||||
|
return videoStack[drawScreen]
|
||||||
|
else
|
||||||
|
return {}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Module
|
-- Module
|
||||||
|
|
@ -64,18 +73,16 @@ function stopDrawing()
|
||||||
|
|
||||||
-- render
|
-- render
|
||||||
screen.endDrawing()
|
screen.endDrawing()
|
||||||
|
|
||||||
-- set the screen
|
|
||||||
drawScreen = ((drawScreen == 0 and 1) or 0)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function render()
|
function render()
|
||||||
startDrawing()
|
|
||||||
stopDrawing()
|
stopDrawing()
|
||||||
|
startDrawing()
|
||||||
end
|
end
|
||||||
|
|
||||||
screen = {}
|
screen = {}
|
||||||
|
|
||||||
|
|
||||||
function screen.switch()
|
function screen.switch()
|
||||||
SCREEN_UP, SCREEN_DOWN = SCREEN_DOWN, SCREEN_UP
|
SCREEN_UP, SCREEN_DOWN = SCREEN_DOWN, SCREEN_UP
|
||||||
end
|
end
|
||||||
|
|
@ -93,35 +100,35 @@ function screen.setAlpha(level, layer)
|
||||||
end
|
end
|
||||||
|
|
||||||
function screen.print(scr, x, y, text, color)
|
function screen.print(scr, x, y, text, color)
|
||||||
videoStack[scr][#videoStack[scr]] = {"text", {offsetX+x, offsetY+y, text, 8, RGB2RGBA(color), nil}}
|
checkBuffer(scr)[#videoStack[scr]+1] = {"text", {offsetX+x, offsetY+y, text, 8, RGB2RGBA(color), nil}}
|
||||||
end
|
end
|
||||||
|
|
||||||
function screen.printFont(scr, x, y, text, color, font)
|
function screen.printFont(scr, x, y, text, color, font)
|
||||||
videoStack[scr][#videoStack[scr]] = {"text", {offsetX+x, offsetY+y, text, 8, RGB2RGBA(color), font}}
|
checkBuffer(scr)[#videoStack[scr]+1] = {"text", {offsetX+x, offsetY+y, text, 8, RGB2RGBA(color), font}}
|
||||||
end
|
end
|
||||||
|
|
||||||
function screen.blit(scr, x, y, img, sx, sy, w, h)
|
function screen.blit(scr, x, y, img, sx, sy, w, h)
|
||||||
local sizex, sizey = img:getSize()
|
local sizex, sizey = img:getSize()
|
||||||
videoStack[scr][#videoStack[scr]] = {"img", img.texture, {offsetX+x, offsetY+y, (sx or 0), (sy or 0), (w or sizex), (h or sizey), img.rotation}}
|
checkBuffer(scr)[#videoStack[scr]+1] = {"img", img.texture, {offsetX+x, offsetY+y, (sx or 0), (sy or 0), (w or sizex), (h or sizey), img.rotation}}
|
||||||
end
|
end
|
||||||
|
|
||||||
function screen.drawPoint(scr, x, y, color)
|
function screen.drawPoint(scr, x, y, color)
|
||||||
videoStack[scr][#videoStack[scr]] = {"point", {offsetX+x, offsetY+y, RGB2RGBA(color)}}
|
checkBuffer(scr)[#videoStack[scr]+1] = {"point", {offsetX+x, offsetY+y, RGB2RGBA(color)}}
|
||||||
end
|
end
|
||||||
|
|
||||||
function screen.drawLine(scr, x0, y0, x1, y1, color)
|
function screen.drawLine(scr, x0, y0, x1, y1, color)
|
||||||
videoStack[scr][#videoStack[scr]] = {"line", {offsetX+x0, offsetX+y0, offsetX+x1, offsetY+y1, RGB2RGBA(color)}}
|
checkBuffer(scr)[#videoStack[scr]+1] = {"line", {offsetX+x0, offsetX+y0, offsetX+x1, offsetY+y1, RGB2RGBA(color)}}
|
||||||
end
|
end
|
||||||
|
|
||||||
function screen.drawRect(scr, x0, y0, x1, y1, color)
|
function screen.drawRect(scr, x0, y0, x1, y1, color)
|
||||||
videoStack[scr][#videoStack[scr]] = {"line", {offsetX+x0, offsetY+y0, offsetX+x0, offsetY+y1, RGB2RGBA(color)}}
|
checkBuffer(scr)[#videoStack[scr]+1] = {"line", {offsetX+x0, offsetY+y0, offsetX+x0, offsetY+y1, RGB2RGBA(color)}}
|
||||||
videoStack[scr][#videoStack[scr]] = {"line", {offsetX+x0, offsetY+y0, offsetX+x1, offsetY+y0, RGB2RGBA(color)}}
|
checkBuffer(scr)[#videoStack[scr]+1] = {"line", {offsetX+x0, offsetY+y0, offsetX+x1, offsetY+y0, RGB2RGBA(color)}}
|
||||||
videoStack[scr][#videoStack[scr]] = {"line", {offsetX+x0, offsetY+y1, offsetX+x1, offsetY+y1, RGB2RGBA(color)}}
|
checkBuffer(scr)[#videoStack[scr]+1] = {"line", {offsetX+x0, offsetY+y1, offsetX+x1, offsetY+y1, RGB2RGBA(color)}}
|
||||||
videoStack[scr][#videoStack[scr]] = {"line", {offsetX+x1, offsetY+y0, offsetX+x1, offsetY+y1, RGB2RGBA(color)}}
|
checkBuffer(scr)[#videoStack[scr]+1] = {"line", {offsetX+x1, offsetY+y0, offsetX+x1, offsetY+y1, RGB2RGBA(color)}}
|
||||||
end
|
end
|
||||||
|
|
||||||
function screen.drawFillRect(scr, x0, y0, x1, y1, color)
|
function screen.drawFillRect(scr, x0, y0, x1, y1, color)
|
||||||
videoStack[scr][#videoStack[scr]] = {"rectangle", {offsetX+x0, offsetY+y0, offsetX+(x1-x0), offsetY+(y1-y0), 0, RGB2RGBA(color)}}
|
checkBuffer(scr)[#videoStack[scr]+1] = {"rectangle", {offsetX+x0, offsetY+y0, offsetX+(x1-x0), offsetY+(y1-y0), 0, RGB2RGBA(color)}}
|
||||||
end
|
end
|
||||||
|
|
||||||
function screen.drawGradientRect(scr, x0, y0, x1, y1, color, color, color, color)
|
function screen.drawGradientRect(scr, x0, y0, x1, y1, color, color, color, color)
|
||||||
|
|
@ -154,32 +161,38 @@ end
|
||||||
|
|
||||||
function screen.startDrawing2D() -- unused
|
function screen.startDrawing2D() -- unused
|
||||||
--reset the video stacks
|
--reset the video stacks
|
||||||
videoStack = {}
|
videoStack[drawScreen] = {}
|
||||||
videoStack[0] = {}
|
|
||||||
videoStack[1] = {}
|
|
||||||
|
|
||||||
-- As you can change the screen size, we have to re-calculate this every time.
|
-- As you can change the screen size, we have to re-calculate this every time.
|
||||||
offsetX = (gfx.BOTTOM_WIDTH-SCREEN_WIDTH)/2
|
offsetX = (gfx.BOTTOM_WIDTH-SCREEN_WIDTH)/2
|
||||||
offsetY = (gfx.BOTTOM_HEIGHT-SCREEN_HEIGHT)/2
|
offsetY = (gfx.BOTTOM_HEIGHT-SCREEN_HEIGHT)/2
|
||||||
if drawScreen == gfx.SCREEN_UP then
|
if drawScreen == 0 then
|
||||||
offsetX = offsetX + 40
|
offsetX = offsetX + 40
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function screen.endDrawing()
|
function screen.endDrawing()
|
||||||
gfx.startFrame(drawScreen)
|
gfx.startFrame(drawScreen)
|
||||||
|
--gfx.text(2, 2, "x: "..offsetX.." ;y: "..offsetY.." ;stackUP: "..#videoStack[0].." ;stackDOWN: "..#videoStack[1]) -- debug only
|
||||||
|
--gfx.text(2, 12, "screen: "..drawScreen.." ; stack: "..#videoStack[drawScreen]) -- debug only
|
||||||
for i=1, #videoStack[drawScreen] do
|
for i=1, #videoStack[drawScreen] do
|
||||||
local e = videoStack[drawScreen][i]
|
local e = videoStack[drawScreen][i]
|
||||||
if e[1] == "img" then
|
if e[1] == "img" then
|
||||||
e[2]:drawPart(unpack(e[3]))
|
e[2]:drawPart(table.unpack(e[3]))
|
||||||
else
|
else
|
||||||
gfx[e[1]](unpack(e[2])
|
gfx[e[1]](table.unpack(e[2]))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
gfx.endFrame()
|
gfx.endFrame()
|
||||||
gfx.render()
|
|
||||||
|
-- set the screen
|
||||||
|
drawScreen = ((drawScreen == 0 and 1) or gfx.render() or 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
function screen.waitForVBL() -- unused
|
function screen.waitForVBL() -- unused
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Initialize the thing
|
||||||
|
|
||||||
|
startDrawing()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue