#include "StdAfx.h" #include "T2BitImage.h" #include "T2DlgItemArrows.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif 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& inRect, CWnd* parentWnd, UINT nId) { CRect rect = inRect; CRect theImageArea; T2BitImage *theImage = GetObjectImage(theImageArea, "DLGITEM:Arrows"); if (theImage) { rect.right = rect.left + theImageArea.Width(); rect.bottom = rect.top + theImageArea.Height(); } return T2DlgItem::Create(windowName, style, rect, parentWnd, nId); } /*virtual*/ void T2DlgItemArrows::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) { CRect rect; GetClientRect(rect); CRect imageRect; if (GetObjectImage(imageRect, "DLGITEM:Arrows")) { CRect upRect = imageRect; upRect.bottom = upRect.top + (upRect.Height() / 2); upRect.OffsetRect(-upRect.left + rect.left, -upRect.top + rect.top); CRect dnRect = upRect; dnRect.OffsetRect(-dnRect.left + rect.left, -dnRect.top + rect.top + upRect.Height() + 1); if (upRect.PtInRect(inPt)) { SetPattern(100); mMouseRect = upRect; } else if (dnRect.PtInRect(inPt)) { 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 theFrameRect; GetClientRect(theFrameRect); int save = pDC->SaveDC(); pDC->SelectPalette(mPalette, false); pDC->RealizePalette(); CRect theImageArea; T2BitImage *theImage = GetObjectImage(theImageArea, "DLGITEM:Arrows", !m74 ? 0 : GetPattern()); if (theImage) { CRect drawRect = theImageArea; drawRect.OffsetRect(-drawRect.left + theFrameRect.left, -drawRect.top + theFrameRect.top); theImage->CopyImage(pDC, theImageArea, 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); }