?? zuanobj.cpp
字號:
#include "StdAfx.h"
#include ".\zuanobj.h"
#using <mscorlib.dll>
#include "visdrawview.h"
#include "visdrawdoc.h"
//#include <math.h>
IMPLEMENT_SERIAL(CZuanObj, CFigureObj, 0)
CZuanObj::CZuanObj(void)
{
}
CZuanObj::~CZuanObj(void)
{
}
CZuanObj::CZuanObj(DrawObj drawObj)
: CFigureObj(drawObj)
{
pToolObj = NULL;
}
CZuanObj::CZuanObj(const CRect& position)
: CFigureObj(position)
{
ASSERT_VALID(this);
// m_picID=0;
m_pointx = 0.0;
m_pointy = 0.0;
m_ltx=m_lty=m_rbx=m_rby=0.0;
}
void CZuanObj::Draw(CVisDrawView* pView,CDC* pDC)
{
ASSERT_VALID(this);
//CPoint nPoint;
//pView->WorldToClient(nPoint,m_pointx,m_pointy);
//把世界坐標轉化為邏輯坐標
CPoint m_ltPoint, m_rbPoint;
CRect rect = CalcBounds(pView);
//nPoint.x=rect.TopLeft().x;
//nPoint.x=rect.TopLeft().y;
m_pic=pView->m_picIDzuan;
bitmap.LoadBitmap(m_pic);
CDC dcComp;
dcComp.CreateCompatibleDC(pDC);
dcComp.SelectObject(&bitmap);
BITMAP bmInfo;
bitmap.GetObject(sizeof(bmInfo),&bmInfo);
pDC->BitBlt(rect.TopLeft().x,rect.TopLeft().y,bmInfo.bmWidth,bmInfo.bmHeight, &dcComp, 0,0,SRCCOPY);
//pDC->SelectObject()
//m_width=bmInfo.bmWidth;
//m_height=bmInfo.bmHeight;
/*
m_RectTracker.m_rect=m_RectLP;
pDC->LPtoDP(m_RectTracker.m_rect);
if(IsSelected())m_RectTracker.Draw(pDC);
*/
bitmap.DeleteObject();
}
void CZuanObj::Serialize(CArchive& ar)
{
ASSERT_VALID(this);
//調用基類串行化
CFigureObj::Serialize(ar);
if (ar.IsStoring())
{
ar << m_ltx << m_lty << m_rbx << m_rby;
}
else
{
ar >> m_ltx >> m_lty >> m_rbx >> m_rby;
}
}
//設定直線端點坐標,為世界坐標
void CZuanObj::SetPoint(int ptNumber, double x, double y)
{
ASSERT(ptNumber <=2);
switch(ptNumber)
{
case 1:
m_ltx = x;
m_lty = y;
break;
case 2:
m_rbx = x;
m_rby = y;
break;
}
}
//返回直線端點的世界坐標
void CZuanObj::GetPoint(int ptNumber, double& x, double& y)
{
ASSERT(ptNumber <=2);
switch(ptNumber)
{
case 1:
x = m_ltx;
y = m_lty;
break;
case 2:
x = m_rbx;
y = m_rby;
break;
}
}
/*
void CCheObj::SetPoint(double pointx, double pointy)
{
m_pointx = pointx;
m_pointy = pointy;
}
void CCheObj::GetPoint(double& pointx, double& pointy)
{
pointx = m_pointx;
pointy = m_pointy;
}
*/
/*//計算外接矩形,以邏輯坐標表示
CRect CCheObj::CalcBounds(CVisDrawView* pView)
{
CPoint nPoint;
pView->WorldToClient(nPoint,m_pointx,m_pointy);
rect.TopLeft()=nPoint;
rect.BottomRight().x=nPoint.x+m_width;
rect.BottomRight().y=nPoint.y+m_height;
//return rect;
//m_Rect.left = pt->x;
//m_Rect.top = pt->y;
//m_Rect.right = m_Rect.left +2000; //+100;
//m_Rect.bottom = m_Rect.top -1000; //+60;
//m_RectLP = rect;
//m_RectTracker.m_rect = rect;
//m_RectTracker.m_nStyle = CRectTracker::resizeOutside;
//m_RectTracker.Draw(pDC);
m_position = rect;
return m_position;
//}
}
*/
//計算外接矩形,以邏輯坐標表示
CRect CZuanObj::CalcBounds(CVisDrawView* pView)
{
CRect rect;
CPoint ltPoint, rbPoint;
pView->WorldToClient(ltPoint,m_ltx,m_lty);
pView->WorldToClient(rbPoint,m_rbx,m_rby);
rect.TopLeft() = ltPoint;
rect.BottomRight() = rbPoint;
m_position = rect;
return rect;
}
/*
double CCheObj::PointToLine(CPoint nStartPt,CPoint nEndPt, CPoint pt)
{
int A,B,C;
double distance;
//計算直線參數
A = nStartPt.y - nEndPt.y;
B = nEndPt.x - nStartPt.x;
C = nStartPt.x*nEndPt.y - nEndPt.x*nStartPt.y;
//計算點到直線距離
distance = (A*pt.x + B*pt.y + C)*(A*pt.x + B*pt.y + C)/(A*A + B*B);
distance = sqrt(distance);
return distance;
}
*/
BOOL CZuanObj::IsSelected(CVisDrawView* pView, const CPoint& point)
{
CPoint local, StartPt, EndPt;
//參數point是鼠標的邏輯坐標
int distance, nSelectDistance;
CRect rect = m_position;
//CPoint local;
local = point;
//鼠標點的設備坐標
pView->DocToClient(rect);
//識別精度值
nSelectDistance = pView->GetDocument()->GetSetectDistance()/2;
//鼠標點的設備坐標
pView->DocToClient(local);
//CPoint pt;
//把點的坐標轉化為邏輯坐標
//pView->WorldToClient(pt, m_pointx, m_pointy);
//把點的坐標由邏輯坐標轉化為設備坐標
//pView->DocToClient(pt);
//計算鼠標點point與點pt之間的像素距離
//第一條直線
distance = abs(local.y - rect.top);
if(distance < nSelectDistance) return true;
//第二條直線
distance = abs(local.x - rect.right);
if(distance < nSelectDistance) return true;
//第三條直線
distance = abs(local.y - rect.bottom);
if(distance < nSelectDistance) return true;
//第四條直線
distance = abs(local.x - rect.left);
if(distance < nSelectDistance) return true;
//根據拾取條件判斷圖元是否被拾取
//return (distance < nSelectDistance);
return false;
}
//返回手柄個數
int CZuanObj::GetHandleCount()
{
ASSERT_VALID(this);
return 9;
}
// 返回手柄中心邏輯坐標
CPoint CZuanObj::GetHandle(CVisDrawView* pView, int nHandle)
{
ASSERT_VALID(this);
return CFigureObj::GetHandle(pView, nHandle);
}
// delta為邏輯坐標
void CZuanObj::MoveTo(CPoint delta, CVisDrawView* pView)
{
ASSERT_VALID(this);
//把delta轉化為世界坐標
double pointx,pointy;
pointx = pView->ClientToWorld(delta.x);
pointy = -pView->ClientToWorld(delta.y);
//修改矩形兩頂點坐標
m_ltx = m_ltx + pointx;
m_lty = m_lty + pointy;
m_rbx = m_rbx + pointx;
m_rby = m_rby + pointy;
//重新計算邊界矩形
CalcBounds(pView);
//修改文檔標志
m_pDocument->SetModifiedFlag();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -