Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using SetMapMode()

Posted on 1998-05-11
5
Medium Priority
?
603 Views
Last Modified: 2013-11-20
I would like to change the default map mode, so that my coordinates do this;
  X increases to the right.
  Y increases upward. (instead of default downward).

I use this to set the map mode to MM_ISOTROPIC:
mode      = pDC->SetMapMode( MM_ISOTROPIC );

But, now how do I specify that I want my Y to increase upward, and my X to increase to the right, and my 0,0 origin to be at some other position in the window?


0
Comment
Question by:gunn
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:mikeblas
ID: 1309712

CRect rect;
GetWindowRect(&rect);

pDC->SetWindowExt(1, 1);
pDC->SetViewportExt(1, -1);
pDC->SetWindowOrg(0, 0);
pDC->SetViewportOrg(0, rect.bottom);


0
 

Author Comment

by:gunn
ID: 1309713
I stuck that code you put in my OnDraw() function; but it didn't work at all. In fact, my line I had drawn and showing, didn't show up after I stuck that in there.

You did not explain your code and why, so I am unable to figure out what is going on, to try and fix it. I'd like to learn too, not just plug in some code I don't understand.

So, if you can explain what should be happening here, and why its not for me, I'd appreciate it.

The SetWindowExt() would return values like (254,-254) and the SetViewportExt() would rturn values like (96,96). So putting in (1,1) and (1,-1) doesn't make quite sense..but I don't know what the 254 and 96 mean either so.........

?
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1309714
You'll find that I answered the question as specifically as you asked it. You asked how, and I showed you; you didn't say you wanted to know why, too.

You didn't tell me what kind of window you're using, for example: are you doing this in a CView, or in a CScrollView?  In what kind of window have you written your code?  That your calls return non-identity values makes it sound like you're writing the code for a CScrollView, and CScrollView is incompatible with MM_ISOTROPIC and MM_ANISOTROPIC.

Have you set any other mapping mode elsewhere in your application? Did the view you're deriving from do it for you?

Mapping modes work by converting one set of coordinates (logical coordinates) to another set of coordinates (device coordinates). In MM_TEXT, device coordinates and logical coordinates are exactly the same.

In other mapping modes, a translation happens. Device coordinates always have (0,0) at the top left, and assign higher x- and y- values to each pixel on the way to the right and down, respectively.

When you call GDI routines, you always supply logical coordinates. If you're translating, you use these formuas:

Dx = ((Lx - WOx) * VEx / WEx) + VOx
Dy = ((Ly - WOy) * VEy / WEy) + VOy

where:
Dx and Dy are the device X- and Y-coordinates drawn to after your translation.
Lx and Ly are the logical X- and Y-coordinates supplied by your call to whatever GDI routine you're using
WOy and WOx are the window x- and y- origins you gave to SetWindowOrg()
WEx and WEy are the window x- and y-extents you gave to SetWindowExt()
VEx and VEy are the viewport x- and y-extents you gave to SetViewportExt()
VOx and VOy are the viewport x- and y-extents you gave to SetViewportOrg()

So, if you code:

// CFlipView derives from CScrollView
void CFlipView::OnDraw(CDC* pDC)
{
   CFlipDoc* pDoc = GetDocument();
   ASSERT_VALID(pDoc);

   CRect rect;
   GetClientRect(rect);

   pDC->SetMapMode(MM_ANISOTROPIC);

   pDC->SetWindowExt(1, 1);
   pDC->SetViewportExt(1, -1);
   pDC->SetWindowOrg(0, 0);
   pDC->SetViewportOrg(0, rect.bottom);

   pDC->MoveTo(rect.TopLeft());
   pDC->LineTo(rect.CenterPoint());
   pDC->LineTo(rect.right, rect.top);
}

you'll end up with a chevron instead of a "v" because the Y-axis is flipped and the logical origin is set to the bottom left.

If you plug the numbers into the formulas I gave, you'll understand why.

.B ekiM

0
 
LVL 11

Accepted Solution

by:
mikeblas earned 150 total points
ID: 1309715
Whoops!  That's an answer, not a comment.

.B ekiM
0
 

Author Comment

by:gunn
ID: 1309716
Thanks a lot. That explanation and sample code got me on the right track and I got my code working the way I wanted it to now.

btw, its a CFormView based app, with no scrolling. I'm using MM_ISOTROPIC, to change the y-coord where it's positive upward. You can see the app (if you're curious) at http://www.radix.net/~gunn/hangar_gunnsite.html
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question