Skip to content

Commit 2810501

Browse files
committed
Added UIFilePickerDialog support for ecode (SpartanJ/ecode#903) and improved the dialog.
1 parent c0c28b9 commit 2810501

10 files changed

Lines changed: 540 additions & 122 deletions

File tree

include/eepp/graphics/fonttruetype.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class IOStream;
1313

1414
namespace EE { namespace Graphics {
1515

16+
struct FontDesc;
17+
1618
class EE_API FontTrueType : public Font {
1719
public:
1820
static FontTrueType* New( const std::string& FontName );
@@ -35,6 +37,8 @@ class EE_API FontTrueType : public Font {
3537

3638
const Font::Info& getInfo() const;
3739

40+
bool getFontDesc( FontDesc& desc ) const;
41+
3842
const Uint32& getFaceIndex() const { return mFaceIndex; }
3943

4044
Glyph getGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, bool italic,

include/eepp/graphics/systemfontresolver.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,32 @@ struct FontDesc {
6262
FontStretch stretch{ FontStretch::Normal };
6363
bool italic{ false };
6464
bool monospace{ false };
65+
66+
std::string getFileKey() const { return path + "#" + String::toString( faceIndex ); }
67+
68+
std::string getStyleKey() const {
69+
return String::toLower( family ) + "#" + String::toString( static_cast<Uint32>( weight ) ) +
70+
"#" + String::toString( static_cast<Uint32>( stretch ) ) + "#" +
71+
String::toString( italic ? 1 : 0 ) + "#" + String::toString( faceIndex );
72+
}
73+
74+
bool sameFile( const FontDesc& other ) const {
75+
return path == other.path && faceIndex == other.faceIndex;
76+
}
77+
78+
bool sameFile( const std::string& otherPath, Uint32 otherFaceIndex = 0 ) const {
79+
return path == otherPath && faceIndex == otherFaceIndex;
80+
}
81+
82+
bool sameStyle( const FontDesc& other ) const { return getStyleKey() == other.getStyleKey(); }
83+
84+
bool operator==( const FontDesc& other ) const {
85+
return family == other.family && path == other.path && faceIndex == other.faceIndex &&
86+
weight == other.weight && stretch == other.stretch && italic == other.italic &&
87+
monospace == other.monospace;
88+
}
89+
90+
bool operator!=( const FontDesc& other ) const { return !( *this == other ); }
6591
};
6692

6793
class EE_API SystemFontResolver {

include/eepp/ui/tools/uifontpickerdialog.hpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,20 @@ struct UIFontSelection {
3333
bool strikeThrough{ false };
3434
bool antialiasing{ true };
3535
Color color{ Color::White };
36+
37+
bool operator==( const UIFontSelection& other ) const {
38+
return font == other.font && size == other.size && underline == other.underline &&
39+
strikeThrough == other.strikeThrough && antialiasing == other.antialiasing &&
40+
color == other.color;
41+
}
42+
43+
bool operator!=( const UIFontSelection& other ) const { return !( *this == other ); }
3644
};
3745

3846
class EE_API UIFontPickerDialog : public UIWindow {
3947
public:
4048
using FontPickedCb = std::function<void( const UIFontSelection& )>;
49+
using FontSelectionChangedCb = std::function<void( const UIFontSelection& )>;
4150

4251
enum Flags {
4352
MonospaceOnly = 1 << 0,
@@ -73,6 +82,8 @@ class EE_API UIFontPickerDialog : public UIWindow {
7382

7483
void setOnFontPicked( FontPickedCb cb );
7584

85+
void setOnFontSelectionChanged( FontSelectionChangedCb cb );
86+
7687
UIPushButton* getButtonOK() const;
7788

7889
UIPushButton* getButtonCancel() const;
@@ -100,10 +111,13 @@ class EE_API UIFontPickerDialog : public UIWindow {
100111
KeyBindings::Shortcut mCloseShortcut{ KEY_UNKNOWN };
101112
UIFontSelection mSelection;
102113
FontPickedCb mFontPickedCb;
114+
FontSelectionChangedCb mFontSelectionChangedCb;
103115
std::vector<FontDesc> mFonts;
104116
std::vector<std::string> mFamilies;
105117
std::vector<FontStyleEntry> mStyles;
106118
std::vector<Uint32> mSizes;
119+
UnorderedSet<std::string> mLoadedFontKeys;
120+
UnorderedMap<std::string, std::string> mFontTags;
107121
std::shared_ptr<Models::Model> mFamilyModel;
108122
std::shared_ptr<Models::Model> mStyleModel;
109123
std::shared_ptr<Models::Model> mSizeModel;
@@ -125,13 +139,14 @@ class EE_API UIFontPickerDialog : public UIWindow {
125139
UICheckBox* mAntialiasing{ nullptr };
126140
UICheckBox* mUnderline{ nullptr };
127141
UICheckBox* mStrikeThrough{ nullptr };
128-
UIPushButton* mColorButton{ nullptr };
142+
UIWidget* mColorButton{ nullptr };
129143
UIPushButton* mButtonOK{ nullptr };
130144
UIPushButton* mButtonCancel{ nullptr };
131145
UIPushButton* mButtonApply{ nullptr };
132146
UIPushButton* mButtonBrowse{ nullptr };
133147
bool mUpdating{ false };
134148
bool mLoadingFonts{ false };
149+
bool mSelectionColorExplicit{ false };
135150
Uint64 mLoadFontsTaskId{ 0 };
136151

137152
struct LoadFontsRequest {
@@ -156,20 +171,30 @@ class EE_API UIFontPickerDialog : public UIWindow {
156171

157172
void sortFonts();
158173

174+
void mergeFontManagerFonts( std::vector<FontDesc>& fonts );
175+
176+
void updateFontTags();
177+
159178
void setFontsLoading( bool loading );
160179

180+
void updateDefaultSelectionColor();
181+
161182
void updateFamilies();
162183

163184
void updateStyles();
164185

165-
void updateSelectionFromLists();
186+
void updateSelectionFromLists( bool notify = true );
187+
188+
void emitSelectionChanged();
166189

167190
void updatePreview();
168191

169192
void selectInitialRows();
170193

171194
void selectFamily( const std::string& family );
172195

196+
void selectRegularStyle();
197+
173198
void selectStyle( const FontDesc& desc );
174199

175200
void selectSize( Uint32 size );

src/eepp/graphics/fonttruetype.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,20 @@ const FontTrueType::Info& FontTrueType::getInfo() const {
545545
return mInfo;
546546
}
547547

548+
bool FontTrueType::getFontDesc( FontDesc& desc ) const {
549+
if ( !loaded() || mInfo.filename.empty() || mInfo.fontpath.empty() )
550+
return false;
551+
552+
desc = FontDesc{};
553+
desc.family = mInfo.family.empty() ? getName() : mInfo.family;
554+
desc.path = mInfo.fontpath + mInfo.filename;
555+
desc.faceIndex = getFaceIndex();
556+
desc.weight = isBold() || isBoldItalic() ? FontWeight::Bold : FontWeight::Normal;
557+
desc.italic = isItalic() || isBoldItalic();
558+
desc.monospace = isIdentifiedAsMonospace();
559+
return !desc.family.empty() && !desc.path.empty();
560+
}
561+
548562
void FontTrueType::updateFontInternalId() {
549563
auto fontInternalId = fontsInternalIds.find( mInfo.family );
550564
if ( fontsInternalIds.end() == fontInternalId ) {

0 commit comments

Comments
 (0)