void ADraggableMoveTile::Tick( float DeltaTime ) { Super::Tick(DeltaTime); processMouseEvents(); UpdateDragMove(DeltaTime); UpdateIndicator(); }
void KeyBoardMouseNavigation::update(){ gadget::KeyboardMouse::EventQueue evt_queue = mKeyBoardMouse->getEventQueue (); gadget::KeyboardMouse::EventQueue::iterator itor = evt_queue.begin (); for(itor = evt_queue.begin(); itor!=evt_queue.end(); ++itor) { const gadget::EventType type = (*itor)->type (); if (type == gadget::KeyPressEvent) { gadget::KeyEventPtr key_evt = boost::dynamic_pointer_cast<gadget::KeyEvent>(*itor); processKeyBoardEvents(key_evt); } else if(type == gadget::MouseButtonPressEvent || type == gadget::MouseButtonReleaseEvent || type == gadget::MouseMoveEvent) { gadget::MouseEventPtr mouse_evt = boost::dynamic_pointer_cast<gadget::MouseEvent>(*itor); processMouseEvents(mouse_evt); } } }
int main() { int frameCnt = 0; struct timeval curTime; float dSecond = 0; float dSecondSum = 0; /* droped if more than 0.5 sec */ timeval_diff_replace(&curTime); flags.pause = GL_FALSE; flags.vsync = GL_TRUE; scene = newScene(flags.vsync); setupGLFWCallbacks(); glfwSetMousePos(scene->context->w / 2, scene->context->h / 2); while (running) { if (glfwGetWindowParam(GLFW_OPENED) == GL_FALSE) { running = GL_FALSE; break; } processKeyboardEvents(dSecond * BASE_FPS); processMouseEvents(dSecond * BASE_FPS); ++frameCnt; dSecond = timeval_diff_replace(&curTime); dSecondSum += dSecond; if (dSecondSum > 0.5f) { viewFps(frameCnt, dSecondSum); frameCnt = 0; dSecondSum = 0.0f; } if (!flags.pause) { modifyWaterMesh(scene->water, dSecond); } draw(); glfwSwapBuffers(); } freeScene(scene); return EXIT_SUCCESS; }
void GuiWarp::render() { ImGuiIO& io = ImGui::GetIO(); if (ImGui::CollapsingHeader(_name.c_str())) { auto warps = getWarps(); _currentWarpName = warps[_currentWarp]->getName(); double leftMargin = ImGui::GetCursorScreenPos().x - ImGui::GetWindowPos().x; ImGui::BeginChild("Warps", ImVec2(ImGui::GetWindowWidth() * 0.25, ImGui::GetWindowWidth() * 0.67), true); ImGui::Text("Select a warp:"); for (int i = 0; i < warps.size(); ++i) { auto& warp = warps[i]; // We need to update the underlying camera auto linkedObj = warp->getLinkedObjects(); for (auto& obj : linkedObj) if (obj->getType() == "camera") dynamic_pointer_cast<Camera>(obj)->render(); auto scene = _scene.lock(); if (_currentWarp == i) scene->sendMessageToWorld("sendAll", {warp->getName(), "showControlLattice", 1}); else scene->sendMessageToWorld("sendAll", {warp->getName(), "showControlLattice", 0}); warp->update(); auto warpSpec = warp->getSpec(); int w = ImGui::GetWindowWidth() - 4 * leftMargin; int h = w * warpSpec.height / warpSpec.width; if(ImGui::ImageButton((void*)(intptr_t)warp->getTexture()->getTexId(), ImVec2(w, h), ImVec2(0, 1), ImVec2(1, 0))) _currentWarp = i; if (ImGui::IsItemHovered()) ImGui::SetTooltip(warp->getName().c_str()); } ImGui::EndChild(); ImGui::SameLine(); ImGui::BeginChild("Configure warp", ImVec2(0, ImGui::GetWindowWidth() * 0.67), false); if (_currentWarp < warps.size()) { auto& warp = warps[_currentWarp]; Values values; ImGui::PushID(warp->getName().c_str()); warp->getAttribute("patchResolution", values); if (ImGui::InputInt("patchResolution", (int*)values[0].data(), 1, 32, ImGuiInputTextFlags_EnterReturnsTrue)) _scene.lock()->sendMessageToWorld("sendAll", {warp->getName(), "patchResolution", values[0].asInt()}); { warp->getAttribute("patchSize", values); vector<int> tmp; tmp.push_back(values[0].asInt()); tmp.push_back(values[1].asInt()); if (ImGui::InputInt2("patchSize", tmp.data(), ImGuiInputTextFlags_EnterReturnsTrue)) _scene.lock()->sendMessageToWorld("sendAll", {warp->getName(), "patchSize", tmp[0], tmp[1]}); } if (auto texture = warp->getTexture()) { auto warpSpec = warp->getSpec(); int w = ImGui::GetWindowWidth() - 2 * leftMargin; int h = w * warpSpec.height / warpSpec.width; ImGui::Image((void*)(intptr_t)texture->getTexId(), ImVec2(w, h), ImVec2(0, 1), ImVec2(1, 0)); if (ImGui::IsItemHoveredRect()) { _noMove = true; processKeyEvents(warp); processMouseEvents(warp, w, h); } else { _noMove = false; } } ImGui::PopID(); } ImGui::EndChild(); } else { auto scene = _scene.lock(); if (_currentWarpName != "") { scene->sendMessageToWorld("sendAll", {_currentWarpName, "showControlLattice", 0}); _currentWarpName = ""; } } }