Jump to content

A sort of image selector


Recommended Posts

Inspired by a video found on the web, i'd like to make a simple image selector, in this way:

This is the starting image:

f9i3o7.jpg

So you can see only 5 of X images, at the center the image is more bigger. Now if you click on the RIGHT ARROW this is the result:

2ikpopt.jpg

So now the 2 is at the center, the second image is 3 etc.

I have try to make an attempt but i have some problem, i don't know how to create the GUICtrlCreatePic stored in an array based on the number/names of images (obv the images has different names, not 1-2-3 ) and move it left-right, maybe with some nice fade effect if possible

On attachment the image and my starting au3 script, thanks for any type of help :D

TEST_Select image.zip

Edited by MyEarth
Link to comment
Share on other sites

Hi MyEarth,

this way can do?.....

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#include <array.au3> ; array managements

local $Box[5] ; contains GUI controls
local $Pic[5] ; contains pictures
Local $Ndx[5] ; contains pointers

for $i = 0 to 4 ; Fill up pointers
    $Ndx[$i] = $i
Next

; load image names
$Pic[0] = "IMG1.JPG"
$Pic[1] = "IMG2.JPG"
$Pic[2] = "IMG3.JPG"
$Pic[3] = "IMG4.JPG"
$Pic[4] = "IMG5.JPG"

$hGUI = GUICreate("TEST_Select image", 670, 301, -1, -1)
$Box[0] = GUICtrlCreatePic($Pic[0], 237, 66, 196, 220)
$Box[1] = GUICtrlCreatePic($Pic[1], 456, 184, 100, 100)
$Box[2] = GUICtrlCreatePic($Pic[2], 564, 185, 100, 100)
$Box[3] = GUICtrlCreatePic($Pic[3], 6, 185, 100, 100)
$Box[4] = GUICtrlCreatePic($Pic[4], 117, 185, 100, 100)
$Dummy_Left = GUICtrlCreateDummy()
$Dummy_Right = GUICtrlCreateDummy()
Local $AccelKeys[2][2] = [["{LEFT}", $Dummy_Left],["{RIGHT}", $Dummy_Right]]
GUISetAccelerators($AccelKeys)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Dummy_Right

            $Pulled = $Ndx[UBound($Ndx)-1] ; take last element
            _ArrayPush($Ndx,$Pulled,1) ; rotate indexes right
            for $i = 0 To UBound($Ndx)-1
                GUICtrlSetImage($Box[$i],$Pic[$Ndx[$i]])
            Next
            ;GUICtrlSetImage($Pic1, "IMG2.JPG")
            ;GUICtrlSetImage($Pic2, "IMG3.JPG")
            ;GUICtrlSetImage($Pic3, "IMG4.JPG")
            ;GUICtrlSetImage($Pic4, "IMG5.JPG")
            ;GUICtrlSetImage($Pic5, "IMG1.JPG")
        Case $Dummy_Left
            $Pulled = $Ndx[0] ; take first element
            _ArrayPush($Ndx,$Pulled,0) ; rotate indexes left
            for $i = 0 To UBound($Ndx)-1
                GUICtrlSetImage($Box[$i],$Pic[$Ndx[$i]])
            Next
            ;GUICtrlSetImage($Pic1, "IMG5.JPG")
            ;GUICtrlSetImage($Pic2, "IMG1.JPG")
            ;GUICtrlSetImage($Pic3, "IMG2.JPG")
            ;GUICtrlSetImage($Pic4, "IMG3.JPG")
            ;GUICtrlSetImage($Pic5, "IMG4.JPG")
    EndSwitch
WEnd

bye

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

I'm sorry, better reading your post I see that you need to rotate many images in a few (5) boxes, well, I put a new listing that can be easily adapted to the number of images and Gui boxes you want, by changing the values ​​of the initial variables.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#include <array.au3> ; array managements

local $MaxPictures = 5 ; number of pictures to slide
local $GuiControls = 5 ; number of Gui boxes
local $Box[$GuiControls] ; contains GUI controls
local $Pic[$MaxPictures] ; contains pictures
Local $Ndx[$MaxPictures] ; contains pointers

for $i = 0 to $MaxPictures-1 ; Fill up pointers
    $Ndx[$i] = $i
Next

; load image names
$Pic[0] = "IMG1.JPG"
$Pic[1] = "IMG2.JPG"
$Pic[2] = "IMG3.JPG"
$Pic[3] = "IMG4.JPG"
$Pic[4] = "IMG5.JPG"
; $Pic[x] = "ImageX.jpg" ; up to $MaxPictures -1

$hGUI = GUICreate("TEST_Select image", 670, 301, -1, -1)
$Box[0] = GUICtrlCreatePic($Pic[0], 237, 66, 196, 220)
$Box[1] = GUICtrlCreatePic($Pic[1], 456, 184, 100, 100)
$Box[2] = GUICtrlCreatePic($Pic[2], 564, 185, 100, 100)
$Box[3] = GUICtrlCreatePic($Pic[3], 6, 185, 100, 100)
$Box[4] = GUICtrlCreatePic($Pic[4], 117, 185, 100, 100)
$Dummy_Left = GUICtrlCreateDummy()
$Dummy_Right = GUICtrlCreateDummy()
Local $AccelKeys[2][2] = [["{LEFT}", $Dummy_Left],["{RIGHT}", $Dummy_Right]]
GUISetAccelerators($AccelKeys)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Dummy_Right
            $Pulled = $Ndx[UBound($Ndx)-1] ; take the last element, it will become the first
            _ArrayPush($Ndx,$Pulled,1) ; rotate indexes right

        Case $Dummy_Left
            $Pulled = $Ndx[0] ; take the first element, it will become the last
            _ArrayPush($Ndx,$Pulled,0) ; rotate indexes left

    EndSwitch

    ; now fill up the gui boxes with the firs X elements
    for $i = 0 To $GuiControls -1
        GUICtrlSetImage($Box[$i],$Pic[$Ndx[$i]])
    Next

WEnd

bye

Edited by Pincopanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Hi

I like it ( you have inverted the arrow :D ) but i have a problem to do this directly with arrays:

#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <File.au3>

$IMG = _FileListToArray(@ScriptDir, "*.jpg", 1)
If @error Then Exit

Local $MaxPictures = $IMG[0] ; number of pictures to slide
Local $GuiControls = 5 ; number of Gui boxes
Local $Box[$GuiControls] ; contains GUI controls
Local $Ndx[$MaxPictures] ; contains pointers

For $i = 0 To $MaxPictures - 1 ; Fill up pointers
    $Ndx[$i] = $i
Next

$hGUI = GUICreate("TEST_Select image", 670, 301, -1, -1)
$Box[0] = GUICtrlCreatePic($IMG[1], 237, 66, 196, 220)
$Box[1] = GUICtrlCreatePic($IMG[2], 456, 184, 100, 100)
$Box[2] = GUICtrlCreatePic($IMG[3], 564, 185, 100, 100)
$Box[3] = GUICtrlCreatePic($IMG[UBound($IMG) - 2], 6, 185, 100, 100)
$Box[4] = GUICtrlCreatePic($IMG[UBound($IMG) - 1], 117, 185, 100, 100)
$Dummy_Left = GUICtrlCreateDummy()
$Dummy_Right = GUICtrlCreateDummy()
Local $AccelKeys[2][2] = [["{LEFT}", $Dummy_Left],["{RIGHT}", $Dummy_Right]]
GUISetAccelerators($AccelKeys)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Dummy_Left
            $Pulled = $Ndx[UBound($Ndx) - 1] ; take the last element, it will become the first
            _ArrayPush($Ndx, $Pulled, 1) ; rotate indexes right
            _Load_Image()
        Case $Dummy_Right
            $Pulled = $Ndx[0] ; take the first element, it will become the last
            _ArrayPush($Ndx, $Pulled, 0) ; rotate indexes left
            _Load_Image()
    EndSwitch
WEnd

Func _Load_Image()
    For $i = 0 To $GuiControls - 1
        GUICtrlSetImage($Box[$i], $IMG[$Ndx[$i] + 1])
    Next
EndFunc   ;==>_Load_Image

As you can see not work as expcted, i don't know why. Using arrays we need the pointed or can be removed?

Edited by MyEarth
Link to comment
Share on other sites

Ok, i have found the problem with array and the script above, the #4, work fine with 5 images

The problem  is with more of 5 images, example if i have 6 image they not need to show in this way

4 5 1 2 3

123 are the first image of the array

45 must to be the lastest and the second to last of the array, in this way:

5 6 1 2 3

And when i rotate on the right -->, i can see:

6 1 2 3 4

and

1 2 3 4 5

and

2 3 4 5 6

and

3 4 5 6 1

etc. i hope i was clear

But not work as expected and will not loaded well, i see:

4 5 1 2 3 --> must to be 5 6 1 2 3

or

5 6 2 3 4 --> must to be 5 6 1 2 3 

etc.

Another problem is when i have < 5 images, but one thing at time. Thanks for the help, i'll appreciate

Edited by MyEarth
Link to comment
Share on other sites

Hi MyEarth

the incorrect sequence of the images was due to a not linear positioning of the Imageboxes on the form, them was positioned in a "random" left to right position, well now I corrected it for you.

Try this new listing, it must show and slide all the images that are in the directory in the correct order.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#include <array.au3> ; array managements
#include <File.au3>

$Pic = _FileListToArray(@ScriptDir, "*.jpg", 1) ; load images
If @error or $Pic[0] < 5 Then
    MsgBox(0,"few images","at least 5 images are needed",5)
    Exit
EndIf
$MaxPictures = $Pic[0] ; number of pictures to slide
_ArrayDelete($Pic,0) ; set to zero based array

local $GuiControls = 5 ; number of Gui boxes
local $Box[$GuiControls] ; contains GUI controls

Local $Ndx[$MaxPictures] ; contains pointers

for $i = 0 to $MaxPictures-1 ; Fill up pointers
    $Ndx[$i] = $i
Next

$hGUI = GUICreate("TEST_Select image", 670, 301, -1, -1)
$Box[0] = GUICtrlCreatePic($Pic[0],6, 185, 100, 100); 237, 66, 196, 220)
$Box[1] = GUICtrlCreatePic($Pic[1],117, 185, 100, 100) ; 456, 184, 100, 100)
$Box[2] = GUICtrlCreatePic($Pic[2], 237, 66, 196, 220) ; 564, 185, 100, 100)
$Box[3] = GUICtrlCreatePic($Pic[3], 456, 184, 100, 100) ; 6, 185, 100, 100)
$Box[4] = GUICtrlCreatePic($Pic[4], 564, 185, 100, 100); 117, 185, 100, 100)
$Dummy_Left = GUICtrlCreateDummy()
$Dummy_Right = GUICtrlCreateDummy()
$Dummy_Enter =  GUICtrlCreateDummy()
Local $AccelKeys[3][2] = [["{LEFT}", $Dummy_Left],["{RIGHT}", $Dummy_Right],["{ENTER}", $Dummy_Enter]]
GUISetAccelerators($AccelKeys)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Dummy_Right
            _ArrayPush($Ndx,$Ndx[0],0) ; rotate indexes left
            for $i = 0 To $GuiControls -1
                GUICtrlSetImage($Box[$i],$Pic[$Ndx[$i]])
            Next
        Case $Dummy_Left
            _ArrayPush($Ndx,$Ndx[UBound($Ndx)-1],1) ; rotate indexes right
            for $i = 0 To $GuiControls -1
                GUICtrlSetImage($Box[$i],$Pic[$Ndx[$i]])
            Next
        Case $Dummy_Enter
            MsgBox(0,"Selection","You selected image nr."&$ndx[2] & @crlf & $Pic[$Ndx[2]])

    EndSwitch
WEnd

Bye

EDIT:
added this simple error trap on image load

If @error or $Pic[0] < 5 Then
    MsgBox(0,"few images","at least 5 images are needed",5)
    Exit
EndIf
Edited by Pincopanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Thanks Pincopanco, is everything perfect except one thing...i want to start with 1 at the central box ( now is 3 ), as my central image, see the picture at the first post. Thanks again

Edited by MyEarth
Link to comment
Share on other sites

hi MyEarth

I do not know in what order the images are loaded from the disk, perhaps in alphabetical order?

however, a simple workaround to obtain the first image in the center may be to add Send("{LEFT 2}") immediately after "GUISetState(@SW_SHOW)"  :)

GUISetState(@SW_SHOW)
Send("{LEFT 2}")

bye

Edited by Pincopanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...