|
5 | 5 | import javax.sound.midi.Sequencer; |
6 | 6 |
|
7 | 7 | import org.eclipse.swt.SWT; |
| 8 | +import org.eclipse.swt.events.PaintEvent; |
| 9 | +import org.eclipse.swt.events.PaintListener; |
8 | 10 | import org.eclipse.swt.events.SelectionAdapter; |
9 | 11 | import org.eclipse.swt.events.SelectionEvent; |
| 12 | +import org.eclipse.swt.graphics.GC; |
10 | 13 | import org.eclipse.swt.graphics.Image; |
11 | 14 | import org.eclipse.swt.layout.GridData; |
12 | 15 | import org.eclipse.swt.layout.GridLayout; |
@@ -35,10 +38,32 @@ public MidiPlaybackControl(Composite parent, Sequencer sequencer) { |
35 | 38 |
|
36 | 39 | createButtonRow(); |
37 | 40 | createSliderRow(); |
| 41 | + addPaintListener(new PaintListener() { |
| 42 | + |
| 43 | + @Override |
| 44 | + public void paintControl(PaintEvent e) { |
| 45 | + drawMarker(e); |
| 46 | + } |
| 47 | + }); |
38 | 48 |
|
39 | 49 | rewind(); |
40 | 50 | } |
41 | 51 |
|
| 52 | + private void drawMarker(PaintEvent e) { |
| 53 | + if (mark > 0) { |
| 54 | + //how to obtain the platform specific button width?? |
| 55 | + //OS.GetSystemMetrics (OS.SM_CXHSCROLL); |
| 56 | + int buttonWidth = 17; |
| 57 | + int baseX = slider.getLocation().x + buttonWidth - 4; |
| 58 | + int baseY = slider.getLocation().y - 5; |
| 59 | + int effectiveWidth = slider.getSize().x - 3 * buttonWidth; |
| 60 | + baseX += effectiveWidth * ((float) mark) / (slider.getMaximum() - slider.getMinimum()); |
| 61 | + |
| 62 | + e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_BLACK)); |
| 63 | + e.gc.fillPolygon(new int[] { baseX, baseY, baseX + 8, baseY, (baseX + 8 / 2), baseY + 4 }); |
| 64 | + } |
| 65 | + } |
| 66 | + |
42 | 67 | private void createButtonRow() { |
43 | 68 | Composite rowParent = new Composite(this, SWT.NONE); |
44 | 69 | rowParent.setLayout(new GridLayout(5, false)); |
@@ -91,9 +116,10 @@ public void widgetSelected(SelectionEvent e) { |
91 | 116 | @Override |
92 | 117 | public void widgetSelected(SelectionEvent e) { |
93 | 118 | mark = getValue(); |
94 | | - goToMark.setEnabled(true); |
| 119 | + goToMark.setEnabled(mark>0); |
95 | 120 | goToMark.setToolTipText(MessageFormat.format("Reset to mark ({0})", display(mark))); |
96 | 121 | focusPlayButton(); |
| 122 | + redraw();//force marker update |
97 | 123 | } |
98 | 124 | }); |
99 | 125 |
|
|
0 commit comments