mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-11-03 22:51:06 +01:00 
			
		
		
		
	Calculate frame-rate for the user, as a purely luxurious feature
..and to reduce sample code size a little.
This commit is contained in:
		@@ -568,17 +568,7 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int)
 | 
				
			|||||||
            ImGui::ColorEdit3("clear color", (float*)&clear_col);
 | 
					            ImGui::ColorEdit3("clear color", (float*)&clear_col);
 | 
				
			||||||
            if (ImGui::Button("Test Window")) show_test_window ^= 1;
 | 
					            if (ImGui::Button("Test Window")) show_test_window ^= 1;
 | 
				
			||||||
            if (ImGui::Button("Another Window")) show_another_window ^= 1;
 | 
					            if (ImGui::Button("Another Window")) show_another_window ^= 1;
 | 
				
			||||||
 | 
					            ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
 | 
				
			||||||
            // Calculate and show frame rate
 | 
					 | 
				
			||||||
            static int   ms_per_frame_idx = 0;
 | 
					 | 
				
			||||||
            static float ms_per_frame[60] = { 0 };
 | 
					 | 
				
			||||||
            static float ms_per_frame_accum = 0.0f;
 | 
					 | 
				
			||||||
            ms_per_frame_accum -= ms_per_frame[ms_per_frame_idx];
 | 
					 | 
				
			||||||
            ms_per_frame[ms_per_frame_idx] = ImGui::GetIO().DeltaTime * 1000.0f;
 | 
					 | 
				
			||||||
            ms_per_frame_accum += ms_per_frame[ms_per_frame_idx];
 | 
					 | 
				
			||||||
            ms_per_frame_idx = (ms_per_frame_idx + 1) % 60;
 | 
					 | 
				
			||||||
            const float ms_per_frame_avg = ms_per_frame_accum / 60;
 | 
					 | 
				
			||||||
            ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", ms_per_frame_avg, 1000.0f / ms_per_frame_avg);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // 2. Show another simple window, this time using an explicit Begin/End pair
 | 
					        // 2. Show another simple window, this time using an explicit Begin/End pair
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -334,17 +334,7 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int)
 | 
				
			|||||||
            ImGui::ColorEdit3("clear color", (float*)&clear_col);
 | 
					            ImGui::ColorEdit3("clear color", (float*)&clear_col);
 | 
				
			||||||
            if (ImGui::Button("Test Window")) show_test_window ^= 1;
 | 
					            if (ImGui::Button("Test Window")) show_test_window ^= 1;
 | 
				
			||||||
            if (ImGui::Button("Another Window")) show_another_window ^= 1;
 | 
					            if (ImGui::Button("Another Window")) show_another_window ^= 1;
 | 
				
			||||||
 | 
					            ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
 | 
				
			||||||
            // Calculate and show frame rate
 | 
					 | 
				
			||||||
            static int   ms_per_frame_idx = 0;
 | 
					 | 
				
			||||||
            static float ms_per_frame[60] = { 0 };
 | 
					 | 
				
			||||||
            static float ms_per_frame_accum = 0.0f;
 | 
					 | 
				
			||||||
            ms_per_frame_accum -= ms_per_frame[ms_per_frame_idx];
 | 
					 | 
				
			||||||
            ms_per_frame[ms_per_frame_idx] = ImGui::GetIO().DeltaTime * 1000.0f;
 | 
					 | 
				
			||||||
            ms_per_frame_accum += ms_per_frame[ms_per_frame_idx];
 | 
					 | 
				
			||||||
            ms_per_frame_idx = (ms_per_frame_idx + 1) % 60;
 | 
					 | 
				
			||||||
            const float ms_per_frame_avg = ms_per_frame_accum / 60;
 | 
					 | 
				
			||||||
            ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", ms_per_frame_avg, 1000.0f / ms_per_frame_avg);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // 2. Show another simple window, this time using an explicit Begin/End pair
 | 
					        // 2. Show another simple window, this time using an explicit Begin/End pair
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -346,17 +346,7 @@ int main(int argc, char** argv)
 | 
				
			|||||||
            ImGui::ColorEdit3("clear color", (float*)&clear_col);
 | 
					            ImGui::ColorEdit3("clear color", (float*)&clear_col);
 | 
				
			||||||
            if (ImGui::Button("Test Window")) show_test_window ^= 1;
 | 
					            if (ImGui::Button("Test Window")) show_test_window ^= 1;
 | 
				
			||||||
            if (ImGui::Button("Another Window")) show_another_window ^= 1;
 | 
					            if (ImGui::Button("Another Window")) show_another_window ^= 1;
 | 
				
			||||||
 | 
					            ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
 | 
				
			||||||
            // Calculate and show frame rate
 | 
					 | 
				
			||||||
            static int   ms_per_frame_idx = 0;
 | 
					 | 
				
			||||||
            static float ms_per_frame[60] = { 0 };
 | 
					 | 
				
			||||||
            static float ms_per_frame_accum = 0.0f;
 | 
					 | 
				
			||||||
            ms_per_frame_accum -= ms_per_frame[ms_per_frame_idx];
 | 
					 | 
				
			||||||
            ms_per_frame[ms_per_frame_idx] = ImGui::GetIO().DeltaTime * 1000.0f;
 | 
					 | 
				
			||||||
            ms_per_frame_accum += ms_per_frame[ms_per_frame_idx];
 | 
					 | 
				
			||||||
            ms_per_frame_idx = (ms_per_frame_idx + 1) % 60;
 | 
					 | 
				
			||||||
            const float ms_per_frame_avg = ms_per_frame_accum / 60;
 | 
					 | 
				
			||||||
            ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", ms_per_frame_avg, 1000.0f / ms_per_frame_avg);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // 2. Show another simple window, this time using an explicit Begin/End pair
 | 
					        // 2. Show another simple window, this time using an explicit Begin/End pair
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -255,17 +255,7 @@ int main(int argc, char** argv)
 | 
				
			|||||||
            ImGui::ColorEdit3("clear color", (float*)&clear_col);
 | 
					            ImGui::ColorEdit3("clear color", (float*)&clear_col);
 | 
				
			||||||
            if (ImGui::Button("Test Window")) show_test_window ^= 1;
 | 
					            if (ImGui::Button("Test Window")) show_test_window ^= 1;
 | 
				
			||||||
            if (ImGui::Button("Another Window")) show_another_window ^= 1;
 | 
					            if (ImGui::Button("Another Window")) show_another_window ^= 1;
 | 
				
			||||||
 | 
					            ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
 | 
				
			||||||
            // Calculate and show frame rate
 | 
					 | 
				
			||||||
            static int   ms_per_frame_idx = 0;
 | 
					 | 
				
			||||||
            static float ms_per_frame[60] = { 0 };
 | 
					 | 
				
			||||||
            static float ms_per_frame_accum = 0.0f;
 | 
					 | 
				
			||||||
            ms_per_frame_accum -= ms_per_frame[ms_per_frame_idx];
 | 
					 | 
				
			||||||
            ms_per_frame[ms_per_frame_idx] = ImGui::GetIO().DeltaTime * 1000.0f;
 | 
					 | 
				
			||||||
            ms_per_frame_accum += ms_per_frame[ms_per_frame_idx];
 | 
					 | 
				
			||||||
            ms_per_frame_idx = (ms_per_frame_idx + 1) % 60;
 | 
					 | 
				
			||||||
            const float ms_per_frame_avg = ms_per_frame_accum / 60;
 | 
					 | 
				
			||||||
            ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", ms_per_frame_avg, 1000.0f / ms_per_frame_avg);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // 2. Show another simple window, this time using an explicit Begin/End pair
 | 
					        // 2. Show another simple window, this time using an explicit Begin/End pair
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										11
									
								
								imgui.cpp
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								imgui.cpp
									
									
									
									
									
								
							@@ -1022,6 +1022,11 @@ struct ImGuiState
 | 
				
			|||||||
    int                     LogStartDepth;
 | 
					    int                     LogStartDepth;
 | 
				
			||||||
    int                     LogAutoExpandMaxDepth;
 | 
					    int                     LogAutoExpandMaxDepth;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Misc
 | 
				
			||||||
 | 
					    float                   FramerateSecPerFrame[120];          // calculate estimate of framerate for user
 | 
				
			||||||
 | 
					    int                     FramerateSecPerFrameIdx;
 | 
				
			||||||
 | 
					    float                   FramerateSecPerFrameAccum;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ImGuiState()
 | 
					    ImGuiState()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        Initialized = false;
 | 
					        Initialized = false;
 | 
				
			||||||
@@ -1719,6 +1724,12 @@ void ImGui::NewFrame()
 | 
				
			|||||||
    for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++)
 | 
					    for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++)
 | 
				
			||||||
        g.IO.KeysDownTime[i] = g.IO.KeysDown[i] ? (g.IO.KeysDownTime[i] < 0.0f ? 0.0f : g.IO.KeysDownTime[i] + g.IO.DeltaTime) : -1.0f;
 | 
					        g.IO.KeysDownTime[i] = g.IO.KeysDown[i] ? (g.IO.KeysDownTime[i] < 0.0f ? 0.0f : g.IO.KeysDownTime[i] + g.IO.DeltaTime) : -1.0f;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Calculate frame-rate for the user, as a purely luxurious feature
 | 
				
			||||||
 | 
					    g.FramerateSecPerFrameAccum += g.IO.DeltaTime - g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx];
 | 
				
			||||||
 | 
					    g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx] = g.IO.DeltaTime;
 | 
				
			||||||
 | 
					    g.FramerateSecPerFrameIdx = (g.FramerateSecPerFrameIdx + 1) % IM_ARRAYSIZE(g.FramerateSecPerFrame);
 | 
				
			||||||
 | 
					    g.IO.Framerate = 1.0f / (g.FramerateSecPerFrameAccum / (float)IM_ARRAYSIZE(g.FramerateSecPerFrame));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Clear reference to active widget if the widget isn't alive anymore
 | 
					    // Clear reference to active widget if the widget isn't alive anymore
 | 
				
			||||||
    g.HoveredId = 0;
 | 
					    g.HoveredId = 0;
 | 
				
			||||||
    if (!g.ActiveIdIsAlive && g.ActiveIdPreviousFrame == g.ActiveId && g.ActiveId != 0)
 | 
					    if (!g.ActiveIdIsAlive && g.ActiveIdPreviousFrame == g.ActiveId && g.ActiveId != 0)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										1
									
								
								imgui.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								imgui.h
									
									
									
									
									
								
							@@ -589,6 +589,7 @@ struct ImGuiIO
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    bool        WantCaptureMouse;           // Mouse is hovering a window or widget is active (= ImGui will use your mouse input)
 | 
					    bool        WantCaptureMouse;           // Mouse is hovering a window or widget is active (= ImGui will use your mouse input)
 | 
				
			||||||
    bool        WantCaptureKeyboard;        // Widget is active (= ImGui will use your keyboard input)
 | 
					    bool        WantCaptureKeyboard;        // Widget is active (= ImGui will use your keyboard input)
 | 
				
			||||||
 | 
					    float       Framerate;                  // Framerate estimation, in frame per second. Rolling average estimation based on IO.DeltaTime over 120 frames
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //------------------------------------------------------------------
 | 
					    //------------------------------------------------------------------
 | 
				
			||||||
    // [Internal] ImGui will maintain those fields for you
 | 
					    // [Internal] ImGui will maintain those fields for you
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user