1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16: http://www.gnu.org/licenses/.
17: http://java-gnome.sourceforge.net/.
18:
19: package cairo;
20:
21: import org.freedesktop.cairo.Context;
22: import org.freedesktop.cairo.LinearPattern;
23: import org.freedesktop.cairo.Pattern;
24: import org.freedesktop.cairo.RadialPattern;
25: import org.gnome.gdk.Event;
26: import org.gnome.gdk.EventExpose;
27: import org.gnome.gdk.Rectangle;
28: import org.gnome.gtk.DrawingArea;
29: import org.gnome.gtk.Gtk;
30: import org.gnome.gtk.Widget;
31: import org.gnome.gtk.Window;
32:
33: /**
34: * Exercise drawing with the Cairo API. If you are rendering a custom Widget
35: * or otherwise drawing stuff with Cairo that is to be presented by GTK, you
36: * are expected to do this in the Widget.ExposeEvent handler for that Widget.
37: *
38: * @author
39: * @author
40: */
41:
42: TODO
43:
44:
45:
46:
47: public class ExampleDrawingInExposeEvent
48: {
49: public static void main(String[] args) {
50: final Window w;
51: final DrawingArea d;
52:
53: Gtk.init(args);
54:
55: w = new Window();
56: w.setTitle("Expose");
57: w.setDefaultSize(150, 150);
58:
59: d = new DrawingArea();
60: w.add(d);
61: w.showAll();
62:
63: d.connect(new Widget.ExposeEvent() {
64: public boolean onExposeEvent(Widget source, EventExpose event) {
65: final Context cr;
66: final Rectangle rect;
67: final Pattern linear, radial;
68:
69:
70:
71:
72:
73: rect = event.getArea();
74: System.out.println("Widget.ExposeEvent bounded by " + rect.getWidth() + "x"
75: + rect.getHeight() + " at " + rect.getX() + "," + rect.getY());
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87: cr = new Context(event);
88:
89:
90:
91:
92:
93: cr.setSource(1.0, 0.1, 0.0, 1.0);
94: cr.moveTo(10, 40);
95: cr.lineTo(120, 145);
96: cr.stroke();
97:
98:
99:
100:
101:
102:
103:
104: cr.setSource(225 / 255.0, 148 / 255.0, 11 / 255.0, 1.0);
105: cr.rectangle(70, 70, 20, 40);
106: cr.fill();
107:
108:
109:
110:
111:
112:
113: linear = new LinearPattern(0, 0, 150, 150);
114: linear.addColorStopRGB(0.0, 0.0, 0.3, 0.8);
115: linear.addColorStopRGB(1.0, 0.0, 0.8, 0.3);
116:
117: radial = new RadialPattern(75, 75, 15, 75, 75, 60);
118: radial.addColorStopRGBA(0, 0.0, 0.0, 0.0, 0.0);
119: radial.addColorStopRGBA(1, 0.0, 0.0, 0.0, 1.0);
120:
121: cr.setSource(linear);
122: cr.mask(radial);
123:
124: return true;
125: }
126: });
127:
128:
129:
130:
131:
132:
133: w.connect(new Window.DeleteEvent() {
134: public boolean onDeleteEvent(Widget source, Event event) {
135: Gtk.mainQuit();
136: return false;
137: }
138: });
139:
140: Gtk.main();
141: }
142: }
143: