Example #1
1
void CTyHMProxy::DrawDC_Vecter(CDC *pDC, CElecMapView *pView)
{
	float minx,miny,maxx,maxy;
	pView->GetFloatRect(&minx,&miny,&maxx,&maxy);
	if (!IntersectRect(minx,miny,maxx,maxy)) return;


	GetRect(&minx,&miny,&maxx,&maxy);
	CPoint pt1,pt2;
	pt1=pView->UPtoLP(minx,miny);
	pt2=pView->UPtoLP(maxx,maxy);
	CRect rt;
	rt.SetRect(pt1,pt2);
	rt.NormalizeRect();
  //DrawVector(LPCSTR vectorname,CDC* pDC,CRect viewRect,CRect clipRect,COLORREF color,BOOL blReplace)
	DrawVector(m_str1,pDC,rt,rt,m_color1,m_bTranslate1);
}
Example #2
0
void CMyRectTracker::GetTrueRect(LPRECT lpTrueRect) const
{
	ASSERT(AfxIsValidAddress(lpTrueRect, sizeof(RECT)));

	CRect rect = m_rect;
	rect.NormalizeRect();
	int nInflateBy = 0;
	if ((m_nStyle & (resizeOutside|hatchedBorder)) != 0)
		nInflateBy += GetHandleSize() - 1;
	if ((m_nStyle & (solidLine|dottedLine)) != 0)
		++nInflateBy;
	rect.InflateRect(nInflateBy, nInflateBy);
	*lpTrueRect = rect;
}
void CTextObject::_OnTextRequestResizeNotify(REQRESIZE* pReqResize)
{
	if (m_pDrawCanvas->IsCapture())
	{
		return;
	}
	//want size is device unit
	FTLASSERT(pReqResize->rc.bottom > pReqResize->rc.top);
	CRect rcWantRect = pReqResize->rc;
	m_pDrawCanvas->ClientToDoc(&rcWantRect);
	int nWantHeight = rcWantRect.Height() + RTPANEL_MARGIN_TOP + RTPANEL_MARGIN_BOTTOM;

	CSize szMin = m_pShareEditPtr->GetMinBoundSize(RTPANEL_MIN_ROW_COUNT, RTPANEL_MIN_COL_COUNT);
	if (nWantHeight < szMin.cy )
	{
		nWantHeight = szMin.cy;
	}
	BOOL bWillSetBound = FALSE;
	CRect rcPosition = m_position;
	rcPosition.NormalizeRect();

	//if (!rcTarget.IsRectEmpty())
	{
		int nOldHeight = FTL_ABS(rcPosition.Height());
		if ( nWantHeight > nOldHeight)
		{
			rcPosition.bottom = rcPosition.top + nWantHeight;
			bWillSetBound = TRUE;
		}

		int nOldWidth = FTL_ABS(rcPosition.Width());
		if (szMin.cx > nOldWidth)
		{
			rcPosition.right = rcPosition.left + szMin.cx;
			bWillSetBound = TRUE;
		}
	}
	CRect rcDrawTarget = m_pDrawCanvas->GetDrawTarget();
	rcDrawTarget.OffsetRect(-rcDrawTarget.TopLeft());

	rcPosition.IntersectRect(rcPosition, rcDrawTarget);
	if (rcPosition != m_position && bWillSetBound)
	{
		m_position = rcPosition;
		m_pShareEditPtr->SetClientBound(m_position, NULL, TRUE);
		m_pDrawCanvas->InvalObject(this);
	}
}
Example #4
0
void CFlatBrushPen::FormGraphData(UINT nMouseState, CPoint point, CRect& rcUpdate)
{
	PointF pt((float)point.x, (float)point.y);

	if(m_nPtCount == 0)
	{
		m_ptary.Add(pt);
		m_nPtCount++;
	}
	else
	{
		PointF ptf = m_ptary[m_nPtCount - 1];
		if(CalcGapOfpoints(pt, ptf) >= 3)
		{
			m_ptary.Add(pt);
			m_nPtCount++;
		}
	}

	if(m_nPtCount >= 2 && !m_bFinish)
	{
		CPoint ptLT((int)m_ptary[m_nPtCount - 1].X, (int)m_ptary[m_nPtCount - 1].Y);
		CPoint ptRB((int)m_ptary[m_nPtCount - 2].X, (int)m_ptary[m_nPtCount - 2].Y);

		rcUpdate.SetRect(ptLT, ptRB);
		rcUpdate.NormalizeRect();

		rcUpdate.InflateRect(3 * m_nWidth, 3 * m_nWidth);
	}

	if(MS_LBTNUP == nMouseState)
	{
		if(( m_nPtCount <= 1) ||
			( m_nPtCount <= 2 && 
			CalcGapOfpoints(m_ptary[0],m_ptary[1]) <= 3))
		{
			m_bDataInvalid = TRUE;
		}
		else
		{
			m_bFinish = TRUE;
			InitHotData();
			rcUpdate = m_rcHot;
		}
	}
}
void CDiagramEntity::SetRect( CRect rect )
/* ============================================================
	Function :		CDiagramEntity::SetRect
	Description :	Sets the object rect, normalized.
					
	Return :		void
	Parameters :	CRect rect	-	The rect to set.
					
	Usage :			Call to place the object.

   ============================================================*/
{

	rect.NormalizeRect();
	SetRect( ( double ) rect.left, ( double ) rect.top, ( double ) rect.right, ( double ) rect.bottom );

}
Example #6
0
void CDrawText::Draw(CDC* pDC)
{
	// skip drawing text when recording EMF
	if (CDrawView::m_IsRecording)	return;

	ASSERT_VALID(this);

	// use brush of paper color
	CBrush *brush=new CBrush;
	brush->CreateSolidBrush(m_pDocument->GetPaperColor());
	pDC->SelectObject(brush);

	int i;
	if (pDC->IsPrinting()) 
		i=1;
	i++;

	CRect rect = m_position;
	if (!pDC->IsPrinting() && !CDrawView::m_IsRecording && CDrawOleObj::c_bShowItems)
		pDC->Rectangle(rect);

	pDC->LPtoDP(rect);
	rect.NormalizeRect();
	rect.InflateRect(-4,-4);			// for border, TENTATIVE
	pDC->DPtoLP(rect);

	CRect trect;
	// for the logical coordinates used in the project
	trect.left   = min(rect.left, rect.right);
	trect.top    = max(rect.top, rect.bottom);
	trect.right  = max(rect.left, rect.right);
	trect.bottom = min(rect.top, rect.bottom);

	CFont* poldfont=pDC->SelectObject(m_pfont);
	TEXTMETRIC tm;
	pDC->GetTextMetrics(&tm); 
	if (tm.tmHeight!=m_lf.lfHeight) 
		AfxGetMainWnd()->MessageBox("display font unmatch logfont");

	pDC->SetTextColor(m_color);
	pDC->SetBkColor(m_pDocument->GetPaperColor());
					
	pDC->DrawText(m_text,-1,&trect,DT_WORDBREAK|AlignTable[m_align].drawstyle);
	pDC->SelectObject(poldfont);	// restore font, esp for preview, force mirrorfont()
}
Example #7
0
void CTyHMProxy::DrawDC_Bmp(CDC *pDC, CElecMapView *pView)
{
	float minx,miny,maxx,maxy;
	pView->GetFloatRect(&minx,&miny,&maxx,&maxy);
	if (!IntersectRect(minx,miny,maxx,maxy)) return;


	GetRect(&minx,&miny,&maxx,&maxy);
	CPoint pt1,pt2;
	pt1=pView->UPtoLP(minx,miny);
	pt2=pView->UPtoLP(maxx,maxy);
	CRect rt;
	rt.SetRect(pt1,pt2);
	rt.NormalizeRect();
  
	DrawImage(m_str1,pDC,pt1.x,pt1.y,rt.Width(),rt.Height(),m_bTranslate1,m_color1);

}
Example #8
0
// returns center of handle in logical coordinates
CPoint CDrawRect::GetHandle(int nHandle)
{
	ASSERT_VALID(this);

	if (m_nShape == line && nHandle == 2)
		nHandle = 5;
	else if (m_nShape == roundRectangle && nHandle == 9)
	{
		CRect rect = m_position;
		rect.NormalizeRect();
		CPoint point = rect.BottomRight();
		point.x -= m_roundness.x / 2;
		point.y -= m_roundness.y / 2;
		return point;
	}

	return CDrawObj::GetHandle(nHandle);
}
BOOL CTextObject::HitTestMove(CPoint point)
{
	CRect rcDevice = m_position;
	m_pDrawCanvas->DocToClient(&rcDevice);
	rcDevice.NormalizeRect();
	if (rcDevice.PtInRect(point))
	{
		//CRect rect = m_position;
		if ( abs(rcDevice.left - point.x) <= TRACK_MARGIN
			|| abs(rcDevice.top - point.y) <= TRACK_MARGIN 
			|| abs(rcDevice.right - point.x) <= TRACK_MARGIN
			|| abs(rcDevice.bottom - point.y) <= TRACK_MARGIN 
			)
		{
			return TRUE;
		}
	}
	return FALSE;
}
Example #10
0
void LTArrowMarking::OnMouseMove( CDC* pdcAct, CPoint pt, CPoint ptOffset )
{
	CRect rErase = r_Rect;
	rErase.NormalizeRect();
	rErase.InflateRect(i_Width * 3, i_Width * 3);

	CDC* pDC = p_Screenshot->GetDC();
	int i = pdcAct->SaveDC();

	// Erase early ones
	pdcAct->BitBlt(rErase.left, rErase.top, rErase.Width(), rErase.Height(), pDC,
		rErase.left + ptOffset.x, rErase.top + ptOffset.y, SRCCOPY);

	r_Rect.SetRect(r_Rect.TopLeft(), pt);

	DrawArrow(pdcAct, r_Rect);

	pdcAct->RestoreDC(i);
}
Example #11
0
//------------------------------------------------------------------------
//FUNCTION: BoundRect
//Find out bounding rectangle of ellipse given both extremes of main axis
//and value of b parameter.
void BoundRect(CPoint P1,CPoint P2,int b,CRect& bRect){
	
	CPoint vector=CPoint(P2.x-P1.x,P2.y-P1.y);	

	float vector_mod=sqrt((double)(vector.x*vector.x+vector.y*vector.y));


	float vector_x=vector.x*b/vector_mod;
	float vector_y=vector.y*b/vector_mod;

	CPoint point1=CPoint(P1.x-vector_y,P1.y+vector_x);
	CPoint point2=CPoint(P2.x+vector_y,P2.y-vector_x);


	bRect=CRect(point1,point2);

	bRect.NormalizeRect();
	
}
BOOL CNCaptureView::_SetSelectRectClipInfo(const CPoint& point)
{
	BOOL bRet = FALSE;
	CDrawTool* pCurDrawTools = CDrawCanvas<CNCaptureView>::GetCurrentTool();
	if (pCurDrawTools->IsNeedClip())
	{
		if(!GetSelection().empty())
		{
			CDrawObject* pActiveDrawObject = GetSelection().front();
			if (pActiveDrawObject)
			{
				m_bClipCursor = TRUE;
				CRect rcSelect = pActiveDrawObject->GetPosition();
				rcSelect.NormalizeRect();
				DocToClient(&rcSelect);

				CRect rcClipTarget = m_rcDrawTarget;
				rcClipTarget.OffsetRect( -rcClipTarget.TopLeft());
				DocToClient(&rcClipTarget);
				ClientToScreen(&rcClipTarget);

				if (smMove == m_nCurrentSelectMode )
				{
					rcClipTarget.right -= rcSelect.Width() ;
					rcClipTarget.bottom -= rcSelect.Height();
					rcClipTarget.OffsetRect(point.x - rcSelect.left, point.y - rcSelect.top);
				}
				else if(smSize == m_nCurrentSelectMode)// || smNetSelectSize == m_nCurrentSelectMode)
				{
					//now do nothing
				}
				rcClipTarget.right += 1;
				rcClipTarget.bottom += 1;

				//FTLTRACE(TEXT("rcClipTarget= [%d,%d], [%d,%d], {%dx%d}\n"), rcClipTarget.left, rcClipTarget.top,
				//	rcClipTarget.right, rcClipTarget.bottom, 
				//	rcClipTarget.Width(), rcClipTarget.Height());
				API_VERIFY(::ClipCursor(&rcClipTarget));
			}
		}
	}
	return bRet;
}
void CWeekTimePicker::UpdateRectArea(HDC hdc, int nWeekIndex)
{
	SetBkMode(hdc, TRANSPARENT);
	FillRect(hdc, &m_vecWeekDayBarRect[nWeekIndex], (HBRUSH)m_brushBarBack.GetSafeHandle());
	
	auto &vecDayRects = m_vecWeekDayBarSelectedRect[nWeekIndex].vecDayRects;
	for (size_t n=0; n<vecDayRects.size(); ++n)
	{
		FillRect(hdc, &vecDayRects[n], (HBRUSH)m_brushBarSelect.GetSafeHandle());
	}

	if (m_nDragBarIndex == nWeekIndex && m_rcDragRect.Width())
	{
		FillRect(hdc, &m_rcDragRect, (HBRUSH)m_brushBarDrag.GetSafeHandle());
		CRect rcText = m_rcDragRect;
		rcText.NormalizeRect();
		RectToTime(m_nDragBarIndex, rcText, m_timeValue.cstrBeginTime, m_timeValue.cstrEndTime);
		DWORD flag = DT_CENTER;
		if (rcText.Width() < 80)
		{
			rcText.InflateRect((80-rcText.Width())/2, 0);
		}
		if (rcText.left < m_vecWeekDayBarRect[nWeekIndex].left)
		{
			rcText.left = m_vecWeekDayBarRect[nWeekIndex].left;
			rcText.right = rcText.left + 80;
			flag = DT_LEFT;
		}
		else if (rcText.right > m_vecWeekDayBarRect[nWeekIndex].right)
		{
			rcText.right = m_vecWeekDayBarRect[nWeekIndex].right;
			rcText.left = rcText.right - 80;
			flag = DT_RIGHT;
		}
		m_timeValue.cstrBeginTime += _T("-");
		m_timeValue.cstrBeginTime += m_timeValue.cstrEndTime;
		DrawText(hdc, m_timeValue.cstrBeginTime, -1, &rcText, DT_SINGLELINE|flag|DT_VCENTER);
		m_timeValue.cstrBeginTime.Empty();
		m_timeValue.cstrEndTime.Empty();
	}
}
Example #14
0
/*=============================================================================
*NAME		:TYSIniFile::ReadRect
			:
*MODULE		:YSIniFiles.cpp
			:
*FUNCTION	:四角形構造体読み込み処理関数です
			:
*PROCESS	:・四角形構造体読み込み処理です。
			:
*INPUT		:const CString section	:セクション名
*INPUT		:const CString iname	:Ident名
*INPUT		:const CRect* rect		:四角形構造体ポインタ
			:
*RETURN		:値
			:
*PROGRAMMED	:Y.Sasai
*HISTORY	:
*ID -- DATE ------- NOTE ------------------------------------------------------
*00 03.02.12 Y.Sasai Ver.0.90 初期作成
*/
CRect TYSIniFile::ReadRect( const CString section, const CString iname, const CRect* rect )
{
	CRect defrect;																				// 2003.02.12 Y.Sasai Ver.0.90 初期値
	CRect result;																				// 2003.02.12 Y.Sasai Ver.0.90 終了値

	if ( rect != NULL ) {																		// 2003.02.12 Y.Sasai Ver.0.90 デフォルト設定があるなら…
		defrect = *rect;																		// 2003.02.12 Y.Sasai Ver.0.90 座標設定
	} else {																					// 2003.02.12 Y.Sasai Ver.0.90 デフォルトがないなら…
		defrect.left = 0;																		// 2003.02.12 Y.Sasai Ver.0.90 初期化だ
		defrect.top = 0;																		// 2003.02.12 Y.Sasai Ver.0.90 初期化だ
		defrect.right = 0;																		// 2003.02.12 Y.Sasai Ver.0.90 初期化だ
		defrect.bottom = 0;																		// 2003.02.12 Y.Sasai Ver.0.90 初期化だ
	}

	result.left = ReadInteger( section, iname + LeftIdent, defrect.left );						// 2003.02.12 Y.Sasai Ver.0.90 左座標読み込み
	result.top = ReadInteger( section, iname + TopIdent, defrect.top );							// 2003.02.12 Y.Sasai Ver.0.90 上座標読み込み
	result.right = ReadInteger( section, iname + RightIdent, defrect.right );					// 2003.02.12 Y.Sasai Ver.0.90 右座標読み込み
	result.bottom = ReadInteger( section, iname + BottomIdent, defrect.bottom );				// 2003.02.12 Y.Sasai Ver.0.90 下座標読み込み
	result.NormalizeRect();																		// 2003.02.12 Y.Sasai Ver.0.90 四角形の正規化

	return ( result );																			// 2003.02.12 Y.Sasai Ver.0.90 おわりだ
}
void CTyStationAssistPng::DrawDC(CDC *pDC, CElecMapView *pView)
{
	try
	{
		ASSERT(pDC != NULL);
		ASSERT(pView != NULL);

		if (pDC == NULL||pView == NULL)
			return;

		if(m_bDelete)	//如果已经处于删除状态
			return;

		float minx,miny,maxx,maxy;
		pView->GetFloatRect(&minx,&miny,&maxx,&maxy);
		if (!IntersectRect(minx,miny,maxx,maxy))
			return;

		GetRect(&minx,&miny,&maxx,&maxy);

		CPoint pt1,pt2;
		pt1 = pView->UPtoLP(minx,miny);
		pt2 = pView->UPtoLP(maxx,maxy);

		CRect rt;
		rt.SetRect(pt1,pt2);
		rt.NormalizeRect();

		if ((rt.Width() < 1)||(rt.Height() < 1))
			return;

		g_ImagePngMapX.DrawImagePng(m_szPngName,pDC->m_hDC,pt1.x,pt1.y,rt.Width(),rt.Height(),pt1.x,pt1.y,rt.Width(),rt.Height(),m_fRotateAngle,SRCCOPY);
	}
	catch(...)
	{

	}
}
Example #16
0
BOOL CGlobalObj::bGetDefaultValue(eCONFIGDETAILS eParam, WINDOWPLACEMENT& sPosition)
{
    BOOL bSizeFound = TRUE;
    CRect omMainFrameSize;
    // Get Main Frame Size
    GetClientRect( sm_hWndMDIParentFrame, &omMainFrameSize );
    omMainFrameSize.NormalizeRect();
    switch( eParam )
    {
        case OUT_WND_PLACEMENT:
        {
            CRect omRect = omMainFrameSize;
            omRect.top   += static_cast<LONG> ( omRect.Height() *
                                                defCHILD_FRAME_PROP_H );
            omRect.right -= static_cast<LONG> ( omRect.right *
                                                defOUTPUT_WND_PROP_X );
            sPosition.rcNormalPosition = omRect;
            /*sPosition.rcNormalPosition.top -= 2 * omToolBarRect.Height();
            sPosition.rcNormalPosition.bottom -= 2 * omToolBarRect.Height();*/
        }
        break;
        case SIMSYS_WND_PLACEMENT:
        {
            CRect omRect = omMainFrameSize;
            // Reduce the size propotionally
            omRect.bottom -= (LONG)(omRect.Height() * defTX_SIM_WND_BOTTOM_MARGIN);
            omRect.right -= (LONG)(omRect.Width() * defTX_SIM_WND_RIGHT_MARGIN);
            // Update the size
            sPosition.rcNormalPosition = omRect;
        }
        break;
        default:
            ASSERT( FALSE );
            bSizeFound = FALSE;
            break;
    }
    return bSizeFound;
}
Example #17
0
void CRectTracker::DrawTrackerRect(
	LPCRECT lpRect, CWnd* pWndClipTo, CDC* pDC, CWnd* pWnd)
{
	// first, normalize the rectangle for drawing
	CRect rect = *lpRect;
	rect.NormalizeRect();

	// convert to client coordinates
	if (pWndClipTo != NULL)
	{
		pWnd->ClientToScreen(&rect);
		pWndClipTo->ScreenToClient(&rect);
	}

	CSize size(0, 0);
	if (!m_bFinalErase)
	{
		// otherwise, size depends on the style
		if (m_nStyle & hatchedBorder)
		{
			size.cx = size.cy = max(1, GetHandleSize(rect)-1);
			rect.InflateRect(size);
		}
		else
		{
			size.cx = CX_BORDER;
			size.cy = CY_BORDER;
		}
	}

	// and draw it
	if (m_bFinalErase || !m_bErase)
		pDC->DrawDragRect(rect, size, m_rectLast, m_sizeLast);

	// remember last rectangles
	m_rectLast = rect;
	m_sizeLast = size;
}
CRect CNCaptureView::_GetSelectRect(const CPoint& ptLogical)
{
	CRect rcSelect;
	rcSelect.SetRectEmpty();

	//already has select rect
	DrawObjectList& drawObjList = GetSelection();
	if (drawObjList.size() == 1)
	{
		CDrawObject* pDrawObj = drawObjList.front();
		FTLASSERT(pDrawObj);
		if (dotSelectRect == pDrawObj->GetDrawObjType())
		{
			rcSelect = pDrawObj->GetPosition();
			if (!rcSelect.PtInRect(ptLogical) && !IsCapture())
			{
				rcSelect.SetRectEmpty();
			}
		}
	}
	else
	{
		if (IsCapture())
		{
			rcSelect.SetRect(GetMouseDownLogicalPoint(), GetMouseLastLogicalPoint());
			rcSelect.NormalizeRect();
		}
	}

	CRect rcImage(0, 0, m_pImage->GetWidth(), m_pImage->GetHeight());
	rcSelect.IntersectRect(rcSelect, rcImage);

	//FTLTRACE(TEXT("ptLogical=[%d,%d], rcSelect=[%d,%d]-[%d,%d]\n"),
	//	ptLogical.x, ptLogical.y , rcSelect.left, rcSelect.top, rcSelect.right, rcSelect.bottom);

	return rcSelect;
}
// 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;
}
int CPage_Node_Lane::FindClickedLink(CPoint pt,bool bOriginAngle /* = true */)
{
	int nRtLinkID = -1;
	for(int j=0;j<m_LinkData.size();j++)
	{
		LinkRecord* pRecord = m_LinkData[j];
		GDPoint cntPoint,lefttop,bottomright;
		CRect centerRect;
		int nR5 = m_Para.nR5;
		int nDis = m_Para.nLaneWidth;
		double theta = bOriginAngle ? pRecord->dTheta : pRecord->dNormTheta;
		int i = (pRecord->nChnlNum+pRecord->nLaneNum+pRecord->nPcktNum + 1) / 2 ;

		if ( pRecord->nIO == 1)
		{
			nDis = -1 * nDis;
		}
		cntPoint.x	= nR5 * cos(theta) + i * nDis * cos(theta-PI/2.0f);
		cntPoint.y	= nR5 * sin(theta) + i * nDis * sin(theta-PI/2.0f);
		
		int nRadius2 = m_Para.nPinPointRadius;
		lefttop.x = cntPoint.x - nRadius2;
		lefttop.y = cntPoint.y - nRadius2;
		bottomright.x = cntPoint.x + nRadius2;
		bottomright.y = cntPoint.y + nRadius2;
		
		centerRect = CRect(NPtoSP(lefttop),NPtoSP(bottomright));
		centerRect.NormalizeRect();
		if ( centerRect.PtInRect(pt) )
		{
			nRtLinkID = pRecord->nLinkID;
			break;
		}
	}
	return nRtLinkID;
}
Example #21
0
void CLayoutZoomoutTool::LButtonDownEvent (UINT nFlags, CPoint point)
{
	if(!m_pLayoutCtrl)
		return;


	if(!m_pLayoutCtrl->GetPageLayout())
		return;


	//Selection Box
	CRectTracker selectBox = CRectTracker(CRect(0,0,0,0),
		CRectTracker::solidLine +
		CRectTracker::resizeOutside );

	selectBox.m_sizeMin = 0;

	bool selected = selectBox.TrackRubberBand(dynamic_cast<CWnd*>(m_pLayoutCtrl), point, FALSE );

	CRect rect = selectBox.m_rect;
	rect.NormalizeRect();

	if( ( rect.BottomRight().x - rect.TopLeft().x ) < 10 &&
		( rect.BottomRight().y - rect.TopLeft().y ) < 10 )
		selected = false;

	
	if( selected == true )
	{
		GEOMETRY::geom::Envelope envelop;
		m_pLayoutCtrl->GetPageLayout()->GetDisplay()->GetDisplayTransformation().GetGeoBound(envelop);

		long lWidth = rect.Width();
		long lHeight = rect.Height();

		double rx = envelop.getWidth()/ lWidth;
		double ry = envelop.getHeight()/ lHeight;

		double dbScale = (rx > ry) ? rx : ry;

		m_pLayoutCtrl->GetPageLayout()->GetDisplay()->GetDisplayTransformation().ZoomToFixScale(dbScale);

		CRect viewRect =m_pLayoutCtrl->GetPageLayout()->GetDisplay()->GetDisplayTransformation().GetViewBound().GetRect();

		double dx=(rect.CenterPoint().x-viewRect.CenterPoint().x)*dbScale;
		double dy=(viewRect.CenterPoint().y-rect.CenterPoint().y)*dbScale;

		m_pLayoutCtrl->GetPageLayout()->GetDisplay()->GetDisplayTransformation().MoveViewBound(dx,dy);

	}
	else
	{
		double geoCenterX, geoCenterY;
		m_pLayoutCtrl->GetPageLayout()->GetDisplay()->GetDisplayTransformation().ConvertDisplayToGeo(point.x,point.y,geoCenterX, geoCenterY);
		m_pLayoutCtrl->GetPageLayout()->GetDisplay()->GetDisplayTransformation().SetGeoCenterX(geoCenterX);
		m_pLayoutCtrl->GetPageLayout()->GetDisplay()->GetDisplayTransformation().SetGeoCenterY(geoCenterY);
		m_pLayoutCtrl->GetPageLayout()->GetDisplay()->GetDisplayTransformation().ZoomViewPosScale(1.5);
	}
	m_pLayoutCtrl->UpdateControl(drawAll);

	
}
Example #22
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));
}
Example #23
0
USAGEMODE HRESULT TXFlexRay_vShowConfigureMsgWindow(void* pParentWnd)
{
    //Place this code at the beginning of the export function.
    //Save previous resource handle and switch to current one.
    HINSTANCE hInst = AfxGetResourceHandle();
    AfxSetResourceHandle(TXFlexRayWindowDLL.hResource);
    //AFX_MANAGE_STATE(AfxGetStaticModuleState());

    if( g_pomTxMsgFlexChildWindow == NULL )
    {
        // Create New Instance
        g_pomTxMsgFlexChildWindow = new CTxMsgFlexChildFrame;
        if( g_pomTxMsgFlexChildWindow != NULL )
        {
            //// Register Window Class
            LPCTSTR strMDIClass = AfxRegisterWndClass(
                                      CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS,
                                      LoadCursor(NULL, IDC_CROSS), 0,
                                      ::LoadIcon(NULL, MAKEINTRESOURCE(IDI_ICO_SEND_MSG)) );

            // Set the size got from configuration module
            WINDOWPLACEMENT sTxWndPlacement;
            SetDefaultWindowPos(sTxWndPlacement);
            WINDOWPLACEMENT* psTxWndPlacement = &sTxWndPlacement;
            CTxFlexRayDataStore::ouGetTxFlexRayDataStoreObj().bGetTxData(TX_WINDOW_PLACEMENT, (void**)&psTxWndPlacement);
            if (sTxWndPlacement.rcNormalPosition.top == -1 ||
                    sTxWndPlacement.length == 0)//Load default configuration
            {
                CRect omRect;
                CWnd* pWnd = (CWnd*)pParentWnd;
                pWnd->GetClientRect(&omRect);
                omRect.NormalizeRect();
                //    // Reduce the size propotionally
                omRect.bottom -= (LONG)(omRect.Height() * defTX_MSG_WND_BOTTOM_MARGIN);
                omRect.right -= (LONG)(omRect.Width() * defTX_MSG_WND_RIGHT_MARGIN);
                //    // Update the size
                //sTxWndPlacement.rcNormalPosition = omRect;

                sTxWndPlacement.flags = 1;
                sTxWndPlacement.length = 44;
                sTxWndPlacement.ptMaxPosition.x = 0;
                sTxWndPlacement.ptMaxPosition.x = 0;
                sTxWndPlacement.ptMinPosition.x = 0;
                sTxWndPlacement.ptMinPosition.y = 0;
                sTxWndPlacement.rcNormalPosition.top = 1;
                sTxWndPlacement.rcNormalPosition.bottom = 661;
                sTxWndPlacement.rcNormalPosition.left = 4;
                sTxWndPlacement.rcNormalPosition.right = 864;
                sTxWndPlacement.showCmd = 1;
            }
            CRect omRect(&(sTxWndPlacement.rcNormalPosition));

            // Create Tx Message Configuration window
            //CRect omRect(0,0,200,200);
            if( g_pomTxMsgFlexChildWindow->Create( strMDIClass,
                                                   "Configure Transmission Messages - FLEXRAY",
                                                   WS_CHILD | WS_OVERLAPPEDWINDOW,
                                                   omRect, (CMDIFrameWnd*)pParentWnd ) == TRUE )
            {
                // Show window and set focus
                g_pomTxMsgFlexChildWindow->ShowWindow( SW_SHOW);
                g_pomTxMsgFlexChildWindow->SetFocus();
                if (sTxWndPlacement.rcNormalPosition.top != -1 &&
                        sTxWndPlacement.length != 0)
                {
                    g_pomTxMsgFlexChildWindow->SetWindowPlacement(&sTxWndPlacement);
                }

            }
        }
        else
        {
            return S_FALSE;
        }
    }
    // If already exist then activate and set the focus
    else
    {
        g_pomTxMsgFlexChildWindow->ShowWindow( SW_RESTORE );
        g_pomTxMsgFlexChildWindow->MDIActivate();
        g_pomTxMsgFlexChildWindow->SetActiveWindow();
    }
    //Place this at the end of the export function.
    //switch back to previous resource handle.
    //   CWnd objParent;
    //objParent.Attach(((CWnd*)pParentWnd)->m_hWnd);

    //objParent.Detach();

    AfxSetResourceHandle(hInst);
    return S_OK;
}
void CSliderCtrlEx::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult) 
{
	int loopMax = colorList.GetSize();	// number of color ranges to process
	LPNMCUSTOMDRAW lpCustDraw = (LPNMCUSTOMDRAW)pNMHDR;

	////////////////////////////////////////////////////////////////////////////////
	// OnCustomDraw() is called at many different stages during the painting process
	// of the control. We only care about the PREPAINT state or the ITEMPREPAINT
	// state and not always then.
	//
	// If we want to be notified about subcontrol painting, we have to say so when
	// we get the initial PREPAINT message.
	////////////////////////////////////////////////////////////////////////////////
	if(lpCustDraw->dwDrawStage == CDDS_PREPAINT)
	{
		// should we report slider's position?
		int curVal = GetPos();
		if((m_Callback != NULL)	&& (curVal != m_oldPosition))
		{
			m_oldPosition = curVal;
			m_Callback(m_p2Object, m_data1, curVal, m_IsDragging);
		}

		// If we don't have any special coloring to do, skip all the silliness...
		if(loopMax <= 0)
		{
			*pResult = CDRF_DODEFAULT;
		}
		else
		{
			// We want to be informed when each part of the control is being
			// processed so we can intercept the channel drawing.
			*pResult = CDRF_NOTIFYITEMDRAW;	// send messages for each piece-part
		}
		return;
	}


	///////////////////////////////////////////////////////////////////////////////
	// A slider (track control) is drawn in several steps:
	//	1. Erase
	//	2. Tics
	//	3. Channel
	//	4. Thumb
	//
	// It would be nice to capture when the background has been painted and
	// before the other sub-pieces have been painted. Then we could just
	// substitute our own painting routine. But this doesn't seem to be
	// available.
	//
	// So this routine captures the tics by inserting operations before
	// painting the thumb.
	//
	// Look at the help on NMCUSTOMDRAW for complete details, but the pNMHDR
	// pointer looks at a structure like:
	//
	// typedef struct tagNMCUSTOMDRAWINFO {
    //	 NMHDR  hdr;
    //	 DWORD  dwDrawStage;	// This indicates what stage of the drawing process is involved
    //	 HDC    hdc;			// graphics context of the control (or sub-component)
    //	 RECT   rc;
    //	 DWORD  dwItemSpec;	// This is the particular piece-part of the slider involved
    //	 UINT   uItemState;
    //	 LPARAM lItemlParam;
	// } NMCUSTOMDRAW
	//
	// The stages include CDDS_PREPAINT, which is just before painting of the entire
	// control. However, unless the *pResult parameter is set to CDRF_NOTIFYITEMDRAW,
	// we will get notification for the control as a whole, not for each piece-part.
	// So the first thing to do is set *pResult. Thereafter, we must intercept
	// the sub-parts.
	//
	// We don't care about painting the background (we will re-paint later on). We
	// don't care about PREPAINT on the CHANNEL or the TICS since we will overwrite
	// everything when we get to the THUMB.
	/////////////////////////////////////////////////////////////////////////////////

	if((lpCustDraw->dwDrawStage == CDDS_ITEMPREPAINT) && (lpCustDraw->dwItemSpec != TBCD_THUMB))
	{
		*pResult = CDRF_DODEFAULT;
		return;
	}

	// get channel orientation
	BOOL IsVertical = (TBS_VERT & GetStyle()) ? TRUE : FALSE;

	// Get the coordinates of the control's window
	CRect crect;
	GetClientRect(crect);	// client coordinates (top = left = 0, bottom = height, right = width)

	// Much of this is "paraphrased" from Nic Wilson's work -- see the header file
	//////////////////////////////////////////////////////////////////////////////////
	// This bit does the tics marks transparently.
	// Create a memory dc to hold a copy of the oldbitmap data that includes the tics,
	// because when we add the background in we will lose the tic marks.
	///////////////////////////////////////////////////////////////////////////////////
	CDC *pDC = CDC::FromHandle(lpCustDraw->hdc);
	CDC SaveCDC;
	CBitmap SaveCBmp;

	//set the colours for the monochrome mask bitmap
	COLORREF crOldBack = pDC->SetBkColor(RGB(0,0,0));			// set to Black
	COLORREF crOldText = pDC->SetTextColor(RGB(255,255,255));	// set to White

	int iWidth  = crect.Width();	// channel width
	int iHeight = crect.Height();	// channel height

	////////////////////////////////////////////////////////////////////////////
	// Create an in-memory copy of displayed bitmap, including the tics.
	// This is a monochrome bitmap since it was created from a memory DC.
	// If it had been created from pDC (an actual device DC, not a memory
	// DC) then this would be something with 8, 16, 24, or 32 bits per pixel.
	//
	// This will have a black background, with the tic marks in white.
	//
	// For reasons I don't yet understand, this saves only the tic marks and
	// the channel's centerline (both originally in black), and not the other
	// colors (such as drawn AROUND the channel's centerline). I am not sure
	// what would have happened if the tic marks were not black...
	////////////////////////////////////////////////////////////////////////////
	SaveCDC.CreateCompatibleDC(pDC);
	SaveCBmp.CreateCompatibleBitmap(&SaveCDC, iWidth, iHeight);
	CBitmap* SaveCBmpOld = (CBitmap *)SaveCDC.SelectObject(SaveCBmp);
	SaveCDC.BitBlt(0, 0, iWidth, iHeight, pDC, crect.left, crect.top, SRCCOPY);

	if(m_dumpBitmaps)	// debugging stuff
	{
		SaveBitmap("MonoTicsMask.bmp",SaveCBmp);
	}

	// Do as much of this stuff in memory as possible, then blit it to the screen
	CDC memDC;
	memDC.CreateCompatibleDC(pDC);
	CBitmap memBM;
	memBM.CreateCompatibleBitmap(pDC,iWidth,iHeight);	// create from pDC, not memDC
	CBitmap *oldbm = memDC.SelectObject(&memBM);

	////////////////////////////////////////////////////////////////////////////////
	// copy screen bitmap to memory bitmap for manipulation. If this is the very
	// first time the control has been updated, the screen bitmap will show only
	// the tic marks (in black) and the default background color (RGB(214,207,189)).
	// If the control has been updated before, remnants of the previously drawn
	// background color ranges will also show up.
	////////////////////////////////////////////////////////////////////////////////
	memDC.BitBlt(0,0,iWidth,iHeight,pDC,0,0,SRCCOPY);

	if(m_dumpBitmaps)	// debugging
	{
		SaveBitmap("ScrnStart.bmp",memBM);
	}

	/////////////////////////////////////////////////////////////////////////////
	// Color parts of the channel if necessary. It SHOULD be necessary since we
	// don't get notifications unless there are colors to print, but we may have
	// a race condition and it is best to check.
	/////////////////////////////////////////////////////////////////////////////
	if(loopMax)
	{
		/////////////////////////////////////////////////////////////////////////////////
		// We need to draw colors over the subrange of the channel that the center of the
		// thumb traverses, rather than the entire client window. Later on, extend these
		// colors outwards to the ends of the client window (for nicer appearance). This
		// allows for more precise correlation with color and thumb position.
		/////////////////////////////////////////////////////////////////////////////////
		CRect chanRect;
		GetChannelRect(&chanRect);
		CRect thmbRect;
		GetThumbRect(&thmbRect);

		// For unknown reasons, GetChannelRect() returns a rectangle
		// as though it were a horizonally oriented slider, even if it isn't!
		if(IsVertical)
		{
			CRect n;	// could probably just change chanRect directly
			n.left = chanRect.top;
			n.right = chanRect.bottom;
			n.top = chanRect.left;
			n.bottom = chanRect.right;
			n.NormalizeRect();
			chanRect.CopyRect(&n);
		}

		// Offset into client rectangle for beginning of coloring range
		int Offset = chanRect.left + thmbRect.Width()/2;
		if(IsVertical)
		{
			Offset = chanRect.top + thmbRect.Height()/2;
		}

		// Range for center of thumb on the channel
		int ht = chanRect.Height() - thmbRect.Height();
		int wd = chanRect.Width()  - thmbRect.Width();

		// scaling between control range and bitmap
		int min,max;
		GetRange(min,max);	// range of values for the slider
		double scale = (double(max) - double(min))/double(IsVertical ? ht : wd);

		BOOL gotStartColor = FALSE;
		BOOL gotEndColor = FALSE;
		COLORREF startColor = 0, endColor = 0;

		int loop;	// Loop through the array of color ranges
		for(loop = 0; loop < loopMax; loop++)
		{
			clrRange clr;
			clr = colorList[loop];
			
			// Get the good values. If not set, then entire range is good
			int lval = clr.lval;
			int hval = clr.hval;
			if((lval < min) || (lval > max)) lval = min;
			if((hval > max) || (hval < min)) hval = max;

			if(lval == min)
			{
				gotStartColor = TRUE;
				startColor = clr.strColor;
			}
			if(hval == max)
			{
				gotEndColor = TRUE;
				endColor = clr.endColor;
			}

			int minVal = lval - min;	// offset into bitmap for this color
			minVal = int(double(minVal)/scale);

			// width (or height for vertical slider) inside bitmap for this color
			int widthVal = hval - lval;
			widthVal = int((double(widthVal)/scale) + 1.0);			
			
			// For drawing a gradient, we need to know the individual RGB values
			int sR,eR,sG,eG,sB,eB;	// start and end R, G, and B values
			sR = GetRValue(clr.strColor);
			eR = GetRValue(clr.endColor);
			sG = GetGValue(clr.strColor);
			eG = GetGValue(clr.endColor);
			sB = GetBValue(clr.strColor);
			eB = GetBValue(clr.endColor);

			if(GradientFill != NULL)
			{
				TRIVERTEX vert[2];	// for specifying range to gradient fill
				GRADIENT_RECT gRect;

// Warning C4244: conversion from 'int' to 'unsigned short', possible loss of data
#pragma warning (push)
#pragma warning (disable : 4244)
				vert[0].Red   = sR<<8;	// expects 16-bit color values!
				vert[0].Green = sG<<8;
				vert[0].Blue  = sB<<8;
				vert[0].Alpha = 0;		// no fading/transparency
				
				vert[1].Red   = eR<<8;
				vert[1].Green = eG<<8;
				vert[1].Blue  = eB<<8;
				vert[1].Alpha = 0;
#pragma warning (pop)

				gRect.UpperLeft = 0;
				gRect.LowerRight = 1;
				
				BOOL retval;
				if(IsVertical)	// vertically oriented?
				{
					vert[0].x = 0;
					vert[0].y = Offset + minVal;
					vert[1].x = iWidth;
					vert[1].y = Offset + minVal + widthVal;
					retval = GradientFill(memDC,vert,2,&gRect,1,GRADIENT_FILL_RECT_V);
				}
				else
				{
					vert[0].x = Offset + minVal;
					vert[0].y = 0;
					vert[1].x = Offset + minVal + widthVal;
					vert[1].y = iHeight;
					retval = GradientFill(memDC,vert,2,&gRect,1,GRADIENT_FILL_RECT_H);
				}
			}
			else
			{
				// Homebrew version of GradientFill for rectangles -- works pretty well, sort of.
				int i;
				for(i = 0; i < widthVal; i++)	// for each pixel column in bitmap color range
				{
					int R = sR;
					int G = sG;
					int B = sB;
					if(widthVal)
					{
						R += ::MulDiv(eR - sR, i, widthVal);
						G += ::MulDiv(eG - sG, i, widthVal);
						B += ::MulDiv(eB - sB, i, widthVal);
					}

					if(IsVertical)
					{
						// widthVal really refers to height
						//memDC.FillSolidRect(0,minVal+i,iWidth,widthVal-i,GetNearestColor(memDC,RGB(R,G,B)));
						memDC.FillSolidRect(
							0,						// starting X value
							Offset + minVal + i,	// starting Y value
							iWidth,					// full width
							1,						// one pixel height
							GetNearestColor(memDC,RGB(R,G,B)));
					}
					else
					{
						//memDC.FillSolidRect(minVal+i,0,widthVal-i,iHeight,GetNearestColor(memDC,RGB(R,G,B)));
						memDC.FillSolidRect(
							Offset + minVal + i,	// Starting X value
							0,						// Starting Y value
							1,						// 1 pixel wide
							iHeight,				// full height
							GetNearestColor(memDC,RGB(R,G,B)));
					}
				}
			}
		}

		if(m_extendColors)
		{
			// If we have put in colors at the slider ends, then extend those same
			// colors to the rest of the background. We could try to determine the
			// colors by examining the bitmap, but this is awkward and it is just
			// as easy to grab them on-the-fly in the coloring loop above.
			//
			// If you want to see why this is done, just set m_extendColors to FALSE
			// and take a look at the control. Ugly. But there might be a legitimate
			// reason for it so leave the option to suppress.
			if(IsVertical)
			{
				if(gotStartColor)
				{
					memDC.FillSolidRect(0, 0, iWidth, Offset, startColor);
				}
				if(gotEndColor)
				{
					memDC.FillSolidRect(0, iHeight - Offset - 1, iWidth, Offset, endColor);
				}
			}
			else
			{
				if(gotStartColor)
				{
					memDC.FillSolidRect(0, 0, Offset, iHeight, startColor);
				}
				if(gotEndColor)
				{
					memDC.FillSolidRect(iWidth - Offset - 1, 0, Offset, iHeight, endColor);
				}
			}
		}
	}

	// The screen bitmap should now have only the color ranges filled in, no tic
	// marks should be visible.
	if(m_dumpBitmaps)	// debugging
	{
		SaveBitmap("ScrnColors.bmp",memBM);
	}
	
	//////////////////////////////////////////////////////////////
	// More "paraphrasing" from Nic Wilson's work...
	//////////////////////////////////////////////////////////////

	////////////////////////////////////////////////////////////////////////////
	// At this point, memDC's bitmap contains just the color ranges drawn above.
	// No tic marks are visible. Doing SRCINVERT with the mask will draw in the
	// tic marks, but all the colors will be backwards. Also, the tics will be
	// whatever color was drawn in the color range stuff, rather than solid,
	// normal tic marks. SRCINVERT means the RGB values are changed by subtracting
	// from 255:
	//
	//		RGB(255,0,0)    --> RGB(0,255,255)
	//		RGB(247,8,0)    --> RGB(8,247,255)
	//		RGB(214,40,255) --> RGB(41,215,0)
	//
	/////////////////////////////////////////////////////////////////////////////
	memDC.SetBkColor(pDC->GetBkColor());
	memDC.SetTextColor(pDC->GetTextColor());
	memDC.BitBlt(0, 0, iWidth, iHeight, &SaveCDC, 0, 0, SRCINVERT);

	if(m_dumpBitmaps)	// debugging
	{
		SaveBitmap("ScrnInvert.bmp",memBM);
	}

	// Change the tic marks from the color range to the background color. This
	// changes only the tic marks (and the channel centerline) and leaves the
	// rest alone. The tic marks wind up black.
	memDC.BitBlt(0, 0, iWidth, iHeight, &SaveCDC, 0, 0, SRCAND);

	if(m_dumpBitmaps)	// debugging
	{
		SaveBitmap("ScrnAnd.bmp",memBM);
	}

	// Finally, invert the color ranges to their normal values. Since the tic
	// marks in the SaveCDC bitmap are white, they get inverted to black.
	memDC.BitBlt(0, 0, iWidth, iHeight, &SaveCDC, 0, 0, SRCINVERT);

	if(m_dumpBitmaps)	// debugging
	{
		SaveBitmap("ScrnFinal.bmp",memBM);
	}
	
	// Now copy out to screen
	pDC->BitBlt(0,0,iWidth,iHeight,&memDC,0,0,SRCCOPY);

	// restore and clean up
	pDC->SetBkColor(crOldBack);
	pDC->SetTextColor(crOldText);
	DeleteObject(SelectObject(SaveCDC, SaveCBmpOld));
	DeleteDC(SaveCDC);
	DeleteObject(SelectObject(memDC,oldbm));
	DeleteDC(memDC);

	*pResult = CDRF_DODEFAULT;

	m_dumpBitmaps = FALSE;	// only do this once!
}
Example #25
0
void CActionSelByRect::LButtonDownEvent(UINT nFlags, CPoint point)
{
	

	//Selection Box
	CRectTracker selectBox = CRectTracker(CRect(0,0,0,0),
		CRectTracker::solidLine +
		CRectTracker::resizeOutside );

	selectBox.m_sizeMin = 0;

	bool selected = selectBox.TrackRubberBand(dynamic_cast<CWnd*>(m_pMapCtrl), point, FALSE );

	CRect rect = selectBox.m_rect;
	rect.NormalizeRect();

	if( ( rect.BottomRight().x - rect.TopLeft().x ) < 10 &&
		( rect.BottomRight().y - rect.TopLeft().y ) < 10 )
		selected = false;

	if(!selected)
	{
		return;
	}

	GEOMETRY::geom::Envelope envelop;
	DIS_RECT disrect;
	disrect.left = rect.left;
	disrect.right = rect.right;
	disrect.top = rect.top;
	disrect.bottom = rect.bottom;
	m_pMap->GetDisplay()->GetDisplayTransformation().TransformToGeo(disrect,&envelop);

	//构造一个用于查询的多边形

	Geodatabase::CSpatialQuery queryfilter;

	//Coordinate coord;
	//LinearRing *pring = GeometryFactory::getDefaultInstance()->createLinearRing();

	/*coord.x =envelop.getMinX();
	coord.y =envelop.getMinY();
	pring->AddPoint(coord);

	coord.x =cExtent.xmax;
	coord.y =cExtent.ymin;
	pring->AddPoint(coord);

	coord.x =cExtent.xmax;
	coord.y =cExtent.ymax;
	pring->AddPoint(coord);

	coord.x =cExtent.xmin;
	coord.y =cExtent.ymax;
	pring->AddPoint(coord);

	coord.x =cExtent.xmin;
	coord.y =cExtent.ymin;
	pring->AddPoint(coord);*/



	//构造一个空间查询条件
	GEOMETRY::geom::Geometry *pGeometry =GEOMETRY::geom::GeometryFactory::getDefaultInstance()->toGeometry(&envelop);
	queryfilter.SetGeometry(pGeometry);
	queryfilter.SetSpatialRel(Geodatabase::SpatialRelIntersects);

	ISelectFeatureTool::Select(&queryfilter);

	GEOMETRY::geom::GeometryFactory::getDefaultInstance()->destroyGeometry(pGeometry);


}
Example #26
0
void CToolMapZoomin::LButtonDownEvent (UINT nFlags, CPoint point)
{
	//获取活动地图控件
	if(!m_pMapCtrl)
		return;

	//获取活动地区
	Carto::CMapPtr pMap = m_pMapCtrl->GetMap();
	if(!pMap)
		return;

	if(m_pMapCtrl->IsActiveX())
	{
		double geoCenterX, geoCenterY;
		pMap->GetDisplay()->GetDisplayTransformation().ConvertDisplayToGeo(point.x,point.y,geoCenterX, geoCenterY);
		pMap->GetDisplay()->GetDisplayTransformation().SetGeoCenterX(geoCenterX);
		pMap->GetDisplay()->GetDisplayTransformation().SetGeoCenterY(geoCenterY);
		pMap->GetDisplay()->GetDisplayTransformation().ZoomViewPosScale(0.667);
	}
	else
	{
		CRectTracker selectBox = CRectTracker(CRect(0,0,0,0),
			CRectTracker::solidLine +
			CRectTracker::resizeOutside );

		selectBox.m_sizeMin = 0;

		bool selected = selectBox.TrackRubberBand(dynamic_cast<CWnd*>(m_pMapCtrl), point, FALSE );

		CRect rect = selectBox.m_rect;
		rect.NormalizeRect();

		if( ( rect.BottomRight().x - rect.TopLeft().x ) < 10 &&
			( rect.BottomRight().y - rect.TopLeft().y ) < 10 )
			selected = false;


		if( selected == true )
		{
			GEOMETRY::geom::Envelope envelop;
			DIS_RECT disrect;
			disrect.left = rect.left;
			disrect.right = rect.right;
			disrect.top = rect.top;
			disrect.bottom = rect.bottom;

			pMap->GetDisplay()->GetDisplayTransformation().TransformToGeo(disrect,&envelop);
			pMap->GetDisplay()->GetDisplayTransformation().FitViewBound(envelop,true);

		}
		else
		{
			double geoCenterX, geoCenterY;
			pMap->GetDisplay()->GetDisplayTransformation().ConvertDisplayToGeo(point.x,point.y,geoCenterX, geoCenterY);
			pMap->GetDisplay()->GetDisplayTransformation().SetGeoCenterX(geoCenterX);
			pMap->GetDisplay()->GetDisplayTransformation().SetGeoCenterY(geoCenterY);
			pMap->GetDisplay()->GetDisplayTransformation().ZoomViewPosScale(0.667);
		}
		
	}
	
     m_pMapCtrl->UpdateControl(drawAll);
	//记录范围
    GEOMETRY::geom::Envelope curExtent;
    pMap->GetDisplay()->GetDisplayTransformation().GetGeoBound(curExtent);
    pMap->GetDisplay()->GetDisplayTransformation().RecordCurExtent(curExtent);

}
Example #27
0
void CModuleWnd::GetDragInfoData(LPSTGMEDIUM lpStgMedium)
{
	ASSERT_VALID(this);
	ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM)));
	
	int nItem;
	CModuleDoc::CModule* pModule;
	CRect rcBound;
	rcBound.SetRectEmpty();
	
	CClientDC dc(this);
	dc.BeginPath();
	
	POSITION pos = GetListCtrl()->GetFirstSelectedItemPosition();
	while (pos)
	{
		nItem = GetListCtrl()->GetNextSelectedItem(pos);
		pModule = m_pCurrentDocument->GetModule(nItem);

		CRect rcObj = pModule->m_rcPosition.GetRECT();
		rcObj.NormalizeRect();
		rcBound.UnionRect(rcBound, rcObj);

		dc.MoveTo(rcObj.left, rcObj.top);
		dc.LineTo(rcObj.right, rcObj.top);
		dc.LineTo(rcObj.right, rcObj.bottom);
		dc.LineTo(rcObj.left, rcObj.bottom);
		dc.LineTo(rcObj.left, rcObj.top);
	}
	
	dc.EndPath();
	
	
	CPoint ptStart = rcBound.CenterPoint();
	theApp.AlignToGrid(ptStart);
	
	LPSTREAM lpStream;
	if (::CreateStreamOnHGlobal(NULL, TRUE, &lpStream) != S_OK)
		AfxThrowMemoryException();
	
	ASSERT(lpStream != NULL);
	
	lpStream->Write(&rcBound, sizeof(CRect), NULL);
	lpStream->Write(&ptStart, sizeof(CPoint), NULL);
	
	int iNumPoints = dc.GetPath(NULL, NULL, 0);
	
	CPoint* pPoints = new CPoint[iNumPoints];
	if (pPoints == NULL)
		AfxThrowMemoryException();
	BYTE* pTypes = new BYTE[iNumPoints];
	if (pTypes == NULL)
		AfxThrowMemoryException();
	
	iNumPoints = dc.GetPath(pPoints, pTypes, iNumPoints);
	
	lpStream->Write(&iNumPoints, sizeof(int), NULL);
	lpStream->Write(pPoints, sizeof(CPoint) * iNumPoints, NULL);
	lpStream->Write(pTypes, sizeof(BYTE) * iNumPoints, NULL);
	
	if (pPoints != NULL)
		delete pPoints;
	if (pTypes != NULL)
		delete pTypes;
	
	// setup the STGMEDIUM
	lpStgMedium->tymed = TYMED_ISTREAM;
	lpStgMedium->pstm = lpStream;
	lpStgMedium->pUnkForRelease = NULL;
}
Example #28
0
	void CLayoutMapZoomout::LButtonDownEvent (UINT nFlags, CPoint point)
	{
		//获取活动地图控件
		Framework::IMapCtrl *pMapCtrl = Framework::IMapCtrl::GetActiveMapCtrl();
		if(!pMapCtrl)
			return;

		Carto::CMapPtr pMap = pMapCtrl->GetMap();
		if(!pMap)
			return;

		Framework::ILayoutCtrl *pLayoutCtrl = Framework::ILayoutCtrl::GetActiveLayoutCtrl();
		if(!pLayoutCtrl)
			return;

		Carto::CPageLayoutPtr pPageLayout = pLayoutCtrl->GetPageLayout();
		if(!pPageLayout)
			return;

		Element::CMapFrame* pMapFrame = NULL;
		Element::IElementPtr pElement = pPageLayout->GetGraphicLayer()->Reset();
		while(pElement)
		{
			if(pElement->GetType() != Element::ET_MAP_FRAME_ELEMENT)
			{
				pElement = pPageLayout->GetGraphicLayer()->Next();
				continue;
			}

			Element::CMapFrame* pTmpMapFrm = dynamic_cast<Element::CMapFrame*>(pElement.get());
			if(pTmpMapFrm->GetMap() != pMap)
			{
				pElement = pPageLayout->GetGraphicLayer()->Next();
				continue;
			}

			pMapFrame = pTmpMapFrm;
			break;
		}

		if(!pMapFrame)
			return;

		DIS_RECT* mapFrameBound = NULL;
		CreateDisplayRect(mapFrameBound);
		mapFrameBound = pPageLayout->GetDisplay()->GetDisplayTransformation().TransformToDisplay(pMapFrame->GetGeometry()->getEnvelopeInternal());

		//Selection Box
		CRectTracker selectBox = CRectTracker(CRect(0,0,0,0),
			CRectTracker::solidLine +
			CRectTracker::resizeOutside );

		selectBox.m_sizeMin = 0;
		bool selected = selectBox.TrackRubberBand(dynamic_cast<CWnd*>(pLayoutCtrl), point, FALSE );

		CRect rect = selectBox.m_rect;
		rect.NormalizeRect();
		if( ( rect.BottomRight().x - rect.TopLeft().x ) < 10 &&
			( rect.BottomRight().y - rect.TopLeft().y ) < 10 )
			selected = false;


		if( selected == true )
		{
			GEOMETRY::geom::Envelope envelop;

			pMap->GetDisplay()->GetDisplayTransformation().GetGeoBound(envelop);

			long lWidth = rect.Width();
			long lHeight = rect.Height();

			double rx = envelop.getWidth()/ lWidth;
			double ry = envelop.getHeight()/ lHeight;

			double dbScale = (rx > ry) ? rx : ry;

			pMap->GetDisplay()->GetDisplayTransformation().ZoomToFixScale(dbScale);

			CRect viewRect =pMap->GetDisplay()->GetDisplayTransformation().GetViewBound().GetRect();

			double dx=(rect.CenterPoint().x - mapFrameBound->left - viewRect.CenterPoint().x)*dbScale;
			double dy=(viewRect.CenterPoint().y - (rect.CenterPoint().y - mapFrameBound->top))*dbScale;

			pMap->GetDisplay()->GetDisplayTransformation().MoveViewBound(dx,dy);

		}
		else
		{
			double geoCenterX, geoCenterY;
			long x,y;
			x = point.x - mapFrameBound->left;
			y = point.y - mapFrameBound->top;
			pMap->GetDisplay()->GetDisplayTransformation().ConvertDisplayToGeo(x,y,geoCenterX, geoCenterY);
			pMap->GetDisplay()->GetDisplayTransformation().SetGeoCenterX(geoCenterX);
			pMap->GetDisplay()->GetDisplayTransformation().SetGeoCenterY(geoCenterY);
			pMap->GetDisplay()->GetDisplayTransformation().ZoomViewPosScale(1.5);	
		}

		GEOMETRY::geom::Envelope viewGeo;
		pMap->GetDisplay()->GetDisplayTransformation().GetGeoBound(viewGeo);
		pMap->SetViewEnvelope(viewGeo);


		FreeDisplayObj(mapFrameBound);
		pLayoutCtrl->UpdateControl();	
	}
Example #29
0
void CDrawWarn::Draw(CDC* pDC)
{
	ASSERT_VALID(this);
	CRect rect = m_position;
	rect.NormalizeRect();

	if(rect.Width() < 10 || rect.Height()<10)
		return;

	Rect GdiRect (rect.TopLeft().x,rect.TopLeft().y,rect.Size().cx,rect.Size().cy); 

	Color crBackColor,crTitleColor,crLineColor,crTextColor ;
	crBackColor.SetFromCOLORREF(m_ctlBackColor);
	crTitleColor.SetFromCOLORREF(m_ctlTitleColor );
	crLineColor.SetFromCOLORREF(m_ctlLineColor);
	crTextColor.SetFromCOLORREF(m_ctlTextColor);

	Graphics graphics (pDC->m_hDC);
	graphics.SetSmoothingMode (SmoothingModeHighSpeed);
	Graphics Textgraphics (pDC->m_hDC);
	SolidBrush  solidBrush(crBackColor);
	SolidBrush  TitleBrush(crTitleColor);
	SolidBrush  TextBrush(crTextColor);
	Pen pen(crLineColor,1);
	
	graphics.FillRectangle(&solidBrush,GdiRect);

        		BSTR bstr = m_fontName.AllocSysString();
///	BSTR bstr = _com_util::ConvertStringToBSTR(m_fontName);
	FontFamily  fontFamily(bstr);
   	SysFreeString(bstr);
	Font font(&fontFamily, m_fontSize, m_fontStyle, UnitPoint);

	for(int j =1; j<= m_nColCount; j++)
	{
		m_nCellWidth = 0;
		for(int i=1; i<= m_nRowCount; i++)
		{
			CRect rc = rect;
			if(m_bIsAutoSize)
			{
				m_nCellWidth = rect.Width()/m_nRowCount;
				m_nCellHeight = rect.Height()/m_nColCount;
				rc.TopLeft().x += (i-1)*m_nCellWidth;
				rc.TopLeft().y += (j-1)*m_nCellHeight;
				m_CellRect = CRect(rc.TopLeft(),CSize(m_nCellWidth,m_nCellHeight));
				m_CellRect.NormalizeRect();
			}
			else
			{
				rc.TopLeft().x += m_nCellWidth;
				m_nCellWidth += rect.Width()*m_nPercent[i-1]/100;
				m_nCellHeight = rect.Height()/m_nColCount;
				rc.TopLeft().y += (j-1)*m_nCellHeight;	
				m_CellRect = CRect(rc.TopLeft(),CSize(rect.Width()*m_nPercent[i-1]/100,m_nCellHeight));
				m_CellRect.NormalizeRect();
			}

			Rect CellRect(m_CellRect.TopLeft().x,m_CellRect.TopLeft().y,m_CellRect.Size().cx,m_CellRect.Size().cy);

			graphics.DrawRectangle(&pen,CellRect);
			
			if(j == m_nColCount)	//画标题
			{
				StringFormat stringFormat;
				stringFormat.SetAlignment(StringAlignmentCenter);
				stringFormat.SetLineAlignment(StringAlignmentCenter);
				stringFormat.SetFormatFlags(StringFormatFlagsDirectionRightToLeft);
				stringFormat.SetTrimming(m_trimmingSyle);

				CString m_strButton;
				if(i == 1)
					m_strButton = "点号";
				if(i == 2)
					m_strButton = "数据";
				if(i == 3)
					m_strButton = "说明";
				if(i == 4)
					m_strButton = "报警原因";
				if(i == 5)
					m_strButton = "时间";

				m_strButton.TrimRight();
        		bstr = m_strButton.AllocSysString();
///				bstr = _com_util::ConvertStringToBSTR(m_strButton);
				RectF theRect (m_CellRect.TopLeft().x,m_CellRect.TopLeft().y,m_CellRect.Size().cx,m_CellRect.Size().cy);
				Matrix matrix(1,0,0,-1,0,0);
				Textgraphics.SetTransform(&matrix);
				
				theRect.Y *=-1;
				theRect.Height*=-1;
				Normallize (theRect);	
				Textgraphics.FillRectangle(&TitleBrush,theRect);
				Textgraphics.DrawString(bstr,-1,&font, theRect,&stringFormat, &TextBrush);
            	SysFreeString(bstr);
			}
			else 
			{					//画文字  m_CStrWarn      pStrWarn
				StringFormat stringFormat;
				stringFormat.SetAlignment(StringAlignmentNear);
				stringFormat.SetLineAlignment(StringAlignmentNear);

            	CString  strWarn;
/*				if(i == 1)
					strWarn = m_CStrWarn[j].strPoint;
				if(i == 2)
					strWarn = m_CStrWarn[j].strDate;
				if(i == 3)
					strWarn = m_CStrWarn[j].strTime;
				if(i == 4)
					strWarn = m_CStrWarn[j].strText;
				if(i == 5)
					strWarn = m_CStrWarn[j].strWarn;
*/
				strWarn.TrimRight();
        		bstr = strWarn.AllocSysString();
///				bstr = _com_util::ConvertStringToBSTR(strWarn);

				RectF theRect (m_CellRect.TopLeft().x,m_CellRect.TopLeft().y,m_CellRect.Size().cx,m_CellRect.Size().cy);
				Matrix matrix(1,0,0,-1,0,0);
				Textgraphics.SetTransform(&matrix);
				
				theRect.Y *=-1;
				theRect.Height*=-1;
				Normallize (theRect);	
				Textgraphics.DrawString(bstr,-1,&font, theRect,&stringFormat, &TextBrush);
             	SysFreeString(bstr);
			}			
		}
	}
	graphics.ReleaseHDC(pDC->m_hDC);
}
Example #30
0
USAGEMODE HRESULT TX_vShowConfigureMsgWindow(void* pParentWnd)
{
    //Place this code at the beginning of the export function.
    //Save previous resource handle and switch to current one.
    HINSTANCE hInst = AfxGetResourceHandle();
    AfxSetResourceHandle(TXWindowDLL.hResource);

    if( g_pomTxMsgChildWindow == NULL )
    {
        // Create New Instance
        g_pomTxMsgChildWindow = new CTxMsgChildFrame;
        if( g_pomTxMsgChildWindow != NULL )
        {
            //// Register Window Class
            LPCTSTR strMDIClass = AfxRegisterWndClass(
                                      CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS,
                                      LoadCursor(NULL, IDC_CROSS), 0,
                                      ::LoadIcon(NULL, MAKEINTRESOURCE(IDI_ICO_SEND_MSG)) );

            //// Set the size got from configuration module
            WINDOWPLACEMENT sTxWndPlacement;
            WINDOWPLACEMENT* psTxWndPlacement = &sTxWndPlacement;
            CTxWndDataStore::ouGetTxWndDataStoreObj().bGetTxData(TX_WINDOW_PLACEMENT, (void**)&psTxWndPlacement);
            if (sTxWndPlacement.rcNormalPosition.top == -1 ||
                    sTxWndPlacement.length == 0)//Load default configuration
            {
                CRect omRect;
                CWnd* pWnd = (CWnd*)pParentWnd;
                pWnd->GetClientRect(&omRect);
                omRect.NormalizeRect();
                // Reduce the size propotionally
                omRect.bottom -= (LONG)(omRect.Height() * defTX_MSG_WND_BOTTOM_MARGIN);
                omRect.right -= (LONG)(omRect.Width() * defTX_MSG_WND_RIGHT_MARGIN);
                // Update the size
                sTxWndPlacement.rcNormalPosition = omRect;
            }
            CRect omRect(&(sTxWndPlacement.rcNormalPosition));

            // Create Tx Message Configuration window
            if( g_pomTxMsgChildWindow->Create( strMDIClass,
                                               _(defSTR_TX_WINDOW_TITLE),
                                               WS_CHILD | WS_OVERLAPPEDWINDOW,
                                               omRect, (CMDIFrameWnd*)pParentWnd ) == TRUE )
            {
                // Show window and set focus
                g_pomTxMsgChildWindow->ShowWindow( SW_SHOW);
                g_pomTxMsgChildWindow->SetFocus();
                g_pomTxMsgChildWindow->SetWindowPlacement(&sTxWndPlacement);
                g_pomTxMsgChildWindow->ShowWindow( SW_SHOW);
            }
        }
        else
        {
            return S_FALSE;
        }
    }
    // If already exist then activate and set the focus
    else
    {
        g_pomTxMsgChildWindow->ShowWindow( SW_RESTORE );
        g_pomTxMsgChildWindow->MDIActivate();
        g_pomTxMsgChildWindow->SetActiveWindow();
    }
    //Place this at the end of the export function.
    //switch back to previous resource handle.
    AfxSetResourceHandle(hInst);
    return S_OK;
}