GUI Picture Positioning

Get help with using AutoHotkey and its commands and hotkeys
User avatar
PuzzledGreatly
Posts: 841
Joined: 29 Sep 2013, 22:18

GUI Picture Positioning

31 Oct 2013, 17:51

Can someone please tell me why the two pictures don't appear in the middle of the screen vertically? Thanks.

Code: Select all

X := A_ScreenWidth
Y := A_ScreenHeight
S := A_ScreenHeight * 0.6

shift := A_ScreenHeight * 0.2
nUP = 2

CX1 := 1*(X/2) - (X/2)/2 - (S/2), CY1 := 1*(Y/2) - (Y/2)/2 - (S/2) + Shift
CX2 := 2*(X/2) - (X/2)/2 - (S/2), CY2 := 1*(Y/2) - (Y/2)/2 - (S/2) + Shift

Gui, 90:-Caption  +ToolWindow  -DPIScale
Gui, 90:Color, yellow, white

	n = 1
	while n <= nUP
	{	
		CPX := CX%n%
		CPY := CY%n%

		Gui, 90:Add, picture, x%CPX% y%CPY% w%S% h-1 BackgroundTrans, elements\bckGreen.png
		
		n ++
	}

Gui, 90:show, center w%A_screenwidth% h%A_screenheight%, Test
Gui, 90:maximize, 

return
Alibaba
Posts: 479
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: GUI Picture Positioning

31 Oct 2013, 20:02

They actually do... (?)
test.JPG
"Nothing is quieter than a loaded gun." - Heinrich Heine
User avatar
PuzzledGreatly
Posts: 841
Joined: 29 Sep 2013, 22:18

Re: GUI Picture Positioning

31 Oct 2013, 21:24

Thanks for the screen shot, the GUI should take up the whole screen - there should be no taskbar. In your example there is more space below the images than above.
just me
Posts: 7013
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: GUI Picture Positioning

01 Nov 2013, 01:20

To center a control C vertically within a given rectangle R within your GUI you might use Y := RTop + ((RHeight - CHeight) // 2). As you see, you have to know the y-position (top) and height of the rectangle as well as the height of the control. Alternatively you might get the control's height after creation using GuiControlGet, C, Pos and move it to the centered position using GuiControl, Move, C, y%Y%.
User avatar
nnnik
Posts: 4448
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: GUI Picture Positioning

02 Nov 2013, 08:48

You'll have to use GUI, +AlwaysonTop to make the Taskbar go away.
Recommends AHK Studio
User avatar
PuzzledGreatly
Posts: 841
Joined: 29 Sep 2013, 22:18

Re: GUI Picture Positioning

02 Nov 2013, 21:12

Thanks, I add +AlwaysOnTop whenI have a fully working script. Addingit before and the warning messages are hidden which makes debugging more awkward. But +AlwaysOnTop won't solve the problem of centring the GUI control will it?
User avatar
nnnik
Posts: 4448
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: GUI Picture Positioning

03 Nov 2013, 14:18

No
But how you calculate it seems way too complex.
And you never use the actual height of the pictures or am I wrong?
Recommends AHK Studio
User avatar
PuzzledGreatly
Posts: 841
Joined: 29 Sep 2013, 22:18

Re: GUI Picture Positioning

03 Nov 2013, 18:43

I would like to make it simpler. The size of the pictures are relative to the size of the screen height. I'm making a fullscreen game and I want to make the pictures as large as possible taking into account the possible presence of text. The size of the pictures depends upon the number of pictures on the screen. In the fuil script that can be from 2 to 10.
User avatar
Sjc1000
Posts: 39
Joined: 02 Oct 2013, 02:07

Re: GUI Picture Positioning

04 Nov 2013, 19:13

Hi PuzzledGreatly,

Try this out. The GUI's are always an 8th of the screen height. And they're always a quarter ( roughly ) of the screen width. And they're positioned in the center.

Code: Select all

guiW	 			:= A_ScreenWidth / 4.5
guiH 				:= A_ScreenHeight / 8
guiPadding 			:= 10


numberOfGUIs 		:= floor( A_ScreenWidth / guiW )

myX 				+= A_ScreenWidth - ( A_ScreenWidth / 2 ) - ( ( guiW + guiPadding ) * numberOfGUIs / 2 )

Loop, % numberOfGUIs
{	Gui, %A_Index%:	Show, w%guiW% h%guiH% x%myX%
	Gui, %A_Index%: -Caption
	myX 			+= guiW + guiPadding
}
the math is transferable to a single GUI of course.
Please find me on the IRC if you have any questions, I'm never on the forum anymore.
User avatar
PuzzledGreatly
Posts: 841
Joined: 29 Sep 2013, 22:18

Re: GUI Picture Positioning

04 Nov 2013, 20:01

Thanks for the code. I added another Gui behind with a grid. Here's a picture:
TestGrid.png
TestGrid.png (4.47 KiB) Viewed 3995 times
The 4 gui's in the centre are closer to the top of the fullscreen than the bottom. Do you know how to get them dead centre?
User avatar
Sjc1000
Posts: 39
Joined: 02 Oct 2013, 02:07

Re: GUI Picture Positioning

04 Nov 2013, 20:48

Try this out.. I just used the same math for the y. Very simple formula. http://www.autohotkey.com/board/topic/9 ... er-option/

Code: Select all

guiW             := A_ScreenWidth / 4.5
guiH             := A_ScreenHeight / 8
guiPadding          := 10


numberOfGUIs       := floor( A_ScreenWidth / guiW )

myX             := A_ScreenWidth - ( A_ScreenWidth / 2 ) - ( ( guiW + guiPadding ) * numberOfGUIs / 2 )
myY 			:= A_ScreenHeight - ( A_ScreenHeight / 2 ) - ( guiH / 2 )

Loop, % numberOfGUIs
{   Gui, %A_Index%:   Show, w%guiW% h%guiH% x%myX% y%myY%
   Gui, %A_Index%: -Caption
   myX          += guiW + guiPadding
}
Please find me on the IRC if you have any questions, I'm never on the forum anymore.
User avatar
PuzzledGreatly
Posts: 841
Joined: 29 Sep 2013, 22:18

Re: GUI Picture Positioning

05 Nov 2013, 19:30

Thanks for the example.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Cifuentes, mitsakos156, ndr, teadrinker, vsub and 145 guests