View few / many images in dynamic GUI

Get help with using AutoHotkey and its commands and hotkeys
Albireo
Posts: 1402
Joined: 16 Oct 2013, 13:53

View few / many images in dynamic GUI

Post by Albireo » 20 Jan 2021, 18:27

Hi!
My wish is to handle an unknown number of images.
Usually there are a few pictures one, two or three, but there can be more than that.
(I want to see all the pictures and choose one of them)

If there are a few images to show, there is no problem (fits in the GUI window)
But if there are too many...

Wrote a small test script that shows two images (easy to add more)

Code: Select all

; Version 20 jan 2020
#Singleinstance force

allImages := [{}]	; Create an object in an array

images = 
( LTrim
	C:\Windows\Web\4K\Wallpaper\Windows\img0_768x1024.jpg
	C:\Windows\Web\4K\Wallpaper\Windows\img0_1366x768.jpg
)
imgNames := strSplit(images, "`n", "`n")

; The start values
imgGuiWidth = 200
imgGuiHeight = 200
guiRatio := imgGuiWidth / imgGuiHeight
imgGuiX := 75
imgGuiY := 50

; Create an Array with information about the images
for k, v in imgNames
{	imgInfo := []
	; Handle the imagename
	SplitPath v, imgName, imgPath
	imgInfo.name := imgName
	imgInfo.path := imgPath
	
	; Check and handle width and height of the image to fit an Area
	Gui 2: add, picture, hwndmypic, % v
	ControlGetPos,,, imgWidth, imgHeight,, ahk_id %mypic%
	imgInfo.orgWidth := imgWidth
	imgInfo.orgHeight := imgHeight
	imgInfo.ratioWidth	:= imgWidth	 / imgGuiWidth 
	imgInfo.ratioHeight	:= imgHeight / imgGuiHeight
	
	If ( imgInfo.ratioWidth > imgInfo.ratioHeight )	; Width is larger
	{	imgInfo.newWidth := imgGuiWidth
		imgInfo.newHeight := Round(imgInfo.orgHeight / imgInfo.ratioWidth, 0)
	}
	else
	{	imgInfo.newWidth := Round(imgInfo.orgWidth / imgInfo.ratioHeight, 0)	; Height is larger
		imgInfo.newHeight := imgGuiHeight
	}
	
	imgInfo.picX := imgGuiX
	imgInfo.picY := imgGuiY
	
/*	
	MsgBox ,, %A_ScriptName% - Row %A_LineNumber%,
	( LTrim
	 %	"Gui wide .: " imgGuiWidth "`tGui Height .: " imgGuiHeight "
		Path . .: `t" imgInfo.path "
		Image  .: `t" imgInfo.name "
		Image Width  . . .: `t"	imgInfo.orgWidth "`tRatio Width  .: " imgInfo.ratioWidth "
		Image Height . . .: `t"	imgInfo.orgHeight "`tRatio Height .: " imgInfo.ratioHeight "
		New Width . . . . .: `t" imgInfo.newWidth "`tNew Height. .: " imgInfo.newHeight "
		- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
		imgInfo.picX .: " imgInfo.picX "
		imgInfo.picY .: " imgInfo.picY
	)
*/
	allImages[A_Index] := imgInfo
	imgGuiY += imgGuiHeight + 50
}

; Max height on GUI
shGUI := imgGuiY + 50 ; winGuiSizeHeight
If ( shGUI > 600 )
	shGUI = 600
swGUI = 350	; winGuiSizeWidth

; Show the result in a GUI
	; --- --- --- --- --- --- --- --- --- --- --- ---  --- --- ---  --- --- --- 
	Gui 1: Font, S14 cGreen Bold, Verdana
	Gui 1: Add, Text, x0 y5 w%swGUI% h25 center , Images

	Loop % allImages.count()
	{	posX := allImages[A_Index].picX
		posY := allImages[A_Index].picY
		Gui 1: Font, s10 cGreen Normal, Arial
		Gui 1: Add, Text, x%posX% y%posY%, % allImages[A_Index].name
		
		height := allImages[A_Index].newHeight
		width  := allImages[A_Index].newWidth
		imgName := allImages[A_Index].path "\" allImages[A_Index].name
		Gui 1: Add, Picture, xp+10 yp+25 h%height% w%width% vImg%A_Index%, % imgName
	}

	Gui 1: Show, x100 y200 w%swGUI% h%shGUI% , %A_ScriptName%
Return

; --- --- --- --- --- --- --- --- --- --- --- ---  --- --- ---  --- --- --- 
ExitApp
But if too many images is added, the last images stop to be shown.

Right now, it feels like clicking on the image to show the next, would be the nicest solution
How is this solved (in a simple way)?
Ideas for other solutions?

User avatar
Hellbent
Posts: 1191
Joined: 23 Sep 2017, 13:34

Re: View few / many images in dynamic GUI

Post by Hellbent » 20 Jan 2021, 18:52

I had done something similar with this Color Picker Mini+



.
20210120185101.png
20210120185101.png (48.13 KiB) Viewed 83 times

.
Something like that?

User avatar
Hellbent
Posts: 1191
Joined: 23 Sep 2017, 13:34

Re: View few / many images in dynamic GUI

Post by Hellbent » 20 Jan 2021, 19:58

Perhaps something like this?

Code: Select all

#SingleInstance, Force
Gui, 1:+AlwaysOnTop -DPIScale
Gui, 1:Color, 22262A
Gui, 1:Show, w1000 h400, DEMO
Gui, 2:+Parent1 -DPIScale -Caption
Gui, 2:Color, 00444A
Gui, 2:Show, x10 y80 h310 w980,
Gui, 3:+Parent2 -DPIScale -Caption
Gui, 3:Color, 00444A
Gui, 3:Show, x0 y10 h290 w10000,
Gui, 1:Add, Slider, x250 y40 w500 Range0-9020 BackgroundTrans ToolTip AltSubmit hwndhwnd gMovePics,0
GuiControl, 1:Focus, % hwnd
x := 0, y:= 0, w := 290, h := 290, Colors := ["005555","00C5D1","0050CC","0021B3","008148","007FCE","222222","005BC4","00FDFC","004C8D","003455"]
Loop, 33   {
  Gui, 3:Add, Progress, % "x" x " y" y " w" w " h" h " BackgroundBlack c" Colors[ Random( 1 , Colors.Length() ) ] , 100
  x += w + 10
}
return
GuiClose:
GuiContextMenu:
*ESC::
   ExitApp
Random(Min,Max){
   Random, out, Min, Max
   return out
}
MovePics:
   GuiControlGet, NewPos, 1:, % Hwnd
   Gui, 3:Show, % "x" NewPos * -1 " y" 10 " w" 10000 " h" 290 " NA"
   return

You can add buttons etc to move exact amounts and all that other stuff. This is more to show the windows in windows in windows trick.


.
20210120195801.png
20210120195801.png (31.18 KiB) Viewed 68 times

Albireo
Posts: 1402
Joined: 16 Oct 2013, 13:53

Re: View few / many images in dynamic GUI

Post by Albireo » 21 Jan 2021, 08:05

Your solutions is very nice (ColorPicker and the image viewer)
But I don't understand, how to use your code in my project....

Post Reply

Return to “Ask For Help”