aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/org/gnu/emacs/EmacsGC.java15
-rw-r--r--java/org/gnu/emacs/EmacsTileObject.java101
2 files changed, 105 insertions, 11 deletions
diff --git a/java/org/gnu/emacs/EmacsGC.java b/java/org/gnu/emacs/EmacsGC.java
index f956b230f8c..d400c23e067 100644
--- a/java/org/gnu/emacs/EmacsGC.java
+++ b/java/org/gnu/emacs/EmacsGC.java
@@ -29,8 +29,6 @@ import android.graphics.PorterDuff.Mode;
29import android.graphics.PorterDuffColorFilter; 29import android.graphics.PorterDuffColorFilter;
30import android.graphics.Shader.TileMode; 30import android.graphics.Shader.TileMode;
31 31
32import android.graphics.drawable.BitmapDrawable;
33
34import android.os.Build; 32import android.os.Build;
35 33
36/* X like graphics context structures. Keep the enums in synch with 34/* X like graphics context structures. Keep the enums in synch with
@@ -58,7 +56,7 @@ public final class EmacsGC extends EmacsHandleObject
58 public Paint gcPaint; 56 public Paint gcPaint;
59 57
60 /* Drawable object for rendering the stiple bitmap. */ 58 /* Drawable object for rendering the stiple bitmap. */
61 public BitmapDrawable tileObject; 59 public EmacsTileObject tileObject;
62 60
63 /* ID incremented every time the clipping rectangles of any GC 61 /* ID incremented every time the clipping rectangles of any GC
64 changes. */ 62 changes. */
@@ -132,11 +130,9 @@ public final class EmacsGC extends EmacsHandleObject
132 130
133 /* Allocate a new tile object if none is already present or it 131 /* Allocate a new tile object if none is already present or it
134 cannot be reconfigured. */ 132 cannot be reconfigured. */
135 if ((tileObject == null) 133 if (tileObject == null)
136 || (Build.VERSION.SDK_INT < Build.VERSION_CODES.S))
137 { 134 {
138 tileObject = new BitmapDrawable (EmacsService.resources, 135 tileObject = new EmacsTileObject (stippleBitmap);
139 stippleBitmap);
140 tileObject.setTileModeXY (TileMode.REPEAT, TileMode.REPEAT); 136 tileObject.setTileModeXY (TileMode.REPEAT, TileMode.REPEAT);
141 } 137 }
142 else 138 else
@@ -144,11 +140,8 @@ public final class EmacsGC extends EmacsHandleObject
144 bitmap. */ 140 bitmap. */
145 tileObject.setBitmap (stippleBitmap); 141 tileObject.setBitmap (stippleBitmap);
146 } 142 }
147 else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
148 && tileObject != null)
149 tileObject.setBitmap (null);
150 else if (tileObject != null) 143 else if (tileObject != null)
151 tileObject = null; 144 tileObject.setBitmap (null);
152 } 145 }
153 146
154 /* Prepare the tile object to draw a stippled image onto a section of 147 /* Prepare the tile object to draw a stippled image onto a section of
diff --git a/java/org/gnu/emacs/EmacsTileObject.java b/java/org/gnu/emacs/EmacsTileObject.java
new file mode 100644
index 00000000000..34a35e83bfb
--- /dev/null
+++ b/java/org/gnu/emacs/EmacsTileObject.java
@@ -0,0 +1,101 @@
1/* Communication module for Android terminals. -*- c-file-style: "GNU" -*-
2
3Copyright (C) 2023-2024 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or (at
10your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
19
20package org.gnu.emacs;
21
22import android.graphics.Bitmap;
23import android.graphics.BitmapShader;
24import android.graphics.Canvas;
25import android.graphics.ColorFilter;
26import android.graphics.Paint;
27import android.graphics.Rect;
28import android.graphics.Shader.TileMode;
29
30/* This is a crude facsimilie of the BitmapDrawable class implementing
31 just enough of its functionality to support displaying stipples in
32 EmacsGC. */
33
34public final class EmacsTileObject
35{
36 /* Color filter object set by EmacsGC. */
37 private ColorFilter colorFilter;
38
39 /* Bitmap object set by EmacsGC. */
40 private Bitmap bitmap;
41
42 /* Tiling modes on either axis. */
43 private TileMode xTile, yTile;
44
45 /* Destination rectangle. */
46 private Rect boundsRect;
47
48 /* Paint providing graphics properties for drawBitmap. */
49 private Paint paint;
50
51
52
53 public
54 EmacsTileObject (Bitmap stippleBitmap)
55 {
56 bitmap = stippleBitmap;
57 paint = new Paint ();
58 }
59
60 public void
61 setBitmap (Bitmap newBitmap)
62 {
63 bitmap = newBitmap;
64 }
65
66 public void
67 setBounds (Rect bounds)
68 {
69 boundsRect = bounds;
70 }
71
72 public void
73 setTileModeXY (TileMode newXTile, TileMode newYTile)
74 {
75 xTile = newXTile;
76 yTile = newYTile;
77 }
78
79 public void
80 setColorFilter (ColorFilter filterObject)
81 {
82 paint.setColorFilter (filterObject);
83 }
84
85 public Bitmap
86 getBitmap ()
87 {
88 return bitmap;
89 }
90
91 /* Replicate `bitmap' over CANVAS so that boundsRect is covered with
92 copies thereof on the X axis, if xTile is REPEAT, and also on the Y
93 axis, if yTile is a like value. */
94
95 public void
96 draw (Canvas canvas)
97 {
98 paint.setShader (new BitmapShader (bitmap, xTile, yTile));
99 canvas.drawRect (boundsRect, paint);
100 }
101};