void GraphicsPath::AddPolygon(const PointF* points, unsigned int pointCount) { Gdiplus::GraphicsPath* gp = reinterpret_cast<Gdiplus::GraphicsPath*>(_private); Gdiplus::PointF* gdiPoints = new Gdiplus::PointF[pointCount]; for(unsigned int a=0; a<pointCount; a++) { gdiPoints[a] = Gdiplus::PointF(points[a]._x, points[a]._y); } gp->AddPolygon(gdiPoints, pointCount); delete[] gdiPoints; }
/*Fix current cursor point.*/ HRESULT INTERACTIVE::FPressed() { if(temp_points_count <= 2) { DisplayText(L"No polygon exists"); return S_FALSE; } Gdiplus::GraphicsPath boundaries; boundaries.AddPolygon(temp_points, temp_points_count); std::wstring name(L"Object "); name.append(boost::lexical_cast<std::wstring, std::size_t>(objects.size())); std::vector<state_changes> changes; state_changes change = {"No_change", 0, 0}; changes.push_back(change); objects.push_back(SCENE_OBJECT(&boundaries, name, L"!caption!", "!sound_path!", "!caption_sound_path!", changes, false)); temp_points_count = 0; name.append(L" saved."); BMP_mix->Clear(key_color); DrawOutlines(); DisplayText(name); return S_OK; }
void VRegion::FromPolygon (const VPolygon& inPolygon) { _Release(); VPolygon* constPoly = (VPolygon*) &inPolygon; #if !USE_GDIPLUS POINT* firstPt = (POINT*) constPoly->WIN_LockPolygon(); fRegion = ::CreatePolygonRgn(firstPt, constPoly->GetPointCount(), WINDING); constPoly->WIN_UnlockPolygon(); // Note: polygon doesnt actually use fOffset. Use AdjustOrigin instead. fOffset.SetPosTo(0, 0); _AdjustOrigin(); #else Gdiplus::GraphicsPath path; path.AddPolygon((Gdiplus::PointF*)constPoly,constPoly->GetPointCount()); fRegion = new Gdiplus::Region(&path); #endif _ComputeBounds(); }
void SelectionHandler::Draw(CDC& offscreenDC) { if (m_selectionState == selstateNoSelection) return; COORD coordStart; COORD coordEnd; SHORT maxX = (m_consoleParams->dwBufferColumns > 0) ? static_cast<SHORT>(m_consoleParams->dwBufferColumns - 1) : static_cast<SHORT>(m_consoleParams->dwColumns - 1); GetSelectionCoordinates(coordStart, coordEnd); SMALL_RECT& srWindow = m_consoleInfo->csbi.srWindow; if( coordEnd.Y < srWindow.Top || coordStart.Y > srWindow.Bottom ) return; INT nXStart = (static_cast<INT>(coordStart.X) - static_cast<INT>(srWindow.Left)) * m_nCharWidth + m_nVInsideBorder; INT nYStart = (static_cast<INT>(coordStart.Y) - static_cast<INT>(srWindow.Top) ) * m_nCharHeight + m_nHInsideBorder; INT nXEnd = (static_cast<INT>( coordEnd.X) - static_cast<INT>(srWindow.Left)) * m_nCharWidth + m_nVInsideBorder; INT nYEnd = (static_cast<INT>( coordEnd.Y) - static_cast<INT>(srWindow.Top) ) * m_nCharHeight + m_nHInsideBorder; INT nXmin = (static_cast<INT>(0) - static_cast<INT>(srWindow.Left)) * m_nCharWidth + m_nVInsideBorder; INT nXmax = (static_cast<INT>(maxX) - static_cast<INT>(srWindow.Left)) * m_nCharWidth + m_nVInsideBorder; Gdiplus::Graphics gr(offscreenDC); Gdiplus::Color selectionColor; selectionColor.SetFromCOLORREF(g_settingsHandler->GetAppearanceSettings().stylesSettings.crSelectionColor); Gdiplus::Pen pen (selectionColor); Gdiplus::SolidBrush brush(Gdiplus::Color(64, selectionColor.GetR(), selectionColor.GetG(), selectionColor.GetB())); Gdiplus::GraphicsPath gp; if( nYStart == nYEnd ) { Gdiplus::Rect rect( nXStart, nYStart, (nXEnd - nXStart) + m_nCharWidth, m_nCharHeight); gp.AddRectangle(rect); } else { /* 2_________3 0______| | | 1 5___| |____________| 4 7 6 */ Gdiplus::Point points[8]; points[0].X = nXmin; points[0].Y = nYStart + m_nCharHeight; points[1].X = nXStart; points[1].Y = points[0].Y; points[2].X = points[1].X; points[2].Y = nYStart; points[3].X = nXmax + m_nCharWidth; points[3].Y = points[2].Y; points[4].X = points[3].X; points[4].Y = nYEnd; points[5].X = nXEnd + m_nCharWidth; points[5].Y = points[4].Y; points[6].X = points[5].X; points[6].Y = nYEnd + m_nCharHeight; points[7].X = points[0].X; points[7].Y = points[6].Y; gp.AddPolygon(points, 8); } gr.FillPath(&brush, &gp); gr.DrawPath(&pen, &gp); }
void CSkinUnitODL::DrawImage(Gdiplus::Graphics& gcDrawer, Gdiplus::GraphicsPath& gcPath, Gdiplus::PointF& ptOffset, Gdiplus::REAL fScale) { if (m_imgSkin) { if (m_nWrapMode>=4) { //居中模式 Gdiplus::RectF rtArea; gcPath.GetBounds(&rtArea); Gdiplus::GraphicsPath gcDrawPath; //图片中间X:(width-imagewidth )/2 + left; //Y: (height - imageheight)/2 +top; Gdiplus::REAL fX0 = (rtArea.Width - m_fSkinWidth-m_nGroutX) /2.0f + rtArea.X; Gdiplus::REAL fY0 = (rtArea.Height - m_fSkinHeight-m_nGroutY) /2.0f + rtArea.Y; Gdiplus::REAL fX1 = m_fSkinWidth + m_nGroutX+ fX0; Gdiplus::REAL fY1 = m_fSkinHeight +m_nGroutY+ fY0; std::vector<Gdiplus::PointF> arrPt; arrPt.emplace_back(fX0, fY0); arrPt.emplace_back(fX1, fY0); arrPt.emplace_back(fX1, fY1); arrPt.emplace_back(fX0, fY1); Gdiplus::Matrix mx; Gdiplus::PointF ptCenter=Gdiplus::PointF((fX1+fX0)/2.0f, (fY1+fY0)/2.0f); mx.RotateAt(m_fRotate, ptCenter); mx.TransformPoints(arrPt.data(), arrPt.size()); gcDrawPath.AddPolygon(arrPt.data(),arrPt.size()); //如果图片的path大于当前区域Path,则居中操作在区域内 { BRepBuilderAPI_MakePolygon ply1; for (auto& ptPos:arrPt) { ply1.Add(gp_Pnt(ptPos.X, 0.0f, ptPos.Y)); } ply1.Close(); TopoDS_Face face1 = BRepBuilderAPI_MakeFace(ply1.Wire()).Face(); std::vector<Gdiplus::PointF> arrPic; arrPic.resize(gcDrawPath.GetPointCount()); gcPath.GetPathPoints(arrPic.data(), arrPic.size()); BRepBuilderAPI_MakePolygon ply2; for (auto& ptPos:arrPic) { ply2.Add(gp_Pnt(ptPos.X, 0.0f, ptPos.Y)); } ply2.Close(); TopoDS_Face face2 = BRepBuilderAPI_MakeFace(ply2.Wire()).Face(); BRepAlgoAPI_Common bc(face1, face2); auto face = bc.Shape(); TopExp_Explorer expWire(face, TopAbs_WIRE); std::vector<Gdiplus::PointF> arrDraw; for ( BRepTools_WireExplorer expVertex(TopoDS::Wire(expWire.Current())); expVertex.More(); expVertex.Next() ) { auto pnt = BRep_Tool::Pnt(expVertex.CurrentVertex()); arrDraw.emplace_back(static_cast<Gdiplus::REAL>(pnt.X()), static_cast<Gdiplus::REAL>(pnt.Z())); } gcDrawPath.Reset(); gcDrawPath.AddPolygon(arrDraw.data(), arrDraw.size()); } Gdiplus::WrapMode wmMode=(Gdiplus::WrapMode)m_nWrapMode; if (std::fabs(m_fRotate)<0.001f) { Gdiplus::TextureBrush brush(m_imgSkin, wmMode); mx.Translate(fX0, fY0); brush.SetTransform(&mx); gcDrawer.FillPath(&brush, &gcDrawPath); } else { Gdiplus::TextureBrush brush(m_imgSkin, wmMode); mx.Translate(fX0, fY0); brush.SetTransform(&mx); gcDrawer.FillPath(&brush, &gcDrawPath); } } else { //铺满模式 Gdiplus::WrapMode wmMode=(Gdiplus::WrapMode)m_nWrapMode; if (std::fabs(m_fRotate)<0.001f) { Gdiplus::TextureBrush brush(m_imgSkin, wmMode); brush.TranslateTransform(ptOffset.X, ptOffset.Y); gcDrawer.FillPath(&brush, &gcPath); } else { Gdiplus::TextureBrush brush(m_imgSkin, wmMode); brush.TranslateTransform(ptOffset.X, ptOffset.Y); brush.RotateTransform(m_fRotate); gcDrawer.FillPath(&brush, &gcPath); } } } }
/* Function creates objects from script - first it take names and than it creates path for a region and afterwards the map of state changes. */ bool INTERACTIVE::CreateObjects() { // attributes std::wstring name; std::wstring caption; std::string sound_path; std::string caption_sound_path; bool finish_scene; // object's space Gdiplus::GraphicsPath boundaries; int verticle_count; Gdiplus::Point * verticles; int x, y; // caused changes std::string state_name; std::vector<state_changes> changes; // control bool verticles_OK = true; // Tag is not necessary for the editor if(!script.FindElem(L"OBJECTS")) return true; script.IntoElem(); // Tag is not necessary for the editor if(!script.FindElem(L"OBJECT")){ script.OutOfElem(); return true; } else do { // atributes reading name = script.GetAttrib(L"name"); caption = script.GetAttrib(L"caption"); sound_path = wstring2string(script.GetAttrib(L"sound_source")); caption_sound_path = wstring2string(script.GetAttrib(L"caption_sound")); verticle_count = atoi((wstring2string(script.GetAttrib(L"v_count"))).c_str()); if(verticle_count < 3){ Log("Verticle count in one of the objects is too low"); verticles_OK = false; } finish_scene = (atoi((wstring2string(script.GetAttrib(L"finish_scene"))).c_str())) != 0 ? true : false; script.IntoElem(); // Jumps into the object if(!CheckTests()){ script.OutOfElem(); continue; } // creates verticles for the object polygon verticles = new Gdiplus::Point [verticle_count]; for(int i = 0; i < verticle_count; i++){ if(!script.FindElem(L"VERTEX")){ Log("There is not responding count of vertices in one object in script."); verticles_OK = false; } x = atoi((wstring2string(script.GetAttrib(L"x"))).c_str()); y = atoi((wstring2string(script.GetAttrib(L"y"))).c_str()); verticles[i] = Gdiplus::Point(x, y); } if(!verticles_OK){ delete [] verticles; script.OutOfElem(); continue; } else{ boundaries.AddPolygon(verticles, verticle_count); delete [] verticles; } // creates the vector of state changes while(script.FindElem(L"STATECHANGE")){ state_changes current_changes; current_changes.name = wstring2string(script.GetData()); current_changes.value = atoi((wstring2string(script.GetAttrib(L"value"))).c_str()); current_changes.replace = atoi((wstring2string(script.GetAttrib(L"replace"))).c_str()) != 0 ? true : false; changes.push_back(current_changes); } script.OutOfElem(); // Jumps out of the object objects.push_back(SCENE_OBJECT(&boundaries, name, caption, sound_path, caption_sound_path, changes, finish_scene)); boundaries.Reset(); changes.clear(); } while(script.FindElem(L"OBJECT")); script.OutOfElem(); return true; }
void CControlArrowStyleSelector::Draw(CDC* pDC) { CRect rc(m_rcControl); int nCount = sizeof(arrowStyles) / sizeof(arrowStyles[0]); for (int i = 0; i < nCount; i++) { CRect rcButton = GetRect(i); if (i == m_nSelected || arrowStyles[i].iArrowStyle == m_iArrowStyle) { BOOL bPressed = GetPressed() && i == m_nSelected; //GetPaintManager()->DrawControlEntry(pDC, &rcButton, m_bEnabled, i == m_nSelected, bPressed, arrowStyles[i].iArrowStyle == m_iArrowStyle, FALSE, GetParent()->GetPosition()); GetPaintManager()->DrawRectangle(pDC, &rcButton, i == m_nSelected, bPressed, m_bEnabled, arrowStyles[i].iArrowStyle == m_iArrowStyle, FALSE, GetParent()->GetType(), GetParent()->GetPosition()); } Gdiplus::Graphics gdipGraphics(pDC->m_hDC); Gdiplus::Pen pen(Gdiplus::Color(255, 0, 0, 0), 1); Gdiplus::SolidBrush brush(Gdiplus::Color(255, 0, 0, 0)); /* if (arrowStyles[i].iArrowStyle == msoLineRoundDot) pen.SetDashCap(Gdiplus::DashCapTriangle); else pen.SetDashCap(Gdiplus::DashCapFlat); pen.SetDashPattern(arrowStyles[i].dashValues, arrowStyles[i].iDashValueCount); pen.SetDashStyle(Gdiplus::DashStyleCustom);*/ // Gdiplus::Point points[3] = {Gdiplus::Point(0, 0), Gdiplus::Point(0, 0), Gdiplus::Point(0, 0)}; Gdiplus::GraphicsPath startCapPath; Gdiplus::GraphicsPath endCapPath; // Create a CustomLineCap object with capPath as the stroke path. int yPos = rcButton.top + XTP_AS_SELECTOR_HEIGHT / 2; switch(arrowStyles[i].startCap) { case Gdiplus::LineCapArrowAnchor: { Gdiplus::AdjustableArrowCap capStart(9, 9, false); pen.SetCustomStartCap(&capStart); break; } case Gdiplus::LineCapTriangle: { Gdiplus::AdjustableArrowCap capStart(6, 5, true); pen.SetCustomStartCap(&capStart); break; } case Gdiplus::LineCapDiamondAnchor: { Gdiplus::Point points[4] = {Gdiplus::Point(rcButton.left , yPos ), Gdiplus::Point(rcButton.left + 5, yPos + 5), Gdiplus::Point(rcButton.left + 10, yPos), Gdiplus::Point(rcButton.left + 5, yPos - 5)}; startCapPath.AddPolygon(points, 4); break; } case Gdiplus::LineCapRoundAnchor: { Gdiplus::Rect rect(rcButton.left, yPos - 5, 10, 10); startCapPath.AddEllipse(rect); break; } default: break; } switch(arrowStyles[i].endCap) { case Gdiplus::LineCapArrowAnchor: { Gdiplus::AdjustableArrowCap capEnd(9, 9, false); pen.SetCustomEndCap(&capEnd); break; } case Gdiplus::LineCapTriangle: { Gdiplus::AdjustableArrowCap capEnd(6, 5, true); pen.SetCustomEndCap(&capEnd); break; } case Gdiplus::LineCapDiamondAnchor: { Gdiplus::Point points[4] = {Gdiplus::Point(rcButton.right - 10 , yPos ), Gdiplus::Point(rcButton.right - 5, yPos + 5), Gdiplus::Point(rcButton.right, yPos), Gdiplus::Point(rcButton.right - 5, yPos - 5)}; endCapPath.AddPolygon(points, 4); break; } case Gdiplus::LineCapRoundAnchor: { Gdiplus::Rect rect(rcButton.right - 10, yPos - 5, 10, 10); endCapPath.AddEllipse(rect); break; } default: break; } if (!m_bEnabled) { pen.SetColor(Gdiplus::Color(255, 128, 128, 128)); brush.SetColor(Gdiplus::Color(255, 128, 128, 128)); } gdipGraphics.DrawLine(&pen, Gdiplus::Point(rcButton.left + 2, yPos), Gdiplus::Point(rcButton.right-2, yPos)); gdipGraphics.FillPath(&brush,&startCapPath); gdipGraphics.FillPath(&brush,&endCapPath); } }