Simple editor - fixed timeline offset

This commit is contained in:
Jindra Petřík
2025-05-22 19:49:10 +02:00
parent 16700bcaca
commit 31c8715fd3
3 changed files with 56 additions and 47 deletions
@@ -33,38 +33,37 @@ import javax.swing.JPanel;
*/
public class TimelineTimePanel extends JPanel implements MouseListener {
public static final Color borderColor = Color.black;
public static final Color BORDER_COLOR = Color.black;
public static final int lineLength = 3;
public static final int LINE_LENGTH = 3;
public static final int lineTextSpace = 3;
public static final int LINE_TEXT_SPACE = 3;
public static final Color fontColor = Color.black;
public static final Color FONT_COLOR = Color.black;
public float fontSize = 10.0f;
private int scrollOffset = 0;
private int selectedFrame = -1;
private int leftPos = 0;
private Timeline timeline;
private final List<FrameSelectionListener> listeners = new ArrayList<>();
private final TimelineDepthPanel depthPanel;
public TimelineTimePanel() {
public TimelineTimePanel(TimelineDepthPanel depthPanel) {
Dimension dim = new Dimension(Integer.MAX_VALUE, TimelineBodyPanel.FRAME_HEIGHT);
setSize(dim);
setPreferredSize(dim);
setMinimumSize(new Dimension(0, TimelineBodyPanel.FRAME_HEIGHT));
addMouseListener(this);
this.depthPanel = depthPanel;
}
public void setTimeline(Timeline timeline) {
int maxDepth = timeline == null ? 0 : timeline.getMaxDepth();
String maxDepthStr = Integer.toString(maxDepth);
setFont(getFont().deriveFont(TimelineDepthPanel.FONT_SIZE));
int maxDepthW = getFontMetrics(getFont()).stringWidth(maxDepthStr);
leftPos = maxDepthW + 2 * TimelineDepthPanel.PADDING;
this.timeline = timeline;
}
@@ -98,10 +97,10 @@ public class TimelineTimePanel extends JPanel implements MouseListener {
int end_f = (scrollOffset + clip.x + clip.width) / frameWidth;
g.setColor(TimelineBodyPanel.getBackgroundColor());
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(borderColor);
g.setColor(BORDER_COLOR);
int xofs = -scrollOffset % frameWidth;
for (int f = 0; f <= end_f; f++) {
g.drawLine(xofs + f * frameWidth + 1, TimelineBodyPanel.FRAME_HEIGHT - 1, xofs + f * frameWidth + 1, TimelineBodyPanel.FRAME_HEIGHT - lineLength);
g.drawLine(xofs + f * frameWidth + 1, TimelineBodyPanel.FRAME_HEIGHT - 1, xofs + f * frameWidth + 1, TimelineBodyPanel.FRAME_HEIGHT - LINE_LENGTH);
}
g.setFont(g.getFont().deriveFont(fontSize));
for (int f = 0; f <= end_f; f++) {
@@ -112,7 +111,7 @@ public class TimelineTimePanel extends JPanel implements MouseListener {
g.setColor(TimelineBodyPanel.SELECTED_BORDER_COLOR);
g.drawRect(xofs + f * frameWidth + 1, 0, frameWidth, TimelineBodyPanel.FRAME_HEIGHT - 1);
}
g.setColor(fontColor);
g.setColor(FONT_COLOR);
if (timeline != null && timeline.timelined instanceof ButtonTag) {
if (f < 5) {
@@ -132,13 +131,13 @@ public class TimelineTimePanel extends JPanel implements MouseListener {
break;
}
int w = g.getFontMetrics().stringWidth(timeStr);
g.drawString(timeStr, xofs + f * frameWidth + frameWidth / 2 - w / 2 + 1, TimelineBodyPanel.FRAME_HEIGHT - lineLength - lineTextSpace);
g.drawString(timeStr, xofs + f * frameWidth + frameWidth / 2 - w / 2 + 1, TimelineBodyPanel.FRAME_HEIGHT - LINE_LENGTH - LINE_TEXT_SPACE);
}
} else {
if ((cur_f + 1) % 5 == 0 || cur_f == 0) {
String timeStr = Integer.toString(cur_f + 1);
int w = g.getFontMetrics().stringWidth(timeStr);
g.drawString(timeStr, xofs + f * frameWidth + frameWidth / 2 - w / 2 + 1, TimelineBodyPanel.FRAME_HEIGHT - lineLength - lineTextSpace);
g.drawString(timeStr, xofs + f * frameWidth + frameWidth / 2 - w / 2 + 1, TimelineBodyPanel.FRAME_HEIGHT - LINE_LENGTH - LINE_TEXT_SPACE);
}
}
}