示例#1
0
/**
 * Draw a string in the shell
 */
void
gui_mch_draw_string(
    int		row,
    int		col,
    char_u	*s,
    int		len,
    int		flags)
{
	QString str = VimWrapper::convertFrom(s, len);
	
	// Font
	QFont f = vimshell->font();
	f.setBold( flags & DRAW_BOLD);
	f.setUnderline( flags & DRAW_UNDERL);
	f.setItalic( flags & DRAW_ITALIC);

	QFontMetrics fm(f);

	int cellwidth = VimWrapper::stringCellWidth(str);
	QPoint pos = VimWrapper::mapText(row, col);
	QRect rect( pos.x(), pos.y(), gui.char_width*cellwidth, gui.char_height);

	if (flags & DRAW_TRANSP) {
		// Do we need to do anything?
	} else {
		// Fill in the background
		QVimShell::PaintOperation op;
		op.type = QVimShell::FILLRECT;
		op.rect = rect;
		op.color = backgroundColor;
		vimshell->queuePaintOp(op);
	}

	// Remove upper linespace from rect
	QRect rect_text( pos.x(), pos.y() + p_linespace/2, gui.char_width*cellwidth, gui.char_height);
	QVimShell::PaintOperation op;
	op.type = QVimShell::DRAWSTRING;
	op.font = f;
	op.rect = rect_text;
	op.str = str;
	op.color = foregroundColor;
	op.undercurl = flags & DRAW_UNDERC;
	if ( op.undercurl ) { // FIXME: Refactor QVimShell::PaintOperation
		op.curlcolor = specialColor;
	}

	// op.pos is the text baseline
	op.pos = rect.topLeft();
	op.pos.setY( op.pos.y() + gui.char_ascent );

	vimshell->queuePaintOp(op);
}
void CPlotWindow:: DrawAxis(CDC &MemDC)
{
	CString str;
// 	CBrush br,*oldbr;
// 	br.CreateSolidBrush(backcolor);
// 	oldbr = MemDC.SelectObject(&br);
// // 	MemDC.Rectangle(X1,Y2,X2,Y1);
// 	MemDC.SelectObject(oldbr);
// 	br.DeleteObject();
	MemDC.FillSolidRect(X1,Y2,X2,Y1,backcolor);
//	MemDC.Rectangle(X1,Y2,X2,Y1);
//	MemDC.SetBkColor(backcolor);
//	MemDC.SelectPalette()
	COLORREF color_text=RGB(255,255,255);
	CPen pen(PS_DASH,1,color_text);
	CPen* pOldPen = MemDC.SelectObject(&pen);
	MemDC.SetTextColor(color_text);
	//Draw X Axis
	MemDC.MoveTo(X1,Y2-2);
	MemDC.LineTo(X2,Y2-2);
	CPen pen1(PS_SOLID,1,color_text);
	MemDC.SelectObject(&pen1);
	if(y1<0 && y2>0)
	{
		int b;
		b= static_cast<int>(((Y1-10)*y2-(Y2+20)*y1)/(y2-y1));
		//Draw Y Axis
		MemDC.MoveTo(X1+Xoffset,Y1-10);
		MemDC.LineTo(X1+Xoffset,Y2+2);
		//Draw Arrow;
		MemDC.MoveTo(X1+Xoffset-arrowsize,Y2+2+arrowsize);
		MemDC.LineTo(X1+Xoffset,Y2+2);
		MemDC.LineTo(X1+Xoffset+arrowsize,Y2+2+arrowsize);
		//Draw X Axis
		MemDC.MoveTo(X1+Xoffset,b);
		MemDC.LineTo(X2-2,b);
		//Draw Arrow;
		MemDC.MoveTo(X2-2-arrowsize,b+arrowsize);
		MemDC.LineTo(X2-2,b);
		MemDC.LineTo(X2-2-arrowsize,b-arrowsize);
		CRect rect_text(X1,b-15,X1+Xoffset-4,b+5);
		str.Format(_T("%ld"),0);
		MemDC.DrawText(str,rect_text,DT_RIGHT|DT_SINGLELINE|DT_VCENTER);
		CRect rect_text1(X1+Xoffset+10,Y2+10,X1+Xoffset+100,Y2+30);
		str.Format(_T("%ld"),y2);
		MemDC.DrawText(str,rect_text1,DT_LEFT|DT_SINGLELINE|DT_VCENTER);
		CRect rect_text2(X1+Xoffset+10,Y1-10,X1+Xoffset+100,Y1-30);
		str.Format(_T("%ld"),y1);
		MemDC.DrawText(str,rect_text2,DT_LEFT|DT_SINGLELINE|DT_VCENTER);
		str.Format(_T("%d"),x_range-1);
		CRect rect_text3(X2-100,b+4,X2-10,b+24);
		MemDC.DrawText(str,rect_text3,DT_RIGHT|DT_SINGLELINE|DT_VCENTER);
		MemDC.MoveTo(X1+Xoffset,Y2+20);
		MemDC.LineTo(X1+Xoffset+6,Y2+20);
		MemDC.MoveTo(X1+Xoffset,Y1-15);
		MemDC.LineTo(X1+Xoffset+6,Y1-15);
		MemDC.MoveTo(X2-20,b);
		MemDC.LineTo(X2-20,b-6);
		Axis_X1 = X1+Xoffset;
		Axis_X2 = X2-20;
		Axis_Y1 = Y1-15;
		Axis_Y2 = Y2+20;
	}
	else
	{
		//XÖáÔÚ×îÏÂÃæ
		CRect rect_text1(X1+Xoffset+10,Y2+10,X1+Xoffset+200,Y2+30);
		str.Format(_T("%ld"),y2);
		MemDC.DrawText(str,rect_text1,DT_LEFT|DT_SINGLELINE|DT_VCENTER);
		CRect rect_text2(X1+Xoffset+10,Y1-Yoffset,X1+Xoffset+200,Y1-Yoffset+20);
		str.Format(_T("%ld"),y1);
		MemDC.DrawText(str,rect_text2,DT_LEFT|DT_SINGLELINE|DT_VCENTER);
		//Draw Y Axis
		MemDC.MoveTo(X1+Xoffset,Y1-Yoffset);
		MemDC.LineTo(X1+Xoffset,Y2+2);
		//Draw Arrow;
		MemDC.MoveTo(X1+Xoffset-arrowsize,Y2+2+arrowsize);
		MemDC.LineTo(X1+Xoffset,Y2+2);
		MemDC.LineTo(X1+Xoffset+arrowsize,Y2+2+arrowsize);
		//Draw X Axis
		MemDC.LineTo(X1+Xoffset+arrowsize,Y2+2+arrowsize);
		MemDC.MoveTo(X1+Xoffset,Y1-Yoffset);
		MemDC.LineTo(X2-2,Y1-Yoffset);
		//Draw Arrow;
		MemDC.MoveTo(X2-2-arrowsize,Y1-Yoffset+arrowsize);
		MemDC.LineTo(X2-2,Y1-Yoffset);
		MemDC.LineTo(X2-2-arrowsize,Y1-Yoffset-arrowsize);
		str.Format(_T("%d"),x_range-1);
		CRect rect_text3(X2-100,Y1-Yoffset+4,X2-10,Y1-Yoffset+24);
		MemDC.DrawText(str,rect_text3,DT_RIGHT|DT_SINGLELINE|DT_VCENTER);
		MemDC.MoveTo(X1+Xoffset,Y2+20);
		MemDC.LineTo(X1+Xoffset+6,Y2+20);
		MemDC.MoveTo(X2-20,Y1-Yoffset);
		MemDC.LineTo(X2-20,Y1-Yoffset-6);
		Axis_X1 = X1+Xoffset;
		Axis_X2 = X2-20;
		Axis_Y1 = Y1-Yoffset;
		Axis_Y2 = Y2+20;
	}
	MemDC.SelectObject(pOldPen);
}