-
Notifications
You must be signed in to change notification settings - Fork 14
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
base: main
Are you sure you want to change the base?
Conversation
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 |
There was a problem hiding this comment.
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).
(* Renders context to PNG *) | ||
let write ctx filename = | ||
Cairo.PNG.write ctx.surface filename; | ||
Cairo.Surface.finish ctx.surface | ||
|
There was a problem hiding this comment.
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.
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 aBackend
module signature and injects geometry/transformation/types modularly. The Cairo backend is now available under Joy.SVG and the canvas backend Joy.Canvas.