ChartCtrl源码剖析之——CChartAxisLabel类
CChartAxisLabel类用来绘制轴标签,上、下、左、右都可以根据实际需要设置对应的轴标签。它处于该控件的区域,如下图所示:
CChartAxisLabel类的头文件。
#if !defined(AFX_CHARTAXISLABEL_H__0E5519C8_A2F4_4CED_9681_32A56B25D0C5__INCLUDED_)
#define AFX_CHARTAXISLABEL_H__0E5519C8_A2F4_4CED_9681_32A56B25D0C5__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "ChartObject.h"
#include "ChartString.h"
class CChartAxis;
class CChartAxisLabel : public CChartObject
{
friend CChartAxis;
public:
void SetText(const TChartString& NewText);
TChartString GetText() const { return m_strLabelText; }
void SetFont(int nPointSize, const TChartString& strFaceName);
CChartAxisLabel(CChartCtrl* pParent, bool bHorizontal);
virtual ~CChartAxisLabel();
private:
void SetPosition(int LeftBorder, int TopBorder, CDC *pDC);
void Draw(CDC* pDC);
CSize GetSize(CDC* pDC) const;
bool m_bIsHorizontal; // Specifies if the axis is horizontal or not
int m_iFontSize;
TChartString m_strFontName;
TChartString m_strLabelText;
};
#endif // !defined(AFX_CHARTAXISLABEL_H__0E5519C8_A2F4_4CED_9681_32A56B25D0C5__INCLUDED_)
CChartAxisLabel类的源文件。
#include "stdafx.h"
#include "ChartAxisLabel.h"
#include "ChartCtrl.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CChartAxisLabel::CChartAxisLabel(CChartCtrl* pParent, bool bHorizontal):CChartObject(pParent)
{
m_bIsHorizontal = bHorizontal;
m_iFontSize = ;
m_strFontName = _T("Microsoft Sans Serif");
m_strLabelText = _T("");
}
CChartAxisLabel::~CChartAxisLabel()
{
}
void CChartAxisLabel::SetText(const TChartString& NewText)
{
m_strLabelText = NewText;
m_pParent->RefreshCtrl();
}
void CChartAxisLabel::SetFont(int nPointSize, const TChartString& strFaceName)
{
m_iFontSize = nPointSize;
m_strFontName = strFaceName;
m_pParent->RefreshCtrl();
}
CSize CChartAxisLabel::GetSize(CDC *pDC) const
{
CSize LabelSize;
LabelSize.cx = ;
LabelSize.cy = ;
if (!m_bIsVisible)
return LabelSize;
if (!pDC->GetSafeHdc())
return LabelSize;
if (m_strLabelText == _T(""))
return LabelSize;
CFont NewFont;
CFont* pOldFont;
NewFont.CreatePointFont(m_iFontSize,m_strFontName.c_str(),pDC);
pOldFont = pDC->SelectObject(&NewFont);
LabelSize = pDC->GetTextExtent(m_strLabelText.c_str());
LabelSize.cx += ;
LabelSize.cy += ;
if (!m_bIsHorizontal)
{
int Width = LabelSize.cy;
int Height = LabelSize.cx;
LabelSize.cx = Width;
LabelSize.cy = Height;
}
pDC->SelectObject(pOldFont);
DeleteObject(NewFont);
return LabelSize;
}
void CChartAxisLabel::Draw(CDC *pDC)
{
if (!m_bIsVisible)
return;
if (!pDC->GetSafeHdc())
return;
if (m_strLabelText == _T(""))
return;
int iPrevMode = pDC->SetBkMode(TRANSPARENT);
COLORREF OldColor = pDC->SetTextColor(m_ObjectColor);
CFont NewFont;
NewFont.CreatePointFont(m_iFontSize,m_strFontName.c_str(),pDC);
CFont* pOldFont;
if (!m_bIsHorizontal)
{
LOGFONT LogFont;
NewFont.GetLogFont(&LogFont);
LogFont.lfOrientation = ;
LogFont.lfEscapement = ;
CFont VertFont;
VertFont.CreateFontIndirect(&LogFont);
pOldFont = pDC->SelectObject(&VertFont);
pDC->ExtTextOut(m_ObjectRect.left + ,m_ObjectRect.top,
ETO_CLIPPED,NULL,m_strLabelText.c_str(),NULL);
pDC->SelectObject(pOldFont);
DeleteObject(VertFont);
DeleteObject(NewFont);
}
else
{
pOldFont = pDC->SelectObject(&NewFont);
pDC->ExtTextOut(m_ObjectRect.left,m_ObjectRect.top + ,
ETO_CLIPPED,NULL,m_strLabelText.c_str(),NULL);
pDC->SelectObject(pOldFont);
DeleteObject(NewFont);
}
pDC->SetBkMode(iPrevMode);
pDC->SetTextColor(OldColor);
}
void CChartAxisLabel::SetPosition(int LeftBorder, int TopBorder, CDC *pDC)
{
CSize NewSize = GetSize(pDC);
CRect NewRect;
NewRect.top = TopBorder;
NewRect.bottom = TopBorder + NewSize.cy;
NewRect.left = LeftBorder;
NewRect.right = LeftBorder + NewSize.cx;
CChartObject::SetRect(NewRect);
}
CChartAxisLabel类在CChartAxis类中设定最终绘制的位置。
ChartCtrl源码剖析之——CChartAxisLabel类的更多相关文章
- ChartCtrl源码剖析之——CChartObject类
首先,做一些简单的铺垫,目前针对ChartCtrl源码的剖析只针对V.15版本.名义上说是剖析,倒不如说是记录下自己针对该控件的理解,非常感谢Cedric Moonen大神,一切的功劳与掌声都该赠予给 ...
- ChartCtrl源码剖析之——CChartAxis类
CChartAxis类用来绘制波形控件的坐标轴,这个源码相对较复杂,当初阅读的时候耗费了不少精力来理解源码中的一些实现细节. CChartAxis类的头文件. #if !defined(AFX_CHA ...
- ChartCtrl源码剖析之——CChartScrollBar类
CChartScrollBar类用来针对每个轴的数据进行滚动,将那些不在当前区域内的数据通过滚动展示出来. CChartScrollBar类的头文件. #pragma once class CChar ...
- ChartCtrl源码剖析之——CChartTitle类
CChartTitle类顾名思义,该类用来绘制波形控件的标题,它处于该控件的区域,如下图所示: CChartTitle类的头文件. #if !defined(AFX_CHARTTITLE_H__499 ...
- ChartCtrl源码剖析之——CChartLegend类
CChartLegend类用来绘制每一个波形的描述信息,它处于该控件的区域,如下图所示: CChartLegend类的头文件. #if !defined(AFX_CHARTLEGEND_H__CD72 ...
- ChartCtrl源码剖析之——CChartGrid类
CChartGrid类用来绘制波形区域中的表格,当绘制波形时波形就显示在这些表格上面.它处于该控件的区域,如下图所示: CChartGrid类的头文件. #if !defined(AFX_CHARTG ...
- PART(Persistent Adaptive Radix Tree)的Java实现源码剖析
论文地址 Adaptive Radix Tree: https://db.in.tum.de/~leis/papers/ART.pdf Persistent Adaptive Radix Tree: ...
- 老李推荐:第6章3节《MonkeyRunner源码剖析》Monkey原理分析-事件源-事件源概览-命令翻译类
老李推荐:第6章3节<MonkeyRunner源码剖析>Monkey原理分析-事件源-事件源概览-命令翻译类 每个来自网络的字串命令都需要进行解析执行,只是有些是在解析的过程中直接执行 ...
- WorldWind源码剖析系列:影像存储类ImageStore、Nlt影像存储类NltImageStore和WMS影像存储类WmsImageStore
影像存储类ImageStore 影像存储类ImageStore提供了计算本地影像路径和远程影像影像URL访问的各种接口,是WmsImageStore类和NltImageStore类的基类.当划分完层次 ...
随机推荐
- 【贪心+二分】codeforces D. Magazine Ad
codeforces.com/contest/803/problem/D [题意] 给定一个字符串,字符串里可能有空格和连字符‘-’,空格和连字符的意义是一样的,都表示:能在那个位置把字符串分成两部分 ...
- [NOIP1999] 提高组 洛谷P1016 旅行家的预算
题目描述 一个旅行家想驾驶汽车以最少的费用从一个城市到另一个城市(假设出发时油箱是空的).给定两个城市之间的距离D1.汽车油箱的容量C(以升为单位).每升汽油能行驶的距离D2.出发点每升汽油价格P和沿 ...
- Codevs 队列练习 合并版
3185 队列练习 1 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 给定一个队列(初始为空),只有两种操作入队和出队,现给出这 ...
- [Usaco2006 Nov] Fence Repair 切割木板
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1356 Solved: 714[Submit][Status][Discuss] Description ...
- sgu179 SGU起航!
//发现dfs除了搜索功能外的其他功能,他本身是一种序列,这个题恰是"先序"的下一个(合法范围内)序列! #include<iostream> #include< ...
- Bootstrap3 为何无法显示Glyphicons 图标
Bootstrap3 为何无法显示Glyphicons 图标 在CSS引入字体即可解决 @font-face { font-family: 'Glyphicons Halflings'; src: u ...
- T1365 浴火银河星际跳跃 codevs
http://codevs.cn/problem/1365/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 小 K 又在玩浴 ...
- TDBXJSONStream(BERLIN新增)的使用
DELPHI 10.1 BERLIN新增TDBXJSONStream类,用于方便地将数据序列为JSON,和将JSON还原出来数据. DATASNAP远程方法也相应地增加了支持返回TDBXJSONStr ...
- 【Todo】Java线程面试题 Top 50 (转载)
原文链接:http://www.importnew.com/12773.html 这里有一个排版好看一点的:http://www.cnblogs.com/dolphin0520/p/3958019.h ...
- ICONFONT在APP中的使用
阿里IconFont平台 http://www.iconfont.cn/ 这里是阿里巴巴UED部门开发的IconFont平台,眼下阿里系的重量级产品都在使用,里面有非常多资源可供使用. 这里说说怎样在 ...