Skip to content

Commit

Permalink
Still need to fix the area under the caption buttons being the only s…
Browse files Browse the repository at this point in the history
…pace to receive inputs and the area outside being the only place to drag.
  • Loading branch information
AlexanderBlackman committed Mar 10, 2022
1 parent f653b15 commit 20feb39
Show file tree
Hide file tree
Showing 5 changed files with 278 additions and 85 deletions.
3 changes: 2 additions & 1 deletion App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using WinUIEx;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
Expand Down Expand Up @@ -47,6 +48,6 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs ar

}

private Window m_window;
public WindowEx m_window;
}
}
18 changes: 3 additions & 15 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
xmlns:winex="using:WinUIEx"
mc:Ignorable="d"
Height="400" Width="400"

>
<Grid >

>
<Grid x:Name="imageGrid" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
Expand All @@ -28,17 +26,7 @@
<Image x:Name="selectedImage" Stretch="Uniform"
Tapped="Image_Tapped" FlyoutBase.AttachedFlyout="{x:Bind ImageCommandsFlyout}"
ContextFlyout="{x:Bind ImageCommandsFlyout}"/>

<!--<CommandBar Background="Transparent" IsOpen="False" DefaultLabelPosition="Bottom" Foreground="LightGreen">
<CommandBar.SecondaryCommands>
<AppBarButton Icon="OpenLocal" Label="Open Picture" Click="OpenFileWindow_Click"/>
<AppBarToggleButton Icon="Pin" Label="Pin to top" x:Name="pinToTopToggleButton" Content="Pin to Front" Click="pinToTopToggle"/>
</CommandBar.SecondaryCommands>
</CommandBar>-->



</Grid>


</winex:WindowEx>
133 changes: 93 additions & 40 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,32 @@ namespace ImageOverlay
/// </summary>
///

[ComImport, System.Runtime.InteropServices.Guid("3E68D4BD-7135-4D10-8018-9FB6D9F33FA1"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IInitializeWithWindow
{
void Initialize([In] IntPtr hwnd);
}



public sealed partial class MainWindow : WindowEx
{
double ratio;

//[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto, PreserveSig = true, SetLastError = false)]
//public static extern IntPtr GetActiveWindow();

//WindowEx rootWindow = (WindowEx)Window.Current;
public MainWindow()
{
this.InitializeComponent();
// this.SizeChanged += MainWindow_SizeChanged;
string[] arguments = Environment.GetCommandLineArgs();
LoadImageOnLaunch();

this.ExtendsContentIntoTitleBar = true;
SetTitleBar(selectedImage);


// OpenFileWindow();

LoadImageOnLaunch();



// OpenFileWindow();
}





private void MainWindow_SizeChanged(object sender, WindowSizeChangedEventArgs args)
{
//selectedImage.Width = args.Size.Width;
Expand All @@ -69,7 +67,7 @@ private void MainWindow_SizeChanged(object sender, WindowSizeChangedEventArgs ar
private void LoadImageOnLaunch()
{
string[] arguments = Environment.GetCommandLineArgs();
if (arguments.Length > 1 )
if (arguments.Length > 1)
{
selectedImage.Source = new BitmapImage(new Uri(arguments[1]));
}
Expand All @@ -80,26 +78,26 @@ private void LoadImageOnLaunch()

public void SetImageSource()
{
//
////selectedImage.Source = new BitmapImage(new Uri("b://847.jpg"));
//
////selectedImage.Source = new BitmapImage(new Uri("b://847.jpg"));

// if (arguments[1] != null)
// selectedImage.Source = new BitmapImage(new Uri(arguments[1]));
// if (arguments[1] != null)
// selectedImage.Source = new BitmapImage(new Uri(arguments[1]));

}

private async void OpenFileWindow_Click(object sender, RoutedEventArgs e)
{
await OpenFileWindow();
await OpenFileWindow();
}

private async Task OpenFileWindow()
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.SetOwnerWindow(this);
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.SetOwnerWindow(this);
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");

Expand All @@ -113,23 +111,23 @@ private async Task OpenFileWindow()
{
//create decoder
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
//Get softwarebitmap from file.
softwareBitmap = await decoder.GetSoftwareBitmapAsync();
//Get softwarebitmap from file.
softwareBitmap = await decoder.GetSoftwareBitmapAsync();

}
}

if (softwareBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 ||
softwareBitmap.BitmapAlphaMode == BitmapAlphaMode.Straight)
{
softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
}
var source = new SoftwareBitmapSource();
await source.SetBitmapAsync(softwareBitmap);
if (softwareBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 ||
softwareBitmap.BitmapAlphaMode == BitmapAlphaMode.Straight)
{
softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
}
var source = new SoftwareBitmapSource();
await source.SetBitmapAsync(softwareBitmap);



setWindowToBitmapRatioSize(softwareBitmap);
selectedImage.Source = source;
setWindowToBitmapRatioSize(softwareBitmap);
selectedImage.Source = source;
}


Expand All @@ -139,20 +137,20 @@ private double setWindowToBitmapRatioSize(SoftwareBitmap image)
ratio = image.PixelHeight / image.PixelWidth;

//TODO get monitor size, and have the images resized if too large

this.Height = image.PixelHeight;
this.Width = image.PixelWidth;


return ratio;
}




private void pinToTopToggle(object sender, RoutedEventArgs e)
{
IsAlwaysOnTop = (IsAlwaysOnTop) ? false : true;
this.IsAlwaysOnTop = (this.IsAlwaysOnTop) ? false : true;
}

private void Image_Tapped(object sender, TappedRoutedEventArgs e)
Expand All @@ -167,5 +165,60 @@ private void Image_Tapped(object sender, TappedRoutedEventArgs e)
};
flyout?.ShowAt((FrameworkElement)sender, options);
}

private void closeApp(object sender, RoutedEventArgs e)
{

}
























//[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto, PreserveSig = true, SetLastError = false)]
//public static extern IntPtr GetActiveWindow();

//public MainWindow()
//{
// this.InitializeComponent();

// Image image = new Image() { Source = new BitmapImage(new Uri("b://motivate3.jpg")) };
// // TapableImage image = new TapableImage();


// //TitleBar = image;

// this.ExtendsContentIntoTitleBar = true;
// this.IsAlwaysOnTop = true;
// SetTitleBar(imageGrid);
// this.SizeChanged += MainWindow_SizeChanged;
// string[] arguments = Environment.GetCommandLineArgs();
// LoadImageOnLaunch();



// OpenFileWindow();



}
}
20 changes: 20 additions & 0 deletions TapableImage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,25 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<!--<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.Resources>
<CommandBarFlyout x:Name="ImageCommandsFlyout">
<AppBarButton Icon="OpenLocal" ToolTipService.ToolTip="Open image" Click="OpenFileWindow_Click"/>
<AppBarToggleButton Icon="Pin" x:Name="pinToTopToggleButton" ToolTipService.ToolTip="Pin to Front" Click="pinToTopToggle"/>
</CommandBarFlyout>
</Grid.Resources>
<Image x:Name="selectedImage" Stretch="Uniform"
Tapped="Image_Tapped" FlyoutBase.AttachedFlyout="{x:Bind ImageCommandsFlyout}"
ContextFlyout="{x:Bind ImageCommandsFlyout}"/>
</Grid>-->



</UserControl>
Loading

0 comments on commit 20feb39

Please sign in to comment.