88 lines
1.8 KiB
C++
88 lines
1.8 KiB
C++
#include <include.h>
|
|
|
|
using namespace window;
|
|
|
|
void c_manager::paint()
|
|
{
|
|
const auto cursor_pos = g::p::input_mgr.get_cursor_pos();
|
|
|
|
const auto try_drag = [this](c_base* window, const math::position_t<int> new_position) -> bool
|
|
{
|
|
const auto screen_size = g::p::screen;
|
|
|
|
const auto my_position = window->_position();
|
|
const auto my_dimension = window->_dimension();
|
|
|
|
const float min_x = 2.0f;
|
|
const float max_x = (screen_size.w - 2.0f);
|
|
|
|
const float min_y = 2.0f;
|
|
const float max_y = (screen_size.h - 2.0f);
|
|
|
|
auto my_new_position = math::position_t<int>{
|
|
new_position.x - my_dimension.w / 2, new_position.y
|
|
};
|
|
|
|
if (my_new_position.x < min_x)
|
|
my_new_position.x = min_x;
|
|
|
|
if ((my_new_position.x + my_dimension.w) > max_x)
|
|
my_new_position.x = (max_x - my_dimension.w);
|
|
|
|
if (my_new_position.y < min_y)
|
|
my_new_position.y = min_y;
|
|
|
|
if ((my_new_position.y + my_dimension.h) > max_y)
|
|
my_new_position.y = (max_y - my_dimension.h);
|
|
|
|
window->_position() = my_new_position;
|
|
|
|
return true;
|
|
};
|
|
|
|
for (auto i = 0; i < m_list.count(); i++)
|
|
{
|
|
auto* const wnd_ptr = m_list[i];
|
|
|
|
if (wnd_ptr == nullptr)
|
|
continue;
|
|
|
|
auto* const wnd = *wnd_ptr;
|
|
|
|
if (wnd == nullptr)
|
|
continue;
|
|
|
|
wnd->paint();
|
|
|
|
if (wnd->has_flag(fl::draggable))
|
|
{
|
|
const auto position = wnd->_position();
|
|
const auto dimension = wnd->_dimension();
|
|
|
|
if (wnd->has_flag(fl::dragging) == false)
|
|
{
|
|
//
|
|
// not being dragged currently.
|
|
//
|
|
|
|
if (g::p::input_mgr.is_button_down(VK_LBUTTON))
|
|
{
|
|
if (in_range<int>(cursor_pos, std::make_pair(position, math::dimension_t<int>{dimension.w, 15})))
|
|
wnd->set_flag(fl::dragging, true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// is being dragged.
|
|
//
|
|
|
|
if (!g::p::input_mgr.is_button_down(VK_LBUTTON))
|
|
wnd->set_flag(fl::dragging, false);
|
|
else
|
|
try_drag(wnd, cursor_pos);
|
|
}
|
|
}
|
|
}
|
|
}
|