void KeyFrameAnimation::Update(float deltaTime) {
    if (HasEnded()) return;

    currentTime += deltaTime;

    currentFrame = GetCurrentKeyFrame(currentFrame);    

    if (currentFrame == keyFrames.size() - 1) {
        currentRepeat++;
        if (HasEnded()) {
            currentFrame--; // step to the last frame (vs return)
        }
        else {
            currentTime = std::fmod(currentTime, keyFrames[currentFrame].time); // or = 0 for animation reset on repeat
            currentFrame = GetCurrentKeyFrame(0);
        }
    }

    KeyFrame& first  = keyFrames[currentFrame    ];
    KeyFrame& second = keyFrames[currentFrame + 1];
    
    float amount = GetTransition(first, second);

    DoLerp(first, second, amount);
}
Beispiel #2
0
void TextRenderer::OnButtonPressEvent(GdkEventButton* event)
{
    if( event->type != GDK_BUTTON_PRESS || !IsLeftButton(event) )
        return;

    Point lct((int)event->x, (int)event->y);
    lct = GetTransition().DevToRel(lct);
    if( CalcTextPlc().Contains(lct) )
    {
        double x = lct.x, y = lct.y;
        {
            CairoStateSave save(caiCont);
            ApplyTextTrans();

            caiCont->device_to_user(x, y);
        }

        int idx, trail;
        utf8::trans tr(GetText());
        if( panLay->xy_to_index(pango_units_from_double(x), pango_units_from_double(y), idx, trail) )
        {
            int new_pos = tr.to_offset(idx);
            // видимо в случае "сложных" букв trail может принимать и отличные от
            // {0, 1} значения (восточные иероглифы?), но нам требуется точность до целого символа
            if( trail )
                new_pos++;

            MoveCursor( new_pos );
        }
        else
            MoveCursor( tr.length() );
    }
}
Beispiel #3
0
//GetPeaksInOneChrom2: strand-sensitive mode: get peak location from tags for one chromosome
int GetPeaksInOneChrom2(CHROM_INFO *chrom, double l1Ratio, double l2Ratio, int *maxL1Count, int *maxL2Count, CONFIG_STRUCT config)
{
	int i;
	int *profile1,*profile2, *rsProfile1, *rsProfile2, *diffProfile1, *diffProfile2;
	int profileLen = (chrom->chromSize)/config.movingStep+1;
	int tmpIndex;
	PEAK_STRUCT *tmpPeaks;
	int tmpPeakNum;
	int minDist; 

	//allocate memory for the profile
	profile1 = (int *)malloc(profileLen*sizeof(int));
	profile2 = (int *)malloc(profileLen*sizeof(int));
	rsProfile1 = (int *)malloc(profileLen*sizeof(int));
	rsProfile2 = (int *)malloc(profileLen*sizeof(int));
	diffProfile1 = (int *)malloc(profileLen*sizeof(int));
	diffProfile2 = (int *)malloc(profileLen*sizeof(int));

	if ((!profile1)||(!profile2)||(!rsProfile1)||(!rsProfile2)||(!diffProfile1)||(!diffProfile2))
	{
		printf("not enough memory!\n");
		return -1;
	}

	memset(profile1, 0, profileLen*sizeof(int));
	memset(profile2, 0, profileLen*sizeof(int));
	memset(rsProfile1, 0, profileLen*sizeof(int));
	memset(rsProfile2, 0, profileLen*sizeof(int));
	memset(diffProfile1, 0, profileLen*sizeof(int));
	memset(diffProfile2, 0, profileLen*sizeof(int));

	//generate profile, assign reads from both ChIP and control libraries to the profile. Reads are re-sampled based on noise rate

	for (i=0;i<chrom->l1PosTagNum;i++)
	{
		if (chrom->l1PosTags[i]>=chrom->chromSize)
		{
			break;
		}

		tmpIndex = (chrom->l1PosTags[i]+config.fragmentSize/2)/config.movingStep;

		tmpIndex = tmpIndex<0?0:tmpIndex;
		tmpIndex = tmpIndex>=profileLen?profileLen-1:tmpIndex;

		profile1[tmpIndex]++;

		if (rand()>RAND_MAX*l1Ratio)
		{
			continue;
		}

		rsProfile1[tmpIndex]++;

		tmpIndex = (chrom->l1PosTags[i])/config.movingStep;

		tmpIndex = tmpIndex<0?0:tmpIndex;
		tmpIndex = tmpIndex>=profileLen?profileLen-1:tmpIndex;

		diffProfile1[tmpIndex]++;
	}

	for (i=0;i<chrom->l1NegTagNum;i++)
	{
		if (chrom->l1NegTags[i]>=chrom->chromSize)
		{
			break;
		}

		tmpIndex = (chrom->l1NegTags[i]-config.fragmentSize/2)/config.movingStep;

		tmpIndex = tmpIndex<0?0:tmpIndex;
		tmpIndex = tmpIndex>=profileLen?profileLen-1:tmpIndex;

		profile1[tmpIndex]++;

		if (rand()>RAND_MAX*l1Ratio)
		{
			continue;
		}

		rsProfile1[tmpIndex]++;

		tmpIndex = (chrom->l1NegTags[i])/config.movingStep;

		tmpIndex = tmpIndex<0?0:tmpIndex;
		tmpIndex = tmpIndex>=profileLen?profileLen-1:tmpIndex;
		diffProfile1[tmpIndex]--;
	}

	for (i=0;i<chrom->l2PosTagNum;i++)
	{
		if (chrom->l2PosTags[i]>=chrom->chromSize)
		{
			break;
		}

		tmpIndex = (chrom->l2PosTags[i]+config.fragmentSize/2)/config.movingStep;

		tmpIndex = tmpIndex<0?0:tmpIndex;
		tmpIndex = tmpIndex>=profileLen?profileLen-1:tmpIndex;

		profile2[tmpIndex]++;

		if (rand()>RAND_MAX*l2Ratio)
		{
			continue;
		}

		rsProfile2[tmpIndex]++;
		
		tmpIndex = (chrom->l2PosTags[i])/config.movingStep;

		tmpIndex = tmpIndex<0?0:tmpIndex;
		tmpIndex = tmpIndex>=profileLen?profileLen-1:tmpIndex;
		diffProfile2[tmpIndex]++;
	}

	for (i=0;i<chrom->l2NegTagNum;i++)
	{
		if (chrom->l2NegTags[i]>=chrom->chromSize)
		{
			break;
		}

		tmpIndex = (chrom->l2NegTags[i]-config.fragmentSize/2)/config.movingStep;

		tmpIndex = tmpIndex<0?0:tmpIndex;
		tmpIndex = tmpIndex>=profileLen?profileLen-1:tmpIndex;

		profile2[tmpIndex]++;

		if (rand()>RAND_MAX*l2Ratio)
		{
			continue;
		}

		rsProfile2[tmpIndex]++;

		tmpIndex = (chrom->l2NegTags[i])/config.movingStep;

		tmpIndex = tmpIndex<0?0:tmpIndex;
		tmpIndex = tmpIndex>=profileLen?profileLen-1:tmpIndex;
		diffProfile2[tmpIndex]--;
	}

	SmoothProfile(profile1, profileLen, config.slidingWinSize/config.movingStep/2);

	SmoothProfile(profile2, profileLen, config.slidingWinSize/config.movingStep/2);

	SmoothProfile(rsProfile1, profileLen, config.slidingWinSize/config.movingStep/2);

	SmoothProfile(rsProfile2, profileLen, config.slidingWinSize/config.movingStep/2);

	SmoothProfile(diffProfile1, profileLen, TRANSITION_SIZE/config.movingStep/2);

	SmoothProfile(diffProfile2, profileLen, TRANSITION_SIZE/config.movingStep/2);

	for (i=0;i<profileLen;i++)
	{
		if (profile1[i]>*maxL1Count)
		{
			*maxL1Count = profile1[i];
		}

		if (profile2[i]>*maxL2Count)
		{
			*maxL2Count = profile2[i];
		}
	}

	//find peaks from profile

	tmpPeaks = (PEAK_STRUCT *)malloc(((chrom->chromSize)/config.movingStep+1)*sizeof(PEAK_STRUCT));

	if (!tmpPeaks)
	{
		printf("not enough memory!\n");
		return -1;
	}

	minDist = config.slidingWinSize/config.movingStep+1;

	tmpPeakNum = GetTransition(diffProfile1,profileLen,tmpPeaks,minDist);

	chrom->l1PeakNum = 0;

	
	for (i=0;i<tmpPeakNum;i++)
	{
		tmpPeaks[i].l1Count = profile1[tmpPeaks[i].peak];
		tmpPeaks[i].l2Count = profile2[tmpPeaks[i].peak];
		tmpPeaks[i].reSampledL1Count = rsProfile1[tmpPeaks[i].peak];
		tmpPeaks[i].reSampledL2Count = rsProfile2[tmpPeaks[i].peak];

		if ((tmpPeaks[i].reSampledL1Count>=config.minCount))
		{
			(chrom->l1PeakNum) ++;
		}
	}

	if (chrom->l1PeakNum<=0)
	{
		free(profile1);
		free(profile2);
		free(rsProfile1);
		free(rsProfile2);
		free(diffProfile1);
		free(diffProfile2);
		free(tmpPeaks);
		return 0;
	}

	chrom->l1Peaks = (PEAK_STRUCT *)malloc((chrom->l1PeakNum)*sizeof(PEAK_STRUCT));

	if (!(chrom->l1Peaks))
	{
		free(profile1);
		free(profile2);
		free(rsProfile1);
		free(rsProfile2);
		free(diffProfile1);
		free(diffProfile2);
		printf("not enough memory!\n");
		return -1;
	}

	chrom->l1PeakNum = 0;

	for (i=0;i<tmpPeakNum;i++)
	{
		if (tmpPeaks[i].reSampledL1Count>=config.minCount)
		{
			memcpy(chrom->l1Peaks+chrom->l1PeakNum, tmpPeaks+i,sizeof(PEAK_STRUCT));
			(chrom->l1PeakNum) ++;
		}
	}

	tmpPeakNum = GetTransition(diffProfile2,profileLen,tmpPeaks,minDist);

	chrom->l2PeakNum = 0;

	for (i=0;i<tmpPeakNum;i++)
	{
		tmpPeaks[i].l1Count = profile2[tmpPeaks[i].peak];
		tmpPeaks[i].l2Count = profile1[tmpPeaks[i].peak];
		tmpPeaks[i].reSampledL1Count = rsProfile2[tmpPeaks[i].peak];
		tmpPeaks[i].reSampledL2Count = rsProfile1[tmpPeaks[i].peak];

		if ((tmpPeaks[i].reSampledL1Count>=config.minCount))
		{
			(chrom->l2PeakNum) ++;
		}
	}

	if (chrom->l2PeakNum<=0)
	{
		free(profile1);
		free(profile2);
		free(rsProfile1);
		free(rsProfile2);
		free(diffProfile1);
		free(diffProfile2);
		free(tmpPeaks);
		return 0;
	}

	chrom->l2Peaks = (PEAK_STRUCT *)malloc((chrom->l2PeakNum)*sizeof(PEAK_STRUCT));

	if (!(chrom->l2Peaks))
	{
		free(profile1);
		free(profile2);
		free(rsProfile1);
		free(rsProfile2);
		free(diffProfile1);
		free(diffProfile2);
		printf("not enough memory!\n");
		return -1;
	}

	chrom->l2PeakNum = 0;

	for (i=0;i<tmpPeakNum;i++)
	{
		if (tmpPeaks[i].reSampledL1Count>=config.minCount)
		{
			memcpy(chrom->l2Peaks+chrom->l2PeakNum, tmpPeaks+i,sizeof(PEAK_STRUCT));
			(chrom->l2PeakNum) ++;
		}
	}

	free(profile1);
	free(profile2);
	free(rsProfile1);
	free(rsProfile2);
	free(diffProfile1);
	free(diffProfile2);
	free(tmpPeaks);

	return chrom->l1PeakNum;
}
Beispiel #4
0
void SUIAnimation::Update( float timeDelta )
{
	SUITransition::Update(timeDelta);

	if (state == Hidden)
	{
		return;
	}

	if (endPoint.x)
	{
		if (!currentPoint.x)
		{
			currentPoint.x = new int(*startPoint.x);
		}
		*currentPoint.x = 
			(*endPoint.x - *startPoint.x) * 
			GetTransition() + *startPoint.x;
	}

	if (endPoint.y)
	{
		if (!currentPoint.y)
		{
			currentPoint.y = new int(*startPoint.y);
		}
		*currentPoint.y =
			(*endPoint.y - *startPoint.y) * 
			GetTransition() + *startPoint.y;
	}

	if (endPoint.width)
	{
		if (!currentPoint.width)
		{
			currentPoint.width = new int(*startPoint.width);
		}
		*currentPoint.width =
			(*endPoint.width - *startPoint.width) * 
			GetTransition() + *startPoint.width;
	}

	if (endPoint.height)
	{
		if (!currentPoint.height)
		{
			currentPoint.height = new int(*startPoint.height);
		}
		*currentPoint.height =
			(*endPoint.height - *startPoint.height) * 
			GetTransition() + *startPoint.height;
	}
	
	if (endPoint.rotation)
	{
		if (!currentPoint.rotation)
		{
			currentPoint.rotation = new float(*startPoint.rotation);
		}
		*currentPoint.rotation = 
			(*endPoint.rotation - *startPoint.rotation) * 
			GetTransition() + *startPoint.rotation;
	}

	if (endPoint.rotationCenterX)
	{
		if (!currentPoint.rotationCenterX)
		{
			currentPoint.rotationCenterX = new float(*startPoint.rotationCenterX);
		}
		*currentPoint.rotationCenterX = 
			(*endPoint.rotationCenterX - *startPoint.rotationCenterX) *
			GetTransition() + *startPoint.rotationCenterX;
	}

	if (endPoint.rotationCenterY)
	{
		if (!currentPoint.rotationCenterY)
		{
			currentPoint.rotationCenterY = new float(*startPoint.rotationCenterY);
		}
		*currentPoint.rotationCenterY = 
			(*endPoint.rotationCenterY - *startPoint.rotationCenterY) *
			GetTransition() + *startPoint.rotationCenterY;
	}
	
	if (endPoint.transparency)
	{
		if (!currentPoint.transparency)
		{
			currentPoint.transparency = new float(*startPoint.transparency);
		}
		*currentPoint.transparency = 
			(*endPoint.transparency - *startPoint.transparency) *
			GetTransition() + *startPoint.transparency;
	}

	if (endPoint.backgroundX)
	{
		if (!currentPoint.backgroundX)
		{
			currentPoint.backgroundX = new int(*startPoint.backgroundX);
		}
		*currentPoint.backgroundX = 
			(*endPoint.backgroundX - *startPoint.backgroundX) *
			GetTransition() + *startPoint.backgroundX;
	}

	if (endPoint.backgroundY)
	{
		if (!currentPoint.backgroundY)
		{
			currentPoint.backgroundY = new int(*startPoint.backgroundY);
		}
		*currentPoint.backgroundY = 
			(*endPoint.backgroundY - *startPoint.backgroundY) *
			GetTransition() + *startPoint.backgroundY;
	}

	if (endPoint.backgroundColor)
	{
		if (!currentPoint.backgroundColor)
		{
			currentPoint.backgroundColor = new D3DCOLOR(*startPoint.backgroundColor);
		}
		*currentPoint.backgroundColor = GetTransition() * 
			(*endPoint.backgroundColor - *startPoint.backgroundColor) + *startPoint.backgroundColor;
	}
	
	if (endPoint.layer)
	{
		if (!currentPoint.layer)
		{
			currentPoint.layer = new float(*startPoint.layer);
		}
		*currentPoint.layer = GetTransition() * (*endPoint.layer - *startPoint.layer)
			+ *startPoint.layer;	
	}
	

	if (state == Active)
	{
		//currentPoint.backgroundImage = endPoint.backgroundImage;
		//currentPoint.backgroundMode = endPoint.backgroundMode;
		//currentPoint.backgroundPosition = endPoint.backgroundPosition;
		return;
	}
	else
	{
		//currentPoint.backgroundImage = startPoint.backgroundImage;
		//currentPoint.backgroundMode = startPoint.backgroundMode;
		//currentPoint.backgroundPosition = startPoint.backgroundPosition;
	}
}
Beispiel #5
0
Rect TextRenderer::CalcTextPlc()
{
    return RelPos(GetTextObj(), GetTransition());
}