コード例 #1
0
ファイル: cairo_visualizer.cpp プロジェクト: urp/urban-robots
void cairo::draw_face_edge_sequences( const Cairo::RefPtr<Cairo::Context>& cr, const Geodesics::surface_type::edge_descriptor& edge, const Geodesics& m_geodesics )
{
  const auto    e0out = Geodesics::edge_handle( edge, m_geodesics.get_surface() );
  const auto 	e0w   = m_geodesics.edge_windows( e0out );
  const auto 	e0in  = e0out.opposite();
  const coord_t e0len = e0out.length();

  // draw base
  draw_edge_sequences( cr, e0w.first, e0w.second, m_geodesics );

  // draw lower left edge

  if( ! e0in.second ) return ;
  auto e1out = e0in.first.next().opposite();

  if( e1out.second )
  {
	auto e1w = m_geodesics.edge_windows( e1out.first );
    const coord_t e1len = e1out.first.length();
    cr->save();

      cr->rotate( - e0in.first.next_inner_angle() );

	  cr->translate( e1len, 0. );

	  cr->rotate( M_PI );
	  //cr->scale( -1., -1. );

      draw_edge_sequences( cr, e1w.first, e1w.second, m_geodesics );

    cr->restore();
  }


  // draw lower right edge

  const Geodesics::edge_handle e2in = e0in.first.previous();
  const auto e2out = e2in.opposite();

  if( ! e2out.second ) return;

  auto e2w = m_geodesics.edge_windows( e2out.first );

  cr->save();

	cr->translate( e0len, 0. );

    cr->rotate( e2in.next_inner_angle() );

    cr->scale( -1., -1. );

    draw_edge_sequences( cr, e2w.first, e2w.second, m_geodesics );

  cr->restore();
}
コード例 #2
0
ファイル: cairo_visualizer.cpp プロジェクト: urp/urban-robots
void cairo::draw_edge_sequence( const Cairo::RefPtr<Cairo::Context>& cr, const Window& window, const Geodesics& m_geodesics, const rgba_color_ref_t& color )
{
  Geodesics::edge_handle edge( window.edge, m_geodesics.get_surface() );

  draw_triangle( cr, edge );

  draw_window( cr, window, color );

  if( window.predeccessor() )
  {
    const Window&          predwin = *window.predeccessor();
    Geodesics::edge_handle prededge( predwin.edge, m_geodesics.get_surface() );

    assert( prededge.opposite().second );

    cr->save();

    if( prededge.source() == edge.source() )
    { // predeccessor on previous edge
	  assert( edge.previous().opposite().first == prededge );
      cr->rotate( edge.previous().next_inner_angle() );
    }else
    {
      assert( prededge.target() == edge.target() );
	  assert( edge.next().opposite().first == prededge );
      // predeccessor on next edge
      cr->translate( edge.length(), 0. );
      cr->rotate( - edge.next_inner_angle() );
      cr->translate( - prededge.length(), 0. );

    }

    draw_edge_sequence( cr, predwin, m_geodesics, color );

    cr->restore();
  }
}
コード例 #3
0
ファイル: texr.cpp プロジェクト: sheik/five-lights
/* Draw the word cairo at NUM_TEXT different angles */
void draw(Cairo::RefPtr<Cairo::Context> cr, int width, int height)
{
    int i, x_off, y_off;
    Cairo::TextExtents extents;
    std::string text("cairo");

    cr->select_font_face("Bitstream Vera Sans", Cairo::FONT_SLANT_NORMAL,
            Cairo::FONT_WEIGHT_NORMAL);
    cr->set_font_size(TEXT_SIZE);

    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->set_source_rgb(0.0, 0.0, 0.0);

    cr->translate(width / 2.0, height / 2.0);

    cr->get_text_extents(text, extents);

    if (NUM_TEXT == 1)
    {
        x_off = y_off = 0;
    }
    else
    {
        y_off = (int) - floor(0.5 + extents.height / 2.0);
        x_off = (int) floor(0.5 + (extents.height + 1.0) / (2.0 * tan (M_PI / NUM_TEXT)));
    }

    for (i=0; i < NUM_TEXT; i++)
    {
        cr->save();
        cr->rotate(2 * M_PI * i / NUM_TEXT);
        cr->set_line_width(1.0);
        cr->set_source_rgb(1, 0, 0);
        cr->stroke();
        cr->move_to(x_off - extents.x_bearing, y_off - extents.y_bearing);
        cr->set_source_rgb(0, 0, 0);
        cr->show_text("Five Lights!");
        cr->restore();
    }
}
コード例 #4
0
/** Button press event handler.
 * @param event event data
 * @return true
 */
bool
LaserDrawingArea::on_button_press_event(GdkEventButton *event)
{
  __last_mouse_x = event->x;
  __last_mouse_y = event->y;

  double user_x = event->x;
  double user_y = event->y;
  Glib::RefPtr<Gdk::Window> window = get_window();
  Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
  cr->save();
  cr->translate(__xc, __yc);
  cr->rotate(0.5 * M_PI + __rotation);
  cr->scale(-__zoom_factor, __zoom_factor);
  cr->device_to_user(user_x, user_y);
  printf("Clicked at (%.3lf, %.3lf)\n", user_x, user_y);
  cr->restore();
  return true;
}
コード例 #5
0
/** Draw Beams of an interface.
 * Draws the beams as lines, circles or hull, depending on draw mode.
 * @param itf either Laser360Interface or Laser720Interface
 * @param window Gdk window
 * @param cr Cairo context to draw to. It is assumed that possible transformations
 * have been setup before.
 */
void
LaserDrawingArea::draw_beams(const fawkes::Interface *itf,
                             Glib::RefPtr<Gdk::Window> &window,
			     const Cairo::RefPtr<Cairo::Context> &cr)
{
  float *distances;
  size_t nd;
  bool clockwise;
  const fawkes::Laser360Interface* itf360 = NULL;
  const fawkes::Laser720Interface* itf720 = NULL;
  if ((itf360 = dynamic_cast<const fawkes::Laser360Interface*>(itf))) {
    distances = itf360->distances();
    nd = itf360->maxlenof_distances();
    clockwise = itf360->is_clockwise_angle();
  } else if ((itf720 = dynamic_cast<const fawkes::Laser720Interface*>(itf))) {
    distances = itf720->distances();
    nd = itf720->maxlenof_distances();
    clockwise = itf720->is_clockwise_angle();
  } else {
    throw fawkes::Exception("Interface is neither Laser360Interface nor Laser720Interface");
  }

  const float nd_factor = 360.0 / nd;


  float *revdists = NULL;
  if (! clockwise) {
    // re-arrange to clockwise
    revdists = (float *)new float[nd];
    for (size_t i = 0; i < nd; ++i) {
      revdists[nd - i] = distances[i];
    }
    distances = revdists;
  }

  cr->scale(__zoom_factor, __zoom_factor);
  cr->rotate(__rotation);
  cr->set_line_width(1. / __zoom_factor);

  draw_scalebox(window, cr);

  if ( __draw_mode == MODE_LINES ) {
    for (size_t i = 0; i < nd; i += __resolution) {
      if ( distances[i] == 0 || ! std::isfinite(distances[i]) )  continue;
      const float anglerad = deg2rad(i * nd_factor);
      cr->move_to(0, 0);
      cr->line_to(distances[i] *  sin(anglerad),
		  distances[i] * -cos(anglerad));
    }
    cr->stroke();
  } else if ( __draw_mode == MODE_POINTS ) {
    const float radius = 4 / __zoom_factor;
    for (size_t i = 0; i < nd; i += __resolution) {
      if ( distances[i] == 0 )  continue;
      float anglerad = deg2rad(i * nd_factor);
      float x = distances[i] *  sin(anglerad);
      float y = distances[i] * -cos(anglerad);
      // circles replaced by rectangles, they are a *lot* faster
      //cr->move_to(x, y);
      //cr->arc(x, y, radius, 0, 2*M_PI);
      cr->rectangle(x, y, radius, radius);
    }
    cr->fill_preserve();
    cr->stroke();
  } else {
    cr->move_to(0, - distances[0]);
    for (size_t i = __resolution; i <= nd + __resolution; i += __resolution) {
      if ( distances[i] == 0 )  continue;
      const float anglerad    = normalize_rad(deg2rad(i * nd_factor));
      cr->line_to(distances[i % nd] *  sin(anglerad),
		  distances[i % nd] * -cos(anglerad));
    }
    cr->stroke();
  }

  if (revdists) delete[] revdists;
}
コード例 #6
0
/** Expose event handler.
 * @param event event info structure.
 * @return signal return value
 */
bool
LaserDrawingArea::on_expose_event(GdkEventExpose* event)
#endif
{
  // This is where we draw on the window
  Glib::RefPtr<Gdk::Window> window = get_window();
  if(window) {
    Gtk::Allocation allocation = get_allocation();

    if(__first_draw)
    {
      __first_draw = false;
      const int width = allocation.get_width();
      const int height = allocation.get_height();
    
      // coordinates for the center of the window
      __xc = width / 2;
      __yc = height / 2;
    }
#if GTK_VERSION_LT(3,0)
    Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
#endif
    cr->set_line_width(1.0);

    cr->set_source_rgb(1, 1, 1);
#if GTK_VERSION_LT(3,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->fill_preserve();
    cr->clip();
#else
    cr->paint();
#endif
    cr->set_source_rgb(0, 0, 0);
    //cr->set_source_rgba(0,0,0,1);

    //    __last_xc += __translation_x;
    //    __last_yc += __translation_y;
    cr->translate(__xc, __yc);
  
    cr->save();
    if (! __connected) {
      Cairo::TextExtents te;
      std::string t = "Not connected to BlackBoard";
      cr->set_source_rgb(1, 0, 0);
      cr->set_font_size(20);
      cr->get_text_extents(t, te);
      cr->move_to(- te.width / 2, -te.height / 2);
      cr->show_text(t);
    } else if ( __laser_ifs.empty() ) {
      Cairo::TextExtents te;
      std::string t = "No interface opened";
      cr->set_source_rgb(1, 0, 0);
      cr->set_font_size(20);
      cr->get_text_extents(t, te);
      cr->move_to(- te.width / 2, -te.height / 2);
      cr->show_text(t);
    } else if (! all_laser_ifs_have_writer() ) {
      Cairo::TextExtents te;
      std::string t = "No writer for ";
      for (std::list<InterfaceColorPair>::const_iterator it = __laser_ifs.begin();
           it != __laser_ifs.end(); ++it) {
        fawkes::Interface* itf = it->first;
        if (!itf->has_writer()) {
          t += itf->uid();
          t += ' ';
        }
      }
      cr->set_source_rgb(1, 0, 0);
      cr->set_font_size(20);
      cr->get_text_extents(t, te);
      cr->move_to(- te.width / 2, -te.height / 2);
      cr->show_text(t);
    } else {
      if (! __break_drawing) {
        for (std::list<InterfaceColorPair>::const_iterator it = __laser_ifs.begin();
             it != __laser_ifs.end(); ++it) {
          fawkes::Interface* laser_if = it->first;
          laser_if->read();
        }
      }

      for (std::list<InterfaceColorPair>::const_iterator it = __laser_ifs.begin();
           it != __laser_ifs.end(); ++it) {
        const fawkes::Interface* laser_if = it->first;
        const Color& color = it->second;
        cr->save();
        cr->set_source_rgb(color.r, color.g, color.b);
        draw_beams(laser_if, window, cr);
        cr->restore();
      }
      if (__robot_drawer)  __robot_drawer->draw_robot(window, cr);
      for (std::list<InterfaceColorPair>::const_iterator it = __laser_ifs.begin();
           it != __laser_ifs.end(); ++it) {
        const fawkes::Interface* laser_if = it->first;
        const Color& color = it->second;
        cr->save();
        cr->set_source_rgb(color.r, color.g, color.b);
        draw_segments(laser_if, window, cr);
        cr->restore();
      }
      draw_persons_legs(window, cr);

      if(__switch_if != NULL && __switch_if->has_writer()){
	SwitchInterface::EnableSwitchMessage *esm = new SwitchInterface::EnableSwitchMessage();
	__switch_if->msgq_enqueue(esm);
      }
    }
    cr->restore();

    cr->save();
    cr->rotate(0.5 * M_PI + __rotation);
    cr->scale(-__zoom_factor, __zoom_factor);
    cr->set_line_width(1. / __zoom_factor);
    if (__visdisp_if) {
      __visdisp->process_messages();
      __visdisp->draw(cr);
    }

    const float radius = 0.01;
    if (__line_if) {
      __line_if->read();
      if (__line_if->has_writer() &&
	  __line_if->is_valid() && __line_if->is_visible()) {

	cr->set_source_rgb(1, 0, 0);
	/*
	std::vector<double> dashes(1);
	dashes[0] = 0.1;
	cr->set_dash(dashes, 0);
	*/
	cr->rectangle(__line_if->world_x() - radius * 0.5, __line_if->world_y() - radius * 0.5, radius, radius);
	cr->rectangle(__line_if->relative_x() - radius * 0.5, __line_if->relative_y() - radius * 0.5, radius, radius);
	cr->fill_preserve();
	cr->stroke();
	cr->move_to(__line_if->world_x(), __line_if->world_y());
	cr->line_to(__line_if->relative_x(), __line_if->relative_y());
	cr->stroke();
      }
    }
    cr->restore();
  }

  return true;
}
コード例 #7
0
ファイル: huitu___.cpp プロジェクト: zzzzzzzzzzz0/zhscript
	void rotate__(Glib::ustring& d1){
		cr_->rotate(s2f__(d1));
	}
コード例 #8
0
ファイル: PhotoPreview.cpp プロジェクト: adsllc/muenstercam
bool PhotoPreview::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) {
	if (!Image)
		return false;

	int Width,Height;
	Gtk::Allocation Allocation = get_allocation();
	Width=Allocation.get_width();
	Height=Allocation.get_height();

	if (Width<=1 || Height<=1)
		return false;

	/* Scale the photo */
	Glib::RefPtr<Gdk::Pixbuf> Scaled;

	/* Preserve aspect ratio */
	double ImageAspectRatio,PreviewAspectRatio;
	PreviewAspectRatio=(float)Width/Height;
	ImageAspectRatio=(float)Image->get_width()/Image->get_height();
	if (ImageAspectRatio<PreviewAspectRatio) {
		Width=Height*ImageAspectRatio;
	} else {
		Height=Width/ImageAspectRatio;
	}

	Scaled=Image->scale_simple(
		Width,
		Height,
		Gdk::INTERP_BILINEAR);

	if (Cfg->GetFlipPreview())
		Scaled=Scaled->flip();

	Gdk::Cairo::set_source_pixbuf(cr, Scaled,
		(Allocation.get_width()/2)-(Scaled->get_width()/2),
		(Allocation.get_height()/2)-(Scaled->get_height()/2)
		);
	cr->paint();

	double TimeLeft=Util::TimeDiff(&PhotoTime,NULL);
	double MinDim=get_width();
	if (get_height()<MinDim)
		MinDim=get_height();

	if (Overlay.length()==0 && TimeLeft>0) {
		double TotalTime=Cfg->GetCountdownCount()*(Cfg->GetCountdownTimeout()/1000.0);
		unsigned int Whole=floor(Cfg->GetCountdownCount()*TimeLeft/TotalTime);
		float Frac=(Cfg->GetCountdownCount()*TimeLeft/TotalTime)-Whole;

		Cairo::RefPtr<Cairo::Context> Context = get_window()->create_cairo_context();

		Context->set_source_rgba(1.0, 1.0, 1.0,0.5);
		Context->translate(get_width()/2.0,get_height()/2.0);

		/* Draw the fractional portion of the countdown */
		Context->save();
		Context->rotate(M_PI/2.0);
		Context->arc(0.0,0.0,MinDim/4.0,0,Frac*2*M_PI);
		Context->fill();
		Context->restore();

		/* Draw the Whole portion of the countdown */
		Context->save();
		Context->set_font_size(MinDim/2.0);
		char StrBuf[1024];
		snprintf(StrBuf,sizeof(StrBuf),"%d",Whole+1);
		Cairo::TextExtents Extents;
		Context->get_text_extents(StrBuf,Extents);
		Context->translate(-Extents.width/2.0,Extents.height/2.0);

		Context->show_text(StrBuf);
		Context->stroke();
		Context->restore();
	}

	if (Overlay.length()) {
		Cairo::RefPtr<Cairo::Context> Context = get_window()->create_cairo_context();
		Context->set_source_rgba(1.0, 1.0, 1.0,0.5);
		Context->translate(get_width()/2.0,get_height()/2.0);

		Context->save();
		Context->set_font_size(MinDim/2.0);
		Cairo::TextExtents Extents;
		Context->get_text_extents(Overlay,Extents);
		Context->translate(-Extents.width/2.0,Extents.height/2.0);

		Context->show_text(Overlay);
		Context->stroke();
		Context->restore();
	}

	return true;
}
コード例 #9
0
static void
skillgui_cairo_render_textpara(GVJ_t *job, pointf p, textpara_t *para)
{
#ifdef USE_GVPLUGIN_TIMETRACKER
  __tt.ping_start(__ttc_text);
  ++__num_text;
#endif
  SkillGuiCairoRenderInstructor *cri = (SkillGuiCairoRenderInstructor *)job->context;
  Cairo::RefPtr<Cairo::Context> cairo = cri->get_cairo();
  obj_state_t *obj = job->obj;

  Cairo::FontWeight weight = Cairo::FONT_WEIGHT_NORMAL;
  Cairo::FontSlant slant   = Cairo::FONT_SLANT_NORMAL;
  char *fontweight = NULL;
  char *fontslant = NULL;
  if (obj->type == CLUSTER_OBJTYPE) {
    fontweight = agget(obj->u.sg, (char *)"fontweight");
    fontslant  = agget(obj->u.sg, (char *)"fontslant");
  } else if (obj->type == ROOTGRAPH_OBJTYPE) {
    fontweight = agget(obj->u.g, (char *)"fontweight");
    fontslant  = agget(obj->u.g, (char *)"fontslant");
  } else if (obj->type == NODE_OBJTYPE) {
    fontweight = agget(obj->u.n, (char *)"fontweight");
    fontslant  = agget(obj->u.n, (char *)"fontslant");
  } else if (obj->type == EDGE_OBJTYPE) {
    fontweight = agget(obj->u.e, (char *)"fontweight");
    fontslant  = agget(obj->u.e, (char *)"fontslant");
  }
  if (fontweight && (strcmp(fontweight, "bold") == 0)) {
    weight = Cairo::FONT_WEIGHT_BOLD;
    p.x -= 8;
  }
  if (fontslant && (strcmp(fontslant, "italic") == 0)) {
    slant = Cairo::FONT_SLANT_ITALIC;
  }

  double offsetx = 0.0;
  double offsety = 0.0;
  double rotate  = 0.0;

  if ( (obj->type == EDGE_OBJTYPE) && (strcmp(para->str, obj->headlabel) == 0) ) {
    char *labelrotate = agget(obj->u.e, (char *)"labelrotate");
    if (labelrotate && (strlen(labelrotate) > 0)) {
      rotate = fawkes::deg2rad(atof(labelrotate));
    }
    char *labeloffsetx = agget(obj->u.e, (char *)"labeloffsetx");
    if (labeloffsetx && (strlen(labeloffsetx) > 0)) {
      offsetx = atof(labeloffsetx);
    }
    char *labeloffsety = agget(obj->u.e, (char *)"labeloffsety");
    if (labeloffsety && (strlen(labeloffsety) > 0)) {
      offsety = atof(labeloffsety);
    }
  }
  //__tt.ping_start(__ttc_text_1);

  Cairo::Matrix old_matrix;
  cairo->get_matrix(old_matrix);

  if (__fontname) {
    cairo->select_font_face(__fontname, slant, weight);
  } else {
    cairo->select_font_face(para->fontname, slant, weight);
  }
  cairo->set_font_size(para->fontsize);
  //cairo->set_font_options ( Cairo::FontOptions() );
  //cairo->set_line_width(1.0);

  Cairo::TextExtents extents;
  cairo->get_text_extents(para->str, extents);

  if (para->just == 'r') {
    p.x -= extents.width;
  } else if (para->just != 'l') {
    p.x -= extents.width / 2.0;
  }

  cairo->move_to(p.x + offsetx, -p.y + offsety);
  cairo->rotate(rotate);
  skillgui_cairo_set_color(cairo, &(obj->pencolor));
  cairo->text_path( para->str );
  cairo->fill();

  cairo->set_matrix(old_matrix);

  //__tt.ping_end(__ttc_text_5);
#ifdef USE_GVPLUGIN_TIMETRACKER
  __tt.ping_end(__ttc_text);
#endif
}