Board index » cppbuilder » Need line clipping method

Need line clipping method

I am going to use LineTo() function to draw a line.  is there a line
clipping method to use with this function
thnx.
 

Re:Need line clipping method


Hi Frank,

Quote
> I am going to use LineTo() function to draw a line.  is there a line
> clipping method to use with this function

You can use a clipping region to limit the extent of your drawing to a certain
region.   The goal is to first create a region defining where you want to allow
output.  This can be a rectangle, ellipse, or any complex shape.  Next, use the
SelectClipRgn() API function to set the clipping region of your target device
context.  Here's an example...

//in header...
    HRGN HClipRgn;

//in source...
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
    HClipRgn = CreateRectRgn(0, 0, 100, 100);

Quote
}

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
    DeleteObject(HClipRgn);

Quote
}

void __fastcall TForm1::Button2Click(TObject *Sender)
{
    Canvas->MoveTo(0, 0);
    Canvas->Pen->Width = 10;
    Canvas->Pen->Color = clBlue;

    SelectClipRgn(Canvas->Handle, HClipRgn);    
    Canvas->LineTo(Width, Height);

Quote
}

HTH.

--------------------------------------
Damon Chandler

http://bcbcaq.freeservers.com
Answers to <Commonly Asked Questions>

Other Threads