Merge pull request #59 from penfold42/a-z

In browse, pressing a-z,0-9 jumps to the next entry with matching 1st letter
This commit is contained in:
Stephen White 2018-08-02 12:22:24 +10:00 committed by GitHub
commit bae47c0157
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 232 additions and 159 deletions

View file

@ -45,21 +45,6 @@ extern void CheckAutoMountImage(EXIT_TYPE reset_reason , FileBrowser* fileBrowse
unsigned char FileBrowser::LSTBuffer[FileBrowser::LSTBuffer_size];
const unsigned FileBrowser::SwapKeys[33] =
{
KEY_F1, KEY_KP1, KEY_1,
KEY_F2, KEY_KP2, KEY_2,
KEY_F3, KEY_KP3, KEY_3,
KEY_F4, KEY_KP4, KEY_4,
KEY_F5, KEY_KP5, KEY_5,
KEY_F6, KEY_KP6, KEY_6,
KEY_F7, KEY_KP7, KEY_7,
KEY_F8, KEY_KP8, KEY_8,
KEY_F9, KEY_KP9, KEY_9,
KEY_F10, KEY_KP0, KEY_0,
KEY_F11, KEY_KPMINUS, KEY_MINUS
};
static const u32 palette[] =
{
RGBA(0x00, 0x00, 0x00, 0xFF),
@ -370,12 +355,72 @@ void FileBrowser::BrowsableList::RefreshViewsHighlightScroll()
bool FileBrowser::BrowsableList::CheckBrowseNavigation()
{
InputMappings* inputMappings = InputMappings::Instance();
u32 numberOfEntriesMinus1 = entries.size() - 1;
bool dirty = false;
u32 index;
for (index = 0; index < views.size(); ++index)
{
dirty |= views[index].CheckBrowseNavigation(index != 0);
}
// check for keys a-z and 0-9
char searchChar = 0;
if (inputMappings->BrowseLetter())
searchChar = inputMappings->getKeyboardLetter();
if (inputMappings->BrowseNumber())
searchChar = inputMappings->getKeyboardNumber();
if (searchChar)
{
char temp[8];
unsigned found=0;
u32 i=0;
snprintf (temp, sizeof(temp), "%c", searchChar);
// first look from next to last
for (i=1+currentIndex; i <= numberOfEntriesMinus1 ; i++)
{
FileBrowser::BrowsableList::Entry* entry = &entries[i];
if (strncasecmp(temp, entry->filImage.fname, 1) == 0)
{
found=i;
break;
}
}
if (!found)
{
// look from first to previous
for (i=0; i< 1+currentIndex ; i++)
{
FileBrowser::BrowsableList::Entry* entry = &entries[i];
if (strncasecmp(temp, entry->filImage.fname, 1) == 0)
{
found=i;
break;
}
}
}
if (found)
{
currentIndex=found;
SetCurrent();
dirty |= 1;
}
}
else if (inputMappings->BrowseHome())
{
currentIndex = 0;
SetCurrent();
dirty |= 1;
}
else if (inputMappings->BrowseEnd())
{
currentIndex = numberOfEntriesMinus1;
SetCurrent();
dirty |= 1;
}
return dirty;
}
@ -400,8 +445,7 @@ FileBrowser::FileBrowser(DiskCaddy* diskCaddy, ROMs* roms, u8* deviceID, bool di
, roms(roms)
, deviceID(deviceID)
, displayPNGIcons(displayPNGIcons)
, buttonChangedDevice(false)
, buttonSelectROM(false)
, buttonChangedROMDevice(false)
, screenMain(screenMain)
, screenLCD(screenLCD)
, scrollHighlightRate(scrollHighlightRate)
@ -418,7 +462,8 @@ FileBrowser::FileBrowser(DiskCaddy* diskCaddy, ROMs* roms, u8* deviceID, bool di
folder.AddView(screenMain, columns, rows, positionX, positionY, false);
positionX = screenMain->ScaleX(1024 - 320);
caddySelections.AddView(screenMain, 6, rows, positionX, positionY, false);
columns = screenMain->ScaleX(40);
caddySelections.AddView(screenMain, columns, rows, positionX, positionY, false);
@ -837,54 +882,51 @@ void FileBrowser::UpdateInputFolders()
Keyboard* keyboard = Keyboard::Instance();
InputMappings* inputMappings = InputMappings::Instance();
buttonChangedROMDevice = false;
if (IEC_Bus::GetInputButtonHeld(4))
{
if (inputMappings->BrowseSelect())
{
GlobalSetDeviceID(8);
ShowDeviceAndROM();
buttonChangedDevice = true;
SelectROMOrDevice(7); // == device 8
buttonChangedROMDevice = true;
}
else if (inputMappings->BrowseUp())
{
GlobalSetDeviceID(9);
ShowDeviceAndROM();
buttonChangedDevice = true;
SelectROMOrDevice(8); // == device 9
buttonChangedROMDevice = true;
}
else if (inputMappings->BrowseDown())
{
GlobalSetDeviceID(10);
ShowDeviceAndROM();
buttonChangedDevice = true;
SelectROMOrDevice(9); // == device 10
buttonChangedROMDevice = true;
}
else if (inputMappings->BrowseBack())
{
GlobalSetDeviceID(11);
ShowDeviceAndROM();
buttonChangedDevice = true;
SelectROMOrDevice(10); // == device 11
buttonChangedROMDevice = true;
}
}
else if (IEC_Bus::GetInputButtonHeld(0))
{
if (inputMappings->BrowseUp())
{
SelectROM(0);
buttonSelectROM = true;
SelectROMOrDevice(0);
buttonChangedROMDevice = true;
}
else if (inputMappings->BrowseDown())
{
SelectROM(1);
buttonSelectROM = true;
SelectROMOrDevice(1);
buttonChangedROMDevice = true;
}
else if (inputMappings->BrowseBack())
{
SelectROM(2);
buttonSelectROM = true;
SelectROMOrDevice(2);
buttonChangedROMDevice = true;
}
else if (inputMappings->BrowseInsert())
{
SelectROM(3);
buttonSelectROM = true;
SelectROMOrDevice(3);
buttonChangedROMDevice = true;
}
}
else
@ -894,13 +936,7 @@ void FileBrowser::UpdateInputFolders()
//u32 numberOfEntriesMinus1 = folder.entries.size() - 1;
bool dirty = false;
if (inputMappings->BrowseSelect())
{
if (buttonSelectROM)
{
buttonSelectROM = false;
}
else
if (inputMappings->BrowseSelect() && !buttonChangedROMDevice )
{
FileBrowser::BrowsableList::Entry* current = folder.current;
if (current)
@ -948,7 +984,6 @@ void FileBrowser::UpdateInputFolders()
}
}
}
}
else if (inputMappings->BrowseDone())
{
selectionsMade = FillCaddyWithSelections();
@ -968,13 +1003,7 @@ void FileBrowser::UpdateInputFolders()
ClearSelections();
dirty = true;
}
else if (inputMappings->BrowseInsert())
{
if (buttonChangedDevice)
{
buttonChangedDevice = false;
}
else
else if (inputMappings->BrowseInsert() && !buttonChangedROMDevice )
{
FileBrowser::BrowsableList::Entry* current = folder.current;
if (current)
@ -982,7 +1011,6 @@ void FileBrowser::UpdateInputFolders()
dirty = AddToCaddy(current);
}
}
}
else if (inputMappings->BrowseNewD64())
{
char newFileName[64];
@ -1011,24 +1039,14 @@ void FileBrowser::UpdateInputFolders()
}
else
{
unsigned keySetIndex;
for (keySetIndex = 0; keySetIndex < 11; ++keySetIndex)
{
unsigned keySetIndexBase = keySetIndex * 3;
if (keyboard->KeyPressed(FileBrowser::SwapKeys[keySetIndexBase])
|| keyboard->KeyPressed(FileBrowser::SwapKeys[keySetIndexBase + 1])
|| keyboard->KeyPressed(FileBrowser::SwapKeys[keySetIndexBase + 2]))
{
if (SelectROM(keySetIndex))
// check for number keys for ROM and Drive Number changes
if (inputMappings->BrowseFunction()
&& inputMappings->getKeyboardFunction() >= 1
&& inputMappings->getKeyboardFunction() <= 11 )
{
SelectROMOrDevice(inputMappings->getKeyboardFunction());
}
else if ( (keySetIndex >= 7) && (keySetIndex <= 10 ) )
{
GlobalSetDeviceID( keySetIndex+1 );
ShowDeviceAndROM();
}
}
}
dirty = folder.CheckBrowseNavigation();
}
@ -1047,8 +1065,17 @@ void FileBrowser::UpdateInputFolders()
}
}
bool FileBrowser::SelectROM(u32 index)
bool FileBrowser::SelectROMOrDevice(u32 index)
// 1-7 select ROM image
// 8-11 change deviceID to 8-11
{
if ( (index >= 8) && (index <= 11 ) )
{
GlobalSetDeviceID( index );
ShowDeviceAndROM();
return true;
}
index--;
if ((index < ROMs::MAX_ROMS) && (roms->ROMValid[index]))
{
roms->currentROMIndex = index;

View file

@ -191,8 +191,6 @@ public:
static const long int LSTBuffer_size = 1024 * 8;
static unsigned char LSTBuffer[];
static const unsigned SwapKeys[];
static u32 Colour(int index);
bool SelectLST(const char* filenameLST);
@ -217,7 +215,7 @@ private:
bool CheckForPNG(const char* filename, FILINFO& filIcon);
void DisplayPNG();
bool SelectROM(u32 index);
bool SelectROMOrDevice(u32 index);
enum State
{
@ -232,8 +230,7 @@ private:
ROMs* roms;
u8* deviceID;
bool displayPNGIcons;
bool buttonChangedDevice;
bool buttonSelectROM;
bool buttonChangedROMDevice;
BrowsableList caddySelections;

View file

@ -152,7 +152,6 @@ bool InputMappings::CheckKeyboardBrowseMode()
keyboardFlags = 0;
// TODO: add KEY_HOME and KEY_END
if (keyboard->KeyHeld(KEY_ESC))
SetKeyboardFlag(ESC_FLAG);
else if (keyboard->KeyHeld(KEY_ENTER))
@ -181,26 +180,58 @@ bool InputMappings::CheckKeyboardBrowseMode()
else
SetKeyboardFlag(PAGEDOWN_FLAG);
}
//else if (keyboard->KeyHeld(KEY_HOME))
// SetKeyboardFlag(PAGEUP_LCD_FLAG);
//else if (keyboard->KeyHeld(KEY_END))
// SetKeyboardFlag(PAGEDOWN_LCD_FLAG);
else if (keyboard->KeyHeld(KEY_HOME))
SetKeyboardFlag(HOME_FLAG);
else if (keyboard->KeyHeld(KEY_END))
SetKeyboardFlag(END_FLAG);
else if (keyboard->KeyHeld(KEY_N) && keyboard->KeyEitherAlt() )
SetKeyboardFlag(NEWD64_FLAG);
else if (keyboard->KeyHeld(KEY_A) && keyboard->KeyEitherAlt() )
SetKeyboardFlag(AUTOLOAD_FLAG);
else if (keyboard->KeyHeld(KEY_R) && keyboard->KeyEitherAlt() )
SetKeyboardFlag(FAKERESET_FLAG);
else if (keyboard->KeyHeld(KEY_W) && keyboard->KeyEitherAlt())
else if (keyboard->KeyHeld(KEY_W) && keyboard->KeyEitherAlt() )
SetKeyboardFlag(WRITEPROTECT_FLAG);
else
{
unsigned index;
for (index = 0; index < 11; ++index)
if (keyboard->KeyNoModifiers())
{
unsigned keySetIndexBase = index * 3;
if (keyboard->KeyHeld(FileBrowser::SwapKeys[keySetIndexBase]) || keyboard->KeyHeld(FileBrowser::SwapKeys[keySetIndexBase + 1]) || keyboard->KeyHeld(FileBrowser::SwapKeys[keySetIndexBase + 2]))
keyboardFlags |= NUMBER_FLAG;
unsigned index;
for (index = KEY_1; index <= KEY_0; ++index)
{
if (keyboard->KeyHeld(index))
{
SetKeyboardFlag(NUMBER_FLAG);
keyboardNumber = index-KEY_1+'1'; // key 1 is ascii '1'
if (keyboardNumber > '9') keyboardNumber = '0';
}
}
for (index = KEY_KP1; index <= KEY_KP0; ++index)
{
if (keyboard->KeyHeld(index))
{
SetKeyboardFlag(NUMBER_FLAG);
keyboardNumber = index-KEY_KP1+'1'; // key 1 is ascii '1'
if (keyboardNumber > '9') keyboardNumber = '0';
}
}
for (index = KEY_A; index <= KEY_Z; ++index)
{
if (keyboard->KeyHeld(index))
{
SetKeyboardFlag(LETTER_FLAG);
keyboardLetter = index-KEY_A+'A'; // key A is ascii 'A'
}
}
for (index = KEY_F1; index <= KEY_F12; ++index) // F13 isnt contiguous
{
if (keyboard->KeyHeld(index))
{
SetKeyboardFlag(FUNCTION_FLAG);
keyboardFunction = index-KEY_F1+1; // key F1 is 1
}
}
}
}
@ -227,12 +258,14 @@ void InputMappings::CheckKeyboardEmulationMode(unsigned numberOfImages, unsigned
else if (numberOfImages > 1)
{
unsigned index;
for (index = 0; index < numberOfImagesMax; ++index)
for (index = 0; index < sizeof(NumberKeys)/sizeof(NumberKeys[0]); index+=3)
{
unsigned keySetIndexBase = index * 3;
if (keyboard->KeyHeld(FileBrowser::SwapKeys[keySetIndexBase]) || keyboard->KeyHeld(FileBrowser::SwapKeys[keySetIndexBase + 1]) || keyboard->KeyHeld(FileBrowser::SwapKeys[keySetIndexBase + 2]))
directDiskSwapRequest |= (1 << index);
if (keyboard->KeyHeld(NumberKeys[index])
|| keyboard->KeyHeld(NumberKeys[index + 1])
|| keyboard->KeyHeld(NumberKeys[index + 2]) )
directDiskSwapRequest |= (1 << index/3);
}
}
}
}

View file

@ -41,8 +41,27 @@
#define AUTOLOAD_FLAG (1 << 15)
#define FAKERESET_FLAG (1 << 16)
#define WRITEPROTECT_FLAG (1 << 17)
#define LETTER_FLAG (1 << 18)
#define HOME_FLAG (1 << 19)
#define END_FLAG (1 << 20)
#define FUNCTION_FLAG (1 << 21)
// dont exceed 32!!
const unsigned NumberKeys[33] =
{
KEY_F1, KEY_KP1, KEY_1,
KEY_F2, KEY_KP2, KEY_2,
KEY_F3, KEY_KP3, KEY_3,
KEY_F4, KEY_KP4, KEY_4,
KEY_F5, KEY_KP5, KEY_5,
KEY_F6, KEY_KP6, KEY_6,
KEY_F7, KEY_KP7, KEY_7,
KEY_F8, KEY_KP8, KEY_8,
KEY_F9, KEY_KP9, KEY_9,
KEY_F10, KEY_KP0, KEY_0,
KEY_F11, KEY_KPMINUS, KEY_MINUS
};
class InputMappings : public Singleton<InputMappings>
{
protected:
@ -59,6 +78,10 @@ protected:
bool enterButtonPressedPrev;
bool enterButtonPressed;
unsigned keyboardNumber;
unsigned keyboardLetter;
unsigned keyboardFunction;
//inline void SetUartFlag(unsigned flag) { uartFlags |= flag; }
//inline bool UartFlag(unsigned flag) { return (uartFlags & flag) != 0; }
inline void SetKeyboardFlag(unsigned flag) { keyboardFlags |= flag; }
@ -101,15 +124,9 @@ public:
return KeyboardFlag(PREV_FLAG)/* | UartFlag(PREV_FLAG)*/ | ButtonFlag(PREV_FLAG);
}
inline bool AutoLoad()
{
return KeyboardFlag(AUTOLOAD_FLAG);
}
inline bool AutoLoad() { return KeyboardFlag(AUTOLOAD_FLAG); }
inline bool FakeReset()
{
return KeyboardFlag(FAKERESET_FLAG);
}
inline bool FakeReset() { return KeyboardFlag(FAKERESET_FLAG); }
inline bool BrowseSelect()
{
@ -135,10 +152,7 @@ public:
{
return KeyboardFlag(PAGEUP_FLAG)/* | UartFlag(PAGEUP_FLAG)*/;
}
inline bool BrowsePageUpLCD()
{
return KeyboardFlag(PAGEUP_LCD_FLAG);
}
inline bool BrowsePageUpLCD() { return KeyboardFlag(PAGEUP_LCD_FLAG); }
inline bool BrowseDown()
{
@ -149,35 +163,32 @@ public:
{
return KeyboardFlag(PAGEDOWN_FLAG)/* | UartFlag(PAGEDOWN_FLAG)*/;
}
inline bool BrowsePageDownLCD()
{
return KeyboardFlag(PAGEDOWN_LCD_FLAG);
}
inline bool BrowsePageDownLCD() { return KeyboardFlag(PAGEDOWN_LCD_FLAG); }
inline bool BrowseInsert()
{
return KeyboardFlag(INSERT_FLAG)/* | UartFlag(INSERT_FLAG)*/ | ButtonFlag(INSERT_FLAG);
}
inline bool BrowseNewD64()
{
return KeyboardFlag(NEWD64_FLAG);
}
inline bool BrowseNewD64() { return KeyboardFlag(NEWD64_FLAG); }
inline bool BrowseAutoLoad()
{
return KeyboardFlag(AUTOLOAD_FLAG);
}
inline bool BrowseAutoLoad() { return KeyboardFlag(AUTOLOAD_FLAG); }
inline bool BrowseFakeReset()
{
return KeyboardFlag(FAKERESET_FLAG);
}
inline bool BrowseFakeReset() { return KeyboardFlag(FAKERESET_FLAG); }
inline bool BrowseWriteProtect()
{
return KeyboardFlag(WRITEPROTECT_FLAG);
}
inline bool BrowseWriteProtect() { return KeyboardFlag(WRITEPROTECT_FLAG); }
inline bool BrowseNumber() { return KeyboardFlag(NUMBER_FLAG); }
inline bool BrowseLetter() { return KeyboardFlag(LETTER_FLAG); }
inline bool BrowseFunction() { return KeyboardFlag(FUNCTION_FLAG); }
inline bool BrowseHome() { return KeyboardFlag(HOME_FLAG); }
inline bool BrowseEnd() { return KeyboardFlag(END_FLAG); }
inline char getKeyboardNumber() { return keyboardNumber; }
inline char getKeyboardLetter() { return (char) keyboardLetter; }
inline unsigned getKeyboardFunction() { return (char) keyboardFunction; }
// Used by the 2 cores so need to be volatile
//volatile static unsigned directDiskSwapRequest;
@ -187,3 +198,4 @@ public:
// static unsigned escapeSequenceIndex;
};
#endif

View file

@ -348,5 +348,9 @@ public:
{
return (modifier & (KEY_MOD_LALT | KEY_MOD_RALT) );
}
inline bool KeyNoModifiers()
{
return (!modifier );
}
};
#endif