Beispiel #1
0
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();
}
bool MapDrawingArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
    cr->translate(tran_x, tran_y);
    cr->set_source(surface, 0, 0);
    cr->paint();
    return true;
}
Beispiel #3
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();
}
Beispiel #4
0
bool CircuitWidget::on_expose_event(GdkEventExpose* event)
{

    (void)event; // placate compiler..
    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();
        double xc = width/2.0;
        double yc = height/2.0;

        Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
        circuitDrawer.renderCairo(cr->cobj());
        cr->rectangle(event->area.x, event->area.y,
                      event->area.width, event->area.height);
        cr->clip();
        cr->rectangle (0, 0, width, height);
        cr->set_source_rgb (1,1,1);
        cr->fill ();
        cr->translate (xc-ext.width/2.0-cx*scale, yc-ext.height/2.0-cy*scale);
        if (circuit) {
            rects = circuitDrawer.draw(*circuit, drawarch, drawparallel, ext, wirestart, wireend, scale, selections, ft_default, wirelabels);
            generate_layout_rects ();
        }
    }

    return true;
}
Beispiel #5
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 #6
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 #7
0
void EmblemCellRenderer::do_render(const Cairo::RefPtr<Cairo::Context>& context, int widget, int background_area, Gdk::Rectangle &cell_area, int flags) {
    context->translate(cell_area.get_x(), cell_area.get_y());
    context->rectangle(0, 0, cell_area.get_width(), cell_area.get_height());
    context->clip();

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

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

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

    context->pop_group_to_source();
    context->set_operator(Cairo::OPERATOR_OVER);
    context->paint();
}
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();
}
Beispiel #9
0
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();
  }
}
Beispiel #10
0
bool rasterpolys(const vector<Poly> &polys,
		 const Vector2d &min, const Vector2d &max, double resolution,
		 Cairo::RefPtr<Cairo::ImageSurface> &surface,
		 Cairo::RefPtr<Cairo::Context> &context)
{
  Vector2d diag = max - min;
  int width  = (int)ceil(diag.x()/resolution);
  int height = (int)ceil(diag.y()/resolution);
  if (height <= 0 || width <= 0)
    return false;
  surface = Cairo::ImageSurface::create(Cairo::FORMAT_A8, width, height);
  //surface->set_device_offset(-min.x()/resolution, -min.y()/resolution);
  context = Cairo::Context::create (surface);
  context->set_fill_rule(Cairo::FILL_RULE_WINDING);
  context->set_antialias(Cairo::ANTIALIAS_DEFAULT);
  context->scale(1/resolution, 1/resolution);
  context->translate(-min.x(), -min.y());
  context->set_source_rgb (0,0,0);
  //cerr << min << endl <<getMatrix(context) << endl;

  // draw boundary
  // context->begin_new_path();
  // context->set_line_width(0.5);
  // context->move_to(min.x(),min.y());
  // context->line_to(max.x(),min.y());
  // context->line_to(max.x(),max.y());
  // context->line_to(min.x(),max.y());
  // // context->move_to(0,0);
  // // context->line_to(diag.x(),0);
  // // context->line_to(diag.x(),diag.y());
  // // context->line_to(0,diag.y());
  // context->close_path();
  // context->stroke();

  context->begin_new_path();
  context->set_line_width(0);
  for (uint i=0; i<polys.size(); i++) {
    Vector2d v = polys[i][0];
    context->move_to(v.x(),v.y());
    for (uint j=0; j<polys[i].size(); j++) {
      Vector2d v = polys[i][j];
      context->line_to(v.x(),v.y());
    }
  }
  context->fill();
  return true;
}
Beispiel #11
0
/* 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();
    }
}
Beispiel #12
0
void Mediator::redraw()
{
  Glib::RefPtr<Gdk::Window> Window = mref_DrawingArea.get_window();

  if (Window)
  {
    Window->clear();

    if (!m_Layers.empty())
    {
      Cairo::RefPtr<Cairo::Context> Context = Window->create_cairo_context();
      Gtk::Allocation allocation = mref_DrawingArea.get_allocation();
      const int width = allocation.get_width();
      const int height = allocation.get_height();

      Context->rectangle(0, 0, width, height);
      Context->clip();
      Context->set_antialias(Cairo::ANTIALIAS_SUBPIXEL);
      Context->scale(mref_DrawingArea.getScale(), -mref_DrawingArea.getScale());
      Context->translate(-mref_DrawingArea.getXTranslate(),
          -mref_DrawingArea.getYTranslate());
      std::vector<Layer*>::reverse_iterator rit;
      for (rit = m_Layers.rbegin(); rit < m_Layers.rend(); ++rit)
      {
        if ((*rit)->getIsDisplay())
        {
          (*rit)->initialiseLayerContext(Context, mref_DrawingArea.getScale());
          if ((*rit)->getClassName() == m_SelectedClassName)
          {
            (*rit)->draw(Context, mref_DrawingArea.getScale(),
                m_SelectedUnitIds, (*rit)->getDisplayID());
          }
          else
          {
            std::set<int> tempVoidVector;
            (*rit)->draw(Context, mref_DrawingArea.getScale(), tempVoidVector,
                (*rit)->getDisplayID());
          }
        }
      }
    }
  }
}
Beispiel #13
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;
}
Beispiel #14
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 #15
0
							 //const Cairo::RefPtr<Cairo::Context>& cr
		virtual bool on_draw(const Cairo::RefPtr<Cairo::Context> &cr) {
			Gtk::Allocation alloc = get_allocation();
			int ancho = alloc.get_width();
			int alto = alloc.get_height();
			int x = ancho / 2;
			int y = alto / 2;
			
			int w = 3 * ancho / 4.0;
			int h = alto / 2.0;
			cr->save();
			
			cr->translate(x, y);
			cr->scale(w, h);
			cr->arc(0, 0, 1.0, 0, 2 * M_PI);
			cr->set_source_rgba(0, 0, 1.0, 0);
			// cr->fill_preserve();
			cr->restore();  // back to opaque black
			cr->stroke();
			return true;
		}
static void
skillgui_cairo_render_ellipse(GVJ_t *job, pointf *A, int filled)
{
#ifdef USE_GVPLUGIN_TIMETRACKER
  __tt.ping_start(__ttc_ellipse);
  ++__num_ellipse;
#endif
  //printf("Render ellipse\n");
  SkillGuiCairoRenderInstructor *cri = (SkillGuiCairoRenderInstructor *)job->context;
  Cairo::RefPtr<Cairo::Context> cairo = cri->get_cairo();
  obj_state_t *obj = job->obj;

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

  skillgui_cairo_set_penstyle(cairo, job);

  cairo->translate(A[0].x, -A[0].y);

  double rx = A[1].x - A[0].x;
  double ry = A[1].y - A[0].y;
  cairo->scale(1, ry / rx);
  cairo->move_to(rx, 0);
  cairo->arc(0, 0, rx, 0, 2 * M_PI);
  cairo->close_path();

  cairo->set_matrix(old_matrix);

  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_ellipse);
#endif
}
Beispiel #17
0
bool InfoWidget::drawChart(const::Cairo::RefPtr<Cairo::Context> &context)
{
	context->save();

	const double width = m_chartDrawingArea.get_allocation().get_width();
	const double height = m_chartDrawingArea.get_allocation().get_height();

	context->set_source_rgb(m_data.color.get_red(), m_data.color.get_green(), m_data.color.get_blue());
	context->rectangle(0, 0, width, height);
	context->fill();

	const Gdk::RGBA color = get_style_context()->get_color();
	context->set_source_rgb(color.get_red(), color.get_green(), color.get_blue());

	const double titleX = width / 2.0;
	const double titleY = height / 2.0;

	auto layout = Pango::Layout::create(context);
	layout->set_justify(true);
	layout->set_alignment(Pango::ALIGN_CENTER);

	if (m_data.subtitle.empty())
		layout->set_markup(m_data.title);
	else
		layout->set_markup(m_data.title + "\n<span size=\"x-small\">" + m_data.subtitle + "</span>");

	auto fontDescription = get_style_context()->get_font();
	fontDescription.set_size(2 * fontDescription.get_size());
	layout->set_font_description(fontDescription);

	const auto rectangle = layout->get_pixel_logical_extents();
	context->translate(titleX - rectangle.get_width() / 2.0, titleY - rectangle.get_height() / 2.0);

	layout->show_in_cairo_context(context);

	context->restore();

	return true;
}
Beispiel #18
0
void ImageWidget::redrawWithoutChanges(Cairo::RefPtr<Cairo::Context> cairo, unsigned width, unsigned height)
{
	if(_isInitialized) {
		cairo->set_source_rgb(1.0, 1.0, 1.0);
		cairo->set_line_width(1.0);
		cairo->rectangle(0, 0, width, height);
		cairo->fill();
		
		int
			destWidth = width - (int) floor(_leftBorderSize + _rightBorderSize),
			destHeight = height - (int) floor(_topBorderSize + _bottomBorderSize),
			sourceWidth = _imageSurface->get_width(),
			sourceHeight = _imageSurface->get_height();
		cairo->save();
		cairo->translate((int) round(_leftBorderSize), (int) round(_topBorderSize));
		cairo->scale((double) destWidth / (double) sourceWidth, (double) destHeight / (double) sourceHeight);
		Cairo::RefPtr<Cairo::SurfacePattern> pattern = Cairo::SurfacePattern::create(_imageSurface);
		pattern->set_filter(_cairoFilter);
		cairo->set_source(pattern);
		cairo->rectangle(0, 0, sourceWidth, sourceHeight);
		cairo->clip();
		cairo->paint();
		cairo->restore();
		cairo->set_source_rgb(0.0, 0.0, 0.0);
		cairo->rectangle(round(_leftBorderSize), round(_topBorderSize), destWidth, destHeight);
		cairo->stroke();

		if(_showColorScale)
			_colorScale->Draw(cairo);
		if(_showXYAxes)
		{
			_vertScale->Draw(cairo);
			_horiScale->Draw(cairo);
		}
		if(_plotTitle != 0)
			_plotTitle->Draw(cairo);
	}
}
Beispiel #19
0
void cairo::draw_triangle( const Cairo::RefPtr<Cairo::Context>& cr, const Geodesics::edge_handle& e0 )
{
  const rgba_color_t color( .8, .8, .8, .3);

  // get edge-free pair
  const Geodesics::edge_handle e1 ( e0.next() );
  const Geodesics::edge_handle e2 ( e1.next() );

  const coord_t e0l= e0.length();
  const coord_t e1l= e1.length();
  const coord_t e2l= e2.length();

  // coordinates of C - using circle-circle intersection ( intersect circle (w.b0,w.d0) with (w.b1,w.d1) )

  cairo_coord_t A(0.,0.);
  cairo_coord_t B(e0l,0.);
  cairo_coord_t C;
  boost::tie(C[0],C[1]) = utk::triangulate( e0l, e2l, e1l );
  //C[1] = - C[1];

  const coord2_t centroid = ( ( coord2_t(e0l, 0) += C ) /= coord_t(3) );

  cr->save();

    //cr->set_operator( Cairo::OPERATOR_DEST_OVER );

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

    cr->save();
      // shrink slightly towards centroid
      cr->translate( centroid[0], centroid[1] );
      cr->scale( .95, .95 );
      cr->translate( -centroid[0], -centroid[1] );
      //draw triangle
      cr->set_line_width( 1. * user_unit_distance( cr ).length() );

      draw_half_arrow( cr, A, B );

      draw_half_arrow( cr, B, C );

      draw_half_arrow( cr, C, A );


    cr->restore();

    cr->stroke();

  cr->restore();

  // draw text
  cr->save();

    cr->user_to_device( A[0], A[1] );
    cr->user_to_device( B[0], B[1] );
    cr->user_to_device( C[0], C[1] );

    cr->set_identity_matrix();

    //cr->select_font_face( "Purisa", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL );

    cr->set_source_rgba( 0., 0., 0.,.5 );

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

    std::ostringstream nrss;
    nrss << e0.source().descriptor();
    draw_centered_text( cr, nrss.str(), A );

    nrss.str("");
    nrss << e1.source().descriptor();
    draw_centered_text( cr, nrss.str(), B );

    nrss.str("");
    nrss << e2.source().descriptor();
    draw_centered_text( cr, nrss.str(), C );

  cr->restore();

}
Beispiel #20
0
bool graphView::on_draw(const Cairo::RefPtr<Cairo::Context>& cr){
	
	//Get the allocation of our widget, and get the height and width from it
	Gtk::Allocation wAllocation = this->get_allocation();
	const int wHeight = wAllocation.get_height();
	const int wWidth = wAllocation.get_width();
	
	const double lineWidth = wHeight;
	
	//scale the Cario context obj to the current wHeight and wWidth
	//cr->scale(wWidth, wHeight);
	//now change the offset point coordinates, so point (0,0) will be at (0.5,0.5)
	cr->translate(wWidth/2, wHeight/2);
	//set the line width to 2 px, this should be a settings for each graph in the futur
	cr->set_line_width(1);
	
	//paint the background white
	cr->set_source_rgb(1,1,1);
	cr->paint();
	
	//draw the coordinatesystem
	cr->set_source_rgb(0,0,0);
	cr->move_to(0,0);
	cr->line_to(wWidth,0);
	cr->move_to(0,0);
	cr->line_to(0,wHeight);
	cr->move_to(0,0);
	cr->line_to(-1*wWidth,0);
	cr->move_to(0,0);
	cr->line_to(0,-1*wHeight);
	
	//draw the axes unit, again this should't be hardcoded in the futur
	cr->move_to(0,0);
	
	for(int i = 1; i <= 25; i++)
	{
		cr->move_to((wWidth*0.5/25)*i,0);
		cr->rel_move_to(0, -8);
		cr->rel_line_to(0,16);
		cr->rel_move_to(0, -8);
		
		cr->move_to((wWidth*0.5/25)*-i,0);
		cr->rel_move_to(0, -8);
		cr->rel_line_to(0,16);
		cr->rel_move_to(0, -8);
		
	}
	
	cr->move_to(0, 0);
	
	for(int i = 1; i <= 25; i++)
	{
		cr->move_to(0,(wHeight*0.5/25)*i);
		cr->rel_move_to(-8,0);
		cr->rel_line_to(16,0);
		cr->rel_move_to(-8,0);
		
		cr->move_to(0,(wHeight*0.5/25)*-i);
		cr->rel_move_to(-8,0);
		cr->rel_line_to(16,0);
		cr->rel_move_to(-8,0);
		
	}
	
	cr->stroke();
	
	cr->set_source_rgb(0.8,0,0);
	if(this->tree)
	{
		cr->set_line_width(3);
		std::vector<equation*> eqs = this->tree->getEquations();
		
		double pxWidth = wWidth/50;
		double pxHeight = wHeight/50;
		
		for(int i = 0; i < eqs.size(); i++){
			
			equation *eq = eqs[i];
			
			for(double x = -25; x<= 25; x+= 0.01)
			{
				double y = eq->getYFromX(x);
				
				cr->move_to(x*pxWidth,-1*(y*pxHeight));
				cr->rel_line_to(1,1);
			}
			cr->stroke();
		}
	}
	
	return true;
}
Beispiel #21
0
void Switch::draw(const Cairo::RefPtr<Cairo::Context>& cr){

    cr->save();
    cr->translate(parent->xoffset + x, y);
    /*
    cr->set_source_rgb(200.0/256.0, 200.0/256.0, 215.0/256.0);
    cr->set_source_rgb(140.0/256.0, 140.0/256.0, 150.0/256.0);
    cr->set_source_rgb(160.0/256.0, 160.0/256.0, 170.0/256.0);
    */
    cr->set_source_rgb(200.0/256.0, 200.0/256.0, 215.0/256.0);
    cr->arc(0,0, 10, 0.0, 2*M_PI);
    cr->fill();
    //hole
    cr->set_source_rgb(30.0/256.0, 30.0/256.0, 30.0/256.0);
    cr->arc(0,0, 7, 0.0, 2*M_PI);
    cr->fill();

    //handle
    const double len = 15.0;
    double endx, endy;
    if(!vertical){
        if(value) {endx =  len; endy = 0.0;}
        else      {endx = -len; endy = 0.0;}
    }else{
        if(value) {endx = 0.0; endy =  len;}
        else      {endx = 0.0; endy = -len;}
    }
    cr->set_line_width(6.0);
    cr->set_line_cap(Cairo::LINE_CAP_ROUND);
    cr->set_source_rgb(1.0,1.0,1.0);
    cr->move_to(0.0,0.0);
    cr->line_to(endx,endy);
    cr->stroke();
    cr->set_source_rgb(170.0/256.0, 170.0/256.0, 170.0/256.0);
    cr->move_to(endx,endy);
    cr->arc(endx,endy,4,0.0,2*M_PI);
    cr->fill();

    //text
    cr->select_font_face("Verdana",Cairo::FONT_SLANT_NORMAL,Cairo::FONT_WEIGHT_BOLD);
    cr->set_font_size(10.0);
    cr->set_source_rgb(1.0,1.0,1.0);
    Cairo::TextExtents tx;
    if(!vertical){
        cr->get_text_extents(text1,tx);
        cr->move_to(-tx.width - 24.0, 3.0 );
        cr->show_text(text1);
        cr->get_text_extents(text2,tx);
        cr->move_to(22.0, 3.0 );
        cr->show_text(text2);
    }else{
        cr->get_text_extents(text1,tx);
        cr->move_to(-tx.width/2.0, -22.0 );
        cr->show_text(text1);
        cr->move_to(-tx.width/2.0, 27.0 );
        cr->get_text_extents(text2,tx);
        cr->show_text(text2);
    }

    cr->restore();
}
Beispiel #22
0
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
}
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
}
void guiRenderer2D::drawMatrices(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height, bool screenshot) {

	cr->scale(m_scaleFactor, m_scaleFactor); // Scale sensor to fit the active window
	cr->translate(m_offsetX, m_offsetY); // Center figure on drawable/surface

	cr->set_line_width(0.25);

	for(uint m = 0; m < m_frameManager->getNumMatrices(); m++) {
		matrixInfo &matrix = m_frameManager->getMatrixInfo(m);
		// TSFrame* tsFrame = m_frameManager->getCurrentFrame();
		TSFrame* tsFrame = m_frameManager->getCurrentFilteredFrame();

		for(uint y = 0; y < matrix.cells_y; y++) {
			for(uint x = 0; x < matrix.cells_x; x++) {

				bool maskedStatic = m_frameManager->getStaticMask(m, x, y);
				bool maskedDynamic = m_frameManager->getDynamicMask(m, x, y);
				uint cellID = matrix.texel_offset + y * matrix.cells_x + x;
				float value = tsFrame->cells[cellID];

				if(maskedStatic) {
					RGB color = determineColor(value);

					// Draw sensor cell rectangle
					cr->rectangle(m_rectangleTopLeftX[cellID], m_rectangleTopLeftY[cellID], m_rectangleWidth[cellID], m_rectangleHeight[cellID]);
					cr->set_source_rgb(0.0, 0.0, 0.0);
					cr->stroke_preserve(); // Cell outline

					if(maskedDynamic) {
						if(value > 0.0) {
							cr->set_source_rgb(color.r, color.g, color.b); // Active cells
						} else  {
							cr->set_source_rgb(1.0, 1.0, 1.0); // Inactive cells
						}
					} else {
						cr->set_source_rgb(0.8, 0.8, 0.8); // Disabled cells
					}
					cr->fill();
				}

				// Highlight selected cells
				if(m_frameManager->isSelected(cellID)) {
					cr->rectangle(m_rectangleTopLeftX[cellID], m_rectangleTopLeftY[cellID], m_rectangleWidth[cellID], m_rectangleHeight[cellID]);
					cr->set_source_rgba(0.0, 1.0, 0.0, 0.5); // Fill active cells
					cr->fill();
				}

				if(screenshot) {
					if(maskedStatic) {
						// Print values
						Cairo::RefPtr<Cairo::ToyFontFace> font = Cairo::ToyFontFace::create("LMSans10", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);
						cr->set_font_face(font);
						cr->set_font_size(matrix.texel_width/3);
						std::ostringstream ss;
						ss << value;
						std::string valueStr = ss.str();

						Cairo::TextExtents te;
						cr->get_text_extents(valueStr, te);

						cr->move_to(m_matrixCellCenterX[cellID]-te.width/2, m_matrixCellCenterY[cellID]+te.height/2);
						cr->set_source_rgb(0.0, 0.0, 0.0);
						cr->show_text(valueStr);
					}
				}

			}
		}

		if(!screenshot) {
			{
				// Print Matrix IDs
				Cairo::RefPtr<Cairo::ToyFontFace> font = Cairo::ToyFontFace::create("LMSans10", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);
				cr->set_font_face(font);
				cr->set_font_size(matrix.cells_x*matrix.texel_width);
				std::ostringstream ss;
				ss << m;
				std::string idString = ss.str();

				Cairo::TextExtents te;
				cr->get_text_extents(idString, te);

				cr->move_to(m_newCenterX[m]-te.width/2, m_newCenterY[m]+te.height/2);
				cr->set_source_rgba(0.3, 0.3, 0.3, 0.3);
				cr->show_text(idString);
			}
		}

	}
}
Beispiel #25
0
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;
}
Beispiel #26
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;
}
Beispiel #27
0
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;
}
Beispiel #28
0
	void translate__(Glib::ustring& d1,Glib::ustring& d2){
		cr_->translate(s2f__(d1), s2f__(d2));
	}
Beispiel #29
0
void area___::test__(){
	int width, height;
	width=da_->get_allocation().get_width();
	height=da_->get_allocation().get_height();

	double m_radius=0.42;
	double m_line_width=0.05;

	// 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_->save();
	cr_->set_source_rgba(0.337, 0.612, 0.117, 0.9);   // green
	cr_->paint();
	cr_->restore();
	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();
		cr_->restore(); // stack-pen-size
	}

	// store the current time
	time_t rawtime;
	time(&rawtime);
	struct tm * timeinfo = localtime (&rawtime);

	// compute the angles of the indicators of our clock
	double minutes = timeinfo->tm_min * M_PI / 30;
	double hours = timeinfo->tm_hour * M_PI / 6;
	double seconds= timeinfo->tm_sec * M_PI / 30;
	cout<<timeinfo->tm_min<<","<<timeinfo->tm_hour<<","<<timeinfo->tm_sec<<endl;

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

	// draw the seconds hand
	cr_->save();
	cr_->set_line_width(m_line_width / 3);
	cr_->set_source_rgba(0.7, 0.7, 0.7, 0.8); // gray
	cr_->move_to(0, 0);
	cr_->line_to(sin(seconds) * (m_radius * 0.9),
			-cos(seconds) * (m_radius * 0.9));
	cr_->stroke();
	cr_->restore();

	// draw the minutes hand
	cr_->set_source_rgba(0.117, 0.337, 0.612, 0.9);   // blue
	cr_->move_to(0, 0);
	cr_->line_to(sin(minutes + seconds / 60) * (m_radius * 0.8),
			-cos(minutes + seconds / 60) * (m_radius * 0.8));
	cr_->stroke();

	// draw the hours hand
	cr_->set_source_rgba(0.337, 0.612, 0.117, 0.9);   // green
	cr_->move_to(0, 0);
	cr_->line_to(sin(hours + minutes / 12.0) * (m_radius * 0.5),
			-cos(hours + minutes / 12.0) * (m_radius * 0.5));
	cr_->stroke();
	cr_->restore();

	// draw a little dot in the middle
	cr_->arc(0, 0, m_line_width / 3.0, 0, 2 * M_PI);
	cr_->fill();
}
void MyWidget::drawWidget()
{
    Painter p(this);

    if (m_color) {
        p.setSourceRGB(1.0, 0, 0);
    } else {
        p.setSourceRGB(0, 0, 0);
    }

    p.translate(minimumSize().width() / 2.0, minimumSize().height() / 2.0);
    p.setLineWidth(m_lineWidth);
    p.arc(0, 0, m_radius, 0, 2 * M_PI);
    p.save();

    p.setSourceRGBA(1.0, 1.0, 1.0, 0.8);
    p.fillPreserve();
    p.restore();
    p.strokePreserve();
    p.clip();

    for (int i = 0; i < 12; ++i) {
        double inset = 30;

        p.save();
        p.setLineCap(Painter::RoundLineCap);

        if(i % 3 != 0) {
            inset *= 0.8;
            p.setLineWidth(1.0);
        }

        p.moveTo((m_radius - inset) * cos (i * M_PI / 6.0),
                 (m_radius - inset) * sin (i * M_PI / 6.0));
        p.lineTo(m_radius * cos (i * M_PI / 6.0),
                 m_radius * sin (i * M_PI / 6.0));
        p.stroke();
        p.restore();
    }

    // store the current time
    time_t rawtime;
    time(&rawtime);
    struct tm * timeinfo = localtime (&rawtime);

    // compute the angles of the indicators of our clock
    double minutes = timeinfo->tm_min * M_PI / 30;
    double hours = timeinfo->tm_hour * M_PI / 6;
    double seconds= timeinfo->tm_sec * M_PI / 30;

    p.save();
    p.setLineCap(Painter::RoundLineCap);

    // draw the seconds hand
    p.save();
    p.setLineWidth(m_lineWidth);
    p.setSourceRGBA(0.7, 0.7, 0.7, 0.8);
    p.moveTo(0, 0);
    p.lineTo(sin(seconds) * (m_radius * 0.9),
             -cos(seconds) * (m_radius * 0.9));
    p.stroke();
    p.restore();

    // draw the minutes hand
    p.setSourceRGBA(0.117, 0.337, 0.612, 0.9);
    p.moveTo(0, 0);
    p.lineTo(sin(minutes + seconds / 60.0) * (m_radius * 0.8),
             -cos(minutes + seconds / 60.0) * (m_radius * 0.8));
    p.stroke();

    // draw the hours hand
    p.setSourceRGBA(0.337, 0.612, 0.117, 0.9);
    p.moveTo(0, 0);
    p.lineTo(sin(hours + minutes / 12.0) * (m_radius * 0.5),
             -cos(hours + minutes / 12.0) * (m_radius * 0.5));
    p.stroke();
    p.restore();

    p.setSourceRGBA(1, 0, 0, 0.5);
    p.arc(0, 0, m_lineWidth * 2.0, 0, 2.0 * M_PI);
    p.fill();

#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();
        cr->restore(); /* stack-pen-size */
    }

    // store the current time
    time_t rawtime;
    time(&rawtime);
    struct tm * timeinfo = localtime (&rawtime);

    // compute the angles of the indicators of our clock
    double minutes = timeinfo->tm_min * M_PI / 30;
    double hours = timeinfo->tm_hour * M_PI / 6;
    double seconds= timeinfo->tm_sec * M_PI / 30;

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

    // draw the seconds hand
    cr->save();
    cr->set_line_width(m_line_width / 3);
    cr->set_source_rgba(0.7, 0.7, 0.7, 0.8); // gray
    cr->move_to(0, 0);
    cr->line_to(sin(seconds) * (m_radius * 0.9), 
            -cos(seconds) * (m_radius * 0.9));
    cr->stroke();
    cr->restore();

    // draw the minutes hand
    cr->set_source_rgba(0.117, 0.337, 0.612, 0.9);   // blue
    cr->move_to(0, 0);
    cr->line_to(sin(minutes + seconds / 60) * (m_radius * 0.8),
            -cos(minutes + seconds / 60) * (m_radius * 0.8));
    cr->stroke();

    // draw the hours hand
    cr->set_source_rgba(0.337, 0.612, 0.117, 0.9);   // green
    cr->move_to(0, 0);
    cr->line_to(sin(hours + minutes / 12.0) * (m_radius * 0.5),
            -cos(hours + minutes / 12.0) * (m_radius * 0.5));
    cr->stroke();
    cr->restore();

    // draw a little dot in the middle
    cr->arc(0, 0, m_line_width / 3.0, 0, 2 * M_PI);
    cr->fill();
  }
#endif
}