Omnimaga
Calculator Community => Other Calc-Related Projects and Ideas => Casio PRIZM => Topic started by: flyingfisch on January 05, 2012, 10:16:28 am
-
NOTE: I am posting this in PRIZM projects, but since there is no LuaFX for PRIZM yet, it would be nice to have a LuaFX/AFX projects section ;)
I have been meaning to make a GUI library for a while and have only now found the time, so here it is in alpha-of-an-alpha :D
Available functions:
* Lua Classes (thanks to adriweb for code)
* Input text (missing in the originl luaFX)
Planned functions to be included:
* Buttons
* Window Manager
* EZ Menus
* Dialog boxes
* Radio Buttons
* Check Boxes
* More :D
Since this project is free and open source, and you are free to fork it if you want, here is the code: ;)
EDIT: Added a GitHub repo (https://github.com/flyingfisch/CalGUI)
-- locals
local line = graydraw.line
local wait = misc.wait
local setcolor = graydraw.setcolor
local text = graydraw.text
local exitprog = misc.exit
local print = nbdraw.print
local find = string.find
local setCursor = nbdraw.setcursor
local strsub = string.sub
local strlen = string.len
--[[--
CalGUI (Pronounced Cal-gew-ey), a GUI library for LuaFX
By flyingfisch
Last Updated 1/05/2012
This project is free and open source.
--]]--
--[[--
Class definition system
Borrowed from LuaNspire
Thanks to adriweb for code
--]]--
class = function(prototype)
local derived = {}
local derivedMT = {
__index = prototype,
__call = function(proto, ...)
local instance = {}
local instanceMT = {
__index = derived,
__call = function()
return nil, "ERROR: Attempt to invoke an instance of a class"
end,
}
setmetatable(instance, instanceMT)
if instance.init then
instance:init(...)
end
return instance
end,
}
setmetatable(derived, derivedMT)
return derived
end
--[[--
Input text system
--]]--
function input()
setcolor(false) --set 5-color mode "false"
i = 1
parse = ""
print(parse .. "_")
--keystrokes
while not key(5) do
repeat
--non-alpha:
if alpha == 0 then
if key(1) then parse = parse .. "0" end
if key(2) then parse = parse .. "." end
if key(4) then parse = parse .. "-" end
if key(6) then parse = parse .. "1" end
if key(7) then parse = parse .. "2" end
if key(8) then parse = parse .. "3" end
if key(9) then parse = parse .. "+" end
if key(10) then parse = parse .. "-" end
if key(11) then parse = parse .. "4" end
if key(12) then parse = parse .. "5" end
if key(13) then parse = parse .. "6" end
if key(14) then parse = parse .. "*" end
if key(15) then parse = parse .. "/" end
if key(16) then parse = parse .. "7" end
if key(17) then parse = parse .. "8" end
if key(18) then parse = parse .. "9" end
if key(19) then parse = strsub(parse,1,#parse-1) end
if key(33) then alpha = 1 end
--alpha:
else
if key(1) then parse = parse .. "z" end
if key(2) then parse = parse .. " " end
if key(3) then parse = parse .. [["]] end
if key(6) then parse = parse .. "u" end
if key(7) then parse = parse .. "v" end
if key(8) then parse = parse .. "w" end
if key(9) then parse = parse .. "x" end
if key(10) then parse = parse .. "y" end
if key(11) then parse = parse .. "p" end
if key(12) then parse = parse .. "q" end
if key(13) then parse = parse .. "r" end
if key(14) then parse = parse .. "s" end
if key(15) then parse = parse .. "t" end
if key(16) then parse = parse .. "m" end
if key(17) then parse = parse .. "n" end
if key(18) then parse = parse .. "o" end
if key(19) then parse = strsub(parse,1,#parse-1) end
if key(21) then parse = parse .. "g" end
if key(22) then parse = parse .. "h" end
if key(23) then parse = parse .. "i" end
if key(24) then parse = parse .. "j" end
if key(25) then parse = parse .. "k" end
if key(26) then parse = parse .. "l" end
if key(27) then parse = parse .. "a" end
if key(28) then parse = parse .. "b" end
if key(29) then parse = parse .. "c" end
if key(30) then parse = parse .. "d" end
if key(31) then parse = parse .. "e" end
if key(32) then parse = parse .. "f" end
if key(34) then parse = parse .. "r" end
if key(33) then alpha = 0 end
end
wait(2) --interrupt
until key(0)
clear nil
setCursor(1,1)
print(parse .. "_")
refresh
if key(5) then break end --check for EXE
wait(3)
end
end
-
does it work with the classes now? sounds great, now you're sort of the inventor of classes for casio lol
looks good, and it might be alpha-of-alpha, but you have to start somewhere.. i wish you good luck with it (not sarcastic or ironically meant xp )
-
does it work with the classes now? sounds great, now you're sort of the inventor of classes for casio lol
looks good, and it might be alpha-of-alpha, but you have to start somewhere.. i wish you good luck with it (not sarcastic or ironically meant xp )
I understand how its meant :)
Yep, It does work with classes.
I added a repo on GitHub for this project: https://github.com/flyingfisch/CalGUI
-
ooh, i just took a look at it, and can't you remake that
if key(1) then parse = parse .. "0" end
if key(2) then parse = parse .. "." end
if key(4) then parse = parse .. "-" end
etc etc
to a table like this:
parsetable = {
["1"]="0",
["2"]=".",
etc..
}
or isn't that possible in luaFX? it would be a lot smaller than now, so you don't need all those statements, just
parse..parsetable[tostring(key)]
-
does it work with the classes now? sounds great, now you're sort of the inventor of classes for casio lol
Just for LuaFX! :p
OW, 208 posts already?
-
ooh, i just took a look at it, and can't you remake that
if key(1) then parse = parse .. "0" end
if key(2) then parse = parse .. "." end
if key(4) then parse = parse .. "-" end
etc etc
to a table like this:
parsetable = {
["1"]="0",
["2"]=".",
etc..
}
or isn't that possible in luaFX? it would be a lot smaller than now, so you don't need all those statements, just
parse..parsetable[tostring(key)]
Ok, so this is using classes?
does it work with the classes now? sounds great, now you're sort of the inventor of classes for casio lol
Just for LuaFX! :p
OW, 208 posts already?
What do you mean by "Just for LuaFX"?
-
no flyingfisch, that's not classes, that's just a table and the reference to it..
i only don't know if that ["0"]= is possible in lua, it would make the work much easier
-
does it work with the classes now? sounds great, now you're sort of the inventor of classes for casio lol
Just for LuaFX! :p
OW, 208 posts already?
What do you mean by "Just for LuaFX"?
C/C++ and classes could be already compiled with GCC or Casio's SDK (if the first option is better than second). But Very good job for making classes :)
and just {"0","1","2"...} is enough, nah?
-
key(0) returns true if one or more keys are pressed.
-
I know that! I'm the guy who forc'd Veb to make that! :p
and with table = {"a" = 5}, we can make table.a = 5, I saw that with trying to make a tilemapper engine...
-
you should go look at my lib i have made for the nspire. it offers all of those things you mentioned plus more. its bieng updated and their are pictures on this site in another topic it might give you some ideas...:
http://ourl.ca/14633/276223;topicseen#new (http://ourl.ca/14633/276223;topicseen#new)
-
What does mean "EZ menus"?
-
is there a big difference between luaFX and Nspire lua? otherwise this gui from jwalker could be really useful
-
Not many graphics functions!
-
what functions are there?
basicly if it supports lines, arcs, text, and the abiliy to fill polygons like rectangles, thats prety much all you need
-
NOt arcs, only full circles.
I know that MonochromeLib support (for black and white) almost all of this (without arcs), but I dunno if Veb have implemented all of this
-
By the way, the class() code should work, but I didn't test it ... Did you ? :D
-
NOt now, I'm "working"... :-°
But alway here for LFX! :p
-
I know that! I'm the guy who forc'd Veb to make that! :p
and with table = {"a" = 5}, we can make table.a = 5, I saw that with trying to make a tilemapper engine...
I was responding to nick... sorry for the miscommunication :P
What does mean "EZ menus"?
Easy menus. Kind of like CASIO-BASIC menus.
is there a big difference between luaFX and Nspire lua? otherwise this gui from jwalker could be really useful
I dont think there is a very big difference, and I am looking at jwalkers code right now :)
-
very good project
good luck
-
you guys have a circle command O.O
i mentioned arcs because thats how we have to draw circles
@ flyingfisch: did you download it off of ticalc, because the new version is wayyyyy better, i mean its like comparing Windows 3.1 to Windows7
anyway im probably going to upload a prerelease version for poeple to test out and comment on very soon here, like maybe tonight.
anyway have fun this is a fun type of project :)
-
NOTE: I am posting this in PRIZM projects, but since there is no LuaFX for PRIZM yet, it would be nice to have a LuaFX/AFX projects section ;)
You could maybe ask admins, but the issue is that the AFX is discontinued so such section would be unpopular. It might be best to wait until LuaFX for the FX-9860G or the Prizm is complete.
-
@ flyingfisch: did you download it off of ticalc, because the new version is wayyyyy better, i mean its like comparing Windows 3.1 to Windows7
lol, is it really that bad your first version?
-
you guys have a circle command O.O
i mentioned arcs because thats how we have to draw circles
@ flyingfisch: did you download it off of ticalc, because the new version is wayyyyy better, i mean its like comparing Windows 3.1 to Windows7
anyway im probably going to upload a prerelease version for poeple to test out and comment on very soon here, like maybe tonight.
anyway have fun this is a fun type of project :)
New version???
Youll have to tell me where it is :P
-
it isnt out yet but i think i posted a link on the first page of the topic and it goes to my topic + some pics
-
Could I have a link to the topic?
-
sure:
http://ourl.ca/14633/276223;topicseen#new (http://ourl.ca/14633/276223;topicseen#new)
-
Thanks!
BTW:
Userbar!
(http://userbars.removedfromgame.com/ub/flyingfisch388.png)
-
@ flyingfisch: did you download it off of ticalc, because the new version is wayyyyy better, i mean its like comparing Windows 3.1 to Windows7
lol, is it really that bad your first version?
lol bad explanation on my part.
it wasnt bad it just was severly limited, and i changed the design of the dialog boxes and added a forms control
dialogs used to only support 1 line of text on the very top portion of the body of the dialog, no controls
below is two images comparing them, the second one is the new look:
(http://www.ticalc.org/cgi-bin/zipview?nspire/lua/libs/wzguilib.zip;12-04-2011%20Image001.jpg)
(http://www.omnimaga.org/index.php?action=dlattach;topic=12036.0;attach=11045;image)
also the context menus are completely random you could change any of the text you wanted to :)
-
Could someone tell me the basics of building a window manager?
-
thats a tough one.... on the TI-Nspire we have on. events
the window manager handles these events
i made a window class to handle that sort of thing
in Work Zone GUI Lib, WZGUILIB is just short for it, parent windows have a controls table and a dialogs table
some functions you would see would be--
window:drawControls(gc)
window:udateControls(control)
window:getFocus()
and a seperate function to find a specific window that is focused: curwin()
it also handlse the basic on. events like: charIn(char), mouseDown(x, y), mouseMove(x, y), backspaceKey(), paint(gc)
scince i dont know what is on prizm, i couldnt tell you what your functions are but if it is event based it would easily be similar
-
Is there lua code for on. events that i could port to luaFX?
-
i dont know what the code is behind the events, it would be operating systems stuff i suppose
-
i dont know what the code is behind the events, it would be operating systems stuff i suppose
Really? I cant do it like i did lua classes?
-
you might be able to... but i dont think so because the events would have to be raised by the operating system, of course your not as limited as we are so you could prbably figured out a way link the events in lua to say a keypress on the calc
-
how do on events work? maybe i can emulate them :)
-
i think a message is sent to the LUA interpreter on the TI-Nspire so thats the only way to recieve input that i can think of right now
-
I mean, how is an on event used? What do they do in a program?
-
o, what they dow is if there is an event, you write code to handle it
like this:
function on.mouseDown(x, y)
sdia.isdrawn = true
sdia.text = "mouse was pressed"
end
just a nod to my GUI library :)
-
do you have to define the event on.mouseDown, or is it in lua nspire by default?
-
its in lua nspire by default
-
ok so i could probably make my own on events using functions? also, casio calcs do not have a cursor default, so im going to try to implement that too. ;)
-
you might be able to make them with functions and a cursor couldnt be that hard, could it?
-
you might be able to make them with functions and a cursor couldnt be that hard, could it?
I could probably do the cursor with classes...
-
i would do cursors with classes, it would make it so much eiser, all you need is to make an image, and have a place to store x, y
-
just do
cursortypes = {
*cursor image data here*
}
cursor:init(x,y,type)
self.x = x
self.y = y
self.type = cursortypes[type]
end
Cursor = cursor(50,50,*number here*)
this way you can add different cursor like we have in nspire, which you can find here (https://sites.google.com/site/stonesetproductions/sources/cursors.zip?attredirects=0&d=1)
it contains a zip with all the cursors in a different image
and then assign a function to it to change the cursor
function cursor:set(type)
Cursor.type = cursortypes[type]
end
cursor:set(*number here*)
-
Thanks nick for your code :)
and for your cursor images (i was having trouble making one that didnt look silly. lol)
@jwalker: Is there a sample program that uses your library that I look at? I want to see how the library is used in a program. Also, which post in your thread has the latest code?
-
im actualy about to upload a prerelease version right now, check in a few miniutes, im using an old crappy school computer so it might take some time :P
EDIT: uploaded!
-
im actualy about to upload a prerelease version right now, check in a few miniutes, im using an old crappy school computer so it might take some time :P
OK. :D
just do
cursortypes = {
*cursor image data here*
}
cursor:init(x,y,type)
self.x = x
self.y = y
self.type = cursortypes[type]
end
Cursor = cursor(50,50,*number here*)
this way you can add different cursor like we have in nspire, which you can find here (https://sites.google.com/site/stonesetproductions/sources/cursors.zip?attredirects=0&d=1)
it contains a zip with all the cursors in a different image
...
OK, does that code use classes or what? (This is my first major program with lua so please bear with me :) )
-
this code does use classes, the one he gave you and mine also
-
I'm gonna have to take another look at jimbauwens explanation of classes :)
-
thats a good idea too, my code only uses one instance of inheritance though, in the form class, do to the fact that the lib is quit large and poeple should be able to choose what code they need and take the other stuff out.
this way if they take out some class and some other class had to inherit from it there would be errors.
also i might add a control class for the controls to inherit from, but i may not do to the fact im trying to make it smaller and more optimized :)
-
thats a good idea too, my code only uses one instance of inheritance though, in the form class, do to the fact that the lib is quit large and poeple should be able to choose what code they need and take the other stuff out.
this way if they take out some class and some other class had to inherit from it there would be errors.
also i might add a control class for the controls to inherit from, but i may not do to the fact im trying to make it smaller and more optimized :)
OK.
Is there a list of on events and their usage?
-
no i didnt list them but they are descriptive...
for example:
function on.mouseDown(x, y) means the mouse was clicked and returns to us x and y
function on.charIn(char) means that a key other than an arrow key was pressed and returns char to us
-
i thought he meant functions from your gui jwalker.. here are all the functions standard in nspire lua
Function name Arguments Called when
on.paint(gc) GC is the graphical context (explained later) platform.window:invalidate() is called
on.arrowKey(arrow) Arrow returns ‘left’,’right’,’up’ or ‘down’ An arrow key had been pressed
on.arrowLeft() - The left arrow key has been pressed
on.arrowRight() - The right arrow key has been pressed
on.arrowUp() - The up arrow key has been pressed
on.arrowDown() - The down arrow key has been pressed
on.enterKey() - The enter key has been pressed
on.escapeKey() - The escape key has been pressed
on.tabKey() - The tab key has been pressed
on.charIn(char) Char can return any char, e.g. char = ‘+’ Any character key has been pressed
on.mouseMove(x,y) x and y return the position of the mouse The mouse moves
on.mouseDown(x,y) x and y return the position of the mouse The mouse has been pressed
on.mouseUp(x,y) x and y return the position of the mouse The mouse has been released
on.create() - The file gets opened (made)
on.destroy() - The file gets closed (destroyed)
on.resize() - The screen is resized (when in the pc software)
on.timer() - The timer is called
on.deleteKey() - The delete key has been pressed
on.backspaceKey() - The backspace key has been pressed
on.returnKey() - The return key has been pressed
on.contextMenu() - The [ctrl][menu] key has been pressed
on.help() - The [ctrl][trig] has been pressed
on.clearKey() - The clear key has been pressed
on.activate() - The tab/page gets activated
on.deactivate() - The tab/page gets inactivated
on.blink() - The focus gets lost on the page
or just go here (http://wiki.inspired-lua.org/Overview_of_the_API)
it's the events part
-
in my GUI on. events are ususaly sent to the window that was retrieved from the curwin() function, except mouse down will check all windows because then a user can give them focus and effectively redraw them overtop of the other windows
some on. events i dont implement, because i dont use them, like on.blink
-
i thought he meant functions from your gui jwalker.. here are all the functions standard in nspire lua
Function name Arguments Called when
on.paint(gc) GC is the graphical context (explained later) platform.window:invalidate() is called
on.arrowKey(arrow) Arrow returns ‘left’,’right’,’up’ or ‘down’ An arrow key had been pressed
on.arrowLeft() - The left arrow key has been pressed
on.arrowRight() - The right arrow key has been pressed
on.arrowUp() - The up arrow key has been pressed
on.arrowDown() - The down arrow key has been pressed
on.enterKey() - The enter key has been pressed
on.escapeKey() - The escape key has been pressed
on.tabKey() - The tab key has been pressed
on.charIn(char) Char can return any char, e.g. char = ‘+’ Any character key has been pressed
on.mouseMove(x,y) x and y return the position of the mouse The mouse moves
on.mouseDown(x,y) x and y return the position of the mouse The mouse has been pressed
on.mouseUp(x,y) x and y return the position of the mouse The mouse has been released
on.create() - The file gets opened (made)
on.destroy() - The file gets closed (destroyed)
on.resize() - The screen is resized (when in the pc software)
on.timer() - The timer is called
on.deleteKey() - The delete key has been pressed
on.backspaceKey() - The backspace key has been pressed
on.returnKey() - The return key has been pressed
on.contextMenu() - The [ctrl][menu] key has been pressed
on.help() - The [ctrl][trig] has been pressed
on.clearKey() - The clear key has been pressed
on.activate() - The tab/page gets activated
on.deactivate() - The tab/page gets inactivated
on.blink() - The focus gets lost on the page
or just go here (http://wiki.inspired-lua.org/Overview_of_the_API)
it's the events part
So yeah, this should be pretty easy to do with classes, right?
-
certainly, you will only have to use loops to determine if a function needs to be called or not..
luaFX is in loops, isn't it?
-
certainly, you will only have to use loops to determine if a function needs to be called or not..
luaFX is in loops, isn't it?
As in, it supports loops?
-
no, i mean, is it event-based? or just like basic programs that you have to create a loop that gets repeated constantly and from which you call certain functions if a statement is true
-
LuaFX is almost exactly the same as lua 5.1. I guess you could make it event based somehow...But yeah, I think you have to do loops
-
Bug report!
After procrastinating for a day, i decided to test the lua classes code with this program:
local print = graydraw.print
class = function(prototype)
local derived = {}
local derivedMT = {
__index = prototype,
__call = function(proto, ...)
local instance = {}
local instanceMT = {
__index = derived,
__call = function()
return nil, "ERROR: Attempt to invoke an instance of a class"
end,
}
setmetatable(instance, instanceMT)
if instance.init then
instance:init(...)
end
return instance
end,
}
setmetatable(derived, derivedMT)
return derived
end
car = class()
function car: init(power, type, lights, etc)
self.power = power
self.type = type
self.lights = lights*2
self.options = etc
end
jeep = car(60, "4x4", 12, {air-conditioning = False, trailer-hook = True})
if jeep.options.trailer-hook then
print("The jeep can have a trailer")
else
print("No trailer for you :(")
end
And....I get an error:
[string 'experiment.lua']:35: '}' expected near '='
So is there a problem with my code, luaFX, or the lua class code?
-
try to remove the spaces, and if that does not work, place quotation mark around the air-conditioning and if that doe not work place [" "] around ari conditioning and if that does not work you're lost xp
-
Well, apparently it did not like the dashes. But now I get another error with this code D:
local print = graydraw.print
class = function(prototype)
local derived = {}
local derivedMT = {
__index = prototype,
__call = function(proto, ...)
local instance = {}
local instanceMT = {
__index = derived,
__call = function()
return nil, "ERROR: Attempt to invoke an instance of a class"
end,
}
setmetatable(instance, instanceMT)
if instance.init then
instance:init(...)
end
return instance
end,
}
setmetatable(derived, derivedMT)
return derived
end
car = class()
function car: init(power, type, lights, etc)
self.power = power
self.type = type
self.lights = lights*2
self.options = etc
end
jeep = car(60, "4x4", 12, {airconditioning = false,trailerhook = true})
if jeep.trailerhook then
print("The jeep can have a trailer")
else
print("No trailer for you :(")
end
Error message:
[string 'experiment.lua']:22: Attempt to call global 'setmetatable', a nil value
-
maybe its something with LuaFX...
the way you used setmetatable works on oclua...
-
oclua?
-
o_O
setmetatable() is a native lua function ....
:o
( http://lua-users.org/wiki/MetamethodsTutorial (http://lua-users.org/wiki/MetamethodsTutorial) )
What version of Lua are you using ?
That may be the problem...
Also, I know there are some encoding problem with Omnimaga codes in posts.
Here's the class function, that you can again copy/paste, maybe it will work this time ?
http://pastebin.com/9gTmaKKK (http://pastebin.com/9gTmaKKK)
-
I guess this is why luaFX is called beta right now. :P
I'll have to ask eiyeron to talk to veb about it for me. :)
-
oclua is the nspire on-calc lua programming stuff
-
Oh, ok. So On-Calc lua. ok :)
-
well, flyingfisch, don't feel like making one too? could be very useful..
-
well, flyingfisch, don't feel like making one too? could be very useful..
On-calc lua editor? Yeah, I think I'll try that when I learn C/C++. Which I should probably do pretty soon. :P
Which language do you think I should learn? C or C++? They both make addins.
-
i asked myself that question too, most people say C++, dunno why, but it's true..
btw: i don't know the difference..
-
i asked myself that question too, most people say C++, dunno why, but it's true..
btw: i don't know the difference..
neither do I :D
I think I'll just stick with lua and make the on-calc editor in lua when we get the ability to write programs from a lua file. ;)
-
I am doing both :)
-
I am doing both :)
Doing both? ???
-
Yea it's taking a long time. :p
I'm learning c for OS development and c++ for
Everything else I can think of :)
-
Yea it's taking a long time. :p
I'm learning c for OS development and c++ for
Everything else I can think of :)
lol. Yeah, I should learn... but... I'm lazy/busy :D :P
-
Yea that's why it's taking so long
It seems like I get it down and het caught up in something else
-
When I asked on planet-casio why it didnt work, Veb (the main LFX developer) responded that:
I believed these functions will never be used, that's why I didn't include them.
If you believe it is necessary, I will include them.
So we should be able to start this project up again pretty soon :)
-
thats great! oh and i updated the lua script to handle windows better if you want to look at it...
http://ourl.ca/14633/277096;topicseen#new (http://ourl.ca/14633/277096;topicseen#new)
-
cool!
-
yea im prety much on the last thing, improuving the textboxes... after that its documentation time :)
-
yea im prety much on the last thing, improuving the textboxes... after that its documentation time :)
Nice. :)
-
i figure i will be done within this week :)