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 {
36  PRT_DEBUG("Destructing VideoLayer...");
38  powerSetting.detach(*this);
39  videoSourceSetting.detach(*this);
40 
41  display.removeLayer(*this);
42  PRT_DEBUG("Destructing VideoLayer... DONE!");
43 }
44 
46 {
47  return videoSourceActivator->getID();
48 }
50 {
51  return videoSourceSetting.getSource();
52 }
53 
54 void VideoLayer::update(const Setting& setting)
55 {
56  if (&setting == &videoSourceSetting) {
57  calcZ();
58  } else if (&setting == &powerSetting) {
59  calcCoverage();
60  }
61 }
62 
63 void VideoLayer::calcZ()
64 {
65  setZ((videoSourceSetting.getSource() == getVideoSource())
66  ? Z_MSX_ACTIVE
67  : Z_MSX_PASSIVE);
68 }
69 
70 void VideoLayer::calcCoverage()
71 {
72  Coverage coverage;
73 
74  if (!powerSetting.getBoolean() || !motherBoard.isActive()) {
75  coverage = COVER_NONE;
76  } else {
77  coverage = COVER_FULL;
78  }
79 
80  setCoverage(coverage);
81 }
82 
83 void VideoLayer::signalEvent(const std::shared_ptr<const Event>& event,
84  EmuTime::param /*time*/)
85 {
86  if ((event->getType() == OPENMSX_MACHINE_ACTIVATED) ||
87  (event->getType() == OPENMSX_MACHINE_DEACTIVATED)) {
88  calcCoverage();
89  }
90 }
91 
93 {
94  // Either when this layer itself is selected or when the video9000
95  // layer is selected and this layer is needed to render a
96  // (superimposed) image.
97  int current = videoSourceSetting.getSource();
98  return (current == getVideoSource()) ||
99  ((current == video9000Source) && (activeVideo9000 != INACTIVE));
100 }
101 
103 {
104  // Either when this layer itself is selected or when the video9000
105  // layer is selected and this layer is the front layer of a
106  // (superimposed) image
107  int current = videoSourceSetting.getSource();
108  return (current == getVideoSource()) ||
109  ((current == video9000Source) && (activeVideo9000 == ACTIVE_FRONT));
110 }
111 
112 } // namespace openmsx
Layer is not visible, that is completely transparent.
Definition: Layer.hh:39
void addLayer(Layer &layer)
Definition: Display.cc:415
virtual ~VideoLayer()
Definition: VideoLayer.cc:34
bool needRender() const
Definition: VideoLayer.cc:92
Send when a machine is (de)activated.
Definition: Event.hh:71
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:45
virtual void update(const Setting &setting)
Definition: VideoLayer.cc:54
void setZ(ZIndex z)
Changes the current Z-index of this layer.
Definition: Layer.cc:20
void attach(Observer< T > &observer)
Definition: Subject.hh:51
void removeLayer(Layer &layer)
Definition: Display.cc:427
void unregisterEventListener(MSXEventListener &listener)
Unregisters a previously registered event listener.
MSXEventDistributor & getMSXEventDistributor()
int getVideoSourceSetting() const
Definition: VideoLayer.cc:49
const EmuTime & param
Definition: EmuTime.hh:20
void setCoverage(Coverage coverage)
Changes the current coverage of this layer.
Definition: Layer.cc:15
VideoLayer(MSXMotherBoard &motherBoard, const std::string &videoSource)
Definition: VideoLayer.cc:14
void detach(Observer< T > &observer)
Definition: Subject.hh:57
bool needRecord() const
Definition: VideoLayer.cc:102
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
#define PRT_DEBUG(mes)
Definition: openmsx.hh:69