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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/editors/tab/layout/LinearViewLayout.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
/*
 
2
 * Created on 04-ene-2006
 
3
 *
 
4
 * TODO To change the template for this generated file go to
 
5
 * Window - Preferences - Java - Code Style - Code Templates
 
6
 */
 
7
package org.herac.tuxguitar.gui.editors.tab.layout;
 
8
 
 
9
import java.util.Iterator;
 
10
 
 
11
import org.eclipse.swt.graphics.Rectangle;
 
12
import org.herac.tuxguitar.gui.editors.TGPainter;
 
13
import org.herac.tuxguitar.gui.editors.tab.TGLyricImpl;
 
14
import org.herac.tuxguitar.gui.editors.tab.TGMeasureImpl;
 
15
import org.herac.tuxguitar.gui.editors.tab.TGTrackImpl;
 
16
import org.herac.tuxguitar.gui.editors.tab.Tablature;
 
17
 
 
18
/**
 
19
 * @author julian
 
20
 *
 
21
 * TODO To change the template for this generated type comment go to
 
22
 * Window - Preferences - Java - Code Style - Code Templates
 
23
 */
 
24
public class LinearViewLayout extends ViewLayout{
 
25
        
 
26
        public LinearViewLayout(Tablature tablature,int style){
 
27
                super(tablature,style);
 
28
        }
 
29
        
 
30
        public int getMode(){
 
31
                return MODE_LINEAR;
 
32
        }
 
33
        
 
34
        public void paintSong(TGPainter painter,Rectangle clientArea,int fromX,int fromY) {
 
35
                this.setWidth(0);
 
36
                this.setHeight(0);
 
37
                this.clearTrackPositions();
 
38
                
 
39
                int style = getStyle();
 
40
                int number = ((style & ViewLayout.DISPLAY_MULTITRACK) == 0?getTablature().getCaret().getTrack().getNumber():-1);
 
41
                int posY = fromY + getFirstTrackSpacing();
 
42
                int height = getFirstTrackSpacing();
 
43
                int trackHeight;
 
44
                Iterator tracks = getSongManager().getSong().getTracks();
 
45
                while(tracks.hasNext()){
 
46
                        TGTrackImpl track = (TGTrackImpl) tracks.next();
 
47
                        if(number < 0 || track.getNumber() == number){
 
48
                                
 
49
                                TrackSpacing ts = new TrackSpacing(this) ;
 
50
                                ts.setSize(TrackSpacing.POSITION_SCORE_MIDDLE_LINES, ((style & DISPLAY_SCORE) != 0 ?( (getScoreLineSpacing() * 5) ):0));
 
51
                                ((TGLyricImpl)track.getLyrics()).start();
 
52
                                
 
53
                                //------AUTO_SPACING---------------------------------------
 
54
                                int maxY = 0;
 
55
                                int minY = 0;
 
56
                                // Need to score extra-lines in edition mode
 
57
                                if( (style & DISPLAY_TABLATURE) == 0 && (style & DISPLAY_SCORE) != 0 ){
 
58
                                        maxY = ((getScoreLineSpacing() * 4) + (getScoreLineSpacing() * 4));
 
59
                                        minY = -(getScoreLineSpacing() * 3);
 
60
                                }
 
61
                                
 
62
                                Iterator measures = track.getMeasures();
 
63
                                while(measures.hasNext()){
 
64
                                        TGMeasureImpl measure = (TGMeasureImpl)measures.next();
 
65
                                        maxY = (measure.getMaxY() > maxY)?measure.getMaxY():maxY;
 
66
                                        minY = (measure.getMinY() < minY)?measure.getMinY():minY;
 
67
                                        measure.registerEffects(this,ts);
 
68
                                }
 
69
                                ts.setSize(TrackSpacing.POSITION_SCORE_UP_LINES, ( (style & DISPLAY_SCORE) != 0 ?Math.abs(minY):0));
 
70
                                if((style & DISPLAY_SCORE) != 0 && maxY + getMinScoreTabSpacing() > getScoreSpacing()){
 
71
                                        ts.setSize(TrackSpacing.POSITION_SCORE_DOWN_LINES, (maxY - (getScoreLineSpacing() * 4)) );
 
72
                                }
 
73
                                
 
74
                                if((style & DISPLAY_TABLATURE) != 0){
 
75
                                        ts.setSize(TrackSpacing.POSITION_TABLATURE_TOP_SEPARATOR,((style & DISPLAY_SCORE) != 0 ?getMinScoreTabSpacing():getStringSpacing()));
 
76
                                        ts.setSize(TrackSpacing.POSITION_TABLATURE, ((style & DISPLAY_SCORE) != 0 ?track.getTabHeight() + getStringSpacing() +1:track.getTabHeight() + ((getStringSpacing() / 2) * 5) +1 ) );
 
77
                                }
 
78
                                ts.setSize(TrackSpacing.POSITION_LYRIC,10);
 
79
                                checkDefaultSpacing(ts);
 
80
                                
 
81
                                //----------------------------------------------------
 
82
                                paintMeasures(track,painter,fromX,posY,ts,clientArea);
 
83
                                paintLines(track,ts,painter,fromX + (getWidth() + 2),posY,(clientArea.width - (fromX + getWidth()) ));
 
84
                                
 
85
                                trackHeight = ts.getSize();
 
86
                                addTrackPosition(track.getNumber(),posY,trackHeight);
 
87
                                
 
88
                                posY += trackHeight + getTrackSpacing();
 
89
                                height += trackHeight + getTrackSpacing();
 
90
                        }
 
91
                }
 
92
                if(getWidth() > clientArea.width){
 
93
                        // solo para dar un espacio.
 
94
                        this.setWidth( getWidth() + getFirstMeasureSpacing());
 
95
                }
 
96
                this.setHeight(height);
 
97
                this.paintCaret(painter);
 
98
        }
 
99
        
 
100
        public void paintMeasures(TGTrackImpl track,TGPainter painter,int fromX, int fromY,TrackSpacing ts,Rectangle clientArea) {
 
101
                int posX = (fromX + getFirstMeasureSpacing());
 
102
                int posY = fromY;
 
103
                int width = getFirstMeasureSpacing();
 
104
                
 
105
                Iterator measures = track.getMeasures();
 
106
                while(measures.hasNext()){
 
107
                        TGMeasureImpl measure = (TGMeasureImpl)measures.next();
 
108
                        
 
109
                        //asigno la posicion dentro del compas
 
110
                        measure.setPosX(posX);
 
111
                        measure.setPosY(posY);
 
112
                        measure.setTs(ts);
 
113
                        
 
114
                        ((TGLyricImpl)track.getLyrics()).setCurrentMeasure(measure);
 
115
                        
 
116
                        //Solo pinto lo que entre en pantalla
 
117
                        boolean isAtX = ((posX + measure.getWidth(this)) > clientArea.x - 100 && posX < clientArea.x + clientArea.width + measure.getWidth(this) + 100);
 
118
                        boolean isAtY = (posY + ts.getSize() > clientArea.y && posY < clientArea.y + clientArea.height + 80);
 
119
                        if(isAtX && isAtY){
 
120
                                paintMeasure(measure,painter,0);
 
121
                                ((TGLyricImpl)track.getLyrics()).paintCurrentNoteBeats(painter,this,measure,posX, posY);
 
122
                        }else{
 
123
                                measure.setOutOfBounds(true);
 
124
                        }
 
125
                        
 
126
                        int measureWidth = measure.getWidth(this);
 
127
                        posX += measureWidth;
 
128
                        width += measureWidth;
 
129
                }
 
130
                this.setWidth(Math.max(getWidth(),width));
 
131
        }
 
132
}