diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index 9ff1d5918..eece622e1 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -411,6 +411,7 @@ function ReaderHighlight:addToMainMenu(menu_items) radio = true, callback = function() self.view.highlight.saved_drawer = style + self:setSelectionColor() end, hold_callback = function(touchmenu_instance) G_reader_settings:saveSetting("highlight_drawing_style", style) @@ -447,6 +448,7 @@ function ReaderHighlight:addToMainMenu(menu_items) bg_colors = self:getHighlightColorList(), callback = function(value) self.view.highlight.saved_color = value + self:setSelectionColor() touchmenu_instance:updateItems() end, }) @@ -470,10 +472,10 @@ function ReaderHighlight:addToMainMenu(menu_items) value_max = 1, precision = "%.2f", value_step = 0.1, - value_hold_step = 0.2, + value_hold_step = 0.05, default_value = 0.2, keep_shown_on_apply = true, - title_text = _("Gray highlight opacity"), + title_text = _("Gray highlight opacity"), info_text = _("The higher the value, the darker the gray."), callback = function(spin) G_reader_settings:saveSetting("highlight_lighten_factor", spin.value) @@ -484,6 +486,45 @@ function ReaderHighlight:addToMainMenu(menu_items) }) end, }) + table.insert(hl_sub_item_table, { + text = _("Use highlight color for selection"), + enabled_func = function() + return self.view.highlight.saved_drawer ~= "invert" + end, + checked_func = function() + return self.view.highlight.saved_drawer ~= "invert" and G_reader_settings:isTrue("highlight_selection_use_highlight_color") + end, + callback = function() + G_reader_settings:flipNilOrFalse("highlight_selection_use_highlight_color") + self:setSelectionColor() + end, + }) + table.insert(hl_sub_item_table, { + text_func = function() + return T(_("Gray selection opacity: %1"), G_reader_settings:readSetting("highlight_selection_lighten_factor") or 0.2) + end, + keep_menu_open = true, + callback = function(touchmenu_instance) + UIManager:show(SpinWidget:new{ + value = G_reader_settings:readSetting("highlight_selection_lighten_factor") or 0.2, + value_min = 0, + value_max = 1, + precision = "%.2f", + value_step = 0.1, + value_hold_step = 0.05, + default_value = 0.2, + title_text = _("Gray selection opacity"), + info_text = _("The higher the value, the darker the gray."), + callback = function(spin) + local value = spin.value ~= 0.2 and spin.value or nil + G_reader_settings:saveSetting("highlight_selection_lighten_factor", value) + self:setSelectionColor() + touchmenu_instance:updateItems() + end, + }) + end, + separator = true, + }) table.insert(hl_sub_item_table, { text_func = function() return T(_("Highlight line height: %1\xE2\x80\xAF%"), G_reader_settings:readSetting("highlight_height_pct") or 100) @@ -501,7 +542,7 @@ function ReaderHighlight:addToMainMenu(menu_items) default_value = 100, unit = "%", keep_shown_on_apply = true, - title_text = _("Highlight line height"), + title_text = _("Highlight line height"), info_text = _("Percentage of the text line height."), callback = function(spin) local value = spin.value ~= 100 and spin.value or nil @@ -2652,7 +2693,7 @@ function ReaderHighlight:onReadSettings(config) self.view.highlight.saved_color = config:readSetting("highlight_color") or G_reader_settings:readSetting("highlight_color") or self.view.highlight.saved_color self.view.highlight.disabled = G_reader_settings:readSetting("default_highlight_action") == "nothing" - + self:setSelectionColor() self.allow_corner_scroll = G_reader_settings:nilOrTrue("highlight_corner_scroll") -- panel zoom settings isn't supported in EPUB @@ -2680,6 +2721,30 @@ function ReaderHighlight:onReadSettings(config) end end +function ReaderHighlight:setSelectionColor() + if self.ui.paging then return end + local color = self.view.highlight.saved_drawer ~= "invert" + and G_reader_settings:isTrue("highlight_selection_use_highlight_color") + and Blitbuffer.HIGHLIGHT_COLORS[self.view.highlight.saved_color] + if color then + if Screen.night_mode then + local r, g, b = color:match("#(..)(..)(..)") + color = string.format("#%02x%02x%02x", 255 - tonumber(r, 16), 255 - tonumber(g, 16), 255 - tonumber(b, 16)) + end + else -- gray + local lighten_factor = G_reader_settings:readSetting("highlight_selection_lighten_factor") or 0.2 + if lighten_factor == 0 then + color = "#FFFFFF" + elseif lighten_factor == 1 then + color = "#000000" + else + color = string.format("%X", math.floor(256 * (1 - lighten_factor))) + color = "#" .. color:rep(3) + end + end + self.document._document:setStringProperty("crengine.highlight.selection.color", color) +end + function ReaderHighlight:onUpdateHoldPanRate() self:setupTouchZones() end diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index 6130acc8b..cb0665683 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -95,7 +95,7 @@ function ReaderView:init() visible_boxes = nil, -- array; visible boxes in the current page, used by ReaderHighlight:onTap() lighten_factor = G_reader_settings:readSetting("highlight_lighten_factor", 0.2), note_mark = G_reader_settings:readSetting("highlight_note_marker"), - temp_drawer = "invert", + temp_drawer = "lighten", temp = {}, saved_drawer = "lighten", -- NOTE: Unfortunately, yellow tends to look like absolute ass on Kaleido panels... @@ -241,7 +241,7 @@ function ReaderView:paintTo(bb, x, y) colorful = self:drawSavedHighlight(bb, x, y) end -- draw temporary highlight - if self.highlight.temp then + if self.highlight.temp and next(self.highlight.temp) then self:drawTempHighlight(bb, x, y) end -- draw highlight position indicator for non-touch @@ -525,11 +525,14 @@ function ReaderView:drawHighlightIndicator(bb, x, y) end function ReaderView:drawTempHighlight(bb, x, y) + local color = self.highlight.saved_drawer ~= "invert" + and G_reader_settings:isTrue("highlight_selection_use_highlight_color") + and Blitbuffer.colorFromName(self.highlight.saved_color) or nil for page, boxes in pairs(self.highlight.temp) do for i = 1, #boxes do local rect = self:pageToScreenTransform(page, boxes[i]) if rect then - self:drawHighlightRect(bb, x, y, rect, self.highlight.temp_drawer) + self:drawHighlightRect(bb, x, y, rect, self.highlight.temp_drawer, color) end end end @@ -685,15 +688,17 @@ function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, color, draw_note end end if drawer == "lighten" then + local lighten_factor = self.highlight.temp and next(self.highlight.temp) + and (G_reader_settings:readSetting("highlight_selection_lighten_factor") or 0.2) or self.highlight.lighten_factor if not color then - bb:darkenRect(x, y, w, h, self.highlight.lighten_factor) + bb:darkenRect(x, y, w, h, lighten_factor) else if bb:getInverse() == 1 then -- MUL doesn't really work on a black background, so, switch to OVER if we're in software nightmode... -- NOTE: If we do *not* invert the color here, it *will* get inverted by the blitter given that the target bb is inverted. -- While not particularly pretty, this (roughly) matches with hardware nightmode, *and* how MuPDF renders highlights... -- But it's *really* not pretty (https://github.com/koreader/koreader/pull/11044#issuecomment-1902886069), so we'll fix it ;p. - local c = Blitbuffer.ColorRGB32(color.r, color.g, color.b, 0xFF * self.highlight.lighten_factor):invert() + local c = Blitbuffer.ColorRGB32(color.r, color.g, color.b, 0xFF * lighten_factor):invert() bb:blendRectRGB32(x, y, w, h, c) else bb:multiplyRectRGB(x, y, w, h, color) diff --git a/frontend/device/devicelistener.lua b/frontend/device/devicelistener.lua index 43c2212d4..1c0cd519a 100644 --- a/frontend/device/devicelistener.lua +++ b/frontend/device/devicelistener.lua @@ -17,6 +17,9 @@ function DeviceListener:onToggleNightMode() -- Make sure CRe will bypass the call cache if self.ui and self.ui.document and self.ui.document.provider == "crengine" then self.ui.document:resetCallCache() + if self.ui.highlight then + self.ui.highlight:setSelectionColor() + end end UIManager:setDirty("all", "full") UIManager:ToggleNightMode(not night_mode)