turtlegraphic.c

Go to the documentation of this file.
00001 
00013 #include "turtlegraphic.h"
00014 
00016 #define CLS_TURTLEGRAPHIC "at/fhv/sgr/graphiclib/TurtleGraphic"
00017 
00018 #ifdef __cplusplus
00019 extern "C" {
00020 #endif
00021 
00031 void turtleright(TurtleGraphic* tg, jfloat angle) {
00032    callVoidMethod(tg->tg.tg, tg->tg.mright, angle);
00033 }
00034 
00044 void turtleleft(TurtleGraphic* tg, jfloat angle) {
00045    callVoidMethod(tg->tg.tg, tg->tg.mleft, angle);
00046 }
00047 
00057 void turtleforward(TurtleGraphic* tg, jfloat l) {
00058    callVoidMethod(tg->tg.tg, tg->tg.mforward, l);
00059 }
00060 
00070 void turtlebackward(TurtleGraphic* tg, jfloat l) {
00071    callVoidMethod(tg->tg.tg, tg->tg.mbackward, l);
00072 }
00073 
00083 void setTurtleAngle(TurtleGraphic* tg, jfloat angle) {
00084    callVoidMethod(tg->tg.tg, tg->tg.msetAngle, angle);
00085 }
00086 
00093 void setTurtleColor(TurtleGraphic* tg, Color c) {
00094    jobject jcolor = convertColor(&c);
00095    callVoidMethod(tg->tg.tg, tg->tg.msetColor, jcolor);
00096    deleteGlobalReference(jcolor);
00097 }
00098 
00109 void moveTurtleTo(TurtleGraphic* tg, jfloat x, jfloat y) {
00110    callVoidMethod(tg->tg.tg, tg->tg.mmoveTo, x, y);
00111 }
00112 
00119 void setTurtleDraw(TurtleGraphic* tg, jboolean draw) {
00120    callVoidMethod(tg->tg.tg, tg->tg.msetDraw, draw);
00121 }
00122 
00132 jfloat getTurtleX(TurtleGraphic* tg) {
00133    return callFloatMethod(tg->tg.tg, tg->tg.mgetX);
00134 }
00135 
00145 jfloat getTurtleY(TurtleGraphic* tg) {
00146    return callFloatMethod(tg->tg.tg, tg->tg.mgetY);
00147 }
00148 
00155 void printTurtleText(TurtleGraphic* tg, const char* text) {
00156    callVoidMethod(tg->tg.tg, tg->tg.mprintText, createJString(text));
00157 }
00158 
00164 void clearTurtleScreen(TurtleGraphic* tg) {
00165    callVoidMethod(tg->tg.tg, tg->tg.mclearScreen);
00166 }
00167 
00173 void initTurtleGraphic_(TurtleGraphic_* tg) {
00174    tg->right = &turtleright;
00175    tg->left = &turtleleft;
00176    tg->forward = &turtleforward;
00177    tg->backward = &turtlebackward;
00178    tg->setAngle = &setTurtleAngle;
00179    tg->setColor = &setTurtleColor;
00180    tg->moveTo = &moveTurtleTo;
00181    tg->setDraw = &setTurtleDraw;
00182    tg->getX = &getTurtleX;
00183    tg->getY = &getTurtleY;
00184    tg->printText = &printTurtleText;
00185    tg->clearScreen = &clearTurtleScreen;
00186 }
00187 
00195 void createTurtleGraphic_(TurtleGraphic* tg, Frame* frame) {
00196    jmethodID constructor;
00197 
00198    tg->tg.clstg = findClass(CLS_TURTLEGRAPHIC);
00199    tg->tg.mright = findMethod(tg->tg.clstg, "right", "(F)V");
00200    tg->tg.mleft = findMethod(tg->tg.clstg, "left", "(F)V");
00201    tg->tg.mmoveTo = findMethod(tg->tg.clstg, "setPos", "(FF)V");
00202    tg->tg.mforward = findMethod(tg->tg.clstg, "forward", "(F)V");
00203    tg->tg.mbackward = findMethod(tg->tg.clstg, "backward", "(F)V");
00204    tg->tg.msetAngle = findMethod(tg->tg.clstg, "setAngle", "(F)V");
00205    tg->tg.msetColor = findMethod(tg->tg.clstg, "setColor", "(Ljava/awt/Color;)V");
00206    tg->tg.mgetX = findMethod(tg->tg.clstg, "getX", "()F");
00207    tg->tg.mgetY = findMethod(tg->tg.clstg, "getY", "()F");
00208    tg->tg.msetDraw = findMethod(tg->tg.clstg, "setDraw", "(Z)V");
00209    tg->tg.mprintText = findMethod(tg->tg.clstg, "printText", "(Ljava/lang/String;)V");
00210    tg->tg.mclearScreen = findMethod(tg->tg.clstg, "clearScreen", "()V");
00211 
00212    constructor = findMethod(tg->tg.clstg, "<init>", "(L" CLS_FRAME ";)V");
00213 
00214    tg->tg.tg = newObject(tg->tg.clstg, constructor, frame->frame.frame);
00215 }
00216 
00224 void createTurtleGraphicCPP(TurtleGraphicCPP_* tg, Frame* frame) {
00225    tg->functions = (TurtleGraphic_*)malloc(sizeof(TurtleGraphic_));
00226    initTurtleGraphic_(tg->functions);
00227    createTurtleGraphic_((TurtleGraphic*)tg, frame);
00228 }
00229 
00237 void createTurtleGraphicC(TurtleGraphic_* tg, Frame* frame) {
00238    initTurtleGraphic_(tg);
00239    createTurtleGraphic_((TurtleGraphic*)tg, frame);
00240 }
00241 
00247 void deleteTurtleGraphic_(TurtleGraphic* tg) {
00248    deleteGlobalReference(tg->tg.tg);
00249    deleteGlobalReference(tg->tg.clstg);
00250 }
00251 
00257 void deleteTurtleGraphicCPP(TurtleGraphicCPP_* tg) {
00258    deleteTurtleGraphic_((TurtleGraphic*)tg);
00259    free(tg->functions);
00260 }
00261 
00267 void deleteTurtleGraphicC(TurtleGraphic_* tg) {
00268    deleteTurtleGraphic_((TurtleGraphic*)tg);
00269 }
00270 
00271 #ifdef __cplusplus
00272 } /* extern "C" */
00273 #endif
00274 
00275 /* end of file turtlegraphic.c */

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