Dual Screen screen saver

Just starting out? Need help? Post your questions and find answers here.
Jon
User
User
Posts: 20
Joined: Sat Apr 26, 2003 9:12 am
Location: New Zealand
Contact:

Dual Screen screen saver

Post by Jon »

Ok here's a nice easy one (I Hope?)

I want to be able to load images from a specified directory in a random order (I have the random order bit sussed)

Also the pictures must be stretched to fit the screen if possible and......

I want the picture to load onto my main screen

I want to display some text/data/another picture on the other screen

(I hope this is making sense?)

Help! I have tried drinking a lot of beer tonight for inspiration but all I have is a full bladder and less braincells 8O
MadMax
Enthusiast
Enthusiast
Posts: 237
Joined: Mon Oct 06, 2003 11:56 am

Post by MadMax »

This kind of question, is difficult to reply to. Because you are practicaly asking for a full program. And we can't tell very well what you know and what you don't.

If you are new to programing, It's best to go little by little. Start by loading an image (for what you what to do, seems a better option than sprite) and display it, then try to fit it etc etc...

And go searching/asking in the forums as you run into trouble. Post some code, so we can see better what the problem is.

As for the dual screen, I have no idea, not lucky enough to have 2 monitors :(

Press F1 and have a look at 2DDrawing, Image, ImagePlugin, FileSystem, and don't forget to look at ClearScreen() and FlipBuffers() in Sprites.

Good luck, and wellcome to this wonderfull coding language.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

two screens and one screen are, from a certain point of view, the same thing, do a search on the board, i've posted some code for multiple monitors in the past, you must have overlooked it ;-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Jon
User
User
Posts: 20
Joined: Sat Apr 26, 2003 9:12 am
Location: New Zealand
Contact:

Post by Jon »

Cheers guys, I figured I was asking for too much :oops: heh, lazy I guess, any way I'll bugger off and potter around then post some code when I get stuck.

L8r
Jon
User
User
Posts: 20
Joined: Sat Apr 26, 2003 9:12 am
Location: New Zealand
Contact:

I think I'm stuck?

Post by Jon »

Ok I've got my pictures loading ok but I'm not sure if I'm doing the delay between pictures properl : Delay(3000)

Also the program dosn't always close nicely some times there's an error :

Error at line 28 : The specified output is null (0 value)
Line 28 -> If StartDrawing(ScreenOutput())

And why does the desktop wallpaper disappear after running this??

Code: Select all

PictureDirectory.s="D:\My Pictures\Wallpaper Cars\" 
UseEC_OLEImageDecoder() 
Dim Picture.s(1000) 

If ExamineDirectory(1,PictureDirectory,"*.*") 
  Repeat
    FileType = NextDirectoryEntry()
    If FileType=1
       Picture(Counter) = DirectoryEntryName()
       Counter+1
    EndIf
  Until FileType = 0 
EndIf

  If InitSprite()And InitKeyboard()And InitMouse()
    If OpenScreen(1280, 1024,32, "")
    
    Repeat
      ; Choose random picture and Load into memory -------------------------------------------------------------------------------------------------
      RandomPicture.s = PictureDirectory + Picture(Random(counter-1))
      ImageID  = LoadImage(0, RandomPicture)    
      ; Centre the picture -----------------------------------------------------------------------------------------------------------------------------------------
      PictureWidth  =ImageWidth() 
      PictureHeight =ImageHeight()
      ImageXPos=(1280/2)-(PictureWidth/2)
      ImageYPos=(1024/2)-(PictureHeight/2)
      ; Display the Picture ---------------------------------------------------------------------------------------------------------------------------------------- 
      If  StartDrawing(ScreenOutput())
        Box(0, 0, 1280, 1024,0) 
        If ImageID <>0
          DrawImage(ImageID, ImageXPos,ImageYPos)
        EndIf
        StopDrawing()
        FlipBuffers(1)
      EndIf
      ; Check for a Keypress/Mouse etc... --------------------------------------------------------------------------------------------------------------------
      Delay (3000)
      ExamineKeyboard()
      ExamineMouse()
    Until KeyboardPushed(#PB_Key_All) Or MouseDeltaX() <> 0 Or MouseDeltaY() <> 0 Or MouseWheel() <> 0 Or MouseButton(1) <> 0 Or MouseButton(2) <> 0 Or MouseButton(3) <> 0
  EndIf
EndIf

End

fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

Jon,

I made some adjutments in your code. The delay is good with 3 seconds. On my own, I would use maybe just a bit longer (4-5 seconds), but it depends on how much images you have to display : more, the delay is good, less enhance the delay to a higher time.

BTW, I changed the image drawing and the delay logic to make it as accurate as possible without to consume CPU (look the different lines of code).

Also I placed a linked list instead of an array, which makes the coding maybe more easy to understand. Also you have not to take care about the images amount you have in the directory you parse.

Now, if you want to add any drawings in your loop, just place some more lines of code in the main loop, inside a StartDrawing() / StopDrawing() pattern.

I finally placed screen's dimensions in variables, and added an image resize calculation to apply resizing with constaint proportions.

Just before to run this again, change directory and screen size to yours. Maybe you will add one thing, is to check the screen about its depth, because people having screens with lower depth than 32 will not run this program.

Code: Select all

NewList Picture.s()

  PictureDirectory.s = "C:\RECUP\images\Space others\"
  UseEC_OLEImageDecoder()

  If ExamineDirectory(1, PictureDirectory, "*.*")
    Repeat
      FileType = NextDirectoryEntry()
      If FileType = 1
         AddElement(Picture())
         Picture() = DirectoryEntryName()
         Counter + 1
      EndIf
    Until FileType = 0
  EndIf

  ScreenXSize = GetSystemMetrics_(#SM_CXSCREEN)
  ScreenYSize = GetSystemMetrics_(#SM_CYSCREEN)
  ScreenDepth = 32
  If InitSprite() And InitKeyboard() And InitMouse()
      If OpenScreen(ScreenXSize, ScreenYSize, ScreenDepth, "Random Images")
          Repeat
            FlipBuffers()
            ClearScreen(0, 0, 0)
            If StartDrawing(ScreenOutput())
                Box(0, 0, ScreenXSize, ScreenYSize,0)
                If ImageID <> 0
                    DrawImage(ImageID, ImageXPos, ImageYPos)
                EndIf
                StopDrawing()
            EndIf
            ; Check for a Keypress/Mouse etc... --------------------------------------------------------------------------------------------------------------------
            If ElapsedMilliseconds() - Delay => 3000
                Delay = ElapsedMilliseconds()
                ; Choose random picture and Load into memory -------------------------------------------------------------------------------------------------
                SelectElement(Picture(), Random(Counter - 1))
                RandomPicture.s = PictureDirectory + Picture()
                If ImageID
                    FreeImage(0)
                EndIf
                ImageID = LoadImage(0, RandomPicture)
                ; Centre the picture -----------------------------------------------------------------------------------------------------------------------------------------
                PictureWidth = ImageWidth()
                PictureHeight = ImageHeight()
                kx.f = PictureWidth / ScreenXSize
                ky.f = PictureHeight / ScreenYSize
                kx.f = ScreenXSize / PictureWidth
                ky.f = ScreenYSize / PictureHeight
                If kx < ky
                    PictureWidth = PictureWidth * kx
                    PictureHeight = PictureHeight * kx
                  Else
                    PictureWidth = PictureWidth * ky
                    PictureHeight = PictureHeight * ky
                EndIf
                ImageID = ResizeImage(0, PictureWidth, PictureHeight)
                ImageXPos = (ScreenXSize - PictureWidth) / 2
                ImageYPos = (ScreenYSize - PictureHeight) / 2
                ; Display the Picture ----------------------------------------------------------------------------------------------------------------------------------------
            EndIf
            ExamineKeyboard()
            ExamineMouse()
            If KeyboardPushed(#PB_Key_All)
                Quit = #TRUE
            EndIf
            If MouseDeltaX() <> 0 Or MouseDeltaY() <> 0 Or MouseWheel() <> 0 Or MouseButton(1) <> 0 Or MouseButton(2) <> 0
                Quit = #TRUE
            EndIf
            Delay(5)
          Until Quit
          CloseScreen()
      EndIf
  EndIf
End
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
Jon
User
User
Posts: 20
Joined: Sat Apr 26, 2003 9:12 am
Location: New Zealand
Contact:

Post by Jon »

fweil wrote:Jon,

I made some adjutments in your code. The delay is good with 3 seconds. On my own, I would use maybe just a bit longer (4-5 seconds), but it depends on how much images you have to display : more, the delay is good, less enhance the delay to a higher time.
Thank you for the code adjustment, much appreciated :). The delay was purely a number picked at random with over 900 car pics it seemed ok while I was playing around with it.
BTW, I changed the image drawing and the delay logic to make it as accurate as possible without to consume CPU (look the different lines of code).
Yes I've looked over the changes and made sense of them. -> :idea:
Also I placed a linked list instead of an array, which makes the coding maybe more easy to understand. Also you have not to take care about the images amount you have in the directory you parse.
Now that really is me being totally lazy :oops: no excuse for that really. Honestly I was going to just make the array bigger then recompile when I had too many pics.... (Oh how shameful is that)
Now, if you want to add any drawings in your loop, just place some more lines of code in the main loop, inside a StartDrawing() / StopDrawing() pattern.
Now, not sure If Ive got the right idea here, do you mean other 2d drawing operations? eg. text etc... or X2D_Text(x.l, y.l, text.s[, angle.l]) (which I am toatally sure is a dud command, must report as a bug?)

I finally placed screen's dimensions in variables, and added an image resize calculation to apply resizing with constaint proportions.
Now that resize is just groovy cheers !!
Maybe you will add one thing, is to check the screen about its depth, because people having screens with lower depth than 32 will not run this program.
well I was just going to make sure it worked on my pc really, but, I spose it's just good practice to have checks in there (I should change my name to lazy coder, heh heh]

1 Question, I had a quick search on the board but nothing really satisfied me, what I want to know is can I use RED BLUE GREEN or Gamma commands etc to do a simple fade in/out? Or is it just a little bit more complicated.
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

Jon,

You may use ChangeGamma() for fade in/out AFAIK, but I can't test it well on my PC. According to documentation, you would have to code first :

ChangeGamma(0, 0, 0, 1) just after OpenScreen

and

ChangeGamma(RedValue, GreenValue, BlueValue, 0)

just after the ClearScreen()

About adding 2D drawings, you may any kind of drawing, either text or points, etc,inside the StartDrawing() / StopDrawing() part.

KRgrds
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
Jon
User
User
Posts: 20
Joined: Sat Apr 26, 2003 9:12 am
Location: New Zealand
Contact:

Post by Jon »

fweil,

Thank's for the pointers on Change gamma, will try it out now.

L8r.
Jon
User
User
Posts: 20
Joined: Sat Apr 26, 2003 9:12 am
Location: New Zealand
Contact:

Post by Jon »

Righto, I've managed to get my pics to fade in then out, I just included a small bit of the code (See earlier post)

Code: Select all

If OpenScreen(ScreenXSize, ScreenYSize, ScreenDepth, "Random Images") 

      ChangeGamma(0, 0, 0, 1)

      Repeat 
       
        For FadeOut=255 To 0 Step -5
          ChangeGamma( FadeOut, FadeOut, FadeOut,0)
        Next     

        FlipBuffers() 
        ClearScreen(0, 0, 0)

        For FadeIn=0 To 255 Step 5
          ChangeGamma(FadeIn,FadeIn,FadeIn,0)
        Next 
Is this the best way to acheive a fadein/out? It's stuffing up the mouse/kboard detection to stop the screen saver?
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

This way to fade in/out is well if you are fading the whole screen.

For fading sprites an appropriate set of commands exists.

You may use both keyboard / mouse events for stopping the screen saver.

I guess it is also possible to eventually hide a screen saver if some CPU is consumed by other processes, but it is more difficult to code. Also when a screen saver runs, it often consume much CPU itself ...
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
Post Reply