8#include "sgui/Internals/Counters.h"
9#include "sgui/Internals/GuiGroup.h"
10#include "sgui/Internals/GuiStates.h"
11#include "sgui/Internals/ScrollerInformation.h"
26class Gui :
public sf::Drawable,
public sf::Transformable
38 sf::Texture& widgetTexture,
40 const sf::RenderWindow& window);
47 sf::Texture& widgetTexture,
49 const sf::RenderWindow& window);
57 sf::Texture& widgetTexture);
70 const Style& newStyle,
71 const bool defaultPadding =
true);
75 void setPadding (
const sf::Vector2f& padding = {0.5f, 0.125f});
85 void setView (
const sf::View& view);
94 void endFrame (
const float tooltipDelay = 0.5f);
101 const sf::RenderWindow& window,
102 const std::optional <sf::Event>& event);
127 const std::string&
text,
141 sf::Vector2f
normalizeSize (
const sf::Vector2f& panelSize)
const;
164 void setAnchor (
const std::string& key =
"");
189 sf::Vector2f
textureSize (
const std::string& texture)
const;
253 const std::string&
text,
262 void separation (
const float thickness = 0.75f);
267 const std::string& textureId,
268 const sf::Vector2f& size = {},
274 const sf::Vector2f& size,
280 const std::string&
text,
286 const std::string& iconName,
300 const std::string&
text,
307 const std::string& iconName,
318 template <
typename Type>
324 const std::string& label =
"",
325 const bool fixedWidth =
false);
329 template <
typename Type>
338 template <
typename Type>
349 const WidgetOptions& options = {});
355 const TextOptions& textOptions = {},
356 const WidgetOptions& options = {});
362 const WidgetOptions& options = {});
369 const float progress,
370 const WidgetOptions& options = {});
377 const std::vector <std::string>& list,
378 const WidgetOptions& options = {});
384 template <
typename Type>
414 const std::function<
float (
float)>& slope,
415 const float thickness = 1.f,
416 const sf::Color& lineColor = sf::Color::White);
422 const std::function<sf::Vector2f (
float)>& slope,
423 const float thickness = 1.f,
424 const sf::Color& lineColor = sf::Color::White);
429 const std::vector<sf::Vector2f>& points,
430 const float thickness = 1.f,
431 const sf::Color& lineColor = sf::Color::White);
438 void draw (sf::RenderTarget& target, sf::RenderStates states)
const override;
440 void addLastVerticalSpacing (
const float amount = 1.f);
441 void addLastHorizontalSpacing (
const float amount = 1.f);
443 void beginGroup (
const bool horizontal,
const sf::FloatRect& box);
446 sf::Vector2f computePosition (
const Panel& settings,
const Constraints& constraint);
448 sf::FloatRect handleParentClipBox (
const sf::FloatRect& box);
450 void removeClipping ();
452 ItemState interactWithMouse (
Panel& settings,
const sf::FloatRect& box,
const std::string& name,
const Tooltip& info);
454 void cachePlotData (
const std::function<
float (
float)>& slope);
455 void cachePlotData (
const std::function<sf::Vector2f (
float)>& slope);
457 void handlePlotBound ();
459 bool isPanelScrollable (
const Impl::GroupData& panel);
460 bool scrollThroughPanel (Impl::GroupData& panel,
const sf::FloatRect& panelBox,
const ItemState panelState,
const bool horizontal);
461 sf::Vector2f scroller (
float& scrollPercent,
const sf::FloatRect& panelBox,
const sf::Vector2f& scrollSize,
const ItemState panelState,
const bool horizontal);
463 float sliderBar (
const sf::FloatRect& parentBox,
const ItemState state,
const float scrollPercent,
const bool horizontal);
465 float scrollerBar (
const sf::FloatRect& parentBox,
const ItemState state,
const float scrollPercent,
const float extraSize,
const bool horizontal);
467 template <
typename Type>
468 Type sliderValue (
const sf::FloatRect& box,
const Type min,
const Type max,
const bool horizontal);
470 void tooltip (
const float apparitionDelay);
471 bool tooltipNeedReset ();
473 bool dropListItem (
float& clock,
const std::string& selectedName,
const std::string& itemName,
const sf::Vector2f& itemSize);
475 ItemState itemStatus (
const sf::FloatRect& boundingbox,
const std::string& item,
const bool condition,
const Tooltip& tooltip = {},
const bool forceActive =
false);
477 void handleKeyInput (std::string&
text,
size_t& textCursorIndex);
478 void drawTextCursor (sf::Vector2f position,
const std::string& inputTextId,
const std::string&
text,
const TextOptions& options);
479 size_t utf8Length (
const std::string&
text)
const;
481 template <
typename Type>
482 void handleNumberKeyInput (Type& number,
size_t& cursorIndex,
const bool focused,
const Type min,
const Type max);
483 template <
typename Type>
484 Type convertKeyIntoNumber (std::string& key,
const Type min,
const Type max)
const;
485 template <
typename Type>
486 std::string formatNumberToString (
const Type& number)
const;
488 std::vector<std::string> formatText (
const std::string&
text,
const sf::Vector2f& boxSize,
const TextType type =
TextType::Normal)
const;
490 uint32_t getFontSize (
const TextType type)
const;
492 std::string truncateText (
const std::string&
text,
const float width)
const;
496 void fontawesomeIcon (
const sf::Vector2f& position,
const std::string&
icon,
const uint32_t fontSize);
498 std::string initializeActivable (
const std::string& key);
499 sf::Vector2f computeRelativePosition (
const sf::Vector2f& displacement = {})
const;
501 WidgetDrawOptions drawOptions (
const WidgetAspect& standard,
const WidgetAspect& custom = {},
const bool horizontal =
true,
const float progress = 1.f)
const;
502 bool isValid (
const Widget widget)
const;
503 bool isValid (
const Slices slices)
const;
504 bool isValid (
const ItemState state)
const;
505 bool isValid (
const std::string&
image)
const;
507 sf::Vector2f widgetDescription (
const sf::Vector2f& position,
const std::string& description);
509 void updateSpacing (
const sf::Vector2f& size);
510 void updateScrolling ();
511 Impl::GroupData getParentGroup ();
513 void handleMouseInputs (
const sf::RenderWindow& window,
const std::optional <sf::Event>& event);
514 void handleKeyboardInputs (
const std::optional <sf::Event>& event);
519 bool mPlotIsBounded =
false;
520 uint32_t mPlotSample = 50u;
522 sf::Clock mInternalClock = {};
523 float mTipAppearClock = 0.f;
524 float mTipDisappearClock = 100.f;
525 float mTextCursorClock = 0.f;
527 float mPixelsPerScroll = 40.f;
529 sf::Vector2f mResetCursorPosition = {};
530 std::stack <sf::Vector2f> mSameLinePosition;
532 Impl::Counters mCounters = {};
533 Impl::GroupChecker mChecker = {};
534 std::string mWidgetChain =
"";
536 sf::Vector2f mCursorPosition = {};
537 sf::Vector2f mPadding = {6.f, 1.5f};
538 sf::Vector2f mLastSpacing = {};
539 sf::Vector2f mWindowSize;
540 sf::Vector2f mPlotBound;
541 std::string mActiveInputNumberStr;
543 bool mSoundIsOn =
false;
544 std::string mPreviousWidgetSoundId =
"";
545 std::string mActiveWidgetSoundId =
"";
546 SoundPlayer mSoundPlayer;
550 sf::Font mFontawesome;
553 PrimitiveShapeRender mColorRender;
555 Impl::InputState mInputState;
556 Impl::InternalItemState mGuiState;
558 std::stack <sf::Vector2f> mAnchors;
559 std::unordered_map <std::string, sf::Vector2f> mAnchorsWithKeys;
560 std::stack <uint32_t> mMenuClippingLayer;
561 std::stack <Impl::GroupData> mGroups;
562 ObjectPool <Impl::GroupHoverBox> mGroupsHoverBoxes;
563 ObjectPool <uint32_t> mGroupsActiveItem;
564 ObjectPool <std::string> mComboBoxActiveItem;
565 ObjectPool <size_t, std::string> mTextCursorPositions;
566 ObjectPool <uint8_t, std::string> mTextHasCursor;
567 ObjectPool <float> mComboBoxClocks;
568 ObjectPool <Panel, std::string> mInputTextPanels;
569 ObjectPool <std::vector <sf::Vector2f>> mPlotsData;
570 ObjectPool <Impl::ScrollerInformation> mGroupsScrollerData;
Definition Interpolation.h:11
Definition Interpolation.h:12
sf::Vector2f textureSize(const std::string &texture) const
to get texture size as stored in the uv mapper
Definition Gui.cpp:271
bool clickable(const sf::Vector2f &size, const WidgetOptions &options={})
display a clickable button that return true if pressed
Definition Gui.cpp:858
sf::Vector2f textSize(const std::string &text, const TextType type=TextType::Normal) const
get normal size of text in gui
Definition Gui.cpp:117
bool button(const std::string &text, const WidgetOptions &options={})
button with a text displayed over it
Definition Gui.cpp:881
void updateTimer()
to allow apparition of tooltip and animation to occur.
Definition Gui.cpp:425
sf::Vector2f lastSpacing() const
get spacing generated by the last widget Return last spacing
Definition Gui.cpp:156
void inputText(std::string &text, const TextOptions &textOptions={}, const WidgetOptions &options={})
modify text on one or multiple line
Definition Gui.cpp:1008
void addSpacing(const sf::Vector2f &amount)
add spacing
Definition Gui.cpp:162
void initialize(sf::Font &font, sf::Texture &widgetTexture, const TextureAtlas &widgetAtlas, const sf::RenderWindow &window)
initialize window size and all required resources this need to be called once before beginFrame/endFr...
Definition Gui.cpp:33
void slider(Type &value, const Type min, const Type max, const WidgetOptions &options={})
slider to vary value between min and max
void endMenu()
endMenu need to be called to clean state after beginMenu.
Definition Gui.cpp:702
void addLastSpacing(const float amount=1.f)
to add (amount > 0) or remove (amount < 0) last widget spacing
Definition Gui.cpp:170
void inputColor(sf::Color &color, const WidgetOptions &options={})
modify a color value through text
Definition Gui.cpp:1172
void inputKey(char &key, const WidgetOptions &options={})
modify a specific character
Definition Gui.cpp:1133
sf::Vector2f activePanelSize() const
get active panel or window size
Definition Gui.cpp:131
void setPadding(const sf::Vector2f &padding={0.5f, 0.125f})
set padding of widgets
Definition Gui.cpp:82
void beginMenu()
menu bar in which menu item can be arranged. Note that it need to be called in a window or box with h...
Definition Gui.cpp:669
std::string comboBox(const std::vector< std::string > &list, const WidgetOptions &options={})
display selected item and all others selectables items when clicked
Definition Gui.cpp:1349
void update(const sf::RenderWindow &window, const std::optional< sf::Event > &event)
set-up inputs for gui interaction.
Definition Gui.cpp:408
sf::Vector2f normalizeSize(const sf::Vector2f &panelSize) const
normalize size of a panel Return panel size in fraction
Definition Gui.cpp:141
void sameLine()
go back to previous line/column, next to the last widget
Definition Gui.cpp:197
void endWindow()
enWindow need to be called to clean state after beginWindow.
Definition Gui.cpp:581
bool isActive() const
to know if some part of the gui are active or hovered. It must be called before endFrame.
Definition Gui.cpp:254
Gui()
load fontawesome and initialize window size.
Definition Gui.cpp:17
void inputVector3(sf::Vector3< Type > &vector, const WidgetOptions &options={}, const sf::Vector3< Type > &min={}, const sf::Vector3< Type > &max={})
modify a vector3 value through text, using three inputNumber call
bool checkBox(bool &checked, const WidgetOptions &options={})
display textured box that can be checked
Definition Gui.cpp:917
sf::Vector2f parentGroupSize()
to get size of the active parent group
Definition Gui.cpp:262
void setSample(const uint32_t sample)
Definition Gui.cpp:1238
void inputNumber(Type &number, const WidgetOptions &options={}, const Type min=0, const Type max=0, const std::string &label="", const bool fixedWidth=false)
modify a number value through text
sf::Vector2f cursorPosition() const
get current cursor position of the gui
Definition Gui.cpp:245
void setPixelsPerScroll(const float amount)
set scroll wheel strength (should be ~ 20.f)
Definition Gui.cpp:88
void setTextureAtlas(const TextureAtlas &widgetAtlas)
set texture atlas
Definition Gui.cpp:56
void setPlotRange(const PlotRange xRange, const PlotRange yRange)
set plot range and number of points sampled
Definition Gui.cpp:1229
float textHeight(const TextType type=TextType::Normal) const
to have standard height size across gui code
Definition Gui.cpp:125
void endFrame(const float tooltipDelay=0.5f)
this function must be called at the end of every loop.
Definition Gui.cpp:292
void setScreenSize(const sf::Vector2f &size)
set screen size, its required for panel and window to call it if no Gui::update was called
Definition Gui.cpp:419
void setStyle(const Style &newStyle, const bool defaultPadding=true)
to change font size, color and item padding.
Definition Gui.cpp:69
void unsetPlotBound()
remove plot bound.
Definition Gui.cpp:1252
void beginFrame()
this function must be called at the start of every loop.
Definition Gui.cpp:280
void setPlotBound(const sf::Vector2f &bound)
set plot size. This depend on the context of use. In a window/panel, plot bound will be limited to th...
Definition Gui.cpp:1245
void progressBar(const float progress, const WidgetOptions &options={})
display advancement of a value between 0 and 1
Definition Gui.cpp:1200
void setResources(sf::Font &font, sf::Texture &widgetTexture)
set resources
Definition Gui.cpp:47
sf::Vector2f denormalizeSize(const sf::Vector2f &panelSize) const
denormalize size of a panel Return panel size in pixels
Definition Gui.cpp:147
void setView(const sf::View &view)
to set gui view
Definition Gui.cpp:106
bool icon(const std::string &iconName, const WidgetOptions &options={})
clickable icon that work like a button
Definition Gui.cpp:899
void setAnchor(const std::string &key="")
register a position at which you can go back with backToAnchor.
Definition Gui.cpp:206
void fontawesome(const std::string &iconName, const TextType type=TextType::Normal)
display a fontawesome icon
Definition Gui.cpp:993
void text(const std::string &text, const TextOptions &textOptions={}, const WidgetOptions &options={})
display text, if a box size is given it will be formatted to fit in
Definition Gui.cpp:951
void backToAnchor(const std::string &key="")
go back to the last setAnchor position set.
Definition Gui.cpp:217
Style & style()
get current style of the gui
Definition Gui.cpp:94
void setSounds(SoundHolder &sounds)
this must be called once if user want to have sound effects
Definition Gui.cpp:62
void forcePlotUpdate()
force cache update
Definition Gui.cpp:1298
void separation(const float thickness=0.75f)
draw a simple line that span the current group width
Definition Gui.cpp:814
void beginPanel(Panel &settings, const Constraints &constraint={}, const WidgetOptions &options={})
static box in which widget will be arranged.
Definition Gui.cpp:601
bool menuItem(const std::string &text, const WidgetOptions &options={})
menu item are clickable button aligned along menu bar. It need to be enclosed in a beginMenu; { menuI...
Definition Gui.cpp:722
void endPanel()
endPanel need to be called to clean state after beginPanel.
Definition Gui.cpp:645
bool beginWindow(Panel &settings, const Constraints &constraint={}, const WidgetOptions &options={})
windows in which widgets will be arranged, their position are automatically computed....
Definition Gui.cpp:456
void inputVector2(sf::Vector2< Type > &vector, const WidgetOptions &options={}, const sf::Vector2< Type > &min={}, const sf::Vector2< Type > &max={})
modify a vector2 value through text, using two inputNumber call
void plot(const std::function< float(float)> &slope, const float thickness=1.f, const sf::Color &lineColor=sf::Color::White)
plot a function R -> R. The data is cached and not recomputed until user request an update with force...
Definition Gui.cpp:1258
void image(const std::string &textureId, const sf::Vector2f &size={}, const WidgetOptions &options={})
draw an image
Definition Gui.cpp:837
store text accessible with a string key, with option to load and store text for a given tongue,...
Definition TextContainer.h:15
Contains texture position and sub-box of all sprites for a given sprite sheet. Animations ca be handl...
Definition TextureAtlas.h:28
Definition Interpolation.h:16
Slices
Defines number of slices for stretchable widgets.
Definition Widgets.h:39
ItemState
List gui elements states.
Definition ItemStates.h:11
TextType
Text type.
Definition Options.h:13
@ Normal
Definition Options.h:16
ResourcesHolder< sf::SoundBuffer > SoundHolder
Definition ResourcesHolder.h:77
Widget
List widget textures available in gui.
Definition Widgets.h:11
Store constraints on position for gui panel. Alignment always precede relative position.
Definition Constraints.h:36
store panel posiiton, size and some parameters
Definition Panel.h:16
plot range for an axis
Definition Plotter.h:14
define gui font style and padding
Definition Style.h:27
Store text options : boxSize, centered, type, etc.
Definition Options.h:74
small struct to ease use of beginPanel and beginWindow in Gui
Definition Panel.h:41