Files
WPicView/WPicView/MainWindow.xaml.cs
2021-07-27 08:16:29 -05:00

165 lines
5.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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;
namespace WPicView
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
string[] allFiles = null;
string[] allDirs = null;
int fPos = 0;
int dPos ;
string searchPattern = "*.png";
ScaleTransform st = new ScaleTransform();
TranslateTransform tt = new TranslateTransform();
TransformGroup group = new TransformGroup();
public MainWindow()
{
InitializeComponent();
// allFiles = System.IO.Directory.GetFiles("C:\\Users\\U15020\\SShot\\2020-05-01");
allDirs = System.IO.Directory.GetDirectories(System.Environment.GetEnvironmentVariable ("USERPROFILE") + "\\SShot", "202*");
dPos = allDirs.Length - 1;
allFiles = System.IO.Directory.GetFiles(allDirs[dPos], searchPattern);
fPos = allFiles.Length-1;
showFile(allFiles[fPos]);
group.Children.Add(st);
group.Children.Add(tt);
}
private void showFile(String fileName) {
this.Title = allFiles[fPos];
try {
IMG1.Source = new BitmapImage(new Uri(fileName));
} catch (Exception ex) {
this.Title = "ERRROR LOADING FILE " + this.Title;
}
}
private void OnKeyDownHandler(object sender, KeyEventArgs e)
{
// Directory Navigation
if (e.Key == System.Windows.Input.Key.Up)
{
if (dPos > 0)
{
dPos -= 1;
allFiles = System.IO.Directory.GetFiles(allDirs[dPos], searchPattern);
fPos = allFiles.Length -1;
}
}
else if (e.Key == System.Windows.Input.Key.Down)
{
if (dPos < allDirs.Length - 1)
{
dPos += 1;
allFiles = System.IO.Directory.GetFiles(allDirs[dPos], searchPattern);
fPos = allFiles.Length - 1;
}
}
// File Navigation
if (e.Key == System.Windows.Input.Key.Right) {
if (fPos < allFiles.Length -1 ) {
fPos += 1;
} else
{
// look if more files popped up in the meantime...
allFiles = System.IO.Directory.GetFiles(allDirs[dPos], searchPattern);
if (fPos < allFiles.Length - 1)
{
fPos += 1;
}
}
} else if (e.Key == System.Windows.Input.Key.Left) {
if (fPos > 0) {
fPos -= 1;
}
}
if (e.Key == Key.End)
{
allFiles = System.IO.Directory.GetFiles(allDirs[dPos], searchPattern);
fPos = allFiles.Length - 1;
}
if (e.Key == Key.Home )
{
fPos = 0;
}
// Display file
if (allFiles.Length > 0)
{
showFile(allFiles[fPos]);
}
// zoom - TODO
if (e.Key == System.Windows.Input.Key.PageUp)
{
//https://stackoverflow.com/questions/741956/pan-zoom-image
IMG1.RenderTransform = group;
st.ScaleX += 0.2;
st.ScaleY += 0.2;
}
if (e.Key == System.Windows.Input.Key.PageDown)
{
//https://stackoverflow.com/questions/741956/pan-zoom-image
IMG1.RenderTransform = group;
st.ScaleX -= 0.2;
st.ScaleY -= 0.2;
}
if (e.Key == System.Windows.Input.Key.L)
{
IMG1.RenderTransform = group;
tt.X -= 25;
}
if (e.Key == System.Windows.Input.Key.H)
{
IMG1.RenderTransform = group;
tt.X += 25;
}
if (e.Key == System.Windows.Input.Key.J)
{
IMG1.RenderTransform = group;
tt.Y -= 25;
}
if (e.Key == System.Windows.Input.Key.K)
{
IMG1.RenderTransform = group;
tt.Y += 25;
}
}
}
}