Unable To Grasp Basic GUI Design, Need Feedback Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Mulsiphix
Posts: 148
Joined: 20 Nov 2015, 17:56

Unable To Grasp Basic GUI Design, Need Feedback

Post by Mulsiphix » 16 Jan 2022, 14:26

I would like to create a simple two frame animation.

Desired Result:
  1. Show ImageA at specific coordinates for 750ms
  2. Hide ImageA (file is 200x200 px)
  3. Show ImageB at specific coordinates for 750ms
  4. Hide ImageB (file is 250x250x px)
The issue with the script below is only ImageA is being utilized, not both as I desire. I don't know how to overcome this. Can anyone help me understand what I am doing wrong?

Code: Select all

Gui, -Caption +AlwaysOnTop +ToolWindow +LastFound
Gui, Margin, 0, 0 ; Remove margins to get perfect alignment with center of screen
Gui, Color, 0000FF ; Set background color. You might need to change this color to one not contained in the crosshair
WinSet, TransColor, 0000FF ; Make the background color transparent

Gui, Add, Picture, vSmall, ImageA.png ; Add picture and assign it a variable
Gui, Add, Picture, vBig, ImageB.png ;
GuiControl, Hide, Big ; If not included, both images appear vertically stacked, moving between coordinate locations. This ensures only one image is shown. 

Gosub, Animate
Return

Animate:
Gui, Show, x680 y1200, Small ; Show ImageA.png at exact screen coordinates
Sleep, 750
Gui, Hide ; Hide ImageA.png
Gui, Show, x650 y1170, Big ; Show ImageB.png at exact screen coordinates
Sleep, 750
Gui, Hide ; Hide ImageB.png
Gosub, Animate ; Restart animation process
Return

Mulsiphix
Posts: 148
Joined: 20 Nov 2015, 17:56

Re: Unable To Grasp Basic GUI Design, Need Feedback

Post by Mulsiphix » 16 Jan 2022, 15:24

This is hardly a code optimized solution, and I am positive there is a more sensible way to achieve the desired effect, but this solved my problem. This gives me exactly the effect I desire. Adding it here in case anybody else finds this thread later and wonders how I solved it.

Code: Select all

Gui, -Caption +AlwaysOnTop +ToolWindow +LastFound
Gui, Margin, 0, 0 ; Remove margins to get perfect alignment with center of screen
Gui, Color, 0000FF ; Set background color. You might need to change this color to one not contained in the crosshair
WinSet, TransColor, 0000FF ; Make the background color transparent

Gui, Add, Picture, vSmall, ImageA.png ; Add picture and assign it a variable
Gui, Add, Picture, vBig, ImageB.png ;

;GuiControl, Hide, Big ; If not included, both images appear vertically stacked. This ensures only one image is shown. Side effect of using this is that only ImageA.png is used for the entire script. Better solution on next line.
GuiControl, Move, Big, x3000 y3000 ; Solves the image stacking problem. Both ImageA.png and ImageB.png appear in script now.

Gosub, Animate
Return

Animate:
Gui, Show, x680 y1200 NA, Small ; Show ImageA.png at exact screen coordinates
Sleep, 750
GuiControl, Move, Big, x0 y0 ; Move ImageB.png back into visable portion of screen.
Gui, Show, x600 y1130 NA, Big ; Unhide and reposition image at exact screen coordinates
Sleep, 750
GuiControl, Move, Big, x3000 y3000 ; Without this line, both images will move slightly when the Animate label is processed a second time. Though neither image will shift further in future loopings of the label.Animate label loops.

Gosub, Animate ; Restart animation process
Return

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Unable To Grasp Basic GUI Design, Need Feedback  Topic is solved

Post by flyingDman » 16 Jan 2022, 15:53

Settimer is probably a better way to achieve this. You can hide or show an image using the hide%var% option were var is either 0 or 1. So that it would boil down to:

Code: Select all

flag := 1
Gui, -Caption +AlwaysOnTop +ToolWindow +LastFound
Gui, Margin, 0, 0 ; Remove margins to get perfect alignment with center of screen
Gui, Color, 0000FF ; Set background color. You might need to change this color to one not contained in the crosshair
WinSet, TransColor, 0000FF ; Make the background color transparent

Gui, Add, Picture, x0 y0 hide vSmall, imagea.png ; Add picture and assign it a variable
Gui, Add, Picture, x80 y130 hide vBig, imageb.png ;
Gui, Show, x0 y0 NA
settimer, label, 750

label:
GuiControl,hide%flag%,small
flag := !flag
GuiControl,hide%flag%,big
return

esc::
exitapp
14.3 & 1.3.7

Mulsiphix
Posts: 148
Joined: 20 Nov 2015, 17:56

Re: Unable To Grasp Basic GUI Design, Need Feedback

Post by Mulsiphix » 16 Jan 2022, 18:55

Wow, your approach is so much cleaner. Thank you for showing it to me. Definitely going to use your script instead. More importantly, I learned something new. Thank you :clap: :D

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Unable To Grasp Basic GUI Design, Need Feedback

Post by flyingDman » 16 Jan 2022, 19:06

You're welcome :thumbup:
14.3 & 1.3.7

Post Reply

Return to “Ask for Help (v1)”