Exemple #1
0
        private void SelectionTimer_Tick(object sender, System.EventArgs e)
        {
            if (this.IsDisposed || this.ownerControl.IsDisposed)
            {
                return;
            }

            if (this.selectedPath == null || this.selectedPath.IsEmpty)
            {
                this.selectionTimer.Enabled = false;
                return;
            }

            if (!this.enableOutlineAnimation)
            {
                return;
            }

            if (this.timer.GetTickCountDouble() < this.coolOffTimeTickCount)
            {
                return;
            }

            if (this.ownerControl != null && this.ownerControl.IsMouseCaptured())
            {
                return;
            }

            int presentTickMod = (int)((Utility.GetTimeMs() / dancingAntsInterval) % 2);

            if (presentTickMod != lastTickMod)
            {
                lastTickMod  = presentTickMod;
                dancingAntsT = unchecked (dancingAntsT + 1);

                if (this.simplifiedRegionForTimer == null)
                {
                    using (PdnGraphicsPath invalidPath = (PdnGraphicsPath)selectedPath.Clone())
                    {
                        invalidPath.CloseAllFigures();

                        float ratio         = 1.0f / (float)OwnerList.ScaleFactor.Ratio;
                        int   inflateAmount = (int)Math.Ceiling(ratio);

                        this.simplifiedRegionForTimer = Utility.SimplifyTrace(invalidPath, 50);
                        Utility.InflateRectanglesInPlace(this.simplifiedRegionForTimer, inflateAmount);
                    }
                }

                try
                {
                    foreach (Rectangle rect in this.simplifiedRegionForTimer)
                    {
                        Invalidate(rect);
                    }
                }

                catch (ObjectDisposedException)
                {
                    try
                    {
                        this.selectionTimer.Enabled = false;
                    }

                    catch (Exception)
                    {
                        // Ignore error
                    }
                }

                if (this.ownerControl == null || (this.ownerControl != null && !this.ownerControl.IsMouseCaptured()))
                {
                    whiteOpacity = Math.Min(whiteOpacity + 16, 255);
                }
            }

            // If it takes "too long" to render the dancing ants, then we institute
            // a cooling-off period during which we will not render the ants.
            // This will curb the CPU usage by a few percent, which will avoid us
            // monopolizing the CPU.
            double maxRenderTime = (double)dancingAntsInterval * maxCpuTime;

            if (renderTime > maxRenderTime)
            {
                double coolOffTime = renderTime / maxRenderTime;
                this.coolOffTimeTickCount = timer.GetTickCountDouble() + coolOffTime;
            }

            this.renderTime = 0.0;
        }