示例#1
0
TreeItem::TreeItem(Globals& g, ds::ui::Sprite* linkedItem)
	: ds::ui::Sprite(g.mEngine)
	, mGlobals(g)
	, mLinkedSprite(linkedItem)
	, mNameText(nullptr)
	, mLabelTextTwo(nullptr)
{
	
	ds::ui::ImageButton* deleteButton = new ds::ui::ImageButton(mEngine, "%APP%/data/images/ui/close_button.png", "%APP%/data/images/ui/close_button.png", 10.0f);
	deleteButton->setScale(0.25f, 0.25f);
	deleteButton->getHighImage().setColor(ci::Color(0.7f, 0.2f, 0.2f));
	addChildPtr(deleteButton);
	deleteButton->setClickFn([this]{
		callAfterDelay([this]{
			mEngine.getNotifier().notify(DeleteSpriteRequest(mLinkedSprite));
		}, 0.01f);
	});


	float paddin = 10.0f;
	mLayoutLPad = paddin / 2.0f;
	mLayoutRPad = paddin/2.0f;
	float theWiddy = 0.0f;
	float theHiddy = 0.0f;
	mNameText = mGlobals.getText("tree:item").create(mEngine, this);
	mNameText->setText(mLinkedSprite->getSpriteName());
	mNameText->setPosition(deleteButton->getScaleWidth(), paddin / 2.0f);
	theWiddy += mNameText->getWidth() + paddin / 2.0f + deleteButton->getScaleWidth();
	theHiddy = mNameText->getFontSize() + paddin;
	

	mLabelTextTwo = mGlobals.getText("tree:item_two").create(mEngine, this);
	mLabelTextTwo->setText(ds::ui::XmlImporter::getSpriteTypeForSprite(mLinkedSprite));
	mLabelTextTwo->setPosition(theWiddy, paddin / 2.0f);
	theWiddy += mLabelTextTwo->getWidth() + paddin / 2.0f;
	if(mLabelTextTwo->getFontSize() + paddin > theHiddy){
		theHiddy = mLabelTextTwo->getFontSize() + paddin;
	}

	setTransparent(false);
	setColor(ci::Color(0.1f, 0.1f, 0.1f));
	setSize(theWiddy, theHiddy);
	enable(true);
	enableMultiTouch(ds::ui::MULTITOUCH_CAN_POSITION);
	setTapCallback([this](ds::ui::Sprite* bs, const ci::Vec3f& pos){
		if(mLinkedSprite){
			mEngine.getNotifier().notify(InspectSpriteRequest(mLinkedSprite));
		} 
	});
}
示例#2
0
NS_MD_BEGIN

bool MenuButton::init() {
	if (!Button::init()) {
		return false;
	}

	setStyle(Button::Style::FlatBlack);
	setTapCallback(std::bind(&MenuButton::onButton, this));
	setSpawnDelay(0.1f);
	setSwallowTouches(false);

	//_background->setVisible(false);

	_menuNameLabel = construct<Label>(FontType::Subhead);
	_menuNameLabel->setVisible(false);
	_menuNameLabel->setAnchorPoint(Vec2(0, 0.5f));
	_menuNameLabel->setLocaleEnabled(true);
	addChild(_menuNameLabel);

	_menuValueLabel = construct<Label>(FontType::Subhead);
	_menuValueLabel->setVisible(false);
	_menuValueLabel->setAnchorPoint(Vec2(1.0f, 0.5f));
	_menuValueLabel->setLocaleEnabled(true);
	addChild(_menuValueLabel);

	_menuNameIcon = construct<IconSprite>();
	_menuNameIcon->setVisible(false);
	_menuNameIcon->setAnchorPoint(Vec2(0, 0.5));
	addChild(_menuNameIcon);

	_menuValueIcon = construct<IconSprite>();
	_menuValueIcon->setVisible(false);
	_menuValueIcon->setAnchorPoint(Vec2(1, 0.5));
	addChild(_menuValueIcon);

	onLightLevel();

	return true;
}
示例#3
0
void MediaPlayer::enableStandardClick(){
	setTapCallback([this](ds::ui::Sprite* bs, const ci::Vec3f& pos){
		handleStandardClick(pos);
	});
}
示例#4
0
bool GalleryScroll::init(const ImageCallback &cb, const std::vector<std::string> &vec, size_t selected) {
	if (!Node::init()) {
		return false;
	}

	_imageCallback = cb;

	_overscrollTop = construct<Overscroll>(Overscroll::Top);
	_overscrollTop->setColor(material::Color::Grey_500);
	addChild(_overscrollTop, maxOf<int>() - 2);

	_overscrollBottom = construct<Overscroll>(Overscroll::Bottom);
	_overscrollBottom->setColor(material::Color::Grey_500);
	addChild(_overscrollBottom, maxOf<int>() - 2);

	_overscrollLeft = construct<Overscroll>(Overscroll::Left);
	_overscrollLeft->setColor(material::Color::Grey_500);
	addChild(_overscrollLeft, maxOf<int>() - 2);

	_overscrollRight = construct<Overscroll>(Overscroll::Right);
	_overscrollRight->setColor(material::Color::Grey_500);
	addChild(_overscrollRight, maxOf<int>() - 2);

	auto l = Rc<gesture::Listener>::create();
	l->setTouchFilter([this] (const Vec2 &loc, const gesture::Listener::DefaultTouchFilter &f) {
		return f(loc);
	});
	l->setTapCallback([this] (gesture::Event ev, const gesture::Tap &t) {
		if (_actionCallback) {
			_actionCallback(t.count==1?Tap:DoubleTap);
		}
		return onTap(t.location(), t.count);
	});
	l->setSwipeCallback([this] (gesture::Event ev, const gesture::Swipe &s) {
		auto density = screen::density();
		if (ev == stappler::gesture::Event::Began) {
			if (_actionCallback) {
				_actionCallback(Swipe);
			}
			return onSwipeBegin(s.location());
		} else if (ev == stappler::gesture::Event::Activated) {
			return onSwipe(cocos2d::Vec2(s.delta.x / density, s.delta.y / density));
		} else if (ev == stappler::gesture::Event::Ended) {
			return onSwipeEnd(cocos2d::Vec2(s.velocity.x / density, s.velocity.y / density));
		}
		return true;
	});
	l->setPinchCallback([this] (stappler::gesture::Event ev, const stappler::gesture::Pinch &p) {
		if (ev == stappler::gesture::Event::Began) {
			if (_actionCallback) {
				_actionCallback(Pinch);
			}
			_hasPinch = true;
		} else if (ev == stappler::gesture::Event::Activated) {
			_hasPinch = false;
			return onPinch(p.location(), p.scale, p.velocity, false);
		} else if (ev == stappler::gesture::Event::Ended || ev == stappler::gesture::Event::Cancelled) {
			_hasPinch = false;
			return onPinch(p.location(), p.scale, p.velocity, true);
		}
		return true;
	});
	addComponent(l);
	_gestureListener = l;

	_images = vec;

	reset(selected);

	return true;
}