void PanelView::updateView() { // вычисл¤ем максимальную высоту всего добра int height = 0; for (VectorPanel::iterator iter=mItems.begin(); iter!=mItems.end(); ++iter) { MyGUI::WidgetPtr widget = (*iter)->getPanelCell()->mainWidget(); if (widget->isShow()) { height += widget->getHeight(); } } // ставим высоту холста, и спрашиваем получившуюс¤ ширину клиента mScrollView->setCanvasSize(0, height); // ширина клиента могла помен¤тс¤ MyGUI::IntCoord coord = mScrollView->getClientCoord(); mScrollView->setCanvasSize(coord.width, height); // выравниваем все панели int pos = 0; for (VectorPanel::iterator iter=mItems.begin(); iter!=mItems.end(); ++iter) { MyGUI::WidgetPtr widget = (*iter)->getPanelCell()->mainWidget(); if (widget->isShow()) { height = widget->getHeight(); widget->setPosition(MyGUI::IntCoord(0, pos, coord.width, height)); pos += height; } } mNeedUpdate = false; MyGUI::Gui::getInstance().eventFrameStart -= MyGUI::newDelegate(this, &PanelView::frameEntered); }
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, ">", ">"); replaceString(linkArgs, "<", "<"); 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()); } }
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; }