diff options
Diffstat (limited to '')
-rw-r--r-- | src/T2DLL/T2DlgItemScr.cpp | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/src/T2DLL/T2DlgItemScr.cpp b/src/T2DLL/T2DlgItemScr.cpp new file mode 100644 index 0000000..692c9a6 --- /dev/null +++ b/src/T2DLL/T2DlgItemScr.cpp @@ -0,0 +1,183 @@ +#include "T2DlgItemScr.h" + +T2DlgItemScr::T2DlgItemScr(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette) + : T2DlgItem(towerDoc, imageObj, palette) +{ + mUpImage = 200; + mDownImage = 200; + mValue = 0; + mRange = 0; + mPage = 0; + mMouseDownPoint = CPoint(0, 0); + mClickedArea = 0; +} + +/*virtual*/ void T2DlgItemScr::SetPage(int page) { + mPage = page; + if (!IsScrollable() && mValue != 0) { + mValue = 0; + Notify(GetDlgCtrlID(), 0, &mValue); + } + Invalidate(); +} + +/*virtual*/ void T2DlgItemScr::SetRange(int range) { + mRange = range; + if (!IsScrollable() && mValue != 0) { + mValue = 0; + Notify(GetDlgCtrlID(), 0, &mValue); + } + Invalidate(); +} + +/*virtual*/ void T2DlgItemScr::SetValue(int value) { + if (!IsScrollable()) + value = 0; + + if (mValue != value) { + mValue = value; + Notify(GetDlgCtrlID(), 0, &mValue); + Invalidate(); + } +} + +/*virtual*/ void T2DlgItemScr::OnT2DlgItemLButtonDown(UINT nFlags, CPoint pt) { + SetCapture(); + m74 = true; + mTimerID = 0; + mClickedArea = ScrollBarHittest(pt); + + if (mClickedArea != 0) { + if (mClickedArea == Area_SetAbsolute) { + mMouseDownPoint = pt; + mMouseDownValue = mValue; + } else { + if (mClickedArea == Area_Up) + mUpImage = 100; + else if (mClickedArea == Area_Down) + mDownImage = 100; + + ScrollBarAction(mClickedArea, 0); + if (mClickedArea == Area_Up || mClickedArea == Area_Down) + mTimerID = SetTimer(999, 100, NULL); + } + } +} + +/*virtual*/ void T2DlgItemScr::OnT2DlgItemLButtonUp(UINT nFlags, CPoint pt) { + if (mClickedArea && mTimerID) + KillTimer(mTimerID); + + ReleaseCapture(); + m74 = false; + mUpImage = 0; + mDownImage = 0; + mClickedArea = 0; + Invalidate(); +} + +/*virtual*/ void T2DlgItemScr::OnT2DlgItemMouseMove(UINT nFlags, CPoint pt) { + if (mClickedArea) { + CRect clientRect; + GetClientRect(clientRect); + + switch (mClickedArea) { + case Area_SetAbsolute: { + int a, b; + clientRect.DeflateRect(0, 16); + CalcScrollBarThumb(&a, &b); + + int val = PositionToValue(clientRect) - b; + if (val == 0) + val = 1; + + ScrollBarAction( + Area_SetAbsolute, + mMouseDownValue + ((PositionToValue(pt) - PositionToValue(mMouseDownPoint)) * (mRange - mPage)) / val + ); + break; + } + case Area_Up: { + CRect upButtonRect; + GetUpButtonRect(clientRect, upButtonRect); + BOOL inUpButton = upButtonRect.PtInRect(pt); + if (inUpButton != m74) { + m74 = inUpButton; + mUpImage = m74 ? 100 : 0; + InvalidateRect(upButtonRect); + } + break; + } + case Area_Down: { + CRect downButtonRect; + GetDnButtonRect(clientRect, downButtonRect); + BOOL inDownButton = downButtonRect.PtInRect(pt); + if (inDownButton != m74) { + m74 = inDownButton; + mDownImage = m74 ? 100 : 0; + InvalidateRect(downButtonRect); + } + break; + } + } + } +} + +void T2DlgItemScr::CalcScrollBarThumb(int* a, int* b) const { + if (!IsScrollable()) { + *a = 16; + *b = 0; + } else { + CRect clientRect; + GetClientRect(clientRect); + + int value = PositionToValue(clientRect); + value -= 32; + + *b = (value * mPage) / mRange; + if (*b < 10) + *b = 10; + *a = (((value - *b) * mValue) / (mRange - mPage)) + 16; + } +} + +void T2DlgItemScr::ScrollBarAction(int area, int arg) { + if (!IsScrollable()) { + mValue = 0; + } else { + switch (area) { + case Area_Up: + mValue--; + break; + case Area_PageUp: + mValue -= mPage / 2; + break; + case Area_SetAbsolute: + mValue = arg; + break; + case Area_PageDown: + mValue += mPage / 2; + break; + case Area_Down: + mValue++; + break; + } + + if (mValue < 0) + mValue = 0; + if (mValue > (mRange - mPage)) + mValue = mRange - mPage; + } + + Notify(GetDlgCtrlID(), 0, &mValue); + Invalidate(); +} + +BOOL T2DlgItemScr::IsScrollable() const { + return (mRange > 0) && (mPage < mRange); +} + +/*virtual*/ void T2DlgItemScr::OnT2Timer(UINT id) { + if (id == mTimerID && m74 && (mClickedArea == Area_Up || mClickedArea == Area_Down)) + ScrollBarAction(mClickedArea, 0); +} |