本文整理汇总了C++中cairo::RefPtr::set_source_rgba方法的典型用法代码示例。如果您正苦于以下问题:C++ RefPtr::set_source_rgba方法的具体用法?C++ RefPtr::set_source_rgba怎么用?C++ RefPtr::set_source_rgba使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cairo::RefPtr
的用法示例。
在下文中一共展示了RefPtr::set_source_rgba方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: renderLabels
void renderLabels(const char* path)
{
BOOST_TEST_MESSAGE("Render: " << path);
Cairo::RefPtr<Cairo::Surface> surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32,
META_TILE_SIZE * TILE_SIZE, META_TILE_SIZE * TILE_SIZE);
Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);
cr->set_source_rgba(0.0, 0.0, 0.0, 1.0);
cr->save();
cr->set_source_rgba(1.0, 1.0, 1.0, 1.0);
cr->paint();
cr->restore();
std::vector<std::pair<string, FloatPoint>> toPlace;
toPlace.push_back(std::pair<string, FloatPoint>("Karlsruhe", FloatPoint(40, 200)));
toPlace.push_back(std::pair<string, FloatPoint>("Mannheim", FloatPoint(400, 200)));
toPlace.push_back(std::pair<string, FloatPoint>("Stuttgard", FloatPoint(200, 260)));
toPlace.push_back(std::pair<string, FloatPoint>("München", FloatPoint(380, 660)));
toPlace.push_back(std::pair<string, FloatPoint>("Pforzheim", FloatPoint(200, 600)));
toPlace.push_back(std::pair<string, FloatPoint>("Wien", FloatPoint(240, 680)));
toPlace.push_back(std::pair<string, FloatPoint>("Paris", FloatPoint(40, 880)));
toPlace.push_back(std::pair<string, FloatPoint>("Rom", FloatPoint(-40, 880)));
toPlace.push_back(std::pair<string, FloatPoint>("Nothing", FloatPoint(400, 760)));
toPlace.push_back(std::pair<string, FloatPoint>("To See", FloatPoint(720, 880)));
toPlace.push_back(std::pair<string, FloatPoint>("Here", FloatPoint(720, 560)));
toPlace.push_back(std::pair<string, FloatPoint>("Bielefeld", FloatPoint(420, 840)));
renderer->renderLabels(cr, toPlace);
BOOST_TEST_MESSAGE("Writing.");
surface->flush();
surface->write_to_png(path);
}
示例2: drawCairo
int drawCairo(const string& fname,
const valarray<double>& Xin, const valarray<double>& Yin,
const Hull& hull) {
#ifdef CAIRO_HAS_SVG_SURFACE
unsigned n=Xin.size();
assert(Yin.size()==n);
// normalise coords to range 0-1
valarray<double> X=Xin, Y=Yin;
X-=X.min();
Y-=Y.min();
X/=X.max();
Y/=Y.max();
Cairo::RefPtr<Cairo::SvgSurface> surface =
Cairo::SvgSurface::create(fname, width+2*border, height+2*border);
Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);
cr->save(); // save the state of the context
cr->set_source_rgba(0.0, 0.0, 0.0, 0.7);
// draw a circle at each coordinate
for(unsigned i=0;i<n;i++) {
dot(cr,xcoord(X[i]),ycoord(Y[i]));
}
cr->set_source_rgba(0.0, 0.0, 0.0, 0.3);
cr->move_to(xcoord(X[hull[0]]),ycoord(Y[hull[0]]));
for(unsigned i=1;i<hull.size();i++) {
cr->line_to(xcoord(X[hull[i]]),ycoord(Y[hull[i]]));
}
cr->line_to(xcoord(X[hull[0]]),ycoord(Y[hull[0]]));
cr->stroke();
cr->set_source_rgba(0.0, 0.0, 0.0, 1.);
for(vector<unsigned>::const_iterator i=hull.begin();i!=hull.end();++i) {
unsigned j=*i;
stringstream ss;
ss<<j;
printf("p[%d]=(%f,%f)\n",j,X[j],Y[j]);
cr->move_to(xcoord(X[j]),ycoord(Y[j]));
cr->show_text(ss.str());
cr->stroke();
}
cr->restore();
cr->show_page();
cout << "Wrote SVG file \"" << fname << "\"" << endl;
return 0;
#else
cout << "You must compile cairo with SVG support for this example to work."
<< endl;
return 1;
#endif
}
示例3: on_draw
virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
Gtk::Allocation allocation = get_allocation();
const int width = allocation.get_width();
const int height = allocation.get_height();
if(!drawing)
{
sort(objects.begin(), objects.end(), PlaneObjectColection::compare);
}
drawing=1;
unsigned int i;
unsigned int j;
cr->set_line_width(2);
Coordenate temp;
for(i=0; i<objects.size(); i++)
{
if(objects[i].get_num_nodos()<2 || objects[i].z>=camera.z) continue;
cr->save();
temp=get_draw_location(objects[i].get_nodo_position(0), width, height, 26.5/M_PI);
cr->line_to(temp.x, temp.y);
cr->move_to(temp.x, temp.y);
for(j=1; j<objects[i].get_num_nodos(); j++)
{
temp=get_draw_location(objects[i].get_nodo_position(j), width, height, 26.5/M_PI);
cr->line_to(temp.x, temp.y);
}
temp=get_draw_location(objects[i].get_nodo_position(0), width, height, 26.5/M_PI);
cr->line_to(temp.x, temp.y);
temp=get_draw_location(objects[i].get_nodo_position(1), width, height, 26.5/M_PI);
cr->line_to(temp.x, temp.y);
cr->set_source_rgba(double(objects[i].fill_color.red)/255, double(objects[i].fill_color.green)/255, double(objects[i].fill_color.blue)/255, double(objects[i].fill_color.alpha)/255);
cr->fill_preserve();
cr->set_source_rgba(double(objects[i].line_color.red)/255, double(objects[i].line_color.green)/255, double(objects[i].line_color.blue)/255, double(objects[i].line_color.alpha)/255);
cr->stroke();
cr->restore();
}
return 1;
}
示例4: 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;
}
示例5: OnDraw
bool Window::OnDraw(const Cairo::RefPtr<Cairo::Context> & cr)
{
cr->set_source_rgba(0.337, 0.612, 0.117, 0.9);
cr->paint();
return false;
}
示例6: draw
void ConsoleWindow::draw(Cairo::RefPtr<Cairo::Context> ctx)
{
ctx->save();
ctx->set_source_rgba(0, 0, 0, 0.8);
ctx->paint();
ctx->set_source_rgba(1, 1, 1, 0.3);
ctx->move_to(0, height - 0.5);
ctx->line_to(width, height - 0.5);
ctx->set_line_width(1);
ctx->stroke();
ctx->restore();
ctx->move_to(10, 16);
ctx->set_source_rgb(1, 1, 1);
ctx->select_font_face("Menlo", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);
ctx->set_font_size(13);
ctx->show_text(input);
}
示例7: draw
void ICLayerLineString::draw(Cairo::RefPtr<Cairo::Context> cr, double scale,
std::set<int> select, bool DisplayID, double Alpha)
{
std::map<int, ICLayerObject*>::iterator it;
for (it = m_ICLayerObject.begin(); it != m_ICLayerObject.end(); it++)
{
if ((*it).second->selfIdExisting())
{
bool isSelect = false;
if (!select.empty())
{
std::set<int>::iterator it2;
it2 = select.find((*it).first);
if (it2 != select.end() && (*it2) == (*it).first)
{
drawLine(cr, (*it).second->getOGRGeometryObject(), scale, true);
isSelect = true;
} else
drawLine(cr, (*it).second->getOGRGeometryObject(), scale, false);
} else
drawLine(cr, (*it).second->getOGRGeometryObject(), scale, false);
if (DisplayID)
{
Cairo::TextExtents extents;
std::stringstream str;
str << (*it).first;
std::string text = str.str();
cr->select_font_face("Bitstream Vera Sans, Arial", Cairo::FONT_SLANT_NORMAL,
Cairo::FONT_WEIGHT_NORMAL);
cr->set_font_size(12 / scale);
Cairo::FontOptions font_options;
font_options.set_hint_style(Cairo::HINT_STYLE_NONE);
font_options.set_hint_metrics(Cairo::HINT_METRICS_OFF);
font_options.set_antialias(Cairo::ANTIALIAS_GRAY);
cr->set_font_options(font_options);
cr->save();
cr->get_text_extents(text, extents);
cr->move_to((*it).second->getCentroid().first,
(*it).second->getCentroid().second);
cr->scale(1, -1);
if (isSelect)
cr->set_source_rgba(0, 0, 0, Alpha);
cr->show_text(text);
cr->stroke();
cr->restore();
}
}
}
}
示例8: clear
void clear()
{
cr->save();
cr->set_operator(Cairo::OPERATOR_CLEAR);
cr->set_source_rgba(1.0, 1.0, 1.0, 1.0);
cr->paint();
cr->restore();
}
示例9: on_expose_event
bool MyPaintBox::on_expose_event(GdkEventExpose *event) {
call_paint_func(event);
Cairo::RefPtr<Cairo::Context> cr = Glib::wrap(event->window, true)->create_cairo_context();
gdk_cairo_region(cr->cobj(), event->region);
cr->clip();
cr->set_source_rgba(0.0, 0.0, 0.0, 1-background_adj->get_value());
cr->paint();
foreach(sigc::bind(sigc::mem_fun(this, &MyPaintBox::propagate_expose), event));
return true;
}
示例10:
/** Draw scale box.
* Draws a circle with a radius of 1m around the robot.
* @param window Gdk window
* @param cr Cairo context to draw to. It is assumed that possible transformations
* have been setup before.
*/
void
LaserDrawingArea::draw_scalebox(Glib::RefPtr<Gdk::Window> &window,
const Cairo::RefPtr<Cairo::Context> &cr)
{
cr->save();
cr->set_source_rgba(0, 0, 0.8, 0.2);
cr->arc(0, 0, 1.0, 0, 2 * M_PI);
cr->stroke();
cr->restore();
}
示例11: 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<BoxFontFace> font = BoxFontFace::create();
cr->set_font_face(font);
cr->set_font_size(FONT_SIZE);
cr->show_text("cairomm!");
// Now show it with the toy text API to
// demonstrate how the glyphs match up
cr->move_to(TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
cr->set_source_rgba(0.2, 0.2, 0.2, 0.3);
Cairo::RefPtr<Cairo::ToyFontFace> toy_font = Cairo::ToyFontFace::create(
"Bitstream Charter", Cairo::FONT_SLANT_NORMAL,
Cairo::FONT_WEIGHT_BOLD);
cr->set_font_face(toy_font);
cr->set_font_size(FONT_SIZE);
cr->show_text("cairomm!");
const char* filename = "user-font.png";
try {
surface->write_to_png(filename);
std::cout << "Wrote Image " << filename << std::endl;
return 0;
} catch (const std::exception& e) {
std::cout << "** Unable to write Image " << filename << std::endl;
return 1;
}
}
示例12: on_draw
bool ColorArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
cr->set_source_rgba(_color.red / 255.0,
_color.green / 255.0,
_color.blue / 255.0,
_color.alpha / 255.0);
cr->paint();
return true;
}
示例13: on_draw
bool MyArea_private::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
if (pixbuf == 0) return false;
cr->set_source_rgba(0xff, 0xff, 0xff, 0xff);
cr->rectangle(0, 0, 800, 640);
cr->fill();
Gdk::Cairo::set_source_pixbuf(cr, pixbuf);
cr->paint();
cr->stroke();
return true;
}
示例14: update_canvas
void HelloWorld::update_canvas(Cairo::RefPtr<Cairo::Context> &context) {
alc_allocation = ara_canvas.get_allocation();
int width = alc_allocation.get_width();
int height = alc_allocation.get_height();
cout << "width: " << width << ", height: " << height << endl;
context->save();
context->set_source_rgba(0, level, 0, 1);
context->scale(width, height);
context->rectangle(0, 0, 1, 1);
context->fill();
context->restore();
}
示例15: draw
void Rect::draw(Cairo::RefPtr<Cairo::Context> cr, int x, int y)
{
//draw a Rectangle centered on (x, y)
int w_2 = width/2;
int h_2 = height/2;
cr->save();
cr->rectangle(x - w_2, y - h_2, width, height);
cr->set_source_rgba(color->getRed(), color->getGreen(), color->getBlue(), 1.0); //opaque
cr->fill();
cr->restore();
}