00001
00013 #ifndef _TURTLEGRAPHIC_H_
00014 #define _TURTLEGRAPHIC_H_
00015
00016 #include "../jnilib.h"
00017 #include "../awt/frame.h"
00018 #include "../graphic/color.h"
00019 #include <stdlib.h>
00020
00021 #ifdef __cplusplus
00022 extern "C" {
00023 #endif
00024
00025 struct TurtleGraphic_;
00026
00027 struct TurtleGraphicCPP_;
00028
00029 #ifdef __cplusplus
00030 typedef TurtleGraphicCPP_ TurtleGraphic;
00031 #define createTurtleGraphic createTurtleGraphicCPP
00032 #define deleteTurtleGraphic deleteTurtleGraphicCPP
00033 #else
00034 typedef struct TurtleGraphic_ TurtleGraphic;
00035 #define createTurtleGraphic createTurtleGraphicC
00036 #define deleteTurtleGraphic deleteTurtleGraphicC
00037 #endif
00038
00042 typedef struct TurtleGraphicData {
00043 jclass clstg;
00044 jobject tg;
00045 jmethodID mright;
00046 jmethodID mleft;
00047 jmethodID mmoveTo;
00048 jmethodID mforward;
00049 jmethodID mbackward;
00050 jmethodID msetAngle;
00051 jmethodID msetColor;
00052 jmethodID mgetX;
00053 jmethodID mgetY;
00054 jmethodID msetDraw;
00055 jmethodID mprintText;
00056 jmethodID mclearScreen;
00057 } TurtleGraphicData;
00058
00062 typedef struct TurtleGraphic_ {
00063 TurtleGraphicData tg;
00064 void (*right)(TurtleGraphic* tg, jfloat angle);
00065 void (*left)(TurtleGraphic* tg, jfloat angle);
00066 void (*moveTo)(TurtleGraphic* tg, jfloat x, jfloat y);
00067 void (*forward)(TurtleGraphic* tg, jfloat l);
00068 void (*backward)(TurtleGraphic* tg, jfloat l);
00069 void (*setAngle)(TurtleGraphic* tg, jfloat angle);
00070 void (*setColor)(TurtleGraphic* tg, Color c);
00071 jfloat (*getX)(TurtleGraphic* tg);
00072 jfloat (*getY)(TurtleGraphic* tg);
00073 void (*setDraw)(TurtleGraphic* tg, jboolean draw);
00074 void (*printText)(TurtleGraphic* tg, const char* text);
00075 void (*clearScreen)(TurtleGraphic* tg);
00076 } TurtleGraphic_;
00077
00081 typedef struct TurtleGraphicCPP_ {
00082 TurtleGraphicData tg;
00083 struct TurtleGraphic_ *functions;
00084
00085 #ifdef __cplusplus
00086 void right(jfloat angle) {
00087 functions->right(this, angle);
00088 }
00089
00090 void left(jfloat angle) {
00091 functions->left(this, angle);
00092 }
00093
00094 void moveTo(jfloat x, jfloat y) {
00095 functions->moveTo(this, x, y);
00096 }
00097
00098 void forward(jfloat l) {
00099 functions->forward(this, l);
00100 }
00101
00102 void backward(jfloat l) {
00103 functions->backward(this, l);
00104 }
00105
00106 void setAngle(jfloat angle) {
00107 functions->setAngle(this, angle);
00108 }
00109
00110 void setColor(Color c) {
00111 functions->setColor(this, c);
00112 }
00113
00114 jfloat getX() {
00115 return functions->getX(this);
00116 }
00117
00118 jfloat getY() {
00119 return functions->getY(this);
00120 }
00121
00122 void setDraw(jboolean draw) {
00123 functions->setDraw(this, draw);
00124 }
00125
00126 void printText(const char* text) {
00127 functions->printText(this, text);
00128 }
00129
00130 void clearScreen() {
00131 functions->clearScreen(this);
00132 }
00133
00134 #endif
00135
00136 } TurtleGraphicCPP_;
00137
00138
00139 void createTurtleGraphicC(TurtleGraphic_* tg, Frame* frame);
00140 void createTurtleGraphicCPP(TurtleGraphicCPP_* tg, Frame* frame);
00141 void deleteTurtleGraphicC(TurtleGraphic_* tg);
00142 void deleteTurtleGraphicCPP(TurtleGraphicCPP_* tg);
00143
00144 #ifdef __cplusplus
00145 }
00146 #endif
00147
00148 #endif
00149
00150