@ -9578,47 +9578,180 @@ static void ShowExampleAppCustomRendering(bool* p_open)
if ( ImGui : : BeginTabItem ( " Shadows " ) )
if ( ImGui : : BeginTabItem ( " Shadows " ) )
{
{
static float shadow_thickness = 40.0f ;
static float shadow_thickness = 40.0f ;
static bool shadow_filled = false ;
static ImVec4 shadow_color = ImVec4 ( 0.0f , 0.0f , 0.0f , 1.0f ) ;
static ImVec4 shadow_color = ImVec4 ( 0.0f , 0.0f , 0.0f , 1.0f ) ;
static ImVec4 shape_color = ImVec4 ( 0.9f , 0.0f , 0.0f , 1.0f ) ;
static bool shadow_filled = false ;
static ImVec4 shape_color = ImVec4 ( 0.9f , 0.6f , 0.3f , 1.0f ) ;
static float shape_rounding = 0.0f ;
static float shape_rounding = 0.0f ;
static ImVec4 bg_color = ImVec4 ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
static ImVec2 shadow_offset ( 0.0f , 0.0f ) ;
static ImVec4 background_color = ImVec4 ( 0.5f , 0.5f , 0.7f , 1.0f ) ;
static bool wireframe = false ;
static bool aa = true ;
static int poly_shape_index = 0 ;
ImGui : : Checkbox ( " Shadow filled " , & shadow_filled ) ;
ImGui : : Checkbox ( " Shadow filled " , & shadow_filled ) ;
ImGui : : SameLine ( ) ;
ImGui : : SameLine ( ) ;
HelpMarker ( " This will fill the section behind the shape to shadow. It's often unnecessary and wasteful but provided for consistency. " ) ;
HelpMarker ( " This will fill the section behind the shape to shadow. It's often unnecessary and wasteful but provided for consistency. " ) ;
ImGui : : Checkbox ( " Wireframe shapes " , & wireframe ) ;
ImGui : : SameLine ( ) ;
HelpMarker ( " This draws the shapes in wireframe so you can see the shadow underneath. " ) ;
ImGui : : Checkbox ( " Anti-aliasing " , & aa ) ;
ImGui : : DragFloat ( " Shadow Thickness " , & shadow_thickness , 1.0f , 0.0f , 100.0f , " %.02f " ) ;
ImGui : : DragFloat ( " Shadow Thickness " , & shadow_thickness , 1.0f , 0.0f , 100.0f , " %.02f " ) ;
ImGui : : SliderFloat2 ( " Offset " , ( float * ) & shadow_offset , - 32.0f , 32.0f ) ;
ImGui : : SameLine ( ) ;
HelpMarker ( " Note that currently circles/convex shapes do not support non-zero offsets for unfilled shadows. " ) ;
ImGui : : ColorEdit4 ( " Background Color " , & background_color . x ) ;
ImGui : : ColorEdit4 ( " Shadow Color " , & shadow_color . x ) ;
ImGui : : ColorEdit4 ( " Shadow Color " , & shadow_color . x ) ;
ImGui : : ColorEdit4 ( " Shape Color " , & shape_color . x ) ;
ImGui : : ColorEdit4 ( " Shape Color " , & shape_color . x ) ;
ImGui : : DragFloat ( " Shape Rounding " , & shape_rounding , 1.0f , 0.0f , 20.0f , " %.02f " ) ;
ImGui : : DragFloat ( " Shape Rounding " , & shape_rounding , 1.0f , 0.0f , 20.0f , " %.02f " ) ;
ImGui : : ColorEdit4 ( " Background Color " , & bg_color . x ) ;
ImGui : : Combo ( " Convex shape " , & poly_shape_index , " Shape 1 \0 Shape 2 \0 Shape 3 \0 Shape 4 \0 Shape 4 (winding reversed) " ) ;
ImDrawList * draw_list = ImGui : : GetWindowDrawList ( ) ;
ImDrawList * draw_list = ImGui : : GetWindowDrawList ( ) ;
ImDrawListFlags old_flags = draw_list - > Flags ;
if ( aa )
draw_list - > Flags | = ~ ImDrawListFlags_AntiAliasedFill ;
else
draw_list - > Flags & = ~ ImDrawListFlags_AntiAliasedFill ;
// Fill a strip of background
draw_list - > AddRectFilled ( ImVec2 ( ImGui : : GetCursorScreenPos ( ) . x , ImGui : : GetCursorScreenPos ( ) . y ) , ImVec2 ( ImGui : : GetCursorScreenPos ( ) . x + ImGui : : GetWindowContentRegionMax ( ) . x , ImGui : : GetCursorScreenPos ( ) . y + 200.0f ) , ImGui : : GetColorU32 ( background_color ) ) ;
// Rectangle
{
{
ImVec2 p = ImGui : : GetCursorScreenPos ( ) ;
ImVec2 p = ImGui : : GetCursorScreenPos ( ) ;
ImVec2 r1 ( p . x + 50.0f , p . y + 50.0f ) ;
ImVec2 r1 ( p . x + 50.0f , p . y + 50.0f ) ;
ImVec2 r2 ( p . x + 150.0f , p . y + 150.0f ) ;
ImVec2 r2 ( p . x + 150.0f , p . y + 150.0f ) ;
draw_list - > AddRectFilled ( p , ImVec2 ( p . x + 200.0f , p . y + 200.0f ) , ImGui : : GetColorU32 ( bg_color ) ) ;
if ( shadow_filled )
if ( shadow_filled )
draw_list - > AddShadowRectFilled ( r1 , r2 , shadow_thickness , ImVec2 ( 0.0f , 0.0f ) , ImGui : : GetColorU32 ( shadow_color ) ) ;
draw_list - > AddShadowRectFilled ( r1 , r2 , shadow_thickness , shadow_offset , ImGui : : GetColorU32 ( shadow_color ) ) ;
else
draw_list - > AddShadowRect ( r1 , r2 , shadow_thickness , shadow_offset , ImGui : : GetColorU32 ( shadow_color ) , shape_rounding ) ;
if ( wireframe )
draw_list - > AddRect ( r1 , r2 , ImGui : : GetColorU32 ( shape_color ) , shape_rounding ) ;
else
else
draw_list - > AddShadowRect ( r1 , r2 , shadow_thickness , ImVec2 ( 0.0f , 0.0f ) , ImGui : : GetColorU32 ( shadow_color ) , shape_rounding ) ;
draw_list - > AddRectFilled ( r1 , r2 , ImGui : : GetColorU32 ( shape_color ) , shape_rounding ) ;
draw_list - > AddRectFilled ( r1 , r2 , ImGui : : GetColorU32 ( shape_color ) , shape_rounding ) ;
ImGui : : Dummy ( ImVec2 ( 200.0f , 200.0f ) ) ;
ImGui : : Dummy ( ImVec2 ( 200.0f , 200.0f ) ) ;
}
}
ImGui : : SameLine ( ) ;
// Circle
{
{
ImVec2 p = ImGui : : GetCursorScreenPos ( ) ;
ImVec2 p = ImGui : : GetCursorScreenPos ( ) ;
ImVec2 center ( p . x + 100.0f , p . y + 100.0f ) ;
float off = 10.0f ;
float radius = 50.0f ;
ImVec2 r1 ( p . x + 50.0f + off , p . y + 50.0f + off ) ;
draw_list - > AddRectFilled ( p , ImVec2 ( p . x + 200.0f , p . y + 200.0f ) , ImGui : : GetColorU32 ( bg_color ) ) ;
ImVec2 r2 ( p . x + 150.0f - off , p . y + 150.0f - off ) ;
ImVec2 c ( p . x + 100.0f , p . y + 100.0f ) ;
if ( shadow_filled )
draw_list - > AddShadowCircleFilled ( c , 50.0f , shadow_thickness , shadow_offset , ImGui : : GetColorU32 ( shadow_color ) ) ;
else
draw_list - > AddShadowCircle ( c , 50.0f , shadow_thickness , ImVec2 ( 0.0f , 0.0f ) , ImGui : : GetColorU32 ( shadow_color ) ) ; // Offset forced to zero here because it isn't supported
if ( wireframe )
draw_list - > AddCircle ( c , 50.0f , ImGui : : GetColorU32 ( shape_color ) , 0 ) ;
else
draw_list - > AddCircleFilled ( c , 50.0f , ImGui : : GetColorU32 ( shape_color ) , 0 ) ;
ImGui : : Dummy ( ImVec2 ( 200.0f , 200.0f ) ) ;
}
ImGui : : SameLine ( ) ;
// Convex shape
{
ImVec2 pos = ImGui : : GetCursorScreenPos ( ) ;
const ImVec2 poly_centre ( pos . x + 50.0f , pos . y + 100.0f ) ;
ImVec2 * poly_points ;
int num_poly_points ;
switch ( poly_shape_index )
{
default :
case 0 :
{
ImVec2 poly_point_data [ ] =
{
ImVec2 ( poly_centre . x - 32.0f , poly_centre . y ) ,
ImVec2 ( poly_centre . x - 24.0f , poly_centre . y + 24.0f ) ,
ImVec2 ( poly_centre . x , poly_centre . y + 32.0f ) ,
ImVec2 ( poly_centre . x + 24.0f , poly_centre . y + 24.0f ) ,
ImVec2 ( poly_centre . x + 32.0f , poly_centre . y ) ,
ImVec2 ( poly_centre . x + 24.0f , poly_centre . y - 24.0f ) ,
ImVec2 ( poly_centre . x , poly_centre . y - 32.0f ) ,
ImVec2 ( poly_centre . x - 32.0f , poly_centre . y - 32.0f )
} ;
poly_points = poly_point_data ;
num_poly_points = 8 ;
break ;
}
case 1 :
{
ImVec2 poly_point_data [ ] =
{
ImVec2 ( poly_centre . x + 40.0f , poly_centre . y - 20.0f ) ,
ImVec2 ( poly_centre . x , poly_centre . y + 32.0f ) ,
ImVec2 ( poly_centre . x - 24.0f , poly_centre . y - 32.0f )
} ;
poly_points = poly_point_data ;
num_poly_points = 3 ;
break ;
}
case 2 :
{
ImVec2 poly_point_data [ ] =
{
ImVec2 ( poly_centre . x - 32.0f , poly_centre . y ) ,
ImVec2 ( poly_centre . x , poly_centre . y + 32.0f ) ,
ImVec2 ( poly_centre . x + 32.0f , poly_centre . y ) ,
ImVec2 ( poly_centre . x , poly_centre . y - 32.0f )
} ;
poly_points = poly_point_data ;
num_poly_points = 4 ;
break ;
}
case 3 :
{
ImVec2 poly_point_data [ ] =
{
ImVec2 ( poly_centre . x - 4.0f , poly_centre . y - 20.0f ) ,
ImVec2 ( poly_centre . x + 12.0f , poly_centre . y + 2.0f ) ,
ImVec2 ( poly_centre . x + 8.0f , poly_centre . y + 16.0f ) ,
ImVec2 ( poly_centre . x , poly_centre . y + 32.0f ) ,
ImVec2 ( poly_centre . x - 16.0f , poly_centre . y - 32.0f )
} ;
poly_points = poly_point_data ;
num_poly_points = 5 ;
break ;
}
case 4 : // Same as test case 3 but with reversed winding
{
ImVec2 poly_point_data [ ] =
{
ImVec2 ( poly_centre . x - 16.0f , poly_centre . y - 32.0f ) ,
ImVec2 ( poly_centre . x , poly_centre . y + 32.0f ) ,
ImVec2 ( poly_centre . x + 8.0f , poly_centre . y + 16.0f ) ,
ImVec2 ( poly_centre . x + 12.0f , poly_centre . y + 2.0f ) ,
ImVec2 ( poly_centre . x - 4.0f , poly_centre . y - 20.0f )
} ;
poly_points = poly_point_data ;
num_poly_points = 5 ;
break ;
}
}
if ( shadow_filled )
if ( shadow_filled )
draw_list - > AddShadowCircleFilled ( center , radius , shadow_thickness , ImVec2 ( 0.0f , 0.0f ) , ImGui : : GetColorU32 ( shadow_color ) , 0 ) ;
draw_list - > AddShadowConvexPolyFilled ( poly_points , num_poly_points , shadow_thickness , shadow_offset , ImGui : : GetColorU32 ( shadow_color ) ) ;
else
draw_list - > AddShadowConvexPoly ( poly_points , num_poly_points , shadow_thickness , ImVec2 ( 0.0f , 0.0f ) , ImGui : : GetColorU32 ( shadow_color ) ) ; // Offset forced to zero because it isn't supported
if ( wireframe )
draw_list - > AddPolyline ( poly_points , num_poly_points , ImGui : : GetColorU32 ( shape_color ) , true , 1.0f ) ;
else
else
draw_list - > AddShadowCircle ( center , radius , shadow_thickness , ImVec2 ( 0.0f , 0.0f ) , ImGui : : GetColorU32 ( shadow_color ) , 0 ) ;
draw_list - > AddConvexPolyFilled ( poly_points , num_poly_points , ImGui : : GetColorU32 ( shape_color ) ) ;
draw_list - > AddCircleFilled ( center , radius , ImGui : : GetColorU32 ( shape_color ) , 0 ) ;
ImGui : : Dummy ( ImVec2 ( 200.0f , 200.0f ) ) ;
ImGui : : Dummy ( ImVec2 ( 200.0f , 200.0f ) ) ;
}
}
draw_list - > Flags = old_flags ;
ImGui : : EndTabItem ( ) ;
ImGui : : EndTabItem ( ) ;
}
}