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

📄 designerview.cpp

📁 《数字图象工程案例》原码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// DesignerView.cpp : implementation of the CDesignerView class
//

#include "stdafx.h"
#include "Designer.h"
#include "DesignerDoc.h"
#include "DesignerView.h"
#include "TEXTUREJW.h"
#include "DrawPicture.h"
#include "DIBAPI.h"
#include "DIB.h"
#include "REDUCECOLOR.h"
#include "DeleteScatter.h"
#include "math.h"

#include "WANGGCZ.h"

#include "PENWUQI.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern class DIB cDib;
extern HDIB hDIB;
extern COLORREF global_ccomm;
extern COLORREF global_cfg;
extern int global_STEP;
extern HCURSOR ghCursor;
extern CPoint ScrollPosforRYTX;


//extern float fcoeff;
/////////////////////////////////////////////////////////////////////////////
// CDesignerView

IMPLEMENT_DYNCREATE(CDesignerView, CScrollView)

BEGIN_MESSAGE_MAP(CDesignerView, CScrollView)
	//{{AFX_MSG_MAP(CDesignerView)

	ON_WM_LBUTTONDOWN()
	ON_WM_VSCROLL()
	ON_WM_MOUSEMOVE()
	ON_WM_RBUTTONDOWN()
	
	ON_WM_LBUTTONUP()

	ON_COMMAND(ID_MENU_GY_QUZADIAN, OnMenuGyQuzadian)
	ON_COMMAND(ID_MENU_PIC_REDUCECOLOR, OnMenuPicReducecolor)
	ON_WM_SETCURSOR()
	ON_COMMAND(ID_EDIT_CUT, OnEditCut)
	ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
	ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
	ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
	ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut)
	ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
	ON_UPDATE_COMMAND_UI(ID_EDIT_REDUCE_COLOR, OnUpdateEditReduceColor)
	ON_UPDATE_COMMAND_UI(ID_MENU_GY_QUZADIAN, OnUpdateMenuGyQuzadian)
	ON_UPDATE_COMMAND_UI(ID_MENU_PIC_REDUCECOLOR, OnUpdateMenuPicReducecolor)
	ON_COMMAND(ID_CIRCLE, OnCircle)
	ON_COMMAND(ID_JIANGLIWANGGE, OnJiangliwangge)
	ON_COMMAND(ID_PEN, OnPen)
	ON_COMMAND(ID_XIQU, OnXiqu)
	ON_COMMAND(ID_ZUZHI, OnZuzhi)
	ON_COMMAND(ID_OPEN_ZUZHI, OnOpenZuzhi)
	ON_COMMAND(ID_YOUQITONG, OnYouqitong)
	ON_COMMAND(ID_PENWUQI, OnPenwuqi)
	ON_COMMAND(ID_RECT, OnRect)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDesignerView construction/destruction

CDesignerView::CDesignerView()
{	
	
	
	
	
	m_CBWhite.CreateSolidBrush(WHITE);
	m_CBRed.CreateSolidBrush(RED);
	m_CBGreen.CreateSolidBrush(GREEN);
	m_CBYellow.CreateSolidBrush(YELLOW);
	m_CBBlue.CreateSolidBrush(BLUE);
	m_CBrushWG.CreateSolidBrush(WGCOLOR);
	m_RectsInfo.RectLen = 0;
	
	m_Circle_Scr.IsValide = false;

	m_RectsInfo.IsValide = false;

	m_Step_Line = STEP;
	m_ReduceColor = false;
	m_Is_WHDivide =0;
	m_LineNum.x =0;
	m_LineNum.y = 0;
	m_Step_Line = 0;

	m_Fill_Picture = false;
	
	m_jwm = 0.0;
	m_texture_type = 1;
	m_DrawMode = MANUAL;
	m_Fill_Picture = false;
	m_Base_Create = false;

	for(int i = 0;i<LINENUM;i++)
		for(int j =0;j<LINENUM;j++)
			m_IsBoxFilled[i][j] = FALSE;
	for( i = 0;i<LINENUM;i++)
		for(int j =0;j<LINENUM;j++)
			m_picture_edge[i][j] = FALSE;
		
		for(i = 0;i<LINENUM;i++)
			for(int j=0;j<LINENUM;j++)
				m_picture_color[i][j] = m_OTHER;
			m_jingnum = LINENUM;
			m_weinum  = LINENUM;
			m_jingmi = 0.0;
			m_weimi  = 0.0;
	m_UndoStruct.m_CurrentP =0;
		
	m_largesmallmode = false;
	m_bmp_width  = 0;
	m_bmp_height = 0;
    m_old_bmp_width = 0;
	m_old_bmp_height = 0;
	m_Pen_Color = RED;
	bmpfirstload = true;
	// TODO: add construction code here

}

CDesignerView::~CDesignerView()
{
	m_CBrushWG.DeleteObject();
	m_CBRed.DeleteObject();
	m_CBBlue.DeleteObject();
	m_CBGreen.DeleteObject();
	m_CBYellow.DeleteObject();
	m_CBWhite.DeleteObject();
}

BOOL CDesignerView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CDesignerView drawing

void CDesignerView::OnDraw(CDC* pDC)
{
	CDesignerDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	if(hDIB && m_ReduceColor == false)
	{
		LPBITMAPINFOHEADER lpbi;
		lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB);
		
		if (bmpfirstload)
		{
			m_bmp_width =   lpbi->biWidth ;
			m_bmp_height =  lpbi->biHeight ;
			bmpfirstload = false ;
			cDib.PaintDIBTrue(pDC->GetSafeHdc(),CRect(OFFSET,OFFSET,m_bmp_width+OFFSET,m_bmp_height+OFFSET),
	                   	 hDIB,CRect(0,0,m_bmp_width,m_bmp_height),SRCCOPY);
		}
		 else
		cDib.PaintDIBTrue(pDC->GetSafeHdc(),CRect(OFFSET,OFFSET,lpbi->biWidth+OFFSET,lpbi->biHeight+OFFSET),
	                   	 hDIB,CRect(0,0,lpbi->biWidth,lpbi->biHeight),SRCCOPY);
    
	}
	
	int  linewidth = 0;
	int  coloumwidth  = 0;

	if(m_jwm !=0){

		COLORREF cfg,ccomm;
	    cfg = m_basetexture.GetFGLineCol();
	    ccomm = m_basetexture.GetCommLineCol();

		if(m_LineNum.x ==0)
		{
			m_LineNum.x = m_LineNum.y = (long)(LINENUM/2.5);
			m_Step_Line = STEP;
			m_Is_WHDivide = true;
		}
		if(this->m_Base_Create)
		{
		
			 Drawnewbase(pDC,m_texture_type,cfg,ccomm,m_jwm,m_LineNum.x,m_LineNum.y,m_Step_Line);
			 linewidth =  m_LineNum.x*m_Step_Line+50;
			 coloumwidth = (int (m_LineNum.y*m_Step_Line*m_jwm) )+50; 
			 SetScrollSizes(MM_TEXT,CSize(linewidth,coloumwidth));
			 ShowPict(pDC,m_Step_Line);
			 ShowPictEdge(pDC,m_Step_Line);
		}
		
	}

}

void CDesignerView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();

	CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx = 500;
    sizeTotal.cy = 500;
	CSize sizemin;
	SetScrollSizes(MM_TEXT, sizeTotal);
}

/////////////////////////////////////////////////////////////////////////////
// CDesignerView printing

BOOL CDesignerView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CDesignerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CDesignerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CDesignerView diagnostics

#ifdef _DEBUG
void CDesignerView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CDesignerView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CDesignerDoc* CDesignerView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDesignerDoc)));
	return (CDesignerDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDesignerView message handlers

void CDesignerView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	COLORREF m_color;
	CPoint tempp;
	tempp = this->GetScrollPosition();
	CDC *dc = this->GetDC();
	if(m_DrawMode ==PASTE && ghCursor)
	{
		this->m_Paste_Current.CurrentMouse = gLocatePoint(point,m_jwm,tempp);
		ReleaseDC(dc);
		goto L;
	}
	
	if(m_DrawMode == CIRCLEMOVE && ghCursor)
	{
		this->m_Circle_Scr.CurrentMouse = point;
		ReleaseDC(dc);
		goto L;
	}
	if(m_DrawMode == PENGWUQI)
	{
		CPoint tp;
		tp = gLocatePoint(point,m_jwm,tempp);
		int PointLocation[200][2];
		srand((unsigned)time(NULL));
		for(int i=0;i<this->m_PenWuQi_Num;i++)
		{	
			int x = rand();
			while(x>=this->m_PenWuQi_Radius*2+1)
				x %=m_PenWuQi_Radius*2+1;
			
			PointLocation[i][0] = x;
			x = rand();
				while(x>=this->m_PenWuQi_Radius*2+1)
				x %=m_PenWuQi_Radius*2+1;
			PointLocation[i][1] = x;
				
		}
		CBrush cbr;
		cbr.CreateSolidBrush(this->m_Pen_Color);
		for(i =0;i<this->m_PenWuQi_Num;i++)
		{
			int x =PointLocation[i][0] - this->m_PenWuQi_Radius;
				x +=tp.x;
				if(x<0)
					x =0;
				if(x>=this->m_LineNum.x-1)
					x = this->m_LineNum.x-1;
			int y = PointLocation[i][1] - this->m_PenWuQi_Radius;
			    y += tp.y;
				if(y<0)
					y=0;
				if(y>=this->m_LineNum.y-1)
					y = this->m_LineNum.y-1;
			dc->FillRect(CRect(x*m_Step_Line+OFFSET+1-tempp.x,y*(int)(m_Step_Line*m_jwm)+OFFSET+1-tempp.y,
							  (x+1)*m_Step_Line+OFFSET-tempp.x,(y+1)*(int)(m_Step_Line*m_jwm)+OFFSET-tempp.y),
							  &cbr);
			if(m_Pen_Color == RED)
				this->m_picture_color[y][x] = m_RED;
			else if(m_Pen_Color==GREEN)
				this->m_picture_color[y][x] = m_GREEN;
			else if(m_Pen_Color==BLUE)
				this->m_picture_color[y][x] = m_BLUE;
			else if(m_Pen_Color==YELLOW)
				this->m_picture_color[y][x] = m_YELLOW;
			else if(m_Pen_Color==WHITE)
				this->m_picture_color[y][x] = m_WHITE;

		}
		cbr.DeleteObject();
		ReleaseDC(dc);
		goto L;
	}
	if(m_DrawMode == YOUQITONG)
	{
		CPoint curpoint = gLocatePoint(point,m_jwm,tempp);
		curpoint.y +=4;
		curpoint.x +=3;
		if(curpoint.x <m_LineNum.x && curpoint.x >=0 && curpoint.y >=0 && curpoint.y <= m_LineNum.y)
			this->YouQiTong(dc,curpoint,tempp,this->m_picture_color[curpoint.y][curpoint.x],this->m_Pen_Color);
	}
	
	if(m_DrawMode == RECTMOVE && ghCursor)
	{
			m_Current_Mouse.x = point.x;
			m_Current_Mouse.y = point.y;
			ReleaseDC(dc);
			goto L;
		
	}
	if(m_DrawMode == RECTDRAW)
	{	
		CPoint judge;
		judge = gLocatePoint(point,m_jwm,tempp);
		if(judge.x <0 || judge.x > m_LineNum.x-1 
			|| judge.y <0 || judge.y > m_LineNum.y-1)
		{
			ReleaseDC(dc);
			goto L;
		}
		this->m_RectsInfo.IsValide = true;
		this->m_RectsInfo.RectLen = 0;
		this->RectLeftTop.x = (gLocatePoint(point,m_jwm,tempp).x)*m_Step_Line+OFFSET+1+tempp.x;
		this->RectLeftTop.y = (gLocatePoint(point,m_jwm,tempp).y)*(int)(m_Step_Line*m_jwm)+OFFSET+1+tempp.y;
		this->m_RectsInfo.LeftTop = RectLeftTop;
	
		ReleaseDC(dc);
		goto L;
	
	}



	
		//吸取颜色
	if(m_DrawMode == XIQU)
	{
			
			CPoint tpp;
			tpp.x = point.x + m_Step_Line*3;
			tpp.y = point.y + m_Step_Line*4;
			m_Pen_Color= GetPixel(dc->GetSafeHdc(),tpp.x,tpp.y);
			 if(m_Pen_Color == WGCOLOR || m_Pen_Color == global_ccomm || m_Pen_Color == global_cfg )
				m_Pen_Color= GetPixel(dc->GetSafeHdc(),tpp.x+1,tpp.y+1);
			 ReleaseDC(dc);
			 goto L;
	}

	//铅笔画图
	if(m_DrawMode == PEN)
	{
		CPoint tp;
		tp = LocatePoint(point);
		if(tp.x< 0 || tp.x >=m_LineNum.x || tp.y<0 || tp.y >=m_LineNum.y)
			goto L;
		tp.x +=2;
		tp.y +=3;
		if(tp.x >=m_LineNum.x || tp.y >=m_LineNum.y)
			goto L;
	
		CBrush m_brush;
		m_brush.CreateSolidBrush(m_Pen_Color);
		dc->FillRect(CRect(tp.x*m_Step_Line+OFFSET-tempp.x+1,tp.y*(int)(m_Step_Line*m_jwm)+OFFSET-tempp.y+1,tp.x*m_Step_Line+OFFSET-tempp.x+m_Step_Line,(tp.y+1)*(int)(m_Step_Line*m_jwm)+OFFSET-tempp.y),&m_brush);
		if(m_Pen_Color == EDGECOLOR)
			m_picture_edge[tp.x][tp.y] = TRUE;
		else
			m_picture_edge[tp.x][tp.y] = FALSE;
		if(m_Pen_Color == RED)
			m_picture_color[tp.y][tp.x] = m_RED;
		else if (m_Pen_Color == GREEN)
			m_picture_color[tp.y][tp.x] = m_GREEN;
		else if (m_Pen_Color == BLUE)
			m_picture_color[tp.y][tp.x] = m_BLUE;
		else if (m_Pen_Color == YELLOW)
			m_picture_color[tp.y][tp.x] = m_YELLOW;
		else if (m_Pen_Color == WHITE)
			m_picture_color[tp.y][tp.x] = m_WHITE;

			
		ReleaseDC(dc);
		m_brush.DeleteObject();
		goto L;
		
	}



	//园得中心点
	if(m_Circle_Scr.IsValide== false && m_DrawMode == CIRCLE && m_Fill_Picture == false)
	{
		m_Circle_Scr.IsValide = true;
		this->m_Circle_Scr.LeftTop = point;
		this->m_Circle_Scr.CurrentMouse = point;
		this->m_Circle_Scr.IsFinish = false;
		ReleaseDC(dc);
		for(int i=0;i<LINENUM;i++)
			for(int j=0;j<LINENUM;j++)
				this->m_picture_edge[i][j] = false;
		goto L;

	}
	//园得半径点
	if(m_Circle_Scr.IsValide == true && !this->m_Circle_Scr.IsFinish)
	{
		
		
		IsCutUsable = true;
		IsCopyUsable = true;

		m_Circle_Scr.IsFinish=true;
		DrawPicture dp;

⌨️ 快捷键说明

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