コード例 #1
0
void
Operation::draw_title(const Glib::RefPtr<Gtk::PrintContext>& print)
{
	double pos_x, pos_y;

	Cairo::RefPtr<Cairo::Context> cairo = print->get_cairo_context();

	DICOM::SummaryInfo* info = const_cast<DICOM::SummaryInfo*>(&dicom_info_);
	DICOM::StudyInfo* study = info->get_study_info();

	// Show Institution Name
	cairo->set_font_size(title_font_size_);
	Cairo::TextExtents cur_ext, prev_ext;
	cairo->get_text_extents( study->get_institution_name(), cur_ext);

	pos_x = (width_ - cur_ext.width) / 2.;
	pos_y = cur_ext.height + OFFSET;
	cairo->move_to( pos_x, pos_y);
	cairo->show_text(study->get_institution_name());

	// Show Institution Address
	prev_ext = cur_ext;
	cairo->set_font_size(subtitle_font_size_);
	cairo->get_text_extents( study->get_institution_address(), cur_ext);

	pos_x = -(prev_ext.width + prev_ext.x_bearing +
		cur_ext.width + cur_ext.x_bearing) / 2.;
	pos_y = cur_ext.height + OFFSET;
	cairo->rel_move_to( pos_x, pos_y);
	cairo->show_text(study->get_institution_address());

	// Show Study Description
	prev_ext = cur_ext;
	cairo->set_font_size(title_font_size_);
	cairo->get_text_extents( study->get_description(), cur_ext);

	pos_x = -(prev_ext.width + prev_ext.x_bearing +
		cur_ext.width + cur_ext.x_bearing) / 2.;
	pos_y = cur_ext.height + OFFSET;
	cairo->rel_move_to( pos_x, pos_y);
	cairo->show_text(study->get_description());


	pos_x = -(width_ + cur_ext.width) / 2.;
	pos_y = cur_ext.height + OFFSET;
	cairo->rel_move_to( pos_x, pos_y);

	cairo->stroke_preserve();
}
コード例 #2
0
void
Operation::draw_patient_info(const Glib::RefPtr<Gtk::PrintContext>& print)
{
	Cairo::RefPtr<Cairo::Context> cairo = print->get_cairo_context();

	Glib::RefPtr<Pango::Layout> layout = print->create_pango_layout();

	Pango::FontDescription font_desc("sans 12");
	layout->set_font_description(font_desc);

	layout->set_width(width_ * Pango::SCALE);

	DICOM::SummaryInfo* info = const_cast<DICOM::SummaryInfo*>(&dicom_info_);
	DICOM::PatientInfo* patient = info->get_patient_info();

	//Set and mark up the text to print:
	Glib::ustring marked_up_form_text;
	Glib::ustring txt = DICOM::format_person_name(patient->get_name());
	marked_up_form_text += "<b>Patient's name</b>: " + txt + "\n";
	marked_up_form_text += "<b>Sex</b>: " + info->get_patient_sex() + "\n";

	DICOM::PatientAge age = info->get_patient_age();
	marked_up_form_text += "<b>Age</b>: " + age.age_string() + "\n\n";

	layout->set_markup(marked_up_form_text);
	layout->show_in_cairo_context(cairo);

	int w, h;
	layout->get_pixel_size( w, h);
	cairo->rel_move_to( 0, h);
	cairo->stroke_preserve();
}
コード例 #3
0
ファイル: graphView.cpp プロジェクト: nicklaswj/GTKgraph
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;
}