diff options
| author | Simon Rettberg | 2015-07-21 17:17:53 +0200 |
|---|---|---|
| committer | Simon Rettberg | 2015-07-21 17:17:53 +0200 |
| commit | a964ad96a20436d914a6bd809ab2b66e3144aba1 (patch) | |
| tree | e44222fd9e8bdf22de209e2a66c3a3a0ddaf5c0f /dozentenmodul/src/main/java | |
| parent | [client] Fixes and improvements related to file transfer; rename bytesToGigab... (diff) | |
| download | tutor-module-a964ad96a20436d914a6bd809ab2b66e3144aba1.tar.gz tutor-module-a964ad96a20436d914a6bd809ab2b66e3144aba1.tar.xz tutor-module-a964ad96a20436d914a6bd809ab2b66e3144aba1.zip | |
[client] Improve rendering of BlockProgressBar
Diffstat (limited to 'dozentenmodul/src/main/java')
| -rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/BlockProgressBar.java | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/BlockProgressBar.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/BlockProgressBar.java index efb41b0c..762fcd20 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/BlockProgressBar.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/BlockProgressBar.java @@ -82,18 +82,21 @@ public class BlockProgressBar extends Canvas { final float width = a.width - 2; final float complete = blocks.getComplete(); final float doneWidth = width * complete; + final Rectangle doneRect = new Rectangle(a.x, a.y, (int) doneWidth, a.height); + final Rectangle remainingRect = new Rectangle(a.x + (int) doneWidth, a.y, (int) (width - doneWidth), a.height); e.gc.setBackground(blue); - e.gc.fillRectangle(a.x, a.y, (int) doneWidth, a.height); + e.gc.fillRectangle(doneRect); e.gc.setBackground(white); - e.gc.fillRectangle(a.x + (int) doneWidth, a.y, (int) (width - doneWidth), a.height); + e.gc.fillRectangle(remainingRect); final String progress = (int) (complete * 100) + "%"; Point textExtent = e.gc.textExtent(progress, SWT.DRAW_TRANSPARENT); final int textX = a.x + (a.width - textExtent.x) / 2; final int textY = a.y + (a.height - textExtent.y) / 2; e.gc.setForeground(white); - e.gc.drawText(progress, textX - 1, textY - 1, true); - e.gc.drawText(progress, textX + 1, textY + 1, true); + e.gc.setClipping(doneRect); + e.gc.drawText(progress, textX, textY, true); e.gc.setForeground(black); + e.gc.setClipping(remainingRect); e.gc.drawText(progress, textX, textY, true); } @@ -104,7 +107,7 @@ public class BlockProgressBar extends Canvas { final float width = a.width - 2; float blockWidth = width / blockCount; int rows = 1; - while (blockWidth * rows < 6 && a.height / rows > 8) { + while (blockWidth * rows < 6 && (float) a.height / rows > 7) { rows++; } blockWidth *= rows; @@ -117,29 +120,24 @@ public class BlockProgressBar extends Canvas { blockHeightVisible = blockHeight - 2; } // Draw + e.gc.setBackground(white); + e.gc.fillRectangle(a); float x = a.x, y = a.y; for (byte block : blocks.getBlocks()) { + float toX = x + blockWidth; if (block >= 0 && block < blockColors.length) { e.gc.setBackground(blockColors[block]); - } else { - e.gc.setBackground(white); + final int boxWidth = ((int) toX) - ((int) x) - 1; + final int boxHeight = (int) (y + blockHeightVisible) - (int) y; + e.gc.fillRectangle((int) x, (int) y, boxWidth > 1 ? boxWidth : 1, boxHeight > 1 ? boxHeight + : 1); } - e.gc.fillRectangle((int) x, (int) y, (int) (x + blockWidth) - (int) x, - (int) (y + blockHeightVisible) - (int) y); - x += blockWidth; + x = toX; if (x + 0.5 > a.width) { - e.gc.setBackground(white); - e.gc.fillRectangle(a.x, (int) (y + blockHeightVisible), a.width, 2); x = a.x; y += blockHeight; } } - // If we're multiline and have an odd number of blocks, there might be some remaining space - draw white - if (x + 0.5 < a.width) { - e.gc.setBackground(white); - e.gc.fillRectangle((int) x, (int) y, (int) (x + blockWidth) - (int) x, - (int) (y + blockHeightVisible) - (int) y); - } } } |
