Commit graph

358 commits

Author SHA1 Message Date
Simon Hausmann
58fc93d352 Prepare for improved font fallback handling in the GL backend
In order to determine the best list of fallback fonts for text
rendering, we need to know what text we're going to render. That's why
this patch passes the text through all the way.
2021-04-13 14:09:11 +02:00
Simon Hausmann
ccca2742c3 Prepare for caching font selection in the GL renderer
Cache the default font properties in a Property<FontRequest>, so that we
can query it in the future when determining the GLFont for text
rendering. When that will happen through a property tracker, the dirty
propagation should mark the item cache dirty when default font
properties change.
2021-04-13 14:09:11 +02:00
Simon Hausmann
f42d759131 Remove dead code
The height method on FontMetrics is not needed anymore. We call `text_size` nowadays.
2021-04-13 11:26:26 +02:00
Olivier Goffart
1773f9143b Add a border-radius property to the Clip
So that `clip: true` used on a Rectangle with border radius can be clipped
with that radius

Only the Qt backend is implemented for now
2021-04-12 19:47:18 +02:00
Simon Hausmann
1e4921de13 Fix LSP server staying alive when closing preview window
* Provide an internal behavior parameter to run_event_loop() that we can use
from the preview to not quit when the last window was closed.
* Fix Drop for the winit event loop GraphicsWindow to drop the backend window correctly
  when unmapping, not when the graphics window dies. Otherwise QuitOnLastWindowClosed doesn't work.
2021-04-06 12:11:55 +02:00
Simon Hausmann
b81803774b Start the LSP thread when the gui thread is ready
This way we can serve preview requests immediately.

This basically makes post_event safe to call before the event loop is entered.
The events will be queued up and sent when the event loop
is created and we have access
to the proxy, which will take over the queue.
2021-04-06 11:40:17 +02:00
Olivier Goffart
723b39c59a Wasm don't have threads anyway, so don't create a GLOBAL_PROXY that needs to be sync 2021-04-04 16:58:26 +02:00
Olivier Goffart
c3046f5a55 Add a way to send an event to the GUI thread from any thread
The idea is that the callback is meant to be run in the gui thread

(untested)
2021-04-03 10:00:12 +02:00
Simon Hausmann
4cbcf2611f Fix recurring C++ timers
* sixtyfps_timer_start needs to *take* the timer id out of the Rust
  timer to avoid that the subsequent drop stops the timer again
* For the Qt event loop, call `timer_event()` once before entering
  QCoreApplication::exec(), to schedule any timers that were started
  beforehand.
* Added a way to quit the event loop gently, in order to use that
  from the C++ unit test.
2021-03-25 20:07:12 +01:00
Simon Hausmann
e63baa5766 Re-organize Window and PlatformWindow construction and referencing
Initialize the self_weak in the PlatformWindow impl using the
Rc::new_cyclic pattern with a construction parameter.
2021-03-25 09:43:59 +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
6f88d78303 Rename Resource to ImageReference in the runtime 2021-03-11 10:06:23 +01:00
Olivier Goffart
89bbdce88e Polish a bit the Brush API 2021-03-10 16:54:33 +01:00
Olivier Goffart
6f715c5612 Don't call render for items outside of the clip rects 2021-03-05 13:05:02 +01:00
Simon Hausmann
27bdb4d481 Added Window.default-font-family
One step towards getting rid of `DemoText` in the printer demo
2021-03-02 13:25:21 +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
3ba92bdc6d Add API to the wasm interpreter to download and register fonts 2021-02-17 15:21:30 +01:00
Simon Hausmann
445ddd58d5 API cleanup
Remove the `application` infix from `register_application_font`, to
reduce the changes that it might be interpreted to be a function that
also changes the default font in all text elements.
2021-02-17 14:37:31 +01:00
Simon Hausmann
45fe6c3e8d Add the ability to load application fonts by path
The viewer command line tool also gains the ability to specify them via `--app-font=/path/to/font.ttf` , which can be specified multiple times.
2021-02-17 14:16:52 +01:00
Simon Hausmann
7cea088a2c Add support for letter-spacing in text
This is conveniently supported by femtovg and Qt
2021-02-16 22:14:50 +01:00
Olivier Goffart
c4e7e38590 Workaround the fact that femtovg needs to explicitly set Hole or Solid
the actual wining is lost
2021-02-16 00:20:25 +01:00
Olivier Goffart
c7723a237b GL colorize
reset properly the canvas state (such as the clip and so on)
and rotate the image otherwise it is painted upside down
2021-02-15 21:00:39 +01:00
Olivier Goffart
1a9267aebe Some debugging aide 2021-02-15 20:15:35 +01:00
Simon Hausmann
a61bbb25b7 Fix colorizing images when transformations are in play
When painting intermittendly on the image for colorization, reset the
transformation on the canvas.

Amends commit fd5757bc44
2021-02-15 20:13:47 +01:00
Simon Hausmann
799b3b16b1 GL backend: Fix clipping with transformations applied to the canvas
After commit fd5757bc44 we now need the
upstream fix to `intersect_scissor` for clipping to work
in flickable.

So patch upstream master in for now.
2021-02-15 11:17:14 +01:00
Simon Hausmann
abe95688b9 Avoid re-parsing SVG images when scaling in the GL renderer
This isn't quite 100% clean but keeping a reference to the original svg tree
is maybe a reasonable compromise for now.
2021-02-12 18:59:02 +01:00
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
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
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
Simon Hausmann
949b61bad7 Implement image colorization for the GL backend 2021-02-05 19:27:03 +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