void GcGraphView::draw(GiGraphics& gs) { int gridType = cmdView()->getOptionInt("showGrid", 0); if (gridType < 1 || gridType > 2 || gs.xf().getViewScale() < 0.05f) return; Box2d rect(gs.xf().getWndRectW()); GiContext ctx(0, GiColor(127, 127, 127, gridType == 2 ? 48 : 20)); if (gridType == 1) { GiContext ctx5(0, GiColor(127, 127, 127, 48)); float x = mgbase::roundReal(rect.xmin, -1) - 10; float y = mgbase::roundReal(rect.ymin, -1) - 10; int i = mgRound(x) / 10; for (; x < rect.xmax + 10; x += 10) { gs.drawLine(i++ % 5 ? &ctx : &ctx5, Point2d(x, rect.ymin), Point2d(x, rect.ymax), false); } i = mgRound(y) / 10; for (; y < rect.ymax + 10; y += 10) { gs.drawLine(i++ % 5 ? &ctx : &ctx5, Point2d(rect.xmin, y), Point2d(rect.xmax, y), false); } } else if (gridType == 2) { for (float x = rect.xmin - 10; x < rect.xmax + 10; x += 10) { for (float y = rect.ymin - 10; y < rect.ymax + 10; y += 10) { gs.drawLine(&ctx, Point2d(x, y - 0.5f), Point2d(x, y + 0.5f), false); gs.drawLine(&ctx, Point2d(x - 0.5f, y), Point2d(x + 0.5f, y), false); } } } GcBaseView::draw(gs); }
bool CDrawShapeView::showContextActions(const int* actions) { CMenu menu; CMenu* popupMenu = NULL; if (actions && actions[0]) { menu.LoadMenu(IDR_CONTEXTMENU); popupMenu = menu.GetSubMenu(0); int i, n = popupMenu->GetMenuItemCount(); for (i = 0; i < n && actions[i] > 0; i++) { m_actions[i] = actions[i]; } while (--n >= i) { m_actions[i] = 0; popupMenu->RemoveMenu(ID_DUMMY_1 + n, MF_BYCOMMAND); } } else { menu.LoadMenu(IDR_STEP1_VIEW); popupMenu = menu.GetSubMenu(1); } CPoint point(mgRound(m_proxy->motion.point.x), mgRound(m_proxy->motion.point.y)); ClientToScreen(&point); return !!popupMenu->TrackPopupMenu(TPM_RIGHTBUTTON | TPM_LEFTALIGN, point.x, point.y, GetParentFrame()); }
static BOOL PolyDraw98(HDC hdc, const Point2d *pxs, const BYTE *types, int n) { POINT pts[3]; for (int i = 0; i < n; i++) { switch (types[i] & ~kGiCloseFigure) { case kGiMoveTo: ::MoveToEx(hdc, mgRound(pxs[i].x), mgRound(pxs[i].y), NULL); break; case kGiLineTo: ::LineTo(hdc, mgRound(pxs[i].x), mgRound(pxs[i].y)); break; case kGiBeziersTo: if (i + 2 >= n) return FALSE; for (int j = 0; j < 3; j++) pxs[i+j].get(pts[j].x, pts[j].y); ::PolyBezierTo(hdc, pts, 3); i += 2; break; default: return FALSE; } if (types[i] & kGiCloseFigure) ::CloseFigure(hdc); } return TRUE; }
bool TransformCmd::draw(const MgMotion* sender, GiGraphics* gs) { if (_lastCmd) _lastCmd->draw(sender, gs); char text[20]; GiContext ctx(-10, GiColor(255, 0, 0, 128)); gs->drawLine(&ctx, getPointM(0, sender), getPointM(1, sender)); Point2d pt(getPointM(1, sender) * gs->xf().modelToDisplay()); #if defined(_MSC_VER) && _MSC_VER >= 1400 // VC8 sprintf_s(text, sizeof(text), "X %d %dd", #else sprintf(text, "X %d %dd", #endif mgRound(_axis[0].length()), mgRound(_axis[0].angle2() * _M_R2D)); gs->rawTextCenter(text, pt.x, pt.y, 40); ctx.setLineColor(GiColor(0, 0, 255, 128)); gs->drawLine(&ctx, getPointM(0, sender), getPointM(2, sender)); pt = getPointM(2, sender) * gs->xf().modelToDisplay(); #if defined(_MSC_VER) && _MSC_VER >= 1400 // VC8 sprintf_s(text, sizeof(text), "Y %d %dd", #else sprintf(text, "Y %d %dd", #endif mgRound(_axis[1].length()), mgRound(_axis[1].angle2() * _M_R2D)); gs->rawTextCenter(text, pt.x, pt.y, 40); return true; }
bool GiCanvasGdi::rawEllipse(const GiContext* ctx, float x, float y, float w, float h) { HDC hdc = m_draw->getDrawDC(); KGDIObject pen (hdc, m_draw->createPen(ctx), false); KGDIObject brush (hdc, m_draw->createBrush(ctx), false); return ::Ellipse(hdc, mgRound(x), mgRound(y), mgRound(x + w), mgRound(y + h)) ? true : false; }
bool GiCanvasGdip::drawCachedBitmap(float x, float y, bool secondBmp) { bool ret = false; G::CachedBitmap* pBmp = gdipCachedBmp(secondBmp); if (m_draw->getDrawGs() != NULL && pBmp != NULL) { ret = (G::Ok == m_draw->getDrawGs()->DrawCachedBitmap( pBmp, mgRound(x), mgRound(y))); } return ret; }
bool GiCanvasGdi::rawLine(const GiContext* ctx, float x1, float y1, float x2, float y2) { HDC hdc = m_draw->getDrawDC(); KGDIObject pen (hdc, m_draw->createPen(ctx), false); BOOL ret = ::MoveToEx(hdc, mgRound(x1), mgRound(y1), NULL); ret = ret && ::LineTo(hdc, mgRound(x2), mgRound(y2)); return ret ? true : false; }
void GiCanvasGdi::_clipBoxChanged(const RECT_2D& clipBox) { RECT rc = { mgRound(clipBox.left), mgRound(clipBox.top), mgRound(clipBox.right), mgRound(clipBox.bottom) }; HRGN hRgn = ::CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom); if (hRgn != NULL) { ::SelectClipRgn(m_draw->getDrawDC(), hRgn); ::DeleteObject(hRgn); } }
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 GdiCachedBmp::draw(const GdiDrawImplBase* pdraw, HDC destDC, float x, float y) const { bool ret = false; if (m_cachedBmp != NULL && destDC != NULL) { GiCompatibleDC memDC (pdraw->m_hdc); if (memDC != NULL) { HGDIOBJ oldBmp = ::SelectObject(memDC, m_cachedBmp); ret = ::BitBlt(destDC, mgRound(x), mgRound(y), pdraw->m_this->xf().getWidth(), pdraw->m_this->xf().getHeight(), memDC, 0, 0, SRCCOPY) != FALSE; ::SelectObject(memDC, oldBmp); } } return ret; }
bool GiCanvasGdi::rawBezierTo(float c1x, float c1y, float c2x, float c2y, float x, float y) { POINT pxs[3] = { mgRound(c1x), mgRound(c1y), mgRound(c2x), mgRound(c2y), mgRound(x), mgRound(y) }; return !!PolyBezierTo(m_draw->getDrawDC(), pxs, 3); }
long GiGdipImage::getHmHeight() const { long ret = 0; if (m_impl->bmp != NULL) { UINT h = m_impl->bmp->GetHeight(); G::REAL dpi = m_impl->bmp->GetVerticalResolution(); ret = mgRound(h / dpi * 2540); } return ret; }
long GiGdipImage::getHmWidth() const { long ret = 0; if (m_impl->bmp != NULL) { UINT w = m_impl->bmp->GetWidth(); G::REAL dpi = m_impl->bmp->GetHorizontalResolution(); ret = mgRound(w / dpi * 2540); } return ret; }
bool GiCanvasWin::rawTextOut(HDC hdc, float x, float y, UInt32 options, const RECT2D& rc, const wchar_t* str, int len, const Int32* pDx) { RECT rect = { mgRound(rc.left), mgRound(rc.top), mgRound(rc.right), mgRound(rc.bottom) }; return ::ExtTextOutW(hdc, mgRound(x), mgRound(y), options, &rect, str, len, reinterpret_cast<const INT *>(pDx)) != 0; }
bool GiCanvasGdip::drawCachedBitmap2(const GiCanvas* p, float x, float y, bool secondBmp) { bool ret = false; if (m_draw->getDrawGs() && p && p->getCanvasType() == getCanvasType()) { const GiCanvasGdip* gs = static_cast<const GiCanvasGdip*>(p); if (gs->xf().getWidth() == xf().getWidth() && gs->xf().getHeight() == xf().getHeight()) { G::CachedBitmap* pBmp = gdipCachedBmp(secondBmp); if (pBmp != NULL) { ret = (G::Ok == m_draw->getDrawGs()->DrawCachedBitmap( pBmp, mgRound(x), mgRound(y))); } } } return ret; }
HGDIOBJ createPen(const GiContext* ctx, bool rectJoin = false) { if (ctx == NULL) ctx = &m_context; if (m_pen == NULL || m_context.getLineStyle() != ctx->getLineStyle() || m_context.getLineWidth() != ctx->getLineWidth() || m_context.getLineColor() != ctx->getLineColor() || m_context.getLineAlpha() != ctx->getLineAlpha()) { m_context.setLineStyle(ctx->getLineStyle()); m_context.setLineWidth(ctx->getLineWidth(), ctx->isAutoScale()); m_context.setLineColor(ctx->getLineColor()); m_context.setLineAlpha(ctx->getLineAlpha()); if (m_pen != NULL) ::DeleteObject(m_pen); if (ctx->isNullLine() || ctx->getLineAlpha() < 127) m_pen = ::GetStockObject(NULL_PEN); else { int width = mgRound(m_this->gs()->calcPenWidth( ctx->getLineWidth(), ctx->isAutoScale())); GiColor color = m_this->gs()->calcPenColor(ctx->getLineColor()); COLORREF cr = RGB(color.r, color.g, color.b); int lineStyle = ctx->getLineStyle(); if (width > 1) { LOGBRUSH logBrush = { BS_SOLID, cr }; m_pen = ::ExtCreatePen( (rectJoin ? PS_JOIN_MITER : 0) | PS_GEOMETRIC | PS_ENDCAP_FLAT | lineStyle, width, &logBrush, 0, NULL); } else { m_pen = ::CreatePen(lineStyle, width, cr); } } } return m_pen; }
GiColor giFromCGColor(CGColorRef color) { int num = CGColorGetNumberOfComponents(color); CGColorSpaceModel space = CGColorSpaceGetModel(CGColorGetColorSpace(color)); const CGFloat *rgba = CGColorGetComponents(color); if (space == kCGColorSpaceModelMonochrome && num >= 2) { UInt8 c = (UInt8)mgRound(rgba[0] * 255); return GiColor(c, c, c, (UInt8)mgRound(rgba[1] * 255)); } if (num < 3) { return GiColor::Invalid(); } return GiColor((UInt8)mgRound(rgba[0] * 255), (UInt8)mgRound(rgba[1] * 255), (UInt8)mgRound(rgba[2] * 255), (UInt8)mgRound(CGColorGetAlpha(color) * 255)); }
bool GiCanvasWin::rawTextOut(HDC hdc, float x, float y, const wchar_t* str, int len) { return ::TextOutW(hdc, mgRound(x), mgRound(y), str, len) != 0; }
bool GiCanvasGdi::rawLineTo(float x, float y) { return ::LineTo(m_draw->getDrawDC(), mgRound(x), mgRound(y)) ? true : false; }
bool GiCanvasGdi::rawMoveTo(float x, float y) { return ::MoveToEx(m_draw->getDrawDC(), mgRound(x), mgRound(y), NULL) ? true : false; }
long GiGdipImage::getDpiX() const { return m_impl->bmp ? mgRound(m_impl->bmp->GetHorizontalResolution()) : 0; }
long GiGdipImage::getDpiY() const { return m_impl->bmp ? mgRound(m_impl->bmp->GetVerticalResolution()) : 0; }