Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Detecting a Click on a line object
Message
De
12/08/2005 04:38:13
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 8 SP1
Divers
Thread ID:
01040465
Message ID:
01040500
Vues:
18
>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?
>

It is not so simple.

First point:
Add OBJTOCLIENT() for hierarchy support

The problems:
You compute on Real domain, but the line live on Integer ( pixels ) domain,
then:
1. VFP Rounding is ?
2. BorderWidth is the line width, but you use a 2*BorderWidth zone

This code is more precise for detect fails,
and if you resize the form to 2000X1000 pixels you can see it better.
On upper left corner you have many FALSE NEGATIVE,
On bottom righ corner you have many FALSE POSITIVE.
PUBLIC oform1
ACTIVATE WINDOW "debug output"

oform1=NEWOBJECT("form1")
oform1.Show
RETURN

DEFINE CLASS form1 AS form

	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"
	DESKTOP = .T.
	
	ADD OBJECT line1 AS lineex WITH ;
		ANCHOR = 15,;
		BorderWidth = 3, ;
		Height = THISFORM.height - 4, ;
		Left = 4, ;
		Top = 4, ;
		Width = THISFORM.Width - 4, ;
		Name = "Line1"
ENDDEFINE

DEFINE CLASS lineex as Line

	* this is a my wish routine for every visual baseclass, but VFPT ......
	PROCEDURE ObjectHitTest(nXCoord,nYCoord)
		IF		BETWEEN(m.nXCoord-OBJTOCLIENT(m.This,OBJTOCLIENT_LEFT)	,0,OBJTOCLIENT(m.This,OBJTOCLIENT_WIDTH) -1);
			AND BETWEEN(m.nYCoord-OBJTOCLIENT(m.This,OBJTOCLIENT_TOP)	,0,OBJTOCLIENT(m.This,OBJTOCLIENT_HEIGHT)-1)
			* check line
			* problem : Line is transparent !!!!
			* 
			IF thisform.Point(m.nXCoord, m.nYCoord)=m.This.BorderColor
				RETURN 1
			ENDIF
		ENDIF
		* none
		RETURN 0
	
	* the ObjectHitTest way
	PROCEDURE MouseMove
		PARAMETERS nButton, nShift, nXCoord, nYCoord
		*!* Is mouse directly over the line?
		*!* if so, color it red
		IF this.ObjectHitTest(nXCoord, nYCoord)
			this.BorderColor = RGB(255,0,0) 
		ELSE
			this.BorderColor = RGB(0,0,0) 
		ENDIF
		IF thisform.Point(m.nXCoord, m.nYCoord)=0
			DEBUGOUT m.nXCoord, m.nYCoord
		ENDIF	
	ENDPROC
	
	* your code
	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
		lineDetect= BETWEEN((nYCoord - this.Top) / lnCurrentXPercentage, lnFullY - this.BorderWidth, lnFullY + this.BorderWidth)
        DO CASE 
        	CASE lineDetect AND Thisform.Point(m.nXCoord, m.nYCoord)#0
        		DEBUGOUT "FALSE POSITIVE",m.nXCoord, m.nYCoord
        	CASE !lineDetect AND Thisform.Point(m.nXCoord, m.nYCoord)=0
        		DEBUGOUT "FALSE NEGATIVE",m.nXCoord, m.nYCoord
		ENDCASE
		
	ENDPROC

ENDDEFINE
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform