Board index » cppbuilder » TImage frame - rectangular selection area

TImage frame - rectangular selection area

Hi,
I am looking for a component, which implements the capability of drawing a
rectangular selection area on top of an image, where the rectangle can be
re-sized, re-positioned, and rotated - BUT in RUN-TIME.
It should be something very similar to inserting a TShape rectangle in
DESIGN TIME ,with the same features that show the "dots" on the
rectangle's limits when it is in focus - that enable the user to do
the re-sizing/re-positioning stuff with the mouse, but with an additional
capability of rotating (like the feature that is offered in
Power-Point/WORD).

Thanx in advance,
   yuval

 

Re:TImage frame - rectangular selection area


This code could do what you are looking for.
It needs a bit of work, though. It rotates the object around the Form's
origin (0,0)
so you can change that to make it rotate around its own center, instead.

POINT Poly1[5]  = {{100,100}, {200, 100}, {200, 200}, {100, 200},
{100,100}};
const POINT *pPoints1 = Poly1;

POINT PolyRot[5];
POINT* pPolyRot = PolyRot;

void Rotate(float x, float y, float alpha, POINT* p, int i)
{
    (p+i)->x = (int)(x * cos(2*3.141516*alpha)) - (y *
sin(2*3.141516*alpha));
    (p+i)->y = (int)(x * sin(2*3.141516*alpha)) + (y *
cos(2*3.141516*alpha));

Quote
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
       for (int i = 0; i< 5; i++)
       {
          Rotate(Poly1[i].x, Poly1[i].y, 1000, pPolyRot, i);
       }

       Polygon( Canvas->Handle, pPolyRot, 5);  //Win32 API

Quote
}

Rodolfo

Quote
"Yuval Nof" <yuv...@elbit.co.il> wrote in message

news:3e22c050$1@newsgroups.borland.com...
Quote
> Hi,
> I am looking for a component, which implements the capability of drawing a
> rectangular selection area on top of an image, where the rectangle can be
> re-sized, re-positioned, and rotated - BUT in RUN-TIME.
> It should be something very similar to inserting a TShape rectangle in
> DESIGN TIME ,with the same features that show the "dots" on the
> rectangle's limits when it is in focus - that enable the user to do
> the re-sizing/re-positioning stuff with the mouse, but with an additional
> capability of rotating (like the feature that is offered in
> Power-Point/WORD).

> Thanx in advance,
>    yuval

Re:TImage frame - rectangular selection area


Sorry about the second post. It was an error.

Rodolfo

Re:TImage frame - rectangular selection area


Thanx a lot, but...
What you suggest actually only gives me the mathematics of how to rotate a
shape on a canvas.
What I need is a RUN-time graphic object, that behaves just like a TShape
rectangle object or any other rectangular visual control on a BCB form -
during DESIGN time.
To clarify myself: During design time, when you use a form and drop a TShape
on it, whenever this TShape object on the form gets the focus (- after you
click the mouse within its area), it gets those dots along its limits - to
emphasize the focus, and in addition - whenever the mouse moves over its
edges, the mouse cursor turns into a "re-size" cursor and allows the
resizing. In addition, you can drag the object over the form using the
mouse.
So, Until now I haven't told you anything new, have I...?  :)

What I am looking for is an recangular object/component/anything - that
would supply the user with the SAME features of re-sizing & re-positioning
that I described, but during RUN-TIME. In addition, I need it to be able to
be rotated - once again, using the user's mouse events.

The purpose is having the capability of letting a user select a rectangular
area in an image, and updating this area in an easy & windows-conventional
way.

If you or anyone else can help me with this one - I would be grateful.

Quote
"Rodolfo Frino" <rodolfofr...@dodo.com.au> wrote in message

news:3e22d820$1@newsgroups.borland.com...
Quote
> The following code needs a bit of work but it could be
> what you are looking for.

> The square shape (Polygon1) rotates around the Form's origin, so you could
> change the Rotate function to achieve rotation around the object's center.

> POINT Poly1[5]  = {{100,100}, {200, 100}, {200, 200}, {100, 200},
> {100,100}};
> const POINT *pPoints1 = Poly1;

> POINT PolyRot[5];
> POINT* pPolyRot = PolyRot;

> void Rotate(float x, float y, float alpha, POINT* p, int i)
> {
>     (p+i)->x = (int)(x * cos(2*3.141516*alpha)) - (y *
> sin(2*3.141516*alpha));
>     (p+i)->y = (int)(x * sin(2*3.141516*alpha)) + (y *
> cos(2*3.141516*alpha));
> }

> void __fastcall TForm1::Button2Click(TObject *Sender)
> {
>        for (int i = 0; i< 5; i++)
>        {
>                Rotate(Poly1[i].x, Poly1[i].y, angle, pPolyRot, i);
>        }

>        // Draw Polygon
>        Polygon( Canvas->Handle, pPolyRot, 5);  //Win32 AP
> }

> Rodolfo

> "Yuval Nof" <yuv...@elbit.co.il> wrote in message
> news:3e22c050$1@newsgroups.borland.com...
> > Hi,
> > I am looking for a component, which implements the capability of drawing
a
> > rectangular selection area on top of an image, where the rectangle can
be
> > re-sized, re-positioned, and rotated - BUT in RUN-TIME.
> > It should be something very similar to inserting a TShape rectangle in
> > DESIGN TIME ,with the same features that show the "dots" on the
> > rectangle's limits when it is in focus - that enable the user to do
> > the re-sizing/re-positioning stuff with the mouse, but with an
additional
> > capability of rotating (like the feature that is offered in
> > Power-Point/WORD).

> > Thanx in advance,
> >    yuval

Re:TImage frame - rectangular selection area


This Rotation function is better

POINT Poly1[5]  = {{100,100}, {200, 100}, {200, 200}, {100, 200},
{100,100}};
POINT *pPoly1   = Poly1;

POINT Poly2[5];
POINT* pPoly2 = Poly2;

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    //Paint on the Form's Canvas Property
    //
    Canvas->Pen->Color = clRed;
    Polygon( Canvas->Handle, pPoly1, 5);  //Win32 API

Quote
}

//--------------------------------------------------------------------------
-

void CopyPoly(POINT* pDest, POINT* pSour, int NumberOfPoints)
{
// Copy Polygon

    for (int i = 0; i< NumberOfPoints; i++)
    {
        (pDest+i)->x = (pSour+i)->x;
        (pDest+i)->y = (pSour+i)->y;
    }

Quote
}

void Rotate(POINT* pin, POINT* pout, float alpha, long xr, long yr,
                    int NumberOfPoints)
{
// General Rotation Function
//Rotate Polygon about a given point P whose coordinates are (xr, yr)
// alpha should be entered in degrees

   float const K = 0.01745329;           // degrees to rad (2*PI/360)

    for (int i = 0; i< NumberOfPoints; i++)
    {
        (pout+i)->x = (long)( xr + (((pin+i)->x - xr) * cos(K*alpha))
                                 - (((pin+i)->y - yr) * sin(K*alpha)) );

        (pout+i)->y = (long)(yr + (((pin+i)->x - xr) * sin(K*alpha))
                                + (((pin+i)->y - yr) * cos(K*alpha)) );
    }

Quote
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
       // Rotate 22.5 degrees
       Rotate(pPoly1, pPoly2, 22.5, 150, 150, 5);

       // Display Polygon
       Polygon(Canvas->Handle, pPoly2, 5);  //Win32 API

       // In case we want to rotate the polygon over and over again
       CopyPoly(pPoly1, pPoly2, 5);

Quote
}

Rodolfo

Re:TImage frame - rectangular selection area


K should be negative -0.01745329

Rodolfo

Re:TImage frame - rectangular selection area


1- Choose the component that you want to use as your run-time graphics
object
(RT component). For example: TImage.

2- Use the Region functions (API's) to define a rectangular region on your
RT component
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/...
_6o6r.asp

3- Rotate the region to achieve rotation of your RT component. Suggestion:
Use the Rotation function that I posted earlier.

4- Use pRTcomponent->SetFocus() to set the focus on your RT component

5- Add the rest of the functionality as per your specs.

Note: I wrote simple example using two Region functions, which is at:
http://members.dodo.net.au/~rodolfofrino/RoundPanel.html

In your case you will need to use other Region functions to achieve what you
want.  Hope it helps.

Rodolfo

Quote
"Yuval Nof" <yuv...@elbit.co.il> wrote in message

news:3e23333b@newsgroups.borland.com...
Quote
> Thanx a lot, but...
> What you suggest actually only gives me the mathematics of how to rotate a
> shape on a canvas.
> What I need is a RUN-time graphic object, that behaves just like a TShape
> rectangle object or any other rectangular visual control on a BCB form -
> during DESIGN time.
> To clarify myself: During design time, when you use a form and drop a
TShape
> on it, whenever this TShape object on the form gets the focus (- after you
> click the mouse within its area), it gets those dots along its limits - to
> emphasize the focus, and in addition - whenever the mouse moves over its
> edges, the mouse cursor turns into a "re-size" cursor and allows the
> resizing. In addition, you can drag the object over the form using the
> mouse.
> So, Until now I haven't told you anything new, have I...?  :)

> What I am looking for is an recangular object/component/anything - that
> would supply the user with the SAME features of re-sizing & re-positioning
> that I described, but during RUN-TIME. In addition, I need it to be able
to
> be rotated - once again, using the user's mouse events.

> The purpose is having the capability of letting a user select a
rectangular
> area in an image, and updating this area in an easy & windows-conventional
> way.

> If you or anyone else can help me with this one - I would be grateful.

Re:TImage frame - rectangular selection area


Rodolfo , Thanx a lot!

Quote
"Rodolfo Frino" <rodolfofr...@dodo.com.au> wrote in message

news:3e235038@newsgroups.borland.com...
Quote
> 1- Choose the component that you want to use as your run-time graphics
> object
> (RT component). For example: TImage.

> 2- Use the Region functions (API's) to define a rectangular region on your
> RT component

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/...
Quote
> _6o6r.asp

> 3- Rotate the region to achieve rotation of your RT component. Suggestion:
> Use the Rotation function that I posted earlier.

> 4- Use pRTcomponent->SetFocus() to set the focus on your RT component

> 5- Add the rest of the functionality as per your specs.

> Note: I wrote simple example using two Region functions, which is at:
> http://members.dodo.net.au/~rodolfofrino/RoundPanel.html

> In your case you will need to use other Region functions to achieve what
you
> want.  Hope it helps.

> Rodolfo

> "Yuval Nof" <yuv...@elbit.co.il> wrote in message
> news:3e23333b@newsgroups.borland.com...
> > Thanx a lot, but...
> > What you suggest actually only gives me the mathematics of how to rotate
a
> > shape on a canvas.
> > What I need is a RUN-time graphic object, that behaves just like a
TShape
> > rectangle object or any other rectangular visual control on a BCB form -
> > during DESIGN time.
> > To clarify myself: During design time, when you use a form and drop a
> TShape
> > on it, whenever this TShape object on the form gets the focus (- after
you
> > click the mouse within its area), it gets those dots along its limits -
to
> > emphasize the focus, and in addition - whenever the mouse moves over its
> > edges, the mouse cursor turns into a "re-size" cursor and allows the
> > resizing. In addition, you can drag the object over the form using the
> > mouse.
> > So, Until now I haven't told you anything new, have I...?  :)

> > What I am looking for is an recangular object/component/anything - that
> > would supply the user with the SAME features of re-sizing &
re-positioning
> > that I described, but during RUN-TIME. In addition, I need it to be able
> to
> > be rotated - once again, using the user's mouse events.

> > The purpose is having the capability of letting a user select a
> rectangular
> > area in an image, and updating this area in an easy &

windows-conventional

- Show quoted text -

Quote
> > way.

> > If you or anyone else can help me with this one - I would be grateful.

Other Threads