Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Thread Tools Display Modes
Old 08-09-2018, 03:13 AM   #1
Human being with feelings
Join Date: Jul 2009
Posts: 2,752
Default SWELL/GDI and LICE: Is it possible to draw inside REAPER's window without flickering?

I am currently experimenting with using GDI to draw basic stuff such as lines and text inside REAPER's windows.

The script is deferred, and it updates the graphics in each cycle.

Everything seems to work fine, except that the GDI-drawn graphics flicker. This is not unexpected, since REAPER and the script update their stuff separately.

Is there a way to avoid this flickering? In each defer cycle, I somehow need to block the window from rendering until the script has added its GDI graphics.

I have tried blocking WM_PAINT messages, and this does indeed stop the window from updating, but then I can't get it to paint again by calling InvalidateRect/UpdateWindow after adding the script graphics, or by sending WM_PAINT myself (and the Win32 documentation warns against sending WM_PAINT messages).
juliansader is offline   Reply With Quote
Old 04-11-2019, 10:00 AM   #2
Human being with feelings
Join Date: Jul 2009
Posts: 2,752

cfillion suggested this approach:

Originally Posted by cfillion View Post
An extension can draw after REAPER (except in some cases where it appears to be repainting directly, eg. the playback cursor) by intercepting the WM_PAINT window message.

(Red=WM_PAINT, Green=js_ReaScript API redrawing at reaper.defer's 30Hz)

... and it works perfectly on Linux and macOS!

Unfortunately, on WindowsOS, it still glitches. I therefore tried to get REAPER to draw into an offscreen memory bitmap instead of the screen, so that this bitmap and the script's LICE bitmap can be composited before blitting to the screen. WM_PAINT can optionally point to a memory bitmap in its WPARAM parameter, but code such as this didn't work, so I suspect that REAPER's windows ignore the WPARAM pointer:
RECT r{0,0,0,0};
GetClientRect(hwnd, &r);
HDC clientDC = GetDC(hwnd);
HDC memDC = CreateCompatibleDC(clientDC);
HBITMAP memBitmap = CreateCompatibleBitmap(clientDC, r.right, r.bottom);
SelectObject(memDC, memBitmap);

LRESULT result = SendMessage(hwnd, WM_PAINT, (WPARAM)memDC, lParam);

AlphaBlend LICE into memDC;

BitBlt(clientDC, 0, 0, r.right, r.bottom, memDC, 0, 0, SRCCOPY);

DeleteObject( memBitmap );
DeleteDC( memDC );
Changing WM_PAINT into WM_PRINT or WM_PRINTCLIENT didn't work either (or at least, not with the options that I tried).

Last edited by juliansader; 04-11-2019 at 10:41 AM.
juliansader is offline   Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -7. The time now is 02:49 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.