iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
IGraphicsWeb.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 <emscripten.h>
14#include <emscripten/val.h>
15#include <emscripten/bind.h>
16#include <emscripten/html5.h>
17
18#include <utility>
19#include <string>
20
21#include "IPlugPlatform.h"
22
23#include "IGraphics_select.h"
24
25using namespace emscripten;
26
27BEGIN_IPLUG_NAMESPACE
28BEGIN_IGRAPHICS_NAMESPACE
29
30static val GetPreloadedImages()
31{
32 return val::global("Browser")["preloadedImages"];
33}
34
35extern void GetScreenDimensions(int& width, int& height);
36
39class IGraphicsWeb final : public IGRAPHICS_DRAW_CLASS
40{
41 class Font;
42 class FileFont;
43 class MemoryFont;
44public:
52 IGraphicsWeb(IGEditorDelegate& dlg, int w, int h, int fps, float scale, val canvas = val::undefined());
54
56 val GetCanvas() const { return mCanvas; }
57
59 bool IsInShadowDOM() const { return mInShadowDOM; }
60
61 void DrawResize() override;
62
63 const char* GetPlatformAPIStr() override { return "WEB"; }
64
65 void HideMouseCursor(bool hide, bool lock) override;
66 void MoveMouseCursor(float x, float y) override { /* NOT SUPPORTABLE*/ }
67 ECursor SetMouseCursor(ECursor cursorType) override;
68 void GetMouseLocation(float& x, float&y) const override;
69
70 void ForceEndUserEdit() override {} // TODO:
71 void* OpenWindow(void* pParent) override;
72 void CloseWindow() override {} // TODO:
73 void* GetWindow() override { return nullptr; } // TODO:
74 bool WindowIsOpen() override { return GetWindow(); } // TODO: ??
75 bool GetTextFromClipboard(WDL_String& str) override { str.Set(mClipboardText.Get()); return true; }
76 bool SetTextInClipboard(const char* str) override { mClipboardText.Set(str); return true; }
77 void UpdateTooltips() override {} // TODO:
78 EMsgBoxResult ShowMessageBox(const char* str, const char* title, EMsgBoxType type, IMsgBoxCompletionHandlerFunc completionHandler) override;
79
80 void PromptForFile(WDL_String& filename, WDL_String& path, EFileAction action, const char* ext, IFileDialogCompletionHandlerFunc completionHandler) override;
81 void PromptForDirectory(WDL_String& path, IFileDialogCompletionHandlerFunc completionHandler) override;
82 bool PromptForColor(IColor& color, const char* str, IColorPickerHandlerFunc func) override;
83 bool OpenURL(const char* url, const char* msgWindowTitle, const char* confirmMsg, const char* errMsgOnFailure) override;
84
85 bool PlatformSupportsMultiTouch() const override { return true; }
86
87 //IGraphicsWeb
88 static void OnMainLoopTimer();
89 double mPrevX = 0.;
90 double mPrevY = 0.;
91
92protected:
93 IPopupMenu* CreatePlatformPopupMenu(IPopupMenu& menu, const IRECT bounds, bool& isAsync) override;
94 void CreatePlatformTextEntry(int paramIdx, const IText& text, const IRECT& bounds, int length, const char* str) override;
95
96private:
97 void RegisterCanvasEvents();
98 void UnregisterCanvasEvents();
99
100 PlatformFontPtr LoadPlatformFont(const char* fontID, const char* fileNameOrResID) override;
101 PlatformFontPtr LoadPlatformFont(const char* fontID, const char* fontName, ETextStyle style) override;
102 PlatformFontPtr LoadPlatformFont(const char* fontID, void* pData, int dataSize) override;
103 void CachePlatformFont(const char* fontID, const PlatformFontPtr& font) override {}
104
105 WDL_String mClipboardText;
106 val mCanvas = val::undefined(); // Canvas element reference
107 val mRootNode = val::undefined(); // Document or ShadowRoot containing the canvas
108 bool mInShadowDOM = false; // True if canvas is inside a Shadow DOM
109 std::string mCanvasSelector; // Unique CSS selector for this instance's canvas
110};
111
112END_IGRAPHICS_NAMESPACE
113END_IPLUG_NAMESPACE
114
Used for choosing a drawing backend.
Include to get consistently named preprocessor macros for different platforms and logging functionali...
An editor delegate base class that uses IGraphics for the UI.
IGraphics platform class for the web.
Definition: IGraphicsWeb.h:40
bool IsInShadowDOM() const
Check if this instance is running inside Shadow DOM.
Definition: IGraphicsWeb.h:59
val GetCanvas() const
Get the canvas element for this instance.
Definition: IGraphicsWeb.h:56
A class for setting the contents of a pop up menu.
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,...