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 "one_of.hh"
11 #include <cassert>
12 
13 namespace 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 
58 void VisibleSurface::update(const Setting& /*setting*/)
59 {
60  updateCursor();
61 }
62 
63 void VisibleSurface::executeRT()
64 {
65  // timer expired, hide cursor
66  videoSystem.showCursor(false);
67  inputEventGenerator.updateGrab(grab);
68 }
69 
70 int VisibleSurface::signalEvent(const std::shared_ptr<const Event>& event)
71 {
72  assert(event->getType() == one_of(OPENMSX_MOUSE_MOTION_EVENT,
75  (void)event;
76  updateCursor();
77  return 0;
78 }
79 
80 void 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 grabinput 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
one_of.hh
VideoSystem.hh
VisibleSurface.hh
openmsx::OPENMSX_MOUSE_MOTION_EVENT
@ OPENMSX_MOUSE_MOTION_EVENT
Definition: Event.hh:15
openmsx::RTSchedulable
Definition: RTSchedulable.hh:11
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:15
openmsx::InputEventGenerator
Definition: InputEventGenerator.hh:18
openmsx::InputEventGenerator::getGrabInput
BooleanSetting & getGrabInput()
Input Grab on or off.
Definition: InputEventGenerator.hh:34
openmsx::RTScheduler
Definition: RTScheduler.hh:20
openmsx::VideoSystem
Video back-end system.
Definition: VideoSystem.hh:21
openmsx::Subject::attach
void attach(Observer< T > &observer)
Definition: Subject.hh:50
openmsx::Setting
Definition: Setting.hh:120
openmsx::EventDistributor
Definition: EventDistributor.hh:17
BooleanSetting.hh
openmsx::RenderSettings::getPointerHideDelaySetting
FloatSetting & getPointerHideDelaySetting()
The amount of time until the pointer is hidden in the openMSX window.
Definition: RenderSettings.hh:163
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
@ OPENMSX_MOUSE_BUTTON_UP_EVENT
Definition: Event.hh:17
one_of
Definition: one_of.hh:7
EventDistributor.hh
RenderSettings.hh
openmsx::Display
Represents the output window/screen of openMSX.
Definition: Display.hh:33
openmsx::Display::getRenderSettings
RenderSettings & getRenderSettings()
Definition: Display.hh:44
openmsx::OPENMSX_MOUSE_BUTTON_DOWN_EVENT
@ OPENMSX_MOUSE_BUTTON_DOWN_EVENT
Definition: Event.hh:18
openmsx::CliComm
Definition: CliComm.hh:11
Event.hh
openmsx::InputEventGenerator::updateGrab
void updateGrab(bool grab)
Must be called when 'grabinput' or 'fullscreen' setting changes.
Definition: InputEventGenerator.cc:422
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
This file implemented 3 utility functions:
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:44