Skip to content

Commit

Permalink
custom slides!
Browse files Browse the repository at this point in the history
  • Loading branch information
meetox80 committed Nov 8, 2023
1 parent 1876884 commit 022611c
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 95 deletions.
3 changes: 2 additions & 1 deletion zstio-tv/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ internal class Config
{
#region Application
public static string Version = "0.24";
public static bool Developer = false;
public static bool Developer = true;
public static string[] ImageExtensions = { ".png", ".jpg", ".jpeg" };

public static string Warning = "Przypominamy, że obowiązuje całkowity zakaz opuszczania terenu szkoły podczas zajęć i przerw międzylekcyjnych.";
#endregion
Expand Down
54 changes: 36 additions & 18 deletions zstio-tv/Display/MediaWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:zstio_tv"
mc:Ignorable="d"
Title="ConfigWindow" Loaded="Window_Loaded" Height="270" Width="800" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize" Background="#FF101010">
Title="MediaWindow" Loaded="WindowLoaded" Height="600" Width="500" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize" Background="#FF101010">
<Window.Resources>
<Style TargetType="Button">
<Setter Property="Background" Value="Transparent"/>
Expand All @@ -27,25 +27,43 @@
</Style>
</Window.Resources>
<Grid>
<Grid Margin="15,15,15,55">
<TabControl BorderBrush="White" Background="{x:Null}">
<TabItem Header="Banner" BorderBrush="{x:Null}">
<Grid Background="#FF101010">
<Rectangle Width="230" Height="80" RadiusX="10" RadiusY="10" VerticalAlignment="Top" Margin="0,15,0,0" DragDrop.Drop="Rectangle_Drop" AllowDrop="True">
<Rectangle.Fill>
<ImageBrush x:Name="previewsource" ImageSource="/Resources/dropimage.png"/>
</Rectangle.Fill>
</Rectangle>
<TabControl Margin="15,15,15,50">
<TabItem Header="Banner">
<Grid Background="#FF151515">
<DataGrid x:Name="bannerdata" BorderBrush="{x:Null}" Background="{x:Null}" Height="420" VerticalAlignment="Top" CanUserDeleteRows="False"/>

<Label Content="Prosimy o umieszczanie grafik w Ratio 23:8" Foreground="White" FontFamily="/Font/InterBold/#Inter" Opacity="0.75" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="10"/>
</Grid>
</TabItem>
</TabControl>
</Grid>
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" Margin="10">
<Button Cursor="Hand" Height="30" Width="120" Content="Wybierz folder" FontFamily="/Font/InterBold/#Inter" Foreground="White" Background="#FF151515" BorderBrush="#FFA94646" Margin="10,0,0,0" Click="BannerSelectFolderClick"/>
<StackPanel Orientation="Horizontal" Margin="10,0,0,0" Height="25">
<Slider x:Name="bannerslider" Width="150" Minimum="2" Maximum="30" Height="22" ValueChanged="BannerSlider_ValueChanged"/>
<Label x:Name="bannerslidertext" Foreground="White" FontFamily="/Font/InterBold/#Inter" Content="9s"/>
</StackPanel>
</StackPanel>
</Grid>
</TabItem>
<TabItem Header="Slajd">
<Grid Background="#FF151515">
<DataGrid x:Name="slidedata" BorderBrush="{x:Null}" Background="{x:Null}" Height="420" VerticalAlignment="Top" CanUserDeleteRows="False"/>

<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,10,10">
<Button Cursor="Hand" Height="30" Width="60" Content="Wyjdz" FontFamily="/Font/InterBold/#Inter" Foreground="White" Background="#FF151515" BorderBrush="#FFA94646" Margin="10,0,0,0" Click="HideButton"/>
<Button Cursor="Hand" Height="30" Width="90" Content="Zastosuj" FontFamily="/Font/InterBold/#Inter" Foreground="White" Background="#FF151515" BorderBrush="#FFA94646" Margin="10,0,0,0" Click="ApplyButton"/>
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" Margin="10">
<Button Cursor="Hand" Height="30" Width="120" Content="Wybierz folder" FontFamily="/Font/InterBold/#Inter" Foreground="White" Background="#FF151515" BorderBrush="#FFA94646" Margin="10,0,0,0" Click="SlideSelectFolderClick"/>
<StackPanel Orientation="Horizontal" Margin="10,0,0,0" Height="25">
<Slider x:Name="slideslider" Width="150" Minimum="2" Maximum="30" Height="22" ValueChanged="SlideSlider_ValueChanged"/>
<Label x:Name="slideslidertext" Foreground="White" FontFamily="/Font/InterBold/#Inter" Content="9s"/>
</StackPanel>
</StackPanel>
</Grid>
</TabItem>
</TabControl>

<StackPanel Orientation="Vertical" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="15,0,0,10">
<CheckBox x:Name="bannervisibility" Foreground="White" Content="Widocznosc Banneru" Click="bannervisibility_Click"/>
<CheckBox x:Name="slidevisibility" Foreground="White" Content="Widocznosc Slajdu" Click="slidevisibility_Click"/>
</StackPanel>

<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,15,10">
<Button Cursor="Hand" Height="30" Width="60" Content="Wyjdź" FontFamily="/Font/InterBold/#Inter" Opacity="0.5" Foreground="White" Background="#FF151515" BorderBrush="#FF5A4343" Margin="10,0,0,0"/>
<Button Cursor="Hand" Height="30" Width="90" Content="Zastosuj" FontFamily="/Font/InterBold/#Inter" Foreground="White" Background="#FF151515" BorderBrush="#FFA94646" Margin="10,0,0,0" Click="Apply"/>
</StackPanel>
</Grid>
</Window>
200 changes: 153 additions & 47 deletions zstio-tv/Display/MediaWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Data;
using System.IO;
using System.Linq;
using System.Windows;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Media.Imaging;
using System.IO;
using System.Windows.Media;
using System.Runtime.InteropServices;
using System.Windows.Interop;
using System.Windows.Threading;

namespace zstio_tv
{
Expand All @@ -16,73 +16,179 @@ public MediaWindow()
InitializeComponent();

Check failure on line 16 in zstio-tv/Display/MediaWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The name 'InitializeComponent' does not exist in the current context
}

private const int GWL_STYLE = -16;
private const int WS_SYSMENU = 0x80000;
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
int SlideBackup = 0;

DispatcherTimer BannerTimer = new DispatcherTimer();
DispatcherTimer SlideTimer = new DispatcherTimer();
private void WindowLoaded(object sender, RoutedEventArgs e)
{
SlideBackup = MainWindow.Pages;

BannerTimer.Interval = TimeSpan.FromSeconds((int)bannerslider.Value);

Check failure on line 27 in zstio-tv/Display/MediaWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The name 'bannerslider' does not exist in the current context
BannerTimer.Tick += BannerTimer_Tick;

SlideTimer.Interval = TimeSpan.FromSeconds((int)slideslider.Value);

Check failure on line 30 in zstio-tv/Display/MediaWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The name 'slideslider' does not exist in the current context
SlideTimer.Tick += SlideTimer_Tick;
}

private void Rectangle_Drop(object sender, DragEventArgs e)
int BannerSlide = 0;
private void BannerTimer_Tick(object sender, EventArgs e)
{
BannerSlide++;
if (BannerSlide == BannerFileCount)
{
BannerSlide = 0;
}
try
{
var DropData = e.Data.GetData(DataFormats.FileDrop);
if (DropData != null)
{
var DropDataFilenames = DropData as string[];
if (DropDataFilenames.Length > 0)
{
Image image = Image.FromFile(DropDataFilenames[0]);
string ImagePath = Path.Combine(BannerDirectory, BannerFiles[BannerSlide]);

using (MemoryStream stream = new MemoryStream())
{
image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
stream.Seek(0, SeekOrigin.Begin);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.UriSource = new Uri(ImagePath, UriKind.RelativeOrAbsolute);
bitmapImage.EndInit();

BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = stream;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
MainWindow._Instance.handler_bar_banner_panel_image.ImageSource = bitmapImage;
} catch (Exception ex)
{
Console.WriteLine(ex);
}
}

previewsource.ImageSource = bitmapImage;
}
}
}
int SlideSlide = 0;
private void SlideTimer_Tick(object sender, EventArgs e)
{
SlideSlide++;
if (SlideSlide == SlideFileCount)
{
SlideSlide = 0;
}
try
{
string ImagePath = Path.Combine(SlideDirectory, SlideFiles[SlideSlide]);

BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.UriSource = new Uri(ImagePath, UriKind.RelativeOrAbsolute);
bitmapImage.EndInit();

MainWindow._Instance.customslideimages_image.ImageSource = bitmapImage;
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}

ImageSource NoImage;
private void Window_Loaded(object sender, RoutedEventArgs e)
private void slidevisibility_Click(object sender, RoutedEventArgs e)
{
var hwnd = new WindowInteropHelper(this).Handle;
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
if (slidevisibility.IsChecked == true)
{
MainWindow.Pages = SlideBackup + 1;
SlideTimer.Interval = TimeSpan.FromSeconds((int)slideslider.Value);
SlideTimer.Start();
} else
{
MainWindow.Pages = SlideBackup;
SlideTimer.Interval = TimeSpan.FromSeconds((int)slideslider.Value);
SlideTimer.Stop();
}
}

NoImage = previewsource.ImageSource;
private void bannervisibility_Click(object sender, RoutedEventArgs e)
{
if (bannervisibility.IsChecked == true)
{
MainWindow._Instance.handler_bar_banner.Visibility = Visibility.Visible;
BannerTimer.Interval = TimeSpan.FromSeconds((int)bannerslider.Value);
BannerTimer.Start();
} else
{
MainWindow._Instance.handler_bar_banner.Visibility = Visibility.Collapsed;
BannerTimer.Interval = TimeSpan.FromSeconds((int)bannerslider.Value);
BannerTimer.Stop();
}
}

int BannerFileCount = 0; string BannerDirectory; string[] BannerFiles;
private void BannerSelectFolderClick(object sender, RoutedEventArgs e)
{
using (var FolderDialog = new FolderBrowserDialog())
{
DialogResult DialogResult = FolderDialog.ShowDialog();

if (DialogResult == DialogResult.OK && !string.IsNullOrWhiteSpace(FolderDialog.SelectedPath))
{
BannerDirectory = FolderDialog.SelectedPath;

BannerFiles = Directory.GetFiles(FolderDialog.SelectedPath)
.Where(file => Config.ImageExtensions.Contains(Path.GetExtension(file), StringComparer.OrdinalIgnoreCase))
.ToArray();

DataTable FilesDataTable = new DataTable();
FilesDataTable.Columns.Add("FileCount", typeof(int));
FilesDataTable.Columns.Add("FileName", typeof(string));

foreach (string FileName in BannerFiles)
{
BannerFileCount++;
DataRow FilesRow = FilesDataTable.NewRow();
FilesRow["FileCount"] = BannerFileCount;
FilesRow["FileName"] = Path.GetFileName(FileName);
FilesDataTable.Rows.Add(FilesRow);
bannerdata.ItemsSource = FilesDataTable.DefaultView;
}
}
}
}

private void ApplyButton(object sender, RoutedEventArgs e)
int SlideFileCount = 0; string SlideDirectory; string[] SlideFiles;
private void SlideSelectFolderClick(object sender, RoutedEventArgs e)
{
if (previewsource.ImageSource == NoImage)
using (var FolderDialog = new FolderBrowserDialog())
{
MessageBox.Show("Prosze wrzucic obrazek.");
return;
DialogResult DialogResult = FolderDialog.ShowDialog();

if (DialogResult == DialogResult.OK && !string.IsNullOrWhiteSpace(FolderDialog.SelectedPath))
{
SlideDirectory = FolderDialog.SelectedPath;

SlideFiles = Directory.GetFiles(FolderDialog.SelectedPath)
.Where(file => Config.ImageExtensions.Contains(Path.GetExtension(file), StringComparer.OrdinalIgnoreCase))
.ToArray();

DataTable FilesDataTable = new DataTable();
FilesDataTable.Columns.Add("FileCount", typeof(int));
FilesDataTable.Columns.Add("FileName", typeof(string));

foreach (string FileName in SlideFiles)
{
SlideFileCount++;
DataRow FilesRow = FilesDataTable.NewRow();
FilesRow["FileCount"] = SlideFileCount;
FilesRow["FileName"] = Path.GetFileName(FileName);
FilesDataTable.Rows.Add(FilesRow);
slidedata.ItemsSource = FilesDataTable.DefaultView;
}
}
}
}

MainWindow._Instance.handler_bar_banner_panel_image.ImageSource = previewsource.ImageSource;
MainWindow._Instance.handler_bar_banner.Visibility = Visibility.Visible;
this.Hide();
private void BannerSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (bannerslider != null && bannerslidertext != null)
bannerslidertext.Content = $"{(int)bannerslider.Value}s";
}
private void SlideSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (slideslider != null && slideslidertext != null)
slideslidertext.Content = $"{(int)slideslider.Value}s";
}

private void HideButton(object sender, RoutedEventArgs e)
private void Apply(object sender, RoutedEventArgs e)
{
this.Hide();
MainWindow._Instance.handler_bar_banner.Visibility = Visibility.Collapsed;
BannerTimer.Interval = TimeSpan.FromSeconds((int)bannerslider.Value);
SlideTimer.Interval = TimeSpan.FromSeconds((int)slideslider.Value);
}
}
}
7 changes: 7 additions & 0 deletions zstio-tv/Helpers/ILesson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,25 @@ public static string[] GetLessons()
}
}

int TemponaryState = 0;
if (NextLessonOrBreakStartTime == DateTime.MaxValue)
{
TemponaryState = 1;
return new string[] { "Brak lekcji na dziś", "" };
}

TimeSpan TimeToNextLessonOrBreak = NextLessonOrBreakStartTime - CurrentTime;

if (TimeToNextLessonOrBreak.TotalMinutes <= 0)
{
TemponaryState = 0;
return new string[] { "Przerwa", "00:00:00" };
}

// replace the api after lessons
if (TemponaryState == 1)
MainWindow.ReplacementsGETAPI_Tick(null, null);

return new string[] { "Przerwa", $"{TimeToNextLessonOrBreak.ToString(@"hh\:mm\:ss")}" };
}
}
Expand Down
16 changes: 12 additions & 4 deletions zstio-tv/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@

<Grid x:Name="handler_content_tabcontrol_replacements_viewer" Margin="0,75,0,0" Height="600">
<StackPanel Margin="0,0,0,0" x:Name="handler_content_tabcontrol_replacements_fields">
<TextBlock Text="Brak zastępstw na dziś." FontFamily="/Font/InterBold/#Inter" Foreground="White" TextAlignment="Center" FontSize="15" Margin="0,20,0,0" Opacity="0.75"/>

<!--
// Field example, to see in designer; uncomment and remove this.
// Made to port into raw c# from xaml
-->
<Grid VerticalAlignment="Top" Margin="0,10,0,0">
<Rectangle Height="45" Width="1000" Fill="#FF0A0A0A" RadiusX="5" RadiusY="5"/>
Expand All @@ -189,9 +190,9 @@
</Grid>
</StackPanel>
</Grid>

-->
</StackPanel>

<TextBlock x:Name="no_replacements" Visibility="Collapsed" FontFamily="/Font/InterBold/#Inter" Foreground="White" FontSize="20" Text="Brak zastępstw." HorizontalAlignment="Center" VerticalAlignment="Center" Opacity="0.75"/>
</Grid>
</Grid>
Expand Down Expand Up @@ -240,7 +241,11 @@

<TabItem Header="TabItem" Foreground="{x:Null}" BorderBrush="{x:Null}" Background="{x:Null}" Visibility="Collapsed">
<Grid>
<Label Content="tab3" Foreground="White"/>
<Rectangle x:Name="customslideimages" RadiusX="15" RadiusY="15" HorizontalAlignment="Center" VerticalAlignment="Center" Height="600" Width="1000" Margin="0,0,0,70">
<Rectangle.Fill>
<ImageBrush x:Name="customslideimages_image"/>
</Rectangle.Fill>
</Rectangle>
</Grid>
</TabItem>

Expand Down Expand Up @@ -283,6 +288,9 @@
<StackPanel x:Name="handler_content_description_pages_display" Orientation="Horizontal" HorizontalAlignment="Center">
<Ellipse Margin="5,0,0,0" Fill="White" Height="8" Width="8"/>
<Ellipse Margin="5,0,0,0" Fill="White" Height="8" Width="8" Opacity="0.5"/>
<Ellipse Margin="5,0,0,0" Fill="White" Height="8" Width="8" Opacity="0.5"/>
<Ellipse Margin="5,0,0,0" Fill="White" Height="8" Width="8" Opacity="0.5"/>
<Ellipse Margin="5,0,0,0" Fill="White" Height="8" Width="8" Opacity="0.5"/>
</StackPanel>
</Grid>
</Grid>
Expand Down
Loading

0 comments on commit 022611c

Please sign in to comment.