diff --git a/bin/assets/colorschemes/colorschemes.conf b/bin/assets/colorschemes/colorschemes.conf index 6e16a6bfe..e9b1c253c 100644 --- a/bin/assets/colorschemes/colorschemes.conf +++ b/bin/assets/colorschemes/colorschemes.conf @@ -23,6 +23,31 @@ string = #f7c95c operator = #93DDFA function = #93DDFA +[eepp] +background = #2e2e32 +text = #e1e1e6 +caret = #93DDFA +selection = #48484f +line_highlight = #343438 +line_number = #525259 +line_number2 = #83838f +line_number_background = #2e2e32 +whitespace = #54575b +line_break_column = #54575b99 +matching_bracket = #FFFFFF33 +matching_selection = #FFFFFF33 + +normal = #cfcfcf +symbol = #cfcfcf +comment = #cd8b00 +keyword = #8a98ff,bold +keyword2 = #8abdff,bold +number = #f0ad6d +literal = #808000,bold +string = #ffcd8b +operator = #cfbfad +function = #76c0d0,bold + [fall] background = #343233 text = #c4b398 diff --git a/include/eepp/graphics/fonttruetype.hpp b/include/eepp/graphics/fonttruetype.hpp index 0b9503102..eeaea143b 100644 --- a/include/eepp/graphics/fonttruetype.hpp +++ b/include/eepp/graphics/fonttruetype.hpp @@ -52,6 +52,12 @@ class EE_API FontTrueType : public Font { FontTrueType& operator=( const FontTrueType& right ); + bool getBoldAdvanceSameAsRegular() const; + + /** You can enable this to not add more space in the advance properties for bold fonts, so they + * advance like a regular glyph (useful for monospaced fonts). */ + void setBoldAdvanceSameAsRegular( bool boldAdvanceSameAsRegular ); + protected: explicit FontTrueType( const std::string& FontName ); @@ -106,6 +112,7 @@ class EE_API FontTrueType : public Font { mutable PageTable mPages; ///< Table containing the glyphs pages by character size mutable std::vector mPixelBuffer; ///< Pixel buffer holding a glyph's pixels before being written to the texture + bool mBoldAdvanceSameAsRegular; }; }} // namespace EE::Graphics diff --git a/include/eepp/ui/doc/syntaxcolorscheme.hpp b/include/eepp/ui/doc/syntaxcolorscheme.hpp index 662dc8c2b..f49440659 100644 --- a/include/eepp/ui/doc/syntaxcolorscheme.hpp +++ b/include/eepp/ui/doc/syntaxcolorscheme.hpp @@ -36,23 +36,33 @@ class EE_API SyntaxColorScheme { static std::vector loadFromPack( Pack* pack, std::string filePackPath ); + struct Style { + Style(){}; + Style( const Color& color ) : color( color ) {} + Style( const Color& color, const Uint32& style ) : color( color ), style( style ) {} + Color color{Color::White}; + Uint32 style{0}; + }; + SyntaxColorScheme(); SyntaxColorScheme( const std::string& name, - const std::unordered_map& syntaxColors, - const std::unordered_map& editorColors ); + const std::unordered_map& syntaxColors, + const std::unordered_map& editorColors ); - const Color& getSyntaxColor( const std::string& type ) const; + const Style& getSyntaxStyle( const std::string& type ) const; - void setSyntaxColors( const std::unordered_map& colors ); + void setSyntaxStyles( const std::unordered_map& styles ); - void setSyntaxColor( const std::string& type, const Color& color ); + void setSyntaxStyle( const std::string& type, const Style& style ); + + const Style& getEditorSyntaxStyle( const std::string& type ) const; const Color& getEditorColor( const std::string& type ) const; - void setEditorColors( const std::unordered_map& colors ); + void setEditorSyntaxStyles( const std::unordered_map& styles ); - void setEditorColor( const std::string& type, const Color& color ); + void setEditorSyntaxStyle( const std::string& type, const Style& style ); const std::string& getName() const; @@ -60,8 +70,8 @@ class EE_API SyntaxColorScheme { protected: std::string mName; - std::unordered_map mSyntaxColors; - std::unordered_map mEditorColors; + std::unordered_map mSyntaxColors; + std::unordered_map mEditorColors; }; }}} // namespace EE::UI::Doc diff --git a/src/eepp/graphics/fonttruetype.cpp b/src/eepp/graphics/fonttruetype.cpp index 43f274a76..04ebfd103 100644 --- a/src/eepp/graphics/fonttruetype.cpp +++ b/src/eepp/graphics/fonttruetype.cpp @@ -65,7 +65,8 @@ FontTrueType::FontTrueType( const std::string& FontName ) : mStreamRec( NULL ), mStroker( NULL ), mRefCount( NULL ), - mInfo() {} + mInfo(), + mBoldAdvanceSameAsRegular( false ) {} FontTrueType::~FontTrueType() { cleanup(); @@ -559,7 +560,7 @@ Glyph FontTrueType::loadGlyph( Uint32 codePoint, unsigned int characterSize, boo // Compute the glyph's advance offset glyph.advance = static_cast( face->glyph->metrics.horiAdvance ) / static_cast( 1 << 6 ); - if ( bold ) + if ( bold && !mBoldAdvanceSameAsRegular ) glyph.advance += static_cast( weight ) / static_cast( 1 << 6 ); int width = bitmap.width; @@ -746,6 +747,14 @@ bool FontTrueType::setCurrentSize( unsigned int characterSize ) const { } } +bool FontTrueType::getBoldAdvanceSameAsRegular() const { + return mBoldAdvanceSameAsRegular; +} + +void FontTrueType::setBoldAdvanceSameAsRegular( bool boldAdvanceSameAsRegular ) { + mBoldAdvanceSameAsRegular = boldAdvanceSameAsRegular; +} + FontTrueType::Page::Page() : texture( NULL ), nextRow( 3 ) { // Make sure that the texture is initialized by default Image image; diff --git a/src/eepp/ui/doc/syntaxcolorscheme.cpp b/src/eepp/ui/doc/syntaxcolorscheme.cpp index e96bf6a71..cad711a65 100644 --- a/src/eepp/ui/doc/syntaxcolorscheme.cpp +++ b/src/eepp/ui/doc/syntaxcolorscheme.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -61,13 +62,34 @@ std::vector SyntaxColorScheme::loadFromStream( IOStream& stre for ( size_t valueIdx = 0; valueIdx < numValues; valueIdx++ ) { std::string valueName( String::toLower( ini.getValueName( keyIdx, valueIdx ) ) ); std::string value( ini.getValue( keyIdx, valueIdx ) ); - if ( !value.empty() && Color::isColorString( value ) ) { - if ( refColorScheme.mSyntaxColors.find( valueName ) != - refColorScheme.mSyntaxColors.end() ) { - colorScheme.setSyntaxColor( valueName, Color( value ) ); - } else if ( refColorScheme.mEditorColors.find( valueName ) != - refColorScheme.mEditorColors.end() ) { - colorScheme.setEditorColor( valueName, Color( value ) ); + if ( !value.empty() ) { + auto values = String::split( value, ',' ); + SyntaxColorScheme::Style style; + for ( auto& val : values ) { + String::toLowerInPlace( val ); + String::trimInPlace( val ); + if ( Color::isColorString( val ) ) { + style.color = Color::fromString( val ); + } else { + if ( "bold" == val ) + style.style |= Graphics::Text::Bold; + else if ( "italic" == val ) + style.style |= Graphics::Text::Italic; + else if ( "underline" == val || "underlined" == val ) + style.style |= Graphics::Text::Underlined; + else if ( "strikethrough" == val ) + style.style |= Graphics::Text::StrikeThrough; + else if ( "shadow" == val ) + style.style |= Graphics::Text::Shadow; + } + + if ( refColorScheme.mSyntaxColors.find( valueName ) != + refColorScheme.mSyntaxColors.end() ) { + colorScheme.setSyntaxStyle( valueName, style ); + } else if ( refColorScheme.mEditorColors.find( valueName ) != + refColorScheme.mEditorColors.end() ) { + colorScheme.setEditorSyntaxStyle( valueName, style ); + } } } } @@ -110,43 +132,53 @@ std::vector SyntaxColorScheme::loadFromPack( Pack* pack, SyntaxColorScheme::SyntaxColorScheme() {} SyntaxColorScheme::SyntaxColorScheme( const std::string& name, - const std::unordered_map& syntaxColors, - const std::unordered_map& editorColors ) : + const std::unordered_map& syntaxColors, + const std::unordered_map& editorColors ) : mName( name ), mSyntaxColors( syntaxColors ), mEditorColors( editorColors ) {} -const Color& SyntaxColorScheme::getSyntaxColor( const std::string& type ) const { +static const SyntaxColorScheme::Style StyleEmpty = {Color::White}; + +const SyntaxColorScheme::Style& SyntaxColorScheme::getSyntaxStyle( const std::string& type ) const { auto it = mSyntaxColors.find( type ); if ( it != mSyntaxColors.end() ) return it->second; - return Color::White; + return StyleEmpty; } -void SyntaxColorScheme::setSyntaxColors( const std::unordered_map& colors ) { - mSyntaxColors.insert( colors.begin(), colors.end() ); +void SyntaxColorScheme::setSyntaxStyles( const std::unordered_map& styles ) { + mSyntaxColors.insert( styles.begin(), styles.end() ); } -void SyntaxColorScheme::setSyntaxColor( const std::string& type, const Color& color ) { - mSyntaxColors[type] = color; +void SyntaxColorScheme::setSyntaxStyle( const std::string& type, + const SyntaxColorScheme::Style& style ) { + mSyntaxColors[type] = style; } -const Color& SyntaxColorScheme::getEditorColor( const std::string& type ) const { +const SyntaxColorScheme::Style& +SyntaxColorScheme::getEditorSyntaxStyle( const std::string& type ) const { auto it = mEditorColors.find( type ); if ( it != mEditorColors.end() ) return it->second; if ( type == "line_number_background" ) - return getEditorColor( "background" ); + return getEditorSyntaxStyle( "background" ); else if ( type == "guide" || type == "line_break_column" || type == "matching_bracket" || type == "matching_selection" ) - return getEditorColor( "selection" ); - return Color::White; + return getEditorSyntaxStyle( "selection" ); + return StyleEmpty; } -void SyntaxColorScheme::setEditorColors( const std::unordered_map& colors ) { - mEditorColors.insert( colors.begin(), colors.end() ); +const Color& SyntaxColorScheme::getEditorColor( const std::string& type ) const { + return getEditorSyntaxStyle( type ).color; } -void SyntaxColorScheme::setEditorColor( const std::string& type, const Color& color ) { - mEditorColors[type] = color; +void SyntaxColorScheme::setEditorSyntaxStyles( + const std::unordered_map& styles ) { + mEditorColors.insert( styles.begin(), styles.end() ); +} + +void SyntaxColorScheme::setEditorSyntaxStyle( const std::string& type, + const SyntaxColorScheme::Style& style ) { + mEditorColors[type] = style; } const std::string& SyntaxColorScheme::getName() const { diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index bd91412fc..d040c91de 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -1462,10 +1462,13 @@ void UICodeEditor::drawLineText( const Int64& index, Vector2f position, const Fl if ( position.x + textWidth >= mScreenPos.x && position.x <= mScreenPos.x + mSize.getWidth() ) { Text line( "", mFont, fontSize ); - Color color( mColorScheme.getSyntaxColor( token.type ), mAlpha ); + const SyntaxColorScheme::Style& style = mColorScheme.getSyntaxStyle( token.type ); + Color color( style.color, mAlpha ); line.setStyleConfig( mFontStyleConfig ); - line.setString( token.text ); + if ( style.style ) + line.setStyle( style.style ); line.setColor( color ); + line.setString( token.text ); line.draw( position.x, position.y ); } else if ( position.x > mScreenPos.x + mSize.getWidth() ) { break; diff --git a/src/tools/codeeditor/codeeditor.cpp b/src/tools/codeeditor/codeeditor.cpp index 0f89bec47..92ad1686b 100644 --- a/src/tools/codeeditor/codeeditor.cpp +++ b/src/tools/codeeditor/codeeditor.cpp @@ -952,13 +952,14 @@ void App::init( const std::string& file, const Float& pidelDensity ) { mUISceneNode = UISceneNode::New(); - Font* font = + FontTrueType* font = FontTrueType::New( "NotoSans-Regular", resPath + "assets/fonts/NotoSans-Regular.ttf" ); - Font* fontMono = + FontTrueType* fontMono = FontTrueType::New( "monospace", resPath + "assets/fonts/DejaVuSansMono.ttf" ); + fontMono->setBoldAdvanceSameAsRegular( true ); - Font* iconFont = FontTrueType::New( "icon", resPath + "assets/fonts/remixicon.ttf" ); + FontTrueType* iconFont = FontTrueType::New( "icon", resPath + "assets/fonts/remixicon.ttf" ); SceneManager::instance()->add( mUISceneNode );