~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/table/TGTableCanvasPainter.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.herac.tuxguitar.gui.table;
 
2
 
 
3
import org.eclipse.swt.SWT;
 
4
import org.eclipse.swt.events.PaintEvent;
 
5
import org.eclipse.swt.events.PaintListener;
 
6
import org.eclipse.swt.graphics.Color;
 
7
import org.herac.tuxguitar.gui.TuxGuitar;
 
8
import org.herac.tuxguitar.gui.editors.TGPainter;
 
9
import org.herac.tuxguitar.gui.editors.tab.TGMeasureImpl;
 
10
import org.herac.tuxguitar.song.models.TGTrack;
 
11
 
 
12
public class TGTableCanvasPainter implements PaintListener{
 
13
        
 
14
        private TGTableViewer viewer;
 
15
        private TGTrack track;
 
16
        
 
17
        public TGTableCanvasPainter(TGTableViewer viewer,TGTrack track){
 
18
                this.viewer = viewer;
 
19
                this.track = track;
 
20
        }
 
21
        
 
22
        public void paintControl(PaintEvent e) {
 
23
                TGPainter painter = new TGPainter(e.gc);
 
24
                paintTrack(painter);
 
25
        }
 
26
        
 
27
        protected void paintTrack(TGPainter painter){
 
28
                if(!TuxGuitar.instance().isLocked()){
 
29
                        TuxGuitar.instance().lock();
 
30
                        
 
31
                        int x = -this.viewer.getHScrollSelection();
 
32
                        int y = 0;
 
33
                        int size = this.viewer.getTable().getRowHeight();
 
34
                        int width = painter.getGC().getDevice().getBounds().width;
 
35
                        boolean playing = TuxGuitar.instance().getPlayer().isRunning();
 
36
                        
 
37
                        painter.setBackground(painter.getGC().getDevice().getSystemColor(SWT.COLOR_GRAY));
 
38
                        painter.initPath(TGPainter.PATH_FILL);
 
39
                        painter.addRectangle(0,y,width,size);
 
40
                        painter.closePath();
 
41
                        
 
42
                        Color trackColor = new Color(painter.getGC().getDevice(),this.track.getColor().getR(),this.track.getColor().getG(),this.track.getColor().getB());
 
43
                        painter.setBackground(trackColor);
 
44
                        painter.setForeground(trackColor);
 
45
                        
 
46
                        int count = this.track.countMeasures();
 
47
                        for(int j = 0;j < count;j++){
 
48
                                TGMeasureImpl measure = (TGMeasureImpl)this.track.getMeasure(j);
 
49
                                if(isRestMeasure(measure)){
 
50
                                        painter.initPath();
 
51
                                        painter.addRectangle(x,y,size - 2,size - 1);
 
52
                                        painter.closePath();
 
53
                                }else{
 
54
                                        painter.initPath(TGPainter.PATH_FILL);
 
55
                                        painter.addRectangle(x,y,size - 1,size );
 
56
                                        painter.closePath();
 
57
                                }
 
58
                                boolean hasCaret = TuxGuitar.instance().getTablatureEditor().getTablature().getCaret().getMeasure().equals(measure);
 
59
                                if((playing && measure.isPlaying(this.viewer.getEditor().getTablature().getViewLayout())) || (!playing && hasCaret)){
 
60
                                        painter.setBackground(painter.getGC().getDevice().getSystemColor(SWT.COLOR_BLACK));
 
61
                                        painter.initPath(TGPainter.PATH_FILL);
 
62
                                        painter.addRectangle(x + 4,y + 4,size - 9,size - 8);
 
63
                                        painter.closePath();
 
64
                                        painter.setBackground(trackColor);
 
65
                                }
 
66
                                x += size;
 
67
                        }
 
68
                        trackColor.dispose();
 
69
                        
 
70
                        TuxGuitar.instance().unlock();
 
71
                }
 
72
        }
 
73
        
 
74
        private boolean isRestMeasure(TGMeasureImpl measure){
 
75
                int beatCount = measure.countBeats();
 
76
                for(int i = 0; i < beatCount; i++){
 
77
                        if( !measure.getBeat(i).isRestBeat() ){
 
78
                                return false;
 
79
                        }
 
80
                }
 
81
                return true;
 
82
        }
 
83
        
 
84
}