painter.h
Go to the documentation of this file.
00001 /********************************************************************** 00002 painter.h - Abstract base class for rendering 00003 00004 Copyright (C) 2009 by Tim Vandermeersch 00005 Some portions Copyright (C) 2009 by Chris Morley 00006 00007 This file is part of the Open Babel project. 00008 For more information, see <http://openbabel.org/> 00009 00010 This program is free software; you can redistribute it and/or modify 00011 it under the terms of the GNU General Public License as published by 00012 the Free Software Foundation version 2 of the License. 00013 00014 This program is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 ***********************************************************************/ 00019 #ifndef OB_PAINTER_H 00020 #define OB_PAINTER_H 00021 00022 #include <openbabel/babelconfig.h> 00023 #include <string> 00024 #include <vector> 00025 #include <sstream> 00026 #ifndef OBDEPICT 00027 #define OBDEPICT 00028 #endif 00029 00030 namespace OpenBabel 00031 { 00037 struct OBDEPICT OBColor 00038 { 00039 OBColor() 00040 { 00041 *this = OBColor(0.0, 0.0, 0.0); 00042 } 00043 OBColor(double _red, double _green, double _blue, double _alpha = 1.0) : 00044 red(_red), green(_green), blue(_blue), alpha(_alpha) 00045 { 00046 } 00047 OBColor(const std::string &color) 00048 { 00049 if (color[0]=='#') 00050 { 00051 std::stringstream ss(color.substr(1)); 00052 unsigned c; 00053 ss >> std::hex >> c; 00054 *this = OBColor((c/0x10000)/256.0, ((c%0x10000)/0x100/256.0), (c%0x100)/256.0); 00055 return; 00056 } 00057 if (color == "black") 00058 *this = OBColor(0.0, 0.0, 0.0); 00059 else if (color == "white") 00060 *this = OBColor(1.0, 1.0, 1.0); 00061 else if (color == "red") 00062 *this = OBColor(1.0, 0.0, 0.0); 00063 else if (color == "green") 00064 *this = OBColor(0.0, 1.0, 0.0); 00065 else if (color == "blue") 00066 *this = OBColor(0.0, 0.0, 1.0); 00067 else if (color == "yellow") 00068 *this = OBColor(1.0, 1.0, 0.0); 00069 else if (color == "gray") 00070 *this = OBColor(0.3, 0.3, 0.3); 00071 else if (color == "cyan") 00072 *this = OBColor(1.0, 0.0, 1.0); 00073 else if (color == "purple") 00074 *this = OBColor(0.5, 0.0, 0.5); 00075 else if (color == "teal") 00076 *this = OBColor(0.0, 0.5, 0.5); 00077 else if (color == "olive") 00078 *this = OBColor(0.5, 0.5, 0.0); 00079 else if (color == "none") 00080 *this = OBColor(0.0, 0.0, 0.0, 0.0); 00081 else 00082 *this = OBColor(0.5, 0.5, 0.5); 00083 } 00084 00085 OBColor(std::vector<double> vec) : red(vec[0]), green(vec[1]), blue(vec[2]), alpha(1.0){} 00086 00087 bool operator !=(const OBColor& other) 00088 { 00089 return red!=other.red || green!=other.green || blue!=other.blue; 00090 } 00091 00092 double red, green, blue, alpha; 00093 }; 00094 00100 struct OBDEPICT OBFontMetrics 00101 { 00102 int fontSize; 00103 double ascent, descent; 00104 double width, height; 00105 }; 00106 00112 class OBDEPICT OBPainter 00113 { 00114 public: 00118 virtual ~OBPainter() {} 00119 00126 virtual void NewCanvas(double width, double height) = 0; 00132 virtual bool IsGood() const = 0; 00136 virtual void SetFontFamily(const std::string &fontFamily) = 0; 00140 virtual void SetFontSize(int pointSize) = 0; 00144 virtual void SetFillColor(const OBColor &color) = 0; 00148 virtual void SetPenColor(const OBColor &color) = 0; 00152 virtual void SetPenWidth(double width) = 0; 00157 virtual void DrawLine(double x1, double y1, double x2, double y2) = 0; 00158 virtual void DrawCircle(double x, double y, double r) = 0; 00165 virtual void DrawPolygon(const std::vector<std::pair<double,double> > &points) = 0; 00166 virtual void DrawText(double x, double y, const std::string &text) = 0; 00167 virtual OBFontMetrics GetFontMetrics(const std::string &text) = 0; 00168 }; 00169 00170 } 00171 00172 #endif 00173


