]> git.basschouten.com Git - openhab-addons.git/blob
5ec5c372524440712841b4f73080da37e7dc5935
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.nanoleaf.internal.layout;
14
15 import java.awt.Color;
16 import java.util.ArrayList;
17 import java.util.List;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.nanoleaf.internal.NanoleafBindingConstants;
21
22 /**
23  * Information to the drawing algorithm about which style to use and how to draw.
24  *
25  * @author Jørgen Austvik - Initial contribution
26  */
27 @NonNullByDefault
28 public class DrawingSettings {
29
30     private static final Color COLOR_SIDE = Color.GRAY;
31     private static final Color COLOR_TEXT = Color.BLACK;
32
33     private final LayoutSettings layoutSettings;
34     private final int imageHeight;
35     private final ImagePoint2D min;
36     private final double rotationRadians;
37
38     public DrawingSettings(LayoutSettings layoutSettings, int imageHeight, ImagePoint2D min, double rotationRadians) {
39         this.imageHeight = imageHeight;
40         this.min = min;
41         this.rotationRadians = rotationRadians;
42         this.layoutSettings = layoutSettings;
43     }
44
45     public boolean shouldDrawLabels() {
46         return layoutSettings.shouldDrawLabels();
47     }
48
49     public boolean shouldDrawCorners() {
50         return layoutSettings.shouldDrawCorners();
51     }
52
53     public boolean shouldDrawOutline() {
54         return layoutSettings.shouldDrawOutline();
55     }
56
57     public boolean shouldFillWithColor() {
58         return layoutSettings.shouldFillWithColor();
59     }
60
61     public Color getOutlineColor() {
62         return COLOR_SIDE;
63     }
64
65     public Color getLabelColor() {
66         return COLOR_TEXT;
67     }
68
69     public ImagePoint2D generateImagePoint(Point2D point) {
70         return toPictureLayout(point, imageHeight, min, rotationRadians);
71     }
72
73     public List<ImagePoint2D> generateImagePoints(List<Point2D> points) {
74         return toPictureLayout(points, imageHeight, min, rotationRadians);
75     }
76
77     private static ImagePoint2D toPictureLayout(Point2D original, int imageHeight, ImagePoint2D min,
78             double rotationRadians) {
79         Point2D rotated = original.rotate(rotationRadians);
80         ImagePoint2D translated = new ImagePoint2D(
81                 NanoleafBindingConstants.LAYOUT_BORDER_WIDTH + rotated.getX() - min.getX(),
82                 imageHeight - NanoleafBindingConstants.LAYOUT_BORDER_WIDTH - rotated.getY() + min.getY());
83         return translated;
84     }
85
86     private static List<ImagePoint2D> toPictureLayout(List<Point2D> originals, int imageHeight, ImagePoint2D min,
87             double rotationRadians) {
88         List<ImagePoint2D> result = new ArrayList<>(originals.size());
89         for (Point2D original : originals) {
90             result.add(toPictureLayout(original, imageHeight, min, rotationRadians));
91         }
92
93         return result;
94     }
95 }