ChartCtrl源码剖析之——CChartScrollBar类
CChartScrollBar类用来针对每个轴的数据进行滚动,将那些不在当前区域内的数据通过滚动展示出来。

CChartScrollBar类的头文件。
#pragma once
class CChartAxis;
class CChartScrollBar : public CScrollBar
{
public:
CChartScrollBar(CChartAxis* pParentAxis);
~CChartScrollBar();
void CreateScrollBar(const CRect& PlottingRect);
void OnHScroll(UINT nSBCode, UINT nPos);
void OnVScroll(UINT nSBCode, UINT nPos);
void Refresh();
void SetEnabled(bool bEnabled) { m_bEnabled = bEnabled; }
bool GetEnabled() const { return m_bEnabled; }
void SetAutoHide(bool bAutoHide) { m_bAutoHide = bAutoHide; }
bool GetAutoHide() const { return m_bAutoHide; }
void OnMouseEnter();
void OnMouseLeave();
private:
bool IsScrollInverted() const;
void MoveAxisToPos(int PreviousPos, int CurPos);
CChartAxis* m_pParentAxis;
bool m_bEnabled;
bool m_bAutoHide;
};
CChartScrollBar类的源文件。
#include "stdafx.h"
#include "ChartScrollBar.h"
#include "ChartAxis.h"
#include "ChartCtrl.h"
#include "math.h"
CChartScrollBar::CChartScrollBar(CChartAxis* pParentAxis)
: CScrollBar(), m_pParentAxis(pParentAxis), m_bEnabled(false),
m_bAutoHide(true)
{
}
CChartScrollBar::~CChartScrollBar()
{
}
void CChartScrollBar::CreateScrollBar(const CRect& PlottingRect)
{
CRect Temp = PlottingRect;
Temp.top++; Temp.left++;
DWORD dwStyle = SBS_HORZ | WS_CHILD;
if (m_pParentAxis->IsHorizontal())
{
if (m_pParentAxis->m_bIsSecondary)
dwStyle |= SBS_TOPALIGN;
else
dwStyle += SBS_BOTTOMALIGN;
}
else
{
if (m_pParentAxis->m_bIsSecondary)
dwStyle |= SBS_VERT | SBS_RIGHTALIGN;
else
dwStyle += SBS_VERT | SBS_LEFTALIGN;
}
CScrollBar::Create(dwStyle, Temp, m_pParentAxis->m_pParent,);
SCROLLINFO info;
info.cbSize = sizeof(SCROLLINFO);
info.fMask = SIF_ALL;
info.nMin = ;
info.nMax = ;
info.nPage = ;
info.nPos = ;
CScrollBar::SetScrollInfo(&info);
}
bool CChartScrollBar::IsScrollInverted() const
{
bool bInverted = false;
if (m_pParentAxis->IsInverted() && m_pParentAxis->m_bIsHorizontal)
bInverted = true;
if (!m_pParentAxis->IsInverted() && !m_pParentAxis->m_bIsHorizontal)
bInverted = true;
return bInverted;
}
void CChartScrollBar::Refresh()
{
double AxisMin=, AxisMax=;
double SeriesMin=, SeriesMax=;
m_pParentAxis->GetMinMax(AxisMin,AxisMax);
m_pParentAxis->GetSeriesMinMax(SeriesMin,SeriesMax);
double dStep = ;
int iTotalSteps = ;
int iCurrentStep = ;
if (m_pParentAxis->IsLogarithmic())
{
// TODO: do something if the series has 0 in it
dStep = pow(AxisMax/AxisMin,0.1);
iTotalSteps = (int)ceil(log(SeriesMax/SeriesMin)/log(dStep));
iCurrentStep = (int)(log(AxisMin/SeriesMin)/log(dStep));
}
else
{
dStep = (AxisMax - AxisMin) / 10.0;
iTotalSteps = (int)ceil((SeriesMax - SeriesMin)/dStep);
iCurrentStep = (int)(iTotalSteps * ((AxisMin - SeriesMin)/(SeriesMax-SeriesMin)));
}
SCROLLINFO info;
info.cbSize = sizeof(SCROLLINFO);
info.fMask = SIF_ALL;
if ( (AxisMax-AxisMin) == || (SeriesMax-SeriesMin)== )
{
info.nMin = ;
info.nMax = ;
info.nPage = ;
info.nPos = ;
}
else
{
info.nMin = ;
info.nMax = iTotalSteps;
info.nPage = ;
info.nPos = iCurrentStep;
if (IsScrollInverted())
info.nPos = iTotalSteps - - iCurrentStep;
else
info.nPos = iCurrentStep;
}
CScrollBar::SetScrollInfo(&info);
}
void CChartScrollBar::OnHScroll(UINT nSBCode, UINT nPos)
{
int MinPos;
int MaxPos;
int PreviousPos = CScrollBar::GetScrollPos();
CScrollBar::GetScrollRange(&MinPos, &MaxPos);
int CurPos = PreviousPos;
bool bUpdate = true;
switch (nSBCode)
{
case SB_LEFT:
CurPos = ;
break;
case SB_RIGHT:
CurPos = MaxPos;
break;
case SB_ENDSCROLL:
bUpdate = false;
break;
case SB_LINELEFT:
if (CurPos > MinPos)
CurPos--;
break;
case SB_LINERIGHT:
if (CurPos < MaxPos-)
CurPos++;
break;
case SB_PAGELEFT:
if (CurPos > MinPos)
CurPos = max(MinPos, CurPos - );
break;
case SB_PAGERIGHT:
if (CurPos < MaxPos-)
CurPos = min(MaxPos, CurPos + );
break;
case SB_THUMBPOSITION:
CurPos = nPos;
break;
case SB_THUMBTRACK:
CurPos = nPos;
break;
}
if (bUpdate)
{
// Set the new position of the thumb (scroll box).
CScrollBar::SetScrollPos(CurPos);
MoveAxisToPos(PreviousPos,CurPos);
}
}
void CChartScrollBar::OnVScroll(UINT nSBCode, UINT nPos)
{
int MinPos;
int MaxPos;
int PreviousPos = CScrollBar::GetScrollPos();
CScrollBar::GetScrollRange(&MinPos, &MaxPos);
int CurPos = PreviousPos;
bool bUpdate = true;
switch (nSBCode)
{
case SB_BOTTOM:
CurPos = MaxPos;
break;
case SB_TOP:
CurPos = ;
break;
case SB_ENDSCROLL:
bUpdate = false;
break;
case SB_LINEDOWN:
if (CurPos < MaxPos-)
CurPos++;
break;
case SB_LINEUP:
if (CurPos > MinPos)
CurPos--;
break;
case SB_PAGEUP:
if (CurPos > MinPos)
CurPos = max(MinPos, CurPos - );
break;
case SB_PAGEDOWN:
if (CurPos < MaxPos-)
CurPos = min(MaxPos, CurPos + );
break;
case SB_THUMBPOSITION:
CurPos = nPos;
break;
case SB_THUMBTRACK:
CurPos = nPos;
break;
}
if (bUpdate)
{
// Set the new position of the thumb (scroll box).
CScrollBar::SetScrollPos(CurPos);
MoveAxisToPos(PreviousPos,CurPos);
}
}
void CChartScrollBar::MoveAxisToPos(int PreviousPos, int CurPos)
{
double AxisMin=, AxisMax=;
double SeriesMin=, SeriesMax=;
m_pParentAxis->GetMinMax(AxisMin,AxisMax);
m_pParentAxis->GetSeriesMinMax(SeriesMin,SeriesMax);
if (m_pParentAxis->IsLogarithmic())
{
double dStep = pow(AxisMax/AxisMin,0.1);
double dFactor = pow(dStep,(CurPos - PreviousPos));
if (IsScrollInverted())
m_pParentAxis->SetZoomMinMax(AxisMin/dFactor,AxisMax/dFactor);
else
m_pParentAxis->SetZoomMinMax(AxisMin*dFactor,AxisMax*dFactor);
}
else
{
double dStep = (AxisMax - AxisMin) / 10.0;
double dOffset = (CurPos - PreviousPos) * dStep;
if (IsScrollInverted())
m_pParentAxis->SetZoomMinMax(AxisMin-dOffset,AxisMax-dOffset);
else
m_pParentAxis->SetZoomMinMax(AxisMin+dOffset,AxisMax+dOffset);
}
}
void CChartScrollBar::OnMouseEnter()
{
if (m_bEnabled && m_bAutoHide)
ShowWindow(SW_SHOW);
}
void CChartScrollBar::OnMouseLeave()
{
if (m_bEnabled && m_bAutoHide)
ShowWindow(SW_HIDE);
}
ChartCtrl源码剖析之——CChartScrollBar类的更多相关文章
- ChartCtrl源码剖析之——CChartObject类
首先,做一些简单的铺垫,目前针对ChartCtrl源码的剖析只针对V.15版本.名义上说是剖析,倒不如说是记录下自己针对该控件的理解,非常感谢Cedric Moonen大神,一切的功劳与掌声都该赠予给 ...
- ChartCtrl源码剖析之——CChartAxis类
CChartAxis类用来绘制波形控件的坐标轴,这个源码相对较复杂,当初阅读的时候耗费了不少精力来理解源码中的一些实现细节. CChartAxis类的头文件. #if !defined(AFX_CHA ...
- ChartCtrl源码剖析之——CChartTitle类
CChartTitle类顾名思义,该类用来绘制波形控件的标题,它处于该控件的区域,如下图所示: CChartTitle类的头文件. #if !defined(AFX_CHARTTITLE_H__499 ...
- ChartCtrl源码剖析之——CChartAxisLabel类
CChartAxisLabel类用来绘制轴标签,上.下.左.右都可以根据实际需要设置对应的轴标签.它处于该控件的区域,如下图所示: CChartAxisLabel类的头文件. #if !defined ...
- 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类的基类.当划分完层次 ...
随机推荐
- HDU 2767 Proving Equivalences(强连通 Tarjan+缩点)
Consider the following exercise, found in a generic linear algebra textbook. Let A be an n × n matri ...
- [Usaco2009 Open]工作安排Job
Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1457 Solved: 687[Submit][Status][Discuss] Descriptio ...
- castle problem——(深度优先搜索,递归实现和stack实现)
将问题的各状态之间的转移关系描述为一个图,则深度优先搜索遍历整个图的框架为:Dfs(v) {if( v 访问过)return;将v标记为访问过;对和v相邻的每个点u: Dfs(u);}int main ...
- PHP 常见问题3
1,Http 和 Https 的区别 第一:http 是超文本传输协议,信息是明文传输,https 是具有安全性的 ssl 加密传输协议 第二:http 和 https 使用的是完全不同的连接方式,端 ...
- PostgreSQL 9.3.1 中文手册(解决关键词报错的问题)
http://www.postgres.cn/docs/9.3/sql-keywords-appendix.html
- [转] OracleDataReader.Read()是否有值
TongYu2009的原文地址 当你执行一次OracleDataReader.Read()是Bool型),注意是只读取一个!如果你的Select语句执行结果是空,或者所有的结果都已经读取完了则Orac ...
- Puppet基于Master/Agent模式实现LNMP平台部署
前言 随着IT行业的迅猛发展,传统的运维方式靠大量人力比较吃力,运维人员面对日益增长的服务器和运维工作,不得不把很多重复的.繁琐的工作利用自动化处理.前期我们介绍了运维自动化工具ansible的简单应 ...
- poj 1258 Agri-Net(Prim)(基础)
Agri-Net Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44487 Accepted: 18173 Descri ...
- 精通CSS:高级Web标准解决方式(第2版)
精通CSS:高级Web标准解决方式(第2版) 跳转至: 导航. 搜索 层叠重要度:(也就是说.用户!important能够覆盖inline style) !important.用户>作者.最后是 ...
- Vue调试工具 vue-devtools
vue-devtools是一款基于chrome浏览器的插件,可以帮我们快速调试vue项目 vue-devtools手动安装: 第一步:找到vue-devtools的github项目(https://g ...