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

Messed around with it some more. I still haven't gotten a good delay going on; in fact the current one seems to be more annoying than the previous, but I'm taking a break from it for a while.

It's now an image viewer with a slideshow feature. Slideshow is enabled with the -d option, or by setting ss=1. A directory can be specified with -d <directory>, or by setting the dir variable. Fullscreen can be toggled with the f key, or set to default by setting fs=1.

In non-slideshow mode, left mouse or page down moves to the next image, right mouse or page up moves backward. Up and Down arrows toggle a "resize image to screen size" feature, which currently stretches the image if it doesn't have the same aspect ratio as your screen.

There are a pile of commented lines that I haven't yet removed...they are my tests while trying to improve the script.

I have no idea if this will work as-is in Windows or Mac, and it can get kinda resource-hungry...it needs to be seriously tweaked.

Code:
dir=os.getenv("HOME").."/image/"
--dir="/home/dsl/image/"
timer=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
if arg[i] == "-d" and murgaLua.isDirectory(arg[i+1]) then dir=arg[i+1] end --specify a directory
end

fltk.fl_register_images()
images = murgaLua.readDirectory(dir)
table.sort(images)
Fl:visible_focus(0)
ww=Fl:w();wh=Fl:h()
imgnum=1
pause=0
fwd=1

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 wait() -- this needs serious work
        fin=os.time()
        socket.sleep(1)
        if Fl:event() == fltk.FL_PUSH then exit() end
        Fl:check()
        if os.difftime (fin, start) < pause then wait() end
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
--if active_image then active_image:uncache() end
active_image=Fl_Shared_Image.get(dir.."/"..images[imgnum])
if active_image then
if fs==0 then fs=1; toggle_fullscreen() end
display:image(active_image)
--if ss==1 then socket.sleep(pause) end
else next_image()
end
display:redraw()
button:take_focus()
pause=timer
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()
--else w:redraw()
end
end

w=fltk:Fl_Double_Window(ww,wh,"MurgaLua Slideshow")
buttons={}
for i=1,4 do
        buttons[i]=fltk:Fl_Button(0,0,0,0)
--      buttons[i]:callback(button_cb)
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)
w:callback(next_image)
else button:callback(button_cb); buttons[1]:callback(button_cb)
--button:when(fltk.FL_WHEN_NOT_CHANGED)
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[4]:shortcut(fltk.FL_Tab)
end

w:show()
--w:fullscreen()

if ss==1 then
-- run slideshow
while 1 do
--Fl:check()
w:do_callback()
start=os.time(); wait()
end
else
next_image()
end
Fl:run()

06-25-2007 05:02 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: