make colors easier to edit

This commit is contained in:
Kartik K. Agaram 2022-07-11 23:03:27 -07:00
parent 2e3a85d94b
commit 3850fbac35
8 changed files with 38 additions and 37 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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()

View File

@ -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

View File

@ -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