Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Any function to draw gradient color?
Any function to draw gradient color? [message #8139] Mon, 12 February 2007 09:53 Go to next message
mobilehunter is currently offline  mobilehunter
Messages: 87
Registered: November 2006
Member
Does Ultimate++ have direct function to draw gradient colour inside shape?

Thanks
Re: Any function to draw gradient color? [message #8140 is a reply to message #8139] Mon, 12 February 2007 10:43 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
No.

The simple way how to achieve that is using Image (generate gradient inside Image, then draw Image).

If you want shape, use ImageDraw to draw shape into alpha channel of Image.

Mirek
Re: Any function to draw gradient color? [message #8196 is a reply to message #8140] Sat, 17 February 2007 15:24 Go to previous messageGo to next message
mobilehunter is currently offline  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 Go to previous messageGo to next message
piratalp is currently offline  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 Go to previous messageGo to next message
nixnixnix is currently offline  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 Go to previous messageGo to next message
mrjt is currently offline  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 Smile

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
Re: Any function to draw gradient color? [message #12045 is a reply to message #12039] Tue, 09 October 2007 15:27 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, no, Color is considerd a color only, no alpha involved (besides Null value).

Anyway, pixels of images are always RGBA structs - all you need is there...

Usually, you use ImageBuffer to make alpha things.

You can however use ImageDraw as well. The trick is that Alpha() method returns you another draw; everything you draw into R channel will become alpha of final Image. A little bit dirty, but cheap to implement and quite easy to use.

(But keep in mind that ImageDraw is generally just cheap solution for simple problems...)

Mirek
Re: Any function to draw gradient color? [message #12190 is a reply to message #12045] Tue, 16 October 2007 23:22 Go to previous message
nixnixnix is currently offline  nixnixnix
Messages: 415
Registered: February 2007
Location: Kelowna, British Columbia
Senior Member
Thanks JT and Mirek,

Not had time to try this yet but it all seems straight forward.

Cheers,

Nick
Previous Topic: Image zoom widget?
Next Topic: Bug in Picture Class
Goto Forum:
  


Current Time: Thu Mar 28 13:30:00 CET 2024

Total time taken to generate the page: 0.01331 seconds