Esempio n. 1
0
void PromptBox::SetLabel(const CEGUI::String& text)
{
	OC_CEGUI_TRY;
	{
		CEGUI::Window* messageText = mPromptBox->getChild(mPromptBox->getName() + "/MessageText");
		CEGUI::Window* editbox = mPromptBox->getChild(mPromptBox->getName() + "/Editbox");
		const float32 offset = 10;
		float32 buttonHeight = mPromptBox->getChild(mPromptBox->getName() + "/ButtonOK")->getPixelSize().d_height;
		float32 editboxHeight = editbox->getPixelSize().d_height;
	
		messageText->setText(text);
		float32 textWidth = StringConverter::FromString<float32>(messageText->getProperty("HorzExtent").c_str());
		float32 textHeight = StringConverter::FromString<float32>(messageText->getProperty("VertExtent").c_str());

		editbox->subscribeEvent(CEGUI::Editbox::EventKeyDown, CEGUI::Event::Subscriber(&PromptBox::OnEditboxKeyDown, this));

		messageText->setArea(CEGUI::UDim(0,offset), CEGUI::UDim(0,0), CEGUI::UDim(1, -2.0f*offset), CEGUI::UDim(1, -buttonHeight-editboxHeight - offset));
		mPromptBox->setWidth(CEGUI::UDim(0, textWidth + 2.0f*offset + INNER_FRAME_OFFSET));
		mPromptBox->setHeight(CEGUI::UDim(0, textHeight + buttonHeight + editboxHeight + offset + INNER_FRAME_OFFSET));
		mPromptBox->setXPosition(CEGUI::UDim(0.5f, -0.5f*mPromptBox->getPixelSize().d_width));
		mPromptBox->setYPosition(CEGUI::UDim(0.5f, -0.5f*mPromptBox->getPixelSize().d_height));

		EnsureWindowIsWideEnough();
	}
	OC_CEGUI_CATCH;
}
Esempio n. 2
0
bool TabNavigation::OnEventKeyDown(const CEGUI::EventArgs& e)
{
	const CEGUI::KeyEventArgs& args = static_cast<const CEGUI::KeyEventArgs&>(e);
	if (args.scancode == CEGUI::Key::Tab) // Tab or Shift+Tab
	{
		WidgetList::iterator itCurrent = Containers::find(mTabOrder.begin(), mTabOrder.end(), args.window);
		OC_ASSERT(itCurrent != mTabOrder.end());
		WidgetList::iterator itFocus = itCurrent;
		CEGUI::Window* newWidget = 0;
		do
		{
			if (args.sysKeys & CEGUI::Shift)
			{
				// Set previous
				if (itFocus == mTabOrder.begin())
					itFocus = mTabOrder.end();
				--itFocus;
			}
			else
			{
				// Set next
				++itFocus;
				if (itFocus == mTabOrder.end())
					itFocus = mTabOrder.begin();
			}
			newWidget = *itFocus;
		}
		while ((!newWidget->isVisible() || newWidget->isDisabled() || newWidget->getProperty("ReadOnly") == "True" ) && itFocus != itCurrent);
		newWidget->activate();

		// Make sure active widget will be visible
		if (mScrollablePane)
		{
			CEGUI::Window* w = newWidget;
			CEGUI::Vector2 widgetOffset(0, 0);
			do
			{
				widgetOffset += w->getPosition().asAbsolute(w->getParentPixelSize());
				w = w->getParent();
			}
			while (w != mScrollablePane && w != 0);

			float32 scrollViewTop = mScrollablePane->getContentPaneArea().getSize().d_height * mScrollablePane->getVerticalScrollPosition();
			float32 scrollViewBottom = scrollViewTop + mScrollablePane->getClipRect().getHeight();
			
			if (widgetOffset.d_y < scrollViewTop || widgetOffset.d_y + newWidget->getPixelSize().d_height > scrollViewBottom)
			{
				// We need to scroll
				mScrollablePane->setVerticalScrollPosition(widgetOffset.d_y / mScrollablePane->getContentPaneArea().getSize().d_height);
			}
		}

		return true;
	}
	return false;
}
//nikai 2010.9.3
void SelectionMover::AlignSpaceBetween(int PaddingValue, const PaddingAlign al)
{
    // Validations
    wxASSERT_MSG(m_selection != NULL, wxT("Selection member is NULL"));

    if(m_selection->Size() <= 1) 
    {
        // Should not happen because of the disabled menu/toolbar item in this case
        LogWarning(wxT("You must select more than one window to align!"));
        return;
    }
    // The first selected window is the one to match. This is for example how Visual Studio's 
    // dialog editor works as well.
    Selection::Boxes::iterator boxIt = m_selection->GetMoveableBoxes().begin();

    const CEGUI::Window *current = boxIt->GetWindow();
            
    CEGUI::Window *pParentWin = current->getParent();
    if(NULL == pParentWin)
    {
        LogWarning(wxT("You can't operate the root window!"));
        wxMessageBox(L"You can't operate the root window!");
        return;
    }
    const long ParentX = CEGUI::CoordConverter::windowToScreenX(*pParentWin,0);
    const long ParentY = CEGUI::CoordConverter::windowToScreenY(*pParentWin,0);
    const long parentWidth = pParentWin->getPixelSize().d_width;
    const long parentHeight = pParentWin->getPixelSize().d_height;

    const CEGUI::URect rect = current->getArea();
    ++boxIt;
    
    for(; boxIt != m_selection->GetMoveableBoxes().end(); ++boxIt) {
        // Deny when it is blocked
        if (boxIt->IsLocked())
        {
            wxMessageBox(L"all the select window ¡¯s can't be locked£¡");
            return;
        }
        CEGUI::Window* curWin = boxIt->GetWindow();
        if (pParentWin != curWin->getParent())
        {
            wxMessageBox(L"all the select window ¡¯s parent must be same£¡");
            return;
        }
    }
    //»Ö¸´µü´úÆ÷λÖÃ
    //boxIt = m_selection->GetMoveableBoxes().begin(); 
    //++boxIt;
    //float lWidth  = current->getPixelSize().d_width;
    //float lHeight = current->getPixelSize().d_height;
    //float RightPos = CEGUI::CoordConverter::windowToScreenX(*current,0)+lWidth;
    //float BottomPos = CEGUI::CoordConverter::windowToScreenY(*current,0)+lHeight;
    //
    //for(; boxIt != m_selection->GetMoveableBoxes().end(); ++boxIt)
    //{
    //    CEGUI::Window* curWin = boxIt->GetWindow();
    //    CEGUI::UDim xPos = curWin->getXPosition();
    //    CEGUI::UDim yPos = curWin->getYPosition();
    //    switch(al)
    //    {
    //    case HorzPadding:
    //        {
    //            float newXPixel = RightPos + PaddingValue;
    //            float xscale = (newXPixel-ParentX)/parentWidth;
    //            xPos = CEGUI::UDim(xscale,0);
    //            break;
    //        }
    //    case VertPadding:
    //        {
    //            float newYPixel = BottomPos + PaddingValue;
    //            float yscale = (newYPixel-ParentY)/parentHeight;
    //            yPos = CEGUI::UDim(yscale,0);
    //            break;
    //        }
    //    default:
    //        LogError(wxT("SelectionMover::AlignSelection - Unrecognized align option (%d)"), al);
    //        return;
    //    }
    //    curWin->setPosition(CEGUI::UVector2(xPos,yPos));
    //    lWidth  = curWin->getPixelSize().d_width;
    //    lHeight = curWin->getPixelSize().d_height;
    //    RightPos = CEGUI::CoordConverter::windowToScreenX(*curWin,0)+lWidth;
    //    BottomPos = CEGUI::CoordConverter::windowToScreenY(*curWin,0)+lHeight;
    //}
    //// Request for a repaint
    //wxGetApp().GetMainFrame()->Refresh();
    boxIt = m_selection->GetMoveableBoxes().begin(); 
    ++boxIt;
    float newPixelWidth  = current->getPixelSize().d_width;
    float newPixelHeight = current->getPixelSize().d_height;
    float RightPos = CEGUI::CoordConverter::windowToScreenX(*current,0)+newPixelWidth;
    float BottomPos = CEGUI::CoordConverter::windowToScreenY(*current,0)+newPixelHeight;

    for(; boxIt != m_selection->GetMoveableBoxes().end(); ++boxIt)
    {
        CEGUI::Window* curWin = boxIt->GetWindow();
        float fLeft = CEGUI::CoordConverter::windowToScreenX(*curWin,0);
        float fTop  = CEGUI::CoordConverter::windowToScreenY(*curWin,0);
        newPixelWidth  = curWin->getPixelSize().d_width;
        newPixelHeight = curWin->getPixelSize().d_height;
        float fRight  = fLeft  + newPixelWidth;
        float fBottom = fTop + newPixelHeight;

        CEGUI::URect newWindowArea = curWin->getArea();
        float sLeft = 0.0f,sTop = 0.0f,sRight = 0.0f, sBottom = 0.0f;
        switch(al)
        {
        case HorzPadding:
            {
                float newXPixel = RightPos + PaddingValue;
                sRight = sLeft = newXPixel - fLeft;
                break;
            }
        case VertPadding:
            {
                float newYPixel = BottomPos + PaddingValue;
                sBottom = sTop = newYPixel - fTop;
                break;
            }
        default:
            LogError(wxT("SelectionMover::AlignSelection - Unrecognized align option (%d)"), al);
            return;
        }

        MoveUsingScale(curWin,newWindowArea,sLeft,sTop,sRight,sBottom);
        curWin->setArea(newWindowArea);
        fLeft = CEGUI::CoordConverter::windowToScreenX(*curWin,0);
        fTop  = CEGUI::CoordConverter::windowToScreenY(*curWin,0);
        RightPos  = fLeft + newPixelWidth;
        BottomPos = fTop  + newPixelHeight;
    }
    // Request for a repaint
    wxGetApp().GetMainFrame()->Refresh();
}