forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Nanoleaf] New Channel: State (openhab#13746)
* [Nanoleaf] New Channel: State Shows an image of the state of the panels with color. Also makes the layout slightly prettier. This is less functional than the layout, and more eyecandy. Signed-off-by: Jørgen Austvik <jaustvik@acm.org>
- Loading branch information
Showing
31 changed files
with
2,417 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
....nanoleaf/src/main/java/org/openhab/binding/nanoleaf/internal/layout/DrawingSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* Copyright (c) 2010-2022 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.nanoleaf.internal.layout; | ||
|
||
import java.awt.Color; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.openhab.binding.nanoleaf.internal.NanoleafBindingConstants; | ||
|
||
/** | ||
* Information to the drawing algorithm about which style to use and how to draw. | ||
* | ||
* @author Jørgen Austvik - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class DrawingSettings { | ||
|
||
private static final Color COLOR_SIDE = Color.GRAY; | ||
private static final Color COLOR_TEXT = Color.BLACK; | ||
|
||
private final LayoutSettings layoutSettings; | ||
private final int imageHeight; | ||
private final ImagePoint2D min; | ||
private final double rotationRadians; | ||
|
||
public DrawingSettings(LayoutSettings layoutSettings, int imageHeight, ImagePoint2D min, double rotationRadians) { | ||
this.imageHeight = imageHeight; | ||
this.min = min; | ||
this.rotationRadians = rotationRadians; | ||
this.layoutSettings = layoutSettings; | ||
} | ||
|
||
public boolean shouldDrawLabels() { | ||
return layoutSettings.shouldDrawLabels(); | ||
} | ||
|
||
public boolean shouldDrawCorners() { | ||
return layoutSettings.shouldDrawCorners(); | ||
} | ||
|
||
public boolean shouldDrawOutline() { | ||
return layoutSettings.shouldDrawOutline(); | ||
} | ||
|
||
public boolean shouldFillWithColor() { | ||
return layoutSettings.shouldFillWithColor(); | ||
} | ||
|
||
public Color getOutlineColor() { | ||
return COLOR_SIDE; | ||
} | ||
|
||
public Color getLabelColor() { | ||
return COLOR_TEXT; | ||
} | ||
|
||
public ImagePoint2D generateImagePoint(Point2D point) { | ||
return toPictureLayout(point, imageHeight, min, rotationRadians); | ||
} | ||
|
||
public List<ImagePoint2D> generateImagePoints(List<Point2D> points) { | ||
return toPictureLayout(points, imageHeight, min, rotationRadians); | ||
} | ||
|
||
private static ImagePoint2D toPictureLayout(Point2D original, int imageHeight, ImagePoint2D min, | ||
double rotationRadians) { | ||
Point2D rotated = original.rotate(rotationRadians); | ||
ImagePoint2D translated = new ImagePoint2D( | ||
NanoleafBindingConstants.LAYOUT_BORDER_WIDTH + rotated.getX() - min.getX(), | ||
imageHeight - NanoleafBindingConstants.LAYOUT_BORDER_WIDTH - rotated.getY() + min.getY()); | ||
return translated; | ||
} | ||
|
||
private static List<ImagePoint2D> toPictureLayout(List<Point2D> originals, int imageHeight, ImagePoint2D min, | ||
double rotationRadians) { | ||
List<ImagePoint2D> result = new ArrayList<>(originals.size()); | ||
for (Point2D original : originals) { | ||
result.add(toPictureLayout(original, imageHeight, min, rotationRadians)); | ||
} | ||
|
||
return result; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...ing.nanoleaf/src/main/java/org/openhab/binding/nanoleaf/internal/layout/ImagePoint2D.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Copyright (c) 2010-2022 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
package org.openhab.binding.nanoleaf.internal.layout; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
||
/** | ||
* Coordinate in the 2D space of the image. | ||
* | ||
* @author Jørgen Austvik - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class ImagePoint2D { | ||
private final int x; | ||
private final int y; | ||
|
||
public ImagePoint2D(int x, int y) { | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
public int getX() { | ||
return x; | ||
} | ||
|
||
public int getY() { | ||
return y; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("image coordinate x:%d, y:%d", x, y); | ||
} | ||
} |
Oops, something went wrong.