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 #include <boost/archive/text_iarchive.hpp>
28 #include <boost/archive/text_oarchive.hpp>
29 #include <boost/serialization/export.hpp>
30
31 #include "systems/base/colour_filter_object_data.h"
32
33 #include <ostream>
34 #include <iostream>
35
36 #include "systems/base/colour.h"
37 #include "systems/base/colour_filter.h"
38 #include "systems/base/graphics_object.h"
39 #include "systems/base/graphics_system.h"
40 #include "systems/base/system.h"
41 #include "utilities/exception.h"
42
ColourFilterObjectData(GraphicsSystem & system,const Rect & screen_rect)43 ColourFilterObjectData::ColourFilterObjectData(GraphicsSystem& system,
44 const Rect& screen_rect)
45 : graphics_system_(system), screen_rect_(screen_rect) {}
46
~ColourFilterObjectData()47 ColourFilterObjectData::~ColourFilterObjectData() {}
48
GetColourFilter()49 ColourFilter* ColourFilterObjectData::GetColourFilter() {
50 if (!colour_filer_)
51 colour_filer_.reset(graphics_system_.BuildColourFiller());
52 return colour_filer_.get();
53 }
54
Render(const GraphicsObject & go,const GraphicsObject * parent,std::ostream * tree)55 void ColourFilterObjectData::Render(const GraphicsObject& go,
56 const GraphicsObject* parent,
57 std::ostream* tree) {
58 if (go.width() != 100 || go.height() != 100) {
59 static bool printed = false;
60 if (!printed) {
61 printed = true;
62 std::cerr << "We can't yet scaling colour filters." << std::endl;
63 }
64 }
65
66 RGBAColour colour = go.colour();
67 GetColourFilter()->Fill(go, screen_rect_, colour);
68
69 if (tree) {
70 *tree << " ColourFilterObjectData" << std::endl
71 << " Screen rect: " << screen_rect_ << std::endl
72 << " Colour: " << colour << std::endl << " Properties: ";
73 PrintGraphicsObjectToTree(go, tree);
74 *tree << std::endl;
75 }
76 }
77
PixelWidth(const GraphicsObject & rendering_properties)78 int ColourFilterObjectData::PixelWidth(
79 const GraphicsObject& rendering_properties) {
80 throw rlvm::Exception("There is no sane value for this!");
81 }
82
PixelHeight(const GraphicsObject & rendering_properties)83 int ColourFilterObjectData::PixelHeight(
84 const GraphicsObject& rendering_properties) {
85 throw rlvm::Exception("There is no sane value for this!");
86 }
87
Clone() const88 GraphicsObjectData* ColourFilterObjectData::Clone() const {
89 return new ColourFilterObjectData(graphics_system_, screen_rect_);
90 }
91
Execute(RLMachine & machine)92 void ColourFilterObjectData::Execute(RLMachine& machine) {
93 // Nothing to do.
94 }
95
IsAnimation() const96 bool ColourFilterObjectData::IsAnimation() const { return false; }
97
PlaySet(int set)98 void ColourFilterObjectData::PlaySet(int set) {
99 // No op
100 }
101
CurrentSurface(const GraphicsObject & rp)102 std::shared_ptr<const Surface> ColourFilterObjectData::CurrentSurface(
103 const GraphicsObject& rp) {
104 return std::shared_ptr<const Surface>();
105 }
106
ObjectInfo(std::ostream & tree)107 void ColourFilterObjectData::ObjectInfo(std::ostream& tree) {
108 tree << "ColourFilterObjectData(" << screen_rect_ << ")" << std::endl;
109 }
110
ColourFilterObjectData(System & system)111 ColourFilterObjectData::ColourFilterObjectData(System& system)
112 : graphics_system_(system.graphics()) {}
113
114 template <class Archive>
serialize(Archive & ar,unsigned int version)115 void ColourFilterObjectData::serialize(Archive& ar, unsigned int version) {
116 ar& boost::serialization::base_object<GraphicsObjectData>(*this);
117 ar& screen_rect_;
118 }
119
120 // -----------------------------------------------------------------------
121
122 // Explicit instantiations for text archives (since we hide the
123 // implementation)
124
125 template void ColourFilterObjectData::serialize<boost::archive::text_iarchive>(
126 boost::archive::text_iarchive& ar,
127 unsigned int version);
128 template void ColourFilterObjectData::serialize<boost::archive::text_oarchive>(
129 boost::archive::text_oarchive& ar,
130 unsigned int version);
131
132 BOOST_CLASS_EXPORT(ColourFilterObjectData);
133