Style 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. #ifndef OSGTEXT_STYLE
  14. #define OSGTEXT_STYLE 1
  15. #include <osg/Object>
  16. #include <osg/Vec2>
  17. #include <osgText/Export>
  18. #include <iosfwd>
  19. #include <vector>
  20. namespace osgText
  21. {
  22. class OSGTEXT_EXPORT Bevel : public osg::Object
  23. {
  24. public:
  25. Bevel();
  26. Bevel(const Bevel& bevel, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  27. META_Object(osgText, Bevel)
  28. bool operator == (const Bevel& rhs) const
  29. {
  30. if (_smoothConcaveJunctions != rhs._smoothConcaveJunctions) return false;
  31. if (_thickness != rhs._thickness) return false;
  32. return _vertices==rhs._vertices;
  33. }
  34. void setSmoothConcaveJunctions(bool flag) { _smoothConcaveJunctions = flag; }
  35. bool getSmoothConcaveJunctions() const { return _smoothConcaveJunctions; }
  36. void setBevelThickness(float thickness) { _thickness = thickness; }
  37. float getBevelThickness() const { return _thickness; }
  38. void flatBevel(float width=0.25f);
  39. void roundedBevel(float width=0.5f, unsigned int numSteps=10);
  40. void roundedBevel2(float width=0.5f, unsigned int numSteps=10);
  41. typedef std::vector<osg::Vec2> Vertices;
  42. void setVertices(const Vertices& vertices) { _vertices = vertices; }
  43. Vertices& getVertices() { return _vertices; }
  44. const Vertices& getVertices() const { return _vertices; }
  45. void print(std::ostream& fout);
  46. protected:
  47. bool _smoothConcaveJunctions;
  48. float _thickness;
  49. Vertices _vertices;
  50. };
  51. class OSGTEXT_EXPORT Style : public osg::Object
  52. {
  53. public:
  54. Style();
  55. Style(const Style& style, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  56. META_Object(osgText, Style);
  57. /// default Layout implementation used if no other is specified on TextNode
  58. static osg::ref_ptr<Style>& getDefaultStyle();
  59. bool operator == (const Style& style) const;
  60. /// NULL is no bevel
  61. void setBevel(Bevel* bevel) { _bevel = bevel; }
  62. const Bevel* getBevel() const { return _bevel.get(); }
  63. /// 1 is the default width of the text
  64. void setWidthRatio(float widthRatio) { _widthRatio = widthRatio; }
  65. float getWidthRatio() const { return _widthRatio; }
  66. /// 0 is 2D text
  67. void setThicknessRatio(float thicknessRatio) { _thicknessRatio = thicknessRatio; }
  68. float getThicknessRatio() const { return _thicknessRatio; }
  69. /// 0 is off
  70. void setOutlineRatio(float outlineRatio) { _outlineRatio = outlineRatio; }
  71. float getOutlineRatio() const { return _outlineRatio; }
  72. /// 1.0 is default number of samples
  73. void setSampleDensity(float sd) { _sampleDensity = sd; }
  74. float getSampleDensity() const { return _sampleDensity; }
  75. protected:
  76. osg::ref_ptr<Bevel> _bevel;
  77. float _widthRatio;
  78. float _thicknessRatio;
  79. float _outlineRatio;
  80. float _sampleDensity;
  81. };
  82. }
  83. #endif