Skip to content

figure_player ​

figure_player, a player for snapshots: previous, play, next, a slider, a speed and a loop mode.

A program that has saved solutions (snapshots 1 to N of a run, frames of an animation) keeps a player_object and draws it with ig_player every frame; the player says which snapshot to show (%index) and is true on the frame it changed it. While it plays it advances on the frame clock (Dear ImGui's time, which headless frames advance by 1/60 s each) and asks for frames, so lazy redraw does not stop it. The player is made of the public widgets of FIGURE (buttons, a slider, a context menu with a number field and radio buttons, inside a group and an id scope), so the scope record of the frame sees it balanced. widgets.md, "Players".

Source: src/lib/figure_player.F90

Dependencies

Contents ​

Variables ​

NameTypeAttributesDescription
MODEScharacter(len=6)parameterThe loop modes, in the menu's order.

Derived Types ​

player_object ​

The state of a player of count snapshots, drawn by ig_player: a plain value the program keeps (one per player) and may set at any time, as the player does when the user acts on it. index is the snapshot shown, 1 to count; playing true while it advances by itself, speed snapshots per second; mode what it does at the last snapshot: 'once' stops there, 'loop' goes on from the first, 'bounce' turns back (and again at the first). Usable before init* and from a task (it draws nothing).

Components

NameTypeAttributesDescription
indexinteger(kind=int32)The snapshot shown, 1 to count.
countinteger(kind=int32)Snapshots, >= 1.
playinglogicalAdvancing by itself.
speedreal(kind=real64)Snapshots per second while playing, > 0 [1/s].
modecharacter(len=6)'once', 'loop' or 'bounce'.
directioninteger(kind=int32)Bounce: +1 forwards, -1 backwards.
phasereal(kind=real64)Snapshots due and not yet stepped (a fraction of one).
t_lastreal(kind=real64)Frame clock at the last frame drawn [s].
frame_lastinteger(kind=int32)Dear ImGui's frame number at the last frame drawn.
was_playinglogicalplaying at the end of the last frame drawn.

Subroutines ​

advance ​

Step the snapshots due (the whole part of phase), as the mode says; once stops playing at the last.

Attributes: pure

fortran
subroutine advance(player)

Arguments

NameTypeIntentAttributesDescription
playertype(player_object)inoutThe player.

Call graph

Functions ​

ig_player ​

A player for player%count snapshots, on one line: previous, play/pause, next, and a slider over the snapshots that shows labels(player%index) (default: index / count). True on the frame the player changed player%index: a button, the slider, or the time while it plays; the program then shows that snapshot. Previous and next step one snapshot and stop the playing (in mode 'loop' they wrap around, in the others they stop at the ends); a drag of the slider stops it too; play at the last snapshot in mode 'once' starts again from the first. A right click on the player opens its menu: the speed (snapshots per second, typed; a value <= 0 is not taken) and the mode ('once', 'loop', 'bounce').

Time: while player%playing, player%speed snapshots per second of the frame clock (Dear ImGui's time: the display's frame times in a window, 1/60 s per frame headless, the time between frames in remote mode); a frame that takes longer steps more snapshots at once. The clock runs on the frames the player is drawn: hidden (a closed tab), it pauses. While playing, it asks for 1 more frame on each frame (app%request_frames), so a lazy loop keeps drawing. Its width is the current item width (ig_set_next_item_width before it, or ig_push_item_width); it is a group: ig_last_item and ig_item_rect after it report the whole player. An index outside 1 to count is moved to the nearest end (and true is returned).

Refused, nothing drawn, false and FIG_ERR_ARGUMENT in stat (or error stop without it): count < 1, speed <= 0 or not finite, an unknown mode, labels not of count entries. No frame open or a task: false, FIG_ERR_STATE. The same in window, headless and remote mode.

Attributes: recursive

Returns: logical

fortran
function ig_player(id, player, labels, stat) result(changed)

Arguments

NameTypeIntentAttributesDescription
idcharacter(len=*)inIts id, unique in the current id scope.
playertype(player_object)inoutThe player's state.
labelscharacter(len=*)inoptionalOne label per snapshot (a time, a file name).
statinteger(kind=int32)outoptionalStatus.

Call graph

speed_ok ​

A speed is finite and above 0 (NaN never compared: no invalid-operation trap in debug builds).

Attributes: elemental

Returns: logical

fortran
function speed_ok(speed) result(ok)

Arguments

NameTypeIntentAttributesDescription
speedreal(kind=real64)inSnapshots per second [1/s].

Call graph

percent_doubled ​

s with each % doubled: a label shown through a printf format as it is.

Attributes: pure

Returns: character(len=:)

fortran
function percent_doubled(s) result(r)

Arguments

NameTypeIntentAttributesDescription
scharacter(len=*)inText.

Call graph

Released under the MIT licence.