WD_HBRUSH wdCreateSolidBrush(WD_HCANVAS hCanvas, WD_COLOR color) { if(d2d_enabled()) { d2d_canvas_t* c = (d2d_canvas_t*) hCanvas; ID2D1SolidColorBrush* b; D2D_COLOR_F clr; HRESULT hr; d2d_init_color(&clr, color); hr = ID2D1RenderTarget_CreateSolidColorBrush( c->target, &clr, NULL, &b); if(FAILED(hr)) { WD_TRACE_HR("wdCreateSolidBrush: " "ID2D1RenderTarget::CreateSolidColorBrush() failed."); return NULL; } return (WD_HBRUSH) b; } else { dummy_GpSolidFill* b; int status; status = gdix_vtable->fn_CreateSolidFill(color, &b); if(status != 0) { WD_TRACE("wdCreateSolidBrush: " "GdipCreateSolidFill() failed. [%d]", status); return NULL; } return (WD_HBRUSH) b; } }
static HRESULT STDMETHODCALLTYPE d2d_dc_render_target_CreateSolidColorBrush(ID2D1DCRenderTarget *iface, const D2D1_COLOR_F *color, const D2D1_BRUSH_PROPERTIES *desc, ID2D1SolidColorBrush **brush) { struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface); TRACE("iface %p, color %p, desc %p, brush %p.\n", iface, color, desc, brush); return ID2D1RenderTarget_CreateSolidColorBrush(render_target->dxgi_target, color, desc, brush); }
static ID2D1Brush *makeSolidBrush(uiDrawBrush *b, ID2D1RenderTarget *rt, D2D1_BRUSH_PROPERTIES *props) { D2D1_COLOR_F color; ID2D1SolidColorBrush *brush; HRESULT hr; color.r = b->R; color.g = b->G; color.b = b->B; color.a = b->A; hr = ID2D1RenderTarget_CreateSolidColorBrush(rt, &color, props, &brush); if (hr != S_OK) logHRESULT("error creating solid brush in makeSolidBrush()", hr); return (ID2D1Brush *) brush; }
static void test_color_brush(void) { D2D1_MATRIX_3X2_F matrix, tmp_matrix; D2D1_BRUSH_PROPERTIES brush_desc; D2D1_COLOR_F color, tmp_color; ID2D1SolidColorBrush *brush; IDXGISwapChain *swapchain; ID2D1RenderTarget *rt; ID3D10Device1 *device; IDXGISurface *surface; D2D1_RECT_F rect; float opacity; HWND window; HRESULT hr; if (!(device = create_device())) { skip("Failed to create device, skipping tests.\n"); return; } window = CreateWindowA("static", "d2d1_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 640, 480, NULL, NULL, NULL, NULL); swapchain = create_swapchain(device, window, TRUE); hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_IDXGISurface, (void **)&surface); ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr); rt = create_render_target(surface); ok(!!rt, "Failed to create render target.\n"); ID2D1RenderTarget_SetDpi(rt, 192.0f, 48.0f); ID2D1RenderTarget_SetAntialiasMode(rt, D2D1_ANTIALIAS_MODE_ALIASED); set_color(&color, 0.0f, 0.0f, 0.0f, 0.0f); hr = ID2D1RenderTarget_CreateSolidColorBrush(rt, &color, NULL, &brush); ok(SUCCEEDED(hr), "Failed to create brush, hr %#x.\n", hr); opacity = ID2D1SolidColorBrush_GetOpacity(brush); ok(opacity == 1.0f, "Got unexpected opacity %.8e.\n", opacity); set_matrix_identity(&matrix); ID2D1SolidColorBrush_GetTransform(brush, &tmp_matrix); ok(!memcmp(&tmp_matrix, &matrix, sizeof(matrix)), "Got unexpected matrix {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e}.\n", tmp_matrix._11, tmp_matrix._12, tmp_matrix._21, tmp_matrix._22, tmp_matrix._31, tmp_matrix._32); tmp_color = ID2D1SolidColorBrush_GetColor(brush); ok(!memcmp(&tmp_color, &color, sizeof(color)), "Got unexpected color {%.8e, %.8e, %.8e, %.8e}.\n", tmp_color.r, tmp_color.g, tmp_color.b, tmp_color.a); ID2D1SolidColorBrush_Release(brush); set_color(&color, 0.0f, 1.0f, 0.0f, 0.8f); brush_desc.opacity = 0.3f; set_matrix_identity(&matrix); scale_matrix(&matrix, 2.0f, 2.0f); brush_desc.transform = matrix; hr = ID2D1RenderTarget_CreateSolidColorBrush(rt, &color, &brush_desc, &brush); ok(SUCCEEDED(hr), "Failed to create brush, hr %#x.\n", hr); opacity = ID2D1SolidColorBrush_GetOpacity(brush); ok(opacity == 0.3f, "Got unexpected opacity %.8e.\n", opacity); ID2D1SolidColorBrush_GetTransform(brush, &tmp_matrix); ok(!memcmp(&tmp_matrix, &matrix, sizeof(matrix)), "Got unexpected matrix {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e}.\n", tmp_matrix._11, tmp_matrix._12, tmp_matrix._21, tmp_matrix._22, tmp_matrix._31, tmp_matrix._32); tmp_color = ID2D1SolidColorBrush_GetColor(brush); ok(!memcmp(&tmp_color, &color, sizeof(color)), "Got unexpected color {%.8e, %.8e, %.8e, %.8e}.\n", tmp_color.r, tmp_color.g, tmp_color.b, tmp_color.a); ID2D1RenderTarget_BeginDraw(rt); set_color(&color, 0.0f, 0.0f, 1.0f, 1.0f); ID2D1RenderTarget_Clear(rt, &color); ID2D1SolidColorBrush_SetOpacity(brush, 1.0f); set_rect(&rect, 40.0f, 120.0f, 120.0f, 360.0f); ID2D1RenderTarget_FillRectangle(rt, &rect, (ID2D1Brush *)brush); set_matrix_identity(&matrix); scale_matrix(&matrix, 0.5f, 2.0f); translate_matrix(&matrix, 320.0f, 240.0f); rotate_matrix(&matrix, M_PI / 4.0f); ID2D1RenderTarget_SetTransform(rt, &matrix); set_color(&color, 1.0f, 0.0f, 0.0f, 0.625f); ID2D1SolidColorBrush_SetColor(brush, &color); ID2D1SolidColorBrush_SetOpacity(brush, 0.75f); set_rect(&rect, -80.0f, -60.0f, 80.0f, 60.0f); ID2D1RenderTarget_FillRectangle(rt, &rect, (ID2D1Brush *)brush); hr = ID2D1RenderTarget_EndDraw(rt, NULL, NULL); ok(SUCCEEDED(hr), "Failed to end draw, hr %#x.\n", hr); ok(compare_surface(surface, "6d1218fca5e21fb7e287b3a439d60dbc251f5ceb"), "Surface does not match.\n"); ID2D1SolidColorBrush_Release(brush); ID2D1RenderTarget_Release(rt); IDXGISurface_Release(surface); IDXGISwapChain_Release(swapchain); ID3D10Device1_Release(device); DestroyWindow(window); }