Example #1
0
bool GUIMessageLayout::Load()
{
	bool res = GUILayout::Load();
	
	MyGUI::ButtonPtr button;

	MyGUI::Gui *gui = GUISystem::GetInstance()->GetGui();
	
	button = gui->findWidget<MyGUI::Button>("MessageButtonOK");
	button->eventMouseButtonClick = MyGUI::newDelegate(this, &GUIMessageLayout::mousePressed);

	MyGUI::WidgetPtr widget = Widgets.front();
	
	widget->setPosition(gui->getViewWidth()/2-widget->getWidth()/2,gui->getViewHeight()/2-widget->getHeight()/2);

	return res;
}
Example #2
0
void InfoBoxDialog::layoutVertically(MyGUI::WidgetPtr widget, int margin)
{
    size_t count = widget->getChildCount();
    int pos = 0;
    pos += margin;
    int width = 0;
    for (unsigned i = 0; i < count; ++i)
    {
        MyGUI::WidgetPtr child = widget->getChildAt(i);
        if (!child->getVisible())
            continue;

        child->setPosition(child->getLeft(), pos);
        width = std::max(width, child->getWidth());
        pos += child->getHeight() + margin;
    }
    width += margin*2;
    widget->setSize(width, pos);
}
void DashBoard::loadLayoutRecursive(MyGUI::WidgetPtr w)
{
    std::string name     = w->getName();
    std::string anim     = w->getUserString("anim");
    std::string debug    = w->getUserString("debug");
    std::string linkArgs = w->getUserString("link");

    // make it unclickable
    w->setUserString("interactive", "0");

    if (!debug.empty())
    {
        w->setVisible(false);
        return;
    }

    // find the root widget and ignore debug widgets
    if (name.size() > prefix.size())
    {
        std::string prefixLessName = name.substr(prefix.size());
        if (prefixLessName == "_Main")
        {
            mainWidget = (MyGUI::WindowPtr)w;
            // resize it
            windowResized();
        }

        // ignore debug widgets
        if (prefixLessName == "DEBUG")
        {
            w->setVisible(false);
            return;
        }
    }


    // animations for this control?
    if (!linkArgs.empty())
    {

        layoutLink_t ctrl;
        memset(&ctrl, 0, sizeof(ctrl));

        if (!name.empty()) strncpy(ctrl.name, name.c_str(), 255);
        ctrl.widget          = w;
        ctrl.initialSize     = w->getSize();
        ctrl.initialPosition = w->getPosition();
        ctrl.last            = 1337.1337f; // force update
        ctrl.lastState       = true;

        // establish the link
        {

            replaceString(linkArgs, "&gt;", ">");
            replaceString(linkArgs, "&lt;", "<");
            String linkName = "";
            if (linkArgs.empty())
            {
                LOG("Dashboard ("+filename+"/"+name+"): empty Link");
                return;
            }
            // conditional checks
            // TODO: improve the logic, this is crap ...
            if (linkArgs.find(">") != linkArgs.npos)
            {
                Ogre::StringVector args = Ogre::StringUtil::split(linkArgs, ">");
                if (args.size() == 2)
                {
                    linkName = args[0];
                    ctrl.conditionArgument = StringConverter::parseReal(args[1]);
                    ctrl.condition = CONDITION_GREATER;
                } else
                {
                    LOG("Dashboard ("+filename+"/"+name+"): error in conditional Link: " + linkArgs);
                    return;
                }
            } else if (linkArgs.find("<") != linkArgs.npos )
            {
                Ogre::StringVector args = Ogre::StringUtil::split(linkArgs, "<");
                if (args.size() == 2)
                {
                    linkName = args[0];
                    ctrl.conditionArgument = StringConverter::parseReal(args[1]);
                    ctrl.condition = CONDITION_LESSER;
                } else
                {
                    LOG("Dashboard ("+filename+"/"+name+"): error in conditional Link: " + linkArgs);
                    return;
                }
            } else
            {
                ctrl.condition         = CONDITION_NONE;
                ctrl.conditionArgument = 0;
                linkName               = linkArgs;
            }

            // now try to get the enum id for it
            int linkID = manager->getLinkIDForName(linkName);
            if (linkID < 0)
            {
                LOG("Dashboard ("+filename+"/"+name+"): unknown Link: " + linkName);
                return;
            }
            ctrl.linkID = linkID;
        }

        // parse more attributes
        ctrl.wmin = StringConverter::parseReal(w->getUserString("min"));
        ctrl.wmax = StringConverter::parseReal(w->getUserString("max"));
        ctrl.vmin = StringConverter::parseReal(w->getUserString("vmin"));
        ctrl.vmax = StringConverter::parseReal(w->getUserString("vmax"));

        String texture = w->getUserString("texture");
        if (!texture.empty()) strncpy(ctrl.texture, texture.c_str(), 255);

        String format = w->getUserString("format");
        if (!format.empty()) strncpy(ctrl.format, format.c_str(), 255);

        String direction = w->getUserString("direction");
        if (direction == "right")     ctrl.direction = DIRECTION_RIGHT;
        else if (direction == "left") ctrl.direction = DIRECTION_LEFT;
        else if (direction == "down") ctrl.direction = DIRECTION_DOWN;
        else if (direction == "up")   ctrl.direction = DIRECTION_UP;
        else if (!direction.empty())
        {
            LOG("Dashboard ("+filename+"/"+name+"): unknown direction: " + direction);
            return;

        }
        // then specializations
        if (anim == "rotate")
        {
            ctrl.animationType = ANIM_ROTATE;
            // check if its the correct control
            // try to cast, will throw
            // and if the link is a float
            /*
            if (manager->getDataType(ctrl.linkID) != DC_FLOAT)
            {
            	LOG("Dashboard ("+filename+"/"+name+"): Rotating controls can only link to floats");
            	continue;
            }
            */

            try
            {
                ctrl.rotImg = w->getSubWidgetMain()->castType<MyGUI::RotatingSkin>();
            }
            catch (...)
            {
                LOG("Dashboard ("+filename+"/"+name+"): Rotating controls must use the RotatingSkin");
                return;
            }
            if (!ctrl.rotImg)
            {
                LOG("Dashboard ("+filename+"/"+name+"): error loading rotation control");
                return;
            }

            // special: set rotation center now into the middle
            ctrl.rotImg->setCenter(MyGUI::IntPoint(w->getHeight() * 0.5f, w->getWidth() * 0.5f));

        }
        else if (anim == "scale")
        {
            ctrl.animationType = ANIM_SCALE;
            if (ctrl.direction == DIRECTION_NONE)
            {
                LOG("Dashboard ("+filename+"/"+name+"): direction empty: scale needs a direction");
                return;
            }
        }
        else if (anim == "translate")
        {
            ctrl.animationType = ANIM_TRANSLATE;
            if (ctrl.direction == DIRECTION_NONE)
            {
                LOG("Dashboard ("+filename+"/"+name+"): direction empty: translate needs a direction");
                return;
            }
        }
        else if (anim == "series")
        {
            ctrl.animationType = ANIM_SERIES;
            ctrl.img = (MyGUI::ImageBox *)w; //w->getSubWidgetMain()->castType<MyGUI::ImageBox>();
            if (!ctrl.img)
            {
                LOG("Dashboard ("+filename+"/"+name+"): error loading series control");
                return;
            }
        }
        else if (anim == "textcolor" || anim == "textcolour")
        {
            ctrl.animationType = ANIM_TEXTCOLOR;

            // try to cast, will throw
            try
            {
                ctrl.txt = (MyGUI::TextBox *)w;
            }
            catch (...)
            {
                LOG("Dashboard ("+filename+"/"+name+"): textcolor controls must use the TextBox Control");
                return;
            }
        }
        else if (anim == "textformat")
        {
            // try to cast, will throw
            try
            {
                ctrl.txt = (MyGUI::TextBox *)w; // w->getSubWidgetMain()->castType<MyGUI::TextBox>();
            }
            catch (...)
            {
                LOG("Dashboard ("+filename+"/"+name+"): Lamp controls must use the ImageBox Control");
                return;
            }
            ctrl.animationType = ANIM_TEXTFORMAT;
        }
        else if (anim == "textstring")
        {
            // try to cast, will throw
            try
            {
                ctrl.txt = (MyGUI::TextBox *)w; // w->getSubWidgetMain()->castType<MyGUI::TextBox>();
            }
            catch (...)
            {
                LOG("Dashboard ("+filename+"/"+name+"): Lamp controls must use the ImageBox Control");
                return;
            }
            ctrl.animationType = ANIM_TEXTSTRING;
        }
        else if (anim == "lamp")
        {
            // try to cast, will throw
            /*
            {
            	try
            	{
            		w->getSubWidgetMain()->castType<MyGUI::ImageBox>();
            	}
            	catch (...)
            	{
            		LOG("Dashboard ("+filename+"/"+name+"): Lamp controls must use the ImageBox Control");
            		continue;
            	}
            }
            */
            ctrl.animationType = ANIM_LAMP;
            ctrl.img = (MyGUI::ImageBox *)w; //w->getSubWidgetMain()->castType<MyGUI::ImageBox>();
            if (!ctrl.img)
            {
                LOG("Dashboard ("+filename+"/"+name+"): error loading Lamp control");
                return;
            }
        }


        controls[free_controls] = ctrl;
        free_controls++;
        if (free_controls >= MAX_CONTROLS)
        {
            LOG("maximum amount of controls reached, discarding the rest: " + TOSTRING(MAX_CONTROLS));
            return;
        }
    }

    // walk the children now
    MyGUI::EnumeratorWidgetPtr e = w->getEnumerator();
    while (e.next())
    {
        loadLayoutRecursive(e.current());
    }
}
void PropertiesPanelView::createPropertiesWidgetsPair(MyGUI::WidgetPtr _window, std::string _property, std::string _value, std::string _type,int y)
{
	pairs_counter++;
	int x1 = 0, x2 = 125;
	int w1 = 120;
	int w2 = _window->getWidth() - x2;
	const int h = PropertyItemHeight;

	if (_property == "Position")
	{
		x1 = 66;
		w1 = w1 - x1;
	}

	MyGUI::StaticTextPtr text;
	MyGUI::WidgetPtr editOrCombo;
	//int string_int_float; // 0 - string, 1 - int, 2 - float

	int widget_for_type;// 0 - Edit, 1 - Combo mode drop, 2 - ...
	std::string type_names[2] = {"Edit", "ComboBox"};
	if ("Name" == _type) widget_for_type = 0;
	else if ("Skin" == _type) widget_for_type = 1;
	else if ("Position" == _type) widget_for_type = 0;
	else if ("Layer" == _type) widget_for_type = 1;
	else if ("String" == _type) widget_for_type = 0;
	else if ("Align" == _type) widget_for_type = 1;
	// не совсем правильно FIXME
	else if ("1 int" == _type) widget_for_type = 0;
	else if ("2 int" == _type) widget_for_type = 0;
	else if ("4 int" == _type) widget_for_type = 0;
	else if ("1 float" == _type) widget_for_type = 0;
	else if ("2 float" == _type) widget_for_type = 0;
	// надо сделать проще FIXME
	else if ("Colour" == _type) widget_for_type = 0;//"Colour" хорошо бы колорпикером
	else if ("MessageButton" == _type) widget_for_type = 1;
	else if ("FileName" == _type) widget_for_type = 0;
	else widget_for_type = 1;

	if ((propertiesText.size() < pairs_counter) || (propertiesText[pairs_counter-1]->getParent() != _window))
	{
		text = _window->createWidget<MyGUI::StaticText>("Editor_StaticText", x1, y, w1, h, MyGUI::Align::Default);
		text->setTextAlign(MyGUI::Align::Right);
		if (propertiesText.size() < pairs_counter)
		{
			propertiesText.push_back(text);
		}
		else
		{
			MyGUI::Gui::getInstance().destroyWidget(propertiesText[pairs_counter-1]);
			propertiesText[pairs_counter-1] = text;
		}
	}
	else
	{
		text = propertiesText[pairs_counter-1];
		text->setVisible(true);
		text->setCoord(x1, y, w1, h);
	}
	std::string prop = _property;
	// trim widget name
	std::string::iterator iter = std::find(prop.begin(), prop.end(), '_');
	if (iter != prop.end()) prop.erase(prop.begin(), ++iter);
	text->setCaption(prop);

	if ((propertiesElement.size() < pairs_counter) || (propertiesElement[pairs_counter-1]->getParent() != _window) ||
		(type_names[widget_for_type] != propertiesElement[pairs_counter-1]->getTypeName()))
	{
		if (widget_for_type == 0)
		{
			editOrCombo = _window->createWidget<MyGUI::Edit>("Edit", x2, y, w2, h, MyGUI::Align::Top | MyGUI::Align::HStretch);
			editOrCombo->castType<MyGUI::Edit>()->eventEditTextChange = newDelegate (this, &PropertiesPanelView::notifyTryApplyProperties);
			editOrCombo->castType<MyGUI::Edit>()->eventEditSelectAccept = newDelegate (this, &PropertiesPanelView::notifyForceApplyProperties);
		}
		else if (widget_for_type == 1)
		{
			editOrCombo = _window->createWidget<MyGUI::ComboBox>("ComboBox", x2, y, w2, h, MyGUI::Align::Top | MyGUI::Align::HStretch);
			editOrCombo->castType<MyGUI::ComboBox>()->eventComboAccept = newDelegate (this, &PropertiesPanelView::notifyForceApplyProperties2);

			editOrCombo->castType<MyGUI::ComboBox>()->setComboModeDrop(true);
		}

		if (propertiesElement.size() < pairs_counter)
		{
			propertiesElement.push_back(editOrCombo);
		}
		else
		{
			MyGUI::Gui::getInstance().destroyWidget(propertiesElement[pairs_counter-1]);
			propertiesElement[pairs_counter-1] = editOrCombo;
		}
	}
	else
	{
		editOrCombo = propertiesElement[pairs_counter-1];
		if (widget_for_type == 1) editOrCombo->castType<MyGUI::ComboBox>()->removeAllItems();
		editOrCombo->setVisible(true);
		editOrCombo->setCoord(x2, y, w2, h);
	}

	// fill possible values
	if (widget_for_type == 1)
	{
		std::vector<std::string> values;
		if (_type == "Skin") values = WidgetTypes::getInstance().find(current_widget->getTypeName())->skin;
		else values = WidgetTypes::getInstance().findPossibleValues(_type);

		for (std::vector<std::string>::iterator iter = values.begin(); iter != values.end(); ++iter)
			editOrCombo->castType<MyGUI::ComboBox>()->addItem(*iter);
	}

	editOrCombo->setUserString("action", _property);
	editOrCombo->setUserString("type", _type);

	if (_value.empty()){
		editOrCombo->setCaption(DEFAULT_VALUE);
	}
	else
	{
		editOrCombo->castType<MyGUI::Edit>()->setOnlyText(_value);
		checkType(editOrCombo->castType<MyGUI::Edit>(), _type);
	}
}