예제 #1
0
파일: drawobj.cpp 프로젝트: mingpen/OpenNT
// point is in logical coordinates
int CDrawObj::HitTest(CPoint point, CDrawView* pView, BOOL bSelected)
{
	ASSERT_VALID(this);
	ASSERT(pView != NULL);

	if (bSelected)
	{
		int nHandleCount = GetHandleCount();
		for (int nHandle = 1; nHandle <= nHandleCount; nHandle += 1)
		{
			// GetHandleRect returns in logical coords
			CRect rc = GetHandleRect(nHandle,pView);
			if (point.x >= rc.left && point.x < rc.right &&
				point.y <= rc.top && point.y > rc.bottom)
				return nHandle;
		}
	}
	else
	{
		if (point.x >= m_position.left && point.x < m_position.right &&
			point.y <= m_position.top && point.y > m_position.bottom)
			return 1;
	}
	return 0;
}
예제 #2
0
int CRectTracker::HitTestHandles(CPoint point) const
{
	CRect rect;
	UINT mask = GetHandleMask();

	// see if hit anywhere inside the tracker
	GetTrueRect(&rect);
	if (!rect.PtInRect(point))
		return hitNothing;  // totally missed

	// see if we hit a handle
	for (int i = 0; i < 8; ++i)
	{
		if (mask & (1<<i))
		{
			GetHandleRect((TrackerHit)i, &rect);
			if (rect.PtInRect(point))
				return (TrackerHit)i;
		}
	}

	// last of all, check for non-hit outside of object, between resize handles
	if ((m_nStyle & hatchedBorder) == 0)
	{
		CRect rect = m_rect;
		rect.NormalizeRect();
		if ((m_nStyle & dottedLine|solidLine) != 0)
			rect.InflateRect(+1, +1);
		if (!rect.PtInRect(point))
			return hitNothing;  // must have been between resize handles
	}
	return hitMiddle;   // no handle hit, but hit object (or object border)
}
예제 #3
0
//------------------------------------------------------    
void CRectTracker::Draw( HDC hDC ) 
{
    SaveDC(hDC);
    HPEN LinePen = CreatePen( PS_SOLID, LineWidth, LineColor );
    HBRUSH HandleBrush = CreateSolidBrush( HandleColor );

    HPEN hOldPen = (HPEN)SelectObject(hDC, LinePen);

	DrawRect(hDC, &CurPos.Begin, &CurPos.End);

	SelectObject(hDC, hOldPen);

    FillRect(hDC, &GetHandleRect(handleBegin), HandleBrush );
    FillRect(hDC, &GetHandleRect(handleEnd), HandleBrush );

	DeleteObject(hOldPen);
	DeleteObject(HandleBrush);
};
예제 #4
0
//------------------------------------------------------    
int CRectTracker::HitTest( const LPPOINT point ) const
{
	ATLASSERT(point);

    // check handles
    RECT R = GetHandleRect(handleBegin);

    if (PtInRect(&R, *point))
        return hitBegin;

    R = GetHandleRect(handleEnd);
    if (PtInRect(&R, *point))
        return hitEnd;

    SetRect(&R, CurPos.Begin.x, CurPos.Begin.y, CurPos.End.x, CurPos.End.y );
    NormalizeRect(&R);
    RECT VicX = R;
    RECT VicY = R;

    InflateRect(&VicX, VicinitySize, 0 );
    InflateRect(&VicY, 0, VicinitySize );

    if (!PtInRect(&VicX, *point) && !PtInRect(&VicY, *point))
        return hitNothing;

    // check distance from the point to the line by x and by y
    int dx = CurPos.End.x - CurPos.Begin.x;
    int dy = CurPos.End.y - CurPos.Begin.y;
	double r = sqrt((double)(dx*dx + dy*dy));

    // compute coordinates relative to the origin of the line
    int x1 = point->x - CurPos.Begin.x;
    int y1 = point->y - CurPos.Begin.y;

    // compute coordinates relative to the line
    double x2 = (x1*dx + y1*dy)/r;
    double y2 = (-x1*dy + y1*dx)/r;

    if ((x2>=0) && (x2<=r) && (y2<=VicinitySize) && (y2 >= -VicinitySize))
        return hitMiddle;

    return hitNothing;
};
예제 #5
0
  int GraphicsBase::MakeHitTest(const glm::vec2& point)
  {
    if (selected_) {
      for (int i = 1; i <= HandleCount(); ++i)
      {
        if (GetHandleRect(i).Contains(point))
          return i;
      }
    }

    if (Contains(point))
      return 0;

    return -1;
  }
예제 #6
0
void LeoRectTracker::Draw(CDC* pDC) 
{

	CPen penBrown(PS_SOLID,1, RGB(192,110,0));
	CPen penGreen(PS_SOLID,2, RGB(0,192,0));
	CPen* pOldPen;
	// draw lines    // 边框颜色
	if ((m_nStyle & (dottedLine|solidLine)) != 0)
	{
		if (m_nStyle & dottedLine)
		{

			pOldPen = pDC->SelectObject(&penGreen);

		}
		else
		{
			pOldPen = pDC->SelectObject(&penBrown);
		}
		CBrush* pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH);
		pDC->Rectangle(&m_rect);

		//画中心点
		SIZE size = {2,2};
		CRect centerRect(m_rect.CenterPoint(), size);
		pDC->FillSolidRect(centerRect,RGB(255,125,0));
	}



	// draw resize handles    // 八个黑角的颜色
	if ((m_nStyle & (resizeInside|resizeOutside)) != 0)
	{
		UINT mask = GetHandleMask();
		CRect rect;
		for (int i = 0; i < 8; ++i)
		{
			if (mask & (1<<i))
			{
				GetHandleRect((TrackerHit)i, &rect);
				pDC->FillSolidRect(rect, RGB(125,125,0));    // RGB(0, 0, 0));
			}
		}
	}
}
// point is in device coordinates
int CDrawObject::HitTest(CPoint point, BOOL bSelected)
{
	FTLASSERT(this);

	if (bSelected)
	{
		int nHandleCount = GetHandleCount();
		for (int nHandle = 1; nHandle <= nHandleCount; nHandle += 1)
		{
			// GetHandleRect returns in device coords
			CRect rc = GetHandleRect(nHandle);
			FTLASSERT(!rc.IsRectEmpty());
			//rc.NormalizeRect();
			//if (1 == nHandle || 2 == nHandle)
			//{
			//	FTLTRACE(TEXT("rcHandle[%d]=[%d,%d]x[%d,%d], point =[%d,%d]\n"),
			//		nHandle, rc.left, rc.top, rc.right, rc.bottom, point.x, point.y);
			//}
			if (rc.PtInRect(point))
			{
				return nHandle;
			}
		}
	}
	else
	{
		FTLASSERT(FALSE);
		CRect rcPosition = m_position;
		rcPosition.NormalizeRect();
		if (rcPosition.PtInRect(point))
		{
			return 1;
		}
	}
	return 0;
}
예제 #8
0
void CRectTracker::Draw(CDC* pDC) const
{
	// set initial DC state
	VERIFY(pDC->SaveDC() != 0);
	pDC->SetMapMode(MM_TEXT);
	pDC->SetViewportOrg(0, 0);
	pDC->SetWindowOrg(0, 0);

	// get normalized rectangle
	CRect rect = m_rect;
	rect.NormalizeRect();

	CPen* pOldPen = NULL;
	CBrush* pOldBrush = NULL;
	CGdiObject* pTemp;
	int nOldROP;

	// draw lines
	if ((m_nStyle & (dottedLine|solidLine)) != 0)
	{
		if (m_nStyle & dottedLine)
			pOldPen = pDC->SelectObject(CPen::FromHandle(blackDottedPen));
		else
			pOldPen = (CPen*)pDC->SelectStockObject(BLACK_PEN);
		pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH);
		nOldROP = pDC->SetROP2(R2_COPYPEN);
		rect.InflateRect(+1, +1);   // borders are one pixel outside
		pDC->Rectangle(rect.left, rect.top, rect.right, rect.bottom);
		pDC->SetROP2(nOldROP);
	}

	// if hatchBrush is going to be used, need to unrealize it
	if ((m_nStyle & (hatchInside|hatchedBorder)) != 0)
		UnrealizeObject(hatchBrush);

	// hatch inside
	if ((m_nStyle & hatchInside) != 0)
	{
		pTemp = pDC->SelectStockObject(NULL_PEN);
		if (pOldPen == NULL)
			pOldPen = (CPen*)pTemp;
		pTemp = pDC->SelectObject(CBrush::FromHandle(hatchBrush));
		if (pOldBrush == NULL)
			pOldBrush = (CBrush*)pTemp;
		pDC->SetBkMode(TRANSPARENT);
#ifndef _MAC
		nOldROP = pDC->SetROP2(R2_MASKNOTPEN);
#else _MAC
		nOldROP = pDC->SetROP2(R2_MERGENOTPEN);
#endif // _MAC
		pDC->Rectangle(rect.left+1, rect.top+1, rect.right, rect.bottom);
		pDC->SetROP2(nOldROP);
	}

	// draw hatched border
	if ((m_nStyle & hatchedBorder) != 0)
	{
		pTemp = pDC->SelectObject(CBrush::FromHandle(hatchBrush));
		if (pOldBrush == NULL)
			pOldBrush = (CBrush*)pTemp;
		pDC->SetBkMode(OPAQUE);
		CRect rectTrue;
		GetTrueRect(&rectTrue);
		pDC->PatBlt(rectTrue.left, rectTrue.top, rectTrue.Width(),
			rect.top-rectTrue.top, 0x000F0001 /* Pn */);
		pDC->PatBlt(rectTrue.left, rect.bottom,
			rectTrue.Width(), rectTrue.bottom-rect.bottom, 0x000F0001 /* Pn */);
		pDC->PatBlt(rectTrue.left, rect.top, rect.left-rectTrue.left,
			rect.Height(), 0x000F0001 /* Pn */);
		pDC->PatBlt(rect.right, rect.top, rectTrue.right-rect.right,
			rect.Height(), 0x000F0001 /* Pn */);
	}

	// draw resize handles
	if ((m_nStyle & (resizeInside|resizeOutside)) != 0)
	{
		UINT mask = GetHandleMask();
		for (int i = 0; i < 8; ++i)
		{
			if (mask & (1<<i))
			{
				GetHandleRect((TrackerHit)i, &rect);
				pDC->FillSolidRect(rect, RGB(0, 0, 0));
			}
		}
	}

	// cleanup pDC state
	if (pOldPen != NULL)
		pDC->SelectObject(pOldPen);
	if (pOldBrush != NULL)
		pDC->SelectObject(pOldBrush);
	VERIFY(pDC->RestoreDC(-1));
}
예제 #9
0
void CScrollBar::EventValueChange(IControl *pSender, tint32 /*iValueNew*/)
{
	// Lasse, add 2008-05-09
	if ((mpScrollPane) && (pSender == mpScrollPane)) {
		SScrollPos sp;
		mpScrollPane->GetScrollPos(sp);
		if (mScrollPos != sp) {
			SRect rectTest1 = GetHandleRect();
			SetScrollPos(sp, true);
			//PositionControls();
			Redraw(GetRect());
			SRect rectTest2 = GetHandleRect();
			int iDummy = 0;
		}
		return;
	}
	// .. Lasse

	// Figure out which one of the controls it is
	std::list<IControl*>::iterator it = mControls.begin();
	if (mControls.size() > 2) {
		it++;
	}
	tint iDelta;
	if (pSender == *it) {
		// Up / left
		iDelta = -10;
	}
	else {
		// Down / right
		iDelta = 10;
	}

	SRect rctHandle = GetHandleRect();

	switch(mType) {
		case TypeHorizontal:
			{
				// Calculate where we want the handle to be
				tint iHandlePosX = rctHandle.iX + iDelta;

				// Calculate movememt from mouse delta
				std::list<IControl*>::iterator it = mControls.begin();
				if (mControls.size() > 2) {
					it++;
				}
				IControl* pControl = *it++;
				SRect RctArrowLeft;
				pControl->GetRect(RctArrowLeft);

				// Left-most possible handle position
				SPos PosLeftMost(RctArrowLeft.iX + RctArrowLeft.iCX, RctArrowLeft.iY);

				pControl = *it;
				SPos PosRightArrow;
				pControl->GetPos(PosRightArrow);
				tint iMaxWidth = PosRightArrow.iX - PosLeftMost.iX;

				// Calculate the relative width we occupy
				tfloat64 fWidthRelative = mScrollPos.VisibleRect.iCX / (double)mScrollPos.AreaSize.iCX;

				// Calculate the ralative position to be
				tfloat64 fPositionRelative = (iHandlePosX - PosLeftMost.iX) / (iMaxWidth - (fWidthRelative * iMaxWidth));

				// Update scrolling position
				mScrollPos.VisibleRect.iX = (int)((fPositionRelative * (mScrollPos.AreaSize.iCX - mScrollPos.VisibleRect.iCX)) + 0.5f);

				// Limit scrolling position
				if (mScrollPos.VisibleRect.iX < 0) {
					mScrollPos.VisibleRect.iX = 0;
				}
				if (mScrollPos.VisibleRect.iX > mScrollPos.AreaSize.iCX - mScrollPos.VisibleRect.iCX) {
					mScrollPos.VisibleRect.iX = mScrollPos.AreaSize.iCX - mScrollPos.VisibleRect.iCX;
				}

				// Redraw and set scroll pos (which will cause scroll pane to redraw)
				CControl::Redraw();
				mpScrollPane->SetScrollPos(mScrollPos);
			}
			break;
		case TypeVertical:
			{
				// Calculate where we want the handle to be
				tint iHandlePosY = rctHandle.iY + iDelta;

				// Calculate movememt from mouse delta
				std::list<IControl*>::iterator it = mControls.begin();
				if (mControls.size() > 2) {
					it++;
				}
				IControl* pControl = *it++;
				SRect RctArrowTop;
				pControl->GetRect(RctArrowTop);

				// Top-most possible handle position
				SPos PosTopMost(RctArrowTop.iX, RctArrowTop.iY + RctArrowTop.iCY);

				pControl = *it;
				SPos PosBottomArrow;
				pControl->GetPos(PosBottomArrow);
				tint iMaxHeight = PosBottomArrow.iY - PosTopMost.iY;

				// Calculate the relative height we occupy
				tfloat64 fHeightRelative = mScrollPos.VisibleRect.iCY / (double)mScrollPos.AreaSize.iCY;

				// Calculate the ralative position to be
				tfloat64 fPositionRelative = (iHandlePosY - PosTopMost.iY) / (iMaxHeight - (fHeightRelative * iMaxHeight));

				// Update scrolling position
				mScrollPos.VisibleRect.iY = (int)((fPositionRelative * (mScrollPos.AreaSize.iCY - mScrollPos.VisibleRect.iCY)) + 0.5f);

				// Limit scrolling position
				if (mScrollPos.VisibleRect.iY < 0) {
					mScrollPos.VisibleRect.iY = 0;
				}
				if (mScrollPos.VisibleRect.iY > mScrollPos.AreaSize.iCY - mScrollPos.VisibleRect.iCY) {
					mScrollPos.VisibleRect.iY = mScrollPos.AreaSize.iCY - mScrollPos.VisibleRect.iCY;
				}

				// Redraw and set scroll pos (which will cause scroll pane to redraw)
				CControl::Redraw();
				mpScrollPane->SetScrollPos(mScrollPos);
			}
			break;
	}
}
예제 #10
0
tbool CScrollBar::OnMouse(EMouseMsg MouseMsg, const SPos& Pos)
{
	if (!IsVisible()) {
		return false;
	}

	if (CPane::OnMouse(MouseMsg, Pos)) {
		return true;
	}

	if (mbScrolling) {
		// We're currently scrolling
		switch(MouseMsg) {
			case MouseMove:
				{
					switch(mType) {
						case TypeHorizontal:
							{
								// Calculate the mouse delta
								tint iMouseDelta = Pos.iX - mMousePosOrg.iX;

								// Calculate where we want the handle to be
								tint iHandlePosX = mScrollBarRectOrg.iX + iMouseDelta;

								// Calculate movememt from mouse delta
								std::list<IControl*>::iterator it = mControls.begin();
								if (mControls.size() > 2) {
									it++;
								}
								IControl* pControl = *it++;
								SRect RctArrowLeft;
								pControl->GetRect(RctArrowLeft);

								// Left-most possible handle position
								SPos PosLeftMost(RctArrowLeft.iX + RctArrowLeft.iCX, RctArrowLeft.iY);

								pControl = *it;
								SPos PosRightArrow;
								pControl->GetPos(PosRightArrow);
								tint iMaxWidth = PosRightArrow.iX - PosLeftMost.iX;

								// Calculate the relative width we occupy
								tfloat64 fWidthRelative = mScrollPos.VisibleRect.iCX / (double)mScrollPos.AreaSize.iCX;

								// Calculate the ralative position to be
								tfloat64 fPositionRelative = (iHandlePosX - PosLeftMost.iX) / (iMaxWidth - (fWidthRelative * iMaxWidth));

								// Update scrolling position
								mScrollPos = mScrollPosOrg;
								mScrollPos.VisibleRect.iX = (int)((fPositionRelative * (mScrollPos.AreaSize.iCX - mScrollPos.VisibleRect.iCX)) + 0.5f);

								// Limit scrolling position
								if (mScrollPos.VisibleRect.iX < 0) {
									mScrollPos.VisibleRect.iX = 0;
								}
								if (mScrollPos.VisibleRect.iX > mScrollPos.AreaSize.iCX - mScrollPos.VisibleRect.iCX) {
									mScrollPos.VisibleRect.iX = mScrollPos.AreaSize.iCX - mScrollPos.VisibleRect.iCX;
								}

								// Redraw and set scroll pos (which will cause scroll pane to redraw)
								CControl::Redraw();
								mpScrollPane->SetScrollPos(mScrollPos);

								SetValue(0);
							}
							break;
						case TypeVertical:
							{
								// Calculate the mouse delta
								tint iMouseDelta = Pos.iY - mMousePosOrg.iY;

								// Calculate where we want the handle to be
								tint iHandlePosY = mScrollBarRectOrg.iY + iMouseDelta;

								// Calculate movememt from mouse delta
								std::list<IControl*>::iterator it = mControls.begin();
								if (mControls.size() > 2) {
									it++;
								}
								IControl* pControl = *it++;
								SRect RctArrowTop;
								pControl->GetRect(RctArrowTop);

								// Top-most possible handle position
								SPos PosTopMost(RctArrowTop.iX, RctArrowTop.iY + RctArrowTop.iCY);

								pControl = *it;
								SPos PosBottomArrow;
								pControl->GetPos(PosBottomArrow);
								tint iMaxHeight = PosBottomArrow.iY - PosTopMost.iY;

								// Calculate the relative height we occupy
								tfloat64 fHeightRelative = mScrollPos.VisibleRect.iCY / (double)mScrollPos.AreaSize.iCY;

								// Calculate the ralative position to be
								tfloat64 fPositionRelative = (iHandlePosY - PosTopMost.iY) / (iMaxHeight - (fHeightRelative * iMaxHeight));

								// Update scrolling position
								mScrollPos = mScrollPosOrg;
								mScrollPos.VisibleRect.iY = (int)((fPositionRelative * (mScrollPos.AreaSize.iCY - mScrollPos.VisibleRect.iCY)) + 0.5f);

								// Limit scrolling position
								if (mScrollPos.VisibleRect.iY < 0) {
									mScrollPos.VisibleRect.iY = 0;
								}
								if (mScrollPos.VisibleRect.iY > mScrollPos.AreaSize.iCY - mScrollPos.VisibleRect.iCY) {
									mScrollPos.VisibleRect.iY = mScrollPos.AreaSize.iCY - mScrollPos.VisibleRect.iCY;
								}

								// Redraw and set scroll pos (which will cause scroll pane to redraw)
								CControl::Redraw();
								mpScrollPane->SetScrollPos(mScrollPos);

								SetValue(0);
							}
							break;
					}
				}
				break;
			case LeftButtonUp:
				{
					dynamic_cast<CWindow*>(GetParentWindow())->ReleaseMouseFocus();

					mbScrolling = false;

					return true;
				}
				break;
		}
	}

	SRect rctHandle = GetHandleRect();
	if (rctHandle.Inside(Pos)) {
		// We hit the handle with the mouse
		if (MouseMsg == LeftButtonDown) {
			mMousePosOrg = Pos;
			mScrollPosOrg = mScrollPos;
			mScrollBarRectOrg = rctHandle;

			dynamic_cast<CWindow*>(GetParentWindow())->GetMouseFocus(dynamic_cast<IControl*>(this));

			mbScrolling = true;

			return true;
		}
	}
	else {
		if (MouseMsg == LeftButtonDown) {
			SRect RctThis;
			GetRect(RctThis);
			if (RctThis.Inside(Pos)) {
				// We hit inside the control (but not the handle)
				switch(mType) {
					case TypeHorizontal:
						{
							// Calculate the mouse delta
							tint iMouseDelta;
							if (Pos.iX < rctHandle.iX) {
								iMouseDelta = -rctHandle.iCX;
							}
							else {
								iMouseDelta = rctHandle.iCX;
							}

							// Calculate where we want the handle to be
							tint iHandlePosX = rctHandle.iX + iMouseDelta;

							// Calculate movememt from mouse delta
							std::list<IControl*>::iterator it = mControls.begin();
							if (mControls.size() > 2) {
								it++;
							}
							IControl* pControl = *it++;
							SRect RctArrowLeft;
							pControl->GetRect(RctArrowLeft);

							// Left-most possible handle position
							SPos PosLeftMost(RctArrowLeft.iX + RctArrowLeft.iCX, RctArrowLeft.iY);

							pControl = *it;
							SPos PosRightArrow;
							pControl->GetPos(PosRightArrow);
							tint iMaxWidth = PosRightArrow.iX - PosLeftMost.iX;

							// Calculate the relative width we occupy
							tfloat64 fWidthRelative = mScrollPos.VisibleRect.iCX / (double)mScrollPos.AreaSize.iCX;

							// Calculate the ralative position to be
							tfloat64 fPositionRelative = (iHandlePosX - PosLeftMost.iX) / (iMaxWidth - (fWidthRelative * iMaxWidth));

							// Update scrolling position
							mScrollPos = mScrollPos;
							mScrollPos.VisibleRect.iX = (int)((fPositionRelative * (mScrollPos.AreaSize.iCX - mScrollPos.VisibleRect.iCX)) + 0.5f);

							// Limit scrolling position
							if (mScrollPos.VisibleRect.iX < 0) {
								mScrollPos.VisibleRect.iX = 0;
							}
							if (mScrollPos.VisibleRect.iX > mScrollPos.AreaSize.iCX - mScrollPos.VisibleRect.iCX) {
								mScrollPos.VisibleRect.iX = mScrollPos.AreaSize.iCX - mScrollPos.VisibleRect.iCX;
							}

							// Redraw and set scroll pos (which will cause scroll pane to redraw)
							CControl::Redraw();
							mpScrollPane->SetScrollPos(mScrollPos);
							
							// Lasse, added 2008-04-17 - bug-fix, didn't fire listeners' EventValueChange
							SetValue(0);
							// .. Lasse
						}
						break;

					case TypeVertical:
						{
							// Calculate the mouse delta
							tint iMouseDelta;
							if (Pos.iY < rctHandle.iY) {
								iMouseDelta = -rctHandle.iCY;
							}
							else {
								iMouseDelta = rctHandle.iCY;
							}

							// Calculate where we want the handle to be
							tint iHandlePosY = rctHandle.iY + iMouseDelta;

							// Calculate movememt from mouse delta
							std::list<IControl*>::iterator it = mControls.begin();
							if (mControls.size() > 2) {
								it++;
							}
							IControl* pControl = *it++;
							SRect RctArrowTop;
							pControl->GetRect(RctArrowTop);

							// Top-most possible handle position
							SPos PosTopMost(RctArrowTop.iX, RctArrowTop.iY + RctArrowTop.iCY);

							pControl = *it;
							SPos PosBottomArrow;
							pControl->GetPos(PosBottomArrow);
							tint iMaxHeight = PosBottomArrow.iY - PosTopMost.iY;

							// Calculate the relative height we occupy
							tfloat64 fHeightRelative = mScrollPos.VisibleRect.iCY / (double)mScrollPos.AreaSize.iCY;

							// Calculate the ralative position to be
							tfloat64 fPositionRelative = (iHandlePosY - PosTopMost.iY) / (iMaxHeight - (fHeightRelative * iMaxHeight));

							// Update scrolling position
							mScrollPos = mScrollPos;
							mScrollPos.VisibleRect.iY = (int)((fPositionRelative * (mScrollPos.AreaSize.iCY - mScrollPos.VisibleRect.iCY)) + 0.5f);

							// Limit scrolling position
							if (mScrollPos.VisibleRect.iY < 0) {
								mScrollPos.VisibleRect.iY = 0;
							}
							if (mScrollPos.VisibleRect.iY > mScrollPos.AreaSize.iCY - mScrollPos.VisibleRect.iCY) {
								mScrollPos.VisibleRect.iY = mScrollPos.AreaSize.iCY - mScrollPos.VisibleRect.iCY;
							}

							// Redraw and set scroll pos (which will cause scroll pane to redraw)
							CControl::Redraw();
							mpScrollPane->SetScrollPos(mScrollPos);
							
							// Lasse, added 2008-04-17 - bug-fix, didn't fire listeners' EventValueChange
							SetValue(0);
							// .. Lasse
						}
						break;
				}
			}
		}
	}

	return false;
}
예제 #11
0
void CScrollBar::OnDraw(const SRect &rUpdate)
{
	if (!IsVisible()) {
		return;
	}

	CPane::OnDraw(rUpdate);

	// Get the rect that the handle must occupy
	SRect rctHandle = GetHandleRect();
	switch(mType) {
		case TypeHorizontal:
			{
				// Draw left-most part
				SRect rctCur(rctHandle);
				rctCur.iCX = mpBitmapSizes[BitmapLeftTopHandle].iCX;
				rctCur.iCY = mpBitmapSizes[BitmapLeftTopHandle].iCY;
				DrawBitmap(mppBitmapRes[BitmapLeftTopHandle], rUpdate, rctCur);

				// Calculate rect for right-most part
				SRect rctRight(rctHandle);
				rctRight.iX = rctRight.iX + rctRight.iCX - mpBitmapSizes[BitmapRightDownHandle].iCX;
				rctRight.iCX = mpBitmapSizes[BitmapRightDownHandle].iCX;

				// Move position for center part
				rctCur.iX += rctCur.iCX;
				// Update with center size
				rctCur.iCX = mpBitmapSizes[BitmapCenterHandle].iCX;
				rctCur.iCY = mpBitmapSizes[BitmapCenterHandle].iCY;
				// Draw center part as many times as neccasary
				while (rctCur.iX < rctRight.iX) {
					DrawBitmap(mppBitmapRes[BitmapCenterHandle], rUpdate, rctCur);
					rctCur.iX += rctCur.iCX;
				}

				// Draw right-most part
				DrawBitmap(mppBitmapRes[BitmapRightDownHandle], rUpdate, rctRight);
			}
			break;
		case TypeVertical:
			{
				// Draw top-most part
				SRect rctCur(rctHandle);
				rctCur.iCX = mpBitmapSizes[BitmapLeftTopHandle].iCX;
				rctCur.iCY = mpBitmapSizes[BitmapLeftTopHandle].iCY;
				DrawBitmap(mppBitmapRes[BitmapLeftTopHandle], rUpdate, rctCur);

				// Calculate rect for bottom-most part
				SRect rctBottom(rctHandle);
				rctBottom.iY = rctBottom.iY + rctBottom.iCY - mpBitmapSizes[BitmapRightDownHandle].iCY;
				rctBottom.iCY = mpBitmapSizes[BitmapRightDownHandle].iCY;

				// Move position for center part
				rctCur.iY += rctCur.iCY;
				// Update with center size
				rctCur.iCX = mpBitmapSizes[BitmapCenterHandle].iCX;
				rctCur.iCY = mpBitmapSizes[BitmapCenterHandle].iCY;
				// Draw center part as many times as neccasary
				while (rctCur.iY < rctBottom.iY) {
					DrawBitmap(mppBitmapRes[BitmapCenterHandle], rUpdate, rctCur);
					rctCur.iY += rctCur.iCY;
				}

				// Draw right-most part
				DrawBitmap(mppBitmapRes[BitmapRightDownHandle], rUpdate, rctBottom);
			}
			break;
	}
}
예제 #12
0
void CColorRectTracker::Draw(CDC* pDC)
{
	// set initial DC state
	VERIFY(pDC->SaveDC() != 0);
	pDC->SetMapMode(MM_TEXT);
	pDC->SetViewportOrg(0, 0);
	pDC->SetWindowOrg(0, 0);

	// get normalized rectangle
	CRect rect = m_rect;
	rect.NormalizeRect();

	CPen* pOldPen = NULL;
	CBrush* pOldBrush = NULL;
	CGdiObject* pTemp;
	int nOldROP;
	
	CPoint ptCenter = rect.CenterPoint();
	int nCrossHairWH = rect.Width() < rect.Height() ? rect.Width()/4 : rect.Height()/4;
	if (nCrossHairWH > 20) nCrossHairWH = 20;
	if (nCrossHairWH < 4) nCrossHairWH = 0;

	// draw lines
	if ((m_nStyle & (dottedLine|solidLine)) != 0)
	{
		rect.InflateRect(+1, +1);   // borders are one pixel outside
		pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH);
		nOldROP = pDC->SetROP2(R2_COPYPEN);

		pOldPen = pDC->SelectObject( &m_WhiteBoldPen );
		pDC->Rectangle(rect.left, rect.top, rect.right, rect.bottom);
		
		if (nCrossHairWH > 0)
		{
			pDC->MoveTo(ptCenter.x-nCrossHairWH/2, ptCenter.y);
			pDC->LineTo(ptCenter.x+nCrossHairWH/2, ptCenter.y);
			pDC->MoveTo(ptCenter.x, ptCenter.y-nCrossHairWH/2);
			pDC->LineTo(ptCenter.x, ptCenter.y+nCrossHairWH/2);
		}
		
		if (m_nStyle & dottedLine)
			pDC->SelectObject(CPen::FromHandle(_afxBlackDottedPen));
		else
			pDC->SelectStockObject(BLACK_PEN);
		pDC->Rectangle(rect.left, rect.top, rect.right, rect.bottom);

		if (nCrossHairWH > 0)
		{
			pDC->MoveTo(ptCenter.x-nCrossHairWH/2, ptCenter.y);
			pDC->LineTo(ptCenter.x+nCrossHairWH/2, ptCenter.y);
			pDC->MoveTo(ptCenter.x, ptCenter.y-nCrossHairWH/2);
			pDC->LineTo(ptCenter.x, ptCenter.y+nCrossHairWH/2);
		}

		pDC->SetROP2(nOldROP);
	}

	// if hatchBrush is going to be used, need to unrealize it
	if ((m_nStyle & (hatchInside|hatchedBorder)) != 0)
		UnrealizeObject(_afxHatchBrush);

	// hatch inside
	if ((m_nStyle & hatchInside) != 0)
	{
		pTemp = pDC->SelectStockObject(NULL_PEN);
		if (pOldPen == NULL)
			pOldPen = (CPen*)pTemp;
		pTemp = pDC->SelectObject(CBrush::FromHandle(_afxHatchBrush));
		if (pOldBrush == NULL)
			pOldBrush = (CBrush*)pTemp;
		pDC->SetBkMode(TRANSPARENT);
		nOldROP = pDC->SetROP2(R2_MASKNOTPEN);
		pDC->Rectangle(rect.left+1, rect.top+1, rect.right, rect.bottom);
		pDC->SetROP2(nOldROP);
	}

	// draw hatched border
	if ((m_nStyle & hatchedBorder) != 0)
	{
		pTemp = pDC->SelectObject(CBrush::FromHandle(_afxHatchBrush));
		if (pOldBrush == NULL)
			pOldBrush = (CBrush*)pTemp;
		pDC->SetBkMode(OPAQUE);
		CRect rectTrue;
		GetTrueRect(&rectTrue);
		pDC->PatBlt(rectTrue.left, rectTrue.top, rectTrue.Width(),
			rect.top-rectTrue.top, 0x000F0001 /* Pn */);
		pDC->PatBlt(rectTrue.left, rect.bottom,
			rectTrue.Width(), rectTrue.bottom-rect.bottom, 0x000F0001 /* Pn */);
		pDC->PatBlt(rectTrue.left, rect.top, rect.left-rectTrue.left,
			rect.Height(), 0x000F0001 /* Pn */);
		pDC->PatBlt(rect.right, rect.top, rectTrue.right-rect.right,
			rect.Height(), 0x000F0001 /* Pn */);
	}

	// draw resize handles
	if ((m_nStyle & (resizeInside|resizeOutside)) != 0)
	{
		UINT mask = GetHandleMask();
		for (int i = 0; i < 8; ++i)
		{
			if (mask & (1<<i))
			{
				GetHandleRect((TrackerHit)i, &rect);
				rect.InflateRect( +1, +1, +1, +1 );
				pDC->FillSolidRect(rect, RGB(0xff, 0xff, 0xff));
				rect.DeflateRect( +1, +1, +1, +1 );
				pDC->FillSolidRect(rect, RGB(0, 0, 0));
			}
		}
	}

	// cleanup pDC state
	if (pOldPen != NULL)
		pDC->SelectObject(pOldPen);
	if (pOldBrush != NULL)
		pDC->SelectObject(pOldBrush);
	VERIFY(pDC->RestoreDC(-1));
}
예제 #13
0
 void GraphicsBase::DrawTracker()
 {
   for (int i = 1; i <= HandleCount(); ++i) {
     GetHandleRect(i).Fill();
   }
 }