Skip to content

Commit

Permalink
Revert "api: enhance Shape::stroke() method usage."
Browse files Browse the repository at this point in the history
This reverts commit 6cbc1de.
Setting def value for 'a' makes it impossible to overload
the 'stroke' api with 3 values (needed for introducing dash offset).
  • Loading branch information
mgrudzinska committed Aug 18, 2023
1 parent f573e13 commit 86e8b13
Show file tree
Hide file tree
Showing 47 changed files with 219 additions and 214 deletions.
9 changes: 4 additions & 5 deletions inc/thorvg.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ class TVG_API Paint
*
* @note The bounding box doesn't indicate the final rendered region. It's the smallest rectangle that encloses the object.
* @see Paint::bounds(float* x, float* y, float* w, float* h, bool transformed);
* @deprecated Use bounds(float* x, float* y, float* w, float* h, bool transformed) instead
*/
TVG_DEPRECATED Result bounds(float* x, float* y, float* w, float* h) const noexcept;

Expand Down Expand Up @@ -984,7 +983,7 @@ class TVG_API Shape final : public Paint
*
* @return Result::Success when succeed, Result::FailedAllocation otherwise.
*/
Result stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) noexcept;
Result stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;

/**
* @brief Sets the gradient fill of the stroke for all of the figures from the path.
Expand Down Expand Up @@ -1059,7 +1058,7 @@ class TVG_API Shape final : public Paint
* @note Either a solid color or a gradient fill is applied, depending on what was set as last.
* @note ClipPath won't use the fill values. (see: enum class CompositeMethod::ClipPath)
*/
Result fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) noexcept;
Result fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;

/**
* @brief Sets the gradient fill for all of the figures from the path.
Expand Down Expand Up @@ -1131,7 +1130,7 @@ class TVG_API Shape final : public Paint
*
* @return Result::Success when succeed.
*/
Result fillColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a = nullptr) const noexcept;
Result fillColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;

/**
* @brief Gets the fill rule value.
Expand All @@ -1157,7 +1156,7 @@ class TVG_API Shape final : public Paint
*
* @return Result::Success when succeed, Result::InsufficientCondition otherwise.
*/
Result strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a = nullptr) const noexcept;
Result strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;

/**
* @brief Gets the pointer to the gradient fill of the stroke.
Expand Down
2 changes: 1 addition & 1 deletion src/bin/svg2png/svg2png.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ struct Renderer

auto shape = tvg::Shape::gen();
shape->appendRect(0, 0, static_cast<float>(w), static_cast<float>(h), 0, 0);
shape->fill(r, g, b);
shape->fill(r, g, b, 255);

if (canvas->push(std::move(shape)) != tvg::Result::Success) return 1;
}
Expand Down
7 changes: 3 additions & 4 deletions src/examples/Accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ void tvgDrawCmds(tvg::Canvas* canvas)
if (paint->identifier() == tvg::Shape::identifier()) {
auto shape = (tvg::Shape*) paint;
//override color?
uint8_t r, g, b;
shape->fillColor(&r, &g, &b);
uint8_t r, g, b, a;
shape->fillColor(&r, &g, &b, &a);
if (r == 255 && g == 180 && b == 0)
shape->fill(0, 0, 255);

shape->fill(0, 0, 255, a);
}

//You can return false, to stop traversing immediately.
Expand Down
8 changes: 4 additions & 4 deletions src/examples/AnimateMasking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
// background
auto bg = tvg::Shape::gen();
bg->appendRect(0, 0, WIDTH, HEIGHT);
bg->fill(255, 255, 255);
bg->fill(255, 255, 255, 255);
canvas->push(std::move(bg));

// image
Expand All @@ -54,16 +54,16 @@ void tvgDrawCmds(tvg::Canvas* canvas)
auto maskShape = tvg::Shape::gen();
pMaskShape = maskShape.get();
maskShape->appendCircle(180, 180, 75, 75);
maskShape->fill(125, 125, 125);
maskShape->stroke(25, 25, 25);
maskShape->fill(125, 125, 125, 255);
maskShape->stroke(25, 25, 25, 255);
maskShape->stroke(tvg::StrokeJoin::Round);
maskShape->stroke(10);
canvas->push(std::move(maskShape));

auto mask = tvg::Shape::gen();
pMask = mask.get();
mask->appendCircle(180, 180, 75, 75);
mask->fill(255, 255, 255); //AlphaMask RGB channels are unused.
mask->fill(255, 255, 255, 255); //AlphaMask RGB channels are unused.

picture2->composite(std::move(mask), tvg::CompositeMethod::AlphaMask);
if (canvas->push(std::move(picture2)) != tvg::Result::Success) return;
Expand Down
24 changes: 12 additions & 12 deletions src/examples/Arc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,60 +33,60 @@ void tvgDrawCmds(tvg::Canvas* canvas)
//Arc Line
auto shape1 = tvg::Shape::gen();
shape1->appendArc(150, 150, 80, 10, 180, false);
shape1->stroke(255, 255, 255);
shape1->stroke(255, 255, 255, 255);
shape1->stroke(2);
if (canvas->push(std::move(shape1)) != tvg::Result::Success) return;

auto shape2 = tvg::Shape::gen();
shape2->appendArc(400, 150, 80, 0, 300, false);
shape2->stroke(255, 255, 255);
shape2->stroke(255, 255, 255, 255);
shape2->stroke(2);
if (canvas->push(std::move(shape2)) != tvg::Result::Success) return;

auto shape3 = tvg::Shape::gen();
shape3->appendArc(600, 150, 80, 300, 60, false);
shape3->stroke(255, 255, 255);
shape3->stroke(255, 255, 255, 255);
shape3->stroke(2);
if (canvas->push(std::move(shape3)) != tvg::Result::Success) return;

//Pie Line
auto shape4 = tvg::Shape::gen();
shape4->appendArc(150, 400, 80, 10, 180, true);
shape4->stroke(255, 255, 255);
shape4->stroke(255, 255, 255, 255);
shape4->stroke(2);
if (canvas->push(std::move(shape4)) != tvg::Result::Success) return;

auto shape5 = tvg::Shape::gen();
shape5->appendArc(400, 400, 80, 0, 300, true);
shape5->stroke(255, 255, 255);
shape5->stroke(255, 255, 255, 255);
shape5->stroke(2);
if (canvas->push(std::move(shape5)) != tvg::Result::Success) return;

auto shape6 = tvg::Shape::gen();
shape6->appendArc(600, 400, 80, 300, 60, true);
shape6->stroke(255, 255, 255);
shape6->stroke(255, 255, 255, 255);
shape6->stroke(2);
if (canvas->push(std::move(shape6)) != tvg::Result::Success) return;

//Pie Fill
auto shape7 = tvg::Shape::gen();
shape7->appendArc(150, 650, 80, 10, 180, true);
shape7->fill(255, 255, 255);
shape7->stroke(255, 0, 0);
shape7->fill(255, 255, 255, 255);
shape7->stroke(255, 0, 0, 255);
shape7->stroke(2);
if (canvas->push(std::move(shape7)) != tvg::Result::Success) return;

auto shape8 = tvg::Shape::gen();
shape8->appendArc(400, 650, 80, 0, 300, true);
shape8->fill(255, 255, 255);
shape8->stroke(255, 0, 0);
shape8->fill(255, 255, 255, 255);
shape8->stroke(255, 0, 0, 255);
shape8->stroke(2);
if (canvas->push(std::move(shape8)) != tvg::Result::Success) return;

auto shape9 = tvg::Shape::gen();
shape9->appendArc(600, 650, 80, 300, 60, true);
shape9->fill(255, 255, 255);
shape9->stroke(255, 0, 0);
shape9->fill(255, 255, 255, 255);
shape9->stroke(255, 0, 0, 255);
shape9->stroke(2);
if (canvas->push(std::move(shape9)) != tvg::Result::Success) return;
}
Expand Down
10 changes: 5 additions & 5 deletions src/examples/Blending.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
//Normal
auto shape1 = tvg::Shape::gen();
shape1->appendRect(0, 0, 400, 400, 50, 50);
shape1->fill(0, 255, 255);
shape1->fill(0, 255, 255, 255);
shape1->blend(tvg::BlendMethod::Normal);
if (canvas->push(std::move(shape1)) != tvg::Result::Success) return;

Expand Down Expand Up @@ -104,7 +104,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
auto shape7 = tvg::Shape::gen();
shape7->appendCircle(600, 650, 200, 150);
shape7->blend(tvg::BlendMethod::Screen);
shape7->fill(0, 0, 255);
shape7->fill(0, 0, 255, 255);
if (canvas->push(std::move(shape7)) != tvg::Result::Success) return;

//SrcOver
Expand All @@ -118,7 +118,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
auto shape9 = tvg::Shape::gen();
shape9->appendRect(600, 650, 350, 250);
shape9->blend(tvg::BlendMethod::Darken);
shape9->fill(10, 255, 155);
shape9->fill(10, 255, 155, 255);
if (canvas->push(std::move(shape9)) != tvg::Result::Success) return;

//Prepare Transformed Image
Expand Down Expand Up @@ -261,9 +261,9 @@ int main(int argc, char **argv)
elm_init(argc, argv);

if (tvgEngine == tvg::CanvasEngine::Sw) {
createSwView(1024, 1024);
createSwView();
} else {
createGlView(1024, 1024);
createGlView();
}

elm_run();
Expand Down
16 changes: 8 additions & 8 deletions src/examples/ClipPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ void tvgDrawCmds(tvg::Canvas* canvas)
//Background
auto shape = tvg::Shape::gen();
shape->appendRect(0, 0, WIDTH, HEIGHT);
shape->fill(255, 255, 255);
shape->fill(255, 255, 255, 255);
if (canvas->push(std::move(shape)) != tvg::Result::Success) return;

//////////////////////////////////////////////
auto scene = tvg::Scene::gen();

auto star1 = tvg::Shape::gen();
tvgDrawStar(star1.get());
star1->fill(255, 255, 0);
star1->stroke(255 ,0, 0);
star1->fill(255, 255, 0, 255);
star1->stroke(255 ,0, 0, 255);
star1->stroke(10);

//Move Star1
Expand All @@ -71,8 +71,8 @@ void tvgDrawCmds(tvg::Canvas* canvas)

auto star2 = tvg::Shape::gen();
tvgDrawStar(star2.get());
star2->fill(0, 255, 255);
star2->stroke(0 ,255, 0);
star2->fill(0, 255, 255, 255);
star2->stroke(0 ,255, 0, 255);
star2->stroke(10);
star2->opacity(100);

Expand Down Expand Up @@ -105,13 +105,13 @@ void tvgDrawCmds(tvg::Canvas* canvas)
fill->colorStops(colorStops, 2);
star3->fill(std::move(fill));

star3->stroke(255 ,0, 0);
star3->stroke(255 ,0, 0, 255);
star3->stroke(10);
star3->translate(400, 0);

// color/alpha/opacity are ignored for a clip object - no need to set them
auto clipRect = tvg::Shape::gen();
clipRect->appendRect(500, 120, 200, 200); //x, y, w, h
clipRect->appendRect(500, 120, 200, 200, 0, 0); //x, y, w, h, rx, ry
clipRect->translate(20, 20);

//Clipping scene to rect(shape)
Expand Down Expand Up @@ -144,7 +144,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)

// color/alpha/opacity are ignored for a clip object - no need to set them
auto clipShape = tvg::Shape::gen();
clipShape->appendRect(600, 420, 100, 100);
clipShape->appendRect(600, 420, 100, 100, 0, 0);

//Clipping shape1 to clipShape
shape1->composite(std::move(clipShape), tvg::CompositeMethod::ClipPath);
Expand Down
4 changes: 2 additions & 2 deletions src/examples/CustomTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ void tvgUpdateCmds(tvg::Canvas* canvas, float progress)
shape->lineTo(-173, 12.5);
shape->lineTo(-53, -5.5);
shape->close();
shape->fill(0, 0, 255);
shape->fill(0, 0, 255, 255);
shape->stroke(3);
shape->stroke(255, 255, 255);
shape->stroke(255, 255, 255, 255);

//Transform Matrix
tvg::Matrix m = {1, 0, 0, 0, 1, 0, 0, 0, 1};
Expand Down
10 changes: 5 additions & 5 deletions src/examples/DirectUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
bg->appendRect(0, 0, WIDTH, HEIGHT);

//fill property will be retained
bg->fill(255, 255, 255);
bg->fill(255, 255, 255, 255);

if (canvas->push(std::move(bg)) != tvg::Result::Success) return;

Expand All @@ -50,8 +50,8 @@ void tvgDrawCmds(tvg::Canvas* canvas)
shape->appendRect(-100, -100, 200, 200);

//fill property will be retained
shape->fill(127, 255, 255);
shape->stroke(0, 0, 255);
shape->fill(127, 255, 255, 255);
shape->stroke(0, 0, 255, 255);
shape->stroke(1);

if (canvas->push(std::move(shape)) != tvg::Result::Success) return;
Expand All @@ -67,8 +67,8 @@ void tvgUpdateCmds(tvg::Canvas* canvas, float progress)
//Reset Shape
if (pShape->reset() == tvg::Result::Success) {
pShape->appendRect(-100 + (800 * progress), -100 + (800 * progress), 200, 200, (100 * progress), (100 * progress));
pShape->fill(127, 255, 255);
pShape->stroke(0, 0, 255);
pShape->fill(127, 255, 255, 255);
pShape->stroke(0, 0, 255, 255);
pShape->stroke(30 * progress);

//Update shape for drawing (this may work asynchronously)
Expand Down
10 changes: 5 additions & 5 deletions src/examples/Duplicate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ void tvgDrawCmds(tvg::Canvas* canvas)
shape1->appendRect(220, 10, 100, 100);

shape1->stroke(3);
shape1->stroke(0, 255, 0);
shape1->stroke(0, 255, 0, 255);

float dashPattern[2] = {4, 4};
shape1->stroke(dashPattern, 2);
shape1->fill(255, 0, 0);
shape1->fill(255, 0, 0, 255);

//Duplicate Shape, Switch fill method
auto shape2 = tvg::cast<tvg::Shape>(shape1->duplicate());
Expand Down Expand Up @@ -75,17 +75,17 @@ void tvgDrawCmds(tvg::Canvas* canvas)

auto shape1 = tvg::Shape::gen();
shape1->appendRect(0, 0, 400, 400, 50, 50);
shape1->fill(0, 255, 0);
shape1->fill(0, 255, 0, 255);
scene1->push(std::move(shape1));

auto shape2 = tvg::Shape::gen();
shape2->appendCircle(400, 400, 200, 200);
shape2->fill(255, 255, 0);
shape2->fill(255, 255, 0, 255);
scene1->push(std::move(shape2));

auto shape3 = tvg::Shape::gen();
shape3->appendCircle(600, 600, 150, 100);
shape3->fill(0, 255, 255);
shape3->fill(0, 255, 255, 255);
scene1->push(std::move(shape3));

scene1->scale(0.25);
Expand Down
4 changes: 2 additions & 2 deletions src/examples/FillRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
shape1->lineTo(385, 150);
shape1->lineTo(80, 355);
shape1->close();
shape1->fill(255, 255, 255);
shape1->fill(255, 255, 255, 255);
shape1->fill(tvg::FillRule::Winding); //Fill all winding shapes

if (canvas->push(std::move(shape1)) != tvg::Result::Success) return;
Expand All @@ -51,7 +51,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
shape2->lineTo(715, 450);
shape2->lineTo(410, 655);
shape2->close();
shape2->fill(255, 255, 255);
shape2->fill(255, 255, 255, 255);
shape2->fill(tvg::FillRule::EvenOdd); //Fill polygons with even odd pattern

if (canvas->push(std::move(shape2)) != tvg::Result::Success) return;
Expand Down
8 changes: 4 additions & 4 deletions src/examples/GradientMasking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
//Mask
auto mask = tvg::Shape::gen();
mask->appendCircle(200, 200, 125, 125);
mask->fill(255, 0, 0);
mask->fill(255, 0, 0, 255);

auto fill = tvg::LinearGradient::gen();
fill->linear(0, 0, 400, 400);
Expand Down Expand Up @@ -70,7 +70,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
//Mask
auto mask1 = tvg::Shape::gen();
mask1->appendCircle(600, 200, 125, 125);
mask1->fill(255, 0, 0);
mask1->fill(255, 0, 0, 255);

auto fill1 = tvg::LinearGradient::gen();
fill1->linear(400, 0, 800, 400);
Expand All @@ -92,7 +92,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
//Mask
auto mask2 = tvg::Shape::gen();
mask2->appendCircle(200, 600, 125, 125);
mask2->fill(255, 0, 0);
mask2->fill(255, 0, 0, 255);

auto fill2 = tvg::LinearGradient::gen();
fill2->linear(0, 400, 400, 800);
Expand Down Expand Up @@ -124,7 +124,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
//Mask
auto mask3 = tvg::Shape::gen();
mask3->appendCircle(600, 600, 125, 125);
mask3->fill(255, 0, 0);
mask3->fill(255, 0, 0, 255);

auto fill3 = tvg::LinearGradient::gen();
fill3->linear(400, 400, 800, 800);
Expand Down
Loading

0 comments on commit 86e8b13

Please sign in to comment.