Exemplo n.º 1
0
  public TerminalView(Context context, TerminalBridge bridge) {
    super(context);

    this.context = context;
    this.bridge = bridge;
    paint = new Paint();

    setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    setFocusable(true);
    setFocusableInTouchMode(true);

    cursorPaint = new Paint();
    cursorPaint.setColor(bridge.color[bridge.defaultFg]);
    cursorPaint.setXfermode(new PixelXorXfermode(bridge.color[bridge.defaultBg]));
    cursorPaint.setAntiAlias(true);

    cursorStrokePaint = new Paint(cursorPaint);
    cursorStrokePaint.setStrokeWidth(0.1f);
    cursorStrokePaint.setStyle(Paint.Style.STROKE);

    /*
     * Set up our cursor indicators on a 1x1 Path object which we can later
     * transform to our character width and height
     */
    // TODO make this into a resource somehow
    shiftCursor = new Path();
    shiftCursor.lineTo(0.5f, 0.33f);
    shiftCursor.lineTo(1.0f, 0.0f);

    altCursor = new Path();
    altCursor.moveTo(0.0f, 1.0f);
    altCursor.lineTo(0.5f, 0.66f);
    altCursor.lineTo(1.0f, 1.0f);

    ctrlCursor = new Path();
    ctrlCursor.moveTo(0.0f, 0.25f);
    ctrlCursor.lineTo(1.0f, 0.5f);
    ctrlCursor.lineTo(0.0f, 0.75f);

    // For creating the transform when the terminal resizes
    tempSrc = new RectF();
    tempSrc.set(0.0f, 0.0f, 1.0f, 1.0f);
    tempDst = new RectF();
    scaleMatrix = new Matrix();

    bridge.addFontSizeChangedListener(this);

    // connect our view up to the bridge
    setOnKeyListener(bridge.getKeyHandler());
  }
Exemplo n.º 2
0
  @Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);

    bridge.parentChanged(this);

    scaleCursors();
  }
Exemplo n.º 3
0
 /**
  * Ask the {@link TerminalBridge} we're connected to to resize to a specific size.
  *
  * @param width
  * @param height
  */
 public void forceSize(int width, int height) {
   bridge.resizeComputed(width, height, getWidth(), getHeight());
 }
Exemplo n.º 4
0
  @Override
  public void onDraw(Canvas canvas) {
    if (bridge.bitmap != null) {
      // draw the bitmap
      bridge.onDraw();

      // draw the bridge bitmap if it exists
      canvas.drawBitmap(bridge.bitmap, 0, 0, paint);

      // also draw cursor if visible
      if (bridge.buffer.isCursorVisible()) {
        int cursorColumn = bridge.buffer.getCursorColumn();
        final int cursorRow = bridge.buffer.getCursorRow();

        final int columns = bridge.buffer.getColumns();

        if (cursorColumn == columns) cursorColumn = columns - 1;

        if (cursorColumn < 0 || cursorRow < 0) return;

        int currentAttribute = bridge.buffer.getAttributes(cursorColumn, cursorRow);
        boolean onWideCharacter = (currentAttribute & VDUBuffer.FULLWIDTH) != 0;

        int x = cursorColumn * bridge.charWidth;
        int y =
            (bridge.buffer.getCursorRow() + bridge.buffer.screenBase - bridge.buffer.windowBase)
                * bridge.charHeight;

        // Save the current clip and translation
        canvas.save();

        canvas.translate(x, y);
        canvas.clipRect(0, 0, bridge.charWidth * (onWideCharacter ? 2 : 1), bridge.charHeight);
        canvas.drawPaint(cursorPaint);

        final int deadKey = bridge.getKeyHandler().getDeadKey();
        if (deadKey != 0) {
          canvas.drawText(new char[] {(char) deadKey}, 0, 1, 0, 0, cursorStrokePaint);
        }

        // Make sure we scale our decorations to the correct size.
        canvas.concat(scaleMatrix);

        int metaState = bridge.getKeyHandler().getMetaState();

        if ((metaState & TerminalKeyListener.META_SHIFT_ON) != 0)
          canvas.drawPath(shiftCursor, cursorStrokePaint);
        else if ((metaState & TerminalKeyListener.META_SHIFT_LOCK) != 0)
          canvas.drawPath(shiftCursor, cursorPaint);

        if ((metaState & TerminalKeyListener.META_ALT_ON) != 0)
          canvas.drawPath(altCursor, cursorStrokePaint);
        else if ((metaState & TerminalKeyListener.META_ALT_LOCK) != 0)
          canvas.drawPath(altCursor, cursorPaint);

        if ((metaState & TerminalKeyListener.META_CTRL_ON) != 0)
          canvas.drawPath(ctrlCursor, cursorStrokePaint);
        else if ((metaState & TerminalKeyListener.META_CTRL_LOCK) != 0)
          canvas.drawPath(ctrlCursor, cursorPaint);

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

      // draw any highlighted area
      if (bridge.isSelectingForCopy()) {
        SelectionArea area = bridge.getSelectionArea();
        canvas.save(Canvas.CLIP_SAVE_FLAG);
        canvas.clipRect(
            area.getLeft() * bridge.charWidth,
            area.getTop() * bridge.charHeight,
            (area.getRight() + 1) * bridge.charWidth,
            (area.getBottom() + 1) * bridge.charHeight);
        canvas.drawPaint(cursorPaint);
        canvas.restore();
      }
    }
  }
Exemplo n.º 5
0
 public void destroy() {
   // tell bridge to destroy its bitmap
   bridge.parentDestroyed();
 }