26#include "imgui_internal.h"
37 : drawlist(_drawlist), origin(_origin), cursor(_origin)
44 drawlist->AddText(this->cursor, color, text_begin, text_end);
45 this->cursor.x += text_size.x;
46 this->size.x = std::max(this->cursor.x - this->origin.x, this->size.x);
47 this->size.y = std::max(this->size.y, text_size.y);
52 ImVec2 size = ImGui::CalcTextSize(text_begin, text_end);
53 const float cur_width = this->cursor.x - this->origin.x;
54 if (wrap_width > 0.f && cur_width + size.x > wrap_width)
60 bool recalc_size =
false;
61 if (this->cursor.x == this->origin.x && this->cursor.y != this->origin.y)
63 while ((*text_begin ==
' ' || *text_begin ==
'\t'))
67 if (text_begin == text_end)
73 size = ImGui::CalcTextSize(text_begin, text_end);
75 this->AddInline(color, size, text_begin, text_end);
80 const char* text_pos = text_begin;
81 const char* tok_begin =
nullptr;
82 while (text_pos != text_end)
85 unsigned int c = (
unsigned int)*text_pos;
86 int bytes_advance = 1;
88 bytes_advance = ImTextCharFromUtf8(&c, text_pos, text_end);
94 if (tok_begin !=
nullptr)
96 this->AddWrapped(color, wrap_width, tok_begin, text_pos);
101 else if (c ==
' ' || c ==
'\t')
103 if (tok_begin !=
nullptr)
105 this->AddWrapped(color, wrap_width, tok_begin, text_pos);
108 this->AddWrapped(color, wrap_width, text_pos, text_pos + bytes_advance);
112 if (tok_begin ==
nullptr)
113 tok_begin = text_pos;
115 text_pos += bytes_advance;
118 if (tok_begin !=
nullptr)
120 this->AddWrapped(color, wrap_width, tok_begin, text_end);
127 const float cur_width = this->cursor.x - this->origin.x;
128 if (wrap_width > 0.f && cur_width > 0.f && cur_width + size.x > wrap_width)
134 out_rect_min = this->cursor;
137 this->cursor.x += size.x + spacing.x;
138 this->line_height = std::max(this->line_height, size.y + spacing.y);
139 this->size.x = std::max(this->size.x, this->cursor.x - this->origin.x);
140 this->size.y = std::max(this->size.y, (this->cursor.y + this->line_height) - this->origin.y);
145 this->size.y += this->line_height;
146 this->cursor.x = this->origin.x;
147 this->cursor.y += this->line_height;
148 this->line_height = ImGui::GetTextLineHeight();
155inline void ColorToInts(ImVec4 v,
int&r,
int&g,
int&b) { r=(int)(v.x*255); g=(int)(v.y*255); b=(int)(v.z*255); }
158void RoR::LoadingIndicatorCircle(
const char* label,
const float indicator_radius,
const ImVec4& main_color,
const ImVec4& backdrop_color,
const int circle_count,
const float speed)
160 ImGuiWindow* window = ImGui::GetCurrentWindow();
161 if (window->SkipItems)
166 ImGuiContext& g = *GImGui;
167 const ImGuiID
id = window->GetID(label);
169 const ImVec2 pos = window->DC.CursorPos;
170 const float circle_radius = indicator_radius / 10.0f;
171 const ImRect bb(pos, ImVec2(pos.x + indicator_radius * 2.0f, pos.y + indicator_radius * 2.0f));
172 ImGui::ItemSize(bb, ImGui::GetStyle().FramePadding.y);
173 if (!ImGui::ItemAdd(bb,
id))
178 const float t = g.Time;
179 const auto degree_offset = 2.0f * IM_PI / circle_count;
181 for (
int i = 0; i < circle_count; ++i)
183 const auto x = indicator_radius * std::sin(degree_offset * i);
184 const auto y = indicator_radius * std::cos(degree_offset * i);
185 const auto growth = std::max(0.0f, std::sin(t * speed - i * degree_offset));
187 color.x = main_color.x * growth + backdrop_color.x * (1.0f - growth);
188 color.y = main_color.y * growth + backdrop_color.y * (1.0f - growth);
189 color.z = main_color.z * growth + backdrop_color.z * (1.0f - growth);
192 window->DrawList->AddCircleFilled(ImVec2(pos.x + indicator_radius +
x,
193 pos.y + indicator_radius -
y),
194 circle_radius + growth * circle_radius,
195 ImGui::GetColorU32(color));
158void RoR::LoadingIndicatorCircle(
const char* label,
const float indicator_radius,
const ImVec4& main_color,
const ImVec4& backdrop_color,
const int circle_count,
const float speed) {
…}
203 ImDrawList* draw_list = ImGui::GetWindowDrawList();
205 float cos_a = cosf(angle);
206 float sin_a = sinf(angle);
209 center + ImRotate(ImVec2(-size.x * 0.5f, -size.y * 0.5f), cos_a, sin_a),
210 center + ImRotate(ImVec2(+size.x * 0.5f, -size.y * 0.5f), cos_a, sin_a),
211 center + ImRotate(ImVec2(+size.x * 0.5f, +size.y * 0.5f), cos_a, sin_a),
212 center + ImRotate(ImVec2(-size.x * 0.5f, +size.y * 0.5f), cos_a, sin_a)
222 draw_list->AddImageQuad(tex_id, pos[0], pos[1], pos[2], pos[3], uvs[0], uvs[1], uvs[2], uvs[3], IM_COL32_WHITE);
230ImVec2
RoR::DrawColorMarkedText(ImDrawList* drawlist, ImVec2 text_cursor, ImVec4 default_color,
float override_alpha,
float wrap_width, std::string
const& line)
233 int r,g,b, dark_r,dark_g,dark_b;
236 std::smatch color_match;
237 std::string::const_iterator seg_start = line.begin();
238 while (std::regex_search(seg_start, line.end(), color_match,
TEXT_COLOR_REGEX))
241 std::string::const_iterator seg_end = color_match[0].first;
242 if (seg_start != seg_end)
244 feeder.
AddMultiline(ImColor(r,g,b,(
int)(override_alpha*255)), wrap_width, &*seg_start, &*seg_end);
247 sscanf(color_match.str(0).c_str(),
"#%2x%2x%2x", &r, &g, &b);
248 if (r==0 && g==0 && b==0)
252 else if (r < dark_r && g < dark_g && b < dark_b)
259 seg_start = color_match[0].second;
263 if (seg_start != line.begin() + line.length())
265 const char* end_ptr = &line.c_str()[line.length()];
266 feeder.
AddMultiline(ImColor(r,g,b,(
int)(override_alpha*255)), wrap_width, &*seg_start, end_ptr);
230ImVec2
RoR::DrawColorMarkedText(ImDrawList* drawlist, ImVec2 text_cursor, ImVec4 default_color,
float override_alpha,
float wrap_width, std::string
const& line) {
…}
274 ImVec2 text_pos = ImGui::GetCursorScreenPos();
277 ImGui::GetStyle().Colors[ImGuiCol_Text],
279 ImGui::GetWindowContentRegionWidth() - ImGui::GetCursorPosX(),
282 ImRect bb(text_pos, text_pos + text_size);
283 ImGui::ItemSize(text_size);
284 ImGui::ItemAdd(bb, 0);
290 if (ImGui::Checkbox(label, &val))
300 bool val = (cvar->
getInt() != 0);
301 if (ImGui::Checkbox(label, &val))
303 cvar->
setVal(val ? 1 : 0);
310 if (ImGui::InputInt(label, &val, 1, 100, ImGuiInputTextFlags_EnterReturnsTrue))
320 if (ImGui::SliderInt(label, &val, v_min, v_max))
330 if (ImGui::SliderFloat(label, &val, v_min, v_max,
"%.2f"))
339 if (ImGui::InputFloat(label, &fval, 0.f, 0.f,
"%.3f", ImGuiInputTextFlags_EnterReturnsTrue))
347 if (ImGui::InputText(label, buf.
GetBuffer(), buf.
GetCapacity(), ImGuiInputTextFlags_EnterReturnsTrue))
351 if (ImGui::IsItemActive())
353 ImGui::TextDisabled(
"(hit Enter key to submit)");
363 int selection = cvar->
getInt();
364 if (ImGui::Combo(label, &selection, values))
376 Ogre::TexturePtr tex = Ogre::static_pointer_cast<Ogre::Texture>(
377 Ogre::TextureManager::getSingleton().createOrRetrieve(name,
"FlagsRG").first);
382 if (!tex->isLoaded())
390 return Ogre::TexturePtr();
396 ImVec2 screen_size = ImGui::GetIO().DisplaySize;
399 int window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar| ImGuiWindowFlags_NoInputs
400 | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoBringToFrontOnFocus;
401 ImGui::SetNextWindowPos(ImVec2(0,0));
402 ImGui::SetNextWindowSize(screen_size);
403 ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0,0,0,0));
404 ImGui::Begin(name.c_str(), NULL, window_flags);
405 ImDrawList* drawlist = ImGui::GetWindowDrawList();
407 ImGui::PopStyleColor(1);
424 size_t prev_size = target.size();
427 target.resize(prev_size + 1,
'\0');
430 target.insert(target.begin() + prev_size + 1, item.begin(), item.end());
440 size_t prev_size = target.size();
443 target.resize(prev_size + 2,
'\0');
448 ImVec4 col = ImGui::GetStyle().Colors[ImGuiCol_Text];
454 const ImVec2 PAD = ImVec2(2.f, 0.f);
455 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, PAD);
456 ImGui::BeginChildFrame(ImGuiID(input_event), ImGui::CalcTextSize(text.c_str()) + PAD*2);
457 ImGui::TextColored(col,
"%s", text.c_str());
458 ImGui::EndChildFrame();
459 ImGui::PopStyleVar();
464 ImVec4 col = ImGui::GetStyle().Colors[ImGuiCol_Text];
470 const ImVec2 PAD = ImVec2(2.f, 0.f);
471 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, PAD);
472 ImGui::PushStyleColor(ImGuiCol_Text, col);
473 ImGui::PushID(input_event);
474 const bool retval = ImGui::Button(text.c_str());
475 if (btn_hovered !=
nullptr)
477 *btn_hovered = ImGui::IsItemHovered();
479 if (btn_active !=
nullptr)
481 *btn_active = ImGui::IsItemActive();
484 ImGui::PopStyleColor();
485 ImGui::PopStyleVar();
491 ImVec4 col = ImGui::GetStyle().Colors[ImGuiCol_Text];
497 const ImVec2 PAD = ImVec2(2.f, 0.f);
498 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, PAD);
499 ImGui::BeginChildFrame(ImGuiID(key), ImGui::CalcTextSize(text.c_str()) + PAD*2);
500 ImGui::TextColored(col,
"%s", text.c_str());
501 ImGui::EndChildFrame();
502 ImGui::PopStyleVar();
508 const ImVec2 PAD = ImVec2(2.f, 0.f);
509 return ImGui::CalcTextSize(text.c_str()) + PAD*2;
515 ImGui::SmallButton(btn_idstr.c_str());
517 ImGui::Button(btn_idstr.c_str());
520 static const ImGuiID IMGUIID_INVALID = 0u;
521 static ImGuiID active_id = IMGUIID_INVALID;
522 static float active_time_left = 0.f;
523 const ImGuiID btn_id = ImGui::GetCurrentWindow()->GetID(btn_idstr.c_str());
525 if (ImGui::IsItemActive())
527 if (active_id != btn_id)
530 active_time_left = time_limit;
534 active_time_left -= ImGui::GetIO().DeltaTime;
535 if (active_time_left <= 0.f)
537 active_id = IMGUIID_INVALID;
542 ImGui::BeginTooltip();
543 std::string text =
_L(
"Hold to confirm");
544 ImGui::TextDisabled(text.c_str());
545 ImGui::ProgressBar(active_time_left/time_limit, ImVec2(ImGui::CalcTextSize(text.c_str()).x, 8.f),
"");
548 else if (btn_id == active_id)
550 active_id = IMGUIID_INVALID;
558 ImGuiWindow* window = ImGui::GetCurrentWindow();
559 const ImGuiID
id = window->GetID(label);
560 ImGuiContext& g = *GImGui;
563 ImGuiInputTextState* state = NULL;
564 if (g.InputTextState.ID !=
id)
569 state = &g.InputTextState;
571 state->Stb.cursor = state->CurLenW;
572 state->Stb.select_start = 0;
573 state->Stb.select_end = 0;
580 ImVec2 screen_size = ImGui::GetIO().DisplaySize;
583 Ogre::Vector3 pos_xyz = world2screen.
Convert(world_pos);
586 out_screen.x = pos_xyz.x;
587 out_screen.y = pos_xyz.y;
596 const ImVec4 LINKCOLOR = ImVec4(0.3, 0.5, 0.9, 1.0);
597 ImGui::PushStyleColor(0, LINKCOLOR);
598 ImVec2 cursorBefore = ImGui::GetCursorScreenPos();
599 ImGui::Text(caption.c_str());
600 ImVec2 textSize = ImGui::CalcTextSize(caption.c_str());
601 ImGui::GetWindowDrawList()->AddLine(
602 cursorBefore + ImVec2(0, textSize.y), cursorBefore + textSize,
604 if (ImGui::IsItemHovered())
606 ImGui::SetMouseCursor(7);
608 ImGui::PopStyleColor(1);
614 if (caption ==
"") { caption = url; tooltip =
false; }
616 if (ImGui::IsItemClicked())
620 if (tooltip && ImGui::IsItemHovered())
622 ImGui::BeginTooltip();
static const std::regex TEXT_COLOR_REGEX
void ColorToInts(ImVec4 v, int &r, int &g, int &b)
static const int TEXT_COLOR_MAX_LEN
Quake-style console variable, defined in RoR.cfg or crated via Console UI and scripts.
std::string const & getStr() const
void setStr(std::string const &str)
Wrapper for classic c-string (local buffer) Refresher: strlen() excludes '\0' terminator; strncat() A...
size_t GetCapacity() const
Str & Assign(const char *src)
< Keeps data close for faster access.
Ogre::Vector3 Convert(Ogre::Vector3 world_pos)
void OpenUrlInDefaultBrowser(std::string const &url)
InputEngine * GetInputEngine()
CameraManager * GetCameraManager()
GUIManager * GetGuiManager()
void ImDrawEventHighlighted(events input_event)
void ImDummyHyperlink(std::string caption)
Looks and behaves (mouuse cursor) like a hypertext, but doesn't open URL.
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.
void DrawGFloatBox(CVar *cvar, const char *label)
void DrawGTextEdit(CVar *cvar, const char *label, Str< 1000 > &buf)
void ImHyperlink(std::string url, std::string caption="", bool tooltip=true)
Full-featured hypertext with tooltip showing full URL.
ImDrawList * GetImDummyFullscreenWindow(const std::string &name="RoR_TransparentFullscreenWindow")
bool ImDrawEventHighlightedButton(events input_event, bool *btn_hovered=nullptr, bool *btn_active=nullptr)
void DrawGIntSlider(CVar *cvar, const char *label, int v_min, int v_max)
void ImTextWrappedColorMarked(std::string const &text)
Prints multiline text with '#rrggbb' color markers. Behaves like ImGui::Text* functions.
void DrawGIntBox(CVar *cvar, const char *label)
void ImTerminateComboboxString(std::string &target)
ImVec2 ImCalcEventHighlightedSize(events input_event)
bool GetScreenPosFromWorldPos(Ogre::Vector3 const &world_pos, ImVec2 &out_screen)
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...
void ImAddItemToComboboxString(std::string &target, std::string const &item)
void ImDrawModifierKeyHighlighted(OIS::KeyCode key)
void DrawGFloatSlider(CVar *cvar, const char *label, float v_min, float v_max)
bool DrawGCheckbox(CVar *cvar, const char *label)
std::string StripColorMarksFromText(std::string const &text)
void DrawGIntCheck(CVar *cvar, const char *label)
bool DrawGCombo(CVar *cvar, const char *label, const char *values)
Ogre::TexturePtr FetchIcon(const char *name)
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.
bool ImMoveTextInputCursorToEnd(const char *label)
bool ImButtonHoldToConfirm(const std::string &btn_idstr, const bool smallbutton, const float time_limit)
ImVec4 highlight_text_color
Helper for drawing multiline wrapped & colored text.
ImVec2 size
Accumulated text size.
ImTextFeeder(ImDrawList *_drawlist, ImVec2 _origin)
void AddInline(ImU32 color, ImVec2 text_size, const char *text, const char *text_end)
No wrapping or trimming.
void AddRectWrapped(ImVec2 size, ImVec2 spacing, float wrap_width, ImVec2 &out_rect_min)
Reserves space for i.e. an image. wrap_width=-1.f disables wrapping.
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.
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.