[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 0918951 2/4: Relocate load_image() to promote
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 0918951 2/4: Relocate load_image() to promote reuse |
Date: |
Thu, 9 Aug 2018 11:26:00 -0400 (EDT) |
branch: master
commit 0918951d116b0a3d920bd488af11c72b5e387b79
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Relocate load_image() to promote reuse
Moved load_image() to 'icon_monger.?pp'. It belongs there because its
implementation seems to be a derivative of icon_monger::CreateBitmap().
---
group_quote_pdf_gen_wx.cpp | 51 +---------------------------------------------
icon_monger.cpp | 47 +++++++++++++++++++++++++++++++++++++++++-
icon_monger.hpp | 3 +++
3 files changed, 50 insertions(+), 51 deletions(-)
diff --git a/group_quote_pdf_gen_wx.cpp b/group_quote_pdf_gen_wx.cpp
index 2c4d1a9..c052fb5 100644
--- a/group_quote_pdf_gen_wx.cpp
+++ b/group_quote_pdf_gen_wx.cpp
@@ -26,9 +26,9 @@
#include "alert.hpp"
#include "assert_lmi.hpp"
#include "calendar_date.hpp" // jdn_t()
-#include "data_directory.hpp" // AddDataDir()
#include "force_linking.hpp"
#include "html.hpp"
+#include "icon_monger.hpp" // load_image()
#include "ledger.hpp"
#include "ledger_invariant.hpp"
#include "ledger_text_formats.hpp" // ledger_format()
@@ -37,7 +37,6 @@
#include "mc_enum_types_aux.hpp" // is_subject_to_ill_reg()
#include "miscellany.hpp" // split_into_lines()
#include "oecumenic_enumerations.hpp"
-#include "path_utility.hpp" // fs::path inserter
#include "pdf_writer_wx.hpp"
#include "ssize_lmi.hpp"
#include "version.hpp"
@@ -45,9 +44,6 @@
#include "wx_utility.hpp" // ConvertDateToWx()
#include "wx_workarounds.hpp" // wxDCTextColorChanger
-#include <boost/filesystem/operations.hpp>
-#include <boost/filesystem/path.hpp>
-
#include <wx/datetime.h>
#include <wx/image.h>
@@ -176,51 +172,6 @@ std::vector<extra_summary_field>
parse_extra_report_fields(std::string const& s)
return fields;
}
-/// Load the image from the given file.
-///
-/// Look for the file in the current working directory, or, if that
-/// fails, in lmi's data directory. Warn if it's not found in either
-/// of those locations, or if it's found but cannot be loaded.
-///
-/// Diagnosed failures are presented merely as warnings so that quotes
-/// can be produced even with a generic system built from the free
-/// public source code only, with no (proprietary) images.
-
-wxImage load_image(char const* file)
-{
- fs::path image_path(file);
- if(!fs::exists(image_path))
- {
- image_path = AddDataDir(file);
- }
- if(!fs::exists(image_path))
- {
- warning()
- << "Unable to find image '"
- << image_path
- << "'. Try reinstalling."
- << "\nA blank image will be used instead."
- << LMI_FLUSH
- ;
- return wxImage();
- }
-
- wxImage image(image_path.string().c_str(), wxBITMAP_TYPE_PNG);
- if(!image.IsOk())
- {
- warning()
- << "Unable to load image '"
- << image_path
- << "'. Try reinstalling."
- << "\nA blank image will be used instead."
- << LMI_FLUSH
- ;
- return wxImage();
- }
-
- return image;
-}
-
enum enum_group_quote_columns
{e_col_number
,e_col_name
diff --git a/icon_monger.cpp b/icon_monger.cpp
index 14a7ccb..ab240bc 100644
--- a/icon_monger.cpp
+++ b/icon_monger.cpp
@@ -25,7 +25,7 @@
#include "alert.hpp"
#include "contains.hpp"
-#include "data_directory.hpp"
+#include "data_directory.hpp" // AddDataDir()
#include "path_utility.hpp" // fs::path inserter
#include <boost/filesystem/operations.hpp>
@@ -253,3 +253,48 @@ wxBitmap icon_monger::CreateBitmap
return wxBitmap(image);
}
+/// Load the image from the given file.
+///
+/// Look for the file in the current working directory, or, if that
+/// fails, in lmi's data directory. Warn if it's not found in either
+/// of those locations, or if it's found but cannot be loaded.
+///
+/// Diagnosed failures are presented merely as warnings so that quotes
+/// can be produced even with a generic system built from the free
+/// public source code only, with no (proprietary) images.
+
+wxImage load_image(char const* file)
+{
+ fs::path image_path(file);
+ if(!fs::exists(image_path))
+ {
+ image_path = AddDataDir(file);
+ }
+ if(!fs::exists(image_path))
+ {
+ warning()
+ << "Unable to find image '"
+ << image_path
+ << "'. Try reinstalling."
+ << "\nA blank image will be used instead."
+ << LMI_FLUSH
+ ;
+ return wxImage();
+ }
+
+ wxImage image(image_path.string().c_str(), wxBITMAP_TYPE_PNG);
+ if(!image.IsOk())
+ {
+ warning()
+ << "Unable to load image '"
+ << image_path
+ << "'. Try reinstalling."
+ << "\nA blank image will be used instead."
+ << LMI_FLUSH
+ ;
+ return wxImage();
+ }
+
+ return image;
+}
+
diff --git a/icon_monger.hpp b/icon_monger.hpp
index dc7c882..bec100f 100644
--- a/icon_monger.hpp
+++ b/icon_monger.hpp
@@ -25,6 +25,7 @@
#include "config.hpp"
#include <wx/artprov.h>
+#include <wx/image.h>
#include <map>
#include <set>
@@ -54,5 +55,7 @@ class icon_monger
std::set<std::string> lmi_specific_icon_names_;
};
+wxImage load_image(char const* file);
+
#endif // icon_monger_hpp