static int l_vbox(lua_State *l) { UI::Context *c = LuaObject<UI::Context>::CheckFromLua(1); if (lua_gettop(l) > 1) LuaObject<UI::VBox>::PushToLua(c->VBox(luaL_checknumber(l, 2))); else LuaObject<UI::VBox>::PushToLua(c->VBox()); return 1; }
static int l_image(lua_State *l) { UI::Context *c = LuaObject<UI::Context>::CheckFromLua(1); const std::string filename(luaL_checkstring(l, 2)); UI::Image::StretchMode stretchMode = UI::Image::STRETCH_PRESERVE_ASPECT; if (lua_gettop(l) > 2) stretchMode = static_cast<UI::Image::StretchMode>(LuaConstants::GetConstantFromArg(l, "UIImageStretchMode", 3)); LuaObject<UI::Image>::PushToLua(c->Image(filename, stretchMode)); return 1; }
static int l_colorbackground(lua_State *l) { UI::Context *c = LuaObject<UI::Context>::CheckFromLua(1); float r = luaL_checknumber(l, 2); float g = luaL_checknumber(l, 3); float b = luaL_checknumber(l, 4); float a = 1.0f; if (lua_gettop(l) > 4) a = luaL_checknumber(l, 5); LuaObject<UI::ColorBackground>::PushToLua(c->ColorBackground(Color(r,g,b,a))); return 1; }
static int l_grid(lua_State *l) { UI::Context *c = LuaObject<UI::Context>::CheckFromLua(1); UI::CellSpec rowSpec(0), colSpec(0); if (lua_istable(l, 2)) rowSpec = UI::CellSpec::FromLuaTable(l, 2); else rowSpec = UI::CellSpec(luaL_checkinteger(l, 2)); if (lua_istable(l, 3)) colSpec = UI::CellSpec::FromLuaTable(l, 3); else colSpec = UI::CellSpec(luaL_checkinteger(l, 3)); LuaObject<UI::Grid>::PushToLua(c->Grid(rowSpec, colSpec)); return 1; }
static int l_scroller(lua_State *l) { UI::Context *c = LuaObject<UI::Context>::CheckFromLua(1); LuaObject<UI::Scroller>::PushToLua(c->Scroller()); return 1; }
static int l_align(lua_State *l) { UI::Context *c = LuaObject<UI::Context>::CheckFromLua(1); UI::Align::Direction dir = static_cast<UI::Align::Direction>(LuaConstants::GetConstantFromArg(l, "UIAlignDirection", 2)); LuaObject<UI::Align>::PushToLua(c->Align(dir)); return 1; }
static int l_margin(lua_State *l) { UI::Context *c = LuaObject<UI::Context>::CheckFromLua(1); LuaObject<UI::Margin>::PushToLua(c->Margin(luaL_checknumber(l, 2))); return 1; }
static int l_background(lua_State *l) { UI::Context *c = LuaObject<UI::Context>::CheckFromLua(1); LuaObject<UI::Background>::PushToLua(c->Background()); return 1; }
void ModelViewer::SetupUI() { UI::Context *c = m_ui.Get(); c->SetFont(UI::Widget::FONT_XSMALL); for (unsigned int i=0; i<9; i++) colorSliders[i] = 0; for (unsigned int i=0; i<6; i++) thrustSliders[i] = 0; animSlider = 0; animValue = 0; if (!m_model) return SetupFilePicker(); const int spacing = 5; UI::SmallButton *reloadButton; UI::SmallButton *toggleGridButton; UI::CheckBox *collMeshCheck; UI::CheckBox *gunsCheck; UI::VBox* outerBox = c->VBox(); UI::VBox* mainBox = c->VBox(5); UI::VBox* bottomBox = c->VBox(5); UI::HBox* sliderBox = c->HBox(); bottomBox->PackEnd(sliderBox); outerBox->PackEnd(UI::WidgetSet( c->Expand()->SetInnerWidget(c->Grid(UI::CellSpec(0.20f,0.8f,0.25f),1) ->SetColumn(0, mainBox) ->SetColumn(2, m_logScroller.Get()) ), bottomBox )); c->SetInnerWidget(c->Margin(spacing)->SetInnerWidget(outerBox)); //model name + reload button: visible even if loading failed mainBox->PackEnd(nameLabel = c->Label(m_modelName)); nameLabel->SetFont(UI::Widget::FONT_NORMAL); add_pair(c, mainBox, reloadButton = c->SmallButton(), "Reload model"); reloadButton->onClick.connect(sigc::bind(sigc::mem_fun(*this, &ModelViewer::OnReloadModel), reloadButton)); if (m_model == 0) { c->Layout(); return; } add_pair(c, mainBox, toggleGridButton = c->SmallButton(), "Grid mode"); add_pair(c, mainBox, collMeshCheck = c->CheckBox(), "Collision mesh"); //pattern selector if (m_model->SupportsPatterns()) { mainBox->PackEnd(c->Label("Pattern:")); mainBox->PackEnd(patternSelector = c->DropDown()->AddOption("Default")); sliderBox->PackEnd( c->Grid(3,4) ->SetColumn(0, UI::WidgetSet( c->Label("Color 1"), c->HBox(spacing)->PackEnd(c->Label("R"))->PackEnd(colorSliders[0] = c->HSlider()), c->HBox(spacing)->PackEnd(c->Label("G"))->PackEnd(colorSliders[1] = c->HSlider()), c->HBox(spacing)->PackEnd(c->Label("B"))->PackEnd(colorSliders[2] = c->HSlider()) )) ->SetColumn(1, UI::WidgetSet( c->Label("Color 2"), c->HBox(spacing)->PackEnd(c->Label("R"))->PackEnd(colorSliders[3] = c->HSlider()), c->HBox(spacing)->PackEnd(c->Label("G"))->PackEnd(colorSliders[4] = c->HSlider()), c->HBox(spacing)->PackEnd(c->Label("B"))->PackEnd(colorSliders[5] = c->HSlider()) )) ->SetColumn(2, UI::WidgetSet( c->Label("Color 3"), c->HBox(spacing)->PackEnd(c->Label("R"))->PackEnd(colorSliders[6] = c->HSlider()), c->HBox(spacing)->PackEnd(c->Label("G"))->PackEnd(colorSliders[7] = c->HSlider()), c->HBox(spacing)->PackEnd(c->Label("B"))->PackEnd(colorSliders[8] = c->HSlider()) )) ); //connect slider signals, set initial values (RGB) const float values[] = { 1.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 1.f }; for(unsigned int i=0; i<3*3; i++) { colorSliders[i]->SetValue(values[i]); colorSliders[i]->onValueChanged.connect(sigc::mem_fun(*this, &ModelViewer::OnModelColorsChanged)); } //// slidems end patternSelector->onOptionSelected.connect(sigc::mem_fun(*this, &ModelViewer::OnPatternChanged)); UpdatePatternList(); } //decal selector //models support up to 4 but 1 is enough here if (m_model->SupportsDecals()) { mainBox->PackEnd(c->Label("Decal:")); mainBox->PackEnd(decalSelector = c->DropDown()); decalSelector->onOptionSelected.connect(sigc::mem_fun(*this, &ModelViewer::OnDecalChanged)); std::vector<std::string> decals; collect_decals(decals); for (std::vector<std::string>::const_iterator it = decals.begin(); it != decals.end(); ++it) { decalSelector->AddOption(*it); } } //light dropdown UI::DropDown *lightSelector; mainBox->PackEnd(c->Label("Lights:")); mainBox->PackEnd( lightSelector = c->DropDown() ->AddOption("1 Front white") ->AddOption("2 Two-point") ->AddOption("3 Backlight") //->AddOption("4 Nuts") ); m_options.lightPreset = 0; add_pair(c, mainBox, gunsCheck = c->CheckBox(), "Attach guns"); //Animation controls if (!m_model->GetAnimations().empty()) { //UI::Button *playBtn; //UI::Button *revBtn; //UI::Button *stopBtn; UI::Box *animBox; mainBox->PackEnd(animBox = c->VBox(spacing)); animBox->PackEnd(m_ui->Label("Animation:")); animBox->PackEnd(animSelector = m_ui->DropDown()->AddOption("None")); //add_pair(m_ui, animBox, playBtn = m_ui->Button(), "Play/Pause"); //add_pair(m_ui, animBox, revBtn = m_ui->Button(), "Play reverse"); //add_pair(m_ui, animBox, stopBtn = m_ui->Button(), "Stop"); bottomBox->PackStart(c->HBox(10)->PackEnd(UI::WidgetSet(c->Label("Animation:"), animSlider = c->HSlider(), animValue = c->Label("0.0")))); animValue->SetFont(UI::Widget::FONT_NORMAL); //playBtn->onClick.connect(sigc::bind(sigc::mem_fun(*this, &ModelViewer::OnAnimPlay), playBtn, false)); //revBtn->onClick.connect(sigc::bind(sigc::mem_fun(*this, &ModelViewer::OnAnimPlay), revBtn, true)); //stopBtn->onClick.connect(sigc::bind(sigc::mem_fun(*this, &ModelViewer::OnAnimStop), stopBtn)); animSlider->onValueChanged.connect(sigc::mem_fun(*this, &ModelViewer::OnAnimSliderChanged)); animSelector->onOptionSelected.connect(sigc::mem_fun(*this, &ModelViewer::OnAnimChanged)); //update anims from model UpdateAnimList(); } //// Thrust sliders bool supportsThrusters = false; { SceneGraph::FindNodeVisitor fivi(SceneGraph::FindNodeVisitor::MATCH_NAME_STARTSWITH, "thruster_"); m_model->GetRoot()->Accept(fivi); supportsThrusters = !fivi.GetResults().empty(); } if (supportsThrusters) { sliderBox->PackStart( c->Grid(2,4) ->SetColumn(0, UI::WidgetSet( // Column 1, Linear thrust sliders c->Label("Linear"), c->HBox(spacing)->PackEnd(c->Label("X"))->PackEnd(thrustSliders[0] = c->HSlider()), c->HBox(spacing)->PackEnd(c->Label("Y"))->PackEnd(thrustSliders[1] = c->HSlider()), c->HBox(spacing)->PackEnd(c->Label("Z"))->PackEnd(thrustSliders[2] = c->HSlider()) )) ->SetColumn(1, UI::WidgetSet( //Column 2, Angular thrust sliders c->Label("Angular"), c->HBox(spacing)->PackEnd(c->Label("Pitch"))->PackEnd(thrustSliders[3] = c->HSlider()), c->HBox(spacing)->PackEnd(c->Label("Yaw"))->PackEnd(thrustSliders[4] = c->HSlider()), c->HBox(spacing)->PackEnd(c->Label("Roll"))->PackEnd(thrustSliders[5] = c->HSlider()) )) ); for(unsigned int i=0; i<2*3; i++) { thrustSliders[i]->SetValue(0.5f); thrustSliders[i]->onValueChanged.connect(sigc::mem_fun(*this, &ModelViewer::OnThrustChanged)); } ////thruster sliders end } c->Layout(); //event handlers collMeshCheck->onClick.connect(sigc::bind(sigc::mem_fun(*this, &ModelViewer::OnToggleCollMesh), collMeshCheck)); gunsCheck->onClick.connect(sigc::bind(sigc::mem_fun(*this, &ModelViewer::OnToggleGuns), gunsCheck)); lightSelector->onOptionSelected.connect(sigc::mem_fun(*this, &ModelViewer::OnLightPresetChanged)); toggleGridButton->onClick.connect(sigc::bind(sigc::mem_fun(*this, &ModelViewer::OnToggleGrid), toggleGridButton)); }
static int l_attr_templates(lua_State *l) { UI::Context *c = LuaObject<UI::Context>::CheckFromLua(1); c->GetTemplateStore().PushCopyToStack(); return 1; }
static int l_dropdown(lua_State *l) { UI::Context *c = LuaObject<UI::Context>::CheckFromLua(1); LuaObject<UI::DropDown>::PushToLua(c->DropDown()); return 1; }
static int l_list(lua_State *l) { UI::Context *c = LuaObject<UI::Context>::CheckFromLua(1); LuaObject<UI::List>::PushToLua(c->List()); return 1; }
static int l_vslider(lua_State *l) { UI::Context *c = LuaObject<UI::Context>::CheckFromLua(1); LuaObject<UI::VSlider>::PushToLua(c->VSlider()); return 1; }
static int l_checkbox(lua_State *l) { UI::Context *c = LuaObject<UI::Context>::CheckFromLua(1); LuaObject<UI::CheckBox>::PushToLua(c->CheckBox()); return 1; }
static int l_button(lua_State *l) { UI::Context *c = LuaObject<UI::Context>::CheckFromLua(1); LuaObject<UI::Button>::PushToLua(c->Button()); return 1; }
static int l_multilinetext(lua_State *l) { UI::Context *c = LuaObject<UI::Context>::CheckFromLua(1); LuaObject<UI::MultiLineText>::PushToLua(c->MultiLineText(luaL_checkstring(l, 2))); return 1; }
static int l_label(lua_State *l) { UI::Context *c = LuaObject<UI::Context>::CheckFromLua(1); LuaObject<UI::Label>::PushToLua(c->Label(luaL_checkstring(l, 2))); return 1; }
void ModelViewer::SetupFilePicker() { UI::Context *c = m_ui.Get(); UI::List *list = c->List(); UI::Button *quitButton = c->Button(); UI::Button *loadButton = c->Button(); quitButton->SetInnerWidget(c->Label("Quit")); loadButton->SetInnerWidget(c->Label("Load")); std::vector<std::string> models; collect_models(models); for (std::vector<std::string>::const_iterator it = models.begin(); it != models.end(); ++it) { list->AddOption(*it); } UI::Widget *fp = c->Grid(UI::CellSpec(1,3,1), UI::CellSpec(1,3,1)) ->SetCell(1,1, c->VBox(10) ->PackEnd(c->Label("Select a model")) ->PackEnd(c->Expand(UI::Expand::BOTH)->SetInnerWidget(c->Scroller()->SetInnerWidget(list))) ->PackEnd(c->Grid(2,1)->SetRow(0, UI::WidgetSet( c->Align(UI::Align::LEFT)->SetInnerWidget(loadButton), c->Align(UI::Align::RIGHT)->SetInnerWidget(quitButton) ))) ); m_logScroller->Layout(); //issues without this c->SetInnerWidget(c->Grid(2,1) ->SetRow(0, UI::WidgetSet(fp, m_logScroller.Get())) ); c->Layout(); loadButton->onClick.connect(sigc::bind(sigc::mem_fun(*this, &ModelViewer::OnPickModel), list)); quitButton->onClick.connect(sigc::mem_fun(*this, &ModelViewer::OnQuit)); }