mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-11-03 22:51:06 +01:00 
			
		
		
		
	Removed direct dependency on sprintf() in imgui.cpp (#1038)
(NB: imgui_demo stills uses it)
This commit is contained in:
		
							
								
								
									
										13
									
								
								imgui.cpp
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								imgui.cpp
									
									
									
									
									
								
							@@ -9502,16 +9502,16 @@ void ImGui::ColorEditOptionsPopup(const float* col, ImGuiColorEditFlags flags)
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        int cr = IM_F32_TO_INT8_SAT(col[0]), cg = IM_F32_TO_INT8_SAT(col[1]), cb = IM_F32_TO_INT8_SAT(col[2]), ca = (flags & ImGuiColorEditFlags_NoAlpha) ? 255 : IM_F32_TO_INT8_SAT(col[3]);
 | 
					        int cr = IM_F32_TO_INT8_SAT(col[0]), cg = IM_F32_TO_INT8_SAT(col[1]), cb = IM_F32_TO_INT8_SAT(col[2]), ca = (flags & ImGuiColorEditFlags_NoAlpha) ? 255 : IM_F32_TO_INT8_SAT(col[3]);
 | 
				
			||||||
        char buf[64];
 | 
					        char buf[64];
 | 
				
			||||||
        sprintf(buf, "(%.3ff, %.3ff, %.3ff, %.3ff)", col[0], col[1], col[2], (flags & ImGuiColorEditFlags_NoAlpha) ? 1.0f : col[3]);
 | 
					        ImFormatString(buf, IM_ARRAYSIZE(buf), "(%.3ff, %.3ff, %.3ff, %.3ff)", col[0], col[1], col[2], (flags & ImGuiColorEditFlags_NoAlpha) ? 1.0f : col[3]);
 | 
				
			||||||
        if (Selectable(buf))
 | 
					        if (Selectable(buf))
 | 
				
			||||||
            SetClipboardText(buf);
 | 
					            SetClipboardText(buf);
 | 
				
			||||||
        sprintf(buf, "(%d,%d,%d,%d)", cr, cg, cb, ca);
 | 
					        ImFormatString(buf, IM_ARRAYSIZE(buf), "(%d,%d,%d,%d)", cr, cg, cb, ca);
 | 
				
			||||||
        if (Selectable(buf))
 | 
					        if (Selectable(buf))
 | 
				
			||||||
            SetClipboardText(buf);
 | 
					            SetClipboardText(buf);
 | 
				
			||||||
        if (flags & ImGuiColorEditFlags_NoAlpha)
 | 
					        if (flags & ImGuiColorEditFlags_NoAlpha)
 | 
				
			||||||
            sprintf(buf, "0x%02X%02X%02X", cr, cg, cb);
 | 
					            ImFormatString(buf, IM_ARRAYSIZE(buf), "0x%02X%02X%02X", cr, cg, cb);
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
            sprintf(buf, "0x%02X%02X%02X%02X", cr, cg, cb, ca);
 | 
					            ImFormatString(buf, IM_ARRAYSIZE(buf), "0x%02X%02X%02X%02X", cr, cg, cb, ca);
 | 
				
			||||||
        if (Selectable(buf))
 | 
					        if (Selectable(buf))
 | 
				
			||||||
            SetClipboardText(buf);
 | 
					            SetClipboardText(buf);
 | 
				
			||||||
        EndPopup();
 | 
					        EndPopup();
 | 
				
			||||||
@@ -10789,13 +10789,14 @@ void ImGui::ShowMetricsWindow(bool* p_open)
 | 
				
			|||||||
                    while (clipper.Step())
 | 
					                    while (clipper.Step())
 | 
				
			||||||
                        for (int prim = clipper.DisplayStart, vtx_i = elem_offset + clipper.DisplayStart*3; prim < clipper.DisplayEnd; prim++)
 | 
					                        for (int prim = clipper.DisplayStart, vtx_i = elem_offset + clipper.DisplayStart*3; prim < clipper.DisplayEnd; prim++)
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            char buf[300], *buf_p = buf;
 | 
					                            char buf[300];
 | 
				
			||||||
 | 
					                            char *buf_p = buf, *buf_end = buf + IM_ARRAYSIZE(buf);
 | 
				
			||||||
                            ImVec2 triangles_pos[3];
 | 
					                            ImVec2 triangles_pos[3];
 | 
				
			||||||
                            for (int n = 0; n < 3; n++, vtx_i++)
 | 
					                            for (int n = 0; n < 3; n++, vtx_i++)
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
                                ImDrawVert& v = draw_list->VtxBuffer[idx_buffer ? idx_buffer[vtx_i] : vtx_i];
 | 
					                                ImDrawVert& v = draw_list->VtxBuffer[idx_buffer ? idx_buffer[vtx_i] : vtx_i];
 | 
				
			||||||
                                triangles_pos[n] = v.pos;
 | 
					                                triangles_pos[n] = v.pos;
 | 
				
			||||||
                                buf_p += sprintf(buf_p, "%s %04d { pos = (%8.2f,%8.2f), uv = (%.6f,%.6f), col = %08X }\n", (n == 0) ? "vtx" : "   ", vtx_i, v.pos.x, v.pos.y, v.uv.x, v.uv.y, v.col);
 | 
					                                buf_p += ImFormatString(buf_p, (int)(buf_end - buf_p), "%s %04d { pos = (%8.2f,%8.2f), uv = (%.6f,%.6f), col = %08X }\n", (n == 0) ? "vtx" : "   ", vtx_i, v.pos.x, v.pos.y, v.uv.x, v.uv.y, v.col);
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                            ImGui::Selectable(buf, false);
 | 
					                            ImGui::Selectable(buf, false);
 | 
				
			||||||
                            if (ImGui::IsItemHovered())
 | 
					                            if (ImGui::IsItemHovered())
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user