1.14.0.5
Coherent HB for UE4
A modern user interface library for games
HummingbirdBaseComponent.h
1 /*
2 This file is part of Hummingbird, modern user interface library for
3 games. Release $RELEASE$. Build $VERSION$ for $LICENSEE$.
4 
5 Copyright (c) 2012-2018 Coherent Labs AD and/or its licensors. All
6 rights reserved in all media.
7 
8 The coded instructions, statements, computer programs, and/or related
9 material (collectively the "Data") in these files contain confidential
10 and unpublished information proprietary Coherent Labs and/or its
11 licensors, which is protected by United States of America federal
12 copyright law and by international treaties.
13 
14 This software or source code is supplied under the terms of a license
15 agreement and nondisclosure agreement with Coherent Labs Limited and may
16 not be copied, disclosed, or exploited except in accordance with the
17 terms of that agreement. The Data may not be disclosed or distributed to
18 third parties, in whole or in part, without the prior written consent of
19 Coherent Labs Limited.
20 
21 COHERENT LABS MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS
22 SOURCE CODE FOR ANY PURPOSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23 HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER, ITS AFFILIATES,
27 PARENT COMPANIES, LICENSORS, SUPPLIERS, OR CONTRIBUTORS BE LIABLE FOR
28 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 ANY WAY OUT OF THE USE OR PERFORMANCE OF THIS SOFTWARE OR SOURCE CODE,
34 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36 #pragma once
37 
38 #include "cohtml/View.h"
39 
40 #include "HummingbirdMeshData.h"
41 #include "HummingbirdSystem.h"
42 #include "HummingbirdEventHelpers.h"
43 #include "HummingbirdViewListener.h"
44 #include "HummingbirdRenderWrapper.h"
45 #include "HummingbirdAudioWrapper.h"
46 #include "HummingbirdDataBinding.h"
47 #include "HummingbirdBaseComponent.generated.h"
48 
49 namespace cohtml
50 {
51 class SystemRenderer;
52 }
53 
54 class FHummingbirdGesturePolicy;
55 
56 UCLASS(BlueprintType)
57 class HUMMINGBIRDPLUGIN_API UHummingbirdBaseComponent : public UActorComponent
58 {
59  GENERATED_UCLASS_BODY()
60 public:
64  UFUNCTION(BlueprintCallable, Category = "Audio")
65  void SetSoundAttenuation(const FSoundAttenuationSettings& Settings);
66 
68  UPROPERTY(BlueprintAssignable)
69  FHBReadyForBindingsSignature ReadyForBindings;
70 
72  UPROPERTY(BlueprintAssignable)
73  FHBBindingsReleasedSignature BindingsReleased;
74 
76  UPROPERTY(BlueprintAssignable)
77  FHBScriptingReady HBScriptingReady;
78 
80  UFUNCTION(BlueprintCallable, Category = "View")
81  virtual void Resize(/*uint32*/ int32 width, /*uint32*/ int32 height);
82 
84  UFUNCTION(BlueprintCallable, Category = "View")
85  bool IsReadyToCreateView() const;
86 
88  UFUNCTION(BlueprintCallable, Category = "View")
89  bool IsReadyForBindings() const;
90 
92  UFUNCTION(BlueprintCallable, Category = "View")
93  bool HasRequestedView() const;
94 
96  UFUNCTION(BlueprintCallable, Category = "View")
97  void ShowPaintRects(bool show);
98 
100  UFUNCTION(BlueprintCallable, Category = "View")
101  void Load(const FString& path);
102 
104  UFUNCTION(BlueprintCallable, Category = "View")
105  void Reload();
106 
108  UFUNCTION(BlueprintCallable, Category = "View")
109  void DebugSaveNextFrame();
110 
112  UFUNCTION(BlueprintCallable, Category = "View")
113  void BeginDebugFrameSave();
114 
116  UFUNCTION(BlueprintCallable, Category = "View")
117  void EndDebugFrameSave();
118 
120  UFUNCTION(BlueprintCallable, Category = "View")
121  void EnableDelayedUpdate(bool bEnabled);
122 
124  UFUNCTION(BlueprintCallable, Category = "ViewScripting")
125  UHummingbirdJSEvent* CreateJSEvent();
126 
128  UFUNCTION(BlueprintCallable, Category = "ViewScripting")
129  void TriggerJSEvent(const FString& name, UHummingbirdJSEvent* eventData) const;
130 
132  UFUNCTION(BlueprintCallable, Category = "ViewScripting")
133  void CreateDataModelFromObject(const FString& Name, UObject* Model);
134 
136  UFUNCTION(BlueprintCallable, CustomThunk, meta = (CustomStructureParam = "Arg"), Category = "ViewScripting")
137  void CreateDataModelFromStruct(const FString& Name, const UStructProperty* Arg);
138 
142  UFUNCTION(BlueprintCallable, Category = "ViewScripting")
143  void UpdateWholeDataModelFromObject(UObject* Model) const;
144 
148  UFUNCTION(BlueprintCallable, CustomThunk, meta = (CustomStructureParam = "Struct"), Category = "ViewScripting")
149  void UpdateWholeDataModelFromStruct(const UStructProperty* Struct) const;
150 
152  UFUNCTION(BlueprintCallable, Category = "ViewScripting")
153  void SynchronizeModels() const;
154 
156  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "View", DisplayName = "Enable Complex CSS Selector Support")
157  bool bEnableComplexCSSSupport;
158 
160  UPROPERTY(BlueprintReadOnly, Category = "View")
161  UTextureRenderTarget2D* Texture;
162 
163  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "View", AdvancedDisplay)
164  TEnumAsByte<enum TextureFilter> Filter;
165 
167  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "View")
168  bool bReceiveInput;
169 
172  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "View")
173  bool bDelayedUpdate;
174 
175  static void CreateSystemIfNecessary(UWorld* World);
176  static class AHummingbirdSystem* GetSystemActor(UWorld* World);
177 
178  virtual ~UHummingbirdBaseComponent();
179  virtual void InitializeComponent() override;
180  virtual void BeginDestroy() override;
181  virtual bool IsReadyForFinishDestroy() override;
182  virtual void FinishDestroy() override;
183 
184  virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
185 
186  bool EnsureMeshData();
187  TArray<FHummingbirdMeshData> MeshData;
188 
189  typedef TArray<TWeakObjectPtr<UHummingbirdBaseComponent>> WeakHummingbirdComponentsArray;
190  static WeakHummingbirdComponentsArray::TIterator GetUHummingbirdBaseComponentIterator(UWorld* world);
191 
192  cohtml::View* GetView() const;
193  cohtml::ViewRenderer* GetViewRenderer() const;
194  FHummingbirdGesturePolicy* GetGesturePolicy();
195 
196 protected:
197  void CreateView(const cohtml::ViewSettings& info, const FString& url);
198 
199  virtual void SendRenderDynamicData_Concurrent() override;
200  virtual bool RequiresGameThreadEndOfFrameUpdates() const override { return true; }
201 
202 private:
203  friend class THummingbirdViewListener<UHummingbirdBaseComponent>;
204 
205  void OnAudioStreamCreated(int Id, int BitDepth, int Channels,
206  float samplingRate);
207  void OnAudioStreamClosed(int Id);
208  void OnAudioStreamPlay(int Id);
209  void OnAudioStreamPause(int Id);
210  void OnAudioDataReceived(int Id, int Samples, float** Pcm,
211  int channels);
212  void OnAudioStreamEnded(int Id);
213  void OnAudioStreamVolumeChanged(int Id, float Volume);
214 
215  THummingbirdAudioWrapper<UHummingbirdBaseComponent> AudioWrapper;
216 
217  void SetReadyForBindings();
218 
219  FCaretRect CaretRect;
220  TUniquePtr<THummingbirdViewListener<UHummingbirdBaseComponent>> Listener;
221  TUniquePtr<FHummingbirdRenderWrapper> RenderWrapper;
222 
223  // Custom deleter function is used so we can use a forward declaration of GesturePolicy
224  struct GesturePolicyDeleter
225  {
226  void operator()(FHummingbirdGesturePolicy* Ptr) const;
227  };
228  TUniquePtr<FHummingbirdGesturePolicy, GesturePolicyDeleter> GesturePolicy;
229 
230  AHummingbirdSystem* SystemActor;
231  cohtml::SystemRenderer* SystemRenderer;
232 
233  bool bIsReadyForBindings;
234 
235  bool bIsLoadingMeshData;
236  bool bHasMeshData;
237 
238  void LoadMeshData(const TArray<TWeakObjectPtr<UStaticMeshComponent>>& Meshes);
239 
240  unsigned PendingLayout;
241 
242 public:
243 #if defined(HUMMINGBIRD_UE4_418_SUPPORT)
244  DECLARE_FUNCTION(execCreateDataModelFromStruct)
245  {
246  if (!bIsReadyForBindings)
247  {
248  return;
249  }
250  P_GET_PROPERTY(UStrProperty, Name);
251 
252  Stack.StepCompiledIn<UStructProperty>(NULL);
253  void* ArgAddress = Stack.MostRecentPropertyAddress;
254  UStructProperty* Prop = Cast<UStructProperty>(Stack.MostRecentProperty);
255 
256  if (Prop)
257  {
258  HummingbirdDataBindingHelpers::CreateModel(GetView(), Name, ArgAddress, Prop->Struct);
259  }
260  P_FINISH;
261  }
262 
263  DECLARE_FUNCTION(execUpdateWholeDataModelFromStruct)
264  {
265  if (!bIsReadyForBindings)
266  {
267  return;
268  }
269 
270  Stack.StepCompiledIn<UStructProperty>(NULL);
271  void* ArgAddress = Stack.MostRecentPropertyAddress;
272  UStructProperty* Prop = Cast<UStructProperty>(Stack.MostRecentProperty);
273  HummingbirdDataBindingHelpers::UpdateWholeModel(GetView(), ArgAddress, Prop->Struct);
274  P_FINISH;
275  }
276 #else
277  //declared here and defined in the cpp file
278  DECLARE_FUNCTION(execCreateDataModelFromStruct);
279  DECLARE_FUNCTION(execUpdateWholeDataModelFromStruct);
280 #endif
281 };
282 
Definition: HummingbirdJSEvent.h:51
Definition: HummingbirdFColorBinder.h:41