mostly finished toggle + sliders

This commit is contained in:
yhqe committed 2026-03-27 00:30:28 -05:00
1 parent 6c17fd9b2f
commit 00a6b4d54e
2 files changed
+222 -30

No files matched your search

+123 -3
View File
@@ -14,6 +14,10 @@
#include <tchar.h>
#include <misc/freetype/imgui_freetype.h>
#include <string>
#include <vector>
#include <cmath>
#include "imgui_internal.h"
#include "fonts/montserrat.c"
// Data
@@ -24,6 +28,8 @@ static bool g_SwapChainOccluded = false;
static UINT g_ResizeWidth = 0, g_ResizeHeight = 0;
static ID3D11RenderTargetView* g_mainRenderTargetView = nullptr;
#define IM_PI 3.14159265358979323846f
// Forward declarations of helper functions
bool CreateDeviceD3D(HWND hWnd);
void CleanupDeviceD3D();
@@ -31,6 +37,24 @@ void CreateRenderTarget();
void CleanupRenderTarget();
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
void draw_star(ImVec2 center, float outerRadius, float innerRadius, int numPoints, ImU32 color, float rotation)
{
ImDrawList* drawList = ImGui::GetWindowDrawList();
int totalPoints = numPoints * 2;
for (int i = 0; i < totalPoints; i++)
{
float angle = rotation + ((float)i / totalPoints) * 2.0f * IM_PI - (IM_PI / 2.0f);
float radius = (i % 2 == 0) ? outerRadius : innerRadius;
drawList->PathLineTo(ImVec2(
center.x + cosf(angle) * radius,
center.y + sinf(angle) * radius
));
}
drawList->PathFillConcave(color);
}
// Main code
int main(int, char**)
{
@@ -78,6 +102,10 @@ int main(int, char**)
// Our state
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
bool test_bool = false;
float test_float = 0.f;
int test_int = 0;
// Main loop
bool done = false;
while (!done)
@@ -133,7 +161,7 @@ int main(int, char**)
auto draw = ImGui::GetWindowDrawList();
auto b_draw = ImGui::GetBackgroundDrawList();
const int shadow_layers = 10;
/*const int shadow_layers = 10;
const float shadow_size = 5.0f;
for (int i = 0; i < shadow_layers; ++i)
{
@@ -146,13 +174,13 @@ int main(int, char**)
IM_COL32(40, 46, 60, alpha),
10.0f + expand
);
}
}*/
draw->AddRectFilled(ImGui::GetWindowPos(), ImGui::GetWindowPos() + ImGui::GetWindowSize(), IM_COL32(40, 46, 60, 255), 10.f);
// titlebar
{
const float title_h = 30.0f;
const float title_r = 10.0f;
const float title_r = 8.f;
const ImU32 col_l = IM_COL32(129, 183, 255, 255);
const ImU32 col_r = IM_COL32(137, 120, 255, 255);
@@ -171,6 +199,89 @@ int main(int, char**)
draw->AddCircleFilled(ImVec2(pos.x + title_r, pos.y + title_r), title_r, col_l, 24);
draw->AddCircleFilled(ImVec2(pos.x + size.x - title_r, pos.y + title_r), title_r, col_r, 24);
const float t = static_cast<float>(ImGui::GetTime());
const int segments = 80;
const float amp = 3.5f;
const float freq = 6.0f;
const float phase_step = 0.8f;
ImU32 wave_color = IM_COL32(180, 200, 255, 140);
for (int l = 0; l < 3; ++l)
{
float y_base = pos.y + title_h * 0.55f + l * 3.5f;
draw->PathClear();
for (int i = 0; i <= segments; ++i)
{
float u = static_cast<float>(i) / static_cast<float>(segments);
float x = pos.x + (size.x) * u;
float y = y_base + std::sinf(u * freq + t * 2.2f + l * phase_step) * amp;
draw->PathLineTo(ImVec2(x, y));
}
draw->PathStroke(wave_color, false, 1.6f);
}
static std::vector<ImVec2> star_offsets;
static std::vector<float> star_radii;
static std::vector<float> star_rotations;
static std::vector<float> star_opacities;
constexpr float kStarRadius = 7.5f;
constexpr float kStarMinDistance = 12.0f;
if (star_offsets.empty())
{
star_offsets.reserve(16);
star_radii.reserve(16);
star_rotations.reserve(16);
star_opacities.reserve(16);
unsigned seed = 1234567u;
const char* title_text = "Mocha";
float title_reserved = 12.0f + ImGui::CalcTextSize(title_text).x + 16.0f;
float x_min = ImClamp(title_reserved, 10.0f, size.x - 10.0f);
float x_max = size.x - 10.0f;
auto nextf = [&seed]() {
seed = seed * 1664525u + 1013904223u;
return (seed >> 8) * (1.0f / 16777216.0f);
};
const int star_count = 16;
float step = (x_max - x_min) / static_cast<float>(star_count);
for (int i = 0; i < star_count; ++i)
{
float jitter = (nextf() - 0.5f) * step * 0.35f;
float x = ImClamp(x_min + (i + 0.5f) * step + jitter, x_min, x_max);
float y = 4.0f + nextf() * (title_h - 8.0f);
ImVec2 candidate(x, y);
bool too_close = false;
for (const ImVec2& p : star_offsets)
{
if (ImLengthSqr(p - candidate) < kStarMinDistance * kStarMinDistance)
{
too_close = true;
break;
}
}
if (too_close)
continue;
star_offsets.push_back(candidate);
star_radii.push_back(kStarRadius * (0.7f + nextf() * 0.6f));
star_rotations.push_back(nextf() * (2.0f * IM_PI));
star_opacities.push_back(0.55f + nextf() * 0.45f);
}
}
draw->PushClipRect(ImVec2(pos.x, pos.y), ImVec2(pos.x + size.x, pos.y + title_h), true);
for (size_t i = 0; i < star_offsets.size(); ++i)
{
float offset = std::sinf(t * 1.5f + static_cast<float>(i) * 0.6f) * 2.2f;
ImVec2 center = pos + star_offsets[i] + ImVec2(0.0f, offset);
float fade = star_opacities[i] * (0.85f + 0.15f * (0.5f + 0.5f * std::sinf(t * 1.5f + static_cast<float>(i) * 0.6f)));
ImU32 star_color = ImGui::ColorConvertFloat4ToU32(ImVec4(1.0f, 1.0f, 1.0f, fade));
draw_star(center, star_radii[i], star_radii[i] * 0.55f, 5, star_color, star_rotations[i]);
}
draw->PopClipRect();
ImGui::SetCursorPos(ImVec2(ImGui::GetCursorPosX() + 2.f, ImGui::GetCursorPosY() - 2.f));
ImGui::Text("Mocha");
}
@@ -213,6 +324,15 @@ int main(int, char**)
ImGui::SetCursorPos(ImVec2(((size.x - text_size.x) * 0.5f), 5.f));
ImGui::Text(text);
}
// content
{
ImGui::SetCursorPos(ImVec2(10, 40));
ImGui::Checkbox("Test Toggle", &test_bool);
ImGui::SetCursorPos(ImVec2(10, ImGui::GetCursorPosY() + 25.f));; ImGui::SliderFloat("Test Slider (float)", &test_float, 0.f, 100.f);
ImGui::SetCursorPosX(10); ImGui::SliderInt("Test Slider (int)", &test_int, 0, 100);
}
}
ImGui::EndChild();
}