Skip to content

Commit d7647df

Browse files
do not flash white when resizing/moving window
1 parent 193db93 commit d7647df

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

SynesthesiaDev.Chibi.Core/ChibiWindow.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public void Run(int width, int height, WindowFlags flags)
217217
lpfnWndProc = wndProcDelegate,
218218
hInstance = hInstance,
219219
hCursor = LoadCursor(HINSTANCE.NULL, IDC_ARROW),
220-
hbrBackground = GetStockObject(StockObjectType.WHITE_BRUSH),
220+
// hbrBackground = GetStockObject(StockObjectType.WHITE_BRUSH),
221221
lpszClassName = class_name
222222
};
223223

@@ -367,6 +367,9 @@ private IntPtr customWndProc(HWND eventHwnd, uint msg, IntPtr wParam, IntPtr lPa
367367

368368
switch (windowMessage)
369369
{
370+
case WindowMessage.WM_ERASEBKGND:
371+
return 1;
372+
370373
case WindowMessage.WM_DESTROY:
371374
PostQuitMessage();
372375

@@ -419,7 +422,9 @@ private IntPtr customWndProc(HWND eventHwnd, uint msg, IntPtr wParam, IntPtr lPa
419422
WindowSize = size;
420423

421424
OnWindowResized.DispatchEvent(resizeEvent, OnEvent);
422-
break;
425+
OnFrame?.Invoke();
426+
427+
return IntPtr.Zero;
423428

424429
case WindowMessage.WM_CLOSE:
425430
var exitRequestedEvent = Pooled.WINDOW_EXIT_REQUESTED_EVENT.Rent();
@@ -502,7 +507,9 @@ private IntPtr customWndProc(HWND eventHwnd, uint msg, IntPtr wParam, IntPtr lPa
502507
WindowPosition = windowPos;
503508

504509
OnWindowMoved.DispatchEvent(moveEvent, OnEvent);
505-
break;
510+
OnFrame?.Invoke();
511+
512+
return IntPtr.Zero;
506513

507514
case WindowMessage.WM_ACTIVATE:
508515
var active = (WM_ACTIVATE_WPARAM)Macros.LOWORD(wParam);

SynesthesiaDev.Chibi.Example/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ private static void Main()
116116

117117
private static void OnFrame()
118118
{
119+
if(!window.IsWindowInitialized) return;
120+
119121
var now = Stopwatch.GetTimestamp();
120122
var dt = (float)(now - lastFrame) / Stopwatch.Frequency;
121123
lastFrame = now;

0 commit comments

Comments
 (0)