Commit graph

171 commits

Author SHA1 Message Date
Simon Hausmann
9a24113acb Use the winit window DPR instead of the QGuiApplication one
A per-window setting will allow correct values when moving windows across screens.
2020-09-15 16:03:58 +02:00
Simon Hausmann
79ba5d9de8 Provide a window reference in various ItemVTable functions
Access to the window, in particular the scale factor, will be needed in a few places.
2020-09-15 15:55:47 +02:00
Simon Hausmann
02d18b09cf Fix warning about x not needing to be mutable 2020-09-15 11:21:01 +02:00
Simon Hausmann
546818ee55 Add key event data structures and event function boiler plate 2020-09-15 11:16:55 +02:00
Simon Hausmann
c69781ace2 Upgrade glow 2020-09-15 11:14:23 +02:00
Simon Hausmann
4f5d491bf7 Minor cleanup
Remove GL context parameters from texture functions that aren't needed.
2020-09-15 09:02:34 +02:00
Simon Hausmann
7c6fd90924 Fix layouting_info with QStyle and High-DPI displays
QStyle returns logical coordinates while SixtyFPS operates on physical
coordinates, so an extra multiplication is needed.

This is a temporary fix until we have access to the concrete (winit)
window we're rendering to, in order to apply the correct DPR.
2020-09-11 08:31:38 +02:00
Simon Hausmann
b82f39ad84 Fix rendering into the QImage with QStyle on high-dpi displays
Apply the DPR to the QImage and reduce the logical rect accordingly.
This ensures that text is scaled well.
2020-09-11 08:18:37 +02:00
Simon Hausmann
bf396ad578 Draw *something* with the mac style
A CGBitmapContext can only be created on a 32bpp/8bpc QImage if the
alpha channel is pre-multiplied.  That context is needed to draw cocoa
controls to the QImage. So create a QImage with pre-multipled alpha.
Fortunately our blend mode in the GL renderer already supports that.

Also a QWidget is needed to have an NSView (through the widget's backing store).
2020-09-11 08:18:37 +02:00
Simon Hausmann
0c2a557b95 Remove QtQuick and QtQml linkage for the Qt backend
We don't need these libraries at the moment.
2020-09-11 08:18:07 +02:00
Simon Hausmann
23ba165752 Remove the use of QApplication::globalStrut()
That is AFAIK a deprecated concept.
2020-09-09 18:55:43 +02:00
Simon Hausmann
ca16b6c082 Clean up the QImage setup for rendering with QStyle
Centralize the code in one function, so that we can later change it to
deal with different device pixel ratios. The function returns an image
and a QRect that contains the logical size.
2020-09-09 18:55:33 +02:00
Olivier Goffart
8761ca80a3 Add SharedArray::push and adjust a bit the API 2020-09-09 18:47:15 +02:00
Simon Hausmann
5801b90f66 Don't crash when Qt and winit fight for application delegates
winit sets an NSApplicationDelegate on the NSApplication and expects it
to remain there. We must instruct Qt not to install its own application delegate, to avoid
winit being confused.
2020-09-09 15:45:27 +02:00
Simon Hausmann
19cce012a0 Add ARGBColor<T> to the color API
As discussed in the last API review, this replaces the as_rgba_f32/u8
"accessor" functions by returning a struct with named fields.
2020-09-08 22:11:23 +02:00
Olivier Goffart
e997dff094 Use a reference as a signal argument.
It will be easier to make that work with C++
2020-09-08 12:12:01 +02:00
Simon Hausmann
220dc2ee47 Fix rendering of rounded rectangles in examples preview
For something like

    Window {
        GridLayout {
            Rectangle {
                border_width: 2lx;
                border_radius: 2lx;
                border_color: black;
            }
        }
    }

The border was not fully visible and partly obscured by the window
frame, the canvas element in the case of the preview in the examples.
That looks bad, and this patch fixes it by respecting the border width
in the geometry used to stroke and fill the rectangle.
2020-09-04 14:27:58 +02:00
Simon Hausmann
b50e42a7ba Avoid large empty canvas elements in the html docs
Some of the example code does not include a Window {} element with a
size.  The html says <canvas width=100 height=100> but it turns out that
winit is not interested in these values and any newly created window
with a canvas will get an initial size of 1024x768.

This is not quite the behavior we want, preserving the canvas size may
be more sensible -- it certainly is for our docs. So this patch tries to
preserve that.
2020-09-04 10:12:34 +02:00
Olivier Goffart
1cf6d81169 Impletment GroupBox with the Qt style 2020-09-02 17:05:28 +02:00
Olivier Goffart
953d3e0422 Fix crash when rendering an empty widget
QPainter does not like to draw in an empty QImage.
And the rendering code does not like to render it.

So we would get this on the console:

```
QPainter::begin: Paint device returned engine == 0, type: 3
QPainter::save: Painter not active
QPainter::save: Painter not active
QPainter::setRenderHint: Painter must be active to set rendering hints
QPainter::save: Painter not active
QPainter::setClipRegion: Painter not active
QPainter::setPen: Painter not active
QPainter::setBrush: Painter not active
QPainter::restore: Unbalanced save/restore
QPainter::setPen: Painter not active
QPainter::setBrush: Painter not active
QPainter::restore: Unbalanced save/restore
QPainter::save: Painter not active
QPainter::restore: Unbalanced save/restore
QPainter::restore: Unbalanced save/restore
thread 'main' panicked at 'attempt to subtract with overflow', sixtyfps_runtime/rendering_backends/gl/texture.rs:285:42
```
2020-09-02 11:50:19 +02:00
Simon Hausmann
570e51eaa9 Improve API of color handling of text
Make the text color a rendering variable, so that it can be passed
through as uniform to the glyph shader and applied to the gray
map of the glyphs. This avoids re-creating the glyph runs when
merely the color changes.

This already "worked" for the glyph cache based text rendering,
but it wasn't used because of the wasm canvas code path. This
patch changes that to render the text into a text using simply black
and then render that texture using our existing glyph shader,
which merely uses the alpha channel anyway.

This reduces also #cfg's.
2020-09-02 11:48:41 +02:00
Olivier Goffart
9782d85fdb Native style works with C++ 2020-09-01 12:25:11 +02:00
Olivier Goffart
f1ad78bc25 Qt style support for the rust backend
Need to set the SIXTYFPS_STYLE=native env variable while compiling
2020-09-01 12:25:11 +02:00
Olivier Goffart
9d5f27db0b Rename QtStyle to Native 2020-09-01 12:25:11 +02:00
Olivier Goffart
27288c65e2 fixup previous commit
I had inverted the condition to test locally
2020-09-01 10:15:31 +02:00
Olivier Goffart
b27f64756e In the Qt backend, having Qt is the default and not having it is the exception
Simplify the config
2020-09-01 09:58:25 +02:00
Simon Hausmann
ebada75431 Fix build without Qt 2020-09-01 09:01:01 +02:00
Olivier Goffart
60201b9c7b Update dependencies 2020-08-31 17:38:22 +02:00
Olivier Goffart
6d41b1981d Move the Qt style to a new backend: the Qt backend
Currently the Qt backend still redirect everything to the GL backend,
but the goal is to use QPainter and QWindow

This also adds a "default" backend, whose goal is to select the proper
backend at compile time
2020-08-31 17:26:04 +02:00
Simon Hausmann
07fa020e81 Fix flickering in gallery example when pressing spin box buttons
The path shader uses only one attribute array, while the others use two.
First rendering with say the glyph shader and then the path one may leave
odd artifacts around with GLES, which is fixed by properly disabling the
vertex attribute arrays after use.

Closes: #17
2020-08-28 17:49:45 +02:00
Olivier Goffart
65acdd78b0 Use xtask to generate the headers instead of build.rs of each lib
Fixes #14
2020-08-27 11:50:09 +02:00
Olivier Goffart
80dd7dcb04 Allow to specify the canvas id when creating a new window with wasm 2020-08-26 17:01:17 +02:00
Olivier Goffart
58cdaeb8dd Update license header to mention that commertial option are available 2020-08-26 13:23:42 +02:00
Simon Hausmann
14fe897086 Move all cbindgen generated code into
sixtyfps::cbindgen_private

Having private in the name makes it clear that this is ... private,
and cbindgen helps remember that it's generated.
2020-08-25 15:29:48 +02:00
Olivier Goffart
ea1f215367 Some polishinbg of the .toml files
- Give all the sixtyfps-* create a 0.0.1 version
 - Make sure that the internal dependences are using the exact same version
   (so "=0.0.1")
 - Add the description/homepage/repository fields in the .toml files
 - Set publish=false  to crates that are not meant to be published on crates.io
2020-08-24 16:28:11 +02:00
Simon Hausmann
7f1d9f5252 Commit correct license tags to Cargo.toml
For now that's GPL-3.0 only, but this can be changed :-)
2020-08-18 10:12:59 +02:00
Simon Hausmann
2823f32692 Apply license headers to all non-binary/non-json sources 2020-08-17 17:55:20 +02:00
Simon Hausmann
a54f222e52 Clean up glyph run creation code
Move more into the glyph cache module
2020-08-13 10:48:27 +02:00
Simon Hausmann
df2620838e Improve RefCell usage
Use a RefCell only where we need it, in the glyph cache. We don't need
it for the platform data.
2020-08-13 10:23:08 +02:00
Simon Hausmann
674a25cfdc Fix leaks of vertex and index buffers
Free them like the other GL resources

Closes: #3
2020-08-12 15:25:54 +02:00
Simon Hausmann
7807631ba0 Fix leaking texture atlas allocations
When a rendering primitive holding a reference into a texture atlas
allocation is dropped, we should free that area for future re-use.
2020-08-10 17:30:41 +02:00
Simon Hausmann
d6ef7c31a8 Fix rendering artifacts when scaling
The use of the texture atlas may result in pixels from adjacent textures
bleeding into the currently rendered texture. The standard technique appears to be
to add a padding around each image.
2020-08-10 15:53:44 +02:00
Simon Hausmann
ccb2e23cf5 Fix GL texture not freeing its texture id
Similar to the shaders, keep a reference count on the resource itself and
keep the context around for convenient deletion.

Fixes: #3
2020-08-10 11:20:58 +02:00
Simon Hausmann
6faf7439c2 Delete GL shader programs automatically
We already keep the context in an RC, might as well keep another copy :-)

This re-applies commit 9b0dfa14b5 but
replaces the Clone trait on Shader, which would lead to duplicate and
too early program deletion, with an Rc<Shader>.
2020-08-10 11:20:58 +02:00
Simon Hausmann
d9c776eb57 Revert "Delete GL shader programs automatically"
This reverts commit 9b0dfa14b5 as there's
an issue with webgl and everything disappearing.
2020-08-10 09:50:04 +02:00
Simon Hausmann
9b0dfa14b5 Delete GL shader programs automatically
We already keep the context in an RC, might as well keep another copy :-)
2020-08-08 13:31:37 +02:00
Simon Hausmann
f86f8360b2 Fix rendering of text with spaces
Don't waste glyphs and potential pixels from the rasterizer for space --
merely use the advance.
2020-08-07 15:32:59 +02:00
Simon Hausmann
aecf6a8878 Center text in buttons in the demo and gallery
This adds horizontal_alignment/vertical_alignment properties, along with
width/height to Text.

This still uses a hard-coded enumeration in the compiler, which is meant
to go away in favor of general enum support.
2020-08-07 10:02:52 +02:00
Simon Hausmann
b6a5810bdc Fix wasm build 2020-08-05 11:10:39 +02:00
Simon Hausmann
d3c596669c Add larger icons to the printer demo
The icons on the main screen are now nicely large and they scale down on
activation.
2020-08-05 10:04:11 +02:00