Jump to content

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

Splash Text with Shadow and Transparent Background Function


  • Please log in to reply
15 replies to this topic
specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007
Posted Image

Here is a function I made for use with one of my current projects and I thought others might find it useful. Plus I have a question about how this is done (at the bottom of post).

The shadow effect is something I learned from skan's Tips N Tricks post.

Usage:
TransSplashText_On(Text)  
TransSplashText_Off()

Optional parameters may be used with "On".
TransSplashText_On(Text,Font,TC,SC,TS,xPos,yPos,TimeOut)
Text = Text to display
Font = Example "Arial"
TC = Font (Text) Color
SC = Shadow Color, use "0" for no shadow
TS = Font (Text) Size
xPos and yPos = The screen position to display the transparent gui window
TimeOut = Milliseconds to display the text, "0" is infinite, meaning splashtext stays until TransSplashText_Off() is used.

Edit, Changed the "TimeOut" to use a timer instead of a loop. This should allow the script to continue while the text is displayed.

Download, TransSplashText.ahk

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;                         Splash Text with a transparent background.                          ;;;
;;; This is accomplished by using a gui window with a transcolor set.  The parameters to pass to;;;
;;; the function are as follows. A demonstration script is included at the bottom of this page. ;;;
;;;                                                                                             ;;;
;;;  Usage:  TransSplashText_On(Text)        TransSplashText_Off()                              ;;;
;;;                                                                                             ;;;
;;; You may also pass the following parameters to the On command.                               ;;;
;;;                                                                                             ;;;
;;;  TransSplashText_On(Text,Font,TC,SC,TS,xPos,yPos,TimeOut)                                   ;;;
;;;                                                                                             ;;;
;;;  Text = Text to display,    Font = Example "Arial",    TC = Color                           ;;;
;;;  SC = Shadow Color, use "0" for no shadow,             TS = Font Size                       ;;;
;;;  xPos and yPos = The screen position to display the text.                                   ;;;
;;;  TimeOut = Milliseconds to display the text, "0" is infinite, Meaning splashtext stays      ;;;
;;;  until TransSplashText_Off() is used.                                                       ;;;
;;;                                                                                             ;;;
;;;  Only the parameters to change need to be used as long as the other parameters are empty    ;;;
;;;  strings.  Example, the following would only change the shadow color, other parameters      ;;;
;;;  still retain their default values.                                                         ;;;
;;;  TransSplashText_On(Text,"","","Red","","","","")                                           ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 

TransSplashText_On(Text="",Font="",TC="",SC="",TS="",xPos="",yPos="",TimeOut="")
	{
	If Text = 
		Text = TransSplashText
	If Font = 
		Font = Impact
	If TC = 
		TC = White
	If SC = 
		SC = 828284
	If TS = 
		TS = 20
	If xPos = 
		xPos = Center
	If yPos = 
		yPos = Center
	If TimeOut = 
		TimeOut = 0
	If SC != 0
		{
		Gui, 99:Font, S%TS% C%SC%, %Font%
		Gui, 99:Add, Text, x12 y12, %Text%
		}
	Gui, 99:Font, S%TS% C%TC%, %Font%
	Gui, 99:Add, Text, x10 y10 BackgroundTrans, %Text%

	Gui, 99:Color, EEAA99
	Gui, 99:+LastFound -Caption +AlwaysOnTop +ToolWindow
	WinSet, TransColor, EEAA99
	Gui, 99:Show, x%xPos% y%yPos% AutoSize, TransSplashTextWindow
	If TimeOut != 0
		{
		SetTimer, TextOff, %TimeOut%
		Return
		TextOff:
		TransSplashText_Off()
		Return
		}
	}

TransSplashText_Off()
	{
	Gui, 99:Destroy
	SetTimer, TextOff, Off
	}

/*	

#NoEnv  
SendMode Input  
SetWorkingDir %A_ScriptDir% 
#SingleInstance, Force
#Include TransSplashText.ahk

Gui, Add, GroupBox, x5 y5 w390 h40, Text to Display
Gui, Add, Edit, x10 y20 w380 r1 vText, Transparent Splash Text

Gui, Add, GroupBox, x5 y50 w100 h40, Font
Gui, Add, Edit, x10 y65 w90 r1 vFont, Impact

Gui, Add, GroupBox, x110 y50 w100 h40 , Text Color
Gui, Add, Edit, x115 y65 w90 r1 vFontColor, White

Gui, Add, GroupBox, x215 y50 w100 h40 , Shadow Color
Gui, Add, Edit, x220 y65 w90 r1 vShadowColor, 828284

Gui, Add, GroupBox, x320 y50 w75 h40 , Font Size
Gui, Add, Edit, x325 y65 w65 r1 vFontSize, 35

Gui, Add, GroupBox, x5 y95 w60 h40 , X Position
Gui, Add, Edit, x10 y110 w50 r1 vxPos, Center

Gui, Add, GroupBox, x70 y95 w60 h40 , Y Position
Gui, Add, Edit, x75 y110 w50 r1 vyPos, 10

Gui, Add, GroupBox, x135 y95 w100 h40 , Time Out in MS
Gui, Add, Edit, x140 y110 w90 r1 vTimeOut, 10000

Gui, Add, GroupBox, x240 y95 w75 h40 ,
Gui, Add, Button, x245 y111 w65 h20 gShow, Show Text

Gui, Add, GroupBox, x320 y95 w75 h40 ,
Gui, Add, Button, x325 y111 w65 h20 gHide, Hide Text

Gui, Add, GroupBox, x5 y140 w390 h205 , Notes
Gui, Add, Text, x10 y155, ShadowColor, 0 = No Shadow
Gui, Add, Text, x10 y+5 w380, TimeOut, 0 = Text stays on screen until TransSplashText_Off() is called.
Gui, Add, Text, x10 y+10, Text - defaults to "TransSplashText".
Gui, Add, Text, x10 y+5, Font - defaults to "Impact".
Gui, Add, Text, x10 y+5, TC (Text Color) - defaults to "White".
Gui, Add, Text, x10 y+5, SC (Shadow Color) - defaults to "828284".
Gui, Add, Text, x10 y+5, TS (Text Size) - defaults to "20".
Gui, Add, Text, x10 y+5, xPos - defaults to "Center".
Gui, Add, Text, x10 y+5, yPos - defaults to "Center".
Gui, Add, Text, x10 y+5, TimeOut - defaults to "0" or no timeOut.

Gui, Show, w400 h350, Test
Return

Show:
Gui, Submit, NoHide
TransSplashText_On(Text,Font,FontColor,ShadowColor,FontSize,xPos,yPos,TimeOut)
Return

Hide:
TransSplashText_Off()
Return

Esc::
Exit:
GuiClose:
Gui, Destroy
ExitApp

*/

Here is the demo script seen in the image above, it is also included in the download.
#NoEnv  
SendMode Input  
SetWorkingDir %A_ScriptDir% 
#SingleInstance, Force
; #Include TransSplashText.ahk

Gui, Add, GroupBox, x5 y5 w390 h40, Text to Display
Gui, Add, Edit, x10 y20 w380 r1 vText, Transparent Splash Text

Gui, Add, GroupBox, x5 y50 w100 h40, Font
Gui, Add, Edit, x10 y65 w90 r1 vFont, Impact

Gui, Add, GroupBox, x110 y50 w100 h40 , Text Color
Gui, Add, Edit, x115 y65 w90 r1 vFontColor, White

Gui, Add, GroupBox, x215 y50 w100 h40 , Shadow Color
Gui, Add, Edit, x220 y65 w90 r1 vShadowColor, 828284

Gui, Add, GroupBox, x320 y50 w75 h40 , Font Size
Gui, Add, Edit, x325 y65 w65 r1 vFontSize, 35

Gui, Add, GroupBox, x5 y95 w60 h40 , X Position
Gui, Add, Edit, x10 y110 w50 r1 vxPos, Center

Gui, Add, GroupBox, x70 y95 w60 h40 , Y Position
Gui, Add, Edit, x75 y110 w50 r1 vyPos, 10

Gui, Add, GroupBox, x135 y95 w100 h40 , Time Out in MS
Gui, Add, Edit, x140 y110 w90 r1 vTimeOut, 10000

Gui, Add, GroupBox, x240 y95 w75 h40 ,
Gui, Add, Button, x245 y111 w65 h20 gShow, Show Text

Gui, Add, GroupBox, x320 y95 w75 h40 ,
Gui, Add, Button, x325 y111 w65 h20 gHide, Hide Text

Gui, Add, GroupBox, x5 y140 w390 h205 , Notes
Gui, Add, Text, x10 y155, ShadowColor, 0 = No Shadow
Gui, Add, Text, x10 y+5 w380, TimeOut, 0 = Text stays on screen until TransSplashText_Off() is called.
Gui, Add, Text, x10 y+10, Text - defaults to "TransSplashText".
Gui, Add, Text, x10 y+5, Font - defaults to "Impact".
Gui, Add, Text, x10 y+5, TC (Text Color) - defaults to "White".
Gui, Add, Text, x10 y+5, SC (Shadow Color) - defaults to "828284".
Gui, Add, Text, x10 y+5, TS (Text Size) - defaults to "20".
Gui, Add, Text, x10 y+5, xPos - defaults to "Center".
Gui, Add, Text, x10 y+5, yPos - defaults to "Center".
Gui, Add, Text, x10 y+5, TimeOut - defaults to "0" or no timeout.

Gui, Show, w400 h350, Test
Return

Show:
Gui, Submit, NoHide
;TransSplashText_On()
TransSplashText_On(Text,Font,FontColor,ShadowColor,FontSize,xPos,yPos,TimeOut)
;TransSplashText_On(Text,"","","Red","","","","")
Return

Hide:
TransSplashText_Off()
Return

Esc::
Exit:
GuiClose:
Gui, Destroy
ExitApp

I you need new version of any scripts I haven't re-uploaded yet feel free to pm me.

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
TransSplashText_On(Text="",Font="",TC="",SC="",TS="",xPos="",yPos="",TimeOut="")
   {
   If Text = 
      Text = TransSplashText
   If Font = 
      Font = Impact
   If TC = 
      TC = White
   If SC = 
      SC = 0
   If TS = 
      TS = 20
   If xPos = 
      xPos = Center
   If yPos = 
      yPos = Center
   If TimeOut = 
      TimeOut = 5000
The same as
TransSplashText_On(Text = "TransSplashText", Font = "Impact", TC = "White", SC = 0, TS = 20, xPos = "Center", yPos = "Center", TimeOut = 5000){
:D

Edit: Which can of course be multiline.

specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007

The same as

TransSplashText_On(Text = "TransSplashText", Font = "Impact", TC = "White", SC = 0, TS = 20, xPos = "Center", yPos = "Center", TimeOut = 5000){

Thanks for the reply but this is what I mentioned above. When I quote the optional parameters no splash text displays. The only way I have been able to get optional parameters to work is by using an empty string. Any ideas?

I'm using the latest AHK basic, Version 1.0.48.05 and winxp.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
If you omit a parameter of a function with AutoHotkey Basic, you are required to omit all subsequent parameters.

AutoHotkey_L allows code like the following (when directly calling a user-defined function):
TransSplashText_On("Test",, "Black") ; Omitted Font.


specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007

If you omit a parameter of a function with AutoHotkey Basic, you are required to omit all subsequent parameters.

I thought about that but the quoted parameters don't work even when I omit all of them. I'm sure there's some dumb typo I've made somewhere. However using empty strings allows me to leave any parameter in any part of the function blank, Like you show above, and it seems to work.

AutoHotkey_L allows code like the following (when directly calling a user-defined function):

I know, I need to update to AHK_L. I'll get around to it soon. :wink:

tomoe_uehara
  • Members
  • 2166 posts
  • Last active: Jun 11 2015 05:33 PM
  • Joined: 05 Sep 2009
Very nice!
Btw, please don't change this script to AHK_L only
Posted Image

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
Why don't you upgrade, tomoe_uehara?
The ANSI x32 shouldn't break any of your existing scripts, so you would have nothing to lose and a hundred Scripts&Functions posts to gain :idea:

specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007
Can anyone think of a way to use the timeout parameter that doesn't hold up the rest of a script?

Currently if you set a timeout a script must wait until the text times out before continuing. If you use a timeout of 0 it doesn't start the loop so the script continues but a TransSplashText_Off() must come later to kill it. This isn't a huge problem but it would be handy if it could be done.

Because of this I've changed the default to not time out.

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
SetTimer :?:

specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007

SetTimer :?:

That did seem to work, I tried the timer before switching to the loop. The drawback is, since there is a label in the include file you can not include it in the auto-execute section of a script, which is ok as long as everyone who downloads understands that.

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
Timers can be inside functions:
#Persistent
ToolTip(text){
   ToolTip % text
   SetTimer, T, -3000
   return
   T:
      tooltip
   return
}
ToolTip("Hi")
MsgBox The tooltip is still running, but it will go away on its own.`nThis box is just to show you how asynchronous timers are :)
Note the function above the commands, not interrupting the Auto-Execute section

Drugwash
  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008
Functions with a truckload of parameters are a PITA - I've learned it the hard way, when I had to go through several scripts and manually change parameters within calls.
An easier and much cleaner way would be a unique, long string of parameters that uses a well established delimiter and if needed, other subsequent parameters that cannot comply to the delimiter in first parameter.

For example, you could call it like this:

TransSplashText_On("TCWhite SC0 TS20 xPCenter yPCenter TO5000", "TransSplashText", "Impact")

TransSplashText_On(p, Text="", Font="")
{
Loop, Parse, p, %A_Space%
	{
	StringLeft, c, A_LoopField, 2
	StringTrimLeft, v, A_LoopField, 2
	%c% := v
	}
 xPos := xP, yPos := yP	; or you may change the rest of the function to only use two-letter variable names
; rest of the function
}

(AHK 1.0.48.05 and Win98SE) forever | My scripts are here


specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007
@nimda, I did not know you could put a label in a function like that. Learned something new. Didn't know about putting the parameters on multilines either, so two new things. :D I think I'll change it back to a timer.

@Drugwash, I've been wondering about using one long parameter, especially on the huge but worthless No Image Image Gui I just did. Really long parameters in that one.

But in this one it seems as if it would limit the use of the optional parameters. As it stands now you can use the defaults of any of the parameters and as long as you have the correct amount of commas only change the parameters you want. If it were one long parameter it would be all or none, you couldn't just change 1 thing in the middle.

Of course if anyone wants to fix this up and release a better version feel free. I've pretty much moved on and want to put this one to rest so hopefully one more change and it's done.

Thanks for the input.

Drugwash
  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008
You can always use the ternary operator for missing/default parameters... But, as you wish. ;)

And the No image GUI is not worthless: it inspired me to build the Kyokusen clock variant. 8)

(AHK 1.0.48.05 and Win98SE) forever | My scripts are here


specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007

You can always use the ternary operator for missing/default parameters... But, as you wish. ;)

And the No image GUI is not worthless: it inspired me to build the Kyokusen clock variant. 8)


Ternary operator, obviously something else I need to learn. I'll eventually get this scripting thing down.

And AWESOME Clock, really cool design. Only thing I think I'd change is to make it a little bigger for us aging folks. I've seen several clocks in these forums but I love the different approach and design. Very Cool. 8)

You're right about the no image gui being not worthless, I learned a lot from that project. Although that particular gui isn't very practical, but a good example of the concept. I think there would be times that the concept would be very handy. And it inspired my next project which I think is going to be just as cool but practical.

Thanks for the kind words.