Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSD AoT library #1349

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions LenovoLegionToolkit.Lib.AoTOSD/Animation/BasicAnimation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include"BasicAnimation.h"

namespace Animation = LenovoLegionToolkit::Lib::AoTOSD::Animation;

Animation::BasicAnimation::BasicAnimation(int speed) :
_speed(speed) {};
23 changes: 23 additions & 0 deletions LenovoLegionToolkit.Lib.AoTOSD/Animation/BasicAnimation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

namespace LenovoLegionToolkit::Lib::AoTOSD::Window { class OSDWindow; }

namespace LenovoLegionToolkit::Lib::AoTOSD::Animation {

class BasicAnimation {

public:
BasicAnimation(int speed);
virtual ~BasicAnimation() {};

virtual bool Animate(Window::OSDWindow* window) = 0;
virtual void Reset(Window::OSDWindow* window) = 0;

virtual int GetUpdateInterval() = 0;

protected:
int _speed;

}; // class BasicAnimation

} // namespace LenovoLegionToolkit::Lib::AoTOSD::Animation
45 changes: 45 additions & 0 deletions LenovoLegionToolkit.Lib.AoTOSD/Animation/FadeOutAnimation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include"FadeOutAnimation.h"
#include"../Window/OSDWindow.h"

namespace Animation = LenovoLegionToolkit::Lib::AoTOSD::Animation;

Animation::FadeOutAnimation::FadeOutAnimation(int speed) :
BasicAnimation(speed)
{
int bestInaccuracy = 255;
int bestInterval = 10;
for (int i = 10; i <= 20; i++)
{
int si = this->_speed / i;
int inaccuracy = 255 - 255 / si * si;
if (inaccuracy < bestInaccuracy)
{
bestInaccuracy = inaccuracy;
bestInterval = i;
}
}
this->_interval = bestInterval;
this->_step = 255 / (this->_speed / this->_interval);
return;
}

bool Animation::FadeOutAnimation::Animate(Window::OSDWindow* window) {
byte current = window->GetTransparency();
int newTrans = current - this->_step;
if (newTrans < 0)
{
newTrans = 0;
return true;
}
window->SetTransparency(newTrans);
return false;
}

void Animation::FadeOutAnimation::Reset(Window::OSDWindow* window) {
window->SetTransparency(255);
return;
}

int Animation::FadeOutAnimation::GetUpdateInterval() {
return this->_interval;
}
24 changes: 24 additions & 0 deletions LenovoLegionToolkit.Lib.AoTOSD/Animation/FadeOutAnimation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include"BasicAnimation.h"

namespace LenovoLegionToolkit::Lib::AoTOSD::Animation {

class FadeOutAnimation final : public BasicAnimation {

public:
FadeOutAnimation(int speed);
~FadeOutAnimation() {};

bool Animate(Window::OSDWindow* window) override;
void Reset(Window::OSDWindow* window) override;

int GetUpdateInterval() override;

private:
int _interval;
int _step;

}; // class FadeOutAnimation

} // namespace LenovoLegionToolkit::Lib::AoTOSD::Animation
103 changes: 103 additions & 0 deletions LenovoLegionToolkit.Lib.AoTOSD/AoTOSD.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include"AoTOSD.h"
#include"Animation/FadeOutAnimation.h"
#include"Utils/BitmapConverter.h"
#include"Utils/DesktopInfos.h"
#include"Utils/GlobalLogger.h"

#include<gdiplus.h>

#define NOTIFICATIONWINDOWAOT_WINDOW_CLASSNAME L"LenovoLegionToolkit-OSDAOT"
#define NOTIFICATIONWINDOWAOT_WINDOW_TITLE L"LenovoLegionToolkit-OSDAOT"

using namespace System;

namespace AoTOSD = LenovoLegionToolkit::Lib::AoTOSD;

AoTOSD::NotificationWindowAoT::NotificationWindowAoT() {
this->_window = new Window::OSDWindow(
NOTIFICATIONWINDOWAOT_WINDOW_CLASSNAME,
NOTIFICATIONWINDOWAOT_WINDOW_TITLE
);
}

AoTOSD::NotificationWindowAoT::~NotificationWindowAoT() {
delete this->_window;
}

void AoTOSD::NotificationWindowAoT::Show(Drawing::Bitmap^ bitmap, NotificationPosition pos, NotificationDuration duration) {
this->_window->SetBitmap(Utils::BitmapConverter::Convert(bitmap));
this->UpdateOSDWindowPosition(pos);
this->UpdateOSDWindowVisibleDuration(duration);
this->_window->Show();
}

void AoTOSD::NotificationWindowAoT::UpdateOSDWindowPosition(NotificationPosition pos) {
POINT newPos = { 0 };
int width = this->_window->GetSizeWidth();
int height = this->_window->GetSizeHeight();
RECT desktopWorkingArea = Utils::DesktopInfos::GetPrimaryDesktopWorkingArea();
switch (pos)
{
case NotificationPosition::BottomLeft:
newPos.x = desktopWorkingArea.left + this->Margin;
newPos.y = desktopWorkingArea.bottom - height - this->Margin;
break;
case NotificationPosition::BottomCenter:
newPos.x = (desktopWorkingArea.right - width) / 2;
newPos.y = desktopWorkingArea.bottom - height - this->Margin;
break;
case NotificationPosition::BottomRight:
newPos.x = desktopWorkingArea.right - width - this->Margin;
newPos.y = desktopWorkingArea.bottom - height - this->Margin;
break;
case NotificationPosition::CenterLeft:
newPos.x = desktopWorkingArea.left + this->Margin;
newPos.y = (desktopWorkingArea.bottom - height) / 2;
break;
case NotificationPosition::Center:
newPos.x = (desktopWorkingArea.right - width) / 2;
newPos.y = (desktopWorkingArea.bottom - height) / 2;
break;
case NotificationPosition::CenterRight:
newPos.x = desktopWorkingArea.right - width - this->Margin;
newPos.y = (desktopWorkingArea.bottom - height) / 2;
break;
case NotificationPosition::TopLeft:
newPos.x = desktopWorkingArea.left + this->Margin;
newPos.y = desktopWorkingArea.top + this->Margin;
break;
case NotificationPosition::TopCenter:
newPos.x = (desktopWorkingArea.right - width) / 2;
newPos.y = desktopWorkingArea.top + this->Margin;
break;
case NotificationPosition::TopRight:
newPos.x = desktopWorkingArea.right - width - this->Margin;
newPos.y = desktopWorkingArea.top + this->Margin;
break;
default:
Log() << L"Illegal notification position given, use center as default.";
newPos.x = (desktopWorkingArea.right - width) / 2;
newPos.y = (desktopWorkingArea.bottom - height) / 2;
break;
}
this->_window->SetPosition(newPos);
}

void AoTOSD::NotificationWindowAoT::UpdateOSDWindowVisibleDuration(NotificationDuration duration) {
switch (duration)
{
case NotificationDuration::Short:
this->_window->SetVisibleDuration(500);
break;
case NotificationDuration::Normal:
this->_window->SetVisibleDuration(1000);
break;
case NotificationDuration::Long:
this->_window->SetVisibleDuration(2500);
break;
default:
Log() << L"Illegal visible duration given, use normal as default.";
this->_window->SetVisibleDuration(1500);
break;
}
}
24 changes: 24 additions & 0 deletions LenovoLegionToolkit.Lib.AoTOSD/AoTOSD.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include"Window/OSDWindow.h"

namespace LenovoLegionToolkit::Lib::AoTOSD {

public ref class NotificationWindowAoT {

public:
NotificationWindowAoT();
~NotificationWindowAoT();

void Show(::System::Drawing::Bitmap^ bitmap, NotificationPosition pos, NotificationDuration duration);

private:
Window::OSDWindow* _window;
static const int Margin = 16;

void UpdateOSDWindowPosition(NotificationPosition pos);
void UpdateOSDWindowVisibleDuration(NotificationDuration duration);

}; // public ref class NotificationWindowAoT

} // namespace LenovoLegionToolkit::Lib::AoTOSD
105 changes: 105 additions & 0 deletions LenovoLegionToolkit.Lib.AoTOSD/LenovoLegionToolkit.Lib.AoTOSD.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<EnableManagedPackageReferenceSupport>true</EnableManagedPackageReferenceSupport>
<ProjectGuid>{39D4480D-8241-4249-BA0B-5CD4F1D8E433}</ProjectGuid>
<Keyword>NetCoreCProj</Keyword>
<RootNamespace>LenovoLegionToolkitLibAoTOSD</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<TargetFramework>net8.0</TargetFramework>
<WindowsTargetPlatformMinVersion>7.0</WindowsTargetPlatformMinVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CLRSupport>NetCore</CLRSupport>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CLRSupport>NetCore</CLRSupport>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<CopyCppRuntimeToOutputDir>true</CopyCppRuntimeToOutputDir>
<CopyLocalProjectReference>true</CopyLocalProjectReference>
<CopyLocalDebugSymbols>true</CopyLocalDebugSymbols>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalUsingDirectories>$(SolutionDir)\LenovoLegionToolkit.Lib\bin\$(Platform)\$(Configuration)\net8.0-windows\win-x64\</AdditionalUsingDirectories>
</ClCompile>
<Link>
<AdditionalDependencies>User32.lib;gdiplus.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies />
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Animation\BasicAnimation.h" />
<ClInclude Include="Animation\FadeOutAnimation.h" />
<ClInclude Include="AoTOSD.h" />
<ClInclude Include="Utils\BitmapConverter.h" />
<ClInclude Include="Utils\DesktopInfos.h" />
<ClInclude Include="Utils\GlobalLogger.h" />
<ClInclude Include="Window\BasicWindow.h" />
<ClInclude Include="Window\LayeredWindow.h" />
<ClInclude Include="Window\OSDWindow.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Animation\BasicAnimation.cpp" />
<ClCompile Include="Animation\FadeOutAnimation.cpp" />
<ClCompile Include="AoTOSD.cpp" />
<ClCompile Include="Utils\BitmapConverter.cpp" />
<ClCompile Include="Utils\DesktopInfos.cpp" />
<ClCompile Include="Utils\GlobalLogger.cpp" />
<ClCompile Include="Window\BasicWindow.cpp" />
<ClCompile Include="Window\LayeredWindow.cpp" />
<ClCompile Include="Window\OSDWindow.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LenovoLegionToolkit.Lib\LenovoLegionToolkit.Lib.csproj">
<Project>{4b902ddc-0ebe-44b3-a53b-5ea176c7522b}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Loading
Loading