本文整理汇总了C++中cairo::RefPtr::set_source_rgb方法的典型用法代码示例。如果您正苦于以下问题:C++ RefPtr::set_source_rgb方法的具体用法?C++ RefPtr::set_source_rgb怎么用?C++ RefPtr::set_source_rgb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cairo::RefPtr
的用法示例。
在下文中一共展示了RefPtr::set_source_rgb方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
/** Drawing event handler. */
virtual bool
on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
switch (_curShape) {
case SHAPE_RECTANGLE:
cr->rectangle(20, 20, 200, 100);
cr->set_source_rgb(0, 0.8, 0);
cr->fill_preserve();
break;
case SHAPE_ELLIPSE:
cr->arc(150, 100, 90, 0, 2 * 3.14);
cr->set_source_rgb(0.8, 0, 0);
cr->fill_preserve();
break;
case SHAPE_TRIANGLE:
cr->move_to(40, 40);
cr->line_to(200, 40);
cr->line_to(120, 160);
cr->line_to(40, 40);
cr->set_source_rgb(0.8, 0, 0.8);
cr->fill_preserve();
cr->set_line_cap(Cairo::LINE_CAP_ROUND);
cr->set_line_join(Cairo::LINE_JOIN_ROUND);
break;
}
cr->set_line_width(3);
cr->set_source_rgb(0, 0, 0);
cr->stroke();
return true;
}
示例2: draw_sim_data
//Lots of this function needs to be optimised, including the pixbuf/bitmap thing and having to draw pretty much double the squares
void Simple_GOL_Area::draw_sim_data(const Cairo::RefPtr<Cairo::Context>& cr, int window_width, int window_height)
{
time_t seconds = time(NULL);
std::cout << "Rendering Simulation " << seconds << "\n";
if (sim_data->get_size() != 0)
{
int data_width = sim_data->get_width();
int data_height = sim_data->get_height();
double step_value_x = double(window_width)/double(sim_data->get_width());
double step_value_y = double(window_height)/double(sim_data->get_height());
for(int i=0; i<data_width; i++)
{
for(int j=0; j<data_height; j++)
{
if(sim_data->get(i,j))
{
cr->set_source_rgb(1,1,1);
}
else
{
cr->set_source_rgb(0,0,0);
}
//Yet to figure out why I have to draw in the black squares as well.
cr->rectangle(int(i*step_value_x), int(j*step_value_y),
int((i+1)*step_value_x), int((j+1)*step_value_y));
//Use bitmap classes so that I don't have to fill every time
cr->fill();
}
}
}
}
示例3: main
int main(int, char**) {
Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create(
Cairo::FORMAT_ARGB32, WIDTH, HEIGHT);
Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);
// fill background in white
cr->set_source_rgb(1.0, 1.0, 1.0);
cr->paint();
// draw a little dot at the point where text will be drawn
cr->arc(TEXT_ORIGIN_X, TEXT_ORIGIN_Y, FONT_SIZE / 4.0, 0, 2 * M_PI);
cr->set_source_rgba(0.0, 1.0, 0.0, 0.5);
cr->fill();
// draw the text
cr->move_to(TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
cr->set_source_rgb(0.8, 0.2, 0.2);
Cairo::RefPtr<Cairo::ToyFontFace> font = Cairo::ToyFontFace::create(
"Bitstream Charter", Cairo::FONT_SLANT_ITALIC,
Cairo::FONT_WEIGHT_BOLD);
cr->set_font_face(font);
cr->set_font_size(FONT_SIZE);
cr->show_text("cairomm!");
surface->write_to_png("toy-text.png");
return 0;
}
示例4:
bool
ButtonWidget::on_expose_event(GdkEventExpose* event)
{
Gtk::DrawingArea::on_expose_event(event);
Glib::RefPtr<Gdk::Window> window = get_window();
if(window)
{
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
int w = get_allocation().get_width() - 10;
int h = get_allocation().get_height() - 10;
cr->set_source_rgb(0.0, 0.0, 0.0);
cr->set_line_width(1.0);
cr->translate(5, 5);
cr->rectangle(0, 0, w, h);
if (down)
cr->fill_preserve();
cr->stroke();
if (down)
cr->set_source_rgb(1.0, 1.0, 1.0);
// FIXME: There are better ways to center text
if (name.size() == 2)
cr->move_to(w/2-6, h/2+3);
else
cr->move_to(w/2-4, h/2+3);
cr->show_text(name);
}
return true;
}
示例5: DrawObstacles
void MapDrawArea::DrawObstacles(const Cairo::RefPtr<Cairo::Context>& cr)
{
// Get size characteristics of the window
Gtk::Allocation allocation = get_allocation();
const int width = allocation.get_width();
const int height = allocation.get_height();
const int lesser = MIN(width, height);
// We should be able to just store the obstacles and path once
// Do need to update based on the window size
std::vector<Coord> vObstacles = guiMapData.copyObstacles();
Coord maxXY = guiMapData.copyMaxCoord();
Coord originCoord = guiMapData.copyStartCoord();
Coord goalCoord = guiMapData.copyEndCoord();
// These have to be updated each iteration
originCoord.x = int( float(width)*float(originCoord.x)/float(maxXY.x) );
originCoord.y = int( float(height)*float(originCoord.y)/float(maxXY.y) );
goalCoord.x = int( float(width)*float(goalCoord.x)/float(maxXY.x) );
goalCoord.y = int( float(height)*float(goalCoord.y)/float(maxXY.y) );
// Draw obstacles
std::vector<Coord> scaledObstacleCoord;
std::vector<Coord> rawObstacleCoord = guiMapData.copyObstacles();
Coord stdCoord;
// Adjust obstacle values based on window size
for(std::vector<Coord>::const_iterator itr=rawObstacleCoord.begin();itr!=rawObstacleCoord.end();++itr)
{
stdCoord.x = int( float(width)*float(itr->x)/float(maxXY.x) );
stdCoord.y = int( height*float(itr->y)/float(maxXY.y) );
scaledObstacleCoord.push_back(stdCoord);
}
cr->save();
cr->set_source_rgb(0.0, 0.0, 0.0); // black for obstacles
cr->set_line_width(lesser * 0.005);
cr->set_line_cap(Cairo::LINE_CAP_ROUND);
// Plot obstacles
for(std::vector<Coord>::iterator itr=scaledObstacleCoord.begin();itr != scaledObstacleCoord.end();++itr)
{
cr->move_to( itr->x,itr->y );
cr->line_to( itr->x,itr->y );
cr->stroke();
}
// Plot start/end coord
cr->save();
cr->set_line_width(lesser * 0.015);
cr->set_source_rgb(1.0, 0.0, 0.0); // red for start point
cr->move_to( originCoord.x,originCoord.y );
cr->line_to( originCoord.x,originCoord.y );
cr->stroke();
cr->save();
cr->set_source_rgb(0.0, 1.0, 0.0); // green for end point
cr->move_to( goalCoord.x,goalCoord.y );
cr->line_to( goalCoord.x,goalCoord.y );
cr->stroke();
}
示例6: draw
void enigma_rotor_window::draw(Cairo::RefPtr<Cairo::Context> cr)
{
vector<double> dashes;
// Pattern used to draw a dashed line (15 pixels of line followed by 15 "empty" pixels)
dashes.push_back(15.0);
dashes.push_back(15.0);
if (has_ellipse)
{
cr->save();
// Draw background ellipse
cr->set_source_rgb(bkg_r, bkg_g, bkg_b);
draw_ellipse(cr, x, y, ellipse_width, ellipse_height);
cr->fill();
// Draw black border of background ellipse
cr->set_source_rgb(BLACK);
cr->set_line_width(1.2);
draw_ellipse(cr, x, y, ellipse_width, ellipse_height);
cr->stroke();
cr->restore();
}
cr->save();
// Draw a line of width rotor_rim_width in the dash background colour
cr->set_line_width(rotor_rim_width);
cr->set_source_rgb(dash_bkg_r, dash_bkg_g, dash_bkg_b);
cr->move_to(x + window_size, y - (2 * window_size));
cr->line_to(x + window_size, y + (2 * window_size));
cr->stroke();
// Draw a dashed line in the dash colour inside the previously drawn line
// This creates the impression of "notches" on the handle/rim
cr->set_source_rgb(dash_r, dash_g, dash_b);
cr->set_dash(dashes, ((wheel_pos - 'A') & 1) * 15); // modifying the offset creates illusion of movement
cr->move_to(x + window_size, y - (2 * window_size));
cr->line_to(x + window_size, y + (2 * window_size));
cr->stroke();
// Draw border around handle/rim
cr->set_line_width(2.0);
cr->unset_dash();
cr->set_source_rgb(DARK_GREY);
cr->rectangle(x + padded_size, y - (2 * window_size), rotor_rim_width, (4 * window_size));
cr->stroke();
cr->restore();
draw_wheel_pos(cr, wheel_pos);
if (has_ellipse)
{
// Draw screws
upper->draw(cr);
lower->draw(cr);
}
}
示例7:
/// Same as draw_buffer, with only the curr_item's full text
void
ViewDrawingArea::render_full_article()
{
// Dimensions of drawing area
Gtk::Allocation allocation = get_allocation();
const int height = allocation.get_height();
const int width = allocation.get_width();
Cairo::RefPtr<Cairo::Context> cr = _pixmap->create_cairo_context();
cr->reset_clip();
cr->rectangle (0.0, 0.0, width, height);
cr->clip();
cr->set_source_rgb (1.0, 1.0, 1.0);
cr->paint();
cr->set_source_rgb (0.0, 0.0, 0.0);
Item *item = AppContext::get().get_curr_item();
item->make_display_unit();
ItemDisplayUnit *du = item->get_display_unit();
du->render (cr, 0, -_vadj->get_value());
cr->show_page();
double h = du->get_height();
if (h > height)
_vadj->set_upper (h - height);
else
_vadj->set_upper (0);
_vadj->set_page_size (height);
_vadj->set_step_increment (height * 1.0/16.0);
_vadj->set_page_increment (height * 15.0/16.0);
_vadj->changed();
}
示例8: pw
void
Renderer_BBox::render_vfunc(
const Glib::RefPtr<Gdk::Window>& drawable,
const Gdk::Rectangle& /*expose_area*/
)
{
assert(get_work_area());
if(!get_work_area())
return;
Cairo::RefPtr<Cairo::Context> cr = drawable->create_cairo_context();
const synfig::Vector::value_type window_startx(get_work_area()->get_window_tl()[0]);
const synfig::Vector::value_type window_starty(get_work_area()->get_window_tl()[1]);
const float pw(get_pw()),ph(get_ph());
const synfig::Point curr_point(get_bbox().get_min());
const synfig::Point drag_point(get_bbox().get_max());
if(get_bbox().area()<10000000000000000.0 && get_bbox().area()>0.00000000000000001)
{
Point tl(std::min(drag_point[0],curr_point[0]),std::min(drag_point[1],curr_point[1]));
Point br(std::max(drag_point[0],curr_point[0]),std::max(drag_point[1],curr_point[1]));
tl[0]=(tl[0]-window_startx)/pw;
tl[1]=(tl[1]-window_starty)/ph;
br[0]=(br[0]-window_startx)/pw;
br[1]=(br[1]-window_starty)/ph;
if(tl[0]>br[0])
swap(tl[0],br[0]);
if(tl[1]>br[1])
swap(tl[1],br[1]);
cr->save();
cr->set_line_cap(Cairo::LINE_CAP_BUTT);
cr->set_line_join(Cairo::LINE_JOIN_MITER);
cr->set_line_width(1.0);
cr->set_source_rgb(1.0,1.0,1.0);
// Operator difference was added in Cairo 1.9.4
// It currently isn't supported by Cairomm
#if CAIRO_VERSION >= 10904
cairo_set_operator(cr->cobj(), CAIRO_OPERATOR_DIFFERENCE);
#else
// Fallback: set color to black
cr->set_source_rgb(0,0,0);
#endif
cr->rectangle(
int(tl[0])+0.5,
int(tl[1])+0.5,
int(br[0]-tl[0]+1),
int(br[1]-tl[1]+1)
);
cr->stroke();
cr->restore();
}
}
示例9: on_draw
bool BookArea::on_draw(const Cairo::RefPtr<Cairo::Context> & cr)
{
Cairo::RefPtr<Cairo::Surface> surface = cr->get_target();
PageDescriptor pd = pages.get(pagenum);
Gtk::Allocation allocation = get_allocation();
const int width = allocation.get_width();
const int height = allocation.get_height();
const int rectangle_width = width;
const int rectangle_height = height;
//cr->set_antialias(ANTIALIAS_BEST);
cr->set_source_rgb(1.0, 1.0, 1.0);
DrawingUtils::draw_rectangle(cr, rectangle_width, rectangle_height);
cr->set_source_rgb(0.15, 0.15, 0.15);
//cr->set_source_rgb(1, 0.33, 0.33);
int start_pos = 0;
int itemid = 0;
for(PageContentItem pci : pd.items) {
if(pci.pct == PAGE_H1) {
start_pos += DrawingUtils::draw_h1(cr, pci.content, rectangle_width, rectangle_height);
}
else if(pci.pct == PAGE_H2) {
// Only pack out the header when it's not the first thing in the page
if (itemid != 0) {
start_pos += 35;
}
start_pos += DrawingUtils::draw_h2(cr, pci.content, rectangle_width, rectangle_height, start_pos);
start_pos += 35;
}
else if(pci.pct == PAGE_PARAGRAPH) {
start_pos += DrawingUtils::draw_text(cr, pci.content, rectangle_width, rectangle_height, start_pos);
}
else if(pci.pct == PAGE_FRAGMENT) {
start_pos += DrawingUtils::draw_fragment(cr, pci.content, rectangle_width, rectangle_height, start_pos);
}
itemid++;
}
//auto it = book.opf_files[0].metadata.find(MetadataType::TITLE);
//const ustring title = it->second.contents;
cr->set_source_rgb(0.5, 0.5, 0.5);
page_num_rect = DrawingUtils::draw_header(cr, rectangle_width, rectangle_height, "Pride and Prejudice", pagenum + 1);
return true;
}
示例10: on_expose_event
bool AdvEnvGUIScope::on_expose_event(GdkEventExpose* event)
{
Glib::RefPtr<Gdk::Window> window = get_window();
if (window)
{
float len, x, y, xscale, yscale;
Gtk::Allocation allocation = get_allocation();
const int width = allocation.get_width();
const int height = allocation.get_height();
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
cr->set_line_width(2.0);
cr->set_source_rgb(0.0, 0.0, 0.0);
cr->paint();
cr->set_source_rgb(0.0, 0.8, 0.0);
cr->rectangle(event->area.x, event->area.y, event->area.width, event->area.height);
cr->clip();
cr->move_to(width, height);
len = m_valueDelay + m_valueAttackTime1 + m_valueAttackTime2 + m_valueAttackTime3 + m_valueAttackTime4 + m_valueReleaseTime1 + m_valueReleaseTime2 + m_valueReleaseTime3 + SUSTAIN_LEN;
xscale = (float) width / len;
yscale = (float) (height - 6);
x = m_valueDelay * xscale;
cr->line_to((int) x, height);
x += m_valueAttackTime1 * xscale;
y = m_valueAttackLevel1 * yscale;
cr->line_to((int) x, height - (int) y);
x += m_valueAttackTime2 * xscale;
y = m_valueAttackLevel2 * yscale;
cr->line_to((int) x, height - (int) y);
x += m_valueAttackTime3 * xscale;
y = m_valueAttackLevel3 * yscale;
cr->line_to((int) x, height - (int) y);
x += m_valueAttackTime4 * xscale;
y = m_valueSustain * yscale;
cr->line_to((int) x, height - (int) y);
x += SUSTAIN_LEN * xscale;
cr->line_to((int) x, height - (int) y);
x += m_valueReleaseTime1 * xscale;
y = m_valueReleaseLevel1 * yscale;
cr->line_to((int) x, height - (int) y);
x += m_valueReleaseTime2 * xscale;
y = m_valueReleaseLevel2 * yscale;
cr->line_to((int) x, height - (int) y);
x += m_valueReleaseTime3 * xscale;
cr->line_to((int) x, height);
x = m_valueDelay * xscale;
cr->line_to((int) x, height);
cr->stroke();
}
return true;
}
示例11: dibujarArco
void GraficoDeTorta::dibujarArco(const Cairo::RefPtr<Cairo::Context>& c,int x, int y, int radio, float angulo0, float angulo1,float r, float g, float b){
c->set_source_rgb(1,1,1);
c->set_line_width(2);
c->arc(x,y,radio, angulo0, angulo1);
c->line_to(x,y);
c->close_path();
c->stroke_preserve();
c->set_source_rgb(r,g,b);
c->fill();
}
示例12: drawBackground
void ItemView::drawBackground(const Cairo::RefPtr<Cairo::Context>& cr, const int width, const int height)
{
//fill background
if (isSelected())
{
cr->set_source_rgb(1, 1, 1);
cr->rectangle(0, 0, width, height);
cr->fill();
}
else
{
cr->set_source_rgb(0.98, 0.98, 0.98);
cr->rectangle(0, 0, width, height);
cr->fill();
}
//time area
Cairo::RefPtr<Cairo::LinearGradient> linearGradientTime = Cairo::LinearGradient::create(0, 0, 0, height);
//set color by status
ColorMode colorMode = getColorMode();
if (colorMode == COLOR_INACTIVE)
{
//gray
linearGradientTime->add_color_stop_rgb(0, 0.75, 0.75, 0.75);
linearGradientTime->add_color_stop_rgb(1, 0.65, 0.65, 0.65);
}
if (colorMode == COLOR_ALARM)
{
//orange
linearGradientTime->add_color_stop_rgb(0, 1.00, 0.60, 0.30);
linearGradientTime->add_color_stop_rgb(1, 0.90, 0.50, 0.20);
}
if (colorMode == COLOR_OK)
{
//green
linearGradientTime->add_color_stop_rgb(0, 0.40, 0.70, 0.45);
linearGradientTime->add_color_stop_rgb(1, 0.30, 0.60, 0.35);
}
cr->set_source(linearGradientTime);
cr->rectangle(0, 0, TIME_WIDTH, height);
cr->fill();
if (isSelected())
drawInnerShadow(cr, width, height);
}
示例13: drawTime
void ItemView::drawTime(const Cairo::RefPtr<Cairo::Context>& cr, const int width, const int height)
{
int text_width;
int text_height;
Glib::RefPtr<Pango::Layout> layTime = Pango::Layout::create(cr);
layTime->set_font_description(fontTime);
layTime->set_text(data.getTimeText());
layTime->get_pixel_size(text_width, text_height);
rectTime.set_x((TIME_WIDTH * 0.5) - (text_width * 0.5));
rectTime.set_y((int)PADDING);
rectTime.set_width(text_width);
rectTime.set_height(text_height);
//highlight
const int highlightSize = 1;
cr->move_to(rectTime.get_x(), rectTime.get_y() - highlightSize);
//set colors
ColorMode colorMode = getColorMode();
if (colorMode == COLOR_INACTIVE)
{
//gray
cr->set_source_rgb(0.6, 0.6, 0.6);
}
if (colorMode == COLOR_ALARM)
{
//orange
cr->set_source_rgb(0.8, 0.40, 0.0);
}
if (colorMode == COLOR_OK)
{
//green
cr->set_source_rgb(0.0, 0.55, 0.0);
}
layTime->show_in_cairo_context(cr);
//inner color
cr->move_to(rectTime.get_x(), rectTime.get_y());
cr->set_source_rgb(1.0, 1.0, 1.0);
layTime->show_in_cairo_context(cr);
}
示例14: on_expose_event
bool CompVis::on_expose_event(GdkEventExpose* event) {
Glib::RefPtr<Gdk::Window> window = get_window();
Allocation allocation = get_allocation();
const int width = allocation.get_width();
const int height = allocation.get_height();
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
// clip to the area indicated by the expose event so that we only redraw
// the portion of the window that needs to be redrawn
cr->rectangle(event->area.x, event->area.y,
event->area.width, event->area.height);
cr->clip();
rms_dB = 20*log10(rms);
thresh_fraction = (threshold - p_ports[p_threshold].min)/threshold_range;
rms_dB_fraction = (rms_dB - p_ports[p_threshold].min)/threshold_range;
// Draw the graph
cr->set_source_rgb(0.5,0.1,0.1);
cr->set_line_width(2);
cr->move_to(0,height);
if (rms_dB <= threshold) {
cr->line_to(rms_dB_fraction*width, height-rms_dB_fraction*height);
cr->line_to(rms_dB_fraction*width, height);
cr->line_to(0,height);
} else {
cr->line_to(thresh_fraction*width, height-thresh_fraction*height);
cr->line_to(rms_dB_fraction*width, height-(thresh_fraction*height + height*(rms_dB_fraction-thresh_fraction)/ratio));
cr->line_to(rms_dB_fraction*width, height);
cr->line_to(0,height);
}
cr->fill();
// draw the compression curve:
cr->set_source_rgb(0.1,0.1,0.1);
cr->move_to(0, height);
cr->line_to(thresh_fraction*width, height-thresh_fraction*height);
cr->line_to(width, height-(thresh_fraction*height + height*(1-thresh_fraction)/ratio));
cr->stroke();
// Draw the gain
cr->set_source_rgb(0.1,0.8,0.1);
cr->rectangle(0,(float)height - (float)height*gain, 10, height);
cr->fill();
return true;
}
示例15: init
void CairoPlugin::init()
{
int height, width;
preferredSize(width, height);
m_img = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, width, height);
m_store = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, width, height);
m_ctx = Cairo::Context::create(m_img);
Cairo::RefPtr < Cairo::Context > ctx = Cairo::Context::create(m_store);
ctx->save();
ctx->set_source_rgb(1.0, 1.0, 1.0);
ctx->set_operator(Cairo::OPERATOR_SOURCE);
ctx->paint();
ctx->set_operator(Cairo::OPERATOR_OVER);
ctx->restore();
m_ctx->save();
m_ctx->set_source_rgb(1.0, 1.0, 1.0);
m_ctx->set_operator(Cairo::OPERATOR_SOURCE);
m_ctx->paint();
m_ctx->set_operator(Cairo::OPERATOR_OVER);
m_ctx->restore();
m_init = false;
m_need = true;
}