1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-27 16:39:29 +00:00

gfx.GFX_TOP, gfx.GFX_BOTTOM, gfx.GFX_LEFT, gfx.GFX_RIGHT -> gfx.TOP, gfx.BOTTOM, gfx.LEFT, gfx.RIGHT

Also commented and moved tests/audio to examples/audio because the code is quite clean, and we lack examples.
This commit is contained in:
Reuh 2015-12-30 19:15:46 +01:00
parent 73b5c55133
commit b87b2676e6
7 changed files with 31 additions and 30 deletions

View file

@ -86,7 +86,7 @@ while ctr.run() do
if not file then
local t = os.time()
repeat
gfx.start(gfx.GFX_TOP)
gfx.start(gfx.TOP)
gfx.text(3, 3, "Can't open file in write mode")
gfx.stop()
gfx.render()
@ -94,7 +94,7 @@ while ctr.run() do
else
for i = 1, #lines, 1 do
file:write(lines[i]..lineEnding)
gfx.start(gfx.GFX_TOP)
gfx.start(gfx.TOP)
gfx.rectangle(0, 0, math.ceil(i/#lines*gfx.TOP_WIDTH), gfx.TOP_HEIGHT, 0, 0xFFFFFFFF)
gfx.color.setDefault(color.background)
gfx.text(gfx.TOP_WIDTH/2, gfx.TOP_HEIGHT/2, math.ceil(i/#lines*100).."%")
@ -138,7 +138,7 @@ while ctr.run() do
end
-- Draw
gfx.start(gfx.GFX_TOP)
gfx.start(gfx.TOP)
-- Lines
local sI = math.floor(scrollY / lineHeight)
@ -169,7 +169,7 @@ while ctr.run() do
gfx.stop()
gfx.start(gfx.GFX_BOTTOM)
gfx.start(gfx.BOTTOM)
gfx.text(3, 3, "FPS: "..math.ceil(gfx.getFPS()))

View file

@ -3,7 +3,7 @@ local hid = require("ctr.hid")
local gfx = require("ctr.gfx")
local audio = require("ctr.audio")
local test = assert(audio.load("test.wav"))
local test = assert(audio.load("test.wav")) -- Load audio file
local channel = -1
local speed = 1
@ -15,32 +15,33 @@ while true do
if keys.down.start then break end
if keys.down.a then
channel = test:play()
channel = test:play() -- Play audio (an audio can be played multiple times at the same time)
end
if keys.down.up then
speed = speed + 0.01
test:speed(speed)
audio.speed(nil, speed)
test:speed(speed) -- Set the audio object default speed, will affect the next time it is played
audio.speed(nil, speed) -- Set the speed of all the currently playing channels
end
if keys.down.down then
speed = speed - 0.01
test:speed(speed)
test:speed(speed) -- See above
audio.speed(nil, speed)
end
if keys.down.left then
leftBalance = leftBalance + 0.1
test:mix(1-leftBalance, leftBalance)
audio.mix(nil, leftBalance, 1-leftBalance)
test:mix(1-leftBalance, leftBalance) -- Set the audio mix: left speaker will be at leftBalance% and right speaker 1-leftBalance%.
-- Like with test:speed(), it won't affect the currently playing audios but the nexts test:play() will have theses mix paramters.
audio.mix(nil, leftBalance, 1-leftBalance) -- Set the mix of all currently playing channels
end
if keys.down.right then
leftBalance = leftBalance - 0.1
test:mix(1-leftBalance, leftBalance)
test:mix(1-leftBalance, leftBalance) -- See above
audio.mix(nil, leftBalance, 1-leftBalance)
end
gfx.start(gfx.GFX_TOP)
gfx.start(gfx.TOP)
gfx.text(5, 5, "Audio test! "..tostring(test:time()).."/"..tostring(test:duration()).."s")
gfx.text(5, 25, "Last audio played on channel "..tostring(channel))
gfx.text(5, 65, "Speed: "..(speed*100).."% - Left balance: "..(leftBalance*100).."%")
@ -49,4 +50,4 @@ while true do
gfx.render()
end
test:unload()
test:unload() -- Unload audio file

View file

@ -47,19 +47,19 @@ while ctr.run() do
dMul = hid.pos3d()
gfx.start(gfx.GFX_TOP, gfx.GFX_LEFT)
gfx.start(gfx.TOP, gfx.LEFT)
drawStuffIn3D(-1)
gfx.stop()
gfx.start(gfx.GFX_TOP, gfx.GFX_RIGHT)
gfx.start(gfx.TOP, gfx.RIGHT)
drawStuffIn3D(1)
gfx.stop()
gfx.start(gfx.GFX_BOTTOM)
gfx.start(gfx.BOTTOM)
gfx.color.setDefault(gfx.color.RGBA8(0, 0, 0))
gfx.text(5, 5, "FPS: "..math.ceil(gfx.getFPS()))

View file

@ -98,7 +98,7 @@ return function(title, curdir, exts, type)
end
-- Draw
gfx.start(gfx.GFX_TOP)
gfx.start(gfx.TOP)
gfx.rectangle(0, 10+(sel-scroll)*15, gfx.TOP_WIDTH, 15, 0, gfx.color.RGBA8(0, 0, 200))
@ -114,7 +114,7 @@ return function(title, curdir, exts, type)
gfx.stop()
gfx.start(gfx.GFX_BOTTOM)
gfx.start(gfx.BOTTOM)
gfx.text(5, 5, title)
gfx.text(5, 20, "Accepted file extensions: "..(exts or "all"))

View file

@ -25,7 +25,7 @@ while ctr.run() do
data = (data.."!")
end
gfx.start(gfx.GFX_TOP)
gfx.start(gfx.TOP)
gfx.text(0, 0, data)
gfx.stop()

View file

@ -53,8 +53,8 @@ void load_map_lib(lua_State *L);
Start drawing to a screen.
Must be called before any draw operation.
@function start
@tparam number screen the screen to draw to (`GFX_TOP` or `GFX_BOTTOM`)
@tparam[opt=GFX_LEFT] number eye the eye to draw to (`GFX_LEFT` or `GFX_RIGHT`)
@tparam number screen the screen to draw to (`gfx.TOP` or `gfx.BOTTOM`)
@tparam[opt=gfx.LEFT] number eye the eye to draw to (`gfx.LEFT` or `gfx.RIGHT`)
*/
static int gfx_start(lua_State *L) {
u8 screen = luaL_checkinteger(L, 1);
@ -382,27 +382,27 @@ struct { char *name; int value; } gfx_constants[] = {
/***
Constant used to select the top screen.
It is equal to `0`.
@field GFX_TOP
@field TOP
*/
{ "GFX_TOP", GFX_TOP },
{ "TOP", GFX_TOP },
/***
Constant used to select the bottom screen.
It is equal to `1`.
@field GFX_BOTTOM
@field BOTTOM
*/
{ "GFX_BOTTOM", GFX_BOTTOM },
{ "BOTTOM", GFX_BOTTOM },
/***
Constant used to select the left eye.
It is equal to `0`.
@field GFX_LEFT
@field LEFT
*/
{ "GFX_LEFT", GFX_LEFT },
{ "LEFT", GFX_LEFT },
/***
Constant used to select the right eye.
It is equal to `1`.
@field GFX_RIGHT
@field RIGHT
*/
{ "GFX_RIGHT", GFX_RIGHT },
{ "RIGHT", GFX_RIGHT },
/***
The top screen height, in pixels.
It is equal to `240`.