Skip to content

Commit cafb450

Browse files
committed
update gui/overlay for scaled interface behavior
1 parent 80aa62d commit cafb450

File tree

1 file changed

+64
-30
lines changed

1 file changed

+64
-30
lines changed

gui/overlay.lua

+64-30
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,12 @@ DraggablePanel.ATTRS{
5454
draggable=true,
5555
drag_anchors={frame=true, body=true},
5656
drag_bound='body',
57+
widget=DEFAULT_NIL,
5758
}
5859

5960
function DraggablePanel:onInput(keys)
60-
if keys._MOUSE_L then
61-
local rect = self.frame_rect
62-
local x,y = self:getMousePos(gui.ViewRect{rect=rect})
63-
if x then
64-
self.on_click()
65-
end
61+
if keys._MOUSE_L and self:getMousePos() then
62+
self.on_click()
6663
end
6764
return DraggablePanel.super.onInput(self, keys)
6865
end
@@ -72,16 +69,16 @@ function DraggablePanel:postUpdateLayout()
7269
local frame = self.frame
7370
local matcher = {t=not not frame.t, b=not not frame.b,
7471
l=not not frame.l, r=not not frame.r}
75-
local parent_rect, frame_rect = self.frame_parent_rect, self.frame_rect
76-
if frame_rect.y1 <= parent_rect.y1 then
77-
frame.t, frame.b = frame_rect.y1-parent_rect.y1, nil
78-
elseif frame_rect.y2 >= parent_rect.y2 then
79-
frame.t, frame.b = nil, parent_rect.y2-frame_rect.y2
72+
local parent_rect, frame_rect = self.widget.frame_parent_rect, self.frame_body
73+
if frame_rect.y1-1 <= parent_rect.y1 then
74+
frame.t, frame.b = frame_rect.y1-parent_rect.y1-1, nil
75+
elseif frame_rect.y2+1 >= parent_rect.y2 then
76+
frame.t, frame.b = nil, parent_rect.y2-frame_rect.y2-1
8077
end
81-
if frame_rect.x1 <= parent_rect.x1 then
82-
frame.l, frame.r = frame_rect.x1-parent_rect.x1, nil
83-
elseif frame_rect.x2 >= parent_rect.x2 then
84-
frame.l, frame.r = nil, parent_rect.x2-frame_rect.x2
78+
if frame_rect.x1-1 <= parent_rect.x1 then
79+
frame.l, frame.r = frame_rect.x1-parent_rect.x1-1, nil
80+
elseif frame_rect.x2+1 >= parent_rect.x2 then
81+
frame.l, frame.r = nil, parent_rect.x2-frame_rect.x2-1
8582
end
8683
self.frame_style = make_highlight_frame_style(self.frame)
8784
if not not frame.t ~= matcher.t or not not frame.b ~= matcher.b
@@ -92,7 +89,7 @@ function DraggablePanel:postUpdateLayout()
9289
end
9390

9491
function DraggablePanel:onRenderFrame(dc, rect)
95-
if self:getMousePos(gui.ViewRect{rect=self.frame_rect}) then
92+
if self:getMousePos() then
9693
self.frame_background = to_pen{
9794
ch=32, fg=COLOR_LIGHTGREEN, bg=COLOR_LIGHTGREEN}
9895
else
@@ -112,6 +109,7 @@ function OverlayConfig:init()
112109
overlay.register_trigger_lock_screen(self)
113110

114111
local contexts = dfhack.gui.getFocusStrings(dfhack.gui.getDFViewscreen(true))
112+
local interface_width_pct = df.global.init.display.max_interface_percentage
115113

116114
local main_panel = widgets.Window{
117115
frame={w=DIALOG_WIDTH, h=LIST_HEIGHT+15},
@@ -124,19 +122,25 @@ function OverlayConfig:init()
124122
frame={t=0, l=0},
125123
text={
126124
'Current contexts: ',
127-
{text=table.concat(contexts, ', '), pen=COLOR_CYAN}
125+
{text=table.concat(contexts, ', '), pen=COLOR_CYAN},
126+
}},
127+
widgets.Label{
128+
frame={t=2, l=0},
129+
text={
130+
'Interface width percent: ',
131+
{text=interface_width_pct, pen=COLOR_CYAN},
128132
}},
129133
widgets.CycleHotkeyLabel{
130134
view_id='filter',
131-
frame={t=2, l=0},
135+
frame={t=4, l=0},
132136
key='CUSTOM_CTRL_O',
133-
label='Showing:',
137+
label='Showing',
134138
options={{label='overlays for the current contexts', value='cur'},
135139
{label='all overlays', value='all'}},
136140
on_change=self:callback('refresh_list')},
137141
widgets.FilteredList{
138142
view_id='list',
139-
frame={t=4, b=7},
143+
frame={t=6, b=7},
140144
on_select=self:callback('highlight_selected'),
141145
},
142146
widgets.HotkeyLabel{
@@ -160,7 +164,21 @@ function OverlayConfig:init()
160164
' to anchor the widget to that edge.',
161165
},
162166
}
163-
self:addviews{main_panel}
167+
168+
self:addviews{
169+
widgets.Divider{
170+
view_id='left_border',
171+
frame={l=0, w=1},
172+
frame_style=gui.FRAME_THIN,
173+
},
174+
widgets.Divider{
175+
view_id='right_border',
176+
frame={r=0, w=1},
177+
frame_style=gui.FRAME_THIN,
178+
},
179+
main_panel,
180+
}
181+
164182
self:refresh_list()
165183
end
166184

@@ -203,15 +221,18 @@ function OverlayConfig:refresh_list(filter)
203221
frame_style=SHADOW_FRAME,
204222
on_click=make_on_click_fn(#choices+1),
205223
name=name,
224+
widget=widget,
206225
}
207226
panel.on_drag_end = function(success)
208227
if (success) then
209228
local frame = panel.frame
210-
local posx = frame.l and tostring(frame.l+2)
211-
or tostring(-(frame.r+2))
212-
local posy = frame.t and tostring(frame.t+2)
213-
or tostring(-(frame.b+2))
214-
overlay.overlay_command({'position', name, posx, posy},true)
229+
local frame_rect = panel.frame_rect
230+
local frame_parent_rect = panel.frame_parent_rect
231+
local posx = frame.l and tostring(frame_rect.x1+2)
232+
or tostring(frame_rect.x2-frame_parent_rect.width-1)
233+
local posy = frame.t and tostring(frame_rect.y1+2)
234+
or tostring(frame_rect.y2-frame_parent_rect.height-1)
235+
overlay.overlay_command({'position', name, posx, posy}, true)
215236
end
216237
self.reposition_panel = nil
217238
end
@@ -267,15 +288,27 @@ function OverlayConfig:reset()
267288
if not obj or not obj.panel then return end
268289
overlay.overlay_command({'position', obj.panel.name, 'default'}, true)
269290
self:refresh_list(self.subviews.filter:getOptionValue())
291+
self:updateLayout()
270292
end
271293

272294
function OverlayConfig:onDismiss()
273295
view = nil
274296
end
275297

298+
function OverlayConfig:preUpdateLayout(parent_rect)
299+
local interface_rect = gui.get_interface_rect()
300+
local left, right = self.subviews.left_border, self.subviews.right_border
301+
left.frame.l = interface_rect.x1 - 1
302+
left.visible = left.frame.l >= 0
303+
right.frame.r = nil
304+
right.frame.l = interface_rect.x2 + 1
305+
right.visible = right.frame.l < parent_rect.width
306+
end
307+
276308
function OverlayConfig:postUpdateLayout()
309+
local rect = gui.ViewRect{rect=gui.get_interface_rect()}
277310
for _,choice in ipairs(self.subviews.list:getChoices()) do
278-
choice.panel:updateLayout(choice.widget.frame_parent_rect)
311+
choice.panel:updateLayout(rect)
279312
end
280313
end
281314

@@ -304,17 +337,18 @@ function OverlayConfig:onInput(keys)
304337
end
305338
end
306339

307-
function OverlayConfig:onRenderFrame(dc, rect)
340+
function OverlayConfig:onRenderFrame()
308341
self:renderParent()
342+
local interface_area_painter = gui.Painter.new(gui.ViewRect{rect=gui.get_interface_rect()})
309343
for _,choice in ipairs(self.subviews.list:getVisibleChoices()) do
310344
local panel = choice.panel
311345
if panel and panel ~= self.selected_panel then
312-
panel:render(dc)
346+
panel:render(interface_area_painter)
313347
end
314348
end
315349
if self.selected_panel then
316350
self.render_selected_panel = function()
317-
self.selected_panel:render(dc)
351+
self.selected_panel:render(interface_area_painter)
318352
end
319353
else
320354
self.render_selected_panel = nil

0 commit comments

Comments
 (0)