Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/fe_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,8 @@ bool FeScriptConfigMenu::on_option_select(

bool FeScriptConfigMenu::save_helper( FeConfigContext &ctx, int first_idx )
{
apply_presets_if_changed( ctx, first_idx );

m_configurable->clear_params();

if ( m_per_display )
Expand Down Expand Up @@ -1970,6 +1972,27 @@ bool FeScriptConfigMenu::save_helper( FeConfigContext &ctx, int first_idx )
return true;
}

void FeScriptConfigMenu::apply_presets_if_changed( FeConfigContext &ctx, int first_idx )
{
FeVM::script_apply_preset_values( ctx, *m_configurable, m_file_path, m_file_name, first_idx );
}

void FeScriptConfigMenu::apply_preset_to_context( FeConfigContext &ctx, int preset_index )
{
// Use force_apply=true so preset is applied even if it matches the saved value
FeVM::script_apply_preset_values( ctx, *m_configurable, m_file_path, m_file_name, 0, true );
}

void FeScriptConfigMenu::handle_preset_override( FeConfigContext &ctx, int changed_option_index )
{
FeVM::script_handle_preset_override( ctx, *m_configurable, m_file_path, m_file_name, changed_option_index );
}

void FeScriptConfigMenu::update_preset_controlled_options( FeConfigContext &ctx )
{
FeVM::script_update_preset_controlled_options( ctx, *m_configurable, m_file_path, m_file_name );
}

FePluginEditMenu::FePluginEditMenu()
: m_plugin( NULL )
{
Expand Down
13 changes: 13 additions & 0 deletions src/fe_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class FeMenuOpt
int type; // see Opt namespace for values
bool trigger_reload = false; // this option will trigger a ui reload on change
bool trigger_colour = false; // special case for menu colour options
bool preset_controlled = false; // this option is controlled by a preset

std::string setting; // the name of the setting
std::string help_msg; // the help message for this option
Expand Down Expand Up @@ -205,6 +206,12 @@ class FeBaseConfigMenu
//
virtual bool save( FeConfigContext &ctx );

// Apply preset values to context immediately when preset selection changes
virtual void apply_preset_to_context( FeConfigContext &ctx, int preset_index ) {}

// Handle when a non-preset option changes - set preset field to "Custom" if applicable
virtual void handle_preset_override( FeConfigContext &ctx, int changed_option_index ) {}

// When true will cause display_config_dialog to save and exit on every change
// Used to create "live" menus, such as Layout Options
// main.cpp must then re-display the menu until user explicitly exits
Expand All @@ -228,13 +235,19 @@ class FeScriptConfigMenu : public FeBaseConfigMenu
FeConfigContext &ctx, FeBaseConfigMenu *& submenu );

bool save_helper( FeConfigContext &ctx, int first_idx=0 );
void apply_presets_if_changed( FeConfigContext &ctx, int first_idx );
void apply_preset_to_context( FeConfigContext &ctx, int preset_index ) override;
void handle_preset_override( FeConfigContext &ctx, int changed_option_index ) override;

FeSettings::FePresentState m_state;
int m_script_id;
FeScriptConfigurable *m_configurable;
FeScriptConfigurable *m_per_display;
std::string m_file_path;
std::string m_file_name;

public:
void update_preset_controlled_options( FeConfigContext &ctx );
};

class FeLayoutEditMenu : public FeScriptConfigMenu
Expand Down
14 changes: 14 additions & 0 deletions src/fe_listbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,20 @@ void FeListBox::set_sela(int a)
setSelColor( c );
}

void FeListBox::set_row_alpha( int index, int alpha )
{
// Convert absolute list index to visible row index
int visible_row = index - m_list_start_offset;

// Only apply if the row is currently visible
if ( visible_row >= 0 && visible_row < (int)m_texts.size() )
{
sf::Color c = m_texts[visible_row].getColor();
c.a = alpha;
m_texts[visible_row].setColor( c );
}
}

void FeListBox::set_sel_rgb(int r, int g, int b )
{
sf::Color c = m_selColour;
Expand Down
1 change: 1 addition & 0 deletions src/fe_listbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class FeListBox : public FeBasePresentable, public sf::Drawable
void set_selb(int b);
void set_sela(int a);
void set_sel_rgb( int, int, int );
void set_row_alpha( int index, int alpha );
int get_selbgr();
int get_selbgg();
int get_selbgb();
Expand Down
63 changes: 63 additions & 0 deletions src/fe_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,10 @@ int FeOverlay::display_config_dialog(
ctx.curr_sel = 0;
m->last_sel = ctx.curr_sel;

FeScriptConfigMenu *script_menu = dynamic_cast<FeScriptConfigMenu*>(m);
if ( script_menu )
script_menu->update_preset_controlled_options( ctx );

sdialog.setCustomText( ctx.curr_sel, ctx.left_list );
vdialog.setCustomText( ctx.curr_sel, ctx.right_list );

Expand Down Expand Up @@ -1555,6 +1559,16 @@ int FeOverlay::display_config_dialog(
text_index( vdialog, vindex, ctx.right_list, -1 );
layout_focus( sdialog, vdialog, ( ctx.curr_opt().type == Opt::INFO ) ? LayoutFocus::Disabled : LayoutFocus::Select );

// Apply dimming to preset-controlled options
for ( unsigned int i = 0; i < ctx.opt_list.size(); i++ )
{
if ( ctx.opt_list[i].preset_controlled )
{
sdialog.set_row_alpha( i, m_disable_alpha );
vdialog.set_row_alpha( i, m_disable_alpha );
}
}

while ( text_index( sdialog, sindex, ctx.left_list, is_preview ? c.sel : -1 ) && event_loop( c ) == false )
{
m->last_sel = ctx.curr_sel;
Expand All @@ -1568,6 +1582,16 @@ int FeOverlay::display_config_dialog(

sdialog.setCustomText( ctx.curr_sel, ctx.left_list );
vdialog.setCustomText( ctx.curr_sel, ctx.right_list );

// Reapply dimming after navigation
for ( unsigned int i = 0; i < ctx.opt_list.size(); i++ )
{
if ( ctx.opt_list[i].preset_controlled )
{
sdialog.set_row_alpha( i, m_disable_alpha );
vdialog.set_row_alpha( i, m_disable_alpha );
}
}
}

text_index( sdialog, sindex, ctx.left_list, -1 );
Expand Down Expand Up @@ -1714,6 +1738,31 @@ int FeOverlay::display_config_dialog(
ctx.save_req = true;
ctx.curr_opt().set_value( new_value );
ctx.right_list[ctx.curr_sel] = ctx.curr_opt().get_value();

// Note: Opaque values are: 1=is_input, 2=is_function, 3=is_preset
if ( ctx.opt_list[ctx.curr_sel].opaque == 3 )
{
m->apply_preset_to_context( ctx, ctx.curr_sel );

for ( unsigned int i = 0; i < ctx.opt_list.size(); i++ )
ctx.right_list[i] = ctx.opt_list[i].get_value();

FeScriptConfigMenu *script_menu = dynamic_cast<FeScriptConfigMenu*>(m);
if ( script_menu )
script_menu->update_preset_controlled_options( ctx );
}
else
{
m->handle_preset_override( ctx, ctx.curr_sel );

for ( unsigned int i = 0; i < ctx.opt_list.size(); i++ )
if ( ctx.opt_list[i].opaque == 3 )
ctx.right_list[i] = ctx.opt_list[i].get_value();

FeScriptConfigMenu *script_menu = dynamic_cast<FeScriptConfigMenu*>(m);
if ( script_menu )
script_menu->update_preset_controlled_options( ctx );
}
}
else if ( refresh_colour )
{
Expand Down Expand Up @@ -1742,6 +1791,12 @@ int FeOverlay::display_config_dialog(
std::string d_str = utf32_to_utf8( str );
ctx.curr_opt().set_value( d_str );
ctx.right_list[ctx.curr_sel] = d_str;

m->handle_preset_override( ctx, ctx.curr_sel );

for ( unsigned int i = 0; i < ctx.opt_list.size(); i++ )
if ( ctx.opt_list[i].opaque == 3 )
ctx.right_list[i] = ctx.opt_list[i].get_value();
}
}

Expand Down Expand Up @@ -1778,6 +1833,14 @@ int FeOverlay::display_config_dialog(

ctx.save_req = true;

m->handle_preset_override( ctx, ctx.curr_sel );

for ( unsigned int i = 0; i < ctx.opt_list.size(); i++ )
if ( ctx.opt_list[i].opaque == 3 )
ctx.right_list[i] = ctx.opt_list[i].get_value();

vdialog.setCustomText( ctx.curr_sel, ctx.right_list );

if ( m->exit_on_change )
{
if ( m->save( ctx ) ) parent_setting_changed = true;
Expand Down
Loading
Loading