From b310c80d15d0399d9bcb79061205db051753ba0b Mon Sep 17 00:00:00 2001 From: Alex <48759429+Aurumaker72@users.noreply.github.com> Date: Sun, 25 Jun 2023 23:50:17 +0200 Subject: [PATCH] Fix BreitbandGraphics backwards compatibility with incomplete color types --- mupen-lua-ugui.lua | 186 ++++++++++++++++++++++----------------------- 1 file changed, 93 insertions(+), 93 deletions(-) diff --git a/mupen-lua-ugui.lua b/mupen-lua-ugui.lua index 24383c9..e0aa38c 100644 --- a/mupen-lua-ugui.lua +++ b/mupen-lua-ugui.lua @@ -1,12 +1,12 @@ --- mupen-lua-ugui 1.0.0 +-- mupen-lua-ugui 1.0.1 if not wgui.fill_rectangle then - print('BreitbandGraphics requires a Mupen64-rr-lua version newer than 1.1.2\r\n') + print("BreitbandGraphics requires a Mupen64-rr-lua version newer than 1.1.2\r\n") end BreitbandGraphics = { color_to_hex = function(color) - return string.format('#%06X', + return string.format("#%06X", (color.r * 0x10000) + (color.g * 0x100) + color.b) end, hex_to_color = function(hex) @@ -14,7 +14,7 @@ BreitbandGraphics = { { r = tonumber(hex:sub(2, 3), 16), g = tonumber(hex:sub(4, 5), 16), - b = tonumber(hex:sub(6, 7), 16), + b = tonumber(hex:sub(6, 7), 16) } end, repeated_to_color = function(value) @@ -22,7 +22,7 @@ BreitbandGraphics = { { r = value, g = value, - b = value, + b = value } end, @@ -30,42 +30,42 @@ BreitbandGraphics = { white = { r = 255, g = 255, - b = 255, + b = 255 }, black = { r = 0, g = 0, - b = 0, + b = 0 }, red = { r = 255, g = 0, - b = 0, + b = 0 }, green = { r = 0, g = 255, - b = 0, + b = 0 }, blue = { r = 0, g = 0, - b = 255, + b = 255 }, yellow = { r = 255, g = 255, - b = 0, + b = 0 }, orange = { r = 255, g = 128, - b = 0, + b = 0 }, magenta = { r = 255, g = 0, - b = 255, + b = 255 }, }, @@ -83,10 +83,10 @@ BreitbandGraphics = { bitmap_cache = {}, color_to_float = function(color) return { - r = color.r / 255.0, - g = color.g / 255.0, - b = color.b / 255.0, - a = (color.a and (color.a / 255.0) or 1.0), + r = (color.r and (color.r / 255.0) or 0.0), + g = (color.g and (color.g / 255.0) or 0.0), + b = (color.b and (color.b / 255.0) or 0.0), + a = (color.a and (color.a / 255.0) or 1.0) } end, get_text_size = function(text, font_size, font_name) @@ -127,9 +127,9 @@ BreitbandGraphics = { rectangle.width / 2, rectangle.height / 2, float_color.r, float_color.g, float_color.b, 1.0) end, draw_text = function(rectangle, horizontal_alignment, vertical_alignment, style, color, font_size, font_name, - text) + text) if text == nil then - text = '' + text = "" end local d_horizontal_alignment = 0 @@ -139,21 +139,21 @@ BreitbandGraphics = { local d_options = 0 local d_text_antialias_mode = 1 - if horizontal_alignment == 'center' then + if horizontal_alignment == "center" then d_horizontal_alignment = 2 - elseif horizontal_alignment == 'start' then + elseif horizontal_alignment == "start" then d_horizontal_alignment = 0 - elseif horizontal_alignment == 'end' then + elseif horizontal_alignment == "end" then d_horizontal_alignment = 1 - elseif horizontal_alignment == 'stretch' then + elseif horizontal_alignment == "stretch" then d_horizontal_alignment = 3 end - if vertical_alignment == 'center' then + if vertical_alignment == "center" then d_vertical_alignment = 2 - elseif vertical_alignment == 'start' then + elseif vertical_alignment == "start" then d_vertical_alignment = 0 - elseif vertical_alignment == 'end' then + elseif vertical_alignment == "end" then d_vertical_alignment = 1 end @@ -192,11 +192,11 @@ BreitbandGraphics = { end, draw_image = function(destination_rectangle, source_rectangle, path, color, filter) if not BreitbandGraphics.renderers.d2d.bitmap_cache[path] then - print('Loaded image from ' .. path) + print("Loaded image from " .. path) wgui.load_image(path, path) end if not filter then - filter = 'nearest' + filter = "nearest" end BreitbandGraphics.renderers.d2d.bitmap_cache[path] = path local float_color = BreitbandGraphics.renderers.d2d.color_to_float(color) @@ -204,25 +204,25 @@ BreitbandGraphics = { destination_rectangle.x + destination_rectangle.width, destination_rectangle.y + destination_rectangle.height, source_rectangle.x, source_rectangle.y, source_rectangle.x + source_rectangle.width, - source_rectangle.y + source_rectangle.height, path, float_color.a, filter == 'nearest' and 0 or 1) - end, + source_rectangle.y + source_rectangle.height, path, float_color.a, filter == "nearest" and 0 or 1) + end }, compat = { - brush = '#FF0000', - pen = '#FF0000', + brush = "#FF0000", + pen = "#FF0000", pen_thickness = 1, font_size = 0, - font_name = 'Fixedsys', - text_color = '#FF0000', - text_options = '', + font_name = "Fixedsys", + text_color = "#FF0000", + text_options = "", any_to_color = function(any) - if any:find('#') then + if any:find("#") then return BreitbandGraphics.hex_to_color(any) else if BreitbandGraphics.colors[any] then return BreitbandGraphics.colors[any] else - print("Can't resolve color " .. any .. ' to anything') + print("Can't resolve color " .. any .. " to anything") end end end, @@ -262,9 +262,9 @@ BreitbandGraphics = { y = y, width = 9999999999, height = size.height, - }, 'start', 'start', { - is_bold = BreitbandGraphics.renderers.compat.text_options:find('b'), - is_italic = BreitbandGraphics.renderers.compat.text_options:find('i'), + }, "start", "start", { + is_bold = BreitbandGraphics.renderers.compat.text_options:find("b"), + is_italic = BreitbandGraphics.renderers.compat.text_options:find("i") }, BreitbandGraphics.renderers.compat.any_to_color(BreitbandGraphics.renderers.compat.text_color), BreitbandGraphics.renderers.compat.font_size, BreitbandGraphics.renderers.compat.font_name, text) @@ -308,8 +308,8 @@ BreitbandGraphics = { height = 999999, }, identifier, BreitbandGraphics.colors.white) end, - }, - }, + } + } } -- reverse polyfill old gdi functions @@ -415,7 +415,7 @@ Mupen_lua_ugui = { input_state = {}, previous_input_state = {}, active_control_uid = nil, - previous_pointer_primary_down_position = {x = 0, y = 0}, + previous_pointer_primary_down_position = { x = 0, y = 0 }, hittest_ignore_rectangles = {}, -- we can only interact with one control per frame has_primary_input_been_handled = false, @@ -452,7 +452,7 @@ Mupen_lua_ugui = { bar_height = 16, item_height = 15, font_size = 12, - font_name = 'MS Shell Dlg 2', + font_name = "MS Shell Dlg 2", draw_raised_frame = function(control, visual_state) local back_color = BreitbandGraphics.repeated_to_color(225) @@ -462,23 +462,23 @@ Mupen_lua_ugui = { back_color = { r = 204, g = 228, - b = 247, + b = 247 } border_color = { r = 0, g = 84, - b = 153, + b = 153 } elseif visual_state == Mupen_lua_ugui.visual_states.hovered then back_color = { r = 229, g = 241, - b = 251, + b = 251 } border_color = { r = 0, g = 120, - b = 215, + b = 215 } elseif visual_state == Mupen_lua_ugui.visual_states.disabled then back_color = BreitbandGraphics.repeated_to_color(204) @@ -501,7 +501,7 @@ Mupen_lua_ugui = { Mupen_lua_ugui.stylers.windows_10.draw_raised_frame(control, visual_state) Mupen_lua_ugui.renderer.draw_text(control.rectangle, 'center', 'center', - {clip = true}, + { clip = true }, visual_state == Mupen_lua_ugui.visual_states.disabled and Mupen_lua_ugui.stylers.windows_10.button_disabled_text_color or BreitbandGraphics.colors.black, Mupen_lua_ugui.stylers.windows_10.font_size, @@ -526,7 +526,7 @@ Mupen_lua_ugui = { border_color = { r = 0, g = 84, - b = 153, + b = 153 } elseif visual_state == Mupen_lua_ugui.visual_states.disabled then back_color = BreitbandGraphics.repeated_to_color(240) @@ -561,9 +561,9 @@ Mupen_lua_ugui = { Mupen_lua_ugui.stylers.windows_10.font_size, Mupen_lua_ugui.stylers.windows_10.font_name) .width, - height = control.rectangle.height, + height = control.rectangle.height }, - BreitbandGraphics.hex_to_color('#0078D7')) + BreitbandGraphics.hex_to_color("#0078D7")) end Mupen_lua_ugui.renderer.draw_text({ @@ -571,7 +571,7 @@ Mupen_lua_ugui = { y = control.rectangle.y, width = control.rectangle.width - Mupen_lua_ugui.stylers.windows_10.textbox_padding * 2, height = control.rectangle.height, - }, 'start', 'start', {clip = true}, visual_state == Mupen_lua_ugui.visual_states.disabled and + }, 'start', 'start', { clip = true }, visual_state == Mupen_lua_ugui.visual_states.disabled and Mupen_lua_ugui.stylers.windows_10.button_disabled_text_color or BreitbandGraphics.colors.black, Mupen_lua_ugui.stylers.windows_10.font_size, Mupen_lua_ugui.stylers.windows_10.font_name, control.text) @@ -605,14 +605,14 @@ Mupen_lua_ugui = { x = selection_start_x, y = control.rectangle.y, width = selection_end_x - selection_start_x, - height = control.rectangle.height, + height = control.rectangle.height }) Mupen_lua_ugui.renderer.draw_text({ x = control.rectangle.x + Mupen_lua_ugui.stylers.windows_10.textbox_padding, y = control.rectangle.y, width = control.rectangle.width - Mupen_lua_ugui.stylers.windows_10.textbox_padding * 2, height = control.rectangle.height, - }, 'start', 'start', {clip = true}, BreitbandGraphics.colors.white, + }, 'start', 'start', { clip = true }, BreitbandGraphics.colors.white, Mupen_lua_ugui.stylers.windows_10.font_size, Mupen_lua_ugui.stylers.windows_10.font_name, control.text) Mupen_lua_ugui.renderer.pop_clip() @@ -628,18 +628,18 @@ Mupen_lua_ugui = { if visual_state == Mupen_lua_ugui.visual_states.active and math.floor(os.clock() * 2) % 2 == 0 and not should_visualize_selection then Mupen_lua_ugui.renderer.draw_line({ x = control.rectangle.x + caret_x, - y = control.rectangle.y + 2, + y = control.rectangle.y + 2 }, { x = control.rectangle.x + caret_x, y = control.rectangle.y + math.max(15, Mupen_lua_ugui.renderer.get_text_size(string_to_caret, 12, Mupen_lua_ugui.stylers.windows_10.font_name) - .height), -- TODO: move text measurement into BreitbandGraphics + .height) -- TODO: move text measurement into BreitbandGraphics }, { r = 0, g = 0, - b = 0, + b = 0 }, 1) end end, @@ -656,12 +656,12 @@ Mupen_lua_ugui = { local tip_color = { r = 255, g = 0, - b = 0, + b = 0 } local line_color = { r = 0, g = 0, - b = 255, + b = 255 } if visual_state == Mupen_lua_ugui.visual_states.disabled then @@ -669,12 +669,12 @@ Mupen_lua_ugui = { tip_color = { r = 255, g = 128, - b = 128, + b = 128 } line_color = { r = 128, g = 128, - b = 255, + b = 255 } end @@ -682,7 +682,7 @@ Mupen_lua_ugui = { x = remap(control.position.x, 0, 1, control.rectangle.x, control.rectangle.x + control.rectangle.width), y = remap(control.position.y, 0, 1, control.rectangle.y, - control.rectangle.y + control.rectangle.height), + control.rectangle.y + control.rectangle.height) } Mupen_lua_ugui.stylers.windows_10.draw_raised_frame(control, visual_state) Mupen_lua_ugui.renderer.fill_ellipse(BreitbandGraphics.inflate_rectangle(control.rectangle, -1), @@ -694,7 +694,7 @@ Mupen_lua_ugui = { y = control.rectangle.y, }, { x = control.rectangle.x + control.rectangle.width / 2, - y = control.rectangle.y + control.rectangle.height, + y = control.rectangle.y + control.rectangle.height }, outline_color, 1) Mupen_lua_ugui.renderer.draw_line({ x = control.rectangle.x, @@ -723,7 +723,7 @@ Mupen_lua_ugui = { local track_color = { r = 231, g = 234, - b = 234, + b = 234 } local track_rectangle = {} local track_border_color = BreitbandGraphics.repeated_to_color(214) @@ -732,14 +732,14 @@ Mupen_lua_ugui = { x = rectangle.x + rectangle.width / 2 - Mupen_lua_ugui.stylers.windows_10.track_thickness / 2, y = rectangle.y, width = Mupen_lua_ugui.stylers.windows_10.track_thickness, - height = rectangle.height, + height = rectangle.height } else track_rectangle = { x = rectangle.x, y = rectangle.y + rectangle.height / 2 - Mupen_lua_ugui.stylers.windows_10.track_thickness / 2, width = rectangle.width, - height = Mupen_lua_ugui.stylers.windows_10.track_thickness, + height = Mupen_lua_ugui.stylers.windows_10.track_thickness } end @@ -751,7 +751,7 @@ Mupen_lua_ugui = { local head_color = { r = 0, g = 122, - b = 217, + b = 217 } if visual_state == Mupen_lua_ugui.visual_states.hovered then head_color = BreitbandGraphics.repeated_to_color(23) @@ -769,7 +769,7 @@ Mupen_lua_ugui = { y = rectangle.y + (value * rectangle.height) - Mupen_lua_ugui.stylers.windows_10.bar_width / 2, width = effective_bar_height, - height = Mupen_lua_ugui.stylers.windows_10.bar_width, + height = Mupen_lua_ugui.stylers.windows_10.bar_width } else head_rectangle = { @@ -778,7 +778,7 @@ Mupen_lua_ugui = { y = rectangle.y + rectangle.height / 2 - effective_bar_height / 2, width = Mupen_lua_ugui.stylers.windows_10.bar_width, - height = effective_bar_height, + height = effective_bar_height } end Mupen_lua_ugui.renderer.fill_rectangle(head_rectangle, head_color) @@ -813,7 +813,7 @@ Mupen_lua_ugui = { y = control.rectangle.y, width = control.rectangle.width, height = control.rectangle.height, - }, 'start', 'center', {clip = true}, text_color, Mupen_lua_ugui.stylers.windows_10.font_size, + }, 'start', 'center', { clip = true }, text_color, Mupen_lua_ugui.stylers.windows_10.font_size, Mupen_lua_ugui.stylers.windows_10.font_name, control.items[control.selected_index]) @@ -822,19 +822,19 @@ Mupen_lua_ugui = { y = control.rectangle.y, width = control.rectangle.width - Mupen_lua_ugui.stylers.windows_10.textbox_padding * 4, height = control.rectangle.height, - }, 'end', 'center', {clip = true}, text_color, Mupen_lua_ugui.stylers.windows_10.font_size, - 'Segoe UI Mono', 'v') + }, 'end', 'center', { clip = true }, text_color, Mupen_lua_ugui.stylers.windows_10.font_size, + "Segoe UI Mono", "v") if Mupen_lua_ugui.control_data[control.uid].is_open then Mupen_lua_ugui.renderer.fill_rectangle(BreitbandGraphics.inflate_rectangle({ x = control.rectangle.x + 1, y = control.rectangle.y + control.rectangle.height, width = control.rectangle.width - 2, - height = #control.items * Mupen_lua_ugui.stylers.windows_10.item_height, + height = #control.items * Mupen_lua_ugui.stylers.windows_10.item_height }, 1), { r = 0, g = 120, - b = 215, + b = 215 }) for i = 1, #control.items, 1 do @@ -843,7 +843,7 @@ Mupen_lua_ugui = { y = control.rectangle.y + control.rectangle.height + (Mupen_lua_ugui.stylers.windows_10.item_height * (i - 1)), width = control.rectangle.width - 2, - height = Mupen_lua_ugui.stylers.windows_10.item_height, + height = Mupen_lua_ugui.stylers.windows_10.item_height } local back_color = BreitbandGraphics.colors.white @@ -852,14 +852,14 @@ Mupen_lua_ugui = { back_color = { r = 0, g = 120, - b = 215, + b = 215 } text_color = BreitbandGraphics.colors.white end Mupen_lua_ugui.renderer.fill_rectangle(rect, back_color) rect.x = rect.x + 2 - Mupen_lua_ugui.renderer.draw_text(rect, 'start', 'center', {clip = true}, text_color, + Mupen_lua_ugui.renderer.draw_text(rect, 'start', 'center', { clip = true }, text_color, Mupen_lua_ugui.stylers.windows_10.font_size, Mupen_lua_ugui.stylers.windows_10.font_name, control.items[i]) @@ -871,12 +871,12 @@ Mupen_lua_ugui = { Mupen_lua_ugui.renderer.fill_rectangle(BreitbandGraphics.inflate_rectangle(control.rectangle, 1), { r = 130, g = 135, - b = 144, + b = 144 }) Mupen_lua_ugui.renderer.fill_rectangle(control.rectangle, { r = 255, g = 255, - b = 255, + b = 255 }) local visual_state = Mupen_lua_ugui.get_visual_state(control) @@ -909,7 +909,7 @@ Mupen_lua_ugui = { local accent_color = { r = 0, g = 120, - b = 215, + b = 215 } if visual_state == Mupen_lua_ugui.visual_states.disabled then @@ -921,7 +921,7 @@ Mupen_lua_ugui = { x = control.rectangle.x, y = control.rectangle.y + y, width = control.rectangle.width, - height = Mupen_lua_ugui.stylers.windows_10.item_height, + height = Mupen_lua_ugui.stylers.windows_10.item_height }, accent_color) text_color = BreitbandGraphics.colors.white @@ -936,8 +936,8 @@ Mupen_lua_ugui = { x = control.rectangle.x + 2, y = control.rectangle.y + y, width = control.rectangle.width, - height = Mupen_lua_ugui.stylers.windows_10.item_height, - }, 'start', 'center', {clip = true}, text_color, Mupen_lua_ugui.stylers.windows_10.font_size, + height = Mupen_lua_ugui.stylers.windows_10.item_height + }, 'start', 'center', { clip = true }, text_color, Mupen_lua_ugui.stylers.windows_10.font_size, Mupen_lua_ugui.stylers.windows_10.font_name, control.items[i]) end @@ -957,19 +957,19 @@ Mupen_lua_ugui = { x = control.rectangle.x + control.rectangle.width - 10, y = control.rectangle.y, width = 10, - height = control.rectangle.height, + height = control.rectangle.height }, BreitbandGraphics.repeated_to_color(240)) Mupen_lua_ugui.renderer.fill_rectangle({ x = control.rectangle.x + control.rectangle.width - 10, y = control.rectangle.y + scrollbar_y, width = 10, - height = scrollbar_height, + height = scrollbar_height }, BreitbandGraphics.repeated_to_color(204)) end Mupen_lua_ugui.renderer.pop_clip() - end, + end }, }, @@ -1113,11 +1113,11 @@ Mupen_lua_ugui = { Mupen_lua_ugui.control_data[control.uid].caret_index = lower_selection Mupen_lua_ugui.control_data[control.uid].selection_start = lower_selection Mupen_lua_ugui.control_data[control.uid].selection_end = lower_selection - text = insert_at(text, ' ', Mupen_lua_ugui.control_data[control.uid].caret_index - 1) + text = insert_at(text, " ", Mupen_lua_ugui.control_data[control.uid].caret_index - 1) Mupen_lua_ugui.control_data[control.uid].caret_index = Mupen_lua_ugui.control_data[control.uid] .caret_index + 1 else - text = insert_at(text, ' ', Mupen_lua_ugui.control_data[control.uid].caret_index - 1) + text = insert_at(text, " ", Mupen_lua_ugui.control_data[control.uid].caret_index - 1) Mupen_lua_ugui.control_data[control.uid].caret_index = Mupen_lua_ugui.control_data[control.uid] .caret_index + 1 end @@ -1254,7 +1254,7 @@ Mupen_lua_ugui = { x = control.rectangle.x, y = control.rectangle.y + control.rectangle.height, width = control.rectangle.width, - height = Mupen_lua_ugui.styler.item_height * #control.items, + height = Mupen_lua_ugui.styler.item_height * #control.items }) then Mupen_lua_ugui.control_data[control.uid].is_open = false end @@ -1270,7 +1270,7 @@ Mupen_lua_ugui = { y = control.rectangle.y + control.rectangle.height + (Mupen_lua_ugui.styler.item_height * (i - 1)), width = control.rectangle.width, - height = Mupen_lua_ugui.styler.item_height, + height = Mupen_lua_ugui.styler.item_height }) then if is_pointer_just_down() then selected_index = i @@ -1290,7 +1290,7 @@ Mupen_lua_ugui = { x = control.rectangle.x, y = control.rectangle.y + control.rectangle.height, width = control.rectangle.width, - height = Mupen_lua_ugui.styler.item_height * #control.items, + height = Mupen_lua_ugui.styler.item_height * #control.items } end selected_index = clamp(selected_index, 1, #control.items) @@ -1359,5 +1359,5 @@ Mupen_lua_ugui = { Mupen_lua_ugui.styler.draw_listbox(control) return selected_index - end, + end }