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
19BEGIN_IPLUG_NAMESPACE
20BEGIN_IGRAPHICS_NAMESPACE
21
24class IGraphicsWin final : public IGRAPHICS_DRAW_CLASS
25{
26 class Font;
27 class InstalledFont;
28 struct HFontHolder;
29public:
30 IGraphicsWin(IGEditorDelegate& dlg, int w, int h, int fps, float scale);
32
33 void SetWinModuleHandle(void* pInstance) override { mHInstance = (HINSTANCE) pInstance; }
34 void* GetWinModuleHandle() override { return mHInstance; }
35
36 void ForceEndUserEdit() override;
37 float GetPlatformWindowScale() const override { return GetScreenScale(); }
38
39 void PlatformResize(bool parentHasResized) override;
40
41#ifdef IGRAPHICS_GL
42 void DrawResize() override; // overriden here to deal with GL graphics context capture
43#endif
44
45 void CheckTabletInput(UINT msg);
46 void DestroyEditWindow();
47
48 void HideMouseCursor(bool hide, bool lock) override;
49 void MoveMouseCursor(float x, float y) override;
50 ECursor SetMouseCursor(ECursor cursorType) override;
51
52 void GetMouseLocation(float& x, float&y) const override;
53
54 EMsgBoxResult ShowMessageBox(const char* str, const char* title, EMsgBoxType type, IMsgBoxCompletionHandlerFunc completionHandler) override;
55
56 void* OpenWindow(void* pParent) override;
57 void CloseWindow() override;
58 bool WindowIsOpen() override { return (mPlugWnd); }
59
60 void UpdateTooltips() override {}
61
62 bool RevealPathInExplorerOrFinder(WDL_String& path, bool select) override;
63 void PromptForFile(WDL_String& fileName, WDL_String& path, EFileAction action, const char* ext, IFileDialogCompletionHandlerFunc completionHandler) override;
64 void PromptForDirectory(WDL_String& dir, IFileDialogCompletionHandlerFunc completionHandler) override;
65 bool PromptForColor(IColor& color, const char* str, IColorPickerHandlerFunc func) override;
66
67 IPopupMenu* GetItemMenu(long idx, long& idxInMenu, long& offsetIdx, IPopupMenu& baseMenu);
68 HMENU CreateMenu(IPopupMenu& menu, long* pOffsetIdx);
69
70 bool OpenURL(const char* url, const char* msgWindowTitle, const char* confirmMsg, const char* errMsgOnFailure) override;
71
72 void* GetWindow() override { return mPlugWnd; }
73
74 const char* GetPlatformAPIStr() override { return "win32"; };
75
76 bool GetTextFromClipboard(WDL_String& str) override;
77 bool SetTextInClipboard(const char* str) override;
78 bool SetFilePathInClipboard(const char* path) override;
79
80 bool InitiateExternalFileDragDrop(const char* path, const IRECT& iconBounds) override;
81
82 bool PlatformSupportsMultiTouch() const override;
83
84 static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
85 static LRESULT CALLBACK ParamEditProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
86 static BOOL CALLBACK FindMainWindow(HWND hWnd, LPARAM lParam);
87
88 DWORD OnVBlankRun();
89
90protected:
91 IPopupMenu* CreatePlatformPopupMenu(IPopupMenu& menu, const IRECT bounds, bool& isAsync) override;
92 void CreatePlatformTextEntry(int paramIdx, const IText& text, const IRECT& bounds, int length, const char* str) override;
93
94 void SetTooltip(const char* tooltip);
95 void ShowTooltip();
96 void HideTooltip();
97
98 HWND GetMainWnd();
99 IRECT GetWindowRECT();
100
101private:
102
105 void OnDisplayTimer(int vBlankCount = 0);
106
107 enum EParamEditMsg
108 {
109 kNone,
110 kEditing,
111 kUpdate,
112 kCancel,
113 kCommit
114 };
115
116 PlatformFontPtr LoadPlatformFont(const char* fontID, const char* fileNameOrResID) override;
117 PlatformFontPtr LoadPlatformFont(const char* fontID, const char* fontName, ETextStyle style) override;
118 PlatformFontPtr LoadPlatformFont(const char* fontID, void* pData, int dataSize) override;
119 void CachePlatformFont(const char* fontID, const PlatformFontPtr& font) override;
120
121 inline IMouseInfo GetMouseInfo(LPARAM lParam, WPARAM wParam);
122 bool MouseCursorIsLocked();
123
124#ifdef IGRAPHICS_GL
125 void CreateGLContext(); // OpenGL context management - TODO: RAII instead ?
126 void DestroyGLContext();
127 void ActivateGLContext() override;
128 void DeactivateGLContext() override;
129 HGLRC mHGLRC = nullptr;
130 HGLRC mStartHGLRC = nullptr;
131 HDC mStartHDC = nullptr;
132#endif
133
134 HINSTANCE mHInstance = nullptr;
135 HWND mPlugWnd = nullptr;
136 HWND mParamEditWnd = nullptr;
137 HWND mTooltipWnd = nullptr;
138 HWND mParentWnd = nullptr;
139 HWND mMainWnd = nullptr;
140 WNDPROC mDefEditProc = nullptr;
141 HFONT mEditFont = nullptr;
142 DWORD mPID = 0;
143
144 void StartVBlankThread(HWND hWnd);
145 void StopVBlankThread();
146 void VBlankNotify();
147
148 HWND mVBlankWindow = 0; // Window to post messages to for every vsync
149 volatile bool mVBlankShutdown = false; // Flag to indiciate that the vsync thread should shutdown
150 HANDLE mVBlankThread = INVALID_HANDLE_VALUE; //ID of thread.
151 volatile DWORD mVBlankCount = 0; // running count of vblank events since the start of the window.
152 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.
153 bool mVSYNCEnabled = false;
154
155 const IParam* mEditParam = nullptr;
156 IText mEditText;
157 IRECT mEditRECT;
158
159 EParamEditMsg mParamEditMsg = kNone;
160 bool mShowingTooltip = false;
161 float mHiddenCursorX = 0.f;
162 float mHiddenCursorY = 0.f;
163 int mTooltipIdx = -1;
164
165 WDL_String mMainWndClassName;
166
167 static StaticStorage<InstalledFont> sPlatformFontCache;
168 static StaticStorage<HFontHolder> sHFontCache;
169
170 std::unordered_map<ITouchID, IMouseInfo> mDeltaCapture; // associative array of touch id pointers to IMouseInfo structs, so that we can get deltas
171};
172
173END_IGRAPHICS_NAMESPACE
174END_IPLUG_NAMESPACE
175
176
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:25
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,...