Пример #1
0
void CReadXML::parseXML(TiXmlDocument* document){
    TiXmlElement* rootElement = document->RootElement();
	const char* name = rootElement->Attribute("name");
	character.setName(name);
	const char* seq = rootElement->Attribute("stroke_seq_id");
	character.setStrokeSeq(seq);
    TiXmlElement* outlineElement = rootElement->FirstChildElement();
    TiXmlElement* strokeElement = outlineElement->FirstChildElement();
    Bujian bujian;
    for (strokeElement;strokeElement;strokeElement = strokeElement->NextSiblingElement())
    {
        TiXmlElement* trunpoint = strokeElement->FirstChildElement();
        Stroke stroke;
        for (trunpoint;trunpoint;trunpoint = trunpoint->NextSiblingElement())
        {
            const char* x = trunpoint->Attribute("x");
            const char* y = trunpoint->Attribute("y");
            const char* statusPoint = trunpoint->Attribute("status");
            stroke.addStatus(statusPoint);
            stroke.addPoint(ccp(atof(x),atof(y)));
        }
        bujian.addStroke(stroke);
    }
    character.addBujian(bujian);
}
Пример #2
0
void StrokeGroup::AppendStrk2Char(Stroke strk1,int mode)
{
    try
	{
  if(nstrokes==0)
  {
        strklist.clear();
        strk1.ChangeStrkCoords(origin,mode);
        strklist.push_back(strk1);
        nstrokes++;
        return;
  }
  else
  {
        strk1.ChangeStrkCoords(origin,mode);
        AddStrk2SG(strk1);
  }
    }
    catch(exception& e)
    {
        string str="StrokeGroup:Exception in AppendStrk2Char: ";
        str.append(e.what());
        logwrite(str);
    }
}
Пример #3
0
void set_join_caps(Stroke const& stroke_, PathType & stroke)
{
    line_join_e join=stroke_.get_line_join();
    switch (join)
    {
    case MITER_JOIN:
        stroke.generator().line_join(agg::miter_join);
        break;
    case MITER_REVERT_JOIN:
        stroke.generator().line_join(agg::miter_join);
        break;
    case ROUND_JOIN:
        stroke.generator().line_join(agg::round_join);
        break;
    default:
        stroke.generator().line_join(agg::bevel_join);
    }

    line_cap_e cap=stroke_.get_line_cap();
    switch (cap)
    {
    case BUTT_CAP:
        stroke.generator().line_cap(agg::butt_cap);
        break;
    case SQUARE_CAP:
        stroke.generator().line_cap(agg::square_cap);
        break;
    default:
        stroke.generator().line_cap(agg::round_cap);
    }
}
Пример #4
0
void set_join_caps_aa(Stroke const& stroke_, Rasterizer & ras)
{

    line_join_e join=stroke_.get_line_join();
    switch (join)
    {
    case MITER_JOIN:
        ras.line_join(agg::outline_miter_accurate_join);
        break;
    case MITER_REVERT_JOIN:
        ras.line_join(agg::outline_no_join);
        break;
    case ROUND_JOIN:
        ras.line_join(agg::outline_round_join);
        break;
    default:
        ras.line_join(agg::outline_no_join);
    }

    line_cap_e cap=stroke_.get_line_cap();
    switch (cap)
    {
    case BUTT_CAP:
        ras.round_cap(false);
        break;
    case SQUARE_CAP:
        ras.round_cap(false);
        break;
    default:
        ras.round_cap(true);
    }
}
Пример #5
0
Omitter::Omitter(Stroke &ioStroke) : Smoother(ioStroke)
{
	StrokeInternal::StrokeVertexIterator v, vend;
	int i = 0;
	for (v = ioStroke.strokeVerticesBegin(), vend = ioStroke.strokeVerticesEnd(); v != vend; ++v, ++i) {
		_u[i] = (v)->curvilinearAbscissa();
	}
}
Пример #6
0
string TcharacterDrawnode::getCharacterStandardInfo(){
	string ret = "";
	int cout = myChar.getStrokeCount();
	for (int i = 1 ; i <= cout ; i++)
	{
		Stroke stroke = myChar.getStroke(i);
		ret += stroke.sendOutputWithStatus();
	}
	return ret;
}
Пример #7
0
void Strokes::paint(QPainter *p, const QPoint &drift)
{
    for (Stroke *stroke = strokes.first(); (stroke = strokes.current()); strokes.next())
    {
        stroke->paint(p, drift);
    }

    if (currentStroke)
        currentStroke->paint(p, drift);
}
Пример #8
0
void menuSelect(int value)
{
  switch(value)
    {
    case 0:
      curve.curveType = CUBIC_BSPLINE;
      curve.forceRecompute();
      glutPostRedisplay();
      break;

    case 1:
      curve.curveType = FOUR_POINT;
      curve.forceRecompute();
      glutPostRedisplay();
      break;

    case 2:
      controlPolygon = !controlPolygon;
      glutPostRedisplay();
      break;
      
    case 3:
      opaque = !opaque;
      glutPostRedisplay();
      break;

    case 4:
      curve.radius += 5;
      glutPostRedisplay();
      break;

    case 5:
      curve.radius -= 5;
      if (curve.radius < 1)
	curve.radius = 1;
      glutPostRedisplay();
      break;

    case 8:
      exit(0);

    //////////////////////// tapering ///////////////////////////
    case 6:
      curve.taperBrush = !curve.taperBrush;
      glutPostRedisplay();
      break;
    //////////////////////// tapering ///////////////////////////

    case 7:
      curve.useTexture = !curve.useTexture;
      glutPostRedisplay();
      break;
    }
}
Пример #9
0
void TipRemoverShader::shade(Stroke &ioStroke) const
{
	StrokeInternal::StrokeVertexIterator v, vend;
	for (v = ioStroke.strokeVerticesBegin(), vend = ioStroke.strokeVerticesEnd(); v != vend; ++v) {
		if (((*v)->curvilinearAbscissa() < _tipLength) ||
		    (((*v)->strokeLength() - (*v)->curvilinearAbscissa()) < _tipLength)) {
			(*v)->attribute().setThickness(0.0, 0.0);
			(*v)->attribute().setColor(1, 1, 1);
		}
	}
}
Пример #10
0
Stroke* Scene::newStroke( const Path& p, int colour, int attribs ) {
  Stroke *s = new Stroke(p);
  s->setAttribute( (Attribute)attribs );

  switch ( colour ) {
  case 0: s->setAttribute( ATTRIB_TOKEN ); break;
  case 1: s->setAttribute( ATTRIB_GOAL ); break;
  default: s->setColour( brushColours[colour] ); break;
  }
  m_strokes.append( s );
  m_recorder.newStroke( p, colour, attribs );
  return s;
}
Пример #11
0
QString Strokes::serialize()
{
    QString r;
    uint i = 0;

    for (Stroke *stroke = strokes.first(); (stroke = strokes.current()); strokes.next(), i++)
    {
        QString p;

        r += p.sprintf("stroke%d=\"", i) + stroke->serialize() + "\"\n";
    }

    return r;
}
Пример #12
0
void PageView::selectObjectAt(double x, double y) {
	XOJ_CHECK_TYPE(PageView);

	int selected = this->page.getSelectedLayerId();
	GdkRectangle matchRect = { x - 10, y - 10, 20, 20 };

	Stroke * strokeMatch = NULL;
	double gap = 1000000000;

	Element * elementMatch = NULL;

	// clear old selection anyway
	this->xournal->getControl()->clearSelection();

	ListIterator<Layer*> it = this->page.layerIterator();
	while (it.hasNext() && selected) {
		Layer * l = it.next();

		ListIterator<Element *> eit = l->elementIterator();
		while (eit.hasNext()) {
			Element * e = eit.next();
			if (e->intersectsArea(&matchRect)) {
				if (e->getType() == ELEMENT_STROKE) {
					Stroke * s = (Stroke *) e;
					double tmpGap = 0;
					if (s->intersects(x, y, 5, &tmpGap)) {
						if (gap > tmpGap) {
							gap = tmpGap;
							strokeMatch = s;
						}
					}
				} else {
					elementMatch = e;
				}
			}
		}

		selected--;
	}

	if (strokeMatch) {
		elementMatch = strokeMatch;
	}

	if (elementMatch) {
		xournal->setSelection(new EditSelection(xournal->getControl()->getUndoRedoHandler(), elementMatch, this, page));

		repaintPage();
	}
}
Пример #13
0
Strokes::Strokes(Strokes &strks)
{
    strokes.clear();
    for (Stroke *stroke = strks.first(); (stroke = strks.current()); strks.next())
    {
        QString d = stroke->serialize();
        addStroke(stroke->serialize());
    }

	maxX = strks.getMaxX();
	maxY = strks.getMaxY();

    currentStroke = 0;
}
Пример #14
0
int CalligraphicShader::shade(Stroke &ioStroke) const
{
  Interface0DIterator v;
  Functions0D::VertexOrientation2DF0D fun;
  StrokeVertex *sv;
  for (v = ioStroke.verticesBegin(); !v.isEnd(); ++v) {
    real thickness;
    if (fun(v) < 0)
      return -1;

    Vec2f vertexOri(fun.result);
    Vec2r ori2d(-vertexOri[1], vertexOri[0]);
    ori2d.normalizeSafe();
    real scal = ori2d * _orientation;
    sv = dynamic_cast<StrokeVertex *>(&(*v));
    if (_clamp && (scal < 0)) {
      scal = 0.0;
      sv->attribute().setColor(1, 1, 1);
    }
    else {
      scal = fabs(scal);
      sv->attribute().setColor(0, 0, 0);
    }
    thickness = _minThickness + scal * (_maxThickness - _minThickness);
    if (thickness < 0.0)
      thickness = 0.0;
    sv->attribute().setThickness(thickness / 2.0, thickness / 2.0);
  }

  return 0;
}
Пример #15
0
void
ServerConnection::send_stroke(const Stroke& stroke, DrawingParameter* param)
{
    const Stroke::Dabs& dabs = stroke.get_dabs();

    std::stringstream str;
    if (param->get_brush().empty())
        str << "set_generic_brush "
            << param->generic_brush.shape << " "
            << param->generic_brush.radius << " "
            << param->generic_brush.spikes << " "
            << param->generic_brush.hardness << " "
            << param->generic_brush.aspect_ratio << " "
            << param->generic_brush.angle << " "
            << std::endl;
    else
        str << "set_brush " << param->get_brush() << std::endl;
    str << "set_tool " << param->tool << std::endl;
    str << "set_opacity " << int(param->opacity) << std::endl;
    str << "set_color "
        << int(param->color.r) << " "
        << int(param->color.g) << " "
        << int(param->color.b) << std::endl;
    str << "stroke_begin" << std::endl;
    for(Stroke::Dabs::const_iterator i = dabs.begin(); i != dabs.end(); ++i)
    {
        str << "dab " << i->time << " " << i->pos.x << " " << i->pos.y << " " << i->pressure << std::endl;
    }
    str << "stroke_end" << std::endl;

    send(str.str());
}
Пример #16
0
int SpatialNoiseShader::shade(Stroke &ioStroke) const
{
  Interface0DIterator v, v2;
  v = ioStroke.verticesBegin();
  Vec2r p(v->getProjectedX(), v->getProjectedY());
  v2 = v;
  ++v2;
  Vec2r p0(v2->getProjectedX(), v2->getProjectedY());
  p0 = p + 2 * (p - p0);
  StrokeVertex *sv;
  sv = dynamic_cast<StrokeVertex *>(&(*v));
  real initU = sv->strokeLength() * real(NB_VALUE_NOISE);
  if (_pureRandom)
    initU += RandGen::drand48() * real(NB_VALUE_NOISE);

  Functions0D::VertexOrientation2DF0D fun;
  while (!v.isEnd()) {
    sv = dynamic_cast<StrokeVertex *>(&(*v));
    Vec2r p(sv->getPoint());
    if (fun(v) < 0)
      return -1;
    Vec2r vertexOri(fun.result);
    Vec2r ori2d(vertexOri[0], vertexOri[1]);
    ori2d = Vec2r(p - p0);
    ori2d.normalizeSafe();

    PseudoNoise mynoise;
    real bruit;

    if (_smooth)
      bruit = mynoise.turbulenceSmooth(_xScale * sv->curvilinearAbscissa() + initU, _nbOctave);
    else
      bruit = mynoise.turbulenceLinear(_xScale * sv->curvilinearAbscissa() + initU, _nbOctave);

    Vec2r noise(-ori2d[1] * _amount * bruit, ori2d[0] * _amount * bruit);

    sv->setPoint(p[0] + noise[0], p[1] + noise[1]);
    p0 = p;

    ++v;
  }

  ioStroke.UpdateLength();

  return 0;
}
Пример #17
0
void QSketch::setStrokes(Strokes *strokes1)
{
    if (strokes && !externalStrokes)
        delete strokes;

    // colors used in the strokes put into choosedColors dialog
    for (Stroke *stroke = strokes1->first(); (stroke = strokes1->current()); strokes1->next())
    {
        QColor strokeColor = stroke->getColor();
        bool colorIn = false;
        for(QColor *color = choosedColors.first(); (color = choosedColors.current()); choosedColors.next())
        {
            if (*color == strokeColor)
            {
                colorIn = true;
                break;
            }
        }

        if (!colorIn)
        {
            choosedColors.append(new QColor(strokeColor));
        }
    }

    strokes = strokes1;
    externalStrokes = true;

	viewP = QPoint(0, 0);

	// rebuild cache
	if (moveMode)
	{
		if (viewCache)
			delete viewCache;
		if(sketchCache)
			delete sketchCache;
		viewCache = sketchCache = 0;

		updateViewCache();
		update();
	}

    modified = true;
}
Пример #18
0
void TextStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const{
  Stroke *stroke = iStrokeRep->getStroke();
  if(!stroke){
    cerr << "no stroke associated with Rep" << endl;
    return;
  }
    
  StrokeInternal::StrokeVertexIterator v = stroke->strokeVerticesBegin();
  StrokeAttribute att;
  while(!v.isEnd()){
    att = v->attribute();
    _ofstream << v->u() << " " << (double) v->getProjectedX() << " " << (double) v->getProjectedY() << " " << (double) v->getProjectedZ() << " " \
      << att.getThicknessL() << " " << att.getThicknessR() << " " \
      << att.getColorR() << " " << att.getColorG() << " " << att.getColorB() << " ";
    ++v;
  }
  _ofstream << endl;
}
Пример #19
0
void Button(int button, int state, int x, int y)
{
  if (state != GLUT_UP)	
    return;

  switch (button) 
    {
    case GLUT_LEFT_BUTTON:
      curve.add(x,windowHeight-y);
      glutPostRedisplay();
      break;

    case GLUT_RIGHT_BUTTON:
      curve.clear();
      glutPostRedisplay();
      break;
    }
}
Пример #20
0
Smoother::Smoother(Stroke &ioStroke)
{
	_stroke = &ioStroke;

	_nbVertices = ioStroke.vertices_size();
	_vertex = new Vec2r[_nbVertices];
	_curvature = new real[_nbVertices];
	_normal = new Vec2r[_nbVertices];
	StrokeInternal::StrokeVertexIterator v, vend;
	int i = 0;
	for (v = ioStroke.strokeVerticesBegin(), vend = ioStroke.strokeVerticesEnd(); v != vend; ++v, ++i) {
		_vertex[i] = (v)->getPoint();
	}
	Vec2r vec_tmp(_vertex[0] - _vertex[_nbVertices - 1]);
	_isClosedCurve = (vec_tmp.norm() < M_EPSILON);

	_safeTest = (_nbVertices > 4);
}
Пример #21
0
StrokeGroup::StrokeGroup(double argorigin[])
{
    try
	{
  label="none";
  nstrokes = 0;
  origin[0]=argorigin[0];
  origin[1]=argorigin[1];
  Stroke emptystrk;
  emptystrk.RandStrk(0);
  strklist.push_back(emptystrk);
    }
    catch(exception& e)
    {
        string str="StrokeGroup:Exception in constructor1: ";
        str.append(e.what());
        logwrite(str);
    }
}
Пример #22
0
/**
 * Create circle stroke for inertia
 */
Stroke* CircleRecognizer::makeCircleShape(Stroke* originalStroke, Inertia& inertia)
{
	int npts = (int) (2 * inertia.rad());
	if (npts < 12)
	{
		npts = 12; // min. number of points
	}

	Stroke* s = new Stroke();
	s->applyStyleFrom(originalStroke);

	for (int i = 0; i <= npts; i++)
	{
		double x = inertia.centerX() + inertia.rad() * cos((2 * M_PI * i) / npts);
		double y = inertia.centerY() + inertia.rad() * sin((2 * M_PI * i) / npts);
		s->addPoint(Point(x, y));
	}

	return s;
}
Пример #23
0
void XournalView::setSelection(EditSelection* selection)
{
	XOJ_CHECK_TYPE(XournalView);

	clearSelection();
	GTK_XOURNAL(this->widget)->selection = selection;

	control->setClipboardHandlerSelection(getSelection());

	bool canChangeSize = false;
	bool canChangeColor = false;

	ListIterator<Element*> it = selection->getElements();

	while (it.hasNext())
	{
		Element* e = it.next();
		if (e->getType() == ELEMENT_TEXT)
		{
			canChangeColor = true;
		}
		else if (e->getType() == ELEMENT_STROKE)
		{
			Stroke* s = (Stroke*) e;
			if (s->getToolType() != STROKE_TOOL_ERASER)
			{
				canChangeColor = true;
			}
			canChangeSize = true;
		}

		if (canChangeColor && canChangeSize)
		{
			break;
		}
	}

	control->getToolHandler()->setSelectionEditTools(canChangeColor, canChangeSize);

	repaintSelection();
}
Пример #24
0
void Redraw(void)
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    //    curve.drawTexture();

    if (opaque)
      glColor3ub(0, 64, 16);
    else
      glColor4ub(0, 64, 16, 128);
    curve.render();

    if (controlPolygon)
      {
	glColor3ub(255,0,0);
	curve.drawControl();
      }

    glutSwapBuffers();
    
    checkForError("swap");
}
Пример #25
0
/// Mouse press function
void mouseclick(int button, int state, int x, int y) {

	xini = x; yini = winh - y;
	if (state == GLUT_DOWN) {
		buttonpressed = button;
		if (buttonpressed == GLUT_MIDDLE_BUTTON) {
			arcball.click(xini, yini);
		}
		else if (buttonpressed == GLUT_RIGHT_BUTTON) {
			screenToWorld(x, winh - y, xwini, ywini, zwini);
		}
		else if (buttonpressed == GLUT_LEFT_BUTTON) {
			stroke.clear();
			screenToWorld(x, winh - y, xwini, ywini, zwini);
			grabStart = Point3(xwini, ywini, zwini);
			grabLast = grabStart;
		}
		sceneIniT = sceneT;
	}
	else if (state == GLUT_UP) {
		if (buttonpressed == GLUT_LEFT_BUTTON)
			if (stroke.size() > 3) {
			stroke.subsampleStroke();

			Point2 bbMin = stroke.getBBmin();
			Point2 bbMax = stroke.getBBmax();
			screenToWorld(bbMin[0], bbMin[1], xwini, ywini, zwini);
			Point3 bbmin(xwini, ywini, 0.0);
			screenToWorld(bbMax[0], bbMax[1], xwini, ywini, zwini);
			Point3 bbmax(xwini, ywini, 0.0);

			//if (mycloth != 0) delete mycloth;
			//mycloth = new Cloth("mesh1.off");
			//mycloth = new Cloth;
			//mycloth->intersect(stroke);
			}
	}
	glutPostRedisplay();
}
Пример #26
0
Stroke::Stroke(const Stroke& ref_stroke, CBBOXpix& ref_bbox, CBBOXpix& target_bbox)
  : _gesture (0),
    _id(ref_stroke.id()), _bbox(target_bbox){

  // first compute the transformed pixels list
  const PIXEL_list& ref_pixels = ref_stroke.pts();
  int nb_ref_pixels = ref_pixels.num();
  if (nb_ref_pixels == 0){
    return;
  }

  PIXEL_list target_pixels;
  ref_to_target(ref_bbox, ref_pixels, target_bbox, target_pixels);


  // then build new gesture
  CARRAY<double>& ref_pressures = ref_stroke.gesture()->pressures();
  _gesture = new GESTURE(0, 0, target_pixels[0], ref_pressures[0]);
  for (int i=1 ; i<nb_ref_pixels ; i++){
    _gesture->add(target_pixels[i], -1.0, ref_pressures[i]);
  }

}
Пример #27
0
void Strokes::addStroke(const QString &serialData)
{
    Stroke *stroke = new Stroke();

    stroke->unserialize(serialData);
    strokes.append(stroke);

	if (stroke->getMaxX() > maxX)
		maxX = stroke->getMaxX();
	if (stroke->getMaxY() > maxY)
		maxY = stroke->getMaxY();
	
}
Пример #28
0
/// Mouse move function
void mousemove(int x, int y) {

	if (buttonpressed == GLUT_MIDDLE_BUTTON) { // rotations handler
		AMatrix<float> mT;
		arcball.drag(x, winh - y, &mT);
		sceneT = mT*sceneIniT;
	}
	else if (buttonpressed == GLUT_RIGHT_BUTTON) { // translations handler
		double xw, yw, zw;
		screenToWorld(x, winh - y, xw, yw, zw);
		AMatrix<float> mT;
		mT.identity();
		mT.translation(xw - xwini, yw - ywini, zw - zwini);
		sceneT = mT*sceneIniT;
	}
	else if (buttonpressed == GLUT_LEFT_BUTTON) {
		Point2 p(x, winh - y);
		stroke.push_back(p);
	}
	glutPostRedisplay();
}
Пример #29
0
void
DrawingContext::draw_stroke(const Stroke& stroke, DrawingParameter* param)
{
  Rect rect = stroke.get_bounding_rect();

  rect.left -= param->thickness()/2;
  rect.top  -= param->thickness()/2;

  rect.right  += param->thickness()/2;
  rect.bottom += param->thickness()/2;

  clip_to(rect, Rect(0, 0, get_width(), get_height()));

  stroke_buffer->clear(rect);
  stroke_buffer->set_param(param);
  stroke_buffer->draw_stroke(stroke, param);
  stroke_buffer->draw(drawable, rect, 0, 0);

  screen_buffer->mark_dirty(rect);

  // FIXME: Limit this to what changed on the buffer instead of whole screen
  navigation->update();
}
Пример #30
0
GList * EraseableStroke::getStroke(Stroke * original) {
	XOJ_CHECK_TYPE(EraseableStroke);

	GList * list = NULL;

	Stroke * s = NULL;
	Point lastPoint(NAN, NAN);
	for (GList * l = this->parts->data; l != NULL; l = l->next) {
		EraseableStrokePart * p = (EraseableStrokePart *) l->data;
		GList * points = p->getPoints();
		if (g_list_length(points) < 2) {
			continue;
		}

		Point a = *((Point *) g_list_first(points)->data);
		Point b = *((Point *) g_list_last(points)->data);
		a.z = p->width;

		if (!lastPoint.equalsPos(a) || s == NULL) {
			if (s) {
				s->addPoint(lastPoint);
			}
			s = new Stroke();
			s->setColor(original->getColor());
			s->setToolType(original->getToolType());
			s->setWidth(original->getWidth());
			list = g_list_append(list, s);
		}
		s->addPoint(a);
		lastPoint = b;
	}
	if (s) {
		s->addPoint(lastPoint);
	}

	return list;
}