crisp font rendering

This commit is contained in:
Kartik K. Agaram 2022-06-02 23:36:07 -07:00
parent b94b007db5
commit 9bbfc2be13
5 changed files with 226 additions and 281 deletions

View File

@ -49,7 +49,7 @@ function Drawing.draw(line)
if p.name then
-- todo: clip
local x,y = Drawing.pixels(p.x)+16+5, Drawing.pixels(p.y)+line.y+5
love.graphics.print(p.name, x,y, 0, Zoom)
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)
@ -60,7 +60,7 @@ function Drawing.draw(line)
else
name_text = App.newText(love.graphics.getFont(), p.name)
end
love.graphics.rectangle('fill', x,y, math.floor(App.width(name_text)*Zoom), math.floor(15*Zoom))
love.graphics.rectangle('fill', x,y, App.width(name_text), Line_height)
end
end
end
@ -355,19 +355,7 @@ function Drawing.mouse_released(x,y, button)
end
function Drawing.keychord_pressed(chord)
if chord == 'C-=' then
Line_width = Line_width/Zoom
Zoom = Zoom+0.5
Line_width = Line_width*Zoom
elseif chord == 'C--' then
Line_width = Line_width/Zoom
Zoom = Zoom-0.5
Line_width = Line_width*Zoom
elseif chord == 'C-0' then
Line_width = Line_width/Zoom
Zoom = 1.5
Line_width = Line_width*Zoom
elseif chord == 'C-f' and not love.mouse.isDown('1') then
if chord == 'C-f' and not love.mouse.isDown('1') then
Current_drawing_mode = 'freehand'
elseif chord == 'C-g' and not love.mouse.isDown('1') then
Current_drawing_mode = 'polygon'

136
help.lua
View File

@ -1,56 +1,56 @@
function draw_help_without_mouse_pressed(drawing)
love.graphics.setColor(0,0.5,0)
local y = drawing.y+10
love.graphics.print("Things you can do:", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Press the mouse button to start drawing a "..current_shape(), 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Hover on a point and press 'ctrl+v' to start moving it,", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("then press the mouse button to finish", 16+30+bullet_indent(),y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Hover on a point and press 'ctrl+n' to name it,", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("then press 'enter' to finish", 16+30+bullet_indent(),y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Hover on a point or shape and press 'ctrl+d' to delete it", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("Things you can do:", 16+30,y)
y = y + Line_height
love.graphics.print("* Press the mouse button to start drawing a "..current_shape(), 16+30,y)
y = y + Line_height
love.graphics.print("* Hover on a point and press 'ctrl+v' to start moving it,", 16+30,y)
y = y + Line_height
love.graphics.print("then press the mouse button to finish", 16+30+bullet_indent(),y)
y = y + Line_height
love.graphics.print("* Hover on a point and press 'ctrl+n' to name it,", 16+30,y)
y = y + Line_height
love.graphics.print("then press 'enter' to finish", 16+30+bullet_indent(),y)
y = y + Line_height
love.graphics.print("* Hover on a point or shape and press 'ctrl+d' to delete it", 16+30,y)
y = y + Line_height
y = y + Line_height
if Current_drawing_mode ~= 'freehand' then
love.graphics.print("* Press 'ctrl+f' to switch to drawing freehand strokes", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Press 'ctrl+f' to switch to drawing freehand strokes", 16+30,y)
y = y + Line_height
end
if Current_drawing_mode ~= 'line' then
love.graphics.print("* Press 'ctrl+l' to switch to drawing lines", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Press 'ctrl+l' to switch to drawing lines", 16+30,y)
y = y + Line_height
end
if Current_drawing_mode ~= 'manhattan' then
love.graphics.print("* Press 'ctrl+m' to switch to drawing horizontal/vertical lines", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Press 'ctrl+m' to switch to drawing horizontal/vertical lines", 16+30,y)
y = y + Line_height
end
if Current_drawing_mode ~= 'circle' then
love.graphics.print("* Press 'ctrl+c' to switch to drawing circles/arcs", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Press 'ctrl+c' to switch to drawing circles/arcs", 16+30,y)
y = y + Line_height
end
if Current_drawing_mode ~= 'polygon' then
love.graphics.print("* Press 'ctrl+g' to switch to drawing polygons", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Press 'ctrl+g' to switch to drawing polygons", 16+30,y)
y = y + Line_height
end
if Current_drawing_mode ~= 'rectangle' then
love.graphics.print("* Press 'ctrl+r' to switch to drawing rectangles", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Press 'ctrl+r' to switch to drawing rectangles", 16+30,y)
y = y + Line_height
end
if Current_drawing_mode ~= 'square' then
love.graphics.print("* Press 'ctrl+s' to switch to drawing squares", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Press 'ctrl+s' to switch to drawing squares", 16+30,y)
y = y + Line_height
end
love.graphics.print("* Press 'ctrl+=' or 'ctrl+-' to Zoom in or out", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Press 'ctrl+0' to reset Zoom", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("Hit 'esc' now to hide this message", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Press 'ctrl+=' or 'ctrl+-' to zoom in or out", 16+30,y)
y = y + Line_height
love.graphics.print("* Press 'ctrl+0' to reset zoom", 16+30,y)
y = y + Line_height
y = y + Line_height
love.graphics.print("Hit 'esc' now to hide this message", 16+30,y)
y = y + Line_height
love.graphics.setColor(0,0.5,0, 0.1)
love.graphics.rectangle('fill', 16,drawing.y, Line_width, math.max(Drawing.pixels(drawing.h),y-drawing.y))
end
@ -58,57 +58,57 @@ end
function draw_help_with_mouse_pressed(drawing)
love.graphics.setColor(0,0.5,0)
local y = drawing.y+10
love.graphics.print("You're currently drawing a "..current_shape(drawing.pending), 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print('Things you can do now:', 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("You're currently drawing a "..current_shape(drawing.pending), 16+30,y)
y = y + Line_height
love.graphics.print('Things you can do now:', 16+30,y)
y = y + Line_height
if Current_drawing_mode == 'freehand' then
love.graphics.print('* Release the mouse button to finish drawing the stroke', 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print('* Release the mouse button to finish drawing the stroke', 16+30,y)
y = y + Line_height
elseif Current_drawing_mode == 'line' or Current_drawing_mode == 'manhattan' then
love.graphics.print('* Release the mouse button to finish drawing the line', 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print('* Release the mouse button to finish drawing the line', 16+30,y)
y = y + Line_height
elseif Current_drawing_mode == 'circle' then
if drawing.pending.mode == 'circle' then
love.graphics.print('* Release the mouse button to finish drawing the circle', 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Press 'a' to draw just an arc of a circle", 16+30,y, 0, Zoom)
love.graphics.print('* Release the mouse button to finish drawing the circle', 16+30,y)
y = y + Line_height
love.graphics.print("* Press 'a' to draw just an arc of a circle", 16+30,y)
else
love.graphics.print('* Release the mouse button to finish drawing the arc', 16+30,y, 0, Zoom)
love.graphics.print('* Release the mouse button to finish drawing the arc', 16+30,y)
end
y = y + math.floor(15*Zoom)
y = y + Line_height
elseif Current_drawing_mode == 'polygon' then
love.graphics.print('* Release the mouse button to finish drawing the polygon', 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Press 'p' to add a vertex to the polygon", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print('* Release the mouse button to finish drawing the polygon', 16+30,y)
y = y + Line_height
love.graphics.print("* Press 'p' to add a vertex to the polygon", 16+30,y)
y = y + Line_height
end
love.graphics.print("* Press 'esc' then release the mouse button to cancel the current shape", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Press 'esc' then release the mouse button to cancel the current shape", 16+30,y)
y = y + Line_height
y = y + Line_height
if Current_drawing_mode ~= 'line' then
love.graphics.print("* Press 'l' to switch to drawing lines", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Press 'l' to switch to drawing lines", 16+30,y)
y = y + Line_height
end
if Current_drawing_mode ~= 'manhattan' then
love.graphics.print("* Press 'm' to switch to drawing horizontal/vertical lines", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Press 'm' to switch to drawing horizontal/vertical lines", 16+30,y)
y = y + Line_height
end
if Current_drawing_mode ~= 'circle' then
love.graphics.print("* Press 'c' to switch to drawing circles/arcs", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Press 'c' to switch to drawing circles/arcs", 16+30,y)
y = y + Line_height
end
if Current_drawing_mode ~= 'polygon' then
love.graphics.print("* Press 'g' to switch to drawing polygons", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Press 'g' to switch to drawing polygons", 16+30,y)
y = y + Line_height
end
if Current_drawing_mode ~= 'rectangle' then
love.graphics.print("* Press 'g' to switch to drawing rectangles", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Press 'g' to switch to drawing rectangles", 16+30,y)
y = y + Line_height
end
if Current_drawing_mode ~= 'square' then
love.graphics.print("* Press 'g' to switch to drawing squares", 16+30,y, 0, Zoom)
y = y + math.floor(15*Zoom)
love.graphics.print("* Press 'g' to switch to drawing squares", 16+30,y)
y = y + Line_height
end
love.graphics.setColor(0,0.5,0, 0.1)
love.graphics.rectangle('fill', 16,drawing.y, Line_width, math.max(Drawing.pixels(drawing.h),y-drawing.y))

View File

@ -61,7 +61,8 @@ Cursor_x, Cursor_y = 0, 0 -- in pixels
Current_drawing_mode = 'line'
Previous_drawing_mode = nil
Zoom = 1.5
Font_height = 14
Line_height = 15
Filename = love.filesystem.getUserDirectory()..'/lines.txt'
@ -138,7 +139,7 @@ function App.draw()
--? print('== draw')
for line_index,line in ipairs(Lines) do
--? print('draw:', y, line_index, line)
if y + math.floor(15*Zoom) > App.screen.height then break end
if y + Line_height > App.screen.height then break end
--? print('a')
if line_index >= Screen_top1.line then
Screen_bottom1.line = line_index
@ -158,7 +159,7 @@ function App.draw()
Text.draw_cursor(25, y)
end
end
y = y + math.floor(15*Zoom) -- text height
y = y + Line_height
elseif line.mode == 'drawing' then
y = y+10 -- padding
line.y = y
@ -168,7 +169,7 @@ function App.draw()
--? print('text')
line.y = y
y, Screen_bottom1.pos = Text.draw(line, Line_width, line_index)
y = y + math.floor(15*Zoom) -- text height
y = y + Line_height
--? print('=> y', y)
end
end
@ -253,6 +254,21 @@ function App.keychord_pressed(chord)
Search_term = ''
Search_backup_cursor1 = {line=Cursor1.line, pos=Cursor1.pos}
assert(Search_text == nil)
elseif chord == 'C-=' then
Font_height = Font_height+2
love.graphics.setFont(love.graphics.newFont(Font_height))
Line_height = math.floor(Font_height*1.1)
Text.redraw_all()
elseif chord == 'C--' then
Font_height = Font_height-2
love.graphics.setFont(love.graphics.newFont(Font_height))
Text.redraw_all()
Line_height = math.floor(Font_height*1.1)
elseif chord == 'C-0' then
Font_height = 14
love.graphics.setFont(love.graphics.newFont(Font_height))
Text.redraw_all()
Line_height = 15
elseif love.mouse.isDown('1') or chord:sub(1,2) == 'C-' then
Drawing.keychord_pressed(chord)
elseif chord == 'escape' and love.mouse.isDown('1') then

328
text.lua

File diff suppressed because it is too large Load Diff

View File

@ -49,7 +49,6 @@ function snapshot(s,e)
cursor=deepcopy(Cursor1),
current_drawing_mode=Drawing_mode,
previous_drawing_mode=Previous_drawing_mode,
zoom=Zoom,
lines={},
start_line=s,
end_line=e,