Skip to content

Instantly share code, notes, and snippets.

@Xenakios
Created December 21, 2018 15:59
Show Gist options
  • Save Xenakios/7d18c08fa5bc0f7bb13e77a4a20cee40 to your computer and use it in GitHub Desktop.
Save Xenakios/7d18c08fa5bc0f7bb13e77a4a20cee40 to your computer and use it in GitHub Desktop.
#define REAPERAPI_NO_LICE
#define REAPERAPI_IMPLEMENT
#include "lice.h"
#include "reaper_plugin_functions.h"
#include <memory>
#include <map>
struct MyDLGTEMPLATE : DLGTEMPLATE
{
WORD ext[3];
MyDLGTEMPLATE()
{
memset(this, 0, sizeof(*this));
}
};
HINSTANCE g_hinst;
HWND g_mainwdn;
class LiceWindow;
std::map<HWND, LiceWindow*> g_windowmap;
class LiceWindow
{
public:
LiceWindow(int x,int y,int w,int h)
{
m_bitmap = std::make_unique<LICE_SysBitmap>(w, h);
MyDLGTEMPLATE t;
t.style = WS_DLGFRAME|WS_CAPTION;
t.cx = w;
t.cy = h;
t.x = x;
t.y = y;
m_x = x;
m_y = y;
m_w = w;
m_h = h;
m_hwnd = CreateDialogIndirectParam(g_hinst, &t, g_mainwdn, (DLGPROC)EditorProc, (LPARAM)this);
if (m_hwnd)
{
g_windowmap[m_hwnd] = this;
ShowWindow(m_hwnd, SW_SHOW);
}
}
virtual ~LiceWindow()
{
if (m_hwnd)
{
DestroyWindow(m_hwnd);
g_windowmap.erase(m_hwnd);
}
}
virtual void draw(LICE_IBitmap* bm) = 0;
private:
HWND m_hwnd = 0;
std::unique_ptr<LICE_SysBitmap> m_bitmap;
int m_x, m_y, m_w, m_h = 0;
static INT_PTR CALLBACK EditorProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if (msg == WM_INITDIALOG)
{
return 0;
}
else if (msg == WM_CLOSE)
{
EndDialog(hwnd, IDOK);
return 0;
}
else if (msg == WM_PAINT)
{
LiceWindow* lwnd = g_windowmap[hwnd];
if (lwnd)
{
lwnd->draw(lwnd->m_bitmap.get());
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
BitBlt(hdc, 0,
0,
lwnd->m_bitmap->getWidth(),
lwnd->m_bitmap->getHeight(),
lwnd->m_bitmap->getDC(), 0, 0, SRCCOPY);
EndPaint(hwnd, &ps);
}
}
return 0;
}
};
class TestWindow : public LiceWindow
{
public:
TestWindow(int x, int y, int w, int h) : LiceWindow(x, y, w, h)
{}
void draw(LICE_IBitmap* bm) override
{
LICE_FillRect(bm, 0, 0, bm->getWidth(), bm->getHeight(), LICE_RGBA(0, 0, 0, 255));
LICE_Line(bm, 0, 0, 100, 100, LICE_RGBA(255, 255, 255, 255));
LICE_Line(bm, 0, 100, 100, 0, LICE_RGBA(0, 255, 0, 255));
}
};
extern "C"
{
REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT(REAPER_PLUGIN_HINSTANCE hInstance, reaper_plugin_info_t *rec) {
if (rec != nullptr)
{
if (REAPERAPI_LoadAPI(rec->GetFunc) > 0) return 0;
g_mainwdn = rec->hwnd_main;
g_hinst = hInstance;
TestWindow* wind = new TestWindow(10, 50, 100, 100);
return 1;
}
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment