2 * Copyright (c) 2007-2013, Czirkos Zoltan http://code.google.com/p/gdash/
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
19 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #include "cave/object/caveobjectraster.hpp"
27 #include "cave/elementproperties.hpp"
29 #include <glib/gi18n.h>
31 #include "fileops/bdcffhelper.hpp"
32 #include "cave/caverendered.hpp"
33 #include "misc/printf.hpp"
35 std::string
CaveRaster::get_bdcff() const {
37 number
.x
= ((p2
.x
- p1
.x
) / dist
.x
+ 1);
38 number
.y
= ((p2
.y
- p1
.y
) / dist
.y
+ 1);
40 return BdcffFormat("Raster") << p1
<< number
<< dist
<< element
;
43 CaveRaster
*CaveRaster::clone_from_bdcff(const std::string
&name
, std::istream
&is
) const {
44 Coordinate p1
, n
, d
, p2
;
45 GdElementEnum element
;
47 if (!(is
>> p1
>> n
>> d
>> element
))
49 p2
.x
= p1
.x
+ (n
.x
- 1) * d
.x
;
50 p2
.y
= p1
.y
+ (n
.y
- 1) * d
.y
;
52 return new CaveRaster(p1
, p2
, d
, element
);
55 CaveRaster
*CaveRaster::clone() const {
56 return new CaveRaster(*this);
59 CaveRaster::CaveRaster(Coordinate _p1
, Coordinate _p2
, Coordinate _dist
, GdElementEnum _element
)
60 : CaveRectangular(GD_RASTER
, _p1
, _p2
),
65 void CaveRaster::draw(CaveRendered
&cave
) const {
66 /* reorder coordinates if not drawing from northwest to southeast */
67 int x1
= p1
.x
, y1
= p1
.y
;
68 int x2
= p2
.x
, y2
= p2
.y
;
69 int dx
= dist
.x
, dy
= dist
.y
;
75 if (dy
< 1) dy
= 1; /* make sure we do not have an infinite loop */
78 for (int y
= y1
; y
<= y2
; y
+= dy
)
79 for (int x
= x1
; x
<= x2
; x
+= dx
)
80 cave
.store_rc(x
, y
, element
, this);
83 PropertyDescription
const CaveRaster::descriptor
[] = {
84 {"", GD_TAB
, 0, N_("Raster")},
85 {"", GD_TYPE_BOOLEAN_LEVELS
, 0, N_("Levels"), GetterBase::create_new(&CaveRaster::seen_on
), N_("Levels on which this object is visible.")},
86 {"", GD_TYPE_COORDINATE
, 0, N_("Start corner"), GetterBase::create_new(&CaveRaster::p1
), N_("Specifies one of the corners of the object."), 0, 127},
87 {"", GD_TYPE_COORDINATE
, 0, N_("End corner"), GetterBase::create_new(&CaveRaster::p2
), N_("Specifies one of the corners of the object."), 0, 127},
88 {"", GD_TYPE_COORDINATE
, 0, N_("Distance"), GetterBase::create_new(&CaveRaster::dist
), N_("The horizontal and vertical distance between elements."), 1, 40},
89 {"", GD_TYPE_ELEMENT
, 0, N_("Element"), GetterBase::create_new(&CaveRaster::element
), N_("The element to draw.")},
93 PropertyDescription
const *CaveRaster::get_description_array() const {
97 std::string
CaveRaster::get_coordinates_text() const {
98 return SPrintf("%d,%d-%d,%d (%d,%d)") % p1
.x
% p1
.y
% p2
.x
% p2
.y
% dist
.x
% dist
.y
;
101 std::string
CaveRaster::get_description_markup() const {
102 return SPrintf(_("Raster from %d,%d to %d,%d of <b>%ms</b>, distance %+d,%+d"))
103 % p1
.x
% p1
.y
% p2
.x
% p2
.y
% visible_name_lowercase(element
) % dist
.x
% dist
.y
;
106 GdElementEnum
CaveRaster::get_characteristic_element() const {