SelectDraw.cpp
资源名称:视频会议系统.rar [点击查看]
上传用户:popouu88
上传日期:2013-02-11
资源大小:2894k
文件大小:7k
源码类别:
IP电话/视频会议
开发平台:
Visual C++
- // SelectDraw.cpp: implementation of the CSelectDraw class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "..WB.h"
- #include "SelectDraw.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CSelectDraw::CSelectDraw( CDrawView * view ) : CDraw( view )
- {
- this->type = SELECT;
- this->m_bErase = false;
- if( this->pen.GetSafeHandle( ) )
- this->pen.DeleteObject( );
- this->pen.CreatePen( PS_DOT , 1 , RGB( 0 , 0 , 0 ) );
- if( this->brush.GetSafeHandle( ) )
- this->brush.DeleteObject( );
- this->brush.CreateStockObject( NULL_BRUSH );
- }
- CSelectDraw::~CSelectDraw( )
- {
- if( ! this->draw_list.empty( ) && ::IsWindow( this->view->GetSafeHwnd( ) ) )
- {
- CDC * pDC = this->view->GetMemDC( );
- int rop = pDC->SetROP2( R2_NOTXORPEN );
- //恢复选中的图元
- CRect rc;
- for( DRAW_LIST::iterator itr = this->draw_list.begin( ); itr != this->draw_list.end( ); itr++ )
- {
- ( * itr )->GetRgn( ).GetRgnBox( &rc );
- rc.InflateRect( 1 , 1 , 1 , 1 );
- pDC->Rectangle( &rc );
- }
- pDC->SetROP2( rop );
- this->draw_list.clear( );
- this->view->Invalidate( );
- }
- }
- //设定画笔颜色
- void CSelectDraw::SetColor( COLORREF color )
- {
- for( DRAW_LIST::iterator itr = this->draw_list.begin( ); itr != this->draw_list.end( ); itr ++ )
- {
- ( * itr )->SetColor( color );
- ( * itr )->Draw( );
- this->view->assembleData( * itr , CDrawView::MODIFY );
- }
- this->view->Invalidate( );
- }
- //取得画笔颜色
- COLORREF CSelectDraw::GetColor( void )
- {
- return RGB( 0 , 0 , 0 );
- }
- //设定画笔宽度
- void CSelectDraw::SetWidth( int width )
- {
- for( DRAW_LIST::iterator itr = this->draw_list.begin( ); itr != this->draw_list.end( ); itr ++ )
- {
- ( * itr )->SetWidth( width );
- ( * itr )->Draw( );
- }
- this->view->Invalidate( );
- }
- //取得画笔宽度
- int CSelectDraw::GetWidth( void )
- {
- return 1;
- }
- //设定画刷是否为空,缺省情况为空
- void CSelectDraw::SetEmpty( bool m_bEmpty )
- {
- this->m_bErase = m_bEmpty;
- }
- //判断画刷是否为空
- bool CSelectDraw::IsEmpty( void )
- {
- return this->m_bErase;
- }
- //选择图元
- void CSelectDraw::Select( void )
- { //取出内存画布
- CDC * pDC = this->view->GetMemDC( );
- //清除选择过的图元
- this->draw_list.clear( );
- //选择的矩形区域
- CRect rc( this->start , this->end );
- rc.NormalizeRect( );
- //清除所有图元后在重画没有被删除掉的图元
- pDC->FillSolidRect( 0 , 0 , this->dcSize.cx , this->dcSize.cy , pDC->GetBkColor( ) );
- //创建选择的区域
- if( this->selRgn.GetSafeHandle( ) )
- this->selRgn.DeleteObject( );
- this->selRgn.CreateRectRgn( 0 , 0 , 0 , 0 );
- CRgn r , r0;
- r.CreateRectRgn( 0 , 0 , 0 , 0 );
- //创建鼠标包含的区域
- r0.CreateRectRgn( rc.left , rc.top , rc.right , rc.bottom );
- //取得列表
- DRAW_LIST * drawlst = view->LockList( );
- bool m_bDelete = false;
- CDraw * draw = NULL;
- //设定选择画布
- pDC->SelectObject( &this->pen );
- pDC->SelectObject( &this->brush );
- //搜索所有图元
- for( DRAW_LIST::iterator itr = drawlst->begin( ); itr != drawlst->end( ); )
- {
- m_bDelete = false;
- draw = * itr;
- //选中了一个图元
- if( r.CombineRgn( &r0 , &draw->GetRgn( ) , RGN_AND ) != NULLREGION )
- {
- if( this->m_bErase )
- { //删除一个图元
- itr = drawlst->erase( itr );
- this->view->assembleData( draw , CDrawView::DEL );
- delete draw;
- m_bDelete = true;
- }
- else //选择一个图元
- {
- draw->Draw( pDC );
- this->draw_list.push_back( draw );
- draw->GetRgn( ).GetRgnBox( &rc );
- rc.InflateRect( 1 , 1 , 1 , 1 );
- //画出矩形框
- pDC->Rectangle( &rc );
- CRgn rr;
- //保存图元所在的最大矩形空间
- rr.CreateRectRgn( rc.left , rc.top , rc.right , rc.bottom );
- this->selRgn.CombineRgn( &this->selRgn , &rr , RGN_OR );
- }
- }
- else //没有删除,画出图元
- draw->Draw( pDC );
- if( ! m_bDelete )
- itr ++;
- }
- this->view->UnlockList( );
- this->view->Invalidate( );
- }
- void CSelectDraw::LButtonDown( UINT nFlags , CPoint point )
- {
- CDraw::LButtonDown( nFlags , point );
- //如果有图元选中且鼠标的当前位置不在选中区域,那么清除所有的选择
- if( ! this->draw_list.empty( ) && ! this->selRgn.PtInRegion( point ) )
- {
- CDC * pDC = this->view->GetMemDC( );
- int rop = pDC->SetROP2( R2_NOTXORPEN );
- CRect rc;
- for( DRAW_LIST::iterator itr = this->draw_list.begin( ); itr != this->draw_list.end( ); itr ++ )
- {
- ( * itr )->GetRgn( ).GetRgnBox( &rc );
- rc.InflateRect( 1 , 1 , 1 , 1 );
- pDC->Rectangle( &rc );
- }
- pDC->SetROP2( rop );
- //清除选择列表和选择框
- this->draw_list.clear( );
- this->selRgn.DeleteObject( );
- }
- }
- void CSelectDraw::MouseMove( UINT nFlags , CPoint point )
- { //设定鼠标形状
- if( this->selRgn.GetSafeHandle( ) )
- {
- HCURSOR hCursor = ::AfxGetApp( )->LoadStandardCursor( MAKEINTRESOURCE( this->selRgn.PtInRegion( point ) ? IDC_SIZEALL : IDC_ARROW ) );
- hCursor = ( HCURSOR )::SetClassLong( this->view->GetSafeHwnd( ) , GCL_HCURSOR , ( long )hCursor );
- ::DestroyCursor( hCursor );
- }
- if( nFlags & MK_LBUTTON )
- { //如果位图为空
- if( this->draw_list.empty( ) )
- CDraw::MouseMove( nFlags , point );
- else if( this->selRgn.GetSafeHandle( ) )
- { //计算移动的方向和大小
- CPoint pt = point - this->end;
- this->end = point;
- //移动区域
- this->selRgn.OffsetRgn( pt );
- CDC * pDC = this->view->GetMemDC( );
- CRect rc;
- int rop = pDC->SetROP2( R2_NOTXORPEN );
- //移动图元
- for( DRAW_LIST::iterator itr = this->draw_list.begin( ); itr != this->draw_list.end( ); itr ++ )
- {
- ( * itr )->GetRgn( ).GetRgnBox( &rc );
- rc.InflateRect( 1 , 1 , 1 , 1 );
- //清除矩形框
- pDC->Rectangle( &rc );
- //移动矩形框
- ( * itr )->GetRgn( ).OffsetRgn( pt );
- rc.OffsetRect( pt );
- pDC->Rectangle( &rc );
- }
- rop = pDC->SetROP2( rop );
- this->view->Invalidate( );
- }
- }
- }
- void CSelectDraw::LButtonUp( UINT nFlags , CPoint point )
- {
- this->end = point;
- if( ! this->draw_list.empty( ) )
- {
- CDC * pDC = this->view->GetMemDC( );
- //删掉所有的图像
- pDC->FillSolidRect( 0 , 0 , this->dcSize.cx , this->dcSize.cy , pDC->GetBkColor( ) );
- DRAW_LIST * drawlst = this->view->LockList( );
- for( DRAW_LIST::iterator itr = drawlst->begin( ); itr != drawlst->end( ); itr ++ )
- ( * itr )->Draw( pDC );
- //画出选择的矩形框和通知外部程序
- CRect rc;
- for( itr = this->draw_list.begin( ); itr != this->draw_list.end( ); itr ++ )
- {
- ( * itr )->GetRgn( ).GetRgnBox( &rc );
- this->view->assembleData( *itr , CDrawView::MODIFY );
- rc.InflateRect( 1 , 1 , 1 , 1 );
- pDC->Rectangle( rc );
- }//重画
- this->view->UnlockList( );
- this->view->Invalidate( );
- }
- else
- {
- if( this->end == this->start )
- this->end.Offset( 1 , 1 );
- this->Select( );
- }
- }
- CDC * CSelectDraw::Draw( CDC * pDC )
- {
- pDC = CDraw::Draw( pDC );
- if( pDC )
- {
- CRect rc( this->start , this->end );
- rc.NormalizeRect( );
- pDC->Rectangle( &rc );
- }
- return pDC;
- }