Click here to Skip to main content
15,846,342 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
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.

C++
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);
}


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!
Posted
Updated 18-Apr-12 17:54pm
v2

1 solution

Looks to me that line

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


should read

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


because in the mid position you want Shift to be zero. When dragging down Shift should become positive.
 
Share this answer
 
v4
Comments
skfoo1 18-Apr-12 22:56pm    
Yea, by right that should be the way. But for some reasons, dragging down nCurPos returns a positive and dragging up nCurPos returns a negative.
nv3 19-Apr-12 2:14am    
Important is the '-' (minus) sign. You must subtract nCurPos from m_nSliderVert not add to it! Have you changed that in your code?

Of course, nCurPos will increase when you scroll down. Hence Shift will decrease and hence your diagram will also move down.
skfoo1 19-Apr-12 3:14am    
Yep, I've changed. But now the diagrams moves up when i dragged up. Think something is wrong with the panning function. gonna go check it out. Thanks for your help. :)
nv3 19-Apr-12 3:23am    
If you want the movement direction reversed, simply exchange the sequence in the subtraction, i.e.

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900