[자답 해결] GDI+ DrawCurve 작동이 잘 안되네요.
글쓴이: cppig1995 / 작성시간: 수, 2007/07/11 - 7:47오전
정적(static) 멤버 함수인 Drw2Shape::DrawCurve에서
전역(global) 함수인 CreateAppropriateBrush를 호출하며,
멤버 함수인 Drw2Shape::Draw는 sh->Type이 CurveTool일 때
Drw2Shape::DrawCurve(G, this)를 호출합니다.
그리고 CDrawing2View의 OnDraw에서 sh.Draw()를 호출합니다.
그런데 화면에 표시되는게 없네요. 저도 뭐가 잘못됐는지 모르겠습니다.
GDI+ 프로그래밍은 처음이라...
고수님들 도움 부탁드립니다.
Status Drw2Shape::DrawCurve(Graphics &G, const Drw2Shape *sh) { Brush *pBL; Status CabSt = CreateAppropriateBrush(&pBL, NULL, sh); if(CabSt != Ok) return CabSt; Pen P(pBL, sh->LineWidth); if(P.GetLastStatus() != Ok) return P.GetLastStatus(); G.DrawCurve(&P, sh->Points, sh->VarDataLen / sizeof(Point), sh->tension); delete pBL; return Ok; }
Status CreateAppropriateBrush(Brush **pBL, Brush **pBF, const Drw2Shape *sh) { try { if(pBL) { switch(sh->WhichBrush & LineMask) { case LineSolidBrush: *pBL = new SolidBrush(sh->LineColor1); break; case LineGradientBrush: *pBL = new LinearGradientBrush(sh->rect, sh->LineColor1, sh->LineColor2, sh->LineGradAngle); break; case LineHatchBrush: *pBL = new HatchBrush(sh->LineHatchStyle, sh->LineColor1, sh->LineColor2); break; } } if(pBF) { switch(sh->WhichBrush & FillMask) { case FillSolidBrush: *pBF = new SolidBrush(sh->FillColor1); break; case FillGradientBrush: *pBF = new LinearGradientBrush(sh->rect, sh->FillColor1, sh->FillColor2, sh->FillGradAngle); break; case FillHatchBrush: *pBF = new HatchBrush(sh->FillHatchStyle, sh->FillColor1, sh->FillColor2); break; } } } catch(...) { return OutOfMemory; } return Ok; }
void CDrawing2View::OnDraw(CDC* pDC) { CDrawing2Doc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; Graphics G(pDC->m_hDC); Drw2Shape sh; Point pts[] = {Point(25, 25), Point(35, 35), Point(45, 15), Point(50, 70), Point(5, 85), Point(35, 25)}; sh.Type = CurveTool; sh.LineColor1 = Color(255, 255, 153, 0); sh.LineColor2 = Color(255, 0, 153, 0); sh.WhichBrush = LineGradientBrush; sh.VarDataLen = sizeof(pts); sh.Points = pts; sh.LineHatchStyle = HatchStyleWeave; sh.tension = 0.7; sh.LineWidth = 30; sh.Draw(G); Invalidate(); }
Forums:
허걱! 자답
CreateAppropriateBrush에서 BrushStyle에 따라 브러시를 생성하게 만들어 놓고,
BrushStyle을 선에 선형 그래디언트 브러시를 사용하게(LineGradientBrush) 설정한 상태에서
해치스타일을 지정했네요;;;
이제 더블버퍼링이 필요해... 엄청난 깜빡거림
[cppig1995@localhost cppig1995]$ make
make: *** No targets specified and no makefile found. 멈춤.
[cppig1995@localhost cppig1995]$ make idea
make: *** 목표 'idea'를 만들 규칙이 없음. 멈춤.
Real programmers /* don't */ comment their code.
If it was hard to write, it should be /* hard to */ read.
댓글 달기