Added ProgressDot II

This commit is contained in:
Robert Vokac 2024-03-23 17:57:41 +01:00
parent 64d6e28323
commit 68f420526a
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055

View File

@ -31,8 +31,9 @@ public class ProgressDot extends Widget {
@Override @Override
public void paintWidget(Graphics g) { public void paintWidget(Graphics g) {
int dotSize = 1;
if (side == 0) { if (side == 0) {
this.side = Math.min(getWidth(), getHeight()); this.side = Math.min(getWidth(), getHeight()) / dotSize;
this.square = side * side; this.square = side * side;
for (int y = 1; y <= side; y++) { for (int y = 1; y <= side; y++) {
for (int x = 1; x <= side; x++) { for (int x = 1; x <= side; x++) {
@ -43,8 +44,8 @@ public class ProgressDot extends Widget {
Double done = donePercent(); Double done = donePercent();
int enabledDotsExpectedSize = (int) (done * square); int enabledDotsExpectedSize = (int) (done * square);
int disabledDotsExpectedSize = square - enabledDotsExpectedSize; int disabledDotsExpectedSize = square - enabledDotsExpectedSize;
// System.out.println("enabledDots.size()=" + enabledDots.size()); System.out.println("enabledDots.size()=" + enabledDots.size());
// System.out.println("disabledDots.size()=" + disabledDots.size()); System.out.println("disabledDots.size()=" + disabledDots.size());
while (enabledDots.size() > enabledDotsExpectedSize) { while (enabledDots.size() > enabledDotsExpectedSize) {
int randomIndex = (int) (enabledDots.size() * Math.random()); int randomIndex = (int) (enabledDots.size() * Math.random());
Dot randomDot = enabledDots.remove(randomIndex); Dot randomDot = enabledDots.remove(randomIndex);
@ -62,15 +63,23 @@ public class ProgressDot extends Widget {
RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints.VALUE_ANTIALIAS_ON);
int numberOfDots = (int) (donePercent() * square); int numberOfDots = (int) (donePercent() * square);
Visibility visibility = Visibility.ofProperty(visibilityProperty); Visibility visibility = Visibility.ofProperty(visibilityProperty);
{ {
if (visibility.isStronglyColored() || mouseOver) { if (visibility.isStronglyColored() || mouseOver) {
brush.setColor(Color.GRAY); brush.setColor(Color.GRAY);
} }
for(Dot d:enabledDots) { for (Dot d : enabledDots) {
brush.drawLine(d.x, d.y, d.x, d.y); brush.fillRect(((d.x - 1) * dotSize) + d.x, ((d.y - 1) * dotSize) + d.y, dotSize+(dotSize > 1 ? 1 : 1), dotSize+(dotSize > 1 ? 1 : 1));
}
if(visibility.isStronglyColored()){
//Color currentColor = brush.getColor();
brush.setColor(Battery.LOW_WEAKLY_COLORED);
for (Dot d : disabledDots) {
brush.fillRect(((d.x - 1) * dotSize) + d.x, ((d.y - 1) * dotSize) + d.y, dotSize+(dotSize > 1 ? 1 : 1), dotSize+(dotSize > 1 ? 1 : 1));
}
//brush.setColor(currentColor);
} }
brush.setColor(FOREGROUND_COLOR); brush.setColor(FOREGROUND_COLOR);
} }