/source/mupen64launcher/src/cselector.cpp
C++ | 2678 lines | 2291 code | 284 blank | 103 comment | 522 complexity | 06c0ec8b69bad6d99a5ac29ad332b597 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-3.0, GPL-3.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- /**
- * @section LICENSE
- *
- * PickleLauncher
- * Copyright (C) 2010-2011 Scott Smith
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * @section LOCATION
- */
- #include "cselector.h"
- CSelector::CSelector() : CBase(),
- Redraw (true),
- SkipFrame (false),
- Rescan (true),
- RefreshList (true),
- SetOneEntryValue (false),
- SetAllEntryValue (false),
- TextScrollDir (true),
- ExtractAllFiles (false),
- DrawState_Title (true),
- DrawState_About (true),
- DrawState_Filter (true),
- DrawState_FilePath (true),
- DrawState_Index (true),
- DrawState_ZipMode (true),
- DrawState_Preview (true),
- DrawState_ButtonL (true),
- DrawState_ButtonR (true),
- Mode (MODE_SELECT_ENTRY),
- LastSelectedEntry (0),
- TextScrollOffset (0),
- CurScrollSpeed (0),
- CurScrollPause (0),
- ListNameHeight (0),
- FramesDrawn (0),
- FramesSkipped (0),
- FramesSleep (0),
- #if defined(DEBUG)
- FPSDrawn (0),
- FPSSkip (0),
- FPSSleep (0),
- FrameCountTime (0),
- LoopTimeAverage (0),
- #endif
- FrameEndTime (0),
- FrameStartTime (0),
- FrameDelay (0),
- Mouse (),
- Joystick (NULL),
- Screen (NULL),
- ImageBackground (NULL),
- ImagePointer (NULL),
- ImageSelectPointer (NULL),
- ImagePreview (NULL),
- ImageTitle (NULL),
- ImageAbout (NULL),
- ImageFilePath (NULL),
- ImageFilter (NULL),
- ImageIndex (NULL),
- ImageZipMode (NULL),
- #if defined(DEBUG)
- ImageDebug (NULL),
- #endif
- ImageButtons (),
- Fonts (),
- Config (),
- Profile (),
- System (),
- ConfigPath (DEF_CONFIG),
- ProfilePath (DEF_PROFILE),
- ZipListPath (DEF_ZIPLIST),
- EventReleased (),
- EventPressCount (),
- ButtonModesLeft (),
- ButtonModesRight (),
- DisplayList (),
- LabelButtons (),
- ListNames (),
- ItemsEntry (),
- ItemsArgument (),
- ItemsValue (),
- ItemsDefPlugin (),
- WhichPlugin (0),
- ItemsRomOption (),
- ItemsRomPlugin (),
- WhichRomPlugin (0),
- RectEntries (),
- RectButtonsLeft (),
- RectButtonsRight (),
- ScreenRectsDirty ()
- {
- Fonts.resize( FONT_SIZE_TOTAL, NULL );
- ButtonModesLeft.resize( BUTTONS_MAX_LEFT );
- ButtonModesRight.resize( BUTTONS_MAX_RIGHT );
- RectButtonsLeft.resize( BUTTONS_MAX_LEFT );
- RectButtonsRight.resize( BUTTONS_MAX_RIGHT );
- ImageButtons.resize( EVENT_TOTAL, NULL );
- LabelButtons.resize( EVENT_TOTAL, "" );
- LabelButtons.at(EVENT_ONE_UP) = BUTTON_LABEL_ONE_UP;
- LabelButtons.at(EVENT_ONE_DOWN) = BUTTON_LABEL_ONE_DOWN;
- LabelButtons.at(EVENT_PAGE_UP) = BUTTON_LABEL_PAGE_UP;
- LabelButtons.at(EVENT_PAGE_DOWN) = BUTTON_LABEL_PAGE_DOWN;
- LabelButtons.at(EVENT_DIR_UP) = BUTTON_LABEL_DIR_UP;
- LabelButtons.at(EVENT_DIR_DOWN) = BUTTON_LABEL_DIR_DOWN;
- LabelButtons.at(EVENT_ZIP_MODE) = BUTTON_LABEL_ZIP_MODE;
- LabelButtons.at(EVENT_CFG_APP) = BUTTON_LABEL_CONFIG;
- LabelButtons.at(EVENT_CFG_ITEM) = BUTTON_LABEL_EDIT;
- LabelButtons.at(EVENT_SET_ONE) = BUTTON_LABEL_SET_ONE;
- LabelButtons.at(EVENT_SET_ALL) = BUTTON_LABEL_SET_ALL;
- LabelButtons.at(EVENT_BACK) = BUTTON_LABEL_BACK;
- LabelButtons.at(EVENT_SELECT) = BUTTON_LABEL_SELECT;
- LabelButtons.at(EVENT_QUIT) = BUTTON_LABEL_QUIT;
- DisplayList.resize( MODE_TOTAL );
- EventPressCount.resize( EVENT_TOTAL, EVENT_LOOPS_OFF );
- EventReleased.resize( EVENT_TOTAL, false );
- }
- CSelector::~CSelector()
- {
- }
- int8_t CSelector::Run( int32_t argc, char** argv )
- {
- int8_t result;
- int16_t selection;
- result = 0;
- ProcessArguments( argc, argv );
- System.SetCPUClock( Config.CPUClock );
- // Load video,input,profile resources
- if (OpenResources())
- {
- result = 1;
- }
- // Display and poll the user for a selection
- if (result == 0)
- {
- selection = DisplayScreen();
- // Setup a exec script for execution following termination of this application
- if (selection >= 0)
- {
- if (RunExec( selection ))
- {
- result = 1;
- }
- }
- else if (selection < -1)
- {
- result = 1;
- }
- else
- {
- result = 0;
- }
- }
- // Release resources
- CloseResources( result );
- return result;
- }
- void CSelector::ProcessArguments( int argc, char** argv )
- {
- uint8_t arg_index;
- string launcher;
- string argument;
- launcher = string(argv[0]);
- Profile.LauncherName = launcher.substr( launcher.find_last_of('/')+1 );
- Profile.LauncherPath = launcher.substr( 0, launcher.find_last_of('/')+1 );
- if (Profile.LauncherPath.compare("./") == 0 || Profile.LauncherPath.length() == 0)
- {
- Profile.LauncherPath = string(getenv("PWD"))+"/";
- }
- #if defined(DEBUG)
- Log( "Running from '%s'\n", launcher.c_str() );
- #endif
- Log( "Running from '%s' as '%s'\n", Profile.LauncherPath.c_str(), Profile.LauncherName.c_str() );
- for (arg_index=0; arg_index<argc; arg_index++ )
- {
- argument = string(argv[arg_index]);
- if (argument.compare( ARG_RESETGUI ) == 0)
- {
- Config.ResetGUI = true;
- }
- else
- if (argument.compare( ARG_PROFILE ) == 0)
- {
- ProfilePath = string(argv[++arg_index]);
- }
- else
- if (argument.compare( ARG_CONFIG ) == 0)
- {
- ConfigPath = string(argv[++arg_index]);
- }
- else
- if (argument.compare( ARG_ZIPLIST ) == 0)
- {
- ZipListPath = string(argv[++arg_index]);
- }
- }
- }
- int8_t CSelector::OpenResources( void )
- {
- uint8_t button_index;
- uint32_t flags;
- string text;
- Log( "Loading config.\n" );
- if (Config.Load( ConfigPath ))
- {
- Log( "Failed to load config\n" );
- return 1;
- }
- Log( "Loading ziplist.\n" );
- if (Config.UseZipSupport == true && Profile.Minizip.LoadUnzipList( ZipListPath ))
- {
- Log( "Failed to load ziplist\n" );
- return 1;
- }
- // Initialize defaults, Video and Audio subsystems
- Log( "Initializing SDL.\n" );
- if (SDL_Init( SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER|SDL_INIT_JOYSTICK )==-1)
- {
- Log( "Failed to initialize SDL: %s.\n", SDL_GetError() );
- return 1;
- }
- Log( "SDL initialized.\n" );
- // Setup SDL Screen
- flags = SCREEN_FLAGS;
- if (Config.Fullscreen == true)
- {
- flags |= SDL_FULLSCREEN;
- }
- Screen = SDL_SetVideoMode( Config.ScreenWidth, Config.ScreenHeight, Config.ScreenDepth, flags );
- if (Screen == NULL)
- {
- Log( "Failed to %dx%dx%d video mode: %s\n", Config.ScreenWidth, Config.ScreenHeight, Config.ScreenDepth, SDL_GetError() );
- return 1;
- }
- // Refresh entire screen for the first frame
- UpdateRect( 0, 0, Config.ScreenWidth, Config.ScreenHeight );
- // Load joystick
- #if !defined(PANDORA) && !defined(X86)
- Joystick = SDL_JoystickOpen(0);
- if (Joystick == NULL)
- {
- Log( "Warning failed to open first joystick: %s\n", SDL_GetError() );
- }
- #endif
- // Setup TTF SDL
- if (TTF_Init() == -1)
- {
- Log( "Failed to init TTF_Init: %s\n", TTF_GetError() );
- return 1;
- }
- // Load ttf font
- Fonts.at(FONT_SIZE_SMALL) = TTF_OpenFont( Config.PathFont.c_str(), Config.FontSizes.at(FONT_SIZE_SMALL) );
- if (!Fonts.at(FONT_SIZE_SMALL))
- {
- Log( "Failed to open small TTF_OpenFont: %s\n", TTF_GetError() );
- return 1;
- }
- Fonts.at(FONT_SIZE_MEDIUM) = TTF_OpenFont( Config.PathFont.c_str(), Config.FontSizes.at(FONT_SIZE_MEDIUM) );
- if (!Fonts.at(FONT_SIZE_MEDIUM))
- {
- Log( "Failed to open medium TTF_OpenFont: %s\n", TTF_GetError() );
- return 1;
- }
- Fonts.at(FONT_SIZE_LARGE) = TTF_OpenFont( Config.PathFont.c_str(), Config.FontSizes.at(FONT_SIZE_LARGE) );
- if (!Fonts.at(FONT_SIZE_LARGE))
- {
- Log( "Failed to open large TTF_OpenFont: %s\n", TTF_GetError() );
- return 1;
- }
- Log( "Loading profile.\n" );
- if (Profile.Load( ProfilePath, Config.Delimiter ))
- {
- Log( "Failed to load profile\n" );
- return 1;
- }
- // Load images
- ImageBackground = LoadImage( Config.PathBackground );
- for (button_index=0; button_index<Config.PathButtons.size(); button_index++)
- {
- ImageButtons.at(button_index) = LoadImage( Config.PathButtons.at(button_index) );
- }
- // Mouse pointer
- if (Config.ShowPointer==true)
- {
- ImagePointer = LoadImage( Config.PathPointer );
- if (ImagePointer == NULL)
- {
- SDL_ShowCursor( SDL_ENABLE );
- }
- else
- {
- SDL_ShowCursor( SDL_DISABLE );
- }
- }
- else
- {
- SDL_ShowCursor( SDL_DISABLE );
- }
- // List selector pointer
- ImageSelectPointer = LoadImage( Config.PathSelectPointer );
- if (ImageSelectPointer == NULL)
- {
- ImageSelectPointer = TTF_RenderText_Solid( Fonts.at(FONT_SIZE_MEDIUM), ENTRY_ARROW, Config.Colors.at(COLOR_BLACK) );
- }
- // Title text
- text = string(APPNAME) + " " + string(APPVERSION);
- if (Profile.TargetApp.length() > 0)
- {
- text += " for " + Profile.TargetApp;
- }
- ImageTitle = TTF_RenderText_Solid( Fonts.at(FONT_SIZE_LARGE), text.c_str(), Config.Colors.at(Config.ColorFontFiles) );
- if (ImageTitle == NULL)
- {
- Log( "Failed to create TTF surface with TTF_RenderText_Solid: %s\n", TTF_GetError() );
- return 1;
- }
- // About text
- text = "Written by " + string(APPAUTHOR) + " " + string(APPCOPYRIGHT);
- ImageAbout = TTF_RenderText_Solid( Fonts.at(FONT_SIZE_SMALL), text.c_str(), Config.Colors.at(Config.ColorFontFiles) );
- if (ImageAbout == NULL)
- {
- Log( "Failed to create TTF surface with TTF_RenderText_Solid: %s\n", TTF_GetError() );
- return 1;
- }
- return 0;
- }
- void CSelector::CloseResources( int8_t result )
- {
- uint8_t button_index;
- if (result == 0)
- {
- Config.Save( ConfigPath );
- Profile.Save( ProfilePath, Config.Delimiter );
- }
- if (Config.UseZipSupport == true)
- {
- Profile.Minizip.SaveUnzipList( ZipListPath );
- }
- // Close joystick
- if (Joystick != NULL)
- {
- Log( "Closing SDL Joystick.\n" );
- SDL_JoystickClose( Joystick );
- Joystick = NULL;
- }
- // Close fonts
- Log( "Closing TTF fonts.\n" );
- if (Fonts.at(FONT_SIZE_SMALL) != NULL)
- {
- TTF_CloseFont( Fonts.at(FONT_SIZE_SMALL) );
- Fonts.at(FONT_SIZE_SMALL) = NULL;
- }
- if (Fonts.at(FONT_SIZE_MEDIUM) != NULL)
- {
- TTF_CloseFont( Fonts.at(FONT_SIZE_MEDIUM) );
- Fonts.at(FONT_SIZE_MEDIUM) = NULL;
- }
- if (Fonts.at(FONT_SIZE_LARGE) != NULL)
- {
- TTF_CloseFont( Fonts.at(FONT_SIZE_LARGE) );
- Fonts.at(FONT_SIZE_LARGE) = NULL;
- }
- // Free images
- FREE_IMAGE( ImageBackground );
- FREE_IMAGE( ImagePointer );
- FREE_IMAGE( ImageSelectPointer );
- FREE_IMAGE( ImagePreview );
- FREE_IMAGE( ImageTitle );
- FREE_IMAGE( ImageAbout );
- FREE_IMAGE( ImageFilePath );
- FREE_IMAGE( ImageFilter );
- FREE_IMAGE( ImageIndex );
- FREE_IMAGE( ImageZipMode );
- #if defined(DEBUG)
- FREE_IMAGE( ImageDebug );
- #endif
- for (button_index=0; button_index<ImageButtons.size(); button_index++)
- {
- FREE_IMAGE( ImageButtons.at(button_index) );
- }
- Log( "Quitting TTF.\n" );
- TTF_Quit();
- Log( "Quitting SDL.\n" );
- SDL_Quit();
- // Flush all std buffers before exit
- fflush( stdout );
- fflush( stderr );
- }
- int16_t CSelector::DisplayScreen( void )
- {
- while (IsEventOff(EVENT_QUIT) == true && (IsEventOff(EVENT_SELECT) == true || Mode != MODE_SELECT_ENTRY) )
- {
- // Get user input
- if (PollInputs())
- {
- return -2;
- }
- // Select the mode
- SelectMode();
- // Configure the buttons according to the mode
- if (ConfigureButtons())
- {
- return -2;
- }
- // Draw the selector
- if (DisplaySelector())
- {
- return -2;
- }
- // Update the screen
- UpdateScreen();
- }
- if (IsEventOn( EVENT_QUIT ) == true)
- {
- // Detete any files exracted from zip
- Profile.Minizip.DelUnzipFiles();
- return -1;
- }
- else
- {
- return DisplayList.at(MODE_SELECT_ENTRY).absolute;
- }
- }
- void CSelector::UpdateRect( int16_t x, int16_t y, int16_t w, int16_t h )
- {
- SDL_Rect rect;
- if (Config.ScreenFlip == false)
- {
- // Safety Checks
- if( x < 0 )
- {
- x = 0;
- Log( "ERROR: UpdateRect X was out of bounds\n" );
- }
- if( y < 0 )
- {
- y = 0;
- Log( "ERROR: UpdateRect Y was out of bounds\n" );
- }
- if( h < 0 )
- {
- h = 0;
- Log( "ERROR: UpdateRect X was out of bounds\n" );
- }
- if( w < 0 )
- {
- w = 0;
- Log( "ERROR: UpdateRect Y was out of bounds\n" );
- }
- if( x > Config.ScreenWidth )
- {
- x = Config.ScreenWidth-1;
- Log( "ERROR: UpdateRect X was out of bounds\n" );
- }
- if( y > Config.ScreenHeight )
- {
- y = Config.ScreenHeight-1;
- Log( "ERROR: UpdateRect Y was out of bounds\n" );
- }
- if( x + w > Config.ScreenWidth )
- {
- w = Config.ScreenWidth-x;
- Log( "ERROR: UpdateRect W was out of bounds\n" );
- }
- if( y + h > Config.ScreenHeight )
- {
- h = Config.ScreenHeight-y;
- Log( "ERROR: UpdateRect H was out of bounds\n" );
- }
- rect.x = x;
- rect.y = y;
- rect.w = w;
- rect.h = h;
- ScreenRectsDirty.push_back( rect );
- }
- }
- void CSelector::UpdateScreen( void )
- {
- #if defined(DEBUG_FORCE_REDRAW)
- Redraw = true;
- #endif
- if (SkipFrame == false && Redraw == true)
- {
- if (Config.ScreenFlip == true)
- {
- if (SDL_Flip( Screen ) != 0)
- {
- Log( "Failed to swap the buffers: %s\n", SDL_GetError() );
- }
- }
- else
- {
- SDL_UpdateRects( Screen, ScreenRectsDirty.size(), &ScreenRectsDirty[0] );
- }
- Redraw = false;
- FramesDrawn++;
- }
- else
- {
- if (SkipFrame == true)
- {
- FramesSkipped++;
- }
- else
- {
- FramesSleep++;
- }
- }
- ScreenRectsDirty.clear();
- FrameEndTime = SDL_GetTicks();
- FrameDelay = (MS_PER_SEC/FRAMES_PER_SEC) - (FrameEndTime - FrameStartTime);
- #if defined(DEBUG_FPS)
- LoopTimeAverage = (LoopTimeAverage + (FrameEndTime - FrameStartTime))/2;
- #endif
- if (FrameDelay < 0)
- {
- if (FramesSkipped/FramesDrawn < FRAME_SKIP_RATIO)
- {
- SkipFrame = true;
- }
- else // Force a frame to be drawn
- {
- SkipFrame = false;
- }
- }
- else
- {
- SkipFrame = false;
- SDL_Delay( MIN(FrameDelay, MS_PER_SEC) );
- }
- FrameStartTime = SDL_GetTicks();
- #if defined(DEBUG_FPS)
- if (FrameStartTime - FrameCountTime >= MS_PER_SEC)
- {
- FrameCountTime = FrameStartTime;
- FPSDrawn = FramesDrawn;
- FPSSkip = FramesSkipped;
- FPSSleep = FramesSleep;
- FramesDrawn = 1;
- FramesSkipped = 0;
- FramesSleep = 0;
- cout << "DEBUG total " << i_to_a(FPSDrawn+FPSSkip+FPSSleep)
- << " fps " << i_to_a(FPSDrawn) << " skip " << i_to_a(FPSSkip) << " slp " << i_to_a(FPSSleep)
- << " loop " << i_to_a(LoopTimeAverage) << endl;
- }
- #endif
- }
- void CSelector::SelectMode( void )
- {
- uint8_t old_mode;
- old_mode = Mode;
- switch (Mode)
- {
- case MODE_SELECT_ENTRY:
- if (IsEventOn( EVENT_CFG_ITEM ) == true)
- {
- if (ItemsEntry.size()>0)
- {
- if (ItemsEntry.at(DisplayList.at(MODE_SELECT_ENTRY).absolute).Type == TYPE_FILE )
- // || (ItemsEntry.at(DisplayList.at(MODE_SELECT_ENTRY).absolute).Type == TYPE_DIR && Profile.LaunchableDirs == true))
- {
- // Profile.ScanRomPlugins(Profile.FilePath+ItemsEntry.at(DisplayList.at(MODE_SELECT_ENTRY).absolute).Name, ItemsRomOption);
- // Per Rom Plugin selection. Find ROMCRC and Load Plugins for this rom
- Mode = MODE_ROM_OPTION;
- }
- }
- }
- else if (IsEventOn( EVENT_CFG_APP ) == true)
- {
- Mode = MODE_SELECT_OPTION;
- }
- break;
- case MODE_SELECT_ARGUMENT:
- if (IsEventOn( EVENT_BACK ) == true)
- {
- Mode = MODE_SELECT_ENTRY;
- }
- if (IsEventOn( EVENT_SELECT ) == true)
- {
- Mode = MODE_SELECT_VALUE;
- }
- break;
- case MODE_SELECT_VALUE:
- if (IsEventOn( EVENT_BACK ) == true)
- {
- Mode = MODE_SELECT_ARGUMENT;
- }
- break;
- case MODE_SELECT_OPTION:
- if (IsEventOn( EVENT_BACK ) == true)
- {
- Mode = MODE_SELECT_ENTRY;
- }
- if (IsEventOn( EVENT_SELECT ) == true)
- {
- WhichPlugin = DisplayList.at(MODE_SELECT_OPTION).absolute;
- Mode = MODE_SELECT_PLUGIN;
- }
- break;
- case MODE_ROM_OPTION:
- if (IsEventOn( EVENT_BACK ) == true)
- {
- Mode = MODE_SELECT_ENTRY;
- }
- if (IsEventOn( EVENT_SELECT ) == true)
- {
- WhichPlugin = DisplayList.at(MODE_ROM_OPTION).absolute;
- Mode = MODE_ROM_PLUGIN;
- }
- break;
- case MODE_SELECT_PLUGIN:
- if (IsEventOn( EVENT_BACK ) == true)
- {
- Mode = MODE_SELECT_OPTION;
- }
- if (IsEventOn( EVENT_SELECT ) == true)
- {
- Profile.SaveDef1Plugin(WhichPlugin, DisplayList.at(MODE_SELECT_PLUGIN).absolute);
- Mode = MODE_SELECT_OPTION;
- }
- break;
- case MODE_ROM_PLUGIN:
- if (IsEventOn( EVENT_BACK ) == true)
- {
- Mode = MODE_ROM_OPTION;
- }
- if (IsEventOn( EVENT_SELECT ) == true)
- {
- Profile.SaveRom1Plugin(WhichPlugin, ItemsRomPlugin[DisplayList.at(MODE_ROM_PLUGIN).absolute].Entry);
- Mode = MODE_ROM_OPTION;
- }
- break;
- default:
- Mode = MODE_SELECT_ENTRY;
- Log( "Error: Unknown Mode\n" );
- break;
- }
- if (Mode != old_mode)
- {
- DrawState_ButtonL = true;
- DrawState_ButtonR = true;
- Rescan = true;
- }
- }
- int8_t CSelector::DisplaySelector( void )
- {
- SDL_Rect rect_pos = { Config.EntryXOffset, Config.EntryYOffset, 0 ,0 };
- if (Rescan)
- {
- RescanItems();
- RefreshList = true;
- Rescan = false;
- }
- if (RefreshList)
- {
- PopulateList();
- DrawState_Index = true;
- Redraw = true;
- RefreshList = false;
- }
- if (Redraw == true || CurScrollPause != 0 || CurScrollSpeed != 0 || TextScrollOffset != 0)
- {
- if (Config.ScreenFlip == true)
- {
- DrawState_Title = true;
- DrawState_About = true;
- DrawState_Filter = true;
- DrawState_FilePath = true;
- DrawState_Index = true;
- DrawState_ZipMode = true;
- DrawState_Preview = true;
- DrawState_ButtonL = true;
- DrawState_ButtonR = true;
- }
- #if defined(DEBUG_DRAW_STATES)
- else
- {
- cout << "DEBUG "
- << " " << i_to_a(DrawState_Title)
- << " " << i_to_a(DrawState_About)
- << " " << i_to_a(DrawState_Filter)
- << " " << i_to_a(DrawState_FilePath)
- << " " << i_to_a(DrawState_Index)
- << " " << i_to_a(DrawState_ZipMode)
- << " " << i_to_a(DrawState_Preview)
- << " " << i_to_a(DrawState_ButtonL)
- << " " << i_to_a(DrawState_ButtonR) << endl;
- }
- #endif
- // Draw background or clear screen
- DrawBackground();
- // Draw text titles to the screen
- if (DrawText( rect_pos ))
- {
- return 1;
- }
- // Draw the buttons for touchscreen
- if (DrawButtons( rect_pos ))
- {
- return 1;
- }
- // Draw the names for the items for display
- if (DrawNames( rect_pos ))
- {
- return 1;
- }
- // Custom mouse pointer
- if (Config.ShowPointer == true && ImagePointer != NULL)
- {
- ApplyImage( Mouse.x, Mouse.y, ImagePointer, Screen, NULL );
- }
- }
- return 0;
- }
- void CSelector::DirectoryUp( void )
- {
- if (Profile.FilePath.length() > 0)
- {
- if (Profile.FilePath.at( Profile.FilePath.length()-1) == '/')
- {
- Profile.FilePath.erase( Profile.FilePath.length()-1 );
- }
- Profile.FilePath = Profile.FilePath.substr( 0, Profile.FilePath.find_last_of('/', Profile.FilePath.length()-1) ) + '/';
- DrawState_FilePath = true;
- Rescan = true;
- }
- else
- {
- Log( "Error: Filepath is empty\n" );
- }
- }
- void CSelector::DirectoryDown( void )
- {
- if (DisplayList.at(MODE_SELECT_ENTRY).absolute < (int16_t)ItemsEntry.size() )
- {
- if (ItemsEntry.at(DisplayList.at(MODE_SELECT_ENTRY).absolute).Type == TYPE_DIR )
- {
- Profile.FilePath += ItemsEntry.at(DisplayList.at(MODE_SELECT_ENTRY).absolute).Name + '/';
- DrawState_FilePath = true;
- Rescan = true;
- EventPressCount.at(EVENT_SELECT) = EVENT_LOOPS_OFF;
- }
- }
- else
- {
- Log( "Error: Item index of %d too large for size of scanitems %d\n", DisplayList.at(MODE_SELECT_ENTRY).absolute, ItemsEntry.size() );
- }
- }
- void CSelector::ZipUp( void )
- {
- DrawState_FilePath = true;
- DrawState_ZipMode = true;
- DrawState_ButtonL = true;
- Rescan = true;
- Profile.ZipFile = "";
- }
- void CSelector::ZipDown( void )
- {
- DrawState_FilePath = true;
- DrawState_ZipMode = true;
- DrawState_ButtonL = true;
- Rescan = true;
- Profile.ZipFile = ItemsEntry.at(DisplayList.at(Mode).absolute).Name;
- EventPressCount.at( EVENT_SELECT ) = EVENT_LOOPS_OFF;
- }
- void CSelector::RescanItems( void )
- {
- uint16_t total;
- switch (Mode)
- {
- case MODE_SELECT_ENTRY:
- Profile.ScanDir( Profile.FilePath, Config.ShowHidden, Config.UseZipSupport, ItemsEntry );
- total = ItemsEntry.size();
- break;
- case MODE_SELECT_ARGUMENT:
- Profile.ScanEntry( ItemsEntry.at(DisplayList.at(MODE_SELECT_ENTRY).absolute), ItemsArgument );
- total = ItemsArgument.size();
- break;
- case MODE_SELECT_VALUE:
- Profile.ScanArgument( ItemsArgument.at(DisplayList.at(MODE_SELECT_ARGUMENT).absolute), ItemsValue );
- total = ItemsValue.size();
- break;
- case MODE_SELECT_OPTION:
- //Profile.ScanOptions( ItemsEntry.at(DisplayList.at(MODE_SELECT_ENTRY).absolute), ItemsArgument );
- Profile.ScanDefPlugins( ItemsArgument );
- total = ItemsArgument.size();
- break;
- case MODE_ROM_OPTION:
- //Profile.ScanOptions( ItemsEntry.at(DisplayList.at(MODE_SELECT_ENTRY).absolute), ItemsArgument );
- Profile.ScanRomPlugins(Profile.FilePath+ItemsEntry.at(DisplayList.at(MODE_SELECT_ENTRY).absolute).Name, ItemsRomOption);
- total = ItemsRomOption.size();
- break;
- case MODE_SELECT_PLUGIN:
- //Profile.ScanOptions( ItemsEntry.at(DisplayList.at(MODE_SELECT_ENTRY).absolute), ItemsArgument );
- Profile.ScanDef1Plugins( WhichPlugin, ItemsDefPlugin );
- total = ItemsDefPlugin.size();
- break;
- case MODE_ROM_PLUGIN:
- //Profile.ScanOptions( ItemsEntry.at(DisplayList.at(MODE_SELECT_ENTRY).absolute), ItemsArgument );
- Profile.ScanRom1Plugins( WhichPlugin, ItemsRomPlugin );
- total = ItemsRomPlugin.size();
- break;
- default:
- total = 0;
- Log( "Error: Unknown Mode\n" );
- break;
- }
- if (total > Config.MaxEntries)
- {
- RectEntries.resize( Config.MaxEntries );
- }
- else
- {
- RectEntries.resize( total );
- }
- ListNames.resize( RectEntries.size() );
- DisplayList.at(Mode).absolute = 0;
- DisplayList.at(Mode).relative = 0;
- DisplayList.at(Mode).first = 0;
- DisplayList.at(Mode).last = 0;
- DisplayList.at(Mode).total = total;
- }
- void CSelector::PopulateList( void )
- {
- // Set limits
- SelectionLimits( DisplayList.at( Mode ) );
- switch (Mode)
- {
- case MODE_SELECT_ENTRY:
- PopModeEntry();
- break;
- case MODE_SELECT_ARGUMENT:
- PopModeArgument();
- break;
- case MODE_SELECT_VALUE:
- PopModeValue();
- break;
- case MODE_SELECT_OPTION:
- PopModeOption();
- break;
- case MODE_ROM_OPTION:
- PopModeRomOption();
- break;
- case MODE_SELECT_PLUGIN:
- PopModePlugin();
- break;
- case MODE_ROM_PLUGIN:
- PopModeRomPlugin();
- break;
- default:
- Log( "Error: CSelector::PopulateList Unknown Mode\n" );
- break;
- }
- }
- void CSelector::PopModeEntry( void )
- {
- uint16_t i;
- uint16_t index;
- for (i=0; i<ListNames.size(); i++)
- {
- index = DisplayList.at( MODE_SELECT_ENTRY ).first+i;
- if (CheckRange( index, ItemsEntry.size() ))
- {
- ListNames.at(i).text.clear();
- if (ItemsEntry.at(index).Entry >= 0)
- {
- ListNames.at(i).text = Profile.Entries.at(ItemsEntry.at(index).Entry).Alias;
- }
- if (ListNames.at(i).text.length() == 0)
- {
- ListNames.at(i).text = ItemsEntry.at(index).Name;
- }
- if (Config.ShowExts == false)
- {
- ListNames.at(i).text = ListNames.at(i).text.substr( 0, ListNames.at(i).text.find_last_of(".") );
- }
- ListNames.at(i).text = ListNames.at(i).text;
- if (index == DisplayList.at(Mode).absolute)
- {
- ListNames.at(i).font = FONT_SIZE_LARGE;
- LoadPreview( ListNames.at(i).text ); // Load preview
- }
- else
- {
- ListNames.at(i).font = FONT_SIZE_MEDIUM;
- }
- ListNames.at(i).color = Config.ColorFontFiles;
- if (ItemsEntry.at(index).Type == TYPE_DIR)
- {
- ListNames.at(i).color = Config.ColorFontFolders;
- }
- }
- else
- {
- Log( "Error: CSelector::PopulateModeSelectEntry Index Error\n" );
- }
- }
- }
- void CSelector::PopModeArgument( void )
- {
- uint16_t i;
- uint16_t index;
- for (i=0; i<ListNames.size(); i++)
- {
- index = DisplayList.at(MODE_SELECT_ARGUMENT).first+i;
- if (CheckRange( index, ItemsArgument.size() ))
- {
- ListNames.at(i).text = ItemsArgument.at(index).Name;
- if (i == DisplayList.at(MODE_SELECT_ARGUMENT).absolute)
- {
- ListNames.at(i).font = FONT_SIZE_LARGE;
- }
- else
- {
- ListNames.at(i).font = FONT_SIZE_MEDIUM;
- }
- ListNames.at(i).color = Config.ColorFontFiles;
- }
- else
- {
- Log( "Error: PopModeArgument index is out of range\n" );
- }
- }
- }
- void CSelector::PopModeValue( void )
- {
- uint16_t i;
- uint16_t index;
- int16_t defvalue;
- int16_t entry;
- listoption_t argument;
- if (CheckRange(DisplayList.at(MODE_SELECT_ARGUMENT).absolute, ItemsArgument.size() ))
- {
- argument = ItemsArgument.at(DisplayList.at(MODE_SELECT_ARGUMENT).absolute);
- for (i=0; i<ListNames.size(); i++)
- {
- index = DisplayList.at(MODE_SELECT_VALUE).first+i;
- if (CheckRange( index, ItemsValue.size() ))
- {
- ListNames.at(i).text = ItemsValue.at(index);
- if (index == DisplayList.at(MODE_SELECT_VALUE).absolute)
- {
- ListNames.at(i).font = FONT_SIZE_LARGE;
- }
- else
- {
- ListNames.at(i).font = FONT_SIZE_MEDIUM;
- }
- // Detect the default value
- if (ItemsArgument.at(DisplayList.at(MODE_SELECT_ARGUMENT).absolute).Command >= 0)
- {
- if (SetAllEntryValue == true)
- {
- Profile.Commands.at(argument.Command).Arguments.at(argument.Argument).Default = DisplayList.at(MODE_SELECT_VALUE).absolute;
- }
- defvalue = Profile.Commands.at(argument.Command).Arguments.at(argument.Argument).Default;
- }
- else
- {
- if (SetAllEntryValue == true)
- {
- Profile.Extensions.at(argument.Extension).Arguments.at(argument.Argument).Default = DisplayList.at(MODE_SELECT_VALUE).absolute;
- }
- defvalue = Profile.Extensions.at(argument.Extension).Arguments.at(argument.Argument).Default;
- }
- if (index==defvalue)
- {
- ListNames.at(i).text += '*';
- }
- // Set the color for the selected item for the entry
- ListNames.at(i).color = Config.ColorFontFiles;
- if (ItemsEntry.at(DisplayList.at(MODE_SELECT_ENTRY).absolute).Entry<0)
- {
- // A custom value has been selected, so create a new entry
- if (SetOneEntryValue == true)
- {
- entry = Profile.AddEntry( argument, ItemsEntry.at(DisplayList.at(MODE_SELECT_ENTRY).absolute).Name );
- if (entry>0)
- {
- ItemsEntry.at(DisplayList.at(MODE_SELECT_ENTRY).absolute).Entry = entry;
- }
- else
- {
- Log( "Error: Could not create new entry\n" );
- }
- }
- else if (index==defvalue)
- {
- ListNames.at(i).color = COLOR_RED;
- }
- }
- if (ItemsEntry.at(DisplayList.at(MODE_SELECT_ENTRY).absolute).Entry>=0)
- {
- if (ItemsArgument.at(DisplayList.at(MODE_SELECT_ARGUMENT).absolute).Command >= 0)
- {
- if (SetOneEntryValue == true || SetAllEntryValue == true)
- {
- Profile.Entries.at(ItemsEntry.at(DisplayList.at(MODE_SELECT_ENTRY).absolute).Entry).CmdValues.at(argument.Command+argument.Argument) = DisplayList.at(MODE_SELECT_VALUE).absolute;
- }
- if (index == Profile.Entries.at(ItemsEntry.at(DisplayList.at(MODE_SELECT_ENTRY).absolute).Entry).CmdValues.at(argument.Command+argument.Argument))
- {
- ListNames.at(i).color = COLOR_RED;
- }
- }
- else
- {
- if (SetOneEntryValue == true || SetAllEntryValue == true)
- {
- Profile.Entries.at(ItemsEntry.at(DisplayList.at(MODE_SELECT_ENTRY).absolute).Entry).ArgValues.at(argument.Argument) = DisplayList.at(MODE_SELECT_VALUE).absolute;
- }
- if (index == Profile.Entries.at(ItemsEntry.at(DisplayList.at(MODE_SELECT_ENTRY).absolute).Entry).ArgValues.at(argument.Argument))
- {
- ListNames.at(i).color = COLOR_RED;
- }
- }
- }
- }
- else
- {
- Log( "Error: PopModeValue index is out of range\n" );
- }
- }
- }
- else
- {
- Log( "Error: PopModeValue argument index out of range\n" );
- }
- }
- void CSelector::PopModeOption( void )
- {
- uint16_t i;
- uint16_t index;
- for (i=0; i<ListNames.size(); i++)
- {
- index = DisplayList.at(MODE_SELECT_OPTION).first+i;
- if (CheckRange( index, ItemsArgument.size() ))
- {
- ListNames.at(i).text = ItemsArgument.at(index).Name;
- if (i == DisplayList.at(MODE_SELECT_OPTION).absolute)
- {
- ListNames.at(i).font = FONT_SIZE_LARGE;
- }
- else
- {
- ListNames.at(i).font = FONT_SIZE_MEDIUM;
- }
- ListNames.at(i).color = Config.ColorFontFiles;
- }
- else
- {
- Log( "Error: PopModeOption index is out of range\n" );
- }
- }
- }
- void CSelector::PopModePlugin( void )
- {
- uint16_t i;
- uint16_t index;
- for (i=0; i<ListNames.size(); i++)
- {
- index = DisplayList.at(MODE_SELECT_PLUGIN).first+i;
- if (CheckRange( index, ItemsDefPlugin.size() ))
- {
- ListNames.at(i).text = ItemsDefPlugin.at(index).Name;
- if (i == DisplayList.at(MODE_SELECT_PLUGIN).absolute)
- {
- ListNames.at(i).font = FONT_SIZE_LARGE;
- }
- else
- {
- ListNames.at(i).font = FONT_SIZE_MEDIUM;
- }
- if (ItemsDefPlugin.at(index).Type == TYPE_DIR)
- ListNames.at(i).color = COLOR_RED;
- else
- ListNames.at(i).color = Config.ColorFontFiles;
- }
- else
- {
- Log( "Error: PopModePlugin index is out of range\n" );
- }
- }
- }
- void CSelector::PopModeRomOption( void )
- {
- uint16_t i;
- uint16_t index;
- for (i=0; i<ListNames.size(); i++)
- {
- index = DisplayList.at(MODE_ROM_OPTION).first+i;
- if (CheckRange( index, ItemsRomOption.size() ))
- {
- ListNames.at(i).text = ItemsRomOption.at(index).Name;
- if (i == DisplayList.at(MODE_ROM_OPTION).absolute)
- {
- ListNames.at(i).font = FONT_SIZE_LARGE;
- }
- else
- {
- ListNames.at(i).font = FONT_SIZE_MEDIUM;
- }
- ListNames.at(i).color = Config.ColorFontFiles;
- }
- else
- {
- Log( "Error: PopModeOption index is out of range\n" );
- }
- }
- }
- void CSelector::PopModeRomPlugin( void )
- {
- uint16_t i;
- uint16_t index;
- for (i=0; i<ListNames.size(); i++)
- {
- index = DisplayList.at(MODE_ROM_PLUGIN).first+i;
- if (CheckRange( index, ItemsRomPlugin.size() ))
- {
- ListNames.at(i).text = ItemsRomPlugin.at(index).Name;
- if (i == DisplayList.at(MODE_ROM_PLUGIN).absolute)
- {
- ListNames.at(i).font = FONT_SIZE_LARGE;
- }
- else
- {
- ListNames.at(i).font = FONT_SIZE_MEDIUM;
- }
- if (ItemsRomPlugin.at(index).Type == TYPE_DIR)
- ListNames.at(i).color = COLOR_RED;
- else
- ListNames.at(i).color = Config.ColorFontFiles;
- }
- else
- {
- Log( "Error: PopModePlugin index is out of range\n" );
- }
- }
- }
- void CSelector::LoadPreview( const string& name )
- {
- string filename;
- SDL_Surface* preview = NULL;
- if (ImagePreview != NULL)
- {
- DrawState_Preview = true;
- }
- FREE_IMAGE( ImagePreview );
- filename = Config.PreviewsPath + "/" + name.substr( 0, name.find_last_of(".")) + ".png";
- preview = LoadImage( filename.c_str() );
- if (preview != NULL)
- {
- ImagePreview = ScaleSurface( preview, Config.PreviewWidth, Config.PreviewHeight );
- FREE_IMAGE( preview );
- DrawState_Preview = true;
- }
- }
- int8_t CSelector::DrawNames( SDL_Rect& location )
- {
- uint16_t entry_index;
- uint16_t startx, starty;
- int16_t offset;
- SDL_Rect rect_clip;
- SDL_Surface* text_surface = NULL;
- if (Config.AutoLayout == false)
- {
- location.x = Config.PosX_ListNames;
- location.y = Config.PosY_ListNames;
- }
- startx = location.x;
- starty = location.y;
- if (ListNames.size() <= 0)
- {
- // Empty directories or zip files
- if (Config.UseZipSupport == true && Profile.ZipFile.length() > 0)
- {
- text_surface = TTF_RenderText_Solid( Fonts.at(FONT_SIZE_MEDIUM), EMPTY_ZIP_LABEL, Config.Colors.at(COLOR_BLACK) );
- }
- else
- {
- text_surface = TTF_RenderText_Solid( Fonts.at(FONT_SIZE_MEDIUM), EMPTY_DIR_LABEL, Config.Colors.at(COLOR_BLACK) );
- }
- if (text_surface != NULL)
- {
- location.x += ImageSelectPointer->w;
- rect_clip.x = 0;
- rect_clip.y = 0;
- rect_clip.w = Config.DisplayListMaxWidth-location.x;
- rect_clip.h = text_surface->h;
- ApplyImage( location.x, location.y, text_surface, Screen, &rect_clip );
- ListNameHeight = MAX(ListNameHeight, location.y+text_surface->h );
- location.x -= ImageSelectPointer->w;
- location.y += text_surface->h + Config.EntryYDelta;
- FREE_IMAGE( text_surface );
- }
- else
- {
- Log( "Failed to create TTF surface with TTF_RenderText_Solid: %s\n", TTF_GetError() );
- return 1;
- }
- }
- else
- {
- for (entry_index=0; entry_index<ListNames.size(); entry_index++)
- {
- offset = 0;
- // Draw the selector pointer
- if (entry_index == DisplayList.at(Mode).relative)
- {
- ApplyImage( location.x, location.y, ImageSelectPointer, Screen, NULL );
- // Reset scroll settings
- if (entry_index != LastSelectedEntry)
- {
- CurScrollPause = 0;
- CurScrollSpeed = 0;
- TextScrollOffset = 0;
- TextScrollDir = true;
- }
- LastSelectedEntry = entry_index;
- }
- text_surface = TTF_RenderText_Solid( Fonts.at(ListNames.at(entry_index).font), ListNames.at(entry_index).text.c_str(), Config.Colors.at(ListNames.at(entry_index).color) );
- if (text_surface != NULL)
- {
- location.x += ImageSelectPointer->w;
- RectEntries.at(entry_index).x = location.x;
- RectEntries.at(entry_index).y = location.y;
- RectEntries.at(entry_index).w = text_surface->w;
- RectEntries.at(entry_index).h = text_surface->h;
- if (text_surface->w > (Config.DisplayListMaxWidth-location.x) )
- {
- RectEntries.at(entry_index).w = Config.DisplayListMaxWidth-location.x;
- if (Config.TextScrollOption == true && DisplayList.at(Mode).relative == entry_index)
- {
- offset = TextScrollOffset;
- if (CurScrollPause > 1)
- {
- CurScrollPause++;
- if (CurScrollPause >= Config.ScrollPauseSpeed)
- {
- CurScrollPause = 1;
- }
- }
- else
- {
- CurScrollSpeed++;
- if (CurScrollSpeed >= Config.ScrollSpeed)
- {
- CurScrollSpeed = 1;
- if (TextScrollDir == true)
- {
- TextScrollOffset += Config.ScreenRatioW;
- }
- else
- {
- TextScrollOffset -= Config.ScreenRatioW;
- }
- Redraw = true;
- }
- if (RectEntries.at(entry_index).w+TextScrollOffset >= text_surface->w)
- {
- TextScrollDir = false;
- CurScrollPause = 2;
- }
- else if (TextScrollOffset <= 0)
- {
- TextScrollDir = true;
- CurScrollPause = 2;
- }
- }
- }
- }
- rect_clip.w = Config.DisplayListMaxWidth-location.x;
- rect_clip.h = text_surface->h;
- rect_clip.x = offset;
- rect_clip.y = 0;
- ApplyImage( location.x, location.y, text_surface, Screen, &rect_clip );
- ListNameHeight = MAX(ListNameHeight, location.y+text_surface->h );
- location.x -= ImageSelectPointer->w;
- location.y += text_surface->h + Config.EntryYDelta;
- FREE_IMAGE( text_surface );
- }
- else
- {
- Log( "Failed to create TTF surface with TTF_RenderText_Solid: %s\n", TTF_GetError() );
- return 1;
- }
- }
- }
- UpdateRect( startx, starty, Config.DisplayListMaxWidth-startx, ListNameHeight-starty );
- return 0;
- }
- void CSelector::SelectionLimits( item_pos_t& pos )
- {
- if (pos.absolute <= pos.first)
- {
- pos.relative = 0;
- if (pos.absolute < 0)
- {
- pos.absolute = 0;
- }
- pos.first = pos.absolute;
- if (pos.total < Config.MaxEntries)
- {
- pos.last = (pos.total-1);
- }
- else
- {
- pos.last = pos.absolute+(Config.MaxEntries-1);
- }
- }
- else if (pos.absolute >= pos.last)
- {
- if (pos.absolute > (int16_t)(pos.total-1))
- {
- pos.absolute = (pos.total-1);
- }
- pos.first = pos.absolute-(Config.MaxEntries-1);
- pos.last = pos.absolute;
- if (pos.total < Config.MaxEntries)
- {
- pos.relative = (pos.total-1);
- }
- else
- {
- pos.relative = Config.MaxEntries-1;
- }
- if (pos.first < 0)
- {
- pos.first = 0;
- }
- }
- }
- void CSelector::DrawBackground( void )
- {
- if (ImageBackground != NULL)
- {
- ApplyImage( 0, 0, ImageBackground, Screen, NULL );
- }
- else
- {
- SDL_FillRect( Screen, NULL, rgb_to_int(Config.Colors.at(Config.ColorBackground)) );
- }
- }
- int8_t CSelector::ConfigureButtons( void )
- {
- uint16_t i;
- // Common button mappings
- ButtonModesLeft.at(0) = EVENT_ONE_UP;
- ButtonModesLeft.at(1) = EVENT_PAGE_UP;
- ButtonModesLeft.at(2) = EVENT_PAGE_DOWN;
- ButtonModesLeft.at(3) = EVENT_ONE_DOWN;
- ButtonModesRight.at(0) = EVENT_QUIT;
- // Specific button mappings
- switch (Mode)
- {
- case MODE_SELECT_ENTRY:
- ButtonModesLeft.at(4) = EVENT_DIR_UP;
- ButtonModesLeft.at(5) = EVENT_DIR_DOWN;
- if (Config.UseZipSupport == true && Profile.ZipFile.length() > 0)
- {
- ButtonModesLeft.at(6) = EVENT_ZIP_MODE;
- }
- else
- {
- ButtonModesLeft.at(6) = EVENT_NONE;
- }
- ButtonModesRight.at(1) = EVENT_SELECT;
- ButtonModesRight.at(2) = EVENT_CFG_ITEM;
- ButtonModesRight.at(3) = EVENT_NONE;
- ButtonModesRight.at(3) = EVENT_CFG_APP; // TODO
- break;
- case MODE_SELECT_ARGUMENT:
- ButtonModesLeft.at(4) = EVENT_NONE;
- ButtonModesLeft.at(5) = EVENT_NONE;
- ButtonModesLeft.at(6) = EVENT_NONE;
- ButtonModesRight.at(1) = EVENT_BACK;
- ButtonModesRight.at(2) = EVENT_SELECT;
- ButtonModesRight.at(3) = EVENT_NONE;
- break;
- case MODE_SELECT_VALUE:
- ButtonModesLeft.at(4) = EVENT_NONE;
- ButtonModesLeft.at(5) = EVENT_NONE;
- ButtonModesLeft.at(6) = EVENT_NONE;
- ButtonModesRight.at(1) = EVENT_BACK;
- ButtonModesRight.at(2) = EVENT_SET_ALL;
- ButtonModesRight.at(3) = EVENT_SET_ONE;
- break;
- case MODE_SELECT_OPTION:
- ButtonModesLeft.at(4) = EVENT_NONE;
- ButtonModesLeft.at(5) = EVENT_NONE;
- ButtonModesLeft.at(6) = EVENT_NONE;
- ButtonModesRight.at(1) = EVENT_BACK;
- ButtonModesRight.at(2) = EVENT_SELECT;
- ButtonModesRight.at(3) = EVENT_NONE;
- break;
- case MODE_SELECT_PLUGIN:
- ButtonModesLeft.at(4) = EVENT_NONE;
- ButtonModesLeft.at(5) = EVENT_NONE;
- ButtonModesLeft.at(6) = EVENT_NONE;
- ButtonModesRight.at(1) = EVENT_BACK;
- ButtonModesRight.at(2) = EVENT_SELECT;
- ButtonModesRight.at(3) = EVENT_NONE;
- break;
- case MODE_ROM_OPTION:
- ButtonModesLeft.at(4) = EVENT_NONE;
- ButtonModesLeft.at(5) = EVENT_NONE;
- ButtonModesLeft.at(6) = EVENT_NONE;
- ButtonModesRight.at(1) = EVENT_BACK;
- ButtonModesRight.at(2) = EVENT_SELECT;
- ButtonModesRight.at(3) = EVENT_NONE;
- break;
- case MODE_ROM_PLUGIN:
- ButtonModesLeft.at(4) = EVENT_NONE;
- ButtonModesLeft.at(5) = EVENT_NONE;
- ButtonModesLeft.at(6) = EVENT_NONE;
- ButtonModesRight.at(1) = EVENT_BACK;
- ButtonModesRight.at(2) = EVENT_SELECT;
- ButtonModesRight.at(3) = EVENT_NONE;
- break;
- default:
- Log( "Error: Unknown Mode\n" );
- return 1;
- break;
- }
- // Overides for button driven by config options
- for (i=0; i<ButtonModesLeft.size(); i++ )
- {
- if (Config.ButtonModesLeftEnable.at(i) == false)
- {
- ButtonModesLeft.at(i) = EVENT_NONE;
- }
- }
- for (i=0; i<ButtonModesRight.size(); i++ )
- {
- if (Config.ButtonModesRightEnable.at(i) == false)
- {
- ButtonModesRight.at(i) = EVENT_NONE;
- }
- }
- return 0;
- }
- int8_t CSelector::DrawButtons( SDL_Rect& location )
- {
- uint8_t button;
- SDL_Rect preview;
- if (Config.AutoLayout == false)
- {
- location.x = Config.PosX_ButtonLeft;
- location.y = Config.PosY_ButtonLeft;
- }
- // Draw buttons on left
- if (DrawState_ButtonL == true)
- {
- for (button=0; button<BUTTONS_MAX_LEFT; button++)
- {
- RectButtonsLeft.at(button).x = location.x;
- RectButtonsLeft.at(button).y = location.y+(Config.ButtonHeightLeft*button)+(Config.EntryYOffset*button);
- RectButtonsLeft.at(button).w = Config.ButtonWidthLeft;
- RectButtonsLeft.at(button).h = Config.ButtonHeightLeft;
- if (ButtonModesLeft.at(button) != EVENT_NONE)
- {
- if (DrawButton( ButtonModesLeft.at(button), Fonts.at(FONT_SIZE_LARGE), RectButtonsLeft.at(button) ))
- {
- return 1;
- }
- }
- UpdateRect( RectButtonsLeft.at(button).x, RectButtonsLeft.at(button).y, RectButtonsLeft.at(button).w, RectButtonsLeft.at(button).h );
- }
- DrawState_ButtonL = false;
- }
- location.x += Config.ButtonWidthLeft + Config.EntryXOffset;
- // Draw buttons on right
- if (DrawState_ButtonR == …
Large files files are truncated, but you can click here to view the full file