Commit graph

476 commits

Author SHA1 Message Date
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
Olivier Goffart
c7ff67d0fc Move the ItemRenderer to the item_rendering module 2021-01-14 08:52:22 +01:00
Simon Hausmann
769ad146e7 Preparation for text handling
Ensure the dpi on the canvas is up-to-date before/after rendering, as
measure_text etc. rely on it and it's otherwise initialized to 1 by
default. Unfortunately this requires jumping through some hoops, but
that can be fixed later in the canvas.
2021-01-14 08:52:22 +01:00
Simon Hausmann
5906f39a47 Silence some warnings 2021-01-14 08:52:22 +01:00
Simon Hausmann
c74c8592a0 Minor simplification of new_renderer trait function
It's not necesary to pass the window dimensions when the renderer owns
the window.
2021-01-14 08:52:22 +01:00
Simon Hausmann
de4194c9ba Make ItemRenderer take &mut again
It's cleaner and indeed possible
2021-01-14 08:52:22 +01:00
Olivier Goffart
16a1b7b2bd Cache the pixmap in the native style 2021-01-14 08:52:22 +01:00
Simon Hausmann
43127cb059 Implement releasing of textures when items are destroyed
This means going back to an immutable renderer reference and interior
mutability for the canvas and the gpu cache. This is because while
traversing the item tree for rendering we may end up destroying
other items due to the lazyness of the models.
2021-01-14 08:52:22 +01:00
Simon Hausmann
1f9ba94c59 Rename the image cache
... to a more general gpu_cache and store an enum. That way we can
encapsulate the resource releasing - in the future - entirely in the
backend through run-time polymorphism in the backend (gpu cache data
enum) instead of a vtable method in the item to destruct the correct
type of data.
2021-01-14 08:52:22 +01:00
Olivier Goffart
6d316185fc Fix Painting of native widget
the cx and cy needs to be the same as the widget position
2021-01-14 08:52:22 +01:00
Olivier Goffart
b157648ab2 More work towards getting native widget with the femtovg backend 2021-01-14 08:52:22 +01:00
Simon Hausmann
7643174f28 Use interior mutability for the canvas
We're going to need it later for the resource releasing
2021-01-14 08:52:22 +01:00
Olivier Goffart
f7c8d53e7a Port the Qt Native item to the new API
this mostly restores code that was removed in commit 1a260b9dce13db38128f1f489633ba96f264d461
2021-01-14 08:52:22 +01:00
Simon Hausmann
d159a3b523 Implement caching of images
Don't re-load/decode the image every frame (and leak it), just load it
once per source change.
2021-01-14 08:52:22 +01:00
Olivier Goffart
4e9021b550 Use a type alias so that cbindgen generates the ItemVTable 2021-01-14 08:52:22 +01:00
Simon Hausmann
8cfcc9bbf9 Fix image positioning, part 2
Don't forget the item's origin
2021-01-14 08:52:22 +01:00
Simon Hausmann
9b72081f01 Fix image scaling
Scale only the image if requested, not its position
2021-01-14 08:52:22 +01:00
Simon Hausmann
d92fe445d5 Remove the old GL renderer
and try to stub in the hooks to trigger the new one
2021-01-14 08:52:22 +01:00
Simon Hausmann
607fecdb18 Simplify rendering interface
Instead of passing through a generic transformation matrix, let's just
pass through what we actually use: a translation point
2021-01-14 08:52:22 +01:00
Simon Hausmann
d4f603246c WIP: Start a femtovg backend 2021-01-14 08:52:22 +01:00
Simon Hausmann
8dea0c88d1 Beginning of a different way of rendering items
This is the start of a different rendering abstraction, the result of a
separate discussion.

The objective is to provide a better backend encapsulation, that will
make it easier to implement other backends and let the backend decide
what to cache and what not. This is done by passing the struct with the
Property<> fields directly to the backend, so that it can decide what
the cache and what to use every time.
2021-01-14 08:52:22 +01:00
Olivier Goffart
8797f6512d Rename Slider min/max property
For consistency with the SpinBox

Fixes https://github.com/sixtyfpsui/sixtyfps/issues/138
2020-12-30 10:02:38 +01:00
Olivier Goffart
56b67eac8c Complete the last patch to add a minimum/maximum properties to the SpinBox 2020-12-29 09:44:19 +01:00
Simon Hausmann
f13215ba2c Bump the glow version 2020-12-23 09:52:24 +01:00
Olivier Goffart
16f5a03c14 Run cargo fmt 2020-12-18 10:29:15 +01:00
Olivier Goffart
dfa25b96f7 Rename SharedArray to SharedVector 2020-12-18 10:26:07 +01:00
Olivier Goffart
0d2d48be4f Rename "signal" to "callback" 2020-12-18 09:51:01 +01:00
Simon Hausmann
ca1fb8ab0d Fix GPU primitive vs. rendering variable division for Rectangle
Changing the border radius or border width does not require uploading a new geometry.
Therefore these can become rendering variables.
2020-12-15 18:08:33 +01:00
Olivier Goffart
b32b7a5a7e Fix the "pressed circle" in the slide puzzle being a square on firefox android 2020-12-15 13:40:24 +01:00