Ejemplo n.º 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();
}
Ejemplo n.º 2
0
void Format7DrawingArea::DrawDisabledText(Cairo::RefPtr<Cairo::Context> refCairo)
{
    refCairo->save();

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

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

    // Print current cursor position
    char cursorPosition[128];
    sprintf(
        cursorPosition,
        "Custom Image is not supported by this camera.");

    // Get width / height of widget
    int width;
    int height;
    get_window()->get_size( width, height );

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

    refCairo->restore();
}
Ejemplo n.º 3
0
int main(int, char**) {
	Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create(
			Cairo::FORMAT_ARGB32, WIDTH, HEIGHT);
	Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);
	// fill background in white
	cr->set_source_rgb(1.0, 1.0, 1.0);
	cr->paint();

	// draw a little dot at the point where text will be drawn
	cr->arc(TEXT_ORIGIN_X, TEXT_ORIGIN_Y, FONT_SIZE / 4.0, 0, 2 * M_PI);
	cr->set_source_rgba(0.0, 1.0, 0.0, 0.5);
	cr->fill();

	// draw the text
	cr->move_to(TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
	cr->set_source_rgb(0.8, 0.2, 0.2);
	Cairo::RefPtr<Cairo::ToyFontFace> font = Cairo::ToyFontFace::create(
			"Bitstream Charter", Cairo::FONT_SLANT_ITALIC,
			Cairo::FONT_WEIGHT_BOLD);
	cr->set_font_face(font);
	cr->set_font_size(FONT_SIZE);
	cr->show_text("cairomm!");
	surface->write_to_png("toy-text.png");
	return 0;
}
Ejemplo n.º 4
0
void ActivityDrawingArea::drawAxis() {
	// draw a reference axis and pod info
	Glib::RefPtr < Gdk::Window > window = get_window();
	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();

	//draw axis
	cr->save();
	cr->set_line_width(2.0);
	this->setSourceRGB(cr, currentColourScheme.getAxisColour());
	cr->set_font_size(12);

	cr->move_to(0, height / 2);
	cr->line_to(width, height / 2);

	cr->move_to(190, 25 + height / 2);
	cr->show_text("20");
	cr->move_to(390, 25 + height / 2);
	cr->show_text("40");
	cr->move_to(590, 25 + height / 2);
	cr->show_text("60");
	cr->move_to(790, 25 + height / 2);
	cr->show_text("80");

	cr->stroke();
	cr->restore();
}
Ejemplo n.º 5
0
void NodeRenderer::label(const Cairo::RefPtr<Cairo::Context>& cr,
		std::list<shared_ptr<Label> >& labels,
		AssetCache& cache)
{
	// nothing to print
	if (s->text.str().size() == 0 || s->font_size <= 0)
		return;

	cr->save();

	cr->set_font_size(s->font_size);

	cr->set_font_face(cache.getFont(
			s->font_family.str(),
			s->font_style == Style::STYLE_ITALIC ? Cairo::FONT_SLANT_ITALIC : Cairo::FONT_SLANT_NORMAL,
			s->font_weight == Style::WEIGHT_BOLD ? Cairo::FONT_WEIGHT_BOLD : Cairo::FONT_WEIGHT_NORMAL
		));

	Cairo::TextExtents textSize;
	cr->get_text_extents(s->text.str(), textSize);

	addLabel(labels, location + FloatPoint(0.0, s->text_offset), textSize);

	cr->restore();
}
Ejemplo n.º 6
0
    void Format7DrawingArea::DrawImageDimensionsText( 
        Cairo::RefPtr<Cairo::Context> refCairo,
        unsigned int left, unsigned int top, unsigned int width, unsigned int height )
    {        
        refCairo->save();

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

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

        // Get width / height of widget
        int widgetWidth = 0;
        int widgetHeight = 0;
        get_window()->get_size( widgetWidth, widgetHeight );

        // Create text for image offset
        char imageOffsets[128];
        sprintf(
            imageOffsets,
            "Start: (%d,%d) End: (%d,%d)",
            left,
            top,
            left + width,
            top + height );
        Cairo::TextExtents offsetExtents;
        refCairo->get_text_extents(imageOffsets, offsetExtents);

        // Draw the offset text
        refCairo->move_to( 
            (widgetWidth/2) - (offsetExtents.width/2),
            (widgetHeight/2) - offsetExtents.height - (offsetExtents.height/2));
        refCairo->show_text( imageOffsets );

        // Create text for image dimensions
        char imageDimensions[128];
        sprintf(
            imageDimensions,
            "Dimensions: %d x %d",
            width,
            height);
        Cairo::TextExtents dimensionsExtents;
        refCairo->get_text_extents(imageDimensions, dimensionsExtents);

        // Draw the dimensions text
        refCairo->move_to( 
            (widgetWidth/2) - (dimensionsExtents.width/2),
            (widgetHeight/2) + dimensionsExtents.height + (dimensionsExtents.height/2));
        refCairo->show_text( imageDimensions );

        refCairo->restore();
    }
Ejemplo n.º 7
0
void ICLayerLineString::draw(Cairo::RefPtr<Cairo::Context> cr, double scale,
    std::set<int> select, bool DisplayID, double Alpha)
{
  std::map<int, ICLayerObject*>::iterator it;
  for (it = m_ICLayerObject.begin(); it != m_ICLayerObject.end(); it++)
  {
    if ((*it).second->selfIdExisting())
    {
      bool isSelect = false;
      if (!select.empty())
      {
        std::set<int>::iterator it2;
        it2 = select.find((*it).first);
        if (it2 != select.end() && (*it2) == (*it).first)
        {
          drawLine(cr, (*it).second->getOGRGeometryObject(), scale, true);
          isSelect = true;
        } else
          drawLine(cr, (*it).second->getOGRGeometryObject(), scale, false);
      } else
        drawLine(cr, (*it).second->getOGRGeometryObject(), scale, false);
      if (DisplayID)
      {
        Cairo::TextExtents extents;

        std::stringstream str;
        str << (*it).first;
        std::string text = str.str();

        cr->select_font_face("Bitstream Vera Sans, Arial", Cairo::FONT_SLANT_NORMAL,
            Cairo::FONT_WEIGHT_NORMAL);
        cr->set_font_size(12 / scale);

        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->save();

        cr->get_text_extents(text, extents);
        cr->move_to((*it).second->getCentroid().first,
            (*it).second->getCentroid().second);
        cr->scale(1, -1);
        if (isSelect)
          cr->set_source_rgba(0, 0, 0, Alpha);

        cr->show_text(text);
        cr->stroke();
        cr->restore();
      }
    }
  }
}
Ejemplo n.º 8
0
int main(int, char**) {
	Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create(
			Cairo::FORMAT_ARGB32, WIDTH, HEIGHT);
	Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);
	// fill background in white
	cr->set_source_rgb(1.0, 1.0, 1.0);
	cr->paint();

	// draw a little dot at the point where text will be drawn
	cr->arc(TEXT_ORIGIN_X, TEXT_ORIGIN_Y, FONT_SIZE / 4.0, 0, 2 * M_PI);
	cr->set_source_rgba(0.0, 1.0, 0.0, 0.5);
	cr->fill();

	// draw the text
	cr->move_to(TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
	cr->set_source_rgb(0.8, 0.2, 0.2);
	Cairo::RefPtr<BoxFontFace> font = BoxFontFace::create();
	cr->set_font_face(font);
	cr->set_font_size(FONT_SIZE);
	cr->show_text("cairomm!");

	// Now show it with the toy text API to
	// demonstrate how the glyphs match up
	cr->move_to(TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
	cr->set_source_rgba(0.2, 0.2, 0.2, 0.3);
	Cairo::RefPtr<Cairo::ToyFontFace> toy_font = Cairo::ToyFontFace::create(
			"Bitstream Charter", Cairo::FONT_SLANT_NORMAL,
			Cairo::FONT_WEIGHT_BOLD);
	cr->set_font_face(toy_font);
	cr->set_font_size(FONT_SIZE);
	cr->show_text("cairomm!");

	const char* filename = "user-font.png";
	try {
		surface->write_to_png(filename);
		std::cout << "Wrote Image " << filename << std::endl;
		return 0;
	} catch (const std::exception& e) {
		std::cout << "** Unable to write Image " << filename << std::endl;
		return 1;
	}
}
Ejemplo n.º 9
0
void ActivityDrawingArea::drawText() {

	// This is where we draw on the window
	Glib::RefPtr < Gdk::Window > window = get_window();
	Cairo::RefPtr < Cairo::Context > cr = window->create_cairo_context();
	cr->save();
	cr->set_line_width(2.0);
	this->setSourceRGB(cr, currentColourScheme.getAxisColour());
	cr->set_font_size(18);
	cr->move_to(0, 20);

	cr->restore();
}
Ejemplo n.º 10
0
	void renderLabels(Cairo::RefPtr<Cairo::Context> cr, std::vector<std::pair<string, FloatPoint> >& toPlace) {
		cr->save();
		cr->set_source_rgba(0.0, 0.0, 0.0, 0.5);
		Cairo::RefPtr<Cairo::ToyFontFace> font = Cairo::ToyFontFace::create(DEFAULT_FONT, Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);
		cr->set_font_face(font);
		cr->set_font_size(120.0);
		cr->set_line_width(2.0);

		Cairo::TextExtents textSize;
		std::list<shared_ptr<Label> > labels;
		int i = 0;
		std::vector<shared_ptr<Style>> styles;
		for (auto& pair : toPlace)
		{
			string& text = pair.first;
			cr->get_text_extents(text, textSize);
			shared_ptr<Style> s = boost::make_shared<Style>();
			s->text = text;
			styles.push_back(s);
			FloatPoint center = pair.second + FloatPoint(textSize.width/2.0, textSize.height/2.0);
			FloatRect owner = FloatRect(center.x, center.y, center.x, center.y);
			FloatPoint origin = pair.second - FloatPoint(textSize.x_bearing, textSize.y_bearing);
			shared_ptr<Label> l = boost::make_shared<Label>(FloatRect(pair.second, textSize.width, textSize.height), owner, s->text, s.get(), origin);

			cr->rectangle(l->box.minX, l->box.minY, l->box.getWidth(), l->box.getHeight());
			cr->stroke();

			labels.push_back(l);
		}

		std::vector<shared_ptr<Label> > placed;
		placeLabels(labels, placed);

		for (auto& l: placed)
		{
			cr->set_source_rgba(0.0, 0.0, 0.0, 1.0);
			cr->move_to(l->box.minX, l->box.maxY);
			cr->show_text(l->style->text.str());
			cr->fill();

			cr->set_source_rgba(1.0, 0.0, 0.0, 0.5);
			cr->rectangle(l->box.minX, l->box.minY, l->box.getWidth(), l->box.getHeight());
			cr->fill();
		}

		cr->restore();
	}
Ejemplo n.º 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();
    }
}
Ejemplo n.º 12
0
void NodeRenderer::label(const Cairo::RefPtr<Cairo::Context>& cr,
		std::list<shared_ptr<Label> >& labels)
{
	// nothing to print
	if (s->text.str().size() == 0 || s->font_size <= 0)
		return;

	cr->save();

	cr->set_font_size(s->font_size);

	Cairo::TextExtents textSize;
	cr->get_text_extents(s->text.str(), textSize);

	addLabel(labels, location, textSize);

	cr->restore();
}
Ejemplo n.º 13
0
void ConsoleWindow::draw(Cairo::RefPtr<Cairo::Context> ctx)
{
	ctx->save();
	ctx->set_source_rgba(0, 0, 0, 0.8);
	ctx->paint();
	ctx->set_source_rgba(1, 1, 1, 0.3);
	ctx->move_to(0, height - 0.5);
	ctx->line_to(width, height - 0.5);
	ctx->set_line_width(1);
	ctx->stroke();
	ctx->restore();

	ctx->move_to(10, 16);
	ctx->set_source_rgb(1, 1, 1);
	ctx->select_font_face("Menlo", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);
	ctx->set_font_size(13);
	ctx->show_text(input);
}
void NodeActivityDrawingArea::drawText() {
	ActivityDrawingArea::drawText();
	// This is where we draw on the window
	Glib::RefPtr < Gdk::Window > window = get_window();
	Cairo::RefPtr < Cairo::Context > cr = window->create_cairo_context();
	Gtk::Allocation allocation = get_allocation();
	const int width = allocation.get_width();
	cr->save();
	cr->set_line_width(2.0);
	cr->set_source_rgb(1, 1, 1);
	cr->set_font_size(12);

	{
		cr->move_to(width / 5, 20);
		std::stringstream ss;
		ss << "ID";
		if (this->isPrimaryInput == true) {
			ss << " (PIN)";
		}
		if (this->isPrimaryOutput == true) {
			ss << " (POUT)";
		}
		ss<< ": " <<node->getUUIDString();
		cr->show_text(ss.str());
	}

	{
		std::stringstream ss;
		cr->move_to(width / 5, 40);
		int impulse_count = node->getImpulses().getSize();
		int inputs_count = node->getConnector().getInputs().size();
		int outputs_count = node->getConnector().getOutputs().size();
		double threshold = node->getActivityThreshold();

		ss << "Impulses: " << impulse_count;
		ss << " Inputs: " << inputs_count;
		ss << " Outputs: " << outputs_count;
		ss << " Threshold: " << threshold;
		cr->show_text(ss.str());
	}
	cr->restore();
}
Ejemplo n.º 15
0
 void TitleBar( Cairo::RefPtr<Cairo::Context> cr, float x, float y, float xS, float yS, std::string name, bool active)
 {
     
     if ( active )
       setColour(cr, COLOUR_GREEN_1 );
     else
       setColour(cr, COLOUR_GREY_1 );
     
     cr->rectangle(x,y, xS, 15);
     cr->set_line_width(2.8);
     cr->fill();
     
     cr->select_font_face ("Impact" , Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);
     cr->set_font_size ( 13 );
     cr->move_to ( x + 8, y + 13 );
     cr->set_source_rgb( 0 / 255.f, 0/255.f , 0/255.f );
     
     cr->show_text ( name );
     //std::cout << "LupppWidget::TitleBar() called!" << std::endl;
 }
Ejemplo n.º 16
0
void Renderer::renderLabels(const Cairo::RefPtr<Cairo::Context>& cr,
							std::vector<shared_ptr<LabelType> >& labels,
							AssetCache& cache) const
{
	cr->save();

	cr->set_line_join(Cairo::LINE_JOIN_ROUND);

	for (auto it = labels.rbegin(); it != labels.rend(); it++)
	{
		const shared_ptr<LabelType>& label = *it;
		const Style* s = label->style;

		cr->set_font_size(s->font_size);

		cr->move_to(label->origin.x, label->origin.y);

		cr->set_font_face(cache.getFont(
					s->font_family.str(),
					s->font_style == Style::STYLE_ITALIC ? Cairo::FONT_SLANT_ITALIC : Cairo::FONT_SLANT_NORMAL,
					s->font_weight == Style::WEIGHT_BOLD ? Cairo::FONT_WEIGHT_BOLD : Cairo::FONT_WEIGHT_NORMAL
				));

		cr->text_path(label->text.str());

		if (s->text_halo_radius > 0.0)
		{
			cr->set_source_color(s->text_halo_color);
			cr->set_line_width(s->text_halo_radius*2.0);
			cr->stroke_preserve();
		}

		cr->set_source_color(s->text_color);
		cr->fill();
	}

	cr->restore();
}
Ejemplo n.º 17
0
//! Debug function that prints identifier on the tile
void Renderer::printTileId(const Cairo::RefPtr<Cairo::Context>& cr,
						   const shared_ptr<TileIdentifier>& id) const
{
	cr->save();

	cr->set_font_size(10);
	cr->move_to(5.0, TILE_SIZE - 10);

	std::ostringstream labelstrm;
	labelstrm << "X: " << id->getX() << " Y: " << id->getY();
	labelstrm << " Zoom: " << id->getZoom();
	labelstrm << " Style: " << id->getStylesheetPath();
	std::string label = labelstrm.str();
	cr->text_path(label.c_str());

	cr->set_source_rgba(1.0, 1.0, 1.0, 1.0);
	cr->set_line_width(2.0);
	cr->stroke_preserve();
	cr->set_source_rgba(0.0, 0.0, 0.0, 1.0);
	cr->fill();

	cr->restore();
}
void ConnectionActivityDrawingArea::drawText() {
	ActivityDrawingArea::drawText();
	// This is where we draw on the window
	Glib::RefPtr < Gdk::Window > window = get_window();
	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();
	cr->save();
	cr->set_line_width(2.0);
	cr->set_source_rgb(1, 1, 1);
	cr->set_font_size(12);

	{
		cr->move_to(width / 5, 20);
		std::stringstream ss;
		ss << "ID";
		if (this->isPrimaryInput == true) {
			ss << " (PIN)";
		}
		if (this->isPrimaryOutput == true) {
			ss << " (POUT)";
		}
		ss << ": " << connection->getUUIDString();
		cr->show_text(ss.str());
	}

	{
		std::stringstream ss;
		cr->move_to(width / 5, 40);
		ss << "Impulses: " << connection->getImpulses().getSize();
		//    	<<" compression: "<<fibril->getMutator().getCompression()
		//  	<<" delay: " <<fibril->getMutator().getDelay();
		cr->show_text(ss.str());
	}
	cr->restore();
}
void ConnectionActivityDrawingArea::drawAxis() {

	// draw a reference axis and pod info
	Glib::RefPtr < Gdk::Window > window = get_window();
	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();

	double max_delay = connection->getActivityTimer()->getStartingDelay();

	//draw axis
	cr->save();
	cr->set_line_width(2.0);
	this->setSourceRGB(cr, currentColourScheme.getAxisColour());
	cr->set_font_size(12);

	cr->move_to(0, height / 2);
	cr->line_to(width, height / 2);

	{
		std::stringstream ss_temp;
		ss_temp << max_delay / 2;
		cr->move_to(-40 + width / 2, 25 + height / 2);
		cr->show_text(ss_temp.str());
	}
	{
		std::stringstream ss_temp;
		ss_temp << max_delay;
		cr->move_to(width - 40, 25 + height / 2);
		cr->show_text(ss_temp.str());
	}

	cr->stroke();
	cr->restore();
}
Ejemplo n.º 20
0
bool GMasterReturn::on_expose_event(GdkEventExpose* event)
{
  // This is where we draw on the window
  Glib::RefPtr<Gdk::Window> window = get_window();
  
  if(window)    // Only run if Window does exist
  {
    // clip to the area indicated by the expose event so that we only redraw
    // the portion of the window that needs to be redrawn
    Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
    cr->rectangle(event->area.x, event->area.y,
            event->area.width, event->area.height);
    cr->clip();
    
    cr->rectangle(event->area.x, event->area.y,
        event->area.width, event->area.height);
    cr->set_source_rgb(0.1 , 0.1 , 0.1 );
    cr->fill();
    
    
    Dial(cr, true, 35 , 0, value, DIAL_MODE_SEND ); // fader
    
    // Dial text "A"
    cr->select_font_face ("Impact" , Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_BOLD);
    cr->set_font_size ( 20 );
    cr->move_to ( 10, 28);
    switch ( ID )
    {
      case 0: setColour(cr, COLOUR_BLUE_1 ); cr->show_text ( "A" ); break;
      case 1: setColour(cr, COLOUR_BLUE_1 ); cr->show_text ( "B" ); break;
      case 2: setColour(cr, COLOUR_BLUE_1 ); cr->show_text ( "C" ); break;
    }
    
  }
  return true;
}
Ejemplo n.º 21
0
    void Format7DrawingArea::DrawCurrentCursorPositionText( 
        Cairo::RefPtr<Cairo::Context> refCairo,
        unsigned int currX, unsigned int currY )
    {
        refCairo->save();

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

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

        // Print current cursor position
        char cursorPosition[128];
        sprintf( 
            cursorPosition,
            "Cursor: (%d, %d)",
            currX,
            currY );

        // Get width / height of widget
        int width;
        int height;
        get_window()->get_size( width, height );

        Cairo::TextExtents textExtents;
        refCairo->get_text_extents( cursorPosition, textExtents );
        refCairo->move_to( (width / 2) - (textExtents.width / 2), (height * 0.9) - (textExtents.height / 2) );
        refCairo->show_text( cursorPosition );

        refCairo->restore();
    }
Ejemplo n.º 22
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();

}
Ejemplo n.º 23
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
}
Ejemplo n.º 24
0
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);
			}
		}

	}
}
Ejemplo n.º 25
0
void HistogramDrawingArea::DrawHistogramGridLabels( Cairo::RefPtr<Cairo::Context> refCairo )
{
    // Reserve the outside 10%
    float paddedLeft, paddedTop, paddedWidth, paddedHeight;
    GetPaddedSize( paddedLeft, paddedTop, paddedWidth, paddedHeight );   

    refCairo->save();

    // Set draw color
    refCairo->set_source_rgb(0, 0, 0);

    // Set the font parameters
    refCairo->select_font_face( 
        "monospace",
        Cairo::FONT_SLANT_NORMAL, 
        Cairo::FONT_WEIGHT_BOLD );
    refCairo->set_font_size( 10 );
    
    const int k_numPartitions = 8;      

    // Render the x-axis labels
    for ( int i=0; i <= k_numPartitions; i++ )
    {
        const float fraction = i / static_cast<float>(k_numPartitions);

        unsigned int maxNumPixelValues = 0;

        for ( int j=0; j < ImageStatistics::NUM_STATISTICS_CHANNELS; j++ )
        {
            unsigned int numPixelValues = 0;

            m_histogramStats.GetNumPixelValues( 
                static_cast<ImageStatistics::StatisticsChannel>(j),
                &numPixelValues );

            maxNumPixelValues = std::max( numPixelValues, maxNumPixelValues );
        }

        char caption[32];
        float pixelValue;
        if ( maxNumPixelValues == 0 )
        {
            pixelValue = 256 * fraction;
        }
        else
        {
            pixelValue = maxNumPixelValues * fraction;                      
        }
        
        sprintf(
            caption,
            "%.0f",
            pixelValue );

        const float xOffset = paddedLeft + (paddedWidth * fraction);
        const float yOffset = paddedTop + paddedHeight + (paddedTop/2); //height - paddedTop;

        Cairo::TextExtents textExtents;
        refCairo->get_text_extents( caption, textExtents );
        refCairo->move_to( 
            xOffset - (textExtents.width / 2), 
            yOffset + (textExtents.height / 2) );
        refCairo->show_text( caption );
    }

    // Render the y-axis labels
    for ( int i=1; i < k_numPartitions; i++ )
    {
        if ( i % 2 != 0 )
        {
            continue;
        }

        const float fraction = i / static_cast<float>(k_numPartitions);       
        float scaleRatio = 100 / static_cast<float>(m_maxVal);       
        float yOffset = paddedTop + paddedHeight - (paddedHeight * fraction * scaleRatio);

        char caption[32];
        sprintf(
            caption,
            "%u%%",
            (i*100)/k_numPartitions );

        if ( yOffset > paddedTop )
        {
            Cairo::TextExtents textExtents;
            refCairo->get_text_extents( caption, textExtents );

            refCairo->move_to( 
                (paddedLeft / 2) - (textExtents.width / 2), 
                yOffset + (textExtents.height / 2) );
            refCairo->show_text( caption );
        }          
    }

    refCairo->restore();
}
Ejemplo n.º 26
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 2.0 Bus" );
                    break;
                case INTERFACE_USB3:
                    sprintf( idCaption, "USB 3.0 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:
			PGRGuid blankGuid;
			if(pNode->GetGuid() == blankGuid)
				sprintf( idCaption, "Node" );
			else
				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();
    }
Ejemplo n.º 27
0
/** Draw person legs.
 * Draws the legs of persons
 * @param window Gdk window
 * @param cr Cairo context to draw to. It is assumed that possible transformations
 * have been setup before.
 */
void
LaserDrawingArea::draw_persons_legs(Glib::RefPtr<Gdk::Window> &window,
				    const Cairo::RefPtr<Cairo::Context> &cr)
{
  std::list<ObjectPositionInterface*>::iterator objpos_if_itt;;

  cr->save();
  if (__l_objpos_if_persons) {
    cr->set_source_rgb(0,0,1);
    for( objpos_if_itt = __l_objpos_if_persons->begin(); 
	 objpos_if_itt != __l_objpos_if_persons->end()  && (*objpos_if_itt)->has_writer();
	 objpos_if_itt++ ) {
      if(!__break_drawing)
	(*objpos_if_itt)->read();
      if ((*objpos_if_itt)->is_valid()){
	std::pair<float,float> pos = transform_coords_from_fawkes((*objpos_if_itt)->relative_x(), (*objpos_if_itt)->relative_y());
	float x=pos.first;
	float y=pos.second;
	cr->move_to(x, y);
	//      cr->arc(x, y, std::max((*objpos_if_itt)->extent_x(),(*objpos_if_itt)->extent_y()), 0, 2*M_PI);
	cr->arc(x, y, 0.2, 0, 2*M_PI);
      }
    }
    cr->stroke();
  }

  if (__l_objpos_if_legs) {
    cr->set_source_rgb(0,1,0);
    for( objpos_if_itt = __l_objpos_if_legs->begin(); 
	 objpos_if_itt != __l_objpos_if_legs->end() && (*objpos_if_itt)->has_writer() ; 
	 objpos_if_itt++ ) {
      if(!__break_drawing)
	(*objpos_if_itt)->read();
      if ((*objpos_if_itt)->is_valid()){
	std::pair<float,float> pos = transform_coords_from_fawkes((*objpos_if_itt)->relative_x(), (*objpos_if_itt)->relative_y());
	float x=pos.first;
	float y=pos.second;
	cr->move_to(x, y);
	cr->arc(x, y, 0.1, 0, 2*M_PI);
      }
    }
    cr->stroke();
  }
  
  if (__l_objpos_if_misc) {
    cr->set_source_rgb(0,1,1);
    for( objpos_if_itt = __l_objpos_if_misc->begin(); 
	 objpos_if_itt != __l_objpos_if_misc->end() && (*objpos_if_itt)->has_writer() ; 
	 objpos_if_itt++ ) {
      if(!__break_drawing)
	(*objpos_if_itt)->read();
      if ((*objpos_if_itt)->is_valid()){
	//      switch( (*objpos_if_itt)->object_type() ){
	//      case ObjectPositionInterface::TYPE_BALL:
	//TYPE_OPPONENT
	if((*objpos_if_itt)->object_type()==ObjectPositionInterface::TYPE_BALL){
	  std::pair<float,float> pos = transform_coords_from_fawkes((*objpos_if_itt)->relative_x(), (*objpos_if_itt)->relative_y());
	  float x=pos.first;
	  float y=pos.second;
	  pos = transform_coords_from_fawkes((*objpos_if_itt)->world_x(), (*objpos_if_itt)->world_y());
	  float begin_x=pos.first;
	  float begin_y=pos.second;
	  pos = transform_coords_from_fawkes((*objpos_if_itt)->world_x_velocity(), (*objpos_if_itt)->world_y_velocity());
	  float end_x= pos.first;
	  float end_y= pos.first;
	  float angle1=atan2(begin_y- y, begin_x - x);
	  float angle2=atan2(end_y- y, end_x - x);
	  float radius=(*objpos_if_itt)->relative_x_velocity();
	  float probability = (*objpos_if_itt)->relative_z_velocity();
	  cr->move_to(begin_x, begin_y);
	  cr->arc(x, y, radius, angle2, angle1);

	  //	Cairo::TextExtents te;
	  std::string t = StringConversions::to_string(probability);
	  t.erase(5);
	  //	  cr->set_source_rgb(0,1 ,1);
	  cr->set_font_size(0.08);
	  //	cr->get_text_extents(t, te);
	  //	cr->move_to(- te.width / 2, -te.height / 2);
	  cr->move_to(begin_x, begin_y);
	  cr->show_text(t);
	  //	  cr->set_source_rgb(0,0,1);
	
	  //	break;
	  //      case ObjectPositionInterface::TYPE_LINE:
	}else if((*objpos_if_itt)->object_type()==ObjectPositionInterface::TYPE_LINE){
	  std::pair<float,float> pos = transform_coords_from_fawkes((*objpos_if_itt)->world_x(), (*objpos_if_itt)->world_y());
	  float begin_x=pos.first;
	  float begin_y=pos.second;
	  pos = transform_coords_from_fawkes((*objpos_if_itt)->world_x_velocity(), (*objpos_if_itt)->world_y_velocity());
	  float end_x= pos.first;
	  float end_y= pos.first;
	  cr->move_to(begin_x, begin_y);
	  cr->line_to(end_x, end_y);
	  //break;
	}
      }
    }
    //  cr->fill_preserve();
    cr->stroke();
  }

  cr->set_source_rgb(1,0,1);

  float r,g,b;
  r=g=b=0.0;
  int color_it=0;
  float delta = 0.25;


  if (__l_track_if) {

    std::list<Position2DTrackInterface*>::iterator track_if_itt;;  
    const float radius (0.1);
    float* x_positions1;
    float* y_positions1;
    int* timestamps1;
    float* x_positions2 = NULL;
    float* y_positions2 = NULL;
    unsigned int track_length1 = 0;
    unsigned int track_length2 = 0;
    int* timestamps2 = NULL;
    unsigned int id;
    cr->set_font_size(0.03);
#ifdef LASERGUI_DEBUG_PRINT_TRACKS
    printf("\n\n################################\n");
#endif
    for( track_if_itt = __l_track_if->begin(); 
	 track_if_itt != __l_track_if->end() && (*track_if_itt)->has_writer();) {
      bool b_compound_track(false);
      if(!__break_drawing)
	(*track_if_itt)->read();
      if ((*track_if_itt)->is_valid()){
	x_positions1=(*track_if_itt)->track_x_positions();
	y_positions1=(*track_if_itt)->track_y_positions();
	timestamps1=(*track_if_itt)->track_timestamps();
	track_length1 = (*track_if_itt)->length();
	id = (*track_if_itt)->track_id();
	++track_if_itt;
	if( track_if_itt != __l_track_if->end() && (*track_if_itt)->has_writer()){
	  if(!__break_drawing)
	    (*track_if_itt)->read();
	  if( (*track_if_itt)->is_valid() && (*track_if_itt)->track_id()==id ){
	    b_compound_track = true;
	    x_positions2=(*track_if_itt)->track_x_positions();
	    y_positions2=(*track_if_itt)->track_y_positions();
	    timestamps2=(*track_if_itt)->track_timestamps();
	    track_length2 = (*track_if_itt)->length();
	    ++track_if_itt;
	  }
	}
#ifdef LASERGUI_DEBUG_PRINT_TRACKS
	printf("\n    trackid %d\n", id);
#endif
	unsigned int i(0);
	unsigned int j(0);
	float x = x_positions1[i];
	float y = y_positions1[i];
	if(b_compound_track){
	  while(j+1 < track_length2 && timestamps2[j] < timestamps1[i]){
	    ++j;
	  }
	  if(timestamps2[j] == timestamps1[i]){
	    x += x_positions2[i];
	    x /= 2;
	    y += y_positions2[i];
	    y /=2;
	  }
	}
	std::pair<float,float> pos = transform_coords_from_fawkes(x,y);
	cr->move_to(pos.first,pos.second);
	for (; i < track_length1; ++i){
	  x = x_positions1[i];
	  y = y_positions1[i];
	  if(b_compound_track){
	    while(j+1 < track_length2 && timestamps2[j] < timestamps1[i]){
	      ++j;
	    }
	    if(timestamps2[j] == timestamps1[i]){
	      x += x_positions2[i];
	      x /= 2;
	      y += y_positions2[i];
	      y /=2;
	    }
	  }
	  std::pair<float,float> pos = transform_coords_from_fawkes(x,y);
	  //cr->move_to(pos.first - radius, pos.second);
	  //	  cr->arc(pos.first, pos.second, radius, 0, 2*M_PI);
	  cr->line_to(pos.first, pos.second);
	  //	cr->rectangle(x_positions[i], y_positions[i], 4 / __zoom_factor, 4 / __zoom_factor);
	
	  //	std::string t = StringConversions::toString(id) + "-" + StringConversions::toString(timestamps[i]);
	  std::string t = StringConversions::to_string(timestamps1[i]);
	  //      cr->move_to(begin_x, begin_y);
	  cr->show_text(t);
	  cr->move_to(pos.first, pos.second);
#ifdef LASERGUI_DEBUG_PRINT_TRACKS
	  printf("( %f,%f,[%d] )", pos.first, pos.second, timestamps1[i] );
#endif
	}

	// chose color    
	if (div(color_it,3).rem == 0) r+= delta;
	if (div(color_it,3).rem == 1) g+= delta;
	if (div(color_it,3).rem == 2) b+= delta;
	cr->set_source_rgb(r,g,b);
	color_it++;

	cr->stroke();
	
	
	i = std::max(0, (int) track_length1 - CFG_PRINT_NR_TRACKELEMENTS);
	j = 0;
	for (; i < track_length1; ++i){
	  x = x_positions1[i];
	  y = y_positions1[i];
	  if(b_compound_track){
	    while(j+1 < track_length2 && timestamps2[j] < timestamps1[i]){
	      ++j;
	    }
	  }
	  
	  std::pair<float,float> pos = transform_coords_from_fawkes(x_positions1[i],y_positions1[i]);
	  cr->move_to(pos.first - radius, pos.second);
	  cr->arc(pos.first, pos.second, radius, 0, 2*M_PI);
	  
	  if(b_compound_track && timestamps2[j] == timestamps1[i]){
	    cr->move_to(pos.first, pos.second);
	    
	    std::pair<float,float> pos = transform_coords_from_fawkes(x_positions2[j],y_positions2[j]);
	    cr->line_to(pos.first, pos.second);
	    cr->move_to(pos.first - radius, pos.second);
	    cr->arc(pos.first, pos.second, radius, 0, 2*M_PI);
	  }
	}
	cr->set_source_rgb(0,0,1);
	cr->stroke();
	
      }
      else{
	break;
      }
    }
  }
  
  /*  DRAW TARGET */
  if(__target_if && __target_if->has_writer()){
    __target_if->read();
    if(__target_if->is_valid()){
      cr->set_source_rgb(1,0,0);
      std::pair<float,float> pos = transform_coords_from_fawkes(__target_if->relative_x(), __target_if->relative_y());
      float x=pos.first;
      float y=pos.second;
      float radius = 0.1;

      cr->move_to(x, y);
      cr->arc(x, y, radius, 0, 2*M_PI);
      cr->move_to(x - radius, y);
      cr->line_to(x + radius, y);
      cr->move_to(x, y - radius );
      cr->line_to(x, y + radius);
      cr->stroke();
    }
  }


  /*
  float r,g,b;
  r=g=b=0.0;
  float delta = 0.2;
  for (int i = 0; i< 15 ; i++){
    
    if (div(i,3).rem == 0) r+= delta;
    if (div(i,3).rem == 1) g+= delta;
    if (div(i,3).rem == 2) b+= delta;
    //    printf("i %d rem %d| r %f, g %f, b %f\n", i, div(i,3).rem,r,g,b);
    cr->move_to(0, (i+1)*0.125);
    cr->set_source_rgb(r,g,b);
    cr->rectangle(0, (i+1)*0.125, 0.1 , 0.1 );
    cr->fill_preserve();
    cr->stroke();
  }
  */
  //  cr->stroke();

  cr->restore();
}
Ejemplo n.º 28
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;
}
Ejemplo n.º 29
0
bool CalibrationArea::on_expose_event(GdkEventExpose *event)
{
    // check that screensize did not change
    if (display_width != get_width() ||
         display_height != get_height()) {
        set_display_size(get_width(), get_height());
    }

    Glib::RefPtr<Gdk::Window> window = get_window();
    if (window) {
        Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
        cr->save();

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

        // Print the text
        cr->set_font_size(font_size);
        double text_height = -1;
        double text_width = -1;
        Cairo::TextExtents extent;
        for (int i = 0; i != help_lines; i++) {
            cr->get_text_extents(help_text[i], extent);
            text_width = std::max(text_width, extent.width);
            text_height = std::max(text_height, extent.height);
        }
        text_height += 2;

        double x = (display_width - text_width) / 2;
        double y = (display_height - text_height) / 2 - 60;
        cr->set_line_width(2);
        cr->rectangle(x - 10, y - (help_lines*text_height) - 10,
                text_width + 20, (help_lines*text_height) + 20);

        // Print help lines
        y -= 3;
        for (int i = help_lines-1; i != -1; i--) {
            cr->get_text_extents(help_text[i], extent);
            cr->move_to(x + (text_width-extent.width)/2, y);
            cr->show_text(help_text[i]);
            y -= text_height;
        }
        cr->stroke();

        // Draw the points
        for (int i = 0; i <= calibrator->get_numclicks(); i++) {
            // set color: already clicked or not
            if (i < calibrator->get_numclicks())
                cr->set_source_rgb(1.0, 1.0, 1.0);
            else
                cr->set_source_rgb(0.8, 0.0, 0.0);

            cr->set_line_width(1);
            cr->move_to(X[i] - cross_lines, Y[i]);
            cr->rel_line_to(cross_lines*2, 0);
            cr->move_to(X[i], Y[i] - cross_lines);
            cr->rel_line_to(0, cross_lines*2);
            cr->stroke();

            cr->arc(X[i], Y[i], cross_circle, 0.0, 2.0 * M_PI);
            cr->stroke();
        }

        // Draw the clock background
        cr->arc(display_width/2, display_height/2, clock_radius/2, 0.0, 2.0 * M_PI);
        cr->set_source_rgb(0.5, 0.5, 0.5);
        cr->fill_preserve();
        cr->stroke();

        cr->set_line_width(clock_line_width);
        cr->arc(display_width/2, display_height/2, (clock_radius - clock_line_width)/2,
             3/2.0*M_PI, (3/2.0*M_PI) + ((double)time_elapsed/(double)max_time) * 2*M_PI);
        cr->set_source_rgb(0.0, 0.0, 0.0);
        cr->stroke();


        // Draw the message (if any)
        if (message != NULL) {
            // Frame the message
            cr->set_font_size(font_size);
            Cairo::TextExtents extent;
            cr->get_text_extents(this->message, extent);
            text_width = extent.width;
            text_height = extent.height;

            x = (display_width - text_width) / 2;
            y = (display_height - text_height + clock_radius) / 2 + 60;
            cr->set_line_width(2);
            cr->rectangle(x - 10, y - text_height - 10,
                    text_width + 20, text_height + 25);

            // Print the message
            cr->move_to(x, y);
            cr->show_text(this->message);
            cr->stroke();
        }

        cr->restore();
    }

    return true;
}
Ejemplo n.º 30
0
void HistogramDrawingArea::DrawRowColGridLabels( 
    Cairo::RefPtr<Cairo::Context> refCairo, 
    unsigned int numPixelValues, 
    unsigned int numValues )
{
    // Reserve the outside 10%
    float paddedLeft, paddedTop, paddedWidth, paddedHeight;
    GetPaddedSize( paddedLeft, paddedTop, paddedWidth, paddedHeight );   

    refCairo->save();

    // Set draw color
    refCairo->set_source_rgb(0, 0, 0);

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

    const int k_numPartitions = 8;      
    for ( int i=0; i <= k_numPartitions; i++ )
    {
        const float fraction = i / static_cast<float>(k_numPartitions);

        char caption[32];
        float dimensionValue = numValues * fraction;

        sprintf(
            caption,
            "%.0f",
            dimensionValue );

        const float xOffset = paddedLeft + (paddedWidth * fraction);
        const float yOffset = paddedTop + paddedHeight + (paddedTop/2);

        Cairo::TextExtents textExtents;
        refCairo->get_text_extents( caption, textExtents );
        refCairo->move_to( 
            xOffset - (textExtents.width / 2), 
            yOffset + (textExtents.height / 2) );
        refCairo->show_text( caption );
    }

    for ( int i=1; i <= k_numPartitions; i++ )
    {
        const float fraction = i / static_cast<float>(k_numPartitions);

        char caption[32];
        float pixelValue = numPixelValues * fraction;

        sprintf(
            caption,
            "%.0f",
            pixelValue );

        float yOffset = paddedTop + paddedHeight - (paddedHeight * fraction);

        Cairo::TextExtents textExtents;
        refCairo->get_text_extents( caption, textExtents );
        refCairo->move_to( 
            (paddedLeft/2) - (textExtents.width / 2), 
            yOffset + (textExtents.height / 2) );
        refCairo->show_text( caption );                   
    }

    refCairo->restore();
}