示例#1
0
bool
Trainer::on_drawing_press(GdkEventButton * event)
{
	if (event->button == 1)
	{
		cur_char_.new_stroke();
		cur_char_.add_point(event->x, event->y);
		last_x = static_cast<int>(event->x);
		last_y = static_cast<int>(event->y);

		Glib::RefPtr<Gdk::Window> win = drawing_.get_window();
		Glib::RefPtr<Gdk::GC> gc = drawing_.get_style()->get_black_gc();

		// draw a number before each stroke
		Glib::RefPtr<Pango::Layout> num = create_pango_layout(chrasis::toString(++stroke_num));
		int lx, ly;
		num->get_size(lx, ly);
		gc->set_rgb_fg_color(colors[2]);
		win->draw_layout(
			gc,
			static_cast<int>(event->x - lx / Pango::SCALE - 5),
			static_cast<int>(event->y - ly / Pango::SCALE - 5),
			num
		);

		// draw a dot
		gc->set_rgb_fg_color(colors[0]);
		win->draw_arc( gc, true,
			static_cast<int>(event->x) - 3,
			static_cast<int>(event->y) - 3,
			5, 5, 0, 23040);
	}

	return false;
}
示例#2
0
void
Trainer::draw_character()
{
	Glib::RefPtr<Gdk::Window> win = drawing_.get_window();
	Glib::RefPtr<Gdk::GC> gc = drawing_.get_style()->get_black_gc();

	stroke_num = 0;
	for (chrasis::Stroke::iterator si = cur_char_.strokes_begin();
	     si != cur_char_.strokes_end();
	     ++si)
	{
		// draw the stroke body
		gc->set_rgb_fg_color(colors[2]);
		for (chrasis::Point::iterator pi = si->points_begin();
		     pi != si->points_end() - 1;
		     ++pi)
		{
			win->draw_line( gc,
				static_cast<int>(pi->x()),
				static_cast<int>(pi->y()),
				static_cast<int>((pi+1)->x()),
				static_cast<int>((pi+1)->y())
			);
		}

		// draw a number before each stroke
		stringstream ss;
		ss << ++stroke_num;
		Glib::RefPtr<Pango::Layout> num = create_pango_layout(ss.str());
		int lx, ly;
		num->get_size(lx, ly);
		win->draw_layout(
			gc,
			static_cast<int>(si->points_begin()->x() - lx / Pango::SCALE - 5),
			static_cast<int>(si->points_begin()->y() - ly / Pango::SCALE - 5),
			num
		);

		// enchant the beginning and ending points
		chrasis::Point::iterator pi[2] =
			{ si->points_begin(), si->points_end() - 1 };

		for (int i=0;i<2;++i)
		{
			gc->set_rgb_fg_color(colors[i]);
			win->draw_arc( gc, true,
				static_cast<int>(pi[i]->x() - 3),
				static_cast<int>(pi[i]->y() - 3),
				5, 5, 0, 23040);
		}
	}
}
示例#3
0
bool Creater::on_drawing_press(GdkEventButton * event)
{
	if (event->button == 1)
	{
		if (cur_chars_.size() == 0)
		{
			this->on_popup_new();

			return false;
		}

		cur_char_->new_stroke();

		cur_char_->add_point(event->x, event->y);

		Glib::RefPtr<Gdk::Window> win = drawing_.get_window();
		Glib::RefPtr<Gdk::GC> gc = drawing_.get_style()->get_black_gc();

		// draw a number before each stroke
		Glib::RefPtr<Pango::Layout> num =
			create_pango_layout(boost::lexical_cast<std::string>(++stroke_num));
		int lx, ly;
		num->get_size(lx, ly);
		gc->set_rgb_fg_color(colors[2]);
		win->draw_layout(
			gc,
			event->x - lx / Pango::SCALE - 5,
			event->y - ly / Pango::SCALE - 5,
			num
		);

		// draw a dot
		gc->set_rgb_fg_color(colors[0]);
		win->draw_arc( gc, true,
			event->x - 3,
			event->y - 3,
			5, 5, 0, 23040);

		last_x = event->x;
		last_y = event->y;
	}

	return false;
}
示例#4
0
bool Creater::on_drawing_release(GdkEventButton * event)
{
	if (event->button == 1)
	{
		if (cur_chars_.size() == 0)
			return false;

		// do not process redundent points
		if (event->x != last_x || event->y != last_y)
			cur_char_->add_point(event->x, event->y);

		Glib::RefPtr<Gdk::Window> win = drawing_.get_window();
		Glib::RefPtr<Gdk::GC> gc = drawing_.get_style()->get_black_gc();

		// draw a dot
		gc->set_rgb_fg_color(colors[1]);
		win->draw_arc( gc, true,
			event->x - 3, event->y - 3,
			5, 5, 0, 23040);
	}

	return false;
}
示例#5
0
bool
Trainer::on_drawing_release(GdkEventButton * event)
{
	if (event->button == 1)
	{
		// do not process redundent points
		if (event->x != last_x || event->y != last_y)
			cur_char_.add_point(event->x, event->y);

		Glib::RefPtr<Gdk::Window> win = drawing_.get_window();
		Glib::RefPtr<Gdk::GC> gc = drawing_.get_style()->get_black_gc();

		// draw a dot
		gc->set_rgb_fg_color(colors[1]);
		win->draw_arc( gc, true,
			static_cast<int>(event->x) - 3,
			static_cast<int>(event->y) - 3,
			5, 5, 0, 23040);

		update_candidate_list();
	}
	return false;
}
示例#6
0
void Creater::draw_character()
{
	if (cur_chars_.size() == 0)
		return;

	Glib::RefPtr<Gdk::Window> win = drawing_.get_window();
	Glib::RefPtr<Gdk::GC> gc = drawing_.get_style()->get_black_gc();

	stroke_num = 0;
	for (Stroke::iterator si = cur_char_->strokes_begin();
	     si != cur_char_->strokes_end();
	     ++si)
	{
		// draw the stroke body
		gc->set_rgb_fg_color(colors[2]);
		for (Point::iterator pi = si->points_begin();
		     pi != si->points_end() - 1;
		     ++pi)
		{
			win->draw_line( gc,
				pi->x(), pi->y(),
				(pi+1)->x(), (pi+1)->y());
		}

		// draw a number before each stroke
		stringstream ss;
		ss << ++stroke_num;
		Glib::RefPtr<Pango::Layout> num = create_pango_layout(ss.str());
		int lx, ly;
		num->get_size(lx, ly);
		win->draw_layout(
			gc,
			si->points_begin()->x() - lx / Pango::SCALE - 5,
			si->points_begin()->y() - ly / Pango::SCALE - 5,
			num
		);

		// enchant the beginning and ending points
		Point::iterator pi[2] =
			{ si->points_begin(), si->points_end() - 1 };

		for (int i=0;i<2;++i)
		{
			gc->set_rgb_fg_color(colors[i]);
			win->draw_arc( gc, true,
				pi[i]->x() - 3, pi[i]->y() - 3,
				5, 5, 0, 23040);
		}
	}

	// get the recognizer instance
	Recognizer & rec = Recognizer::Instance();

	stroke_num = 0;
	// draw the normalized version
	int scale = 100;
	Character nc = rec.normalize( *cur_char_ );
	for (Stroke::iterator si = nc.strokes_begin();
	     si != nc.strokes_end();
	     ++si)
	{
		gc->set_rgb_fg_color(colors[3]);
		for (Point::iterator pi = si->points_begin();
		     pi != si->points_end() - 1;
		     ++pi)
		{
			win->draw_line( gc,
				pi->x() * scale, pi->y() * scale,
				(pi+1)->x() * scale, (pi+1)->y() * scale);
			win->draw_arc( gc, true,
				pi->x() * scale - 3, pi->y() * scale - 3,
				5, 5, 0, 23040);
		}

		// draw a number before each stroke
		Glib::RefPtr<Pango::Layout> num =
			create_pango_layout(boost::lexical_cast<std::string>(++stroke_num));
		int lx, ly;
		num->get_size(lx, ly);
		win->draw_layout(
			gc,
			si->points_begin()->x() * scale - lx / Pango::SCALE - 5,
			si->points_begin()->y() * scale - ly / Pango::SCALE - 5,
			num
		);

		// enchant the beginning and ending points
		Point::iterator pi[2] =
			{ si->points_begin(), si->points_end() - 1 };

		for (int i=0;i<2;++i)
		{
			gc->set_rgb_fg_color(colors[i]);
			win->draw_arc( gc, true,
				pi[i]->x() * scale - 3, pi[i]->y() * scale - 3,
				5, 5, 0, 23040);
		}
	}

}
示例#7
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;
	}

}