Cocos2d-x3.1ImageView的使用

ImageView源码如下

#ifndef __UIIMAGEVIEW_H__
#define __UIIMAGEVIEW_H__

#include "ui/UIWidget.h"

NS_CC_BEGIN

namespace ui {

/**
*   @js NA
*   @lua NA
*/
class ImageView : public Widget//公有继承自Widget
{
    
    DECLARE_CLASS_GUI_INFO
    
public:
    /**
     * Default constructor
     */
    ImageView();

    /**
     * Default destructor
     */
    virtual ~ImageView();

    /**
     * Allocates and initializes.
     */
    static ImageView* create();
    
    /**
     * create a  imageview 
     *
     * @param imageFileName   file name of texture.
     *
     * @param texType    @see UI_TEX_TYPE_LOCAL
     */
    static ImageView* create(const std::string& imageFileName, TextureResType texType = TextureResType::LOCAL);
    //create,第一个参数image的名称,第二个参数文理的类型

    /**
     * Load texture for imageview.
     *
     * @param fileName   file name of texture.
     *
     * @param texType    @see UI_TEX_TYPE_LOCAL
     *///重新载入纹理
    void loadTexture(const std::string& fileName,TextureResType texType = TextureResType::LOCAL);

    /**
     * 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);

    /**
     * Sets if imageview is using scale9 renderer.
     *
     * @param able true that using scale9 renderer, false otherwise.
     *///设置Scale9 Enable
    void setScale9Enabled(bool able);
//<span style="white-space:pre">	</span>判断是否开启Scale9
    bool isScale9Enabled();

    /**
     * Sets capinsets for imageview, if imageview is using scale9 renderer.
     *
     * @param capInsets    capinsets for imageview
     *///
    void setCapInsets(const Rect &capInsets);

    const Rect& getCapInsets();

    //override "ignoreContentAdaptWithSize" method of widget.
    virtual void ignoreContentAdaptWithSize(bool ignore) override;
//忽略大小
    /**
     * Returns the "class name" of widget.
     *///返回类的名称
    virtual std::string getDescription() const override;
<span style="white-space:pre">	</span>//返回虚拟纹理大小
    virtual const Size& getVirtualRendererSize() const override;
    virtual Node* getVirtualRenderer() override;
    
CC_CONSTRUCTOR_ACCESS:
    //initializes state of widget.
    virtual bool init() override;
    virtual bool init(const std::string& imageFileName, TextureResType texType = TextureResType::LOCAL);

protected:
    virtual void initRenderer() override;
    virtual void onSizeChanged() override;
    virtual void updateTextureColor() override;
    virtual void updateTextureOpacity() override;
    virtual void updateTextureRGBA() override;
    virtual void updateFlippedX() override;
    virtual void updateFlippedY() override;
    void imageTextureScaleChangedWithSize();
    virtual Widget* createCloneInstance() override;
    virtual void copySpecialProperties(Widget* model) override;
    virtual void adaptRenderers() override;
protected:
    bool _scale9Enabled;
    bool _prevIgnoreSize;
    Rect _capInsets;
    Node* _imageRenderer;
    std::string _textureFile;
    TextureResType _imageTexType;
    Size _imageTextureSize;
    bool _imageRendererAdaptDirty;
};

}

NS_CC_END

#endif /* defined(__CocoGUI__ImageView__) */

//代码示例
//在HelloWorld.cpp中得init函数中添加
    ImageView* imageView = ImageView::create("buttonHighlighted.png");
    imageView->setScale9Enabled(true);
    imageView->setSize(Size(300,150));
    imageView->setPosition(Vec2(winSize.width / 2.0f, winSize.height / 2.0f));
    addChild(imageView);


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值