예제 #1
0
	MyGUI::IntCoord WidgetCreatorManager::getCoordNewWidget(const MyGUI::IntPoint& _point)
	{
		MyGUI::IntPoint point = _point;
		if (!MyGUI::InputManager::getInstance().isShiftPressed())
		{
			point.left += mGridStep / 2;
			point.top += mGridStep / 2;
		}

		MyGUI::Widget* parent = mNewWidget->getParent();
		if (parent != nullptr && !mNewWidget->isRootWidget())
			point -= parent->getAbsolutePosition();

		if (!MyGUI::InputManager::getInstance().isShiftPressed())
		{
			point.left = toGrid(point.left);
			point.top = toGrid(point.top);
		}

		MyGUI::IntCoord coord = MyGUI::IntCoord(
			std::min(mStartPoint.left, point.left),
			std::min(mStartPoint.top, point.top),
			abs(point.left - mStartPoint.left),
			abs(point.top - mStartPoint.top));

		return coord;
	}
예제 #2
0
void WidgetCreatorManager::moveNewWidget(const MyGUI::IntPoint& _point)
{
    if (mNewWidget == nullptr)
    {
        // тип виджета может отсутсвовать
        if (!MyGUI::WidgetManager::getInstance().isFactoryExist(mWidgetType))
            return;

        // выделяем верний виджет
        if (!mPopupMode)
            WidgetSelectorManager::getInstance().selectWidget(mStartPoint);

        MyGUI::Widget* parent = WidgetSelectorManager::getInstance().getSelectedWidget();

        // пока не найдем ближайшего над нами способного быть родителем
        while (parent != nullptr && !WidgetTypes::getInstance().findWidgetStyle(parent->getTypeName())->parent)
            parent = parent->getParent();

        if (!WidgetTypes::getInstance().findWidgetStyle(mWidgetType)->child)
            parent = nullptr;

        if (parent != nullptr)
            mNewWidget = parent->createWidgetT(
                             mPopupMode ? MyGUI::WidgetStyle::Popup : MyGUI::WidgetStyle::Child,
                             mWidgetType,
                             EditorWidgets::getInstance().getSkinReplace(mWidgetSkin),
                             MyGUI::IntCoord(),
                             MyGUI::Align::Default,
                             DEFAULT_EDITOR_LAYER);
        else
            mNewWidget = MyGUI::Gui::getInstance().createWidgetT(
                             mWidgetType,
                             EditorWidgets::getInstance().getSkinReplace(mWidgetSkin),
                             MyGUI::IntCoord(),
                             MyGUI::Align::Default,
                             DEFAULT_EDITOR_LAYER);

        // переводим старт поинт в координаты отца
        if (parent != nullptr && !mNewWidget->isRootWidget())
        {
            if (parent->getClientWidget())
                mStartPoint -= parent->getClientWidget()->getAbsolutePosition();
            else
                mStartPoint -= parent->getAbsolutePosition();
        }

        if (!MyGUI::InputManager::getInstance().isShiftPressed())
        {
            mStartPoint.left = Grid::getInstance().toGrid(mStartPoint.left);
            mStartPoint.top = Grid::getInstance().toGrid(mStartPoint.top);
        }
    }

    MyGUI::IntCoord coord = getCoordNewWidget(_point);
    mNewWidget->setCoord(coord);

    eventChangeSelector(true, mNewWidget->getAbsoluteCoord());
}
예제 #3
0
	void WorkspaceControl::updateSelectionFromValue()
	{
		// саму рамку отображаем в глобальных
		if (mCurrentWidget != nullptr)
		{
			MyGUI::Widget* parent = mCurrentWidget->getParent();
			if (parent != nullptr && !mCurrentWidget->isRootWidget())
				mAreaSelectorControl->setCoord(mCoordValue + parent->getAbsolutePosition());
			else
				mAreaSelectorControl->setCoord(mCoordValue);
		}
	}
예제 #4
0
	void WorkspaceControl::notifyPropertyChangeCoord(MyGUI::Widget* _widget, const MyGUI::IntCoord& _coordValue, const std::string& _owner)
	{
		if (_owner == "WorkspaceControl" || _widget != mCurrentWidget)
			return;

		// тут приходит в абсолютных, конвертим в локальные
		mCoordValue = _coordValue;
		if (mCurrentWidget != nullptr)
		{
			MyGUI::Widget* parent = mCurrentWidget->getParent();
			if (parent != nullptr && !mCurrentWidget->isRootWidget())
				mCoordValue = mCoordValue - parent->getAbsolutePosition();
		}

		updateSelectionFromValue();
	}
예제 #5
0
	void WorkspaceControl::notifyChangePosition()
	{
		if (!mMoveableWidget)
			return;

		mCoordValue = mAreaSelectorControl->getCoord();

		// конвертируем в локальные координаты
		if (mCurrentWidget != nullptr)
		{
			MyGUI::Widget* parent = mCurrentWidget->getParent();
			if (parent != nullptr && !mCurrentWidget->isRootWidget())
				mCoordValue = mCoordValue - parent->getAbsolutePosition();
		}

		// снапим к гриду
		if (!MyGUI::InputManager::getInstance().isShiftPressed())
		{
			MyGUI::IntCoord coord = mCoordValue;
			MyGUI::IntCoord actionScale = mAreaSelectorControl->getActionScale();

			if (actionScale.left != 0 && actionScale.width != 0)
			{
				int right = coord.right();
				coord.width = toGrid(coord.width + (mGridStep / 2));
				coord.left = right - coord.width;
			}
			else if (actionScale.width != 0)
			{
				int right = toGrid(coord.right() + (mGridStep / 2));
				coord.width = right - coord.left;
			}
			else if (actionScale.left != 0)
			{
				coord.left = toGrid(coord.left + (mGridStep / 2));
			}

			if (actionScale.top != 0 && actionScale.height != 0)
			{
				int bottom = coord.bottom();
				coord.height = toGrid(coord.height + (mGridStep / 2));
				coord.top = bottom - coord.height;
			}
			else if (actionScale.height != 0)
			{
				int bottom = toGrid(coord.bottom() + (mGridStep / 2));
				coord.height = bottom - coord.top;
			}
			else if (actionScale.top != 0)
			{
				coord.top = toGrid(coord.top + (mGridStep / 2));
			}

			if (coord != mCoordValue)
			{
				mCoordValue = coord;
				updateSelectionFromValue();
			}
		}

		if (mCurrentWidget != nullptr)
			setWidgetCoord(mCurrentWidget, mCoordValue);

		UndoManager::getInstance().addValue(PR_POSITION);
	}