示例#1
0
  @Override
  public void Draw(Canvas canvas, Paint paint) {

    Typeface tf = paint.getTypeface();
    paint.setUnderlineText(underline);
    paint.setTypeface(Typeface.create(tf, style));
    paint.setTextSize(size);
    paint.setStyle(Paint.Style.FILL);

    if (v.currBrushColor != -1) { // draw background rect
      int clr = paint.getColor();
      paint.setColor(v.currBrushColor + v.Opaque);
      canvas.drawRect(
          x - 1,
          y,
          x + paint.measureText(text) + 1,
          y - paint.ascent() + paint.descent() / 2,
          paint);
      paint.setColor(clr);
    }

    canvas.drawText(text, x, y - paint.ascent(), paint);

    paint.setStyle(Paint.Style.STROKE);
    paint.setUnderlineText(false);
    paint.setTypeface(tf);
  }
  @Override
  public void draw(Canvas canvas) {
    Rect bounds = getBounds();
    int cellSize = Math.min(bounds.height(), bounds.width());
    float x0 = bounds.left;
    float y0 = bounds.top;
    float x1 = bounds.right;
    float y1 = bounds.bottom;
    float xM = bounds.centerX();
    float yM = bounds.centerY();
    float border = cellSize / 8;
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(border / 2);

    switch (kind) {
      case BRANCH_ALL:
      case BRANCH_LEFT:
      case BRANCH_LEFT_AND_RIGTH:
      case BRANCH_RIGHT:
        if (kind == Kind.BRANCH_ALL
            || kind == Kind.BRANCH_LEFT
            || kind == Kind.BRANCH_LEFT_AND_RIGTH) {
          canvas.drawLine(xM, y0 + border, x0 + border, yM, paint);
        }
        if (kind == Kind.BRANCH_ALL || kind == Kind.BRANCH_LEFT || kind == Kind.BRANCH_RIGHT) {
          canvas.drawLine(xM, y0 + border, xM, y1 - border, paint);
        }
        if (kind == Kind.BRANCH_ALL
            || kind == Kind.BRANCH_RIGHT
            || kind == Kind.BRANCH_LEFT_AND_RIGTH) {
          canvas.drawLine(xM, y0 + border, x1 - border, yM, paint);
        }
        break;

      case CLASSIFIER:
        {
          int color = paint.getColor();
          paint.setColor(Colors.GRAY[1]);
          paint.setStyle(Paint.Style.FILL);
          canvas.drawCircle(bounds.centerX(), bounds.centerY(), cellSize / 2, paint);

          paint.setColor(color);
          paint.setStyle(Paint.Style.STROKE);
          canvas.drawCircle(bounds.centerX(), bounds.centerY(), cellSize / 2, paint);
          break;
        }
      case MODULE:
        rect.set(bounds);
        rect.bottom = x0 + 1.5f * border;
        rect.right = bounds.centerX();
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        canvas.drawRoundRect(rect, border / 2, border / 2, paint);
        rect.top = rect.centerY();
        canvas.drawRect(rect, paint);
        rect.set(bounds);
        rect.top += 1.5 * border;
        rect.bottom -= 1 * border;
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawRoundRect(rect, border, border, paint);
        break;
      case CONTINUOUS_OPERATION:
        paint.setUnderlineText(true);
        // Fallthrough intended
      case OPERATION:
        rect.set(bounds);
        rect.top += border;
        rect.bottom -= border;
        canvas.drawRoundRect(rect, border, border, paint);
        // canvas.drawRect(rect, paint);
        break;
      case PROPERTY:
        path.rewind();
        path.moveTo(x0 + border, y0 + border);
        path.lineTo(x1, y0 + border);
        path.lineTo(x1 - border, y1 - border);
        path.lineTo(x0, y1 - border);
        path.close();
        canvas.drawPath(path, paint);
        break;
      case SOUND:
        path.rewind();
        path.moveTo(x1 - border, y0 + border);
        path.lineTo(x1 - border, y1 - border);
        path.lineTo(xM, yM + 1.5f * border);
        path.lineTo(xM, yM - 1.5f * border);
        path.close();
        canvas.drawPath(path, paint);
        rect.left = x0 + border;
        rect.right = xM - 1.5f * border;
        rect.top = yM - 1.5f * border;
        rect.bottom = yM + 1.5f * border;
        canvas.drawRect(rect, paint);
        return;

      case TUTORIAL:
        path.rewind();
        path.moveTo(x1 - 2 * border, y0 + 4 * border);
        path.lineTo(x1 - 2 * border, y1 - 2 * border);
        path.lineTo(xM, y1 - border);
        path.lineTo(x0 + 2 * border, y1 - 2 * border);
        path.lineTo(x0 + 2 * border, y0 + 4 * border);
        canvas.drawPath(path, paint);

        path.rewind();
        path.moveTo(xM, y0 + border);
        path.lineTo(x1, y0 + 3 * border);
        path.lineTo(xM, y0 + 5 * border);
        path.lineTo(x0, y0 + 3 * border);
        path.close();
        canvas.drawPath(path, paint);
        canvas.drawLine(x1, y0 + 3 * border, x1, yM + (text == null ? 2 : 1) * border, paint);
        break;
    }

    if (text != null) {
      paint.setStyle(Paint.Style.FILL);
      if (kind == Kind.TUTORIAL) {
        paint.setTextSize(cellSize * 0.33f);
        paint.setTextAlign(Paint.Align.RIGHT);
        TextHelper.drawText(
            context,
            canvas,
            text,
            bounds.right,
            bounds.bottom,
            paint,
            TextHelper.VerticalAlign.BOTTOM);
      } else {
        paint.setTextSize(cellSize * (kind == Kind.CLASSIFIER ? 0.66f : 0.5f));
        //      canvas.drawText(text, bounds.centerX(), bounds.bottom - cellSize * (kind ==
        // Kind.CLASSIFIER ? 0.25f : 0.33f), paint);
        TextHelper.drawText(
            context,
            canvas,
            text,
            bounds.centerX(),
            bounds.centerY(),
            paint,
            TextHelper.VerticalAlign.CENTER);
      }
    } /*else {
            paint.setStyle(Paint.Style.FILL);
            rect.set(bounds);
            rect.inset(border, border);
            rect.top += border;
            paint.setColor(Colors.GRAY[0]);
            canvas.drawRect(rect, paint);
            paint.setColor(Colors.GRAY[3]);
            paint.setStrokeWidth(cellSize / 16);
            paint.setStyle(Paint.Style.STROKE);
            canvas.drawRect(rect, paint);

            path.rewind();
            path.moveTo(x0 + border, y0 + 2 * border);
            path.lineTo(x0 + 2 * border, y0 + border);
            path.lineTo(x1 - 2 * border, y0 + border);
            path.lineTo(x1 - border, y0 + 2 * border);

      //      path.lineTo(x1 - border, y1 - 2 * border);
        //    path.lineTo(xM, y1);
          //  path.lineTo(x0 + border, y1 - 2 * border);
      //      path.close();
            //paint.setColor(Color.BLACK);
            canvas.drawPath(path, paint);
      //      canvas.drawPath(path, paint);
      //      canvas.drawLine(x0 + border, y0 + 2 * border, xM, y0 + 4 * border, paint);
        //    canvas.drawLine(x1 - border, y0 + 2 * border, xM, y0 + 4 * border, paint);
          //  canvas.drawLine(xM, y1, xM, y0 + 4* border, paint);
          }
      */
  }
  public void onDraw() {
    int fg, bg;
    synchronized (buffer) {
      boolean entireDirty = buffer.update[0] || fullRedraw;
      boolean isWideCharacter = false;

      // walk through all lines in the buffer
      for (int l = 0; l < buffer.height; l++) {

        // check if this line is dirty and needs to be repainted
        // also check for entire-buffer dirty flags
        if (!entireDirty && !buffer.update[l + 1]) continue;

        // reset dirty flag for this line
        buffer.update[l + 1] = false;

        // walk through all characters in this line
        for (int c = 0; c < buffer.width; c++) {
          int addr = 0;
          int currAttr = buffer.charAttributes[buffer.windowBase + l][c];

          {
            int fgcolor = defaultFg;

            // check if foreground color attribute is set
            if ((currAttr & VDUBuffer.COLOR_FG) != 0)
              fgcolor = ((currAttr & VDUBuffer.COLOR_FG) >> VDUBuffer.COLOR_FG_SHIFT) - 1;

            if (fgcolor < 8 && (currAttr & VDUBuffer.BOLD) != 0) fg = color[fgcolor + 8];
            else fg = color[fgcolor];
          }

          // check if background color attribute is set
          if ((currAttr & VDUBuffer.COLOR_BG) != 0)
            bg = color[((currAttr & VDUBuffer.COLOR_BG) >> VDUBuffer.COLOR_BG_SHIFT) - 1];
          else bg = color[defaultBg];

          // support character inversion by swapping background and foreground color
          if ((currAttr & VDUBuffer.INVERT) != 0) {
            int swapc = bg;
            bg = fg;
            fg = swapc;
          }

          // set underlined attributes if requested
          defaultPaint.setUnderlineText((currAttr & VDUBuffer.UNDERLINE) != 0);

          isWideCharacter = (currAttr & VDUBuffer.FULLWIDTH) != 0;

          if (isWideCharacter) addr++;
          else {
            // determine the amount of continuous characters with the same settings and print them
            // all at once
            while (c + addr < buffer.width
                && buffer.charAttributes[buffer.windowBase + l][c + addr] == currAttr) {
              addr++;
            }
          }

          // Save the current clip region
          canvas.save(Canvas.CLIP_SAVE_FLAG);

          // clear this dirty area with background color
          defaultPaint.setColor(bg);
          if (isWideCharacter) {
            canvas.clipRect(
                c * charWidth, l * charHeight, (c + 2) * charWidth, (l + 1) * charHeight);
          } else {
            canvas.clipRect(
                c * charWidth, l * charHeight, (c + addr) * charWidth, (l + 1) * charHeight);
          }
          canvas.drawPaint(defaultPaint);

          // write the text string starting at 'c' for 'addr' number of characters
          defaultPaint.setColor(fg);
          if ((currAttr & VDUBuffer.INVISIBLE) == 0)
            canvas.drawText(
                buffer.charArray[buffer.windowBase + l],
                c,
                addr,
                c * charWidth,
                (l * charHeight) - charTop,
                defaultPaint);

          // Restore the previous clip region
          canvas.restore();

          // advance to the next text block with different characteristics
          c += addr - 1;
          if (isWideCharacter) c++;
        }
      }

      // reset entire-buffer flags
      buffer.update[0] = false;
    }
    fullRedraw = false;
  }
示例#4
0
 public void paintText(float x, float y, String text, boolean underline) {
   paint.setUnderlineText(underline);
   canvas.drawText(text, x, y, paint);
 }