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.Path;
25 import android.graphics.Point;
26 import android.graphics.Rect;
27 import android.graphics.RectF;
28
29 public final class EmacsFillPolygon
30 {
31 public static void
32 perform (EmacsDrawable drawable, EmacsGC gc, Point points[])
33 {
34 Canvas canvas;
35 Path path;
36 Paint paint;
37 Rect rect;
38 RectF rectF;
39 int i;
40
41 canvas = drawable.lockCanvas (gc);
42
43 if (canvas == null)
44 return;
45
46 paint = gc.gcPaint;
47
48 /* Build the path from the given array of points. */
49 path = new Path ();
50
51 if (points.length >= 1)
52 {
53 path.moveTo (points[0].x, points[0].y);
54
55 for (i = 1; i < points.length; ++i)
56 path.lineTo (points[i].x, points[i].y);
57
58 path.close ();
59 }
60
61 /* Compute the damage rectangle. */
62 rectF = new RectF (0, 0, 0, 0);
63 path.computeBounds (rectF, true);
64
65 rect = new Rect ((int) Math.floor (rectF.left),
66 (int) Math.floor (rectF.top),
67 (int) Math.ceil (rectF.right),
68 (int) Math.ceil (rectF.bottom));
69
70 paint.setStyle (Paint.Style.FILL);
71
72 if (gc.clip_mask == null)
73 canvas.drawPath (path, paint);
74
75 drawable.damageRect (rect);
76
77 /* FillPolygon with clip mask not implemented; it is not used by
78 Emacs. */
79 }
80 }