<commit_before>﻿/// @file
/// @version 3.4
/// 
/// @section LICENSE
/// 
/// This program is free software; you can redistribute it and/or modify it under
/// the terms of the BSD license: http://opensource.org/licenses/BSD-3-Clause

#ifdef _WINRT_WINDOW
#include <gtypes/Vector2.h>
#include <hltypes/harray.h>
#include <hltypes/hlog.h>
#include <hltypes/hstring.h>

#include "Keys.h"
#include "Platform.h"
#include "Rendersystem.h"
#include "SystemDelegate.h"
#include "Window.h"
#include "WinRT.h"
#include "WinRT_BaseApp.h"
#include "WinRT_Window.h"

using namespace Windows::Foundation;
using namespace Windows::Graphics::Display;
using namespace Windows::UI::Core;
#ifndef _WINP8
using namespace Windows::UI::ViewManagement;
#endif

namespace april
{
	WinRT_BaseApp::WinRT_BaseApp()
	{
		DisplayProperties::AutoRotationPreferences = (DisplayOrientations::Landscape | DisplayOrientations::LandscapeFlipped);
		this->scrollHorizontal = false;
		this->mouseMoveMessagesCount = 0;
		this->startTime = get_system_tick_count();
		this->currentButton = april::AK_NONE;
	}

	WinRT_BaseApp::~WinRT_BaseApp()
	{
	}

	void WinRT_BaseApp::assignEvents(CoreWindow^ window)
	{
		window->SizeChanged +=
			ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(
				this, &WinRT_BaseApp::OnWindowSizeChanged);
		window->VisibilityChanged +=
			ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(
				this, &WinRT_BaseApp::OnVisibilityChanged);
		window->PointerPressed +=
			ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(
				this, &WinRT_BaseApp::OnTouchDown);
		window->PointerReleased +=
			ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(
				this, &WinRT_BaseApp::OnTouchUp);
		window->PointerMoved +=
			ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(
				this, &WinRT_BaseApp::OnTouchMove);
		window->PointerWheelChanged +=
			ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(
				this, &WinRT_BaseApp::OnMouseScroll);
		window->KeyDown +=
			ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(
				this, &WinRT_BaseApp::OnKeyDown);
		window->KeyUp +=
			ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(
				this, &WinRT_BaseApp::OnKeyUp);
		window->CharacterReceived +=
			ref new TypedEventHandler<CoreWindow^, CharacterReceivedEventArgs^>(
				this, &WinRT_BaseApp::OnCharacterReceived);
		window->Closed +=
			ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(
				this, &WinRT_BaseApp::OnWindowClosed);
		DisplayProperties::OrientationChanged +=
			ref new DisplayPropertiesEventHandler(
				this, &WinRT_BaseApp::OnOrientationChanged);
		InputPane::GetForCurrentView()->Showing +=
			ref new TypedEventHandler<InputPane^, InputPaneVisibilityEventArgs^>(
				this, &WinRT_BaseApp::OnVirtualKeyboardShow);
		InputPane::GetForCurrentView()->Hiding +=
			ref new TypedEventHandler<InputPane^, InputPaneVisibilityEventArgs^>(
				this, &WinRT_BaseApp::OnVirtualKeyboardHide);
	}

	void WinRT_BaseApp::OnSuspend(_In_ Object^ sender, _In_ SuspendingEventArgs^ args)
	{
		this->handleFocusChange(false);
	}

	void WinRT_BaseApp::OnResume(_In_ Object^ sender, _In_ Object^ args)
	{
		this->handleFocusChange(true);
	}

	void WinRT_BaseApp::OnWindowClosed(_In_ CoreWindow^ sender, _In_ CoreWindowEventArgs^ args)
	{
		if (april::window != NULL)
		{
			april::window->handleQuitRequest(false);
		}
		args->Handled = true;
	}

	void WinRT_BaseApp::handleFocusChange(bool focused)
	{
		if (april::rendersys != NULL && focused)
		{
			april::rendersys->reset();
		}
		if (april::window != NULL && april::window->isFocused() != focused && WinRT::Interface->canSuspendResume())
		{
			april::window->handleFocusChangeEvent(focused);
		}
	}

	void WinRT_BaseApp::OnWindowSizeChanged(_In_ CoreWindow^ sender, _In_ WindowSizeChangedEventArgs^ args)
	{
		if (april::rendersys != NULL)
		{
			april::rendersys->reset();
		}
		WinRT::Interface->updateViewState();
		if (april::window != NULL)
		{
			((WinRT_Window*)april::window)->changeSize((int)args->Size.Width, (int)args->Size.Height);
		}
		args->Handled = true;
	}
	
	void WinRT_BaseApp::OnVisibilityChanged(_In_ CoreWindow^ sender, _In_ VisibilityChangedEventArgs^ args)
	{
		WinRT::Interface->updateViewState();
		args->Handled = true;
	}

	void WinRT_BaseApp::OnOrientationChanged(_In_ Object^ args)<commit_msg>- fixed another WinRT DPI-related bug<commit_after>﻿/// @file
/// @version 3.4
/// 
/// @section LICENSE
/// 
/// This program is free software; you can redistribute it and/or modify it under
/// the terms of the BSD license: http://opensource.org/licenses/BSD-3-Clause

#ifdef _WINRT_WINDOW
#include <gtypes/Vector2.h>
#include <hltypes/harray.h>
#include <hltypes/hlog.h>
#include <hltypes/hstring.h>

#include "Keys.h"
#include "Platform.h"
#include "Rendersystem.h"
#include "SystemDelegate.h"
#include "Window.h"
#include "WinRT.h"
#include "WinRT_BaseApp.h"
#include "WinRT_Window.h"

using namespace Windows::Foundation;
using namespace Windows::Graphics::Display;
using namespace Windows::UI::Core;
#ifndef _WINP8
using namespace Windows::UI::ViewManagement;
#endif

namespace april
{
	WinRT_BaseApp::WinRT_BaseApp()
	{
		DisplayProperties::AutoRotationPreferences = (DisplayOrientations::Landscape | DisplayOrientations::LandscapeFlipped);
		this->scrollHorizontal = false;
		this->mouseMoveMessagesCount = 0;
		this->startTime = get_system_tick_count();
		this->currentButton = april::AK_NONE;
	}

	WinRT_BaseApp::~WinRT_BaseApp()
	{
	}

	void WinRT_BaseApp::assignEvents(CoreWindow^ window)
	{
		window->SizeChanged +=
			ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(
				this, &WinRT_BaseApp::OnWindowSizeChanged);
		window->VisibilityChanged +=
			ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(
				this, &WinRT_BaseApp::OnVisibilityChanged);
		window->PointerPressed +=
			ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(
				this, &WinRT_BaseApp::OnTouchDown);
		window->PointerReleased +=
			ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(
				this, &WinRT_BaseApp::OnTouchUp);
		window->PointerMoved +=
			ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(
				this, &WinRT_BaseApp::OnTouchMove);
		window->PointerWheelChanged +=
			ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(
				this, &WinRT_BaseApp::OnMouseScroll);
		window->KeyDown +=
			ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(
				this, &WinRT_BaseApp::OnKeyDown);
		window->KeyUp +=
			ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(
				this, &WinRT_BaseApp::OnKeyUp);
		window->CharacterReceived +=
			ref new TypedEventHandler<CoreWindow^, CharacterReceivedEventArgs^>(
				this, &WinRT_BaseApp::OnCharacterReceived);
		window->Closed +=
			ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(
				this, &WinRT_BaseApp::OnWindowClosed);
		DisplayProperties::OrientationChanged +=
			ref new DisplayPropertiesEventHandler(
				this, &WinRT_BaseApp::OnOrientationChanged);
		InputPane::GetForCurrentView()->Showing +=
			ref new TypedEventHandler<InputPane^, InputPaneVisibilityEventArgs^>(
				this, &WinRT_BaseApp::OnVirtualKeyboardShow);
		InputPane::GetForCurrentView()->Hiding +=
			ref new TypedEventHandler<InputPane^, InputPaneVisibilityEventArgs^>(
				this, &WinRT_BaseApp::OnVirtualKeyboardHide);
	}

	void WinRT_BaseApp::OnSuspend(_In_ Object^ sender, _In_ SuspendingEventArgs^ args)
	{
		this->handleFocusChange(false);
	}

	void WinRT_BaseApp::OnResume(_In_ Object^ sender, _In_ Object^ args)
	{
		this->handleFocusChange(true);
	}

	void WinRT_BaseApp::OnWindowClosed(_In_ CoreWindow^ sender, _In_ CoreWindowEventArgs^ args)
	{
		if (april::window != NULL)
		{
			april::window->handleQuitRequest(false);
		}
		args->Handled = true;
	}

	void WinRT_BaseApp::handleFocusChange(bool focused)
	{
		if (april::rendersys != NULL && focused)
		{
			april::rendersys->reset();
		}
		if (april::window != NULL && april::window->isFocused() != focused && WinRT::Interface->canSuspendResume())
		{
			april::window->handleFocusChangeEvent(focused);
		}
	}

	void WinRT_BaseApp::OnWindowSizeChanged(_In_ CoreWindow^ sender, _In_ WindowSizeChangedEventArgs^ args)
	{
		if (april::rendersys != NULL)
		{
			april::rendersys->reset();
		}
		WinRT::Interface->updateViewState();
		if (april::window != NULL)
		{
			april::SystemInfo info = april::getSystemInfo();
			int width = (int)(args->Size.Width * info.displayDpi / 96.0f);
			int height = (int)(args->Size.Height * info.displayDpi / 96.0f);
			((WinRT_Window*)april::window)->changeSize(width, height);
		}
		args->Handled = true;
	}
	
	void WinRT_BaseApp::OnVisibilityChanged(_In_ CoreWindow^ sender, _In_ VisibilityChangedEventArgs^ args)
	{
		WinRT::Interface->updateViewState();
		args->Handled = true;
	}

	void WinRT_BaseApp::OnOrientationChanged(_In_ Object^ args)
{'fraction_non_alphanumeric': 0.13351375732972484, 'fraction_numerical': 0.0020297699594046007, 'mean_word_length': 5.838087895142637, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6015030', 'n_tokens_mistral': 3122, 'n_tokens_neox': 2866, 'n_words': 521}