Solved

Simple CRectangle question

Posted on 2000-03-03
15
170 Views
Last Modified: 2013-11-20
Hi,
I have two CRectangle objects. When I draw those rectangles, one is inside the other. What I need to do is that after one rectangle is changed (either its dimensions or its position) the other one must change proportionally.
For instance, in every drawing program, if you draw two rectangles, one embedded in the other, and then you select both and group them, when you resize the group, both rectangles are resized in the same manner.

Any help?
0
Comment
Question by:elito
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 3
  • 2
  • +1
15 Comments
 
LVL 5

Expert Comment

by:Wyn
ID: 2580886
Pre-requisite:
We know the ratio in between.

First:
Get the size of the first CRect.
Second:
Get the Center Point of the first CRect.
Third:
Using the ratio in between to get the size of the second CRect correspondingly and cut x,y of the second size in half and substract Center Point by it respectively will give you the top-left point of the second.
Fourth:
Using the CRect( POINT point, SIZE size )to construct the second CRect.

Regards
W.Yinan
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2580914
If you already have the second.You can simply CopyRect to it...
0
 
LVL 3

Expert Comment

by:qocarlos
ID: 2580915
Hi W.Yinan,
Thanks for your help but, could you please give me source code?

Consider that I know all the parameters of Rect1 and Rect2 and that Rect1 is resized:

***********************Rect 1
*                     *
*                     *
*   ******* Rect2     *
*   *     *           *
*   *     *           *
*   *******           *
*                     *
*                     *
***********************

Thanks.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:Wyn
ID: 2580937
->Third:
Using the ratio in between to get the size of the second CRect correspondingly and
===============

ratio here means length-to-length(both  Y and X axis)ratio you want ,like 0.7(second/first) or so.You simple multiply it to the size of first...
(sorry for poor english)

Hope helpful.
Regards
W.Yinan

 
0
 

Author Comment

by:elito
ID: 2580948
sorry, I was using NT account of qocarlos.

Elito
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2580953
->Thanks for your help but, could you please give me source code?
===============
Here is 3:00am , I will try to now.
But not 100% tonight...
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2581030



 
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2581037
Opps, I misundertand a little.It's not similar rect and dont have the same certerpoint.
0
 
LVL 3

Expert Comment

by:qocarlos
ID: 2581111
Hi,


I have put in the following link an example of what I'm trying to do:

http://qomestre.usc.es/test.htm

cheers
0
 

Author Comment

by:elito
ID: 2581176
sorry I used again qocarlos account...
Im gonna have problems with him :-)

Elito
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2582508
http://qomestre.usc.es/test.htm
need some qualifications..
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2582545
btw:I think it's complex for free change and you should delete this question and ask again for more points to attract experts to help you.

Sincerely
W.Yinan
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 50 total points
ID: 2582946
I'm not sure if this is what you need (because I don't know how to login to the given URL), but here's a function which I think calculates what you need:

// pass the Rect1 before it was moved/resized as orgRect
// pass the Rect2 as refRect
// pass the Rect1 after it was moved/resized as newRect
// returns new Rect2
// (I'm using some float math here because I was too lazy to think about a more performant way without using floats)

CRect CalcRect( CRect orgRect, CRect refRect, CRect newRect )
{
 CRect newChildRect;

 float xAsp = newRect.Width() / (float)orgRect.Width();
 float yAsp = newRect.Height() / (float)orgRect.Height();
 CPoint offset( refRect.left - orgRect.left, refRect.top - orgRect.top );

 newChildRect.left = newRect.left + (int)( offset.x * xAsp );
 newChildRect.top = newRect.top + (int)( offset.y * yAsp );
 newChildRect.right = newChildRect.left + (int)( refRect.Width() * xAsp );
 newChildRect.bottom = newChildRect.top + (int)( refRect.Height() * yAsp );

 return newChildRect;
}

hope this helps,

ZOPPO
0
 

Author Comment

by:elito
ID: 2612760
Hi!
Sorry about the delay in getting back to you.
That was exactly what I needed! thanks

elito
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2612773
no problem     :)

have a nice day,

ZOPPO
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 54
Looking for a specific application/software 2 124
haveThree challenge 22 126
changeXy challenge 13 96
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 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