예제 #1
0
void HoleModeResult::startAnim(){
        HCCWindow::startAnim();
    if (m_star>0&&m_star<=4) {
        for (int i=0; i<m_star; i++) {
            IntToStringFormat(_starName, "gift_%d", i);
            UIWidget* mStars = m_tips->getChildByName(_starName);
            mStars->setVisible(true);
            PopNodeQ(mStars, 0.6f+0.4f*i);
        }
    }
    UIWidget* mLight = m_tips->getChildByName("light");
    UIWidget* btn_home = m_tips->getChildByName("btn_home");
    UIWidget* btn_next = m_tips->getChildByName("btn_next");
    UIWidget* mTitle = m_tips->getChildByName("title_bg");
    
    mLight->setVisible(false);
    mLight->runAction(CCRepeatForever::create(CCRotateBy::create(6.0f, 360)));
    mLight->runAction(CCSequence::create(CCDelayTime::create(0.6f+0.4f*m_star),CCShow::create(),NULL));
    mTitle->runAction(CCSequence::create(CCDelayTime::create(0.6f+0.4f*m_star),CCRepeat::create(CCSequence::create(CCScaleTo::create(0.15f, 1.1f),CCScaleTo::create(0.3f, 1.0f),NULL),99),NULL));
    if (m_rewards) {
        for (unsigned int i=0; i<m_rewards->count()&&i<4; i++) {
            RewardInfo* info = (RewardInfo*)m_rewards->objectAtIndex(i);
            IntToStringFormat(_rName,"reward_%d",i+1);
            UIImageView* mReward = (UIImageView*)m_tips->getChildByName(_rName);
            IntToStringFormat(_iconName, "icons/icon_reward_%d.png",info->id);
            mReward->setTexture(_iconName);
            UILabelAtlas* num = (UILabelAtlas*)mReward->getChildByName("count");
            IntToStringFormat(_count, ":%d",info->count);
            num->setStringValue(_count);
            mReward->setVisible(true);
            PopNodeQ(mReward, 0.4f+0.4f*m_star);
        }
        m_rewards->removeAllObjects();
        CC_SAFE_DELETE(m_rewards);
    }

    PopNode(btn_home, 0.4f+0.4f*m_star);
    PopNode(btn_next, 0.8f+0.4f*m_star);
    
    btn_home->addReleaseEvent(this, coco_releaseselector(HoleModeResult::onHome));
    btn_next->addReleaseEvent(this, coco_releaseselector(HoleModeResult::onRestart));
    
    UIWidget* mContainer = m_tips->getChildByName("Container");
    
    const int count = 8;
    
    UILabelAtlas* mNums[count];
    for (int i=0; i<count; i++) {
        IntToStringFormat(mName, "m_%d", i);
        mNums[i] = (UILabelAtlas*)mContainer->getChildByName(mName);
    }
    SetDepthNum(mNums, count, m_totaldepth)
//    {
//        int tmpNum = m_totaldepth;
//        
//        for (int i=0; i<count; i++) {
//            IntToString(n, tmpNum%10)
//            tmpNum/=10;
//            mNums[i]->setStringValue(n);
//        }
//    }
    ScrollDepthNum(mNums, count, m_totaldepth, m_totaldepth+m_currentdepth);
//    {
//        int pre = m_totaldepth;
//        int current = m_totaldepth+m_currentdepth;
//        for (int i=0; i<count; i++) {
//            if (current%10==pre%10) {
//                current/=10;
//                pre/=10;
//                continue;
//            }
//            IntToString(n, current%10);
//            current/=10;
//            pre/=10;
//            CCPoint pos = mNums[i]->getPosition();
//            UIWidget* parent = mNums[i]->getParent();
//            mNums[i]->runAction(CCSequence::create(CCDelayTime::create(0.5f), CCMoveBy::create(0.3f, ccp(0, 50)),CCCallFuncND::create(this, callfuncND_selector(G::G_callbackRemoveUIWidget2),mNums[i]),NULL));
//            mNums[i] = UILabelAtlas::create();
//            mNums[i]->setProperty(n, "numbers/num3.png", 20, 28, "0");
//            mNums[i]->setPosition(ccp(pos.x,pos.y-50));
//            parent->addChild(mNums[i]);
//            mNums[i]->runAction(CCSequence::create(CCDelayTime::create(0.5f), CCMoveBy::create(0.3f, ccp(0, 50)),NULL));
//        }
//    }
    

}
void UIScrollView::resortChildren()
{
    if (!m_children || m_children->count() <= 0)
    {
        return;
    }
    UIWidget* leftChild = (UIWidget*)(m_children->objectAtIndex(0));
    UIWidget* rightChild = (UIWidget*)(m_children->objectAtIndex(0));
    UIWidget* topChild = (UIWidget*)(m_children->objectAtIndex(0));
    UIWidget* bottomChild = (UIWidget*)(m_children->objectAtIndex(0));
    ccArray* arrayChildren = m_children->data;
    int childrenCount = arrayChildren->num;
    for (int i = 0; i < childrenCount; i++)
    {
        UIWidget* child = (UIWidget*)(arrayChildren->arr[i]);
        if (leftChild->getRelativeRect().origin.x > child->getRelativeRect().origin.x)
        {
            leftChild = child;
        }
        if (rightChild->getRelativeRect().origin.x + rightChild->getRelativeRect().size.width < child->getRelativeRect().origin.x + child->getRelativeRect().size.width)
        {
            rightChild = child;
        }
        if (topChild->getRelativeRect().origin.y + topChild->getRelativeRect().size.height < child->getRelativeRect().origin.y + child->getRelativeRect().size.height)
        {
            topChild = child;
        }
        if (bottomChild->getRelativeRect().origin.y > child->getRelativeRect().origin.y){
            bottomChild = child;
        }
    }
    m_pTopChild = topChild;
    m_pBottomChild = bottomChild;
    m_pLeftChild = leftChild;
    m_pRightChild = rightChild;
}
예제 #3
0
void JSUI::HandleWidgetEvent(StringHash eventType, VariantMap& eventData)
{
    using namespace WidgetEvent;

    UIWidget* handler = static_cast<UIWidget*>(eventData[P_HANDLER].GetPtr());
    UIWidget* target = static_cast<UIWidget*>(eventData[P_TARGET].GetPtr());

    if (!handler)
        return;

    void* handlerHeapPtr = handler->JSGetHeapPtr();

    if (!handlerHeapPtr)
        return;

    // if we have a target, however no corresponding JS object return
    if (target && !target->JSGetHeapPtr())
        return;

    tb::EVENT_TYPE type = (tb::EVENT_TYPE) eventData[P_TYPE].GetUInt();

    if (type == tb::EVENT_TYPE_CHANGED)
    {
        int top = duk_get_top(ctx_);
        duk_push_heapptr(ctx_, handlerHeapPtr);
        duk_get_prop_string(ctx_, -1, "onChanged");
        if (duk_is_callable(ctx_, -1)) {

            if (duk_pcall(ctx_, 0) != 0)
            {
                JSVM::GetJSVM(nullptr)->SendJSErrorEvent();
            }
            else
            {
                if (duk_is_boolean(ctx_, -1) && duk_to_boolean(ctx_, -1))
                    eventData[P_HANDLED] = true;
            }
        }
        duk_pop_n(ctx_, 2);
        assert(top == duk_get_top(ctx_));
        return;

    }

    // general event handler, bubbles to (wrapped) parent widgets unless handled (returns true)
    if (type == tb::EVENT_TYPE_CLICK)
    {
        int top = duk_get_top(ctx_);
        duk_push_heapptr(ctx_, handlerHeapPtr);
        duk_get_prop_string(ctx_, -1, "onEvent");
        if (duk_is_callable(ctx_, -1)) {

            PushWidgetEventObject(eventData);

            duk_call(ctx_, 1);

            if (duk_is_boolean(ctx_, -1) && duk_to_boolean(ctx_, -1))
                eventData[P_HANDLED] = true;
        }
        duk_pop_n(ctx_, 2);
        assert(top == duk_get_top(ctx_));
    }

    // specific event handlers
    if (type == tb::EVENT_TYPE_CLICK)
    {
        int top = duk_get_top(ctx_);
        duk_push_heapptr(ctx_, handlerHeapPtr);
        duk_get_prop_string(ctx_, -1, "onClick");
        if (duk_is_callable(ctx_, -1)) {

            if (duk_pcall(ctx_, 0) != 0)
            {
                JSVM::GetJSVM(nullptr)->SendJSErrorEvent();
            }
            else
            {
                if (duk_is_boolean(ctx_, -1) && duk_to_boolean(ctx_, -1))
                    eventData[P_HANDLED] = true;
            }
        }
        duk_pop_n(ctx_, 2);
        assert(top == duk_get_top(ctx_));
        return;
    }

}
예제 #4
0
void HoleModeResult::init(void *data){
    m_tips = CCUIHELPER->createWidgetFromJsonFile("HoleModeResult.json");
    HoleModeResultParam* param = (HoleModeResultParam*)data;
    int _score = 0;
    int _topScore = G::g_hole_max_score;
    m_star = 0;
    int _coin = 0;
    m_rewards = NULL;
    m_currentdepth = 0;
    if (param) {
        _score = param->hole_score;
        m_currentdepth = param ->depth;
    }
    m_totaldepth = G::g_hole_total_depth;
    
    for (int i=0; i< maxunlimitscorescount; i++) {
        if (_score<unlimitrewardscores[i]) {
            break;
        }
        m_star++;
    }
    
    m_rewards= CCArray::create();
    switch (m_star) {
        case 4:
            m_rewards->addObject(new RewardInfo(t_getRandom(6)+2,1));
        case 3:
            m_rewards->addObject(new RewardInfo(t_getRandom(6)+2,1));
        case 2:
            _coin += 1000;;
        case 1:
            _coin += 1000;
            break;
        default:
            break;
    }
    
    UIWidget* label_noReward = m_tips->getChildByName("label_noReward");
    if (m_rewards->count() == 0) {
        label_noReward->setVisible(true);
    }
    UILabelAtlas* mScore = (UILabelAtlas*)m_tips->getChildByName("mScore");
    UILabelAtlas* mTopScore = (UILabelAtlas*)m_tips->getChildByName("mTopScore");
    UILabelAtlas* mCoin = (UILabelAtlas*)m_tips->getChildByName("mCoin");
    IntToString(_nScore, _score);
    IntToString(_nTopScore, _topScore);
    IntToString(_nCoin, _coin);
    mScore->setStringValue(_nScore);
    mTopScore->setStringValue(_nTopScore);
    mCoin->setStringValue(_nCoin);
    
    UIWidget* mScoreLabel = NULL;
    if (_score>_topScore) {
        mScoreLabel = m_tips->getChildByName("label_mScore_1");
        G::g_hole_max_score = _score;
    }else{
        mScoreLabel = m_tips->getChildByName("label_mScore_0");
    }
    if (mScoreLabel) {
        mScoreLabel->setVisible(true);
    }
    
    G::g_hole_total_depth = m_currentdepth+m_totaldepth;
    
    G::G_getReward(0,_coin);
    
    G::G_getRewards(m_rewards);
    
    HPersistence::S()->SaveToFile();
    CC_SAFE_DELETE(param);
}
예제 #5
0
void GameEndBuy::update(float dt){
    UIWidget* mCoin = m_tips->getChildByName("mCoin");
    UILabelBMFont* coin_num = (UILabelBMFont*)mCoin->getChildByName("num");
    IntToString(_coin, G::G_getCoin());
    coin_num->setText(_coin);
}
예제 #6
0
void JSUI::PushWidgetEventObject(VariantMap& eventData)
{

    UI* ui = GetSubsystem<UI>();

    using namespace WidgetEvent;

    // create the event object
    duk_push_object(ctx_);

    // target
    UIWidget* target = static_cast<UIWidget*>(eventData[P_TARGET].GetPtr());

    if (target)
    {
        assert(target->JSGetHeapPtr());
        duk_push_heapptr(ctx_, target->JSGetHeapPtr());
    }
    else
    {
        duk_push_null(ctx_);
    }

    duk_put_prop_string(ctx_, -2, "target");

    duk_push_number(ctx_, (duk_double_t) eventData[P_TYPE].GetUInt());
    duk_put_prop_string(ctx_, -2, "type");

    duk_push_number(ctx_, (duk_double_t) eventData[P_X].GetInt());
    duk_put_prop_string(ctx_, -2, "x");

    duk_push_number(ctx_, (duk_double_t) eventData[P_Y].GetInt());
    duk_put_prop_string(ctx_, -2, "y");

    duk_push_number(ctx_, (duk_double_t) eventData[P_DELTAX].GetInt());
    duk_put_prop_string(ctx_, -2, "deltaX");

    duk_push_number(ctx_, (duk_double_t) eventData[P_DELTAX].GetInt());
    duk_put_prop_string(ctx_, -2, "deltaY");

    duk_push_number(ctx_, (duk_double_t) eventData[P_COUNT].GetInt());
    duk_put_prop_string(ctx_, -2, "count");

    duk_push_number(ctx_, (duk_double_t) eventData[P_KEY].GetInt());
    duk_put_prop_string(ctx_, -2, "key");

    duk_push_number(ctx_, (duk_double_t) eventData[P_SPECIALKEY].GetInt());
    duk_put_prop_string(ctx_, -2, "specialKey");

    duk_push_number(ctx_, (duk_double_t) eventData[P_MODIFIERKEYS].GetInt());
    duk_put_prop_string(ctx_, -2, "modifierKeys");

    duk_push_number(ctx_, (duk_double_t) eventData[P_MODIFIERKEYS].GetInt());
    duk_put_prop_string(ctx_, -2, "modifierKeys");

    String id;
    unsigned blah = eventData[P_REFID].GetUInt();
    ui->GetTBIDString(eventData[P_REFID].GetUInt(), id);
    duk_push_string(ctx_, id.CString() );
    duk_put_prop_string(ctx_, -2, "refID");

    duk_push_boolean(ctx_,eventData[P_TOUCH].GetBool() ? 1 : 0);
    duk_put_prop_string(ctx_, -2, "touch");

}
예제 #7
0
bool SelectMenuView::init()
{
	char tmp[32];
	UILayer::init();

	// background
	UIImageView* background = UIImageView::create();
	background->loadTexture("level_bg.jpg",UI_TEX_TYPE_PLIST);
	background->setAnchorPoint(CCPoint(0,0));
	this->addWidget(background);

	// Beauty Card
	UIPageView* scrollView = UIPageView::create();
	scrollView->setTouchEnabled(true);
	scrollView->setSize( CCSize( GAME_WIDTH, GAME_HEIGHT * 3 / 4 ) );
	scrollView->setPosition(CCPoint( 0, GAME_HEIGHT/8 ));
	scrollView->setName("scrollView");

	UILayout* widgetBeautyCard = (UILayout*)GUIReader::shareReader()->widgetFromJsonFile("BeautyCard.ExportJson");

	for( int i = 0; i < MAX_BEAUTY_NUM; i++ )
	{
		Layout* layout = Layout::create();
		layout->setSize(CCSize(GAME_WIDTH, GAME_HEIGHT * 3 / 4));

		ScrollButton* button = ScrollButton::create();
		button->setSize(CCSize(160,200));

		UILayout* widget = NULL;
		if(i == 0)
		{
			widget = widgetBeautyCard;
		}
		else
		{
			widget =  static_cast<UILayout*>(widgetBeautyCard->clone());
		}

		widget->setAnchorPoint(CCPoint( 0.5f, 0.5f));
		button->setPosition(CCPoint(GAME_WIDTH/2,GAME_HEIGHT* 3 / 8));
		sprintf(tmp,"beautyCard%d",i);
		button->setName(tmp);
		//widget->setPosition( Point( GAME_WIDTH * i, 0 ) );
		button->setTag( i + CARD_TAG );

		button->addChild(widget);
		layout->addChild( button );
		scrollView->addPage( layout );
	}

	//CC_SAFE_DELETE(widgetTree);
	//CC_SAFE_DELETE(jsonDict);
	//CC_SAFE_DELETE_ARRAY(des);

	scrollView->addEventListener(this, pagevieweventselector(SelectMenuView::onPageViewMove));
	this->addWidget( scrollView );
	
	// bottom 
	UIWidget* bottomWidget = (UIWidget*)GUIReader::shareReader()->widgetFromJsonFile("SelectUI.ExportJson");
	bottomWidget->setName("bottomUIWidget");
	this->addWidget( bottomWidget );

	// buttton
	UIButton* button_back = static_cast<UIButton*>( bottomWidget->getChildByName("Button_back") );
	UIButton* button_seal = static_cast<UIButton*>( bottomWidget->getChildByName("Button_seal") );
	button_back->addTouchEventListener(this,toucheventselector(SelectMenuView::onTouchButton));
	button_back->setTouchEnabled(true);
	button_back->setPressedActionEnabled(true);
	button_seal->addTouchEventListener(this,toucheventselector(SelectMenuView::onTouchButton));
	button_seal->setTouchEnabled(true);
	button_seal->setPressedActionEnabled(true);

	// Evil Mask panel
	_panelEvil = (UIWidget*)GUIReader::shareReader()->widgetFromJsonFile("PanelEvil.ExportJson");
	_panelEvil->retain();

	// unlock panel
	_panelUnlock = (UIWidget*)GUIReader::shareReader()->widgetFromJsonFile("PanelSelectLock.ExportJson");
	_panelUnlock->retain();

	return true;
}
예제 #8
0
void StageSelectScene::DoClickStage(CCObject* sender)
{
	UIWidget* pBut = (UIWidget*)sender;
	StageWaitScene::SetSceneVal(scene_daily,pBut->getTag());
	KUIAssist::_switch2StageWaitScene();
}
예제 #9
0
UIWidget* UI::WrapWidget(tb::TBWidget* widget)
{
    if (!widget)
        return NULL;

    if (widgetWrap_.Contains(widget))
        return widgetWrap_[widget];

    // switch this to use a factory?

    // this is order dependent as we're using IsOfType which also works if a base class

    if (widget->IsOfType<TBPopupWindow>())
    {
        UIPopupWindow* popupWindow = new UIPopupWindow(context_, false);
        popupWindow->SetWidget(widget);
        widgetWrap_[widget] = popupWindow;
        return popupWindow;
    }

    if (widget->IsOfType<TBDimmer>())
    {
        UIDimmer* dimmer = new UIDimmer(context_, false);
        dimmer->SetWidget(widget);
        widgetWrap_[widget] = dimmer;
        return dimmer;
    }

    if (widget->IsOfType<TBScrollContainer>())
    {
        UIScrollContainer* container = new UIScrollContainer(context_, false);
        container->SetWidget(widget);
        widgetWrap_[widget] = container;
        return container;
    }

    if (widget->IsOfType<TBInlineSelect>())
    {
        UIInlineSelect* select = new UIInlineSelect(context_, false);
        select->SetWidget(widget);
        widgetWrap_[widget] = select;
        return select;
    }

    if (widget->IsOfType<TBSection>())
    {
        UISection* section = new UISection(context_, false);
        section->SetWidget(widget);
        widgetWrap_[widget] = section;
        return section;
    }

    if (widget->IsOfType<TBSeparator>())
    {
        UISeparator* sep = new UISeparator(context_, false);
        sep->SetWidget(widget);
        widgetWrap_[widget] = sep;
        return sep;
    }

    if (widget->IsOfType<TBContainer>())
    {
        UIContainer* container = new UIContainer(context_, false);
        container->SetWidget(widget);
        widgetWrap_[widget] = container;
        return container;
    }

    if (widget->IsOfType<TBSelectDropdown>())
    {
        UISelectDropdown* select = new UISelectDropdown(context_, false);
        select->SetWidget(widget);
        widgetWrap_[widget] = select;
        return select;
    }

    if (widget->IsOfType<TBButton>())
    {
        // don't wrap the close button of a TBWindow.close
        if (widget->GetID() == TBIDC("TBWindow.close"))
            return 0;

        UIButton* button = new UIButton(context_, false);
        button->SetWidget(widget);
        widgetWrap_[widget] = button;
        return button;
    }

    if (widget->IsOfType<TBTextField>())
    {
        UITextField* textfield = new UITextField(context_, false);
        textfield->SetWidget(widget);
        widgetWrap_[widget] = textfield;
        return textfield;
    }

    if (widget->IsOfType<TBEditField>())
    {
        UIEditField* editfield = new UIEditField(context_, false);
        editfield->SetWidget(widget);
        widgetWrap_[widget] = editfield;
        return editfield;
    }

    if (widget->IsOfType<TBSkinImage>())
    {
        UISkinImage* skinimage = new UISkinImage(context_, "", false);
        skinimage->SetWidget(widget);
        widgetWrap_[widget] = skinimage;
        return skinimage;
    }

    if (widget->IsOfType<TBImageWidget>())
    {
        UIImageWidget* imagewidget = new UIImageWidget(context_, false);
        imagewidget->SetWidget(widget);
        widgetWrap_[widget] = imagewidget;
        return imagewidget;
    }
    if (widget->IsOfType<TBClickLabel>())
    {
        UIClickLabel* nwidget = new UIClickLabel(context_, false);
        nwidget->SetWidget(widget);
        widgetWrap_[widget] = nwidget;
        return nwidget;
    }

    if (widget->IsOfType<TBCheckBox>())
    {
        UICheckBox* nwidget = new UICheckBox(context_, false);
        nwidget->SetWidget(widget);
        widgetWrap_[widget] = nwidget;
        return nwidget;
    }

    if (widget->IsOfType<TBSelectList>())
    {
        UISelectList* nwidget = new UISelectList(context_, false);
        nwidget->SetWidget(widget);
        widgetWrap_[widget] = nwidget;
        return nwidget;
    }

    if (widget->IsOfType<TBMessageWindow>())
    {
        UIMessageWindow* nwidget = new UIMessageWindow(context_, NULL, "", false);
        nwidget->SetWidget(widget);
        widgetWrap_[widget] = nwidget;
        return nwidget;
    }

    if (widget->IsOfType<TBTabContainer>())
    {
        UITabContainer* nwidget = new UITabContainer(context_, false);
        nwidget->SetWidget(widget);
        widgetWrap_[widget] = nwidget;
        return nwidget;
    }

    if (widget->IsOfType<SceneViewWidget>())
    {
        UISceneView* nwidget = new UISceneView(context_, false);
        nwidget->SetWidget(widget);
        widgetWrap_[widget] = nwidget;
        return nwidget;
    }


    if (widget->IsOfType<TBLayout>())
    {
        UILayout* layout = new UILayout(context_, (UI_AXIS) widget->GetAxis(), false);
        layout->SetWidget(widget);
        widgetWrap_[widget] = layout;
        return layout;
    }

    if (widget->IsOfType<TBWidget>())
    {
        UIWidget* nwidget = new UIWidget(context_, false);
        nwidget->SetWidget(widget);
        widgetWrap_[widget] = nwidget;
        return nwidget;
    }


    return 0;
}
예제 #10
0
void SelectMenuView::noticeView(SelectMenuModel* model)
{
#pragma region RESET_SCROLL_RECT
	char tmp[32];
	UIPageView* scrollView = static_cast<UIPageView*>(this->getWidgetByName("scrollView"));
	for( int i = 0; i < MAX_BEAUTY_NUM; i++ )
	{
		UIWidget* widget = scrollView->getChildByTag( i + CARD_TAG );
		widget->addTouchEventListener(this , toucheventselector(SelectMenuView::onTouchBeautyCard));
		//UIImageView* card_bg = static_cast<UIImageView*>(widget->getChildByName("card_bg"));
		//card_bg->setTouchEnabled(true);
		//card_bg->addTouchEventListener(this , toucheventselector(SelectMenuView::touchBeautyCard));

		UILabelBMFont* nameTxt = static_cast<UILabelBMFont*>(widget->getChildByName("txt_name"));
		UILabelBMFont* timeTxt = static_cast<UILabelBMFont*>(widget->getChildByName("txt_time"));
		UIImageView* beautyHead = static_cast<UIImageView*>(widget->getChildByName("head"));
		UIImageView* beContinue = static_cast<UIImageView*>(widget->getChildByName("moreLevel"));
		UIImageView* passRibbon = static_cast<UIImageView*>(widget->getChildByName("lock"));
		UIImageView* hearts[MAX_HEART];
		UIImageView* stars[MAX_STAR];
		for( int n = 0; n < MAX_HEART; n++ )
		{
			sprintf( tmp, "heart%d",n+1 );
			hearts[n] = static_cast<UIImageView*>(widget->getChildByName(tmp));
			hearts[n]->setVisible(false);
			sprintf( tmp, "star%d",n+1 );
			stars[n] = static_cast<UIImageView*>(widget->getChildByName(tmp));
			stars[n]->setVisible(false);
		}

		if( i < REAL_BEAUTY_NUM )
		{
			BeautyData data = model->getBeautyData(i);
			// --------------------------- Setting ---------------------------
			//if( i < REAL_BEAUTY_NUM )
			//{
				sprintf( tmp , "head_%d.png" , i);
				beautyHead->loadTexture(tmp ,UI_TEX_TYPE_PLIST);
			//}
			nameTxt->setText( data.name );
			if(data.time>9) sprintf( tmp,"%d:00", data.time );
			else sprintf( tmp,"0%d:00", data.time );
			timeTxt->setVisible(true);
			timeTxt->setText(tmp);
			for ( int n = 0; n < MAX_STAR; n++ )
			{
				if( n < data.difficult ) stars[n]->setVisible(true);
				else stars[n]->setVisible(false);
			}
			int heartNum = model->getUserGainHeartNum(i);
			for ( int n = 0; n < MAX_HEART; n++ )
			{
				if( n < heartNum ) hearts[n]->setVisible(true);
				else hearts[n]->setVisible(false);
			}
			beContinue->setVisible(false);
			if(heartNum < 0)
			{// not pass && close
				passRibbon->setVisible(true);
			}
			else
			{// pass || open
				passRibbon->setVisible(false);
			}
		}
		/////////////
		else
		{
			if(i == MAX_BEAUTY_NUM - 1 )
			{
				beContinue->setVisible(true);
				beautyHead->loadTexture("head_9.png" ,UI_TEX_TYPE_PLIST);
			}
			else
			{
				sprintf( tmp , "head_%d.png" , i);
				beautyHead->loadTexture(tmp ,UI_TEX_TYPE_PLIST);
			}
			nameTxt->setText( "???????????" );
			timeTxt->setText("--:--");
			passRibbon->setVisible(false);
		}
	}
#pragma endregion
}
예제 #11
0
void UIDragDrop::HandleMouseMove(StringHash eventType, VariantMap& eventData)
{
    if (dragObject_.Null() && dragSourceWidget_.Null())
        return;

    if (dragObject_.Null())
    {
        dragObject_ = dragSourceWidget_->GetDragObject();

        if (dragObject_.Null())
        {
            dragSourceWidget_ = 0;
            return;
        }

    }

    using namespace MouseMove;

    int x = eventData[P_X].GetInt();
    int y = eventData[P_Y].GetInt();

    // tolerance to 8 pixels to start drag/drop operation
    IntVector2 mousePos(x, y);
    mousePos -= mouseDownPosition_;
    if (Abs(mousePos.x_) < 8 && Abs(mousePos.y_) < 8)
        return;

    // initialize if necessary
    if (dragLayout_->GetVisibility() == UI_WIDGET_VISIBILITY_GONE)
    {
        dragLayout_->GetInternalWidget()->SetZ(WIDGET_Z_TOP);
        dragLayout_->SetVisibility(UI_WIDGET_VISIBILITY_VISIBLE);
        dragText_->SetText(dragObject_->GetText());

        UIPreferredSize* sz = dragLayout_->GetPreferredSize();
        dragLayout_->SetRect(IntRect(0, 0, sz->GetMinWidth(), sz->GetMinHeight()));
    }

    // see if we have a widget
    TBWidget* tbw = TBWidget::hovered_widget;

    while(tbw && (!tbw->GetDelegate() || tbw->IsOfType<TBLayout>()))
    {
        tbw = tbw->GetParent();
    }

    if (!tbw || !tbw->GetParent())
        return;

    UIWidget* hoverWidget = (UIWidget*) tbw->GetDelegate();

    if (!hoverWidget->GetInternalWidget())
        return;

    if (hoverWidget != currentTargetWidget_)
    {
        if (currentTargetWidget_)
        {
            VariantMap exitData;
            exitData[DragExitWidget::P_WIDGET] = currentTargetWidget_;
            exitData[DragExitWidget::P_DRAGOBJECT] = dragObject_;
            currentTargetWidget_->SendEvent(E_DRAGEXITWIDGET, exitData);
        }

        currentTargetWidget_ = hoverWidget;

        VariantMap enterData;
        enterData[DragEnterWidget::P_WIDGET] = currentTargetWidget_;
        enterData[DragEnterWidget::P_DRAGOBJECT] = dragObject_;
        currentTargetWidget_->SendEvent(E_DRAGENTERWIDGET, enterData);

    }

    dragLayout_->SetPosition(x, y - 20);

}
예제 #12
0
UIWidget* UI::WrapWidget(tb::TBWidget* widget)
{
    if (!widget)
        return NULL;

    if (widgetWrap_.Contains(widget))
        return widgetWrap_[widget];

    // switch this to use a factory?

    // this is order dependent as we're using IsOfType which also works if a base class

    if (widget->IsOfType<TBPopupWindow>())
    {
        UIPopupWindow* popupWindow = new UIPopupWindow(context_, false);
        popupWindow->SetWidget(widget);
        WrapWidget(popupWindow, widget);
        return popupWindow;
    }

    if (widget->IsOfType<TBDimmer>())
    {
        UIDimmer* dimmer = new UIDimmer(context_, false);
        dimmer->SetWidget(widget);
        WrapWidget(dimmer, widget);
        return dimmer;
    }

    if (widget->IsOfType<TBScrollContainer>())
    {
        UIScrollContainer* container = new UIScrollContainer(context_, false);
        container->SetWidget(widget);
        WrapWidget(container, widget);
        return container;
    }

    if (widget->IsOfType<TBInlineSelect>())
    {
        UIInlineSelect* select = new UIInlineSelect(context_, false);
        select->SetWidget(widget);
        WrapWidget(select, widget);
        return select;
    }

    if (widget->IsOfType<TBSlider>())
    {
        UISlider* slider = new UISlider(context_, false);
        slider->SetWidget(widget);
        WrapWidget(slider, widget);
        return slider;
    }

    if (widget->IsOfType<TBScrollBar>())
    {
        UIScrollBar* slider = new UIScrollBar(context_, false);
        slider->SetWidget(widget);
        WrapWidget(slider, widget);
        return slider;
    }

    if (widget->IsOfType<TBColorWidget>())
    {
        UIColorWidget* colorWidget = new UIColorWidget(context_, false);
        colorWidget->SetWidget(widget);
        WrapWidget(colorWidget, widget);
        return colorWidget;
    }

    if (widget->IsOfType<TBColorWheel>())
    {
        UIColorWheel* colorWheel = new UIColorWheel(context_, false);
        colorWheel->SetWidget(widget);
        WrapWidget(colorWheel, widget);
        return colorWheel;
    }

    if (widget->IsOfType<TBSection>())
    {
        UISection* section = new UISection(context_, false);
        section->SetWidget(widget);
        WrapWidget(section, widget);
        return section;
    }

    if (widget->IsOfType<TBSeparator>())
    {
        UISeparator* sep = new UISeparator(context_, false);
        sep->SetWidget(widget);
        WrapWidget(sep, widget);
        return sep;
    }

    if (widget->IsOfType<TBContainer>())
    {
        UIContainer* container = new UIContainer(context_, false);
        container->SetWidget(widget);
        WrapWidget(container, widget);
        return container;
    }

    if (widget->IsOfType<TBSelectDropdown>())
    {
        UISelectDropdown* select = new UISelectDropdown(context_, false);
        select->SetWidget(widget);
        WrapWidget(select, widget);
        return select;
    }

    if (widget->IsOfType<TBPulldownMenu>())
    {
        UIPulldownMenu* select = new UIPulldownMenu(context_, false);
        select->SetWidget(widget);
        WrapWidget(select, widget);
        return select;
    }

    if (widget->IsOfType<TBButton>())
    {
        // don't wrap the close button of a TBWindow.close
        if (widget->GetID() == TBIDC("TBWindow.close"))
            return 0;

        UIButton* button = new UIButton(context_, false);
        button->SetWidget(widget);
        WrapWidget(button, widget);
        return button;
    }

    if (widget->IsOfType<TBTextField>())
    {
        UITextField* textfield = new UITextField(context_, false);
        textfield->SetWidget(widget);
        WrapWidget(textfield, widget);
        return textfield;
    }

    if (widget->IsOfType<TBEditField>())
    {
        UIEditField* editfield = new UIEditField(context_, false);
        editfield->SetWidget(widget);
        WrapWidget(editfield, widget);
        return editfield;
    }

    if (widget->IsOfType<TBSkinImage>())
    {
        UISkinImage* skinimage = new UISkinImage(context_, "", false);
        skinimage->SetWidget(widget);
        WrapWidget(skinimage, widget);
        return skinimage;
    }

    if (widget->IsOfType<TBImageWidget>())
    {
        UIImageWidget* imagewidget = new UIImageWidget(context_, false);
        imagewidget->SetWidget(widget);
        WrapWidget(imagewidget, widget);
        return imagewidget;
    }
    if (widget->IsOfType<TBClickLabel>())
    {
        UIClickLabel* nwidget = new UIClickLabel(context_, false);
        nwidget->SetWidget(widget);
        WrapWidget(nwidget, widget);
        return nwidget;
    }

    if (widget->IsOfType<TBCheckBox>())
    {
        UICheckBox* nwidget = new UICheckBox(context_, false);
        nwidget->SetWidget(widget);
        WrapWidget(nwidget, widget);
        return nwidget;
    }

    if (widget->IsOfType<TBRadioButton>())
    {
        UIRadioButton* nwidget = new UIRadioButton(context_, false);
        nwidget->SetWidget(widget);
        WrapWidget(nwidget, widget);
        return nwidget;
    }

    if (widget->IsOfType<TBBarGraph>())
    {
        UIBargraph* nwidget = new UIBargraph(context_, false);
        nwidget->SetWidget(widget);
        WrapWidget(nwidget, widget);
        return nwidget;
    }

    if (widget->IsOfType<TBSelectList>())
    {
        UISelectList* nwidget = new UISelectList(context_, false);
        nwidget->SetWidget(widget);
        WrapWidget(nwidget, widget);
        return nwidget;
    }

    if (widget->IsOfType<TBMessageWindow>())
    {
        UIMessageWindow* nwidget = new UIMessageWindow(context_, NULL, "", false);
        nwidget->SetWidget(widget);
        WrapWidget(nwidget, widget);
        return nwidget;
    }

    if (widget->IsOfType<TBPromptWindow>())
    {
        UIPromptWindow* nwidget = new UIPromptWindow(context_, NULL, "", false);
        nwidget->SetWidget(widget);
        WrapWidget(nwidget, widget);
        return nwidget;
    }

    if (widget->IsOfType<TBFinderWindow>())
    {
        UIFinderWindow* nwidget = new UIFinderWindow(context_, NULL, "", false);
        nwidget->SetWidget(widget);
        WrapWidget(nwidget, widget);
        return nwidget;
    }

    if (widget->IsOfType<TBTabContainer>())
    {
        UITabContainer* nwidget = new UITabContainer(context_, false);
        nwidget->SetWidget(widget);
        WrapWidget(nwidget, widget);
        return nwidget;
    }

    if (widget->IsOfType<SceneViewWidget>())
    {
        UISceneView* nwidget = new UISceneView(context_, false);
        nwidget->SetWidget(widget);
        WrapWidget(nwidget, widget);
        return nwidget;
    }


    if (widget->IsOfType<TBLayout>())
    {
        UILayout* layout = new UILayout(context_, (UI_AXIS) widget->GetAxis(), false);
        layout->SetWidget(widget);
        WrapWidget(layout, widget);
        return layout;
    }

    if (widget->IsOfType<TBWidget>())
    {
        UIWidget* nwidget = new UIWidget(context_, false);
        nwidget->SetWidget(widget);
        WrapWidget(nwidget, widget);
        return nwidget;
    }


    return 0;
}
예제 #13
0
void UIListView::setLoopPosition()
{
    switch (m_eDirection)
    {
        case LISTVIEW_DIR_VERTICAL: // vertical
            switch (m_eMoveDirection)
            {
                case LISTVIEW_MOVE_DIR_UP: // up
                {
                    ccArray* arrayChildren = m_children->data;
                    unsigned int childrenCount = arrayChildren->num;
                    
                    if (m_overTopArray->count() == childrenCount)
                    {
                        unsigned int count = childrenCount;
                        for (unsigned int i = 0; i < count; ++i)
                        {   
                            UIWidget* child = dynamic_cast<UIWidget*>(m_overTopArray->objectAtIndex(i));
                            
                            if (i == 0)
                            {
                                float height = child->getSize().height;
                                float offset = (child->getWidgetType() == WidgetTypeWidget) ? height / 2 : height;
                                float y = m_fTopBoundary - m_fDisBoundaryToChild_0 - offset;
                                child->setPosition(ccp(child->getPosition().x, y));
                            }
                            else
                            {
                                UIWidget* prev_child = dynamic_cast<UIWidget*>(m_overTopArray->objectAtIndex(i - 1));
                                child->setPosition(ccp(child->getPosition().x, prev_child->getPosition().y - m_fDisBetweenChild));
                            }
                        }
                    }
                    else
                    {
                        float scroll_top = m_fTopBoundary;
                        
                        ccArray* arrayChildren = m_children->data;
                        int count = arrayChildren->num;
                        for (int i = 0; i < count; ++i)
                        {
                            UIWidget* child = dynamic_cast<UIWidget*>(arrayChildren->arr[i]);
                            float child_bottom = child->getBottomInParent();
                            
                            if (child_bottom >= scroll_top)
                            {
                                int index = (i == 0) ? (count - 1) : (i - 1);
                                UIWidget* prev_child = dynamic_cast<UIWidget*>(arrayChildren->arr[index]);
                                child->setPosition(ccp(child->getPosition().x, prev_child->getPosition().y - m_fDisBetweenChild));
                            }
                        }
                    }
                }
                    break;
                    
                case LISTVIEW_MOVE_DIR_DOWN: // down
                {
                    ccArray* arrayChildren = m_children->data;
                    unsigned int childrenCount = arrayChildren->num;
                    
                    if (m_overBottomArray->count() == childrenCount)
                    {
                        unsigned int count = childrenCount;
                        for (unsigned int i = 0; i < count; ++i)
                        {
                            UIWidget* child = dynamic_cast<UIWidget*>(m_overBottomArray->objectAtIndex(i));
                            
                            if (i == 0)
                            {                                
                                float y = m_fBottomBoundary + m_fDisBoundaryToChild_0 - m_fDisBetweenChild;
                                child->setPosition(ccp(child->getPosition().x, y));
                            }
                            else
                            {
                                UIWidget* prev_child = dynamic_cast<UIWidget*>(m_overBottomArray->objectAtIndex(i - 1));
                                child->setPosition(ccp(child->getPosition().x, prev_child->getPosition().y + m_fDisBetweenChild));                                    
                            }
                        }
                    }
                    else
                    {
                        float scroll_bottom = m_fBottomBoundary;
                        
                        ccArray* arrayChildren = m_children->data;
                        int count = arrayChildren->num;
                        for (int i = count - 1; i >= 0; --i)
                        {
                            UIWidget* child = dynamic_cast<UIWidget*>(arrayChildren->arr[i]);
                            float child_top = child->getTopInParent();
                            
                            if (child_top <= scroll_bottom)
                            {
                                int index = (i == count - 1) ? 0 : (i + 1);
                                UIWidget* next_child = dynamic_cast<UIWidget*>(arrayChildren->arr[index]);
                                child->setPosition(ccp(child->getPosition().x, next_child->getPosition().y + m_fDisBetweenChild));                                    
                            }
                        }
                    }
                }
                    break;
                    
                default:
                    break;
            }
            break;
            
        case LISTVIEW_DIR_HORIZONTAL: // horizontal
            switch (m_eMoveDirection)
            {
                case LISTVIEW_MOVE_DIR_LEFT: // left
                {
                    ccArray* arrayChildren = m_children->data;
                    unsigned int childrenCount = arrayChildren->num;
                    
                    if (m_overLeftArray->count() == childrenCount)
                    {
                        unsigned int count = childrenCount;
                        for (unsigned int i = 0; i < count; ++i)
                        {
                            UIWidget* child = dynamic_cast<UIWidget*>(m_overLeftArray->objectAtIndex(i));
                            
                            if (i == 0)
                            {
                                float width = child->getSize().width;
                                float offset = (child->getWidgetType() == WidgetTypeWidget) ? (width / 2) : 0;                                
                                float x = m_fLeftBoundary + m_fDisBoundaryToChild_0 + width + offset;
                                child->setPosition(ccp(x, child->getPosition().y));
                            }
                            else
                            {
                                UIWidget* prev_child = dynamic_cast<UIWidget*>(m_overLeftArray->objectAtIndex(i - 1));
                                child->setPosition(ccp(prev_child->getPosition().x + m_fDisBetweenChild, child->getPosition().y));                                    
                            }
                        }
                    }
                    else
                    {
                        float scroll_left = m_fLeftBoundary;
                        
                        ccArray* arrayChildren = m_children->data;
                        int count = arrayChildren->num;
                        for (int i = 0; i < count; ++i)
                        {
                            UIWidget* child = dynamic_cast<UIWidget*>(arrayChildren->arr[i]);
                            float child_right = child->getRightInParent();
                            
                            if (child_right <= scroll_left)
                            {
                                int index = (i == 0) ? (count - 1) : (i - 1);
                                UIWidget* prev_child = dynamic_cast<UIWidget*>(arrayChildren->arr[index]);
                                child->setPosition(ccp(prev_child->getPosition().x + m_fDisBetweenChild, child->getPosition().y));
                            }
                        }
                    }
                }
                    break;
                    
                case LISTVIEW_MOVE_DIR_RIGHT: // right
                {
                    ccArray* arrayChildren = m_children->data;
                    unsigned int childrenCount = arrayChildren->num;
                    
                    if (m_overRightArray->count() == childrenCount)
                    {
                        unsigned int count = childrenCount;
                        for (unsigned int i = 0; i < count; ++i)
                        {
                            UIWidget* child = dynamic_cast<UIWidget*>(m_overRightArray->objectAtIndex(i));
                            
                            if (i == 0)
                            {
                                float x = m_fRightBoundary - m_fDisBoundaryToChild_0 + m_fDisBetweenChild;
                                child->setPosition(ccp(x, child->getPosition().y));
                            }
                            else
                            {
                                UIWidget* prev_child = dynamic_cast<UIWidget*>(m_overRightArray->objectAtIndex(i - 1));
                                child->setPosition(ccp(prev_child->getPosition().x - m_fDisBetweenChild, child->getPosition().y));                                                                
                            }
                        }
                    }
                    else
                    {
                        float scroll_right = m_fRightBoundary;
                        
                        ccArray* arrayChildren = m_children->data;
                        int count = arrayChildren->num;
                        for (int i = count - 1; i >= 0; --i)
                        {
                            UIWidget* child = dynamic_cast<UIWidget*>(arrayChildren->arr[i]);
                            float child_left = child->getLeftInParent();
                            
                            if (child_left >= scroll_right)
                            {
                                int index = (i == count - 1) ? 0 : (i + 1);
                                UIWidget* next_child = dynamic_cast<UIWidget*>(arrayChildren->arr[index]);
                                child->setPosition(ccp(next_child->getPosition().x - m_fDisBetweenChild, child->getPosition().y));
                            }
                        }
                    }
                }
                    break;
                    
                default:
                    break;
            }
            break;
            
        default:
            break;
    }
}
float UIScrollView::calculateOffsetWithDragForce(float moveOffset)
{
    float offset = moveOffset;
    UIWidget* child = getCheckPositionChild();
    
    switch (m_eDirection)
    {
        case SCROLLVIEW_DIR_VERTICAL: // vertical
            switch (m_eMoveDirection)
            {
                case SCROLLVIEW_MOVE_DIR_UP: // up
                    {
                        float scroll_bottom = m_fBottomBoundary;
                        float child_bottom = child->getRelativeBottomPos();
                        
                        if (child_bottom > scroll_bottom)
                        {
                            offset -= m_fDragForce * offset / m_fHeight;
                        }
                    }
                    break;
                    
                case SCROLLVIEW_MOVE_DIR_DOWN: // down
                    {
                        float scroll_top = m_fTopBoundary;
                        float child_top = child->getRelativeTopPos();
                        
                        if (child_top < scroll_top)
                        {
                            offset -= m_fDragForce * offset / m_fHeight;
                        }
                    }
                    break;
                    
                default:
                    break;
            }
            break;
            
        case SCROLLVIEW_DIR_HORIZONTAL: // horizontal
            switch (m_eMoveDirection)
            {
                case SCROLLVIEW_MOVE_DIR_LEFT: // left
                    {
                        float scroll_right = m_fRightBoundary;
                        float child_right = child->getRelativeRightPos();
                        
                        if (child_right < scroll_right)
                        {
                            offset -= m_fDragForce * offset / m_fWidth;
                        }
                    }
                    break;
                    
                case SCROLLVIEW_MOVE_DIR_RIGHT: // right
                    {
                        float scroll_left = m_fLeftBoundary;
                        float child_left = child->getRelativeLeftPos();
                        
                        if (child_left > scroll_left)
                        {
                            offset -= m_fDragForce * offset / m_fWidth;
                        }
                    }
                    break;
                    
                default:
                    break;
            }
            break;
            
        default:
            break;
    }
    
    offset = MIN(offset, m_fDisBetweenChild);
    
    return offset;
}
예제 #15
0
bool UIDirect3D9Window::event(QEvent *Event)
{
    int type = Event->type();

    if (type == QEvent::KeyPress || type == QEvent::KeyRelease)
    {
        QKeyEvent *keyevent = static_cast<QKeyEvent*>(Event);

        if (keyevent)
        {
            keyevent->accept();
            UIWidget* focuswidget = m_theme ? m_theme->GetFocusWidget() : NULL;

            if (focuswidget && focuswidget->Type() == UITextEditor::kUITextEditorType)
            {
                UITextEditor *texteditor = static_cast<UITextEditor*>(focuswidget);
                if (texteditor && texteditor->HandleTextInput(keyevent))
                    return true;
            }

            int action = GetActionFromKey(keyevent);

            if (action && focuswidget)
            {
                if (focuswidget->HandleAction(action))
                    return true;
            }

            switch (action)
            {
                case Torc::Escape:
                    close();
                    return true;
                case Torc::Suspend:
                    gPower->Suspend();
                    return true;
                case Torc::DisableStudioLevels:
                    SetStudioLevels(false);
                    break;
                case Torc::EnableStudioLevels:
                    SetStudioLevels(true);
                    break;
                case Torc::ToggleStudioLevels:
                    SetStudioLevels(!m_studioLevels);
                    break;
                default: break;
            }
        }
    }
    else if (type == QEvent::Timer)
    {
        QTimerEvent *timerevent = dynamic_cast<QTimerEvent*>(Event);

        if (timerevent && timerevent->timerId() == m_mainTimer)
        {
            MainLoop();
            return true;
        }
    }
    else if (type == QEvent::Paint)
    {
        return true;
    }

    return QWidget::event(Event);
}
예제 #16
0
void UILayout::doLayout()
{
    switch (m_eLayoutType)
    {
        case LAYOUT_ABSOLUTE:
            break;
        case LAYOUT_LINEAR_VERTICAL:
        {
            ccArray* layoutChildrenArray = getChildren()->data;
            int length = layoutChildrenArray->num;
            CCSize layoutSize = getSize();
            float topBoundary = layoutSize.height;
            for (int i=0; i<length; ++i)
            {
                UIWidget* child = dynamic_cast<UIWidget*>(layoutChildrenArray->arr[i]);
                UILinearLayoutParameter* layoutParameter = dynamic_cast<UILinearLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR));
                
                if (layoutParameter)
                {
                    UILinearGravity childGravity = layoutParameter->getGravity();
                    CCPoint ap = child->getAnchorPoint();
                    CCSize cs = child->getSize();
                    float finalPosX = ap.x * cs.width;
                    float finalPosY = topBoundary - ((1.0f-ap.y) * cs.height);
                    switch (childGravity)
                    {
                        case LINEAR_GRAVITY_NONE:
                        case LINEAR_GRAVITY_LEFT:
                            break;
                        case LINEAR_GRAVITY_RIGHT:
                            finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width);
                            break;
                        case LINEAR_GRAVITY_CENTER_HORIZONTAL:
                            finalPosX = layoutSize.width / 2.0f - cs.width * (0.5f-ap.x);
                            break;
                        default:
                            break;
                    }
                    UIMargin mg = layoutParameter->getMargin();
                    finalPosX += mg.left;
                    finalPosY -= mg.top;
                    child->setPosition(ccp(finalPosX, finalPosY));
                    topBoundary = child->getBottomInParent() - mg.bottom;
                }
            }
            break;
        }
        case LAYOUT_LINEAR_HORIZONTAL:
        {
            ccArray* layoutChildrenArray = getChildren()->data;
            int length = layoutChildrenArray->num;
            CCSize layoutSize = getSize();
            float leftBoundary = 0.0f;
            for (int i=0; i<length; ++i)
            {
                UIWidget* child = dynamic_cast<UIWidget*>(layoutChildrenArray->arr[i]);
                UILinearLayoutParameter* layoutParameter = dynamic_cast<UILinearLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR));
                
                if (layoutParameter)
                {
                    UILinearGravity childGravity = layoutParameter->getGravity();
                    CCPoint ap = child->getAnchorPoint();
                    CCSize cs = child->getSize();
                    float finalPosX = leftBoundary + (ap.x * cs.width);
                    float finalPosY = layoutSize.height - (1.0f - ap.y) * cs.height;
                    switch (childGravity)
                    {
                        case LINEAR_GRAVITY_NONE:
                        case LINEAR_GRAVITY_TOP:
                            break;
                        case LINEAR_GRAVITY_BOTTOM:
                            finalPosY = ap.y * cs.height;
                            break;
                        case LINEAR_GRAVITY_CENTER_VERTICAL:
                            finalPosY = layoutSize.height / 2.0f - cs.height * (0.5f - ap.y);
                            break;
                        default:
                            break;
                    }
                    UIMargin mg = layoutParameter->getMargin();
                    finalPosX += mg.left;
                    finalPosY -= mg.top;
                    child->setPosition(ccp(finalPosX, finalPosY));
                    leftBoundary = child->getRightInParent() + mg.right;
                }
            }
            break;
        }
        case LAYOUT_RELATIVE:
        {
            ccArray* layoutChildrenArray = getChildren()->data;
            int length = layoutChildrenArray->num;
            int unlayoutChildCount = length;
            CCSize layoutSize = getSize();
            
            for (int i=0; i<length; i++)
            {
                UIWidget* child = dynamic_cast<UIWidget*>(layoutChildrenArray->arr[i]);
                UIRelativeLayoutParameter* layoutParameter = dynamic_cast<UIRelativeLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));
                layoutParameter->m_bPut = false;
            }
            
            while (unlayoutChildCount > 0)
            {
                for (int i=0; i<length; i++)
                {
                    UIWidget* child = dynamic_cast<UIWidget*>(layoutChildrenArray->arr[i]);
                    UIRelativeLayoutParameter* layoutParameter = dynamic_cast<UIRelativeLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));
                    
                    if (layoutParameter)
                    {
                        if (layoutParameter->m_bPut)
                        {
                            continue;
                        }
                        CCPoint ap = child->getAnchorPoint();
                        CCSize cs = child->getSize();
                        UIRelativeAlign align = layoutParameter->getAlign();
                        const char* relativeName = layoutParameter->getRelativeToWidgetName();
                        UIWidget* relativeWidget = NULL;
                        UIRelativeLayoutParameter* relativeWidgetLP = NULL;
                        float finalPosX = 0.0f;
                        float finalPosY = 0.0f;
                        if (relativeName && strcmp(relativeName, ""))
                        {
                            relativeWidget = CCUIHELPER->seekWidgetByRelativeName(this, relativeName);
                            if (relativeWidget)
                            {
                                relativeWidgetLP = dynamic_cast<UIRelativeLayoutParameter*>(relativeWidget->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));
                            }
                        }
                        switch (align)
                        {
                            case RELATIVE_ALIGN_NONE:
                            case RELATIVE_ALIGN_PARENT_TOP_LEFT:
                                finalPosX = ap.x * cs.width;
                                finalPosY = layoutSize.height - ((1.0f - ap.y) * cs.height);
                                break;
                            case RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL:
                                finalPosX = layoutSize.width * 0.5f - cs.width * (0.5f - ap.x);
                                finalPosY = layoutSize.height - ((1.0f - ap.y) * cs.height);
                                break;
                            case RELATIVE_ALIGN_PARENT_TOP_RIGHT:
                                finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width);
                                finalPosY = layoutSize.height - ((1.0f - ap.y) * cs.height);
                                break;
                            case RELATIVE_ALIGN_PARENT_LEFT_CENTER_VERTICAL:
                                finalPosX = ap.x * cs.width;
                                finalPosY = layoutSize.height * 0.5f - cs.height * (0.5f - ap.y);
                                break;
                            case RELATIVE_CENTER_IN_PARENT:
                                finalPosX = layoutSize.width * 0.5f - cs.width * (0.5f - ap.x);
                                finalPosY = layoutSize.height * 0.5f - cs.height * (0.5f - ap.y);
                                break;
                            case RELATIVE_ALIGN_PARENT_RIGHT_CENTER_VERTICAL:
                                finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width);
                                finalPosY = layoutSize.height * 0.5f - cs.height * (0.5f - ap.y);
                                break;
                            case RELATIVE_ALIGN_PARENT_LEFT_BOTTOM:
                                finalPosX = ap.x * cs.width;
                                finalPosY = ap.y * cs.height;
                                break;
                            case RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL:
                                finalPosX = layoutSize.width * 0.5f - cs.width * (0.5f - ap.x);
                                finalPosY = ap.y * cs.height;
                                break;
                            case RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM:
                                finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width);
                                finalPosY = ap.y * cs.height;
                                break;
                                
                            case RELATIVE_LOCATION_ABOVE_LEFTALIGN:
                                if (relativeWidget)
                                {
                                    if (relativeWidgetLP && !relativeWidgetLP->m_bPut)
                                    {
                                        continue;
                                    }
                                    float locationBottom = relativeWidget->getTopInParent();
                                    float locationLeft = relativeWidget->getLeftInParent();
                                    finalPosY = locationBottom + ap.y * cs.height;
                                    finalPosX = locationLeft + ap.x * cs.width;
                                }
                                break;
                            case RELATIVE_LOCATION_ABOVE_CENTER:
                                if (relativeWidget)
                                {
                                    if (relativeWidgetLP && !relativeWidgetLP->m_bPut)
                                    {
                                        continue;
                                    }
                                    CCSize rbs = relativeWidget->getSize();
                                    float locationBottom = relativeWidget->getTopInParent();
                                    
                                    finalPosY = locationBottom + ap.y * cs.height;
                                    finalPosX = relativeWidget->getLeftInParent() + rbs.width * 0.5f + ap.x * cs.width - cs.width * 0.5f;
                                }
                                break;
                            case RELATIVE_LOCATION_ABOVE_RIGHTALIGN:
                                if (relativeWidget)
                                {
                                    if (relativeWidgetLP && !relativeWidgetLP->m_bPut)
                                    {
                                        continue;
                                    }
                                    float locationBottom = relativeWidget->getTopInParent();
                                    float locationRight = relativeWidget->getRightInParent();
                                    finalPosY = locationBottom + ap.y * cs.height;
                                    finalPosX = locationRight - (1.0f - ap.x) * cs.width;
                                }
                                break;
                            case RELATIVE_LOCATION_LEFT_OF_TOPALIGN:
                                if (relativeWidget)
                                {
                                    if (relativeWidgetLP && !relativeWidgetLP->m_bPut)
                                    {
                                        continue;
                                    }
                                    float locationTop = relativeWidget->getTopInParent();
                                    float locationRight = relativeWidget->getLeftInParent();
                                    finalPosY = locationTop - (1.0f - ap.y) * cs.height;
                                    finalPosX = locationRight - (1.0f - ap.x) * cs.width;
                                }
                                break;
                            case RELATIVE_LOCATION_LEFT_OF_CENTER:
                                if (relativeWidget)
                                {
                                    if (relativeWidgetLP && !relativeWidgetLP->m_bPut)
                                    {
                                        continue;
                                    }
                                    CCSize rbs = relativeWidget->getSize();
                                    float locationRight = relativeWidget->getLeftInParent();
                                    finalPosX = locationRight - (1.0f - ap.x) * cs.width;
                                    
                                    finalPosY = relativeWidget->getBottomInParent() + rbs.height * 0.5f + ap.y * cs.height - cs.height * 0.5f;
                                }
                                break;
                            case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN:
                                if (relativeWidget)
                                {
                                    if (relativeWidgetLP && !relativeWidgetLP->m_bPut)
                                    {
                                        continue;
                                    }
                                    float locationBottom = relativeWidget->getBottomInParent();
                                    float locationRight = relativeWidget->getLeftInParent();
                                    finalPosY = locationBottom + ap.y * cs.height;
                                    finalPosX = locationRight - (1.0f - ap.x) * cs.width;
                                }
                                break;
                            case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN:
                                if (relativeWidget)
                                {
                                    if (relativeWidgetLP && !relativeWidgetLP->m_bPut)
                                    {
                                        continue;
                                    }
                                    float locationTop = relativeWidget->getTopInParent();
                                    float locationLeft = relativeWidget->getRightInParent();
                                    finalPosY = locationTop - (1.0f - ap.y) * cs.height;
                                    finalPosX = locationLeft + ap.x * cs.width;
                                }
                                break;
                            case RELATIVE_LOCATION_RIGHT_OF_CENTER:
                                if (relativeWidget)
                                {
                                    if (relativeWidgetLP && !relativeWidgetLP->m_bPut)
                                    {
                                        continue;
                                    }
                                    CCSize rbs = relativeWidget->getSize();
                                    float locationLeft = relativeWidget->getRightInParent();
                                    finalPosX = locationLeft + ap.x * cs.width;
                                    
                                    finalPosY = relativeWidget->getBottomInParent() + rbs.height * 0.5f + ap.y * cs.height - cs.height * 0.5f;
                                }
                                break;
                            case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN:
                                if (relativeWidget)
                                {
                                    if (relativeWidgetLP && !relativeWidgetLP->m_bPut)
                                    {
                                        continue;
                                    }
                                    float locationBottom = relativeWidget->getBottomInParent();
                                    float locationLeft = relativeWidget->getRightInParent();
                                    finalPosY = locationBottom + ap.y * cs.height;
                                    finalPosX = locationLeft + ap.x * cs.width;
                                }
                                break;
                            case RELATIVE_LOCATION_BELOW_LEFTALIGN:
                                if (relativeWidget)
                                {
                                    if (relativeWidgetLP && !relativeWidgetLP->m_bPut)
                                    {
                                        continue;
                                    }
                                    float locationTop = relativeWidget->getBottomInParent();
                                    float locationLeft = relativeWidget->getLeftInParent();
                                    finalPosY = locationTop - (1.0f - ap.y) * cs.height;
                                    finalPosX = locationLeft + ap.x * cs.width;
                                }
                                break;
                            case RELATIVE_LOCATION_BELOW_CENTER:
                                if (relativeWidget)
                                {
                                    if (relativeWidgetLP && !relativeWidgetLP->m_bPut)
                                    {
                                        continue;
                                    }
                                    CCSize rbs = relativeWidget->getSize();
                                    float locationTop = relativeWidget->getBottomInParent();
                                    
                                    finalPosY = locationTop - (1.0f - ap.y) * cs.height;
                                    finalPosX = relativeWidget->getLeftInParent() + rbs.width * 0.5f + ap.x * cs.width - cs.width * 0.5f;
                                }
                                break;
                            case RELATIVE_LOCATION_BELOW_RIGHTALIGN:
                                if (relativeWidget)
                                {
                                    if (relativeWidgetLP && !relativeWidgetLP->m_bPut)
                                    {
                                        continue;
                                    }
                                    float locationTop = relativeWidget->getBottomInParent();
                                    float locationRight = relativeWidget->getRightInParent();
                                    finalPosY = locationTop - (1.0f - ap.y) * cs.height;
                                    finalPosX = locationRight - (1.0f - ap.x) * cs.width;
                                }
                                break;
                            default:
                                break;
                        }
                        UIMargin relativeWidgetMargin;
                        UIMargin mg = layoutParameter->getMargin();
                        if (relativeWidget)
                        {
                            relativeWidgetMargin = relativeWidget->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE)->getMargin();
                        }
                        //handle margin
                        switch (align)
                        {
                            case RELATIVE_ALIGN_NONE:
                            case RELATIVE_ALIGN_PARENT_TOP_LEFT:
                                finalPosX += mg.left;
                                finalPosY -= mg.top;
                                break;
                            case RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL:
                                finalPosY -= mg.top;
                                break;
                            case RELATIVE_ALIGN_PARENT_TOP_RIGHT:
                                finalPosX -= mg.right;
                                finalPosY -= mg.top;
                                break;
                            case RELATIVE_ALIGN_PARENT_LEFT_CENTER_VERTICAL:
                                finalPosX += mg.left;
                                break;
                            case RELATIVE_CENTER_IN_PARENT:
                                break;
                            case RELATIVE_ALIGN_PARENT_RIGHT_CENTER_VERTICAL:
                                finalPosX -= mg.right;
                                break;
                            case RELATIVE_ALIGN_PARENT_LEFT_BOTTOM:
                                finalPosX += mg.left;
                                finalPosY += mg.bottom;
                                break;
                            case RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL:
                                finalPosY += mg.bottom;
                                break;
                            case RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM:
                                finalPosX -= mg.right;
                                finalPosY += mg.bottom;
                                break;
                                
                            case RELATIVE_LOCATION_ABOVE_LEFTALIGN:
                            case RELATIVE_LOCATION_ABOVE_CENTER:
                            case RELATIVE_LOCATION_ABOVE_RIGHTALIGN:
                                finalPosY += mg.bottom;
                                finalPosY += relativeWidgetMargin.top;
                                break;
                            case RELATIVE_LOCATION_LEFT_OF_TOPALIGN:
                            case RELATIVE_LOCATION_LEFT_OF_CENTER:
                            case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN:
                                finalPosX -= mg.right;
                                finalPosX -= relativeWidgetMargin.left;
                                break;
                            case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN:
                            case RELATIVE_LOCATION_RIGHT_OF_CENTER:
                            case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN:
                                finalPosX += mg.left;
                                finalPosX += relativeWidgetMargin.right;
                                break;
                            case RELATIVE_LOCATION_BELOW_LEFTALIGN:
                            case RELATIVE_LOCATION_BELOW_CENTER:
                            case RELATIVE_LOCATION_BELOW_RIGHTALIGN:
                                finalPosY -= mg.top;
                                finalPosY -= relativeWidgetMargin.bottom;
                                break;
                            default:
                                break;
                        }
                        child->setPosition(ccp(finalPosX, finalPosY));
                        layoutParameter->m_bPut = true;
                        unlayoutChildCount--;
                    }
                }
            }
            break;
        }
        default:
            break;
    }
}
예제 #17
0
파일: KUIAssist.cpp 프로젝트: joyfish/zgc
UIWidget* KUIAssist::_setVisible(UIWidget* panel,const char* baseName,int pos,bool bVisible)
{
	UIWidget* pWidget = GetIndexWidget(panel,baseName,pos);
	if(pWidget) pWidget->setVisible(bVisible);
	return pWidget;
}