|
|
@ -8,6 +8,7 @@ local utils = require('utils')
|
|
|
|
|
|
|
|
|
|
|
|
local dscreen = dfhack.screen
|
|
|
|
local dscreen = dfhack.screen
|
|
|
|
local getval = utils.getval
|
|
|
|
local getval = utils.getval
|
|
|
|
|
|
|
|
local to_pen = dfhack.pen.parse
|
|
|
|
|
|
|
|
|
|
|
|
local function show_view(view,vis)
|
|
|
|
local function show_view(view,vis)
|
|
|
|
if view then
|
|
|
|
if view then
|
|
|
@ -25,16 +26,13 @@ end
|
|
|
|
|
|
|
|
|
|
|
|
STANDARDSCROLL = {
|
|
|
|
STANDARDSCROLL = {
|
|
|
|
STANDARDSCROLL_UP = -1,
|
|
|
|
STANDARDSCROLL_UP = -1,
|
|
|
|
|
|
|
|
KEYBOARD_CURSOR_UP = -1,
|
|
|
|
STANDARDSCROLL_DOWN = 1,
|
|
|
|
STANDARDSCROLL_DOWN = 1,
|
|
|
|
|
|
|
|
KEYBOARD_CURSOR_DOWN = 1,
|
|
|
|
STANDARDSCROLL_PAGEUP = '-page',
|
|
|
|
STANDARDSCROLL_PAGEUP = '-page',
|
|
|
|
|
|
|
|
KEYBOARD_CURSOR_UP_FAST = '-page',
|
|
|
|
STANDARDSCROLL_PAGEDOWN = '+page',
|
|
|
|
STANDARDSCROLL_PAGEDOWN = '+page',
|
|
|
|
}
|
|
|
|
KEYBOARD_CURSOR_DOWN_FAST = '+page',
|
|
|
|
|
|
|
|
|
|
|
|
SECONDSCROLL = {
|
|
|
|
|
|
|
|
SECONDSCROLL_UP = -1,
|
|
|
|
|
|
|
|
SECONDSCROLL_DOWN = 1,
|
|
|
|
|
|
|
|
SECONDSCROLL_PAGEUP = '-page',
|
|
|
|
|
|
|
|
SECONDSCROLL_PAGEDOWN = '+page',
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
------------
|
|
|
|
------------
|
|
|
@ -365,8 +363,10 @@ function Panel:setKeyboardDragEnabled(enabled)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if enabled then
|
|
|
|
if enabled then
|
|
|
|
local kbd_get_pos = function() return {x=0, y=0} end
|
|
|
|
local kbd_get_pos = function()
|
|
|
|
Panel_begin_drag(self, kbd_get_pos())
|
|
|
|
return {x=self.frame_rect.x1, y=self.frame_rect.y1}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
Panel_begin_drag(self)
|
|
|
|
self.kbd_get_pos = kbd_get_pos
|
|
|
|
self.kbd_get_pos = kbd_get_pos
|
|
|
|
else
|
|
|
|
else
|
|
|
|
Panel_end_drag(self)
|
|
|
|
Panel_end_drag(self)
|
|
|
@ -441,6 +441,9 @@ end
|
|
|
|
-- if self.autoarrange_subviews is true, lay out visible subviews vertically,
|
|
|
|
-- if self.autoarrange_subviews is true, lay out visible subviews vertically,
|
|
|
|
-- adding gaps between widgets according to self.autoarrange_gap.
|
|
|
|
-- adding gaps between widgets according to self.autoarrange_gap.
|
|
|
|
function Panel:postUpdateLayout()
|
|
|
|
function Panel:postUpdateLayout()
|
|
|
|
|
|
|
|
-- don't leave artifacts behind on the parent screen when we move
|
|
|
|
|
|
|
|
gui.Screen.request_full_screen_refresh = true
|
|
|
|
|
|
|
|
|
|
|
|
if not self.autoarrange_subviews then return end
|
|
|
|
if not self.autoarrange_subviews then return end
|
|
|
|
|
|
|
|
|
|
|
|
local gap = self.autoarrange_gap
|
|
|
|
local gap = self.autoarrange_gap
|
|
|
@ -465,7 +468,7 @@ function Panel:onRenderFrame(dc, rect)
|
|
|
|
gui.paint_frame(dc, rect, self.frame_style, self.frame_title)
|
|
|
|
gui.paint_frame(dc, rect, self.frame_style, self.frame_title)
|
|
|
|
if self.kbd_get_pos then
|
|
|
|
if self.kbd_get_pos then
|
|
|
|
local pos = self.kbd_get_pos()
|
|
|
|
local pos = self.kbd_get_pos()
|
|
|
|
local pen = dfhack.pen.parse{fg=COLOR_GREEN, bg=COLOR_BLACK}
|
|
|
|
local pen = to_pen{fg=COLOR_GREEN, bg=COLOR_BLACK}
|
|
|
|
dc:seek(pos.x, pos.y):pen(pen):char(string.char(0xDB))
|
|
|
|
dc:seek(pos.x, pos.y):pen(pen):char(string.char(0xDB))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if self.drag_offset and not self.kbd_get_pos
|
|
|
|
if self.drag_offset and not self.kbd_get_pos
|
|
|
@ -654,6 +657,12 @@ function EditField:onRenderBody(dc)
|
|
|
|
dc:string((' '):rep(dc.clip_x2 - dc.x))
|
|
|
|
dc:string((' '):rep(dc.clip_x2 - dc.x))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function EditField:insert(text)
|
|
|
|
|
|
|
|
local old = self.text
|
|
|
|
|
|
|
|
self:setText(old:sub(1,self.cursor-1)..text..old:sub(self.cursor),
|
|
|
|
|
|
|
|
self.cursor + #text)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function EditField:onInput(keys)
|
|
|
|
function EditField:onInput(keys)
|
|
|
|
if not self.focus then
|
|
|
|
if not self.focus then
|
|
|
|
-- only react to our hotkey
|
|
|
|
-- only react to our hotkey
|
|
|
@ -676,22 +685,20 @@ function EditField:onInput(keys)
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if keys.SELECT then
|
|
|
|
if keys.SELECT or keys.CUSTOM_SHIFT_ENTER then
|
|
|
|
if self.key then
|
|
|
|
if self.key then
|
|
|
|
self:setFocus(false)
|
|
|
|
self:setFocus(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if self.on_submit then
|
|
|
|
if keys.CUSTOM_SHIFT_ENTER then
|
|
|
|
self.on_submit(self.text)
|
|
|
|
if self.on_submit2 then
|
|
|
|
return true
|
|
|
|
self.on_submit2(self.text)
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
return not not self.key
|
|
|
|
end
|
|
|
|
elseif keys.SEC_SELECT then
|
|
|
|
else
|
|
|
|
if self.key then
|
|
|
|
if self.on_submit then
|
|
|
|
self:setFocus(false)
|
|
|
|
self.on_submit(self.text)
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
if self.on_submit2 then
|
|
|
|
end
|
|
|
|
self.on_submit2(self.text)
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return not not self.key
|
|
|
|
return not not self.key
|
|
|
|
elseif keys._MOUSE_L then
|
|
|
|
elseif keys._MOUSE_L then
|
|
|
@ -712,8 +719,7 @@ function EditField:onInput(keys)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
local cv = string.char(keys._STRING)
|
|
|
|
local cv = string.char(keys._STRING)
|
|
|
|
if not self.on_char or self.on_char(cv, old) then
|
|
|
|
if not self.on_char or self.on_char(cv, old) then
|
|
|
|
self:setText(old:sub(1,self.cursor-1)..cv..old:sub(self.cursor),
|
|
|
|
self:insert(cv)
|
|
|
|
self.cursor + 1)
|
|
|
|
|
|
|
|
elseif self.on_char then
|
|
|
|
elseif self.on_char then
|
|
|
|
return self.modal
|
|
|
|
return self.modal
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -722,25 +728,25 @@ function EditField:onInput(keys)
|
|
|
|
self.on_change(self.text, old)
|
|
|
|
self.on_change(self.text, old)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
elseif keys.CURSOR_LEFT then
|
|
|
|
elseif keys.KEYBOARD_CURSOR_LEFT then
|
|
|
|
self:setCursor(self.cursor - 1)
|
|
|
|
self:setCursor(self.cursor - 1)
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
elseif keys.A_MOVE_W_DOWN then -- Ctrl-Left (end of prev word)
|
|
|
|
elseif keys.CUSTOM_CTRL_B then -- back one word
|
|
|
|
local _, prev_word_end = self.text:sub(1, self.cursor-1):
|
|
|
|
local _, prev_word_end = self.text:sub(1, self.cursor-1):
|
|
|
|
find('.*[%w_%-][^%w_%-]')
|
|
|
|
find('.*[%w_%-][^%w_%-]')
|
|
|
|
self:setCursor(prev_word_end or 1)
|
|
|
|
self:setCursor(prev_word_end or 1)
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
elseif keys.A_CARE_MOVE_W then -- Alt-Left (home)
|
|
|
|
elseif keys.CUSTOM_CTRL_A then -- home
|
|
|
|
self:setCursor(1)
|
|
|
|
self:setCursor(1)
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
elseif keys.CURSOR_RIGHT then
|
|
|
|
elseif keys.KEYBOARD_CURSOR_RIGHT then
|
|
|
|
self:setCursor(self.cursor + 1)
|
|
|
|
self:setCursor(self.cursor + 1)
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
elseif keys.A_MOVE_E_DOWN then -- Ctrl-Right (beginning of next word)
|
|
|
|
elseif keys.CUSTOM_CTRL_F then -- forward one word
|
|
|
|
local _,next_word_start = self.text:find('[^%w_%-][%w_%-]', self.cursor)
|
|
|
|
local _,next_word_start = self.text:find('[^%w_%-][%w_%-]', self.cursor)
|
|
|
|
self:setCursor(next_word_start)
|
|
|
|
self:setCursor(next_word_start)
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
elseif keys.A_CARE_MOVE_E then -- Alt-Right (end)
|
|
|
|
elseif keys.CUSTOM_CTRL_E then -- end
|
|
|
|
self:setCursor()
|
|
|
|
self:setCursor()
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -759,14 +765,12 @@ SCROLL_DELAY_MS = 20
|
|
|
|
Scrollbar = defclass(Scrollbar, Widget)
|
|
|
|
Scrollbar = defclass(Scrollbar, Widget)
|
|
|
|
|
|
|
|
|
|
|
|
Scrollbar.ATTRS{
|
|
|
|
Scrollbar.ATTRS{
|
|
|
|
fg = COLOR_LIGHTGREEN,
|
|
|
|
|
|
|
|
bg = COLOR_CYAN,
|
|
|
|
|
|
|
|
on_scroll = DEFAULT_NIL,
|
|
|
|
on_scroll = DEFAULT_NIL,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function Scrollbar:preinit(init_table)
|
|
|
|
function Scrollbar:preinit(init_table)
|
|
|
|
init_table.frame = init_table.frame or {}
|
|
|
|
init_table.frame = init_table.frame or {}
|
|
|
|
init_table.frame.w = init_table.frame.w or 1
|
|
|
|
init_table.frame.w = init_table.frame.w or 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Scrollbar:init()
|
|
|
|
function Scrollbar:init()
|
|
|
@ -824,36 +828,95 @@ local function scrollbar_is_visible(scrollbar)
|
|
|
|
return scrollbar.elems_per_page < scrollbar.num_elems
|
|
|
|
return scrollbar.elems_per_page < scrollbar.num_elems
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local UP_ARROW_CHAR = string.char(24)
|
|
|
|
local SCROLLBAR_UP_LEFT_PEN = to_pen{tile=922, ch=47, fg=COLOR_CYAN, bg=COLOR_BLACK}
|
|
|
|
local DOWN_ARROW_CHAR = string.char(25)
|
|
|
|
local SCROLLBAR_UP_RIGHT_PEN = to_pen{tile=923, ch=92, fg=COLOR_CYAN, bg=COLOR_BLACK}
|
|
|
|
local NO_ARROW_CHAR = string.char(32)
|
|
|
|
local SCROLLBAR_DOWN_LEFT_PEN = to_pen{tile=946, ch=92, fg=COLOR_CYAN, bg=COLOR_BLACK}
|
|
|
|
local BAR_CHAR = string.char(7)
|
|
|
|
local SCROLLBAR_DOWN_RIGHT_PEN = to_pen{tile=947, ch=47, fg=COLOR_CYAN, bg=COLOR_BLACK}
|
|
|
|
local BAR_BG_CHAR = string.char(179)
|
|
|
|
local SCROLLBAR_BAR_UP_LEFT_PEN = to_pen{tile=930, ch=219, fg=COLOR_CYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_UP_RIGHT_PEN = to_pen{tile=931, ch=219, fg=COLOR_CYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_LEFT_PEN = to_pen{tile=954, ch=219, fg=COLOR_CYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_RIGHT_PEN = to_pen{tile=955, ch=219, fg=COLOR_CYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_CENTER_UP_LEFT_PEN = to_pen{tile=932, ch=219, fg=COLOR_CYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_CENTER_UP_RIGHT_PEN = to_pen{tile=933, ch=219, fg=COLOR_CYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_CENTER_DOWN_LEFT_PEN = to_pen{tile=960, ch=219, fg=COLOR_CYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_CENTER_DOWN_RIGHT_PEN = to_pen{tile=961, ch=219, fg=COLOR_CYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_CENTER_LEFT_PEN = to_pen{tile=940, ch=219, fg=COLOR_CYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_CENTER_RIGHT_PEN = to_pen{tile=941, ch=219, fg=COLOR_CYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_DOWN_LEFT_PEN = to_pen{tile=966, ch=219, fg=COLOR_CYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_DOWN_RIGHT_PEN = to_pen{tile=967, ch=219, fg=COLOR_CYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_UP_LEFT_HOVER_PEN = to_pen{tile=924, ch=47, fg=COLOR_LIGHTCYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_UP_RIGHT_HOVER_PEN = to_pen{tile=925, ch=92, fg=COLOR_LIGHTCYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_DOWN_LEFT_HOVER_PEN = to_pen{tile=936, ch=92, fg=COLOR_LIGHTCYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_DOWN_RIGHT_HOVER_PEN = to_pen{tile=937, ch=47, fg=COLOR_LIGHTCYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_UP_LEFT_HOVER_PEN = to_pen{tile=930, ch=219, fg=COLOR_LIGHTCYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_UP_RIGHT_HOVER_PEN = to_pen{tile=931, ch=219, fg=COLOR_LIGHTCYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_LEFT_HOVER_PEN = to_pen{tile=954, ch=219, fg=COLOR_LIGHTCYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_RIGHT_HOVER_PEN = to_pen{tile=955, ch=219, fg=COLOR_LIGHTCYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_CENTER_UP_LEFT_HOVER_PEN = to_pen{tile=956, ch=219, fg=COLOR_LIGHTCYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_CENTER_UP_RIGHT_HOVER_PEN = to_pen{tile=957, ch=219, fg=COLOR_LIGHTCYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_CENTER_DOWN_LEFT_HOVER_PEN = to_pen{tile=968, ch=219, fg=COLOR_LIGHTCYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_CENTER_DOWN_RIGHT_HOVER_PEN = to_pen{tile=969, ch=219, fg=COLOR_LIGHTCYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_CENTER_LEFT_HOVER_PEN = to_pen{tile=942, ch=219, fg=COLOR_LIGHTCYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_CENTER_RIGHT_HOVER_PEN = to_pen{tile=943, ch=219, fg=COLOR_LIGHTCYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_DOWN_LEFT_HOVER_PEN = to_pen{tile=966, ch=219, fg=COLOR_LIGHTCYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_DOWN_RIGHT_HOVER_PEN = to_pen{tile=967, ch=219, fg=COLOR_LIGHTCYAN, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_BG_LEFT_PEN = to_pen{tile=934, ch=176, fg=COLOR_DARKGREY, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
local SCROLLBAR_BAR_BG_RIGHT_PEN = to_pen{tile=935, ch=176, fg=COLOR_DARKGREY, bg=COLOR_BLACK}
|
|
|
|
|
|
|
|
|
|
|
|
function Scrollbar:onRenderBody(dc)
|
|
|
|
function Scrollbar:onRenderBody(dc)
|
|
|
|
-- don't draw if all elements are visible
|
|
|
|
-- don't draw if all elements are visible
|
|
|
|
if not scrollbar_is_visible(self) then
|
|
|
|
if not scrollbar_is_visible(self) then
|
|
|
|
return
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- render up arrow if we're not at the top
|
|
|
|
-- determine which elements should be highlighted
|
|
|
|
dc:seek(0, 0):char(
|
|
|
|
local _,hover_y = self:getMousePos()
|
|
|
|
self.top_elem == 1 and NO_ARROW_CHAR or UP_ARROW_CHAR, self.fg, self.bg)
|
|
|
|
local hover_up, hover_down, hover_bar = false, false, false
|
|
|
|
|
|
|
|
if hover_y == 0 then
|
|
|
|
|
|
|
|
hover_up = true
|
|
|
|
|
|
|
|
elseif hover_y == dc.height-1 then
|
|
|
|
|
|
|
|
hover_down = true
|
|
|
|
|
|
|
|
elseif hover_y then
|
|
|
|
|
|
|
|
hover_bar = true
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
-- render up arrow
|
|
|
|
|
|
|
|
dc:seek(0, 0)
|
|
|
|
|
|
|
|
dc:char(nil, hover_up and SCROLLBAR_UP_LEFT_HOVER_PEN or SCROLLBAR_UP_LEFT_PEN)
|
|
|
|
|
|
|
|
dc:char(nil, hover_up and SCROLLBAR_UP_RIGHT_HOVER_PEN or SCROLLBAR_UP_RIGHT_PEN)
|
|
|
|
-- render scrollbar body
|
|
|
|
-- render scrollbar body
|
|
|
|
local starty = self.bar_offset + 1
|
|
|
|
local starty = self.bar_offset + 1
|
|
|
|
local endy = self.bar_offset + self.bar_height
|
|
|
|
local endy = self.bar_offset + self.bar_height
|
|
|
|
|
|
|
|
local midy = (starty + endy)/2
|
|
|
|
for y=1,dc.height-2 do
|
|
|
|
for y=1,dc.height-2 do
|
|
|
|
dc:seek(0, y)
|
|
|
|
dc:seek(0, y)
|
|
|
|
if y >= starty and y <= endy then
|
|
|
|
if y >= starty and y <= endy then
|
|
|
|
dc:char(BAR_CHAR, self.fg)
|
|
|
|
if y == starty and y <= midy - 1 then
|
|
|
|
|
|
|
|
dc:char(nil, hover_bar and SCROLLBAR_BAR_UP_LEFT_HOVER_PEN or SCROLLBAR_BAR_UP_LEFT_PEN)
|
|
|
|
|
|
|
|
dc:char(nil, hover_bar and SCROLLBAR_BAR_UP_RIGHT_HOVER_PEN or SCROLLBAR_BAR_UP_RIGHT_PEN)
|
|
|
|
|
|
|
|
elseif y == midy - 0.5 then
|
|
|
|
|
|
|
|
dc:char(nil, hover_bar and SCROLLBAR_BAR_CENTER_UP_LEFT_HOVER_PEN or SCROLLBAR_BAR_CENTER_UP_LEFT_PEN)
|
|
|
|
|
|
|
|
dc:char(nil, hover_bar and SCROLLBAR_BAR_CENTER_UP_RIGHT_HOVER_PEN or SCROLLBAR_BAR_CENTER_UP_RIGHT_PEN)
|
|
|
|
|
|
|
|
elseif y == midy + 0.5 then
|
|
|
|
|
|
|
|
dc:char(nil, hover_bar and SCROLLBAR_BAR_CENTER_DOWN_LEFT_HOVER_PEN or SCROLLBAR_BAR_CENTER_DOWN_LEFT_PEN)
|
|
|
|
|
|
|
|
dc:char(nil, hover_bar and SCROLLBAR_BAR_CENTER_DOWN_RIGHT_HOVER_PEN or SCROLLBAR_BAR_CENTER_DOWN_RIGHT_PEN)
|
|
|
|
|
|
|
|
elseif y == midy then
|
|
|
|
|
|
|
|
dc:char(nil, hover_bar and SCROLLBAR_BAR_CENTER_LEFT_HOVER_PEN or SCROLLBAR_BAR_CENTER_LEFT_PEN)
|
|
|
|
|
|
|
|
dc:char(nil, hover_bar and SCROLLBAR_BAR_CENTER_RIGHT_HOVER_PEN or SCROLLBAR_BAR_CENTER_RIGHT_PEN)
|
|
|
|
|
|
|
|
elseif y == endy and y >= midy + 1 then
|
|
|
|
|
|
|
|
dc:char(nil, hover_bar and SCROLLBAR_BAR_DOWN_LEFT_HOVER_PEN or SCROLLBAR_BAR_DOWN_LEFT_PEN)
|
|
|
|
|
|
|
|
dc:char(nil, hover_bar and SCROLLBAR_BAR_DOWN_RIGHT_HOVER_PEN or SCROLLBAR_BAR_DOWN_RIGHT_PEN)
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
dc:char(nil, hover_bar and SCROLLBAR_BAR_LEFT_HOVER_PEN or SCROLLBAR_BAR_LEFT_PEN)
|
|
|
|
|
|
|
|
dc:char(nil, hover_bar and SCROLLBAR_BAR_RIGHT_HOVER_PEN or SCROLLBAR_BAR_RIGHT_PEN)
|
|
|
|
|
|
|
|
end
|
|
|
|
else
|
|
|
|
else
|
|
|
|
dc:char(BAR_BG_CHAR, self.bg)
|
|
|
|
dc:char(nil, SCROLLBAR_BAR_BG_LEFT_PEN)
|
|
|
|
|
|
|
|
dc:char(nil, SCROLLBAR_BAR_BG_RIGHT_PEN)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- render down arrow if we're not at the bottom
|
|
|
|
-- render down arrow
|
|
|
|
local last_visible_el = self.top_elem + self.elems_per_page - 1
|
|
|
|
dc:seek(0, dc.height-1)
|
|
|
|
dc:seek(0, dc.height-1):char(
|
|
|
|
dc:char(nil, hover_down and SCROLLBAR_DOWN_LEFT_HOVER_PEN or SCROLLBAR_DOWN_LEFT_PEN)
|
|
|
|
last_visible_el >= self.num_elems and NO_ARROW_CHAR or DOWN_ARROW_CHAR,
|
|
|
|
dc:char(nil, hover_down and SCROLLBAR_DOWN_RIGHT_HOVER_PEN or SCROLLBAR_DOWN_RIGHT_PEN)
|
|
|
|
self.fg, self.bg)
|
|
|
|
|
|
|
|
if not self.on_scroll then return end
|
|
|
|
if not self.on_scroll then return end
|
|
|
|
-- manage state for dragging and continuous scrolling
|
|
|
|
-- manage state for dragging and continuous scrolling
|
|
|
|
if self.is_dragging then
|
|
|
|
if self.is_dragging then
|
|
|
@ -877,10 +940,26 @@ function Scrollbar:onRenderBody(dc)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Scrollbar:onInput(keys)
|
|
|
|
function Scrollbar:onInput(keys)
|
|
|
|
if not keys._MOUSE_L_DOWN or not self.on_scroll
|
|
|
|
if not self.on_scroll or not scrollbar_is_visible(self) then
|
|
|
|
or not scrollbar_is_visible(self) then
|
|
|
|
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.parent_view:getMousePos() then
|
|
|
|
|
|
|
|
if keys.CONTEXT_SCROLL_UP then
|
|
|
|
|
|
|
|
self.on_scroll('up_small')
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
elseif keys.CONTEXT_SCROLL_DOWN then
|
|
|
|
|
|
|
|
self.on_scroll('down_small')
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
elseif keys.CONTEXT_SCROLL_PAGEUP then
|
|
|
|
|
|
|
|
self.on_scroll('up_large')
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
elseif keys.CONTEXT_SCROLL_PAGEDOWN then
|
|
|
|
|
|
|
|
self.on_scroll('down_large')
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
if not keys._MOUSE_L_DOWN then return false end
|
|
|
|
local _,y = self:getMousePos()
|
|
|
|
local _,y = self:getMousePos()
|
|
|
|
if not y then return false end
|
|
|
|
if not y then return false end
|
|
|
|
local scroll_spec = nil
|
|
|
|
local scroll_spec = nil
|
|
|
@ -988,13 +1067,13 @@ function render_text(obj,dc,x0,y0,pen,dpen,disabled)
|
|
|
|
if token.tile then
|
|
|
|
if token.tile then
|
|
|
|
x = x + 1
|
|
|
|
x = x + 1
|
|
|
|
if dc then
|
|
|
|
if dc then
|
|
|
|
dc:char(nil, token.tile)
|
|
|
|
dc:tile(nil, token.tile)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if token.text or token.key then
|
|
|
|
if token.text or token.key then
|
|
|
|
local text = ''..(getval(token.text) or '')
|
|
|
|
local text = ''..(getval(token.text) or '')
|
|
|
|
local keypen = dfhack.pen.parse(token.key_pen or COLOR_LIGHTGREEN)
|
|
|
|
local keypen = to_pen(token.key_pen or COLOR_LIGHTGREEN)
|
|
|
|
|
|
|
|
|
|
|
|
if dc then
|
|
|
|
if dc then
|
|
|
|
local tpen = getval(token.pen)
|
|
|
|
local tpen = getval(token.pen)
|
|
|
@ -1247,7 +1326,7 @@ end
|
|
|
|
-- we can't set the text in init() since we may not yet have a frame that we
|
|
|
|
-- we can't set the text in init() since we may not yet have a frame that we
|
|
|
|
-- can get wrapping bounds from.
|
|
|
|
-- can get wrapping bounds from.
|
|
|
|
function WrappedLabel:postComputeFrame()
|
|
|
|
function WrappedLabel:postComputeFrame()
|
|
|
|
local wrapped_text = self:getWrappedText(self.frame_body.width-1)
|
|
|
|
local wrapped_text = self:getWrappedText(self.frame_body.width-3)
|
|
|
|
if not wrapped_text then return end
|
|
|
|
if not wrapped_text then return end
|
|
|
|
local text = {}
|
|
|
|
local text = {}
|
|
|
|
for _,line in ipairs(wrapped_text:split(NEWLINE)) do
|
|
|
|
for _,line in ipairs(wrapped_text:split(NEWLINE)) do
|
|
|
@ -1622,12 +1701,14 @@ end
|
|
|
|
function List:submit()
|
|
|
|
function List:submit()
|
|
|
|
if self.on_submit and #self.choices > 0 then
|
|
|
|
if self.on_submit and #self.choices > 0 then
|
|
|
|
self.on_submit(self:getSelected())
|
|
|
|
self.on_submit(self:getSelected())
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function List:submit2()
|
|
|
|
function List:submit2()
|
|
|
|
if self.on_submit2 and #self.choices > 0 then
|
|
|
|
if self.on_submit2 and #self.choices > 0 then
|
|
|
|
self.on_submit2(self:getSelected())
|
|
|
|
self.on_submit2(self:getSelected())
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -1635,12 +1716,10 @@ function List:onInput(keys)
|
|
|
|
if self:inputToSubviews(keys) then
|
|
|
|
if self:inputToSubviews(keys) then
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if self.on_submit and keys.SELECT then
|
|
|
|
if keys.SELECT then
|
|
|
|
self:submit()
|
|
|
|
return self:submit()
|
|
|
|
return true
|
|
|
|
elseif keys.CUSTOM_SHIFT_ENTER then
|
|
|
|
elseif self.on_submit2 and keys.SEC_SELECT then
|
|
|
|
return self:submit2()
|
|
|
|
self:submit2()
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
elseif keys._MOUSE_L_DOWN then
|
|
|
|
elseif keys._MOUSE_L_DOWN then
|
|
|
|
local idx = self:getIdxUnderMouse()
|
|
|
|
local idx = self:getIdxUnderMouse()
|
|
|
|
if idx then
|
|
|
|
if idx then
|
|
|
|