 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
qyte Guest
|
Posted: Wed Mar 16, 2005 10:23 am Post subject: TShape??? |
|
|
although TShape icon shows a triangle it does not seem to support it.
Does anyone know how i can put a triangle shape into a form?
Is the triangle supported or not?
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Wed Mar 16, 2005 10:41 am Post subject: Re: TShape??? |
|
|
qyte <gyte (AT) vivodinet (DOT) gr> wrote:
| Quote: |
[...] Does anyone know how i can put a triangle shape into a form?
|
Yes. However, design considerations need to take into account
the object used so that the drawing is static. For example, if
you draw directly on the form and an object is placed over the
form or the form is minimized and restored, the drawing will
not be redrawn unless you account for those possibilties.
| Quote: | Is the triangle supported or not?
|
Yes. Look at TCanvas::Polygon. BTW, TShape is a TCanvas
decendant so it probably has that method available.
~ JD
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Mar 16, 2005 7:40 pm Post subject: Re: TShape??? |
|
|
"JD" <nospam (AT) nospam (DOT) com> wrote
| Quote: | Yes. Look at TCanvas::Polygon. BTW, TShape is a
TCanvas decendant so it probably has that method available.
|
TShape does not derive from TCanvas. It derives from TGraphicControl, which
has a Canvas property.
Gambit
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Mar 16, 2005 7:53 pm Post subject: Re: TShape??? |
|
|
"qyte" <gyte (AT) vivodinet (DOT) gr> wrote
| Quote: | although TShape icon shows a triangle it does not seem to
support it.
|
As you have already noticed, TShape does not support triangles.
| Quote: | Does anyone know how i can put a triangle shape into a form?
|
You will have to create the triangle yourself manually. One way to do that
is to derive a new component from TShape and add Triangle support to it.
For example (untested):
enum TMyShapeType {mstNone, mstTriangle};
class TMyShape : public TShape
{
private:
TMyShapeType FMyShape;
void __fastcall SetMyShape(TMyShapeType Value);
protected:
void __fastcall Paint();
public:
__fastcall TMyShape(TComponent *Owner);
__published:
__property TMyShapeType MyShape = {read=FMyShape, write=SetMyShape,
default=mstNone};
};
__fastcall TMyShape::TMyShape(TComponent *Owner)
: TShape(Owner), FMyShape(mstNone)
{
}
void __fastcall TMyShape::SetMyShape(TMyShapeType Value)
{
if( FMyShape != Value )
{
FMyShape = Value;
Invalidate();
}
}
void __fastcall TMyShape::Paint()
{
if( FMyShape == mstTriangle )
{
Canvas->Pen = TShape::Pen;
Canvas->Brush = TShape::Brush;
int X = (Canvas->Pen->Width / 2);
int Y = X;
int W = (Width - Canvas->Pen->Width);
int H = (Height - Canvas->Pen->Width);
TPoint pts[3];
pts[0] = Point(X + (W / 2), Y);
pts[1] = Point(X, Y + H);
pts[2] = Point(X + W, Y + H);
Canvas->Polygon(pts, 2);
}
else
TShape::Paint();
}
Gambit
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Thu Mar 17, 2005 1:11 am Post subject: Re: TShape??? |
|
|
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote:
| Quote: |
TShape does not derive from TCanvas.
|
I was thinking of TChart (which derives from TPanel) but that
was incorrect as well.
~ JD
|
|
| Back to top |
|
 |
qyte Guest
|
Posted: Sat Mar 19, 2005 9:12 am Post subject: Re: TShape??? |
|
|
Remy Lebeau (TeamB) wrote:
| Quote: |
enum TMyShapeType {mstNone, mstTriangle};
class TMyShape : public TShape
{
private:
TMyShapeType FMyShape;
void __fastcall SetMyShape(TMyShapeType Value);
protected:
void __fastcall Paint();
public:
__fastcall TMyShape(TComponent *Owner);
__published:
__property TMyShapeType MyShape = {read=FMyShape, write=SetMyShape,
default=mstNone};
};
__fastcall TMyShape::TMyShape(TComponent *Owner)
: TShape(Owner), FMyShape(mstNone)
{
}
void __fastcall TMyShape::SetMyShape(TMyShapeType Value)
{
if( FMyShape != Value )
{
FMyShape = Value;
Invalidate();
}
}
void __fastcall TMyShape::Paint()
{
if( FMyShape == mstTriangle )
{
Canvas->Pen = TShape::Pen;
Canvas->Brush = TShape::Brush;
int X = (Canvas->Pen->Width / 2);
int Y = X;
int W = (Width - Canvas->Pen->Width);
int H = (Height - Canvas->Pen->Width);
TPoint pts[3];
pts[0] = Point(X + (W / 2), Y);
pts[1] = Point(X, Y + H);
pts[2] = Point(X + W, Y + H);
Canvas->Polygon(pts, 2);
}
else
TShape::Paint();
}
Gambit
|
The above code works fine. i added another property so that i can
draw the triangle in another direction.
Do you know which are the basic steps for adding an OnClick event
to this component? I found a tutorial in www.thebits.org but it talks
about non visual components and is too long. Apart from that i don't
think that it fits the case. Anyway if you know it would be great.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|