1701 Commits

Author SHA1 Message Date
d3ef8e65dc js: Simplify drawing context management
There's not much point in re-requesting the drawing context from the
offscreen canvas at the start of each drawing operation.  The canvas
keeps the context around and returns it on every call to getContext(),
so we may as well just keep our reference to it too.  This does mean
that the front-end won't detect puzzles drawing outside of a redraw
operation, but I think it's the mid-end's job to assert things like
that.

Rumours that I'm doing this because I had a mysterious bug whereby ctx
was unexpectedly null are entirely true.
2022-12-03 15:46:58 +00:00
f0d4705364 js: Switch to using the resize handle in the HTML 2022-12-02 23:49:00 +00:00
2522dd249b js: Don't bother resizing offscreen canvas at startup
It will get its size set soon enough once we know the size of the
puzzle anyway.
2022-12-02 23:49:00 +00:00
85dabc1eb9 js: Improve comment explaining same-origin policy for file:
Also a way around it, at least in Firefox.
2022-12-02 23:49:00 +00:00
acd1f45152 js: Add an SVG resize handle to the HTML
This is more compact than carefully drawing it on a canvas in
JavaScript.  More importantly, the SVG resize handle scales nicely as
the page is zoomed, or on high-DPI screens.

At the moment, the nice SVG resize handle is removed by JavaScript,
but we need to wait a little while for everyone to get the new HTML
cached before changing that.
2022-12-02 23:43:51 +00:00
66a927920a js: Remove a JavaScript construct that confused emcc -O3 2022-12-02 02:10:19 +00:00
2b5a4a062c Document how Enter and Space are handled in the mid-end
They've been canonicalised to CURSOR_SELECT and CURSOR_SELECT2 since
2008.
2022-11-30 13:11:13 +00:00
dbb2d2adb2 js: Allow for putting a resize handle in HTML 2022-11-29 23:34:43 +00:00
1611a5e058 Developer doc correction: list.c is not generated by Perl any more 2022-11-29 21:13:52 +00:00
b967a3ea86 js: Remove support for creating the status bar in JavaScript
Now we depend on its being in the HTML.
2022-11-28 22:51:15 +00:00
e8cdac58e5 js: Don't word-wrap the status bar
With word-wrapping disabled, long status-bar texts fall off the
right-hand end rather than wrapping onto an invisible second line.
This is less confusing because it makes the overflow more obvious.
I've also turned on "text-overflow: ellipsis" for extra obviousness.
Finally, this also the need to explicitly set the height of the status
bar, not that that was doing any harm.
2022-11-28 22:49:30 +00:00
4be221ba49 Update current-as-of commit ID in developer docs
I think I've made all the updates necessary already.
2022-11-27 19:52:47 +00:00
c6e312b252 js: Remove "width" and "height" attributes from HTML <canvas>
They were set to "1px", which isn't a valid value since they're meant to
be integers.  Since they weren't valid, they were ignored.  This doesn't
seem to have caused any trouble, so they may as well be removed.  In any
case, the canvas is invisible until after its size has been set by
JavaScript.
2022-11-27 19:39:18 +00:00
19540d2ef8 js: Hide menus and resize handle when printing 2022-11-26 08:55:36 +00:00
115edab459 js: Remove alpha channel from almost all our canvases
Specifying the { alpha: false } option when creating a rendering context
tells the browser that we won't use transparency, and the standard
puzzle canvases, along with blitters, are all opaque.  No obvious
effect, but the MDN suggests that this should reduce CPU usage.

The one exception here is the resize handle, which actually is
transparent.
2022-11-25 19:13:43 +00:00
a6a799720f js: Correct co-ordinate-mapping function for what CSS actually does
By default, CSS uses "object-fit: fill", which means that an object is
independently scaled in both dimensions to fit its containing box.
This is simpler than what I'd assumed (which was "object-fill:
contain").  Obviously, the HTML could be changed to use a different
object-fit, in which case this code would have to detect it, but for
now following the CSS default is more correct than not.
2022-11-25 18:42:44 +00:00
d90c0a9edb flip: Set a lower bound on the size of little diagrams
This ensures that they don't vanish entirely and small tile sizes.
2022-11-25 18:04:39 +00:00
0b36c01639 mines: Ensure highlights don't vanish at small tile sizes
The highlights for covered squares now have a minimum width of 1 pixel,
which means that Mines is comfortably playabale down to about 8 pixel
tilesize, below which the numbers become unreadable.
2022-11-25 13:29:04 +00:00
5a2ea91cad js: Subtle extra padding for menus
Each menu item has a -0.5px margin so that the borders of adjacent menu
items overlap, but we don't actually want the menu items to protrude
beyond the containing <ul>.  Adding 0.5px of padding to the <ul>
achieves that.
2022-11-24 23:28:28 +00:00
38e17ebab2 js: If the HTML contains a dialogue-box form, delete it
This is so that (given time for caches to expire) I can switch to having
a persistent dialogue box in HTML rather than fabricating it from
scratch in JavaScript each time it's used.
2022-11-24 21:03:31 +00:00
36c9062cbd js: Disable menu keyboard controls when dialogue box is active
I think this is broadly the wrong approach, but it's an improvement
until I implement the right one.
2022-11-24 18:26:59 +00:00
271fb7f47c js: More conventional marking of menu item types
Menu items that open dialogue boxes are now marked with ellipses, while
menu items that lead to submenus have pointing triangles.

The triangles are implemented as SVG files embedded in data: URLs in the
CSS, which is kind of silly but also works really well.  There are
suitable characters in Unicode, but some of my test systems don't have
fonts containing them, so maybe the SVG is better.
2022-11-24 16:24:59 +00:00
fe29d1cbf5 js: Replace status-bar holder in HTML with status bar itself
This makes the HTML simpler, and will allow for simplifying the JS too.
2022-11-23 23:19:28 +00:00
b5ccb0c9af js: Add actions for more keys in menus
I expect Escape to exit the menu, and SoftRight should do that as well
for KaiOS.  Backspace goes up one level through the menus, again because
that's conventional on KaiOS and not too confusing elsewhere.
2022-11-23 22:27:54 +00:00
e79270368b js: Move global keyboard handler to capturing phase
In the bubbling phase it managed to catch the "Enter" keypress that
opened a dialogue box from the menu and use it to close the dialogue
box again.  I think it's probably reasonable to have it run earlier and
just permanently steal any keypresses it wants.
2022-11-23 21:56:42 +00:00
2d439dd00e js: Move focus-tracking to entirely "focus" events
When we disable a button, it loses focus but doesn't generate a "blur"
event.  This means our "focus-within" class goes wrong.  Instead of
relying on "blur" events to remove the class, remove it from any
inappropriate elements in the "focus" handler.  This requires attaching
the handler to the root element of the document, but I've got plans that
need that anyway.
2022-11-23 21:56:42 +00:00
8445f07827 js: Replace :focus-within with JS-maintained .focus-within
Old browsers (like KaiOS 2.5) don't have :focus-within, but it's pretty
easy to replace the pseudo-class with a real .focus-within class
maintained by JavaScript event handlers.  This is made only marginally
fiddlier by the odd fact that "focus" and "blur" events don't bubble.
2022-11-23 21:56:42 +00:00
52cd58043a js: Add keyboard navigation for menus
Once the input focus is in the menu system (for instance by Shift+Tab
from the puzzle), you can move left and right through the menu bar and
up and down within each menu.  Enter selects a menu item.  The current
menu item is tracked by giving it the input focus.
2022-11-23 21:53:59 +00:00
b1b2da9896 Mid-move icon for Cube 2022-11-23 21:28:10 +00:00
96cda05b89 Add missing dependency of screenshots on their save files 2022-11-23 14:34:37 +00:00
fffeae956a nullgame: Don't bother blanking the puzzle window
This is now centralised in the mid-end.
2022-11-22 13:54:30 +00:00
8f46f437a7 gtk: Fix a missing "const" qualifier when building with GTK 2 2022-11-22 13:54:30 +00:00
25803916cb Fix mid-move icons
They've been broken since the move to CMake, which had an incorrect
variable substitution in the --redo argument.
2022-11-22 00:57:55 +00:00
434e6a43cf js: When removing the status bar, null out its variable
It seems polite to allow it to be garbage-collected.
2022-11-21 14:59:19 +00:00
f7557852b5 js: Tiny comment fix 2022-11-21 14:55:17 +00:00
77c8b50834 js: Allow status bar to be present in the HTML
I'm generally in favour of putting HTML in HTML rather the constructing
it in JavaScript, and this will allow for simplifying the code
eventually.  This only changes the JavaScript to make sure that's in
people's caches before I change the HTML itself.
2022-11-20 19:10:23 +00:00
f86623bbd9 Palisade: scale line thickness unboundedly with tile size.
The previous expression for WIDTH defined it, curiously, as (1 +
(TILESIZE >= 16) + (TILESIZE >= 32) + (TILESIZE >= 64)) which is
roughly logarithmic in tile size, but bounded above by a maximum of 4
pixels. On high-DPI displays this isn't really good enough any more.
Now I've set the line thickness to a constant fraction of the tile
size (but still bounded below by 1), so it's much easier to see the
lines when the puzzle is expanded to extra large size.
2022-11-18 22:22:52 +00:00
10bd3aeb2a pearl: Return NULL when Backspace or Escape does nothing
When there's no drag in progress, cancelling the drag has no effect.
Returning NULL lets the front-end know this, which in particular means
the Backspace key can leave the app in KaiOS.
2022-11-18 14:40:56 +00:00
51b496e118 mines: Grammar fix in instructions 2022-11-18 00:11:39 +00:00
7e19d6f4b1 Document new new undo/redo keys 2022-11-16 09:27:40 +00:00
5157a18550 Extra key mappings: '*' to undo and '#' to redo
This is what I keep expecting on my phone.  Implemented in the mid-end
since no backend currently uses those keys.
2022-11-15 23:48:32 +00:00
1b3a6bd204 js: Create the puzzle resize handle only if the puzzle is resizable
If there's no resizable div to attach it to, there's not much point in
creating the handle and the doing nothing with it.
2022-11-15 23:01:36 +00:00
298615408b js: Insert a space in game-type submenu headings as well 2022-11-15 23:01:36 +00:00
ff406d4edc js: Convert space after tick in menus to a space character
Older Firefox versions don't support "-moz-appearance: none" on radio
buttons, which seems to mean that the specifies padding for them
doesn't appear.  Using a space character instead works fine, so do that
everywhere.  This seems to move the text slightly closer to the tick on
browsers that do support "appearance: none", but the result is quite
acceptable.

This also makes the focus outline on the ticks slightly less weird.
2022-11-15 01:31:01 +00:00
a55c0c188b js: Use -moz-appearance and -webkit-appearance
The "appearance" property is newer than WebAssembly, but major browsers
have much older namespaced versions that we can support as well.
2022-11-15 01:06:35 +00:00
a90bb4a4ef js: Better handling of games without presets and/or solve
Games with neither presets nor configuration (which may only be the Null
Game) have been slightly broken since the introduction of hierarchical
preset menus, in that the code to remove the "Type..." menu stopped
being called then.  My switch to using radio buttons in menus then broke
them utterly because it's not possible to set the value of an empty
radio group, causing a crash at startup.

Fix this by detected when there's no preset menu, removing the item from
the menu bar, and setting the variable that's meant to indicate this has
been done.

The solve button problem was more subtle, in that only the <button> was
being hidden and not the <li> containing it, which led to the right border of the menu bar being two pixels thick.  Switch to fully removing
the <li> from the DOM, like we now do with the presets menu, since that
also makes my keyboard handler (in another branch) simpler.
2022-11-13 14:05:55 +00:00
5a225bf585 js: Substantially simplify timer code
The C code in the Emscripten front-end already keeps a timer_active
variable to ensure that the timer can be activated only when it's
inactive, and deactivated only when it's active.  Adjusting the
JavaScript side to rely on this makes the code much simpler.  The only
oddity is that it now requests a new animation frame before calling the
callback so that it's ready to be cancelled if the callback decides to
deactivate the timer.
2022-11-13 00:15:00 +00:00
5a90dd9312 js: Give keyboard focus to the puzzle canvas at startup again
I think this has been broken since a752e73, when the canvas changed to
being hidden, and hence unable to receive keyboard focus, when the page
loaded.  I've now moved the focus() call to after the canvas gets
displayed.
2022-11-12 17:21:03 +00:00
8ef28a4fd6 js: Remove class="text/css" from <style> element
This is the wrong attribute, and the correct type="text/css" is
deprecated by MDN.  Since it's never worked, the deprecated attribute
presumably isn't needed either.
2022-11-12 15:32:18 +00:00
208e2508d3 js: Add a way to have environment variables
They can now be specified by sticking some JSON in a <script> element in
the Web page:

<script id="environment" type="application/json">
   { "LOOPY_DEFAULT": "20x10t11dh" }
</script>

This isn't brilliantly useful, but it does allow for changing settings
without recompiling.
2022-11-12 15:03:40 +00:00