Skip to content

Commit

Permalink
Add smoothing level.
Browse files Browse the repository at this point in the history
  • Loading branch information
gregersn committed Nov 9, 2024
1 parent 7548dc8 commit d9f59d0
Show file tree
Hide file tree
Showing 52 changed files with 134 additions and 102 deletions.
3 changes: 2 additions & 1 deletion include/pyro/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Pyro
GraphicsMode mode;
std::filesystem::path filename{""};

bool _smooth{true};
int _smooth{3};
unsigned int _curvedetail{32};

Shape _shape{Shape()};
Expand Down Expand Up @@ -85,6 +85,7 @@ namespace Pyro
virtual void strokejoin(int join);

virtual void smooth();
virtual void smooth(int level);
virtual void nosmooth();

// Transformation
Expand Down
1 change: 1 addition & 0 deletions include/pyro/graphics_cairo.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace Pyro

void background(float r, float g, float b, float a) override;
void smooth() override;
void smooth(int level) override;
void nosmooth() override;
void strokecap(int cap) override;
void strokejoin(int join) override;
Expand Down
1 change: 1 addition & 0 deletions include/pyro/pyro.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace Pyro
// **** /RENDERING ****

inline void smooth() { pg->smooth(); };
inline void smooth(int level) { pg->smooth(level); };
inline void nosmooth() { pg->nosmooth(); };

inline float strokeweight() { return pg->strokeweight(); };
Expand Down
4 changes: 2 additions & 2 deletions screenshots/expected/image_a_over_b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_a_over_b_with_alpha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_blend_ADD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_blend_BLEND.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_blend_BURN.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_blend_DARKEST.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_blend_DIFFERENCE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_blend_DODGE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_blend_EXCLUSION.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_blend_HARD_LIGHT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_blend_LIGHTEST.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_blend_MULTIPLY.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_blend_OVERLAY.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_blend_SCREEN.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_blend_SOFT_LIGHT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_blend_SUBTRACT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_convert_4ch_to_1ch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_convert_4ch_to_3ch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_place_1ch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_place_3ch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_place_4ch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_place_default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_place_scaled_rotated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_resize_scale_down_bi_loaded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_resize_scale_down_nn_loaded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions screenshots/expected/image_resize_scale_up_bi_loaded.png
4 changes: 2 additions & 2 deletions screenshots/expected/image_resize_scale_up_nn_loaded.png
4 changes: 2 additions & 2 deletions screenshots/expected/image_single_channel_mask.png
4 changes: 2 additions & 2 deletions screenshots/expected/noise_2d.png
4 changes: 2 additions & 2 deletions screenshots/expected/push_pop_style.png
4 changes: 2 additions & 2 deletions screenshots/expected/shape_circle.png
4 changes: 2 additions & 2 deletions screenshots/expected/shape_curve.png
4 changes: 2 additions & 2 deletions screenshots/expected/shape_curve_bezier.png
4 changes: 2 additions & 2 deletions screenshots/expected/shape_curve_bezier_vertex.png
4 changes: 2 additions & 2 deletions screenshots/expected/shape_curve_vertex.png
4 changes: 2 additions & 2 deletions screenshots/expected/shape_ellipse.png
4 changes: 2 additions & 2 deletions screenshots/expected/shape_multi_contour.png
4 changes: 2 additions & 2 deletions screenshots/expected/shape_n_ellipses.png
4 changes: 2 additions & 2 deletions screenshots/expected/shape_rect_center.png
4 changes: 2 additions & 2 deletions screenshots/expected/shape_rect_corner.png
4 changes: 2 additions & 2 deletions screenshots/expected/shape_triangle.png
4 changes: 2 additions & 2 deletions screenshots/expected/stroke_cap.png
4 changes: 2 additions & 2 deletions screenshots/expected/stroke_join.png
4 changes: 2 additions & 2 deletions screenshots/expected/stroke_weight.png
4 changes: 2 additions & 2 deletions screenshots/expected/test_image.png
4 changes: 2 additions & 2 deletions screenshots/expected/typography_simple_string.png
4 changes: 2 additions & 2 deletions screenshots/expected/using_current_unit.png
9 changes: 7 additions & 2 deletions src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,17 @@ namespace Pyro

void Graphics::smooth()
{
this->_smooth = true;
this->smooth(2);
}

void Graphics::smooth(int level)
{
this->_smooth = max(min(level, 8), 0);
}

void Graphics::nosmooth()
{
this->_smooth = false;
this->smooth(0);
}

float Graphics::strokeweight()
Expand Down
34 changes: 29 additions & 5 deletions src/graphics_cairo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ namespace Pyro

void GraphicsCairo::shape(Shape s, float x, float y)
{
// TODO: Use unit
cairo_save(this->cr);
cairo_new_path(this->cr);

Expand Down Expand Up @@ -218,14 +217,39 @@ namespace Pyro

void GraphicsCairo::smooth()
{
this->_smooth = true;
cairo_set_antialias(this->cr, CAIRO_ANTIALIAS_DEFAULT);
this->smooth(2);
}

void GraphicsCairo::smooth(int level)
{
this->_smooth = level;
cairo_antialias_t cairo_antialias_level = CAIRO_ANTIALIAS_DEFAULT;
switch (this->_smooth)
{
case 0:
cairo_antialias_level = CAIRO_ANTIALIAS_NONE;
break;
case 1:
case 2:
cairo_antialias_level = CAIRO_ANTIALIAS_FAST;
break;
case 3:
cairo_antialias_level = CAIRO_ANTIALIAS_GOOD;
break;
case 4:
case 5:
case 6:
case 7:
case 8:
cairo_antialias_level = CAIRO_ANTIALIAS_BEST;
break;
}
cairo_set_antialias(this->cr, cairo_antialias_level);
}

void GraphicsCairo::nosmooth()
{
this->_smooth = false;
cairo_set_antialias(this->cr, CAIRO_ANTIALIAS_NONE);
this->smooth(0);
}

void GraphicsCairo::strokecap(int cap)
Expand Down

0 comments on commit d9f59d0

Please sign in to comment.