16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-17 23:39:18 +02:00

opengl 3.3 renderer integration, minor renderer tweaks

This commit is contained in:
tmj-fstate
2019-10-31 19:37:53 +01:00
parent 9dcaa1e339
commit ae3cecfa42
49 changed files with 1804 additions and 412 deletions

View File

@@ -598,6 +598,10 @@ namespace ImGui
IMGUI_API void* MemAlloc(size_t size);
IMGUI_API void MemFree(void* ptr);
// by zfedoran, https://github.com/ocornut/imgui/issues/1901
IMGUI_API bool BufferingBar( const char* label, float value, const ImVec2& size_arg, const ImU32& bg_col, const ImU32& fg_col );
IMGUI_API bool Spinner( const char* label, float radius, int thickness, const ImU32& color );
} // namespace ImGui
// Flags for ImGui::Begin()

View File

@@ -5728,3 +5728,91 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool* p_selected,
}
return false;
}
// by zfedoran, https://github.com/ocornut/imgui/issues/1901
bool ImGui::BufferingBar( const char* label, float value, const ImVec2& size_arg, const ImU32& bg_col, const ImU32& fg_col ) {
ImGuiWindow* window = GetCurrentWindow();
if( window->SkipItems )
return false;
ImGuiContext& g = *GImGui;
const ImGuiStyle& style = g.Style;
const ImGuiID id = window->GetID( label );
ImVec2 pos = window->DC.CursorPos;
ImVec2 size = size_arg;
size.x -= style.FramePadding.x * 2;
const ImRect bb( pos, ImVec2( pos.x + size.x, pos.y + size.y ) );
ItemSize( bb, style.FramePadding.y );
if( !ItemAdd( bb, id ) )
return false;
// Render
const float circleStart = std::max( size.x * 0.7f, size.x - 30.f );
const float circleEnd = size.x;
const float circleWidth = circleEnd - circleStart;
window->DrawList->AddRectFilled( bb.Min, ImVec2( pos.x + circleStart, bb.Max.y ), bg_col );
window->DrawList->AddRectFilled( bb.Min, ImVec2( pos.x + circleStart * value, bb.Max.y ), fg_col );
const float t = g.FrameCount * 0.1f; // g.Time;
const float r = size.y / 2;
const float speed = 1.5f;
const float a = speed * 0;
const float b = speed * 0.333f;
const float c = speed * 0.666f;
const float o1 = ( circleWidth + r ) * ( t + a - speed * (int)( ( t + a ) / speed ) ) / speed;
const float o2 = ( circleWidth + r ) * ( t + b - speed * (int)( ( t + b ) / speed ) ) / speed;
const float o3 = ( circleWidth + r ) * ( t + c - speed * (int)( ( t + c ) / speed ) ) / speed;
window->DrawList->AddCircleFilled( ImVec2( pos.x + circleEnd - o1, bb.Min.y + r ), r, bg_col );
window->DrawList->AddCircleFilled( ImVec2( pos.x + circleEnd - o2, bb.Min.y + r ), r, bg_col );
window->DrawList->AddCircleFilled( ImVec2( pos.x + circleEnd - o3, bb.Min.y + r ), r, bg_col );
return true;
}
bool ImGui::Spinner( const char* label, float radius, int thickness, const ImU32& color ) {
ImGuiWindow* window = GetCurrentWindow();
if( window->SkipItems )
return false;
ImGuiContext& g = *GImGui;
const ImGuiStyle& style = g.Style;
const ImGuiID id = window->GetID( label );
ImVec2 pos = window->DC.CursorPos;
ImVec2 size( ( radius ) * 2, ( radius + style.FramePadding.y ) * 2 );
const ImRect bb( pos, ImVec2( pos.x + size.x, pos.y + size.y ) );
ItemSize( bb, style.FramePadding.y );
if( !ItemAdd( bb, id ) )
return false;
// Render
window->DrawList->PathClear();
auto progress { g.FrameCount * 0.1f };
int num_segments = 30;
int start = abs( ImSin( progress * 1.8f )*( num_segments - 5 ) );
const float a_min = IM_PI * 2.0f * ( (float)start ) / (float)num_segments;
const float a_max = IM_PI * 2.0f * ( (float)num_segments - 3 ) / (float)num_segments;
const ImVec2 centre = ImVec2( pos.x + radius, pos.y + radius + style.FramePadding.y );
for( int i = 0; i < num_segments; i++ ) {
const float a = a_min + ( (float)i / (float)num_segments ) * ( a_max - a_min );
window->DrawList->PathLineTo( ImVec2( centre.x + ImCos( a + progress * 8 ) * radius,
centre.y + ImSin( a + progress * 8 ) * radius ) );
}
window->DrawList->PathStroke( color, false, thickness );
return true;
}