diff options
Diffstat (limited to '')
-rw-r--r-- | src/T2DLL/T2DlgItemArrows.cpp | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/src/T2DLL/T2DlgItemArrows.cpp b/src/T2DLL/T2DlgItemArrows.cpp new file mode 100644 index 0000000..64c9ae3 --- /dev/null +++ b/src/T2DLL/T2DlgItemArrows.cpp @@ -0,0 +1,139 @@ +#include "T2BitImage.h" +#include "T2DlgItemArrows.h" + +T2DlgItemArrows::T2DlgItemArrows(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItem(inDoc, inImageObj, inPalette) + , mMinimum(0) + , mMaximum(0) + , mIsClicked(false) +{ +} + +/*virtual*/ T2DlgItemArrows::~T2DlgItemArrows() { +} + +/*virtual*/ BOOL T2DlgItemArrows::Create(const char* windowName, DWORD style, const RECT& rect, CWnd* parentWnd, UINT nId) { + CRect rectToUse = rect; + CRect imageRect; + T2BitImage *image = GetObjectImage(imageRect, "DLGITEM:Arrows"); + if (image) { + rectToUse.right = rectToUse.left + imageRect.Width(); + rectToUse.bottom = rectToUse.top + imageRect.Height(); + } + return T2DlgItem::Create(windowName, style, rectToUse, parentWnd, nId); +} + +/*virtual*/ void T2DlgItemArrows::OnT2DlgItemLButtonDown(UINT nFlags, CPoint pt) { + CRect clientRect; + GetClientRect(clientRect); + + CRect imageRect; + if (GetObjectImage(imageRect, "DLGITEM:Arrows")) { + CRect upRect = imageRect; + upRect.bottom = upRect.top + (imageRect.Height() / 2); + upRect.OffsetRect(-upRect.left + clientRect.left, -upRect.top + clientRect.top); + + CRect dnRect = imageRect; + dnRect.OffsetRect(-dnRect.left + clientRect.left, -dnRect.top + clientRect.top + upRect.Height() + 1); + + if (upRect.PtInRect(pt)) { + SetPattern(100); + mMouseRect = upRect; + } else if (dnRect.PtInRect(pt)) { + SetPattern(101); + mMouseRect = dnRect; + } + } + + if (GetPattern() != 0) { + SetCapture(); + m74 = true; + mIsClicked = true; + InvalidateRect(mMouseRect); + + SetValue(GetValue() + (GetPattern() == 100 ? 1 : -1)); + Notify(GetDlgCtrlID(), 0, NULL); + mTimerID = SetTimer(999, 100, NULL); + } +} + +/*virtual*/ void T2DlgItemArrows::OnT2DlgItemLButtonUp(UINT nFlags, CPoint pt) { + if (mIsClicked) { + if (mTimerID) + KillTimer(mTimerID); + + SetPattern(0); + ReleaseCapture(); + mIsClicked = false; + + if (m74) { + m74 = false; + InvalidateRect(mMouseRect); + } + } +} + +/*virtual*/ void T2DlgItemArrows::OnT2DlgItemMouseMove(UINT nFlags, CPoint pt) { + if (mIsClicked) { + BOOL inRect = mMouseRect.PtInRect(pt); + if (inRect != m74) { + m74 = inRect; + InvalidateRect(mMouseRect); + } + } +} + +/*virtual*/ BOOL T2DlgItemArrows::OnT2DlgItemEraseBkgnd(CDC* pDC) { + CRect clientRect; + GetClientRect(clientRect); + + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + CRect imageRect; + int pattern; + if (!m74) + pattern = 0; + else + pattern = GetPattern(); + T2BitImage *image = GetObjectImage(imageRect, "DLGITEM:Arrows", pattern); + + if (image) { + CRect drawRect = imageRect; + drawRect.OffsetRect(-drawRect.left + clientRect.left, -drawRect.top + clientRect.top); + image->CopyImage(pDC, imageRect, drawRect, 0, NULL); + } + + pDC->RestoreDC(save); + + return true; +} + +/*virtual*/ void T2DlgItemArrows::OnT2Timer(UINT id) { + if (id == mTimerID && m74) { + SetValue(GetValue() + (GetPattern() == 100 ? 1 : -1)); + Notify(GetDlgCtrlID(), 0, NULL); + } +} + +/*virtual*/ void T2DlgItemArrows::SetMinValue(int inValue) { + mMinimum = inValue; + if (mValue < inValue) + SetValue(inValue); +} + +/*virtual*/ void T2DlgItemArrows::SetMaxValue(int inValue) { + mMaximum = inValue; + if (mValue > inValue) + SetValue(inValue); +} + +/*virtual*/ void T2DlgItemArrows::SetValue(int inValue) { + if (inValue < mMinimum) + inValue = mMinimum; + else if (inValue > mMaximum) + inValue = mMaximum; + + T2DlgItem::SetValue(inValue); +} |