root/java/org/gnu/emacs/EmacsDrawLine.java

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. perform

     1 /* Communication module for Android terminals.  -*- c-file-style: "GNU" -*-
     2 
     3 Copyright (C) 2023 Free Software Foundation, Inc.
     4 
     5 This file is part of GNU Emacs.
     6 
     7 GNU Emacs is free software: you can redistribute it and/or modify
     8 it under the terms of the GNU General Public License as published by
     9 the Free Software Foundation, either version 3 of the License, or (at
    10 your option) any later version.
    11 
    12 GNU Emacs is distributed in the hope that it will be useful,
    13 but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 GNU General Public License for more details.
    16 
    17 You should have received a copy of the GNU General Public License
    18 along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
    19 
    20 package org.gnu.emacs;
    21 
    22 import android.graphics.Canvas;
    23 import android.graphics.Paint;
    24 import android.graphics.Rect;
    25 
    26 public final class EmacsDrawLine
    27 {
    28   public static void
    29   perform (EmacsDrawable drawable, EmacsGC gc,
    30            int x, int y, int x2, int y2)
    31   {
    32     Rect rect;
    33     Canvas canvas;
    34     Paint paint;
    35     int x0, x1, y0, y1;
    36 
    37     /* TODO implement stippling.  */
    38     if (gc.fill_style == EmacsGC.GC_FILL_OPAQUE_STIPPLED)
    39       return;
    40 
    41     /* Calculate the leftmost and rightmost points.  */
    42 
    43     x0 = Math.min (x, x2 + 1);
    44     x1 = Math.max (x, x2 + 1);
    45     y0 = Math.min (y, y2 + 1);
    46     y1 = Math.max (y, y2 + 1);
    47 
    48     /* And the clip rectangle.  */
    49 
    50     paint = gc.gcPaint;
    51     rect = new Rect (x0, y0, x1, y1);
    52     canvas = drawable.lockCanvas (gc);
    53 
    54     if (canvas == null)
    55       return;
    56 
    57     paint.setStyle (Paint.Style.FILL);
    58 
    59     /* Since drawLine has PostScript style behavior, adjust the
    60        coordinates appropriately.
    61 
    62        The left most pixel of a straight line is always partially
    63        filled.  Patch it in manually.  */
    64 
    65     if (gc.clip_mask == null)
    66       {
    67         canvas.drawLine ((float) x + 0.5f, (float) y + 0.5f,
    68                          (float) x2 + 0.5f, (float) y2 + 0.5f,
    69                          paint);
    70 
    71         if (x2 > x)
    72           canvas.drawRect (new Rect (x, y, x + 1, y + 1), paint);
    73       }
    74 
    75     /* DrawLine with clip mask not implemented; it is not used by
    76        Emacs.  */
    77     drawable.damageRect (rect);
    78   }
    79 }

/* [<][>][^][v][top][bottom][index][help] */