void GraphicsImpl::guiCallback(MyGUI::WidgetPtr sender) { std::string name = sender->getName(); if (name == "do") { InformationManager::Instance()->postDataToFeed("gui_event", DataContainer(DO_BUTTON)); } if (name == "exit") { InformationManager::Instance()->postDataToFeed("gui_event", DataContainer(EXIT_BUTTON)); } }
void GuiPopup::ButtonClick(MyGUI::WidgetPtr wp) { // get result button id btnResult = -1; sscanf(wp->getName().c_str(), "PopBtn%d", &btnResult); // save return fields from edits EditBox* ed; ed = (EditBox*)mWnd->findWidget("PopEdit0"); if (ed) edit0 = ed->getCaption(); ed = (EditBox*)mWnd->findWidget("PopEdit1"); if (ed) edit1 = ed->getCaption(); ed = (EditBox*)mWnd->findWidget("PopEdit2"); if (ed) edit2 = ed->getCaption(); ed = (EditBox*)mWnd->findWidget("PopEdit3"); if (ed) edit3 = ed->getCaption(); //Hide(); // done in delegate mDelegates(); }
SpaceShipDesignerGUI::SpaceShipDesignerGUI(ENGINE *engine, SpaceShipDesigner *parent) { mParent = parent; mEngine = engine; mGUI = engine->loadGUI("Designer.layout"); for(MyGUI::VectorWidgetPtr::iterator i=mGUI.begin(); i!=mGUI.end(); ++i) { MyGUI::WidgetPtr w = *i; if(w->getName() == "Root") { mRoot = w; mRoot->setSize(mEngine->getWindow()->getWidth(), mEngine->getWindow()->getHeight()); for(size_t j=0; j<mRoot->getChildCount(); j++) { if(w->getChildAt(j)->getTypeName() == "Button") w->getChildAt(j)->eventMouseButtonClick = MyGUI::newDelegate(SpaceShipDesignerGUI::buttonClicked); else if(w->getChildAt(j)->getTypeName() == "EditBox") ((MyGUI::EditBox *)w->getChildAt(j))->eventEditTextChange = MyGUI::newDelegate(SpaceShipDesignerGUI::editBoxUpdated); } } } }
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()); } }