Commit graph

5985 commits

Author SHA1 Message Date
Bill Currie
5ad6ec2757 [ui] Distribute remaining space over expand children
It's not perfect as the first N expanding children get grown by 1 pixel
regarless of weight, but it's much better than leaving a (possibly quite
large) gap at the edge of the layout.
2023-07-10 22:13:58 +09:00
Bill Currie
c18e432e0f [ui] Make windows fit to children
I'm not sure this is what I want, especially in the long run, but it
does make simple windows much easier to create (and not look broken due
to being specified too small).
2023-07-10 22:12:45 +09:00
Bill Currie
48cc4db45d [ui] Give windows a small border
It's currently hard-coded to black, but it makes the windows much easier
to see when overlapping.
2023-07-10 22:10:04 +09:00
Bill Currie
7e758327f6 [glsl] Use a unified queue for batched quads
This makes the glsl renderer compatible with canvases, and thus imui. It
also makes for much saner draw call counts.
2023-07-10 19:12:41 +09:00
Bill Currie
4e7bd11415 [build] Clean up make distcheck issues 2023-07-10 11:12:22 +09:00
Bill Currie
ac625830c8 [ui] Raise a window when its title bar is clicked
Getting to have a real UI here.
2023-07-10 00:11:24 +09:00
Bill Currie
79e4a5f6a8 [ui] Add the concept of draw order to canvases
Canvas draw order is sorted by group then order within the group. As a
fallback, the canvas entity id is used to keep the sort stable, but
that's only as stable as the ids themselves (if the canvases are
destroyed and recreated, the ids may switch around).
2023-07-09 23:27:26 +09:00
Bill Currie
c2d68f5495 [ui] Avoid creating a subpool for the canvas component
It's never used and just not needed.
2023-07-09 22:22:05 +09:00
Bill Currie
9f737000a8 [ui] Put windows on separate canvases
This fixes the draw order issues shown by overlapping windows.
2023-07-09 22:22:05 +09:00
Bill Currie
f359f47e54 [ui] Add a formatted label (like printf)
Formatted printing is just too handy, and having to use va all the time
is a bit of a pain.
2023-07-09 12:10:28 +09:00
Bill Currie
a8b80c4be5 [ui] Delete subpools when a canvas is deleted
Yet another finger in the memory dyke.
2023-07-09 12:06:08 +09:00
Bill Currie
76b6d3141b [ecs] Use correct index when deleting subpool ranges
Coming up with tests is hard. Breaking code with real code is easy.
2023-07-09 11:52:11 +09:00
Bill Currie
bf05da26cc [ui] Make Canvas_SetLen operate on only one canvas
I plan on using sub-canvases to fix the imui window overlap issue and
don't want the windows being affected by (eg) hud canvas size changes.
2023-07-08 20:56:40 +09:00
Bill Currie
c32ffce886 [ecs] Add a function to move a subpool to be the last
This has use when the order of components in the pool affects draw order
(or has other significance), especially at the subpool level. I plan to
use it for fixing overlapping windows in imui.
2023-07-08 19:55:37 +09:00
Bill Currie
9ff38418d3 [client] Move cshift into client screen canvas
This fixes cshifts affecting the console and debug canvases. The
crosshair and center print have also been moved for the same reason.
2023-07-08 14:32:02 +09:00
Bill Currie
3138c7ae3b [client] Clean up screen view creation 2023-07-08 14:04:29 +09:00
Bill Currie
8bb5d2e1c9 [vulkan] Plug a memory leak in capture
I probably need to do this for other subsystems as well, but it stood
out when chasing down another memory leak.
2023-07-08 11:15:51 +09:00
Bill Currie
79ab2f7ba7 [ui] Add a shaped text cache system
Shaped text is cached using all the shaping parameters as well as the
text itself as a key. This makes text shaping a non-issue for imui when
the text is stable, taking my simple test from 120fps to 1000fps
(optimized build).
2023-07-08 11:15:51 +09:00
Bill Currie
0360e33a00 [ecs] Add "tree mode" to hierarchies
As I had long suspected, building large hierarchies is fiendishly
expensive (at least O(N^2)). However, this is because the hierarchies
are structured such that adding high-level nodes results in a lot of
copying due to the flattened (breadth-first) layout (which does make for
excellent breadth-first performance when working with a hierarchy).

Using tree mode allows adding new nodes to be O(1) (I guess O(N) for the
size of the sub-tree being added, but that's not supported yet) and
costs only an additional 8 bytes per node. Switching from flat mode to
tree mode is very cheap as only the additional tree-related indices need
to be fixed up (they're almost entirely ignored in flat mode). Switching
from tree to flat mode is a little more expensive as the entire tree
needs to be copied, but it seems to be an O(N) (size of the tree).

With this, building the style editor window went from about 25% to about
5% (and most of that is realloc!), with a 1.3% cost for switching from
tree mode to flat mode.

There's still a lot of work to do (supporting removal and tree inserts).
2023-07-07 14:42:49 +09:00
Bill Currie
008aebf344 [console] Implement a very lame style editor
Lame partly because the color selection is not nice. However, it has
shown how slow hierarchy creation can be (it swamps font layout even).
2023-07-06 19:39:26 +09:00
Bill Currie
d8eef0be34 [ui] Avoid adding empty labels for radio buttons
More places will need it, but this fixes a problem with a large array of
just buttons.
2023-07-06 19:36:03 +09:00
Bill Currie
d4b11923b9 [ui] Add inactive labels and a style api
Labels are always good and the style api allows pushing/popping and
modifying the current style.
2023-07-06 19:34:48 +09:00
Bill Currie
b58c373f3e [ui] Use correct type for expansion calculations
Using unsigned in the calculations makes for some very large views.
2023-07-06 19:31:18 +09:00
Bill Currie
08cd03e632 [ui] Allow the parent layout rules to be modified
This makes it easy to control whether a window is a fixed size or fits
its children (or any other scheme, though those are the two most
likely).
2023-07-06 19:24:23 +09:00
Bill Currie
9b81ac1d38 [ui] Use macros for component ids
Saves me having to write the calculation every time they're needed.
2023-07-06 19:06:09 +09:00
Bill Currie
df40a50b91 [ui] Implement dragable collapsible windows
And of course, closable.
2023-07-06 12:21:14 +09:00
Bill Currie
300badc96a Fix a couple of windows build issues
There's still the problem with unused variables when building for
windows because of vulkan debug stuff, but this fixes the important
errors. It actually still works (at least under wine).
2023-07-06 02:04:47 +09:00
Bill Currie
a6e75b7617 [ui] Add a very basic style system
Nothing can be changed at the moment, but it actually looks a little
like a UI.
2023-07-06 01:27:46 +09:00
Bill Currie
b34d3cae91 [ui] Rename the imui size control enumerators
I didn't particularly like the "kind" in the name. I'm not super happy
with percent, but it will do for now.
2023-07-06 00:15:34 +09:00
Bill Currie
0fab830be6 [ui] Implement auto-expand layout
By default, horizontal and vertical layouts expand to fill their parent
in their on-axis direction (horizontally for horizontal layouts), but
fit to their child views in their off-axis.

Flexible space views take advantage of auto-expansion, pushing sibling
views such that the grandparent view is filled on the parent view's
on-axis, and the parent view is filled by the space in the parent view's
off-axis. Flexible views currently have a background fill, allowing them
to provide background filling of the overall view with minimal overdraw
(ancestor views don't need to have any fill at all).
2023-07-05 19:33:00 +09:00
Bill Currie
a92754caf1 [ui] Free the label when freeing the state
Plugs a memory leak.
2023-07-04 17:24:45 +09:00
Bill Currie
104fba13a6 [ui] Add a text color component
Despite the current rendering API taking only byte color, the component
holds a uint32_t to allow for rgba color when I figure out a suitable
API.
2023-07-04 17:17:16 +09:00
Bill Currie
7e338b7e29 [ecs] Delay calculation of last index
Removing a hierarchy from an entity can result in a large number of
component removes in the same pool, thus changing index of the lest
element of the pool. This *seems* to fix the memory corruption I've been
experiencing with the debug UI.
2023-07-04 16:37:09 +09:00
Bill Currie
71bc708030 [ecs] Use nullindex for hierarchy indices
Even though nullindex and nulent have the same value, they have very
different meanings (and I might shift to 0 for nulent).
2023-07-04 14:43:20 +09:00
Bill Currie
5000004f7d [util] Integrate sys_mem into the build
Nicely, all that was needed was a couple of includes and renaming the
functions.
2023-07-04 14:39:36 +09:00
Bill Currie
d9362e81ae [util] Add functions to get the memory usage
Found on stackexchange
(https://stackoverflow.com/questions/669438/how-to-get-memory-usage-at-runtime-using-c)
but written by David Robert Nadeau. Currently unmodified (so changes
can be tracked properly).
2023-07-04 12:49:05 +09:00
Bill Currie
403cf72f52 [ui] Implement a layout stack and radio buttons
Also, remove an intermittent double free caused by deleting views that
have already been deleted.
2023-07-04 01:31:04 +09:00
Bill Currie
6fa016e23b [vulkan] Delay main render resizes by 2s
This makes window resizing a little more responsive (though it could be
better yet (maybe, could be an X11 limitation)).
2023-07-03 23:38:57 +09:00
Bill Currie
e37b477739 [ui] Implement checkbox
Simplistic, but it works. Also cleaned up some of the repetitive code.
2023-07-03 23:33:15 +09:00
Bill Currie
cd4791c5d3 [vulkan] Get window resize working again
The biggest change was splitting up the job resources into
per-render-pass resources, allowing individual render passes to
reallocate their resources without affecting any others. After that, it
was just getting translucency and capture working after a window resize.
2023-07-03 20:05:27 +09:00
Bill Currie
45e09673c7 [vulkan] Increase (and unify) va context count
The increase wasn't really necessary, but I noticed that windows was
still at 4... not so good.
2023-07-03 19:53:53 +09:00
Bill Currie
76b110bf0b [ui] Fix use of an uninitialized pointer
I had forgotten that Hash_NewTable checked the hashctx parameter, so
calling Hash_NewTable in the struct initializer meant the hasctx was
uninitialized.
2023-07-03 16:35:51 +09:00
Bill Currie
6d823cca84 [ui] Rebuild the hierarchy every frame
This takes care of element order stability. It did need reworking the
mouse tracking code (including adding an active flag to views), but now
buttons seem to work correctly.
2023-07-03 03:52:07 +09:00
Bill Currie
0b6e8b60bd [ecs] Add a component rotation function
This allows rotation of components within the array. I'm not sure if
it's what I want, but it was an interesting exercise anyway.
2023-07-03 01:40:26 +09:00
Bill Currie
4471a40494 [vulkan] Get the forward renderer passing validation
It looks horrible due to the lack of lighting etc, but it's good enough
for basic testing, especially of my render job design (that passed with
flying colors).
2023-07-02 19:58:56 +09:00
Bill Currie
260a10d75c [vulkan] Add a very basic forward rendering pass
It's not fully compliant yet, but it sorta kinda maybe worked on my
pinebook (still slow, but no hardware vulkan :( )
2023-07-02 18:31:22 +09:00
Bill Currie
a6a0b6cb63 [ui] Use View_Delete to delete the view
It's there for a reason :P. Fixes most of the really bad behavior after
disabling some widgets (re-layout isn't working at all, though, and
adding the widgets back again puts them in the wrong place).
2023-07-02 16:40:05 +09:00
Bill Currie
7c17921277 [ui] Remove view from hash table when pruning
Fixes a segfault after removing some widgets. Otherwise, it seems
pruning is working.
2023-07-02 16:10:27 +09:00
Bill Currie
3aceccf4aa [ui] Use the same key algorithm for Hash_Find
Using label + key_offset in both imui_state_getkey and the call to
Hash_Find greatly simplifies the logic of using the correct key. Fixes
an ever-growing set of buttons when using separators (hmm, I think this
means pruning isn't working correctly).
2023-07-02 15:14:21 +09:00
Bill Currie
68e155448d [ui] Position text correctly in its view
It turns out text positioning was a little more complicated than I
remembered. The Y offset is relative to the baseline with Y going down.
2023-07-02 15:11:11 +09:00