MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / RenderMouseCursor

Method RenderMouseCursor

imgui_tiny_app/imgui/imgui.cpp:4106–4138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4104}
4105
4106void ImGui::RenderMouseCursor(ImVec2 base_pos, float base_scale, ImGuiMouseCursor mouse_cursor, ImU32 col_fill, ImU32 col_border, ImU32 col_shadow)
4107{
4108 ImGuiContext& g = *GImGui;
4109 if (mouse_cursor <= ImGuiMouseCursor_None || mouse_cursor >= ImGuiMouseCursor_COUNT) // We intentionally accept out of bound values.
4110 mouse_cursor = ImGuiMouseCursor_Arrow;
4111 ImFontAtlas* font_atlas = g.DrawListSharedData.FontAtlas;
4112 for (ImGuiViewportP* viewport : g.Viewports)
4113 {
4114 // We scale cursor with current viewport/monitor, however Windows 10 for its own hardware cursor seems to be using a different scale factor.
4115 ImVec2 offset, size, uv[4];
4116 if (!ImFontAtlasGetMouseCursorTexData(font_atlas, mouse_cursor, &offset, &size, &uv[0], &uv[2]))
4117 continue;
4118 const ImVec2 pos = base_pos - offset;
4119 const float scale = base_scale * viewport->DpiScale;
4120 if (!viewport->GetMainRect().Overlaps(ImRect(pos, pos + ImVec2(size.x + 2, size.y + 2) * scale)))
4121 continue;
4122 ImDrawList* draw_list = GetForegroundDrawList(viewport);
4123 ImTextureRef tex_ref = font_atlas->TexRef;
4124 draw_list->PushTexture(tex_ref);
4125 draw_list->AddImage(tex_ref, pos + ImVec2(1, 0) * scale, pos + (ImVec2(1, 0) + size) * scale, uv[2], uv[3], col_shadow);
4126 draw_list->AddImage(tex_ref, pos + ImVec2(2, 0) * scale, pos + (ImVec2(2, 0) + size) * scale, uv[2], uv[3], col_shadow);
4127 draw_list->AddImage(tex_ref, pos, pos + size * scale, uv[2], uv[3], col_border);
4128 draw_list->AddImage(tex_ref, pos, pos + size * scale, uv[0], uv[1], col_fill);
4129 if (mouse_cursor == ImGuiMouseCursor_Wait || mouse_cursor == ImGuiMouseCursor_Progress)
4130 {
4131 float a_min = ImFmod((float)g.Time * 5.0f, 2.0f * IM_PI);
4132 float a_max = a_min + IM_PI * 1.65f;
4133 draw_list->PathArcTo(pos + ImVec2(14, -1) * scale, 6.0f * scale, a_min, a_max);
4134 draw_list->PathStroke(col_fill, ImDrawFlags_None, 3.0f * scale);
4135 }
4136 draw_list->PopTexture();
4137 }
4138}
4139
4140//-----------------------------------------------------------------------------
4141// [SECTION] INITIALIZATION, SHUTDOWN

Callers

nothing calls this directly

Calls 10

ImVec2Function · 0.85
GetForegroundDrawListFunction · 0.85
GetMainRectMethod · 0.80
PushTextureMethod · 0.80
AddImageMethod · 0.80
PathArcToMethod · 0.80
PathStrokeMethod · 0.80
PopTextureMethod · 0.80
ImRectFunction · 0.70

Tested by

no test coverage detected