AutoHotkey Community

It is currently May 27th, 2012, 8:43 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: May 14th, 2006, 10:11 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Quote:
How to Simulate a Graphical Button in a GUI?
http://www.autohotkey.com/forum/viewtopic.php?p=59899#59899

Quote:
Foreword: This post is NOT about adding a Picture to a GUI Button.
If you are interested and want to know How to Create a Picture Button,
you may visit corrupt's post: Graphic Buttons


PART 1 : Efficiently using picture(s) to Simulate the Effect of Button Press.

A regular GUI Button is a 3D object. That is, the Button is displayed projected (in default state) and looks sunkenwhen depressed. The GUI Button remains sunken until you release the Mouse Button ( gLabel will not be executed unless the mouse button is released).

A Button has two states - ON ( Sunken ) / OFF ( Projected ) . Its obvious that we need two semi identical pictures to display the sunken & projected state of a button.

Do we always need two pictures to simulate a Button Press?

The answer is NO! In most cases a single picture would suffice.

Instead of the Projected & Sunken states of a Button I have attempted to simulate Flat & Sunken
states using a single ICON with the following code:
Code:
Gui, -Sysmenu +Toolwindow
Gui, Add , Picture, x13  y13 w32 h32 E0x200 vState1 icon1 , %A_AhkPath%
Gui, Add , Picture, x+10 y13 w34 h34 Border vState0 icon1 , %A_AhkPath%
Gui, Add, Text , x13 ,E0x200   Border
Gui, Show, x50 y50 AutoSize, Picture Options
Return

GuiEscape:
 ExitApp
Return
    Snapshot: Image
  • Have used Border in the Picture's option for drawing a thin border around the Flat Button
  • Have used an Extend Style E0x200 in the Picture's option for simulating the Sunken Button effect.
  • The default size of Icon is w32 h32, but Extend Style E0x200 increases the size of the Sunken Button
  • Flat button has been sized two pixels extra to match the size of Sunken Button.


    The following code overlaps the two Styles (of the same Icon) to simulate a Graphical Checkbox
Code:
; Toggle.ahk - Readymade code for a Graphical Checkbox

Gui, +Sysmenu +ToolWindow
Gui, Margin,12,12
Gui, Add , Picture, x13 y13 w32 h32 E0x200 vState1 icon1 gSubRoutine1, %A_AhkPath%
Gui, Add , Picture, x13 y13 w34 h34 Border vState0 icon1 gSubRoutine1, %A_AhkPath%
GoSub, Toggle_Switch

Gui, Show, x50 y50 AutoSize, Toggle
Return

Toggle_Switch:
If Toggle=0
  {
   GuiControl, Hide, State0
   GuiControl, Show, State1
   Toggle=1
  }
Else {
   GuiControl, Hide, State1
   GuiControl, Show, State0
   Toggle=0
  }
Return

SubRoutine1:
  GoSub,Toggle_Switch
;                     < - - - - - - - - P U T  Y O U R  C O D E  H E R E
Return

GuiEscape:
GuiClose:
 ExitApp
Return

      Snapshots: Image <-OFF/ON-> Image

    The following code overlaps the two Styles (of the same Icon) to simulate a Graphical Button.
Code:
;RegularButton.ahk - Readymade Code testing a Graphical Button
Gui, +Sysmenu +ToolWindow
Gui, Margin,12,12
Gui, Add , Picture, x13 y13 w34 h34 E0x200   vState1 icon1 gSubRoutine1, %A_AhkPath%
Gui, Add , Picture, x13 y13 w32 h32 0x400000 vState0 icon1 gSubRoutine1, %A_AhkPath%

Gui, Show, x50 y50 AutoSize, Button
Return

SubRoutine1:
   GuiControl, Hide, State0
   Sleep 250
   GuiControl, Show, State0
   Msgbox,                < - - - - - - - - P U T  T H E  M A I N  C O D E  H E R E
Return

GuiEscape:
GuiClose:
 ExitApp
Return

    Note: Unlike in a Graphical Checkbox, I have used 0x400000 to display the Graphical Button projected.

Quote:
How to Simulate a Graphical Button in a GUI?

PART 2 : An Advanced Technique - MPPS type Button


In PART ONE I wrote:
A regular GUI Button is a 3D object. That is, the Button is displayed projected (in default state) and looks sunken when depressed. The GUI Button remains sunken until you release the Mouse Button ( gLabel will not be executed unless the mouse button is released).


PART 1 dealt with the techniques in creating a Graphical Button / Graphical Checkbox and
we know that a Push button has two states : ON and OFF. Both the examples posted were
calling Subroutine1 which we could use as a Toggle switch.

In this PART, I am posting the resultant code of my experiment to simulate a third state.
The code demonstrates the detection of Button-Press duration of a Graphical button.


    In simple terms:

  • a Normal Mouse click on the Graphical button will be used to toggle a variable ( calls Subroutine1 ) , and
  • a Long Mouse click on the Graphical button will trigger a special routine ( calls Subroutine2 ).
Code:
; MPPS_Type_Button.ahk
;#InstallMouseHook

/*

- A Normal Click on the Graphical button will call Subroutine0
- A Long Click (Keep the "Left Mouse Button" down on the graphical button
  for 1 second) will trigger Subroutine1

*/

Gui, +Sysmenu +ToolWindow +AlwaysOnTop
Gui, Margin,12,12
Gui, Add , Picture, x13 y13 w32 h32 E0x200 vState1 icon1 gMPPS_Type_Button, %A_AhkPath%
Gui, Add , Picture, x13 y13 w34 h34 Border vState0 icon1 gMPPS_Type_Button, %A_AhkPath%
Gui, Show, x50 y50 AutoSize, MPPS

Return

MPPS_Type_Button:
  GuiControl Hide, State0
  TC := A_TickCount
  Loop, {
    MouseDown:=GetKeyState("LButton","P")
    If (!MouseDown) {
       LongClick=0
       Break
    }
    If (A_TickCount-TC) > 1000 {
       LongClick=1
       Break
        }
  }
  GuiControl Show, State0

  IfEqual,LongClick,1,GoSub,SubRoutine1
  else GoSub, SubRoutine0

Return

SubRoutine1:
 Msgbox,64, Subroutine1
,That was a Long Click..`n`nThis Subroutine may be used to execute a Special task, 10
Return

SubRoutine0:
 Msgbox,64, Subroutine0
,That was a Normal Click..`n`nThis Subroutine may be used to Toggle a Variable, 10
Return

GuiEscape:
GuiClose:
 ExitApp
Return

    • MPPS type button requires Mouse Hook (Windows NT/2000/XP or later)

Quote:
MPPS in MPPS type button stands for

Mobile Phone Power Switch

The Acronym that came to my mind when I applied the concept to a Graphical Button.

I do not know about international preferences for Mobiles,
but in India, 80% of the Mobiles are from Nokia and the function of its Power button is like follows:-

  • A Long press switches it ON

    and when ON
  • A Short press will show a Confirmation menu to switch it off
  • A Long press will switch it Off without confirmation.
I have mimicked this functionality for the Graphic Button.


Visit the following post for a Utility based on this concept.

Crazy Scripting : Muter v1.0 ( MPPS type Button )


Credits: Post by PhiLho @ Ask for Help Topic: Picture buttons.... by jsmain

Regards, :)

PS: Feedback please!

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Last edited by SKAN on June 16th, 2008, 7:28 am, edited 7 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 14th, 2006, 12:45 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
What is MPPS?

I tested the code in the first part, it is excellent! I like the sunken effect done without using two pictures. Very good idea!
The second part I will test later, because I think it won't work on Win98 (I am on my old computer right now).

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 14th, 2006, 1:13 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Dear PhiLho, :)

You wrote:
I tested the code in the first part, it is excellent! I like the sunken effect done without using two pictures. Very good idea!


Thanks! :D. I did refer your post http://www.autohotkey.com/forum/viewtopic.php?p=52707#52707
and forgot to give credit. :( (It took me more than 5 hours to compile this post, and it slipped off my mind!).
Now, I have edited the post & have given the credit.

You wrote:
The second part I will test later, because I think it won't work on Win98 (I am on my old computer right now).


I await your valuable opinion on the MPPS type Button. :)

Regards, :)


Last edited by SKAN on June 16th, 2008, 7:29 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 14th, 2006, 6:23 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
You can simulate button up/down effects also with GroupBoxes.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 15th, 2006, 9:18 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Goyyah wrote:
I await your valuable opinion on the MPPS type Button. :)
Not much to say, it offers an interesting functionnality, and it works well. I still don't know what is MPPS...

Note on lines: you can make them with a Picture element, using a one pixel image (or 2/3 pixels for shadow effects). I still have to study how to use an image defined in the script without writing it to disk.

Side-note: I think this topic belongs more to the Scripts & Functions section, this one is for topics slightly outside AHK's realm (external utilities that can be used with AutoHotkey). What do you think?

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 15th, 2006, 10:06 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Dear PhiLho, :)

You wrote:
Not much to say, it offers an interesting functionnality, and it works well. I still don't know what is MPPS...


:D. I have particularly not replied it - means there is an Unread PM lying in your inbox :D

You wrote:
Note on lines: you can make them with a Picture element, using a one pixel image (or 2/3 pixels for shadow effects). I still have to study how to use an image defined in the script without writing it to disk.


I am aware of that technique.

You wrote:
I think this topic belongs more to the Scripts & Functions section, this one is for topics slightly outside AHK's realm (external utilities that can be used with AutoHotkey). What do you think?


Quote:
Ask for Help
Ask questions and (hopefully) get answers. Post helpful tips and tricks.


Or maybe in the above section? :D
I will have to bump the topic two/three times a day to keep it in the first page.

I am still learning AHK & whenever I come out with interesting things, I want to post it under one topic. And I want this topic to be easily accessible so that it does not get lost in this ocean of posts.

Not everybody can search successfully. Especially, when they cannot put in words of what they have in mind. Don`t you agree?

I leave it to Mr.Chris to decide where this topic should be.

Regards, :)


Last edited by SKAN on June 16th, 2008, 7:29 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 15th, 2006, 1:36 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Goyyah wrote:
You wrote:
Not much to say, it offers an interesting functionnality, and it works well. I still don't know what is MPPS...


:D. I have particularly not replied it - means there is an Unread PM lying in your inbox :D
? Oh, you sent a Private Message. I have no access to my private mailbox during the day, and I fail to see the "You have 1 new message" link in the forum. :-P
OK, you made up this abbreviation. But it is fine, you can "disclose it", I think, it is a smart and useful use of graphic buttons.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group