DSLua Community

General DS Programming Chats => Code Hashing => Topic started by: nonchip on October 21, 2007, 08:54:17 AM



Title: Reset the Stylus
Post by: nonchip on October 21, 2007, 08:54:17 AM
I wrote a menu for a paint project.
Code:
require("functions.inc.lua")
SCREEN_TOP    = 1
SCREEN_BOTTOM = 0
BGTopText = Screen.LoadTextBG()
BGBotText = Screen.LoadTextBG()
Screen.Initialize( SCREEN_TOP,    BGTopText )
Screen.Initialize( SCREEN_BOTTOM, BGBotText )

BGTopText:PrintXY( 1, 5, "Hi "..DSLua.UserName().."!" )
BGTopText:PrintXY( 3, 5, "Welcome to SKETCH" )
while Pads.Start() == false do
    BGBotText:PrintXY(1,2,"Click for Keyboard-Mode")
    BGBotText:PrintXY(1,5,"Click for Stylus-Mode")
    BGBotText:PrintXY(1,8,"Click for Stylus-Line-Mode")
    while true do
        DSLua.LidCloseAction()
        if stylusInTextBox(1, 1, 5, 3) then
            DSLua.WaitForNoKey()
            BGBotText:Clear()
            dofile("sketch_keyboard.lua")
            break
        end
        if stylusInTextBox(1, 4, 5, 6) then
            DSLua.WaitForNoStylus()
            BGBotText:Clear()
            dofile("sketch_stylus_free.lua")
            break
        end
        if stylusInTextBox(1, 7, 5, 9) then
            DSLua.WaitForNoStylus()
            BGBotText:Clear()
            dofile("sketch_stylus_lines.lua")
            break
        end
    end
end

stylusInTextBox(x1, y1, x2, y2) runs stylusInBox(x1*8, y1*8, x2*8, y2*8) to get text-screen coords.

But if i use this, and don't tap the screen after selecting the mode, it restarts the same mode automatically, because the coords are the same.
how can i reset the stylus coords????



PS: I think i add a button to drag the "Click here to ..."-button to


Title: Re: Reset the Stylus
Post by: daltonlaffs on October 22, 2007, 03:18:46 PM
Resetting coordinates is next to impossible, but there is a solution to this problem: The Stylus.Down() function.

Here's a fixed version of your code:

Code:
require("functions.inc.lua")
SCREEN_TOP    = 1
SCREEN_BOTTOM = 0
BGTopText = Screen.LoadTextBG()
BGBotText = Screen.LoadTextBG()
Screen.Initialize( SCREEN_TOP,    BGTopText )
Screen.Initialize( SCREEN_BOTTOM, BGBotText )

BGTopText:PrintXY( 1, 5, "Hi "..DSLua.UserName().."!" )
BGTopText:PrintXY( 3, 5, "Welcome to SKETCH" )
while Pads.Start() == false do
    BGBotText:PrintXY(1,2,"Click for Keyboard-Mode")
    BGBotText:PrintXY(1,5,"Click for Stylus-Mode")
    BGBotText:PrintXY(1,8,"Click for Stylus-Line-Mode")
    while true do
        DSLua.LidCloseAction()
if Stylus.Down() then
        if stylusInTextBox(1, 1, 5, 3) then
            DSLua.WaitForNoKey()
            BGBotText:Clear()
            dofile("sketch_keyboard.lua")
            break
        end
        if stylusInTextBox(1, 4, 5, 6) then
            DSLua.WaitForNoStylus()
            BGBotText:Clear()
            dofile("sketch_stylus_free.lua")
            break
        end
        if stylusInTextBox(1, 7, 5, 9) then
            DSLua.WaitForNoStylus()
            BGBotText:Clear()
            dofile("sketch_stylus_lines.lua")
            break
        end
    end
end
end

The simple addition was to check whether the Stylus is on the screen or not. If not, the stylusInBox commands aren't even run, so the old coordinates are not processed.


Title: Re: Reset the Stylus
Post by: nonchip on October 25, 2007, 01:34:11 PM
thanks, but i think the DnD-method I use is a cool demonstration of the DSLua functions.