📄 textrue.cpp
字号:
// TEXTRUE.cpp : implementation file
//
#include "stdafx.h"
#include "Designer.h"
#include "TEXTRUE.h"
#include <afxdlgs.h>
#include "MainFrm.h"
#include "DesignerView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// TEXTRUE dialog
//extern int jing[];
//extern int wei[];
//extern int calculate;
TEXTRUE::TEXTRUE(CWnd* pParent /*=NULL*/)
: CDialog(TEXTRUE::IDD, pParent)
{
//{{AFX_DATA_INIT(TEXTRUE)
m_jm = 0;
m_wm = 0;
//}}AFX_DATA_INIT
}
TEXTRUE::TEXTRUE(CView *pView)
{
this->m_type = 0;
for(int i =0;i<MAXJW;i++)
for(int j=0;j<MAXJW;j++)
this->m_jwlabel[j][i] =0;
//this->m_JN = this->m_jing_num;
//this->m_WN = this->m_wei_num;
// this->m_texture_color = RGB(255,0,0);
// CWnd *pButton;
// pButton = GetDlgItem(IDC_BUTTON_RED,NULL);
}
void TEXTRUE::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(TEXTRUE)
// DDX_Text(pDX, IDC_EDIT_JM, m_jm);
// DDX_Text(pDX, IDC_EDIT_WM, m_wm);
// DDX_Text(pDX, IDC_EDIT_WEINUM, m_WN);
// DDX_Text(pDX, IDC_EDIT_JINGNUM, m_JN);
//}}AFX_DATA_MAP
}
BOOL TEXTRUE::Create()
{
return CDialog::Create(TEXTRUE::IDD);
}
BEGIN_MESSAGE_MAP(TEXTRUE, CDialog)
//{{AFX_MSG_MAP(TEXTRUE)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_BN_CLICKED(IDC_BUTTON_BLUE, OnButtonBlue)
ON_BN_CLICKED(IDC_BUTTON_GREEN, OnButtonGreen)
ON_BN_CLICKED(IDC_BUTTON_RED, OnButtonRed)
ON_BN_CLICKED(IDC_BUTTON_YELLOW, OnButtonYellow)
ON_BN_CLICKED(IDC_BUTTON_TEXTURE_SAVE, OnButtonTextureSave)
ON_BN_CLICKED(ID_MOVE_TEXTURE, OnMoveTexture)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// TEXTRUE message handlers
void TEXTRUE::OnPaint()
{
CPaintDC dc(this); // device context for painting
this->DrawGrid(&dc);
this->FillGrid(&dc);
// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
}
void TEXTRUE::DrawGrid(CDC *dc)
{
int TEXTURESTEP = STEP*2;
this->SetTextureRect();
int i,centerx,centery;
CPen Pen;
Pen.CreatePen(PS_SOLID, 1, RGB(128, 128, 128));
dc->SelectObject(&Pen);
CWnd *Chart;
Chart = GetDlgItem(IDC_STATIC_TEXTURE_CHART);
Chart->GetWindowRect(&m_texture_chart);
ScreenToClient(&m_texture_chart);
centerx = (m_texture_chart.right-m_texture_chart.left)/2+m_texture_chart.left;
centery = (m_texture_chart.bottom-m_texture_chart.top)/2+m_texture_chart.top;
m_centerpoint.x = centerx;
m_centerpoint.y = centery;
for(i = GridRect.top;i<=GridRect.bottom;i++)
{
dc->MoveTo(GridRect.left*TEXTURESTEP+centerx,(i*(int)(TEXTURESTEP*this->m_coeff))+centery);
dc->LineTo(GridRect.right*TEXTURESTEP+centerx,(i*(int)(TEXTURESTEP*this->m_coeff))+centery);
}
for(i = GridRect.left;i<=GridRect.right;i++)
{
dc->MoveTo(i*TEXTURESTEP+centerx,(int)(GridRect.top*(int)(TEXTURESTEP*this->m_coeff))+centery);
dc->LineTo(i*TEXTURESTEP+centerx,(int)(GridRect.bottom*(int)(TEXTURESTEP*this->m_coeff))+centery);
}
//delete Chart;
}
void TEXTRUE::ChangeButtonColor(CDC *pDC)
{
// COLORREF m_ButtonColor;
//m_ButtonColor=RGB (0 , 0 , 255);
// pDC->SetBkColor (m_clrBack);
}
void TEXTRUE::OnLButtonDown(UINT nFlags, CPoint point)
{
int a =0;
int TEXTURESTEP = STEP*2;
// TODO: Add your message handler code here and/or call default
if((point.x<m_centerpoint.x+(GridRect.right*TEXTURESTEP))&&(point.x>m_centerpoint.x+GridRect.left*TEXTURESTEP)
&&(point.y<m_centerpoint.y+(int)(GridRect.bottom*TEXTURESTEP*m_coeff))&&(point.y>m_centerpoint.y+(int)(GridRect.top*TEXTURESTEP*m_coeff))&&((point.x-m_centerpoint.x)%TEXTURESTEP !=0)&&((int)((point.y-m_centerpoint.y)*m_coeff)%(int)(m_coeff*TEXTURESTEP) !=0))
{
long x = point.x;
long y = point.y;
CDC *pdc;
CBrush cbr;
cbr.CreateSolidBrush(m_texture_color);
pdc =GetDC();
pdc->SelectObject(cbr);
pdc->FloodFill(x,y,RGB(128,128,128));
//pdc->FillRect(CRect(j*STEP+OFFSET+1,(int)(i*STEP*m_jwm)+OFFSET+1,j*STEP+STEP+OFFSET,(int)((i+1)*STEP*m_jwm)+OFFSET),&cbr);
ReleaseDC(pdc) ;
cbr.DeleteObject();
int j =(x - m_centerpoint.x-GridRect.left*TEXTURESTEP)/TEXTURESTEP;
int w =(y - m_centerpoint.y-(int)(GridRect.top*TEXTURESTEP*m_coeff))/(int)(m_coeff*TEXTURESTEP);
int lable;
if(m_texture_color == RGB(255,0,0))
lable = 1;
else if(m_texture_color == RGB(0,255,0))
lable = 2;
else if(m_texture_color == RGB(0,0,255))
lable = 3;
else if(m_texture_color == RGB(255,255,0))
lable = 4;
else
lable = 5;
this->m_jwlabel[j][w] = lable;
}
CDialog::OnLButtonDown(nFlags, point);
}
BOOL TEXTRUE::OnInitDialog()
{
CDialog::OnInitDialog();
this->m_texture_color = RGB(255,0,0);
if(this->m_type == 0)
for(int i =0;i<MAXJW;i++)
for(int j =0;j<MAXJW;j++)
{
m_jwlabel[i][j] = 0;
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void TEXTRUE::SetTextureRect()
{
int currentj = this->m_jing_num;
int currentw = this->m_wei_num;
if(currentj%2 ==0)
{
this->GridRect.left = -currentj/2;
this->GridRect.right = currentj/2;
if(currentw %2 == 0)
{
this->GridRect.top = -currentw /2;
this->GridRect.bottom = currentw/2;
}
else
{
this->GridRect.top = -(currentw+1)/2;
this->GridRect.bottom = currentw/2;
}
}
else
{
this->GridRect.left = -(currentj+1)/2;
this->GridRect.right = currentj/2;
if(currentw %2 == 0)
{
this->GridRect.top = -currentw /2;
this->GridRect.bottom = currentw/2;
}
else
{
this->GridRect.top = -(currentw+1)/2;
this->GridRect.bottom = currentw/2;
}
}
}
void TEXTRUE::OnButtonBlue()
{
// TODO: Add your control notification handler code here
this->m_texture_color = RGB(0,0,255);
}
void TEXTRUE::OnButtonGreen()
{
// TODO: Add your control notification handler code here
this->m_texture_color = RGB(0,255,0);
}
void TEXTRUE::OnButtonRed()
{
// TODO: Add your control notification handler code here
this->m_texture_color = RGB(255,0,0);
}
void TEXTRUE::OnButtonYellow()
{
// TODO: Add your control notification handler code here
this->m_texture_color = RGB(255,255,0);
}
void TEXTRUE::OnButtonTextureSave()
{
// TODO: Add your control notification handler code here
CFileDialog dlg(FALSE,"zuz","*.zuz",NULL,"*.zuz",NULL);
if(dlg.DoModal() == IDOK)
{
FILE *fp;
//VERIFY(file.Open(dlg.GetPathName(),CFile::modeCreate));
//file.Write()
if(dlg.GetFileExt() == "zuz")
{
if((fp = fopen(dlg.GetPathName(),"w+"))!=0)
{
fprintf(fp,"%d ",this->m_jing_num);
fprintf(fp,"%d ",this->m_wei_num);
fprintf(fp,"%f ",this->m_coeff);
fprintf(fp,"%f ",this->m_jm);
fprintf(fp,"%f ",this->m_wm);
for(int i =0;i<m_wei_num;i++)
for(int j =0;j<m_jing_num;j++)
{
fprintf(fp,"%d ",m_jwlabel[j][i]);
}
}
fclose(fp);
}
}
}
void TEXTRUE::FillGrid(CDC *dc)
{
int j = this->m_jing_num;
int w = this->m_wei_num;
int TEXTURESTEP = STEP*2;
long x ,y;
CBrush cbr;
int change[2];
change[0] = change[1] = -1;
for(int i=0;i<w;i++)
for(int ii=0;ii<j;ii++)
{
x = (this->GridRect.left+ii)*TEXTURESTEP+this->m_centerpoint.x;
y = (int)((this->GridRect.top+i)*(int)(TEXTURESTEP*this->m_coeff)+this->m_centerpoint.y);
if(this->m_jwlabel[i][ii] == 1)
{
m_texture_color = RGB(255,0,0);
if(change[0] != 1)
{
change[0] =1;
change[1] = 1;
}
}
else if(m_jwlabel[i][ii] == 2)
{
m_texture_color = RGB(0,255,0);
if(change[0] != 2)
{
change[0] =2;
change[1] = 1;
}
}
else if(m_jwlabel[i][ii] == 3)
{
m_texture_color = RGB(0,0,255);
if(change[0] != 3)
{
change[0] =3;
change[1] = 1;
}
}
else if(m_jwlabel[i][ii] ==4)
{
m_texture_color = RGB(255,255,0);
if(change[0] != 4)
{
change[0] =4;
change[1] = 1;
}
}
else{
m_texture_color = RGB(255,255,255);
if(change[0] != 0)
{
change[0] =0;
change[1] = 1;
}
}
cbr.CreateSolidBrush(m_texture_color);
if(change[1] ==1)
{
dc->FillRect(CRect(x+1,y+1,x+TEXTURESTEP,y+TEXTURESTEP*this->m_coeff),&cbr);
}
else
dc->FillRect(CRect(x+1,y+1,x+TEXTURESTEP,y+TEXTURESTEP*this->m_coeff),&cbr);
cbr.DeleteObject();
change[1] = 0;
}
}
void TEXTRUE::OnMoveTexture()
{
CMainFrame * pFrame = static_cast <CMainFrame *>(AfxGetMainWnd());
CDesignerView *m_pMainView = pFrame->GetMainView();
m_pMainView->m_Fill_Picture = true;
for(int i =0;i<MAXJW;i++)
for(int j=0;j<MAXJW;j++)
{
m_pMainView->m_jwlabel[i][j] = this->m_jwlabel[j][i];
}
m_pMainView->m_width = this->m_jing_num;
m_pMainView->m_height = this->m_wei_num;
m_pMainView->m_DrawMode = OTHER;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -