From da3baebd43e20befe46df1ced7ece8b69eceb759 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 2 Aug 2015 09:15:36 -0600 Subject: [PATCH 1/2] Fixed lower-right resize grip hit box not scaling along with its rendered size (#287) --- imgui.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index df2eabf15..dcd613e04 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3972,10 +3972,12 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_ else { ImU32 resize_col = 0; + const float resize_corner_size = ImMax(g.FontSize * 1.35f, window_rounding + 1.0f + g.FontSize * 0.2f); if (!(flags & ImGuiWindowFlags_AlwaysAutoResize) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0 && !(flags & ImGuiWindowFlags_NoResize)) { // Manual resize - const ImRect resize_rect(window->Rect().GetBR()-ImVec2(14,14), window->Rect().GetBR()); + const ImVec2 br = window->Rect().GetBR(); + const ImRect resize_rect(br - ImVec2(resize_corner_size * 0.75f, resize_corner_size * 0.75f), br); const ImGuiID resize_id = window->GetID("#RESIZE"); bool hovered, held; ButtonBehavior(resize_rect, resize_id, &hovered, &held, true, ImGuiButtonFlags_FlattenChilds); @@ -4049,12 +4051,9 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_ // (after the input handling so we don't have a frame of latency) if (!(flags & ImGuiWindowFlags_NoResize)) { - const float base_size = g.FontSize * 1.35f; - const float min_size = window_rounding + 1.0f + g.FontSize * 0.2f; - const float corner_size = ImMax(base_size, min_size); const ImVec2 br = window->Rect().GetBR(); - window->DrawList->PathLineTo(br + ImVec2(-corner_size, 0.0f)); - window->DrawList->PathLineTo(br + ImVec2(0.0f, -corner_size)); + window->DrawList->PathLineTo(br + ImVec2(-resize_corner_size, 0.0f)); + window->DrawList->PathLineTo(br + ImVec2(0.0f, -resize_corner_size)); window->DrawList->PathArcToFast(ImVec2(br.x - window_rounding, br.y - window_rounding), window_rounding, 0, 3); window->DrawList->PathFill(resize_col); } From 3aca4468176b55638188006d6aa5ab40c69fb170 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 3 Aug 2015 08:10:10 -0600 Subject: [PATCH 2/2] Added ImFontAtlas::AddFontFromMemoryCompressedBase85TTF() --- imgui.cpp | 29 ++++++++++++++++------------- imgui.h | 3 ++- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index dcd613e04..af32df115 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9895,10 +9895,9 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg) return Fonts.back(); } +// Default font ttf is compressed with stb_compress then base85 encoded (see extra_fonts/binary_to_compressed_c.cpp for encoder) static unsigned int stb_decompress_length(unsigned char *input); static unsigned int stb_decompress(unsigned char *output, unsigned char *i, unsigned int length); - -// Default font ttf is compressed with stb_compress then base85 encoded (see extra_fonts/binary_to_compressed_c.cpp for encoder) static const char* GetDefaultCompressedFontDataTTFBase85(); static unsigned int Decode85Byte(char c) { return c >= '\\' ? c-36 : c-35; } 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])))); } @@ -9906,22 +9905,16 @@ static void Decode85(const unsigned char* src, unsigned int* dst) { fo // Load embedded ProggyClean.ttf at size 13 ImFont* ImFontAtlas::AddFontDefault(const ImFontConfig* font_cfg_template) { - const char* ttf_compressed_base85 = GetDefaultCompressedFontDataTTFBase85(); - int ttf_compressed_size = (((int)strlen(ttf_compressed_base85) + 4) / 5) * 4; - void* ttf_compressed = ImGui::MemAlloc(ttf_compressed_size); - Decode85((const unsigned char*)ttf_compressed_base85, (unsigned int*)ttf_compressed); - - ImFontConfig font_cfg; - if (font_cfg_template) - font_cfg = *font_cfg_template; - else + ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig(); + if (!font_cfg_template) { font_cfg.OversampleH = font_cfg.OversampleV = 1; font_cfg.PixelSnapH = true; } if (font_cfg.Name[0] == '\0') strcpy(font_cfg.Name, ""); - ImFont* font = AddFontFromMemoryCompressedTTF(ttf_compressed, ttf_compressed_size, 13.0f, &font_cfg, GetGlyphRangesDefault()); - ImGui::MemFree(ttf_compressed); + + const char* ttf_compressed_base85 = GetDefaultCompressedFontDataTTFBase85(); + ImFont* font = AddFontFromMemoryCompressedBase85TTF(ttf_compressed_base85, 13.0f, &font_cfg, GetGlyphRangesDefault()); return font; } @@ -9969,6 +9962,16 @@ ImFont* ImFontAtlas::AddFontFromMemoryCompressedTTF(const void* compressed_ttf_d return AddFontFromMemoryTTF(buf_decompressed_data, (int)buf_decompressed_size, size_pixels, font_cfg_template, glyph_ranges); } +ImFont* ImFontAtlas::AddFontFromMemoryCompressedBase85TTF(const char* compressed_ttf_data_base85, float size_pixels, const ImFontConfig* font_cfg, const ImWchar* glyph_ranges) +{ + int compressed_ttf_size = (((int)strlen(compressed_ttf_data_base85) + 4) / 5) * 4; + void* compressed_ttf = ImGui::MemAlloc(compressed_ttf_size); + Decode85((const unsigned char*)compressed_ttf_data_base85, (unsigned int*)compressed_ttf); + ImFont* font = AddFontFromMemoryCompressedTTF(compressed_ttf, compressed_ttf_size, size_pixels, font_cfg, glyph_ranges); + ImGui::MemFree(compressed_ttf); + return font; +} + bool ImFontAtlas::Build() { IM_ASSERT(ConfigData.Size > 0); diff --git a/imgui.h b/imgui.h index 9f3ea0cd2..e7c5315da 100644 --- a/imgui.h +++ b/imgui.h @@ -1155,7 +1155,8 @@ struct ImFontAtlas IMGUI_API ImFont* AddFontDefault(const ImFontConfig* font_cfg = NULL); IMGUI_API ImFont* AddFontFromFileTTF(const char* filename, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL); 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() - 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 + 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 + 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 IMGUI_API void ClearTexData(); // Clear the CPU-side texture data. Saves RAM once the texture has been copied to graphics memory. IMGUI_API void ClearInputData(); // Clear the input TTF data (inc sizes, glyph ranges) IMGUI_API void ClearFonts(); // Clear the ImGui-side font data (glyphs storage, UV coordinates)