mirror of
https://github.com/Bloodysharp/Synthetic.git
synced 2026-10-10 13:23:11 +08:00
425 lines
18 KiB
C++
425 lines
18 KiB
C++
#include "../settings/functions.h"
|
|
|
|
using namespace ImGui;
|
|
|
|
static inline ImDrawFlags fix_rect_corner_flag(ImDrawFlags flags)
|
|
{
|
|
IM_ASSERT((flags & 0x0F) == 0 && "Misuse of legacy hardcoded ImDrawCornerFlags values!");
|
|
if ((flags & ImDrawFlags_RoundCornersMask_) == 0) flags |= ImDrawFlags_RoundCornersAll;
|
|
|
|
return flags;
|
|
}
|
|
|
|
void c_draw::rect_filled_multi_color(ImDrawList* draw, const ImVec2& p_min, const ImVec2& p_max, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left, float rounding, ImDrawFlags flags)
|
|
{
|
|
if (((col_upr_left | col_upr_right | col_bot_right | col_bot_left) & IM_COL32_A_MASK) == 0)
|
|
return;
|
|
|
|
auto fix_rect_corner_flags = [](ImDrawFlags rflags)
|
|
{
|
|
if ((rflags & ImDrawFlags_RoundCornersMask_) == 0)
|
|
rflags |= ImDrawFlags_RoundCornersAll;
|
|
return rflags;
|
|
};
|
|
|
|
flags = fix_rect_corner_flags(flags);
|
|
rounding = ImMin(rounding, ImFabs(p_max.x - p_min.x) * (((flags & ImDrawFlags_RoundCornersTop) == ImDrawFlags_RoundCornersTop) || ((flags & ImDrawFlags_RoundCornersBottom) == ImDrawFlags_RoundCornersBottom) ? 0.5f : 1.0f) - 1.0f);
|
|
rounding = ImMin(rounding, ImFabs(p_max.y - p_min.y) * (((flags & ImDrawFlags_RoundCornersLeft) == ImDrawFlags_RoundCornersLeft) || ((flags & ImDrawFlags_RoundCornersRight) == ImDrawFlags_RoundCornersRight) ? 0.5f : 1.0f) - 1.0f);
|
|
|
|
if (rounding > 0.0f)
|
|
{
|
|
const int size_before = draw->VtxBuffer.Size;
|
|
draw->AddRectFilled(p_min, p_max, IM_COL32_WHITE, rounding, flags);
|
|
const int size_after = draw->VtxBuffer.Size;
|
|
|
|
for (int i = size_before; i < size_after; i++)
|
|
{
|
|
ImDrawVert* vert = draw->VtxBuffer.Data + i;
|
|
|
|
ImVec4 upr_left = ImGui::ColorConvertU32ToFloat4(col_upr_left);
|
|
ImVec4 bot_left = ImGui::ColorConvertU32ToFloat4(col_bot_left);
|
|
ImVec4 up_right = ImGui::ColorConvertU32ToFloat4(col_upr_right);
|
|
ImVec4 bot_right = ImGui::ColorConvertU32ToFloat4(col_bot_right);
|
|
|
|
float X = ImClamp((vert->pos.x - p_min.x) / (p_max.x - p_min.x), 0.0f, 1.0f);
|
|
|
|
// 4 colors - 8 deltas
|
|
|
|
float r1 = upr_left.x + (up_right.x - upr_left.x) * X;
|
|
float r2 = bot_left.x + (bot_right.x - bot_left.x) * X;
|
|
|
|
float g1 = upr_left.y + (up_right.y - upr_left.y) * X;
|
|
float g2 = bot_left.y + (bot_right.y - bot_left.y) * X;
|
|
|
|
float b1 = upr_left.z + (up_right.z - upr_left.z) * X;
|
|
float b2 = bot_left.z + (bot_right.z - bot_left.z) * X;
|
|
|
|
float a1 = upr_left.w + (up_right.w - upr_left.w) * X;
|
|
float a2 = bot_left.w + (bot_right.w - bot_left.w) * X;
|
|
|
|
|
|
float Y = ImClamp((vert->pos.y - p_min.y) / (p_max.y - p_min.y), 0.0f, 1.0f);
|
|
float r = r1 + (r2 - r1) * Y;
|
|
float g = g1 + (g2 - g1) * Y;
|
|
float b = b1 + (b2 - b1) * Y;
|
|
float a = a1 + (a2 - a1) * Y;
|
|
ImVec4 RGBA(r, g, b, a);
|
|
|
|
RGBA = RGBA * ImGui::ColorConvertU32ToFloat4(vert->col);
|
|
|
|
vert->col = ImColor(RGBA);
|
|
}
|
|
return;
|
|
}
|
|
|
|
const ImVec2 uv = draw->_Data->TexUvWhitePixel;
|
|
draw->PrimReserve(6, 4);
|
|
draw->PrimWriteIdx((ImDrawIdx)(draw->_VtxCurrentIdx)); draw->PrimWriteIdx((ImDrawIdx)(draw->_VtxCurrentIdx + 1)); draw->PrimWriteIdx((ImDrawIdx)(draw->_VtxCurrentIdx + 2));
|
|
draw->PrimWriteIdx((ImDrawIdx)(draw->_VtxCurrentIdx)); draw->PrimWriteIdx((ImDrawIdx)(draw->_VtxCurrentIdx + 2)); draw->PrimWriteIdx((ImDrawIdx)(draw->_VtxCurrentIdx + 3));
|
|
draw->PrimWriteVtx(p_min, uv, col_upr_left);
|
|
draw->PrimWriteVtx(ImVec2(p_max.x, p_min.y), uv, col_upr_right);
|
|
draw->PrimWriteVtx(p_max, uv, col_bot_right);
|
|
draw->PrimWriteVtx(ImVec2(p_min.x, p_max.y), uv, col_bot_left);
|
|
}
|
|
|
|
void set_linear_color(ImDrawList* draw_list, int vert_start_idx, int vert_end_idx, ImVec2 gradient_p0, ImVec2 gradient_p1, ImU32 col0, ImU32 col1)
|
|
{
|
|
ImVec2 gradient_extent = gradient_p1 - gradient_p0;
|
|
float gradient_inv_length2 = 1.0f / ImLengthSqr(gradient_extent);
|
|
ImDrawVert* vert_start = draw_list->VtxBuffer.Data + vert_start_idx;
|
|
ImDrawVert* vert_end = draw_list->VtxBuffer.Data + vert_end_idx;
|
|
const int col0_r = (int)(col0 >> IM_COL32_R_SHIFT) & 0xFF;
|
|
const int col0_g = (int)(col0 >> IM_COL32_G_SHIFT) & 0xFF;
|
|
const int col0_b = (int)(col0 >> IM_COL32_B_SHIFT) & 0xFF;
|
|
const int col_delta_r = ((int)(col1 >> IM_COL32_R_SHIFT) & 0xFF) - col0_r;
|
|
const int col_delta_g = ((int)(col1 >> IM_COL32_G_SHIFT) & 0xFF) - col0_g;
|
|
const int col_delta_b = ((int)(col1 >> IM_COL32_B_SHIFT) & 0xFF) - col0_b;
|
|
for (ImDrawVert* vert = vert_start; vert < vert_end; vert++)
|
|
{
|
|
float d = ImDot(vert->pos - gradient_p0, gradient_extent);
|
|
float t = ImClamp(d * gradient_inv_length2, 0.0f, 1.0f);
|
|
int r = (int)(col0_r + col_delta_r * t);
|
|
int g = (int)(col0_g + col_delta_g * t);
|
|
int b = (int)(col0_b + col_delta_b * t);
|
|
vert->col = (r << IM_COL32_R_SHIFT) | (g << IM_COL32_G_SHIFT) | (b << IM_COL32_B_SHIFT) | (vert->col & IM_COL32_A_MASK);
|
|
}
|
|
}
|
|
|
|
void c_draw::fade_rect_filled(ImDrawList* draw, const ImVec2& pos_min, const ImVec2& pos_max, ImU32 col_one, ImU32 col_two, fade_direction direction, float rounding, ImDrawFlags flags)
|
|
{
|
|
const ImVec2 fade_pos_in = (direction == fade_direction::diagonally_reversed) ? ImVec2(pos_max.x, pos_min.y) : pos_min;
|
|
|
|
const ImVec2 fade_pos_out = (direction == fade_direction::vertically) ? ImVec2(pos_min.x, pos_max.y) :
|
|
(direction == fade_direction::horizontally) ? ImVec2(pos_max.x, pos_min.y) :
|
|
(direction == fade_direction::diagonally) ? pos_max :
|
|
(direction == fade_direction::diagonally_reversed) ? ImVec2(pos_min.x, pos_max.y) : ImVec2(0, 0);
|
|
|
|
const int vtx_buffer_start = draw->VtxBuffer.Size;
|
|
draw->AddRectFilled(pos_min, pos_max, gui->get_clr(ImVec4(1.f, 1.f, 1.f, 1.f)), rounding, flags);
|
|
const int vtx_buffer_end = draw->VtxBuffer.Size;
|
|
set_linear_color(draw, vtx_buffer_start, vtx_buffer_end, fade_pos_in, fade_pos_out, col_one, col_two);
|
|
}
|
|
|
|
void c_draw::render_text(ImDrawList* draw_list, ImFont* font, const ImVec2& pos_min, const ImVec2& pos_max, ImU32 color, const char* text, const char* text_display_end, const ImVec2* text_size_if_known, const ImVec2& align, const ImRect* clip_rect)
|
|
{
|
|
gui->push_font(font);
|
|
|
|
ImVec2 pos = pos_min;
|
|
const ImVec2 text_size = text_size_if_known ? *text_size_if_known : CalcTextSize(text, text_display_end, false, 0.0f);
|
|
|
|
const ImVec2* clip_min = clip_rect ? &clip_rect->Min : &pos_min;
|
|
const ImVec2* clip_max = clip_rect ? &clip_rect->Max : &pos_max;
|
|
bool need_clipping = (pos.x + text_size.x >= clip_max->x) || (pos.y + text_size.y >= clip_max->y);
|
|
if (clip_rect) need_clipping |= (pos.x < clip_min->x) || (pos.y < clip_min->y);
|
|
|
|
if (align.x > 0.0f) pos.x = ImMax(pos.x, pos.x + (pos_max.x - pos.x - text_size.x) * align.x);
|
|
if (align.y > 0.0f) pos.y = ImMax(pos.y, pos.y + (pos_max.y - pos.y - text_size.y) * align.y);
|
|
|
|
if (need_clipping)
|
|
{
|
|
ImVec4 fine_clip_rect(clip_min->x, clip_min->y, clip_max->x, clip_max->y);
|
|
draw_list->AddText(NULL, 0, pos, color, text, text_display_end, 0.0f, &fine_clip_rect);
|
|
}
|
|
else
|
|
{
|
|
draw_list->AddText(NULL, 0, pos, color, text, text_display_end, 0.0f, NULL);
|
|
}
|
|
gui->pop_font();
|
|
}
|
|
|
|
void c_draw::radial_gradient(ImDrawList* draw_list, const ImVec2& center, float radius, ImU32 col_in, ImU32 col_out)
|
|
{
|
|
if (((col_in | col_out) & IM_COL32_A_MASK) == 0 || radius < 0.5f) return;
|
|
|
|
draw_list->_PathArcToFastEx(center, radius, 0, IM_DRAWLIST_ARCFAST_SAMPLE_MAX, 0);
|
|
const int count = draw_list->_Path.Size - 1;
|
|
|
|
unsigned int vtx_base = draw_list->_VtxCurrentIdx;
|
|
draw_list->PrimReserve(count * 3, count + 1);
|
|
|
|
const ImVec2 uv = draw_list->_Data->TexUvWhitePixel;
|
|
draw_list->PrimWriteVtx(center, uv, col_in);
|
|
for (int n = 0; n < count; n++)
|
|
draw_list->PrimWriteVtx(draw_list->_Path[n], uv, col_out);
|
|
|
|
for (int n = 0; n < count; n++)
|
|
{
|
|
draw_list->PrimWriteIdx((ImDrawIdx)(vtx_base));
|
|
draw_list->PrimWriteIdx((ImDrawIdx)(vtx_base + 1 + n));
|
|
draw_list->PrimWriteIdx((ImDrawIdx)(vtx_base + 1 + ((n + 1) % count)));
|
|
}
|
|
draw_list->_Path.Size = 0;
|
|
}
|
|
|
|
void c_draw::set_linear_color_alpha(ImDrawList* draw_list, int vert_start_idx, int vert_end_idx, ImVec2 gradient_p0, ImVec2 gradient_p1, ImU32 col0, ImU32 col1)
|
|
{
|
|
ImVec2 gradient_extent = gradient_p1 - gradient_p0;
|
|
float gradient_inv_length2 = 1.0f / ImLengthSqr(gradient_extent);
|
|
ImDrawVert* vert_start = draw_list->VtxBuffer.Data + vert_start_idx;
|
|
ImDrawVert* vert_end = draw_list->VtxBuffer.Data + vert_end_idx;
|
|
const int col0_r = (int)(col0 >> IM_COL32_R_SHIFT) & 0xFF;
|
|
const int col0_g = (int)(col0 >> IM_COL32_G_SHIFT) & 0xFF;
|
|
const int col0_b = (int)(col0 >> IM_COL32_B_SHIFT) & 0xFF;
|
|
const int col0_a = (int)(col0 >> IM_COL32_A_SHIFT) & 0xFF;
|
|
const int col_delta_r = ((int)(col1 >> IM_COL32_R_SHIFT) & 0xFF) - col0_r;
|
|
const int col_delta_g = ((int)(col1 >> IM_COL32_G_SHIFT) & 0xFF) - col0_g;
|
|
const int col_delta_b = ((int)(col1 >> IM_COL32_B_SHIFT) & 0xFF) - col0_b;
|
|
const int col_delta_a = ((int)(col1 >> IM_COL32_A_SHIFT) & 0xFF) - col0_a;
|
|
for (ImDrawVert* vert = vert_start; vert < vert_end; vert++)
|
|
{
|
|
float d = ImDot(vert->pos - gradient_p0, gradient_extent);
|
|
float t = ImClamp(d * gradient_inv_length2, 0.0f, 1.0f);
|
|
int r = (int)(col0_r + col_delta_r * t);
|
|
int g = (int)(col0_g + col_delta_g * t);
|
|
int b = (int)(col0_b + col_delta_b * t);
|
|
int a = (int)(col0_a + col_delta_a * t);
|
|
vert->col = (r << IM_COL32_R_SHIFT) | (g << IM_COL32_G_SHIFT) | (b << IM_COL32_B_SHIFT) | (a << IM_COL32_A_SHIFT);
|
|
}
|
|
}
|
|
|
|
void c_draw::add_rect_filled(ImDrawList* draw_list, const ImVec2& p_min, const ImVec2& p_max, ImU32 col, float rounding, ImDrawFlags flags)
|
|
{
|
|
if ((col & IM_COL32_A_MASK) == 0) return;
|
|
|
|
if (rounding < 0.5f || (flags & ImDrawFlags_RoundCornersMask_) == ImDrawFlags_RoundCornersNone)
|
|
{
|
|
draw_list->PrimReserve(6, 4);
|
|
draw_list->PrimRect(p_min, p_max, col);
|
|
}
|
|
else
|
|
{
|
|
draw_list->PathRect(p_min, p_max, rounding, flags);
|
|
draw_list->PathFillConvex(col);
|
|
}
|
|
}
|
|
|
|
void c_draw::add_rect(ImDrawList* draw_list, const ImVec2& p_min, const ImVec2& p_max, ImU32 col, float rounding, ImDrawFlags flags, float thickness)
|
|
{
|
|
if ((col & IM_COL32_A_MASK) == 0) return;
|
|
if (draw_list->Flags & ImDrawListFlags_AntiAliasedLines) draw_list->PathRect(p_min + ImVec2(0.50f, 0.50f), p_max - ImVec2(0.50f, 0.50f), rounding, flags);
|
|
else draw_list->PathRect(p_min + ImVec2(0.50f, 0.50f), p_max - ImVec2(0.49f, 0.49f), rounding, flags);
|
|
|
|
draw_list->PathStroke(col, ImDrawFlags_Closed, thickness);
|
|
}
|
|
|
|
void c_draw::add_circle_filled(ImDrawList* draw_list, const ImVec2& center, float radius, ImU32 col, int num_segments)
|
|
{
|
|
if ((col & IM_COL32_A_MASK) == 0 || radius < 0.5f) return;
|
|
|
|
if (num_segments <= 0)
|
|
{
|
|
draw_list->_PathArcToFastEx(center, radius, 0, IM_DRAWLIST_ARCFAST_SAMPLE_MAX, 0);
|
|
draw_list->_Path.Size--;
|
|
}
|
|
else
|
|
{
|
|
num_segments = ImClamp(num_segments, 3, IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX);
|
|
|
|
const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments;
|
|
draw_list->PathArcTo(center, radius, 0.0f, a_max, num_segments - 1);
|
|
}
|
|
|
|
draw_list->PathFillConvex(col);
|
|
}
|
|
|
|
void c_draw::add_circle(ImDrawList* draw_list, const ImVec2& center, float radius, ImU32 col, int num_segments, float thickness)
|
|
{
|
|
if ((col & IM_COL32_A_MASK) == 0 || radius < 0.5f) return;
|
|
|
|
if (num_segments <= 0)
|
|
{
|
|
draw_list->_PathArcToFastEx(center, radius - 0.5f, 0, IM_DRAWLIST_ARCFAST_SAMPLE_MAX, 0);
|
|
draw_list->_Path.Size--;
|
|
}
|
|
else
|
|
{
|
|
num_segments = ImClamp(num_segments, 3, IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX);
|
|
|
|
const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments;
|
|
draw_list->PathArcTo(center, radius - 0.5f, 0.0f, a_max, num_segments - 1);
|
|
}
|
|
|
|
draw_list->PathStroke(col, ImDrawFlags_Closed, thickness);
|
|
}
|
|
|
|
void c_draw::add_text(ImDrawList* draw_list, const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end, float wrap_width, const ImVec4* cpu_fine_clip_rect)
|
|
{
|
|
if ((col & IM_COL32_A_MASK) == 0) return;
|
|
if (text_begin == text_end || text_begin[0] == 0) return;
|
|
|
|
if (text_end == NULL) text_end = text_begin + strlen(text_begin);
|
|
if (font == NULL) font = draw_list->_Data->Font;
|
|
if (font_size == 0.0f) font_size = draw_list->_Data->FontSize;
|
|
|
|
IM_ASSERT(font->ContainerAtlas->TexID == draw_list->_CmdHeader.TextureId);
|
|
|
|
ImVec4 clip_rect = draw_list->_CmdHeader.ClipRect;
|
|
if (cpu_fine_clip_rect)
|
|
{
|
|
clip_rect.x = ImMax(clip_rect.x, cpu_fine_clip_rect->x);
|
|
clip_rect.y = ImMax(clip_rect.y, cpu_fine_clip_rect->y);
|
|
clip_rect.z = ImMin(clip_rect.z, cpu_fine_clip_rect->z);
|
|
clip_rect.w = ImMin(clip_rect.w, cpu_fine_clip_rect->w);
|
|
}
|
|
font->RenderText(draw_list, font_size, pos, col, clip_rect, text_begin, text_end, wrap_width, cpu_fine_clip_rect != NULL);
|
|
}
|
|
|
|
void c_draw::render_text(ImFont* font, ImDrawList* draw_list, const ImVec2& pos_min, const ImVec2& pos_max, ImU32 color, const char* text, const char* text_display_end, const ImVec2* text_size_if_known, const ImVec2& align, const ImRect* clip_rect)
|
|
{
|
|
gui->push_font(font);
|
|
|
|
ImVec2 pos = pos_min;
|
|
const ImVec2 text_size = text_size_if_known ? *text_size_if_known : CalcTextSize(text, text_display_end, false, 0.0f);
|
|
|
|
const ImVec2* clip_min = clip_rect ? &clip_rect->Min : &pos_min;
|
|
const ImVec2* clip_max = clip_rect ? &clip_rect->Max : &pos_max;
|
|
bool need_clipping = (pos.x + text_size.x >= clip_max->x) || (pos.y + text_size.y >= clip_max->y);
|
|
if (clip_rect) need_clipping |= (pos.x < clip_min->x) || (pos.y < clip_min->y);
|
|
|
|
if (align.x > 0.0f) pos.x = ImMax(pos.x, pos.x + (pos_max.x - pos.x - text_size.x) * align.x);
|
|
if (align.y > 0.0f) pos.y = ImMax(pos.y, pos.y + (pos_max.y - pos.y - text_size.y) * align.y);
|
|
|
|
if (need_clipping)
|
|
{
|
|
ImVec4 fine_clip_rect(clip_min->x, clip_min->y, clip_max->x, clip_max->y);
|
|
add_text(draw_list, NULL, 0, pos, color, text, text_display_end, 0.0f, &fine_clip_rect);
|
|
}
|
|
else
|
|
{
|
|
add_text(draw_list, NULL, 0, pos, color, text, text_display_end, 0.0f, NULL);
|
|
}
|
|
gui->pop_font();
|
|
}
|
|
|
|
void c_draw::render_text_with_spacing(const char* text, float spacing, ImVec2 position1, ImVec2 position2, ImU32 color, bool centered)
|
|
{
|
|
ImVec2 pos = position1;
|
|
|
|
float max_width = 0.0f;
|
|
float total_height = 0.0f;
|
|
const char* temp = text;
|
|
while (*temp)
|
|
{
|
|
if (*temp != '\n' && *temp != ' ')
|
|
{
|
|
float width = ImGui::CalcTextSize(temp, temp + 1).x;
|
|
if (width > max_width)
|
|
{
|
|
max_width = width;
|
|
}
|
|
total_height += ImGui::GetTextLineHeight() + spacing;
|
|
}
|
|
temp++;
|
|
}
|
|
total_height -= spacing;
|
|
|
|
if (centered)
|
|
{
|
|
float center_x = (position1.x + position2.x) / 2.0f;
|
|
float center_y = (position1.y + position2.y) / 2.0f;
|
|
pos.x = center_x - max_width / 2.0f;
|
|
pos.y = center_y - total_height / 2.0f;
|
|
}
|
|
|
|
while (*text)
|
|
{
|
|
if (*text != '\n' && *text != ' ')
|
|
{
|
|
ImGui::SetCursorScreenPos(pos);
|
|
ImGui::TextColored(ImGui::ColorConvertU32ToFloat4(color), "%c", *text);
|
|
pos.y += ImGui::GetTextLineHeight() + spacing;
|
|
}
|
|
text++;
|
|
}
|
|
}
|
|
|
|
void c_draw::add_image(ImDrawList* draw_list, ImTextureID user_texture_id, const ImVec2& p_min, const ImVec2& p_max, const ImVec2& uv_min, const ImVec2& uv_max, ImU32 col)
|
|
{
|
|
if ((col & IM_COL32_A_MASK) == 0) return;
|
|
|
|
const bool push_texture_id = user_texture_id != draw_list->_CmdHeader.TextureId;
|
|
if (push_texture_id) draw_list->PushTextureID(user_texture_id);
|
|
|
|
draw_list->PrimReserve(6, 4);
|
|
draw_list->PrimRectUV(p_min, p_max, uv_min, uv_max, col);
|
|
|
|
if (push_texture_id) draw_list->PopTextureID();
|
|
}
|
|
|
|
void c_draw::add_image_rounded(ImDrawList* draw_list, ImTextureID user_texture_id, const ImVec2& p_min, const ImVec2& p_max, const ImVec2& uv_min, const ImVec2& uv_max, ImU32 col, float rounding, ImDrawFlags flags)
|
|
{
|
|
if ((col & IM_COL32_A_MASK) == 0) return;
|
|
|
|
flags = fix_rect_corner_flag(flags);
|
|
if (rounding < 0.5f || (flags & ImDrawFlags_RoundCornersMask_) == ImDrawFlags_RoundCornersNone)
|
|
{
|
|
draw->add_image(draw_list, user_texture_id, p_min, p_max, uv_min, uv_max, col);
|
|
return;
|
|
}
|
|
|
|
const bool push_texture_id = user_texture_id != draw_list->_CmdHeader.TextureId;
|
|
if (push_texture_id) draw_list->PushTextureID(user_texture_id);
|
|
|
|
int vert_start_idx = draw_list->VtxBuffer.Size;
|
|
draw_list->PathRect(p_min, p_max, rounding, flags);
|
|
draw_list->PathFillConvex(col);
|
|
int vert_end_idx = draw_list->VtxBuffer.Size;
|
|
ImGui::ShadeVertsLinearUV(draw_list, vert_start_idx, vert_end_idx, p_min, p_max, uv_min, uv_max, true);
|
|
|
|
if (push_texture_id) draw_list->PopTextureID();
|
|
}
|
|
|
|
void c_draw::add_line(ImDrawList* draw, const ImVec2& p1, const ImVec2& p2, ImU32 col, float thickness)
|
|
{
|
|
if ((col & IM_COL32_A_MASK) == 0) return;
|
|
|
|
draw->PathLineTo(p1 + ImVec2(0.5f, 0.5f));
|
|
draw->PathLineTo(p2 + ImVec2(0.5f, 0.5f));
|
|
draw->PathStroke(col, 0, thickness);
|
|
}
|
|
|
|
void c_draw::push_clip_rect(ImDrawList* draw, const ImVec2& cr_min, const ImVec2& cr_max, bool intersect_with_current_clip_rect)
|
|
{
|
|
ImVec4 cr(cr_min.x, cr_min.y, cr_max.x, cr_max.y);
|
|
if (intersect_with_current_clip_rect)
|
|
{
|
|
ImVec4 current = draw->_CmdHeader.ClipRect;
|
|
if (cr.x < current.x) cr.x = current.x;
|
|
if (cr.y < current.y) cr.y = current.y;
|
|
if (cr.z > current.z) cr.z = current.z;
|
|
if (cr.w > current.w) cr.w = current.w;
|
|
}
|
|
cr.z = ImMax(cr.x, cr.z);
|
|
cr.w = ImMax(cr.y, cr.w);
|
|
|
|
draw->_ClipRectStack.push_back(cr);
|
|
draw->_CmdHeader.ClipRect = cr;
|
|
draw->_OnChangedClipRect();
|
|
}
|
|
|
|
void c_draw::pop_clip_rect(ImDrawList* draw)
|
|
{
|
|
draw->_ClipRectStack.pop_back();
|
|
draw->_CmdHeader.ClipRect = (draw->_ClipRectStack.Size == 0) ? draw->_Data->ClipRectFullscreen : draw->_ClipRectStack.Data[draw->_ClipRectStack.Size - 1];
|
|
draw->_OnChangedClipRect();
|
|
} |