iPlug2 - C++ Audio Plug-in Framework
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 
19 BEGIN_IPLUG_NAMESPACE
20 BEGIN_IGRAPHICS_NAMESPACE
21 
24 class IGraphicsWin final : public IGRAPHICS_DRAW_CLASS
25 {
26  class Font;
27  class InstalledFont;
28  struct HFontHolder;
29 public:
30  IGraphicsWin(IGEditorDelegate& dlg, int w, int h, int fps, float scale);
31  ~IGraphicsWin();
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* caption, EMsgBoxType type, IMsgBoxCompletionHanderFunc 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) override;
64  void PromptForDirectory(WDL_String& dir) 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);
71 
72  void* GetWindow() override { return mPlugWnd; }
73  HWND GetParentWindow() const { return mParentWnd; }
74  HWND GetMainWnd();
75  void SetMainWndClassName(const char* name) { mMainWndClassName.Set(name); }
76 // void GetMainWndClassName(char* name) { strcpy(name, mMainWndClassName.Get()); }
77  IRECT GetWindowRECT();
78  void SetWindowTitle(const char* str);
79 
80  const char* GetPlatformAPIStr() override { return "win32"; };
81 
82  bool GetTextFromClipboard(WDL_String& str) override;
83  bool SetTextInClipboard(const char* str) override;
84 
85  bool PlatformSupportsMultiTouch() const override;
86 
87 
88  static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
89  static LRESULT CALLBACK ParamEditProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
90  static BOOL CALLBACK FindMainWindow(HWND hWnd, LPARAM lParam);
91 
92  DWORD OnVBlankRun();
93 
94 protected:
95  IPopupMenu* CreatePlatformPopupMenu(IPopupMenu& menu, const IRECT& bounds, bool& isAsync) override;
96  void CreatePlatformTextEntry(int paramIdx, const IText& text, const IRECT& bounds, int length, const char* str) override;
97 
98  void SetTooltip(const char* tooltip);
99  void ShowTooltip();
100  void HideTooltip();
101 
102 private:
103 
106  void OnDisplayTimer(int vBlankCount = 0);
107 
108  enum EParamEditMsg
109  {
110  kNone,
111  kEditing,
112  kUpdate,
113  kCancel,
114  kCommit
115  };
116 
117  PlatformFontPtr LoadPlatformFont(const char* fontID, const char* fileNameOrResID) override;
118  PlatformFontPtr LoadPlatformFont(const char* fontID, const char* fontName, ETextStyle style) override;
119  PlatformFontPtr LoadPlatformFont(const char* fontID, void* pData, int dataSize) override;
120  void CachePlatformFont(const char* fontID, const PlatformFontPtr& font) override;
121 
122  inline IMouseInfo GetMouseInfo(LPARAM lParam, WPARAM wParam);
123  inline IMouseInfo GetMouseInfoDeltas(float& dX, float& dY, LPARAM lParam, WPARAM wParam);
124  bool MouseCursorIsLocked();
125 
126 #ifdef IGRAPHICS_GL
127  void CreateGLContext(); // OpenGL context management - TODO: RAII instead ?
128  void DestroyGLContext();
129  void ActivateGLContext() override;
130  void DeactivateGLContext() override;
131  HGLRC mHGLRC = nullptr;
132  HGLRC mStartHGLRC = nullptr;
133  HDC mStartHDC = nullptr;
134 #endif
135 
136  HINSTANCE mHInstance = nullptr;
137  HWND mPlugWnd = nullptr;
138  HWND mParamEditWnd = nullptr;
139  HWND mTooltipWnd = nullptr;
140  HWND mParentWnd = nullptr;
141  HWND mMainWnd = nullptr;
142  WNDPROC mDefEditProc = nullptr;
143  HFONT mEditFont = nullptr;
144  DWORD mPID = 0;
145 
146  void StartVBlankThread(HWND hWnd);
147  void StopVBlankThread();
148  void VBlankNotify();
149  HWND mVBlankWindow = 0; // Window to post messages to for every vsync
150  volatile bool mVBlankShutdown = false; // Flag to indiciate that the vsync thread should shutdown
151  HANDLE mVBlankThread = INVALID_HANDLE_VALUE; //ID of thread.
152  volatile DWORD mVBlankCount = 0; // running count of vblank events since the start of the window.
153  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.
154  bool mVSYNCEnabled = false;
155 
156  const IParam* mEditParam = nullptr;
157  IText mEditText;
158  IRECT mEditRECT;
159 
160  EParamEditMsg mParamEditMsg = kNone;
161  bool mShowingTooltip = false;
162  float mHiddenCursorX = 0.f;
163  float mHiddenCursorY = 0.f;
164  int mTooltipIdx = -1;
165 
166  WDL_String mMainWndClassName;
167 
168  static StaticStorage<InstalledFont> sPlatformFontCache;
169  static StaticStorage<HFontHolder> sHFontCache;
170 
171  std::unordered_map<ITouchID, IMouseInfo> mDeltaCapture; // associative array of touch id pointers to IMouseInfo structs, so that we can get deltas
172 };
173 
174 END_IGRAPHICS_NAMESPACE
175 END_IPLUG_NAMESPACE
176 
177 
Used to manage a rectangular area, independent of draw class/platform.
IGraphics platform class for Windows.
Definition: IGraphicsWin.h:24
Used for choosing a drawing backend.
IPlug&#39;s parameter class.
Used to manage color data, independent of draw class/platform.
An editor delegate base class for a SOMETHING that uses IGraphics for it&#39;s UI.
A class for setting the contents of a pop up menu.
IText is used to manage font and text/text entry style for a piece of text on the UI...
Used to group mouse coordinates with mouse modifier information.