Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canvas backend and module functors #98

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

FayCarsons
Copy link
Collaborator

Integrated the HTML canvas backend and added module functors so that backends can be created easily.

I went with JSOO as Melange seems immature and documentation is less than ideal. It was unclear how Melange would integrate with a library that targets both native and the browser.

Adding new backends should now be easy as there's a Joy module functor that takes a Backend module signature and injects geometry/transformation/types modularly. The Cairo backend is now available under Joy.SVG and the canvas backend Joy.Canvas.

Comment on lines +24 to +54
module type Backend = sig
type context

val context : context option ref

type 'a point = 'a Shape.point
type shape = Shape.shape
type shapes = Shape.shapes
type transformation = Transform.transformation
type color = Color.color

val point : int -> int -> float Shape.point
val circle : ?c:float Shape.point -> int -> Shape.shape
val rectangle : ?c:float Shape.point -> int -> int -> Shape.shape
val polygon : float Shape.point list -> Shape.shape
val ellipse : ?c:float Shape.point -> int -> int -> Shape.shape
val line : ?a:float Shape.point -> float Shape.point -> Shape.shape
val complex : Shape.shape list -> Shape.shape
val rotate : int -> Transform.transformation
val scale : float -> Transform.transformation
val translate : int -> int -> Transform.transformation
val with_stroke : color -> shape -> shape
val with_fill : color -> shape -> shape
val map_stroke : (color -> color) -> shape -> shape
val map_fill : (color -> color) -> shape -> shape
val white : color
val black : color
val red : color
val blue : color
val green : color
val yellow : color
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API should not be customisable.

I am working on a change where we can add the module functor you wrote for Impl (with fewer of those functions).

Comment on lines +10 to +14
(* Renders context to PNG *)
let write ctx filename =
Cairo.PNG.write ctx.surface filename;
Cairo.Surface.finish ctx.surface

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only renders PNG, not SVG.

Moreover, we should not use Cairo for SVG - even if it does support that - because we want to be able to run SVG backend in the browser. Cairo will need the native library to be installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants