Commit Graph

27 Commits

Author SHA1 Message Date
Xavier Del Campo Romero f8c74babda label.c: Set empty text by default
This will avoid crashing the application on rendering due to
uninitialized labels.
2022-09-23 04:20:13 +02:00
Xavier Del Campo Romero 9e308d97d9 gui.c: Remove unneeded condition
Even if neither hcentered or vcentered are used, GUI element position
must be determined by that of its parents.
2022-09-23 04:18:20 +02:00
Xavier Del Campo Romero 68ccd085fc gui.c: Fix minor const-correctness issues 2022-09-23 04:17:44 +02:00
Xavier Del Campo Romero d989dc6f49 gui: Allow elements to be hidden
When a GUI element is hidden, no rendering or updating is done to it or
its children. This can be useful to define a complex GUI tree structure
that changes under specific conditions, without redefining it.
2022-09-23 04:15:55 +02:00
Xavier Del Campo Romero 9d3e754f36 Implement checkbox GUI element 2022-09-23 04:12:07 +02:00
Xavier Del Campo Romero 85d4af0266 gui: fix wrong logic on update/render/deinit
The older implementation caused some elements to be
update/rendered/deinitialized more than once per call. For example,
considering the following tree of GUI elements:

A
    B
    C
        D
    E

The older implementation would update/render/deinitialize C and E more
than once, as shown below:

Update A
Update B
Update C
Update D
Update E
Update C

This was because a GUI element was acting on its siblings, but the
siblings would also act on theirs, causing the extra calls.

OTOH, as an additional improvement, no nested call is now required for
siblings.
2022-09-21 18:14:44 +02:00
Xavier Del Campo Romero 3eef29c327 menu: Implement join_menu 2022-09-20 17:34:25 +02:00
Xavier Del Campo Romero 8f9737b776 Implement GUI line edit 2022-09-20 17:34:25 +02:00
Xavier Del Campo Romero e3356fde2d gui: Implement gui_deinit 2022-09-20 17:34:25 +02:00
Xavier Del Campo Romero 4c5630b0d4 Remap calls to pad/mouse/keyboard to input 2022-09-20 16:56:30 +02:00
Xavier Del Campo Romero 96dbdea21e gui: Update elements in reverse order
This allows to calculate dimensions for containers with children
containers in it.
2022-07-15 01:03:36 +02:00
Xavier Del Campo Romero e636accfd5 Allow children of gui_container be resized anytime
So far, their position inside the container was determined when
initializing the interface. However, if a child were resized
afterwards, the container would not adjust its elements accordingly.
Moreover, the implementation for gui_container relied on hacking the
children's X/Y coordinates, which could only be done once.

Now, two additional members have been added to gui_common so that
specific X/Y offset can be determined by the parent, additionally to the
traditional rules followed by gui_coords. Despite the extra memory
footprint, it now allows containers to set specific X/Y offsets for
their children on every game cycle.
2022-07-10 00:26:48 +02:00
Xavier Del Campo Romero 251bd41c44 Allow multiple button types 2022-07-07 02:37:25 +02:00
Xavier Del Campo Romero a0363cef85 button.c: fix wrong function call 2022-07-07 02:37:25 +02:00
Xavier Del Campo Romero 4f714af054 rounded_rect.h: fix typo 2022-07-07 02:37:25 +02:00
Xavier Del Campo Romero 7325906351 gui/container: support spacing between GUI elements 2022-07-02 04:42:41 +02:00
Xavier Del Campo Romero 93d2c39b1b gui/bar: support arbitrary x/y and width 2022-07-02 04:41:22 +02:00
Xavier Del Campo Romero b0eb562b9b gui: reuse callback data
There is no need to allocate memory for these callbacks for each single
GUI element. Instead, a single, statically-allocated instance can be
shared among all GUI elements of a given type.
2022-07-02 04:08:35 +02:00
Xavier Del Campo Romero e68c2fb4be gui: implement container
Containers, somewhat inspired by GtkBox, allow to packed other GUI
elements into a single row or column.
2022-07-02 00:53:03 +02:00
Xavier Del Campo Romero 04b9219ee5 button.c: h/v-center child label by default 2022-07-02 00:50:26 +02:00
Xavier Del Campo Romero 033ed5fb94 gui.c: fix wrong logic on gui_coords
The older logic would iterate for all parents, where each parent would
again iterate for all of its parents, until no more parents found.
This is however not needed, since only inspecting the closest parent
will already cause the (recursive) algorithm to iterate for all parents.
2022-07-02 00:49:36 +02:00
Xavier Del Campo Romero ec9f41f1ab gui: allow custom add_child callback 2022-07-02 00:45:51 +02:00
Xavier Del Campo Romero 391c8958b1 button.c: fail on negative width 2022-06-29 01:01:03 +02:00
Xavier Del Campo Romero cff35e88f5 gui: implement {h,v}centered 2022-06-29 00:39:06 +02:00
Xavier Del Campo Romero 7c75118429 Revamp gui component
`gui` was tighly coupled to game logic, and could not be extended for
other purposes. Therefore, a generic GUI implementation, loosely
inspired by well-known GUI frameworks such as GTK, is now provided, with
the following properties:

- Does not depend on dynamic or static memory allocation, only automatic
(i.e., stack) memory allocation required.
- Portable among existing implementations.
- Simple to extend.
- Tiny memory footprint.

`gui` is now composed by GUI elements that can be chained to form a tree
structure. This is useful e.g.: to calculate X/Y coordinates for a given
GUI element given its parent(s).

This commit also refactors the older implementation, moving
game-specific logic into `player` and making use of the new component.
2022-06-26 20:00:27 +02:00
Xavier Del Campo Romero 3d90015c62 Replace x_get functions with macros
The PS1 port relies on a heap for primitives since the GPU renders the
scene asynchronously. However, SDL-based platforms render primitives
synchronously, so structures can be allocated on the stack instead.
2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero 8c10334252 Add project source code 2022-03-30 08:20:20 +02:00