使用滑块进行图形平移 [英] Using Sliders to do panning for graphs

查看:125
本文介绍了使用滑块进行图形平移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的程序中有2个滑块,可以平移X& Y轴分别.
控制X轴平移的滑块(水平)工作正常.但是控制Y轴平移的滑块(垂直)不起作用.

Hi,

I''ve 2 sliders in my program to do panning for the X & Y axis respectively.
The slider (Horizontal) controlling the panning for X-axis works fine. But the slider (vertical) controlling the panning for Y-axis does not work.

m_sliderHorizontal.SetBuddy(&m_ChartCtrl, FALSE);
m_slidervertical.SetBuddy(&m_ChartCtrl, FALSE);

m_sliderHorizontal.SetRange(nMinX, nMaxX); // Range is >= 0 (Min & Max values of inital X-axis)
m_slidervertical.SetRange(nMinY, nMaxY);   // Range includes "-" & "+" values (Min & Max values of inital Y-axis)
			
m_sliderHorizontal.SetTicFreq(1);
m_slidervertical.SetTicFreq(1);
	
m_sliderHorizontal.SetPos(0);
m_slidervertical.SetPos(m_nSliderVert);  // Set the slider to the middle

void CDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
	int nCurPos = m_sliderHorizontal.GetPos();
	double Shift = m_dMinX - (double)nCurPos;  // How much the slider shifted

	m_dSliderMinXShift = m_dMinX - Shift;     
	m_dSliderMaxXShift = m_dMaxX - Shift;

	m_pBottomAxis->SetZoomMinMax(m_dSliderMinXShift, m_dSliderMaxXShift);  // Panning
	
	SetMinMax(); // Get Current X-axis's Min & Max Values

	CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}

void CDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
	int nCurPos = m_slidervertical.GetPos();
	double Shift = (double)(m_nSliderVert + nCurPos);

	m_dSliderMinYShift = m_dMinY - Shift;
	m_dSliderMaxYShift = m_dMaxY - Shift;
	
	m_pLeftAxis->SetZoomMinMax(m_dSliderMinYShift, m_dSliderMaxYShift);  // Panning
	
	SetMinMax(); // Get Current Y-axis's Min & Max Values
	CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}



水平滑块工作正常.但是,垂直滑块与水平滑块的功能不同.每当我拖动垂直滑块时,Min&如果在负范围内,Y轴的最大值将变小;在正范围内,Y轴的最大值将变大.它永远不会回到原始范围.

示例:
当我向上拖动滑块时,图形和轴将向下移动,并且Y轴的最小值和最大值将不断增大.比起我甚至开始向下拖动到滑块控件的末尾,它永远不会回到原始范围.当我再次将其拖回时,Min&最大值变得更大.


我想做的是,当我向上拖动垂直滑块时,轴和曲线图应向下移动,这是通过在原始范围内使用SetZoomMinMaxMax()函数来完成的.

希望我能澄清我的问题.请原谅我的英语不好.
感谢您的帮助!



The horizontal slider works fine. The vertical slider, however, does not works the same as the horizontal slider. Whenever i dragged the vertical slider, the Min & Max values of the Y-axis will get smaller if its in the negative range, bigger if in the positive range. It will never go back to the original range.

Example:
When i drag the slider up, the graphs and axis will move downwards and the Min and max values of Y-axis will keep getting bigger. Than when i start to drag down even to the end of the slider control, it never go back to the original range. When i drag it back up again, the Min & Max values gets even bigger.


What i want to do is that when i drag the vertical slider up, the axis together with the graphs should be moving downwards which is accomplished by the function SetZoomMinMax() within the original range.

Hope i make my question clear. Pardon my bad English.
Thanks for helping!

推荐答案

在我看来那条线

Looks to me that line

double Shift = (double)(m_nSliderVert + nCurPos);



应该阅读



should read

double Shift = (double)(nCurPos - m_nSliderVert);



因为在中间位置您希望Shift为零.向下拖动时,Shift应该变成正数.



because in the mid position you want Shift to be zero. When dragging down Shift should become positive.


这篇关于使用滑块进行图形平移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆