Loading...
Searching...
No Matches
painter.h
Go to the documentation of this file.
/**********************************************************************
painter.h - Abstract base class for rendering
Copyright (C) 2009 by Tim Vandermeersch
Some portions Copyright (C) 2009 by Chris Morley
This file is part of the Open Babel project.
For more information, see <http://openbabel.org/>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2 of the License.
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.
***********************************************************************/
#ifndef OB_PAINTER_H
#define OB_PAINTER_H
#include <openbabel/babelconfig.h>
#include <string>
#include <vector>
#include <sstream>
#ifndef OBDEPICT
#define OBDEPICT
#endif
namespace OpenBabel
{
struct OBDEPICT OBColor
{
public:
OBColor()
{
*this = OBColor(0.0, 0.0, 0.0);
}
OBColor(double _red, double _green, double _blue, double _alpha = 1.0) :
red(_red), green(_green), blue(_blue), alpha(_alpha)
{
}
OBColor(const std::string &color)
{
if (color[0]=='#')
{
std::stringstream ss(color.substr(1));
unsigned c;
ss >> std::hex >> c;
*this = OBColor((c/0x10000)/256.0, ((c%0x10000)/0x100/256.0), (c%0x100)/256.0);
return;
}
if (color == "black")
*this = OBColor(0.0, 0.0, 0.0);
else if (color == "white")
*this = OBColor(1.0, 1.0, 1.0);
else if (color == "red")
*this = OBColor(1.0, 0.0, 0.0);
else if (color == "green")
*this = OBColor(0.0, 1.0, 0.0);
else if (color == "blue")
*this = OBColor(0.0, 0.0, 1.0);
else if (color == "yellow")
*this = OBColor(1.0, 1.0, 0.0);
else if (color == "gray")
*this = OBColor(0.3, 0.3, 0.3);
else if (color == "cyan")
*this = OBColor(1.0, 0.0, 1.0);
else if (color == "purple")
*this = OBColor(0.5, 0.0, 0.5);
else if (color == "teal")
*this = OBColor(0.0, 0.5, 0.5);
else if (color == "olive")
*this = OBColor(0.5, 0.5, 0.0);
else if (color == "none")
*this = OBColor(0.0, 0.0, 0.0, 0.0);
else
*this = OBColor(0.5, 0.5, 0.5);
}
OBColor(std::vector<double> vec) : red(vec[0]), green(vec[1]), blue(vec[2]), alpha(1.0){}
bool operator !=(const OBColor& other)
{
return red!=other.red || green!=other.green || blue!=other.blue;
}
bool operator <(const OBColor& other) const
{
if (red < other.red)
return true;
else if (red > other.red)
return false;
else if (green < other.green)
return true;
else if (green > other.green)
return false;
else if (blue<other.blue)
return true;
return false;
}
double red, green, blue, alpha;
};
struct OBDEPICT OBFontMetrics
{
int fontSize;
double ascent, descent;
double width, height;
};
class OBDEPICT OBPainter
{
public:
virtual ~OBPainter() {}
virtual void NewCanvas(double width, double height) = 0;
virtual bool IsGood() const = 0;
virtual void SetFontFamily(const std::string &fontFamily) = 0;
virtual void SetFontSize(int pointSize) = 0;
virtual void SetFillColor(const OBColor &color) = 0;
virtual void SetFillRadial(const OBColor &start, const OBColor &end) = 0;
virtual void SetPenColor(const OBColor &color) = 0;
virtual void SetPenWidth(double width) = 0;
virtual double GetPenWidth() = 0;
virtual void DrawLine(double x1, double y1, double x2, double y2, const std::vector<double> & dashes=std::vector<double>()) = 0;
virtual void DrawCircle(double x, double y, double r) = 0;
virtual void DrawPolygon(const std::vector<std::pair<double,double> > &points) = 0;
virtual void DrawBall(double x, double y, double r, double opacity = 1.0) = 0;
virtual void DrawText(double x, double y, const std::string &text) = 0;
virtual OBFontMetrics GetFontMetrics(const std::string &text) = 0;
};
}
#endif
OpenBabel::OBPainter
Abstract painter base class used by OBDepict.
Definition painter.h:129
OpenBabel::OBPainter::SetPenColor
virtual void SetPenColor(const OBColor &color)=0
OpenBabel::OBPainter::NewCanvas
virtual void NewCanvas(double width, double height)=0
OpenBabel::OBPainter::SetFillColor
virtual void SetFillColor(const OBColor &color)=0
OpenBabel::OBPainter::SetFontSize
virtual void SetFontSize(int pointSize)=0
OpenBabel::OBPainter::~OBPainter
virtual ~OBPainter()
Definition painter.h:134
OpenBabel::OBPainter::GetPenWidth
virtual double GetPenWidth()=0
OpenBabel::OBPainter::DrawPolygon
virtual void DrawPolygon(const std::vector< std::pair< double, double > > &points)=0
OpenBabel::OBPainter::SetFillRadial
virtual void SetFillRadial(const OBColor &start, const OBColor &end)=0
OpenBabel::OBPainter::SetPenWidth
virtual void SetPenWidth(double width)=0
OpenBabel::OBPainter::IsGood
virtual bool IsGood() const =0
OpenBabel::OBPainter::SetFontFamily
virtual void SetFontFamily(const std::string &fontFamily)=0
OpenBabel::OBPainter::DrawCircle
virtual void DrawCircle(double x, double y, double r)=0
OpenBabel::OBPainter::DrawBall
virtual void DrawBall(double x, double y, double r, double opacity=1.0)=0
OpenBabel::OBPainter::DrawText
virtual void DrawText(double x, double y, const std::string &text)=0
OpenBabel::OBPainter::GetFontMetrics
virtual OBFontMetrics GetFontMetrics(const std::string &text)=0
OpenBabel::OBPainter::DrawLine
virtual void DrawLine(double x1, double y1, double x2, double y2, const std::vector< double > &dashes=std::vector< double >())=0
OpenBabel
Global namespace for all Open Babel code.
Definition alias.h:23
OpenBabel::OBColor
Color class used by OBDepict.
Definition painter.h:38
OpenBabel::OBColor::alpha
double alpha
Definition painter.h:108
OpenBabel::OBColor::green
double green
Definition painter.h:108
OpenBabel::OBColor::OBColor
OBColor(std::vector< double > vec)
Definition painter.h:86
OpenBabel::OBColor::red
double red
Definition painter.h:108
OpenBabel::OBColor::OBColor
OBColor()
Definition painter.h:40
OpenBabel::OBColor::OBColor
OBColor(double _red, double _green, double _blue, double _alpha=1.0)
Definition painter.h:44
OpenBabel::OBColor::OBColor
OBColor(const std::string &color)
Definition painter.h:48
OpenBabel::OBColor::blue
double blue
Definition painter.h:108
OpenBabel::OBFontMetrics
Font metrics class used by OBDepict.
Definition painter.h:117
OpenBabel::OBFontMetrics::descent
double descent
Definition painter.h:119
OpenBabel::OBFontMetrics::ascent
double ascent
Definition painter.h:119
OpenBabel::OBFontMetrics::fontSize
int fontSize
Definition painter.h:118
OpenBabel::OBFontMetrics::height
double height
Definition painter.h:120
OpenBabel::OBFontMetrics::width
double width
Definition painter.h:120