Board index » cppbuilder » GradientFill array of Rects ?

GradientFill array of Rects ?


2007-12-30 12:10:11 AM
cppbuilder48
Hi
When I look at GradientFill at
msdn2.microsoft.com/en-us/library/ms532348.aspx
They say: An array of GRADIENT_RECT structures in rectangle mode.
But they also say:
In GRADIENT_FILL_RECT_V mode, two endpoints describe a rectangle.
I have tried the code below, but I only get the first rectangle
painted with the colors from the last rectangle.
Am I doing something wrong or does it only work with one rectangle ??
Thanks in advance
Asger
void __fastcall TAjBmp::MsnPipeFillGradient(TRect &Rct, TAjColor &Cl1, TAjColor &Cl2,
bool Vertical)
{
int Part3W = Rct.Width()/3;
int Part3H = Rct.Height()/3;
int WMindt = Vertical ? Rct.Right : Rct.Left + Part3W;
int HMindt = Vertical ? Rct.Top + Part3H : Rct.Bottom;
TRIVERTEX vert[4] ;
GRADIENT_RECT gRect[2];
vert [0] .x = Rct.Left;
vert [0] .y = Rct.Top;
vert [0] .Alpha = 0x0000;
vert [0] .Red = Cl2.Cl16Red;//0x0000;
vert [0] .Green = Cl2.Cl16Green;//0x0000;
vert [0] .Blue = Cl2.Cl16Blue;//0x8800;
vert [1] .x = WMindt;
vert [1] .y = HMindt;
vert [1] .Red = Cl1.Cl16Red;//0x2700;
vert [1] .Green = Cl1.Cl16Green;//0xCE00;
vert [1] .Blue = Cl1.Cl16Blue;//0xFE00;
vert [1] .Alpha = 0x0000;
Cl2.MsnBugFix(Cl1, Rct.Height());
vert [2] .x = WMindt;
vert [2] .y = HMindt;
vert [2] .Red = Cl1.Cl16Red;//0x2700;
vert [2] .Green = Cl1.Cl16Green;//0xCE00;
vert [2] .Blue = Cl1.Cl16Blue;//0xFE00;
vert [2] .Alpha = 0x0000;
vert [3] .x = Rct.Right;
vert [3] .y = Rct.Bottom;
vert [3] .Red = Cl2.Cl16Red;//0x0000;
vert [3] .Green = Cl2.Cl16Green;//0x0000;
vert [3] .Blue = Cl2.Cl16Blue;//0x8800;
vert [3] .Alpha = 0x0000;
gRect[0].UpperLeft = 0;
gRect[0].LowerRight = 1;
gRect[1].UpperLeft = 2;
gRect[1].LowerRight = 3;
if(Vertical)
GradientFill(FDcHandle, vert, 4, gRect, 2, GRADIENT_FILL_RECT_V);
else GradientFill(FDcHandle, vert, 4, gRect, 2, GRADIENT_FILL_RECT_H);
}
//---------------------------------------------------------------------------
 
 

Re:GradientFill array of Rects ?

Asger Joergensen < XXXX@XXXXX.COM >wrote:
Quote

When I look at GradientFill at
msdn2.microsoft.com/en-us/library/ms532348.aspx
They say: An array of GRADIENT_RECT structures in rectangle mode.
That is in error. For the pMesh member, it should say that
depending on dwMode, pMesh points to either a GRADIENT_RECT
or a GRADIENT_TRIANGLE - not an array of them.
~ JD
 

Re:GradientFill array of Rects ?

JD wrote:
Quote
Asger Joergensen < XXXX@XXXXX.COM >wrote:
>When I look at GradientFill at
>msdn2.microsoft.com/en-us/library/ms532348.aspx
>They say: An array of GRADIENT_RECT structures in rectangle mode.

That is in error. For the pMesh member, it should say that
depending on dwMode, pMesh points to either a GRADIENT_RECT
or a GRADIENT_TRIANGLE - not an array of them.

~ JD

Here's some sample code that I finally got working, thanks to many in
this group.
DC
// Used to place color value into the high-order byte of the
// Color16 type
#define ByteToColor16(b) (((COLOR16)(b)) << 8)
//---------------------------------------------------------------------------
void __fastcall TMainForm::wmPaintMessage(TMessage &Msg)
{
TRect clRect = Image1->ClientRect;
int startColor = ColorToRGB(clBlue);
int endColor = ColorToRGB(clBlack);
TRIVERTEX vert[2] = {0};
GRADIENT_RECT gRect;
vert[0].x = clRect.Left;
vert[0].y = clRect.Top;
vert[0].Red = ByteToColor16(GetRValue(startColor));
vert[0].Green = ByteToColor16(GetGValue(startColor));
vert[0].Blue = ByteToColor16(GetBValue(startColor));
vert[0].Alpha = 0x0000;
vert[1].x = clRect.Right;
vert[1].y = clRect.Bottom;
vert[1].Red = ByteToColor16(GetRValue(endColor));
vert[1].Green = ByteToColor16(GetGValue(endColor));
vert[1].Blue = ByteToColor16(GetBValue(endColor));
vert[1].Alpha = 0x0000;
gRect.UpperLeft = 0;
gRect.LowerRight = 1;
GradientFill(Image1->Canvas->Handle,
vert, 2,
&gRect, 1,
GRADIENT_FILL_RECT_V
);
TForm::Dispatch(&Msg);
} //End wmPaintMessage()
 

{smallsort}