| 1 | #include <osgText/Text> |
|---|
| 2 | |
|---|
| 3 | #include <iostream> |
|---|
| 4 | #include <string> |
|---|
| 5 | |
|---|
| 6 | #include <osg/Vec3> |
|---|
| 7 | #include <osg/Vec4> |
|---|
| 8 | #include <osg/io_utils> |
|---|
| 9 | |
|---|
| 10 | #include <osgDB/Registry> |
|---|
| 11 | #include <osgDB/Input> |
|---|
| 12 | #include <osgDB/Output> |
|---|
| 13 | #include <osgDB/ParameterOutput> |
|---|
| 14 | |
|---|
| 15 | bool Text_readLocalData(osg::Object &obj, osgDB::Input &fr); |
|---|
| 16 | bool Text_writeLocalData(const osg::Object &obj, osgDB::Output &fw); |
|---|
| 17 | |
|---|
| 18 | REGISTER_DOTOSGWRAPPER(Text_Proxy) |
|---|
| 19 | ( |
|---|
| 20 | new osgText::Text, |
|---|
| 21 | "Text", |
|---|
| 22 | "Object Drawable TextBase Text", |
|---|
| 23 | Text_readLocalData, |
|---|
| 24 | Text_writeLocalData |
|---|
| 25 | ); |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | osgText::Text::BackdropType convertBackdropTypeStringToEnum(std::string & str) |
|---|
| 29 | { |
|---|
| 30 | if (str=="DROP_SHADOW_BOTTOM_RIGHT") return osgText::Text::DROP_SHADOW_BOTTOM_RIGHT; |
|---|
| 31 | else if (str=="DROP_SHADOW_CENTER_RIGHT") return osgText::Text::DROP_SHADOW_CENTER_RIGHT; |
|---|
| 32 | else if (str=="DROP_SHADOW_TOP_RIGHT") return osgText::Text::DROP_SHADOW_TOP_RIGHT; |
|---|
| 33 | else if (str=="DROP_SHADOW_BOTTOM_CENTER") return osgText::Text::DROP_SHADOW_BOTTOM_CENTER; |
|---|
| 34 | else if (str=="DROP_SHADOW_TOP_CENTER") return osgText::Text::DROP_SHADOW_TOP_CENTER; |
|---|
| 35 | else if (str=="DROP_SHADOW_BOTTOM_LEFT") return osgText::Text::DROP_SHADOW_BOTTOM_LEFT; |
|---|
| 36 | else if (str=="DROP_SHADOW_CENTER_LEFT") return osgText::Text::DROP_SHADOW_CENTER_LEFT; |
|---|
| 37 | else if (str=="DROP_SHADOW_TOP_LEFT") return osgText::Text::DROP_SHADOW_TOP_LEFT; |
|---|
| 38 | else if (str=="OUTLINE") return osgText::Text::OUTLINE; |
|---|
| 39 | else if (str=="NONE") return osgText::Text::NONE; |
|---|
| 40 | else return static_cast<osgText::Text::BackdropType>(-1); |
|---|
| 41 | } |
|---|
| 42 | std::string convertBackdropTypeEnumToString(osgText::Text::BackdropType backdropType) |
|---|
| 43 | { |
|---|
| 44 | switch (backdropType) |
|---|
| 45 | { |
|---|
| 46 | case osgText::Text::DROP_SHADOW_BOTTOM_RIGHT: return "DROP_SHADOW_BOTTOM_RIGHT"; |
|---|
| 47 | case osgText::Text::DROP_SHADOW_CENTER_RIGHT: return "DROP_SHADOW_CENTER_RIGHT"; |
|---|
| 48 | case osgText::Text::DROP_SHADOW_TOP_RIGHT: return "DROP_SHADOW_TOP_RIGHT"; |
|---|
| 49 | case osgText::Text::DROP_SHADOW_BOTTOM_CENTER: return "DROP_SHADOW_BOTTOM_CENTER"; |
|---|
| 50 | case osgText::Text::DROP_SHADOW_TOP_CENTER: return "DROP_SHADOW_TOP_CENTER"; |
|---|
| 51 | case osgText::Text::DROP_SHADOW_BOTTOM_LEFT: return "DROP_SHADOW_BOTTOM_LEFT"; |
|---|
| 52 | case osgText::Text::DROP_SHADOW_CENTER_LEFT: return "DROP_SHADOW_CENTER_LEFT"; |
|---|
| 53 | case osgText::Text::DROP_SHADOW_TOP_LEFT: return "DROP_SHADOW_TOP_LEFT"; |
|---|
| 54 | case osgText::Text::OUTLINE: return "OUTLINE"; |
|---|
| 55 | case osgText::Text::NONE: return "NONE"; |
|---|
| 56 | default : return ""; |
|---|
| 57 | } |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | osgText::Text::BackdropImplementation convertBackdropImplementationStringToEnum(std::string & str) |
|---|
| 62 | { |
|---|
| 63 | if (str=="POLYGON_OFFSET") return osgText::Text::POLYGON_OFFSET; |
|---|
| 64 | else if (str=="NO_DEPTH_BUFFER") return osgText::Text::NO_DEPTH_BUFFER; |
|---|
| 65 | else if (str=="DEPTH_RANGE") return osgText::Text::DEPTH_RANGE; |
|---|
| 66 | else if (str=="STENCIL_BUFFER") return osgText::Text::STENCIL_BUFFER; |
|---|
| 67 | else return static_cast<osgText::Text::BackdropImplementation>(-1); |
|---|
| 68 | } |
|---|
| 69 | std::string convertBackdropImplementationEnumToString(osgText::Text::BackdropImplementation backdropImplementation) |
|---|
| 70 | { |
|---|
| 71 | switch (backdropImplementation) |
|---|
| 72 | { |
|---|
| 73 | case osgText::Text::POLYGON_OFFSET: return "POLYGON_OFFSET"; |
|---|
| 74 | case osgText::Text::NO_DEPTH_BUFFER: return "NO_DEPTH_BUFFER"; |
|---|
| 75 | case osgText::Text::DEPTH_RANGE: return "DEPTH_RANGE"; |
|---|
| 76 | case osgText::Text::STENCIL_BUFFER: return "STENCIL_BUFFER"; |
|---|
| 77 | default : return ""; |
|---|
| 78 | } |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | osgText::Text::ColorGradientMode convertColorGradientModeStringToEnum(std::string & str) |
|---|
| 82 | { |
|---|
| 83 | if (str=="SOLID") return osgText::Text::SOLID; |
|---|
| 84 | else if (str=="PER_CHARACTER") return osgText::Text::PER_CHARACTER; |
|---|
| 85 | else if (str=="OVERALL") return osgText::Text::OVERALL; |
|---|
| 86 | else return static_cast<osgText::Text::ColorGradientMode>(-1); |
|---|
| 87 | } |
|---|
| 88 | std::string convertColorGradientModeEnumToString(osgText::Text::ColorGradientMode colorGradientMode) |
|---|
| 89 | { |
|---|
| 90 | switch (colorGradientMode) |
|---|
| 91 | { |
|---|
| 92 | case osgText::Text::SOLID: return "SOLID"; |
|---|
| 93 | case osgText::Text::PER_CHARACTER: return "PER_CHARACTER"; |
|---|
| 94 | case osgText::Text::OVERALL: return "OVERALL"; |
|---|
| 95 | default : return ""; |
|---|
| 96 | } |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | bool Text_readLocalData(osg::Object &obj, osgDB::Input &fr) |
|---|
| 101 | { |
|---|
| 102 | osgText::Text &text = static_cast<osgText::Text &>(obj); |
|---|
| 103 | bool itAdvanced = false; |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | if (fr[0].matchWord("backdropType")) |
|---|
| 108 | { |
|---|
| 109 | std::string str = fr[1].getStr(); |
|---|
| 110 | osgText::Text::BackdropType backdropType = convertBackdropTypeStringToEnum(str); |
|---|
| 111 | |
|---|
| 112 | if (backdropType != static_cast<osgText::Text::BackdropType>(-1)) |
|---|
| 113 | text.setBackdropType(backdropType); |
|---|
| 114 | |
|---|
| 115 | fr += 2; |
|---|
| 116 | itAdvanced = true; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | float backdropHorizontalOffset = text.getBackdropHorizontalOffset(); |
|---|
| 120 | float backdropVerticalOffset = text.getBackdropVerticalOffset(); |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | if (fr[0].matchWord("backdropHorizontalOffset")) |
|---|
| 124 | { |
|---|
| 125 | if (fr[1].getFloat(backdropHorizontalOffset)) |
|---|
| 126 | { |
|---|
| 127 | fr += 2; |
|---|
| 128 | itAdvanced = true; |
|---|
| 129 | } |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | if (fr[0].matchWord("backdropVerticalOffset")) |
|---|
| 134 | { |
|---|
| 135 | if (fr[1].getFloat(backdropVerticalOffset)) |
|---|
| 136 | { |
|---|
| 137 | fr += 2; |
|---|
| 138 | itAdvanced = true; |
|---|
| 139 | } |
|---|
| 140 | } |
|---|
| 141 | text.setBackdropOffset(backdropHorizontalOffset, backdropVerticalOffset); |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | if (fr[0].matchWord("backdropColor")) |
|---|
| 145 | { |
|---|
| 146 | osg::Vec4 c; |
|---|
| 147 | if (fr[1].getFloat(c.x()) && fr[2].getFloat(c.y()) && fr[3].getFloat(c.z()) && fr[4].getFloat(c.w())) |
|---|
| 148 | { |
|---|
| 149 | text.setBackdropColor(c); |
|---|
| 150 | fr += 4; |
|---|
| 151 | itAdvanced = true; |
|---|
| 152 | } |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | if (fr[0].matchWord("backdropImplementation")) |
|---|
| 157 | { |
|---|
| 158 | std::string str = fr[1].getStr(); |
|---|
| 159 | osgText::Text::BackdropImplementation backdropImplementation = convertBackdropImplementationStringToEnum(str); |
|---|
| 160 | |
|---|
| 161 | if (backdropImplementation != static_cast<osgText::Text::BackdropImplementation>(-1)) |
|---|
| 162 | text.setBackdropImplementation(backdropImplementation); |
|---|
| 163 | |
|---|
| 164 | fr += 2; |
|---|
| 165 | itAdvanced = true; |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | if (fr[0].matchWord("colorGradientMode")) |
|---|
| 170 | { |
|---|
| 171 | std::string str = fr[1].getStr(); |
|---|
| 172 | osgText::Text::ColorGradientMode colorGradientMode = convertColorGradientModeStringToEnum(str); |
|---|
| 173 | |
|---|
| 174 | if (colorGradientMode != static_cast<osgText::Text::ColorGradientMode>(-1)) |
|---|
| 175 | text.setColorGradientMode(colorGradientMode); |
|---|
| 176 | |
|---|
| 177 | fr += 2; |
|---|
| 178 | itAdvanced = true; |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | osg::Vec4 colorGradientTopLeft = text.getColorGradientTopLeft(); |
|---|
| 183 | osg::Vec4 colorGradientBottomLeft = text.getColorGradientBottomLeft(); |
|---|
| 184 | osg::Vec4 colorGradientBottomRight = text.getColorGradientBottomRight(); |
|---|
| 185 | osg::Vec4 colorGradientTopRight = text.getColorGradientTopRight(); |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | if (fr[0].matchWord("colorGradientTopLeft")) |
|---|
| 189 | { |
|---|
| 190 | osg::Vec4 c; |
|---|
| 191 | if (fr[1].getFloat(c.x()) && fr[2].getFloat(c.y()) && fr[3].getFloat(c.z()) && fr[4].getFloat(c.w())) |
|---|
| 192 | { |
|---|
| 193 | colorGradientTopLeft = c; |
|---|
| 194 | fr += 4; |
|---|
| 195 | itAdvanced = true; |
|---|
| 196 | } |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | if (fr[0].matchWord("colorGradientBottomLeft")) |
|---|
| 201 | { |
|---|
| 202 | osg::Vec4 c; |
|---|
| 203 | if (fr[1].getFloat(c.x()) && fr[2].getFloat(c.y()) && fr[3].getFloat(c.z()) && fr[4].getFloat(c.w())) |
|---|
| 204 | { |
|---|
| 205 | colorGradientBottomLeft = c; |
|---|
| 206 | fr += 4; |
|---|
| 207 | itAdvanced = true; |
|---|
| 208 | } |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | if (fr[0].matchWord("colorGradientBottomRight")) |
|---|
| 213 | { |
|---|
| 214 | osg::Vec4 c; |
|---|
| 215 | if (fr[1].getFloat(c.x()) && fr[2].getFloat(c.y()) && fr[3].getFloat(c.z()) && fr[4].getFloat(c.w())) |
|---|
| 216 | { |
|---|
| 217 | colorGradientBottomRight = c; |
|---|
| 218 | fr += 4; |
|---|
| 219 | itAdvanced = true; |
|---|
| 220 | } |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | if (fr[0].matchWord("colorGradientTopRight")) |
|---|
| 225 | { |
|---|
| 226 | osg::Vec4 c; |
|---|
| 227 | if (fr[1].getFloat(c.x()) && fr[2].getFloat(c.y()) && fr[3].getFloat(c.z()) && fr[4].getFloat(c.w())) |
|---|
| 228 | { |
|---|
| 229 | colorGradientTopRight = c; |
|---|
| 230 | fr += 4; |
|---|
| 231 | itAdvanced = true; |
|---|
| 232 | } |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | text.setColorGradientCorners(colorGradientTopLeft, colorGradientBottomLeft, colorGradientBottomRight, colorGradientTopRight); |
|---|
| 236 | |
|---|
| 237 | return itAdvanced; |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | bool Text_writeLocalData(const osg::Object &obj, osgDB::Output &fw) |
|---|
| 241 | { |
|---|
| 242 | const osgText::Text &text = static_cast<const osgText::Text &>(obj); |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | fw.indent() << "backdropType " << convertBackdropTypeEnumToString(text.getBackdropType()) << std::endl; |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | fw.indent() << "backdropHorizontalOffset " << text.getBackdropHorizontalOffset() << std::endl; |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | fw.indent() << "backdropVerticalOffset " << text.getBackdropVerticalOffset() << std::endl; |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | osg::Vec4 c = text.getBackdropColor(); |
|---|
| 255 | fw.indent() << "backdropColor " << c.x() << " " << c.y() << " " << c.z() << " " << c.w() << std::endl; |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | fw.indent() << "backdropImplementation " << convertBackdropImplementationEnumToString(text.getBackdropImplementation()) << std::endl; |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | fw.indent() << "colorGradientMode " << convertColorGradientModeEnumToString(text.getColorGradientMode()) << std::endl; |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | c = text.getColorGradientTopLeft(); |
|---|
| 265 | fw.indent() << "colorGradientTopLeft " << c.x() << " " << c.y() << " " << c.z() << " " << c.w() << std::endl; |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | c = text.getColorGradientBottomLeft(); |
|---|
| 269 | fw.indent() << "colorGradientBottomLeft " << c.x() << " " << c.y() << " " << c.z() << " " << c.w() << std::endl; |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | c = text.getColorGradientBottomRight(); |
|---|
| 273 | fw.indent() << "colorGradientBottomRight " << c.x() << " " << c.y() << " " << c.z() << " " << c.w() << std::endl; |
|---|
| 274 | |
|---|
| 275 | |
|---|
| 276 | c = text.getColorGradientTopRight(); |
|---|
| 277 | fw.indent() << "colorGradientTopRight " << c.x() << " " << c.y() << " " << c.z() << " " << c.w() << std::endl; |
|---|
| 278 | |
|---|
| 279 | return true; |
|---|
| 280 | } |
|---|