Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 8e76379

Browse files
committed
Don't store mouse position separately in BuyMenuGUI and ObjectPickerGUI - I don't even why to begin with honestly
1 parent 8da2323 commit 8e76379

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

Menus/BuyMenuGUI.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ void BuyMenuGUI::Clear()
115115
m_pClearButton = 0;
116116
m_Loadouts.clear();
117117
m_PurchaseMade = false;
118-
m_CursorPos.Reset();
119118

120119
m_EnforceMaxPassengersConstraint = true;
121120
m_EnforceMaxMassConstraint = true;
@@ -1019,9 +1018,9 @@ void BuyMenuGUI::Update()
10191018
/////////////////////////////////////////////////////
10201019
// Mouse cursor logic
10211020

1022-
int mouseX, mouseY;
1023-
m_pGUIInput->GetMousePosition(&mouseX, &mouseY);
1024-
m_CursorPos.SetXY(mouseX, mouseY);
1021+
int mousePosX;
1022+
int mousePosY;
1023+
m_pGUIInput->GetMousePosition(&mousePosX, &mousePosY);
10251024

10261025
////////////////////////////////////////////
10271026
// Notification blinking logic
@@ -1227,7 +1226,7 @@ void BuyMenuGUI::Update()
12271226
for (int category = 0; category < CATEGORYCOUNT; ++category) {
12281227
if (!m_pCategoryTabs[category]->IsEnabled()) {
12291228
if (m_MenuCategory == category) { m_pCategoryTabs[m_MenuCategory]->SetEnabled(true); }
1230-
if (m_pCategoryTabs[category]->PointInside(m_CursorPos.GetFloorIntX() + 3, m_CursorPos.GetFloorIntY())) {
1229+
if (m_pCategoryTabs[category]->PointInside(mousePosX + 3, mousePosY)) {
12311230
if (m_pController->IsState(PRESS_PRIMARY)) {
12321231
m_MenuCategory = category;
12331232
m_pCategoryTabs[m_MenuCategory]->SetFocus();
@@ -1715,7 +1714,7 @@ void BuyMenuGUI::Update()
17151714
if (m_MenuEnabled == ENABLED) {
17161715
if (m_pController->IsState(WEAPON_RELOAD)) {
17171716
TryPurchase();
1718-
} else if (m_pController->IsMouseControlled() && (m_pController->IsState(PRESS_PRIMARY) || m_pController->IsState(PRESS_SECONDARY)) && m_CursorPos.m_X > m_pParentBox->GetWidth()) {
1717+
} else if (m_pController->IsMouseControlled() && (m_pController->IsState(PRESS_PRIMARY) || m_pController->IsState(PRESS_SECONDARY)) && mousePosX > m_pParentBox->GetWidth()) {
17191718
if (m_pController->IsState(PRESS_PRIMARY)) {
17201719
TryPurchase();
17211720
} else {
@@ -1822,7 +1821,7 @@ void BuyMenuGUI::Update()
18221821
m_pShopList->SetFocus();
18231822
m_MenuFocus = ITEMS;
18241823

1825-
GUIListPanel::Item *pItem = m_pShopList->GetItem(m_CursorPos.m_X, m_CursorPos.m_Y);
1824+
GUIListPanel::Item *pItem = m_pShopList->GetItem(mousePosX, mousePosY);
18261825

18271826
// If a module group list item, toggle its expansion and update the list
18281827
if (pItem && pItem->m_ExtraIndex >= 0)
@@ -1920,7 +1919,7 @@ void BuyMenuGUI::Update()
19201919
m_MenuFocus = ITEMS;
19211920

19221921
// See if it's hovering over any item
1923-
GUIListPanel::Item *pItem = m_pShopList->GetItem(m_CursorPos.m_X, m_CursorPos.m_Y);
1922+
GUIListPanel::Item *pItem = m_pShopList->GetItem(mousePosX, mousePosY);
19241923
if (pItem)
19251924
{
19261925
// Don't let mouse movement change the index if it's still hovering inside the same item.
@@ -1998,7 +1997,7 @@ void BuyMenuGUI::Update()
19981997
m_MenuFocus = ORDER;
19991998

20001999
// See if it's hovering over any item
2001-
GUIListPanel::Item *pItem = m_pCartList->GetItem(m_CursorPos.m_X, m_CursorPos.m_Y);
2000+
GUIListPanel::Item *pItem = m_pCartList->GetItem(mousePosX, mousePosY);
20022001
if (pItem)
20032002
{
20042003
// Don't let mouse movement change the index if it's still hovering inside the same item.
@@ -2061,7 +2060,10 @@ void BuyMenuGUI::Draw(BITMAP *drawBitmap) const {
20612060
m_pGUIController->Draw(&drawScreen);
20622061
if (IsEnabled() && m_pController->IsMouseControlled()) {
20632062
if (g_SettingsMan.FactionBuyMenuThemeCursorsDisabled()) {
2064-
draw_sprite(drawBitmap, s_pCursor, m_CursorPos.GetFloorIntX(), m_CursorPos.GetFloorIntY());
2063+
int mousePosX;
2064+
int mousePosY;
2065+
m_pGUIInput->GetMousePosition(&mousePosX, &mousePosY);
2066+
draw_sprite(drawBitmap, s_pCursor, mousePosX, mousePosY);
20652067
} else {
20662068
m_pGUIController->DrawMouse(&drawScreen);
20672069
}

Menus/BuyMenuGUI.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,6 @@ class BuyMenuGUI {
864864
int m_DeliveryWidth; //!< The width of the currently selected delivery craft, which will determine the width of the LZ marker.
865865
// The cursor image shared by all buy menus
866866
static BITMAP *s_pCursor;
867-
// Screen position of the cursor
868-
Vector m_CursorPos;
869867

870868
// If true UI won't afford to order a craft with more passengers than allowed by craft
871869
bool m_EnforceMaxPassengersConstraint;

Menus/ObjectPickerGUI.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ namespace RTE {
3030
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3131

3232
void ObjectPickerGUI::Clear() {
33-
m_CursorPos.Reset();
3433
m_GUIScreen = nullptr;
3534
m_GUIInput = nullptr;
3635
m_GUIControlManager = nullptr;
@@ -128,8 +127,8 @@ namespace RTE {
128127
if (enable && m_PickerState != PickerState::Enabled && m_PickerState != PickerState::Enabling) {
129128
m_PickerState = PickerState::Enabling;
130129
g_UInputMan.TrapMousePos(false, m_Controller->GetPlayer());
131-
m_CursorPos.SetXY(static_cast<float>(g_FrameMan.GetPlayerFrameBufferWidth(m_Controller->GetPlayer()) / 2), static_cast<float>(g_FrameMan.GetPlayerFrameBufferHeight(m_Controller->GetPlayer()) / 2));
132-
g_UInputMan.SetMousePos(m_CursorPos, m_Controller->GetPlayer());
130+
Vector playerFramebufferCenter = Vector(static_cast<float>(g_FrameMan.GetPlayerFrameBufferWidth(m_Controller->GetPlayer())), static_cast<float>(g_FrameMan.GetPlayerFrameBufferHeight(m_Controller->GetPlayer()))) / 2;
131+
g_UInputMan.SetMousePos(playerFramebufferCenter, m_Controller->GetPlayer());
133132

134133
SetListFocus(m_ObjectsList->GetItemList()->empty() ? PickerFocus::GroupList : PickerFocus::ObjectList);
135134

@@ -514,10 +513,9 @@ namespace RTE {
514513
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
515514

516515
bool ObjectPickerGUI::HandleMouseEvents() {
517-
int mouseX;
518-
int mouseY;
519-
m_GUIInput->GetMousePosition(&mouseX, &mouseY);
520-
m_CursorPos.SetXY(static_cast<float>(mouseX), static_cast<float>(mouseY));
516+
int mousePosX;
517+
int mousePosY;
518+
m_GUIInput->GetMousePosition(&mousePosX, &mousePosY);
521519

522520
GUIEvent guiEvent;
523521
while (m_GUIControlManager->GetEvent(&guiEvent)) {
@@ -526,7 +524,7 @@ namespace RTE {
526524
if (guiEvent.GetMsg() == GUIListBox::MouseDown && (guiEvent.GetData() & GUIListBox::MOUSE_LEFT)) {
527525
SelectGroupByIndex(m_GroupsList->GetSelectedIndex());
528526
} else if (guiEvent.GetMsg() == GUIListBox::MouseMove) {
529-
const GUIListPanel::Item *groupListItem = m_GroupsList->GetItem(m_CursorPos.GetFloorIntX(), m_CursorPos.GetFloorIntY());
527+
const GUIListPanel::Item *groupListItem = m_GroupsList->GetItem(mousePosX, mousePosY);
530528
if (groupListItem && m_SelectedGroupIndex != groupListItem->m_ID) { SelectGroupByIndex(groupListItem->m_ID, false); }
531529
} else if (guiEvent.GetMsg() == GUIListBox::MouseEnter) {
532530
SetListFocus(PickerFocus::GroupList);
@@ -545,13 +543,13 @@ namespace RTE {
545543
}
546544
}
547545
} else if (guiEvent.GetMsg() == GUIListBox::MouseMove) {
548-
const GUIListPanel::Item *objectListItem = m_ObjectsList->GetItem(m_CursorPos.GetFloorIntX(), m_CursorPos.GetFloorIntY());
546+
const GUIListPanel::Item *objectListItem = m_ObjectsList->GetItem(mousePosX, mousePosY);
549547
if (objectListItem && m_SelectedObjectIndex != objectListItem->m_ID) { SelectObjectByIndex(objectListItem->m_ID); }
550548
} else if (guiEvent.GetMsg() == GUIListBox::MouseEnter) {
551549
SetListFocus(PickerFocus::ObjectList);
552550
}
553551
} else {
554-
if (guiEvent.GetMsg() == GUIListBox::Click && m_CursorPos.GetFloorIntX() < m_ParentBox->GetXPos()) {
552+
if (guiEvent.GetMsg() == GUIListBox::Click && mousePosX < m_ParentBox->GetXPos()) {
555553
return true;
556554
}
557555
}
@@ -600,7 +598,10 @@ namespace RTE {
600598
m_GUIControlManager->Draw(&drawScreen);
601599
if (IsEnabled() && m_Controller->IsMouseControlled()) {
602600
if (g_SettingsMan.FactionBuyMenuThemeCursorsDisabled()) {
603-
draw_sprite(drawBitmap, s_Cursor, m_CursorPos.GetFloorIntX(), m_CursorPos.GetFloorIntY());
601+
int mousePosX;
602+
int mousePosY;
603+
m_GUIInput->GetMousePosition(&mousePosX, &mousePosY);
604+
draw_sprite(drawBitmap, s_Cursor, mousePosX, mousePosY);
604605
} else {
605606
m_GUIControlManager->DrawMouse(&drawScreen);
606607
}

Menus/ObjectPickerGUI.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ namespace RTE {
163163
enum class PickerFocus { GroupList, ObjectList };
164164

165165
static BITMAP *s_Cursor; //!< The cursor image shared by all pickers.
166-
Vector m_CursorPos; //!< Screen position of the cursor.
167166

168167
std::unique_ptr<AllegroScreen> m_GUIScreen; //!< The GUIScreen interface that will be used by this ObjectPickerGUI's GUIControlManager.
169168
std::unique_ptr<GUIInputWrapper> m_GUIInput; //!< The GUIInput interface that will be used by this ObjectPickerGUI's GUIControlManager.

0 commit comments

Comments
 (0)