button

.h

#pragma once;

#include "cocos2d.h"
#include <string>
using std::string;
using namespace cocos2d;

enum LabelSide
{
	LS_LEFT,
	LS_RIGHT,
	LS_COUNT,
};

class Button:public CCNode
{

public:
	bool init();
	static Button* create();
	void setText(LabelSide side,string text,string font,size_t fontsize,ccColor3B color3b);
	void setTextBox(LabelSide side,CCSize size);
	void setTextDesion(LabelSide side);
private:
	CCLabelTTF*mLabel[LS_COUNT];
	CCMenuItemImage*mItemImage;
};



.cpp

#include "Button.h"

#define default_box CCSizeMake(100,50);

bool Button::init()
{
	for(int i = 0; i < LS_COUNT;i++)
	{
		mLabel[i] = CCLabelTTF::create();
		mLabel[i]->setPosition(CCPointMake(0,0));
	}

	mItemImage = CCMenuItemImage::create();
	return true;
}

void Button::setText(LabelSide side,string text,string font,size_t fontsize,ccColor3B color3b)
{
	mLabel[side]->initWithString(text.c_str(),font.c_str(),fontsize);
	mLabel[side]->setColor(color3b);
}

void Button::setTextBox(LabelSide side,CCSize size)
{
	mLabel[side]->setDimensions(size);
}

Button* Button::create()
{
	Button * pRet = new Button();
	if (pRet && pRet->init())
	{
		pRet->autorelease();
	}
	else
	{
		CC_SAFE_DELETE(pRet);
	}
	return pRet;
}




你可能感兴趣的:(button)