77 lines
1.7 KiB
C++
77 lines
1.7 KiB
C++
#include "dl_tool_ctrl_2d.h"
|
|
|
|
#ifndef DL_DISABLE_RENDER
|
|
#include "system/dl_time.h"
|
|
#include "system/dl_system.h"
|
|
|
|
namespace dl::Tool
|
|
{
|
|
|
|
void Controller2d::Update(Coor* coor)
|
|
{
|
|
if (_bMoveWasd)
|
|
{
|
|
float dt = _moveSpeed * g_time->GetDelta();
|
|
if (g_input->KeyState(KeyCode::LEFT_SHIFT))
|
|
dt *= _moveSpeedShift;
|
|
if (g_input->KeyState(KeyCode::W))
|
|
coor->DtPosition({ 0, dt });
|
|
if (g_input->KeyState(KeyCode::S))
|
|
coor->DtPosition({ 0, -dt });
|
|
if (g_input->KeyState(KeyCode::A))
|
|
coor->DtPosition({ dt, 0 });
|
|
if (g_input->KeyState(KeyCode::D))
|
|
coor->DtPosition({ -dt, 0 });
|
|
}
|
|
if (_bScaleWheel)
|
|
{
|
|
Float y = g_input->GetScrollDelta()[1];
|
|
if (y)
|
|
{
|
|
Position pos0;
|
|
if (_bScaleWithMouse)
|
|
pos0 = toPosition(g_input->GetCursorPosition());
|
|
else
|
|
pos0 = toPosition(g_system->GetWindowSize()) * 0.5f;
|
|
|
|
Position pos_in_map = coor->WorldToThis(pos0);
|
|
|
|
if (_scaleLevel.empty())
|
|
{
|
|
coor->DtScale(-y * _scaleSpeed * g_time->GetDelta());
|
|
float s = std::clamp(coor->GetScale()[0], _scaleRange[0], _scaleRange[1]);
|
|
coor->SetScale(s);
|
|
}
|
|
else
|
|
{
|
|
if (y > 0 && _scaleLevelCur > 0)
|
|
--_scaleLevelCur;
|
|
else if (y < 0 && _scaleLevelCur + 1 < _scaleLevel.size())
|
|
++_scaleLevelCur;
|
|
coor->SetScale(_scaleLevel[_scaleLevelCur]);
|
|
}
|
|
|
|
Position pos1 = coor->ThisToWorld(pos_in_map);
|
|
coor->DtPosition(pos0 - pos1);
|
|
}
|
|
}
|
|
if (_keyDrag != MouseCode::UNKNOWN)
|
|
{
|
|
_drag._key = _keyDrag;
|
|
_drag.Update(coor, true);
|
|
}
|
|
}
|
|
|
|
void Controller2d::UpdateLimit(Coor* coor, const Size& size_map)
|
|
{
|
|
Position size_window = toPosition(g_system->GetWindowSize());
|
|
Position size = toPosition(size_map) * _scaleLevel[_scaleLevelCur];
|
|
|
|
if (Each::Less(size, size_window))
|
|
{
|
|
coor->SetPosition(size_window * 0.5f);
|
|
}
|
|
}
|
|
|
|
}
|
|
#endif |