bool TextWindowHandler::handleKey(const InputEvent &e) { DisplayWindow * d; e.fprint( stderr ); InputState * wimp = _wm->wimp(); wimp->setEvent(e); bool ret = false; if (wimp->ctrlDown ) { bool ret = true; switch ( wimp->lastKey ) { case KEY_CTRL_N: fprintf(stderr,"Make new window\n"); d = new DisplayWindow(); d->setContent(new TextContent()); _wm->addWindow(d); d->moveto(wimp->lastPos[0], wimp->lastPos[1] ); break; case KEY_CTRL_F: case KEY_CTRL_O: //create new window and pass the call down... if ( !_wm->top()) { DirScanner dr; fileData * f = dr.openFileDialog(); fileData * nf = f; int c = 0; while ( nf ) { EM_log( CK_LOG_INFO, "(audicle) opening file %d : %s", c, nf->fileName.c_str()); d = new DisplayWindow(); TextContent * ntext = new TextContent(); ntext->open((char*)nf->fileName.c_str()); d->setContent(ntext); Point2D np = wimp->lastPos + Point2D(0.03, -0.03 ) * (double)c; d->moveto(np[0], np[1] ); _wm->addWindow(d); _wm->setTopWindow(d); c++; nf = nf->next; } } break; default: ret = false; } } return ret; }
bool ResizeBrushesToolController::doStartMouseDrag(const InputState& inputState) { if (!handleInput(inputState)) return false; const bool split = inputState.modifierKeysDown(ModifierKeys::MKCtrlCmd); if (m_tool->beginResize(inputState.pickResult(), split)) { updateDragFaces(inputState); return true; } return false; }
void MenuView::OnUpdate(const float dt) { InputState inputState; mCommon->getInputState(&inputState); accumulatorKeyPress -= dt; if (accumulatorKeyPress <= 0) { accumulatorKeyPress = 0; } if (inputState.isDown(Button::BUTTON_MOUSELEFT) && accumulatorKeyPress == 0) { mModel->CheckInput(Vec2(inputState.mMouseX, inputState.mMouseY)); accumulatorKeyPress = delayKeyPress; } }
RestrictedDragPolicy::DragInfo ClipToolController::MoveClipPointPart::doStartDrag(const InputState& inputState) { if (inputState.mouseButtons() != MouseButtons::MBLeft || inputState.modifierKeys() != ModifierKeys::MKNone) return DragInfo(); Vec3 initialPoint; if (!m_callback->tool()->beginDragPoint(inputState.pickResult(), initialPoint)) return DragInfo(); DragRestricter* restricter = m_callback->createDragRestricter(inputState, initialPoint); DragSnapper* snapper = m_callback->createDragSnapper(inputState); return DragInfo(restricter, snapper, initialPoint); }
RestrictedDragPolicy::DragInfo ClipToolController::AddClipPointPart::doStartDrag(const InputState& inputState) { if (inputState.mouseButtons() != MouseButtons::MBLeft || inputState.modifierKeys() != ModifierKeys::MKNone) return DragInfo(); Vec3 initialPoint; if (!m_callback->addClipPoint(inputState, initialPoint)) return DragInfo(); m_secondPointSet = false; DragRestricter* restricter = m_callback->createDragRestricter(inputState, initialPoint); DragSnapper* snapper = m_callback->createDragSnapper(inputState); return DragInfo(restricter, snapper, initialPoint); }
bool doGetNewClipPointPosition(const InputState& inputState, Vec3& position) const { const Renderer::Camera& camera = inputState.camera(); const Vec3 viewDir = camera.direction().firstAxis(); const Ray3& pickRay = inputState.pickRay(); const Vec3 defaultPos = m_tool->defaultClipPointPos(); const FloatType distance = pickRay.intersectWithPlane(viewDir, defaultPos); if (Math::isnan(distance)) return false; position = pickRay.pointAtDistance(distance); const Grid& grid = m_tool->grid(); position = grid.snap(position); return true; }
void CreateBrushTool::handleResetPlane(InputState& inputState, Planef& plane, Vec3f& initialPoint) { float distance = plane.intersectWithRay(inputState.pickRay()); if (Math<float>::isnan(distance)) return; initialPoint = inputState.pickRay().pointAtDistance(distance); if (inputState.modifierKeys() == ModifierKeys::MKAlt) { Vec3f planeNorm = inputState.pickRay().direction; planeNorm[2] = 0.0f; planeNorm.normalize(); plane = Planef(planeNorm, initialPoint); } else { plane = Planef::horizontalDragPlane(initialPoint); } }
void ResizeBrushesToolController::doPick(const InputState& inputState, Model::PickResult& pickResult) { if (handleInput(inputState)) { const Model::Hit hit = doPick(inputState.pickRay(), pickResult); if (hit.isMatch()) pickResult.addHit(hit); } }
bool SetBrushFaceAttributesTool::performCopy(const InputState& inputState, const bool applyToBrush) { if (!applies(inputState)) return false; MapDocumentSPtr document = lock(m_document); const Model::BrushFaceList& selectedFaces = document->selectedBrushFaces(); if (selectedFaces.size() != 1) return false; const Model::Hit& hit = inputState.pickResult().query().pickable().type(Model::Brush::BrushHit).occluded().first(); if (!hit.isMatch()) return false; Model::BrushFace* source = selectedFaces.front(); Model::BrushFace* targetFace = Model::hitToFace(hit); Model::Brush* targetBrush = targetFace->brush(); const Model::BrushFaceList targetList = applyToBrush ? targetBrush->faces() : Model::BrushFaceList(1, targetFace); const Transaction transaction(document); document->deselectAll(); document->select(targetList); if (copyAttributes(inputState)) document->setFaceAttributes(source->attribs()); else document->setTexture(source->texture()); document->deselectAll(); document->select(source); return true; }
Vec3::List getHelpVectors(const InputState& inputState) const { const Model::Hit& hit = inputState.pickResult().query().pickable().type(Model::Brush::BrushHit).occluded().first(); assert(hit.isMatch()); Model::BrushFace* face = Model::hitToFace(hit); return selectHelpVectors(face, hit.hitPoint()); }
void CameraTool2D::doMouseScroll(const InputState& inputState) { if (zoom(inputState)) { const float speed = pref(Preferences::CameraMouseWheelInvert) ? -1.0f : 1.0f; if (inputState.scrollY() != 0.0f) { const Vec2f mousePos(static_cast<float>(inputState.mouseX()), static_cast<float>(inputState.mouseY())); const Vec3f oldWorldPos = m_camera.unproject(mousePos.x(), mousePos.y(), 0.0f); const float factor = 1.0f + inputState.scrollY() / 50.0f * speed; m_camera.zoom(factor); const Vec3f newWorldPos = m_camera.unproject(mousePos.x(), mousePos.y(), 0.0f); const Vec3f delta = newWorldPos - oldWorldPos; m_camera.moveBy(-delta); } } }
MoveObjectsToolController::MoveInfo MoveObjectsToolController::doStartMove(const InputState& inputState) { if (!inputState.modifierKeysPressed(ModifierKeys::MKNone) && !inputState.modifierKeysPressed(ModifierKeys::MKAlt) && !inputState.modifierKeysPressed(ModifierKeys::MKCtrlCmd) && !inputState.modifierKeysPressed(ModifierKeys::MKCtrlCmd | ModifierKeys::MKAlt)) return MoveInfo(); const Model::PickResult& pickResult = inputState.pickResult(); const Model::Hit& hit = pickResult.query().pickable().type(Model::Group::GroupHit | Model::Entity::EntityHit | Model::Brush::BrushHit).selected().first(); if (!hit.isMatch()) return MoveInfo(); if (!m_tool->startMove(inputState)) return MoveInfo(); return MoveInfo(hit.hitPoint()); }
void NetworkClient::SendCommand(InputState & _inputState) { if (networkState == NetworkState::WELCOMED) { clock_t time = clock(); if (time > timeOfLastMove + FREQUENCY_SENDING_COMMANDS) { if (_inputState.GetXs() != 0) { std::string message = std::string(HEADER_TRYPOSITION) + "_" + /*std::to_string(id) + "_" + */std::to_string(_inputState.GetXs()); _inputState.Reset(); Send(message); } timeOfLastMove = time; } } }
void EntitiesEditor::onInput(const InputState &state) { auto mouse_pos = state.mousePos() - clippedRect().min; computeCursor(mouse_pos, mouse_pos, state.isKeyPressed(InputKey::lshift)); if(state.isKeyDown('s')) { m_mode = Mode::selecting; sendEvent(this, Event::button_clicked, m_mode); } if(state.isKeyDown('p')) { m_mode = Mode::placing; sendEvent(this, Event::button_clicked, m_mode); } if(m_proto) { int inc = 0; if(state.isKeyDown(InputKey::left)) inc = -1; if(state.isKeyDown(InputKey::right)) inc = 1; int dir_count = m_proto->sprite().dirCount(0); if(inc && dir_count) m_proto_angle = (m_proto_angle + inc + dir_count) % dir_count; m_proto->setDirAngle(constant::pi * 2.0f * (float)m_proto_angle / float(dir_count)); } if(state.isKeyPressed(InputKey::del)) { for(int i = 0; i < (int)m_selected_ids.size(); i++) m_entity_map.remove(m_selected_ids[i]); m_selected_ids.clear(); } m_view.update(state); }
void update(const Window::WindowState& windowState, const InputState& inputState, f32 timeStep) override { if (m_viewportRect != windowState.rect) { m_viewportRect = windowState.rect; //glViewport(0, 0, m_viewportRect.width, m_viewportRect.height); } if (inputState.keyPressed(GLFW_KEY_ESCAPE)) { m_engine->stop(); } }
DragInfo doStartDrag(const InputState& inputState) { if (!inputState.modifierKeysDown(ModifierKeys::MKShift)) return DragInfo(); if (!m_tool->polyhedron().polygon()) return DragInfo(); m_oldPolyhedron = m_tool->polyhedron(); const Polyhedron3::FaceHit hit = m_oldPolyhedron.pickFace(inputState.pickRay()); const Vec3 origin = inputState.pickRay().pointAtDistance(hit.distance); const Vec3 direction = hit.face->normal(); const Line3 line(origin, direction); m_dragDir = line.direction; return DragInfo(new LineDragRestricter(line), new NoDragSnapper(), origin); }
bool doGetNewClipPointPosition(const InputState& inputState, Vec3& position) const { const Model::Hit& hit = inputState.pickResult().query().pickable().type(Model::Brush::BrushHit).occluded().first(); if (!hit.isMatch()) return false; Model::BrushFace* face = hit.target<Model::BrushFace*>(); const Grid& grid = m_tool->grid(); position = grid.snap(hit.hitPoint(), face->boundary()); return true; }
void UVRotateTool::doRender(const InputState& inputState, Renderer::RenderContext& renderContext, Renderer::RenderBatch& renderBatch) { if (!m_helper.valid()) return; const Model::PickResult& pickResult = inputState.pickResult(); const Model::Hit& angleHandleHit = pickResult.query().type(AngleHandleHit).occluded().first(); const bool highlight = angleHandleHit.isMatch() || thisToolDragging(); renderBatch.addOneShot(new Render(m_helper, CenterHandleRadius, RotateHandleRadius, highlight)); }
void View::update(const InputState &state) { if(state.isKeyDown('g')) { if(m_is_visible) { if(m_cell_size == 3) m_cell_size = 6; else if(m_cell_size == 6) m_cell_size = 9; else { m_cell_size = 1; m_is_visible = false; } } else { m_cell_size = 3; m_is_visible = true; } } int height_change = state.mouseWheelMove() + (state.isKeyDownAuto(InputKey::pagedown)? -1 : 0) + (state.isKeyDownAuto(InputKey::pageup)? 1 : 0); if(height_change) m_height = clamp(m_height + height_change, 0, (int)Grid::max_height); { int actions[TileGroup::Group::side_count] = { InputKey::kp_1, InputKey::kp_2, InputKey::kp_3, InputKey::kp_6, InputKey::kp_9, InputKey::kp_8, InputKey::kp_7, InputKey::kp_4 }; for(int n = 0; n < arraySize(actions); n++) if(state.isKeyDownAuto(actions[n])) m_view_pos += worldToScreen(TileGroup::Group::s_side_offsets[n] * m_cell_size); } if((state.isKeyPressed(InputKey::lctrl) && state.isMouseButtonPressed(InputButton::left)) || state.isMouseButtonPressed(InputButton::middle)) m_view_pos -= state.mouseMove(); IRect rect = worldToScreen(IBox(int3(0, 0, 0), asXZY(m_tile_map.dimensions(), 256))); m_view_pos = clamp(m_view_pos, rect.min, rect.max - m_view_size); }
bool RotateObjectsTool::handleStartDrag(InputState& inputState) { if (inputState.mouseButtons() != MouseButtons::MBLeft || inputState.modifierKeys() != ModifierKeys::MKNone) return false; Model::EditStateManager& editStateManager = document().editStateManager(); const Model::EntityList& entities = editStateManager.selectedEntities(); const Model::BrushList& brushes = editStateManager.selectedBrushes(); if (entities.empty() && brushes.empty()) return false; Model::RotateHandleHit* hit = static_cast<Model::RotateHandleHit*>(inputState.pickResult().first(Model::HitType::RotateHandleHit, true, view().filter())); if (hit == NULL) return false; Vec3f test = hit->hitPoint() - m_rotateHandle.position(); switch (hit->hitArea()) { case Model::RotateHandleHit::HAXAxis: m_axis = Vec3f::PosX; m_invert = ((test.dot(Vec3f::PosX) > 0.0f) == (test.dot(Vec3f::PosY) > 0.0f)); break; case Model::RotateHandleHit::HAYAxis: m_axis = Vec3f::PosY; m_invert = ((test.dot(Vec3f::PosX) > 0.0f) != (test.dot(Vec3f::PosY) > 0.0f)); break; case Model::RotateHandleHit::HAZAxis: m_axis = Vec3f::PosZ; m_invert = false; break; } m_startX = inputState.x(); m_startY = inputState.y(); m_angle = 0.0f; m_center = m_rotateHandle.position(); m_rotateHandle.lock(); beginCommandGroup(Controller::Command::makeObjectActionName(wxT("Rotate"), entities, brushes)); return true; }
bool CameraTool2D::doMouseDrag(const InputState& inputState) { if (pan(inputState)) { const Vec2f currentMousePos(static_cast<float>(inputState.mouseX()), static_cast<float>(inputState.mouseY())); const Vec3f lastWorldPos = m_camera.unproject(m_lastMousePos.x(), m_lastMousePos.y(), 0.0f); const Vec3f currentWorldPos = m_camera.unproject(currentMousePos.x(), currentMousePos.y(), 0.0f); const Vec3f delta = currentWorldPos - lastWorldPos; m_camera.moveBy(-delta); m_lastMousePos = currentMousePos; return true; } return false; }
void RotateObjectsTool::handleRender(InputState& inputState, Renderer::Vbo& vbo, Renderer::RenderContext& renderContext) { Model::EditStateManager& editStateManager = document().editStateManager(); if (editStateManager.selectedEntities().empty() && editStateManager.selectedBrushes().empty()) return; Model::RotateHandleHit* hit = NULL; if (m_rotateHandle.locked()) hit = m_rotateHandle.lastHit(); else hit = static_cast<Model::RotateHandleHit*>(inputState.pickResult().first(Model::HitType::RotateHandleHit, true, view().filter())); m_rotateHandle.render(hit, vbo, renderContext, m_angle); }
void CreateEntityTool::updateEntityPosition(InputState& inputState) { assert(m_entity != NULL); Utility::Grid& grid = document().grid(); Model::FaceHit* hit = static_cast<Model::FaceHit*>(inputState.pickResult().first(Model::HitType::FaceHit, true, view().filter())); Vec3f delta; if (hit == NULL) { Vec3f newPosition = inputState.camera().defaultPoint(inputState.pickRay().direction); const Vec3f& center = m_entity->bounds().center(); delta = grid.moveDeltaForEntity(center, document().map().worldBounds(), newPosition - center); } else { Model::Face& face = hit->face(); delta = grid.moveDeltaForEntity(face, m_entity->bounds(), document().map().worldBounds(), inputState.pickRay(), hit->hitPoint()); } if (delta.null()) return; m_entity->setProperty(Model::Entity::OriginKey, m_entity->origin() + delta, true); m_entityFigure->invalidate(); }
void ClipToolController::Callback::renderFeedback(const InputState& inputState, Renderer::RenderContext& renderContext, Renderer::RenderBatch& renderBatch) { if (inputState.anyToolDragging()) return; Vec3 position; if (!doGetNewClipPointPosition(inputState, position)) return; if (!m_tool->canAddPoint(position)) return; m_tool->renderFeedback(renderContext, renderBatch, position); }
void InputDeviceTouch::InternalUpdate(InputDeltaState* delta) { impl_->Update(delta); if ((manager_.IsDebugRenderingEnabled() || IsDebugRenderingEnabled()) && manager_.GetDebugRenderer()) { DebugRenderer* debugRenderer = manager_.GetDebugRenderer(); InputState* state = GetInputState(); for (unsigned i = 0; i < TouchPointCount; ++i) { if (state->GetBool(Touch0Down + i*4)) { const float x = state->GetFloat(Touch0X + i*4); const float y = state->GetFloat(Touch0Y + i*4); debugRenderer->DrawCircle(x, y, 0.03f); } } } }
void ActionMap::UpdateMapping(const InputState & input) { std::map<Action, ActionState::AState, ActionComparer>::iterator i = _actionMap.begin(); _input = &input; for (;i != _actionMap.end(); i++) { if (input.KeyDown(i->first.Key)) { i->second = ActionState::Pressed; } else if (input.KeyUp(i->first.Key)) { i->second = ActionState::Released; } else { i->second = ActionState::None; } if (i->first.MouseButtons) { if (i->first.MouseButtons & input.mbPressed) { i->second = ActionState::Pressed; } else if (i->first.MouseButtons & input.mbReleased) { i->second = ActionState::Released; } } } }
DragInfo doStartDrag(const InputState& inputState) { if (inputState.modifierKeysDown(ModifierKeys::MKShift)) return DragInfo(); const Model::PickResult& pickResult = inputState.pickResult(); const Model::Hit& hit = pickResult.query().pickable().type(Model::Brush::BrushHit).occluded().first(); if (!hit.isMatch()) return DragInfo(); m_oldPolyhedron = m_tool->polyhedron(); const Model::BrushFace* face = Model::hitToFace(hit); m_plane = face->boundary(); m_initialPoint = hit.hitPoint(); updatePolyhedron(m_initialPoint); SurfaceDragRestricter* restricter = new SurfaceDragRestricter(); restricter->setPickable(true); restricter->setType(Model::Brush::BrushHit); restricter->setOccluded(true); return DragInfo(restricter, new NoDragSnapper(), m_initialPoint); }
bool CreateComplexBrushToolController3D::doMouseDoubleClick(const InputState& inputState) { if (!inputState.mouseButtonsDown(MouseButtons::MBLeft)) return false; if (!inputState.checkModifierKeys(MK_No, MK_No, MK_No)) return false; const Model::PickResult& pickResult = inputState.pickResult(); const Model::Hit& hit = pickResult.query().pickable().type(Model::Brush::BrushHit).occluded().first(); if (!hit.isMatch()) return false; Polyhedron3 polyhedron = m_tool->polyhedron(); const Model::BrushFace* face = Model::hitToFace(hit); const Model::BrushFace::VertexList vertices = face->vertices(); Model::BrushFace::VertexList::const_iterator it, end; for (it = vertices.begin(), end = vertices.end(); it != end; ++it) polyhedron.addPoint((*it)->position()); m_tool->update(polyhedron); return true; }
bool CreateComplexBrushToolController3D::doMouseClick(const InputState& inputState) { if (!inputState.mouseButtonsDown(MouseButtons::MBLeft)) return false; if (!inputState.checkModifierKeys(MK_No, MK_No, MK_No)) return false; const Model::PickResult& pickResult = inputState.pickResult(); const Model::Hit& hit = pickResult.query().pickable().type(Model::Brush::BrushHit).occluded().first(); if (!hit.isMatch()) return false; const Grid& grid = m_tool->grid(); const Model::BrushFace* face = Model::hitToFace(hit); const Vec3 snapped = grid.snap(hit.hitPoint(), face->boundary()); Polyhedron3 polyhedron = m_tool->polyhedron(); polyhedron.addPoint(snapped); m_tool->update(polyhedron); return true; }
bool View::update(const InputState & state) { std::list<View*> copy = m_children; copy.sort([](View* v1, View* v2) { return v1->z() > v2->z(); }); for (View* v : copy) { if (v->containsPoint(state.getCursor())) { if (v->update(state)) { return true; } } } return onUpdate(state); }