6 #include <wx/dcmemory.h>
7 #include <wx/filedlg.h>
14 if (doAll && formats.
size() > 1) {
15 desc +=
"All supported formats|";
17 desc +=
"*." + format.extension +
";";
26 desc += format.description +
" (*." + format.extension +
")|*." + format.extension;
32 const std::string& fileMask,
33 std::string& defaultDir,
35 wxFileDialog dialog(
nullptr, title,
"", defaultDir, fileMask, flags);
36 if (dialog.ShowModal() == wxID_CANCEL) {
39 std::string s(dialog.GetPath());
40 Path path(std::move(s));
41 defaultDir = path.parentPath().native();
42 return std::make_pair(path, !fileMask.empty() ? dialog.GetFilterIndex() : -1);
46 static std::string defaultDir =
"";
48 doFileDialog(title, getDesc(formats,
true), defaultDir, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
50 return pathAndIndex->first;
57 static std::string defaultDir =
"";
59 doFileDialog(title, getDesc(formats,
false), defaultDir, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
61 const int index = pathAndIndex->second;
63 const std::string ext = formats[index].extension;
64 pathAndIndex->first.replaceExtension(ext);
66 return pathAndIndex->first;
72 static Size getSubscriptSize(
const std::wstring& text) {
74 if (!text.empty() && text[0] == L
'-') {
77 for (; size < text.size(); ++size) {
78 const char c = text[size];
79 if ((c < L'0' || c > L
'9') && (c < L'a' || c > L
'z') && (c < L'A' || c > L
'Z')) {
89 wxPoint actPoint = point;
90 const wxFont font = dc.GetFont();
91 const wxFont subcriptFont = font.Smaller();
93 while ((n = text.find_first_of(L
"_^", m)) != std::string::npos) {
94 const bool isSubscript = text[n] ==
'_';
95 std::wstring part = text.substr(m, n - m);
96 wxSize extent = dc.GetTextExtent(part);
98 dc.DrawText(part, actPoint);
100 actPoint.x += extent.x;
101 const Size subscriptSize = getSubscriptSize(text.substr(n + 1));
102 const std::wstring subscript = text.substr(n + 1, subscriptSize);
103 dc.SetFont(subcriptFont);
104 wxPoint subscriptPoint = isSubscript ? wxPoint(actPoint.x + 2, actPoint.y + extent.y / 3)
105 : wxPoint(actPoint.x + 2, actPoint.y - extent.y / 4);
107 dc.DrawText(subscript, subscriptPoint);
108 actPoint.x = subscriptPoint.x + dc.GetTextExtent(subscript).x;
111 m = n + 1 + subscriptSize;
114 dc.DrawText(text.substr(m), actPoint);
123 std::stringstream ss;
124 if (absValue == 0._f || (absValue >= 1._f / decimalThreshold && absValue <= decimalThreshold)) {
127 ss << std::setprecision(precision) << std::scientific << value;
129 std::string s = ss.str();
131 std::wstring printable;
135 bool exponent =
false;
136 for (
Size i = 0; i < s.size(); ++i) {
144 printable += L
"\u00D710^";
164 wxSize extent = dc.GetTextExtent(text);
165 if (text.find(L
"^") != std::string::npos) {
172 offset.x -= extent.x;
175 offset.x -= extent.x / 2;
178 offset.y -= extent.y;
181 offset.y -= extent.y / 2;
187 wxFont font = dc.GetFont();
189 dc.SetTextForeground(wxColour(label.color));
190 font.SetPointSize(label.fontSize);
192 const wxPoint origin(label.position + getOriginOffset(dc, label.align, label.text));
uint32_t Size
Integral type used to index arrays (by default).
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
INLINE auto abs(const T &f)
#define NAMESPACE_SPH_END
const NothingType NOTHING
void printLabels(wxDC &dc, ArrayView< const IRenderOutput::Label > labels)
void drawTextWithSubscripts(wxDC &dc, const std::wstring &text, const wxPoint point)
std::wstring toPrintableString(const Float value, const Size precision, const Float decimalThreshold)
Converts the value to a printable string.
Optional< Path > doSaveFileDialog(const std::string &title, Array< FileFormat > &&formats)
Optional< Path > doOpenFileDialog(const std::string &title, Array< FileFormat > &&formats)
Random utility functions for drawing stuff to DC.
Object providing safe access to continuous memory of data.
INLINE TCounter size() const
Generic dynamically allocated resizable storage.
constexpr INLINE bool has(const TEnum flag) const
Checks if the object has a given flag.
Wrapper of type value of which may or may not be present.
Object representing a path on a filesystem.