コード例 #1
0
// @pymethod int|PyCRgn|GetRgnBox|Retrieves the coordinates of the bounding rectangle of the CRgn object
// Return Values: the bounding rectangle as a tuple (l,t,r,b)
PyObject *
PyCRgn::get_rgn_box(PyObject *self, PyObject *args)
	{
	CRgn *pRgn = PyCRgn::GetRgn(self);
	if (!pRgn) return NULL;

	CHECK_NO_ARGS2(args,GetRgnBox);

	RECT rect = {0,0,0,0};
	int result=pRgn->GetRgnBox(&rect);

	return Py_BuildValue("i(iiii)", result, rect.left, rect.top, rect.right, rect.bottom);
	}
コード例 #2
0
ファイル: ChildView.cpp プロジェクト: cosmicflame/tmviewer
void CChildView::OnPaint() 
{
  CPaintDC *dc;
  CDC *pdc;
  CRgn ur;
  ur.CreateRectRgn(0, 0, 0, 0);
  GetUpdateRgn(&ur);

  CRect cr;
  GetClientRect(&cr);
  if (theApp.m_bStarted && !theApp.m_map.IsEmpty()) {
//    pdc = &dc;
    m_MemDC.SelectClipRgn(&ur);
    pdc = &m_MemDC;

    theApp.m_map.DrawMap(*pdc, &cr, &ur);

    CRect r;
//    r = cr;
    ur.GetRgnBox(r);
//    r.InflateRect(1, 1);
    if (r.left < 0)
      r.left = 0;
    if (r.top < 0)
      r.top = 0;
  	dc = new CPaintDC(this); // device context for painting
    dc->BitBlt(r.left, r.top, r.Width(), r.Height(), &m_MemDC, r.left, r.top, SRCCOPY);
  }
  else {
  	dc = new CPaintDC(this); // device context for painting
    if (theApp.m_bStarted) {
      dc->SetTextAlign(TA_CENTER);
      CPoint cp = cr.CenterPoint();
      CString s;
      s.Format("There are no maps in '%s'", theApp.m_map.m_sMapsPath);
      dc->ExtTextOut(cp.x, cp.y - dc->GetOutputTextExtent("W").cy/2, ETO_OPAQUE, &cr, s, NULL);
    }
    else {
      dc->FillSolidRect(cr, 0);
    }
  }
  delete dc;
}
コード例 #3
0
ファイル: MyCom1.cpp プロジェクト: KnowNo/backup
STDMETHODIMP CMyCom1::DrawOffset(unsigned long m_pDC, unsigned long m_pOffset, double m_Scale, unsigned long m_pGraphInfo, BOOL scale_flag, BOOL m_active_flag)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState())

	// TODO: Add your implementation code here
	CClientDC * pDC = (CClientDC*) m_pDC;
	GraphInfo * pGraphInfo;

	//设置
	if ( m_pGraphInfo != NULL )
	{
		pGraphInfo = (GraphInfo*)m_pGraphInfo;
		m_GraphInfo.SetGraphInfo(*pGraphInfo);
	}
	else
		pGraphInfo = &m_GraphInfo;
	
		
	//计算偏移量
	if ( m_pOffset != NULL )
	{
		CPoint * offset = (CPoint *)m_pOffset;
		OffsetRgn((unsigned long)offset);
	}

	//设置激活标志
	isActive = m_active_flag;

	double scale = 0;
	m_scale_flag = scale_flag;
	if ( m_scale_flag )
		scale = m_Scale;
	else
		scale = 1;

	CFont * sysFont = pDC->SelectObject(&(pGraphInfo->font));
	CPen * pen = new CPen( pGraphInfo->normal_penStyle, pGraphInfo->normal_linewidth, pGraphInfo->normal_linecolor );	//构造画笔
	CPen * sysPen = pDC->SelectObject(pen);
	CBrush * normalBrush = new CBrush( pGraphInfo->normal_regioncolor );	//普通显示的画刷
	CBrush * activeBrush = new CBrush( pGraphInfo->active_regioncolor );	//激活后的画刷
	CBrush * blackBrush = new CBrush( BLACKBRUSHCOLOR );
	
	CRgn outRgn;
	outRgn.CreateRectRgn(0, 0, 5, 5);
	CRect smallRect;
	
	//判断是否激活了,如果激活,添加outRect
	if ( isActive )	//激活
	{
		if ( m_scale_flag )	//如果是在modelview区域
		{
			//选中后,在外边画一个方框
			outRgn.CombineRgn(&upRgn, &downRgn, RGN_OR);
			outRgn.GetRgnBox(&outRect);
			outRect.InflateRect(5, 5);
			
			pDC->MoveTo(outRect.left, outRect.top);
			pDC->LineTo(outRect.right, outRect.top);
			pDC->LineTo(outRect.right, outRect.bottom);
			pDC->LineTo(outRect.left, outRect.bottom);
			pDC->LineTo(outRect.left, outRect.top);

			//画出upRgn, downRgn, 和连线
			//pDC->FillRgn(&upRgn, normalBrush);
			CRect upRect;
			upRgn.GetRgnBox(upRect);
			pDC->Rectangle(upRect);
			pDC->MoveTo(upPoints[2]);
			pDC->LineTo(upPoints[5]);

			pDC->MoveTo(topPoint);
			pDC->LineTo(bottomPoint);
			pDC->MoveTo(leftPoint);
			pDC->LineTo(rightPoint);
			pDC->FillRgn(&downRgn, normalBrush);

			inRect.SetRect(upPoints[0].x, upPoints[0].y, upPoints[2].x, upPoints[2].y);
			pDC->SetTextColor(pGraphInfo->textcolor);
			pDC->DrawText(m_name, inRect, TEXTOUTFOMAT);	//|DT_END_ELLIPSIS);
						
			//在矩形的角上,画四个小矩形,5*5象素
			smallRect.SetRect(outRect.left, outRect.top, outRect.left+5, outRect.top+5);
			pDC->FillRect(smallRect, blackBrush);
			smallRect.SetRect(outRect.right-5, outRect.top, outRect.right, outRect.top+5);
			pDC->FillRect(smallRect, blackBrush);
			smallRect.SetRect(outRect.right-5, outRect.bottom-5, outRect.right, outRect.bottom);
			pDC->FillRect(smallRect, blackBrush);
			smallRect.SetRect(outRect.left, outRect.bottom-5, outRect.left+5, outRect.bottom);
			pDC->FillRect(smallRect, blackBrush);
		}
		else	//如果是在comview区域
		{
			//选中后,在外边画一个方框
			downRgn.GetRgnBox(&outRect);
			outRect.InflateRect(5, 5);

			pDC->MoveTo(outRect.left, outRect.top);
			pDC->LineTo(outRect.right, outRect.top);
			pDC->LineTo(outRect.right, outRect.bottom);
			pDC->LineTo(outRect.left, outRect.bottom);
			pDC->LineTo(outRect.left, outRect.top);

			//画出downRgn
			pDC->FillRgn(&downRgn, normalBrush);

			//在矩形的角上,画四个小矩形,5*5象素
			smallRect.SetRect(outRect.left, outRect.top, outRect.left+5, outRect.top+5);
			pDC->FillRect(smallRect, blackBrush);
			smallRect.SetRect(outRect.right-5, outRect.top, outRect.right, outRect.top+5);
			pDC->FillRect(smallRect, blackBrush);
			smallRect.SetRect(outRect.right-5, outRect.bottom-5, outRect.right, outRect.bottom);
			pDC->FillRect(smallRect, blackBrush);
			smallRect.SetRect(outRect.left, outRect.bottom-5, outRect.left+5, outRect.bottom);
			pDC->FillRect(smallRect, blackBrush);
		}
	}
	else	//未激活
	{
		if ( m_scale_flag )	//如果是在modelview区域
		{
			//画出upRgn, downRgn, 和连线
			//pDC->FillRgn(&upRgn, normalBrush);
			CRect upRect;
			upRgn.GetRgnBox(upRect);
			pDC->Rectangle(upRect);
			pDC->MoveTo(upPoints[2]);
			pDC->LineTo(upPoints[5]);

			pDC->MoveTo(topPoint);
			pDC->LineTo(bottomPoint);
			pDC->MoveTo(leftPoint);
			pDC->LineTo(rightPoint);
			pDC->FillRgn(&downRgn, normalBrush);

			inRect.SetRect(upPoints[0].x, upPoints[0].y, upPoints[2].x, upPoints[2].y);
			pDC->SetTextColor(pGraphInfo->textcolor);
			pDC->DrawText(m_name, inRect, TEXTOUTFOMAT);	//|DT_END_ELLIPSIS);
		}
		else	//如果是在comview区域
		{
			//画出downRgn
			pDC->FillRgn(&downRgn, normalBrush);
		}
	}

		//释放
	pDC->SelectObject(sysFont);
	pDC->SelectObject(sysPen);
	
	delete(pen);
	delete(normalBrush);
	delete(activeBrush);
	delete(blackBrush);
	
	return S_OK;
}
コード例 #4
0
ファイル: mfxWhlPan.cpp プロジェクト: aolko/construct
BOOL CWheelWnd::Create(CWnd* pParentWnd, WORD wStyle, CAutoPanParameters* pAutoPanParameters)
{
	ASSERT(m_bIsInitialized);
	ASSERT(::IsWindow(pParentWnd->m_hWnd));

	// Is there a window to pan?
	if (!pParentWnd || !::IsWindow(pParentWnd->m_hWnd))
	{
		delete this;
		return FALSE;
	}

	// copy style
	m_wStyle = wStyle;

#ifdef _DEBUG
	TCHAR szClassName[MAX_PATH];
	::GetClassName(pParentWnd->m_hWnd, szClassName, MAX_PATH);
	TRACE1("We are panning a \"%s\"\n", szClassName);
#endif //_DEBUG

	if (pAutoPanParameters == NULL)
	{
		if (wStyle & MFX_WHEELWNDSTYLE_SCROLLBYMESSAGE)
		{
			pAutoPanParameters = &m_AutoPanParametersMessage;
		}
		else if (wStyle & MFX_WHEELWNDSTYLE_SCROLLBYMESSAGEEX)
		{
			pAutoPanParameters = &m_AutoPanParametersLineMessages;
		}
		else if (wStyle & MFX_WHEELWNDSTYLE_SCROLLBYMESSAGEREG)
		{
			pAutoPanParameters = &m_AutoPanParametersRegMessage;
		}
		else if (wStyle & MFX_WHEELWNDSTYLE_SCROLLBYMESSAGETRK)
		{
			pAutoPanParameters = &m_AutoPanParametersMessageThumbTrack;
		}
	}

	if (pAutoPanParameters == NULL)
	{
		// Set algorithms for common controls...
		CAutoPanParameters* pRealisation;
		for (POSITION pos = m_lstAutoPanParameters.GetHeadPosition(); pos != NULL; )
		{
			pRealisation = m_lstAutoPanParameters.GetNext(pos);
			m_pParentWnd = pRealisation->PanThisWindow(pParentWnd);

			if (m_pParentWnd)
			{
				m_pRealisation = pRealisation;
				break;
			}
		}
	}
	else
	{
		m_pRealisation = pAutoPanParameters;
		m_pParentWnd   = pParentWnd;
	}

	if (m_pRealisation && m_pParentWnd)
	{
		m_bNoVertScroll  = (wStyle & MFX_WHEELWNDSTYLE_LEFTRIGHTONLY)?true:false;
		m_bNoVertScroll |= m_pRealisation->NoVertScroll(m_pParentWnd);

		m_bNoHorzScroll  = (wStyle & MFX_WHEELWNDSTYLE_UPDOWNONLY)?true:false;
		m_bNoHorzScroll |= m_pRealisation->NoHorzScroll(m_pParentWnd);
	}

	// Is there a way to pan this window?
	// Can we pan the window to any direction?
	if(!m_pRealisation || !m_pParentWnd || (m_bNoVertScroll && m_bNoHorzScroll))
	{
		delete this;
		return FALSE;
	}

	// start xtraverse mods
//	HWND app = ::GetAncestor(pParentWnd->GetSafeHwnd(), GA_ROOTOWNER);
//	::SendMessage(app, WM_SETREDRAW, FALSE, 0);
	// end xtraverse mods

	// Get the Window!
	if (!CreateEx(
			WS_EX_TOOLWINDOW,
			AfxRegisterWndClass(CS_SAVEBITS), NULL, WS_CLIPSIBLINGS|WS_POPUP,
			0, 0, 1, 1,
			NULL, NULL))
	{
		TRACE0("Failed to create window in CreateEx\n");
		ASSERT(0);
		return FALSE;
	}

	CRgn rgn;
	m_pRealisation->GetBitmapDimensions(bitmapSize, m_pParentWnd);
	m_pRealisation->CreateWindowRegion(rgn, m_pParentWnd);

	CRect rcWndDrag;
	rgn.GetRgnBox(&rcWndDrag);

	m_WindowSize.cx = rcWndDrag.Width();
	m_WindowSize.cy = rcWndDrag.Height();

	rcWndDrag.TopLeft().x = 0;
	rcWndDrag.TopLeft().y = 0;
	rcWndDrag.OffsetRect(-rcWndDrag.Width()/2, -rcWndDrag.Height()/2);

	GetCursorPos(&m_ptWheelOrg);
	rcWndDrag.OffsetRect(m_ptWheelOrg.x, m_ptWheelOrg.y);

	SetWindowRgn(rgn, FALSE);
	MoveWindow(rcWndDrag);

	if (m_pRealisation->GetWindowResID(m_pParentWnd) != 0) 
	{
		m_bmpOrigin.LoadBitmap(m_pRealisation->GetWindowResID(m_pParentWnd));
		ShowWindow(SW_SHOW);
	}

	SetCapture();
	m_nWheelTimer = SetTimer(1968, TIMER_DELAY_MS, NULL);

	m_nOriginBmpIndex=bitmapSize.cx;
	if(!m_bNoVertScroll)
	{
		m_nOriginBmpIndex=bitmapSize.cx * 2;
		if(!m_bNoHorzScroll)
			m_nOriginBmpIndex=0;
	}
	
	// start xtraverse mods
//	::SendMessage(app, WM_NCACTIVATE, TRUE, 0);
//	::SendMessage(app, WM_SETREDRAW, TRUE, 0);
	// end xtraverse mods

	return TRUE;
}
コード例 #5
0
//****************************************************************************************
void CBCGPControlBarImpl::DrawNcArea ()
{
	CWindowDC dc(m_pBar);

	CRect rectClient;
	m_pBar->GetClientRect(rectClient);

	CRect rectWindow;
	m_pBar->GetWindowRect(rectWindow);

	m_pBar->ScreenToClient(rectWindow);
	rectClient.OffsetRect(-rectWindow.left, -rectWindow.top);
	dc.ExcludeClipRect (rectClient);

	BOOL bRTL = m_pBar->GetExStyle() & WS_EX_LAYOUTRTL;

	{
		MSG* pMsg = &AfxGetThreadState()->m_lastSentMsg;

		ASSERT (pMsg->hwnd == m_pBar->m_hWnd);
		ASSERT (pMsg->message == WM_NCPAINT);

		CRgn* pRgn = NULL;
		if (pMsg->wParam != 1 && 
			(pRgn = CRgn::FromHandle ((HRGN) pMsg->wParam)) != NULL)
		{
			CRect rect;
			m_pBar->GetWindowRect (rect);

			if (bRTL)
			{
				CRect rect2;
				pRgn->GetRgnBox(&rect2);
				rect2.OffsetRect(rect.right - rect2.right - rect2.left, -rect.top);
				CRgn rgn;
				rgn.CreateRectRgnIndirect(&rect2);
				dc.SelectClipRgn(&rgn, RGN_AND);
			}
			else
			{
				pRgn->OffsetRgn (- rect.TopLeft ());
				dc.SelectClipRgn (pRgn, RGN_AND);
			}
		}
	}

	if (!m_pBar->m_bIsTransparentBorder)
	{
		// draw borders in non-client area
		rectWindow.OffsetRect(-rectWindow.left, -rectWindow.top);
		CBCGPVisualManager::GetInstance ()->OnDrawBarBorder (&dc, m_pBar, rectWindow);

		// erase parts not drawn
		dc.IntersectClipRect(rectWindow);
		CBCGPVisualManager::GetInstance ()->OnFillBarBackground  (&dc, m_pBar, rectWindow,
			CRect (0, 0, 0, 0), TRUE /* NC area */);
	}
	else
	{
		GetBackgroundFromParent(&dc);
	}

	// draw gripper in non-client area
	if ((m_pBar->GetBarStyle () & (CBRS_GRIPPER|CBRS_FLOATING)) != CBRS_GRIPPER)
	{
		dc.SelectClipRgn (NULL);
		return;
	}

	CRect rectGripper;
	GetGripperRect (rectGripper);

	if (rectGripper.Width() >= 1 && rectGripper.Height() >= 1)
	{
		BOOL bHorz = (m_pBar->GetBarStyle () & CBRS_ORIENT_HORZ) ? TRUE : FALSE;

		CBCGPVisualManager::GetInstance ()->OnDrawBarGripper (
			&dc, rectGripper, bHorz, m_pBar);
	}

	dc.SelectClipRgn (NULL);
}
コード例 #6
0
LRESULT CRegionSelect::OnLButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	if(!Down) return 0;
	Down = false;
	End.x = LOWORD(lParam)+1; 
	End.y = HIWORD(lParam)+1;
	CRgn newRegion;	RECT winRect;
	SHORT shiftState = GetAsyncKeyState(VK_SHIFT);

	WORD fwKeys = wParam; 
	m_bPictureChanged = true;

	if(m_SelectionMode == smFreeform) 
	{
		Finish();
		return 0;
	}

	if(m_SelectionMode != smWindowHandles || (abs(End.x-Start.x)>7 && abs(End.y-Start.y)>7))
	newRegion.CreateRectRgn(Start.x,Start.y,End.x,End.y);

	else
	{
		
		::GetWindowRect(hSelWnd, &winRect);

		newRegion.CreateRectRgnIndirect(&winRect);
		newRegion.OffsetRgn(topLeft);
		RECT invRect;
		newRegion.GetRgnBox(&invRect);

		Start.x = invRect.left;
		Start.y = invRect.top;
		End.x = invRect.right;
		End.y = invRect.bottom;
		if(fwKeys & MK_CONTROL)
			m_SelectedWindowsRegion.AddWindow(hSelWnd, false);
		else m_SelectedWindowsRegion.AddWindow(hSelWnd, true);
		//hSelWnd = 0;
	}

	if(fwKeys & MK_CONTROL)	
	{
		m_SelectionRegion.CombineRgn(newRegion, RGN_DIFF);
		
	}
	else if(shiftState& 0x8000) // shift is down
	{
		m_SelectionRegion.CombineRgn(newRegion, RGN_OR);
	}
	else
	{
		m_SelectionRegion.CombineRgn(newRegion, RGN_OR);
		Finish();
		return 0;
	}
	if(!RectCount)
	{
		RectCount++;
		Invalidate();
	}
	else{
	RectCount++;

		RECT RectToRepaint;
		//if(m_SelectionMode != smWindowHandles)
		{
	RectToRepaint.left = min(Start.x, End.x) - m_brushSize;
	RectToRepaint.top = min(Start.y, End.y) - m_brushSize;
	RectToRepaint.right = max(Start.x, End.x) + m_brushSize;
	RectToRepaint.bottom = max(Start.y, End.y) + m_brushSize;
		
InvalidateRect(&RectToRepaint);
		}

	}

	Start.x = -1;
	Start.y = -1;
	End.x = -1;
	End.y = -1;
	return 0;
}
コード例 #7
0
LRESULT CRegionSelect::OnPaint(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
{
	PAINTSTRUCT ps;
	BeginPaint(&ps);

	HDC dc = ps.hdc;

	int w = ps.rcPaint.right-ps.rcPaint.left;
	int h = ps.rcPaint.bottom-ps.rcPaint.top;

	if(m_bPictureChanged)
	{
		if(Down) return 0;
		RECT rc;
		GetClientRect(&rc);
		CRgn newRegion;
		newRegion.CreateRectRgn(0,0,rc.right,rc.bottom);
		SelectClipRgn(doubleDC, newRegion);
		BitBlt(doubleDC,ps.rcPaint.left,ps.rcPaint.top,w,h,memDC2,  ps.rcPaint.left,ps.rcPaint.top,SRCCOPY);
		newRegion.CombineRgn(m_SelectionRegion,RGN_DIFF);
		CBrush br;
		SelectClipRgn(doubleDC, newRegion);
		br.CreateSolidBrush(RGB(200,200,0));
		BLENDFUNCTION bf ;
		//настройки прозрачности
		bf.BlendOp = AC_SRC_OVER;
		bf.BlendFlags = 1;
		bf.SourceConstantAlpha = 40; // прозрачность 50% (0 - 255)
		bf.AlphaFormat = 0;///*0 */ /*AC_SRC_ALPHA*/0;
		
		if(RectCount) 
			if(AlphaBlend(doubleDC, ps.rcPaint.left, ps.rcPaint.top, w,h, alphaDC, ps.rcPaint.left, ps.rcPaint.top, w,h, bf)==FALSE)
			{
				//MessageBox(_T("Alphablend failed"));
			};
		newRegion.DeleteObject();
		newRegion.CreateRectRgn(0,0,rc.right,rc.bottom);
		SelectClipRgn(doubleDC, newRegion);
		RECT SelWndRect;
		if(hSelWnd)
		{
			CRgn WindowRgn = GetWindowVisibleRegion(hSelWnd);
			WindowRgn.OffsetRgn(topLeft);
			WindowRgn.GetRgnBox(&SelWndRect);
			CRect DrawingRect = SelWndRect;
			DrawingRect.DeflateRect(2, 2);
			SelectObject(doubleDC, pen);
			SetROP2(doubleDC, R2_NOTXORPEN);
			SelectClipRgn(doubleDC, 0);
			Rectangle(doubleDC, DrawingRect.left,DrawingRect.top, DrawingRect.right, DrawingRect.bottom);
		}
		m_bPictureChanged = false;
	}
	BitBlt(dc,ps.rcPaint.left,
		ps.rcPaint.top,w,h,doubleDC,ps.rcPaint.left,
		ps.rcPaint.top,SRCCOPY);

	EndPaint(&ps);
	m_bPainted = true;
	return 0;
}