Browse Source

Fixed more clang warnings + AddFontFromMemoryTTF() not honoring font_no parameter

ocornut 10 years ago
parent
commit
1f8d209202
3 changed files with 21 additions and 16 deletions
  1. 16 12
      imgui.cpp
  2. 2 2
      imgui.h
  3. 3 2
      stb_rect_pack.h

+ 16 - 12
imgui.cpp

@@ -321,22 +321,22 @@
 #pragma clang diagnostic ignored "-Wformat-nonliteral"      // warning : format string is not a string literal              // passing non-literal to vsnformat(). yes, user passing incorrect format strings can crash the code.
 #pragma clang diagnostic ignored "-Wexit-time-destructors"  // warning : declaration requires an exit-time destructor       // exit-time destruction order is undefined. if MemFree() leads to users code that has been disabled before exit it might cause problems. ImGui coding style welcomes static/globals.
 #pragma clang diagnostic ignored "-Wglobal-constructors"    // warning : declaration requires a global destructor           // similar to above, not sure what the exact difference it.
+#pragma clang diagnostic ignored "-Wsign-conversion"        // warning : implicit conversion chanjges signedness            // 
 #endif
 
 //-------------------------------------------------------------------------
 // STB libraries implementation
 //-------------------------------------------------------------------------
 
-#define STBRP_STATIC
-#define STB_RECT_PACK_IMPLEMENTATION
 #ifdef __clang__
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wunused-function"
+#pragma clang diagnostic ignored "-Wmissing-prototypes"
 #endif
+
+#define STBRP_STATIC
+#define STB_RECT_PACK_IMPLEMENTATION
 #include "stb_rect_pack.h"
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif
 
 #define STB_TRUETYPE_IMPLEMENTATION
 #define STBTT_malloc(x,u)  ((void)(u), ImGui::MemAlloc(x))
@@ -348,6 +348,10 @@ struct ImGuiTextEditState;
 #define STB_TEXTEDIT_CHARTYPE ImWchar
 #include "stb_textedit.h"
 
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
 //-------------------------------------------------------------------------
 // Forward Declarations
 //-------------------------------------------------------------------------
@@ -6376,11 +6380,11 @@ void    ImFontAtlas::GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_wid
     {
         unsigned char* pixels;
         GetTexDataAsAlpha8(&pixels, NULL, NULL);
-        TexPixelsRGBA32 = (unsigned int*)ImGui::MemAlloc(TexWidth * TexHeight * 4);
+        TexPixelsRGBA32 = (unsigned int*)ImGui::MemAlloc((size_t)(TexWidth * TexHeight * 4));
         const unsigned char* src = pixels;
         unsigned int* dst = TexPixelsRGBA32;
         for (int n = TexWidth * TexHeight; n > 0; n--)
-            *dst++ = ((*src++) << 24) | 0x00FFFFFF;
+            *dst++ = ((unsigned int)(*src++) << 24) | 0x00FFFFFF;
     }
 
     *out_pixels = (unsigned char*)TexPixelsRGBA32;
@@ -6440,7 +6444,7 @@ ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* in_ttf_data, size_t in_ttf_data_
     data->TTFDataSize = in_ttf_data_size;
     data->SizePixels = size_pixels;
     data->GlyphRanges = glyph_ranges;
-    data->FontNo = 0;
+    data->FontNo = font_no;
     InputData.push_back(data);
 
     // Invalidate texture
@@ -6497,7 +6501,7 @@ bool    ImFontAtlas::Build()
 
         // Setup ranges
         int glyph_count = 0;
-        int glyph_ranges_count = 0;
+        size_t glyph_ranges_count = 0;
         for (const ImWchar* in_range = data.GlyphRanges; in_range[0] && in_range[1]; in_range += 2)
         {
             glyph_count += (in_range[1] - in_range[0]) + 1;
@@ -6577,10 +6581,10 @@ bool    ImFontAtlas::Build()
                 data.OutFont->Glyphs.resize(data.OutFont->Glyphs.size() + 1);
                 ImFont::Glyph& glyph = data.OutFont->Glyphs.back();
                 glyph.Codepoint = (ImWchar)codepoint;
-                glyph.Width = pc.x1 - pc.x0 + 1;
-                glyph.Height = pc.y1 - pc.y0 + 1;
+                glyph.Width = (signed short)pc.x1 - pc.x0 + 1;
+                glyph.Height = (signed short)pc.y1 - pc.y0 + 1;
                 glyph.XOffset = (signed short)(pc.xoff);
-                glyph.YOffset = (signed short)(pc.yoff) + (int)(font_ascent * font_scale);
+                glyph.YOffset = (signed short)(pc.yoff + (int)(font_ascent * font_scale));
                 glyph.XAdvance = (signed short)(pc.xadvance + character_spacing_x);  // Bake spacing into XAdvance
                 glyph.U0 = ((float)pc.x0 - 0.5f) * uv_scale_x;
                 glyph.V0 = ((float)pc.y0 - 0.5f) * uv_scale_y;

+ 2 - 2
imgui.h

@@ -433,7 +433,7 @@ enum ImGuiStyleVar_
     ImGuiStyleVar_FrameRounding,     // float
     ImGuiStyleVar_ItemSpacing,       // ImVec2
     ImGuiStyleVar_ItemInnerSpacing,  // ImVec2
-    ImGuiStyleVar_TreeNodeSpacing,   // float
+    ImGuiStyleVar_TreeNodeSpacing    // float
 };
 
 // Enumeration for ColorEditMode()
@@ -452,7 +452,7 @@ enum ImGuiSetCondition_
 {
     ImGuiSetCondition_Always              = 1 << 0, // Set the variable
     ImGuiSetCondition_FirstUseThisSession = 1 << 1, // Only set the variable on the first call for this window (once per session)
-    ImGuiSetCondition_FirstUseEver        = 1 << 2, // Only set the variable if the window doesn't exist in the .ini file
+    ImGuiSetCondition_FirstUseEver        = 1 << 2  // Only set the variable if the window doesn't exist in the .ini file
 };
 
 struct ImGuiStyle

+ 3 - 2
stb_rect_pack.h

@@ -129,7 +129,7 @@ enum
 {
    STBRP_HEURISTIC_Skyline_default=0,
    STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
-   STBRP_HEURISTIC_Skyline_BF_sortHeight,
+   STBRP_HEURISTIC_Skyline_BF_sortHeight
 };
 
 
@@ -178,7 +178,7 @@ struct stbrp_context
 
 enum
 {
-   STBRP__INIT_skyline = 1,
+   STBRP__INIT_skyline = 1
 };
 
 STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
@@ -248,6 +248,7 @@ STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height,
 // find minimum y position if it starts at x1
 static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
 {
+   (void)c;
    stbrp_node *node = first;
    int x1 = x0 + width;
    int min_y, visited_width, waste_area;