Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GDI mapping modes

154 views
Skip to first unread message

Hans-J. Ude

unread,
Sep 6, 2010, 7:28:43 AM9/6/10
to
You can arrange a DC by SetWindowOrg/Ext and SetViewportOrg/Ext and
easily do scaling and mirroring that way. But I don't remember that any
rotation is supported. How about GDI+ ? If it's supported there, how
much effort is it to port existing code? I want to draw the same objects
alternatively 90° counter-clockwise. I want only the objects rotated,
not their positioning on screen.

TIA,
Hans

Mikel

unread,
Sep 6, 2010, 9:14:40 AM9/6/10
to

In GDI, you can rotate with ::SetWorldTransform or
CDC::SetWorldTransform. It's relatively easy. When I tried it, the
"only" problem I had was that I wanted to mirror one axis, and I got
all the texts mirrored too.

I think I got to work in GDI+ too, but I don't remember it well. It
was quite a long ago, and I stuck with GDI so I know much more GDI
than GDI+ now.

Hans-J. Ude

unread,
Sep 6, 2010, 10:51:11 AM9/6/10
to
Am 06.09.2010 15:14, schrieb Mikel:
> In GDI, you can rotate with ::SetWorldTransform or
> CDC::SetWorldTransform. It's relatively easy. When I tried it, the
> "only" problem I had was that I wanted to mirror one axis, and I got
> all the texts mirrored too.

Thanks for the info, i'll have a look.

Hans

Joseph M. Newcomer

unread,
Sep 6, 2010, 7:59:48 PM9/6/10
to
Note that SetWorldTransform only works if you do SetGraphicsMode to GM_ADVANCED. And MFC
doesn't have methods for the advanced APIs, so you have to rely on the (HDC) cast to
convert a CDC to an HDC, e.g.,

CDC dc(this);

::SetGraphicsMode(dc, GM_ADVANCED);

::SetWorldTransform(dc, rotate90);

Note that what rotates is the coordinate system, so you have to think carefully of the
consequences of the rotation. If you have a triangle that is bounded by (40, 40, 60, 60)
then when you rotate the coordinate system, the triangle will be drawn in the (virtual)
space above and to the left of the top corner of the visible window, e.g.,

###|###
###|###
###+-----
###| V
###|

where I'm letting 0, 0 remain at the top left corner; the rotating the axis 90 degrees
will result in the drawing

###| >
###|
###+----
###|###
###|###

so you have to essentially set the origin at the 0,0 point of where you want the object
drawn, draw the object relative to that point, and if rotated 90 degrees, you will have to
account for the transformation of the starting coordinate. So if I want to see

###|###
###|###
###+----
###| >
###|

then I need to rotate the relative axis 90 degrees, but start drawing the shape by
specifying the origin as the bottom left corner of its bounding box, instead of the top
left corner.

Rotation in and of itself is not sufficient; you have to make sure you have transformed
everything correctly. For example, if I set 0,0 to be the lower left corner of the window
(assuming the window is square) then I will draw, instead of (and * represents the 0,0
point)

###|###
###|###
###*----
###| V
###|Ox

the following

###|###
###|###
###+---
###| >x
###| O
###*

Then everything you draw (text, objects, etc.) are rotated 90 degrees.
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Hans-J. Ude

unread,
Sep 7, 2010, 4:48:46 AM9/7/10
to
Am 07.09.2010 01:59, schrieb Joseph M. Newcomer:

> Rotation in and of itself is not sufficient; you have to make sure you have transformed
> everything correctly. For example, if I set 0,0 to be the lower left corner of the window
> (assuming the window is square) then I will draw, instead of (and * represents the 0,0
> point)

I assumed that I had to specify a rotation point, regardless the
graphics system (GDI vs. GDI+). It's good to know that I can stay with GDI.

> Then everything you draw (text, objects, etc.) are rotated 90 degrees.

I assumed that too, that's what I don't want. In my particular case the
object to draw is a guitar chord symbol, my program generates a lot of
them. Usually the strings are vertical and frets are horizontal, that's
like I display them now. But when I browse the internet I see more and
more images which display them the other way round. So I thought it
would be comfortable to support both. (Maybe in an update...)

I have a function DrawChordObject (pDC, x, y, ...) anyway. x,y is the
upper left corner. I'll have to split that function into
DrawGraphics(...) and DrawDescription(...) I assume that
SaveDC/RestoreDC will switch back SetWorldTransform() too, right? I'll
figure out the details

Thanks Joe, your explanations were clear and comprehensive as usual.

Hans

Joseph M. Newcomer

unread,
Sep 7, 2010, 10:21:59 AM9/7/10
to
See below...

On Tue, 07 Sep 2010 10:48:46 +0200, "Hans-J. Ude" <ne...@s237965939.online.de> wrote:

>Am 07.09.2010 01:59, schrieb Joseph M. Newcomer:
>
>> Rotation in and of itself is not sufficient; you have to make sure you have transformed
>> everything correctly. For example, if I set 0,0 to be the lower left corner of the window
>> (assuming the window is square) then I will draw, instead of (and * represents the 0,0
>> point)
>
>I assumed that I had to specify a rotation point, regardless the
>graphics system (GDI vs. GDI+). It's good to know that I can stay with GDI.
>

****
I did a lot with this kind of transformation in my early years, but mostly in PostScript
programming. It does harbor surprises.
*****


>> Then everything you draw (text, objects, etc.) are rotated 90 degrees.
>
>I assumed that too, that's what I don't want. In my particular case the
>object to draw is a guitar chord symbol, my program generates a lot of
>them. Usually the strings are vertical and frets are horizontal, that's
>like I display them now. But when I browse the internet I see more and
>more images which display them the other way round. So I thought it
>would be comfortable to support both. (Maybe in an update...)

*****
No problem, just do the transformation "locally" when you draw that symbol. Again, the
key is to draw the symbol relative to a 0,0 axis and then set the origin so that under the
rotation you get what you expect. Note that SaveDC() and RestoreDC() are your New Best
Friends here.
*****


>
>I have a function DrawChordObject (pDC, x, y, ...) anyway. x,y is the
>upper left corner. I'll have to split that function into
>DrawGraphics(...) and DrawDescription(...) I assume that
>SaveDC/RestoreDC will switch back SetWorldTransform() too, right? I'll
>figure out the details

*****
Yes. See above comment.
joe
****


>
>Thanks Joe, your explanations were clear and comprehensive as usual.
>
>Hans

0 new messages