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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/editors/tab/TGLyricImpl.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.editors.tab;
 
2
 
 
3
import org.herac.tuxguitar.gui.editors.TGPainter;
 
4
import org.herac.tuxguitar.gui.editors.tab.layout.TrackSpacing;
 
5
import org.herac.tuxguitar.gui.editors.tab.layout.ViewLayout;
 
6
import org.herac.tuxguitar.song.models.TGLyric;
 
7
 
 
8
public class TGLyricImpl extends TGLyric{
 
9
        
 
10
        private int height;
 
11
        private int nextIndex = 0;
 
12
        
 
13
        public TGLyricImpl(){
 
14
                this.height = 0;
 
15
        }
 
16
        
 
17
        public void setFrom(int from) {
 
18
                super.setFrom(from);
 
19
                this.update();
 
20
        }
 
21
        
 
22
        public void setLyrics(String lyrics) {
 
23
                super.setLyrics(lyrics);
 
24
                this.update();
 
25
        }
 
26
        
 
27
        private void update(){
 
28
                this.height = (this.isEmpty()?0:10);
 
29
        }
 
30
        
 
31
        public void start(){
 
32
                this.start(0);
 
33
        }
 
34
        
 
35
        public void start(int index){
 
36
                this.nextIndex = index;
 
37
        }
 
38
        
 
39
        public void setCurrentMeasure(TGMeasureImpl measure){
 
40
                if(measure.getNumber() >= getFrom()){
 
41
                        measure.setLyricBeatIndex(this.nextIndex);
 
42
                        this.nextIndex += (measure.getNotEmptyBeats());
 
43
                }else{
 
44
                        measure.setLyricBeatIndex(-1);
 
45
                        this.start();
 
46
                }
 
47
        }
 
48
        
 
49
        public void paintCurrentNoteBeats(TGPainter painter,ViewLayout layout,TGMeasureImpl currentMeasure ,int fromX,int fromY){
 
50
                int from = currentMeasure.getLyricBeatIndex();
 
51
                String[] beats = getLyricBeats();
 
52
                if(beats != null && from >= 0 && from < beats.length){
 
53
                        int beatIndex = 0;
 
54
                        for(int i = 0;i < currentMeasure.countBeats();i ++){
 
55
                                TGBeatImpl beat = (TGBeatImpl)currentMeasure.getBeat(i);
 
56
                                if(!beat.isRestBeat()){
 
57
                                        if((from + beatIndex) < beats.length){
 
58
                                                String str = beats[from + beatIndex].trim();
 
59
                                                if(str.length() > 0){
 
60
                                                        int x = (fromX + beat.getPosX() + beat.getSpacing() + 2);
 
61
                                                        layout.setLyricStyle(painter,(layout.isPlayModeEnabled() && beat.isPlaying(layout)));
 
62
                                                        painter.drawString(str,x + 13,(fromY + currentMeasure.getTs().getPosition(TrackSpacing.POSITION_LYRIC)));
 
63
                                                }
 
64
                                        }
 
65
                                        beatIndex ++;
 
66
                                }
 
67
                        }
 
68
                }
 
69
        }
 
70
        
 
71
        public int getHeight(){
 
72
                return this.height;
 
73
        }
 
74
}