M
Michele Santucci
Hallo,
I have a small (hopefully) problem... I defined an user control that in the
Paint overriden method does the following things:
protected override void OnPaint( PaintEventArgs e )
{
e.Graphics.Clear( BackColor );
e.Graphics.SmoothingMode = _SmoothingMode;
e.Graphics.CompositingQuality = _CompositingQuality;
e.Graphics.InterpolationMode = _InterpolationMode;
e.Graphics.TextRenderingHint = _TextRenderingHint;
e.Graphics.TranslateTransform( Width / 2,Height / 2 );
e.Graphics.RotateTransform( -180 );
// Apply global transform paramenters
e.Graphics.RotateTransform( _Rotation );
e.Graphics.TranslateTransform( _XOffset,_YOffset );
e.Graphics.ScaleTransform( _Zoom,_Zoom );
//
_PaintBackground( e.Graphics );
_PaintForeground( e.Graphics );
e.Graphics.ResetTransform();
base.OnPaint( e );
}
This allow me to draw foreground and background graphic elements using just
_Rotation, _XOffset, _YOffset, _Zoom parameters to change the
'point-of-view' on the global scene.
Everything works fine but now I'm stuck with a problem ... I have to
retrieve the 'virtual' coordinate of a point on the viewport
corresponding to the actual mouse position.
The very first question is 'how do I do that?' ... the second one is
'where?'
I figured that the answer to the first question is to apply the same
transformations applied to the Graphic object
just to the location point defined by mouse position but I don't know how to
reply that...
The answer to the second is more difficult for me to figure out since, for
my knowledge the only place where the e.Graphics state is available is
inside the OnPaint method while the mouse position update is available
trough the OnMouseMove method ...
I think there's a pretty simple solution to this...
I have a small (hopefully) problem... I defined an user control that in the
Paint overriden method does the following things:
protected override void OnPaint( PaintEventArgs e )
{
e.Graphics.Clear( BackColor );
e.Graphics.SmoothingMode = _SmoothingMode;
e.Graphics.CompositingQuality = _CompositingQuality;
e.Graphics.InterpolationMode = _InterpolationMode;
e.Graphics.TextRenderingHint = _TextRenderingHint;
e.Graphics.TranslateTransform( Width / 2,Height / 2 );
e.Graphics.RotateTransform( -180 );
// Apply global transform paramenters
e.Graphics.RotateTransform( _Rotation );
e.Graphics.TranslateTransform( _XOffset,_YOffset );
e.Graphics.ScaleTransform( _Zoom,_Zoom );
//
_PaintBackground( e.Graphics );
_PaintForeground( e.Graphics );
e.Graphics.ResetTransform();
base.OnPaint( e );
}
This allow me to draw foreground and background graphic elements using just
_Rotation, _XOffset, _YOffset, _Zoom parameters to change the
'point-of-view' on the global scene.
Everything works fine but now I'm stuck with a problem ... I have to
retrieve the 'virtual' coordinate of a point on the viewport
corresponding to the actual mouse position.
The very first question is 'how do I do that?' ... the second one is
'where?'
I figured that the answer to the first question is to apply the same
transformations applied to the Graphic object
just to the location point defined by mouse position but I don't know how to
reply that...
The answer to the second is more difficult for me to figure out since, for
my knowledge the only place where the e.Graphics state is available is
inside the OnPaint method while the mouse position update is available
trough the OnMouseMove method ...
I think there's a pretty simple solution to this...