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); }
void GDITest(void) { ENUMLOGFONTEXW enumlog; EXTLOGFONTW extlog; memset(& enumlog, 0, sizeof(enumlog)); memset(& extlog, 0, sizeof(extlog)); int j = sizeof(enumlog); int k = sizeof(extlog); for (int i=0; i<sizeof(FIXARRAY)/sizeof(long); i++) { char t[20]; long v = FIXARRAY[i]; if ( v >= 0) t[0] = '+'; else { t[0] = '-'; v = - v; } sprintf(t+1, "%d + %d/16\n", v/16, v%16); OutputDebugString(t); } HDC hDC = GetDC(NULL); HBITMAP bmp1 = CreateBitmap(100, 100, 1, 1, NULL); HBITMAP bmp2 = CreateBitmap(100, 100, 1, 4, NULL); HBITMAP bmp3 = CreateBitmap(100, 100, 1, 8, NULL); HBITMAP bmp4 = CreateBitmap(100, 100, 3, 8, NULL); HBITMAP bmp5 = CreateBitmap(100, 100, 1, 24, NULL); void * dibbits; HBITMAP bmp6 = CreateDIBSection(hDC, (BITMAPINFO *) & dib, DIB_RGB_COLORS, & dibbits, NULL, 0); BeginPath(hDC); MoveToEx(hDC, 100, 100, NULL); LineTo(hDC, 150, 150); PolyBezierTo(hDC, & Points[0], 3); CloseFigure(hDC); Ellipse(hDC, -100, -100, 100, 100); EndPath(hDC); POINT points[20]; BYTE types[20]; int n = GetPath(hDC, NULL, NULL, 0); n = GetPath(hDC, points, types, min(n, 20)); SetBitmapDimensionEx(bmp1, 10000, 10000, NULL); }
PHP_METHOD(WinGdiPath, beizerTo) { wingdi_devicecontext_object *dc_obj; wingdi_path_object *path_obj; zval ***parameters, **x, **y; POINT *points = NULL; DWORD points_total = 0; int param_count, i; WINGDI_ERROR_HANDLING(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", ¶meters, ¶m_count) == FAILURE) return; WINGDI_RESTORE_ERRORS(); path_obj = zend_object_store_get_object(getThis() TSRMLS_CC); dc_obj = zend_object_store_get_object(path_obj->device_context TSRMLS_CC); points = emalloc(param_count * sizeof(POINT)); for (i = 0; i < param_count; i++) { // We expect only arrays if (Z_TYPE_PP(parameters[i]) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected array for parameter %d, got %s", i + 1, zend_zval_type_name(*(parameters[i]))); goto CLEANUP; } else { // We want 2 elements if (zend_hash_num_elements(Z_ARRVAL_PP(parameters[i])) != 2) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected 2 elements for array at parameter %d, got %d", i + 1, zend_hash_num_elements(Z_ARRVAL_PP(parameters[i]))); goto CLEANUP; } else { zend_hash_index_find(Z_ARRVAL_PP(parameters[i]), 0, (void **)&x); zend_hash_index_find(Z_ARRVAL_PP(parameters[i]), 1, (void **)&y); if (Z_TYPE_PP(x) != IS_LONG) convert_to_long(*x); if (Z_TYPE_PP(y) != IS_LONG) convert_to_long(*y); points[i].x = Z_LVAL_PP(x); points[i].y = Z_LVAL_PP(y); points_total++; } } } RETVAL_BOOL(PolyBezierTo(dc_obj->hdc, points, points_total)); CLEANUP: efree(points); }
static void dw_gt_curveto(vd_trace_interface *I, double x0, double y0, double x1, double y1, double x2, double y2) { POINT p[3]; get_window(); if (host.tw == NULL) return; p[0].x = SX(x0), p[0].y = SY(y0); p[1].x = SX(x1), p[1].y = SY(y1); p[2].x = SX(x2), p[2].y = SY(y2); PolyBezierTo(I->host->hdc, p, 3); }
void __fastcall TExtPolyline::DrawBezierSeg(void *dc,int n) { int n1=(n+1)%Count; int p1=(n+Count-1)%Count; POINT pt[3]; pt[0].x=Points[p1].x; pt[0].y=Points[p1].y; pt[1].x=Points[n].x; pt[1].y=Points[n].y; pt[2].x=Points[n1].x; pt[2].y=Points[n1].y; PolyBezierTo(dc,pt,3); }
bool GiCanvasGdi::rawBezierTo(const Point2d* pxs, int count) { bool ret = false; if (count > 0) { std::vector<POINT> pts; pts.resize(count); for (int i = 0; i < count; i++) pxs[i].get(pts[i].x, pts[i].y); ret = !!PolyBezierTo(m_draw->getDrawDC(), &pts.front(), count); } return ret; }
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_CREATE: { INITCOMMONCONTROLSEX icx; icx.dwSize = sizeof(INITCOMMONCONTROLSEX); icx.dwICC = ICC_BAR_CLASSES; InitCommonControlsEx(&icx); hTrackBar = CreateWindow( TRACKBAR_CLASS, "", TBS_HORZ | TBS_BOTH | TBS_AUTOTICKS | TBS_FIXEDLENGTH | TBS_ENABLESELRANGE | WS_CHILD | WS_VISIBLE, 10, 260, 375, 40, hWnd, NULL, hInst, NULL ); assert(hTrackBar != NULL); SNDMSG(hTrackBar, TBM_SETTHUMBLENGTH, 20, 0); SNDMSG(hTrackBar, TBM_SETRANGEMAX, TRUE, 100); // create the TrueType (scalable) font HDC hDC = GetDC(hWnd); try { // see Chapter 4 for the definition of MakeFont hTTFont = font::MakeFont(hDC, "Impact", 72); if (!hTTFont) throw; } catch (...) { ReleaseDC(hWnd, hDC); } ReleaseDC(hWnd, hDC); break; } case WM_HSCROLL: { if (reinterpret_cast<HWND>(lParam) == hTrackBar) { // // adjust the scaling factor according to // the position of the trackbar's slider // scale = static_cast<double>( (SNDMSG(hTrackBar, TBM_GETPOS, 0, 0) + 1) / 50.0 ); InvalidateRect(hWnd, NULL, true); } break; } case WM_ERASEBKGND: { LRESULT res = DefWindowProc(hWnd, msg, wParam, lParam); HDC hDC = reinterpret_cast<HDC>(wParam); HFONT hOldFont = static_cast<HFONT>( SelectObject(hDC, hTTFont) ); try { SetBkMode(hDC, TRANSPARENT); // open a path bracket if (!BeginPath(hDC)) throw; // record the text to the path TextOut(hDC, 10, 10, pText, lstrlen(pText)); // close the path bracket and // select the path into hDC EndPath(hDC); // determine the number of endpoints in the path const int num_points = GetPath(hDC, NULL, NULL, 0); if (num_points > 0) { // make room for the POINTs and vertex types POINT* pPEnds = new POINT[num_points]; unsigned char* pTypes = new unsigned char[num_points]; try { // get the path's description int num_got = GetPath(hDC, pPEnds, pTypes, num_points); if (num_got > 0) { // start a new path bracket if (!BeginPath(hDC)) throw; // scale each point in the description int iPoint; for (iPoint = 0; iPoint < num_got; ++iPoint) { pPEnds[iPoint].x = static_cast<LONG>( scale * pPEnds[iPoint].x + 0.5 ); pPEnds[iPoint].y = static_cast<LONG>( scale * pPEnds[iPoint].y + 0.5 ); } for (iPoint = 0; iPoint < num_points; ++iPoint) { // handle the MoveToEx case if (pTypes[iPoint] == PT_MOVETO) { MoveToEx( hDC, pPEnds[iPoint].x, pPEnds[iPoint].y, NULL ); } // handle the LineTo case else if ( pTypes[iPoint] == PT_LINETO || pTypes[iPoint] == (PT_LINETO | PT_CLOSEFIGURE) ) { LineTo(hDC, pPEnds[iPoint].x, pPEnds[iPoint].y); } // handle the PolyBezierTo case else if ( pTypes[iPoint] == PT_BEZIERTO || pTypes[iPoint] == (PT_BEZIERTO | PT_CLOSEFIGURE) ) { PolyBezierTo(hDC, pPEnds + iPoint, 3); iPoint += 2; } } // close the new path bracket EndPath(hDC); // stroke and fill the new path StrokeAndFillPath(hDC); } } catch (...) { // clean up delete [] pTypes; delete [] pPEnds; throw; } // clean up delete [] pTypes; delete [] pPEnds; } // ... } catch (...) { SelectObject(hDC, hOldFont); } SelectObject(hDC, hOldFont); return res; } case WM_SIZE: { MoveWindow( hTrackBar, 0, HIWORD(lParam) - 40, LOWORD(lParam), 40, false ); break; } case WM_DESTROY: { // clean up DeleteObject(hTTFont); PostQuitMessage(0); break; } } return DefWindowProc(hWnd, msg, wParam, lParam); }
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static HWND button, BezierTool, LineTool,Pen,EllipseTool,RectangleTool,EraserTool; int width; int xMouse, yMouse; HDC hdc = GetDC(hwnd); static POINT line, lineStart; static BOOL lineStarted; static BOOL ellipseStarted; static RECT ellipse; static BOOL rectangleStarted; static RECT rectangle; static int bezierStage = 0; static POINT bezierPoints[4]; static POINT bezierPoint; HDC hdcMem; BITMAP bitmap; HGDIOBJ oldBitmap; HBITMAP hbmplogo = NULL; hbmplogo = (HBITMAP)LoadImage(hInstance, "paint.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); GetObject(hbmplogo, sizeof(bitmap), &bitmap); HDC hDC; PAINTSTRUCT Ps; HBRUSH NewBrush; HPEN linePen; HPEN linePen2; HPEN linePen3; linePen= CreatePen(PS_SOLID,2,RGB(255,255,0)); linePen2=CreatePen(PS_DASHDOTDOT,4,RGB(255,0,255)); linePen3=CreatePen(PS_STYLE_MASK,6,RGB(0,128,255)); SelectObject(hdc,linePen); POINT Pt[4] = { { 20, 12 }, { 88, 246 }, { 364, 192 }, { 250, 48 } }; PolyBezierTo(hdc,Pt,4); switch (message) /* handle the messages */ { case WM_CREATE: BezierTool = CreateWindowEx( 0, "Button", "Bezier", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, 30, 250, 180, 20, hwnd, (HMENU)IDB_BEZIER, hInstance, NULL); LineTool = CreateWindowEx( 0, "Button", "Line", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, 30, 280, 180, 20, hwnd, (HMENU)IDB_LINE, hInstance, NULL); Pen = CreateWindowEx( 0, "Button", "Pen", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, 30, 310, 180, 20, hwnd, (HMENU)IDB_PEN, hInstance, NULL); EllipseTool = CreateWindowEx( 0, "Button", "Ellipse", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, 30, 340, 180, 20, hwnd, (HMENU)IDB_ELLIPSE, hInstance, NULL); RectangleTool = CreateWindowEx( 0, "Button", "Rectangle", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, 30, 370, 180, 20, hwnd, (HMENU)IDB_RECTANGLE, hInstance, NULL); EraserTool = CreateWindowEx( 0, "Button", "Eraser", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, 30, 415, 180, 20, hwnd, (HMENU)IDB_ERASER, hInstance, NULL); hbmplogo = (HBITMAP)LoadImage(hInstance, "paint.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); return 0; case WM_MOUSEMOVE: xMouse = GET_X_LPARAM(lParam); yMouse = GET_Y_LPARAM(lParam); if (xMouse > 250 && xMouse < 880 && yMouse > 20 && yMouse < 550 ) { if(wParam & MK_LBUTTON) { if (Button_GetCheck(Pen) == BST_CHECKED) { width = 2; linePen = CreatePen(PS_SOLID, width, RGB(0, 0, 0)); SelectObject(hdc, linePen); MoveToEx(hdc, xMouse, yMouse, NULL); LineTo(hdc, pointPen.x, pointPen.y); DeleteObject(linePen); pointPen.x = xMouse; pointPen.y = yMouse; } if (Button_GetCheck(LineTool) == BST_CHECKED) { width = 2; // draw previous line with white linePen = CreatePen(PS_SOLID, width, RGB(255, 255, 255)); SelectObject(hdc, linePen); MoveToEx(hdc, lineStart.x, lineStart.y, NULL); LineTo(hdc, line.x, line.y); DeleteObject(linePen); // draw the line linePen = CreatePen(PS_SOLID, width, RGB(0, 0, 0)); SelectObject(hdc, linePen); MoveToEx(hdc, lineStart.x, lineStart.y, NULL); LineTo(hdc, xMouse, yMouse); DeleteObject(linePen); line.x = xMouse; line.y = yMouse; } // Eraser if((wParam == MK_LBUTTON) && (Button_GetCheck(EraserTool) == BST_CHECKED)) { width = 6; rectangle.left = xMouse - (width / 2); rectangle.right = xMouse + (width / 2); rectangle.top = yMouse - (width / 2); rectangle.bottom = yMouse + (width / 2); InvalidateRect(hwnd, &rectangle, FALSE); SendMessage(hwnd, WM_PAINT, 0, 0); //ValidateRect(hwnd, &rect); } } } break; case WM_LBUTTONUP : xMouse = GET_X_LPARAM(lParam); yMouse = GET_Y_LPARAM(lParam); if (xMouse > 250 && xMouse < 880 && yMouse > 20 && yMouse < 550 ) { if (Button_GetCheck(LineTool) == BST_CHECKED) { width = 2; // draw previous line with white SelectObject(hdc, CreatePen(PS_SOLID, width, RGB(0, 0, 0))); MoveToEx(hdc, lineStart.x, lineStart.y, NULL); LineTo(hdc, line.x, line.y); // draw the line linePen = CreatePen(PS_SOLID, width, RGB(0, 0, 0)); SelectObject(hdc, linePen); MoveToEx(hdc, lineStart.x, lineStart.y, NULL); LineTo(hdc, xMouse, yMouse); DeleteObject(linePen); line.x = xMouse; line.y = yMouse; } if(ellipseStarted) { SelectObject(hdc, linePen2); SelectObject(hdc, NewBrush); Ellipse(hdc, ellipse.left, ellipse.top, xMouse, yMouse); DeleteObject(linePen2); DeleteObject(NewBrush); ellipseStarted = false; } if(rectangleStarted) { SelectObject(hdc, linePen); SelectObject(hdc, NewBrush); Rectangle(hdc, rectangle.left, rectangle.top, xMouse, yMouse); DeleteObject(linePen); DeleteObject(NewBrush); rectangleStarted = false; } if(bezierStage == 1) { bezierPoint.x = xMouse; bezierPoint.y = yMouse; bezierPoints[1] = bezierPoint; bezierStage = 2; } if(bezierStage == 3) { bezierPoint.x = xMouse; bezierPoint.y = yMouse; bezierPoints[3] = bezierPoint; bezierStage = 0; SelectObject(hdc, linePen3); PolyBezier(hdc, bezierPoints, 4); DeleteObject(linePen3); } } break; case WM_LBUTTONDOWN: xMouse = GET_X_LPARAM(lParam); yMouse = GET_Y_LPARAM(lParam); //250, 20, 880, 550 if (xMouse > 250 && xMouse < 880 && yMouse > 20 && yMouse < 550 ) { if(wParam == MK_LBUTTON) { if (Button_GetCheck(Pen) == BST_CHECKED) { pointPen.x = xMouse; pointPen.y = yMouse; } if (Button_GetCheck(LineTool) == BST_CHECKED) { lineStart.x = xMouse; lineStart.y = yMouse; line.x = xMouse; line.y = yMouse; } if((wParam == MK_LBUTTON) && (Button_GetCheck(EllipseTool) == BST_CHECKED)) { ellipse.left = xMouse; ellipse.top = yMouse; ellipseStarted = true; } if((wParam == MK_LBUTTON) && (Button_GetCheck(RectangleTool) == BST_CHECKED)) { rectangle.left = xMouse; rectangle.top = yMouse; rectangleStarted = true; } if((wParam == MK_LBUTTON) && (Button_GetCheck(BezierTool) == BST_CHECKED)) { if(bezierStage == 0) { bezierPoint.x = xMouse; bezierPoint.y = yMouse; bezierPoints[0] = bezierPoint; bezierStage = 1; } else { bezierPoint.x = xMouse; bezierPoint.y = yMouse; bezierPoints[2] = bezierPoint; bezierStage = 3; } } } } break; case WM_PAINT: hDC = BeginPaint(hwnd, &Ps); NewBrush = CreateSolidBrush(RGB(255, 255, 255)); SelectObject(hDC, NewBrush); Rectangle(hDC, 250, 20, 880, 550); DeleteObject(NewBrush); //PolyBezier(hDC, Pt, 4); //EndPaint(hWnd, &Ps); // Draw logo hdcMem = CreateCompatibleDC(hdc); SelectObject(hdcMem, hbmplogo); // Copy the bits from the memory DC into the current dc BitBlt(hdc, 10, 10, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY); // Restore the old bitmap DeleteDC(hdcMem); EndPaint(hwnd, &Ps); break; case WM_DESTROY: PostQuitMessage (0); /* send a WM_QUIT to the message queue */ break; default: /* for messages that we don't deal with */ return DefWindowProc (hwnd, message, wParam, lParam); } return 0; }
void EmfPaintEngine::drawPath ( const QPainterPath & path ) { setClipping(); int points = path.elementCount(); POINT *pts = new POINT[points]; BYTE *types = new BYTE[points]; POINT *bzs = new POINT[3]; int bez = 0; BeginPath(metaDC); QMatrix m = painter()->worldMatrix(); for (int i = 0; i < points; i++){ QPainterPath::Element el = path.elementAt(i); QPointF p = m.map(QPointF(el.x, el.y)); int x = qRound(p.x()); int y = qRound(p.y()); pts[i].x = x; pts[i].y = y; switch(el.type){ case QPainterPath::MoveToElement: types[i] = PT_MOVETO; #ifndef Q_WS_WIN MoveToEx (metaDC, x, y, 0); #endif break; case QPainterPath::LineToElement: types[i] = PT_LINETO; #ifndef Q_WS_WIN LineTo(metaDC, x, y); #endif break; case QPainterPath::CurveToElement: types[i] = PT_BEZIERTO; #ifndef Q_WS_WIN bzs[bez] = pts[i]; bez++; #endif break; case QPainterPath::CurveToDataElement: types[i] = PT_BEZIERTO; #ifndef Q_WS_WIN bzs[bez] = pts[i]; if (bez == 2){ PolyBezierTo(metaDC, bzs, 3); bez = 0; } else bez++; #endif break; } } HPEN wpen = convertPen(painter()->pen()); SelectObject(metaDC, wpen); #ifdef Q_WS_WIN PolyDraw(metaDC, pts, types, points); #else StrokePath(metaDC); #endif HBRUSH wbrush = convertBrush(painter()->brush()); SelectObject(metaDC, wbrush); EndPath(metaDC); if(QPoint(pts[0].x, pts[0].y) == QPoint(pts[points - 1].x, pts[points - 1].y)) StrokeAndFillPath(metaDC); else { FillPath(metaDC); #ifdef Q_WS_WIN PolyDraw(metaDC, pts, types, points); #else StrokePath(metaDC); #endif } resetClipping(); DeleteObject(wbrush); DeleteObject(wpen); delete [] pts; delete [] types; }