2014-03-11 17:13:54 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2022-01-04 12:36:20 +08:00
|
|
|
https://adxeproject.github.io/
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __UIIMAGEVIEW_H__
|
|
|
|
#define __UIIMAGEVIEW_H__
|
|
|
|
|
|
|
|
#include "ui/UIWidget.h"
|
2014-07-21 17:45:56 +08:00
|
|
|
#include "ui/GUIExport.h"
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup ui
|
|
|
|
* @{
|
|
|
|
*/
|
2015-03-26 15:47:14 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2015-12-05 00:26:07 +08:00
|
|
|
struct CC_DLL ResourceData;
|
2015-11-18 13:38:29 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace ui
|
|
|
|
{
|
|
|
|
class Scale9Sprite;
|
2015-11-24 19:17:38 +08:00
|
|
|
/**
|
2015-03-26 15:47:14 +08:00
|
|
|
* @brief A widget to display images.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
class CC_GUI_DLL ImageView : public Widget, public cocos2d::BlendProtocol
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
DECLARE_CLASS_GUI_INFO
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Default constructor
|
2015-03-30 21:38:32 +08:00
|
|
|
* @js ctor
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua new
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
ImageView();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default destructor
|
2015-03-30 21:38:32 +08:00
|
|
|
* @js NA
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua NA
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
virtual ~ImageView();
|
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Create a empty ImageView.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
static ImageView* create();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-04-02 16:37:09 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Create a imageview with a image name.
|
2014-04-02 16:37:09 +08:00
|
|
|
*
|
2014-05-20 16:45:09 +08:00
|
|
|
* @param imageFileName file name of texture.
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param texType @see `Widget::TextureResType`
|
|
|
|
* @return A ImageView instance.
|
2014-04-02 16:37:09 +08:00
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
static ImageView* create(std::string_view imageFileName, TextureResType texType = TextureResType::LOCAL);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load texture for imageview.
|
|
|
|
*
|
|
|
|
* @param fileName file name of texture.
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param texType @see `Widget::TextureResType`
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
void loadTexture(std::string_view fileName, TextureResType texType = TextureResType::LOCAL);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the texture rect of the ImageView in points.
|
|
|
|
* It will call setTextureRect:rotated:untrimmedSize with rotated = NO, and utrimmedSize = rect.size.
|
|
|
|
*/
|
|
|
|
void setTextureRect(const Rect& rect);
|
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Enable scale9 renderer.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-27 17:09:54 +08:00
|
|
|
* @param enabled Set to true will use scale9 renderer, false otherwise.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2015-03-27 17:09:54 +08:00
|
|
|
void setScale9Enabled(bool enabled);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Query whether button is using scale9 renderer or not.
|
|
|
|
*@return whether button use scale9 renderer or not.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
bool isScale9Enabled() const;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Sets capInsets for imageview.
|
|
|
|
* The capInsets affects the ImageView's renderer only if `setScale9Enabled(true)` is called.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
|
|
|
* @param capInsets capinsets for imageview
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void setCapInsets(const Rect& capInsets);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Get ImageView's capInsets size.
|
|
|
|
* @return Query capInsets size in Rect
|
|
|
|
* @see `setCapInsets(const Rect&)`
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
const Rect& getCapInsets() const;
|
|
|
|
|
2017-08-22 09:40:37 +08:00
|
|
|
/**
|
|
|
|
* Sets the source blending function.
|
|
|
|
*
|
2021-12-25 10:04:45 +08:00
|
|
|
* @param blendFunc A structure with source and destination factor to specify pixel arithmetic. e.g.
|
|
|
|
* {BlendFactor::ONE, BlendFactor::ONE}, {BlendFactor::SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA}.
|
2017-08-22 09:40:37 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void setBlendFunc(const BlendFunc& blendFunc) override;
|
|
|
|
|
2017-08-22 09:40:37 +08:00
|
|
|
/**
|
|
|
|
* Returns the blending function that is currently being used.
|
|
|
|
*
|
|
|
|
* @return A BlendFunc structure with source and destination factor which specified pixel arithmetic.
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual const BlendFunc& getBlendFunc() const override;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
// override methods.
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual void ignoreContentAdaptWithSize(bool ignore) override;
|
|
|
|
virtual std::string getDescription() const override;
|
2021-10-23 23:27:14 +08:00
|
|
|
virtual Vec2 getVirtualRendererSize() const override;
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual Node* getVirtualRenderer() override;
|
2015-11-18 13:38:29 +08:00
|
|
|
|
2015-12-05 00:26:07 +08:00
|
|
|
ResourceData getRenderFile();
|
2015-11-18 13:38:29 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
// initializes state of widget.
|
|
|
|
virtual bool init() override;
|
2021-12-26 23:26:34 +08:00
|
|
|
virtual bool init(std::string_view imageFileName, TextureResType texType = TextureResType::LOCAL);
|
2014-04-02 16:37:09 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
protected:
|
|
|
|
virtual void initRenderer() override;
|
|
|
|
virtual void onSizeChanged() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-06 16:02:44 +08:00
|
|
|
virtual void adaptRenderers() override;
|
2015-06-05 14:19:05 +08:00
|
|
|
void loadTexture(SpriteFrame* spriteframe);
|
|
|
|
void setupTexture();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
void imageTextureScaleChangedWithSize();
|
|
|
|
virtual Widget* createCloneInstance() override;
|
|
|
|
virtual void copySpecialProperties(Widget* model) override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
protected:
|
|
|
|
bool _scale9Enabled;
|
|
|
|
bool _prevIgnoreSize;
|
|
|
|
Rect _capInsets;
|
2014-07-30 15:27:18 +08:00
|
|
|
Scale9Sprite* _imageRenderer;
|
2014-03-11 17:13:54 +08:00
|
|
|
TextureResType _imageTexType;
|
2021-10-23 23:27:14 +08:00
|
|
|
Vec2 _imageTextureSize;
|
2014-04-17 14:08:25 +08:00
|
|
|
bool _imageRendererAdaptDirty;
|
2015-11-18 13:38:29 +08:00
|
|
|
std::string _textureFile;
|
2014-03-11 17:13:54 +08:00
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace ui
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-03-26 15:47:14 +08:00
|
|
|
NS_CC_END
|
2015-03-25 18:17:58 +08:00
|
|
|
// end of ui group
|
|
|
|
/// @}
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
#endif /* defined(__CocoGUI__ImageView__) */
|