58 lines
1.8 KiB
C++
58 lines
1.8 KiB
C++
/*
|
|
Copyright 2016-2018 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 "world_moveable.hpp"
|
|
#include <cassert>
|
|
|
|
namespace curry {
|
|
WorldMoveable::WorldMoveable (const WorldSizeNotifiable::DeferredRegister& parDeferredRegister) :
|
|
WorldSizeNotifiable(parDeferredRegister),
|
|
m_position(vec2f(0.0f), vec2f(0.0f), vec2f(0.0f)),
|
|
m_world(parDeferredRegister.world())
|
|
{
|
|
assert(m_world);
|
|
}
|
|
void WorldMoveable::world_size_changed (const vec2us&, const vec2i& parPixelSize) {
|
|
m_position.change_minmax(m_position.get_min(), vector_cast<vec2f>(parPixelSize));
|
|
}
|
|
|
|
void WorldMoveable::set_position (const vec2f& parPos) {
|
|
m_position = parPos;
|
|
}
|
|
|
|
const vec2f& WorldMoveable::position() const {
|
|
return m_position.get();
|
|
}
|
|
|
|
void WorldMoveable::update_moveable_size (const vec2f& parOldSz, const vec2f& parNewSz) {
|
|
if (m_position.get_min() != m_position.get_max())
|
|
m_position.change_minmax(m_position.get_min(), m_position.get_max() + parOldSz - parNewSz);
|
|
}
|
|
|
|
WorldGrid& WorldMoveable::world() {
|
|
assert(m_world);
|
|
return *m_world;
|
|
}
|
|
|
|
const WorldGrid& WorldMoveable::world() const {
|
|
assert(m_world);
|
|
return *m_world;
|
|
}
|
|
} //namespace curry
|