-
Notifications
You must be signed in to change notification settings - Fork 0
/
BigPicture.xaml.cs
248 lines (213 loc) · 8.14 KB
/
BigPicture.xaml.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
namespace search3D
{
/// <summary>
/// Interaction logic for BigPicture.xaml
/// </summary>
public partial class BigPicture : UserControl
{
public delegate void CallbackAtEnd();
s3dCore.SearchEngines.ISearchElement contentElement;
BitmapImage imageToSave = null;
RotateTransform imageRotation = null;
public CallbackAtEnd AtEnd;
public BigPicture()
{
InitializeComponent();
this.Background = Brushes.Black;
this.Visibility = Visibility.Collapsed;
loadingProgress.Visibility = Visibility.Collapsed;
imageRotation = new RotateTransform();
imageRotation.CenterX = 0.5;
imageRotation.CenterY = 0.5;
imageRotation.Angle = 0;
}
public void SetContent(s3dCore.SearchEngines.ISearchElement element)
{
imageRotation.Angle = 0;
Brush brush = element.GetFullQualityBrush();
if (element.GetElementType() == s3dCore.SearchEngines.SearchElementType.etImage)
{
ImageBrush brushTemp = brush as ImageBrush;
if (brushTemp.ImageSource is BitmapImage)
{
imageToSave = brushTemp.ImageSource as BitmapImage;
imagePanel.Visibility = Visibility.Visible;
}
else
{
throw new Exception("brush is not image!");
}
imagePanel.Visibility = Visibility.Visible;
browser.Visibility = Visibility.Collapsed;
content.Background = brush;
element.SetOnProgressDelegate(OnImageProgress);
}
else
{
imagePanel.Visibility = Visibility.Collapsed;
if (element.GetElementType() == s3dCore.SearchEngines.SearchElementType.etVideo)
{
content.Visibility = Visibility.Collapsed;
browser.Visibility = Visibility.Visible;
browser.Navigate(new Uri(element.GetFullContentUlr(), UriKind.RelativeOrAbsolute));
}
}
contentElement = element;
labelContentTitle.Content = element.GetLabel();
}
public void FadeIn(double seconds)
{
this.Visibility = Visibility.Visible;
errorLabel.Visibility = Visibility.Collapsed;
Helper.ShowAndFadeIn(this, seconds);
HelpSystem.GlobalSystem.ShowHelp("double click to return to search mode", 2);
}
public void FadeOut(double seconds)
{
if (browser.Visibility == Visibility.Visible)
{
browser.Source = null;
browser.Visibility = Visibility.Collapsed;
}
if (contentElement != null)
{
imageToSave = null;
contentElement.DisposeFullQualityBrush();
contentElement.SetOnProgressDelegate(null);
}
Helper.HideAndFadeOut(this, seconds);
HelpSystem.GlobalSystem.HideHelp();
if (AtEnd != null) AtEnd();
}
void OnImageProgress(int p)
{
loadingProgress.Value = p;
if (p >= 0 && loadingProgress.Visibility == Visibility.Collapsed)
{
Helper.ShowAndFadeIn(loadingProgress, 0.5);
Helper.HideAndFadeOut(labelContentTitle, 0.5);
}
if (p > 99 && loadingProgress.Visibility == Visibility.Visible)
{
Helper.ShowAndFadeIn(labelContentTitle, 0.5);
Helper.HideAndFadeOut(loadingProgress, 0.5);
}
// error?
if (p < 0)
{
Helper.ShowAndFadeIn(errorLabel, 0.5);
}
}
private void rotLeft_Click(object sender, RoutedEventArgs e)
{
throw new NotImplementedException();
}
private void rotRight_Click(object sender, RoutedEventArgs e)
{
throw new NotImplementedException();
}
private void saveBtn_Click(object sender, RoutedEventArgs e)
{
if (contentElement.GetElementType() != s3dCore.SearchEngines.SearchElementType.etImage) return;
System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
sfd.InitialDirectory = @search3D.Properties.Settings.Default.StoreDirectory;
sfd.Filter = "Jpg files (*.jpg)|*.jpg|Jpg files (*.jpeg)|*.jpeg|Bmp files (*.bmp)|*.bmp" +
"|Png files (*.png)|*.png|Tif files (*.tif)|*.tif|Tif files (*.tiff)|*.tiff" +
"|Gif files (*.gif)|*.gif|Wmp files (*.wmp)|*.wmp|All files (*.*)|*.*";
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if (sfd.FileName != string.Empty)
{
string errorMessage;
//TODO : need to make save path available in App.Config
if (SaveImageToDisk(sfd.FileName, out errorMessage))
{
MessageBox.Show("File was saved properly!", "Save Ok",
MessageBoxButton.OK, MessageBoxImage.Information);
}
else
MessageBox.Show(errorMessage, "Error",
MessageBoxButton.OK, MessageBoxImage.Error);
}
else
MessageBox.Show("You need to enter a filename", "Error",
MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void cropBtn_Click(object sender, RoutedEventArgs e)
{
throw new NotImplementedException();
}
bool SaveImageToDisk(string filename, out string errorMessage)
{
string extension = filename.LastIndexOf(".") > -1 ? filename.Substring(filename.LastIndexOf(".")) : ".jpg";
BitmapEncoder encoder = null;
switch (extension.ToLower())
{
case ".jpg":
case ".jpeg":
encoder = new JpegBitmapEncoder();
break;
case ".bmp":
encoder = new BmpBitmapEncoder();
break;
case ".png":
encoder = new PngBitmapEncoder();
break;
case ".tif":
case ".tiff":
encoder = new TiffBitmapEncoder();
break;
case ".gif":
encoder = new GifBitmapEncoder();
break;
case ".wmp":
encoder = new WmpBitmapEncoder();
break;
default:
errorMessage = "extension is wrong!";
return false;
}
try
{
FileStream stream = new FileStream(filename, FileMode.Create);
encoder.Frames.Add(BitmapFrame.Create(imageToSave));
encoder.Save(stream);
errorMessage = "";
stream.Close();
return true;
}
catch (Exception e)
{
errorMessage = e.ToString();
}
return false;
}
private void goBackBtn_Click(object sender, RoutedEventArgs e)
{
FadeOut(0.5);
}
private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount > 1)
{
FadeOut(0.5);
}
}
}
}