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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 774 jeremybenn
/* qtgraphics.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 <jni.h>
40
#include <QPainter>
41
#include <QBrush>
42
#include <QLinearGradient>
43
#include <QPen>
44
#include <QPaintDevice>
45
#include <QPainterPath>
46
#include <QImage>
47
#include <QColor>
48
#include <gnu_java_awt_peer_qt_QtGraphics.h>
49
#include "nativewrapper.h"
50
#include "qtimage.h"
51
#include "qtstrings.h"
52
#include "qtcomponent.h"
53
#include "qtgraphics.h"
54
#include "qtfont.h"
55
 
56
// Constants from java.awt.AlphaComposite
57
#define CLEAR     1
58
#define SRC       2
59
#define DST       9
60
#define SRC_OVER  3
61
#define DST_OVER  4
62
#define SRC_IN    5
63
#define DST_IN    6
64
#define SRC_OUT   7
65
#define DST_OUT   8
66
#define SRC_ATOP  10
67
#define DST_ATOP  11
68
#define XOR       12
69
 
70
GraphicsPainter *getPainter( JNIEnv *env, jobject obj )
71
{
72
  jclass cls = env->GetObjectClass( obj );
73
  jfieldID field = env->GetFieldID( cls, "nativeObject", "J" );
74
  return (GraphicsPainter *)env->GetLongField( obj, field );
75
}
76
 
77
static void setNativePtr( JNIEnv *env, jobject obj, void *value )
78
{
79
  jlong longValue = (jlong) value;
80
  jclass cls = env->GetObjectClass( obj );
81
  jfieldID field = env->GetFieldID( cls, "nativeObject", "J" );
82
  env->SetLongField( obj, field, longValue );
83
}
84
 
85
static jobject getToolkit( JNIEnv *env, jobject obj )
86
{
87
  jclass cls = env->FindClass( "gnu/java/awt/peer/qt/QtGraphics" );
88
 
89
  jfieldID field = env->GetFieldID( cls, "toolkit",
90
                                    "Lgnu/java/awt/peer/qt/QtToolkit;" );
91
  return env->GetObjectField( obj, field );
92
}
93
 
94
///////////////////////// JNI methods ////////////////////////////////
95
 
96
/**
97
 * Clones the parent QPainter object.
98
 */
99
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_cloneNativeContext
100
(JNIEnv *env, jobject obj, jobject parent)
101
{
102
  GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, parent );
103
  assert( painter );
104
  QPainter *newPainter = new GraphicsPainter( painter->device() );
105
  assert( newPainter );
106
  setNativePtr(env, obj, newPainter);
107
}
108
 
109
/*
110
 * Start of JNI methods
111
 */
112
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_initImage
113
(JNIEnv *env, jobject obj, jobject image)
114
{
115
  QImage *im = getQtImage( env, image );
116
  assert( im );
117
  QPainter *painter = new GraphicsPainter( im );
118
  assert( painter );
119
  setNativePtr(env, obj, painter);
120
  painter->setRenderHint(QPainter::TextAntialiasing);
121
  painter->setRenderHint(QPainter::Antialiasing);
122
  painter->setRenderHint(QPainter::SmoothPixmapTransform);
123
}
124
 
125
/*
126
 * Start of JNI methods
127
 */
128
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_initVolatileImage
129
(JNIEnv *env, jobject obj, jobject image)
130
{
131
  QPixmap *im = getQtVolatileImage( env, image );
132
  assert( im );
133
  QPainter *painter = new GraphicsPainter( im );
134
  assert( painter );
135
  setNativePtr(env, obj, painter);
136
  painter->setRenderHint(QPainter::TextAntialiasing);
137
  painter->setRenderHint(QPainter::Antialiasing);
138
  painter->setRenderHint(QPainter::SmoothPixmapTransform);
139
}
140
 
141
/**
142
 * Deletes the QPainter
143
 */
144
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_delete
145
(JNIEnv *env, jobject obj)
146
{
147
  GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, obj );
148
  setNativePtr( env, obj, NULL );
149
  if( painter )
150
    {
151
      if( painter->isActive() )
152
        painter->end();
153
      delete painter;
154
    }
155
}
156
 
157
///////////////////////////////////////////////////////////
158
/*
159
 * Sets the clip to a path.
160
 */
161
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setClipNative
162
(JNIEnv *env, jobject obj, jobject path)
163
{
164
  QPainter *painter = getPainter( env, obj );
165
  assert( painter );
166
  QPainterPath *pp = (QPainterPath *)getNativeObject( env, path );
167
  assert( pp );
168
  painter->setClipPath( *pp );
169
}
170
 
171
/*
172
 * Sets the clip to a rectangle.
173
 */
174
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setClipRectNative
175
(JNIEnv *env, jobject obj, jint x, jint y, jint w, jint h)
176
{
177
  QPainter *painter = getPainter( env, obj );
178
  assert( painter );
179
  painter->setClipRect( x, y, w, h );
180
}
181
 
182
/*
183
 * Intersects a shape with the current clip.
184
 */
185
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_intersectClipNative
186
(JNIEnv *env, jobject obj, jobject path)
187
{
188
  QPainter *painter = getPainter( env, obj );
189
  assert( painter );
190
  QPainterPath *pp = (QPainterPath *)getNativeObject( env, path );
191
  assert( pp );
192
  painter->setClipPath( *pp, Qt::IntersectClip );
193
}
194
 
195
/*
196
 * Intersect a rectangle with the current clip.
197
 */
198
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_intersectClipRectNative
199
(JNIEnv *env, jobject obj, jint x, jint y, jint w, jint h)
200
{
201
  QPainter *painter = getPainter( env, obj );
202
  assert( painter );
203
  painter->setClipRect( x, y, w, h, Qt::IntersectClip );
204
}
205
 
206
/*
207
 * Returns a QPainterPath object with the clip path of this painter.
208
 */
209
JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_getClipNative
210
(JNIEnv *env, jobject obj)
211
{
212
  QPainter *painter = getPainter( env, obj );
213
  assert( painter );
214
  jclass cls = env->FindClass("gnu/java/awt/peer/qt/QPainterPath");
215
  jmethodID method = env->GetMethodID(cls, "<init>", "()V");
216
 
217
  jobject ppo = env->NewObject(cls, method);
218
  QPainterPath qpp = painter->clipPath();
219
  setNativeObject(env, ppo, &qpp);
220
 
221
  env->DeleteLocalRef( cls );
222
  return ppo;
223
}
224
 
225
/*
226
 * Returns a Rectangle with the bounds of this painters clip path.
227
 */
228
JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_getClipBounds
229
(JNIEnv *env, jobject obj)
230
{
231
  QPainter *painter = getPainter( env, obj );
232
  assert( painter );
233
  qreal x, y, w, h;
234
  painter->clipPath().boundingRect().getRect(&x, &y, &w, &h);
235
 
236
  jclass cls = env->FindClass("java/awt/Rectangle");
237
  assert( cls != NULL);
238
  jmethodID mid = env->GetMethodID(cls, "<init>", "(IIII)V");
239
  assert( mid != NULL);
240
  jvalue values[4];
241
 
242
  values[0].i = (jint) x;
243
  values[1].i = (jint) y;
244
  values[2].i = (jint) w;
245
  values[3].i = (jint) h;
246
 
247
  return env->NewObjectA(cls, mid, values);
248
}
249
 
250
///////////////////////// Color stuff ////////////////////////
251
/**
252
 *
253
 */
254
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setColor
255
(JNIEnv *env, jobject obj, jint r, jint g, jint b, jint alpha)
256
{
257
  GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, obj );
258
  assert( painter );
259
  painter->currentPen->setColor( QColor(r, g, b, alpha) );
260
  painter->setPen( *painter->currentPen );
261
  painter->currentBrush = new QBrush( QColor(r, g, b, alpha) );
262
  painter->setBrush( *painter->currentBrush );
263
  painter->currentColor = new QColor(r, g, b, alpha);
264
}
265
 
266
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setAlphaNative
267
  (JNIEnv *env, jobject obj, jdouble alpha)
268
{
269
  GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, obj );
270
  assert( painter );
271
 
272
  QColor c = painter->currentPen->color();
273
  c.setAlphaF( (qreal)alpha );
274
  painter->currentPen->setColor(c);
275
 
276
  c = painter->currentBrush->color();
277
  c.setAlphaF( (qreal)alpha );
278
  painter->currentBrush->setColor( c );
279
}
280
 
281
/*
282
 * Class:     gnu_java_awt_peer_qt_QtGraphics
283
 * Method:    drawNative
284
 * Signature: (Lgnu/java/awt/peer/qt/QPainterPath;)V
285
 */
286
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_drawNative
287
(JNIEnv *env, jobject obj, jobject path)
288
{
289
  GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, obj );
290
  assert( painter );
291
  QPainterPath *pp = (QPainterPath *)getNativeObject( env, path );
292
  assert( pp );
293
  painter->setPen( *painter->currentPen );
294
  painter->setBrush( Qt::NoBrush );
295
  painter->drawPath( *pp );
296
}
297
 
298
/*
299
 * Class:     gnu_java_awt_peer_qt_QtGraphics
300
 * Method:    fillNative
301
 * Signature: (Lgnu/java/awt/peer/qt/QPainterPath;)V
302
 */
303
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_fillNative
304
(JNIEnv *env, jobject obj, jobject path)
305
{
306
  GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, obj );
307
  assert( painter );
308
  QPainterPath *pp = (QPainterPath *)getNativeObject( env, path );
309
  assert( pp );
310
 
311
  painter->setPen(Qt::NoPen);
312
  painter->setBrush( *painter->currentBrush );
313
  painter->drawPath( *pp );
314
}
315
 
316
/**
317
 * Draws a string.
318
 */
319
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_drawStringNative
320
(JNIEnv *env, jobject obj, jstring str, jdouble x, jdouble y)
321
{
322
  GraphicsPainter *painter = getPainter( env, obj );
323
  assert( painter );
324
  QString *qStr = getQString(env, str);
325
  painter->setBrush( Qt::NoBrush );
326
  painter->setPen( *painter->currentPen );
327
  painter->drawText(QPointF( (qreal)x, (qreal)y ), *qStr);
328
  delete qStr;
329
}
330
 
331
/*
332
 * Sets the native stroke
333
 */
334
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setNativeStroke
335
(JNIEnv *env, jobject obj, jobject stroke)
336
{
337
  GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, obj );
338
  assert( painter );
339
  QPen *pen = (QPen *)getNativeObject(env, stroke);
340
  assert( pen );
341
  painter->currentPen = new QPen( *pen );
342
  painter->setPen( *painter->currentPen );
343
}
344
 
345
/*
346
 * Sets the transform
347
 */
348
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setQtTransform
349
(JNIEnv *env, jobject obj, jobject matrix)
350
{
351
  QPainter *painter = getPainter( env, obj );
352
  assert( painter );
353
  QMatrix *m = (QMatrix *)getNativeObject( env, matrix );
354
  assert( m );
355
  painter->setMatrix( *m );
356
}
357
 
358
/**
359
 * Set the font
360
 */
361
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setFontNative
362
(JNIEnv *env, jobject obj, jobject fontpeer)
363
{
364
  QPainter *painter = getPainter( env, obj );
365
  assert( painter );
366
  QFont *font = (QFont *) getFont( env, fontpeer );
367
  assert( font );
368
  painter->setFont( *font );
369
}
370
 
371
/*
372
 * Sets Porter-Duff compositing.
373
 */
374
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setNativeComposite
375
(JNIEnv *env, jobject obj, jint compositeMode)
376
{
377
  QPainter *painter = getPainter( env, obj );
378
  assert( painter );
379
  QPainter::CompositionMode mode;
380
 
381
  switch( compositeMode )
382
    {
383
    case CLEAR:
384
      mode = QPainter::CompositionMode_Clear;
385
      break;
386
    case SRC:
387
      mode = QPainter::CompositionMode_Source;
388
      break;
389
    case DST:
390
      mode = QPainter::CompositionMode_Destination;
391
      break;
392
    case SRC_OVER:
393
      mode = QPainter::CompositionMode_SourceOver;
394
      break;
395
    case DST_OVER:
396
      mode = QPainter::CompositionMode_DestinationOver;
397
      break;
398
    case SRC_IN:
399
      mode = QPainter::CompositionMode_SourceIn;
400
      break;
401
    case DST_IN:
402
      mode = QPainter::CompositionMode_DestinationIn;
403
      break;
404
    case SRC_OUT:
405
      mode = QPainter::CompositionMode_SourceOut;
406
      break;
407
    case DST_OUT:
408
      mode = QPainter::CompositionMode_DestinationOut;
409
      break;
410
    case SRC_ATOP:
411
      mode = QPainter::CompositionMode_SourceAtop;
412
      break;
413
    case DST_ATOP:
414
      mode = QPainter::CompositionMode_DestinationAtop;
415
      break;
416
    case XOR:
417
      mode = QPainter::CompositionMode_Xor;
418
      break;
419
    }
420
  painter->setCompositionMode( mode );
421
}
422
 
423
/**
424
 * Sets the current brush to a linear gradient.
425
 */
426
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setLinearGradient
427
(JNIEnv *env, jobject obj, jint r1, jint g1, jint b1, jint r2, jint g2,
428
jint b2, jdouble x1, jdouble y1, jdouble x2, jdouble y2, jboolean cyclic)
429
{
430
  GraphicsPainter *painter = getPainter( env, obj );
431
  assert( painter );
432
  QLinearGradient *lg = new QLinearGradient(QPointF( (qreal)x1, (qreal)y1 ),
433
                                            QPointF( (qreal)x2, (qreal)y2 ) );
434
  lg->setColorAt( (qreal)0.0, QColor(r1, g1, b1) );
435
  lg->setColorAt( (qreal)1.0, QColor(r2, g2, b2) );
436
  if( cyclic == JNI_TRUE )
437
    lg->setSpread( QGradient::ReflectSpread );
438
  else
439
    lg->setSpread( QGradient::PadSpread );
440
  painter->currentBrush = new QBrush( *lg );
441
  delete lg;
442
}
443
 
444
/*
445
 */
446
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_fill3DRect
447
(JNIEnv *env, jobject obj, jint x, jint y, jint w, jint h, jboolean raised)
448
{
449
  GraphicsPainter *painter = getPainter( env, obj );
450
  assert( painter );
451
  // FIXME: Adjust colors
452
  painter->fillRect ( x, y, w, h, QBrush( *painter->currentColor) );
453
  QPen *p = new QPen( *painter->currentColor );
454
  p->setWidth( 1 );
455
  painter->setPen( *p );
456
  painter->drawLine( x + w, y, x + w, y + h);
457
  painter->drawLine( x, y + h, x + w, y + h);
458
}
459
 
460
/*
461
 */
462
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_draw3DRect
463
(JNIEnv *env, jobject obj, jint x, jint y, jint w, jint h, jboolean raised)
464
{
465
  GraphicsPainter *painter = getPainter( env, obj );
466
  assert( painter );
467
  // FIXME: Adjust colors
468
  QPen *p = new QPen( *painter->currentColor );
469
  p->setWidth( 1 );
470
  painter->setPen( *p );
471
  painter->drawLine( x, y, x + w, y );
472
  painter->drawLine( x, y, x, y + h);
473
  painter->drawLine( x + w, y, x + w, y + h);
474
  painter->drawLine( x, y + h, x + w, y + h);
475
}

powered by: WebSVN 2.1.0

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