当前位置: 首页>>代码示例>>C++>>正文


C++ RefPtr::scale方法代码示例

本文整理汇总了C++中cairo::RefPtr::scale方法的典型用法代码示例。如果您正苦于以下问题:C++ RefPtr::scale方法的具体用法?C++ RefPtr::scale怎么用?C++ RefPtr::scale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cairo::RefPtr的用法示例。


在下文中一共展示了RefPtr::scale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: render

void CharacterRenderer::render(const Cairo::RefPtr<Cairo::Context> &cr) {
  unsigned int sprite_index = 0;
  if (first_render_) {
    first_render_ = false;
    last_x_ = position_.x();
  }

  std::vector<Glib::RefPtr<Gdk::Pixbuf> > *images;

  if (std::abs(last_x_ - position_.x()) > THRESHOLD) {
    sprite_index = ((sprite_step_ / 6) % sprites_moving_size()) + 1;
    if (last_x_ - position_.x() > 0.0) {
      right_direction_ = false;
    } else {
      right_direction_ = true;
    }
  }
  if (last_x_ - position_.x() > THRESHOLD) {
    images = &images_left_;
  } else if ((last_x_ - position_.x()) < -THRESHOLD) {
    images = &images_right_;
  } else {
    if (right_direction_) {
      images = &images_right_;
    } else {
      images = &images_left_;
    }
  }

  cr->translate(position_.x(), position_.y());
  cr->scale(1.0 / (*images)[sprite_index]->get_width(), 1.0 / (*images)[sprite_index]->get_height());
  cr->translate(-(*images)[sprite_index]->get_width() / 2, -(*images)[sprite_index]->get_height() / 2);
  Gdk::Cairo::set_source_pixbuf(cr, (*images)[sprite_index], 0, 0);
  cr->paint();
  sprite_step_++;
  last_x_ = position_.x();
}
开发者ID:tinchou,项目名称:bluesjackrabbit,代码行数:37,代码来源:CharacterRenderer.cpp

示例2: if


//.........这里部分代码省略.........
      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;
}
开发者ID:,项目名称:,代码行数:101,代码来源:

示例3: graficar

bool MonitorInterface::graficar(GdkEventExpose* event){
	/* genero ejes de coordenadas
					^
		<<offsetx>>	|
					|-------->
						^
						o
						f
						y
						^
		*/
	Glib::RefPtr<Gdk::Window> ventana= draw_area->get_window();
	if (!ventana) {
		return false;
	}
	Gtk::Allocation allocation = draw_area->get_allocation();
	const int width = allocation.get_width();
	const int height = allocation.get_height();
	Cairo::RefPtr < Cairo::Context > cr = ventana->create_cairo_context();

	// dibujo TEXTO	en el grefico EJE Y
	double distacia_y = height/double(CANT_DIVISIONES);
	syslog(LOG_DEBUG, "Distacia_y: %f", distacia_y);

	double valor =0;
	for(size_t i=1;i<CANT_DIVISIONES-2;++i){
		stringstream aux;
		string auxaux;
		// el -10 es por el tamaño de la letra, ya que se empieza a dibujar desde la pos arriba a la izquierda
		cr->move_to(width*0.02,height -i*distacia_y -offset_y*height -8);

		valor+=(max_medida/(CANT_DIVISIONES));
		aux<<std::setprecision(2)<<fixed<<(valor);
		aux>>auxaux;
		Glib::RefPtr<Pango::Layout> pl = draw_area->create_pango_layout(auxaux);
		//Glib::RefPtr<Pango::FontDescription >desc = pango_font_description_from_string("Sans Bold 8");
		//pango_layout_set_font_description(pl, desc);
		pl->show_in_cairo_context(cr);
	}
	// fin del dibujo del TEXTO EJE Y
	// dibujo eje x
	double distancia_x = width/double(CANT_DIVISIONES);
	int valor_x =-16;
	for(size_t i=0;i<CANT_DIVISIONES;++i){
		stringstream aux_x;
		string auxaux_x;
		cr->move_to(distancia_x*i+ width*offset_x-10, height-offset_y*height+4);
		aux_x<<std::setprecision(2)<<fixed<<(valor_x);
		aux_x>>auxaux_x;
		Glib::RefPtr<Pango::Layout> pl = draw_area->create_pango_layout(auxaux_x);
		pl->show_in_cairo_context(cr);
		valor_x++;

	}
	// fin dibujo ejex
	cr->move_to(width*0.015, height-offset_y*height);
	Glib::RefPtr<Pango::Layout> pl = draw_area->create_pango_layout("MB/seg");
	pl->show_in_cairo_context(cr);
	cr->scale(width, height);

	this->dibujar_ejes(cr);
	this->dibujar_division_x(cr, CANT_DIVISIONES, offset_x, offset_y);
	this->dibujar_division_y(cr, CANT_DIVISIONES, offset_y, offset_x);

	double espacio = 1 / double(medidas.size());
	double x = 0;

	// genero linea de graficos
	cr->set_line_width(0.009);
	cr->set_source_rgba(0.337, 0.612, 0.117, 0.9);
	list<double>::iterator it;
	it = medidas.begin();
	cr->move_to(0 + offset_x, 1 - (*it / max_medida) - offset_y);
	it++;
	for (; it != medidas.end(); ++it) {
		x += espacio;
		cr->line_to(x+offset_x, 1 - (*it / max_medida) -offset_y);
	}

	cr->stroke();

	return true;
}
开发者ID:jorgeCollinet,项目名称:tp-tp5-uba-2013,代码行数:83,代码来源:monitorInterface.cpp

示例4: if

bool studio::Widget_Preview::redraw(GdkEventExpose */*heh*/)
{
	//And render the drawing area
	Glib::RefPtr<Gdk::Pixbuf> pxnew, px = currentbuf;
	cairo_surface_t* cs;
	bool use_cairo= preview->get_use_cairo();
	if(use_cairo)
	{
		if(current_surface)
			cs=cairo_surface_reference(current_surface);
		else
			return true;
	}
	
	int dw = draw_area.get_width();
	int dh = draw_area.get_height();
	
	if(use_cairo && !cs)
		return true;
	else if(!use_cairo && !px)
		return true;
	//made not need this line
	//if ( draw_area.get_height() == 0 || px->get_height() == 0 || px->get_width() == 0)
	//	return true;

	//figure out the scaling factors...
	float sx, sy;
	float q = 1 / preview->get_zoom();
	int nw, nh;
	int w,h;
	
	// grab the source dimensions
	if(use_cairo)
	{
		w=cairo_image_surface_get_width(cs);
		h=cairo_image_surface_get_height(cs);
	}
	else
	{
		w=px->get_width();
		h=px->get_height();
	}

	Gtk::Entry* entry = zoom_preview.get_entry();
	String str(entry->get_text());
	Glib::ustring text = str;
	locale_from_utf8 (text);
	const char *c = text.c_str();

	if (text == _("Fit") || text == "fit")
	{
		sx = dw / (float)w;
		sy = dh/ (float)h;

		//synfig::info("widget_preview redraw: now to scale the bitmap: %.3f x %.3f",sx,sy);

		//round to smallest scale (fit entire thing in window without distortion)
		if(sx > sy) sx = sy;

		//cleanup previous size request
		draw_area.set_size_request();
	}

	//limit zoom level from 0.01 to 10 times
	else if (atof(c) > 1000)
	{
		sx = sy = 10 * q;
	}

	else if (atof(c) <= 0 )
	{
		sx = sy = 0 ;
		draw_area.set_size_request(0, 0);
	}

	else sx = sy = atof(c) / 100 * q;

	//scale to a new pixmap and then copy over to the window
	nw = (int)(w * sx);
	nh = (int)(h * sx);

	if(nw == 0 || nh == 0)return true;

	if(!use_cairo)
		pxnew = px->scale_simple(nw, nh, Gdk::INTERP_NEAREST);

	//except "Fit" or "fit", we need to set size request for scrolled window
	if (text != _("Fit") && text != "fit")
	{
		draw_area.set_size_request(nw, nh);
		dw = draw_area.get_width();
		dh = draw_area.get_height();
	}

	//synfig::info("Now to draw to the window...");
	//copy to window
	Glib::RefPtr<Gdk::Window>	wind = draw_area.get_window();
	Cairo::RefPtr<Cairo::Context> cr = wind->create_cairo_context();

	if(!wind) synfig::warning("The destination window is broken...");
//.........这里部分代码省略.........
开发者ID:berteh,项目名称:synfig,代码行数:101,代码来源:preview.cpp

示例5:

	void scale2__(Glib::ustring& x,Glib::ustring& y){
		cr_->scale(s2f__(x), s2f__(y));
	}
开发者ID:zzzzzzzzzzz0,项目名称:zhscript,代码行数:3,代码来源:huitu___.cpp

示例6: scale__

	void scale__(Glib::ustring& w,Glib::ustring& h){
		cr_->scale(s2i__(w), s2i__(h));
	}
开发者ID:zzzzzzzzzzz0,项目名称:zhscript,代码行数:3,代码来源:huitu___.cpp

示例7: RestoreContext

void Thing::RestoreContext(Cairo::RefPtr<Cairo::Context> myCr) const
{
	myCr->rotate_degrees(-orientationAngle);
	myCr->translate(-position[0], -position[1]);
    myCr->scale(1/scalingFactor, 1/scalingFactor);
}
开发者ID:serena-ivaldi,项目名称:iCub_crawling_old,代码行数:6,代码来源:Thing.cpp

示例8: draw_window

void cairo::draw_window( const Cairo::RefPtr<Cairo::Context>& cr, const Window& window, const rgba_color_ref_t& color )
{

  const ps_t ps = window.pseudosource();

  cairo_coord_t B0( window.bound<LEFT>(), 0 );
  cairo_coord_t B1( window.bound<RIGHT>(), 0 );
  cairo_coord_t PS( ps[0], ps[1] );

  cr->save();

    cr->set_source_rgba( color[0], color[1], color[2], color[3] );

    cr->move_to( B0[0], B0[1] + cr->get_line_width() );

    cr->line_to( B1[0], B1[1] + cr->get_line_width() );

    cr->stroke();

    std::vector<double> dashes(2);
    dashes[0] = 2. * user_unit_distance( cr ).length();
    dashes[1] = 10. * user_unit_distance( cr ).length();

    cr->set_dash( dashes, 0. );

    cr->set_source_rgba( color[0], color[1], color[2], color[3]*.5 );

    cr->move_to( B1[0], B1[1] );

    cr->line_to( PS[0], PS[1] );

    cr->line_to( B0[0], B0[1] );

    cr->stroke();

  cr->restore();

  cr->save();

    cr->set_font_size( 8. * user_unit_distance( cr ).length() );

    cr->set_source_rgba( color[0], color[1], color[2], 1. );

    std::ostringstream nrss;
    nrss << window.id;

    cairo_coord_t pos = (B0+B1)*.5;
	pos[1] += 5.*user_unit_distance( cr ).length();

    cr->translate( pos[0], pos[1] );

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

    draw_centered_text( cr, nrss.str() );

  cr->restore();

  #if defined DBG_FLAT_MMP_VISUALIZER_DRAW_WINDOW
  std::clog << "mmp::visualizer::draw_window\t|"
            << window
            << std::endl
            << "\t\t\t\t\t|"
            << " color " << color
            << " bounds " << bb
            << std::endl;
  #endif
}
开发者ID:urp,项目名称:urban-robots,代码行数:67,代码来源:cairo_visualizer.cpp

示例9:

bool studio::Widget_NavView::on_drawto_draw(const Cairo::RefPtr<Cairo::Context> &cr)
{
#ifdef SINGLE_THREADED
	// don't redraw if the previous redraw is still running single-threaded
	// or we end up destroying the renderer that's rendering it
	if (App::single_threaded && renderer && renderer->updating)
		return false;
#endif

	//draw the good stuff
	on_start_render();

	//if we've got a preview etc. display it...
	if(get_canvas_view())
	{
		//axis transform from units to pixel coords
		float xaxis = 0, yaxis = 0;

		int canvw = get_canvas_view()->get_canvas()->rend_desc().get_w();
		int w, h;
	
		float pw = get_canvas_view()->get_canvas()->rend_desc().get_pw();
		float ph = get_canvas_view()->get_canvas()->rend_desc().get_ph();
		if(prev && !studio::App::navigator_uses_cairo)
		{
			w = prev->get_width();
			h = prev->get_height();
		}
		if(studio::App::navigator_uses_cairo)
		{
			w=cairo_image_surface_get_width(cairo_surface);
			h=cairo_image_surface_get_height(cairo_surface);
		}

		//scale up/down to the nearest pixel ratio...
		//and center in center
		float offx=0, offy=0;

		float sx, sy;
		int nw,nh;

		sx = drawto.get_width() / (float)w;
		sy = drawto.get_height() / (float)h;

		//round to smallest scale (fit entire thing in window without distortion)
		if(sx > sy) sx = sy;
		//else sy = sx;

		//scaling and stuff
		// the point to navpixel space conversion should be:
		//		(navpixels / canvpixels) * (canvpixels / canvsize)
		//	or (navpixels / prevpixels) * (prevpixels / navpixels)
		xaxis = sx * w / (float)canvw;
		yaxis = xaxis/ph;
		xaxis /= pw;

		//scale to a new pixmap and then copy over to the window
		nw = (int)(w*sx);
		nh = (int)(h*sx);

		//must now center to be cool
		offx = (drawto.get_width() - nw)/2;
		offy = (drawto.get_height() - nh)/2;

		//trivial escape
		if(nw == 0 || nh == 0)return true;

		//draw to drawing area
		if(prev && !studio::App::navigator_uses_cairo)
		{
			Glib::RefPtr<Gdk::Pixbuf> scalepx = prev->scale_simple(nw,nh,Gdk::INTERP_NEAREST);

			cr->save();

			//synfig::warning("Nav: Drawing scaled bitmap");
			Gdk::Cairo::set_source_pixbuf(
				cr, //cairo context
				scalepx, //pixbuf
				(int)offx, (int)offy //coordinates to place upper left corner of pixbuf
				);
			cr->paint();
			cr->restore();
		}
		if(studio::App::navigator_uses_cairo)
		{
			cr->save();
			cr->scale(sx, sx);
			cairo_set_source_surface(cr->cobj(), cairo_surface, offx/sx, offy/sx);
			cairo_pattern_set_filter(cairo_get_source(cr->cobj()), CAIRO_FILTER_NEAREST);
			cr->paint();
			cr->restore();	
		}
		cr->save();
		//draw fancy red rectangle around focus point
		const Point &wtl = get_canvas_view()->work_area->get_window_tl(),
					&wbr = get_canvas_view()->work_area->get_window_br();

		//it must be clamped to the drawing area though
		int l=0,rw=0,t=0,rh=0;
		const Point fp = -get_canvas_view()->work_area->get_focus_point();
//.........这里部分代码省略.........
开发者ID:ChillyCider,项目名称:synfig-reloaded,代码行数:101,代码来源:dock_navigator.cpp

示例10: on_draw

bool ClockDrawArea::on_draw(const Cairo::RefPtr<Cairo::Context>& context){
	//Get the drawing area
	auto allocation = get_allocation();
	const int width = allocation.get_width();
	const int height = allocation.get_height();

	//Set the scale to a unit square
	context->scale(width, height);

	//Set (0.5, 0.5) to (0, 0). convenient to draw with arc.
	context->translate(0.5, 0.5);

	//Paint the background of the window;
	context->save();
	context->set_source_rgba(0.337, 0.612, 0.117, 0.9);
	context->paint();
	context->restore();

	//Draw the outer edge of the clock
	context->set_line_width(3 * m_LineWidth);
	context->arc(0, 0, m_Radius, 0, 2 * M_PI);

	//Paint the background color of the clock
	context->save();
	context->set_source_rgba(1.0, 1.0, 1.0, 0.8);
	context->fill_preserve();
	context->restore();

	//Draw a center point for good looking
	context->stroke();
	context->arc(0, 0, 0.05 * m_Radius, 0, 2 * M_PI);
	context->stroke();

	//Draw ticks
	context->save();
	double l = 1;

	for(int i = 0; i <= 11; i++){

		if((i % 3) == 0) {
			l = m_Radius * 0.8;
		}else{
			l = m_Radius * 0.9;
		}

		context->move_to(l * cos(i * 2* M_PI /12), l * sin(i * 2 * M_PI /12));
		context->line_to(m_Radius * cos(i * 2 * M_PI /12), m_Radius * sin(i * 2 * M_PI /12));

	}
	context->stroke();
	context->restore();

	//Get the current time from system and save info to a timeinfo struct
	time_t rawTime;
	time(&rawTime);

	struct tm * timeinfo = localtime(&rawTime);

	//Calculate the angle of hands of the clock
	auto radSeconds = (timeinfo->tm_sec * 2 * M_PI /60) - M_PI/2;
	auto radMinutes = (timeinfo->tm_min * 2 * M_PI /60) - M_PI/2;
	auto radHours = (timeinfo->tm_hour * 2 * M_PI /12) - M_PI/2  + timeinfo->tm_min * 2 * M_PI /(60 * 12);

	//Draw the hands of the clock
	context->save();

	//The hand of seconds
	context->set_source_rgba(0.823, 0.322, 0.155, 0.9);
	context->set_line_width(m_LineWidth);
	l = 0.9 * m_Radius;
	context->move_to(0,0);
	context->line_to(l * cos(radSeconds), l * sin(radSeconds));
	context->stroke();

	//The hand of minutes
	context->set_source_rgba(0.632, 0.802, 0.266, 0.9);
	context->set_line_width(2 * m_LineWidth);
	l = 0.8 * m_Radius;
	context->move_to(0,0);
	context->line_to(l * cos(radMinutes), l * sin(radMinutes));
	context->stroke();

	//The hand of hours
	context->set_source_rgba(0.104, 0.582, 0.723, 0.9);
	context->set_line_width(3 * m_LineWidth);
	l = 0.65 * m_Radius;
	context->move_to(0,0);
	context->line_to(l * cos(radHours), l * sin(radHours));
	context->stroke();

	context->restore();


	return true;
}
开发者ID:havor,项目名称:Clock,代码行数:95,代码来源:ClockDrawArea.cpp

示例11: agget

static void
skillgui_cairo_render_begin_page(GVJ_t *job)
{
#ifdef USE_GVPLUGIN_TIMETRACKER
  __tt.ping_start(__ttc_page);
  __tt.ping_start(__ttc_beginpage);
#endif
  SkillGuiCairoRenderInstructor *cri = (SkillGuiCairoRenderInstructor *)job->context;

  obj_state_t *obj = job->obj;
  if (obj && obj->type == ROOTGRAPH_OBJTYPE) {
    __fontname = agget(obj->u.g, (char *)"fontname");
  }

  float bbwidth  = job->bb.UR.x - job->bb.LL.x;
  float bbheight = job->bb.UR.y - job->bb.LL.y;

  cri->set_bb(bbwidth, bbheight);
  cri->set_pad(job->pad.x, job->pad.y);
  Cairo::RefPtr<Cairo::Context> cairo = cri->get_cairo();

  double pad_x, pad_y;
  cri->get_pad(pad_x, pad_y);

  // For internal calculations we need to care about the padding
  //bbwidth  += 2 * pad_x;
  //bbheight += 2 * pad_y;

  double avwidth, avheight;
  cri->get_dimensions(avwidth, avheight);
  float translate_x = 0;
  float translate_y = 0;

  if ( cri->scale_override() ) {
    float zoom = cri->get_scale();
    float zwidth  = bbwidth * zoom;
    float zheight = bbheight * zoom;
    translate_x += (avwidth  - zwidth ) / 2.;
    translate_y += (avheight - zheight) / 2.;

    double translate_x, translate_y;
    cri->get_translation(translate_x, translate_y);

    cairo->translate(translate_x, translate_y);
    cairo->scale(zoom, zoom);

  } else {
    float zoom_w = avwidth  / bbwidth;
    float zoom_h = avheight / bbheight;
    float zoom   = std::min(zoom_w, zoom_h);

    if (bbwidth > avwidth || bbheight > avheight) {
      float zwidth  = bbwidth * zoom;
      float zheight = bbheight * zoom;
      translate_x += (avwidth  - zwidth ) / 2.;
      translate_y += (avheight - zheight) / 2. + zheight;
    } else {
      zoom = 1.0;
      translate_x += (avwidth  - bbwidth)  / 2.;
      translate_y += (avheight - bbheight) / 2. + bbheight;
    }

    cri->set_scale(zoom);
    cri->set_translation(translate_x, translate_y);

    cairo->translate(translate_x + pad_x * zoom, translate_y - pad_y * zoom);
    cairo->scale(zoom, zoom);
  }



#ifdef USE_GVPLUGIN_TIMETRACKER
  __num_ellipse = 0;
  __num_bezier = 0;
  __num_polygon = 0;
  __num_polyline = 0;
  __num_text = 0;

  __tt.ping_end(__ttc_beginpage);
#endif
}
开发者ID:timn,项目名称:ros-skillgui,代码行数:81,代码来源:gvplugin_skillgui_cairo.cpp

示例12: drawImage

void ImageDrawable::drawImage(const Cairo::RefPtr<Cairo::Context> &cr, const Gtk::Allocation &allocation) {
	auto image = images->current();
	auto surface = image->getPrimary();
	int rwidth, rheight;
	double rscale;
	double rx, ry;

	//cout << "image " << iwidth << "x" << iheight << " " << iorientation.first << "," << iorientation.second << endl;

	calcRenderedImage(image, allocation, rwidth, rheight, rscale, rx, ry);

	cr->translate(rx, ry);
	cr->scale(rscale, rscale);

	waiting = !surface;

	if (image->isPrimaryFailed()) {
		// TODO display fancy failed indicator
		cr->set_source_rgb(0.75, 0.5, 0.5);
		cr->rectangle(0, 0, rwidth, rheight);
		cr->clip();
		cr->paint();
		return;
	} else if (!surface) {
		// TODO display fancy loading animation
		cr->set_source_rgb(0.5, 0.75, 0.5);
		cr->rectangle(0, 0, rwidth, rheight);
		cr->clip();
		cr->paint();
		return;
	}

	switch (image->getOrientation().first) {
	case Image::Rotate::ROTATE_NONE:
		break;

	case Image::Rotate::ROTATE_90:
		cr->translate(image->height(), 0);
		cr->rotate_degrees(90);
		break;

	case Image::Rotate::ROTATE_180:
		cr->translate(image->width(), image->height());
		cr->rotate_degrees(180);
		break;

	case Image::Rotate::ROTATE_270:
		cr->translate(0, image->width());
		cr->rotate_degrees(270);
		break;
	}

	if (image->getOrientation().second) {
		cr->translate(image->width(), 0);
		cr->scale(-1, 1);
	}

	auto pattern = Cairo::SurfacePattern::create(surface);
	pattern->set_filter(Cairo::Filter::FILTER_FAST);
	cr->set_source(pattern);

	//auto start = chrono::steady_clock::now();
	cr->paint();
	//auto stop = chrono::steady_clock::now();
	//cout << "paint " << chrono::duration_cast<chrono::milliseconds>(stop - start).count() << "ms" << endl;

	if (afPoints) {
		//start = chrono::steady_clock::now();
		auto properties = image->getProperties();
		valarray<double> dashes(5.0 / rscale, 5.0 / rscale);

		cr->save();
		cr->set_operator(static_cast<Cairo::Operator>(CAIRO_OPERATOR_DIFFERENCE));

		for (auto &rect : properties.focusPoints) {
			if (properties.focusPointsActive.find(rect) != properties.focusPointsActive.cend()) {
				cr->set_source_rgb(1, 0, 1);
				cr->set_line_width(4.0 / rscale);
				cr->unset_dash();
			} else if (properties.focusPointsSelected.find(rect) != properties.focusPointsSelected.cend()) {
				cr->set_source_rgb(1, 0, 0);
				cr->set_line_width(2.0 / rscale);
				cr->unset_dash();
			} else {
				cr->set_source_rgb(1, 1, 1);
				cr->set_line_width(1.0 / rscale);
				cr->set_dash(dashes, 0);
			}
			cr->rectangle(rect.x, rect.y, rect.width, rect.height);
			cr->stroke();
		}

		cr->restore();

		//stop = chrono::steady_clock::now();
		//cout << "afpaint " << chrono::duration_cast<chrono::milliseconds>(stop - start).count() << "ms" << endl;
	}
}
开发者ID:lp0,项目名称:fiv,代码行数:98,代码来源:ImageDrawable.cpp

示例13: dsc

static void
draw_text (Cairo::RefPtr<Cairo::Context> cr, int wdh, int hgt)
{
    RefPtr<Pango::Layout> layout = Pango::Layout::create(cr);
    //layout->set_single_paragraph_mode(true);
    layout->set_text("MTextTextM\nAbc\nff");


    Pango::FontDescription dsc(FONT);
    layout->set_font_description(dsc);

    int t_wdh, t_hgt;
    layout->get_size(t_wdh, t_hgt);

    double t_sz = (double)dsc.get_size()/t_wdh;
    double new_sz = wdh * t_sz ;

    io::cout << "new_sz " << new_sz << io::endl;
    io::cout << "wdh " << wdh << io::endl;

    dsc.set_size( int(new_sz*PANGO_SCALE) );
    layout->set_font_description(dsc);

    layout->get_size(t_wdh, t_hgt);
    io::cout << "t_wdh " << t_wdh/(double)PANGO_SCALE << io::endl;

    // для наглядности
    cr->set_line_width(1.0);
    cr->rectangle(0, 0, wdh, hgt);
    cr->stroke();


    cr->save();

    cr->move_to(0, 0);
    cr->scale( 1.0, hgt / ((double)t_hgt/PANGO_SCALE) );
    //cr->scale( wdh / ((double)t_wdh/PANGO_SCALE), hgt / ((double)t_hgt/PANGO_SCALE) );

    layout->update_from_cairo_context(cr);

    pango_cairo_show_layout(cr->cobj(), layout->gobj());

    {
        Pango::Rectangle w_rct, s_rct;
        int cur_pos;

        cur_pos = 1;
        layout->get_cursor_pos(cur_pos, w_rct, s_rct);
        pango_extents_to_pixels(0, w_rct.gobj());

        io::cout << "curs - x, y, hgt " << w_rct.get_x() << " " << w_rct.get_y() << " " << w_rct.get_height() << io::endl;
        cr->move_to(w_rct.get_x()+5, w_rct.get_y());
        cr->line_to(w_rct.get_x()+5, w_rct.get_y()+w_rct.get_height());
        cr->stroke();


        cur_pos = 11;
        layout->get_cursor_pos(cur_pos, w_rct, s_rct);
        pango_extents_to_pixels(0, w_rct.gobj());

        io::cout << "curs - x, y, hgt " << w_rct.get_x() << " " << w_rct.get_y() << " " << w_rct.get_height() << io::endl;
        cr->move_to(w_rct.get_x()+5, w_rct.get_y());
        cr->line_to(w_rct.get_x()+5, w_rct.get_y()+w_rct.get_height());
        cr->stroke();

    }


    cr->restore();
}
开发者ID:cargabsj175,项目名称:bombono-dvd,代码行数:70,代码来源:test_text.cpp

示例14: Exception

/** 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;
}
开发者ID:,项目名称:,代码行数:84,代码来源:

示例15: drawWidget


//.........这里部分代码省略.........

#if 0
  // This is where we draw on the window
  Glib::RefPtr<Gdk::Window> window = get_window();
  if(window)
  {
    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();

    if(event)
    {
        // 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();
    }

    // background gradient
    {
        Cairo::RefPtr<Cairo::LinearGradient> pat = Cairo::LinearGradient::create(0.0, 0.0, 0.0, height);
        pat->add_color_stop_rgb(1.0, 1.0, 1.0, 1.0);
        pat->add_color_stop_rgb(0.0, 0.0, 0.0, 0.0);
        cr->rectangle(0, 0, width, height);
        cr->set_source(pat);
        cr->fill();
    }

    // scale to unit square and translate (0, 0) to be (0.5, 0.5), i.e.
    // the center of the window
    cr->scale(width, height);
    cr->translate(0.5, 0.5);
    cr->set_line_width(m_line_width);

    cr->arc(0, 0, m_radius, 0, 2 * M_PI);
    cr->save();
    cr->set_source_rgba(1.0, 1.0, 1.0, 0.8);
    cr->fill_preserve();
    cr->restore();
    cr->stroke_preserve();
    cr->clip();

    //clock ticks
    for (int i = 0; i < 12; i++)
    {
        double inset = 0.05;

        cr->save();
        cr->set_line_cap(Cairo::LINE_CAP_ROUND);

        if(i % 3 != 0)
        {
            inset *= 0.8;
            cr->set_line_width(0.03);
        }

        cr->move_to(
                (m_radius - inset) * cos (i * M_PI / 6),
                (m_radius - inset) * sin (i * M_PI / 6));
        cr->line_to (
                m_radius * cos (i * M_PI / 6),
                m_radius * sin (i * M_PI / 6));
        cr->stroke();
开发者ID:ereslibre,项目名称:ideallibrary-old-extern,代码行数:67,代码来源:main.cpp


注:本文中的cairo::RefPtr::scale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。