<commit_before>/*!
	@file
	@author		<NAME>
	@date		11/2007
*/
/*
	This file is part of MyGUI.

	MyGUI is free software: you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	MyGUI is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "MyGUI_Precompiled.h"
#include "MyGUI_Window.h"
#include "MyGUI_Macros.h"
#include "MyGUI_Gui.h"
#include "MyGUI_ControllerManager.h"
#include "MyGUI_InputManager.h"
#include "MyGUI_WidgetManager.h"
#include "MyGUI_ResourceSkin.h"

namespace MyGUI
{

	const float WINDOW_ALPHA_ACTIVE = ALPHA_MAX;
	const float WINDOW_ALPHA_FOCUS = 0.7f;
	const float WINDOW_ALPHA_DEACTIVE = 0.3f;
	const float WINDOW_SPEED_COEF = 3.0f;

	const int WINDOW_SNAP_DISTANSE = 10;

	Window::Window() :
		mWidgetCaption(nullptr),
		mMouseRootFocus(false),
		mKeyRootFocus(false),
		mIsAutoAlpha(false),
		mSnap(false),
		mAnimateSmooth(false),
		mClient(nullptr)
	{
	}

	void Window::initialiseOverride()
	{
		Base::initialiseOverride();

		// FIXME нам нужен фокус клавы
		setNeedKeyFocus(true);

		// дефолтные размеры
		mMinmax.set(0, 0, (std::numeric_limits<int>::max)(), (std::numeric_limits<int>::max)());

		bool main_move = false;
		if (isUserString("MainMove"))
		{
			setUserString("Scale", "1 1 0 0");
			main_move = true;
		}

		assignWidget(mClient, "Client");
		if (mClient != nullptr)
		{
			if (main_move)
			{
				mClient->setUserString("Scale", "1 1 0 0");
				mClient->eventMouseButtonPressed += newDelegate(this, &Window::notifyMousePressed);
				mClient->eventMouseDrag += newDelegate(this, &Window::notifyMouseDrag);
			}
			setWidgetClient(mClient);
		}

		assignWidget(mWidgetCaption, "Caption");
		if (mWidgetCaption != nullptr)
		{
			mWidgetCaption->eventMouseButtonPressed += newDelegate(this, &Window::notifyMousePressed);
			mWidgetCaption->eventMouseDrag += newDelegate(this, &Window::notifyMouseDrag);
		}

		VectorWidgetPtr buttons = getSkinWidgetsByName("Button");
		for (VectorWidgetPtr::iterator iter = buttons.begin(); iter != buttons.end(); ++iter)
		{
			(*iter)->eventMouseButtonClick += newDelegate(this, &Window::notifyPressedButtonEvent);
		}

		VectorWidgetPtr actions = getSkinWidgetsByName("Action");
		for (VectorWidgetPtr::iterator iter = actions.begin(); iter != actions.end(); ++iter)
		{
			(*iter)->eventMouseButtonPressed += newDelegate(this, &Window::notifyMousePressed);
			(*iter)->eventMouseDrag += newDelegate(this, &Window::notifyMouseDrag);
		}
	}

	void Window::shutdownOverride()
	{
		mClient = nullptr;
		mWidgetCaption = nullptr;

		Base::shutdownOverride();
	}

	void Window::onMouseChangeRootFocus(bool _focus)
	{
		mMouseRootFocus = _focus;
		updateAlpha();

		Base::onMouseChangeRootFocus(_focus);
	}

	void Window::onKeyChangeRootFocus(bool _focus)
	{
		mKeyRootFocus = _focus;
		updateAlpha();

		Base::onKeyChangeRootFocus(_focus);
	}

	void Window::onMouseDrag(int _left, int _top)
	{
		// на тот случай, если двигать окно, можно за любое место виджета
		notifyMouseDrag(this, _left, _top);

		Base::onMouseDrag(_left, _top);
	}

	void Window::onMouseButtonPressed(int _left, int _top, MouseButton _id)
	{
		notifyMousePressed(this, _left, _top, _id);

		Base::onMouseButtonPressed(_left, _top, _id);
	}

	void Window::notifyMousePressed(MyGUI::Widget* _sender, int _left, int _top, MouseButton _id)
	{
		if (MouseButton::Left == _id)
		{
			mPreActionCoord = mCoord;
			mCurrentActionScale = IntCoord::parse(_sender->getUserString("Scale"));
		}
	}

	void Window::notifyPressedButtonEvent(MyGUI::Widget* _sender)
	{
		eventWindowButtonPressed(this, _sender->getUserString("Event"));
	}

	void Window::notifyMouseDrag(MyGUI::Widget* _sender, int _left, int _top)
	{
		const IntPoint& point = InputManager::getInstance().getLastLeftPressed();

		IntCoord coord = mCurrentActionScale;
		coord.left *= (_left - point.left);
		coord.top *= (_top - point.top);
		coord.width *= (_left - point.left);
		coord.height *= (_top - point.top);

		if (coord.left == 0 && coord.top == 0)<commit_msg>don't send eventWindowChangeCoord if Window coord wasn't changed<commit_after>/*!
	@file
	@author		<NAME>
	@date		11/2007
*/
/*
	This file is part of MyGUI.

	MyGUI is free software: you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	MyGUI is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "MyGUI_Precompiled.h"
#include "MyGUI_Window.h"
#include "MyGUI_Macros.h"
#include "MyGUI_Gui.h"
#include "MyGUI_ControllerManager.h"
#include "MyGUI_InputManager.h"
#include "MyGUI_WidgetManager.h"
#include "MyGUI_ResourceSkin.h"

namespace MyGUI
{

	const float WINDOW_ALPHA_ACTIVE = ALPHA_MAX;
	const float WINDOW_ALPHA_FOCUS = 0.7f;
	const float WINDOW_ALPHA_DEACTIVE = 0.3f;
	const float WINDOW_SPEED_COEF = 3.0f;

	const int WINDOW_SNAP_DISTANSE = 10;

	Window::Window() :
		mWidgetCaption(nullptr),
		mMouseRootFocus(false),
		mKeyRootFocus(false),
		mIsAutoAlpha(false),
		mSnap(false),
		mAnimateSmooth(false),
		mClient(nullptr)
	{
	}

	void Window::initialiseOverride()
	{
		Base::initialiseOverride();

		// FIXME нам нужен фокус клавы
		setNeedKeyFocus(true);

		// дефолтные размеры
		mMinmax.set(0, 0, (std::numeric_limits<int>::max)(), (std::numeric_limits<int>::max)());

		bool main_move = false;
		if (isUserString("MainMove"))
		{
			setUserString("Scale", "1 1 0 0");
			main_move = true;
		}

		assignWidget(mClient, "Client");
		if (mClient != nullptr)
		{
			if (main_move)
			{
				mClient->setUserString("Scale", "1 1 0 0");
				mClient->eventMouseButtonPressed += newDelegate(this, &Window::notifyMousePressed);
				mClient->eventMouseDrag += newDelegate(this, &Window::notifyMouseDrag);
			}
			setWidgetClient(mClient);
		}

		assignWidget(mWidgetCaption, "Caption");
		if (mWidgetCaption != nullptr)
		{
			mWidgetCaption->eventMouseButtonPressed += newDelegate(this, &Window::notifyMousePressed);
			mWidgetCaption->eventMouseDrag += newDelegate(this, &Window::notifyMouseDrag);
		}

		VectorWidgetPtr buttons = getSkinWidgetsByName("Button");
		for (VectorWidgetPtr::iterator iter = buttons.begin(); iter != buttons.end(); ++iter)
		{
			(*iter)->eventMouseButtonClick += newDelegate(this, &Window::notifyPressedButtonEvent);
		}

		VectorWidgetPtr actions = getSkinWidgetsByName("Action");
		for (VectorWidgetPtr::iterator iter = actions.begin(); iter != actions.end(); ++iter)
		{
			(*iter)->eventMouseButtonPressed += newDelegate(this, &Window::notifyMousePressed);
			(*iter)->eventMouseDrag += newDelegate(this, &Window::notifyMouseDrag);
		}
	}

	void Window::shutdownOverride()
	{
		mClient = nullptr;
		mWidgetCaption = nullptr;

		Base::shutdownOverride();
	}

	void Window::onMouseChangeRootFocus(bool _focus)
	{
		mMouseRootFocus = _focus;
		updateAlpha();

		Base::onMouseChangeRootFocus(_focus);
	}

	void Window::onKeyChangeRootFocus(bool _focus)
	{
		mKeyRootFocus = _focus;
		updateAlpha();

		Base::onKeyChangeRootFocus(_focus);
	}

	void Window::onMouseDrag(int _left, int _top)
	{
		// на тот случай, если двигать окно, можно за любое место виджета
		notifyMouseDrag(this, _left, _top);

		Base::onMouseDrag(_left, _top);
	}

	void Window::onMouseButtonPressed(int _left, int _top, MouseButton _id)
	{
		notifyMousePressed(this, _left, _top, _id);

		Base::onMouseButtonPressed(_left, _top, _id);
	}

	void Window::notifyMousePressed(MyGUI::Widget* _sender, int _left, int _top, MouseButton _id)
	{
		if (MouseButton::Left == _id)
		{
			mPreActionCoord = mCoord;
			mCurrentActionScale = IntCoord::parse(_sender->getUserString("Scale"));
		}
	}

	void Window::notifyPressedButtonEvent(MyGUI::Widget* _sender)
	{
		eventWindowButtonPressed(this, _sender->getUserString("Event"));
	}

	void Window::notifyMouseDrag(MyGUI::Widget* _sender, int _left, int _top)
	{
		const IntPoint& point = InputManager::getInstance().getLastLeftPressed();

		IntCoord coord = mCurrentActionScale;
		coord.left *= (_left - point.left);
		coord.top *= (_top - point.top);
		coord.width *= (_left - point.left);
		coord.height *= (_top - point.top);

		if (coord.empty()) return;

		if (coord.left == 0 && coord.top == 0)
{'fraction_non_alphanumeric': 0.12612412568002665, 'fraction_numerical': 0.005995336960142112, 'mean_word_length': 4.985382059800664, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2467978', 'n_tokens_mistral': 3311, 'n_tokens_neox': 3039, 'n_words': 711}