From d66c4bafcecbe2b72785260f67d66a125f5783a7 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Wed, 17 Aug 2016 07:27:41 +0800 Subject: [PATCH] code refine --- source/gui/widgets/button.cpp | 15 +++++-------- source/gui/widgets/float_listbox.cpp | 32 +++++++++++----------------- source/gui/widgets/listbox.cpp | 14 +++++------- source/gui/widgets/menubar.cpp | 8 ++----- 4 files changed, 25 insertions(+), 44 deletions(-) diff --git a/source/gui/widgets/button.cpp b/source/gui/widgets/button.cpp index f4a1ab3f..a12a9415 100644 --- a/source/gui/widgets/button.cpp +++ b/source/gui/widgets/button.cpp @@ -287,14 +287,6 @@ namespace nana{ namespace drawerbase graph.gradual_rectangle(r, from, to, true); } - void draw_corner_point(::nana::paint::graphics& graph, const rectangle& r) - { - graph.set_pixel(r.x, r.y); - graph.set_pixel(r.right() - 1, r.y); - graph.set_pixel(r.right() - 1, r.bottom() - 1); - graph.set_pixel(r.x, r.bottom() - 1); - } - void trigger::_m_draw_border(graph_reference graph) { nana::rectangle r(graph.size()); @@ -303,10 +295,13 @@ namespace nana{ namespace drawerbase graph.frame_rectangle(r, lt, lt, rb, rb); graph.palette(false, colors::button_face); - draw_corner_point(graph, r); + + paint::draw draw(graph); + draw.corner(r, 1); graph.palette(false, static_cast(0x919191)); - draw_corner_point(graph, r.pare_off(1)); + + draw.corner(r.pare_off(1), 1); if (element_state::pressed == attr_.e_state) graph.rectangle(r, false, static_cast(0xc3c3c3)); diff --git a/source/gui/widgets/float_listbox.cpp b/source/gui/widgets/float_listbox.cpp index d47098cb..8ad3c144 100644 --- a/source/gui/widgets/float_listbox.cpp +++ b/source/gui/widgets/float_listbox.cpp @@ -36,28 +36,20 @@ namespace nana { if (state == StateHighlighted) { - ::nana::color clr(static_cast(0xafc7e3)); - graph.rectangle(r, false, clr); + graph.rectangle(r, false, static_cast(0xafc7e3)); - auto right = r.right() - 1; - auto bottom = r.bottom() - 1; graph.palette(false, colors::white); - graph.set_pixel(r.x, r.y); - graph.set_pixel(right, r.y); - graph.set_pixel(r.x, bottom); - graph.set_pixel(right, bottom); - --right; - --bottom; - graph.palette(false, clr); - graph.set_pixel(r.x + 1, r.y + 1); - graph.set_pixel(right, r.y + 1); - graph.set_pixel(r.x + 1, bottom); - graph.set_pixel(right, bottom); + paint::draw draw{ graph }; + draw.corner(r, 1); - nana::rectangle po_r(r); - graph.rectangle(po_r.pare_off(1), false, static_cast(0xEBF4FB)); - graph.gradual_rectangle(po_r.pare_off(1), static_cast(0xDDECFD), static_cast(0xC2DCFD), true); + graph.palette(false, static_cast(0xafc7e3)); + + auto inner_r = r; + draw.corner(inner_r.pare_off(1), 1); + + graph.rectangle(inner_r, false, static_cast(0xEBF4FB)); + graph.gradual_rectangle(inner_r.pare_off(1), static_cast(0xDDECFD), static_cast(0xC2DCFD), true); } else graph.rectangle(r, true, colors::white); @@ -83,7 +75,9 @@ namespace nana unsigned item_pixels(graph_reference graph) const { - return graph.text_extent_size(L"jHWn/?\\{[(0569").height + 4; + unsigned ascent, descent, ileading; + graph.text_metrics(ascent, descent, ileading); + return ascent + descent + 4; } };//end class item_renderer diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index 3ccb4fa0..0a3327a2 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -3940,18 +3940,14 @@ namespace nana void _m_draw_border(int x, int y, unsigned width) const { //Draw selecting inner rectangle - auto graph = essence_->graph; + rectangle r{ x, y, width, essence_->scheme_ptr->item_height }; - graph->rectangle({ x, y, width, essence_->scheme_ptr->item_height }, false, static_cast(0x99defd)); - graph->rectangle({ x + 1, y + 1, width - 2, essence_->scheme_ptr->item_height - 2 }, false, colors::white); + essence_->graph->rectangle(r, false, static_cast(0x99defd)); - const int right = x + width - 1; - const int bottom = y + essence_->scheme_ptr->item_height - 1; + essence_->graph->palette(false, colors::white); + paint::draw(*essence_->graph).corner(r, 1); - graph->set_pixel(x, y); - graph->set_pixel(x, bottom); - graph->set_pixel(right, y); - graph->set_pixel(right, bottom); + essence_->graph->rectangle(r.pare_off(1), false); } private: essence * const essence_; diff --git a/source/gui/widgets/menubar.cpp b/source/gui/widgets/menubar.cpp index 9d40d9ec..e810d053 100644 --- a/source/gui/widgets/menubar.cpp +++ b/source/gui/widgets/menubar.cpp @@ -112,13 +112,9 @@ namespace nana nana::rectangle r(pos, size); graph_.rectangle(r, false, border); - int right = pos.x + static_cast(size.width) - 1; - int bottom = pos.y + static_cast(size.height) - 1; graph_.palette(false, corner); - graph_.set_pixel(pos.x, pos.y); - graph_.set_pixel(right, pos.y); - graph_.set_pixel(pos.x, bottom); - graph_.set_pixel(right, bottom); + + paint::draw{ graph_ }.corner(r, 1); graph_.rectangle(r.pare_off(1), true, body); }