shape.c

Go to the documentation of this file.
00001 
00014 #include "shape.h"
00015 
00016 #ifdef __cplusplus
00017 extern "C" {
00018 #endif
00019 
00029 Color getShapeColor(Shape* shape) {
00030    Color c;
00031    jobject jcolor = callObjectMethod(shape->shape.shape, shape->shape.mgetColor);
00032    c = convertJavaColor(jcolor);
00033    deleteGlobalReference(jcolor);
00034    return c;
00035 }
00036 
00045 void setShapeColor(Shape* shape, const Color* c) {
00046    jobject jcolor = convertColor(c);
00047    callVoidMethod(shape->shape.shape, shape->shape.msetColor, jcolor);
00048    deleteGlobalReference(jcolor);
00049 }
00050 
00060 jboolean isShapeFilled(Shape* shape) {
00061    return callBooleanMethod(shape->shape.shape, shape->shape.misFilled);
00062 }
00063 
00072 void setShapeFilled(Shape* shape, jboolean filled) {
00073    callVoidMethod(shape->shape.shape, shape->shape.msetFilled, filled);
00074 }
00075 
00081 void closeShapePath(Shape* shape) {
00082    callVoidMethod(shape->shape.shape, shape->shape.mclosePath);
00083 }
00084 
00094 void moveShapeTo(Shape* shape, jfloat x, jfloat y) {
00095    callVoidMethod(shape->shape.shape, shape->shape.mmoveTo, x ,y);
00096 }
00097 
00107 void lineShapeTo(Shape* shape, jfloat x, jfloat y) {
00108    callVoidMethod(shape->shape.shape, shape->shape.mlineTo, x ,y);
00109 }
00110 
00124 void curveShapeTo(Shape* shape, jfloat x1, jfloat y1, jfloat x2, jfloat y2, jfloat x3, jfloat y3) {
00125    callVoidMethod(shape->shape.shape, shape->shape.mcurveTo, x1 ,y1, x2, y2, x3, y3);
00126 }
00127 
00140 void quadShapeTo(Shape* shape, jfloat x1, jfloat y1, jfloat x2, jfloat y2) {
00141    callVoidMethod(shape->shape.shape, shape->shape.mquadTo, x1 ,y1, x2, y2);
00142 }
00143 
00149 void initShape_(Shape_* shape) {
00150    shape->setColor = &setShapeColor;
00151    shape->getColor = &getShapeColor;
00152    shape->isFilled = &isShapeFilled;
00153    shape->setFilled = &setShapeFilled;
00154    shape->closePath = &closeShapePath;
00155    shape->moveTo = &moveShapeTo;
00156    shape->lineTo = &lineShapeTo;
00157    shape->curveTo = &curveShapeTo;
00158    shape->quadTo = &quadShapeTo;
00159 }
00166 void createShape_(Shape* shape) {
00167    jmethodID constructor;
00168 
00169    shape->shape.clsshape = findClass(CLS_SHAPE);
00170    shape->shape.mgetColor = findMethod(shape->shape.clsshape, "getColor", "()Ljava/awt/Color;");
00171    shape->shape.msetColor = findMethod(shape->shape.clsshape, "setColor", "(Ljava/awt/Color;)V");
00172    shape->shape.misFilled = findMethod(shape->shape.clsshape, "isFilled", "()Z");
00173    shape->shape.msetFilled = findMethod(shape->shape.clsshape, "setFilled", "(Z)V");
00174    shape->shape.mclosePath = findMethod(shape->shape.clsshape, "closePath", "()V"); 
00175    shape->shape.mmoveTo = findMethod(shape->shape.clsshape, "moveTo", "(FF)V"); 
00176    shape->shape.mlineTo = findMethod(shape->shape.clsshape, "lineTo", "(FF)V"); 
00177    shape->shape.mcurveTo = findMethod(shape->shape.clsshape, "curveTo", "(FFFFFF)V");
00178    shape->shape.mquadTo = findMethod(shape->shape.clsshape, "quadTo", "(FFFF)V"); 
00179 
00180    constructor = findMethod(shape->shape.clsshape, "<init>", "()V");
00181 
00182    shape->shape.shape = newObject(shape->shape.clsshape, constructor);
00183 }
00184 
00191 void createShapeCPP(ShapeCPP_* shape) {
00192    shape->functions = (Shape_*)malloc(sizeof(Shape_));
00193    initShape_(shape->functions);
00194    createShape_((Shape*)shape);
00195 }
00196 
00203 void createShapeC(Shape_* shape) {
00204    initShape_(shape);
00205    createShape_((Shape*)shape);
00206 }
00207 
00213 void deleteShape_(Shape* shape) {
00214    deleteGlobalReference(shape->shape.shape);
00215    deleteGlobalReference(shape->shape.clsshape);
00216 }
00217 
00223 void deleteShapeCPP(ShapeCPP_* shape) {
00224    deleteShape_((Shape*)shape);
00225    free(shape->functions);
00226 }
00227 
00233 void deleteShapeC(Shape_* shape) {
00234    deleteShape_((Shape*)shape);
00235 }
00236 
00237 #ifdef __cplusplus
00238 } /* extern "C" */
00239 #endif
00240 
00241 /* end of file shape.c */

Generated on Sat Nov 19 14:11:11 2005 for GrubC by  doxygen 1.4.4