1
package org.herac.tuxguitar.gui.editors;
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;
11
public class TGPainter {
13
public static final int PATH_DRAW = 0x01;
15
public static final int PATH_FILL = 0x02;
17
private boolean pathEmpty;
29
public TGPainter(GC gc){
33
public TGPainter(Image image){
37
public void init(Image image){
38
this.init(new GC(image));
41
public void init(GC gc){
42
if(this.gc != null && !this.gc.isDisposed()){
48
public void initPath(int style){
50
this.path = new Path(this.gc.getDevice());
51
this.pathEmpty = true;
54
public void initPath(){
55
this.initPath( PATH_DRAW );
58
public void closePath(){
60
System.out.println("Warning: Empty Path!");
63
if( (this.style & PATH_DRAW) != 0){
64
TGPainterUtils.beforePath(this.gc);
65
this.gc.drawPath(this.path);
67
if( (this.style & PATH_FILL) != 0){
68
TGPainterUtils.beforePath(this.gc);
69
this.gc.fillPath(this.path);
73
this.pathEmpty = true;
80
public void dispose(){
84
public void setBackground(Color arg0) {
85
this.gc.setBackground(arg0);
88
public void setFont(Font arg0) {
89
this.gc.setFont(arg0);
92
public void setForeground(Color arg0) {
93
this.gc.setForeground(arg0);
96
public void setLineStyle(int arg0) {
97
this.gc.setLineStyle(arg0);
100
public void setLineWidth(int arg0) {
101
this.gc.setLineWidth(arg0);
104
public void setAlpha(int alpha) {
105
this.gc.setAlpha(alpha);
108
public void copyArea(Image image, int x, int y) {
109
this.gc.copyArea(image, x, y);
112
public Point getStringExtent(String string) {
113
TGPainterUtils.beforeString(this.gc);
114
return this.gc.stringExtent(string);
117
public void drawString(String string, int x, int y) {
118
TGPainterUtils.beforeString(this.gc);
119
this.gc.drawString(string, x, y);
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);
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);
132
public void drawImage(Image image, int x, int y) {
133
TGPainterUtils.beforeImage(this.gc);
134
this.gc.drawImage(image, x, y);
137
public void drawPolygon(int[] arg0) {
138
this.gc.drawPolygon(arg0);
141
public void fillPolygon(int[] arg0) {
142
this.gc.fillPolygon(arg0);
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;
150
public void lineTo(float arg0, float arg1) {
151
this.path.lineTo(arg0, arg1);
152
this.pathEmpty = false;
155
public void moveTo(float arg0, float arg1) {
156
this.path.moveTo(arg0, arg1);
157
this.pathEmpty = false;
160
public void addString(String arg0, float arg1, float arg2, Font arg3) {
161
this.path.addString(arg0, arg1, arg2, arg3);
162
this.pathEmpty = false;
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;
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;
175
public void addRectangle(float x,float y,float width,float height) {
176
this.path.addRectangle(x, y, width, height);
177
this.pathEmpty = false;
180
public void addRectangle(Rectangle rectangle) {
181
this.path.addRectangle(rectangle.x,rectangle.y,rectangle.width,rectangle.height);
182
this.pathEmpty = false;