0 Members and 1 Guest are viewing this topic.
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+.
I see, but how do we retrieve it? Is there a function in Lua that does that or do you access memory directly?
gui.addWindow("Title","dialogBox","This text shows multi-line text functions :\nLorem ipsum dolor sit amet",{{"Button 1"},{"Button 2"},{"Another button"}})
--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() endfunction 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