Commit graph

25 commits

Author SHA1 Message Date
Simon Hausmann
e7bc91c804 Add support for specifying the viewbox of path elements 2021-05-21 19:51:00 +02:00
Simon Hausmann
9a4dc4a8dc Clean up femtovg crate dependencies
Let only the GL backend depend on femtovg, by moving the color functions.
This way it's easier to change the femtovg version in one place.
2021-05-20 08:56:11 +02:00
Olivier Goffart
f3da9532d7 Remove left over debug output 2021-04-12 13:05:00 +02:00
Olivier Goffart
af8be46019 Interpolation between gradients for the animations 2021-04-12 12:33:15 +02:00
Olivier Goffart
fb4f955302 Fix angle within gradients
line_for_angle takes a value in degrees, but the sin and cos are expected to be in radians
2021-04-07 18:31:13 +02:00
Simon Hausmann
477729da52 Improve brush property test coverage
Test that assigning colors works:

* Test the implicit `Brush(const Color &)` C++ constructor
* Add derive_more::From to allow convenient conversion in Rust
* When assigning to brush properties in JavaScript, try at least to see if it's a color string (could be extended in the future)
2021-04-01 08:27:10 +02:00
Olivier Goffart
41c6c79bc1 Better name for the femtovg feature
Just use the name of the crate, i believe this is the convension
2021-03-19 09:48:19 +01:00
Olivier Goffart
35cce45cbc Add a fii feature so that we don't compile in the ffi code if not required 2021-03-16 18:09:57 +01:00
Olivier Goffart
89bbdce88e Polish a bit the Brush API 2021-03-10 16:54:33 +01:00
Simon Hausmann
f087cc18bc Remove extern "C" functions from wasm module
We don't need these functions and their export. They account for ~20kb in
the optimized .wasm - plus JS glue code.
2021-02-26 17:04:49 +01:00
Simon Hausmann
391d0152f0 Add Color::brighter/darker functions
These are exposed in .60 as well as in Rust and C++ and implemented by
converting to HSV color space and adjusting the brightness (value).
2021-02-24 10:49:27 +01:00
Simon Hausmann
2ce672bd68 Reduce dependencies
Use only specific lyon packages instead of pulling all of them in.
This slightly speeds up compilation as well as for example lyon_tesselation
doesn't need to be compiled anymore.
2021-02-09 17:22:01 +01:00
Simon Hausmann
50d9211e0a Fix failing default_color.60 test
Allow converting a brush to a color. In the case of a gradient, the color of the first stop is returned.

For the C++ generator this requires adding the extra case of explicitly
calling the `Brush(const Color &)` constructor, despite it being implicit,
in order to generate the correct code when we have IR that casts twice:

```
   Expression::Cast {
       from: Expression::Cast {
           from: Expression::Cast {
               from: Expression::NumberLiteral(...),
               to: Type::Color,
           }
           to: Type::Brush,
       },
       to: Type::Color,
   }
```
2021-02-04 13:44:10 +01:00
Simon Hausmann
fd3c8bf9fa Simplify path event iteration code
* Always apply a transformation (less variants)
* Let the path data iterator take ownership of the data. That will
  make it possible to return a PathDataIterator from a function in the
  future
2021-02-04 09:08:00 +01:00
Simon Hausmann
c41062e9bb Fix linear gradient rendering with the GL backend
Share the code for transforming the gradient's angle to start and end points,
and apply the transformation to the bounds.
2021-02-03 14:38:29 +01:00
Simon Hausmann
7982325da4 Change Rectangle::background's type to be a brush
This also introduces the brush type in the compiler and generators. At the
moment only conversion from Color is implemented.
2021-02-03 12:49:44 +01:00
Simon Hausmann
bc194241fd Prepare for Brush becoming a property type
We're going to need support for InterpolatedValue, which at the moment
has trait requirements that are a bit too tight.

It's sufficient if it takes references to values and doesn't require Copy or Clone.
The latter can go into the bounds where it's actually used.
2021-02-03 11:04:52 +01:00
Olivier Goffart
e4a1f50a9a Brush support in the interpreter 2021-02-03 09:28:33 +01:00
Simon Hausmann
93c0fe54ea Prepare for using graphics::Brush in the rendering backends
by introducing mappings to QBrush and femtovg::Paint
2021-02-03 08:39:53 +01:00
Simon Hausmann
488d71042e Fix test build 2021-02-01 16:53:44 +01:00
Simon Hausmann
f33b26fa93 Make Brush compile for C++
A few changes were required:

 * `LinearGradient(LinearGradient)` as enum variant unfortunately
    won't compile because the cbindgen generated constructor
    function (`LinearGradient()`) will try to also instantiate the
    variant type inside (`LinearGradient`) and that won't find the type
    but the function itself and error out. So the inner type is now
    called `LinearGradientBrush`.

 * The same name dance was required for `Color`, where the enum variant
   instead is called `SolidColor`

 * `BrushInner` was removed in favor of just `Brush`. The nicer Rust
    API will be the public variant, and for cbindgen we can just put
    the generated enum into an internal namespace, like we do for
    Resource for example

 * A `NoBrush` variant was added. Maybe that name could be improved?
2021-02-01 16:51:04 +01:00
Simon Hausmann
d065e7e879 Add a comment about the "encoding" of LinearGradient 2021-02-01 15:06:19 +01:00
Simon Hausmann
b90eb04088 Begin with the brush data structure
This patch also adds `extend` to `SharedVector`, for convenience.
2021-02-01 14:45:49 +01:00
Simon Hausmann
b608f3b7c0 Split out the path data structures and functions into a separate module 2021-02-01 13:37:47 +01:00
Simon Hausmann
ee2671fe70 Reduce the size of graphics.rs a little
Split out the color related intos into a module of their own.
2021-02-01 13:22:14 +01:00