OsmAnd
|
00001 #ifndef _OSMAND_COMMON_H 00002 #define _OSMAND_COMMON_H 00003 00004 #include <jni.h> 00005 #include <string> 00006 #include <vector> 00007 #include <hash_map> 00008 00009 #include <SkPath.h> 00010 #include <SkBitmap.h> 00011 00012 #ifdef PROFILE_NATIVE_OPERATIONS 00013 #define PROFILE_NATIVE_OPERATION(rc, op) rc->nativeOperations.pause(); op; rc->nativeOperations.start() 00014 #else 00015 #define PROFILE_NATIVE_OPERATION(rc, op) op; 00016 #endif 00017 00018 struct RenderingContext; 00019 00020 JNIEnv* getGlobalJniEnv(); 00021 JNIEnv* setGlobalJniEnv(JNIEnv*); 00022 00023 // Android helpers 00024 extern const char* const LOG_TAG; 00025 00026 // JNI Helpers 00027 void throwNewException(const char* msg); 00028 jclass findClass(const char* className, bool mustHave = true); 00029 std::string getString(jstring st); 00030 std::string getStringMethod(jobject o, jmethodID fid, int i); 00031 std::string getStringMethod(jobject o, jmethodID fid); 00032 std::string getStringField(jobject o, jfieldID fid); 00033 jobject newGlobalRef(jobject o); 00034 jfieldID getFid(jclass cls, const char* fieldName, const char* sig); 00035 00036 void pullFromJavaRenderingContext(jobject jrc, RenderingContext* rc); 00037 void pushToJavaRenderingContext(jobject jrc, RenderingContext* rc); 00038 00039 class ElapsedTimer 00040 { 00041 private: 00042 long elapsedTime; 00043 bool enableFlag; 00044 timespec startInit; 00045 timespec endInit; 00046 bool run; 00047 00048 public: 00049 ElapsedTimer(); 00050 00051 void enable(); 00052 void disable(); 00053 00054 void start(); 00055 void pause(); 00056 00057 int getElapsedTime(); 00058 }; 00059 00060 struct TextDrawInfo { 00061 TextDrawInfo(std::string); 00062 ~TextDrawInfo(); 00063 00064 std::string text; 00065 00066 SkRect bounds; 00067 float centerX; 00068 float centerY; 00069 00070 float textSize; 00071 float minDistance; 00072 int textColor; 00073 int textShadow; 00074 uint textWrap; 00075 bool bold; 00076 std::string shieldRes; 00077 int textOrder; 00078 00079 bool drawOnPath; 00080 SkPath* path; 00081 float pathRotate; 00082 float vOffset; 00083 float hOffset; 00084 }; 00085 00086 struct IconDrawInfo 00087 { 00088 IconDrawInfo(); 00089 00090 SkBitmap* bmp; 00091 float x; 00092 float y; 00093 }; 00094 00095 struct RenderingContext 00096 { 00097 RenderingContext(); 00098 ~RenderingContext(); 00099 bool interrupted(); 00100 00101 jobject javaRenderingContext; 00102 00103 jobject androidContext; 00104 bool useEnglishNames; 00105 00106 std::vector<TextDrawInfo*> textToDraw; 00107 std::vector<IconDrawInfo> iconsToDraw; 00108 bool highResMode; 00109 float mapTextSize; 00110 float density; 00111 00112 float leftX; 00113 float topY; 00114 int width; 00115 int height; 00116 00117 int zoom; 00118 float rotate; 00119 float tileDivisor; 00120 00121 // debug purpose 00122 int pointCount; 00123 int pointInsideCount; 00124 int visible; 00125 int allObjects; 00126 int lastRenderedKey; 00127 class ElapsedTimer textRendering; 00128 class ElapsedTimer nativeOperations; 00129 00130 // use to calculate points 00131 float calcX; 00132 float calcY; 00133 00134 float cosRotateTileSize; 00135 float sinRotateTileSize; 00136 00137 int shadowRenderingMode; 00138 00139 // not expect any shadow 00140 int shadowLevelMin; 00141 int shadowLevelMax; 00142 }; 00143 00144 float getDensityValue(RenderingContext* rc, float val); 00145 00146 SkBitmap* getCachedBitmap(RenderingContext* rc, const std::string& bitmapResource); 00147 00148 #endif /*_OSMAND_COMMON_H*/