Commit graph

93 commits

Author SHA1 Message Date
Simon Hausmann
3b971a2e2f Remove Color::From<u32>
Instead make it clear on the call site what the encoding is (argb).
2020-09-03 11:17:40 +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
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
8aae0447fd Minor doc fix
crate -> module
2020-08-31 14:14:48 +02:00
Simon Hausmann
0f052c9008 Minor doc fix for Color 2020-08-31 14:13:37 +02:00
Simon Hausmann
156e788810 Document GraphicsWindow 2020-08-31 14:12:14 +02:00
Simon Hausmann
722b7d843e Added documentation for RenderingCache 2020-08-31 14:08:01 +02:00
Simon Hausmann
684b0cba58 Document HighLevelRenderingPrimitive 2020-08-31 13:55:41 +02:00
Simon Hausmann
3010a236e0 Add docs for RenderingPrimitivesBuilder, Frame and RenderingVariable 2020-08-31 13:37:37 +02:00
Simon Hausmann
5b6e951052 Document graphics::GraphicsBackend
More docs to come for the other classes, submitting this to reduce risk of conflicts.
2020-08-31 13:24:40 +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
2823f32692 Apply license headers to all non-binary/non-json sources 2020-08-17 17:55:20 +02:00
Simon Hausmann
b96b627a4f Release graphics resources of items when destroying components
This is only implemented for Rust at the moment.
2020-08-13 13:31:29 +02:00
Simon Hausmann
3668234872 Use more fine-grained interior mutability for the rendering
Borrow the rendering and cache individually with different mutability.
We might later, for destruction handling, need to borrow the rendering
cache mutably. That in turn *may* happen even during rendering itself,
as the models are updated lazily during visitor traversal and that may
result in item destruction.
2020-08-13 11:33:34 +02:00
Simon Hausmann
89953e1957 Replace GenericWindow::window_handle() that returns a Ref with a callback
The std::cell::Ref<> exposes the way a refcell is used in a way that
makes it harder to change.
2020-08-13 11:33:34 +02:00
Simon Hausmann
d3a474af26 Move corelib::Component and friends back into their dedicated component module 2020-08-12 11:39:07 +02:00
Simon Hausmann
b21aa4f9e7 Rename PropertyListenerScope to PropertyTracker 2020-08-12 11:31:33 +02:00
Simon Hausmann
62a8b15f09 Move ItemVTable and frieds to corelib::items
To avoid ambiguities regarding the use of FieldOffset, the BuiltinItem
proc-macro uses fully-qualified type names now.
2020-08-12 10:10:51 +02:00
Simon Hausmann
aafb96cb93 Get rid of abi::datastructures::WindowProperties
Instead, pass a reference to the root item when mapping the window,
at which point we can downcast to the new Window item. If we have one,
then we'll read its width/height (for initial values) and install
bindings to keep them up-to-date.
2020-08-12 09:44:42 +02:00
Simon Hausmann
c1f91e38ca Move the window scale factor into GraphicsWindow 2020-08-11 13:42:51 +02:00
Simon Hausmann
5b90f3edf5 Unmap the window after running the component
This gives a timing wise clearly controlled shutdown of the GL context.
2020-08-11 13:27:31 +02:00
Olivier Goffart
36243ccdf7 Traverse item front to back for input events 2020-08-10 10:45:02 +02:00
Olivier Goffart
55ec533c40 WIP input events
Compile and passes tests. But the mouse event are currently not working
2020-08-07 16:06:49 +02:00
Simon Hausmann
829990f9b1 WIP
Co-authored-by: Olivier Goffart <ogoffart@woboq.com>
2020-08-07 16:06:49 +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
7ad693da60 Make window state handling more robust
Replace the three (ref)cells in the window with one refcell to an enum that
determines that the window is either unmapped (with a factory available)
or mapped (we have a graphics backend and rendering cache).
2020-08-06 16:57:19 +02:00
Simon Hausmann
99d1000749 Change interior mutability of GraphicsWindow
The interior mutability was visible to the outside via new() returning a
Rc<RefCell<..>>.

When doing deep recursions during rendering for example, that window is
mutably borrowed. That in turn prevents us from adding further members
such as window scale properties, etc. that may be read *during* that
traversal as they'd require an immutable refernce to a already mutably
borrowed refcell contents.

So instead, make the individual fields refcells.
2020-08-06 16:56:49 +02:00
Simon Hausmann
f755518dd5 Fix value of width/height on the root item if not specified
Fixes the broken gallery :-)
2020-08-05 13:33:05 +02:00
Simon Hausmann
5dfb9aa875 Fix initialize size of printer demo
Map it to 800x600 logical pixels for a better initial look.

This implements respecting the initial values for width/height and tries
to apply them to the window begin created.

The PinnedOptionalProp wrapper is needed because while cbindgen mapped
the previous Option<&...> to a raw pointer, the new Option<Pin<&...>> is
not detected as a pointer.
2020-08-05 13:22:53 +02:00
Simon Hausmann
0f1b1fd0db Fix initial value of the scale factor window property
We need to initialize it property once we have a platform window.
2020-08-05 10:49:53 +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
Simon Hausmann
48df8d0911 Rework the API between the items and the renderer
Move fields out of the HighLevelRenderingPrimitive that are suitable to
represent as uniform variables. That reduces fields like Image or
Rectangle to their image or dimension, and only if *they* change, then
we re-do the work of building geometry and uploading it to the GPU.

Instead, the typically animated properties such as the position or the
color are passed separately with each draw call. This avoids re-decoding
PNG files and uploading them again when moving an image element around
on the screen.
2020-08-05 09:44:12 +02:00
Simon Hausmann
a9297af00d Update the rendering primitives lazily using a property listener scope
This also allows avoiding the need to store the high-level rendering
primitive item in the low-level primitive struct for comparison later.
2020-08-04 22:48:03 +02:00
Simon Hausmann
685a3fb8ab Rename Text::font_pixel_size to just font_size
Since length are resolution independent, it doesn't make sense anymore
to have the pixel infix.
2020-08-04 16:56:42 +02:00
Simon Hausmann
f79b80f1e6 Split corelib::abi::sharedarray into corelib::sharedarray and corelib::sharedarray::ffi 2020-08-04 08:26:44 +02:00
Simon Hausmann
0252d2ac34 Move slice out of abi 2020-08-03 17:41:16 +02:00
Simon Hausmann
9b13b363c3 Move corelib::abi::properties to corelib::properties
And the bits that are only there for the C binding are now in an ffi sub-module.
2020-08-03 17:32:28 +02:00
Simon Hausmann
785bdb62ed Fix linking on Linux 2020-08-03 15:35:19 +02:00
Simon Hausmann
f284af27c0 Fix build without rtti 2020-08-03 14:34:34 +02:00
Simon Hausmann
37fa04098f Move MouseEvent and MouseEventType from datastructures into input 2020-08-03 13:55:33 +02:00
Simon Hausmann
30d7a0b36d Move PathData and friends from datastructure to
graphics
2020-08-03 13:43:44 +02:00
Simon Hausmann
1b270f42d0 Move datastructures::Color into graphics 2020-08-03 13:27:35 +02:00
Simon Hausmann
fa87363dc5 Move Point, Rect and Size into graphics
And move the expanded structures for cbindgen into an ffi sub-module.
2020-08-03 13:24:39 +02:00
Simon Hausmann
ce7f66320b Move datastructures::Resource into graphics
It's only used for graphics at the moment and used
for image resources.
2020-08-03 12:47:05 +02:00
Simon Hausmann
05f3ff10a6 Rename graphics::RenderingPrimitive to HighLevelRenderingPrimitive
That plays better with the existing LowlLevelRenderingPrimitive.
2020-08-03 12:39:57 +02:00
Simon Hausmann
550d0122a5 Move datastructures::RenderingPrimitive to graphics 2020-08-03 12:39:52 +02:00
Olivier Goffart
9760cf4969 Begin to implement a Flickable
The implementation is still very rough and will need to be improved
2020-07-30 14:36:21 +02:00
Simon Hausmann
c847a7b924 Fix values of width/height properties on initial show on macOS 2020-07-28 14:45:17 +02:00
Olivier Goffart
96a2efcb93 Only recompute the layout when needed 2020-07-28 10:43:06 +02:00