Skip to content

Commit

Permalink
Improved scale
Browse files Browse the repository at this point in the history
  • Loading branch information
serjiokov committed May 16, 2020
1 parent 61f1064 commit e785774
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 34 deletions.
Expand Up @@ -26,6 +26,6 @@
*/
public interface ChronographObjectLabelRenderer<T extends Brick> {

public void drawLabel(String label, Position brickPosition, GC gc, Rectangle objectBounds, int vOffset);
public void drawLabel(String label, Position brickPosition, GC gc, Rectangle objectBounds, int vOffset, int scale);

}
Expand Up @@ -33,19 +33,22 @@
public class ObjectLabelRendererImpl implements ChronographObjectLabelRenderer<Brick> {

@Override
public void drawLabel(String label, Position brickPosition, GC gc, Rectangle objectBounds, int vOffset) {
public void drawLabel(String label, Position brickPosition, GC gc, Rectangle objectBounds, int vOffset, int scale) {
FontMetrics fontMetrics = gc.getFontMetrics();
int height = fontMetrics.getHeight();
gc.setForeground(StageStyler.STAGE_TEXT_COLOR);
gc.setLineStyle(SWT.LINE_SOLID);
int mediana = objectBounds.height / 2 - height / 2;
gc.drawString(label, objectBounds.x + height / 2, objectBounds.y - height, true);

String msg = String.valueOf(UnitConverter.unitsToLocalDate((int) brickPosition.start()));
gc.drawString(msg, objectBounds.x + BrickStyler.getHeight(), objectBounds.y + mediana, true);
msg = String.valueOf(UnitConverter.unitsToLocalDate((int) brickPosition.end()));
Point msgExtent = gc.textExtent(msg);
gc.drawString(msg, objectBounds.x + objectBounds.width - (msgExtent.x + msgExtent.y), objectBounds.y + mediana,
true);
if (scale > 1) {
gc.drawString(label, objectBounds.x + height / 2, objectBounds.y - height, true);
msg = String.valueOf(UnitConverter.unitsToLocalDate((int) brickPosition.end()));
Point msgExtent = gc.textExtent(msg);
gc.drawString(msg, objectBounds.x + objectBounds.width - (msgExtent.x + msgExtent.y),
objectBounds.y + mediana, true);
}
gc.setLineStyle(SWT.LINE_SOLID);
gc.setForeground(StageStyler.STAGE_TOP_COLOR);
gc.drawLine(objectBounds.x, 0, objectBounds.x, 20);
Expand Down
Expand Up @@ -30,13 +30,15 @@
public class RulerMonthRendererImpl implements ChronographStageRulerRenderer {

private final SimpleDateFormat sdf = new SimpleDateFormat("MMMM"); //$NON-NLS-1$
private final SimpleDateFormat sdfNum = new SimpleDateFormat("MM"); //$NON-NLS-1$
private final Calendar calendar = Calendar.getInstance(TimeZone.getDefault());

@Override
public void draw(GC gc, Rectangle bounds, int scale, int width, int tiksOffset, int xAxis) {
int xMaxPosition = bounds.width + bounds.x;
int yBottomPosition = bounds.y + bounds.height - RulerStyler.RULER_MOUNTH_HEIGHT
- RulerStyler.RULER_YEAR_HEIGHT;
int yTopPosition = bounds.y + bounds.height - RulerStyler.RULER_YEAR_HEIGHT;
int xPosition = 0;
calendar.clear();
calendar.set(Calendar.YEAR, 2019);
Expand All @@ -50,11 +52,16 @@ public void draw(GC gc, Rectangle bounds, int scale, int width, int tiksOffset,
while (true) {

if (calendar.get(Calendar.DAY_OF_MONTH) == 1) {
gc.setForeground(RulerStyler.RULER_BRD_COLOR);
gc.drawLine(xPosition, bounds.y, xPosition, yBottomPosition);
gc.setForeground(RulerStyler.RULER_BTM_COLOR);
// grid line
gc.drawLine(xPosition, bounds.y, xPosition, yTopPosition);
String msg = sdf.format(calendar.getTime());
if (width < 2) {
msg = sdfNum.format(calendar.getTime());
}
gc.setForeground(RulerStyler.RULER_TEXT_COLOR);
gc.drawString(msg, xPosition + 4, yBottomPosition + 3, true);

}
xPosition += width;
if (xPosition > xMaxPosition) {
Expand Down
Expand Up @@ -16,7 +16,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.function.Consumer;

import org.eclipse.chronograph.internal.api.Area;
import org.eclipse.chronograph.internal.api.Brick;
Expand Down Expand Up @@ -286,19 +285,16 @@ private void drawSceneObjects(final GC gc, Area area, final Collection<? extends
if (area == null) {
return;
}
bricks.stream().forEach(new Consumer<Brick>() {
@Override
public void accept(Brick brick) {
calculator.calculateObjectPosition(brick, area, pXhint, pYhint, pxlHint);
Area brickArea = getDrawingArea(brick);
if (brickArea != null) {
Rectangle rectangleArea = areaRectangle.apply(brickArea);
INSTANCE.getContentPainter().draw(brick, gc, rectangleArea, pYhint);
String label = labelProvider.getText(brick);
INSTANCE.getLabelPainter().drawLabel(label, brick.position(), gc, rectangleArea, pYhint);
INSTANCE.getDurationPainter().drawObjectDuration(brick, gc, pYhint);
}
};
bricks.stream().forEach(brick -> {
calculator.calculateObjectPosition(brick, area, pXhint, pYhint, pxlHint);
Area brickArea = getDrawingArea(brick);
if (brickArea != null) {
Rectangle rectangleArea = areaRectangle.apply(brickArea);
INSTANCE.getContentPainter().draw(brick, gc, rectangleArea, pYhint);
String label = labelProvider.getText(brick);
INSTANCE.getLabelPainter().drawLabel(label, brick.position(), gc, rectangleArea, pYhint, pxlHint);
INSTANCE.getDurationPainter().drawObjectDuration(brick, gc, pYhint);
}
});
}

Expand All @@ -315,7 +311,7 @@ private void drawSelectedObjects(final GC gc, Area area, final Collection<? exte
Rectangle rectangleArea = areaRectangle.apply(brickArea);
INSTANCE.getSelectedContentPainter().draw(brick, gc, rectangleArea, pYhint);
String label = labelProvider.getText(brick);
INSTANCE.getLabelPainter().drawLabel(label, brick.position(), gc, rectangleArea, pYhint);
INSTANCE.getLabelPainter().drawLabel(label, brick.position(), gc, rectangleArea, pYhint, pxlHint);
INSTANCE.getDurationPainter().drawObjectDuration(brick, gc, pYhint);
}
}
Expand Down Expand Up @@ -358,17 +354,18 @@ public List<? extends Brick> getDrawingObjects() {
private void updateStageScale() {
if (stageScale <= 0) {
stageScale = 1;
pxlHint = stageScale * 2;
}
if (stageScale == 2 || stageScale == 3) {
pxlHint = stageScale * 2;
}
if (stageScale == 4) {
pxlHint = stageScale * 3;
}
if (stageScale > 4) {
pxlHint = stageScale * SCALE_DEFAULT;

}
pxlHint = stageScale;
// if (stageScale == 2 || stageScale == 3) {
// pxlHint = stageScale * 1;
// }
// if (stageScale == 4) {
// pxlHint = stageScale * 2;
// }
// if (stageScale > 4) {
// pxlHint = stageScale * SCALE_DEFAULT;
// }
}

public void scaleUp() {
Expand Down

0 comments on commit e785774

Please sign in to comment.