mapnik/include/stroke.hpp

170 lines
4.1 KiB
C++
Raw Normal View History

2006-03-31 12:32:02 +02:00
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
2005-06-14 17:06:59 +02:00
*
2006-03-31 12:32:02 +02:00
* Copyright (C) 2006 Artem Pavlenko
2005-06-14 17:06:59 +02:00
*
2006-03-31 12:32:02 +02:00
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
2005-06-14 17:06:59 +02:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2006-03-31 12:32:02 +02:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
2005-06-14 17:06:59 +02:00
*
2006-03-31 12:32:02 +02:00
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
2005-06-14 17:06:59 +02:00
//$Id$
#ifndef STROKE_HPP
#define STROKE_HPP
#include "color.hpp"
#include <vector>
namespace mapnik
{
using std::pair;
using std::vector;
typedef vector<pair<float,float> > dash_array;
enum line_cap_e
2006-05-19 18:08:42 +02:00
{
BUTT_CAP,
SQUARE_CAP,
ROUND_CAP
};
2005-06-14 17:06:59 +02:00
enum line_join_e
2006-05-19 18:08:42 +02:00
{
MITER_JOIN,
MITER_REVERT_JOIN,
ROUND_JOIN,
BEVEL_JOIN
};
2005-06-14 17:06:59 +02:00
class stroke
{
2006-05-19 18:08:42 +02:00
Color c_;
float width_;
float opacity_; // 0.0 - 1.0
line_cap_e line_cap_;
line_join_e line_join_;
dash_array dash_;
2005-06-14 17:06:59 +02:00
public:
explicit stroke()
2006-05-19 18:08:42 +02:00
: c_(0,0,0),
width_(1.0),
opacity_(1.0),
line_cap_(BUTT_CAP),
line_join_(MITER_JOIN),
dash_() {}
2005-06-14 17:06:59 +02:00
2006-05-19 18:08:42 +02:00
stroke(Color const& c, float width=1.0)
: c_(c),
width_(width),
opacity_(1.0),
line_cap_(BUTT_CAP),
line_join_(MITER_JOIN),
dash_() {}
2005-06-14 17:06:59 +02:00
2006-05-19 18:08:42 +02:00
stroke(stroke const& other)
: c_(other.c_),
width_(other.width_),
opacity_(other.opacity_),
line_cap_(other.line_cap_),
line_join_(other.line_join_),
dash_(other.dash_) {}
2005-06-14 17:06:59 +02:00
2006-05-19 18:08:42 +02:00
stroke& operator=(const stroke& rhs)
{
stroke tmp(rhs);
swap(tmp);
return *this;
}
2005-06-14 17:06:59 +02:00
2006-05-19 18:08:42 +02:00
void set_color(const Color& c)
{
c_=c;
}
2005-06-14 17:06:59 +02:00
2006-05-19 18:08:42 +02:00
Color const& get_color() const
{
return c_;
}
2005-06-14 17:06:59 +02:00
2006-05-19 18:08:42 +02:00
float get_width() const
{
return width_;
}
void set_width(float w)
{
width_=w;
}
2005-06-14 17:06:59 +02:00
2006-05-19 18:08:42 +02:00
void set_opacity(float opacity)
{
if (opacity > 1.0) opacity_=1.0;
else if (opacity < 0.0) opacity_=0.0;
else opacity_=opacity;
}
2005-06-14 17:06:59 +02:00
2006-05-19 18:08:42 +02:00
float get_opacity() const
{
return opacity_;
}
2005-06-14 17:06:59 +02:00
2006-05-19 18:08:42 +02:00
void set_line_cap(line_cap_e line_cap)
{
line_cap_=line_cap;
}
2005-06-14 17:06:59 +02:00
2006-05-19 18:08:42 +02:00
line_cap_e get_line_cap() const
{
return line_cap_;
}
2005-06-14 17:06:59 +02:00
2006-05-19 18:08:42 +02:00
void set_line_join(line_join_e line_join)
{
line_join_=line_join;
}
2005-06-14 17:06:59 +02:00
2006-05-19 18:08:42 +02:00
line_join_e get_line_join() const
{
return line_join_;
}
2005-06-14 17:06:59 +02:00
2006-05-19 18:08:42 +02:00
void add_dash(float dash,float gap)
{
dash_.push_back(std::make_pair(dash,gap));
}
bool has_dash() const
{
return dash_.size()>0 ? true : false ;
}
2005-06-14 17:06:59 +02:00
2006-05-19 18:08:42 +02:00
dash_array const& get_dash_array() const
{
return dash_;
}
2005-06-14 17:06:59 +02:00
private:
2006-05-19 18:08:42 +02:00
void swap(const stroke& other) throw()
{
c_=other.c_;
width_=other.width_;
opacity_=other.opacity_;
line_cap_=other.line_cap_;
line_join_=other.line_join_;
dash_ = other.dash_;
}
2005-06-14 17:06:59 +02:00
};
}
#endif //STROKE_HPP