⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 photo.cpp

📁 三国志IX武将编辑器
💻 CPP
字号:
// Photo.cpp : implementation file
//

#include "stdafx.h"
#include "San9Edit.h"
#include "Photo.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPhoto dialog


CPhoto::CPhoto(CWnd* pParent /*=NULL*/)
	: CDialog(CPhoto::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPhoto)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_code=0xffff;
	oldpos.x=-1;
	oldpos.y=-1;
}


void CPhoto::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPhoto)
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPhoto, CDialog)
	//{{AFX_MSG_MAP(CPhoto)
	ON_WM_PAINT()
	ON_BN_CLICKED(IDC_OK, OnChange)
	ON_WM_LBUTTONDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPhoto message handlers

BOOL CPhoto::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_tempcode=m_code;

	Load();

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CPhoto::Load()
{
	char name[256];
	::GetModuleFileName(NULL,name,255);
	CString Name=name;
    
	Name=Name.Left(Name.ReverseFind('\\'));

	if(Name[Name.GetLength()-1]!='\\') Name+="\\";

	Name+="photo.bmp";

	m_pic.LoadPicture(IDR_JPEG_PHOTO,"JPEG_PHOTO");
}

void CPhoto::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
    Draw();
	// Do not call CDialog::OnPaint() for painting messages
}

CRect CPhoto::GetRect(int code)
{
   	CRect src;
	this->GetClientRect(&src);
 
	int width=(src.Width()-20)/16;
	int height=(src.Height()-50)/7;

	if(code>=1 && code<=32)
	{
	   code--;
       src.left=(code%8)*width;
	   src.top=(code/8)*height;
	}
	else
	if(code>=33 && code<=64)
	{
	   code-=33;
       src.left=(code%8)*width+width*8;
	   src.top=(code/8)*height;
	}
	else
	if(code>=65 && code<=80)
	{
	   code-=65;
       src.left=(code%8)*width;
	   src.top=(code/8)*height+height*4;
	}
	else
	if(code>=81 && code<=96)
	{
	   code-=81;
       src.left=(code%8)*width+width*8;
	   src.top=(code/8)*height+height*4;
	}
	else
	if(code>=97 && code<=100)
	{
	   code-=97;
       src.left=(code%8)*width;
	   src.top=height*6;
	}

	src.left+=10;
	src.top+=10;
    src.right=src.left+width;
	src.bottom=src.top+height;

	return src;
}

void CPhoto::Draw()
{
	CClientDC dc(this);
	CRect rc;
	this->GetClientRect(&rc);
 
	CRect src;
	
	for(int i=1;i<=100;i++)
	{
		src=GetRect(i);
		DrawSingle(dc.m_hDC,i,src);
	}

	//m_pic.DrawPicture(dc.m_hDC,10,10,rc.Width()-20,rc.Height()-50);

    src=GetRect(m_tempcode);
    OnLButtonDown(0, CPoint(src.left+5,src.top+5));
}

void CPhoto::DrawSingle(HDC hdc,int code,CRect rc)
{
	if(code<=0 || code>100) return;

	int width=(m_pic.GetWidth())/16;
	int height=(m_pic.GetHeight())/7;

	CRect src;

	if(code>=1 && code<=32)
	{
	   code--;
       src.left=(code%8)*width;
	   src.top=(code/8)*height;
	}
	else
	if(code>=33 && code<=64)
	{
	   code-=33;
       src.left=(code%8)*width+width*8;
	   src.top=(code/8)*height;
	}
	else
	if(code>=65 && code<=80)
	{
	   code-=65;
       src.left=(code%8)*width;
	   src.top=(code/8)*height+height*4;
	}
	else
	if(code>=81 && code<=96)
	{
	   code-=81;
       src.left=(code%8)*width+width*8;
	   src.top=(code/8)*height+height*4;
	}
	else
	if(code>=97 && code<=100)
	{
	   code-=97;
       src.left=(code%8)*width;
	   src.top=height*6;
	}
   
	src.right=src.left+width;
	src.bottom=src.top+height;

    m_pic.DrawRect(hdc,rc,src);
}

void CPhoto::OnChange()
{
   m_code=m_tempcode;
   EndDialog(IDOK);
}

void CPhoto::DrawRect(HDC hdc,int x1,int y1,int x2,int y2)
{
	::MoveToEx(hdc,x1,y1,NULL);
	::LineTo(hdc,x2,y1);
	::LineTo(hdc,x2,y2);
	::LineTo(hdc,x1,y2);
	::LineTo(hdc,x1,y1);
}

void CPhoto::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CRect rc;
	this->GetClientRect(&rc);
 
	int width=(rc.Width()-20)/16;
	int height=(rc.Height()-50)/7;

	int x=(point.x-10)/width;
	int y=(point.y-10)/height;

	if(x<16)
	{
		if(y>=0 && y<4)
		{
			if(x<8)
			{
			m_tempcode=0;
			m_tempcode+=y*8;
			m_tempcode+=x+1;
			}
			else
			{
			m_tempcode=32;
			m_tempcode+=y*8;
			m_tempcode+=(x-8)+1;
			}
		}
		else
		if(y>=4 && y<6)
		{
			if(x<8)
			{
			m_tempcode=64;
			m_tempcode+=(y-4)*8;
			m_tempcode+=x+1;
			}
			else
			{
			m_tempcode=80;
			m_tempcode+=(y-4)*8;
			m_tempcode+=(x-8)+1;
			}
		}
		else
		if(y==6)
		{
			m_tempcode=96;
			m_tempcode+=x+1;
		}
		else
		{
			CDialog::OnLButtonDown(nFlags, point);
			return;
		}
	}
    else
	{
	        CDialog::OnLButtonDown(nFlags, point);
			return;
	}

	if(m_tempcode>0 && m_tempcode<=100)
	{
		CClientDC dc(this);

		dc.SetROP2(R2_COPYPEN);
		CPen pen;
		pen.CreatePen(PS_SOLID,2,RGB(192,192,192));
		dc.SelectObject(&pen);

		if(!(oldpos.x==-1 && oldpos.y==-1))
		DrawRect(dc.m_hDC,oldpos.x*width+10,oldpos.y*height+10,(oldpos.x+1)*width+10,(oldpos.y+1)*height+10);

		oldpos.x=x;
		oldpos.y=y;

	    pen.CreatePen(PS_SOLID,2,RGB(255,0,0));
		dc.SelectObject(&pen);

        DrawRect(dc.m_hDC,oldpos.x*width+10,oldpos.y*height+10,(oldpos.x+1)*width+10,(oldpos.y+1)*height+10);

		pen.DeleteObject();
	}

	CDialog::OnLButtonDown(nFlags, point);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -