Commit Graph

100 Commits

Author SHA1 Message Date
Kartik K. Agaram 0075298a29 new fork: show raw text for drawing below it
https://merveilles.town/@maleza/109398870908062135

Lots of issues:
* can't edit the raw text
* ..but it confusingly displays a second cursor
* raw text doesn't update when drawing (need to constantly deserialize
  the drawing to JSON)
* ... lots of others

This is an early experiment.
2022-11-24 09:21:58 -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
Kartik K. Agaram 9644b066bd . 2022-06-15 09:59:18 -07:00
Kartik K. Agaram d77bcd8f8c stop recording points for arcs
It was kinda weird that we were recording the start but not the end.
And moving the start point didn't actually affect the arc.
Let's see if we actually ever need it.
2022-06-15 09:57:49 -07:00
Kartik K. Agaram 4280b19cac move current mode indicator slightly 2022-06-15 09:03:31 -07:00
Kartik K. Agaram a40d2c424e standardize on ordering of cases 2022-06-15 08:53:34 -07:00
Kartik K. Agaram 93a9dfd364 test: moving a point
I found some code in the process that seems unreachable. Some chance of
a regression here..
2022-06-14 21:08:07 -07:00
Kartik K. Agaram 2b4e14189b tests for drawing polygons 2022-06-14 14:59:09 -07:00