1
/****************************************************************************
2
Xplanet 0.94 - render an image of a planet into an X window
3
Copyright (C) 2002 Hari Nair <hari@alumni.caltech.edu>
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
****************************************************************************/
30
static int num_markers = 0;
32
Marker::Marker(const int X, const int Y,
33
const string Text, const int Align)
48
fontsize = opts.fontsize;
68
Marker::operator < (const Marker &m)
74
Marker::operator > (const Marker &m)
80
Marker::operator == (const Marker &m)
86
Marker::operator != (const Marker &m)
92
Marker::setImage(const int width, const int height)
95
image_height = height;
96
image.left = x - width/2;
97
image.right = x + width/2;
98
image.top = y - height/2;
99
image.bottom = y + height/2;
103
Marker::setImage(string filename)
105
if (readImageFile(filename, image_width, image_height, image_data))
107
image.left = x - image_width/2;
108
image.right = x + image_width/2;
109
image.top = y - image_height/2;
110
image.bottom = y + image_height/2;
114
cerr << "Can't read image " << filename << endl;
120
Marker::setCorners(const int x1, const int y1,
121
const int x2, const int y2)
123
label.left = min(x1, x2);
124
label.right = max(x1, x2);
125
label.top = min(y1, y2);
126
label.bottom = max(y1, y2);
130
Marker::overlap(const Marker &m)
132
return(overlap(m.image) + overlap(m.label));
136
Marker::overlap(const BoundingBox &b)
138
if (label.left > b.right || label.right < b.left) return(0);
140
if (label.top > b.bottom || label.bottom < b.top) return(0);
143
if (label.left > b.left)
144
width = min(b.right, label.right) - label.left;
146
width = min(b.right, label.right) - max(b.left, label.left);
148
if (label.top > b.top)
149
height = min(b.bottom, label.bottom) - label.top;
151
height = min(b.bottom, label.bottom) - max(b.top, label.top);
153
return(width * height);
157
Marker::printCorners(ofstream &outfile)
159
outfile << min(image.left, label.left) << ","
160
<< min(image.top, label.top) << " "
161
<< max(image.right, label.right) << ","
162
<< max(image.bottom, label.bottom) << "\t" << text << endl;
166
Marker::setTransparency(unsigned char *pixel)
169
memcpy(transparent, pixel, 3);
173
Marker::isTransparent(const int pixel_x, const int pixel_y)
175
if (!transparency || image_data == NULL) return(false);
177
unsigned char *pixel = (image_data
178
+ 3 * (pixel_y * image_width + pixel_x));
180
for (int i = 0; i < 3; i++)
181
if (pixel[i] != transparent[i]) return(false);