📄 setwallblockdlg.cpp
字号:
#include "stdafx.h"
#include "45MapMaker.h"
#include "SetWallBlockDlg.h"
#include ".\setwallblockdlg.h"
//SetWallBlockDlg 对话框
void SetWallBlockDlg::TranBitblt(HDC *tarDC,int x,int y,int w,int h,HDC *srcDC,int sx,int sy,COLORREF rgbMask)
//透明贴图函数,tarDC 贴图目标DC srcDC贴图原DC x y 贴图目标DC的坐标 sx,xy原DC坐标 rgbMask关键色
{
HDC ImageDC,MaskDC;
HBITMAP Image;
HBITMAP maskBitmap;
//创建宽高位wh的位图
Image = CreateCompatibleBitmap(*tarDC,w,h);//创建一个和tarDC环境一样的位图,并且设置宽和高
maskBitmap = CreateBitmap( w, h, 1, 1, NULL );//创建黑白位图
//创建兼容内存dc
ImageDC = CreateCompatibleDC(*tarDC);
MaskDC = CreateCompatibleDC(*tarDC);
//设备描述表和位图关联,就是说设备描述表的操作都在位图上面进行
SelectObject(ImageDC,Image);
SelectObject(MaskDC,maskBitmap );
//帖原图
BitBlt(ImageDC,0,0,w,h,*srcDC,sx,sy,SRCCOPY);
SetBkColor(ImageDC,rgbMask);
BitBlt(MaskDC, 0, 0, w, h, ImageDC, 0, 0, SRCCOPY );
SetBkColor(ImageDC,RGB(0,0,0));
SetTextColor(ImageDC,RGB(255,255,255));
BitBlt(ImageDC,0, 0, w,h, MaskDC, 0, 0, SRCAND);
BitBlt(*tarDC,x,y,w, h, MaskDC, 0, 0, SRCAND);
BitBlt(*tarDC,x,y,w, h, ImageDC, 0, 0,SRCPAINT);
DeleteObject(ImageDC);
DeleteObject(MaskDC);
DeleteObject(Image);
DeleteObject(maskBitmap);
}
IMPLEMENT_DYNAMIC(SetWallBlockDlg, CDialog)
SetWallBlockDlg::SetWallBlockDlg(CWnd* pParent /*=NULL*/)
: CDialog(SetWallBlockDlg::IDD, pParent)
, m_Offistx(0)
, m_Offisty(0)
{
}
SetWallBlockDlg::SetWallBlockDlg(int id):CDialog(SetWallBlockDlg::IDD,NULL),m_Offistx(0),m_Offisty(0)
{
projectnum = 0;
mouse = 0;
editProject = false;
editCenter = false;
beginw = beginh = 0;
CMy45MapMakerApp* theApp=NULL;
theApp=(CMy45MapMakerApp*)AfxGetApp();
this->Image = theApp->GetCSurface("Wall",id); //取得图片的DDraw指针
this->Tile = theApp->GetCSurface("Tile",1); //取得1号Tile的指针
tileWidth = Tile->GetDDrawDesc().dwWidth;
tileHeight = Tile->GetDDrawDesc().dwHeight;
if(Image->GetDDrawDesc().dwWidth%(tileWidth/2)==0)
w = Image->GetDDrawDesc().dwWidth/(tileWidth/2)+1;
else
w = Image->GetDDrawDesc().dwWidth/(tileWidth/2)+2;
if(Image->GetDDrawDesc().dwHeight%tileHeight==0)
h = Image->GetDDrawDesc().dwHeight/tileHeight+1;
else
h = Image->GetDDrawDesc().dwHeight/(tileHeight)+2;
Imagex = (Image->GetDDrawDesc().dwWidth%(tileWidth/2))/2;
Imagey = (Image->GetDDrawDesc().dwHeight%tileHeight)/2;
center = theApp->GetCSurface("Wall",101);
project = theApp->GetCSurface("Wall",100);
centerx = w/2;
centery = h/2;
}
SetWallBlockDlg::SetWallBlockDlg(int id,WallConfig*temp):CDialog(SetWallBlockDlg::IDD,NULL),m_Offistx(0),m_Offisty(0)
{
projectnum = 0;
mouse = 0;
editProject = false;
editCenter = false;
beginw = beginh = 0;
CMy45MapMakerApp* theApp=NULL;
theApp=(CMy45MapMakerApp*)AfxGetApp();
this->Image = theApp->GetCSurface("Wall",id); //取得图片的DDraw指针
this->Tile = theApp->GetCSurface("Tile",1); //取得1号Tile的指针
tileWidth = Tile->GetDDrawDesc().dwWidth;
tileHeight = Tile->GetDDrawDesc().dwHeight;
if(Image->GetDDrawDesc().dwWidth%(tileWidth/2)==0)
w = Image->GetDDrawDesc().dwWidth/(tileWidth/2)+1;
else
w = Image->GetDDrawDesc().dwWidth/(tileWidth/2)+2;
if(Image->GetDDrawDesc().dwHeight%tileHeight==0)
h = Image->GetDDrawDesc().dwHeight/tileHeight+1;
else
h = Image->GetDDrawDesc().dwHeight/(tileHeight)+2;
Imagex = (Image->GetDDrawDesc().dwWidth%(tileWidth/2))/2;
Imagey = (Image->GetDDrawDesc().dwHeight%tileHeight)/2;
center = theApp->GetCSurface("Wall",101);
project = theApp->GetCSurface("Wall",100);
///////////////
//中心点位置: offx+Imagex , offy+Imagey
centerx = temp->centerx;
centery = temp->centery;
//temp.x = Imagexx-Imagex-m_Offistx;
m_Offistx = (centerx*(tileWidth/2))-Imagex-temp->offx;
if(centerx%2==0)
{
m_Offisty = (centery*(tileHeight)) - Imagey-temp->offy;
}
else
m_Offisty = (centery*(tileHeight)) - Imagey-temp->offy+tileHeight/2;
projectnum = temp->projectnumber;
vtProject = temp->project;
}
SetWallBlockDlg::~SetWallBlockDlg()
{
}
void SetWallBlockDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_BLOCKPIC, m_StaticPic);
DDX_Control(pDX, IDC_SCROLLBARY, ScrollBary);
DDX_Control(pDX, IDC_SCROLLBARX, ScrollBarx);
DDX_Text(pDX, IDC_OFFX, m_Offistx);
DDX_Text(pDX, IDC_OFFY, m_Offisty);
DDX_Control(pDX, IDC_RADIO1, m_flagsetprogjet);
DDX_Control(pDX, IDC_RADIO2, m_flagCenter);
DDX_Control(pDX, IDC_SPIN1, m_spinx);
DDX_Control(pDX, IDC_SPIN2, m_spiny);
}
BEGIN_MESSAGE_MAP(SetWallBlockDlg, CDialog)
ON_WM_PAINT()
ON_WM_MOUSEMOVE()
ON_BN_CLICKED(IDC_BTNSETBLOCK, OnBnClickedBtnsetblock)
ON_BN_CLICKED(IDC_BTNSETCENTER, OnBnClickedBtnsetcenter)
ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN1, OnDeltaposSpin1)
ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN2, OnDeltaposSpin2)
// ON_WM_CHAR()
//ON_WM_KEYUP()
ON_WM_VSCROLL()
ON_WM_HSCROLL()
//ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
//ON_WM_CONTEXTMENU()
ON_WM_RBUTTONDOWN()
END_MESSAGE_MAP()
// SetWallBlockDlg 消息处理程序
//为了在对话框中使用滚动条控件,必须把对话框中的消息屏蔽掉,然后路由给我们的CMyScrollBar处理消息
//原理请见候婕的深入浅出mpc第三章 6大技术仿真的最后2章有关消息的路由
LRESULT SetWallBlockDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: 在此添加专用代码和/或调用基类
switch( message )
{
case WM_CREATE:
{
break;
}
case WM_VSCROLL:
{
break;
}
case WM_HSCROLL:
{
break;
}
}
return CDialog::WindowProc(message, wParam, lParam);
}
void SetWallBlockDlg::DrawStatic()
{
CRect rt;
m_StaticPic.GetClientRect(&rt);
CMy45MapMakerApp* theApp=(CMy45MapMakerApp*)AfxGetApp();
theApp->display->Clear();
DrawFront(rt);
// DrawProject(rt);
DrawImage(rt);
int w1 = rt.Width();
int h1 = rt.Height();
if(((w-1)*tileWidth/2)<w1)
w1 = (w-1)*tileWidth/2;
if(((h-1)*tileHeight)<h1)
h1 = (h-1)*tileHeight;
HDC hdc;
theApp->display->GetBackBuffer()->GetDC(&hdc);
::BitBlt(m_StaticPic.GetDC()->m_hDC,0,0,w1,h1,hdc,0,0,SRCCOPY);
theApp->display->GetBackBuffer()->ReleaseDC(hdc);//注意释放~~~~~~~~~~~~~~~~~~~~~~~~~
}
CPoint SetWallBlockDlg::calculateOffist()
{
//图片的偏移点为中心点与m_offist的和
CPoint temp;
temp.x = Imagexx-Imagex-m_Offistx;
temp.y = Imageyy-Imagey-m_Offisty;
int i=0;
std::vector<CPoint>::iterator is = vtProject.begin();
for(;is!=vtProject.end();is++)
i++;
projectnum = i;
return temp;
}
void SetWallBlockDlg::DrawProject()
{
CRect rt;
m_StaticPic.GetClientRect(&rt);
CMy45MapMakerApp* theApp=(CMy45MapMakerApp*)AfxGetApp();
int w2 = rt.Width();
int h2 = rt.Height();
if(((w-1)*tileWidth/2)<w2)
w2 = (w-1)*tileWidth/2;
if(((h-1)*tileHeight)<h2)
h2 = (h-1)*tileHeight;
HDC hdc;
theApp->display->GetBackBuffer()->GetDC(&hdc);
::BitBlt(m_StaticPic.GetDC()->m_hDC,0,0,w2,h2,hdc,0,0,SRCCOPY);
theApp->display->GetBackBuffer()->ReleaseDC(hdc);//注意释放~~~~~~~~~~~~~~~~~~~~~~~~~
center->GetDDrawSurface()->GetDC(&hdc);
HDC hdc2;
project->GetDDrawSurface()->GetDC(&hdc2);
int wid,heig;
int i=0,j=0,h1,id,ix,iy,ixbegin,hbegin;
ix = ixbegin=-tileWidth/2;
{
if((j+beginw)%2==0)
{
iy = hbegin=-tileHeight/2;
h1 = tileHeight/2;
}
else
{
iy = hbegin=0;
h1=-tileHeight/2;
}
}
for(i=0;i<w;i++)
{
for(j=0;j<h;j++)
{
{
if(i==w-1||i==12)
wid = tileWidth/2;
else
wid = tileWidth;
if(j==h-1||j==10)
{
if((beginw+i)%2==0)
heig = tileHeight/2;
else
heig = 0;
}
else
heig = tileHeight;
if(editCenter||editProject)
{
if((editx-beginw)==i&&(edity-beginh)==j)
{
if(editCenter)
this->TranBitblt(&(m_StaticPic.GetDC()->m_hDC),ix,iy,wid,heig,&hdc,0,0,RGB(255,0,255));
else
this->TranBitblt(&(m_StaticPic.GetDC()->m_hDC),ix,iy,wid,heig,&hdc2,0,0,RGB(255,0,255));
}
}
}
iy+=tileHeight;
}
ix=ixbegin+tileWidth/2;//每次画完一列之后x坐标要向右移动
ixbegin+=tileWidth/2; //然后作一下纪录
iy=hbegin+h1; //iy要回到原来位置并且变动
hbegin+=h1;
h1 = -h1;
}
center->GetDDrawSurface()->ReleaseDC(hdc);
project->GetDDrawSurface()->ReleaseDC(hdc2);
}
void SetWallBlockDlg::DrawFront(CRect& rt)
{
CMy45MapMakerApp* theApp=(CMy45MapMakerApp*)AfxGetApp();
int width = 8; //需要画画的区域大小
int height =6; //
int i=0,j=0,h1,id,ix,iy,ixbegin,hbegin;
ix = ixbegin=-tileWidth/2;
{
if((j+beginw)%2==0)
{
iy = hbegin=-tileHeight/2;
h1 = tileHeight/2;
}
else
{
iy = hbegin=0;
h1=-tileHeight/2;
}
}
for(i=0;i<w;i++)
{
for(j=0;j<h;j++)
{
{
if(this->Tile)
{
theApp->display->Blt(ix,iy,Tile);
}
//画投影
std::vector<CPoint>::iterator is = vtProject.begin();
for(;is!=vtProject.end();is++)
{
if(((*is).x-beginw)==i&&((*is).y-beginh)==j)
{
theApp->display->Blt(ix,iy,this->project);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -