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)
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
25 JNIEXPORT
void JNICALL
26 Java_gnu_classpath_examples_jawt_DemoJAWT_paintIt (JNIEnv
* env
,
32 JAWT_DrawingSurface
* surface
;
33 JAWT_DrawingSurfaceInfo
* surface_info
;
34 JAWT_X11DrawingSurfaceInfo
* surface_info_x11
;
38 char* test_string
= "JAWT";
46 awt
.version
= JAWT_VERSION_1_3
;
47 if (JAWT_GetAWT (env
, &awt
) == JNI_FALSE
)
49 printf ("couldn't find AWT\n");
53 surface
= awt
.GetDrawingSurface (env
, canvas
);
56 printf ("drawing surface is NULL\n");
60 lock
= surface
->Lock (surface
);
61 if ((lock
& JAWT_LOCK_ERROR
) != 0)
63 printf ("couldn't lock drawing surface\n");
64 awt
.FreeDrawingSurface (surface
);
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
);
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
)),
96 printf ("color allocation failed\n");
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
)),
110 printf ("color allocation failed\n");
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
)),
124 printf ("color allocation failed\n");
128 for (c
= 5; c
>= 0; c
--)
131 XSetForeground (display
, gc
, yellow
.pixel
);
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
));
143 XFreeGC (display
, gc
);
145 surface
->FreeDrawingSurfaceInfo (surface_info
);
147 surface
->Unlock (surface
);
149 awt
.FreeDrawingSurface (surface
);