Skip to content
The Chat Archive
gpt-4-0314· OpenAI WildChat-4.8M (AI2)

const Cup = () => { cupDrawer.drawFill( context, item, maxVolume, yPosition,…

  1. User

    const Cup = () => {

          cupDrawer.drawFill(
            context,
            item,
            maxVolume,
            yPosition,
            realCellHeight,
            canvasSize.width,
            dpiScale,
            darkMode
          );
    

    export default Cup;

    const cupDrawer = {

    drawFill: ( ctx: CanvasRenderingContext2D, cupItem: CupItem, maxVolume: number, yPosition: number, cellHeight: number, fullWidth: number, dpiScale: number, darkMode: boolean, ) => { ctx.beginPath(); ctx.strokeStyle = "#ffffff00"; ctx.lineWidth = cupOptions().border.width; ctx.fillStyle = cupItem.side === "Buy" ? cupOptions(darkMode).bestBuy.fillColor : cupOptions(darkMode).bestSell.fillColor; drawRoundedRect( ctx, 0, yPosition, cupTools.getCellWidth(fullWidth, cupItem.quantity, maxVolume, false), cellHeight, cupOptions().border.radius * dpiScale, ); ctx.fill(); ctx.stroke(); },

    };

    export default cupDrawer;

    const cupOptions = (darkMode?: boolean) => ({ sell: { backgroundColor: darkMode ? "#4A0B09" : "#F3C9CE", priceColor: darkMode ? "#fff" : "#B41C18", quantityColor: darkMode ? "#CA1612" : "#191919", }, bestSell: { backgroundColor: darkMode ? "#4A0B09" : "#d0706d", fillColor: darkMode ? "#CA1612" : "#a5120e", priceColor: "#FFFFFF", quantityColor: "#FFFFFF", }, buy: { backgroundColor: darkMode ? "#0f3b2b" : "#CAD7CD", priceColor: darkMode ? "#fff" : "#006943", quantityColor: darkMode ? "#00923A" : "#191919", }, bestBuy: { backgroundColor: darkMode ? "#006943" : "#4d967b", fillColor: darkMode ? "#00923A" : "#005737", priceColor: "#FFFFFF", quantityColor: "#FFFFFF", }, font: { family: "Mont", sizePx: 11, weight: 400, }, border: { width: 1, color: darkMode ? "#191919" : "#ffffff", radius: 6, }, cell: { paddingX: 4, defaultHeight: 16, }, });

    export const drawRoundedRect = ( ctx: CanvasRenderingContext2D, x: number, y: number, width: number, height: number, radius: number, ): void => { ctx.beginPath(); ctx.moveTo(x + radius, y + 1); ctx.lineTo(x + width - radius, y + 1); ctx.lineTo(x + width - radius, y + height - 1); ctx.lineTo(x + radius, y + height - 1); ctx.arcTo(x, y + height - 1, x, y + height - radius - 1, radius); ctx.lineTo(x, y + radius + 1); ctx.arcTo(x, y + 1, x + radius, y + 1, radius); ctx.closePath(); };

    export default cupOptions; нужно вместо drawRoundedRect отрисовать прямоугольник и потом скруглить углы цветом светлой/темной темы. думаю нужно путь только построить немного иначе и в два патча (beginPath / closePath)

  2. Assistant

    Для этого вы можете сначала нарисовать прямоугольник с закругленными углами, а затем изменить цвет линии и полупрозрачность контекста, чтобы нарисовать внешние и внутренние полукруги вокруг углов прямоугольника.

    Вот пример:

    const drawRoundedRectWithBorder = (
      ctx,
      x,
      y,
      width,
      height,
      radius,
      fillStyle,
      borderWidth,
      borderColor
    ) => {
      // Draw filling rect
      ctx.beginPath();
      ctx.moveTo(x + radius, y);
      ctx.lineTo(x + width - radius, y);
      ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
      ctx.lineTo(x + width, y + height - radius);
      ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
      ctx.lineTo(x + radius, y + height);
      ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
      ctx.lineTo(x, y + radius);
      ctx.quadraticCurveTo(x, y, x + radius, y);
      ctx.closePath();
      ctx.fillStyle = fillStyle;
      ctx.fill();
    
      // Draw border arcs
      ctx.beginPath();
      ctx.arc(x + radius, y + radius, radius, Math.PI, Math.PI * 1.5);
      ctx.arc(x + width - radius, y + radius, radius, Math.PI * 1.5, Math.PI * 2);
      ctx.arc(x + width - radius, y + height - radius, radius, 0, Math.PI * 0.5);
      ctx.arc(x + radius, y + height - radius, radius, Math.PI * 0.5, Math.PI);
      ctx.closePath();
      ctx.lineWidth = borderWidth;
      ctx.strokeStyle = borderColor;
      ctx.stroke();
    };
    
    const cupDrawer = {
      drawFill: (
        ctx,
        cupItem,
        maxVolume,
        yPosition,
        cellHeight,
        fullWidth,
        dpiScale,
        darkMode
      ) => {
        const fillColor =
          cupItem.side === "Buy"
            ? cupOptions(darkMode).bestBuy.fillColor
            : cupOptions(darkMode).bestSell.fillColor;
        const borderColor =
          darkMode ? "#191919" : "#ffffff";
        const borderWidth = cupOptions().border.width;
    
        drawRoundedRectWithBorder(
          ctx,
          0,
          yPosition,
          cupTools.getCellWidth(fullWidth, cupItem.quantity, maxVolume, false),
          cellHeight,
          cupOptions().border.radius * dpiScale,
          fillColor,
          borderWidth,
          borderColor
        );
      },
    };
    

    Этот код первоначально рисует заливку прямоугольника с закругленными углами, используя функцию drawRoundedRectWithBorder. Затем он изменяет цвет линии и полупрозрачность контекста, чтобы нарисовать внешние и внутренние полукруги вокруг углов прямоугольника. Таким образом, вы получаете нужный эффект закругления углов цветом светлой/темной темы.