openMSX
VisibleSurface.cc
Go to the documentation of this file.
1#include "VisibleSurface.hh"
2#include "Display.hh"
3#include "RenderSettings.hh"
4#include "VideoSystem.hh"
5#include "FloatSetting.hh"
6#include "BooleanSetting.hh"
7#include "Event.hh"
8#include "EventDistributor.hh"
10#include "one_of.hh"
11#include <cassert>
12
13namespace openmsx {
14
16 Display& display_,
17 RTScheduler& rtScheduler,
18 EventDistributor& eventDistributor_,
19 InputEventGenerator& inputEventGenerator_,
20 CliComm& cliComm_,
21 VideoSystem& videoSystem_)
22 : RTSchedulable(rtScheduler)
23 , display(display_)
24 , eventDistributor(eventDistributor_)
25 , inputEventGenerator(inputEventGenerator_)
26 , cliComm(cliComm_)
27 , videoSystem(videoSystem_)
28{
29 auto& renderSettings = display.getRenderSettings();
30
31 inputEventGenerator.getGrabInput().attach(*this);
32 renderSettings.getPointerHideDelaySetting().attach(*this);
33 renderSettings.getFullScreenSetting().attach(*this);
34 eventDistributor.registerEventListener(
36 eventDistributor.registerEventListener(
38 eventDistributor.registerEventListener(
40
41 updateCursor();
42}
43
45{
46 eventDistributor.unregisterEventListener(
48 eventDistributor.unregisterEventListener(
50 eventDistributor.unregisterEventListener(
52 inputEventGenerator.getGrabInput().detach(*this);
53 auto& renderSettings = display.getRenderSettings();
54 renderSettings.getPointerHideDelaySetting().detach(*this);
55 renderSettings.getFullScreenSetting().detach(*this);
56}
57
58void VisibleSurface::update(const Setting& /*setting*/) noexcept
59{
60 updateCursor();
61}
62
63void VisibleSurface::executeRT()
64{
65 // timer expired, hide cursor
66 videoSystem.showCursor(false);
67 inputEventGenerator.updateGrab(grab);
68}
69
70int VisibleSurface::signalEvent(const Event& event)
71{
72 assert(getType(event) == one_of(EventType::MOUSE_MOTION,
75 (void)event;
76 updateCursor();
77 return 0;
78}
79
80void VisibleSurface::updateCursor()
81{
82 cancelRT();
83 auto& renderSettings = display.getRenderSettings();
84 grab = renderSettings.getFullScreen() ||
85 inputEventGenerator.getGrabInput().getBoolean();
86 if (grab) {
87 // always hide cursor in fullscreen or grab-input mode, but do it
88 // after the derived class is constructed to avoid an SDL bug.
89 scheduleRT(0);
90 return;
91 }
92 inputEventGenerator.updateGrab(grab);
93 float delay = renderSettings.getPointerHideDelay();
94 if (delay == 0.0f) {
95 videoSystem.showCursor(false);
96 } else {
97 videoSystem.showCursor(true);
98 if (delay > 0.0f) {
99 scheduleRT(int(delay * 1e6f)); // delay in s, schedule in us
100 }
101 }
102}
103
104} // namespace openmsx
Definition: one_of.hh:7
bool getBoolean() const noexcept
Represents the output window/screen of openMSX.
Definition: Display.hh:33
RenderSettings & getRenderSettings()
Definition: Display.hh:44
void unregisterEventListener(EventType type, EventListener &listener)
Unregisters a previously registered event listener.
void registerEventListener(EventType type, EventListener &listener, Priority priority=OTHER)
Registers a given object to receive certain events.
BooleanSetting & getGrabInput()
Input Grab on or off.
void updateGrab(bool grab)
Must be called when 'grabinput' or 'fullscreen' setting changes.
void scheduleRT(uint64_t delta)
FloatSetting & getPointerHideDelaySetting()
The amount of time until the pointer is hidden in the openMSX window.
void detach(Observer< T > &observer)
Definition: Subject.hh:56
void attach(Observer< T > &observer)
Definition: Subject.hh:50
Video back-end system.
Definition: VideoSystem.hh:23
virtual void showCursor(bool show)=0
VisibleSurface(Display &display, RTScheduler &rtScheduler, EventDistributor &eventDistributor, InputEventGenerator &inputEventGenerator, CliComm &cliComm, VideoSystem &videoSystem)
This file implemented 3 utility functions:
Definition: Autofire.cc:9
EventType getType(const Event &event)
Definition: Event.hh:644