using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using Telerik.Windows.Controls;
using Telerik.Windows.Media.Imaging.Tools;
using Telerik.Windows.Media.Imaging.Tools.UI;

namespace Drawing
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            this.LoadSampleImage(this.imageEditor, "RadImageEditor.png");

            this.Loaded += (s, e) =>
            {
                var pane = this.imageEditor.ChildrenOfType<InlineToolSettingsPane>().FirstOrDefault();
                pane.Opacity = 0;
                pane.Margin = new Thickness(-500, 0, 0, 0);
                imageEditor.ExecuteTool(new DrawTool());
            };
        }

        private string SampleImageFolder = "Images/";

        public void LoadSampleImage(RadImageEditor imageEditor, string image)
        {
            using (Stream stream = Application.GetResourceStream(GetResourceUri(SampleImageFolder + image)).Stream)
            {
                imageEditor.Image = new Telerik.Windows.Media.Imaging.RadBitmap(stream);
                imageEditor.ApplyTemplate();
            }

            
        }

        public static Uri GetResourceUri(string resource)
        {
            AssemblyName assemblyName = new AssemblyName(typeof(MainPage).Assembly.FullName);
            string resourcePath = "/" + assemblyName.Name + ";component/" + resource;
            Uri resourceUri = new Uri(resourcePath, UriKind.Relative);

            return resourceUri;
        }
    }
}
