drawSelectView method

void drawSelectView(
  1. Canvas canvas,
  2. int index,
  3. bool isLeft
)

Implementation

void drawSelectView(Canvas canvas, int index, bool isLeft) {
  DepthEntity entity = isLeft ? mBuyData![index] : mSellData![index];
  double dx = isLeft ? getBuyX(index) : getSellX(index);

  double radius = 8.0;
  if (dx < mDrawWidth) {
    canvas.drawCircle(Offset(dx, getY(entity.vol)), radius / 3,
        mBuyLinePaint!..style = PaintingStyle.fill);
    canvas.drawCircle(Offset(dx, getY(entity.vol)), radius,
        mBuyLinePaint!..style = PaintingStyle.stroke);
  } else {
    canvas.drawCircle(Offset(dx, getY(entity.vol)), radius / 3,
        mSellLinePaint!..style = PaintingStyle.fill);
    canvas.drawCircle(Offset(dx, getY(entity.vol)), radius,
        mSellLinePaint!..style = PaintingStyle.stroke);
  }

  //画底部
  TextPainter priceTP =
      getTextPainter(entity.price.toStringAsFixed(fixedLength!));
  priceTP.layout();
  double left;
  if (dx <= priceTP.width / 2) {
    left = 0;
  } else if (dx >= mWidth - priceTP.width / 2) {
    left = mWidth - priceTP.width;
  } else {
    left = dx - priceTP.width / 2;
  }
  Rect bottomRect = Rect.fromLTRB(left - 3, mDrawHeight + 3,
      left + priceTP.width + 3, mDrawHeight + mPaddingBottom);
  canvas.drawRect(bottomRect, selectPaint!);
  canvas.drawRect(bottomRect, selectBorderPaint!);
  priceTP.paint(
      canvas,
      Offset(bottomRect.left + (bottomRect.width - priceTP.width) / 2,
          bottomRect.top + (bottomRect.height - priceTP.height) / 2));
  //画左边
  TextPainter amountTP =
      getTextPainter(entity.vol.toStringAsFixed(fixedLength!));
  amountTP.layout();
  double y = getY(entity.vol);
  double rightRectTop;
  if (y <= amountTP.height / 2) {
    rightRectTop = 0;
  } else if (y >= mDrawHeight - amountTP.height / 2) {
    rightRectTop = mDrawHeight - amountTP.height;
  } else {
    rightRectTop = y - amountTP.height / 2;
  }
  Rect rightRect = Rect.fromLTRB(mWidth - amountTP.width - 6,
      rightRectTop - 3, mWidth, rightRectTop + amountTP.height + 3);
  canvas.drawRect(rightRect, selectPaint!);
  canvas.drawRect(rightRect, selectBorderPaint!);
  amountTP.paint(
      canvas,
      Offset(rightRect.left + (rightRect.width - amountTP.width) / 2,
          rightRect.top + (rightRect.height - amountTP.height) / 2));
}