Code Sample |
ww=360 --window width wh=420 --window height presses = 0 -- used for the repeat button function button_press(self) if self == butts[10] or self == butts[11] or self == butts[12] then if self:value() == 1 then status="activated" else status="deactivated" end out:value("\""..self:label().."\" was "..status) presses = 0 elseif self == butts[9] then presses = presses+1 out:value("\""..self:label().."\" was pressed "..presses.." times") else out:value("\""..self:label().."\" was pressed") presses = 0 end end w=fltk:Fl_Window(ww,wh,"murgaLua Button Demo") butts={} ---------- ---- Here are two methods of laying out an array of similar widgets -- Method 1 --butts[1]=fltk:Fl_Button(10,10,ww-20,25,"Fl_Button default") --butts[2]=fltk:Fl_Button(10,40,ww-20,25,"Fl_Button down") --butts[3]=fltk:Fl_Button(10,70,ww-20,25,"Fl_Button thin") --butts[4]=fltk:Fl_Button(10,100,ww-20,25,"Fl_Button thin down") --butts[5]=fltk:Fl_Button(10,130,ww-20,25,"Fl_Button engraved") --butts[6]=fltk:Fl_Button(10,160,ww-20,25,"Fl_Button embossed") --butts[7]=fltk:Fl_Button(10,190,ww-20,25,"Fl_Button border") -- Method 2 labels={"default","down","thin","thin down","engraved","embossed","border"} for i = 1,7 do butts[i]=fltk:Fl_Button(10,30*i-20,ww-20,25,"Fl_Button "..labels[i]) end ---------- butts[2]:box(fltk.FL_DOWN_BOX) butts[3]:box(fltk.FL_THIN_UP_BOX) butts[4]:box(fltk.FL_THIN_DOWN_BOX) butts[5]:box(fltk.FL_ENGRAVED_BOX) butts[6]:box(fltk.FL_EMBOSSED_BOX) butts[7]:box(fltk.FL_BORDER_BOX) butts[8]=fltk:Fl_Return_Button(10,220,ww-20,25,"Fl_Return_Button") butts[9]=fltk:Fl_Repeat_Button(10,250,ww-20,25,"Fl_Repeat_Button") butts[10]=fltk:Fl_Light_Button(10,280,ww-20,25,"Fl_Light_Button") butts[11]=fltk:Fl_Round_Button(10,310,ww-20,25,"Fl_Round_Button") butts[12]=fltk:Fl_Check_Button(10,340,ww-20,25,"Fl_Check_Button") for i = 1,12 do butts[i]:callback(button_press) end out=fltk:Fl_Output(10,370,ww-20,25) w:show() Fl:run() |
Code Sample |
ww=180 --window width wh=200 --window height w=fltk:Fl_Window(ww,wh,"murgaLua Clock Demo") clock=fltk:Fl_Clock(5,5,ww-10,ww-10,"a clock") clock:box(fltk.FL_DOWN_BOX) w:show() Fl:run() |
Code Sample |
ww=350 --window width wh=400 --window height function thing_cb() xpos=string.format("%.2f",thing:xvalue()*100) ypos=string.format("%.2f",thing:yvalue()*100) out:value("X: "..xpos.." Y: "..ypos) --out:value("X: "..thing:xvalue().." Y: "..thing:yvalue()) end w=fltk:Fl_Window(ww,wh,"murgaLua Positioner Demo") frame=fltk:Fl_Box(2,2,ww-4,ww-4); frame:box(fltk.FL_UP_BOX) thing=fltk:Fl_Positioner(5,5,ww-10,ww-10,"percentage of window size"); thing:box(fltk.FL_DOWN_BOX) thing:callback(thing_cb) out=fltk:Fl_Output(5,wh-30,ww-10,25) w:show() Fl:run() |
Code Sample |
ww=350 --window width wh=100 --window height w=fltk:Fl_Window(ww,wh,"murgaLua Progress Demo") thing=fltk:Fl_Progress(10,10,ww-20,30,"0 %"); thing:box(fltk.FL_DOWN_BOX) thing:selection_color(fltk.FL_BLACK) function go_cb() if thing:value() == 100 then thing:selection_color(fltk.FL_BLACK) thing:value(0) else if thing:value() >= 75 then thing:selection_color(fltk.FL_RED) end thing:value(thing:value()+1) end thing:label(thing:value().." %") end go=fltk:Fl_Repeat_Button(10,50,ww-20,30,"hold me down"); go:callback(go_cb) w:show() Fl:run() |
Code Sample |
ww=400 --window width wh=350 --window height dir=os.getenv("HOME").."/.xtdesktop/" -- ending slash is vital images = murgaLua.readDirectory(dir) fltk.fl_register_images() function get_image_data(self) for i=0,table.getn(images) do if self:tooltip() == dir..images[i] then -- find the right image display:image(icon[i]:copy(128,128)) --show it bigger! display_label:label(images[i].."\n"..icon[i]:w().."x"..icon[i]:h()) -- show height and width display:redraw() break end end end w=fltk:Fl_Window(ww,wh,"murgaLua Gif/Png Icon Demo") display=fltk:Fl_Box(120,30,256,256) -- big image display_label=fltk:Fl_Box(120,290,256,40) display_label:label("nothing") display:box(fltk.FL_THIN_DOWN_BOX) scroll=fltk:Fl_Scroll(5,5,90,330) pack=fltk:Fl_Pack(5,5,68,300) pack:spacing(2) icon={}; butt={} row=1;col=1 -- since the images table contains more than just images (*.lnk gets in too) -- i'm building the icons from specific items in the table. for i=0,table.getn(images) do if string.find (images[i],".png",-4,plain) or string.find (images[i],".gif",-4,plain) then icon[i]=Fl_Shared_Image.get(dir..images[i]) butt[i]=fltk:Fl_Button(0,0,64,64) butt[i]:align(fltk.FL_ALIGN_CLIP) butt[i]:image(icon[i]) butt[i]:tooltip(dir..images[i]) butt[i]:callback(get_image_data) end end w:show() Fl:run() |