Jump to content
Developer Wiki and Function Reference Links ×

Is there a simple method to "mirror" (dupe & flip) a 2D object?


Recommended Posts

I'm trying to economize code, and figured I had a clever solution...

But it does not work, my procedures are lacking?I have not been able to ascertain how to simply "duplicate and mirror" a 2D object.

To explain, instead of making two, separate draw door by type routines, I figured "if the door is a double, just draw half and mirror it..."

the first part checks if it's a double-version and sets a couple variables:

FlipIt := FALSE;

If PDOORS = 'Double Door' then

begin

FlipIt := TRUE;

DoorWidth := (wRight/2);

End;

the procedure then draws the appropriate door, then duplicates itself...

PROCEDURE DrawSimpleHinged;

BEGIN

BeginGroup;

Rect(wLeft,wBottom-DoorWidth,wLeft+DoorThickness,wBottom);

Rect(WLeft,wBottom,wLeft+DoorWidth, wBottom+DoorThickness);

Oval(wLeft-.5",wBottom-.5",wLeft+.5",wBottom+.5");

ArcByCenter(wLeft,wBottom,DoorWidth,0,-90);

EndGroup;

If FLIPIT then

begin

FirstHalf := HDuplicate(LNewObj,DoorWidth,0);

SetSelect(FirstHalf); FlipHor;

End;

END; {DrawSimpleHinged}

...but, of course, this just flips the entire PIO, not the door-half.

Am I doing the handles wrong, or missing an obvious command?

I sure appreciate the help!

PS. other code critique welcome, I?m know I'm a n00b, feel free to school me!

?

Edited by AEChadwick
Link to comment

Objects inside of PIOs are not actually drawn (and therefore don't have a handle or exist to the LNewObject command) until the PIO refresh routine is done.

No way that I know of to get around this.

I think all (or at least most) of us have fought with this at some point as it would be so useful to be able to access the components inside the PIO.

Link to comment

Well, that's not entirely true. Objects within PIOs are added to the drawing structure as the code runs, so you can get a handle to them using LNewObj. There are a few objects that don't respon to LNewObj no matter where you create them. Search the forum for the Waldo method for a workaround. You're getting a handle directly from HDuplicate, so that's not an issue.

The gist of what Pat said is correct. Objects don't DRAW on screen until the code finishes, so you can't use any commands dependent on selection. In general you should avoid using and VS commands that use the selection instead of a handle. You should only use SetSelect as part of your UI -- if you want the user to see certain objects selected when your code finishes. There is a version of flip that uses a handle (can't recall it off the top of my head). Use that instead of FlipHor, and all should be fine.

If you really want to write efficient code, make the door creation section in to a sub-procedure that takes an integer as a variable (I call mine flipMult). Multiply evry X coordinate by flipMult. Set to 1 for the right half and -1 for the left half.

-Josh

Link to comment

Sorry but I tend to disagree with both. Objects do get a handle and are drawn as they are created. You do not see any change when the object has been created because the screen does not refresh until the code completes.

I have created tools with a loop structure and a redraw function within that would get called as I moved the cursor & reported the x,y position as text on the drawing. Also while debugging, I have terminated the code before it completes and any objects that have been created to that point will be drawn.

I also recall that in the beginning of VS most function calls operated on selected objects only as it has been with menu commands. Back then we relied on menu commands a lot since there was no equivalent functions. Over time, VS functions were added to operate on object handles as well.

Having said that and looking at the code, the problem I see is that when an object is created, it is automatically selected. When flipHor is called all the objects are selected and consequently, all the objects get flipped. Try it with "DSelectAll" before the creation of the second group object as in:

Begin

DSelectAll;

FirstHalf := HDuplicate(LNewObj,DoorWidth,0);

SetSelect(FirstHalf);

FlipHor;

End;

The other way of mirroring as Josh pointed out is to create the same object with the x,y coordinates in the opposite direction.

Link to comment

Miguel, you're fantastic!

I had just finished cobbling two routines as "flipmult" variations (had to get out the Pythagorean Theorem for part...), but I instantly abandoned them and plugged in that DSelectAll. It worked perfectly.

I had previously avoided DSelect, thunking it would drop the entire PIO... I should have experimented. Looks like everyone is learning valuable lessons today!

Thanks to everyone! I absolutely love posting here, everyone is always smart and helpful [unlike most of the rest of the internet].

?

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...