lionleaf / lionleaf/dwitter

Helper addition: M (mouse coordinate translation)

Open
#141 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
803
Forks
68
PR merge metrics
No merged PRs in 30d

Description

I wanted to see if I could add an interactive element to a dweet, so I decided to attach a mousemove listener to take the mouse coordinate into account. Now, paying for the cost of adding an event listener and whatnot is fair game, but I didn't anticipate how expensive it'd be just to get something canvas-usable out of the mouse event. In the end I dweeted [this little paint demo][1].

[1]: https://www.dwitter.net/d/1577

The annoying boilerplate-y part is the computation of the mouse (x,y) coordinate in relation to canvas coordinates, especially when taking different resolutions (non-fullscreen, fullscreen at different resolutions) into account. It seems reasonable to suggest a helper function to help deal with different resolutions, since that part seems to be meant to be transparent to the dweet (i.e., the canvas is always 1920×1080).

So, I suggest a helper function `M`:

M = (e) => [ e.offsetX/c.offsetWidth *1920,
e.offsetY/c.offsetHeight*1080 ]

The dweeter could then get the mouse coordinates in canvas coordinates via a simple `[X,Y]=M(e)`.

Thoughts? I do realise new helpers should have quite a lot of friction to being added, or we'll just end up abbreviating everything…

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the proposed M helper and the linked paint demo to understand the expected mouse-coordinate behavior across canvas sizes. Then inspect how helpers are exposed to dweets and determine whether the helper should be accepted; done means the project has an agreed implementation and coverage for the translated coordinates.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.