1 // -*- Mode: C++; tab-width:2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi:tw=80:et:ts=2:sts=2
3 //
4 // -----------------------------------------------------------------------
5 //
6 // This file is part of RLVM, a RealLive virtual machine clone.
7 //
8 // -----------------------------------------------------------------------
9 //
10 // Copyright (C) 2011 Elliot Glaysher
11 //
12 // This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 3 of the License, or
15 // (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
25 // -----------------------------------------------------------------------
26
27 #ifndef SRC_SYSTEMS_BASE_COLOUR_FILTER_OBJECT_DATA_H_
28 #define SRC_SYSTEMS_BASE_COLOUR_FILTER_OBJECT_DATA_H_
29
30 #include <boost/serialization/access.hpp>
31
32 #include <memory>
33
34 #include "machine/rlmachine.h"
35 #include "machine/serialization.h"
36 #include "systems/base/graphics_object_data.h"
37 #include "systems/base/rect.h"
38
39 class ColourFilter;
40 class GraphicsObject;
41 class GraphicsSystem;
42
43 class ColourFilterObjectData : public GraphicsObjectData {
44 public:
45 ColourFilterObjectData(GraphicsSystem& system, const Rect& screen_rect);
46 virtual ~ColourFilterObjectData();
47
48 // load_construct_data helper. Wish I could make this private.
49 explicit ColourFilterObjectData(System& system);
50
set_rect(const Rect & screen_rect)51 void set_rect(const Rect& screen_rect) { screen_rect_ = screen_rect; }
52
53 // Returns the colour filter, lazily creating it if necessary.
54 ColourFilter* GetColourFilter();
55
56 // Overridden from GraphicsObjectData:
57 virtual void Render(const GraphicsObject& go,
58 const GraphicsObject* parent,
59 std::ostream* tree) override;
60 virtual int PixelWidth(const GraphicsObject& rendering_properties) override;
61 virtual int PixelHeight(const GraphicsObject& rendering_properties) override;
62 virtual GraphicsObjectData* Clone() const override;
63 virtual void Execute(RLMachine& machine) override;
64 virtual bool IsAnimation() const override;
65 virtual void PlaySet(int set) override;
66
67 protected:
68 virtual std::shared_ptr<const Surface> CurrentSurface(
69 const GraphicsObject& rp) override;
70 virtual void ObjectInfo(std::ostream& tree) override;
71
72 private:
73 GraphicsSystem& graphics_system_;
74
75 Rect screen_rect_;
76
77 std::unique_ptr<ColourFilter> colour_filer_;
78
79 friend class boost::serialization::access;
80 template <class Archive>
81 void serialize(Archive& ar, const unsigned int file_version);
82 };
83
84 // We need help creating ColourFilterObjectData s since they don't have a
85 // default constructor:
86 namespace boost {
87 namespace serialization {
88 template <class Archive>
load_construct_data(Archive & ar,ColourFilterObjectData * t,const unsigned int file_version)89 inline void load_construct_data(Archive& ar,
90 ColourFilterObjectData* t,
91 const unsigned int file_version) {
92 ::new (t) ColourFilterObjectData(Serialization::g_current_machine->system());
93 }
94 } // namespace serialization
95 } // namespace boost
96
97 #endif // SRC_SYSTEMS_BASE_COLOUR_FILTER_OBJECT_DATA_H_
98