Exemplo n.º 1
0
bool MouseAwareTreeView::queueDrawIfNeccesary(int32_t x, int32_t y, Glib::ustring* pPath)
{
    Gtk::TreeModel::Path mousePath;
    Gtk::TreeViewColumn* pColumn;
    Gdk::Rectangle rect;

    convert_bin_window_to_widget_coords (x, y, m_MouseInfo.x, m_MouseInfo.y);

    if (get_path_at_pos(x, y, mousePath, pColumn, x, y))
    {
        int32_t offsetX, offsetY;
        convert_bin_window_to_widget_coords(0, 0, offsetX, offsetY);

        m_MouseInfo.x -= offsetX;
        m_MouseInfo.y -= offsetY;

        get_cell_area(mousePath, *pColumn, rect);
        queue_draw_area(rect.get_x() + offsetX, rect.get_y() + offsetY, rect.get_width(), rect.get_height());
        if (rect.get_y() != m_CurrentCell)
        {
            m_CurrentCell = rect.get_y();
            m_CellChanged = true;
        }

        if (pPath)
        {
            *pPath = mousePath.to_string();
        }
        return true;
    }

    return false;
}
Exemplo n.º 2
0
void GazeTracker::boundToScreenCoordinates(Point &estimate) {
	int numMonitors = Gdk::Screen::get_default()->get_n_monitors();
	Gdk::Rectangle monitorGeometry;
	Glib::RefPtr<Gdk::Screen> screen = Gdk::Display::get_default()->get_default_screen();

	// Geometry of main monitor
	screen->get_monitor_geometry(numMonitors - 1, monitorGeometry);

	// If x or y coordinates are outside screen boundaries, correct them
	if (estimate.x < monitorGeometry.get_x()) {
		estimate.x = monitorGeometry.get_x();
	}

	if (estimate.y < monitorGeometry.get_y()) {
		estimate.y = monitorGeometry.get_y();
	}

	if (estimate.x >= monitorGeometry.get_x() + monitorGeometry.get_width()) {
		estimate.x = monitorGeometry.get_x() + monitorGeometry.get_width();
	}

	if (estimate.y >= monitorGeometry.get_y() + monitorGeometry.get_height()) {
		estimate.y = monitorGeometry.get_y() + monitorGeometry.get_height();
	}
}
Exemplo n.º 3
0
bool LinkHints::getObjectAtPos(gdouble x, gdouble y, ObjectType *obj) {
	for(iterator h = begin(); h != end(); h++) {
		Gdk::Rectangle r = (*h)->drawRect();
		if(x >= r.get_x() && y >= r.get_y() && x <= r.get_x() + r.get_width() && y <= r.get_y() + r.get_height()) {
			*obj = ObjectType(*h);
			return true;
		}
	}
	return false;
}
Exemplo n.º 4
0
  bool BugzillaNoteAddin::insert_bug(int x, int y, const std::string & uri, int id)
  {
    try {
      BugzillaLink::Ptr link_tag = 
        BugzillaLink::Ptr::cast_dynamic(get_note()->get_tag_table()->create_dynamic_tag(TAG_NAME));
      link_tag->set_bug_url(uri);

      // Place the cursor in the position where the uri was
      // dropped, adjusting x,y by the TextView's VisibleRect.
      Gdk::Rectangle rect;
      get_window()->editor()->get_visible_rect(rect);
      x = x + rect.get_x();
      y = y + rect.get_y();
      Gtk::TextIter cursor;
      gnote::NoteBuffer::Ptr buffer = get_buffer();
      get_window()->editor()->get_iter_at_location(cursor, x, y);
      buffer->place_cursor (cursor);

      std::string string_id = boost::lexical_cast<std::string>(id);
      buffer->undoer().add_undo_action (new InsertBugAction (cursor, 
                                                             string_id, 
                                                             link_tag));

      std::vector<Glib::RefPtr<Gtk::TextTag> > tags;
      tags.push_back(link_tag);
      buffer->insert_with_tags (cursor, 
                                string_id, 
                                tags);
      return true;
    } 
    catch (...)
    {
		}
    return false;
  }
Exemplo n.º 5
0
void ItemView::drawButton(const Cairo::RefPtr<Cairo::Context>& cr, Gtk::Image* image, Gdk::Rectangle rect)
{
    const Glib::RefPtr<Gdk::Pixbuf> icon = image->get_pixbuf();

    const int iconLeft = rect.get_x() + (rect.get_width() * 0.5) - (icon->get_width() * 0.5);
    const int iconTop = rect.get_y() + (rect.get_height() * 0.5) - (icon->get_height() * 0.5);

    Gdk::Cairo::set_source_pixbuf(cr, icon, iconLeft, iconTop);
    cr->rectangle(iconLeft, iconTop, icon->get_width(), icon->get_height());
    cr->fill();
}
Exemplo n.º 6
0
bool ItemView::isHit(GdkEventButton* event, Gdk::Rectangle& rect)
{
    const int left = rect.get_x();
    const int top = rect.get_y();
    const int right = left + rect.get_width();
    const int bottom = top + rect.get_height();

    if (event->x > left && event->x < right)
        if (event->y > top && event->y < bottom)
            return true;

    return false;}
Exemplo n.º 7
0
void sourceview___::scroll2__(SourceView*sv,Gtk::TextIter ti){
	RefPtr<Gtk::TextBuffer> tb=sv->get_buffer();
	tb->place_cursor(ti);
	Gtk::TextBuffer::iterator i1,i2;
	tb->get_selection_bounds(i1,i2);

	Gdk::Rectangle rect;
	sv->get_visible_rect(rect);
	int y = -1;
	int height = -1;
	sv->get_line_yrange(i1, y, height);
	if (y < rect.get_y() + rect.get_height() + 16)
		 sv->scroll_to_mark(tb->get_insert(), 0);
}
Exemplo n.º 8
0
void EmblemCellRenderer::do_render(const Cairo::RefPtr<Cairo::Context>& context, int widget, int background_area, Gdk::Rectangle &cell_area, int flags) {
    context->translate(cell_area.get_x(), cell_area.get_y());
    context->rectangle(0, 0, cell_area.get_width(), cell_area.get_height());
    context->clip();

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

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

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

    context->pop_group_to_source();
    context->set_operator(Cairo::OPERATOR_OVER);
    context->paint();
}
Exemplo n.º 9
0
int textview___::insert__(std::deque<Glib::ustring>* p,size_t start){
	Gtk::TextView* tv=tv__(p,1+start);
	if(!tv){
		return 1;
	}
	int i=0;
	size_t i_ctl=3+start;
	if(p->size()>i_ctl){
		if((*p)[i_ctl]=="头")
			i=1;
		else if((*p)[i_ctl]=="尾")
			i=2;
		else{
			d_(sh_,err_show_buzhichi_,2,p,i_ctl);
			return 1;
		}
	}
	Glib::RefPtr < Gtk::TextBuffer > tb = tv->get_buffer();
	Gtk::TextBuffer::iterator i1,i2;
	switch(i){
	case 1:
		i1=tb->begin();
		break;
	case 2:
		i1=tb->end();
		break;
	default:
		tb->get_selection_bounds(i1,i2);
		if(i2>i1){
			i1=tb->erase(i1,i2);
		}
		break;
	}
	Gdk::Rectangle rect;
	tv->get_visible_rect(rect);
	int y = -1;
	int height = -1;
	tv->get_line_yrange(i1, y, height);
	tb->place_cursor(tb->insert(i1, (*p)[2+start]));
	if (y < rect.get_y() + rect.get_height() + 16)
		 tv->scroll_to_mark(tb->get_insert(), 0);
	return 1;
}
Exemplo n.º 10
0
void
studio::render_gradient_to_window(const Glib::RefPtr<Gdk::Drawable>& window,const Gdk::Rectangle& ca,const synfig::Gradient &gradient)
{
	int	height = ca.get_height();
	int	width = ca.get_width()-4;

	float sample_width(1.0f/(float)width);
	Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(window));
	const Color bg1(0.25, 0.25, 0.25);
	const Color bg2(0.5, 0.5, 0.5);
	Gdk::Color gdk_c;
	int i;
	for(i=0;i<width;i++)
	{
		const Color c(gradient(float(i)/float(width),sample_width));
		const Color c1(Color::blend(c,bg1,1.0).clamped());
		const Color c2(Color::blend(c,bg2,1.0).clamped());
		gushort r1(256*App::gamma.r_F32_to_U8(c1.get_r()));
		gushort g1(256*App::gamma.g_F32_to_U8(c1.get_g()));
		gushort b1(256*App::gamma.b_F32_to_U8(c1.get_b()));
		gushort r2(256*App::gamma.r_F32_to_U8(c2.get_r()));
		gushort g2(256*App::gamma.g_F32_to_U8(c2.get_g()));
		gushort b2(256*App::gamma.b_F32_to_U8(c2.get_b()));

		if((i*2/height)&1)
		{
			gdk_c.set_rgb(r1,g1,b1);
			gc->set_rgb_fg_color(gdk_c);
			window->draw_rectangle(gc, true, ca.get_x()+i+2, ca.get_y(), 1, height/2);

			gdk_c.set_rgb(r2,g2,b2);
			gc->set_rgb_fg_color(gdk_c);
			window->draw_rectangle(gc, true, ca.get_x()+i+2, ca.get_y()+height/2, 1, height/2);
		}
		else
		{
			gdk_c.set_rgb(r2,g2,b2);
			gc->set_rgb_fg_color(gdk_c);
			window->draw_rectangle(gc, true, ca.get_x()+i+2, ca.get_y(), 1, height/2);

			gdk_c.set_rgb(r1,g1,b1);
			gc->set_rgb_fg_color(gdk_c);
			window->draw_rectangle(gc, true, ca.get_x()+i+2, ca.get_y()+height/2, 1, height/2);
		}
	}
	gc->set_rgb_fg_color(Gdk::Color("#ffffff"));
	window->draw_rectangle(gc, false, ca.get_x()+1, ca.get_y()+1, ca.get_width()-3, height-3);
	gc->set_rgb_fg_color(Gdk::Color("#000000"));
	window->draw_rectangle(gc, false, ca.get_x(), ca.get_y(), ca.get_width()-1, height-1);
}
Exemplo n.º 11
0
void
studio::render_time_point_to_window(
	const Glib::RefPtr<Gdk::Drawable>& window,
	const Gdk::Rectangle& area,
	const synfig::TimePoint &tp,
	bool selected
)
{
	Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(window));
	const Gdk::Color black("#2e3436");

	if(selected)
		gc->set_line_attributes(2,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
	else
		gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);

	Gdk::Color color;
	std::vector<Gdk::Point> points;

/*-	BEFORE ------------------------------------- */

	color=get_interp_color(tp.get_before());
	color=color_darken(color,1.0f);
	if(selected)color=color_darken(color,1.3f);
	gc->set_rgb_fg_color(color);

	switch(tp.get_before())
	{
	case INTERPOLATION_TCB:
		window->draw_arc(
			gc,
			true,
			area.get_x(),
			area.get_y(),
			area.get_width(),
			area.get_height(),
			64*90,
			64*180
		);
		gc->set_rgb_fg_color(black);
		window->draw_arc(
			gc,
			false,
			area.get_x(),
			area.get_y(),
			area.get_width(),
			area.get_height(),
			64*90,
			64*180
		);
		break;

	case INTERPOLATION_HALT:
		window->draw_arc(
			gc,
			true,
			area.get_x(),
			area.get_y(),
			area.get_width(),
			area.get_height()*2,
			64*90,
			64*90
		);
		gc->set_rgb_fg_color(black);
		window->draw_arc(
			gc,
			false,
			area.get_x(),
			area.get_y(),
			area.get_width(),
			area.get_height()*2,
			64*90,
			64*90
		);

		points.clear();
		points.push_back(Gdk::Point(area.get_x(),area.get_y()+area.get_height()));
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()+area.get_height()));
		window->draw_lines(gc,points);

		break;

	case INTERPOLATION_LINEAR:
		points.clear();
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()));
		points.push_back(Gdk::Point(area.get_x(),area.get_y()+area.get_height()));
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()+area.get_height()));
		window->draw_polygon(gc,true,points);
		gc->set_rgb_fg_color(black);
		window->draw_lines(gc,points);
		break;

	case INTERPOLATION_CONSTANT:
		points.clear();
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()));
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/4,area.get_y()));
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/4,area.get_y()+area.get_height()/2));
		points.push_back(Gdk::Point(area.get_x(),area.get_y()+area.get_height()/2));
		points.push_back(Gdk::Point(area.get_x(),area.get_y()+area.get_height()));
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()+area.get_height()));
		window->draw_polygon(gc,true,points);
		gc->set_rgb_fg_color(black);
		window->draw_lines(gc,points);
		break;

	case INTERPOLATION_CLAMPED:
		points.clear();
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()));
		points.push_back(Gdk::Point(area.get_x(),area.get_y()+area.get_height()/2));
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()+area.get_height()));
		window->draw_polygon(gc,true,points);
		gc->set_rgb_fg_color(black);
		window->draw_lines(gc,points);
		break;

	case INTERPOLATION_UNDEFINED: default:
		points.clear();
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()));
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/3,area.get_y()));
		points.push_back(Gdk::Point(area.get_x(),area.get_y()+area.get_height()/3));
		points.push_back(Gdk::Point(area.get_x(),area.get_y()+area.get_height()-area.get_height()/3));
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/3,area.get_y()+area.get_height()));
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()+area.get_height()));
		window->draw_polygon(gc,true,points);
		gc->set_rgb_fg_color(black);
		window->draw_lines(gc,points);
		break;
	}

/*-	AFTER -------------------------------------- */

	color=get_interp_color(tp.get_after());
	color=color_darken(color,0.8f);
	if(selected)color=color_darken(color,1.3f);
	gc->set_rgb_fg_color(color);

	switch(tp.get_after())
	{
	case INTERPOLATION_TCB:
		window->draw_arc(
			gc,
			true,
			area.get_x(),
			area.get_y(),
			area.get_width(),
			area.get_height(),
			64*270,
			64*180
		);
		gc->set_rgb_fg_color(black);
		window->draw_arc(
			gc,
			false,
			area.get_x(),
			area.get_y(),
			area.get_width(),
			area.get_height(),
			64*270,
			64*180
		);
		break;

	case INTERPOLATION_HALT:
		window->draw_arc(
			gc,
			true,
			area.get_x(),
			area.get_y()-area.get_height(),
			area.get_width(),
			area.get_height()*2,
			64*270,
			64*90
		);
		gc->set_rgb_fg_color(black);
		window->draw_arc(
			gc,
			false,
			area.get_x(),
			area.get_y()-area.get_height(),
			area.get_width(),
			area.get_height()*2,
			64*270,
			64*90
		);

		points.clear();
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()));
		points.push_back(Gdk::Point(area.get_x()+area.get_width(),area.get_y()));
		window->draw_lines(gc,points);

		break;

	case INTERPOLATION_LINEAR:
		points.clear();
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()));
		points.push_back(Gdk::Point(area.get_x()+area.get_width(),area.get_y()));
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()+area.get_height()));
		window->draw_polygon(gc,true,points);
		gc->set_rgb_fg_color(black);
		window->draw_lines(gc,points);
		break;

	case INTERPOLATION_CONSTANT:
		points.clear();
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()));
		points.push_back(Gdk::Point(area.get_x()+area.get_width(),area.get_y()));
		points.push_back(Gdk::Point(area.get_x()+area.get_width(),area.get_y()+area.get_height()/2));
		points.push_back(Gdk::Point(area.get_x()+area.get_width()-area.get_width()/4,area.get_y()+area.get_height()/2));
		points.push_back(Gdk::Point(area.get_x()+area.get_width()-area.get_width()/4,area.get_y()+area.get_height()));
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()+area.get_height()));
		window->draw_polygon(gc,true,points);
		gc->set_rgb_fg_color(black);
		window->draw_lines(gc,points);
		break;

	case INTERPOLATION_CLAMPED:
		points.clear();
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()));
		points.push_back(Gdk::Point(area.get_x()+area.get_width(),area.get_y()+area.get_height()/2));
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()+area.get_height()));
		window->draw_polygon(gc,true,points);
		gc->set_rgb_fg_color(black);
		window->draw_lines(gc,points);
		break;

	case INTERPOLATION_UNDEFINED: default:
		points.clear();
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()));
		points.push_back(Gdk::Point(area.get_x()+area.get_width()-area.get_width()/3,area.get_y()));
		points.push_back(Gdk::Point(area.get_x()+area.get_width(),area.get_y()+area.get_height()/3));
		points.push_back(Gdk::Point(area.get_x()+area.get_width(),area.get_y()+area.get_height()-area.get_height()/3));
		points.push_back(Gdk::Point(area.get_x()+area.get_width()-area.get_width()/3,area.get_y()+area.get_height()));
		points.push_back(Gdk::Point(area.get_x()+area.get_width()/2,area.get_y()+area.get_height()));
		window->draw_polygon(gc,true,points);
		gc->set_rgb_fg_color(black);
		window->draw_lines(gc,points);
		break;
	}

}
Exemplo n.º 12
0
void GazeTracker::calculateTrainingErrors() {
	int numMonitors = Gdk::Screen::get_default()->get_n_monitors();
	Gdk::Rectangle monitorGeometry;
	Glib::RefPtr<Gdk::Screen> screen = Gdk::Display::get_default()->get_default_screen();

	// Geometry of main monitor
	screen->get_monitor_geometry(numMonitors - 1, monitorGeometry);

	std::vector<Point> points = getSubVector(_calTargets, &CalTarget::point);

	//std::cout << "Input count: " << _inputCount;
	//std::cout << ", Target size: " << _calTargets.size() << std::endl;

	for (int i = 0; i < _calTargets.size(); i++) {
		double xTotal = 0;
		double yTotal = 0;
		double sampleCount = 0;

		//std::cout << points[i].x << ", " << points[i].y << " x " << allOutputCoords[j][0] << ", " << allOutputCoords[j][1] << std::endl;

		int j = 0;
		while (j < _inputCount && points[i].x == allOutputCoords[j][0] && points[i].y == allOutputCoords[j][1]) {
			double xEstimate = (_gaussianProcessX->getmean(Utils::SharedImage(allImages[j], &ignore)) + _gaussianProcessXLeft->getmean(Utils::SharedImage(allImagesLeft[j], &ignore))) / 2;
			double yEstimate = (_gaussianProcessY->getmean(Utils::SharedImage(allImages[j], &ignore)) + _gaussianProcessYLeft->getmean(Utils::SharedImage(allImagesLeft[j], &ignore))) / 2;

			//std::cout << "i, j = (" << i << ", " << j << "), est: " << xEstimate << "(" << _gaussianProcessX->getmean(SharedImage(allImages[j], &ignore)) << "," << _gaussianProcessXLeft->getmean(SharedImage(allImagesLeft[j], &ignore)) << ")" << ", " << yEstimate << "(" << _gaussianProcessY->getmean(SharedImage(allImages[j], &ignore)) << "," << _gaussianProcessYLeft->getmean(SharedImage(allImagesLeft[j], &ignore)) << ")" << std::endl;

			xTotal += xEstimate;
			yTotal += yEstimate;
			sampleCount++;
			j++;
		}

		xTotal /= sampleCount;
		yTotal /= sampleCount;

		*outputFile << "TARGET: (" << _calTargets[i].point.x << "\t, " << _calTargets[i].point.y << "\t),\tESTIMATE: (" << xTotal << "\t, " << yTotal << ")" << std::endl;
		//std::cout << "TARGET: (" << _calTargets[i].point.x << "\t, " << _calTargets[i].point.y << "\t),\tESTIMATE: (" << xTotal << "\t, " << yTotal << "),\tDIFF: (" << fabs(_calTargets[i].point.x- x_total) << "\t, " << fabs(_calTargets[i].point.y - y_total) << ")" << std::endl;

		// Calibration error removal
		_xv[i][0] = xTotal;		// Source
		_xv[i][1] = yTotal;

		// Targets
		_fvX[i] = _calTargets[i].point.x;
		_fvY[i] = _calTargets[i].point.y;
		_sigv[i] = 0;

		int targetId = getTargetId(Point(xTotal, yTotal));

		if (targetId != i) {
			std::cout << "Target id is not the expected one!! (Expected: "<< i << ", Current: " << targetId << ")" << std::endl;
		}
	}

	// Add the corners of the monitor as 4 extra data points. This helps the correction for points that are near the edge of monitor
	_xv[_calTargets.size()][0] = monitorGeometry.get_x();
	_xv[_calTargets.size()][1] = monitorGeometry.get_y();
	_fvX[_calTargets.size()] = monitorGeometry.get_x()-40;
	_fvY[_calTargets.size()] = monitorGeometry.get_y()-40;

	_xv[_calTargets.size()+1][0] = monitorGeometry.get_x() + monitorGeometry.get_width();
	_xv[_calTargets.size()+1][1] = monitorGeometry.get_y();
	_fvX[_calTargets.size()+1] = monitorGeometry.get_x() + monitorGeometry.get_width() + 40;
	_fvY[_calTargets.size()+1] = monitorGeometry.get_y() - 40;

	_xv[_calTargets.size()+2][0] = monitorGeometry.get_x() + monitorGeometry.get_width();
	_xv[_calTargets.size()+2][1] = monitorGeometry.get_y() + monitorGeometry.get_height();
	_fvX[_calTargets.size()+2] = monitorGeometry.get_x() + monitorGeometry.get_width() + 40;
	_fvY[_calTargets.size()+2] = monitorGeometry.get_y() + monitorGeometry.get_height() + 40;

	_xv[_calTargets.size()+3][0] = monitorGeometry.get_x();
	_xv[_calTargets.size()+3][1] = monitorGeometry.get_y() + monitorGeometry.get_height();
	_fvX[_calTargets.size()+3] = monitorGeometry.get_x() - 40;
	_fvY[_calTargets.size()+3] = monitorGeometry.get_y() + monitorGeometry.get_height() + 40;

	int pointCount = _calTargets.size() + 4;
	int N = pointCount;
	N = binomialInv(N, 2) - 1;

	// Find the best beta and gamma parameters for interpolation
	mirBetaGamma(1, 2, pointCount, (double *)_xv, _fvX, _sigv, 0, NULL, NULL, NULL, N, 2, 50.0, &_betaX, &_gammaX);
	mirBetaGamma(1, 2, pointCount, (double *)_xv, _fvY, _sigv, 0, NULL, NULL, NULL, N, 2, 50.0, &_betaY, &_gammaY);

	*outputFile << std::endl << std::endl;
	std::cout << std::endl << std::endl;

	outputFile->flush();

	std::cout << "ERROR CALCULATION FINISHED. BETA = " << _betaX << ", " << _betaY << ", GAMMA IS " << _gammaX << ", " << _gammaY << std::endl;
	for (int i = 0; i < pointCount; i++) {
		std::cout << _xv[i][0] << ", " << _xv[i][1] << std::endl;
	}

	//checkErrorCorrection();
}
Exemplo n.º 13
0
inline bool operator==(const Gdk::Rectangle& a, const Gdk::Rectangle& b)
{
  return a.get_x()==b.get_x() && a.get_y()==b.get_y() && a.get_width()==b.get_width() && a.get_height()==b.get_height();
}
Exemplo n.º 14
0
void
CellRenderer_TimeTrack::render_vfunc(
	const ::Cairo::RefPtr< ::Cairo::Context>& cr,
	Gtk::Widget& /* widget */,
	const Gdk::Rectangle& /* background_area */,
	const Gdk::Rectangle& cell_area,
	Gtk::CellRendererState /* flags */)
{
	if(!cr)
		return;

	Glib::RefPtr<Gtk::Adjustment> adjustment=get_adjustment();
	// Gtk::StateType state = Gtk::STATE_ACTIVE;
	// Gtk::ShadowType shadow;

	Gdk::Color
		curr_time_color("#0000ff"),
		inactive_color("#000000"),
		keyframe_color("#a07f7f");
	Gdk::Color activepoint_color[2];

	activepoint_color[0]=Gdk::Color("#ff0000");
	activepoint_color[1]=Gdk::Color("#00ff00");

	int stride = Cairo::ImageSurface::format_stride_for_width(Cairo::FORMAT_A1, 2);
	std::vector<unsigned char> stipple_xpm(2*stride, 0);
	stipple_xpm[0] = 2;
	Cairo::RefPtr<Cairo::ImageSurface> inactive_mask_img = Cairo::ImageSurface::create(&stipple_xpm.front(), Cairo::FORMAT_A1, 2, 2, stride);

	synfig::Canvas::Handle canvas(property_canvas().get_value());

	synfigapp::ValueDesc value_desc = property_value_desc().get_value();
	synfig::ValueNode *base_value = value_desc.get_value_node().get();
	// synfig::ValueNode_Animated *value_node=dynamic_cast<synfig::ValueNode_Animated*>(base_value);

	synfig::ValueNode_DynamicList *parent_value_node(0);
	if(property_value_desc().get_value().parent_is_value_node())
		parent_value_node=dynamic_cast<synfig::ValueNode_DynamicList*>(property_value_desc().get_value().get_parent_value_node().get());

	// If the canvas is defined, then load up the keyframes
	if(canvas)
	{
		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)cell_area.get_width()/(adjustment->get_upper()-adjustment->get_lower())*(iter->get_time()-adjustment->get_lower())));
			if(iter->get_time()>=adjustment->get_lower() && iter->get_time()<adjustment->get_upper())
			{
				cr->set_source_rgb(keyframe_color.get_red_p(), keyframe_color.get_green_p(), keyframe_color.get_blue_p());
				cr->rectangle(cell_area.get_x()+x, cell_area.get_y(), 1, cell_area.get_height()+1);
				cr->fill();
			}
		}
	}

	//render all the time points that exist
	{
		const synfig::Node::time_set *tset = get_times_from_vdesc(value_desc);

		if(tset)
		{
			const synfig::Time time_offset = get_time_offset_from_vdesc(value_desc);
			synfig::Node::time_set::const_iterator	i = tset->begin(), end = tset->end();

			float 	lower = adjustment->get_lower(),
					upper = adjustment->get_upper();

			Gdk::Rectangle area(cell_area);

			bool valselected = sel_value.get_value_node() == base_value && !sel_times.empty();

			float cfps = get_canvas()->rend_desc().get_frame_rate();

			vector<Time>	drawredafter;

			Time diff = actual_time - actual_dragtime;//selected_time-drag_time;
			for(; i != end; ++i)
			{
				//find the coordinate in the drawable space...
				Time t_orig = i->get_time();
				if(!t_orig.is_valid()) continue;
				Time t = t_orig - time_offset;
				if(t<adjustment->get_lower() || t>adjustment->get_upper()) continue;

				//if it found it... (might want to change comparison, and optimize
				//					 sel_times.find to not produce an overall nlogn solution)

				bool selected=false;
				//not dragging... just draw as per normal
				//if move dragging draw offset
				//if copy dragging draw both...

				if(valselected && sel_times.find(t_orig) != sel_times.end())
				{
					if(dragging) //skip if we're dragging because we'll render it later
					{
						if(mode & COPY_MASK) // draw both blue and red moved
						{
							drawredafter.push_back(t + diff.round(cfps));
						}else if(mode & DELETE_MASK) //it's just red...
						{
							selected=true;
						}else //move - draw the red on top of the others...
						{
							drawredafter.push_back(t + diff.round(cfps));
							continue;
						}
					}else
					{
						selected=true;
					}
				}

				//synfig::info("Displaying time: %.3f s",(float)t);
				const int x = (int)((t-lower)*area.get_width()/(upper-lower));

				//should draw me a grey filled circle...
				Gdk::Rectangle area2(
					area.get_x() - area.get_height()/2 + x + 1,
					area.get_y() + 1,
					area.get_height()-2,
					area.get_height()-2
				);
				render_time_point_to_window(cr,area2,*i - time_offset,selected);
			}

			{
				vector<Time>::iterator i = drawredafter.begin(), end = drawredafter.end();
				for(; i != end; ++i)
				{
					//find the coordinate in the drawable space...
					Time t = *i;

					if(!t.is_valid())
						continue;

					//synfig::info("Displaying time: %.3f s",(float)t);
					const int x = (int)((t-lower)*area.get_width()/(upper-lower));

					//should draw me a grey filled circle...

					Gdk::Rectangle area2(
						area.get_x() - area.get_height()/2 + x + 1,
						area.get_y() + 1,
						area.get_height()-2,
						area.get_height()-2
					);
					render_time_point_to_window(cr,area2,*i,true);
				}
			}
		}
	}

	Gdk::Rectangle area(cell_area);
	// If the parent of this value node is a dynamic list, then
	// render the on and off times
	if(parent_value_node)
	{
		const int index(property_value_desc().get_value().get_index());
		const synfig::ValueNode_DynamicList::ListEntry& list_entry(parent_value_node->list[index]);
		const synfig::ValueNode_DynamicList::ListEntry::ActivepointList& activepoint_list(list_entry.timing_info);
		synfig::ValueNode_DynamicList::ListEntry::ActivepointList::const_iterator iter,next;

		bool is_off(false);
		if(!activepoint_list.empty())
			is_off=!activepoint_list.front().state;

		int xstart(0);

		int x=0 /*,prevx=0*/;
		for(next=activepoint_list.begin(),iter=next++;iter!=activepoint_list.end();iter=next++)
		{
			x=((int)((float)area.get_width()/(adjustment->get_upper()-adjustment->get_lower())*(iter->time-adjustment->get_lower())));
			if(x<0)x=0;
			if(x>area.get_width())x=area.get_width();

			bool status_at_time=0;
			if(next!=activepoint_list.end())
			{
				status_at_time=!list_entry.status_at_time((iter->time+next->time)/2.0);
			}
			else
				status_at_time=!list_entry.status_at_time(Time::end());

			if(!is_off && status_at_time)
			{
				xstart=x;
				is_off=true;
			}
			else
			if(is_off && !status_at_time)
			{
				cr->set_source_rgb( inactive_color.get_red_p(),
									inactive_color.get_green_p(),
									inactive_color.get_red_p() );
				cr->mask(inactive_mask_img, 0, 0);
				cr->rectangle(area.get_x()+xstart, area.get_y(), x-xstart, area.get_height());
				cr->fill();
				is_off=false;
			}

			if(iter->time>=adjustment->get_lower() && iter->time<adjustment->get_upper())
			{
				int w(1);
				if(selected==*iter)
					w=3;
				cr->set_source_rgb( activepoint_color[iter->state].get_red_p(),
									activepoint_color[iter->state].get_green_p(),
									activepoint_color[iter->state].get_red_p() );
				cr->rectangle(area.get_x()+x-w/2, area.get_y(), w, area.get_height());
				cr->fill();
			}
			//prevx=x;
		}
		if(is_off)
		{
			cr->set_source_rgb( inactive_color.get_red_p(),
								inactive_color.get_green_p(),
								inactive_color.get_red_p() );
			cr->mask(inactive_mask_img, 0, 0);
			cr->rectangle(area.get_x()+xstart, area.get_y(), area.get_width()-xstart, area.get_height());
			cr->fill();
		}
	}

	// Render a line that defines the current tick in time
	{
		const int x((int)((float)area.get_width()/(adjustment->get_upper()-adjustment->get_lower())*(adjustment->get_value()-adjustment->get_lower())));
		if(adjustment->get_value()>=adjustment->get_lower() && adjustment->get_value()<adjustment->get_upper())
		{
			cr->set_source_rgb( curr_time_color.get_red_p(),
								curr_time_color.get_green_p(),
								curr_time_color.get_red_p() );
			cr->rectangle(area.get_x()+x, area.get_y(), 1, area.get_height());
			cr->fill();
		}
	}
}
Exemplo n.º 15
0
void
CellRenderer_ValueBase::render_vfunc(
		const Glib::RefPtr<Gdk::Drawable>& window,
		Gtk::Widget& widget,
		const Gdk::Rectangle& background_area,
		const Gdk::Rectangle& ca,
		const Gdk::Rectangle& expose_area,
		Gtk::CellRendererState flags)
{
	if(!window)
		return;
//	const unsigned int cell_xpad = property_xpad();
//	const unsigned int cell_ypad = property_ypad();

	//int x_offset = 0, y_offset = 0;
//	int	width = ca.get_width();
	int	height = ca.get_height();
//	get_size(widget, ca, x_offset, y_offset, width, height);

//	width  -= cell_xpad * 2;
//	height -= cell_ypad * 2;

//	if(width <= 0 || height <= 0)
//		return;

	Gtk::StateType state = Gtk::STATE_INSENSITIVE;
	if(property_editable())
		state = Gtk::STATE_NORMAL;
	if((flags & Gtk::CELL_RENDERER_SELECTED) != 0)
		state = (widget.has_focus()) ? Gtk::STATE_SELECTED : Gtk::STATE_ACTIVE;

	ValueBase data=property_value_.get_value();

	switch(data.get_type())
	{
	case ValueBase::TYPE_REAL:
		if(((synfig::ParamDesc)property_param_desc_).get_is_distance())
		{
			Distance x(data.get(Real()),Distance::SYSTEM_UNITS);
			x.convert(App::distance_system,get_canvas()->rend_desc());
			property_text()=(Glib::ustring)x.get_string(6).c_str();
		}
		else
			property_text()=(Glib::ustring)strprintf("%.6f",data.get(Real()));
		break;
	case ValueBase::TYPE_TIME:
		property_text()=(Glib::ustring)data.get(Time()).get_string(get_canvas()->rend_desc().get_frame_rate(),App::get_time_format());
		break;
	case ValueBase::TYPE_ANGLE:
		property_text()=(Glib::ustring)strprintf("%.2fᵒ",(Real)Angle::deg(data.get(Angle())).get());
		break;
	case ValueBase::TYPE_INTEGER:
		{
			String param_hint, child_param_hint;
			param_hint=get_param_desc().get_hint();
			child_param_hint=get_child_param_desc().get_hint();
			if(param_hint!="enum" && child_param_hint!="enum")
			{
				property_text()=(Glib::ustring)strprintf("%i",data.get(int()));
			}
			else
			{
				property_text()=(Glib::ustring)strprintf("(%i)",data.get(int()));
				std::list<synfig::ParamDesc::EnumData> enum_list;
				if(param_hint=="enum")
					enum_list=((synfig::ParamDesc)property_param_desc_).get_enum_list();
				else if(child_param_hint=="enum")
					enum_list=((synfig::ParamDesc)property_child_param_desc_).get_enum_list();
				std::list<synfig::ParamDesc::EnumData>::iterator iter;
				for(iter=enum_list.begin();iter!=enum_list.end();iter++)
					if(iter->value==data.get(int()))
					{
						// don't show the key_board s_hortcut under_scores
						String local_name = iter->local_name;
						String::size_type pos = local_name.find_first_of('_');
						if (pos != String::npos)
							property_text() = local_name.substr(0,pos) + local_name.substr(pos+1);
						else
							property_text() = local_name;
						break;
					}
			}
		}
		break;

	case ValueBase::TYPE_VECTOR:
		{
			Vector vector=data.get(Vector());
			Distance x(vector[0],Distance::SYSTEM_UNITS),y(vector[1],Distance::SYSTEM_UNITS);
			x.convert(App::distance_system,get_canvas()->rend_desc());
			y.convert(App::distance_system,get_canvas()->rend_desc());
			property_text()=static_cast<Glib::ustring>(strprintf("%s,%s",x.get_string(6).c_str(),y.get_string(6).c_str()));
		}
		break;

	case ValueBase::TYPE_STRING:

		if(data.get_type()==ValueBase::TYPE_STRING)
		{
			if(!data.get(synfig::String()).empty())
				property_text()=static_cast<Glib::ustring>(data.get(synfig::String()));
			else
				property_text()=Glib::ustring("<empty>");
		}
		break;
	case ValueBase::TYPE_CANVAS:
		if(data.get(etl::handle<synfig::Canvas>()))
		{
			if(data.get(etl::handle<synfig::Canvas>())->is_inline())
				property_text()=_("<Group>");
			else
				property_text()=(Glib::ustring)data.get(etl::handle<synfig::Canvas>())->get_id();
		}
		else
			property_text()=_("<No Image Selected>");
		break;
	case ValueBase::TYPE_COLOR:
		{
			render_color_to_window(window,ca,data.get(Color()));
			return;
		}
		break;
	case ValueBase::TYPE_BOOL:
		{
			widget.get_style()->paint_check(
				Glib::RefPtr<Gdk::Window>::cast_static(window), state,
				data.get(bool())?Gtk::SHADOW_IN:Gtk::SHADOW_OUT,
				ca, widget, "cellcheck",
				ca.get_x()/* + x_offset + cell_xpad*/,
				ca.get_y()/* + y_offset + cell_ypad*/,
				height-1,height-1);
			return;
		}
		break;
	case ValueBase::TYPE_NIL:
		//property_text()=(Glib::ustring)" ";
		return;
		break;
	case ValueBase::TYPE_GRADIENT:
		render_gradient_to_window(window,ca,data.get(Gradient()));
		return;
		break;
	case ValueBase::TYPE_BONE:
	case ValueBase::TYPE_SEGMENT:
	case ValueBase::TYPE_LIST:
	case ValueBase::TYPE_BLINEPOINT:
	case ValueBase::TYPE_WIDTHPOINT:
	case ValueBase::TYPE_DASHITEM:
		property_text()=(Glib::ustring)(ValueBase::type_local_name(data.get_type()));
		break;
	case ValueBase::TYPE_VALUENODE_BONE:
	{
		ValueNode_Bone::Handle bone_node(data.get(ValueNode_Bone::Handle()));
		String name(_("No Parent"));

		if (!bone_node->is_root())
		{
			name = (*(bone_node->get_link("name")))(get_canvas()->get_time()).get(String());
			if (name.empty())
				name = bone_node->get_guid().get_string();
		}

		property_text()=(Glib::ustring)(name);
		break;
	}
	default:
		property_text()=static_cast<Glib::ustring>(_("UNKNOWN"));
		break;
	}
	CellRendererText::render_vfunc(window,widget,background_area,ca,expose_area,flags);
}
/** Render the cell.
 * This is called to render the cell.
 * @param window window
 * @param widget widget
 * @param background_area dimensions of the background area
 * @param cell_area dimensions of the cell area
 * @param expose_area dimensions of the exposed area
 * @param flags render flags
 */
void
TwoLinesCellRenderer::render_vfunc(const Glib::RefPtr<Gdk::Drawable> &window,
				   Gtk::Widget &widget,
				   const Gdk::Rectangle &background_area,
				   const Gdk::Rectangle &cell_area,
				   const Gdk::Rectangle &expose_area,
				   Gtk::CellRendererState flags)
#endif
{
#ifdef GLIBMM_PROPERTIES_ENABLED
  // Get cell size
  int x_offset = 0, y_offset = 0;
#if GTK_VERSION_LT(3,0)
  int width = 0, height = 0;
  get_size(widget, cell_area, x_offset, y_offset, width, height);

  // Get cell state
  //Gtk::StateType state;
  Gtk::StateType text_state;
  if ((flags & Gtk::CELL_RENDERER_SELECTED) != 0) {
    //state = Gtk::STATE_SELECTED;
    text_state = (widget.has_focus()) ? Gtk::STATE_SELECTED : Gtk::STATE_ACTIVE;
  } else {
    //state = Gtk::STATE_NORMAL;
    text_state = (widget.is_sensitive()) ? Gtk::STATE_NORMAL : Gtk::STATE_INSENSITIVE;
  }
	
  // Draw color text
  Glib::RefPtr<Gdk::Window> win =
    Glib::RefPtr<Gdk::Window>::cast_dynamic(window);
#endif
  Glib::RefPtr<Pango::Layout> layout_ptr =
    widget.create_pango_layout(__property_line1);
  Pango::Rectangle rect1 = layout_ptr->get_pixel_logical_extents();
#if GTK_VERSION_GE(3,0)
  cr->move_to(cell_area.get_x() + x_offset + 2 * property_xpad(),
              cell_area.get_y() + y_offset + 2 * property_ypad());
  layout_ptr->show_in_cairo_context(cr);
#else
  widget.get_style()->paint_layout(win, text_state, true, cell_area,
				   widget, "cellrenderertext",
				   cell_area.get_x() + x_offset + 2 * property_xpad(),
				   cell_area.get_y() + y_offset + 2 * property_ypad(),
				   layout_ptr);
#endif

  if (__property_line2_enabled.get_value()) {
    Glib::RefPtr<Pango::Layout> layout2 =
      widget.create_pango_layout(__property_line2);
#if GTK_VERSION_GE(3,0)
    Pango::FontDescription font2("sans 10");
#else
    Glib::RefPtr<Gtk::Style> style = widget.get_style();
    Pango::FontDescription font2 = style->get_font();
#endif
    font2.set_size((int)roundf(Pango::SCALE_SMALL * font2.get_size()));
    layout2->set_font_description(font2);
    //Pango::Rectangle rect2 = layout2->get_pixel_logical_extents();
    layout2->set_ellipsize(Pango::ELLIPSIZE_END);
    layout2->set_width((cell_area.get_width() - property_xpad()) * Pango::SCALE);

#if GTK_VERSION_GE(3,0)
  cr->move_to(cell_area.get_x() + x_offset + property_xpad(),
              cell_area.get_y() + y_offset + property_ypad() +
             rect1.get_height() + 4);
  layout2->show_in_cairo_context(cr);
#else
    widget.get_style()->paint_layout (win, text_state, true, cell_area,
                                      widget, "cellrenderertext",
                                      cell_area.get_x() + x_offset + property_xpad(),
                                      cell_area.get_y() + y_offset + property_ypad() + rect1.get_height() + 4,
                                      layout2);
#endif
  }
#endif
}
Exemplo n.º 17
0
void LinkHint::draw(DrawContext dc) {
	if(!textLayout) {
		textLayout = Pango::Layout::create(dc);
		textLayout->set_text(text);
		textLayout->set_wrap(Pango::WRAP_WORD);
		//textLayout->set_ellipsize(Pango::ELLIPSIZE_END);
		Pango::FontDescription f("arial 8");
		textLayout->set_font_description(f);
		textLayout->set_indent(10);
		textLayout->set_alignment(Pango::ALIGN_LEFT);
		textLayout->set_width(width*Pango::SCALE);
		textLayout->set_height(-1);
		textLayout->get_pixel_size(width, height);
	}

	Gdk::Rectangle r = drawRect();

	Gdk::Cairo::set_source_rgba(dc, darkColor);
	int px = parent->x + parent->width / 2;
	int py = parent->y + parent->height / 2;
	int mx = parent->x + x + width / 2;
	int my = parent->y + y + height / 2;

	dc->set_dash(dash, 1);
	dc->move_to(px, py);
	if(!(x + width < 0 || x > parent->width))
		dc->line_to((px + mx) / 2, my);
	else if(x < 0)
		dc->line_to((px + parent->x + x + width) / 2, my);
	else
		dc->line_to((px + parent->x + x) / 2, my);
	dc->line_to(mx, my);
	dc->stroke();
	dc->unset_dash();

	//Cairo::Antialias old_a = dc->get_antialias();
	//if(old_a == Cairo::ANTIALIAS_NONE)
	//	dc->set_antialias(Cairo::ANTIALIAS_DEFAULT);

	Gdk::Cairo::set_source_rgba(dc, sysColors.btnLight);
	dc->rectangle(r.get_x(), r.get_y(), r.get_width(), r.get_height());
	//roundRect(dc, r.get_x(), r.get_y(), r.get_width(), r.get_height());
	dc->fill();

	Gdk::Cairo::set_source_rgba(dc, sysColors.btnDark);
	dc->rectangle(r.get_x(), r.get_y(), r.get_width(), r.get_height());
	//roundRect(dc, r.get_x(), r.get_y(), r.get_width(), r.get_height());
	dc->stroke();

	//dc->set_antialias(old_a);

	//Gdk::Cairo::set_source_color(dc, darkColor);
	//dc->rectangle(r.get_x(), r.get_y(), r.get_width() - 1, r.get_height() - 1);
	//roundRect(dc, r.get_x(), r.get_y(), r.get_width(), r.get_height());
	//dc->stroke();

	//dc->set_font_size(11);
	//dc->select_font_face("arial", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL);
	//dc->move_to(r.get_x() + 4, r.get_y() + 12);
	//dc->show_text(text);

	//dc->rectangle(r.get_x(), r.get_y(), r.get_width(), r.get_height());
	//dc->clip();

	dc->set_source_rgb(0, 0, 0);
	dc->move_to(r.get_x() + 3, r.get_y() + 3);
	textLayout->show_in_cairo_context(dc);

	//dc->reset_clip();
}
Exemplo n.º 18
0
	bool
	on_event(GdkEvent *event)
	{
		switch(event->type)
		{
		case GDK_SCROLL:
			if(mimic_tree_view)
			{
				if(event->scroll.direction==GDK_SCROLL_DOWN)
				{
					mimic_tree_view->get_vadjustment()->set_value(
						std::min(
							mimic_tree_view->get_vadjustment()->get_value()+
							mimic_tree_view->get_vadjustment()->get_step_increment(),
							mimic_tree_view->get_vadjustment()->get_upper()-
							mimic_tree_view->get_vadjustment()->get_page_size()
						)
					);
					mimic_tree_view->get_vadjustment()->value_changed();
				}
				else if(event->scroll.direction==GDK_SCROLL_UP)
				{
					mimic_tree_view->get_vadjustment()->set_value(
						std::max(
							mimic_tree_view->get_vadjustment()->get_value()-
							mimic_tree_view->get_vadjustment()->get_step_increment(),
							mimic_tree_view->get_vadjustment()->get_lower()
						)
					);
					mimic_tree_view->get_vadjustment()->value_changed();
				}
			}
			break;
		case GDK_BUTTON_PRESS:
			{
				Gtk::TreeModel::Path path;
				Gtk::TreeViewColumn *column;
				int cell_x, cell_y;
				if(!get_path_at_pos(
					int(event->button.x),int(event->button.y),	// x, y
					path, // TreeModel::Path&
					column, //TreeViewColumn*&
					cell_x,cell_y //int&cell_x,int&cell_y
					)
				) break;
				const Gtk::TreeRow row = *(get_model()->get_iter(path));

				if(column && column->get_first_cell_renderer()==cellrenderer_time_track)
				{
					Gdk::Rectangle rect;
					get_cell_area(path,*column,rect);
					cellrenderer_time_track->property_value_desc()=row[model.value_desc];
					cellrenderer_time_track->property_canvas()=row[model.canvas];
					cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
					queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
					return true;
					//return signal_param_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
				}
			}
			break;

		case GDK_MOTION_NOTIFY:
			{
				Gtk::TreeModel::Path path;
				Gtk::TreeViewColumn *column;
				int cell_x, cell_y;
				if(!get_path_at_pos(
					(int)event->motion.x,(int)event->motion.y,	// x, y
					path, // TreeModel::Path&
					column, //TreeViewColumn*&
					cell_x,cell_y //int&cell_x,int&cell_y
					)
				) break;

				if(!get_model()->get_iter(path))
					break;

				Gtk::TreeRow row = *(get_model()->get_iter(path));

				if ((event->motion.state&GDK_BUTTON1_MASK || event->motion.state&GDK_BUTTON3_MASK) &&
					column &&
					cellrenderer_time_track == column->get_first_cell_renderer())
				{
					Gdk::Rectangle rect;
					get_cell_area(path,*column,rect);
					cellrenderer_time_track->property_value_desc()=row[model.value_desc];
					cellrenderer_time_track->property_canvas()=row[model.canvas];
					cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
					queue_draw();
					//queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
					return true;
				}
/*				else
				if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
				{
					tooltips_.unset_tip(*this);
					Glib::ustring tooltips_string(row[layer_model.tooltip]);
					last_tooltip_path=path;
					if(!tooltips_string.empty())
					{
						tooltips_.set_tip(*this,tooltips_string);
						tooltips_.force_window();
					}
				}
*/
				return true;
			}
			break;
		case GDK_BUTTON_RELEASE:
			{
				Gtk::TreeModel::Path path;
				Gtk::TreeViewColumn *column;
				int cell_x, cell_y;
				if(!get_path_at_pos(
					(int)event->button.x,(int)event->button.y,	// x, y
					path, // TreeModel::Path&
					column, //TreeViewColumn*&
					cell_x,cell_y //int&cell_x,int&cell_y
					)
				) break;

				if(!get_model()->get_iter(path))
					break;

				Gtk::TreeRow row = *(get_model()->get_iter(path));

				if(column && cellrenderer_time_track==column->get_first_cell_renderer())
				{
					Gdk::Rectangle rect;
					get_cell_area(path,*column,rect);
					cellrenderer_time_track->property_value_desc()=row[model.value_desc];
					cellrenderer_time_track->property_canvas()=row[model.canvas];
					cellrenderer_time_track->activate(event,*this,path.to_string(),rect,rect,Gtk::CellRendererState());
					queue_draw();
					queue_draw_area(rect.get_x(),rect.get_y(),rect.get_width(),rect.get_height());
					return true;
				}
			}
			break;
		default:
			break;
		}
		mimic_resync();
		return Gtk::TreeView::on_event(event);
	}
Exemplo n.º 19
0
void GazeTracker::calculateTrainingErrors() {
	int num_of_monitors = Gdk::Screen::get_default()->get_n_monitors();
	Gdk::Rectangle monitorgeometry;
	Glib::RefPtr<Gdk::Screen> screen = Gdk::Display::get_default()->get_default_screen();

	// Geometry of main monitor
	screen->get_monitor_geometry(num_of_monitors - 1, monitorgeometry);
	
	vector<Point> points = getsubvector(caltargets, &CalTarget::point);
	
	int j = 0;
	
	//cout << "Input count: " << input_count;
	//cout << ", Target size: " << caltargets.size() << endl;
	
	for(int i=0; i<caltargets.size(); i++) {
		double x_total = 0;
		double y_total = 0;
		double sample_count = 0;
		
		//cout << points[i].x << ", " << points[i].y << " x " << all_output_coords[j][0] << ", " << all_output_coords[j][1] << endl;
		
		while(j < input_count && points[i].x == all_output_coords[j][0] && points[i].y == all_output_coords[j][1]) {
			double x_estimate = (gpx->getmean(SharedImage(all_images[j], &ignore)) + gpx_left->getmean(SharedImage(all_images_left[j], &ignore))) / 2;
			double y_estimate = (gpy->getmean(SharedImage(all_images[j], &ignore)) + gpy_left->getmean(SharedImage(all_images_left[j], &ignore))) / 2;
			
			//cout << "i, j = (" << i << ", " << j << "), est: " << x_estimate << "("<< gpx->getmean(SharedImage(all_images[j], &ignore)) << ","<< gpx_left->getmean(SharedImage(all_images_left[j], &ignore)) << ")" << ", " << y_estimate << "("<< gpy->getmean(SharedImage(all_images[j], &ignore)) <<","<< gpy_left->getmean(SharedImage(all_images_left[j], &ignore)) << ")"<< endl;
			
			x_total += x_estimate;
			y_total += y_estimate;
			sample_count++;
			j++;
		}
		
		x_total /= sample_count;
		y_total /= sample_count;
	
		*output_file << "TARGET: (" << caltargets[i].point.x << "\t, " << caltargets[i].point.y << "\t),\tESTIMATE: ("<< x_total << "\t, " << y_total <<")" << endl;
		//cout << "TARGET: (" << caltargets[i].point.x << "\t, " << caltargets[i].point.y << "\t),\tESTIMATE: ("<< x_total << "\t, " << y_total <<"),\tDIFF: ("<< fabs(caltargets[i].point.x- x_total) << "\t, " << fabs(caltargets[i].point.y - y_total) <<")" << endl;
		
		// Calibration error removal
		xv[i][0] = x_total;		// Source
		xv[i][1] = y_total;
		
		// Targets
		fv_x[i] = caltargets[i].point.x;
		fv_y[i] = caltargets[i].point.y;
		sigv[i] = 0;
		
		int targetId = getTargetId(Point(x_total, y_total));
		
		if(targetId != i) {
			cout << "Target id is not the expected one!! (Expected: "<< i<< ", Current: "<< targetId << ")" << endl;
		}
		
	}
	
	// Add the corners of the monitor as 4 extra data points. This helps the correction for points that are near the edge of monitor
	xv[caltargets.size()][0] = monitorgeometry.get_x();
	xv[caltargets.size()][1] = monitorgeometry.get_y();
	fv_x[caltargets.size()] = monitorgeometry.get_x()-40;
	fv_y[caltargets.size()] = monitorgeometry.get_y()-40;
	
	xv[caltargets.size()+1][0] = monitorgeometry.get_x() + monitorgeometry.get_width();
	xv[caltargets.size()+1][1] = monitorgeometry.get_y();
	fv_x[caltargets.size()+1] = monitorgeometry.get_x() + monitorgeometry.get_width() + 40;
	fv_y[caltargets.size()+1] = monitorgeometry.get_y() - 40;
	
	xv[caltargets.size()+2][0] = monitorgeometry.get_x() + monitorgeometry.get_width();
	xv[caltargets.size()+2][1] = monitorgeometry.get_y() + monitorgeometry.get_height();
	fv_x[caltargets.size()+2] = monitorgeometry.get_x() + monitorgeometry.get_width() + 40;
	fv_y[caltargets.size()+2] = monitorgeometry.get_y() + monitorgeometry.get_height() + 40;
	
	xv[caltargets.size()+3][0] = monitorgeometry.get_x();
	xv[caltargets.size()+3][1] = monitorgeometry.get_y() + monitorgeometry.get_height();
	fv_x[caltargets.size()+3] = monitorgeometry.get_x() - 40;
	fv_y[caltargets.size()+3] = monitorgeometry.get_y() + monitorgeometry.get_height() + 40;
	
	int point_count = caltargets.size() + 4;
    int N = point_count;
    N = binomialInv(N, 2) - 1;
	
	// Find the best beta and gamma parameters for interpolation
    mirBetaGamma(1, 2, point_count, (double*)xv, fv_x, sigv, 0, NULL, NULL, NULL,
                 N, 2, 50.0, &beta_x, &gamma_x);
    mirBetaGamma(1, 2, point_count, (double*)xv, fv_y, sigv, 0, NULL, NULL, NULL,
                 N, 2, 50.0, &beta_y, &gamma_y);
	
	*output_file << endl << endl;
	cout << endl << endl;
	
	output_file->flush();
	
	
	cout << "ERROR CALCULATION FINISHED. BETA = " << beta_x << ", " << beta_y << ", GAMMA IS " << gamma_x << ", " << gamma_y << endl;
	for(int j=0; j<point_count; j++) {
			cout << xv[j][0] << ", " << xv[j][1] << endl;
	}
	

    //checkErrorCorrection();
}
Exemplo n.º 20
0
 int
 TimelineLayoutHelper::layout_headers_recursive (TrackTree::iterator_base parent_iterator
                                                ,const int branch_offset
                                                ,const int header_width
                                                ,const int indent_width
                                                ,const int depth
                                                ,const bool parent_expanded)
 {
   REQUIRE(depth >= 0);
   
   const bool dragging = is_dragging_track();
   int child_offset = 0;
   
   TrackTree::sibling_iterator iterator;
   for (iterator = layoutTree.begin(parent_iterator);
        iterator != layoutTree.end(parent_iterator);
        iterator++)
     {
       Gdk::Rectangle rect;
       int track_height = 0;
       
       const shared_ptr<model::Track> &modelTrack = *iterator;
       REQUIRE(modelTrack);
       
       shared_ptr<timeline::Track> timeline_track = lookup_timeline_track(modelTrack);
       
       // Is this the root track of a dragging branch?
       bool being_dragged = false;
       if (dragging)
         being_dragged = (modelTrack == *draggingTrackIter);
       
       // Is the track going to be shown?
       if (parent_expanded)
         {
           // Calculate and store the box of the header
           track_height = timeline_track->get_height()
                          + TimelineWidget::TrackPadding;
           const int indent = depth * indent_width;
           
           rect = Gdk::Rectangle(indent                             // x
                                ,branch_offset + child_offset       // y
                                ,max( header_width - indent, 0 )    // width
                                ,track_height);                     // height
           
           // Offset for the next header
           child_offset += track_height;
           
           // Is this header being dragged?
           if (being_dragged)
             rect.set_y(dragPoint.get_y() - dragStartOffset.get_y());
           
           headerBoxes[timeline_track] = rect;
         }
       
       // Is the track animating?
       const bool is_track_animating = timeline_track->is_expand_animating();
       animating |= is_track_animating;
       
       // Recurse to children?
       const bool expand_child = (animating || timeline_track->get_expanded())
                                 && parent_expanded;
       
       int child_branch_height =
           layout_headers_recursive (iterator
                                    ,rect.get_y() + track_height
                                    ,header_width
                                    ,indent_width
                                    ,depth + 1
                                    ,expand_child);
       
       // Do collapse animation as necessary
       if (is_track_animating)
         {
           // Calculate the height of the area which will be
           // shown as expanded
           const float a = timeline_track->get_expand_animation_state();
           child_branch_height *= a * a;
           const int y_limit = branch_offset + child_offset + child_branch_height;
           
           // Obscureed tracks according to the animation state
           TrackTree::pre_order_iterator descendant_iterator(iterator);
           descendant_iterator++;
           TrackTree::sibling_iterator end(iterator);
           end++;
           
           for (descendant_iterator = layoutTree.begin(parent_iterator);
                descendant_iterator != end;
                descendant_iterator++)
             {
               const weak_ptr<timeline::Track> track = lookup_timeline_track(*descendant_iterator);
               const Gdk::Rectangle &rect = headerBoxes[track];
               
               if (rect.get_y() + rect.get_height() > y_limit)
                 headerBoxes.erase(track);
             }
             
           // Tick the track expand animation
           timeline_track->tick_expand_animation();
         }
       
       child_offset += child_branch_height;
     }
     
   return child_offset;
 }
Exemplo n.º 21
0
void
studio::render_color_to_window(const Cairo::RefPtr<Cairo::Context> &cr, const Gdk::Rectangle &ca, const synfig::Color &color)
{
	const int height(ca.get_height());
	const int width(ca.get_width());

	const int square_size(height/2);

	if(color.get_alpha()!=1.0)
	{
		// In this case we need to render the alpha squares

		const Color bg1(
			colorconv_apply_gamma(
				Color::blend(color,Color(0.75, 0.75, 0.75),1.0).clamped() ));
		const Color bg2(
			colorconv_apply_gamma(
				Color::blend(color,Color(0.5, 0.5, 0.5),1.0).clamped() ));

		bool toggle(false);
		for(int i=0;i<width;i+=square_size)
		{
			const int square_width(min(square_size,width-i));

			if(toggle)
			{
		        cr->set_source_rgb(bg1.get_r(), bg1.get_g(), bg1.get_b());
		        cr->rectangle(ca.get_x()+i, ca.get_y(), square_width, square_size);
		        cr->fill();

		        cr->set_source_rgb(bg2.get_r(), bg2.get_g(), bg2.get_b());
		        cr->rectangle(ca.get_x()+i, ca.get_y()+square_size, square_width, square_size);
		        cr->fill();
				toggle=false;
			}
			else
			{
		        cr->set_source_rgb(bg2.get_r(), bg2.get_g(), bg2.get_b());
		        cr->rectangle(ca.get_x()+i, ca.get_y(), square_width, square_size);
		        cr->fill();

		        cr->set_source_rgb(bg1.get_r(), bg1.get_g(), bg1.get_b());
		        cr->rectangle(ca.get_x()+i, ca.get_y()+square_size, square_width, square_size);
		        cr->fill();
				toggle=true;
			}
		}
	}
	else
	{
		synfig::Color c = colorconv_apply_gamma(color);
        cr->set_source_rgb(c.get_r(), c.get_g(), c.get_b());
        cr->rectangle(ca.get_x(), ca.get_y(), width-1, height-1);
        cr->fill();
	}

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

    cr->set_source_rgb(0.0, 0.0, 0.0);
    cr->rectangle(ca.get_x(), ca.get_y(), width-1, height-1);
    cr->stroke();
}
Exemplo n.º 22
0
    //
    // DND Drop handling
    //
  void NoteEditor::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext> & context,
                                         int x, int y,
                                         const Gtk::SelectionData & selection_data,
                                         guint info,  guint time)
  {
    bool has_url = false;

    std::vector<std::string> targets = context->list_targets();
    for(std::vector<std::string>::const_iterator iter = targets.begin();
        iter != targets.end(); ++iter) {
      const std::string & target(*iter);
      if (target == "text/uri-list" ||
          target == "_NETSCAPE_URL") {
        has_url = true;
        break;
      }
    }

    if (has_url) {
      utils::UriList uri_list(selection_data);
      bool more_than_one = false;

      // Place the cursor in the position where the uri was
      // dropped, adjusting x,y by the TextView's VisibleRect.
      Gdk::Rectangle rect;
      get_visible_rect(rect);
      int adjustedX = x + rect.get_x();
      int adjustedY = y + rect.get_y();
      Gtk::TextIter cursor;
      get_iter_at_location (cursor, adjustedX, adjustedY);
      get_buffer()->place_cursor (cursor);

      Glib::RefPtr<Gtk::TextTag> link_tag = get_buffer()->get_tag_table()->lookup ("link:url");

      for(utils::UriList::const_iterator iter = uri_list.begin();
          iter != uri_list.end(); ++iter) {
        const sharp::Uri & uri(*iter);
        DBG_OUT("Got Dropped URI: %s", uri.to_string().c_str());
        std::string insert;
        if (uri.is_file()) {
          // URL-escape the path in case
          // there are spaces (bug #303902)
          insert = sharp::Uri::escape_uri_string(uri.local_path());
        } 
        else {
          insert = uri.to_string ();
        }

        if (insert.empty() || sharp::string_trim(insert).empty())
          continue;

        if (more_than_one) {
          cursor = get_buffer()->get_iter_at_mark (get_buffer()->get_insert());

          // FIXME: The space here is a hack
          // around a bug in the URL Regex which
          // matches across newlines.
          if (cursor.get_line_offset() == 0) {
            get_buffer()->insert (cursor, " \n");
          }
          else {
            get_buffer()->insert (cursor, ", ");
          }
        }

        get_buffer()->insert_with_tag(cursor, insert, link_tag);
        more_than_one = true;
      }

      context->drag_finish(more_than_one, false, time);
    } 
    else {
      Gtk::TextView::on_drag_data_received (context, x, y, selection_data, info, time);
    }
  }
Exemplo n.º 23
0
void
CellRenderer_ValueBase::render_vfunc(
		const Glib::RefPtr<Gdk::Drawable>& window,
		Gtk::Widget& widget,
		const Gdk::Rectangle& background_area,
		const Gdk::Rectangle& ca,
		const Gdk::Rectangle& expose_area,
		Gtk::CellRendererState flags)
{
	if(!window)
		return;
//	const unsigned int cell_xpad = property_xpad();
//	const unsigned int cell_ypad = property_ypad();

	//int x_offset = 0, y_offset = 0;
//	int	width = ca.get_width();
	int	height = ca.get_height();
//	get_size(widget, ca, x_offset, y_offset, width, height);

//	width  -= cell_xpad * 2;
//	height -= cell_ypad * 2;

//	if(width <= 0 || height <= 0)
//		return;

	Gtk::StateType state = Gtk::STATE_INSENSITIVE;
	if(property_editable())
		state = Gtk::STATE_NORMAL;
	if((flags & Gtk::CELL_RENDERER_SELECTED) != 0)
		state = (widget.has_focus()) ? Gtk::STATE_SELECTED : Gtk::STATE_ACTIVE;

	ValueBase data=property_value_.get_value();

	Type &type(data.get_type());
	if (type == type_real)
	{
		if(((synfig::ParamDesc)property_param_desc_).get_is_distance())
		{
			Distance x(data.get(Real()),Distance::SYSTEM_UNITS);
			x.convert(App::distance_system,get_canvas()->rend_desc());
			property_text()=(Glib::ustring)x.get_string(6).c_str();
		}
		else
			property_text()=(Glib::ustring)strprintf("%.6f",data.get(Real()));
	}
	else
	if (type == type_time)
	{
		property_text()=(Glib::ustring)data.get(Time()).get_string(get_canvas()->rend_desc().get_frame_rate(),App::get_time_format());
	}
	else
	if (type == type_angle)
	{
		property_text()=(Glib::ustring)strprintf("%.2fᵒ",(Real)Angle::deg(data.get(Angle())).get());
	}
	else
	if (type == type_integer)
	{
		String param_hint, child_param_hint;
		param_hint=get_param_desc().get_hint();
		child_param_hint=get_child_param_desc().get_hint();
		if(param_hint!="enum" && child_param_hint!="enum")
		{
			property_text()=(Glib::ustring)strprintf("%i",data.get(int()));
		}
		else
		{
			property_text()=(Glib::ustring)strprintf("(%i)",data.get(int()));
			std::list<synfig::ParamDesc::EnumData> enum_list;
			if(param_hint=="enum")
				enum_list=((synfig::ParamDesc)property_param_desc_).get_enum_list();
			else if(child_param_hint=="enum")
				enum_list=((synfig::ParamDesc)property_child_param_desc_).get_enum_list();
			std::list<synfig::ParamDesc::EnumData>::iterator iter;
			for(iter=enum_list.begin();iter!=enum_list.end();iter++)
				if(iter->value==data.get(int()))
				{
					// don't show the key_board s_hortcut under_scores
					String local_name = iter->local_name;
					String::size_type pos = local_name.find_first_of('_');
					if (pos != String::npos)
						property_text() = local_name.substr(0,pos) + local_name.substr(pos+1);
					else
						property_text() = local_name;
					break;
				}
		}
	}
	else
	if (type == type_vector)
	{
		Vector vector=data.get(Vector());
		Distance x(vector[0],Distance::SYSTEM_UNITS),y(vector[1],Distance::SYSTEM_UNITS);
		x.convert(App::distance_system,get_canvas()->rend_desc());
		y.convert(App::distance_system,get_canvas()->rend_desc());
		property_text()=static_cast<Glib::ustring>(strprintf("%s,%s",x.get_string(6).c_str(),y.get_string(6).c_str()));
	}
	else
	if (type == type_transformation)
	{
		const Transformation &transformation=data.get(Transformation());
		const Vector &offset = transformation.offset;
		const Angle::deg angle(transformation.angle);
		const Vector &scale = transformation.scale;
		Distance x(offset[0],Distance::SYSTEM_UNITS),y(offset[1],Distance::SYSTEM_UNITS);
		x.convert(App::distance_system,get_canvas()->rend_desc());
		y.convert(App::distance_system,get_canvas()->rend_desc());
		Distance sx(scale[0],Distance::SYSTEM_UNITS),sy(scale[1],Distance::SYSTEM_UNITS);
		sx.convert(App::distance_system,get_canvas()->rend_desc());
		sy.convert(App::distance_system,get_canvas()->rend_desc());
		property_text()=static_cast<Glib::ustring>(strprintf(
			"%s,%s,%.2fᵒ,%s,%s",
			x.get_string(6).c_str(), y.get_string(6).c_str(),
			(Real)angle.get(),
			sx.get_string(6).c_str(), sy.get_string(6).c_str()
		));
	}
	else
	if (type == type_string)
	{
		if(data.get_type()==type_string)
		{
			if(!data.get(synfig::String()).empty())
				property_text()=static_cast<Glib::ustring>(data.get(synfig::String()));
			else
				property_text()=Glib::ustring("<empty>");
		}
	}
	else
	if (type == type_canvas)
	{
		if(data.get(etl::handle<synfig::Canvas>()))
		{
			if(data.get(etl::handle<synfig::Canvas>())->is_inline())
				property_text()=_("<Group>");
			else
				property_text()=(Glib::ustring)data.get(etl::handle<synfig::Canvas>())->get_id();
		}
		else
			property_text()=_("<No Image Selected>");
	}
	else
	if (type == type_color)
	{
		render_color_to_window(window,ca,data.get(Color()));
		return;
	}
	else
	if (type == type_bool)
	{
		widget.get_style()->paint_check(
			Glib::RefPtr<Gdk::Window>::cast_static(window), state,
			data.get(bool())?Gtk::SHADOW_IN:Gtk::SHADOW_OUT,
			ca, widget, "cellcheck",
			ca.get_x()/* + x_offset + cell_xpad*/,
			ca.get_y()/* + y_offset + cell_ypad*/,
			height-1,height-1);
		return;
	}
	else
	if (type == type_nil)
	{
		//property_text()=(Glib::ustring)" ";
		return;
	}
	else
	if (type == type_gradient)
	{
		render_gradient_to_window(window,ca,data.get(Gradient()));
		return;
	}
	else
	if (type == type_bone_object
	 || type == type_segment
	 || type == type_list
	 || type == type_bline_point
	 || type == type_width_point
	 || type == type_dash_item)
	{
		property_text()=(Glib::ustring)(data.get_type().description.local_name);
	}
	else
	if (type == type_bone_valuenode)
	{
		ValueNode_Bone::Handle bone_node(data.get(ValueNode_Bone::Handle()));
		String name(_("No Parent"));

		if (!bone_node->is_root())
		{
			name = (*(bone_node->get_link("name")))(get_canvas()->get_time()).get(String());
			if (name.empty())
				name = bone_node->get_guid().get_string();
		}

		property_text()=(Glib::ustring)(name);
	}
	else
	{
		property_text()=static_cast<Glib::ustring>(type.description.local_name);
	}

	CellRendererText::render_vfunc(window,widget,background_area,ca,expose_area,flags);
}
Exemplo n.º 24
0
void
CellRenderer_TimeTrack::render_vfunc(
    const Glib::RefPtr<Gdk::Drawable>& window,
    Gtk::Widget& widget,
    const Gdk::Rectangle& /*background_area*/,
    const Gdk::Rectangle& area_,
    const Gdk::Rectangle& /*expose_area*/,
    Gtk::CellRendererState /*flags*/)
{
    if(!window)
        return;

    Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(window));
    Glib::RefPtr<Gdk::GC> inactive_gc(Gdk::GC::create(window));
    Gtk::Adjustment *adjustment=get_adjustment();
    // Gtk::StateType state = Gtk::STATE_ACTIVE;
    // Gtk::ShadowType shadow;

    Gdk::Color
    curr_time_color("#0000ff"),
                    inactive_color("#000000"),
                    keyframe_color("#a07f7f");
    Gdk::Color activepoint_color[2];

    activepoint_color[0]=Gdk::Color("#ff0000");
    activepoint_color[1]=Gdk::Color("#00ff00");

    inactive_gc->set_rgb_fg_color(inactive_color);
    inactive_gc->set_stipple(Gdk::Bitmap::create(stipple_xpm,2,2));
    inactive_gc->set_fill(Gdk::STIPPLED);

    synfig::Canvas::Handle canvas(property_canvas().get_value());

    synfigapp::ValueDesc value_desc = property_value_desc().get_value();
    synfig::ValueNode *base_value = value_desc.get_value_node().get();
    // synfig::ValueNode_Animated *value_node=dynamic_cast<synfig::ValueNode_Animated*>(base_value);

    synfig::ValueNode_DynamicList *parent_value_node(0);
    if(property_value_desc().get_value().parent_is_value_node())
        parent_value_node=dynamic_cast<synfig::ValueNode_DynamicList*>(property_value_desc().get_value().get_parent_value_node().get());

    // If the canvas is defined, then load up the keyframes
    if(canvas)
    {
        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)area_.get_width()/(adjustment->get_upper()-adjustment->get_lower())*(iter->get_time()-adjustment->get_lower())));
            if(iter->get_time()>=adjustment->get_lower() && iter->get_time()<adjustment->get_upper())
            {
                gc->set_rgb_fg_color(keyframe_color);
                window->draw_rectangle(gc, true, area_.get_x()+x, area_.get_y(), 1, area_.get_height()+1);
            }
        }
    }

    //render all the time points that exist
    {
        const synfig::Node::time_set *tset = get_times_from_vdesc(value_desc);

        if(tset)
        {
            const synfig::Time time_offset = get_time_offset_from_vdesc(value_desc);
            synfig::Node::time_set::const_iterator	i = tset->begin(), end = tset->end();

            float 	lower = adjustment->get_lower(),
                    upper = adjustment->get_upper();

            Glib::RefPtr<Gdk::GC>	gc = Gdk::GC::create(widget.get_window());

            Gdk::Rectangle area(area_);
            gc->set_clip_rectangle(area);
            gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);

            bool valselected = sel_value.get_value_node() == base_value && !sel_times.empty();

            float cfps = get_canvas()->rend_desc().get_frame_rate();

            vector<Time>	drawredafter;

            Time diff = actual_time - actual_dragtime;//selected_time-drag_time;
            for(; i != end; ++i)
            {
                //find the coordinate in the drawable space...
                Time t_orig = i->get_time();
                if(!t_orig.is_valid()) continue;
                Time t = t_orig - time_offset;
                if(t<adjustment->get_lower() || t>adjustment->get_upper()) continue;

                //if it found it... (might want to change comparison, and optimize
                //					 sel_times.find to not produce an overall nlogn solution)

                bool selected=false;
                //not dragging... just draw as per normal
                //if move dragging draw offset
                //if copy dragging draw both...

                if(valselected && sel_times.find(t_orig) != sel_times.end())
                {
                    if(dragging) //skip if we're dragging because we'll render it later
                    {
                        if(mode & COPY_MASK) // draw both blue and red moved
                        {
                            drawredafter.push_back(t + diff.round(cfps));
                            gc->set_rgb_fg_color(Gdk::Color("#00EEEE"));
                        } else if(mode & DELETE_MASK) //it's just red...
                        {
                            gc->set_rgb_fg_color(Gdk::Color("#EE0000"));
                            selected=true;
                        } else //move - draw the red on top of the others...
                        {
                            drawredafter.push_back(t + diff.round(cfps));
                            continue;
                        }
                    } else
                    {
                        gc->set_rgb_fg_color(Gdk::Color("#EE0000"));
                        selected=true;
                    }
                } else
                {
                    gc->set_rgb_fg_color(Gdk::Color("#00EEEE"));
                }

                //synfig::info("Displaying time: %.3f s",(float)t);
                const int x = (int)((t-lower)*area.get_width()/(upper-lower));

                //should draw me a grey filled circle...
                Gdk::Rectangle area2(
                    area.get_x() - area.get_height()/2 + x + 1,
                    area.get_y() + 1,
                    area.get_height()-2,
                    area.get_height()-2
                );
                render_time_point_to_window(window,area2,*i - time_offset,selected);

                /*window->draw_arc(gc,true,
                area.get_x() + x - area.get_height()/4,	area.get_y() + area.get_height()/8,
                area.get_height()/2, area.get_height()*3/4,
                0, 64*360);

                gc->set_rgb_fg_color(Gdk::Color("#000000"));
                window->draw_arc(gc,false,
                area.get_x() + x - area.get_height()/4,	area.get_y() + area.get_height()/8,
                area.get_height()/2, area.get_height()*3/4,
                0, 64*360);
                */
            }

            {
                vector<Time>::iterator i = drawredafter.begin(), end = drawredafter.end();
                for(; i != end; ++i)
                {
                    //find the coordinate in the drawable space...
                    Time t = *i;

                    if(!t.is_valid())
                        continue;

                    //synfig::info("Displaying time: %.3f s",(float)t);
                    const int x = (int)((t-lower)*area.get_width()/(upper-lower));

                    //should draw me a grey filled circle...

                    Gdk::Rectangle area2(
                        area.get_x() - area.get_height()/2 + x + 1,
                        area.get_y() + 1,
                        area.get_height()-2,
                        area.get_height()-2
                    );
                    render_time_point_to_window(window,area2,*i,true);
                    /*					gc->set_rgb_fg_color(Gdk::Color("#EE0000"));
                    					window->draw_arc(gc,true,
                    					area.get_x() + x - area.get_height()/4,	area.get_y() + area.get_height()/8,
                    					area.get_height()/2, area.get_height()*3/4,
                    					0, 64*360);

                    					gc->set_rgb_fg_color(Gdk::Color("#000000"));
                    					window->draw_arc(gc,false,
                    					area.get_x() + x - area.get_height()/4,	area.get_y() + area.get_height()/8,
                    					area.get_height()/2, area.get_height()*3/4,
                    					0, 64*360);
                    */
                }
            }
        }
    }

    /* THIS IS NOW HANDLED ENTIRELY BY THE TIMEPOINT SYSTEM
    // This this is an animated value node, then render the waypoints
    if(value_node)
    {
    	//now render the actual waypoints
    	synfig::ValueNode_Animated::WaypointList::iterator iter;
    	for(
    		iter=value_node->waypoint_list().begin();
    		iter!=value_node->waypoint_list().end();
    		iter++
    	)
    	{
    		if(!iter->get_time().is_valid())
    			continue;
    		int x;
    		bool selected=false;
    		if(is_selected(*iter))
    		{
    			Time t(iter->get_time());


    			if(dragging)
    				t=(t+selected_time-drag_time).round(get_canvas()->rend_desc().get_frame_rate());

    			x=(int)((float)area.get_width()/(adjustment->get_upper()-adjustment->get_lower())*(t-adjustment->get_lower()));
    			shadow=Gtk::SHADOW_IN;
    			selected=true;
    		}
    		else
    		{
    			x=(int)((float)area.get_width()/(adjustment->get_upper()-adjustment->get_lower())*(iter->get_time()-adjustment->get_lower()));
    			shadow=Gtk::SHADOW_OUT;
    			selected=false;
    		}


    		widget.get_style()->paint_diamond(
    			Glib::RefPtr<Gdk::Window>::cast_static(window),
    			state,
    			shadow,
    			area,
    			widget,
    			"solid",
    			area.get_x()+x-area.get_height()/4,
    			area.get_y()+area.get_height()/4,
    			area.get_height()/2,
    			area.get_height()/2
    		);
    	}
    }
    */
    Gdk::Rectangle area(area_);
    // If the parent of this value node is a dynamic list, then
    // render the on and off times
    if(parent_value_node)
    {
        const int index(property_value_desc().get_value().get_index());
        const synfig::ValueNode_DynamicList::ListEntry& list_entry(parent_value_node->list[index]);
        const synfig::ValueNode_DynamicList::ListEntry::ActivepointList& activepoint_list(list_entry.timing_info);
        synfig::ValueNode_DynamicList::ListEntry::ActivepointList::const_iterator iter,next;

        bool is_off(false);
        if(!activepoint_list.empty())
            is_off=!activepoint_list.front().state;

        int xstart(0);

        int x=0 /*,prevx=0*/;
        for(next=activepoint_list.begin(),iter=next++; iter!=activepoint_list.end(); iter=next++)
        {
            x=((int)((float)area.get_width()/(adjustment->get_upper()-adjustment->get_lower())*(iter->time-adjustment->get_lower())));
            if(x<0)x=0;
            if(x>area.get_width())x=area.get_width();

            bool status_at_time=0;
            if(next!=activepoint_list.end())
            {
                status_at_time=!list_entry.status_at_time((iter->time+next->time)/2.0);
            }
            else
                status_at_time=!list_entry.status_at_time(Time::end());

            if(!is_off && status_at_time)
            {
                xstart=x;
                is_off=true;
            }
            else if(is_off && !status_at_time)
            {
                window->draw_rectangle(inactive_gc, true, area.get_x()+xstart, area.get_y(), x-xstart, area.get_height());
                is_off=false;
            }

            /*
            if(!is_off && iter!=activepoint_list.end() && next->state==false && iter->state==false)
            {
            	xstart=x;
            	is_off=true;
            }
            else if(is_off && next!=activepoint_list.end() && iter->state==false && next->state==true)
            {
            	window->draw_rectangle(inactive_gc, true, area.get_x()+xstart, area.get_y(), x-xstart, area.get_height());
            	is_off=false;
            }
            else if(is_off && iter!=activepoint_list.end() && iter->state==true)
            {
            	window->draw_rectangle(inactive_gc, true, area.get_x()+xstart, area.get_y(), prevx-xstart, area.get_height());
            	is_off=false;
            }
            */



            if(iter->time>=adjustment->get_lower() && iter->time<adjustment->get_upper())
            {
                int w(1);
                if(selected==*iter)
                    w=3;
                gc->set_rgb_fg_color(activepoint_color[iter->state]);
                window->draw_rectangle(gc, true, area.get_x()+x-w/2, area.get_y(), w, area.get_height());
            }
            //prevx=x;
        }
        if(is_off)
        {
            window->draw_rectangle(inactive_gc, true, area.get_x()+xstart, area.get_y(), area.get_width()-xstart, area.get_height());
        }
    }

    // Render a line that defines the current tick in time
    {
        gc->set_rgb_fg_color(curr_time_color);

        const int x((int)((float)area.get_width()/(adjustment->get_upper()-adjustment->get_lower())*(adjustment->get_value()-adjustment->get_lower())));

        if(adjustment->get_value()>=adjustment->get_lower() && adjustment->get_value()<adjustment->get_upper())
            window->draw_rectangle(gc, true, area.get_x()+x, area.get_y(), 1, area.get_height());
    }
}