bool GiCanvasGdip::rawEndPath(const GiContext* ctx, bool fill) { bool ret = false; if (m_draw->m_path != NULL) { if (fill) { G::Brush* pBrush = m_draw->createBrush(ctx); if (pBrush != NULL) { ret = (G::Ok == m_draw->getDrawGs()->FillPath( pBrush, m_draw->m_path)); } } TempGdipPen pPen(m_draw, ctx); if (pPen != NULL) { ret = (G::Ok == m_draw->getDrawGs()->DrawPath(pPen, m_draw->m_path)); } delete m_draw->m_path; m_draw->m_path = NULL; } return ret; }
bool GiCanvasGdip::rawRect(const GiContext* ctx, float x, float y, float w, float h) { bool ret = false; TempGdipPen pPen(m_draw, ctx); G::Brush* pBrush = m_draw->createBrush(ctx); if (w < 0) { x += w; w = -w; } if (h < 0) { y += h; h = -h; } if (pBrush != NULL && w > 0 && h > 0) { ret = (G::Ok == m_draw->getDrawGs()->FillRectangle(pBrush, mgRound(x), mgRound(y), mgRound(w), mgRound(h))); } if (pPen != NULL && w > 0 && h > 0) { ret = (G::Ok == m_draw->getDrawGs()->DrawRectangle(pPen, mgRound(x), mgRound(y), mgRound(w), mgRound(h))); } return ret; }
bool GiCanvasGdip::rawEllipse(const GiContext* ctx, float x, float y, float w, float h) { bool ret = false; TempGdipPen pPen(m_draw, ctx); G::Brush* pBrush = m_draw->createBrush(ctx); if (w < 0) { x += w; w = -w; } if (h < 0) { y += h; h = -h; } if (pBrush != NULL && w > 0 && h > 0) { ret = (G::Ok == m_draw->getDrawGs()->FillEllipse(pBrush, x, y, w, h)); } if (pPen != NULL && w > 0 && h > 0) { ret = (G::Ok == m_draw->getDrawGs()->DrawEllipse(pPen, x, y, w, h)); } return ret; }
bool GiCanvasGdip::rawLine(const GiContext* ctx, float x1, float y1, float x2, float y2) { bool ret = false; TempGdipPen pPen(m_draw, ctx); if (pPen != NULL) { ret = (G::Ok == m_draw->getDrawGs()->DrawLine(pPen, x1, y1, x2, y2)); } return ret; }
bool GiCanvasGdip::rawBeziers(const GiContext* ctx, const Point2d* pxs, int count) { bool ret = false; TempGdipPen pPen(m_draw, ctx); if (pPen != NULL) { ret = (G::Ok == m_draw->getDrawGs()->DrawBeziers( pPen, (G::PointF*)pxs, count)); } return ret; }
bool GiCanvasGdip::rawPolygon(const GiContext* ctx, const Point2d* pxs, int count) { bool ret = false; TempGdipPen pPen(m_draw, ctx); G::Brush* pBrush = m_draw->createBrush(ctx); if (pBrush != NULL) { ret = (G::Ok == m_draw->getDrawGs()->FillPolygon(pBrush, (G::PointF*)pxs, count)); } if (pPen != NULL) { ret = (G::Ok == m_draw->getDrawGs()->DrawPolygon( pPen, (G::PointF*)pxs, count)); } return ret; }
/************************************************************************ * DrawRect * 在指定视频通道窗口画方框 / 红框(选中),或黑框(未选) * ************************************************************************/ void CDlgTempFavorite::DrawRect(int iWinID, int bHighLight) { COLORREF m_color; CDC *dc = GetDC(); switch (bHighLight) { case 0: m_color = RGB(14,84,76); break; case 1: m_color = RGB(116,236,250); break; case 2: m_color = RGB(0,200,0); break; case 3: m_color = RGB(14,84,76); break; } CRect Rect; m_ch[iWinID].GetWindowRect(&Rect); ScreenToClient(&Rect); //rc.InflateRect(1, 1, 0, 0); Rect.left--; //Rect.right++; Rect.top--; //Rect.bottom++; CPen pPen(PS_SOLID, 1, m_color); CPen *oldPen = dc->SelectObject(&pPen); dc->MoveTo(Rect.left,Rect.top); dc->LineTo(Rect.right,Rect.top); dc->LineTo(Rect.right,Rect.bottom); dc->LineTo(Rect.left,Rect.bottom); dc->LineTo(Rect.left,Rect.top); dc->SelectObject(oldPen); ReleaseDC(dc); }
bool GiCanvasGdip::rawPath(const GiContext* ctx, int count, const Point2d* pxs, const UInt8* types) { bool ret = false; G::GraphicsPath* pPath = NULL; if (pxs != NULL && types != NULL && count > 1 && (pPath = new G::GraphicsPath) != NULL) { if (NULL == ctx) ctx = getCurrentContext(); ret = m_draw->addPolyToPath(pPath, count, pxs, types); if (ret) { if (ctx->hasFillColor()) { G::Brush* pBrush = m_draw->createBrush(ctx); if (pBrush != NULL) { ret = (G::Ok == m_draw->getDrawGs()->FillPath(pBrush, pPath)); } } TempGdipPen pPen(m_draw, ctx); if (pPen != NULL) { ret = (G::Ok == m_draw->getDrawGs()->DrawPath(pPen, pPath)); } } } if (pPath != NULL) delete pPath; return ret; }
void Esh3DRenderer::render(const EshShape& in_shape, EshRendererContext& in_rendererContext,MfGdiBrush *in_brush) { ChLOG_DEBUG_START_FN; if (!setUp(in_shape, in_rendererContext)) { return; } // temporary pen & brush so I can see what I'm doing! //ChAutoPtr<MfGdiBrush> pBrush = m_driver.CreateSolidBrush(CsColour(0x88, 0x88, 0x88)); //ChAutoPtr<MfGdiPen> pPen = m_driver.CreatePen(MfGdiPen::Style_Solid, 4, CsColour(0,0,0), ChVector<ChFLT8>()); //ChAutoPtr<MfGdiBrush> pBrush = EshGdiObjectFactory::makeNullBrush(m_driver); ChAutoPtr<MfGdiPen> pPen(EshGdiObjectFactory::makeNullPen(m_driver)); // LINUX_PORT // TODO - pen must be null pen, but because faces aren't being shaded according to normal angle, an // outline is being drawn to figure out where the faces are //in_rendererContext.getDeviceContextReference().SetBrush(*pBrush); //in_rendererContext.getDeviceContextReference().TakeBrush(pBrush.giveUpOwnership()); in_rendererContext.getDeviceContextReference().TakePen(pPen.giveUpOwnership()); if (in_rendererContext.hasTransformation()) { // 2D rotation must be done before any 3D rotation/skew, so multiply on right of current // 3D world transform, which at this point will have the skew and rotation already m_worldTransform = m_worldTransform * CsMatrix3D<ChFLT8>(in_rendererContext.getTransformationMatrix()); } m_pPathData = ChNEW EshPathRendererData(*m_pGeometry, in_rendererContext); m_pPathData->init(); MfGdiDeviceContext& deviceContext = in_rendererContext.getDeviceContextReference(); // use non-const verion of method to have geometry add implied segments const EshPathCommandTable& pathCommands = m_pPathData->getPathCommandsReference(); if (pathCommands.size() == 0) { return; } bool skip = true; bool isFirstSegmentDrawn = false; CsPoint<ChFLT8> startPosition(0,0); CsPoint<ChFLT8> position(0,0); CsPoint<ChFLT8> nextPosition(0,0); const EshPathCommand* pCurrentPathCommand; const EshPathCommand* pNextPathCommand; ChUINT2 j = 0; /** * TODO - is it possible for the first path param to be an editing command? */ pNextPathCommand = &pathCommands[0]; EshPathCommandTypeEnums nextPathCommandType = pNextPathCommand->m_type; CsPlanarPolygon<ChFLT8> frontFace; CsPlanarPolygon<ChFLT8> extrusion; for (ChUINT4 i=1; i <= pathCommands.size(); i++) { pCurrentPathCommand = pNextPathCommand; // Skip editing commands skip = true; while ( skip && i < pathCommands.size()) { skip = (ESH_PATH_CMD_HA <= pathCommands[i].m_type && pathCommands[i].m_type <= ESH_PATH_CMD_HI); if(skip) { ++i; } } if (i == pathCommands.size()) { nextPathCommandType = ESH_PATH_CMD_E; } else { pNextPathCommand = &pathCommands[i]; nextPathCommandType = pNextPathCommand->m_type; } bool isLastCommand = (nextPathCommandType == ESH_PATH_CMD_E); bool isEnd = isLastCommand; switch (pCurrentPathCommand->m_type) { case ESH_PATH_CMD_L: // Line to // openClosedPath(deviceContext); for (j=0; j < pCurrentPathCommand->m_unCount; j++) { isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1); m_pPathData->getPoint(nextPosition); //m_pPathData->getPoint(nextPosition); if (!isFirstSegmentDrawn) { startPosition = position; frontFace.addPoint(m_worldTransform * ChPoint3DF8(position, m_lForeDepth)); isFirstSegmentDrawn = true; } if (m_isFilled) { frontFace.addPoint(m_worldTransform * ChPoint3DF8(nextPosition, m_lForeDepth)); } // TODO - linecap stuff makePolygon(position, nextPosition, extrusion); m_tree.insert(extrusion); position = nextPosition; } break; case ESH_PATH_CMD_C: // Cubic curve // openClosedPath(deviceContext); for (j=0; j < pCurrentPathCommand->m_unCount; j++) { ChPoint3DF8 p0(position.getX(), position.getY(), m_lForeDepth); ChPoint3DF8 p1(m_pPathData->getPointF8(), m_lForeDepth); // 1st control point ChPoint3DF8 p2(m_pPathData->getPointF8(), m_lForeDepth); // 2nd control point m_pPathData->getPoint(nextPosition); ChPoint3DF8 p3(nextPosition, m_lForeDepth); // endpoint if (!isFirstSegmentDrawn) { startPosition = position; if (m_isFilled) { frontFace.addPoint(m_worldTransform * ChPoint3DF8(position, m_lForeDepth)); } isFirstSegmentDrawn = true; } divideBezier(p0, p1, p2, p3, frontFace); position = nextPosition; } break; case ESH_PATH_CMD_M: // Move to - count is always 1 ChASSERT(pCurrentPathCommand->m_unCount == 1); m_pPathData->getPoint(position); break; case ESH_PATH_CMD_X: // Close path nextPosition = startPosition; if (position != nextPosition) { makePolygon(position, nextPosition, extrusion); m_tree.insert(extrusion); position = nextPosition; } if (m_isFilled) { m_faces.push_back(frontFace); frontFace.clear(); } isFirstSegmentDrawn = false; break; case ESH_PATH_CMD_E: // End path data attribute /* Freeform paths will not have a close path command, however, if the path is filled, we still need a polygon for that line segment. */ if (m_isFilled && position != startPosition) { makePolygon(position, startPosition, extrusion); m_tree.insert(extrusion); position = startPosition; m_faces.push_back(frontFace); frontFace.clear(); } break; case ESH_PATH_CMD_AE: // Angle ellipse to for (j=0; j < pCurrentPathCommand->m_unCount; j++) { isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1); if (!isFirstSegmentDrawn) { startPosition = makeAngleEllipse(in_rendererContext, position, false, j, frontFace); isFirstSegmentDrawn = true; } else { makeAngleEllipse(in_rendererContext, position, false, j, frontFace); } } break; case ESH_PATH_CMD_AL: // Angle ellipse for (j=0; j < pCurrentPathCommand->m_unCount; j++) { isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1); if (!isFirstSegmentDrawn) { startPosition = makeAngleEllipse(in_rendererContext, position, true, j, frontFace); isFirstSegmentDrawn = true; } else { makeAngleEllipse(in_rendererContext, position, true, j, frontFace); } } break; case ESH_PATH_CMD_AT: // Arc to for (j=0; j < pCurrentPathCommand->m_unCount; j++) { isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1); if (!isFirstSegmentDrawn) { startPosition = makeArc(position, false, j, false, frontFace); isFirstSegmentDrawn = true; } else { makeArc(position, false, j, false, frontFace); } } break; case ESH_PATH_CMD_AR: // Arc for (j=0; j < pCurrentPathCommand->m_unCount; j++) { isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1); if (!isFirstSegmentDrawn) { startPosition = makeArc(position, true, j, false, frontFace); frontFace.addPoint(m_worldTransform * ChPoint3DF8(position, m_lForeDepth)); isFirstSegmentDrawn = true; } else { makeArc(position, true, j, false, frontFace); } } break; case ESH_PATH_CMD_WA: // Clockwise arc to for (j=0; j < pCurrentPathCommand->m_unCount; j++) { isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1); if (!isFirstSegmentDrawn) { startPosition = makeArc(position, false, j, true, frontFace); isFirstSegmentDrawn = true; } else { makeArc(position, false, j, true, frontFace); } } break; case ESH_PATH_CMD_WR: // Clockwise arc for (j=0; j < pCurrentPathCommand->m_unCount; j++) { isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1); if (!isFirstSegmentDrawn) { startPosition = makeArc(position, true, j, true, frontFace); frontFace.addPoint(m_worldTransform * ChPoint3DF8(position, m_lForeDepth)); isFirstSegmentDrawn = true; } else { makeArc(position, true, j, true, frontFace); } } break; case ESH_PATH_CMD_QX: // Elliptical quadrant x for (j=0; j < pCurrentPathCommand->m_unCount; j++) { if (!isFirstSegmentDrawn) { startPosition = position; isFirstSegmentDrawn = true; } isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1); makeQuadrantArc(position, j % 2 == 0, frontFace); } break; case ESH_PATH_CMD_QY: // Elliptical quadrant y for (j=0; j < pCurrentPathCommand->m_unCount; j++) { if (!isFirstSegmentDrawn) { startPosition = position; frontFace.addPoint(m_worldTransform * ChPoint3DF8(position, m_lForeDepth)); isFirstSegmentDrawn = true; } isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1); makeQuadrantArc(position, j % 2 == 1, frontFace); } break; } } // Draw the actual shape. m_tree.render(m_driver, in_rendererContext); if (m_isFilled) { ChBYTE opacity = 255; const EshFill &fill = in_shape.getFill(); if (fill.isOpacitySet()) { opacity = fill.getOpacity() >> 8; } renderPrimaryFaces(deviceContext,in_brush,opacity); }