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