2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.nanoleaf.internal.layout;
15 import java.awt.Color;
16 import java.util.ArrayList;
17 import java.util.List;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.nanoleaf.internal.NanoleafBindingConstants;
23 * Information to the drawing algorithm about which style to use and how to draw.
25 * @author Jørgen Austvik - Initial contribution
28 public class DrawingSettings {
30 private static final Color COLOR_SIDE = Color.GRAY;
31 private static final Color COLOR_TEXT = Color.BLACK;
33 private final LayoutSettings layoutSettings;
34 private final int imageHeight;
35 private final ImagePoint2D min;
36 private final double rotationRadians;
38 public DrawingSettings(LayoutSettings layoutSettings, int imageHeight, ImagePoint2D min, double rotationRadians) {
39 this.imageHeight = imageHeight;
41 this.rotationRadians = rotationRadians;
42 this.layoutSettings = layoutSettings;
45 public boolean shouldDrawLabels() {
46 return layoutSettings.shouldDrawLabels();
49 public boolean shouldDrawCorners() {
50 return layoutSettings.shouldDrawCorners();
53 public boolean shouldDrawOutline() {
54 return layoutSettings.shouldDrawOutline();
57 public boolean shouldFillWithColor() {
58 return layoutSettings.shouldFillWithColor();
61 public Color getOutlineColor() {
65 public Color getLabelColor() {
69 public ImagePoint2D generateImagePoint(Point2D point) {
70 return toPictureLayout(point, imageHeight, min, rotationRadians);
73 public List<ImagePoint2D> generateImagePoints(List<Point2D> points) {
74 return toPictureLayout(points, imageHeight, min, rotationRadians);
77 private static ImagePoint2D toPictureLayout(Point2D original, int imageHeight, ImagePoint2D min,
78 double rotationRadians) {
79 Point2D rotated = original.rotate(rotationRadians);
80 return new ImagePoint2D(NanoleafBindingConstants.LAYOUT_BORDER_WIDTH + rotated.getX() - min.getX(),
81 imageHeight - NanoleafBindingConstants.LAYOUT_BORDER_WIDTH - rotated.getY() + min.getY());
84 private static List<ImagePoint2D> toPictureLayout(List<Point2D> originals, int imageHeight, ImagePoint2D min,
85 double rotationRadians) {
86 List<ImagePoint2D> result = new ArrayList<>(originals.size());
87 for (Point2D original : originals) {
88 result.add(toPictureLayout(original, imageHeight, min, rotationRadians));