Skip to content

Commit

Permalink
add missing files.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Jan 5, 2024
1 parent 673a913 commit 463190f
Show file tree
Hide file tree
Showing 2 changed files with 706 additions and 0 deletions.
94 changes: 94 additions & 0 deletions libraries/ZWidget/include/zwidget/core/pathfill.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#pragma once

#include <vector>
#include <stdint.h>
#include "core/rect.h"

/*
// 3x3 transform matrix
class PathFillTransform
{
public:
PathFillTransform() { for (int i = 0; i < 9; i++) matrix[i] = 0.0f; matrix[0] = matrix[4] = matrix[8] = 1.0; }
PathFillTransform(const float* mat3x3) { for (int i = 0; i < 9; i++) matrix[i] = (double)mat3x3[i]; }
PathFillTransform(const double* mat3x3) { for (int i = 0; i < 9; i++) matrix[i] = mat3x3[i]; }
double matrix[9];
};
*/

enum class PathFillMode
{
alternate,
winding
};

enum class PathFillCommand
{
line,
quadradic,
cubic
};

class PathFillSubpath
{
public:
PathFillSubpath() : points(1) { }

std::vector<Point> points;
std::vector<PathFillCommand> commands;
bool closed = false;
};

class PathFillDesc
{
public:
PathFillDesc() : subpaths(1) { }

PathFillMode fill_mode = PathFillMode::alternate;
std::vector<PathFillSubpath> subpaths;

void MoveTo(const Point& point)
{
if (!subpaths.back().commands.empty())
{
subpaths.push_back(PathFillSubpath());
}
subpaths.back().points.front() = point;
}

void LineTo(const Point& point)
{
auto& subpath = subpaths.back();
subpath.points.push_back(point);
subpath.commands.push_back(PathFillCommand::line);
}

void BezierTo(const Point& control, const Point& point)
{
auto& subpath = subpaths.back();
subpath.points.push_back(control);
subpath.points.push_back(point);
subpath.commands.push_back(PathFillCommand::quadradic);
}

void BezierTo(const Point& control1, const Point& control2, const Point& point)
{
auto& subpath = subpaths.back();
subpath.points.push_back(control1);
subpath.points.push_back(control2);
subpath.points.push_back(point);
subpath.commands.push_back(PathFillCommand::cubic);
}

void Close()
{
if (!subpaths.back().commands.empty())
{
subpaths.back().closed = true;
subpaths.push_back(PathFillSubpath());
}
}

void Rasterize(uint8_t* dest, int width, int height, bool blend = false);
};
Loading

0 comments on commit 463190f

Please sign in to comment.