MCPcopy Create free account
hub / github.com/Aloshi/EmulationStation / createElement

Method createElement

src/components/ThemeComponent.cpp:255–306  ·  view source on GitHub ↗

takes an XML element definition and creates an object from it

Source from the content-addressed store, hash-verified

253
254//takes an XML element definition and creates an object from it
255GuiComponent* ThemeComponent::createElement(pugi::xml_node data, GuiComponent* parent)
256{
257 std::string type = data.child("type").text().get();
258
259 if(type == "image")
260 {
261 std::string path = expandPath(data.child("path").text().get());
262
263 if(!boost::filesystem::exists(path))
264 {
265 LOG(LogError) << "Error - theme image \"" << path << "\" does not exist.";
266 return NULL;
267 }
268
269 std::string pos = data.child("pos").text().get();
270 std::string dim = data.child("dim").text().get();
271 std::string origin = data.child("origin").text().get();
272
273 bool tiled = data.child("tiled") != 0;
274
275 //split position and dimension information
276 std::string posX, posY;
277 splitString(pos, ' ', &posX, &posY);
278
279 std::string dimW, dimH;
280 splitString(dim, ' ', &dimW, &dimH);
281
282 std::string originX, originY;
283 splitString(origin, ' ', &originX, &originY);
284
285 //resolve to pixels from percentages/variables
286 float x = resolveExp(posX) * Renderer::getScreenWidth();
287 float y = resolveExp(posY) * Renderer::getScreenHeight();
288 float w = resolveExp(dimW) * Renderer::getScreenWidth();
289 float h = resolveExp(dimH) * Renderer::getScreenHeight();
290
291 float ox = strToFloat(originX);
292 float oy = strToFloat(originY);
293
294 ImageComponent* comp = new ImageComponent(mWindow, x, y, "", w, h, true);
295 comp->setOrigin(ox, oy);
296 comp->setTiling(tiled);
297 comp->setImage(path);
298
299 addChild(comp);
300 return comp;
301 }
302
303
304 LOG(LogError) << "Theme component type \"" << type << "\" unknown!";
305 return NULL;
306}
307
308//expands a file path (./ becomes the directory of this theme file, ~/ becomes $HOME/)
309std::string ThemeComponent::expandPath(std::string path)

Callers

nothing calls this directly

Calls 8

textMethod · 0.80
childMethod · 0.80
setOriginMethod · 0.80
setTilingMethod · 0.80
setImageMethod · 0.80
getScreenWidthFunction · 0.50
getScreenHeightFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected