I am trying to draw a gradient in a rectangle using cairomm. I found the code below which helped a lot. My problem is I want to turn this rectangle into a progress bar. Is there a way to modify the code so that it at a certain percentage of the bar the gradient only shows in that length of the bar. also the gradient needs to not be the stop and start colors, but needs to be the start color to color in the gradient corresponding to the percentage of the rectangles length. How would I go about doing this? These would be used in a automotive application that I have been developing.
// Create the context for the widget
Cairo::RefPtr<Cairo::Context> context = get_window()->create_cairo_context();
...
// Rectangle
double x0 = 0.0;
double y0 = 0.0;
double x1 = 100.0;
double y1 = 100.0;
// Colors
Gdk::Color start_color( "blue" );
Gdk::Color end_color( "midnight blue" );
// Create the linear gradient diagonal
Cairo::RefPtr< Cairo::LinearGradient > background_gradient_ptr = Cairo::LinearGradient::create (
x0, y0, x1, y1);
// Set grandient colors
background_gradient_ptr->add_color_stop_rgb (0,
start_color.get_red_p(), start_color.get_green_p(), start_color.get_blue_p());
background_gradient_ptr->add_color_stop_rgb (1,
end_color.get_red_p(), end_color.get_green_p(), end_color.get_blue_p());
// Draw a rectangle and fill with gradient
context->set_source (background_gradient_ptr);
context->rectangle (x0, y0, x1, y1);
context->fill();