AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

change color if mouse is above text (like a menu or button)

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Mon Feb 22, 2010 1:56 pm    Post subject: change color if mouse is above text (like a menu or button) Reply with quote

I made this script and it works ok.
But there should be a better way.

This is what it does:
If your mouse position is above the text it changes the text color(like in a menu or button).
And the text functions as a buttons.


Code:
Gui +LastFound -Caption Border
Gui, Color, Black, Black

Gui, Font, S10 cWhite, Comic Sans MS
Gui, Add, Text, gReload x2 y2 w80 h20 , Reload
Gui, Add, Text, gPauze x2 y22 w80 h20 , Pauze
Gui, Add, Text, gSuspend x2 y42 w80 h20 , Suspend

Gui, Show,  w80 h63, MenuOptions

GoSub Position
Return



Position:
if WinActive("ahk_class AutoHotkeyGUI")
CoordMode, Mouse, Relative ;get mouse position
Loop
{
; get the position of the text
   MouseGetPos, VarX, VarY
   
   ;-------------------------
   If VarX between 2 and 80
      TempX = 1
   Else
      TempX = 0
   ;--------------
   If VarY between 2 and 21
      TempY = 1
   Else if VarY between 22 and 41
      TempY = 2
   Else if VarY between 42 and 62
      TempY = 3
   Else
      TempY = 0
   ;-------------------------
   
   If (TempX = 1 and TempY = 1)
   {
      Gosub  TReload ; mouse is above the text Reload
   }
   Else if (TempX = 1 and TempY = 2)
   {
      Gosub TPauze ; mouse is above the text Pauze
   }
   Else if (TempX = 1 and TempY = 3)
   {
      Gosub TSuspend ; mouse is above the text Suspend
   }
   Else
   {
      Gosub TOutside ; mouse is not above any text (only usefull if there are other things in the gui)
   }
}

Return



TReload:
Gui, Font, S10 cYellow, Comic Sans MS
GuiControl, Font, Reload  ;change color yellow

Gui, Font, S10 cWhite, Comic Sans MS
GuiControl, Font, Pauze ;change color white

Gui, Font, S10 cWhite, Comic Sans MS
GuiControl, Font, Suspend ;change color white
Return

TPauze:
Gui, Font, S10 cYellow, Comic Sans MS
GuiControl, Font, Pauze

Gui, Font, S10 cWhite, Comic Sans MS
GuiControl, Font, Suspend

Gui, Font, S10 cWhite, Comic Sans MS
GuiControl, Font, Reload
Return

TSuspend:
Gui, Font, S10 cYellow, Comic Sans MS
GuiControl, Font, Suspend

Gui, Font, S10 cWhite, Comic Sans MS
GuiControl, Font, Pauze

Gui, Font, S10 cWhite, Comic Sans MS
GuiControl, Font, Reload
Return

TOutside:
Gui, Font, S10 cWhite, Comic Sans MS
GuiControl, Font, Suspend

Gui, Font, S10 cWhite, Comic Sans MS
GuiControl, Font, Pauze

Gui, Font, S10 cWhite, Comic Sans MS
GuiControl, Font, Reload
Return



Reload:
   Reload
Return

Suspend:
   Suspend
Return

Pauze:
   Pause
Return



So my question is how can i make the code shorter and less noobish?
Ideas or example's are welcome.
Back to top
polyethene



Joined: 11 Aug 2004
Posts: 5248
Location: UK

PostPosted: Mon Feb 22, 2010 4:44 pm    Post subject: Reply with quote

There is no need to make changes if you wrote the code and feel comfortable with it.

If however you're interested in some tips here is one suggestion: GUI fonts can be combined like so -

Code:
TOutside:
Gui, Font, S10 cWhite, Comic Sans MS
GuiControl, Font, Suspend
GuiControl, Font, Pauze
GuiControl, Font, Reload
Return

_________________
GitHubScriptsIronAHK Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
closed



Joined: 07 Feb 2008
Posts: 509

PostPosted: Tue Feb 23, 2010 8:49 am    Post subject: Reply with quote

I played around with this idea of changing text color when mouse_over and stumbled on a problem when using event mouse tracking.

It works well until you put a g-label then sometimes it does not work and you have to move the mouse a bit over the text.

I removed the g-labels except on pause text.You can see the difference moving over suspend or reload text and the pause text that has a g-label.

Does anyone sees the origin of the problem?

Code:
Gui +LastFound  -Caption +Border
Gui, Color, Black, Black
Gui, Font, S10 cWhite, Comic Sans MS
Gui, Add, Text,  x2 y2 w80 h20 , Reload
Gui, Add, Text,  x2 y22 w80 h20 vpause gpause, Pause
Gui, Add, Text,  x2 y42 w80 h20 , Suspend
Gui, Show,  w80 h63, MenuOptions
handle:=winexist()

list=static1,static2,static3

OnMessage(0x200,"OnMouseMove")
OnMessage(0x2A3,"OnMouseLeave")
VarSetCapacity(TME,16,0), NumPut(16,TME,0), NumPut(2,TME,4), NumPut(handle,TME,8)

Return


OnMouseMove( wParam, lParam, Msg ) {
   Global
   DllCall( "TrackMouseEvent","uint",&TME )
   MouseGetPos, ,,foundhandle,controlvar
   ToolTip, %controlvar%
   Gosub, setcolor
return
}

setcolor:
stringSplit, change,list,`,
Loop %change0%
{
control:=change%A_Index%

if (control = controlvar)
{
Gui, Font, S10 cYellow, Comic Sans MS
GuiControl, Font, %controlvar% 
}
else
{
Gui, Font, S10 cwhite, Comic Sans MS
GuiControl, Font, %control% 
}
}
return



OnMouseLeave() {
  Global
  Gui, Font, S10 cwhite, Comic Sans MS
  GuiControl, Font, %controlvar% 
return
}

pause:
MsgBox, ,,pause,2
return

suspend:
MsgBox, ,,suspend,2
return
Back to top
View user's profile Send private message
Guest






PostPosted: Wed Feb 24, 2010 10:59 pm    Post subject: Reply with quote

thank you for the reply's

althoug i dont understand al the code in yume's script jet.
so i cant help you with the origin of the problem..

bye
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group