From 331f19e679662eec5d1f91dc75517ca40a813f5b Mon Sep 17 00:00:00 2001 From: Jinhao Date: Tue, 2 Jun 2015 03:44:35 +0800 Subject: [PATCH] fix menu image issue --- include/nana/gui/widgets/listbox.hpp | 1 - include/nana/gui/widgets/menu.hpp | 2 +- source/gui/widgets/menu.cpp | 7 ++++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/nana/gui/widgets/listbox.hpp b/include/nana/gui/widgets/listbox.hpp index 87309008..8720d5d5 100644 --- a/include/nana/gui/widgets/listbox.hpp +++ b/include/nana/gui/widgets/listbox.hpp @@ -17,7 +17,6 @@ #include "widget.hpp" #include #include -//#include #include #include diff --git a/include/nana/gui/widgets/menu.hpp b/include/nana/gui/widgets/menu.hpp index 883760cf..512d30d7 100644 --- a/include/nana/gui/widgets/menu.hpp +++ b/include/nana/gui/widgets/menu.hpp @@ -108,7 +108,7 @@ namespace nana virtual void background(graph_reference, window) = 0; virtual void item(graph_reference, const nana::rectangle&, const attr&) = 0; - virtual void item_image(graph_reference, const nana::point&, const paint::image&) = 0; + virtual void item_image(graph_reference, const nana::point&, unsigned image_px, const paint::image&) = 0; virtual void item_text(graph_reference, const nana::point&, const nana::string&, unsigned text_pixels, const attr&) = 0; virtual void sub_arrow(graph_reference, const nana::point&, unsigned item_pixels, const attr&) = 0; }; diff --git a/source/gui/widgets/menu.cpp b/source/gui/widgets/menu.cpp index 9f6ec24c..1050affa 100644 --- a/source/gui/widgets/menu.cpp +++ b/source/gui/widgets/menu.cpp @@ -144,9 +144,9 @@ namespace nana } } - void item_image(graph_reference graph, const nana::point& pos, const paint::image& img) + void item_image(graph_reference graph, const nana::point& pos, unsigned image_px, const paint::image& img) { - img.paste(graph, pos.x, pos.y); + img.stretch(img.size(), graph, { pos, ::nana::size(image_px, image_px)}); } void item_text(graph_reference graph, const nana::point& pos, const nana::string& text, unsigned text_pixels, const attr& at) @@ -524,6 +524,7 @@ namespace nana renderer->background(*graph_, *widget_); const unsigned item_h_px = _m_item_height(); + const unsigned image_px = item_h_px - 2; nana::rectangle item_r(2, 2, graph_->width() - 4, item_h_px); unsigned strpixels = item_r.width - 60; @@ -552,7 +553,7 @@ namespace nana nana::string text = API::transform_shortkey_text(m.text, hotkey, &hotkey_pos); if(m.image.empty() == false) - renderer->item_image(*graph_, nana::point(item_r.x + 5, item_r.y + (item_h_px - m.image.size().height) / 2), m.image); + renderer->item_image(*graph_, nana::point(item_r.x + 5, item_r.y + static_cast(item_h_px - image_px) / 2 - 1), image_px, m.image); renderer->item_text(*graph_, nana::point(item_r.x + 40, item_r.y + text_top_off), text, strpixels, attr);