Commit graph

454 commits

Author SHA1 Message Date
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
Olivier Goffart
7bd1fb9ec8 Silence warning 2021-01-14 08:53:13 +01:00
Olivier Goffart
1ea522a7d0 Qt backend: Make the animation not take 100% CPU 2021-01-14 08:53:13 +01:00
Olivier Goffart
7dfc43977f Qt backend: animations 2021-01-14 08:53:13 +01:00
Olivier Goffart
118d40d9e9 QtBackend: Timer 2021-01-14 08:53:13 +01:00
Olivier Goffart
7b4c600a4f Fix compilation after rebase 2021-01-14 08:53:13 +01:00
Olivier Goffart
d4c357195d Qt backend: make clicking on a TextInput not panic 2021-01-14 08:53:13 +01:00
Olivier Goffart
1eac260d99 Qt Backend: font size fixes 2021-01-14 08:53:13 +01:00
Olivier Goffart
d71bb9ab84 Qt backend: Image rendering 2021-01-14 08:53:13 +01:00
Olivier Goffart
49c9881d10 fix compile 2021-01-14 08:53:13 +01:00
Olivier Goffart
7d91651b48 Qt backend: input events 2021-01-14 08:53:13 +01:00
Olivier Goffart
4aa9faf532 Qt backend: border rectangle 2021-01-14 08:53:13 +01:00
Olivier Goffart
aeb67fa927 Qt backend: Resize event and layouting 2021-01-14 08:53:13 +01:00
Olivier Goffart
531ff42973 WIP: Qt backend using Qt 2021-01-14 08:53:13 +01:00
Simon Hausmann
35f51fe339 Clean up FontRequest interface
Represent a non-specified pixel size and font weight through a None option.

This is cleaner and has the added benefit that the backend can now
easily decide what the default size/weight should be.
2021-01-14 08:53:13 +01:00
Simon Hausmann
36c41ef758 Simplify font interface in the backend
For the GL backend a resolved font is just a handle (femtovg::FontId)
and we can cache that. Consequently we don't really need Rc<dyn Font>
but can let `fn font(...)` on the backend return a "resolved" font that
includes the pixel size, which in turn simplifies the Font trait
signatures.

The only caveat is that because on the item level we don't know what the
chosen backend type is, we can only receive a `dyn Font`, which means
it's wrapped - for now - in a Box.
2021-01-14 08:53:13 +01:00
Simon Hausmann
a684f36b8d Simplify children clip handling
Use a save/restore state pattern for the entire renderer instead of passing around clip rectangles as data structure.

That's less data copying and maps naturally to existing mechanisms,
which in turn can use their own dirty handling to make
save_state/restore_state as cheap as possible.
2021-01-14 08:53:13 +01:00
Simon Hausmann
4aea74358c Improve rendering of rectangle borders
The border should extend to the inside of the rectangle,
like in CSS.
2021-01-14 08:53:13 +01:00
Simon Hausmann
fa15accbbd Load images referenced by multiple items only once
Re-apply the caching mechanism from the old renderer
that keeps weak references and drains them after frame rendering.

This fixes switching between the themes in the slide puzzle.
2021-01-14 08:53:13 +01:00
Simon Hausmann
edb17f996f Move the entire custom application font handling into the backend
Some backends may not require a copy of the data, for example.
2021-01-14 08:53:13 +01:00
Simon Hausmann
1ed35fb628 Replace uses of FIELD_OFFSETS.foo.apply_pin(bar) with bar.foo() 2021-01-14 08:53:13 +01:00
Simon Hausmann
65dcb2cb33 Merge BuiltinItem and GeneratePropertyAccessors derive macros
... into the new SixtyFPSElement macro. This generates getters for all properties.
2021-01-14 08:53:13 +01:00
Simon Hausmann
a48f4253a2 Minor cleanup in draw_text
Create the font request on the text item side to reduce duplication and
remove the fallback logic from the font_weight accessor, in preparation
for automatic generation of that getter.
2021-01-14 08:53:13 +01:00
Simon Hausmann
a02186df22 Add support for application fonts
Needed to run the sliding puzzle demo
2021-01-14 08:53:13 +01:00
Olivier Goffart
0522b04d70 Rename create_gl_window to create_window 2021-01-14 08:53:13 +01:00
Simon Hausmann
cd915ddbe0 More vertical text alignment fixes - makes the printer demo look better
* When calculating the height of text for vertical alignment purposes,
  don't use the minimum height but stick to ascent + descent - like the old
  renderer. This gives Text items a constant height that depends on the
  font size and not the content.
* Avoid scaling text metrics twice. It turns out that femtovg uses the
  device pixel ratio / dpi argument for `set_size` only for scaling text
  metrics. Since we do all the mapping from logical pixels to physical pixels
  it's correct to let femto only operate in physical pixel range. As a bonus
  this allows removing the refresh_window_scale_factor() dance in the
  backend (including making the context current, etc.)
2021-01-14 08:53:13 +01:00
Simon Hausmann
b61c1e3af7 Fix baseline for text items
In the previous renderer the text, by default, is drawn at the top of the
bounding box. The default femtovg alignment is more like QPainter, but
that's not quite what we want here.
2021-01-14 08:53:13 +01:00
Simon Hausmann
065d717814 Fix missing rectangle border rendering 2021-01-14 08:53:13 +01:00
Simon Hausmann
76cee4a598 Fix some warnings about unused variables or imports 2021-01-14 08:53:13 +01:00
Simon Hausmann
9d7e151cb9 Simplify property access code in the renderer
Generate convenient property accessors using a derive macro
2021-01-14 08:53:13 +01:00
Olivier Goffart
9ef1c36a52 Move the eventloop module to the backend 2021-01-14 08:53:13 +01:00
Olivier Goffart
ab08502c77 Move the GraphicsWindow to the graphics backend 2021-01-14 08:53:13 +01:00
Simon Hausmann
41910f6694 Remove HasFont trait
This was only used for syntactic sugar which, as it turns out,
we can also have with a regular associated function that takes
Pin<&Self> \o/
2021-01-14 08:53:13 +01:00
Simon Hausmann
727c9a19f7 Add basic text item support
This needs more work, but gets something onto the screen at least.
2021-01-14 08:53:13 +01:00
Olivier Goffart
9050c29305 Don't use the window through the eventloop module 2021-01-14 08:53:13 +01:00