Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Any function to draw gradient color?
|
|
Re: Any function to draw gradient color? [message #8196 is a reply to message #8140] |
Sat, 17 February 2007 15:24   |
mobilehunter
Messages: 87 Registered: November 2006
|
Member |
|
|
Hi Mirek,
This is my code modified from msdn examples. Hope i did the correct way. Btw where do you use GradientColor function?
edited: Ah sorry my code only fill to rectangular shape
void DrawRect(Draw& w,Rect rectClient,Color fromColor,Color toColor,int level)
{
Rect rectFill; // Rectangle for filling band
float fStep; // How large is each band?
int iOnBand; // Loop index
// Determine how large each band should be in order to cover the
// client with 256 bands (one for every color intensity level)
fStep = (float)rectClient.bottom / level*1.0f;
// Start filling bands
for (iOnBand = 0; iOnBand < level; iOnBand++)
{
// Set the location of the current band
rectFill.Set(rectClient.left,rectClient.top+(int)(iOnBand * fStep),
rectClient.right,rectClient.top+(int)((iOnBand+1) * fStep));
w.DrawRect(rectFill, GradientColor(fromColor,toColor,iOnBand,level));
}
}
example usage:
DrawRect(w,Rect(10,10,70,80),Yellow(),Black(),256);
[Updated on: Sat, 17 February 2007 15:30] Report message to a moderator
|
|
|
Re: Any function to draw gradient color? [message #11382 is a reply to message #8196] |
Mon, 10 September 2007 19:07   |
piratalp
Messages: 26 Registered: September 2007 Location: Argentina
|
Promising Member |
|
|
mobilehunter wrote on Sat, 17 February 2007 11:24 | Hi Mirek,
This is my code modified from msdn examples. Hope i did the correct way. Btw where do you use GradientColor function?
edited: Ah sorry my code only fill to rectangular shape
void DrawRect(Draw& w,Rect rectClient,Color fromColor,Color toColor,int level)
{
Rect rectFill; // Rectangle for filling band
float fStep; // How large is each band?
int iOnBand; // Loop index
// Determine how large each band should be in order to cover the
// client with 256 bands (one for every color intensity level)
fStep = (float)rectClient.bottom / level*1.0f;
// Start filling bands
for (iOnBand = 0; iOnBand < level; iOnBand++)
{
// Set the location of the current band
rectFill.Set(rectClient.left,rectClient.top+(int)(iOnBand * fStep),
rectClient.right,rectClient.top+(int)((iOnBand+1) * fStep));
w.DrawRect(rectFill, GradientColor(fromColor,toColor,iOnBand,level));
}
}
example usage:
DrawRect(w,Rect(10,10,70,80),Yellow(),Black(),256);
|
There is a much easier way for drawing a gradient:
void DrawGradient(Draw &w, Rect r, Color c1, Color c2)
{
int i;
for (i = r.top; i <= r.bottom; i++)
w.DrawLine(i, r.left, i, r.right, GradientColor(c1, c2, i - r.Top, r.Height());
}
That's all
NOTE: I've just wrote it in seconds from what's in my mind, I've done a Ribbon Chameleon Skin for Ultimate++ that can render both Office 2003 and Office 2007 styles with any combination of colors, I would like to contribute it to Ultimate++ but I'll have to add some code to Chameleon to support very basic things like Palettes and also change some widgets that have no ChPaint calls, how can I stay in synch with development version (uvs?)? Mirek?
Regards, Mauricio
|
|
|
Re: Any function to draw gradient color? [message #12039 is a reply to message #8140] |
Tue, 09 October 2007 14:13   |
nixnixnix
Messages: 415 Registered: February 2007 Location: Kelowna, British Columbia
|
Senior Member |
|
|
Hi Mirek,
I'm very interested in the idea of being able to draw to the alpha channel. How is this accomplished please? Obviously, my preference would be to be able to specify a Color as Color(R,G,B,A) and then draw shapes with varying transparency.
You say that it is possible to draw a shape into the alpha channel using ImageDraw. Do you mean ImageMaskDraw and even then, how is this done please?
It would be great to be able to use your drawing functions such as DrawPolyPolygon() with varying transparency. Failing that, if one could specify an ImageDraw object as entirely transparent and then draw shapes using Colors of varying transparencies, that would be just as good.
Nick
[Updated on: Tue, 09 October 2007 14:46] Report message to a moderator
|
|
|
Re: Any function to draw gradient color? [message #12043 is a reply to message #12039] |
Tue, 09 October 2007 15:23   |
mrjt
Messages: 705 Registered: March 2007 Location: London
|
Contributor |
|
|
I obviously don't know as much about this as Mirek, but in the interests of a quick answer I'll tell you what I know and he can correct me later 
As I understand the only way of drawing to the alpha channel is using DrawImage. You can create an image in the usual ways or, if you want to draw primitives with an alpha channel Mirek suggests something like:
virtual void Paint(Draw& draw)
{
draw.DrawRect(GetSize(), SColorFace());
ImageDraw img(200, 100);
img.Alpha().DrawRect(0, 0, 200, 100, Color(128, 0, 0));
img.Alpha().DrawText(0, 0, "This is the alpha channel", StdFont(), Color(0, 0, 0));
img.DrawRect(0, 0, 200, 100, Red());
draw.DrawImage(1, 1, img);
}
Note that:
- The alpha channel is initially all 0 (hence the first DrawRect above)
- When drawing to Alpha(), only the red channel is used for the alpha value.
If you only want alpha gradients you may want to look at CreateHorzFadeOut/HorzFadeOut (I believe the second caches the created image).
James
|
|
|
|
|
Goto Forum:
Current Time: Sun May 11 12:13:38 CEST 2025
Total time taken to generate the page: 0.00866 seconds
|