Commit Graph

106 Commits

Author SHA1 Message Date
Kartik K. Agaram 95d88a8298 use editor state font for width calculations 2024-01-12 05:23:06 -08:00
Kartik K. Agaram 007b965b11 audit all asserts
Each one should provide a message that will show up within LÖVE. Stop
relying on nearby prints to the terminal.

I also found some unnecessary ones.

There is some potential here for performance regressions: the format()
calls will trigger whether or not the assertion fails, and cause
allocations. So far Lua's GC seems good enough to manage the load even
with Moby Dick, even in some situations that caused issues in the past
like undo.
2023-11-18 11:32:01 -08:00
Kartik K. Agaram ab5ba3f3e5 assume starty can be nil in update
This is a backport of a bugfix in pensieve.love. It's not _technically_
a bug here in lines.love, but it seems worth establishing an
architectural invariant (or rather lack of invariant).

LÖVE's standard event loop performs the following sequence of operations
in a single frame:
  * process events
  * update
  * draw

Ideally any mutations to global state happen during the first two
phases, while drawing includes no mutation.

However, there is a special case: `starty`, the top y coordinate for
each each line in the editor. This is used all over the place, and the
cheapest way to compute it is to simply save it while drawing.

However, draw by definition only updates `starty` for lines that are
drawn on screen. To avoid stale data on lines off screen, say after
scrolling, events often clear `starty` for all lines, leaving it to the
next draw phase to repopulate the right lines.

Sandwiched between the above two "however"s, the update phase needs to
gracefully handle `starty` being nil in the occasional frame right after
an event.

I think I've audited all our uses of `starty`, and this commit fixes the
only place that violates this rule.
2023-09-15 11:13:04 -07:00
Kartik K. Agaram 0e20565e17 clean up a slight jitter when drawing circles
Earlier the ghost while drawing wouldn't quite match the final shape.
Now the math is identical in draw_pending_shape.

It's a little unfortunate that we have this duplication of formulae.

At least there are no other stray calls of App.mouse_x in
draw_pending_shape.
2023-09-15 08:30:15 -07:00
Kartik K. Agaram 876d6298b4 App.width can no longer take a Text
In the process I discovered the horrible fact that Text.x allocates a new Text.
And it gets called (just once, thank goodness) on every single frame.
2023-04-01 18:12:29 -07:00
Kartik K. Agaram e0448d7d7f consistent names in a few more places 2022-12-23 19:32:58 -08:00
Kartik K. Agaram 2b3e09ca0f make love event names consistent
I want the words to be easy to read, and to use a consistent tense.
update and focus seem more timeless; let's make everything like those.
2022-12-23 18:52:28 -08:00
Kartik K. Agaram 1a6f533e2c dedup points while loading drawing from disk 2022-09-03 19:24:40 -07:00
Kartik K. Agaram cfdac28e18 distinguish consistently between mouse buttons and other buttons 2022-08-23 09:36:08 -07:00
Kartik K. Agaram 65879591ca bugfix: imprecision in drawing
scenario:
  slowly press down mouse button and drag to draw a line
  release mouse button

Before this commit the point would jump just a little bit on release,
and points would go slightly to the left of where I expect.

Yet another thing it's hard to write an automated test for.
2022-08-03 18:40:07 -07:00
Kartik K. Agaram f72185ab19 round one coordinate 2022-07-30 07:13:45 -07:00
Kartik K. Agaram 9d80e92415 round coordinates to integers in a few places
Thanks Lion Kimbro for pointing out this issue.

I still have to use floats for start/end angles of arcs. That might be a
sign that I don't have the right serialization yet for them. Or that
that feature needs to go.

I started out with a hazy idea of only using 8-bit ints for coordinates,
but now I'm not sure how committed I am to that constraint. While the
width is always 256 units, it might be nice to create long portrait
drawings at some point, whose height is greater than 256 units.
2022-07-29 21:54:06 -07:00
Kartik K. Agaram b7a67ab1e9 bugfix: online help
Broken in the commit before last.
2022-07-22 02:29:23 -07:00
Kartik K. Agaram 1937379da3 move drawing.starty into line cache 2022-07-20 17:08:00 -07:00
Kartik K. Agaram e4f9d50a55 a more radical attempt at ignoring nil y's 2022-07-13 09:31:54 -07:00
Kartik K. Agaram d231f4d37d no, bring back that defense
Scenario where I ran into it:
  start a stroke inside a drawing
  press 'o' to switch to circle mode (but any mode switch will do)

The problem is that Text.textinput unconditionally blows away all .y
values. Sometimes we have to wait for a draw() to fill them back in.
2022-07-13 09:21:19 -07:00
Kartik K. Agaram 22ad5373c5 a bug I've never run into
The previous commit was failing inside a test that I can't reproduce
manually. Perhaps it's something about how often draw/update run in
practice. Anyways, it's definitely uncovered a real issue.
2022-07-13 08:40:04 -07:00
Kartik K. Agaram 6659de60f3 hoist couple of variables out
This seems to uncover a corner case I'd never run into until now.
2022-07-13 08:24:16 -07:00
Kartik K. Agaram 3b1f2cf9de use available variables 2022-07-13 08:19:58 -07:00
Kartik K. Agaram 5017659bf4 more idiomatic variable names 2022-07-13 08:19:06 -07:00
Kartik K. Agaram 457136a986 chunking by simple local variable 2022-07-13 08:14:01 -07:00
Kartik K. Agaram 9f962b7cac make local functions look different 2022-07-13 08:04:06 -07:00
Kartik K. Agaram cfa04c3ca1 more chunks, same approach 2022-07-13 08:02:41 -07:00
Kartik K. Agaram 5a04d0c221 chunk up some long lines
Hopefully this is more approachable. Though now I'm creating two new
temporary functions on every draw. Whether I need them or not.
2022-07-13 07:50:50 -07:00
Kartik K. Agaram 9e9e8ed35c drop final mention of state global beyond main.lua
This is all unfortunate in several ways
- lots of functions have extra args
- table lookups where we used to have a simple variable
- program initialization is a lot more delicate

Let's see if it was worthwhile. Can we now actually build around the
editor component in forks?
2022-07-12 22:05:53 -07:00
Kartik K. Agaram 70a15b3bc9 replace globals with args in a few functions
- Drawing.draw_shape
  - Drawing.draw_pending_shape
  - Drawing.in_drawing
  - Drawing.find_or_insert_point
  - Drawing.near
  - Drawing.pixels
2022-07-12 21:58:46 -07:00
Kartik K. Agaram 307e875c1c correct a mis-named threshold 2022-07-12 21:41:09 -07:00
Kartik K. Agaram 3dd5413dbf drop heavyweight near check on file load/store 2022-07-12 21:29:30 -07:00
Kartik K. Agaram 3b36093553 left/right margin -> left/right coordinates
Editor state initialization now depends on window dimensions, so we have
to more carefully orchestrate startup.
2022-07-12 20:54:50 -07:00
Kartik K. Agaram 1ede1c3c6d add state arg to a few functions
- Drawing.current_drawing
  - Drawing.select_shape_at_mouse
  - Drawing.select_point_at_mouse
  - Drawing.select_drawing_at_mouse
2022-07-12 17:27:00 -07:00
Kartik K. Agaram 674d571576 add state arg to few functions
- draw_help_without_mouse_pressed
  - draw_help_with_mouse_pressed
  - current_shape
2022-07-12 17:05:21 -07:00
Kartik K. Agaram e990b1be92 add state arg to Drawing.update 2022-07-12 16:26:00 -07:00
Kartik K. Agaram 2307cb3ded add state arg to Drawing.draw 2022-07-12 16:25:29 -07:00
Kartik K. Agaram d6795f9df0 add state arg to Drawing.mouse_released 2022-07-12 16:21:56 -07:00
Kartik K. Agaram 780105cb13 add state arg to Drawing.keychord_pressed 2022-07-12 16:21:03 -07:00
Kartik K. Agaram d7ee9a75e4 add state arg to Drawing.mouse_pressed 2022-07-12 16:20:25 -07:00
Kartik K. Agaram 8bbc1ffe34 group all editor globals
We're still accessing them through a global. But we'll change that next.
2022-07-12 15:24:56 -07:00
Kartik K. Agaram 3850fbac35 make colors easier to edit 2022-07-11 23:18:26 -07:00
Kartik K. Agaram 3dccd7f81a stop pretending globals are local
One advantage of this approach: we don't end up with multiple lexical
scopes containing duplicates of the same modules.
2022-07-11 22:11:58 -07:00
Kartik K. Agaram 26a98d027b make freehand drawings smoother
Now I might actually use them more, and maybe I can start considering
taking out some shapes. Do I really need circles if I don't provide
ellipses?

Thanks Ivan Reese for the feedback. "What drawings does your tool
encourage?"

Minor note: taking out the deepcopy creates a cute little string like
effect, where the curve grows tighter the slower you draw it.
2022-07-05 11:38:08 -07:00
Kartik K. Agaram 3422d92a00 bugfix: 'escape' to cancel a stroke
This has been broken since commit b544e8c357 on May 17 :/
I'm just undoing that commit, which turns out to be completely
unnecessary. And adding a test.
2022-07-05 11:06:55 -07:00
Kartik K. Agaram 429a42eb1c right margin 2022-06-30 22:54:34 -07:00
Kartik K. Agaram 8c7bea8f76 rip out notion of Line_width 2022-06-30 19:50:27 -07:00
Kartik K. Agaram 515dad95f9 keep drawings within the line width slider as well 2022-06-22 21:08:17 -07:00
Kartik K. Agaram 97bbc7da7f clean up 2022-06-17 23:16:49 -07:00
Kartik K. Agaram 0248339898 more precise shape selection
It's important that the error be additive rather than multiplicative,
otherwise the area grows asymmetrically along a line.

Hopefully freehand drawings will work more intuitively now.
2022-06-17 23:15:09 -07:00
Kartik K. Agaram 26995dd62e correct commit f3abc2cbf2
I can't be trusted to do anything without a test.

This should fix #5. Please reopen if it doesn't.
2022-06-17 22:53:05 -07:00
Kartik K. Agaram f3abc2cbf2 better handle moving points
This should hopefully address #5. I'm removing some constraints from
manhattan lines, rectangles and squares.
2022-06-17 21:40:59 -07:00
Kartik K. Agaram bed0ddd2b7 dead code 2022-06-15 11:11:06 -07:00
Kartik K. Agaram b1ee70d62c move 2022-06-15 11:10:30 -07:00