www.pudn.com > CTableDemo.rar > Shape.cpp


/************************************************************************************************ 
// $Header:$ 
//*********************************************************************************************** 
/************************************************************************************************/ 
/*                                                                                              */ 
/* 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" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// 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); 
        } 
 
    CPen* pPen = dc.SelectObject(&Pen); 
    COLORREF crBackColor = dc.SetBkColor(m_crBackgroundColor); 
     
    if (m_byLineStyle!=SHP_NONE) { 
         
        dc.MoveTo(0, Rect.Height()/2); 
        dc.LineTo(Rect.Width()-1, Rect.Height()/2); 
        dc.SetBkColor(crBackColor); 
        } 
     
    Pen.DeleteObject(); 
 
    CBrush Brush(m_crItemColor); 
    Pen.CreatePen(PS_SOLID, 1, m_crBorderColor); 
    CBrush* pBrush = dc.SelectObject(&Brush); 
    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); 
 
    return; 
    } 
 
 
//*********************************************************************************************** 
// END OF FILE 
// $Log:$ 
//***********************************************************************************************