Permalink
Browse files

Initial support for shortcut navigation and multiple level menus

- romlists can contain entries that act as a shortcut to another Display.
  The UI to add shortcuts is not there yet, but basically any entry in a
  romlist where the "emulator" field is set to "@" will act as a shortcut to
  the Display named in the "romname" field.
- Displays are "stacked" when a shortcut is selected, so when the user later
  presses the "Back" UI button the FE will navigate back to the previous Display
  (the Display that the shortcut was selected from)
- The "fe.set_display" squirrel function has been updated to allow scripts
  to (optionally) specify whether the display should be "stacked" or not
  • Loading branch information...
mickelson committed Sep 12, 2017
1 parent 15936c2 commit b71b0e48c478a115a9648968701b6191f831e23e
Showing with 103 additions and 21 deletions.
  1. +4 −0 Layouts.md
  2. +33 −4 src/fe_settings.cpp
  3. +23 −3 src/fe_settings.hpp
  4. +9 −3 src/fe_vm.cpp
  5. +1 −0 src/fe_vm.hpp
  6. +33 −11 src/main.cpp
View
@@ -835,6 +835,7 @@ Return Value:
<a name="set_display" />
#### `fe.set_display()` ####
fe.set_display( index, stack_previous )
fe.set_display( index )
Change to the display at the specified index. This should align with the
@@ -847,6 +848,9 @@ Parameters:
* index - The index of the display to change to. This should correspond to
the index in the fe.displays array of the intended new display. The index for
the current display is stored in `fe.list.display_index`.
* stack_previous - [boolean] if set to `true`, the new display is stacked on
the current one, so that when the user selects the "Back" UI button the frontend
will navigate back to the earlier display. Default value is `false`.
Return Value:
View
@@ -677,6 +677,13 @@ void FeSettings::construct_display_maps()
void FeSettings::save_state()
{
int display_idx = m_current_display;
// If we have a display stack we save the entry at the bottom of the stack as the
// 'current' display
//
if ( !m_display_stack.empty() )
display_idx = m_display_stack.front();
if ( display_idx < 0 )
display_idx = m_current_search_index;
@@ -1291,14 +1298,35 @@ int FeSettings::display_menu_get_current_selection_as_absolute_display_index()
return m_display_menu[ m_current_search_index ];
}
// return true if layout needs to be reloaded as a result
bool FeSettings::set_display( int index )
bool FeSettings::set_display( int index, bool stack_previous )
{
std::string old_path, old_file;
get_path( Layout, old_path, old_file );
if ( index < 0 )
m_current_search_index = find_idx_in_vec( m_current_display, m_display_menu );
if ( stack_previous )
{
if ( index == -1 )
{
if ( !m_display_stack.empty() )
{
index = m_display_stack.back();
m_display_stack.pop_back();
}
else
index = m_current_display;
}
else if (( m_current_display != index ) && ( m_current_display >= 0 ))
m_display_stack.push_back( m_current_display );
}
else
{
if ( index < 0 )
m_current_search_index = find_idx_in_vec( m_current_display, m_display_menu );
// If not stacking, clear the existing back stack (if any)
m_display_stack.clear();
}
m_current_display = index;
@@ -1310,6 +1338,7 @@ bool FeSettings::set_display( int index )
return (( old_path.compare( new_path ) != 0 )
|| ( old_file.compare( new_file ) != 0 ));
}
// return true if layout needs to be reloaded as a result
View
@@ -28,6 +28,7 @@
#include "fe_romlist.hpp"
#include "fe_input.hpp"
#include "fe_util.hpp"
#include <deque>
extern const char *FE_ART_EXTENSIONS[];
@@ -165,6 +166,8 @@ class FeSettings : public FeBaseConfigurable
std::vector<int> m_display_cycle; // display indices to show in cycle
std::vector<int> m_display_menu; // display indices to show in menu
std::map<GameExtra,std::string> m_game_extras; // "extra" rom settings for the current rom
std::deque<int> m_display_stack; // stack for displays to navigate to when "back" button pressed (and
// display shortcuts are used)
FeRomList m_rl;
FeInputMap m_inputmap;
@@ -278,10 +281,27 @@ class FeSettings : public FeBaseConfigurable
void step_current_selection( int step );
void set_current_selection( int filter_index, int rom_index ); // use rom_index<0 to only change the filter
// Switches the display
// returns true if the display change results in a new layout, false otherwise
//////////////////////
//
bool set_display( int index );
// Set the "display" that will be shown to the one at the specified index
//
//////////////////////
//
// index=-1, stack_previous=false is a special case, used to show the "displays menu"
// when a custom layout is being used
//
// If "stack_previous" is true, the currently shown display is added to the display
// stack (so that if the user presses the back button later the fe will navigate back
// to the earlier display). If index is -1 when stack_previous is true, then the
// display will be moved to the display at the top of the display stack (if there is one)
//
// Returns true if the display change results in a new layout, false otherwise
//
bool set_display( int index, bool stack_previous=false );
// Return true if there are displays available to navigate back to on a "back" button press
//
bool back_displays_available() { return !m_display_stack.empty(); };
int get_current_display_index() const;
int get_display_index_from_name( const std::string &name ) const;
View
@@ -854,7 +854,8 @@ bool FeVM::on_new_layout()
fe.Func<const char* (*)(const char *)>(_SC("path_expand"), &FeVM::cb_path_expand);
fe.Func<Table (*)()>(_SC("get_config"), &FeVM::cb_get_config);
fe.Func<void (*)(const char *)>(_SC("signal"), &FeVM::cb_signal);
fe.Func<void (*)(int)>(_SC("set_display"), &FeVM::cb_set_display);
fe.Overload<void (*)(int, bool)>(_SC("set_display"), &FeVM::cb_set_display);
fe.Overload<void (*)(int)>(_SC("set_display"), &FeVM::cb_set_display);
//
// Define variables that get exposed to Squirrel
@@ -2197,7 +2198,7 @@ void FeVM::cb_signal( const char *sig )
}
}
void FeVM::cb_set_display( int idx )
void FeVM::cb_set_display( int idx, bool stack_previous )
{
HSQUIRRELVM vm = Sqrat::DefaultVM::Get();
FeVM *fev = (FeVM *)sq_getforeignptr( vm );
@@ -2208,10 +2209,15 @@ void FeVM::cb_set_display( int idx )
if ( idx < 0 )
idx = 0;
fes->set_display( idx );
fes->set_display( idx, stack_previous );
fev->m_posted_commands.push( FeInputMap::Reload );
}
void FeVM::cb_set_display( int idx )
{
cb_set_display( idx, false );
}
void FeVM::init_with_default_layout()
{
//
View
@@ -221,6 +221,7 @@ class FeVM : public FePresent
static const char *cb_get_art( const char *);
static Sqrat::Table cb_get_config();
static void cb_signal( const char * );
static void cb_set_display( int, bool );
static void cb_set_display( int );
};
View
@@ -236,11 +236,11 @@ int main(int argc, char *argv[])
if ( index < 0 )
{
std::cerr << "Error resolving shortcut, Display `" << name << "' not found.";
std::cerr << "Error resolving shortcut, Display `" << name << "' not found." << std::endl;
}
else
{
if ( feSettings.set_display( index ) )
if ( feSettings.set_display( index, true ) )
feVM.load_layout();
else
feVM.update_to_new_list( 0, true );
@@ -395,17 +395,37 @@ int main(int argc, char *argv[])
}
//
// If FE is configured to show displays menu on startup, then the "Back" UI
// button goes back to that menu accordingly...
// Handle special case Back UI button behaviour
//
if (( c == FeInputMap::Back )
&& ( feSettings.get_startup_mode() == FeSettings::ShowDisplaysMenu )
&& ( feSettings.get_present_state() == FeSettings::Layout_Showing )
&& ( feSettings.get_current_display_index() >= 0 ))
if ( c == FeInputMap::Back )
{
FeVM::cb_signal( "displays_menu" );
redraw=true;
continue;
//
// If a display shortcut was used previously, then the "Back" UI
// button goes back to the previous display accordingly...
//
if ( feSettings.back_displays_available() )
{
if ( feSettings.set_display( -1, true ) )
feVM.load_layout();
else
feVM.update_to_new_list( 0, true );
redraw=true;
continue;
}
//
// If FE is configured to show displays menu on startup, then the "Back" UI
// button goes back to that menu accordingly...
//
if (( feSettings.get_startup_mode() == FeSettings::ShowDisplaysMenu )
&& ( feSettings.get_present_state() == FeSettings::Layout_Showing )
&& ( feSettings.get_current_display_index() >= 0 ))
{
FeVM::cb_signal( "displays_menu" );
redraw=true;
continue;
}
}
c = feSettings.get_default_command( c );
@@ -531,6 +551,7 @@ int main(int argc, char *argv[])
//
feSettings.set_display(-1);
feVM.load_layout( true );
redraw=true;
break;
}
@@ -579,6 +600,7 @@ int main(int argc, char *argv[])
else
feVM.update_to_new_list( 0, true );
}
redraw=true;
}
}

0 comments on commit b71b0e4

Please sign in to comment.