Make creature strokes non-scaling. (#6)
This attempts to manually scale the strokes on creatures so they aren't affected by scale. The weird thing here is that applying `vector-effect="non-scaling-stroke"` does not appear to do the trick--rather, it makes all the strokes look _super heavy_. So in this PR we scale the stroke by the inverse of whatever we're cumulatively scaling by when we're drawing something.pull/7/head
rodzic
2b27ae02a4
commit
d663915f0e
|
@ -47,6 +47,7 @@ type AttachmentChildren = JSX.Element | JSX.Element[];
|
||||||
|
|
||||||
type CreatureContextType = SvgSymbolContext & {
|
type CreatureContextType = SvgSymbolContext & {
|
||||||
attachmentScale: number;
|
attachmentScale: number;
|
||||||
|
cumulativeScale: number;
|
||||||
parent: SvgSymbolData | null;
|
parent: SvgSymbolData | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -55,6 +56,7 @@ const DEFAULT_ATTACHMENT_SCALE = 0.5;
|
||||||
const CreatureContext = React.createContext<CreatureContextType>({
|
const CreatureContext = React.createContext<CreatureContextType>({
|
||||||
...createSvgSymbolContext(),
|
...createSvgSymbolContext(),
|
||||||
attachmentScale: DEFAULT_ATTACHMENT_SCALE,
|
attachmentScale: DEFAULT_ATTACHMENT_SCALE,
|
||||||
|
cumulativeScale: 1,
|
||||||
parent: null,
|
parent: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -71,7 +73,14 @@ const CreatureSymbol: React.FC<CreatureSymbolProps> = (props) => {
|
||||||
const ourSymbol = (
|
const ourSymbol = (
|
||||||
<>
|
<>
|
||||||
{props.children && (
|
{props.children && (
|
||||||
<CreatureContext.Provider value={{ ...ctx, parent: data }}>
|
<CreatureContext.Provider
|
||||||
|
value={{
|
||||||
|
...ctx,
|
||||||
|
parent: data,
|
||||||
|
cumulativeScale: ctx.attachmentScale * ctx.cumulativeScale,
|
||||||
|
strokeScale: 1 / ctx.cumulativeScale,
|
||||||
|
}}
|
||||||
|
>
|
||||||
{props.children}
|
{props.children}
|
||||||
</CreatureContext.Provider>
|
</CreatureContext.Provider>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { SVGProps } from "react";
|
||||||
import { BBox } from "../vendor/bezier-js";
|
import { BBox } from "../vendor/bezier-js";
|
||||||
import { FILL_REPLACEMENT_COLOR, STROKE_REPLACEMENT_COLOR } from "./colors";
|
import { FILL_REPLACEMENT_COLOR, STROKE_REPLACEMENT_COLOR } from "./colors";
|
||||||
import { Specs } from "./specs";
|
import { Specs } from "./specs";
|
||||||
|
import { float } from "./util";
|
||||||
import { VisibleSpecs } from "./visible-specs";
|
import { VisibleSpecs } from "./visible-specs";
|
||||||
|
|
||||||
export type SvgSymbolData = {
|
export type SvgSymbolData = {
|
||||||
|
@ -28,12 +29,14 @@ export type SvgSymbolElement = (
|
||||||
export type SvgSymbolContext = {
|
export type SvgSymbolContext = {
|
||||||
stroke: string;
|
stroke: string;
|
||||||
fill: string;
|
fill: string;
|
||||||
|
strokeScale: number;
|
||||||
showSpecs: boolean;
|
showSpecs: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFAULT_CONTEXT: SvgSymbolContext = {
|
const DEFAULT_CONTEXT: SvgSymbolContext = {
|
||||||
stroke: "#000000",
|
stroke: "#000000",
|
||||||
fill: "#ffffff",
|
fill: "#ffffff",
|
||||||
|
strokeScale: 1,
|
||||||
showSpecs: false,
|
showSpecs: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -64,14 +67,18 @@ function reactifySvgSymbolElement(
|
||||||
el: SvgSymbolElement,
|
el: SvgSymbolElement,
|
||||||
key: number
|
key: number
|
||||||
): JSX.Element {
|
): JSX.Element {
|
||||||
let { fill, stroke } = el.props;
|
let { fill, stroke, strokeWidth } = el.props;
|
||||||
fill = getColor(ctx, fill);
|
fill = getColor(ctx, fill);
|
||||||
stroke = getColor(ctx, stroke);
|
stroke = getColor(ctx, stroke);
|
||||||
|
if (strokeWidth !== undefined) {
|
||||||
|
strokeWidth = float(strokeWidth) * ctx.strokeScale;
|
||||||
|
}
|
||||||
return React.createElement(
|
return React.createElement(
|
||||||
el.tagName,
|
el.tagName,
|
||||||
{
|
{
|
||||||
...el.props,
|
...el.props,
|
||||||
id: undefined,
|
id: undefined,
|
||||||
|
strokeWidth,
|
||||||
fill,
|
fill,
|
||||||
stroke,
|
stroke,
|
||||||
key,
|
key,
|
||||||
|
|
Ładowanie…
Reference in New Issue