// static void CanvasGdiplus::InitializeDC(HDC context) { // Enables world transformation. // If the GM_ADVANCED graphics mode is set, GDI always draws arcs in the // counterclockwise direction in logical space. This is equivalent to the // statement that, in the GM_ADVANCED graphics mode, both arc control points // and arcs themselves fully respect the device context's world-to-device // transformation. BOOL res = SetGraphicsMode(context, GM_ADVANCED); DCHECK(res != 0); // Enables dithering. res = SetStretchBltMode(context, HALFTONE); DCHECK(res != 0); // As per SetStretchBltMode() documentation, SetBrushOrgEx() must be called // right after. res = SetBrushOrgEx(context, 0, 0, NULL); DCHECK(res != 0); // Sets up default orientation. res = SetArcDirection(context, AD_CLOCKWISE); DCHECK(res != 0); // Sets up default colors. res = SetBkColor(context, RGB(255, 255, 255)); DCHECK(res != CLR_INVALID); res = SetTextColor(context, RGB(0, 0, 0)); DCHECK(res != CLR_INVALID); res = SetDCBrushColor(context, RGB(255, 255, 255)); DCHECK(res != CLR_INVALID); res = SetDCPenColor(context, RGB(0, 0, 0)); DCHECK(res != CLR_INVALID); // Sets up default transparency. res = SetBkMode(context, OPAQUE); DCHECK(res != 0); res = SetROP2(context, R2_COPYPEN); DCHECK(res != 0); }
/* EXPORT-> MakeXGraf: Create and open window, initialization */ void MakeXGraf(char *wname, int x, int y, int w, int h, int bw) /* WIN32: bw is ignored. */ { WNDCLASS WindowClass; char sbuf[256], *hgraf = "HGraf"; HDC dc; if (winCreated) HError(6870, "MakeXGraf: Attempt to recreate the graphics window"); WindowClass.hInstance = GetModuleHandle(NULL); WindowClass.lpszClassName = hgraf; WindowClass.lpfnWndProc = HGWinFunc; WindowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; WindowClass.hIcon = NULL; WindowClass.hCursor = LoadCursor(NULL,IDC_ARROW); WindowClass.lpszMenuName = NULL; WindowClass.cbClsExtra = 0; WindowClass.cbWndExtra = 0; WindowClass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); RegisterClass(&WindowClass); strcpy(sbuf, hgraf); strcat(sbuf, ": "); strcat(sbuf, wname); theWindow = CreateWindow(hgraf, sbuf, WS_OVERLAPPEDWINDOW | WS_VISIBLE, x,y, w,h, HWND_DESKTOP, NULL, WindowClass.hInstance, NULL); /* adjust window size so that the client rectangle is the size requested */ /* by the caller of MakeXGraf() --- Win32 interprets w and h as the dimensions */ /* of the overall window. */ GetClientRect(theWindow,&ClientRect); MoveWindow(theWindow,x,y,w+w-ClientRect.right,h+h-ClientRect.bottom,TRUE); GetClientRect(theWindow,&ClientRect); /* Obtain and initialize device contexts */ dc = GetDC(theWindow); memDC = CreateCompatibleDC(dc); SetArcDirection(memDC,AD_COUNTERCLOCKWISE); SetArcDirection(dc,AD_COUNTERCLOCKWISE); SetPolyFillMode(memDC,WINDING); SetPolyFillMode(memDC,WINDING); SetTextAlign(memDC,TA_BASELINE | TA_LEFT); SetTextAlign(dc,TA_BASELINE | TA_LEFT); SetBkMode(memDC,TRANSPARENT); SetBkMode(dc,TRANSPARENT); theBitmap = CreateCompatibleBitmap(dc,w,h); SelectObject(memDC,theBitmap); ReleaseDC(theWindow,dc); CreateHeap(&btnHeap, "Button heap", MHEAP, sizeof(HButton), 1.0, 100, 100); InitGlobals(); InstallColours(); winCreated = TRUE; HSetColour(WHITE); HFillRectangle(0,0,ClientRect.right,ClientRect.bottom); }
// simulate AngleArcTo using ArcTo BOOL AngleArcTo(HDC hDC, int X, int Y, DWORD dwRadius, FLOAT eStartAngle, FLOAT eSweepAngle) { const FLOAT pi = (FLOAT) 3.141592653586; if ( eSweepAngle >=360 ) // more than one circle is one circle eSweepAngle = 360; else if ( eSweepAngle <= -360 ) eSweepAngle = - 360; FLOAT eEndAngle = (eStartAngle + eSweepAngle ) * pi / 180; eStartAngle = eStartAngle * pi / 180; int dir; if ( eSweepAngle > 0 ) dir = SetArcDirection(hDC, AD_COUNTERCLOCKWISE); else dir = SetArcDirection(hDC, AD_CLOCKWISE); BOOL rslt = ArcTo(hDC, X - dwRadius, Y - dwRadius, X + dwRadius, Y + dwRadius, X + (int) (dwRadius * 10 * cos(eStartAngle)), Y - (int) (dwRadius * 10 * sin(eStartAngle)), X + (int) (dwRadius * 10 * cos(eEndAngle)), Y - (int) (dwRadius * 10 * sin(eEndAngle))); SetArcDirection(hDC, dir); return rslt; }
BOOL nulldrv_AngleArc( PHYSDEV dev, INT x, INT y, DWORD radius, FLOAT start, FLOAT sweep ) { INT x1 = GDI_ROUND( x + cos( start * M_PI / 180 ) * radius ); INT y1 = GDI_ROUND( y - sin( start * M_PI / 180 ) * radius ); INT x2 = GDI_ROUND( x + cos( (start + sweep) * M_PI / 180) * radius ); INT y2 = GDI_ROUND( y - sin( (start + sweep) * M_PI / 180) * radius ); INT arcdir = SetArcDirection( dev->hdc, sweep >= 0 ? AD_COUNTERCLOCKWISE : AD_CLOCKWISE ); BOOL ret = ArcTo( dev->hdc, x - radius, y - radius, x + radius, y + radius, x1, y1, x2, y2 ); SetArcDirection( dev->hdc, arcdir ); return ret; }
void Win32Window::drawCircle(int Ox, int Oy, int radius, COLORREF color, int linewidth) { HPEN hPen = CreatePen(PS_SOLID, linewidth, color); SelectObject(hDoubleBufferDC, hPen); SetArcDirection(hDoubleBufferDC,AD_CLOCKWISE); Arc(hDoubleBufferDC, Ox - radius, Oy - radius, Ox + radius, Oy + radius, Ox, Oy - radius, Ox, Oy + radius); SetArcDirection(hDoubleBufferDC,AD_COUNTERCLOCKWISE); Arc(hDoubleBufferDC, Ox - radius, Oy - radius, Ox + radius, Oy + radius, Ox, Oy - radius, Ox, Oy + radius); DeleteObject(hPen); }
int WIN_Arc(int x0, int y0, int radius, double theta, double delta_theta) /* * Notes: * Draws an arc of <radius> and center at (x0,y0) beginning at * angle theta (in rad) and ending at theta + delta_theta */ { tpWindowData wd; HPEN OldPen; HPEN NewPen; int left, right, top, bottom; int xs, ys, xe, ye; int yb; int direction; double r; double dx0; double dy0; if (!currentgraph) return 0; wd = pWindowData(currentgraph); if (!wd) return 0; direction = AD_COUNTERCLOCKWISE; if (delta_theta < 0) { theta = theta + delta_theta; delta_theta = - delta_theta; direction = AD_CLOCKWISE; } SetArcDirection( wd->hDC, direction); /* some geometric considerations in advance */ yb = wd->Area.bottom; left = x0 - radius; right = x0 + radius; top = y0 + radius; bottom = y0 - radius; r = radius; dx0 = x0; dy0 = y0; xs = (dx0 + (r * cos(theta))); ys = (dy0 + (r * sin(theta))); xe = (dx0 + (r * cos(theta + delta_theta))); ye = (dy0 + (r * sin(theta + delta_theta))); /* plot */ NewPen = CreatePen( LType(wd->ColorIndex), linewidth, ColorTable[wd->ColorIndex] ); OldPen = SelectObject(wd->hDC, NewPen); Arc( wd->hDC, left, yb-top, right, yb-bottom, xs, yb-ys, xe, yb-ye); OldPen = SelectObject(wd->hDC, OldPen); DeleteObject( NewPen); return 0; }
static void test_arcto(void) { HDC hdc = GetDC(0); BeginPath(hdc); SetArcDirection(hdc, AD_CLOCKWISE); if (!ArcTo(hdc, 200, 200, 400, 300, 200, 200, 400, 300) && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) { /* ArcTo is only available on Win2k and later */ win_skip("ArcTo is not available\n"); goto done; } SetArcDirection(hdc, AD_COUNTERCLOCKWISE); ArcTo(hdc, 210, 210, 390, 290, 390, 290, 210, 210); CloseFigure(hdc); EndPath(hdc); ok_path(hdc, "arcto_path", arcto_path, sizeof(arcto_path)/sizeof(path_test_t), 0); done: ReleaseDC(0, hdc); }
PHP_METHOD(WinGdiPath, setArcDirection) { wingdi_devicecontext_object *dc_obj; wingdi_path_object *path_obj; int arc_dir; WINGDI_ERROR_HANDLING(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &arc_dir) == 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); RETURN_BOOL(SetArcDirection(dc_obj->hdc, arc_dir)); }
/*************************************************************************** * DoSetArcDirection - Win32 to Win16 Metafile Converter Entry Point **************************************************************************/ BOOL WINAPI DoSetArcDirection(PLOCALDC pLocalDC, INT iArcDirection) { pLocalDC->iArcDirection = iArcDirection ; return(SetArcDirection(pLocalDC->hdcHelper, iArcDirection) != 0); }