~haowenl/vorg-windows

f3d5b897086282e32e445c1d970bcb32e7cc7d90 — Haowen Liu 11 months ago cb8437b
Add hover thumbnail display
M vorg-windows/App.xaml.cpp => vorg-windows/App.xaml.cpp +8 -3
@@ 116,11 116,16 @@ void App::PopulateGalleryData(

        hstring hash = to_hstring(fileData.getHash());
        hstring videoPath = to_hstring(videoPathUTF8.string());
        // NOTE: currently only the first thumbnail at 25% is used
        hstring thumbnailPath = to_hstring(thumbnailPathsUTF8[0].string());
        winrtData.Hash(hash);
        winrtData.VideoPath(videoPath);
        winrtData.ThumbnailPath(thumbnailPath);

        Windows::Foundation::Collections::IObservableVector<hstring> thumbnailPaths =
            single_threaded_observable_vector<hstring>();
        for (auto &thumbnailPath : thumbnailPathsUTF8)
        {
            thumbnailPaths.Append(to_hstring(thumbnailPath.string()));
        }
        winrtData.ThumbnailPaths(thumbnailPaths);

        resultData.Append(winrtData);
    }

M vorg-windows/BrowseGalleryPage.xaml => vorg-windows/BrowseGalleryPage.xaml +2 -3
@@ 12,13 12,12 @@

    <Page.Resources>
        <DataTemplate x:Key="ThumbnailTemplate" x:DataType="local:VideoGalleryData">
            <Image
            <local:HoverThumbnailDisplay
                Width="190"
                Height="130"
                DoubleTapped="Thumbnail_DoubleTapped"
                IsDoubleTapEnabled="True"
                Source="{x:Bind ThumbnailPath}"
                Stretch="UniformToFill" />
                Thumbnails="{x:Bind ThumbnailPaths}" />
        </DataTemplate>
    </Page.Resources>


A vorg-windows/HoverThumbnailDisplay.idl => vorg-windows/HoverThumbnailDisplay.idl +13 -0
@@ 0,0 1,13 @@
namespace vorg_windows
{
[default_interface] runtimeclass HoverThumbnailDisplay : Microsoft.UI.Xaml.Controls.Grid
{
    HoverThumbnailDisplay();

    Windows.Foundation.Collections.IObservableVector<String> Thumbnails
    {
        get;
        set;
    };
}
} // namespace vorg_windows

A vorg-windows/HoverThumbnailDisplay.xaml => vorg-windows/HoverThumbnailDisplay.xaml +18 -0
@@ 0,0 1,18 @@
<Grid
    x:Class="vorg_windows.HoverThumbnailDisplay"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="using:vorg_windows"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    PointerEntered="MainGrid_PointerEntered"
    PointerExited="MainGrid_PointerExited"
    mc:Ignorable="d">

    <!--<Image
        x:Name="MainImage"
        PointerEntered="MainImage_PointerEntered"
        PointerExited="MainImage_PointerExited"
        Stretch="UniformToFill" />-->

</Grid>

A vorg-windows/HoverThumbnailDisplay.xaml.cpp => vorg-windows/HoverThumbnailDisplay.xaml.cpp +85 -0
@@ 0,0 1,85 @@
#include "pch.h"

#include "HoverThumbnailDisplay.xaml.h"
#if __has_include("HoverThumbnailDisplay.g.cpp")
#include "HoverThumbnailDisplay.g.cpp"
#endif

#include <chrono>

using namespace winrt;
using namespace Microsoft::UI::Xaml;

namespace winrt::vorg_windows::implementation
{
HoverThumbnailDisplay::HoverThumbnailDisplay()
{
    InitializeComponent();

    mTimer.Interval(std::chrono::milliseconds{500});
    mTickToken = mTimer.Tick({this, &HoverThumbnailDisplay::Timer_Tick});
}

HoverThumbnailDisplay::~HoverThumbnailDisplay()
{
    mTimer.Tick(mTickToken);
}

Windows::Foundation::Collections::IObservableVector<hstring> HoverThumbnailDisplay::Thumbnails() const
{
    return mThumbnails;
}

void HoverThumbnailDisplay::Thumbnails(const Windows::Foundation::Collections::IObservableVector<hstring> &thumbnails)
{
    mThumbnails = thumbnails;

    // Load all thumbnails
    mThumbnailImages.clear();
    for (uint32_t i = 0; i < thumbnails.Size(); ++i)
    {
        Microsoft::UI::Xaml::Media::Imaging::BitmapImage bitmap;
        bitmap.UriSource(Windows::Foundation::Uri{thumbnails.GetAt(i)});
        Microsoft::UI::Xaml::Controls::Image image;
        image.Source(bitmap);
        image.Stretch(Microsoft::UI::Xaml::Media::Stretch::UniformToFill);
        if (i == 0)
        {
            image.Visibility(Microsoft::UI::Xaml::Visibility::Visible);
        }
        else
        {
            image.Visibility(Microsoft::UI::Xaml::Visibility::Collapsed);
        }
        this->Children().Append(image);
        mThumbnailImages.emplace_back(image);
    }
}

void HoverThumbnailDisplay::MainGrid_PointerEntered(const Windows::Foundation::IInspectable &,
                                                    const Microsoft::UI::Xaml::Input::PointerRoutedEventArgs &)
{
    mTimer.Start();
}

void HoverThumbnailDisplay::MainGrid_PointerExited(const Windows::Foundation::IInspectable &,
                                                   const Microsoft::UI::Xaml::Input::PointerRoutedEventArgs &)
{
    mTimer.Stop();
    int pastIndex = mCurrentIndex;
    mCurrentIndex = 0;
    Children().GetAt(0).Visibility(Microsoft::UI::Xaml::Visibility::Visible);
    if (pastIndex != 0)
        Children().GetAt(pastIndex).Visibility(Microsoft::UI::Xaml::Visibility::Collapsed);
}

void HoverThumbnailDisplay::Timer_Tick(const Windows::Foundation::IInspectable &,
                                       const Windows::Foundation::IInspectable &)
{
    int pastIndex = mCurrentIndex;
    mCurrentIndex += 1;
    mCurrentIndex %= mThumbnailImages.size();
    Children().GetAt(mCurrentIndex).Visibility(Microsoft::UI::Xaml::Visibility::Visible);
    Children().GetAt(pastIndex).Visibility(Microsoft::UI::Xaml::Visibility::Collapsed);
}
} // namespace winrt::vorg_windows::implementation

A vorg-windows/HoverThumbnailDisplay.xaml.h => vorg-windows/HoverThumbnailDisplay.xaml.h +43 -0
@@ 0,0 1,43 @@
#pragma once

#include "HoverThumbnailDisplay.g.h"

#include <vector>

namespace winrt::vorg_windows::implementation
{
struct HoverThumbnailDisplay : HoverThumbnailDisplayT<HoverThumbnailDisplay>
{
    HoverThumbnailDisplay();
    ~HoverThumbnailDisplay();

    // Properties
    Windows::Foundation::Collections::IObservableVector<hstring> Thumbnails() const;
    void Thumbnails(const Windows::Foundation::Collections::IObservableVector<hstring> &thumbnails);

    // Handlers
    void MainGrid_PointerEntered(const Windows::Foundation::IInspectable &,
                                  const Microsoft::UI::Xaml::Input::PointerRoutedEventArgs &);
    void MainGrid_PointerExited(const Windows::Foundation::IInspectable &,
                                 const Microsoft::UI::Xaml::Input::PointerRoutedEventArgs &);

    void Timer_Tick(const Windows::Foundation::IInspectable &, const Windows::Foundation::IInspectable &);

  private:
    // Properties
    Windows::Foundation::Collections::IObservableVector<hstring> mThumbnails;

    // Members
    Microsoft::UI::Xaml::DispatcherTimer mTimer;
    event_token mTickToken;
    int mCurrentIndex;
    std::vector<Microsoft::UI::Xaml::Controls::Image> mThumbnailImages;
};
} // namespace winrt::vorg_windows::implementation

namespace winrt::vorg_windows::factory_implementation
{
struct HoverThumbnailDisplay : HoverThumbnailDisplayT<HoverThumbnailDisplay, implementation::HoverThumbnailDisplay>
{
};
} // namespace winrt::vorg_windows::factory_implementation

M vorg-windows/VideoGalleryData.cpp => vorg-windows/VideoGalleryData.cpp +5 -4
@@ 17,14 17,15 @@ void VideoGalleryData::Hash(const hstring &hash)
    mHash = hash;
}

hstring VideoGalleryData::ThumbnailPath() const
Windows::Foundation::Collections::IObservableVector<hstring> VideoGalleryData::ThumbnailPaths() const
{
    return mThumbnailPath;
    return mThumbnailPaths;
}

void VideoGalleryData::ThumbnailPath(const hstring &thumbnailPath)
void VideoGalleryData::ThumbnailPaths(
    const Windows::Foundation::Collections::IObservableVector<hstring> &thumbnailPaths)
{
    mThumbnailPath = thumbnailPath;
    mThumbnailPaths = thumbnailPaths;
}

hstring VideoGalleryData::VideoPath() const

M vorg-windows/VideoGalleryData.h => vorg-windows/VideoGalleryData.h +3 -3
@@ 9,15 9,15 @@ struct VideoGalleryData : VideoGalleryDataT<VideoGalleryData>
    hstring Hash() const;
    void Hash(const hstring &hash);

    hstring ThumbnailPath() const;
    void ThumbnailPath(const hstring &thumbnailPath);
    Windows::Foundation::Collections::IObservableVector<hstring> ThumbnailPaths() const;
    void ThumbnailPaths(const Windows::Foundation::Collections::IObservableVector<hstring> &thumbnailPaths);

    hstring VideoPath() const;
    void VideoPath(const hstring &videoPath);

  private:
    hstring mHash;
    hstring mThumbnailPath;
    Windows::Foundation::Collections::IObservableVector<hstring> mThumbnailPaths;
    hstring mVideoPath;
};
} // namespace winrt::vorg_windows::implementation

M vorg-windows/VideoGalleryData.idl => vorg-windows/VideoGalleryData.idl +1 -1
@@ 4,7 4,7 @@ namespace vorg_windows
    VideoGalleryData();

    String Hash;
    String ThumbnailPath;
    Windows.Foundation.Collections.IObservableVector<String> ThumbnailPaths;
    String VideoPath;
}
} // namespace vorg_windows

M vorg-windows/pch.h => vorg-windows/pch.h +1 -0
@@ 23,6 23,7 @@
#include <winrt/Microsoft.UI.Xaml.Interop.h>
#include <winrt/Microsoft.UI.Xaml.Markup.h>
#include <winrt/Microsoft.UI.Xaml.Media.Animation.h>
#include <winrt/Microsoft.UI.Xaml.Media.Imaging.h>
#include <winrt/Microsoft.UI.Xaml.Media.h>
#include <winrt/Microsoft.UI.Xaml.Navigation.h>
#include <winrt/Microsoft.UI.Xaml.Shapes.h>

M vorg-windows/vorg-windows.vcxproj => vorg-windows/vorg-windows.vcxproj +15 -0
@@ 139,6 139,10 @@
      <DependentUpon>BrowsePage.xaml</DependentUpon>
      <SubType>Code</SubType>
    </ClInclude>
    <ClInclude Include="HoverThumbnailDisplay.xaml.h">
      <DependentUpon>HoverThumbnailDisplay.xaml</DependentUpon>
      <SubType>Code</SubType>
    </ClInclude>
    <ClInclude Include="VideoGalleryData.h" />
    <ClInclude Include="ErrorContentDialog.xaml.h">
      <DependentUpon>ErrorContentDialog.xaml</DependentUpon>


@@ 192,6 196,9 @@
    <Page Include="ErrorContentDialog.xaml">
      <SubType>Designer</SubType>
    </Page>
    <Page Include="HoverThumbnailDisplay.xaml">
      <SubType>Designer</SubType>
    </Page>
    <Page Include="ImportEditPage.xaml">
      <SubType>Designer</SubType>
    </Page>


@@ 225,6 232,10 @@
      <DependentUpon>BrowsePage.xaml</DependentUpon>
      <SubType>Code</SubType>
    </ClCompile>
    <ClCompile Include="HoverThumbnailDisplay.xaml.cpp">
      <DependentUpon>HoverThumbnailDisplay.xaml</DependentUpon>
      <SubType>Code</SubType>
    </ClCompile>
    <ClCompile Include="VideoGalleryData.cpp" />
    <ClCompile Include="ErrorContentDialog.xaml.cpp">
      <DependentUpon>ErrorContentDialog.xaml</DependentUpon>


@@ 284,6 295,10 @@
      <DependentUpon>BrowsePage.xaml</DependentUpon>
      <SubType>Code</SubType>
    </Midl>
    <Midl Include="HoverThumbnailDisplay.idl">
      <DependentUpon>HoverThumbnailDisplay.xaml</DependentUpon>
      <SubType>Code</SubType>
    </Midl>
    <Midl Include="VideoGalleryData.idl" />
    <Midl Include="ErrorContentDialog.idl">
      <DependentUpon>ErrorContentDialog.xaml</DependentUpon>

M vorg-windows/vorg-windows.vcxproj.filters => vorg-windows/vorg-windows.vcxproj.filters +1 -0
@@ 27,6 27,7 @@
      <Filter>BrowsePage</Filter>
    </Page>
    <Page Include="VideoDataEditor.xaml" />
    <Page Include="HoverThumbnailDisplay.xaml" />
  </ItemGroup>
  <ItemGroup>
    <Midl Include="App.idl" />