You.i Engine
YiImageView.h
Go to the documentation of this file.
1 // © You i Labs Inc. All rights reserved.
2 #ifndef _YI_IMAGE_VIEW_H_
3 #define _YI_IMAGE_VIEW_H_
4 
5 #include "asset/YiAssetTexture.h"
7 #include "network/YiUrl.h"
8 #include "signal/YiSignal.h"
9 #include "utility/YiColor.h"
10 #include "view/YiSceneView.h"
11 
12 class CYIImageLoader;
13 class CYITextSceneNode;
14 class CYIUrl;
15 
97 class CYIImageView : public CYISceneView
98 {
99 public:
105  enum class ScaleMode
106  {
107  Stretch = 0,
108  Fill,
110  Fit,
111  ActualSize,
113  };
114 
122  enum class RepeatMode
123  {
124  None,
125  Tile,
126  Mirror,
127  ClampToEdge
128  };
129 
130  CYIImageView();
131  virtual ~CYIImageView();
132 
133  virtual bool Init() override;
134 
140  void SetScaleMode(ScaleMode scaleMode);
141 
147  ScaleMode GetScaleMode() const;
148 
157  void SetRepeatMode(RepeatMode repeatMode);
158 
165  RepeatMode GetRepeatMode() const;
166 
172  void SetMipmappingEnabled(bool enable);
173 
177  bool IsMipmappingEnabled() const;
178 
184  void SetImage(const std::shared_ptr<CYIAssetTextureBase> &pTexture, bool isNPatch = false);
185 
192  void SetImage(const CYIUrl &url);
193 
197  virtual void Reset() override;
198 
202  void SetOverlayTextColor(const CYIColor &color);
203 
207  void SetOverlayTextSize(const uint32_t &fontSize);
208 
212  void SetOverlayTextFontID(const ssize_t &fontID);
213 
217  void SetOverlayText(const CYIString &text);
218 
222  virtual void OnImageHasChanged();
223 
227  CYISceneNode *GetImageNode() const;
228 
234  void SetImageUrl(const CYIUrl &url);
235 
244  const CYIUrl &GetImageUrl() const;
245 
246  virtual void Measure(const MeasureSpec &widthSpec, const MeasureSpec &heightSpec, const MeasureSpec &depthSpec) override;
247 
248  virtual void ApplyMeasurements() override;
249 
258 
259 protected:
264 
266 
276 
277  std::shared_ptr<CYIBitmap> m_pImagePlaceholderNPatchBitmap;
278  std::shared_ptr<CYIMesh> m_pImagePlaceholderMesh;
279  std::shared_ptr<CYIMaterial> m_pImagePlaceholderMaterial;
280 
281 private:
282  enum class DisplayState;
283 
284  void AssetReady(const std::shared_ptr<CYIAsset> &pTex, const CYIUrl &url);
285  void AssetDownloadFailed(CYIAssetDownloadHelper::FailureType failureType, const CYIUrl &url);
286  void AssetDownloadCancelled(const CYIUrl &url);
287  void OnImageDownloadFailed(const CYIString &rError);
288  void ReconfigureSize(CYISceneNode *pNode);
289  void Cleanup();
290  std::shared_ptr<CYIMesh> ResizeImageNodeMesh(CYISceneNode *pNode, float newWidth, float newHeight) const;
291  void PlayTransitionTimeline(DisplayState from, DisplayState to);
292  void TransitionToState(DisplayState to);
293  void ValidateRepeatMode();
294 
295  DisplayState m_imageDisplayState;
296 
297  CYISceneNode *m_pSwapNode;
298  CYIAbstractTimeline *m_pImageSwapTimeline;
299  std::unique_ptr<CYIAbstractTimeline> m_pResetTimeline;
300  CYIAbstractTimeline *m_pImagePlaceholderToSuccessTimeline;
301  CYIAbstractTimeline *m_pImagePlaceholderToFailureTimeline;
302  CYIAbstractTimeline *m_pImagePlaceholderFailureToSuccessTimeline;
303  CYIAbstractTimeline *m_pImageFailureToSuccessTimeline;
304  CYIAbstractTimeline *m_pImageSuccessToFailureTimeline;
305 
306  std::unique_ptr<CYIAssetDownloadHelper> m_pImageDownloader;
307 
309 };
310 
314 #endif // _YI_IMAGE_VIEW_H_
void SetMipmappingEnabled(bool enable)
The base class for the timeline framework.
Definition: YiAbstractTimeline.h:29
Will proportionally scale the image to fill the &#39;ImageNode&#39;, with the excess overflowing beyond the b...
glm::vec3 m_imagePlaceholderAnchorPoint
Definition: YiImageView.h:263
void SetOverlayTextColor(const CYIColor &color)
const CYIUrl & GetImageUrl() const
FailureType
Definition: YiAssetDownloadHelper.h:33
ssize_t m_defaultFontID
Definition: YiImageView.h:271
std::shared_ptr< CYIBitmap > m_pImagePlaceholderNPatchBitmap
Definition: YiImageView.h:277
CYISceneNode * m_pImageNode
Definition: YiImageView.h:265
The base class for all view types. Views are containers of renderable elements that often define inte...
Definition: YiSceneView.h:47
float m_imagePlaceholderWidth
Definition: YiImageView.h:260
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:32
bool IsMipmappingEnabled() const
CYIColor m_DefaultTextColor
Definition: YiImageView.h:269
long long ssize_t
Definition: YiPredefWindows.h:21
int32_t m_defaultFontSize
Definition: YiImageView.h:270
virtual void OnImageHasChanged()
Will proportionally scale the image to fill the &#39;ImageNode&#39;, with the excess being cropped...
ScaleMode GetScaleMode() const
A simple view which downloads and renders images.
Definition: YiImageView.h:97
constexpr std::enable_if< YiEnableBitmaskOperators< E >::enable, bool >::type None(E a)
Definition: YiEnumBitmaskOperators.h:136
std::shared_ptr< CYIMesh > m_pImagePlaceholderMesh
Definition: YiImageView.h:278
CYIString m_defaultText
Definition: YiImageView.h:268
virtual ~CYIImageView()
The original size and aspect ratio of the image will be retained, and it will overflow the bounds of ...
CYISceneNode * GetImageNode() const
void SetRepeatMode(RepeatMode repeatMode)
virtual void Reset() override
virtual void ApplyMeasurements() override
CYIUrl m_ImageUrl
Definition: YiImageView.h:275
std::shared_ptr< CYIMaterial > m_pImagePlaceholderMaterial
Definition: YiImageView.h:279
void SetImage(const std::shared_ptr< CYIAssetTextureBase > &pTexture, bool isNPatch=false)
Will proportionally scale the image to fit within the bounds of the &#39;ImageNode&#39;. There may be negativ...
A scene node is the base type for all nodes which are used by the scene manager; it is an integral pa...
Definition: YiSceneNode.h:105
Definition: YiSceneNode.h:374
A scene node type that renders text.
Definition: YiTextSceneNode.h:79
void SetOverlayTextSize(const uint32_t &fontSize)
The original size and aspect ratio of the image will be retained, and it will be centered in the midd...
A class used to encapsulate an URL.
Definition: YiUrl.h:24
CYISignal ImageAssigned
Definition: YiImageView.h:253
RepeatMode m_repeatMode
Definition: YiImageView.h:273
virtual bool Init() override
RepeatMode
Definition: YiImageView.h:122
ScaleMode
Definition: YiImageView.h:105
void SetScaleMode(ScaleMode scaleMode)
Will stretch the image to fill the &#39;ImageNode&#39;. The aspect ratio of the image is not retained...
#define YI_TYPE_BASES(CLASS, BASES...)
Definition: YiRtti.h:259
CYITextSceneNode * m_pDefaultTextNode
Definition: YiImageView.h:267
CYISignal< const CYIString & > ImageAssignmentFailed
Definition: YiImageView.h:257
float m_imagePlaceholderAspectRatio
Definition: YiImageView.h:262
void SetOverlayTextFontID(const ssize_t &fontID)
A class used to represent a color value.
Definition: YiColor.h:35
virtual void Measure(const MeasureSpec &widthSpec, const MeasureSpec &heightSpec, const MeasureSpec &depthSpec) override
Signals and slots are a thread-safe and flexible communication framework that will allow various obje...
Definition: YiSignal.h:169
void SetImageUrl(const CYIUrl &url)
ScaleMode m_scaleMode
Definition: YiImageView.h:272
void SetOverlayText(const CYIString &text)
float m_imagePlaceholderHeight
Definition: YiImageView.h:261
bool m_useMipmapping
Definition: YiImageView.h:274
RepeatMode GetRepeatMode() const