예제 #1
0
    void WindowCaption::align()
    {
        MyGUI::IntSize textSize = getTextSize();
        MyGUI::Widget* caption = mClient;
        caption->setSize(textSize.width + 24, caption->getHeight());

        int barwidth = (getWidth()-caption->getWidth())/2;
        caption->setPosition(barwidth, caption->getTop());
        if (mLeft)
            mLeft->setCoord(0, mLeft->getTop(), barwidth, mLeft->getHeight());
        if (mRight)
            mRight->setCoord(barwidth + caption->getWidth(), mRight->getTop(), barwidth, mRight->getHeight());
    }
예제 #2
0
/*重新布局窗口
*/
void Grid::reLayout(){
	assert(parent && column > 0 );
	int i,x,y,width,height;
	MyGUI::IntSize size;
	vector<int> mh((int)(parent->getChildCount()/column)+1),mv(column);
	MyGUI::ScrollView *psw = parent->castType<MyGUI::ScrollView>(false);

	fill(mh.begin(),mh.end(),0);
	fill(mv.begin(),mv.end(),0);
	for( i = 0;i<(int)parent->getChildCount();++i ){
		MyGUI::Widget* pchild = parent->getChildAt(i);
		MyGUI::IntSize size = pchild->getSize();
		//如果没有设置这里自动计算
		if( size.width==0 ){
			size.width = CalcWidgetSize(pchild).width;
		}
		if( size.height==0 ){
			size.height = CalcWidgetSize(pchild).height;
		}
		if( size.width>mv[i%column] )
			mv[i%column] = size.width;
		if( size.height>mh[(int)(i/column)] )
			mh[(int)(i/column)] = size.height;
	}
	width = sum(mv,mv.size())+(column-1)*space;
	height = sum(mh,mh.size());
	size = parent->getSize();
	//对于ScrollView可能有Bug,这里减去24感觉正好
	if( psw ){
		size.width -= 24;
		size.height -= 24;
	}
	//不要小于0
	x = max((int)((size.width-width)/2),0);
	y = max((int)((size.height-height)/2),0);
	for( i = 0;i<(int)parent->getChildCount();++i ){
		int col,row;
		MyGUI::Widget* pchild = parent->getChildAt(i);
		//这里使用中心对齐
		col = i%column;
		row = (int)(i/column);
		pchild->setPosition(MyGUI::IntPoint(x+col*space+sum(mv,col),y+sum(mh,row)));
		pchild->setSize(MyGUI::IntSize(mv[col],mh[row]));
	}
	//如果父窗口是ScrollView
	
	if( psw )psw->setCanvasSize( max(size.width,width),max(size.height,height) );
}
예제 #3
0
파일: itemview.cpp 프로젝트: ace13/openmw
void ItemView::layoutWidgets()
{
    if (!mScrollView->getChildCount())
        return;

    int x = 0;
    int y = 0;
    MyGUI::Widget* dragArea = mScrollView->getChildAt(0);
    int maxHeight = mScrollView->getHeight();

    int rows = maxHeight/42;
    rows = std::max(rows, 1);
    bool showScrollbar = int(std::ceil(dragArea->getChildCount()/float(rows))) > mScrollView->getWidth()/42;
    if (showScrollbar)
        maxHeight -= 18;

    for (unsigned int i=0; i<dragArea->getChildCount(); ++i)
    {
        MyGUI::Widget* w = dragArea->getChildAt(i);

        w->setPosition(x, y);

        y += 42;

        if (y > maxHeight-42 && i < dragArea->getChildCount()-1)
        {
            x += 42;
            y = 0;
        }
    }
    x += 42;

    MyGUI::IntSize size = MyGUI::IntSize(std::max(mScrollView->getSize().width, x), mScrollView->getSize().height);

    // Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden
    mScrollView->setVisibleVScroll(false);
    mScrollView->setVisibleHScroll(false);
    mScrollView->setCanvasSize(size);
    mScrollView->setVisibleVScroll(true);
    mScrollView->setVisibleHScroll(true);
    dragArea->setSize(size);
}
예제 #4
0
void ItemView::layoutWidgets()
{
    if (!mScrollView->getChildCount())
        return;

    int x = 0;
    int y = 0;
    int maxHeight = mScrollView->getSize().height - 58;

    MyGUI::Widget* dragArea = mScrollView->getChildAt(0);

    for (unsigned int i=0; i<dragArea->getChildCount(); ++i)
    {
        MyGUI::Widget* w = dragArea->getChildAt(i);

        w->setPosition(x, y);

        y += 42;
        if (y > maxHeight)
        {
            x += 42;
            y = 0;
        }
    }
    x += 42;

    MyGUI::IntSize size = MyGUI::IntSize(std::max(mScrollView->getSize().width, x), mScrollView->getSize().height);

    // Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden
    mScrollView->setVisibleVScroll(false);
    mScrollView->setVisibleHScroll(false);
    mScrollView->setCanvasSize(size);
    mScrollView->setVisibleVScroll(true);
    mScrollView->setVisibleHScroll(true);
    dragArea->setSize(size);
}
예제 #5
0
파일: itemview.cpp 프로젝트: Allxere/openmw
void ItemView::update()
{
    while (mScrollView->getChildCount())
        MyGUI::Gui::getInstance().destroyWidget(mScrollView->getChildAt(0));

    if (!mModel)
        return;

    int x = 0;
    int y = 0;
    int maxHeight = mScrollView->getSize().height - 58;

    mModel->update();

    MyGUI::Widget* dragArea = mScrollView->createWidget<MyGUI::Widget>("",0,0,mScrollView->getWidth(),mScrollView->getHeight(),
                                                                       MyGUI::Align::Stretch);
    dragArea->setNeedMouseFocus(true);
    dragArea->eventMouseButtonClick += MyGUI::newDelegate(this, &ItemView::onSelectedBackground);
    dragArea->eventMouseWheel += MyGUI::newDelegate(this, &ItemView::onMouseWheel);

    for (ItemModel::ModelIndex i=0; i<static_cast<int>(mModel->getItemCount()); ++i)
    {
        const ItemStack& item = mModel->getItem(i);

        /// \todo performance improvement: don't create/destroy all the widgets everytime the container window changes size, only reposition them
        ItemWidget* itemWidget = dragArea->createWidget<ItemWidget>("MW_ItemIcon",
            MyGUI::IntCoord(x, y, 42, 42), MyGUI::Align::Default);
        itemWidget->setUserString("ToolTipType", "ItemModelIndex");
        itemWidget->setUserData(std::make_pair(i, mModel));
        ItemWidget::ItemState state = ItemWidget::None;
        if (item.mType == ItemStack::Type_Barter)
            state = ItemWidget::Barter;
        if (item.mType == ItemStack::Type_Equipped)
            state = ItemWidget::Equip;
        itemWidget->setItem(item.mBase, state);

        itemWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ItemView::onSelectedItem);
        itemWidget->eventMouseWheel += MyGUI::newDelegate(this, &ItemView::onMouseWheel);

        // text widget that shows item count
        // TODO: move to ItemWidget
        MyGUI::TextBox* text = itemWidget->createWidget<MyGUI::TextBox>("SandBrightText",
            MyGUI::IntCoord(5, 19, 32, 18), MyGUI::Align::Default, std::string("Label"));
        text->setTextAlign(MyGUI::Align::Right);
        text->setNeedMouseFocus(false);
        text->setTextShadow(true);
        text->setTextShadowColour(MyGUI::Colour(0,0,0));
        text->setCaption(getCountString(item.mCount));

        y += 42;
        if (y > maxHeight)
        {
            x += 42;
            y = 0;
        }

    }
    x += 42;
    MyGUI::IntSize size = MyGUI::IntSize(std::max(mScrollView->getSize().width, x), mScrollView->getSize().height);

    // Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden
    mScrollView->setVisibleVScroll(false);
    mScrollView->setVisibleHScroll(false);
    mScrollView->setCanvasSize(size);
    mScrollView->setVisibleVScroll(true);
    mScrollView->setVisibleHScroll(true);
    dragArea->setSize(size);
}