fix bug that round_rectangle always draws black background(#246)

This commit is contained in:
Jinhao 2017-08-27 11:14:50 +08:00
parent ec9ec611b4
commit 5c28e72320

View File

@ -1076,13 +1076,12 @@ namespace paint
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
if (pos1 != pos2) if (pos1 != pos2)
{ {
auto pen = ::CreatePen(PS_SOLID, 1, NANA_RGB(impl_->handle->get_color())); auto prv_pen = ::SelectObject(impl_->handle->context, ::CreatePen(PS_SOLID, 1, NANA_RGB(impl_->handle->get_color())));
::DeleteObject(::SelectObject(impl_->handle->context, pen));
::MoveToEx(impl_->handle->context, pos1.x, pos1.y, 0); ::MoveToEx(impl_->handle->context, pos1.x, pos1.y, 0);
::LineTo(impl_->handle->context, pos2.x, pos2.y); ::LineTo(impl_->handle->context, pos2.x, pos2.y);
DeleteObject(pen); ::DeleteObject(::SelectObject(impl_->handle->context, prv_pen));
} }
::SetPixel(impl_->handle->context, pos2.x, pos2.y, NANA_RGB(impl_->handle->get_color())); ::SetPixel(impl_->handle->context, pos2.x, pos2.y, NANA_RGB(impl_->handle->get_color()));
#elif defined(NANA_X11) #elif defined(NANA_X11)
@ -1110,12 +1109,11 @@ namespace paint
{ {
if (!impl_->handle) return; if (!impl_->handle) return;
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
auto pen = ::CreatePen(PS_SOLID, 1, NANA_RGB(impl_->handle->get_color())); auto prv_pen = ::SelectObject(impl_->handle->context, ::CreatePen(PS_SOLID, 1, NANA_RGB(impl_->handle->get_color())));
::DeleteObject(::SelectObject(impl_->handle->context, pen));
::LineTo(impl_->handle->context, pos.x, pos.y); ::LineTo(impl_->handle->context, pos.x, pos.y);
DeleteObject(pen); ::DeleteObject(::SelectObject(impl_->handle->context, prv_pen));
#elif defined(NANA_X11) #elif defined(NANA_X11)
Display* disp = nana::detail::platform_spec::instance().open_display(); Display* disp = nana::detail::platform_spec::instance().open_display();
impl_->handle->update_color(); impl_->handle->update_color();
@ -1278,17 +1276,13 @@ namespace paint
if (solid) if (solid)
{ {
auto pen = ::CreatePen(PS_SOLID, 1, NANA_RGB(impl_->handle->get_color())); auto prv_pen = ::SelectObject(impl_->handle->context, ::CreatePen(PS_SOLID, 1, NANA_RGB(impl_->handle->get_color())));
::DeleteObject(::SelectObject(impl_->handle->context, pen)); auto prv_brush = ::SelectObject(impl_->handle->context, ::CreateSolidBrush(NANA_RGB(solid_clr.px_color().value)));
auto brush = ::CreateSolidBrush(solid_clr.px_color().value);
auto pr_brush = ::SelectObject(impl_->handle->context, brush);
::RoundRect(impl_->handle->context, r.x, r.y, r.right(), r.bottom(), static_cast<int>(radius_x * 2), static_cast<int>(radius_y * 2)); ::RoundRect(impl_->handle->context, r.x, r.y, r.right(), r.bottom(), static_cast<int>(radius_x * 2), static_cast<int>(radius_y * 2));
::DeleteObject(::SelectObject(impl_->handle->context, pr_brush)); ::DeleteObject(::SelectObject(impl_->handle->context, prv_brush));
::DeleteObject(::SelectObject(impl_->handle->context, prv_pen));
DeleteObject(pen);
} }
else else
{ {