root/java/org/gnu/emacs/EmacsGC.java

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

DEFINITIONS

This source file includes following definitions.
  1. markDirty
  2. resetXfermode

     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.Rect;
    23 import android.graphics.Paint;
    24 
    25 import android.graphics.PorterDuff.Mode;
    26 import android.graphics.PorterDuffXfermode;
    27 import android.graphics.Xfermode;
    28 
    29 /* X like graphics context structures.  Keep the enums in synch with
    30    androidgui.h! */
    31 
    32 public final class EmacsGC extends EmacsHandleObject
    33 {
    34   public static final int GC_COPY = 0;
    35   public static final int GC_XOR  = 1;
    36 
    37   public static final int GC_FILL_SOLID                 = 0;
    38   public static final int GC_FILL_OPAQUE_STIPPLED       = 1;
    39 
    40   public static final Xfermode xorAlu, srcInAlu;
    41 
    42   public int function, fill_style;
    43   public int foreground, background;
    44   public int clip_x_origin, clip_y_origin;
    45   public int ts_origin_x, ts_origin_y;
    46   public Rect clip_rects[], real_clip_rects[];
    47   public EmacsPixmap clip_mask, stipple;
    48   public Paint gcPaint;
    49 
    50   /* ID incremented every time the clipping rectangles of any GC
    51      changes.  */
    52   private static long clip_serial;
    53 
    54   /* The value of clipRectID after the last time this GCs clip
    55      rectangles changed.  0 if there are no clip rectangles.  */
    56   public long clipRectID;
    57 
    58   static
    59   {
    60     xorAlu = new PorterDuffXfermode (Mode.XOR);
    61     srcInAlu = new PorterDuffXfermode (Mode.SRC_IN);
    62   }
    63 
    64   /* The following fields are only set on immutable GCs.  */
    65 
    66   public
    67   EmacsGC (short handle)
    68   {
    69     /* For historical reasons the C code has an extra layer of
    70        indirection above this GC handle.  struct android_gc is the GC
    71        used by Emacs code, while android_gcontext is the type of the
    72        handle.  */
    73     super (handle);
    74 
    75     fill_style = GC_FILL_SOLID;
    76     function = GC_COPY;
    77     foreground = 0;
    78     background = 0xffffff;
    79     gcPaint = new Paint ();
    80   }
    81 
    82   /* Mark this GC as dirty.  Apply parameters to the paint and
    83      recompute real_clip_rects.  */
    84 
    85   public void
    86   markDirty (boolean clipRectsChanged)
    87   {
    88     int i;
    89 
    90     if (clipRectsChanged)
    91       {
    92         if ((ts_origin_x != 0 || ts_origin_y != 0)
    93             && clip_rects != null)
    94           {
    95             real_clip_rects = new Rect[clip_rects.length];
    96 
    97             for (i = 0; i < clip_rects.length; ++i)
    98               {
    99                 real_clip_rects[i] = new Rect (clip_rects[i]);
   100                 real_clip_rects[i].offset (ts_origin_x, ts_origin_y);
   101               }
   102           }
   103         else
   104           real_clip_rects = clip_rects;
   105 
   106         clipRectID = ++clip_serial;
   107       }
   108 
   109     gcPaint.setStrokeWidth (1f);
   110     gcPaint.setColor (foreground | 0xff000000);
   111     gcPaint.setXfermode (function == GC_XOR
   112                          ? xorAlu : srcInAlu);
   113   }
   114 
   115   public void
   116   resetXfermode ()
   117   {
   118     gcPaint.setXfermode (function == GC_XOR
   119                          ? xorAlu : srcInAlu);
   120   }
   121 };

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