1.added to_string method to Color
2.added factory methods to python Color use factory methods
This commit is contained in:
parent
3818da6bc5
commit
c3ff3084ca
3 changed files with 25 additions and 10 deletions
|
@ -49,11 +49,6 @@ class _Envelope(Envelope,_injector):
|
|||
return 'Envelope(%s,%s,%s,%s)' % \
|
||||
(self.minx,self.miny,self.maxx,self.maxy)
|
||||
|
||||
class _Color(Color,_injector):
|
||||
def __repr__(self):
|
||||
return 'Color(%s,%s,%s,%s)' % \
|
||||
(self.r,self.g,self.b,self.a)
|
||||
|
||||
#register datasources
|
||||
from mapnik import DatasourceCache
|
||||
DatasourceCache.instance().register_datasources('%s' % inputpluginspath)
|
||||
|
|
|
@ -41,20 +41,31 @@ Color create_from_string(const char* str)
|
|||
return color_factory::from_string(str);
|
||||
}
|
||||
|
||||
Color create_from_rgb(unsigned r, unsigned g,unsigned b)
|
||||
{
|
||||
return Color(r,g,b);
|
||||
}
|
||||
|
||||
Color create_from_rgba(unsigned r, unsigned g,unsigned b,unsigned a)
|
||||
{
|
||||
return Color(r,g,b,a);
|
||||
}
|
||||
|
||||
void export_color ()
|
||||
{
|
||||
using namespace boost::python;
|
||||
class_<Color>("Color",init<>())
|
||||
.def(init<int,int,int,boost::python::optional<int> >())
|
||||
.add_property("r",&Color::red,&Color::set_red)
|
||||
.add_property("g",&Color::green,&Color::set_green)
|
||||
.add_property("b",&Color::blue,&Color::set_blue)
|
||||
.add_property("a",&Color::alpha)
|
||||
.def(self == self)
|
||||
.def_pickle(color_pickle_suite())
|
||||
.def("fromString",&create_from_string)
|
||||
.staticmethod("fromString")
|
||||
;
|
||||
//def("Color",&create_from_string);
|
||||
.def("__str__",&Color::to_string)
|
||||
;
|
||||
|
||||
def("Color",&create_from_string);
|
||||
def("Color",&create_from_rgba);
|
||||
def("Color",&create_from_rgb);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#ifndef COLOR_HPP
|
||||
#define COLOR_HPP
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
class Color
|
||||
|
@ -91,6 +93,13 @@ namespace mapnik {
|
|||
{
|
||||
return rgba_ == other.rgba_;
|
||||
}
|
||||
|
||||
inline std::string to_string() const
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "rgb (" << red() << "," << green() << "," << blue() <<")";
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue