OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [gnu/] [java/] [awt/] [peer/] [gtk/] [GdkGraphics.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* GdkGraphics.java
2
   Copyright (C) 1998, 1999, 2002, 2005  Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
 
39
package gnu.java.awt.peer.gtk;
40
 
41
import gnu.classpath.Configuration;
42
 
43
import java.awt.Color;
44
import java.awt.Dimension;
45
import java.awt.Font;
46
import java.awt.FontMetrics;
47
import java.awt.Graphics;
48
import java.awt.Image;
49
import java.awt.Rectangle;
50
import java.awt.Shape;
51
import java.awt.SystemColor;
52
import java.awt.image.ImageObserver;
53
import java.text.AttributedCharacterIterator;
54
 
55
public class GdkGraphics extends Graphics
56
{
57
  static
58
  {
59
    if (Configuration.INIT_LOAD_LIBRARY)
60
      {
61
        System.loadLibrary("gtkpeer");
62
      }
63
    initStaticState ();
64
  }
65
 
66
  static native void initStaticState();
67
  private final int native_state = GtkGenericPeer.getUniqueInteger ();
68
 
69
  Color color, xorColor;
70
  GtkComponentPeer component;
71
  Font font = new Font ("Dialog", Font.PLAIN, 12);
72
  Rectangle clip;
73
  GtkImage image;
74
 
75
  int xOffset = 0;
76
  int yOffset = 0;
77
 
78
  static final int GDK_COPY = 0, GDK_XOR = 2;
79
 
80
  native void initState (GtkComponentPeer component);
81
  native void initStateUnlocked (GtkComponentPeer component);
82
  native void initState (int width, int height);
83
  native void initFromImage (GtkImage image);
84
  native void copyState (GdkGraphics g);
85
 
86
  GdkGraphics (GdkGraphics g)
87
  {
88
    color = g.color;
89
    xorColor = g.xorColor;
90
    font = g.font;
91
    if (font == null)
92
      font = new Font ("Dialog", Font.PLAIN, 12);
93
    clip = new Rectangle (g.clip);
94
    component = g.component;
95
 
96
    copyState (g);
97
  }
98
 
99
  GdkGraphics (int width, int height)
100
  {
101
    initState (width, height);
102
    color = Color.black;
103
    clip = new Rectangle (0, 0, width, height);
104
    font = new Font ("Dialog", Font.PLAIN, 12);
105
  }
106
 
107
  GdkGraphics (GtkImage image)
108
  {
109
    this.image = image;
110
    initFromImage (image);
111
    color = Color.black;
112
    clip = new Rectangle (0, 0,
113
                          image.getWidth(null), image.getHeight(null));
114
    font = new Font ("Dialog", Font.PLAIN, 12);
115
  }
116
 
117
  GdkGraphics (GtkComponentPeer component)
118
  {
119
    this.component = component;
120
    color = Color.black;
121
 
122
    if (component.isRealized ())
123
      initComponentGraphics ();
124
    else
125
      connectSignals (component);
126
  }
127
 
128
  void initComponentGraphics ()
129
  {
130
    initState (component);
131
    color = component.awtComponent.getForeground ();
132
    if (color == null)
133
      color = Color.BLACK;
134
    Dimension d = component.awtComponent.getSize ();
135
    clip = new Rectangle (0, 0, d.width, d.height);
136
  }
137
 
138
  // called back by native side: realize_cb
139
  void initComponentGraphicsUnlocked ()
140
  {
141
    initStateUnlocked (component);
142
    color = component.awtComponent.getForeground ();
143
    if (color == null)
144
      color = Color.BLACK;
145
    Dimension d = component.awtComponent.getSize ();
146
    clip = new Rectangle (0, 0, d.width, d.height);
147
  }
148
 
149
  native void connectSignals (GtkComponentPeer component);
150
 
151
  public native void clearRect(int x, int y, int width, int height);
152
 
153
  public void clipRect (int x, int y, int width, int height)
154
  {
155
    if (component != null && ! component.isRealized ())
156
      return;
157
 
158
    clip = clip.intersection (new Rectangle (x, y, width, height));
159
    setClipRectangle (clip.x, clip.y, clip.width, clip.height);
160
  }
161
 
162
  public native void copyArea(int x, int y, int width, int height,
163
                              int dx, int dy);
164
 
165
  public Graphics create ()
166
  {
167
    return new GdkGraphics (this);
168
  }
169
 
170
  public native void dispose();
171
 
172
  public boolean drawImage (Image img, int x, int y,
173
                            Color bgcolor, ImageObserver observer)
174
  {
175
    return drawImage(img, x, y, img.getWidth(null), img.getHeight(null),
176
                     bgcolor, observer);
177
  }
178
 
179
  public boolean drawImage (Image img, int x, int y, ImageObserver observer)
180
  {
181
    return drawImage (img, x, y, null, observer);
182
  }
183
 
184
  public boolean drawImage (Image img, int x, int y, int width, int height,
185
                            Color bgcolor, ImageObserver observer)
186
  {
187
    if (img instanceof GtkImage)
188
      return ((GtkImage)img).drawImage (this, x, y, width, height,
189
                                        bgcolor, observer);
190
    else
191
      return (new GtkImage(img.getSource())).drawImage (this, x, y,
192
                                                        width, height,
193
                                                        bgcolor, observer);
194
  }
195
 
196
  public boolean drawImage (Image img, int x, int y, int width, int height,
197
                            ImageObserver observer)
198
  {
199
    return drawImage (img, x, y, width, height,  null, observer);
200
  }
201
 
202
  public boolean drawImage (Image img, int dx1, int dy1, int dx2, int dy2,
203
                            int sx1, int sy1, int sx2, int sy2,
204
                            Color bgcolor, ImageObserver observer)
205
  {
206
    if (img instanceof GtkImage)
207
      return ((GtkImage)img).drawImage(this, dx1, dy1, dx2, dy2,
208
                                       sx1, sy1, sx2, sy2, bgcolor, observer);
209
    else
210
      return (new GtkImage(img.getSource())).drawImage(this, dx1, dy1,
211
                                                       dx2, dy2,
212
                                                       sx1, sy1, sx2, sy2,
213
                                                       bgcolor, observer);
214
  }
215
 
216
  public boolean drawImage (Image img, int dx1, int dy1, int dx2, int dy2,
217
                            int sx1, int sy1, int sx2, int sy2,
218
                            ImageObserver observer)
219
  {
220
    return drawImage (img, dx1, dy1, dx2, dy2,
221
                      sx1, sy1, sx2, sy2,
222
                      null, observer);
223
  }
224
 
225
  public native void drawLine(int x1, int y1, int x2, int y2);
226
 
227
  public native void drawArc(int x, int y, int width, int height,
228
                             int startAngle, int arcAngle);
229
  public native void fillArc(int x, int y, int width, int height,
230
                             int startAngle, int arcAngle);
231
  public native void drawOval(int x, int y, int width, int height);
232
  public native void fillOval(int x, int y, int width, int height);
233
 
234
  public native void drawPolygon(int[] xPoints, int[] yPoints, int nPoints);
235
  public native void fillPolygon(int[] xPoints, int[] yPoints, int nPoints);
236
 
237
  public native void drawPolyline(int[] xPoints, int[] yPoints, int nPoints);
238
 
239
  public native void drawRect(int x, int y, int width, int height);
240
  public native void fillRect(int x, int y, int width, int height);
241
 
242
  GdkFontPeer getFontPeer()
243
  {
244
    return (GdkFontPeer) getFont().getPeer();
245
  }
246
 
247
  native void drawString (GdkFontPeer f, String str, int x, int y);
248
  public void drawString (String str, int x, int y)
249
  {
250
    drawString(getFontPeer(), str, x, y);
251
  }
252
 
253
 
254
  public void drawString (AttributedCharacterIterator ci, int x, int y)
255
  {
256
    throw new Error ("not implemented");
257
  }
258
 
259
  public void drawRoundRect(int x, int y, int width, int height,
260
                            int arcWidth, int arcHeight)
261
  {
262
    if (arcWidth > width)
263
      arcWidth = width;
264
    if (arcHeight > height)
265
      arcHeight = height;
266
 
267
    int xx = x + width - arcWidth;
268
    int yy = y + height - arcHeight;
269
 
270
    drawArc (x, y, arcWidth, arcHeight, 90, 90);
271
    drawArc (xx, y, arcWidth, arcHeight, 0, 90);
272
    drawArc (xx, yy, arcWidth, arcHeight, 270, 90);
273
    drawArc (x, yy, arcWidth, arcHeight, 180, 90);
274
 
275
    int y1 = y + arcHeight / 2;
276
    int y2 = y + height - arcHeight / 2;
277
    drawLine (x, y1, x, y2);
278
    drawLine (x + width, y1, x + width, y2);
279
 
280
    int x1 = x + arcWidth / 2;
281
    int x2 = x + width - arcWidth / 2;
282
    drawLine (x1, y, x2, y);
283
    drawLine (x1, y + height, x2, y + height);
284
  }
285
 
286
  public void fillRoundRect (int x, int y, int width, int height,
287
                             int arcWidth, int arcHeight)
288
  {
289
    if (arcWidth > width)
290
      arcWidth = width;
291
    if (arcHeight > height)
292
      arcHeight = height;
293
 
294
    int xx = x + width - arcWidth;
295
    int yy = y + height - arcHeight;
296
 
297
    fillArc (x, y, arcWidth, arcHeight, 90, 90);
298
    fillArc (xx, y, arcWidth, arcHeight, 0, 90);
299
    fillArc (xx, yy, arcWidth, arcHeight, 270, 90);
300
    fillArc (x, yy, arcWidth, arcHeight, 180, 90);
301
 
302
    fillRect (x, y + arcHeight / 2, width, height - arcHeight + 1);
303
    fillRect (x + arcWidth / 2, y, width - arcWidth + 1, height);
304
  }
305
 
306
  public Shape getClip ()
307
  {
308
    return getClipBounds ();
309
  }
310
 
311
  public Rectangle getClipBounds ()
312
  {
313
    if (clip == null)
314
      return null;
315
    else
316
      return clip.getBounds();
317
  }
318
 
319
  public Color getColor ()
320
  {
321
    return color;
322
  }
323
 
324
  public Font getFont ()
325
  {
326
    return font;
327
  }
328
 
329
  public FontMetrics getFontMetrics (Font font)
330
  {
331
    return new GdkFontMetrics (font);
332
  }
333
 
334
  native void setClipRectangle (int x, int y, int width, int height);
335
 
336
  public void setClip (int x, int y, int width, int height)
337
  {
338
    if ((component != null && ! component.isRealized ())
339
        || clip == null)
340
      return;
341
 
342
    clip.x = x;
343
    clip.y = y;
344
    clip.width = width;
345
    clip.height = height;
346
 
347
    setClipRectangle (x, y, width, height);
348
  }
349
 
350
  public void setClip (Rectangle clip)
351
  {
352
    setClip (clip.x, clip.y, clip.width, clip.height);
353
  }
354
 
355
  public void setClip (Shape clip)
356
  {
357
    if (clip == null)
358
      {
359
        // Reset clipping.
360
        Dimension d = component.awtComponent.getSize();
361
        setClip(new Rectangle (0, 0, d.width, d.height));
362
      }
363
    else
364
      setClip(clip.getBounds());
365
  }
366
 
367
  private native void setFGColor(int red, int green, int blue);
368
 
369
  public void setColor (Color c)
370
  {
371
    if (c == null)
372
      color = Color.BLACK;
373
    else
374
      color = c;
375
 
376
    if (xorColor == null) /* paint mode */
377
      setFGColor (color.getRed (), color.getGreen (), color.getBlue ());
378
    else                  /* xor mode */
379
      setFGColor (color.getRed   () ^ xorColor.getRed (),
380
                  color.getGreen () ^ xorColor.getGreen (),
381
                  color.getBlue  () ^ xorColor.getBlue ());
382
  }
383
 
384
  public void setFont (Font font)
385
  {
386
    if (font != null)
387
      this.font = font;
388
  }
389
 
390
  native void setFunction (int gdk_func);
391
 
392
  public void setPaintMode ()
393
  {
394
    xorColor = null;
395
 
396
    setFunction (GDK_COPY);
397
    setFGColor (color.getRed (), color.getGreen (), color.getBlue ());
398
  }
399
 
400
  public void setXORMode (Color c)
401
  {
402
    xorColor = c;
403
 
404
    setFunction (GDK_XOR);
405
    setFGColor (color.getRed   () ^ xorColor.getRed (),
406
                color.getGreen () ^ xorColor.getGreen (),
407
                color.getBlue  () ^ xorColor.getBlue ());
408
  }
409
 
410
  public native void translateNative(int x, int y);
411
 
412
  public void translate (int x, int y)
413
  {
414
    if (component != null && ! component.isRealized ())
415
      return;
416
 
417
    clip.x -= x;
418
    clip.y -= y;
419
 
420
    translateNative (x, y);
421
  }
422
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.