int playstate::Canvas_Show(lua_State* L) { int numParams = lua_gettop(L); if(numParams < 1) { luaM_printerror(L, "Expected: Canvas.Show(name : String)"); return 0; } const playstate::string name = lua_tostring(L, -1); lua_pop(L, 1); Canvas& canvas = GameRunner::Get().GetCanvas(); CanvasGroup* group = canvas.GetCanvasGroupByName(name); if(group != NULL) { //group->Show(); } else { luaM_printerror(L, "Could not find a CanvasGroup by the name of: '%s'", name.c_str()); } assert_not_implemented(); return 0; }
int playstate::SceneGroup_Load(lua_State* L) { const playstate::string fileName = lua_tostring(L, -1); lua_pop(L, 1); try { ScriptSystem& scriptSystem = ScriptSystem::Get(); std::auto_ptr<Script> script = scriptSystem.CompileFile(fileName); SceneGroup* group = script->ReadInstance<SceneGroup>(); if(group == NULL) { ILogger::Get().Error("The file: '%s' did not return a scene group.", fileName.c_str()); lua_pushnil(L); } else luaM_pushobject(L, "SceneGroup", group); return 1; } catch(ScriptException e) { ILogger::Get().Error("Could not load scene group: '%s'. Reason: '%s'", fileName.c_str(), e.GetMessage().c_str()); } lua_pushnil(L); return 1; }
bool ButtonControl::Render(const Canvas& canvas, GuiGeometryBuilder* builder, const Rect& rect, const playstate::string& text) { // Status used GuiMouseState::Enum state = canvas.GetMouseState(rect); const Color& buttonColorTop = mButtonColors[2 * (uint32)state]; const Color& buttonColorBotton = mButtonColors[2 * (uint32)state + 1]; const Color& fontColor = mFontColors[(uint32)state]; // Add body builder->AddGradientQuad(rect, buttonColorTop, buttonColorBotton); if(mFont.IsNotNull() && !text.empty()) { builder->AddText(mFont.Get(), rect, fontColor, text, FontAlign::CENTER); } if(state == GuiMouseState::HOVER && canvas.GetMouseClick() == MouseButtons::LEFT) { return true; } return false; }
bool CheckboxControl::Render(const Canvas& canvas, GuiGeometryBuilder* builder, const Rect& rect, bool toggled, const playstate::string& text) { // Status used GuiMouseState::Enum state = canvas.GetMouseState(rect); const uint32 checkboxBorderOffset = 1U; const uint32 checkboxToggleOffset = checkboxBorderOffset + 3U; // Add border around checkbox button const Rect checkboxButtonBorder(rect.Position, Size(mCheckboxSize, mCheckboxSize)); builder->AddQuad(checkboxButtonBorder, Color::Black); // Add checkbox button const Color& boxColorTop = mCheckboxColors[2 * (uint32)state]; const Color& boxColorBottom = mCheckboxColors[2 * (uint32)state + 1]; const Rect checkboxButton(rect.Position + Point(checkboxBorderOffset, checkboxBorderOffset), Size(mCheckboxSize - (checkboxBorderOffset * 2), mCheckboxSize - (checkboxBorderOffset * 2))); builder->AddGradientQuad(checkboxButton, boxColorTop, boxColorBottom); // Add geometry if checkbox is toggled (enabled) if(toggled) { const Rect toggledCoords(rect.Position + Point(checkboxToggleOffset, checkboxToggleOffset), Size(mCheckboxSize - (checkboxToggleOffset * 2), mCheckboxSize - (checkboxToggleOffset * 2))); builder->AddQuad(toggledCoords, Color::White); } // Add checkbox text if one is present. if(text.length() > 0 && !mFont.IsNull()) { const Color& fontColor = mFontColors[toggled ? 1 : 0]; builder->AddText(mFont.Get(), rect + Rect(mCheckboxSize + 10, 0, 0, 0), fontColor, text, FontAlign::LEFT); } if(state == GuiMouseState::HOVER && canvas.GetMouseClick() == MouseButtons::LEFT) { toggled = !toggled; } return toggled; }