RigsofRods
Soft-body Physics Simulation
GUIUtils.h
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2013-2020 Petr Ohlidal
4 
5  For more information, see http://www.rigsofrods.org/
6 
7  Rigs of Rods is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License version 3, as
9  published by the Free Software Foundation.
10 
11  Rigs of Rods is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include "Application.h"
23 #include "GUIManager.h"
24 
25 namespace RoR {
26 
27 struct ImTextFeeder
28 {
29  ImTextFeeder(ImDrawList* _drawlist, ImVec2 _origin): drawlist(_drawlist), origin(_origin), cursor(_origin) {}
30 
32  void AddInline(ImU32 color, ImVec2 text_size, const char* text, const char* text_end);
34  void AddWrapped(ImU32 color, float wrap_width, const char* text, const char* text_end);
36  void AddMultiline(ImU32 color, float wrap_width, const char* text, const char* text_end);
37  void NextLine();
38 
39  ImDrawList* drawlist;
40  ImVec2 cursor;
41  ImVec2 origin;
42  ImVec2 size = ImVec2(0,0);
43 };
44 
46 void LoadingIndicatorCircle(const char* label, const float indicator_radius, const ImVec4& main_color, const ImVec4& backdrop_color, const int circle_count, const float speed);
47 
49 void DrawImageRotated(ImTextureID tex_id, ImVec2 center, ImVec2 size, float angle);
50 
52 ImVec2 DrawColorMarkedText(ImDrawList* drawlist, ImVec2 text_cursor, ImVec4 default_color, float override_alpha, float wrap_width, std::string const& line);
53 
54 std::string StripColorMarksFromText(std::string const& text);
55 
57 void ImTextWrappedColorMarked(std::string const& text);
58 
59 bool DrawGCheckbox(CVar* cvar, const char* label);
60 
61 void DrawGIntCheck(CVar* cvar, const char* label);
62 
63 void DrawGIntBox(CVar* cvar, const char* label);
64 
65 void DrawGIntSlider(CVar* cvar, const char* label, int v_min, int v_max);
66 
67 void DrawGFloatSlider(CVar* cvar, const char* label, float v_min, float v_max);
68 
69 void DrawGFloatBox(CVar* cvar, const char* label);
70 
71 void DrawGTextEdit(CVar* cvar, const char* label, Str<1000>& buf);
72 
73 void DrawGCombo(CVar* cvar, const char* label, const char* values);
74 
75 Ogre::TexturePtr FetchIcon(const char* name);
76 
77 // Fullscreen drawing helpers
78 ImDrawList* GetImDummyFullscreenWindow(const std::string& name = "RoR_TransparentFullscreenWindow");
79 bool GetScreenPosFromWorldPos(Ogre::Vector3 const& world_pos, ImVec2& out_screen);
80 
81 // Helpers for coposing combobox item strings.
82 void ImAddItemToComboboxString(std::string& target, std::string const& item);
83 void ImTerminateComboboxString(std::string& target);
84 
85 // Input engine helpers
86 void ImDrawEventHighlighted(events input_event);
87 bool ImDrawEventHighlightedButton(events input_event, bool* btn_hovered = nullptr, bool* btn_active = nullptr);
88 void ImDrawModifierKeyHighlighted(OIS::KeyCode key);
89 ImVec2 ImCalcEventHighlightedSize(events input_event);
90 
91 // Draws button which must be held for a period to report "clicked" - shows a tooltip with countdown progressbar.
92 bool ImButtonHoldToConfirm(const std::string& btn_idstr, const bool smallbutton, const float time_limit);
93 
94 } // namespace RoR
RoR::ImTextWrappedColorMarked
void ImTextWrappedColorMarked(std::string const &text)
Prints multiline text with '#rrggbb' color markers. Behaves like ImGui::Text* functions.
Definition: GUIUtils.cpp:246
RoR::ImCalcEventHighlightedSize
ImVec2 ImCalcEventHighlightedSize(events input_event)
Definition: GUIUtils.cpp:467
RoR::ImAddItemToComboboxString
void ImAddItemToComboboxString(std::string &target, std::string const &item)
Definition: GUIUtils.cpp:374
RoR::StripColorMarksFromText
std::string StripColorMarksFromText(std::string const &text)
Definition: GUIUtils.cpp:199
RoR::DrawGFloatSlider
void DrawGFloatSlider(CVar *cvar, const char *label, float v_min, float v_max)
Definition: GUIUtils.cpp:300
RoR::FetchIcon
Ogre::TexturePtr FetchIcon(const char *name)
Definition: GUIUtils.cpp:344
RoR::ImTextFeeder::cursor
ImVec2 cursor
Next draw position, screen space.
Definition: GUIUtils.h:40
RoR::ImTextFeeder::AddMultiline
void AddMultiline(ImU32 color, float wrap_width, const char *text, const char *text_end)
Wraps substrings separated by blanks. wrap_width=-1.f disables wrapping.
Definition: GUIUtils.cpp:71
RoR::DrawGCombo
void DrawGCombo(CVar *cvar, const char *label, const char *values)
Definition: GUIUtils.cpp:335
RoR::DrawGTextEdit
void DrawGTextEdit(CVar *cvar, const char *label, Str< 1000 > &buf)
Definition: GUIUtils.cpp:319
RoR::DrawGIntBox
void DrawGIntBox(CVar *cvar, const char *label)
Definition: GUIUtils.cpp:281
RoR::GetScreenPosFromWorldPos
bool GetScreenPosFromWorldPos(Ogre::Vector3 const &world_pos, ImVec2 &out_screen)
Definition: GUIUtils.cpp:518
RoR::ImTextFeeder::size
ImVec2 size
Accumulated text size.
Definition: GUIUtils.h:42
RoR::DrawColorMarkedText
ImVec2 DrawColorMarkedText(ImDrawList *drawlist, ImVec2 text_cursor, ImVec4 default_color, float override_alpha, float wrap_width, std::string const &line)
Draw multiline text with '#rrggbb' color markers. Returns total text size.
Definition: GUIUtils.cpp:204
RoR::ImDrawModifierKeyHighlighted
void ImDrawModifierKeyHighlighted(OIS::KeyCode key)
Definition: GUIUtils.cpp:451
RoR::ImTextFeeder::AddInline
void AddInline(ImU32 color, ImVec2 text_size, const char *text, const char *text_end)
No wrapping or trimming.
Definition: GUIUtils.cpp:35
RoR::DrawGFloatBox
void DrawGFloatBox(CVar *cvar, const char *label)
Definition: GUIUtils.cpp:310
RoR::ImTextFeeder::NextLine
void NextLine()
Definition: GUIUtils.cpp:117
RoR::DrawGIntSlider
void DrawGIntSlider(CVar *cvar, const char *label, int v_min, int v_max)
Definition: GUIUtils.cpp:290
RoR::ImTextFeeder
Helper for drawing multiline wrapped & colored text.
Definition: GUIUtils.h:27
GUIManager.h
RoR::GetImDummyFullscreenWindow
ImDrawList * GetImDummyFullscreenWindow(const std::string &name="RoR_TransparentFullscreenWindow")
Definition: GUIUtils.cpp:356
RoR::Str< 1000 >
RoR::ImButtonHoldToConfirm
bool ImButtonHoldToConfirm(const std::string &btn_idstr, const bool smallbutton, const float time_limit)
Definition: GUIUtils.cpp:474
Application.h
Central state/object manager and communications hub.
RoR::ImDrawEventHighlightedButton
bool ImDrawEventHighlightedButton(events input_event, bool *btn_hovered=nullptr, bool *btn_active=nullptr)
Definition: GUIUtils.cpp:424
RoR::DrawGIntCheck
void DrawGIntCheck(CVar *cvar, const char *label)
Definition: GUIUtils.cpp:272
RoR::CVar
Quake-style console variable, defined in RoR.cfg or crated via Console UI and scripts.
Definition: CVar.h:52
RoR::ImTextFeeder::AddWrapped
void AddWrapped(ImU32 color, float wrap_width, const char *text, const char *text_end)
Wraps entire input. Trims leading blanks on extra lines. wrap_width=-1.f disables wrapping.
Definition: GUIUtils.cpp:43
RoR::ImTextFeeder::ImTextFeeder
ImTextFeeder(ImDrawList *_drawlist, ImVec2 _origin)
Definition: GUIUtils.h:29
RoR::ImTextFeeder::origin
ImVec2 origin
First draw position, screen space.
Definition: GUIUtils.h:41
RoR::ImTerminateComboboxString
void ImTerminateComboboxString(std::string &target)
Definition: GUIUtils.cpp:396
RoR::DrawGCheckbox
bool DrawGCheckbox(CVar *cvar, const char *label)
Definition: GUIUtils.cpp:261
RoR::ImDrawEventHighlighted
void ImDrawEventHighlighted(events input_event)
Definition: GUIUtils.cpp:408
RoR::events
events
Definition: InputEngine.h:74
RoR::ImTextFeeder::drawlist
ImDrawList * drawlist
Definition: GUIUtils.h:39
RoR::LoadingIndicatorCircle
void LoadingIndicatorCircle(const char *label, const float indicator_radius, const ImVec4 &main_color, const ImVec4 &backdrop_color, const int circle_count, const float speed)
Draws animated loading spinner.
Definition: GUIUtils.cpp:132
RoR
Definition: AppContext.h:36
RoR::DrawImageRotated
void DrawImageRotated(ImTextureID tex_id, ImVec2 center, ImVec2 size, float angle)
Add rotated textured quad to ImDrawList, source: https://github.com/ocornut/imgui/issues/1982#issueco...
Definition: GUIUtils.cpp:175