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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [native/] [jni/] [qt-peer/] [qpainterpath.cpp] - Blame information for rev 774

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 774 jeremybenn
/* qpainterpath.cpp --
2
   Copyright (C)  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
#include <assert.h>
39
#include <QPainterPath>
40
#include <gnu_java_awt_peer_qt_QPainterPath.h>
41
#include "nativewrapper.h"
42
 
43
// java.awt.geom.PathIterator constants.
44
#define WIND_EVEN_ODD 0
45
#define WIND_NON_ZERO 1
46
 
47
 
48
/*
49
 * Creates an empty QPainterPath.
50
 */
51
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_init
52
(JNIEnv *env, jobject obj, jint windingRule)
53
{
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);
59
}
60
 
61
/*
62
 * MoveTo
63
 */
64
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_moveTo
65
(JNIEnv *env, jobject obj, jdouble x, jdouble y)
66
{
67
  QPainterPath *path = (QPainterPath *)getNativeObject(env, obj);
68
  assert( path );
69
  path->moveTo( (qreal)x, (qreal)y );
70
}
71
 
72
/*
73
 * Closes the subpath.
74
 */
75
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_close
76
(JNIEnv *env, jobject obj)
77
{
78
  QPainterPath *path = (QPainterPath *)getNativeObject(env, obj);
79
  assert( path );
80
  path->closeSubpath();
81
}
82
 
83
/*
84
 * LineTo
85
 */
86
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_lineTo
87
(JNIEnv *env, jobject obj, jdouble x, jdouble y)
88
{
89
  QPainterPath *path = (QPainterPath *)getNativeObject(env, obj);
90
  assert( path );
91
  path->lineTo( (qreal)x, (qreal)y );
92
}
93
 
94
/*
95
 * QuadraticTo
96
 */
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)
99
{
100
  QPainterPath *path = (QPainterPath *)getNativeObject(env, obj);
101
  assert( path );
102
  path->quadTo( (qreal)x, (qreal)y, (qreal)x2, (qreal)y2 );
103
}
104
 
105
/*
106
 * CubicTo
107
 */
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)
111
{
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 );
117
}
118
 
119
/*
120
 * Delete the native object
121
 */
122
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_dispose
123
  (JNIEnv *env, jobject obj)
124
{
125
  QPainterPath *path = (QPainterPath *)getNativeObject(env, obj);
126
  if ( path )
127
    delete path;
128
}
129
 
130
/********* GeneralPath functions *****************************/
131
 
132
// FIXME : Cache method ids.
133
 
134
static void gp_moveTo( JNIEnv *env,
135
                       jobject gp,
136
                       jclass cls,
137
                       double x1,
138
                       double y1 )
139
{
140
  jmethodID method;
141
  jvalue values[2];
142
 
143
  values[0].f = (jfloat) x1;
144
  values[1].f = (jfloat) y1;
145
 
146
  method = env->GetMethodID(cls, "moveTo", "(FF)V");
147
  env->CallVoidMethodA( gp, method, values );
148
}
149
 
150
static void gp_lineTo( JNIEnv *env,
151
                       jobject gp,
152
                       jclass cls,
153
                       double x1,
154
                       double y1 )
155
{
156
  jmethodID method;
157
  jvalue values[2];
158
 
159
  values[0].f = (jfloat) x1;
160
  values[1].f = (jfloat) y1;
161
 
162
  method = env->GetMethodID(cls, "lineTo", "(FF)V");
163
  env->CallVoidMethodA( gp, method, values );
164
}
165
 
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 )
175
{
176
  jmethodID method;
177
  jvalue values[6];
178
 
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;
185
 
186
  method = env->GetMethodID(cls, "curveTo", "(FFFFFF)V");
187
  env->CallVoidMethodA( gp, method, values );
188
}
189
 
190
/**
191
 * Returns the QPainterPath obj as a java.awt.geom.GeneralPath.
192
 */
193
JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_getPath
194
(JNIEnv *env, jobject obj)
195
{
196
  jclass cls;
197
  jmethodID method;
198
  jobject gp;
199
  QPainterPath::Element currElement;
200
  int windingRule;
201
 
202
  QPainterPath *path = new QPainterPath();
203
  assert( path );
204
 
205
  windingRule = (path->fillRule() == Qt::OddEvenFill) ?
206
    WIND_EVEN_ODD : WIND_NON_ZERO;
207
 
208
  cls = env->FindClass("java/awt/geom/GeneralPath");
209
  method = env->GetMethodID(cls, "<init>", "(I)V");
210
  gp = env->NewObject(cls, method, windingRule);
211
 
212
  for( int i = 0; i < path->elementCount(); i++)
213
    {
214
      currElement = path->elementAt( i );
215
      switch(currElement.type)
216
        {
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;
234
        }
235
    }
236
  env->DeleteLocalRef( cls );
237
  return gp;
238
}
239
 

powered by: WebSVN 2.1.0

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