bool Field::MoveObject(std::shared_ptr<Unit> object, const long x_steps, const long y_steps, const bool trim) { const bool x_trim = (x_steps < 0 && static_cast<size_t>(-x_steps) > object->GetX()); const bool y_trim = (y_steps < 0 && static_cast<size_t>(-y_steps) > object->GetY()); if (trim) { return MoveObjectTo(object, x_trim ? 0 : object->GetX() + x_steps, y_trim ? 0 : object->GetY() + y_steps, true); } else { return MoveObjectTo(object, object->GetX() + x_steps, object->GetY() + y_steps, trim); } }
touchmind::VISITOR_RESULT operator()(std::shared_ptr<touchmind::model::node::NodeModel> node) { D2D1_RECT_F layoutRect = D2D1::RectF(node->GetX() + m_insets.left, node->GetY() + m_insets.top, node->GetX() + node->GetWidth() - m_insets.right, node->GetY() + node->GetHeight() - m_insets.bottom); if (m_nodeIdToView.count(node->GetId()) != 0) { std::shared_ptr<touchmind::view::node::BaseNodeView> &nodeView = m_nodeIdToView[node->GetId()]; nodeView->SetHandled(); auto editControlIndex = m_nodeViewManager->GetEditControlIndexFromNodeId(node->GetId()); std::shared_ptr<touchmind::control::DWriteEditControl> editControl = m_pEditControlManager->GetEditControl(editControlIndex); if (editControl != nullptr) { editControl->SetLayoutRect(layoutRect); } } else { touchmind::control::EDIT_CONTROL_INDEX editControlIndex; HRESULT hr = m_nodeViewManager->_CreateEditControl(layoutRect, node->GetText(), &editControlIndex); if (SUCCEEDED(hr)) { auto nodeView = touchmind::view::node::NodeViewFactory::Create(node); nodeView->SetNodeViewManager(m_nodeViewManager); nodeView->SetEditControlManager(m_pEditControlManager); nodeView->SetEditControlIndex(editControlIndex); nodeView->SetHandled(); m_nodeIdToView.insert({node->GetId(), nodeView}); } else { LOG(SEVERITY_LEVEL_WARN) << L"Failed to create an edit control"; } } return touchmind::VISITOR_RESULT_CONTINUE; }
touchmind::VISITOR_RESULT operator()(std::shared_ptr<touchmind::model::node::NodeModel> node) { HRESULT hr = S_OK; m_pXPSPrint->_PrintNode(node); if (FAILED(hr)) { LOG(SEVERITY_LEVEL_WARN) << L"_PrintNodeBody failed at node(" << node->GetId() << L", hr = " << hr; return touchmind::VISITOR_RESULT_STOP; } XpsDWriteTextRenderer* pTextRenderer = m_pXPSPrint->GetTextRenderer(); touchmind::view::node::NodeViewManager *pNodeViewManager = m_pXPSPrint->GetNodeViewManager(); control::DWriteEditControlManager *pEditControlManager = m_pXPSPrint->GetEditControlManager(); control::EDIT_CONTROL_INDEX editControlIndex = pNodeViewManager->GetEditControlIndexFromNodeId(node->GetId()); std::shared_ptr<control::DWriteEditControl> pEditControl = pEditControlManager->GetEditControl(editControlIndex); if (pEditControl != nullptr) { IDWriteTextLayout* pTextLayout = pEditControl->GetTextLayout(); if (pTextLayout != nullptr) { pTextLayout->Draw(nullptr, pTextRenderer, node->GetX() + m_pXPSPrint->GetConfiguration()->GetInsets().left, node->GetY() + m_pXPSPrint->GetConfiguration()->GetInsets().top); } else { LOG(SEVERITY_LEVEL_WARN) << L"TextLayout is null"; } } else { LOG(SEVERITY_LEVEL_WARN) << L"Could not found EditControl for Node(" << node->GetId() << L")"; } return touchmind::VISITOR_RESULT_CONTINUE; }
bool UpdateMap(std::shared_ptr<VisibleObject> &player, std::vector<std::shared_ptr<VisibleObject> > &objectVec, Map &map, unsigned int &score, SoundPlayer &soundPlayer, ResourceManager &resMan) { bool powerPill(false); glm::ivec2 where((int)(player->GetX()), (int)(player->GetY())); Object obj(map.GetWhichObject(where)); if(obj == Object::tree || obj == Object::powerPill || obj == Object::specialObject) { UpdateObject(where, map, player->GetPlayer(), objectVec); switch(obj) { case Object::tree: score += 10; soundPlayer.AddToPlay(*(resMan.GetSound("chop.ogg"))); break; case Object::powerPill: score += 10; soundPlayer.AddToPlay(*(resMan.GetSound("chainsaw.ogg"))); powerPill = true; break; case Object::specialObject: soundPlayer.AddToPlay(*(resMan.GetSound("woodpile.ogg"))); score += 100; break; default: break; } } return powerPill; }
void touchmind::win::CanvasPanel::EditNode(const std::shared_ptr<touchmind::model::node::NodeModel> &node) { m_pScrollBarHelper->MoveWindowTo(node->GetX() + node->GetWidth() / 2.0f, node->GetY() + node->GetHeight() / 2.0f); Insets insets = GetTouchMindApp()->GetConfiguration()->GetInsets(); D2D1_POINT_2F nodeClientPoint; nodeClientPoint.x = node->GetX(); nodeClientPoint.y = node->GetY(); POINT nodeWindowPoint; touchmind::util::CoordinateConversion::ConvertModelToWindowCoordinate(m_hwnd, GetScrollBarHelper(), nodeClientPoint, &nodeWindowPoint); m_pEdittingNode = node; m_pNodeViewManager->SynchronizeWithModel(); auto editControlIndex = m_pNodeViewManager->GetEditControlIndexFromNodeId(m_pEdittingNode->GetId()); if (editControlIndex >= 0) { auto editControl = m_pEditControlManager->GetEditControl(editControlIndex); m_pEditControlManager->SetFocus(editControlIndex); } Invalidate(); }
void Drivetrain::MoveWithJoystick(std::shared_ptr<frc::Joystick> throttleJstick, std::shared_ptr<frc::Joystick> turnJstick) { double xValue; double yValue; xValue = turnJstick->GetX() * m_driveXScaling; yValue = throttleJstick->GetY(); if (!m_lowGear) { yValue *= m_driveYScaling; } if (m_talonValidL1 && m_talonValidR3) diffDrive->ArcadeDrive(-yValue, xValue, true); }
bool Field::Kill(std::shared_ptr<Unit> unit, const size_t reason) { auto cell = GetCell(unit->GetX(), unit->GetY()); Application *gui = Application::GetInstance(); if (cell->GetUnit() == unit) { const size_t id = unit->GetId(); *gui << "Unit "<< id << " is dead: " << pimpl_->GetReason(reason) << "\n"; const size_t x = unit->GetX(); const size_t y = unit->GetY(); const double energy = unit->GetDna("normal_weight"); const bool carnivore = unit->IsCarnivore(); cell->RemoveObject(); gui->RemoveObject(unit); unit->alive_ = false; unit->RemoveStatistics(); InsertNmo(std::make_shared<Flesh>(energy, carnivore), x, y); *gui << "Flesh of unit " << id << " inserted at: " << x << ", " << y << "\n"; return true; } else { *gui << "\nERROR: Possible lose of some object. Program will continue.\n"; return false; } }
touchmind::VISITOR_RESULT operator()(std::shared_ptr<touchmind::model::node::NodeModel> node) { static wchar_t *colors[] = { L"red", L"green", L"yellow", L"blue", L"orange", L"gray" }; out << L"<!-- " << node->GetText() << L" -->" << std::endl; out << L"<v:rect style=\"position:absolute;margin-top:" << (node->GetY() + offsetY) << L";margin-left:" << (node->GetX() + offsetX) << L";width:" << node->GetWidth() << L";height:" << node->GetHeight() << L";z-index:2\" fillcolor=\"" << colors[node->GetLevel()] << L"\" strokecolor=\"black\" strokeweight=\"1pt\"/>" << std::endl; return touchmind::VISITOR_RESULT_CONTINUE; }
void touchmind::print::XPSPrint::_PrintNode(const std::shared_ptr<touchmind::model::node::NodeModel> &node) { CComPtr<IXpsOMVisualCollection> canvasVisuals = nullptr; CHK_RES(canvasVisuals, m_pXpsCanvas->GetVisuals(&canvasVisuals)); CComPtr<IXpsOMSolidColorBrush> fillBrush = nullptr; COLORREF bgColor = touchmind::util::ColorUtil::ToColorref(node->GetBackgroundColor()); XPS_COLOR bodyColor; bodyColor.colorType = XPS_COLOR_TYPE_SRGB; bodyColor.value.sRGB.alpha = 0xff; bodyColor.value.sRGB.red = GetRValue(bgColor); bodyColor.value.sRGB.green = GetGValue(bgColor); bodyColor.value.sRGB.blue = GetBValue(bgColor); CHK_RES(fillBrush, m_pXpsFactory->CreateSolidColorBrush(&bodyColor, nullptr, &fillBrush)); CComPtr<IXpsOMSolidColorBrush> strokeBrush = nullptr; ZeroMemory(&bodyColor, sizeof(bodyColor)); bodyColor.colorType = XPS_COLOR_TYPE_SRGB; bodyColor.value.sRGB.alpha = 0xff; bodyColor.value.sRGB.red = 0; bodyColor.value.sRGB.green = 0; bodyColor.value.sRGB.blue = 0; CHK_RES(strokeBrush, m_pXpsFactory->CreateSolidColorBrush(&bodyColor, nullptr, &strokeBrush)); XPS_RECT rect = {node->GetX(), node->GetY(), node->GetWidth(), node->GetHeight()}; CComPtr<IXpsOMGeometryFigure> xpsFigure = nullptr; if (node->GetNodeShape() == NODE_SHAPE_RECTANGLE) { XPSGeometryBuilder::CreateRectangleGeometry(m_pXpsFactory, rect, &xpsFigure); } else { XPSGeometryBuilder::CreateRoundedRectangleGeometry(m_pXpsFactory, rect, 10.0f, &xpsFigure); } CComPtr<IXpsOMGeometry> xpsGeometry = nullptr; CHK_RES(xpsGeometry, m_pXpsFactory->CreateGeometry(&xpsGeometry)); CComPtr<IXpsOMGeometryFigureCollection> xpsFigureCollection = nullptr; CHK_HR(xpsGeometry->GetFigures(&xpsFigureCollection)); CHK_HR(xpsFigureCollection->Append(xpsFigure)); CComPtr<IXpsOMPath> path = nullptr; CHK_RES(path, m_pXpsFactory->CreatePath(&path)); CHK_HR(path->SetFillBrushLocal(fillBrush)); CHK_HR(path->SetStrokeBrushLocal(strokeBrush)); CHK_HR(path->SetGeometryLocal(xpsGeometry)); CHK_HR(canvasVisuals->Append(path)); }
bool Field::KillNmo(std::shared_ptr<NonMovableObject> object) { Application *gui = Application::GetInstance(); for (size_t i = 0; i < pimpl_->non_movable_objects_.size(); ++i) { if (object == pimpl_->non_movable_objects_[i]) { auto cell = GetCell(object->GetX(), object->GetY()); if (cell == nullptr) { *gui << "\nERROR: Possible lose of NonMovableObject. Program will continue.\n"; return false; } cell->RemoveObject(); gui->RemoveObject(object); if (pimpl_->non_movable_objects_.size() == 1) pimpl_->non_movable_objects_.clear(); else if (i + 1 == pimpl_->non_movable_objects_.size()) pimpl_->non_movable_objects_.pop_back(); else { pimpl_->non_movable_objects_[i] = pimpl_->non_movable_objects_.back(); pimpl_->non_movable_objects_.pop_back(); } return true; } } return false; }
// Put methods for controlling this subsystem // here. Call these from Commands. void Chassis::DriveWithStick(std::shared_ptr<Joystick> stick) { double x = stick->GetX() + biasTurn; double y = stick->GetY() + biasStraight; robotDrive41->ArcadeDrive(y, x, false); }
Texture::Texture( std::shared_ptr<Texture> tex, int x, int y, int width, int height): m_rt(tex->GetRawTexture()), m_x(tex->GetX() + x), m_y(tex->GetY() + y), m_width(width), m_height(height) { int x2 = m_x + m_width; int y2 = m_y + m_height; if (m_x < tex->GetX()) { m_x = tex->GetX(); } else if (tex->GetX() + tex->GetWidth() < m_x) { m_x = tex->GetX() + tex->GetWidth(); } if (x2 < tex->GetX()) { x2 = tex->GetX(); } else if (tex->GetX() + tex->GetWidth() < x2) { x2 = tex->GetX() + tex->GetWidth(); } if (m_y < tex->GetY()) { m_y = tex->GetY(); } else if (tex->GetY() + tex->GetHeight() < m_y) { m_y = tex->GetY() + tex->GetHeight(); } if (y2 < tex->GetY()) { y2 = tex->GetY(); } else if (tex->GetY() + tex->GetHeight() < y2) { y2 = tex->GetY() + tex->GetHeight(); } m_width = x2 - m_x; m_height = y2 - m_y; glGenBuffers(1, &m_texcoord); glBindBuffer(GL_ARRAY_BUFFER, m_texcoord); GLdouble tc[4][2] = { {GetCoordLeft() , GetCoordTop() }, {GetCoordLeft() , GetCoordBottom()}, {GetCoordRight(), GetCoordTop() }, {GetCoordRight(), GetCoordBottom()} }; glBufferData(GL_ARRAY_BUFFER, sizeof(tc) * sizeof(GLdouble), tc, GL_STATIC_DRAW); }
void touchmind::layout::LayoutManager::SecondWalk( const std::shared_ptr<touchmind::model::node::NodeModel> &tree, const std::shared_ptr<touchmind::model::node::NodeModel> &node, int level, FLOAT x, FLOAT y) { if (level <= m_configuration->GetMaxDepth()) { FLOAT xTmp = mw_rootXOffset + _GetLayoutWorkData(node)->prelim + x; FLOAT yTmp = mw_rootYOffset + y; FLOAT maxSizeTmp = 0; FLOAT nodeSizeTmp = 0; bool flag = false; switch (m_configuration->GetLayoutOrientation()) { case LAYOUT_ORIENTATION_TOP: case LAYOUT_ORIENTATION_BOTTOM: maxSizeTmp = mw_maxLevelHeight[level]; nodeSizeTmp = node->GetHeight(); break; case LAYOUT_ORIENTATION_RIGHT: case LAYOUT_ORIENTATION_LEFT: maxSizeTmp = mw_maxLevelWidth[level]; flag = true; nodeSizeTmp = node->GetWidth(); break; } switch (m_configuration->GetNodeJustification()) { case NODE_JUSTIFICATION_TOP: node->SetX(xTmp); node->SetY(yTmp); break; case NODE_JUSTIFICATION_CENTER: node->SetX(xTmp); node->SetY(yTmp + (maxSizeTmp - nodeSizeTmp) / 2); break; case NODE_JUSTIFICATION_BOTTOM: node->SetX(xTmp); node->SetY(yTmp + maxSizeTmp - nodeSizeTmp); break; } if (flag) { FLOAT swapTmp = node->GetX(); node->SetX(node->GetY()); node->SetY(swapTmp); } switch (m_configuration->GetLayoutOrientation()) { case LAYOUT_ORIENTATION_BOTTOM: node->SetY(-node->GetY() - nodeSizeTmp); break; case LAYOUT_ORIENTATION_RIGHT: node->SetX(-node->GetX() - nodeSizeTmp); break; } if (node->GetChildrenCount() != 0) { SecondWalk(tree, node->GetFirstChild(), level + 1, x + _GetLayoutWorkData(node)->modifier, y + maxSizeTmp + m_configuration->GetLevelSeparation()); } std::shared_ptr<touchmind::model::node::NodeModel> rightSibling = node->GetRightSibling(); if (rightSibling != nullptr) { SecondWalk(tree, rightSibling, level, x, y); } } }
touchmind::VISITOR_RESULT operator()(std::shared_ptr<touchmind::model::node::NodeModel> node) { node->SetX((node->GetX() + m_offsetX) * m_zoomX); node->SetY((node->GetY() + m_offsetY) * m_zoomY); return touchmind::VISITOR_RESULT_CONTINUE; }