Commit graph

544 commits

Author SHA1 Message Date
Simon Hausmann
fd5757bc44 Simplify coordinate handling for item rendering
Remove the pos parameter to the render functions and instead let
the item renderer apply the transformation on the rendere (femtovg
canvas or QPainter).

So `draw_*` functions in the backend now always operate in item local
coordinates.
2021-02-12 17:12:58 +01:00
Olivier Goffart
9eac131ae5 Add the logo in the docs 2021-02-12 08:24:42 +01:00
Simon Hausmann
7ac288a849 Fix disappearing html images
Commit 8a66af0746 resulted in pending html
images not being strongly referenced anymore through the item's
rendering cache when first queried in the image size query. That means
they initially reported a size (1x1) and after loading they *should*
mark the bindings dirty that depend on the implicit size, but since the
image was deleted (and along with it the notifying property), the image
kept its visible (1x1) size.

Similarly, images would get loaded too much from disk - same cause,
different effect.

To fix this, go back to the earlier design where the renderer's image
cache keeps a strong reference.
2021-02-11 08:17:33 +01:00
Simon Hausmann
0c6d88160a Fix wasm build 2021-02-10 21:35:10 +01:00
Simon Hausmann
b5095e9729 Fix source scaling detection for the Qt backend
ClippedImage without a source rect or one that's identical to the target should also allow for source scaling
2021-02-10 21:33:04 +01:00
Simon Hausmann
f704e4c823 Implement rendering SVG with specified size
Relates to #129
2021-02-10 21:08:58 +01:00
Simon Hausmann
ad0d2f04e1 Small image handling cleanup
Use a dedicated structure for femtovg based textures
2021-02-10 20:36:32 +01:00
Simon Hausmann
12b58af1b1 Support rendering SVGs with a specified size in the GL backend
This is limited to resvg's FitTo::Width though, so the aspect ratio will
always be preserved. This might however be desirable anyway.

Relates to #129
2021-02-10 17:52:34 +01:00
Simon Hausmann
8a66af0746 Clean up image size determination in the rendering backend
Don't use the item's rendering cache to determine the image size, as
that's soley for rendering. The Qt backend doesn't use the item cache
and the GL backend neither after this change. Instead both backends have
a cache for decoded images.
2021-02-10 17:34:29 +01:00
Simon Hausmann
2dd5ea61bb Add support for Path.fill-rule
For some reason it's not working with the Qt renderer though
2021-02-10 14:08:32 +01:00
Simon Hausmann
d2e0ecba93 Move the image handling code into a separate module 2021-02-10 12:49:26 +01:00
Simon Hausmann
7b46eed0a7 Minor cleanup
Move the html image element handling also into CachedImage
2021-02-10 12:44:05 +01:00
Simon Hausmann
91edc0a896 Fix the wasm build 2021-02-10 12:41:38 +01:00
Simon Hausmann
d3268555cc Clean up image loading a bit in the GL backend
Use helper functions to load from path or data, and print error
messages to stderr if we're having problems decoding images or
rendering the SVG.
2021-02-10 11:39:40 +01:00
Simon Hausmann
f1d41db006 Clarify comment in draw_image_impl 2021-02-10 11:12:06 +01:00
Simon Hausmann
0a2385ad58 Fix colorization of images loaded via HTTP
There are two problems that this patch fixes:

  * It may happen that the image is not loaded yet, which means
    we need to wait with the colorization effect instead of colorizing
    the dummy (1x1) texture.

  * It may happen that we transition from a regular image to one
    that has a valid colorization brush, in which case we need to
    invalidate the graphics item cache.
2021-02-10 09:06:09 +01:00
Olivier Goffart
9db575952d Fix bold font with Qt
Qt expect a font between 0 and 99.
This is the mapping somehow used for QFont::Weight enum
2021-02-09 10:59:11 +01:00
Olivier Goffart
f7a76dc352 Add ImageFit::cover, and fix ImageFit::contain 2021-02-09 10:52:04 +01:00
Simon Hausmann
de9a215a1c Fix use of Clip inside a scrolled Flickable with the GL backend
We're using `Canvas::intersect_scissor` to combine the viewport clip of
the flickable with any child `Clip` element, for example. Unfortunately
`intersect_scissor` has a bug and this patch works around it by doing
the scissor intersection manually. This works because we don't apply a
global transform on the canvas -- all scaling and translation is done
locally in the draw functions.
2021-02-09 10:43:02 +01:00
Olivier Goffart
ec90d0c525 wasm: Resize the canvas to make sure it fits the window constraints 2021-02-09 09:41:01 +01:00
Simon Hausmann
24c3d4daed Fix ImageFit::contain with the GL backend
The centering of the source image was missing
2021-02-09 08:55:39 +01:00
Simon Hausmann
4e6cc8da43 Fix panic when trying to load an image with an empty path
We choose to ignore that and treat it like Resource::None
2021-02-08 15:16:05 +01:00
Olivier Goffart
8b535991ec Handle Esc in the GL backend
Issue #165
2021-02-08 09:00:09 +01:00
Simon Hausmann
949b61bad7 Implement image colorization for the GL backend 2021-02-05 19:27:03 +01:00
Olivier Goffart
9bdb793ec1 Rename Window::color to background 2021-02-05 09:38:40 +01:00
Olivier Goffart
743d729ecb Silent warning 2021-02-04 18:15:06 +01:00
Olivier Goffart
0e2471f76b Image::colorize support
(Qt only)
2021-02-04 17:44:01 +01:00
Simon Hausmann
3f541972ef Change Rectangle::border-color to be a brush
This allows things like filling a thick border with a gradient.
2021-02-04 17:05:00 +01:00
Simon Hausmann
a13cd33cd6 Fix Brush::NoBrush rendering
Don't map `NoBrush` to `femtovg::Paint::default()`, as that defaults to a
white solid fill.
2021-02-04 14:11:38 +01:00
Simon Hausmann
4e4817e041 Fix drop shadow rendering with the GL backend when using border radius without blur
The inner fill rect needs to follow the shape of the original rectangle.
When it has a radius we need to bleed it "slightly" into the shadow rect to avoid gaps,
and then draw it before the shadow.

Fixes #156
2021-02-04 12:59:36 +01:00
Simon Hausmann
1a9419638d Change the type of the color property for Text and TextInput to be a brush
This allows filling glyphs with gradients. However femtovg
appears to apply the start/end position per-glyph
instead of globally - resulting in a different result than Qt.
2021-02-04 11:54:57 +01:00
Simon Hausmann
d92c8cab23 Fix path fitting
Include the stroke width in the boundaries when fitting a path into the
size of a `Path` element.
2021-02-04 09:09:23 +01:00
Simon Hausmann
66df71a3ca Convert Path to support brushes
* Rename `fill-color` to `fill`
* Rename `stroke-colo` to `stroke`
* Support using a brush for both properties
2021-02-03 15:45:33 +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
Olivier Goffart
8555f4f83a Fix Qt gradients coordinate mode 2021-02-03 13:29:02 +01:00
Olivier Goffart
8f93fdcc4e Convert Linear Gradient to QBrush
(Untested)
2021-02-03 12:57:51 +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
3d3606a8f1 Remove unused rust module
This file is not needed anymore

Amends commit 5df6c99f4f
2021-02-03 08:56:53 +01:00
Simon Hausmann
16a7585d07 Hack to make the demos start up with latest macOS and GL backend
The fallback list has changed slightly and it appears that SIP is
slowing down reading ~75MB font files.

This is sub-optimal though, font-kit shouldn't assert on certain fonts
and it should really mmap fonts instead of
reading them into memory.
2021-02-03 08:55:44 +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
1f091cb1c0 Rename Rectangle.color to Rectangle.background
Add support for built-in property aliases and rename `color` to
`background` - in preparation for it also changing to type brush.

Right now the alias is silent, a deprecation and overall change
will come in a subsequent change.
2021-02-02 17:01:12 +01:00
Simon Hausmann
69508575ec Fix rendering of Flickable
It should clip to its geometry
2021-02-01 15:35:36 +01:00
Simon Hausmann
08413212f9 Improve rendering of circles with the GL backend
Rendering a circle using `rounded_rect` will create a path with `LineTo`
verbs for the edges. Unfortunately those create visible artefacts,
especially in lower resolutions.

Therefore this patch attempts to detect this scenario and draw a circle instead.

Fixes #152
2021-02-01 12:50:26 +01:00
Simon Hausmann
3648995fef Fix window size with Qt backend when no size is specified
Our memory tutorial and docs sometimes use `Window { ... }` without any
`width` or `height` specified. That we should not tell the window manager :)
2021-01-29 16:11:05 +01:00
Simon Hausmann
5df6c99f4f Improve application font support for WASM and simplify font handling
We can use fontdb on all platforms, which gives consistent font query
behavior of application fonts. And then we also don't need our hand-made
"db" anymore for the wasm build and the included DejaVu font.
2021-01-28 21:47:52 +01:00
Simon Hausmann
615ead0db0 Include SVG support also in the wasm build
This disables text in SVG, but that's not really working yet anyway
because it needs to be connected to the font selection SixtyFPS uses.
2021-01-28 21:24:07 +01:00
Olivier Goffart
f928026d98 Fix mouse over with the Qt backend 2021-01-28 18:22:23 +01:00
Olivier Goffart
b5bb27c083 Fix the memory game's tile not closing with the Qt backend
updating a model does not make the redraw_listener dirty
2021-01-28 18:16:28 +01:00
Simon Hausmann
e387d72421 Fix rendering artifacts with the GL backend in the memory tutorial
When a tile is open artifacts would be visible around the edge of the
tile. That's because a zero width rectangle would cause pixels to appear
with femtovg. The Qt backend however has an early abort in
`get_geometry!`.

This patches applies the same early-abort semantics to both backends and
switches to `<= 0`, corresponding to euclid::Size's `is_empty()`.
2021-01-28 17:57:35 +01:00
Olivier Goffart
a07fbf777a Fix initial windows size with the Qt backend 2021-01-28 17:23:10 +01:00