Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / native / jni / qt-peer / qpainterpath.cpp
blobcfe9eeae93aab1afe37e33537cd37406405522dd
1 /* qpainterpath.cpp --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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 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.
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. */
38 #include <assert.h>
39 #include <QPainterPath>
40 #include <gnu_java_awt_peer_qt_QPainterPath.h>
41 #include "nativewrapper.h"
43 // java.awt.geom.PathIterator constants.
44 #define WIND_EVEN_ODD 0
45 #define WIND_NON_ZERO 1
49 * Creates an empty QPainterPath.
51 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_init
52 (JNIEnv *env, jobject obj, jint windingRule)
54 QPainterPath *path = new QPainterPath();
55 assert( path );
56 path->setFillRule( (windingRule == WIND_EVEN_ODD) ?
57 Qt::OddEvenFill : Qt::WindingFill );
58 setNativeObject(env, obj, path);
62 * MoveTo
64 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_moveTo
65 (JNIEnv *env, jobject obj, jdouble x, jdouble y)
67 QPainterPath *path = (QPainterPath *)getNativeObject(env, obj);
68 assert( path );
69 path->moveTo( (qreal)x, (qreal)y );
73 * Closes the subpath.
75 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_close
76 (JNIEnv *env, jobject obj)
78 QPainterPath *path = (QPainterPath *)getNativeObject(env, obj);
79 assert( path );
80 path->closeSubpath();
84 * LineTo
86 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_lineTo
87 (JNIEnv *env, jobject obj, jdouble x, jdouble y)
89 QPainterPath *path = (QPainterPath *)getNativeObject(env, obj);
90 assert( path );
91 path->lineTo( (qreal)x, (qreal)y );
95 * QuadraticTo
97 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_quadTo
98 (JNIEnv *env, jobject obj, jdouble x, jdouble y, jdouble x2, jdouble y2)
100 QPainterPath *path = (QPainterPath *)getNativeObject(env, obj);
101 assert( path );
102 path->quadTo( (qreal)x, (qreal)y, (qreal)x2, (qreal)y2 );
106 * CubicTo
108 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_cubicTo
109 (JNIEnv *env, jobject obj, jdouble x, jdouble y, jdouble x2, jdouble y2,
110 jdouble x3, jdouble y3)
112 QPainterPath *path = (QPainterPath *)getNativeObject(env, obj);
113 assert( path );
114 path->cubicTo( (qreal)x, (qreal)y,
115 (qreal)x2, (qreal)y2,
116 (qreal)x3, (qreal)y3 );
120 * Delete the native object
122 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_dispose
123 (JNIEnv *env, jobject obj)
125 QPainterPath *path = (QPainterPath *)getNativeObject(env, obj);
126 if ( path )
127 delete path;
130 /********* GeneralPath functions *****************************/
132 // FIXME : Cache method ids.
134 static void gp_moveTo( JNIEnv *env,
135 jobject gp,
136 jclass cls,
137 double x1,
138 double y1 )
140 jmethodID method;
141 jvalue values[2];
143 values[0].f = (jfloat) x1;
144 values[1].f = (jfloat) y1;
146 method = env->GetMethodID(cls, "moveTo", "(FF)V");
147 env->CallVoidMethodA( gp, method, values );
150 static void gp_lineTo( JNIEnv *env,
151 jobject gp,
152 jclass cls,
153 double x1,
154 double y1 )
156 jmethodID method;
157 jvalue values[2];
159 values[0].f = (jfloat) x1;
160 values[1].f = (jfloat) y1;
162 method = env->GetMethodID(cls, "lineTo", "(FF)V");
163 env->CallVoidMethodA( gp, method, values );
166 static void gp_curveTo( JNIEnv *env,
167 jobject gp,
168 jclass cls,
169 double x1,
170 double y1,
171 double x2,
172 double y2,
173 double x3,
174 double y3 )
176 jmethodID method;
177 jvalue values[6];
179 values[0].f = (jfloat) x1;
180 values[1].f = (jfloat) y1;
181 values[2].f = (jfloat) x2;
182 values[3].f = (jfloat) y2;
183 values[4].f = (jfloat) x3;
184 values[5].f = (jfloat) y3;
186 method = env->GetMethodID(cls, "curveTo", "(FFFFFF)V");
187 env->CallVoidMethodA( gp, method, values );
191 * Returns the QPainterPath obj as a java.awt.geom.GeneralPath.
193 JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_getPath
194 (JNIEnv *env, jobject obj)
196 jclass cls;
197 jmethodID method;
198 jobject gp;
199 QPainterPath::Element currElement;
200 int windingRule;
202 QPainterPath *path = new QPainterPath();
203 assert( path );
205 windingRule = (path->fillRule() == Qt::OddEvenFill) ?
206 WIND_EVEN_ODD : WIND_NON_ZERO;
208 cls = env->FindClass("java/awt/geom/GeneralPath");
209 method = env->GetMethodID(cls, "<init>", "(I)V");
210 gp = env->NewObject(cls, method, windingRule);
212 for( int i = 0; i < path->elementCount(); i++)
214 currElement = path->elementAt( i );
215 switch(currElement.type)
217 case QPainterPath::MoveToElement:
218 gp_moveTo(env, gp, cls, currElement.x, currElement.y);
219 break;
220 case QPainterPath::LineToElement:
221 gp_lineTo(env, gp, cls, currElement.x, currElement.y);
222 break;
223 case QPainterPath::CurveToElement:
224 if( i + 2 >= path->elementCount() )
225 break;
226 if(path->elementAt(i + 1).type != QPainterPath::CurveToDataElement ||
227 path->elementAt(i + 2).type != QPainterPath::CurveToDataElement)
228 break;
229 gp_curveTo(env, gp, cls, currElement.x, currElement.y,
230 path->elementAt(i + 1).x, path->elementAt(i + 1).y,
231 path->elementAt(i + 2).x, path->elementAt(i + 2).y );
232 i += 2;
233 break;
236 env->DeleteLocalRef( cls );
237 return gp;