You.i Engine
YiImageView.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2017. 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;
14 class CYITextSceneNode;
15 class CYIUrl;
16 
98 class CYIImageView : public CYISceneView
99 {
100 public:
107  {
114  };
115 
124  {
129  };
130 
131  CYIImageView();
132  virtual ~CYIImageView();
133 
134  virtual bool Init() override;
135 
141  void SetScaleMode(SCALE_MODE eScaleMode);
142 
148  SCALE_MODE GetScaleMode() const;
149 
158  void SetRepeatMode(REPEAT_MODE eRepeatMode);
159 
166  REPEAT_MODE GetRepeatMode() const;
167 
173  void SetMipmappingEnabled(bool bEnable);
174 
178  bool IsMipmappingEnabled() const;
179 
185  void SetImage(const std::shared_ptr<CYIAssetTextureBase> &pTexture);
186 
193  void SetImage(const CYIUrl &url);
194 
198  virtual void Reset() override;
199 
203  void SetOverlayTextColor(const CYIColor &color);
204 
208  void SetOverlayTextSize(const uint32_t &nFontSize);
209 
213  void SetOverlayTextFontID(const ssize_t &nFontID);
214 
218  void SetOverlayText(const CYIString &text);
219 
223  virtual void OnImageHasChanged();
224 
228  CYISceneNode *GetImageNode() const;
229 
235  void SetImageUrl(const CYIUrl &url);
236 
245  const CYIUrl &GetImageUrl() const;
246 
247  virtual void Measure(const MeasureSpec &widthSpec, const MeasureSpec &heightSpec, const MeasureSpec &depthSpec) override;
248 
249  virtual void ApplyMeasurements() override;
250 
259 
260 protected:
265 
267 
277 
278  std::shared_ptr<CYIAssetTexture> m_pTextAsset;
279  std::shared_ptr<CYIMesh> m_pImagePlaceholderMesh;
280  std::shared_ptr<CYIMaterial> m_pImagePlaceholderMaterial;
281 
282 private:
283  enum class DisplayState;
284 
285  void AssetReady(const std::shared_ptr<CYIAsset> &pTex, const CYIUrl &url);
286  void AssetDownloadFailed(CYIAssetDownloadHelper::FAILURE_TYPE eFailureType, const CYIUrl &url);
287  void AssetDownloadCancelled(const CYIUrl &url);
288  void OnImageDownloadFailed(const CYIString &rError);
289  void ReconfigureSize(CYISceneNode *pNode);
290  void Cleanup();
291  std::shared_ptr<CYIMesh> ResizeImageNodeMesh(CYISceneNode *pNode, float fNewWidth, float fNewHeight) const;
292  void PlayTransitionTimeline(DisplayState from, DisplayState to);
293  void TransitionToState(DisplayState to);
294  void ValidateRepeatMode();
295 
296  DisplayState m_eImageDisplayState;
297 
298  CYISceneNode *m_pSwapNode;
299  CYIAbstractTimeline *m_pImageSwapTimeline;
300  std::unique_ptr<CYIAbstractTimeline> m_pResetTimeline;
301  CYIAbstractTimeline *m_pImagePlaceholderToSuccessTimeline;
302  CYIAbstractTimeline *m_pImagePlaceholderToFailureTimeline;
303  CYIAbstractTimeline *m_pImagePlaceholderFailureToSuccessTimeline;
304  CYIAbstractTimeline *m_pImageFailureToSuccessTimeline;
305  CYIAbstractTimeline *m_pImageSuccessToFailureTimeline;
306 
307  CYIAssetDownloadHelper m_imageDownloader;
308 
310 };
311 
315 #endif // _YI_IMAGE_VIEW_H_
The base class for the timeline framework.
Definition: YiAbstractTimeline.h:29
Will proportionally scale the image to fit within the bounds of the &#39;ImageNode&#39;. There may be negativ...
Definition: YiImageView.h:111
glm::vec3 m_imagePlaceholderAnchorPoint
Definition: YiImageView.h:264
void SetOverlayTextColor(const CYIColor &color)
void SetMipmappingEnabled(bool bEnable)
Definition: YiSceneNode.h:356
Will proportionally scale the image to fill the &#39;ImageNode&#39;, with the excess overflowing beyond the b...
Definition: YiImageView.h:110
CYISceneNode * m_pImageNode
Definition: YiImageView.h:266
The image will be tiled within empty space of the &#39;ImageNode&#39;.
Definition: YiImageView.h:126
The base class for all view types. Views are containers of renderable elements that often define inte...
Definition: YiSceneView.h:47
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:35
A class that loads data in a pool of threads.
Definition: YiLoadThreadManager.h:37
CYIColor m_DefaultTextColor
Definition: YiImageView.h:270
Will stretch the image to fill the &#39;ImageNode&#39;. The aspect ratio of the image is not retained...
Definition: YiImageView.h:108
int32_t m_nDefaultFontSize
Definition: YiImageView.h:271
#define YI_TYPE_BASES(...)
Definition: YiRtti.h:350
virtual void OnImageHasChanged()
SCALE_MODE m_eScaleMode
Definition: YiImageView.h:273
A simple view which downloads and renders images.
Definition: YiImageView.h:98
Will proportionally scale the image to fill the &#39;ImageNode&#39;, with the excess being cropped...
Definition: YiImageView.h:109
SCALE_MODE GetScaleMode() const
bool IsMipmappingEnabled() const
float m_fImagePlaceholderWidth
Definition: YiImageView.h:261
const CYIUrl & GetImageUrl() const
std::shared_ptr< CYIMesh > m_pImagePlaceholderMesh
Definition: YiImageView.h:279
virtual ~CYIImageView()
void SetImage(const std::shared_ptr< CYIAssetTextureBase > &pTexture)
CYIString m_sDefaultText
Definition: YiImageView.h:269
ssize_t m_nDefaultFontID
Definition: YiImageView.h:272
virtual void Reset() override
virtual void ApplyMeasurements() override
CYIUrl m_ImageUrl
Definition: YiImageView.h:276
std::shared_ptr< CYIMaterial > m_pImagePlaceholderMaterial
Definition: YiImageView.h:280
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:114
A scene node type that renders text.
Definition: YiTextSceneNode.h:77
CYISceneNode * GetImageNode() const
std::shared_ptr< CYIAssetTexture > m_pTextAsset
Definition: YiImageView.h:278
A class used to encapsulate an URL.
Definition: YiUrl.h:24
CYISignal ImageAssigned
Definition: YiImageView.h:254
Similar tiling to REPEAT_TILE except the tiles adjacent to the image will be the mirror image of the ...
Definition: YiImageView.h:127
void SetRepeatMode(REPEAT_MODE eRepeatMode)
A download helper class used for downloading assets off of web servers.
Definition: YiAssetDownloadHelper.h:23
The original size and aspect ratio of the image will be retained, and it will overflow the bounds of ...
Definition: YiImageView.h:113
virtual bool Init() override
SCALE_MODE
Definition: YiImageView.h:106
The image will not repeat.
Definition: YiImageView.h:125
bool m_bUseMipmapping
Definition: YiImageView.h:275
int ssize_t
Definition: YiPredefWin32.h:133
CYITextSceneNode * m_pDefaultTextNode
Definition: YiImageView.h:268
float m_fImagePlaceholderHeight
Definition: YiImageView.h:262
CYISignal< const CYIString & > ImageAssignmentFailed
Definition: YiImageView.h:258
void SetOverlayTextSize(const uint32_t &nFontSize)
void SetScaleMode(SCALE_MODE eScaleMode)
REPEAT_MODE GetRepeatMode() const
REPEAT_MODE
Definition: YiImageView.h:123
float m_fImagePlaceholderAspectRatio
Definition: YiImageView.h:263
A class used to represent a color value.
Definition: YiColor.h:31
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:164
REPEAT_MODE m_eRepeatMode
Definition: YiImageView.h:274
The edge pixels of the image are stretched to the size of &#39;ImageNode&#39;.
Definition: YiImageView.h:128
void SetImageUrl(const CYIUrl &url)
FAILURE_TYPE
Definition: YiAssetDownloadHelper.h:32
void SetOverlayText(const CYIString &text)
void SetOverlayTextFontID(const ssize_t &nFontID)
The original size and aspect ratio of the image will be retained, and it will be centered in the midd...
Definition: YiImageView.h:112