Log In  

Cart [#22727#] | Code | 2016-06-12 | License: CC4-BY-NC-SA | Embed
10

UPDATE: (0.2) Updated the mouse library so that the cursor can be driven by the gamepad OR the mouse at any time, to make the cart compatible with all Pico-8 devices.

I'm cobbling together a UI/mouse library for my own use, and thought it might be useful to others. For now the only widget is a button, but I wrote the API so that it's easy to modify and extend (in theory). Will provide more documentation if there's interest.

This would be a quick "hello world" with the library, for instance:

--button "onclick" callback
function hideme(this)
 this.visible=false
end

function _init()
 --enable the mouse and
 --set the cursor to a 6x6 sprite 
 --at index 0
 mouse_init(0,6,6)

 --create a new parent UI and
 --make it the active one
 mainui = ui_make()
 ui_setactive(mainui)

 --make a button labeled "hello, world!" 
 --which calls hideme() when clicked.
 --It will draw at screen position (30,30).
 --I could also optionally specify a width and height,
 --but if I leave it out the button will be sized automatically
 --based on the length of the label text.
 btn_make(mainui, "hello, world!", hideme, 30, 30)
end

function _update()
 --update mouse position and do event callbacks
 --as needed
 mouse_update()
end

function _draw()
 cls()

 --print mouse position
 print(mouse.x.." "..mouse.y,0,0,7)

 -- draw mouse on top of UI
 ui_draw()
 mouse_draw()
end

thanks to gamax92 for uncovering this nifty feature...

P#22582 2016-06-10 02:25 ( Edited 2016-06-12 07:00)

:: Elven

Why not QWERTY? :)

P#22585 2016-06-10 03:57 ( Edited 2016-06-10 07:57)

Solidarity with AZERTY-users? (Also I didn't want to encourage anyone to actually use this as a keyboard...)

P#22590 2016-06-10 04:12 ( Edited 2016-06-10 08:33)

(Also I didn't want to encourage anyone to actually use this as a keyboard...)

Why not Dvorak then?

P#22595 2016-06-10 06:44 ( Edited 2016-06-10 10:45)
:: jihem

Bépo !!! (french dvorak) lol
hiragana? katakana?
More seriously, I'm trying to do a small katakana font to be used with the code of my cartridge about font.

P#22598 2016-06-10 06:58 ( Edited 2016-06-10 10:58)
:: matt
P#22611 2016-06-10 13:19 ( Edited 2016-06-10 17:19)
:: jihem

@matt
Thanks
This will help me :-)

P#22688 2016-06-11 15:27 ( Edited 2016-06-11 19:27)

[Please log in to post a comment]

About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-11-20 20:50 | 0.022s | 4194k | Q:37