24 #include "imgui_internal.h"
37 this->
cursor.x += text_size.x;
38 this->
size.x = std::max(this->
cursor.x - this->origin.x, this->size.x);
39 this->
size.y = std::max(this->
size.y, text_size.y);
44 ImVec2 size = ImGui::CalcTextSize(text_begin, text_end);
45 const float cur_width = this->cursor.x - this->origin.x;
46 if (wrap_width > 0.f && cur_width + size.x > wrap_width)
52 bool recalc_size =
false;
53 if (this->cursor.x == this->origin.x && this->cursor.y != this->origin.y)
55 while ((*text_begin ==
' ' || *text_begin ==
'\t'))
59 if (text_begin == text_end)
65 size = ImGui::CalcTextSize(text_begin, text_end);
67 this->AddInline(color, size, text_begin, text_end);
72 const char* text_pos = text_begin;
73 const char* tok_begin =
nullptr;
74 while (text_pos != text_end)
77 unsigned int c = (
unsigned int)*text_pos;
78 int bytes_advance = 1;
80 bytes_advance = ImTextCharFromUtf8(&c, text_pos, text_end);
86 if (tok_begin !=
nullptr)
88 this->AddWrapped(color, wrap_width, tok_begin, text_pos);
93 else if (c ==
' ' || c ==
'\t')
95 if (tok_begin !=
nullptr)
97 this->AddWrapped(color, wrap_width, tok_begin, text_pos);
100 this->AddWrapped(color, wrap_width, text_pos, text_pos + bytes_advance);
104 if (tok_begin ==
nullptr)
105 tok_begin = text_pos;
107 text_pos += bytes_advance;
110 if (tok_begin !=
nullptr)
112 this->AddWrapped(color, wrap_width, tok_begin, text_end);
118 const float height = ImGui::GetTextLineHeight();
119 this->size.y += height;
120 this->cursor.x = this->origin.x;
121 this->cursor.y += height;
128 inline 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); }
131 void RoR::LoadingIndicatorCircle(
const char* label,
const float indicator_radius,
const ImVec4& main_color,
const ImVec4& backdrop_color,
const int circle_count,
const float speed)
133 ImGuiWindow* window = ImGui::GetCurrentWindow();
134 if (window->SkipItems)
139 ImGuiContext& g = *GImGui;
140 const ImGuiID
id = window->GetID(label);
142 const ImVec2 pos = window->DC.CursorPos;
143 const float circle_radius = indicator_radius / 10.0f;
144 const ImRect bb(pos, ImVec2(pos.x + indicator_radius * 2.0f, pos.y + indicator_radius * 2.0f));
145 ImGui::ItemSize(bb, ImGui::GetStyle().FramePadding.y);
146 if (!ImGui::ItemAdd(bb,
id))
151 const float t = g.Time;
152 const auto degree_offset = 2.0f * IM_PI / circle_count;
154 for (
int i = 0; i < circle_count; ++i)
156 const auto x = indicator_radius * std::sin(degree_offset * i);
157 const auto y = indicator_radius * std::cos(degree_offset * i);
158 const auto growth = std::max(0.0f, std::sin(t * speed - i * degree_offset));
160 color.x = main_color.x * growth + backdrop_color.x * (1.0f - growth);
161 color.y = main_color.y * growth + backdrop_color.y * (1.0f - growth);
162 color.z = main_color.z * growth + backdrop_color.z * (1.0f - growth);
165 window->DrawList->AddCircleFilled(ImVec2(pos.x + indicator_radius +
x,
166 pos.y + indicator_radius -
y),
167 circle_radius + growth * circle_radius,
168 ImGui::GetColorU32(color));
176 ImDrawList* draw_list = ImGui::GetWindowDrawList();
178 float cos_a = cosf(angle);
179 float sin_a = sinf(angle);
182 center + ImRotate(ImVec2(-size.x * 0.5f, -size.y * 0.5f), cos_a, sin_a),
183 center + ImRotate(ImVec2(+size.x * 0.5f, -size.y * 0.5f), cos_a, sin_a),
184 center + ImRotate(ImVec2(+size.x * 0.5f, +size.y * 0.5f), cos_a, sin_a),
185 center + ImRotate(ImVec2(-size.x * 0.5f, +size.y * 0.5f), cos_a, sin_a)
195 draw_list->AddImageQuad(tex_id, pos[0], pos[1], pos[2], pos[3], uvs[0], uvs[1], uvs[2], uvs[3], IM_COL32_WHITE);
203 ImVec2
RoR::DrawColorMarkedText(ImDrawList* drawlist, ImVec2 text_cursor, ImVec4 default_color,
float override_alpha,
float wrap_width, std::string
const& line)
206 int r,g,b, dark_r,dark_g,dark_b;
209 std::smatch color_match;
210 std::string::const_iterator seg_start = line.begin();
211 while (std::regex_search(seg_start, line.end(), color_match,
TEXT_COLOR_REGEX))
214 std::string::const_iterator seg_end = color_match[0].first;
215 if (seg_start != seg_end)
217 feeder.
AddMultiline(ImColor(r,g,b,(
int)(override_alpha*255)), wrap_width, &*seg_start, &*seg_end);
220 sscanf(color_match.str(0).c_str(),
"#%2x%2x%2x", &r, &g, &b);
221 if (r==0 && g==0 && b==0)
225 else if (r < dark_r && g < dark_g && b < dark_b)
232 seg_start = color_match[0].second;
236 if (seg_start != line.begin() + line.length())
238 const char* end_ptr = &line.c_str()[line.length()];
239 feeder.
AddMultiline(ImColor(r,g,b,(
int)(override_alpha*255)), wrap_width, &*seg_start, end_ptr);
247 ImVec2 text_pos = ImGui::GetCursorScreenPos();
250 ImGui::GetStyle().Colors[ImGuiCol_Text],
252 ImGui::GetWindowContentRegionWidth() - ImGui::GetCursorPosX(),
255 ImRect bb(text_pos, text_pos + text_size);
256 ImGui::ItemSize(text_size);
257 ImGui::ItemAdd(bb, 0);
263 if (ImGui::Checkbox(label, &val))
273 bool val = (cvar->
getInt() != 0);
274 if (ImGui::Checkbox(label, &val))
276 cvar->
setVal(val ? 1 : 0);
283 if (ImGui::InputInt(label, &val, 1, 100, ImGuiInputTextFlags_EnterReturnsTrue))
293 if (ImGui::SliderInt(label, &val, v_min, v_max))
303 if (ImGui::SliderFloat(label, &val, v_min, v_max,
"%.2f"))
312 if (ImGui::InputFloat(label, &fval, 0.f, 0.f,
"%.3f", ImGuiInputTextFlags_EnterReturnsTrue))
320 if (ImGui::InputText(label, buf.
GetBuffer(), buf.
GetCapacity(), ImGuiInputTextFlags_EnterReturnsTrue))
324 if (ImGui::IsItemActive())
326 ImGui::TextDisabled(
"(hit Enter key to submit)");
336 int selection = cvar->
getInt();
337 if (ImGui::Combo(label, &selection, values))
347 return Ogre::static_pointer_cast<Ogre::Texture>(
348 Ogre::TextureManager::getSingleton().createOrRetrieve(name,
"FlagsRG").first);
352 return Ogre::TexturePtr();
357 ImVec2 screen_size = ImGui::GetIO().DisplaySize;
360 int window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar| ImGuiWindowFlags_NoInputs
361 | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoBringToFrontOnFocus;
362 ImGui::SetNextWindowPos(ImVec2(0,0));
363 ImGui::SetNextWindowSize(screen_size);
364 ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0,0,0,0));
365 ImGui::Begin(
"RoR_TransparentFullscreenWindow", NULL, window_flags);
366 ImDrawList* drawlist = ImGui::GetWindowDrawList();
368 ImGui::PopStyleColor(1);
385 size_t prev_size = target.size();
388 target.resize(prev_size + 1,
'\0');
391 target.insert(target.begin() + prev_size + 1, item.begin(), item.end());
401 size_t prev_size = target.size();
404 target.resize(prev_size + 2,
'\0');
409 ImVec4 col = ImGui::GetStyle().Colors[ImGuiCol_Text];
415 const ImVec2 PAD = ImVec2(2.f, 0.f);
416 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, PAD);
417 ImGui::BeginChildFrame(ImGuiID(input_event), ImGui::CalcTextSize(text.c_str()) + PAD*2);
418 ImGui::TextColored(col,
"%s", text.c_str());
419 ImGui::EndChildFrame();
420 ImGui::PopStyleVar();
426 ImVec4 col = ImGui::GetStyle().Colors[ImGuiCol_Text];
432 const ImVec2 PAD = ImVec2(2.f, 0.f);
433 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, PAD);
434 ImGui::BeginChildFrame(ImGuiID(key), ImGui::CalcTextSize(text.c_str()) + PAD*2);
435 ImGui::TextColored(col,
"%s", text.c_str());
436 ImGui::EndChildFrame();
437 ImGui::PopStyleVar();
443 ImGui::SmallButton(btn_idstr.c_str());
445 ImGui::Button(btn_idstr.c_str());
448 static const ImGuiID IMGUIID_INVALID = 0u;
449 static ImGuiID active_id = IMGUIID_INVALID;
450 static float active_time_left = 0.f;
451 const ImGuiID btn_id = ImGui::GetCurrentWindow()->GetID(btn_idstr.c_str());
453 if (ImGui::IsItemActive())
455 if (active_id != btn_id)
458 active_time_left = time_limit;
462 active_time_left -= ImGui::GetIO().DeltaTime;
463 if (active_time_left <= 0.f)
465 active_id = IMGUIID_INVALID;
470 ImGui::BeginTooltip();
471 std::string text =
_L(
"Hold to confirm");
472 ImGui::TextDisabled(text.c_str());
473 ImGui::ProgressBar(active_time_left/time_limit, ImVec2(ImGui::CalcTextSize(text.c_str()).x, 8.f),
"");
476 else if (btn_id == active_id)
478 active_id = IMGUIID_INVALID;