Beispiel #1
0
void NodeRenderer::icon(const Cairo::RefPtr<Cairo::Context>& cr, AssetCache& cache)
{
	// path to icon not set
	if (s->icon_image.str().size() == 0 || s->icon_width == 0.0 || s->icon_height == 0.0)
		return;

	cr->save();

	Cairo::RefPtr<Cairo::ImageSurface> image = cache.getImage(s->icon_image.str());
	double width = s->icon_width < 0 ? image->get_width() : s->icon_width;
	double height = s->icon_height < 0 ? image->get_height() : s->icon_height;
	double x0 = floor(location.x - width/2.0);
	double y0 = floor(location.y - height/2.0);
	cr->translate(x0, y0);
	cr->scale(width / image->get_width(),
			  height / image->get_height());
	cr->set_source(image, 0, 0);

	if (s->icon_opacity < 1.0)
		cr->paint_with_alpha(s->icon_opacity);
	else
		cr->paint();

	cr->restore();
}
void ActivityDrawingArea::drawAxis() {
	// draw a reference axis and pod info
	Glib::RefPtr < Gdk::Window > window = get_window();
	Cairo::RefPtr < Cairo::Context > cr = window->create_cairo_context();
	Gtk::Allocation allocation = get_allocation();
	const int width = allocation.get_width();
	const int height = allocation.get_height();

	//draw axis
	cr->save();
	cr->set_line_width(2.0);
	this->setSourceRGB(cr, currentColourScheme.getAxisColour());
	cr->set_font_size(12);

	cr->move_to(0, height / 2);
	cr->line_to(width, height / 2);

	cr->move_to(190, 25 + height / 2);
	cr->show_text("20");
	cr->move_to(390, 25 + height / 2);
	cr->show_text("40");
	cr->move_to(590, 25 + height / 2);
	cr->show_text("60");
	cr->move_to(790, 25 + height / 2);
	cr->show_text("80");

	cr->stroke();
	cr->restore();
}
Beispiel #3
0
void NodeRenderer::shield(const Cairo::RefPtr<Cairo::Context>& cr,
		std::list<shared_ptr<Shield> >& shields,
		AssetCache& cache)
{
	// nothing to print
	if (s->shield_text.str().size() == 0 || s->font_size <= 0)
		return;

	cr->save();

	cr->set_font_size(s->font_size);

	cr->set_font_face(cache.getFont(
			s->font_family.str(),
			s->font_style == Style::STYLE_ITALIC ? Cairo::FONT_SLANT_ITALIC : Cairo::FONT_SLANT_NORMAL,
			s->font_weight == Style::WEIGHT_BOLD ? Cairo::FONT_WEIGHT_BOLD : Cairo::FONT_WEIGHT_NORMAL
		));

	Cairo::TextExtents textSize;
	cr->get_text_extents(s->shield_text.str(), textSize);

	addShield(shields, location, textSize);

	cr->restore();
}
Beispiel #4
0
bool RegionChooser::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) {
    double clipx1, clipx2, clipy1, clipy2;
    cr->get_clip_extents(clipx1, clipy1, clipx2, clipy2);
#endif

    cr->save();
    cr->set_line_width(1);

#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
    const Gdk::Color bg = get_style()->get_bg(Gtk::STATE_NORMAL);
#else
    const Gdk::RGBA bg = get_style_context()->get_background_color();
#endif
    Gdk::Cairo::set_source_rgba(cr, bg);
    cr->paint();

    if (clipy2 > h1) {
        draw_keyboard(cr, clipx1, clipx2);
    }

    if (clipy1 < h1 && instrument) {
        draw_regions(cr, clipx1, clipx2);
    }

    cr->restore();

    return true;
}
Beispiel #5
0
		bool on_expose_event(GdkEventExpose* ev) {
			Glib::RefPtr< Gdk::Window > window = get_window();
			if (window) {
				Cairo::RefPtr< Cairo::Context > ctx = window->create_cairo_context();
				Gtk::Allocation alloc = get_allocation();
				const int height = alloc.get_height();
				const int width = alloc.get_width();

				ctx->scale(width, height); //escala para que ocupe siempre toda la pantalla. Notar que es ancho y después alto.
				ctx->set_line_width(ANCHO_LINEA);
				
				// contorno
				ctx->move_to(0.0, 1.0); // muevo hacia el punto inicial, que arbitrariamente elegí que fuera el de la izquierda abajo
				ctx->line_to(0.0, 0.0); // línea hacia el punto de arriba a la izquierda
				ctx->line_to(1.0, 0.0); // línea hacia el punto de arriba a la derecha
				ctx->line_to(1.0, 1.0); // línea hacia el punto de abajo a la derecha
				ctx->close_path(); // cierro el camino
				ctx->save(); // salvo porque voy a cambiar el color
					ctx->set_source_rgb(1.0, 1.0, 1.0); // seteo el color al blanco
					ctx->fill_preserve(); // relleno todo el cuadrado, preservando el camino para dibujar el contorno
				ctx->restore();
				ctx->stroke(); // pinto el camino en negro

				// triángulo azul de abajo
				ctx->move_to(0.0, 1.0); // muevo hacia el punto inicial, que arbitrariamente elegí que fuera el de la izquierda
				ctx->line_to(0.5, 0.5); // línea hacia el punto del medio
				ctx->line_to(1.0, 1.0); // línea hacia el punto de abajo a la derecha
				ctx->close_path(); // cierro el camino
				ctx->save(); // salvo porque voy a cambiar el color
					ctx->set_source_rgb(0.0, 0.0, 1.0); // seteo el color al azul
					ctx->fill_preserve(); // relleno todo triángulo, preservando el camino para dibujar el contorno
				ctx->restore();
				ctx->stroke(); // pinto el camino en negro

				// triángulo azul de arriba
				ctx->move_to(0.0, 0.0); // muevo hacia el punto inicial, que arbitrariamente elegí que fuera el de la izquierda
				ctx->line_to(0.5, 0.5); // línea hacia el punto del medio
				ctx->line_to(1.0, 0.0); // línea hacia el punto de arriba a la derecha
				ctx->close_path(); // cierro el camino
				ctx->save(); // salvo porque voy a cambiar el color
					ctx->set_source_rgb(0.0, 0.0, 1.0); // seteo el color al azul
					ctx->fill_preserve(); // relleno todo triángulo, preservando el camino para dibujar el contorno
				ctx->restore();
				ctx->stroke(); // pinto el camino en negro				
			}
			return true;			
		}
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
}
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

}
Beispiel #8
0
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();
	}
}
void ActivityDrawingArea::drawPoints(std::map<double, double> & ps, const double reference_line) {
	//std::cout<<"ActivityDrawingArea::drawPoints: " <<std::endl;
	// This is where we draw on the window
	Glib::RefPtr < Gdk::Window > window = get_window();
	Cairo::RefPtr < Cairo::Context > cr = window->create_cairo_context();
	cr->save();
	Gtk::Allocation allocation = get_allocation();
	const int width = allocation.get_width();
	const int height = allocation.get_height();

	cr->set_line_width(2.0);
	//  std::cout<<"ActivityDrawingArea::drawPoints: colour: "<<"("<<main_colour[0]<<","<<main_colour[1]<<","<< main_colour[2] <<std::endl;
	this->setSourceRGB(cr, currentColourScheme.getMainColour());

	//scale the drawing in x and y
	double maxy = 0;
	std::map<double, double>::iterator it_ps = ps.begin();
	while (it_ps != ps.end()) {
		if (it_ps->second < 0 && -(it_ps->second) > maxy) {
			maxy = -(it_ps->second);
		} else if (it_ps->second > 0 && (it_ps->second) > maxy) {
			maxy = (it_ps->second);
		}
		++it_ps;
	}

	double scaley = 0.2 * (double) ActivityDrawingArea::ACTIVITY_HEIGHT / maxy;
	double scalex = 10;

	it_ps = ps.begin();
	if (it_ps != ps.end()) {
		cr->move_to(scalex * it_ps->first, (0.5 * height) - (scaley * it_ps->second));
	} else {
		cr->move_to(0, height / 2);
	}
	while (it_ps != ps.end()) {
		//	std::cout<<"ActivityDrawingArea::drawPoints: " << it_ps->first <<","<<-it_ps->second<<std::endl;
		cr->line_to((scalex * it_ps->first), (0.5 * height) - (scaley * it_ps->second));
		++it_ps;
	}
	cr->stroke();

	// draw reference line if not zero
	if (reference_line>0.00001 || reference_line < -0.00001) {
		Gdk::Color temp_colour(currentColourScheme.getMainColour());
		this->setSourceRGB(cr, Gdk::Color("tomato"));
		cr->set_line_width(1.0);
		const std::vector<double> dashed= { 1.0 };
		cr->set_dash(dashed, 1);
		double scaled_reference_line = (0.5 * height) - (scaley * reference_line);
		double neg_scaled_reference_line = (0.5 * height) + (scaley * reference_line);
		cr->move_to(0, scaled_reference_line);
		cr->line_to(width, scaled_reference_line);
		cr->move_to(0, neg_scaled_reference_line);
			cr->line_to(width, neg_scaled_reference_line);
		cr->stroke();
	}
	cr->restore();
}
Beispiel #10
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
}
Beispiel #11
0
void Anchor::draw(const Cairo::RefPtr<Cairo::Context>& context) const
{
        context->save();
        context->move_to(mX,mY);
        context->set_source_rgb(0., 1., 0.);
        context->rectangle(mX, mY, ANCHOR_WIDTH, ANCHOR_HEIGHT);
        context->fill();
        context->restore();
}
    void Format7DrawingArea::DrawImageDimensionsText( 
        Cairo::RefPtr<Cairo::Context> refCairo,
        unsigned int left, unsigned int top, unsigned int width, unsigned int height )
    {        
        refCairo->save();

        // Set the font parameters
        refCairo->select_font_face( 
            "monospace",
            Cairo::FONT_SLANT_NORMAL, 
            Cairo::FONT_WEIGHT_BOLD );
        refCairo->set_font_size( 10 );

        // Set draw color to black
        refCairo->set_source_rgb(0.0, 0.0, 0.0);       

        // Get width / height of widget
        int widgetWidth = 0;
        int widgetHeight = 0;
        get_window()->get_size( widgetWidth, widgetHeight );

        // Create text for image offset
        char imageOffsets[128];
        sprintf(
            imageOffsets,
            "Start: (%d,%d) End: (%d,%d)",
            left,
            top,
            left + width,
            top + height );
        Cairo::TextExtents offsetExtents;
        refCairo->get_text_extents(imageOffsets, offsetExtents);

        // Draw the offset text
        refCairo->move_to( 
            (widgetWidth/2) - (offsetExtents.width/2),
            (widgetHeight/2) - offsetExtents.height - (offsetExtents.height/2));
        refCairo->show_text( imageOffsets );

        // Create text for image dimensions
        char imageDimensions[128];
        sprintf(
            imageDimensions,
            "Dimensions: %d x %d",
            width,
            height);
        Cairo::TextExtents dimensionsExtents;
        refCairo->get_text_extents(imageDimensions, dimensionsExtents);

        // Draw the dimensions text
        refCairo->move_to( 
            (widgetWidth/2) - (dimensionsExtents.width/2),
            (widgetHeight/2) + dimensionsExtents.height + (dimensionsExtents.height/2));
        refCairo->show_text( imageDimensions );

        refCairo->restore();
    }
Beispiel #13
0
void DependencyArrow::draw(const Cairo::RefPtr<Cairo::Context>& context) const
{
    // the way to compute the (tcx, tcy) single control point of the
    // quadratic
    double dX = mControlPoint.getX() - mOrigin->getX();
    double dY = mControlPoint.getY() - mOrigin->getY();
    double d1 = std::sqrt(dX * dX + dY * dY);
    double d = d1;

    dX = mDestination->getX() - mControlPoint.getX();
    dY = mDestination->getY() - mControlPoint.getY();
    d += std::sqrt(dX * dX + dY * dY);
    double t = d1/d;

    double t1 = 1.0 - t;
    double tSq = t * t;
    double denom = 2.0 * t * t1;

    double tcx = (mControlPoint.getX() - t1 * t1 * mOrigin->getX() -
        tSq * mDestination->getX()) / denom;
    double tcy = (mControlPoint.getY() - t1 * t1 * mOrigin->getY() -
        tSq * mDestination->getY()) / denom;

    // from the single point of the quadratic to the both of the cubic
    double tcxq1 = mOrigin->getX() + 2. * (tcx - mOrigin->getX()) / 3.;
    double tcyq1 = mOrigin->getY() + 2. * (tcy - mOrigin->getY()) / 3.;
    double tcxq2 = mDestination->getX() +
        2. * (tcx - mDestination->getX()) / 3.;
    double tcyq2 = mDestination->getY() +
        2. * (tcy - mDestination->getY()) / 3.;

    // and now to draw,
    std::valarray< double > dashes(2);
    double angle = atan2 (mDestination->getY() - tcyq2,
        mDestination->getX() - tcxq2) + M_PI;
    double x1 = mDestination->getX() + 9 * std::cos(angle - 0.35);
    double y1 = mDestination->getY() + 9 * std::sin(angle - 0.35);
    double x2 = mDestination->getX() + 9 * std::cos(angle + 0.35);
    double y2 = mDestination->getY() + 9 * std::sin(angle + 0.35);
    dashes[0] = 8.0;
    dashes[1] = 3.0;

    context->save();
    context->set_line_width(1);
    context->move_to(mDestination->getX(), mDestination->getY());
    context->line_to(x1,y1);
    context->line_to(x2,y2);
    context->line_to(mDestination->getX(), mDestination->getY());
    context->fill();

    context->set_dash(dashes,0.);
    context->move_to(mOrigin->getX(), mOrigin->getY());
    context->curve_to(tcxq1, tcyq1, tcxq2, tcyq2, mDestination->getX(),
        mDestination->getY());
    context->stroke();
    context->restore();
}
Beispiel #14
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();
      }
    }
  }
}
Beispiel #15
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();
}
Beispiel #16
0
 // helper function to draw an image
 void Draw::draw_img(const Cairo::RefPtr<Cairo::Context>& cr, const Glib::RefPtr<Gdk::Pixbuf>&  img,
     const double translate_x, const double translate_y, const double scale_x, const double scale_y)
 {
     cr->save();
     cr->translate(translate_x, translate_y);
     cr->scale(scale_x, scale_y);
     Gdk::Cairo::set_source_pixbuf(cr, img);
     cr->paint();
     cr->restore();
 }
Beispiel #17
0
void CardWidget::Draw(Cairo::RefPtr<Cairo::Context> cr, int x, int y)
{
	bool highlight = highlightOnHover && isMouseInArea;
	Cairo::RefPtr<Cairo::ImageSurface> image = PrefSlots::getImagesStorage().GetCardImage(card);
	cr->save();
	cr->translate(x, y);
	cr->scale(1.0 * width / image->get_width(), 1.0 * height / image->get_height());
	cr->rectangle(0, 0, image->get_width(), image->get_height());
	cr->clip();
	if( highlight ) {
		cr->save();
		cr->set_source_rgb(0.1, 0.8, 0.1);
		cr->paint();
		cr->restore();
	}
	cr->set_source(image, 0, 0);
	cr->paint_with_alpha( highlight ? 0.7 : 1.0 );
	cr->restore();
}
Beispiel #18
0
void enigma_rotor_window::draw_wheel_pos(Cairo::RefPtr<Cairo::Context> cr, gunichar new_pos)
{
    wheel_pos = new_pos; 
    const char *trans_2 = "00000000011111111112222222";
    const char *trans_1 = "12345678901234567890123456";
    int win_size = ((int)(padded_size)) - 1;
    
    cr->save();
        
        // Draw background of rotor window as a rectangle filled with the rotor background colour
        cr->set_source_rgb(rotor_r, rotor_g, rotor_b);
        cr->rectangle(x - win_size / 2, y - win_size / 2, win_size, win_size); // Set path
        cr->fill_preserve(); // Fill everyting inside the path and preserve the path
        
        // Draw black border around the path, i.e. the rectangle that represents the rotor window        
        cr->set_line_width(1.0);
        cr->set_source_rgb(BLACK);
        cr->stroke();
    
    cr->restore();
    
    cr->save();
        
        // Set colour in which to draw the rotor position
        if (!is_greek)
            cr->set_source_rgb(BLACK); // Default is black
        else
            cr->set_source_rgb(RED); // The greek wheel on M4 has red markings
        
        if (!is_numeric)
        {
            // rotor position is displayed as character A-Z
            print_char(cr, x, y, new_pos, font_size_char);
        }
        else
        {
            // rotor position is displayed as a number 01, 02, ..., 26
            print_char(cr, x - char_width_numeric / 2, y, trans_2[new_pos - 'A'], font_size_numeric);
            print_char(cr, x + char_width_numeric / 2, y, trans_1[new_pos - 'A'], font_size_numeric);   
        }
    
    cr->restore();    
}
Beispiel #19
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();
	}
Beispiel #20
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;
		}
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();
}
Beispiel #22
0
void thin_rotor::draw(Cairo::RefPtr<Cairo::Context> cr)
{
    cr->save();
    
        // Draw rotor window rectangle
        cr->set_source_rgb(red, green, blue);
        cr->set_line_width(1.0);
        cr->rectangle(x - width / 2, y - height / 2, width, height);
        cr->fill();
        cr->stroke();
    
    cr->restore();    
    
    cr->save();
    
        // Draw rotor position
        cr->set_source_rgb(BLACK);
        print_char(cr, x, y, wheel_pos, width - 2);
        
    cr->restore();    
}
Beispiel #23
0
void cairo::draw_centered_text( const Cairo::RefPtr<Cairo::Context>& cr, const std::string& utf8, const cairo_coord_t& pos )
{
  cr->save();

  Cairo::TextExtents texts;
  cr->get_text_extents( utf8, texts );

  cr->move_to( pos[0] - texts.width/2. - texts.x_bearing , pos[1] );

  cr->show_text( utf8 );

  cr->restore();
}
void ActivityDrawingArea::drawText() {

	// This is where we draw on the window
	Glib::RefPtr < Gdk::Window > window = get_window();
	Cairo::RefPtr < Cairo::Context > cr = window->create_cairo_context();
	cr->save();
	cr->set_line_width(2.0);
	this->setSourceRGB(cr, currentColourScheme.getAxisColour());
	cr->set_font_size(18);
	cr->move_to(0, 20);

	cr->restore();
}
Beispiel #25
0
void PlotContour::draw_plot(const Cairo::RefPtr<Cairo::Context> &cr, const int width, const int height) {
    if (!shown)
        return;

    draw_plot_init(cr, width, height);

    change_plstream_color(pls, axes_color);

    //plot the box with its axes
    pls->adv(0);
    pls->vpor(0.1, 0.9, 0.1, 0.9);
    pls->wind(plotted_range_x[0], plotted_range_x[1],
              plotted_range_y[0], plotted_range_y[1]);
    pls->box( "bcnst", 0.0, 0, "bcnstv", 0.0, 0 );


    //set the label color
    change_plstream_color(pls, titles_color);

    pls->lab(axis_title_x.c_str(), axis_title_y.c_str(), plot_title.c_str());

    //thinks to set before drawing:
    // 1) edge_color
    // 2) edge_width
    change_plstream_color(pls, edge_color);

    pls->width(edge_width);

    auto data = dynamic_cast<PlotDataSurface*>(plot_data[0]);
    std::vector<double> x = data->get_vector_x();
    std::vector<double> y = data->get_vector_y();
    PLcGrid cgrid;
    cgrid.xg = &x[0];
    cgrid.yg = &y[0];
    cgrid.nx = x.size();
    cgrid.ny = y.size();
    double **z = data->get_array2d_z();

    pls->setcontlabelparam(0.01, 0.6, 0.1, is_showing_labels());

    pls->cont(z, x.size(), y.size(), 1, x.size(), 1, y.size(), &clevels[0], nlevels, PLCALLBACK::tr1, (void *) &cgrid);

    free_array2d((void **) z, x.size());

    cr->restore();

    coordinate_transform_plplot_to_cairo(plotted_range_x[0], plotted_range_y[0],
                                         cairo_range_x[0], cairo_range_y[0]);
    coordinate_transform_plplot_to_cairo(plotted_range_x[1], plotted_range_y[1],
                                         cairo_range_x[1], cairo_range_y[1]);
}
Beispiel #26
0
/**
 * Makes the window draw itself.
 */
void Window::redraw()
{
	LOG(kLogDebug, "Redrawing window %p", this);
	needsRedraw = false;
	Cairo::RefPtr<Cairo::Context> context = Cairo::Context::create(store);

	context->save();
	context->set_operator(Cairo::OPERATOR_CLEAR);
	context->paint();
	context->restore();

	draw(context);
	loadTexture();
}
Beispiel #27
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();
}
Beispiel #28
0
void ItemView::drawButtons(const Cairo::RefPtr<Cairo::Context>& cr, const int width, const int height)
{
    cr->save();

    cr->set_antialias(Cairo::ANTIALIAS_NONE);

    if (isSelected())
    {
        drawButton(cr, Resources::res->imgBtnDelete, rectBtnDelete);
        drawButton(cr, Resources::res->imgBtnEdit, rectBtnEdit);
    }

    cr->restore();
}
Beispiel #29
0
//! Only renders the shield background, the text is rendered in renderLabels
void Renderer::renderShields(const Cairo::RefPtr<Cairo::Context>& cr,
							 std::vector<shared_ptr<Shield> >& shields) const
{
	cr->save();

	cr->set_line_join(Cairo::LINE_JOIN_ROUND);

	for (auto& shield : shields)
	{
		const Style* s = shield->style;

		double x0, y0, height, width;
		double border = ceil(s->shield_frame_width/2.0 + s->shield_casing_width);
		x0 = shield->shield.minX + border;
		y0 = shield->shield.minY + border;
		width = shield->shield.getWidth() - 2*border;
		height = shield->shield.getHeight() - 2*border;
		if ((int) s->shield_frame_width % 2 == 1) {
			x0 -= 0.5;
			y0 -= 0.5;
		}
		if (s->shield_shape == Style::ShieldShape::ROUNDED) {
			cr->arc(x0 + height/2.0, y0 + height/2.0,
					height/2.0, boost::math::constants::pi<double>()/2.0, 3.0*boost::math::constants::pi<double>()/2.0);
			cr->arc(x0 + width - height/2.0, y0 + height/2.0,
					height/2.0, 3.0*boost::math::constants::pi<double>()/2.0, boost::math::constants::pi<double>()/2.0);
			cr->close_path();
		} else
			cr->rectangle(x0, y0, width, height);

		// shield casing
		if (s->shield_casing_width > 0) {
			cr->set_source_color(s->shield_casing_color),
			cr->set_line_width(s->shield_frame_width + s->shield_casing_width * 2.0);
			cr->stroke_preserve();
		}

		// shield background
		cr->set_source_color(s->shield_color),
		cr->fill_preserve();

		// shield frame
		cr->set_source_color(s->shield_frame_color),
		cr->set_line_width(s->shield_frame_width);
		cr->stroke();
	}

	cr->restore();
}
Beispiel #30
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();
}