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