📄 drawbase.cpp
字号:
// DrawBase.cpp: implementation of the CDrawBase class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DrawBase.h"
#include "DrawView.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDrawBase::CDrawBase( CDrawView & v ) : view( v )
{
this->draw_id = "";
memset( &this->draw , 0 , sizeof( DRAW ) );
this->draw.pen.lopnWidth = CPoint( 1 , 1 );
this->draw_select = false;
}
CDrawBase::~CDrawBase()
{
}
CString CDrawBase::GetId( void )
{
if( this->draw_id.IsEmpty())
this->draw_id.Format( "%s:%p" , this->view.username , this );
return this->draw_id;
}
void CDrawBase::SetId( const char * id )
{
this->draw_id = id;
}
CDrawBase * CDrawBase::Clone( void )
{
return NULL;
}
HCURSOR CDrawBase::GetCursor( void )
{
static HCURSOR hCursor = ::AfxGetApp()->LoadStandardCursor( IDC_ARROW );
return hCursor;
}
bool CDrawBase::Select( CRect & rc )
{
this->draw_select = false;
return false;
}
char * CDrawBase::Encode( int & size , bool erase )
{ //图元id
CString id = this->GetId( );
size = id.GetLength() + 1 + sizeof( DRAW );
char * buffer = new char[ size ];
ASSERT( buffer );
strcpy( buffer , id );
this->draw.version = WB_VERSION;
memcpy( buffer + id.GetLength() + 1 , &this->draw , sizeof( DRAW ) );
if( erase ) size -= sizeof( DRAW );
return buffer;
}
bool CDrawBase::Decode( char * buffer , int size )
{ //图元id
this->draw_id = buffer; size -= this->draw_id.GetLength() + 1;
if( size >= sizeof( DRAW ) )
memcpy( &this->draw , buffer + this->draw_id.GetLength() + 1 , sizeof( DRAW ) );
return this->draw.version == WB_VERSION;
}
void CDrawBase::OnDraw( CDC * pDC )
{
if( this->draw_select )
{
CPen pen( PS_DOT , 1 , RGB( 0 , 0 , 0 ) );
pDC->SelectObject( &pen );
pDC->SelectStockObject( NULL_BRUSH );
CRect rc( this->draw.start , this->draw.end );
rc.NormalizeRect();
rc.InflateRect( this->draw.pen.lopnWidth.x / 2 + 2 , this->draw.pen.lopnWidth.y / 2 + 2 );
pDC->Rectangle( rc );
}
static CPen pen;
if( pen.GetSafeHandle( ) ) pen.DeleteObject();
pen.CreatePenIndirect( &this->draw.pen );
static CBrush brush;
if( brush.GetSafeHandle( ) ) brush.DeleteObject();
brush.CreateBrushIndirect( &this->draw.brush );
pDC->SelectObject( &pen );
pDC->SelectObject( &brush );
}
void CDrawBase::OnLButtonDown( UINT nFlags, CPoint point )
{
if( nFlags & MK_LBUTTON )
this->draw.end = this->draw.start = point;
}
void CDrawBase::OnMouseMove( UINT nFlags, CPoint point )
{
if( nFlags & MK_LBUTTON )
{
this->draw.end = point;
//刷新
this->view.Invalidate();
}
}
void CDrawBase::OnLButtonUp( UINT nFlags, CPoint point )
{
if( nFlags & MK_LBUTTON )
{
this->draw.end = point;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -