20130313
[gdash.git] / src / cave / object / caveobjectrectangle.cpp
blob617f73764fc55627f02ee3e2402f7fd3191d9435
1 /*
2 * Copyright (c) 2007-2013, Czirkos Zoltan http://code.google.com/p/gdash/
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include "config.h"
19 #include "cave/object/caveobjectrectangle.hpp"
20 #include "cave/elementproperties.hpp"
22 #include <glib/gi18n.h>
24 #include "fileops/bdcffhelper.hpp"
25 #include "cave/caverendered.hpp"
26 #include "misc/printf.hpp"
28 std::string CaveRectangle::get_bdcff() const
30 return BdcffFormat("Rectangle") << p1 << p2 << element;
33 CaveRectangle* CaveRectangle::clone_from_bdcff(const std::string &name, std::istream &is) const
35 Coordinate p1, p2;
36 GdElementEnum element;
37 if (!(is >> p1 >> p2 >> element))
38 return NULL;
39 return new CaveRectangle(p1, p2, element);
43 CaveRectangle::CaveRectangle(Coordinate _p1, Coordinate _p2, GdElementEnum _element)
44 : CaveRectangular(GD_RECTANGLE, _p1, _p2),
45 element(_element)
49 /* rectangle, frame only */
50 void CaveRectangle::draw(CaveRendered &cave) const
52 /* reorder coordinates if not drawing from northwest to southeast */
53 int x1=p1.x;
54 int y1=p1.y;
55 int x2=p2.x;
56 int y2=p2.y;
57 if (y1>y2)
58 std::swap(y1, y2);
59 if (x1>x2)
60 std::swap(x1, x2);
62 for (int x=x1; x<=x2; x++) {
63 cave.store_rc(x, y1, element, this);
64 cave.store_rc(x, y2, element, this);
66 for (int y=y1; y<=y2; y++) {
67 cave.store_rc(x1, y, element, this);
68 cave.store_rc(x2, y, element, this);
72 PropertyDescription const CaveRectangle::descriptor[] = {
73 {"", GD_TAB, 0, N_("Rectangle")},
74 {"", GD_TYPE_BOOLEAN_LEVELS, 0, N_("Levels"), GetterBase::create_new(&CaveRectangle::seen_on), N_("Levels on which this object is visible.")},
75 {"", GD_TYPE_COORDINATE, 0, N_("Start corner"), GetterBase::create_new(&CaveRectangle::p1), N_("Specifies one of the corners of the object."), 0, 127},
76 {"", GD_TYPE_COORDINATE, 0, N_("End corner"), GetterBase::create_new(&CaveRectangle::p2), N_("Specifies one of the corners of the object."), 0, 127},
77 {"", GD_TYPE_ELEMENT, 0, N_("Element"), GetterBase::create_new(&CaveRectangle::element), N_("The element to draw.")},
78 {NULL},
81 PropertyDescription const* CaveRectangle::get_description_array() const
83 return descriptor;
86 std::string CaveRectangle::get_description_markup() const
88 return SPrintf(_("Rectangle from %d,%d to %d,%d of <b>%s</b>"))
89 % p1.x % p1.y % p2.x % p2.y % gd_element_properties[element].lowercase_name;