/*
	Copyright 2016, 2017 Michele "King_DuckZ" Santullo

	This file is part of MyCurry.

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

	MyCurry 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 General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with MyCurry.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "sizenotifiable.hpp"
#include "sizeratio.hpp"
#include "sdlmain.hpp"
#include <cassert>
#include <ciso646>

namespace cloonel {
	namespace implem {
	} //namespace implem

	namespace regbehaviours {
		///----------------------------------------------------------------------
		///----------------------------------------------------------------------
		void AutoRegister::Register (SizeNotifiableBase* parNotifiable) {
			assert(m_sdlmain);
#if !defined(NDEBUG)
			assert(not m_registered);
			m_registered = true;
#endif
			m_id = m_sdlmain->RegisterForResChange(parNotifiable);
		}

		///----------------------------------------------------------------------
		///----------------------------------------------------------------------
		void AutoRegister::Unregister() noexcept {
#if !defined(NDEBUG)
			assert(m_registered or not m_sdlmain);
			m_registered = false;
#endif
			if (m_sdlmain) {
				m_sdlmain->UnregisterForResChange(m_id);
			}
		}

		///----------------------------------------------------------------------
		///----------------------------------------------------------------------
		AutoRegister::AutoRegister (AutoRegister&& parOther, SizeNotifiableBase* parSwapTo) :
			m_sdlmain(nullptr),
			m_id(0)
#if !defined(NDEBUG)
			, m_registered(false)
#endif
		{
			std::swap(m_sdlmain, parOther.m_sdlmain);
			std::swap(m_id, parOther.m_id);
#if !defined(NDEBUG)
			std::swap(m_registered, parOther.m_registered);
#endif
			assert(m_sdlmain);
			m_sdlmain->SwapRegisteredForResChange(m_id, parSwapTo);
		}
	} //namespace regbehaviours

	///--------------------------------------------------------------------------
	///--------------------------------------------------------------------------
	void SizeNotifiableBase::NotifyResChanged (const SizeRatio& parSize) {
		m_scaleRatio = parSize.Ratio();
	}
} //namespace cloonel
