Page 1 of 1

TVClose() - Close GUI like a TV shutdown

Posted: 10 Jan 2014, 19:38
by tmplinshi
This is a very simple idea and code. Just decrease height then decrease width, that's it. See GIF image below:
Image

TVClose()

Code: Select all

TVClose(HideAndRestore = False, H_ReduceCount = 2, W_ReduceCount = 2)
{
	Gui, %A_Gui%:+LastFound
	WinGetPos, x, y, w, h
	p := HideAndRestore ? [x, y, w, h] : "" ; Backup GUI position
	
	; Decrease height (keep 3 pixels)
	Step := (h - 3) / H_ReduceCount
	Loop, % H_ReduceCount
	{
		y += Step / 2 ; Moving down
		h -= Step     ; Decreasing height
		WinMove,,,, %y%,, %h%
	}
	
	; Decrease Width (keep 3 pixels)
	Step := (w - 3) / W_ReduceCount
	Loop, % W_ReduceCount
	{
		x += Step / 2 ; Moving right
		w -= Step     ; Decreasing width
		WinMove,,, %x%,, %w%
	}
	
	if HideAndRestore
	{
		Gui, %A_Gui%:Hide
		WinMove,,, % p.1, % p.2, % p.3, % p.4 ; Restore GUI position
	}
}
Sample 1:

Code: Select all

Gui, Show, w1000 h500
Return

GuiClose:
	TVClose(True, 30, 10)
Return

; GuiClose:
; 	TVClose()
; ExitApp
Sample 2: (by joedf)

Code: Select all

Gui, Show, w1000 h500
Return

GuiClose:
	SetWinDelay, 10
	TVClose(False, 6, 6)
ExitApp
A much better version by AfterLemon --> viewtopic.php?f=6&t=1370#p10497

Re: TVClose() - Close GUI like a TV shutdown

Posted: 14 Jan 2014, 07:23
by Cristi
Thx, it looks very nice for how small it is the code :p

Re: TVClose() - Close GUI like a TV shutdown

Posted: 18 Jan 2014, 15:54
by Leefme
@tmplinshi:

1. with your example, if I replace "ExitApp" with "Return" a small gui 'remnant' remains.
can you fix this?
2. can you give an example of how to use --> HideAndRestore = true

Re: TVClose() - Close GUI like a TV shutdown

Posted: 18 Jan 2014, 16:00
by tmplinshi
Hi, Leefme, try TVClose(True)

Code: Select all

Gui, Show, w1000 h500
Return

GuiClose:
    TVClose(True)
Return

F1::Gui, Show

TVClose(HideAndRestore = False)
{
    Gui, %A_Gui%:+LastFound
    WinGetPos, x, y, w, h
    p := HideAndRestore ? [x, y, w, h] : "" ; Backup GUI position

    ; Decrease height (keep 3 pixels)
    Step := (h - 3) / 2
    Loop, 2
    {
        y += Step / 2 ; Moving down
        h -= Step     ; Decreasing height
        WinMove,,,, %y%,, %h%
    }

    ; Decrease Width (keep 3 pixels)
    Step := (w - 3) / 2
    Loop, 2
    {
        x += Step / 2 ; Moving right
        w -= Step     ; Decreasing width
        WinMove,,, %x%,, %w%
    }

    if HideAndRestore
    {
        Gui, %A_Gui%:Hide
        WinMove,,, % p.1, % p.2, % p.3, % p.4 ; Restore GUI position
    }
}

Re: TVClose() - Close GUI like a TV shutdown

Posted: 18 Jan 2014, 17:33
by tmplinshi
2014-1-19 Update: Added 2 parameters (H_ReduceCount and W_ReduceCount)

Re: TVClose() - Close GUI like a TV shutdown

Posted: 20 Jan 2014, 14:24
by Leefme
tmplinshi wrote:Hi, Leefme, try TVClose(True)
I tried the new script just as you posted, with the 'true'
The window shrinks, but then the window briefly appears at the original full and disappears again.

F1 makes the window appear fullsize again.

IMO, it ain't quite right yet.

Re: TVClose() - Close GUI like a TV shutdown

Posted: 20 Jan 2014, 15:31
by tmplinshi
Leefme wrote:
tmplinshi wrote:Hi, Leefme, try TVClose(True)
I tried the new script just as you posted, with the 'true'
The window shrinks, but then the window briefly appears at the original full and disappears again.

F1 makes the window appear fullsize again.

IMO, it ain't quite right yet.
Oh, that is strange. The window should be hidden, after then restored to original size and position. But what you said is in reverse order. Did you changed the code by mistaken? The last part should be:

Code: Select all

	if HideAndRestore
	{
		Gui, %A_Gui%:Hide
		WinMove,,, % p.1, % p.2, % p.3, % p.4 ; Restore GUI position
	}
If not, could you post your testing code to here or send it to me?

Yes, F1 is just an example code for testing.

Re: TVClose() - Close GUI like a TV shutdown

Posted: 20 Jan 2014, 16:51
by Leefme
You have misunderstood, you already have the code.

In the 3rd entry of this thread, I made 2 requests
In the 4th entry of this thread, you responded, stating "Hi, Leefme, try TVClose(True)"

I copied all the code within that "4th entry" and placed it in a new script.
The result was:
The window shrinks, but then the window briefly appears at the original full and disappears again.

Re: TVClose() - Close GUI like a TV shutdown

Posted: 20 Jan 2014, 19:32
by joedf
interesting idea... :)

Code: Select all

SetWinDelay, 10
TVClose(false,6,6)
But currently, this seems to be the most realistic setting to me.
cheers! ;)

Re: TVClose() - Close GUI like a TV shutdown

Posted: 21 Jan 2014, 07:23
by tmplinshi
Sorry, Leefme. I can't understand why is that. Hope others can help you.

@joedf
Nice setting. I never tried SetWinDelay. Thanks for the example.

Re: TVClose() - Close GUI like a TV shutdown

Posted: 29 Jan 2014, 17:30
by AfterLemon
Was testing some new ideas about managing numerical issues with windows when I saw this.

Wrote a version of it that handles both closing and opening animations.

JUST UPDATED:
Handles Windows too!
No Open/Close Designation. Does the opposite (open/close) of whichever was last done on it. (if you can think of a reason to change that, let me know.)
Works well up to 500k steps (is slow above 10k and very slow above 100k)
SEE NEXT POST

Code: Select all

SetTitleMatchMode,2
WindowName:=

Gui,Show,w500 h500 x100,GuiName
HWND:=WinExist(WINDOWNAME)
HWND2:=WinExist("GuiName")

F1::
	TVCloseOpen(HWND,50,50)
return

F2::
	TVCloseOpen(HWND2,100,100)
return

F3::WinShow,ahk_id %HWND%
F4::WinShow,ahk_id %HWND2%

TVCloseOpen(HWND,HeightStep:=100,WidthStep:=100){ ; Credit @ tmplinshi,Improved and Modified by AfterLemon
static p:=[]
	WinDelay:=A_WinDelay
	SetWinDelay,-1
	If p[HWND].1{
		x:=p[HWND].1+(p[HWND].3/2),y:=p[HWND].2+(p[HWND].4/2),Step:=p[HWND].4/HeightStep,Step2:=p[HWND].3/WidthStep
		WinMove,ahk_id %HWND%,,x,y,(p[HWND].5&0xC00000?-3:3),(p[HWND].5&0xC00000?-25:3)
		WinShow,ahk_id %HWND%
		Loop,% WidthStep
			WinMove,ahk_id %HWND%,,% xn:=x-((Step2*A_Index)/2),,% wn:=p[HWND].3-(Step2*(WidthStep-A_Index))
		If(p[HWND].5&0xC00000)
			WinSet,Style,+0xC00000,ahk_id %HWND%
		Loop,% HeightStep
			WinMove,ahk_id %HWND%,,,% yn:=y-((Step*A_Index)/2),,% hn:=p[HWND].4-(Step*(HeightStep-A_Index))
		p[HWND]:=""
	}else{
		WinGetPos,x,y,w,h,ahk_id %HWND%
		WinGet,S,Style,ahk_id %HWND%
		p[HWND]:=[x,y,w,h,S],Step:=(h-3)/HeightStep,Step2:=(w-3)/WidthStep
		Loop,% HeightStep
			WinMove,ahk_id %HWND%,,,% y:=y+(Step/2),,% h:=h-Step
		WinSet,Style,-0xC00000,ahk_id %HWND%
		WinSet,Redraw,,ahk_id %HWND%
		Loop,% WidthStep
			WinMove,ahk_id %HWND%,,% x:=x+(Step2/2),,% w:=w-Step2
		WinHide,ahk_id %HWND%
		WinMove,ahk_id %HWND%,,% p[HWND].1,% p[HWND].2,% p[HWND].3,% p[HWND].4
	}SetWinDelay,%WinDelay%
}
EDIT: Sorry for so many edits. Now handles multiple Windows independently.
EDIT 2: Wasn't reseting the size properly since switching to working with windows.

PROBLEMS: Still does not allow windows with closing dialogs to exit properly, if used in unison with NCHITTEST

Re: TVClose() - Close GUI like a TV shutdown

Posted: 29 Jan 2014, 18:50
by tmplinshi
@AfterLemon
wow, your version looks much better. I've added a link to your version in the #1 post.

Re: TVClose() - Close GUI like a TV shutdown

Posted: 30 Jan 2014, 12:04
by AfterLemon
Just updated to include Windows as well!
Newest version available here: viewtopic.php?f=6&t=1370#p10497

Re: TVClose() - Close GUI like a TV shutdown

Posted: 31 Jan 2014, 10:08
by Relayer
Hi,

I added a few things that I wanted to contribute.

1. Added fade-in to make it look like a TV tube is warming up.
2. Added a black dummy background for closing to mimic the TV tube going black.

I changed the function around for my own purposes which means what I have done will not just plug into what others have done. I have the function instantiate with the "GUI, Show", I allow a re-open with Gui ID only, and the function can be passed a gui number/name OR the HWND and work. Having said that, I wanted to let you see what else could be done to add to the effect. So, before studying the script run it to see the new effects.

Relayer

Code: Select all

#SingleInstance Force
#NoEnv
SetTitleMatchMode, 2  ;contains
CoordMode, Mouse, Relative


SetBatchLines, -1

Gui, 1:+HWNDGui1ID
;Gui, 1:Show, x100 h-25 w-3 ;w500 h500 x100

TVCloseOpen(Gui1ID, 100, 100, 500, 500)

;Gui,2:Show, x612 h-25 w-3 ;w500 h500 x612
Gui, 2:+HWNDGui2ID
TVCloseOpen(2, 612, 100, 300, 500, "hide")

Return

GuiEscape:
GuiClose:
	TVCloseOpen(Gui1ID, "close")
	TVCloseOpen(2)
return

2GuiEscape:
2GuiClose:
	TVCloseOpen(2, "close")
	TVCloseOpen(Gui1ID)
return

TVCloseOpen(GuiID, x = 0, y = 0, w = 0, h = 0, WidthStep = 75, HeightStep = 75)
{
static p:=[]
	WinDelay:=A_WinDelay
	SetWinDelay,-1
	Gui,%GuiID%:+LastFound
	WinGet,S,Style

	if (SubStr(x, 1, 1) = "c") and (p.HasKey(GuiID))
	{
		;close
		WinGetPos,x,y,w,h
		p[GuiID] := [x,y,w,h]
		
		
		Gui, %GuiID%:+AlwaysOnTop
		Gui, dummy:-Caption
		Gui, dummy:Color, Black
		Gui, dummy:Show, % "x" x " y" y " w" w " h" h
		
		Step:=(h-3)/HeightStep, Step2:=(w-3)/WidthStep
		Loop,% HeightStep
		{
			WinMove,,,,% y:=y+(Step/2),,% h:=h-Step
		}
		Loop,% WidthStep
		{
			WinMove,,,% x:=x+(Step2/2),,% w:=w-Step2
		}
		Sleep, 500
		Gui, dummy:Destroy
		Gui,%GuiID%:Hide
		WinMove,,,% p[GuiID].1,% p[GuiID].2,% p[GuiID].3,% p[GuiID].4
		Gui, %GuiID%:+AlwaysOnTop
	}
	else if (SubStr(x, 1, 1) = "c") and !(p.HasKey(GuiID))
		Return False
	else
	{
		if !(p.HasKey(GuiID))
		{
			p.Insert(GuiID)
			p[GuiID] := [x, y, w, h]
		}
		if !(SubStr(WidthStep, 1, 1) = "h")
		{
			;open
			
			Gui, %GuiID%:+AlwaysOnTop
			Gui, dummy:-Caption
			Gui, dummy:Color, Black
			Gui, dummy:Show, % "x" p[GuiID].1 " y" p[GuiID].2 " w" p[GuiID].3 " h" p[GuiID].4
			Sleep, 250
			
			x:=p[GuiID].1+(p[GuiID].3/2),y:=p[GuiID].2+(p[GuiID].4/2),Step:=p[GuiID].4/HeightStep,Step2:=p[GuiID].3/WidthStep
			Gui,%GuiID%:Show,% "x" x " y" y " w" (S&0xC0000?-3:3) " h" (S&0xC0000?-22:3)
			trans := 125
			tStep := Floor((255 - trans) / HeightStep)
			Loop,% WidthStep
			{
				WinMove,,,% x-((Step2*A_Index)/2),,% p[GuiID].3-(Step2*(WidthStep-A_Index))
			}
			Loop,% HeightStep
			{
				WinMove,,,,% yn:=y-((Step*A_Index)/2),,% hn:=p[GuiID].4-(Step*(HeightStep-A_Index))
				WinSet, Transparent, % (A_Index * tStep), A
			}
			c := (HeightStep * tStep)
			Loop, % (255 - c)
				WinSet, Transparent, % c + A_Index, A
			Gui, dummy:Destroy
		}
	}
	SetWinDelay,%WinDelay%

}

Re: TVClose() - Close GUI like a TV shutdown

Posted: 31 Jan 2014, 10:38
by AfterLemon
Couple things... the caption check in your
Gui,%GuiID%:Show,% "x" x " y" y " w" (S&0xC0000?-3:3) " h" (S&0xC0000?-22:3)
needs to be 0xC00000 (updated in my post)

Secondly, your temporary black GUI needs to have +ToolWindow so that there isn't a secondary window shown on the taskbar.
Finally, while the idea is interesting, the main GUI handling causes that empty line in the middle of the black.
WinSet,Redraw might help.

Re: TVClose() - Close GUI like a TV shutdown

Posted: 31 Jan 2014, 11:09
by Relayer
AfterLemon,

Thanks for the feedback. I didn't mean to present my script as finished in any way. I simply wanted to toss out a few ideas I had. I would fully expect the ideas to be rewritten into other people's scripts in ways they deem fit for their purposes. In fact, at this point this script is just for fun and may never be polished.

Relayer

Re: TVClose() - Close GUI like a TV shutdown

Posted: 01 Feb 2014, 04:06
by tmplinshi
@Relayer
interesting :D