Page 1 of 1

[Implemented] CanvasGadget - mouse clicks

Posted: Sun Aug 14, 2011 10:59 am
by DoubleDutch
It would be good for the canvas gadget to get mouseclick and doubleclick events - this way you can make a custom gadget react properly for a doubleclick. (some users may change the speed of double-clicks).

Re: CanvasGadget - mouse clicks

Posted: Sun Aug 14, 2011 11:48 am
by graph100
I wonder if it could be add. Because of the mouse up event, and the mouse down event, the click is decomposed into 2 events. Doing a third one would be a pretty time loss.
Just add something ^^ :

check the debugger output for the image gadget and the canvasgadget : it react in the same way :

Code: Select all

If OpenWindow(0, 0, 0, 400, 300, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
	CanvasGadget(0, 10, 10, 380, 135, #PB_Canvas_Keyboard)
	ImageGadget(1, 10, 155, 380, 135, 0)
	
	StartDrawing(CanvasOutput(0))
	Box(0, 0, GadgetWidth(0), GadgetHeight(0), 0)
	StopDrawing()
	
Else
	End
EndIf


Repeat
	event = WaitWindowEvent()
	
	If event = #PB_Event_Gadget
		Select EventGadget()
			Case 0
				Select EventType()
					Case #PB_EventType_MouseEnter
						Mouse_button_had_been_down = #False
						
					Case #PB_EventType_LeftButtonDown
						Mouse_button_had_been_down = #True
						
					Case #PB_EventType_LeftButtonUp
						If Mouse_button_had_been_down
							Mouse_button_had_been_down = #False
							
							If ElapsedMilliseconds() - Mouse_button_double_click_time < 200 ; <----- HERE ajust the Double click time
								;{ DOUBLE CLICK
								
								Debug "CANVASGADGET : double click"
								; for a double click you just add a counter !
								
								;}
								
							EndIf
							Mouse_button_double_click_time = ElapsedMilliseconds()
							
							;{ CLICK
							
							Debug "CANVASGADGET : click"
							
								; here you it's has if the user had clicked !!
								; you can even specifie a timeout for the click, and other parameters.
							
							;}
							
						EndIf
						
						
						
				EndSelect
				
				
			Case 1
				Select EventType()
					Case #PB_EventType_LeftClick
						Debug "IMAGEGADGET : click"
					Case #PB_EventType_LeftDoubleClick
						Debug "IMAGEGADGET : Double click"
						
				EndSelect
				
				
		EndSelect
	EndIf
	
Until event = #PB_Event_CloseWindow

End

Re: CanvasGadget - mouse clicks

Posted: Sun Aug 14, 2011 12:59 pm
by Derren

Re: CanvasGadget - mouse clicks

Posted: Sun Aug 14, 2011 1:05 pm
by DoubleDutch
Graph100: Thanks for the code

Derren: Thanks for the link

:)

Re: CanvasGadget - mouse clicks

Posted: Sun Aug 14, 2011 2:40 pm
by graph100
Speaking of custom Gadget, you can go see there : Custom gadget :mrgreen:

Re: CanvasGadget - mouse clicks

Posted: Sun Aug 14, 2011 4:55 pm
by DoubleDutch
Graph100: That's a great link. Thanks. :)

It's a shame that the PB scrollbars don't give live event data as this would have made it so that you didn't have to use custom ones in the 'custom gadget' code (in the link).

Re: CanvasGadget - mouse clicks

Posted: Sun Aug 14, 2011 5:59 pm
by graph100
yes, that's a shame, but with that I can tweak my gadget too the extreme ;)
this would allow to create entire UI with the same colour theme. If someone is motivated enough, the look of the gadget can easily be redesigned :mrgreen:
because the operating is separated of the look.

even though it is in French, I hope you find it interesting ^^. In the beginning I started coding and wrote the comment in French, but It's quite difficult to think in a another language.
Maybe, when I would have advance a little more, I will translate all the comments French / English.
If you have any suggestion, please post them, even in English ;) I'm pretty reluctant to post on the English forum with a code not too advanced. (And maintaining 2 post about the same subject is pretty tiring)

Re: CanvasGadget - mouse clicks

Posted: Wed Aug 17, 2011 10:01 pm
by freak
added for the next beta

Re: CanvasGadget - mouse clicks

Posted: Wed Aug 17, 2011 10:25 pm
by DoubleDutch
Thanks. :)