|
|
#include "stdafx.h"
|
|
|
#include "SigmaDoc.h"
|
|
|
#include "ItemCopyAsImagePolygon.h"
|
|
|
#include "ItemExportFile.H"
|
|
|
#include "MxnFormat\AxisLayout.h"
|
|
|
#include "gdiplus.h"
|
|
|
#include <algorithm>
|
|
|
|
|
|
NItem::CItemCopyAsImagePolygon::CItemCopyAsImagePolygon(CSigmaDoc * ppDoc)
|
|
|
: CItemCopyAsImageEx(ppDoc)
|
|
|
{
|
|
|
this->SetType(ITEM_COPY_AS_IMAGE_POLYGON);
|
|
|
}
|
|
|
|
|
|
NItem::CItemCopyAsImagePolygon::~CItemCopyAsImagePolygon()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
void NItem::CItemCopyAsImagePolygon::SetPolygon(CCurveEx* pCurve)
|
|
|
{
|
|
|
m_pCurve = pCurve;
|
|
|
}
|
|
|
|
|
|
int NItem::CItemCopyAsImagePolygon::SetRange(CRect rect)
|
|
|
{
|
|
|
if (m_pCurve == nullptr)
|
|
|
{
|
|
|
m_coorRect = CRect();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
m_coorRect = GetBounds(m_pCurve);
|
|
|
}
|
|
|
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
void NItem::CItemCopyAsImagePolygon::DrawShadow(CDC *pDC, CRect &rectScreen, CRect rectCenter)
|
|
|
{
|
|
|
if (m_pCurve == nullptr)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
int width = rectScreen.right - rectScreen.left;
|
|
|
int height = rectScreen.bottom - rectScreen.top;
|
|
|
|
|
|
Gdiplus::Rect rect(rectScreen.left, rectScreen.top, width, height);
|
|
|
Gdiplus::Region region(rect);
|
|
|
|
|
|
Gdiplus::GraphicsPath polygon;
|
|
|
CreatePolygon(polygon, m_pCurve);
|
|
|
|
|
|
region.Xor(&polygon);
|
|
|
|
|
|
Gdiplus::Graphics graphics(pDC->m_hDC);
|
|
|
Gdiplus::SolidBrush brushTrans(Gdiplus::Color(228, 255, 255, 255));
|
|
|
graphics.FillRegion(&brushTrans, ®ion);
|
|
|
}
|
|
|
|
|
|
CRect NItem::CItemCopyAsImagePolygon::GetBounds(CCurveEx* pCurve)
|
|
|
{
|
|
|
std::vector<int> x;
|
|
|
std::vector<int> y;
|
|
|
|
|
|
for (int i = 0; i < pCurve->num; i++)
|
|
|
{
|
|
|
x.push_back(pCurve->x[i]);
|
|
|
y.push_back(pCurve->y[i]);
|
|
|
}
|
|
|
|
|
|
int left = *std::min_element(x.begin(), x.end());
|
|
|
int right = *std::max_element(x.begin(), x.end());
|
|
|
int top = *std::min_element(y.begin(), y.end());
|
|
|
int bottom = *std::max_element(y.begin(), y.end());
|
|
|
|
|
|
return CRect(left, top, right, bottom);
|
|
|
}
|
|
|
|
|
|
void NItem::CItemCopyAsImagePolygon::CreatePolygon(Gdiplus::GraphicsPath& polygon, CCurveEx* pCurve)
|
|
|
{
|
|
|
std::unique_ptr<Gdiplus::Point[]> points(new Gdiplus::Point[pCurve->num]);
|
|
|
for (int i = 0; i < pCurve->num; i++)
|
|
|
{
|
|
|
points[i].X = GetDC()->GetSX(pCurve->x[i]);
|
|
|
points[i].Y = GetDC()->GetSY(pCurve->y[i]);
|
|
|
}
|
|
|
polygon.AddPolygon(points.get(), pCurve->num);
|
|
|
}
|
|
|
|
|
|
void NItem::CItemCopyAsImagePolygon::TrackHandle(int nHandle, CPoint point, CDC * pDCScreen)
|
|
|
{
|
|
|
// <20><><EFBFBD>Dz<EFBFBD><C7B2><EFBFBD>Ҫ<EFBFBD><D2AA>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>ʲô<CAB2><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
}
|
|
|
|
|
|
void NItem::CItemCopyAsImagePolygon::CopyToClipboard(CRect8& rect, double scaleFactor)
|
|
|
{
|
|
|
CXyDC* pXyDc = GetDC();
|
|
|
CRect rt = pXyDc->GetScreen(rect);
|
|
|
if (rt.IsRectEmpty()) return;
|
|
|
|
|
|
//
|
|
|
pXyDc->Reduce(scaleFactor);
|
|
|
CRect rtScale = pXyDc->GetScreen(rect);
|
|
|
|
|
|
double dx = rect.left - pXyDc->left;
|
|
|
double dy = rect.top - pXyDc->top;
|
|
|
pXyDc->OffsetRect(dx, dy);
|
|
|
|
|
|
CItemExportFile ef(GetDoc());
|
|
|
CMemoryDC *pmdc = ef.ExportImage(rtScale.Size(), 24);
|
|
|
if (pmdc)
|
|
|
{
|
|
|
Gdiplus::GraphicsPath polygon;
|
|
|
CreatePolygon(polygon, m_pCurve);
|
|
|
|
|
|
Gdiplus::RectF rectF{};
|
|
|
polygon.GetBounds(&rectF, nullptr, nullptr);
|
|
|
|
|
|
Gdiplus::Rect rect(rectF.X, rectF.Y + 1, rectF.Width - 1, rectF.Height - 1);
|
|
|
Gdiplus::Region region(rect);
|
|
|
|
|
|
region.Xor(&polygon);
|
|
|
Gdiplus::Graphics graphics(pmdc->GetSafeHdc());
|
|
|
Gdiplus::SolidBrush brushTrans(Gdiplus::Color::White);
|
|
|
graphics.FillRegion(&brushTrans, ®ion);
|
|
|
|
|
|
pmdc->CopyToClipboard();
|
|
|
delete pmdc;
|
|
|
}
|
|
|
|
|
|
pXyDc->OffsetRect(-dx, -dy);
|
|
|
pXyDc->Reduce(1.0/scaleFactor);
|
|
|
}
|