@ -277,10 +277,27 @@ void ImGui::StyleColorsLight(ImGuiStyle* dst)
}
//-----------------------------------------------------------------------------
// ImDrawList
// ImDrawList Data
//-----------------------------------------------------------------------------
static const ImVec4 GNullClipRect ( - 8192.0f , - 8192.0f , + 8192.0f , + 8192.0f ) ; // Large values that are easy to encode in a few bits+shift
ImDrawListSharedData : : ImDrawListSharedData ( )
{
Font = NULL ;
FontSize = 0.0f ;
CurveTessellationTol = 0.0f ;
ClipRectFullscreen = ImVec4 ( - 8192.0f , - 8192.0f , + 8192.0f , + 8192.0f ) ;
// Const data
for ( int i = 0 ; i < IM_ARRAYSIZE ( CircleVtx12 ) ; i + + )
{
const float a = ( ( float ) i * 2 * IM_PI ) / ( float ) IM_ARRAYSIZE ( CircleVtx12 ) ;
CircleVtx12 [ i ] = ImVec2 ( cosf ( a ) , sinf ( a ) ) ;
}
}
//-----------------------------------------------------------------------------
// ImDrawList
//-----------------------------------------------------------------------------
void ImDrawList : : Clear ( )
{
@ -321,7 +338,7 @@ void ImDrawList::ClearFreeMemory()
}
// Using macros because C++ is a terrible language, we want guaranteed inline, no code in header, and no overhead in Debug builds
# define GetCurrentClipRect() (_ClipRectStack.Size ? _ClipRectStack.Data[_ClipRectStack.Size-1] : GNullClipRect )
# define GetCurrentClipRect() (_ClipRectStack.Size ? _ClipRectStack.Data[_ClipRectStack.Size-1] : _Data->ClipRectFullscreen )
# define GetCurrentTextureId() (_TextureIdStack.Size ? _TextureIdStack.Data[_TextureIdStack.Size-1] : NULL)
void ImDrawList : : AddDrawCmd ( )
@ -412,8 +429,7 @@ void ImDrawList::PushClipRect(ImVec2 cr_min, ImVec2 cr_max, bool intersect_with_
void ImDrawList : : PushClipRectFullScreen ( )
{
PushClipRect ( ImVec2 ( GNullClipRect . x , GNullClipRect . y ) , ImVec2 ( GNullClipRect . z , GNullClipRect . w ) ) ;
//PushClipRect(GetVisibleRect()); // FIXME-OPT: This would be more correct but we're not supposed to access ImGuiContext from here?
PushClipRect ( ImVec2 ( _Data - > ClipRectFullscreen . x , _Data - > ClipRectFullscreen . y ) , ImVec2 ( _Data - > ClipRectFullscreen . z , _Data - > ClipRectFullscreen . w ) ) ;
}
void ImDrawList : : PopClipRect ( )
@ -533,7 +549,7 @@ void ImDrawList::PrimReserve(int idx_count, int vtx_count)
// Fully unrolled with inline call to keep our debug builds decently fast.
void ImDrawList : : PrimRect ( const ImVec2 & a , const ImVec2 & c , ImU32 col )
{
ImVec2 b ( c . x , a . y ) , d ( a . x , c . y ) , uv ( GImGui- > Font TexUvWhitePixel) ;
ImVec2 b ( c . x , a . y ) , d ( a . x , c . y ) , uv ( _Data- > TexUvWhitePixel) ;
ImDrawIdx idx = ( ImDrawIdx ) _VtxCurrentIdx ;
_IdxWritePtr [ 0 ] = idx ; _IdxWritePtr [ 1 ] = ( ImDrawIdx ) ( idx + 1 ) ; _IdxWritePtr [ 2 ] = ( ImDrawIdx ) ( idx + 2 ) ;
_IdxWritePtr [ 3 ] = idx ; _IdxWritePtr [ 4 ] = ( ImDrawIdx ) ( idx + 2 ) ; _IdxWritePtr [ 5 ] = ( ImDrawIdx ) ( idx + 3 ) ;
@ -581,7 +597,7 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32
if ( points_count < 2 )
return ;
const ImVec2 uv = GImGui- > Font TexUvWhitePixel;
const ImVec2 uv = _Data- > TexUvWhitePixel;
anti_aliased & = GImGui - > Style . AntiAliasedLines ;
//if (ImGui::GetIO().KeyCtrl) anti_aliased = false; // Debug
@ -759,7 +775,7 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32
void ImDrawList : : AddConvexPolyFilled ( const ImVec2 * points , const int points_count , ImU32 col , bool anti_aliased )
{
const ImVec2 uv = GImGui- > Font TexUvWhitePixel;
const ImVec2 uv = _Data- > TexUvWhitePixel;
anti_aliased & = GImGui - > Style . AntiAliasedShapes ;
//if (ImGui::GetIO().KeyCtrl) anti_aliased = false; // Debug
@ -842,20 +858,6 @@ void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_coun
void ImDrawList : : PathArcToFast ( const ImVec2 & centre , float radius , int a_min_of_12 , int a_max_of_12 )
{
static ImVec2 circle_vtx [ 12 ] ;
static bool circle_vtx_builds = false ;
const int circle_vtx_count = IM_ARRAYSIZE ( circle_vtx ) ;
if ( ! circle_vtx_builds )
{
for ( int i = 0 ; i < circle_vtx_count ; i + + )
{
const float a = ( ( float ) i / ( float ) circle_vtx_count ) * 2 * IM_PI ;
circle_vtx [ i ] . x = cosf ( a ) ;
circle_vtx [ i ] . y = sinf ( a ) ;
}
circle_vtx_builds = true ;
}
if ( radius = = 0.0f | | a_min_of_12 > a_max_of_12 )
{
_Path . push_back ( centre ) ;
@ -864,7 +866,7 @@ void ImDrawList::PathArcToFast(const ImVec2& centre, float radius, int a_min_of_
_Path . reserve ( _Path . Size + ( a_max_of_12 - a_min_of_12 + 1 ) ) ;
for ( int a = a_min_of_12 ; a < = a_max_of_12 ; a + + )
{
const ImVec2 & c = circle_vtx[ a % circle_vtx_count ] ;
const ImVec2 & c = _Data- > CircleVtx12 [ a % IM_ARRAYSIZE ( _Data - > CircleVtx12 ) ] ;
_Path . push_back ( ImVec2 ( centre . x + c . x * radius , centre . y + c . y * radius ) ) ;
}
}
@ -916,7 +918,7 @@ void ImDrawList::PathBezierCurveTo(const ImVec2& p2, const ImVec2& p3, const ImV
if ( num_segments = = 0 )
{
// Auto-tessellated
PathBezierToCasteljau ( & _Path , p1 . x , p1 . y , p2 . x , p2 . y , p3 . x , p3 . y , p4 . x , p4 . y , GImGui- > Style . CurveTessellationTol , 0 ) ;
PathBezierToCasteljau ( & _Path , p1 . x , p1 . y , p2 . x , p2 . y , p3 . x , p3 . y , p4 . x , p4 . y , _Data- > CurveTessellationTol , 0 ) ;
}
else
{
@ -998,7 +1000,7 @@ void ImDrawList::AddRectFilledMultiColor(const ImVec2& a, const ImVec2& c, ImU32
if ( ( ( col_upr_left | col_upr_right | col_bot_right | col_bot_left ) & IM_COL32_A_MASK ) = = 0 )
return ;
const ImVec2 uv = GImGui- > Font TexUvWhitePixel;
const ImVec2 uv = _Data- > TexUvWhitePixel;
PrimReserve ( 6 , 4 ) ;
PrimWriteIdx ( ( ImDrawIdx ) ( _VtxCurrentIdx ) ) ; PrimWriteIdx ( ( ImDrawIdx ) ( _VtxCurrentIdx + 1 ) ) ; PrimWriteIdx ( ( ImDrawIdx ) ( _VtxCurrentIdx + 2 ) ) ;
PrimWriteIdx ( ( ImDrawIdx ) ( _VtxCurrentIdx ) ) ; PrimWriteIdx ( ( ImDrawIdx ) ( _VtxCurrentIdx + 2 ) ) ; PrimWriteIdx ( ( ImDrawIdx ) ( _VtxCurrentIdx + 3 ) ) ;
@ -1094,12 +1096,11 @@ void ImDrawList::AddText(const ImFont* font, float font_size, const ImVec2& pos,
if ( text_begin = = text_end )
return ;
// IMPORTANT: This is one of the few instance of breaking the encapsulation of ImDrawList, as we pull this from ImGui state, but it is just SO useful.
// Might just move Font/FontSize to ImDrawList?
// Pull default font/size from the shared ImDrawListSharedData instance
if ( font = = NULL )
font = GImGui - > Font ;
font = _Data - > Font ;
if ( font_size = = 0.0f )
font_size = GImGui - > FontSize ;
font_size = _Data - > FontSize ;
IM_ASSERT ( font - > ContainerAtlas - > TexID = = _TextureIdStack . back ( ) ) ; // Use high-level ImGui::PushFont() or low-level ImDrawList::PushTextureId() to change font.