Commit 2b4235d8 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

improved configuration of fill and stroke styles

parent 0ee6ce9f
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -41,9 +41,7 @@ ReturnCode arrow_draw_default(
  line_style.line_width = size;
  strokeLine(layer, from, to, line_style);

  FillStyle head_style;
  head_style.color = color;
  fillPath(layer, head_path, head_style);
  fillPath(layer, head_path, color);

  return OK;
}
+35 −10
Original line number Diff line number Diff line
@@ -20,35 +20,40 @@ namespace fviz {
void fillPath(
    Layer* layer,
    const Path& path,
    const FillStyle& style) {
    const Color& color) {
  fillPath(
      layer,
      Rectangle(0, 0, layer->width, layer->height),
      path.data(),
      path.size(),
      style);
      path,
      color);
}

void fillPath(
    Layer* layer,
    const Rectangle& clip,
    const Path& path,
    const FillStyle& style) {
    const Color& color) {
  layer_ops::BrushFillOp op;
  op.clip = clip;
  op.path = path;
  op.style = style;
  op.color = color;

  layer->apply(op);
}

void fillPath(
ReturnCode fillPath(
    Layer* layer,
    const Path& path,
    const FillStyle& style) {
  return style(path, layer);
}

ReturnCode fillPath(
    Layer* layer,
    const Rectangle& clip,
    const PathData* point_data,
    size_t point_count,
    const Path& path,
    const FillStyle& style) {
  return fillPath(layer, clip, Path(point_data, point_count), style);
  return style(path, layer);
}

void strokePath(
@@ -68,6 +73,10 @@ void strokePath(
    const Rectangle& clip,
    const Path& path,
    const StrokeStyle& style) {
  if (style.line_width == 0) {
    return;
  }

  layer_ops::BrushStrokeOp op;
  op.clip = clip;
  op.path = path;
@@ -131,6 +140,22 @@ void fillRectangle(
  fillPath(layer, clip, p, style);
}

void fillRectangle(
    Layer* layer,
    const Point& origin,
    double width,
    double height,
    const Color& color) {
  Path p;
  p.moveTo(origin.x, origin.y);
  p.lineTo(origin.x + width, origin.y);
  p.lineTo(origin.x + width, origin.y + height);
  p.lineTo(origin.x, origin.y + height);
  p.lineTo(origin.x, origin.y);

  Rectangle clip(0, 0, layer->width, layer->height);
  fillPath(layer, clip, p, color);
}

} // namespace fviz
+13 −23
Original line number Diff line number Diff line
@@ -19,42 +19,32 @@
#include "path.h"
#include "measure.h"
#include "layout.h"
#include "style.h"

namespace fviz {
class Layer;

enum class StrokeLineJoin { MITER, ROUND, BEVEL };
enum class StrokeLineCap { BUTT, SQUARE, ROUND};

struct StrokeStyle {
  StrokeStyle() :
    line_join(StrokeLineJoin::MITER),
    line_cap(StrokeLineCap::SQUARE),
    color(Color::fromRGB(0, 0, 0)) {}

  Measure line_width;
  StrokeLineJoin line_join;
  StrokeLineCap line_cap;
  Color color;
};

struct FillStyle {
  FillStyle() :
    color(Color::fromRGB(0, 0, 0)) {}

  Color color;
};
ReturnCode fillPath(
    Layer* layer,
    const Path& path,
    const FillStyle& style);

void fillPath(
    Layer* layer,
    const Path& path,
    const Color& color);

ReturnCode fillPath(
    Layer* layer,
    const Rectangle& clip,
    const Path& path,
    const FillStyle& style);

void fillPath(
    Layer* layer,
    const Rectangle& clip,
    const Path& path,
    const FillStyle& style);
    const Color& color);

void fillPath(
    Layer* layer,
@@ -99,7 +89,7 @@ void fillRectangle(
    const Point& origin,
    double width,
    double height,
    const FillStyle& style);
    const Color& color);

} // namespace fviz
+2 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include "brush.h"
#include "text.h"
#include "text_layout.h"
#include "style.h"

namespace fviz {
namespace layer_ops {
@@ -37,7 +38,7 @@ struct BrushStrokeOp {
struct BrushFillOp {
  Rectangle clip;
  Path path;
  FillStyle style;
  Color color;
};

struct TextSpanOp {
+2 −2
Original line number Diff line number Diff line
@@ -130,12 +130,12 @@ Status svg_fill_path(
    SVGDataRef svg) {
  const auto& clip = op.clip;
  const auto& path = op.path;
  const auto& style = op.style;
  const auto& color = op.color;

  svg->buffer
      << "  "
      << "<path"
      << svg_attr("fill", style.color.to_hex_str())
      << svg_attr("fill", color.to_hex_str())
      << svg_attr("d", svg_path_data(path))
      << "/>"
      << "\n";
Loading