@ -3249,6 +3249,34 @@ void ImGui::RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFl
}
}
}
}
void ImGui : : RenderMouseCursor ( ImVec2 base_pos , float base_scale , ImGuiMouseCursor mouse_cursor , ImU32 col_fill , ImU32 col_border , ImU32 col_shadow )
{
ImGuiContext & g = * GImGui ;
IM_ASSERT ( mouse_cursor > ImGuiMouseCursor_None & & mouse_cursor < ImGuiMouseCursor_COUNT ) ;
ImFontAtlas * font_atlas = g . DrawListSharedData . Font - > ContainerAtlas ;
for ( int n = 0 ; n < g . Viewports . Size ; n + + )
{
// We scale cursor with current viewport/monitor, however Windows 10 for its own hardware cursor seems to be using a different scale factor.
ImVec2 offset , size , uv [ 4 ] ;
if ( ! font_atlas - > GetMouseCursorTexData ( mouse_cursor , & offset , & size , & uv [ 0 ] , & uv [ 2 ] ) )
continue ;
ImGuiViewportP * viewport = g . Viewports [ n ] ;
const ImVec2 pos = base_pos - offset ;
const float scale = base_scale * viewport - > DpiScale ;
if ( ! viewport - > GetMainRect ( ) . Overlaps ( ImRect ( pos , pos + ImVec2 ( size . x + 2 , size . y + 2 ) * scale ) ) )
continue ;
ImDrawList * draw_list = GetForegroundDrawList ( viewport ) ;
ImTextureID tex_id = font_atlas - > TexID ;
draw_list - > PushTextureID ( tex_id ) ;
draw_list - > AddImage ( tex_id , pos + ImVec2 ( 1 , 0 ) * scale , pos + ( ImVec2 ( 1 , 0 ) + size ) * scale , uv [ 2 ] , uv [ 3 ] , col_shadow ) ;
draw_list - > AddImage ( tex_id , pos + ImVec2 ( 2 , 0 ) * scale , pos + ( ImVec2 ( 2 , 0 ) + size ) * scale , uv [ 2 ] , uv [ 3 ] , col_shadow ) ;
draw_list - > AddImage ( tex_id , pos , pos + size * scale , uv [ 2 ] , uv [ 3 ] , col_border ) ;
draw_list - > AddImage ( tex_id , pos , pos + size * scale , uv [ 0 ] , uv [ 1 ] , col_fill ) ;
draw_list - > PopTextureID ( ) ;
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// [SECTION] MAIN CODE (most of the code! lots of stuff, needs tidying up!)
// [SECTION] MAIN CODE (most of the code! lots of stuff, needs tidying up!)
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
@ -5129,9 +5157,9 @@ void ImGui::Render()
if ( first_render_of_frame )
if ( first_render_of_frame )
RenderDimmedBackgrounds ( ) ;
RenderDimmedBackgrounds ( ) ;
ImVec2 mouse_cursor_offset , mouse_cursor_size , mouse_cursor_uv [ 4 ] ;
// Draw software mouse cursor if requested by io.MouseDrawCursor flag
if ( g . IO . MouseDrawCursor & & g. MouseCursor ! = ImGuiMouseCursor_None )
if ( g . IO . MouseDrawCursor & & first_render_of_frame & & g. MouseCursor ! = ImGuiMouseCursor_None )
g. IO . Fonts - > GetMouseCursorTexData ( g . MouseCursor , & mouse_cursor_offset , & mouse_cursor_size , & mouse_cursor_uv [ 0 ] , & mouse_cursor_uv [ 2 ] ) ;
RenderMouseCursor( g . IO . MousePos , g . Style . MouseCursorScale , g . MouseCursor , IM_COL32_WHITE , IM_COL32_BLACK , IM_COL32 ( 0 , 0 , 0 , 48 ) ) ;
// Setup ImDrawData structures for end-user
// Setup ImDrawData structures for end-user
g . IO . MetricsRenderVertices = g . IO . MetricsRenderIndices = 0 ;
g . IO . MetricsRenderVertices = g . IO . MetricsRenderIndices = 0 ;
@ -5140,15 +5168,6 @@ void ImGui::Render()
ImGuiViewportP * viewport = g . Viewports [ n ] ;
ImGuiViewportP * viewport = g . Viewports [ n ] ;
viewport - > DrawDataBuilder . FlattenIntoSingleLayer ( ) ;
viewport - > DrawDataBuilder . FlattenIntoSingleLayer ( ) ;
// Draw software mouse cursor if requested by io.MouseDrawCursor flag
// (note we scale cursor by current viewport/monitor, however Windows 10 for its own hardware cursor seems to be using a different scale factor)
if ( mouse_cursor_size . x > 0.0f & & mouse_cursor_size . y > 0.0f & & first_render_of_frame )
{
float scale = g . Style . MouseCursorScale * viewport - > DpiScale ;
if ( viewport - > GetMainRect ( ) . Overlaps ( ImRect ( g . IO . MousePos , g . IO . MousePos + ImVec2 ( mouse_cursor_size . x + 2 , mouse_cursor_size . y + 2 ) * scale ) ) )
RenderMouseCursor ( GetForegroundDrawList ( viewport ) , g . IO . MousePos , scale , g . MouseCursor , IM_COL32_WHITE , IM_COL32_BLACK , IM_COL32 ( 0 , 0 , 0 , 48 ) ) ;
}
// Add foreground ImDrawList (for each active viewport)
// Add foreground ImDrawList (for each active viewport)
if ( viewport - > DrawLists [ 1 ] ! = NULL )
if ( viewport - > DrawLists [ 1 ] ! = NULL )
AddDrawListToDrawData ( & viewport - > DrawDataBuilder . Layers [ 0 ] , GetForegroundDrawList ( viewport ) ) ;
AddDrawListToDrawData ( & viewport - > DrawDataBuilder . Layers [ 0 ] , GetForegroundDrawList ( viewport ) ) ;