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
20#include "IPlugPlatform.h"
21
22#include "IGraphics_select.h"
23
24using namespace emscripten;
25
26BEGIN_IPLUG_NAMESPACE
27BEGIN_IGRAPHICS_NAMESPACE
28
29static val GetCanvas()
30{
31 return val::global("document").call<val>("getElementById", std::string("canvas"));
32}
33
34static val GetPreloadedImages()
35{
36 return val::global("Browser")["preloadedImages"];
37}
38
39extern void GetScreenDimensions(int& width, int& height);
40
43class IGraphicsWeb final : public IGRAPHICS_DRAW_CLASS
44{
45 class Font;
46 class FileFont;
47 class MemoryFont;
48public:
49 IGraphicsWeb(IGEditorDelegate& dlg, int w, int h, int fps, float scale);
51
52 void DrawResize() override;
53
54 const char* GetPlatformAPIStr() override { return "WEB"; }
55
56 void HideMouseCursor(bool hide, bool lock) override;
57 void MoveMouseCursor(float x, float y) override { /* NOT SUPPORTABLE*/ }
58 ECursor SetMouseCursor(ECursor cursorType) override;
59 void GetMouseLocation(float& x, float&y) const override;
60
61 void ForceEndUserEdit() override {} // TODO:
62 void* OpenWindow(void* pParent) override;
63 void CloseWindow() override {} // TODO:
64 void* GetWindow() override { return nullptr; } // TODO:
65 bool WindowIsOpen() override { return GetWindow(); } // TODO: ??
66 bool GetTextFromClipboard(WDL_String& str) override { str.Set(mClipboardText.Get()); return true; }
67 bool SetTextInClipboard(const char* str) override { mClipboardText.Set(str); return true; }
68 void UpdateTooltips() override {} // TODO:
69 EMsgBoxResult ShowMessageBox(const char* str, const char* title, EMsgBoxType type, IMsgBoxCompletionHandlerFunc completionHandler) override;
70
71 void PromptForFile(WDL_String& filename, WDL_String& path, EFileAction action, const char* ext, IFileDialogCompletionHandlerFunc completionHandler) override;
72 void PromptForDirectory(WDL_String& path, IFileDialogCompletionHandlerFunc completionHandler) override;
73 bool PromptForColor(IColor& color, const char* str, IColorPickerHandlerFunc func) override;
74 bool OpenURL(const char* url, const char* msgWindowTitle, const char* confirmMsg, const char* errMsgOnFailure) override;
75
76 bool PlatformSupportsMultiTouch() const override { return true; }
77
78 //IGraphicsWeb
79 static void OnMainLoopTimer();
80 double mPrevX = 0.;
81 double mPrevY = 0.;
82
83protected:
84 IPopupMenu* CreatePlatformPopupMenu(IPopupMenu& menu, const IRECT bounds, bool& isAsync) override;
85 void CreatePlatformTextEntry(int paramIdx, const IText& text, const IRECT& bounds, int length, const char* str) override;
86
87private:
88 PlatformFontPtr LoadPlatformFont(const char* fontID, const char* fileNameOrResID) override;
89 PlatformFontPtr LoadPlatformFont(const char* fontID, const char* fontName, ETextStyle style) override;
90 PlatformFontPtr LoadPlatformFont(const char* fontID, void* pData, int dataSize) override;
91 void CachePlatformFont(const char* fontID, const PlatformFontPtr& font) override {}
92
93 WDL_String mClipboardText;
94};
95
96END_IGRAPHICS_NAMESPACE
97END_IPLUG_NAMESPACE
98
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:44
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,...