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
}
void ValidationPanel::refresh()
{
	// update the label
	crn::StringUTF8 lab = "<span font_desc=\"" + Config::GetFont() + "\">" + title + "</span>";
	lab += " (";
	lab += nelem;
	lab += ")";
	auto *labw = get_label_widget();
	auto *llab = dynamic_cast<Gtk::Label*>(labw);
	if (llab)
		llab->set_markup(lab.CStr());
	else
		set_label(lab.CStr());
	

	if (/*(positions.size() != elements.size()) ||*/ (dispw <= 0) || (disph <= 0) || locked)
		return;

	Glib::RefPtr<Gdk::Window> win = da.get_window();
	if (win)
	{
		// if the drawing area is fully created
		// create a buffer
		Glib::RefPtr<Gdk::Pixmap> pm = Gdk::Pixmap::create(win, dispw, disph);
		// clear the buffer
		pm->draw_rectangle(da_gc, true, 0, 0, dispw, disph);
		int offset = -int(scroll.get_value());

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


		// draw the words
		for (const ValidationPanel::ElementList::value_type &el : elements)
		{
			if (!el.second.empty())
			{
				int by = positions[el.second.begin()->first].Y;
				int ey = by;
				for (const ValidationPanel::ElementCluster::value_type &w : el.second)
				{
					int y = positions[w.first].Y + w.second.img->get_height();
					if (y > ey) ey = y;
				}
				if ((el.first == elements.rbegin()->first) && (ey < disph))
				{
					// fill till the end of the display
					ey = disph;
				}
				ValidationPanel::set_color(cc, el.first);
				cc->rectangle(0, by + offset, dispw, ey - by);
				cc->fill();
			}
			for (const ValidationPanel::ElementCluster::value_type &w : el.second)
			{
				Glib::RefPtr<Gdk::Pixbuf> wpb = w.second.img;

				pm->draw_pixbuf(da_gc, wpb, 0, 0, positions[w.first].X, positions[w.first].Y + offset, w.second.img->get_width(), w.second.img->get_height(), Gdk::RGB_DITHER_NONE, 0, 0);
			}
		}

		// draw the mark
		if (mark.size() > 1)
		{
			cc->set_source_rgb(1.0, 0, 0);
			cc->move_to(mark.front().X, mark.front().Y + offset);
			for (size_t tmp = 1; tmp < mark.size(); ++tmp)
			{
				cc->line_to(mark[tmp].X, mark[tmp].Y + offset);
			}
			cc->stroke();
		}

		// copy pixmap to drawing area
		win->draw_drawable(da_gc, pm, 0, 0, 0, 0);
	}

}
Beispiel #3
0
    // main drawing routine
    bool Draw::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
    {
        int num_cells = b.num_bowls + 2;
        double inv_num_cells = 1.0 / num_cells;

        Gtk::Allocation alloc = get_allocation();

        Pango::FontDescription font("Monospace");
        font.set_size(std::min(alloc.get_width(), alloc.get_height()) * .1 * Pango::SCALE);
        cr->set_source_rgb(0.0, 0.0, 0.0);

        // draw bg
        draw_img(cr, bg_board, 0.0, 0.0, alloc.get_width() / (bg_board->get_width() - .5),
            alloc.get_height() / (bg_board->get_height() - .5));

        // draw bg for left store
        draw_img(cr, bg_store, 0.0, 0.0, alloc.get_width() / (bg_store->get_width() - .5) * inv_num_cells,
            alloc.get_height() / (bg_store->get_height() - .5));

        // l store beads
        for(auto & j: b.l_store.beads)
        {
            draw_img(cr, bead_imgs[j.color_i], alloc.get_width() * j.pos[0], alloc.get_height() * j.pos[1],
                alloc.get_width() / (bead_imgs[j.color_i]->get_width() - .5) * inv_num_cells,
                alloc.get_height() / (bead_imgs[j.color_i]->get_height() - .5) * .5);
            draw_img(cr, bead_s_img, alloc.get_width() * j.pos[0], alloc.get_height() * j.pos[1],
                alloc.get_width() / (bead_s_img->get_width() - .5) * inv_num_cells,
                alloc.get_height() / (bead_s_img->get_height() - .5) * .5);
        }

        // draw # for left store
        draw_num(cr, font, b.l_store.beads.size(), alloc.get_width() * .5 * inv_num_cells,
            alloc.get_height() * .5);

        // draw bg for right store
        draw_img(cr, bg_store, alloc.get_width() * (1.0 - inv_num_cells), 0,
            alloc.get_width() / (bg_store->get_width() - .5) * inv_num_cells,
            alloc.get_height() / (bg_store->get_height() - .5));

        // r store beads
        for(auto & j: b.r_store.beads)
        {
            draw_img(cr, bead_imgs[j.color_i], alloc.get_width() * j.pos[0], alloc.get_height() * j.pos[1],
                alloc.get_width() / (bead_imgs[j.color_i]->get_width() - .5) * inv_num_cells,
                alloc.get_height() / (bead_imgs[j.color_i]->get_height() - .5) * .5);
            draw_img(cr, bead_s_img, alloc.get_width() * j.pos[0], alloc.get_height() * j.pos[1],
                alloc.get_width() / (bead_s_img->get_width() - .5) * inv_num_cells,
                alloc.get_height() / (bead_s_img->get_height() - .5) * .5);
        }

        // draw # for right store
        draw_num(cr, font, b.r_store.beads.size(), alloc.get_width() * (1.0 - .5 * inv_num_cells),
            alloc.get_height() * .5);

        // draw bowls
        for(size_t i = 0; i < b.top_row.size(); ++i)
        {
            // draw upper row hint
            if(hint_player == PLAYER_2 && show_hint && hint_i == (int)i)
            {
                draw_img(cr, hint_img, alloc.get_width() * (i + 1) * inv_num_cells, 0.0,
                    alloc.get_width() / (hint_img->get_width() - .5) * inv_num_cells,
                    alloc.get_height() / (hint_img->get_height() - .5) * .5);
            }

            // upper row bgs
            draw_img(cr, bg_bowl, alloc.get_width() * (i + 1) * inv_num_cells, 0,
                alloc.get_width() / (bg_bowl->get_width() - .5) * inv_num_cells,
                alloc.get_height() / (bg_bowl->get_height() - .5) * .5);

            // upper row beads
            for(auto & j: b.top_row[i].beads)
            {
                draw_img(cr, bead_imgs[j.color_i], alloc.get_width() * j.pos[0], alloc.get_height() * j.pos[1],
                    alloc.get_width() / (bead_imgs[j.color_i]->get_width() - .5) * inv_num_cells,
                    alloc.get_height() / (bead_imgs[j.color_i]->get_height() - .5) * .5);
                draw_img(cr, bead_s_img, alloc.get_width() * j.pos[0], alloc.get_height() * j.pos[1],
                    alloc.get_width() / (bead_s_img->get_width() - .5) * inv_num_cells,
                    alloc.get_height() / (bead_s_img->get_height() - .5) * .5);
            }

            // upper row txt
            draw_num(cr, font, b.top_row[i].beads.size(), alloc.get_width() * (2 * i + 3) * .5 * inv_num_cells,
                alloc.get_height() * .25);

            // draw lower row hint
            if(hint_player == PLAYER_1 && show_hint && hint_i == (int)i)
            {
                draw_img(cr, hint_img, alloc.get_width() * (i + 1) * inv_num_cells, .5 * alloc.get_height(),
                    alloc.get_width() / (hint_img->get_width() - .5) * inv_num_cells,
                    alloc.get_height() / (hint_img->get_height() - .5) * .5);
            }

            // lower row bgs
            draw_img(cr, bg_bowl, alloc.get_width() * (i + 1) * inv_num_cells, .5 * alloc.get_height(),
                alloc.get_width() / (bg_bowl->get_width() - .5) * inv_num_cells,
                alloc.get_height() / (bg_bowl->get_height() - .5) * .5);

            // lower row beads
            for(auto & j: b.bottom_row[i].beads)
            {
                draw_img(cr, bead_imgs[j.color_i], alloc.get_width() * j.pos[0], alloc.get_height() * j.pos[1],
                    alloc.get_width() / (bead_imgs[j.color_i]->get_width() - .5) * inv_num_cells,
                    alloc.get_height() / (bead_imgs[j.color_i]->get_height() - .5) * .5);
                draw_img(cr, bead_s_img, alloc.get_width() * j.pos[0], alloc.get_height() * j.pos[1],
                    alloc.get_width() / (bead_s_img->get_width() - .5) * inv_num_cells,
                    alloc.get_height() / (bead_s_img->get_height() - .5) * .5);
            }

            // lower row txt
            draw_num(cr, font, b.bottom_row[i].beads.size(), alloc.get_width() * (2 * i + 3) * .5 * inv_num_cells,
                alloc.get_height() * .75);
        }
        return true;
    }
Beispiel #4
0
void OutputFile::generate() {
    unsigned E=es.size();
    bool cleanupRoutes=false;
    if(routes==NULL) {
        cleanupRoutes=true;
        routes = new vector<straightener::Route*>(E);
        for(unsigned i=0;i<E;i++) {
            straightener::Route* r=new straightener::Route(2);
            r->xs[0]=rs[es[i].first]->getCentreX();
            r->ys[0]=rs[es[i].first]->getCentreY();
            r->xs[1]=rs[es[i].second]->getCentreX();
            r->ys[1]=rs[es[i].second]->getCentreY();
            (*routes)[i]=r;
        }
    }

#if defined (CAIRO_HAS_SVG_SURFACE) && defined (CAIRO_HAS_PDF_SURFACE)
    double width,height,r=2;
    if(rects) r=rs[0]->width()/2;
    double xmin=DBL_MAX, ymin=xmin;
    double xmax=-DBL_MAX, ymax=xmax;
    for (unsigned i=0;i<rs.size();i++) {
        double x=rs[i]->getCentreX(), y=rs[i]->getCentreY();
        xmin=min(xmin,x);
        ymin=min(ymin,y);
        xmax=max(xmax,x);
        ymax=max(ymax,y);
    }
    xmax+=2*r;
    ymax+=2*r;
    xmin-=2*r;
    ymin-=2*r;
    width=xmax-xmin;
    height=ymax-ymin;

    Cairo::RefPtr<Cairo::Context> cr;
    openCairo(cr,width,height);

    /* set background colour
    cr->save(); // save the state of the context
    cr->set_source_rgb(0.86, 0.85, 0.47);
    cr->paint();    // fill image with the color
    cr->restore();  // color is back to black now
    */

    cr->set_line_width(1.);
    cr->set_font_size(8);
    cr->save();
    if(rc) for(Clusters::const_iterator c=rc->clusters.begin();c!=rc->clusters.end();c++) {
        draw_cluster_boundary(cr,**c,xmin,ymin);
    }
    if(curvedEdges)
        draw_curved_edges(cr,es,xmin,ymin);
    else 
        draw_edges(cr,*routes,xmin,ymin);
    Cairo::TextExtents te;
    for (unsigned i=0;i<rs.size();i++) {
        if(!rects) {
            double x=rs[i]->getCentreX()-xmin, y=rs[i]->getCentreY()-ymin;
            cr->arc(x,y,r, 0.0, 2.0 * M_PI);
            cr->fill();
        } else {
            double x=rs[i]->getMinX()-xmin+0.5, y=rs[i]->getMinY()-ymin+0.5;
            std::string str;
            if(labels.size()==rs.size()) {
                str=labels[i];
            } else {
                std::stringstream s; s<<i;
                str=s.str();
            }
            cr->get_text_extents(str,te);
            /*
            double llx = x-te.width/2.-1;
            double lly = y-te.height/2.-1;
            cr->rectangle(llx,lly,te.width+2,te.height+2);
            */
            cr->rectangle(x,y,
                    rs[i]->width()-1,rs[i]->height()-1);
            cr->stroke_preserve();
            cr->save();
            cr->set_source_rgba(245./255., 233./255., 177./255., 0.6);
            cr->fill();
            cr->restore();
            if(labels.size()==rs.size()) {
                cr->move_to(x-te.x_bearing+te.width/2.,y-te.y_bearing+te.height/2.);
                cr->show_text(str);
            }
            cr->stroke();
        }
    }

    cr->show_page();

    std::cout << "Wrote file \"" << fname << "\"" << std::endl;

#else
    std::cout << 
            "WARNING: cola::OutputFile::generate(): No SVG file produced." <<
            std::endl <<
            "         You must have cairomm (and cairo with SVG support) " <<
            "this to work." << std::endl;
#endif

    if(cleanupRoutes) {
        for(unsigned i=0;i<E;i++) {
            delete (*routes)[i];
        }
        delete routes;
    }
}
Beispiel #5
0
bool Canvas::on_expose_event(GdkEventExpose * evt) {
	Glib::RefPtr<Gdk::Window> window = get_window();
	if (!window) return false; // no window yet?

	if (!seen_first_expose_event) {
		seen_first_expose_event = true;
		main->controlsWindow().starting_position();
	}

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

	if (!surface) return true; // Haven't rendered yet? Nothing we can do
	if (evt) {
		cr->rectangle(evt->area.x, evt->area.y, evt->area.width, evt->area.height);
		cr->clip();
	}

	cr->set_source(surface, 0, 0);
	cr->paint();

	if (main->dragrect.is_active() && main->dragrect.surface_valid()) {
		cr->save();
		cr->set_source(main->dragrect.get_surface(), 0, 0);
		cr->paint();
		cr->restore();
	}

	if (main->hud_active()) {
		Cairo::RefPtr<Cairo::Surface>& sfc = main->get_hud_surface();
		if (sfc)
			cr->set_source(sfc, 0, 0); // TODO HUD position
		cr->paint();
	}
	return true;
}
Beispiel #6
0
bool studio::Widget_Preview::redraw(const Cairo::RefPtr<Cairo::Context> &cr)
{
	//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;
	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();
	if(!wind) synfig::warning("The destination window is broken...");

	if(!use_cairo)
	{
		/* Options for drawing...
			1) store with alpha, then clear and render with alpha every frame
				- more time consuming
				+ more expandable
			2) store with just pixel info
				- less expandable
				+ faster
				+ better memory footprint
		*/
		//px->composite(const Glib::RefPtr<Gdk::Pixbuf>& dest, int dest_x, int dest_y, int dest_width, int dest_height, double offset_x, double offset_y, double scale_x, double scale_y, InterpType interp_type, int overall_alpha) const

		cr->save();
		Gdk::Cairo::set_source_pixbuf(
			cr, //cairo context
			pxnew, //pixbuf
			//coordinates to place center of the preview window
			(dw - nw) / 2, (dh - nh) / 2
			);
		cr->paint();
		cr->restore();
	}
	else
	{
		cr->save();
		cr->scale(sx, sx);
		cairo_set_source_surface(cr->cobj(), cs, (dw - nw)/(2*sx), (dh - nh)/(2*sx));
		cairo_pattern_set_filter(cairo_get_source(cr->cobj()), CAIRO_FILTER_NEAREST);
		cairo_surface_destroy(cs);
		cr->paint();
		cr->restore();
	}

	//synfig::warning("Refresh the draw area");
	//make sure the widget refreshes

	return false;
}
Beispiel #7
0
void OutputFile::draw_cluster_boundary(Cairo::RefPtr<Cairo::Context> const &cr,
        Cluster &c,
        const double xmin,
        const double ymin) {
    c.computeBoundary(rs);
    cr->save();
    // background
    cr->set_source_rgb(0.7, 0.7, 224./255.);
    cr->move_to(c.hullX[0]-xmin,c.hullY[0]-ymin);
    for(unsigned i=1;i<c.hullX.size();i++) {
        cr->line_to(c.hullX[i]-xmin,c.hullY[i]-ymin);
    }
    cr->line_to(c.hullX[0]-xmin,c.hullY[0]-ymin);
    cr->fill();
    cr->restore();
    // outline
    cr->move_to(c.hullX[0]-xmin,c.hullY[0]-ymin);
    for(unsigned i=1;i<c.hullX.size();i++) {
        cr->line_to(c.hullX[i]-xmin,c.hullY[i]-ymin);
    }
    cr->line_to(c.hullX[0]-xmin,c.hullY[0]-ymin);
    cr->stroke();
}
Beispiel #8
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 #9
0
void NodeRenderer::icon(const Cairo::RefPtr<Cairo::Context>& cr, IconCache& cache)
{
	// path to icon not set
	if (s->icon.str().size() == 0 || s->icon_width == 0.0 || s->icon_height == 0.0)
		return;

	cr->save();

	Cairo::RefPtr<Cairo::ImageSurface> image = cache.getIcon(s->icon.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);
	cr->paint();

	cr->restore();
}
Beispiel #10
0
/**
 * Render the Preview
 * @param Cairo::Context cr
 * @return Gtk::Window::on_draw(cr)
 */
bool Preview::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
      
    Configuration::Theme theme = Configuration::getTheme();
    if (theme.forPreview().enabled()) {


        cr->set_source_rgba(
                theme.forPreview().background().red,
                theme.forPreview().background().green,
                theme.forPreview().background().blue,
                theme.forPreview().background().alpha);

        Utilities::RoundedRectangle(cr, 0, 0, this->get_width(), this->get_height(),
                theme.forPreview().roundedRatious());

        cr->fill();

    }




    if (!m_isActive) {
        return Gtk::Window::on_draw(cr);
    }


    if (m_previewtems.size() < 1) {
        this->hideMe();
        return Gtk::Window::on_draw(cr);
    }



    int idx = 0;
    for (DockItem* item : m_previewtems) {
        if (item->m_window == NULL || item->m_xid == 0 || !item->visible)
            continue;

        int pos_x = 20 + (m_previewWidth * idx);
        int pos_y = 16;
        int pos_width = m_previewWidth - DEF_PREVIEW_LEFT_MARGING;
        int pos_height = 20;


        cr->set_source_rgba(
                theme.forPreview().foreground().red,
                theme.forPreview().foreground().green,
                theme.forPreview().foreground().blue,
                theme.forPreview().foreground().alpha);

        cr->set_line_width(theme.forPreview().lineWith());

        if (item->m_imageLoadedRequired)
            cr->set_line_width(theme.forPreview().lineWith() + 0.5);

        if (theme.getPreviewBinaryValue() == 0) {
            Utilities::RoundedRectangle(cr,
                    DEF_PREVIEW_LEFT_MARGING + (m_previewWidth * idx),
                    16, m_previewWidth,
                    m_previewHeight - DEF_PREVIEW_RIGHT_MARGING,
                    theme.forPreview().roundedRatious());

            cr->stroke();
        } else {
            cr->set_line_width(theme.forPreview().lineWith());
            int pos_x = DEF_PREVIEW_LEFT_MARGING + (m_previewWidth * idx);
            int y_pos = 16;
            int width = m_previewWidth;
            int height = m_previewHeight;
            int value = theme.getPreviewBinaryValue();
            /* Vertical Left*/
            int bit = CHECK_BIT(value, 3);
            if (bit == 1) {

                cr->set_line_width(theme.forPreview().lineWith());
                cr->move_to(pos_x, y_pos);
                cr->line_to(pos_x, y_pos);
                cr->line_to(pos_x, y_pos + (m_previewHeight - DEF_PREVIEW_RIGHT_MARGING));
                cr->stroke();

            }
            /* Top */
            bit = CHECK_BIT(value, 2);
            if (bit == 1) {
                cr->set_line_width(theme.forPreview().lineWith());
                cr->move_to(pos_x, y_pos);
                cr->line_to(pos_x, y_pos);
                cr->line_to(pos_x + (m_previewWidth), y_pos);
                cr->stroke();
            }

            /* Right vertical */
            bit = CHECK_BIT(value, 1);
            if (bit == 1) {
                cr->set_line_width(theme.forPreview().lineWith());
                cr->move_to(pos_x + m_previewWidth, y_pos);
                cr->line_to(pos_x + m_previewWidth, y_pos);
                cr->line_to(pos_x + m_previewWidth, y_pos + (m_previewHeight - DEF_PREVIEW_RIGHT_MARGING));
                cr->stroke();
            }

            bit = CHECK_BIT(value, 0);
            if (bit == 1) {
                cr->set_line_width(theme.forPreview().lineWith());
                cr->move_to(pos_x, y_pos + (m_previewHeight - DEF_PREVIEW_RIGHT_MARGING));
                cr->line_to(pos_x, y_pos + (m_previewHeight - DEF_PREVIEW_RIGHT_MARGING));
                cr->line_to(pos_x + m_previewWidth, y_pos + (m_previewHeight - DEF_PREVIEW_RIGHT_MARGING));
                cr->stroke();
            }

        }


        // TEXT 
        // draw title and create clipping rectangle
        //  JG        
        cr->set_source_rgba(
                theme.forPreviewTitle().background().red,
                theme.forPreviewTitle().background().green,
                theme.forPreviewTitle().background().blue,
                theme.forPreviewTitle().foreground().alpha);
        cr->rectangle(pos_x, pos_y + 2, pos_width + 2, pos_height);
        // cr->clip_preserve();
        cr->fill();
        //    JG
        cr->set_source_rgba(
                theme.forPreviewTitle().foreground().red,
                theme.forPreviewTitle().foreground().green,
                theme.forPreviewTitle().foreground().blue,
                theme.forPreviewTitle().foreground().alpha);
        cr->set_line_width(theme.forPreviewTitle().lineWith());
        cr->rectangle(pos_x, pos_y + 2, pos_width + 2, pos_height);
        cr->stroke();



        // draw title the clipping rectangle
        //cr->set_source_rgba(1.0, 1.0, 1.0, 0.0);

        cr->rectangle(pos_x, pos_y + 2, pos_width, pos_height);
        cr->clip_preserve();
        cr->stroke();




        cr->set_source_rgba(
                theme.forPreviewTitleText().foreground().red,
                theme.forPreviewTitleText().foreground().green,
                theme.forPreviewTitleText().foreground().blue,
                theme.forPreviewTitleText().foreground().alpha);

        auto layout = create_pango_layout(item->m_titlename);
        layout->set_font_description(font);
        //cr->set_source_rgba(1.0, 1.0, 1.0, 1.0); // white text
        cr->move_to(pos_x, pos_y + 2);
        layout->show_in_cairo_context(cr);
        cr->reset_clip(); // Reset the clipping 



        if (item->m_imageLoadedRequired) {
            GdkPixbuf *scaledpb = getScaledPixbuf(item);

            if (scaledpb == nullptr) {
                continue;
            }

            // show the loaded image. 
            showPreview(cr, scaledpb, idx);

            // Checks if the image have movement.
            if (item->isMovementDetected(scaledpb) && !item->m_isDynamic) {
                item->m_isDynamic = true;
            }

            // if no movement has been detected, means that the image 
            // is static and we don't need to reload it again 
            if (++item->m_frames > 3 && !item->m_isDynamic) {
                item->m_scaledPixbuf = scaledpb;
                item->m_frames = 0;
                item->m_imageLoadedRequired = false;
            }

            // if the image is static do not unreference the scaledpb.
            if (item->m_imageLoadedRequired)
                g_object_unref(scaledpb);

        } else {
            // show the loaded static image. 
            showPreview(cr, item->m_scaledPixbuf, idx);

        }



        // selector
        if (m_currentIndex == idx) {

            // rectangle background selector
            pos_x = DEF_PREVIEW_LEFT_MARGING + (m_previewWidth * m_currentIndex);
            pos_y = 16;
            pos_width = m_previewWidth + 1;
            pos_height = m_previewHeight - DEF_PREVIEW_RIGHT_MARGING;

            if (m_previewtems.size() > 1) {
                cr->set_source_rgba(
                        theme.forPreviewSelector().background().red,
                        theme.forPreviewSelector().background().green,
                        theme.forPreviewSelector().background().blue,
                        theme.forPreviewSelector().background().alpha);

                Utilities::RoundedRectangle(cr, pos_x, pos_y, pos_width, pos_height,
                        theme.forPreviewSelector().roundedRatious());
                cr->fill();
            }

            cr->set_source_rgba(
                    theme.forPreviewSelector().foreground().red,
                    theme.forPreviewSelector().foreground().green,
                    theme.forPreviewSelector().foreground().blue,
                    theme.forPreviewSelector().foreground().alpha);
            cr->set_line_width(theme.forPreviewSelector().lineWith());

            if (theme.getPreviewSelectorBinaryValue() == 0) {

                Utilities::RoundedRectangle(cr, pos_x, pos_y, pos_width, pos_height,
                        theme.forPreviewSelector().roundedRatious());
                cr->stroke();
            } else {


                int value = theme.getPreviewSelectorBinaryValue();
                //                /* Vertical Left*/
                int bit = CHECK_BIT(value, 3);
                if (bit == 1) {


                    cr->move_to(pos_x, pos_y);
                    cr->line_to(pos_x, pos_y);
                    cr->line_to(pos_x, pos_y + (pos_height));
                    cr->stroke();

                }
                /* Top */
                bit = CHECK_BIT(value, 2);
                if (bit == 1) {

                    cr->move_to(pos_x, pos_y);
                    cr->line_to(pos_x, pos_y);
                    cr->line_to(pos_x + (pos_width), pos_y);
                    cr->stroke();
                }

                /* Right vertical */
                bit = CHECK_BIT(value, 1);
                if (bit == 1) {

                    cr->move_to(pos_x + pos_width, pos_y);
                    cr->line_to(pos_x + pos_width, pos_y);
                    cr->line_to(pos_x + pos_width, pos_y + (m_previewHeight - DEF_PREVIEW_RIGHT_MARGING));
                    cr->stroke();
                }

                bit = CHECK_BIT(value, 0);
                if (bit == 1) {

                    cr->move_to(pos_x, pos_y + (m_previewHeight - DEF_PREVIEW_RIGHT_MARGING));
                    cr->line_to(pos_x, pos_y + (m_previewHeight - DEF_PREVIEW_RIGHT_MARGING));
                    cr->line_to(pos_x + m_previewWidth, pos_y + (m_previewHeight - DEF_PREVIEW_RIGHT_MARGING));
                    cr->stroke();
                }
            }


            cr->set_source_rgba(
                    theme.forPreviewSelectorClose().background().red,
                    theme.forPreviewSelectorClose().background().green,
                    theme.forPreviewSelectorClose().background().blue,
                    theme.forPreviewSelectorClose().background().alpha);


            pos_x = (m_previewWidth - 5) + (m_previewWidth * m_currentIndex);
            cr->move_to(pos_x + 3, DEF_PREVIEW_RIGHT_MARGING);

            cr->rectangle(pos_x, 18, DEF_PREVIEW_LEFT_MARGING, DEF_PREVIEW_LEFT_MARGING + 2);
            cr->fill();

            cr->set_source_rgba(
                    theme.forPreviewSelectorClose().foreground().red,
                    theme.forPreviewSelectorClose().foreground().green,
                    theme.forPreviewSelectorClose().foreground().blue,
                    theme.forPreviewSelectorClose().foreground().alpha);
            cr->set_line_width(theme.forPreviewSelectorClose().lineWith());

            // Close X text
            cr->move_to(pos_x + 3, DEF_PREVIEW_RIGHT_MARGING - 1);
            cr->show_text("X");


        }




        idx++;
    }
    return Gtk::Window::on_draw(cr);
}
Beispiel #11
0
bool
ColorSlider::on_draw(const Cairo::RefPtr<Cairo::Context> &cr)
{
	Color color(color_);

	static const slider_color_func jump_table[int(TYPE_END)] =
	{
		slider_color_TYPE_R,
		slider_color_TYPE_G,
		slider_color_TYPE_B,
		slider_color_TYPE_Y,
		slider_color_TYPE_U,
		slider_color_TYPE_V,
		slider_color_TYPE_HUE,
		slider_color_TYPE_SAT,
		slider_color_TYPE_A,
	};

	slider_color_func color_func(jump_table[int(type)]);

	float amount;
	switch(type)
	{
		case TYPE_R: amount=color.get_r(); break;
		case TYPE_G: amount=color.get_g(); break;
		case TYPE_B: amount=color.get_b(); break;
		case TYPE_Y: amount=color.get_y(); break;
		case TYPE_U: amount=color.get_u()+0.5; break;
		case TYPE_V: amount=color.get_v()+0.5; break;
		case TYPE_HUE: amount=Angle::rot(color.get_uv_angle()).get(); amount-=floor(amount); break;
		case TYPE_SAT: amount=color.get_s()*2.0; break;
		case TYPE_A: amount=color.get_a(); break;
		default: amount=0; break;
	}
	if(use_colorspace_gamma() && (type<TYPE_U))
		amount=gamma_in(amount);

	const int height(get_height());
	const int width(get_width());

	Gdk::Rectangle ca(0,0,width,height);

	const Color bg1(0.75, 0.75, 0.75);
	const Color bg2(0.5, 0.5, 0.5);
	int i;
	for(i=width-1;i>=0;i--)
	{
		color_func(color,
				   (use_colorspace_gamma() && type<TYPE_U)
				   ? gamma_out(float(i)/float(width))
				   :		  (float(i)/float(width)));
		const Color c1(
			colorconv_apply_gamma(
				Color::blend(color,bg1,1.0).clamped() ));
		const Color c2(
			colorconv_apply_gamma(
				Color::blend(color,bg2,1.0).clamped() ));
		assert(c1.is_valid());
		assert(c2.is_valid());

		if((i*2/height)&1)
		{
	        cr->set_source_rgb(c1.get_r(), c1.get_g(), c1.get_b());
	        cr->rectangle(ca.get_x()+i, ca.get_y(), 1, height/2);
	        cr->fill();

	        cr->set_source_rgb(c2.get_r(), c2.get_g(), c2.get_b());
	        cr->rectangle(ca.get_x()+i, ca.get_y()+height/2, 1, height/2);
	        cr->fill();
		}
		else
		{
	        cr->set_source_rgb(c2.get_r(), c2.get_g(), c2.get_b());
	        cr->rectangle(ca.get_x()+i, ca.get_y(), 1, height/2);
	        cr->fill();

	        cr->set_source_rgb(c1.get_r(), c1.get_g(), c1.get_b());
	        cr->rectangle(ca.get_x()+i, ca.get_y()+height/2, 1, height/2);
	        cr->fill();
		}
	}

	get_style_context()->render_arrow(
		cr,
		1.5*M_PI,
		(int(amount*width)-height/2),
		0,
		height
	);

    cr->set_source_rgb(1, 1, 1);
    cr->rectangle(ca.get_x()+1, ca.get_y()+1, width-3, height-3);
    cr->stroke();

    cr->set_source_rgb(0, 0, 0);
    cr->rectangle(ca.get_x(), ca.get_y(), width-1, height-1);
    cr->stroke();
	return true;
}
Beispiel #12
0
void DependencyArrow::draw(const Cairo::RefPtr<Cairo::Context>& context) const
{
    // the way to compute the (tcx, tcy) single control point of the
    // quadratic
    double dX = mControlPoint.getX() - mOrigin->getX();
    double dY = mControlPoint.getY() - mOrigin->getY();
    double d1 = std::sqrt(dX * dX + dY * dY);
    double d = d1;

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

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

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

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

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

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

    context->set_dash(dashes,0.);
    context->move_to(mOrigin->getX(), mOrigin->getY());
    context->curve_to(tcxq1, tcyq1, tcxq2, tcyq2, mDestination->getX(),
        mDestination->getY());
    context->stroke();
    context->restore();
}
Beispiel #13
0
static void
draw_page (GtkPrintOperation */*operation*/,
           GtkPrintContext   *context,
           gint               /*page_nr*/,
           gpointer           user_data)
{
    struct workaround_gtkmm *junk = (struct workaround_gtkmm*)user_data;
    //printf("%s %d\n",__FUNCTION__, page_nr);

    if (junk->_tab->as_bitmap()) {
        // Render as exported PNG
        gdouble width = sp_document_width(junk->_doc);
        gdouble height = sp_document_height(junk->_doc);
        gdouble dpi = junk->_tab->bitmap_dpi();
        std::string tmp_png;
        std::string tmp_base = "inkscape-print-png-XXXXXX";

        int tmp_fd;
        if ( (tmp_fd = Inkscape::IO::file_open_tmp (tmp_png, tmp_base)) >= 0) {
            close(tmp_fd);

            guint32 bgcolor = 0x00000000;
            Inkscape::XML::Node *nv = sp_repr_lookup_name (junk->_doc->rroot, "sodipodi:namedview");
            if (nv && nv->attribute("pagecolor"))
                bgcolor = sp_svg_read_color(nv->attribute("pagecolor"), 0xffffff00);
            if (nv && nv->attribute("inkscape:pageopacity"))
                bgcolor |= SP_COLOR_F_TO_U(sp_repr_get_double_attribute (nv, "inkscape:pageopacity", 1.0));

            sp_export_png_file(junk->_doc, tmp_png.c_str(), 0.0, 0.0,
                width, height,
                (unsigned long)(width * dpi / PX_PER_IN),
                (unsigned long)(height * dpi / PX_PER_IN),
                dpi, dpi, bgcolor, NULL, NULL, true, NULL);

            // This doesn't seem to work:
            //context->set_cairo_context ( Cairo::Context::create (Cairo::ImageSurface::create_from_png (tmp_png) ), dpi, dpi );
            //
            // so we'll use a surface pattern blat instead...
            //
            // but the C++ interface isn't implemented in cairomm:
            //context->get_cairo_context ()->set_source_surface(Cairo::ImageSurface::create_from_png (tmp_png) );
            //
            // so do it in C:
            {
                Cairo::RefPtr<Cairo::ImageSurface> png = Cairo::ImageSurface::create_from_png (tmp_png);
                cairo_t *cr = gtk_print_context_get_cairo_context (context);
		cairo_matrix_t m;
		cairo_get_matrix(cr, &m);
		cairo_scale(cr, PT_PER_IN / dpi, PT_PER_IN / dpi);
                // FIXME: why is the origin offset??
                cairo_set_source_surface(cr, png->cobj(), -16.0, -16.0);
		cairo_paint(cr);
		cairo_set_matrix(cr, &m);
            }

            // Clean up
            unlink (tmp_png.c_str());
        }
        else {
            g_warning(_("Could not open temporary PNG for bitmap printing"));
        }
    }
    else {
        // Render as vectors
        Inkscape::Extension::Internal::CairoRenderer renderer;
        Inkscape::Extension::Internal::CairoRenderContext *ctx = renderer.createContext();

        // ctx->setPSLevel(CAIRO_PS_LEVEL_3);
        ctx->setTextToPath(false);
        ctx->setFilterToBitmap(true);
        ctx->setBitmapResolution(72);

        cairo_t *cr = gtk_print_context_get_cairo_context (context);
        cairo_surface_t *surface = cairo_get_target(cr);


/**
	Call cairo_win32_printing_surface directly as a workaround until GTK uses this call.
	When GTK uses cairo_win32_printing_surface this automatically reverts.
*/
#ifdef WIN32
        if (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_WIN32) {
        HDC dc = cairo_win32_surface_get_dc (surface);
        surface = _cairo_win32_printing_surface_create (dc);
        }
#endif

        bool ret = ctx->setSurfaceTarget (surface, true);        if (ret) {
            ret = renderer.setupDocument (ctx, junk->_doc, TRUE, NULL);
            if (ret) {
                renderer.renderItem(ctx, junk->_base);
                ret = ctx->finish();
            }
            else {
                g_warning(_("Could not set up Document"));
            }
        }
        else {
            g_warning(_("Failed to set CairoRenderContext"));
        }

        // Clean up
        renderer.destroyContext(ctx);
    }

}
bool AdvEnvGUIScope::on_expose_event(GdkEventExpose* event)
{
	Glib::RefPtr<Gdk::Window> window = get_window();
	if (window)
	{
		float len, x, y, xscale, yscale;

		Gtk::Allocation allocation = get_allocation();
		const int width = allocation.get_width();
		const int height = allocation.get_height();

		Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
		cr->set_line_width(2.0);
		cr->set_source_rgb(0.0, 0.0, 0.0);
		cr->paint();

		cr->set_source_rgb(0.0, 0.8, 0.0);

		cr->rectangle(event->area.x, event->area.y, event->area.width, event->area.height);
		cr->clip();

		cr->move_to(width, height);

		len = m_valueDelay + m_valueAttackTime1 + m_valueAttackTime2 + m_valueAttackTime3 + m_valueAttackTime4 + m_valueReleaseTime1 + m_valueReleaseTime2 + m_valueReleaseTime3 + SUSTAIN_LEN;
		xscale = (float) width / len;
		yscale = (float) (height - 6);

		x = m_valueDelay * xscale;
		cr->line_to((int) x, height);
		x += m_valueAttackTime1 * xscale;
		y = m_valueAttackLevel1 * yscale;
		cr->line_to((int) x, height - (int) y);
		x += m_valueAttackTime2 * xscale;
		y = m_valueAttackLevel2 * yscale;
		cr->line_to((int) x, height - (int) y);
		x += m_valueAttackTime3 * xscale;
		y = m_valueAttackLevel3 * yscale;
		cr->line_to((int) x, height - (int) y);
		x += m_valueAttackTime4 * xscale;
		y = m_valueSustain * yscale;
		cr->line_to((int) x, height - (int) y);
		x += SUSTAIN_LEN * xscale;
		cr->line_to((int) x, height - (int) y);
		x += m_valueReleaseTime1 * xscale;
		y = m_valueReleaseLevel1 * yscale;
		cr->line_to((int) x, height - (int) y);
		x += m_valueReleaseTime2 * xscale;
		y = m_valueReleaseLevel2 * yscale;
		cr->line_to((int) x, height - (int) y);
		x += m_valueReleaseTime3 * xscale;
		cr->line_to((int) x, height);
		x = m_valueDelay * xscale;
		cr->line_to((int) x, height);
		cr->stroke();
	}

	return true;
}
Beispiel #15
0
    void NodeSurface::DrawNodeText( 
        Cairo::RefPtr<Cairo::Context> refCairo, 
        TopologyNode* pNode,
        int x, 
        int y )
    {
        refCairo->save();

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

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

        char idCaption[128];

        TopologyNode::NodeType nodeType = pNode->GetNodeType();        
        switch (nodeType)
        {
        case TopologyNode::COMPUTER:
            sprintf( idCaption, "PC" );
            break;

        case TopologyNode::BUS:
            {
                refCairo->set_font_size( 18 );

                InterfaceType interfaceType = pNode->GetInterfaceType();
                switch (interfaceType)
                {
                case INTERFACE_IEEE1394:
                    sprintf( idCaption, "1394 Bus" );
                    break;
                case INTERFACE_USB2:
                    sprintf( idCaption, "USB Bus" );
                    break;
				case INTERFACE_GIGE:
                    sprintf( idCaption, "GigE Bus" );
                    break;
                default:
                    sprintf( idCaption, "Bus" );
                    break;
                }                
            }            
            break;

        case TopologyNode::CAMERA:
            sprintf( idCaption, "ID: %d", pNode->GetDeviceId() );
            break;

        case TopologyNode::NODE:
            sprintf( idCaption, "Node" );
            break;
        }

        Cairo::TextExtents textExtents;
        refCairo->get_text_extents( idCaption, textExtents );
        refCairo->move_to( x - (textExtents.width / 2) , y + (textExtents.height / 2) );
        refCairo->show_text( idCaption );

        refCairo->restore();
    }
bool CPagePreview::on_expose_event(GdkEventExpose *event)
	{			
	Glib::RefPtr<Gdk::Window> window = get_window();
	if(window)
		{
		// get the cairo context amd allocation
		Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
		Gtk::Allocation allocation = get_allocation();
		const int width = allocation.get_width();
		const int height = allocation.get_height();
		
		// coordinates for the center of the window
		int xc, yc;
		xc = width / 2;
		yc = height / 2;

		
		// 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();
		
		// draw a neat shadow
		cr->set_source_rgba(0.0,0.0,0.0,0.4);
		cr->begin_new_path();
		cr->move_to( xborder+offset,yborder+offset );
		cr->line_to( width-xborder+offset,yborder+offset );
		cr->line_to( width-xborder+offset,height-yborder+offset );
		cr->line_to( xborder+offset,height-yborder+offset );
		cr->close_path();
		cr->fill();

		// draw the page outline
		cr->set_source_rgb(0.0,0.0,0.0); // black
		cr->set_line_width( 2.0 );
		cr->begin_new_path();
		cr->move_to( xborder-offset,yborder-offset );
		cr->line_to( width-xborder-offset,yborder-offset );
		cr->line_to( width-xborder-offset,height-yborder-offset );
		cr->line_to( xborder-offset,height-yborder-offset );
		cr->close_path();
		cr->stroke_preserve();
		
		// fill the page with white
		cr->save();
		cr->set_source_rgb(1.0,1.0,1.0); // white
		cr->fill_preserve();
		cr->restore();
		
		// draw the page margin
		cr->set_source_rgb( 0.8,0.8,0.8 ); // light grey
		cr->set_line_width( 1.0 );
		cr->begin_new_path();
		cr->move_to( uleft.x, uleft.y );
		cr->line_to( lright.x, uleft.y );
		cr->line_to( lright.x, lright.y );
		cr->line_to( uleft.x, lright.y );
		cr->close_path();
		cr->stroke();

		// and the image preview
		ImagePixbuf->render_to_drawable( get_window(),
									get_style()->get_black_gc(),
									0,
									0,
									xpos,
									ypos,
									ImagePixbuf->get_width(), //image->get_width(),
									ImagePixbuf->get_height(), //image->get_height(),
									Gdk::RGB_DITHER_NONE,0,0 ); // */
									
		return true;
		}
	}
Beispiel #17
0
    void NodeSurface::DrawPorts( 
        Cairo::RefPtr<Cairo::Context> refCairo, 
        TopologyNode* pNode )
    {
        refCairo->save();

        const float k_divisor = 255.0;
        float red = 38 / k_divisor;
        float green = 199 / k_divisor;
        float blue = 38 / k_divisor;
        refCairo->set_source_rgb( red, green, blue );

        refCairo->set_source_rgb( 0, 0, 0 );

        refCairo->set_line_width( 5 );

        int numChildren = 0;
        for ( unsigned int i=0; i < pNode->GetNumPorts(); i++ )
        {
            if ( pNode->GetPortType(i) == TopologyNode::CONNECTED_TO_CHILD )
            {
                numChildren++;
            }
        }

        int childIndex = 0;
        for ( unsigned int i=0; i < pNode->GetNumPorts(); i++ )
        {
            TopologyNode::PortType currPort = pNode->GetPortType(i);

            switch (currPort)
            {
            case TopologyNode::NOT_CONNECTED:
                break;

            case TopologyNode::CONNECTED_TO_PARENT:                
                {
                    refCairo->move_to( sk_nodeWidth/2 - sk_portWidth/2, 0 );
                    refCairo->rel_line_to( sk_portWidth, 0 );
                    refCairo->rel_line_to( 0, sk_portHeight );
                    refCairo->rel_line_to( -sk_portWidth, 0 );
                    refCairo->fill();
                }
                break;

            case TopologyNode::CONNECTED_TO_CHILD:
                {
                    int startX = (sk_nodeWidth / (numChildren+1)) * (childIndex+1);

                    refCairo->move_to( startX - sk_portWidth/2, sk_nodeHeight );
                    refCairo->rel_line_to( sk_portWidth, 0 );
                    refCairo->rel_line_to( 0, -sk_portHeight );
                    refCairo->rel_line_to( -sk_portWidth, 0 );
                    refCairo->fill();                    
 
                    childIndex++;
                }
                break;

            default:
                break;

            }
        }

        refCairo->restore();
    }
Beispiel #18
0
void ItemView::drawBackground(const Cairo::RefPtr<Cairo::Context>& cr, const int width, const int height)
{
    //fill background
    if (isSelected())
    {
        cr->set_source_rgb(1, 1, 1);
        cr->rectangle(0, 0, width, height);
        cr->fill();
    }
    else
    {
        cr->set_source_rgb(0.98, 0.98, 0.98);
        cr->rectangle(0, 0, width, height);
        cr->fill();
    }

    //time area
    Cairo::RefPtr<Cairo::LinearGradient> linearGradientTime = Cairo::LinearGradient::create(0, 0, 0, height);

    //set color by status
    ColorMode colorMode = getColorMode();

    if (colorMode == COLOR_INACTIVE)
    {
        //gray
        linearGradientTime->add_color_stop_rgb(0, 0.75, 0.75, 0.75);
        linearGradientTime->add_color_stop_rgb(1, 0.65, 0.65, 0.65);
    }

    if (colorMode == COLOR_ALARM)
    {
        //orange
        linearGradientTime->add_color_stop_rgb(0, 1.00, 0.60, 0.30);
        linearGradientTime->add_color_stop_rgb(1, 0.90, 0.50, 0.20);
    }

    if (colorMode == COLOR_OK)
    {
        //green
        linearGradientTime->add_color_stop_rgb(0, 0.40, 0.70, 0.45);
        linearGradientTime->add_color_stop_rgb(1, 0.30, 0.60, 0.35);
    }

    cr->set_source(linearGradientTime);
    cr->rectangle(0, 0, TIME_WIDTH, height);
    cr->fill();

    if (isSelected())
        drawInnerShadow(cr, width, height);
}
Beispiel #19
0
Cairo::RefPtr<Cairo::ImageSurface> ImagesStorage::loadFrenchCard(Cairo::RefPtr<Cairo::ImageSurface> sourceImages, Preference::Card card)
{
	Cairo::RefPtr<Cairo::ImageSurface> cardImage = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 
		sourceImages->get_width() / 13.0, sourceImages->get_height() / 5.0);
	Cairo::RefPtr<Cairo::Context> cardsImagesDrawer = Cairo::Context::create( cardImage );
	cardsImagesDrawer->set_source_rgb(1, 1, 1);
	double x = getFrenchCardCoord(card, CT_X, sourceImages->get_width());
	double y = getFrenchCardCoord(card, CT_Y, sourceImages->get_height());
	cardsImagesDrawer->set_source(sourceImages, -x, -y);
	cardsImagesDrawer->rectangle(0, 0, sourceImages->get_width() / 13.0, sourceImages->get_height() / 5.0);
	cardsImagesDrawer->clip();
	cardsImagesDrawer->paint();
	return cardImage;
}
Beispiel #20
0
int main()
{
    Cairo::RefPtr<Cairo::ImageSurface> surface =
        Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 600, 400);

    Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);

    cr->save(); // save the state of the context
    cr->set_source_rgb(0.86, 0.85, 0.47);
    cr->paint();    // fill image with the color
    cr->restore();  // color is back to black now

    cr->save();
    // draw a border around the image
    cr->set_line_width(20.0);    // make the line wider
    cr->rectangle(0.0, 0.0, surface->get_width(), surface->get_height());
    cr->stroke();

    cr->set_source_rgba(0.0, 0.0, 0.0, 0.7);
    // draw a circle in the center of the image
    cr->arc(surface->get_width() / 2.0, surface->get_height() / 2.0,
            surface->get_height() / 4.0, 0.0, 2.0 * M_PI);
    cr->stroke();

    // draw a diagonal line
    cr->move_to(surface->get_width() / 4.0, surface->get_height() / 4.0);
    cr->line_to(surface->get_width() * 3.0 / 4.0, surface->get_height() * 3.0 / 4.0);
    cr->stroke();
    cr->restore();

#ifdef CAIRO_HAS_PNG_FUNCTIONS

    std::string filename = "image.png";
    surface->write_to_png(filename);

    std::cout << "Wrote png file \"" << filename << "\"" << std::endl;

#else

    std::cout << "You must compile cairo with PNG support for this example to work."
        << std::endl;

#endif
}
Beispiel #21
0
/*
 * draw edges bundled.  That is, edges are drawn as splines, with the control points
 * between adjacent edges outgoing from a particular node shared if the angle between them
 * is less than pi/8
 */
void OutputFile::draw_curved_edges(Cairo::RefPtr<Cairo::Context> &cr,
        vector<cola::Edge> const & es, 
        const double xmin, 
        const double ymin) {
    using namespace bundles;
    vector<CNode> nodes(rs.size());
    vector<CEdge> edges(es.size());
    for (unsigned i=0;i<es.size();i++) {
        CEdge *e=&edges[i];
        unsigned start=es[i].first;
        unsigned end=es[i].second;
        e->startID=start;
        e->endID=end;
        nodes[start].x=rs[start]->getCentreX()-xmin;
        nodes[start].y=rs[start]->getCentreY()-ymin;
        nodes[end].x=rs[end]->getCentreX()-xmin;
        nodes[end].y=rs[end]->getCentreY()-ymin;
        e->x0=nodes[start].x;
        e->x1=nodes[start].x;
        e->x2=nodes[end].x;
        e->x3=nodes[end].x;
        e->y0=nodes[start].y;
        e->y1=nodes[start].y;
        e->y2=nodes[end].y;
        e->y3=nodes[end].y;
        nodes[end].edges.push_back(e);
        nodes[start].edges.push_back(e);
    }

    for (unsigned i=0;i<nodes.size();i++) {
        CNode u=nodes[i];
        if(u.edges.size()<2) continue;
        for (unsigned j=0;j<u.edges.size();j++) {
            CBundle* b=new CBundle(u);
            b->addEdge(u.edges[j]);
            u.bundles.push_back(b);
        }
        u.bundles.sort(clockwise());
        /*
        printf("Sorted:  \n");
        list<CBundle*>::iterator i,j;
        for(list<CBundle*>::iterator i=u.bundles.begin();i!=u.bundles.end();i++) {
                CBundle* a=*i;
                a->dump();
                printf("  angle=%f\n",a->yangle());
        }
        printf("---------\n");
        */
        while(true) {
            double minAngle=DBL_MAX;
            list<CBundle*>::iterator mini,minj,i,j;
            for(i=u.bundles.begin();i!=u.bundles.end();i++) {
                j=i;
                if(++j==u.bundles.end()) {
                    j=u.bundles.begin(); 
                }
                CBundle* a=*i;
                CBundle* b=*j;
                double angle=b->yangle()-a->yangle();
                if(angle<0) angle+=2*M_PI;
                //printf("between ");
                //a->dump(); b->dump();
                //printf(" angle=%f\n",angle);
                if(angle<minAngle) {
                    minAngle=angle;
                    mini=i;
                    minj=j;
                }
            }
            if(minAngle>cos(M_PI/8.)) break;
            CBundle* a=*mini;
            CBundle* b=*minj;
            //a->dump();
            //b->dump();
            b->merge(a);
            //printf("***Merged on %f***: ",minAngle);
            //b->dump();
            //printf("\n");
            u.bundles.erase(mini);
            if(u.bundles.size() < 2) break;
        }
        for(list<CBundle*>::iterator i=u.bundles.begin();i!=u.bundles.end();i++) {
            CBundle* b=*i;
            for(unsigned i=0;i<b->edges.size();i++) {
                CEdge* e=b->edges[i];
                if(e->x0==u.x&&e->y0==u.y) {
                    e->x1=b->x1();
                    e->y1=b->y1();
                } else {
                    e->x2=b->x1();
                    e->y2=b->y1();
                }
            }
        }
    }

    cr->save();
    // background
    cr->set_source_rgba(0,0,1,0.2);
    for (unsigned i=0;i<edges.size();i++) {
        CEdge &e=edges[i];
        cr->move_to(e.x0,e.y0);
        cr->curve_to(e.x1,e.y1,e.x2,e.y2,e.x3,e.y3);
        cr->stroke();
    }
    cr->restore();
}
Beispiel #22
0
void MapDrawArea::ClearDrawingArea(const Cairo::RefPtr<Cairo::Context>& cr)
{
	cr->set_source_rgb(255,255,255);
	cr->paint();
}
Beispiel #23
0
bool
Widget_Curves::on_draw(const Cairo::RefPtr<Cairo::Context> &cr)
{
	const int h(get_height());
	const int w(get_width());

	get_style_context()->render_background(cr, 0, 0, w, h);

	if(!time_adjustment_ || !range_adjustment_ || !h || !w)
		return false;

	if(!curve_list_.size())
		return false;

	const Real t_begin(time_adjustment_->get_lower());
	const Real t_end(time_adjustment_->get_upper());
	const Real dt((t_end-t_begin)/w);

	const Real r_bottom(range_adjustment_->get_value());
	const Real r_top(r_bottom+range_adjustment_->get_page_size());
	const Real dr((r_top-r_bottom)/h);
	Real r_max(-100000000);
	Real r_min(100000000);

	std::list<CurveStruct>::iterator curve_iter;
	//Figure out maximum number of channels
	for(curve_iter=curve_list_.begin();curve_iter!=curve_list_.end();++curve_iter)
	{
		int channels(curve_iter->channels.size());
		if(channels>MAX_CHANNELS)
		{
			channels=MAX_CHANNELS;
			synfig::warning("Not allowed more than %d channels! Truncating...", MAX_CHANNELS);
		}
	}
	// and use it when sizing the points
	vector<Gdk::Point> points[MAX_CHANNELS];

	// Draw zero mark
	cr->set_source_rgb(0.31, 0.31, 0.31);
	cr->rectangle(0, round_to_int((0-r_bottom)/dr), w, 0);
	cr->stroke();

	// This try to find a valid canvas to show the keyframes of those
	// valuenodes. If not canvas found then no keyframes marks are shown.
	synfig::Canvas::Handle canvas=0;
	for(curve_iter=curve_list_.begin();curve_iter!=curve_list_.end();++curve_iter)
	{
		canvas=curve_iter->value_desc.get_canvas();
		if(canvas)
			break;
	}

	if(canvas)
	{
	// Draw vertical lines for the keyframes marks.
		const synfig::KeyframeList& keyframe_list(canvas->keyframe_list());
		synfig::KeyframeList::const_iterator iter;

		for(iter=keyframe_list.begin();iter!=keyframe_list.end();++iter)
		{
			if(!iter->get_time().is_valid())
				continue;

			const int x((int)((float)w/(t_end-t_begin)*(iter->get_time()-t_begin)));
			if(iter->get_time()>=t_begin && iter->get_time()<t_end)
			{
				cr->set_source_rgb(0.63, 0.5, 0.5);
				cr->rectangle(x, 0, 1, h);
				cr->fill();
			}
		}
	}

	// Draw current time
	cr->set_source_rgb(0, 0, 1);
	cr->rectangle(round_to_int((time_adjustment_->get_value()-t_begin)/dt), 0, 0, h);
	cr->stroke();

	// Draw curves for the valuenodes stored in the curve list
	for(curve_iter=curve_list_.begin();curve_iter!=curve_list_.end();++curve_iter)
	{
		Real t;
		int i;
		int channels(curve_iter->channels.size());
		for(i=0;i<channels;i++)
			points[i].clear();

		for(i=0,t=t_begin;i<w;i++,t+=dt)
		{
			for(int chan=0;chan<channels;chan++)
			{
				Real x(curve_iter->get_value(chan,t,dt));
				r_max=max(r_max,x);
				r_min=min(r_min,x);
				points[chan].push_back(
					Gdk::Point(
						i,
						round_to_int(
							(
								x-r_bottom
							)/dr
						)
					)
				);
			}
		}

		// Draw the graph curves with 0.5 width
		cr->set_line_width(0.5);
		for(int chan=0;chan<channels;chan++)
		{
			// Draw the curve
			std::vector<Gdk::Point> &p = points[chan];
			for(std::vector<Gdk::Point>::iterator i = p.begin(); i != p.end(); ++i)
			{
				if (i == p.begin())
					cr->move_to(i->get_x(), i->get_y());
				else
					cr->line_to(i->get_x(), i->get_y());
			}
			const Gdk::Color &color = curve_iter->channels[chan].color;
			cr->set_source_rgb(color.get_red_p(), color.get_green_p(), color.get_blue_p());
			cr->stroke();

			Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_pango_context()));
			layout->set_text(curve_iter->channels[chan].name);

			cr->move_to(1, points[chan][0].get_y()+1);
			layout->show_in_cairo_context(cr);
		}
	}

	if(!curve_list_.empty())
	{
		range_adjustment_->set_upper(r_max+range_adjustment_->get_page_size()/2);
		range_adjustment_->set_lower(r_min-range_adjustment_->get_page_size()/2);
	}

	return true;
}
Beispiel #24
0
void MapDrawArea::DrawObstacles(const Cairo::RefPtr<Cairo::Context>& cr)
{
	// Get size characteristics of the window
	Gtk::Allocation allocation = get_allocation();
	const int width = allocation.get_width();
	const int height = allocation.get_height();
	const int lesser = MIN(width, height);

	// We should be able to just store the obstacles and path once
	// Do need to update based on the window size
	std::vector<Coord> vObstacles = guiMapData.copyObstacles();
	Coord maxXY = guiMapData.copyMaxCoord();
	Coord originCoord = guiMapData.copyStartCoord();
	Coord goalCoord = guiMapData.copyEndCoord();

	// These have to be updated each iteration
	originCoord.x = int( float(width)*float(originCoord.x)/float(maxXY.x) );
	originCoord.y = int( float(height)*float(originCoord.y)/float(maxXY.y) );
	goalCoord.x = int( float(width)*float(goalCoord.x)/float(maxXY.x) );
	goalCoord.y = int( float(height)*float(goalCoord.y)/float(maxXY.y) );

	// Draw obstacles
	std::vector<Coord> scaledObstacleCoord;
	std::vector<Coord> rawObstacleCoord = guiMapData.copyObstacles();
	Coord stdCoord;

	// Adjust obstacle values based on window size
	for(std::vector<Coord>::const_iterator itr=rawObstacleCoord.begin();itr!=rawObstacleCoord.end();++itr)
	{
		stdCoord.x = int( float(width)*float(itr->x)/float(maxXY.x) );
		stdCoord.y = int( height*float(itr->y)/float(maxXY.y) );
		scaledObstacleCoord.push_back(stdCoord);
	}

	cr->save();
	cr->set_source_rgb(0.0, 0.0, 0.0);	// black for obstacles
	cr->set_line_width(lesser * 0.005);
	cr->set_line_cap(Cairo::LINE_CAP_ROUND);

	// Plot obstacles
	for(std::vector<Coord>::iterator itr=scaledObstacleCoord.begin();itr != scaledObstacleCoord.end();++itr)
	{
		cr->move_to( itr->x,itr->y );
		cr->line_to( itr->x,itr->y );
		cr->stroke();
	}

	// Plot start/end coord
	cr->save();
	cr->set_line_width(lesser * 0.015);
	cr->set_source_rgb(1.0, 0.0, 0.0);	// red for start point
	cr->move_to( originCoord.x,originCoord.y );
	cr->line_to( originCoord.x,originCoord.y );
	cr->stroke();
	cr->save();
	cr->set_source_rgb(0.0, 1.0, 0.0);	// green for end point
	cr->move_to( goalCoord.x,goalCoord.y );
	cr->line_to( goalCoord.x,goalCoord.y );
	cr->stroke();
}
Beispiel #25
0
Cairo::RefPtr<CairoContext> CairoContext::create(Cairo::RefPtr<Cairo::Surface> const &target)
{
    cairo_t *ct = cairo_create(target->cobj());
    Cairo::RefPtr<CairoContext> ret(new CairoContext(ct, true));
    return ret;
}
Beispiel #26
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 #27
0
Cairo::RefPtr<Cairo::ImageSurface>
TextSurface::create_cairo_surface(const std::string& text, const TextProperties& text_props,
                                  Cairo::TextExtents& out_text_extents,
                                  Cairo::FontExtents& out_font_extents)
{
  { // get TextExtents and FontExtents
    Cairo::RefPtr<Cairo::ImageSurface> tmp_surface = Cairo::ImageSurface::create(Cairo::FORMAT_RGB24, 0, 0);
    Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(tmp_surface);
    cr->set_font_size(text_props.get_font_size());
    cr->select_font_face(text_props.get_font(), Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);
    cr->get_text_extents(text, out_text_extents);
    cr->get_font_extents(out_font_extents);
  }

  Cairo::RefPtr<Cairo::ImageSurface>
    surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32,
                                          static_cast<int>(out_text_extents.width  + text_props.get_line_width()),
                                          static_cast<int>(out_text_extents.height + text_props.get_line_width()));

  Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);

  // set the font
  cr->set_font_size(text_props.get_font_size());
  cr->select_font_face(text_props.get_font(), Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);

  if (text_props.get_line_width() != 0)
  {
    // create path
    cr->move_to(-out_text_extents.x_bearing + text_props.get_line_width()/2.0,
                -out_text_extents.y_bearing + text_props.get_line_width()/2.0);
    cr->text_path(text);

    // paint
    cr->set_line_width(text_props.get_line_width());
    cr->set_line_join(Cairo::LINE_JOIN_ROUND);
    cr->set_source_rgb(0.0, 0.0, 0.0);
    cr->stroke();
  }

  // print text
  cr->move_to(-out_text_extents.x_bearing + text_props.get_line_width()/2.0,
              -out_text_extents.y_bearing + text_props.get_line_width()/2.0);
  cr->set_source_rgb(1.0, 1.0, 0.0);

  double y = -out_text_extents.y_bearing - out_font_extents.ascent;

  // toying around with color gradients
  if (false)
  {
    Cairo::RefPtr<Cairo::LinearGradient> gradient = Cairo::LinearGradient::create(0, y,
                                                                                  0, y + out_font_extents.ascent + out_font_extents.descent);
    gradient->add_color_stop_rgb(0.0, 1.0, 1.0, 0.0);
    gradient->add_color_stop_rgb(0.5, 1.0, 1.0, 1.0);
    gradient->add_color_stop_rgb(0.5, 0.4, 0.4, 0.2);
    gradient->add_color_stop_rgb(1.0, 1.0, 1.0, 0.0);
    cr->set_source(gradient);
  }

  cr->show_text(text);

  return surface;
}
Beispiel #28
0
    void NodeSurface::DrawRoundedRectangle( 
        Cairo::RefPtr<Cairo::Context> refCairo, 
        double x, 
        double y, 
        double width, 
        double height, 
        double radius,
        double red,
        double green,
        double blue,
        bool selected )
    {
        refCairo->save();

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

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

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

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

        refCairo->restore();
    }
bool toggle::on_expose_event(GdkEventExpose* event)
{

  // 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() - (allocation.get_height()/3);
    const int height_offset = allocation.get_height()/6;

    // coordinates for the center of the window
    int xc, yc;
    xc = width / 2;
    yc = height / 2;

    Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
    cr->set_line_width(6.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->clip();
    
    // background grad

     Cairo::RefPtr<Cairo::LinearGradient> back_grad =
Cairo::LinearGradient::create( 0,0,0,allocation.get_height() );


	switch (pos_mode)
	{
		case 0:
	        back_grad->add_color_stop_rgba(0,top_colour.get_red_p(),top_colour.get_green_p(),top_colour.get_blue_p(),1);
	        back_grad->add_color_stop_rgba(1,bottom_colour.get_red_p(),bottom_colour.get_green_p(),bottom_colour.get_blue_p(),1);
		break;

		case 1:
	        back_grad->add_color_stop_rgba(0,top_colour.get_red_p(),top_colour.get_green_p(),top_colour.get_blue_p(),1);
	        back_grad->add_color_stop_rgba(1,
			(bottom_colour.get_red_p() + top_colour.get_red_p())/2,
			(bottom_colour.get_green_p() + top_colour.get_green_p())/2,
			(bottom_colour.get_blue_p() + top_colour.get_blue_p())/2,
			1);
		break;

		case 2:
	        back_grad->add_color_stop_rgba(0,
			(bottom_colour.get_red_p() + top_colour.get_red_p())/2,
			(bottom_colour.get_green_p() + top_colour.get_green_p())/2,
			(bottom_colour.get_blue_p() + top_colour.get_blue_p())/2,
			1);
	        back_grad->add_color_stop_rgba(1,bottom_colour.get_red_p(),bottom_colour.get_green_p(),bottom_colour.get_blue_p(),1);
		break;
	}

	// fill background
	if (rounded<5)
	{
		rounded_rectangle(cr,rounded, grad_top_colour,
			grad_bottom_colour, event->area.x, event->area.y,
			event->area.width, event->area.height,pos_mode,
			top_colour.to_string(),bottom_colour.to_string() );
	}
	else 
	{
		cr->rectangle(event->area.x, event->area.y,
			event->area.width, event->area.height);
	}

	cr->set_source(back_grad);
	cr->fill();



    // ------------------------------------------------------------------


    // draw text label
    cr->select_font_face("Bitstream Vera Sans", Cairo::FONT_SLANT_NORMAL,
     Cairo::FONT_WEIGHT_NORMAL);
    cr->set_font_size(width/4.5);
    cr->set_source_rgba(0.9,0.9,0.9,0.8);
    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);
	
    int x_font_centre = (width/2) - ((width/5) * (label.length()/3.5));

    cr->set_font_options(font_options);
    cr->move_to(x_font_centre,height/3.5);
    cr->show_text(label);
    cr->move_to(x_font_centre,allocation.get_height()  - (height_offset/3) );


    cr->set_line_width(width/14);
    cr->set_source_rgba(0.8,0.8,0.8,1.0);

     Cairo::RefPtr<Cairo::LinearGradient> grad2 =
Cairo::LinearGradient::create(width/4, 0,width-(width/4), 0 );
        grad2->add_color_stop_rgba(0.0,0.2,0.2,0.2,1);
        grad2->add_color_stop_rgba(0.4,0.8,0.8,0.8,1);
        grad2->add_color_stop_rgba(1.0,0.4,0.4,0.4,1);

    cr->set_source(grad2);

	Cairo::RefPtr<Cairo::LinearGradient> toggle_grad1;
	Cairo::RefPtr<Cairo::RadialGradient> grad_led;

    stringstream slider_value;
    switch (val)
    {
    	case 0:
		slider_value.str("Off");

		cr->arc((allocation.get_width()/1.9), (allocation.get_height()/1.9), (allocation.get_width()/2.8), 0.0, 2 * M_PI);

		cr->set_source_rgba(0,0,0,0.5);
		cr->fill();
	
		toggle_grad1 = Cairo::LinearGradient::create( (allocation.get_width()/1.9), (allocation.get_height()/1.9),allocation.get_width()/3,allocation.get_height()/3 );
		toggle_grad1->add_color_stop_rgba(0,0.2,0.2,0.2,1);
		toggle_grad1->add_color_stop_rgba(0.5,0.4,0.4,0.4,1);
		toggle_grad1->add_color_stop_rgba(1,0.0,0.0,0.0,1);

		cr->arc((allocation.get_width()/1.9), (allocation.get_height()/1.9), (allocation.get_width()/3), 0.0, 2 * M_PI);

		cr->set_source(toggle_grad1);
		cr->fill();

		cr->arc((allocation.get_width()/1.9), (allocation.get_height()/1.9), (allocation.get_width()/5), 0.0, 2 * M_PI);

		cr->set_source_rgba(0,0,0,0.5);
		cr->fill();

		grad_led = Cairo::RadialGradient::create( (allocation.get_width()/2),
			(allocation.get_height()/2), 0, (allocation.get_width()/2),
			(allocation.get_height()/2) ,(allocation.get_width()/2.5));
	
	        grad_led->add_color_stop_rgba(0,0.0,0.2,0.0,1);
	        grad_led->add_color_stop_rgba(0.3,0.0,0.01,0.0,1);
	        grad_led->add_color_stop_rgba(0.8,0.0,0.01,0.0,1);
	        grad_led->add_color_stop_rgba(1.0,0.0,0.0,0.0,1);

		cr->arc((allocation.get_width()/1.9), (allocation.get_height()/1.9), (allocation.get_width()/6), 0.0, 2 * M_PI);
		cr->set_source(grad_led);
		cr->fill();

		break;
    	case 1:
		slider_value.str("On");

		cr->arc((allocation.get_width()/1.9), (allocation.get_height()/1.9), (allocation.get_width()/2.8), 0.0, 2 * M_PI);

		cr->set_source_rgba(0,0,0,0.5);
		cr->fill();

		toggle_grad1 = Cairo::LinearGradient::create( (allocation.get_width()/1.9), (allocation.get_height()/1.9),allocation.get_width()/3,allocation.get_height()/3 );
		toggle_grad1->add_color_stop_rgba(0,0.2,0.2,0.2,1);
		toggle_grad1->add_color_stop_rgba(0.3,0.4,0.4,0.4,1);
		toggle_grad1->add_color_stop_rgba(1,0.0,0.0,0.0,1);

		cr->arc((allocation.get_width()/1.9), (allocation.get_height()/1.9), (allocation.get_width()/3), 0.0, 2 * M_PI);

		cr->set_source(toggle_grad1);
		cr->fill();

		cr->arc((allocation.get_width()/1.9), (allocation.get_height()/1.9), (allocation.get_width()/5), 0.0, 2 * M_PI);

		cr->set_source_rgba(0,0,0,0.5);
		cr->fill();

		grad_led = Cairo::RadialGradient::create( (allocation.get_width()/1.9),
			(allocation.get_height()/1.9), 0, (allocation.get_width()/2),
			(allocation.get_height()/2) ,(allocation.get_width()/2.5));
	
	        grad_led->add_color_stop_rgba(0,0.0,0.9,0.0,1);
	        grad_led->add_color_stop_rgba(0.3,0.0,0.1,0.0,1);
	        grad_led->add_color_stop_rgba(0.9,0.0,0.10,0.0,1);
	        grad_led->add_color_stop_rgba(1.0,0.0,0.0,0.0,1);

		cr->arc((allocation.get_width()/1.9), (allocation.get_height()/1.9), (allocation.get_width()/6), 0.0, 2 * M_PI);
		cr->set_source(grad_led);
		cr->fill();
		break;
    }

    x_font_centre = (width/2) - ((width/5) * (slider_value.str().length()/3.5));
    cr->move_to(x_font_centre,allocation.get_height() - (height_offset/1.5) );

    cr->set_source_rgba(0.9,0.9,0.9,0.8);
    cr->show_text(slider_value.str());

  }

  return true;
}
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
}