Skip to content

Commit

Permalink
refactor(radar): code clean up
Browse files Browse the repository at this point in the history
Move window size defintions near top of function so the sizes can be
reused when calculating the bounds for detecting mouse clicks.
  • Loading branch information
mwerle committed Nov 27, 2024
1 parent 77e96f9 commit 88cc619
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions data/pigui/modules/radar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,11 @@ local function displayRadar()
local zoom = 0
local toggle_radar = false

local window_width = ui.reticuleCircleRadius * 1.8
local window_height = radar2d.size * 2
local window_pos = Vector2(center.x - window_width / 2, center.y - window_height / 2)
local windowFlags = ui.WindowFlags {"NoTitleBar", "NoResize", "NoFocusOnAppearing", "NoBringToFrontOnFocus", "NoSavedSettings"}

--
-- keyboard handling
--
Expand Down Expand Up @@ -414,10 +419,10 @@ local function displayRadar()
return (mp - center):length() < radar2d.getRadius(radar2d)
end
return ui.isMouseHoveringRect(
Vector2(center.x - ui.reticuleCircleRadius * 0.9,
center.y - ui.reticuleCircleRadius * 0.7),
Vector2(center.x + ui.reticuleCircleRadius * 0.9,
center.y + ui.reticuleCircleRadius * 0.7))
Vector2(center.x - window_width/2,
center.y - window_height/2),
Vector2(center.x + window_width/2,
center.y + window_height/2))
end

if radar_popup_displayed then
Expand Down Expand Up @@ -456,10 +461,6 @@ local function displayRadar()
-- drawing functionality
--
-- This is in a window so the buttons work and the mouse-wheel is captured
local window_width = ui.reticuleCircleRadius * 1.8
local window_height = radar2d.size * 2
local window_pos = Vector2(center.x - window_width / 2, center.y - window_height / 2)
local windowFlags = ui.WindowFlags {"NoTitleBar", "NoResize", "NoFocusOnAppearing", "NoBringToFrontOnFocus", "NoSavedSettings"}
ui.setNextWindowPos(window_pos, "Always")
ui.setNextWindowPadding(Vector2(0))
ui.setNextWindowSize(Vector2(window_width, window_height), "Always")
Expand Down

0 comments on commit 88cc619

Please sign in to comment.