HighTechTalks DotNet Forums  

GDI

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss GDI in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Michele Santucci
 
Posts: n/a

Default GDI - 02-12-2010 , 02:59 PM






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...

Reply With Quote
  #2  
Old   
James Hahn
 
Posts: n/a

Default Re: GDI - 02-13-2010 , 03:43 PM






Your surmise about your first problem is correct. There's an example here:
http://www.bobpowell.net/graphicsstack.aspx

I think your second problem is related. You will not get the accumulated
transforms from the 'graphics state' in the paint event as you seem to be
implying - you will recreate the transforms from the parameters used to
create the original transforms. This can be created (or 'replayed') at any
point where you the mouse pointer coordinates are available to your, such as
MouseDown or MouseMove. There's nothing created in the Paint event that
isn't also available to you elsewhere from the same set of parameters used
to do the transformations in that event.

"Michele Santucci" <michele.santucci (AT) cdh (DOT) it> wrote

Quote:
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...

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.