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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/editors/TGPainter.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;
 
2
 
 
3
import org.eclipse.swt.graphics.Color;
 
4
import org.eclipse.swt.graphics.Font;
 
5
import org.eclipse.swt.graphics.GC;
 
6
import org.eclipse.swt.graphics.Image;
 
7
import org.eclipse.swt.graphics.Path;
 
8
import org.eclipse.swt.graphics.Point;
 
9
import org.eclipse.swt.graphics.Rectangle;
 
10
 
 
11
public class TGPainter {
 
12
        
 
13
        public static final int PATH_DRAW = 0x01;
 
14
        
 
15
        public static final int PATH_FILL = 0x02;
 
16
        
 
17
        private boolean pathEmpty;
 
18
        
 
19
        private int style;
 
20
        
 
21
        private GC gc;
 
22
        
 
23
        private Path path;
 
24
        
 
25
        public TGPainter(){
 
26
                super();
 
27
        }
 
28
        
 
29
        public TGPainter(GC gc){
 
30
                this.init(gc);
 
31
        }
 
32
        
 
33
        public TGPainter(Image image){
 
34
                this.init(image);
 
35
        }
 
36
        
 
37
        public void init(Image image){
 
38
                this.init(new GC(image));
 
39
        }
 
40
        
 
41
        public void init(GC gc){
 
42
                if(this.gc != null && !this.gc.isDisposed()){
 
43
                        this.gc.dispose();
 
44
                }
 
45
                this.gc = gc;
 
46
        }
 
47
        
 
48
        public void initPath(int style){
 
49
                this.style = style;
 
50
                this.path = new Path(this.gc.getDevice());
 
51
                this.pathEmpty = true;
 
52
        }
 
53
        
 
54
        public void initPath(){
 
55
                this.initPath( PATH_DRAW );
 
56
        }
 
57
        
 
58
        public void closePath(){
 
59
                if(this.pathEmpty){
 
60
                        System.out.println("Warning: Empty Path!");
 
61
                }
 
62
                
 
63
                if( (this.style & PATH_DRAW) != 0){
 
64
                        TGPainterUtils.beforePath(this.gc);
 
65
                        this.gc.drawPath(this.path);
 
66
                }
 
67
                if( (this.style & PATH_FILL) != 0){
 
68
                        TGPainterUtils.beforePath(this.gc);
 
69
                        this.gc.fillPath(this.path);
 
70
                }
 
71
                this.style = 0;
 
72
                this.path.dispose();
 
73
                this.pathEmpty = true;
 
74
        }
 
75
        
 
76
        public GC getGC(){
 
77
                return this.gc;
 
78
        }
 
79
        
 
80
        public void dispose(){
 
81
                this.gc.dispose();
 
82
        }
 
83
        
 
84
        public void setBackground(Color arg0) {
 
85
                this.gc.setBackground(arg0);
 
86
        }
 
87
        
 
88
        public void setFont(Font arg0) {
 
89
                this.gc.setFont(arg0);
 
90
        }
 
91
        
 
92
        public void setForeground(Color arg0) {
 
93
                this.gc.setForeground(arg0);
 
94
        }
 
95
        
 
96
        public void setLineStyle(int arg0) {
 
97
                this.gc.setLineStyle(arg0);
 
98
        }
 
99
        
 
100
        public void setLineWidth(int arg0) {
 
101
                this.gc.setLineWidth(arg0);
 
102
        }
 
103
        
 
104
        public void setAlpha(int alpha) {
 
105
                this.gc.setAlpha(alpha);
 
106
        }
 
107
        
 
108
        public void copyArea(Image image, int x, int y) {
 
109
                this.gc.copyArea(image, x, y);
 
110
        }
 
111
        
 
112
        public Point getStringExtent(String string) {
 
113
                TGPainterUtils.beforeString(this.gc);
 
114
                return this.gc.stringExtent(string);
 
115
        }
 
116
        
 
117
        public void drawString(String string, int x, int y) {
 
118
                TGPainterUtils.beforeString(this.gc);
 
119
                this.gc.drawString(string, x, y);
 
120
        }
 
121
        
 
122
        public void drawString(String string, int x, int y, boolean isTransparent) {
 
123
                TGPainterUtils.beforeString(this.gc);
 
124
                this.gc.drawString(string, x, y, isTransparent);
 
125
        }
 
126
        
 
127
        public void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) {
 
128
                TGPainterUtils.beforeImage(this.gc);
 
129
                this.gc.drawImage(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight);
 
130
        }
 
131
        
 
132
        public void drawImage(Image image, int x, int y) {
 
133
                TGPainterUtils.beforeImage(this.gc);
 
134
                this.gc.drawImage(image, x, y);
 
135
        }
 
136
        
 
137
        public void drawPolygon(int[] arg0) {
 
138
                this.gc.drawPolygon(arg0);
 
139
        }
 
140
        
 
141
        public void fillPolygon(int[] arg0) {
 
142
                this.gc.fillPolygon(arg0);
 
143
        }
 
144
        
 
145
        public void cubicTo(float arg0, float arg1, float arg2, float arg3, float arg4, float arg5) {
 
146
                this.path.cubicTo(arg0, arg1, arg2, arg3, arg4, arg5);
 
147
                this.pathEmpty = false;
 
148
        }
 
149
        
 
150
        public void lineTo(float arg0, float arg1) {
 
151
                this.path.lineTo(arg0, arg1);
 
152
                this.pathEmpty = false;
 
153
        }
 
154
        
 
155
        public void moveTo(float arg0, float arg1) {
 
156
                this.path.moveTo(arg0, arg1);
 
157
                this.pathEmpty = false;
 
158
        }
 
159
        
 
160
        public void addString(String arg0, float arg1, float arg2, Font arg3) {
 
161
                this.path.addString(arg0, arg1, arg2, arg3);
 
162
                this.pathEmpty = false;
 
163
        }
 
164
        
 
165
        public void addArc(float arg0, float arg1, float arg2, float arg3, float arg4, float arg5) {
 
166
                this.path.addArc(arg0, arg1, arg2, arg3, arg4, arg5);
 
167
                this.pathEmpty = false;
 
168
        }
 
169
        
 
170
        public void addOval(float arg0, float arg1, float arg2, float arg3) {
 
171
                this.path.addArc(arg0, arg1, arg2, arg3, 0, 360);
 
172
                this.pathEmpty = false;
 
173
        }
 
174
        
 
175
        public void addRectangle(float x,float y,float width,float height) {
 
176
                this.path.addRectangle(x, y, width, height);
 
177
                this.pathEmpty = false;
 
178
        }
 
179
        
 
180
        public void addRectangle(Rectangle rectangle) {
 
181
                this.path.addRectangle(rectangle.x,rectangle.y,rectangle.width,rectangle.height);
 
182
                this.pathEmpty = false;
 
183
        }
 
184
}