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 } 00056 if (color == "black") 00057 *this = OBColor(0.0, 0.0, 0.0); 00058 else if (color == "white") 00059 *this = OBColor(1.0, 1.0, 1.0); 00060 else if (color == "red") 00061 *this = OBColor(1.0, 0.0, 0.0); 00062 else if (color == "green") 00063 *this = OBColor(0.0, 1.0, 0.0); 00064 else if (color == "blue") 00065 *this = OBColor(0.0, 0.0, 1.0); 00066 else if (color == "yellow") 00067 *this = OBColor(1.0, 1.0, 0.0); 00068 else if (color == "gray") 00069 *this = OBColor(0.3, 0.3, 0.3); 00070 else if (color == "cyan") 00071 *this = OBColor(1.0, 0.0, 1.0); 00072 else if (color == "purple") 00073 *this = OBColor(0.5, 0.0, 0.5); 00074 else if (color == "teal") 00075 *this = OBColor(0.0, 0.5, 0.5); 00076 else if (color == "olive") 00077 *this = OBColor(0.5, 0.5, 0.0); 00078 else 00079 *this = OBColor(0.5, 0.5, 0.5); 00080 } 00081 00082 OBColor(std::vector<double> vec) : red(vec[0]), green(vec[1]), blue(vec[2]), alpha(1.0){} 00083 00084 bool operator !=(const OBColor& other) 00085 { 00086 return red!=other.red || green!=other.green || blue!=other.blue; 00087 } 00088 00089 double red, green, blue, alpha; 00090 }; 00091 00097 struct OBDEPICT OBFontMetrics 00098 { 00099 int fontSize; 00100 double ascent, descent; 00101 double width, height; 00102 }; 00103 00109 class OBDEPICT OBPainter 00110 { 00111 public: 00115 virtual ~OBPainter() {} 00116 00123 virtual void NewCanvas(double width, double height) = 0; 00129 virtual bool IsGood() const = 0; 00133 virtual void SetFontFamily(const std::string &fontFamily) = 0; 00137 virtual void SetFontSize(int pointSize) = 0; 00141 virtual void SetFillColor(const OBColor &color) = 0; 00145 virtual void SetPenColor(const OBColor &color) = 0; 00149 virtual void SetPenWidth(double width) = 0; 00154 virtual void DrawLine(double x1, double y1, double x2, double y2) = 0; 00155 virtual void DrawCircle(double x, double y, double r) = 0; 00162 virtual void DrawPolygon(const std::vector<std::pair<double,double> > &points) = 0; 00163 virtual void DrawText(double x, double y, const std::string &text) = 0; 00164 virtual OBFontMetrics GetFontMetrics(const std::string &text) = 0; 00165 }; 00166 00167 } 00168 00169 #endif 00170
This file is part of the documentation for Open Babel, version 2.3.