shape.cpp

来自「The application wizard has created this 」· C++ 代码 · 共 196 行

CPP
196
字号
/************************************************************************************************
// $Header: /home/cvsroot/SoccerDoctor/Chart/Shape.cpp,v 1.4 2002/09/10 06:44:35 peter Exp $
//***********************************************************************************************
/************************************************************************************************/
/*                                                                                              */
/* File    : Shape.cpp                                                                          */
/*                                                                                              */
/* Purpose : interface for the shape that appears next to the legend text                       */
/*                                                                                              */
/* Author  : Scott Pelger                                             Date Created: 10JUN02     */
/*                                                                                              */
/* Revisions                                                                                    */
/*                                                                                              */
/* Engineer              Date        Description                                                */
/*                                                                                              */
/* Scott Pelger          10JUN02     initial version                                            */
/*                                                                                              */
/************************************************************************************************/
// Shape.cpp : implementation file
//

#include "stdafx.h"
#include "Shape.h"


/////////////////////////////////////////////////////////////////////////////
// CShape

BEGIN_MESSAGE_MAP(CShape, CWnd)
	//{{AFX_MSG_MAP(CShape)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShape message handlers

void CShape::OnPaint() {
	
	CRect Rect;
    GetClientRect(&Rect);

    int nOffset = (Rect.Width()-ITEM_WIDTH)/2;
    
    CPaintDC dc(this);

    CPen Pen;
    switch (m_byLineStyle) {
        case SHP_NONE :
            break;
        case SHP_SOLID :
            Pen.CreatePen(PS_SOLID, 1, m_crBorderColor);
            break;
        case SHP_DASH :
            Pen.CreatePen(PS_DASH, 1, m_crBorderColor);
            break;
        case SHP_DOT :
            Pen.CreatePen(PS_DOT, 1, m_crBorderColor);
            break;
        case SHP_DASHDOT :
            Pen.CreatePen(PS_DASHDOT, 1, m_crBorderColor);
            break;
        case SHP_DASHDOTDOT :
            Pen.CreatePen(PS_DASHDOTDOT, 1, m_crBorderColor);
            break;
        default :
            ASSERT(FALSE);
    }

	if (m_byLineStyle != SHP_NONE) {
		CPen* pPen = dc.SelectObject(&Pen);
		COLORREF crBackColor = dc.SetBkColor(m_crBackgroundColor);
		dc.MoveTo(0, Rect.Height()/2);
		dc.LineTo(Rect.Width()-1, Rect.Height()/2);
		dc.SetBkColor(crBackColor);
		dc.SelectObject(pPen);
		Pen.DeleteObject();
    }

    CBrush Brush(m_crItemColor);
    Pen.CreatePen(PS_SOLID, 1, m_crBorderColor);
    CBrush* pBrush = dc.SelectObject(&Brush);
    CPen* pPen = dc.SelectObject(&Pen);
    
    switch (m_byItemStyle) {
        case SHP_NONE :
            break;
        case SHP_SQUARE : {
            POINT Points[4];
            
            Points[0].x = nOffset;
            Points[0].y = 0;
            
            Points[1].x = nOffset;
            Points[1].y = ITEM_HEIGHT-1;
            
            Points[2].x = nOffset+ITEM_WIDTH-1;
            Points[2].y = ITEM_HEIGHT-1;
            
            Points[3].x = nOffset+ITEM_WIDTH-1;
            Points[3].y = 0;
            
            dc.Polygon(Points, 4);
            
            break;
            }
        case SHP_CIRCLE :
            dc.Ellipse(nOffset, 0, nOffset+ITEM_WIDTH, ITEM_HEIGHT);
            break;
        case SHP_TRIANGLE : {
            POINT Points[3];
            
            Points[0].x = nOffset+ITEM_WIDTH/2-1;
            Points[0].y = 0;
            
            Points[1].x = nOffset;
            Points[1].y = ITEM_HEIGHT-1;
            
            Points[2].x = nOffset+ITEM_WIDTH-2;
            Points[2].y = ITEM_HEIGHT-1;
            
            dc.Polygon(Points, 3);
            
            break;
            }
        case SHP_DIAMOND : {
            POINT Points[4];
            
            Points[0].x = nOffset+ITEM_WIDTH/2-1;
            Points[0].y = 1;
            
            Points[1].x = nOffset;
            Points[1].y = ITEM_HEIGHT/2;
            
            Points[2].x = nOffset+ITEM_WIDTH/2-1;
            Points[2].y = ITEM_HEIGHT-1;
            
            Points[3].x = nOffset+ITEM_WIDTH-2;
            Points[3].y = ITEM_HEIGHT/2;
            
            dc.Polygon(Points, 4);
            
            break;
            }
        case SHP_CROSS : {
            POINT Points[12];
            
            Points[0].x = nOffset+(ITEM_WIDTH-1)/3;
            Points[0].y = 0;
            
            Points[1].x = nOffset+(ITEM_WIDTH-1)/3;
            Points[1].y = (ITEM_HEIGHT-1)/3;
            
            Points[2].x = nOffset;
            Points[2].y = (ITEM_HEIGHT-1)/3;
            
            Points[3].x = nOffset;
            Points[3].y = (ITEM_HEIGHT-1)*2/3;
            
            Points[4].x = nOffset+(ITEM_WIDTH-1)/3;
            Points[4].y = (ITEM_HEIGHT-1)*2/3;
            
            Points[5].x = nOffset+(ITEM_WIDTH-1)/3;
            Points[5].y = ITEM_HEIGHT-1;
            
            Points[6].x = nOffset+(ITEM_WIDTH-1)*2/3;
            Points[6].y = ITEM_HEIGHT-1;
            
            Points[7].x = nOffset+(ITEM_WIDTH-1)*2/3;
            Points[7].y = (ITEM_HEIGHT-1)*2/3;
            
            Points[8].x = nOffset+ITEM_WIDTH-1;
            Points[8].y = (ITEM_HEIGHT-1)*2/3;
            
            Points[9].x = nOffset+ITEM_WIDTH-1;
            Points[9].y = (ITEM_HEIGHT-1)/3;
            
            Points[10].x = nOffset+(ITEM_WIDTH-1)*2/3;
            Points[10].y = (ITEM_HEIGHT-1)/3;
            
            Points[11].x = nOffset+(ITEM_WIDTH-1)*2/3;
            Points[11].y = 0;
            
            dc.Polygon(Points, 12);
            
            break;
            }
        default:
            ASSERT(FALSE);
        }

    dc.SelectObject(pBrush);
    dc.SelectObject(pPen);
	Pen.DeleteObject();
	Brush.DeleteObject();
}

⌨️ 快捷键说明

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