На самом деле я Zodiak
-
Автор темы
- #1
Шрифт: Segoe UI [может быть semibold, не уверен]
Размер: 15
C++:
void styling ( )
{
ImGui::StyleColorsDark ( );
auto& style = ImGui::GetStyle ( );
ImGuiIO& io = ImGui::GetIO ( );
style.Colors [ ImGuiCol_ChildBg ] = ImVec4 ( 0.07f, 0.07f, 0.07f, 1.f );
style.Colors [ ImGuiCol_WindowBg ] = ImVec4 ( 0.07f, 0.07f, 0.07f, 1.f );
style.Colors [ ImGuiCol_ScrollbarBg ] = ImVec4 ( 0.00f, 0.00f, 0.00f, 0.f );
style.Colors [ ImGuiCol_CheckMark ] = ImVec4 ( 0.07f, 0.07f, 0.07f, 1.f );
style.Colors [ ImGuiCol_Separator ] = ImVec4 ( 0.4f, 0.4f, 0.4f, 0.1f );
style.Colors [ ImGuiCol_FrameBg ] = ImVec4 ( 0.2f, 0.2f, 0.2f, 0.09f );
style.Colors [ ImGuiCol_FrameBgActive ] = ImVec4 ( 0.2f, 0.2f, 0.2f, 0.09f );
style.Colors [ ImGuiCol_FrameBgHovered ] = ImVec4 ( 0.2f, 0.2f, 0.2f, 0.09f );
style.FrameRounding = 2.f;
style.ChildRounding = 3.f;
style.WindowRounding = 3.f;
}
struct slider_anim
{
float move_anim;
float circle_anim;
float text_grayness;
float value_anim;
float value_anim_int;
};
bool slider_scalar ( const char* label, ImGuiDataType data_type, void* p_data, const void* p_min, const void* p_max, const char* format, ImGuiSliderFlags flags )
{
using namespace ImGui;
ImGuiWindow* window = GetCurrentWindow ( );
if ( window->SkipItems )
return false;
ImGuiContext& g = *GImGui;
const ImGuiStyle& style = g.Style;
const ImGuiID id = window->GetID ( label );
const float w = CalcItemWidth ( );
const ImVec2 label_size = CalcTextSize ( label, NULL, true );
window->DC.CursorPos += ImVec2 ( 5.f, 10.f );
const ImRect frame_bb ( window->DC.CursorPos, window->DC.CursorPos + ImVec2 ( w, label_size.y + style.FramePadding.y * 2.0f ) );
const ImRect total_bb ( ImVec2( frame_bb.Min.x, frame_bb.Min.y ), frame_bb.Max + ImVec2 ( label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f ) );
const bool temp_input_allowed = ( flags & ImGuiSliderFlags_NoInput ) == 0;
ItemSize ( total_bb, style.FramePadding.y );
if ( !ItemAdd ( total_bb, id, &frame_bb, temp_input_allowed ? ImGuiItemFlags_Inputable : 0 ) )
return false;
// Default format string when passing NULL
if ( format == NULL )
format = DataTypeGetInfo ( data_type )->PrintFmt;
const bool hovered = ItemHoverable ( frame_bb, id, g.LastItemData.InFlags );
bool temp_input_is_active = temp_input_allowed && TempInputIsActive ( id );
if ( !temp_input_is_active )
{
// Tabbing or CTRL-clicking on Slider turns it into an input box
const bool clicked = hovered && IsMouseClicked ( 0, ImGuiInputFlags_None, id );
const bool make_active = ( clicked || g.NavActivateId == id );
if ( make_active && clicked )
SetKeyOwner ( ImGuiKey_MouseLeft, id );
if ( make_active && temp_input_allowed )
if ( ( clicked && g.IO.KeyCtrl ) || ( g.NavActivateId == id && ( g.NavActivateFlags & ImGuiActivateFlags_PreferInput ) ) )
temp_input_is_active = true;
if ( make_active && !temp_input_is_active )
{
SetActiveID ( id, window );
SetFocusID ( id, window );
FocusWindow ( window );
g.ActiveIdUsingNavDirMask |= ( 1 << ImGuiDir_Left ) | ( 1 << ImGuiDir_Right );
}
}
if ( temp_input_is_active )
{
// Only clamp CTRL+Click input when ImGuiSliderFlags_AlwaysClamp is set
const bool is_clamp_input = ( flags & ImGuiSliderFlags_AlwaysClamp ) != 0;
return TempInputScalar ( frame_bb, id, label, data_type, p_data, format, is_clamp_input ? p_min : NULL, is_clamp_input ? p_max : NULL );
}
float frame_y_additional = frame_bb.Min.y + 8.f;
// Draw frame
const ImU32 frame_col = GetColorU32 ( g.ActiveId == id ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg );
RenderNavHighlight ( frame_bb, id );
RenderFrame ( ImVec2 ( frame_bb.Min.x, frame_y_additional ), ImVec2 ( frame_bb.Max.x, frame_bb.Max.y - 8.f ), frame_col, true, g.Style.FrameRounding );
// Slider behavior
ImRect grab_bb;
const bool value_changed = SliderBehavior ( frame_bb, id, data_type, p_data, p_min, p_max, format, flags, &grab_bb );
if ( value_changed )
MarkItemEdited ( id );
static std::map<ImGuiID, slider_anim> animation_map;
auto animation = animation_map.find ( id );
if ( animation == animation_map.end ( ) )
{
animation_map.insert ( { id, {0.f,0.f, ImGui::IsItemActive ( ) ? 1.f : 0.4f,0.f,0} } );
animation = animation_map.find ( id );
}
// Render grab
if ( grab_bb.Max.x > grab_bb.Min.x )
{
auto value_to_set = grab_bb.Max.x - frame_bb.Min.x;
animation->second.move_anim = ImLerp ( animation->second.move_anim, value_to_set, g.IO.DeltaTime * 7.f );
animation->second.circle_anim = ImLerp ( animation->second.circle_anim, ImGui::IsItemActive() ? 7.f : 5.f, g.IO.DeltaTime * 7.f );
float grab_height = grab_bb.Max.y - grab_bb.Min.y;
window->DrawList->AddRectFilled ( ImVec2 ( frame_bb.Min.x, frame_y_additional ), ImVec2( frame_bb.Min.x + animation->second.move_anim, frame_bb.Max.y - 8.f ), ImColor ( ImVec4 ( 153.f / 255.f, 39.f / 255.f, 245.f / 255.f, 1.f ) ), g.Style.FrameRounding );
window->DrawList->AddCircleFilled ( ImVec2 ( frame_bb.Min.x + animation->second.move_anim, grab_bb.Max.y - grab_height / 2 ), animation->second.circle_anim, ImColor (255,255,255,255 ), 100 );
window->DrawList->AddCircleFilled ( ImVec2 ( frame_bb.Min.x + animation->second.move_anim, grab_bb.Max.y - grab_height/2), 3.f, ImColor ( ImVec4 ( 153.f / 255.f, 39.f / 255.f, 245.f / 255.f, 1.f ) ), 100 );
//window->DrawList->AddRectFilled ( grab_bb.Min, grab_bb.Max, GetColorU32 ( g.ActiveId == id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab ), style.GrabRounding );
}
const void* pdata_temp = 0;
int val = 0;
if ( data_type == ImGuiDataType_S32 || data_type == ImGuiDataType_U32 )
{
int data = [I]( int[/I] ) ( p_data );
animation->second.value_anim_int = ImLerp ( animation->second.value_anim_int, ( float ) data, g.IO.DeltaTime * 7.f );
if ( abs ( ( int ) animation->second.value_anim_int - data ) < 2 )
animation->second.value_anim_int = ( float ) data;
val = ( int ) animation->second.value_anim_int;
pdata_temp = &val;
}
if ( data_type == ImGuiDataType_Float )
{
animation->second.value_anim = ImLerp ( animation->second.value_anim, [I]( float[/I] ) ( p_data ), g.IO.DeltaTime * 7.f );
pdata_temp = &animation->second.value_anim;
}
animation->second.text_grayness = ImLerp ( animation->second.text_grayness, ImGui::IsItemActive ( ) ? 1.f : 0.4f, g.IO.DeltaTime * 7 );
// Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
char value_buf [ 64 ];
const char* value_buf_end = value_buf + DataTypeFormatString ( value_buf, IM_ARRAYSIZE ( value_buf ), data_type, pdata_temp == 0 ? p_data : pdata_temp, format );
if ( g.LogEnabled )
LogSetNextTextDecoration ( "{", "}" );
ImVec2 value_size = ImGui::CalcTextSize ( value_buf );
RenderText ( ImVec2 ( frame_bb.Max.x - value_size.x, frame_bb.Min.y - 10.f ), value_buf, value_buf_end );
ImGui::PushStyleColor ( ImGuiCol_Text, ImVec4 ( animation->second.text_grayness, animation->second.text_grayness, animation->second.text_grayness, animation->second.text_grayness ) );
if ( label_size.x > 0.0f )
RenderText ( ImVec2 ( frame_bb.Min.x, frame_bb.Min.y - 10.f), label );
ImGui::PopStyleColor ( );
ImGui::Separator ( );
IMGUI_TEST_ENGINE_ITEM_INFO ( id, label, g.LastItemData.StatusFlags | ( temp_input_allowed ? ImGuiItemStatusFlags_Inputable : 0 ) );
return value_changed;
}
bool slider_float ( const char* label, float* v, float v_min, float v_max, const char* format = "%0.3f", ImGuiSliderFlags flags = ImGuiSliderFlags_NoInput )
{
return slider_scalar ( label, ImGuiDataType_Float, v, &v_min, &v_max, format, flags );
}
bool slider_int ( const char* label, int* v, int v_min, int v_max, const char* format = "%d", ImGuiSliderFlags flags = ImGuiSliderFlags_NoInput )
{
return slider_scalar ( label, ImGuiDataType_S32, v, &v_min, &v_max, format, flags );
}