예제 #1
0
void MessageBox::SetButtons(const MessageBoxButtons& buttons)
{
	float32 sumWidth = 0;
	for (MessageBoxButtons::const_iterator it = buttons.begin(); it != buttons.end(); ++it)
	{
		CEGUI::Window* button = GetButton(*it);
		OC_DASSERT(button != 0);
		float32 width = button->getWidth().d_offset;
		sumWidth += width;
	}

	float32 totalWidth = sumWidth + BUTTON_MARGIN * (buttons.size() - 1);

	float32 left = 0;
	for (MessageBoxButtons::const_iterator it = buttons.begin(); it != buttons.end(); ++it)
	{
		CEGUI::Window* button = GetButton(*it);
		OC_DASSERT(button != 0);
		float32 width = button->getWidth().d_offset;

		button->setPosition(CEGUI::UVector2(CEGUI::UDim(0.5f, -0.5f * totalWidth + left), button->getPosition().d_y));
		button->setWidth(CEGUI::UDim(0, width));
		button->setVisible(true);
		button->setID((CEGUI::uint)*it);
		button->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&GUISystem::MessageBox::OnButtonClicked, this));
		
		left += width + BUTTON_MARGIN;
	}

	mMinWidth = totalWidth + 2.0f * BUTTON_MARGIN;
}
예제 #2
0
//------------------------------------------------------------------------
void SelectionMover::AlignSelection(const Alignment alignment)
{
    // 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();

    CEGUI::Window *current = boxIt->GetWindow();

    const CEGUI::URect rect = current->getArea();
    ++boxIt;

    for(; boxIt != m_selection->GetMoveableBoxes().end(); ++boxIt) {
        // Deny when it is blocked
        if (boxIt->IsLocked())
            continue;
        
        current = boxIt->GetWindow();
        
        switch(alignment)
        {
        case AlignLeft:
            current->setPosition(CEGUI::UVector2(rect.d_min.d_x, current->getPosition().d_y));
            break;
        case AlignRight:
            current->setPosition(CEGUI::UVector2(rect.d_max.d_x - current->getWidth(), current->getPosition().d_y));
            break;
        case AlignTop:
            current->setPosition(CEGUI::UVector2(current->getPosition().d_x, rect.d_min.d_y));
            break;
        case AlignBottom:
            current->setPosition(CEGUI::UVector2(current->getPosition().d_x, rect.d_max.d_y - current->getHeight()));
            break;
        case AlignWidth:
            // The svn diff for this block will be big; no clue what the previous code
            // was doing there..
            current->setWidth(rect.getWidth());
            break;
        case AlignHeight:
            // The svn diff for this block will be big; no clue what the previous code
            // was doing there..
            current->setHeight(rect.getHeight());
            break;
        default:
            LogError(wxT("SelectionMover::AlignSelection - Unrecognized align option (%d)"), alignment);
            return;
        }
    }
    // Request for a repaint
    wxGetApp().GetMainFrame()->Refresh();
}