void touchmind::view::linkedge::impl::ArrowLinkEdgeView::CreateDeviceDependentResources(
    touchmind::Context *pContext, ID2D1RenderTarget *pRenderTarget) {
  if (GetLinkModel().expired()) {
    return;
  }
  auto link = GetLinkModel().lock();
  if (!link->IsValid()) {
    return;
  }
  auto linkEdge = link->GetEdge(GetEdgeId());
  auto node = link->GetNode(GetEdgeId());
  if (linkEdge->IsRepaintRequired(GetRepaintCounter()) || m_pArrowGeometry == nullptr || m_pBrush == nullptr) {
    ID2D1Factory *pD2DFactory = pContext->GetD2DFactory();

    D2D1_POINT_2F point0 = link->GetEdgePoint(GetEdgeId());
    std::vector<D2D1_POINT_2F> points;
    view::GeometryBuilder::CalculateArrowPoints(point0, linkEdge->GetMarkerSize() + link->GetLineWidth(),
                                                linkEdge->GetMarkerSize() + link->GetLineWidth(), linkEdge->GetAngle(),
                                                node->GetAncestorPosition(), points);
    m_pArrowGeometry = nullptr;
    CHK_RES(m_pArrowGeometry,
            view::GeometryBuilder::CreatePathGeometryFromPoints(pD2DFactory, points, &m_pArrowGeometry));

    m_pBrush = nullptr;
    CHK_RES(m_pBrush, pRenderTarget->CreateSolidColorBrush(link->GetLineColor(), D2D1::BrushProperties(), &m_pBrush));
    SetRepaintCounter(linkEdge);
  }
}
Esempio n. 2
0
void touchmind::print::XPSPrint::_PrintLinkEdge(
    const std::shared_ptr<touchmind::model::link::LinkModel> &link,
    EDGE_ID edgeId )
{
    auto linkEdge = link->GetEdge(edgeId);
    if (linkEdge->GetStyle() == EDGE_STYLE_NORMAL) {
        return;
    }
    FLOAT markerSize = linkEdge->GetMarkerSize();
    auto node = link->GetNode(edgeId);
    D2D1_POINT_2F point0 = link->GetEdgePoint(edgeId);
    NODE_SIDE nodeSide = link->GetNode(edgeId)->GetAncestorPosition();

    CComPtr<IXpsOMVisualCollection> canvasVisuals = nullptr;
    CHK_HR(m_pXpsCanvas->GetVisuals(&canvasVisuals));

    COLORREF colorref = util::ColorUtil::ToColorref(link->GetLineColor());
    CComPtr<IXpsOMSolidColorBrush> strokeBrush = nullptr;
    XPS_COLOR bodyColor;
    bodyColor.colorType        = XPS_COLOR_TYPE_SRGB;
    bodyColor.value.sRGB.alpha = 0xFF;
    bodyColor.value.sRGB.red   = GetRValue(colorref);
    bodyColor.value.sRGB.green = GetGValue(colorref);
    bodyColor.value.sRGB.blue  = GetBValue(colorref);
    CHK_RES(strokeBrush,
            m_pXpsFactory->CreateSolidColorBrush(&bodyColor, nullptr, &strokeBrush));

    CComPtr<IXpsOMGeometryFigure> xpsFigure = nullptr;
    if (linkEdge->GetStyle() == EDGE_STYLE_CIRCLE) {
        FLOAT shift = (nodeSide == NODE_SIDE_RIGHT ? markerSize / 2.0f : -markerSize / 2.0f);
        XPSGeometryBuilder::CreateCircleGeometry(
            m_pXpsFactory,
            D2D1::Point2F(point0.x + shift, point0.y),
            markerSize / 2.0f,
            &xpsFigure);
    } else {
        std::vector<D2D1_POINT_2F> points;
        view::GeometryBuilder::CalculateArrowPoints(
            point0,
            linkEdge->GetMarkerSize() + link->GetLineWidth(),
            linkEdge->GetMarkerSize() + link->GetLineWidth(),
            linkEdge->GetAngle(),
            node->GetAncestorPosition(),
            points);
        XPSGeometryBuilder::CreatePathGeometryFromPoints(
            m_pXpsFactory,
            points,
            &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> xpsPath = nullptr;
    CHK_RES(xpsPath, m_pXpsFactory->CreatePath(&xpsPath));
    CHK_HR(xpsPath->SetFillBrushLocal(strokeBrush));
    CHK_HR(xpsPath->SetGeometryLocal(xpsGeometry));
    CHK_HR(canvasVisuals->Append(xpsPath));
}