version 6.01 0 frmMain 1 0 0 0 7 3 0 0 3 0 0 0 0 0 0 0 0 9 1 0 238 268 E:\privat\pda\B4ppc\icons\Photo.ico 2 dzImageDesktop.dll FormLib.dll 2 dzImage.dll FormLib.dll 2 flb:FormLib imageclass:ImageClass Sub designer addform(frmMain,"Photo","",0,0,0)@ addlabel(frmmain,lblWait,60,115,135,25,"Loading...",0,0,0,255,255,255,True,True,16)@ addlabel(frmmain,lblInfo,0,50,240,20,"",0,0,0,255,255,255,True,True,8)@ addimagebutton(frmmain,imgbtnHelp,0,0,48,48,"",0,0,0,0,0,0,"cCenterImage","help.gif",True,True,True,9)@ addimagebutton(frmmain,imgbtnQuit,192,0,48,48,"",0,0,0,0,0,0,"cCenterImage","quit.gif",True,True,True,9)@ addimagelist(frmmain,photolist,75,205,80,25)@ End Sub @EndOfDesignText@' PHOTO VIEWER ' Small program to display photos. ' Program scans directories for jpg-photos given in settings file "directories.txt". ' Control by sliding finger across the screen (left, right, up, down). ' ' Currently runs only on Windows Mobile PDA with 320 x 240 resolution. ' Requires .Net (should be Standard with Windows Mobile 5 and 6). ' ' Requires Basic4ppc to compile source code. ' Frank Dux, 2008 ' www.frankdux.de Sub Globals 'Declare the global variables here. Dim Type(Width, Height) ImgSize Dim currentimagecounter ' pointer in list of file names of currently displayed photo Dim totalnumberofphotos ' as of list of filenames Dim directoryfile ' file contains directories to be searched for photos AddArrayList ("list_of_directories") ' dynamical array to (temporary) hold list of list_of_directories to search for photos Dim touchdown_x ' x-point where finger pressed screen Dim touchdown_y 'y-point where finger pressed screen Dim touchup_x ' x-point where finger left screen Dim touchup_y ' x-point where finger left screen Dim x_center, y_center ' center points (x and y) of screen Dim x_delta, y_delta ' minimum distance (in x, y direction) that finger must move on the screen to fire forward/backward event Dim zoomspeed ' speed of zooming down the picture when changing Dim numberofchars ' Number of characters of filename (incl path) that are shown in info label Dim showchars ' temp var to determine number of chars to show Dim mousedown_in_progress ' Boolean flag which is set when mousedown was detected, and is checked in mouse_up - to avoid multiple mouse_up-handling End Sub Sub App_Start directoryfile = AppPath & "\directories.txt" ' set some graphic stuff zoomspeed = -50 ' determines speed of image change; images are zoomed down from 100 to 0 in these steps. Currently not used, as it is too slow anyway x_center = 120 x_delta = 30 y_center = 120 y_delta = 30 numberofchars = 30 mousedown_in_progress = False ' reset some values for first use touchdown_x = x_center ' reset touchdown_y = y_center ' reset currentimagecounter = 0 'prepare fullscreen mode flb.New1("frmMain",B4PObject(1)) flb.FullScreen (CPPC) 'On the device it will remove the title bar too 'prepare for photodisplay AddArrayList ("photolist_filenames") ' this array list will contain the list of all photo filenames read_directories ' call sub which reads all directories as set in file totalnumberofphotos = photolist_filenames.Count ' to know how many photos we have 'photolist is a list of images (!), Not filenames, that contains always only 1 image - the one that is displayed on the screen. ' It would be easier to load all images into this list, but too memory intensive photolist.Add(photolist_filenames.item(0)) ' Add first image of list to imagelist ' Create an ImageClass item to allow manipulations of the photo ImageClass.New1 ImageClass.Image = photolist.item(0) 'load the current photo ImgSize() = ImageClass.ImageSize(ImageClass.Image) ' determine size ratio = ImgSize.Width / ImgSize.Height ' determine ration to find out if this is portrait or landscape If ratio > 1 Then frmMain.Image = ImageClass.RotateImage(ImageClass.Image,270) ' rotate if landscape, then show Else frmMain.Image = ImageClass.Image ' show image End If currentfilename = photolist_filenames.item(currentimagecounter) ' get the filename of the current photo showchars = Min(StrLength(AppPath)+5,numberofchars) ' determine number of characters to be shown; must not be larger that complete pathname of smallest possible name (e.g.: "a.jpg") lblInfo.Text = (currentimagecounter+1) & "/" & totalnumberofphotos & " (..." & SubString(currentfilename,StrLength(currentfilename)-showchars,showchars) & ")" ' fill info label ' hide buttons - should not be displayed in full screen mode, only when menu items are selected (move finger down on screen) imgbtnQuit.visible = false imgbtnHelp.visible = false lblInfo.visible = false lblWait.visible = false frmMain.Show End Sub Sub frmMain_MouseDown (x,y) touchdown_x = x ' remember point where finger touched screen touchdown_y = y mousedown_in_progress = true End Sub Sub frmMain_Mouseup (x,y) touchup_x = x ' remember point where finger left screen touchup_y = y ' now check if user stroked right or left or up or down. Compare touchdown-values with touchup-values If ((touchdown_x > x_center) AND (touchup_x < touchdown_x) AND ((touchdown_x - touchup_x) > x_delta) AND (mousedown_in_progress = true) ) Then ' stroked right mousedown_in_progress = false lblWait.visible = true ' show wait-label lblWait.refresh ' and make sure it's displayed touchdown_x = x_center ' reset the touchdown-value to be sure we start over again next time If (currentimagecounter < (totalnumberofphotos-1)) Then ' is there still a photo to the right? currentimagecounter = currentimagecounter+1 ' count up if not yet at end of array ' For zoomfactor = 100 To 1 Step zoomspeed ' frmMain.Image = ImageClass.ZoomImage(frmMain.Image,zoomfactor) ' Next photolist.Clear ' clear current list of photos (contains only 1 anyway) to save memory photolist.Add(photolist_filenames.item(currentimagecounter)) ' now add the photo to image list defined by filename of current counter ImageClass.Image = photolist.item(0) ' now we have the photo (not only its filename) in photolist. Assign it to ImageClass to work with it ImgSize() = ImageClass.ImageSize(ImageClass.Image) ' get ratio, same as above ratio = ImgSize.Width / ImgSize.Height If ratio > 1 Then frmMain.Image = ImageClass.RotateImage(ImageClass.Image,270) ' rotate if landscape, then display Else frmMain.Image = ImageClass.Image ' show image End If currentfilename = photolist_filenames.item(currentimagecounter) ' get the filename lblInfo.Text = (currentimagecounter+1) & "/" & totalnumberofphotos & " (..." & SubString(currentfilename,StrLength(currentfilename)-showchars,showchars) & ")" ' ... and assign it to the label End If lblWait.visible = false ' hide wait-label End If ' stroked right If ((touchdown_x < x_center) AND (touchup_x > touchdown_x) AND ((touchup_x - touchdown_x) > x_delta) AND (mousedown_in_progress = true)) Then ' stroked left mousedown_in_progress = false lblWait.visible = true lblWait.refresh touchdown_x = x_center ' reset If (currentimagecounter > 0) Then currentimagecounter = currentimagecounter-1 ' count down if not yet at beginning of array ' For zoomfactor = 100 To 1 Step zoomspeed ' frmMain.Image = ImageClass.ZoomImage(frmMain.Image,zoomfactor) ' Next photolist.Clear ' clear current list of photos (contains only 1 anyway) to save memory photolist.Add(photolist_filenames.item(currentimagecounter)) ' now add the photo to image list defined by filename of current counter ImageClass.Image = photolist.item(0) ImgSize() = ImageClass.ImageSize(ImageClass.Image) ratio = ImgSize.Width / ImgSize.Height If ratio > 1 Then frmMain.Image = ImageClass.RotateImage(ImageClass.Image,270) ' rotate if landscape Else frmMain.Image = ImageClass.Image ' show image End If currentfilename = photolist_filenames.item(currentimagecounter) lblInfo.Text = (currentimagecounter+1) & "/" & totalnumberofphotos & " (..." & SubString(currentfilename,StrLength(currentfilename)-showchars,showchars) & ")" End If lblWait.visible = false End If ' stroked right If ((touchdown_y < y_center) AND (touchup_y > touchdown_y) AND ((touchup_y - touchdown_y) > y_delta) AND (mousedown_in_progress = true)) Then ' stroked down mousedown_in_progress = false touchdown_y = y_center ' reset imgbtnQuit.visible = true ' show the buttons imgbtnHelp.visible = true lblInfo.visible = true End If ' stroked down If ((touchdown_y > y_center) AND (touchup_y < touchdown_y) AND ((touchdown_y - touchup_y) > y_delta) AND (mousedown_in_progress = true)) Then ' stroked up mousedown_in_progress = false touchdown_y = y_center ' reset imgbtnQuit.visible = false ' hide the buttons imgbtnHelp.visible = false lblInfo.visible = false ImageClass.Image = photolist.item(0) ' show the normal photo again; might have changed to instructions if user pressed help ImgSize() = ImageClass.ImageSize(ImageClass.Image) ratio = ImgSize.Width / ImgSize.Height If ratio > 1 Then frmMain.Image = ImageClass.RotateImage(ImageClass.Image,270) ' rotate if landscape, then display Else frmMain.Image = ImageClass.Image ' show image End If End If ' stroked up End Sub Sub imgbtnQuit_Click frmMain.Close ' quit End Sub Sub imgbtnHelp_Click lblInfo.visible = false ' hide info-label, not needed here frmMain.Image = AppPath & "\black.jpg" ' show instructions (as just another image) End Sub Sub read_directories ErrorLabel(errread) ' File contains directories to search for photos ' Each line is a directory entry FileOpen (c1,directoryfile,cRead ,, cASCII) r = FileRead (c1) Do Until r = EOF list_of_directories.add(r) ' add each line to array list r = FileRead (c1) Loop FileClose (c1) i = 0 ' use as index For i = 0 To list_of_directories.count-1 Step 1 ' loop through directory list r=list_of_directories.item(i) FileSearch(photolist_filenames, r,"*.jpg") ' fill the list Next ' for list_of_directories.clear ' clear list to save memory Return'If there were no "Return" here, the error message would have shown. errread: Msgbox("Error when trying to read list of directories. Make sure the file 'directories.txt' exists on your device (in the directory where this program was installed to) and holds directory names.","",cMsgboxOK,cMsgboxHand) End Sub