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)
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
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
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. */
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();
56 path
->setFillRule( (windingRule
== WIND_EVEN_ODD
) ?
57 Qt::OddEvenFill
: Qt::WindingFill
);
58 setNativeObject(env
, obj
, path
);
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
);
69 path
->moveTo( (qreal
)x
, (qreal
)y
);
75 JNIEXPORT
void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_close
76 (JNIEnv
*env
, jobject obj
)
78 QPainterPath
*path
= (QPainterPath
*)getNativeObject(env
, obj
);
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
);
91 path
->lineTo( (qreal
)x
, (qreal
)y
);
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
);
102 path
->quadTo( (qreal
)x
, (qreal
)y
, (qreal
)x2
, (qreal
)y2
);
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
);
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
);
130 /********* GeneralPath functions *****************************/
132 // FIXME : Cache method ids.
134 static void gp_moveTo( JNIEnv
*env
,
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
,
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
,
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
)
199 QPainterPath::Element currElement
;
202 QPainterPath
*path
= new QPainterPath();
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
);
220 case QPainterPath::LineToElement
:
221 gp_lineTo(env
, gp
, cls
, currElement
.x
, currElement
.y
);
223 case QPainterPath::CurveToElement
:
224 if( i
+ 2 >= path
->elementCount() )
226 if(path
->elementAt(i
+ 1).type
!= QPainterPath::CurveToDataElement
||
227 path
->elementAt(i
+ 2).type
!= QPainterPath::CurveToDataElement
)
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
);
236 env
->DeleteLocalRef( cls
);