Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / examples / gnu / classpath / examples / jawt / DemoJAWT.c
blobee2d7bfec4a45a4ca93b80261ce1d2d38782e7a7
1 /* DemoJAWT.c -- native portion of AWT Native Interface demo
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath examples.
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.
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.
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. */
21 #include "DemoJAWT.h"
22 #include "jawt_md.h"
23 #include <string.h>
25 JNIEXPORT void JNICALL
26 Java_gnu_classpath_examples_jawt_DemoJAWT_paintIt (JNIEnv* env,
27 jobject canvas,
28 jobject graphics,
29 jboolean on)
31 JAWT awt;
32 JAWT_DrawingSurface* surface;
33 JAWT_DrawingSurfaceInfo* surface_info;
34 JAWT_X11DrawingSurfaceInfo* surface_info_x11;
35 jint lock;
36 GC gc;
37 int c;
38 char* test_string = "JAWT";
39 XColor orange;
40 XColor yellow;
41 XColor blue;
42 Display* display;
43 Drawable drawable;
44 Status status;
46 awt.version = JAWT_VERSION_1_3;
47 if (JAWT_GetAWT (env, &awt) == JNI_FALSE)
49 printf ("couldn't find AWT\n");
50 return;
53 surface = awt.GetDrawingSurface (env, canvas);
54 if (surface == NULL)
56 printf ("drawing surface is NULL\n");
57 return;
60 lock = surface->Lock (surface);
61 if ((lock & JAWT_LOCK_ERROR) != 0)
63 printf ("couldn't lock drawing surface\n");
64 awt.FreeDrawingSurface (surface);
65 return;
68 surface_info = surface->GetDrawingSurfaceInfo (surface);
69 if (surface_info == NULL)
71 printf ("couldn't get surface information\n");
72 surface->Unlock (surface);
73 awt.FreeDrawingSurface (surface);
74 return;
77 surface_info_x11 = (JAWT_X11DrawingSurfaceInfo*) surface_info->platformInfo;
79 display = surface_info_x11->display;
80 drawable = surface_info_x11->drawable;
82 gc = XCreateGC (display, drawable, 0, 0);
83 XSetBackground (display, gc, 0);
85 orange.red = 254 * 65535 / 255;
86 orange.green = 90 * 65535 / 255;
87 orange.blue = 16 * 65535 / 255;
89 /* assume color lookups succeed */
90 status = XAllocColor (display, DefaultColormap (display,
91 DefaultScreen (display)),
92 &orange);
94 if (!status)
96 printf ("color allocation failed\n");
97 goto cleanup;
100 yellow.red = 255 * 65535 / 255;
101 yellow.green = 255 * 65535 / 255;
102 yellow.blue = 0 * 65535 / 255;
104 XAllocColor (display, DefaultColormap (display,
105 DefaultScreen (display)),
106 &yellow);
108 if (!status)
110 printf ("color allocation failed\n");
111 goto cleanup;
114 blue.red = 16 * 65535 / 255;
115 blue.green = 30 * 65535 / 255;
116 blue.blue = 137 * 65535 / 255;
118 XAllocColor (display, DefaultColormap (display,
119 DefaultScreen (display)),
120 &blue);
122 if (!status)
124 printf ("color allocation failed\n");
125 goto cleanup;
128 for (c = 5; c >= 0; c--)
130 if (c % 2 == on)
131 XSetForeground (display, gc, yellow.pixel);
132 else
133 XSetForeground (display, gc, orange.pixel);
135 XFillArc (display, drawable, gc, 140 - c * 15, 140 - c * 15, c * 30, c * 30, 0, 360 * 64);
138 XSetForeground (display, gc, blue.pixel);
139 XDrawString (display, drawable,
140 gc, 129, 145, test_string, strlen (test_string));
142 cleanup:
143 XFreeGC (display, gc);
145 surface->FreeDrawingSurfaceInfo (surface_info);
147 surface->Unlock (surface);
149 awt.FreeDrawingSurface (surface);