1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
|
/*
* $Revision: 3521 $
*
* last checkin:
* $Author: gutwenger $
* $Date: 2013-05-31 14:52:33 +0200 (Fri, 31 May 2013) $
***************************************************************/
/** \file
* \brief Declaration of basic types for graphics.
*
* \author Carsten Gutwenger
*
* \par License:
* This file is part of the Open Graph Drawing Framework (OGDF).
*
* \par
* Copyright (C)<br>
* See README.txt in the root directory of the OGDF installation for details.
*
* \par
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* Version 2 or 3 as published by the Free Software Foundation;
* see the file LICENSE.txt included in the packaging of this file
* for details.
*
* \par
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* \par
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* \see http://www.gnu.org/copyleft/gpl.html
***************************************************************/
#ifdef _MSC_VER
#pragma once
#endif
#ifndef OGDF_GRAPHICS_H
#define OGDF_GRAPHICS_H
#include <ogdf/basic/basic.h>
namespace ogdf {
//! Line types of strokes.
enum StrokeType {
stNone, //!< no line
stSolid, //!< solid line
stDash, //!< dashed line
stDot, //!< dotted line
stDashdot, //!< line style "dash dot dash dot ..."
stDashdotdot //!< line style "dash dot dot dash dot dot ..."
};
//! Converts integer \a i to stroke type.
StrokeType intToStrokeType(int i);
//! Line cap types of strokes.
enum StrokeLineCap {
slcButt,
slcRound,
slcSquare
};
//! Line join types of strokes.
enum StrokeLineJoin {
sljMiter,
sljRound,
sljBevel
};
//! Fill patterns.
enum FillPattern {
fpNone,
fpSolid,
fpDense1,
fpDense2,
fpDense3,
fpDense4,
fpDense5,
fpDense6,
fpDense7,
fpHorizontal,
fpVertical,
fpCross,
fpBackwardDiagonal,
fpForwardDiagonal,
fpDiagonalCross
};
//! Converts integer \a i to fill pattern.
FillPattern intToFillPattern(int i);
//! Types for node shapes.
enum Shape {
shRect, //!< rectangle
shRoundedRect, //!< rectangle with rounded corners
shEllipse, //!< ellipse
shTriangle, //!< isosceles triangle (base side down)
shPentagon, //!< pentagon
shHexagon, //!< hexagon
shOctagon, //!< octagon
shRhomb, //!< rhomb (=diamond)
shTrapeze, //!< trapeze (upper side shorter)
shParallelogram, //!< parallelogram (slanted to the right)
shInvTriangle, //!< isosceles triangle (base side up)
shInvTrapeze, //!< inverted trapeze (upper side longer)
shInvParallelogram, //!< inverted parallelogram (slanted to the left)
shImage
};
//! Types for edge arrows.
enum EdgeArrow {
eaNone, //!< no edge arrows
eaLast, //!< edge arrow at target node of the edge
eaFirst, //!< edge arrow at source node of the edge
eaBoth, //!< edge arrow at target and source node of the edge
eaUndefined
};
//! Colors reresented as RGBA values.
/**
* The Color class represents colors with four components: R (red), G (green), B (blue), and A (alpha channel).
* Each component has a value between and 255. The alpha channel controls tranparency, where an opaque color
* has an alpha channel of 255.
*/
class Color {
__uint8 m_red, m_green, m_blue, m_alpha;
public:
//! Named colors (same as SVG color keywords).
enum Name {
Aliceblue,
Antiquewhite,
Aqua,
Aquamarine,
Azure,
Beige,
Bisque,
Black,
Blanchedalmond,
Blue,
Blueviolet,
Brown,
Burlywood,
Cadetblue,
Chartreuse,
Chocolate,
Coral,
Cornflowerblue,
Cornsilk,
Crimson,
Cyan,
Darkblue,
Darkcyan,
Darkgoldenrod,
Darkgray,
Darkgreen,
Darkgrey,
Darkkhaki,
Darkmagenta,
Darkolivegreen,
Darkorange,
Darkorchid,
Darkred,
Darksalmon,
Darkseagreen,
Darkslateblue,
Darkslategray,
Darkslategrey,
Darkturquoise,
Darkviolet,
Deeppink,
Deepskyblue,
Dimgray,
Dimgrey,
Dodgerblue,
Firebrick,
Floralwhite,
Forestgreen,
Fuchsia,
Gainsboro,
Ghostwhite,
Gold,
Goldenrod,
Gray,
Green,
Greenyellow,
Grey,
Honeydew,
Hotpink,
Indianred,
Indigo,
Ivory,
Khaki,
Lavender,
Lavenderblush,
Lawngreen,
Lemonchiffon,
Lightblue,
Lightcoral,
Lightcyan,
Lightgoldenrodyellow,
Lightgray,
Lightgreen,
Lightgrey,
Lightpink,
Lightsalmon,
Lightseagreen,
Lightskyblue,
Lightslategray,
Lightslategrey,
Lightsteelblue,
Lightyellow,
Lime,
Limegreen,
Linen,
Magenta,
Maroon,
Mediumaquamarine,
Mediumblue,
Mediumorchid,
Mediumpurple,
Mediumseagreen,
Mediumslateblue,
Mediumspringgreen,
Mediumturquoise,
Mediumvioletred,
Midnightblue,
Mintcream,
Mistyrose,
Moccasin,
Navajowhite,
Navy,
Oldlace,
Olive,
Olivedrab,
Orange,
Orangered,
Orchid,
Palegoldenrod,
Palegreen,
Paleturquoise,
Palevioletred,
Papayawhip,
Peachpuff,
Peru,
Pink,
Plum,
Powderblue,
Purple,
Red,
Rosybrown,
Royalblue,
Saddlebrown,
Salmon,
Sandybrown,
Seagreen,
Seashell,
Sienna,
Silver,
Skyblue,
Slateblue,
Slategray,
Slategrey,
Snow,
Springgreen,
Steelblue,
Tan,
Teal,
Thistle,
Tomato,
Turquoise,
Violet,
Wheat,
White,
Whitesmoke,
Yellow,
Yellowgreen
};
//! Creates an opaque black color.
Color() : m_red(0), m_green(0), m_blue(0), m_alpha(255) { }
//! Creates a color from given RGBA-values.
Color(__uint8 r, __uint8 g, __uint8 b, __uint8 a = 255) : m_red(r), m_green(g), m_blue(b), m_alpha(a) { }
//! Creates a color from given RGBA-values.
Color(int r, int g, int b, int a = 255) : m_red((__uint8)r), m_green((__uint8)g), m_blue((__uint8)b), m_alpha((__uint8)a) { }
//! Creates a color from given color name \a name.
Color(Color::Name name);
//! Crates a color from string \a str.
Color(const string &str) { fromString(str); }
//! Crates a color from string \a str.
Color(const char *str) { fromString(string(str)); }
//! Returns the red component.
__uint8 red() const { return m_red; }
//! Returns the green component.
__uint8 green() const { return m_green; }
//! Returns the blue component.
__uint8 blue() const { return m_blue; }
//! Returns the alpha channel.
__uint8 alpha() const { return m_alpha; }
//! Sets the red component to \a r.
void red(__uint8 r) { m_red = r; }
//! Sets the green component to \a g.
void green(__uint8 g) { m_green = g; }
//! Sets the blue component to \a b.
void blue(__uint8 b) { m_blue = b; }
//! Sets the alpha channel to \a a.
void alpha(__uint8 a) { m_alpha = a; }
//! Converts the color to a string and returns it.
/**
* Colors as represented as strings using the \#RRGGBB hex notation.
* Please note that in this notation the alpha channel is not represented and
* is assumed to be 255 (an opaque color).
*/
string toString() const;
//! Sets the color the the color defined by \a str.
bool fromString(const string &str);
//! Returns true iff \a c and this color are equal in every component.
bool operator==(const Color &c) const {
return m_red == c.m_red && m_green == c.m_green && m_blue == c.m_blue && m_alpha == c.m_alpha;
}
//! Returns true iff \a c and this color differ in any component.
bool operator!=(const Color &c) const {
return !operator==(c);
}
//! Writes the string representation of color \a c to output stream \a os.
friend ostream &operator<<(ostream &os, const Color &c) {
return os << c.toString();
}
};
//! Properties of strokes.
struct Stroke {
Color m_color; //!< stroke color
float m_width; //!< stroke width
StrokeType m_type : 8; //!< stroke type (e.g. solid or dashed)
StrokeLineCap m_cap : 8; //!< line-cap of the stroke
StrokeLineJoin m_join : 8; //!< line-join of the stroke
Stroke() : m_color(Color::Black), m_width(1.0f), m_type(stSolid), m_cap(slcButt), m_join(sljMiter) { }
Stroke(Color c) : m_color(c), m_width(1.0f), m_type(stSolid), m_cap(slcButt), m_join(sljMiter) { }
};
//! Properties of fills.
struct Fill {
Color m_color; //!< fill color
Color m_bgColor; //!< background color of fill pattern
FillPattern m_pattern; //!< fill pattern
Fill() : m_color(Color::White), m_bgColor(Color::Black), m_pattern(fpSolid) { }
Fill(Color c) : m_color(c), m_bgColor(Color::Black), m_pattern(fpSolid) { }
Fill(Color c, FillPattern pattern) : m_color(c), m_bgColor(Color::Black), m_pattern(pattern) { }
Fill(Color c, Color bgColor, FillPattern pattern) : m_color(c), m_bgColor(bgColor), m_pattern(pattern) { }
};
} // end namespace ogdf
#endif
|