Beispiel #1
0
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);    
    }
}
Beispiel #2
0
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();
}
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();
}
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 #5
0
void RegionChooser::draw_keyboard(const Cairo::RefPtr<Cairo::Context>& cr,
                                  int clip_low, int clip_high) {
    const int h = KEYBOARD_HEIGHT;
    const int w = get_width() - 1;
    const int bh = int(h * 0.55);

    Gdk::Cairo::set_source_rgba(cr, black);
    cr->rectangle(0.5, h1 + 0.5, w, h - 1);
    cr->stroke();

    int x1 = key_to_x(20.5, w);
    Gdk::Cairo::set_source_rgba(cr, grey1);
    cr->rectangle(1, h1 + 1, x1 - 1, h - 2);
    cr->fill();

    int x2 = key_to_x(109.5, w);
    Gdk::Cairo::set_source_rgba(cr, white);
    cr->rectangle(x1 + 1, h1 + 1, x2 - x1 - 1, h - 2);
    cr->fill();

    Gdk::Cairo::set_source_rgba(cr, grey1);
    cr->rectangle(x2 + 1, h1 + 1, w - x2 - 1, h - 2);
    cr->fill();

    Gdk::Cairo::set_source_rgba(cr, black);

    int clipkey1 = std::max(0, x_to_key_right(clip_low - 1, w));
    int clipkey2 = std::min(x_to_key_right(clip_high - 1, w) + 1, 128);

    for (int i = clipkey1 ; i < clipkey2 ; i++) {
        int note = (i + 3) % 12;
        int x = key_to_x(i, w);

        if (note == 1 || note == 4 || note == 6 ||
            note == 9 || note == 11) {
            // black key: short line in the middle, with a rectangle
            // on top
            int x2 = key_to_x(i + 0.5, w);
            cr->move_to(x2 + 0.5, h1 + bh + 0.5);
            cr->line_to(x2 + 0.5, h1 + h - 1);
            cr->stroke();

            int x3 = key_to_x(i + 1, w);
            cr->rectangle(x, h1 + 1, x3 - x + 1, bh);
            cr->fill();
        } else if (note == 3 || note == 8) {
            // C or F: long line to the left
            cr->move_to(x + 0.5, h1 + 1);
            cr->line_to(x + 0.5, h1 + h - 1);
            cr->stroke();
        }

        if (key_pressed[i]) draw_key(cr, i);

        if (note == 3) draw_digit(cr, i);
    }
}
Beispiel #6
0
void BezierPath::Invocation::draw(const Cairo::RefPtr<Cairo::Context> & cr)
{
	if (!path) return;	
	
	//Execute the bezier path.
	path->execute(cr);
	
	//Stroke, fill or do both.
	if (stroke && fill) {
		cr->fill_preserve();
		cr->stroke();
	}
	else if (stroke) cr->stroke();
	else if (fill)   cr->fill();
}
Beispiel #7
0
bool Balls::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();

  cr->save();
  cr->scale(width, height);

  cr->set_line_width(0.001);
  for (auto ball : balls_)
    {
      cr->set_source_rgb(ball.color_r,ball.color_g,ball.color_b);
      cr->arc(ball.p.x,ball.p.y,
              ball.rad,
              0,2*M_PI);
      cr->fill();
      cr->stroke();
    }

  cr->restore();

  const Ball &ball1 = balls_[balls_.size()-1];
  std::ostringstream info;
  info << "x = " << ball1.p.x << "\ny = " << ball1.p.y;
  infobox_.show(cr,width,height,info.str());

  return true;
}
Beispiel #8
0
void
HomVectorDrawer::draw(Cairo::RefPtr<Cairo::Context>& context)
{
  context->save();

  HomPoint start, end;
  if (m_offset)
    {
      start = HomPoint( m_offset->x(), m_offset->y() );
      end   = HomPoint( m_offset->x() + m_vector->x(),
			m_offset->y() + m_vector->y() );
    }
  else
    {
      start = HomPoint( 0.0, 0.0 );
      end   = HomPoint( m_vector->x(), m_vector->y() );
    }

  context->move_to( start.x(), start.y() );
  context->line_to( end.x()  , end.y()   );
  context->arc( end.x(), end.y(), 0.06, 0.0, 2.0 * M_PI);
  context->fill();

  context->stroke();
  context->restore();
}
static void
skillgui_cairo_render_bezier(GVJ_t * job, pointf * A, int n, int arrow_at_start,
		int arrow_at_end, int filled)
{
#ifdef USE_GVPLUGIN_TIMETRACKER
  __tt.ping_start(__ttc_bezier);
  ++__num_bezier;
#endif
  //printf("Bezier\n");
  SkillGuiCairoRenderInstructor *cri = (SkillGuiCairoRenderInstructor *)job->context;
  Cairo::RefPtr<Cairo::Context> cairo = cri->get_cairo();
  obj_state_t *obj = job->obj;

  skillgui_cairo_set_penstyle(cairo, job);

  cairo->move_to(A[0].x, -A[0].y);
  for (int i = 1; i < n; i += 3)
    cairo->curve_to(A[i].x, -A[i].y, A[i + 1].x, -A[i + 1].y,
		    A[i + 2].x, -A[i + 2].y);
  if (filled) {
    skillgui_cairo_set_color(cairo, &(obj->fillcolor));
    cairo->fill_preserve();
  }
  skillgui_cairo_set_color(cairo, &(obj->pencolor));
  cairo->stroke();

#ifdef USE_GVPLUGIN_TIMETRACKER
  __tt.ping_end(__ttc_bezier);
#endif
}
static void
skillgui_cairo_render_polyline(GVJ_t * job, pointf * A, int n)
{
#ifdef USE_GVPLUGIN_TIMETRACKER
  __tt.ping_start(__ttc_polyline);
  ++__num_polyline;
#endif
  //printf("Polyline\n");
  SkillGuiCairoRenderInstructor *cri = (SkillGuiCairoRenderInstructor *)job->context;
  Cairo::RefPtr<Cairo::Context> cairo = cri->get_cairo();
  obj_state_t *obj = job->obj;

  skillgui_cairo_set_penstyle(cairo, job);

  //cairo->set_line_width(obj->penwidth * job->scale.x);
  cairo->move_to(A[0].x, -A[0].y);
  for (int i = 1; i < n; i++) {
    cairo->line_to(A[i].x, -A[i].y);
  }
  skillgui_cairo_set_color(cairo, &(obj->pencolor));
  cairo->stroke();

#ifdef USE_GVPLUGIN_TIMETRACKER
  __tt.ping_end(__ttc_polyline);
#endif
}
Beispiel #11
0
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;
}
Beispiel #12
0
        /** 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;
        }
Beispiel #13
0
void MapDrawArea::DrawOptimalPath(const Cairo::RefPtr<Cairo::Context>& cr)
{
	// This is where we draw on 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);
	const Coord maxXY = guiMapData.copyMaxCoord();

	// Copy the optimal path to the draw area
	std::vector<Coord> optimalPath = guiMapData.copyOptPath();

	// Plot the path
	cr->save();
	cr->set_source_rgb(1.0, 0.08, 0.58);	// pink for path
	cr->set_line_width(lesser * 0.005);
	cr->set_line_cap(Cairo::LINE_CAP_ROUND);

	for(std::vector<Coord>::iterator itr=optimalPath.begin();itr != optimalPath.end();++itr)
	{
		cr->move_to( int( float(width)*float(itr->x)/float(maxXY.x) ),int( height*float(itr->y)/float(maxXY.y)));
		cr->line_to( int( float(width)*float(itr->x)/float(maxXY.x) ),int( height*float(itr->y)/float(maxXY.y)));
		cr->stroke();
	}
}
void
Renderer_Dragbox::render_vfunc(
	const Glib::RefPtr<Gdk::Window>& drawable,
	const Gdk::Rectangle& /*expose_area*/
)
{
	assert(get_work_area());
	if(!get_work_area())
		return;

	// const synfig::Vector focus_point(get_work_area()->get_focus_point());
	// Warning : Unused focus_point
	int drawable_w = drawable->get_width();
	int drawable_h = drawable->get_height();

	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_curr_point());
	const synfig::Point& drag_point(get_drag_point());

	{
		cr->save();
		cr->set_line_cap(Cairo::LINE_CAP_BUTT);
		cr->set_line_join(Cairo::LINE_JOIN_MITER);
		cr->set_antialias(Cairo::ANTIALIAS_NONE);

		cr->set_line_width(1.0);
		cr->set_source_rgb(0,0,0);
		std::valarray<double> dashes(2);
		dashes[0]=5.0;
		dashes[1]=5.0;
		cr->set_dash(dashes, 0);

		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->rectangle(
			tl[0],
			tl[1],
			br[0]-tl[0],
			br[1]-tl[1]
		);
		cr->stroke();

		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();
}
void Simple_GOL_Area::draw_grid(const Cairo::RefPtr<Cairo::Context>& cr, int window_width, int window_height)
{	
	int data_amount = sim_data->get_size();
	
	if (data_amount != 0)
	{
		//sim_data->set_width(20);
		double step_value_x = double(window_width)/double(sim_data->get_width());
		double step_value_y = double(window_height)/double(sim_data->get_height());

		cr->save();
	
		cr->set_line_width(1.0);
		cr->set_source_rgb(0.5,0.5,1);
		cr->move_to(0,0);

		for(double i=0; i<window_width; i = i+ step_value_x)
		{
			cr->move_to(i, 0);
			cr->line_to(i, window_height);
		}
	
		for(double i=0; i<window_height; i = i+step_value_y)
		{
			cr->move_to(0, i);
			cr->line_to(window_width, i);
		}
	
		cr->stroke();
		cr->restore();
	}	
}
Beispiel #17
0
void GraphicalItem::drawRoundedRectangle(
    const Cairo::RefPtr<Cairo::Context>& context,
    int x, int y,
    int width, int height,
    double aspect,
    double corner_radius,
    double red, double green, double blue)
{
    double radius = corner_radius / aspect;
    double degrees = M_PI / 180.0;

    context->begin_new_sub_path();
    context->arc(x + width - radius, y + radius, radius,
        -90 * degrees, 0 * degrees);
    context->arc(x + width - radius, y + height - radius,
        radius, 0 * degrees, 90 * degrees);
    context->arc(x + radius, y + height - radius, radius,
        90 * degrees, 180 * degrees);
    context->arc(x + radius, y + radius, radius,
        180 * degrees, 270 * degrees);
    context->close_path();

    context->set_source_rgb(red, green, blue);
    context->fill_preserve();
    setColor(Settings::settings().getForegroundColor(), context);
    context->stroke();
}
Beispiel #18
0
/* Callback on_draw */
bool SensorsMap::on_draw (const Cairo::RefPtr<Cairo::Context>& cr)
{
  /* Get window allocation */
  Gtk::Allocation allocation = get_allocation ();
  const int width = allocation.get_width ();
  const int height = allocation.get_height ();

  /* Get center of the window */
  int xc, yc;
  xc = width / 2;
  yc = height / 2;

// DEBUG
cr->set_line_width(10.0);

// draw red lines out from the center of the window
cr->set_source_rgb(0.8, 0.0, 0.0);
cr->move_to(0, 0);
cr->line_to(xc, yc);
cr->line_to(0, height);
cr->move_to(xc, yc);
cr->line_to(width, yc);
cr->stroke();
// END DEBUG

  /* Return success */
  return true;
}
bool MyWidget::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
  const double scale_x = (double)get_allocation().get_width() / m_scale;
  const double scale_y = (double)get_allocation().get_height() / m_scale;

  // paint the background
  Gdk::Cairo::set_source_rgba(cr, get_style_context()->get_background_color());
  cr->paint();

  // draw the foreground
  Gdk::Cairo::set_source_rgba(cr, get_style_context()->get_color());
  cr->move_to(155.*scale_x, 165.*scale_y);
  cr->line_to(155.*scale_x, 838.*scale_y);
  cr->line_to(265.*scale_x, 900.*scale_y);
  cr->line_to(849.*scale_x, 564.*scale_y);
  cr->line_to(849.*scale_x, 438.*scale_y);
  cr->line_to(265.*scale_x, 100.*scale_y);
  cr->line_to(155.*scale_x, 165.*scale_y);
  cr->move_to(265.*scale_x, 100.*scale_y);
  cr->line_to(265.*scale_x, 652.*scale_y);
  cr->line_to(526.*scale_x, 502.*scale_y);
  cr->move_to(369.*scale_x, 411.*scale_y);
  cr->line_to(633.*scale_x, 564.*scale_y);
  cr->move_to(369.*scale_x, 286.*scale_y);
  cr->line_to(369.*scale_x, 592.*scale_y);
  cr->move_to(369.*scale_x, 286.*scale_y);
  cr->line_to(849.*scale_x, 564.*scale_y);
  cr->move_to(633.*scale_x, 564.*scale_y);
  cr->line_to(155.*scale_x, 838.*scale_y);
  cr->stroke();

  return true;
}
Beispiel #20
0
void
ColorSlider::draw_arrow(
	const Cairo::RefPtr<Cairo::Context> &cr,
	double x, double y,
	double width, double height,
	int size,
	bool fill)
{
	//TODO hardcoded colors
	Color dark(0, 0, 0);
	Color light(1, 1, 1);

	//!TODO FActorize ! (Duplicate code with "Widget_Keyframe_List::draw_arrow")
	//! Upper black pointing down arrow
	cr->set_source_rgb(dark.get_r(), dark.get_g(), dark.get_b());
	cr->set_line_width(1.0);
	cr->move_to(x, y);
	cr->line_to(x - 0.5*width, y - height);
	cr->line_to(x + 0.5*width, y - height);
	cr->close_path();
	if (fill)
	{
/*		//! Draw on outline
		cr->fill_preserve();
		cr->set_source_rgb(light.get_r(), light.get_g(), light.get_b());
		cr->stroke();
*/
		cr->fill();
	}else cr->stroke();

	//! Bottom light pointing up arrow
	cr->set_source_rgb(light.get_r(), light.get_g(), light.get_b());
	cr->set_line_width(1.0);
	cr->move_to(x, size - height);
	cr->line_to(x - 0.5*width, size);
	cr->line_to(x + 0.5*width, size);
	cr->close_path();
	if (fill)
	{
/*		//! Draw on outline
		cr->fill_preserve();
		cr->set_source_rgb(dark.get_r(), dark.get_g(), dark.get_b());
		cr->stroke();
*/
		cr->fill();
	}else cr->stroke();
}
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
}
Beispiel #22
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;			
		}
Beispiel #23
0
    void NodeSurface::DrawRoundedRectangle( 
        Cairo::RefPtr<Cairo::Context> refCairo, 
        double x, 
        double y, 
        double width, 
        double height, 
        double radius,
        double red,
        double green,
        double blue,
        bool selected )
    {
        refCairo->save();

        if ( (radius > height/2.0) || (radius > width/2.0) )
        {
            radius = std::min<double>(height / 2, width / 2);
        }

        refCairo->move_to( x, y + radius );
        refCairo->arc( x + radius, y + radius, radius, sk_pi, -sk_pi / 2.0 );
        refCairo->line_to( x + width - radius, y );
        refCairo->arc( x + width - radius, y + radius, radius, -sk_pi / 2.0, 0 );
        refCairo->line_to( x + width, y + height - radius );
        refCairo->arc( x + width - radius, y + height - radius, radius, 0, sk_pi / 2.0 );
        refCairo->line_to( x + radius, y + height );
        refCairo->arc( x + radius, y + height - radius, radius, sk_pi / 2.0, sk_pi );
        refCairo->close_path();

        refCairo->set_source_rgb( red, green, blue );
        refCairo->fill_preserve();

        if ( selected == true )
        {
            refCairo->set_source_rgb( 1.0, 0.0, 0.0 );
            refCairo->set_line_width( 2 );
            refCairo->stroke();   
        }
        else
        {
            refCairo->set_source_rgb( 0.0, 0.0, 0.0 );
            refCairo->set_line_width( 1 );
            refCairo->stroke();   
        }            

        refCairo->restore();
    }
Beispiel #24
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();
	}
}
Beispiel #25
0
/** \brief Signal handler.
    \param cr is a pointer to the cairo context
    \return always true

    Draws population development (of preys and predators) in the cairo
    context object.
 */
bool
Graph::on_draw (const Cairo::RefPtr<Cairo::Context> &cr) {
    int w = get_width();
    int h = get_height();

    if (_is_enabled) {
        cr->save();

        cr->rectangle(0, 0, w, h);
        cr->set_source_rgb(1, 1, 1);
        cr->fill();

        Bounded<TValues::size_type> startb(0, 0, _values[PREY].size());
        Bounded<TValues::size_type> stopb(0, 0, _values[PREY].size());
        TValues::size_type start = 0;
        TValues::size_type stop = 0;

        if (_cont_zoom) {
            stop = _values[PREY].size();
            start = 0;
        }
        else {
            if (_cont_pos) {
                stopb = _values[PREY].size();
                start = (stopb - _visible_range).get_value();
                stop = start + _visible_range;
            }
            else {
                start = _visible_position;
                stop = start + _visible_range;
            }
        }

        draw_line(cr, _values[PREY], _max_values[PREY], start, stop);
        cr->set_source_rgb(0, 0, 0);
        cr->stroke();

        draw_line(cr, _values[PREDATOR], _max_values[PREDATOR],  start, stop);
        cr->set_source_rgb(1, 0, 0);
        cr->stroke();

        cr->restore();
    }

    return true;
}
Beispiel #26
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 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;
}
void MonitorInterface::dibujar_division_y(Cairo::RefPtr < Cairo::Context >& cr, size_t cant_div, double& offsety, double& offsetx) {
	double distancia = 1/double(cant_div);
	for(size_t i=0;i<cant_div;++i){
		cr->set_line_width(0.009);
		cr->move_to(offsetx-largo/2	,i*distancia-offsety);
		cr->line_to(offsetx+largo/2	,i*distancia-offsety);
		cr->stroke();
	}
}
Beispiel #29
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 #30
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();
      }
    }
  }
}