iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
IGraphicsWin.h
1/*
2 ==============================================================================
3
4 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5
6 See LICENSE.txt for more info.
7
8 ==============================================================================
9*/
10
11#pragma once
12
13#include <windows.h>
14#include <windowsx.h>
15#include <winuser.h>
16
17#include "IGraphics_select.h"
18#include "IGraphicsWinFonts.h"
19
20BEGIN_IPLUG_NAMESPACE
21BEGIN_IGRAPHICS_NAMESPACE
22
25class IGraphicsWin final : public IGRAPHICS_DRAW_CLASS
26{
28 using Font = WinFont;
29
30public:
31 IGraphicsWin(IGEditorDelegate& dlg, int w, int h, int fps, float scale);
33
34 void SetWinModuleHandle(void* pInstance) override { mHInstance = (HINSTANCE) pInstance; }
35 void* GetWinModuleHandle() override { return mHInstance; }
36
37 void ForceEndUserEdit() override;
38 float GetPlatformWindowScale() const override { return GetScreenScale(); }
39
40 void PlatformResize(bool parentHasResized) override;
41
42 void CheckTabletInput(UINT msg);
43 void DestroyEditWindow();
44
45 void HideMouseCursor(bool hide, bool lock) override;
46 void MoveMouseCursor(float x, float y) override;
47 ECursor SetMouseCursor(ECursor cursorType) override;
48
49 void GetMouseLocation(float& x, float&y) const override;
50
51 EMsgBoxResult ShowMessageBox(const char* str, const char* title, EMsgBoxType type, IMsgBoxCompletionHandlerFunc completionHandler) override;
52
53 void* OpenWindow(void* pParent) override;
54 void CloseWindow() override;
55 bool WindowIsOpen() override { return (mPlugWnd); }
56
57 void UpdateTooltips() override {}
58
59 bool RevealPathInExplorerOrFinder(WDL_String& path, bool select) override;
60 void PromptForFile(WDL_String& fileName, WDL_String& path, EFileAction action, const char* ext, IFileDialogCompletionHandlerFunc completionHandler) override;
61 void PromptForDirectory(WDL_String& dir, IFileDialogCompletionHandlerFunc completionHandler) override;
62 bool PromptForColor(IColor& color, const char* str, IColorPickerHandlerFunc func) override;
63
64 IPopupMenu* GetItemMenu(long idx, long& idxInMenu, long& offsetIdx, IPopupMenu& baseMenu);
65 HMENU CreateMenu(IPopupMenu& menu, long* pOffsetIdx);
66
67 bool OpenURL(const char* url, const char* msgWindowTitle, const char* confirmMsg, const char* errMsgOnFailure) override;
68
69 void* GetWindow() override { return mPlugWnd; }
70
71 const char* GetPlatformAPIStr() override { return "win32"; };
72
73 bool GetTextFromClipboard(WDL_String& str) override;
74 bool SetTextInClipboard(const char* str) override;
75 bool SetFilePathInClipboard(const char* path) override;
76
77 bool InitiateExternalFileDragDrop(const char* path, const IRECT& iconBounds) override;
78
79 bool PlatformSupportsMultiTouch() const override;
80
81 static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
82 static LRESULT CALLBACK ParamEditProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
83 static BOOL CALLBACK FindMainWindow(HWND hWnd, LPARAM lParam);
84
85 DWORD OnVBlankRun();
86
87protected:
88 IPopupMenu* CreatePlatformPopupMenu(IPopupMenu& menu, const IRECT bounds, bool& isAsync) override;
89 void CreatePlatformTextEntry(int paramIdx, const IText& text, const IRECT& bounds, int length, const char* str) override;
90
91 void SetTooltip(const char* tooltip);
92 void ShowTooltip();
93 void HideTooltip();
94
95 HWND GetMainWnd();
96 IRECT GetWindowRECT();
97
98private:
99
102 void OnDisplayTimer(int vBlankCount = 0);
103
104 enum EParamEditMsg
105 {
106 kNone,
107 kEditing,
108 kUpdate,
109 kCancel,
110 kCommit
111 };
112
113 PlatformFontPtr LoadPlatformFont(const char* fontID, const char* fileNameOrResID) override;
114 PlatformFontPtr LoadPlatformFont(const char* fontID, const char* fontName, ETextStyle style) override;
115 PlatformFontPtr LoadPlatformFont(const char* fontID, void* pData, int dataSize) override;
116 void CachePlatformFont(const char* fontID, const PlatformFontPtr& font) override;
117
118 inline IMouseInfo GetMouseInfo(LPARAM lParam, WPARAM wParam);
119 bool MouseCursorIsLocked();
120
121 void ActivateGLContext() override;
122 void DeactivateGLContext() override;
123
124#ifdef IGRAPHICS_GL
125 void CreateGLContext(); // OpenGL context management - TODO: RAII instead ?
126 void DestroyGLContext();
127 HGLRC mHGLRC = nullptr;
128 HGLRC mStartHGLRC = nullptr;
129 HDC mStartHDC = nullptr;
130#endif
131
132 HINSTANCE mHInstance = nullptr;
133 HWND mPlugWnd = nullptr;
134 HWND mParamEditWnd = nullptr;
135 HWND mTooltipWnd = nullptr;
136 HWND mParentWnd = nullptr;
137 HWND mMainWnd = nullptr;
138 WNDPROC mDefEditProc = nullptr;
139 HFONT mEditFont = nullptr;
140 DWORD mPID = 0;
141
142 void StartVBlankThread(HWND hWnd);
143 void StopVBlankThread();
144 void VBlankNotify();
145
146 HWND mVBlankWindow = 0; // Window to post messages to for every vsync
147 volatile bool mVBlankShutdown = false; // Flag to indiciate that the vsync thread should shutdown
148 HANDLE mVBlankThread = INVALID_HANDLE_VALUE; //ID of thread.
149 volatile DWORD mVBlankCount = 0; // running count of vblank events since the start of the window.
150 int mVBlankSkipUntil = 0; // support for skipping vblank notification if the last callback took too long. This helps keep the message pump clear in the case of overload.
151 bool mVSYNCEnabled = false;
152
153 const IParam* mEditParam = nullptr;
154 IText mEditText;
155 IRECT mEditRECT;
156
157 EParamEditMsg mParamEditMsg = kNone;
158 bool mShowingTooltip = false;
159 float mHiddenCursorX = 0.f;
160 float mHiddenCursorY = 0.f;
161 int mTooltipIdx = -1;
162
163 WDL_String mMainWndClassName;
164
165 static StaticStorage<InstalledFont> sPlatformFontCache;
166 static StaticStorage<HFontHolder> sHFontCache;
167
168 std::unordered_map<ITouchID, IMouseInfo> mDeltaCapture; // associative array of touch id pointers to IMouseInfo structs, so that we can get deltas
169};
170
171END_IGRAPHICS_NAMESPACE
172END_IPLUG_NAMESPACE
173
174
Used for choosing a drawing backend.
An editor delegate base class that uses IGraphics for the UI.
IGraphics platform class for Windows.
Definition: IGraphicsWin.h:26
IPlug's parameter class.
A class for setting the contents of a pop up menu.
Used to group mouse coordinates with mouse modifier information.
Used to manage color data, independent of draw class/platform.
Used to manage a rectangular area, independent of draw class/platform.
IText is used to manage font and text/text entry style for a piece of text on the UI,...