void CRevisionGraphWnd::DrawGlyphs ( GraphicsDevice& graphics , Image* glyphs , const CVisibleGraphNode* node , const RectF& nodeRect , DWORD state , DWORD allowed , bool upsideDown) { // shortcut if ((state == 0) && (allowed == 0)) return; // draw all glyphs PointF topCenter (0.5f * nodeRect.GetLeft() + 0.5f * nodeRect.GetRight(), nodeRect.GetTop()); PointF rightCenter (nodeRect.GetRight(), 0.5f * nodeRect.GetTop() + 0.5f * nodeRect.GetBottom()); PointF bottomCenter (0.5f * nodeRect.GetLeft() + 0.5f * nodeRect.GetRight(), nodeRect.GetBottom()); DrawGlyphs ( graphics , glyphs , node , upsideDown ? bottomCenter : topCenter , (state & CGraphNodeStates::COLLAPSED_ABOVE) ? ExpandGlyph : CollapseGlyph , (state & CGraphNodeStates::SPLIT_ABOVE) ? JoinGlyph : SplitGlyph , upsideDown ? Below : Above , CGraphNodeStates::COLLAPSED_ABOVE , CGraphNodeStates::SPLIT_ABOVE , (allowed & CGraphNodeStates::COLLAPSED_ABOVE) != 0); DrawGlyphs ( graphics , glyphs , node , rightCenter , (state & CGraphNodeStates::COLLAPSED_RIGHT) ? ExpandGlyph : CollapseGlyph , (state & CGraphNodeStates::SPLIT_RIGHT) ? JoinGlyph : SplitGlyph , Right , CGraphNodeStates::COLLAPSED_RIGHT , CGraphNodeStates::SPLIT_RIGHT , (allowed & CGraphNodeStates::COLLAPSED_RIGHT) != 0); DrawGlyphs ( graphics , glyphs , node , upsideDown ? topCenter : bottomCenter , (state & CGraphNodeStates::COLLAPSED_BELOW) ? ExpandGlyph : CollapseGlyph , (state & CGraphNodeStates::SPLIT_BELOW) ? JoinGlyph : SplitGlyph , upsideDown ? Above : Below , CGraphNodeStates::COLLAPSED_BELOW , CGraphNodeStates::SPLIT_BELOW , (allowed & CGraphNodeStates::COLLAPSED_BELOW) != 0); }
void CRevisionGraphWnd::CutawayPoints (const RectF& rect, float cutLen, TCutRectangle& result) { result[0] = PointF (rect.X, rect.Y + cutLen); result[1] = PointF (rect.X + cutLen, rect.Y); result[2] = PointF (rect.GetRight() - cutLen, rect.Y); result[3] = PointF (rect.GetRight(), rect.Y + cutLen); result[4] = PointF (rect.GetRight(), rect.GetBottom() - cutLen); result[5] = PointF (rect.GetRight() - cutLen, rect.GetBottom()); result[6] = PointF (rect.X + cutLen, rect.GetBottom()); result[7] = PointF (rect.X, rect.GetBottom() - cutLen); }
void DrawItemCircle::initCircle(RectF rect,float pos_x,float pos_y,float radius) { setRect(rect); RectF rectCircle = RectF(pos_x - radius,pos_y - radius,radius*2.0,radius*2.0); //获得圆弧上下左右各点 PointF top( (rectCircle.GetRight() + rectCircle.GetLeft())/2 , rectCircle.GetTop() ); PointF left( rectCircle.GetLeft() , (rectCircle.GetBottom() + rectCircle.GetTop())/2 ); PointF bottom((rectCircle.GetRight() + rectCircle.GetLeft())/2,rectCircle.GetBottom()); PointF right(rectCircle.GetRight(),(rectCircle.GetBottom() + rectCircle.GetTop())/2); m_lines.clear(); m_lines.push_back(new DrawArcLine(top,left,radius,DrawTools::ArcSignLeft)); m_lines.push_back(new DrawArcLine(left,bottom,radius,DrawTools::ArcSignLeft)); m_lines.push_back(new DrawArcLine(bottom,right,radius,DrawTools::ArcSignLeft)); m_lines.push_back(new DrawArcLine(right,top,radius,DrawTools::ArcSignLeft)); }
void Window::adjust(wchar_t* largestLine, int height) { POINT pt; GetCursorPos(&pt); HMONITOR hMon = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST); MONITORINFO monInfo; monInfo.cbSize = sizeof (MONITORINFO); GetMonitorInfo(hMon , &monInfo); RectF bounds = font->getTextBounds(GetDC(NULL), monInfo.rcMonitor, largestLine); RECT rect = {0, 0, (LONG)(bounds.GetRight()) + 120, (LONG)(bounds.GetBottom()) * height + 10}; clientRect.top = rect.top; clientRect.left = rect.left; clientRect.bottom = rect.bottom; clientRect.right = rect.right; AdjustWindowRect(&rect, showedStyle, TRUE); int x = monInfo.rcMonitor.left + ((monInfo.rcMonitor.right - monInfo.rcMonitor.left) - (rect.right - rect.left)) / 2; int y = monInfo.rcMonitor.top + (monInfo.rcMonitor.bottom - monInfo.rcMonitor.top) - (rect.bottom - rect.top); MoveWindow(hWnd, x, y, rect.right - rect.left, rect.bottom - rect.top, TRUE); }
void CIGPropertyManager::DrawProperty (const IGLibrary::IGHasProperties& hasPropObj, HWND hListBox, int nOffsetWidth, int nListboxItemId, Graphics& graphics) { vector <pair<wstring,wstring>> vProp = hasPropObj.GetPropertiesAndValues(); pair<wstring,wstring> curProp; int idxItem = 0; for(vector <pair<wstring,wstring>>::const_iterator it = vProp.begin(); it != vProp.end(); ++it, idxItem++){ if (idxItem == nListboxItemId) { curProp = *it; break; } } RECT rcItem; ::ZeroMemory (&rcItem, sizeof (RECT)); ::SendMessageW (hListBox, (UINT)LB_GETITEMRECT, (WPARAM)nListboxItemId, (LPARAM)&rcItem); RectF rcfNameProp ((float)rcItem.left + 5.0f, (float)rcItem.top, (float)(rcItem.right - rcItem.left) / 2.0f - 5.0f, (float)(rcItem.bottom - rcItem.top)); RectF rcfValueProp (rcfNameProp); rcfValueProp.X = rcfNameProp.GetRight() + 5.0f; rcfValueProp.Width -= nOffsetWidth + 5.0f; DrawProperty (curProp, rcfNameProp, rcfValueProp, graphics); }
int Window::drawLine(HDC hdc, int oy, std::wstring string, TextFont* fnt) { using namespace Gdiplus; int x = (showed ? 0 : leftMargin) - 5; int y = (showed ? 0 : topMargin) + oy; const wchar_t* text = string.c_str(); if (fnt == 0) fnt = font; Graphics graphics(hdc); graphics.SetSmoothingMode(SmoothingModeAntiAlias); FontFamily fontFamily; fnt->GetFamily(&fontFamily); RectF boundRect = fnt->getTextBounds(hdc, clientRect, text); x += ((clientRect.right - clientRect.left) - (int)(boundRect.GetRight() - boundRect.GetLeft()) - 2) / 2; y -= ((int)boundRect.GetBottom()) + 5; StringFormat strformat; GraphicsPath path; path.AddString(text, wcslen(text), &fontFamily, fnt->GetStyle(), graphics.GetDpiY() * fnt->GetSize() / 72, Gdiplus::Point(x, y), &strformat ); // Outline color + size Pen pen(Color(0, 0, 0), fnt->GetSize()/7); pen.SetLineJoin(LineJoinRound); graphics.DrawPath(&pen, &path); // Text color SolidBrush brush(Color(254, 254, 254)); graphics.FillPath(&brush, &path); Rect bounds; path.GetBounds(&bounds, 0, &pen); return (int)boundRect.GetBottom(); }
void DrawSudoku(Image * pImage, Graphics * pGraphics, RectF& rcDraw , UINT nLeft, UINT nTop, UINT nRight, UINT nBottom ) { if (pGraphics == NULL) return; if (pImage == NULL) return; UINT cx = pImage->GetWidth(); UINT cy = pImage->GetHeight(); if ( nLeft + nRight > cx ) { nLeft = nRight = 0; } if ( nTop + nBottom > cy ) { nTop = nBottom = 0; } //左上角 if (nLeft > 0 && nTop > 0 && nTop < cy && nLeft < cx) { pGraphics->DrawImage( pImage , rcDraw.GetLeft(), rcDraw.GetTop() , 0.0f, 0.0f, (float)nLeft, (float)nTop , Gdiplus:: UnitPixel ); } //右上角 if (nRight > 0 && nTop > 0 && nTop < cy && nRight < cx) { pGraphics->DrawImage( pImage , rcDraw.GetRight() - (float)nRight, rcDraw.GetTop() , (float)cx - (float)nRight, 0.0f, (float)nRight, (float)nTop , Gdiplus:: UnitPixel ); } //右下角 if (nRight > 0 && nBottom > 0 && nBottom < cy && nRight < cx) { pGraphics->DrawImage( pImage , rcDraw.GetRight() - (float)nRight, rcDraw.GetBottom() - (float)nBottom , (float)cx - (float)nRight, (float)cy - (float)nBottom, (float)nRight, (float)nBottom , Gdiplus:: UnitPixel ); } //左下角 if (nLeft > 0 && nBottom > 0 && nBottom < cy && nLeft < cx) { pGraphics->DrawImage( pImage , rcDraw.GetLeft(), rcDraw.GetBottom() - (float)nBottom , 0.0f, (float)cy - (float)nBottom , (float)nLeft, (float)nBottom , Gdiplus:: UnitPixel ); } ImageAttributes ImgAtt; ImgAtt.SetWrapMode(WrapModeTileFlipXY); //左边 if (nLeft > 0 && cy - nTop - nBottom > 0) { RectF rc(rcDraw.GetLeft(), rcDraw.GetTop() + (float)nTop , (float)nLeft, rcDraw.Height - (float)nTop - (float)nBottom ); pGraphics->DrawImage( pImage , rc , 0.0f, (float)nTop, (float)nLeft, (float)cy - (float)nTop - (float)nBottom , UnitPixel, &ImgAtt ); } //上边 if (nTop > 0 && cx - nLeft - nRight > 0) { RectF rc(rcDraw.GetLeft() + (float)nLeft, rcDraw.GetTop() , rcDraw.Width - (float)nLeft - (float)nRight, (float)nTop ); pGraphics->DrawImage( pImage , rc , (float)nLeft, 0.0f, (float)cx - (float)nLeft - (float)nRight, (float)nTop , UnitPixel, &ImgAtt ); } //右边 if (nRight > 0 && cy - nTop - nBottom > 0) { RectF rc(rcDraw.GetRight() - (float)nRight, rcDraw.GetTop() + (float)nTop , (float)nRight, rcDraw.Height - (float)nTop - (float)nBottom ); pGraphics->DrawImage( pImage , rc , (float)cx - (float)nRight, (float)nTop, (float)nRight, (float)cy - (float)nTop - (float)nBottom , UnitPixel, &ImgAtt ); } //下边 if (nBottom > 0 && cx - nLeft - nRight > 0) { RectF rc(rcDraw.GetLeft() + (float)nLeft, rcDraw.GetBottom() - (float)nBottom , rcDraw.Width - (float)nLeft - (float)nRight, (float)nBottom ); pGraphics->DrawImage( pImage , rc , (float)nLeft, (float)cy - (float)nBottom, (float)cx - (float)nLeft - (float)nRight, (float)nBottom , UnitPixel, &ImgAtt ); CString str; str.Format("下边:%0.4f", rc.GetTop()); OutputDebugString(str); } //中间 { RectF rc = rcDraw; if (nLeft > 0) rc.X += (float)nLeft; if (nTop > 0) rc.Y += (float)nTop; if (nRight > 0) rc.Width -= (float)nRight; if (nBottom > 0) rc.Height -= (float)nBottom; rc.Width -= (float)nLeft; rc.Height -= (float)nTop; pGraphics->DrawImage( pImage , rc , (float)nLeft, (float)nTop, (float)(cx - nLeft - nRight), (float)(cy - nBottom - nTop) , UnitPixel, &ImgAtt ); } }