Click here to Skip to main content
15,887,485 members
Articles / Desktop Programming / WPF

C.B.R.

Rate me:
Please Sign up or sign in to vote.
4.96/5 (52 votes)
22 Oct 2012GPL329 min read 124.4K   1.8K   132  
Comic and electronic publication reader with library management, extended file conversion, and devices support.
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using CBR.Core.Helpers;
using CBR.Core.Models;
using CBR.Core.Services;

namespace CBR.Views
{
    /// <summary>
    /// Interaction logic for SimulateView.xaml
    /// </summary>
    public partial class SimulateView : Window
    {
        public SimulateView()
        {
            InitializeComponent();

            IsLandscape = true;

            //create a dispatch timer to load the image cache
            _TimeLineClock = new DispatcherTimer();
            _TimeLineClock.Interval = new TimeSpan(0, 0, 2);
            _TimeLineClock.IsEnabled = true;
            _TimeLineClock.Tick += new EventHandler(TimeLineClockElapsed);
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            _currentPage = BookData.Pages[0];
            _currentZone = null;
            _DurationCounter = 0;
        }

        public Book BookData { get; set; }

        internal Page _currentPage;
        internal Zone _currentZone;
        internal int _DurationCounter = 0;

        public bool IsLandscape { get; set; }

        private DispatcherTimer _TimeLineClock;

        private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }

        private void btnSwapLandscape_Click(object sender, RoutedEventArgs e)
        {
            if (IsLandscape)
            {
                this.mainGrid.LayoutTransform = new RotateTransform(90, 0.5, 0.5);
            }
            else
            {
                this.mainGrid.LayoutTransform = null;
            }
            
            IsLandscape = !IsLandscape;

            double previous = this.ActualWidth;
            this.Width = this.ActualHeight;
            this.Height = previous;
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            _TimeLineClock.Stop();
            _TimeLineClock.IsEnabled = false;
            
            this.Close();
        }

        public void TimeLineClockElapsed(object tag, EventArgs args)
        {
            try
            {

                //retreive the image brush
                ImageBrush imageBrush = (ImageBrush)rctZoom.Fill;
                
                //increase timer duration
                _DurationCounter += 2;

                Page oldPage = _currentPage;
                Zone oldFrame = _currentZone;

                // if no frame stored or duration is over, search the new frame in the page
                if (_currentZone == null || _DurationCounter > _currentZone.Duration)
                    BookServiceFactory.Instance.GetService(BookData).GotoFrame(BookData, ref _currentPage, ref _currentZone, 1);

                //we change the page, so change the image
                if( oldPage != _currentPage)
                {
                    imageBrush.ImageSource = _currentPage.Image;
                }

                //we change the zone, so change the parameters
                if (oldFrame != _currentZone)
                {
                    Rect viewBox = imageBrush.Viewbox;
                    viewBox.X = _currentZone.X;
                    viewBox.Y = _currentZone.Y;
                    viewBox.Width = _currentZone.Width;
                    viewBox.Height = _currentZone.Height;
                    imageBrush.Viewbox = viewBox;

                    lblDebugInfo.Content = string.Format("Frame {0} for {1} second(s) on location ({2}, {3}, {4}, {5}) ",
                        _currentZone.OrderNum, _currentZone.Duration, _currentZone.X, _currentZone.Y, _currentZone.Width, _currentZone.Height);
                }
            }
            catch (Exception err)
            {
                ExceptionHelper.Manage("SimulateView:TimeLineClockElapsed", err);
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Architect
France France
WPF and MVVM fan, I practice C # in all its forms from the beginning of the NET Framework without mentioning C ++ / MFC and other software packages such as databases, ASP, WCF, Web & Windows services, Application, and now Core and UWP.
In my wasted hours, I am guilty of having fathered C.B.R. and its cousins C.B.R. for WinRT and UWP on the Windows store.
But apart from that, I am a great handyman ... the house, a rocket stove to heat the jacuzzi and the last one: a wood oven for pizza, bread, and everything that goes inside

https://guillaumewaser.wordpress.com/
https://fouretcompagnie.wordpress.com/

Comments and Discussions