DrawNotes.cpp 3.73 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
#include "StdAfx.h"
#include "DrawNotes.h"

DrawNotes::DrawNotes(void)
{
}

DrawNotes::~DrawNotes(void)
{
}

void DrawLine_std( HDC hDC, WORD line_width, Color line_clr, Point pt_begin, Point pt_end )
{
	Graphics graph(hDC);

	// draw begin
	graph.DrawLine(&Gdiplus::Pen(line_clr, line_width), pt_begin, pt_end);
}

void DrawLine_dot( HDC hDC, WORD line_width, Color line_clr, Point pt_begin, Point pt_end )
{
	Graphics graph(hDC);

	// draw begin
	Gdiplus::Pen dotPen(line_clr, line_width);
	dotPen.SetDashStyle(Gdiplus::DashStyle::DashStyleDash);
	graph.DrawLine(&dotPen, pt_begin, pt_end);
}

void DrawLine_wave( HDC hDC, WORD line_width, Color line_clr, Point pt_begin, Point pt_end )
{
	Graphics graph(hDC);

	int step = 5;
	int AM = -2;

	int pt_num = (pt_end.X-pt_begin.X)/step +1;

	Point *pts = new Point[ pt_num ];
	pts[0] = pt_begin;

	int top = pt_begin.Y - AM;
	int bottom = pt_begin.Y + AM;

	for (int i=1; i<pt_num; i++)
	{
		pts[i].X = pts[i-1].X + step;
		pts[i].Y = pts[i-1].Y + AM;

		if ( pts[i].Y<=top || pts[i].Y>=bottom )
		{
			AM = -AM;
		}
	}

	pts[pt_num-1] = pt_end;

	graph.DrawLines(&Gdiplus::Pen(line_clr, line_width), pts, pt_num);
	// graph.DrawBeziers(&Gdiplus::Pen(line_clr, line_width), pts, pt_num);

	delete[]pts;
}

void DrawLine_mark( HDC hDC, WORD line_width, Color line_clr, Point pt_begin, Point pt_end )
{
	Graphics graph(hDC);

	// draw begin
	graph.FillRectangle(&Gdiplus::SolidBrush(Color(90, line_clr.GetR(), line_clr.GetG(), line_clr.GetB())), pt_begin.X, pt_begin.Y, pt_end.X-pt_begin.X, line_width);
}
void DrawNotes::DrawLine( HDC hDC, TP_NOTES_TYPE line_type, WORD line_width, Color line_clr, Point pt_begin, Point pt_end )
{
	switch (line_type)
	{
	case NOTES_LINE_STD:
		DrawLine_std(hDC, line_width, line_clr, pt_begin, pt_end);
		break;
	case NOTES_LINE_WAVE:
		DrawLine_wave(hDC, line_width, line_clr, pt_begin, pt_end);
		break;
	case NOTES_LINE_DOT:
		DrawLine_dot(hDC, line_width, line_clr, pt_begin, pt_end);
		break;
	case NOTES_LINE_MARK:
		DrawLine_mark(hDC, line_width, line_clr, pt_begin, pt_end);
		break;
	}
}

void DrawNotes::DrawLineFree( HDC hDC, WORD line_width, Color line_clr, std::vector<double> &note_pt )
{
	int pt_num = note_pt.size() / 2;
	if (pt_num < 2)
	{
		return;
	}

	Gdiplus::Graphics graph(hDC);
	Gdiplus::Pen myPen(line_clr, line_width);

	PointF *pts = new PointF[pt_num];
	int idx_pt = 0;
	for (UINT i = 0; i<note_pt.size(); i += 2)
	{
		pts[idx_pt].X = (REAL)note_pt[i];
		pts[idx_pt].Y = (REAL)note_pt[i+1];

		idx_pt++;

		// 		if (i + 2 < pt_num)
		// 		{
		// 			graph.DrawLine(&myPen, (REAL)note_pt[i], (REAL)note_pt[i + 1], (REAL)note_pt[i + 2], (REAL)note_pt[i + 3]);
		// 		}

	}

	//Gdiplus::GraphicsPath path;
	//path.AddBeziers(pts, pt_num);
	//path.AddCurve(pts, pt_num);

	graph.SetSmoothingMode(SmoothingModeAntiAlias);
	graph.DrawCurve(&myPen, pts, pt_num, 0.2);

	delete[]pts;
}

void DrawNotes::DrawRect( HDC hDC, WORD line_width, Color line_clr, Gdiplus::DashStyle line_style, Point pt_begin, Point pt_end )
{
	Graphics graph(hDC);

	Gdiplus::Pen myPen(line_clr, line_width);
	myPen.SetDashStyle(Gdiplus::DashStyle::DashStyleDash);

	// draw begin
	graph.DrawRectangle(&myPen, pt_begin.X, pt_begin.Y, pt_end.X-pt_begin.X, pt_end.Y-pt_begin.Y);
}

void DrawNotes::DrawImg( HDC hDC, CString imgFile, RECT &rt )
{
	Graphics graph(hDC);

	ColorMatrix colorMatrix=
	{
		1,0,0,0,0,
		0,1,0,0,0,
		0,0,1,0,0,
		0,0,0,0.7,0,
		0,0,0,0,1,
	};
	ImageAttributes imageAttr;
	imageAttr.SetColorMatrix(&colorMatrix);

	// ͼ
	Image img(imgFile);

	Rect dstRC(rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top);
	int x =img.GetWidth();
	int y =img.GetHeight();
	// 
	/*graph.DrawImage(&img,
		dstRC,
		0, 0, img.GetWidth(), img.GetHeight(),
		UnitPixel, &imageAttr, NULL, NULL);*/
	graph.DrawImage(&img,dstRC);
}