2.9.16.0
Coherent GT for UE4
CoherentUIGTBaseComponent.h
1 /*
2 This file is part of Coherent UI GT, 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 "Coherent/UIGT/View.h"
39 
40 #include "CoherentUIGTMeshData.h"
41 #include "CoherentUIGTSystem.h"
42 #include "CoherentUIGTEventHelpers.h"
43 #include "CoherentUIGTViewListener.h"
44 #include "CoherentUIGTRenderWrapper.h"
45 #include "CoherentUIGTAudioWrapper.h"
46 #include "CoherentUIGTDataBinding.h"
47 
48 #if !defined(COHERENT_UI_GT_UE4_413_SUPPORT)
49 #include "Runtime/Core/Public/HAL/ThreadSafeBool.h"
50 #endif
51 
52 #include "CoherentUIGTBaseComponent.generated.h"
53 
54 namespace Coherent
55 {
56 namespace UIGT
57 {
58 class UISystemRenderer;
59 }
60 }
62 
63 UCLASS(BlueprintType)
64 class COHERENTUIGTPLUGIN_API UCoherentUIGTBaseComponent : public UActorComponent
65 {
66  GENERATED_UCLASS_BODY()
67 
68 public:
69  typedef TSharedPtr<TCoherentUIGTViewListener<UCoherentUIGTBaseComponent>> ListenerPtr;
70  typedef TSharedPtr<FCoherentUIGTRenderWrapper> RenderWrapperPtr;
71 
73  UPROPERTY(BlueprintAssignable)
74  FUIGTReadyForBindingsSignature ReadyForBindings;
75 
77  UPROPERTY(BlueprintAssignable)
78  FUIGTBindingsReleasedSignature BindingsReleased;
79 
81  UPROPERTY(BlueprintAssignable)
82  FUIGTFinishLoadSignature FinishLoad;
83 
85  UPROPERTY(BlueprintAssignable)
86  FUIGTFailLoadSignature FailLoad;
87 
89  UPROPERTY(BlueprintAssignable)
90  FUIGTStartLoadingSignature StartLoading;
91 
93  UPROPERTY(BlueprintAssignable)
94  FUIGTNavigateToSignature NavigateTo;
95 
97  UPROPERTY(BlueprintAssignable)
98  FUIGTOnJavaScriptEvent JavaScriptEvent;
99 
101  UPROPERTY(BlueprintAssignable)
102  FUIGTScriptingReady UIGTScriptingReady;
103 
106  UPROPERTY()
107  FUIGTOnLiveViewSizeRequest LiveViewSizeRequested;
108 
110  FUIGTOnPerformanceAuditSignature OnPerformanceAudit;
111 
113  UFUNCTION(BlueprintCallable, Category = "View")
114  virtual void Resize(/*uint32*/ int32 width, /*uint32*/ int32 height);
115 
117  UFUNCTION(BlueprintCallable, Category = "View")
118  bool IsReadyToCreateView() const;
119 
121  UFUNCTION(BlueprintCallable, Category = "View")
122  bool IsReadyForBindings() const;
123 
125  UFUNCTION(BlueprintCallable, Category = "View")
126  bool HasRequestedView() const;
127 
129  UFUNCTION(BlueprintCallable, Category = "View")
130  bool IsTransparent() const;
131 
133  UFUNCTION(BlueprintCallable, Category = "View")
134  void ShowPaintRects(bool show);
135 
137  UFUNCTION(BlueprintCallable, Category = "View")
138  void Redraw() const;
139 
141  UFUNCTION(BlueprintCallable, Category = "View")
142  void Load(const FString& path);
143 
145  UFUNCTION(BlueprintCallable, Category = "View")
146  void Reload();
147 
149  UFUNCTION(BlueprintCallable, Category = "View")
150  bool IsDocumentReady() const;
151 
153  UFUNCTION(BlueprintCallable, Category = "View")
154  void DebugSaveNextFrame();
155 
157  UFUNCTION(BlueprintCallable, Category = "View")
158  void BeginDebugFrameSave();
159 
161  UFUNCTION(BlueprintCallable, Category = "View")
162  void EndDebugFrameSave();
163 
165  UPROPERTY(BlueprintReadOnly, Category = "View")
166  UTextureRenderTarget2D* Texture;
167 
168  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "View", AdvancedDisplay)
169  TEnumAsByte<enum TextureFilter> Filter;
170 
172  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "View")
173  bool bReceiveInput;
174 
177  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "View")
178  bool bReceiveInputWhenTransparent;
179 
181  UFUNCTION(BlueprintCallable, Category = "View")
182  void SetClickThroughAlphaThreshold(float threshold);
183 
185  UFUNCTION(BlueprintCallable, Category = "View")
186  float GetClickThroughAlphaThreshold() const;
187 
189  UFUNCTION(BlueprintCallable, Category = "View")
190  void EnableDelayedUpdate(bool bEnabled);
191 
193  UFUNCTION(BlueprintCallable, Category = "ViewScripting")
194  UCoherentUIGTJSEvent* CreateJSEvent();
195 
197  UFUNCTION(BlueprintCallable, Category = "ViewScripting")
198  void TriggerJSEvent(const FString& name, UCoherentUIGTJSEvent* eventData) const;
199 
201  UFUNCTION(BlueprintCallable, Category = "ViewScripting")
202  void CreateDataModelFromObject(const FString& Name, UObject* Model);
203 
204  // COH_BACKWARD_COMPATIBLE_BLOCK_START
206  UFUNCTION(BlueprintCallable, CustomThunk, meta = (CustomStructureParam = "Arg"), Category = "ViewScripting")
207  void CreateDataModelFromStruct(const FString& Name, const TFieldPath<FStructProperty> Arg);
208 
211  UFUNCTION(BlueprintCallable, CustomThunk, meta = (CustomStructureParam = "Arg"), Category = "ViewScripting")
212  void UpdateWholeDataModelFromStruct(const TFieldPath<FStructProperty> Arg) const;
213  // COH_BACKWARD_COMPATIBLE_BLOCK_END
214 
217  UFUNCTION(BlueprintCallable, Category = "ViewScripting")
218  void UpdateWholeDataModelFromObject(UObject* Model) const;
219 
221  UFUNCTION(BlueprintCallable, Category = "ViewScripting")
222  void SynchronizeModels() const;
223 
227  //UFUNCTION(BlueprintCallable, Category = "Audio") TODO: FIXME!
228  void SetSoundAttenuation(const FAttenuationSettingsClass& settings);
229 
230  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ViewWarnings")
231  bool AllowPerformanceWarnings;
232 
233  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ViewWarnings", meta = (ClampMin = "0", UIMin = "0", UIMax = "100"))
234  float ExecuteJSTimersThresholdMs;
235 
236  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ViewWarnings", meta = (ClampMin = "0", UIMin = "0", UIMax = "100"))
237  float UpdateStylesAndLayoutThresholdMs;
238 
239  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ViewWarnings", meta = (ClampMin = "0", UIMin = "0", UIMax = "100"))
240  float RecordRenderingCommandsThresholdMs;
241 
242  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ViewWarnings", meta = (ClampMin = "0", UIMin = "0", UIMax = "100"))
243  float PaintWarningThresholdMs;
244 
245  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ViewWarnings", meta = (ClampMin = "0", UIMin = "0", UIMax = "200"))
246  int32 LayersCountThreshold;
247 
248  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ViewWarnings", meta = (ClampMin = "0", UIMin = "128", UIMax = "8192"))
249  int32 LayerWidthThreshold;
250 
251  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ViewWarnings", meta = (ClampMin = "0", UIMin = "128", UIMax = "8192"))
252  int32 LayerHeightThreshold;
253 
256  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "View")
257  bool bEnableAdditionalDefaultStyles;
258 
261  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "View")
262  bool bDelayedUpdate;
263 
264  DECLARE_DELEGATE_RetVal(TUniquePtr<FCohComponentViewState>, FOnViewStateAdoption);
268  FOnViewStateAdoption OnViewStateAdoption;
269 
270  DECLARE_DELEGATE_OneParam(FOnViewStatePostAdoption, const TUniquePtr<FCohComponentViewState>&);
274  FOnViewStatePostAdoption OnViewStatePostAdoption;
275 
276  DECLARE_DELEGATE_OneParam(FOnViewStatePutForAdoption, TUniquePtr<FCohComponentViewState>&);
280  FOnViewStatePutForAdoption OnViewStatePutForAdoption;
281 
282  EMouseCursor::Type CurrentMouseCursor;
283 
284  Coherent::UIGT::View* GetView() const;
285  static void CreateSystemIfNecessary(UWorld* World);
286  static class ACoherentUIGTSystem* GetSystemActor(UWorld* World);
287 
288  virtual ~UCoherentUIGTBaseComponent();
289  virtual void InitializeComponent() override;
290  virtual void BeginDestroy() override;
291  virtual bool IsReadyForFinishDestroy() override;
292  virtual void FinishDestroy() override;
293 
294  virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
295  void IssueMouseOnUIQuery(float normX, float normY);
296 
297  bool EnsureMeshData();
298  TArray<FCoherentUIGTMeshData> MeshData;
299 
300  const FCaretRect& GetCaretRect() const;
301  void SetCaretRect(int x, int y, unsigned width, unsigned height);
302 
303  typedef TArray<TWeakObjectPtr<UCoherentUIGTBaseComponent>> WeakCoherentUIGTComponentsArray;
304  static WeakCoherentUIGTComponentsArray::TIterator GetUCoherentUIGTBaseComponentIterator(UWorld* world);
305 
306  Coherent::UIGT::ViewRenderer* GetViewRenderer() const;
307 
308  bool bWasMouseOnUILastFrame;
309 
310 protected:
311  void CreateView(const Coherent::UIGT::ViewInfo& info, const FString& url, bool PaintToBackBuffer = false);
312  ListenerPtr Listener;
313  RenderWrapperPtr RenderWrapper;
314 
315 private:
317 
318  void SetReadyForBindings();
319  void OnCallback(const char* eventName, const Coherent::UIGT::EventArguments& arguments);
320 
321  void OnLiveViewSizeRequested(const FString& name, int32& width, int32& height);
322  void OnLiveViewActivate(const FString& name, bool active);
323  void OnCursorChanged(Coherent::UIGT::CursorType Cursor);
324 
325  void OnAudioStreamCreated(int id, int bitDepth, int channels,
326  float samplingRate);
327  void OnAudioStreamClosed(int id);
328  void OnAudioStreamPlay(int id);
329  void OnAudioStreamPause(int id);
330  void OnAudioDataReceived(int id, int samples, float** pcm,
331  int channels);
332  void OnAudioStreamEnded(int id);
333 
334  UPROPERTY(Transient)
335  UCoherentUIGTAudioWrapper* AudioWrapper;
336 
337  FCaretRect CaretRect;
338  ACoherentUIGTSystem* SystemActor;
339  Coherent::UIGT::UISystemRenderer* SystemRenderer;
340 
341  bool bIsLoadingMeshData;
342 
343 #if defined(COHERENT_UI_GT_UE4_413_SUPPORT)
344  bool bHasMeshData;
345 #else
346  FThreadSafeBool bHasMeshData;
347 #endif
348 
349  void LoadMeshData(const TArray<TWeakObjectPtr<UStaticMeshComponent>>& Meshes);
350 
351  unsigned PendingLayout;
352 
353 public:
354 #if defined(COHERENT_UI_GT_UE4_418_SUPPORT)
355  DECLARE_FUNCTION(execCreateDataModelFromStruct)
356  {
357  if (!IsReadyForBindings())
358  {
359  return;
360  }
361  P_GET_PROPERTY(UStrProperty, Name);
362 
363  Stack.StepCompiledIn<UStructProperty>(NULL);
364  void* ArgAddress = Stack.MostRecentPropertyAddress;
365  UStructProperty* Prop = Cast<UStructProperty>(Stack.MostRecentProperty);
366 
367  if (Prop)
368  {
369  CoherentUIGTDataBindingHelpers::CreateModel(GetView(), Name, ArgAddress, Prop->Struct);
370  }
371  P_FINISH;
372  }
373 
374  DECLARE_FUNCTION(execUpdateWholeDataModelFromStruct)
375  {
376  if (!IsReadyForBindings())
377  {
378  return;
379  }
380 
381  Stack.StepCompiledIn<UStructProperty>(NULL);
382  void* ArgAddress = Stack.MostRecentPropertyAddress;
383  UStructProperty* Prop = Cast<UStructProperty>(Stack.MostRecentProperty);
384  CoherentUIGTDataBindingHelpers::UpdateWholeModel(GetView(), ArgAddress, Prop->Struct);
385  P_FINISH;
386  }
387 #else
388  //declared here and defined in the cpp file
389  DECLARE_FUNCTION(execCreateDataModelFromStruct);
390  DECLARE_FUNCTION(execUpdateWholeDataModelFromStruct);
391 #endif
392 };
393 
395 {
396  typedef UCoherentUIGTBaseComponent::ListenerPtr ListenerPtr;
397  typedef UCoherentUIGTBaseComponent::RenderWrapperPtr RenderWrapperPtr;
398 
399  ListenerPtr Listener;
400  RenderWrapperPtr RenderWrapper;
401 
403  {}
404 
405  FCohComponentViewState(ListenerPtr InListener, RenderWrapperPtr InRenderWrapper)
406  : Listener(InListener)
407  , RenderWrapper(InRenderWrapper)
408  {}
409 
410  Coherent::UIGT::View* GetView()
411  {
412  return RenderWrapper->GetView();
413  }
414 
415  void DestroyRenderWrapper()
416  {
417  if (RenderWrapper.IsValid())
418  {
419  RenderWrapper->BeginDestroy();
420  RenderWrapper->WaitForFinishDestroy();
421  RenderWrapper->FinishDestroy();
422  }
423  }
424 };
Definition: CoherentUIGTAudioWrapper.h:66
Definition: CoherentUIGTBaseComponent.h:394
Definition: CoherentUIGTMeshData.h:52
Definition: CoherentUIGTBaseComponent.h:64
Definition: CoherentUIGTEventHelpers.h:73
Definition: CoherentUIGTSystem.h:52
Definition: CoherentUIGTViewListener.h:44
Definition: CoherentUIGTJSEvent.h:52
Definition: CoherentUIGTFColorBinder.h:40