Settings Menu refactor.

Allow control over antialias per-render call. UICodeEditor Minimap now disables AA by default.
This commit is contained in:
Martín Lucas Golini
2024-04-12 20:02:47 -03:00
parent e6968fd670
commit dd99e040e6
11 changed files with 124 additions and 50 deletions

View File

@@ -276,6 +276,10 @@ typedef char GLchar;
#endif
#ifndef GL_MULTISAMPLE
#define GL_MULTISAMPLE 0x809D
#endif
#include <eepp/graphics/renderer/rendererhelper.hpp>
#endif

View File

@@ -132,6 +132,10 @@ class EE_API Renderer {
void pixelStorei( unsigned int pname, int param );
void multisample( bool enable );
bool isMultisample();
RendererGL* getRendererGL();
RendererGL3* getRendererGL3();
@@ -278,7 +282,12 @@ class EE_API Renderer {
protected:
static Renderer* sSingleton;
enum RendererStateFlags { RSF_LINE_SMOOTH = 0, RSF_POLYGON_MODE, RSF_POLYGON_SMOOTH };
enum RendererStateFlags {
RSF_LINE_SMOOTH = 0,
RSF_POLYGON_MODE,
RSF_POLYGON_SMOOTH,
RFS_MULTISAMPLE
};
Uint32 mExtensions;
Uint32 mStateFlags;

View File

@@ -142,6 +142,7 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
Float scale{ 1 };
int tabWidth{ 4 };
bool drawBackground{ true };
bool allowSmoothing{ false };
Float gutterWidth{ 5 }; // dp width
};

View File

@@ -376,8 +376,7 @@ bool Renderer::shadersSupported() {
std::string Renderer::getExtensions() {
std::string exts;
#if defined( EE_X11_PLATFORM ) || EE_PLATFORM == EE_PLATFORM_WIN || \
EE_PLATFORM == EE_PLATFORM_MACOS
#if defined( EE_X11_PLATFORM ) || EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOS
if ( GLv_3 == version() || GLv_3CP == version() ) {
static pglGetStringiFunc eeglGetStringiFunc = NULL;
@@ -582,6 +581,19 @@ void Renderer::pixelStorei( unsigned int pname, int param ) {
glPixelStorei( pname, param );
}
void Renderer::multisample( bool enabled ) {
if ( enabled )
enable( GL_MULTISAMPLE );
else
disable( GL_MULTISAMPLE );
BitOp::writeBitKey( &mStateFlags, RFS_MULTISAMPLE, enabled ? 1 : 0 );
}
bool Renderer::isMultisample() {
return BitOp::readBitKey( &mStateFlags, RFS_MULTISAMPLE );
}
void Renderer::polygonMode( const PrimitiveFillMode& Mode ) {
if ( Mode == DRAW_FILL )
polygonMode( GL_FRONT_AND_BACK, GL_FILL );

View File

@@ -48,7 +48,7 @@ void UIBackgroundDrawable::draw( const Vector2f& position, const Sizef& size ) {
if ( hasRadius() && mVertexBuffer ) {
bool isPolySmooth = GLi->isPolygonSmooth();
if ( mSmooth )
if ( mSmooth && !isPolySmooth )
GLi->polygonSmooth( true );
mVertexBuffer->bind();

View File

@@ -3,8 +3,10 @@
#include <eepp/graphics/fonttruetype.hpp>
#include <eepp/graphics/globalbatchrenderer.hpp>
#include <eepp/graphics/primitives.hpp>
#include <eepp/graphics/renderer/renderer.hpp>
#include <eepp/scene/scenemanager.hpp>
#include <eepp/system/luapattern.hpp>
#include <eepp/system/scopedop.hpp>
#include <eepp/ui/doc/syntaxdefinitionmanager.hpp>
#include <eepp/ui/tools/uicolorpicker.hpp>
#include <eepp/ui/tools/uidocfindreplace.hpp>
@@ -3630,6 +3632,18 @@ void UICodeEditor::drawMinimap( const Vector2f& start,
minimapStartLine = eemax( 0, eemin( minimapStartLine, lineCount - maxMinmapLines ) );
}
// Disable multi-sample to avoid rectangle-smoothing
bool disableMultisample = !mMinimapConfig.allowSmoothing && GLi->isMultisample();
ScopedOp op(
[disableMultisample] {
if ( disableMultisample )
GLi->multisample( false );
},
[disableMultisample] {
if ( disableMultisample )
GLi->multisample( true );
} );
GlobalBatchRenderer* BR = GlobalBatchRenderer::instance();
BR->setTexture( nullptr );
BR->setBlendMode( BlendMode::Alpha() );

View File

@@ -389,6 +389,8 @@ bool WindowSDL::create( WindowSettings Settings, ContextSettings Context ) {
if ( NULL == Renderer::existsSingleton() ) {
Renderer::createSingleton( mWindow.ContextConfig.Version );
Renderer::instance()->init();
if ( mWindow.ContextConfig.Multisamples > 0 )
Renderer::instance()->multisample( true );
}
getMainContext();

View File

@@ -871,19 +871,13 @@ const std::string& App::getFileToOpen() const {
void App::switchSidePanel() {
mConfig.ui.showSidePanel = !mConfig.ui.showSidePanel;
mSettings->getWindowMenu()
->getItemId( "show-side-panel" )
->asType<UIMenuCheckBox>()
->setActive( mConfig.ui.showSidePanel );
mSettings->updateViewMenu();
showSidePanel( mConfig.ui.showSidePanel );
}
void App::switchStatusBar() {
mConfig.ui.showStatusBar = !mConfig.ui.showStatusBar;
auto chk =
mSettings->getWindowMenu()->getItemId( "toggle-status-bar" )->asType<UIMenuCheckBox>();
if ( chk->isActive() != mConfig.ui.showStatusBar )
chk->setActive( mConfig.ui.showStatusBar );
mSettings->updateViewMenu();
updateDocInfoLocation();
showStatusBar( mConfig.ui.showStatusBar );
}
@@ -900,6 +894,8 @@ void App::panelPosition( const PanelPosition& panelPosition ) {
mProjectSplitter->getFirstWidget() != mSidePanel ) ) {
mProjectSplitter->swap( true );
}
mSettings->updateViewMenu();
}
void App::setUIColorScheme( const ColorSchemePreference& colorScheme ) {
@@ -2439,10 +2435,7 @@ NotificationCenter* App::getNotificationCenter() const {
void App::fullscreenToggle() {
mWindow->toggleFullscreen();
mSettings->getWindowMenu()
->find( "fullscreen-toggle" )
->asType<UIMenuCheckBox>()
->setActive( !mWindow->isWindowed() );
mSettings->updateViewMenu();
}
void App::showGlobalSearch( bool searchAndReplace ) {

View File

@@ -238,6 +238,9 @@ void IconManager::init( UISceneNode* sceneNode, FontTrueType* iconFont, FontTrue
{ "circle-filled", 0xea71 },
{ "circle", 0xeabc },
{ "diff-multiple", 0xec23 },
{ "extensions", 0xeae6 },
{ "window-opt", 0xeb7f },
{ "tools", 0xeb6d },
};
for ( const auto& icon : codIcons )

View File

@@ -91,9 +91,10 @@ void SettingsMenu::createSettingsMenu( App* app ) {
->setId( "term-menu" );
mSettingsMenu->addSubMenu( i18n( "edit", "Edit" ), nullptr, createEditMenu() );
mSettingsMenu->addSubMenu( i18n( "view", "View" ), nullptr, createViewMenu() );
mSettingsMenu->addSubMenu( i18n( "tools", "Tools" ), nullptr, createToolsMenu() );
mSettingsMenu->addSubMenu( i18n( "window", "Window" ), nullptr, createWindowMenu() );
mSettingsMenu->add( i18n( "plugin_manager", "Plugin Manager" ), findIcon( "package" ) )
mSettingsMenu->addSubMenu( i18n( "tools", "Tools" ), findIcon( "tools" ), createToolsMenu() );
mSettingsMenu->addSubMenu( i18n( "window", "Window" ), findIcon( "window-opt" ),
createWindowMenu() );
mSettingsMenu->add( i18n( "plugin_manager", "Plugin Manager" ), findIcon( "extensions" ) )
->setId( "plugin-manager-open" );
mSettingsMenu->addSubMenu( i18n( "help", "Help" ), findIcon( "help" ), createHelpMenu() );
mSettingsMenu->addSeparator();
@@ -936,7 +937,7 @@ UIMenu* SettingsMenu::createWindowMenu() {
findIcon( "color-scheme" ), colorsMenu );
mWindowMenu->addSubMenu( i18n( "ui_thene", "UI Theme" ), findIcon( "palette" ),
createThemesMenu() );
mWindowMenu->addSubMenu( i18n( "ui_renderer", "Renderer" ), findIcon( "renderer" ),
mWindowMenu->addSubMenu( i18n( "ui_renderer", "Renderer" ), findIcon( "package" ),
createRendererMenu() );
mWindowMenu
->add( i18n( "ui_scale_factor", "UI Scale Factor (Pixel Density)" ),
@@ -966,27 +967,7 @@ UIMenu* SettingsMenu::createWindowMenu() {
->add( i18n( "key_bindings", "Key Bindings" ), findIcon( "keybindings" ),
getKeybind( "keybindings" ) )
->setId( "keybindings" );
mWindowMenu->addSeparator();
mWindowMenu
->addCheckBox( i18n( "fullscreen_mode", "Full Screen Mode" ), false,
getKeybind( "fullscreen-toggle" ) )
->setId( "fullscreen-toggle" );
mWindowMenu
->addCheckBox( i18n( "show_side_panel", "Show Side Panel" ),
mApp->getConfig().ui.showSidePanel, getKeybind( "switch-side-panel" ) )
->setId( "show-side-panel" );
mWindowMenu
->addCheckBox( i18n( "show_status_bar", "Show Status Bar" ),
mApp->getConfig().ui.showStatusBar, getKeybind( "toggle-status-bar" ) )
->setId( "toggle-status-bar" );
mWindowMenu
->add( i18n( "move_panel_left_ellipsis", "Move panel to left..." ),
findIcon( "layout-left" ), getKeybind( "layout-left" ) )
->setId( "move-panel-left" );
mWindowMenu
->add( i18n( "move_panel_right_ellipsis", "Move panel to right..." ),
findIcon( "layout-right" ), getKeybind( "layout-rigth" ) )
->setId( "move-panel-right" );
mWindowMenu->addSeparator();
UIPopUpMenu* splitMenu = UIPopUpMenu::New();
@@ -1048,15 +1029,6 @@ UIMenu* SettingsMenu::createWindowMenu() {
->add( i18n( "zoom_reset", "Zoom Reset" ), findIcon( "zoom-reset" ),
getKeybind( "font-size-reset" ) )
->setId( "zoom-reset" );
mWindowMenu->addSeparator();
mWindowMenu
->add( i18n( "show_console", "Show Console" ), findIcon( "terminal" ),
getKeybind( "console-toggle" ) )
->setId( "console-toggle" );
mWindowMenu
->add( i18n( "inspect_widgets", "Inspect Widgets" ), findIcon( "package" ),
getKeybind( "debug-widget-tree-view" ) )
->setId( "debug-widget-tree-view" );
mWindowMenu->on( Event::OnItemClicked, [this]( const Event* event ) {
if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) )
return;
@@ -1239,6 +1211,30 @@ UIMenu* SettingsMenu::createViewMenu() {
"directory tree." ) )
->setId( "sync-project-tree" );
mViewMenu->addSeparator();
mViewMenu
->addCheckBox( i18n( "fullscreen_mode", "Full Screen Mode" ), false,
getKeybind( "fullscreen-toggle" ) )
->setId( "fullscreen-toggle" );
mViewMenu
->addCheckBox( i18n( "show_side_panel", "Show Side Panel" ),
mApp->getConfig().ui.showSidePanel, getKeybind( "switch-side-panel" ) )
->setId( "show-side-panel" );
mViewMenu
->addCheckBox( i18n( "show_status_bar", "Show Status Bar" ),
mApp->getConfig().ui.showStatusBar, getKeybind( "toggle-status-bar" ) )
->setId( "toggle-status-bar" );
mViewMenu
->add( i18n( "move_panel_left_ellipsis", "Move panel to left..." ),
findIcon( "layout-left" ), getKeybind( "layout-left" ) )
->setId( "move-panel-left" )
->setVisible( mApp->getConfig().ui.panelPosition == PanelPosition::Right );
mViewMenu
->add( i18n( "move_panel_right_ellipsis", "Move panel to right..." ),
findIcon( "layout-right" ), getKeybind( "layout-rigth" ) )
->setId( "move-panel-right" )
->setVisible( mApp->getConfig().ui.panelPosition == PanelPosition::Left );
mViewMenu->on( Event::OnItemClicked, [this]( const Event* event ) {
if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) )
return;
@@ -1392,6 +1388,18 @@ UIPopUpMenu* SettingsMenu::createToolsMenu() {
->add( i18n( "load_cur_dir_as_folder", "Load current document directory as folder" ),
findIcon( "folder" ), getKeybind( "load-current-dir" ) )
->setId( "load-current-dir" );
mToolsMenu->addSeparator();
mToolsMenu
->add( i18n( "show_console", "Show Console" ), findIcon( "terminal" ),
getKeybind( "console-toggle" ) )
->setId( "console-toggle" );
mToolsMenu
->add( i18n( "inspect_widgets", "Inspect Widgets" ), findIcon( "package" ),
getKeybind( "debug-widget-tree-view" ) )
->setId( "debug-widget-tree-view" );
mToolsMenu->on( Event::OnItemClicked, [this]( const Event* event ) {
if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) )
return;
@@ -1670,6 +1678,26 @@ void SettingsMenu::updateDocumentMenu() {
->setActive( mSplitter->getCurEditor()->isLocked() );
}
void SettingsMenu::updateViewMenu() {
mViewMenu->getItemId( "fullscreen-toggle" )
->asType<UIMenuCheckBox>()
->setActive( !mApp->getWindow()->isWindowed() );
mViewMenu->getItemId( "toggle-status-bar" )
->asType<UIMenuCheckBox>()
->setActive( mApp->getConfig().ui.showStatusBar );
mViewMenu->getItemId( "show-side-panel" )
->asType<UIMenuCheckBox>()
->setActive( mApp->getConfig().ui.showSidePanel );
mViewMenu->getItemId( "move-panel-left" )
->setVisible( mApp->getConfig().ui.panelPosition == PanelPosition::Right );
mViewMenu->getItemId( "move-panel-right" )
->setVisible( mApp->getConfig().ui.panelPosition == PanelPosition::Left );
}
void SettingsMenu::updateGlobalDocumentSettingsMenu() {
mGlobalMenu->find( "autoreload_on_disk_change" )
->asType<UIMenuCheckBox>()
@@ -1942,6 +1970,10 @@ void SettingsMenu::updatedReopenClosedFileState() {
}
}
UIPopUpMenu* SettingsMenu::getViewMenu() const {
return mViewMenu;
}
UIPopUpMenu* SettingsMenu::getWindowMenu() const {
return mWindowMenu;
}

View File

@@ -50,6 +50,8 @@ class SettingsMenu {
void updateDocumentMenu();
void updateViewMenu();
void updateGlobalDocumentSettingsMenu();
void showProjectTreeMenu();
@@ -64,6 +66,8 @@ class SettingsMenu {
void updatedReopenClosedFileState();
UIPopUpMenu* getViewMenu() const;
UIPopUpMenu* getWindowMenu() const;
UIPopUpMenu* getSettingsMenu() const;