Dash drawing working

presentation
Andreas Butti 7 years ago
parent 87b3e8687a
commit f8a99f6895
  1. 3
      src/control/tools/StrokeHandler.cpp
  2. 13
      src/model/Stroke.cpp
  3. 1
      src/model/Stroke.h
  4. 17
      src/view/StrokeView.cpp
  5. 2
      src/view/StrokeView.h

@ -159,11 +159,12 @@ void StrokeHandler::onButtonReleaseEvent(const PositionInputData& pos)
}
}
if (stroke->getFill() != -1)
if (stroke->getFill() != -1 || stroke->hasDashes())
{
// The stroke is not filled on drawing time
// If the stroke has fill values, it needs to be re-rendered
// else the fill will not be visible.
// The same for dashes
view.drawStroke(crMask, stroke, 0, 1, true, true);
}

@ -212,12 +212,25 @@ double Stroke::getWidth() const
*/
bool Stroke::getDashes(const double*& dashes, int& dashCount)
{
XOJ_CHECK_TYPE(Stroke);
dashes = this->dashes;
dashCount = this->dashCount;
return this->dashCount > 0;
}
/**
* Get dash array and count
*
* @return true if dashed
*/
bool Stroke::hasDashes()
{
XOJ_CHECK_TYPE(Stroke);
return this->dashCount > 0;
}
bool Stroke::isInSelection(ShapeContainer* container)
{
XOJ_CHECK_TYPE(Stroke);

@ -87,6 +87,7 @@ public:
* @return true if dashed
*/
bool getDashes(const double*& dashes, int& dashCount);
bool hasDashes();
bool intersects(double x, double y, double halfSize, double* gap = NULL);

@ -40,7 +40,7 @@ void StrokeView::drawFillStroke()
cairo_fill(cr);
}
void StrokeView::applyDashed(cairo_t* cr, Stroke* s, double offset)
void StrokeView::applyDashed(double offset)
{
const double* dashes = NULL;
int dashCount = 0;
@ -48,6 +48,11 @@ void StrokeView::applyDashed(cairo_t* cr, Stroke* s, double offset)
{
cairo_set_dash(cr, dashes, dashCount, offset);
}
else
{
// Disable dash
cairo_set_dash(cr, NULL, 0, 0);
}
}
void StrokeView::drawEraseableStroke(cairo_t* cr, Stroke* s)
@ -113,7 +118,9 @@ void StrokeView::drawNoPressure()
// Set width
cairo_set_line_width(cr, width * scaleFactor);
//applyDashed(cr, s);
applyDashed(0);
Point lastPoint = points.get();
while (points.hasNext())
{
@ -129,6 +136,7 @@ void StrokeView::drawNoPressure()
}
count++;
lastPoint = p;
}
cairo_stroke(cr);
@ -161,7 +169,7 @@ void StrokeView::drawWithPressuire()
ArrayIterator<Point> points = s->pointIterator();
Point lastPoint1 = points.next();
double dashOffset = 0;
while (points.hasNext())
{
Point p = points.next();
@ -174,12 +182,15 @@ void StrokeView::drawWithPressuire()
// Set width
cairo_set_line_width(cr, width * scaleFactor);
applyDashed(dashOffset);
cairo_move_to(cr, lastPoint1.x, lastPoint1.y);
cairo_line_to(cr, p.x, p.y);
cairo_stroke(cr);
}
count++;
dashOffset += lastPoint1.lineLengthTo(p);
lastPoint1 = p;
}

@ -32,7 +32,7 @@ public:
private:
void drawFillStroke();
void applyDashed(cairo_t* cr, Stroke* s, double offset);
void applyDashed(double offset);
void drawEraseableStroke(cairo_t* cr, Stroke* s);
/**

Loading…
Cancel
Save