Add missing path methods to the C API
This commit is contained in:
parent
d2fbb23031
commit
2129e4f2e1
|
@ -29,6 +29,11 @@ extern "C" {
|
||||||
#define PF_LINE_JOIN_BEVEL 1
|
#define PF_LINE_JOIN_BEVEL 1
|
||||||
#define PF_LINE_JOIN_ROUND 2
|
#define PF_LINE_JOIN_ROUND 2
|
||||||
|
|
||||||
|
// `geometry`
|
||||||
|
|
||||||
|
#define PF_ARC_DIRECTION_CW 0
|
||||||
|
#define PF_ARC_DIRECTION_CCW 1
|
||||||
|
|
||||||
// `gl`
|
// `gl`
|
||||||
|
|
||||||
#define PF_GL_VERSION_GL3 0
|
#define PF_GL_VERSION_GL3 0
|
||||||
|
@ -50,6 +55,7 @@ struct PFCanvasFontContext;
|
||||||
typedef struct PFCanvasFontContext *PFCanvasFontContextRef;
|
typedef struct PFCanvasFontContext *PFCanvasFontContextRef;
|
||||||
typedef uint8_t PFLineCap;
|
typedef uint8_t PFLineCap;
|
||||||
typedef uint8_t PFLineJoin;
|
typedef uint8_t PFLineJoin;
|
||||||
|
typedef uint8_t PFArcDirection;
|
||||||
|
|
||||||
// `geometry`
|
// `geometry`
|
||||||
|
|
||||||
|
@ -139,6 +145,20 @@ void PFPathBezierCurveTo(PFPathRef path,
|
||||||
const PFVector2F *ctrl0,
|
const PFVector2F *ctrl0,
|
||||||
const PFVector2F *ctrl1,
|
const PFVector2F *ctrl1,
|
||||||
const PFVector2F *to);
|
const PFVector2F *to);
|
||||||
|
void PFPathArc(PFPathRef path,
|
||||||
|
const PFVector2F *center,
|
||||||
|
float radius,
|
||||||
|
float start_angle,
|
||||||
|
float end_angle,
|
||||||
|
PFArcDirection direction);
|
||||||
|
void PFPathArcTo(PFPathRef path, const PFVector2F *ctrl, const PFVector2F *to, float radius);
|
||||||
|
void PFPathRect(PFPathRef path, const PFRectF *rect);
|
||||||
|
void PFPathEllipse(PFPathRef path,
|
||||||
|
const PFVector2F *center,
|
||||||
|
const PFVector2F *axes,
|
||||||
|
float rotation,
|
||||||
|
float start_angle,
|
||||||
|
float end_angle);
|
||||||
void PFPathClosePath(PFPathRef path);
|
void PFPathClosePath(PFPathRef path);
|
||||||
|
|
||||||
// `gl`
|
// `gl`
|
||||||
|
|
44
c/src/lib.rs
44
c/src/lib.rs
|
@ -12,9 +12,10 @@
|
||||||
|
|
||||||
use gl;
|
use gl;
|
||||||
use pathfinder_canvas::{CanvasFontContext, CanvasRenderingContext2D, LineJoin, Path2D};
|
use pathfinder_canvas::{CanvasFontContext, CanvasRenderingContext2D, LineJoin, Path2D};
|
||||||
use pathfinder_geometry::basic::vector::{Vector2F, Vector2I};
|
|
||||||
use pathfinder_geometry::basic::rect::{RectF, RectI};
|
use pathfinder_geometry::basic::rect::{RectF, RectI};
|
||||||
|
use pathfinder_geometry::basic::vector::{Vector2F, Vector2I};
|
||||||
use pathfinder_geometry::color::ColorF;
|
use pathfinder_geometry::color::ColorF;
|
||||||
|
use pathfinder_geometry::outline::ArcDirection;
|
||||||
use pathfinder_geometry::stroke::LineCap;
|
use pathfinder_geometry::stroke::LineCap;
|
||||||
use pathfinder_gl::{GLDevice, GLVersion};
|
use pathfinder_gl::{GLDevice, GLVersion};
|
||||||
use pathfinder_gpu::resources::{FilesystemResourceLoader, ResourceLoader};
|
use pathfinder_gpu::resources::{FilesystemResourceLoader, ResourceLoader};
|
||||||
|
@ -41,7 +42,13 @@ pub const PF_LINE_JOIN_MITER: u8 = 0;
|
||||||
pub const PF_LINE_JOIN_BEVEL: u8 = 1;
|
pub const PF_LINE_JOIN_BEVEL: u8 = 1;
|
||||||
pub const PF_LINE_JOIN_ROUND: u8 = 2;
|
pub const PF_LINE_JOIN_ROUND: u8 = 2;
|
||||||
|
|
||||||
|
// `geometry`
|
||||||
|
|
||||||
|
pub const PF_ARC_DIRECTION_CW: u8 = 0;
|
||||||
|
pub const PF_ARC_DIRECTION_CCW: u8 = 1;
|
||||||
|
|
||||||
// `renderer`
|
// `renderer`
|
||||||
|
|
||||||
pub const PF_RENDERER_OPTIONS_FLAGS_HAS_BACKGROUND_COLOR: u8 = 0x1;
|
pub const PF_RENDERER_OPTIONS_FLAGS_HAS_BACKGROUND_COLOR: u8 = 0x1;
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
|
@ -52,6 +59,7 @@ pub type PFPathRef = *mut Path2D;
|
||||||
pub type PFCanvasFontContextRef = *mut CanvasFontContext;
|
pub type PFCanvasFontContextRef = *mut CanvasFontContext;
|
||||||
pub type PFLineCap = u8;
|
pub type PFLineCap = u8;
|
||||||
pub type PFLineJoin = u8;
|
pub type PFLineJoin = u8;
|
||||||
|
pub type PFArcDirection = u8;
|
||||||
|
|
||||||
// `geometry`
|
// `geometry`
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
@ -249,6 +257,40 @@ pub unsafe extern "C" fn PFPathBezierCurveTo(path: PFPathRef,
|
||||||
(*path).bezier_curve_to((*ctrl0).to_rust(), (*ctrl1).to_rust(), (*to).to_rust())
|
(*path).bezier_curve_to((*ctrl0).to_rust(), (*ctrl1).to_rust(), (*to).to_rust())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn PFPathArc(path: PFPathRef,
|
||||||
|
center: *const PFVector2F,
|
||||||
|
radius: f32,
|
||||||
|
start_angle: f32,
|
||||||
|
end_angle: f32,
|
||||||
|
direction: PFArcDirection) {
|
||||||
|
let direction = if direction == 0 { ArcDirection::CW } else { ArcDirection::CCW };
|
||||||
|
(*path).arc((*center).to_rust(), radius, start_angle, end_angle, direction)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn PFPathArcTo(path: PFPathRef,
|
||||||
|
ctrl: *const PFVector2F,
|
||||||
|
to: *const PFVector2F,
|
||||||
|
radius: f32) {
|
||||||
|
(*path).arc_to((*ctrl).to_rust(), (*to).to_rust(), radius)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn PFPathRect(path: PFPathRef, rect: *const PFRectF) {
|
||||||
|
(*path).rect((*rect).to_rust())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn PFPathEllipse(path: PFPathRef,
|
||||||
|
center: *const PFVector2F,
|
||||||
|
axes: *const PFVector2F,
|
||||||
|
rotation: f32,
|
||||||
|
start_angle: f32,
|
||||||
|
end_angle: f32) {
|
||||||
|
(*path).ellipse((*center).to_rust(), (*axes).to_rust(), rotation, start_angle, end_angle)
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn PFPathClosePath(path: PFPathRef) {
|
pub unsafe extern "C" fn PFPathClosePath(path: PFPathRef) {
|
||||||
(*path).close_path()
|
(*path).close_path()
|
||||||
|
|
Loading…
Reference in New Issue