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

« back to all changes in this revision

Viewing changes to 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.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 LinearViewLayout extends ViewLayout{
26
 
 
27
 
    public LinearViewLayout(Tablature tablature,SongManager songManager,boolean multitrack,boolean scoreEnabled,boolean tablatureEnabled){
28
 
        super(tablature,songManager,multitrack,scoreEnabled,tablatureEnabled);
29
 
    }
30
 
    
31
 
    public int getMode(){
32
 
        return MODE_LINEAR;
33
 
    }
34
 
    
35
 
    public void paintSong(GC gc,Rectangle clientArea,int fromX,int fromY){  
36
 
        clearTrackPositions();
37
 
        if(isMultitrack()){
38
 
            paintTracks(getTablature().getCaret().getSongCoords().getTrackCoords(),gc,clientArea,fromX,fromY);
39
 
        }else{
40
 
            List tracksCoords = new ArrayList();
41
 
            tracksCoords.add(getTablature().getCaret().getSongTrackCoords());
42
 
            paintTracks(tracksCoords,gc,clientArea,fromX,fromY);
43
 
        }        
44
 
        paintCaret(gc);
45
 
    }
46
 
    
47
 
    public void paintTracks(List tracksCoords,GC gc,Rectangle clientArea,int fromX,int fromY) {               
48
 
        int posY = fromY + getDefaultFirstTrackSpan();        
49
 
        int height = getDefaultFirstTrackSpan();   
50
 
        int trackHeight;
51
 
        for (int trackIdx = 0; trackIdx < tracksCoords.size(); trackIdx++) {
52
 
            SongTrackCoords trackCoords = (SongTrackCoords) tracksCoords.get(trackIdx);            
53
 
            TrackSpacing ts = new TrackSpacing(this) ;
54
 
            ts.setSize(TrackSpacing.POSITION_SCORE_MIDDLE_LINES, ((isScoreEnabled())?( (DEFAULT_SCORE_LINE_SPAN * 5) ):0));            
55
 
            trackCoords.getLyricPainter().start();
56
 
            
57
 
            //------AUTO_SPACING---------------------------------------
58
 
            if(AUTO_SPACING_ENABLED){
59
 
                int maxY = 0;
60
 
                int minY = 0;
61
 
                for(int i = 0;i < trackCoords.getMeasuresCoords().size();i++){
62
 
                        MeasureCoords measure = (MeasureCoords)trackCoords.getMeasuresCoords().get(i);
63
 
                        maxY = (measure.getMaxY() > maxY)?measure.getMaxY():maxY;
64
 
                        minY = (measure.getMinY() < minY)?measure.getMinY():minY;
65
 
                        measure.registerEffects(ts);
66
 
                }               
67
 
                ts.setSize(TrackSpacing.POSITION_SCORE_UP_LINES, ((isScoreEnabled())?Math.abs(minY):0));                                
68
 
                if(isScoreEnabled() && maxY + MIN_SCORE_TAB_SPAN > DEFAULT_SCORE_SPAN){
69
 
                        ts.setSize(TrackSpacing.POSITION_SCORE_DOWN_LINES, (maxY - (getScoreLineSpan() * 4)) );
70
 
                }               
71
 
                        }                        
72
 
            ts.setSize(TrackSpacing.POSITION_TABLATURE_TOP_SEPARATOR,(isScoreEnabled()?getMinScoreTabSpan():getStringSpan()));
73
 
            ts.setSize(TrackSpacing.POSITION_TABLATURE, ( isTablatureEnabled()?(isScoreEnabled()?trackCoords.getTabHeight() + getStringSpan() +1:trackCoords.getTabHeight() + ((getStringSpan() / 2) * 5) +1 ) :0) );
74
 
            ts.setSize(TrackSpacing.POSITION_LYRIC,10);                        
75
 
                checkTopSpan(ts);
76
 
            
77
 
            //----------------------------------------------------                                
78
 
            paintMeasures(trackCoords,trackCoords.getMeasuresCoords(),gc,fromX,posY,ts,clientArea);            
79
 
            paintLines(trackCoords,ts,gc,fromX + (getWidth() + 2),posY,(clientArea.width - (fromX + getWidth()) ));
80
 
           
81
 
            trackHeight = ts.getSize();
82
 
            addTrackPosition((int)trackCoords.getTrack().getNumber(),posY,trackHeight);            
83
 
            
84
 
            posY += trackHeight + DEFAULT_TRACK_SPAN;
85
 
                        height += trackHeight + DEFAULT_TRACK_SPAN;    
86
 
        }                  
87
 
        setHeight(height);        
88
 
    }
89
 
  
90
 
    public void paintMeasures(SongTrackCoords trackCoords,List measuresCoords,GC gc,int fromX, int fromY,TrackSpacing ts,Rectangle clientArea) {        
91
 
        int posX = (fromX + DEFAULT_HORIZONTAL_SPAN);
92
 
        int posY = fromY;
93
 
        
94
 
        for (int measureIdx = 0; measureIdx < measuresCoords.size(); measureIdx++) {            
95
 
            MeasureCoords measureCoords = (MeasureCoords) measuresCoords.get(measureIdx);            
96
 
                      
97
 
            //asigno la posicion dentro del compas
98
 
            measureCoords.setPosX(posX);
99
 
            measureCoords.setPosY(posY);            
100
 
            measureCoords.setTs(ts);
101
 
            
102
 
            trackCoords.getLyricPainter().setCurrentMeasure(measureCoords);
103
 
            
104
 
            //Solo pinto lo que entre en pantalla  
105
 
            boolean isAtX = ((posX + measureCoords.getWidth()) > clientArea.x - 100 && posX < clientArea.x + clientArea.width + measureCoords.getWidth() + 100);
106
 
            boolean isAtY = (posY + ts.getSize() > clientArea.y && posY < clientArea.y + clientArea.height + 80);
107
 
            if(isAtX && isAtY){
108
 
                paintMeasure(measureCoords,gc,posX, posY,0,clientArea);
109
 
                trackCoords.getLyricPainter().paintCurrentNoteBeats(gc,this,measureCoords,posX, posY);
110
 
            }else{
111
 
                measureCoords.setOutOfBounds(true);
112
 
            } 
113
 
            posX += measureCoords.getWidth();       
114
 
        }
115
 
        setWidth(posX + (-fromX));
116
 
    }
117
 
    
118
 
    public boolean followMeasure(MeasureCoords measure,boolean redraw){
119
 
        return getTablature().moveScrollHorizontalTo(measure,DEFAULT_HORIZONTAL_SPAN,redraw);
120
 
    }   
121
 
}