MCPcopy
hub / github.com/1j01/jspaint / $ToolBox

Function $ToolBox

src/$ToolBox.js:17–123  ·  view source on GitHub ↗

* @param {Tool[]} tools * @param {boolean=} is_extras * @returns {JQuery & I$ToolBox & I$Component}

(tools, is_extras)

Source from the content-addressed store, hash-verified

15 * @returns {JQuery<HTMLDivElement> & I$ToolBox & I$Component}
16 */
17function $ToolBox(tools, is_extras) {
18 const $tools = $(E("div")).addClass("tools");
19 const $tool_options = $(E("div")).addClass("tool-options");
20
21 let showing_tooltips = false;
22 $tools.on("pointerleave", () => {
23 showing_tooltips = false;
24 $status_text.default();
25 });
26
27 const $buttons = $($.map(tools, (tool, i) => {
28 const $b = $(E("div")).addClass("tool");
29 $b.appendTo($tools);
30 tool.$button = $b;
31
32 $b.attr("title", tool.name);
33
34 const $icon = $(E("span")).addClass("tool-icon");
35 $icon.appendTo($b);
36 const update_css = () => {
37 const use_svg = !theme_dev_blob_url && (
38 (
39 get_theme() === "modern.css" || get_theme() === "modern-dark.css" ?
40 // only use raster when screen pixels line up with image pixels exactly
41 (window.devicePixelRatio !== 1) :
42 // with nearest neighbor scaling, favor raster at larger integer sizes as well, for retro look
43 (window.devicePixelRatio >= 3 || (window.devicePixelRatio % 1) !== 0)
44 ) ||
45 $("body").hasClass("enlarge-ui")
46 );
47 $icon.css({
48 display: "block",
49 position: "absolute",
50 left: 4,
51 top: 4,
52 width: 16,
53 height: 16,
54 backgroundImage: theme_dev_blob_url ? `url(${theme_dev_blob_url})` : "",
55 "--icon-index": i.toString(),
56 });
57 $icon.toggleClass("use-svg", use_svg);
58 };
59 update_css();
60 $G.on("theme-load resize", update_css);
61
62 $b.on("click", (e) => {
63 if (e.shiftKey || e.ctrlKey) {
64 select_tool(tool, true);
65 return;
66 }
67 if (selected_tool === tool && tool.deselect) {
68 select_tools(return_to_tools);
69 } else {
70 select_tool(tool);
71 }
72 });
73
74 $b.on("pointerenter", () => {

Callers 1

app.jsFile · 0.90

Calls 15

EFunction · 0.90
select_toolFunction · 0.90
select_toolsFunction · 0.90
$ComponentFunction · 0.90
make_css_cursorFunction · 0.90
update_cssFunction · 0.85
show_tooltipFunction · 0.85
localizeFunction · 0.85
onMethod · 0.80
defaultMethod · 0.80
addMethod · 0.80
update_selected_toolMethod · 0.80

Tested by

no test coverage detected