/** * @file XTPMarkupPolygon.cpp * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ #include "StdAfx.h" #include "GraphicLibrary/GdiPlus/XTPGdiPlus.h" #include "Common/XTPTypeId.h" #include "Common/XTPFramework.h" #include "Common/XTPSystemHelpers.h" #include "Common/XTPSynchro.h" #include "Common/XTPApplication.h" #include "Common/XTPSingleton.h" #include "Common/XTPGdiObjects.h" #include "Common/Base/Types/XTPSize.h" #include "Common/XTPResourceManager.h" #include #include "Markup/XTPMarkupContext.h" #include "Markup/XTPMarkupObject.h" #include "Markup/XTPMarkupInputElement.h" #include "Markup/XTPMarkupUIElement.h" #include "Markup/XTPMarkupFrameworkElement.h" #include "Markup/Shapes/XTPMarkupShape.h" #include "Markup/Shapes/XTPMarkupPolygon.h" #include "Markup/XTPMarkupDrawingContext.h" #include "Markup/XTPMarkupIIDs.h" #include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" #ifdef _DEBUG # undef THIS_FILE static char THIS_FILE[] = __FILE__; # define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////////// // CXTPMarkupPolygon CXTPMarkupDependencyProperty* CXTPMarkupPolygon::m_pPointsProperty = NULL; IMPLEMENT_MARKUPCLASS(L"Polygon", CXTPMarkupPolygon, CXTPMarkupShape) void CXTPMarkupPolygon::RegisterMarkupClass() { m_pPointsProperty = CXTPMarkupDependencyProperty::Register( L"Points", MARKUP_TYPE(CXTPMarkupPointCollection), MARKUP_TYPE(CXTPMarkupPolygon), new CXTPMarkupPropertyMetadata(NULL, CXTPMarkupPropertyMetadata::flagAffectsMeasure | CXTPMarkupPropertyMetadata::flagAffectsArrange)); } CXTPMarkupPolygon::CXTPMarkupPolygon() { } CXTPMarkupPolygon::~CXTPMarkupPolygon() { } void CXTPMarkupPolygon::SetPoints(CXTPMarkupPointCollection* pPoints) { SetValue(m_pPointsProperty, pPoints); } CXTPMarkupPointCollection* CXTPMarkupPolygon::GetPoints() const { return MARKUP_STATICCAST(CXTPMarkupPointCollection, GetValue(m_pPointsProperty)); } CSize CXTPMarkupPolygon::MeasureOverride(CXTPMarkupDrawingContext* /*pDC*/, CSize szAvailableSize) { CXTPMarkupPointCollection* pPoints = GetPoints(); if (!pPoints) return CSize(0, 0); CRect rcBounds = pPoints->GetBounds(); CSize szBound(max(rcBounds.Width(), rcBounds.right), max(rcBounds.Height(), rcBounds.bottom)); if (GetStretch() != xtpMarkupStretchNone) { if (szAvailableSize.cx < INT_MAX) szBound.cx = szAvailableSize.cx; if (szAvailableSize.cy < INT_MAX) szBound.cy = szAvailableSize.cy; } return szBound; } void CXTPMarkupPolygon::OnRender(CXTPMarkupDrawingContext* pDC) { CXTPMarkupStrokeStyle strokeStyle; GetStrokeStyle(&strokeStyle); CXTPMarkupBrush* pFillBrush = GetFill(); if (!strokeStyle.pStrokeBrush && !pFillBrush) return; CXTPMarkupPointCollection* pPoints = GetPoints(); if (!pPoints) return; const CXTPMarkupPointCollection::CPointArray& arr = pPoints->GetPoints(); XTPMarkupSmoothingMode oldSmoothingMode = pDC->SetSmoothingMode(GetSmoothingMode()); if (GetStretch() != xtpMarkupStretchNone) { CXTPMarkupPointCollection::CPointArray arrStretch; pPoints->Stretch(arrStretch, GetRenderSize()); pDC->Polygon(arrStretch.GetData(), (int)arrStretch.GetSize(), &strokeStyle, pFillBrush); } else { pDC->Polygon(arr.GetData(), (int)arr.GetSize(), &strokeStyle, pFillBrush); } pDC->SetSmoothingMode(oldSmoothingMode); } #include "Common/Base/Diagnostic/XTPBeginAfxMap.h" BEGIN_DISPATCH_MAP(CXTPMarkupPolygon, CXTPMarkupShape) DISP_PROPERTY_EX_ID(CXTPMarkupPolygon, "Points", 600, OleGetPoints, OleSetPoints, VT_BSTR) END_DISPATCH_MAP() #include "Common/Base/Diagnostic/XTPEndAfxMap.h" BSTR CXTPMarkupPolygon::OleGetPoints() { CXTPMarkupPointCollection* pPoints = GetPoints(); if (NULL == pPoints) return ::SysAllocString(L""); const CXTPMarkupPointCollection::CPointArray& arr = pPoints->GetPoints(); CString strPoints; INT_PTR nCount = arr.GetSize(); WCHAR buf[0x10]; for (INT_PTR i = 0; i < nCount; i++) { const Gdiplus::GpPointF& pt = arr[i]; #if (_MSC_VER > 1310) // VS2005 swprintf_s(buf, _countof(buf), L"%g", pt.X); #else swprintf(buf, L"%g", pt.X); #endif strPoints += buf; strPoints += _T(" "); #if (_MSC_VER > 1310) // VS2005 swprintf_s(buf, _countof(buf), L"%g", pt.Y); #else swprintf(buf, L"%g", pt.Y); #endif strPoints += buf; if ((i + 1) != nCount) strPoints += _T(", "); } return strPoints.AllocSysString(); } void CXTPMarkupPolygon::OleSetPoints(LPCTSTR lpPoints) { CXTPMarkupPointCollection::CPointArray arr; if (!CXTPMarkupPointCollection::ConvertFromString(GetMarkupContext(), XTP_CT2CW(lpPoints), arr)) AfxThrowOleException(E_INVALIDARG); SetPoints(new CXTPMarkupPointCollection(arr)); } #ifdef _XTP_ACTIVEX BEGIN_INTERFACE_MAP(CXTPMarkupPolygon, CXTPMarkupFrameworkElement) INTERFACE_PART(CXTPMarkupPolygon, XTPDIID_MarkupPolygon, Dispatch) END_INTERFACE_MAP() IMPLEMENT_OLETYPELIB_EX(CXTPMarkupPolygon, XTPDIID_MarkupPolygon) #endif