void CCharSymbolSelectListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	CDC* pDC;
	long lCurRow = 0; //当前行数
	long lNumSymbols = 0;
	long lStartSymbol = 0;

	pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	lCurRow = long(lpDrawItemStruct->itemID);//得到当前行数
	if (lCurRow < 0 || NULL == m_pCharDraw)
		return;

	lStartSymbol = lCurRow * NUMSYMBOLPERROW + 1;
	lNumSymbols = FONTSYMBOLNUMS;

	CPen nPen(PS_SOLID,2,RGB(0,0,0)), nSelPen(PS_SOLID,2,RGB(255,0,0)) , *pOldPen;

	Display::IDisplayPtr pDisplay ( new Display::IDisplay() );
	pDisplay->SetDC( (long)pDC->GetSafeHdc() , m_rect.Width() , m_rect.Height() );
	CPoint  pt;
	CRect rect;
	for(int i = lStartSymbol ; i <  lStartSymbol + NUMSYMBOLPERROW && i<= lNumSymbols ; ++i)
	{
		pt.x = (i - lStartSymbol) * m_lItemHeight;//先计算左上角
		pt.y = lpDrawItemStruct->rcItem.top;
		rect.SetRect(pt.x,pt.y,pt.x + m_lItemHeight,pt.y + m_lItemHeight);//计算矩形区域

		pt.x +=  m_lItemHeight/2;
		pt.y +=  m_lItemHeight/2;

		pOldPen = pDC->SelectObject(&nPen);	

		if (rect.top < 0)
		{
			continue;
		}

		if (rect.bottom > m_rect.bottom)
		{
			continue;
		}
		pDC->Rectangle(&rect); 

		pDC->SelectObject(pOldPen);

		if (m_lNewSelectId == i)
		{
			pOldPen = pDC->SelectObject(&nSelPen);	
			pDC->Rectangle(&rect);
			pDC->SelectObject(pOldPen);

			unsigned long color = m_pCharDraw->GetMarkColor();
		//	m_pCharDraw->SetMarkerColor(RGB(255 , 255 , 255));
			m_pCharDraw->SetCharMap(i);

			DIS_RECT drawRect;
			drawRect.left =rect.left;
			drawRect.right =rect.right;
			drawRect.top =rect.top;
			drawRect.bottom =rect.bottom;

			pDisplay->DrawLegend( m_pCharDraw.get() , &drawRect , 0 );
		//	m_pCharDraw->SetMarkerColor(color);

			if (m_ctrlToolTip.m_hWnd != NULL)
			{
				CString tip;
				tip.Format("Unicode:%d" , m_lNewSelectId);
				m_ctrlToolTip.AddTool(this , tip , &rect , 10);
				m_ctrlToolTip.Activate(TRUE);

			}
		}
		else
		{
			DIS_RECT drawRect;
			drawRect.left =rect.left;
			drawRect.right =rect.right;
			drawRect.top =rect.top;
			drawRect.bottom =rect.bottom;
			m_pCharDraw->SetCharMap(i);
			pDisplay->DrawLegend( m_pCharDraw.get() , &drawRect , 0 );
		}
	}

		
}
Beispiel #2
0
void CGelView::DrawGel(CDC* pDC, CRect rcBounds) 
{
	char tBuff[128];
    
    CBrush bBrush;
	bBrush.CreateSolidBrush( RGB(255,255,255) );
	pDC->FillRect( &rcBounds, &bBrush );
	pDC->SetBkColor( RGB(255,255,255) );

	CSize docSize = GetGelSize();

	double ypi = pDC->GetDeviceCaps(LOGPIXELSY);
	double xpi = pDC->GetDeviceCaps(LOGPIXELSX);

	int x = (int)((double)docSize.cx/100.0 * xpi);
	int y = (int)((double)docSize.cy/100.0 * ypi);

	int xoff = rcBounds.TopLeft().x;
	int yoff = rcBounds.TopLeft().y;

	int YSpace = (int)(ypi / 24.0);
	int XSpace = (int)(xpi / 24.0);

	// Lets draw graph always ...
	//
	CFont fontTmp;
	CFont* pOldFont = SelectDocFont(pDC, fontTmp, 900);

	CPen nPen( PS_SOLID, m_LineWidth, RGB(0,0,0) );
    CPen* oPen = pDC->SelectObject(&nPen);


	CSize fontSize = pDC->GetTextExtent( "X", 1 );
	int NamesHeight = 0;
	POSITION gPos = m_listGel.GetHeadPosition();
	while ( gPos != NULL ) {
		SGel *pSGel = (SGel *)m_listGel.GetNext(gPos);
		CString strName = pSGel->Sequence->GetTitle();
		strName = strName.Left(10);

		CSize fontSize = pDC->GetTextExtent( strName, strName.GetLength() );
		int iHeight = fontSize.cx;
		if ( iHeight > NamesHeight ) NamesHeight = iHeight;

	}


//	int xborder = (int)((double)x * .05);

  	_snprintf( tBuff, 127, "%d", m_MaxY );	// = "1.0";
	CSize tstrsz;
	tstrsz = pDC->GetTextExtent( tBuff, strlen(tBuff) );
	int xborder = tstrsz.cx + XSpace;

	int yborder = (int)(xpi / 24.0);

	yborder += m_LineWidth;


	pDC->MoveTo(xoff + (xborder), yoff + (NamesHeight + YSpace - m_LineWidth) );
	pDC->LineTo(xoff + (xborder),yoff + (y - yborder));
	pDC->LineTo(xoff + (x - XSpace),yoff + (y - yborder));
	pDC->LineTo(xoff + (x - XSpace),yoff + ( NamesHeight + YSpace - m_LineWidth ));
	pDC->LineTo(xoff + (xborder ),yoff + (NamesHeight + YSpace - m_LineWidth ));

	int GraphWidth = (x - XSpace) - xborder;


	int drl = 1;
	while ( drl < m_MinY ) {
		if ( drl * 10 > m_MinY ) break;
		drl = drl * 10;
	}
	double YRange = m_MaxY - (double)drl + 1;

	double dblYMult = (double)y - (yborder + NamesHeight + YSpace);


	
	if ( m_listGel.GetCount() != 0 ) {

		int GelCount = m_listGel.GetCount();
		int dWidth = GraphWidth - ( GelCount * m_LineWidth * 2 );
		int BandWidth = dWidth / GelCount;

		int Band = 0;

		gPos = m_listGel.GetHeadPosition();
		while ( gPos != NULL ) {
			SGel *pSGel = (SGel *)m_listGel.GetNext(gPos);
			CString strName = pSGel->Sequence->GetTitle();
			strName = strName.Left(10);

			double dblXVal = (Band * BandWidth) + (Band * m_LineWidth * 2) - (m_LineWidth * 2);

			pDC->ExtTextOut( 
				1 + xoff + ((int)dblXVal + xborder) + ( BandWidth / 2 ) - ( fontSize.cx / 2 ),
				yoff + (NamesHeight + YSpace - m_LineWidth - 2), 
				ETO_CLIPPED, CRect ( xoff, yoff, xoff + x, yoff + y ), 
				strName, strName.GetLength(), NULL
			);

			Band++;

			int wdrl = drl;
			int inc = drl;
			while ( wdrl < m_MaxY ) {

				double dblYVal = 1.0 - (log (double( wdrl - drl + 1)) / log(YRange));


				dblYVal *= dblYMult;
				int tyloc = yoff + (NamesHeight + YSpace + (int)dblYVal - 1);

				pDC->MoveTo(
					1 + xoff + ((int)dblXVal + BandWidth + xborder + m_LineWidth+ m_LineWidth), 
					tyloc);
				pDC->LineTo(
					1 + xoff + ((int)dblXVal + BandWidth + xborder + m_LineWidth+ m_LineWidth + m_LineWidth), 
					tyloc);
				pDC->LineTo(
					1 + xoff + ((int)dblXVal + BandWidth + xborder + m_LineWidth+ m_LineWidth), 
					tyloc);


				wdrl += inc;
				if ( wdrl == inc * 10 ) {
					inc = inc * 10;
				}


			}


		}

		pDC->SelectObject( pOldFont );
		fontTmp.DeleteObject();
		pOldFont = SelectDocFont(pDC, fontTmp, 0);

		int yinc = ((y - yborder) - (NamesHeight + YSpace ))/4;

		pDC->MoveTo(xoff + (xborder),yoff + ( NamesHeight + YSpace ));
		pDC->LineTo(xoff + (xborder - XSpace),yoff + ( NamesHeight + YSpace ));
		pDC->LineTo(xoff + (xborder),yoff + ( NamesHeight + YSpace ));


  		_snprintf( tBuff, 127, "%d", m_MaxY );	// = "1.0";
		CSize tstrsz;
		tstrsz = pDC->GetTextExtent( tBuff, strlen(tBuff) );
		// pDC->LPtoDP( &tstrsz );

		pDC->ExtTextOut( 
			xoff + (xborder - XSpace - tstrsz.cx), 
			yoff + (NamesHeight + YSpace) - tstrsz.cy,  
			ETO_CLIPPED, CRect ( xoff, yoff, xoff + x, yoff + y ), 
			tBuff, strlen(tBuff), NULL 
		);




		int wdrl = drl;
		int inc = drl;
		while ( wdrl < m_MaxY ) {

			double dblYVal = 1.0 - (log (double( wdrl - drl + 1)) / log(YRange));


			dblYVal *= dblYMult;
			int tyloc = yoff + (NamesHeight + YSpace + (int)dblYVal - 1);

			pDC->MoveTo(xoff + (xborder),tyloc);
			pDC->LineTo(xoff + (xborder - XSpace),tyloc);
			pDC->LineTo(xoff + (xborder),tyloc);

			if ( wdrl == inc || wdrl == inc *5 ) {
				pDC->MoveTo(xoff + (xborder),tyloc);
				pDC->LineTo(xoff + (xborder - XSpace),tyloc);
				pDC->LineTo(xoff + (xborder),tyloc);
				
				_snprintf( tBuff, 127, "%d", wdrl );	// = ".75";
				tstrsz = pDC->GetTextExtent( tBuff, strlen(tBuff) );

				pDC->ExtTextOut( 
					xoff + (xborder - XSpace - tstrsz.cx), 
					tyloc -(tstrsz.cy/2),  
					ETO_CLIPPED, CRect ( xoff, tyloc-(tstrsz.cy/2), xoff + x, (tyloc -(tstrsz.cy/2)) + y ), 
					tBuff, strlen(tBuff), NULL 
				);
			}

			wdrl += inc;
			if ( wdrl == inc * 10 ) {
				inc = inc * 10;
			}
		}

		// For assumed Y Scale = 0 - 1.0
		// Create a red pen.
		pDC->SelectObject( oPen );
		nPen.DeleteObject();
		nPen.CreatePen( PS_SOLID, m_LineWidth, RGB(255,0,0) );
		oPen = pDC->SelectObject(&nPen);

		Band = 0;

		gPos = m_listGel.GetHeadPosition();
		while ( gPos != NULL ) {
			SGel *pSGel = (SGel *)m_listGel.GetNext(gPos);

			double dblXVal = (Band * BandWidth) + (Band * m_LineWidth * 2);

			int FragCount = pSGel->arrGelLoc.GetSize();

			for ( int i=0; i < FragCount; ++i ) {
				
				double ss = pSGel->arrGelLoc[i] / 100000000.0;
				double dblYVal = 1.0 - (log( (ss * YRange) - drl + 1) / log(YRange));

				dblYVal *= dblYMult;

				pDC->MoveTo( 
					1 + xoff + ((int)dblXVal + xborder), 
					yoff + (NamesHeight + YSpace + (int)dblYVal - 1)
				);
				pDC->LineTo( 
					1 + xoff + ((int)dblXVal + BandWidth + xborder) - (m_LineWidth * 2),
					yoff + (NamesHeight + YSpace +  (int)dblYVal - 1)
				);
				pDC->LineTo( 
					1 + xoff + ((int)dblXVal + xborder), 
					yoff + (NamesHeight + YSpace + (int)dblYVal - 1)
				);

			}

			Band++;
		}

	}

	pDC->SelectObject( oPen );
	nPen.DeleteObject();



	pDC->SelectObject( pOldFont );
	fontTmp.DeleteObject();


}
void CCharSymbolSelectListBox::SetNewSelectId(long lNewSelectId)
{
	long preId = m_lNewSelectId;
	m_lNewSelectId = lNewSelectId;
	CRect RectOld,RectNew;
	DIS_RECT rectOld, rectNew;
	
	if(m_lNewSelectId != m_lOldSelectId)
	{
		UpdateWindow();

		//old
		GetItemRect((m_lOldSelectId - 1) / NUMSYMBOLPERROW, &RectOld);										
			
		RectOld.left = RectOld.left + (m_lOldSelectId - 1) % NUMSYMBOLPERROW * m_lItemHeight;
		RectOld.right = RectOld.left + m_lItemHeight;

		rectOld.left = RectOld.left;
		rectOld.right = RectOld.right;
		rectOld.top = RectOld.top;
		rectOld.bottom = RectOld.bottom;
		
		//new
		GetItemRect((m_lNewSelectId - 1) / NUMSYMBOLPERROW, &RectNew);

		RectNew.left = RectNew.left + (m_lNewSelectId - 1) % NUMSYMBOLPERROW * m_lItemHeight;
		RectNew.right = RectNew.left + m_lItemHeight;

		rectNew.left = RectNew.left;
		rectNew.right = RectNew.right;
		rectNew.top = RectNew.top;
		rectNew.bottom = RectNew.bottom;

		//draw
		CDC * pDC = GetDC();
		COLORREF bgCr = pDC->GetBkColor();
		Display::IDisplayPtr pDisplay ( new Display::IDisplay);
		pDisplay->SetDC( (long)pDC->GetSafeHdc() , m_rect.Width() , m_rect.Height() );
	
		CPen* pOldPen;
		//绘制旧
		CPen nPen(PS_SOLID,2,RGB(0,0,0)) ;
		pOldPen = pDC->SelectObject(&nPen);	
		pDC->Rectangle(&RectOld); 
		pDC->SelectObject(pOldPen);

		m_pCharDraw->SetCharMap(m_lOldSelectId);	
		pDisplay->DrawLegend( m_pCharDraw.get() , &rectOld , 0 );

		//绘制新
		CPen nNewPen(PS_SOLID,2,RGB(255,0,0));
		pOldPen = pDC->SelectObject(&nNewPen);	
		pDC->Rectangle(&RectNew); 
		pDC->SelectObject(pOldPen);

		m_pCharDraw->SetCharMap(m_lNewSelectId);		
		pDisplay->DrawLegend( m_pCharDraw.get() , &rectNew , 0 );
		
		ReleaseDC(pDC);
		UpdateWindow();

		m_lOldSelectId = preId;
	}
	
}