23 typedef SSIZE_T ssize_t;
26 #include "flatui/font_util.h"
27 #include "flatui/version.h"
29 #include "fplbase/asset_manager.h"
30 #include "fplbase/input.h"
31 #include "mathfu/constants.h"
108 static const int kMaxDimensions = 4;
110 static const int kSecondsToMotiveTime = 10000;
115 :
type(kAnimTypeCount),
188 fplbase::InputSystem &input, motive::MotiveEngine *motive_engine,
189 const std::function<
void()> &gui_definition);
197 fplbase::InputSystem &input,
198 const std::function<
void()> &gui_definition);
262 kEventIsDragging = 32,
322 kEditStatusInEdit = 1,
323 kEditStatusUpdated = 2,
324 kEditStatusFinished = 3,
325 kEditStatusCanceled = 4,
371 kLayoutHorizontalTop = kDirHorizontal| kAlignTop,
372 kLayoutHorizontalCenter = kDirHorizontal| kAlignCenter,
373 kLayoutHorizontalBottom = kDirHorizontal| kAlignBottom,
374 kLayoutVerticalLeft = kDirVertical | kAlignLeft,
375 kLayoutVerticalCenter = kDirVertical | kAlignCenter,
376 kLayoutVerticalRight = kDirVertical | kAlignRight,
377 kLayoutOverlay = kDirOverlay | kAlignCenter,
418 Margin(
float left,
float top,
float right,
float bottom)
419 :
borders(mathfu::vec4(left, top, right, bottom)) {}
459 void Image(
const fplbase::Texture &texture,
float ysize,
479 void Label(
const char *text,
float ysize, HashedId label_id = kNullHash);
490 void Label(
const char *text,
float ysize,
const mathfu::vec2 &size,
491 HashedId label_id = kNullHash);
503 void Label(
const char *text,
float ysize,
const mathfu::vec2 &label_size,
517 void HtmlLabel(
const char *html,
float ysize,
const mathfu::vec2 &label_size,
543 const mathfu::vec2 &offset);
560 void EnableTextSDF(
bool inner_sdf,
bool outer_sdf,
float threshold);
586 bool SetTextFont(
const char *font_names[], int32_t count);
636 Event Edit(
float ysize,
const mathfu::vec2 &size,
const char *
id,
654 const char *
id,
EditStatus *status, std::string *
string);
779 void SetScrollSpeed(
float scroll_speed_drag,
float scroll_speed_wheel,
780 float scroll_speed_gamepad);
829 const mathfu::vec4 &patch_info);
842 void StartScroll(
const mathfu::vec2 &size, mathfu::vec2 *offset);
872 void CustomElement(
const mathfu::vec2 &virtual_size,
const char *
id,
873 const std::function<
void(
const mathfu::vec2i &pos,
874 const mathfu::vec2i &size)>
886 void RenderTexture(
const fplbase::Texture &tex,
const mathfu::vec2i &pos,
887 const mathfu::vec2i &size);
900 void RenderTexture(
const fplbase::Texture &tex,
const mathfu::vec2i &pos,
901 const mathfu::vec2i &size,
const mathfu::vec4 &color);
926 const mathfu::vec4 &patch_info,
927 const mathfu::vec2i &pos,
928 const mathfu::vec2i &size);
967 const mathfu::vec2 &offset);
1017 const std::function<
void(HashedId
id,
Event event)> &callback);
1020 const FlatUIVersion *GetFlatUIVersion();
1039 template <
typename T>
1042 static const float *ToFloatArray(
const T &data);
1043 static T FromFloatArray(
const float *floats);
1044 static int Dimension();
1050 static const float *ToFloatArray(
const float &data) {
return &data; }
1051 static float FromFloatArray(
const float *floats) {
return *floats; }
1052 static int Dimension() {
return 1; }
1058 typedef mathfu::Vector<float, d> Vec;
1059 static const float *ToFloatArray(
const Vec &data) {
return &data[0]; }
1060 static Vec FromFloatArray(
const float *floats) {
return Vec(floats); }
1061 static int Dimension() {
return d; }
1067 const float *
Animatable(HashedId
id,
const float *starting_values,
1074 const float *target_velocities,
int dimensions,
1132 SequenceId
AddSprite(
const char *group_id,
1133 const std::function<
bool(SequenceId seq)> &draw);
1152 template <
typename T>
1172 template <
typename T>
1174 return Animatable<T>(HashId(
id), starting_value);
1191 template <
typename T>
1193 const T& target_velocity,
1216 template <
typename T>
1218 const T& target_velocity,
1220 StartAnimation<T>(HashId(
id), target_value, target_velocity, description);
1225 #endif // FPL_FLATUI_H
void StartSlider(Direction direction, float scroll_margin, float *value)
Make the current group into a slider group that can handle basic slider behavior. The group will capt...
void SetDragStartThreshold(int drag_start_threshold)
Set a threshold value for the start of a drag operation.
void EndGroup()
Clean up the Group element start by StartGroup().
Specifies the margins for a group, in units of virtual resolution.
Definition: flatui.h:395
double AnimationTimeRemaining(HashedId id)
Returns the time remaining for an animation.
ssize_t GetCapturedPointerIndex()
Get the index of th ecaptured pointer.
void DrawSprites(const char *group_id)
Draws all the sprites created with 'group_id' in AddSprite().
float GetScale()
Get the scaling factor for the virtual resolution.
void RenderTexture(const fplbase::Texture &tex, const mathfu::vec2i &pos, const mathfu::vec2i &size)
Render a Texture to a specific position with a given size.
mathfu::vec2 PhysicalToVirtual(const mathfu::vec2i &v)
Converts a physical screen coordinate to a virtual value.
void StartAnimation(HashedId id, const T &target_value, const T &target_velocity, const AnimCurveDescription &description)
This function sets the target value and velocity to which an animation, that is identified by id...
Definition: flatui.h:1192
void RenderTextureNinePatch(const fplbase::Texture &tex, const mathfu::vec4 &patch_info, const mathfu::vec2i &pos, const mathfu::vec2i &size)
Render a nine-patch texture at a specific position with a given size.
AnimType
Anim type describes the algorithm used to animate a UI element.
Definition: flatui.h:101
Event Edit(float ysize, const mathfu::vec2 &size, const char *id, EditStatus *status, std::string *string)
Renders an edit text box as a GUI element.
Event
Event types are returned by most interactive elements. These are flags, because multiple events may o...
Definition: flatui.h:255
FontManager manages font rendering with OpenGL utilizing freetype and harfbuzz as a glyph rendering a...
Definition: font_manager.h:109
T Animatable(HashedId id, const T &starting_value)
This function creates a new Motivator if it doesn't already exist and returns the current value of it...
Definition: flatui.h:1153
float typical_total_time
Definition: flatui.h:144
const char *const kDefaultImageID
A sentinel value for image IDs.
Definition: flatui.h:389
EditStatus
Status of Edit widget.
Definition: flatui.h:320
void Run(fplbase::AssetManager &assetman, FontManager &fontman, fplbase::InputSystem &input, motive::MotiveEngine *motive_engine, const std::function< void()> &gui_definition)
The core function that drives the GUI.
void SetTextDirection(const TextLayoutDirection direction)
Override a text layout direction set by SetTextLocale() API.
bool IsLastEventPointerType()
void SetDepthTest(bool enable)
Enables depth testing, when needed for rendering a UI in 3D.
void SetScrollSpeed(float scroll_speed_drag, float scroll_speed_wheel, float scroll_speed_gamepad)
Set the scroll speed of the drag, mouse wheel, and gamepad operations.
void SetGlobalListener(const std::function< void(HashedId id, Event event)> &callback)
Set a global listener callback that receives all events to all interactive elements (useful for loggi...
void ColorBackground(const mathfu::vec4 &color)
Set the background color for the group.
void SetTextColor(const mathfu::vec4 &color)
Set the Label's text color.
void CustomElement(const mathfu::vec2 &virtual_size, const char *id, const std::function< void(const mathfu::vec2i &pos, const mathfu::vec2i &size)> renderer)
Create a custom element with a given size.
int NumActiveSprites(HashedId id)
This function returns the current number of sprites animating on screen.
void PositionGroup(Alignment horizontal, Alignment vertical, const mathfu::vec2 &offset)
Position a group within the screen as a whole.
void StartAnimation(const char *id, const T &target_value, const T &target_velocity, const AnimCurveDescription &description)
This function sets the target value and velocity to which an animation, that is identified by id...
Definition: flatui.h:1217
Margin(float left, float top, float right, float bottom)
Creates a margin specifying all four sides individually.
Definition: flatui.h:418
void EnableTextSDF(bool inner_sdf, bool outer_sdf, float threshold)
Enable/Disable a signed distance field generation with glyphs. A SDF generation of an inner region an...
void SetTextKerningScale(float scale)
Set a kerning scale used in the text rendering.
void Image(const fplbase::Texture &texture, float ysize, const char *id=kDefaultImageID)
Render an image as a GUI element.
void Label(const char *text, float ysize, HashedId label_id=kNullHash)
Render a label as a GUI element.
void SetDefaultFocus()
Set the default keyboard/gamepad focus to the current element.
const char *const kDefaultGroupID
A sentinel value for group IDs.
Definition: flatui.h:384
void SetImageColor(const mathfu::vec4 &color)
Set the Images's tint.
void SetTextEllipsis(const char *ellipsis)
Set an ellipsis string used in label/edit widgets.
void StartGroup(Layout layout, float spacing=0, const char *id=kDefaultGroupID)
Create a group of elements with a given layout and intra-element spacing.
void EndSlider()
Ends the current slider group.
Margin(float x, float y)
Create a Margin with the left and right sizes of x, and top and bottom sizes of y.
Definition: flatui.h:408
AnimType type
Definition: flatui.h:128
TextAlignment
Alignment of the text.
Definition: font_buffer.h:110
void SetMargin(const Margin &margin)
Sets the margin for the current group.
converts from a mathfu::vector to a const float pointer and vice versa.
Definition: flatui.h:1040
void ImageBackgroundNinePatch(const fplbase::Texture &tex, const mathfu::vec4 &patch_info)
Set the background texture for the group with nine patch settings.
const float FLATUI_DEFAULT_VIRTUAL_RESOLUTION
The default virtual resolution, if none is set.
Definition: flatui.h:933
mathfu::vec2i VirtualToPhysical(const mathfu::vec2 &v)
Converts a virtual screen coordinate to a physical value.
void StartScroll(const mathfu::vec2 &size, mathfu::vec2 *offset)
Make the current group into a scrolling group that can display arbitrary sized elements inside a wind...
Margin(float m)
Create a Margin with all four sides of equal size.
Definition: flatui.h:399
void ImageBackground(const fplbase::Texture &tex)
Set the background texture for the group.
void SetTextOuterColor(const mathfu::vec4 &color, float size, const mathfu::vec2 &offset)
Set the Label's outer color (e.g. drop shadow color). To use the feature, outer SDF generation needs ...
void EndScroll()
Ends the current scrolling group.
bool SetTextFont(const char *font_name)
Set the Label's font.
void SetTextLocale(const char *locale)
Set a locale used for the text rendering.
void ModalGroup()
Called inside of a group that that is mean to act like a popup inside of a kLayoutOverlay.
SequenceId AddSprite(const char *group_id, const std::function< bool(SequenceId seq)> &draw)
This function adds a sprite, which will be drawn and then forgotten after it is finished firing...
void HtmlLabel(const char *html, float ysize, const mathfu::vec2 &label_size, TextAlignment alignment, const char *id)
Render simple HTML text.
float typical_delta_distance
Definition: flatui.h:139
void UseExistingProjection(const mathfu::vec2i &canvas_size)
By default, FlatUI sets up a projection matrix for all the rendering that covers the entire screen (a...
Direction
Direction of the groups.
Definition: flatui.h:301
T Animatable(const char *id, const T &starting_value)
This function creates a new animation if it doesn't already exist and returns the current value of it...
Definition: flatui.h:1173
void EnableTextHyphenation(bool enable)
Enable/Disable the hyphenation in the text label.
TextLayoutDirection
Specify how to layout texts. Default value is TextLayoutDirectionLTR.
Definition: font_buffer.h:75
mathfu::vec2 GetVirtualResolution()
Alignment
Alignment of the groups.
Definition: flatui.h:282
void CapturePointer(const char *element_id)
Caputre a pointer event.
Layout
Specify how to layout a group.
Definition: flatui.h:370
mathfu::vec4_packed borders
A vector of four floats containing the values for the four sides of the margin.
Definition: flatui.h:427
float bias
Definition: flatui.h:164
Describes a curve's typical shape.
Definition: flatui.h:113
void SetTextLineHeightScale(float scale)
Set a line height scale used in the text rendering.
void SetVirtualResolution(float virtual_resolution)
Set the virtual resolution of the smallest dimension of the screen (the Y size in landscape mode...
void ApplyCustomTransform(const mathfu::mat4 &imvp)
If you're rendering the UI at a location that does not correspond to the display's pixels (e...
Event CheckEvent()
Check for events from the current group.
mathfu::vec2 GroupPosition()
void ReleasePointer()
Release a pointer capture.