Ejemplo n.º 1
0
// Loads the default shortcuts from the registry
void EventManager::loadAccelerators() {
	if (_debugMode) {
		std::cout << "EventManager: Loading accelerators...\n";
	}

	xml::NodeList shortcutSets = GlobalRegistry().findXPath("user/ui/input//shortcuts");

	if (_debugMode) {
		std::cout << "Found " << shortcutSets.size() << " sets.\n";
	}

	// If we have two sets of shortcuts, delete the default ones
	if (shortcutSets.size() > 1) {
		GlobalRegistry().deleteXPath("user/ui/input//shortcuts[@name='default']");
	}

	// Find all accelerators
	xml::NodeList shortcutList = GlobalRegistry().findXPath("user/ui/input/shortcuts//shortcut");

	if (shortcutList.size() > 0) {
		rMessage() << "EventManager: Shortcuts found in Registry: " <<
			static_cast<int>(shortcutList.size()) << std::endl;
		for (unsigned int i = 0; i < shortcutList.size(); i++) {
			const std::string key = shortcutList[i].getAttributeValue("key");

			if (_debugMode) {
				std::cout << "Looking up command: " << shortcutList[i].getAttributeValue("command") << "\n";
				std::cout << "Key is: >> " << key << " << \n";
			}

			// Try to lookup the command
			IEventPtr event = findEvent(shortcutList[i].getAttributeValue("command"));

			// Check for a non-empty key string
			if (key != "") {
				 // Check for valid command definitions were found
				if (!event->empty()) {
					// Get the modifier string (e.g. "SHIFT+ALT")
					const std::string modifierStr = shortcutList[i].getAttributeValue("modifiers");

					if (!duplicateAccelerator(key, modifierStr, event)) {
						// Create the accelerator object
						IAccelerator& accelerator = addAccelerator(key, modifierStr);

						// Connect the newly created accelerator to the command
						accelerator.connectEvent(event);
					}
				}
				else {
					rWarning() << "EventManager: Cannot load shortcut definition (command invalid)."
						<< std::endl;
				}
			}
		}
	}
	else {
		// No accelerator definitions found!
		rWarning() << "EventManager: No shortcut definitions found..." << std::endl;
	}
}
Ejemplo n.º 2
0
void UIManager::addLocalBitmapsAsIconFactory()
{
    // Destination Gtk::IconFactory
    _iconFactory = Gtk::IconFactory::create();

    // Iterate over each file in the bitmaps dir
    std::string bitmapsPath = GlobalRegistry().get(RKEY_BITMAPS_PATH) + "/";

    Glib::Dir bitmapsDir(bitmapsPath);
    for (Glib::DirIterator i = bitmapsDir.begin();
         i != bitmapsDir.end();
         ++i)
    {
        Glib::ustring filename = *i;

		// Skip directories
		if (Glib::file_test(bitmapsPath + filename, Glib::FILE_TEST_IS_DIR))
		{
			continue;
		}

        // Load the pixbuf into an IconSet
		try
		{
			Gtk::IconSet is(
				Gdk::Pixbuf::create_from_file(bitmapsPath + filename)
			);

			// Add IconSet to Factory with "darkradiant:" stock prefix
			Glib::ustring filenameWithoutExtension = filename.substr(
				0, filename.rfind(".")
			);

			Gtk::StockID stockID(
				Glib::ustring::compose(
					"darkradiant:%1", filenameWithoutExtension
				)
			);

			_iconFactory->add(stockID, is);
		}
		catch (Gdk::PixbufError& ex)
		{
			rWarning() << "Could not load pixbuf from file: " <<
				filename << ": " << ex.what() << std::endl;
		}
		catch (Glib::FileError& ex)
		{
			rWarning() << "Could not load pixbuf from file: " <<
				filename << ": " << ex.what() << std::endl;
		}
    }

    // Add the IconFactory to the default factory list
    _iconFactory->add_default();
}
Ejemplo n.º 3
0
GameSetupPage* GameSetupPage::CreatePageForGame(const game::IGamePtr& game, wxWindow* parent)
{
	EnsureDefaultPages();

	// Check the game setup dialog type, default to idTech generic
	std::string type = GameSetupPageIdTech::TYPE();

	xml::NodeList nodes = game->getLocalXPath("/gameSetup/dialog");

	if (!nodes.empty())
	{
		std::string value = nodes[0].getAttributeValue("type");

		if (!value.empty())
		{
			type = value;
		}
	}

	GameSetupPages::const_iterator found = _registeredPages.find(type);

	if (found != _registeredPages.end())
	{
		return found->second(parent, game);
	}
	
	rWarning() << "No Game Setup Page associated to type " << type << 
		", will fall back to a generic idTech setup page." << std::endl;

	return new GameSetupPageIdTech(parent, game);
}
Ejemplo n.º 4
0
    // Post-process after attachment parsing
    void validateAttachments()
    {
        // During parsing we indexed spawnargs by string suffix so that matching
        // keys could be found. From now on we are no longer interested in the
        // suffixes so we will re-build the maps indexed by name instead.
        reindexMapByName(_objects);
        reindexMapByName(_positions);

        // Drop any attached objects that specify a non-existent position (I
        // assume new positions cannot be dynamically created in game).
        for (AttachedObjects::iterator i = _objects.begin();
             i != _objects.end();
             /* in-loop increment */)
        {
            if (_positions.find(i->second.posName) == _positions.end())
            {
                rWarning()
                    << "[eclassmgr] Entity class '" << _parentClassname 
                    << "' tries to attach '" << i->first << "' at non-existent "
                    << "position '" << i->second.posName << "'\n";

                _objects.erase(i++);
            }
			else
			{
				++i;
			}
        }
    }
Ejemplo n.º 5
0
void MenuManager::add(const std::string& insertPath,
							const std::string& name,
							eMenuItemType type,
							const std::string& caption,
							const std::string& icon,
							const std::string& eventName)
{
	if (!_root) return; // root has already been removed

	MenuElementPtr parent = _root->find(insertPath);

	if (!parent)
	{
		rWarning() << "Cannot insert element at non-existent parent " << insertPath << std::endl;
		return;
	}

	MenuElementPtr element = MenuElement::CreateForType(type);

	element->setName(name);
	element->setCaption(caption);
	element->setIcon(icon);
	element->setEvent(eventName);

	parent->addChild(element);

	handleElementAdded(element);
}
Ejemplo n.º 6
0
void MenuManager::insert(const std::string& insertPath,
						 const std::string& name,
						 eMenuItemType type,
						 const std::string& caption,
						 const std::string& icon,
						 const std::string& eventName)
{
	if (!_root) return; // root has already been removed

	MenuElementPtr insertBefore = _root->find(insertPath);

	if (!insertBefore || !insertBefore->getParent())
	{
		rWarning() << "Cannot insert before non-existent item or item doesn't have a parent" 
			<< insertPath << std::endl;
		return;
	}

	MenuElementPtr element = MenuElement::CreateForType(type);

	element->setName(name);
	element->setCaption(caption);
	element->setIcon(icon);
	element->setEvent(eventName);

	insertBefore->getParent()->insertChild(element, insertBefore);

	handleElementAdded(element);
}
Ejemplo n.º 7
0
void LanguageManager::findAvailableLanguages()
{
	// English (index 0) is always available
	_availableLanguages.push_back(0);

	wxFileTranslationsLoader loader;
	wxArrayString translations = loader.GetAvailableTranslations(GETTEXT_PACKAGE);

	std::for_each(translations.begin(), translations.end(), [&] (const wxString& lang)
	{
		// Get the index (is this a known language?)
		try
		{
			int index = getLanguageIndex(lang.ToStdString());

			// Add this to the list (could use more extensive checking, but this is enough for now)
			_availableLanguages.push_back(index);
		}
		catch (UnknownLanguageException&)
		{
			rWarning() << "Skipping unknown language: " << lang << std::endl;
		}
	});

	rMessage() << "Found " << _availableLanguages.size() << " language folders." << std::endl;
}
Ejemplo n.º 8
0
GlyphSetPtr GlyphSet::createFromDatFile(const std::string& vfsPath,
										const std::string& fontname,
										const std::string& language,
										Resolution resolution)
{
	ArchiveFilePtr file = GlobalFileSystem().openFile(vfsPath);

	// Check file size
	if (file->size() != sizeof(q3font::Q3FontInfo))
	{
		rWarning() << "FontLoader: invalid file size of file "
			<< vfsPath << ", expected " << sizeof(q3font::Q3FontInfo)
			<< ", found " << file->size() << std::endl;
		return GlyphSetPtr();
	}

	// Allocate a buffer with the Quake3 info structure
	q3font::Q3FontInfoPtr buf(new q3font::Q3FontInfo);

	InputStream& stream = file->getInputStream();
	stream.read(
		reinterpret_cast<StreamBase::byte_type*>(buf.get()),
		sizeof(q3font::Q3FontInfo)
	);

	// Construct a glyph set using the loaded info
	GlyphSetPtr glyphSet(new GlyphSet(*buf, fontname, language, resolution));

	rMessage() << "FontLoader: "  << vfsPath << " loaded successfully." << std::endl;

	return glyphSet;
}
Ejemplo n.º 9
0
void mergeSelectedBrushes(const cmd::ArgumentList& args)
{
	// Get the current selection
	BrushPtrVector brushes = selection::algorithm::getSelectedBrushes();

	if (brushes.empty()) {
		rMessage() << _("CSG Merge: No brushes selected.") << std::endl;
		wxutil::Messagebox::ShowError(_("CSG Merge: No brushes selected."));
		return;
	}

	if (brushes.size() < 2) {
		rMessage() << "CSG Merge: At least two brushes have to be selected.\n";
		wxutil::Messagebox::ShowError("CSG Merge: At least two brushes have to be selected.");
		return;
	}

	rMessage() << "CSG Merge: Merging " << brushes.size() << " brushes." << std::endl;

	UndoableCommand undo("mergeSelectedBrushes");

	// Take the last selected node as reference for layers and parent
	scene::INodePtr merged = GlobalSelectionSystem().ultimateSelected();

	scene::INodePtr parent = merged->getParent();
	assert(parent != NULL);

	// Create a new BrushNode
	scene::INodePtr node = GlobalBrushCreator().createBrush();

	// Insert the newly created brush into the (same) parent entity
	parent->addChildNode(node);

	// Move the new brush to the same layers as the merged one
	node->assignToLayers(merged->getLayers());

	// Get the contained brush
	Brush* brush = Node_getBrush(node);

	// Attempt to merge the selected brushes into the new one
	if (!Brush_merge(*brush, brushes, true))
	{
		rWarning() << "CSG Merge: Failed - result would not be convex." << std::endl;
		return;
	}

	ASSERT_MESSAGE(!brush->empty(), "brush left with no faces after merge");

	// Remove the original brushes
	for (BrushPtrVector::iterator i = brushes.begin(); i != brushes.end(); ++i)
	{
		scene::removeNodeFromParent(*i);
	}

	// Select the new brush
	Node_setSelected(node, true);

	rMessage() << "CSG Merge: Succeeded." << std::endl;
	SceneChangeNotify();
}
Ejemplo n.º 10
0
    virtual bool pre(const scene::INodePtr& node)
    {
        NamespacedPtr namespaced = Node_getNamespaced(node);
        if (!namespaced)
        {
            return true;
        }

        INamespace* foreignNamespace = namespaced->getNamespace();

        // Do not reconnect to same namespace, this causes invalid name changes
        if (foreignNamespace == _nspace)
        {
            rWarning() << "ConnectNamespacedWalker: node '" << node->name()
                       << "' is already attached to namespace at " << _nspace
                       << std::endl;

            return true;
        }
        else if (foreignNamespace)
        {
            // The node is already connected to a different namespace, disconnect
            namespaced->disconnectNameObservers();
            namespaced->detachNames();
            namespaced->setNamespace(NULL);
        }

        // Set the namespace reference and add all "names"
        namespaced->setNamespace(_nspace);
        namespaced->attachNames();

        return true;
    }
Ejemplo n.º 11
0
void Doom3MapCompiler::dmapCmd(const cmd::ArgumentList& args)
{
	if (args.size() != 1)
	{
		rWarning() << "Usage: dmap <mapFile>" << std::endl;
		return;
	}

	std::string mapFile = args[0].getString();
	
	if (!boost::algorithm::iends_with(mapFile, ".map"))
	{
		mapFile.append(".map");
	}

	std::string mapPath = mapFile;

	// Find the map file
	if (!path_is_absolute(mapPath.c_str()))
	{
		mapPath = GlobalFileSystem().findFile(mapFile);

		if (mapPath.empty())
		{
			// Try again with maps/ prepended
			mapFile = "maps/" + mapFile;
			mapPath = GlobalFileSystem().findFile(mapFile);
		}

		mapPath += mapFile;
	}

	// Start the sequence
	runDmap(mapPath);
}
Ejemplo n.º 12
0
void EventManager::setToggled(const std::string& name, const bool toggled)
{
	// Check could be placed here by boost::shared_ptr's dynamic_pointer_cast
	if (!findEvent(name)->setToggled(toggled)) {
		rWarning() << "EventManager: Event " << name
			<< " is not a Toggle." << std::endl;
	}
}
Ejemplo n.º 13
0
void PrefabSelector::handleSelectionChange()
{
    wxDataViewItem item = _treeView->GetSelection();

    if (!item.IsOk())
    {
        clearPreview();
        return;
    }

    wxutil::TreeModel::Row row(item, *_treeView->GetModel());

    if (row[_columns.isFolder].getBool())
    {
        clearPreview();
        return;
    }

    std::string prefabPath = row[_columns.vfspath];

	_mapResource = GlobalMapResourceManager().capture(prefabPath);

	if (_mapResource == NULL)
	{
        clearPreview();
		return;
	}

	_lastPrefab = prefabPath;

	// Suppress the map loading dialog to avoid user
	// getting stuck in the "drag filename" operation
	registry::ScopedKeyChanger<bool> changer(
		RKEY_MAP_SUPPRESS_LOAD_STATUS_DIALOG, true
		);

	if (_mapResource->load())
	{
		// Get the node from the resource
		scene::INodePtr root = _mapResource->getNode();

		assert(root != NULL);

		// Set the new rootnode
		_preview->setRootNode(root);

		_preview->getWidget()->Refresh();
	}
	else
	{
		// Map load failed
		rWarning() << "Could not load prefab: " << prefabPath << std::endl;
        clearPreview();
	}

	updateUsageInfo();
}
Ejemplo n.º 14
0
void InfoFileManager::registerInfoFileModule(const IMapInfoFileModulePtr& module)
{
	if (_modules.find(module) != _modules.end())
	{
		rWarning() << "Duplicate info file module registered: " << module->getName() << std::endl;
		return;
	}

	_modules.insert(module);
}
Ejemplo n.º 15
0
guint EventManager::getGDKCode(const std::string& keyStr)
{
	guint returnValue = gdk_keyval_to_upper(gdk_keyval_from_name(keyStr.c_str()));

	if (returnValue == GDK_VoidSymbol) {
		rWarning() << "EventManager: Could not recognise key " << keyStr << std::endl;
	}

	return returnValue;
}
Ejemplo n.º 16
0
void InfoFile::parseInfoFileBody()
{
	// The opening brace of the master block
	_tok.assertNextToken("{");

	while (_tok.hasMoreTokens())
	{
		std::string token = _tok.nextToken();

		bool blockParsed = false;

		// Send each block to the modules that are able to load it
		GlobalMapInfoFileManager().foreachModule([&](IMapInfoFileModule& module)
		{
			if (!blockParsed && module.canParseBlock(token))
			{
				module.parseBlock(token, _tok);
				blockParsed = true;
			}
		});

		if (blockParsed)
		{
			continue; // block was processed by a module
		}

		if (token == "}")
		{
			break;
		}

		// Unknown token, try to ignore that block
		rWarning() << "Unknown keyword " << token << " encountered, will try to ignore this block." << std::endl;

		// We can only ignore a block if there is a block beginning curly brace
		_tok.assertNextToken("{");

		// Ignore the block
		int depth = 1;

		while (_tok.hasMoreTokens() && depth > 0)
		{
			std::string token2 = _tok.nextToken();

			if (token2 == "{") 
			{
				depth++;
			}
			else if (token2 == "}") 
			{
				depth--;
			}
		}
	}
}
Ejemplo n.º 17
0
void InfoFileManager::unregisterInfoFileModule(const IMapInfoFileModulePtr& module)
{
	if (_modules.find(module) == _modules.end())
	{
		rWarning() << "Trying to unregister non-existent info file module: " << module->getName() << std::endl;
		return;

	}

	_modules.erase(module);
}
Ejemplo n.º 18
0
// Connects the given accelerator to the given command (identified by the string)
void EventManager::connectAccelerator(IAccelerator& accelerator, const std::string& command) {
	IEventPtr event = findEvent(command);

	if (!event->empty()) {
		// Command found, connect it to the accelerator by passing its pointer
		accelerator.connectEvent(event);
	}
	else {
		// Command NOT found
		rWarning() << "EventManager: Unable to connect command: " << command << std::endl;
	}
}
void PropertyEditorFactory::registerPropertyEditor(const std::string& key, const IPropertyEditorPtr& editor)
{
	std::pair<PropertyEditorMap::iterator, bool> result = _customEditors.insert(
		PropertyEditorMap::value_type(key, editor)
	);

	if (!result.second)
	{
		rWarning() << "Could not register property editor for key " << key <<
			", is already associated." << std::endl;;
	}
}
Ejemplo n.º 20
0
void LanguageManager::findAvailableLanguages()
{
	// English (index 0) is always available
	_availableLanguages.push_back(0);

	// Search folder
	fs::path start(_i18nPath);

	if (!fs::exists(start))
	{
		rWarning() << "Cannot find i18n directory, skipping search for language files." << std::endl;
		return;
	}

	for (fs::directory_iterator it(start); it != fs::directory_iterator(); ++it)
	{
		// Get the candidate
		const fs::path& candidate = *it;

		if (fs::is_directory(candidate))
		{
			// Get the index (is this a known language?)
			try
			{
				int index = getLanguageIndex(candidate.filename().string());

				// Add this to the list (could use more extensive checking, but this is enough for now)
				_availableLanguages.push_back(index);
			}
			catch (UnknownLanguageException&)
			{
				rWarning() << "Skipping unknown language: "
					<< candidate.filename() << std::endl;
				continue;
			}
		}
	}

	rMessage() << "Found " << _availableLanguages.size() << " language folders." << std::endl;
}
Ejemplo n.º 21
0
Glib::RefPtr<Gdk::Pixbuf> UIManager::getLocalPixbufWithMask(const std::string& fileName) {

	// Try to find a cached pixbuf before loading from disk
	PixBufMap::iterator i = _localPixBufsWithMask.find(fileName);

	if (i != _localPixBufsWithMask.end())
	{
		return i->second;
	}

	// Not cached yet, load afresh

	std::string fullFileName(GlobalRegistry().get(RKEY_BITMAPS_PATH) + fileName);

	Glib::RefPtr<Gdk::Pixbuf> rgba;

	try
	{
		Glib::RefPtr<Gdk::Pixbuf> rgb = Gdk::Pixbuf::create_from_file(fullFileName);

		if (rgb)
		{
			// File load successful, add alpha channel
			rgba = rgb->add_alpha(true, 255, 0, 255);
		}
		else
		{
			rError() << "Couldn't load rgb pixbuf " << fullFileName << std::endl;
		}
	}
	catch (Glib::FileError& err)
	{
		rWarning() << "Couldn't load rgb pixbuf " << fullFileName << std::endl;
		rWarning() << err.what() << std::endl;
	}

	_localPixBufsWithMask.insert(PixBufMap::value_type(fileName, rgba));

	return rgba;
}
void PropertyEditorFactory::unregisterPropertyEditor(const std::string& key)
{
	PropertyEditorMap::iterator found = _customEditors.find(key);

	if (found != _customEditors.end())
	{
		_customEditors.erase(found);
	}
	else
	{
		rWarning() << "Cannot unregister property editor for key " << key << std::endl;
	}
}
Ejemplo n.º 23
0
// Checks if the eventName is already registered and writes to rMessage, if so
bool EventManager::alreadyRegistered(const std::string& eventName) {
	// Try to find the command and see if it's already registered
	IEventPtr foundEvent = findEvent(eventName);

	if (foundEvent->empty()) {
		return false;
	}
	else {
		rWarning() << "EventManager: Event " << eventName
			<< " already registered!" << std::endl;
		return true;
	}
}
Ejemplo n.º 24
0
void ObjectiveEntity::writeObjectiveConditions(Entity& ent)
{
	// No need to clear previous set of obj_condition_ spawnargs, 
	// as they've been removed by clearEntity() already

	// Spawnargs are numbered starting with 1 as first index
	std::size_t index = 1;

	// Go through all the conditions and save them. Skip invalid ones such that the
	// set of conditions will be "compressed" in terms of their indices.
	for (ObjectiveEntity::ConditionMap::const_iterator i = _objConditions.begin(); 
		 i != _objConditions.end(); ++i)
	{
		const ObjectiveCondition& cond = *i->second;

		if (!cond.isValid())
		{
			continue; // skip invalid conditions without increasing the index
		}

		std::string prefix = (boost::format(OBJ_COND_PREFIX + "%d_") % index).str();

		ent.setKeyValue(prefix + "src_mission", string::to_string(cond.sourceMission));
		ent.setKeyValue(prefix + "src_obj", string::to_string(cond.sourceObjective));
		ent.setKeyValue(prefix + "src_state", string::to_string(cond.sourceState));
		ent.setKeyValue(prefix + "target_obj", string::to_string(cond.targetObjective));

		std::string typeKey = prefix + "type";

		switch (cond.type)
		{
		case ObjectiveCondition::CHANGE_STATE:
			ent.setKeyValue(typeKey, "changestate");
			break;
		case ObjectiveCondition::CHANGE_VISIBILITY:
			ent.setKeyValue(typeKey, "changevisibility");
			break;
		case ObjectiveCondition::CHANGE_MANDATORY:
			ent.setKeyValue(typeKey, "changemandatory");
			break;
		default:
			ent.setKeyValue(typeKey, ""); // empty value to be sure
			rWarning() << "Invalid objective condition type encountered on saving." << std::endl;
			break;
		};

		ent.setKeyValue(prefix + "value", string::to_string(cond.value));

		++index; // next index
	}
}
Ejemplo n.º 25
0
void CipherFileIO::initHeader() {
  // check if the file has a header, and read it if it does..  Otherwise,
  // create one.
  off_t rawSize = base->getSize();
  if (rawSize >= HEADER_SIZE) {
    rDebug("reading existing header, rawSize = %" PRIi64, rawSize);
    // has a header.. read it
    unsigned char buf[8] = {0};

    IORequest req;
    req.offset = 0;
    req.data = buf;
    req.dataLen = 8;
    base->read(req);

    cipher->streamDecode(buf, sizeof(buf), externalIV, key);

    fileIV = 0;
    for (int i = 0; i < 8; ++i) fileIV = (fileIV << 8) | (uint64_t)buf[i];

    rAssert(fileIV != 0);  // 0 is never used..
  } else {
    rDebug("creating new file IV header");

    unsigned char buf[8] = {0};
    do {
      if (!cipher->randomize(buf, 8, false))
        throw ERROR("Unable to generate a random file IV");

      fileIV = 0;
      for (int i = 0; i < 8; ++i) fileIV = (fileIV << 8) | (uint64_t)buf[i];

      if (fileIV == 0)
        rWarning("Unexpected result: randomize returned 8 null bytes!");
    } while (fileIV == 0);  // don't accept 0 as an option..

    if (base->isWritable()) {
      cipher->streamEncode(buf, sizeof(buf), externalIV, key);

      IORequest req;
      req.offset = 0;
      req.data = buf;
      req.dataLen = 8;

      base->write(req);
    } else
      rDebug("base not writable, IV not written..");
  }
  rDebug("initHeader finished, fileIV = %" PRIu64, fileIV);
}
Ejemplo n.º 26
0
bool PodSync::doSync( void )
{
    bool result = true;
    const char *pDst = m_pConfig->getString( "destination_directory" );
    const char *pSrc = m_pConfig->getString( "source_directory" );
    if( 0 != pDst && 0 != pSrc )
    {
        rInfo( "Performing sync from %s to %s", pSrc, pDst );
        if( true == performSync( pSrc, pDst ))
        {
            rInfo( "Sync completed" );
        }
        else
        {
            rWarning( "Sync failed" );
        }
    }
    else
    {
        rWarning( "Bad config" );
        result = false;
    }
    return result;
}
Ejemplo n.º 27
0
Glib::RefPtr<Gdk::Pixbuf> UIManager::getLocalPixbuf(const std::string& fileName)
{
	// Try to use a cached pixbuf first
	PixBufMap::iterator i = _localPixBufs.find(fileName);

	if (i != _localPixBufs.end())
	{
		return i->second;
	}

	// Not cached yet, load afresh

	// Construct the full filename using the Bitmaps path
	std::string fullFileName(GlobalRegistry().get(RKEY_BITMAPS_PATH) + fileName);

	Glib::RefPtr<Gdk::Pixbuf> pixbuf;

	try
	{
		pixbuf = Gdk::Pixbuf::create_from_file(fullFileName);

		if (!pixbuf)
		{
			rError() << "Couldn't load pixbuf " << fullFileName << std::endl;
		}
	}
	catch (Glib::FileError& err)
	{
		rWarning() << "Couldn't load pixbuf " << fullFileName << std::endl;
		rWarning() << err.what() << std::endl;
	}

	_localPixBufs.insert(PixBufMap::value_type(fileName, pixbuf));

	return pixbuf;
}
Ejemplo n.º 28
0
void EventManager::disconnectDialogWindow(Gtk::Window* window)
{
	HandlerMap::iterator found = _dialogWindows.find(window);

	if (found != _dialogWindows.end())
	{
		found->second.first.disconnect();
		found->second.second.disconnect();

		_dialogWindows.erase(found);
	}
	else
	{
		rWarning()  << "EventManager::disconnect: Widget is not connected." << std::endl;
	}
}
Ejemplo n.º 29
0
void FontLoader::operator()(const vfs::FileInfo& fileInfo)
{
	// Construct the full VFS path
	std::string fullPath = os::standardPath(_basePath + fileInfo.name);

	std::regex expr("^/?(.*)/.*_(\\d{2})\\.dat$", std::regex::icase);
	std::smatch matches;

	if (std::regex_match(fileInfo.name, matches, expr))
	{
		// Get the font name and resolution from the match
		std::string fontname = matches[1];
		std::string resolutionStr = matches[2];

		int r = string::convert<int>(resolutionStr);

		Resolution resolution = NumResolutions;

		switch (r)
		{
		case 12:
			resolution = Resolution12;
			break;
		case 24:
			resolution = Resolution24;
			break;
		case 48:
			resolution = Resolution48;
			break;
		};

		if (resolution != NumResolutions)
		{
			// Create the font (if not done yet), acquire the info structure
			FontInfoPtr font = _manager.findOrCreateFontInfo(fontname);

			// Load the DAT file and create the glyph info
			font->glyphSets[resolution] = GlyphSet::createFromDatFile(
				fullPath, fontname, _manager.getCurLanguage(), resolution
			);
		}
		else
		{
			rWarning() << "FontLoader: ignoring DAT: " << fileInfo.name << std::endl;
		}
	}
}
void RadiantWindowObserver::removeObservedWidget(const Glib::RefPtr<Gtk::Widget>& observed)
{
	RefPtrKeyHandlerMap::iterator found = _refKeyHandlers.find(observed);

	if (found == _refKeyHandlers.end())
	{
		rWarning() <<
			"RadiantWindowObserver: Cannot remove observed refptr widget, not found."
			<< std::endl;
		return;
	}

	// Disconnect the key handler
	found->second.disconnect();

	// And remove the element from our map
	_refKeyHandlers.erase(found);
}