1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SLMitsuControls;
using System.Windows.Media.Imaging;
using System.Windows.Browser;
using System.ComponentModel;
using System.Threading;
using System.Windows.Threading;
namespace SLBookDemoApp
{
public partial class Page : UserControl, IDataProvider
{
private List<Button> pages;
private List<Image> images;
private List<Image> lstImg;
private Int32 temps = 500;
String strPDF;
String pdfPlaquette;
String pdfCommunication;
String pdfAchat;
String pdfRH;
private IDictionary<String, String> _parameters = null;
private bool _dragging = false; // True when magnifying
private const double _scale = 4.0; // Scale factor
private double _radius = 160.0; // Radius of lens
private Image _image; // Magnified image
private EllipseGeometry _lens; // Clipping region
private EllipseGeometry _border; // Lens border
private Path _path; // Path representing lens border
public Page(IDictionary<String, String> p)
{
this._parameters = p;
InitializeComponent();
pages = new List<Button>();
images = new List<Image>();
lstImg = new List<Image>();
Int32 nbParameter = _parameters.Count();
if (nbParameter != 0)
{
temps = Int32.Parse(_parameters["temps"].ToString());
pdfPlaquette = _parameters["pdf0"].ToString();
if (String.IsNullOrEmpty(pdfPlaquette))
btnPlaquette.Visibility = System.Windows.Visibility.Collapsed;
else
btnPlaquette.Visibility = System.Windows.Visibility.Visible;
pdfCommunication = _parameters["pdf1"].ToString();
if (String.IsNullOrEmpty(pdfCommunication))
btnFicheCommunication.Visibility = System.Windows.Visibility.Collapsed;
else
btnFicheCommunication.Visibility = System.Windows.Visibility.Visible;
pdfAchat = _parameters["pdf2"].ToString();
if (String.IsNullOrEmpty(pdfAchat))
btnAchat.Visibility = System.Windows.Visibility.Collapsed;
else
btnAchat.Visibility = System.Windows.Visibility.Visible;
pdfRH = _parameters["pdf3"].ToString();
if (String.IsNullOrEmpty(pdfRH))
btnRH.Visibility = System.Windows.Visibility.Collapsed;
else
btnRH.Visibility = System.Windows.Visibility.Visible;
Image img;
foreach (KeyValuePair<String, String> item in _parameters)
{
if (item.Key.Contains("page") == true)
{
//lblParametres.Text += item.Key + " => " + item.Value + "\r\n";
img = new Image();
BitmapImage bi3 = new BitmapImage();
bi3.UriSource = new Uri("http://www.monSite.fr/upload/plaquette/" + item.Value, UriKind.Absolute);
img.Stretch = Stretch.Fill;
img.Source = bi3;
lstImg.Add(img);
}
}
}
// Create a magnified image for zooming
_image = new Image();
_image.Width = MainCanvas.Width * _scale;
_image.Height = MainCanvas.Height * _scale;
_image.Visibility = Visibility.Collapsed;
// Render the main Canvas into the image at _scale times its nominal size
WriteableBitmap bitmap = new WriteableBitmap((int)_image.Width, (int)_image.Height);
ScaleTransform transform = new ScaleTransform();
transform.ScaleX = transform.ScaleY = _scale;
bitmap.Render(MainCanvas, transform);
bitmap.Invalidate();
_image.Source = bitmap;
// Apply a clipping region to the magnified image
_lens = new EllipseGeometry();
_lens.RadiusX = _lens.RadiusY = _radius;
_image.Clip = _lens;
// Add the magnified image to the XAML DOM
MainCanvas.Children.Add(_image);
// Create a Path to represent the edge of the lens
_border = new EllipseGeometry();
_border.RadiusX = _border.RadiusY = _radius;
_path = new Path();
_path.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x80, 0x80, 0x80));
_path.StrokeThickness = 1.0;
_path.Data = _border;
_path.Visibility = Visibility.Collapsed;
// Add the Path to the XAML DOM
MainCanvas.Children.Add(_path);
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
Button btn;
foreach (Image item in lstImg)
{
btn = new Button();
btn.Content = item;
pages.Add(btn);
}
int i = 0;
foreach (var b in pages)
{
if (i % 2 == 0)
b.Click += Button_Click;
else
b.Click += Button_Click_1;
i++;
}
book.SetData(this);
}
#region IDataProvider Members
public object GetItem(int index)
{
return pages[index];
}
public int GetCount()
{
return pages.Count;
}
#endregion
private void Button_Click(object sender, RoutedEventArgs e)
{
book.AnimateToNextPage(temps);
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
book.AnimateToPreviousPage(temps);
}
private void btnNext_Click(object sender, RoutedEventArgs e)
{
book.AnimateToNextPage(temps);
}
private void bntPrevious_Click(object sender, RoutedEventArgs e)
{
book.AnimateToPreviousPage(temps);
}
private void btnFicheCommunication_Click(object sender, RoutedEventArgs e)
{
HtmlPage.Window.Navigate(new Uri("http://www.monSite.fr/upload/plaquette/" + pdfCommunication), "_blank");
}
private void btnPlaquette_Click(object sender, RoutedEventArgs e)
{
HtmlPage.Window.Navigate(new Uri("http://www.monSite.fr/upload/plaquette/" + pdfPlaquette), "_blank");
}
private void btnAchat_Click(object sender, RoutedEventArgs e)
{
HtmlPage.Window.Navigate(new Uri("http://www.monSite.fr/upload/plaquette/" + pdfAchat), "_blank");
}
private void btnRH_Click(object sender, RoutedEventArgs e)
{
HtmlPage.Window.Navigate(new Uri("http://www.monSite.fr/upload/plaquette/" + pdfRH), "_blank");
}
private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
double x = e.GetPosition(MainCanvas).X;
double y = e.GetPosition(MainCanvas).Y;
// Display the magnifying glass if the cursor is inside the Canvas
if (x > 0.0 || x < MainCanvas.Width || y > 0.0 || y < MainCanvas.Height)
{
PositionLens(x, y);
_image.Visibility = Visibility.Visible;
_path.Visibility = Visibility.Visible;
((FrameworkElement)sender).CaptureMouse();
_dragging = true;
}
}
private void OnMouseMove(object sender, MouseEventArgs e)
{
if (_dragging)
{
double x = e.GetPosition(MainCanvas).X;
double y = e.GetPosition(MainCanvas).Y;
// Hide the magnifying glass if the cursor has left the Canvas
if (x < 0.0 || x > MainCanvas.Width || y < 0.0 || y > MainCanvas.Height)
{
_image.Visibility = Visibility.Collapsed;
_path.Visibility = Visibility.Collapsed;
((FrameworkElement)sender).ReleaseMouseCapture();
_dragging = false;
}
else
PositionLens(x, y);
}
}
private void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
// Hide the magnifying glass when the mouse button is released
if (_dragging)
{
_image.Visibility = Visibility.Collapsed;
_path.Visibility = Visibility.Collapsed;
((FrameworkElement)sender).ReleaseMouseCapture();
_dragging = false;
}
}
private void PositionLens(double x, double y)
{
_lens.Center = new Point(x * _scale, y * _scale);
_border.Center = new Point(x, y);
_image.SetValue(Canvas.LeftProperty, (1 - _scale) * x);
_image.SetValue(Canvas.TopProperty, (1 - _scale) * y);
}
}
} |