GUI: Add mousewheel scrolling to credits.

This commit is contained in:
elasota 2023-01-02 19:46:40 -05:00 committed by Filippos Karapetis
parent 76b02ac0d6
commit 648d7e9718
2 changed files with 22 additions and 2 deletions

View file

@ -86,7 +86,7 @@ static const char *gpl_text[] = {
AboutDialog::AboutDialog()
: Dialog(10, 20, 300, 174),
_scrollPos(0), _scrollTime(0), _willClose(false) {
_scrollPos(0), _scrollTime(0), _willClose(false), _autoScroll(true) {
reflowLayout();
@ -257,7 +257,7 @@ void AboutDialog::drawDialog(DrawLayer layerToDraw) {
void AboutDialog::handleTickle() {
const uint32 t = g_system->getMillis();
int scrollOffset = ((int)t - (int)_scrollTime) / kScrollMillisPerPixel;
if (scrollOffset > 0) {
if (_autoScroll && scrollOffset > 0) {
int modifiers = g_system->getEventManager()->getModifierState();
// Scroll faster when shift is pressed
@ -284,6 +284,24 @@ void AboutDialog::handleMouseUp(int x, int y, int button, int clickCount) {
close();
}
void AboutDialog::handleMouseWheel(int x, int y, int direction) {
const int stepping = 5 * _lineHeight * direction;
if (stepping == 0)
return;
_autoScroll = false;
int newScrollPos = _scrollPos + stepping;
if (_scrollPos < 0) {
_scrollPos = 0;
} else if ((uint32)newScrollPos < _lines.size() * _lineHeight) {
_scrollPos = newScrollPos;
}
drawDialog(kDrawLayerForeground);
}
void AboutDialog::handleKeyDown(Common::KeyState state) {
EEHandler eeHandler;

View file

@ -39,6 +39,7 @@ protected:
Common::U32StringArray _lines;
uint32 _lineHeight;
bool _willClose;
bool _autoScroll;
int _xOff, _yOff;
@ -54,6 +55,7 @@ public:
void drawDialog(DrawLayer layerToDraw) override;
void handleTickle() override;
void handleMouseUp(int x, int y, int button, int clickCount) override;
void handleMouseWheel(int x, int y, int direction) override;
void handleKeyDown(Common::KeyState state) override;
void handleKeyUp(Common::KeyState state) override;