# drawing using relative coordinates

• 07-27-2011
megafiddle
drawing using relative coordinates
Are there functions to draw using relative coordinates (relative to some starting point), as opposed to drawing to absolute coordinates?

Specifically, I need to draw an unfilled rectangle (frame) of fixed size at various positions.

I know how to draw them with absolute coordinates, just seems like there ought to be relative
versions.
• 07-27-2011
tabstop
I believe the solution is called a "variable".
Code:

```new_origin_x = 50; new_origin_y = 25; Function_That_Draws(new_origin_x+10, new_origin_y+20);```
Perhaps more seriously, since this is the Windows board, there are the coordinate systems Windows knows about: Types of Coordinate Systems (Windows)
• 07-27-2011
megafiddle
Thanks for the coordinate system link.

I realize that I can add the relative values to an absolute origin; that is what I am doing now.

I am wondering if there are functions where the origin is specified as absolutes, and the other
coordinates are relative to that origin.
• 07-27-2011
tabstop
Normally that's handled using transformations. I have no idea what you are actually using, but a search on transformations at MSDN got me Global and Local Transformations (Windows)
• 07-27-2011
megafiddle
Thanks again, but what I am wondering is something simpler. Also I am using only C, not C++.

For example, if I need a 20x20 square at location 500, 600, I would like to use:

x = 500, y = 600, rectangle(x, y, 20, 20),

not x = 500, y = 600, rectangle(x, y, x+20, y+20)

Of course, either I have to do the math or the function has to do the math, but the code is neater
if a function already handles the math.
• 07-27-2011
novacain
Look at SetViewportOrgEx and SetWindowOrgEx

The GDI Mapping Mode
• 07-29-2011
megafiddle
Thanks, all, for the info.

I can definitely use it, although it's not quite related to my question.

The msdn reference can be overwhelming and I can never be sure I've seen everything. It looks
like there are no relative drawing functions of the type I was wondering about.

No problem though. Can do things as I have been, it just would have been convenient.
• 07-30-2011
Quote:

Originally Posted by megafiddle
Can do things as I have been, it just would have been convenient.

Or you could just write your own functions...
• 07-31-2011
novacain
Quote:

Originally Posted by megafiddle
I can definitely use it, although it's not quite related to my question.

Prahaps you could rephrase your question then.

>> I need to draw an unfilled rectangle (frame) of fixed size at various positions.
Call SetViewportOrgEx() with the top left of the rectangle and then call FillRect() or Rectangle() with a rect 0, 0, width, height
• 08-22-2011
megafiddle
Well yes, but my current method is still simpler:

rectangle(x, y, x+20, y+20);