2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <boost/algorithm/string.hpp>
23 #include "exceptions.h"
26 using namespace boost;
28 Screen::Screen (string n)
31 vector<Format const *> f = Format::all ();
32 for (vector<Format const *>::iterator i = f.begin(); i != f.end(); ++i) {
33 set_geometry (*i, Position (0, 0), Size (2048, 1080));
38 Screen::set_geometry (Format const * f, Position p, Size s)
40 _geometries[f] = Geometry (p, s);
44 Screen::position (Format const * f) const
46 GeometryMap::const_iterator i = _geometries.find (f);
47 if (i == _geometries.end ()) {
48 throw PlayError ("format not found for screen");
51 return i->second.position;
55 Screen::size (Format const * f) const
57 GeometryMap::const_iterator i = _geometries.find (f);
58 if (i == _geometries.end ()) {
59 throw PlayError ("format not found for screen");
62 return i->second.size;
66 Screen::as_metadata () const
69 s << "\"" << _name << "\"";
71 for (GeometryMap::const_iterator i = _geometries.begin(); i != _geometries.end(); ++i) {
72 s << " " << i->first->as_metadata()
73 << " " << i->second.position.x << " " << i->second.position.y
74 << " " << i->second.size.width << " " << i->second.size.height;
81 Screen::create_from_metadata (string v)
83 vector<string> b = split_at_spaces_considering_quotes (v);
86 return shared_ptr<Screen> ();
89 shared_ptr<Screen> s (new Screen (b[0]));
91 vector<string>::size_type i = 1;
92 while (b.size() > i) {
93 if (b.size() >= (i + 5)) {
95 Format::from_metadata (b[i].c_str()),
96 Position (atoi (b[i+1].c_str()), atoi (b[i+2].c_str())),
97 Size (atoi (b[i+3].c_str()), atoi (b[i+4].c_str()))