1ReaperExtBase::ReaperExtBase(reaper_plugin_info_t* pRec)
2: EDITOR_DELEGATE_CLASS(0)
5 mTimer = std::unique_ptr<Timer>(Timer::Create(std::bind(&ReaperExtBase::OnTimer,
this, std::placeholders::_1), IDLE_TIMER_RATE));
8ReaperExtBase::~ReaperExtBase()
13void ReaperExtBase::OnTimer(
Timer& t)
18auto ClientResize = [](HWND hWnd,
int nWidth,
int nHeight) {
19 RECT rcClient, rcWindow;
21 int screenwidth, screenheight;
24 screenwidth = GetSystemMetrics(SM_CXSCREEN);
25 screenheight = GetSystemMetrics(SM_CYSCREEN);
26 x = (screenwidth / 2) - (nWidth / 2);
27 y = (screenheight / 2) - (nHeight / 2);
29 GetClientRect(hWnd, &rcClient);
30 GetWindowRect(hWnd, &rcWindow);
31 ptDiff.x = (rcWindow.right - rcWindow.left) - rcClient.right;
32 ptDiff.y = (rcWindow.bottom - rcWindow.top) - rcClient.bottom;
34 SetWindowPos(hWnd, 0, x, y, nWidth + ptDiff.x, nHeight + ptDiff.y, 0);
37bool ReaperExtBase::EditorResizeFromUI(
int viewWidth,
int viewHeight,
bool needsPlatformResize)
39 if (viewWidth != GetEditorWidth() || viewHeight != GetEditorHeight())
42#define TITLEBAR_BODGE 22
44 GetWindowRect(gHWND, &r);
45 SetWindowPos(gHWND, 0, r.left, r.bottom - viewHeight - TITLEBAR_BODGE, viewWidth, viewHeight + TITLEBAR_BODGE, 0);
58 gHWND = CreateDialog(gHINSTANCE, MAKEINTRESOURCE(IDD_DIALOG_MAIN), gParent, ReaperExtBase::MainDlgProc);
64void ReaperExtBase::ToggleDocking()
69 ShowWindow(gHWND, SW_HIDE);
70 DockWindowAdd(gHWND, (
char*)
"TEST", 0,
false);
71 DockWindowActivate(gHWND);
85 int commandID = mRec->Register(
"command_id", (
void*) actionName );
90 action.accel.accel.cmd = commandID;
91 action.accel.desc = actionName;
92 action.addMenuItem = addMenuItem;
93 action.pToggle = pToggle;
95 gActions.push_back(action);
97 mRec->Register(
"gaccel", (
void*) &gActions.back().accel);
101bool ReaperExtBase::HookCommandProc(
int command,
int flag)
103 std::vector<ReaperAction>::iterator it = std::find_if (gActions.begin(), gActions.end(), [&](
const auto& e) { return e.accel.accel.cmd == command; });
105 if(it != gActions.end())
114int ReaperExtBase::ToggleActionCallback(
int command)
116 std::vector<ReaperAction>::iterator it = std::find_if (gActions.begin(), gActions.end(), [&](
const auto& e) { return e.accel.accel.cmd == command; });
118 if(it != gActions.end())
120 if(it->pToggle ==
nullptr)
130WDL_DLGRET ReaperExtBase::MainDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
142 extern float GetScaleForHWND(HWND hWnd);
148 AttachWindowTopmostButton(hwnd);
149 gPlug->OpenWindow(hwnd);
150 auto scale = GetScaleForHWND(hwnd);
151 ClientResize(hwnd, PLUG_WIDTH * scale, PLUG_HEIGHT * scale);
152 ShowWindow(hwnd, SW_SHOW);
153 GetWindowRect(hwnd, &gPrevBounds);
161 gPlug->CloseWindow();
void ShowHideMainWindow()
void RegisterAction(const char *actionName, std::function< void()> func, bool addMenuItem=false, int *pToggle=nullptr)
Helper struct for registering Reaper Actions.