News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
(very) basic slideshow
Author Message
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #1
RE: (very) basic slideshow

Update using the new murgaLua.createFltkTimer() in murgaLua 0.5. It's much nicer now =o)
Also added a file list, but it hasn't been thoroughly tested.

Code:
#!/usr/bin/murgaLua
-- simple image viewer
-- mikshaw 2007
-- inspired by the work of john murga
-- requires murgaLua version 0.5 or greater

--dir=os.getenv("HOME").."/image/"
dir="./"
pause=5 --seconds
ss=0 -- screensaver 1=on 0=off
fs=0 -- fullscreen

-- Check for commandline arguments
for i=1,table.getn(arg) do
if arg[i] == "-s" then ss=1 end --activate slideshow
if arg[i] == "-f" then fs=1 end --force fullscreen ("f" to toggle)
if arg[i] == "-l" then ls=1 end --show file list {"l" to toggle)
if arg[i] == "-d" and murgaLua.isDirectory(arg[i+1]) then dir=arg[i+1] end --specify a directory
end

fltk.fl_register_images()
allfiles = murgaLua.readDirectory(dir)
table.sort(allfiles)
images = {}
for i=1,table.getn(allfiles) do
if string.find(allfiles[i],"%.jpg$") or string.find(allfiles[i],"%.png$") or string.find(allfiles[i],"%.gif$") then table.insert(images,allfiles[i]) end
end
Fl:visible_focus(0)
ww=Fl:w();wh=Fl:h()
imgnum=0
fwd=1

timer=murgaLua.createFltkTimer()

function exit() print("goodbye"); os.exit(0) end

function toggle_fullscreen()
if fs==1 then
w:fullscreen_off(ww/2-active_image:w()/2,wh/2-active_image:h()/2,active_image:w(),active_image:h())
fs=0
else w:fullscreen(); fs=1
end
button:size(w:w(),w:h())
display:size(w:w(),w:h())
end

function zoomin()
zoom_image=active_image:copy(ww,wh)
display:image(zoom_image)
w:resize(0,0,ww,wh)
display:size(ww,wh)
display:redraw()
end
function zoomout()
display:image(active_image)
if fs==0 then fs=1; toggle_fullscreen() end
display:redraw()
end

function toggle_list()
if ls==1 then ls=0; fw:hide() else ls=1; fw:show() end
end

function show_image()
active_image=Fl_Shared_Image.get(dir.."/"..images[imgnum])
if active_image then
if fs==0 then fs=1; toggle_fullscreen() end --reusing toggle_fullscreen to resize window to image size
display:image(active_image)
else next_image()
end
list:value(imgnum)
display:redraw()
end

function next_image()
if fwd == 0 then
if imgnum <= 1 then imgnum=table.getn(images) else imgnum = imgnum-1 end
else
if imgnum >= table.getn(images) then imgnum=1 else imgnum = imgnum+1 end
end
show_image()
if ss==1 then timer:doWait(pause) end
button:take_focus()
end

function button_cb()
if Fl:event_button() == fltk.FL_RIGHT_MOUSE or Fl:event_key() == fltk.FL_Page_Up then fwd=0 else fwd=1 end
if Fl:event_button() == fltk.FL_MIDDLE_MOUSE then
toggle_fullscreen()
else    next_image()
end
end

w=fltk:Fl_Double_Window(ww,wh,"MurgaLua Image Viewer")
buttons={}
for i=1,5 do buttons[i]=fltk:Fl_Button(0,0,0,0) end
button=fltk:Fl_Button(0,0,ww,wh)
button:box(1);button:color(fltk.FL_BLACK);button:selection_color(fltk.FL_BLACK)
display=fltk:Fl_Box(0,0,ww,wh)
--w:resizable(display)
display:box(1);display:color(fltk.FL_BLACK)
if ss==1 then
button:callback(exit)
timer:callback(next_image)
else button:callback(button_cb); buttons[1]:callback(button_cb)
button:shortcut(fltk.FL_Page_Down)
buttons[1]:shortcut(fltk.FL_Page_Up)
buttons[2]:shortcut(fltk.FL_Up); buttons[2]:callback(zoomin)
buttons[3]:shortcut(fltk.FL_Down); buttons[3]:callback(zoomout)
buttons[4]:label("&fullscreen"); buttons[4]:callback(toggle_fullscreen)
buttons[5]:label("&list"); buttons[5]:callback(toggle_list)
end
fltk.Fl_End()


fw=fltk:Fl_Window(0,0,ww/3,wh/2)
list=fltk:Fl_Hold_Browser(2,2,ww/3-4,wh/2-4) -- file list
fltk.Fl_End()
function choose_image()
imgnum=list:value()
show_image()
end
list:callback(choose_image)
for i=1,table.getn(images) do list:add(images[i]) end

w:show()
if ls==1 then fw:show() end
next_image()

Fl:run()

07-03-2007 04:57 AM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Messages In This Thread
(very) basic slideshow - mikshaw - 06-24-2007, 08:55 AM
RE: (very) basic slideshow - mikshaw - 06-24-2007, 12:53 PM
RE: (very) basic slideshow - mikshaw - 06-25-2007, 05:02 AM
RE: (very) basic slideshow - iGame3D - 06-25-2007, 08:13 AM
RE: (very) basic slideshow - mikshaw - 06-25-2007, 11:17 AM
RE: (very) basic slideshow - mikshaw - 07-03-2007 04:57 AM
RE: (very) basic slideshow - iGame3D - 07-03-2007, 09:28 AM
RE: (very) basic slideshow - mikshaw - 07-03-2007, 12:56 PM
RE: (very) basic slideshow - mikshaw - 07-06-2007, 06:29 AM
RE: (very) basic slideshow - mikshaw - 07-16-2007, 12:06 PM

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: