From ac5d3c7e3654b09720b2f181755c6fe1cac60804 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 4 Nov 2015 12:17:30 -0300 Subject: [PATCH] Cache font previews in FontPopup --- src/app/ui/font_popup.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/app/ui/font_popup.cpp b/src/app/ui/font_popup.cpp index 71077e4c8..dadec4bc3 100644 --- a/src/app/ui/font_popup.cpp +++ b/src/app/ui/font_popup.cpp @@ -24,6 +24,7 @@ #include "base/unique_ptr.h" #include "doc/conversion_she.h" #include "doc/image.h" +#include "doc/image_ref.h" #include "she/surface.h" #include "she/system.h" #include "ui/box.h" @@ -40,17 +41,20 @@ #endif #include +#include namespace app { using namespace ui; +static std::map g_thumbnails; + class FontItem : public ListItem { public: FontItem(const std::string& fn) : ListItem(base::get_file_title(fn)) - , m_filename(fn) - , m_loaded(false) { + , m_image(g_thumbnails[fn]) + , m_filename(fn) { } const std::string& filename() const { @@ -86,6 +90,9 @@ private: } void onSelect() override { + if (m_image) + return; + ListBox* listbox = static_cast(getParent()); if (!listbox) return; @@ -94,7 +101,6 @@ private: gfx::Color color = theme->colors.text(); try { - m_loaded = true; m_image.reset( render_text( m_filename, 16, @@ -107,6 +113,9 @@ private: View* view = View::getView(listbox); view->updateView(); listbox->makeChildVisible(this); + + // Save the thumbnail for future FontPopups + g_thumbnails[m_filename] = m_image; } catch (const std::exception&) { // Ignore errors @@ -114,9 +123,8 @@ private: } private: - base::UniquePtr m_image; + doc::ImageRef m_image; std::string m_filename; - bool m_loaded; }; FontPopup::FontPopup()