Moved mouse delta code to be more async
This commit is contained in:
parent
631f3b931d
commit
5f3c03a8e8
@ -40,8 +40,8 @@ public:
|
||||
bool m_bKeysInit = false;
|
||||
int m_iMouseX;
|
||||
int m_iMouseY;
|
||||
int mouse_dx;
|
||||
int mouse_dy;
|
||||
[[deprecated]] int mouse_dx;
|
||||
[[deprecated]] int mouse_dy;
|
||||
bool fake_scroll = false;
|
||||
|
||||
glez::rgba GetColor();
|
||||
|
@ -52,6 +52,7 @@ public:
|
||||
virtual void OnKeyPress(CatKey key, bool repeat) override;
|
||||
virtual void OnMouseEnter() override;
|
||||
virtual void OnMouseLeave() override;
|
||||
virtual void OnMouseMove(std::pair<int, int>) override;
|
||||
virtual void Draw(int x, int y) override;
|
||||
virtual void Update() override;
|
||||
virtual void MoveChildren() override;
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
Logo(IWidget*);
|
||||
virtual bool AlwaysVisible() override;
|
||||
virtual void Draw(int x, int y) override;
|
||||
virtual void Update() override;
|
||||
virtual void OnMouseMove(std::pair<int, int>) override;
|
||||
glez::texture texture;
|
||||
};
|
||||
|
||||
|
@ -49,6 +49,7 @@ public:
|
||||
virtual void OnMouseLeave();
|
||||
virtual void OnMousePress();
|
||||
virtual void OnMouseRelease();
|
||||
virtual void OnMouseMove(std::pair<int, int>);
|
||||
virtual void Update();
|
||||
virtual void HandleCustomEvent(std::string_view event);
|
||||
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
inline virtual void OnMouseLeave() { this->hover = false; }
|
||||
inline virtual void OnMousePress() { this->press = true; }
|
||||
inline virtual void OnMouseRelease() { this->press = false; }
|
||||
inline virtual void OnMouseMove(std::pair<int, int>) { }
|
||||
inline virtual void OnKeyPress(CatKey key, bool repeat) {};
|
||||
inline virtual void OnKeyRelease(CatKey key) {};
|
||||
inline virtual void OnFocusGain() { this->focus = true; }
|
||||
|
@ -48,6 +48,7 @@ public:
|
||||
virtual void OnMouseLeave() = 0;
|
||||
virtual void OnMousePress() = 0;
|
||||
virtual void OnMouseRelease() = 0;
|
||||
virtual void OnMouseMove(std::pair<int, int>) = 0;
|
||||
virtual void OnKeyPress(CatKey key, bool repeat) = 0;
|
||||
virtual void OnKeyRelease(CatKey key) = 0;
|
||||
virtual void OnFocusGain() = 0;
|
||||
|
@ -29,10 +29,8 @@ public:
|
||||
CTitleBar(IWidget* parent, std::string title);
|
||||
|
||||
virtual void Draw(int x, int y);
|
||||
virtual void OnMouseMove(std::pair<int, int>);
|
||||
virtual void Update();
|
||||
|
||||
std::string m_strTitle;
|
||||
int m_iDraggingStage;
|
||||
int m_nLastX;
|
||||
int m_nLastY;
|
||||
};
|
||||
|
@ -152,8 +152,12 @@ void Canvas::Update() {
|
||||
|
||||
auto nmouse = input::GetMouse();
|
||||
|
||||
mouse_dx = nmouse.first - m_iMouseX;
|
||||
mouse_dy = nmouse.second - m_iMouseY;
|
||||
{
|
||||
auto mouse_delta = std::make_pair(nmouse.first - m_iMouseX, nmouse.second - m_iMouseY);
|
||||
mouse_dx = mouse_delta.first, mouse_dy = mouse_delta.second;
|
||||
if (mouse_delta.first || mouse_delta.second)
|
||||
this->OnMouseMove(mouse_delta);
|
||||
}
|
||||
|
||||
m_iMouseX = nmouse.first;
|
||||
m_iMouseY = nmouse.second;
|
||||
|
@ -267,14 +267,17 @@ void List::SetParent(IWidget* parent) {
|
||||
root_list = this;
|
||||
}
|
||||
|
||||
void List::Update() {
|
||||
CBaseContainer::Update();
|
||||
void List::OnMouseMove(std::pair<int, int> delta) {
|
||||
if (IsPressed() && root_list == this) {
|
||||
const auto& offset = root_list->GetOffset();
|
||||
root_list->SetOffset(offset.first + this->GetCanvas()->mouse_dx, offset.second + this->GetCanvas()->mouse_dy);
|
||||
root_list->SetOffset(offset.first + delta.first, offset.second + delta.second);
|
||||
}
|
||||
}
|
||||
|
||||
void List::Update() {
|
||||
CBaseContainer::Update();
|
||||
}
|
||||
|
||||
void List::MoveChildren() {
|
||||
int accy = 2;
|
||||
int j = 0;
|
||||
|
@ -44,11 +44,11 @@ void Logo::Draw(int x, int y) {
|
||||
glez::draw::rect_textured(x, y, embeded_logo_png_rgba.width, embeded_logo_png_rgba.height, this->GetCanvas()->GetColor(), this->texture, 0, 0, embeded_logo_png_rgba.width, embeded_logo_png_rgba.height, 0.0f);
|
||||
}
|
||||
|
||||
void Logo::Update() {
|
||||
void Logo::OnMouseMove(std::pair<int, int> delta) {
|
||||
if (this->IsPressed()) {
|
||||
auto offset = GetOffset();
|
||||
offset.first += this->GetCanvas()->mouse_dx;
|
||||
offset.second += this->GetCanvas()->mouse_dy;
|
||||
offset.first += delta.first;
|
||||
offset.second += delta.second;
|
||||
SetOffset(offset.first, offset.second);
|
||||
}
|
||||
}
|
||||
|
@ -185,6 +185,12 @@ void CBaseContainer::OnMouseRelease() {
|
||||
GetPressedChild()->OnMouseRelease();
|
||||
}
|
||||
|
||||
void CBaseContainer::OnMouseMove(std::pair<int, int> delta) {
|
||||
CBaseWidget::OnMouseMove(delta);
|
||||
for (auto* i : this->m_children)
|
||||
i->OnMouseMove(delta);
|
||||
}
|
||||
|
||||
void CBaseContainer::PressOn(IWidget* child) {
|
||||
m_pPressedChild = child;
|
||||
if (child) {
|
||||
|
@ -26,9 +26,6 @@
|
||||
CTitleBar::CTitleBar(IWidget* parent, std::string title)
|
||||
: CBaseWidget("titlebar", parent) {
|
||||
m_strTitle = title;
|
||||
m_iDraggingStage = 0;
|
||||
m_nLastX = 0;
|
||||
m_nLastY = 0;
|
||||
SetPositionMode(ABSOLUTE);
|
||||
}
|
||||
|
||||
@ -40,23 +37,16 @@ void CTitleBar::Draw(int x, int y) {
|
||||
glez::draw::string(x + (size.first - l) / 2, y + TITLEBAR_PADDING_H, m_strTitle, this->GetCanvas()->GetFont(), glez::color::white, nullptr, nullptr);
|
||||
}
|
||||
|
||||
void CTitleBar::OnMouseMove(std::pair<int, int> delta) {
|
||||
if (this->IsPressed()) {
|
||||
auto offset = GetParent()->GetOffset();
|
||||
GetParent()->SetOffset(offset.first + delta.first, offset.second + delta.second);
|
||||
}
|
||||
}
|
||||
|
||||
void CTitleBar::Update() {
|
||||
auto psize = GetParent()->GetSize();
|
||||
float l, h;
|
||||
this->GetCanvas()->GetFont().stringSize(m_strTitle, &l, &h);
|
||||
SetSize(psize.first, 2 * TITLEBAR_PADDING_H + h);
|
||||
if (!IsPressed()) {
|
||||
m_iDraggingStage = 0;
|
||||
return;
|
||||
}
|
||||
if (m_iDraggingStage == 0) {
|
||||
m_iDraggingStage = 1;
|
||||
} else {
|
||||
int dx = this->GetCanvas()->m_iMouseX - m_nLastX;
|
||||
int dy = this->GetCanvas()->m_iMouseY - m_nLastY;
|
||||
auto offset = GetParent()->GetOffset();
|
||||
GetParent()->SetOffset(offset.first + dx, offset.second + dy);
|
||||
}
|
||||
m_nLastX = this->GetCanvas()->m_iMouseX;
|
||||
m_nLastY = this->GetCanvas()->m_iMouseY;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user