diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-07-11 23:03:27 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-07-11 23:18:26 -0700 |
commit | 3850fbac35bb5679ed58753491db4a4cd2267a73 (patch) | |
tree | a296ccc5d26f507d38fe4771c453ae4a2ef012c2 | |
parent | 2e3a85d94be44bfb53554d0e7ba8a36f8e91c605 (diff) | |
download | view.love-3850fbac35bb5679ed58753491db4a4cd2267a73.tar.gz |
make colors easier to edit
-rw-r--r-- | app.lua | 4 | ||||
-rw-r--r-- | drawing.lua | 14 | ||||
-rw-r--r-- | edit.lua | 14 | ||||
-rw-r--r-- | help.lua | 8 | ||||
-rw-r--r-- | icons.lua | 17 | ||||
-rw-r--r-- | search.lua | 6 | ||||
-rw-r--r-- | select.lua | 4 | ||||
-rw-r--r-- | text.lua | 8 |
8 files changed, 38 insertions, 37 deletions
diff --git a/app.lua b/app.lua index e5be2b0..56b9dba 100644 --- a/app.lua +++ b/app.lua @@ -157,6 +157,10 @@ function App.screen.print(msg, x,y) end end +function App.color(color) + love.graphics.setColor(color.r, color.g, color.b, color.a) +end + App.time = 1 function App.getTime() return App.time diff --git a/drawing.lua b/drawing.lua index 8668915..53f2c78 100644 --- a/drawing.lua +++ b/drawing.lua @@ -7,7 +7,7 @@ require 'drawing_tests' function Drawing.draw(line) local pmx,pmy = App.mouse_x(), App.mouse_y() if pmx < App.screen.width-Margin_right and pmy > line.y and pmy < line.y+Drawing.pixels(line.h) then - love.graphics.setColor(0.75,0.75,0.75) + App.color(Icon_color) love.graphics.rectangle('line', Margin_left,line.y, App.screen.width-Margin_width,Drawing.pixels(line.h)) if icon[Current_drawing_mode] then icon[Current_drawing_mode](App.screen.width-Margin_right-22, line.y+4) @@ -31,19 +31,19 @@ function Drawing.draw(line) for _,shape in ipairs(line.shapes) do assert(shape) if geom.on_shape(mx,my, line, shape) then - love.graphics.setColor(1,0,0) + App.color(Focus_stroke_color) else - love.graphics.setColor(0,0,0) + App.color(Stroke_color) end Drawing.draw_shape(Margin_left,line.y, line, shape) end for i,p in ipairs(line.points) do if p.deleted == nil then if Drawing.near(p, mx,my) then - love.graphics.setColor(1,0,0) + App.color(Focus_stroke_color) love.graphics.circle('line', Drawing.pixels(p.x)+Margin_left,Drawing.pixels(p.y)+line.y, 4) else - love.graphics.setColor(0,0,0) + App.color(Stroke_color) love.graphics.circle('fill', Drawing.pixels(p.x)+Margin_left,Drawing.pixels(p.y)+line.y, 2) end if p.name then @@ -52,7 +52,7 @@ function Drawing.draw(line) love.graphics.print(p.name, x,y) if Current_drawing_mode == 'name' and i == line.pending.target_point then -- create a faint red box for the name - love.graphics.setColor(1,0,0,0.1) + App.color(Current_name_background_color) local name_text -- TODO: avoid computing name width on every repaint if p.name == '' then @@ -65,7 +65,7 @@ function Drawing.draw(line) end end end - love.graphics.setColor(0.75,0.75,0.75) + App.color(Current_stroke_color) Drawing.draw_pending_shape(Margin_left,line.y, line) end diff --git a/edit.lua b/edit.lua index 8ecbf24..c2a6a90 100644 --- a/edit.lua +++ b/edit.lua @@ -1,3 +1,15 @@ +-- some constants people might like to tweak +Text_color = {r=0, g=0, b=0} +Cursor_color = {r=1, g=0, b=0} +Stroke_color = {r=0, g=0, b=0} +Current_stroke_color = {r=0.7, g=0.7, b=0.7} -- in process of being drawn +Current_name_background_color = {r=1, g=0, b=0, a=0.1} -- name currently being edited +Focus_stroke_color = {r=1, g=0, b=0} -- what mouse is hovering over +Highlight_color = {r=0.7, g=0.7, b=0.9} -- selected text +Icon_color = {r=0.7, g=0.7, b=0.7} -- color of current mode icon in drawings +Help_color = {r=0, g=0.5, b=0} +Help_background_color = {r=0, g=0.5, b=0, a=0.1} + utf8 = require 'utf8' require 'file' @@ -102,7 +114,7 @@ end -- App.initialize_globals function edit.draw() Button_handlers = {} - love.graphics.setColor(0, 0, 0) + App.color(Text_color) --? print(Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos) assert(Text.le1(Screen_top1, Cursor1)) Cursor_y = -1 diff --git a/help.lua b/help.lua index ccaed84..92cdb0a 100644 --- a/help.lua +++ b/help.lua @@ -1,5 +1,5 @@ function draw_help_without_mouse_pressed(drawing) - love.graphics.setColor(0,0.5,0) + App.color(Help_color) local y = drawing.y+10 love.graphics.print("Things you can do:", Margin_left+30,y) y = y + Line_height @@ -45,12 +45,12 @@ function draw_help_without_mouse_pressed(drawing) y = y + Line_height love.graphics.print("Press 'esc' now to hide this message", Margin_left+30,y) y = y + Line_height - love.graphics.setColor(0,0.5,0, 0.1) + App.color(Help_background_color) love.graphics.rectangle('fill', Margin_left,drawing.y, App.screen.width-Margin_width, math.max(Drawing.pixels(drawing.h),y-drawing.y)) end function draw_help_with_mouse_pressed(drawing) - love.graphics.setColor(0,0.5,0) + App.color(Help_color) local y = drawing.y+10 love.graphics.print("You're currently drawing a "..current_shape(drawing.pending), Margin_left+30,y) y = y + Line_height @@ -124,7 +124,7 @@ function draw_help_with_mouse_pressed(drawing) love.graphics.print("* Press 's' to switch to drawing squares", Margin_left+30,y) y = y + Line_height end - love.graphics.setColor(0,0.5,0, 0.1) + App.color(Help_background_color) love.graphics.rectangle('fill', Margin_left,drawing.y, App.screen.width-Margin_width, math.max(Drawing.pixels(drawing.h),y-drawing.y)) end diff --git a/icons.lua b/icons.lua index 06ebf50..19939cf 100644 --- a/icons.lua +++ b/icons.lua @@ -1,25 +1,10 @@ icon = {} -function icon.line_width(x, y) - love.graphics.setColor(0.7,0.7,0.7) - love.graphics.line(x+0,y+0, x+9,y+0) - love.graphics.line(x+0,y+1, x+9,y+1) - love.graphics.line(x+0,y+2, x+9,y+2) - love.graphics.line(x+0,y+3, x+9,y+3) - love.graphics.line(x+0,y+4, x+9,y+4) - love.graphics.line(x+0,y+5, x+9,y+5) - love.graphics.line(x+1,y+6, x+8,y+6) - love.graphics.line(x+2,y+7, x+7,y+7) - love.graphics.line(x+3,y+8, x+6,y+8) - love.graphics.line(x+4,y+9, x+5,y+9) -end - function icon.insert_drawing(x, y) - love.graphics.setColor(0.7,0.7,0.7) + App.color(Icon_color) love.graphics.rectangle('line', x,y, 12,12) love.graphics.line(4,y+6, 16,y+6) love.graphics.line(10,y, 10,y+12) - love.graphics.setColor(0, 0, 0) end function icon.freehand(x, y) diff --git a/search.lua b/search.lua index 5ab9e04..eca7cd7 100644 --- a/search.lua +++ b/search.lua @@ -11,14 +11,14 @@ function Text.draw_search_bar() love.graphics.rectangle('fill', 20, y-6, App.screen.width-40, h+2, 2,2) love.graphics.setColor(0.6,0.6,0.6) love.graphics.rectangle('line', 20, y-6, App.screen.width-40, h+2, 2,2) - love.graphics.setColor(0,0,0) + App.color(Text_color) App.screen.print(Search_term, 25,y-5) - love.graphics.setColor(1,0,0) + App.color(Cursor_color) if Search_text == nil then Search_text = App.newText(love.graphics.getFont(), Search_term) end love.graphics.circle('fill', 25+App.width(Search_text),y-5+h, 2) - love.graphics.setColor(0,0,0) + App.color(Text_color) end function Text.search_next() diff --git a/select.lua b/select.lua index adf4739..9e88c60 100644 --- a/select.lua +++ b/select.lua @@ -68,9 +68,9 @@ function Text.draw_highlight(line, x,y, pos, lo,hi) local s = line.data:sub(lo_offset, hi_offset-1) local text = App.newText(love.graphics.getFont(), s) local text_width = App.width(text) - love.graphics.setColor(0.7,0.7,0.9) + App.color(Highlight_color) love.graphics.rectangle('fill', x+lo_px,y, text_width,Line_height) - love.graphics.setColor(0,0,0) + App.color(Text_color) return lo_px end end diff --git a/text.lua b/text.lua index 9926269..c61a488 100644 --- a/text.lua +++ b/text.lua @@ -11,7 +11,7 @@ require 'text_tests' -- position of start of final screen line drawn function Text.draw(line, line_index, top, left, right) --? print('text.draw', line_index) - love.graphics.setColor(0,0,0) + App.color(Text_color) -- wrap long lines local x = left local y = top @@ -59,7 +59,7 @@ function Text.draw(line, line_index, top, left, right) if Search_term then if Lines[Cursor1.line].data:sub(Cursor1.pos, Cursor1.pos+utf8.len(Search_term)-1) == Search_term then local lo_px = Text.draw_highlight(line, x,y, pos, Cursor1.pos, Cursor1.pos+utf8.len(Search_term)) - love.graphics.setColor(0,0,0) + App.color(Text_color) love.graphics.print(Search_term, x+lo_px,y) end else @@ -83,9 +83,9 @@ end function Text.draw_cursor(x, y) -- blink every 0.5s if math.floor(Cursor_time*2)%2 == 0 then - love.graphics.setColor(1,0,0) + App.color(Cursor_color) love.graphics.rectangle('fill', x,y, 3,Line_height) - love.graphics.setColor(0,0,0) + App.color(Text_color) end Cursor_x = x Cursor_y = y+Line_height |