From 855694e8c7bd9717d7e4bd393bcabc67da7aa6cb Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sun, 30 Apr 2017 04:32:23 +0800 Subject: [PATCH] fix text_editor line color issue --- .../gui/widgets/skeletons/text_editor.hpp | 2 +- source/gui/widgets/skeletons/text_editor.cpp | 23 ++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/include/nana/gui/widgets/skeletons/text_editor.hpp b/include/nana/gui/widgets/skeletons/text_editor.hpp index a4eb16d8..3fe3e157 100644 --- a/include/nana/gui/widgets/skeletons/text_editor.hpp +++ b/include/nana/gui/widgets/skeletons/text_editor.hpp @@ -213,7 +213,7 @@ namespace nana{ namespace widgets bool try_refresh(); private: - nana::color _m_draw_colored_area(paint::graphics& graph, std::size_t line_pos); + nana::color _m_draw_colored_area(paint::graphics& graph, const std::pair& row, bool whole_line); std::vector _m_render_text(const ::nana::color& text_color); void _m_pre_calc_lines(std::size_t line_off, std::size_t lines); diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index eed730ea..1981fb11 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -2656,17 +2656,24 @@ namespace nana{ namespace widgets return false; } - color text_editor::_m_draw_colored_area(paint::graphics& graph, std::size_t line_pos) + color text_editor::_m_draw_colored_area(paint::graphics& graph, const std::pair& row, bool whole_line) { - auto area = impl_->colored_area.find(line_pos); + auto area = impl_->colored_area.find(row.first); if (area) { if (!area->bgcolor.invisible()) { - auto top = _m_caret_to_screen(upoint{ 0, static_cast(line_pos) }).y; + auto const height = line_height(); - const unsigned pixels = line_height(); - const rectangle area_r = { text_area_.area.x, top, width_pixels(), static_cast(pixels * impl_->capacities.behavior->take_lines(line_pos))}; + auto top = _m_caret_to_screen(upoint{ 0, static_cast(row.first) }).y; + std::size_t lines = 1; + + if (whole_line) + lines = impl_->capacities.behavior->take_lines(row.first); + else + top += height * row.second; + + const rectangle area_r = { text_area_.area.x, top, width_pixels(), static_cast(height * lines) }; if (API::is_transparent_background(this->window_)) graph.blend(area_r, area->bgcolor, 1); @@ -2705,7 +2712,7 @@ namespace nana{ namespace widgets if (row.first >= line_count) break; - auto fgcolor = _m_draw_colored_area(graph_, row.first); + auto fgcolor = _m_draw_colored_area(graph_, row, false); if (fgcolor.invisible()) fgcolor = text_color; @@ -2945,11 +2952,11 @@ namespace nana{ namespace widgets if (!API::dev::copy_transparent_background(window_, update_area, graph_, update_area.position())) { - _m_draw_colored_area(graph_, pos); + _m_draw_colored_area(graph_, { pos, 0 }, true); graph_.rectangle(update_area, true, API::bgcolor(window_)); } else - _m_draw_colored_area(graph_, pos); + _m_draw_colored_area(graph_, { pos, 0 }, true); auto fgcolor = API::fgcolor(window_); auto text_ptr = textbase().getline(pos).c_str();