static void STATUSBAR_RefreshPart (const STATUS_INFO *infoPtr, HDC hdc, const STATUSWINDOWPART *part, int itemID) { HBRUSH hbrBk; HTHEME theme; TRACE("item %d\n", itemID); if (part->bound.right < part->bound.left) return; if (!RectVisible(hdc, &part->bound)) return; if ((theme = GetWindowTheme (infoPtr->Self))) { RECT cr; GetClientRect (infoPtr->Self, &cr); DrawThemeBackground(theme, hdc, 0, 0, &cr, &part->bound); } else { if (infoPtr->clrBk != CLR_DEFAULT) hbrBk = CreateSolidBrush (infoPtr->clrBk); else hbrBk = GetSysColorBrush (COLOR_3DFACE); FillRect(hdc, &part->bound, hbrBk); if (infoPtr->clrBk != CLR_DEFAULT) DeleteObject (hbrBk); } STATUSBAR_DrawPart (infoPtr, hdc, part, itemID); }
afx_msg void CLayerView::OnPaint() { RECT client_rect; GetClientRect(&client_rect); CPaintDC dc_(this); HDC dc = dc_.m_hDC; for (int i = 0; i < client_rect.bottom / LAYER_BUTTON_HEIGHT + 1; i++) { RECT rect = { 0, i * LAYER_BUTTON_HEIGHT, client_rect.right, (i + 1) * LAYER_BUTTON_HEIGHT }; // visibility check if (!RectVisible(dc, &rect)) { continue; } // if the layer isn't part of the map, draw an empty rectangle if ((i + m_TopLayer) >= m_Map->GetNumLayers()) { FillRect(dc, &rect, (HBRUSH)(COLOR_APPWORKSPACE + 1)); continue; } // draw layers upside down! int layer = m_Map->GetNumLayers() - i - m_TopLayer - 1; DrawLayerButton(dc, rect, m_Map->GetLayer(layer), (m_SelectedLayer == layer)); } }
WEBC_BOOL DisplayManager::IsVisible(DisplayElement *pElem) { if (pElem->GetManager() == this) { DISPLAY_INT left = 0, top = 0; if (pElem == mRoot.Get()) { // the root object is always visible return WEBC_TRUE; } if (pElem->mpParent) { pElem->mpParent->GetDisplayPosition(pElem, &left, &top); } else { left = pElem->mRect.left; top = pElem->mRect.top; } WebRect rect(pElem->mRect); rect.MoveTo(left, top); return (RectVisible(&rect)); } return WEBC_FALSE; }
void DrawOnRichEdit(void) { HDC hdc = GetDC(m_hwnd); if (RectVisible(hdc, &m_orect)) { RECT crct; GetClientRect(m_hwnd, &crct); HRGN hrgnOld = CreateRectRgnIndirect(&crct); int res = GetClipRgn(hdc, hrgnOld); HRGN hrgn = CreateRectRgnIndirect(&crct); SelectClipRgn(hdc, hrgn); DeleteObject(hrgn); DoDirectDraw(hdc); SelectClipRgn(hdc, res < 1 ? NULL : hrgnOld); DeleteObject(hrgnOld); } else { m_visible = false; m_allowAni = false; UnloadSmiley(); } ReleaseDC(m_hwnd, hdc); }
VOID WINAPI tdDraw3DRect( HDC hDC, LPRECT lpRect, UINT uiShadowWidth, UINT uiFlags ) { /* sanity check--don't work if you don't have to! */ if ( !uiShadowWidth || !RectVisible( hDC, lpRect ) ) return ; if (uiFlags & DRAW3D_CREASE) { tdDraw3DCrease( hDC, lpRect, uiFlags ) ; return ; } /* if width is 1 use lines instead of polygons */ if (uiShadowWidth == 1) { /* draw the top line */ Draw3DLine1( hDC, lpRect->left, lpRect->top, lpRect->right - lpRect->left, DRAW3D_TOPLINE | uiFlags ) ; /* right line */ Draw3DLine1( hDC, lpRect->right, lpRect->top, lpRect->bottom - lpRect->top, DRAW3D_RIGHTLINE | uiFlags ) ; /* bottom line */ Draw3DLine1( hDC, lpRect->left, lpRect->bottom, lpRect->right - lpRect->left, DRAW3D_BOTTOMLINE | uiFlags ) ; /* left line */ Draw3DLine1( hDC, lpRect->left, lpRect->top, lpRect->bottom - lpRect->top, DRAW3D_LEFTLINE | uiFlags ) ; } else { /* draw the top line */ tdDraw3DLine( hDC, lpRect->left, lpRect->top, lpRect->right - lpRect->left, uiShadowWidth, DRAW3D_TOPLINE | uiFlags ) ; /* right line */ tdDraw3DLine( hDC, lpRect->right, lpRect->top, lpRect->bottom - lpRect->top, uiShadowWidth, DRAW3D_RIGHTLINE | uiFlags ) ; /* bottom line */ tdDraw3DLine( hDC, lpRect->left, lpRect->bottom, lpRect->right - lpRect->left, uiShadowWidth, DRAW3D_BOTTOMLINE | uiFlags ) ; /* left line */ tdDraw3DLine( hDC, lpRect->left, lpRect->top, lpRect->bottom - lpRect->top, uiShadowWidth, DRAW3D_LEFTLINE | uiFlags ) ; } } /* Draw3DRect() */
void CContainerWnd::PaintBuffer(HWND hwnd, HDC dc, int width, int height) { PaintBufferPre(hwnd, dc, width, height); POINT prevPoint = { 0, 0 }; int dcState = 0; for (auto comp : m_components) { if(RectVisible(dc, comp)) { dcState = SaveDC(dc); SetViewportOrgEx(dc, comp->left, comp->top, &prevPoint); comp->Paint(hwnd, dc); GdiFlush(); if(dcState)RestoreDC(dc, dcState); } } // SetViewportOrgEx(dc, 0, 0, &prevPoint); PaintBufferPost(hwnd, dc, width, height); }
extern bool _wrectvisible( /************************/ float x1, float y1, float x2, float y2 ) { int px1, py1; int px2, py2; WPI_RECT rect; int left, right, top, bottom; convert_pt( x1, y1, &px1, &py1 ); convert_pt( x2, y2, &px2, &py2 ); left = _min( px1, px2 ); right = _max( px1, px2 ); top = _min( py1, py2 ); bottom = _max( py1, py2 ); _wpi_setintrectvalues( &rect, left, top, right, bottom ); return( RectVisible( Win_dc, &rect ) ); }
static void test_window_dc_clipping(void) { HDC hdc; HRGN hrgn, hrgn_empty; HWND hwnd; RECT rc; int ret, screen_width, screen_height; /* Windows versions earlier than Win2k do not support the virtual screen metrics, * so we fall back to the primary screen metrics. */ screen_width = GetSystemMetrics(SM_CXVIRTUALSCREEN); if(!screen_width) screen_width = GetSystemMetrics(SM_CXSCREEN); screen_height = GetSystemMetrics(SM_CYVIRTUALSCREEN); if(!screen_height) screen_height = GetSystemMetrics(SM_CYSCREEN); trace("screen resolution %d x %d\n", screen_width, screen_height); hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, -100, -100, screen_width * 2, screen_height * 2, 0, 0, 0, NULL); hdc = GetWindowDC(0); hrgn_empty = CreateRectRgn(0, 0, 0, 0); hrgn = CreateRectRgn(0, 0, 0, 0); ret = GetClipRgn(hdc, hrgn); ok(ret == 0, "expected 0, got %d\n", ret); ret = ExtSelectClipRgn(hdc, 0, RGN_DIFF); ok(ret == 0, "expected 0, got %d\n", ret); ret = GetClipRgn(hdc, hrgn); ok(ret == 0, "expected 0, got %d\n", ret); ret = ExtSelectClipRgn(hdc, hrgn_empty, RGN_DIFF); ok(ret == SIMPLEREGION || (ret == COMPLEXREGION && GetSystemMetrics(SM_CMONITORS) > 1), "expected SIMPLEREGION, got %d\n", ret); ret = GetClipRgn(hdc, hrgn); ok(ret == 1, "expected 1, got %d\n", ret); ret = GetRgnBox(hrgn, &rc); ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret); ok(rc.left == 0 && rc.top == 0 && rc.right == screen_width && rc.bottom == screen_height, "expected 0,0-%d,%d, got %d,%d-%d,%d\n", screen_width, screen_height, rc.left, rc.top, rc.right, rc.bottom); SetRect( &rc, 10, 10, 20, 20 ); ret = RectVisible( hdc, &rc ); ok( ret, "RectVisible failed for %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom ); SetRect( &rc, 20, 20, 10, 10 ); ret = RectVisible( hdc, &rc ); ok( ret, "RectVisible failed for %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom ); ret = ExtSelectClipRgn(hdc, 0, RGN_DIFF); ok(ret == 0, "expected 0, got %d\n", ret); ret = GetClipRgn(hdc, hrgn); ok(ret == 1, "expected 1, got %d\n", ret); ret = GetRgnBox(hrgn, &rc); ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret); ok(rc.left == 0 && rc.top == 0 && rc.right == screen_width && rc.bottom == screen_height, "expected 0,0-%d,%d, got %d,%d-%d,%d\n", screen_width, screen_height, rc.left, rc.top, rc.right, rc.bottom); ret = ExtSelectClipRgn(hdc, 0, RGN_COPY); ok(ret == SIMPLEREGION || (ret == COMPLEXREGION && GetSystemMetrics(SM_CMONITORS) > 1), "expected SIMPLEREGION, got %d\n", ret); ret = GetClipRgn(hdc, hrgn); ok(ret == 0, "expected 0, got %d\n", ret); DeleteDC(hdc); DeleteObject(hrgn); DeleteObject(hrgn_empty); DestroyWindow(hwnd); }
static void test_memory_dc_clipping(void) { HDC hdc; HRGN hrgn, hrgn_empty; HBITMAP hbmp; RECT rc; int ret; hdc = CreateCompatibleDC(0); hrgn_empty = CreateRectRgn(0, 0, 0, 0); hrgn = CreateRectRgn(0, 0, 0, 0); hbmp = CreateCompatibleBitmap(hdc, 100, 100); ret = GetClipRgn(hdc, hrgn); ok(ret == 0, "expected 0, got %d\n", ret); ret = ExtSelectClipRgn(hdc, hrgn_empty, RGN_DIFF); ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret); ret = GetClipRgn(hdc, hrgn); ok(ret == 1, "expected 1, got %d\n", ret); ret = GetRgnBox(hrgn, &rc); ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret); ok(rc.left == 0 && rc.top == 0 && rc.right == 1 && rc.bottom == 1, "expected 0,0-1,1, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom); ret = ExtSelectClipRgn(hdc, 0, RGN_COPY); ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret); ret = GetClipRgn(hdc, hrgn); ok(ret == 0, "expected 0, got %d\n", ret); ret = ExtSelectClipRgn(hdc, 0, RGN_DIFF); ok(ret == 0, "expected 0, got %d\n", ret); ret = GetClipRgn(hdc, hrgn); ok(ret == 0, "expected 0, got %d\n", ret); SelectObject(hdc, hbmp); ret = ExtSelectClipRgn(hdc, hrgn_empty, RGN_DIFF); ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret); ret = GetClipRgn(hdc, hrgn); ok(ret == 1, "expected 1, got %d\n", ret); ret = GetRgnBox(hrgn, &rc); ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret); ok(rc.left == 0 && rc.top == 0 && rc.right == 100 && rc.bottom == 100, "expected 0,0-100,100, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom); SetRect( &rc, 10, 10, 20, 20 ); ret = RectVisible( hdc, &rc ); ok( ret, "RectVisible failed for %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom ); SetRect( &rc, 20, 20, 10, 10 ); ret = RectVisible( hdc, &rc ); ok( ret, "RectVisible failed for %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom ); ret = ExtSelectClipRgn(hdc, 0, RGN_DIFF); ok(ret == 0, "expected 0, got %d\n", ret); ret = GetClipRgn(hdc, hrgn); ok(ret == 1, "expected 1, got %d\n", ret); ret = GetRgnBox(hrgn, &rc); ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret); ok(rc.left == 0 && rc.top == 0 && rc.right == 100 && rc.bottom == 100, "expected 0,0-100,100, got %d,%d-%d,%d\n", rc.left, rc.top, rc.right, rc.bottom); DeleteDC(hdc); DeleteObject(hrgn); DeleteObject(hrgn_empty); DeleteObject(hbmp); }
static LRESULT APIENTRY LevelControlWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { LevelControlData *lcd = (LevelControlData *)GetWindowLongPtr(hwnd, 0); switch(msg) { case WM_NCCREATE: if (!(lcd = new LevelControlData)) return FALSE; memset(lcd,0,sizeof(LevelControlData)); lcd->nTabs = 3; lcd->iPos[0] = 0; lcd->rgbTab[0] = 0xFFFFFF; lcd->rgbLow = 0x000000; lcd->rgbHigh = 0xFFFFFF; lcd->iMovingTab = -1; SetWindowLongPtr(hwnd, 0, (LONG_PTR)lcd); return TRUE; case WM_CREATE: case WM_SIZE: LevelControlResize(hwnd, lcd); break; case WM_DESTROY: delete lcd; SetWindowLongPtr(hwnd, 0, 0); break; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc; int i, x, w, h; RECT r; hdc = BeginPaint(hwnd, &ps); w = lcd->w; h = lcd->rColorBand.bottom - lcd->rColorBand.top; if (RectVisible(hdc, &lcd->rColorBand)) { int dr, dg, db; int xlo, xhi; RECT rClip; dr = (signed long)(lcd->rgbHigh&0xff) - (signed long)(lcd->rgbLow&0xff); dg = ((signed long)(lcd->rgbHigh&0xff00) - (signed long)(lcd->rgbLow&0xff00))>>8; db = ((signed long)(lcd->rgbHigh&0xff0000) - (signed long)(lcd->rgbLow&0xff0000))>>16; r = lcd->rColorBand; xlo = 0; xhi = w; i = GetClipBox(hdc, &rClip); if (i!=ERROR && i!=NULLREGION) { RECT rClip2; IntersectRect(&rClip2, &r, &rClip); xlo = rClip2.left - r.left; xhi = rClip2.right - r.left; } for(x=xlo; x<xhi; x++) { HBRUSH hbr; COLORREF cr; r.left = lcd->rColorBand.left + x; r.right = r.left+1; cr = lcd->rgbLow + ((dr*x + w/2)/w) + (((dg*x + w/2)/w) << 8) + (((db*x + w/2)/w) << 16); if (hbr = CreateSolidBrush(cr)) { FillRect(hdc, &r, hbr); DeleteObject(hbr); } } } for(i=0; i<lcd->nTabs; i++) { POINT pt[3]; HBRUSH hbr; HGDIOBJ hgoOld; pt[0].x = lcd->iPixPos[i]; pt[1].x = lcd->iPixPos[i]+lcd->iTabW; pt[2].x = lcd->iPixPos[i]+2*lcd->iTabW; pt[0].y = pt[2].y = lcd->rColorBand.bottom+lcd->iTabH-1; pt[1].y = lcd->rColorBand.bottom; if (hbr = CreateSolidBrush(lcd->rgbTab[i])) hgoOld = SelectObject(hdc, hbr); Polygon(hdc, pt, 3); if (hbr) DeleteObject(SelectObject(hdc, hgoOld)); } EndPaint(hwnd, &ps); } break; case WM_LBUTTONDOWN: { int x = LOWORD(lParam); int y = HIWORD(lParam); if (y >= lcd->rColorBand.bottom && y<lcd->rColorBand.bottom+lcd->iTabH) { int i; int best_tab = -1, best_dx = 100; for(i=0; i<lcd->nTabs; i++) { int dx = (x-lcd->iTabW) - lcd->iPixPos[i]; int adx = abs(dx); // Pick the closest tab to cursor; if tabs are on the same // position, pick the lowest tab if mouse is to the left and // the highest tab if mouse is to the right if (adx < 8 && (best_tab == -1 || adx < best_dx || (adx == best_dx && dx>0))) { best_dx = adx; best_tab = i; } } if (best_tab >= 0) { SetCapture(hwnd); lcd->iMovingTab = best_tab; lcd->iMovingOffset = x - lcd->iPixPos[best_tab]; } } } break; case WM_LBUTTONUP: if (lcd->iMovingTab>=0) { ReleaseCapture(); lcd->iMovingTab = -1; } break; case WM_MOUSEMOVE: if (lcd->iMovingTab>=0) { int pos, pixpos; RECT r; pixpos = (int)(signed short)LOWORD(lParam) - lcd->iMovingOffset; pos = LevelPixelToRatio(pixpos, lcd->w); // clip position against spectrum if (pixpos<0) { pos = 0; pixpos = 0; } else if (pixpos >= lcd->rColorBand.right - lcd->rColorBand.left) { pixpos = lcd->rColorBand.right - lcd->rColorBand.left - 1; pos = 0xFFFF; } // don't let tabs pass each other if (lcd->iMovingTab>0 && pos < lcd->iPos[lcd->iMovingTab-1]) { pos = lcd->iPos[lcd->iMovingTab-1]; pixpos = lcd->iPixPos[lcd->iMovingTab-1]; } else if (lcd->iMovingTab < lcd->nTabs-1 && pos > lcd->iPos[lcd->iMovingTab+1]) { pos = lcd->iPos[lcd->iMovingTab+1]; pixpos = lcd->iPixPos[lcd->iMovingTab+1]; } // render changes r.left = lcd->iPixPos[lcd->iMovingTab]; r.right = lcd->iPixPos[lcd->iMovingTab]+2*lcd->iTabW+1; r.top = lcd->rColorBand.bottom; r.bottom = r.top + lcd->iTabH; InvalidateRect(hwnd, &r, TRUE); lcd->iPos[lcd->iMovingTab] = pos; lcd->iPixPos[lcd->iMovingTab] = pixpos; r.left = pixpos; r.right = pixpos+2*lcd->iTabW+1; InvalidateRect(hwnd, &r, TRUE); UpdateWindow(hwnd); // send notification message to parent window NMVLTABCHANGE nmvltc; nmvltc.hdr.code = VLCN_TABCHANGE; nmvltc.hdr.hwndFrom = hwnd; nmvltc.hdr.idFrom = GetWindowLong(hwnd, GWL_ID); nmvltc.iTab = lcd->iMovingTab; nmvltc.iNewPos = pos; SendMessage(GetParent(hwnd), WM_NOTIFY, nmvltc.hdr.idFrom, (LPARAM)&nmvltc); } break; case VLCM_SETTABCOUNT: lcd->nTabs = lParam; if (wParam) InvalidateRect(hwnd, &lcd->rTabBand, TRUE); break; case VLCM_SETTABCOLOR: lcd->rgbTab[LOWORD(wParam)] = lParam; if (HIWORD(wParam)) InvalidateRect(hwnd, &lcd->rTabBand, TRUE); break; case VLCM_MOVETABPOS: case VLCM_SETTABPOS: lcd->iPos[LOWORD(wParam)] = lParam; lcd->iPixPos[LOWORD(wParam)] = LevelRatioToPixel(lParam, lcd->w); if (HIWORD(wParam)) InvalidateRect(hwnd, &lcd->rTabBand, TRUE); if (msg == VLCM_MOVETABPOS) { NMVLTABCHANGE nmvltc; nmvltc.hdr.code = VLCN_TABCHANGE; nmvltc.hdr.hwndFrom = hwnd; nmvltc.hdr.idFrom = GetWindowLong(hwnd, GWL_ID); nmvltc.iTab = LOWORD(wParam); nmvltc.iNewPos = lParam; SendMessage(GetParent(hwnd), WM_NOTIFY, nmvltc.hdr.idFrom, (LPARAM)&nmvltc); } break; case VLCM_SETGRADIENT: lcd->rgbLow = wParam; lcd->rgbHigh = lParam; InvalidateRect(hwnd, &lcd->rColorBand, FALSE); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); }
void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph) { int align = SetTextAlign(c->hDC, TA_BASELINE); ME_DisplayItem *p; ME_Run *run; ME_Paragraph *para = NULL; RECT rc, rcPara; int y = c->pt.y; int height = 0, baseline = 0, no=0, pno = 0; int xs, xe; int visible = 0; int nMargWidth = 0; c->pt.x = c->rcView.left; rcPara.left = c->rcView.left; rcPara.right = c->rcView.right; for (p = paragraph; p!=paragraph->member.para.next_para; p = p->next) { switch(p->type) { case diParagraph: para = &p->member.para; break; case diStartRow: assert(para); nMargWidth = (pno==0?para->nFirstMargin:para->nLeftMargin); xs = c->rcView.left+nMargWidth; xe = c->rcView.right-para->nRightMargin; y += height; rcPara.top = y; rcPara.bottom = y+p->member.row.nHeight; visible = RectVisible(c->hDC, &rcPara); if (visible) { HBRUSH hbr; hbr = CreateSolidBrush(ME_GetBackColor(c->editor)); /* left margin */ rc.left = c->rcView.left; rc.right = c->rcView.left+nMargWidth; rc.top = y; rc.bottom = y+p->member.row.nHeight; FillRect(c->hDC, &rc, hbr/* c->hbrMargin */); /* right margin */ rc.left = xe; rc.right = c->rcView.right; FillRect(c->hDC, &rc, hbr/* c->hbrMargin */); rc.left = c->rcView.left+nMargWidth; rc.right = xe; FillRect(c->hDC, &rc, hbr); DeleteObject(hbr); } if (me_debug) { const WCHAR wszRowDebug[] = {'r','o','w','[','%','d',']',0}; WCHAR buf[128]; POINT pt = c->pt; wsprintfW(buf, wszRowDebug, no); pt.y = 12+y; ME_DebugWrite(c->hDC, &pt, buf); } height = p->member.row.nHeight; baseline = p->member.row.nBaseline; pno++; break; case diRun: assert(para); run = &p->member.run; if (visible && me_debug) { rc.left = c->rcView.left+run->pt.x; rc.right = c->rcView.left+run->pt.x+run->nWidth; rc.top = c->pt.y+run->pt.y; rc.bottom = c->pt.y+run->pt.y+height; TRACE("rc = (%ld, %ld, %ld, %ld)\n", rc.left, rc.top, rc.right, rc.bottom); if (run->nFlags & MERF_SKIPPED) DrawFocusRect(c->hDC, &rc); else FrameRect(c->hDC, &rc, GetSysColorBrush(COLOR_GRAYTEXT)); } if (visible) ME_DrawRun(c, run->pt.x, c->pt.y+run->pt.y+baseline, p, ¶graph->member.para); if (me_debug) { /* I'm using %ls, hope wsprintfW is not going to use wrong (4-byte) WCHAR version */ const WCHAR wszRunDebug[] = {'[','%','d',':','%','x',']',' ','%','l','s',0}; WCHAR buf[2560]; POINT pt; pt.x = run->pt.x; pt.y = c->pt.y + run->pt.y; wsprintfW(buf, wszRunDebug, no, p->member.run.nFlags, p->member.run.strText->szData); ME_DebugWrite(c->hDC, &pt, buf); } /* c->pt.x += p->member.run.nWidth; */ break; default: break; } no++; } SetTextAlign(c->hDC, align); }
/*+/csubr/TOC/internal------------------------------------------------------- * PlPOINTPlot - plot an array of POINT structures * * Purpose: * Plots an array of POINT structures. * * If the number of points is 1, then PL_LINE... gets plotted as * though it were PL_POINT. * * Return Value: * PL_OK, or * other error codes * *-Date Author Revision * -------- ------------ -------- * 09-27-95 R. Cole created *--------------------------------------------------------------------------*/ int PlPOINTPlot( PL_CTX *pPlot, // I pointer to plot context structure HDC hDC, // I HDC const RECT *pRectPts, // I pointer to rect bounding points, or NULL const POINT *aPts, // I array of POINT structures int nPts, // I number of array elements int eDrawType, // I PL_LINE... or PL_POINT or PL_... mark float fPts, // I drawing thickness or mark size, in points COLORREF rgb) // I color to use for drawing { int retStat=PL_OK; HBRUSH hBrush=0, hOldBrush=0; HPEN hPen=0, hOldPen=0; int stat, j; RECT rectPts; // If the caller has told us the RECT that bounds the points to be // drawn, check to see if the RECT (or a part of it) lies within // the area of the window that needs to be drawn. If not, just // exit from this routine. if (pRectPts != NULL) { rectPts = *pRectPts; // Make the rect follow the Windows convention. rectPts.right += 1; rectPts.bottom += 1; if (pPlot->hRgnPaint != 0) { if (!RectInRegion(pPlot->hRgnPaint, &rectPts)) goto done; } if (!RectVisible(hDC, &rectPts)) goto done; } // Now draw the actual data points. There is a separate section // here for each drawing type. One of the overriding objectives // in how this is coded is to minimize the number of subroutine // calls. if (nPts >= 2 && eDrawType >= PL_LINE && eDrawType <= PL_LINE_DASHDOTDOT) { // Draw all "line" types. stat = Polyline(hDC, aPts, nPts); if (stat == 0) { // In some cases (not well understood), Polyline // fails. When this happens, draw the line one // point at a time. MoveToEx(hDC, aPts[0].x, aPts[0].y, NULL); for (j=1; j<nPts; j++) LineTo(hDC, aPts[j].x, aPts[j].y); } SetPixel(hDC, aPts[nPts-1].x, aPts[nPts-1].y, rgb); } else if (eDrawType >= PL_SQUARE && eDrawType <= PL_CROSS) { // Draw all "plot mark" types. int wid, ht; ht = PL_YPTS_TO_YPIX(fPts); wid = PL_XPTS_TO_XPIX(fPts); for (j=0; j<nPts; j++) { retStat = PlDraw_discrete(pPlot, hDC, aPts[j].x, aPts[j].y, wid, ht, eDrawType, 0, 0, 0, 0, 0, 0, rgb); if (retStat != PL_OK) goto done; } } else { // Draw PL_POINT type. int nX, nY; nX = PL_XPTS_TO_XPIX(fPts); nY = PL_YPTS_TO_YPIX(fPts); if (nX <= 1 && nY <= 1) { for (j=0; j<nPts; j++) SetPixel(hDC, aPts[j].x, aPts[j].y, rgb); } else { int xL, xR, yB, yT; int iHalfWid=(nX - 1)/2; int iHalfHt=(nY - 1)/2; if ((hPen = CreatePen(PS_SOLID, 1, rgb)) == 0) goto gdi_error; /* KG */ //hOldPen = SelectObject(hDC, hPen); hOldPen = (HPEN)SelectObject(hDC, hPen); if ((hBrush = CreateSolidBrush(rgb)) == 0) goto gdi_error; /* KG */ //hOldBrush = SelectObject(hDC, hBrush); hOldBrush = (HBRUSH)SelectObject(hDC, hBrush); for (j=0; j<nPts; j++) { xL = aPts[j].x - iHalfWid; xR = xL + nX; yT = aPts[j].y - iHalfHt; yB = yT + nY; Ellipse(hDC, xL, yT, xR, yB); } } } done: if (hOldPen != 0) SelectObject(hDC, hOldPen); if (hPen != 0) DeleteObject(hPen); if (hOldBrush != 0) SelectObject(hDC, hOldBrush); if (hBrush != 0) DeleteObject(hBrush); return retStat; gdi_error: retStat = PL_GDI_FAIL; goto done; }