[Implemented] CanvasGadget - mouse clicks

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

[Implemented] CanvasGadget - mouse clicks

Post 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).
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
graph100
Enthusiast
Enthusiast
Posts: 115
Joined: Tue Aug 10, 2010 3:17 pm

Re: CanvasGadget - mouse clicks

Post 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
_________________________________________________
My Website : CeriseCode (Warning : perpetual changes & not completed ;))
User avatar
Derren
Enthusiast
Enthusiast
Posts: 316
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: CanvasGadget - mouse clicks

Post by Derren »

User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: CanvasGadget - mouse clicks

Post by DoubleDutch »

Graph100: Thanks for the code

Derren: Thanks for the link

:)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
graph100
Enthusiast
Enthusiast
Posts: 115
Joined: Tue Aug 10, 2010 3:17 pm

Re: CanvasGadget - mouse clicks

Post by graph100 »

Speaking of custom Gadget, you can go see there : Custom gadget :mrgreen:
_________________________________________________
My Website : CeriseCode (Warning : perpetual changes & not completed ;))
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: CanvasGadget - mouse clicks

Post 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).
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
graph100
Enthusiast
Enthusiast
Posts: 115
Joined: Tue Aug 10, 2010 3:17 pm

Re: CanvasGadget - mouse clicks

Post 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)
_________________________________________________
My Website : CeriseCode (Warning : perpetual changes & not completed ;))
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: CanvasGadget - mouse clicks

Post by freak »

added for the next beta
quidquid Latine dictum sit altum videtur
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: CanvasGadget - mouse clicks

Post by DoubleDutch »

Thanks. :)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Post Reply