Skip to content

Commit

Permalink
Pos Ed. right mouse button scrolling + code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
8bitbubsy committed Sep 7, 2023
1 parent 45b60c7 commit baeb792
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 88 deletions.
62 changes: 10 additions & 52 deletions src/pt2_keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,7 @@ void keyDownHandler(SDL_Scancode scancode, SDL_Keycode keycode)
{
if (ui.posEdScreenShown)
{
if (song->currPos > 0)
{
if (song->currPos-(POSED_LIST_SIZE-1) > 0)
modSetPos(song->currPos-(POSED_LIST_SIZE-1), DONT_SET_ROW);
else
modSetPos(0, DONT_SET_ROW);
}
posEdPageUp();
}
else if (ui.diskOpScreenShown)
{
Expand Down Expand Up @@ -435,13 +429,7 @@ void keyDownHandler(SDL_Scancode scancode, SDL_Keycode keycode)
{
if (ui.posEdScreenShown)
{
if (song->currPos != song->header.songLength-1)
{
if (song->currPos+(POSED_LIST_SIZE-1) <= song->header.songLength-1)
modSetPos(song->currPos+(POSED_LIST_SIZE-1), DONT_SET_ROW);
else
modSetPos(song->header.songLength - 1, DONT_SET_ROW);
}
posEdPageDown();
}
else if (ui.diskOpScreenShown)
{
Expand Down Expand Up @@ -472,8 +460,7 @@ void keyDownHandler(SDL_Scancode scancode, SDL_Keycode keycode)
{
if (ui.posEdScreenShown)
{
if (song->currPos > 0)
modSetPos(0, DONT_SET_ROW);
posEdScrollToTop();
}
else if (ui.diskOpScreenShown)
{
Expand All @@ -495,7 +482,7 @@ void keyDownHandler(SDL_Scancode scancode, SDL_Keycode keycode)
{
if (ui.posEdScreenShown)
{
modSetPos(song->header.songLength - 1, DONT_SET_ROW);
posEdScrollToBottom();
}
else if (ui.diskOpScreenShown)
{
Expand Down Expand Up @@ -1696,14 +1683,7 @@ void keyDownHandler(SDL_Scancode scancode, SDL_Keycode keycode)
}
else if (ui.posEdScreenShown)
{
if (song->currPos != song->header.songLength-1)
{
if (++song->currPos > song->header.songLength-1)
song->currPos = song->header.songLength-1;

modSetPos(song->currPos, DONT_SET_ROW);
ui.updatePosEd = true;
}
posEdScrollDown();

if (!keyb.repeatKey)
keyb.delayCounter = 0;
Expand Down Expand Up @@ -1745,11 +1725,7 @@ void keyDownHandler(SDL_Scancode scancode, SDL_Keycode keycode)
}
else if (ui.posEdScreenShown)
{
if (song->currPos > 0)
{
modSetPos(song->currPos - 1, DONT_SET_ROW);
ui.updatePosEd = true;
}
posEdScrollUp();

if (!keyb.repeatKey)
keyb.delayCounter = 0;
Expand Down Expand Up @@ -2969,10 +2945,7 @@ void handleKeyRepeat(SDL_Scancode scancode)

if (ui.posEdScreenShown)
{
if (song->currPos-(POSED_LIST_SIZE-1) > 0)
modSetPos(song->currPos-(POSED_LIST_SIZE-1), DONT_SET_ROW);
else
modSetPos(0, DONT_SET_ROW);
posEdPageUp();
}
else if (ui.diskOpScreenShown)
{
Expand Down Expand Up @@ -3006,10 +2979,7 @@ void handleKeyRepeat(SDL_Scancode scancode)

if (ui.posEdScreenShown)
{
if (song->currPos+(POSED_LIST_SIZE-1) <= song->header.songLength-1)
modSetPos(song->currPos+(POSED_LIST_SIZE-1), DONT_SET_ROW);
else
modSetPos(song->header.songLength - 1, DONT_SET_ROW);
posEdPageDown();
}
else if (ui.diskOpScreenShown)
{
Expand Down Expand Up @@ -3167,11 +3137,7 @@ void handleKeyRepeat(SDL_Scancode scancode)
if (keyb.repeatCounter >= 3)
{
keyb.repeatCounter = 0;
if (song->currPos > 0)
{
modSetPos(song->currPos - 1, DONT_SET_ROW);
ui.updatePosEd = true;
}
posEdScrollUp();
}
}
else if (!ui.samplerScreenShown)
Expand Down Expand Up @@ -3220,15 +3186,7 @@ void handleKeyRepeat(SDL_Scancode scancode)
if (keyb.repeatCounter >= 3)
{
keyb.repeatCounter = 0;

if (song->currPos != song->header.songLength-1)
{
if (++song->currPos > song->header.songLength-1)
song->currPos = song->header.songLength-1;

modSetPos(song->currPos, DONT_SET_ROW);
ui.updatePosEd = true;
}
posEdScrollDown();
}
}
else if (!ui.samplerScreenShown)
Expand Down
46 changes: 10 additions & 36 deletions src/pt2_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1901,9 +1901,9 @@ void mouseWheelUpHandler(void)
ui.updateDiskOpFileList = true;
}
}
else if (ui.posEdScreenShown && song->currPos > 0)
else if (ui.posEdScreenShown)
{
modSetPos(song->currPos - 1, DONT_SET_ROW);
posEdScrollUp();
}
}
else if (ui.samplerScreenShown) // lower part of screen
Expand Down Expand Up @@ -1933,9 +1933,9 @@ void mouseWheelDownHandler(void)
ui.updateDiskOpFileList = true;
}
}
else if (ui.posEdScreenShown && song->currPos < song->header.songLength-1)
else if (ui.posEdScreenShown)
{
modSetPos(song->currPos + 1, DONT_SET_ROW);
posEdScrollDown();
}
}
else if (ui.samplerScreenShown) // lower part of screen
Expand Down Expand Up @@ -3043,34 +3043,10 @@ static bool handleGUIButtons(int32_t button) // are you prepared to enter the ju
break;

case PTB_PE_PATTNAME: posEdEditName(); break;

case PTB_PE_SCROLLTOP:
{
if (song->currPos != 0)
modSetPos(0, DONT_SET_ROW);
}
break;

case PTB_PE_SCROLLUP:
{
if (song->currPos > 0)
modSetPos(song->currPos - 1, DONT_SET_ROW);
}
break;

case PTB_PE_SCROLLDOWN:
{
if (song->currPos < song->header.songLength-1)
modSetPos(song->currPos + 1, DONT_SET_ROW);
}
break;

case PTB_PE_SCROLLBOT:
{
if (song->currPos != song->header.songLength-1)
modSetPos(song->header.songLength - 1, DONT_SET_ROW);
}
break;
case PTB_PE_SCROLLTOP: posEdScrollToTop(); break;
case PTB_PE_SCROLLUP: posEdScrollUp(); break;
case PTB_PE_SCROLLDOWN: posEdScrollDown(); break;
case PTB_PE_SCROLLBOT: posEdScrollToBottom(); break;

case PTB_PE_EXIT:
{
Expand Down Expand Up @@ -4626,8 +4602,7 @@ static void handleRepeatedGUIButtons(void)
if (mouse.repeatCounter >= 2)
{
mouse.repeatCounter = 0;
if (song->currPos > 0)
modSetPos(song->currPos - 1, DONT_SET_ROW);
posEdScrollUp();
}
}
break;
Expand All @@ -4637,8 +4612,7 @@ static void handleRepeatedGUIButtons(void)
if (mouse.repeatCounter >= 2)
{
mouse.repeatCounter = 0;
if (song->currPos < song->header.songLength-1)
modSetPos(song->currPos + 1, DONT_SET_ROW);
posEdScrollDown();
}
}
break;
Expand Down
68 changes: 68 additions & 0 deletions src/pt2_posed.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,74 @@

static char posEdNames[MAX_PATTERNS][16];

void posEdScrollDown(void)
{
const uint16_t scrollAmount = mouse.rightButtonPressed ? 10 : 1;

if (song->currPos < song->header.songLength-1)
{
int16_t pos = song->currPos + scrollAmount;
if (pos > song->header.songLength-1)
pos = song->header.songLength-1;

modSetPos(pos, DONT_SET_ROW);
}
}

void posEdScrollUp(void)
{
const uint16_t scrollAmount = mouse.rightButtonPressed ? 10 : 1;

if (song->currPos > 0)
{
int16_t pos = song->currPos - scrollAmount;
if (pos < 0)
pos = 0;

modSetPos(pos, DONT_SET_ROW);
}
}

void posEdPageUp(void)
{
const uint16_t scrollAmount = POSED_LIST_SIZE;

if (song->currPos > 0)
{
int16_t pos = song->currPos - scrollAmount;
if (pos < 0)
pos = 0;

modSetPos(pos, DONT_SET_ROW);
}
}

void posEdPageDown(void)
{
const uint16_t scrollAmount = POSED_LIST_SIZE;

if (song->currPos < song->header.songLength-1)
{
int16_t pos = song->currPos + scrollAmount;
if (pos > song->header.songLength-1)
pos = song->header.songLength-1;

modSetPos(pos, DONT_SET_ROW);
}
}

void posEdScrollToTop(void)
{
if (song->currPos > 0)
modSetPos(0, DONT_SET_ROW);
}

void posEdScrollToBottom(void)
{
if (song->currPos < song->header.songLength-1)
modSetPos(song->header.songLength-1, DONT_SET_ROW);
}

void posEdClearNames(void)
{
memset(posEdNames, 0, sizeof (posEdNames));
Expand Down
6 changes: 6 additions & 0 deletions src/pt2_posed.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

#define POSED_LIST_SIZE 12

void posEdScrollDown(void);
void posEdScrollUp(void);
void posEdScrollToTop(void);
void posEdScrollToBottom(void);
void posEdPageUp(void);
void posEdPageDown(void);
void posEdClearNames(void);
void posEdEditName(void);
void posEdInsert(void);
Expand Down

0 comments on commit baeb792

Please sign in to comment.