| 281 | int(BrushSlot::Flags::BrushAngle); |
| 282 | |
| 283 | void AppBrushes::load(const std::string& filename) |
| 284 | { |
| 285 | XmlDocumentRef doc = app::open_xml(filename); |
| 286 | tinyxml2::XMLHandle handle(doc.get()); |
| 287 | tinyxml2::XMLElement* brushElem = handle |
| 288 | .FirstChildElement("brushes") |
| 289 | .FirstChildElement("brush").ToElement(); |
| 290 | |
| 291 | while (brushElem) { |
| 292 | // flags |
| 293 | int flags = 0; |
| 294 | BrushRef brush; |
| 295 | app::Color fgColor; |
| 296 | app::Color bgColor; |
| 297 | tools::InkType inkType = tools::InkType::DEFAULT; |
| 298 | int inkOpacity = 255; |
| 299 | Shade shade; |
| 300 | bool pixelPerfect = false; |
| 301 | |
| 302 | // Brush |
| 303 | const char* type = brushElem->Attribute("type"); |
| 304 | const char* size = brushElem->Attribute("size"); |
| 305 | const char* angle = brushElem->Attribute("angle"); |
| 306 | if (type || size || angle) { |
| 307 | if (type) flags |= int(BrushSlot::Flags::BrushType); |
| 308 | if (size) flags |= int(BrushSlot::Flags::BrushSize); |
| 309 | if (angle) flags |= int(BrushSlot::Flags::BrushAngle); |
| 310 | brush.reset( |
| 311 | new Brush( |
| 312 | (type ? string_id_to_brush_type(type): kFirstBrushType), |
| 313 | (size ? base::convert_to<int>(std::string(size)): 1), |
| 314 | (angle ? base::convert_to<int>(std::string(angle)): 0))); |
| 315 | } |
| 316 | |
| 317 | // Brush image |
| 318 | if (tinyxml2::XMLElement* imageElem = brushElem->FirstChildElement("image")) { |
| 319 | ImageRef image = load_xml_image(imageElem); |
| 320 | if (image) { |
| 321 | if (!brush) |
| 322 | brush.reset(new Brush()); |
| 323 | brush->setImage(image.get()); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | // Colors |
| 328 | if (tinyxml2::XMLElement* fgcolorElem = brushElem->FirstChildElement("fgcolor")) { |
| 329 | if (auto value = fgcolorElem->Attribute("value")) { |
| 330 | fgColor = app::Color::fromString(value); |
| 331 | flags |= int(BrushSlot::Flags::FgColor); |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | if (tinyxml2::XMLElement* bgcolorElem = brushElem->FirstChildElement("bgcolor")) { |
| 336 | if (auto value = bgcolorElem->Attribute("value")) { |
| 337 | bgColor = app::Color::fromString(value); |
| 338 | flags |= int(BrushSlot::Flags::BgColor); |
| 339 | } |
| 340 | } |
no test coverage detected