Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Detecting a Click on a line object
Message
 
À
12/08/2005 02:50:32
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 8 SP1
Divers
Thread ID:
01040465
Message ID:
01040491
Vues:
17
Yes, it is odd that certain black points are being logged to the debug output window. They shouldn't be. Perhaps it is a paint problem? I haven't found any logical errors in the code, nor have any been reported by users. Any thoughts?

Also, your addition does show another way (as you surmised) to handle this given a unique color for the lines. However, in the cases where I have used it I didn't have a unique color to rely on and sometimes the lines were invisible but I still needed to know whether the mouse was over them.

As for polypoint lines, I do not have code that can do that (code for almost everything else, but not that <g>)... though it could be done (made even easier by the fact that polypoints relies on percentages). Seems you will have to reinvent the wheel on this one, or use a unique color for your lines.

Thanks for posting the debug output code... I'll be looking into it further. If the code is failing in certain circumstances, I want to know.

>>This post definitely caught my eye... I've worked on a number of CAD and Construction Blueprint manipulation projects in Visual FoxPro and this is one of the things that really created some havoc the first time I ran into it (that and creating and shading irregular shapes - though Visual FoxPro 9 fixed that with the advent of the polypoints property). Anyways, the solution I came up with was not as hard as it first looked to figure out whether the mouse is over the line. Here's a working example... just cut-n-paste into a prg file and run it. Then pass your mouse over the lines and as the mouse is directly over the line it will change the line's color so you know that it's being detected. The important code is in the lineex class's mousemove event, just place that type of code in your line's mousedown event to decide whether the click is to be considered an "actual" click or not.
>>
>>
PUBLIC oform1
>>
>>oform1=NEWOBJECT("form1")
>>oform1.Show
>>RETURN
>>
>>DEFINE CLASS form1 AS form
>>
>>	DoCreate = .T.
>>	Caption = "Form1"
>>	Name = "Form1"
>>
>>	ADD OBJECT line1 AS lineex WITH ;
>>		BorderWidth = 3, ;
>>		Height = 156, ;
>>		Left = 60, ;
>>		Top = 48, ;
>>		Width = 132, ;
>>		Name = "Line1"
>>
>>	ADD OBJECT line2 AS lineex WITH ;
>>		BorderWidth = 3, ;
>>		Height = 120, ;
>>		Left = 204, ;
>>		Top = 24, ;
>>		Width = 156, ;
>>		LineSlant = "/", ;
>>		Name = "Line2"
>>ENDDEFINE
>>
>>DEFINE CLASS lineex as Line
>>
>>	PROCEDURE MouseMove
>>		PARAMETERS nButton, nShift, nXCoord, nYCoord
>>		LOCAL lnFullX, lnFullY, lnCurrentX
>>		lnFullX = this.Width
>>		lnFullY = this.height
>>		lnCurrentXPercentage = (nXCoord - this.Left)/lnFullX
>>
>>		IF This.LineSlant = "/"
>>			lnCurrentXPercentage = (1 - lnCurrentXPercentage)
>>		ENDIF
>>
>>		*!* Is mouse directly over the line?
>>		*!* if so, color it red
>>		IF BETWEEN((nYCoord - this.Top) / lnCurrentXPercentage, lnFullY - this.BorderWidth, lnFullY + this.BorderWidth)
>>			this.BorderColor = RGB(255,0,0)
>>		ELSE
>>			this.BorderColor = RGB(0,0,0)
>>		ENDIF
>>	ENDPROC
>>ENDDEFINE
>>
>>>I have a line object slanting from left to right (so the line object is kind of a square). Clicking anywhere on the object (even not on the actual line) causes the click event to fire. How would I be able to detect if the users actually clicked on the line part of the line object? Anybody have some suggestions.
>>>
>>>I need to do this becuase there are objects behind this line object that needs to respond to mouse events, I want to pass the event to those objects if the users did NOT click on the visible line.
>>>
>>>Thanks for any help.
>>>
>>>Scott
>
>Sorry Craig but ... i think a moment.
>Expected no debug message:
>
>PUBLIC oform1
>ACTIVATE WINDOW "debug output"
>
>oform1=NEWOBJECT("form1")
>oform1.Show
>RETURN
>
>DEFINE CLASS form1 AS form
>
>	DoCreate = .T.
>	Caption = "Form1"
>	Name = "Form1"
>
>	ADD OBJECT line1 AS lineex WITH ;
>		BorderWidth = 3, ;
>		Height = 156, ;
>		Left = 60, ;
>		Top = 48, ;
>		Width = 132, ;
>		Name = "Line1"
>
>	ADD OBJECT line2 AS lineex WITH ;
>		BorderWidth = 3, ;
>		Height = 120, ;
>		Left = 204, ;
>		Top = 24, ;
>		Width = 156, ;
>		LineSlant = "/", ;
>		Name = "Line2"
>ENDDEFINE
>
>DEFINE CLASS lineex as Line
>
>	PROCEDURE MouseMove
>		PARAMETERS nButton, nShift, nXCoord, nYCoord
>		LOCAL lnFullX, lnFullY, lnCurrentX
>		lnFullX = this.Width
>		lnFullY = this.height
>		lnCurrentXPercentage = (nXCoord - this.Left)/lnFullX
>
>		IF This.LineSlant = "/"
>			lnCurrentXPercentage = (1 - lnCurrentXPercentage)
>		ENDIF
>		*!* Is mouse directly over the line?
>		*!* if so, color it red
>		IF BETWEEN((nYCoord - this.Top) / lnCurrentXPercentage, lnFullY - this.BorderWidth, lnFullY + this.BorderWidth)
>			this.BorderColor = RGB(255,0,0)
>		ELSE
>			this.BorderColor = RGB(0,0,0)
>		ENDIF
>                * I don't owe I can be above to a black point
>		IF thisform.Point(m.nXCoord, m.nYCoord)=0
>			DEBUGOUT m.nXCoord, m.nYCoord
>		ENDIF	
>	ENDPROC
>ENDDEFINE
>
>This show the solution way, also :)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform