示例#1
0
bool HelpScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }

    setKeypadEnabled(true);

    LayoutManager *layoutManager = LayoutManager::getInstance();
    CCRect visibleRect = layoutManager->getVisibleRect();

    CCDirector *director = CCDirector::sharedDirector();
    m_Background = CCSprite::create("help.png");
    m_Background->retain();
    m_Background->setPosition(director->getVisibleOrigin() + director->getVisibleSize() / 2);
    addChild(m_Background);

    CCMenuItemImage *pBack = CCMenuItemImage::create("back.png", NULL, this, menu_selector(HelpScene::backCallback));
    pBack->setAnchorPoint(CCPointZero);
    pBack->setPosition(ccp(visibleRect.origin.x + 18, visibleRect.origin.y + 12));

    CCMenu *pMenu = CCMenu::create(pBack, NULL);
    pMenu->setAnchorPoint(CCPointZero);
    pMenu->setPosition(CCPointZero);
    addChild(pMenu);

    return true;
}
示例#2
0
 int32_t elect_write_ds(const LayoutManager& meta, const int32_t elect_count, VUINT64& elect_ds_list)
 {
   WriteStrategy strategy(meta.get_elect_seq(), *meta.get_ns_global_info());
   int64_t elect_seq = meta.get_elect_seq();
   int32_t ret = elect_ds(strategy, ExcludeGroupElectOperation(), meta, elect_count, elect_seq, elect_ds_list);
   meta.set_elect_seq(elect_seq);
   return ret;
 }
示例#3
0
 int32_t elect_replicate_dest_ds(const LayoutManager& meta,
     const ReplicateSourceStrategy::counter_type& dest_counter, const int32_t elect_count, VUINT64& elect_ds_list)
 {
   ReplicateDestStrategy strategy(meta.get_elect_seq(), *meta.get_ns_global_info(), dest_counter);
   int64_t elect_seq = meta.get_elect_seq();
   int32_t ret = elect_ds(strategy, ExcludeGroupElectOperation(), meta, elect_count, elect_seq, elect_ds_list);
   meta.set_elect_seq(elect_seq);
   return ret;
 }
示例#4
0
 bool ServerCollect::clear(LayoutManager& manager, const time_t now)
 {
   mutex_.wrlock();
   int32_t size = hold_->size();
   BlockCollect** blocks = NULL;
   if (size > 0)//这里size大部份情况下都为0,所以拷贝的代价是能接受的
   {
     int32_t index = 0;
     blocks = new (std::nothrow)BlockCollect*[size];
     assert(NULL != blocks);
     for (BLOCKS_ITER iter = hold_->begin(); iter != hold_->end(); iter++)
     {
       blocks[index++] = (*iter);
     }
   }
   clear_();
   mutex_.unlock();
   if (size > 0)
   {
     BlockCollect* pblock = NULL;
     ArrayHelper<BlockCollect*> helper(size, blocks, size);
     for (int32_t i = 0; i < helper.get_array_index(); ++i)
     {
       //这里有点问题,如果server刚下线,在上次server结构过期之前又上来了,此时解除了关系是不正确的
       //这里先在这里简单搞下在block解除关系的时候,如果检测ID和指针都一致时才解除关系
       pblock = *helper.at(i);
       assert(NULL != pblock);
       manager.get_block_manager().relieve_relation(pblock, this, now, BLOCK_COMPARE_SERVER_BY_ID_POINTER);
     }
     tbsys::gDeleteA(blocks);
   }
   return true;
 }
	void createGui()
	{
		using namespace MyGUI;

  		LayoutManager* layMan = LayoutManager::getInstancePtr();
		mContainer = layMan->loadLayout("Composer.layout");

		Gui& gui = Gui::getInstance();
		Widget* box = gui.findWidgetT("MenuBox");
		if (!box)
			throw std::runtime_error("MenuBox not found!");

		IntSize boxSize = box->getSize();
		RenderManager& renderMgr = RenderManager::getInstance();
		IntSize size = renderMgr.getViewSize();
		// leave 1 pixel space to the sides
		box->setSize(size.width - 2, boxSize.height);  
	}
示例#6
0
void Layout::doLayout()
{
    
    if (!_doLayoutDirty)
    {
        return;
    }
    
    sortAllChildren();

    LayoutManager* executant = this->createLayoutManager();
    
    if (executant)
    {
        executant->doLayout(this);
    }
    
    _doLayoutDirty = false;
}
示例#7
0
文件: ui.cpp 项目: Adolfoi/native
void UIText(int font, const LayoutManager &layout, const char *text, uint32_t color, float scale, int align)
{
	ui_draw2d.SetFontScale(scale, scale);
	float w, h;
	ui_draw2d.MeasureText(font, text, &w, &h);
	float x, y;
	layout.GetPos(&w, &h, &x, &y);
	UIText(font, x, y, text, color, scale, 0);
	ui_draw2d.SetFontScale(1.0f, 1.0f);
}
示例#8
0
int UIButton(int id, const LayoutManager &layout, float w, float h, const char *text, int button_align) {
	if (h == 0.0f)
		h = themeAtlas->images[theme.buttonImage].h;

	float x, y;
	layout.GetPos(&w, &h, &x, &y);

	if (button_align & ALIGN_HCENTER) x -= w / 2;
	if (button_align & ALIGN_VCENTER) y -= h / 2;
	if (button_align & ALIGN_RIGHT) x -= w;
	if (button_align & ALIGN_BOTTOM) y -= h;

	int txOffset = 0;

	int clicked = 0;
	for (int i = 0; i < MAX_POINTERS; i++) {
		// Check whether the button should be hot, use a generous margin for touch ease
		if (UIRegionHit(i, x, y, w, h, 8)) {
			uistate.hotitem[i] = id;
			if (uistate.activeitem[i] == 0 && uistate.mousedown[i]) {
				uistate.activeitem[i] = id;
			}
		}

		if (uistate.hotitem[i] == id) {
			if (uistate.activeitem[i] == id) {
				// Button is both 'hot' and 'active'
				txOffset = 2;
			} else {
				// Button is merely 'hot'
			}
		} else {
			// button is not hot, but it may be active
		}

		// If button is hot and active, but mouse button is not
		// down, the user must have clicked the button.
		if (uistate.mousedown[i] == 0 &&
				uistate.hotitem[i] == id &&
				uistate.activeitem[i] == id) {
			clicked = 1;
		}
	}

	// Render button

	if (h == themeAtlas->images[theme.buttonImage].h)
		ui_draw2d.DrawImage2GridH((txOffset && theme.buttonSelected) ? theme.buttonSelected : theme.buttonImage, x, y, x + w);
	else
		ui_draw2d.DrawImage4Grid((txOffset && theme.buttonSelected) ? theme.buttonSelected : theme.buttonImage, x, y, x + w, y + h);
	ui_draw2d.DrawTextShadow(theme.uiFont, text, x + w/2, y + h/2 + txOffset, 0xFFFFFFFF, ALIGN_HCENTER | ALIGN_VCENTER);

	uistate.lastwidget = id;
	return clicked;
}
示例#9
0
文件: ui.cpp 项目: Adolfoi/native
int UIImageButton(int id, const LayoutManager &layout, float w, int image, int button_align) {
	float h = 64;
	float x, y;
	layout.GetPos(&w, &h, &x, &y);

	if (button_align & ALIGN_HCENTER) x -= w / 2;
	if (button_align & ALIGN_VCENTER) y -= h / 2;
	if (button_align & ALIGN_RIGHT) x -= w;
	if (button_align & ALIGN_BOTTOMRIGHT) y -= h;

	int txOffset = 0;
	int clicked = 0;
	for (int i = 0; i < MAX_POINTERS; i++) {
		// Check whether the button should be hot, use a generous margin for touch ease
		if (UIRegionHit(i, x, y, w, h, 8)) {
			uistate.hotitem[i] = id;
			if (uistate.activeitem[i] == 0 && uistate.mousedown[i])
				uistate.activeitem[i] = id;
		}

		if (uistate.hotitem[i] == id) {
			if (uistate.activeitem[i] == id) {
				// Button is both 'hot' and 'active'
				txOffset = 2;
			} else {
				// Button is merely 'hot'
			}
		} else {
			// button is not hot, but it may be active§
		}

		// If button is hot and active, but mouse button is not
		// down, the user must have clicked the button.
		if (uistate.mousedown[i] == 0 &&
			uistate.hotitem[i] == id &&
			uistate.activeitem[i] == id) {
				clicked = 1;
		}
	}

	// Render button

	ui_draw2d.DrawImage2GridH(theme.buttonImage, x, y, x + w);
	ui_draw2d.DrawImage(image, x + w/2, y + h/2 + txOffset, 1.0f, 0xFFFFFFFF, ALIGN_HCENTER | ALIGN_VCENTER);

	uistate.lastwidget = id;
	return clicked;
}
示例#10
0
int UITextureButton(UIContext *ctx, int id, const LayoutManager &layout, float w, float h, Texture *texture, int button_align, uint32_t color, int drop_shadow)	// uses current UI atlas for fetching images.
{
	float x, y;
	layout.GetPos(&w, &h, &x, &y);

	if (button_align & ALIGN_HCENTER) x -= w / 2;
	if (button_align & ALIGN_VCENTER) y -= h / 2;
	if (button_align & ALIGN_RIGHT) x -= w;
	if (button_align & ALIGN_BOTTOMRIGHT) y -= h;

	int txOffset = 0;
	int clicked = 0;
	for (int i = 0; i < MAX_POINTERS; i++) {
		// Check whether the button should be hot, use a generous margin for touch ease
		if (UIRegionHit(i, x, y, w, h, 8)) {
			uistate.hotitem[i] = id;
			if (uistate.activeitem[i] == 0 && uistate.mousedown[i])
				uistate.activeitem[i] = id;
		}

		if (uistate.hotitem[i] == id) {
			if (uistate.activeitem[i] == id) {
				// Button is both 'hot' and 'active'
				txOffset = 2;
			} else {
				// Button is merely 'hot'
			}
		} else {
			// button is not hot, but it may be active
		}

		// If button is hot and active, but mouse button is not
		// down, the user must have clicked the button.
		if (uistate.mousedown[i] == 0 &&
			uistate.hotitem[i] == id &&
			uistate.activeitem[i] == id) {
				clicked = 1;
		}
	}
	if (texture) {
		float tw = texture->Width();
		float th = texture->Height();

		// Adjust position so we don't stretch the image vertically or horizontally.
		// TODO: Add a param to specify fit?  The below assumes it's never too wide.
		float nw = h * tw / th;
		x += (w - nw) / 2.0f;
		w = nw;
	}

	// Render button
	int dropsize = 10;
	if (drop_shadow && texture)
	{
		if (txOffset) {
			dropsize = 3;
			y += txOffset * 2;
		}
		ui_draw2d.DrawImage4Grid(drop_shadow, x - dropsize, y, x+w + dropsize, y+h+dropsize*1.5, 
			blackAlpha(0.5f), 1.0f);
		ui_draw2d.Flush(true);
	}

	if (texture) {
		texture->Bind(0);
	} else {
		ui_draw2d.DrawImage2GridH(theme.buttonImage, x, y, x + w, color);
		ui_draw2d.Flush();

		Texture::Unbind();
	}
	ui_draw2d.DrawTexRect(x, y, x+w, y+h, 0, 0, 1, 1, color);

	ui_draw2d.Flush();
	ctx->RebindTexture();

	uistate.lastwidget = id;
	return clicked;
}
bool ChoosePackageScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }

    setKeypadEnabled(true);

    CCDirector *director = CCDirector::sharedDirector();
    LayoutManager *layoutManager = LayoutManager::getInstance();
    CCRect visibleRect = layoutManager->getVisibleRect();

    m_Background = CCSprite::create("bg_common.jpg");
    m_Background->retain();
    m_Background->setPosition(director->getVisibleOrigin() + director->getVisibleSize() / 2);
    addChild(m_Background);

    CCSprite *sprite = CCSprite::create("stage_select.png");
    sprite->setPosition(ccp(visibleRect.origin.x + visibleRect.size.width / 2, 630));
    addChild(sprite);

    // Create the page view
    int pageViewHeight = 556;
    int pageWidth = 336;
    LGPageView *pageView = LGPageView::create();
    pageView->setTouchEnabled(true);
    pageView->setSize(CCSizeMake(visibleRect.size.width, pageViewHeight));
    pageView->setPosition(CCSizeMake(visibleRect.origin.x,  + visibleRect.origin.y + (visibleRect.size.height - pageViewHeight) / 2));
    pageView->setPageWidth(pageWidth);
    pageView->setIndicatorEnable(true);

    StageManager *stageManager = StageManager::getInstance();
    for (int i = 0; i < sizeof(PACKAGE_IMAGE) / sizeof(PACKAGE_IMAGE[0]); ++i)
    {
        Layout *layout = Layout::create();
        layout->setSize(CCSizeMake(pageWidth, pageView->getSize().height));

        UIImageView *imageView = UIImageView::create();
        imageView->loadTexture(PACKAGE_IMAGE[i]);
        imageView->setPosition(ccp(layout->getRect().size.width / 2, layout->getRect().size.height / 2));
        imageView->setTag(i);
        imageView->addReleaseEvent(this, coco_releaseselector(ChoosePackageScene::selectPackageCallback));
        imageView->setTouchEnabled(true);
        layout->addChild(imageView);

        ccFontDefinition strokeTextDef;
        strokeTextDef.m_fontSize = 100;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
        strokeTextDef.m_fontName = "Lithograph";
#else
        strokeTextDef.m_fontName = "fonts/Lithograph.ttf";
#endif
        strokeTextDef.m_stroke.m_strokeEnabled = true;
        strokeTextDef.m_stroke.m_strokeColor = LayoutManager::getInstance()->DefaultStroke;
        strokeTextDef.m_stroke.m_strokeSize = 30;
        strokeTextDef.m_fontFillColor = ccWHITE;
        CCLabelTTF *labelStage = CCStrokeLabel::createWithFontDefinition(CCString::createWithFormat(" %d ", (i + 1))->getCString(), strokeTextDef);
        labelStage->setPosition(ccp(layout->getRect().size.width / 2, layout->getRect().size.height / 2));
        layout->addCCNode(labelStage);

        strokeTextDef.m_fontSize = 40;
        strokeTextDef.m_stroke.m_strokeSize = 16;
        CCLabelTTF *labelCompletion = CCStrokeLabel::createWithFontDefinition(CCString::createWithFormat(" %d/%d ", stageManager->getCompletedStageCount(i), stageManager->getStageCount(i))->getCString(), strokeTextDef);
        labelCompletion->setPosition(ccp(layout->getRect().size.width / 2, layout->getRect().size.height / 2 - labelStage->getContentSize().height / 2 - labelCompletion->getContentSize().height / 2));
        layout->addCCNode(labelCompletion);

        m_LabelCompletions->addObject(labelCompletion);

        pageView->addPage(layout);
    }

    UILayer *pUiLayer = UILayer::create();
    pUiLayer->addWidget(pageView);
    addChild(pUiLayer);
    pUiLayer->scheduleUpdate();

    CCMenuItemImage *pBack = CCMenuItemImage::create("back.png", NULL, this, menu_selector(ChoosePackageScene::backCallback));
    pBack->setAnchorPoint(CCPointZero);
    pBack->setPosition(ccp(visibleRect.origin.x + 18, visibleRect.origin.y + 12));

    CCMenu *pMenu = CCMenu::create(pBack, NULL);
    pMenu->setAnchorPoint(CCPointZero);
    pMenu->setPosition(CCPointZero);
    addChild(pMenu);

    return true;
}