An easy playlist to show pictures

Find quick help here to get you started with Hollywood
Post Reply
User avatar
Juan Carlos
Posts: 410
Joined: Mon Sep 06, 2010 1:02 pm
Location: Palencia
Contact:

An easy playlist to show pictures

Post by Juan Carlos » Fri Dec 11, 2015 2:54 pm

I'm working in an easy playlist for example to show pictures with right and left arrow keys, the example load a picture with L key open the folder to load the picture and show it but I found several problems like files aren't pictures and others, I go for the correct way or I loss my timem this example cans useful for other playlist, music, etc.

Code: Select all

@DISPLAY {Title="Pre PlayList", Width=800, Height=600}
Local ficheros$={}
Local directorios$={}

Local NumeroFiles, NumeroFotos=0
Local Num=0
Local SaltoY=100
Local MueveFoto=0
Local Imagen=0

/****** FUNCIÓN LECTURA DEL PULSADO DE TECLAS *****/
Function p_EventFunc(msg)
  Switch(msg.action)
    Case "OnKeyDown":		

	     /* Loading Picture with L key */
	     If msg.key = "L" Or msg.key = "l"
		p_Carga()
	     EndIf

	     /* Previous picture with Right key */	
	     If msg.key = "LEFT"
		If Imagen=1
		   MueveFoto=MueveFoto-1
		   If MueveFoto<0 ;to avoid show the picture -1, it no is true.
			MueveFoto=0
			Return()
		   Else		   
			
			FileMuestra$=LaRuta$..ficheros$[MueveFoto]
			Cls()

			ret=IsPicture(FileMuestra$) ;checking file loaded is a picture.
			If ret=True
			   LoadBrush(70, FileMuestra$)
			   ScaleBrush(70, 800, 600, Smooth=True)
			   DisplayBrush(70, #CENTER, #CENTER)
			
			   TextOut(10, 130, FileMuestra$, {Color=#RED})
			   TextOut(10, 150, "Number picture: "..MueveFoto, {Color=#RED})
			Else
			   TextOut(10, 150, "Number picture: "..MueveFoto, {Color=#RED})
			
			   ;Remove from array the item no picture.
			   RemoveItem(ficheros$, MueveFoto)
			   NumeroFotos=ListItems(ficheros$)	
   	
			EndIf
		   EndIf		
		EndIf
	     EndIf
	
	     /* Next picture with Right key */
	     If msg.key = "RIGHT"
		If Imagen=1
		   MueveFoto=MueveFoto+1
		   If MueveFoto=>NumeroFotos ;to avoid show the picture more that no be.
		      MueveFoto=NumeroFotos
		      Return()
		   Else
			
			FileMuestra$=LaRuta$..ficheros$[MueveFoto]
			Cls()

			ret=IsPicture(FileMuestra$) ;checking file loaded is a picture.
			If ret=True
			   LoadBrush(70, FileMuestra$)		   
			   ScaleBrush(70, 800, 600, Smooth=True)   
			   DisplayBrush(70, #CENTER, #CENTER)
			
			   TextOut(10, 130, FileMuestra$, {Color=#RED})
			   TextOut(10, 150, "Number picture: "..MueveFoto, {Color=#RED})
			Else
			   TextOut(10, 150, "Number picture: "..MueveFoto, {Color=#RED})
			
			   ;Remove from array the item no picture.
			   RemoveItem(ficheros$, MueveFoto)
			   NumeroFotos=ListItems(ficheros$)		
		
			EndIf
		   EndIf   
		
		EndIf
	     EndIf

  EndSwitch
EndFunction

/**** FUNCIÓN CARGA DE LAS IMAGENES ****/
Function p_Carga()
  Local Imagen$=FileRequest("Load file", "jpg|jp2|png|lbm|bmp|svg|tif")
  If Imagen$=""
     SystemRequest("Loading error", "File not loaded", "OK", #REQICON_ERROR)
     Return()
  Else
     NumeroFiles=0 ; Puesta a 0.
     MueveFoto=-1 ;to begin with first picture.
     ficheros$={} ;Clear the array.

     LoadBrush(70, Imagen$)

     ret=IsPicture(Imagen$) ;checking file loaded is a picture.
     If ret=True
	ScaleBrush(70, 800, 600, Smooth=True)
	DisplayBrush(70, #CENTER, #CENTER)
	
	Imagen=1 ;Picture loaded.

	LaRuta$=PathPart(Imagen$) ;get path for the picture.
	Grafico$=FilePart(Imagen$) ;get the name form picture.
	FileCopy$=LaRuta$..Grafico$

	ReadDirectory(LaRuta$, ficheros$, directorios$)
	NumeroFiles=ListItems(ficheros$) ;get the number of items inside the folder.
	NumeroFotos=NumeroFiles-1 ;Deleting from array the name of folder, it is a extra item.

	TextOut(10, 130, "Number picures in drawer: "..NumeroFotos, {Color=#RED})
	TextOut(10, 150, Grafico$, {Color=#RED})
     EndIf
  EndIf
EndFunction

InstallEventHandler({OnKeyDown = p_EventFunc})

EscapeQuit(True)
Repeat
   WaitEvent
Forever

Post Reply