2014-03-11 17:13:54 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
namespace ui {
|
2014-07-30 15:27:18 +08:00
|
|
|
class Scale9Sprite;
|
2014-03-11 17:13:54 +08:00
|
|
|
/**
|
2015-03-26 15:47:14 +08:00
|
|
|
* @brief A widget to display images.
|
|
|
|
*/
|
2014-07-21 17:45:56 +08:00
|
|
|
class CC_GUI_DLL ImageView : public Widget
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
DECLARE_CLASS_GUI_INFO
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Default constructor
|
|
|
|
*/
|
|
|
|
ImageView();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default destructor
|
|
|
|
*/
|
|
|
|
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();
|
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
|
|
|
*/
|
2014-05-09 14:56:05 +08:00
|
|
|
static ImageView* create(const std::string& imageFileName, TextureResType texType = TextureResType::LOCAL);
|
2014-04-02 16:37:09 +08:00
|
|
|
|
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
|
|
|
*/
|
2014-05-09 14:56:05 +08:00
|
|
|
void loadTexture(const std::string& 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-25 18:17:58 +08:00
|
|
|
* @param enable Set to true will use scale9 renderer, false otherwise.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
void setScale9Enabled(bool able);
|
|
|
|
|
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.
|
|
|
|
*/
|
2014-05-27 11:09:55 +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
|
|
|
|
*/
|
|
|
|
void setCapInsets(const Rect &capInsets);
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Get ImageView's capInsets size.
|
|
|
|
* @return Query capInsets size in Rect
|
|
|
|
* @see `setCapInsets(const Rect&)`
|
|
|
|
*/
|
2014-05-27 11:09:55 +08:00
|
|
|
const Rect& getCapInsets()const;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
//override methods.
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual void ignoreContentAdaptWithSize(bool ignore) override;
|
|
|
|
virtual std::string getDescription() const override;
|
2014-09-12 14:39:22 +08:00
|
|
|
virtual Size getVirtualRendererSize() const override;
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual Node* getVirtualRenderer() override;
|
2014-04-02 16:37:09 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
|
|
|
//initializes state of widget.
|
|
|
|
virtual bool init() override;
|
2014-05-09 14:56:05 +08:00
|
|
|
virtual bool init(const std::string& 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;
|
2014-06-06 16:02:44 +08:00
|
|
|
|
|
|
|
virtual void adaptRenderers() override;
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
void imageTextureScaleChangedWithSize();
|
|
|
|
virtual Widget* createCloneInstance() override;
|
|
|
|
virtual void copySpecialProperties(Widget* model) override;
|
|
|
|
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
|
|
|
std::string _textureFile;
|
|
|
|
TextureResType _imageTexType;
|
|
|
|
Size _imageTextureSize;
|
2014-04-17 14:08:25 +08:00
|
|
|
bool _imageRendererAdaptDirty;
|
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__) */
|