presenter: scroll slides with mouse wheel #916

This commit is contained in:
Alex Andres 2024-06-21 14:50:55 +02:00
parent 1bf66358b0
commit 5674eaab92
No known key found for this signature in database
GPG key ID: 340764C7851D7041
4 changed files with 76 additions and 3 deletions

View file

@ -0,0 +1,44 @@
/*
* Copyright (C) 2020 TU Darmstadt, Department of Computer Science,
* Embedded Systems and Applications Group.
*
* 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/>.
*/
package org.lecturestudio.presenter.api.input;
public interface MouseWheelHandler {
/**
* An event dispatched when the mouse wheel was rotated in a component.
*
* @param x The horizontal x coordinate for the mouse location.
* @param y The vertical y coordinate for the mouse location.
* @param wheelRotation The integer number of "clicks" by which the mouse wheel was rotated.
*/
record MouseWheelEvent(int x, int y, int wheelRotation) {
}
/**
* Invoked when the mouse wheel is rotated.
*
* @param e the event to be processed.
*
* @see MouseWheelEvent
*/
void mouseWheelMoved(MouseWheelEvent e);
}

View file

@ -111,6 +111,7 @@ import org.lecturestudio.presenter.api.event.ScreenShareEndEvent;
import org.lecturestudio.presenter.api.event.ScreenShareStateEvent;
import org.lecturestudio.presenter.api.event.StreamReconnectStateEvent;
import org.lecturestudio.presenter.api.event.StreamingStateEvent;
import org.lecturestudio.presenter.api.input.MouseWheelHandler;
import org.lecturestudio.presenter.api.input.Shortcut;
import org.lecturestudio.presenter.api.model.*;
import org.lecturestudio.presenter.api.service.*;
@ -1265,7 +1266,7 @@ public class SlidesPresenter extends Presenter<SlidesView> {
@Override
public void initialize() {
stylusHandler = new StylusHandler(toolController, () -> {
// Cancel page selection task.
// Cancel a page selection task.
if (nonNull(idleTimer)) {
idleTimer.stop();
idleTimer = null;
@ -1349,6 +1350,8 @@ public class SlidesPresenter extends Presenter<SlidesView> {
// setUseMouse(newValue);
// });
view.setMouseWheelHandler(this::mouseWheelMoved);
setUseMouse(config.getUseMouseInput());
view.setOnExternalMessagesPositionChanged(this::externalMessagesPositionChanged);
@ -1481,6 +1484,15 @@ public class SlidesPresenter extends Presenter<SlidesView> {
}
}
private void mouseWheelMoved(MouseWheelHandler.MouseWheelEvent e) {
if (e.wheelRotation() < 0) {
previousPage();
}
else {
nextPage();
}
}
private void initExternalScreenBehavior(ExternalWindowConfiguration config, BiConsumer<Boolean, Boolean> action) {
final ObservableList<Screen> screens = presentationController.getScreens();

View file

@ -34,6 +34,7 @@ import org.lecturestudio.core.model.DocumentOutline;
import org.lecturestudio.core.model.DocumentOutlineItem;
import org.lecturestudio.core.model.Page;
import org.lecturestudio.core.view.*;
import org.lecturestudio.presenter.api.input.MouseWheelHandler;
import org.lecturestudio.presenter.api.model.*;
import org.lecturestudio.presenter.api.config.SlideViewConfiguration;
import org.lecturestudio.swing.model.ExternalWindowPosition;
@ -82,6 +83,8 @@ public interface SlidesView extends View {
void setExtendedFullscreen(boolean extended);
void setMouseWheelHandler(MouseWheelHandler handler);
void createStylusInput(StylusHandler handler);
void createMouseInput(ToolController toolController);

View file

@ -65,6 +65,7 @@ import org.lecturestudio.core.stylus.StylusHandler;
import org.lecturestudio.core.view.*;
import org.lecturestudio.core.view.Action;
import org.lecturestudio.presenter.api.config.SlideViewConfiguration;
import org.lecturestudio.presenter.api.input.MouseWheelHandler;
import org.lecturestudio.presenter.api.model.*;
import org.lecturestudio.presenter.api.service.UserPrivilegeService;
import org.lecturestudio.presenter.api.view.SlidesView;
@ -226,6 +227,8 @@ public class SwingSlidesView extends JPanel implements SlidesView {
private SlideView slideNotesView;
private MouseWheelListener mouseWheelListener;
private StylusListener stylusListener;
private BufferedImage peerViewImage;
@ -610,6 +613,19 @@ public class SwingSlidesView extends JPanel implements SlidesView {
bottomTabPane.setVisible(show);
}
@Override
public void setMouseWheelHandler(MouseWheelHandler handler) {
if (nonNull(mouseWheelListener)) {
removeMouseWheelListener(mouseWheelListener);
}
mouseWheelListener = e -> {
handler.mouseWheelMoved(new MouseWheelHandler.MouseWheelEvent(e.getX(), e.getY(), e.getWheelRotation()));
};
addMouseWheelListener(mouseWheelListener);
}
@Override
public void createStylusInput(StylusHandler handler) {
if (nonNull(mouseListener)) {
@ -2129,8 +2145,6 @@ public class SwingSlidesView extends JPanel implements SlidesView {
return false;
});
addMouseWheelListener(e -> scrollPreview(e.getWheelRotation()));
ToolTipManager.sharedInstance().registerComponent(outlineTree);
// Use one-way tree selection.