openMSX
VideoLayer.cc
Go to the documentation of this file.
1 #include "VideoLayer.hh"
2 #include "Display.hh"
3 #include "Reactor.hh"
4 #include "GlobalSettings.hh"
5 #include "BooleanSetting.hh"
6 #include "MSXEventDistributor.hh"
7 #include "MSXMotherBoard.hh"
8 #include "Event.hh"
9 #include "one_of.hh"
10 
11 namespace openmsx {
12 
14  const std::string& videoSource_)
15  : motherBoard(motherBoard_)
16  , display(motherBoard.getReactor().getDisplay())
17  , videoSourceSetting(motherBoard.getVideoSource())
18  , videoSourceActivator(videoSourceSetting, videoSource_)
19  , powerSetting(motherBoard.getReactor().getGlobalSettings().getPowerSetting())
20  , video9000Source(0)
21  , activeVideo9000(INACTIVE)
22 {
23  calcCoverage();
24  calcZ();
25  display.addLayer(*this);
26 
27  videoSourceSetting.attach(*this);
28  powerSetting.attach(*this);
29  motherBoard.getMSXEventDistributor().registerEventListener(*this);
30 }
31 
33 {
35  powerSetting.detach(*this);
36  videoSourceSetting.detach(*this);
37 
38  display.removeLayer(*this);
39 }
40 
42 {
43  return videoSourceActivator.getID();
44 }
46 {
47  return videoSourceSetting.getSource();
48 }
49 
50 void VideoLayer::update(const Setting& setting)
51 {
52  if (&setting == &videoSourceSetting) {
53  calcZ();
54  } else if (&setting == &powerSetting) {
55  calcCoverage();
56  }
57 }
58 
59 void VideoLayer::calcZ()
60 {
61  setZ((videoSourceSetting.getSource() == getVideoSource())
62  ? Z_MSX_ACTIVE
63  : Z_MSX_PASSIVE);
64 }
65 
66 void VideoLayer::calcCoverage()
67 {
68  Coverage cov;
69  if (!powerSetting.getBoolean() || !motherBoard.isActive()) {
70  cov = COVER_NONE;
71  } else {
72  cov = COVER_FULL;
73  }
74  setCoverage(cov);
75 }
76 
77 void VideoLayer::signalMSXEvent(const std::shared_ptr<const Event>& event,
78  EmuTime::param /*time*/)
79 {
80  if (event->getType() == one_of(OPENMSX_MACHINE_ACTIVATED,
82  calcCoverage();
83  }
84 }
85 
87 {
88  // Either when this layer itself is selected or when the video9000
89  // layer is selected and this layer is needed to render a
90  // (superimposed) image.
91  int current = videoSourceSetting.getSource();
92  return (current == getVideoSource()) ||
93  ((current == video9000Source) && (activeVideo9000 != INACTIVE));
94 }
95 
97 {
98  // Either when this layer itself is selected or when the video9000
99  // layer is selected and this layer is the front layer of a
100  // (superimposed) image
101  int current = videoSourceSetting.getSource();
102  return (current == getVideoSource()) ||
103  ((current == video9000Source) && (activeVideo9000 == ACTIVE_FRONT));
104 }
105 
106 } // namespace openmsx
one_of.hh
openmsx::VideoLayer::ACTIVE_FRONT
@ ACTIVE_FRONT
Definition: VideoLayer.hh:41
openmsx::Subject::detach
void detach(Observer< T > &observer)
Definition: Subject.hh:56
Display.hh
MSXEventDistributor.hh
openmsx::VideoLayer::getVideoSourceSetting
int getVideoSourceSetting() const
Definition: VideoLayer.cc:45
openmsx::Layer::Z_MSX_PASSIVE
@ Z_MSX_PASSIVE
Definition: Layer.hh:20
openmsx::Subject::attach
void attach(Observer< T > &observer)
Definition: Subject.hh:50
openmsx::OPENMSX_MACHINE_DEACTIVATED
@ OPENMSX_MACHINE_DEACTIVATED
Definition: Event.hh:65
openmsx::Setting
Definition: Setting.hh:120
BooleanSetting.hh
openmsx::MSXMotherBoard::getMSXEventDistributor
MSXEventDistributor & getMSXEventDistributor()
Definition: MSXMotherBoard.hh:119
openmsx::VideoLayer::needRender
bool needRender() const
Definition: VideoLayer.cc:86
openmsx::VideoLayer::getVideoSource
int getVideoSource() const
Returns the ID for this videolayer.
Definition: VideoLayer.cc:41
Reactor.hh
openmsx::MSXMotherBoard
Definition: MSXMotherBoard.hh:60
one_of
Definition: one_of.hh:7
openmsx::OPENMSX_MACHINE_ACTIVATED
@ OPENMSX_MACHINE_ACTIVATED
Send when a machine is (de)activated.
Definition: Event.hh:64
openmsx::Layer::setZ
void setZ(ZIndex z)
Changes the current Z-index of this layer.
Definition: Layer.cc:6
openmsx::VideoLayer::VideoLayer
VideoLayer(const VideoLayer &)=delete
openmsx::VideoSourceSetting::getSource
int getSource() noexcept
Definition: VideoSourceSetting.cc:35
GlobalSettings.hh
openmsx::VideoLayer::INACTIVE
@ INACTIVE
Definition: VideoLayer.hh:41
openmsx::MSXEventDistributor::unregisterEventListener
void unregisterEventListener(MSXEventListener &listener)
Unregisters a previously registered event listener.
Definition: MSXEventDistributor.cc:24
VideoLayer.hh
openmsx::MSXMotherBoard::isActive
bool isActive() const
Definition: MSXMotherBoard.hh:95
openmsx::Layer::setCoverage
void setCoverage(Coverage coverage_)
Changes the current coverage of this layer.
Definition: Layer.hh:70
Event.hh
openmsx::VideoLayer::~VideoLayer
~VideoLayer() override
Definition: VideoLayer.cc:32
openmsx::Layer::COVER_FULL
@ COVER_FULL
Layer fully covers the screen: any underlying layers are invisible.
Definition: Layer.hh:32
openmsx::Layer::Z_MSX_ACTIVE
@ Z_MSX_ACTIVE
Definition: Layer.hh:21
openmsx::VideoLayer::needRecord
bool needRecord() const
Definition: VideoLayer.cc:96
openmsx::VideoSourceActivator::getID
int getID() const
Definition: VideoSourceSetting.hh:39
openmsx::Display::addLayer
void addLayer(Layer &layer)
Definition: Display.cc:376
openmsx::Layer::COVER_NONE
@ COVER_NONE
Layer is not visible, that is completely transparent.
Definition: Layer.hh:39
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
MSXMotherBoard.hh
openmsx::BooleanSetting::getBoolean
bool getBoolean() const noexcept
Definition: BooleanSetting.hh:17
openmsx::MSXEventDistributor::registerEventListener
void registerEventListener(MSXEventListener &listener)
Registers a given object to receive certain events.
Definition: MSXEventDistributor.cc:18
openmsx::Display::removeLayer
void removeLayer(Layer &layer)
Definition: Display.cc:384
openmsx::VideoLayer::update
void update(const Setting &setting) override
Definition: VideoLayer.cc:50
openmsx::Layer::Coverage
Coverage
Describes how much of the screen is currently covered by a particular layer.
Definition: Layer.hh:29