Author Topic: Updating WZGUILib  (Read 158700 times)

0 Members and 1 Guest are viewing this topic.

Offline jwalker

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 660
  • Rating: +13/-0
  • Almost everything I have released includes a 'WZ'
    • View Profile
Updating WZGUILib
« on: December 27, 2011, 12:03:30 am »
Ok, so im updating my library and the documentation. So far i have Dialog Boxes, Text Boxes, Radio Buttons, Check Boxes, Numeric Up Downs, Labels and Picture Boxes. I would like some input if you have used my library or if i could add some controlls to it.
I did fix the picture box bug so it does work correctly, I am also working on adding more editing functions to the text boxes.
tell me if i missed something
<a href="http://www.nerdtests.com/ft_cg.php?im">
<img src="http://www.nerdtests.com/images/ft/cg.php?val=9612" alt="My computer geek score is greater than 41% of all people in the world! How do you compare? Click here to find out!"> </a>

Support Casio-Scene against the attacks of matt @ matpac.co.uk ! For more information: Casio-Scene shuts down & Matt actions threads

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Updating WZGUILib
« Reply #1 on: December 27, 2011, 04:55:54 am »
Hi :)
I never tried your library but to me it doesn't look like you are using classes.
Making your code object oriented will make your life a 1000 times easier ;)

In case you never heard of classes, here is some reference:
http://ourl.ca/12291
http://www.inspired-lua.org/2011/05/5-object-classes/

I would also try to use a "screenmanager", create a screen class were all the functions of "on" are redirected too.
You can also take a look at  my GUI library I'm developing for EEPro (https://github.com/adriweb/EEPro-for-Nspire ). I extensively use classes there.
« Last Edit: December 27, 2011, 04:56:11 am by jimbauwens »

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Updating WZGUILib
« Reply #2 on: December 27, 2011, 06:48:36 am »
Good job, but in EEPro, we've been doing some intensive GUI Lib work, and here's an example of dialog boxes we make :



with this kind of code :

Code: [Select]

add_unit = Dialog("Add unit","10","7.5","80","85")

unit_value = sInput()
unit_value.ww = "77"
unit_value.number = true

units_list = sList()
units_list.hh = "41"
units_list.ww = "77"
units_list.shrink = true

lbl1 = sLabel("Value:", unit_value)
lbl2 = sLabel("Unit:", units_list)

button_ok = sButton("OK", compute)
button_esc = sButton("Cancel", remove_screen)

add_unit:appendWidget(lbl1, "2", "18")
add_unit:appendWidget(lbl2, "2", "38")
add_unit:appendWidget(unit_value, "20", "18")
add_unit:appendWidget(units_list, "20", "38")
add_unit:appendWidget(button_ok, "60", "82")
add_unit:appendWidget(button_esc, "75", "82")

( https://github.com/adriweb/EEPro-for-Nspire/blob/master/2%20-%20%20FormulaPro/FPGui.lua )

They are all interactive (tab keys to switch focus, unicode input text, react to mouse and keyboard) etc.

Maybe you should try to make some native-looklike GUI stuff and then we'd combien what you have with what we've done in EEPro ? :)
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline jwalker

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 660
  • Rating: +13/-0
  • Almost everything I have released includes a 'WZ'
    • View Profile
Re: Updating WZGUILib
« Reply #3 on: December 27, 2011, 11:23:57 am »
ok good to know. one of the reasons i am updating it is to make a better use of the lua's OOP programming.
the screen manager idea is one that i hadnt thought of before that i probably should have.
The EEPro stuff looks realy cool too
<a href="http://www.nerdtests.com/ft_cg.php?im">
<img src="http://www.nerdtests.com/images/ft/cg.php?val=9612" alt="My computer geek score is greater than 41% of all people in the world! How do you compare? Click here to find out!"> </a>

Support Casio-Scene against the attacks of matt @ matpac.co.uk ! For more information: Casio-Scene shuts down & Matt actions threads

Offline Nick

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1166
  • Rating: +161/-3
  • You just got omnom'd
    • View Profile
    • Nick Steen
Re: Updating WZGUILib
« Reply #4 on: December 28, 2011, 03:50:31 pm »
would you mind posting your source, or a screenie with everything working? i wanna see how it looks like

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Updating WZGUILib
« Reply #5 on: December 28, 2011, 03:59:46 pm »
Just check ticalc.org :)

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: Updating WZGUILib
« Reply #6 on: December 28, 2011, 05:00:38 pm »
So... Whats wsguilib? A GUI library?

Offline Nick

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1166
  • Rating: +161/-3
  • You just got omnom'd
    • View Profile
    • Nick Steen
Re: Updating WZGUILib
« Reply #7 on: December 28, 2011, 05:12:47 pm »
yes it is a set of radiobuttons, checkboxes, screens, textboxes etc

here's a pic of it:
« Last Edit: December 28, 2011, 05:13:07 pm by Nick »

Offline jwalker

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 660
  • Rating: +13/-0
  • Almost everything I have released includes a 'WZ'
    • View Profile
Re: Updating WZGUILib
« Reply #8 on: December 28, 2011, 06:00:15 pm »
yea, i added some stuff to it and put it on ticalc a few hours ago. some things i have to fix yet is the lack of inheritance and the fact that dialog boxes only support text right now. its a good thing i have the rest of christmas break to work on it :)
meaning i am adding a screen manager and better features for dialog boxes
here is some code for  numeric up downs that i added:
Code: [Select]
function NumericUD:init(x, y, num, selected, linecolor, maxnum, minnumber, textcolor, pmbcolor)
self.x = x
self.y = y
self.pmbcolor = pmbcolor
self.num = num
self.text = tostring(num)
self.selected = selected
self.linecolor = linecolor
self.maxnum = maxnum
self.minnumber = minnumber
self.textcolor = textcolor
self.width = 42
self.height = 23
table.insert(NUDTable, self)
end

function NumericUD:paint(gc)
gc:setPen("thin", "smooth")
gc:setColorRGB(unpack(self.pmbcolor))
gc:drawLine(self.x + 35, self.y, self.x + 35, self.y + 23)
gc:drawLine(self.x + 35, self.y + 11, self.x + 42, self.y + 11)
gc:setFont("serif", "r", 6)
gc:drawString("+", self.x + 36, self.y - 2, "top")
gc:drawString("-", self.x + 36, self.y + 10, "top")
gc:setColorRGB(unpack(self.linecolor))
gc:drawRect(self.x, self.y, self.width, self.height)
gc:setColorRGB(unpack(self.textcolor))
gc:setFont("serif", "r", 11)
gc:drawString(self.text, self.x + 2, self.y + 2, "top")
end
function NumericUD:click(x, y)
if y >= self.y and y <= self.y + 11 and x >= self.x + 35 and x <= self.x + 40 then
self:Up()
elseif y >= self.y + 11 and y <= self.y + 23 and x >= self.x + 35 and x <= self.x + 40 then
self:Down()
end
end
function NumericUD:Up()
if self.num ~= self.maxnum then
self.num = self.num + 1
self.text = tostring(self.num)
end
platform.window:invalidate()
end
function NumericUD:Down()
if self.num ~= self.minnumber then
self.num = self.num - 1
self.text = tostring(self.num)
end
platform.window:invalidate()
end
function drawNUD(gc)
for _, NUD in pairs(NUDTable) do
NUD:paint(gc)
end
end
i probably would have worked on it way more, but i found a bug in the picture box function
<a href="http://www.nerdtests.com/ft_cg.php?im">
<img src="http://www.nerdtests.com/images/ft/cg.php?val=9612" alt="My computer geek score is greater than 41% of all people in the world! How do you compare? Click here to find out!"> </a>

Support Casio-Scene against the attacks of matt @ matpac.co.uk ! For more information: Casio-Scene shuts down & Matt actions threads

Offline Nick

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1166
  • Rating: +161/-3
  • You just got omnom'd
    • View Profile
    • Nick Steen
Re: Updating WZGUILib
« Reply #9 on: December 28, 2011, 06:01:07 pm »
maybe i can give you one advice. i would make the colors more soft. I mean not those flashy green fluocolors, but simple grey or so

and maybe put the close button on the dialog box in the middle, it will look more real if you understand what i mean

Offline jwalker

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 660
  • Rating: +13/-0
  • Almost everything I have released includes a 'WZ'
    • View Profile
Re: Updating WZGUILib
« Reply #10 on: December 28, 2011, 06:18:49 pm »
i was thinking something like that too. and i might change the circle to a square. the colors can be changed just by creating the dialog box or changing the color after it is created kind of like this:
Code: [Select]
----colors:
color = {
black = {0, 0, 0},
lightgreen = {0, 255, 0},}
-----------dialog code
dialog = class()

function dialog:init( x, y, text, title, isselected, backcolor, textcolor, closecolor, isdrawn)--add buttons and other features
self.x = x
self.y = y
self.text = text
self.title = title
self.width = 200
self.height = 150
self.cbw = 10
self.cbh = 10
self.cbx = self.x + 175
self.cby = self.y + 7
self.selected = isselected
self.backcolor = backcolor
self.textcolor = textcolor
self.closecolor = closecolor
self.isdrawn = isdrawn
self.moveable = false
table.insert(dialogTable, self)
end
function dialog:paint(gc)
if self.isdrawn then
gc:setFont("sansserif", "b", 12)
gc:setColorRGB(unpack(self.backcolor))
gc:fillRect( self.x, self.y, self.width, self.height)
gc:setColorRGB(unpack(color.white))
gc:fillRect( self.x + 5, self.y + 20, self.width - 10, self.height - 30)
gc:setColorRGB(unpack(self.textcolor))
if string.len(self.title) > 10 then
self.title = string.sub(self.title, 1, 10).."..."
end
gc:drawString(self.title, self.x + 10, self.y + 8, "middle")
gc:drawString(self.text, self.x + 9, self.y + 25, "middle")
gc:setColorRGB(unpack(self.closecolor))
gc:fillArc( self.cbx, self.cby, self.cbw, self.cbh, 0, 360)
end
end
function dialog:checkUnclick()
self.moveable = false
cursor.set("default")
self.selected = false
platform.window:invalidate()
end
function dialog:checkClick(x, y)
if self.isdrawn then
if (x >= self.cbx and x <= self.cbx + 10) and (y >= self.cby and y <= self.cby + 10) then
self:close()
elseif self.moveable == false and (x >= self.x and x <= self.x + self.width) and (y >=self.y and y <= self.y + (self.height - 130)) then
self:wasclicked(x, y)
else
self:checkUnclick()
end
end
end
function dialog:close()
self.selected = false
self.isdrawn = false
self.moveable = false
cursor.set("default")
platform.window:invalidate()
end
function dialog:wasclicked(x, y)
self.moveable = true
if self.selected ~= self then
for _, dlg in pairs(dialogTable) do
dlg.selected = false
end
self.selected = true
end
self.xvar = x - self.x
self.yvar = y - self.y
cursor.set("drag grab")
platform.window:invalidate()
end
function dialog:mouseMove(x, y)
if self.moveable and self.isdrawn and self.selected then
cursor.set("drag grab")
self.x = x - self.xvar
self.y = y - self.yvar
self.cbx = self.x + 175
self.cby = self.y + 7
platform.window:invalidate()
end
end
function drawDialog(gc)
for _, SD in pairs(dialogTable) do
if SD.isdrawn then
SD:paint(gc)
end
end
end
------------
---------------create the dialog box
function on.create()
dia1 = dialog(45, 23, "Color change", "Colors", false, color.lightgreen, color.red, color.red, true)
end
----------------------------say a function changes the color like this later on if it is called
function color_change()
dia1.backcolor = color.black
-----after that the color of the boarder would be black
end
in the end its what the programmer decides, but i probably would tone the colors down just because they are hard to see on the calc :P
EDIT: @epic7 it is a small, easy to use gui library that offers quite a few features, im working on making a better use of the OOP that Nspire lua offers
« Last Edit: December 28, 2011, 07:12:14 pm by jwalker »
<a href="http://www.nerdtests.com/ft_cg.php?im">
<img src="http://www.nerdtests.com/images/ft/cg.php?val=9612" alt="My computer geek score is greater than 41% of all people in the world! How do you compare? Click here to find out!"> </a>

Support Casio-Scene against the attacks of matt @ matpac.co.uk ! For more information: Casio-Scene shuts down & Matt actions threads

Offline jwalker

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 660
  • Rating: +13/-0
  • Almost everything I have released includes a 'WZ'
    • View Profile
Re: Updating WZGUILib
« Reply #11 on: December 29, 2011, 06:54:50 pm »
Im trying to make a cursor for the text box but ive encountered a problem...
im not quite sure if the "gc:getStringWidth" command works properly
does anyone else have problems with it
<a href="http://www.nerdtests.com/ft_cg.php?im">
<img src="http://www.nerdtests.com/images/ft/cg.php?val=9612" alt="My computer geek score is greater than 41% of all people in the world! How do you compare? Click here to find out!"> </a>

Support Casio-Scene against the attacks of matt @ matpac.co.uk ! For more information: Casio-Scene shuts down & Matt actions threads

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Updating WZGUILib
« Reply #12 on: December 30, 2011, 04:26:18 am »
It works fine for me. What is the problem ?

Offline jwalker

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 660
  • Rating: +13/-0
  • Almost everything I have released includes a 'WZ'
    • View Profile
Re: Updating WZGUILib
« Reply #13 on: December 30, 2011, 11:12:41 am »
the problem is that with diffrent charachters like a and A it dosen't seem to recognize the diffrence in size:
example this code:
Code: [Select]
textbox = class()

function textbox:init(x, y, text, selected, textcolor, tbcolor)
self.x = x
self.y = y
self.width = 156
self.height = 20
self.text = text
self.textcolor = textcolor
self.tbcolor = tbcolor
self.selected = isselected
self.curx = self.x + platform.gc():getStringWidth(self.text)
self.cury = y + 1
self.curh = (self.y + self.height) - 1
table.insert(textboxTable, self)
end
function textbox:paint(gc)
gc:setColorRGB(unpack(self.tbcolor))
gc:drawRect( self.x, self.y, self.width, self.height)
gc:setColorRGB(unpack(self.textcolor))
gc:setFont("serif", "r", 11)
gc:drawString( self.text, self.x + 4, self.y + 8, "middle")
gc:setColorRGB(unpack(color.black))
gc:drawLine(self.curx, self.cury, self.curx, self.curh)
end
function textbox:charIn(ch)
if self.selected then
if (self.width - 8) < platform.gc():getStringWidth(self.text) then
platform.window:invalidate()
else
self.text = self.text..ch
self.curx = self.x + platform.gc():getStringWidth(self.text) + 2
platform.window:invalidate()
end
end
end
function textbox:backspace()
if self.selected then
self.text = string.sub(self.text, 1, string.len(self.text) - 1)
self.curx = self.x + platform.gc():getStringWidth(self.text) + 2
platform.window:invalidate()
end
end

function textbox:click()
if self.selected then
self.selected = false
else
for _, tb in pairs(textboxTable) do
tb.selected = false
end
self.selected = true
end
platform.window:invalidate()
end

function textbox:checkClick(x, y)
if y >= self.y and y <= self.y + self.height and x >= self.x and x <= self.x + self.width then
self:click()
end
end
the code is this: cury = self.x + platform.gc():getStringWidth(self.text)
it seems that if you continualy type a lowercase "a" the cursor goes farther ahead
and it seems that if you continualy type a capital "A" the cursor will fall behind
this is the same for most of the capitol and lowercase letters
also this dosent have a drawTB function because im working on a small screen manager
<a href="http://www.nerdtests.com/ft_cg.php?im">
<img src="http://www.nerdtests.com/images/ft/cg.php?val=9612" alt="My computer geek score is greater than 41% of all people in the world! How do you compare? Click here to find out!"> </a>

Support Casio-Scene against the attacks of matt @ matpac.co.uk ! For more information: Casio-Scene shuts down & Matt actions threads

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Updating WZGUILib
« Reply #14 on: December 30, 2011, 12:24:16 pm »
Your problem might come from the fact that you're using platform.gc():getStringWidth()  instead of the normal  gc  you use when you draw stuff.
platform.gc() initialize a new  gc   and then doesn't know about the font properties (size etc.) of the one you want, so this is probably the source of problem...

Try either to :
  -  pass gc (the one you use to draw with) to the function where   getStringWidth()   is needed, then do that with this gc.
  -  calculate the width beforehand (then pass it to the function)... but that might be too heavy. It's better to use the 1st solution.
« Last Edit: December 30, 2011, 12:26:34 pm by adriweb »
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation