예제 #1
0
void List::draw_label_helper(const Cairo::RefPtr<Cairo::Context> & cr, ListNode * label, const char * text, int x, int y, LabelArrowPos arrowPos) {
	cr->set_source_rgb(0.0, 0.0, 0.0);
	Pango::FontDescription font;
	font.set_family("Monospace");
	font.set_weight(Pango::WEIGHT_BOLD);
	Glib::RefPtr<Pango::Layout> layout = create_pango_layout(text);
	layout->set_font_description(font);
	int text_w, text_h;
	layout->get_pixel_size(text_w, text_h);
	cr->move_to(x, y);
	layout->show_in_cairo_context(cr);
	if (label != NULL) {
		if (arrowPos == RIGHT) {
		draw_arrow_helper(cr, x + text_w + 10, y + text_h / 2, label->x - 10, label->y + ListNode::field_h);
		} else {
		draw_arrow_helper(cr, x - 10, y + text_h / 2, label->x + ListNode::field_w + 10, label->y + ListNode::field_h);
		}
	} else {
		if (arrowPos == RIGHT) {
			draw_null_arrow(cr, x + text_w + 10, y + text_h / 2, true);
		} else {
			draw_null_arrow(cr, x - 10, y + text_h / 2, false);
		}
	}
}
예제 #2
0
void ListNode::draw_text(const Cairo::RefPtr<Cairo::Context> & cr, int x, int y) {
	char * str = new char[10];
	sprintf(str, "%d", data);

	Pango::FontDescription font;
	font.set_family("Monospace");
	font.set_weight(Pango::WEIGHT_BOLD);
	Glib::RefPtr<Pango::Layout> layout = create_pango_layout(str);
	layout->set_font_description(font);
	int text_w, text_h;
	layout->get_pixel_size(text_w, text_h);
	cr->move_to(x + (field_w - text_w) / 2, y + (field_h - text_h) / 2);
	layout->show_in_cairo_context(cr);
}
예제 #3
0
bool GraficoDeTorta::dibujar(const Cairo::RefPtr<Cairo::Context>& contexto){
	Gdk::Rectangle rect = dibujo->get_allocation();
	Pango::FontDescription font;
	font.set_family("Monospace");
	font.set_weight(Pango::WEIGHT_BOLD);

	if(stock.size() == 0) return false;
	contexto->set_source_rgb(1.0,1.0,1.0);
	contexto->paint();	
	
	int total = 0;
	for(unsigned int i = 0; i < stock.size(); i++){
		total +=  stock[i].second;
	}
	float step = 2*M_PI/total;
	total = 0;
	

	float angulo0=0;
	for(unsigned int i = 0; i < stock.size(); i++){
		float angulo1 = step*stock[i].second + angulo0;
		dibujarArco(contexto,rect.get_width()/2-rect.get_width()/4,rect.get_height()/2,rect.get_width()<rect.get_height()?rect.get_width()/4:rect.get_height()/4,angulo0,angulo1,red[i],green[i],blue[i]);
		angulo0 = angulo1;
	}
	
	Glib::RefPtr<Pango::Layout> layout;
	std::stringstream s;
	for(unsigned int i = 0; i < stock.size(); i++){
		s.str("");
		s << stock[i].first << "\t" << stock[i].second;
		layout = dibujo->create_pango_layout(s.str());
		layout -> set_font_description(font);
		int t_width, t_height;
		layout->get_pixel_size(t_width,t_height);
		contexto->set_source_rgb(0,0,0);	
		contexto -> move_to((rect.get_width())/2,15*(i+1)+5);
		layout -> show_in_cairo_context(contexto);
		contexto -> set_source_rgb(red[i],green[i],blue[i]);
		contexto -> rectangle(rect.get_width()/2+80,15*(i+1)+5,30,15);
		contexto -> fill();
	}
	return true;
}