Commit graph

488 commits

Author SHA1 Message Date
Olivier Goffart
f1ce103c7b WIP: start splitting Window and PLatformWindow 2021-01-15 15:02:55 +01:00
Simon Hausmann
76fbf46f23 Fix rendering of the memory puzzle with the GL backend
Femtovg only accepts certain image sources. A comment in the source
suggests that a conversion could be done but that it's an expensive
operation the user should decide if it's okay or not. For us it's
okay, so let's do it.

Similarly, avoid the potential ImageSource::try_from failure when
querying just for the size, as GenericImage view has the dimensions we
need.
2021-01-15 14:09:27 +01:00
Olivier Goffart
547b2a7f6e Introduce Backend trait
Such that the font are properly registered when the GL backend is chosen at runtime
2021-01-15 12:20:32 +01:00
Simon Hausmann
c8cd073d92 Add support for partial image loading
Allow images to be just decoded and uploaded to the GPU in a separate
step. This is in preparation to implicit size support, where the actual
dimension of the image can be determined by decoding it immediately when
needed and uploaded to the GPU later (when we can be sure to have a
current GL context).

For images loaded through HTMLImageElement this is trickier, in the
sense that - unlike when loading off disk - it is inherently async.
Therefore we use a Property<bool> that we toggle when loading is
complete, in order to mark any dependent bindings as dirty, after
reporting an initial (1, 1) size.
2021-01-15 10:02:36 +01:00
Simon Hausmann
4dcbe94bff Some GL renderer cleanup
Move data structures shared between the GLRenderer and the
GLItemRenderer into a *ka-ching* shared data structure. This reduces the
amount of separate Rc instances.

Also moving the image loading functions from GLItemRenderer to
GLRendererData will allow for re-use from the GLRenderer in the future.
2021-01-15 10:02:26 +01:00
Olivier Goffart
aa7f362f10 Actually remove the GraphicsBackend completely
It is not longer in used for the abstraction between backend,
we'll make a new trait for it later
2021-01-14 17:46:30 +01:00
Olivier Goffart
7931896027 GL: Remove the Backend generic in the GenericWindow 2021-01-14 17:33:12 +01:00
Olivier Goffart
9741b56e30 Start implementing path with the Qt backend
(WIP)
2021-01-14 13:22:53 +01:00
Olivier Goffart
fff024731b Don't pass Pin by reference
(consistant with other method in that trait)
2021-01-14 11:54:17 +01:00
Simon Hausmann
42a5a62fb5 Fix rendering of image elements without specified width/height
Fall back to the source image dimensions like the old renderer
2021-01-14 08:53:14 +01:00
Olivier Goffart
a069ceae7f Fix warning with wasm 2021-01-14 08:53:14 +01:00
Simon Hausmann
de67b865dc Implement basic font fallbacks for WASM and macOS
Our demos use some symbols such as the back arrow and the ugly style
uses a down arrow for the combo box. These symbols are not in Roboto and
also not in the default font font_kit gives us on macOS.

Therefore for WASM we switch over to DejaVu, which is bigger than
Roboto.

For macOS this patch implements rudimentary fallback list generation
using CTFontCopyDefaultCascadeListForLanguages. This needs further work
to respect the locale and correctly translate styles - eventually this
should go into font-kit.

A general aspect with the font fallback handling is that femtovg doesn't
support on-demand loading yet. Instead it uses owned_ttf_parser, so
every font will be read entirely off disk. That's why for macOS we trim
the list. We could perhaps do the analysis ourselves.

Linux and Windows are to follow.
2021-01-14 08:53:14 +01:00
Simon Hausmann
cd1ef1c80e Simplify fontdb handling
`with_face_source` falls back to memmap and provides a nicer interface
2021-01-14 08:53:14 +01:00
Simon Hausmann
f4d3395f61 Prepare for font fallback lists
Separate GLFont from GLFontMetrics, the latter being as light as keeping
primarily the request around (and canvas), the former holding the list
of font resolution.
2021-01-14 08:53:14 +01:00
Olivier Goffart
fa3d26fea8 Make the fallback to GL when Qt is not available work 2021-01-14 08:53:14 +01:00
Olivier Goffart
44e279382f Qt backend: fix tests 2021-01-14 08:53:14 +01:00
Olivier Goffart
21c2100f8d Fix warnings 2021-01-14 08:53:14 +01:00
Olivier Goffart
2231711cf9 Qt text backend: draw the TextInput 2021-01-14 08:53:14 +01:00
Simon Hausmann
653fa491d9 Fix sub-image rendering
* Fix passing the correct source clip rect (width and height were missing)
* Adjust to nanovg's image rendering model where the image is basically
  a patter underneath the path rendered. So for a sub-image
  we need to offset the image pattern and scale the pattern and the path.
2021-01-14 08:53:14 +01:00
Simon Hausmann
1c8ab9829c Minor cleanup in GLFont's paint creation 2021-01-14 08:53:14 +01:00
Simon Hausmann
b79e4180c8 Rename trait Font to trait FontMetrics
This name more closely resembles the functionality it provides.
2021-01-14 08:53:14 +01:00
Olivier Goffart
62150cba1a Basic text input 2021-01-14 08:53:13 +01:00
Olivier Goffart
f396c1749f Qt backend: Don't cache the font
Not necessary after all
2021-01-14 08:53:13 +01:00
Olivier Goffart
61e6e9cf74 Qt backend: Actually fix border drawing 2021-01-14 08:53:13 +01:00
Olivier Goffart
55da32c343 Qt backend: fix border rectangle of the checkbox in the slide puzzle 2021-01-14 08:53:13 +01:00
Olivier Goffart
705c3f6ec0 Qt Backend: enable anti-aliasing 2021-01-14 08:53:13 +01:00
Olivier Goffart
b0d89d5fd7 Qt backend: font cache 2021-01-14 08:53:13 +01:00
Olivier Goffart
12e954ad03 Qt backend: properly clear the cache 2021-01-14 08:53:13 +01:00
Olivier Goffart
00f165f6ed Qt backend: cache images 2021-01-14 08:53:13 +01:00
Olivier Goffart
84c7b28256 Decouple the ItemRenderer from QPainter so it can hold a cache 2021-01-14 08:53:13 +01:00
Simon Hausmann
21bd79c1b7 Prospective C++ build fix
Include <memory> for std::unique_ptr
2021-01-14 08:53:13 +01:00
Simon Hausmann
e74159f993 Fix license header check 2021-01-14 08:53:13 +01:00
Simon Hausmann
6b300ab194 Use the latest release of femtovg 2021-01-14 08:53:13 +01:00
Simon Hausmann
98162e6325 Implement image fitting
Based on the old renderer code
2021-01-14 08:53:13 +01:00
Simon Hausmann
6c24a98036 Unify image drawing functions 2021-01-14 08:53:13 +01:00
Simon Hausmann
30bc16db73 Avoid possible leaks when loading html images and then destroying the window
Keep weak references to the canvas, etc. for the DOM closure
2021-01-14 08:53:13 +01:00
Olivier Goffart
0b20d13401 Qt backend: Implement register_application_font_from_memory 2021-01-14 08:53:13 +01:00
Simon Hausmann
54ae1310af Add support for loading remote images for wasm builds 2021-01-14 08:53:13 +01:00
Olivier Goffart
e77872c775 Let Qt handle all the highdpi thing, and don't borther within SixtyFPS
This is less than ideal, because the phx unit has no meening anymore.
Eventually we will want to do that right
2021-01-14 08:53:13 +01:00
Olivier Goffart
754020d999 Qt backend: Popup menu 2021-01-14 08:53:13 +01:00
Simon Hausmann
3dba030243 Fix wasm build
This re-enables the wasm port through femtovg's wasm support. The Roboto
is included as a generic fallback font.
2021-01-14 08:53:13 +01:00
Olivier Goffart
10dffa7d79 Use the QPainter directly when using the Qt paint engine 2021-01-14 08:53:13 +01:00
Olivier Goffart
46dbb1ee9e By default, enable the GL backend also on desktop
So it can be chosen with an env variable or if Qt is not available
2021-01-14 08:53:13 +01:00
Olivier Goffart
58904f1858 Revert "Switch to a released version of femtovg"
This reverts commit cce8fb8c3863eb9b734e0a6755ebec9fd72dc895.

The version 0.1.0 of femtovg brings an old version of harfbuzz_rs
which brings a conflicting version of freetype with font-kit
2021-01-14 08:53:13 +01:00
Simon Hausmann
930ef429ef Removed unused crate dependencies 2021-01-14 08:53:13 +01:00
Simon Hausmann
66a34cede9 Switch to a released version of femtovg
Only the wasm build will require a git version for now, which we'll patch.
2021-01-14 08:53:13 +01:00
Simon Hausmann
8c23155cae Implement text selection drawing 2021-01-14 08:53:13 +01:00
Simon Hausmann
cdfc36e881 Fix clicking into text input to place the cursor
Implement text_offset_for_x_position
2021-01-14 08:53:13 +01:00
Simon Hausmann
743bcc77f6 Render text inputs and cursors
The selection is still missing
2021-01-14 08:53:13 +01:00
Simon Hausmann
cb972402e7 Fix rendering of rectangles with large borders
Constrain the border width by the rectangle to avoid that the border
would cancel itself out when too big.

This fixes most of the checkbox rendering in the slide puzzle.
2021-01-14 08:53:13 +01:00