Exemplo n.º 1
0
 public BblAnimation()
 {
     _timer                    = new Timer();
     _timer.Interval           = 0xfffffff;
     _stillStartTimer          = new Timer();
     _stillStartTimer.Interval = 0xfffffff;
     _current                  = new ImageViewingParams();
 }
Exemplo n.º 2
0
 public void SetIvp(string filename, ImageViewingParams value)
 {
     if (_ivps == null)
     {
         throw new InvalidOperationException();
     }
     _ivps[value.filename] = value;
 }
Exemplo n.º 3
0
        public void Harmonize(ref ImageViewingParams harmonize)
        {
            float ratio = rect.Width / rect.Height;
            float test  = harmonize.rect.Width / harmonize.rect.Height;

            if (test != ratio)
            {
                float dif = harmonize.rect.Width - (ratio * harmonize.rect.Height);
                harmonize.l += dif / 2;
                harmonize.r -= dif / 2;
            }
        }
Exemplo n.º 4
0
        //BblAnimType type,
        public void Init(ImageViewingParams start, ImageViewingParams end,
                         BblAnimationTickDelegate tickHandler, int duration, int stillStartDelay = 0, int fps = 0)
        {
            //if (type == BblAnimType.IvpRestoration || _curType != BblAnimType.IvpRestoration)
            //{
            //    if (isRunning && !_current.isReset)
            //    {
            //        EndNow();

            //    }
            //}
            //else
            if (isRunning && !_current.isReset)
            {
                float x = _end.center.X - _current.center.X;
                float y = _end.center.Y - _current.center.Y;

                float hw = (_end.rect.Width - _current.rect.Width) / 2;
                float hh = (_end.rect.Height - _current.rect.Height) / 2;

                start = _current;
                end.Set(end.l + x - hw, end.t + y - hh, end.r + x + hw, end.b + y + hh, end.rotation);
                Reset();
            }

            _start       = start;
            _end         = end;
            _duration    = duration;
            _tickHandler = tickHandler;
            Tick        += tickHandler;

            if (fps <= 0)
            {
                fps = 100;
            }
            _timer.Interval = (int)(1000.0f / (float)fps);
            _timer.Tick    += TimerElapsed;

            _stillStartDelay = stillStartDelay;
            if (stillStartDelay > 0)
            {
                _stillStartTimer.Interval = stillStartDelay;
                _stillStartTimer.Tick    += StillStartElapsed;
            }

            _rotation = _end.rotation - _start.rotation;
            if (_rotation > 180)
            {
                _rotation = -(360 - _rotation);
            }

            _deltaWidth  = _end.rect.Width - _start.rect.Width;
            _deltaHeight = _end.rect.Height - _start.rect.Height;

            float xTrans = _end.center.X - _start.center.X;
            float yTrans = _end.center.Y - _start.center.Y;

            _translation = new Vector2(xTrans, yTrans);

            _frameCount = 0;

            _running = true;

            if (_stillStartDelay > 0)
            {
                Tick(this, _start);
                _stillStartTimer.Start();
            }
            else
            {
                _startTime = DateTime.Now;
                _endTime   = _startTime + new TimeSpan(0, 0, 0, 0, _duration);
                _timer.Start();
            }
        }
Exemplo n.º 5
0
        // This runs on FileSystemWatcher thread
        public bool OnPageFileRenamed(FileInfoEx oldPath, FileInfoEx newPath)
        {
            ImageViewingParams ivp = new ImageViewingParams();

            ivp.Reset();
            BblPage oldPage = null;
            BblPage newPage = null;

            if (IsPopulated)
            {
                oldPage = _pages.Where(x => x.Path == oldPath.FullName).FirstOrDefault();
                ivp     = oldPage.Ivp;
                newPage = new BblPage(this);
                newPage.SetInfo(newPath);


                Application.Current.Dispatcher.BeginInvokeIfRequired(
                    DispatcherPriority.Normal,
                    new Action(() =>
                {
                    lock (_lock) {
                        _pages.Remove(oldPage);
                        int idx = 0;
                        for (; idx < _pages.Count; idx++)
                        {
                            if (Utils.SafeNativeMethods.StrCmpLogicalW(_pages[idx].Filename, newPath.Name) >= 0)
                            {
                                break;
                            }
                        }
                        _pages.Insert(idx, newPage);
                    }
                }));
            }


            if ((ivp != null && ivp.isDirty) || (_ivps != null && _ivps.TryGetValue(oldPath.Name, out ivp)))
            {
                ivp.filename = newPath.Name;
                if (newPage != null)
                {
                    lock (newPage._lock) newPage.Ivp = ivp;
                }
                if (_ivps != null)
                {
                    _ivps.Remove(oldPath.Name);
                    if (!_ivps.ContainsKey(newPath.Name))
                    {
                        try  { _ivps.Add(newPath.Name, ivp); }
                        catch (System.ArgumentException e)
                        {
                            if ((UInt32)e.HResult != 0x80070057)
                            {
                                Console.WriteLine(e.Message);
                            }
                        }
                        catch (Exception x) { Console.WriteLine(x.Message); }
                    }
                }
            }

            return(false);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Restore image viewing parameters from
        /// serialized file.
        /// </summary>
        public virtual void DeserializeIVP()
        {
            if (_ivps != null)
            {
                throw new InvalidOperationException();
            }

            lock (_lock) {
                _ivps = new Dictionary <string, ImageViewingParams>();
                foreach (var p in _pages)
                {
                    ImageViewingParams ivp = new ImageViewingParams();
                    ivp.filename = p.Filename;
                    if (!_ivps.ContainsKey(p.Filename))
                    {
                        _ivps.Add(p.Filename, ivp);
                    }
                }
            }

            if (File.Exists(IvpPath))
            {
                var           deserializer = new System.Xml.Serialization.XmlSerializer(typeof(IvpCollection));
                TextReader    reader       = null;
                IvpCollection XmlData      = null;
                object        obj          = null;

                try
                {
                    reader = new StreamReader(IvpPath);
                    obj    = deserializer.Deserialize(reader);
                }
                catch
                {
                    if (reader != null)
                    {
                        reader.Close();
                    }
                    reader = null;
                    File.Delete(IvpPath);
                }
                finally
                {
                    if (obj != null)
                    {
                        XmlData = (IvpCollection)obj;
                    }
                    List <ImageViewingParams> ivps = null;
                    if (XmlData != null)
                    {
                        ivps = new List <ImageViewingParams>(XmlData.Collection);
                    }
                    if (reader != null)
                    {
                        reader.Close();
                    }

                    if (ivps != null)
                    {
                        lock (_lock)
                        {
                            foreach (var ivp in ivps)
                            {
                                if (ivp.filename == null)
                                {
                                    continue;
                                }
                                _ivps[ivp.filename] = ivp;
                            }
                        }
                    }
                }
            }
        }