Esempio n. 1
0
bool Layer::swapKeyFrames( int position1, int position2 ) //Current behaviour, need to refresh the swapped cels
{

    bool keyPosition1 = false, keyPosition2 = false;
    KeyFrame* pFirstFrame;
    KeyFrame* pSecondFrame;


    if ( keyExists( position1 ) )
    {
        auto firstFrame = mKeyFrames.find( position1 );
        pFirstFrame = firstFrame->second;

        mKeyFrames.erase( position1 );

        //pFirstFrame = getKeyFrameAtPosition( position1 );
        //removeKeyFrame( position1 );

        keyPosition1 = true;
    }

	if ( keyExists( position2 ) )
    {
        auto secondFrame = mKeyFrames.find( position2 );
        pSecondFrame = secondFrame->second;

        mKeyFrames.erase( position2 );

        //pSecondFrame = getKeyFrameAtPosition( position2 );
        //removeKeyFrame( position2 );

        keyPosition2 = true;
    }

    if ( keyPosition2 )
    {
        //addKeyFrame( position1, pSecondFrame );
        pSecondFrame->setPos( position1 );
        mKeyFrames.insert( std::make_pair( position1, pSecondFrame ) );
    } 
	else if ( position1 == 1 ) 
	{
        addNewKeyAt( position1 );
    }

    if ( keyPosition1 )
    {
        //addKeyFrame( position2, pFirstFrame );
        pFirstFrame->setPos( position2 );
        mKeyFrames.insert( std::make_pair( position2, pFirstFrame ) );
    } 
	else if ( position2 == 1 )
	{
		addNewKeyAt( position2 );
    }

    return true;

}
Esempio n. 2
0
bool isChain(const std::string src, const std::string tgt) {
    std::cout << src << " == " << tgt << std::endl;
    if ((!keyExists(src)) || (!keyExists(tgt))) {
        return false;
    }
    // obvious base case - both phrases are the same
    if (src == tgt) {
        return true;
    }
    return false;
}
Esempio n. 3
0
bool AttrList_setItem(AttrList l, String key, int v){
   bool   retVal = false;
   int    idx    = -1;
   size_t i;
   String tmpKey;

   idx = getIndex(l);
   if(idx >= 0){
      if(!keyExists(l, key)){
         if(attrListPool[idx].length == (attrListPool[idx].size - 1)){
            growList(idx, (attrListPool[idx].size * 2));
         }
         for(i = 0; i < attrListPool[idx].size; ++i){
            if(attrListPool[idx].keys[i] == INVALID_STRING){
               break;
            }
         }
         tmpKey = new_String(NULL);
         if(tmpKey != INVALID_STRING && String_copyString(tmpKey, key)){
            attrListPool[idx].keys[i] = tmpKey;
            attrListPool[idx].data[i] = v;
            attrListPool[idx].length++;
            retVal = true;
         }
      }
   }
   return retVal;
}
Esempio n. 4
0
void SpriteManager::addSpriteSheet(const std::string &key, const char *fname, SDL_Rect r, int w, int h, int border,unsigned transp) {
	if (fileExists(fname)) {
		SDL_Surface * image = IMG_Load(fname);
		int iw = image->w;
		int ih = image->h;
		SDL_Surface * tmp = SDL_CreateRGBSurface(0, w, h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
		Uint32 *pixels = (Uint32 *)tmp->pixels;
		Uint32 *origpixels = (Uint32 *)image->pixels;
		int c = 0;
		for (int i = border; i < iw-w; i += w + border) {
			for (int j = border; j < ih-h; j += h + border) {
				for (int x = 0; x < w; ++x) {
					for (int y = 0; y < h; ++y) {
						if ((origpixels[(j + y)*iw + (i + x)] ^ transp) == 0) pixels[x + y*w] = 0;
						else pixels[x + y*w] = origpixels[(j + y)*iw + (i + x)];
					}
				}
				std::string tmpkey = key + std::to_string(c);
				++c;
				if (!keyExists(tmpkey)) {
					list[tmpkey] = Sprite(SDL_CreateTextureFromSurface(renderer, tmp), r, w, h);
					log(VERBOSE_LOAD, "LOADED SPRITESHEET %s FROM %s", tmpkey.c_str(), fname);
				}
				else {
					log(VERBOSE_ERRORS, "Repeated sprite key %s", tmpkey.c_str());
				}
			}
		}
		
	}
	else {
		log(VERBOSE_ERRORS, "File not found %s", fname);
	}
}
Esempio n. 5
0
std::string OptionsWrapper::getSingleValue(const std::string& key, Enum::GameOption modmapFlag) const
{
	Enum::OptionType optType = Enum::opt_undefined;

	if (keyExists(key, modmapFlag, false, optType)) {
		GameOptionsMapCIter optIt = m_opts.find((int)modmapFlag);
		if (optIt == m_opts.end())
			return "";

		const GameOptions& tempOpt = optIt->second;
		switch (optType) {
			case Enum::opt_float:
				return Util::ToFloatString(GetItem(tempOpt.float_map, key).value);
			case Enum::opt_bool:
				return Util::ToIntString(GetItem(tempOpt.bool_map, key).value);
			case Enum::opt_string:
				return GetItem(tempOpt.string_map, key).value;
			case Enum::opt_list:
				return GetItem(tempOpt.list_map, key).value;
			case Enum::opt_undefined:
			default:
				return "";
		}
	}
	return "";
}
Esempio n. 6
0
bool Editor::importBitmapImage( QString filePath )
{
    backup( tr( "ImportImg" ) );

    QImageReader reader( filePath );

    Q_ASSERT( layers()->currentLayer()->type() == Layer::BITMAP );
    auto layer = static_cast<LayerBitmap*>( layers()->currentLayer() );

    QImage img( reader.size(), QImage::Format_ARGB32_Premultiplied );

    while ( reader.read( &img ) )
    {
        if ( img.isNull() || reader.nextImageDelay() <= 0 )
        {
            break;
        }

        if ( !layer->keyExists( currentFrame() ) )
        {
            addNewKey();
        }
        BitmapImage* bitmapImage = layer->getBitmapImageAtFrame( currentFrame() );

        QRect boundaries = img.rect();
        boundaries.moveTopLeft( mScribbleArea->getCentralPoint().toPoint() - QPoint( boundaries.width() / 2, boundaries.height() / 2 ) );

        BitmapImage* importedBitmapImage = new BitmapImage( boundaries, img );
        bitmapImage->paste( importedBitmapImage );

        scrubTo( currentFrame() + 1 );
    }

    return true;
}
Esempio n. 7
0
std::vector<double> XConf::splitValueDouble( const std::string &key, double def, const xstring &separator ) const {
  if (!keyExists(key)) return std::vector<double>();
  std::vector<xstring> v = getValue(key).split(separator);
  std::vector<double> v2;
  for (int i=0; i<v.size(); ++i)
    v2.push_back( v[i].toDouble(def) );
  return v2;
}
Esempio n. 8
0
bool OptionsWrapper::setSingleOption(const std::string& key, const std::string& value)
{
	Enum::OptionType optType = Enum::opt_undefined;
	if (keyExists(key, Enum::ModOption, false, optType)) {
		return setSingleOptionTypeSwitch(key, value, Enum::ModOption, optType);
	}
	return false;
}
Esempio n. 9
0
Enum::OptionType OptionsWrapper::GetSingleOptionType(const std::string& key) const
{
	Enum::OptionType type = Enum::opt_undefined;
	for (int g = 0; g < Enum::LastOption; g++) {
		if (keyExists(key, (Enum::GameOption)g, false, type))
			return type;
	}
	return Enum::opt_undefined;
}
Esempio n. 10
0
void ArgumentVector::push_back(std::string key, std::string value) {
	if (keyExists(key)) {
		printd(WARNING,
				"ArgumentVector::push_back(): inserting duplicate entry for key %s! First entry will be removed!\n",
				key.c_str());
		arguments.erase(key);
	} // if
	arguments.insert(make_pair(key, Argument(value)));
} // push_back
Esempio n. 11
0
void LayerCamera::loadImageAtFrame( int frameNumber, QTransform view )
{
    if ( keyExists( frameNumber ) )
    {
        removeKeyFrame( frameNumber );
    }
    Camera* camera = new Camera( view );
    camera->setPos( frameNumber );
    addKeyFrame( frameNumber, camera );
}
OptionType OptionsWrapper::GetSingleOptionType ( const wxString& key) const
{
	OptionType type = opt_undefined;
	for ( int g = 0; g < LastOption; g++ )
	{
		if (keyExists(key,(GameOption)g,false,type))
			return type;
	}
	return opt_undefined;
}
Esempio n. 13
0
bool OptionsWrapper::keyExists(const std::string& key) const
{
	bool found = false;
	for (int flag = 0; flag < Enum::PrivateOptions; flag++) {
		Enum::OptionType optType = Enum::opt_undefined;
		found = keyExists(key, (Enum::GameOption)flag, false, optType);
		if (found)
			break;
	}
	return found;
}
Esempio n. 14
0
bool AttrList_replaceItem(AttrList l, String key, int v){
   bool retVal = true;
   
   if(keyExists(l, key)){
      retVal = AttrList_deleteItem(l, key);
   }
   if(retVal){
      retVal = AttrList_setItem(l, key, v);
   }
   return retVal;
}
Esempio n. 15
0
//-------------------------------------------------------------------------
//-- Attach this object to the registry
CTinyCadRegistry::CTinyCadRegistry() :
	CRegistry()
{
	m_oKey.Create(HKEY_CURRENT_USER, M_SKEY);

	// Does the registry information exist - if not create it
	if (!keyExists(M_SPAGESIZE))
	{
		CreateDefaultEntries();
	}
}
bool OptionsWrapper::keyExists( const wxString& key ) const
{
	bool found = false;
	for ( int flag = 0; flag < PrivateOptions; flag++ )
	{
		OptionType optType = opt_undefined;
		found = keyExists( key, (GameOption)flag, false, optType );
		if ( found ) break;
	}
	return found;
}
bool Editor::importBitmapImage( QString filePath )
{
    backup( tr( "ImportImg" ) );
    qDebug(filePath.toLatin1().data());
    QImageReader reader( filePath );

    Q_ASSERT( layers()->currentLayer()->type() == Layer::BITMAP );
    auto layer = static_cast<LayerBitmap*>( layers()->currentLayer() );

    QImage img;//( reader.size(), QImage::Format_ARGB32_Premultiplied );
    img.load(filePath);
    while ( reader.read( &img ) )
    {/*
        if ( img.isNull() || reader.nextImageDelay() <= 0 )
        {
            qDebug("why not image");
            break;
        }*/

        if ( !layer->keyExists( currentFrame() ) )
        {
            qDebug("why not imagesadfsdaf ssd");
            addNewKey();
        }


        BitmapImage* bitmapImage = layer->getBitmapImageAtFrame( currentFrame() );

        QRect boundaries = img.rect();

        boundaries.moveTopLeft( mScribbleArea->getCentralPoint().toPoint() - QPoint( boundaries.width() / 2, boundaries.height() / 2 ) );
        BitmapImage* importedBitmapImage = new BitmapImage( boundaries, img );
        bitmapImage->paste( importedBitmapImage );

      if(layers()->currentLayerIndex()>2)
      {
        //下面用来框出倒入的图片
        mScribbleArea->mySelection.moveTopLeft(mScribbleArea->getCentralPoint().toPoint() - QPoint( boundaries.width()/1.5, boundaries.height()/1.5) );//这个是为了将值赋给QRectF
        mScribbleArea->mySelection.moveBottomRight(mScribbleArea->getCentralPoint().toPoint() + QPoint( boundaries.width()/1.5, boundaries.height()/1.5));
        mScribbleArea->mySelection.setTopLeft(mScribbleArea->getCentralPoint().toPoint() - QPoint( boundaries.width()/1.5, boundaries.height()/1.5));
        mScribbleArea->mySelection.setBottomRight(mScribbleArea->getCentralPoint().toPoint() + QPoint( boundaries.width()/1.5, boundaries.height()/1.5));
        //mScribbleArea->mySelection.moveBottomRight(QPoint( boundaries.width()/2, boundaries.height()/2));
        mScribbleArea->setSelection( mScribbleArea->mySelection, true );
        mScribbleArea->myTransformedSelection = mScribbleArea->mySelection.adjusted( 0, 0, 0, 0 );
        mScribbleArea->myTempTransformedSelection = mScribbleArea->mySelection.adjusted( 0, 0, 0, 0 );
        mScribbleArea->update();
        mScribbleArea->mIncludeImg[mLayerManager->currentLayerIndex()]=mScribbleArea->mySelection;
        tools()->setCurrentTool(MOVE);
       }
       // scrubTo( currentFrame() + 1 );
    }

    return true;
}
Esempio n. 18
0
void LayerVector::loadImageAtFrame(QString path, int frameNumber)
{
    if ( keyExists( frameNumber ) )
    {
        removeKeyFrame( frameNumber, false );
    }
    VectorImage* vecImg = new VectorImage;
    vecImg->setPos( frameNumber );
    vecImg->setObject( object() );
    vecImg->read( path );
    addKeyFrame( frameNumber, vecImg );
}
Esempio n. 19
0
Enum::GameOption OptionsWrapper::GetSection(const std::string& key) const
{
	Enum::GameOption ret = Enum::LastOption;
	bool found = false;
	for (int flag = 0; flag < Enum::PrivateOptions; flag++) {
		Enum::OptionType optType = Enum::opt_undefined;
		found = keyExists(key, (Enum::GameOption)flag, false, optType);
		if (found) {
			ret = (Enum::GameOption)flag;
			break;
		}
	}
	return ret;
}
Esempio n. 20
0
void ConfigFile::extractContents(const std::string &line)
{
    std::string temp = line;
    temp.erase(0, temp.find_first_not_of("\t "));
    size_t sepPos = temp.find('=');

    std::string key, value;
    extractKey(key, sepPos, temp);
    extractValue(value, sepPos, temp);

    if (!keyExists(key))
        contents.insert(std::pair<std::string, std::string > (key, value));
    else
        std::cout << "CFG: Can only have unique key names!\n" << std::endl;
}
Esempio n. 21
0
int LayerManager::LastFrameAtFrame( int frameIndex )
{
    Object* pObj = editor()->object();
    for ( int i = frameIndex; i >= 0; i -= 1 )
    {
        for ( int layerIndex = 0; layerIndex < pObj->getLayerCount(); ++layerIndex )
        {
            auto pLayer = pObj->getLayer( layerIndex );
            if ( pLayer->keyExists( i ) )
            {
                return i;
            }
        }
    }
    return -1;
}
OptionsWrapper::GameOption OptionsWrapper::GetSection( const wxString& key ) const
{
	GameOption ret = LastOption;
	bool found = false;
	for ( int flag = 0; flag < PrivateOptions; flag++ )
	{
		OptionType optType = opt_undefined;
		found = keyExists( key, (GameOption)flag, false, optType );
		if ( found )
		{
			 ret = (GameOption)flag;
			 break;
		}
	}
	return ret;
}
Esempio n. 23
0
std::string OptionsWrapper::GetNameListOptValue(const std::string& key, Enum::GameOption flag) const
{
	Enum::OptionType optType;
	if (keyExists(key, flag, false, optType)) {
		if (optType == Enum::opt_list) {
			GameOptionsMapCIter optIt = m_opts.find((int)flag);
			if (optIt == m_opts.end())
				return "";

			GameOptions tempOpt = optIt->second;
			return ((tempOpt.list_map)[key].cbx_choices[(tempOpt.list_map)[key].cur_choice_index]);
		}
	}
	// at this point retrieval failed
	return "";
}
Esempio n. 24
0
bool OptionsWrapper::setOptions(stringPairVec* options, Enum::GameOption modmapFlag)
{
	for (stringPairVec::const_iterator it = options->begin(); it != options->end(); ++it) {
		std::string key = it->first;
		std::string value = it->second;

		//we don't want to add a key that doesn't already exists
		Enum::OptionType optType = Enum::opt_undefined;
		if (!keyExists(key, modmapFlag, false, optType))
			return false;
		else {
			if (!setSingleOptionTypeSwitch(key, value, modmapFlag, optType))
				return false;
		}
	}
	return true;
}
Esempio n. 25
0
void SpriteManager::addImage(const std::string &key, const char *fname, SDL_Rect r) {
	// check if key exists 
	if (!keyExists(key)) {
		if (fileExists(fname)) {
			SDL_Surface * image = IMG_Load(fname);
			list[key] = Sprite(SDL_CreateTextureFromSurface(renderer, image), r,image->w,image->h);
			SDL_FreeSurface(image);
			log(VERBOSE_LOAD, "LOADED SPRITESHEET %s FROM %s",key.c_str(), fname);
		}
		else {
			log(VERBOSE_ERRORS, "File not found %s", fname);
		}
	}
	else {
		log(VERBOSE_ERRORS, "Repeated sprite key %s", key.c_str());
	}
}
    virtual StatusWith<SpecialFormatInserted> insert(OperationContext* opCtx,
                                                     const BSONObj& key,
                                                     const RecordId& loc,
                                                     bool dupsAllowed) {
        invariant(loc.isValid());
        invariant(!hasFieldNames(key));


        // TODO optimization: save the iterator from the dup-check to speed up insert
        if (!dupsAllowed && keyExists(*_data, key))
            return buildDupKeyErrorStatus(key, _collectionNamespace, _indexName, _keyPattern);

        IndexKeyEntry entry(key.getOwned(), loc);
        if (_data->insert(entry).second) {
            _currentKeySize += key.objsize();
            opCtx->recoveryUnit()->registerChange(new IndexChange(_data, entry, true));
        }
        return StatusWith<SpecialFormatInserted>(SpecialFormatInserted::NoSpecialFormatInserted);
    }
Esempio n. 27
0
void SpriteManager::addText(const std::string &key, const char *text, const SDL_Color &color, int ptsize, const char* fontfile, SDL_Rect r) {
	if (!keyExists(key)) {
		if (fileExists(fontfile)) {
			TTF_Font* font;
			font = TTF_OpenFont(fontfile, ptsize);
			SDL_Surface *image = TTF_RenderText_Blended(font, text, color);
			list[key] = Sprite(SDL_CreateTextureFromSurface(renderer, image), r, image->w, image->h);
			SDL_FreeSurface(image);
			TTF_CloseFont(font);
			log(VERBOSE_LOAD, "LOADED TEXT %s [%s] USING %s", key.c_str(), text, fontfile);
		}
		else {
			log(VERBOSE_ERRORS, "File not found %s", fontfile);
		}
	}
	else {
		log(VERBOSE_ERRORS, "Repeated sprite key %s", key.c_str());
	}
}
Esempio n. 28
0
std::string OptionsWrapper::GetNameListOptItemKey(const std::string& optkey, const std::string& itemname, Enum::GameOption flag) const
{
	Enum::OptionType optType;
	if (keyExists(optkey, flag, false, optType)) {
		if (optType == Enum::opt_list) {
			GameOptionsMapCIter optIt = m_opts.find((int)flag);
			if (optIt == m_opts.end())
				return "";

			GameOptions tempOpt = optIt->second;
			for (ListItemVec::const_iterator it = (tempOpt.list_map)[optkey].listitems.begin(); it != (tempOpt.list_map)[optkey].listitems.end(); ++it) {
				if (it->name == itemname)
					return it->key;
			}
		}
	}

	// at this point retrieval failed
	return "";
}
Esempio n. 29
0
bool Editor::importBitmapImage(QString filePath, int space)
{
    QImageReader reader(filePath);

    Q_ASSERT(layers()->currentLayer()->type() == Layer::BITMAP);
    auto layer = static_cast<LayerBitmap*>(layers()->currentLayer());

    QImage img(reader.size(), QImage::Format_ARGB32_Premultiplied);
    if (img.isNull())
    {
        return false;
    }

    while (reader.read(&img))
    {
        if (!layer->keyExists(currentFrame()))
        {
            addNewKey();
        }
        BitmapImage* bitmapImage = layer->getBitmapImageAtFrame(currentFrame());

        BitmapImage importedBitmapImage(mScribbleArea->getCentralPoint().toPoint() - QPoint(img.width() / 2, img.height() / 2), img);
        bitmapImage->paste(&importedBitmapImage);

        if (space > 1) {
            scrubTo(currentFrame() + space);
        } else {
            scrubTo(currentFrame() + 1);
        }

        backup(tr("Import Image"));

        // Workaround for tiff import getting stuck in this loop
        if (!reader.supportsAnimation())
        {
            break;
        }
    }

    return true;
}
Esempio n. 30
0
std::string OptionsWrapper::getDefaultValue(const std::string& key, Enum::GameOption modmapFlag) const
{
	Enum::OptionType optType = Enum::opt_undefined;
	std::string ret;
	if (keyExists(key, modmapFlag, false, optType)) {
		//purposefully create a copy, no better idea
		GameOptionsMapCIter optIt = m_opts.find((int)modmapFlag);
		if (optIt == m_opts.end())
			return "";

		const GameOptions& tempOpt = optIt->second;
		switch (optType) {
			{
				case Enum::opt_bool:
					ret = Util::ToIntString(GetItem(tempOpt.bool_map, key).def);
					break;
			}
			case Enum::opt_float: {
				ret = Util::ToFloatString(GetItem(tempOpt.float_map, key).def);
				break;
			}
			case Enum::opt_string: {
				ret = GetItem(tempOpt.string_map, key).def;
				break;
			}
			case Enum::opt_list: {
				ret = GetItem(tempOpt.list_map, key).def;
				break;
			}
			default: {
				break;
			}
		}
	}
	return ret;
}