From 94d86b91ec07867efa48a88b909e1108df3cf24d Mon Sep 17 00:00:00 2001 From: HugoBDesigner Date: Thu, 22 May 2025 01:41:53 -0300 Subject: [PATCH 1/2] Shift to draw line, new colors for pen Buttons 7, 8 and 9 now correspond to colors white, gray and black. Holding Shift and clicking two points now draws a straight line between them. This also applies to eraser. --- whiteboard.lua | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/whiteboard.lua b/whiteboard.lua index d044f5b..36fcf2c 100644 --- a/whiteboard.lua +++ b/whiteboard.lua @@ -25,7 +25,10 @@ function M.create_whiteboard() whiteboard.previous_color_index = 1 whiteboard.color_index = 1 --Color format is 0xABGR - whiteboard.color_array = {0xff4d4de8, 0xff4d9de8, 0xff4de5e8, 0xff4de88e, 0xff95e84d, 0xffe8d34d, 0xffe8574d, 0xffe84d9d, 0xffbc4de8} + -- OLD INDEX: RED, ORANGE, YELLOW, GREEN, TEAL, BLUE, INDIGO, PURPLE, MAGENTA + -- whiteboard.color_array = {0xff4d4de8, 0xff4d9de8, 0xff4de5e8, 0xff4de88e, 0xff95e84d, 0xffe8d34d, 0xffe8574d, 0xffe84d9d, 0xffbc4de8} + -- NEW INDEX: RED, ORANGE, YELLOW, GREEN (AVOCADO), BLUE, PURPLE, WHITE, GRAY, BLACK + whiteboard.color_array = {0xff3a12ea, 0xff236cf5, 0xff0dc6ff, 0xff12b362, 0xfffc6541, 0xff80035e, 0xffffffff, 0xff808080, 0xff000000} whiteboard.draw_size = 6 whiteboard.eraser_size = 26 whiteboard.size_max = 12 -- size_max must be a minimum of 2. @@ -232,6 +235,8 @@ function M.create_whiteboard() end whiteboard.update = function (source, graphics) + local shift_down = winapi.GetAsyncKeyState(0x10) + local mouse_down = winapi.GetAsyncKeyState(winapi.VK_LBUTTON) local window = winapi.GetForegroundWindow() if mouse_down then @@ -260,20 +265,34 @@ function M.create_whiteboard() end if whiteboard.color_index ~= 0 or #(whiteboard.lines) > 0 then + local linepoints = false + if (not whiteboard.drawing and shift_down and #whiteboard.lines > 0) then + -- Extend previous point + whiteboard.drawing = true + local current_line = whiteboard.lines[#(whiteboard.lines)] + local lastpoint = current_line.points[ #(current_line.points) ] + + whiteboard.prev_mouse_pos = {x = lastpoint.x, y = lastpoint.y} + end + if whiteboard.drawing then local effect = obs.obs_get_base_effect(obs.OBS_EFFECT_DEFAULT) if not effect then return end + + if linepoints == false then + linepoints = { + { x = whiteboard.prev_mouse_pos.x, y = whiteboard.prev_mouse_pos.y }, + { x = mouse_pos.x, y = mouse_pos.y } + } + end local new_segment = { color = whiteboard.color_index, size = size, arrow = whiteboard.arrow_mode, - points = { - { x = whiteboard.prev_mouse_pos.x, y = whiteboard.prev_mouse_pos.y }, - { x = mouse_pos.x, y = mouse_pos.y } - } + points = linepoints } local current_line = whiteboard.lines[#(whiteboard.lines)] @@ -335,4 +354,4 @@ function M.create_whiteboard() return whiteboard end -return M \ No newline at end of file +return M From 16ce03113f8e8261e8a2cd128541a754f84f1a24 Mon Sep 17 00:00:00 2001 From: HugoBDesigner Date: Thu, 22 May 2025 01:47:13 -0300 Subject: [PATCH 2/2] Removed redundant code Redundant code from a previous version that wasn't actually doing anything --- whiteboard.lua | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/whiteboard.lua b/whiteboard.lua index 36fcf2c..c1d8ffc 100644 --- a/whiteboard.lua +++ b/whiteboard.lua @@ -265,7 +265,6 @@ function M.create_whiteboard() end if whiteboard.color_index ~= 0 or #(whiteboard.lines) > 0 then - local linepoints = false if (not whiteboard.drawing and shift_down and #whiteboard.lines > 0) then -- Extend previous point whiteboard.drawing = true @@ -281,18 +280,14 @@ function M.create_whiteboard() return end - if linepoints == false then - linepoints = { - { x = whiteboard.prev_mouse_pos.x, y = whiteboard.prev_mouse_pos.y }, - { x = mouse_pos.x, y = mouse_pos.y } - } - end - local new_segment = { color = whiteboard.color_index, size = size, arrow = whiteboard.arrow_mode, - points = linepoints + points = { + { x = whiteboard.prev_mouse_pos.x, y = whiteboard.prev_mouse_pos.y }, + { x = mouse_pos.x, y = mouse_pos.y } + } } local current_line = whiteboard.lines[#(whiteboard.lines)]