How can I replace the buttons in your newest example with png images files?
Here is the replacement code for the button graphics.
Replace these two functions ( and edit the paths to your images in the "AddControls" function ).
I wrote out the two buttons in different ways so that you can get a better sense of how things work. You can pick either approach, or a combo of both ( As is the case with the main window object [ Gui1 ] ).
Code: Select all
;###################################################################
AddControls( Gui1 ){
Gui1.Controls := {}
Gui1.Handles := []
;**********************************************
;**********************************************
Gui1.Controls.Button_1 := { X: 10 , Y: 10 , W: 100 , H: 100 , Function: "ToggleState" , DefaultImage: Gdip_CreateBitmapFromFile( "Default.png" ) , HoveredImage: Gdip_CreateBitmapFromFile( "Hover.png" ) , PressedImage: Gdip_CreateBitmapFromFile( "Pressed.png" ) , DefaultImage_Sel: Gdip_CreateBitmapFromFile( "Default.png" ) , HoveredImage_Sel: Gdip_CreateBitmapFromFile( "Hover.png" ) , PressedImage_Sel: Gdip_CreateBitmapFromFile( "Pressed.png" ) }
;**********************************************
;**********************************************
Gui1.Controls.Button_2 := {} ;create an associative array ( hearafter called an object unless specified )
cc := Gui1.Controls.Button_2 ;cc is now the same object as the button object. acting on one is the same as acting on the other.
cc.X := 120 ;adding a new property ( key: [ x ] ) and assigning a value to it
cc.Y := 10
cc.W := 100
cc.H := 100
cc.Function := "ToggleState"
cc.DefaultImage := Gdip_CreateBitmapFromFile( "Default.png" )
cc.HoveredImage := Gdip_CreateBitmapFromFile( "Hover.png" )
cc.PressedImage := Gdip_CreateBitmapFromFile( "Pressed.png" )
cc.DefaultImage_Sel := Gdip_CreateBitmapFromFile( "Default_Sel.png" )
cc.HoveredImage_Sel := Gdip_CreateBitmapFromFile( "Hover_Sel.png" )
cc.PressedImage_Sel := Gdip_CreateBitmapFromFile( "Pressed_Sel.png" )
;**********************************************
;**********************************************
for k , v in Gui1.Controls {
cc := Gui1.Controls[ k ]
Gui, % Gui1.Hwnd ":Add" , Text , % "x" cc.X " y" cc.Y " w" cc.W " h" cc.H " hwndhwnd"
cc.Hwnd := hwnd
cc.Name := k
Gui1.Handles[ hwnd ] := cc
bd := Func( cc.Function ).Bind( Gui1 , hwnd )
GuiControl, % Gui1.Hwnd ":+G", % hwnd , % bd
}
}
;###################################################################
DrawWindow( Gui1 ){
Gui1.ClearWindow()
for k , v in Gui1.Controls { ;loop through all of the radio controls
cc := Gui1.Controls[ k ]
if( k = Gui1.SelectedControl ){
if( k = Gui1.PressedControl ){
; [ Selected and pressed ]
;Replace with your button ( same for below ).
;Set "dispose" to zero so that you can use this image over and over.
;Set "AutoUpdate" to zero so that everything can get drawn before the window updates with the new graphics.
This.Gui1.DrawBitmap( cc.PressedImage_Sel , { X: cc.X , Y: cc.Y , W: cc.W , H: cc.H } , dispose := 0 , AutoUpdate := 0 )
}else if( k = Gui1.HoveredControl ){
; [ Selected and hovered ]
This.Gui1.DrawBitmap( cc.HoveredImage_Sel , { X: cc.X , Y: cc.Y , W: cc.W , H: cc.H } , 0 , 0 )
}else{
; [ Selected and default ]
This.Gui1.DrawBitmap( cc.DefaultImage_Sel , { X: cc.X , Y: cc.Y , W: cc.W , H: cc.H } , 0 , 0 )
}
}else{
if( k = Gui1.PressedControl ){
; [ Pressed ]
This.Gui1.DrawBitmap( cc.PressedImage , { X: cc.X , Y: cc.Y , W: cc.W , H: cc.H } , 0 , 0 )
}else if( k = Gui1.HoveredControl ){
; [ Hovered ]
This.Gui1.DrawBitmap( cc.HoveredImage , { X: cc.X , Y: cc.Y , W: cc.W , H: cc.H } , 0 , 0 )
}else{
; [ Default ]
This.Gui1.DrawBitmap( cc.DefaultImage , { X: cc.X , Y: cc.Y , W: cc.W , H: cc.H } , 0 , 0 )
}
}
}
Gui1.UpdateWindow()
}
how can I make clicking the button run a specific routine?
For example,
Click Button 1, Send 1
Click Button 2, Send 2
That's not how radio controls normally work.
You would usually try to preform an action and look to see if a radio is selected or not.
If I wanted to make it so that if the first button is toggled on, when I press the up arrow key it would move my cursor to 100*100
If the first button isn't toggled, pressing the up arrow key would do whatever it normally would.
Code: Select all
;###################################################################
#If ( Gui1.SelectedControl = "Button_1" ) ;Defines the start of a context sensitive hotkey / hotstrings section.
Up::
MouseMove, 100 , 100
return
#If ;end of section
;###################################################################
Or if I wanted to use it in another label
Code: Select all
;###################################################################
SomeOtherLabelTriggeredBySomethingElse:
;You can also use a "Switch/Case" *See Docs*
if( Gui1.SelectedControl = "Button_1" ){
msgbox, Hello World
}else if( Gui1.SelectedControl = "Button_2" ){
Tooltip, Hello World
}else{
SoundBeep, 500 , 500
}
return
;###################################################################
If on the other hand you are trying to toggle another image or window or something like that and want the action to take place right away, then all you need to do is either add a gosub to the toggleState label, or edit in what you want to do directly to the toggle label.
Another thing that you can do is have a different function for each of the radios. ( i.e. change the function for them in "AddControls()" )
Example:
Code: Select all
;###################################################################
AnotherLabel:
msgbox, in the label
return
;###################################################################
ToggleState( Gui1 , hwnd ){
SetTimer, WatchLeaveHover , Off
sleep, 60
Gui1.Busy := 1
cc := Gui1.Handles[ hwnd ]
Gui1.PressedControl := cc.Name
DrawWindow( Gui1 )
While( GetKeyState( "LButton" , "P" ) )
Sleep, 30
MouseGetPos,,,, ctrl , 2
Gui1.PressedControl := ""
if( ctrl = hwnd ){
if( cc.Name = Gui1.SelectedControl ){
Gui1.SelectedControl := ""
Gui1.HoveredControl := cc.Name
;Nothing is currently selected. If I want to hide something or whatever I would add that here.
;*** Depending on what I need to happen, I would add this before or after the two lines above***
}else{
;One of the two radios are selected.
Gui1.SelectedControl := cc.Name
Gui1.HoveredControl := cc.Name
if( Gui1.SelectedControl = "Button_1" ){
MsgBox, Hello World
;This will call up the other label, execute the code in that label and then jump back here and then go to the next line and continue.
goSub, AnotherLabel
}else if( Gui1.SelectedControl = "Button_2" ){
SoundBeep
;This will allow this current thread to finish before calling a new thread via the timer.
SetTimer, AnotherLabel , -60
}
}
}else{
;This happens if you press a button but move your cursor away from the button before releasing your mouse. i.e. cancel the action.
Gui1.HoveredControl := ""
}
;Where you place these next 3 lines has to do with whether or not the action takes a long time to do or the order you want things to take place in.
;You may want to draw the window before your action. i.e. do the next three lines before you call the label.
DrawWindow( Gui1 )
Gui1.Busy := 0
SetTimer, WatchLeaveHover , 60
}
;###################################################################
Thank you, I tried to figure this out myself without asking for further help but I've hit another wall
I hope that helps.
If you have any other questions feel free to ask.