Page 2 of 2

Re: Owner-drawn buttons

Posted: Tue May 15, 2012 6:23 am
by Kukulkan
Hello,
Any chance for a MacOS adaption?
We will port our client to MacOS, too. If we are finished, I will update the source to work on MacOS, too. Like Bisonte said, it is only about the mouse pointer.

Kukulkan

Re: Owner-drawn buttons

Posted: Mon Jul 16, 2012 3:25 pm
by Kukulkan
Hi,

I just updated the initial post with the most recent code. I added rbutton_Hide() function to allow hiding and unhiding rbutton's. If you are using HideGadget() function of PB, the mouse-pointer will still get a hand if you are over such gadget. Using rbutton_Hide() fixes this.

Kukulkan

Re: Owner-drawn buttons

Posted: Wed Feb 06, 2013 3:30 pm
by MrPrimus
Hello,

I like your code, but I have a little problem

sample code

Code: Select all

; TEST AND EXAMPLE CODE
XIncludeFile "rbutton_include.pbi"

OpenWindow(0, 100, 200, 290, 50, "rButton test window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
SetWindowColor(0, RGB(255, 255, 255))
rbutton_SetFont("Arial", 9, #PB_Font_Bold | #PB_Font_Italic, RGB(255,255,255), -120)
rbutton_Init_OwnerDrawn(80, 30, GetWindowColor(0), RGBA(214,236,255,255), RGBA(0,220,255,255), RGBA(255,255,255,255), RGBA(60,225,137,255),5, 2)
Define regSmall1.i = rbutton_Create(#PB_Any, 0, "open", 10, 10, 0)
Define regSmall2.i = rbutton_Create(#PB_Any, 0, "infos", 105, 10, 0)
rbutton_Init_OwnerDrawn(80, 30, GetWindowColor(0), RGBA(236,214,214,255), RGBA(191,120,120,255), RGBA(255,255,255,255), RGBA(225,60,60,255),5, 2)
Define regSmall3.i = rbutton_Create(#PB_Any, 0, "Quit", 200, 10, 0)

Define Quit.i = 0

Repeat
	Define Event.i = WaitWindowEvent()

	If Event.i = #PB_Event_CloseWindow  ; If the user has pressed on the close button
		Quit.i = 1
	EndIf
	
	If Event.i = #PB_Event_Gadget
		If EventGadget() = regSmall1.i
		  File$ = OpenFileRequester("Chose a file", "C:\", "file txt|*.txt",1)
		EndIf
		If EventGadget() = regSmall2.i
		   MessageRequester("Infos","Dummy")
		EndIf
		If EventGadget() = regSmall3.i
		  Quit.i = 1
		EndIf
	EndIf
	
	rbutton_CheckHover(0)

Until Quit.i = 1

End

first click the save button for example, opens the window OpenFileRequester, close the window and move the cursor over the save button but do not click, the window opens again OpenFileRequester .

for such info button with a window MessageRequester

test on Windows Seven, not tested with Linux

I'm forgetting something in the code?

thank you

sorry for my bad english

Re: Owner-drawn buttons

Posted: Wed Feb 06, 2013 4:58 pm
by Kukulkan
Hi,

you are ignoring some basics: An event might be mouse over, left click, right click etc. In your case, you fire the requester on ALL events (even on mouse over). You should restrict this to left-click:

Code: Select all

; TEST AND EXAMPLE CODE
XIncludeFile "rbutton_include.pbi"
OpenWindow(0, 100, 200, 290, 50, "rButton test window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
SetWindowColor(0, RGB(255, 255, 255))
rbutton_SetFont("Arial", 9, #PB_Font_Bold | #PB_Font_Italic, RGB(255,255,255), -120)
rbutton_Init_OwnerDrawn(80, 30, GetWindowColor(0), RGBA(214,236,255,255), RGBA(0,220,255,255), RGBA(255,255,255,255), RGBA(60,225,137,255),5, 2)
Define regSmall1.i = rbutton_Create(#PB_Any, 0, "open", 10, 10, 0)
Define regSmall2.i = rbutton_Create(#PB_Any, 0, "infos", 105, 10, 0)
rbutton_Init_OwnerDrawn(80, 30, GetWindowColor(0), RGBA(236,214,214,255), RGBA(191,120,120,255), RGBA(255,255,255,255), RGBA(225,60,60,255),5, 2)
Define regSmall3.i = rbutton_Create(#PB_Any, 0, "Quit", 200, 10, 0)

Define Quit.i = 0
Repeat
   Define Event.i = WaitWindowEvent()

   ; I would do this before the handling. Depending on the used event you might want to have hover done before working.
   rbutton_CheckHover(0)

   If Event.i = #PB_Event_CloseWindow  ; If the user has pressed on the close button
      Quit.i = 1
   EndIf
   
   If Event.i = #PB_Event_Gadget
     Define EG.i = EventGadget()
     Define ET.i = EventType()
     If ET.i = #PB_EventType_LeftClick ; somebody clicked the button with left click
       Select EG.i
          Case regSmall1.i
            File$ = OpenFileRequester("Chose a file", "C:\", "file txt|*.txt",1)
          Case regSmall2.i
            MessageRequester("Infos","Dummy")
          Case regSmall3.i
            Quit.i = 1
       EndSelect
     EndIf
   EndIf
Until Quit.i = 1
End
Best

Kukulkan

Re: Owner-drawn buttons

Posted: Wed Feb 06, 2013 5:26 pm
by davido
Hi kukulkan,

Thanks very much for sharing this wonderful code. :D

Re: Owner-drawn buttons

Posted: Wed Feb 06, 2013 6:05 pm
by MrPrimus
Hi kukulkan,

Thank you for your quick response and your explanation, I'll be more careful in the future before asking a question so stupid :?.

I'm going read and reread the documentation PureBasic

Again, thank you for sharing your code

MrPrimus

Re: Owner-drawn buttons

Posted: Thu Feb 07, 2013 8:19 am
by Kukulkan
Hi Mr. Primus,
MrPrimus wrote:Hi kukulkan,
Thank you for your quick response and your explanation, I'll be more careful in the future before asking a question so stupid :?.
I dont wanted to sound bugged. Its absolutely ok to ask questions and I'm willing to help. It was not that stupid. No problem :-)

Best,

Kukulkan

Re: Owner-drawn buttons

Posted: Sun Jun 09, 2013 7:12 pm
by shaggy1969
Hi Kukulkan,

I love your rbutton Gadget. It's the best thing since sliced bread!!! Really Awesome, it gives my little app such a clean, stylish, modern and professional look and feel. However... :wink:

I am trying to add a start/stop toggle a button/s... the button (No icon, "start app" text) starts another app and while this app is running be replaced by a new button (icon, "stop app")

I can switch between hide and show between the two buttons using rbutton_Hide #True and #False. but if i place them over each other, as it were, the button flickers because there is confusion as to which button is getting the mouseover/hover event.

Is there a way to achieve this without the flicker, as it saves valuable space?

PS... it would be awesome if one could use the exact same visual effects other Gadgets, like Tabs of the PanelGadget and preferably not bound to a rectangle so that alpha channels/transparency can be used.

Re: Owner-drawn buttons

Posted: Mon Jun 10, 2013 6:38 am
by Kukulkan
Hi,

glad that you like it :mrgreen:

Sadly, I dont know the reason. I believe you can update the rbutton_Hide() function with some API (Windows: SendMessage_()) to make it work by disabling the whole gadget. If it does not help, you can try to update the rbutton_CheckHover() function. Maybe the problem is in there?

I'm currently in a big project and therefore I do not have the time to check this. Sorry.

Kukulkan