Canvas and MouseArchives Forums/BlitzPlus Programming/Canvas and Mouse
| Hello, 1 big problem:|
How can I check if my mouse ( MouseX(canvaswindow) ) is within the canvas?
I have a picture as canvas on my gui. Now I want to pic a color from this image. When I hit the mousebutton anywhere on the gui my function to pic color is starting up. It should only start up when the mouse is within the canvas and the mousebutten hit. I hope you understand what I mean :-)
| Hi, In checking with events with waitevent, use $205 and $206 events to see if you are "in" or "out" any given canvas. Use EventSource to find which canvas you are entering or leaving. Here, you can simply set global flags to specify if the mouse is "in" or "out" any given canvas where as you can make sure when you hit the mousebutton that your 'pic color' function will only get called when supposed to.|
below is sort of pseudo code on checking if the mouse has entered or exited any canvas:
;$205 - Mouse enter
;Generated when the mouse pointer enters a canvas gadget.
DebugLog "enter MainCanvas"
DebugLog "enter ColorPickerCanvas"
;$206 - Mouse leave
;Generated when the mouse pointer leaves a canvas gadget.
DebugLog "exit MainCanvas"
DebugLog "exit ColorPickerCanvas"
Hope this helps...
| Yes, it works, but i had to create a second canvas as background. Is there an other way? Sure not or?|
| Are you intially using one canvas for everything? If so, then you just check a rectangular region around your image and see if the mouse position is inside or outside of that region.|
Or... do you have a seperate canvas for this image you want to pick colors from? If so, using the pseudo method I shown above should work for you.
You said you had to create a second canvas as a background? Did you use a second canvas for your image to pick color from before I replied the first time?
| If you are only using one canvas and just want to check to see if your mouse is over your image that is on that canvas, you can do something like this:|
If (MouseX(canvaswindow)>ImageX) And (MouseY(canvaswindow)>ImageY) And (MouseX(canvaswindow)<(ImageX+ImageWidth)) And (MouseY(canvaswindow)<(ImageY+ImageHeight))
| This will work. when the $201 'mouse clicked' event occurs just check that the event source is the canvas as well:|
Case $201 ; mouse clicked
mx=MouseX(canvas) : gy=MouseY(canvas)
If EventData()=1 ;lmb
;;; LEFT BUTTON CLICKED IN CANVAS
If EventData()=2 ;rmb
;;; RIGHT BUTTON CLICKED IN CANVAS
| OK, I'll testing both variations ... :-) ... |