Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[How to] Center something with no +Center option


  • Please log in to reply
3 replies to this topic
Sjc1000
  • Members
  • 572 posts
  • Last active: Mar 11 2017 11:41 AM
  • Joined: 06 Feb 2012

Hello, this little tutorial is how to center absolutely everything, with a simple formula you can literally center everything.

This is just for people who aren't the best with math, and they cannot figure it out.

 

With this simple trick you can even center windows.

 

 

Here is the formula

x 		:= Gui_Width - ( Gui_Width / 2 ) - ( Control_Width / 2 )
y 		:= Gui_Height - ( Gui_Height / 2 ) - ( Control_Height / 2 )

Pretty simple, if you follow this you will be able to center everything. 

 

Working example.

guiW 			:= 300
guiH			:= 200

controlH		:= 100
controlW 		:= 50

controlX 		:= guiW - ( guiW / 2 ) - ( controlW / 2 )
controlY 		:= guiH - ( guiH / 2 ) - ( controlH / 2 )

Gui, Add, Button, w%controlW% h%controlH% x%controlX% y%controlY%
Gui, Show, w%guiW% h%guiH%

This shows a button exactly in the middle of the GUI. You can change around the guiW / guiH and controlH / controlW variables and it will stay in the middle.

 

Hope this was useful ;)


Sjc1000 - Insert inspirational quote here!

PLEASE find me on the IRC if you have questions. I'm never on the forum anymore.

 


Butters
  • Members
  • 22 posts
  • Last active: Mar 08 2014 02:00 AM
  • Joined: 15 Sep 2013

can i use this to make reticle and how?



Multigamer
  • Members
  • 9 posts
  • Last active:
  • Joined: 26 Feb 2014

thx a lot



Sjc1000
  • Members
  • 572 posts
  • Last active: Mar 11 2017 11:41 AM
  • Joined: 06 Feb 2012

Hi Butters, Sorry for the late reply. I didn't see this anyone had posted until Tankdriver42 did.

 

 

This script REQUIRES GDIP which can be found here  http://www.autohotke...ary-145-by-tic/

Just download the ahk file and put it in with the script called 'Gdip.ahk'

#include Gdip.ahk
;==== GDIP Stuff =============================================================================
CoordMode, Mouse, Screen


;- Color -------------------------------
main 					:= 0xAAAAAAFF
;---------------------------------------

;- Startup -----------------------------
If !pToken 		:= Gdip_Startup()
{	MsgBox, GDIP could not start`, please make sure you have it on your system.
	ExitApp
}
;---------------------------------------

;- Gui ---------------------------------
Gui, -Caption +E0x80000 +LastFound +ToolWindow +AlwaysOnTop +hwndOSD
Gui, Show, x0 y0 w%A_ScreenWidth% h%A_ScreenHeight% NA
;---------------------------------------

;- Creates the stuff -------------------
hbm			:= CreateDIBSection( A_ScreenWidth, A_ScreenHeight)
hdc			:= CreateCompatibleDC()
obm			:= SelectObject( hdc, hbm)

pGraphics 	:= Gdip_GraphicsFromHDC( hdc)
;---------------------------------------

;- Pens --------------------------------
mainPen 	:= Gdip_CreatePen( main, 5)
;---------------------------------------

;==============================================================================================


setTimer, updateOSD, 10
return


updateOSD:
	Gdip_GraphicsClear(pGraphics)
	mouseGetPos, mX, mY
	
	length 				:= 140				; change this for longer crosshairs.
	
	Gdip_DrawLine(pGraphics, mainPen, mX - ( length / 2 ) , mY , mX + ( length / 2 ), mY)
	Gdip_DrawLine(pGraphics, mainPen, mX, mY - ( length / 2), mX, mY + ( length / 2 ))
	
	UpdateLayeredWindow( OSD, hdc, 0, 0, A_ScreenWidth, A_ScreenHeight)
Return:

Sjc1000 - Insert inspirational quote here!

PLEASE find me on the IRC if you have questions. I'm never on the forum anymore.