20#include "IPlugWebView.h"
23BEGIN_IGRAPHICS_NAMESPACE
28using OnMessageFunc = std::function<void(
IWebViewControl* pControl,
const char* jsonMsg)>;
45 IWebViewControl(
const IRECT& bounds,
bool opaque, OnReadyFunc readyFunc =
nullptr, OnMessageFunc msgFunc =
nullptr,
bool enableDevTools =
false,
bool enableScroll =
false)
48 , mOnReadyFunc(readyFunc)
49 , mOnMessageFunc(msgFunc)
50 , mEnableDevTools(enableDevTools)
51 , mEnableScroll(enableScroll)
61 mPlatformView =
nullptr;
67 mPlatformView = OpenWebView(pGraphics->
GetWindow(), mRECT.L, mRECT.T, mRECT.
W(), mRECT.
H(), pGraphics->
GetDrawScale(), mEnableDevTools);
69 EnableScroll(mEnableScroll);
77 void OnWebViewReady()
override
83 void OnWebContentLoaded()
override
85 EnableInteraction(mEnableInteraction);
88 void OnMessageFromWebView(
const char* json)
override
91 mOnMessageFunc(
this, json);
96 UpdateWebViewBounds();
101 UpdateWebViewBounds();
108 mEnableInteraction = !ignore;
109 EnableInteraction(mEnableInteraction);
123 void UpdateWebViewBounds()
126 SetWebViewBounds(mRECT.L * ds, mRECT.T * ds, mRECT.
W() * ds, mRECT.
H() * ds, ds);
129 void* mPlatformView =
nullptr;
130 OnReadyFunc mOnReadyFunc;
131 OnMessageFunc mOnMessageFunc;
132 bool mEnableDevTools =
false;
133 bool mEnableInteraction =
true;
134 bool mEnableScroll =
false;
137END_IGRAPHICS_NAMESPACE
This file contains the base IControl implementation, along with some base classes for specific types ...
The lowest level base class of an IGraphics control.
virtual void Hide(bool hide)
Shows or hides the IControl.
The lowest level base class of an IGraphics context.
virtual void * GetWindow()=0
Get a pointer to the platform view e.g.
virtual void AttachPlatformView(const IRECT &r, void *pView)
Add an OS view as a sub-view, on top of the IGraphics view.
virtual void HidePlatformView(void *pView, bool hide)
Hide a previously attached platform view from the IGraphics view.
virtual void RemovePlatformView(void *pView)
Remove a previously attached platform view from the IGraphics view.
float GetDrawScale() const
Gets the graphics context scaling factor.
A control that allows the embedding of HTML UI inside an IGraphics context using a platform-native we...
void OnRescale() override
Implement to do something when graphics is scaled globally (e.g.
void OnResize() override
Called when IControl is constructed or resized using SetRect().
void SetIgnoreMouse(bool ignore) override
Specify whether the control should respond to mouse events.
void Hide(bool hide) override
Shows or hides the IControl.
void OnAttached() override
Called after the control has been attached, and its delegate and graphics member variable set.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
IWebViewControl(const IRECT &bounds, bool opaque, OnReadyFunc readyFunc=nullptr, OnMessageFunc msgFunc=nullptr, bool enableDevTools=false, bool enableScroll=false)
Constructs am IWebViewControl.
Used to manage a rectangular area, independent of draw class/platform.