Skip to content

Commit 815d1d9

Browse files
committed
Merge remote-tracking branch 'origin' into 2015-07-cleanup
Conflicts: imgui.cpp
2 parents e099798 + 3aca446 commit 815d1d9

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

imgui.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3610,10 +3610,12 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_
36103610
else
36113611
{
36123612
ImU32 resize_col = 0;
3613+
const float resize_corner_size = ImMax(g.FontSize * 1.35f, window_rounding + 1.0f + g.FontSize * 0.2f);
36133614
if (!(flags & ImGuiWindowFlags_AlwaysAutoResize) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0 && !(flags & ImGuiWindowFlags_NoResize))
36143615
{
36153616
// Manual resize
3616-
const ImRect resize_rect(window->Rect().GetBR()-ImVec2(14,14), window->Rect().GetBR());
3617+
const ImVec2 br = window->Rect().GetBR();
3618+
const ImRect resize_rect(br - ImVec2(resize_corner_size * 0.75f, resize_corner_size * 0.75f), br);
36173619
const ImGuiID resize_id = window->GetID("#RESIZE");
36183620
bool hovered, held;
36193621
ButtonBehavior(resize_rect, resize_id, &hovered, &held, true, ImGuiButtonFlags_FlattenChilds);
@@ -3687,12 +3689,9 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_
36873689
// (after the input handling so we don't have a frame of latency)
36883690
if (!(flags & ImGuiWindowFlags_NoResize))
36893691
{
3690-
const float base_size = g.FontSize * 1.35f;
3691-
const float min_size = window_rounding + 1.0f + g.FontSize * 0.2f;
3692-
const float corner_size = ImMax(base_size, min_size);
36933692
const ImVec2 br = window->Rect().GetBR();
3694-
window->DrawList->PathLineTo(br + ImVec2(-corner_size, 0.0f));
3695-
window->DrawList->PathLineTo(br + ImVec2(0.0f, -corner_size));
3693+
window->DrawList->PathLineTo(br + ImVec2(-resize_corner_size, 0.0f));
3694+
window->DrawList->PathLineTo(br + ImVec2(0.0f, -resize_corner_size));
36963695
window->DrawList->PathArcToFast(ImVec2(br.x - window_rounding, br.y - window_rounding), window_rounding, 0, 3);
36973696
window->DrawList->PathFill(resize_col);
36983697
}

imgui.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,8 @@ struct ImFontAtlas
11571157
IMGUI_API ImFont* AddFontDefault(const ImFontConfig* font_cfg = NULL);
11581158
IMGUI_API ImFont* AddFontFromFileTTF(const char* filename, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL);
11591159
IMGUI_API ImFont* AddFontFromMemoryTTF(void* ttf_data, int ttf_size, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL); // Transfer ownership of 'ttf_data' to ImFontAtlas, will be deleted after Build()
1160-
IMGUI_API ImFont* AddFontFromMemoryCompressedTTF(const void* compressed_ttf_data, int compressed_ttf_size, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL); // 'compressed_ttf_data' untouched and still owned by caller. Compress with binary_to_compressed_c.cpp
1160+
IMGUI_API ImFont* AddFontFromMemoryCompressedTTF(const void* compressed_ttf_data, int compressed_ttf_size, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL); // 'compressed_ttf_data' still owned by caller. Compress with binary_to_compressed_c.cpp
1161+
IMGUI_API ImFont* AddFontFromMemoryCompressedBase85TTF(const char* compressed_ttf_data_base85, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL); // 'compressed_ttf_data_base85' still owned by caller. Compress with binary_to_compressed_c.cpp with -base85 paramaeter
11611162
IMGUI_API void ClearTexData(); // Clear the CPU-side texture data. Saves RAM once the texture has been copied to graphics memory.
11621163
IMGUI_API void ClearInputData(); // Clear the input TTF data (inc sizes, glyph ranges)
11631164
IMGUI_API void ClearFonts(); // Clear the ImGui-side font data (glyphs storage, UV coordinates)

imgui_draw.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -965,33 +965,26 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg)
965965
return Fonts.back();
966966
}
967967

968+
// Default font ttf is compressed with stb_compress then base85 encoded (see extra_fonts/binary_to_compressed_c.cpp for encoder)
968969
static unsigned int stb_decompress_length(unsigned char *input);
969970
static unsigned int stb_decompress(unsigned char *output, unsigned char *i, unsigned int length);
970-
971-
// Default font ttf is compressed with stb_compress then base85 encoded (see extra_fonts/binary_to_compressed_c.cpp for encoder)
972971
static const char* GetDefaultCompressedFontDataTTFBase85();
973972
static unsigned int Decode85Byte(char c) { return c >= '\\' ? c-36 : c-35; }
974973
static void Decode85(const unsigned char* src, unsigned int* dst) { for (; *src; src += 5) *dst++ = Decode85Byte(src[0]) + 85*(Decode85Byte(src[1]) + 85*(Decode85Byte(src[2]) + 85*(Decode85Byte(src[3]) + 85*Decode85Byte(src[4])))); }
975974

976975
// Load embedded ProggyClean.ttf at size 13
977976
ImFont* ImFontAtlas::AddFontDefault(const ImFontConfig* font_cfg_template)
978977
{
979-
const char* ttf_compressed_base85 = GetDefaultCompressedFontDataTTFBase85();
980-
int ttf_compressed_size = (((int)strlen(ttf_compressed_base85) + 4) / 5) * 4;
981-
void* ttf_compressed = ImGui::MemAlloc(ttf_compressed_size);
982-
Decode85((const unsigned char*)ttf_compressed_base85, (unsigned int*)ttf_compressed);
983-
984-
ImFontConfig font_cfg;
985-
if (font_cfg_template)
986-
font_cfg = *font_cfg_template;
987-
else
978+
ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig();
979+
if (!font_cfg_template)
988980
{
989981
font_cfg.OversampleH = font_cfg.OversampleV = 1;
990982
font_cfg.PixelSnapH = true;
991983
}
992984
if (font_cfg.Name[0] == '\0') strcpy(font_cfg.Name, "<default>");
993-
ImFont* font = AddFontFromMemoryCompressedTTF(ttf_compressed, ttf_compressed_size, 13.0f, &font_cfg, GetGlyphRangesDefault());
994-
ImGui::MemFree(ttf_compressed);
985+
986+
const char* ttf_compressed_base85 = GetDefaultCompressedFontDataTTFBase85();
987+
ImFont* font = AddFontFromMemoryCompressedBase85TTF(ttf_compressed_base85, 13.0f, &font_cfg, GetGlyphRangesDefault());
995988
return font;
996989
}
997990

@@ -1039,6 +1032,16 @@ ImFont* ImFontAtlas::AddFontFromMemoryCompressedTTF(const void* compressed_ttf_d
10391032
return AddFontFromMemoryTTF(buf_decompressed_data, (int)buf_decompressed_size, size_pixels, font_cfg_template, glyph_ranges);
10401033
}
10411034

1035+
ImFont* ImFontAtlas::AddFontFromMemoryCompressedBase85TTF(const char* compressed_ttf_data_base85, float size_pixels, const ImFontConfig* font_cfg, const ImWchar* glyph_ranges)
1036+
{
1037+
int compressed_ttf_size = (((int)strlen(compressed_ttf_data_base85) + 4) / 5) * 4;
1038+
void* compressed_ttf = ImGui::MemAlloc(compressed_ttf_size);
1039+
Decode85((const unsigned char*)compressed_ttf_data_base85, (unsigned int*)compressed_ttf);
1040+
ImFont* font = AddFontFromMemoryCompressedTTF(compressed_ttf, compressed_ttf_size, size_pixels, font_cfg, glyph_ranges);
1041+
ImGui::MemFree(compressed_ttf);
1042+
return font;
1043+
}
1044+
10421045
bool ImFontAtlas::Build()
10431046
{
10441047
IM_ASSERT(ConfigData.Size > 0);

0 commit comments

Comments
 (0)