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

📄 legendtext.cpp

📁 The application wizard has created this SoccerDoctor application for you. This application not onl
💻 CPP
字号:
/************************************************************************************************
// $Header: /home/cvsroot/SoccerDoctor/Chart/LegendText.cpp,v 1.3 2002/09/10 06:44:35 peter Exp $
//***********************************************************************************************
/************************************************************************************************/
/*                                                                                              */
/* File    : LegendText.cpp                                                                     */
/*                                                                                              */
/* Purpose : interface for the legend text                                                      */
/*                                                                                              */
/* Author  : Scott Pelger                                             Date Created: 10JUN02     */
/*                                                                                              */
/* Revisions                                                                                    */
/*                                                                                              */
/* Engineer              Date        Description                                                */
/*                                                                                              */
/* Scott Pelger          10JUN02     initial version                                            */
/*                                                                                              */
/************************************************************************************************/
// LegendText.cpp : implementation file
//

#include "stdafx.h"
#include "LegendText.h"

/////////////////////////////////////////////////////////////////////////////
// CLegendText

CLegendText::CLegendText() :
    m_rcClientRect(0, 0, 0, 0),
    m_pFont(NULL),
    m_byTextStyle(LT_NORMAL),
    m_byItemStyle(SHP_SQUARE),
    m_byLineStyle(SHP_NONE),
    m_bCreate(FALSE) {
        
    m_wndShape.SetItemColor(RGB(255, 0, 0));
	m_wndShape.SetBorderColor(RGB(255, 255, 0));
	m_wndShape.SetLineColor(RGB(255, 255, 0));
    m_wndShape.SetItemStyle(SHP_SQUARE);
    m_wndShape.SetLineStyle(SHP_NONE);
    
    return;
    }

CLegendText::~CLegendText() {
    
	if (m_pFont){
        m_pFont->DeleteObject();
		delete m_pFont;
	}

    return;
    }

BEGIN_MESSAGE_MAP(CLegendText, CStatic)
	//{{AFX_MSG_MAP(CLegendText)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLegendText message handlers

BOOL CLegendText::SetFont(BYTE byPointSize, char *psFontName, BYTE byStyle) {
    
	if (m_pFont){
        m_pFont->DeleteObject();
	}
    if (!m_pFont) {
        m_pFont = new CFont;
        if (!m_pFont)
            return TRUE;
        }
    
    LOGFONT lf;
    
    memset(&lf, 0, sizeof(LOGFONT));
        
    strcpy(lf.lfFaceName, psFontName);

    byPointSize = byPointSize<10?10:byPointSize;

    lf.lfHeight     = byPointSize*10;
    lf.lfWeight     = byStyle&LT_BOLD?FW_BOLD:FW_NORMAL;
    lf.lfItalic     = byStyle&LT_ITALIC;
    lf.lfUnderline  = byStyle&LT_UNDERLINE;
  
    CClientDC dc(this);

    m_pFont->CreatePointFontIndirect(&lf, &dc);

    return FALSE;
    }

COLORREF CLegendText::SetItemColor(COLORREF crColor) {

    COLORREF crTempColor = m_crItemColor;
    m_crItemColor = crColor;

    m_wndShape.SetItemColor(crColor);
    
    return crTempColor;
    }

COLORREF CLegendText::SetBorderColor(COLORREF crColor) {

    COLORREF crTempColor = m_crBorderColor;
    m_crBorderColor = crColor;

    m_wndShape.SetBorderColor(crColor);
    
    return crTempColor;
    }

COLORREF CLegendText::SetLineColor(COLORREF crColor) {

    COLORREF crTempColor = m_crLineColor;
    m_crLineColor = crColor;

    m_wndShape.SetLineColor(crColor);
    
    return crTempColor;
    }

COLORREF CLegendText::SetTextColor(COLORREF crColor) {

    COLORREF crTempColor = m_crTextColor;
    m_crTextColor = crColor;

    m_wndShape.SetBorderColor(crColor);

    return crTempColor;
    }

COLORREF CLegendText::SetBackgroundColor(COLORREF crColor) {

    COLORREF crTempColor = m_crBackgroundColor;
    m_crBackgroundColor = crColor;
    
    m_wndShape.SetBackgroundColor(crColor);
    
    return crTempColor;
    }

void CLegendText::OnPaint() {

    CPaintDC    dc(this);
	CString     String;
    
    COLORREF crTextColor = dc.SetTextColor(m_crTextColor);
    COLORREF crBackColor = dc.SetBkColor(m_crBackgroundColor);
    CFont* pFont = dc.SelectObject(m_pFont);

    GetWindowText(String);

    dc.DrawText(String, -1, &m_rcClientRect, DT_CALCRECT);
    dc.FillSolidRect(&m_rcClientRect, m_crBackgroundColor);

    SetWindowPos(NULL, 0, 0, m_rcClientRect.Width()+ITEM_WIDTH*2+ITEM_SPACING, m_rcClientRect.Height(), SWP_NOZORDER|SWP_NOMOVE);
    
    //need set the position of the shape window
    m_wndShape.SetWindowPos(NULL, 0, (m_rcClientRect.Height()-ITEM_HEIGHT)/2, ITEM_WIDTH*2, ITEM_HEIGHT, SWP_NOZORDER);
    
    m_rcClientRect.OffsetRect(ITEM_WIDTH*2+ITEM_SPACING, 0);
    
    dc.DrawText(String, -1, &m_rcClientRect, DT_LEFT|DT_VCENTER);

    m_rcClientRect.left -= ITEM_WIDTH*2+ITEM_SPACING;
    
    dc.SetTextColor(crTextColor);
    dc.SetBkColor(crBackColor);
    dc.SelectObject(pFont);
}

void CLegendText::PreSubclassWindow() {
	
    if (!m_bCreate)
        m_wndShape.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, 1010);
    CStatic::PreSubclassWindow();

    _CalculateClientRect();
    
    return;
    }

BOOL CLegendText::Create(LPCTSTR lpszText, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID) {

    m_bCreate = TRUE;
    
    BOOL bReturn(CStatic::Create(lpszText, dwStyle, rect, pParentWnd, nID));

    if (bReturn)
        m_wndShape.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, 1010);    

    _CalculateClientRect();
    
    return bReturn;
    }

void CLegendText::_CalculateClientRect() {

    CClientDC   dc(this);
	CString     String;
    
    CFont* pFont = dc.SelectObject(m_pFont);

    GetWindowText(String);

    dc.DrawText(String, -1, &m_rcClientRect, DT_CALCRECT);
    
    m_rcClientRect.OffsetRect(ITEM_WIDTH*2+ITEM_SPACING, 0);
    m_rcClientRect.left -= ITEM_WIDTH*2+ITEM_SPACING;
    
    dc.SelectObject(pFont);

    return;
    }

//***********************************************************************************************
// END OF FILE
// $Log: LegendText.cpp,v $
// Revision 1.3  2002/09/10 06:44:35  peter
// 没有GDI资源泄漏了
//
// Revision 1.2  2002/09/08 03:42:36  peter
// 可以在98下面用了,chart 当所有值都是0的时候有问题
//
// Revision 1.1  2002/09/07 06:03:54  peter
// 新的chart类,从别的地方拷来的
//
//***********************************************************************************************

⌨️ 快捷键说明

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