TIA,
Hans
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.
Thanks for the info, i'll have a look.
Hans
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
> 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
>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