A virtual currency betting bot for Twitch chat. https://ddark.net/better
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
better/src/better_imgui_utils.cpp

159 lines
4.2 KiB

#pragma warning (disable: 4200) // nonstandard extension used: zero-sized array in struct/union
#include <cmath>
#include <imgui.h>
#include <imgui_internal.h>
#include <implot.h>
#include "better_imgui_utils.h"
#include "better_App.h"
bool imgui_any_mouse_buttons_held(ImGuiIO& io)
{
for (int i = 0; i < sizeof(io.MouseDown); ++i)
if (io.MouseDown[i]) return true;
return false;
}
bool imgui_confirmable_button(char* button_text, ImVec2& button_size, bool dark_mode, bool skip_confirm)
{
ImGuiStorage* storage = ImGui::GetStateStorage();
ImGui::PushID("imgui_confirmable_button");
auto id = ImGui::GetID(button_text);
bool* button_clicked_once = storage->GetBoolRef(id, false);
bool res = false;
if (button_size.x == 0.0f)
{
f32 width_first = ImGui::CalcTextSize(button_text, NULL, true, -1.0f).x;
f32 width_second = ImGui::CalcTextSize("Confirm", NULL, false, -1.0f).x;
button_size.x = BETTER_MAX(width_first, width_second) + 2.0f * ImGui::GetStyle().FramePadding.x;
}
if (!*button_clicked_once)
{
if (ImGui::Button(button_text, button_size))
{
if (skip_confirm)
res = true;
else
*button_clicked_once = true;
}
}
else
{
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, dark_mode? ImVec4(0.85f,0.1f,0.1f,1) : ImVec4(0.9f,0.2f,0.2f,1));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1,0,0,1));
if (ImGui::Button("Confirm", button_size))
{
*button_clicked_once = false;
res = true;
}
if (!ImGui::IsItemHovered())
*button_clicked_once = false;
ImGui::PopStyleColor(2);
}
ImGui::PopID();
return res;
}
bool imgui_clickable_text(const char* fmt, ...)
{
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(ImGuiCol_ButtonHovered, 1.0f));
va_list args;
va_start(args, fmt);
ImGui::TextV(fmt, args);
va_end(args);
if (ImGui::IsItemHovered())
{
ImVec2 min = ImGui::GetItemRectMin(),
max = ImGui::GetItemRectMax();
min.y = max.y;
ImGui::GetWindowDrawList()->AddLine(min, max, ImGui::GetColorU32(ImGuiCol_Text), 1.0f);
}
ImGui::PopStyleColor();
return ImGui::IsItemClicked();
}
void imgui_tooltip(const char* str)
{
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
ImGui::TextUnformatted(str);
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}
}
void imgui_tooltipf(const char* fmt, ...)
{
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
va_list args;
va_start(args, fmt);
ImGui::TextV(fmt, args);
va_end(args);
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}
}
void imgui_extra(const char* content)
{
ImGui::SameLine();
ImGui::TextDisabled(ICON_FA_QUESTION_CIRCLE);
imgui_tooltip(content);
}
void imgui_push_disabled()
{
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.6f);
}
void imgui_pop_disabled()
{
ImGui::PopStyleVar();
ImGui::PopItemFlag();
}
ImPlotPoint bar_chart_getter(void* app, i32 i)
{
return ImPlotPoint(i, BetTable_get_point_sum(&((App*)app)->bet_options[i]));
}
ImVec4 imgui_mod_color(ImVec4 in_color, f32 h_mod, f32 s_mod, f32 v_mod, f32 a_mod)
{
h_mod = BETTER_CLAMP(h_mod, -1.0f, 1.0f);
s_mod = BETTER_CLAMP(s_mod, -1.0f, 1.0f);
v_mod = BETTER_CLAMP(v_mod, -1.0f, 1.0f);
a_mod = BETTER_CLAMP(a_mod, -1.0f, 1.0f);
f32 h, s, v, a = in_color.w;
ImGui::ColorConvertRGBtoHSV(in_color.x, in_color.y, in_color.z, h, s, v);
h = BETTER_LERP(h, ceilf(h_mod*0.5f), BETTER_ABS(h_mod));
s = BETTER_LERP(s, ceilf(s_mod*0.5f), BETTER_ABS(s_mod));
v = BETTER_LERP(v, ceilf(v_mod*0.5f), BETTER_ABS(v_mod));
a = BETTER_LERP(a, ceilf(a_mod*0.5f), BETTER_ABS(a_mod));
ImVec4 out_color;
ImGui::ColorConvertHSVtoRGB(h, s, v, out_color.x, out_color.y, out_color.z);
out_color.w = a;
return out_color;
}