tgparkk / notepad

1 stars 0 forks source link

Draw line #15

Open tgparkk opened 2 weeks ago

tgparkk commented 2 weeks ago
void CLayerHDMap::DrawLine(Gdiplus::Graphics& graphics, Gdiplus::Pen& pen, const std::vector<POINT2D>& geo, LineStyle style) {
    std::vector<Gdiplus::Point> pPoints;
    pPoints.reserve(geo.size());

    Gdiplus::GraphicsPath path(Gdiplus::FillModeAlternate);

    for (const auto& point : geo) {
        auto screenPt = mWndManager->MapToScreen(point);
        pPoints.emplace_back(screenPt);
    }

    switch (style) {
        case LineStyle::Solid: {
            // 기본 실선
            path.AddLines(&pPoints[0], pPoints.size());
            break;
        }
        case LineStyle::Zigzag: {
            // 지그재그 효과 추가
            for (size_t i = 0; i < pPoints.size() - 1; i++) {
                Gdiplus::Point pt1 = pPoints[i];
                Gdiplus::Point pt2 = pPoints[i + 1];
                Gdiplus::Point mid((pt1.X + pt2.X) / 2, (pt1.Y + pt2.Y) / 2 + 5); // 중간에 오프셋 추가
                path.AddLine(pt1, mid);
                path.AddLine(mid, pt2);
            }
            break;
        }
        case LineStyle::DoubleSolid: {
            // 두 줄 실선
            Gdiplus::Pen pen2(pen.GetColor(), pen.GetWidth() / 2);
            Gdiplus::Matrix offset;
            offset.Translate(3, 0);
            pen2.SetTransform(&offset);
            graphics.DrawPath(&pen2, &path);
            path.AddLines(&pPoints[0], pPoints.size());
            break;
        }
        case LineStyle::SolidDashed: {
            // 실선과 점선 조합
            Gdiplus::Pen dashedPen(pen.GetColor(), pen.GetWidth());
            dashedPen.SetDashStyle(Gdiplus::DashStyleDash);
            graphics.DrawPath(&dashedPen, &path);
            path.AddLines(&pPoints[0], pPoints.size());
            break;
        }
        case LineStyle::DoubleDashed: {
            // 두 줄 점선
            Gdiplus::Pen dashedPen(pen.GetColor(), pen.GetWidth());
            dashedPen.SetDashStyle(Gdiplus::DashStyleDash);
            path.AddLines(&pPoints[0], pPoints.size());
            graphics.DrawPath(&dashedPen, &path);
            break;
        }
        case LineStyle::DoubleZigzag: {
            // 두 줄 지그재그
            for (size_t i = 0; i < pPoints.size() - 1; i++) {
                Gdiplus::Point pt1 = pPoints[i];
                Gdiplus::Point pt2 = pPoints[i + 1];
                Gdiplus::Point mid((pt1.X + pt2.X) / 2, (pt1.Y + pt2.Y) / 2 + 5);
                path.AddLine(pt1, mid);
                path.AddLine(mid, pt2);
            }
            break;
        }
    }

    graphics.DrawPath(&pen, &path);
}
tgparkk commented 1 week ago

enum class LineStyle { Solid, // 기본 실선 Zigzag, // 지그재그 DoubleSolid, // 두 줄 실선 SolidDashed, // 실선 + 점선 DoubleDashed, // 두 줄 점선 DoubleZigzag // 두 줄 지그재그 };

tgparkk commented 1 week ago
void CLayerHDMap::DrawSolidLine(Gdiplus::Graphics& graphics, Gdiplus::Pen& pen, const std::vector<POINT2D>& geo) {
    std::vector<Gdiplus::Point> pPoints;
    pPoints.reserve(geo.size());

    for (const auto& point : geo) {
        auto screenPt = mWndManager->MapToScreen(point);
        pPoints.emplace_back(screenPt);
    }

    Gdiplus::GraphicsPath path(Gdiplus::FillModeAlternate);
    path.AddLines(&pPoints[0], pPoints.size());

    graphics.DrawPath(&pen, &path);
}
void CLayerHDMap::DrawZigzagLine(Gdiplus::Graphics& graphics, Gdiplus::Pen& pen, const std::vector<POINT2D>& geo) {
    std::vector<Gdiplus::Point> pPoints;
    pPoints.reserve(geo.size());

    for (const auto& point : geo) {
        auto screenPt = mWndManager->MapToScreen(point);
        pPoints.emplace_back(screenPt);
    }

    Gdiplus::GraphicsPath path(Gdiplus::FillModeAlternate);
    for (size_t i = 0; i < pPoints.size() - 1; i++) {
        Gdiplus::Point pt1 = pPoints[i];
        Gdiplus::Point pt2 = pPoints[i + 1];
        Gdiplus::Point mid((pt1.X + pt2.X) / 2, (pt1.Y + pt2.Y) / 2 + 5); // 중간에 오프셋 추가
        path.AddLine(pt1, mid);
        path.AddLine(mid, pt2);
    }

    graphics.DrawPath(&pen, &path);
}
void CLayerHDMap::DrawDoubleSolidLine(Gdiplus::Graphics& graphics, Gdiplus::Pen& pen, const std::vector<POINT2D>& geo, float offset) {
    std::vector<Gdiplus::Point> pPoints;
    pPoints.reserve(geo.size());

    for (const auto& point : geo) {
        auto screenPt = mWndManager->MapToScreen(point);
        pPoints.emplace_back(screenPt);
    }

    Gdiplus::GraphicsPath path1(Gdiplus::FillModeAlternate);
    Gdiplus::GraphicsPath path2(Gdiplus::FillModeAlternate);

    for (const auto& pt : pPoints) {
        path1.AddLine(pt.X - offset, pt.Y, pt.X + offset, pt.Y); // 상단 선
        path2.AddLine(pt.X, pt.Y - offset, pt.X, pt.Y + offset); // 하단 선
    }

    graphics.DrawPath(&pen, &path1);
    graphics.DrawPath(&pen, &path2);
}
void CLayerHDMap::DrawSolidDashedLine(Gdiplus::Graphics& graphics, Gdiplus::Pen& solidPen, Gdiplus::Pen& dashedPen, const std::vector<POINT2D>& geo, float offset) {
    std::vector<Gdiplus::Point> pPoints;
    pPoints.reserve(geo.size());

    for (const auto& point : geo) {
        auto screenPt = mWndManager->MapToScreen(point);
        pPoints.emplace_back(screenPt);
    }

    Gdiplus::GraphicsPath solidPath(Gdiplus::FillModeAlternate);
    Gdiplus::GraphicsPath dashedPath(Gdiplus::FillModeAlternate);

    for (const auto& pt : pPoints) {
        solidPath.AddLine(pt.X, pt.Y - offset, pt.X, pt.Y); // 위쪽 실선
        dashedPath.AddLine(pt.X, pt.Y, pt.X, pt.Y + offset); // 아래쪽 점선
    }

    graphics.DrawPath(&solidPen, &solidPath);
    graphics.DrawPath(&dashedPen, &dashedPath);
}
void CLayerHDMap::DrawDoubleDashedLine(Gdiplus::Graphics& graphics, Gdiplus::Pen& dashedPen, const std::vector<POINT2D>& geo, float offset) {
    std::vector<Gdiplus::Point> pPoints;
    pPoints.reserve(geo.size());

    for (const auto& point : geo) {
        auto screenPt = mWndManager->MapToScreen(point);
        pPoints.emplace_back(screenPt);
    }

    Gdiplus::GraphicsPath upperDashedPath(Gdiplus::FillModeAlternate);
    Gdiplus::GraphicsPath lowerDashedPath(Gdiplus::FillModeAlternate);

    for (const auto& pt : pPoints) {
        upperDashedPath.AddLine(pt.X - offset, pt.Y, pt.X, pt.Y + offset); // 상단 점선
        lowerDashedPath.AddLine(pt.X, pt.Y + offset, pt.X, pt.Y); // 하단 점선
    }

    graphics.DrawPath(&dashedPen, &upperDashedPath);
    graphics.DrawPath(&dashedPen, &lowerDashedPath);
}
void CLayerHDMap::DrawDoubleZigzagLine(Gdiplus::Graphics& graphics, Gdiplus::Pen& pen, const std::vector<POINT2D>& geo, float offset) {
    std::vector<Gdiplus::Point> pPoints;
    pPoints.reserve(geo.size());

    for (const auto& point : geo) {
        auto screenPt = mWndManager->MapToScreen(point);
        pPoints.emplace_back(screenPt);
    }

    Gdiplus::GraphicsPath upperPath(Gdiplus::FillModeAlternate);
    Gdiplus::GraphicsPath lowerPath(Gdiplus::FillModeAlternate);

    for (size_t i = 0; i < pPoints.size() - 1; i++) {
        Gdiplus::Point pt1 = pPoints[i];
        Gdiplus::Point pt2 = pPoints[i + 1];

        // 상단 지그재그
        Gdiplus::Point midUpper((pt1.X + pt2.X) / 2, (pt1.Y + pt2.Y) / 2 + offset);
        upperPath.AddLine(pt1, midUpper);
        upperPath.AddLine(midUpper, pt2);

        // 하단 지그재그
        Gdiplus::Point midLower((pt1.X + pt2.X) / 2, (pt1.Y + pt2.Y) / 2 - offset);
        lowerPath.AddLine(pt1, midLower);
        lowerPath.AddLine(midLower, pt2);
    }

    graphics.DrawPath(&pen, &upperPath);
    graphics.DrawPath(&pen, &lowerPath);
}
tgparkk commented 1 week ago
void CLayerHDMap::DrawDashedLine(Gdiplus::Graphics& graphics, Gdiplus::Pen& pen, const std::vector<POINT2D>& geo) {
    // 점선 스타일 설정
    pen.SetDashStyle(Gdiplus::DashStyleDash);

    std::vector<Gdiplus::Point> pPoints;
    pPoints.reserve(geo.size());

    for (const auto& point : geo) {
        auto screenPt = mWndManager->MapToScreen(point);
        pPoints.emplace_back(screenPt);
    }

    Gdiplus::GraphicsPath path(Gdiplus::FillModeAlternate);
    path.AddLines(&pPoints[0], pPoints.size());

    // 점선 그리기
    graphics.DrawPath(&pen, &path);
}
tgparkk commented 1 week ago
void CLayerHDMap::DrawSolidLine(Gdiplus::Graphics& graphics, const std::vector<POINT2D>& geo, Gdiplus::Color color, float width) {
    Gdiplus::Pen pen(color, width); // 펜 생성 (색상과 두께)

    std::vector<Gdiplus::Point> pPoints;
    pPoints.reserve(geo.size());

    for (const auto& point : geo) {
        auto screenPt = mWndManager->MapToScreen(point);
        pPoints.emplace_back(screenPt);
    }

    Gdiplus::GraphicsPath path(Gdiplus::FillModeAlternate);
    path.AddLines(&pPoints[0], pPoints.size());

    graphics.DrawPath(&pen, &path);
}

void CLayerHDMap::DrawDashedLine(Gdiplus::Graphics& graphics, const std::vector<POINT2D>& geo, Gdiplus::Color color, float width) {
    Gdiplus::Pen pen(color, width); // 펜 생성
    pen.SetDashStyle(Gdiplus::DashStyleDash); // 점선 스타일 설정

    std::vector<Gdiplus::Point> pPoints;
    pPoints.reserve(geo.size());

    for (const auto& point : geo) {
        auto screenPt = mWndManager->MapToScreen(point);
        pPoints.emplace_back(screenPt);
    }

    Gdiplus::GraphicsPath path(Gdiplus::FillModeAlternate);
    path.AddLines(&pPoints[0], pPoints.size());

    graphics.DrawPath(&pen, &path);
}

void CLayerHDMap::DrawZigzagLine(Gdiplus::Graphics& graphics, const std::vector<POINT2D>& geo, Gdiplus::Color color, float width) {
    Gdiplus::Pen pen(color, width); // 펜 생성

    std::vector<Gdiplus::Point> pPoints;
    pPoints.reserve(geo.size());

    for (const auto& point : geo) {
        auto screenPt = mWndManager->MapToScreen(point);
        pPoints.emplace_back(screenPt);
    }

    Gdiplus::GraphicsPath path(Gdiplus::FillModeAlternate);
    for (size_t i = 0; i < pPoints.size() - 1; i++) {
        Gdiplus::Point pt1 = pPoints[i];
        Gdiplus::Point pt2 = pPoints[i + 1];
        Gdiplus::Point mid((pt1.X + pt2.X) / 2, (pt1.Y + pt2.Y) / 2 + 5); // 중간에 오프셋 추가
        path.AddLine(pt1, mid);
        path.AddLine(mid, pt2);
    }

    graphics.DrawPath(&pen, &path);
}

void CLayerHDMap::DrawDoubleSolidLine(Gdiplus::Graphics& graphics, const std::vector<POINT2D>& geo, Gdiplus::Color color, float width, float offset) {
    Gdiplus::Pen pen(color, width); // 펜 생성

    std::vector<Gdiplus::Point> pPoints;
    pPoints.reserve(geo.size());

    for (const auto& point : geo) {
        auto screenPt = mWndManager->MapToScreen(point);
        pPoints.emplace_back(screenPt);
    }

    Gdiplus::GraphicsPath upperPath(Gdiplus::FillModeAlternate);
    Gdiplus::GraphicsPath lowerPath(Gdiplus::FillModeAlternate);

    for (const auto& pt : pPoints) {
        upperPath.AddLine(pt.X - offset, pt.Y, pt.X + offset, pt.Y); // 상단 선
        lowerPath.AddLine(pt.X, pt.Y - offset, pt.X, pt.Y + offset); // 하단 선
    }

    graphics.DrawPath(&pen, &upperPath);
    graphics.DrawPath(&pen, &lowerPath);
}

void CLayerHDMap::DrawSolidDashedLine(Gdiplus::Graphics& graphics, const std::vector<POINT2D>& geo, Gdiplus::Color solidColor, Gdiplus::Color dashedColor, float width, float offset) {
    Gdiplus::Pen solidPen(solidColor, width);  // 실선 펜
    Gdiplus::Pen dashedPen(dashedColor, width); // 점선 펜
    dashedPen.SetDashStyle(Gdiplus::DashStyleDash);

    std::vector<Gdiplus::Point> pPoints;
    pPoints.reserve(geo.size());

    for (const auto& point : geo) {
        auto screenPt = mWndManager->MapToScreen(point);
        pPoints.emplace_back(screenPt);
    }

    Gdiplus::GraphicsPath solidPath(Gdiplus::FillModeAlternate);
    Gdiplus::GraphicsPath dashedPath(Gdiplus::FillModeAlternate);

    for (const auto& pt : pPoints) {
        solidPath.AddLine(pt.X, pt.Y - offset, pt.X, pt.Y); // 위쪽 실선
        dashedPath.AddLine(pt.X, pt.Y, pt.X, pt.Y + offset); // 아래쪽 점선
    }

    graphics.DrawPath(&solidPen, &solidPath);
    graphics.DrawPath(&dashedPen, &dashedPath);
}

void CLayerHDMap::DrawDoubleDashedLine(Gdiplus::Graphics& graphics, const std::vector<POINT2D>& geo, Gdiplus::Color color, float width, float offset) {
    // 첫 번째 펜 (위쪽 점선)
    Gdiplus::Pen upperPen(color, width);
    upperPen.SetDashStyle(Gdiplus::DashStyleDash);

    // 두 번째 펜 (아래쪽 점선)
    Gdiplus::Pen lowerPen(color, width);
    lowerPen.SetDashStyle(Gdiplus::DashStyleDash);

    std::vector<Gdiplus::Point> pPoints;
    pPoints.reserve(geo.size());

    for (const auto& point : geo) {
        auto screenPt = mWndManager->MapToScreen(point);
        pPoints.emplace_back(screenPt);
    }

    Gdiplus::GraphicsPath upperPath(Gdiplus::FillModeAlternate);
    Gdiplus::GraphicsPath lowerPath(Gdiplus::FillModeAlternate);

    for (size_t i = 0; i < pPoints.size(); ++i) {
        // 위쪽 점선: y좌표에 -offset 적용
        Gdiplus::Point upperPoint(pPoints[i].X, pPoints[i].Y - offset);
        upperPath.AddLine(upperPoint, (i + 1 < pPoints.size()) ? 
                          Gdiplus::Point(pPoints[i + 1].X, pPoints[i + 1].Y - offset) : upperPoint);

        // 아래쪽 점선: y좌표에 +offset 적용
        Gdiplus::Point lowerPoint(pPoints[i].X, pPoints[i].Y + offset);
        lowerPath.AddLine(lowerPoint, (i + 1 < pPoints.size()) ? 
                          Gdiplus::Point(pPoints[i + 1].X, pPoints[i + 1].Y + offset) : lowerPoint);
    }

    // 위쪽 점선 그리기
    graphics.DrawPath(&upperPen, &upperPath);

    // 아래쪽 점선 그리기
    graphics.DrawPath(&lowerPen, &lowerPath);
}

void CLayerHDMap::DrawDoubleZigzagLine(Gdiplus::Graphics& graphics, const std::vector<POINT2D>& geo, Gdiplus::Color color, float width, float offset) {
    Gdiplus::Pen pen(color, width); // 펜 생성

    std::vector<Gdiplus::Point> pPoints;
    pPoints.reserve(geo.size());

    for (const auto& point : geo) {
        auto screenPt = mWndManager->MapToScreen(point);
        pPoints.emplace_back(screenPt);
    }

    Gdiplus::GraphicsPath upperPath(Gdiplus::FillModeAlternate);
    Gdiplus::GraphicsPath lowerPath(Gdiplus::FillModeAlternate);

    // 위쪽 지그재그와 아래쪽 지그재그를 계산
    for (size_t i = 0; i < pPoints.size() - 1; ++i) {
        // 현재 점과 다음 점
        Gdiplus::Point pt1 = pPoints[i];
        Gdiplus::Point pt2 = pPoints[i + 1];

        // 중간에 오프셋을 추가한 지그재그 점 생성
        Gdiplus::Point upperMid((pt1.X + pt2.X) / 2, (pt1.Y + pt2.Y) / 2 - offset);
        Gdiplus::Point lowerMid((pt1.X + pt2.X) / 2, (pt1.Y + pt2.Y) / 2 + offset);

        // 위쪽 지그재그
        upperPath.AddLine(pt1.X, pt1.Y - offset, upperMid.X, upperMid.Y);
        upperPath.AddLine(upperMid.X, upperMid.Y, pt2.X, pt2.Y - offset);

        // 아래쪽 지그재그
        lowerPath.AddLine(pt1.X, pt1.Y + offset, lowerMid.X, lowerMid.Y);
        lowerPath.AddLine(lowerMid.X, lowerMid.Y, pt2.X, pt2.Y + offset);
    }

    // 위쪽 및 아래쪽 지그재그 그리기
    graphics.DrawPath(&pen, &upperPath);
    graphics.DrawPath(&pen, &lowerPath);
}