본문 바로가기
::public/윈도우즈 응용 프로그래밍

Direct2D - 붓(Brush)

by 해맑은욱 2019. 9. 27.

*컬러(color)

;D2D1_COLOR_F 구조체로 표현.

// D2D1_COLOR_F
typedef struct _D3DCOLORVALUE {
    float r;    // 빨강
    float g;    // 초록
    float b;    // 
    float a;    // 0=투명,1=불투명
} D3DCOLORVALUE;
cs

 

*컬러 클래스

// ColorF(UINT32 rgb, FLOAT a = 1.0)
ColorF(0x9ACD321.0f);
// ColorF(Enum knownColor, FLOAT a = 1.0)
ColorF(D2D1::ColorF::Black, 1.0f);
// ColorF(FLOAT red, FLOAT green, FLOAT blue, FLOAT alpha = 1.0)
ColorF(0.93f, 0.94f, 0.96f, 1.0f);
cs

*붓(brush)

;ID2D1Brush 인터페이스 객체.

ID2D1SolidColorBrush: 단색 붓.

ID2D1LinearGradientBrush: 선형 계조 붓.

ID2D1RadialGradientBrush: 방사형 계조 붓.

ID2D1BitmapBrush: 비트맵 붓.

// 칠할 사각형 모양을 정의함.
D2D1_RECT_F rcBrushRect = D2D1::RectF(50150150);
 
// 단색 붓 데모.
gp_render_target->SetTransform(D2D1::Matrix3x2F::Translation(D2D1::SizeF(55)));
gp_render_target->FillRectangle(&rcBrushRect, mp_yellow_brush);
gp_render_target->DrawRectangle(&rcBrushRect, mp_black_brush, 1NULL);
 
// 계조 명세 지점 구조체인 D2D1_GRADIENT_STOP 구조체의 배열을 생성.
ID2D1GradientStopCollection* pGradientStops = NULL;
 
D2D1_GRADIENT_STOP gradientStops[2];
gradientStops[0].color = D2D1::ColorF(D2D1::ColorF::Yellow, 1);
gradientStops[0].position = 0.0f;
gradientStops[1].color = D2D1::ColorF(D2D1::ColorF::ForestGreen, 1);
gradientStops[1].position = 1.0f;
// D2D1_GRADIENT_STOP 구조체의 배열로부터 ID2D1GradientStopCollection 객체 생성.
gp_render_target->CreateGradientStopCollection(
    gradientStops, 2, D2D1_GAMMA_2_2, D2D1_EXTEND_MODE_CLAMP, &pGradientStops);
 
// GradientBruch 생성.
ID2D1LinearGradientBrush* pLinearGradientBrush = NULL;
// ID2D1GradientStopCollection 객체로부터 선형 계조 붓 생성. 
// 계조 축은 사각형의 왼쪽 상단 모서리에서 시작해서 오른쪽 하단 모서리에서 끝남.
gp_render_target->CreateLinearGradientBrush(
    D2D1::LinearGradientBrushProperties(D2D1::Point2F(00), D2D1::Point2F(150150)), 
    pGradientStops, 
    &pLinearGradientBrush);
 
// GradientBruch 생성.
ID2D1RadialGradientBrush* pRadialGradientBrush = NULL;
// ID2D1GradientStopCollection 객체로부터 방사형 계조 붓 생성. 
// 계조의 중심은 상자의 중심이며 계조 원점의 오프셋은 (0,0)임.
gp_render_target->CreateRadialGradientBrush(
    D2D1::RadialGradientBrushProperties(D2D1::Point2F(7575), D2D1::Point2F(00), 7575), 
    pGradientStops, 
    &pRadialGradientBrush);
 
// 선형 계조 붓 데모.
gp_render_target->SetTransform(D2D1::Matrix3x2F::Translation(D2D1::SizeF(2005)));
gp_render_target->FillRectangle(&rcBrushRect, pLinearGradientBrush);
gp_render_target->DrawRectangle(&rcBrushRect, mp_black_brush, 1NULL);
    
// 방사형 계조 붓 데모.
gp_render_target->SetTransform(D2D1::Matrix3x2F::Translation(D2D1::SizeF(5200)));
D2D1_ELLIPSE ellipse = D2D1::Ellipse(D2D1::Point2F(75.f, 75.f), 75.f, 75.f);
gp_render_target->FillEllipse(ellipse, pRadialGradientBrush);
gp_render_target->DrawEllipse(ellipse, mp_black_brush, 1NULL);
cs

 

'::public > 윈도우즈 응용 프로그래밍' 카테고리의 다른 글

Direct2D - 텍스트  (0) 2019.09.30
Direct2D - 비트맵(Bitmap)  (0) 2019.09.27
Direct2D - 기하  (0) 2019.09.26
Direct2D - 변환  (0) 2019.09.26
Direct2D - 렌더타겟  (0) 2019.09.26