Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Twilight Sparkle

Pages: [1]
1
Lua / Re: Numstrat - Stumbling into Lua
« on: September 23, 2012, 07:08:17 am »
A screen manager is something that allows you to devide your Lua applications in several pieces.
Basically, you will have a paint handler for every scene in your program, without needing to put all your stuff in on.paint.

Here is a simple screen manager, so you can understand how it works a bit:
Code: [Select]

------ Screen Manager -------

-- In this table we will contain all 'screen' objects.
Screens = {}

-- This function is used to push a screen into the above table (Screens)
function pushScreen(scrn)
    table.insert(Screens, scrn)
    platform.window:invalidate()
end

-- This function is used to remove the last item in the 'Screens' table
function pullScreen()
    table.remove(Screens)
    platform.window:invalidate()
end

-- Return the last item of 'Screens', the current screen
function currentScreen()
    return Screens[#Screens]
end

-- This function will loop through all screens in the 'Screens' table and draw them
function paintScreens(gc)
    for _, screen in ipairs(Screens) do
        screen:paint(gc)
    end
end

-- Our screen object class
Screen = class()

function Screen:arrowKey() end
function Screen:paint()        end
function Screen:charIn()      end
function Screen:enterKey()  end

-- Link the Screen manager to 'on'

function on.paint(gc)              paintScreens(gc)                           end
function on.arrowKey(arrow) currentScreen():arrowKey(arrow) end
function on.charIn(ch)            currentScreen():charIn(ch)           end
function on.enterKey()            currentScreen():enterKey()          end

--- User code ----
popup = Screen()

function popup:paint(gc)
    gc:setColorRGB(255,255,255)
    gc:fillRect(50,50,200,100)
    gc:setColorRGB(0,0,0)
    gc:drawRect(50,50,200,100)
    gc:drawString("Hey!", 52, 50, "top")
    gc:drawString("Press enter to hide this popup", 52, 80, "top")
end

function popup:enterKey()
    pullScreen()
end


main = Screen()

function main:paint(gc)
    gc:drawString("Hello World! Press enter :D", 10, 10, "top")
end

function main:enterKey()
    pushScreen(popup)
end

pushScreen(main)

Adriweb and Jim Bauwens created a more advanced screen manager together with a nice widget API, you can find it on the github page for EEPro I think.

2
Lua / Re: Numstrat - Stumbling into Lua
« on: September 18, 2012, 11:34:33 am »
Hi, just wanted to note that you can change
Code: [Select]
    if state == "attack" then
        if r2 == 1 then
            gc:drawString("Attack was successful . + "  .. r1, 10, 50, "top")
        else    --if r2 == 0 then
            gc:drawString("Attack was unsuccessful . -" .. r1, 10, 50, "top")
        end
    elseif state == "defense" then
        if r2 == 1 then
            gc:drawString("Defense was successful . + "  .. r1, 10, 50, "top")
        else    --if r2 == 0 then
            gc:drawString("Defense was unsuccessful . -" .. r1, 10, 50, "top")
        end
    end

to

Code: [Select]
if state ~= "" then
gc:drawString((state=="attack" and "Attack" or "Defense") .. " was " .. (r2==0 and "unsuccessful. -" or "successful. +") .. r1, 10, 50, "top")
end

Makes it a bit smaler :D

3
TI-Nspire / Re: Nspire Movie Player - alternative to nPlayer
« on: September 18, 2012, 11:23:14 am »
Oh, that sounds nice too :D

4
TI-Nspire / Re: Nspire Movie Player - alternative to nPlayer
« on: September 17, 2012, 02:22:28 pm »
Porting libmpeg2 surely is interesting, but will it not require more std C syscalls to be added to Ndless ?
http://www.rockbox.org/wiki/PluginMpegplayer contains some useful information in the bottom links regarding libmpeg2, if anyone is interested in it :)

5
Lua / Re: Look what my Nspire can do
« on: September 17, 2012, 12:31:52 pm »
Wow, this is pretty cool !
Can't wait until it is finished :)

Pages: [1]