MCPcopy Create free account
hub / github.com/LibreSprite/LibreSprite / load

Method load

src/app/app_brushes.cpp:283–382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

281 int(BrushSlot::Flags::BrushAngle);
282
283void 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 }

Callers 1

set_config_fileFunction · 0.45

Calls 10

open_xmlFunction · 0.85
string_id_to_brush_typeFunction · 0.85
load_xml_imageFunction · 0.85
string_id_to_ink_typeFunction · 0.85
shade_from_stringFunction · 0.85
bool_attr_is_trueFunction · 0.85
FlagsEnum · 0.70
getMethod · 0.45
resetMethod · 0.45
setImageMethod · 0.45

Tested by

no test coverage detected