25 #include "imgui_internal.h"
38 this->
cursor.x += text_size.x;
39 this->
size.x = std::max(this->
cursor.x - this->origin.x, this->size.x);
40 this->
size.y = std::max(this->
size.y, text_size.y);
45 ImVec2 size = ImGui::CalcTextSize(text_begin, text_end);
46 const float cur_width = this->cursor.x - this->origin.x;
47 if (wrap_width > 0.f && cur_width + size.x > wrap_width)
53 bool recalc_size =
false;
54 if (this->cursor.x == this->origin.x && this->cursor.y != this->origin.y)
56 while ((*text_begin ==
' ' || *text_begin ==
'\t'))
60 if (text_begin == text_end)
66 size = ImGui::CalcTextSize(text_begin, text_end);
68 this->AddInline(color, size, text_begin, text_end);
73 const char* text_pos = text_begin;
74 const char* tok_begin =
nullptr;
75 while (text_pos != text_end)
78 unsigned int c = (
unsigned int)*text_pos;
79 int bytes_advance = 1;
81 bytes_advance = ImTextCharFromUtf8(&c, text_pos, text_end);
87 if (tok_begin !=
nullptr)
89 this->AddWrapped(color, wrap_width, tok_begin, text_pos);
94 else if (c ==
' ' || c ==
'\t')
96 if (tok_begin !=
nullptr)
98 this->AddWrapped(color, wrap_width, tok_begin, text_pos);
101 this->AddWrapped(color, wrap_width, text_pos, text_pos + bytes_advance);
105 if (tok_begin ==
nullptr)
106 tok_begin = text_pos;
108 text_pos += bytes_advance;
111 if (tok_begin !=
nullptr)
113 this->AddWrapped(color, wrap_width, tok_begin, text_end);
119 const float height = ImGui::GetTextLineHeight();
120 this->size.y += height;
121 this->cursor.x = this->origin.x;
122 this->cursor.y += height;
129 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); }
132 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)
134 ImGuiWindow* window = ImGui::GetCurrentWindow();
135 if (window->SkipItems)
140 ImGuiContext& g = *GImGui;
141 const ImGuiID
id = window->GetID(label);
143 const ImVec2 pos = window->DC.CursorPos;
144 const float circle_radius = indicator_radius / 10.0f;
145 const ImRect bb(pos, ImVec2(pos.x + indicator_radius * 2.0f, pos.y + indicator_radius * 2.0f));
146 ImGui::ItemSize(bb, ImGui::GetStyle().FramePadding.y);
147 if (!ImGui::ItemAdd(bb,
id))
152 const float t = g.Time;
153 const auto degree_offset = 2.0f * IM_PI / circle_count;
155 for (
int i = 0; i < circle_count; ++i)
157 const auto x = indicator_radius * std::sin(degree_offset * i);
158 const auto y = indicator_radius * std::cos(degree_offset * i);
159 const auto growth = std::max(0.0f, std::sin(t * speed - i * degree_offset));
161 color.x = main_color.x * growth + backdrop_color.x * (1.0f - growth);
162 color.y = main_color.y * growth + backdrop_color.y * (1.0f - growth);
163 color.z = main_color.z * growth + backdrop_color.z * (1.0f - growth);
166 window->DrawList->AddCircleFilled(ImVec2(pos.x + indicator_radius +
x,
167 pos.y + indicator_radius -
y),
168 circle_radius + growth * circle_radius,
169 ImGui::GetColorU32(color));
177 ImDrawList* draw_list = ImGui::GetWindowDrawList();
179 float cos_a = cosf(angle);
180 float sin_a = sinf(angle);
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),
186 center + ImRotate(ImVec2(-size.x * 0.5f, +size.y * 0.5f), cos_a, sin_a)
196 draw_list->AddImageQuad(tex_id, pos[0], pos[1], pos[2], pos[3], uvs[0], uvs[1], uvs[2], uvs[3], IM_COL32_WHITE);
204 ImVec2
RoR::DrawColorMarkedText(ImDrawList* drawlist, ImVec2 text_cursor, ImVec4 default_color,
float override_alpha,
float wrap_width, std::string
const& line)
207 int r,g,b, dark_r,dark_g,dark_b;
210 std::smatch color_match;
211 std::string::const_iterator seg_start = line.begin();
212 while (std::regex_search(seg_start, line.end(), color_match,
TEXT_COLOR_REGEX))
215 std::string::const_iterator seg_end = color_match[0].first;
216 if (seg_start != seg_end)
218 feeder.
AddMultiline(ImColor(r,g,b,(
int)(override_alpha*255)), wrap_width, &*seg_start, &*seg_end);
221 sscanf(color_match.str(0).c_str(),
"#%2x%2x%2x", &r, &g, &b);
222 if (r==0 && g==0 && b==0)
226 else if (r < dark_r && g < dark_g && b < dark_b)
233 seg_start = color_match[0].second;
237 if (seg_start != line.begin() + line.length())
239 const char* end_ptr = &line.c_str()[line.length()];
240 feeder.
AddMultiline(ImColor(r,g,b,(
int)(override_alpha*255)), wrap_width, &*seg_start, end_ptr);
248 ImVec2 text_pos = ImGui::GetCursorScreenPos();
251 ImGui::GetStyle().Colors[ImGuiCol_Text],
253 ImGui::GetWindowContentRegionWidth() - ImGui::GetCursorPosX(),
256 ImRect bb(text_pos, text_pos + text_size);
257 ImGui::ItemSize(text_size);
258 ImGui::ItemAdd(bb, 0);
264 if (ImGui::Checkbox(label, &val))
274 bool val = (cvar->
getInt() != 0);
275 if (ImGui::Checkbox(label, &val))
277 cvar->
setVal(val ? 1 : 0);
284 if (ImGui::InputInt(label, &val, 1, 100, ImGuiInputTextFlags_EnterReturnsTrue))
294 if (ImGui::SliderInt(label, &val, v_min, v_max))
304 if (ImGui::SliderFloat(label, &val, v_min, v_max,
"%.2f"))
313 if (ImGui::InputFloat(label, &fval, 0.f, 0.f,
"%.3f", ImGuiInputTextFlags_EnterReturnsTrue))
321 if (ImGui::InputText(label, buf.
GetBuffer(), buf.
GetCapacity(), ImGuiInputTextFlags_EnterReturnsTrue))
325 if (ImGui::IsItemActive())
327 ImGui::TextDisabled(
"(hit Enter key to submit)");
337 int selection = cvar->
getInt();
338 if (ImGui::Combo(label, &selection, values))
348 return Ogre::static_pointer_cast<Ogre::Texture>(
349 Ogre::TextureManager::getSingleton().createOrRetrieve(name,
"FlagsRG").first);
353 return Ogre::TexturePtr();
358 ImVec2 screen_size = ImGui::GetIO().DisplaySize;
361 int window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar| ImGuiWindowFlags_NoInputs
362 | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoBringToFrontOnFocus;
363 ImGui::SetNextWindowPos(ImVec2(0,0));
364 ImGui::SetNextWindowSize(screen_size);
365 ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0,0,0,0));
366 ImGui::Begin(name.c_str(), NULL, window_flags);
367 ImDrawList* drawlist = ImGui::GetWindowDrawList();
369 ImGui::PopStyleColor(1);
386 size_t prev_size = target.size();
389 target.resize(prev_size + 1,
'\0');
392 target.insert(target.begin() + prev_size + 1, item.begin(), item.end());
402 size_t prev_size = target.size();
405 target.resize(prev_size + 2,
'\0');
410 ImVec4 col = ImGui::GetStyle().Colors[ImGuiCol_Text];
416 const ImVec2 PAD = ImVec2(2.f, 0.f);
417 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, PAD);
418 ImGui::BeginChildFrame(ImGuiID(input_event), ImGui::CalcTextSize(text.c_str()) + PAD*2);
419 ImGui::TextColored(col,
"%s", text.c_str());
420 ImGui::EndChildFrame();
421 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::PushStyleColor(ImGuiCol_Text, col);
435 ImGui::PushID(input_event);
436 const bool retval = ImGui::Button(text.c_str());
437 if (btn_hovered !=
nullptr)
439 *btn_hovered = ImGui::IsItemHovered();
441 if (btn_active !=
nullptr)
443 *btn_active = ImGui::IsItemActive();
446 ImGui::PopStyleColor();
447 ImGui::PopStyleVar();
453 ImVec4 col = ImGui::GetStyle().Colors[ImGuiCol_Text];
459 const ImVec2 PAD = ImVec2(2.f, 0.f);
460 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, PAD);
461 ImGui::BeginChildFrame(ImGuiID(key), ImGui::CalcTextSize(text.c_str()) + PAD*2);
462 ImGui::TextColored(col,
"%s", text.c_str());
463 ImGui::EndChildFrame();
464 ImGui::PopStyleVar();
470 const ImVec2 PAD = ImVec2(2.f, 0.f);
471 return ImGui::CalcTextSize(text.c_str()) + PAD*2;
477 ImGui::SmallButton(btn_idstr.c_str());
479 ImGui::Button(btn_idstr.c_str());
482 static const ImGuiID IMGUIID_INVALID = 0u;
483 static ImGuiID active_id = IMGUIID_INVALID;
484 static float active_time_left = 0.f;
485 const ImGuiID btn_id = ImGui::GetCurrentWindow()->GetID(btn_idstr.c_str());
487 if (ImGui::IsItemActive())
489 if (active_id != btn_id)
492 active_time_left = time_limit;
496 active_time_left -= ImGui::GetIO().DeltaTime;
497 if (active_time_left <= 0.f)
499 active_id = IMGUIID_INVALID;
504 ImGui::BeginTooltip();
505 std::string text =
_L(
"Hold to confirm");
506 ImGui::TextDisabled(text.c_str());
507 ImGui::ProgressBar(active_time_left/time_limit, ImVec2(ImGui::CalcTextSize(text.c_str()).x, 8.f),
"");
510 else if (btn_id == active_id)
512 active_id = IMGUIID_INVALID;
520 ImVec2 screen_size = ImGui::GetIO().DisplaySize;
523 Ogre::Vector3 pos_xyz = world2screen.
Convert(world_pos);
526 out_screen.x = pos_xyz.x;
527 out_screen.y = pos_xyz.y;