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