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]; 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[] = static const u32 palette[] =
{ {
RGBA(0x00, 0x00, 0x00, 0xFF), RGBA(0x00, 0x00, 0x00, 0xFF),
@ -370,12 +355,72 @@ void FileBrowser::BrowsableList::RefreshViewsHighlightScroll()
bool FileBrowser::BrowsableList::CheckBrowseNavigation() bool FileBrowser::BrowsableList::CheckBrowseNavigation()
{ {
InputMappings* inputMappings = InputMappings::Instance();
u32 numberOfEntriesMinus1 = entries.size() - 1;
bool dirty = false; bool dirty = false;
u32 index; u32 index;
for (index = 0; index < views.size(); ++index) for (index = 0; index < views.size(); ++index)
{ {
dirty |= views[index].CheckBrowseNavigation(index != 0); 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; return dirty;
} }
@ -400,8 +445,7 @@ FileBrowser::FileBrowser(DiskCaddy* diskCaddy, ROMs* roms, u8* deviceID, bool di
, roms(roms) , roms(roms)
, deviceID(deviceID) , deviceID(deviceID)
, displayPNGIcons(displayPNGIcons) , displayPNGIcons(displayPNGIcons)
, buttonChangedDevice(false) , buttonChangedROMDevice(false)
, buttonSelectROM(false)
, screenMain(screenMain) , screenMain(screenMain)
, screenLCD(screenLCD) , screenLCD(screenLCD)
, scrollHighlightRate(scrollHighlightRate) , scrollHighlightRate(scrollHighlightRate)
@ -418,7 +462,8 @@ FileBrowser::FileBrowser(DiskCaddy* diskCaddy, ROMs* roms, u8* deviceID, bool di
folder.AddView(screenMain, columns, rows, positionX, positionY, false); folder.AddView(screenMain, columns, rows, positionX, positionY, false);
positionX = screenMain->ScaleX(1024 - 320); 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(); Keyboard* keyboard = Keyboard::Instance();
InputMappings* inputMappings = InputMappings::Instance(); InputMappings* inputMappings = InputMappings::Instance();
buttonChangedROMDevice = false;
if (IEC_Bus::GetInputButtonHeld(4)) if (IEC_Bus::GetInputButtonHeld(4))
{ {
if (inputMappings->BrowseSelect()) if (inputMappings->BrowseSelect())
{ {
GlobalSetDeviceID(8); SelectROMOrDevice(7); // == device 8
ShowDeviceAndROM(); buttonChangedROMDevice = true;
buttonChangedDevice = true;
} }
else if (inputMappings->BrowseUp()) else if (inputMappings->BrowseUp())
{ {
GlobalSetDeviceID(9); SelectROMOrDevice(8); // == device 9
ShowDeviceAndROM(); buttonChangedROMDevice = true;
buttonChangedDevice = true;
} }
else if (inputMappings->BrowseDown()) else if (inputMappings->BrowseDown())
{ {
GlobalSetDeviceID(10); SelectROMOrDevice(9); // == device 10
ShowDeviceAndROM(); buttonChangedROMDevice = true;
buttonChangedDevice = true;
} }
else if (inputMappings->BrowseBack()) else if (inputMappings->BrowseBack())
{ {
GlobalSetDeviceID(11); SelectROMOrDevice(10); // == device 11
ShowDeviceAndROM(); buttonChangedROMDevice = true;
buttonChangedDevice = true;
} }
} }
else if (IEC_Bus::GetInputButtonHeld(0)) else if (IEC_Bus::GetInputButtonHeld(0))
{ {
if (inputMappings->BrowseUp()) if (inputMappings->BrowseUp())
{ {
SelectROM(0); SelectROMOrDevice(0);
buttonSelectROM = true; buttonChangedROMDevice = true;
} }
else if (inputMappings->BrowseDown()) else if (inputMappings->BrowseDown())
{ {
SelectROM(1); SelectROMOrDevice(1);
buttonSelectROM = true; buttonChangedROMDevice = true;
} }
else if (inputMappings->BrowseBack()) else if (inputMappings->BrowseBack())
{ {
SelectROM(2); SelectROMOrDevice(2);
buttonSelectROM = true; buttonChangedROMDevice = true;
} }
else if (inputMappings->BrowseInsert()) else if (inputMappings->BrowseInsert())
{ {
SelectROM(3); SelectROMOrDevice(3);
buttonSelectROM = true; buttonChangedROMDevice = true;
} }
} }
else else
@ -894,13 +936,7 @@ void FileBrowser::UpdateInputFolders()
//u32 numberOfEntriesMinus1 = folder.entries.size() - 1; //u32 numberOfEntriesMinus1 = folder.entries.size() - 1;
bool dirty = false; bool dirty = false;
if (inputMappings->BrowseSelect()) if (inputMappings->BrowseSelect() && !buttonChangedROMDevice )
{
if (buttonSelectROM)
{
buttonSelectROM = false;
}
else
{ {
FileBrowser::BrowsableList::Entry* current = folder.current; FileBrowser::BrowsableList::Entry* current = folder.current;
if (current) if (current)
@ -948,7 +984,6 @@ void FileBrowser::UpdateInputFolders()
} }
} }
} }
}
else if (inputMappings->BrowseDone()) else if (inputMappings->BrowseDone())
{ {
selectionsMade = FillCaddyWithSelections(); selectionsMade = FillCaddyWithSelections();
@ -968,13 +1003,7 @@ void FileBrowser::UpdateInputFolders()
ClearSelections(); ClearSelections();
dirty = true; dirty = true;
} }
else if (inputMappings->BrowseInsert()) else if (inputMappings->BrowseInsert() && !buttonChangedROMDevice )
{
if (buttonChangedDevice)
{
buttonChangedDevice = false;
}
else
{ {
FileBrowser::BrowsableList::Entry* current = folder.current; FileBrowser::BrowsableList::Entry* current = folder.current;
if (current) if (current)
@ -982,7 +1011,6 @@ void FileBrowser::UpdateInputFolders()
dirty = AddToCaddy(current); dirty = AddToCaddy(current);
} }
} }
}
else if (inputMappings->BrowseNewD64()) else if (inputMappings->BrowseNewD64())
{ {
char newFileName[64]; char newFileName[64];
@ -1011,24 +1039,14 @@ void FileBrowser::UpdateInputFolders()
} }
else else
{ {
unsigned keySetIndex; // check for number keys for ROM and Drive Number changes
for (keySetIndex = 0; keySetIndex < 11; ++keySetIndex) if (inputMappings->BrowseFunction()
{ && inputMappings->getKeyboardFunction() >= 1
unsigned keySetIndexBase = keySetIndex * 3; && inputMappings->getKeyboardFunction() <= 11 )
if (keyboard->KeyPressed(FileBrowser::SwapKeys[keySetIndexBase])
|| keyboard->KeyPressed(FileBrowser::SwapKeys[keySetIndexBase + 1])
|| keyboard->KeyPressed(FileBrowser::SwapKeys[keySetIndexBase + 2]))
{
if (SelectROM(keySetIndex))
{ {
SelectROMOrDevice(inputMappings->getKeyboardFunction());
} }
else if ( (keySetIndex >= 7) && (keySetIndex <= 10 ) )
{
GlobalSetDeviceID( keySetIndex+1 );
ShowDeviceAndROM();
}
}
}
dirty = folder.CheckBrowseNavigation(); 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])) if ((index < ROMs::MAX_ROMS) && (roms->ROMValid[index]))
{ {
roms->currentROMIndex = index; roms->currentROMIndex = index;

View File

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

View File

@ -152,7 +152,6 @@ bool InputMappings::CheckKeyboardBrowseMode()
keyboardFlags = 0; keyboardFlags = 0;
// TODO: add KEY_HOME and KEY_END
if (keyboard->KeyHeld(KEY_ESC)) if (keyboard->KeyHeld(KEY_ESC))
SetKeyboardFlag(ESC_FLAG); SetKeyboardFlag(ESC_FLAG);
else if (keyboard->KeyHeld(KEY_ENTER)) else if (keyboard->KeyHeld(KEY_ENTER))
@ -181,10 +180,10 @@ bool InputMappings::CheckKeyboardBrowseMode()
else else
SetKeyboardFlag(PAGEDOWN_FLAG); SetKeyboardFlag(PAGEDOWN_FLAG);
} }
//else if (keyboard->KeyHeld(KEY_HOME)) else if (keyboard->KeyHeld(KEY_HOME))
// SetKeyboardFlag(PAGEUP_LCD_FLAG); SetKeyboardFlag(HOME_FLAG);
//else if (keyboard->KeyHeld(KEY_END)) else if (keyboard->KeyHeld(KEY_END))
// SetKeyboardFlag(PAGEDOWN_LCD_FLAG); SetKeyboardFlag(END_FLAG);
else if (keyboard->KeyHeld(KEY_N) && keyboard->KeyEitherAlt() ) else if (keyboard->KeyHeld(KEY_N) && keyboard->KeyEitherAlt() )
SetKeyboardFlag(NEWD64_FLAG); SetKeyboardFlag(NEWD64_FLAG);
else if (keyboard->KeyHeld(KEY_A) && keyboard->KeyEitherAlt() ) else if (keyboard->KeyHeld(KEY_A) && keyboard->KeyEitherAlt() )
@ -195,12 +194,44 @@ bool InputMappings::CheckKeyboardBrowseMode()
SetKeyboardFlag(WRITEPROTECT_FLAG); SetKeyboardFlag(WRITEPROTECT_FLAG);
else else
{ {
unsigned index; if (keyboard->KeyNoModifiers())
for (index = 0; index < 11; ++index)
{ {
unsigned keySetIndexBase = index * 3; unsigned index;
if (keyboard->KeyHeld(FileBrowser::SwapKeys[keySetIndexBase]) || keyboard->KeyHeld(FileBrowser::SwapKeys[keySetIndexBase + 1]) || keyboard->KeyHeld(FileBrowser::SwapKeys[keySetIndexBase + 2]))
keyboardFlags |= NUMBER_FLAG; 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) else if (numberOfImages > 1)
{ {
unsigned index; 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(NumberKeys[index])
if (keyboard->KeyHeld(FileBrowser::SwapKeys[keySetIndexBase]) || keyboard->KeyHeld(FileBrowser::SwapKeys[keySetIndexBase + 1]) || keyboard->KeyHeld(FileBrowser::SwapKeys[keySetIndexBase + 2])) || keyboard->KeyHeld(NumberKeys[index + 1])
directDiskSwapRequest |= (1 << index); || keyboard->KeyHeld(NumberKeys[index + 2]) )
directDiskSwapRequest |= (1 << index/3);
} }
} }
} }
} }

View File

@ -41,8 +41,27 @@
#define AUTOLOAD_FLAG (1 << 15) #define AUTOLOAD_FLAG (1 << 15)
#define FAKERESET_FLAG (1 << 16) #define FAKERESET_FLAG (1 << 16)
#define WRITEPROTECT_FLAG (1 << 17) #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!! // 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> class InputMappings : public Singleton<InputMappings>
{ {
protected: protected:
@ -59,6 +78,10 @@ protected:
bool enterButtonPressedPrev; bool enterButtonPressedPrev;
bool enterButtonPressed; bool enterButtonPressed;
unsigned keyboardNumber;
unsigned keyboardLetter;
unsigned keyboardFunction;
//inline void SetUartFlag(unsigned flag) { uartFlags |= flag; } //inline void SetUartFlag(unsigned flag) { uartFlags |= flag; }
//inline bool UartFlag(unsigned flag) { return (uartFlags & flag) != 0; } //inline bool UartFlag(unsigned flag) { return (uartFlags & flag) != 0; }
inline void SetKeyboardFlag(unsigned flag) { keyboardFlags |= flag; } inline void SetKeyboardFlag(unsigned flag) { keyboardFlags |= flag; }
@ -101,15 +124,9 @@ public:
return KeyboardFlag(PREV_FLAG)/* | UartFlag(PREV_FLAG)*/ | ButtonFlag(PREV_FLAG); return KeyboardFlag(PREV_FLAG)/* | UartFlag(PREV_FLAG)*/ | ButtonFlag(PREV_FLAG);
} }
inline bool AutoLoad() inline bool AutoLoad() { return KeyboardFlag(AUTOLOAD_FLAG); }
{
return KeyboardFlag(AUTOLOAD_FLAG);
}
inline bool FakeReset() inline bool FakeReset() { return KeyboardFlag(FAKERESET_FLAG); }
{
return KeyboardFlag(FAKERESET_FLAG);
}
inline bool BrowseSelect() inline bool BrowseSelect()
{ {
@ -135,10 +152,7 @@ public:
{ {
return KeyboardFlag(PAGEUP_FLAG)/* | UartFlag(PAGEUP_FLAG)*/; return KeyboardFlag(PAGEUP_FLAG)/* | UartFlag(PAGEUP_FLAG)*/;
} }
inline bool BrowsePageUpLCD() inline bool BrowsePageUpLCD() { return KeyboardFlag(PAGEUP_LCD_FLAG); }
{
return KeyboardFlag(PAGEUP_LCD_FLAG);
}
inline bool BrowseDown() inline bool BrowseDown()
{ {
@ -149,35 +163,32 @@ public:
{ {
return KeyboardFlag(PAGEDOWN_FLAG)/* | UartFlag(PAGEDOWN_FLAG)*/; return KeyboardFlag(PAGEDOWN_FLAG)/* | UartFlag(PAGEDOWN_FLAG)*/;
} }
inline bool BrowsePageDownLCD() inline bool BrowsePageDownLCD() { return KeyboardFlag(PAGEDOWN_LCD_FLAG); }
{
return KeyboardFlag(PAGEDOWN_LCD_FLAG);
}
inline bool BrowseInsert() inline bool BrowseInsert()
{ {
return KeyboardFlag(INSERT_FLAG)/* | UartFlag(INSERT_FLAG)*/ | ButtonFlag(INSERT_FLAG); return KeyboardFlag(INSERT_FLAG)/* | UartFlag(INSERT_FLAG)*/ | ButtonFlag(INSERT_FLAG);
} }
inline bool BrowseNewD64() inline bool BrowseNewD64() { return KeyboardFlag(NEWD64_FLAG); }
{
return KeyboardFlag(NEWD64_FLAG);
}
inline bool BrowseAutoLoad() inline bool BrowseAutoLoad() { return KeyboardFlag(AUTOLOAD_FLAG); }
{
return KeyboardFlag(AUTOLOAD_FLAG);
}
inline bool BrowseFakeReset() inline bool BrowseFakeReset() { return KeyboardFlag(FAKERESET_FLAG); }
{
return KeyboardFlag(FAKERESET_FLAG);
}
inline bool BrowseWriteProtect() inline bool BrowseWriteProtect() { return KeyboardFlag(WRITEPROTECT_FLAG); }
{
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 // Used by the 2 cores so need to be volatile
//volatile static unsigned directDiskSwapRequest; //volatile static unsigned directDiskSwapRequest;
@ -187,3 +198,4 @@ public:
// static unsigned escapeSequenceIndex; // static unsigned escapeSequenceIndex;
}; };
#endif #endif

View File

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