void selectionChanged() override { // we're only really interested in when the selection changes, regardless of if it was // clicked or not so we'll only override this method const File selectedFile (fileTree.getSelectedFile()); if (selectedFile.existsAsFile()) imagePreview.setImage (ImageCache::getFromFile (selectedFile)); // the image cahce is a handly way to load images from files or directly from memory and // will keep them hanging around for a few seconds in case they are requested elsewhere }
//takes an XML element definition and creates an object from it GuiComponent* ThemeComponent::createElement(pugi::xml_node data, GuiComponent* parent) { std::string type = data.child("type").text().get(); if(type == "image") { std::string path = expandPath(data.child("path").text().get()); if(!boost::filesystem::exists(path)) { LOG(LogError) << "Error - theme image \"" << path << "\" does not exist."; return NULL; } std::string pos = data.child("pos").text().get(); std::string dim = data.child("dim").text().get(); std::string origin = data.child("origin").text().get(); bool tiled = data.child("tiled") != 0; //split position and dimension information std::string posX, posY; splitString(pos, ' ', &posX, &posY); std::string dimW, dimH; splitString(dim, ' ', &dimW, &dimH); std::string originX, originY; splitString(origin, ' ', &originX, &originY); //resolve to pixels from percentages/variables int x = (int)(resolveExp(posX) * Renderer::getScreenWidth()); int y = (int)(resolveExp(posY) * Renderer::getScreenHeight()); int w = (int)(resolveExp(dimW) * Renderer::getScreenWidth()); int h = (int)(resolveExp(dimH) * Renderer::getScreenHeight()); float ox = strToFloat(originX); float oy = strToFloat(originY); ImageComponent* comp = new ImageComponent(mWindow, x, y, "", w, h, true); comp->setOrigin(ox, oy); comp->setTiling(tiled); comp->setImage(path); addChild(comp); return comp; } LOG(LogError) << "Theme component type \"" << type << "\" unknown!"; return NULL; }
void handleAsyncUpdate() override { if (incomingImage.isValid()) lastSnapshot.setImage (incomingImage); }