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

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/editors/tab/layout/PageViewLayout.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.ArrayList;
10
 
import java.util.List;
11
 
 
12
 
import org.eclipse.swt.graphics.GC;
13
 
import org.eclipse.swt.graphics.Rectangle;
14
 
import org.herac.tuxguitar.gui.editors.tab.MeasureCoords;
15
 
import org.herac.tuxguitar.gui.editors.tab.SongTrackCoords;
16
 
import org.herac.tuxguitar.gui.editors.tab.Tablature;
17
 
import org.herac.tuxguitar.song.managers.SongManager;
18
 
 
19
 
/**
20
 
 * @author julian
21
 
 *
22
 
 * TODO To change the template for this generated type comment go to
23
 
 * Window - Preferences - Java - Code Style - Code Templates
24
 
 */
25
 
public class PageViewLayout extends ViewLayout{
26
 
    private int displayWidth;
27
 
    private int divisionCount;
28
 
    
29
 
    public PageViewLayout(Tablature tablature,SongManager songManager,boolean multitrack,boolean scoreEnabled,boolean tablatureEnabled){
30
 
        super(tablature,songManager,multitrack,scoreEnabled,tablatureEnabled);
31
 
        this.displayWidth = (getTablature().getDisplay().getBounds().width - getTablature().getVerticalBar().getSize().x);
32
 
    }
33
 
    
34
 
    public int getMode(){
35
 
        return MODE_PAGE;
36
 
    }
37
 
        
38
 
    public void paintSong(GC gc,Rectangle clientArea,int fromX,int fromY){ 
39
 
        clearTrackPositions();
40
 
        if(isMultitrack()){
41
 
            paintTracks(getTablature().getCaret().getSongCoords().getTrackCoords(),gc,clientArea,fromX,fromY);
42
 
        }else{
43
 
            List tracksCoords = new ArrayList();
44
 
            tracksCoords.add(getTablature().getCaret().getSongTrackCoords());
45
 
            paintTracks(tracksCoords,gc,clientArea,fromX,fromY);
46
 
        }
47
 
        
48
 
        paintCaret(gc);
49
 
    }
50
 
    
51
 
    public void paintTracks(List tracksCoords,GC gc,Rectangle clientArea,int fromX,int fromY) {         
52
 
        int posY = fromY + getDefaultFirstTrackSpan();
53
 
        int height = getDefaultFirstTrackSpan();
54
 
        int lineHeight = 0;     
55
 
        
56
 
        SongTrackCoords firstTrack = (SongTrackCoords)tracksCoords.get(0);
57
 
        int measureCount = firstTrack.getMeasuresCoords().size();
58
 
        int nextMeasureIndex = 0;
59
 
        while(measureCount > nextMeasureIndex){         
60
 
                TempLine line = null;                   
61
 
                for (int trackIdx = 0; trackIdx < tracksCoords.size(); trackIdx++) {
62
 
                        SongTrackCoords trackCoords = (SongTrackCoords) tracksCoords.get(trackIdx);                                             
63
 
                TrackSpacing ts = new TrackSpacing(this) ;
64
 
                ts.setSize(TrackSpacing.POSITION_SCORE_MIDDLE_LINES, ((isScoreEnabled())?( (DEFAULT_SCORE_LINE_SPAN * 5) ):0));
65
 
                                        
66
 
                        if(nextMeasureIndex == 0){
67
 
                                trackCoords.getLyricPainter().start();
68
 
                        }
69
 
                        
70
 
                        line = getTempLines(fromX,trackCoords.getMeasuresCoords(),nextMeasureIndex,ts);
71
 
                        if(AUTO_SPACING_ENABLED && isScoreEnabled()){                           
72
 
                        ts.setSize(TrackSpacing.POSITION_SCORE_UP_LINES, Math.abs(line.minY));                              
73
 
                        if(isScoreEnabled() && line.maxY + MIN_SCORE_TAB_SPAN > DEFAULT_SCORE_SPAN){
74
 
                                ts.setSize(TrackSpacing.POSITION_SCORE_DOWN_LINES, (line.maxY - (getScoreLineSpan() * 4)) );
75
 
                        }       
76
 
                        }       
77
 
                ts.setSize(TrackSpacing.POSITION_TABLATURE_TOP_SEPARATOR,(isScoreEnabled()?getMinScoreTabSpan():getStringSpan()));
78
 
                ts.setSize(TrackSpacing.POSITION_TABLATURE, ( isTablatureEnabled()?(isScoreEnabled()?trackCoords.getTabHeight() + getStringSpan() +1:trackCoords.getTabHeight() + ((getStringSpan() / 2) * 5) +1 ) :0) );
79
 
                ts.setSize(TrackSpacing.POSITION_LYRIC,10);            
80
 
                checkTopSpan(ts);
81
 
                                        
82
 
                        paintLine(trackCoords,line,gc,fromX,posY,ts,trackIdx,clientArea);
83
 
                        
84
 
                        lineHeight = ts.getSize();
85
 
                        addTrackPosition((int)trackCoords.getTrack().getNumber(),posY,lineHeight);              
86
 
                        if((line.lastIndex + 1) >=  measureCount && line.tempWith < (getMaxWidth() - 20)){                                                              
87
 
                        paintLines(trackCoords,ts,gc,(fromX + DEFAULT_HORIZONTAL_SPAN + line.tempWith + 2),posY,((getMaxWidth() - 15) - (fromX + line.tempWith)));                      
88
 
                        }                
89
 
                        
90
 
                posY += lineHeight + DEFAULT_TRACK_SPAN;
91
 
                        height += lineHeight + DEFAULT_TRACK_SPAN;
92
 
                }        
93
 
                nextMeasureIndex = line.lastIndex + 1;
94
 
        }       
95
 
        setHeight(height);
96
 
    }
97
 
    
98
 
    
99
 
    
100
 
    public void paintLine(SongTrackCoords trackCoords,TempLine line,GC gc,int fromX, int fromY,TrackSpacing ts,int trackIdx,Rectangle clientArea) {          
101
 
        int posX = (fromX + DEFAULT_HORIZONTAL_SPAN);
102
 
        int posY = fromY;
103
 
        int width = 0;
104
 
        int height = 0;        
105
 
        
106
 
        //verifico si esta en el area de cliente
107
 
        boolean isAtX = ((posX + fromX) > clientArea.x - 1500 && (posX + fromX) < clientArea.x + clientArea.width + 100);
108
 
        boolean isAtY = (posY + ts.getSize() > clientArea.y && posY < clientArea.y + clientArea.height + 80);
109
 
 
110
 
        int measureSpan = 0;
111
 
        if(line.fullLine){
112
 
                int diff = ( getMaxWidth() - line.tempWith);
113
 
                if(diff != 0 && line.measures.size() > 0){
114
 
                        measureSpan = diff / line.measures.size();                    
115
 
                }
116
 
        }
117
 
            
118
 
        for(int i = 0;i < line.measures.size();i ++){
119
 
                int index = ((Integer)line.measures.get(i)).intValue();
120
 
            MeasureCoords currMeasureCoords = (MeasureCoords)trackCoords.getMeasuresCoords().get(index);
121
 
                    
122
 
            //asigno la posicion dentro del compas
123
 
            currMeasureCoords.setPosX(posX);
124
 
            currMeasureCoords.setPosY(posY);              
125
 
            currMeasureCoords.setTs(ts);
126
 
 
127
 
            trackCoords.getLyricPainter().setCurrentMeasure(currMeasureCoords);
128
 
            
129
 
            currMeasureCoords.setFirstOfLine(i == 0);
130
 
                
131
 
            if(isAtX && isAtY){
132
 
                paintMeasure(currMeasureCoords,gc,posX, posY,measureSpan,clientArea);
133
 
                trackCoords.getLyricPainter().paintCurrentNoteBeats(gc,this,currMeasureCoords,posX, posY);
134
 
            }else{
135
 
                currMeasureCoords.setOutOfBounds(true);
136
 
            }                    
137
 
            posX += currMeasureCoords.getWidth() + currMeasureCoords.getSpan();
138
 
            
139
 
            if(posX > width){
140
 
                width = posX;                
141
 
            }                                                        
142
 
        }                
143
 
        setWidth((width > getWidth())?width:getWidth());
144
 
    }          
145
 
   
146
 
    
147
 
    public TempLine getTempLines(int posX,List measuresCoords,int fromIndex,TrackSpacing ts) {          
148
 
        TempLine line = new TempLine();
149
 
        this.divisionCount = 1;                         
150
 
        for (int measureIdx = fromIndex; measureIdx < measuresCoords.size(); measureIdx++) {                            
151
 
            MeasureCoords measureCoords = (MeasureCoords) measuresCoords.get(measureIdx);                                            
152
 
 
153
 
            //verifico si tengo que bajar de linea
154
 
            if((line.tempWith + measureCoords.getWidth()) >=  getMaxWidth() && !line.measures.isEmpty()){
155
 
                line.fullLine = true;
156
 
                return line;
157
 
            }
158
 
            line.tempWith +=  measureCoords.getWidth();
159
 
            line.maxY = (measureCoords.getMaxY() > line.maxY)?measureCoords.getMaxY():line.maxY;
160
 
            line.minY = (measureCoords.getMinY() < line.minY)?measureCoords.getMinY():line.minY;                
161
 
            
162
 
            line.addMeasure(measureIdx);
163
 
            measureCoords.registerEffects(ts);
164
 
        }        
165
 
       
166
 
        return line;
167
 
    }    
168
 
 
169
 
    public boolean followMeasure(MeasureCoords measure,boolean redraw){
170
 
        return getTablature().moveScrollVerticalTo(measure,getDefaultFirstTrackSpan(),redraw);
171
 
    }       
172
 
 
173
 
    public int getMaxWidth(){
174
 
        return (displayWidth - (DEFAULT_HORIZONTAL_SPAN * 2));
175
 
    }
176
 
        
177
 
    private class TempLine{     
178
 
        private int tempWith;           
179
 
        private int lastIndex;
180
 
        private int startBeat;
181
 
        private boolean fullLine;
182
 
        private List measures = new ArrayList();
183
 
        
184
 
        private int maxY = 0;
185
 
        private int minY = 0;
186
 
        
187
 
        private void addMeasure(int index){
188
 
                this.measures.add(new Integer(index));
189
 
                this.lastIndex = index;
190
 
        }
191
 
    }
192
 
    
193
 
}