Example #1
0
	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);
	}
Example #2
0
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

}
Example #3
0
		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;
		}
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;
}
Example #5
0
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;
}
Example #6
0
	void renderLabels(Cairo::RefPtr<Cairo::Context> cr, std::vector<std::pair<string, FloatPoint> >& toPlace) {
		cr->save();
		cr->set_source_rgba(0.0, 0.0, 0.0, 0.5);
		Cairo::RefPtr<Cairo::ToyFontFace> font = Cairo::ToyFontFace::create(DEFAULT_FONT, Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);
		cr->set_font_face(font);
		cr->set_font_size(120.0);
		cr->set_line_width(2.0);

		Cairo::TextExtents textSize;
		std::list<shared_ptr<Label> > labels;
		int i = 0;
		std::vector<shared_ptr<Style>> styles;
		for (auto& pair : toPlace)
		{
			string& text = pair.first;
			cr->get_text_extents(text, textSize);
			shared_ptr<Style> s = boost::make_shared<Style>();
			s->text = text;
			styles.push_back(s);
			FloatPoint center = pair.second + FloatPoint(textSize.width/2.0, textSize.height/2.0);
			FloatRect owner = FloatRect(center.x, center.y, center.x, center.y);
			FloatPoint origin = pair.second - FloatPoint(textSize.x_bearing, textSize.y_bearing);
			shared_ptr<Label> l = boost::make_shared<Label>(FloatRect(pair.second, textSize.width, textSize.height), owner, s->text, s.get(), origin);

			cr->rectangle(l->box.minX, l->box.minY, l->box.getWidth(), l->box.getHeight());
			cr->stroke();

			labels.push_back(l);
		}

		std::vector<shared_ptr<Label> > placed;
		placeLabels(labels, placed);

		for (auto& l: placed)
		{
			cr->set_source_rgba(0.0, 0.0, 0.0, 1.0);
			cr->move_to(l->box.minX, l->box.maxY);
			cr->show_text(l->style->text.str());
			cr->fill();

			cr->set_source_rgba(1.0, 0.0, 0.0, 0.5);
			cr->rectangle(l->box.minX, l->box.minY, l->box.getWidth(), l->box.getHeight());
			cr->fill();
		}

		cr->restore();
	}
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);
}
Example #8
0
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();
      }
    }
  }
}
Example #9
0
	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();
	}
Example #10
0
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;
}
Example #11
0
/** 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();
}
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;
	}
}
Example #13
0
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;
}
Example #14
0
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;
}
Example #15
0
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();
}
Example #16
0
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();
}
Example #17
0
void EmblemCellRenderer::do_render(const Cairo::RefPtr<Cairo::Context>& context, int widget, int background_area, Gdk::Rectangle &cell_area, int flags) {
    context->translate(cell_area.get_x(), cell_area.get_y());
    context->rectangle(0, 0, cell_area.get_width(), cell_area.get_height());
    context->clip();

    // TODO: Incorporate padding
    context->push_group();
    if (!this->_icon_name.empty()) {
        Glib::RefPtr<Gdk::Pixbuf> pixbuf = this->_get_pixbuf(this->_icon_name, this->_icon_size);
        context->set_operator(Cairo::OPERATOR_SOURCE);
        // Assumes square icons; may break if we don't get the requested size
        int height_offset = int((cell_area.get_height() - pixbuf->get_height())/2);
        Gdk::Cairo::set_source_pixbuf(context, pixbuf, 0, height_offset);
        context->rectangle(0, height_offset,
                          pixbuf->get_width(), pixbuf->get_height());
        context->fill();

        if (this->_tint_color) {
            Gdk::RGBA* c = this->_tint_color;
            gushort r = c->get_red();
            gushort g = c->get_green();
            gushort b = c->get_blue();
            // Figure out the difference between our tint colour and an
            // empirically determined (i.e., guessed) satisfying luma and
            // adjust the base colours accordingly
            double luma = (r + r + b + g + g + g) / 6.;
            double extra_luma = (1.2 - luma) / 3.;
            r = std::min(r + extra_luma, 1.);
            g = std::min(g + extra_luma, 1.);
            b = std::min(b + extra_luma, 1.);
            context->set_source_rgba(r, g, b, 0.4);
            context->set_operator(Cairo::OPERATOR_ATOP);
            context->paint();
        }

        if (!this->_emblem_name.empty()) {
            Glib::RefPtr<Gdk::Pixbuf> pixbuf = this->_get_pixbuf(this->_emblem_name, this->_emblem_size);
            int x_offset = this->_icon_size - this->_emblem_size;
            context->set_operator(Cairo::OPERATOR_OVER);
            Gdk::Cairo::set_source_pixbuf(context, pixbuf, x_offset, 0);
            context->rectangle(x_offset, 0,
                              cell_area.get_width(), this->_emblem_size);
            context->fill();
        }
    }

    context->pop_group_to_source();
    context->set_operator(Cairo::OPERATOR_OVER);
    context->paint();
}
Example #18
0
//! Debug function that prints identifier on the tile
void Renderer::printTileId(const Cairo::RefPtr<Cairo::Context>& cr,
						   const shared_ptr<TileIdentifier>& id) const
{
	cr->save();

	cr->set_font_size(10);
	cr->move_to(5.0, TILE_SIZE - 10);

	std::ostringstream labelstrm;
	labelstrm << "X: " << id->getX() << " Y: " << id->getY();
	labelstrm << " Zoom: " << id->getZoom();
	labelstrm << " Style: " << id->getStylesheetPath();
	std::string label = labelstrm.str();
	cr->text_path(label.c_str());

	cr->set_source_rgba(1.0, 1.0, 1.0, 1.0);
	cr->set_line_width(2.0);
	cr->stroke_preserve();
	cr->set_source_rgba(0.0, 0.0, 0.0, 1.0);
	cr->fill();

	cr->restore();
}
Example #19
0
	bool MainWindow::first_draw(const Cairo::RefPtr<Cairo::Context>& cr)
	{
		Gtk::Allocation allocation = m_first.get_allocation();
		cr->set_source_rgba(0, 0, 0, 1);
		cr->rectangle(0, 0, allocation.get_width(), allocation.get_height());
		cr->fill();

		if(m_png)
		{
			cr->set_source(m_png, 0, 0);
			cr->paint();
		}

		return true;
	}
Example #20
0
void OutputFile::draw_edges(Cairo::RefPtr<Cairo::Context> &cr,
 vector<straightener::Route*> const & es, double const xmin, double const ymin) {
    cr->save();
    // background
    cr->set_source_rgba(0,0,1,0.5);
    for (unsigned i=0;i<es.size();i++) {
        const straightener::Route* r=es[i];
        cr->move_to(r->xs[0]-xmin,r->ys[0]-ymin);
        for (unsigned j=1;j<r->n;j++) {
            cr->line_to(r->xs[j]-xmin,r->ys[j]-ymin);
        }
        cr->stroke();
    }
    cr->restore();
}
int main() {
#ifdef CAIRO_HAS_PDF_SURFACE

	std::string filename = "image.pdf";
	int width = 600;
	int height = 400;
	Cairo::RefPtr<Cairo::PdfSurface> surface = Cairo::PdfSurface::create(
			filename, width, height);

	Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);

	cr->save(); // save the state of the context
	cr->set_source_rgb(0.86, 0.85, 0.47);
	cr->paint(); // fill image with the color
	cr->restore(); // color is back to black now

	cr->save();
	// draw a border around the image
	cr->set_line_width(20.0); // make the line wider
	cr->rectangle(0.0, 0.0, cairo_image_surface_get_width(surface->cobj()),
			height);
	cr->stroke();

	cr->set_source_rgba(0.0, 0.0, 0.0, 0.7);
	// draw a circle in the center of the image
	cr->arc(width / 2.0, height / 2.0, height / 4.0, 0.0, 2.0 * M_PI);
	cr->stroke();

	// draw a diagonal line
	cr->move_to(width / 4.0, height / 4.0);
	cr->line_to(width * 3.0 / 4.0, height * 3.0 / 4.0);
	cr->stroke();
	cr->restore();

	cr->show_page();

	std::cout << "Wrote PDF file \"" << filename << "\"" << std::endl;
	return 0;

#else

	std::cout << "You must compile cairo with PDF support for this example to work."
	<< std::endl;
	return 1;

#endif
}
Example #22
0
    void drawMotionItem(const MotionItem2D& item){
      Glib::RefPtr<Gdk::Window> window = drawingAreaMain->get_window();
      if(window){
	int width;
	int height;
	
	drawingAreaMain->get_size_request(width,height);
	
	Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
      
	if (item.motion > 0){
	  cr->set_source_rgba(1.0, 0.0, 0.0,1.0);
	  cr->rectangle(item.area.x, item.area.y, item.area.width, item.area.height);
	  cr->stroke();
	}
      }
    }
Example #23
0
int main()
{
  Cairo::RefPtr<Cairo::ImageSurface> surface =
    Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 600, 400);

  Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);

  cr->save(); // save the state of the context
  cr->set_source_rgb(0.86, 0.85, 0.47);
  cr->paint();   // fill image with the color
  cr->restore(); // color is back to black now

  cr->save();
  // draw a border around the image
  cr->set_line_width(20.0); // make the line wider
  cr->rectangle(0.0, 0.0, surface->get_width(), surface->get_height());
  cr->stroke();

  cr->set_source_rgba(0.0, 0.0, 0.0, 0.7);
  // draw a circle in the center of the image
  cr->arc(surface->get_width() / 2.0, surface->get_height() / 2.0,
          surface->get_height() / 4.0, 0.0, 2.0 * M_PI);
  cr->stroke();

  // draw a diagonal line
  cr->move_to(surface->get_width() / 4.0, surface->get_height() / 4.0);
  cr->line_to(surface->get_width() * 3.0 / 4.0,
              surface->get_height() * 3.0 / 4.0);
  cr->stroke();
  cr->restore();

#ifdef CAIRO_HAS_PNG_FUNCTIONS

  std::string filename = "image.png";
  surface->write_to_png(filename);

  std::cout << "Wrote png file \"" << filename << "\"" << std::endl;

#else

  std::cout
    << "You must compile cairo with PNG support for this example to work."
    << std::endl;

#endif
}
bool TransparentSlider::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
    auto window = get_window();

    Cairo::RectangleInt window_size;
    Cairo::RectangleInt clip;
    double x1, y1, x2, y2;
    cr->get_clip_extents(x1, y1, x2, y2);

    clip.height = _round(y2-y1);
    clip.width = _round(x2-x1);
    clip.x = _round(x1);
    clip.y = _round(y1);

    window_size.x = 0;
    window_size.y = 0;
    window_size.height = window->get_height();
    window_size.width = window->get_width();

    cr->save();

    if (_SUPPORTS_ALPHA) {
        cr->set_source_rgba(                    // transparent
                _adjustmentRed->get_value(),
                _adjustmentGreen->get_value(),
                _adjustmentBlue->get_value(),
                _adjustmentAlpha->get_value());
    } else {
        cr->set_source_rgb(                     // opaque
                _adjustmentRed->get_value(),
                _adjustmentGreen->get_value(),
                _adjustmentBlue->get_value());
    }
    cr->set_operator(Cairo::OPERATOR_SOURCE);

    if (clip.height==window_size.height && clip.width==window_size.width && clip.x==window_size.x && clip.y==window_size.y) {
    } else {
        window->invalidate(true);
    }
    cr->reset_clip();
    cr->paint();
    cr->restore();

    return Gtk::Window::on_draw(cr);
}
Example #25
0
void CurveEditPart::drawControlLine(Cairo::RefPtr<Cairo::Context> context, const Point& start_point, const Point& end_point)
{
    context->begin_new_path();
    context->move_to (start_point.getX(), start_point.getY());
    context->line_to (end_point.getX(), end_point.getY());

    context->set_source_rgba (1, 0, 0, 0.5);

    std::vector< double > dashes(2);
    dashes[0] = 2.0;
    dashes[1] = 2.0;

    context->set_dash (dashes, 0.0);

    context->set_line_width (1.0);

    context->stroke();
}
void RectangularSelectionLayer::draw(const Cairo::RefPtr<Cairo::Context>& context)
{
	if (!_is_visible || !_width || !_height) {
		return;
	}

	if (_current_time != _timestamp) {
		return;
	}

	context->save();

	context->set_source_rgba(1.0, 0.0, 0.0, 0.5);
	context->rectangle(_x - 0.5, _y - 0.5, _width, _height);
	context->set_line_width(1.0);
	context->stroke();

	context->restore();
}
Example #27
0
							 //const Cairo::RefPtr<Cairo::Context>& cr
		virtual bool on_draw(const Cairo::RefPtr<Cairo::Context> &cr) {
			Gtk::Allocation alloc = get_allocation();
			int ancho = alloc.get_width();
			int alto = alloc.get_height();
			int x = ancho / 2;
			int y = alto / 2;
			
			int w = 3 * ancho / 4.0;
			int h = alto / 2.0;
			cr->save();
			
			cr->translate(x, y);
			cr->scale(w, h);
			cr->arc(0, 0, 1.0, 0, 2 * M_PI);
			cr->set_source_rgba(0, 0, 1.0, 0);
			// cr->fill_preserve();
			cr->restore();  // back to opaque black
			cr->stroke();
			return true;
		}
Example #28
0
bool level_editor::tileset_display::on_expose_event(GdkEventExpose* event) {
  Glib::RefPtr<Gdk::Window> window = get_window();

  if (!window || !m_surface)
    return true;

  Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
  cr->rectangle(event->area.x, event->area.y, event->area.width, event->area.height);
  cr->clip();

  cr->set_source(m_surface, 0, 0);
  cr->paint();

  // Show selection rectangle when we are selecting
  if (m_selecting
      || ((m_select_x != m_select_end_x || m_select_y != m_select_end_y)
          && m_preferences.sticky_tile_selection)) {
    const int x = std::min(m_select_x, m_select_end_x) * m_tile_width;
    const int y = std::min(m_select_y, m_select_end_y) * m_tile_height;

    const int w = (std::abs(m_select_x - m_select_end_x))
                    * m_tile_width;
    const int h = (std::abs(m_select_y - m_select_end_y))
                    * m_tile_height;

    cr->save();
      cr->rectangle(x, y, w, h);
      // TODO: move selection color somewhere else (preferences?)
      cr->set_source_rgb(0.7, 1, 1);
      if (m_preferences.selection_background) {
        cr->stroke_preserve();
        cr->set_source_rgba(0.7, 1, 0, 0.2);
        cr->fill();
      } else {
        cr->stroke();
      }
    cr->restore();
  }

  return true;
}
Example #29
0
/**
 * Draws a curve for the speed graph.
 */
void GtkGraph::draw(std::queue<double> q, double height, double increment, double maxValue, const Cairo::RefPtr<Cairo::Context>& cr)
{
	// wizards use computers
	// computers use numbers
	// no magic
	
	double offset = increment * (m_displaySize - q.size());

	cr->move_to(0, height);
	for(unsigned i = 0; i< (m_displaySize - q.size());++i)
		cr->line_to(i*increment, height);


	double oldy;
	if(q.empty()) return;

	oldy = height - (q.front() * height / maxValue);
	cr->line_to(offset, oldy);
	q.pop();
	double x = increment + offset;
	while(!q.empty())
	{
		double y = height - (q.front() * height / maxValue);
		cr->curve_to(x - increment/2, oldy, x - increment/2, y, x, y);
		q.pop();
		oldy = y;
		x += increment;
	}

	if(gt::Settings::settings["GraphStyle"] == "Fill")
	{
		cr->stroke_preserve();
		Gdk::Cairo::set_source_rgba(cr, Gdk::RGBA(gt::Settings::settings[(upl) ? "GraphUploadFillColor" : "GraphDownloadFillColor"]));
		cr->line_to(x - increment, height);
		cr->line_to(0,height);
		auto k = Gdk::RGBA(gt::Settings::settings[(upl) ? "GraphUploadFillColor" : "GraphDownloadFillColor"]);
		cr->set_source_rgba(k.get_red(), k.get_green(), k.get_blue(), k.get_alpha() * 0.5);
		cr->fill();
	}
	else cr->stroke();
}
Example #30
0
    void drawMotion(const MotionItem2DSeq& motionSeq){
      Glib::RefPtr<Gdk::Window> window = drawingAreaMain->get_window();
      if(window){
	int width;
	int height;
	
	drawingAreaMain->get_size_request(width,height);
	
	Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
      
	// Store context
	//cr->save();
      
	// Draw the source image on the widget context
	//cr->set_source(pImpl->image_surface, 0.0, 0.0);
	//cr->rectangle(0.0, 0.0, imgBuff->get_width(), imgBuff->get_height());
	//cr->clip();
	//cr->paint();
      
      
	//cr->set_line_width(2.0);
      
	// 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();
      
      
	MotionItem2DSeq::const_iterator m_it = motionSeq.begin();
	for (;m_it!=motionSeq.end(); m_it++){
	  if (m_it->motion > 0){
	    cr->set_source_rgba(1.0, 0.0, 0.0,1.0);
	    cr->rectangle(m_it->area.x, m_it->area.y, m_it->area.width, m_it->area.height);
	    cr->stroke();
	  }
	}
	// Restore context
	//cr->restore();
      }
    }