Author Topic: [Lua] Image Editor  (Read 39336 times)

0 Members and 1 Guest are viewing this topic.

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: [Lua] Image Editor
« Reply #60 on: October 31, 2011, 07:21:45 am »
I don't have written any readme
* Chockosta runs

But everything should be listed in the menu

Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: [Lua] Image Editor
« Reply #61 on: October 31, 2011, 07:24:41 am »
Oh yeah. I'm keep forgetting to try menu button XP
thanks XD
Sig wipe!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: [Lua] Image Editor
« Reply #62 on: December 25, 2011, 09:59:44 pm »
I like the new features. I didn't try this yet but I should really do so, soon. I haven't read the thread yet but I am curious how the sprite saving/exporting (if any exporting) works? Is it possible to create sprites for use in other tns files? I don't recall the Nspire having any form of external file like on the 83+.

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: [Lua] Image Editor
« Reply #63 on: December 26, 2011, 05:20:36 am »
I like the new features. I didn't try this yet but I should really do so, soon. I haven't read the thread yet but I am curious how the sprite saving/exporting (if any exporting) works? Is it possible to create sprites for use in other tns files? I don't recall the Nspire having any form of external file like on the 83+.

Actually when you copy/paste things, it stays in memory even when you close the current document.
So you can put something from a doc to another that way.

But anyway, there is another way that consists into saving a var in a public document stored in the MyLib folder, because this one can be accessed "dynamically" whenever and from wherever you want, so this is good for sharing stuff between docs.
This is the technique we'll use in EEPro. (for loading user-made custom formula databases)
« Last Edit: December 26, 2011, 05:20:58 am by adriweb »
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: [Lua] Image Editor
« Reply #64 on: December 27, 2011, 01:11:48 am »
I see, but how do we retrieve it? Is there a function in Lua that does that or do you access memory directly?

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: [Lua] Image Editor
« Reply #65 on: December 27, 2011, 06:42:19 am »
I see, but how do we retrieve it? Is there a function in Lua that does that or do you access memory directly?
There are clipboard setter and getters, yes.
Same for math variables :)
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: [Lua] Image Editor
« Reply #66 on: December 28, 2011, 02:19:32 pm »
I am currently rewriting this project...
It should not take too much time, so expect some news soon...

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: [Lua] Image Editor
« Reply #67 on: December 30, 2011, 06:06:41 pm »
Good to hear. Good luck! :)

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: [Lua] Image Editor
« Reply #68 on: December 31, 2011, 11:13:53 am »
Some work on the GUI...
It is now possible to open a native-like window with 1 line :
Code: [Select]
gui.addWindow("Title","dialogBox","This text shows multi-line text functions :\nLorem ipsum dolor sit amet",{{"Button 1"},{"Button 2"},{"Another button"}})
See attachment for result.

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: [Lua] Image Editor
« Reply #69 on: December 31, 2011, 12:29:20 pm »
That's some impressive native-looking window.

Did you do it by yourself or took some routines from EEPro ? :) (No proble, if you did :) )
If you didn't, we could use some of your code for EEPro, then ?

(You'd be a contributor if you want, actually)


Edit :  Also, code ? :D
« Last Edit: December 31, 2011, 12:39:46 pm by adriweb »
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: [Lua] Image Editor
« Reply #70 on: December 31, 2011, 03:24:30 pm »
Looks pretty nice indeed. :)

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: [Lua] Image Editor
« Reply #71 on: December 31, 2011, 05:21:32 pm »
Wow, I'm also busy on a GUI api (for EEPro) that looks like native dialogs (some of my dialogs can just look the same as yours :P)
Maybe we can share ideas?

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: [Lua] Image Editor
« Reply #72 on: January 01, 2012, 04:35:44 am »
@Adriweb :
I didn't take any routine from EEPro. If I did, I would have mentioned it. By the way, I didn't know that the source code of EEPro was visible... Where could I see it ?
You sure can use my code, but for now there is almost nothing. (no event gestion, no custom layout...)
And it might not be easy since I don't use OOP.

@DJ_O :
Thanks !

@jimbauwens :
I would be honored to share ideas with you, but my little GUI engine is nothing compared to EEPro API. I will just add text boxes, and it will be enough for me...

If you want the code of this sample, here it is :
Code: [Select]
--GUI GESTION
gui={}
gui.windows={}
gui.dialogBox={}

function gui.errorMessage(errorText)
 gui.addWindow("Error","dialogBox",errorText,{{"OK"}})
end

function gui.addWindow(windowName,windowType,text,buttons)
 table.insert(gui.windows,{windowName,windowType,text,buttons})
end

function gui.closeWindow()
 table.remove(gui.windows)
end

function gui.nbWindows()
 return #gui.windows
end

function gui.current()
 return gui.windows[#gui.windows]
end

function gui.paint(gc)
 for i,e in pairs(gui.windows) do
  gui[e[2]].paint(gc,e)
 end
end

function gui.dialogBox.paint(gc,dialogBox)
 gc:setFont("sansserif","r",10)
 local sizeX=improvedStr.width(gc,dialogBox[3])+24
 local sizeY=improvedStr.height(gc,dialogBox[3])+17
 gui.paintWindowBG(gc,dialogBox[1],sizeX,sizeY)
 gui.paintTextArea(gc,dialogBox[3],sizeX,sizeY)
 gui.paintButtons(gc,dialogBox[4],sizeX,sizeY)
end

function gui.paintButtons(gc,buttons,sizeX,sizeY)
 local x,y=(width()-sizeX)/2,(height()-sizeY-15)/2
 local size,totalSize,pos={},-7,{}
 for i,e in pairs(buttons) do
  size[i]=gc:getStringWidth(e[1])+10
  totalSize=totalSize+size[i]+7
 end
 pos[1]=(width()-totalSize)/2
 for i=2,#buttons do
  pos[i]=pos[i-1]+size[i-1]+7
 end
 for i,e in pairs(buttons) do
  gc:setColorRGB(136,136,136)
  gc:fillRect(pos[i],y+sizeY+9,size[i],23)
  gc:fillRect(pos[i]+1,y+sizeY+8,size[i]-2,25)
  gc:fillRect(pos[i]+2,y+sizeY+7,size[i]-4,27)
  gc:setColorRGB(255,255,255)
  gc:fillRect(pos[i]+2,y+sizeY+9,size[i]-4,23)
  gc:setColorRGB(0,0,0)
  gc:drawString(e[1],pos[i]+5,y+sizeY+20,"middle")
 end
end

function gui.paintTextArea(gc,text,sizeX,sizeY)
 local x,y=(width()-sizeX)/2,(height()-sizeY-15)/2
 if isCX() then
  gc:setColorRGB(128,128,128)
 else
  gc:setColorRGB(255,255,255)
 end
 gc:drawRect(x+6,y+6,sizeX-13,sizeY-13)
 gc:setColorRGB(0,0,0)
 improvedStr.draw(gc,text,x+12,y+9)
end

function gui.paintWindowBG(gc,name,sizeX,sizeY)
 local x,y=(width()-sizeX)/2,(height()-sizeY-15)/2
 if isCX() then
  gc:setColorRGB(100,100,100)
 else
  gc:setColorRGB(200,200,200)
 end
 gc:fillRect(x-1,y-23,sizeX+4,sizeY+65)
 gc:fillRect(x,y-22,sizeX+4,sizeY+65)
 gc:fillRect(x+1,y-21,sizeX+4,sizeY+65)
 if isCX() then
  gc:setColorRGB(128,128,128)
 else
  gc:setColorRGB(0,0,0)
 end
 gc:fillRect(x-2,y-24,sizeX+4,sizeY+65)
 if isCX() then
  for i=1,22 do
   gc:setColorRGB(32+i*3,32+i*3,32+i*3)
   gc:fillRect(x,y+i-23,sizeX,1)
  end
 else
  gc:setColorRGB(0,0,0)
  gc:fillRect(x,y-22,sizeX,22)
 end
 gc:setColorRGB(255,255,255)
 gc:setFont("sansserif","r",10)
 gc:drawString(name,x+2,y-9,"baseline")
 gc:setColorRGB(224,224,224)
 gc:fillRect(x,y,sizeX,sizeY+39)
 gc:setColorRGB(128,128,128)
 gc:fillRect(x+6,y+sizeY,sizeX-12,2)
end




--MULTIPLE LINE STRING GESTION
improvedStr={}

function improvedStr.draw(gc,str,x,y)
 str=tostring(str)
 local table1={improvedStr.cut(str)}
 for i,e in pairs(table1) do
  gc:drawString(e,x,y+(i-1)*gc:getStringHeight("a"),"top")
 end
end

function improvedStr.width(gc,str)
 str=tostring(str)
 local table1={improvedStr.cut(str)}
 local table2={}
 for i,e in pairs(table1) do
  table2[i]=gc:getStringWidth(e)
 end
 table.sort(table2)
 return table2[#table2]
end

function improvedStr.height(gc,str)
 str=tostring(str)
 local table1={improvedStr.cut(str)}
 return gc:getStringHeight("a")*#table1
end

function improvedStr.cut(str)
 local table1,finished={},false
 local posStart,posEnd,last=1,0,1
 while not finished do
  posStart,posEnd=string.find(str,"\n",posEnd+1)
  if posStart then
   table.insert(table1,string.sub(str,last,posStart-1))
   last=posEnd+1
  else
   table.insert(table1,string.sub(str,last))
   finished=true
  end
 end
 return unpack(table1)
end

-- END OF GUI
 
function width() return platform.window:width() end
function height() return platform.window:height() end
function isCX() return platform.isColorDisplay() end
 
gui.addWindow("Title","dialogBox","This text shows multi-line text functions :\nLorem ipsum dolor sit amet",{{"Button 1"},{"Button 2"},{"Another button"}})

function on.paint(gc)
 gui.paint(gc)
end

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: [Lua] Image Editor
« Reply #73 on: January 01, 2012, 04:49:02 am »
Really nice, thanks ;)

I'll let Jim Bauwens decide how these ideas are shared etc.

Maybe we should all (all the community) share our code and put it somewhere on GitHub in a seperate project ("nGUI ?"), in order to have a common GUI project library.
With everyone's code and ideas, we sure would have the best-looking library :)


Edit : I tested it and it works great : Indeed, it's purely graphical so no interactinos or whatever, but still, the graphical part and the awesome-native-look is a good point.
Jim's way in EEPro is actually more complex since everything in the dialog box is "modular" and can act with the keyboard/mouse since the list, the text inputs etc. are all widgets added to a main widget (the dialog box)
« Last Edit: January 01, 2012, 04:58:47 am by adriweb »
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: [Lua] Image Editor
« Reply #74 on: January 01, 2012, 06:45:41 am »
What I will try to do is to make a similar dialog system. Right now I have to append all widgets to the dialog manually. As Adriweb suggested a couple of day's ago, I really should make (informative) dialog boxes as easy as yours :)

I didn't look yet at your code (I'm on my phone now), but I will do soon :)