Style 3.34 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
 *
 * This library is open source and may be redistributed and/or modified under
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 *
 * This library 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
 * OpenSceneGraph Public License for more details.
*/

#ifndef OSGTEXT_STYLE
#define OSGTEXT_STYLE 1

#include <osg/Object>
#include <osg/Vec2>
#include <osgText/Export>

#include <iosfwd>
#include <vector>

namespace osgText
{

class OSGTEXT_EXPORT Bevel : public osg::Object
{
    public:

        Bevel();
        Bevel(const Bevel& bevel, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);

        META_Object(osgText, Bevel)

        bool operator == (const Bevel& rhs) const
        {
            if (_thickness != rhs._thickness) return false;
            return _vertices==rhs._vertices;
        }

        void setBevelThickness(float thickness) { _thickness = thickness; }
        float getBevelThickness() const { return _thickness; }

        void flatBevel(float width=0.25f);

        void roundedBevel(float width=0.5f, unsigned int numSteps=10);

        void roundedBevel2(float width=0.5f, unsigned int numSteps=10);

        typedef std::vector<osg::Vec2> Vertices;

        void setVertices(const Vertices& vertices) { _vertices = vertices; }
        Vertices& getVertices() { return _vertices; }
        const Vertices& getVertices() const { return _vertices; }

        void print(std::ostream& fout);

    protected:

        float           _thickness;
        Vertices        _vertices;
};


class OSGTEXT_EXPORT Style : public osg::Object
{
    public:

        Style();
        Style(const Style& style, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);

        META_Object(osgText, Style)

        /// default Layout implementation used if no other is specified on TextNode
        static osg::ref_ptr<Style>& getDefaultStyle();

        bool operator == (const Style& style) const;

        /// NULL is no bevel
        void setBevel(Bevel* bevel) { _bevel = bevel; }
        const Bevel* getBevel() const { return _bevel.get(); }


        /// 1 is the default width of the text
        void setWidthRatio(float widthRatio) { _widthRatio = widthRatio; }
        float getWidthRatio() const { return _widthRatio; }

        /// 0 is 2D text
        void setThicknessRatio(float thicknessRatio) { _thicknessRatio = thicknessRatio; }
        float getThicknessRatio() const { return _thicknessRatio; }

        /// 0 is off
        void setOutlineRatio(float outlineRatio) { _outlineRatio = outlineRatio; }
        float getOutlineRatio() const { return _outlineRatio; }

        /// 1.0 is default number of samples
        void setSampleDensity(float sd) { _sampleDensity = sd; }
        float getSampleDensity() const { return _sampleDensity; }

    protected:

        osg::ref_ptr<Bevel>     _bevel;

        float                   _widthRatio;
        float                   _thicknessRatio;
        float                   _outlineRatio;
        float                   _sampleDensity;
};

}

#endif