summaryrefslogtreecommitdiff
path: root/navit/graphics
diff options
context:
space:
mode:
authorJoseph Herlant <herlantj@gmail.com>2018-05-25 22:06:51 -0700
committerJoseph Herlant <aerostitch@users.noreply.github.com>2018-05-25 22:17:50 -0700
commit8a76acb966f7059caf9d72c853175bd923b1e9d7 (patch)
tree1735178f7a0718831b88d2c36ea18a9955de3224 /navit/graphics
parent032f15287b472f1a4b5349533f3e5b468684b281 (diff)
downloadnavit-8a76acb966f7059caf9d72c853175bd923b1e9d7.tar.gz
cleanup:global:Use astyle to reformat everything
Diffstat (limited to 'navit/graphics')
-rw-r--r--navit/graphics/android/graphics_android.c1617
-rw-r--r--navit/graphics/egl/graphics_egl.c595
-rw-r--r--navit/graphics/gd/graphics_gd.c1311
-rw-r--r--navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c1753
-rw-r--r--navit/graphics/null/graphics_null.c317
-rw-r--r--navit/graphics/opengl/graphics_opengl.c2426
-rw-r--r--navit/graphics/opengl/graphics_opengl_egl.c111
-rw-r--r--navit/graphics/opengl/graphics_opengl_x11.c234
-rw-r--r--navit/graphics/qt5/QNavitQuick.cpp67
-rw-r--r--navit/graphics/qt5/QNavitWidget.cpp65
-rw-r--r--navit/graphics/qt5/event_qt5.cpp48
-rw-r--r--navit/graphics/qt5/graphics_qt5.cpp137
-rw-r--r--navit/graphics/qt_qpainter/RenderArea.cpp336
-rw-r--r--navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp1214
-rw-r--r--navit/graphics/sdl/event.c475
-rw-r--r--navit/graphics/sdl/event_sdl.c393
-rw-r--r--navit/graphics/sdl/graphics_sdl.c1540
-rw-r--r--navit/graphics/sdl/raster.c2403
-rw-r--r--navit/graphics/win32/graphics_win32.c901
-rw-r--r--navit/graphics/win32/xpm2bmp.c594
20 files changed, 7920 insertions, 8617 deletions
diff --git a/navit/graphics/android/graphics_android.c b/navit/graphics/android/graphics_android.c
index 6cc776227..a6a6565f4 100644
--- a/navit/graphics/android/graphics_android.c
+++ b/navit/graphics/android/graphics_android.c
@@ -35,148 +35,139 @@
#include "command.h"
struct graphics_priv {
- jclass NavitGraphicsClass;
- jmethodID NavitGraphics_draw_polyline, NavitGraphics_draw_polygon, NavitGraphics_draw_rectangle,
- NavitGraphics_draw_circle, NavitGraphics_draw_text, NavitGraphics_draw_image,
- NavitGraphics_draw_image_warp, NavitGraphics_draw_mode, NavitGraphics_draw_drag,
- NavitGraphics_overlay_disable, NavitGraphics_overlay_resize, NavitGraphics_SetCamera,
- NavitGraphics_setBackgroundColor;
-
- jclass PaintClass;
- jmethodID Paint_init,Paint_setStrokeWidth,Paint_setARGB;
-
- jobject NavitGraphics;
- jobject Paint;
-
- jclass BitmapFactoryClass;
- jmethodID BitmapFactory_decodeFile, BitmapFactory_decodeResource;
-
- jclass BitmapClass;
- jmethodID Bitmap_getHeight, Bitmap_getWidth, Bitmap_createScaledBitmap;
-
- jclass ContextClass;
- jmethodID Context_getResources;
-
- jclass ResourcesClass;
- jobject Resources;
- jmethodID Resources_getIdentifier;
-
- jobject packageName;
-
- struct callback_list *cbl;
- struct window win;
- struct padding *padding;
- jint bgcolor;
+ jclass NavitGraphicsClass;
+ jmethodID NavitGraphics_draw_polyline, NavitGraphics_draw_polygon, NavitGraphics_draw_rectangle,
+ NavitGraphics_draw_circle, NavitGraphics_draw_text, NavitGraphics_draw_image,
+ NavitGraphics_draw_image_warp, NavitGraphics_draw_mode, NavitGraphics_draw_drag,
+ NavitGraphics_overlay_disable, NavitGraphics_overlay_resize, NavitGraphics_SetCamera,
+ NavitGraphics_setBackgroundColor;
+
+ jclass PaintClass;
+ jmethodID Paint_init,Paint_setStrokeWidth,Paint_setARGB;
+
+ jobject NavitGraphics;
+ jobject Paint;
+
+ jclass BitmapFactoryClass;
+ jmethodID BitmapFactory_decodeFile, BitmapFactory_decodeResource;
+
+ jclass BitmapClass;
+ jmethodID Bitmap_getHeight, Bitmap_getWidth, Bitmap_createScaledBitmap;
+
+ jclass ContextClass;
+ jmethodID Context_getResources;
+
+ jclass ResourcesClass;
+ jobject Resources;
+ jmethodID Resources_getIdentifier;
+
+ jobject packageName;
+
+ struct callback_list *cbl;
+ struct window win;
+ struct padding *padding;
+ jint bgcolor;
};
struct graphics_font_priv {
- int size;
+ int size;
};
struct graphics_gc_priv {
- struct graphics_priv *gra;
- int linewidth;
- enum draw_mode_num mode;
- int a,r,g,b;
- unsigned char *dashes;
- int ndashes;
+ struct graphics_priv *gra;
+ int linewidth;
+ enum draw_mode_num mode;
+ int a,r,g,b;
+ unsigned char *dashes;
+ int ndashes;
};
struct graphics_image_priv {
- jobject Bitmap;
- int width;
- int height;
- struct point hot;
+ jobject Bitmap;
+ int width;
+ int height;
+ struct point hot;
};
static GHashTable *image_cache_hash = NULL;
static int
-find_class_global(char *name, jclass *ret)
-{
- *ret=(*jnienv)->FindClass(jnienv, name);
- if (! *ret) {
- dbg(lvl_error,"Failed to get Class %s",name);
- return 0;
- }
- *ret = (*jnienv)->NewGlobalRef(jnienv, *ret);
- return 1;
+find_class_global(char *name, jclass *ret) {
+ *ret=(*jnienv)->FindClass(jnienv, name);
+ if (! *ret) {
+ dbg(lvl_error,"Failed to get Class %s",name);
+ return 0;
+ }
+ *ret = (*jnienv)->NewGlobalRef(jnienv, *ret);
+ return 1;
}
static int
-find_method(jclass class, char *name, char *args, jmethodID *ret)
-{
- *ret = (*jnienv)->GetMethodID(jnienv, class, name, args);
- if (*ret == NULL) {
- dbg(lvl_error,"Failed to get Method %s with signature %s",name,args);
- return 0;
- }
- return 1;
+find_method(jclass class, char *name, char *args, jmethodID *ret) {
+ *ret = (*jnienv)->GetMethodID(jnienv, class, name, args);
+ if (*ret == NULL) {
+ dbg(lvl_error,"Failed to get Method %s with signature %s",name,args);
+ return 0;
+ }
+ return 1;
}
static int
-find_static_method(jclass class, char *name, char *args, jmethodID *ret)
-{
- *ret = (*jnienv)->GetStaticMethodID(jnienv, class, name, args);
- if (*ret == NULL) {
- dbg(lvl_error,"Failed to get static Method %s with signature %s",name,args);
- return 0;
- }
- return 1;
+find_static_method(jclass class, char *name, char *args, jmethodID *ret) {
+ *ret = (*jnienv)->GetStaticMethodID(jnienv, class, name, args);
+ if (*ret == NULL) {
+ dbg(lvl_error,"Failed to get static Method %s with signature %s",name,args);
+ return 0;
+ }
+ return 1;
}
static void
-graphics_destroy(struct graphics_priv *gr)
-{
+graphics_destroy(struct graphics_priv *gr) {
}
-static void font_destroy(struct graphics_font_priv *font)
-{
- g_free(font);
+static void font_destroy(struct graphics_font_priv *font) {
+ g_free(font);
}
static struct graphics_font_methods font_methods = {
- font_destroy
+ font_destroy
};
-static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth, char *font, int size, int flags)
-{
- struct graphics_font_priv *ret=g_new0(struct graphics_font_priv, 1);
- *meth=font_methods;
+static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth, char *font,
+ int size, int flags) {
+ struct graphics_font_priv *ret=g_new0(struct graphics_font_priv, 1);
+ *meth=font_methods;
- ret->size=size;
- return ret;
+ ret->size=size;
+ return ret;
}
static void
-gc_destroy(struct graphics_gc_priv *gc)
-{
- g_free(gc->dashes);
- g_free(gc);
+gc_destroy(struct graphics_gc_priv *gc) {
+ g_free(gc->dashes);
+ g_free(gc);
}
static void
-gc_set_linewidth(struct graphics_gc_priv *gc, int w)
-{
+gc_set_linewidth(struct graphics_gc_priv *gc, int w) {
gc->linewidth = w;
}
static void
-gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n)
-{
- g_free(gc->dashes);
- gc->ndashes=n;
- if(n) {
- gc->dashes=g_malloc(n);
- memcpy(gc->dashes, dash_list, n);
- } else {
- gc->dashes=NULL;
- }
+gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n) {
+ g_free(gc->dashes);
+ gc->ndashes=n;
+ if(n) {
+ gc->dashes=g_malloc(n);
+ memcpy(gc->dashes, dash_list, n);
+ } else {
+ gc->dashes=NULL;
+ }
}
static void
-gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
-{
+gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) {
gc->r = c->r >> 8;
gc->g = c->g >> 8;
gc->b = c->b >> 8;
@@ -184,305 +175,294 @@ gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
}
static void
-gc_set_background(struct graphics_gc_priv *gc, struct color *c)
-{
+gc_set_background(struct graphics_gc_priv *gc, struct color *c) {
}
static struct graphics_gc_methods gc_methods = {
- gc_destroy,
- gc_set_linewidth,
- gc_set_dashes,
- gc_set_foreground,
- gc_set_background
+ gc_destroy,
+ gc_set_linewidth,
+ gc_set_dashes,
+ gc_set_foreground,
+ gc_set_background
};
-static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
-{
- struct graphics_gc_priv *ret=g_new0(struct graphics_gc_priv, 1);
- *meth=gc_methods;
+static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
+ struct graphics_gc_priv *ret=g_new0(struct graphics_gc_priv, 1);
+ *meth=gc_methods;
- ret->gra = gr;
- ret->a = ret->r = ret->g = ret->b = 255;
- ret->linewidth=1;
- return ret;
+ ret->gra = gr;
+ ret->a = ret->r = ret->g = ret->b = 255;
+ ret->linewidth=1;
+ return ret;
}
-static void image_destroy(struct graphics_image_priv *img)
-{
+static void image_destroy(struct graphics_image_priv *img) {
// unused?
}
static struct graphics_image_methods image_methods = {
- image_destroy
+ image_destroy
};
static struct graphics_image_priv *
-image_new(struct graphics_priv *gra, struct graphics_image_methods *meth, char *path, int *w, int *h, struct point *hot, int rotation)
-{
- struct graphics_image_priv* ret = NULL;
-
- ret=g_new0(struct graphics_image_priv, 1);
- jstring string;
- jclass localBitmap = NULL;
- int id;
-
- dbg(lvl_debug,"enter %s",path);
- if (!strncmp(path,"res/drawable/",13)) {
- jstring a=(*jnienv)->NewStringUTF(jnienv, "drawable");
- char *path_noext=g_strdup(path+13);
- char *pos=strrchr(path_noext, '.');
- if (pos)
- *pos='\0';
- dbg(lvl_debug,"path_noext=%s",path_noext);
- string = (*jnienv)->NewStringUTF(jnienv, path_noext);
- g_free(path_noext);
- id=(*jnienv)->CallIntMethod(jnienv, gra->Resources, gra->Resources_getIdentifier, string, a, gra->packageName);
- dbg(lvl_debug,"id=%d",id);
- if (id)
- localBitmap=(*jnienv)->CallStaticObjectMethod(jnienv, gra->BitmapFactoryClass, gra->BitmapFactory_decodeResource, gra->Resources, id);
- (*jnienv)->DeleteLocalRef(jnienv, a);
- } else {
- string = (*jnienv)->NewStringUTF(jnienv, path);
- localBitmap=(*jnienv)->CallStaticObjectMethod(jnienv, gra->BitmapFactoryClass, gra->BitmapFactory_decodeFile, string);
- }
- if (localBitmap) {
- ret->width=(*jnienv)->CallIntMethod(jnienv, localBitmap, gra->Bitmap_getWidth);
- ret->height=(*jnienv)->CallIntMethod(jnienv, localBitmap, gra->Bitmap_getHeight);
- if((*w!=IMAGE_W_H_UNSET && *w!=ret->width) || (*h!=IMAGE_W_H_UNSET && *w!=ret->height)) {
- jclass scaledBitmap=(*jnienv)->CallStaticObjectMethod(jnienv, gra->BitmapClass,
- gra->Bitmap_createScaledBitmap, localBitmap, (*w==IMAGE_W_H_UNSET)?ret->width:*w, (*h==IMAGE_W_H_UNSET)?ret->height:*h, JNI_TRUE);
- if(!scaledBitmap) {
- dbg(lvl_error,"Bitmap scaling to %dx%d failed for %s",*w,*h,path);
- } else {
- (*jnienv)->DeleteLocalRef(jnienv, localBitmap);
- localBitmap=scaledBitmap;
- ret->width=(*jnienv)->CallIntMethod(jnienv, localBitmap, gra->Bitmap_getWidth);
- ret->height=(*jnienv)->CallIntMethod(jnienv, localBitmap, gra->Bitmap_getHeight);
- }
- }
- ret->Bitmap = (*jnienv)->NewGlobalRef(jnienv, localBitmap);
- (*jnienv)->DeleteLocalRef(jnienv, localBitmap);
-
- dbg(lvl_debug,"w=%d h=%d for %s",ret->width,ret->height,path);
- ret->hot.x=ret->width/2;
- ret->hot.y=ret->height/2;
- } else {
- g_free(ret);
- ret=NULL;
- dbg(lvl_warning,"Failed to open %s",path);
- }
- (*jnienv)->DeleteLocalRef(jnienv, string);
- if (ret) {
- *w=ret->width;
- *h=ret->height;
- if (hot)
- *hot=ret->hot;
- }
-
- return ret;
+image_new(struct graphics_priv *gra, struct graphics_image_methods *meth, char *path, int *w, int *h, struct point *hot,
+ int rotation) {
+ struct graphics_image_priv* ret = NULL;
+
+ ret=g_new0(struct graphics_image_priv, 1);
+ jstring string;
+ jclass localBitmap = NULL;
+ int id;
+
+ dbg(lvl_debug,"enter %s",path);
+ if (!strncmp(path,"res/drawable/",13)) {
+ jstring a=(*jnienv)->NewStringUTF(jnienv, "drawable");
+ char *path_noext=g_strdup(path+13);
+ char *pos=strrchr(path_noext, '.');
+ if (pos)
+ *pos='\0';
+ dbg(lvl_debug,"path_noext=%s",path_noext);
+ string = (*jnienv)->NewStringUTF(jnienv, path_noext);
+ g_free(path_noext);
+ id=(*jnienv)->CallIntMethod(jnienv, gra->Resources, gra->Resources_getIdentifier, string, a, gra->packageName);
+ dbg(lvl_debug,"id=%d",id);
+ if (id)
+ localBitmap=(*jnienv)->CallStaticObjectMethod(jnienv, gra->BitmapFactoryClass, gra->BitmapFactory_decodeResource,
+ gra->Resources, id);
+ (*jnienv)->DeleteLocalRef(jnienv, a);
+ } else {
+ string = (*jnienv)->NewStringUTF(jnienv, path);
+ localBitmap=(*jnienv)->CallStaticObjectMethod(jnienv, gra->BitmapFactoryClass, gra->BitmapFactory_decodeFile, string);
+ }
+ if (localBitmap) {
+ ret->width=(*jnienv)->CallIntMethod(jnienv, localBitmap, gra->Bitmap_getWidth);
+ ret->height=(*jnienv)->CallIntMethod(jnienv, localBitmap, gra->Bitmap_getHeight);
+ if((*w!=IMAGE_W_H_UNSET && *w!=ret->width) || (*h!=IMAGE_W_H_UNSET && *w!=ret->height)) {
+ jclass scaledBitmap=(*jnienv)->CallStaticObjectMethod(jnienv, gra->BitmapClass,
+ gra->Bitmap_createScaledBitmap, localBitmap, (*w==IMAGE_W_H_UNSET)?ret->width:*w, (*h==IMAGE_W_H_UNSET)?ret->height:*h,
+ JNI_TRUE);
+ if(!scaledBitmap) {
+ dbg(lvl_error,"Bitmap scaling to %dx%d failed for %s",*w,*h,path);
+ } else {
+ (*jnienv)->DeleteLocalRef(jnienv, localBitmap);
+ localBitmap=scaledBitmap;
+ ret->width=(*jnienv)->CallIntMethod(jnienv, localBitmap, gra->Bitmap_getWidth);
+ ret->height=(*jnienv)->CallIntMethod(jnienv, localBitmap, gra->Bitmap_getHeight);
+ }
+ }
+ ret->Bitmap = (*jnienv)->NewGlobalRef(jnienv, localBitmap);
+ (*jnienv)->DeleteLocalRef(jnienv, localBitmap);
+
+ dbg(lvl_debug,"w=%d h=%d for %s",ret->width,ret->height,path);
+ ret->hot.x=ret->width/2;
+ ret->hot.y=ret->height/2;
+ } else {
+ g_free(ret);
+ ret=NULL;
+ dbg(lvl_warning,"Failed to open %s",path);
+ }
+ (*jnienv)->DeleteLocalRef(jnienv, string);
+ if (ret) {
+ *w=ret->width;
+ *h=ret->height;
+ if (hot)
+ *hot=ret->hot;
+ }
+
+ return ret;
}
-static void initPaint(struct graphics_priv *gra, struct graphics_gc_priv *gc)
-{
+static void initPaint(struct graphics_priv *gra, struct graphics_gc_priv *gc) {
float wf = gc->linewidth;
(*jnienv)->CallVoidMethod(jnienv, gc->gra->Paint, gra->Paint_setStrokeWidth, wf);
(*jnienv)->CallVoidMethod(jnienv, gc->gra->Paint, gra->Paint_setARGB, gc->a, gc->r, gc->g, gc->b);
}
static void
-draw_lines(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count)
-{
- int arrsize=1+4+1+gc->ndashes+count*2;
- jint pc[arrsize];
- int i;
- jintArray points;
- if (count <= 0)
- return;
- points = (*jnienv)->NewIntArray(jnienv,arrsize);
- pc[0]=gc->linewidth;
- pc[1]=gc->a;
- pc[2]=gc->r;
- pc[3]=gc->g;
- pc[4]=gc->b;
- pc[5]=gc->ndashes;
- for (i = 0 ; i < gc->ndashes ; i++) {
- pc[6+i] = gc->dashes[i];
- }
- for (i = 0 ; i < count ; i++) {
- pc[6+gc->ndashes+i*2]=p[i].x;
- pc[6+gc->ndashes+i*2+1]=p[i].y;
- }
- (*jnienv)->SetIntArrayRegion(jnienv, points, 0, arrsize, pc);
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_polyline, gc->gra->Paint, points);
- (*jnienv)->DeleteLocalRef(jnienv, points);
+draw_lines(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count) {
+ int arrsize=1+4+1+gc->ndashes+count*2;
+ jint pc[arrsize];
+ int i;
+ jintArray points;
+ if (count <= 0)
+ return;
+ points = (*jnienv)->NewIntArray(jnienv,arrsize);
+ pc[0]=gc->linewidth;
+ pc[1]=gc->a;
+ pc[2]=gc->r;
+ pc[3]=gc->g;
+ pc[4]=gc->b;
+ pc[5]=gc->ndashes;
+ for (i = 0 ; i < gc->ndashes ; i++) {
+ pc[6+i] = gc->dashes[i];
+ }
+ for (i = 0 ; i < count ; i++) {
+ pc[6+gc->ndashes+i*2]=p[i].x;
+ pc[6+gc->ndashes+i*2+1]=p[i].y;
+ }
+ (*jnienv)->SetIntArrayRegion(jnienv, points, 0, arrsize, pc);
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_polyline, gc->gra->Paint, points);
+ (*jnienv)->DeleteLocalRef(jnienv, points);
}
static void
-draw_polygon(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count)
-{
- int arrsize=1+4+count*2;
- jint pc[arrsize];
- int i;
- jintArray points;
- if (count <= 0)
- return;
- points = (*jnienv)->NewIntArray(jnienv,arrsize);
- for (i = 0 ; i < count ; i++) {
- pc[5+i*2]=p[i].x;
- pc[5+i*2+1]=p[i].y;
- }
- pc[0]=gc->linewidth;
- pc[1]=gc->a;
- pc[2]=gc->r;
- pc[3]=gc->g;
- pc[4]=gc->b;
- (*jnienv)->SetIntArrayRegion(jnienv, points, 0, arrsize, pc);
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_polygon, gc->gra->Paint, points);
- (*jnienv)->DeleteLocalRef(jnienv, points);
+draw_polygon(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count) {
+ int arrsize=1+4+count*2;
+ jint pc[arrsize];
+ int i;
+ jintArray points;
+ if (count <= 0)
+ return;
+ points = (*jnienv)->NewIntArray(jnienv,arrsize);
+ for (i = 0 ; i < count ; i++) {
+ pc[5+i*2]=p[i].x;
+ pc[5+i*2+1]=p[i].y;
+ }
+ pc[0]=gc->linewidth;
+ pc[1]=gc->a;
+ pc[2]=gc->r;
+ pc[3]=gc->g;
+ pc[4]=gc->b;
+ (*jnienv)->SetIntArrayRegion(jnienv, points, 0, arrsize, pc);
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_polygon, gc->gra->Paint, points);
+ (*jnienv)->DeleteLocalRef(jnienv, points);
}
static void
-draw_rectangle(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int w, int h)
-{
- initPaint(gra, gc);
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_rectangle, gc->gra->Paint, p->x, p->y, w, h);
+draw_rectangle(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int w, int h) {
+ initPaint(gra, gc);
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_rectangle, gc->gra->Paint, p->x, p->y, w,
+ h);
}
static void
-draw_circle(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int r)
-{
- initPaint(gra, gc);
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_circle, gc->gra->Paint, p->x, p->y, r);
+draw_circle(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int r) {
+ initPaint(gra, gc);
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_circle, gc->gra->Paint, p->x, p->y, r);
}
static void
-draw_text(struct graphics_priv *gra, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy)
-{
- int bgcolor=0;
- dbg(lvl_debug,"enter %s", text);
- initPaint(gra, fg);
- if(bg)
- bgcolor=(bg->a<<24)| (bg->r<<16) | (bg->g<<8) | bg->b;
- jstring string = (*jnienv)->NewStringUTF(jnienv, text);
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_text, fg->gra->Paint, p->x, p->y, string, font->size, dx, dy, bgcolor);
- (*jnienv)->DeleteLocalRef(jnienv, string);
+draw_text(struct graphics_priv *gra, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg,
+ struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy) {
+ int bgcolor=0;
+ dbg(lvl_debug,"enter %s", text);
+ initPaint(gra, fg);
+ if(bg)
+ bgcolor=(bg->a<<24)| (bg->r<<16) | (bg->g<<8) | bg->b;
+ jstring string = (*jnienv)->NewStringUTF(jnienv, text);
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_text, fg->gra->Paint, p->x, p->y, string,
+ font->size, dx, dy, bgcolor);
+ (*jnienv)->DeleteLocalRef(jnienv, string);
}
static void
-draw_image(struct graphics_priv *gra, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img)
-{
- dbg(lvl_debug,"enter %p",img);
- initPaint(gra, fg);
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_image, fg->gra->Paint, p->x, p->y, img->Bitmap);
-
+draw_image(struct graphics_priv *gra, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img) {
+ dbg(lvl_debug,"enter %p",img);
+ initPaint(gra, fg);
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_image, fg->gra->Paint, p->x, p->y,
+ img->Bitmap);
+
}
static void
-draw_image_warp (struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count, struct graphics_image_priv *img)
-{
-
- /*
- *
- *
- * if coord count==3 then top.left top.right bottom.left
- *
- */
-
- if (count==3)
- {
- initPaint(gr, fg);
- (*jnienv)->CallVoidMethod(jnienv, gr->NavitGraphics, gr->NavitGraphics_draw_image_warp, fg->gra->Paint,
- count, p[0].x, p[0].y,p[1].x, p[1].y, p[2].x, p[2].y, img->Bitmap);
- } else
- dbg(lvl_debug,"draw_image_warp is called with unsupported count parameter value %d", count);
+draw_image_warp (struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count,
+ struct graphics_image_priv *img) {
+
+ /*
+ *
+ *
+ * if coord count==3 then top.left top.right bottom.left
+ *
+ */
+
+ if (count==3) {
+ initPaint(gr, fg);
+ (*jnienv)->CallVoidMethod(jnienv, gr->NavitGraphics, gr->NavitGraphics_draw_image_warp, fg->gra->Paint,
+ count, p[0].x, p[0].y,p[1].x, p[1].y, p[2].x, p[2].y, img->Bitmap);
+ } else
+ dbg(lvl_debug,"draw_image_warp is called with unsupported count parameter value %d", count);
}
-static void draw_drag(struct graphics_priv *gra, struct point *p)
-{
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_drag, p ? p->x : 0, p ? p->y : 0);
+static void draw_drag(struct graphics_priv *gra, struct point *p) {
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_drag, p ? p->x : 0, p ? p->y : 0);
}
static void
-background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
+background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
}
static void
-draw_mode(struct graphics_priv *gra, enum draw_mode_num mode)
-{
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_mode, (int)mode);
+draw_mode(struct graphics_priv *gra, enum draw_mode_num mode) {
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_mode, (int)mode);
}
-static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound);
+static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p,
+ int w, int h, int wraparound);
static void *
-get_data(struct graphics_priv *this, const char *type)
-{
- if (!strcmp(type,"padding"))
- return this->padding;
- if (!strcmp(type,"window"))
- return &this->win;
- return NULL;
+get_data(struct graphics_priv *this, const char *type) {
+ if (!strcmp(type,"padding"))
+ return this->padding;
+ if (!strcmp(type,"window"))
+ return &this->win;
+ return NULL;
}
-static void image_free(struct graphics_priv *gr, struct graphics_image_priv *priv)
-{
+static void image_free(struct graphics_priv *gr, struct graphics_image_priv *priv) {
}
-static void get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy, struct point *ret, int estimate)
-{
- int len = g_utf8_strlen(text, -1);
- int xMin = 0;
- int yMin = 0;
- int yMax = 13*font->size/256;
- int xMax = 9*font->size*len/256;
-
- ret[0].x = xMin;
- ret[0].y = -yMin;
- ret[1].x = xMin;
- ret[1].y = -yMax;
- ret[2].x = xMax;
- ret[2].y = -yMax;
- ret[3].x = xMax;
- ret[3].y = -yMin;
+static void get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy,
+ struct point *ret, int estimate) {
+ int len = g_utf8_strlen(text, -1);
+ int xMin = 0;
+ int yMin = 0;
+ int yMax = 13*font->size/256;
+ int xMax = 9*font->size*len/256;
+
+ ret[0].x = xMin;
+ ret[0].y = -yMin;
+ ret[1].x = xMin;
+ ret[1].y = -yMax;
+ ret[2].x = xMax;
+ ret[2].y = -yMax;
+ ret[3].x = xMax;
+ ret[3].y = -yMin;
}
-static void overlay_disable(struct graphics_priv *gra, int disable)
-{
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_overlay_disable, disable);
+static void overlay_disable(struct graphics_priv *gra, int disable) {
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_overlay_disable, disable);
}
-static void overlay_resize(struct graphics_priv *gra, struct point *pnt, int w, int h, int wraparound)
-{
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_overlay_resize, pnt ? pnt->x:0 , pnt ? pnt->y:0, w, h, wraparound);
+static void overlay_resize(struct graphics_priv *gra, struct point *pnt, int w, int h, int wraparound) {
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_overlay_resize, pnt ? pnt->x:0, pnt ? pnt->y:0,
+ w, h, wraparound);
}
static int
-set_attr(struct graphics_priv *gra, struct attr *attr)
-{
- switch (attr->type) {
- case attr_use_camera:
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_SetCamera, attr->u.num);
- return 1;
- case attr_background_color:
- gra->bgcolor = (attr->u.color->a / 0x101) << 24
- | (attr->u.color->r / 0x101) << 16
- | (attr->u.color->g / 0x101) << 8
- | (attr->u.color->b / 0x101);
- dbg(lvl_debug, "set attr_background_color %04x %04x %04x %04x (%08x)",
- attr->u.color->r, attr->u.color->g, attr->u.color->b, attr->u.color->a, gra->bgcolor);
- if (gra->NavitGraphics_setBackgroundColor != NULL)
- (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_setBackgroundColor, gra->bgcolor);
- else
- dbg(lvl_error, "NavitGraphics.setBackgroundColor not found, cannot set background color");
- return 1;
- default:
- return 0;
- }
+set_attr(struct graphics_priv *gra, struct attr *attr) {
+ switch (attr->type) {
+ case attr_use_camera:
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_SetCamera, attr->u.num);
+ return 1;
+ case attr_background_color:
+ gra->bgcolor = (attr->u.color->a / 0x101) << 24
+ | (attr->u.color->r / 0x101) << 16
+ | (attr->u.color->g / 0x101) << 8
+ | (attr->u.color->b / 0x101);
+ dbg(lvl_debug, "set attr_background_color %04x %04x %04x %04x (%08x)",
+ attr->u.color->r, attr->u.color->g, attr->u.color->b, attr->u.color->a, gra->bgcolor);
+ if (gra->NavitGraphics_setBackgroundColor != NULL)
+ (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_setBackgroundColor, gra->bgcolor);
+ else
+ dbg(lvl_error, "NavitGraphics.setBackgroundColor not found, cannot set background color");
+ return 1;
+ default:
+ return 0;
+ }
}
@@ -492,97 +472,91 @@ void hide_native_keyboard (struct graphics_keyboard *kbd);
static struct graphics_methods graphics_methods = {
- graphics_destroy,
- draw_mode,
- draw_lines,
- draw_polygon,
- draw_rectangle,
- draw_circle,
- draw_text,
- draw_image,
- draw_image_warp,
- draw_drag,
- font_new,
- gc_new,
- background_gc,
- overlay_new,
- image_new,
- get_data,
- image_free,
- get_text_bbox,
- overlay_disable,
- overlay_resize,
- set_attr,
- show_native_keyboard,
- hide_native_keyboard,
+ graphics_destroy,
+ draw_mode,
+ draw_lines,
+ draw_polygon,
+ draw_rectangle,
+ draw_circle,
+ draw_text,
+ draw_image,
+ draw_image_warp,
+ draw_drag,
+ font_new,
+ gc_new,
+ background_gc,
+ overlay_new,
+ image_new,
+ get_data,
+ image_free,
+ get_text_bbox,
+ overlay_disable,
+ overlay_resize,
+ set_attr,
+ show_native_keyboard,
+ hide_native_keyboard,
};
static void
-resize_callback(struct graphics_priv *gra, int w, int h)
-{
- dbg(lvl_debug,"w=%d h=%d ok",w,h);
- dbg(lvl_debug,"gra=%p, %d callbacks in list", gra, g_list_length(gra->cbl));
- callback_list_call_attr_2(gra->cbl, attr_resize, (void *)w, (void *)h);
+resize_callback(struct graphics_priv *gra, int w, int h) {
+ dbg(lvl_debug,"w=%d h=%d ok",w,h);
+ dbg(lvl_debug,"gra=%p, %d callbacks in list", gra, g_list_length(gra->cbl));
+ callback_list_call_attr_2(gra->cbl, attr_resize, (void *)w, (void *)h);
}
static void
-padding_callback(struct graphics_priv *gra, int left, int top, int right, int bottom)
-{
- dbg(lvl_debug, "win.padding left=%d top=%d right=%d bottom=%d ok", left, top, right, bottom);
- gra->padding->left = left;
- gra->padding->top = top;
- gra->padding->right = right;
- gra->padding->bottom = bottom;
+padding_callback(struct graphics_priv *gra, int left, int top, int right, int bottom) {
+ dbg(lvl_debug, "win.padding left=%d top=%d right=%d bottom=%d ok", left, top, right, bottom);
+ gra->padding->left = left;
+ gra->padding->top = top;
+ gra->padding->right = right;
+ gra->padding->bottom = bottom;
}
static void
-motion_callback(struct graphics_priv *gra, int x, int y)
-{
- struct point p;
- p.x=x;
- p.y=y;
- callback_list_call_attr_1(gra->cbl, attr_motion, (void *)&p);
+motion_callback(struct graphics_priv *gra, int x, int y) {
+ struct point p;
+ p.x=x;
+ p.y=y;
+ callback_list_call_attr_1(gra->cbl, attr_motion, (void *)&p);
}
static void
-keypress_callback(struct graphics_priv *gra, char *s)
-{
- dbg(lvl_debug,"enter %s",s);
- callback_list_call_attr_1(gra->cbl, attr_keypress, s);
+keypress_callback(struct graphics_priv *gra, char *s) {
+ dbg(lvl_debug,"enter %s",s);
+ callback_list_call_attr_1(gra->cbl, attr_keypress, s);
}
static void
-button_callback(struct graphics_priv *gra, int pressed, int button, int x, int y)
-{
- struct point p;
- p.x=x;
- p.y=y;
- callback_list_call_attr_3(gra->cbl, attr_button, (void *)pressed, (void *)button, (void *)&p);
+button_callback(struct graphics_priv *gra, int pressed, int button, int x, int y) {
+ struct point p;
+ p.x=x;
+ p.y=y;
+ callback_list_call_attr_3(gra->cbl, attr_button, (void *)pressed, (void *)button, (void *)&p);
}
static int
-set_activity(jobject graphics)
-{
- jclass ActivityClass;
- jmethodID cid;
-
- ActivityClass = (*jnienv)->GetObjectClass(jnienv, android_activity);
- dbg(lvl_debug,"at 5");
- if (ActivityClass == NULL) {
- dbg(lvl_debug,"no activity class found");
- return 0;
- }
- dbg(lvl_debug,"at 6");
- cid = (*jnienv)->GetMethodID(jnienv, ActivityClass, "setContentView", "(Landroid/view/View;)V");
- if (cid == NULL) {
- dbg(lvl_error,"no setContentView method found");
- return 0;
- }
- dbg(lvl_debug,"at 7");
- (*jnienv)->CallVoidMethod(jnienv, android_activity, cid, graphics);
- dbg(lvl_debug,"at 8");
- return 1;
+set_activity(jobject graphics) {
+ jclass ActivityClass;
+ jmethodID cid;
+
+ ActivityClass = (*jnienv)->GetObjectClass(jnienv, android_activity);
+ dbg(lvl_debug,"at 5");
+ if (ActivityClass == NULL) {
+ dbg(lvl_debug,"no activity class found");
+ return 0;
+ }
+ dbg(lvl_debug,"at 6");
+ cid = (*jnienv)->GetMethodID(jnienv, ActivityClass, "setContentView", "(Landroid/view/View;)V");
+ if (cid == NULL) {
+ dbg(lvl_error,"no setContentView method found");
+ return 0;
+ }
+ dbg(lvl_debug,"at 7");
+ (*jnienv)->CallVoidMethod(jnienv, android_activity, cid, graphics);
+ dbg(lvl_debug,"at 8");
+ return 1;
}
/**
@@ -599,166 +573,178 @@ set_activity(jobject graphics)
* @param use_camera Whether to use the camera (0 for overlays)
*/
static int
-graphics_android_init(struct graphics_priv *ret, struct graphics_priv *parent, struct point *pnt, int w, int h, int wraparound, int use_camera)
-{
- struct callback *cb;
- jmethodID cid, Context_getPackageName;
-
- dbg(lvl_debug,"at 2 jnienv=%p",jnienv);
- if (parent)
- ret->padding = parent->padding;
- if (!find_class_global("android/graphics/Paint", &ret->PaintClass))
- return 0;
- if (!find_method(ret->PaintClass, "<init>", "(I)V", &ret->Paint_init))
- return 0;
- if (!find_method(ret->PaintClass, "setARGB", "(IIII)V", &ret->Paint_setARGB))
- return 0;
- if (!find_method(ret->PaintClass, "setStrokeWidth", "(F)V", &ret->Paint_setStrokeWidth))
- return 0;
-
- if (!find_class_global("android/graphics/BitmapFactory", &ret->BitmapFactoryClass))
- return 0;
- if (!find_static_method(ret->BitmapFactoryClass, "decodeFile", "(Ljava/lang/String;)Landroid/graphics/Bitmap;", &ret->BitmapFactory_decodeFile))
- return 0;
- if (!find_static_method(ret->BitmapFactoryClass, "decodeResource", "(Landroid/content/res/Resources;I)Landroid/graphics/Bitmap;", &ret->BitmapFactory_decodeResource))
- return 0;
-
- if (!find_class_global("android/graphics/Bitmap", &ret->BitmapClass))
- return 0;
- if (!find_method(ret->BitmapClass, "getHeight", "()I", &ret->Bitmap_getHeight))
- return 0;
- if (!find_method(ret->BitmapClass, "getWidth", "()I", &ret->Bitmap_getWidth))
- return 0;
- if (!find_static_method(ret->BitmapClass, "createScaledBitmap", "(Landroid/graphics/Bitmap;IIZ)Landroid/graphics/Bitmap;", &ret->Bitmap_createScaledBitmap))
- return 0;
-
- if (!find_class_global("android/content/Context", &ret->ContextClass))
- return 0;
- if (!find_method(ret->ContextClass, "getResources", "()Landroid/content/res/Resources;", &ret->Context_getResources))
- return 0;
-
-
- ret->Resources=(*jnienv)->CallObjectMethod(jnienv, android_activity, ret->Context_getResources);
- if (ret->Resources)
- ret->Resources = (*jnienv)->NewGlobalRef(jnienv, ret->Resources);
- if (!find_class_global("android/content/res/Resources", &ret->ResourcesClass))
- return 0;
- if (!find_method(ret->ResourcesClass, "getIdentifier", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I", &ret->Resources_getIdentifier))
- return 0;
-
- if (!find_method(ret->ContextClass, "getPackageName", "()Ljava/lang/String;", &Context_getPackageName))
- return 0;
- ret->packageName=(*jnienv)->CallObjectMethod(jnienv, android_activity, Context_getPackageName);
- ret->packageName=(*jnienv)->NewGlobalRef(jnienv, ret->packageName);
-
- if (!find_class_global("org/navitproject/navit/NavitGraphics", &ret->NavitGraphicsClass))
- return 0;
- dbg(lvl_debug,"at 3");
- cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "<init>", "(Landroid/app/Activity;Lorg/navitproject/navit/NavitGraphics;IIIIII)V");
- if (cid == NULL) {
- dbg(lvl_error,"no method found");
- return 0; /* exception thrown */
- }
- dbg(lvl_debug,"at 4 android_activity=%p",android_activity);
- ret->NavitGraphics=(*jnienv)->NewObject(jnienv, ret->NavitGraphicsClass, cid, android_activity, parent ? parent->NavitGraphics : NULL, pnt ? pnt->x:0 , pnt ? pnt->y:0, w, h, wraparound, use_camera);
- dbg(lvl_debug,"result=%p",ret->NavitGraphics);
- if (ret->NavitGraphics)
- ret->NavitGraphics = (*jnienv)->NewGlobalRef(jnienv, ret->NavitGraphics);
-
- /* Create a single global Paint, otherwise android will quickly run out
- * of global refs.*/
- /* 0x101 = text kerning (default), antialiasing */
- ret->Paint=(*jnienv)->NewObject(jnienv, ret->PaintClass, ret->Paint_init, 0x101);
-
- dbg(lvl_debug,"result=%p",ret->Paint);
- if (ret->Paint)
- ret->Paint = (*jnienv)->NewGlobalRef(jnienv, ret->Paint);
-
- cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setSizeChangedCallback", "(I)V");
- if (cid == NULL) {
- dbg(lvl_error,"no SetResizeCallback method found");
- return 0; /* exception thrown */
- }
- cb=callback_new_1(callback_cast(resize_callback), ret);
- (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
-
- cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setPaddingChangedCallback", "(I)V");
- if (cid == NULL) {
- dbg(lvl_error,"no SetPaddingCallback method found");
- return 0; /* exception thrown */
- }
- cb=callback_new_1(callback_cast(padding_callback), ret);
- (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
-
- cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setButtonCallback", "(I)V");
- if (cid == NULL) {
- dbg(lvl_error,"no SetButtonCallback method found");
- return 0; /* exception thrown */
- }
- cb=callback_new_1(callback_cast(button_callback), ret);
- (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
-
- cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setMotionCallback", "(I)V");
- if (cid == NULL) {
- dbg(lvl_error,"no SetMotionCallback method found");
- return 0; /* exception thrown */
- }
- cb=callback_new_1(callback_cast(motion_callback), ret);
- (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
-
- cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setKeypressCallback", "(I)V");
- if (cid == NULL) {
- dbg(lvl_error,"no SetKeypressCallback method found");
- return 0; /* exception thrown */
- }
- cb=callback_new_1(callback_cast(keypress_callback), ret);
- (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
-
- if (!find_method(ret->NavitGraphicsClass, "draw_polyline", "(Landroid/graphics/Paint;[I)V", &ret->NavitGraphics_draw_polyline))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "draw_polygon", "(Landroid/graphics/Paint;[I)V", &ret->NavitGraphics_draw_polygon))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "draw_rectangle", "(Landroid/graphics/Paint;IIII)V", &ret->NavitGraphics_draw_rectangle))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "draw_circle", "(Landroid/graphics/Paint;III)V", &ret->NavitGraphics_draw_circle))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "draw_text", "(Landroid/graphics/Paint;IILjava/lang/String;IIII)V", &ret->NavitGraphics_draw_text))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "draw_image", "(Landroid/graphics/Paint;IILandroid/graphics/Bitmap;)V", &ret->NavitGraphics_draw_image))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "draw_image_warp", "(Landroid/graphics/Paint;IIIIIIILandroid/graphics/Bitmap;)V", &ret->NavitGraphics_draw_image_warp))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "draw_mode", "(I)V", &ret->NavitGraphics_draw_mode))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "draw_drag", "(II)V", &ret->NavitGraphics_draw_drag))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "overlay_disable", "(I)V", &ret->NavitGraphics_overlay_disable))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "overlay_resize", "(IIIII)V", &ret->NavitGraphics_overlay_resize))
- return 0;
- if (!find_method(ret->NavitGraphicsClass, "SetCamera", "(I)V", &ret->NavitGraphics_SetCamera))
- return 0;
+graphics_android_init(struct graphics_priv *ret, struct graphics_priv *parent, struct point *pnt, int w, int h,
+ int wraparound, int use_camera) {
+ struct callback *cb;
+ jmethodID cid, Context_getPackageName;
+
+ dbg(lvl_debug,"at 2 jnienv=%p",jnienv);
+ if (parent)
+ ret->padding = parent->padding;
+ if (!find_class_global("android/graphics/Paint", &ret->PaintClass))
+ return 0;
+ if (!find_method(ret->PaintClass, "<init>", "(I)V", &ret->Paint_init))
+ return 0;
+ if (!find_method(ret->PaintClass, "setARGB", "(IIII)V", &ret->Paint_setARGB))
+ return 0;
+ if (!find_method(ret->PaintClass, "setStrokeWidth", "(F)V", &ret->Paint_setStrokeWidth))
+ return 0;
+
+ if (!find_class_global("android/graphics/BitmapFactory", &ret->BitmapFactoryClass))
+ return 0;
+ if (!find_static_method(ret->BitmapFactoryClass, "decodeFile", "(Ljava/lang/String;)Landroid/graphics/Bitmap;",
+ &ret->BitmapFactory_decodeFile))
+ return 0;
+ if (!find_static_method(ret->BitmapFactoryClass, "decodeResource",
+ "(Landroid/content/res/Resources;I)Landroid/graphics/Bitmap;", &ret->BitmapFactory_decodeResource))
+ return 0;
+
+ if (!find_class_global("android/graphics/Bitmap", &ret->BitmapClass))
+ return 0;
+ if (!find_method(ret->BitmapClass, "getHeight", "()I", &ret->Bitmap_getHeight))
+ return 0;
+ if (!find_method(ret->BitmapClass, "getWidth", "()I", &ret->Bitmap_getWidth))
+ return 0;
+ if (!find_static_method(ret->BitmapClass, "createScaledBitmap",
+ "(Landroid/graphics/Bitmap;IIZ)Landroid/graphics/Bitmap;", &ret->Bitmap_createScaledBitmap))
+ return 0;
+
+ if (!find_class_global("android/content/Context", &ret->ContextClass))
+ return 0;
+ if (!find_method(ret->ContextClass, "getResources", "()Landroid/content/res/Resources;", &ret->Context_getResources))
+ return 0;
+
+
+ ret->Resources=(*jnienv)->CallObjectMethod(jnienv, android_activity, ret->Context_getResources);
+ if (ret->Resources)
+ ret->Resources = (*jnienv)->NewGlobalRef(jnienv, ret->Resources);
+ if (!find_class_global("android/content/res/Resources", &ret->ResourcesClass))
+ return 0;
+ if (!find_method(ret->ResourcesClass, "getIdentifier", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I",
+ &ret->Resources_getIdentifier))
+ return 0;
+
+ if (!find_method(ret->ContextClass, "getPackageName", "()Ljava/lang/String;", &Context_getPackageName))
+ return 0;
+ ret->packageName=(*jnienv)->CallObjectMethod(jnienv, android_activity, Context_getPackageName);
+ ret->packageName=(*jnienv)->NewGlobalRef(jnienv, ret->packageName);
+
+ if (!find_class_global("org/navitproject/navit/NavitGraphics", &ret->NavitGraphicsClass))
+ return 0;
+ dbg(lvl_debug,"at 3");
+ cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "<init>",
+ "(Landroid/app/Activity;Lorg/navitproject/navit/NavitGraphics;IIIIII)V");
+ if (cid == NULL) {
+ dbg(lvl_error,"no method found");
+ return 0; /* exception thrown */
+ }
+ dbg(lvl_debug,"at 4 android_activity=%p",android_activity);
+ ret->NavitGraphics=(*jnienv)->NewObject(jnienv, ret->NavitGraphicsClass, cid, android_activity,
+ parent ? parent->NavitGraphics : NULL, pnt ? pnt->x:0, pnt ? pnt->y:0, w, h, wraparound, use_camera);
+ dbg(lvl_debug,"result=%p",ret->NavitGraphics);
+ if (ret->NavitGraphics)
+ ret->NavitGraphics = (*jnienv)->NewGlobalRef(jnienv, ret->NavitGraphics);
+
+ /* Create a single global Paint, otherwise android will quickly run out
+ * of global refs.*/
+ /* 0x101 = text kerning (default), antialiasing */
+ ret->Paint=(*jnienv)->NewObject(jnienv, ret->PaintClass, ret->Paint_init, 0x101);
+
+ dbg(lvl_debug,"result=%p",ret->Paint);
+ if (ret->Paint)
+ ret->Paint = (*jnienv)->NewGlobalRef(jnienv, ret->Paint);
+
+ cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setSizeChangedCallback", "(I)V");
+ if (cid == NULL) {
+ dbg(lvl_error,"no SetResizeCallback method found");
+ return 0; /* exception thrown */
+ }
+ cb=callback_new_1(callback_cast(resize_callback), ret);
+ (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
+
+ cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setPaddingChangedCallback", "(I)V");
+ if (cid == NULL) {
+ dbg(lvl_error,"no SetPaddingCallback method found");
+ return 0; /* exception thrown */
+ }
+ cb=callback_new_1(callback_cast(padding_callback), ret);
+ (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
+
+ cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setButtonCallback", "(I)V");
+ if (cid == NULL) {
+ dbg(lvl_error,"no SetButtonCallback method found");
+ return 0; /* exception thrown */
+ }
+ cb=callback_new_1(callback_cast(button_callback), ret);
+ (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
+
+ cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setMotionCallback", "(I)V");
+ if (cid == NULL) {
+ dbg(lvl_error,"no SetMotionCallback method found");
+ return 0; /* exception thrown */
+ }
+ cb=callback_new_1(callback_cast(motion_callback), ret);
+ (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
+
+ cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setKeypressCallback", "(I)V");
+ if (cid == NULL) {
+ dbg(lvl_error,"no SetKeypressCallback method found");
+ return 0; /* exception thrown */
+ }
+ cb=callback_new_1(callback_cast(keypress_callback), ret);
+ (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
+
+ if (!find_method(ret->NavitGraphicsClass, "draw_polyline", "(Landroid/graphics/Paint;[I)V",
+ &ret->NavitGraphics_draw_polyline))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "draw_polygon", "(Landroid/graphics/Paint;[I)V",
+ &ret->NavitGraphics_draw_polygon))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "draw_rectangle", "(Landroid/graphics/Paint;IIII)V",
+ &ret->NavitGraphics_draw_rectangle))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "draw_circle", "(Landroid/graphics/Paint;III)V",
+ &ret->NavitGraphics_draw_circle))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "draw_text", "(Landroid/graphics/Paint;IILjava/lang/String;IIII)V",
+ &ret->NavitGraphics_draw_text))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "draw_image", "(Landroid/graphics/Paint;IILandroid/graphics/Bitmap;)V",
+ &ret->NavitGraphics_draw_image))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "draw_image_warp",
+ "(Landroid/graphics/Paint;IIIIIIILandroid/graphics/Bitmap;)V", &ret->NavitGraphics_draw_image_warp))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "draw_mode", "(I)V", &ret->NavitGraphics_draw_mode))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "draw_drag", "(II)V", &ret->NavitGraphics_draw_drag))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "overlay_disable", "(I)V", &ret->NavitGraphics_overlay_disable))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "overlay_resize", "(IIIII)V", &ret->NavitGraphics_overlay_resize))
+ return 0;
+ if (!find_method(ret->NavitGraphicsClass, "SetCamera", "(I)V", &ret->NavitGraphics_SetCamera))
+ return 0;
#if 0
- set_activity(ret->NavitGraphics);
+ set_activity(ret->NavitGraphics);
#endif
- return 1;
+ return 1;
}
static jclass NavitClass;
-static jmethodID Navit_disableSuspend, Navit_exit, Navit_fullscreen, Navit_runOptionsItem, Navit_showMenu, Navit_showNativeKeyboard, Navit_hideNativeKeyboard;
+static jmethodID Navit_disableSuspend, Navit_exit, Navit_fullscreen, Navit_runOptionsItem, Navit_showMenu,
+ Navit_showNativeKeyboard, Navit_hideNativeKeyboard;
static int
-graphics_android_fullscreen(struct window *win, int on)
-{
- (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_fullscreen, on);
- return 1;
+graphics_android_fullscreen(struct window *win, int on) {
+ (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_fullscreen, on);
+ return 1;
}
static void
-graphics_android_disable_suspend(struct window *win)
-{
- dbg(lvl_debug,"enter");
- (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_disableSuspend);
+graphics_android_disable_suspend(struct window *win) {
+ dbg(lvl_debug,"enter");
+ (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_disableSuspend);
}
/**
@@ -773,18 +759,18 @@ graphics_android_disable_suspend(struct window *win)
* @param valid
*/
static void
-graphics_android_cmd_runMenuItem(struct graphics_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- int ncmd=0;
- dbg(0,"Running %s",function);
- if(!strcmp(function,"map_download_dialog")) {
- ncmd=3;
- } else if(!strcmp(function,"backup_restore_dialog")) {
- ncmd=7;
- } else if(!strcmp(function,"set_map_location")) {
- ncmd=10;
- }
- (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_runOptionsItem, ncmd);
+graphics_android_cmd_runMenuItem(struct graphics_priv *this, char *function, struct attr **in, struct attr ***out,
+ int *valid) {
+ int ncmd=0;
+ dbg(0,"Running %s",function);
+ if(!strcmp(function,"map_download_dialog")) {
+ ncmd=3;
+ } else if(!strcmp(function,"backup_restore_dialog")) {
+ ncmd=7;
+ } else if(!strcmp(function,"set_map_location")) {
+ ncmd=10;
+ }
+ (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_runOptionsItem, ncmd);
}
/**
@@ -799,10 +785,10 @@ graphics_android_cmd_runMenuItem(struct graphics_priv *this, char *function, str
* @param valid
*/
static void
-graphics_android_cmd_menu(struct graphics_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
-{
- dbg(lvl_debug, "enter");
- (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_showMenu);
+graphics_android_cmd_menu(struct graphics_priv *this, char *function, struct attr **in, struct attr ***out,
+ int *valid) {
+ dbg(lvl_debug, "enter");
+ (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_showMenu);
}
/**
@@ -810,10 +796,10 @@ graphics_android_cmd_menu(struct graphics_priv *this, char *function, struct att
* this command.
*/
static struct command_table commands[] = {
- {"map_download_dialog",command_cast(graphics_android_cmd_runMenuItem)},
- {"set_map_location",command_cast(graphics_android_cmd_runMenuItem)},
- {"backup_restore_dialog",command_cast(graphics_android_cmd_runMenuItem)},
- {"menu", command_cast(graphics_android_cmd_menu)},
+ {"map_download_dialog",command_cast(graphics_android_cmd_runMenuItem)},
+ {"set_map_location",command_cast(graphics_android_cmd_runMenuItem)},
+ {"backup_restore_dialog",command_cast(graphics_android_cmd_runMenuItem)},
+ {"menu", command_cast(graphics_android_cmd_menu)},
};
/**
@@ -830,75 +816,75 @@ static struct command_table commands[] = {
* @return The new graphics instance
*/
static struct graphics_priv *
-graphics_android_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
- struct graphics_priv *ret;
- struct attr *attr;
- int use_camera=0;
- jmethodID cid;
- jint android_bgcolor;
-
- dbg(lvl_debug, "enter");
- if (!event_request_system("android","graphics_android"))
- return NULL;
- ret=g_new0(struct graphics_priv, 1);
-
- ret->cbl=cbl;
- *meth=graphics_methods;
- ret->win.priv=ret;
- ret->win.fullscreen=graphics_android_fullscreen;
- ret->win.disable_suspend=graphics_android_disable_suspend;
- ret->padding = g_new0(struct padding, 1);
- ret->padding->left = 0;
- ret->padding->top = 0;
- ret->padding->right = 0;
- ret->padding->bottom = 0;
- /* attr_background_color is the background color for system bars (API 17+ only) */
- if ((attr=attr_search(attrs, NULL, attr_background_color))) {
- ret->bgcolor = (attr->u.color->a / 0x101) << 24
- | (attr->u.color->r / 0x101) << 16
- | (attr->u.color->g / 0x101) << 8
- | (attr->u.color->b / 0x101);
- dbg(lvl_debug, "attr_background_color %04x %04x %04x %04x (%08x)",
- attr->u.color->r, attr->u.color->g, attr->u.color->b, attr->u.color->a, ret->bgcolor);
- } else {
- /* default is the same as for OSD */
- ret->bgcolor = 0x60000000;
- }
- if ((attr=attr_search(attrs, NULL, attr_use_camera))) {
- use_camera=attr->u.num;
- }
- if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
- command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), ret);
+graphics_android_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl) {
+ struct graphics_priv *ret;
+ struct attr *attr;
+ int use_camera=0;
+ jmethodID cid;
+ jint android_bgcolor;
+
+ dbg(lvl_debug, "enter");
+ if (!event_request_system("android","graphics_android"))
+ return NULL;
+ ret=g_new0(struct graphics_priv, 1);
+
+ ret->cbl=cbl;
+ *meth=graphics_methods;
+ ret->win.priv=ret;
+ ret->win.fullscreen=graphics_android_fullscreen;
+ ret->win.disable_suspend=graphics_android_disable_suspend;
+ ret->padding = g_new0(struct padding, 1);
+ ret->padding->left = 0;
+ ret->padding->top = 0;
+ ret->padding->right = 0;
+ ret->padding->bottom = 0;
+ /* attr_background_color is the background color for system bars (API 17+ only) */
+ if ((attr=attr_search(attrs, NULL, attr_background_color))) {
+ ret->bgcolor = (attr->u.color->a / 0x101) << 24
+ | (attr->u.color->r / 0x101) << 16
+ | (attr->u.color->g / 0x101) << 8
+ | (attr->u.color->b / 0x101);
+ dbg(lvl_debug, "attr_background_color %04x %04x %04x %04x (%08x)",
+ attr->u.color->r, attr->u.color->g, attr->u.color->b, attr->u.color->a, ret->bgcolor);
+ } else {
+ /* default is the same as for OSD */
+ ret->bgcolor = 0x60000000;
+ }
+ if ((attr=attr_search(attrs, NULL, attr_use_camera))) {
+ use_camera=attr->u.num;
+ }
+ if ((attr=attr_search(attrs, NULL, attr_callback_list))) {
+ command_add_table(attr->u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), ret);
+ }
+ image_cache_hash = g_hash_table_new(g_str_hash, g_str_equal);
+ if (graphics_android_init(ret, NULL, NULL, 0, 0, 0, use_camera)) {
+ cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "hasMenuButton", "()Z");
+ if (cid != NULL) {
+ attr = g_new0(struct attr, 1);
+ attr->type = attr_has_menu_button;
+ attr->u.num = (*jnienv)->CallBooleanMethod(jnienv, ret->NavitGraphics, cid);
+
+ /*
+ * Although the attribute refers to information obtained by the graphics plugin, we are storing it
+ * with the navit object: the object is easier to access from anywhere in the program, and ultimately
+ * it refers to a configuration value affecting all of Navit, thus users are likely to look for it in
+ * the navit object (as the fact that graphics also handles input devices is not immedately obvious).
+ */
+ navit_object_set_attr((struct navit_object *) nav, attr);
+ dbg(lvl_debug, "attr_has_menu_button=%d", attr->u.num);
+ g_free(attr);
+ }
+ ret->NavitGraphics_setBackgroundColor = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setBackgroundColor",
+ "(I)V");
+ if (ret->NavitGraphics_setBackgroundColor != NULL) {
+ (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, ret->NavitGraphics_setBackgroundColor, ret->bgcolor);
}
- image_cache_hash = g_hash_table_new(g_str_hash, g_str_equal);
- if (graphics_android_init(ret, NULL, NULL, 0, 0, 0, use_camera)) {
- cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "hasMenuButton", "()Z");
- if (cid != NULL) {
- attr = g_new0(struct attr, 1);
- attr->type = attr_has_menu_button;
- attr->u.num = (*jnienv)->CallBooleanMethod(jnienv, ret->NavitGraphics, cid);
-
- /*
- * Although the attribute refers to information obtained by the graphics plugin, we are storing it
- * with the navit object: the object is easier to access from anywhere in the program, and ultimately
- * it refers to a configuration value affecting all of Navit, thus users are likely to look for it in
- * the navit object (as the fact that graphics also handles input devices is not immedately obvious).
- */
- navit_object_set_attr((struct navit_object *) nav, attr);
- dbg(lvl_debug, "attr_has_menu_button=%d", attr->u.num);
- g_free(attr);
- }
- ret->NavitGraphics_setBackgroundColor = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setBackgroundColor", "(I)V");
- if (ret->NavitGraphics_setBackgroundColor != NULL) {
- (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, ret->NavitGraphics_setBackgroundColor, ret->bgcolor);
- }
- dbg(lvl_debug,"returning %p",ret);
- return ret;
- } else {
- g_free(ret);
- return NULL;
- }
+ dbg(lvl_debug,"returning %p",ret);
+ return ret;
+ } else {
+ g_free(ret);
+ return NULL;
+ }
}
/**
@@ -917,30 +903,27 @@ graphics_android_new(struct navit *nav, struct graphics_methods *meth, struct at
* @return The graphics instance for the new overlay
*/
static struct graphics_priv *
-overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound)
-{
- struct graphics_priv *ret=g_new0(struct graphics_priv, 1);
- *meth=graphics_methods;
- if (graphics_android_init(ret, gr, p, w, h, wraparound, 0)) {
- dbg(lvl_debug,"returning %p",ret);
- return ret;
- } else {
- g_free(ret);
- return NULL;
- }
+overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound) {
+ struct graphics_priv *ret=g_new0(struct graphics_priv, 1);
+ *meth=graphics_methods;
+ if (graphics_android_init(ret, gr, p, w, h, wraparound, 0)) {
+ dbg(lvl_debug,"returning %p",ret);
+ return ret;
+ } else {
+ g_free(ret);
+ return NULL;
+ }
}
static void
-event_android_main_loop_run(void)
-{
- dbg(lvl_debug,"enter");
+event_android_main_loop_run(void) {
+ dbg(lvl_debug,"enter");
}
-static void event_android_main_loop_quit(void)
-{
- dbg(lvl_debug,"enter");
- (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_exit);
+static void event_android_main_loop_quit(void) {
+ dbg(lvl_debug,"enter");
+ (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_exit);
}
@@ -957,191 +940,180 @@ static jmethodID NavitWatch_init;
static jmethodID NavitWatch_remove;
-static void do_poll(JNIEnv *env, int fd, int cond)
-{
- struct pollfd pfd;
- pfd.fd=fd;
- dbg(lvl_debug,"%p poll called for %d %d", fd, cond);
- switch ((enum event_watch_cond)cond) {
- case event_watch_cond_read:
- pfd.events=POLLIN;
- break;
- case event_watch_cond_write:
- pfd.events=POLLOUT;
- break;
- case event_watch_cond_except:
- pfd.events=POLLERR;
- break;
- default:
- pfd.events=0;
- }
- pfd.revents=0;
- poll(&pfd, 1, -1);
+static void do_poll(JNIEnv *env, int fd, int cond) {
+ struct pollfd pfd;
+ pfd.fd=fd;
+ dbg(lvl_debug,"%p poll called for %d %d", fd, cond);
+ switch ((enum event_watch_cond)cond) {
+ case event_watch_cond_read:
+ pfd.events=POLLIN;
+ break;
+ case event_watch_cond_write:
+ pfd.events=POLLOUT;
+ break;
+ case event_watch_cond_except:
+ pfd.events=POLLERR;
+ break;
+ default:
+ pfd.events=0;
+ }
+ pfd.revents=0;
+ poll(&pfd, 1, -1);
}
static struct event_watch *
-event_android_add_watch(int h, enum event_watch_cond cond, struct callback *cb)
-{
- jobject ret;
- ret=(*jnienv)->NewObject(jnienv, NavitWatchClass, NavitWatch_init, (int)do_poll, h, (int) cond, (int)cb);
- dbg(lvl_debug,"result for %d,%d,%p=%p",h,cond,cb,ret);
- if (ret)
- ret = (*jnienv)->NewGlobalRef(jnienv, ret);
- return (struct event_watch *)ret;
+event_android_add_watch(int h, enum event_watch_cond cond, struct callback *cb) {
+ jobject ret;
+ ret=(*jnienv)->NewObject(jnienv, NavitWatchClass, NavitWatch_init, (int)do_poll, h, (int) cond, (int)cb);
+ dbg(lvl_debug,"result for %d,%d,%p=%p",h,cond,cb,ret);
+ if (ret)
+ ret = (*jnienv)->NewGlobalRef(jnienv, ret);
+ return (struct event_watch *)ret;
}
static void
-event_android_remove_watch(struct event_watch *ev)
-{
- dbg(lvl_debug,"enter %p",ev);
- if (ev) {
- jobject obj=(jobject )ev;
- (*jnienv)->CallVoidMethod(jnienv, obj, NavitWatch_remove);
- (*jnienv)->DeleteGlobalRef(jnienv, obj);
- }
+event_android_remove_watch(struct event_watch *ev) {
+ dbg(lvl_debug,"enter %p",ev);
+ if (ev) {
+ jobject obj=(jobject )ev;
+ (*jnienv)->CallVoidMethod(jnienv, obj, NavitWatch_remove);
+ (*jnienv)->DeleteGlobalRef(jnienv, obj);
+ }
}
-struct event_timeout
-{
- void (*handle_timeout)(struct event_timeout *priv);
- jobject jni_timeout;
- int multi;
- struct callback *cb;
+struct event_timeout {
+ void (*handle_timeout)(struct event_timeout *priv);
+ jobject jni_timeout;
+ int multi;
+ struct callback *cb;
};
static void
-event_android_remove_timeout(struct event_timeout *priv)
-{
- if (priv && priv->jni_timeout) {
- (*jnienv)->CallVoidMethod(jnienv, priv->jni_timeout, NavitTimeout_remove);
- (*jnienv)->DeleteGlobalRef(jnienv, priv->jni_timeout);
- priv->jni_timeout = NULL;
- }
+event_android_remove_timeout(struct event_timeout *priv) {
+ if (priv && priv->jni_timeout) {
+ (*jnienv)->CallVoidMethod(jnienv, priv->jni_timeout, NavitTimeout_remove);
+ (*jnienv)->DeleteGlobalRef(jnienv, priv->jni_timeout);
+ priv->jni_timeout = NULL;
+ }
}
-static void event_android_handle_timeout(struct event_timeout *priv)
-{
- callback_call_0(priv->cb);
- if (!priv->multi)
- event_android_remove_timeout(priv);
+static void event_android_handle_timeout(struct event_timeout *priv) {
+ callback_call_0(priv->cb);
+ if (!priv->multi)
+ event_android_remove_timeout(priv);
}
static struct event_timeout *
-event_android_add_timeout(int timeout, int multi, struct callback *cb)
-{
- struct event_timeout *ret = g_new0(struct event_timeout, 1);
- ret->cb = cb;
- ret->multi = multi;
- ret->handle_timeout = event_android_handle_timeout;
- ret->jni_timeout = (*jnienv)->NewObject(jnienv, NavitTimeoutClass, NavitTimeout_init, timeout, multi, (int)ret);
- if (ret->jni_timeout)
- ret->jni_timeout = (*jnienv)->NewGlobalRef(jnienv, ret->jni_timeout);
- return ret;
+event_android_add_timeout(int timeout, int multi, struct callback *cb) {
+ struct event_timeout *ret = g_new0(struct event_timeout, 1);
+ ret->cb = cb;
+ ret->multi = multi;
+ ret->handle_timeout = event_android_handle_timeout;
+ ret->jni_timeout = (*jnienv)->NewObject(jnienv, NavitTimeoutClass, NavitTimeout_init, timeout, multi, (int)ret);
+ if (ret->jni_timeout)
+ ret->jni_timeout = (*jnienv)->NewGlobalRef(jnienv, ret->jni_timeout);
+ return ret;
}
static struct event_idle *
-event_android_add_idle(int priority, struct callback *cb)
-{
+event_android_add_idle(int priority, struct callback *cb) {
#if 0
- jobject ret;
- dbg(lvl_debug,"enter");
- ret=(*jnienv)->NewObject(jnienv, NavitIdleClass, NavitIdle_init, (int)cb);
- dbg(lvl_debug,"result for %p=%p",cb,ret);
- if (ret)
- ret = (*jnienv)->NewGlobalRef(jnienv, ret);
- return (struct event_idle *)ret;
+ jobject ret;
+ dbg(lvl_debug,"enter");
+ ret=(*jnienv)->NewObject(jnienv, NavitIdleClass, NavitIdle_init, (int)cb);
+ dbg(lvl_debug,"result for %p=%p",cb,ret);
+ if (ret)
+ ret = (*jnienv)->NewGlobalRef(jnienv, ret);
+ return (struct event_idle *)ret;
#endif
- return (struct event_idle *)event_android_add_timeout(1, 1, cb);
+ return (struct event_idle *)event_android_add_timeout(1, 1, cb);
}
static void
-event_android_remove_idle(struct event_idle *ev)
-{
+event_android_remove_idle(struct event_idle *ev) {
#if 0
- dbg(lvl_debug,"enter %p",ev);
- if (ev) {
- jobject obj=(jobject )ev;
- (*jnienv)->CallVoidMethod(jnienv, obj, NavitIdle_remove);
- (*jnienv)->DeleteGlobalRef(jnienv, obj);
- }
+ dbg(lvl_debug,"enter %p",ev);
+ if (ev) {
+ jobject obj=(jobject )ev;
+ (*jnienv)->CallVoidMethod(jnienv, obj, NavitIdle_remove);
+ (*jnienv)->DeleteGlobalRef(jnienv, obj);
+ }
#endif
- event_android_remove_timeout((struct event_timeout *)ev);
+ event_android_remove_timeout((struct event_timeout *)ev);
}
static void
-event_android_call_callback(struct callback_list *cb)
-{
- dbg(lvl_debug,"enter");
+event_android_call_callback(struct callback_list *cb) {
+ dbg(lvl_debug,"enter");
}
static struct event_methods event_android_methods = {
- event_android_main_loop_run,
- event_android_main_loop_quit,
- event_android_add_watch,
- event_android_remove_watch,
- event_android_add_timeout,
- event_android_remove_timeout,
- event_android_add_idle,
- event_android_remove_idle,
- event_android_call_callback,
+ event_android_main_loop_run,
+ event_android_main_loop_quit,
+ event_android_add_watch,
+ event_android_remove_watch,
+ event_android_add_timeout,
+ event_android_remove_timeout,
+ event_android_add_idle,
+ event_android_remove_idle,
+ event_android_call_callback,
};
static struct event_priv *
-event_android_new(struct event_methods *meth)
-{
- dbg(lvl_debug,"enter");
- if (!find_class_global("org/navitproject/navit/NavitTimeout", &NavitTimeoutClass))
- return NULL;
- NavitTimeout_init = (*jnienv)->GetMethodID(jnienv, NavitTimeoutClass, "<init>", "(IZI)V");
- if (NavitTimeout_init == NULL)
- return NULL;
- NavitTimeout_remove = (*jnienv)->GetMethodID(jnienv, NavitTimeoutClass, "remove", "()V");
- if (NavitTimeout_remove == NULL)
- return NULL;
+event_android_new(struct event_methods *meth) {
+ dbg(lvl_debug,"enter");
+ if (!find_class_global("org/navitproject/navit/NavitTimeout", &NavitTimeoutClass))
+ return NULL;
+ NavitTimeout_init = (*jnienv)->GetMethodID(jnienv, NavitTimeoutClass, "<init>", "(IZI)V");
+ if (NavitTimeout_init == NULL)
+ return NULL;
+ NavitTimeout_remove = (*jnienv)->GetMethodID(jnienv, NavitTimeoutClass, "remove", "()V");
+ if (NavitTimeout_remove == NULL)
+ return NULL;
#if 0
- if (!find_class_global("org/navitproject/navit/NavitIdle", &NavitIdleClass))
- return NULL;
- NavitIdle_init = (*jnienv)->GetMethodID(jnienv, NavitIdleClass, "<init>", "(I)V");
- if (NavitIdle_init == NULL)
- return NULL;
- NavitIdle_remove = (*jnienv)->GetMethodID(jnienv, NavitIdleClass, "remove", "()V");
- if (NavitIdle_remove == NULL)
- return NULL;
+ if (!find_class_global("org/navitproject/navit/NavitIdle", &NavitIdleClass))
+ return NULL;
+ NavitIdle_init = (*jnienv)->GetMethodID(jnienv, NavitIdleClass, "<init>", "(I)V");
+ if (NavitIdle_init == NULL)
+ return NULL;
+ NavitIdle_remove = (*jnienv)->GetMethodID(jnienv, NavitIdleClass, "remove", "()V");
+ if (NavitIdle_remove == NULL)
+ return NULL;
#endif
- if (!find_class_global("org/navitproject/navit/NavitWatch", &NavitWatchClass))
- return NULL;
- NavitWatch_init = (*jnienv)->GetMethodID(jnienv, NavitWatchClass, "<init>", "(IIII)V");
- if (NavitWatch_init == NULL)
- return NULL;
- NavitWatch_remove = (*jnienv)->GetMethodID(jnienv, NavitWatchClass, "remove", "()V");
- if (NavitWatch_remove == NULL)
- return NULL;
-
- if (!find_class_global("org/navitproject/navit/Navit", &NavitClass))
- return NULL;
- Navit_disableSuspend = (*jnienv)->GetMethodID(jnienv, NavitClass, "disableSuspend", "()V");
- if (Navit_disableSuspend == NULL)
- return NULL;
- Navit_exit = (*jnienv)->GetMethodID(jnienv, NavitClass, "exit", "()V");
- if (Navit_exit == NULL)
- return NULL;
- Navit_fullscreen = (*jnienv)->GetMethodID(jnienv, NavitClass, "fullscreen", "(I)V");
- if (Navit_fullscreen == NULL)
- return NULL;
- Navit_runOptionsItem = (*jnienv)->GetMethodID(jnienv, NavitClass, "runOptionsItem", "(I)V");
- if (Navit_runOptionsItem == NULL)
- return NULL;
- Navit_showMenu = (*jnienv)->GetMethodID(jnienv, NavitClass, "showMenu", "()V");
- if (Navit_showMenu == NULL)
- return NULL;
- Navit_showNativeKeyboard = (*jnienv)->GetMethodID(jnienv, NavitClass, "showNativeKeyboard", "()I");
- Navit_hideNativeKeyboard = (*jnienv)->GetMethodID(jnienv, NavitClass, "hideNativeKeyboard", "()V");
-
- dbg(lvl_debug,"ok");
- *meth=event_android_methods;
+ if (!find_class_global("org/navitproject/navit/NavitWatch", &NavitWatchClass))
+ return NULL;
+ NavitWatch_init = (*jnienv)->GetMethodID(jnienv, NavitWatchClass, "<init>", "(IIII)V");
+ if (NavitWatch_init == NULL)
return NULL;
+ NavitWatch_remove = (*jnienv)->GetMethodID(jnienv, NavitWatchClass, "remove", "()V");
+ if (NavitWatch_remove == NULL)
+ return NULL;
+
+ if (!find_class_global("org/navitproject/navit/Navit", &NavitClass))
+ return NULL;
+ Navit_disableSuspend = (*jnienv)->GetMethodID(jnienv, NavitClass, "disableSuspend", "()V");
+ if (Navit_disableSuspend == NULL)
+ return NULL;
+ Navit_exit = (*jnienv)->GetMethodID(jnienv, NavitClass, "exit", "()V");
+ if (Navit_exit == NULL)
+ return NULL;
+ Navit_fullscreen = (*jnienv)->GetMethodID(jnienv, NavitClass, "fullscreen", "(I)V");
+ if (Navit_fullscreen == NULL)
+ return NULL;
+ Navit_runOptionsItem = (*jnienv)->GetMethodID(jnienv, NavitClass, "runOptionsItem", "(I)V");
+ if (Navit_runOptionsItem == NULL)
+ return NULL;
+ Navit_showMenu = (*jnienv)->GetMethodID(jnienv, NavitClass, "showMenu", "()V");
+ if (Navit_showMenu == NULL)
+ return NULL;
+ Navit_showNativeKeyboard = (*jnienv)->GetMethodID(jnienv, NavitClass, "showNativeKeyboard", "()I");
+ Navit_hideNativeKeyboard = (*jnienv)->GetMethodID(jnienv, NavitClass, "hideNativeKeyboard", "()V");
+
+ dbg(lvl_debug,"ok");
+ *meth=event_android_methods;
+ return NULL;
}
@@ -1164,16 +1136,16 @@ event_android_new(struct event_methods *meth)
* @return True if the input method is going to be displayed, false if not.
*/
int show_native_keyboard (struct graphics_keyboard *kbd) {
- kbd->w = -1;
- if (Navit_showNativeKeyboard == NULL) {
- dbg(lvl_error, "method Navit.showNativeKeyboard() not found, cannot display keyboard");
- return 0;
- }
- kbd->h = (*jnienv)->CallIntMethod(jnienv, android_activity, Navit_showNativeKeyboard);
- dbg(lvl_error, "keyboard size is %d x %d px", kbd->w, kbd->h);
- dbg(lvl_error, "return");
- /* zero height means we're not showing a keyboard, therefore normalize height to boolean */
- return !!(kbd->h);
+ kbd->w = -1;
+ if (Navit_showNativeKeyboard == NULL) {
+ dbg(lvl_error, "method Navit.showNativeKeyboard() not found, cannot display keyboard");
+ return 0;
+ }
+ kbd->h = (*jnienv)->CallIntMethod(jnienv, android_activity, Navit_showNativeKeyboard);
+ dbg(lvl_error, "keyboard size is %d x %d px", kbd->w, kbd->h);
+ dbg(lvl_error, "return");
+ /* zero height means we're not showing a keyboard, therefore normalize height to boolean */
+ return !!(kbd->h);
}
@@ -1185,19 +1157,18 @@ int show_native_keyboard (struct graphics_keyboard *kbd) {
* will be freed by this function.
*/
void hide_native_keyboard (struct graphics_keyboard *kbd) {
- if (Navit_hideNativeKeyboard == NULL) {
- dbg(lvl_error, "method Navit.hideNativeKeyboard() not found, cannot dismiss keyboard");
- return;
- }
- (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_hideNativeKeyboard);
- g_free(kbd->gra_priv);
+ if (Navit_hideNativeKeyboard == NULL) {
+ dbg(lvl_error, "method Navit.hideNativeKeyboard() not found, cannot dismiss keyboard");
+ return;
+ }
+ (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_hideNativeKeyboard);
+ g_free(kbd->gra_priv);
}
void
-plugin_init(void)
-{
- dbg(lvl_debug,"enter");
- plugin_register_category_graphics("android", graphics_android_new);
- plugin_register_category_event("android", event_android_new);
+plugin_init(void) {
+ dbg(lvl_debug,"enter");
+ plugin_register_category_graphics("android", graphics_android_new);
+ plugin_register_category_event("android", event_android_new);
}
diff --git a/navit/graphics/egl/graphics_egl.c b/navit/graphics/egl/graphics_egl.c
index 8a500a00e..758528a37 100644
--- a/navit/graphics/egl/graphics_egl.c
+++ b/navit/graphics/egl/graphics_egl.c
@@ -88,7 +88,8 @@ struct graphics_priv {
struct graphics_gc_priv *background_gc;
enum draw_mode_num mode;
GLuint program;
- GLint mvp_location, position_location, color_location, texture_position_location, use_texture_location, texture_location;
+ GLint mvp_location, position_location, color_location, texture_position_location, use_texture_location,
+ texture_location;
struct callback_list *cbl;
struct font_freetype_methods freetype_methods;
struct navit *nav;
@@ -114,25 +115,24 @@ struct graphics_opengl_platform {
EGLConfig config[1];
};
-struct contour
-{
- struct point *p;
- unsigned int count;
+struct contour {
+ struct point *p;
+ unsigned int count;
};
static GHashTable *hImageData;
static int USERWANTSTOQUIT = 0;
static struct graphics_priv *graphics_priv_root;
static struct graphics_priv *graphics_opengl_new_helper(struct
- graphics_methods
- *meth);
+ graphics_methods
+ *meth);
/*
* GLES 2 Compatible vertex and fragment shaders
* Taken from opengl driver
*/
const char vertex_src [] =
-" \
+ " \
attribute vec2 position; \
attribute vec2 texture_position; \
uniform mat4 mvp; \
@@ -146,7 +146,7 @@ const char vertex_src [] =
";
const char fragment_src [] =
-" \
+ " \
uniform lowp vec4 avcolor; \
uniform sampler2D texture; \
uniform bool use_texture; \
@@ -166,140 +166,142 @@ const char fragment_src [] =
* Found at http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
* Adapted and debugged for this use
*/
-float area(const struct contour* contour)
-{
- int p, q;
- int n = contour->count - 1;
- float A = 0.f;
-
- for (p=n-1, q=0; q < n; p=q++)
- {
- A += contour->p[p].x * contour->p[q].y - contour->p[q].x * contour->p[p].y;
- }
- return A * .5f;
+float area(const struct contour* contour) {
+ int p, q;
+ int n = contour->count - 1;
+ float A = 0.f;
+
+ for (p=n-1, q=0; q < n; p=q++) {
+ A += contour->p[p].x * contour->p[q].y - contour->p[q].x * contour->p[p].y;
+ }
+ return A * .5f;
}
int
inside_triangle(float Ax, float Ay,
- float Bx, float By,
- float Cx, float Cy,
- float Px, float Py)
-{
- float ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy;
- float cCROSSap, bCROSScp, aCROSSbp;
-
- ax = Cx - Bx; ay = Cy - By;
- bx = Ax - Cx; by = Ay - Cy;
- cx = Bx - Ax; cy = By - Ay;
- apx= Px - Ax; apy= Py - Ay;
- bpx= Px - Bx; bpy= Py - By;
- cpx= Px - Cx; cpy= Py - Cy;
-
- aCROSSbp = ax*bpy - ay*bpx;
- cCROSSap = cx*apy - cy*apx;
- bCROSScp = bx*cpy - by*cpx;
-
- return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f));
+ float Bx, float By,
+ float Cx, float Cy,
+ float Px, float Py) {
+ float ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy;
+ float cCROSSap, bCROSScp, aCROSSbp;
+
+ ax = Cx - Bx;
+ ay = Cy - By;
+ bx = Ax - Cx;
+ by = Ay - Cy;
+ cx = Bx - Ax;
+ cy = By - Ay;
+ apx= Px - Ax;
+ apy= Py - Ay;
+ bpx= Px - Bx;
+ bpy= Py - By;
+ cpx= Px - Cx;
+ cpy= Py - Cy;
+
+ aCROSSbp = ax*bpy - ay*bpx;
+ cCROSSap = cx*apy - cy*apx;
+ bCROSScp = bx*cpy - by*cpx;
+
+ return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f));
}
int
-snip(const struct point* pnt,int u,int v,int w,int n,int *V)
-{
- int p;
- float Ax, Ay, Bx, By, Cx, Cy, Px, Py;
-
- Ax = pnt[V[u]].x;
- Ay = pnt[V[u]].y;
-
- Bx = pnt[V[v]].x;
- By = pnt[V[v]].y;
-
- Cx = pnt[V[w]].x;
- Cy = pnt[V[w]].y;
-
- if ( (((Bx-Ax)*(Cy-Ay)) - ((By-Ay)*(Cx-Ax))) < 0.f )
- return 0;
-
- for (p=0;p<n;p++)
- {
- if( (p == u) || (p == v) || (p == w) )
- continue;
- Px = pnt[V[p]].x;
- Py = pnt[V[p]].y;
- if (inside_triangle(Ax,Ay,Bx,By,Cx,Cy,Px,Py))
- return 0;
- }
-
- return 1;
+snip(const struct point* pnt,int u,int v,int w,int n,int *V) {
+ int p;
+ float Ax, Ay, Bx, By, Cx, Cy, Px, Py;
+
+ Ax = pnt[V[u]].x;
+ Ay = pnt[V[u]].y;
+
+ Bx = pnt[V[v]].x;
+ By = pnt[V[v]].y;
+
+ Cx = pnt[V[w]].x;
+ Cy = pnt[V[w]].y;
+
+ if ( (((Bx-Ax)*(Cy-Ay)) - ((By-Ay)*(Cx-Ax))) < 0.f )
+ return 0;
+
+ for (p=0; p<n; p++) {
+ if( (p == u) || (p == v) || (p == w) )
+ continue;
+ Px = pnt[V[p]].x;
+ Py = pnt[V[p]].y;
+ if (inside_triangle(Ax,Ay,Bx,By,Cx,Cy,Px,Py))
+ return 0;
+ }
+
+ return 1;
}
int
-process_triangles(const struct contour* contour, struct contour* result)
-{
- int v;
- int contour_size = contour->count - 1;
- int polygon_temp_size = contour_size * 80;
- int final_count = 0;
- result->p = malloc(sizeof(struct point) * polygon_temp_size);
-
- int n = contour_size;
- if ( n < 3 ) return 0;
-
- int *V = alloca(sizeof(int)*n);
-
- if ( 0.0f < area(contour) )
- for (v=0; v<n; v++) V[v] = v;
- else
- for(v=0; v<n; v++) V[v] = (n-1)-v;
-
- int nv = n;
-
- int count = 2*nv;
-
- for(v=nv-1; nv>2; )
- {
- /* if we loop, it is probably a non-simple polygon */
- if (0 >= (count--))
- {
- //** Triangulate: ERROR - probable bad polygon!
- break;
- }
-
- /* three consecutive vertices in current polygon, <u,v,w> */
- int u = v ; if (nv <= u) u = 0; /* previous */
- v = u+1; if (nv <= v) v = 0; /* new v */
- int w = v+1; if (nv <= w) w = 0; /* next */
-
- if ( snip(contour->p,u,v,w,nv,V) )
- {
- int a,b,c,s,t;
-
- /* true names of the vertices */
- a = V[u]; b = V[v]; c = V[w];
-
- /* output Triangle */
- result->p[final_count++] = contour->p[a];
- result->p[final_count++] = contour->p[b];
- result->p[final_count++] = contour->p[c];
-
- if (final_count >= polygon_temp_size){
- free(result->p);
- return 0;
- }
-
- /* remove v from remaining polygon */
- for(s=v,t=v+1;t<nv;s++,t++)
- V[s] = V[t];
- nv--;
-
- /* resest error detection counter */
- count = 2*nv;
- }
- }
-
- result->count = final_count;
-
- return 1;
+process_triangles(const struct contour* contour, struct contour* result) {
+ int v;
+ int contour_size = contour->count - 1;
+ int polygon_temp_size = contour_size * 80;
+ int final_count = 0;
+ result->p = malloc(sizeof(struct point) * polygon_temp_size);
+
+ int n = contour_size;
+ if ( n < 3 ) return 0;
+
+ int *V = alloca(sizeof(int)*n);
+
+ if ( 0.0f < area(contour) )
+ for (v=0; v<n; v++) V[v] = v;
+ else
+ for(v=0; v<n; v++) V[v] = (n-1)-v;
+
+ int nv = n;
+
+ int count = 2*nv;
+
+ for(v=nv-1; nv>2; ) {
+ /* if we loop, it is probably a non-simple polygon */
+ if (0 >= (count--)) {
+ //** Triangulate: ERROR - probable bad polygon!
+ break;
+ }
+
+ /* three consecutive vertices in current polygon, <u,v,w> */
+ int u = v ;
+ if (nv <= u) u = 0; /* previous */
+ v = u+1;
+ if (nv <= v) v = 0; /* new v */
+ int w = v+1;
+ if (nv <= w) w = 0; /* next */
+
+ if ( snip(contour->p,u,v,w,nv,V) ) {
+ int a,b,c,s,t;
+
+ /* true names of the vertices */
+ a = V[u];
+ b = V[v];
+ c = V[w];
+
+ /* output Triangle */
+ result->p[final_count++] = contour->p[a];
+ result->p[final_count++] = contour->p[b];
+ result->p[final_count++] = contour->p[c];
+
+ if (final_count >= polygon_temp_size) {
+ free(result->p);
+ return 0;
+ }
+
+ /* remove v from remaining polygon */
+ for(s=v,t=v+1; t<nv; s++,t++)
+ V[s] = V[t];
+ nv--;
+
+ /* resest error detection counter */
+ count = 2*nv;
+ }
+ }
+
+ result->count = final_count;
+
+ return 1;
}
// ** Efficient Polygon Triangulation **
@@ -308,9 +310,8 @@ process_triangles(const struct contour* contour, struct contour* result)
* Destroys SDL/EGL context
*/
static void
-sdl_egl_destroy(struct graphics_opengl_platform *egl)
-{
- if (egl->eglwindow){
+sdl_egl_destroy(struct graphics_opengl_platform *egl) {
+ if (egl->eglwindow) {
SDL_GL_DeleteContext(egl->eglcontext);
SDL_DestroyWindow(egl->eglwindow);
}
@@ -322,8 +323,7 @@ sdl_egl_destroy(struct graphics_opengl_platform *egl)
* Swap EGL buffer
*/
static void
-sdl_egl_swap_buffers(struct graphics_opengl_platform *egl)
-{
+sdl_egl_swap_buffers(struct graphics_opengl_platform *egl) {
SDL_GL_SwapWindow(egl->eglwindow);
}
@@ -331,8 +331,7 @@ sdl_egl_swap_buffers(struct graphics_opengl_platform *egl)
* Main graphic destroy
*/
static void
-graphics_destroy(struct graphics_priv *gr)
-{
+graphics_destroy(struct graphics_priv *gr) {
/*FIXME graphics_destroy is never called */
gr->freetype_methods.destroy();
g_free(gr);
@@ -342,22 +341,19 @@ graphics_destroy(struct graphics_priv *gr)
}
static void
-gc_destroy(struct graphics_gc_priv *gc)
-{
+gc_destroy(struct graphics_gc_priv *gc) {
g_free(gc);
gc = NULL;
}
static void
-gc_set_linewidth(struct graphics_gc_priv *gc, int w)
-{
+gc_set_linewidth(struct graphics_gc_priv *gc, int w) {
gc->linewidth = w;
}
static void
gc_set_dashes(struct graphics_gc_priv *gc, int width, int offset,
- unsigned char *dash_list, int n)
-{
+ unsigned char *dash_list, int n) {
int i;
const int cOpenglMaskBits = 16;
gc->dash_count = n;
@@ -388,7 +384,7 @@ gc_set_dashes(struct graphics_gc_priv *gc, int width, int offset,
++dash_list[i];
++num_error[i % 2];
} else if (0 < num_error[i % 2]
- && 2 < dash_list[i]) {
+ && 2 < dash_list[i]) {
++dash_list[i];
--num_error[i % 2];
}
@@ -413,8 +409,7 @@ gc_set_dashes(struct graphics_gc_priv *gc, int width, int offset,
static void
-gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
-{
+gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) {
gc->fr = c->r / 65535.0;
gc->fg = c->g / 65535.0;
gc->fb = c->b / 65535.0;
@@ -422,8 +417,7 @@ gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
}
static void
-gc_set_background(struct graphics_gc_priv *gc, struct color *c)
-{
+gc_set_background(struct graphics_gc_priv *gc, struct color *c) {
gc->br = c->r / 65535.0;
gc->bg = c->g / 65535.0;
gc->bb = c->b / 65535.0;
@@ -439,8 +433,7 @@ static struct graphics_gc_methods gc_methods = {
};
static struct graphics_gc_priv *
-gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
-{
+gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
struct graphics_gc_priv *gc = g_new0(struct graphics_gc_priv, 1);
*meth = gc_methods;
@@ -453,14 +446,13 @@ static struct graphics_image_priv image_error;
static struct graphics_image_priv *
image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name, int *w, int *h,
- struct point *hot, int rotation)
-{
+ struct point *hot, int rotation) {
struct graphics_image_priv *gi;
/* FIXME: meth is not used yet.. so gi leaks. at least xpm is small */
struct graphics_image_priv *curr_elem =
- g_hash_table_lookup(hImageData, name);
+ g_hash_table_lookup(hImageData, name);
if (curr_elem == &image_error) {
//found but couldn't be loaded
@@ -476,21 +468,18 @@ image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *n
if (strlen(name) < 4) {
g_hash_table_insert(hImageData, g_strdup(name),
- &image_error);
+ &image_error);
return NULL;
}
gi = g_new0(struct graphics_image_priv, 1);
gi->img = IMG_Load(name);
- if(gi->img)
- {
+ if(gi->img) {
*w=gi->img->w;
*h=gi->img->h;
hot->x=*w/2;
hot->y=*h/2;
- }
- else
- {
+ } else {
/* TODO: debug "colour parse errors" on xpm */
dbg(lvl_error,"image_new on '%s' failed: %s", name, IMG_GetError());
g_free(gi);
@@ -506,15 +495,13 @@ image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *n
}
static void
-image_free(struct graphics_priv *gr, struct graphics_image_priv * gi)
-{
+image_free(struct graphics_priv *gr, struct graphics_image_priv * gi) {
// SDL_FreeSurface(gi->img);
// g_free(gi);
}
static void
-set_color(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
+set_color(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
GLfloat col[4];
col[0]=gc->fr;
col[1]=gc->fg;
@@ -524,8 +511,7 @@ set_color(struct graphics_priv *gr, struct graphics_gc_priv *gc)
}
static void
-draw_array(struct graphics_priv *gr, struct point *p, int count, GLenum mode)
-{
+draw_array(struct graphics_priv *gr, struct point *p, int count, GLenum mode) {
int i;
GLf *x;//[count*2];
x = alloca(sizeof(GLf)*count*2);
@@ -539,8 +525,7 @@ draw_array(struct graphics_priv *gr, struct point *p, int count, GLenum mode)
}
static void
-draw_rectangle_do(struct graphics_priv *gr, struct point *p, int w, int h)
-{
+draw_rectangle_do(struct graphics_priv *gr, struct point *p, int w, int h) {
struct point pa[4];
pa[0]=pa[1]=pa[2]=pa[3]=*p;
pa[0].x+=w;
@@ -552,8 +537,7 @@ draw_rectangle_do(struct graphics_priv *gr, struct point *p, int w, int h)
static void
-draw_image_es(struct graphics_priv *gr, struct point *p, int w, int h, unsigned char *data)
-{
+draw_image_es(struct graphics_priv *gr, struct point *p, int w, int h, unsigned char *data) {
GLf x[8];
GLuint texture;
memset(x, 0, sizeof(x));
@@ -588,8 +572,7 @@ draw_image_es(struct graphics_priv *gr, struct point *p, int w, int h, unsigned
}
inline void
-get_overlay_pos(struct graphics_priv *gr, struct point *point_out)
-{
+get_overlay_pos(struct graphics_priv *gr, struct point *point_out) {
if (gr->parent == NULL) {
point_out->x = 0;
point_out->y = 0;
@@ -607,8 +590,7 @@ get_overlay_pos(struct graphics_priv *gr, struct point *point_out)
}
inline void
-draw_overlay(struct graphics_priv *gr)
-{
+draw_overlay(struct graphics_priv *gr) {
struct point p_eff;
GLf x[8];
@@ -638,11 +620,10 @@ draw_overlay(struct graphics_priv *gr)
static void
draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc,
- struct point *p, int count)
-{
+ struct point *p, int count) {
if ((gr->parent && !gr->parent->overlay_enabled)
- || (gr->parent && gr->parent->overlay_enabled
- && !gr->overlay_enabled)) {
+ || (gr->parent && gr->parent->overlay_enabled
+ && !gr->overlay_enabled)) {
return;
}
@@ -657,12 +638,11 @@ draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc,
static void
draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc,
- struct point *p, int count)
-{
+ struct point *p, int count) {
int ok;
if ((gr->parent && !gr->parent->overlay_enabled)
- || (gr->parent && gr->parent->overlay_enabled
- && !gr->overlay_enabled)) {
+ || (gr->parent && gr->parent->overlay_enabled
+ && !gr->overlay_enabled)) {
return;
}
set_color(gr, gc);
@@ -671,7 +651,7 @@ draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc,
contour.count = count;
contour.p = p;
ok = process_triangles(&contour, &result);
- if (ok && gr->fill_poly){
+ if (ok && gr->fill_poly) {
draw_array(gr, result.p, result.count, GL_TRIANGLES);
free(result.p);
} else {
@@ -681,11 +661,10 @@ draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc,
static void
draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc,
- struct point *p, int w, int h)
-{
+ struct point *p, int w, int h) {
if ((gr->parent && !gr->parent->overlay_enabled)
- || (gr->parent && gr->parent->overlay_enabled
- && !gr->overlay_enabled)) {
+ || (gr->parent && gr->parent->overlay_enabled
+ && !gr->overlay_enabled)) {
return;
}
set_color(gr, gc);
@@ -695,16 +674,16 @@ draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc,
static void
display_text_draw(struct font_freetype_text *text,
- struct graphics_priv *gr, struct graphics_gc_priv *fg,
- struct graphics_gc_priv *bg, int color, struct point *p)
-{
+ struct graphics_priv *gr, struct graphics_gc_priv *fg,
+ struct graphics_gc_priv *bg, int color, struct point *p) {
int i, x, y, stride;
struct font_freetype_glyph *g, **gp;
unsigned char *shadow, *glyph;
struct color transparent = { 0x0000, 0x0000, 0x0000, 0x0000 };
- struct color black =
- { fg->fr * 65535, fg->fg * 65535, fg->fb * 65535,
- fg->fa * 65535 };
+ struct color black = {
+ fg->fr * 65535, fg->fg * 65535, fg->fb * 65535,
+ fg->fa * 65535
+ };
struct color white = { 0xffff, 0xffff, 0xffff, 0xffff };
if (bg) {
@@ -752,9 +731,9 @@ display_text_draw(struct font_freetype_text *text,
if (color) {
shadow = g_malloc(stride * (g->h + 2));
gr->freetype_methods.get_shadow(g, shadow,
- stride,
- &white,
- &transparent);
+ stride,
+ &white,
+ &transparent);
struct point p;
p.x=((x + g->x) >> 6)-1;
@@ -781,12 +760,12 @@ display_text_draw(struct font_freetype_text *text,
glyph =
g_malloc(stride * g->h * 4);
gr->freetype_methods.get_glyph(g,
- glyph,
- stride
- * 4,
- &black,
- &white,
- &transparent);
+ glyph,
+ stride
+ * 4,
+ &black,
+ &white,
+ &transparent);
struct point p;
p.x=(x + g->x) >> 6;
p.y=(y + g->y) >> 6;
@@ -797,10 +776,10 @@ display_text_draw(struct font_freetype_text *text,
stride *= 4;
glyph = g_malloc(stride * g->h);
gr->freetype_methods.get_glyph(g, glyph,
- stride,
- &black,
- &white,
- &transparent);
+ stride,
+ &black,
+ &white,
+ &transparent);
struct point p;
p.x=(x + g->x) >> 6;
p.y=(y + g->y) >> 6;
@@ -816,12 +795,11 @@ display_text_draw(struct font_freetype_text *text,
static void
draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg,
- struct graphics_gc_priv *bg, struct graphics_font_priv *font,
- char *text, struct point *p, int dx, int dy)
-{
+ struct graphics_gc_priv *bg, struct graphics_font_priv *font,
+ char *text, struct point *p, int dx, int dy) {
if ((gr->parent && !gr->parent->overlay_enabled)
- || (gr->parent && gr->parent->overlay_enabled
- && !gr->overlay_enabled)) {
+ || (gr->parent && gr->parent->overlay_enabled
+ && !gr->overlay_enabled)) {
return;
}
@@ -835,8 +813,8 @@ draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg,
graphics_priv_root->dirty = 1;
t = gr->freetype_methods.text_new(text,
- (struct font_freetype_font *)
- font, dx, dy);
+ (struct font_freetype_font *)
+ font, dx, dy);
struct point p_eff;
p_eff.x = p->x;
@@ -849,14 +827,12 @@ draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg,
static void
draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg,
- struct point *p, struct graphics_image_priv *img)
-{
+ struct point *p, struct graphics_image_priv *img) {
draw_image_es(gr, p, img->img->w, img->img->h, img->img->pixels);
}
static void
-draw_drag(struct graphics_priv *gr, struct point *p)
-{
+draw_drag(struct graphics_priv *gr, struct point *p) {
if (p) {
gr->p.x = p->x;
gr->p.y = p->y;
@@ -864,8 +840,7 @@ draw_drag(struct graphics_priv *gr, struct point *p)
}
static void
-background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
+background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
gr->background_gc = gc;
}
@@ -873,8 +848,7 @@ background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
* Draws map in background
*/
static void
-draw_background(struct graphics_priv *gr)
-{
+draw_background(struct graphics_priv *gr) {
struct point p_eff;
GLf x[8];
@@ -909,24 +883,23 @@ draw_background(struct graphics_priv *gr)
and are recomposed altogether at draw_mode_end request for root
*/
static void
-draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
-{
+draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
GLfloat matrix[16];
struct graphics_priv *overlay = NULL;
int i;
- if (mode == draw_mode_begin){
+ if (mode == draw_mode_begin) {
// Should not be necessary...
// SDL_GL_MakeCurrent(gr->platform->eglwindow, gr->platform->eglcontext);
- if (gr->parent == NULL){
+ if (gr->parent == NULL) {
// Full redraw, reset drag position
gr->p.x = 0;
gr->p.y = 0;
}
// Need to setup appropriate projection matrix
- for (i = 0; i < 16 ; i++){
+ for (i = 0; i < 16 ; i++) {
matrix[i] = 0.0;
}
@@ -948,7 +921,7 @@ draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
if (mode == draw_mode_end && gr->parent == NULL) {
overlay = gr->overlays;
draw_background(gr);
- while(overlay){
+ while(overlay) {
if (gr->overlay_enabled)
draw_overlay(overlay);
overlay = overlay->next;
@@ -960,21 +933,18 @@ draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
}
static int
-graphics_opengl_fullscreen(struct window *w, int on)
-{
+graphics_opengl_fullscreen(struct window *w, int on) {
return 1;
}
static void
-graphics_opengl_disable_suspend(struct window *w)
-{
+graphics_opengl_disable_suspend(struct window *w) {
// No op
}
static GLuint
-load_shader(const char *shader_source, GLenum type)
-{
+load_shader(const char *shader_source, GLenum type) {
GLuint shader = glCreateShader(type);
glShaderSource(shader, 1, &shader_source, NULL);
@@ -984,8 +954,7 @@ load_shader(const char *shader_source, GLenum type)
}
static void *
-get_data(struct graphics_priv *this, const char *type)
-{
+get_data(struct graphics_priv *this, const char *type) {
GLuint vertexShader;
GLuint fragmentShader;
struct window* win;
@@ -993,18 +962,18 @@ get_data(struct graphics_priv *this, const char *type)
if (!strcmp(type, "gtk_widget")) {
fprintf(stderr,
- "Currently GTK gui is not yet supported with EGL graphics driver\n");
+ "Currently GTK gui is not yet supported with EGL graphics driver\n");
return NULL;
}
if(strcmp(type, "window") == 0) {
SDL_GL_MakeCurrent(this->platform->eglwindow, this->platform->eglcontext);
- glClearColor ( 0 , 0 , 0 , 1);
+ glClearColor ( 0, 0, 0, 1);
glClear ( GL_COLOR_BUFFER_BIT );
callback_list_call_attr_2(graphics_priv_root->cbl, attr_resize,
- GINT_TO_POINTER(this->width), GINT_TO_POINTER(this->height));
+ GINT_TO_POINTER(this->width), GINT_TO_POINTER(this->height));
this->program = glCreateProgram();
vertexShader = load_shader(vertex_src, GL_VERTEX_SHADER);
@@ -1039,8 +1008,7 @@ get_data(struct graphics_priv *this, const char *type)
}
static void
-overlay_disable(struct graphics_priv *gr, int disable)
-{
+overlay_disable(struct graphics_priv *gr, int disable) {
gr->overlay_enabled = !disable;
gr->force_redraw = 1;
draw_mode(gr, draw_mode_end);
@@ -1049,8 +1017,7 @@ overlay_disable(struct graphics_priv *gr, int disable)
// Need more testing
static void
overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h,
- int wraparound)
-{
+ int wraparound) {
int changed = 0;
int w2, h2;
@@ -1095,16 +1062,16 @@ overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h,
}
callback_list_call_attr_2(gr->cbl, attr_resize,
- GINT_TO_POINTER(gr->width),
- GINT_TO_POINTER(gr->height));
+ GINT_TO_POINTER(gr->width),
+ GINT_TO_POINTER(gr->height));
}
}
static struct graphics_priv *overlay_new(struct graphics_priv *gr,
- struct graphics_methods *meth,
- struct point *p, int w, int h,
- int wraparound);
+ struct graphics_methods *meth,
+ struct point *p, int w, int h,
+ int wraparound);
static struct graphics_methods graphics_methods = {
graphics_destroy,
@@ -1133,8 +1100,7 @@ static struct graphics_methods graphics_methods = {
};
static struct graphics_priv *
-graphics_opengl_new_helper(struct graphics_methods *meth)
-{
+graphics_opengl_new_helper(struct graphics_methods *meth) {
struct font_priv *(*font_freetype_new) (void *meth);
font_freetype_new = plugin_get_category_font("freetype");
@@ -1150,16 +1116,15 @@ graphics_opengl_new_helper(struct graphics_methods *meth)
meth->font_new =
(struct graphics_font_priv *
(*)(struct graphics_priv *, struct graphics_font_methods *,
- char *, int, int)) this->freetype_methods.font_new;
+ char *, int, int)) this->freetype_methods.font_new;
meth->get_text_bbox =
(void (*) (struct graphics_priv *, struct graphics_font_priv *,
- char *, int, int, struct point*, int)) this->freetype_methods.get_text_bbox;
+ char *, int, int, struct point*, int)) this->freetype_methods.get_text_bbox;
return this;
}
static void
-create_framebuffer_texture(struct graphics_priv *gr)
-{
+create_framebuffer_texture(struct graphics_priv *gr) {
GLenum status;
// Prepare a new framebuffer object
glGenFramebuffers(1, &gr->framebuffer_name);
@@ -1182,8 +1147,7 @@ create_framebuffer_texture(struct graphics_priv *gr)
static struct graphics_priv *
overlay_new(struct graphics_priv *gr, struct graphics_methods *meth,
- struct point *p, int w, int h, int wraparound)
-{
+ struct point *p, int w, int h, int wraparound) {
struct graphics_priv *this = graphics_opengl_new_helper(meth);
this->p.x = p->x;
@@ -1219,8 +1183,7 @@ overlay_new(struct graphics_priv *gr, struct graphics_methods *meth,
}
-static gboolean graphics_sdl_idle(void *data)
-{
+static gboolean graphics_sdl_idle(void *data) {
struct graphics_priv *gr = (struct graphics_priv *)data;
struct point p;
SDL_Event ev;
@@ -1230,17 +1193,14 @@ static gboolean graphics_sdl_idle(void *data)
char keycode;
// Process SDL events (KEYS + MOUSE)
- while(1)
- {
- ret = SDL_PollEvent(&ev);
+ while(1) {
+ ret = SDL_PollEvent(&ev);
- if(!ret)
- break;
+ if(!ret)
+ break;
- switch(ev.type)
- {
- case SDL_MOUSEMOTION:
- {
+ switch(ev.type) {
+ case SDL_MOUSEMOTION: {
p.x = ev.motion.x;
p.y = ev.motion.y;
//gr->force_redraw = 1;
@@ -1248,82 +1208,68 @@ static gboolean graphics_sdl_idle(void *data)
break;
}
- case SDL_KEYDOWN:
- {
+ case SDL_KEYDOWN: {
memset(keybuf, 0, sizeof(keybuf));
- switch(ev.key.keysym.sym)
- {
+ switch(ev.key.keysym.sym) {
case SDLK_F1:
graphics_priv_root->fill_poly = !graphics_priv_root->fill_poly;
break;
case SDLK_F2:
graphics_priv_root->show_overlays = !graphics_priv_root->show_overlays;
break;
- case SDLK_LEFT:
- {
+ case SDLK_LEFT: {
keybuf[0] = NAVIT_KEY_LEFT;
break;
- }
- case SDLK_RIGHT:
- {
+ }
+ case SDLK_RIGHT: {
keybuf[0] = NAVIT_KEY_RIGHT;
break;
- }
- case SDLK_BACKSPACE:
- {
+ }
+ case SDLK_BACKSPACE: {
keybuf[0] = NAVIT_KEY_BACKSPACE;
break;
- }
- case SDLK_RETURN:
- {
+ }
+ case SDLK_RETURN: {
keybuf[0] = NAVIT_KEY_RETURN;
break;
- }
- case SDLK_DOWN:
- {
+ }
+ case SDLK_DOWN: {
keybuf[0] = NAVIT_KEY_DOWN;
break;
- }
- case SDLK_PAGEUP:
- {
+ }
+ case SDLK_PAGEUP: {
keybuf[0] = NAVIT_KEY_ZOOM_OUT;
break;
- }
- case SDLK_UP:
- {
+ }
+ case SDLK_UP: {
keybuf[0] = NAVIT_KEY_UP;
break;
- }
- case SDLK_PAGEDOWN:
- {
+ }
+ case SDLK_PAGEDOWN: {
keybuf[0] = NAVIT_KEY_ZOOM_IN;
break;
- }
- case SDLK_ESCAPE:
- {
+ }
+ case SDLK_ESCAPE: {
USERWANTSTOQUIT = 1;
break;
- }
- default:
- {
+ }
+ default: {
/* return unicode chars when they can be converted to ascii */
// Need more work...
keycode = ev.key.keysym.sym;
keybuf[0] = keycode <= 127 ? keycode : 0;
break;
- }
+ }
}
if (keybuf[0]) {
callback_list_call_attr_1(gr->cbl, attr_keypress, (void *)keybuf);
}
break;
}
- case SDL_KEYUP:
- {
+ case SDL_KEYUP: {
break;
}
- case SDL_MOUSEBUTTONDOWN:
- {
+ case SDL_MOUSEBUTTONDOWN: {
p.x = ev.button.x;
p.y = ev.button.y;
graphics_priv_root->force_redraw = 1;
@@ -1331,26 +1277,23 @@ static gboolean graphics_sdl_idle(void *data)
break;
}
- case SDL_MOUSEBUTTONUP:
- {
+ case SDL_MOUSEBUTTONUP: {
p.x = ev.button.x;
p.y = ev.button.y;
callback_list_call_attr_3(gr->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER((int)ev.button.button), (void *)&p);
break;
}
- case SDL_QUIT:
- {
+ case SDL_QUIT: {
break;
}
- default:
- {
+ default: {
break;
}
- }
+ }
}
- if (USERWANTSTOQUIT){
+ if (USERWANTSTOQUIT) {
SDL_Quit();
exit(0);
}
@@ -1361,8 +1304,7 @@ static gboolean graphics_sdl_idle(void *data)
static struct graphics_priv *
graphics_opengl_new(struct navit *nav, struct graphics_methods *meth,
- struct attr **attrs, struct callback_list *cbl)
-{
+ struct attr **attrs, struct callback_list *cbl) {
struct attr *attr;
if (!event_request_system("glib", "graphics_opengl_new"))
return NULL;
@@ -1404,7 +1346,7 @@ graphics_opengl_new(struct navit *nav, struct graphics_methods *meth,
// SDL Init
int sdl_status = SDL_Init(SDL_INIT_VIDEO|SDL_INIT_EVENTS);
- if (sdl_status != 0){
+ if (sdl_status != 0) {
fprintf(stderr, "\nUnable to initialize SDL: %i %s\n", sdl_status, SDL_GetError() );
exit(1);
}
@@ -1421,13 +1363,13 @@ graphics_opengl_new(struct navit *nav, struct graphics_methods *meth,
SDL_GL_SetSwapInterval(0);
ret->eglwindow = SDL_CreateWindow(
- "Navit EGL", // window title
- SDL_WINDOWPOS_UNDEFINED, // initial x position
- SDL_WINDOWPOS_UNDEFINED, // initial y position
- this->width, // width, in pixels
- this->height, // height, in pixels
- flags
- );
+ "Navit EGL", // window title
+ SDL_WINDOWPOS_UNDEFINED, // initial x position
+ SDL_WINDOWPOS_UNDEFINED, // initial y position
+ this->width, // width, in pixels
+ this->height, // height, in pixels
+ flags
+ );
if (ret->eglwindow == NULL) {
fprintf(stderr, "\nUnable to initialize SDL window: %s\n", SDL_GetError() );
@@ -1435,7 +1377,7 @@ graphics_opengl_new(struct navit *nav, struct graphics_methods *meth,
}
ret->eglcontext = SDL_GL_CreateContext(ret->eglwindow);
- if (ret->eglcontext == NULL){
+ if (ret->eglcontext == NULL) {
printf("EGL context creation failed\n");
goto error;
}
@@ -1451,8 +1393,7 @@ error:
}
void
-plugin_init(void)
-{
+plugin_init(void) {
plugin_register_category_graphics("egl", graphics_opengl_new);
}
diff --git a/navit/graphics/gd/graphics_gd.c b/navit/graphics/gd/graphics_gd.c
index c2d09ae46..a4c59c823 100644
--- a/navit/graphics/gd/graphics_gd.c
+++ b/navit/graphics/gd/graphics_gd.c
@@ -48,8 +48,8 @@
#endif
struct shmem_header {
- int flag;
- int w,h,bpp;
+ int flag;
+ int w,h,bpp;
};
#ifdef HAVE_XPM
@@ -65,821 +65,786 @@ static void add_overlays(struct graphics_priv *overlay, gdImagePtr im);
#include <X11/xpm.h>
-BGD_DECLARE(gdImagePtr) gdImageCreateFromXpm (char *filename)
-{
- XpmInfo info;
- XpmImage image;
- int i, j, k, number;
- char buf[5];
- gdImagePtr im = 0;
- int *pointer;
- int red = 0, green = 0, blue = 0, alpha = 0;
- int *colors;
- int ret;
- ret = XpmReadFileToXpmImage (filename, &image, &info);
- if (ret != XpmSuccess)
- return 0;
-
- if (!(im = gdImageCreate (image.width, image.height)))
- return 0;
-
- number = image.ncolors;
- if (overflow2(sizeof (int), number)) {
- return 0;
- }
- colors = (int *) gdMalloc (sizeof (int) * number);
- if (colors == NULL)
- return (0);
- for (i = 0; i < number; i++)
- {
- alpha = 0;
- switch (strlen (image.colorTable[i].c_color))
- {
- case 4:
- if (!strcasecmp(image.colorTable[i].c_color,"none")) {
- red = 0;
- green = 0;
- blue = 0;
- alpha = 127;
- } else {
- buf[1] = '\0';
- buf[0] = image.colorTable[i].c_color[1];
- red = strtol (buf, NULL, 16);
-
- buf[0] = image.colorTable[i].c_color[3];
- green = strtol (buf, NULL, 16);
-
- buf[0] = image.colorTable[i].c_color[5];
- blue = strtol (buf, NULL, 16);
- }
- break;
- case 7:
- buf[2] = '\0';
- buf[0] = image.colorTable[i].c_color[1];
- buf[1] = image.colorTable[i].c_color[2];
- red = strtol (buf, NULL, 16);
-
- buf[0] = image.colorTable[i].c_color[3];
- buf[1] = image.colorTable[i].c_color[4];
- green = strtol (buf, NULL, 16);
-
- buf[0] = image.colorTable[i].c_color[5];
- buf[1] = image.colorTable[i].c_color[6];
- blue = strtol (buf, NULL, 16);
- break;
- case 10:
- buf[3] = '\0';
- buf[0] = image.colorTable[i].c_color[1];
- buf[1] = image.colorTable[i].c_color[2];
- buf[2] = image.colorTable[i].c_color[3];
- red = strtol (buf, NULL, 16);
- red /= 64;
-
- buf[0] = image.colorTable[i].c_color[4];
- buf[1] = image.colorTable[i].c_color[5];
- buf[2] = image.colorTable[i].c_color[6];
- green = strtol (buf, NULL, 16);
- green /= 64;
-
- buf[0] = image.colorTable[i].c_color[7];
- buf[1] = image.colorTable[i].c_color[8];
- buf[2] = image.colorTable[i].c_color[9];
- blue = strtol (buf, NULL, 16);
- blue /= 64;
- break;
- case 13:
- buf[4] = '\0';
- buf[0] = image.colorTable[i].c_color[1];
- buf[1] = image.colorTable[i].c_color[2];
- buf[2] = image.colorTable[i].c_color[3];
- buf[3] = image.colorTable[i].c_color[4];
- red = strtol (buf, NULL, 16);
- red /= 256;
-
- buf[0] = image.colorTable[i].c_color[5];
- buf[1] = image.colorTable[i].c_color[6];
- buf[2] = image.colorTable[i].c_color[7];
- buf[3] = image.colorTable[i].c_color[8];
- green = strtol (buf, NULL, 16);
- green /= 256;
-
- buf[0] = image.colorTable[i].c_color[9];
- buf[1] = image.colorTable[i].c_color[10];
- buf[2] = image.colorTable[i].c_color[11];
- buf[3] = image.colorTable[i].c_color[12];
- blue = strtol (buf, NULL, 16);
- blue /= 256;
- break;
- }
-
-
- colors[i] = gdImageColorResolveAlpha(im, red, green, blue, alpha);
- if (colors[i] == -1)
- fprintf (stderr, "ARRRGH\n");
+BGD_DECLARE(gdImagePtr) gdImageCreateFromXpm (char *filename) {
+ XpmInfo info;
+ XpmImage image;
+ int i, j, k, number;
+ char buf[5];
+ gdImagePtr im = 0;
+ int *pointer;
+ int red = 0, green = 0, blue = 0, alpha = 0;
+ int *colors;
+ int ret;
+ ret = XpmReadFileToXpmImage (filename, &image, &info);
+ if (ret != XpmSuccess)
+ return 0;
+
+ if (!(im = gdImageCreate (image.width, image.height)))
+ return 0;
+
+ number = image.ncolors;
+ if (overflow2(sizeof (int), number)) {
+ return 0;
+ }
+ colors = (int *) gdMalloc (sizeof (int) * number);
+ if (colors == NULL)
+ return (0);
+ for (i = 0; i < number; i++) {
+ alpha = 0;
+ switch (strlen (image.colorTable[i].c_color)) {
+ case 4:
+ if (!strcasecmp(image.colorTable[i].c_color,"none")) {
+ red = 0;
+ green = 0;
+ blue = 0;
+ alpha = 127;
+ } else {
+ buf[1] = '\0';
+ buf[0] = image.colorTable[i].c_color[1];
+ red = strtol (buf, NULL, 16);
+
+ buf[0] = image.colorTable[i].c_color[3];
+ green = strtol (buf, NULL, 16);
+
+ buf[0] = image.colorTable[i].c_color[5];
+ blue = strtol (buf, NULL, 16);
+ }
+ break;
+ case 7:
+ buf[2] = '\0';
+ buf[0] = image.colorTable[i].c_color[1];
+ buf[1] = image.colorTable[i].c_color[2];
+ red = strtol (buf, NULL, 16);
+
+ buf[0] = image.colorTable[i].c_color[3];
+ buf[1] = image.colorTable[i].c_color[4];
+ green = strtol (buf, NULL, 16);
+
+ buf[0] = image.colorTable[i].c_color[5];
+ buf[1] = image.colorTable[i].c_color[6];
+ blue = strtol (buf, NULL, 16);
+ break;
+ case 10:
+ buf[3] = '\0';
+ buf[0] = image.colorTable[i].c_color[1];
+ buf[1] = image.colorTable[i].c_color[2];
+ buf[2] = image.colorTable[i].c_color[3];
+ red = strtol (buf, NULL, 16);
+ red /= 64;
+
+ buf[0] = image.colorTable[i].c_color[4];
+ buf[1] = image.colorTable[i].c_color[5];
+ buf[2] = image.colorTable[i].c_color[6];
+ green = strtol (buf, NULL, 16);
+ green /= 64;
+
+ buf[0] = image.colorTable[i].c_color[7];
+ buf[1] = image.colorTable[i].c_color[8];
+ buf[2] = image.colorTable[i].c_color[9];
+ blue = strtol (buf, NULL, 16);
+ blue /= 64;
+ break;
+ case 13:
+ buf[4] = '\0';
+ buf[0] = image.colorTable[i].c_color[1];
+ buf[1] = image.colorTable[i].c_color[2];
+ buf[2] = image.colorTable[i].c_color[3];
+ buf[3] = image.colorTable[i].c_color[4];
+ red = strtol (buf, NULL, 16);
+ red /= 256;
+
+ buf[0] = image.colorTable[i].c_color[5];
+ buf[1] = image.colorTable[i].c_color[6];
+ buf[2] = image.colorTable[i].c_color[7];
+ buf[3] = image.colorTable[i].c_color[8];
+ green = strtol (buf, NULL, 16);
+ green /= 256;
+
+ buf[0] = image.colorTable[i].c_color[9];
+ buf[1] = image.colorTable[i].c_color[10];
+ buf[2] = image.colorTable[i].c_color[11];
+ buf[3] = image.colorTable[i].c_color[12];
+ blue = strtol (buf, NULL, 16);
+ blue /= 256;
+ break;
+ }
+
+
+ colors[i] = gdImageColorResolveAlpha(im, red, green, blue, alpha);
+ if (colors[i] == -1)
+ fprintf (stderr, "ARRRGH\n");
}
- pointer = (int *) image.data;
- for (i = 0; i < image.height; i++)
- {
- for (j = 0; j < image.width; j++)
- {
- k = *pointer++;
- gdImageSetPixel (im, j, i, colors[k]);
- }
+ pointer = (int *) image.data;
+ for (i = 0; i < image.height; i++) {
+ for (j = 0; j < image.width; j++) {
+ k = *pointer++;
+ gdImageSetPixel (im, j, i, colors[k]);
+ }
}
- gdFree (colors);
- return (im);
+ gdFree (colors);
+ return (im);
}
#endif
struct graphics_priv {
- gdImagePtr im;
- int w,h,flags,overlay,shmkey,shmsize,shmoffset;
- void *shm;
- struct shmem_header *shm_header;
- struct point p;
- struct callback *cb;
- struct callback_list *cbl;
- struct navit *nav;
- struct graphics_gc_priv *background;
- struct font_freetype_methods freetype_methods;
- struct window window;
- struct graphics_data_image image;
- struct graphics_priv *next,*overlays;
- GList *sockets;
+ gdImagePtr im;
+ int w,h,flags,overlay,shmkey,shmsize,shmoffset;
+ void *shm;
+ struct shmem_header *shm_header;
+ struct point p;
+ struct callback *cb;
+ struct callback_list *cbl;
+ struct navit *nav;
+ struct graphics_gc_priv *background;
+ struct font_freetype_methods freetype_methods;
+ struct window window;
+ struct graphics_data_image image;
+ struct graphics_priv *next,*overlays;
+ GList *sockets;
};
struct graphics_gc_priv {
- struct graphics_priv *gr;
- int color;
- int bgcolor;
- int width;
- struct color color2;
- unsigned char *dash_list;
- int dash_count;
- int dash_list_len;
+ struct graphics_priv *gr;
+ int color;
+ int bgcolor;
+ int width;
+ struct color color2;
+ unsigned char *dash_list;
+ int dash_count;
+ int dash_list_len;
};
struct graphics_image_priv {
- gdImagePtr im;
+ gdImagePtr im;
};
static void
-graphics_destroy(struct graphics_priv *gr)
-{
- gr->freetype_methods.destroy();
- g_free(gr);
+graphics_destroy(struct graphics_priv *gr) {
+ gr->freetype_methods.destroy();
+ g_free(gr);
}
static void
-gc_destroy(struct graphics_gc_priv *gc)
-{
- if (gc->color != -1)
- gdImageColorDeallocate(gc->gr->im, gc->color);
- if (gc->bgcolor != -1)
- gdImageColorDeallocate(gc->gr->im, gc->bgcolor);
- g_free(gc->dash_list);
- g_free(gc);
+gc_destroy(struct graphics_gc_priv *gc) {
+ if (gc->color != -1)
+ gdImageColorDeallocate(gc->gr->im, gc->color);
+ if (gc->bgcolor != -1)
+ gdImageColorDeallocate(gc->gr->im, gc->bgcolor);
+ g_free(gc->dash_list);
+ g_free(gc);
}
static void
-gc_set_linewidth(struct graphics_gc_priv *gc, int w)
-{
- gc->width=w;
+gc_set_linewidth(struct graphics_gc_priv *gc, int w) {
+ gc->width=w;
}
static void
-gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n)
-{
- int i,count=0;
- g_free(gc->dash_list);
- gc->dash_list=g_new(unsigned char, n);
- for (i = 0 ; i < n ; i++) {
- gc->dash_list[i]=dash_list[i];
- count+=dash_list[i];
- }
- gc->dash_list_len=n;
- gc->dash_count=count;
+gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n) {
+ int i,count=0;
+ g_free(gc->dash_list);
+ gc->dash_list=g_new(unsigned char, n);
+ for (i = 0 ; i < n ; i++) {
+ gc->dash_list[i]=dash_list[i];
+ count+=dash_list[i];
+ }
+ gc->dash_list_len=n;
+ gc->dash_count=count;
}
static void
-gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
-{
- gc->color2=*c;
- gc->color=gdImageColorAllocate(gc->gr->im, c->r>>8, c->g>>8, c->b>>8);
+gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) {
+ gc->color2=*c;
+ gc->color=gdImageColorAllocate(gc->gr->im, c->r>>8, c->g>>8, c->b>>8);
}
static void
-gc_set_background(struct graphics_gc_priv *gc, struct color *c)
-{
- gc->bgcolor=gdImageColorAllocate(gc->gr->im, c->r>>8, c->g>>8, c->b>>8);
+gc_set_background(struct graphics_gc_priv *gc, struct color *c) {
+ gc->bgcolor=gdImageColorAllocate(gc->gr->im, c->r>>8, c->g>>8, c->b>>8);
}
static struct graphics_gc_methods gc_methods = {
- gc_destroy,
- gc_set_linewidth,
- gc_set_dashes,
- gc_set_foreground,
- gc_set_background
+ gc_destroy,
+ gc_set_linewidth,
+ gc_set_dashes,
+ gc_set_foreground,
+ gc_set_background
};
-static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
-{
- struct graphics_gc_priv *ret=g_new0(struct graphics_gc_priv, 1);
- ret->gr=gr;
- ret->width=1;
- ret->color=-1;
- ret->bgcolor=-1;
- *meth=gc_methods;
- return ret;
+static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
+ struct graphics_gc_priv *ret=g_new0(struct graphics_gc_priv, 1);
+ ret->gr=gr;
+ ret->width=1;
+ ret->color=-1;
+ ret->bgcolor=-1;
+ *meth=gc_methods;
+ return ret;
}
static struct graphics_image_priv *
-image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name, int *w, int *h, struct point *hot, int rotation)
-{
- FILE *file;
- struct graphics_image_priv *ret=NULL;
- gdImagePtr im=NULL;
- int len;
-
- if (! name)
- return NULL;
- len=strlen(name);
- if (len < 4)
- return NULL;
- file=fopen(name,"r");
- if (file) {
- if (!strcmp(name+len-4,".png"))
+image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name, int *w, int *h, struct point *hot,
+ int rotation) {
+ FILE *file;
+ struct graphics_image_priv *ret=NULL;
+ gdImagePtr im=NULL;
+ int len;
+
+ if (! name)
+ return NULL;
+ len=strlen(name);
+ if (len < 4)
+ return NULL;
+ file=fopen(name,"r");
+ if (file) {
+ if (!strcmp(name+len-4,".png"))
#ifdef HAVE_GRAPHICS_GD_PNG
- im=gdImageCreateFromPng(file);
+ im=gdImageCreateFromPng(file);
#else
- im=NULL;
+ im=NULL;
#endif
- else if (!strcmp(name+len-4,".xpm"))
- im=gdImageCreateFromXpm(name);
- else if (!strcmp(name+len-4,".gif")) {
- im=gdImageCreateFromGif(file);
- }
- fclose(file);
- }
- if (im) {
- ret=g_new0(struct graphics_image_priv, 1);
- ret->im=im;
- *w=im->sx;
- *h=im->sy;
- hot->x=im->sx/2;
- hot->y=im->sy/2;
- }
- return ret;
+ else if (!strcmp(name+len-4,".xpm"))
+ im=gdImageCreateFromXpm(name);
+ else if (!strcmp(name+len-4,".gif")) {
+ im=gdImageCreateFromGif(file);
+ }
+ fclose(file);
+ }
+ if (im) {
+ ret=g_new0(struct graphics_image_priv, 1);
+ ret->im=im;
+ *w=im->sx;
+ *h=im->sy;
+ hot->x=im->sx/2;
+ hot->y=im->sy/2;
+ }
+ return ret;
}
static void
-draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
- int color[gc->dash_count],cc;
- int i,j,k=0;
-
- if (gc->dash_count) {
- cc=gc->color;
- for (i = 0 ; i < gc->dash_list_len ; i++) {
- for (j = 0 ; j < gc->dash_list[i] ; j++) {
- color[k++]=cc;
- }
- if (cc == gdTransparent)
- cc=gc->color;
- else
- cc=gdTransparent;
- }
- gdImageSetStyle(gr->im, color, gc->dash_count);
- }
- gdImageSetThickness(gr->im, gc->width);
- cc=gc->color;
- if (gr->flags & 8) {
- gdImageSetAntiAliased(gr->im, cc);
- cc=gdAntiAliased;
- }
+draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
+ int color[gc->dash_count],cc;
+ int i,j,k=0;
+
+ if (gc->dash_count) {
+ cc=gc->color;
+ for (i = 0 ; i < gc->dash_list_len ; i++) {
+ for (j = 0 ; j < gc->dash_list[i] ; j++) {
+ color[k++]=cc;
+ }
+ if (cc == gdTransparent)
+ cc=gc->color;
+ else
+ cc=gdTransparent;
+ }
+ gdImageSetStyle(gr->im, color, gc->dash_count);
+ }
+ gdImageSetThickness(gr->im, gc->width);
+ cc=gc->color;
+ if (gr->flags & 8) {
+ gdImageSetAntiAliased(gr->im, cc);
+ cc=gdAntiAliased;
+ }
#ifdef GD_NO_IMAGE_OPEN_POLYGON
- for (i = 0 ; i < count-1 ; i++)
- gdImageLine(gr->im, p[i].x, p[i].y, p[i+1].x, p[i+1].y, gc->dash_count ? gdStyled : cc);
+ for (i = 0 ; i < count-1 ; i++)
+ gdImageLine(gr->im, p[i].x, p[i].y, p[i+1].x, p[i+1].y, gc->dash_count ? gdStyled : cc);
#else
- gdImageOpenPolygon(gr->im, (gdPointPtr) p, count, gc->dash_count ? gdStyled : cc);
+ gdImageOpenPolygon(gr->im, (gdPointPtr) p, count, gc->dash_count ? gdStyled : cc);
#endif
}
static void
-draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
- int cc=gc->color;
- if (gr->flags & 8) {
- gdImageSetAntiAliased(gr->im, cc);
- cc=gdAntiAliased;
- }
- gdImageFilledPolygon(gr->im, (gdPointPtr) p, count, cc);
+draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
+ int cc=gc->color;
+ if (gr->flags & 8) {
+ gdImageSetAntiAliased(gr->im, cc);
+ cc=gdAntiAliased;
+ }
+ gdImageFilledPolygon(gr->im, (gdPointPtr) p, count, cc);
}
static void
-draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h)
-{
- int cc=gc->color;
- if (gr->flags & 8) {
- gdImageSetAntiAliased(gr->im, cc);
- cc=gdAntiAliased;
- }
- gdImageFilledRectangle(gr->im, p->x, p->y, p->x+w, p->y+h, cc);
+draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h) {
+ int cc=gc->color;
+ if (gr->flags & 8) {
+ gdImageSetAntiAliased(gr->im, cc);
+ cc=gdAntiAliased;
+ }
+ gdImageFilledRectangle(gr->im, p->x, p->y, p->x+w, p->y+h, cc);
}
static void
-draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r)
-{
- int cc=gc->color;
- if (gr->flags & 8) {
- gdImageSetAntiAliased(gr->im, cc);
- cc=gdAntiAliased;
- }
- gdImageSetThickness(gr->im, gc->width);
- gdImageArc(gr->im, p->x, p->y, r, r, 0, 360, cc);
+draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r) {
+ int cc=gc->color;
+ if (gr->flags & 8) {
+ gdImageSetAntiAliased(gr->im, cc);
+ cc=gdAntiAliased;
+ }
+ gdImageSetThickness(gr->im, gc->width);
+ gdImageArc(gr->im, p->x, p->y, r, r, 0, 360, cc);
}
static void
-draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy)
-{
- struct font_freetype_text *t;
- struct font_freetype_glyph *g, **gp;
- gdImagePtr im;
- int i,x,y,w,h;
- t=gr->freetype_methods.text_new(text, (struct font_freetype_font *)font, dx, dy);
- struct color fgc,bgc,transparent = {0x0, 0x0, 0x0, 0x7f7f};
- fgc=fg->color2;
- fgc.a=0;
-
- if (bg) {
- bgc=bg->color2;
- bgc.a=0;
- x=p->x << 6;
- y=p->y << 6;
- gp=t->glyph;
- i=t->glyph_count;
- while (i-- > 0)
- {
- g=*gp++;
- w=g->w;
- h=g->h;
- if (w && h) {
- im=gdImageCreateTrueColor(w+2, h+2);
- gr->freetype_methods.get_shadow(g,(unsigned char *)(im->tpixels),0,&bgc,&transparent);
- gdImageCopy(gr->im, im, ((x+g->x)>>6)-1, ((y+g->y)>>6)-1, 0, 0, w+2, h+2);
- gdImageDestroy(im);
- }
- x+=g->dx;
- y+=g->dy;
- }
- } else
- bgc=transparent;
- x=p->x << 6;
- y=p->y << 6;
- gp=t->glyph;
- i=t->glyph_count;
- while (i-- > 0)
- {
- g=*gp++;
- w=g->w;
- h=g->h;
- if (w && h) {
- im=gdImageCreateTrueColor(w, h);
- gr->freetype_methods.get_glyph(g,(unsigned char *)(im->tpixels),0,&fgc,&bgc,&transparent);
- gdImageCopy(gr->im, im, (x+g->x)>>6, (y+g->y)>>6, 0, 0, w, h);
- gdImageDestroy(im);
- }
- x+=g->dx;
- y+=g->dy;
- }
- gr->freetype_methods.text_destroy(t);
+draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg,
+ struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy) {
+ struct font_freetype_text *t;
+ struct font_freetype_glyph *g, **gp;
+ gdImagePtr im;
+ int i,x,y,w,h;
+ t=gr->freetype_methods.text_new(text, (struct font_freetype_font *)font, dx, dy);
+ struct color fgc,bgc,transparent = {0x0, 0x0, 0x0, 0x7f7f};
+ fgc=fg->color2;
+ fgc.a=0;
+
+ if (bg) {
+ bgc=bg->color2;
+ bgc.a=0;
+ x=p->x << 6;
+ y=p->y << 6;
+ gp=t->glyph;
+ i=t->glyph_count;
+ while (i-- > 0) {
+ g=*gp++;
+ w=g->w;
+ h=g->h;
+ if (w && h) {
+ im=gdImageCreateTrueColor(w+2, h+2);
+ gr->freetype_methods.get_shadow(g,(unsigned char *)(im->tpixels),0,&bgc,&transparent);
+ gdImageCopy(gr->im, im, ((x+g->x)>>6)-1, ((y+g->y)>>6)-1, 0, 0, w+2, h+2);
+ gdImageDestroy(im);
+ }
+ x+=g->dx;
+ y+=g->dy;
+ }
+ } else
+ bgc=transparent;
+ x=p->x << 6;
+ y=p->y << 6;
+ gp=t->glyph;
+ i=t->glyph_count;
+ while (i-- > 0) {
+ g=*gp++;
+ w=g->w;
+ h=g->h;
+ if (w && h) {
+ im=gdImageCreateTrueColor(w, h);
+ gr->freetype_methods.get_glyph(g,(unsigned char *)(im->tpixels),0,&fgc,&bgc,&transparent);
+ gdImageCopy(gr->im, im, (x+g->x)>>6, (y+g->y)>>6, 0, 0, w, h);
+ gdImageDestroy(im);
+ }
+ x+=g->dx;
+ y+=g->dy;
+ }
+ gr->freetype_methods.text_destroy(t);
}
static void
-draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img)
-{
- gdImageCopy(gr->im, img->im, p->x, p->y, 0, 0, img->im->sx, img->im->sy);
+draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img) {
+ gdImageCopy(gr->im, img->im, p->x, p->y, 0, 0, img->im->sx, img->im->sy);
}
static void
-draw_drag(struct graphics_priv *gr, struct point *p)
-{
- if (p)
- gr->p=*p;
- else {
- gr->p.x=0;
- gr->p.y=0;
- }
+draw_drag(struct graphics_priv *gr, struct point *p) {
+ if (p)
+ gr->p=*p;
+ else {
+ gr->p.x=0;
+ gr->p.y=0;
+ }
}
static void
-background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
- gr->background=gc;
+background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
+ gr->background=gc;
}
static void
-draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
-{
- FILE *pngout;
+draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
+ FILE *pngout;
#if 0
- if (mode == draw_mode_begin && gr->background) {
- gdImageFilledRectangle(gr->im, 0, 0, gr->w, gr->h, gr->background->color);
- }
+ if (mode == draw_mode_begin && gr->background) {
+ gdImageFilledRectangle(gr->im, 0, 0, gr->w, gr->h, gr->background->color);
+ }
#endif
- if (mode == draw_mode_end && !gr->overlay) {
- add_overlays(gr->overlays, gr->im);
- if (!(gr->flags & 1)) {
+ if (mode == draw_mode_end && !gr->overlay) {
+ add_overlays(gr->overlays, gr->im);
+ if (!(gr->flags & 1)) {
#ifdef HAVE_GRAPHICS_GD_PNG
- rename("test.png","test.png.old");
- pngout=fopen("test.png", "wb");
- gdImagePng(gr->im, pngout);
- fclose(pngout);
+ rename("test.png","test.png.old");
+ pngout=fopen("test.png", "wb");
+ gdImagePng(gr->im, pngout);
+ fclose(pngout);
#else
- rename("test.gd","test.gd.old");
- pngout=fopen("test.gd", "wb");
- gdImageGd(gr->im, pngout);
- fclose(pngout);
+ rename("test.gd","test.gd.old");
+ pngout=fopen("test.gd", "wb");
+ gdImageGd(gr->im, pngout);
+ fclose(pngout);
#endif
- }
- if (gr->flags & 2) {
- struct shmem_header *next=shm_next(gr);
- gr->shm_header->flag=1;
- dbg(lvl_debug,"next flag is %d",next->flag);
- if (!next->flag) {
- gr->shm_header=next;
- image_setup(gr);
- }
- }
+ }
+ if (gr->flags & 2) {
+ struct shmem_header *next=shm_next(gr);
+ gr->shm_header->flag=1;
+ dbg(lvl_debug,"next flag is %d",next->flag);
+ if (!next->flag) {
+ gr->shm_header=next;
+ image_setup(gr);
+ }
+ }
#ifdef HAVE_GRAPHICS_GD_PNG
#ifdef HAVE_SOCKET
- if (gr->flags & 4) {
- int size, size_written;
- void *data=gdImagePngPtr(gr->im, &size);
- GList *sockets=gr->sockets;
- while (sockets) {
- int fd=socket(PF_INET, SOCK_STREAM, 0);
- if (fd < 0) {
- dbg(lvl_error,"socket failed");
- } else {
- if (connect(fd, (struct sockaddr *)sockets->data, sizeof(struct sockaddr_in)) < 0) {
- dbg(lvl_error,"connect failed");
- } else {
- size_written=write(fd, data, size);
- dbg(lvl_debug,"size %d vs %d",size, size_written);
- if (shutdown(fd, SHUT_RDWR) < 0)
- dbg(lvl_error,"shutdown failed");
- }
- close(fd);
- }
- sockets=g_list_next(sockets);
- }
- gdFree(data);
- }
+ if (gr->flags & 4) {
+ int size, size_written;
+ void *data=gdImagePngPtr(gr->im, &size);
+ GList *sockets=gr->sockets;
+ while (sockets) {
+ int fd=socket(PF_INET, SOCK_STREAM, 0);
+ if (fd < 0) {
+ dbg(lvl_error,"socket failed");
+ } else {
+ if (connect(fd, (struct sockaddr *)sockets->data, sizeof(struct sockaddr_in)) < 0) {
+ dbg(lvl_error,"connect failed");
+ } else {
+ size_written=write(fd, data, size);
+ dbg(lvl_debug,"size %d vs %d",size, size_written);
+ if (shutdown(fd, SHUT_RDWR) < 0)
+ dbg(lvl_error,"shutdown failed");
+ }
+ close(fd);
+ }
+ sockets=g_list_next(sockets);
+ }
+ gdFree(data);
+ }
#endif
#endif
- }
+ }
}
-static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound);
+static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p,
+ int w, int h, int wraparound);
static void
-add_overlays(struct graphics_priv *overlay, gdImagePtr im)
-{
- while (overlay) {
- if (overlay->background) {
- gdImagePtr res,src;
- int y,x;
- int bgcol=overlay->background->color;
- res=gdImageCreateTrueColor(overlay->w,overlay->h);
- src=gdImageCreateTrueColor(overlay->w,overlay->h);
- gdImageCopy(src, im, 0, 0, overlay->p.x, overlay->p.y, overlay->w, overlay->h);
- for (y = 0 ; y < overlay->h ; y++) {
- unsigned int *res_line=res->tpixels[y];
- unsigned int *src_line=src->tpixels[y];
- unsigned int *overlay_line=overlay->im->tpixels[y];
- for (x = 0 ; x < overlay->w ; x++) {
- if (overlay_line[x] != bgcol)
- res_line[x]=overlay_line[x];
- else
- res_line[x]=src_line[x];
- }
- }
- gdImageCopy(im, res, overlay->p.x, overlay->p.y, 0, 0, overlay->w, overlay->h);
- gdImageDestroy(res);
- gdImageDestroy(src);
- } else
- gdImageCopy(im, overlay->im, overlay->p.x, overlay->p.y, 0, 0, overlay->w, overlay->h);
- overlay=overlay->next;
- }
+add_overlays(struct graphics_priv *overlay, gdImagePtr im) {
+ while (overlay) {
+ if (overlay->background) {
+ gdImagePtr res,src;
+ int y,x;
+ int bgcol=overlay->background->color;
+ res=gdImageCreateTrueColor(overlay->w,overlay->h);
+ src=gdImageCreateTrueColor(overlay->w,overlay->h);
+ gdImageCopy(src, im, 0, 0, overlay->p.x, overlay->p.y, overlay->w, overlay->h);
+ for (y = 0 ; y < overlay->h ; y++) {
+ unsigned int *res_line=res->tpixels[y];
+ unsigned int *src_line=src->tpixels[y];
+ unsigned int *overlay_line=overlay->im->tpixels[y];
+ for (x = 0 ; x < overlay->w ; x++) {
+ if (overlay_line[x] != bgcol)
+ res_line[x]=overlay_line[x];
+ else
+ res_line[x]=src_line[x];
+ }
+ }
+ gdImageCopy(im, res, overlay->p.x, overlay->p.y, 0, 0, overlay->w, overlay->h);
+ gdImageDestroy(res);
+ gdImageDestroy(src);
+ } else
+ gdImageCopy(im, overlay->im, overlay->p.x, overlay->p.y, 0, 0, overlay->w, overlay->h);
+ overlay=overlay->next;
+ }
}
static void *
-get_data(struct graphics_priv *this, char *type)
-{
- int b;
- struct point p;
- gdImagePtr im = this->im;
- dbg(lvl_debug,"type=%s",type);
- if (!strcmp(type,"window"))
- return &this->window;
- if (!strcmp(type,"image_png")) {
- if (this->overlays) {
- struct graphics_priv *overlay=this->overlays;
- im=gdImageCreateTrueColor(this->w,this->h);
- gdImageCopy(im, this->im, 0, 0, 0, 0, this->w, this->h);
- add_overlays(overlay, im);
- }
- if (this->image.data)
- gdFree(this->image.data);
+get_data(struct graphics_priv *this, char *type) {
+ int b;
+ struct point p;
+ gdImagePtr im = this->im;
+ dbg(lvl_debug,"type=%s",type);
+ if (!strcmp(type,"window"))
+ return &this->window;
+ if (!strcmp(type,"image_png")) {
+ if (this->overlays) {
+ struct graphics_priv *overlay=this->overlays;
+ im=gdImageCreateTrueColor(this->w,this->h);
+ gdImageCopy(im, this->im, 0, 0, 0, 0, this->w, this->h);
+ add_overlays(overlay, im);
+ }
+ if (this->image.data)
+ gdFree(this->image.data);
#ifdef HAVE_GRAPHICS_GD_PNG
- this->image.data=gdImagePngPtr(im, &this->image.size);
+ this->image.data=gdImagePngPtr(im, &this->image.size);
#else
- this->image.data=NULL;
+ this->image.data=NULL;
#endif
- if (this->overlays)
- gdImageDestroy(im);
- return &this->image;
- }
- if (sscanf(type,"click_%d_%d_%d",&p.x,&p.y,&b) == 3) {
- dbg(lvl_debug,"click %d %d %d",p.x,p.y,b);
- callback_list_call_attr_3(this->cbl, attr_button, (void *)b, (void *)1, (void *)&p);
- }
- if (sscanf(type,"move_%d_%d",&p.x,&p.y) == 2) {
- dbg(lvl_debug,"move %d %d",p.x,p.y);
- callback_list_call_attr_1(this->cbl, attr_motion, (void *)&p);
- }
- return NULL;
+ if (this->overlays)
+ gdImageDestroy(im);
+ return &this->image;
+ }
+ if (sscanf(type,"click_%d_%d_%d",&p.x,&p.y,&b) == 3) {
+ dbg(lvl_debug,"click %d %d %d",p.x,p.y,b);
+ callback_list_call_attr_3(this->cbl, attr_button, (void *)b, (void *)1, (void *)&p);
+ }
+ if (sscanf(type,"move_%d_%d",&p.x,&p.y) == 2) {
+ dbg(lvl_debug,"move %d %d",p.x,p.y);
+ callback_list_call_attr_1(this->cbl, attr_motion, (void *)&p);
+ }
+ return NULL;
}
static void
-image_free(struct graphics_priv *gr, struct graphics_image_priv *priv)
-{
- gdImageDestroy(priv->im);
- g_free(priv);
+image_free(struct graphics_priv *gr, struct graphics_image_priv *priv) {
+ gdImageDestroy(priv->im);
+ g_free(priv);
}
static void
-overlay_disable(struct graphics_priv *gr, int disable)
-{
- dbg(lvl_debug,"enter");
+overlay_disable(struct graphics_priv *gr, int disable) {
+ dbg(lvl_debug,"enter");
}
static void
-overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h, int wraparound)
-{
- dbg(lvl_debug,"enter");
+overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h, int wraparound) {
+ dbg(lvl_debug,"enter");
}
struct shmem_header *
-shm_next(struct graphics_priv *gr)
-{
- char *next=(char *)gr->shm_header+gr->shmoffset;
- if (next+gr->shmoffset > (char *)gr->shm+gr->shmsize) {
- dbg(lvl_debug,"wraparound");
- return gr->shm;
- }
- dbg(lvl_debug,"next 0x%x (offset 0x%x)",next-(char *)gr->shm,gr->shmoffset);
- return (struct shmem_header *)next;
-
+shm_next(struct graphics_priv *gr) {
+ char *next=(char *)gr->shm_header+gr->shmoffset;
+ if (next+gr->shmoffset > (char *)gr->shm+gr->shmsize) {
+ dbg(lvl_debug,"wraparound");
+ return gr->shm;
+ }
+ dbg(lvl_debug,"next 0x%x (offset 0x%x)",next-(char *)gr->shm,gr->shmoffset);
+ return (struct shmem_header *)next;
+
}
static void
-image_setup(struct graphics_priv *gr)
-{
- int i,*shm=(int *)(gr->shm_header+1);
- if (!gr->shmkey)
- return;
- for (i = 0 ; i < gr->h ; i++)
- gr->im->tpixels[i]=shm+gr->w*i;
- gr->shm_header->w=gr->w;
- gr->shm_header->h=gr->h;
- gr->shm_header->bpp=32;
- gr->shm_header->flag=0;
+image_setup(struct graphics_priv *gr) {
+ int i,*shm=(int *)(gr->shm_header+1);
+ if (!gr->shmkey)
+ return;
+ for (i = 0 ; i < gr->h ; i++)
+ gr->im->tpixels[i]=shm+gr->w*i;
+ gr->shm_header->w=gr->w;
+ gr->shm_header->h=gr->h;
+ gr->shm_header->bpp=32;
+ gr->shm_header->flag=0;
}
static void
-image_create(struct graphics_priv *gr)
-{
- dbg(lvl_debug,"shmkey %d",gr->shmkey);
+image_create(struct graphics_priv *gr) {
+ dbg(lvl_debug,"shmkey %d",gr->shmkey);
#ifdef HAVE_SHMEM
- if (gr->shmkey) {
- int size=gr->h*gr->w*sizeof(int);
- int shmid=shmget(gr->shmkey, size, 0666);
- dbg(lvl_debug,"shmid for key 0x%x is 0x%x",gr->shmkey, shmid);
- if (shmid < 0)
- dbg(lvl_debug,"shmget");
- gr->shm=shmat(shmid, NULL, 0);
- if (!gr->shm)
- dbg(lvl_debug,"shmat");
- gr->shm_header=gr->shm;
- gr->im=g_new0(gdImage,1);
- gr->im->tpixels=g_new(int *,gr->h);
- gr->im->sx=gr->w;
- gr->im->sy=gr->h;
- gr->im->transparent=-1;
- gr->im->trueColor=1;
- gr->im->alphaBlendingFlag=1;
- gr->im->thick=1;
- gr->im->cx2=gr->im->sx-1;
- gr->im->cy2=gr->im->sy-1;
- image_setup(gr);
- } else
+ if (gr->shmkey) {
+ int size=gr->h*gr->w*sizeof(int);
+ int shmid=shmget(gr->shmkey, size, 0666);
+ dbg(lvl_debug,"shmid for key 0x%x is 0x%x",gr->shmkey, shmid);
+ if (shmid < 0)
+ dbg(lvl_debug,"shmget");
+ gr->shm=shmat(shmid, NULL, 0);
+ if (!gr->shm)
+ dbg(lvl_debug,"shmat");
+ gr->shm_header=gr->shm;
+ gr->im=g_new0(gdImage,1);
+ gr->im->tpixels=g_new(int *,gr->h);
+ gr->im->sx=gr->w;
+ gr->im->sy=gr->h;
+ gr->im->transparent=-1;
+ gr->im->trueColor=1;
+ gr->im->alphaBlendingFlag=1;
+ gr->im->thick=1;
+ gr->im->cx2=gr->im->sx-1;
+ gr->im->cy2=gr->im->sy-1;
+ image_setup(gr);
+ } else
#endif
- gr->im=gdImageCreateTrueColor(gr->w,gr->h);
+ gr->im=gdImageCreateTrueColor(gr->w,gr->h);
}
static void
-image_destroy(struct graphics_priv *gr)
-{
+image_destroy(struct graphics_priv *gr) {
#ifdef HAVE_SHMEM
- if (gr->shmkey) {
- shmdt(gr->shm);
- g_free(gr->im->tpixels);
- g_free(gr->im);
- } else
+ if (gr->shmkey) {
+ shmdt(gr->shm);
+ g_free(gr->im->tpixels);
+ g_free(gr->im);
+ } else
#endif
- gdImageDestroy(gr->im);
- gr->im=NULL;
+ gdImageDestroy(gr->im);
+ gr->im=NULL;
}
static int
-set_attr_do(struct graphics_priv *gr, struct attr *attr, int init)
-{
- char *s,*c,*n,*p;
- switch (attr->type) {
- case attr_w:
- if (gr->w != attr->u.num) {
- gr->w=attr->u.num;
- if (!init) {
- if (gr->im)
- image_destroy(gr);
- image_create(gr);
- emit_callback(gr);
- }
- }
- break;
- case attr_h:
- if (gr->h != attr->u.num) {
- gr->h=attr->u.num;
- if (!init) {
- if (gr->im)
- image_destroy(gr);
- image_create(gr);
- emit_callback(gr);
- }
- }
- break;
- case attr_flags:
- gr->flags=attr->u.num;
- break;
- case attr_shmkey:
- gr->shmkey=attr->u.num;
- break;
- case attr_shmsize:
- gr->shmsize=attr->u.num;
- break;
- case attr_shmoffset:
- gr->shmoffset=attr->u.num;
- break;
+set_attr_do(struct graphics_priv *gr, struct attr *attr, int init) {
+ char *s,*c,*n,*p;
+ switch (attr->type) {
+ case attr_w:
+ if (gr->w != attr->u.num) {
+ gr->w=attr->u.num;
+ if (!init) {
+ if (gr->im)
+ image_destroy(gr);
+ image_create(gr);
+ emit_callback(gr);
+ }
+ }
+ break;
+ case attr_h:
+ if (gr->h != attr->u.num) {
+ gr->h=attr->u.num;
+ if (!init) {
+ if (gr->im)
+ image_destroy(gr);
+ image_create(gr);
+ emit_callback(gr);
+ }
+ }
+ break;
+ case attr_flags:
+ gr->flags=attr->u.num;
+ break;
+ case attr_shmkey:
+ gr->shmkey=attr->u.num;
+ break;
+ case attr_shmsize:
+ gr->shmsize=attr->u.num;
+ break;
+ case attr_shmoffset:
+ gr->shmoffset=attr->u.num;
+ break;
#ifdef HAVE_SOCKET
- case attr_socket:
- g_list_foreach(gr->sockets, (GFunc)g_free, NULL);
- g_list_free(gr->sockets);
- gr->sockets=NULL;
- c=s=g_strdup(attr->u.str);
- dbg(lvl_debug,"s=%s",s);
- while (c) {
- n=strchr(c,',');
- if (n)
- *n++='\0';
- p=strchr(c,':');
- if (p) {
- *p++='\0';
- struct sockaddr_in *sin=g_new(struct sockaddr_in, 1);
- sin->sin_family=AF_INET;
- sin->sin_port=ntohs(atoi(p));
- if (inet_aton(c, &sin->sin_addr)) {
- gr->sockets=g_list_append(gr->sockets, sin);
- } else {
- dbg(lvl_error,"error in %s",c);
- g_free(sin);
- }
- dbg(lvl_debug,"host=%s port=%s",c,p);
- } else
- dbg(lvl_error,"error in format: %s",p);
- c=n;
- }
- g_free(s);
+ case attr_socket:
+ g_list_foreach(gr->sockets, (GFunc)g_free, NULL);
+ g_list_free(gr->sockets);
+ gr->sockets=NULL;
+ c=s=g_strdup(attr->u.str);
+ dbg(lvl_debug,"s=%s",s);
+ while (c) {
+ n=strchr(c,',');
+ if (n)
+ *n++='\0';
+ p=strchr(c,':');
+ if (p) {
+ *p++='\0';
+ struct sockaddr_in *sin=g_new(struct sockaddr_in, 1);
+ sin->sin_family=AF_INET;
+ sin->sin_port=ntohs(atoi(p));
+ if (inet_aton(c, &sin->sin_addr)) {
+ gr->sockets=g_list_append(gr->sockets, sin);
+ } else {
+ dbg(lvl_error,"error in %s",c);
+ g_free(sin);
+ }
+ dbg(lvl_debug,"host=%s port=%s",c,p);
+ } else
+ dbg(lvl_error,"error in format: %s",p);
+ c=n;
+ }
+ g_free(s);
#endif
- default:
- return 0;
- }
- return 1;
+ default:
+ return 0;
+ }
+ return 1;
}
static int
-set_attr(struct graphics_priv *gr, struct attr *attr)
-{
- return set_attr_do(gr, attr, 0);
+set_attr(struct graphics_priv *gr, struct attr *attr) {
+ return set_attr_do(gr, attr, 0);
}
static struct graphics_methods graphics_methods = {
- graphics_destroy,
- draw_mode,
- draw_lines,
- draw_polygon,
- draw_rectangle,
- draw_circle,
- draw_text,
- draw_image,
- NULL,
- draw_drag,
- NULL,
- gc_new,
- background_gc,
- overlay_new,
- image_new,
- get_data,
- image_free,
- NULL,
- overlay_disable,
- overlay_resize,
- set_attr,
- NULL, /* show_native_keyboard */
- NULL, /* hide_native_keyboard */
+ graphics_destroy,
+ draw_mode,
+ draw_lines,
+ draw_polygon,
+ draw_rectangle,
+ draw_circle,
+ draw_text,
+ draw_image,
+ NULL,
+ draw_drag,
+ NULL,
+ gc_new,
+ background_gc,
+ overlay_new,
+ image_new,
+ get_data,
+ image_free,
+ NULL,
+ overlay_disable,
+ overlay_resize,
+ set_attr,
+ NULL, /* show_native_keyboard */
+ NULL, /* hide_native_keyboard */
};
static struct graphics_priv *
-overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound)
-{
- struct font_priv * (*font_freetype_new)(void *meth);
- struct graphics_priv *ret;
-
- dbg(lvl_debug,"enter");
- ret=g_new0(struct graphics_priv, 1);
- *meth=graphics_methods;
- font_freetype_new=plugin_get_category_font("freetype");
- if (!font_freetype_new)
- return NULL;
- font_freetype_new(&ret->freetype_methods);
- ret->p=*p;
- ret->w=w;
- ret->h=h;
- ret->overlay=1;
- ret->flags=1;
- ret->im=gdImageCreateTrueColor(ret->w,ret->h);
- ret->next=gr->overlays;
- gr->overlays=ret;
-
- return ret;
+overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound) {
+ struct font_priv * (*font_freetype_new)(void *meth);
+ struct graphics_priv *ret;
+
+ dbg(lvl_debug,"enter");
+ ret=g_new0(struct graphics_priv, 1);
+ *meth=graphics_methods;
+ font_freetype_new=plugin_get_category_font("freetype");
+ if (!font_freetype_new)
+ return NULL;
+ font_freetype_new(&ret->freetype_methods);
+ ret->p=*p;
+ ret->w=w;
+ ret->h=h;
+ ret->overlay=1;
+ ret->flags=1;
+ ret->im=gdImageCreateTrueColor(ret->w,ret->h);
+ ret->next=gr->overlays;
+ gr->overlays=ret;
+
+ return ret;
}
static void
-emit_callback(struct graphics_priv *priv)
-{
- callback_list_call_attr_2(priv->cbl, attr_resize, (void *)priv->w, (void *)priv->h);
+emit_callback(struct graphics_priv *priv) {
+ callback_list_call_attr_2(priv->cbl, attr_resize, (void *)priv->w, (void *)priv->h);
}
static struct graphics_priv *
-graphics_gd_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
- struct font_priv * (*font_freetype_new)(void *meth);
- struct graphics_priv *ret;
- event_request_system("glib","graphics_gd_new");
- font_freetype_new=plugin_get_category_font("freetype");
- if (!font_freetype_new)
- return NULL;
- *meth=graphics_methods;
- ret=g_new0(struct graphics_priv, 1);
- font_freetype_new(&ret->freetype_methods);
- meth->font_new=(struct graphics_font_priv *(*)(struct graphics_priv *, struct graphics_font_methods *, char *, int, int))ret->freetype_methods.font_new;
- meth->get_text_bbox=ret->freetype_methods.get_text_bbox;
- ret->cb=callback_new_attr_1(callback_cast(emit_callback), attr_navit, ret);
- navit_add_callback(nav, ret->cb);
- ret->cbl=cbl;
- ret->nav=nav;
- ret->w=800;
- ret->h=600;
- while (*attrs) {
- set_attr_do(ret, *attrs, 1);
- attrs++;
- }
- if (!ret->im)
- image_create(ret);
- return ret;
+graphics_gd_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl) {
+ struct font_priv * (*font_freetype_new)(void *meth);
+ struct graphics_priv *ret;
+ event_request_system("glib","graphics_gd_new");
+ font_freetype_new=plugin_get_category_font("freetype");
+ if (!font_freetype_new)
+ return NULL;
+ *meth=graphics_methods;
+ ret=g_new0(struct graphics_priv, 1);
+ font_freetype_new(&ret->freetype_methods);
+ meth->font_new=(struct graphics_font_priv *(*)(struct graphics_priv *, struct graphics_font_methods *, char *, int,
+ int))ret->freetype_methods.font_new;
+ meth->get_text_bbox=ret->freetype_methods.get_text_bbox;
+ ret->cb=callback_new_attr_1(callback_cast(emit_callback), attr_navit, ret);
+ navit_add_callback(nav, ret->cb);
+ ret->cbl=cbl;
+ ret->nav=nav;
+ ret->w=800;
+ ret->h=600;
+ while (*attrs) {
+ set_attr_do(ret, *attrs, 1);
+ attrs++;
+ }
+ if (!ret->im)
+ image_create(ret);
+ return ret;
}
void
-plugin_init(void)
-{
- plugin_register_category_graphics("gd", graphics_gd_new);
+plugin_init(void) {
+ plugin_register_category_graphics("gd", graphics_gd_new);
}
diff --git a/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c b/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c
index 0eb147fce..e840901ab 100644
--- a/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c
+++ b/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c
@@ -60,683 +60,654 @@
struct graphics_priv {
- GdkEventButton button_event;
- int button_timeout;
- GtkWidget *widget;
- GtkWidget *win;
- struct window window;
- cairo_t *cairo;
- struct point p;
- int width;
- int height;
- int win_w;
- int win_h;
- int visible;
- int overlay_disabled;
- int overlay_autodisabled;
- int wraparound;
- struct graphics_priv *parent;
- struct graphics_priv *overlays;
- struct graphics_priv *next;
- struct graphics_gc_priv *background_gc;
- struct callback_list *cbl;
- struct font_freetype_methods freetype_methods;
- struct navit *nav;
- int pid;
- struct timeval button_press[8];
- struct timeval button_release[8];
- int timeout;
- int delay;
- char *window_title;
+ GdkEventButton button_event;
+ int button_timeout;
+ GtkWidget *widget;
+ GtkWidget *win;
+ struct window window;
+ cairo_t *cairo;
+ struct point p;
+ int width;
+ int height;
+ int win_w;
+ int win_h;
+ int visible;
+ int overlay_disabled;
+ int overlay_autodisabled;
+ int wraparound;
+ struct graphics_priv *parent;
+ struct graphics_priv *overlays;
+ struct graphics_priv *next;
+ struct graphics_gc_priv *background_gc;
+ struct callback_list *cbl;
+ struct font_freetype_methods freetype_methods;
+ struct navit *nav;
+ int pid;
+ struct timeval button_press[8];
+ struct timeval button_release[8];
+ int timeout;
+ int delay;
+ char *window_title;
};
struct graphics_gc_priv {
- struct graphics_priv *gr;
- struct color c;
- double linewidth;
- double *dashes;
- int ndashes;
- double offset;
+ struct graphics_priv *gr;
+ struct color c;
+ double linewidth;
+ double *dashes;
+ int ndashes;
+ double offset;
};
struct graphics_image_priv {
- GdkPixbuf *pixbuf;
- int w;
- int h;
+ GdkPixbuf *pixbuf;
+ int w;
+ int h;
#ifdef HAVE_IMLIB2
- void *image;
+ void *image;
#endif
};
static void
-graphics_destroy(struct graphics_priv *gr)
-{
- dbg(lvl_debug,"enter parent %p",gr->parent);
- gr->freetype_methods.destroy();
- if (!gr->parent) {
- dbg(lvl_debug,"enter win %p",gr->win);
- if (gr->win)
- gtk_widget_destroy(gr->win);
- dbg(lvl_debug,"widget %p",gr->widget);
- if (gr->widget)
- gtk_widget_destroy(gr->widget);
- g_free(gr->window_title);
- }
- g_free(gr);
+graphics_destroy(struct graphics_priv *gr) {
+ dbg(lvl_debug,"enter parent %p",gr->parent);
+ gr->freetype_methods.destroy();
+ if (!gr->parent) {
+ dbg(lvl_debug,"enter win %p",gr->win);
+ if (gr->win)
+ gtk_widget_destroy(gr->win);
+ dbg(lvl_debug,"widget %p",gr->widget);
+ if (gr->widget)
+ gtk_widget_destroy(gr->widget);
+ g_free(gr->window_title);
+ }
+ g_free(gr);
}
static void
-gc_destroy(struct graphics_gc_priv *gc)
-{
- g_free(gc);
+gc_destroy(struct graphics_gc_priv *gc) {
+ g_free(gc);
}
static void
-gc_set_linewidth(struct graphics_gc_priv *gc, int w)
-{
- gc->linewidth = w;
+gc_set_linewidth(struct graphics_gc_priv *gc, int w) {
+ gc->linewidth = w;
}
static void
-gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n)
-{
- int i;
- g_free(gc->dashes);
- gc->ndashes=n;
- gc->offset=offset;
- if(n) {
- gc->dashes=g_malloc_n(n, sizeof(double));
- for (i=0; i<n; i++) {
- gc->dashes[i]=dash_list[i];
- }
- } else {
- gc->dashes=NULL;
- }
+gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n) {
+ int i;
+ g_free(gc->dashes);
+ gc->ndashes=n;
+ gc->offset=offset;
+ if(n) {
+ gc->dashes=g_malloc_n(n, sizeof(double));
+ for (i=0; i<n; i++) {
+ gc->dashes[i]=dash_list[i];
+ }
+ } else {
+ gc->dashes=NULL;
+ }
}
static void
-gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
-{
- gc->c=*c;
+gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) {
+ gc->c=*c;
}
static void
-gc_set_background(struct graphics_gc_priv *gc, struct color *c)
-{
+gc_set_background(struct graphics_gc_priv *gc, struct color *c) {
}
static struct graphics_gc_methods gc_methods = {
- gc_destroy,
- gc_set_linewidth,
- gc_set_dashes,
- gc_set_foreground,
- gc_set_background,
+ gc_destroy,
+ gc_set_linewidth,
+ gc_set_dashes,
+ gc_set_foreground,
+ gc_set_background,
};
-static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
-{
- struct graphics_gc_priv *gc=g_new(struct graphics_gc_priv, 1);
+static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
+ struct graphics_gc_priv *gc=g_new(struct graphics_gc_priv, 1);
- *meth=gc_methods;
- gc->gr=gr;
+ *meth=gc_methods;
+ gc->gr=gr;
- gc->linewidth=1;
- gc->c.r=0;
- gc->c.g=0;
- gc->c.b=0;
- gc->c.a=0;
- gc->dashes=NULL;
- gc->ndashes=0;
- gc->offset=0;
+ gc->linewidth=1;
+ gc->c.r=0;
+ gc->c.g=0;
+ gc->c.b=0;
+ gc->c.a=0;
+ gc->dashes=NULL;
+ gc->ndashes=0;
+ gc->offset=0;
- return gc;
+ return gc;
}
static struct graphics_image_priv *
-image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name, int *w, int *h, struct point *hot, int rotation)
-{
- GdkPixbuf *pixbuf;
- struct graphics_image_priv *ret;
- const char *option;
-
- if (!strcmp(name,"buffer:")) {
- struct graphics_image_buffer *buffer=(struct graphics_image_buffer *)name;
- GdkPixbufLoader *loader=gdk_pixbuf_loader_new();
- if (!loader)
- return NULL;
- if (*w != IMAGE_W_H_UNSET || *h != IMAGE_W_H_UNSET)
- gdk_pixbuf_loader_set_size(loader, *w, *h);
- gdk_pixbuf_loader_write(loader, buffer->start, buffer->len, NULL);
- gdk_pixbuf_loader_close(loader, NULL);
- pixbuf=gdk_pixbuf_loader_get_pixbuf(loader);
- g_object_ref(pixbuf);
- g_object_unref(loader);
- } else {
- if (*w == IMAGE_W_H_UNSET && *h == IMAGE_W_H_UNSET)
- pixbuf=gdk_pixbuf_new_from_file(name, NULL);
- else
- pixbuf=gdk_pixbuf_new_from_file_at_size(name, *w, *h, NULL);
- }
-
- if (!pixbuf)
- return NULL;
-
- if (rotation) {
- GdkPixbuf *tmp;
- switch (rotation) {
- case 90:
- rotation=270;
- break;
- case 180:
- break;
- case 270:
- rotation=90;
- break;
- default:
- return NULL;
- }
-
- tmp=gdk_pixbuf_rotate_simple(pixbuf, rotation);
-
- if (!tmp) {
- g_object_unref(pixbuf);
- return NULL;
- }
-
- g_object_unref(pixbuf);
- pixbuf=tmp;
- }
-
- ret=g_new0(struct graphics_image_priv, 1);
- ret->pixbuf=pixbuf;
- ret->w=gdk_pixbuf_get_width(pixbuf);
- ret->h=gdk_pixbuf_get_height(pixbuf);
- *w=ret->w;
- *h=ret->h;
- if (hot) {
- option=gdk_pixbuf_get_option(pixbuf, "x_hot");
- if (option)
- hot->x=atoi(option);
- else
- hot->x=ret->w/2-1;
- option=gdk_pixbuf_get_option(pixbuf, "y_hot");
- if (option)
- hot->y=atoi(option);
- else
- hot->y=ret->h/2-1;
- }
- return ret;
+image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name, int *w, int *h, struct point *hot,
+ int rotation) {
+ GdkPixbuf *pixbuf;
+ struct graphics_image_priv *ret;
+ const char *option;
+
+ if (!strcmp(name,"buffer:")) {
+ struct graphics_image_buffer *buffer=(struct graphics_image_buffer *)name;
+ GdkPixbufLoader *loader=gdk_pixbuf_loader_new();
+ if (!loader)
+ return NULL;
+ if (*w != IMAGE_W_H_UNSET || *h != IMAGE_W_H_UNSET)
+ gdk_pixbuf_loader_set_size(loader, *w, *h);
+ gdk_pixbuf_loader_write(loader, buffer->start, buffer->len, NULL);
+ gdk_pixbuf_loader_close(loader, NULL);
+ pixbuf=gdk_pixbuf_loader_get_pixbuf(loader);
+ g_object_ref(pixbuf);
+ g_object_unref(loader);
+ } else {
+ if (*w == IMAGE_W_H_UNSET && *h == IMAGE_W_H_UNSET)
+ pixbuf=gdk_pixbuf_new_from_file(name, NULL);
+ else
+ pixbuf=gdk_pixbuf_new_from_file_at_size(name, *w, *h, NULL);
+ }
+
+ if (!pixbuf)
+ return NULL;
+
+ if (rotation) {
+ GdkPixbuf *tmp;
+ switch (rotation) {
+ case 90:
+ rotation=270;
+ break;
+ case 180:
+ break;
+ case 270:
+ rotation=90;
+ break;
+ default:
+ return NULL;
+ }
+
+ tmp=gdk_pixbuf_rotate_simple(pixbuf, rotation);
+
+ if (!tmp) {
+ g_object_unref(pixbuf);
+ return NULL;
+ }
+
+ g_object_unref(pixbuf);
+ pixbuf=tmp;
+ }
+
+ ret=g_new0(struct graphics_image_priv, 1);
+ ret->pixbuf=pixbuf;
+ ret->w=gdk_pixbuf_get_width(pixbuf);
+ ret->h=gdk_pixbuf_get_height(pixbuf);
+ *w=ret->w;
+ *h=ret->h;
+ if (hot) {
+ option=gdk_pixbuf_get_option(pixbuf, "x_hot");
+ if (option)
+ hot->x=atoi(option);
+ else
+ hot->x=ret->w/2-1;
+ option=gdk_pixbuf_get_option(pixbuf, "y_hot");
+ if (option)
+ hot->y=atoi(option);
+ else
+ hot->y=ret->h/2-1;
+ }
+ return ret;
}
-static void
-image_free(struct graphics_priv *gr, struct graphics_image_priv *priv)
-{
- g_object_unref(priv->pixbuf);
- g_free(priv);
+static void
+image_free(struct graphics_priv *gr, struct graphics_image_priv *priv) {
+ g_object_unref(priv->pixbuf);
+ g_free(priv);
}
static void
-set_drawing_color(cairo_t *cairo, struct color c)
-{
- double col_max = 1<<COLOR_BITDEPTH;
- cairo_set_source_rgba(cairo, c.r/col_max, c.g/col_max, c.b/col_max, c.a/col_max);
+set_drawing_color(cairo_t *cairo, struct color c) {
+ double col_max = 1<<COLOR_BITDEPTH;
+ cairo_set_source_rgba(cairo, c.r/col_max, c.g/col_max, c.b/col_max, c.a/col_max);
}
static void
-set_stroke_params_from_gc(cairo_t *cairo, struct graphics_gc_priv *gc)
-{
- set_drawing_color(cairo, gc->c);
- cairo_set_dash(cairo, gc->dashes, gc->ndashes, gc->offset);
- cairo_set_line_width(cairo, gc->linewidth);
+set_stroke_params_from_gc(cairo_t *cairo, struct graphics_gc_priv *gc) {
+ set_drawing_color(cairo, gc->c);
+ cairo_set_dash(cairo, gc->dashes, gc->ndashes, gc->offset);
+ cairo_set_line_width(cairo, gc->linewidth);
}
static void
-draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
- int i;
- if (!count)
- return;
- cairo_move_to(gr->cairo, p[0].x, p[0].y);
- for (i=1; i<count; i++) {
- cairo_line_to(gr->cairo, p[i].x, p[i].y);
- }
- set_stroke_params_from_gc(gr->cairo, gc);
- cairo_stroke(gr->cairo);
+draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
+ int i;
+ if (!count)
+ return;
+ cairo_move_to(gr->cairo, p[0].x, p[0].y);
+ for (i=1; i<count; i++) {
+ cairo_line_to(gr->cairo, p[i].x, p[i].y);
+ }
+ set_stroke_params_from_gc(gr->cairo, gc);
+ cairo_stroke(gr->cairo);
}
static void
-draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
- int i;
- set_drawing_color(gr->cairo, gc->c);
- cairo_move_to(gr->cairo, p[0].x, p[0].y);
- for (i=1; i<count; i++) {
- cairo_line_to(gr->cairo, p[i].x, p[i].y);
- }
- cairo_fill(gr->cairo);
+draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
+ int i;
+ set_drawing_color(gr->cairo, gc->c);
+ cairo_move_to(gr->cairo, p[0].x, p[0].y);
+ for (i=1; i<count; i++) {
+ cairo_line_to(gr->cairo, p[i].x, p[i].y);
+ }
+ cairo_fill(gr->cairo);
}
static void
-draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h)
-{
- cairo_save(gr->cairo);
- // Use OPERATOR_SOURCE to overwrite old contents even when drawing with transparency.
- // Necessary for OSD drawing.
- cairo_set_operator(gr->cairo, CAIRO_OPERATOR_SOURCE);
- cairo_rectangle(gr->cairo, p->x, p->y, w, h);
- set_drawing_color(gr->cairo, gc->c);
- cairo_fill(gr->cairo);
- cairo_restore(gr->cairo);
+draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h) {
+ cairo_save(gr->cairo);
+ // Use OPERATOR_SOURCE to overwrite old contents even when drawing with transparency.
+ // Necessary for OSD drawing.
+ cairo_set_operator(gr->cairo, CAIRO_OPERATOR_SOURCE);
+ cairo_rectangle(gr->cairo, p->x, p->y, w, h);
+ set_drawing_color(gr->cairo, gc->c);
+ cairo_fill(gr->cairo);
+ cairo_restore(gr->cairo);
}
static void
-draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r)
-{
- cairo_arc (gr->cairo, p->x, p->y, r/2, 0.0, 2*M_PI);
- set_stroke_params_from_gc(gr->cairo, gc);
- cairo_stroke(gr->cairo);
+draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r) {
+ cairo_arc (gr->cairo, p->x, p->y, r/2, 0.0, 2*M_PI);
+ set_stroke_params_from_gc(gr->cairo, gc);
+ cairo_stroke(gr->cairo);
}
static void
-draw_rgb_image_buffer(cairo_t *cairo, int buffer_width, int buffer_height, int draw_pos_x, int draw_pos_y, int stride, unsigned char *buffer)
-{
- cairo_surface_t *buffer_surface = cairo_image_surface_create_for_data(
- buffer, CAIRO_FORMAT_ARGB32, buffer_width, buffer_height, stride);
- cairo_set_source_surface(cairo, buffer_surface, draw_pos_x, draw_pos_y);
- cairo_paint(cairo);
- cairo_surface_destroy(buffer_surface);
+draw_rgb_image_buffer(cairo_t *cairo, int buffer_width, int buffer_height, int draw_pos_x, int draw_pos_y, int stride,
+ unsigned char *buffer) {
+ cairo_surface_t *buffer_surface = cairo_image_surface_create_for_data(
+ buffer, CAIRO_FORMAT_ARGB32, buffer_width, buffer_height, stride);
+ cairo_set_source_surface(cairo, buffer_surface, draw_pos_x, draw_pos_y);
+ cairo_paint(cairo);
+ cairo_surface_destroy(buffer_surface);
}
static void
-display_text_draw(struct font_freetype_text *text, struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct point *p)
-{
- int i,x,y,stride;
- struct font_freetype_glyph *g, **gp;
- struct color transparent={0x0,0x0,0x0,0x0};
-
- gp=text->glyph;
- i=text->glyph_count;
- x=p->x << 6;
- y=p->y << 6;
- while (i-- > 0)
- {
- g=*gp++;
- if (g->w && g->h && bg ) {
- unsigned char *shadow;
- stride=cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, g->w+2);
- shadow=g_malloc(stride*(g->h+2));
- gr->freetype_methods.get_shadow(g, shadow, stride, &bg->c, &transparent);
- draw_rgb_image_buffer(gr->cairo, g->w+2, g->h+2, ((x+g->x)>>6)-1, ((y+g->y)>>6)-1, stride, shadow);
- g_free(shadow);
- }
- x+=g->dx;
- y+=g->dy;
- }
- x=p->x << 6;
- y=p->y << 6;
- gp=text->glyph;
- i=text->glyph_count;
- while (i-- > 0)
- {
- g=*gp++;
- if (g->w && g->h) {
- unsigned char *glyph;
- stride=cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, g->w);
- glyph=g_malloc(stride*g->h);
- gr->freetype_methods.get_glyph(g, glyph, stride, &fg->c, bg?&bg->c:&transparent, &transparent);
- draw_rgb_image_buffer(gr->cairo, g->w, g->h, (x+g->x)>>6, (y+g->y)>>6, stride, glyph);
- g_free(glyph);
- }
- x+=g->dx;
- y+=g->dy;
- }
+display_text_draw(struct font_freetype_text *text, struct graphics_priv *gr, struct graphics_gc_priv *fg,
+ struct graphics_gc_priv *bg, struct point *p) {
+ int i,x,y,stride;
+ struct font_freetype_glyph *g, **gp;
+ struct color transparent= {0x0,0x0,0x0,0x0};
+
+ gp=text->glyph;
+ i=text->glyph_count;
+ x=p->x << 6;
+ y=p->y << 6;
+ while (i-- > 0) {
+ g=*gp++;
+ if (g->w && g->h && bg ) {
+ unsigned char *shadow;
+ stride=cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, g->w+2);
+ shadow=g_malloc(stride*(g->h+2));
+ gr->freetype_methods.get_shadow(g, shadow, stride, &bg->c, &transparent);
+ draw_rgb_image_buffer(gr->cairo, g->w+2, g->h+2, ((x+g->x)>>6)-1, ((y+g->y)>>6)-1, stride, shadow);
+ g_free(shadow);
+ }
+ x+=g->dx;
+ y+=g->dy;
+ }
+ x=p->x << 6;
+ y=p->y << 6;
+ gp=text->glyph;
+ i=text->glyph_count;
+ while (i-- > 0) {
+ g=*gp++;
+ if (g->w && g->h) {
+ unsigned char *glyph;
+ stride=cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, g->w);
+ glyph=g_malloc(stride*g->h);
+ gr->freetype_methods.get_glyph(g, glyph, stride, &fg->c, bg?&bg->c:&transparent, &transparent);
+ draw_rgb_image_buffer(gr->cairo, g->w, g->h, (x+g->x)>>6, (y+g->y)>>6, stride, glyph);
+ g_free(glyph);
+ }
+ x+=g->dx;
+ y+=g->dy;
+ }
}
static void
-draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy)
-{
- struct font_freetype_text *t;
-
- if (! font)
- {
- dbg(lvl_error,"no font, returning");
- return;
- }
+draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg,
+ struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy) {
+ struct font_freetype_text *t;
+
+ if (! font) {
+ dbg(lvl_error,"no font, returning");
+ return;
+ }
#if 0 /* Temporarily disabled because it destroys text rendering of overlays and in gui internal in some places */
- /*
- This needs an improvement, no one checks if the strings are visible
- */
- if (p->x > gr->width-50 || p->y > gr->height-50) {
- return;
- }
- if (p->x < -50 || p->y < -50) {
- return;
- }
+ /*
+ This needs an improvement, no one checks if the strings are visible
+ */
+ if (p->x > gr->width-50 || p->y > gr->height-50) {
+ return;
+ }
+ if (p->x < -50 || p->y < -50) {
+ return;
+ }
#endif
- if (bg && !bg->c.a)
- bg=NULL;
- t=gr->freetype_methods.text_new(text, (struct font_freetype_font *)font, dx, dy);
- display_text_draw(t, gr, fg, bg, p);
- gr->freetype_methods.text_destroy(t);
+ if (bg && !bg->c.a)
+ bg=NULL;
+ t=gr->freetype_methods.text_new(text, (struct font_freetype_font *)font, dx, dy);
+ display_text_draw(t, gr, fg, bg, p);
+ gr->freetype_methods.text_destroy(t);
}
static void
-draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img)
-{
- gdk_cairo_set_source_pixbuf(gr->cairo, img->pixbuf, p->x, p->y);
- cairo_paint(gr->cairo);
+draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img) {
+ gdk_cairo_set_source_pixbuf(gr->cairo, img->pixbuf, p->x, p->y);
+ cairo_paint(gr->cairo);
}
#ifdef HAVE_IMLIB2
static unsigned char*
-create_buffer_with_stride_if_required(unsigned char *input_buffer, int w, int h, size_t bytes_per_pixel, size_t output_stride)
-{
- int line;
- size_t input_offset, output_offset;
- unsigned char *out_buf;
- size_t input_stride = w*bytes_per_pixel;
- if (input_stride == output_stride) {
- return NULL;
- }
-
- out_buf = g_malloc(h*output_stride);
- for (line = 0; line < h; line++) {
- input_offset = line*input_stride;
- output_offset = line*output_stride;
- memcpy(out_buf+output_offset, input_buffer+input_offset, input_stride);
- }
- return out_buf;
+create_buffer_with_stride_if_required(unsigned char *input_buffer, int w, int h, size_t bytes_per_pixel,
+ size_t output_stride) {
+ int line;
+ size_t input_offset, output_offset;
+ unsigned char *out_buf;
+ size_t input_stride = w*bytes_per_pixel;
+ if (input_stride == output_stride) {
+ return NULL;
+ }
+
+ out_buf = g_malloc(h*output_stride);
+ for (line = 0; line < h; line++) {
+ input_offset = line*input_stride;
+ output_offset = line*output_stride;
+ memcpy(out_buf+output_offset, input_buffer+input_offset, input_stride);
+ }
+ return out_buf;
}
static void
-draw_image_warp(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count, struct graphics_image_priv *img)
-{
- int w,h;
- DATA32 *intermediate_buffer;
- unsigned char* intermediate_buffer_aligned;
- Imlib_Image intermediate_image;
- size_t stride;
- dbg(lvl_debug,"draw_image_warp data=%p", img);
- w = img->w;
- h = img->h;
- if (!img->image) {
- int x,y;
- img->image=imlib_create_image(w, h);
- imlib_context_set_image(img->image);
- if (gdk_pixbuf_get_colorspace(img->pixbuf) != GDK_COLORSPACE_RGB || gdk_pixbuf_get_bits_per_sample(img->pixbuf) != 8) {
- dbg(lvl_error,"implement me");
- } else if (gdk_pixbuf_get_has_alpha(img->pixbuf) && gdk_pixbuf_get_n_channels(img->pixbuf) == 4) {
- for (y=0 ; y < h ; y++) {
- unsigned int *dst=imlib_image_get_data()+y*w;
- unsigned char *src=gdk_pixbuf_get_pixels(img->pixbuf)+y*gdk_pixbuf_get_rowstride(img->pixbuf);
- for (x=0 ; x < w ; x++) {
- *dst++=0xff000000|(src[0] << 16)|(src[1] << 8)|src[2];
- src+=4;
- }
- }
- } else if (!gdk_pixbuf_get_has_alpha(img->pixbuf) && gdk_pixbuf_get_n_channels(img->pixbuf) == 3) {
- for (y=0 ; y < h ; y++) {
- unsigned int *dst=imlib_image_get_data()+y*w;
- unsigned char *src=gdk_pixbuf_get_pixels(img->pixbuf)+y*gdk_pixbuf_get_rowstride(img->pixbuf);
- for (x=0 ; x < w ; x++) {
- *dst++=0xff000000|(src[0] << 16)|(src[1] << 8)|src[2];
- src+=3;
- }
- }
- } else {
- dbg(lvl_error,"implement me");
- }
-
- }
-
- intermediate_buffer = g_malloc0(gr->width*gr->height*4);
- intermediate_image = imlib_create_image_using_data(gr->width, gr->height, intermediate_buffer);
- imlib_context_set_image(intermediate_image);
- imlib_image_set_has_alpha(1);
-
- if (count == 3) {
- /* 0 1
+draw_image_warp(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count,
+ struct graphics_image_priv *img) {
+ int w,h;
+ DATA32 *intermediate_buffer;
+ unsigned char* intermediate_buffer_aligned;
+ Imlib_Image intermediate_image;
+ size_t stride;
+ dbg(lvl_debug,"draw_image_warp data=%p", img);
+ w = img->w;
+ h = img->h;
+ if (!img->image) {
+ int x,y;
+ img->image=imlib_create_image(w, h);
+ imlib_context_set_image(img->image);
+ if (gdk_pixbuf_get_colorspace(img->pixbuf) != GDK_COLORSPACE_RGB || gdk_pixbuf_get_bits_per_sample(img->pixbuf) != 8) {
+ dbg(lvl_error,"implement me");
+ } else if (gdk_pixbuf_get_has_alpha(img->pixbuf) && gdk_pixbuf_get_n_channels(img->pixbuf) == 4) {
+ for (y=0 ; y < h ; y++) {
+ unsigned int *dst=imlib_image_get_data()+y*w;
+ unsigned char *src=gdk_pixbuf_get_pixels(img->pixbuf)+y*gdk_pixbuf_get_rowstride(img->pixbuf);
+ for (x=0 ; x < w ; x++) {
+ *dst++=0xff000000|(src[0] << 16)|(src[1] << 8)|src[2];
+ src+=4;
+ }
+ }
+ } else if (!gdk_pixbuf_get_has_alpha(img->pixbuf) && gdk_pixbuf_get_n_channels(img->pixbuf) == 3) {
+ for (y=0 ; y < h ; y++) {
+ unsigned int *dst=imlib_image_get_data()+y*w;
+ unsigned char *src=gdk_pixbuf_get_pixels(img->pixbuf)+y*gdk_pixbuf_get_rowstride(img->pixbuf);
+ for (x=0 ; x < w ; x++) {
+ *dst++=0xff000000|(src[0] << 16)|(src[1] << 8)|src[2];
+ src+=3;
+ }
+ }
+ } else {
+ dbg(lvl_error,"implement me");
+ }
+
+ }
+
+ intermediate_buffer = g_malloc0(gr->width*gr->height*4);
+ intermediate_image = imlib_create_image_using_data(gr->width, gr->height, intermediate_buffer);
+ imlib_context_set_image(intermediate_image);
+ imlib_image_set_has_alpha(1);
+
+ if (count == 3) {
+ /* 0 1
2 */
- imlib_blend_image_onto_image_skewed(img->image, 1, 0, 0, w, h, p[0].x, p[0].y, p[1].x-p[0].x, p[1].y-p[0].y, p[2].x-p[0].x, p[2].y-p[0].y);
- }
- if (count == 2) {
- /* 0
+ imlib_blend_image_onto_image_skewed(img->image, 1, 0, 0, w, h, p[0].x, p[0].y, p[1].x-p[0].x, p[1].y-p[0].y,
+ p[2].x-p[0].x, p[2].y-p[0].y);
+ }
+ if (count == 2) {
+ /* 0
1 */
- imlib_blend_image_onto_image_skewed(img->image, 1, 0, 0, w, h, p[0].x, p[0].y, p[1].x-p[0].x, 0, 0, p[1].y-p[0].y);
- }
- if (count == 1) {
- /*
+ imlib_blend_image_onto_image_skewed(img->image, 1, 0, 0, w, h, p[0].x, p[0].y, p[1].x-p[0].x, 0, 0, p[1].y-p[0].y);
+ }
+ if (count == 1) {
+ /*
0
*/
- imlib_blend_image_onto_image_skewed(img->image, 1, 0, 0, w, h, p[0].x-w/2, p[0].y-h/2, w, 0, 0, h);
- }
-
- stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, gr->width);
- intermediate_buffer_aligned = create_buffer_with_stride_if_required(
- (unsigned char* )intermediate_buffer, gr->width, gr->height, sizeof(DATA32), stride);
- cairo_surface_t *buffer_surface = cairo_image_surface_create_for_data(
- intermediate_buffer_aligned ? intermediate_buffer_aligned : (unsigned char*)intermediate_buffer,
- CAIRO_FORMAT_ARGB32, gr->width, gr->height, stride);
- cairo_set_source_surface(gr->cairo, buffer_surface, 0, 0);
- cairo_paint(gr->cairo);
-
- cairo_surface_destroy(buffer_surface);
- imlib_free_image();
- g_free(intermediate_buffer);
- g_free(intermediate_buffer_aligned);
+ imlib_blend_image_onto_image_skewed(img->image, 1, 0, 0, w, h, p[0].x-w/2, p[0].y-h/2, w, 0, 0, h);
+ }
+
+ stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, gr->width);
+ intermediate_buffer_aligned = create_buffer_with_stride_if_required(
+ (unsigned char* )intermediate_buffer, gr->width, gr->height, sizeof(DATA32), stride);
+ cairo_surface_t *buffer_surface = cairo_image_surface_create_for_data(
+ intermediate_buffer_aligned ? intermediate_buffer_aligned : (unsigned char*)intermediate_buffer,
+ CAIRO_FORMAT_ARGB32, gr->width, gr->height, stride);
+ cairo_set_source_surface(gr->cairo, buffer_surface, 0, 0);
+ cairo_paint(gr->cairo);
+
+ cairo_surface_destroy(buffer_surface);
+ imlib_free_image();
+ g_free(intermediate_buffer);
+ g_free(intermediate_buffer_aligned);
}
#endif
static void
-overlay_rect(struct graphics_priv *parent, struct graphics_priv *overlay, GdkRectangle *r)
-{
- r->x=overlay->p.x;
- r->y=overlay->p.y;
- r->width=overlay->width;
- r->height=overlay->height;
- if (!overlay->wraparound)
- return;
- if (r->x < 0)
- r->x += parent->width;
- if (r->y < 0)
- r->y += parent->height;
- if (r->width < 0)
- r->width += parent->width;
- if (r->height < 0)
- r->height += parent->height;
+overlay_rect(struct graphics_priv *parent, struct graphics_priv *overlay, GdkRectangle *r) {
+ r->x=overlay->p.x;
+ r->y=overlay->p.y;
+ r->width=overlay->width;
+ r->height=overlay->height;
+ if (!overlay->wraparound)
+ return;
+ if (r->x < 0)
+ r->x += parent->width;
+ if (r->y < 0)
+ r->y += parent->height;
+ if (r->width < 0)
+ r->width += parent->width;
+ if (r->height < 0)
+ r->height += parent->height;
}
static void
-overlay_draw(struct graphics_priv *parent, struct graphics_priv *overlay, GdkRectangle *re, cairo_t *cairo)
-{
- GdkRectangle or, ir;
- if (parent->overlay_disabled || overlay->overlay_disabled || overlay->overlay_autodisabled)
- return;
- overlay_rect(parent, overlay, &or);
- if (! gdk_rectangle_intersect(re, &or, &ir))
- return;
- or.x-=re->x;
- or.y-=re->y;
- cairo_surface_t *overlay_surface = cairo_get_target(overlay->cairo);
- cairo_set_source_surface(cairo, overlay_surface, or.x, or.y);
- cairo_paint(cairo);
+overlay_draw(struct graphics_priv *parent, struct graphics_priv *overlay, GdkRectangle *re, cairo_t *cairo) {
+ GdkRectangle or, ir;
+ if (parent->overlay_disabled || overlay->overlay_disabled || overlay->overlay_autodisabled)
+ return;
+ overlay_rect(parent, overlay, &or);
+ if (! gdk_rectangle_intersect(re, &or, &ir))
+ return;
+ or.x-=re->x;
+ or.y-=re->y;
+ cairo_surface_t *overlay_surface = cairo_get_target(overlay->cairo);
+ cairo_set_source_surface(cairo, overlay_surface, or.x, or.y);
+ cairo_paint(cairo);
}
static void
-draw_drag(struct graphics_priv *gr, struct point *p)
-{
- if (p)
- gr->p=*p;
- else {
- gr->p.x=0;
- gr->p.y=0;
- }
+draw_drag(struct graphics_priv *gr, struct point *p) {
+ if (p)
+ gr->p=*p;
+ else {
+ gr->p.x=0;
+ gr->p.y=0;
+ }
}
static void
-background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
- gr->background_gc=gc;
+background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
+ gr->background_gc=gc;
}
static void
-draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
-{
- if (mode == draw_mode_end) {
- // Just invalidate the whole window. We could only the invalidate the area of
- // graphics_priv, but that is probably not significantly faster.
- gdk_window_invalidate_rect(gr->widget->window, NULL, TRUE);
- }
+draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
+ if (mode == draw_mode_end) {
+ // Just invalidate the whole window. We could only the invalidate the area of
+ // graphics_priv, but that is probably not significantly faster.
+ gdk_window_invalidate_rect(gr->widget->window, NULL, TRUE);
+ }
}
/* Events */
static gint
-configure(GtkWidget * widget, GdkEventConfigure * event, gpointer user_data)
-{
- struct graphics_priv *gra=user_data;
- if (! gra->visible)
- return TRUE;
+configure(GtkWidget * widget, GdkEventConfigure * event, gpointer user_data) {
+ struct graphics_priv *gra=user_data;
+ if (! gra->visible)
+ return TRUE;
#ifndef _WIN32
- dbg(lvl_debug,"window=%lu", GDK_WINDOW_XID(widget->window));
+ dbg(lvl_debug,"window=%lu", GDK_WINDOW_XID(widget->window));
#endif
- gra->width=widget->allocation.width;
- gra->height=widget->allocation.height;
- cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, gra->width, gra->height);
- if (gra->cairo)
- cairo_destroy(gra->cairo);
- gra->cairo = cairo_create(surface);
- cairo_surface_destroy(surface);
- cairo_set_antialias (gra->cairo, CAIRO_ANTIALIAS_GOOD);
- callback_list_call_attr_2(gra->cbl, attr_resize, GINT_TO_POINTER(gra->width), GINT_TO_POINTER(gra->height));
- return TRUE;
+ gra->width=widget->allocation.width;
+ gra->height=widget->allocation.height;
+ cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, gra->width, gra->height);
+ if (gra->cairo)
+ cairo_destroy(gra->cairo);
+ gra->cairo = cairo_create(surface);
+ cairo_surface_destroy(surface);
+ cairo_set_antialias (gra->cairo, CAIRO_ANTIALIAS_GOOD);
+ callback_list_call_attr_2(gra->cbl, attr_resize, GINT_TO_POINTER(gra->width), GINT_TO_POINTER(gra->height));
+ return TRUE;
}
static gint
-expose(GtkWidget * widget, GdkEventExpose * event, gpointer user_data)
-{
- struct graphics_priv *gra=user_data;
- struct graphics_gc_priv *background_gc=gra->background_gc;
- struct graphics_priv *overlay;
-
- gra->visible=1;
- if (! gra->cairo)
- configure(widget, NULL, user_data);
-
- cairo_t *cairo=gdk_cairo_create(widget->window);
- if (gra->p.x || gra->p.y) {
- set_drawing_color(cairo, background_gc->c);
- cairo_paint(cairo);
- }
- cairo_set_source_surface(cairo, cairo_get_target(gra->cairo), gra->p.x, gra->p.y);
- cairo_paint(cairo);
-
- overlay = gra->overlays;
- while (overlay) {
- overlay_draw(gra,overlay,&event->area,cairo);
- overlay=overlay->next;
- }
-
- cairo_destroy(cairo);
- return FALSE;
+expose(GtkWidget * widget, GdkEventExpose * event, gpointer user_data) {
+ struct graphics_priv *gra=user_data;
+ struct graphics_gc_priv *background_gc=gra->background_gc;
+ struct graphics_priv *overlay;
+
+ gra->visible=1;
+ if (! gra->cairo)
+ configure(widget, NULL, user_data);
+
+ cairo_t *cairo=gdk_cairo_create(widget->window);
+ if (gra->p.x || gra->p.y) {
+ set_drawing_color(cairo, background_gc->c);
+ cairo_paint(cairo);
+ }
+ cairo_set_source_surface(cairo, cairo_get_target(gra->cairo), gra->p.x, gra->p.y);
+ cairo_paint(cairo);
+
+ overlay = gra->overlays;
+ while (overlay) {
+ overlay_draw(gra,overlay,&event->area,cairo);
+ overlay=overlay->next;
+ }
+
+ cairo_destroy(cairo);
+ return FALSE;
}
static int
-tv_delta(struct timeval *old, struct timeval *new)
-{
- if (new->tv_sec-old->tv_sec >= INT_MAX/1000)
- return INT_MAX;
- return (new->tv_sec-old->tv_sec)*1000+(new->tv_usec-old->tv_usec)/1000;
+tv_delta(struct timeval *old, struct timeval *new) {
+ if (new->tv_sec-old->tv_sec >= INT_MAX/1000)
+ return INT_MAX;
+ return (new->tv_sec-old->tv_sec)*1000+(new->tv_usec-old->tv_usec)/1000;
}
static gint
-button_press(GtkWidget * widget, GdkEventButton * event, gpointer user_data)
-{
- struct graphics_priv *this=user_data;
- struct point p;
- struct timeval tv;
- struct timezone tz;
-
- gettimeofday(&tv, &tz);
-
- if (event->button < 8) {
- if (tv_delta(&this->button_press[event->button], &tv) < this->timeout)
- return FALSE;
- this->button_press[event->button]= tv;
- this->button_release[event->button].tv_sec=0;
- this->button_release[event->button].tv_usec=0;
- }
- p.x=event->x;
- p.y=event->y;
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(event->button), (void *)&p);
- return FALSE;
+button_press(GtkWidget * widget, GdkEventButton * event, gpointer user_data) {
+ struct graphics_priv *this=user_data;
+ struct point p;
+ struct timeval tv;
+ struct timezone tz;
+
+ gettimeofday(&tv, &tz);
+
+ if (event->button < 8) {
+ if (tv_delta(&this->button_press[event->button], &tv) < this->timeout)
+ return FALSE;
+ this->button_press[event->button]= tv;
+ this->button_release[event->button].tv_sec=0;
+ this->button_release[event->button].tv_usec=0;
+ }
+ p.x=event->x;
+ p.y=event->y;
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(event->button), (void *)&p);
+ return FALSE;
}
static gint
-button_release(GtkWidget * widget, GdkEventButton * event, gpointer user_data)
-{
- struct graphics_priv *this=user_data;
- struct point p;
- struct timeval tv;
- struct timezone tz;
-
- gettimeofday(&tv, &tz);
-
- if (event->button < 8) {
- if (tv_delta(&this->button_release[event->button], &tv) < this->timeout)
- return FALSE;
- this->button_release[event->button]= tv;
- this->button_press[event->button].tv_sec=0;
- this->button_press[event->button].tv_usec=0;
- }
- p.x=event->x;
- p.y=event->y;
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(event->button), (void *)&p);
- return FALSE;
+button_release(GtkWidget * widget, GdkEventButton * event, gpointer user_data) {
+ struct graphics_priv *this=user_data;
+ struct point p;
+ struct timeval tv;
+ struct timezone tz;
+
+ gettimeofday(&tv, &tz);
+
+ if (event->button < 8) {
+ if (tv_delta(&this->button_release[event->button], &tv) < this->timeout)
+ return FALSE;
+ this->button_release[event->button]= tv;
+ this->button_press[event->button].tv_sec=0;
+ this->button_press[event->button].tv_usec=0;
+ }
+ p.x=event->x;
+ p.y=event->y;
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(event->button), (void *)&p);
+ return FALSE;
}
static gint
-scroll(GtkWidget * widget, GdkEventScroll * event, gpointer user_data)
-{
- struct graphics_priv *this=user_data;
- struct point p;
- int button;
-
- p.x=event->x;
- p.y=event->y;
- switch (event->direction) {
- case GDK_SCROLL_UP:
- button=4;
- break;
- case GDK_SCROLL_DOWN:
- button=5;
- break;
- default:
- button=-1;
- break;
- }
- if (button != -1) {
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), (void *)&p);
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), (void *)&p);
- }
- return FALSE;
+scroll(GtkWidget * widget, GdkEventScroll * event, gpointer user_data) {
+ struct graphics_priv *this=user_data;
+ struct point p;
+ int button;
+
+ p.x=event->x;
+ p.y=event->y;
+ switch (event->direction) {
+ case GDK_SCROLL_UP:
+ button=4;
+ break;
+ case GDK_SCROLL_DOWN:
+ button=5;
+ break;
+ default:
+ button=-1;
+ break;
+ }
+ if (button != -1) {
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), (void *)&p);
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), (void *)&p);
+ }
+ return FALSE;
}
static gint
-motion_notify(GtkWidget * widget, GdkEventMotion * event, gpointer user_data)
-{
- struct graphics_priv *this=user_data;
- struct point p;
-
- p.x=event->x;
- p.y=event->y;
- callback_list_call_attr_1(this->cbl, attr_motion, (void *)&p);
- return FALSE;
+motion_notify(GtkWidget * widget, GdkEventMotion * event, gpointer user_data) {
+ struct graphics_priv *this=user_data;
+ struct point p;
+
+ p.x=event->x;
+ p.y=event->y;
+ callback_list_call_attr_1(this->cbl, attr_motion, (void *)&p);
+ return FALSE;
}
/* *
@@ -747,268 +718,259 @@ motion_notify(GtkWidget * widget, GdkEventMotion * event, gpointer user_data)
* * @returns TRUE
* */
static gint
-delete(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
-{
- struct graphics_priv *this=user_data;
- dbg(lvl_debug,"enter this->win=%p",this->win);
- if (this->delay & 2) {
- if (this->win)
- this->win=NULL;
- } else {
- callback_list_call_attr_0(this->cbl, attr_window_closed);
- }
- return TRUE;
+delete(GtkWidget *widget, GdkEventKey *event, gpointer user_data) {
+ struct graphics_priv *this=user_data;
+ dbg(lvl_debug,"enter this->win=%p",this->win);
+ if (this->delay & 2) {
+ if (this->win)
+ this->win=NULL;
+ } else {
+ callback_list_call_attr_0(this->cbl, attr_window_closed);
+ }
+ return TRUE;
}
static gint
-keypress(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
-{
- struct graphics_priv *this=user_data;
- int len,ucode;
- char key[8];
- ucode=gdk_keyval_to_unicode(event->keyval);
- len=g_unichar_to_utf8(ucode, key);
- key[len]='\0';
-
- switch (event->keyval) {
- case GDK_Up:
- key[0]=NAVIT_KEY_UP;
- key[1]='\0';
- break;
- case GDK_Down:
- key[0]=NAVIT_KEY_DOWN;
- key[1]='\0';
- break;
- case GDK_Left:
- key[0]=NAVIT_KEY_LEFT;
- key[1]='\0';
- break;
- case GDK_Right:
- key[0]=NAVIT_KEY_RIGHT;
- key[1]='\0';
- break;
- case GDK_BackSpace:
- key[0]=NAVIT_KEY_BACKSPACE;
- key[1]='\0';
- break;
- case GDK_Tab:
- key[0]='\t';
- key[1]='\0';
- break;
- case GDK_Delete:
- key[0]=NAVIT_KEY_DELETE;
- key[1]='\0';
- break;
- case GDK_Escape:
- key[0]=NAVIT_KEY_BACK;
- key[1]='\0';
- break;
- case GDK_Return:
- case GDK_KP_Enter:
- key[0]=NAVIT_KEY_RETURN;
- key[1]='\0';
- break;
- case GDK_Book:
+keypress(GtkWidget *widget, GdkEventKey *event, gpointer user_data) {
+ struct graphics_priv *this=user_data;
+ int len,ucode;
+ char key[8];
+ ucode=gdk_keyval_to_unicode(event->keyval);
+ len=g_unichar_to_utf8(ucode, key);
+ key[len]='\0';
+
+ switch (event->keyval) {
+ case GDK_Up:
+ key[0]=NAVIT_KEY_UP;
+ key[1]='\0';
+ break;
+ case GDK_Down:
+ key[0]=NAVIT_KEY_DOWN;
+ key[1]='\0';
+ break;
+ case GDK_Left:
+ key[0]=NAVIT_KEY_LEFT;
+ key[1]='\0';
+ break;
+ case GDK_Right:
+ key[0]=NAVIT_KEY_RIGHT;
+ key[1]='\0';
+ break;
+ case GDK_BackSpace:
+ key[0]=NAVIT_KEY_BACKSPACE;
+ key[1]='\0';
+ break;
+ case GDK_Tab:
+ key[0]='\t';
+ key[1]='\0';
+ break;
+ case GDK_Delete:
+ key[0]=NAVIT_KEY_DELETE;
+ key[1]='\0';
+ break;
+ case GDK_Escape:
+ key[0]=NAVIT_KEY_BACK;
+ key[1]='\0';
+ break;
+ case GDK_Return:
+ case GDK_KP_Enter:
+ key[0]=NAVIT_KEY_RETURN;
+ key[1]='\0';
+ break;
+ case GDK_Book:
#ifdef USE_HILDON
- case GDK_F7:
+ case GDK_F7:
#endif
- key[0]=NAVIT_KEY_ZOOM_IN;
- key[1]='\0';
- break;
- case GDK_Calendar:
+ key[0]=NAVIT_KEY_ZOOM_IN;
+ key[1]='\0';
+ break;
+ case GDK_Calendar:
#ifdef USE_HILDON
- case GDK_F8:
+ case GDK_F8:
#endif
- key[0]=NAVIT_KEY_ZOOM_OUT;
- key[1]='\0';
- break;
- case GDK_Page_Up:
- key[0]=NAVIT_KEY_PAGE_UP;
- key[1]='\0';
- break;
- case GDK_Page_Down:
- key[0]=NAVIT_KEY_PAGE_DOWN;
- key[1]='\0';
- break;
- }
- if (key[0])
- callback_list_call_attr_1(this->cbl, attr_keypress, (void *)key);
- else
- dbg(lvl_debug,"keyval 0x%x", event->keyval);
-
- return FALSE;
+ key[0]=NAVIT_KEY_ZOOM_OUT;
+ key[1]='\0';
+ break;
+ case GDK_Page_Up:
+ key[0]=NAVIT_KEY_PAGE_UP;
+ key[1]='\0';
+ break;
+ case GDK_Page_Down:
+ key[0]=NAVIT_KEY_PAGE_DOWN;
+ key[1]='\0';
+ break;
+ }
+ if (key[0])
+ callback_list_call_attr_1(this->cbl, attr_keypress, (void *)key);
+ else
+ dbg(lvl_debug,"keyval 0x%x", event->keyval);
+
+ return FALSE;
}
static struct graphics_priv *graphics_gtk_drawing_area_new_helper(struct graphics_methods *meth);
static void
-overlay_disable(struct graphics_priv *gr, int disabled)
-{
- if (!gr->overlay_disabled != !disabled) {
- gr->overlay_disabled=disabled;
- if (gr->parent) {
- GdkRectangle r;
- overlay_rect(gr->parent, gr, &r);
- gdk_window_invalidate_rect(gr->parent->widget->window, &r, TRUE);
- }
- }
+overlay_disable(struct graphics_priv *gr, int disabled) {
+ if (!gr->overlay_disabled != !disabled) {
+ gr->overlay_disabled=disabled;
+ if (gr->parent) {
+ GdkRectangle r;
+ overlay_rect(gr->parent, gr, &r);
+ gdk_window_invalidate_rect(gr->parent->widget->window, &r, TRUE);
+ }
+ }
}
static void
-overlay_resize(struct graphics_priv *this, struct point *p, int w, int h, int wraparound)
-{
- //do not dereference parent for non overlay osds
- if(!this->parent) {
- return;
- }
-
- int changed = 0;
- int w2,h2;
-
- if (w == 0) {
- w2 = 1;
- } else {
- w2 = w;
- }
-
- if (h == 0) {
- h2 = 1;
- } else {
- h2 = h;
- }
-
- this->p = *p;
- if (this->width != w2) {
- this->width = w2;
- changed = 1;
- }
-
- if (this->height != h2) {
- this->height = h2;
- changed = 1;
- }
-
- this->wraparound = wraparound;
-
- if (changed) {
- cairo_destroy(this->cairo);
- cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w2, h2);
- this->cairo=cairo_create(surface);
- cairo_surface_destroy(surface);
-
- if ((w == 0) || (h == 0)) {
- this->overlay_autodisabled = 1;
- } else {
- this->overlay_autodisabled = 0;
- }
-
- callback_list_call_attr_2(this->cbl, attr_resize, GINT_TO_POINTER(this->width), GINT_TO_POINTER(this->height));
- }
+overlay_resize(struct graphics_priv *this, struct point *p, int w, int h, int wraparound) {
+ //do not dereference parent for non overlay osds
+ if(!this->parent) {
+ return;
+ }
+
+ int changed = 0;
+ int w2,h2;
+
+ if (w == 0) {
+ w2 = 1;
+ } else {
+ w2 = w;
+ }
+
+ if (h == 0) {
+ h2 = 1;
+ } else {
+ h2 = h;
+ }
+
+ this->p = *p;
+ if (this->width != w2) {
+ this->width = w2;
+ changed = 1;
+ }
+
+ if (this->height != h2) {
+ this->height = h2;
+ changed = 1;
+ }
+
+ this->wraparound = wraparound;
+
+ if (changed) {
+ cairo_destroy(this->cairo);
+ cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w2, h2);
+ this->cairo=cairo_create(surface);
+ cairo_surface_destroy(surface);
+
+ if ((w == 0) || (h == 0)) {
+ this->overlay_autodisabled = 1;
+ } else {
+ this->overlay_autodisabled = 0;
+ }
+
+ callback_list_call_attr_2(this->cbl, attr_resize, GINT_TO_POINTER(this->width), GINT_TO_POINTER(this->height));
+ }
}
static void
-get_data_window(struct graphics_priv *this, unsigned int xid)
-{
- if (!xid)
- this->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- else
- this->win = gtk_plug_new(xid);
- if (!gtk_widget_get_parent(this->widget))
- gtk_widget_ref(this->widget);
- gtk_window_set_default_size(GTK_WINDOW(this->win), this->win_w, this->win_h);
- dbg(lvl_debug,"h= %i, w= %i",this->win_h, this->win_w);
- gtk_window_set_title(GTK_WINDOW(this->win), this->window_title);
- gtk_window_set_wmclass (GTK_WINDOW (this->win), "navit", this->window_title);
- gtk_widget_realize(this->win);
- if (gtk_widget_get_parent(this->widget))
- gtk_widget_reparent(this->widget, this->win);
- else
- gtk_container_add(GTK_CONTAINER(this->win), this->widget);
- gtk_widget_show_all(this->win);
- GTK_WIDGET_SET_FLAGS (this->widget, GTK_CAN_FOCUS);
- gtk_widget_set_sensitive(this->widget, TRUE);
- gtk_widget_grab_focus(this->widget);
- g_signal_connect(G_OBJECT(this->widget), "key-press-event", G_CALLBACK(keypress), this);
- g_signal_connect(G_OBJECT(this->win), "delete_event", G_CALLBACK(delete), this);
+get_data_window(struct graphics_priv *this, unsigned int xid) {
+ if (!xid)
+ this->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ else
+ this->win = gtk_plug_new(xid);
+ if (!gtk_widget_get_parent(this->widget))
+ gtk_widget_ref(this->widget);
+ gtk_window_set_default_size(GTK_WINDOW(this->win), this->win_w, this->win_h);
+ dbg(lvl_debug,"h= %i, w= %i",this->win_h, this->win_w);
+ gtk_window_set_title(GTK_WINDOW(this->win), this->window_title);
+ gtk_window_set_wmclass (GTK_WINDOW (this->win), "navit", this->window_title);
+ gtk_widget_realize(this->win);
+ if (gtk_widget_get_parent(this->widget))
+ gtk_widget_reparent(this->widget, this->win);
+ else
+ gtk_container_add(GTK_CONTAINER(this->win), this->widget);
+ gtk_widget_show_all(this->win);
+ GTK_WIDGET_SET_FLAGS (this->widget, GTK_CAN_FOCUS);
+ gtk_widget_set_sensitive(this->widget, TRUE);
+ gtk_widget_grab_focus(this->widget);
+ g_signal_connect(G_OBJECT(this->widget), "key-press-event", G_CALLBACK(keypress), this);
+ g_signal_connect(G_OBJECT(this->win), "delete_event", G_CALLBACK(delete), this);
}
static int
-set_attr(struct graphics_priv *gr, struct attr *attr)
-{
- dbg(lvl_debug,"enter");
- switch (attr->type) {
- case attr_windowid:
- get_data_window(gr, attr->u.num);
- return 1;
- default:
- return 0;
- }
+set_attr(struct graphics_priv *gr, struct attr *attr) {
+ dbg(lvl_debug,"enter");
+ switch (attr->type) {
+ case attr_windowid:
+ get_data_window(gr, attr->u.num);
+ return 1;
+ default:
+ return 0;
+ }
}
static struct graphics_priv *
-overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound)
-{
- int w2,h2;
- struct graphics_priv *this=graphics_gtk_drawing_area_new_helper(meth);
- this->widget=gr->widget;
- this->p=*p;
- this->width=w;
- this->height=h;
- this->parent=gr;
-
- /* If either height or width is 0, we set it to 1 to avoid warnings, and
- * disable the overlay. */
- if (h == 0) {
- h2 = 1;
- } else {
- h2 = h;
- }
-
- if (w == 0) {
- w2 = 1;
- } else {
- w2 = w;
- }
-
- cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w2, h2);
- this->cairo=cairo_create(surface);
- cairo_surface_destroy(surface);
-
- if ((w == 0) || (h == 0)) {
- this->overlay_autodisabled = 1;
- } else {
- this->overlay_autodisabled = 0;
- }
-
- this->next=gr->overlays;
- this->wraparound=wraparound;
- gr->overlays=this;
- return this;
+overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound) {
+ int w2,h2;
+ struct graphics_priv *this=graphics_gtk_drawing_area_new_helper(meth);
+ this->widget=gr->widget;
+ this->p=*p;
+ this->width=w;
+ this->height=h;
+ this->parent=gr;
+
+ /* If either height or width is 0, we set it to 1 to avoid warnings, and
+ * disable the overlay. */
+ if (h == 0) {
+ h2 = 1;
+ } else {
+ h2 = h;
+ }
+
+ if (w == 0) {
+ w2 = 1;
+ } else {
+ w2 = w;
+ }
+
+ cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w2, h2);
+ this->cairo=cairo_create(surface);
+ cairo_surface_destroy(surface);
+
+ if ((w == 0) || (h == 0)) {
+ this->overlay_autodisabled = 1;
+ } else {
+ this->overlay_autodisabled = 0;
+ }
+
+ this->next=gr->overlays;
+ this->wraparound=wraparound;
+ gr->overlays=this;
+ return this;
}
static int gtk_argc;
-static char **gtk_argv={NULL};
+static char **gtk_argv= {NULL};
static int
-graphics_gtk_drawing_area_fullscreen(struct window *w, int on)
-{
- struct graphics_priv *gr=w->priv;
- if (on)
- gtk_window_fullscreen(GTK_WINDOW(gr->win));
- else
- gtk_window_unfullscreen(GTK_WINDOW(gr->win));
- return 1;
-}
+graphics_gtk_drawing_area_fullscreen(struct window *w, int on) {
+ struct graphics_priv *gr=w->priv;
+ if (on)
+ gtk_window_fullscreen(GTK_WINDOW(gr->win));
+ else
+ gtk_window_unfullscreen(GTK_WINDOW(gr->win));
+ return 1;
+}
static void
-graphics_gtk_drawing_area_disable_suspend(struct window *w)
-{
- struct graphics_priv *gr=w->priv;
+graphics_gtk_drawing_area_disable_suspend(struct window *w) {
+ struct graphics_priv *gr=w->priv;
#ifndef _WIN32
- if (gr->pid)
- kill(gr->pid, SIGWINCH);
+ if (gr->pid)
+ kill(gr->pid, SIGWINCH);
#else
dbg(lvl_warning, "failed to kill() under Windows");
#endif
@@ -1016,144 +978,143 @@ graphics_gtk_drawing_area_disable_suspend(struct window *w)
static void *
-get_data(struct graphics_priv *this, char const *type)
-{
- FILE *f;
- if (!strcmp(type,"gtk_widget"))
- return this->widget;
+get_data(struct graphics_priv *this, char const *type) {
+ FILE *f;
+ if (!strcmp(type,"gtk_widget"))
+ return this->widget;
#ifndef _WIN32
- if (!strcmp(type,"xwindow_id"))
- return (void *)GDK_WINDOW_XID(this->win ? this->win->window : this->widget->window);
+ if (!strcmp(type,"xwindow_id"))
+ return (void *)GDK_WINDOW_XID(this->win ? this->win->window : this->widget->window);
#endif
- if (!strcmp(type,"window")) {
- char *cp = getenv("NAVIT_XID");
- unsigned xid = 0;
- if (cp)
- xid = strtol(cp, NULL, 0);
- if (!(this->delay & 1))
- get_data_window(this, xid);
- this->window.fullscreen=graphics_gtk_drawing_area_fullscreen;
- this->window.disable_suspend=graphics_gtk_drawing_area_disable_suspend;
- this->window.priv=this;
+ if (!strcmp(type,"window")) {
+ char *cp = getenv("NAVIT_XID");
+ unsigned xid = 0;
+ if (cp)
+ xid = strtol(cp, NULL, 0);
+ if (!(this->delay & 1))
+ get_data_window(this, xid);
+ this->window.fullscreen=graphics_gtk_drawing_area_fullscreen;
+ this->window.disable_suspend=graphics_gtk_drawing_area_disable_suspend;
+ this->window.priv=this;
#if !defined(_WIN32) && !defined(__CEGCC__)
- f=popen("pidof /usr/bin/ipaq-sleep","r");
- if (f) {
- int fscanf_result;
- fscanf_result = fscanf(f,"%d",&this->pid);
- if ((fscanf_result == EOF) || (fscanf_result == 0)){
- dbg(lvl_warning, "Failed to open iPaq sleep file. Error-Code: %d" , errno);
- }
- dbg(lvl_debug,"ipaq_sleep pid=%d", this->pid);
- pclose(f);
- }
+ f=popen("pidof /usr/bin/ipaq-sleep","r");
+ if (f) {
+ int fscanf_result;
+ fscanf_result = fscanf(f,"%d",&this->pid);
+ if ((fscanf_result == EOF) || (fscanf_result == 0)) {
+ dbg(lvl_warning, "Failed to open iPaq sleep file. Error-Code: %d", errno);
+ }
+ dbg(lvl_debug,"ipaq_sleep pid=%d", this->pid);
+ pclose(f);
+ }
#endif
- return &this->window;
- }
- return NULL;
+ return &this->window;
+ }
+ return NULL;
}
static struct graphics_methods graphics_methods = {
- graphics_destroy,
- draw_mode,
- draw_lines,
- draw_polygon,
- draw_rectangle,
- draw_circle,
- draw_text,
- draw_image,
+ graphics_destroy,
+ draw_mode,
+ draw_lines,
+ draw_polygon,
+ draw_rectangle,
+ draw_circle,
+ draw_text,
+ draw_image,
#ifdef HAVE_IMLIB2
- draw_image_warp,
+ draw_image_warp,
#else
- NULL,
+ NULL,
#endif
- draw_drag,
- NULL, /* font_new */
- gc_new,
- background_gc,
- overlay_new,
- image_new,
- get_data,
- image_free,
- NULL, /* get_text_bbox */
- overlay_disable,
- overlay_resize,
- set_attr,
- NULL, /* show_native_keyboard */
- NULL, /* hide_native_keyboard */
+ draw_drag,
+ NULL, /* font_new */
+ gc_new,
+ background_gc,
+ overlay_new,
+ image_new,
+ get_data,
+ image_free,
+ NULL, /* get_text_bbox */
+ overlay_disable,
+ overlay_resize,
+ set_attr,
+ NULL, /* show_native_keyboard */
+ NULL, /* hide_native_keyboard */
};
static struct graphics_priv *
-graphics_gtk_drawing_area_new_helper(struct graphics_methods *meth)
-{
- struct font_priv * (*font_freetype_new)(void *meth);
- font_freetype_new=plugin_get_category_font("freetype");
- if (!font_freetype_new)
- return NULL;
- struct graphics_priv *this=g_new0(struct graphics_priv,1);
- font_freetype_new(&this->freetype_methods);
- *meth=graphics_methods;
- meth->font_new=(struct graphics_font_priv *(*)(struct graphics_priv *, struct graphics_font_methods *, char *, int, int))this->freetype_methods.font_new;
- meth->get_text_bbox=(void(*)(struct graphics_priv*, struct graphics_font_priv *, char *, int, int, struct point *, int))this->freetype_methods.get_text_bbox;
- return this;
+graphics_gtk_drawing_area_new_helper(struct graphics_methods *meth) {
+ struct font_priv * (*font_freetype_new)(void *meth);
+ font_freetype_new=plugin_get_category_font("freetype");
+ if (!font_freetype_new)
+ return NULL;
+ struct graphics_priv *this=g_new0(struct graphics_priv,1);
+ font_freetype_new(&this->freetype_methods);
+ *meth=graphics_methods;
+ meth->font_new=(struct graphics_font_priv *(*)(struct graphics_priv *, struct graphics_font_methods *, char *, int,
+ int))this->freetype_methods.font_new;
+ meth->get_text_bbox=(void(*)(struct graphics_priv*, struct graphics_font_priv *, char *, int, int, struct point *,
+ int))this->freetype_methods.get_text_bbox;
+ return this;
}
static struct graphics_priv *
-graphics_gtk_drawing_area_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
- int i;
- GtkWidget *draw;
- struct attr *attr;
-
- if (! event_request_system("glib","graphics_gtk_drawing_area_new"))
- return NULL;
-
- draw=gtk_drawing_area_new();
- struct graphics_priv *this=graphics_gtk_drawing_area_new_helper(meth);
- this->nav = nav;
- this->widget=draw;
- this->win_w=792;
- if ((attr=attr_search(attrs, NULL, attr_w)))
- this->win_w=attr->u.num;
- this->win_h=547;
- if ((attr=attr_search(attrs, NULL, attr_h)))
- this->win_h=attr->u.num;
- this->timeout=100;
- if ((attr=attr_search(attrs, NULL, attr_timeout)))
- this->timeout=attr->u.num;
- this->delay=0;
- if ((attr=attr_search(attrs, NULL, attr_delay)))
- this->delay=attr->u.num;
- if ((attr=attr_search(attrs, NULL, attr_window_title)))
- this->window_title=g_strdup(attr->u.str);
- else
- this->window_title=g_strdup("Navit");
- this->cbl=cbl;
- gtk_widget_set_events(draw, GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK|GDK_POINTER_MOTION_MASK|GDK_KEY_PRESS_MASK);
- g_signal_connect(G_OBJECT(draw), "expose_event", G_CALLBACK(expose), this);
- g_signal_connect(G_OBJECT(draw), "configure_event", G_CALLBACK(configure), this);
- g_signal_connect(G_OBJECT(draw), "button_press_event", G_CALLBACK(button_press), this);
- g_signal_connect(G_OBJECT(draw), "button_release_event", G_CALLBACK(button_release), this);
- g_signal_connect(G_OBJECT(draw), "scroll_event", G_CALLBACK(scroll), this);
- g_signal_connect(G_OBJECT(draw), "motion_notify_event", G_CALLBACK(motion_notify), this);
- g_signal_connect(G_OBJECT(draw), "delete_event", G_CALLBACK(delete), nav);
-
- for (i = 0; i < 8; i++) {
- this->button_press[i].tv_sec = 0;
- this->button_press[i].tv_usec = 0;
- this->button_release[i].tv_sec = 0;
- this->button_release[i].tv_usec = 0;
- }
-
- return this;
+graphics_gtk_drawing_area_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs,
+ struct callback_list *cbl) {
+ int i;
+ GtkWidget *draw;
+ struct attr *attr;
+
+ if (! event_request_system("glib","graphics_gtk_drawing_area_new"))
+ return NULL;
+
+ draw=gtk_drawing_area_new();
+ struct graphics_priv *this=graphics_gtk_drawing_area_new_helper(meth);
+ this->nav = nav;
+ this->widget=draw;
+ this->win_w=792;
+ if ((attr=attr_search(attrs, NULL, attr_w)))
+ this->win_w=attr->u.num;
+ this->win_h=547;
+ if ((attr=attr_search(attrs, NULL, attr_h)))
+ this->win_h=attr->u.num;
+ this->timeout=100;
+ if ((attr=attr_search(attrs, NULL, attr_timeout)))
+ this->timeout=attr->u.num;
+ this->delay=0;
+ if ((attr=attr_search(attrs, NULL, attr_delay)))
+ this->delay=attr->u.num;
+ if ((attr=attr_search(attrs, NULL, attr_window_title)))
+ this->window_title=g_strdup(attr->u.str);
+ else
+ this->window_title=g_strdup("Navit");
+ this->cbl=cbl;
+ gtk_widget_set_events(draw, GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK|GDK_POINTER_MOTION_MASK|GDK_KEY_PRESS_MASK);
+ g_signal_connect(G_OBJECT(draw), "expose_event", G_CALLBACK(expose), this);
+ g_signal_connect(G_OBJECT(draw), "configure_event", G_CALLBACK(configure), this);
+ g_signal_connect(G_OBJECT(draw), "button_press_event", G_CALLBACK(button_press), this);
+ g_signal_connect(G_OBJECT(draw), "button_release_event", G_CALLBACK(button_release), this);
+ g_signal_connect(G_OBJECT(draw), "scroll_event", G_CALLBACK(scroll), this);
+ g_signal_connect(G_OBJECT(draw), "motion_notify_event", G_CALLBACK(motion_notify), this);
+ g_signal_connect(G_OBJECT(draw), "delete_event", G_CALLBACK(delete), nav);
+
+ for (i = 0; i < 8; i++) {
+ this->button_press[i].tv_sec = 0;
+ this->button_press[i].tv_usec = 0;
+ this->button_release[i].tv_sec = 0;
+ this->button_release[i].tv_usec = 0;
+ }
+
+ return this;
}
void
-plugin_init(void)
-{
- gtk_init(&gtk_argc, &gtk_argv);
- gtk_set_locale();
+plugin_init(void) {
+ gtk_init(&gtk_argc, &gtk_argv);
+ gtk_set_locale();
#ifdef HAVE_API_WIN32
- setlocale(LC_NUMERIC, "C"); /* WIN32 gtk resets LC_NUMERIC */
+ setlocale(LC_NUMERIC, "C"); /* WIN32 gtk resets LC_NUMERIC */
#endif
- plugin_register_category_graphics("gtk_drawing_area", graphics_gtk_drawing_area_new);
+ plugin_register_category_graphics("gtk_drawing_area", graphics_gtk_drawing_area_new);
}
diff --git a/navit/graphics/null/graphics_null.c b/navit/graphics/null/graphics_null.c
index 3b527800f..edceb778e 100644
--- a/navit/graphics/null/graphics_null.c
+++ b/navit/graphics/null/graphics_null.c
@@ -39,321 +39,286 @@
static struct callback_list* callbacks;
static struct graphics_priv {
- int dummy;
+ int dummy;
} graphics_priv;
static struct graphics_font_priv {
- int dummy;
+ int dummy;
} graphics_font_priv;
static struct graphics_gc_priv {
- int dummy;
+ int dummy;
} graphics_gc_priv;
static struct graphics_image_priv {
- int dummy;
+ int dummy;
} graphics_image_priv;
static void
-graphics_destroy(struct graphics_priv *gr)
-{
+graphics_destroy(struct graphics_priv *gr) {
}
-static void font_destroy(struct graphics_font_priv *font)
-{
+static void font_destroy(struct graphics_font_priv *font) {
}
static struct graphics_font_methods font_methods = {
- font_destroy
+ font_destroy
};
-static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth, char *font, int size, int flags)
-{
- *meth=font_methods;
- return &graphics_font_priv;
+static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth, char *font,
+ int size, int flags) {
+ *meth=font_methods;
+ return &graphics_font_priv;
}
static void
-gc_destroy(struct graphics_gc_priv *gc)
-{
+gc_destroy(struct graphics_gc_priv *gc) {
}
static void
-gc_set_linewidth(struct graphics_gc_priv *gc, int w)
-{
+gc_set_linewidth(struct graphics_gc_priv *gc, int w) {
}
static void
-gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n)
-{
+gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n) {
}
static void
-gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
-{
+gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) {
}
static void
-gc_set_background(struct graphics_gc_priv *gc, struct color *c)
-{
+gc_set_background(struct graphics_gc_priv *gc, struct color *c) {
}
static struct graphics_gc_methods gc_methods = {
- gc_destroy,
- gc_set_linewidth,
- gc_set_dashes,
- gc_set_foreground,
- gc_set_background
+ gc_destroy,
+ gc_set_linewidth,
+ gc_set_dashes,
+ gc_set_foreground,
+ gc_set_background
};
-static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
-{
- *meth=gc_methods;
- return &graphics_gc_priv;
+static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
+ *meth=gc_methods;
+ return &graphics_gc_priv;
}
static struct graphics_image_priv *
-image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *path, int *w, int *h, struct point *hot, int rotation)
-{
- return &graphics_image_priv;
+image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *path, int *w, int *h, struct point *hot,
+ int rotation) {
+ return &graphics_image_priv;
}
static void
-draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
+draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
}
static void
-draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
+draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
}
static void
-draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h)
-{
+draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h) {
}
static void
-draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r)
-{
+draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r) {
}
static void
-draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy)
-{
+draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg,
+ struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy) {
}
static void
-draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img)
-{
+draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img) {
}
-static void draw_drag(struct graphics_priv *gr, struct point *p)
-{
+static void draw_drag(struct graphics_priv *gr, struct point *p) {
}
static void
-background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
+background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
}
static void
-draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
-{
+draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
}
-static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound);
+static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p,
+ int w, int h, int wraparound);
static void
-resize_callback(int w, int h)
-{
- callback_list_call_attr_2(callbacks, attr_resize,
- GINT_TO_POINTER(1), GINT_TO_POINTER(1));
+resize_callback(int w, int h) {
+ callback_list_call_attr_2(callbacks, attr_resize,
+ GINT_TO_POINTER(1), GINT_TO_POINTER(1));
}
static int
-graphics_null_fullscreen(struct window *w, int on)
-{
- return 1;
+graphics_null_fullscreen(struct window *w, int on) {
+ return 1;
}
static void
-graphics_null_disable_suspend(struct window *w)
-{
+graphics_null_disable_suspend(struct window *w) {
}
static void *
-get_data(struct graphics_priv *this, char const *type)
-{
- if (strcmp(type, "window") == 0) {
- struct window *win;
- win = g_new0(struct window, 1);
- win->priv = this;
- win->fullscreen = graphics_null_fullscreen;
- win->disable_suspend = graphics_null_disable_suspend;
- resize_callback(1,1);
- return win;
- }
- return NULL;
+get_data(struct graphics_priv *this, char const *type) {
+ if (strcmp(type, "window") == 0) {
+ struct window *win;
+ win = g_new0(struct window, 1);
+ win->priv = this;
+ win->fullscreen = graphics_null_fullscreen;
+ win->disable_suspend = graphics_null_disable_suspend;
+ resize_callback(1,1);
+ return win;
+ }
+ return NULL;
}
-static void image_free(struct graphics_priv *gr, struct graphics_image_priv *priv)
-{
+static void image_free(struct graphics_priv *gr, struct graphics_image_priv *priv) {
}
-static void get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy, struct point *ret, int estimate)
-{
+static void get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy,
+ struct point *ret, int estimate) {
}
-static void overlay_disable(struct graphics_priv *gr, int disable)
-{
+static void overlay_disable(struct graphics_priv *gr, int disable) {
}
-static void overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h, int wraparound)
-{
+static void overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h, int wraparound) {
}
static struct graphics_methods graphics_methods = {
- graphics_destroy,
- draw_mode,
- draw_lines,
- draw_polygon,
- draw_rectangle,
- draw_circle,
- draw_text,
- draw_image,
- NULL,
- draw_drag,
- font_new,
- gc_new,
- background_gc,
- overlay_new,
- image_new,
- get_data,
- image_free,
- get_text_bbox,
- overlay_disable,
- overlay_resize,
- NULL, /* show_native_keyboard */
- NULL, /* hide_native_keyboard */
+ graphics_destroy,
+ draw_mode,
+ draw_lines,
+ draw_polygon,
+ draw_rectangle,
+ draw_circle,
+ draw_text,
+ draw_image,
+ NULL,
+ draw_drag,
+ font_new,
+ gc_new,
+ background_gc,
+ overlay_new,
+ image_new,
+ get_data,
+ image_free,
+ get_text_bbox,
+ overlay_disable,
+ overlay_resize,
+ NULL, /* show_native_keyboard */
+ NULL, /* hide_native_keyboard */
};
static struct graphics_priv *
-overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound)
-{
- *meth=graphics_methods;
- return &graphics_priv;
+overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound) {
+ *meth=graphics_methods;
+ return &graphics_priv;
}
static struct graphics_priv *
-graphics_null_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
- struct attr *event_loop_system = NULL;
- *meth=graphics_methods;
-
- event_loop_system = attr_search(attrs, NULL, attr_event_loop_system);
-
- if (event_loop_system && event_loop_system->u.str) {
- dbg(lvl_debug, "event_system is %s", event_loop_system->u.str);
- if (!event_request_system(event_loop_system->u.str, "graphics_null"))
- return NULL;
- } else {
- if (!event_request_system("null", "graphics_null"))
- return NULL;
- }
- callbacks = cbl;
- resize_callback(1,1);
- return &graphics_priv;
+graphics_null_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl) {
+ struct attr *event_loop_system = NULL;
+ *meth=graphics_methods;
+
+ event_loop_system = attr_search(attrs, NULL, attr_event_loop_system);
+
+ if (event_loop_system && event_loop_system->u.str) {
+ dbg(lvl_debug, "event_system is %s", event_loop_system->u.str);
+ if (!event_request_system(event_loop_system->u.str, "graphics_null"))
+ return NULL;
+ } else {
+ if (!event_request_system("null", "graphics_null"))
+ return NULL;
+ }
+ callbacks = cbl;
+ resize_callback(1,1);
+ return &graphics_priv;
}
static void
-event_null_main_loop_run(void)
-{
+event_null_main_loop_run(void) {
- dbg(lvl_debug,"enter");
- for (;;)
- sleep(1);
+ dbg(lvl_debug,"enter");
+ for (;;)
+ sleep(1);
}
-static void event_null_main_loop_quit(void)
-{
- dbg(lvl_debug,"enter");
+static void event_null_main_loop_quit(void) {
+ dbg(lvl_debug,"enter");
}
static struct event_watch *
-event_null_add_watch(int h, enum event_watch_cond cond, struct callback *cb)
-{
- dbg(lvl_debug,"enter");
- return NULL;
+event_null_add_watch(int h, enum event_watch_cond cond, struct callback *cb) {
+ dbg(lvl_debug,"enter");
+ return NULL;
}
static void
-event_null_remove_watch(struct event_watch *ev)
-{
- dbg(lvl_debug,"enter");
+event_null_remove_watch(struct event_watch *ev) {
+ dbg(lvl_debug,"enter");
}
static struct event_timeout *
-event_null_add_timeout(int timeout, int multi, struct callback *cb)
-{
- dbg(lvl_debug,"enter");
- return NULL;
+event_null_add_timeout(int timeout, int multi, struct callback *cb) {
+ dbg(lvl_debug,"enter");
+ return NULL;
}
static void
-event_null_remove_timeout(struct event_timeout *to)
-{
- dbg(lvl_debug,"enter");
+event_null_remove_timeout(struct event_timeout *to) {
+ dbg(lvl_debug,"enter");
}
static struct event_idle *
-event_null_add_idle(int priority, struct callback *cb)
-{
- dbg(lvl_debug,"enter");
- return NULL;
+event_null_add_idle(int priority, struct callback *cb) {
+ dbg(lvl_debug,"enter");
+ return NULL;
}
static void
-event_null_remove_idle(struct event_idle *ev)
-{
- dbg(lvl_debug,"enter");
+event_null_remove_idle(struct event_idle *ev) {
+ dbg(lvl_debug,"enter");
}
static void
-event_null_call_callback(struct callback_list *cb)
-{
- dbg(lvl_debug,"enter");
+event_null_call_callback(struct callback_list *cb) {
+ dbg(lvl_debug,"enter");
}
static struct event_methods event_null_methods = {
- event_null_main_loop_run,
- event_null_main_loop_quit,
- event_null_add_watch,
- event_null_remove_watch,
- event_null_add_timeout,
- event_null_remove_timeout,
- event_null_add_idle,
- event_null_remove_idle,
- event_null_call_callback,
+ event_null_main_loop_run,
+ event_null_main_loop_quit,
+ event_null_add_watch,
+ event_null_remove_watch,
+ event_null_add_timeout,
+ event_null_remove_timeout,
+ event_null_add_idle,
+ event_null_remove_idle,
+ event_null_call_callback,
};
static struct event_priv *
-event_null_new(struct event_methods *meth)
-{
- *meth=event_null_methods;
- return NULL;
+event_null_new(struct event_methods *meth) {
+ *meth=event_null_methods;
+ return NULL;
}
void
-plugin_init(void)
-{
- plugin_register_category_graphics("null", graphics_null_new);
- plugin_register_category_event("null", event_null_new);
+plugin_init(void) {
+ plugin_register_category_graphics("null", graphics_null_new);
+ plugin_register_category_event("null", event_null_new);
}
diff --git a/navit/graphics/opengl/graphics_opengl.c b/navit/graphics/opengl/graphics_opengl.c
index c23d57204..b6b3c8782 100644
--- a/navit/graphics/opengl/graphics_opengl.c
+++ b/navit/graphics/opengl/graphics_opengl.c
@@ -114,73 +114,74 @@ typedef GLfixed GLf;
//#define MIRRORED_VIEW 1
struct graphics_gc_priv {
- struct graphics_priv *gr;
- float fr, fg, fb, fa;
- float br, bg, bb, ba;
- int linewidth;
- unsigned char *dash_list;
- int dash_count;
- int dash_mask;
+ struct graphics_priv *gr;
+ float fr, fg, fb, fa;
+ float br, bg, bb, ba;
+ int linewidth;
+ unsigned char *dash_list;
+ int dash_count;
+ int dash_mask;
} graphics_gc_priv;
struct graphics_priv {
- int button_timeout;
- struct point p;
- int width;
- int height;
- int library_init;
- int visible;
- int overlay_enabled;
- int overlay_autodisabled;
- int wraparound;
- struct graphics_priv *parent;
- struct graphics_priv *overlays;
- struct graphics_priv *next;
- struct graphics_gc_priv *background_gc;
- enum draw_mode_num mode;
- void (*resize_callback) (void *data, int w, int h);
- void *resize_callback_data;
- void (*motion_callback) (void *data, struct point * p);
- void *motion_callback_data;
- void (*button_callback) (void *data, int press, int button,
- struct point * p);
- void *button_callback_data;
+ int button_timeout;
+ struct point p;
+ int width;
+ int height;
+ int library_init;
+ int visible;
+ int overlay_enabled;
+ int overlay_autodisabled;
+ int wraparound;
+ struct graphics_priv *parent;
+ struct graphics_priv *overlays;
+ struct graphics_priv *next;
+ struct graphics_gc_priv *background_gc;
+ enum draw_mode_num mode;
+ void (*resize_callback) (void *data, int w, int h);
+ void *resize_callback_data;
+ void (*motion_callback) (void *data, struct point * p);
+ void *motion_callback_data;
+ void (*button_callback) (void *data, int press, int button,
+ struct point * p);
+ void *button_callback_data;
#ifdef USE_OPENGLES
- GLuint program;
- GLint mvp_location, position_location, color_location, texture_position_location, use_texture_location, texture_location;
+ GLuint program;
+ GLint mvp_location, position_location, color_location, texture_position_location, use_texture_location,
+ texture_location;
#else
- GLuint DLid;
+ GLuint DLid;
#endif
- struct callback_list *cbl;
- struct font_freetype_methods freetype_methods;
- struct navit *nav;
- int timeout;
- int delay;
- struct window window;
- int dirty; //display needs to be redrawn (draw on root graphics or overlay is done)
- int force_redraw; //display needs to be redrawn (draw on root graphics or overlay is done)
- time_t last_refresh_time; //last display refresh time
- struct graphics_opengl_window_system *window_system;
- struct graphics_opengl_window_system_methods *window_system_methods;
- struct graphics_opengl_platform *platform;
- struct graphics_opengl_platform_methods *platform_methods;
+ struct callback_list *cbl;
+ struct font_freetype_methods freetype_methods;
+ struct navit *nav;
+ int timeout;
+ int delay;
+ struct window window;
+ int dirty; //display needs to be redrawn (draw on root graphics or overlay is done)
+ int force_redraw; //display needs to be redrawn (draw on root graphics or overlay is done)
+ time_t last_refresh_time; //last display refresh time
+ struct graphics_opengl_window_system *window_system;
+ struct graphics_opengl_window_system_methods *window_system_methods;
+ struct graphics_opengl_platform *platform;
+ struct graphics_opengl_platform_methods *platform_methods;
};
static struct graphics_priv *graphics_priv_root;
struct graphics_image_priv {
- int w;
- int h;
- int hot_x;
- int hot_y;
- unsigned char *data;
- char *path;
+ int w;
+ int h;
+ int hot_x;
+ int hot_y;
+ unsigned char *data;
+ char *path;
} graphics_image_priv;
struct mouse_event_queue_element {
- int button;
- int state;
- int x;
- int y;
+ int button;
+ int state;
+ int x;
+ int y;
};
static const int mouse_event_queue_size = 100;
@@ -204,8 +205,8 @@ const char *getPrimitiveType(GLenum type);
#endif
static struct graphics_priv *graphics_opengl_new_helper(struct
- graphics_methods
- *meth);
+ graphics_methods
+ *meth);
static void display(void);
static void resize_callback(int w, int h);
#ifdef USE_OPENGLES
@@ -217,7 +218,7 @@ static void glut_close(void);
#ifdef USE_OPENGLES2
const char vertex_src [] =
-" \
+ " \
attribute vec2 position; \
attribute vec2 texture_position; \
uniform mat4 mvp; \
@@ -231,7 +232,7 @@ const char vertex_src [] =
";
const char fragment_src [] =
-" \
+ " \
uniform lowp vec4 avcolor; \
uniform sampler2D texture; \
uniform bool use_texture; \
@@ -248,455 +249,440 @@ const char fragment_src [] =
#endif
static void
-graphics_destroy(struct graphics_priv *gr)
-{
- /*FIXME graphics_destroy is never called */
- /*TODO add destroy code for image cache(delete entries in hImageData) */
- gr->freetype_methods.destroy();
- g_free(gr);
- gr = NULL;
+graphics_destroy(struct graphics_priv *gr) {
+ /*FIXME graphics_destroy is never called */
+ /*TODO add destroy code for image cache(delete entries in hImageData) */
+ gr->freetype_methods.destroy();
+ g_free(gr);
+ gr = NULL;
}
static void
-gc_destroy(struct graphics_gc_priv *gc)
-{
- g_free(gc);
- gc = NULL;
+gc_destroy(struct graphics_gc_priv *gc) {
+ g_free(gc);
+ gc = NULL;
}
static void
-gc_set_linewidth(struct graphics_gc_priv *gc, int w)
-{
- gc->linewidth = w;
+gc_set_linewidth(struct graphics_gc_priv *gc, int w) {
+ gc->linewidth = w;
}
static void
gc_set_dashes(struct graphics_gc_priv *gc, int width, int offset,
- unsigned char *dash_list, int n)
-{
- int i;
- const int cOpenglMaskBits = 16;
- gc->dash_count = n;
- if (1 == n) {
- gc->dash_mask = 0;
- for (i = 0; i < cOpenglMaskBits; ++i) {
- gc->dash_mask <<= 1;
- gc->dash_mask |= (i / n) % 2;
- }
- } else if (1 < n) {
- unsigned char *curr = dash_list;
- int cnt = 0; //dot counter
- int dcnt = 0; //dash element counter
- int sum_dash = 0;
- gc->dash_mask = 0;
-
- for (i = 0; i < n; ++i) {
- sum_dash += dash_list[i];
- }
-
- //scale dashlist elements to max size
- if (sum_dash > cOpenglMaskBits) {
- int num_error[2] = { 0, 0 }; //count elements rounded to 0 for odd(drawn) and even(masked) for compensation
- double factor = (1.0 * cOpenglMaskBits) / sum_dash;
- for (i = 0; i < n; ++i) { //calculate dashlist max and largest common denomiator for scaling
- dash_list[i] *= factor;
- if (dash_list[i] == 0) {
- ++dash_list[i];
- ++num_error[i % 2];
- } else if (0 < num_error[i % 2]
- && 2 < dash_list[i]) {
- ++dash_list[i];
- --num_error[i % 2];
- }
- }
- }
- //calculate mask
- for (i = 0; i < cOpenglMaskBits; ++i) {
- gc->dash_mask <<= 1;
- gc->dash_mask |= 1 - dcnt % 2;
- ++cnt;
- if (cnt == *curr) {
- cnt = 0;
- ++curr;
- ++dcnt;
- if (dcnt == n) {
- curr = dash_list;
- }
- }
- }
- }
+ unsigned char *dash_list, int n) {
+ int i;
+ const int cOpenglMaskBits = 16;
+ gc->dash_count = n;
+ if (1 == n) {
+ gc->dash_mask = 0;
+ for (i = 0; i < cOpenglMaskBits; ++i) {
+ gc->dash_mask <<= 1;
+ gc->dash_mask |= (i / n) % 2;
+ }
+ } else if (1 < n) {
+ unsigned char *curr = dash_list;
+ int cnt = 0; //dot counter
+ int dcnt = 0; //dash element counter
+ int sum_dash = 0;
+ gc->dash_mask = 0;
+
+ for (i = 0; i < n; ++i) {
+ sum_dash += dash_list[i];
+ }
+
+ //scale dashlist elements to max size
+ if (sum_dash > cOpenglMaskBits) {
+ int num_error[2] = { 0, 0 }; //count elements rounded to 0 for odd(drawn) and even(masked) for compensation
+ double factor = (1.0 * cOpenglMaskBits) / sum_dash;
+ for (i = 0; i < n; ++i) { //calculate dashlist max and largest common denomiator for scaling
+ dash_list[i] *= factor;
+ if (dash_list[i] == 0) {
+ ++dash_list[i];
+ ++num_error[i % 2];
+ } else if (0 < num_error[i % 2]
+ && 2 < dash_list[i]) {
+ ++dash_list[i];
+ --num_error[i % 2];
+ }
+ }
+ }
+ //calculate mask
+ for (i = 0; i < cOpenglMaskBits; ++i) {
+ gc->dash_mask <<= 1;
+ gc->dash_mask |= 1 - dcnt % 2;
+ ++cnt;
+ if (cnt == *curr) {
+ cnt = 0;
+ ++curr;
+ ++dcnt;
+ if (dcnt == n) {
+ curr = dash_list;
+ }
+ }
+ }
+ }
}
static void
-gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
-{
- gc->fr = c->r / 65535.0;
- gc->fg = c->g / 65535.0;
- gc->fb = c->b / 65535.0;
- gc->fa = c->a / 65535.0;
+gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) {
+ gc->fr = c->r / 65535.0;
+ gc->fg = c->g / 65535.0;
+ gc->fb = c->b / 65535.0;
+ gc->fa = c->a / 65535.0;
}
static void
-gc_set_background(struct graphics_gc_priv *gc, struct color *c)
-{
- gc->br = c->r / 65535.0;
- gc->bg = c->g / 65535.0;
- gc->bb = c->b / 65535.0;
- gc->ba = c->a / 65535.0;
+gc_set_background(struct graphics_gc_priv *gc, struct color *c) {
+ gc->br = c->r / 65535.0;
+ gc->bg = c->g / 65535.0;
+ gc->bb = c->b / 65535.0;
+ gc->ba = c->a / 65535.0;
}
static struct graphics_gc_methods gc_methods = {
- gc_destroy,
- gc_set_linewidth,
- gc_set_dashes,
- gc_set_foreground,
- gc_set_background
+ gc_destroy,
+ gc_set_linewidth,
+ gc_set_dashes,
+ gc_set_foreground,
+ gc_set_background
};
static struct graphics_gc_priv *
-gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
-{
- struct graphics_gc_priv *gc = g_new0(struct graphics_gc_priv, 1);
-
- *meth = gc_methods;
- gc->gr = gr;
- gc->linewidth = 1;
- return gc;
+gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
+ struct graphics_gc_priv *gc = g_new0(struct graphics_gc_priv, 1);
+
+ *meth = gc_methods;
+ gc->gr = gr;
+ gc->linewidth = 1;
+ return gc;
}
static struct graphics_image_priv image_error;
static struct graphics_image_priv *
image_new(struct graphics_priv *gr, struct graphics_image_methods *meth,
- char *path, int *w, int *h, struct point *hot, int rotation)
-{
+ char *path, int *w, int *h, struct point *hot, int rotation) {
#ifdef HAVE_FREEIMAGE
- FIBITMAP *image;
- RGBQUAD aPixel;
- unsigned char *data;
- int width, height, i, j;
- struct graphics_image_priv *gi;
- //check if image already exists in hashmap
- struct graphics_image_priv *curr_elem =
- g_hash_table_lookup(hImageData, path);
- if (curr_elem == &image_error) {
- //found but couldn't be loaded
- return NULL;
- } else if (curr_elem) {
- //found and OK -> use hastable entry
- *w = curr_elem->w;
- *h = curr_elem->h;
- hot->x = curr_elem->w / 2 - 1;
- hot->y = curr_elem->h / 2 - 1;
- return curr_elem;
- } else {
- if (strlen(path) < 4) {
- g_hash_table_insert(hImageData, g_strdup(path),
- &image_error);
- return NULL;
- }
- char *ext_str = path + strlen(path) - 3;
- if (strstr(ext_str, "png") || strstr(path, "PNG")) {
- if ((image =
- FreeImage_Load(FIF_PNG, path, 0)) == NULL) {
- g_hash_table_insert(hImageData,
- g_strdup(path),
- &image_error);
- return NULL;
- }
- } else if (strstr(ext_str, "xpm") || strstr(path, "XPM")) {
- if ((image =
- FreeImage_Load(FIF_XPM, path, 0)) == NULL) {
- g_hash_table_insert(hImageData,
- g_strdup(path),
- &image_error);
- return NULL;
- }
- } else if (strstr(ext_str, "svg") || strstr(path, "SVG")) {
- char path_new[256];
- snprintf(path_new, strlen(path) - 3, "%s", path);
- strcat(path_new, "_48_48.png");
-
- if ((image =
- FreeImage_Load(FIF_PNG, path_new,
- 0)) == NULL) {
- g_hash_table_insert(hImageData,
- g_strdup(path),
- &image_error);
- return NULL;
- }
- } else {
- g_hash_table_insert(hImageData, g_strdup(path),
- &image_error);
- return NULL;
- }
-
- if (FreeImage_GetBPP(image) == 64) {
- FIBITMAP *image2;
- image2 = FreeImage_ConvertTo32Bits(image);
- FreeImage_Unload(image);
- image = image2;
- }
+ FIBITMAP *image;
+ RGBQUAD aPixel;
+ unsigned char *data;
+ int width, height, i, j;
+ struct graphics_image_priv *gi;
+ //check if image already exists in hashmap
+ struct graphics_image_priv *curr_elem =
+ g_hash_table_lookup(hImageData, path);
+ if (curr_elem == &image_error) {
+ //found but couldn't be loaded
+ return NULL;
+ } else if (curr_elem) {
+ //found and OK -> use hastable entry
+ *w = curr_elem->w;
+ *h = curr_elem->h;
+ hot->x = curr_elem->w / 2 - 1;
+ hot->y = curr_elem->h / 2 - 1;
+ return curr_elem;
+ } else {
+ if (strlen(path) < 4) {
+ g_hash_table_insert(hImageData, g_strdup(path),
+ &image_error);
+ return NULL;
+ }
+ char *ext_str = path + strlen(path) - 3;
+ if (strstr(ext_str, "png") || strstr(path, "PNG")) {
+ if ((image =
+ FreeImage_Load(FIF_PNG, path, 0)) == NULL) {
+ g_hash_table_insert(hImageData,
+ g_strdup(path),
+ &image_error);
+ return NULL;
+ }
+ } else if (strstr(ext_str, "xpm") || strstr(path, "XPM")) {
+ if ((image =
+ FreeImage_Load(FIF_XPM, path, 0)) == NULL) {
+ g_hash_table_insert(hImageData,
+ g_strdup(path),
+ &image_error);
+ return NULL;
+ }
+ } else if (strstr(ext_str, "svg") || strstr(path, "SVG")) {
+ char path_new[256];
+ snprintf(path_new, strlen(path) - 3, "%s", path);
+ strcat(path_new, "_48_48.png");
+
+ if ((image =
+ FreeImage_Load(FIF_PNG, path_new,
+ 0)) == NULL) {
+ g_hash_table_insert(hImageData,
+ g_strdup(path),
+ &image_error);
+ return NULL;
+ }
+ } else {
+ g_hash_table_insert(hImageData, g_strdup(path),
+ &image_error);
+ return NULL;
+ }
+
+ if (FreeImage_GetBPP(image) == 64) {
+ FIBITMAP *image2;
+ image2 = FreeImage_ConvertTo32Bits(image);
+ FreeImage_Unload(image);
+ image = image2;
+ }
#if FREEIMAGE_MAJOR_VERSION*100+FREEIMAGE_MINOR_VERSION >= 313
- if (rotation) {
- FIBITMAP *image2;
- image2 = FreeImage_Rotate(image, rotation, NULL);
- image = image2;
- }
+ if (rotation) {
+ FIBITMAP *image2;
+ image2 = FreeImage_Rotate(image, rotation, NULL);
+ image = image2;
+ }
#endif
- gi = g_new0(struct graphics_image_priv, 1);
-
- width = FreeImage_GetWidth(image);
- height = FreeImage_GetHeight(image);
-
- if ((*w != width || *h != height) && *w != IMAGE_W_H_UNSET && *h != IMAGE_W_H_UNSET) {
- FIBITMAP *image2;
- image2 = FreeImage_Rescale(image, *w, *h, FILTER_BOX);
- FreeImage_Unload(image);
- image = image2;
- width = *w;
- height = *h;
- }
-
- data = (unsigned char *) malloc(width * height * 4);
-
- RGBQUAD *palette = NULL;
- if (FreeImage_GetBPP(image) == 8) {
- palette = FreeImage_GetPalette(image);
- }
-
- for (i = 0; i < height; i++) {
- for (j = 0; j < width; j++) {
- unsigned char idx;
- if (FreeImage_GetBPP(image) == 8) {
- FreeImage_GetPixelIndex(image, j,
- height -
- i - 1,
- &idx);
- data[4 * width * i + 4 * j + 0] =
- palette[idx].rgbRed;
- data[4 * width * i + 4 * j + 1] =
- palette[idx].rgbGreen;
- data[4 * width * i + 4 * j + 2] =
- palette[idx].rgbBlue;
- data[4 * width * i + 4 * j + 3] =
- 255;
- } else if (FreeImage_GetBPP(image) == 16
- || FreeImage_GetBPP(image) == 24
- || FreeImage_GetBPP(image) ==
- 32) {
- FreeImage_GetPixelColor(image, j,
- height -
- i - 1,
- &aPixel);
- int transparent =
- (aPixel.rgbRed == 0
- && aPixel.rgbBlue == 0
- && aPixel.rgbGreen == 0);
- data[4 * width * i + 4 * j + 0] =
- transparent ? 0 : (aPixel.
- rgbRed);
- data[4 * width * i + 4 * j + 1] =
- (aPixel.rgbGreen);
- data[4 * width * i + 4 * j + 2] =
- transparent ? 0 : (aPixel.
- rgbBlue);
- data[4 * width * i + 4 * j + 3] =
- transparent ? 0 : 255;
-
- }
- }
- }
-
- FreeImage_Unload(image);
-
- *w = width;
- *h = height;
- gi->w = width;
- gi->h = height;
- gi->hot_x = width / 2 - 1;
- gi->hot_y = height / 2 - 1;
- hot->x = width / 2 - 1;
- hot->y = height / 2 - 1;
- gi->data = data;
- gi->path = path;
- //add to hashtable
- g_hash_table_insert(hImageData, g_strdup(path), gi);
- return gi;
- }
+ gi = g_new0(struct graphics_image_priv, 1);
+
+ width = FreeImage_GetWidth(image);
+ height = FreeImage_GetHeight(image);
+
+ if ((*w != width || *h != height) && *w != IMAGE_W_H_UNSET && *h != IMAGE_W_H_UNSET) {
+ FIBITMAP *image2;
+ image2 = FreeImage_Rescale(image, *w, *h, FILTER_BOX);
+ FreeImage_Unload(image);
+ image = image2;
+ width = *w;
+ height = *h;
+ }
+
+ data = (unsigned char *) malloc(width * height * 4);
+
+ RGBQUAD *palette = NULL;
+ if (FreeImage_GetBPP(image) == 8) {
+ palette = FreeImage_GetPalette(image);
+ }
+
+ for (i = 0; i < height; i++) {
+ for (j = 0; j < width; j++) {
+ unsigned char idx;
+ if (FreeImage_GetBPP(image) == 8) {
+ FreeImage_GetPixelIndex(image, j,
+ height -
+ i - 1,
+ &idx);
+ data[4 * width * i + 4 * j + 0] =
+ palette[idx].rgbRed;
+ data[4 * width * i + 4 * j + 1] =
+ palette[idx].rgbGreen;
+ data[4 * width * i + 4 * j + 2] =
+ palette[idx].rgbBlue;
+ data[4 * width * i + 4 * j + 3] =
+ 255;
+ } else if (FreeImage_GetBPP(image) == 16
+ || FreeImage_GetBPP(image) == 24
+ || FreeImage_GetBPP(image) ==
+ 32) {
+ FreeImage_GetPixelColor(image, j,
+ height -
+ i - 1,
+ &aPixel);
+ int transparent =
+ (aPixel.rgbRed == 0
+ && aPixel.rgbBlue == 0
+ && aPixel.rgbGreen == 0);
+ data[4 * width * i + 4 * j + 0] =
+ transparent ? 0 : (aPixel.
+ rgbRed);
+ data[4 * width * i + 4 * j + 1] =
+ (aPixel.rgbGreen);
+ data[4 * width * i + 4 * j + 2] =
+ transparent ? 0 : (aPixel.
+ rgbBlue);
+ data[4 * width * i + 4 * j + 3] =
+ transparent ? 0 : 255;
+
+ }
+ }
+ }
+
+ FreeImage_Unload(image);
+
+ *w = width;
+ *h = height;
+ gi->w = width;
+ gi->h = height;
+ gi->hot_x = width / 2 - 1;
+ gi->hot_y = height / 2 - 1;
+ hot->x = width / 2 - 1;
+ hot->y = height / 2 - 1;
+ gi->data = data;
+ gi->path = path;
+ //add to hashtable
+ g_hash_table_insert(hImageData, g_strdup(path), gi);
+ return gi;
+ }
#else
- dbg(lvl_error,"FreeImage not available - cannot load any images.");
- return NULL;
+ dbg(lvl_error,"FreeImage not available - cannot load any images.");
+ return NULL;
#endif
}
static void
-set_color(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
+set_color(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
#ifdef USE_OPENGLES2
- GLfloat col[4];
- col[0]=gc->fr;
- col[1]=gc->fg;
- col[2]=gc->fb;
- col[3]=1.0;
- glUniform4fv(gr->color_location, 1, col);
+ GLfloat col[4];
+ col[0]=gc->fr;
+ col[1]=gc->fg;
+ col[2]=gc->fb;
+ col[3]=1.0;
+ glUniform4fv(gr->color_location, 1, col);
#else
- glColor4f(glF(gc->fr), glF(gc->fg), glF(gc->fb), glF(gc->fa));
+ glColor4f(glF(gc->fr), glF(gc->fg), glF(gc->fb), glF(gc->fa));
#endif
}
static void
-draw_array(struct graphics_priv *gr, struct point *p, int count, GLenum mode)
-{
- int i;
+draw_array(struct graphics_priv *gr, struct point *p, int count, GLenum mode) {
+ int i;
#ifdef USE_OPENGLES
- GLf x[count*2];
+ GLf x[count*2];
#else
- glBegin(mode);
+ glBegin(mode);
#endif
- for (i = 0 ; i < count ; i++) {
+ for (i = 0 ; i < count ; i++) {
#ifdef USE_OPENGLES
- x[i*2]=glF(p[i].x);
- x[i*2+1]=glF(p[i].y);
+ x[i*2]=glF(p[i].x);
+ x[i*2+1]=glF(p[i].y);
#else
- glVertex2f(p[i].x, p[i].y);
+ glVertex2f(p[i].x, p[i].y);
#endif
- }
+ }
#ifdef USE_OPENGLES
#ifdef USE_OPENGLES2
- glVertexAttribPointer (gr->position_location, 2, GL_FLOAT, 0, 0, x );
+ glVertexAttribPointer (gr->position_location, 2, GL_FLOAT, 0, 0, x );
#else
- glVertexPointer(2, GL_F, 0, x);
+ glVertexPointer(2, GL_F, 0, x);
#endif
- glDrawArrays(mode, 0, count);
+ glDrawArrays(mode, 0, count);
#else
- glEnd();
+ glEnd();
#endif
}
static void
-draw_rectangle_do(struct graphics_priv *gr, struct point *p, int w, int h)
-{
- struct point pa[4];
- pa[0]=pa[1]=pa[2]=pa[3]=*p;
- pa[0].x+=w;
- pa[1].x+=w;
- pa[1].y+=h;
- pa[3].y+=h;
- draw_array(gr, pa, 4, GL_TRIANGLE_STRIP);
+draw_rectangle_do(struct graphics_priv *gr, struct point *p, int w, int h) {
+ struct point pa[4];
+ pa[0]=pa[1]=pa[2]=pa[3]=*p;
+ pa[0].x+=w;
+ pa[1].x+=w;
+ pa[1].y+=h;
+ pa[3].y+=h;
+ draw_array(gr, pa, 4, GL_TRIANGLE_STRIP);
}
#ifdef USE_OPENGLES
-static int next_power2(int x)
-{
- int r=1;
- while (r < x)
- r*=2;
- return r;
+static int next_power2(int x) {
+ int r=1;
+ while (r < x)
+ r*=2;
+ return r;
}
static void
-draw_image_es(struct graphics_priv *gr, struct point *p, int w, int h, unsigned char *data)
-{
- GLf x[8];
+draw_image_es(struct graphics_priv *gr, struct point *p, int w, int h, unsigned char *data) {
+ GLf x[8];
- memset(x, 0, sizeof(x));
+ memset(x, 0, sizeof(x));
#if REQUIRES_POWER_OF_2
- int w2=next_power2(w);
- int h2=next_power2(h);
- int y;
- if (w2 != w || h2 != h) {
- char *newpix=g_malloc0(w2*h2*4);
- for (y=0 ; y < h ; y++)
- memcpy(newpix+y*w2*4, data+y*w*4, w*4);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w2, h2, 0, GL_RGBA, GL_UNSIGNED_BYTE, newpix);
- g_free(newpix);
- w=w2;
- h=h2;
- } else
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+ int w2=next_power2(w);
+ int h2=next_power2(h);
+ int y;
+ if (w2 != w || h2 != h) {
+ char *newpix=g_malloc0(w2*h2*4);
+ for (y=0 ; y < h ; y++)
+ memcpy(newpix+y*w2*4, data+y*w*4, w*4);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w2, h2, 0, GL_RGBA, GL_UNSIGNED_BYTE, newpix);
+ g_free(newpix);
+ w=w2;
+ h=h2;
+ } else
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
#else
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
#endif
- x[0]+=glF(1);
- x[2]+=glF(1);
- x[3]+=glF(1);
- x[7]+=glF(1);
+ x[0]+=glF(1);
+ x[2]+=glF(1);
+ x[3]+=glF(1);
+ x[7]+=glF(1);
#ifdef USE_OPENGLES2
- glUniform1i(gr->use_texture_location, 1);
- glEnableVertexAttribArray(gr->texture_position_location);
- glVertexAttribPointer (gr->texture_position_location, 2, GL_FLOAT, 0, 0, x );
+ glUniform1i(gr->use_texture_location, 1);
+ glEnableVertexAttribArray(gr->texture_position_location);
+ glVertexAttribPointer (gr->texture_position_location, 2, GL_FLOAT, 0, 0, x );
#else
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glEnable(GL_TEXTURE_2D);
- glTexCoordPointer(2, GL_F, 0, x);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glEnable(GL_TEXTURE_2D);
+ glTexCoordPointer(2, GL_F, 0, x);
#endif
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- draw_rectangle_do(gr, p, w, h);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ draw_rectangle_do(gr, p, w, h);
#ifdef USE_OPENGLES2
- glUniform1i(gr->use_texture_location, 0);
- glDisableVertexAttribArray(gr->texture_position_location);
+ glUniform1i(gr->use_texture_location, 0);
+ glDisableVertexAttribArray(gr->texture_position_location);
#else
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glDisable(GL_TEXTURE_2D);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ glDisable(GL_TEXTURE_2D);
#endif
- glDisable(GL_BLEND);
+ glDisable(GL_BLEND);
}
#endif
static void
-get_overlay_pos(struct graphics_priv *gr, struct point *point_out)
-{
- if (gr->parent == NULL) {
- point_out->x = 0;
- point_out->y = 0;
- return;
- }
- point_out->x = gr->p.x;
- if (point_out->x < 0) {
- point_out->x += gr->parent->width;
- }
-
- point_out->y = gr->p.y;
- if (point_out->y < 0) {
- point_out->y += gr->parent->height;
- }
+get_overlay_pos(struct graphics_priv *gr, struct point *point_out) {
+ if (gr->parent == NULL) {
+ point_out->x = 0;
+ point_out->y = 0;
+ return;
+ }
+ point_out->x = gr->p.x;
+ if (point_out->x < 0) {
+ point_out->x += gr->parent->width;
+ }
+
+ point_out->y = gr->p.y;
+ if (point_out->y < 0) {
+ point_out->y += gr->parent->height;
+ }
}
static void
draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc,
- struct point *p, int count)
-{
- if ((gr->parent && !gr->parent->overlay_enabled)
- || (gr->parent && gr->parent->overlay_enabled
- && !gr->overlay_enabled)) {
- return;
- }
+ struct point *p, int count) {
+ if ((gr->parent && !gr->parent->overlay_enabled)
+ || (gr->parent && gr->parent->overlay_enabled
+ && !gr->overlay_enabled)) {
+ return;
+ }
#if !defined(USE_OPENGLES) || defined(USE_OPENGLES2)
- glLineWidth(gc->linewidth);
+ glLineWidth(gc->linewidth);
#endif
- set_color(gr, gc);
- graphics_priv_root->dirty = 1;
+ set_color(gr, gc);
+ graphics_priv_root->dirty = 1;
#ifndef USE_OPENGLES
- if (!gr->parent && 0 < gc->dash_count) {
- glLineStipple(1, gc->dash_mask);
- glEnable(GL_LINE_STIPPLE);
- }
+ if (!gr->parent && 0 < gc->dash_count) {
+ glLineStipple(1, gc->dash_mask);
+ glEnable(GL_LINE_STIPPLE);
+ }
#endif
- draw_array(gr, p, count, GL_LINE_STRIP);
+ draw_array(gr, p, count, GL_LINE_STRIP);
#ifndef USE_OPENGLES
- if (!gr->parent && 0 < gc->dash_count) {
- glDisable(GL_LINE_STIPPLE);
- }
+ if (!gr->parent && 0 < gc->dash_count) {
+ glDisable(GL_LINE_STIPPLE);
+ }
#endif
}
@@ -706,87 +692,82 @@ static struct point tess_array[512];
static GLenum tess_type;
const char *
-getPrimitiveType(GLenum type)
-{
- char *ret = "";
-
- switch (type) {
- case 0x0000:
- ret = "GL_POINTS";
- break;
- case 0x0001:
- ret = "GL_LINES";
- break;
- case 0x0002:
- ret = "GL_LINE_LOOP";
- break;
- case 0x0003:
- ret = "GL_LINE_STRIP";
- break;
- case 0x0004:
- ret = "GL_TRIANGLES";
- break;
- case 0x0005:
- ret = "GL_TRIANGLE_STRIP";
- break;
- case 0x0006:
- ret = "GL_TRIANGLE_FAN";
- break;
- case 0x0007:
- ret = "GL_QUADS";
- break;
- case 0x0008:
- ret = "GL_QUAD_STRIP";
- break;
- case 0x0009:
- ret = "GL_POLYGON";
- break;
- }
- return ret;
+getPrimitiveType(GLenum type) {
+ char *ret = "";
+
+ switch (type) {
+ case 0x0000:
+ ret = "GL_POINTS";
+ break;
+ case 0x0001:
+ ret = "GL_LINES";
+ break;
+ case 0x0002:
+ ret = "GL_LINE_LOOP";
+ break;
+ case 0x0003:
+ ret = "GL_LINE_STRIP";
+ break;
+ case 0x0004:
+ ret = "GL_TRIANGLES";
+ break;
+ case 0x0005:
+ ret = "GL_TRIANGLE_STRIP";
+ break;
+ case 0x0006:
+ ret = "GL_TRIANGLE_FAN";
+ break;
+ case 0x0007:
+ ret = "GL_QUADS";
+ break;
+ case 0x0008:
+ ret = "GL_QUAD_STRIP";
+ break;
+ case 0x0009:
+ ret = "GL_POLYGON";
+ break;
+ }
+ return ret;
}
void APIENTRY
-tessBeginCB(GLenum which)
-{
- dbg(lvl_debug, "glBegin( %s );", getPrimitiveType(which));
- tess_type=which;
- tess_count=0;
+tessBeginCB(GLenum which) {
+ dbg(lvl_debug, "glBegin( %s );", getPrimitiveType(which));
+ tess_type=which;
+ tess_count=0;
}
void APIENTRY
-tessEndCB(void)
-{
- dbg(lvl_debug, "glEnd();");
- draw_array(graphics_priv_root, tess_array, tess_count, tess_type);
+tessEndCB(void) {
+ dbg(lvl_debug, "glEnd();");
+ draw_array(graphics_priv_root, tess_array, tess_count, tess_type);
}
void APIENTRY
-tessVertexCB(const GLvoid * data)
-{
- // cast back to double type
- const GLdouble *ptr = (const GLdouble *) data;
- dbg(lvl_debug, " glVertex3d();");
-
- tess_array[tess_count].x=ptr[0];
- tess_array[tess_count].y=ptr[1];
- if (tess_count < 511)
- tess_count++;
- else
- dbg(lvl_error,"overflow");
+tessVertexCB(const GLvoid * data) {
+ // cast back to double type
+ const GLdouble *ptr = (const GLdouble *) data;
+ dbg(lvl_debug, " glVertex3d();");
+
+ tess_array[tess_count].x=ptr[0];
+ tess_array[tess_count].y=ptr[1];
+ if (tess_count < 511)
+ tess_count++;
+ else
+ dbg(lvl_error,"overflow");
}
void APIENTRY
-tessCombineCB(GLdouble c[3], void *d[4], GLfloat w[4], void **out)
-{
- GLdouble *nv = (GLdouble *) malloc(sizeof(GLdouble) * 3);
- nv[0] = c[0];
- nv[1] = c[1];
- nv[2] = c[2];
- *out = nv;
+tessCombineCB(GLdouble c[3], void *d[4], GLfloat w[4], void **out) {
+ GLdouble *nv = (GLdouble *) malloc(sizeof(GLdouble) * 3);
+ nv[0] = c[0];
+ nv[1] = c[1];
+ nv[2] = c[2];
+ *out = nv;
}
#endif
@@ -794,1029 +775,988 @@ tessCombineCB(GLdouble c[3], void *d[4], GLfloat w[4], void **out)
static void
draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc,
- struct point *p, int count)
-{
- if ((gr->parent && !gr->parent->overlay_enabled)
- || (gr->parent && gr->parent->overlay_enabled
- && !gr->overlay_enabled)) {
- return;
- }
- set_color(gr, gc);
- graphics_priv_root->dirty = 1;
+ struct point *p, int count) {
+ if ((gr->parent && !gr->parent->overlay_enabled)
+ || (gr->parent && gr->parent->overlay_enabled
+ && !gr->overlay_enabled)) {
+ return;
+ }
+ set_color(gr, gc);
+ graphics_priv_root->dirty = 1;
#if defined(USE_OPENGLES) && !defined(USE_GLUT_FOR_OPENGLES)
- draw_array(gr, p, count, GL_LINE_STRIP);
+ draw_array(gr, p, count, GL_LINE_STRIP);
#else
- GLUtesselator *tess = gluNewTess(); // create a tessellator
- if (!tess)
- return; // failed to create tessellation object, return 0
-
- GLdouble quad1[count][3];
- int i;
- for (i = 0; i < count; i++) {
- quad1[i][0] = (GLdouble) (p[i].x);
- quad1[i][1] = (GLdouble) (p[i].y);
- quad1[i][2] = 0;
- }
-
-
- // register callback functions
- gluTessCallback(tess, GLU_TESS_BEGIN, (void (APIENTRY *)(void)) tessBeginCB);
- gluTessCallback(tess, GLU_TESS_END, (void (APIENTRY *)(void)) tessEndCB);
- // gluTessCallback(tess, GLU_TESS_ERROR, (void (*)(void))tessErrorCB);
- gluTessCallback(tess, GLU_TESS_VERTEX, (void (APIENTRY *)(void)) tessVertexCB);
- gluTessCallback(tess, GLU_TESS_COMBINE, (void (APIENTRY *)(void)) tessCombineCB);
-
- // tessellate and compile a concave quad into display list
- // gluTessVertex() takes 3 params: tess object, pointer to vertex coords,
- // and pointer to vertex data to be passed to vertex callback.
- // The second param is used only to perform tessellation, and the third
- // param is the actual vertex data to draw. It is usually same as the second
- // param, but It can be more than vertex coord, for example, color, normal
- // and UV coords which are needed for actual drawing.
- // Here, we are looking at only vertex coods, so the 2nd and 3rd params are
- // pointing same address.
- gluTessBeginPolygon(tess, 0); // with NULL data
- gluTessBeginContour(tess);
- for (i = 0; i < count; i++) {
- gluTessVertex(tess, quad1[i], quad1[i]);
- }
- gluTessEndContour(tess);
- gluTessEndPolygon(tess);
-
- gluDeleteTess(tess); // delete after tessellation
+ GLUtesselator *tess = gluNewTess(); // create a tessellator
+ if (!tess)
+ return; // failed to create tessellation object, return 0
+
+ GLdouble quad1[count][3];
+ int i;
+ for (i = 0; i < count; i++) {
+ quad1[i][0] = (GLdouble) (p[i].x);
+ quad1[i][1] = (GLdouble) (p[i].y);
+ quad1[i][2] = 0;
+ }
+
+
+ // register callback functions
+ gluTessCallback(tess, GLU_TESS_BEGIN, (void (APIENTRY *)(void)) tessBeginCB);
+ gluTessCallback(tess, GLU_TESS_END, (void (APIENTRY *)(void)) tessEndCB);
+ // gluTessCallback(tess, GLU_TESS_ERROR, (void (*)(void))tessErrorCB);
+ gluTessCallback(tess, GLU_TESS_VERTEX, (void (APIENTRY *)(void)) tessVertexCB);
+ gluTessCallback(tess, GLU_TESS_COMBINE, (void (APIENTRY *)(void)) tessCombineCB);
+
+ // tessellate and compile a concave quad into display list
+ // gluTessVertex() takes 3 params: tess object, pointer to vertex coords,
+ // and pointer to vertex data to be passed to vertex callback.
+ // The second param is used only to perform tessellation, and the third
+ // param is the actual vertex data to draw. It is usually same as the second
+ // param, but It can be more than vertex coord, for example, color, normal
+ // and UV coords which are needed for actual drawing.
+ // Here, we are looking at only vertex coods, so the 2nd and 3rd params are
+ // pointing same address.
+ gluTessBeginPolygon(tess, 0); // with NULL data
+ gluTessBeginContour(tess);
+ for (i = 0; i < count; i++) {
+ gluTessVertex(tess, quad1[i], quad1[i]);
+ }
+ gluTessEndContour(tess);
+ gluTessEndPolygon(tess);
+
+ gluDeleteTess(tess); // delete after tessellation
#endif
}
static void
draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc,
- struct point *p, int w, int h)
-{
- if ((gr->parent && !gr->parent->overlay_enabled)
- || (gr->parent && gr->parent->overlay_enabled
- && !gr->overlay_enabled)) {
- return;
- }
- set_color(gr, gc);
- draw_rectangle_do(gr, p, w, h);
- graphics_priv_root->dirty = 1;
+ struct point *p, int w, int h) {
+ if ((gr->parent && !gr->parent->overlay_enabled)
+ || (gr->parent && gr->parent->overlay_enabled
+ && !gr->overlay_enabled)) {
+ return;
+ }
+ set_color(gr, gc);
+ draw_rectangle_do(gr, p, w, h);
+ graphics_priv_root->dirty = 1;
}
static void
display_text_draw(struct font_freetype_text *text,
- struct graphics_priv *gr, struct graphics_gc_priv *fg,
- struct graphics_gc_priv *bg, int color, struct point *p)
-{
- int i, x, y, stride;
- struct font_freetype_glyph *g, **gp;
- unsigned char *shadow, *glyph;
- struct color transparent = { 0x0000, 0x0000, 0x0000, 0x0000 };
- struct color black =
- { fg->fr * 65535, fg->fg * 65535, fg->fb * 65535,
- fg->fa * 65535 };
- struct color white = { 0xffff, 0xffff, 0xffff, 0xffff };
-
- if (bg) {
- if (COLOR_IS_WHITE(black) && COLOR_IS_BLACK(white)) {
- black.r = 65535;
- black.g = 65535;
- black.b = 65535;
- black.a = 65535;
-
- white.r = 0;
- white.g = 0;
- white.b = 0;
- white.a = 65535;
- } else if (COLOR_IS_BLACK(black) && COLOR_IS_WHITE(white)) {
- white.r = 65535;
- white.g = 65535;
- white.b = 65535;
- white.a = 65535;
-
- black.r = 0;
- black.g = 0;
- black.b = 0;
- black.a = 65535;
- } else {
- white.r = bg->fr;
- white.g = bg->fg;
- white.b = bg->fb;
- white.a = bg->fa;
- }
- } else {
- white.r = 0;
- white.g = 0;
- white.b = 0;
- white.a = 0;
- }
-
- gp = text->glyph;
- i = text->glyph_count;
- x = p->x << 6;
- y = p->y << 6;
- while (i-- > 0) {
- g = *gp++;
- if (g->w && g->h && bg) {
- stride = (g->w + 2) * 4;
- if (color) {
- shadow = g_malloc(stride * (g->h + 2));
- gr->freetype_methods.get_shadow(g, shadow,
- stride,
- &white,
- &transparent);
+ struct graphics_priv *gr, struct graphics_gc_priv *fg,
+ struct graphics_gc_priv *bg, int color, struct point *p) {
+ int i, x, y, stride;
+ struct font_freetype_glyph *g, **gp;
+ unsigned char *shadow, *glyph;
+ struct color transparent = { 0x0000, 0x0000, 0x0000, 0x0000 };
+ struct color black = {
+ fg->fr * 65535, fg->fg * 65535, fg->fb * 65535,
+ fg->fa * 65535
+ };
+ struct color white = { 0xffff, 0xffff, 0xffff, 0xffff };
+
+ if (bg) {
+ if (COLOR_IS_WHITE(black) && COLOR_IS_BLACK(white)) {
+ black.r = 65535;
+ black.g = 65535;
+ black.b = 65535;
+ black.a = 65535;
+
+ white.r = 0;
+ white.g = 0;
+ white.b = 0;
+ white.a = 65535;
+ } else if (COLOR_IS_BLACK(black) && COLOR_IS_WHITE(white)) {
+ white.r = 65535;
+ white.g = 65535;
+ white.b = 65535;
+ white.a = 65535;
+
+ black.r = 0;
+ black.g = 0;
+ black.b = 0;
+ black.a = 65535;
+ } else {
+ white.r = bg->fr;
+ white.g = bg->fg;
+ white.b = bg->fb;
+ white.a = bg->fa;
+ }
+ } else {
+ white.r = 0;
+ white.g = 0;
+ white.b = 0;
+ white.a = 0;
+ }
+
+ gp = text->glyph;
+ i = text->glyph_count;
+ x = p->x << 6;
+ y = p->y << 6;
+ while (i-- > 0) {
+ g = *gp++;
+ if (g->w && g->h && bg) {
+ stride = (g->w + 2) * 4;
+ if (color) {
+ shadow = g_malloc(stride * (g->h + 2));
+ gr->freetype_methods.get_shadow(g, shadow,
+ stride,
+ &white,
+ &transparent);
#ifdef USE_OPENGLES
- struct point p;
- p.x=((x + g->x) >> 6)-1;
- p.y=((y + g->y) >> 6)-1;
- draw_image_es(gr, &p, g->w+2, g->h+2, shadow);
+ struct point p;
+ p.x=((x + g->x) >> 6)-1;
+ p.y=((y + g->y) >> 6)-1;
+ draw_image_es(gr, &p, g->w+2, g->h+2, shadow);
#else
#ifdef MIRRORED_VIEW
- glPixelZoom(-1.0, -1.0); //mirrored mode
+ glPixelZoom(-1.0, -1.0); //mirrored mode
#else
- glPixelZoom(1.0, -1.0);
+ glPixelZoom(1.0, -1.0);
#endif
- glRasterPos2d((x + g->x) >> 6,
- (y + g->y) >> 6);
- glDrawPixels(g->w + 2, g->h + 2, PIXEL_FORMAT,
- GL_UNSIGNED_BYTE, shadow);
+ glRasterPos2d((x + g->x) >> 6,
+ (y + g->y) >> 6);
+ glDrawPixels(g->w + 2, g->h + 2, PIXEL_FORMAT,
+ GL_UNSIGNED_BYTE, shadow);
#endif
- g_free(shadow);
- }
- }
- x += g->dx;
- y += g->dy;
- }
-
- x = p->x << 6;
- y = p->y << 6;
- gp = text->glyph;
- i = text->glyph_count;
- while (i-- > 0) {
- g = *gp++;
- if (g->w && g->h) {
- if (color) {
- stride = g->w;
- if (bg) {
- glyph =
- g_malloc(stride * g->h * 4);
- gr->freetype_methods.get_glyph(g,
- glyph,
- stride
- * 4,
- &black,
- &white,
- &transparent);
+ g_free(shadow);
+ }
+ }
+ x += g->dx;
+ y += g->dy;
+ }
+
+ x = p->x << 6;
+ y = p->y << 6;
+ gp = text->glyph;
+ i = text->glyph_count;
+ while (i-- > 0) {
+ g = *gp++;
+ if (g->w && g->h) {
+ if (color) {
+ stride = g->w;
+ if (bg) {
+ glyph =
+ g_malloc(stride * g->h * 4);
+ gr->freetype_methods.get_glyph(g,
+ glyph,
+ stride
+ * 4,
+ &black,
+ &white,
+ &transparent);
#ifdef USE_OPENGLES
- struct point p;
- p.x=(x + g->x) >> 6;
- p.y=(y + g->y) >> 6;
- draw_image_es(gr, &p, g->w, g->h, glyph);
+ struct point p;
+ p.x=(x + g->x) >> 6;
+ p.y=(y + g->y) >> 6;
+ draw_image_es(gr, &p, g->w, g->h, glyph);
#else
#ifdef MIRRORED_VIEW
- glPixelZoom(-1.0, -1.0); //mirrored mode
+ glPixelZoom(-1.0, -1.0); //mirrored mode
#else
- glPixelZoom(1.0, -1.0);
+ glPixelZoom(1.0, -1.0);
#endif
- glRasterPos2d((x + g->x) >> 6,
- (y + g->y) >> 6);
- glDrawPixels(g->w, g->h, PIXEL_FORMAT,
- GL_UNSIGNED_BYTE,
- glyph);
+ glRasterPos2d((x + g->x) >> 6,
+ (y + g->y) >> 6);
+ glDrawPixels(g->w, g->h, PIXEL_FORMAT,
+ GL_UNSIGNED_BYTE,
+ glyph);
#endif
- g_free(glyph);
- }
- stride *= 4;
- glyph = g_malloc(stride * g->h);
- gr->freetype_methods.get_glyph(g, glyph,
- stride,
- &black,
- &white,
- &transparent);
+ g_free(glyph);
+ }
+ stride *= 4;
+ glyph = g_malloc(stride * g->h);
+ gr->freetype_methods.get_glyph(g, glyph,
+ stride,
+ &black,
+ &white,
+ &transparent);
#ifdef USE_OPENGLES
- struct point p;
- p.x=(x + g->x) >> 6;
- p.y=(y + g->y) >> 6;
- draw_image_es(gr, &p, g->w, g->h, glyph);
+ struct point p;
+ p.x=(x + g->x) >> 6;
+ p.y=(y + g->y) >> 6;
+ draw_image_es(gr, &p, g->w, g->h, glyph);
#else
#ifdef MIRRORED_VIEW
- glPixelZoom(-1.0, -1.0); //mirrored mode
+ glPixelZoom(-1.0, -1.0); //mirrored mode
#else
- glPixelZoom(1.0, -1.0);
+ glPixelZoom(1.0, -1.0);
#endif
- glRasterPos2d((x + g->x) >> 6,
- (y + g->y) >> 6);
- glDrawPixels(g->w, g->h, PIXEL_FORMAT,
- GL_UNSIGNED_BYTE, glyph);
+ glRasterPos2d((x + g->x) >> 6,
+ (y + g->y) >> 6);
+ glDrawPixels(g->w, g->h, PIXEL_FORMAT,
+ GL_UNSIGNED_BYTE, glyph);
#endif
- g_free(glyph);
- }
- }
- x += g->dx;
- y += g->dy;
- }
+ g_free(glyph);
+ }
+ }
+ x += g->dx;
+ y += g->dy;
+ }
}
static void
draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg,
- struct graphics_gc_priv *bg, struct graphics_font_priv *font,
- char *text, struct point *p, int dx, int dy)
-{
- if ((gr->parent && !gr->parent->overlay_enabled)
- || (gr->parent && gr->parent->overlay_enabled
- && !gr->overlay_enabled)) {
- return;
- }
-
- struct font_freetype_text *t;
- int color = 1;
-
- if (!font) {
- dbg(lvl_error, "no font, returning");
- return;
- }
-
- graphics_priv_root->dirty = 1;
-
- t = gr->freetype_methods.text_new(text,
- (struct font_freetype_font *)
- font, dx, dy);
-
- struct point p_eff;
- p_eff.x = p->x;
- p_eff.y = p->y;
-
- display_text_draw(t, gr, fg, bg, color, &p_eff);
- gr->freetype_methods.text_destroy(t);
+ struct graphics_gc_priv *bg, struct graphics_font_priv *font,
+ char *text, struct point *p, int dx, int dy) {
+ if ((gr->parent && !gr->parent->overlay_enabled)
+ || (gr->parent && gr->parent->overlay_enabled
+ && !gr->overlay_enabled)) {
+ return;
+ }
+
+ struct font_freetype_text *t;
+ int color = 1;
+
+ if (!font) {
+ dbg(lvl_error, "no font, returning");
+ return;
+ }
+
+ graphics_priv_root->dirty = 1;
+
+ t = gr->freetype_methods.text_new(text,
+ (struct font_freetype_font *)
+ font, dx, dy);
+
+ struct point p_eff;
+ p_eff.x = p->x;
+ p_eff.y = p->y;
+
+ display_text_draw(t, gr, fg, bg, color, &p_eff);
+ gr->freetype_methods.text_destroy(t);
}
static void
draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg,
- struct point *p, struct graphics_image_priv *img)
-{
+ struct point *p, struct graphics_image_priv *img) {
#ifdef USE_OPENGLES
- draw_image_es(gr, p, img->w, img->h, img->data);
+ draw_image_es(gr, p, img->w, img->h, img->data);
#else
- if ((gr->parent && !gr->parent->overlay_enabled)
- || (gr->parent && gr->parent->overlay_enabled
- && !gr->overlay_enabled)) {
- return;
- }
+ if ((gr->parent && !gr->parent->overlay_enabled)
+ || (gr->parent && gr->parent->overlay_enabled
+ && !gr->overlay_enabled)) {
+ return;
+ }
- if (!img || !img->data) {
- return;
- }
+ if (!img || !img->data) {
+ return;
+ }
- graphics_priv_root->dirty = 1;
+ graphics_priv_root->dirty = 1;
- struct point p_eff;
- p_eff.x = p->x + img->hot_x;
- p_eff.y = p->y + img->hot_y;
+ struct point p_eff;
+ p_eff.x = p->x + img->hot_x;
+ p_eff.y = p->y + img->hot_y;
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glRasterPos2d(p_eff.x - img->hot_x, p_eff.y - img->hot_y);
- glDrawPixels(img->w, img->h, GL_RGBA, GL_UNSIGNED_BYTE, img->data);
+ glRasterPos2d(p_eff.x - img->hot_x, p_eff.y - img->hot_y);
+ glDrawPixels(img->w, img->h, GL_RGBA, GL_UNSIGNED_BYTE, img->data);
#endif
}
static void
-draw_drag(struct graphics_priv *gr, struct point *p)
-{
+draw_drag(struct graphics_priv *gr, struct point *p) {
- if (p) {
- gr->p.x = p->x;
- gr->p.y = p->y;
- }
+ if (p) {
+ gr->p.x = p->x;
+ gr->p.y = p->y;
+ }
}
static void
-background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
- gr->background_gc = gc;
+background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
+ gr->background_gc = gc;
}
static void
-handle_mouse_queue(void)
-{
+handle_mouse_queue(void) {
#ifdef USE_OPENGLES
#else
- static int locked = 0;
- if (!locked) {
- locked = 1;
- } else {
- return;
- }
-
- if (mouse_event_queue_begin_idx < mouse_event_queue_end_idx) {
- if (mouse_queue[mouse_event_queue_begin_idx].button ==
- GLUT_LEFT_BUTTON
- && mouse_queue[mouse_event_queue_begin_idx].state ==
- GLUT_UP) {
- struct point p;
- p.x =
- mouse_queue[mouse_event_queue_begin_idx %
- mouse_event_queue_size].x;
- p.y =
- mouse_queue[mouse_event_queue_begin_idx %
- mouse_event_queue_size].y;
- graphics_priv_root->force_redraw = 1;
- callback_list_call_attr_3(graphics_priv_root->cbl,
- attr_button, (void *) 0,
- 1, (void *) &p);
- } else if (mouse_queue[mouse_event_queue_begin_idx].
- button == GLUT_LEFT_BUTTON
- && mouse_queue[mouse_event_queue_begin_idx].
- state == GLUT_DOWN) {
- struct point p;
- p.x =
- mouse_queue[mouse_event_queue_begin_idx %
- mouse_event_queue_size].x;
- p.y =
- mouse_queue[mouse_event_queue_begin_idx %
- mouse_event_queue_size].y;
- graphics_priv_root->force_redraw = 1;
- callback_list_call_attr_3(graphics_priv_root->cbl,
- attr_button, (void *) 1,
- 1, (void *) &p);
- }
- ++mouse_event_queue_begin_idx;
- }
- locked = 0;
+ static int locked = 0;
+ if (!locked) {
+ locked = 1;
+ } else {
+ return;
+ }
+
+ if (mouse_event_queue_begin_idx < mouse_event_queue_end_idx) {
+ if (mouse_queue[mouse_event_queue_begin_idx].button ==
+ GLUT_LEFT_BUTTON
+ && mouse_queue[mouse_event_queue_begin_idx].state ==
+ GLUT_UP) {
+ struct point p;
+ p.x =
+ mouse_queue[mouse_event_queue_begin_idx %
+ mouse_event_queue_size].x;
+ p.y =
+ mouse_queue[mouse_event_queue_begin_idx %
+ mouse_event_queue_size].y;
+ graphics_priv_root->force_redraw = 1;
+ callback_list_call_attr_3(graphics_priv_root->cbl,
+ attr_button, (void *) 0,
+ 1, (void *) &p);
+ } else if (mouse_queue[mouse_event_queue_begin_idx].
+ button == GLUT_LEFT_BUTTON
+ && mouse_queue[mouse_event_queue_begin_idx].
+ state == GLUT_DOWN) {
+ struct point p;
+ p.x =
+ mouse_queue[mouse_event_queue_begin_idx %
+ mouse_event_queue_size].x;
+ p.y =
+ mouse_queue[mouse_event_queue_begin_idx %
+ mouse_event_queue_size].y;
+ graphics_priv_root->force_redraw = 1;
+ callback_list_call_attr_3(graphics_priv_root->cbl,
+ attr_button, (void *) 1,
+ 1, (void *) &p);
+ }
+ ++mouse_event_queue_begin_idx;
+ }
+ locked = 0;
#endif
}
/*draws root graphics and its overlays*/
static int
-redraw_screen(struct graphics_priv *gr)
-{
+redraw_screen(struct graphics_priv *gr) {
#ifdef USE_OPENGLES
#else
- graphics_priv_root->dirty = 0;
-
- glCallList(gr->DLid);
- //display overlays display list
- struct graphics_priv *overlay;
- overlay = gr->overlays;
- while (gr->overlay_enabled && overlay) {
- if (overlay->overlay_enabled) {
- glPushMatrix();
- struct point p_eff;
- get_overlay_pos(overlay, &p_eff);
- glTranslatef(p_eff.x, p_eff.y, 1);
- glCallList(overlay->DLid);
- glPopMatrix();
- }
- overlay = overlay->next;
- }
- glutSwapBuffers();
+ graphics_priv_root->dirty = 0;
+
+ glCallList(gr->DLid);
+ //display overlays display list
+ struct graphics_priv *overlay;
+ overlay = gr->overlays;
+ while (gr->overlay_enabled && overlay) {
+ if (overlay->overlay_enabled) {
+ glPushMatrix();
+ struct point p_eff;
+ get_overlay_pos(overlay, &p_eff);
+ glTranslatef(p_eff.x, p_eff.y, 1);
+ glCallList(overlay->DLid);
+ glPopMatrix();
+ }
+ overlay = overlay->next;
+ }
+ glutSwapBuffers();
#endif
- return TRUE;
+ return TRUE;
}
#ifndef USE_OPENGLES
/*filters call to redraw in overlay enabled(map) mode*/
static gboolean
-redraw_filter(gpointer data)
-{
- struct graphics_priv *gr = (struct graphics_priv*) data;
- if (gr->overlay_enabled && gr->dirty) {
- redraw_screen(gr);
- }
- return 0;
+redraw_filter(gpointer data) {
+ struct graphics_priv *gr = (struct graphics_priv*) data;
+ if (gr->overlay_enabled && gr->dirty) {
+ redraw_screen(gr);
+ }
+ return 0;
}
#endif
static void
-draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
-{
- if (gr->parent) { //overlay
+draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
+ if (gr->parent) { //overlay
#ifdef USE_OPENGLES
#else
- if (mode == draw_mode_begin) {
- glNewList(gr->DLid, GL_COMPILE);
- }
+ if (mode == draw_mode_begin) {
+ glNewList(gr->DLid, GL_COMPILE);
+ }
- if (mode == draw_mode_end) {
- glEndList();
- }
+ if (mode == draw_mode_end) {
+ glEndList();
+ }
#endif
- } else { //root graphics
- if (mode == draw_mode_begin) {
+ } else { //root graphics
+ if (mode == draw_mode_begin) {
#ifdef USE_OPENGLES
#else
- glNewList(gr->DLid, GL_COMPILE);
+ glNewList(gr->DLid, GL_COMPILE);
#endif
- }
+ }
- if (mode == draw_mode_end) {
+ if (mode == draw_mode_end) {
#ifdef USE_OPENGLES
- gr->platform_methods->swap_buffers(gr->platform);
+ gr->platform_methods->swap_buffers(gr->platform);
#else
- glEndList();
- gr->force_redraw = 1;
- if (!gr->overlay_enabled || gr->force_redraw) {
- redraw_screen(gr);
- }
+ glEndList();
+ gr->force_redraw = 1;
+ if (!gr->overlay_enabled || gr->force_redraw) {
+ redraw_screen(gr);
+ }
#endif
- }
- }
- gr->mode = mode;
+ }
+ }
+ gr->mode = mode;
}
static struct graphics_priv *overlay_new(struct graphics_priv *gr,
- struct graphics_methods *meth,
- struct point *p, int w, int h,
- int wraparound);
+ struct graphics_methods *meth,
+ struct point *p, int w, int h,
+ int wraparound);
static int
-graphics_opengl_fullscreen(struct window *w, int on)
-{
- return 1;
+graphics_opengl_fullscreen(struct window *w, int on) {
+ return 1;
}
static void
-graphics_opengl_disable_suspend(struct window *w)
-{
+graphics_opengl_disable_suspend(struct window *w) {
}
#ifdef USE_OPENGLES2
static GLuint
-load_shader(const char *shader_source, GLenum type)
-{
- GLuint shader = glCreateShader(type);
+load_shader(const char *shader_source, GLenum type) {
+ GLuint shader = glCreateShader(type);
- glShaderSource(shader, 1, &shader_source, NULL);
- glCompileShader(shader);
+ glShaderSource(shader, 1, &shader_source, NULL);
+ glCompileShader(shader);
- return shader;
+ return shader;
}
#endif
static void *
-get_data(struct graphics_priv *this, const char *type)
-{
- /*TODO initialize gtkglext context when type=="gtk_widget" */
- if (!strcmp(type, "gtk_widget")) {
- fprintf(stderr,
- "Currently GTK gui is not yet supported with opengl graphics driver\n");
- return NULL;
- }
- if (strcmp(type, "window") == 0) {
- struct window *win;
+get_data(struct graphics_priv *this, const char *type) {
+ /*TODO initialize gtkglext context when type=="gtk_widget" */
+ if (!strcmp(type, "gtk_widget")) {
+ fprintf(stderr,
+ "Currently GTK gui is not yet supported with opengl graphics driver\n");
+ return NULL;
+ }
+ if (strcmp(type, "window") == 0) {
+ struct window *win;
#ifdef USE_OPENGLES
- GLuint vertexShader;
- GLuint fragmentShader;
- GLuint textures;
- GLfloat matrix[16];
- int i;
-
- this->window_system=graphics_opengl_x11_new(NULL, this->width, this->height, 32, &this->window_system_methods);
- this->platform=graphics_opengl_egl_new(this->window_system_methods->get_display(this->window_system),
- this->window_system_methods->get_window(this->window_system),
- &this->platform_methods);
- this->window_system_methods->set_callbacks(this->window_system, this, resize_callback_do, click_notify_do, motion_notify_do, NULL);
- resize_callback(this->width,this->height);
+ GLuint vertexShader;
+ GLuint fragmentShader;
+ GLuint textures;
+ GLfloat matrix[16];
+ int i;
+
+ this->window_system=graphics_opengl_x11_new(NULL, this->width, this->height, 32, &this->window_system_methods);
+ this->platform=graphics_opengl_egl_new(this->window_system_methods->get_display(this->window_system),
+ this->window_system_methods->get_window(this->window_system),
+ &this->platform_methods);
+ this->window_system_methods->set_callbacks(this->window_system, this, resize_callback_do, click_notify_do,
+ motion_notify_do, NULL);
+ resize_callback(this->width,this->height);
#if 0
- glClearColor ( 0.4 , 0.4 , 0.4 , 1);
+ glClearColor ( 0.4, 0.4, 0.4, 1);
#endif
- glClear ( GL_COLOR_BUFFER_BIT );
+ glClear ( GL_COLOR_BUFFER_BIT );
#ifdef USE_OPENGLES2
- this->program=glCreateProgram();
- vertexShader = load_shader(vertex_src, GL_VERTEX_SHADER);
- fragmentShader = load_shader(fragment_src, GL_FRAGMENT_SHADER);
- glAttachShader(this->program, vertexShader);
- glAttachShader(this->program, fragmentShader);
- glLinkProgram(this->program);
- glUseProgram(this->program);
- this->mvp_location=glGetUniformLocation(this->program, "mvp");
- this->position_location=glGetAttribLocation(this->program, "position");
- glEnableVertexAttribArray(this->position_location);
- this->texture_position_location=glGetAttribLocation(this->program, "texture_position");
- this->color_location=glGetUniformLocation(this->program, "avcolor");
- this->texture_location=glGetUniformLocation(this->program, "texture");
- this->use_texture_location=glGetUniformLocation(this->program, "use_texture");
- glUniform1i(this->use_texture_location, 0);
- glUniform1i(this->texture_location, 0);
-
- for (i = 0 ; i < 16 ; i++)
- matrix[i]=0.0;
- matrix[0]=2.0/this->width;
- matrix[5]=-2.0/this->height;
- matrix[10]=1;
- matrix[12]=-1;
- matrix[13]=1;
- matrix[15]=1;
- glUniformMatrix4fv(this->mvp_location, 1, GL_FALSE, matrix);
+ this->program=glCreateProgram();
+ vertexShader = load_shader(vertex_src, GL_VERTEX_SHADER);
+ fragmentShader = load_shader(fragment_src, GL_FRAGMENT_SHADER);
+ glAttachShader(this->program, vertexShader);
+ glAttachShader(this->program, fragmentShader);
+ glLinkProgram(this->program);
+ glUseProgram(this->program);
+ this->mvp_location=glGetUniformLocation(this->program, "mvp");
+ this->position_location=glGetAttribLocation(this->program, "position");
+ glEnableVertexAttribArray(this->position_location);
+ this->texture_position_location=glGetAttribLocation(this->program, "texture_position");
+ this->color_location=glGetUniformLocation(this->program, "avcolor");
+ this->texture_location=glGetUniformLocation(this->program, "texture");
+ this->use_texture_location=glGetUniformLocation(this->program, "use_texture");
+ glUniform1i(this->use_texture_location, 0);
+ glUniform1i(this->texture_location, 0);
+
+ for (i = 0 ; i < 16 ; i++)
+ matrix[i]=0.0;
+ matrix[0]=2.0/this->width;
+ matrix[5]=-2.0/this->height;
+ matrix[10]=1;
+ matrix[12]=-1;
+ matrix[13]=1;
+ matrix[15]=1;
+ glUniformMatrix4fv(this->mvp_location, 1, GL_FALSE, matrix);
#else
- glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_VERTEX_ARRAY);
#endif
- glGenTextures(1, &textures);
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, textures);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glGenTextures(1, &textures);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, textures);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
#ifndef USE_OPENGLES2
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
#endif
#endif
- win = g_new0(struct window, 1);
- win->priv = this;
- win->fullscreen = graphics_opengl_fullscreen;
- win->disable_suspend = graphics_opengl_disable_suspend;
- return win;
- } else {
+ win = g_new0(struct window, 1);
+ win->priv = this;
+ win->fullscreen = graphics_opengl_fullscreen;
+ win->disable_suspend = graphics_opengl_disable_suspend;
+ return win;
+ } else {
#ifdef USE_OPENGLES
- return NULL;
+ return NULL;
#else
- return &this->DLid;
+ return &this->DLid;
#endif
- }
+ }
}
static void
-image_free(struct graphics_priv *gr, struct graphics_image_priv *priv)
-{
+image_free(struct graphics_priv *gr, struct graphics_image_priv *priv) {
//TODO free image data in hashtable when graphics is destroyed
//currently graphics destroy is not called !!!
-/*
- g_free(priv->data);
- priv->data = NULL;
- g_free(priv);
- priv = NULL;
-*/
+ /*
+ g_free(priv->data);
+ priv->data = NULL;
+ g_free(priv);
+ priv = NULL;
+ */
}
static void
-overlay_disable(struct graphics_priv *gr, int disable)
-{
- gr->overlay_enabled = !disable;
- gr->force_redraw = 1;
- draw_mode(gr, draw_mode_end);
+overlay_disable(struct graphics_priv *gr, int disable) {
+ gr->overlay_enabled = !disable;
+ gr->force_redraw = 1;
+ draw_mode(gr, draw_mode_end);
}
static void
overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h,
- int wraparound)
-{
- int changed = 0;
- int w2, h2;
-
- if (w == 0) {
- w2 = 1;
- } else {
- w2 = w;
- }
-
- if (h == 0) {
- h2 = 1;
- } else {
- h2 = h;
- }
-
- gr->p = *p;
- if (gr->width != w2) {
- gr->width = w2;
- changed = 1;
- }
-
- if (gr->height != h2) {
- gr->height = h2;
- changed = 1;
- }
-
- gr->wraparound = wraparound;
-
- if (changed) {
- if ((w == 0) || (h == 0)) {
- gr->overlay_autodisabled = 1;
- } else {
- gr->overlay_autodisabled = 0;
- }
-
- callback_list_call_attr_2(gr->cbl, attr_resize,
- GINT_TO_POINTER(gr->width),
- GINT_TO_POINTER(gr->height));
- }
+ int wraparound) {
+ int changed = 0;
+ int w2, h2;
+
+ if (w == 0) {
+ w2 = 1;
+ } else {
+ w2 = w;
+ }
+
+ if (h == 0) {
+ h2 = 1;
+ } else {
+ h2 = h;
+ }
+
+ gr->p = *p;
+ if (gr->width != w2) {
+ gr->width = w2;
+ changed = 1;
+ }
+
+ if (gr->height != h2) {
+ gr->height = h2;
+ changed = 1;
+ }
+
+ gr->wraparound = wraparound;
+
+ if (changed) {
+ if ((w == 0) || (h == 0)) {
+ gr->overlay_autodisabled = 1;
+ } else {
+ gr->overlay_autodisabled = 0;
+ }
+
+ callback_list_call_attr_2(gr->cbl, attr_resize,
+ GINT_TO_POINTER(gr->width),
+ GINT_TO_POINTER(gr->height));
+ }
}
static struct graphics_methods graphics_methods = {
- graphics_destroy,
- draw_mode,
- draw_lines,
- draw_polygon,
- draw_rectangle,
- NULL,
- draw_text,
- draw_image,
- NULL,
- draw_drag,
- NULL,
- gc_new,
- background_gc,
- overlay_new,
- image_new,
- get_data,
- image_free,
- NULL,
- overlay_disable,
- overlay_resize,
- NULL, /* show_native_keyboard */
- NULL, /* hide_native_keyboard */
+ graphics_destroy,
+ draw_mode,
+ draw_lines,
+ draw_polygon,
+ draw_rectangle,
+ NULL,
+ draw_text,
+ draw_image,
+ NULL,
+ draw_drag,
+ NULL,
+ gc_new,
+ background_gc,
+ overlay_new,
+ image_new,
+ get_data,
+ image_free,
+ NULL,
+ overlay_disable,
+ overlay_resize,
+ NULL, /* show_native_keyboard */
+ NULL, /* hide_native_keyboard */
};
static struct graphics_priv *
-graphics_opengl_new_helper(struct graphics_methods *meth)
-{
- struct font_priv *(*font_freetype_new) (void *meth);
- font_freetype_new = plugin_get_category_font("freetype");
-
- if (!font_freetype_new) {
- return NULL;
- }
-
- struct graphics_priv *this = g_new0(struct graphics_priv, 1);
-
- font_freetype_new(&this->freetype_methods);
- *meth = graphics_methods;
-
- meth->font_new =
- (struct graphics_font_priv *
- (*)(struct graphics_priv *, struct graphics_font_methods *,
- char *, int, int)) this->freetype_methods.font_new;
- meth->get_text_bbox =
- (void (*) (struct graphics_priv *, struct graphics_font_priv *,
- char *, int, int, struct point*, int)) this->freetype_methods.get_text_bbox;
- return this;
+graphics_opengl_new_helper(struct graphics_methods *meth) {
+ struct font_priv *(*font_freetype_new) (void *meth);
+ font_freetype_new = plugin_get_category_font("freetype");
+
+ if (!font_freetype_new) {
+ return NULL;
+ }
+
+ struct graphics_priv *this = g_new0(struct graphics_priv, 1);
+
+ font_freetype_new(&this->freetype_methods);
+ *meth = graphics_methods;
+
+ meth->font_new =
+ (struct graphics_font_priv *
+ (*)(struct graphics_priv *, struct graphics_font_methods *,
+ char *, int, int)) this->freetype_methods.font_new;
+ meth->get_text_bbox =
+ (void (*) (struct graphics_priv *, struct graphics_font_priv *,
+ char *, int, int, struct point*, int)) this->freetype_methods.get_text_bbox;
+ return this;
}
static struct graphics_priv *
overlay_new(struct graphics_priv *gr, struct graphics_methods *meth,
- struct point *p, int w, int h, int wraparound)
-{
- struct graphics_priv *this = graphics_opengl_new_helper(meth);
- this->p = *p;
- this->width = w;
- this->height = h;
- this->parent = gr;
-
- if ((w == 0) || (h == 0)) {
- this->overlay_autodisabled = 1;
- } else {
- this->overlay_autodisabled = 0;
- }
- this->overlay_enabled = 1;
- this->overlay_autodisabled = 0;
-
- this->next = gr->overlays;
- gr->overlays = this;
+ struct point *p, int w, int h, int wraparound) {
+ struct graphics_priv *this = graphics_opengl_new_helper(meth);
+ this->p = *p;
+ this->width = w;
+ this->height = h;
+ this->parent = gr;
+
+ if ((w == 0) || (h == 0)) {
+ this->overlay_autodisabled = 1;
+ } else {
+ this->overlay_autodisabled = 0;
+ }
+ this->overlay_enabled = 1;
+ this->overlay_autodisabled = 0;
+
+ this->next = gr->overlays;
+ gr->overlays = this;
#ifdef USE_OPENGLES
#else
- this->DLid = glGenLists(1);
+ this->DLid = glGenLists(1);
#endif
- return this;
+ return this;
}
#ifdef USE_OPENGLES
static void
-click_notify_do(struct graphics_priv *priv, int button, int state, int x, int y)
-{
- struct point p={x,y};
- dbg(lvl_debug,"enter state %d button %d",state,button);
- callback_list_call_attr_3(priv->cbl, attr_button, (void *) state, (void *)button, (void *) &p);
+click_notify_do(struct graphics_priv *priv, int button, int state, int x, int y) {
+ struct point p= {x,y};
+ dbg(lvl_debug,"enter state %d button %d",state,button);
+ callback_list_call_attr_3(priv->cbl, attr_button, (void *) state, (void *)button, (void *) &p);
}
#endif
static void
-click_notify(int button, int state, int x, int y)
-{
- mouse_queue[mouse_event_queue_end_idx %
- mouse_event_queue_size].button = button;
- mouse_queue[mouse_event_queue_end_idx %
- mouse_event_queue_size].state = state;
+click_notify(int button, int state, int x, int y) {
+ mouse_queue[mouse_event_queue_end_idx %
+ mouse_event_queue_size].button = button;
+ mouse_queue[mouse_event_queue_end_idx %
+ mouse_event_queue_size].state = state;
#ifdef MIRRORED_VIEW
- mouse_queue[mouse_event_queue_end_idx % mouse_event_queue_size].x =
- graphics_priv_root->width - x;
+ mouse_queue[mouse_event_queue_end_idx % mouse_event_queue_size].x =
+ graphics_priv_root->width - x;
#else
- mouse_queue[mouse_event_queue_end_idx % mouse_event_queue_size].x =
- x;
+ mouse_queue[mouse_event_queue_end_idx % mouse_event_queue_size].x =
+ x;
#endif
- mouse_queue[mouse_event_queue_end_idx % mouse_event_queue_size].y =
- y;
- ++mouse_event_queue_end_idx;
+ mouse_queue[mouse_event_queue_end_idx % mouse_event_queue_size].y =
+ y;
+ ++mouse_event_queue_end_idx;
}
static void
-motion_notify_do(struct graphics_priv *priv, int x, int y)
-{
- struct point p;
+motion_notify_do(struct graphics_priv *priv, int x, int y) {
+ struct point p;
#ifdef MIRRORED_VIEW
- p.x = priv->width - x;
+ p.x = priv->width - x;
#else
- p.x = x;
+ p.x = x;
#endif
- p.y = y;
- callback_list_call_attr_1(priv->cbl, attr_motion,
- (void *) &p);
- return;
+ p.y = y;
+ callback_list_call_attr_1(priv->cbl, attr_motion,
+ (void *) &p);
+ return;
}
static void
-motion_notify(int x, int y)
-{
- motion_notify_do(graphics_priv_root, x, y);
+motion_notify(int x, int y) {
+ motion_notify_do(graphics_priv_root, x, y);
}
#ifndef USE_OPENGLES
static gboolean
-graphics_opengl_idle(void *data)
-{
- static int opengl_init_ok = 0;
- if (!opengl_init_ok) {
- callback_list_call_attr_2(graphics_priv_root->cbl,
- attr_resize,
- GINT_TO_POINTER
- (graphics_priv_root->width),
- GINT_TO_POINTER
- (graphics_priv_root->height));
- opengl_init_ok = 1;
- } else {
-
+graphics_opengl_idle(void *data) {
+ static int opengl_init_ok = 0;
+ if (!opengl_init_ok) {
+ callback_list_call_attr_2(graphics_priv_root->cbl,
+ attr_resize,
+ GINT_TO_POINTER
+ (graphics_priv_root->width),
+ GINT_TO_POINTER
+ (graphics_priv_root->height));
+ opengl_init_ok = 1;
+ } else {
+
#ifdef FREEGLUT
- glutMainLoopEvent();
+ glutMainLoopEvent();
#endif
- handle_mouse_queue();
- }
- return TRUE;
+ handle_mouse_queue();
+ }
+ return TRUE;
}
#endif
static void
-ProcessNormalKeys(unsigned char key_in, int x, int y)
-{
- int key = 0;
- char keybuf[2];
-
- switch (key_in) {
- case 13:
- key = NAVIT_KEY_RETURN;
- break;
- default:
- key = key_in;
- break;
- }
- keybuf[0] = key;
- keybuf[1] = '\0';
- graphics_priv_root->force_redraw = 1;
- callback_list_call_attr_1(graphics_priv_root->cbl, attr_keypress,
- (void *) keybuf);
+ProcessNormalKeys(unsigned char key_in, int x, int y) {
+ int key = 0;
+ char keybuf[2];
+
+ switch (key_in) {
+ case 13:
+ key = NAVIT_KEY_RETURN;
+ break;
+ default:
+ key = key_in;
+ break;
+ }
+ keybuf[0] = key;
+ keybuf[1] = '\0';
+ graphics_priv_root->force_redraw = 1;
+ callback_list_call_attr_1(graphics_priv_root->cbl, attr_keypress,
+ (void *) keybuf);
}
static void
-ProcessSpecialKeys(int key_in, int x, int y)
-{
- int key = 0;
- char keybuf[2];
-
- switch (key_in) {
- case 102:
- key = NAVIT_KEY_RIGHT;
- break;
- case 100:
- key = NAVIT_KEY_LEFT;
- break;
- case 103:
- key = NAVIT_KEY_DOWN;
- break;
- case 101:
- key = NAVIT_KEY_UP;
- break;
- case 104:
- key = NAVIT_KEY_ZOOM_OUT;
- break;
- case 105:
- key = NAVIT_KEY_ZOOM_IN;
- break;
- default:
- break;
- } //switch
-
- graphics_priv_root->force_redraw = 1;
- keybuf[0] = key;
- keybuf[1] = '\0';
- callback_list_call_attr_1(graphics_priv_root->cbl, attr_keypress,
- (void *) keybuf);
+ProcessSpecialKeys(int key_in, int x, int y) {
+ int key = 0;
+ char keybuf[2];
+
+ switch (key_in) {
+ case 102:
+ key = NAVIT_KEY_RIGHT;
+ break;
+ case 100:
+ key = NAVIT_KEY_LEFT;
+ break;
+ case 103:
+ key = NAVIT_KEY_DOWN;
+ break;
+ case 101:
+ key = NAVIT_KEY_UP;
+ break;
+ case 104:
+ key = NAVIT_KEY_ZOOM_OUT;
+ break;
+ case 105:
+ key = NAVIT_KEY_ZOOM_IN;
+ break;
+ default:
+ break;
+ } //switch
+
+ graphics_priv_root->force_redraw = 1;
+ keybuf[0] = key;
+ keybuf[1] = '\0';
+ callback_list_call_attr_1(graphics_priv_root->cbl, attr_keypress,
+ (void *) keybuf);
}
static void
-resize_callback_do(struct graphics_priv *priv, int w, int h)
-{
- glViewport(0, 0, w, h);
+resize_callback_do(struct graphics_priv *priv, int w, int h) {
+ glViewport(0, 0, w, h);
#ifndef USE_OPENGLES2
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
#ifdef MIRRORED_VIEW
- glOrthof(glF(w), glF(0), glF(h), glF(0), glF(1), glF(-1));
+ glOrthof(glF(w), glF(0), glF(h), glF(0), glF(1), glF(-1));
#else
- glOrthof(glF(0), glF(w), glF(h), glF(0), glF(1), glF(-1));
+ glOrthof(glF(0), glF(w), glF(h), glF(0), glF(1), glF(-1));
#endif
#endif
- priv->width = w;
- priv->height = h;
+ priv->width = w;
+ priv->height = h;
- callback_list_call_attr_2(priv->cbl, attr_resize,
- GINT_TO_POINTER(w), GINT_TO_POINTER(h));
+ callback_list_call_attr_2(priv->cbl, attr_resize,
+ GINT_TO_POINTER(w), GINT_TO_POINTER(h));
}
static void
-resize_callback(int w, int h)
-{
- resize_callback_do(graphics_priv_root, w, h);
+resize_callback(int w, int h) {
+ resize_callback_do(graphics_priv_root, w, h);
}
static void
-display(void)
-{
- graphics_priv_root->force_redraw = 1;
- redraw_screen(graphics_priv_root);
- resize_callback(graphics_priv_root->width,
- graphics_priv_root->height);
+display(void) {
+ graphics_priv_root->force_redraw = 1;
+ redraw_screen(graphics_priv_root);
+ resize_callback(graphics_priv_root->width,
+ graphics_priv_root->height);
}
static void
-glut_close(void)
-{
- callback_list_call_attr_0(graphics_priv_root->cbl,
- attr_window_closed);
+glut_close(void) {
+ callback_list_call_attr_0(graphics_priv_root->cbl,
+ attr_window_closed);
}
static struct graphics_priv *
graphics_opengl_new(struct navit *nav, struct graphics_methods *meth,
- struct attr **attrs, struct callback_list *cbl)
-{
- struct attr *attr;
-
- if (!event_request_system("glib", "graphics_opengl_new"))
- return NULL;
-
- struct graphics_priv *this = graphics_opengl_new_helper(meth);
- graphics_priv_root = this;
-
- this->nav = nav;
- this->parent = NULL;
- this->overlay_enabled = 1;
-
- this->width = SCREEN_WIDTH;
- if ((attr = attr_search(attrs, NULL, attr_w)))
- this->width = attr->u.num;
- this->height = SCREEN_HEIGHT;
- if ((attr = attr_search(attrs, NULL, attr_h)))
- this->height = attr->u.num;
- this->timeout = 100;
- if ((attr = attr_search(attrs, NULL, attr_timeout)))
- this->timeout = attr->u.num;
- this->delay = 0;
- if ((attr = attr_search(attrs, NULL, attr_delay)))
- this->delay = attr->u.num;
- this->cbl = cbl;
-
- char *cmdline = "";
- int argc = 0;
+ struct attr **attrs, struct callback_list *cbl) {
+ struct attr *attr;
+
+ if (!event_request_system("glib", "graphics_opengl_new"))
+ return NULL;
+
+ struct graphics_priv *this = graphics_opengl_new_helper(meth);
+ graphics_priv_root = this;
+
+ this->nav = nav;
+ this->parent = NULL;
+ this->overlay_enabled = 1;
+
+ this->width = SCREEN_WIDTH;
+ if ((attr = attr_search(attrs, NULL, attr_w)))
+ this->width = attr->u.num;
+ this->height = SCREEN_HEIGHT;
+ if ((attr = attr_search(attrs, NULL, attr_h)))
+ this->height = attr->u.num;
+ this->timeout = 100;
+ if ((attr = attr_search(attrs, NULL, attr_timeout)))
+ this->timeout = attr->u.num;
+ this->delay = 0;
+ if ((attr = attr_search(attrs, NULL, attr_delay)))
+ this->delay = attr->u.num;
+ this->cbl = cbl;
+
+ char *cmdline = "";
+ int argc = 0;
#ifndef USE_OPENGLES
- glutInit(&argc, &cmdline);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
+ glutInit(&argc, &cmdline);
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
- glutInitWindowSize(this->width, this->height);
- glutInitWindowPosition(0, 0);
- glutCreateWindow("Navit opengl window");
+ glutInitWindowSize(this->width, this->height);
+ glutInitWindowPosition(0, 0);
+ glutCreateWindow("Navit opengl window");
- glutDisplayFunc(display);
- glutReshapeFunc(resize_callback);
- resize_callback(this->width, this->height);
+ glutDisplayFunc(display);
+ glutReshapeFunc(resize_callback);
+ resize_callback(this->width, this->height);
#endif
- graphics_priv_root->cbl = cbl;
- graphics_priv_root->width = this->width;
- graphics_priv_root->height = this->height;
+ graphics_priv_root->cbl = cbl;
+ graphics_priv_root->width = this->width;
+ graphics_priv_root->height = this->height;
#ifndef USE_OPENGLES
- glutMotionFunc(motion_notify);
- glutPassiveMotionFunc(motion_notify);
- glutMouseFunc(click_notify);
- glutKeyboardFunc(ProcessNormalKeys);
- glutSpecialFunc(ProcessSpecialKeys);
+ glutMotionFunc(motion_notify);
+ glutPassiveMotionFunc(motion_notify);
+ glutMouseFunc(click_notify);
+ glutKeyboardFunc(ProcessNormalKeys);
+ glutSpecialFunc(ProcessSpecialKeys);
#ifdef FREEGLUT
- glutCloseFunc(glut_close);
+ glutCloseFunc(glut_close);
#endif
- this->DLid = glGenLists(1);
+ this->DLid = glGenLists(1);
- g_timeout_add(G_PRIORITY_DEFAULT + 10, graphics_opengl_idle, NULL);
+ g_timeout_add(G_PRIORITY_DEFAULT + 10, graphics_opengl_idle, NULL);
- /*this will only refresh screen in map(overlay enabled) mode */
- g_timeout_add(G_PRIORITY_DEFAULT + 1000, redraw_filter, this);
+ /*this will only refresh screen in map(overlay enabled) mode */
+ g_timeout_add(G_PRIORITY_DEFAULT + 1000, redraw_filter, this);
#endif
- //create hash table for uncompressed image data
- hImageData = g_hash_table_new(g_str_hash, g_str_equal);
- return this;
+ //create hash table for uncompressed image data
+ hImageData = g_hash_table_new(g_str_hash, g_str_equal);
+ return this;
}
static void
-event_opengl_main_loop_run(void)
-{
- dbg(lvl_info, "enter");
+event_opengl_main_loop_run(void) {
+ dbg(lvl_info, "enter");
}
static void
-event_opengl_main_loop_quit(void)
-{
- dbg(lvl_debug, "enter");
+event_opengl_main_loop_quit(void) {
+ dbg(lvl_debug, "enter");
}
static struct event_watch *
event_opengl_add_watch(int fd, enum event_watch_cond cond,
- struct callback *cb)
-{
- dbg(lvl_debug, "enter");
- return NULL;
+ struct callback *cb) {
+ dbg(lvl_debug, "enter");
+ return NULL;
}
static void
-event_opengl_remove_watch(struct event_watch *ev)
-{
- dbg(lvl_debug, "enter");
+event_opengl_remove_watch(struct event_watch *ev) {
+ dbg(lvl_debug, "enter");
}
static struct event_timeout *
-event_opengl_add_timeout(int timeout, int multi, struct callback *cb)
-{
- dbg(lvl_debug, "enter");
- return NULL;
+event_opengl_add_timeout(int timeout, int multi, struct callback *cb) {
+ dbg(lvl_debug, "enter");
+ return NULL;
}
static void
-event_opengl_remove_timeout(struct event_timeout *to)
-{
- dbg(lvl_debug, "enter");
+event_opengl_remove_timeout(struct event_timeout *to) {
+ dbg(lvl_debug, "enter");
}
static struct event_idle *
-event_opengl_add_idle(int priority, struct callback *cb)
-{
- dbg(lvl_debug, "enter");
- return NULL;
+event_opengl_add_idle(int priority, struct callback *cb) {
+ dbg(lvl_debug, "enter");
+ return NULL;
}
static void
-event_opengl_remove_idle(struct event_idle *ev)
-{
- dbg(lvl_debug, "enter");
+event_opengl_remove_idle(struct event_idle *ev) {
+ dbg(lvl_debug, "enter");
}
static void
-event_opengl_call_callback(struct callback_list *cb)
-{
- dbg(lvl_debug, "enter");
+event_opengl_call_callback(struct callback_list *cb) {
+ dbg(lvl_debug, "enter");
}
static struct event_methods event_opengl_methods = {
- event_opengl_main_loop_run,
- event_opengl_main_loop_quit,
- event_opengl_add_watch,
- event_opengl_remove_watch,
- event_opengl_add_timeout,
- event_opengl_remove_timeout,
- event_opengl_add_idle,
- event_opengl_remove_idle,
- event_opengl_call_callback,
+ event_opengl_main_loop_run,
+ event_opengl_main_loop_quit,
+ event_opengl_add_watch,
+ event_opengl_remove_watch,
+ event_opengl_add_timeout,
+ event_opengl_remove_timeout,
+ event_opengl_add_idle,
+ event_opengl_remove_idle,
+ event_opengl_call_callback,
};
static struct event_priv *
-event_opengl_new(struct event_methods *meth)
-{
- *meth = event_opengl_methods;
- return NULL;
+event_opengl_new(struct event_methods *meth) {
+ *meth = event_opengl_methods;
+ return NULL;
}
void
-plugin_init(void)
-{
- plugin_register_category_graphics("opengl", graphics_opengl_new);
- plugin_register_category_event("opengl", event_opengl_new);
+plugin_init(void) {
+ plugin_register_category_graphics("opengl", graphics_opengl_new);
+ plugin_register_category_event("opengl", event_opengl_new);
}
diff --git a/navit/graphics/opengl/graphics_opengl_egl.c b/navit/graphics/opengl/graphics_opengl_egl.c
index 64e85e700..bb3ef5544 100644
--- a/navit/graphics/opengl/graphics_opengl_egl.c
+++ b/navit/graphics/opengl/graphics_opengl_egl.c
@@ -11,87 +11,84 @@
#include "debug.h"
struct graphics_opengl_platform {
- EGLSurface eglwindow;
- EGLDisplay egldisplay;
- EGLConfig config[1];
- EGLContext context;
+ EGLSurface eglwindow;
+ EGLDisplay egldisplay;
+ EGLConfig config[1];
+ EGLContext context;
};
static EGLint attributeList[] = {
- EGL_RED_SIZE, 8,
- EGL_ALPHA_SIZE, 8,
- EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+ EGL_RED_SIZE, 8,
+ EGL_ALPHA_SIZE, 8,
+ EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
#ifdef USE_OPENGLES2
- EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
#endif
- EGL_NONE
+ EGL_NONE
};
EGLint aEGLContextAttributes[] = {
#ifdef USE_OPENGLES2
- EGL_CONTEXT_CLIENT_VERSION, 2,
+ EGL_CONTEXT_CLIENT_VERSION, 2,
#endif
- EGL_NONE
+ EGL_NONE
};
static void
-graphics_opengl_egl_destroy(struct graphics_opengl_platform *egl)
-{
- g_free(egl);
+graphics_opengl_egl_destroy(struct graphics_opengl_platform *egl) {
+ g_free(egl);
}
static void
-graphics_opengl_egl_swap_buffers(struct graphics_opengl_platform *egl)
-{
- eglSwapBuffers(egl->egldisplay, egl->eglwindow);
+graphics_opengl_egl_swap_buffers(struct graphics_opengl_platform *egl) {
+ eglSwapBuffers(egl->egldisplay, egl->eglwindow);
}
struct graphics_opengl_platform_methods graphics_opengl_egl_methods = {
- graphics_opengl_egl_destroy,
- graphics_opengl_egl_swap_buffers,
+ graphics_opengl_egl_destroy,
+ graphics_opengl_egl_swap_buffers,
};
struct graphics_opengl_platform *
-graphics_opengl_egl_new(void *display, void *window, struct graphics_opengl_platform_methods **methods)
-{
- struct graphics_opengl_platform *ret=g_new0(struct graphics_opengl_platform,1);
- EGLint major,minor,nconfig;
+graphics_opengl_egl_new(void *display, void *window, struct graphics_opengl_platform_methods **methods) {
+ struct graphics_opengl_platform *ret=g_new0(struct graphics_opengl_platform,1);
+ EGLint major,minor,nconfig;
- *methods=&graphics_opengl_egl_methods;
- ret->egldisplay = eglGetDisplay((EGLNativeDisplayType)display);
- if (!ret->egldisplay) {
- dbg(lvl_error, "can't get display");
- goto error;
- }
- if (!eglInitialize(ret->egldisplay, &major, &minor)) {
- dbg(lvl_error, "eglInitialize failed");
- goto error;
- }
- dbg(lvl_debug,"eglInitialize ok with version %d.%d",major,minor);
- eglBindAPI(EGL_OPENGL_ES_API);
- if (!eglChooseConfig(ret->egldisplay, attributeList, ret->config, sizeof(ret->config)/sizeof(EGLConfig), &nconfig)) {
- dbg(lvl_error, "eglChooseConfig failed");
- goto error;
- }
- if (nconfig != 1) {
- dbg(lvl_error, "unexpected number of configs %d",nconfig);
- goto error;
- }
- ret->eglwindow = eglCreateWindowSurface(ret->egldisplay, ret->config[0], (NativeWindowType) window, NULL);
- if (ret->eglwindow == EGL_NO_SURFACE) {
- dbg(lvl_error, "eglCreateWindowSurface failed");
- goto error;
- }
- ret->context = eglCreateContext(ret->egldisplay, ret->config[0], EGL_NO_CONTEXT, aEGLContextAttributes);
- if (ret->context == EGL_NO_CONTEXT) {
- dbg(lvl_error, "eglCreateContext failed");
- goto error;
- }
- eglMakeCurrent(ret->egldisplay, ret->eglwindow, ret->eglwindow, ret->context);
- return ret;
+ *methods=&graphics_opengl_egl_methods;
+ ret->egldisplay = eglGetDisplay((EGLNativeDisplayType)display);
+ if (!ret->egldisplay) {
+ dbg(lvl_error, "can't get display");
+ goto error;
+ }
+ if (!eglInitialize(ret->egldisplay, &major, &minor)) {
+ dbg(lvl_error, "eglInitialize failed");
+ goto error;
+ }
+ dbg(lvl_debug,"eglInitialize ok with version %d.%d",major,minor);
+ eglBindAPI(EGL_OPENGL_ES_API);
+ if (!eglChooseConfig(ret->egldisplay, attributeList, ret->config, sizeof(ret->config)/sizeof(EGLConfig), &nconfig)) {
+ dbg(lvl_error, "eglChooseConfig failed");
+ goto error;
+ }
+ if (nconfig != 1) {
+ dbg(lvl_error, "unexpected number of configs %d",nconfig);
+ goto error;
+ }
+ ret->eglwindow = eglCreateWindowSurface(ret->egldisplay, ret->config[0], (NativeWindowType) window, NULL);
+ if (ret->eglwindow == EGL_NO_SURFACE) {
+ dbg(lvl_error, "eglCreateWindowSurface failed");
+ goto error;
+ }
+ ret->context = eglCreateContext(ret->egldisplay, ret->config[0], EGL_NO_CONTEXT, aEGLContextAttributes);
+ if (ret->context == EGL_NO_CONTEXT) {
+ dbg(lvl_error, "eglCreateContext failed");
+ goto error;
+ }
+ eglMakeCurrent(ret->egldisplay, ret->eglwindow, ret->eglwindow, ret->context);
+ return ret;
error:
- graphics_opengl_egl_destroy(ret);
- return NULL;
+ graphics_opengl_egl_destroy(ret);
+ return NULL;
}
diff --git a/navit/graphics/opengl/graphics_opengl_x11.c b/navit/graphics/opengl/graphics_opengl_x11.c
index a52192406..fa9b44f0b 100644
--- a/navit/graphics/opengl/graphics_opengl_x11.c
+++ b/navit/graphics/opengl/graphics_opengl_x11.c
@@ -7,147 +7,145 @@
#include "graphics_opengl.h"
struct graphics_opengl_window_system {
- Display *display;
- int screen;
- Window window,root_window;
- XVisualInfo visual;
- Colormap colormap;
- struct callback *cb;
- struct event_watch *watch;
- void *data;
- void (*resize)(void *data, int w, int h);
- void (*button)(void *data, int button, int state, int x, int y);
- void (*motion)(void *data, int x, int y);
- void *keypress;
+ Display *display;
+ int screen;
+ Window window,root_window;
+ XVisualInfo visual;
+ Colormap colormap;
+ struct callback *cb;
+ struct event_watch *watch;
+ void *data;
+ void (*resize)(void *data, int w, int h);
+ void (*button)(void *data, int button, int state, int x, int y);
+ void (*motion)(void *data, int x, int y);
+ void *keypress;
};
static void
-graphics_opengl_x11_destroy(struct graphics_opengl_window_system *x11)
-{
- if (x11->watch)
- event_remove_watch(x11->watch);
- if (x11->cb)
- callback_destroy(x11->cb);
- if (x11->display) {
- if (x11->window)
- XDestroyWindow(x11->display, x11->window);
- if (x11->colormap)
- XFreeColormap(x11->display, x11->colormap);
- XCloseDisplay(x11->display);
- }
- g_free(x11);
+graphics_opengl_x11_destroy(struct graphics_opengl_window_system *x11) {
+ if (x11->watch)
+ event_remove_watch(x11->watch);
+ if (x11->cb)
+ callback_destroy(x11->cb);
+ if (x11->display) {
+ if (x11->window)
+ XDestroyWindow(x11->display, x11->window);
+ if (x11->colormap)
+ XFreeColormap(x11->display, x11->colormap);
+ XCloseDisplay(x11->display);
+ }
+ g_free(x11);
}
static void *
-graphics_opengl_get_display(struct graphics_opengl_window_system *x11)
-{
- return x11->display;
+graphics_opengl_get_display(struct graphics_opengl_window_system *x11) {
+ return x11->display;
}
static void *
-graphics_opengl_get_window(struct graphics_opengl_window_system *x11)
-{
- return (void *)x11->window;
+graphics_opengl_get_window(struct graphics_opengl_window_system *x11) {
+ return (void *)x11->window;
}
static void
-graphics_opengl_set_callbacks(struct graphics_opengl_window_system *x11, void *data, void *resize, void *button, void *motion, void *keypress)
-{
- x11->data=data;
- x11->resize=resize;
- x11->button=button;
- x11->motion=motion;
- x11->keypress=keypress;
+graphics_opengl_set_callbacks(struct graphics_opengl_window_system *x11, void *data, void *resize, void *button,
+ void *motion, void *keypress) {
+ x11->data=data;
+ x11->resize=resize;
+ x11->button=button;
+ x11->motion=motion;
+ x11->keypress=keypress;
}
struct graphics_opengl_window_system_methods graphics_opengl_x11_methods = {
- graphics_opengl_x11_destroy,
- graphics_opengl_get_display,
- graphics_opengl_get_window,
- graphics_opengl_set_callbacks,
+ graphics_opengl_x11_destroy,
+ graphics_opengl_get_display,
+ graphics_opengl_get_window,
+ graphics_opengl_set_callbacks,
};
static void
-graphics_opengl_x11_watch(struct graphics_opengl_window_system *x11)
-{
- XEvent event;
- while (XPending(x11->display)) {
- XNextEvent(x11->display, &event);
- switch(event.type) {
- case ButtonPress:
- if (x11->button)
- x11->button(x11->data,event.xbutton.button,1,event.xbutton.x,event.xbutton.y);
- break;
- case ButtonRelease:
- if (x11->button)
- x11->button(x11->data,event.xbutton.button,0,event.xbutton.x,event.xbutton.y);
- break;
- case ConfigureNotify:
- dbg(lvl_debug,"ConfigureNotify");
- break;
- case Expose:
- dbg(lvl_debug,"Expose");
- break;
- case KeyPress:
- dbg(lvl_debug,"KeyPress");
- break;
- case KeyRelease:
- dbg(lvl_debug,"KeyRelease");
- break;
- case MapNotify:
- dbg(lvl_debug,"MapNotify");
- break;
- case MotionNotify:
- if (x11->motion)
- x11->motion(x11->data,event.xmotion.x,event.xmotion.y);
- break;
- case ReparentNotify:
- dbg(lvl_debug,"ReparentNotify");
- break;
- default:
- dbg(lvl_debug,"type %d",event.type);
- }
- }
+graphics_opengl_x11_watch(struct graphics_opengl_window_system *x11) {
+ XEvent event;
+ while (XPending(x11->display)) {
+ XNextEvent(x11->display, &event);
+ switch(event.type) {
+ case ButtonPress:
+ if (x11->button)
+ x11->button(x11->data,event.xbutton.button,1,event.xbutton.x,event.xbutton.y);
+ break;
+ case ButtonRelease:
+ if (x11->button)
+ x11->button(x11->data,event.xbutton.button,0,event.xbutton.x,event.xbutton.y);
+ break;
+ case ConfigureNotify:
+ dbg(lvl_debug,"ConfigureNotify");
+ break;
+ case Expose:
+ dbg(lvl_debug,"Expose");
+ break;
+ case KeyPress:
+ dbg(lvl_debug,"KeyPress");
+ break;
+ case KeyRelease:
+ dbg(lvl_debug,"KeyRelease");
+ break;
+ case MapNotify:
+ dbg(lvl_debug,"MapNotify");
+ break;
+ case MotionNotify:
+ if (x11->motion)
+ x11->motion(x11->data,event.xmotion.x,event.xmotion.y);
+ break;
+ case ReparentNotify:
+ dbg(lvl_debug,"ReparentNotify");
+ break;
+ default:
+ dbg(lvl_debug,"type %d",event.type);
+ }
+ }
}
-
+
struct graphics_opengl_window_system *
-graphics_opengl_x11_new(void *displayname, int w, int h, int depth, struct graphics_opengl_window_system_methods **methods)
-{
- struct graphics_opengl_window_system *ret=g_new0(struct graphics_opengl_window_system, 1);
- XSetWindowAttributes attributes;
- unsigned long valuemask;
+graphics_opengl_x11_new(void *displayname, int w, int h, int depth,
+ struct graphics_opengl_window_system_methods **methods) {
+ struct graphics_opengl_window_system *ret=g_new0(struct graphics_opengl_window_system, 1);
+ XSetWindowAttributes attributes;
+ unsigned long valuemask;
- ret->cb=callback_new_1(callback_cast(graphics_opengl_x11_watch), ret);
- if (!event_request_system("glib", "graphics_opengl_x11_new"))
- goto error;
- *methods=&graphics_opengl_x11_methods;
- ret->display=XOpenDisplay(displayname);
- if (!ret->display) {
- dbg(lvl_error,"failed to open display");
- goto error;
- }
- ret->watch=event_add_watch(ConnectionNumber(ret->display), event_watch_cond_read, ret->cb);
- ret->screen=XDefaultScreen(ret->display);
- ret->root_window=RootWindow(ret->display, ret->screen);
- if (!XMatchVisualInfo(ret->display, ret->screen, depth, TrueColor, &ret->visual)) {
- dbg(lvl_error,"failed to find visual");
- goto error;
- }
- ret->colormap=XCreateColormap(ret->display, ret->root_window, ret->visual.visual, AllocNone);
- valuemask = /* CWBackPixel | */ CWBorderPixel | CWEventMask | CWColormap ; // | CWBackingStore;
- attributes.colormap = ret->colormap;
- attributes.border_pixel = 0;
- attributes.event_mask = StructureNotifyMask | ExposureMask | ButtonPressMask | ButtonMotionMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask;
- attributes.backing_store = Always;
- ret->window=XCreateWindow(ret->display, RootWindow(ret->display, ret->screen), 0, 0, w, h, 0, ret->visual.depth, InputOutput, ret->visual.visual, valuemask, &attributes);
- XMapWindow(ret->display, ret->window);
- XFlush(ret->display);
- graphics_opengl_x11_watch(ret);
- return ret;
+ ret->cb=callback_new_1(callback_cast(graphics_opengl_x11_watch), ret);
+ if (!event_request_system("glib", "graphics_opengl_x11_new"))
+ goto error;
+ *methods=&graphics_opengl_x11_methods;
+ ret->display=XOpenDisplay(displayname);
+ if (!ret->display) {
+ dbg(lvl_error,"failed to open display");
+ goto error;
+ }
+ ret->watch=event_add_watch(ConnectionNumber(ret->display), event_watch_cond_read, ret->cb);
+ ret->screen=XDefaultScreen(ret->display);
+ ret->root_window=RootWindow(ret->display, ret->screen);
+ if (!XMatchVisualInfo(ret->display, ret->screen, depth, TrueColor, &ret->visual)) {
+ dbg(lvl_error,"failed to find visual");
+ goto error;
+ }
+ ret->colormap=XCreateColormap(ret->display, ret->root_window, ret->visual.visual, AllocNone);
+ valuemask = /* CWBackPixel | */ CWBorderPixel | CWEventMask | CWColormap ; // | CWBackingStore;
+ attributes.colormap = ret->colormap;
+ attributes.border_pixel = 0;
+ attributes.event_mask = StructureNotifyMask | ExposureMask | ButtonPressMask | ButtonMotionMask | ButtonReleaseMask |
+ KeyPressMask | KeyReleaseMask;
+ attributes.backing_store = Always;
+ ret->window=XCreateWindow(ret->display, RootWindow(ret->display, ret->screen), 0, 0, w, h, 0, ret->visual.depth,
+ InputOutput, ret->visual.visual, valuemask, &attributes);
+ XMapWindow(ret->display, ret->window);
+ XFlush(ret->display);
+ graphics_opengl_x11_watch(ret);
+ return ret;
error:
- graphics_opengl_x11_destroy(ret);
- return NULL;
+ graphics_opengl_x11_destroy(ret);
+ return NULL;
}
diff --git a/navit/graphics/qt5/QNavitQuick.cpp b/navit/graphics/qt5/QNavitQuick.cpp
index ffc7a56b0..6981f3af7 100644
--- a/navit/graphics/qt5/QNavitQuick.cpp
+++ b/navit/graphics/qt5/QNavitQuick.cpp
@@ -46,21 +46,18 @@ extern "C" {
#include <QPainter>
QNavitQuick::QNavitQuick(QQuickItem* parent)
- : QQuickPaintedItem(parent)
-{
+ : QQuickPaintedItem(parent) {
setAcceptedMouseButtons(Qt::AllButtons);
graphics_priv = NULL;
}
-void QNavitQuick::setGraphicContext(GraphicsPriv* gp)
-{
+void QNavitQuick::setGraphicContext(GraphicsPriv* gp) {
dbg(lvl_debug, "enter");
graphics_priv = gp->gp;
QObject::connect(gp, SIGNAL(update()), this, SLOT(update()));
}
-static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEvent* event)
-{
+static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEvent* event) {
GHashTableIter iter;
struct graphics_priv *key, *value;
g_hash_table_iter_init(&iter, gp->overlays);
@@ -68,7 +65,8 @@ static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEve
if (!value->disable) {
QRect rr(value->x, value->y, value->pixmap->width(), value->pixmap->height());
if (event->rect().intersects(rr)) {
- dbg(lvl_debug, "draw overlay (%d, %d, %d, %d)", value->x + value->scroll_x, value->y + value->scroll_y, value->pixmap->width(), value->pixmap->height());
+ dbg(lvl_debug, "draw overlay (%d, %d, %d, %d)", value->x + value->scroll_x, value->y + value->scroll_y,
+ value->pixmap->width(), value->pixmap->height());
painter->drawPixmap(value->x, value->y, *value->pixmap);
/* draw overlays of overlay if any by recursive calling */
paintOverlays(painter, value, event);
@@ -77,11 +75,12 @@ static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEve
}
}
-void QNavitQuick::paint(QPainter* painter)
-{
- QPaintEvent event = QPaintEvent(QRect(boundingRect().x(), boundingRect().y(), boundingRect().width(), boundingRect().height()));
+void QNavitQuick::paint(QPainter* painter) {
+ QPaintEvent event = QPaintEvent(QRect(boundingRect().x(), boundingRect().y(), boundingRect().width(),
+ boundingRect().height()));
- dbg(lvl_debug, "enter (%f, %f, %f, %f)", boundingRect().x(), boundingRect().y(), boundingRect().width(), boundingRect().height());
+ dbg(lvl_debug, "enter (%f, %f, %f, %f)", boundingRect().x(), boundingRect().y(), boundingRect().width(),
+ boundingRect().height());
/* color background if any */
if (graphics_priv->background_graphics_gc_priv != NULL) {
@@ -90,13 +89,12 @@ void QNavitQuick::paint(QPainter* painter)
}
/* draw base */
painter->drawPixmap(graphics_priv->scroll_x, graphics_priv->scroll_y, *graphics_priv->pixmap,
- boundingRect().x(), boundingRect().y(),
- boundingRect().width(), boundingRect().height());
+ boundingRect().x(), boundingRect().y(),
+ boundingRect().width(), boundingRect().height());
paintOverlays(painter, graphics_priv, &event);
}
-void QNavitQuick::keyPressEvent(QKeyEvent* event)
-{
+void QNavitQuick::keyPressEvent(QKeyEvent* event) {
dbg(lvl_debug, "enter");
char key[2];
int keycode;
@@ -160,13 +158,11 @@ void QNavitQuick::keyPressEvent(QKeyEvent* event)
dbg(lvl_debug, "keyval 0x%x", keycode);
}
-void QNavitQuick::keyReleaseEvent(QKeyEvent* event)
-{
+void QNavitQuick::keyReleaseEvent(QKeyEvent* event) {
dbg(lvl_debug, "enter");
}
-void QNavitQuick::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry)
-{
+void QNavitQuick::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) {
dbg(lvl_debug, "enter");
QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry);
QPainter* painter = NULL;
@@ -187,47 +183,47 @@ void QNavitQuick::geometryChanged(const QRectF& newGeometry, const QRectF& oldGe
delete painter;
}
dbg(lvl_debug, "size %fx%f", width(), height());
- dbg(lvl_debug, "pixmap %p %dx%d", graphics_priv->pixmap, graphics_priv->pixmap->width(), graphics_priv->pixmap->height());
+ dbg(lvl_debug, "pixmap %p %dx%d", graphics_priv->pixmap, graphics_priv->pixmap->width(),
+ graphics_priv->pixmap->height());
/* if the root window got resized, tell navit about it */
if (graphics_priv->root)
resize_callback(graphics_priv, width(), height());
}
-void QNavitQuick::mouseEvent(int pressed, QMouseEvent* event)
-{
+void QNavitQuick::mouseEvent(int pressed, QMouseEvent* event) {
struct point p;
dbg(lvl_debug, "enter");
p.x = event->x();
p.y = event->y();
switch (event->button()) {
case Qt::LeftButton:
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1),
+ GINT_TO_POINTER(&p));
break;
case Qt::MidButton:
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2),
+ GINT_TO_POINTER(&p));
break;
case Qt::RightButton:
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3),
+ GINT_TO_POINTER(&p));
break;
default:
break;
}
}
-void QNavitQuick::mousePressEvent(QMouseEvent* event)
-{
+void QNavitQuick::mousePressEvent(QMouseEvent* event) {
dbg(lvl_debug, "enter");
mouseEvent(1, event);
}
-void QNavitQuick::mouseReleaseEvent(QMouseEvent* event)
-{
+void QNavitQuick::mouseReleaseEvent(QMouseEvent* event) {
dbg(lvl_debug, "enter");
mouseEvent(0, event);
}
-void QNavitQuick::mouseMoveEvent(QMouseEvent* event)
-{
+void QNavitQuick::mouseMoveEvent(QMouseEvent* event) {
dbg(lvl_debug, "enter");
struct point p;
p.x = event->x();
@@ -235,8 +231,7 @@ void QNavitQuick::mouseMoveEvent(QMouseEvent* event)
callback_list_call_attr_1(graphics_priv->callbacks, attr_motion, (void*)&p);
}
-void QNavitQuick::wheelEvent(QWheelEvent* event)
-{
+void QNavitQuick::wheelEvent(QWheelEvent* event) {
struct point p;
int button;
dbg(lvl_debug, "enter");
@@ -251,8 +246,10 @@ void QNavitQuick::wheelEvent(QWheelEvent* event)
button = -1;
if (button != -1) {
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button),
+ GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button),
+ GINT_TO_POINTER(&p));
}
event->accept();
diff --git a/navit/graphics/qt5/QNavitWidget.cpp b/navit/graphics/qt5/QNavitWidget.cpp
index df051b557..9c2b96505 100644
--- a/navit/graphics/qt5/QNavitWidget.cpp
+++ b/navit/graphics/qt5/QNavitWidget.cpp
@@ -46,23 +46,20 @@ extern "C" {
#include "graphics_qt5.h"
QNavitWidget::QNavitWidget(struct graphics_priv* my_graphics_priv,
- QWidget* parent,
- Qt::WindowFlags flags)
- : QWidget(parent, flags)
-{
+ QWidget* parent,
+ Qt::WindowFlags flags)
+ : QWidget(parent, flags) {
graphics_priv = my_graphics_priv;
}
-bool QNavitWidget::event(QEvent* event)
-{
+bool QNavitWidget::event(QEvent* event) {
if (event->type() == QEvent::Gesture)
dbg(lvl_debug, "Gesture event caught");
//return gestureEvent(static_cast<QGestureEvent*>(event));
return QWidget::event(event);
}
-static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEvent* event)
-{
+static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEvent* event) {
GHashTableIter iter;
struct graphics_priv *key, *value;
g_hash_table_iter_init(&iter, gp->overlays);
@@ -70,7 +67,8 @@ static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEve
if (!value->disable) {
QRect rr(value->x, value->y, value->pixmap->width(), value->pixmap->height());
if (event->rect().intersects(rr)) {
- dbg(lvl_debug, "draw overlay (%d, %d, %d, %d)", value->x + value->scroll_x, value->y + value->scroll_y, value->pixmap->width(), value->pixmap->height());
+ dbg(lvl_debug, "draw overlay (%d, %d, %d, %d)", value->x + value->scroll_x, value->y + value->scroll_y,
+ value->pixmap->width(), value->pixmap->height());
painter->drawPixmap(value->x + value->scroll_x, value->y + value->scroll_y, *value->pixmap);
/* draw overlays of overlay if any by recursive calling */
paintOverlays(painter, value, event);
@@ -79,9 +77,9 @@ static void paintOverlays(QPainter* painter, struct graphics_priv* gp, QPaintEve
}
}
-void QNavitWidget::paintEvent(QPaintEvent* event)
-{
- dbg(lvl_debug, "enter (%d, %d, %d, %d)", event->rect().x(), event->rect().y(), event->rect().width(), event->rect().height());
+void QNavitWidget::paintEvent(QPaintEvent* event) {
+ dbg(lvl_debug, "enter (%d, %d, %d, %d)", event->rect().x(), event->rect().y(), event->rect().width(),
+ event->rect().height());
QPainter painter(this);
/* color background if any */
if (graphics_priv->background_graphics_gc_priv != NULL) {
@@ -89,13 +87,12 @@ void QNavitWidget::paintEvent(QPaintEvent* event)
painter.fillRect(event->rect(), *graphics_priv->background_graphics_gc_priv->brush);
}
painter.drawPixmap(event->rect().x(), event->rect().y(), *graphics_priv->pixmap,
- event->rect().x() - graphics_priv->scroll_x, event->rect().y() - graphics_priv->scroll_y,
- event->rect().width(), event->rect().height());
+ event->rect().x() - graphics_priv->scroll_x, event->rect().y() - graphics_priv->scroll_y,
+ event->rect().width(), event->rect().height());
paintOverlays(&painter, graphics_priv, event);
}
-void QNavitWidget::resizeEvent(QResizeEvent* event)
-{
+void QNavitWidget::resizeEvent(QResizeEvent* event) {
QPainter* painter = NULL;
if (graphics_priv->pixmap != NULL) {
delete graphics_priv->pixmap;
@@ -110,35 +107,37 @@ void QNavitWidget::resizeEvent(QResizeEvent* event)
delete painter;
}
dbg(lvl_debug, "size %dx%d", width(), height());
- dbg(lvl_debug, "pixmap %p %dx%d", graphics_priv->pixmap, graphics_priv->pixmap->width(), graphics_priv->pixmap->height());
+ dbg(lvl_debug, "pixmap %p %dx%d", graphics_priv->pixmap, graphics_priv->pixmap->width(),
+ graphics_priv->pixmap->height());
/* if the root window got resized, tell navit about it */
if (graphics_priv->root)
resize_callback(graphics_priv, width(), height());
}
-void QNavitWidget::mouseEvent(int pressed, QMouseEvent* event)
-{
+void QNavitWidget::mouseEvent(int pressed, QMouseEvent* event) {
struct point p;
// dbg(lvl_debug,"enter");
p.x = event->x();
p.y = event->y();
switch (event->button()) {
case Qt::LeftButton:
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1),
+ GINT_TO_POINTER(&p));
break;
case Qt::MidButton:
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2),
+ GINT_TO_POINTER(&p));
break;
case Qt::RightButton:
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3),
+ GINT_TO_POINTER(&p));
break;
default:
break;
}
}
-void QNavitWidget::keyPressEvent(QKeyEvent* event)
-{
+void QNavitWidget::keyPressEvent(QKeyEvent* event) {
dbg(lvl_debug, "enter");
char key[2];
int keycode;
@@ -202,20 +201,17 @@ void QNavitWidget::keyPressEvent(QKeyEvent* event)
dbg(lvl_debug, "keyval 0x%x", keycode);
}
-void QNavitWidget::mousePressEvent(QMouseEvent* event)
-{
+void QNavitWidget::mousePressEvent(QMouseEvent* event) {
// dbg(lvl_debug,"enter");
mouseEvent(1, event);
}
-void QNavitWidget::mouseReleaseEvent(QMouseEvent* event)
-{
+void QNavitWidget::mouseReleaseEvent(QMouseEvent* event) {
// dbg(lvl_debug,"enter");
mouseEvent(0, event);
}
-void QNavitWidget::mouseMoveEvent(QMouseEvent* event)
-{
+void QNavitWidget::mouseMoveEvent(QMouseEvent* event) {
struct point p;
// dbg(lvl_debug,"enter");
p.x = event->x();
@@ -223,8 +219,7 @@ void QNavitWidget::mouseMoveEvent(QMouseEvent* event)
callback_list_call_attr_1(graphics_priv->callbacks, attr_motion, (void*)&p);
}
-void QNavitWidget::wheelEvent(QWheelEvent* event)
-{
+void QNavitWidget::wheelEvent(QWheelEvent* event) {
struct point p;
int button;
dbg(lvl_debug, "enter");
@@ -239,8 +234,10 @@ void QNavitWidget::wheelEvent(QWheelEvent* event)
button = -1;
if (button != -1) {
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
- callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button),
+ GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button),
+ GINT_TO_POINTER(&p));
}
event->accept();
diff --git a/navit/graphics/qt5/event_qt5.cpp b/navit/graphics/qt5/event_qt5.cpp
index e7cb1fd9f..02e637439 100644
--- a/navit/graphics/qt5/event_qt5.cpp
+++ b/navit/graphics/qt5/event_qt5.cpp
@@ -58,26 +58,23 @@ struct event_watch {
static void event_qt5_remove_timeout(struct event_timeout* to);
qt5_navit_timer::qt5_navit_timer(QObject* parent)
- : QObject(parent)
-{
+ : QObject(parent) {
timer_type = g_hash_table_new(NULL, NULL);
timer_callback = g_hash_table_new(NULL, NULL);
watches = g_hash_table_new(NULL, NULL);
dbg(lvl_debug, "qt5_navit_timer object created");
}
-void qt5_navit_timer::watchEvent(int id)
-{
- struct event_watch* ret = g_new0(struct event_watch, 1);
- ret = (struct event_watch*)g_hash_table_lookup(watches, (void*)(long)id);
- if (ret) {
+void qt5_navit_timer::watchEvent(int id) {
+ struct event_watch* ret = g_new0(struct event_watch, 1);
+ ret = (struct event_watch*)g_hash_table_lookup(watches, (void*)(long)id);
+ if (ret) {
dbg(lvl_debug, "callback found, calling it");
callback_call_0(ret->cb);
}
}
-void qt5_navit_timer::timerEvent(QTimerEvent* event)
-{
+void qt5_navit_timer::timerEvent(QTimerEvent* event) {
int id = event->timerId();
void* multi = NULL;
// dbg(lvl_debug, "TimerEvent (%d)", id);
@@ -96,23 +93,20 @@ void qt5_navit_timer::timerEvent(QTimerEvent* event)
qt5_navit_timer* qt5_timer = NULL;
static void
-event_qt5_main_loop_run(void)
-{
+event_qt5_main_loop_run(void) {
dbg(lvl_debug, "enter");
if (navit_app != NULL)
navit_app->exec();
}
-static void event_qt5_main_loop_quit(void)
-{
+static void event_qt5_main_loop_quit(void) {
dbg(lvl_debug, "enter");
exit(0);
}
static struct event_watch*
-event_qt5_add_watch(int fd, enum event_watch_cond cond, struct callback* cb)
-{
+event_qt5_add_watch(int fd, enum event_watch_cond cond, struct callback* cb) {
dbg(lvl_debug, "enter fd=%d", (int)(long)fd);
struct event_watch* ret = g_new0(struct event_watch, 1);
ret->fd = fd;
@@ -124,8 +118,7 @@ event_qt5_add_watch(int fd, enum event_watch_cond cond, struct callback* cb)
}
static void
-event_qt5_remove_watch(struct event_watch* ev)
-{
+event_qt5_remove_watch(struct event_watch* ev) {
dbg(lvl_debug, "enter");
g_hash_table_remove(qt5_timer->watches, GINT_TO_POINTER(ev->fd));
delete (ev->sn);
@@ -133,8 +126,7 @@ event_qt5_remove_watch(struct event_watch* ev)
}
static struct event_timeout*
-event_qt5_add_timeout(int timeout, int multi, struct callback* cb)
-{
+event_qt5_add_timeout(int timeout, int multi, struct callback* cb) {
int id;
dbg(lvl_debug, "add timeout %d, mul %d, %p ==", timeout, multi, cb);
id = qt5_timer->startTimer(timeout);
@@ -145,8 +137,7 @@ event_qt5_add_timeout(int timeout, int multi, struct callback* cb)
}
static void
-event_qt5_remove_timeout(struct event_timeout* to)
-{
+event_qt5_remove_timeout(struct event_timeout* to) {
dbg(lvl_debug, "remove timeout (%d)", (int)(long)to);
qt5_timer->killTimer((int)(long)to);
g_hash_table_remove(qt5_timer->timer_callback, to);
@@ -154,22 +145,19 @@ event_qt5_remove_timeout(struct event_timeout* to)
}
static struct event_idle*
-event_qt5_add_idle(int priority, struct callback* cb)
-{
+event_qt5_add_idle(int priority, struct callback* cb) {
dbg(lvl_debug, "add idle event");
return (struct event_idle*)event_qt5_add_timeout(0, 1, cb);
}
static void
-event_qt5_remove_idle(struct event_idle* ev)
-{
+event_qt5_remove_idle(struct event_idle* ev) {
dbg(lvl_debug, "Remove idle timeout");
event_qt5_remove_timeout((struct event_timeout*)ev);
}
static void
-event_qt5_call_callback(struct callback_list* cb)
-{
+event_qt5_call_callback(struct callback_list* cb) {
dbg(lvl_debug, "enter");
}
@@ -186,14 +174,12 @@ static struct event_methods event_qt5_methods = {
};
static struct event_priv*
-event_qt5_new(struct event_methods* meth)
-{
+event_qt5_new(struct event_methods* meth) {
*meth = event_qt5_methods;
qt5_timer = new qt5_navit_timer(NULL);
return NULL;
}
-void qt5_event_init(void)
-{
+void qt5_event_init(void) {
plugin_register_category_event("qt5", event_qt5_new);
}
diff --git a/navit/graphics/qt5/graphics_qt5.cpp b/navit/graphics/qt5/graphics_qt5.cpp
index f142758ea..ddcd51244 100644
--- a/navit/graphics/qt5/graphics_qt5.cpp
+++ b/navit/graphics/qt5/graphics_qt5.cpp
@@ -64,17 +64,14 @@ extern "C" {
#endif
#if USE_QML
-GraphicsPriv::GraphicsPriv(struct graphics_priv* gp)
-{
+GraphicsPriv::GraphicsPriv(struct graphics_priv* gp) {
this->gp = gp;
}
-GraphicsPriv::~GraphicsPriv()
-{
+GraphicsPriv::~GraphicsPriv() {
}
-void GraphicsPriv::emit_update()
-{
+void GraphicsPriv::emit_update() {
emit update();
}
#endif
@@ -90,8 +87,7 @@ struct graphics_image_priv {
};
static void
-graphics_destroy(struct graphics_priv* gr)
-{
+graphics_destroy(struct graphics_priv* gr) {
// dbg(lvl_debug,"enter");
#if HAVE_FREETYPE
gr->freetype_methods.destroy();
@@ -144,8 +140,7 @@ graphics_destroy(struct graphics_priv* gr)
g_free(gr);
}
-static void font_destroy(struct graphics_font_priv* font)
-{
+static void font_destroy(struct graphics_font_priv* font) {
// dbg(lvl_debug,"enter");
if (font->font != NULL)
delete (font->font);
@@ -186,8 +181,8 @@ static const char* fontfamilies[] = {
*
* Allocates a font handle and returnes filled interface stucture
*/
-static struct graphics_font_priv* font_new(struct graphics_priv* gr, struct graphics_font_methods* meth, char* font, int size, int flags)
-{
+static struct graphics_font_priv* font_new(struct graphics_priv* gr, struct graphics_font_methods* meth, char* font,
+ int size, int flags) {
int a = 0;
struct graphics_font_priv* font_priv;
dbg(lvl_debug, "enter (font %s, %d, 0x%x)", font, size, flags);
@@ -225,8 +220,7 @@ static struct graphics_font_priv* font_new(struct graphics_priv* gr, struct grap
}
static void
-gc_destroy(struct graphics_gc_priv* gc)
-{
+gc_destroy(struct graphics_gc_priv* gc) {
// dbg(lvl_debug,"enter gc=%p", gc);
delete (gc->pen);
delete (gc->brush);
@@ -234,15 +228,13 @@ gc_destroy(struct graphics_gc_priv* gc)
}
static void
-gc_set_linewidth(struct graphics_gc_priv* gc, int w)
-{
+gc_set_linewidth(struct graphics_gc_priv* gc, int w) {
// dbg(lvl_debug,"enter gc=%p, %d", gc, w);
gc->pen->setWidth(w);
}
static void
-gc_set_dashes(struct graphics_gc_priv* gc, int w, int offset, unsigned char* dash_list, int n)
-{
+gc_set_dashes(struct graphics_gc_priv* gc, int w, int offset, unsigned char* dash_list, int n) {
if (n <= 0) {
dbg(lvl_error, "Refuse to set dashes without dash pattern");
}
@@ -263,8 +255,7 @@ gc_set_dashes(struct graphics_gc_priv* gc, int w, int offset, unsigned char* das
}
static void
-gc_set_foreground(struct graphics_gc_priv* gc, struct color* c)
-{
+gc_set_foreground(struct graphics_gc_priv* gc, struct color* c) {
QColor col(c->r >> 8, c->g >> 8, c->b >> 8, c->a >> 8);
// dbg(lvl_debug,"context %p: color %02x%02x%02x",gc, c->r >> 8, c->g >> 8, c->b >> 8);
gc->pen->setColor(col);
@@ -273,8 +264,7 @@ gc_set_foreground(struct graphics_gc_priv* gc, struct color* c)
}
static void
-gc_set_background(struct graphics_gc_priv* gc, struct color* c)
-{
+gc_set_background(struct graphics_gc_priv* gc, struct color* c) {
QColor col(c->r >> 8, c->g >> 8, c->b >> 8, c->a >> 8);
// dbg(lvl_debug,"context %p: color %02x%02x%02x",gc, c->r >> 8, c->g >> 8, c->b >> 8);
//gc->pen->setColor(col);
@@ -289,8 +279,7 @@ static struct graphics_gc_methods gc_methods = {
gc_set_background
};
-static struct graphics_gc_priv* gc_new(struct graphics_priv* gr, struct graphics_gc_methods* meth)
-{
+static struct graphics_gc_priv* gc_new(struct graphics_priv* gr, struct graphics_gc_methods* meth) {
struct graphics_gc_priv* graphics_gc_priv = NULL;
// dbg(lvl_debug,"enter gr==%p", gr);
graphics_gc_priv = g_new0(struct graphics_gc_priv, 1);
@@ -302,8 +291,7 @@ static struct graphics_gc_priv* gc_new(struct graphics_priv* gr, struct graphics
return graphics_gc_priv;
}
-static void image_destroy(struct graphics_image_priv* img)
-{
+static void image_destroy(struct graphics_image_priv* img) {
// dbg(lvl_debug, "enter");
if (img->pixmap != NULL)
delete (img->pixmap);
@@ -315,8 +303,8 @@ struct graphics_image_methods image_methods = {
};
static struct graphics_image_priv*
-image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* path, int* w, int* h, struct point* hot, int rotation)
-{
+image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* path, int* w, int* h, struct point* hot,
+ int rotation) {
struct graphics_image_priv* image_priv;
// dbg(lvl_debug,"enter %s, %d %d", path, *w, *h);
if (path[0] == 0) {
@@ -376,7 +364,8 @@ image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* p
/* check if we need to scale this */
if ((*w > 0) && (*h > 0)) {
if ((image_priv->pixmap->width() != *w) || (image_priv->pixmap->height() != *h)) {
- dbg(lvl_debug, "scale pixmap %s, %d->%d,%d->%d", path, image_priv->pixmap->width(), *w, image_priv->pixmap->height(), *h);
+ dbg(lvl_debug, "scale pixmap %s, %d->%d,%d->%d", path, image_priv->pixmap->width(), *w, image_priv->pixmap->height(),
+ *h);
QPixmap* scaled = new QPixmap(image_priv->pixmap->scaled(*w, *h, Qt::IgnoreAspectRatio, Qt::FastTransformation));
delete (image_priv->pixmap);
image_priv->pixmap = scaled;
@@ -396,8 +385,7 @@ image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* p
}
static void
-draw_lines(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int count)
-{
+draw_lines(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int count) {
int i;
QPolygon polygon;
// dbg(lvl_debug,"enter gr=%p, gc=%p, (%d, %d)", gr, gc, p->x, p->y);
@@ -411,8 +399,7 @@ draw_lines(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point*
}
static void
-draw_polygon(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int count)
-{
+draw_polygon(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int count) {
int i;
QPolygon polygon;
// dbg(lvl_debug,"enter gr=%p, gc=%p, (%d, %d)", gr, gc, p->x, p->y);
@@ -434,8 +421,7 @@ draw_polygon(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point
}
static void
-draw_rectangle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int w, int h)
-{
+draw_rectangle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int w, int h) {
// dbg(lvl_debug,"gr=%p gc=%p %d,%d,%d,%d", gr, gc, p->x, p->y, w, h);
if (gr->painter == NULL)
return;
@@ -450,8 +436,7 @@ draw_rectangle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct poi
}
static void
-draw_circle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int r)
-{
+draw_circle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int r) {
// dbg(lvl_debug,"enter gr=%p, gc=%p, (%d,%d) r=%d", gr, gc, p->x, p->y, r);
if (gr->painter == NULL)
return;
@@ -473,8 +458,8 @@ draw_circle(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point*
* Renders given text on gr surface. Draws nice contrast outline around text.
*/
static void
-draw_text(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct graphics_gc_priv* bg, struct graphics_font_priv* font, char* text, struct point* p, int dx, int dy)
-{
+draw_text(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct graphics_gc_priv* bg,
+ struct graphics_font_priv* font, char* text, struct point* p, int dx, int dy) {
dbg(lvl_debug, "enter gc=%p, fg=%p, bg=%p pos(%d,%d) d(%d, %d) %s", gr, fg, bg, p->x, p->y, dx, dy, text);
QPainter* painter = gr->painter;
if (painter == NULL)
@@ -566,8 +551,7 @@ draw_text(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct graphics
}
static void
-draw_image(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct point* p, struct graphics_image_priv* img)
-{
+draw_image(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct point* p, struct graphics_image_priv* img) {
// dbg(lvl_debug,"enter");
if (gr->painter != NULL)
gr->painter->drawPixmap(p->x, p->y, *img->pixmap);
@@ -584,8 +568,7 @@ draw_image(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct point*
* called for root layer. There the content of the root layer is to be moved
* by given vector. On root layer, NULL indicates the end of a drag.
*/
-static void draw_drag(struct graphics_priv* gr, struct point* p)
-{
+static void draw_drag(struct graphics_priv* gr, struct point* p) {
struct point vector;
if (p != NULL) {
@@ -622,15 +605,13 @@ static void draw_drag(struct graphics_priv* gr, struct point* p)
}
static void
-background_gc(struct graphics_priv* gr, struct graphics_gc_priv* gc)
-{
+background_gc(struct graphics_priv* gr, struct graphics_gc_priv* gc) {
// dbg(lvl_debug,"register context %p on %p", gc, gr);
gr->background_graphics_gc_priv = gc;
}
static void
-draw_mode(struct graphics_priv* gr, enum draw_mode_num mode)
-{
+draw_mode(struct graphics_priv* gr, enum draw_mode_num mode) {
switch (mode) {
case draw_mode_begin:
dbg(lvl_debug, "Begin drawing on context %p (use == %d)", gr, gr->use_count);
@@ -672,18 +653,17 @@ draw_mode(struct graphics_priv* gr, enum draw_mode_num mode)
}
}
-static struct graphics_priv* overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p, int w, int h, int wraparound);
+static struct graphics_priv* overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p,
+ int w, int h, int wraparound);
-void resize_callback(struct graphics_priv* gr, int w, int h)
-{
+void resize_callback(struct graphics_priv* gr, int w, int h) {
// dbg(lvl_debug,"enter (%d, %d)", w, h);
callback_list_call_attr_2(gr->callbacks, attr_resize,
- GINT_TO_POINTER(w), GINT_TO_POINTER(h));
+ GINT_TO_POINTER(w), GINT_TO_POINTER(h));
}
static int
-graphics_qt5_fullscreen(struct window* w, int on)
-{
+graphics_qt5_fullscreen(struct window* w, int on) {
struct graphics_priv* gr;
// dbg(lvl_debug,"enter");
gr = (struct graphics_priv*)w->priv;
@@ -708,8 +688,7 @@ graphics_qt5_fullscreen(struct window* w, int on)
#ifdef SAILFISH_OS
static void
-keep_display_on(struct graphics_priv* priv)
-{
+keep_display_on(struct graphics_priv* priv) {
// dbg(lvl_debug,"enter");
QDBusConnection system = QDBusConnection::connectToBus(QDBusConnection::SystemBus, "system");
QDBusInterface interface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request", system);
@@ -719,8 +698,7 @@ keep_display_on(struct graphics_priv* priv)
#endif
static void
-graphics_qt5_disable_suspend(struct window* w)
-{
+graphics_qt5_disable_suspend(struct window* w) {
// dbg(lvl_debug,"enter");
#ifdef SAILFISH_OS
struct graphics_priv* gr;
@@ -734,8 +712,7 @@ graphics_qt5_disable_suspend(struct window* w)
}
static void*
-get_data(struct graphics_priv* this_priv, char const* type)
-{
+get_data(struct graphics_priv* this_priv, char const* type) {
// dbg(lvl_debug,"enter: %s", type);
if (strcmp(type, "window") == 0) {
struct window* win;
@@ -754,8 +731,7 @@ get_data(struct graphics_priv* this_priv, char const* type)
return NULL;
}
-static void image_free(struct graphics_priv* gr, struct graphics_image_priv* priv)
-{
+static void image_free(struct graphics_priv* gr, struct graphics_image_priv* priv) {
// dbg(lvl_debug,"enter");
delete (priv->pixmap);
g_free(priv);
@@ -773,8 +749,8 @@ static void image_free(struct graphics_priv* gr, struct graphics_image_priv* pri
*
* Calculates the bounding box around the given text.
*/
-static void get_text_bbox(struct graphics_priv* gr, struct graphics_font_priv* font, char* text, int dx, int dy, struct point* ret, int estimate)
-{
+static void get_text_bbox(struct graphics_priv* gr, struct graphics_font_priv* font, char* text, int dx, int dy,
+ struct point* ret, int estimate) {
int i;
struct point pt;
QString tmp = QString::fromUtf8(text);
@@ -807,8 +783,7 @@ static void get_text_bbox(struct graphics_priv* gr, struct graphics_font_priv* f
}
}
-static void overlay_disable(struct graphics_priv* gr, int disable)
-{
+static void overlay_disable(struct graphics_priv* gr, int disable) {
GHashTableIter iter;
struct graphics_priv *key, *value;
// dbg(lvl_debug,"enter gr=%p, %d", gr, disable);
@@ -820,8 +795,7 @@ static void overlay_disable(struct graphics_priv* gr, int disable)
}
}
-static void overlay_resize(struct graphics_priv* gr, struct point* p, int w, int h, int wraparound)
-{
+static void overlay_resize(struct graphics_priv* gr, struct point* p, int w, int h, int wraparound) {
// dbg(lvl_debug,"enter");
gr->x = p->x;
gr->y = p->y;
@@ -860,8 +834,7 @@ static struct graphics_methods graphics_methods = {
/* create new graphics context on given context */
static struct graphics_priv*
-overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p, int w, int h, int wraparound)
-{
+overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p, int w, int h, int wraparound) {
struct graphics_priv* graphics_priv = NULL;
graphics_priv = g_new0(struct graphics_priv, 1);
*meth = graphics_methods;
@@ -869,8 +842,10 @@ overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct poin
if (gr->font_freetype_new) {
graphics_priv->font_freetype_new = gr->font_freetype_new;
gr->font_freetype_new(&graphics_priv->freetype_methods);
- meth->font_new = (struct graphics_font_priv * (*)(struct graphics_priv*, struct graphics_font_methods*, char*, int, int))graphics_priv->freetype_methods.font_new;
- meth->get_text_bbox = (void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*, int))graphics_priv->freetype_methods.get_text_bbox;
+ meth->font_new = (struct graphics_font_priv * (*)(struct graphics_priv*, struct graphics_font_methods*, char*, int,
+ int))graphics_priv->freetype_methods.font_new;
+ meth->get_text_bbox = (void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*,
+ int))graphics_priv->freetype_methods.get_text_bbox;
}
#endif
#if USE_QML
@@ -904,8 +879,7 @@ overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct poin
/* create application and initial graphics context */
static struct graphics_priv*
-graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr** attrs, struct callback_list* cbl)
-{
+graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr** attrs, struct callback_list* cbl) {
struct graphics_priv* graphics_priv = NULL;
struct attr* event_loop_system = NULL;
struct attr* platform = NULL;
@@ -971,7 +945,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
graphics_priv->argv[graphics_priv->argc] = g_strdup(platform->u.str);
graphics_priv->argc++;
}
-/* create surrounding application */
+ /* create surrounding application */
#if USE_QWIDGET
QApplication* internal_app = new QApplication(graphics_priv->argc, graphics_priv->argv);
navit_app = internal_app;
@@ -982,8 +956,10 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
#if HAVE_FREETYPE
graphics_priv->font_freetype_new = font_freetype_new;
font_freetype_new(&graphics_priv->freetype_methods);
- meth->font_new = (struct graphics_font_priv * (*)(struct graphics_priv*, struct graphics_font_methods*, char*, int, int))graphics_priv->freetype_methods.font_new;
- meth->get_text_bbox = (void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*, int))graphics_priv->freetype_methods.get_text_bbox;
+ meth->font_new = (struct graphics_font_priv * (*)(struct graphics_priv*, struct graphics_font_methods*, char*, int,
+ int))graphics_priv->freetype_methods.font_new;
+ meth->get_text_bbox = (void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*,
+ int))graphics_priv->freetype_methods.get_text_bbox;
#endif
graphics_priv->callbacks = cbl;
graphics_priv->pixmap = NULL;
@@ -1004,7 +980,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
/* register our QtQuick widget to allow it's usage within QML */
qmlRegisterType<QNavitQuick>("com.navit.graphics_qt5", 1, 0, "QNavitQuick");
/* get our qml application from embedded resources. May be replaced by the
- * QtQuick gui component if enabled */
+ * QtQuick gui component if enabled */
graphics_priv->engine = new QQmlApplicationEngine();
if (graphics_priv->engine != NULL) {
graphics_priv->GPriv = new GraphicsPriv(graphics_priv);
@@ -1024,7 +1000,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
}
#endif
if ((fullscreen = attr_search(attrs, NULL, attr_fullscreen)) && (fullscreen->u.num)) {
-/* show this maximized */
+ /* show this maximized */
#if USE_QML
if (graphics_priv->window != NULL)
graphics_priv->window->setWindowState(Qt::WindowFullScreen);
@@ -1083,7 +1059,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
/* tell Navit our geometry */
resize_callback(graphics_priv, graphics_priv->pixmap->width(), graphics_priv->pixmap->height());
-/* show our window */
+ /* show our window */
#if USE_QML
if (graphics_priv->window != NULL)
graphics_priv->window->show();
@@ -1096,8 +1072,7 @@ graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr**
return graphics_priv;
}
-void plugin_init(void)
-{
+void plugin_init(void) {
#if USE_QML
Q_INIT_RESOURCE(graphics_qt5);
#endif
diff --git a/navit/graphics/qt_qpainter/RenderArea.cpp b/navit/graphics/qt_qpainter/RenderArea.cpp
index 4a20b1d54..76f8f198f 100644
--- a/navit/graphics/qt_qpainter/RenderArea.cpp
+++ b/navit/graphics/qt_qpainter/RenderArea.cpp
@@ -22,19 +22,18 @@
#include "RenderArea.moc"
#ifdef QT_QPAINTER_USE_EMBEDDING
-EmbeddedWidget::EmbeddedWidget(struct graphics_priv *priv, QWidget* child, QWidget *parent)
-: QX11EmbedWidget(parent) {
+EmbeddedWidget::EmbeddedWidget(struct graphics_priv *priv, QWidget* child, QWidget *parent)
+ : QX11EmbedWidget(parent) {
this->gra=priv;
- this->setWindowTitle(priv->window_title);
- QStackedLayout* _outerLayout = new QStackedLayout(this);
- this->setLayout(_outerLayout);
- _outerLayout->addWidget(child);
- _outerLayout->setCurrentWidget(child);
+ this->setWindowTitle(priv->window_title);
+ QStackedLayout* _outerLayout = new QStackedLayout(this);
+ this->setLayout(_outerLayout);
+ _outerLayout->addWidget(child);
+ _outerLayout->setCurrentWidget(child);
}
-void EmbeddedWidget::closeEvent(QCloseEvent* event)
-{
- gra->widget->processClose();
+void EmbeddedWidget::closeEvent(QCloseEvent* event) {
+ gra->widget->processClose();
}
#endif /* QT_QPAINTER_USE_EMBEDDING */
@@ -44,27 +43,26 @@ void EmbeddedWidget::closeEvent(QCloseEvent* event)
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
RenderArea::RenderArea(struct graphics_priv *priv, QT_QPAINTER_RENDERAREA_PARENT *parent, int w, int h, int overlay)
- : QT_QPAINTER_RENDERAREA_PARENT(parent)
-{
- pixmap = new QPixmap(w, h);
+ : QT_QPAINTER_RENDERAREA_PARENT(parent) {
+ pixmap = new QPixmap(w, h);
#ifndef QT_QPAINTER_NO_WIDGET
- if (!overlay) {
-#if QT_VERSION >= 0x040700
- grabGesture(Qt::PinchGesture);
- grabGesture(Qt::SwipeGesture);
- grabGesture(Qt::PanGesture);
+ if (!overlay) {
+#if QT_VERSION >= 0x040700
+ grabGesture(Qt::PinchGesture);
+ grabGesture(Qt::SwipeGesture);
+ grabGesture(Qt::PanGesture);
#endif
- setWindowTitle(priv->window_title);
- }
+ setWindowTitle(priv->window_title);
+ }
#endif
- is_overlay=overlay;
- gra=priv;
+ is_overlay=overlay;
+ gra=priv;
#ifdef QT_QPAINTER_USE_EVENT_QT
- timer_type=g_hash_table_new(NULL, NULL);
- timer_callback=g_hash_table_new(NULL, NULL);
- watches=g_hash_table_new(NULL, NULL);
+ timer_type=g_hash_table_new(NULL, NULL);
+ timer_callback=g_hash_table_new(NULL, NULL);
+ watches=g_hash_table_new(NULL, NULL);
#ifndef QT_QPAINTER_NO_WIDGET
- setAttribute(Qt::WA_OpaquePaintEvent, true);
+ setAttribute(Qt::WA_OpaquePaintEvent, true);
#endif
#endif
}
@@ -73,33 +71,29 @@ RenderArea::RenderArea(struct graphics_priv *priv, QT_QPAINTER_RENDERAREA_PARENT
//# Description: QWidget:closeEvent
//# Comment: Deletes navit object and stops event loop on graphics shutdown
//##############################################################################################################
-void RenderArea::processClose()
-{
- callback_list_call_attr_0(this->cbl, attr_window_closed);
+void RenderArea::processClose() {
+ callback_list_call_attr_0(this->cbl, attr_window_closed);
}
-void RenderArea::closeEvent(QCloseEvent* event)
-{
- this->processClose();
+void RenderArea::closeEvent(QCloseEvent* event) {
+ this->processClose();
}
-bool RenderArea::event(QEvent *event)
-{
-#if QT_VERSION >= 0x040700
- if (event->type() == QEvent::Gesture) {
- dbg(lvl_debug,"gesture");
- return true;
- }
+bool RenderArea::event(QEvent *event) {
+#if QT_VERSION >= 0x040700
+ if (event->type() == QEvent::Gesture) {
+ dbg(lvl_debug,"gesture");
+ return true;
+ }
#endif
- return QWidget::event(event);
+ return QWidget::event(event);
}
//##############################################################################################################
//# Description: QWidget:sizeHint
//# Comment: This property holds the recommended size for the widget
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-QSize RenderArea::sizeHint() const
-{
- return QSize(gra->w, gra->h);
+QSize RenderArea::sizeHint() const {
+ return QSize(gra->w, gra->h);
}
//##############################################################################################################
@@ -107,25 +101,23 @@ QSize RenderArea::sizeHint() const
//# Comment: A paint event is a request to repaint all or part of the widget.
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-void RenderArea::paintEvent(QPaintEvent * event)
-{
- qt_qpainter_draw(gra, &event->rect(), 1);
+void RenderArea::paintEvent(QPaintEvent * event) {
+ qt_qpainter_draw(gra, &event->rect(), 1);
}
-void RenderArea::do_resize(QSize size)
-{
+void RenderArea::do_resize(QSize size) {
if (pixmap->paintingActive()) {
pixmap->paintEngine()->painter()->end();
}
- delete pixmap;
- pixmap=new QPixmap(size);
- pixmap->fill();
+ delete pixmap;
+ pixmap=new QPixmap(size);
+ pixmap->fill();
QPainter painter(pixmap);
QBrush brush;
- painter.fillRect(0, 0, size.width(), size.height(), brush);
- dbg(lvl_debug,"size %dx%d", size.width(), size.height());
- dbg(lvl_debug,"pixmap %p %dx%d", pixmap, pixmap->width(), pixmap->height());
- callback_list_call_attr_2(this->cbl, attr_resize, GINT_TO_POINTER(size.width()), GINT_TO_POINTER(size.height()));
+ painter.fillRect(0, 0, size.width(), size.height(), brush);
+ dbg(lvl_debug,"size %dx%d", size.width(), size.height());
+ dbg(lvl_debug,"pixmap %p %dx%d", pixmap, pixmap->width(), pixmap->height());
+ callback_list_call_attr_2(this->cbl, attr_resize, GINT_TO_POINTER(size.width()), GINT_TO_POINTER(size.height()));
}
//##############################################################################################################
@@ -133,11 +125,10 @@ void RenderArea::do_resize(QSize size)
//# Comment: When resizeEvent() is called, the widget already has its new geometry.
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-void RenderArea::resizeEvent(QResizeEvent * event)
-{
- if (!this->is_overlay) {
- RenderArea::do_resize(event->size());
- }
+void RenderArea::resizeEvent(QResizeEvent * event) {
+ if (!this->is_overlay) {
+ RenderArea::do_resize(event->size());
+ }
}
//##############################################################################################################
@@ -145,34 +136,31 @@ void RenderArea::resizeEvent(QResizeEvent * event)
//# Comment: Delegate of QWidget::mousePressEvent and QWidget::mouseReleaseEvent (see below)
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-void RenderArea::mouseEvent(int pressed, QMouseEvent *event)
-{
- struct point p;
- p.x=event->x();
- p.y=event->y();
- switch (event->button()) {
- case Qt::LeftButton:
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1), GINT_TO_POINTER(&p));
- break;
- case Qt::MidButton:
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2), GINT_TO_POINTER(&p));
- break;
- case Qt::RightButton:
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3), GINT_TO_POINTER(&p));
- break;
- default:
- break;
- }
+void RenderArea::mouseEvent(int pressed, QMouseEvent *event) {
+ struct point p;
+ p.x=event->x();
+ p.y=event->y();
+ switch (event->button()) {
+ case Qt::LeftButton:
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1), GINT_TO_POINTER(&p));
+ break;
+ case Qt::MidButton:
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2), GINT_TO_POINTER(&p));
+ break;
+ case Qt::RightButton:
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3), GINT_TO_POINTER(&p));
+ break;
+ default:
+ break;
+ }
}
-void RenderArea::mousePressEvent(QMouseEvent *event)
-{
- mouseEvent(1, event);
+void RenderArea::mousePressEvent(QMouseEvent *event) {
+ mouseEvent(1, event);
}
-void RenderArea::mouseReleaseEvent(QMouseEvent *event)
-{
- mouseEvent(0, event);
+void RenderArea::mouseReleaseEvent(QMouseEvent *event) {
+ mouseEvent(0, event);
}
//##############################################################################################################
@@ -180,12 +168,11 @@ void RenderArea::mouseReleaseEvent(QMouseEvent *event)
//# Comment: If mouse tracking is switched on, mouse move events occur even if no mouse button is pressed.
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-void RenderArea::mouseMoveEvent(QMouseEvent *event)
-{
- struct point p;
- p.x=event->x();
- p.y=event->y();
- callback_list_call_attr_1(this->cbl, attr_motion, (void *)&p);
+void RenderArea::mouseMoveEvent(QMouseEvent *event) {
+ struct point p;
+ p.x=event->x();
+ p.y=event->y();
+ callback_list_call_attr_1(this->cbl, attr_motion, (void *)&p);
}
@@ -194,114 +181,109 @@ void RenderArea::mouseMoveEvent(QMouseEvent *event)
//# Comment:
//# Authors: Stefan Klumpp (04/2008)
//##############################################################################################################
-void RenderArea::wheelEvent(QWheelEvent *event)
-{
- struct point p;
- int button;
-
- p.x=event->x(); // xy-coordinates of the mouse pointer
- p.y=event->y();
-
- if (event->delta() > 0) // wheel movement away from the person
- button=4;
- else if (event->delta() < 0) // wheel movement towards the person
- button=5;
- else
- button=-1;
-
- if (button != -1) {
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
- callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
- }
-
- event->accept();
+void RenderArea::wheelEvent(QWheelEvent *event) {
+ struct point p;
+ int button;
+
+ p.x=event->x(); // xy-coordinates of the mouse pointer
+ p.y=event->y();
+
+ if (event->delta() > 0) // wheel movement away from the person
+ button=4;
+ else if (event->delta() < 0) // wheel movement towards the person
+ button=5;
+ else
+ button=-1;
+
+ if (button != -1) {
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
+ callback_list_call_attr_3(this->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), GINT_TO_POINTER(&p));
+ }
+
+ event->accept();
}
#define CASE(x) case x:
-void RenderArea::keyPressEvent(QKeyEvent *event)
-{
- QString str=event->text();
- const char *text=str.toUtf8().constData();
- dbg(lvl_debug,"enter text='%s' 0x%x (%zu) key=%d", text, text[0], strlen(text), event->key());
- if (!text || !text[0] || text[0] == 0x7f) {
- dbg(lvl_debug,"special key");
- switch (event->key()) {
- case 4099:
- {
- char text_backspace[] = {NAVIT_KEY_BACKSPACE,'\0'};
- text=text_backspace;
- }
- break;
- case 4101:
+void RenderArea::keyPressEvent(QKeyEvent *event) {
+ QString str=event->text();
+ const char *text=str.toUtf8().constData();
+ dbg(lvl_debug,"enter text='%s' 0x%x (%zu) key=%d", text, text[0], strlen(text), event->key());
+ if (!text || !text[0] || text[0] == 0x7f) {
+ dbg(lvl_debug,"special key");
+ switch (event->key()) {
+ case 4099: {
+ char text_backspace[] = {NAVIT_KEY_BACKSPACE,'\0'};
+ text=text_backspace;
+ }
+ break;
+ case 4101:
#ifdef QT_QPAINTER_CUSTOM_RETURN
- QT_QPAINTER_CUSTOM_RETURN
+ QT_QPAINTER_CUSTOM_RETURN
#endif
- {
- char text_return[] = {NAVIT_KEY_RETURN,'\0'};
- text=text_return;
- }
- break;
- case 4114:
+ {
+ char text_return[] = {NAVIT_KEY_RETURN,'\0'};
+ text=text_return;
+ }
+ break;
+ case 4114:
#ifdef QT_QPAINTER_CUSTOM_LEFT
- QT_QPAINTER_CUSTOM_LEFT
+ QT_QPAINTER_CUSTOM_LEFT
#endif
- {
- char text_left[] = {NAVIT_KEY_LEFT,'\0'};
- text=text_left;
- }
- break;
- case 4115:
+ {
+ char text_left[] = {NAVIT_KEY_LEFT,'\0'};
+ text=text_left;
+ }
+ break;
+ case 4115:
#ifdef QT_QPAINTER_CUSTOM_UP
- QT_QPAINTER_CUSTOM_UP
+ QT_QPAINTER_CUSTOM_UP
#endif
- {
- char text_up[] = {NAVIT_KEY_UP,'\0'};
- text=text_up;
- }
- break;
- case 4116:
+ {
+ char text_up[] = {NAVIT_KEY_UP,'\0'};
+ text=text_up;
+ }
+ break;
+ case 4116:
#ifdef QT_QPAINTER_CUSTOM_RIGHT
- QT_QPAINTER_CUSTOM_RIGHT
+ QT_QPAINTER_CUSTOM_RIGHT
#endif
- {
- char text_right[] = {NAVIT_KEY_RIGHT,'\0'};
- text=text_right;
- }
- break;
- case 4117:
+ {
+ char text_right[] = {NAVIT_KEY_RIGHT,'\0'};
+ text=text_right;
+ }
+ break;
+ case 4117:
#ifdef QT_QPAINTER_CUSTOM_DOWN
- QT_QPAINTER_CUSTOM_DOWN
+ QT_QPAINTER_CUSTOM_DOWN
#endif
- {
- char text_down[] = {NAVIT_KEY_DOWN,'\0'};
- text=text_down;
- }
- break;
- }
- }
- callback_list_call_attr_1(this->cbl, attr_keypress, (void *)text);
- event->accept();
+ {
+ char text_down[] = {NAVIT_KEY_DOWN,'\0'};
+ text=text_down;
+ }
+ break;
+ }
+ }
+ callback_list_call_attr_1(this->cbl, attr_keypress, (void *)text);
+ event->accept();
}
-void RenderArea::watchEvent(int fd)
-{
+void RenderArea::watchEvent(int fd) {
#ifdef QT_QPAINTER_USE_EVENT_QT
- struct event_watch *ev=(struct event_watch *)g_hash_table_lookup(watches, (void *)fd);
- dbg(lvl_debug,"fd=%d ev=%p cb=%p", fd, ev, ev->cb);
- callback_call_0(ev->cb);
+ struct event_watch *ev=(struct event_watch *)g_hash_table_lookup(watches, (void *)fd);
+ dbg(lvl_debug,"fd=%d ev=%p cb=%p", fd, ev, ev->cb);
+ callback_call_0(ev->cb);
#endif
}
#ifdef QT_QPAINTER_USE_EVENT_QT
-void RenderArea::timerEvent(QTimerEvent *event)
-{
- int id=event->timerId();
- struct callback *cb=(struct callback *)g_hash_table_lookup(timer_callback, (void *)id);
- if (cb)
- callback_call_0(cb);
- if (!g_hash_table_lookup(timer_type, (void *)id))
- event_qt_remove_timeout((struct event_timeout *)id);
+void RenderArea::timerEvent(QTimerEvent *event) {
+ int id=event->timerId();
+ struct callback *cb=(struct callback *)g_hash_table_lookup(timer_callback, (void *)id);
+ if (cb)
+ callback_call_0(cb);
+ if (!g_hash_table_lookup(timer_type, (void *)id))
+ event_qt_remove_timeout((struct event_timeout *)id);
}
#endif /* QT_QPAINTER_USE_EVENT_QT */
diff --git a/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp b/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp
index 4fd4f46f6..7f90aa9d4 100644
--- a/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp
+++ b/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp
@@ -21,7 +21,7 @@
//#
//# File: graphics_qt_qpainter.cpp
//# Description: Graphics interface for internal GUI using Qt (Trolltech.com)
-//# Comment:
+//# Comment:
//# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
//#
//##############################################################################################################
@@ -31,84 +31,82 @@
#include "RenderArea.h"
//##############################################################################################################
-//# Description: RenderArea (QWidget) class for the main window (map, menu, ...)
-//# Comment:
+//# Description: RenderArea (QWidget) class for the main window (map, menu, ...)
+//# Comment:
//# Authors: Martin Schaller (04/2008), Stefan Klumpp (04/2008)
//##############################################################################################################
static void
-overlay_rect(struct graphics_priv *parent, struct graphics_priv *overlay, int clean, QRect *r)
-{
- struct point p;
- int w,h;
- if (clean) {
- p=overlay->pclean;
- } else {
- p=overlay->p;;
- }
- w=overlay->widget->pixmap->width();
- h=overlay->widget->pixmap->height();
- if (overlay->wraparound) {
- if (p.x < 0)
- p.x+=parent->widget->pixmap->width();
- if (p.y < 0)
- p.y+=parent->widget->pixmap->height();
- if (w < 0)
- w += parent->widget->pixmap->width();
- if (h < 0)
- h += parent->widget->pixmap->height();
- }
- r->setRect(p.x, p.y, w, h);
+overlay_rect(struct graphics_priv *parent, struct graphics_priv *overlay, int clean, QRect *r) {
+ struct point p;
+ int w,h;
+ if (clean) {
+ p=overlay->pclean;
+ } else {
+ p=overlay->p;;
+ }
+ w=overlay->widget->pixmap->width();
+ h=overlay->widget->pixmap->height();
+ if (overlay->wraparound) {
+ if (p.x < 0)
+ p.x+=parent->widget->pixmap->width();
+ if (p.y < 0)
+ p.y+=parent->widget->pixmap->height();
+ if (w < 0)
+ w += parent->widget->pixmap->width();
+ if (h < 0)
+ h += parent->widget->pixmap->height();
+ }
+ r->setRect(p.x, p.y, w, h);
}
void
-qt_qpainter_draw(struct graphics_priv *gr, const QRect *r, int paintev)
-{
- if (!paintev) {
+qt_qpainter_draw(struct graphics_priv *gr, const QRect *r, int paintev) {
+ if (!paintev) {
#ifndef QT_QPAINTER_NO_WIDGET
- dbg(lvl_debug,"update %d,%d %d x %d", r->x(), r->y(), r->width(), r->height());
- if (r->x() <= -r->width())
- return;
- if (r->y() <= -r->height())
- return;
- if (r->x() > gr->widget->pixmap->width())
- return;
- if (r->y() > gr->widget->pixmap->height())
- return;
- dbg(lvl_debug,"update valid %d,%d %dx%d", r->x(), r->y(), r->width(), r->height());
- gr->widget->update(*r);
+ dbg(lvl_debug,"update %d,%d %d x %d", r->x(), r->y(), r->width(), r->height());
+ if (r->x() <= -r->width())
+ return;
+ if (r->y() <= -r->height())
+ return;
+ if (r->x() > gr->widget->pixmap->width())
+ return;
+ if (r->y() > gr->widget->pixmap->height())
+ return;
+ dbg(lvl_debug,"update valid %d,%d %dx%d", r->x(), r->y(), r->width(), r->height());
+ gr->widget->update(*r);
#endif
- return;
- }
- QPixmap pixmap(r->width(),r->height());
- QPainter painter(&pixmap);
- struct graphics_priv *overlay=NULL;
- if (! gr->overlay_disable)
- overlay=gr->overlays;
- if ((gr->p.x || gr->p.y) && gr->background_gc) {
- painter.setPen(*gr->background_gc->pen);
- painter.fillRect(0, 0, gr->widget->pixmap->width(), gr->widget->pixmap->height(), *gr->background_gc->brush);
- }
- painter.drawPixmap(QPoint(gr->p.x,gr->p.y), *gr->widget->pixmap, *r);
- while (overlay) {
- QRect ovr;
- overlay_rect(gr, overlay, 0, &ovr);
- if (!overlay->overlay_disable && r->intersects(ovr)) {
- unsigned char *data;
- int i,size=ovr.width()*ovr.height();
- QImage img=overlay->widget->pixmap->toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied);
- data=img.bits();
- for (i = 0 ; i < size ; i++) {
- if (data[0] == overlay->rgba[0] && data[1] == overlay->rgba[1] && data[2] == overlay->rgba[2])
- data[3]=overlay->rgba[3];
- data+=4;
- }
- painter.drawImage(QPoint(ovr.x()-r->x(),ovr.y()-r->y()), img);
- }
- overlay=overlay->next;
- }
+ return;
+ }
+ QPixmap pixmap(r->width(),r->height());
+ QPainter painter(&pixmap);
+ struct graphics_priv *overlay=NULL;
+ if (! gr->overlay_disable)
+ overlay=gr->overlays;
+ if ((gr->p.x || gr->p.y) && gr->background_gc) {
+ painter.setPen(*gr->background_gc->pen);
+ painter.fillRect(0, 0, gr->widget->pixmap->width(), gr->widget->pixmap->height(), *gr->background_gc->brush);
+ }
+ painter.drawPixmap(QPoint(gr->p.x,gr->p.y), *gr->widget->pixmap, *r);
+ while (overlay) {
+ QRect ovr;
+ overlay_rect(gr, overlay, 0, &ovr);
+ if (!overlay->overlay_disable && r->intersects(ovr)) {
+ unsigned char *data;
+ int i,size=ovr.width()*ovr.height();
+ QImage img=overlay->widget->pixmap->toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied);
+ data=img.bits();
+ for (i = 0 ; i < size ; i++) {
+ if (data[0] == overlay->rgba[0] && data[1] == overlay->rgba[1] && data[2] == overlay->rgba[2])
+ data[3]=overlay->rgba[3];
+ data+=4;
+ }
+ painter.drawImage(QPoint(ovr.x()-r->x(),ovr.y()-r->y()), img);
+ }
+ overlay=overlay->next;
+ }
#ifndef QT_QPAINTER_NO_WIDGET
- QPainter painterw(gr->widget);
- painterw.drawPixmap(r->x(), r->y(), pixmap);
+ QPainter painterw(gr->widget);
+ painterw.drawPixmap(r->x(), r->y(), pixmap);
#endif
}
@@ -120,614 +118,597 @@ qt_qpainter_draw(struct graphics_priv *gr, const QRect *r, int paintev)
//##############################################################################################################
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
struct graphics_font_priv {
- QFont *font;
+ QFont *font;
};
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
struct graphics_image_priv {
- QPixmap *pixmap;
+ QPixmap *pixmap;
};
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void graphics_destroy(struct graphics_priv *gr)
-{
+static void graphics_destroy(struct graphics_priv *gr) {
#ifdef QT_QPAINTER_USE_FREETYPE
- gr->freetype_methods.destroy();
+ gr->freetype_methods.destroy();
#endif
- g_free(gr->window_title);
- g_free(gr);
+ g_free(gr->window_title);
+ g_free(gr);
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void font_destroy(struct graphics_font_priv *font)
-{
+static void font_destroy(struct graphics_font_priv *font) {
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
static struct graphics_font_methods font_methods = {
- font_destroy
+ font_destroy
};
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth, char *fontfamily, int size, int flags)
-{
- struct graphics_font_priv *ret=g_new0(struct graphics_font_priv, 1);
- ret->font=new QFont("Arial",size/20);
- *meth=font_methods;
- return ret;
+static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth,
+ char *fontfamily, int size, int flags) {
+ struct graphics_font_priv *ret=g_new0(struct graphics_font_priv, 1);
+ ret->font=new QFont("Arial",size/20);
+ *meth=font_methods;
+ return ret;
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void gc_destroy(struct graphics_gc_priv *gc)
-{
- delete gc->pen;
- delete gc->brush;
- g_free(gc);
+static void gc_destroy(struct graphics_gc_priv *gc) {
+ delete gc->pen;
+ delete gc->brush;
+ g_free(gc);
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void gc_set_linewidth(struct graphics_gc_priv *gc, int w)
-{
- gc->pen->setWidth(w);
+static void gc_set_linewidth(struct graphics_gc_priv *gc, int w) {
+ gc->pen->setWidth(w);
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n)
-{
+static void gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n) {
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
-{
- QColor col(c->r >> 8, c->g >> 8, c->b >> 8 /* , c->a >> 8 */);
- gc->pen->setColor(col);
- gc->brush->setColor(col);
- gc->c=*c;
+static void gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) {
+ QColor col(c->r >> 8, c->g >> 8, c->b >> 8 /* , c->a >> 8 */);
+ gc->pen->setColor(col);
+ gc->brush->setColor(col);
+ gc->c=*c;
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void gc_set_background(struct graphics_gc_priv *gc, struct color *c)
-{
+static void gc_set_background(struct graphics_gc_priv *gc, struct color *c) {
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
static struct graphics_gc_methods gc_methods = {
- gc_destroy,
- gc_set_linewidth,
- gc_set_dashes,
- gc_set_foreground,
- gc_set_background
+ gc_destroy,
+ gc_set_linewidth,
+ gc_set_dashes,
+ gc_set_foreground,
+ gc_set_background
};
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
-{
- *meth=gc_methods;
- struct graphics_gc_priv *ret=g_new0(struct graphics_gc_priv, 1);
- ret->pen=new QPen();
- ret->brush=new QBrush(Qt::SolidPattern);
- return ret;
+static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
+ *meth=gc_methods;
+ struct graphics_gc_priv *ret=g_new0(struct graphics_gc_priv, 1);
+ ret->pen=new QPen();
+ ret->brush=new QBrush(Qt::SolidPattern);
+ return ret;
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static struct graphics_image_priv * image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *path, int *w, int *h, struct point *hot, int rotation)
-{
- struct graphics_image_priv *ret;
- QPixmap *cachedPixmap;
- QString key(path);
+static struct graphics_image_priv * image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *path,
+ int *w, int *h, struct point *hot, int rotation) {
+ struct graphics_image_priv *ret;
+ QPixmap *cachedPixmap;
+ QString key(path);
- ret=g_new0(struct graphics_image_priv, 1);
+ ret=g_new0(struct graphics_image_priv, 1);
- cachedPixmap=QPixmapCache::find(key);
- if (!cachedPixmap) {
+ cachedPixmap=QPixmapCache::find(key);
+ if (!cachedPixmap) {
#ifdef HAVE_QT_SVG
- if(key.endsWith(".svg", Qt::CaseInsensitive)) {
- QSvgRenderer renderer(key);
- if (!renderer.isValid()) {
- g_free(ret);
- return NULL;
- }
- ret->pixmap=new QPixmap(renderer.defaultSize());
- ret->pixmap->fill(Qt::transparent);
- QPainter painter(ret->pixmap);
- renderer.render(&painter);
-
- } else {
-
- ret->pixmap=new QPixmap(path);
-
- }
-#else
- ret->pixmap=new QPixmap(path);
+ if(key.endsWith(".svg", Qt::CaseInsensitive)) {
+ QSvgRenderer renderer(key);
+ if (!renderer.isValid()) {
+ g_free(ret);
+ return NULL;
+ }
+ ret->pixmap=new QPixmap(renderer.defaultSize());
+ ret->pixmap->fill(Qt::transparent);
+ QPainter painter(ret->pixmap);
+ renderer.render(&painter);
+
+ } else {
+
+ ret->pixmap=new QPixmap(path);
+
+ }
+#else
+ ret->pixmap=new QPixmap(path);
#endif /* QT__VERSION */
- if (ret->pixmap->isNull()) {
- g_free(ret);
- return NULL;
- }
-
- QPixmapCache::insert(key,QPixmap(*ret->pixmap));
- } else {
- ret->pixmap=new QPixmap(*cachedPixmap);
- }
+ if (ret->pixmap->isNull()) {
+ g_free(ret);
+ return NULL;
+ }
+
+ QPixmapCache::insert(key,QPixmap(*ret->pixmap));
+ } else {
+ ret->pixmap=new QPixmap(*cachedPixmap);
+ }
- *w=ret->pixmap->width();
- *h=ret->pixmap->height();
- if (hot) {
- hot->x=*w/2;
- hot->y=*h/2;
- }
+ *w=ret->pixmap->width();
+ *h=ret->pixmap->height();
+ if (hot) {
+ hot->x=*w/2;
+ hot->y=*h/2;
+ }
- return ret;
+ return ret;
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
- int i;
- QPolygon polygon;
+static void draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
+ int i;
+ QPolygon polygon;
- for (i = 0 ; i < count ; i++)
- polygon.putPoints(i, 1, p[i].x, p[i].y);
- gr->painter->setPen(*gc->pen);
- gr->painter->drawPolyline(polygon);
+ for (i = 0 ; i < count ; i++)
+ polygon.putPoints(i, 1, p[i].x, p[i].y);
+ gr->painter->setPen(*gc->pen);
+ gr->painter->drawPolyline(polygon);
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
- int i;
- QPolygon polygon;
+static void draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
+ int i;
+ QPolygon polygon;
- for (i = 0 ; i < count ; i++)
- polygon.putPoints(i, 1, p[i].x, p[i].y);
- gr->painter->setPen(*gc->pen);
- gr->painter->setBrush(*gc->brush);
- gr->painter->drawPolygon(polygon);
+ for (i = 0 ; i < count ; i++)
+ polygon.putPoints(i, 1, p[i].x, p[i].y);
+ gr->painter->setPen(*gc->pen);
+ gr->painter->setBrush(*gc->brush);
+ gr->painter->drawPolygon(polygon);
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h)
-{
- dbg(lvl_debug,"gr=%p gc=%p %d,%d,%d,%d", gr, gc, p->x, p->y, w, h);
- gr->painter->fillRect(p->x,p->y, w, h, *gc->brush);
+static void draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h) {
+ dbg(lvl_debug,"gr=%p gc=%p %d,%d,%d,%d", gr, gc, p->x, p->y, w, h);
+ gr->painter->fillRect(p->x,p->y, w, h, *gc->brush);
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r)
-{
- gr->painter->setPen(*gc->pen);
- gr->painter->drawArc(p->x-r/2, p->y-r/2, r, r, 0, 360*16);
-
+static void draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r) {
+ gr->painter->setPen(*gc->pen);
+ gr->painter->drawArc(p->x-r/2, p->y-r/2, r, r, 0, 360*16);
+
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy)
-{
- QPainter *painter=gr->painter;
+static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg,
+ struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy) {
+ QPainter *painter=gr->painter;
#ifndef QT_QPAINTER_USE_FREETYPE
- QString tmp=QString::fromUtf8(text);
+ QString tmp=QString::fromUtf8(text);
#ifndef QT_NO_TRANSFORMATIONS
- QMatrix sav=gr->painter->worldMatrix();
- QMatrix m(dx/65535.0,dy/65535.0,-dy/65535.0,dx/65535.0,p->x,p->y);
- painter->setWorldMatrix(m,TRUE);
- painter->setPen(*fg->pen);
- painter->setFont(*font->font);
- painter->drawText(0, 0, tmp);
- painter->setWorldMatrix(sav);
+ QMatrix sav=gr->painter->worldMatrix();
+ QMatrix m(dx/65535.0,dy/65535.0,-dy/65535.0,dx/65535.0,p->x,p->y);
+ painter->setWorldMatrix(m,TRUE);
+ painter->setPen(*fg->pen);
+ painter->setFont(*font->font);
+ painter->drawText(0, 0, tmp);
+ painter->setWorldMatrix(sav);
#else
- painter->setPen(*fg->pen);
- painter->setFont(*font->font);
- painter->drawText(p->x, p->y, tmp);
+ painter->setPen(*fg->pen);
+ painter->setFont(*font->font);
+ painter->drawText(p->x, p->y, tmp);
#endif
#else
- struct font_freetype_text *t;
- struct font_freetype_glyph *g, **gp;
- struct color transparent = {0x0000, 0x0000, 0x0000, 0x0000};
- struct color *fgc=&fg->c, *bgc=&bg->c;
-
- int i,x,y;
-
- if (! font)
- return;
- t=gr->freetype_methods.text_new(text, (struct font_freetype_font *)font, dx, dy);
- x=p->x << 6;
- y=p->y << 6;
- gp=t->glyph;
- i=t->glyph_count;
- if (bg) {
- while (i-- > 0) {
- g=*gp++;
- if (g->w && g->h) {
- unsigned char *data;
- QImage img(g->w+2, g->h+2, QImage::Format_ARGB32_Premultiplied);
- data=img.bits();
- gr->freetype_methods.get_shadow(g,(unsigned char *)data,img.bytesPerLine(),bgc,&transparent);
-
- painter->drawImage(((x+g->x)>>6)-1, ((y+g->y)>>6)-1, img);
- }
- x+=g->dx;
- y+=g->dy;
- }
- } else
- bgc=&transparent;
- x=p->x << 6;
- y=p->y << 6;
- gp=t->glyph;
- i=t->glyph_count;
- while (i-- > 0) {
- g=*gp++;
- if (g->w && g->h) {
- unsigned char *data;
- QImage img(g->w, g->h, QImage::Format_ARGB32_Premultiplied);
- data=img.bits();
- gr->freetype_methods.get_glyph(g,(unsigned char *)data,img.bytesPerLine(),fgc,bgc,&transparent);
- painter->drawImage((x+g->x)>>6, (y+g->y)>>6, img);
- }
- x+=g->dx;
- y+=g->dy;
- }
- gr->freetype_methods.text_destroy(t);
+ struct font_freetype_text *t;
+ struct font_freetype_glyph *g, **gp;
+ struct color transparent = {0x0000, 0x0000, 0x0000, 0x0000};
+ struct color *fgc=&fg->c, *bgc=&bg->c;
+
+ int i,x,y;
+
+ if (! font)
+ return;
+ t=gr->freetype_methods.text_new(text, (struct font_freetype_font *)font, dx, dy);
+ x=p->x << 6;
+ y=p->y << 6;
+ gp=t->glyph;
+ i=t->glyph_count;
+ if (bg) {
+ while (i-- > 0) {
+ g=*gp++;
+ if (g->w && g->h) {
+ unsigned char *data;
+ QImage img(g->w+2, g->h+2, QImage::Format_ARGB32_Premultiplied);
+ data=img.bits();
+ gr->freetype_methods.get_shadow(g,(unsigned char *)data,img.bytesPerLine(),bgc,&transparent);
+
+ painter->drawImage(((x+g->x)>>6)-1, ((y+g->y)>>6)-1, img);
+ }
+ x+=g->dx;
+ y+=g->dy;
+ }
+ } else
+ bgc=&transparent;
+ x=p->x << 6;
+ y=p->y << 6;
+ gp=t->glyph;
+ i=t->glyph_count;
+ while (i-- > 0) {
+ g=*gp++;
+ if (g->w && g->h) {
+ unsigned char *data;
+ QImage img(g->w, g->h, QImage::Format_ARGB32_Premultiplied);
+ data=img.bits();
+ gr->freetype_methods.get_glyph(g,(unsigned char *)data,img.bytesPerLine(),fgc,bgc,&transparent);
+ painter->drawImage((x+g->x)>>6, (y+g->y)>>6, img);
+ }
+ x+=g->dx;
+ y+=g->dy;
+ }
+ gr->freetype_methods.text_destroy(t);
#endif
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img)
-{
- gr->painter->drawPixmap(p->x, p->y, *img->pixmap);
+static void draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p,
+ struct graphics_image_priv *img) {
+ gr->painter->drawPixmap(p->x, p->y, *img->pixmap);
}
static void
-draw_drag(struct graphics_priv *gr, struct point *p)
-{
- if (!gr->cleanup) {
- gr->pclean=gr->p;
- gr->cleanup=1;
- }
- if (p)
- gr->p=*p;
- else {
- gr->p.x=0;
- gr->p.y=0;
- }
-}
-
-//##############################################################################################################
-//# Description:
-//# Comment:
+draw_drag(struct graphics_priv *gr, struct point *p) {
+ if (!gr->cleanup) {
+ gr->pclean=gr->p;
+ gr->cleanup=1;
+ }
+ if (p)
+ gr->p=*p;
+ else {
+ gr->p.x=0;
+ gr->p.y=0;
+ }
+}
+
+//##############################################################################################################
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
- gr->background_gc=gc;
- gr->rgba[2]=gc->c.r >> 8;
- gr->rgba[1]=gc->c.g >> 8;
- gr->rgba[0]=gc->c.b >> 8;
- gr->rgba[3]=gc->c.a >> 8;
+static void background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
+ gr->background_gc=gc;
+ gr->rgba[2]=gc->c.r >> 8;
+ gr->rgba[1]=gc->c.g >> 8;
+ gr->rgba[0]=gc->c.b >> 8;
+ gr->rgba[3]=gc->c.a >> 8;
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
-{
- dbg(lvl_debug,"mode for %p %d", gr, mode);
- QRect r;
- if (mode == draw_mode_begin) {
- if (gr->widget->pixmap->paintingActive()) {
- gr->widget->pixmap->paintEngine()->painter()->end();
- }
- gr->painter->begin(gr->widget->pixmap);
- }
- if (mode == draw_mode_end) {
- gr->painter->end();
- if (gr->parent) {
- if (gr->cleanup) {
- overlay_rect(gr->parent, gr, 1, &r);
- qt_qpainter_draw(gr->parent, &r, 0);
- gr->cleanup=0;
- }
- overlay_rect(gr->parent, gr, 0, &r);
- qt_qpainter_draw(gr->parent, &r, 0);
- } else {
- r.setRect(0, 0, gr->widget->pixmap->width(), gr->widget->pixmap->height());
- qt_qpainter_draw(gr, &r, 0);
- }
- if (!gr->parent)
- QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents|QEventLoop::ExcludeSocketNotifiers|QEventLoop::DeferredDeletion|QEventLoop::X11ExcludeTimers);
- }
- gr->mode=mode;
-}
-
-//##############################################################################################################
-//# Description:
-//# Comment:
+static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
+ dbg(lvl_debug,"mode for %p %d", gr, mode);
+ QRect r;
+ if (mode == draw_mode_begin) {
+ if (gr->widget->pixmap->paintingActive()) {
+ gr->widget->pixmap->paintEngine()->painter()->end();
+ }
+ gr->painter->begin(gr->widget->pixmap);
+ }
+ if (mode == draw_mode_end) {
+ gr->painter->end();
+ if (gr->parent) {
+ if (gr->cleanup) {
+ overlay_rect(gr->parent, gr, 1, &r);
+ qt_qpainter_draw(gr->parent, &r, 0);
+ gr->cleanup=0;
+ }
+ overlay_rect(gr->parent, gr, 0, &r);
+ qt_qpainter_draw(gr->parent, &r, 0);
+ } else {
+ r.setRect(0, 0, gr->widget->pixmap->width(), gr->widget->pixmap->height());
+ qt_qpainter_draw(gr, &r, 0);
+ }
+ if (!gr->parent)
+ QCoreApplication::processEvents(
+ QEventLoop::ExcludeUserInputEvents|QEventLoop::ExcludeSocketNotifiers|QEventLoop::DeferredDeletion|QEventLoop::X11ExcludeTimers);
+ }
+ gr->mode=mode;
+}
+
+//##############################################################################################################
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h,int wraparound);
+static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p,
+ int w, int h,int wraparound);
static int argc=1;
-static char *argv[]={NULL,NULL,NULL};
+static char *argv[]= {NULL,NULL,NULL};
static int
-fullscreen(struct window *win, int on)
-{
+fullscreen(struct window *win, int on) {
#ifndef QT_QPAINTER_NO_WIDGET
- struct graphics_priv *this_=(struct graphics_priv *)win->priv;
- QWidget* _outerWidget;
+ struct graphics_priv *this_=(struct graphics_priv *)win->priv;
+ QWidget* _outerWidget;
#ifdef QT_QPAINTER_USE_EMBEDDING
- _outerWidget=(QWidget*)this_->widget->parent();
+ _outerWidget=(QWidget*)this_->widget->parent();
#else
- _outerWidget=this_->widget;
+ _outerWidget=this_->widget;
#endif /* QT_QPAINTER_USE_EMBEDDING */
- if (on)
- _outerWidget->showFullScreen();
- else
- _outerWidget->showMaximized();
+ if (on)
+ _outerWidget->showFullScreen();
+ else
+ _outerWidget->showMaximized();
#endif
- return 1;
+ return 1;
}
static void
-disable_suspend(struct window *win)
-{
+disable_suspend(struct window *win) {
#ifdef HAVE_QPE
- struct graphics_priv *this_=(struct graphics_priv *)win->priv;
- this_->app->setTempScreenSaverMode(QPEApplication::DisableLightOff);
+ struct graphics_priv *this_=(struct graphics_priv *)win->priv;
+ this_->app->setTempScreenSaverMode(QPEApplication::DisableLightOff);
#endif
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void * get_data(struct graphics_priv *this_, const char *type)
-{
- struct window *win;
- QString xid;
- bool ok;
-
- if (!strcmp(type, "resize")) {
- dbg(lvl_debug,"resize %d %d",this_->w,this_->h);
- QSize size(this_->w,this_->h);
- this_->widget->do_resize(size);
- }
- if (!strcmp(type, "qt_widget"))
- return this_->widget;
- if (!strcmp(type, "qt_pixmap"))
- return this_->widget->pixmap;
- if (!strcmp(type, "window")) {
- win=g_new(struct window, 1);
+static void * get_data(struct graphics_priv *this_, const char *type) {
+ struct window *win;
+ QString xid;
+ bool ok;
+
+ if (!strcmp(type, "resize")) {
+ dbg(lvl_debug,"resize %d %d",this_->w,this_->h);
+ QSize size(this_->w,this_->h);
+ this_->widget->do_resize(size);
+ }
+ if (!strcmp(type, "qt_widget"))
+ return this_->widget;
+ if (!strcmp(type, "qt_pixmap"))
+ return this_->widget->pixmap;
+ if (!strcmp(type, "window")) {
+ win=g_new(struct window, 1);
#ifndef QT_QPAINTER_NO_WIDGET
#ifdef QT_QPAINTER_USE_EMBEDDING
- EmbeddedWidget* _outerWidget=new EmbeddedWidget(this_,this_->widget,NULL);
- xid=getenv("NAVIT_XID");
- if (xid.length()>0) {
- _outerWidget->embedInto(xid.toULong(&ok,0));
- }
- _outerWidget->show();
+ EmbeddedWidget* _outerWidget=new EmbeddedWidget(this_,this_->widget,NULL);
+ xid=getenv("NAVIT_XID");
+ if (xid.length()>0) {
+ _outerWidget->embedInto(xid.toULong(&ok,0));
+ }
+ _outerWidget->show();
#endif /* QT_QPAINTER_USE_EMBEDDING */
- if (this_->w && this_->h)
- this_->widget->show();
- else
- this_->widget->showMaximized();
+ if (this_->w && this_->h)
+ this_->widget->show();
+ else
+ this_->widget->showMaximized();
#endif /* QT_QPAINTER_NO_WIDGET */
- win->priv=this_;
- win->fullscreen=fullscreen;
- win->disable_suspend=disable_suspend;
- return win;
- }
- return NULL;
+ win->priv=this_;
+ win->fullscreen=fullscreen;
+ win->disable_suspend=disable_suspend;
+ return win;
+ }
+ return NULL;
}
static void
-image_free(struct graphics_priv *gr, struct graphics_image_priv *priv)
-{
- delete priv->pixmap;
- g_free(priv);
+image_free(struct graphics_priv *gr, struct graphics_image_priv *priv) {
+ delete priv->pixmap;
+ g_free(priv);
}
static void
-get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy, struct point *ret, int estimate)
-{
- QPainter *painter=gr->painter;
- QString tmp=QString::fromUtf8(text);
- painter->setFont(*font->font);
- QRect r=painter->boundingRect(0,0,gr->w,gr->h,0,tmp);
- ret[0].x=0;
- ret[0].y=-r.height();
- ret[1].x=0;
- ret[1].y=0;
- ret[2].x=r.width();
- ret[2].y=0;
- ret[3].x=r.width();
- ret[3].y=-r.height();
-}
-
-
-//##############################################################################################################
-//# Description:
-//# Comment:
+get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy, struct point *ret,
+ int estimate) {
+ QPainter *painter=gr->painter;
+ QString tmp=QString::fromUtf8(text);
+ painter->setFont(*font->font);
+ QRect r=painter->boundingRect(0,0,gr->w,gr->h,0,tmp);
+ ret[0].x=0;
+ ret[0].y=-r.height();
+ ret[1].x=0;
+ ret[1].y=0;
+ ret[2].x=r.width();
+ ret[2].y=0;
+ ret[3].x=r.width();
+ ret[3].y=-r.height();
+}
+
+
+//##############################################################################################################
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static void overlay_disable(struct graphics_priv *gr, int disable)
-{
- gr->overlay_disable=disable;
+static void overlay_disable(struct graphics_priv *gr, int disable) {
+ gr->overlay_disable=disable;
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static int set_attr(struct graphics_priv *gr, struct attr *attr)
-{
- switch (attr->type) {
- case attr_w:
- gr->w=attr->u.num;
- if (gr->w != 0 && gr->h != 0) {
- QSize size(gr->w,gr->h);
- gr->widget->do_resize(size);
- }
- break;
- case attr_h:
- gr->h=attr->u.num;
- if (gr->w != 0 && gr->h != 0) {
- QSize size(gr->w,gr->h);
- gr->widget->do_resize(size);
- }
- break;
- default:
- return 0;
- }
- return 1;
-}
-
-//##############################################################################################################
-//# Description:
-//# Comment:
+static int set_attr(struct graphics_priv *gr, struct attr *attr) {
+ switch (attr->type) {
+ case attr_w:
+ gr->w=attr->u.num;
+ if (gr->w != 0 && gr->h != 0) {
+ QSize size(gr->w,gr->h);
+ gr->widget->do_resize(size);
+ }
+ break;
+ case attr_h:
+ gr->h=attr->u.num;
+ if (gr->w != 0 && gr->h != 0) {
+ QSize size(gr->w,gr->h);
+ gr->widget->do_resize(size);
+ }
+ break;
+ default:
+ return 0;
+ }
+ return 1;
+}
+
+//##############################################################################################################
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
static struct graphics_methods graphics_methods = {
- graphics_destroy,
- draw_mode,
- draw_lines,
- draw_polygon,
- draw_rectangle,
- draw_circle,
- draw_text,
- draw_image,
- NULL,
- draw_drag,
- font_new,
- gc_new,
- background_gc,
- overlay_new,
- image_new,
- get_data,
- image_free,
- get_text_bbox,
- overlay_disable,
- NULL,
- set_attr,
- NULL, /* show_native_keyboard */
- NULL, /* hide_native_keyboard */
+ graphics_destroy,
+ draw_mode,
+ draw_lines,
+ draw_polygon,
+ draw_rectangle,
+ draw_circle,
+ draw_text,
+ draw_image,
+ NULL,
+ draw_drag,
+ font_new,
+ gc_new,
+ background_gc,
+ overlay_new,
+ image_new,
+ get_data,
+ image_free,
+ get_text_bbox,
+ overlay_disable,
+ NULL,
+ set_attr,
+ NULL, /* show_native_keyboard */
+ NULL, /* hide_native_keyboard */
};
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h,int wraparound)
-{
- *meth=graphics_methods;
- struct graphics_priv *ret=g_new0(struct graphics_priv, 1);
+static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p,
+ int w, int h,int wraparound) {
+ *meth=graphics_methods;
+ struct graphics_priv *ret=g_new0(struct graphics_priv, 1);
#ifdef QT_QPAINTER_USE_FREETYPE
- if (gr->font_freetype_new) {
- ret->font_freetype_new=gr->font_freetype_new;
- gr->font_freetype_new(&ret->freetype_methods);
- meth->font_new=(struct graphics_font_priv *(*)(struct graphics_priv *, struct graphics_font_methods *, char *, int, int))ret->freetype_methods.font_new;
- meth->get_text_bbox=(void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*, int))ret->freetype_methods.get_text_bbox;
- }
+ if (gr->font_freetype_new) {
+ ret->font_freetype_new=gr->font_freetype_new;
+ gr->font_freetype_new(&ret->freetype_methods);
+ meth->font_new=(struct graphics_font_priv *(*)(struct graphics_priv *, struct graphics_font_methods *, char *, int,
+ int))ret->freetype_methods.font_new;
+ meth->get_text_bbox=(void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*,
+ int))ret->freetype_methods.get_text_bbox;
+ }
#endif
- ret->widget= new RenderArea(ret,gr->widget,w,h,1);
- ret->wraparound=wraparound;
- ret->painter=new QPainter;
- ret->p=*p;
- ret->parent=gr;
- ret->next=gr->overlays;
- gr->overlays=ret;
+ ret->widget= new RenderArea(ret,gr->widget,w,h,1);
+ ret->wraparound=wraparound;
+ ret->painter=new QPainter;
+ ret->p=*p;
+ ret->parent=gr;
+ ret->next=gr->overlays;
+ gr->overlays=ret;
#ifndef QT_QPAINTER_NO_WIDGET
- ret->widget->hide();
+ ret->widget->hide();
#endif
- return ret;
+ return ret;
}
#ifdef QT_QPAINTER_USE_EVENT_QT
@@ -736,198 +717,189 @@ static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graph
static struct graphics_priv *event_gr;
static void
-event_qt_main_loop_run(void)
-{
- event_gr->app->exec();
+event_qt_main_loop_run(void) {
+ event_gr->app->exec();
}
-static void event_qt_main_loop_quit(void)
-{
- dbg(lvl_debug,"enter");
- exit(0);
+static void event_qt_main_loop_quit(void) {
+ dbg(lvl_debug,"enter");
+ exit(0);
}
static struct event_watch *
-event_qt_add_watch(int fd, enum event_watch_cond cond, struct callback *cb)
-{
- dbg(lvl_debug,"enter fd=%d",(int)(long)fd);
- struct event_watch *ret=g_new0(struct event_watch, 1);
- ret->fd=fd;
- ret->cb=cb;
- g_hash_table_insert(event_gr->widget->watches, GINT_TO_POINTER(fd), ret);
- ret->sn=new QSocketNotifier(fd, QSocketNotifier::Read, event_gr->widget);
- QObject::connect(ret->sn, SIGNAL(activated(int)), event_gr->widget, SLOT(watchEvent(int)));
- return ret;
+event_qt_add_watch(int fd, enum event_watch_cond cond, struct callback *cb) {
+ dbg(lvl_debug,"enter fd=%d",(int)(long)fd);
+ struct event_watch *ret=g_new0(struct event_watch, 1);
+ ret->fd=fd;
+ ret->cb=cb;
+ g_hash_table_insert(event_gr->widget->watches, GINT_TO_POINTER(fd), ret);
+ ret->sn=new QSocketNotifier(fd, QSocketNotifier::Read, event_gr->widget);
+ QObject::connect(ret->sn, SIGNAL(activated(int)), event_gr->widget, SLOT(watchEvent(int)));
+ return ret;
}
static void
-event_qt_remove_watch(struct event_watch *ev)
-{
- g_hash_table_remove(event_gr->widget->watches, GINT_TO_POINTER(ev->fd));
- delete(ev->sn);
- g_free(ev);
+event_qt_remove_watch(struct event_watch *ev) {
+ g_hash_table_remove(event_gr->widget->watches, GINT_TO_POINTER(ev->fd));
+ delete(ev->sn);
+ g_free(ev);
}
static struct event_timeout *
-event_qt_add_timeout(int timeout, int multi, struct callback *cb)
-{
- int id;
- id=event_gr->widget->startTimer(timeout);
- g_hash_table_insert(event_gr->widget->timer_callback, (void *)id, cb);
- g_hash_table_insert(event_gr->widget->timer_type, (void *)id, (void *)!!multi);
- return (struct event_timeout *)id;
+event_qt_add_timeout(int timeout, int multi, struct callback *cb) {
+ int id;
+ id=event_gr->widget->startTimer(timeout);
+ g_hash_table_insert(event_gr->widget->timer_callback, (void *)id, cb);
+ g_hash_table_insert(event_gr->widget->timer_type, (void *)id, (void *)!!multi);
+ return (struct event_timeout *)id;
}
void
-event_qt_remove_timeout(struct event_timeout *ev)
-{
- event_gr->widget->killTimer((int)(long)ev);
- g_hash_table_remove(event_gr->widget->timer_callback, ev);
- g_hash_table_remove(event_gr->widget->timer_type, ev);
+event_qt_remove_timeout(struct event_timeout *ev) {
+ event_gr->widget->killTimer((int)(long)ev);
+ g_hash_table_remove(event_gr->widget->timer_callback, ev);
+ g_hash_table_remove(event_gr->widget->timer_type, ev);
}
static struct event_idle *
-event_qt_add_idle(int priority, struct callback *cb)
-{
- dbg(lvl_debug,"enter");
- return (struct event_idle *)event_qt_add_timeout(0, 1, cb);
+event_qt_add_idle(int priority, struct callback *cb) {
+ dbg(lvl_debug,"enter");
+ return (struct event_idle *)event_qt_add_timeout(0, 1, cb);
}
static void
-event_qt_remove_idle(struct event_idle *ev)
-{
- dbg(lvl_debug,"enter");
- event_qt_remove_timeout((struct event_timeout *) ev);
+event_qt_remove_idle(struct event_idle *ev) {
+ dbg(lvl_debug,"enter");
+ event_qt_remove_timeout((struct event_timeout *) ev);
}
static void
-event_qt_call_callback(struct callback_list *cb)
-{
- dbg(lvl_debug,"enter");
+event_qt_call_callback(struct callback_list *cb) {
+ dbg(lvl_debug,"enter");
}
static struct event_methods event_qt_methods = {
- event_qt_main_loop_run,
- event_qt_main_loop_quit,
- event_qt_add_watch,
- event_qt_remove_watch,
- event_qt_add_timeout,
- event_qt_remove_timeout,
- event_qt_add_idle,
- event_qt_remove_idle,
- event_qt_call_callback,
+ event_qt_main_loop_run,
+ event_qt_main_loop_quit,
+ event_qt_add_watch,
+ event_qt_remove_watch,
+ event_qt_add_timeout,
+ event_qt_remove_timeout,
+ event_qt_add_idle,
+ event_qt_remove_idle,
+ event_qt_call_callback,
};
struct event_priv {
};
struct event_priv *
-event_qt_new(struct event_methods *meth)
-{
- dbg(lvl_debug,"enter");
- *meth=event_qt_methods;
- return NULL;
+event_qt_new(struct event_methods *meth) {
+ dbg(lvl_debug,"enter");
+ *meth=event_qt_methods;
+ return NULL;
}
#endif
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-static struct graphics_priv * graphics_qt_qpainter_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
- struct graphics_priv *ret;
- struct font_priv * (*font_freetype_new)(void *meth);
- struct attr *attr;
+static struct graphics_priv * graphics_qt_qpainter_new(struct navit *nav, struct graphics_methods *meth,
+ struct attr **attrs, struct callback_list *cbl) {
+ struct graphics_priv *ret;
+ struct font_priv * (*font_freetype_new)(void *meth);
+ struct attr *attr;
- dbg(lvl_debug,"enter");
+ dbg(lvl_debug,"enter");
#ifdef QT_QPAINTER_USE_EVENT_QT
- if (event_gr)
- return NULL;
- if (! event_request_system("qt","graphics_qt_qpainter_new"))
- return NULL;
+ if (event_gr)
+ return NULL;
+ if (! event_request_system("qt","graphics_qt_qpainter_new"))
+ return NULL;
#endif
#ifdef QT_QPAINTER_USE_EVENT_GLIB
- if (! event_request_system("glib","graphics_qt_qpainter_new"))
- return NULL;
+ if (! event_request_system("glib","graphics_qt_qpainter_new"))
+ return NULL;
#endif
#ifdef QT_QPAINTER_USE_FREETYPE
- font_freetype_new=(struct font_priv *(*)(void *))plugin_get_category_font("freetype");
- if (!font_freetype_new) {
- dbg(lvl_error,"no freetype");
- return NULL;
- }
+ font_freetype_new=(struct font_priv *(*)(void *))plugin_get_category_font("freetype");
+ if (!font_freetype_new) {
+ dbg(lvl_error,"no freetype");
+ return NULL;
+ }
#endif
- ret=g_new0(struct graphics_priv, 1);
- *meth=graphics_methods;
- ret->nav=nav;
+ ret=g_new0(struct graphics_priv, 1);
+ *meth=graphics_methods;
+ ret->nav=nav;
#ifdef QT_QPAINTER_USE_FREETYPE
- ret->font_freetype_new=font_freetype_new;
- font_freetype_new(&ret->freetype_methods);
- meth->font_new=(struct graphics_font_priv *(*)(struct graphics_priv *, struct graphics_font_methods *, char *, int, int))ret->freetype_methods.font_new;
- meth->get_text_bbox=(void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*, int))ret->freetype_methods.get_text_bbox;
+ ret->font_freetype_new=font_freetype_new;
+ font_freetype_new(&ret->freetype_methods);
+ meth->font_new=(struct graphics_font_priv *(*)(struct graphics_priv *, struct graphics_font_methods *, char *, int,
+ int))ret->freetype_methods.font_new;
+ meth->get_text_bbox=(void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*,
+ int))ret->freetype_methods.get_text_bbox;
#endif
#if defined QT_QPAINTER_USE_EMBEDDING && QT_VERSION >= 0x040500
- if ((attr=attr_search(attrs, NULL, attr_gc_type)))
- QApplication::setGraphicsSystem(attr->u.str);
- else
- QApplication::setGraphicsSystem("raster");
+ if ((attr=attr_search(attrs, NULL, attr_gc_type)))
+ QApplication::setGraphicsSystem(attr->u.str);
+ else
+ QApplication::setGraphicsSystem("raster");
#endif
- argv[0]=(char*)malloc(255);
- strcpy(argv[0], "navit");
- if ((attr=attr_search(attrs, NULL, attr_flags)))
- ret->flags=attr->u.num;
- if (ret->flags & 1) {
- argv[1]=(char*)malloc(255);
- strcpy(argv[1], "-qws");
- argc++;
- }
+ argv[0]=(char*)malloc(255);
+ strcpy(argv[0], "navit");
+ if ((attr=attr_search(attrs, NULL, attr_flags)))
+ ret->flags=attr->u.num;
+ if (ret->flags & 1) {
+ argv[1]=(char*)malloc(255);
+ strcpy(argv[1], "-qws");
+ argc++;
+ }
#ifndef QT_QPAINTER_NO_APP
#ifdef HAVE_QPE
- ret->app = new QPEApplication(argc, argv);
+ ret->app = new QPEApplication(argc, argv);
#else
- ret->app = new QApplication(argc, argv);
+ ret->app = new QApplication(argc, argv);
#endif
#endif
- ret->widget= new RenderArea(ret);
- ret->widget->cbl=cbl;
- ret->painter = new QPainter;
+ ret->widget= new RenderArea(ret);
+ ret->widget->cbl=cbl;
+ ret->painter = new QPainter;
#ifdef QT_QPAINTER_USE_EVENT_QT
- event_gr=ret;
+ event_gr=ret;
#endif
- ret->w=800;
- ret->h=600;
- if ((attr=attr_search(attrs, NULL, attr_w)))
- ret->w=attr->u.num;
- if ((attr=attr_search(attrs, NULL, attr_h)))
- ret->h=attr->u.num;
- if ((attr=attr_search(attrs, NULL, attr_window_title)))
- ret->window_title=g_strdup(attr->u.str);
- else
- ret->window_title=g_strdup("Navit");
+ ret->w=800;
+ ret->h=600;
+ if ((attr=attr_search(attrs, NULL, attr_w)))
+ ret->w=attr->u.num;
+ if ((attr=attr_search(attrs, NULL, attr_h)))
+ ret->h=attr->u.num;
+ if ((attr=attr_search(attrs, NULL, attr_window_title)))
+ ret->window_title=g_strdup(attr->u.str);
+ else
+ ret->window_title=g_strdup("Navit");
- dbg(lvl_debug,"return");
- return ret;
+ dbg(lvl_debug,"return");
+ return ret;
}
//##############################################################################################################
-//# Description:
-//# Comment:
+//# Description:
+//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
-void plugin_init(void)
-{
- plugin_register_category_graphics("qt_qpainter", graphics_qt_qpainter_new);
+void plugin_init(void) {
+ plugin_register_category_graphics("qt_qpainter", graphics_qt_qpainter_new);
#ifdef QT_QPAINTER_USE_EVENT_QT
- plugin_register_category_event("qt", event_qt_new);
+ plugin_register_category_event("qt", event_qt_new);
#endif
}
-// *** EOF ***
+// *** EOF ***
diff --git a/navit/graphics/sdl/event.c b/navit/graphics/sdl/event.c
index 647330813..f5499c0c2 100644
--- a/navit/graphics/sdl/event.c
+++ b/navit/graphics/sdl/event.c
@@ -8,26 +8,26 @@
#include "webos/webos.h"
struct event_timeout {
- SDL_TimerID id;
- int multi;
- struct callback *cb;
+ SDL_TimerID id;
+ int multi;
+ struct callback *cb;
};
struct idle_task {
- int priority;
- struct callback *cb;
+ int priority;
+ struct callback *cb;
};
struct event_watch {
- struct pollfd *pfd;
- struct callback *cb;
+ struct pollfd *pfd;
+ struct callback *cb;
};
static void event_sdl_watch_thread(GPtrArray *);
static void event_sdl_watch_startthread(GPtrArray *watch_list);
static void event_sdl_watch_stopthread(void);
static struct event_watch *event_sdl_add_watch(int, enum event_watch_cond,
- struct callback *);
+ struct callback *);
static void event_sdl_remove_watch(struct event_watch *);
static struct event_timeout *event_sdl_add_timeout(int, int, struct callback *);
static void event_sdl_remove_timeout(struct event_timeout *);
@@ -42,340 +42,341 @@ static SDL_Joystick *accelerometer = NULL;
static unsigned int orientation = WEBOS_ORIENTATION_PORTRAIT;
static void sdl_accelerometer_handler(void* param) {
- struct graphics_priv *gr = (struct graphics_priv *) param;
- int xAxis = SDL_JoystickGetAxis(accelerometer, 0);
- int yAxis = SDL_JoystickGetAxis(accelerometer, 1);
- int zAxis = SDL_JoystickGetAxis(accelerometer, 2);
- unsigned char new_orientation;
-
- dbg(lvl_info, "x(%d) y(%d) z(%d) c(%d)", xAxis, yAxis, zAxis,
- sdl_orientation_count);
-
- if (zAxis > -30000) {
- if (xAxis < -15000 && yAxis > -5000 && yAxis < 5000)
- new_orientation = WEBOS_ORIENTATION_LANDSCAPE;
- else if (yAxis > 15000 && xAxis > -5000 && xAxis < 5000)
- new_orientation = WEBOS_ORIENTATION_PORTRAIT;
- else
- return;
- } else
- return;
-
- if (new_orientation == sdl_next_orientation) {
- if (sdl_orientation_count < 3)
- sdl_orientation_count++;
- } else {
- sdl_orientation_count = 0;
- sdl_next_orientation = new_orientation;
- return;
- }
-
- if (sdl_orientation_count == 3) {
- sdl_orientation_count++;
-
- if (new_orientation != orientation) {
- dbg(lvl_debug, "x(%d) y(%d) z(%d) o(%d)", xAxis, yAxis, zAxis,
- new_orientation);
- orientation = new_orientation;
-
- SDL_Event event;
- SDL_UserEvent userevent;
-
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_ROTATE;
- userevent.data1 = NULL;
- userevent.data2 = NULL;
-
- event.type = SDL_USEREVENT;
- event.user = userevent;
-
- SDL_PushEvent(&event);
- }
- }
+ struct graphics_priv *gr = (struct graphics_priv *) param;
+ int xAxis = SDL_JoystickGetAxis(accelerometer, 0);
+ int yAxis = SDL_JoystickGetAxis(accelerometer, 1);
+ int zAxis = SDL_JoystickGetAxis(accelerometer, 2);
+ unsigned char new_orientation;
+
+ dbg(lvl_info, "x(%d) y(%d) z(%d) c(%d)", xAxis, yAxis, zAxis,
+ sdl_orientation_count);
+
+ if (zAxis > -30000) {
+ if (xAxis < -15000 && yAxis > -5000 && yAxis < 5000)
+ new_orientation = WEBOS_ORIENTATION_LANDSCAPE;
+ else if (yAxis > 15000 && xAxis > -5000 && xAxis < 5000)
+ new_orientation = WEBOS_ORIENTATION_PORTRAIT;
+ else
+ return;
+ } else
+ return;
+
+ if (new_orientation == sdl_next_orientation) {
+ if (sdl_orientation_count < 3)
+ sdl_orientation_count++;
+ } else {
+ sdl_orientation_count = 0;
+ sdl_next_orientation = new_orientation;
+ return;
+ }
+
+ if (sdl_orientation_count == 3) {
+ sdl_orientation_count++;
+
+ if (new_orientation != orientation) {
+ dbg(lvl_debug, "x(%d) y(%d) z(%d) o(%d)", xAxis, yAxis, zAxis,
+ new_orientation);
+ orientation = new_orientation;
+
+ SDL_Event event;
+ SDL_UserEvent userevent;
+
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_ROTATE;
+ userevent.data1 = NULL;
+ userevent.data2 = NULL;
+
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
+
+ SDL_PushEvent(&event);
+ }
+ }
}
#endif
/* ---------- SDL Eventhandling ---------- */
static Uint32 sdl_timer_callback(Uint32 interval, void* param) {
- struct event_timeout *timeout = (struct event_timeout*) param;
+ struct event_timeout *timeout = (struct event_timeout*) param;
- dbg(lvl_debug, "timer(%p) multi(%d) interval(%d) fired", param, timeout->multi,
- interval);
+ dbg(lvl_debug, "timer(%p) multi(%d) interval(%d) fired", param, timeout->multi,
+ interval);
- SDL_Event event;
- SDL_UserEvent userevent;
+ SDL_Event event;
+ SDL_UserEvent userevent;
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_TIMER;
- userevent.data1 = timeout->cb;
- userevent.data2 = NULL;
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_TIMER;
+ userevent.data1 = timeout->cb;
+ userevent.data2 = NULL;
- event.type = SDL_USEREVENT;
- event.user = userevent;
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
- SDL_PushEvent(&event);
+ SDL_PushEvent(&event);
- if (timeout->multi == 0) {
- g_free(timeout);
- timeout = NULL;
- return 0; // cancel timer
- }
- return interval; // reactivate timer
+ if (timeout->multi == 0) {
+ g_free(timeout);
+ timeout = NULL;
+ return 0; // cancel timer
+ }
+ return interval; // reactivate timer
}
/* SDL Mainloop */
static void event_sdl_main_loop_run(void) {
#ifdef USE_WEBOS_ACCELEROMETER
- struct callback* accel_cb = NULL;
- struct event_timeout* accel_to = NULL;
- if (PDL_GetPDKVersion() > 100) {
- accel_cb = callback_new_1(callback_cast(sdl_accelerometer_handler), gr);
- accel_to = event_add_timeout(200, 1, accel_cb);
- }
+ struct callback* accel_cb = NULL;
+ struct event_timeout* accel_to = NULL;
+ if (PDL_GetPDKVersion() > 100) {
+ accel_cb = callback_new_1(callback_cast(sdl_accelerometer_handler), gr);
+ accel_to = event_add_timeout(200, 1, accel_cb);
+ }
#endif
- graphics_sdl_idle(NULL);
+ graphics_sdl_idle(NULL);
- event_sdl_watch_stopthread();
+ event_sdl_watch_stopthread();
#ifdef USE_WEBOS_ACCELEROMETER
- SDL_JoystickClose(accelerometer);
- if (PDL_GetPDKVersion() > 100) {
- event_remove_timeout(accel_to);
- callback_destroy(accel_cb);
- }
+ SDL_JoystickClose(accelerometer);
+ if (PDL_GetPDKVersion() > 100) {
+ event_remove_timeout(accel_to);
+ callback_destroy(accel_cb);
+ }
#endif
}
static void event_sdl_main_loop_quit(void) {
- quit_event_loop = 1;
+ quit_event_loop = 1;
}
/* Watch */
static void event_sdl_watch_thread(GPtrArray *watch_list) {
- struct pollfd *pfds = g_new0 (struct pollfd, watch_list->len);
- struct event_watch *ew;
- int ret;
- int idx;
-
- for (idx = 0; idx < watch_list->len; idx++) {
- ew = g_ptr_array_index(watch_list, idx);
- g_memmove(&pfds[idx], ew->pfd, sizeof(struct pollfd));
- }
-
- while ((ret = ppoll(pfds, watch_list->len, NULL, NULL)) > 0) {
- for (idx = 0; idx < watch_list->len; idx++) {
- if (pfds[idx].revents == pfds[idx].events) { /* The requested event happened, notify mainloop! */
- ew = g_ptr_array_index(watch_list, idx);
- dbg(lvl_debug, "watch(%p) event(%d) encountered", ew,
- pfds[idx].revents);
-
- SDL_Event event;
- SDL_UserEvent userevent;
-
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_WATCH;
- userevent.data1 = ew->cb;
- userevent.data2 = NULL;
-
- event.type = SDL_USEREVENT;
- event.user = userevent;
-
- SDL_PushEvent(&event);
- }
- }
- }
-
- g_free(pfds);
-
- pthread_exit(0);
+ struct pollfd *pfds = g_new0 (struct pollfd, watch_list->len);
+ struct event_watch *ew;
+ int ret;
+ int idx;
+
+ for (idx = 0; idx < watch_list->len; idx++) {
+ ew = g_ptr_array_index(watch_list, idx);
+ g_memmove(&pfds[idx], ew->pfd, sizeof(struct pollfd));
+ }
+
+ while ((ret = ppoll(pfds, watch_list->len, NULL, NULL)) > 0) {
+ for (idx = 0; idx < watch_list->len; idx++) {
+ if (pfds[idx].revents == pfds[idx].events) { /* The requested event happened, notify mainloop! */
+ ew = g_ptr_array_index(watch_list, idx);
+ dbg(lvl_debug, "watch(%p) event(%d) encountered", ew,
+ pfds[idx].revents);
+
+ SDL_Event event;
+ SDL_UserEvent userevent;
+
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_WATCH;
+ userevent.data1 = ew->cb;
+ userevent.data2 = NULL;
+
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
+
+ SDL_PushEvent(&event);
+ }
+ }
+ }
+
+ g_free(pfds);
+
+ pthread_exit(0);
}
static void event_sdl_watch_startthread(GPtrArray *watch_list) {
- dbg(lvl_debug, "enter");
- if (sdl_watch_thread)
- event_sdl_watch_stopthread();
+ dbg(lvl_debug, "enter");
+ if (sdl_watch_thread)
+ event_sdl_watch_stopthread();
- int ret;
- ret = pthread_create(&sdl_watch_thread, NULL,
- (void *) event_sdl_watch_thread, (void *) watch_list);
+ int ret;
+ ret = pthread_create(&sdl_watch_thread, NULL,
+ (void *) event_sdl_watch_thread, (void *) watch_list);
- dbg_assert(ret == 0);
+ dbg_assert(ret == 0);
}
static void event_sdl_watch_stopthread() {
- dbg(lvl_debug, "enter");
- if (sdl_watch_thread) {
- /* Notify the watch thread that the list of FDs will change */
- pthread_kill(sdl_watch_thread, SIGUSR1);
- pthread_join(sdl_watch_thread, NULL);
- sdl_watch_thread = 0;
- }
+ dbg(lvl_debug, "enter");
+ if (sdl_watch_thread) {
+ /* Notify the watch thread that the list of FDs will change */
+ pthread_kill(sdl_watch_thread, SIGUSR1);
+ pthread_join(sdl_watch_thread, NULL);
+ sdl_watch_thread = 0;
+ }
}
static struct event_watch *
event_sdl_add_watch(int fd, enum event_watch_cond cond, struct callback *cb) {
- dbg(lvl_debug, "fd(%d) cond(%x) cb(%x)", fd, cond, cb);
+ dbg(lvl_debug, "fd(%d) cond(%x) cb(%x)", fd, cond, cb);
- event_sdl_watch_stopthread();
+ event_sdl_watch_stopthread();
- if (!sdl_watch_list)
- sdl_watch_list = g_ptr_array_new();
+ if (!sdl_watch_list)
+ sdl_watch_list = g_ptr_array_new();
- struct event_watch *new_ew = g_new0 (struct event_watch, 1);
- struct pollfd *pfd = g_new0 (struct pollfd, 1);
+ struct event_watch *new_ew = g_new0 (struct event_watch, 1);
+ struct pollfd *pfd = g_new0 (struct pollfd, 1);
- pfd->fd = fd;
+ pfd->fd = fd;
- /* Modify watchlist here */
- switch (cond) {
- case event_watch_cond_read:
- pfd->events = POLLIN;
- break;
- case event_watch_cond_write:
- pfd->events = POLLOUT;
- break;
- case event_watch_cond_except:
- pfd->events = POLLERR | POLLHUP;
- break;
- }
+ /* Modify watchlist here */
+ switch (cond) {
+ case event_watch_cond_read:
+ pfd->events = POLLIN;
+ break;
+ case event_watch_cond_write:
+ pfd->events = POLLOUT;
+ break;
+ case event_watch_cond_except:
+ pfd->events = POLLERR | POLLHUP;
+ break;
+ }
- new_ew->pfd = (struct pollfd*) pfd;
- new_ew->cb = cb;
+ new_ew->pfd = (struct pollfd*) pfd;
+ new_ew->cb = cb;
- g_ptr_array_add(sdl_watch_list, (gpointer) new_ew);
+ g_ptr_array_add(sdl_watch_list, (gpointer) new_ew);
- event_sdl_watch_startthread(sdl_watch_list);
+ event_sdl_watch_startthread(sdl_watch_list);
- return new_ew;
+ return new_ew;
}
static void event_sdl_remove_watch(struct event_watch *ew) {
- dbg(lvl_debug, "enter %p", ew);
+ dbg(lvl_debug, "enter %p", ew);
- event_sdl_watch_stopthread();
+ event_sdl_watch_stopthread();
- g_ptr_array_remove(sdl_watch_list, ew);
- g_free(ew->pfd);
- g_free(ew);
+ g_ptr_array_remove(sdl_watch_list, ew);
+ g_free(ew->pfd);
+ g_free(ew);
- if (sdl_watch_list->len > 0)
- event_sdl_watch_startthread(sdl_watch_list);
+ if (sdl_watch_list->len > 0)
+ event_sdl_watch_startthread(sdl_watch_list);
}
/* Timeout */
static struct event_timeout *
event_sdl_add_timeout(int timeout, int multi, struct callback *cb) {
- struct event_timeout * ret = g_new0(struct event_timeout, 1);
- if (!ret)
- return ret;
- dbg(lvl_debug, "timer(%p) multi(%d) interval(%d) cb(%p) added", ret, multi,
- timeout, cb);
- ret->multi = multi;
- ret->cb = cb;
- ret->id = SDL_AddTimer(timeout, sdl_timer_callback, ret);
-
- return ret;
+ struct event_timeout * ret = g_new0(struct event_timeout, 1);
+ if (!ret)
+ return ret;
+ dbg(lvl_debug, "timer(%p) multi(%d) interval(%d) cb(%p) added", ret, multi,
+ timeout, cb);
+ ret->multi = multi;
+ ret->cb = cb;
+ ret->id = SDL_AddTimer(timeout, sdl_timer_callback, ret);
+
+ return ret;
}
static void event_sdl_remove_timeout(struct event_timeout *to) {
- dbg(lvl_info, "enter %p", to);
- if (to != NULL) {
- int ret = to->id ? SDL_RemoveTimer(to->id) : SDL_TRUE;
- if (ret == SDL_FALSE) {
- dbg(lvl_debug, "SDL_RemoveTimer (%p) failed", to->id);
- } else {
- g_free(to);
- dbg(lvl_debug, "timer(%p) removed", to);
- }
- }
+ dbg(lvl_info, "enter %p", to);
+ if (to != NULL) {
+ int ret = to->id ? SDL_RemoveTimer(to->id) : SDL_TRUE;
+ if (ret == SDL_FALSE) {
+ dbg(lvl_debug, "SDL_RemoveTimer (%p) failed", to->id);
+ } else {
+ g_free(to);
+ dbg(lvl_debug, "timer(%p) removed", to);
+ }
+ }
}
/* Idle */
/* sort ptr_array by priority, increasing order */
static gint sdl_sort_idle_tasks(gconstpointer parama, gconstpointer paramb) {
- struct idle_task *a = (struct idle_task *) parama;
- struct idle_task *b = (struct idle_task *) paramb;
- if (a->priority < b->priority)
- return -1;
- if (a->priority > b->priority)
- return 1;
- return 0;
+ struct idle_task *a = (struct idle_task *) parama;
+ struct idle_task *b = (struct idle_task *) paramb;
+ if (a->priority < b->priority)
+ return -1;
+ if (a->priority > b->priority)
+ return 1;
+ return 0;
}
static struct event_idle *
event_sdl_add_idle(int priority, struct callback *cb) {
- dbg(lvl_debug, "add idle priority(%d) cb(%p)", priority, cb);
+ dbg(lvl_debug, "add idle priority(%d) cb(%p)", priority, cb);
- struct idle_task *task = g_new0(struct idle_task, 1);
- task->priority = priority;
- task->cb = cb;
+ struct idle_task *task = g_new0(struct idle_task, 1);
+ task->priority = priority;
+ task->cb = cb;
- g_ptr_array_add(idle_tasks, (gpointer) task);
+ g_ptr_array_add(idle_tasks, (gpointer) task);
- if (idle_tasks->len < 2) {
- SDL_Event event;
- SDL_UserEvent userevent;
+ if (idle_tasks->len < 2) {
+ SDL_Event event;
+ SDL_UserEvent userevent;
- dbg(lvl_debug, "poking eventloop because of new idle_events");
+ dbg(lvl_debug, "poking eventloop because of new idle_events");
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_IDLE_EVENT;
- userevent.data1 = NULL;
- userevent.data2 = NULL;
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_IDLE_EVENT;
+ userevent.data1 = NULL;
+ userevent.data2 = NULL;
- event.type = SDL_USEREVENT;
- event.user = userevent;
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
- SDL_PushEvent(&event);
- } else
- // more than one entry => sort the list
- g_ptr_array_sort(idle_tasks, sdl_sort_idle_tasks);
+ SDL_PushEvent(&event);
+ } else
+ // more than one entry => sort the list
+ g_ptr_array_sort(idle_tasks, sdl_sort_idle_tasks);
- return (struct event_idle *) task;
+ return (struct event_idle *) task;
}
static void event_sdl_remove_idle(struct event_idle *task) {
- dbg(lvl_debug, "remove task(%p)", task);
- g_ptr_array_remove(idle_tasks, (gpointer) task);
+ dbg(lvl_debug, "remove task(%p)", task);
+ g_ptr_array_remove(idle_tasks, (gpointer) task);
}
/* callback */
static void event_sdl_call_callback(struct callback_list *cbl) {
- dbg(lvl_debug, "call_callback cbl(%p)", cbl);
- SDL_Event event;
- SDL_UserEvent userevent;
+ dbg(lvl_debug, "call_callback cbl(%p)", cbl);
+ SDL_Event event;
+ SDL_UserEvent userevent;
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_CALL_CALLBACK;
- userevent.data1 = cbl;
- userevent.data2 = NULL;
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_CALL_CALLBACK;
+ userevent.data1 = cbl;
+ userevent.data2 = NULL;
- event.type = SDL_USEREVENT;
- event.user = userevent;
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
- SDL_PushEvent(&event);
+ SDL_PushEvent(&event);
}
static struct event_methods event_sdl_methods = { event_sdl_main_loop_run,
- event_sdl_main_loop_quit, event_sdl_add_watch, event_sdl_remove_watch,
- event_sdl_add_timeout, event_sdl_remove_timeout, event_sdl_add_idle,
- event_sdl_remove_idle, event_sdl_call_callback, };
+ event_sdl_main_loop_quit, event_sdl_add_watch, event_sdl_remove_watch,
+ event_sdl_add_timeout, event_sdl_remove_timeout, event_sdl_add_idle,
+ event_sdl_remove_idle, event_sdl_call_callback,
+};
static struct event_priv *
event_sdl_new(struct event_methods* methods) {
- idle_tasks = g_ptr_array_new();
- *methods = event_sdl_methods;
- return NULL;
+ idle_tasks = g_ptr_array_new();
+ *methods = event_sdl_methods;
+ return NULL;
}
/* ---------- SDL Eventhandling ---------- */
void sdl_event_init(void) {
- plugin_register_category_event("sdl", event_sdl_new);
+ plugin_register_category_event("sdl", event_sdl_new);
}
diff --git a/navit/graphics/sdl/event_sdl.c b/navit/graphics/sdl/event_sdl.c
index d60c2d04c..d74b91f27 100644
--- a/navit/graphics/sdl/event_sdl.c
+++ b/navit/graphics/sdl/event_sdl.c
@@ -44,300 +44,281 @@ static void event_sdl_remove_idle(struct event_idle *);
static void event_sdl_call_callback(struct callback_list *);
static Uint32
-sdl_timer_callback(Uint32 interval, void* param)
-{
- struct event_timeout *timeout=(struct event_timeout*)param;
+sdl_timer_callback(Uint32 interval, void* param) {
+ struct event_timeout *timeout=(struct event_timeout*)param;
- dbg(lvl_debug,"timer(%p) multi(%d) interval(%d) fired", param, timeout->multi, interval);
+ dbg(lvl_debug,"timer(%p) multi(%d) interval(%d) fired", param, timeout->multi, interval);
- SDL_Event event;
- SDL_UserEvent userevent;
+ SDL_Event event;
+ SDL_UserEvent userevent;
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_TIMER;
- userevent.data1 = timeout->cb;
- userevent.data2 = NULL;
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_TIMER;
+ userevent.data1 = timeout->cb;
+ userevent.data2 = NULL;
- event.type = SDL_USEREVENT;
- event.user = userevent;
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
- SDL_PushEvent (&event);
+ SDL_PushEvent (&event);
- if (timeout->multi == 0) {
- timeout->id = 0;
- return 0; // cancel timer
- }
- return interval; // reactivate timer
+ if (timeout->multi == 0) {
+ timeout->id = 0;
+ return 0; // cancel timer
+ }
+ return interval; // reactivate timer
}
/* SDL Mainloop */
static void
-event_sdl_main_loop_run(void)
-{
- graphics_sdl_idle(NULL);
- event_sdl_watch_stopthread();
+event_sdl_main_loop_run(void) {
+ graphics_sdl_idle(NULL);
+ event_sdl_watch_stopthread();
}
static void
-event_sdl_main_loop_quit(void)
-{
- quit_event_loop = 1;
+event_sdl_main_loop_quit(void) {
+ quit_event_loop = 1;
}
/* Watch */
void
-event_sdl_watch_thread (GPtrArray *watch_list)
-{
- struct pollfd *pfds = g_new0 (struct pollfd, watch_list->len);
- struct event_watch *ew;
- int ret;
- int idx;
-
- for (idx = 0; idx < watch_list->len; idx++ ) {
- ew = g_ptr_array_index (watch_list, idx);
- g_memmove (&pfds[idx], ew->pfd, sizeof(struct pollfd));
- }
-
- while ((ret = ppoll(pfds, watch_list->len, NULL, NULL)) > 0) {
- for (idx = 0; idx < watch_list->len; idx++ ) {
- if (pfds[idx].revents == pfds[idx].events) { /* The requested event happened, notify mainloop! */
- ew = g_ptr_array_index (watch_list, idx);
- dbg(lvl_debug,"watch(%p) event(%d) encountered", ew, pfds[idx].revents);
-
- SDL_Event event;
- SDL_UserEvent userevent;
-
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_WATCH;
- userevent.data1 = ew->cb;
- userevent.data2 = NULL;
-
- event.type = SDL_USEREVENT;
- event.user = userevent;
-
- SDL_PushEvent (&event);
- }
- }
- }
-
- g_free(pfds);
-
- pthread_exit(0);
+event_sdl_watch_thread (GPtrArray *watch_list) {
+ struct pollfd *pfds = g_new0 (struct pollfd, watch_list->len);
+ struct event_watch *ew;
+ int ret;
+ int idx;
+
+ for (idx = 0; idx < watch_list->len; idx++ ) {
+ ew = g_ptr_array_index (watch_list, idx);
+ g_memmove (&pfds[idx], ew->pfd, sizeof(struct pollfd));
+ }
+
+ while ((ret = ppoll(pfds, watch_list->len, NULL, NULL)) > 0) {
+ for (idx = 0; idx < watch_list->len; idx++ ) {
+ if (pfds[idx].revents == pfds[idx].events) { /* The requested event happened, notify mainloop! */
+ ew = g_ptr_array_index (watch_list, idx);
+ dbg(lvl_debug,"watch(%p) event(%d) encountered", ew, pfds[idx].revents);
+
+ SDL_Event event;
+ SDL_UserEvent userevent;
+
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_WATCH;
+ userevent.data1 = ew->cb;
+ userevent.data2 = NULL;
+
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
+
+ SDL_PushEvent (&event);
+ }
+ }
+ }
+
+ g_free(pfds);
+
+ pthread_exit(0);
}
static void
-event_sdl_watch_startthread(GPtrArray *watch_list)
-{
- dbg(lvl_debug,"enter");
- if (sdl_watch_thread)
- event_sdl_watch_stopthread();
+event_sdl_watch_startthread(GPtrArray *watch_list) {
+ dbg(lvl_debug,"enter");
+ if (sdl_watch_thread)
+ event_sdl_watch_stopthread();
- int ret;
- ret = pthread_create (&sdl_watch_thread, NULL, (void *)event_sdl_watch_thread, (void *)watch_list);
+ int ret;
+ ret = pthread_create (&sdl_watch_thread, NULL, (void *)event_sdl_watch_thread, (void *)watch_list);
- dbg_assert (ret == 0);
+ dbg_assert (ret == 0);
}
static void
-event_sdl_watch_stopthread()
-{
- dbg(lvl_debug,"enter");
- if (sdl_watch_thread) {
- /* Notify the watch thread that the list of FDs will change */
- pthread_kill(sdl_watch_thread, SIGUSR1);
- pthread_join(sdl_watch_thread, NULL);
- sdl_watch_thread = 0;
- }
+event_sdl_watch_stopthread() {
+ dbg(lvl_debug,"enter");
+ if (sdl_watch_thread) {
+ /* Notify the watch thread that the list of FDs will change */
+ pthread_kill(sdl_watch_thread, SIGUSR1);
+ pthread_join(sdl_watch_thread, NULL);
+ sdl_watch_thread = 0;
+ }
}
static struct event_watch *
-event_sdl_add_watch(int fd, enum event_watch_cond cond, struct callback *cb)
-{
- dbg(lvl_debug,"fd(%d) cond(%x) cb(%x)", fd, cond, cb);
+event_sdl_add_watch(int fd, enum event_watch_cond cond, struct callback *cb) {
+ dbg(lvl_debug,"fd(%d) cond(%x) cb(%x)", fd, cond, cb);
- event_sdl_watch_stopthread();
+ event_sdl_watch_stopthread();
- if (!sdl_watch_list)
- sdl_watch_list = g_ptr_array_new();
+ if (!sdl_watch_list)
+ sdl_watch_list = g_ptr_array_new();
- struct event_watch *new_ew = g_new0 (struct event_watch, 1);
- struct pollfd *pfd = g_new0 (struct pollfd, 1);
+ struct event_watch *new_ew = g_new0 (struct event_watch, 1);
+ struct pollfd *pfd = g_new0 (struct pollfd, 1);
- pfd->fd = fd;
+ pfd->fd = fd;
- /* Modify watchlist here */
- switch (cond) {
- case event_watch_cond_read:
- pfd->events = POLLIN;
- break;
- case event_watch_cond_write:
- pfd->events = POLLOUT;
- break;
- case event_watch_cond_except:
- pfd->events = POLLERR|POLLHUP;
- break;
- }
+ /* Modify watchlist here */
+ switch (cond) {
+ case event_watch_cond_read:
+ pfd->events = POLLIN;
+ break;
+ case event_watch_cond_write:
+ pfd->events = POLLOUT;
+ break;
+ case event_watch_cond_except:
+ pfd->events = POLLERR|POLLHUP;
+ break;
+ }
- new_ew->pfd = (struct pollfd*) pfd;
- new_ew->cb = cb;
+ new_ew->pfd = (struct pollfd*) pfd;
+ new_ew->cb = cb;
- g_ptr_array_add (sdl_watch_list, (gpointer)new_ew);
+ g_ptr_array_add (sdl_watch_list, (gpointer)new_ew);
- event_sdl_watch_startthread(sdl_watch_list);
+ event_sdl_watch_startthread(sdl_watch_list);
- return new_ew;
+ return new_ew;
}
static void
-event_sdl_remove_watch(struct event_watch *ew)
-{
- dbg(lvl_debug,"enter %p",ew);
+event_sdl_remove_watch(struct event_watch *ew) {
+ dbg(lvl_debug,"enter %p",ew);
- event_sdl_watch_stopthread();
+ event_sdl_watch_stopthread();
- g_ptr_array_remove (sdl_watch_list, ew);
- g_free (ew->pfd);
- g_free (ew);
+ g_ptr_array_remove (sdl_watch_list, ew);
+ g_free (ew->pfd);
+ g_free (ew);
- if (sdl_watch_list->len > 0)
- event_sdl_watch_startthread(sdl_watch_list);
+ if (sdl_watch_list->len > 0)
+ event_sdl_watch_startthread(sdl_watch_list);
}
/* Timeout */
static struct event_timeout *
-event_sdl_add_timeout(int timeout, int multi, struct callback *cb)
-{
- struct event_timeout * ret = g_new0(struct event_timeout, 1);
- if(!ret) {
- dbg(lvl_error,"g_new0 failed");
- return ret;
- }
- dbg(lvl_debug,"timer(%p) multi(%d) interval(%d) cb(%p) added",ret, multi, timeout, cb);
- ret->multi = multi;
- ret->cb = cb;
- ret->id = SDL_AddTimer(timeout, sdl_timer_callback, ret);
-
- return ret;
+event_sdl_add_timeout(int timeout, int multi, struct callback *cb) {
+ struct event_timeout * ret = g_new0(struct event_timeout, 1);
+ if(!ret) {
+ dbg(lvl_error,"g_new0 failed");
+ return ret;
+ }
+ dbg(lvl_debug,"timer(%p) multi(%d) interval(%d) cb(%p) added",ret, multi, timeout, cb);
+ ret->multi = multi;
+ ret->cb = cb;
+ ret->id = SDL_AddTimer(timeout, sdl_timer_callback, ret);
+
+ return ret;
}
static void
-event_sdl_remove_timeout(struct event_timeout *to)
-{
- dbg(lvl_info,"enter %p", to);
- if(to)
- {
- /* do not SDL_RemoveTimer if oneshot timer has already fired */
- int ret = to->id == 0 ? SDL_TRUE : SDL_RemoveTimer(to->id);
-
- if (ret == SDL_FALSE)
- dbg(lvl_error,"SDL_RemoveTimer (%p) failed", to->id);
-
- g_free(to);
- dbg(lvl_debug,"timer(%p) removed", to);
- }
+event_sdl_remove_timeout(struct event_timeout *to) {
+ dbg(lvl_info,"enter %p", to);
+ if(to) {
+ /* do not SDL_RemoveTimer if oneshot timer has already fired */
+ int ret = to->id == 0 ? SDL_TRUE : SDL_RemoveTimer(to->id);
+
+ if (ret == SDL_FALSE)
+ dbg(lvl_error,"SDL_RemoveTimer (%p) failed", to->id);
+
+ g_free(to);
+ dbg(lvl_debug,"timer(%p) removed", to);
+ }
}
/* Idle */
/* sort ptr_array by priority, increasing order */
static gint
-sdl_sort_idle_tasks(gconstpointer parama, gconstpointer paramb)
-{
- struct idle_task *a = (struct idle_task *)parama;
- struct idle_task *b = (struct idle_task *)paramb;
- if (a->priority < b->priority)
- return -1;
- if (a->priority > b->priority)
- return 1;
- return 0;
+sdl_sort_idle_tasks(gconstpointer parama, gconstpointer paramb) {
+ struct idle_task *a = (struct idle_task *)parama;
+ struct idle_task *b = (struct idle_task *)paramb;
+ if (a->priority < b->priority)
+ return -1;
+ if (a->priority > b->priority)
+ return 1;
+ return 0;
}
static struct event_idle *
-event_sdl_add_idle(int priority, struct callback *cb)
-{
- dbg(lvl_debug,"add idle priority(%d) cb(%p)", priority, cb);
+event_sdl_add_idle(int priority, struct callback *cb) {
+ dbg(lvl_debug,"add idle priority(%d) cb(%p)", priority, cb);
- struct idle_task *task = g_new0(struct idle_task, 1);
- task->priority = priority;
- task->cb = cb;
+ struct idle_task *task = g_new0(struct idle_task, 1);
+ task->priority = priority;
+ task->cb = cb;
- g_ptr_array_add(idle_tasks, (gpointer)task);
+ g_ptr_array_add(idle_tasks, (gpointer)task);
- if (idle_tasks->len < 2)
- {
- SDL_Event event;
- SDL_UserEvent userevent;
+ if (idle_tasks->len < 2) {
+ SDL_Event event;
+ SDL_UserEvent userevent;
- dbg(lvl_debug,"poking eventloop because of new idle_events");
+ dbg(lvl_debug,"poking eventloop because of new idle_events");
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_IDLE_EVENT;
- userevent.data1 = NULL;
- userevent.data2 = NULL;
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_IDLE_EVENT;
+ userevent.data1 = NULL;
+ userevent.data2 = NULL;
- event.type = SDL_USEREVENT;
- event.user = userevent;
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
- SDL_PushEvent (&event);
- }
- else // more than one entry => sort the list
- g_ptr_array_sort(idle_tasks, sdl_sort_idle_tasks);
+ SDL_PushEvent (&event);
+ } else // more than one entry => sort the list
+ g_ptr_array_sort(idle_tasks, sdl_sort_idle_tasks);
- return (struct event_idle *)task;
+ return (struct event_idle *)task;
}
static void
-event_sdl_remove_idle(struct event_idle *task)
-{
- dbg(lvl_debug,"remove task(%p)", task);
- g_ptr_array_remove(idle_tasks, (gpointer)task);
+event_sdl_remove_idle(struct event_idle *task) {
+ dbg(lvl_debug,"remove task(%p)", task);
+ g_ptr_array_remove(idle_tasks, (gpointer)task);
}
/* callback */
static void
-event_sdl_call_callback(struct callback_list *cbl)
-{
- dbg(lvl_debug,"call_callback cbl(%p)",cbl);
- SDL_Event event;
- SDL_UserEvent userevent;
+event_sdl_call_callback(struct callback_list *cbl) {
+ dbg(lvl_debug,"call_callback cbl(%p)",cbl);
+ SDL_Event event;
+ SDL_UserEvent userevent;
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_CALL_CALLBACK;
- userevent.data1 = cbl;
- userevent.data2 = NULL;
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_CALL_CALLBACK;
+ userevent.data1 = cbl;
+ userevent.data2 = NULL;
- event.type = SDL_USEREVENT;
- event.user = userevent;
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
- SDL_PushEvent (&event);
+ SDL_PushEvent (&event);
}
static struct event_methods event_sdl_methods = {
- event_sdl_main_loop_run,
- event_sdl_main_loop_quit,
- event_sdl_add_watch,
- event_sdl_remove_watch,
- event_sdl_add_timeout,
- event_sdl_remove_timeout,
- event_sdl_add_idle,
- event_sdl_remove_idle,
- event_sdl_call_callback,
+ event_sdl_main_loop_run,
+ event_sdl_main_loop_quit,
+ event_sdl_add_watch,
+ event_sdl_remove_watch,
+ event_sdl_add_timeout,
+ event_sdl_remove_timeout,
+ event_sdl_add_idle,
+ event_sdl_remove_idle,
+ event_sdl_call_callback,
};
static struct event_priv *
-event_sdl_new(struct event_methods* methods)
-{
- idle_tasks = g_ptr_array_new();
- *methods = event_sdl_methods;
- return NULL;
+event_sdl_new(struct event_methods* methods) {
+ idle_tasks = g_ptr_array_new();
+ *methods = event_sdl_methods;
+ return NULL;
}
void
-event_sdl_register(void)
-{
- plugin_register_category_event("sdl", event_sdl_new);
+event_sdl_register(void) {
+ plugin_register_category_event("sdl", event_sdl_new);
}
diff --git a/navit/graphics/sdl/graphics_sdl.c b/navit/graphics/sdl/graphics_sdl.c
index a87805b73..92f8f4eb8 100644
--- a/navit/graphics/sdl/graphics_sdl.c
+++ b/navit/graphics/sdl/graphics_sdl.c
@@ -183,22 +183,18 @@ struct graphics_image_priv {
static void
-graphics_destroy(struct graphics_priv *gr)
-{
+graphics_destroy(struct graphics_priv *gr) {
dbg(lvl_debug, "graphics_destroy %p %u", gr, gr->overlay_mode);
- if(gr->overlay_mode)
- {
+ if(gr->overlay_mode) {
SDL_FreeSurface(gr->screen);
gr->overlay_parent->overlay_array[gr->overlay_idx] = NULL;
- }
- else
- {
- g_free (ft_buffer);
- gr->freetype_methods.destroy();
+ } else {
+ g_free (ft_buffer);
+ gr->freetype_methods.destroy();
#ifdef USE_WEBOS_ACCELEROMETER
- SDL_JoystickClose(gr->accelerometer);
+ SDL_JoystickClose(gr->accelerometer);
#endif
#ifdef USE_WEBOS
PDL_Quit();
@@ -212,27 +208,23 @@ graphics_destroy(struct graphics_priv *gr)
/* graphics_gc */
static void
-gc_destroy(struct graphics_gc_priv *gc)
-{
+gc_destroy(struct graphics_gc_priv *gc) {
g_free(gc);
}
static void
-gc_set_linewidth(struct graphics_gc_priv *gc, int w)
-{
+gc_set_linewidth(struct graphics_gc_priv *gc, int w) {
dbg(lvl_debug, "gc_set_linewidth %p %d", gc, w);
gc->linewidth = w;
}
static void
-gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n)
-{
+gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n) {
/* TODO */
}
static void
-gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
-{
+gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) {
dbg(lvl_debug, "gc_set_foreground: %p %d %d %d %d", gc, c->a, c->r, c->g, c->b);
gc->fore_r = c->r/256;
gc->fore_g = c->g/256;
@@ -241,8 +233,7 @@ gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
}
static void
-gc_set_background(struct graphics_gc_priv *gc, struct color *c)
-{
+gc_set_background(struct graphics_gc_priv *gc, struct color *c) {
dbg(lvl_debug, "gc_set_background: %p %d %d %d %d", gc, c->a, c->r, c->g, c->b);
gc->back_r = c->r/256;
gc->back_g = c->g/256;
@@ -258,8 +249,7 @@ static struct graphics_gc_methods gc_methods = {
gc_set_background
};
-static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
-{
+static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
struct graphics_gc_priv *gc=g_new0(struct graphics_gc_priv, 1);
*meth=gc_methods;
gc->gr=gr;
@@ -270,16 +260,14 @@ static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics
static struct graphics_image_priv *
image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name, int *w, int *h,
- struct point *hot, int rotation)
-{
+ struct point *hot, int rotation) {
struct graphics_image_priv *gi;
/* FIXME: meth is not used yet.. so gi leaks. at least xpm is small */
gi = g_new0(struct graphics_image_priv, 1);
gi->img = IMG_Load(name);
- if(gi->img)
- {
+ if(gi->img) {
/* TBD: improves blit performance? */
#if !SDL_VERSION_ATLEAST(1,3,0)
SDL_SetColorKey(gi->img, SDL_RLEACCEL, gi->img->format->colorkey);
@@ -288,9 +276,7 @@ image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *n
*h=gi->img->h;
hot->x=*w/2;
hot->y=*h/2;
- }
- else
- {
+ } else {
/* TODO: debug "colour parse errors" on xpm */
dbg(lvl_error,"image_new on '%s' failed: %s", name, IMG_GetError());
g_free(gi);
@@ -301,18 +287,16 @@ image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *n
}
static void
-image_free(struct graphics_priv *gr, struct graphics_image_priv * gi)
-{
+image_free(struct graphics_priv *gr, struct graphics_image_priv * gi) {
SDL_FreeSurface(gi->img);
g_free(gi);
}
static void
-draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
- if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent && gr->overlay_parent->overlay_enable && !gr->overlay_enable) )
- {
- return;
+draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
+ if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent
+ && gr->overlay_parent->overlay_enable && !gr->overlay_enable) ) {
+ return;
}
Sint16 *vx, *vy;
@@ -322,8 +306,7 @@ draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point
vx = alloca(count * sizeof(Sint16));
vy = alloca(count * sizeof(Sint16));
- for(i = 0; i < count; i++)
- {
+ for(i = 0; i < count; i++) {
x = (Sint16)p[i].x;
y = (Sint16)p[i].y;
vx[i] = x;
@@ -332,96 +315,84 @@ draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point
dbg(lvl_debug, "draw_polygon: %p %i %d,%d", gc, i, p[i].x, p[i].y);
}
- if(gr->aa)
- {
+ if(gr->aa) {
raster_aapolygon(gr->screen, count, vx, vy,
- SDL_MapRGBA(gr->screen->format,
- gc->fore_r,
- gc->fore_g,
- gc->fore_b,
- gc->fore_a));
- }
- else
- {
+ SDL_MapRGBA(gr->screen->format,
+ gc->fore_r,
+ gc->fore_g,
+ gc->fore_b,
+ gc->fore_a));
+ } else {
raster_polygon(gr->screen, count, vx, vy,
- SDL_MapRGBA(gr->screen->format,
- gc->fore_r,
- gc->fore_g,
- gc->fore_b,
- gc->fore_a));
+ SDL_MapRGBA(gr->screen->format,
+ gc->fore_r,
+ gc->fore_g,
+ gc->fore_b,
+ gc->fore_a));
}
}
static void
-draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h)
-{
- if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent && gr->overlay_parent->overlay_enable && !gr->overlay_enable) )
- {
- return;
+draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h) {
+ if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent
+ && gr->overlay_parent->overlay_enable && !gr->overlay_enable) ) {
+ return;
}
dbg(lvl_debug, "draw_rectangle: %d %d %d %d r=%d g=%d b=%d a=%d", p->x, p->y, w, h,
- gc->fore_r, gc->fore_g, gc->fore_b, gc->fore_a);
- if(w > gr->screen->w)
- {
+ gc->fore_r, gc->fore_g, gc->fore_b, gc->fore_a);
+ if(w > gr->screen->w) {
w = gr->screen->w;
}
- if(h > gr->screen->h)
- {
+ if(h > gr->screen->h) {
h = gr->screen->h;
}
raster_rect(gr->screen, p->x, p->y, w, h,
- SDL_MapRGBA(gr->screen->format,
- gc->fore_r,
- gc->fore_g,
- gc->fore_b,
- gc->fore_a));
+ SDL_MapRGBA(gr->screen->format,
+ gc->fore_r,
+ gc->fore_g,
+ gc->fore_b,
+ gc->fore_a));
}
static void
-draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r)
-{
- if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent && gr->overlay_parent->overlay_enable && !gr->overlay_enable) )
- {
- return;
+draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r) {
+ if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent
+ && gr->overlay_parent->overlay_enable && !gr->overlay_enable) ) {
+ return;
}
/* FIXME: does not quite match gtk */
/* hack for osd compass.. why is this needed!? */
- if(gr->overlay_mode)
- {
+ if(gr->overlay_mode) {
r = r / 2;
}
- if(gr->aa)
- {
+ if(gr->aa) {
raster_aacircle(gr->screen, p->x, p->y, r,
- SDL_MapRGBA(gr->screen->format,
- gc->fore_r,
- gc->fore_g,
- gc->fore_b,
- gc->fore_a));
- }
- else
- {
+ SDL_MapRGBA(gr->screen->format,
+ gc->fore_r,
+ gc->fore_g,
+ gc->fore_b,
+ gc->fore_a));
+ } else {
raster_circle(gr->screen, p->x, p->y, r,
- SDL_MapRGBA(gr->screen->format,
- gc->fore_r,
- gc->fore_g,
- gc->fore_b,
- gc->fore_a));
+ SDL_MapRGBA(gr->screen->format,
+ gc->fore_r,
+ gc->fore_g,
+ gc->fore_b,
+ gc->fore_a));
}
}
static void
-draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
- if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent && gr->overlay_parent->overlay_enable && !gr->overlay_enable) )
- {
- return;
+draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
+ if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent
+ && gr->overlay_parent->overlay_enable && !gr->overlay_enable) ) {
+ return;
}
/* you might expect lines to be simpler than the other shapes.
@@ -439,60 +410,47 @@ draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *
//int lw = 1;
int i;
- for(i = 0; i < count-1; i++)
- {
- float dx=p[i+1].x-p[i].x;
- float dy=p[i+1].y-p[i].y;
+ for(i = 0; i < count-1; i++) {
+ float dx=p[i+1].x-p[i].x;
+ float dy=p[i+1].y-p[i].y;
float angle;
int x_lw_adj, y_lw_adj;
- if(lw == 1)
- {
- if(gr->aa)
- {
+ if(lw == 1) {
+ if(gr->aa) {
raster_aaline(gr->screen, p[i].x, p[i].y, p[i+1].x, p[i+1].y,
- SDL_MapRGBA(gr->screen->format,
- gc->fore_r,
- gc->fore_g,
- gc->fore_b,
- gc->fore_a));
- }
- else
- {
+ SDL_MapRGBA(gr->screen->format,
+ gc->fore_r,
+ gc->fore_g,
+ gc->fore_b,
+ gc->fore_a));
+ } else {
raster_line(gr->screen, p[i].x, p[i].y, p[i+1].x, p[i+1].y,
- SDL_MapRGBA(gr->screen->format,
- gc->fore_r,
- gc->fore_g,
- gc->fore_b,
- gc->fore_a));
+ SDL_MapRGBA(gr->screen->format,
+ gc->fore_r,
+ gc->fore_g,
+ gc->fore_b,
+ gc->fore_a));
}
- }
- else
- {
+ } else {
/* there is probably a much simpler way but this works ok */
/* FIXME: float + double mixture */
/* FIXME: lrint(round())? */
- if(dy == 0.0)
- {
+ if(dy == 0.0) {
angle = 0.0;
x_lw_adj = 0;
y_lw_adj = round((float)lw/2.0);
- }
- else if(dx == 0.0)
- {
+ } else if(dx == 0.0) {
angle = 0.0;
x_lw_adj = round((float)lw/2.0);
y_lw_adj = 0;
- }
- else
- {
+ } else {
angle = (M_PI/2.0) - atan(abs(dx)/abs(dy));
x_lw_adj = round(sin(angle)*(float)lw/2.0);
y_lw_adj = round(cos(angle)*(float)lw/2.0);
- if((x_lw_adj < 0) || (y_lw_adj < 0))
- {
+ if((x_lw_adj < 0) || (y_lw_adj < 0)) {
dbg(lvl_debug, "i=%d", i);
dbg(lvl_debug, " %d,%d->%d,%d", p[i].x, p[i].y, p[i+1].x, p[i+1].y);
dbg(lvl_debug, " lw=%d angle=%f", lw, 180.0 * angle / M_PI);
@@ -500,12 +458,10 @@ draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *
}
}
- if(p[i+1].x > p[i].x)
- {
+ if(p[i+1].x > p[i].x) {
x_lw_adj = -x_lw_adj;
}
- if(p[i+1].y > p[i].y)
- {
+ if(p[i+1].y > p[i].y) {
y_lw_adj = -y_lw_adj;
}
@@ -530,10 +486,8 @@ draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *
/* FIXME: should just draw a half circle */
/* now some circular endcaps, if the width is over 2 */
- if(lw > 2)
- {
- if(i == 0)
- {
+ if(lw > 2) {
+ if(i == 0) {
draw_circle(gr, gc, &p[i], lw/2);
}
/* we truncate on the divide on purpose, so we don't go outside the line */
@@ -545,10 +499,9 @@ draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *
static void
-set_pixel(SDL_Surface *surface, int x, int y, Uint8 r2, Uint8 g2, Uint8 b2, Uint8 a2)
-{
+set_pixel(SDL_Surface *surface, int x, int y, Uint8 r2, Uint8 g2, Uint8 b2, Uint8 a2) {
if(x<0 || y<0 || x>=surface->w || y>=surface->h) {
- return;
+ return;
}
void *target_pixel = ((Uint8*)surface->pixels + y * surface->pitch + x * surface->format->BytesPerPixel);
@@ -556,85 +509,82 @@ set_pixel(SDL_Surface *surface, int x, int y, Uint8 r2, Uint8 g2, Uint8 b2, Uint
Uint8 r1,g1,b1,a1;
switch(surface->format->BytesPerPixel) {
- case 2:
- {
- SDL_GetRGBA(*(Uint16 *)target_pixel, surface->format, &r1, &g1, &b1, &a1);
- *(Uint16 *)target_pixel = SDL_MapRGBA(surface->format,
- (r1*(0xff-a2)/0xff) + (r2*a2/0xff),
- (g1*(0xff-a2)/0xff) + (g2*a2/0xff),
- (b1*(0xff-a2)/0xff) + (b2*a2/0xff),
- a2 + a1*(0xff-a2)/0xff );
- break;
- }
- case 4:
- {
- SDL_GetRGBA(*(Uint32 *)target_pixel, surface->format, &r1, &g1, &b1, &a1);
- *(Uint32 *)target_pixel = SDL_MapRGBA(surface->format,
- (r1*(0xff-a2)/0xff) + (r2*a2/0xff),
- (g1*(0xff-a2)/0xff) + (g2*a2/0xff),
- (b1*(0xff-a2)/0xff) + (b2*a2/0xff),
- a2 + a1*(0xff-a2)/0xff );
- break;
- }
+ case 2: {
+ SDL_GetRGBA(*(Uint16 *)target_pixel, surface->format, &r1, &g1, &b1, &a1);
+ *(Uint16 *)target_pixel = SDL_MapRGBA(surface->format,
+ (r1*(0xff-a2)/0xff) + (r2*a2/0xff),
+ (g1*(0xff-a2)/0xff) + (g2*a2/0xff),
+ (b1*(0xff-a2)/0xff) + (b2*a2/0xff),
+ a2 + a1*(0xff-a2)/0xff );
+ break;
+ }
+ case 4: {
+ SDL_GetRGBA(*(Uint32 *)target_pixel, surface->format, &r1, &g1, &b1, &a1);
+ *(Uint32 *)target_pixel = SDL_MapRGBA(surface->format,
+ (r1*(0xff-a2)/0xff) + (r2*a2/0xff),
+ (g1*(0xff-a2)/0xff) + (g2*a2/0xff),
+ (b1*(0xff-a2)/0xff) + (b2*a2/0xff),
+ a2 + a1*(0xff-a2)/0xff );
+ break;
+ }
}
}
static void
-resize_ft_buffer (unsigned int new_size)
-{
+resize_ft_buffer (unsigned int new_size) {
if (new_size > ft_buffer_size) {
- g_free (ft_buffer);
- ft_buffer = g_malloc (new_size);
- dbg(lvl_debug, "old_size(%u) new_size(%u) ft_buffer(%p)", ft_buffer_size, new_size, ft_buffer);
- ft_buffer_size = new_size;
+ g_free (ft_buffer);
+ ft_buffer = g_malloc (new_size);
+ dbg(lvl_debug, "old_size(%u) new_size(%u) ft_buffer(%p)", ft_buffer_size, new_size, ft_buffer);
+ ft_buffer_size = new_size;
}
}
static void
display_text_draw(struct font_freetype_text *text,
- struct graphics_priv *gr, struct graphics_gc_priv *fg,
- struct graphics_gc_priv *bg, int color, struct point *p)
-{
+ struct graphics_priv *gr, struct graphics_gc_priv *fg,
+ struct graphics_gc_priv *bg, int color, struct point *p) {
int i, x, y, stride;
struct font_freetype_glyph *g, **gp;
struct color transparent = { 0x0000, 0x0000, 0x0000, 0x0000 };
struct color black = { fg->fore_r * 255, fg->fore_g * 255,
- fg->fore_b * 255, fg->fore_a * 255 };
+ fg->fore_b * 255, fg->fore_a * 255
+ };
struct color white = { 0xffff, 0xffff, 0xffff, 0xffff };
if (bg) {
- if (COLOR_IS_WHITE(black) && COLOR_IS_BLACK(white)) {
- black.r = 65535;
- black.g = 65535;
- black.b = 65535;
- black.a = 65535;
-
- white.r = 0;
- white.g = 0;
- white.b = 0;
- white.a = 65535;
- } else if (COLOR_IS_BLACK(black) && COLOR_IS_WHITE(white)) {
- white.r = 65535;
- white.g = 65535;
- white.b = 65535;
- white.a = 65535;
-
- black.r = 0;
- black.g = 0;
- black.b = 0;
- black.a = 65535;
- } else {
- white.r = bg->fore_r * 255;
- white.g = bg->fore_g * 255;
- white.b = bg->fore_b * 255;
- white.a = bg->fore_a * 255;
- }
+ if (COLOR_IS_WHITE(black) && COLOR_IS_BLACK(white)) {
+ black.r = 65535;
+ black.g = 65535;
+ black.b = 65535;
+ black.a = 65535;
+
+ white.r = 0;
+ white.g = 0;
+ white.b = 0;
+ white.a = 65535;
+ } else if (COLOR_IS_BLACK(black) && COLOR_IS_WHITE(white)) {
+ white.r = 65535;
+ white.g = 65535;
+ white.b = 65535;
+ white.a = 65535;
+
+ black.r = 0;
+ black.g = 0;
+ black.b = 0;
+ black.a = 65535;
+ } else {
+ white.r = bg->fore_r * 255;
+ white.g = bg->fore_g * 255;
+ white.b = bg->fore_b * 255;
+ white.a = bg->fore_a * 255;
+ }
} else {
- white.r = 0;
- white.g = 0;
- white.b = 0;
- white.a = 0;
+ white.r = 0;
+ white.g = 0;
+ white.b = 0;
+ white.a = 0;
}
@@ -643,32 +593,32 @@ display_text_draw(struct font_freetype_text *text,
x = p->x << 6;
y = p->y << 6;
while (i-- > 0) {
- g = *gp++;
- if (g->w && g->h && bg) {
- stride = (g->w + 2) * 4;
- if (color) {
- resize_ft_buffer(stride * (g->h + 2));
- gr->freetype_methods.get_shadow(g, ft_buffer, stride, &white, &transparent);
-
- SDL_Surface *glyph_surface =
- SDL_CreateRGBSurfaceFrom(ft_buffer, g->w + 2, g->h + 2,
- 32,
- stride,
- 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
- if (glyph_surface) {
- SDL_Rect r;
- r.x = (x + g->x) >> 6;
- r.y = (y + g->y) >> 6;
- r.w = g->w + 2;
- r.h = g->h + 2;
-
- SDL_BlitSurface(glyph_surface, NULL, gr->screen, &r);
- SDL_FreeSurface(glyph_surface);
- }
- }
- }
- x += g->dx;
- y += g->dy;
+ g = *gp++;
+ if (g->w && g->h && bg) {
+ stride = (g->w + 2) * 4;
+ if (color) {
+ resize_ft_buffer(stride * (g->h + 2));
+ gr->freetype_methods.get_shadow(g, ft_buffer, stride, &white, &transparent);
+
+ SDL_Surface *glyph_surface =
+ SDL_CreateRGBSurfaceFrom(ft_buffer, g->w + 2, g->h + 2,
+ 32,
+ stride,
+ 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
+ if (glyph_surface) {
+ SDL_Rect r;
+ r.x = (x + g->x) >> 6;
+ r.y = (y + g->y) >> 6;
+ r.w = g->w + 2;
+ r.h = g->h + 2;
+
+ SDL_BlitSurface(glyph_surface, NULL, gr->screen, &r);
+ SDL_FreeSurface(glyph_surface);
+ }
+ }
+ }
+ x += g->dx;
+ y += g->dy;
}
gp = text->glyph;
@@ -676,80 +626,79 @@ display_text_draw(struct font_freetype_text *text,
x = p->x << 6;
y = p->y << 6;
while (i-- > 0) {
- g = *gp++;
- if (g->w && g->h) {
- if (color) {
- stride = g->w;
- if (bg) {
- resize_ft_buffer(stride * g->h * 4);
- gr->freetype_methods.get_glyph(g, ft_buffer,
- stride * 4, &black,
- &white, &transparent);
- SDL_Surface *glyph_surface =
- SDL_CreateRGBSurfaceFrom(ft_buffer, g->w, g->h, 32,
- stride * 4,
- 0x000000ff,0x0000ff00, 0x00ff0000,0xff000000);
- if (glyph_surface) {
- SDL_Rect r;
- r.x = (x + g->x) >> 6;
- r.y = (y + g->y) >> 6;
- r.w = g->w;
- r.h = g->h;
-
- SDL_BlitSurface(glyph_surface, NULL, gr->screen,&r);
- SDL_FreeSurface(glyph_surface);
- }
- }
- stride *= 4;
- resize_ft_buffer(stride * g->h);
- gr->freetype_methods.get_glyph(g, ft_buffer, stride,
- &black, &white,
- &transparent);
- int ii, jj;
- unsigned char* pGlyph = ft_buffer;
- for (jj = 0; jj < g->h; ++jj) {
- for (ii = 0; ii < g->w; ++ii) {
- if(*(pGlyph+3) > 0) {
+ g = *gp++;
+ if (g->w && g->h) {
+ if (color) {
+ stride = g->w;
+ if (bg) {
+ resize_ft_buffer(stride * g->h * 4);
+ gr->freetype_methods.get_glyph(g, ft_buffer,
+ stride * 4, &black,
+ &white, &transparent);
+ SDL_Surface *glyph_surface =
+ SDL_CreateRGBSurfaceFrom(ft_buffer, g->w, g->h, 32,
+ stride * 4,
+ 0x000000ff,0x0000ff00, 0x00ff0000,0xff000000);
+ if (glyph_surface) {
+ SDL_Rect r;
+ r.x = (x + g->x) >> 6;
+ r.y = (y + g->y) >> 6;
+ r.w = g->w;
+ r.h = g->h;
+
+ SDL_BlitSurface(glyph_surface, NULL, gr->screen,&r);
+ SDL_FreeSurface(glyph_surface);
+ }
+ }
+ stride *= 4;
+ resize_ft_buffer(stride * g->h);
+ gr->freetype_methods.get_glyph(g, ft_buffer, stride,
+ &black, &white,
+ &transparent);
+ int ii, jj;
+ unsigned char* pGlyph = ft_buffer;
+ for (jj = 0; jj < g->h; ++jj) {
+ for (ii = 0; ii < g->w; ++ii) {
+ if(*(pGlyph+3) > 0) {
set_pixel(gr->screen,
- ii+((x + g->x) >> 6),
- jj+((y + g->y) >> 6),
- *(pGlyph+2), // Pixels are in BGRA format
- *(pGlyph+1),
- *(pGlyph+0),
- *(pGlyph+3)
- );
+ ii+((x + g->x) >> 6),
+ jj+((y + g->y) >> 6),
+ *(pGlyph+2), // Pixels are in BGRA format
+ *(pGlyph+1),
+ *(pGlyph+0),
+ *(pGlyph+3)
+ );
}
pGlyph += 4;
- }
- }
- }
- }
- x += g->dx;
- y += g->dy;
+ }
+ }
+ }
+ }
+ x += g->dx;
+ y += g->dy;
}
}
static void
draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg,
- struct graphics_gc_priv *bg, struct graphics_font_priv *font,
- char *text, struct point *p, int dx, int dy)
-{
+ struct graphics_gc_priv *bg, struct graphics_font_priv *font,
+ char *text, struct point *p, int dx, int dy) {
if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable)
- || (gr->overlay_parent && gr->overlay_parent->overlay_enable
- && !gr->overlay_enable)) {
- return;
+ || (gr->overlay_parent && gr->overlay_parent->overlay_enable
+ && !gr->overlay_enable)) {
+ return;
}
struct font_freetype_text *t;
int color = 1;
if (!font) {
- dbg(lvl_error, "no font, returning");
- return;
+ dbg(lvl_error, "no font, returning");
+ return;
}
t = gr->freetype_methods.text_new(text,
- (struct font_freetype_font *) font,
- dx, dy);
+ (struct font_freetype_font *) font,
+ dx, dy);
struct point p_eff;
p_eff.x = p->x;
@@ -760,11 +709,10 @@ draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg,
}
static void
-draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img)
-{
- if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent && gr->overlay_parent->overlay_enable && !gr->overlay_enable) )
- {
- return;
+draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img) {
+ if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent
+ && gr->overlay_parent->overlay_enable && !gr->overlay_enable) ) {
+ return;
}
SDL_Rect r;
@@ -778,36 +726,27 @@ draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *
}
static void
-background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
+background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
dbg(lvl_debug, "background_gc");
}
static void
-draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
-{
+draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
struct graphics_priv *ov;
SDL_Rect rect;
int i;
- if(gr->overlay_mode)
- {
+ if(gr->overlay_mode) {
/* will be drawn below */
- }
- else
- {
+ } else {
dbg(lvl_debug, "draw_mode: %d", mode);
- if(mode == draw_mode_end)
- {
- if((gr->draw_mode == draw_mode_begin) && gr->overlay_enable)
- {
- for(i = 0; i < OVERLAY_MAX; i++)
- {
+ if(mode == draw_mode_end) {
+ if((gr->draw_mode == draw_mode_begin) && gr->overlay_enable) {
+ for(i = 0; i < OVERLAY_MAX; i++) {
ov = gr->overlay_array[i];
- if(ov && ov->overlay_enable)
- {
+ if(ov && ov->overlay_enable) {
rect.x = ov->overlay_x;
if(rect.x<0) rect.x += gr->screen->w;
rect.y = ov->overlay_y;
@@ -827,12 +766,11 @@ draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
}
}
-static void overlay_disable(struct graphics_priv *gr, int disable)
-{
+static void overlay_disable(struct graphics_priv *gr, int disable) {
gr->overlay_enable = !disable;
struct graphics_priv *curr_gr = gr;
if(gr->overlay_parent) {
- curr_gr = gr->overlay_parent;
+ curr_gr = gr->overlay_parent;
}
draw_mode(curr_gr,draw_mode_end);
}
@@ -840,48 +778,44 @@ static void overlay_disable(struct graphics_priv *gr, int disable)
static struct graphics_priv *
overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound);
-static int window_fullscreen(struct window *win, int on)
-{
+static int window_fullscreen(struct window *win, int on) {
struct graphics_priv *gr=(struct graphics_priv *)win->priv;
/* Update video flags */
if(on) {
- gr->video_flags |= SDL_FULLSCREEN;
+ gr->video_flags |= SDL_FULLSCREEN;
} else {
- gr->video_flags &= ~SDL_FULLSCREEN;
+ gr->video_flags &= ~SDL_FULLSCREEN;
}
/* Update video mode */
gr->screen = SDL_SetVideoMode(gr->screen->w, gr->screen->h, gr->video_bpp, gr->video_flags);
if(gr->screen == NULL) {
- navit_destroy(gr->nav);
- }
- else {
- callback_list_call_attr_2(gr->cbl, attr_resize, GINT_TO_POINTER(gr->screen->w), GINT_TO_POINTER(gr->screen->h));
+ navit_destroy(gr->nav);
+ } else {
+ callback_list_call_attr_2(gr->cbl, attr_resize, GINT_TO_POINTER(gr->screen->w), GINT_TO_POINTER(gr->screen->h));
}
return 1;
}
static void *
-get_data(struct graphics_priv *this, char const *type)
-{
+get_data(struct graphics_priv *this, char const *type) {
if(strcmp(type, "window") == 0) {
- struct window *win;
- win=g_new(struct window, 1);
- win->priv=this;
- win->fullscreen=window_fullscreen;
- win->disable_suspend=NULL;
- return win;
+ struct window *win;
+ win=g_new(struct window, 1);
+ win->priv=this;
+ win->fullscreen=window_fullscreen;
+ win->disable_suspend=NULL;
+ return win;
} else {
- return NULL;
+ return NULL;
}
}
-static void draw_drag(struct graphics_priv *gr, struct point *p)
-{
+static void draw_drag(struct graphics_priv *gr, struct point *p) {
if(p) {
- gr->overlay_x = p->x;
- gr->overlay_y = p->y;
+ gr->overlay_x = p->x;
+ gr->overlay_y = p->y;
}
}
@@ -907,74 +841,70 @@ static struct graphics_methods graphics_methods = {
overlay_disable,
NULL, /* overlay_resize */
NULL, /* set_attr */
- NULL, /* show_native_keyboard */
- NULL, /* hide_native_keyboard */
+ NULL, /* show_native_keyboard */
+ NULL, /* hide_native_keyboard */
};
static struct graphics_priv *
-overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h,int wraparound)
-{
+overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h,int wraparound) {
struct graphics_priv *ov;
Uint32 rmask, gmask, bmask, amask;
int i;
- for(i = 0; i < OVERLAY_MAX; i++)
- {
- if(gr->overlay_array[i] == NULL)
- {
- break;
- }
+ for(i = 0; i < OVERLAY_MAX; i++) {
+ if(gr->overlay_array[i] == NULL) {
+ break;
+ }
}
- if(i == OVERLAY_MAX)
- {
- dbg(lvl_error, "too many overlays! increase OVERLAY_MAX");
- return NULL;
+ if(i == OVERLAY_MAX) {
+ dbg(lvl_error, "too many overlays! increase OVERLAY_MAX");
+ return NULL;
}
dbg(lvl_debug, "overlay_new %d %d %d %u %u (%x, %x, %x ,%x, %d)", i,
- p->x,
- p->y,
- w,
- h,
- gr->screen->format->Rmask,
- gr->screen->format->Gmask,
- gr->screen->format->Bmask,
- gr->screen->format->Amask,
- gr->screen->format->BitsPerPixel
+ p->x,
+ p->y,
+ w,
+ h,
+ gr->screen->format->Rmask,
+ gr->screen->format->Gmask,
+ gr->screen->format->Bmask,
+ gr->screen->format->Amask,
+ gr->screen->format->BitsPerPixel
);
ov = g_new0(struct graphics_priv, 1);
switch(gr->screen->format->BitsPerPixel) {
- case 8:
- rmask = 0xc0;
- gmask = 0x30;
- bmask = 0x0c;
- amask = 0x03;
- break;
- case 16:
- rmask = 0xf000;
- gmask = 0x0f00;
- bmask = 0x00f0;
- amask = 0x000f;
- break;
- case 32:
- rmask = 0xff000000;
- gmask = 0x00ff0000;
- bmask = 0x0000ff00;
- amask = 0x000000ff;
- break;
- default:
- rmask = gr->screen->format->Rmask;
- gmask = gr->screen->format->Gmask;
- bmask = gr->screen->format->Bmask;
- amask = gr->screen->format->Amask;
+ case 8:
+ rmask = 0xc0;
+ gmask = 0x30;
+ bmask = 0x0c;
+ amask = 0x03;
+ break;
+ case 16:
+ rmask = 0xf000;
+ gmask = 0x0f00;
+ bmask = 0x00f0;
+ amask = 0x000f;
+ break;
+ case 32:
+ rmask = 0xff000000;
+ gmask = 0x00ff0000;
+ bmask = 0x0000ff00;
+ amask = 0x000000ff;
+ break;
+ default:
+ rmask = gr->screen->format->Rmask;
+ gmask = gr->screen->format->Gmask;
+ bmask = gr->screen->format->Bmask;
+ amask = gr->screen->format->Amask;
}
ov->screen = SDL_CreateRGBSurface(SDL_SWSURFACE,
- w, h,
- gr->screen->format->BitsPerPixel,
- rmask, gmask, bmask, amask);
+ w, h,
+ gr->screen->format->BitsPerPixel,
+ rmask, gmask, bmask, amask);
ov->overlay_mode = 1;
ov->overlay_enable = 1;
@@ -988,9 +918,8 @@ overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct poin
struct font_priv *(*font_freetype_new) (void *meth);
font_freetype_new = plugin_get_category_font ("freetype");
- if (!font_freetype_new)
- {
- return NULL;
+ if (!font_freetype_new) {
+ return NULL;
}
@@ -999,9 +928,9 @@ overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct poin
*meth=graphics_methods;
meth->font_new =
- (struct graphics_font_priv *
- (*)(struct graphics_priv *, struct graphics_font_methods *, char *, int,
- int)) ov->freetype_methods.font_new;
+ (struct graphics_font_priv *
+ (*)(struct graphics_priv *, struct graphics_font_methods *, char *, int,
+ int)) ov->freetype_methods.font_new;
meth->get_text_bbox = (void *)ov->freetype_methods.get_text_bbox;
@@ -1010,8 +939,7 @@ overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct poin
return ov;
}
-static gboolean graphics_sdl_idle(void *data)
-{
+static gboolean graphics_sdl_idle(void *data) {
struct graphics_priv *gr = (struct graphics_priv *)data;
struct point p;
SDL_Event ev;
@@ -1021,13 +949,12 @@ static gboolean graphics_sdl_idle(void *data)
#ifdef USE_WEBOS
if(data==NULL) {
- if(the_graphics!=NULL) {
- gr = the_graphics;
- }
- else {
- dbg(lvl_error,"graphics_idle: graphics not set!");
- return FALSE;
- }
+ if(the_graphics!=NULL) {
+ gr = the_graphics;
+ } else {
+ dbg(lvl_error,"graphics_idle: graphics not set!");
+ return FALSE;
+ }
}
#endif
@@ -1037,9 +964,8 @@ static gboolean graphics_sdl_idle(void *data)
graphics_gtk does it during Configure, but SDL does not have
an equivalent event, so we use our own flag
*/
- if(gr->resize_callback_initial != 0)
- {
- callback_list_call_attr_2(gr->cbl, attr_resize, GINT_TO_POINTER(gr->screen->w), GINT_TO_POINTER(gr->screen->h));
+ if(gr->resize_callback_initial != 0) {
+ callback_list_call_attr_2(gr->cbl, attr_resize, GINT_TO_POINTER(gr->screen->w), GINT_TO_POINTER(gr->screen->h));
gr->resize_callback_initial = 0;
}
@@ -1047,8 +973,8 @@ static gboolean graphics_sdl_idle(void *data)
struct callback* accel_cb = NULL;
struct event_timeout* accel_to = NULL;
if (PDL_GetPDKVersion() > 100) {
- accel_cb = callback_new_1(callback_cast(sdl_accelerometer_handler), gr);
- accel_to = event_add_timeout(200, 1, accel_cb);
+ accel_cb = callback_new_1(callback_cast(sdl_accelerometer_handler), gr);
+ accel_to = event_add_timeout(200, 1, accel_cb);
}
#endif
#ifdef USE_WEBOS
@@ -1062,321 +988,305 @@ static gboolean graphics_sdl_idle(void *data)
#endif
{
#ifdef USE_WEBOS
- ret = 0;
- if(idle_tasks->len > 0)
- {
- while (!(ret = SDL_PollEvent(&ev)) && idle_tasks->len > 0)
- {
- if (idle_tasks_idx >= idle_tasks->len)
- idle_tasks_idx = 0;
-
- dbg(lvl_debug,"idle_tasks_idx(%d)",idle_tasks_idx);
- task = (struct idle_task *)g_ptr_array_index(idle_tasks,idle_tasks_idx);
-
- if (idle_tasks_idx == 0) // only execute tasks with lowest priority value
- idle_tasks_cur_priority = task->priority;
- if (task->priority > idle_tasks_cur_priority)
- idle_tasks_idx = 0;
- else
- {
- callback_call_0(task->cb);
- idle_tasks_idx++;
- }
- }
- }
- if (!ret) // If we get here there are no idle_tasks and we have no events pending
- ret = SDL_WaitEvent(&ev);
+ ret = 0;
+ if(idle_tasks->len > 0) {
+ while (!(ret = SDL_PollEvent(&ev)) && idle_tasks->len > 0) {
+ if (idle_tasks_idx >= idle_tasks->len)
+ idle_tasks_idx = 0;
+
+ dbg(lvl_debug,"idle_tasks_idx(%d)",idle_tasks_idx);
+ task = (struct idle_task *)g_ptr_array_index(idle_tasks,idle_tasks_idx);
+
+ if (idle_tasks_idx == 0) // only execute tasks with lowest priority value
+ idle_tasks_cur_priority = task->priority;
+ if (task->priority > idle_tasks_cur_priority)
+ idle_tasks_idx = 0;
+ else {
+ callback_call_0(task->cb);
+ idle_tasks_idx++;
+ }
+ }
+ }
+ if (!ret) // If we get here there are no idle_tasks and we have no events pending
+ ret = SDL_WaitEvent(&ev);
#else
- ret = SDL_PollEvent(&ev);
+ ret = SDL_PollEvent(&ev);
#endif
- if(ret == 0)
- {
- break;
- }
+ if(ret == 0) {
+ break;
+ }
#ifdef USE_WEBOS
- dbg(lvl_debug,"SDL_Event %d", ev.type);
+ dbg(lvl_debug,"SDL_Event %d", ev.type);
#endif
- switch(ev.type)
- {
- case SDL_MOUSEMOTION:
- {
- p.x = ev.motion.x;
- p.y = ev.motion.y;
- callback_list_call_attr_1(gr->cbl, attr_motion, (void *)&p);
- break;
- }
-
- case SDL_KEYDOWN:
- {
- memset(keybuf, 0, sizeof(keybuf));
- switch(ev.key.keysym.sym)
- {
- case SDLK_LEFT:
- {
- keybuf[0] = NAVIT_KEY_LEFT;
- break;
- }
- case SDLK_RIGHT:
- {
- keybuf[0] = NAVIT_KEY_RIGHT;
- break;
- }
- case SDLK_BACKSPACE:
- {
- keybuf[0] = NAVIT_KEY_BACKSPACE;
- break;
- }
- case SDLK_RETURN:
- {
- keybuf[0] = NAVIT_KEY_RETURN;
- break;
- }
- case SDLK_DOWN:
- {
- keybuf[0] = NAVIT_KEY_DOWN;
- break;
- }
- case SDLK_PAGEUP:
- {
- keybuf[0] = NAVIT_KEY_ZOOM_OUT;
- break;
- }
- case SDLK_UP:
- {
- keybuf[0] = NAVIT_KEY_UP;
- break;
- }
- case SDLK_PAGEDOWN:
- {
- keybuf[0] = NAVIT_KEY_ZOOM_IN;
- break;
- }
+ switch(ev.type) {
+ case SDL_MOUSEMOTION: {
+ p.x = ev.motion.x;
+ p.y = ev.motion.y;
+ callback_list_call_attr_1(gr->cbl, attr_motion, (void *)&p);
+ break;
+ }
+
+ case SDL_KEYDOWN: {
+ memset(keybuf, 0, sizeof(keybuf));
+ switch(ev.key.keysym.sym) {
+ case SDLK_LEFT: {
+ keybuf[0] = NAVIT_KEY_LEFT;
+ break;
+ }
+ case SDLK_RIGHT: {
+ keybuf[0] = NAVIT_KEY_RIGHT;
+ break;
+ }
+ case SDLK_BACKSPACE: {
+ keybuf[0] = NAVIT_KEY_BACKSPACE;
+ break;
+ }
+ case SDLK_RETURN: {
+ keybuf[0] = NAVIT_KEY_RETURN;
+ break;
+ }
+ case SDLK_DOWN: {
+ keybuf[0] = NAVIT_KEY_DOWN;
+ break;
+ }
+ case SDLK_PAGEUP: {
+ keybuf[0] = NAVIT_KEY_ZOOM_OUT;
+ break;
+ }
+ case SDLK_UP: {
+ keybuf[0] = NAVIT_KEY_UP;
+ break;
+ }
+ case SDLK_PAGEDOWN: {
+ keybuf[0] = NAVIT_KEY_ZOOM_IN;
+ break;
+ }
#ifdef USE_WEBOS
- case WEBOS_KEY_SHIFT:
- {
- if ((key_mod & WEBOS_KEY_MOD_SHIFT_STICKY) == WEBOS_KEY_MOD_SHIFT_STICKY)
- key_mod &= ~(WEBOS_KEY_MOD_SHIFT_STICKY);
- else if ((key_mod & WEBOS_KEY_MOD_SHIFT) == WEBOS_KEY_MOD_SHIFT)
- key_mod |= WEBOS_KEY_MOD_SHIFT_STICKY;
- else
- key_mod |= WEBOS_KEY_MOD_SHIFT;
- break;
- }
- case WEBOS_KEY_ORANGE:
- {
- if ((key_mod & WEBOS_KEY_MOD_ORANGE_STICKY) == WEBOS_KEY_MOD_ORANGE_STICKY)
- key_mod &= ~(WEBOS_KEY_MOD_ORANGE_STICKY);
- else if ((key_mod & WEBOS_KEY_MOD_ORANGE) == WEBOS_KEY_MOD_ORANGE)
- key_mod |= WEBOS_KEY_MOD_ORANGE_STICKY;
- else
- key_mod |= WEBOS_KEY_MOD_ORANGE;
- break;
- }
- case WEBOS_KEY_SYM:
- {
- /* Toggle the on-screen keyboard */
- //callback_list_call_attr_1(gr->cbl, attr_keyboard_toggle); // Not implemented yet
- break;
- }
- case PDLK_GESTURE_BACK:
- {
- keybuf[0] = NAVIT_KEY_BACK;
- break;
- }
- case PDLK_GESTURE_FORWARD:
- case PDLK_GESTURE_AREA:
- {
- break;
- }
+ case WEBOS_KEY_SHIFT: {
+ if ((key_mod & WEBOS_KEY_MOD_SHIFT_STICKY) == WEBOS_KEY_MOD_SHIFT_STICKY)
+ key_mod &= ~(WEBOS_KEY_MOD_SHIFT_STICKY);
+ else if ((key_mod & WEBOS_KEY_MOD_SHIFT) == WEBOS_KEY_MOD_SHIFT)
+ key_mod |= WEBOS_KEY_MOD_SHIFT_STICKY;
+ else
+ key_mod |= WEBOS_KEY_MOD_SHIFT;
+ break;
+ }
+ case WEBOS_KEY_ORANGE: {
+ if ((key_mod & WEBOS_KEY_MOD_ORANGE_STICKY) == WEBOS_KEY_MOD_ORANGE_STICKY)
+ key_mod &= ~(WEBOS_KEY_MOD_ORANGE_STICKY);
+ else if ((key_mod & WEBOS_KEY_MOD_ORANGE) == WEBOS_KEY_MOD_ORANGE)
+ key_mod |= WEBOS_KEY_MOD_ORANGE_STICKY;
+ else
+ key_mod |= WEBOS_KEY_MOD_ORANGE;
+ break;
+ }
+ case WEBOS_KEY_SYM: {
+ /* Toggle the on-screen keyboard */
+ //callback_list_call_attr_1(gr->cbl, attr_keyboard_toggle); // Not implemented yet
+ break;
+ }
+ case PDLK_GESTURE_BACK: {
+ keybuf[0] = NAVIT_KEY_BACK;
+ break;
+ }
+ case PDLK_GESTURE_FORWARD:
+ case PDLK_GESTURE_AREA: {
+ break;
+ }
#endif
- default:
- {
+ default: {
#ifdef USE_WEBOS
- if (ev.key.keysym.unicode < 0x80 && ev.key.keysym.unicode > 0) {
- keybuf[0] = (char)ev.key.keysym.unicode;
- if ((key_mod & WEBOS_KEY_MOD_ORANGE) == WEBOS_KEY_MOD_ORANGE) {
- switch(keybuf[0]) {
- case 'e': keybuf[0] = '1'; break;
- case 'r': keybuf[0] = '2'; break;
- case 't': keybuf[0] = '3'; break;
- case 'd': keybuf[0] = '4'; break;
- case 'f': keybuf[0] = '5'; break;
- case 'g': keybuf[0] = '6'; break;
- case 'x': keybuf[0] = '7'; break;
- case 'c': keybuf[0] = '8'; break;
- case 'v': keybuf[0] = '9'; break;
- case '@': keybuf[0] = '0'; break;
- case ',': keybuf[0] = '-'; break;
- case 'u': strncpy(keybuf, "ü", sizeof(keybuf)); break;
- case 'a': strncpy(keybuf, "ä", sizeof(keybuf)); break;
- case 'o': strncpy(keybuf, "ö", sizeof(keybuf)); break;
- case 's': strncpy(keybuf, "ß", sizeof(keybuf)); break;
- }
-}
- if ((key_mod & WEBOS_KEY_MOD_SHIFT_STICKY) != WEBOS_KEY_MOD_SHIFT_STICKY)
- key_mod &= ~(WEBOS_KEY_MOD_SHIFT_STICKY);
- if ((key_mod & WEBOS_KEY_MOD_ORANGE_STICKY) != WEBOS_KEY_MOD_ORANGE_STICKY)
- key_mod &= ~(WEBOS_KEY_MOD_ORANGE_STICKY);
- }
- else {
- dbg(lvl_error,"Unknown key sym: %x", ev.key.keysym.sym);
- }
+ if (ev.key.keysym.unicode < 0x80 && ev.key.keysym.unicode > 0) {
+ keybuf[0] = (char)ev.key.keysym.unicode;
+ if ((key_mod & WEBOS_KEY_MOD_ORANGE) == WEBOS_KEY_MOD_ORANGE) {
+ switch(keybuf[0]) {
+ case 'e':
+ keybuf[0] = '1';
+ break;
+ case 'r':
+ keybuf[0] = '2';
+ break;
+ case 't':
+ keybuf[0] = '3';
+ break;
+ case 'd':
+ keybuf[0] = '4';
+ break;
+ case 'f':
+ keybuf[0] = '5';
+ break;
+ case 'g':
+ keybuf[0] = '6';
+ break;
+ case 'x':
+ keybuf[0] = '7';
+ break;
+ case 'c':
+ keybuf[0] = '8';
+ break;
+ case 'v':
+ keybuf[0] = '9';
+ break;
+ case '@':
+ keybuf[0] = '0';
+ break;
+ case ',':
+ keybuf[0] = '-';
+ break;
+ case 'u':
+ strncpy(keybuf, "ü", sizeof(keybuf));
+ break;
+ case 'a':
+ strncpy(keybuf, "ä", sizeof(keybuf));
+ break;
+ case 'o':
+ strncpy(keybuf, "ö", sizeof(keybuf));
+ break;
+ case 's':
+ strncpy(keybuf, "ß", sizeof(keybuf));
+ break;
+ }
+ }
+ if ((key_mod & WEBOS_KEY_MOD_SHIFT_STICKY) != WEBOS_KEY_MOD_SHIFT_STICKY)
+ key_mod &= ~(WEBOS_KEY_MOD_SHIFT_STICKY);
+ if ((key_mod & WEBOS_KEY_MOD_ORANGE_STICKY) != WEBOS_KEY_MOD_ORANGE_STICKY)
+ key_mod &= ~(WEBOS_KEY_MOD_ORANGE_STICKY);
+ } else {
+ dbg(lvl_error,"Unknown key sym: %x", ev.key.keysym.sym);
+ }
#else
- /* return unicode chars when they can be converted to ascii */
- keybuf[0] = ev.key.keysym.unicode<=127 ? ev.key.keysym.unicode : 0;
+ /* return unicode chars when they can be converted to ascii */
+ keybuf[0] = ev.key.keysym.unicode<=127 ? ev.key.keysym.unicode : 0;
#endif
- break;
- }
- }
-
- dbg(lvl_info,"key mod: 0x%x", key_mod);
-
- if (keybuf[0]) {
- callback_list_call_attr_1(gr->cbl, attr_keypress, (void *)keybuf);
- }
- break;
- }
-
- case SDL_KEYUP:
- {
- break;
- }
-
- case SDL_MOUSEBUTTONDOWN:
- {
- dbg(lvl_debug, "SDL_MOUSEBUTTONDOWN %d %d %d %d %d",
- ev.button.which,
- ev.button.button,
- ev.button.state,
- ev.button.x,
- ev.button.y);
-
- p.x = ev.button.x;
- p.y = ev.button.y;
- callback_list_call_attr_3(gr->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER((int)ev.button.button), (void *)&p);
- break;
- }
-
- case SDL_MOUSEBUTTONUP:
- {
- dbg(lvl_debug, "SDL_MOUSEBUTTONUP %d %d %d %d %d",
- ev.button.which,
- ev.button.button,
- ev.button.state,
- ev.button.x,
- ev.button.y);
-
- p.x = ev.button.x;
- p.y = ev.button.y;
- callback_list_call_attr_3(gr->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER((int)ev.button.button), (void *)&p);
- break;
- }
-
- case SDL_QUIT:
- {
+ break;
+ }
+ }
+
+ dbg(lvl_info,"key mod: 0x%x", key_mod);
+
+ if (keybuf[0]) {
+ callback_list_call_attr_1(gr->cbl, attr_keypress, (void *)keybuf);
+ }
+ break;
+ }
+
+ case SDL_KEYUP: {
+ break;
+ }
+
+ case SDL_MOUSEBUTTONDOWN: {
+ dbg(lvl_debug, "SDL_MOUSEBUTTONDOWN %d %d %d %d %d",
+ ev.button.which,
+ ev.button.button,
+ ev.button.state,
+ ev.button.x,
+ ev.button.y);
+
+ p.x = ev.button.x;
+ p.y = ev.button.y;
+ callback_list_call_attr_3(gr->cbl, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER((int)ev.button.button), (void *)&p);
+ break;
+ }
+
+ case SDL_MOUSEBUTTONUP: {
+ dbg(lvl_debug, "SDL_MOUSEBUTTONUP %d %d %d %d %d",
+ ev.button.which,
+ ev.button.button,
+ ev.button.state,
+ ev.button.x,
+ ev.button.y);
+
+ p.x = ev.button.x;
+ p.y = ev.button.y;
+ callback_list_call_attr_3(gr->cbl, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER((int)ev.button.button), (void *)&p);
+ break;
+ }
+
+ case SDL_QUIT: {
#ifdef USE_WEBOS
- quit_event_loop = 1;
- navit_destroy(gr->nav);
+ quit_event_loop = 1;
+ navit_destroy(gr->nav);
#endif
- break;
- }
+ break;
+ }
- case SDL_VIDEORESIZE:
- {
+ case SDL_VIDEORESIZE: {
- gr->screen = SDL_SetVideoMode(ev.resize.w, ev.resize.h, gr->video_bpp, gr->video_flags);
- if(gr->screen == NULL)
- {
- navit_destroy(gr->nav);
- }
- else
- {
- callback_list_call_attr_2(gr->cbl, attr_resize, GINT_TO_POINTER(gr->screen->w), GINT_TO_POINTER(gr->screen->h));
- }
+ gr->screen = SDL_SetVideoMode(ev.resize.w, ev.resize.h, gr->video_bpp, gr->video_flags);
+ if(gr->screen == NULL) {
+ navit_destroy(gr->nav);
+ } else {
+ callback_list_call_attr_2(gr->cbl, attr_resize, GINT_TO_POINTER(gr->screen->w), GINT_TO_POINTER(gr->screen->h));
+ }
- break;
- }
+ break;
+ }
#ifdef USE_WEBOS
- case SDL_USEREVENT:
- {
- SDL_UserEvent userevent = ev.user;
- dbg(lvl_info,"received SDL_USEREVENT type(%x) code(%x)",userevent.type,userevent.code);
- if (userevent.type != SDL_USEREVENT)
- break;
-
- if (userevent.code == PDL_GPS_UPDATE)
- {
- struct attr vehicle_attr;
- struct vehicle *v;
- navit_get_attr(gr->nav, attr_vehicle, &vehicle_attr, NULL);
- v = vehicle_attr.u.vehicle;
- if (v) {
- struct attr attr;
- attr.type = attr_pdl_gps_update;
- attr.u.data = userevent.data1;
- vehicle_set_attr(v, &attr);
- }
- }
- else if(userevent.code == SDL_USEREVENT_CODE_TIMER)
- {
- struct callback *cb = (struct callback *)userevent.data1;
- dbg(lvl_debug, "SDL_USEREVENT timer received cb(%p)", cb);
- callback_call_0(cb);
- }
- else if(userevent.code == SDL_USEREVENT_CODE_WATCH)
- {
- struct callback *cb = (struct callback *)userevent.data1;
- dbg(lvl_debug, "SDL_USEREVENT watch received cb(%p)", cb);
- callback_call_0(cb);
- }
- else if(userevent.code == SDL_USEREVENT_CODE_CALL_CALLBACK)
- {
- struct callback_list *cbl = (struct callback_list *)userevent.data1;
- dbg(lvl_debug, "SDL_USEREVENT call_callback received cbl(%p)", cbl);
- callback_list_call_0(cbl);
- }
- else if(userevent.code == SDL_USEREVENT_CODE_IDLE_EVENT) {
- dbg(lvl_debug, "SDL_USEREVENT idle_event received");
- }
+ case SDL_USEREVENT: {
+ SDL_UserEvent userevent = ev.user;
+ dbg(lvl_info,"received SDL_USEREVENT type(%x) code(%x)",userevent.type,userevent.code);
+ if (userevent.type != SDL_USEREVENT)
+ break;
+
+ if (userevent.code == PDL_GPS_UPDATE) {
+ struct attr vehicle_attr;
+ struct vehicle *v;
+ navit_get_attr(gr->nav, attr_vehicle, &vehicle_attr, NULL);
+ v = vehicle_attr.u.vehicle;
+ if (v) {
+ struct attr attr;
+ attr.type = attr_pdl_gps_update;
+ attr.u.data = userevent.data1;
+ vehicle_set_attr(v, &attr);
+ }
+ } else if(userevent.code == SDL_USEREVENT_CODE_TIMER) {
+ struct callback *cb = (struct callback *)userevent.data1;
+ dbg(lvl_debug, "SDL_USEREVENT timer received cb(%p)", cb);
+ callback_call_0(cb);
+ } else if(userevent.code == SDL_USEREVENT_CODE_WATCH) {
+ struct callback *cb = (struct callback *)userevent.data1;
+ dbg(lvl_debug, "SDL_USEREVENT watch received cb(%p)", cb);
+ callback_call_0(cb);
+ } else if(userevent.code == SDL_USEREVENT_CODE_CALL_CALLBACK) {
+ struct callback_list *cbl = (struct callback_list *)userevent.data1;
+ dbg(lvl_debug, "SDL_USEREVENT call_callback received cbl(%p)", cbl);
+ callback_list_call_0(cbl);
+ } else if(userevent.code == SDL_USEREVENT_CODE_IDLE_EVENT) {
+ dbg(lvl_debug, "SDL_USEREVENT idle_event received");
+ }
#ifdef USE_WEBOS_ACCELEROMETER
- else if(userevent.code == SDL_USEREVENT_CODE_ROTATE)
- {
- dbg(lvl_debug, "SDL_USEREVENT rotate received");
- switch(gr->orientation)
- {
- case WEBOS_ORIENTATION_PORTRAIT:
- gr->screen = SDL_SetVideoMode(gr->real_w, gr->real_h, gr->video_bpp, gr->video_flags);
- PDL_SetOrientation(PDL_ORIENTATION_0);
- break;
- case WEBOS_ORIENTATION_LANDSCAPE:
- gr->screen = SDL_SetVideoMode(gr->real_h, gr->real_w, gr->video_bpp, gr->video_flags);
- PDL_SetOrientation(PDL_ORIENTATION_270);
- break;
- }
- if(gr->screen == NULL)
- {
- navit_destroy(gr->nav);
- }
- else
- {
- callback_list_call_attr_2(gr->cbl, attr_resize, (void *)gr->screen->w, (void *)gr->screen->h);
- }
- }
+ else if(userevent.code == SDL_USEREVENT_CODE_ROTATE) {
+ dbg(lvl_debug, "SDL_USEREVENT rotate received");
+ switch(gr->orientation) {
+ case WEBOS_ORIENTATION_PORTRAIT:
+ gr->screen = SDL_SetVideoMode(gr->real_w, gr->real_h, gr->video_bpp, gr->video_flags);
+ PDL_SetOrientation(PDL_ORIENTATION_0);
+ break;
+ case WEBOS_ORIENTATION_LANDSCAPE:
+ gr->screen = SDL_SetVideoMode(gr->real_h, gr->real_w, gr->video_bpp, gr->video_flags);
+ PDL_SetOrientation(PDL_ORIENTATION_270);
+ break;
+ }
+ if(gr->screen == NULL) {
+ navit_destroy(gr->nav);
+ } else {
+ callback_list_call_attr_2(gr->cbl, attr_resize, (void *)gr->screen->w, (void *)gr->screen->h);
+ }
+ }
#endif
- else
- dbg(lvl_warning, "unknown SDL_USEREVENT");
+ else
+ dbg(lvl_warning, "unknown SDL_USEREVENT");
- break;
- }
+ break;
+ }
#endif
- default:
- {
- dbg(lvl_debug, "SDL_Event %d", ev.type);
- break;
- }
- }
+ default: {
+ dbg(lvl_debug, "SDL_Event %d", ev.type);
+ break;
+ }
+ }
}
#ifdef USE_WEBOS
@@ -1385,8 +1295,8 @@ static gboolean graphics_sdl_idle(void *data)
#ifdef USE_WEBOS_ACCELEROMETER
if (PDL_GetPDKVersion() > 100) {
- event_remove_timeout(accel_to);
- callback_destroy(accel_cb);
+ event_remove_timeout(accel_to);
+ callback_destroy(accel_cb);
}
#endif
@@ -1395,8 +1305,7 @@ static gboolean graphics_sdl_idle(void *data)
static struct graphics_priv *
-graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
+graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl) {
struct graphics_priv *this=g_new0(struct graphics_priv, 1);
struct font_priv *(*font_freetype_new) (void *meth);
struct attr *attr;
@@ -1409,19 +1318,19 @@ graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr *
/* initialize fonts */
font_freetype_new = plugin_get_category_font("freetype");
- if (!font_freetype_new) {
- g_free(this);
- return NULL;
- }
+ if (!font_freetype_new) {
+ g_free(this);
+ return NULL;
+ }
- font_freetype_new(&this->freetype_methods);
+ font_freetype_new(&this->freetype_methods);
- *meth = graphics_methods;
+ *meth = graphics_methods;
- meth->font_new = (struct graphics_font_priv *
- (*)(struct graphics_priv *, struct graphics_font_methods *, char *, int,
- int)) this->freetype_methods.font_new;
- meth->get_text_bbox = (void*) this->freetype_methods.get_text_bbox;
+ meth->font_new = (struct graphics_font_priv *
+ (*)(struct graphics_priv *, struct graphics_font_methods *, char *, int,
+ int)) this->freetype_methods.font_new;
+ meth->get_text_bbox = (void*) this->freetype_methods.get_text_bbox;
dbg(lvl_debug,"Calling SDL_Init");
#ifdef USE_WEBOS
@@ -1433,10 +1342,9 @@ graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr *
#else
ret = SDL_Init(SDL_INIT_VIDEO);
#endif
- if(ret < 0)
- {
- dbg(lvl_error,"SDL_Init failed %d", ret);
- this->freetype_methods.destroy();
+ if(ret < 0) {
+ dbg(lvl_error,"SDL_Init failed %d", ret);
+ this->freetype_methods.destroy();
g_free(this);
return NULL;
}
@@ -1444,10 +1352,9 @@ graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr *
#ifdef USE_WEBOS
dbg(lvl_debug,"Calling PDL_Init(0)");
ret = PDL_Init(0);
- if(ret < 0)
- {
- dbg(lvl_error,"PDL_Init failed %d", ret);
- this->freetype_methods.destroy();
+ if(ret < 0) {
+ dbg(lvl_error,"PDL_Init failed %d", ret);
+ this->freetype_methods.destroy();
g_free(this);
return NULL;
}
@@ -1456,9 +1363,9 @@ graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr *
#else
if (! event_request_system("glib","graphics_sdl_new")) {
#endif
- dbg(lvl_error,"event_request_system failed");
- this->freetype_methods.destroy();
- g_free(this);
+ dbg(lvl_error,"event_request_system failed");
+ this->freetype_methods.destroy();
+ g_free(this);
return NULL;
}
@@ -1477,8 +1384,8 @@ graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr *
if ((attr=attr_search(attrs, NULL, attr_bpp)))
this->video_bpp=attr->u.num;
if ((attr=attr_search(attrs, NULL, attr_flags))) {
- if (attr->u.num & 1)
- this->video_flags = SDL_SWSURFACE;
+ if (attr->u.num & 1)
+ this->video_flags = SDL_SWSURFACE;
}
if ((attr=attr_search(attrs, NULL, attr_frame))) {
if(!attr->u.num)
@@ -1487,10 +1394,9 @@ graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr *
this->screen = SDL_SetVideoMode(w, h, this->video_bpp, this->video_flags);
- if(this->screen == NULL)
- {
- dbg(lvl_error,"SDL_SetVideoMode failed");
- this->freetype_methods.destroy();
+ if(this->screen == NULL) {
+ dbg(lvl_error,"SDL_SetVideoMode failed");
+ this->freetype_methods.destroy();
g_free(this);
#ifdef USE_WEBOS
PDL_Quit();
@@ -1504,18 +1410,17 @@ graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr *
h = this->screen->h;
dbg(lvl_debug, "using screen %ix%i@%i",
- this->screen->w, this->screen->h,
- this->screen->format->BytesPerPixel * 8);
+ this->screen->w, this->screen->h,
+ this->screen->format->BytesPerPixel * 8);
#ifdef USE_WEBOS_ACCELEROMETER
if ( w > h ) {
- this->orientation = WEBOS_ORIENTATION_LANDSCAPE;
- this->real_w = h;
- this->real_h = w;
- }
- else {
- this->orientation = WEBOS_ORIENTATION_PORTRAIT;
- this->real_w = w;
- this->real_h = h;
+ this->orientation = WEBOS_ORIENTATION_LANDSCAPE;
+ this->real_w = h;
+ this->real_h = w;
+ } else {
+ this->orientation = WEBOS_ORIENTATION_PORTRAIT;
+ this->real_w = w;
+ this->real_h = h;
}
this->accelerometer = SDL_JoystickOpen(0);
#endif
@@ -1530,7 +1435,7 @@ graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr *
#ifdef USE_WEBOS
if(the_graphics!=NULL) {
- dbg(lvl_debug,"graphics_sdl_new: graphics struct already set: %d!", the_graphics_count);
+ dbg(lvl_debug,"graphics_sdl_new: graphics struct already set: %d!", the_graphics_count);
}
the_graphics = this;
the_graphics_count++;
@@ -1552,8 +1457,7 @@ graphics_sdl_new(struct navit *nav, struct graphics_methods *meth, struct attr *
/* ---------- SDL Eventhandling ---------- */
static Uint32
-sdl_timer_callback(Uint32 interval, void* param)
-{
+sdl_timer_callback(Uint32 interval, void* param) {
struct event_timeout *timeout=(struct event_timeout*)param;
dbg(lvl_debug,"timer(%p) multi(%d) interval(%d) fired", param, timeout->multi, interval);
@@ -1572,8 +1476,8 @@ sdl_timer_callback(Uint32 interval, void* param)
SDL_PushEvent (&event);
if (timeout->multi == 0) {
- timeout->id = 0;
- return 0; // cancel timer
+ timeout->id = 0;
+ return 0; // cancel timer
}
return interval; // reactivate timer
}
@@ -1581,54 +1485,51 @@ sdl_timer_callback(Uint32 interval, void* param)
/* SDL Mainloop */
static void
-event_sdl_main_loop_run(void)
-{
+event_sdl_main_loop_run(void) {
PDL_ScreenTimeoutEnable(PDL_FALSE);
graphics_sdl_idle(NULL);
PDL_ScreenTimeoutEnable(PDL_TRUE);
}
static void
-event_sdl_main_loop_quit(void)
-{
+event_sdl_main_loop_quit(void) {
quit_event_loop = 1;
}
/* Watch */
static void
-event_sdl_watch_thread (GPtrArray *watch_list)
-{
+event_sdl_watch_thread (GPtrArray *watch_list) {
struct pollfd *pfds = g_new0 (struct pollfd, watch_list->len);
struct event_watch *ew;
int ret;
int idx;
for (idx = 0; idx < watch_list->len; idx++ ) {
- ew = g_ptr_array_index (watch_list, idx);
- g_memmove (&pfds[idx], ew->pfd, sizeof(struct pollfd));
+ ew = g_ptr_array_index (watch_list, idx);
+ g_memmove (&pfds[idx], ew->pfd, sizeof(struct pollfd));
}
while ((ret = ppoll(pfds, watch_list->len, NULL, NULL)) > 0) {
- for (idx = 0; idx < watch_list->len; idx++ ) {
- if (pfds[idx].revents == pfds[idx].events) { /* The requested event happened, notify mainloop! */
- ew = g_ptr_array_index (watch_list, idx);
- dbg(lvl_debug,"watch(%p) event(%d) encountered", ew, pfds[idx].revents);
+ for (idx = 0; idx < watch_list->len; idx++ ) {
+ if (pfds[idx].revents == pfds[idx].events) { /* The requested event happened, notify mainloop! */
+ ew = g_ptr_array_index (watch_list, idx);
+ dbg(lvl_debug,"watch(%p) event(%d) encountered", ew, pfds[idx].revents);
- SDL_Event event;
- SDL_UserEvent userevent;
+ SDL_Event event;
+ SDL_UserEvent userevent;
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_WATCH;
- userevent.data1 = ew->cb;
- userevent.data2 = NULL;
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_WATCH;
+ userevent.data1 = ew->cb;
+ userevent.data2 = NULL;
- event.type = SDL_USEREVENT;
- event.user = userevent;
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
- SDL_PushEvent (&event);
- }
- }
+ SDL_PushEvent (&event);
+ }
+ }
}
g_free(pfds);
@@ -1637,11 +1538,10 @@ event_sdl_watch_thread (GPtrArray *watch_list)
}
static void
-event_sdl_watch_startthread(GPtrArray *watch_list)
-{
+event_sdl_watch_startthread(GPtrArray *watch_list) {
dbg(lvl_debug,"enter");
if (sdl_watch_thread)
- event_sdl_watch_stopthread();
+ event_sdl_watch_stopthread();
int ret;
ret = pthread_create (&sdl_watch_thread, NULL, (void *)event_sdl_watch_thread, (void *)watch_list);
@@ -1650,26 +1550,24 @@ event_sdl_watch_startthread(GPtrArray *watch_list)
}
static void
-event_sdl_watch_stopthread()
-{
+event_sdl_watch_stopthread() {
dbg(lvl_debug,"enter");
if (sdl_watch_thread) {
- /* Notify the watch thread that the list of FDs will change */
- pthread_kill(sdl_watch_thread, SIGUSR1);
- pthread_join(sdl_watch_thread, NULL);
- sdl_watch_thread = 0;
+ /* Notify the watch thread that the list of FDs will change */
+ pthread_kill(sdl_watch_thread, SIGUSR1);
+ pthread_join(sdl_watch_thread, NULL);
+ sdl_watch_thread = 0;
}
}
static struct event_watch *
-event_sdl_add_watch(int fd, enum event_watch_cond cond, struct callback *cb)
-{
+event_sdl_add_watch(int fd, enum event_watch_cond cond, struct callback *cb) {
dbg(lvl_debug,"fd(%d) cond(%x) cb(%x)", fd, cond, cb);
event_sdl_watch_stopthread();
if (!sdl_watch_list)
- sdl_watch_list = g_ptr_array_new();
+ sdl_watch_list = g_ptr_array_new();
struct event_watch *new_ew = g_new0 (struct event_watch, 1);
struct pollfd *pfd = g_new0 (struct pollfd, 1);
@@ -1678,15 +1576,15 @@ event_sdl_add_watch(int fd, enum event_watch_cond cond, struct callback *cb)
/* Modify watchlist here */
switch (cond) {
- case event_watch_cond_read:
- pfd->events = POLLIN;
- break;
- case event_watch_cond_write:
- pfd->events = POLLOUT;
- break;
- case event_watch_cond_except:
- pfd->events = POLLERR|POLLHUP;
- break;
+ case event_watch_cond_read:
+ pfd->events = POLLIN;
+ break;
+ case event_watch_cond_write:
+ pfd->events = POLLOUT;
+ break;
+ case event_watch_cond_except:
+ pfd->events = POLLERR|POLLHUP;
+ break;
}
new_ew->pfd = (struct pollfd*) pfd;
@@ -1700,8 +1598,7 @@ event_sdl_add_watch(int fd, enum event_watch_cond cond, struct callback *cb)
}
static void
-event_sdl_remove_watch(struct event_watch *ew)
-{
+event_sdl_remove_watch(struct event_watch *ew) {
dbg(lvl_debug,"enter %p",ew);
event_sdl_watch_stopthread();
@@ -1711,18 +1608,17 @@ event_sdl_remove_watch(struct event_watch *ew)
g_free (ew);
if (sdl_watch_list->len > 0)
- event_sdl_watch_startthread(sdl_watch_list);
+ event_sdl_watch_startthread(sdl_watch_list);
}
/* Timeout */
static struct event_timeout *
-event_sdl_add_timeout(int timeout, int multi, struct callback *cb)
-{
+event_sdl_add_timeout(int timeout, int multi, struct callback *cb) {
struct event_timeout * ret = g_new0(struct event_timeout, 1);
if(!ret) {
- dbg(lvl_error,"g_new0 failed");
- return ret;
+ dbg(lvl_error,"g_new0 failed");
+ return ret;
}
dbg(lvl_debug,"timer(%p) multi(%d) interval(%d) cb(%p) added",ret, multi, timeout, cb);
ret->multi = multi;
@@ -1733,19 +1629,17 @@ event_sdl_add_timeout(int timeout, int multi, struct callback *cb)
}
static void
-event_sdl_remove_timeout(struct event_timeout *to)
-{
+event_sdl_remove_timeout(struct event_timeout *to) {
dbg(lvl_info,"enter %p", to);
- if(to)
- {
- /* do not SDL_RemoveTimer if oneshot timer has already fired */
- int ret = to->id == 0 ? SDL_TRUE : SDL_RemoveTimer(to->id);
+ if(to) {
+ /* do not SDL_RemoveTimer if oneshot timer has already fired */
+ int ret = to->id == 0 ? SDL_TRUE : SDL_RemoveTimer(to->id);
if (ret == SDL_FALSE)
- dbg(lvl_error,"SDL_RemoveTimer (%p) failed", to->id);
+ dbg(lvl_error,"SDL_RemoveTimer (%p) failed", to->id);
- g_free(to);
- dbg(lvl_debug,"timer(%p) removed", to);
+ g_free(to);
+ dbg(lvl_debug,"timer(%p) removed", to);
}
}
@@ -1753,20 +1647,18 @@ event_sdl_remove_timeout(struct event_timeout *to)
/* sort ptr_array by priority, increasing order */
static gint
-sdl_sort_idle_tasks(gconstpointer parama, gconstpointer paramb)
-{
+sdl_sort_idle_tasks(gconstpointer parama, gconstpointer paramb) {
struct idle_task *a = (struct idle_task *)parama;
struct idle_task *b = (struct idle_task *)paramb;
if (a->priority < b->priority)
- return -1;
+ return -1;
if (a->priority > b->priority)
- return 1;
+ return 1;
return 0;
}
static struct event_idle *
-event_sdl_add_idle(int priority, struct callback *cb)
-{
+event_sdl_add_idle(int priority, struct callback *cb) {
dbg(lvl_debug,"add idle priority(%d) cb(%p)", priority, cb);
struct idle_task *task = g_new0(struct idle_task, 1);
@@ -1775,32 +1667,29 @@ event_sdl_add_idle(int priority, struct callback *cb)
g_ptr_array_add(idle_tasks, (gpointer)task);
- if (idle_tasks->len < 2)
- {
- SDL_Event event;
- SDL_UserEvent userevent;
+ if (idle_tasks->len < 2) {
+ SDL_Event event;
+ SDL_UserEvent userevent;
- dbg(lvl_debug,"poking eventloop because of new idle_events");
+ dbg(lvl_debug,"poking eventloop because of new idle_events");
- userevent.type = SDL_USEREVENT;
- userevent.code = SDL_USEREVENT_CODE_IDLE_EVENT;
- userevent.data1 = NULL;
- userevent.data2 = NULL;
+ userevent.type = SDL_USEREVENT;
+ userevent.code = SDL_USEREVENT_CODE_IDLE_EVENT;
+ userevent.data1 = NULL;
+ userevent.data2 = NULL;
- event.type = SDL_USEREVENT;
- event.user = userevent;
+ event.type = SDL_USEREVENT;
+ event.user = userevent;
- SDL_PushEvent (&event);
- }
- else // more than one entry => sort the list
- g_ptr_array_sort(idle_tasks, sdl_sort_idle_tasks);
+ SDL_PushEvent (&event);
+ } else // more than one entry => sort the list
+ g_ptr_array_sort(idle_tasks, sdl_sort_idle_tasks);
return (struct event_idle *)task;
}
static void
-event_sdl_remove_idle(struct event_idle *task)
-{
+event_sdl_remove_idle(struct event_idle *task) {
dbg(lvl_debug,"remove task(%p)", task);
g_ptr_array_remove(idle_tasks, (gpointer)task);
}
@@ -1808,8 +1697,7 @@ event_sdl_remove_idle(struct event_idle *task)
/* callback */
static void
-event_sdl_call_callback(struct callback_list *cbl)
-{
+event_sdl_call_callback(struct callback_list *cbl) {
dbg(lvl_debug,"call_callback cbl(%p)",cbl);
SDL_Event event;
SDL_UserEvent userevent;
@@ -1838,8 +1726,7 @@ static struct event_methods event_sdl_methods = {
};
static struct event_priv *
-event_sdl_new(struct event_methods* methods)
-{
+event_sdl_new(struct event_methods* methods) {
idle_tasks = g_ptr_array_new();
*methods = event_sdl_methods;
return NULL;
@@ -1849,8 +1736,7 @@ event_sdl_new(struct event_methods* methods)
#endif
void
-plugin_init(void)
-{
+plugin_init(void) {
#ifdef USE_WEBOS
plugin_register_category_event("sdl", event_sdl_new);
#endif
diff --git a/navit/graphics/sdl/raster.c b/navit/graphics/sdl/raster.c
index 82c79212c..6c713844b 100644
--- a/navit/graphics/sdl/raster.c
+++ b/navit/graphics/sdl/raster.c
@@ -25,49 +25,37 @@
/* raster_rect */
-static inline void raster_rect_inline(SDL_Surface *dst, int16_t x1, int16_t y1, int16_t w, int16_t h, uint32_t color)
-{
+static inline void raster_rect_inline(SDL_Surface *dst, int16_t x1, int16_t y1, int16_t w, int16_t h, uint32_t color) {
/* sge */
SDL_Rect rect;
#if 1
- if((w <= 0) || (h <= 0))
- {
+ if((w <= 0) || (h <= 0)) {
return;
}
#if 0
- if(x1 < 0)
- {
- if((x1 + w) < 0)
- {
+ if(x1 < 0) {
+ if((x1 + w) < 0) {
return;
- }
- else
- {
+ } else {
w = w + x1;
x1 = 0;
}
}
- if(y1 < 0)
- {
- if((y1 + h) < 0)
- {
+ if(y1 < 0) {
+ if((y1 + h) < 0) {
return;
- }
- else
- {
+ } else {
h = h + y1;
y1 = 0;
}
}
- if(x1 + w >= dst->w)
- {
+ if(x1 + w >= dst->w) {
w = dst->w - x1;
}
- if(y1 + h >= dst->h)
- {
+ if(y1 + h >= dst->h) {
h = dst->h - y1;
}
#endif
@@ -87,172 +75,171 @@ static inline void raster_rect_inline(SDL_Surface *dst, int16_t x1, int16_t y1,
/*
* Order coordinates to ensure that
- * x1<=x2 and y1<=y2
+ * x1<=x2 and y1<=y2
*/
if (x1 > x2) {
- tmp = x1;
- x1 = x2;
- x2 = tmp;
+ tmp = x1;
+ x1 = x2;
+ x2 = tmp;
}
if (y1 > y2) {
- tmp = y1;
- y1 = y2;
- y2 = tmp;
+ tmp = y1;
+ y1 = y2;
+ y2 = tmp;
}
- /*
- * Get clipping boundary and
- * check visibility
+ /*
+ * Get clipping boundary and
+ * check visibility
*/
left = dst->clip_rect.x;
if (x2<left) {
- return(0);
+ return(0);
}
right = dst->clip_rect.x + dst->clip_rect.w - 1;
if (x1>right) {
- return(0);
+ return(0);
}
top = dst->clip_rect.y;
if (y2<top) {
- return(0);
+ return(0);
}
bottom = dst->clip_rect.y + dst->clip_rect.h - 1;
if (y1>bottom) {
- return(0);
+ return(0);
}
-
+
/* Clip all points */
- if (x1<left) {
- x1=left;
+ if (x1<left) {
+ x1=left;
} else if (x1>right) {
- x1=right;
+ x1=right;
}
- if (x2<left) {
- x2=left;
+ if (x2<left) {
+ x2=left;
} else if (x2>right) {
- x2=right;
+ x2=right;
}
- if (y1<top) {
- y1=top;
+ if (y1<top) {
+ y1=top;
} else if (y1>bottom) {
- y1=bottom;
+ y1=bottom;
}
- if (y2<top) {
- y2=top;
+ if (y2<top) {
+ y2=top;
} else if (y2>bottom) {
- y2=bottom;
+ y2=bottom;
}
#if 0
/*
- * Test for special cases of straight line or single point
+ * Test for special cases of straight line or single point
*/
if (x1 == x2) {
- if (y1 == y2) {
- return (pixelColor(dst, x1, y1, color));
- } else {
- return (vlineColor(dst, x1, y1, y2, color));
- }
+ if (y1 == y2) {
+ return (pixelColor(dst, x1, y1, color));
+ } else {
+ return (vlineColor(dst, x1, y1, y2, color));
+ }
}
if (y1 == y2) {
- return (hlineColor(dst, x1, x2, y1, color));
+ return (hlineColor(dst, x1, x2, y1, color));
}
#endif
/*
- * Calculate width&height
+ * Calculate width&height
*/
w = x2 - x1;
h = y2 - y1;
- /*
- * No alpha-blending required
- */
+ /*
+ * No alpha-blending required
+ */
#if 0
- /*
- * Setup color
- */
- colorptr = (Uint8 *) & color;
- if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
- color = SDL_MapRGBA(dst->format, colorptr[0], colorptr[1], colorptr[2], colorptr[3]);
- } else {
- color = SDL_MapRGBA(dst->format, colorptr[3], colorptr[2], colorptr[1], colorptr[0]);
- }
+ /*
+ * Setup color
+ */
+ colorptr = (Uint8 *) & color;
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
+ color = SDL_MapRGBA(dst->format, colorptr[0], colorptr[1], colorptr[2], colorptr[3]);
+ } else {
+ color = SDL_MapRGBA(dst->format, colorptr[3], colorptr[2], colorptr[1], colorptr[0]);
+ }
#endif
- /*
- * Lock surface
- */
- SDL_LockSurface(dst);
-
- /*
- * More variable setup
- */
- dx = w;
- dy = h;
- pixx = dst->format->BytesPerPixel;
- pixy = dst->pitch;
- pixel = ((Uint8 *) dst->pixels) + pixx * (int) x1 + pixy * (int) y1;
- pixellast = pixel + pixx * dx + pixy * dy;
- dx++;
-
- /*
- * Draw
- */
- switch (dst->format->BytesPerPixel) {
- case 1:
- for (; pixel <= pixellast; pixel += pixy) {
- memset(pixel, (Uint8) color, dx);
- }
- break;
- case 2:
- pixy -= (pixx * dx);
- for (; pixel <= pixellast; pixel += pixy) {
- for (x = 0; x < dx; x++) {
- *(Uint16*) pixel = color;
- pixel += pixx;
- }
- }
- break;
- case 3:
- pixy -= (pixx * dx);
- for (; pixel <= pixellast; pixel += pixy) {
- for (x = 0; x < dx; x++) {
- if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
- pixel[0] = (color >> 16) & 0xff;
- pixel[1] = (color >> 8) & 0xff;
- pixel[2] = color & 0xff;
- } else {
- pixel[0] = color & 0xff;
- pixel[1] = (color >> 8) & 0xff;
- pixel[2] = (color >> 16) & 0xff;
- }
- pixel += pixx;
- }
- }
- break;
- default: /* case 4 */
- pixy -= (pixx * dx);
- for (; pixel <= pixellast; pixel += pixy) {
- for (x = 0; x < dx; x++) {
- *(Uint32 *) pixel = color;
- pixel += pixx;
- }
- }
- break;
- }
-
- /*
- * Unlock surface
- */
- SDL_UnlockSurface(dst);
+ /*
+ * Lock surface
+ */
+ SDL_LockSurface(dst);
+
+ /*
+ * More variable setup
+ */
+ dx = w;
+ dy = h;
+ pixx = dst->format->BytesPerPixel;
+ pixy = dst->pitch;
+ pixel = ((Uint8 *) dst->pixels) + pixx * (int) x1 + pixy * (int) y1;
+ pixellast = pixel + pixx * dx + pixy * dy;
+ dx++;
+
+ /*
+ * Draw
+ */
+ switch (dst->format->BytesPerPixel) {
+ case 1:
+ for (; pixel <= pixellast; pixel += pixy) {
+ memset(pixel, (Uint8) color, dx);
+ }
+ break;
+ case 2:
+ pixy -= (pixx * dx);
+ for (; pixel <= pixellast; pixel += pixy) {
+ for (x = 0; x < dx; x++) {
+ *(Uint16*) pixel = color;
+ pixel += pixx;
+ }
+ }
+ break;
+ case 3:
+ pixy -= (pixx * dx);
+ for (; pixel <= pixellast; pixel += pixy) {
+ for (x = 0; x < dx; x++) {
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
+ pixel[0] = (color >> 16) & 0xff;
+ pixel[1] = (color >> 8) & 0xff;
+ pixel[2] = color & 0xff;
+ } else {
+ pixel[0] = color & 0xff;
+ pixel[1] = (color >> 8) & 0xff;
+ pixel[2] = (color >> 16) & 0xff;
+ }
+ pixel += pixx;
+ }
+ }
+ break;
+ default: /* case 4 */
+ pixy -= (pixx * dx);
+ for (; pixel <= pixellast; pixel += pixy) {
+ for (x = 0; x < dx; x++) {
+ *(Uint32 *) pixel = color;
+ pixel += pixx;
+ }
+ }
+ break;
+ }
+
+ /*
+ * Unlock surface
+ */
+ SDL_UnlockSurface(dst);
#endif
}
-void raster_rect(SDL_Surface *s, int16_t x, int16_t y, int16_t w, int16_t h, uint32_t col)
-{
+void raster_rect(SDL_Surface *s, int16_t x, int16_t y, int16_t w, int16_t h, uint32_t col) {
raster_rect_inline(s, x, y, w, h, col);
}
@@ -270,222 +257,219 @@ void raster_rect(SDL_Surface *s, int16_t x, int16_t y, int16_t w, int16_t h, uin
#define clip_ymax(surface) surface->clip_rect.y+surface->clip_rect.h-1
-static void raster_PutPixel(SDL_Surface *surface, Sint16 x, Sint16 y, Uint32 color)
-{
- if(x>=clip_xmin(surface) && x<=clip_xmax(surface) && y>=clip_ymin(surface) && y<=clip_ymax(surface)){
- switch (surface->format->BytesPerPixel) {
- case 1: { /* Assuming 8-bpp */
- *((Uint8 *)surface->pixels + y*surface->pitch + x) = color;
- }
- break;
-
- case 2: { /* Probably 15-bpp or 16-bpp */
- *((Uint16 *)surface->pixels + y*surface->pitch/2 + x) = color;
- }
- break;
-
- case 3: { /* Slow 24-bpp mode, usually not used */
- Uint8 *pix = (Uint8 *)surface->pixels + y * surface->pitch + x*3;
-
- /* Gack - slow, but endian correct */
- *(pix+surface->format->Rshift/8) = color>>surface->format->Rshift;
- *(pix+surface->format->Gshift/8) = color>>surface->format->Gshift;
- *(pix+surface->format->Bshift/8) = color>>surface->format->Bshift;
- *(pix+surface->format->Ashift/8) = color>>surface->format->Ashift;
- }
- break;
-
- case 4: { /* Probably 32-bpp */
- *((Uint32 *)surface->pixels + y*surface->pitch/4 + x) = color;
- }
- break;
- }
- }
+static void raster_PutPixel(SDL_Surface *surface, Sint16 x, Sint16 y, Uint32 color) {
+ if(x>=clip_xmin(surface) && x<=clip_xmax(surface) && y>=clip_ymin(surface) && y<=clip_ymax(surface)) {
+ switch (surface->format->BytesPerPixel) {
+ case 1: { /* Assuming 8-bpp */
+ *((Uint8 *)surface->pixels + y*surface->pitch + x) = color;
+ }
+ break;
+
+ case 2: { /* Probably 15-bpp or 16-bpp */
+ *((Uint16 *)surface->pixels + y*surface->pitch/2 + x) = color;
+ }
+ break;
+
+ case 3: { /* Slow 24-bpp mode, usually not used */
+ Uint8 *pix = (Uint8 *)surface->pixels + y * surface->pitch + x*3;
+
+ /* Gack - slow, but endian correct */
+ *(pix+surface->format->Rshift/8) = color>>surface->format->Rshift;
+ *(pix+surface->format->Gshift/8) = color>>surface->format->Gshift;
+ *(pix+surface->format->Bshift/8) = color>>surface->format->Bshift;
+ *(pix+surface->format->Ashift/8) = color>>surface->format->Ashift;
+ }
+ break;
+
+ case 4: { /* Probably 32-bpp */
+ *((Uint32 *)surface->pixels + y*surface->pitch/4 + x) = color;
+ }
+ break;
+ }
+ }
}
/* PutPixel routine with alpha blending, input color in destination format */
/* New, faster routine - default blending pixel */
-static void raster_PutPixelAlpha(SDL_Surface * surface, Sint16 x, Sint16 y, Uint32 color, Uint8 alpha)
-{
+static void raster_PutPixelAlpha(SDL_Surface * surface, Sint16 x, Sint16 y, Uint32 color, Uint8 alpha) {
/* sdl-gfx */
Uint32 Rmask = surface->format->Rmask, Gmask =
- surface->format->Gmask, Bmask = surface->format->Bmask, Amask = surface->format->Amask;
+ surface->format->Gmask, Bmask = surface->format->Bmask, Amask = surface->format->Amask;
Uint32 R = 0, G = 0, B = 0, A = 0;
if (x >= clip_xmin(surface) && x <= clip_xmax(surface)
- && y >= clip_ymin(surface) && y <= clip_ymax(surface)) {
-
- switch (surface->format->BytesPerPixel) {
- case 1:{ /* Assuming 8-bpp */
- if (alpha == 255) {
- *((Uint8 *) surface->pixels + y * surface->pitch + x) = color;
- } else {
- Uint8 *pixel = (Uint8 *) surface->pixels + y * surface->pitch + x;
-
- Uint8 dR = surface->format->palette->colors[*pixel].r;
- Uint8 dG = surface->format->palette->colors[*pixel].g;
- Uint8 dB = surface->format->palette->colors[*pixel].b;
- Uint8 sR = surface->format->palette->colors[color].r;
- Uint8 sG = surface->format->palette->colors[color].g;
- Uint8 sB = surface->format->palette->colors[color].b;
-
- dR = dR + ((sR - dR) * alpha >> 8);
- dG = dG + ((sG - dG) * alpha >> 8);
- dB = dB + ((sB - dB) * alpha >> 8);
-
- *pixel = SDL_MapRGB(surface->format, dR, dG, dB);
- }
- }
- break;
-
- case 2:{ /* Probably 15-bpp or 16-bpp */
- if (alpha == 255) {
- *((Uint16 *) surface->pixels + y * surface->pitch / 2 + x) = color;
- } else {
- Uint16 *pixel = (Uint16 *) surface->pixels + y * surface->pitch / 2 + x;
- Uint32 dc = *pixel;
-
- R = ((dc & Rmask) + (((color & Rmask) - (dc & Rmask)) * alpha >> 8)) & Rmask;
- G = ((dc & Gmask) + (((color & Gmask) - (dc & Gmask)) * alpha >> 8)) & Gmask;
- B = ((dc & Bmask) + (((color & Bmask) - (dc & Bmask)) * alpha >> 8)) & Bmask;
- if (Amask)
- A = ((dc & Amask) + (((color & Amask) - (dc & Amask)) * alpha >> 8)) & Amask;
-
- *pixel = R | G | B | A;
- }
- }
- break;
-
- case 3:{ /* Slow 24-bpp mode, usually not used */
- Uint8 *pix = (Uint8 *) surface->pixels + y * surface->pitch + x * 3;
- Uint8 rshift8 = surface->format->Rshift / 8;
- Uint8 gshift8 = surface->format->Gshift / 8;
- Uint8 bshift8 = surface->format->Bshift / 8;
- Uint8 ashift8 = surface->format->Ashift / 8;
-
-
- if (alpha == 255) {
- *(pix + rshift8) = color >> surface->format->Rshift;
- *(pix + gshift8) = color >> surface->format->Gshift;
- *(pix + bshift8) = color >> surface->format->Bshift;
- *(pix + ashift8) = color >> surface->format->Ashift;
- } else {
- Uint8 dR, dG, dB, dA = 0;
- Uint8 sR, sG, sB, sA = 0;
-
- pix = (Uint8 *) surface->pixels + y * surface->pitch + x * 3;
-
- dR = *((pix) + rshift8);
- dG = *((pix) + gshift8);
- dB = *((pix) + bshift8);
- dA = *((pix) + ashift8);
-
- sR = (color >> surface->format->Rshift) & 0xff;
- sG = (color >> surface->format->Gshift) & 0xff;
- sB = (color >> surface->format->Bshift) & 0xff;
- sA = (color >> surface->format->Ashift) & 0xff;
-
- dR = dR + ((sR - dR) * alpha >> 8);
- dG = dG + ((sG - dG) * alpha >> 8);
- dB = dB + ((sB - dB) * alpha >> 8);
- dA = dA + ((sA - dA) * alpha >> 8);
-
- *((pix) + rshift8) = dR;
- *((pix) + gshift8) = dG;
- *((pix) + bshift8) = dB;
- *((pix) + ashift8) = dA;
- }
- }
- break;
+ && y >= clip_ymin(surface) && y <= clip_ymax(surface)) {
+
+ switch (surface->format->BytesPerPixel) {
+ case 1: { /* Assuming 8-bpp */
+ if (alpha == 255) {
+ *((Uint8 *) surface->pixels + y * surface->pitch + x) = color;
+ } else {
+ Uint8 *pixel = (Uint8 *) surface->pixels + y * surface->pitch + x;
+
+ Uint8 dR = surface->format->palette->colors[*pixel].r;
+ Uint8 dG = surface->format->palette->colors[*pixel].g;
+ Uint8 dB = surface->format->palette->colors[*pixel].b;
+ Uint8 sR = surface->format->palette->colors[color].r;
+ Uint8 sG = surface->format->palette->colors[color].g;
+ Uint8 sB = surface->format->palette->colors[color].b;
+
+ dR = dR + ((sR - dR) * alpha >> 8);
+ dG = dG + ((sG - dG) * alpha >> 8);
+ dB = dB + ((sB - dB) * alpha >> 8);
+
+ *pixel = SDL_MapRGB(surface->format, dR, dG, dB);
+ }
+ }
+ break;
+
+ case 2: { /* Probably 15-bpp or 16-bpp */
+ if (alpha == 255) {
+ *((Uint16 *) surface->pixels + y * surface->pitch / 2 + x) = color;
+ } else {
+ Uint16 *pixel = (Uint16 *) surface->pixels + y * surface->pitch / 2 + x;
+ Uint32 dc = *pixel;
+
+ R = ((dc & Rmask) + (((color & Rmask) - (dc & Rmask)) * alpha >> 8)) & Rmask;
+ G = ((dc & Gmask) + (((color & Gmask) - (dc & Gmask)) * alpha >> 8)) & Gmask;
+ B = ((dc & Bmask) + (((color & Bmask) - (dc & Bmask)) * alpha >> 8)) & Bmask;
+ if (Amask)
+ A = ((dc & Amask) + (((color & Amask) - (dc & Amask)) * alpha >> 8)) & Amask;
+
+ *pixel = R | G | B | A;
+ }
+ }
+ break;
+
+ case 3: { /* Slow 24-bpp mode, usually not used */
+ Uint8 *pix = (Uint8 *) surface->pixels + y * surface->pitch + x * 3;
+ Uint8 rshift8 = surface->format->Rshift / 8;
+ Uint8 gshift8 = surface->format->Gshift / 8;
+ Uint8 bshift8 = surface->format->Bshift / 8;
+ Uint8 ashift8 = surface->format->Ashift / 8;
+
+
+ if (alpha == 255) {
+ *(pix + rshift8) = color >> surface->format->Rshift;
+ *(pix + gshift8) = color >> surface->format->Gshift;
+ *(pix + bshift8) = color >> surface->format->Bshift;
+ *(pix + ashift8) = color >> surface->format->Ashift;
+ } else {
+ Uint8 dR, dG, dB, dA = 0;
+ Uint8 sR, sG, sB, sA = 0;
+
+ pix = (Uint8 *) surface->pixels + y * surface->pitch + x * 3;
+
+ dR = *((pix) + rshift8);
+ dG = *((pix) + gshift8);
+ dB = *((pix) + bshift8);
+ dA = *((pix) + ashift8);
+
+ sR = (color >> surface->format->Rshift) & 0xff;
+ sG = (color >> surface->format->Gshift) & 0xff;
+ sB = (color >> surface->format->Bshift) & 0xff;
+ sA = (color >> surface->format->Ashift) & 0xff;
+
+ dR = dR + ((sR - dR) * alpha >> 8);
+ dG = dG + ((sG - dG) * alpha >> 8);
+ dB = dB + ((sB - dB) * alpha >> 8);
+ dA = dA + ((sA - dA) * alpha >> 8);
+
+ *((pix) + rshift8) = dR;
+ *((pix) + gshift8) = dG;
+ *((pix) + bshift8) = dB;
+ *((pix) + ashift8) = dA;
+ }
+ }
+ break;
#ifdef ORIGINAL_ALPHA_PIXEL_ROUTINE
- case 4:{ /* Probably :-) 32-bpp */
- if (alpha == 255) {
- *((Uint32 *) surface->pixels + y * surface->pitch / 4 + x) = color;
- } else {
- Uint32 Rshift, Gshift, Bshift, Ashift;
- Uint32 *pixel = (Uint32 *) surface->pixels + y * surface->pitch / 4 + x;
- Uint32 dc = *pixel;
-
- Rshift = surface->format->Rshift;
- Gshift = surface->format->Gshift;
- Bshift = surface->format->Bshift;
- Ashift = surface->format->Ashift;
-
- R = ((dc & Rmask) + (((((color & Rmask) - (dc & Rmask)) >> Rshift) * alpha >> 8) << Rshift)) & Rmask;
- G = ((dc & Gmask) + (((((color & Gmask) - (dc & Gmask)) >> Gshift) * alpha >> 8) << Gshift)) & Gmask;
- B = ((dc & Bmask) + (((((color & Bmask) - (dc & Bmask)) >> Bshift) * alpha >> 8) << Bshift)) & Bmask;
- if (Amask)
- A = ((dc & Amask) + (((((color & Amask) - (dc & Amask)) >> Ashift) * alpha >> 8) << Ashift)) & Amask;
-
- *pixel = R | G | B | A;
- }
- }
- break;
+ case 4: { /* Probably :-) 32-bpp */
+ if (alpha == 255) {
+ *((Uint32 *) surface->pixels + y * surface->pitch / 4 + x) = color;
+ } else {
+ Uint32 Rshift, Gshift, Bshift, Ashift;
+ Uint32 *pixel = (Uint32 *) surface->pixels + y * surface->pitch / 4 + x;
+ Uint32 dc = *pixel;
+
+ Rshift = surface->format->Rshift;
+ Gshift = surface->format->Gshift;
+ Bshift = surface->format->Bshift;
+ Ashift = surface->format->Ashift;
+
+ R = ((dc & Rmask) + (((((color & Rmask) - (dc & Rmask)) >> Rshift) * alpha >> 8) << Rshift)) & Rmask;
+ G = ((dc & Gmask) + (((((color & Gmask) - (dc & Gmask)) >> Gshift) * alpha >> 8) << Gshift)) & Gmask;
+ B = ((dc & Bmask) + (((((color & Bmask) - (dc & Bmask)) >> Bshift) * alpha >> 8) << Bshift)) & Bmask;
+ if (Amask)
+ A = ((dc & Amask) + (((((color & Amask) - (dc & Amask)) >> Ashift) * alpha >> 8) << Ashift)) & Amask;
+
+ *pixel = R | G | B | A;
+ }
+ }
+ break;
#endif
#ifdef MODIFIED_ALPHA_PIXEL_ROUTINE
- case 4:{ /* Probably :-) 32-bpp */
- if (alpha == 255) {
- *((Uint32 *) surface->pixels + y * surface->pitch / 4 + x) = color;
- } else {
- Uint32 Rshift, Gshift, Bshift, Ashift;
- Uint32 *pixel = (Uint32 *) surface->pixels + y * surface->pitch / 4 + x;
- Uint32 dc = *pixel;
- Uint32 dR = (color & Rmask), dG = (color & Gmask), dB = (color & Bmask);
- Uint32 surfaceAlpha, preMultR, preMultG, preMultB;
- Uint32 aTmp;
-
- Rshift = surface->format->Rshift;
- Gshift = surface->format->Gshift;
- Bshift = surface->format->Bshift;
- Ashift = surface->format->Ashift;
-
- preMultR = (alpha * (dR>>Rshift));
- preMultG = (alpha * (dG>>Gshift));
- preMultB = (alpha * (dB>>Bshift));
-
- surfaceAlpha = ((dc & Amask) >> Ashift);
- aTmp = (255 - alpha);
- if ((A = 255 - ((aTmp * (255 - surfaceAlpha)) >> 8 ))) {
- aTmp *= surfaceAlpha;
- R = (preMultR + ((aTmp * ((dc & Rmask) >> Rshift)) >> 8)) / A << Rshift & Rmask;
- G = (preMultG + ((aTmp * ((dc & Gmask) >> Gshift)) >> 8)) / A << Gshift & Gmask;
- B = (preMultB + ((aTmp * ((dc & Bmask) >> Bshift)) >> 8)) / A << Bshift & Bmask;
- }
- *pixel = R | G | B | (A << Ashift & Amask);
-
- }
- }
- break;
+ case 4: { /* Probably :-) 32-bpp */
+ if (alpha == 255) {
+ *((Uint32 *) surface->pixels + y * surface->pitch / 4 + x) = color;
+ } else {
+ Uint32 Rshift, Gshift, Bshift, Ashift;
+ Uint32 *pixel = (Uint32 *) surface->pixels + y * surface->pitch / 4 + x;
+ Uint32 dc = *pixel;
+ Uint32 dR = (color & Rmask), dG = (color & Gmask), dB = (color & Bmask);
+ Uint32 surfaceAlpha, preMultR, preMultG, preMultB;
+ Uint32 aTmp;
+
+ Rshift = surface->format->Rshift;
+ Gshift = surface->format->Gshift;
+ Bshift = surface->format->Bshift;
+ Ashift = surface->format->Ashift;
+
+ preMultR = (alpha * (dR>>Rshift));
+ preMultG = (alpha * (dG>>Gshift));
+ preMultB = (alpha * (dB>>Bshift));
+
+ surfaceAlpha = ((dc & Amask) >> Ashift);
+ aTmp = (255 - alpha);
+ if ((A = 255 - ((aTmp * (255 - surfaceAlpha)) >> 8 ))) {
+ aTmp *= surfaceAlpha;
+ R = (preMultR + ((aTmp * ((dc & Rmask) >> Rshift)) >> 8)) / A << Rshift & Rmask;
+ G = (preMultG + ((aTmp * ((dc & Gmask) >> Gshift)) >> 8)) / A << Gshift & Gmask;
+ B = (preMultB + ((aTmp * ((dc & Bmask) >> Bshift)) >> 8)) / A << Bshift & Bmask;
+ }
+ *pixel = R | G | B | (A << Ashift & Amask);
+
+ }
+ }
+ break;
#endif
- }
+ }
}
}
/* FIXME: eliminate these 2 functions */
-static int raster_pixelColorNolock(SDL_Surface * dst, Sint16 x, Sint16 y, Uint32 color)
-{
+static int raster_pixelColorNolock(SDL_Surface * dst, Sint16 x, Sint16 y, Uint32 color) {
int result = 0;
#if 0
/*
- * Setup color
+ * Setup color
*/
alpha = color & 0x000000ff;
mcolor =
- SDL_MapRGBA(dst->format, (color & 0xff000000) >> 24,
- (color & 0x00ff0000) >> 16, (color & 0x0000ff00) >> 8, alpha);
+ SDL_MapRGBA(dst->format, (color & 0xff000000) >> 24,
+ (color & 0x00ff0000) >> 16, (color & 0x0000ff00) >> 8, alpha);
#endif
/*
- * Draw
+ * Draw
*/
raster_PutPixel(dst, x, y, color);
@@ -495,18 +479,17 @@ static int raster_pixelColorNolock(SDL_Surface * dst, Sint16 x, Sint16 y, Uint32
/* Pixel - using alpha weight on color for AA-drawing - no locking */
-static int raster_pixelColorWeightNolock(SDL_Surface * dst, Sint16 x, Sint16 y, Uint32 color, Uint32 weight)
-{
+static int raster_pixelColorWeightNolock(SDL_Surface * dst, Sint16 x, Sint16 y, Uint32 color, Uint32 weight) {
#if 0
Uint32 a;
/*
- * Get alpha
+ * Get alpha
*/
a = (color & (Uint32) 0x000000ff);
/*
- * Modify Alpha by weight
+ * Modify Alpha by weight
*/
a = ((a * weight) >> 8);
#endif
@@ -521,17 +504,23 @@ static int raster_pixelColorWeightNolock(SDL_Surface * dst, Sint16 x, Sint16 y,
-static inline void raster_hline(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16 y, Uint32 color)
-{
+static inline void raster_hline(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16 y, Uint32 color) {
#if 1
- SDL_Rect l;
+ SDL_Rect l;
/* sge */
- if(x1>x2){Sint16 tmp=x1; x1=x2; x2=tmp;}
-
- l.x=x1; l.y=y; l.w=x2-x1+1; l.h=1;
-
- SDL_FillRect(dst, &l, color);
+ if(x1>x2) {
+ Sint16 tmp=x1;
+ x1=x2;
+ x2=tmp;
+ }
+
+ l.x=x1;
+ l.y=y;
+ l.w=x2-x1+1;
+ l.h=1;
+
+ SDL_FillRect(dst, &l, color);
#else
/* sdl_gfx */
@@ -544,14 +533,12 @@ static inline void raster_hline(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16
int result = -1;
#if 0
int i;
- union
- {
+ union {
double d;
uint16_t col[4];
} doub;
- for(i = 0; i < 4; i++)
- {
+ for(i = 0; i < 4; i++) {
doub.col[i] = color;
}
#endif
@@ -560,48 +547,48 @@ static inline void raster_hline(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16
* Check visibility of clipping rectangle
*/
if ((dst->clip_rect.w==0) || (dst->clip_rect.h==0)) {
- return(0);
+ return(0);
}
-
+
/*
* Swap x1, x2 if required to ensure x1<=x2
*/
if (x1 > x2) {
- xtmp = x1;
- x1 = x2;
- x2 = xtmp;
+ xtmp = x1;
+ x1 = x2;
+ x2 = xtmp;
}
/*
* Get clipping boundary and
- * check visibility of hline
+ * check visibility of hline
*/
left = dst->clip_rect.x;
if (x2<left) {
- return(0);
+ return(0);
}
right = dst->clip_rect.x + dst->clip_rect.w - 1;
if (x1>right) {
- return(0);
+ return(0);
}
top = dst->clip_rect.y;
bottom = dst->clip_rect.y + dst->clip_rect.h - 1;
if ((y<top) || (y>bottom)) {
- return (0);
+ return (0);
}
/*
- * Clip x
+ * Clip x
*/
if (x1 < left) {
- x1 = left;
+ x1 = left;
}
if (x2 > right) {
- x2 = right;
+ x2 = right;
}
/*
- * Calculate width
+ * Calculate width
*/
w = x2 - x1;
@@ -609,88 +596,93 @@ static inline void raster_hline(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16
printf("raster_hline %d %d %d %d\n", x1, x2, y, w);
#endif
- /*
- * Lock surface
- */
+ /*
+ * Lock surface
+ */
if (SDL_MUSTLOCK(dst)) {
- SDL_LockSurface(dst);
- }
-
- /*
- * More variable setup
- */
- dx = w;
- pixx = dst->format->BytesPerPixel;
- pixy = dst->pitch;
- pixel = ((Uint8 *) dst->pixels) + pixx * (int) x1 + pixy * (int) y;
-
- /*
- * Draw
- */
- switch (dst->format->BytesPerPixel) {
- case 1:
- memset(pixel, color, dx);
- break;
- case 2:
- pixellast = pixel + dx + dx;
+ SDL_LockSurface(dst);
+ }
+
+ /*
+ * More variable setup
+ */
+ dx = w;
+ pixx = dst->format->BytesPerPixel;
+ pixy = dst->pitch;
+ pixel = ((Uint8 *) dst->pixels) + pixx * (int) x1 + pixy * (int) y;
+
+ /*
+ * Draw
+ */
+ switch (dst->format->BytesPerPixel) {
+ case 1:
+ memset(pixel, color, dx);
+ break;
+ case 2:
+ pixellast = pixel + dx + dx;
#if 0
- for (; (pixel+3) <= pixellast; pixel += 4*pixx)
- {
- *(double *)pixel = doub.d;
+ for (; (pixel+3) <= pixellast; pixel += 4*pixx) {
+ *(double *)pixel = doub.d;
}
#endif
- for (; pixel <= pixellast; pixel += pixx) {
- *(Uint16 *) pixel = color;
- }
- break;
- case 3:
- pixellast = pixel + dx + dx + dx;
- for (; pixel <= pixellast; pixel += pixx) {
- if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
- pixel[0] = (color >> 16) & 0xff;
- pixel[1] = (color >> 8) & 0xff;
- pixel[2] = color & 0xff;
- } else {
- pixel[0] = color & 0xff;
- pixel[1] = (color >> 8) & 0xff;
- pixel[2] = (color >> 16) & 0xff;
- }
- }
- break;
- default: /* case 4 */
- dx = dx + dx;
- pixellast = pixel + dx + dx;
- for (; pixel <= pixellast; pixel += pixx) {
- *(Uint32 *) pixel = color;
- }
- break;
- }
-
- /*
- * Unlock surface
- */
+ for (; pixel <= pixellast; pixel += pixx) {
+ *(Uint16 *) pixel = color;
+ }
+ break;
+ case 3:
+ pixellast = pixel + dx + dx + dx;
+ for (; pixel <= pixellast; pixel += pixx) {
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
+ pixel[0] = (color >> 16) & 0xff;
+ pixel[1] = (color >> 8) & 0xff;
+ pixel[2] = color & 0xff;
+ } else {
+ pixel[0] = color & 0xff;
+ pixel[1] = (color >> 8) & 0xff;
+ pixel[2] = (color >> 16) & 0xff;
+ }
+ }
+ break;
+ default: /* case 4 */
+ dx = dx + dx;
+ pixellast = pixel + dx + dx;
+ for (; pixel <= pixellast; pixel += pixx) {
+ *(Uint32 *) pixel = color;
+ }
+ break;
+ }
+
+ /*
+ * Unlock surface
+ */
if (SDL_MUSTLOCK(dst)) {
- SDL_UnlockSurface(dst);
+ SDL_UnlockSurface(dst);
}
- /*
- * Set result code
- */
- result = 0;
+ /*
+ * Set result code
+ */
+ result = 0;
return (result);
#endif
}
-static void raster_vline(SDL_Surface *dst, Sint16 x, Sint16 y1, Sint16 y2, Uint32 color)
-{
- SDL_Rect l;
+static void raster_vline(SDL_Surface *dst, Sint16 x, Sint16 y1, Sint16 y2, Uint32 color) {
+ SDL_Rect l;
+
+ if(y1>y2) {
+ Sint16 tmp=y1;
+ y1=y2;
+ y2=tmp;
+ }
+
+ l.x=x;
+ l.y=y1;
+ l.w=1;
+ l.h=y2-y1+1;
- if(y1>y2){Sint16 tmp=y1; y1=y2; y2=tmp;}
-
- l.x=x; l.y=y1; l.w=1; l.h=y2-y1+1;
-
- SDL_FillRect(dst, &l, color);
+ SDL_FillRect(dst, &l, color);
}
@@ -704,25 +696,23 @@ static void raster_vline(SDL_Surface *dst, Sint16 x, Sint16 y1, Sint16 y2, Uint3
#define CLIP_REJECT(a,b) (a&b)
#define CLIP_ACCEPT(a,b) (!(a|b))
-static int clipEncode(Sint16 x, Sint16 y, Sint16 left, Sint16 top, Sint16 right, Sint16 bottom)
-{
+static int clipEncode(Sint16 x, Sint16 y, Sint16 left, Sint16 top, Sint16 right, Sint16 bottom) {
int code = 0;
if (x < left) {
- code |= CLIP_LEFT_EDGE;
+ code |= CLIP_LEFT_EDGE;
} else if (x > right) {
- code |= CLIP_RIGHT_EDGE;
+ code |= CLIP_RIGHT_EDGE;
}
if (y < top) {
- code |= CLIP_TOP_EDGE;
+ code |= CLIP_TOP_EDGE;
} else if (y > bottom) {
- code |= CLIP_BOTTOM_EDGE;
+ code |= CLIP_BOTTOM_EDGE;
}
return code;
}
-static int clipLine(SDL_Surface * dst, Sint16 * x1, Sint16 * y1, Sint16 * x2, Sint16 * y2)
-{
+static int clipLine(SDL_Surface * dst, Sint16 * x1, Sint16 * y1, Sint16 * x2, Sint16 * y2) {
Sint16 left, right, top, bottom;
int code1, code2;
int draw = 0;
@@ -730,7 +720,7 @@ static int clipLine(SDL_Surface * dst, Sint16 * x1, Sint16 * y1, Sint16 * x2, Si
float m;
/*
- * Get clipping boundary
+ * Get clipping boundary
*/
left = dst->clip_rect.x;
right = dst->clip_rect.x + dst->clip_rect.w - 1;
@@ -738,56 +728,55 @@ static int clipLine(SDL_Surface * dst, Sint16 * x1, Sint16 * y1, Sint16 * x2, Si
bottom = dst->clip_rect.y + dst->clip_rect.h - 1;
while (1) {
- code1 = clipEncode(*x1, *y1, left, top, right, bottom);
- code2 = clipEncode(*x2, *y2, left, top, right, bottom);
- if (CLIP_ACCEPT(code1, code2)) {
- draw = 1;
- break;
- } else if (CLIP_REJECT(code1, code2))
- break;
- else {
- if (CLIP_INSIDE(code1)) {
- swaptmp = *x2;
- *x2 = *x1;
- *x1 = swaptmp;
- swaptmp = *y2;
- *y2 = *y1;
- *y1 = swaptmp;
- swaptmp = code2;
- code2 = code1;
- code1 = swaptmp;
- }
- if (*x2 != *x1) {
- m = (*y2 - *y1) / (float) (*x2 - *x1);
- } else {
- m = 1.0f;
- }
- if (code1 & CLIP_LEFT_EDGE) {
- *y1 += (Sint16) ((left - *x1) * m);
- *x1 = left;
- } else if (code1 & CLIP_RIGHT_EDGE) {
- *y1 += (Sint16) ((right - *x1) * m);
- *x1 = right;
- } else if (code1 & CLIP_BOTTOM_EDGE) {
- if (*x2 != *x1) {
- *x1 += (Sint16) ((bottom - *y1) / m);
- }
- *y1 = bottom;
- } else if (code1 & CLIP_TOP_EDGE) {
- if (*x2 != *x1) {
- *x1 += (Sint16) ((top - *y1) / m);
- }
- *y1 = top;
- }
- }
+ code1 = clipEncode(*x1, *y1, left, top, right, bottom);
+ code2 = clipEncode(*x2, *y2, left, top, right, bottom);
+ if (CLIP_ACCEPT(code1, code2)) {
+ draw = 1;
+ break;
+ } else if (CLIP_REJECT(code1, code2))
+ break;
+ else {
+ if (CLIP_INSIDE(code1)) {
+ swaptmp = *x2;
+ *x2 = *x1;
+ *x1 = swaptmp;
+ swaptmp = *y2;
+ *y2 = *y1;
+ *y1 = swaptmp;
+ swaptmp = code2;
+ code2 = code1;
+ code1 = swaptmp;
+ }
+ if (*x2 != *x1) {
+ m = (*y2 - *y1) / (float) (*x2 - *x1);
+ } else {
+ m = 1.0f;
+ }
+ if (code1 & CLIP_LEFT_EDGE) {
+ *y1 += (Sint16) ((left - *x1) * m);
+ *x1 = left;
+ } else if (code1 & CLIP_RIGHT_EDGE) {
+ *y1 += (Sint16) ((right - *x1) * m);
+ *x1 = right;
+ } else if (code1 & CLIP_BOTTOM_EDGE) {
+ if (*x2 != *x1) {
+ *x1 += (Sint16) ((bottom - *y1) / m);
+ }
+ *y1 = bottom;
+ } else if (code1 & CLIP_TOP_EDGE) {
+ if (*x2 != *x1) {
+ *x1 += (Sint16) ((top - *y1) / m);
+ }
+ *y1 = top;
+ }
+ }
}
return draw;
}
-void raster_line(SDL_Surface *dst, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint32_t color)
-{
+void raster_line(SDL_Surface *dst, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint32_t color) {
/* sdl-gfx */
int pixx, pixy;
int x, y;
@@ -797,40 +786,40 @@ void raster_line(SDL_Surface *dst, int16_t x1, int16_t y1, int16_t x2, int16_t y
void *pixel;
/*
- * Clip line and test if we have to draw
+ * Clip line and test if we have to draw
*/
if (!(clipLine(dst, &x1, &y1, &x2, &y2))) {
- return;
+ return;
}
/*
- * Test for special cases of straight lines or single point
+ * Test for special cases of straight lines or single point
*/
if (x1 == x2) {
- if (y1 < y2) {
- raster_vline(dst, x1, y1, y2, color);
- return;
- } else if (y1 > y2) {
- raster_vline(dst, x1, y2, y1, color);
- return;
- } else {
- raster_PutPixel(dst, x1, y1, color);
- return;
- }
+ if (y1 < y2) {
+ raster_vline(dst, x1, y1, y2, color);
+ return;
+ } else if (y1 > y2) {
+ raster_vline(dst, x1, y2, y1, color);
+ return;
+ } else {
+ raster_PutPixel(dst, x1, y1, color);
+ return;
+ }
}
if (y1 == y2) {
- if (x1 < x2) {
- raster_hline(dst, x1, x2, y1, color);
- return;
- } else if (x1 > x2) {
- raster_hline(dst, x2, x1, y1, color);
- return;
- }
+ if (x1 < x2) {
+ raster_hline(dst, x1, x2, y1, color);
+ return;
+ } else if (x1 > x2) {
+ raster_hline(dst, x2, x1, y1, color);
+ return;
+ }
}
/*
- * Variable setup
+ * Variable setup
*/
dx = x2 - x1;
dy = y2 - y1;
@@ -839,105 +828,105 @@ void raster_line(SDL_Surface *dst, int16_t x1, int16_t y1, int16_t x2, int16_t y
/* Lock surface */
if (SDL_MUSTLOCK(dst)) {
- if (SDL_LockSurface(dst) < 0) {
- return;
- }
+ if (SDL_LockSurface(dst) < 0) {
+ return;
+ }
}
- /*
- * No alpha blending - use fast pixel routines
- */
+ /*
+ * No alpha blending - use fast pixel routines
+ */
#if 0
- /*
- * Setup color
- */
- colorptr = (Uint8 *) & color;
- if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
- color = SDL_MapRGBA(dst->format, colorptr[0], colorptr[1], colorptr[2], colorptr[3]);
- } else {
- color = SDL_MapRGBA(dst->format, colorptr[3], colorptr[2], colorptr[1], colorptr[0]);
- }
+ /*
+ * Setup color
+ */
+ colorptr = (Uint8 *) & color;
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
+ color = SDL_MapRGBA(dst->format, colorptr[0], colorptr[1], colorptr[2], colorptr[3]);
+ } else {
+ color = SDL_MapRGBA(dst->format, colorptr[3], colorptr[2], colorptr[1], colorptr[0]);
+ }
#endif
- /*
- * More variable setup
- */
- dx = sx * dx + 1;
- dy = sy * dy + 1;
- pixx = dst->format->BytesPerPixel;
- pixy = dst->pitch;
- pixel = ((Uint8 *) dst->pixels) + pixx * (int) x1 + pixy * (int) y1;
- pixx *= sx;
- pixy *= sy;
- if (dx < dy) {
- swaptmp = dx;
- dx = dy;
- dy = swaptmp;
- swaptmp = pixx;
- pixx = pixy;
- pixy = swaptmp;
- }
-
- /*
- * Draw
- */
- x = 0;
- y = 0;
- switch (dst->format->BytesPerPixel) {
- case 1:
- for (; x < dx; x++, pixel=(Uint8 *)pixel+pixx) {
- *(Uint8 *)pixel = color;
- y += dy;
- if (y >= dx) {
- y -= dx;
- pixel = (Uint8 *)pixel + pixy;
- }
- }
- break;
- case 2:
- for (; x < dx; x++, pixel=(Uint8 *)pixel+pixx) {
- *(Uint16 *) pixel = color;
- y += dy;
- if (y >= dx) {
- y -= dx;
- pixel = (Uint8 *)pixel + pixy;
- }
- }
- break;
- case 3:
- for (; x < dx; x++, pixel=(Uint8 *)pixel+pixx) {
- if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
- *(Uint8 *)pixel = (color >> 16) & 0xff;
- *((Uint8 *)pixel+1) = (color >> 8) & 0xff;
- *((Uint8 *)pixel+2) = color & 0xff;
- } else {
- *(Uint8 *)pixel = color & 0xff;
- *((Uint8 *)pixel+1) = (color >> 8) & 0xff;
- *((Uint8 *)pixel+2) = (color >> 16) & 0xff;
- }
- y += dy;
- if (y >= dx) {
- y -= dx;
- pixel = (Uint8 *)pixel + pixy;
- }
- }
- break;
- default: /* case 4 */
- for (; x < dx; x++, pixel=(Uint8 *)pixel+pixx) {
- *(Uint32 *) pixel = color;
- y += dy;
- if (y >= dx) {
- y -= dx;
- pixel = (Uint8 *)pixel + pixy;
- }
- }
- break;
- }
+ /*
+ * More variable setup
+ */
+ dx = sx * dx + 1;
+ dy = sy * dy + 1;
+ pixx = dst->format->BytesPerPixel;
+ pixy = dst->pitch;
+ pixel = ((Uint8 *) dst->pixels) + pixx * (int) x1 + pixy * (int) y1;
+ pixx *= sx;
+ pixy *= sy;
+ if (dx < dy) {
+ swaptmp = dx;
+ dx = dy;
+ dy = swaptmp;
+ swaptmp = pixx;
+ pixx = pixy;
+ pixy = swaptmp;
+ }
+
+ /*
+ * Draw
+ */
+ x = 0;
+ y = 0;
+ switch (dst->format->BytesPerPixel) {
+ case 1:
+ for (; x < dx; x++, pixel=(Uint8 *)pixel+pixx) {
+ *(Uint8 *)pixel = color;
+ y += dy;
+ if (y >= dx) {
+ y -= dx;
+ pixel = (Uint8 *)pixel + pixy;
+ }
+ }
+ break;
+ case 2:
+ for (; x < dx; x++, pixel=(Uint8 *)pixel+pixx) {
+ *(Uint16 *) pixel = color;
+ y += dy;
+ if (y >= dx) {
+ y -= dx;
+ pixel = (Uint8 *)pixel + pixy;
+ }
+ }
+ break;
+ case 3:
+ for (; x < dx; x++, pixel=(Uint8 *)pixel+pixx) {
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
+ *(Uint8 *)pixel = (color >> 16) & 0xff;
+ *((Uint8 *)pixel+1) = (color >> 8) & 0xff;
+ *((Uint8 *)pixel+2) = color & 0xff;
+ } else {
+ *(Uint8 *)pixel = color & 0xff;
+ *((Uint8 *)pixel+1) = (color >> 8) & 0xff;
+ *((Uint8 *)pixel+2) = (color >> 16) & 0xff;
+ }
+ y += dy;
+ if (y >= dx) {
+ y -= dx;
+ pixel = (Uint8 *)pixel + pixy;
+ }
+ }
+ break;
+ default: /* case 4 */
+ for (; x < dx; x++, pixel=(Uint8 *)pixel+pixx) {
+ *(Uint32 *) pixel = color;
+ y += dy;
+ if (y >= dx) {
+ y -= dx;
+ pixel = (Uint8 *)pixel + pixy;
+ }
+ }
+ break;
+ }
/* Unlock surface */
if (SDL_MUSTLOCK(dst)) {
- SDL_UnlockSurface(dst);
+ SDL_UnlockSurface(dst);
}
return;
@@ -947,8 +936,8 @@ void raster_line(SDL_Surface *dst, int16_t x1, int16_t y1, int16_t x2, int16_t y
#define AAlevels 256
#define AAbits 8
-static void raster_aalineColorInt(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color, int draw_endpoint)
-{
+static void raster_aalineColorInt(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color,
+ int draw_endpoint) {
Sint32 xx0, yy0, xx1, yy1;
Uint32 intshift, erracc, erradj;
Uint32 erracctmp, wgt;
@@ -958,18 +947,18 @@ static void raster_aalineColorInt(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint1
* Check visibility of clipping rectangle
*/
if ((dst->clip_rect.w==0) || (dst->clip_rect.h==0)) {
- return;
+ return;
}
/*
- * Clip line and test if we have to draw
+ * Clip line and test if we have to draw
*/
if (!(clipLine(dst, &x1, &y1, &x2, &y2))) {
- return;
+ return;
}
/*
- * Keep on working with 32bit numbers
+ * Keep on working with 32bit numbers
*/
xx0 = x1;
yy0 = y1;
@@ -977,177 +966,176 @@ static void raster_aalineColorInt(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint1
yy1 = y2;
/*
- * Reorder points if required
+ * Reorder points if required
*/
if (yy0 > yy1) {
- tmp = yy0;
- yy0 = yy1;
- yy1 = tmp;
- tmp = xx0;
- xx0 = xx1;
- xx1 = tmp;
+ tmp = yy0;
+ yy0 = yy1;
+ yy1 = tmp;
+ tmp = xx0;
+ xx0 = xx1;
+ xx1 = tmp;
}
/*
- * Calculate distance
+ * Calculate distance
*/
dx = xx1 - xx0;
dy = yy1 - yy0;
/*
- * Adjust for negative dx and set xdir
+ * Adjust for negative dx and set xdir
*/
if (dx >= 0) {
- xdir = 1;
+ xdir = 1;
} else {
- xdir = -1;
- dx = (-dx);
+ xdir = -1;
+ dx = (-dx);
}
/*
- * Check for special cases
+ * Check for special cases
*/
if (dx == 0) {
- /*
- * Vertical line
- */
- raster_vline(dst, x1, y1, y2, color);
- return;
+ /*
+ * Vertical line
+ */
+ raster_vline(dst, x1, y1, y2, color);
+ return;
} else if (dy == 0) {
- /*
- * Horizontal line
- */
- raster_hline(dst, x1, x2, y1, color);
- return;
+ /*
+ * Horizontal line
+ */
+ raster_hline(dst, x1, x2, y1, color);
+ return;
} else if (dx == dy) {
- /*
- * Diagonal line
- */
- raster_line(dst, x1, y1, x2, y2, color);
- return;
+ /*
+ * Diagonal line
+ */
+ raster_line(dst, x1, y1, x2, y2, color);
+ return;
}
/*
- * Zero accumulator
+ * Zero accumulator
*/
erracc = 0;
/*
- * # of bits by which to shift erracc to get intensity level
+ * # of bits by which to shift erracc to get intensity level
*/
intshift = 32 - AAbits;
/* Lock surface */
if (SDL_MUSTLOCK(dst)) {
- if (SDL_LockSurface(dst) < 0) {
- return;
- }
+ if (SDL_LockSurface(dst) < 0) {
+ return;
+ }
}
/*
- * Draw the initial pixel in the foreground color
+ * Draw the initial pixel in the foreground color
*/
raster_pixelColorNolock(dst, x1, y1, color);
/*
- * x-major or y-major?
+ * x-major or y-major?
*/
if (dy > dx) {
- /*
- * y-major. Calculate 16-bit fixed point fractional part of a pixel that
- * X advances every time Y advances 1 pixel, truncating the result so that
- * we won't overrun the endpoint along the X axis
- */
- /*
- * Not-so-portable version: erradj = ((Uint64)dx << 32) / (Uint64)dy;
- */
- erradj = ((dx << 16) / dy) << 16;
-
- /*
- * draw all pixels other than the first and last
- */
- x0pxdir = xx0 + xdir;
- while (--dy) {
- erracctmp = erracc;
- erracc += erradj;
- if (erracc <= erracctmp) {
- /*
- * rollover in error accumulator, x coord advances
- */
- xx0 = x0pxdir;
- x0pxdir += xdir;
- }
- yy0++; /* y-major so always advance Y */
-
- /*
- * the AAbits most significant bits of erracc give us the intensity
- * weighting for this pixel, and the complement of the weighting for
- * the paired pixel.
- */
- wgt = (erracc >> intshift) & 255;
- raster_pixelColorWeightNolock (dst, xx0, yy0, color, 255 - wgt);
- raster_pixelColorWeightNolock (dst, x0pxdir, yy0, color, wgt);
- }
+ /*
+ * y-major. Calculate 16-bit fixed point fractional part of a pixel that
+ * X advances every time Y advances 1 pixel, truncating the result so that
+ * we won't overrun the endpoint along the X axis
+ */
+ /*
+ * Not-so-portable version: erradj = ((Uint64)dx << 32) / (Uint64)dy;
+ */
+ erradj = ((dx << 16) / dy) << 16;
+
+ /*
+ * draw all pixels other than the first and last
+ */
+ x0pxdir = xx0 + xdir;
+ while (--dy) {
+ erracctmp = erracc;
+ erracc += erradj;
+ if (erracc <= erracctmp) {
+ /*
+ * rollover in error accumulator, x coord advances
+ */
+ xx0 = x0pxdir;
+ x0pxdir += xdir;
+ }
+ yy0++; /* y-major so always advance Y */
+
+ /*
+ * the AAbits most significant bits of erracc give us the intensity
+ * weighting for this pixel, and the complement of the weighting for
+ * the paired pixel.
+ */
+ wgt = (erracc >> intshift) & 255;
+ raster_pixelColorWeightNolock (dst, xx0, yy0, color, 255 - wgt);
+ raster_pixelColorWeightNolock (dst, x0pxdir, yy0, color, wgt);
+ }
} else {
- /*
- * x-major line. Calculate 16-bit fixed-point fractional part of a pixel
- * that Y advances each time X advances 1 pixel, truncating the result so
- * that we won't overrun the endpoint along the X axis.
- */
- /*
- * Not-so-portable version: erradj = ((Uint64)dy << 32) / (Uint64)dx;
- */
- erradj = ((dy << 16) / dx) << 16;
-
- /*
- * draw all pixels other than the first and last
- */
- y0p1 = yy0 + 1;
- while (--dx) {
-
- erracctmp = erracc;
- erracc += erradj;
- if (erracc <= erracctmp) {
- /*
- * Accumulator turned over, advance y
- */
- yy0 = y0p1;
- y0p1++;
- }
- xx0 += xdir; /* x-major so always advance X */
- /*
- * the AAbits most significant bits of erracc give us the intensity
- * weighting for this pixel, and the complement of the weighting for
- * the paired pixel.
- */
- wgt = (erracc >> intshift) & 255;
- raster_pixelColorWeightNolock (dst, xx0, yy0, color, 255 - wgt);
- raster_pixelColorWeightNolock (dst, xx0, y0p1, color, wgt);
- }
- }
-
- /*
- * Do we have to draw the endpoint
+ /*
+ * x-major line. Calculate 16-bit fixed-point fractional part of a pixel
+ * that Y advances each time X advances 1 pixel, truncating the result so
+ * that we won't overrun the endpoint along the X axis.
+ */
+ /*
+ * Not-so-portable version: erradj = ((Uint64)dy << 32) / (Uint64)dx;
+ */
+ erradj = ((dy << 16) / dx) << 16;
+
+ /*
+ * draw all pixels other than the first and last
+ */
+ y0p1 = yy0 + 1;
+ while (--dx) {
+
+ erracctmp = erracc;
+ erracc += erradj;
+ if (erracc <= erracctmp) {
+ /*
+ * Accumulator turned over, advance y
+ */
+ yy0 = y0p1;
+ y0p1++;
+ }
+ xx0 += xdir; /* x-major so always advance X */
+ /*
+ * the AAbits most significant bits of erracc give us the intensity
+ * weighting for this pixel, and the complement of the weighting for
+ * the paired pixel.
+ */
+ wgt = (erracc >> intshift) & 255;
+ raster_pixelColorWeightNolock (dst, xx0, yy0, color, 255 - wgt);
+ raster_pixelColorWeightNolock (dst, xx0, y0p1, color, wgt);
+ }
+ }
+
+ /*
+ * Do we have to draw the endpoint
*/
if (draw_endpoint) {
- /*
- * Draw final pixel, always exactly intersected by the line and doesn't
- * need to be weighted.
- */
- raster_pixelColorNolock (dst, x2, y2, color);
+ /*
+ * Draw final pixel, always exactly intersected by the line and doesn't
+ * need to be weighted.
+ */
+ raster_pixelColorNolock (dst, x2, y2, color);
}
/* Unlock surface */
if (SDL_MUSTLOCK(dst)) {
- SDL_UnlockSurface(dst);
+ SDL_UnlockSurface(dst);
}
}
-void raster_aaline(SDL_Surface *s, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint32_t col)
-{
+void raster_aaline(SDL_Surface *s, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint32_t col) {
raster_aalineColorInt(s, x1, y1, x2, y2, col, 1);
}
@@ -1155,8 +1143,7 @@ void raster_aaline(SDL_Surface *s, int16_t x1, int16_t y1, int16_t x2, int16_t y
/* raster :: circle */
-void raster_circle(SDL_Surface *dst, int16_t x, int16_t y, int16_t r, uint32_t color)
-{
+void raster_circle(SDL_Surface *dst, int16_t x, int16_t y, int16_t r, uint32_t color) {
/* sdl-gfx */
Sint16 left, right, top, bottom;
Sint16 x1, y1, x2, y2;
@@ -1174,297 +1161,284 @@ void raster_circle(SDL_Surface *dst, int16_t x, int16_t y, int16_t r, uint32_t c
* Check visibility of clipping rectangle
*/
if ((dst->clip_rect.w==0) || (dst->clip_rect.h==0)) {
- return;
+ return;
}
/*
- * Sanity check radius
+ * Sanity check radius
*/
if (r < 0) {
- return;
+ return;
}
/*
- * Special case for r=0 - draw a point
+ * Special case for r=0 - draw a point
*/
if (r == 0) {
- return (raster_PutPixel(dst, x, y, color));
+ return (raster_PutPixel(dst, x, y, color));
}
/*
- * Get circle and clipping boundary and
- * test if bounding box of circle is visible
+ * Get circle and clipping boundary and
+ * test if bounding box of circle is visible
*/
x2 = x + r;
left = dst->clip_rect.x;
if (x2<left) {
- return;
- }
+ return;
+ }
x1 = x - r;
right = dst->clip_rect.x + dst->clip_rect.w - 1;
if (x1>right) {
- return;
- }
+ return;
+ }
y2 = y + r;
top = dst->clip_rect.y;
if (y2<top) {
- return;
- }
+ return;
+ }
y1 = y - r;
bottom = dst->clip_rect.y + dst->clip_rect.h - 1;
if (y1>bottom) {
- return;
- }
+ return;
+ }
/*
- * Draw
+ * Draw
*/
do {
- xpcx = x + cx;
- xmcx = x - cx;
- xpcy = x + cy;
- xmcy = x - cy;
- if (ocy != cy) {
- if (cy > 0) {
- ypcy = y + cy;
- ymcy = y - cy;
- raster_hline(dst, xmcx, xpcx, ypcy, color);
- raster_hline(dst, xmcx, xpcx, ymcy, color);
+ xpcx = x + cx;
+ xmcx = x - cx;
+ xpcy = x + cy;
+ xmcy = x - cy;
+ if (ocy != cy) {
+ if (cy > 0) {
+ ypcy = y + cy;
+ ymcy = y - cy;
+ raster_hline(dst, xmcx, xpcx, ypcy, color);
+ raster_hline(dst, xmcx, xpcx, ymcy, color);
// raster_rect_inline(dst, xmcx, ypcy, 2*cx, 1, color);
// raster_rect_inline(dst, xmcx, ymcy, 2*cx, 1, color);
- } else {
- raster_hline(dst, xmcx, xpcx, y, color);
+ } else {
+ raster_hline(dst, xmcx, xpcx, y, color);
// raster_rect_inline(dst, xmcx, y, 2*cx, 1, color);
- }
- ocy = cy;
- }
- if (ocx != cx) {
- if (cx != cy) {
- if (cx > 0) {
- ypcx = y + cx;
- ymcx = y - cx;
- raster_hline(dst, xmcy, xpcy, ymcx, color);
- raster_hline(dst, xmcy, xpcy, ypcx, color);
- //raster_rect_inline(dst, xmcy, ymcx, 2*cy, 1, color);
- //raster_rect_inline(dst, xmcy, ypcx, 2*cy, 1, color);
- } else {
- raster_hline(dst, xmcy, xpcy, y, color);
- //raster_rect_inline(dst, xmcy, y, 2*cy, 1, color);
- }
- }
- ocx = cx;
- }
- /*
- * Update
- */
- if (df < 0) {
- df += d_e;
- d_e += 2;
- d_se += 2;
- } else {
- df += d_se;
- d_e += 2;
- d_se += 4;
- cy--;
- }
- cx++;
+ }
+ ocy = cy;
+ }
+ if (ocx != cx) {
+ if (cx != cy) {
+ if (cx > 0) {
+ ypcx = y + cx;
+ ymcx = y - cx;
+ raster_hline(dst, xmcy, xpcy, ymcx, color);
+ raster_hline(dst, xmcy, xpcy, ypcx, color);
+ //raster_rect_inline(dst, xmcy, ymcx, 2*cy, 1, color);
+ //raster_rect_inline(dst, xmcy, ypcx, 2*cy, 1, color);
+ } else {
+ raster_hline(dst, xmcy, xpcy, y, color);
+ //raster_rect_inline(dst, xmcy, y, 2*cy, 1, color);
+ }
+ }
+ ocx = cx;
+ }
+ /*
+ * Update
+ */
+ if (df < 0) {
+ df += d_e;
+ d_e += 2;
+ d_se += 2;
+ } else {
+ df += d_se;
+ d_e += 2;
+ d_se += 4;
+ cy--;
+ }
+ cx++;
} while (cx <= cy);
}
/* FIXME: convert to fixed pt */
-static void raster_AAFilledEllipse(SDL_Surface *surface, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 ry, Uint32 color)
-{
+static void raster_AAFilledEllipse(SDL_Surface *surface, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 ry, Uint32 color) {
/* sge */
- /* Sanity check */
- if (rx < 1)
- rx = 1;
- if (ry < 1)
- ry = 1;
-
- int a2 = rx * rx;
- int b2 = ry * ry;
-
- int ds = 2 * a2;
- int dt = 2 * b2;
-
- int dxt = (int)(a2 / sqrt(a2 + b2));
-
- int t = 0;
- int s = -2 * a2 * ry;
- int d = 0;
-
- Sint16 x = xc;
- Sint16 y = yc - ry;
-
- Sint16 xs, ys, dyt;
- float cp, is, ip, imax = 1.0;
-
- /* Lock surface */
- if ( SDL_MUSTLOCK(surface) )
- if ( SDL_LockSurface(surface) < 0 )
- return;
-
- /* "End points" */
- raster_PutPixel(surface, x, y, color);
- raster_PutPixel(surface, 2*xc-x, y, color);
-
- raster_PutPixel(surface, x, 2*yc-y, color);
- raster_PutPixel(surface, 2*xc-x, 2*yc-y, color);
-
- /* unlock surface */
- if (SDL_MUSTLOCK(surface) )
- SDL_UnlockSurface(surface);
-
- raster_vline(surface, x, y+1, 2*yc-y-1, color);
-
- int i;
-
- for (i = 1; i <= dxt; i++)
- {
- x--;
- d += t - b2;
-
- if (d >= 0)
- ys = y - 1;
- else if ((d - s - a2) > 0)
- {
- if ((2 * d - s - a2) >= 0)
- ys = y + 1;
- else
- {
- ys = y;
- y++;
- d -= s + a2;
- s += ds;
- }
- }
- else
- {
- y++;
- ys = y + 1;
- d -= s + a2;
- s += ds;
- }
-
- t -= dt;
-
- /* Calculate alpha */
- cp = (float) abs(d) / abs(s);
- is = cp * imax;
- ip = imax - is;
-
-
- /* Lock surface */
- if ( SDL_MUSTLOCK(surface) )
- if ( SDL_LockSurface(surface) < 0 )
- return;
-
- /* Upper half */
- raster_PutPixelAlpha(surface, x, y, color, (Uint8)(ip*255));
- raster_PutPixelAlpha(surface, 2*xc-x, y, color, (Uint8)(ip*255));
-
- raster_PutPixelAlpha(surface, x, ys, color, (Uint8)(is*255));
- raster_PutPixelAlpha(surface, 2*xc-x, ys, color, (Uint8)(is*255));
-
-
- /* Lower half */
- raster_PutPixelAlpha(surface, x, 2*yc-y, color, (Uint8)(ip*255));
- raster_PutPixelAlpha(surface, 2*xc-x, 2*yc-y, color, (Uint8)(ip*255));
-
- raster_PutPixelAlpha(surface, x, 2*yc-ys, color, (Uint8)(is*255));
- raster_PutPixelAlpha(surface, 2*xc-x, 2*yc-ys, color, (Uint8)(is*255));
-
- /* unlock surface */
- if (SDL_MUSTLOCK(surface) )
- SDL_UnlockSurface(surface);
-
-
- /* Fill */
- raster_vline(surface, x, y+1, 2*yc-y-1, color);
- raster_vline(surface, 2*xc-x, y+1, 2*yc-y-1, color);
- raster_vline(surface, x, ys+1, 2*yc-ys-1, color);
- raster_vline(surface, 2*xc-x, ys+1, 2*yc-ys-1, color);
- }
-
- dyt = abs(y - yc);
-
- for (i = 1; i <= dyt; i++)
- {
- y++;
- d -= s + a2;
-
- if (d <= 0)
- xs = x + 1;
- else if ((d + t - b2) < 0)
- {
- if ((2 * d + t - b2) <= 0)
- xs = x - 1;
- else
- {
- xs = x;
- x--;
- d += t - b2;
- t -= dt;
- }
- }
- else
- {
- x--;
- xs = x - 1;
- d += t - b2;
- t -= dt;
- }
-
- s += ds;
-
- /* Calculate alpha */
- cp = (float) abs(d) / abs(t);
- is = cp * imax;
- ip = imax - is;
-
-
- /* Lock surface */
- if ( SDL_MUSTLOCK(surface) )
- if ( SDL_LockSurface(surface) < 0 )
- return;
-
- /* Upper half */
- raster_PutPixelAlpha(surface, x, y, color, (Uint8)(ip*255));
- raster_PutPixelAlpha(surface, 2*xc-x, y, color, (Uint8)(ip*255));
-
- raster_PutPixelAlpha(surface, xs, y, color, (Uint8)(is*255));
- raster_PutPixelAlpha(surface, 2*xc-xs, y, color, (Uint8)(is*255));
-
-
- /* Lower half*/
- raster_PutPixelAlpha(surface, x, 2*yc-y, color, (Uint8)(ip*255));
- raster_PutPixelAlpha(surface, 2*xc-x, 2*yc-y, color, (Uint8)(ip*255));
-
- raster_PutPixelAlpha(surface, xs, 2*yc-y, color, (Uint8)(is*255));
- raster_PutPixelAlpha(surface, 2*xc-xs, 2*yc-y, color, (Uint8)(is*255));
-
- /* unlock surface */
- if (SDL_MUSTLOCK(surface) )
- SDL_UnlockSurface(surface);
-
- /* Fill */
- raster_hline(surface, x+1, 2*xc-x-1, y, color);
- raster_hline(surface, xs+1, 2*xc-xs-1, y, color);
- raster_hline(surface, x+1, 2*xc-x-1, 2*yc-y, color);
- raster_hline(surface, xs+1, 2*xc-xs-1, 2*yc-y, color);
- }
+ /* Sanity check */
+ if (rx < 1)
+ rx = 1;
+ if (ry < 1)
+ ry = 1;
+
+ int a2 = rx * rx;
+ int b2 = ry * ry;
+
+ int ds = 2 * a2;
+ int dt = 2 * b2;
+
+ int dxt = (int)(a2 / sqrt(a2 + b2));
+
+ int t = 0;
+ int s = -2 * a2 * ry;
+ int d = 0;
+
+ Sint16 x = xc;
+ Sint16 y = yc - ry;
+
+ Sint16 xs, ys, dyt;
+ float cp, is, ip, imax = 1.0;
+
+ /* Lock surface */
+ if ( SDL_MUSTLOCK(surface) )
+ if ( SDL_LockSurface(surface) < 0 )
+ return;
+
+ /* "End points" */
+ raster_PutPixel(surface, x, y, color);
+ raster_PutPixel(surface, 2*xc-x, y, color);
+
+ raster_PutPixel(surface, x, 2*yc-y, color);
+ raster_PutPixel(surface, 2*xc-x, 2*yc-y, color);
+
+ /* unlock surface */
+ if (SDL_MUSTLOCK(surface) )
+ SDL_UnlockSurface(surface);
+
+ raster_vline(surface, x, y+1, 2*yc-y-1, color);
+
+ int i;
+
+ for (i = 1; i <= dxt; i++) {
+ x--;
+ d += t - b2;
+
+ if (d >= 0)
+ ys = y - 1;
+ else if ((d - s - a2) > 0) {
+ if ((2 * d - s - a2) >= 0)
+ ys = y + 1;
+ else {
+ ys = y;
+ y++;
+ d -= s + a2;
+ s += ds;
+ }
+ } else {
+ y++;
+ ys = y + 1;
+ d -= s + a2;
+ s += ds;
+ }
+
+ t -= dt;
+
+ /* Calculate alpha */
+ cp = (float) abs(d) / abs(s);
+ is = cp * imax;
+ ip = imax - is;
+
+
+ /* Lock surface */
+ if ( SDL_MUSTLOCK(surface) )
+ if ( SDL_LockSurface(surface) < 0 )
+ return;
+
+ /* Upper half */
+ raster_PutPixelAlpha(surface, x, y, color, (Uint8)(ip*255));
+ raster_PutPixelAlpha(surface, 2*xc-x, y, color, (Uint8)(ip*255));
+
+ raster_PutPixelAlpha(surface, x, ys, color, (Uint8)(is*255));
+ raster_PutPixelAlpha(surface, 2*xc-x, ys, color, (Uint8)(is*255));
+
+
+ /* Lower half */
+ raster_PutPixelAlpha(surface, x, 2*yc-y, color, (Uint8)(ip*255));
+ raster_PutPixelAlpha(surface, 2*xc-x, 2*yc-y, color, (Uint8)(ip*255));
+
+ raster_PutPixelAlpha(surface, x, 2*yc-ys, color, (Uint8)(is*255));
+ raster_PutPixelAlpha(surface, 2*xc-x, 2*yc-ys, color, (Uint8)(is*255));
+
+ /* unlock surface */
+ if (SDL_MUSTLOCK(surface) )
+ SDL_UnlockSurface(surface);
+
+
+ /* Fill */
+ raster_vline(surface, x, y+1, 2*yc-y-1, color);
+ raster_vline(surface, 2*xc-x, y+1, 2*yc-y-1, color);
+ raster_vline(surface, x, ys+1, 2*yc-ys-1, color);
+ raster_vline(surface, 2*xc-x, ys+1, 2*yc-ys-1, color);
+ }
+
+ dyt = abs(y - yc);
+
+ for (i = 1; i <= dyt; i++) {
+ y++;
+ d -= s + a2;
+
+ if (d <= 0)
+ xs = x + 1;
+ else if ((d + t - b2) < 0) {
+ if ((2 * d + t - b2) <= 0)
+ xs = x - 1;
+ else {
+ xs = x;
+ x--;
+ d += t - b2;
+ t -= dt;
+ }
+ } else {
+ x--;
+ xs = x - 1;
+ d += t - b2;
+ t -= dt;
+ }
+
+ s += ds;
+
+ /* Calculate alpha */
+ cp = (float) abs(d) / abs(t);
+ is = cp * imax;
+ ip = imax - is;
+
+
+ /* Lock surface */
+ if ( SDL_MUSTLOCK(surface) )
+ if ( SDL_LockSurface(surface) < 0 )
+ return;
+
+ /* Upper half */
+ raster_PutPixelAlpha(surface, x, y, color, (Uint8)(ip*255));
+ raster_PutPixelAlpha(surface, 2*xc-x, y, color, (Uint8)(ip*255));
+
+ raster_PutPixelAlpha(surface, xs, y, color, (Uint8)(is*255));
+ raster_PutPixelAlpha(surface, 2*xc-xs, y, color, (Uint8)(is*255));
+
+
+ /* Lower half*/
+ raster_PutPixelAlpha(surface, x, 2*yc-y, color, (Uint8)(ip*255));
+ raster_PutPixelAlpha(surface, 2*xc-x, 2*yc-y, color, (Uint8)(ip*255));
+
+ raster_PutPixelAlpha(surface, xs, 2*yc-y, color, (Uint8)(is*255));
+ raster_PutPixelAlpha(surface, 2*xc-xs, 2*yc-y, color, (Uint8)(is*255));
+
+ /* unlock surface */
+ if (SDL_MUSTLOCK(surface) )
+ SDL_UnlockSurface(surface);
+
+ /* Fill */
+ raster_hline(surface, x+1, 2*xc-x-1, y, color);
+ raster_hline(surface, xs+1, 2*xc-xs-1, y, color);
+ raster_hline(surface, x+1, 2*xc-x-1, 2*yc-y, color);
+ raster_hline(surface, xs+1, 2*xc-xs-1, 2*yc-y, color);
+ }
}
-void raster_aacircle(SDL_Surface *s, int16_t x, int16_t y, int16_t r, uint32_t col)
-{
+void raster_aacircle(SDL_Surface *s, int16_t x, int16_t y, int16_t r, uint32_t col) {
raster_AAFilledEllipse(s, x, y, r, r, col);
}
#if 0
-void raster_aacircle(SDL_Surface *s, int16_t x, int16_t y, int16_t r, uint32_t col)
-{
+void raster_aacircle(SDL_Surface *s, int16_t x, int16_t y, int16_t r, uint32_t col) {
/* sdl-gfx */
Sint16 left, right, top, bottom;
int result;
@@ -1483,159 +1457,150 @@ void raster_aacircle(SDL_Surface *s, int16_t x, int16_t y, int16_t r, uint32_t c
* Check visibility of clipping rectangle
*/
if ((dst->clip_rect.w==0) || (dst->clip_rect.h==0)) {
- return;
+ return;
}
/*
- * Sanity check radius
+ * Sanity check radius
*/
if (r < 0) {
- return;
+ return;
}
#if 0
/*
- * Special case for r=0 - draw a point
+ * Special case for r=0 - draw a point
*/
if (r == 0) {
- return (pixelColor(dst, x, y, color));
+ return (pixelColor(dst, x, y, color));
}
#endif
/*
- * Get circle and clipping boundary and
- * test if bounding box of circle is visible
+ * Get circle and clipping boundary and
+ * test if bounding box of circle is visible
*/
x2 = x + r;
left = dst->clip_rect.x;
if (x2<left) {
- return;
- }
+ return;
+ }
x1 = x - r;
right = dst->clip_rect.x + dst->clip_rect.w - 1;
if (x1>right) {
- return;
- }
+ return;
+ }
y2 = y + r;
top = dst->clip_rect.y;
if (y2<top) {
- return;
- }
+ return;
+ }
y1 = y - r;
bottom = dst->clip_rect.y + dst->clip_rect.h - 1;
if (y1>bottom) {
- return;
- }
+ return;
+ }
/*
- * Draw
+ * Draw
*/
result = 0;
do {
- xpcx = x + cx;
- xmcx = x - cx;
- xpcy = x + cy;
- xmcy = x - cy;
- if (ocy != cy) {
- if (cy > 0) {
- ypcy = y + cy;
- ymcy = y - cy;
- raster_hlineColor(dst, xmcx, xpcx, ypcy, color);
- raster_hlineColor(dst, xmcx, xpcx, ymcy, color);
+ xpcx = x + cx;
+ xmcx = x - cx;
+ xpcy = x + cy;
+ xmcy = x - cy;
+ if (ocy != cy) {
+ if (cy > 0) {
+ ypcy = y + cy;
+ ymcy = y - cy;
+ raster_hlineColor(dst, xmcx, xpcx, ypcy, color);
+ raster_hlineColor(dst, xmcx, xpcx, ymcy, color);
// raster_rect_inline(dst, xmcx, ypcy, 2*cx, 1, color);
// raster_rect_inline(dst, xmcx, ymcy, 2*cx, 1, color);
- } else {
- raster_hlineColor(dst, xmcx, xpcx, y, color);
+ } else {
+ raster_hlineColor(dst, xmcx, xpcx, y, color);
// raster_rect_inline(dst, xmcx, y, 2*cx, 1, color);
- }
- ocy = cy;
- }
- if (ocx != cx) {
- if (cx != cy) {
- if (cx > 0) {
- ypcx = y + cx;
- ymcx = y - cx;
- raster_hlineColor(dst, xmcy, xpcy, ymcx, color);
- raster_hlineColor(dst, xmcy, xpcy, ypcx, color);
- //raster_rect_inline(dst, xmcy, ymcx, 2*cy, 1, color);
- //raster_rect_inline(dst, xmcy, ypcx, 2*cy, 1, color);
- } else {
- raster_hlineColor(dst, xmcy, xpcy, y, color);
- //raster_rect_inline(dst, xmcy, y, 2*cy, 1, color);
- }
- }
- ocx = cx;
- }
- /*
- * Update
- */
- if (df < 0) {
- df += d_e;
- d_e += 2;
- d_se += 2;
- } else {
- df += d_se;
- d_e += 2;
- d_se += 4;
- cy--;
- }
- cx++;
+ }
+ ocy = cy;
+ }
+ if (ocx != cx) {
+ if (cx != cy) {
+ if (cx > 0) {
+ ypcx = y + cx;
+ ymcx = y - cx;
+ raster_hlineColor(dst, xmcy, xpcy, ymcx, color);
+ raster_hlineColor(dst, xmcy, xpcy, ypcx, color);
+ //raster_rect_inline(dst, xmcy, ymcx, 2*cy, 1, color);
+ //raster_rect_inline(dst, xmcy, ypcx, 2*cy, 1, color);
+ } else {
+ raster_hlineColor(dst, xmcy, xpcy, y, color);
+ //raster_rect_inline(dst, xmcy, y, 2*cy, 1, color);
+ }
+ }
+ ocx = cx;
+ }
+ /*
+ * Update
+ */
+ if (df < 0) {
+ df += d_e;
+ d_e += 2;
+ d_se += 2;
+ } else {
+ df += d_se;
+ d_e += 2;
+ d_se += 4;
+ cy--;
+ }
+ cx++;
} while (cx <= cy);
#if 0
/* sge */
- Sint16 cx = 0;
- Sint16 cy = r;
- int draw=1;
- Sint16 df = 1 - r;
- Sint16 d_e = 3;
- Sint16 d_se = -2 * r + 5;
+ Sint16 cx = 0;
+ Sint16 cy = r;
+ int draw=1;
+ Sint16 df = 1 - r;
+ Sint16 d_e = 3;
+ Sint16 d_se = -2 * r + 5;
#ifdef DEBUG
printf("raster_circle %d %d %d\n", x, y, r);
#endif
- if(r < 0)
- {
+ if(r < 0) {
return;
}
- do {
- if(draw)
- {
- raster_rect_inline(s, x-cx, y+cy, 2*cx, 1, col);
- raster_rect_inline(s, x-cx, y-cy, 2*cx, 1, col);
- draw=0;
- }
- if(cx!=cy)
- {
- if(cx)
- {
+ do {
+ if(draw) {
+ raster_rect_inline(s, x-cx, y+cy, 2*cx, 1, col);
+ raster_rect_inline(s, x-cx, y-cy, 2*cx, 1, col);
+ draw=0;
+ }
+ if(cx!=cy) {
+ if(cx) {
raster_rect_inline(s, x-cy, y-cx, 2*cy, 1, col);
raster_rect_inline(s, x-cy, y+cx, 2*cy, 1, col);
- }
- else
- {
+ } else {
raster_rect_inline(s, x-cy, y, 2*cy, 1, col);
}
- }
-
- if (df < 0)
- {
- df += d_e;
- d_e += 2;
- d_se += 2;
- }
- else
- {
- df += d_se;
- d_e += 2;
- d_se += 4;
- cy--;
- draw=1;
- }
- cx++;
- } while(cx <= cy);
+ }
+
+ if (df < 0) {
+ df += d_e;
+ d_e += 2;
+ d_se += 2;
+ } else {
+ df += d_se;
+ d_e += 2;
+ d_se += 4;
+ cy--;
+ draw=1;
+ }
+ cx++;
+ } while(cx <= cy);
#endif
}
#endif
@@ -1649,8 +1614,7 @@ void raster_aacircle(SDL_Surface *s, int16_t x, int16_t y, int16_t r, uint32_t c
/* Helper qsort callback for polygon drawing */
-static int gfxPrimitivesCompareInt(const void *a, const void *b)
-{
+static int gfxPrimitivesCompareInt(const void *a, const void *b) {
return (*(const int *) a) - (*(const int *) b);
}
@@ -1659,10 +1623,10 @@ static int gfxPrimitivesCompareInt(const void *a, const void *b)
static int *gfxPrimitivesPolyIntsGlobal = NULL;
static int gfxPrimitivesPolyAllocatedGlobal = 0;
-/* (Note: The last two parameters are optional; but required for multithreaded operation.) */
+/* (Note: The last two parameters are optional; but required for multithreaded operation.) */
-static inline int raster_filledPolygonColorMT(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color, int **polyInts, int *polyAllocated)
-{
+static inline int raster_filledPolygonColorMT(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n,
+ Uint32 color, int **polyInts, int *polyAllocated) {
/* sdl-gfx */
int result;
int i;
@@ -1679,135 +1643,133 @@ static inline int raster_filledPolygonColorMT(SDL_Surface * dst, const Sint16 *
* Check visibility of clipping rectangle
*/
if ((dst->clip_rect.w==0) || (dst->clip_rect.h==0)) {
- return(0);
+ return(0);
}
/*
* Sanity check number of edges
*/
if (n < 3) {
- return -1;
+ return -1;
}
-
+
/*
- * Map polygon cache
+ * Map polygon cache
*/
if ((polyInts==NULL) || (polyAllocated==NULL)) {
- /* Use global cache */
- gfxPrimitivesPolyInts = gfxPrimitivesPolyIntsGlobal;
- gfxPrimitivesPolyAllocated = gfxPrimitivesPolyAllocatedGlobal;
+ /* Use global cache */
+ gfxPrimitivesPolyInts = gfxPrimitivesPolyIntsGlobal;
+ gfxPrimitivesPolyAllocated = gfxPrimitivesPolyAllocatedGlobal;
} else {
- /* Use local cache */
- gfxPrimitivesPolyInts = *polyInts;
- gfxPrimitivesPolyAllocated = *polyAllocated;
+ /* Use local cache */
+ gfxPrimitivesPolyInts = *polyInts;
+ gfxPrimitivesPolyAllocated = *polyAllocated;
}
/*
- * Allocate temp array, only grow array
+ * Allocate temp array, only grow array
*/
if (!gfxPrimitivesPolyAllocated) {
- gfxPrimitivesPolyInts = (int *) malloc(sizeof(int) * n);
- gfxPrimitivesPolyAllocated = n;
+ gfxPrimitivesPolyInts = (int *) malloc(sizeof(int) * n);
+ gfxPrimitivesPolyAllocated = n;
} else {
- if (gfxPrimitivesPolyAllocated < n) {
- gfxPrimitivesPolyInts = (int *) realloc(gfxPrimitivesPolyInts, sizeof(int) * n);
- gfxPrimitivesPolyAllocated = n;
- }
+ if (gfxPrimitivesPolyAllocated < n) {
+ gfxPrimitivesPolyInts = (int *) realloc(gfxPrimitivesPolyInts, sizeof(int) * n);
+ gfxPrimitivesPolyAllocated = n;
+ }
}
/*
* Check temp array
*/
- if (gfxPrimitivesPolyInts==NULL) {
- gfxPrimitivesPolyAllocated = 0;
+ if (gfxPrimitivesPolyInts==NULL) {
+ gfxPrimitivesPolyAllocated = 0;
}
/*
* Update cache variables
*/
- if ((polyInts==NULL) || (polyAllocated==NULL)) {
- gfxPrimitivesPolyIntsGlobal = gfxPrimitivesPolyInts;
- gfxPrimitivesPolyAllocatedGlobal = gfxPrimitivesPolyAllocated;
+ if ((polyInts==NULL) || (polyAllocated==NULL)) {
+ gfxPrimitivesPolyIntsGlobal = gfxPrimitivesPolyInts;
+ gfxPrimitivesPolyAllocatedGlobal = gfxPrimitivesPolyAllocated;
} else {
- *polyInts = gfxPrimitivesPolyInts;
- *polyAllocated = gfxPrimitivesPolyAllocated;
+ *polyInts = gfxPrimitivesPolyInts;
+ *polyAllocated = gfxPrimitivesPolyAllocated;
}
/*
* Check temp array again
*/
- if (gfxPrimitivesPolyInts==NULL) {
- return(-1);
+ if (gfxPrimitivesPolyInts==NULL) {
+ return(-1);
}
/*
- * Determine Y maxima
+ * Determine Y maxima
*/
miny = vy[0];
maxy = vy[0];
for (i = 1; (i < n); i++) {
- if (vy[i] < miny) {
- miny = vy[i];
- } else if (vy[i] > maxy) {
- maxy = vy[i];
- }
+ if (vy[i] < miny) {
+ miny = vy[i];
+ } else if (vy[i] > maxy) {
+ maxy = vy[i];
+ }
}
/*
- * Draw, scanning y
+ * Draw, scanning y
*/
result = 0;
for (y = miny; (y <= maxy); y++) {
- ints = 0;
- for (i = 0; (i < n); i++) {
- if (!i) {
- ind1 = n - 1;
- ind2 = 0;
- } else {
- ind1 = i - 1;
- ind2 = i;
- }
- y1 = vy[ind1];
- y2 = vy[ind2];
- if (y1 < y2) {
- x1 = vx[ind1];
- x2 = vx[ind2];
- } else if (y1 > y2) {
- y2 = vy[ind1];
- y1 = vy[ind2];
- x2 = vx[ind1];
- x1 = vx[ind2];
- } else {
- continue;
- }
- if ( ((y >= y1) && (y < y2)) || ((y == maxy) && (y > y1) && (y <= y2)) ) {
- gfxPrimitivesPolyInts[ints++] = ((65536 * (y - y1)) / (y2 - y1)) * (x2 - x1) + (65536 * x1);
- }
- }
-
- qsort(gfxPrimitivesPolyInts, ints, sizeof(int), gfxPrimitivesCompareInt);
-
- for (i = 0; (i < ints); i += 2) {
- xa = gfxPrimitivesPolyInts[i] + 1;
- xa = (xa >> 16) + ((xa & 32768) >> 15);
- xb = gfxPrimitivesPolyInts[i+1] - 1;
- xb = (xb >> 16) + ((xb & 32768) >> 15);
- raster_hline(dst, xa, xb, y, color);
+ ints = 0;
+ for (i = 0; (i < n); i++) {
+ if (!i) {
+ ind1 = n - 1;
+ ind2 = 0;
+ } else {
+ ind1 = i - 1;
+ ind2 = i;
+ }
+ y1 = vy[ind1];
+ y2 = vy[ind2];
+ if (y1 < y2) {
+ x1 = vx[ind1];
+ x2 = vx[ind2];
+ } else if (y1 > y2) {
+ y2 = vy[ind1];
+ y1 = vy[ind2];
+ x2 = vx[ind1];
+ x1 = vx[ind2];
+ } else {
+ continue;
+ }
+ if ( ((y >= y1) && (y < y2)) || ((y == maxy) && (y > y1) && (y <= y2)) ) {
+ gfxPrimitivesPolyInts[ints++] = ((65536 * (y - y1)) / (y2 - y1)) * (x2 - x1) + (65536 * x1);
+ }
+ }
+
+ qsort(gfxPrimitivesPolyInts, ints, sizeof(int), gfxPrimitivesCompareInt);
+
+ for (i = 0; (i < ints); i += 2) {
+ xa = gfxPrimitivesPolyInts[i] + 1;
+ xa = (xa >> 16) + ((xa & 32768) >> 15);
+ xb = gfxPrimitivesPolyInts[i+1] - 1;
+ xb = (xb >> 16) + ((xb & 32768) >> 15);
+ raster_hline(dst, xa, xb, y, color);
// raster_rect_inline(dst, xa, y, xb - xa, 1, color);
- }
+ }
}
return (result);
}
-void raster_polygon(SDL_Surface *s, int16_t n, int16_t *vx, int16_t *vy, uint32_t col)
-{
+void raster_polygon(SDL_Surface *s, int16_t n, int16_t *vx, int16_t *vy, uint32_t col) {
raster_filledPolygonColorMT(s, vx, vy, n, col, NULL, NULL);
}
-void raster_aapolygon(SDL_Surface *dst, int16_t n, int16_t *vx, int16_t *vy, uint32_t color)
-{
+void raster_aapolygon(SDL_Surface *dst, int16_t n, int16_t *vx, int16_t *vy, uint32_t color) {
/* sdl-gfx + sge w/ rphlx changes: basically, draw aaline border,
then fill.
@@ -1833,19 +1795,19 @@ void raster_aapolygon(SDL_Surface *dst, int16_t n, int16_t *vx, int16_t *vy, uin
* Check visibility of clipping rectangle
*/
if ((dst->clip_rect.w==0) || (dst->clip_rect.h==0)) {
- return;
+ return;
}
/*
* Sanity check number of edges
*/
if (n < 3) {
- return;
+ return;
}
/*
- * Pointer setup
+ * Pointer setup
*/
px1 = px2 = vx;
py1 = py2 = vy;
@@ -1853,155 +1815,150 @@ void raster_aapolygon(SDL_Surface *dst, int16_t n, int16_t *vx, int16_t *vy, uin
py2++;
/*
- * Draw
+ * Draw
*/
for (i = 1; i < n; i++) {
- raster_aalineColorInt(dst, *px1, *py1, *px2, *py2, color, 0);
- px1 = px2;
- py1 = py2;
- px2++;
- py2++;
+ raster_aalineColorInt(dst, *px1, *py1, *px2, *py2, color, 0);
+ px1 = px2;
+ py1 = py2;
+ px2++;
+ py2++;
}
raster_aalineColorInt(dst, *px1, *py1, *vx, *vy, color, 0);
/*
- * Map polygon cache
+ * Map polygon cache
*/
if ((polyInts==NULL) || (polyAllocated==NULL)) {
- /* Use global cache */
- gfxPrimitivesPolyInts = gfxPrimitivesPolyIntsGlobal;
- gfxPrimitivesPolyAllocated = gfxPrimitivesPolyAllocatedGlobal;
+ /* Use global cache */
+ gfxPrimitivesPolyInts = gfxPrimitivesPolyIntsGlobal;
+ gfxPrimitivesPolyAllocated = gfxPrimitivesPolyAllocatedGlobal;
} else {
- /* Use local cache */
- gfxPrimitivesPolyInts = *polyInts;
- gfxPrimitivesPolyAllocated = *polyAllocated;
+ /* Use local cache */
+ gfxPrimitivesPolyInts = *polyInts;
+ gfxPrimitivesPolyAllocated = *polyAllocated;
}
/*
- * Allocate temp array, only grow array
+ * Allocate temp array, only grow array
*/
if (!gfxPrimitivesPolyAllocated) {
- gfxPrimitivesPolyInts = (int *) malloc(sizeof(int) * n);
- gfxPrimitivesPolyAllocated = n;
+ gfxPrimitivesPolyInts = (int *) malloc(sizeof(int) * n);
+ gfxPrimitivesPolyAllocated = n;
} else {
- if (gfxPrimitivesPolyAllocated < n) {
- gfxPrimitivesPolyInts = (int *) realloc(gfxPrimitivesPolyInts, sizeof(int) * n);
- gfxPrimitivesPolyAllocated = n;
- }
+ if (gfxPrimitivesPolyAllocated < n) {
+ gfxPrimitivesPolyInts = (int *) realloc(gfxPrimitivesPolyInts, sizeof(int) * n);
+ gfxPrimitivesPolyAllocated = n;
+ }
}
/*
* Check temp array
*/
- if (gfxPrimitivesPolyInts==NULL) {
- gfxPrimitivesPolyAllocated = 0;
+ if (gfxPrimitivesPolyInts==NULL) {
+ gfxPrimitivesPolyAllocated = 0;
}
/*
* Update cache variables
*/
- if ((polyInts==NULL) || (polyAllocated==NULL)) {
- gfxPrimitivesPolyIntsGlobal = gfxPrimitivesPolyInts;
- gfxPrimitivesPolyAllocatedGlobal = gfxPrimitivesPolyAllocated;
+ if ((polyInts==NULL) || (polyAllocated==NULL)) {
+ gfxPrimitivesPolyIntsGlobal = gfxPrimitivesPolyInts;
+ gfxPrimitivesPolyAllocatedGlobal = gfxPrimitivesPolyAllocated;
} else {
- *polyInts = gfxPrimitivesPolyInts;
- *polyAllocated = gfxPrimitivesPolyAllocated;
+ *polyInts = gfxPrimitivesPolyInts;
+ *polyAllocated = gfxPrimitivesPolyAllocated;
}
/*
* Check temp array again
*/
- if (gfxPrimitivesPolyInts==NULL) {
- return;
+ if (gfxPrimitivesPolyInts==NULL) {
+ return;
}
/*
- * Determine Y maxima
+ * Determine Y maxima
*/
miny = vy[0];
maxy = vy[0];
for (i = 1; (i < n); i++) {
- if (vy[i] < miny) {
- miny = vy[i];
- } else if (vy[i] > maxy) {
- maxy = vy[i];
- }
+ if (vy[i] < miny) {
+ miny = vy[i];
+ } else if (vy[i] > maxy) {
+ maxy = vy[i];
+ }
}
/*
- * Draw, scanning y
+ * Draw, scanning y
*/
for (y = miny; (y <= maxy); y++) {
- ints = 0;
- for (i = 0; (i < n); i++) {
- if (!i) {
- ind1 = n - 1;
- ind2 = 0;
- } else {
- ind1 = i - 1;
- ind2 = i;
- }
- y1 = vy[ind1];
- y2 = vy[ind2];
- if (y1 < y2) {
- x1 = vx[ind1];
- x2 = vx[ind2];
- } else if (y1 > y2) {
- y2 = vy[ind1];
- y1 = vy[ind2];
- x2 = vx[ind1];
- x1 = vx[ind2];
- } else {
- continue;
- }
- if ( ((y >= y1) && (y < y2)) || ((y == maxy) && (y > y1) && (y <= y2)) ) {
- gfxPrimitivesPolyInts[ints++] = ((65536 * (y - y1)) / (y2 - y1)) * (x2 - x1) + (65536 * x1);
- }
- }
-
- qsort(gfxPrimitivesPolyInts, ints, sizeof(int), gfxPrimitivesCompareInt);
+ ints = 0;
+ for (i = 0; (i < n); i++) {
+ if (!i) {
+ ind1 = n - 1;
+ ind2 = 0;
+ } else {
+ ind1 = i - 1;
+ ind2 = i;
+ }
+ y1 = vy[ind1];
+ y2 = vy[ind2];
+ if (y1 < y2) {
+ x1 = vx[ind1];
+ x2 = vx[ind2];
+ } else if (y1 > y2) {
+ y2 = vy[ind1];
+ y1 = vy[ind2];
+ x2 = vx[ind1];
+ x1 = vx[ind2];
+ } else {
+ continue;
+ }
+ if ( ((y >= y1) && (y < y2)) || ((y == maxy) && (y > y1) && (y <= y2)) ) {
+ gfxPrimitivesPolyInts[ints++] = ((65536 * (y - y1)) / (y2 - y1)) * (x2 - x1) + (65536 * x1);
+ }
+ }
+
+ qsort(gfxPrimitivesPolyInts, ints, sizeof(int), gfxPrimitivesCompareInt);
// o = p = -1;
- for (i = 0; (i < ints); i +=2) {
+ for (i = 0; (i < ints); i +=2) {
#if 0
- xa = gfxPrimitivesPolyInts[i] + 1;
- xa = (xa >> 16) + ((xa & 32768) >> 15);
- xb = gfxPrimitivesPolyInts[i+1] - 1;
- xb = (xb >> 16) + ((xb & 32768) >> 15);
+ xa = gfxPrimitivesPolyInts[i] + 1;
+ xa = (xa >> 16) + ((xa & 32768) >> 15);
+ xb = gfxPrimitivesPolyInts[i+1] - 1;
+ xb = (xb >> 16) + ((xb & 32768) >> 15);
#else
- xa = (gfxPrimitivesPolyInts[i] >> 16);
- xb = (gfxPrimitivesPolyInts[i+1] >> 16);
+ xa = (gfxPrimitivesPolyInts[i] >> 16);
+ xb = (gfxPrimitivesPolyInts[i+1] >> 16);
#endif
#if 0
- if(o < 0)
- {
- o = xa+1;
- }
- else if(p < 0)
- {
- p = xa;
- }
-
- if( (o >= 0) && (p >= 0))
- {
- if(p-o < 0)
- {
- o = p = -1;
- continue;
+ if(o < 0) {
+ o = xa+1;
+ } else if(p < 0) {
+ p = xa;
}
- raster_hlineColor(dst, o, p, y, color);
+ if( (o >= 0) && (p >= 0)) {
+ if(p-o < 0) {
+ o = p = -1;
+ continue;
+ }
- o = p = -1;
- }
+ raster_hlineColor(dst, o, p, y, color);
+
+ o = p = -1;
+ }
#else
- raster_hline(dst, xa+1, xb, y, color);
+ raster_hline(dst, xa+1, xb, y, color);
#endif
// raster_rect_inline(dst, xa, y, xb - xa, 1, color);
- }
+ }
}
}
diff --git a/navit/graphics/win32/graphics_win32.c b/navit/graphics/win32/graphics_win32.c
index a450789c4..668cd595d 100644
--- a/navit/graphics/win32/graphics_win32.c
+++ b/navit/graphics/win32/graphics_win32.c
@@ -29,10 +29,10 @@
#if defined(_WIN32_WCE) && _WIN32_WCE < 0x500 && !defined(__MINGW32CE__)
typedef struct {
- int BlendOp;
- int BlendFlags;
- int SourceConstantAlpha;
- int AlphaFormat;
+ int BlendOp;
+ int BlendFlags;
+ int SourceConstantAlpha;
+ int AlphaFormat;
} BLENDFUNCTION;
#define AC_SRC_OVER 1
@@ -58,8 +58,7 @@ typedef BOOL (WINAPI *FP_AlphaBlend) ( HDC hdcDest,
typedef int (WINAPI *FP_SetStretchBltMode) (HDC dc,int mode);
-struct graphics_priv
-{
+struct graphics_priv {
struct navit *nav;
struct window window;
struct point p;
@@ -95,8 +94,7 @@ struct graphics_priv
GHashTable *image_cache_hash;
};
-struct window_priv
-{
+struct window_priv {
HANDLE hBackLight;
};
@@ -121,8 +119,7 @@ HFONT EzCreateFont (HDC hdc, TCHAR * szFaceName, int iDeciPtHeight,
#define EZ_ATTR_STRIKEOUT 8
HFONT EzCreateFont (HDC hdc, TCHAR * szFaceName, int iDeciPtHeight,
- int iDeciPtWidth, int iAttributes, BOOL fLogRes)
-{
+ int iDeciPtWidth, int iAttributes, BOOL fLogRes) {
FLOAT cxDpi, cyDpi ;
HFONT hFont ;
LOGFONT lf ;
@@ -140,13 +137,10 @@ HFONT EzCreateFont (HDC hdc, TCHAR * szFaceName, int iDeciPtHeight,
SetWindowOrgEx (hdc, 0, 0, NULL) ;
#endif
- if (fLogRes)
- {
+ if (fLogRes) {
cxDpi = (FLOAT) GetDeviceCaps (hdc, LOGPIXELSX) ;
cyDpi = (FLOAT) GetDeviceCaps (hdc, LOGPIXELSY) ;
- }
- else
- {
+ } else {
cxDpi = (FLOAT) (25.4 * GetDeviceCaps (hdc, HORZRES) /
GetDeviceCaps (hdc, HORZSIZE)) ;
@@ -178,8 +172,7 @@ HFONT EzCreateFont (HDC hdc, TCHAR * szFaceName, int iDeciPtHeight,
hFont = CreateFontIndirect (&lf) ;
- if (iDeciPtWidth != 0)
- {
+ if (iDeciPtWidth != 0) {
hFont = (HFONT) SelectObject (hdc, hFont) ;
GetTextMetrics (hdc, &tm) ;
@@ -196,21 +189,19 @@ HFONT EzCreateFont (HDC hdc, TCHAR * szFaceName, int iDeciPtHeight,
return hFont ;
}
-struct graphics_image_priv
-{
+struct graphics_image_priv {
PXPM2BMP pxpm;
- int width,height,row_bytes,channels;
+ int width,height,row_bytes,channels;
unsigned char *png_pixels;
HBITMAP hBitmap;
struct point hot;
};
-static void ErrorExit(LPTSTR lpszFunction)
-{
+static void ErrorExit(LPTSTR lpszFunction) {
// Retrieve the system error message for the last-error code
- LPVOID lpMsgBuf;
+ LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
DWORD dw = GetLastError();
@@ -238,8 +229,7 @@ static void ErrorExit(LPTSTR lpszFunction)
-struct graphics_gc_priv
-{
+struct graphics_gc_priv {
HWND hwnd;
int line_width;
COLORREF fg_color;
@@ -253,13 +243,11 @@ struct graphics_gc_priv
};
-static void create_memory_dc(struct graphics_priv *gr)
-{
+static void create_memory_dc(struct graphics_priv *gr) {
HDC hdc;
BITMAPINFO bOverlayInfo;
- if (gr->hMemDC)
- {
+ if (gr->hMemDC) {
(void)SelectBitmap(gr->hMemDC, gr->hOldBitmap);
DeleteBitmap(gr->hBitmap);
DeleteDC(gr->hMemDC);
@@ -287,80 +275,72 @@ static void create_memory_dc(struct graphics_priv *gr)
bOverlayInfo.bmiHeader.biCompression = BI_RGB;
bOverlayInfo.bmiHeader.biPlanes = 1;
gr->hPrebuildDC = CreateCompatibleDC(NULL);
- gr->hPrebuildBitmap = CreateDIBSection(gr->hMemDC, &bOverlayInfo, DIB_RGB_COLORS , (void **)&gr->pPixelData, NULL, 0);
+ gr->hPrebuildBitmap = CreateDIBSection(gr->hMemDC, &bOverlayInfo, DIB_RGB_COLORS, (void **)&gr->pPixelData, NULL, 0);
gr->hOldPrebuildBitmap = SelectBitmap(gr->hPrebuildDC, gr->hPrebuildBitmap);
#endif
gr->hBitmap = CreateCompatibleBitmap(hdc, gr->width, gr->height );
- if ( gr->hBitmap )
- {
+ if ( gr->hBitmap ) {
gr->hOldBitmap = SelectBitmap( gr->hMemDC, gr->hBitmap);
}
ReleaseDC( gr->wnd_handle, hdc );
}
-static void HandleButtonClick( struct graphics_priv *gra_priv, int updown, int button, long lParam )
-{
+static void HandleButtonClick( struct graphics_priv *gra_priv, int updown, int button, long lParam ) {
struct point pt = { LOWORD(lParam), HIWORD(lParam) };
callback_list_call_attr_3(gra_priv->cbl, attr_button, (void *)updown, (void *)button, (void *)&pt);
}
-static void HandleKeyChar(struct graphics_priv *gra_priv, WPARAM wParam)
-{
+static void HandleKeyChar(struct graphics_priv *gra_priv, WPARAM wParam) {
TCHAR key = (TCHAR) wParam;
char *s=NULL;
- char k[]={0,0};
+ char k[]= {0,0};
dbg(lvl_debug,"HandleKey %d",key);
- switch (key) {
+ switch (key) {
default:
- k[0]=key;
- s=k;
+ k[0]=key;
+ s=k;
break;
}
- if (s)
+ if (s)
callback_list_call_attr_1(gra_priv->cbl, attr_keypress, (void *)s);
}
-static void HandleKeyDown(struct graphics_priv *gra_priv, WPARAM wParam)
-{
+static void HandleKeyDown(struct graphics_priv *gra_priv, WPARAM wParam) {
int key = (int) wParam;
- char up[]={NAVIT_KEY_UP,0};
- char down[]={NAVIT_KEY_DOWN,0};
- char left[]={NAVIT_KEY_LEFT,0};
- char right[]={NAVIT_KEY_RIGHT,0};
+ char up[]= {NAVIT_KEY_UP,0};
+ char down[]= {NAVIT_KEY_DOWN,0};
+ char left[]= {NAVIT_KEY_LEFT,0};
+ char right[]= {NAVIT_KEY_RIGHT,0};
char *s=NULL;
dbg(lvl_debug,"HandleKey %d",key);
- switch (key) {
+ switch (key) {
case 37:
- s=left;
+ s=left;
break;
case 38:
- s=up;
+ s=up;
break;
case 39:
- s=right;
+ s=right;
break;
case 40:
- s=down;
+ s=down;
break;
}
- if (s)
+ if (s)
callback_list_call_attr_1(gra_priv->cbl, attr_keypress, (void *)s);
}
-static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
-{
+static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
- struct graphics_priv* gra_priv = (struct graphics_priv*)GetWindowLongPtr( hwnd , DWLP_USER );
+ struct graphics_priv* gra_priv = (struct graphics_priv*)GetWindowLongPtr( hwnd, DWLP_USER );
- switch (Message)
- {
- case WM_CREATE:
- {
- if ( gra_priv )
- {
+ switch (Message) {
+ case WM_CREATE: {
+ if ( gra_priv ) {
RECT rc ;
GetClientRect( hwnd, &rc );
@@ -371,8 +351,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
}
break;
case WM_COMMAND:
- switch (LOWORD(wParam))
- {
+ switch (LOWORD(wParam)) {
case WM_USER + 1:
break;
}
@@ -381,8 +360,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
DestroyWindow(hwnd);
break;
case WM_USER+1:
- if ( gra_priv )
- {
+ if ( gra_priv ) {
RECT rc ;
GetClientRect( hwnd, &rc );
@@ -393,8 +371,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
callback_list_call_attr_2(gra_priv->cbl, attr_resize, (void *)gra_priv->width, (void *)gra_priv->height);
}
break;
- case WM_USER+2:
- {
+ case WM_USER+2: {
struct callback_list *cbl = (struct callback_list*)wParam;
#ifdef HAVE_API_WIN32_CE
/* FIXME: Reset the idle timer need a better place */
@@ -405,8 +382,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
break;
case WM_SIZE:
- if ( gra_priv )
- {
+ if ( gra_priv ) {
gra_priv->width = LOWORD( lParam );
gra_priv->height = HIWORD( lParam );
create_memory_dc(gra_priv);
@@ -416,11 +392,9 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
break;
case WM_DESTROY:
#ifdef HAVE_API_WIN32_CE
- if ( gra_priv && gra_priv->window.priv )
- {
+ if ( gra_priv && gra_priv->window.priv ) {
struct window_priv *win_priv = gra_priv->window.priv;
- if (win_priv->hBackLight)
- {
+ if (win_priv->hBackLight) {
ReleasePowerRequirement(win_priv->hBackLight);
}
}
@@ -428,9 +402,8 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
PostQuitMessage(0);
break;
case WM_PAINT:
- if ( gra_priv && gra_priv->hMemDC)
- {
- struct graphics_priv* overlay;
+ if ( gra_priv && gra_priv->hMemDC) {
+ struct graphics_priv* overlay;
PAINTSTRUCT ps = { 0 };
HDC hdc;
profile(0, NULL);
@@ -438,84 +411,79 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
overlay = gra_priv->overlays;
#ifndef FAST_TRANSPARENCY
- BitBlt( gra_priv->hPrebuildDC, 0, 0, gra_priv->width , gra_priv->height, gra_priv->hMemDC, 0, 0, SRCCOPY);
+ BitBlt( gra_priv->hPrebuildDC, 0, 0, gra_priv->width, gra_priv->height, gra_priv->hMemDC, 0, 0, SRCCOPY);
#endif
- while ( !gra_priv->disabled && overlay)
- {
- if ( !overlay->disabled && overlay->p.x >= 0 &&
- overlay->p.y >= 0 &&
- overlay->p.x < gra_priv->width &&
- overlay->p.y < gra_priv->height )
- {
- int x,y;
- int destPixel, srcPixel;
+ while ( !gra_priv->disabled && overlay) {
+ if ( !overlay->disabled && overlay->p.x >= 0 &&
+ overlay->p.y >= 0 &&
+ overlay->p.x < gra_priv->width &&
+ overlay->p.y < gra_priv->height ) {
+ int x,y;
+ int destPixel, srcPixel;
int h,w;
#ifdef FAST_TRANSPARENCY
- if ( !overlay->hPrebuildDC )
- {
- overlay->hPrebuildBitmap = CreateBitmap(overlay->width,overlay->height,1,1,NULL);
- overlay->hPrebuildDC = CreateCompatibleDC(NULL);
- overlay->hOldPrebuildBitmap = SelectBitmap( overlay->hPrebuildDC, overlay->hPrebuildBitmap);
- SetBkColor(overlay->hMemDC,RGB(overlay->transparent_color.r >> 8,overlay->transparent_color.g >> 8,overlay->transparent_color.b >> 8));
- BitBlt(overlay->hPrebuildDC,0,0,overlay->width,overlay->height,overlay->hMemDC,0,0,SRCCOPY);
- BitBlt(overlay->hMemDC,0,0,overlay->width,overlay->height,overlay->hPrebuildDC,0,0,SRCINVERT);
- }
+ if ( !overlay->hPrebuildDC ) {
+ overlay->hPrebuildBitmap = CreateBitmap(overlay->width,overlay->height,1,1,NULL);
+ overlay->hPrebuildDC = CreateCompatibleDC(NULL);
+ overlay->hOldPrebuildBitmap = SelectBitmap( overlay->hPrebuildDC, overlay->hPrebuildBitmap);
+ SetBkColor(overlay->hMemDC,RGB(overlay->transparent_color.r >> 8,overlay->transparent_color.g >> 8,
+ overlay->transparent_color.b >> 8));
+ BitBlt(overlay->hPrebuildDC,0,0,overlay->width,overlay->height,overlay->hMemDC,0,0,SRCCOPY);
+ BitBlt(overlay->hMemDC,0,0,overlay->width,overlay->height,overlay->hPrebuildDC,0,0,SRCINVERT);
+ }
#else
- const COLORREF transparent_color = RGB(overlay->transparent_color.r >> 8,overlay->transparent_color.g >> 8,overlay->transparent_color.b >> 8);
-
- BitBlt( overlay->hPrebuildDC, 0, 0, overlay->width , overlay->height, overlay->hMemDC, 0, 0, SRCCOPY);
-
- h=overlay->height;
- w=overlay->width;
- if (w > gra_priv->width-overlay->p.x)
- w=gra_priv->width-overlay->p.x;
- if (h > gra_priv->height-overlay->p.y)
- h=gra_priv->height-overlay->p.y;
- for ( y = 0; y < h ;y++ )
- {
- for ( x = 0; x < w; x++ )
- {
- srcPixel = y*overlay->width+x;
- destPixel = ((overlay->p.y + y) * gra_priv->width) + (overlay->p.x + x);
- if ( overlay->pPixelData[srcPixel] == transparent_color )
- {
- destPixel = ((overlay->p.y + y) * gra_priv->width) + (overlay->p.x + x);
-
- gra_priv->pPixelData[destPixel] = RGB ( ((65535 - overlay->transparent_color.a) * GetRValue(gra_priv->pPixelData[destPixel]) + overlay->transparent_color.a * GetRValue(overlay->pPixelData[srcPixel])) / 65535,
- ((65535 - overlay->transparent_color.a) * GetGValue(gra_priv->pPixelData[destPixel]) + overlay->transparent_color.a * GetGValue(overlay->pPixelData[srcPixel])) / 65535,
- ((65535 - overlay->transparent_color.a) * GetBValue(gra_priv->pPixelData[destPixel]) + overlay->transparent_color.a * GetBValue(overlay->pPixelData[srcPixel])) / 65535);
-
- }
- else
- {
- gra_priv->pPixelData[destPixel] = overlay->pPixelData[srcPixel];
- }
- }
-
- }
+ const COLORREF transparent_color = RGB(overlay->transparent_color.r >> 8,overlay->transparent_color.g >> 8,
+ overlay->transparent_color.b >> 8);
+
+ BitBlt( overlay->hPrebuildDC, 0, 0, overlay->width, overlay->height, overlay->hMemDC, 0, 0, SRCCOPY);
+
+ h=overlay->height;
+ w=overlay->width;
+ if (w > gra_priv->width-overlay->p.x)
+ w=gra_priv->width-overlay->p.x;
+ if (h > gra_priv->height-overlay->p.y)
+ h=gra_priv->height-overlay->p.y;
+ for ( y = 0; y < h ; y++ ) {
+ for ( x = 0; x < w; x++ ) {
+ srcPixel = y*overlay->width+x;
+ destPixel = ((overlay->p.y + y) * gra_priv->width) + (overlay->p.x + x);
+ if ( overlay->pPixelData[srcPixel] == transparent_color ) {
+ destPixel = ((overlay->p.y + y) * gra_priv->width) + (overlay->p.x + x);
+
+ gra_priv->pPixelData[destPixel] = RGB ( ((65535 - overlay->transparent_color.a) * GetRValue(
+ gra_priv->pPixelData[destPixel]) + overlay->transparent_color.a * GetRValue(overlay->pPixelData[srcPixel])) / 65535,
+ ((65535 - overlay->transparent_color.a) * GetGValue(gra_priv->pPixelData[destPixel]) + overlay->transparent_color.a *
+ GetGValue(overlay->pPixelData[srcPixel])) / 65535,
+ ((65535 - overlay->transparent_color.a) * GetBValue(gra_priv->pPixelData[destPixel]) + overlay->transparent_color.a *
+ GetBValue(overlay->pPixelData[srcPixel])) / 65535);
+
+ } else {
+ gra_priv->pPixelData[destPixel] = overlay->pPixelData[srcPixel];
+ }
+ }
+
+ }
#endif
- }
- overlay = overlay->next;
- }
+ }
+ overlay = overlay->next;
+ }
#ifndef FAST_TRANSPARENCY
hdc = BeginPaint(hwnd, &ps);
- BitBlt( hdc, 0, 0, gra_priv->width , gra_priv->height, gra_priv->hPrebuildDC, 0, 0, SRCCOPY );
+ BitBlt( hdc, 0, 0, gra_priv->width, gra_priv->height, gra_priv->hPrebuildDC, 0, 0, SRCCOPY );
#else
HDC hdc = BeginPaint(hwnd, &ps);
- BitBlt( hdc, 0, 0, gra_priv->width , gra_priv->height, gra_priv->hMemDC, 0, 0, SRCCOPY );
+ BitBlt( hdc, 0, 0, gra_priv->width, gra_priv->height, gra_priv->hMemDC, 0, 0, SRCCOPY );
overlay = gra_priv->overlays;
- while ( !gra_priv->disabled && overlay && !overlay->disabled )
- {
+ while ( !gra_priv->disabled && overlay && !overlay->disabled ) {
if ( overlay->p.x > 0 &&
overlay->p.y > 0 &&
overlay->p.x + overlay->width < gra_priv->width &&
- overlay->p.y + overlay->height < gra_priv->height )
- {
+ overlay->p.y + overlay->height < gra_priv->height ) {
BitBlt(hdc,overlay->p.x,overlay->p.y,overlay->width,overlay->height,overlay->hPrebuildDC,0,0,SRCAND);
BitBlt(hdc,overlay->p.x,overlay->p.y,overlay->width,overlay->height,overlay->hMemDC,0,0,SRCPAINT);
}
@@ -526,21 +494,18 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
profile(0, "WM_PAINT\n");
}
break;
- case WM_MOUSEMOVE:
- {
+ case WM_MOUSEMOVE: {
struct point pt = { LOWORD(lParam), HIWORD(lParam) };
callback_list_call_attr_1(gra_priv->cbl, attr_motion, (void *)&pt);
}
break;
- case WM_LBUTTONDOWN:
- {
+ case WM_LBUTTONDOWN: {
dbg(lvl_debug, "LBUTTONDOWN");
HandleButtonClick( gra_priv, 1, 1, lParam);
}
break;
- case WM_LBUTTONUP:
- {
+ case WM_LBUTTONUP: {
dbg(lvl_debug, "LBUTTONUP");
HandleButtonClick( gra_priv, 0, 1, lParam);
}
@@ -561,23 +526,23 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
case WM_KEYDOWN:
HandleKeyDown( gra_priv, wParam);
break;
- case WM_COPYDATA:
- dbg(lvl_debug,"got WM_COPYDATA");
+ case WM_COPYDATA:
+ dbg(lvl_debug,"got WM_COPYDATA");
callback_list_call_attr_2(gra_priv->cbl, attr_wm_copydata, (void *)wParam, (void*)lParam);
break;
#ifdef HAVE_API_WIN32_CE
case WM_SETFOCUS:
if (fullscr) {
- HWND hwndSip = FindWindow(L"MS_SIPBUTTON", NULL);
- // deactivate the SIP button
- ShowWindow(hwndSip, SW_HIDE);
+ HWND hwndSip = FindWindow(L"MS_SIPBUTTON", NULL);
+ // deactivate the SIP button
+ ShowWindow(hwndSip, SW_HIDE);
}
break;
- case WM_KILLFOCUS:
+ case WM_KILLFOCUS:
if (fullscr != 1) {
- HWND hwndSip = FindWindow(L"MS_SIPBUTTON", NULL);
- // active the SIP button
- ShowWindow(hwndSip, SW_SHOW);
+ HWND hwndSip = FindWindow(L"MS_SIPBUTTON", NULL);
+ // active the SIP button
+ ShowWindow(hwndSip, SW_SHOW);
}
break;
#endif
@@ -587,34 +552,34 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
return 0;
}
-static int fullscreen(struct window *win, int on)
-{
+static int fullscreen(struct window *win, int on) {
#ifdef HAVE_API_WIN32_CE
HWND hwndTaskbar = FindWindow(L"HHTaskBar", NULL);
HWND hwndSip = FindWindow(L"MS_SIPBUTTON", NULL);
RECT taskbar_rect;
fullscr = on;
- if (on) {
+ if (on) {
ShowWindow(hwndTaskbar, SW_HIDE);
MoveWindow(g_hwnd, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), FALSE);
-
- // deactivate the SIP button
- ShowWindow(hwndSip, SW_HIDE);
-
- } else {
+
+ // deactivate the SIP button
+ ShowWindow(hwndSip, SW_HIDE);
+
+ } else {
ShowWindow(hwndTaskbar, SW_SHOW);
GetWindowRect( hwndTaskbar, &taskbar_rect);
- MoveWindow(g_hwnd, 0, taskbar_rect.bottom, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN) - taskbar_rect.bottom, FALSE);
-
- // activate the SIP button
- ShowWindow(hwndSip, SW_SHOW);
+ MoveWindow(g_hwnd, 0, taskbar_rect.bottom, GetSystemMetrics(SM_CXSCREEN),
+ GetSystemMetrics(SM_CYSCREEN) - taskbar_rect.bottom, FALSE);
+
+ // activate the SIP button
+ ShowWindow(hwndSip, SW_SHOW);
}
#else
- if (on) {
+ if (on) {
ShowWindow(g_hwnd, SW_MAXIMIZE);
- } else {
+ } else {
ShowWindow(g_hwnd, SW_RESTORE);
}
@@ -625,14 +590,12 @@ static int fullscreen(struct window *win, int on)
extern void WINAPI SystemIdleTimerReset(void);
static struct event_timeout *
- event_win32_add_timeout(int timeout, int multi, struct callback *cb);
+event_win32_add_timeout(int timeout, int multi, struct callback *cb);
-static void disable_suspend(struct window *win)
-{
+static void disable_suspend(struct window *win) {
#ifdef HAVE_API_WIN32_CE
struct window_priv *win_priv = win->priv;
- if ( win_priv && !win_priv->hBackLight )
- {
+ if ( win_priv && !win_priv->hBackLight ) {
win_priv->hBackLight = SetPowerRequirement(TEXT("BKL1:"), 0, 0x01, NULL, 0);
event_win32_add_timeout(29000, 1, callback_new(SystemIdleTimerReset, 0, NULL));
}
@@ -643,8 +606,7 @@ static void disable_suspend(struct window *win)
static const TCHAR g_szClassName[] = {'N','A','V','G','R','A','\0'};
-static HANDLE CreateGraphicsWindows( struct graphics_priv* gr, HMENU hMenu )
-{
+static HANDLE CreateGraphicsWindows( struct graphics_priv* gr, HMENU hMenu ) {
int wStyle = WS_VISIBLE;
HWND hwnd;
#ifdef HAVE_API_WIN32_CE
@@ -693,16 +655,14 @@ static HANDLE CreateGraphicsWindows( struct graphics_priv* gr, HMENU hMenu )
return NULL;
}
- if(gr->frame)
- {
- if ( hMenu )
- {
+ if(gr->frame) {
+ if ( hMenu ) {
wStyle = WS_CHILD;
} else {
wStyle = WS_OVERLAPPED|WS_VISIBLE;
}
} else {
- wStyle = WS_VISIBLE | WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
+ wStyle = WS_VISIBLE | WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
}
#ifdef HAVE_API_WIN32_CE
@@ -730,8 +690,7 @@ static HANDLE CreateGraphicsWindows( struct graphics_priv* gr, HMENU hMenu )
GetModuleHandle(NULL),
NULL);
#endif
- if (hwnd == NULL)
- {
+ if (hwnd == NULL) {
dbg(lvl_error, "Window creation failed: %d", GetLastError());
return NULL;
}
@@ -739,16 +698,16 @@ static HANDLE CreateGraphicsWindows( struct graphics_priv* gr, HMENU hMenu )
not avail for earlier Win and not present in my mingw :(. ChangeWindowMessageFilter may not be present in later Win versions. Welcome late binding!
*/
if(gr->ChangeWindowMessageFilter)
- gr->ChangeWindowMessageFilter(WM_COPYDATA,1 /*MSGFLT_ADD*/);
- else if(gr->ChangeWindowMessageFilterEx)
- gr->ChangeWindowMessageFilterEx(hwnd,WM_COPYDATA,1 /*MSGFLT_ALLOW*/,NULL);
+ gr->ChangeWindowMessageFilter(WM_COPYDATA,1 /*MSGFLT_ADD*/);
+ else if(gr->ChangeWindowMessageFilterEx)
+ gr->ChangeWindowMessageFilterEx(hwnd,WM_COPYDATA,1 /*MSGFLT_ALLOW*/,NULL);
gr->wnd_handle = hwnd;
callback_list_call_attr_2(gr->cbl, attr_resize, (void *)gr->width, (void *)gr->height);
create_memory_dc(gr);
- SetWindowLongPtr( hwnd , DWLP_USER, (LONG_PTR)gr );
+ SetWindowLongPtr( hwnd, DWLP_USER, (LONG_PTR)gr );
ShowWindow( hwnd, SW_SHOW );
UpdateWindow( hwnd );
@@ -760,38 +719,33 @@ static HANDLE CreateGraphicsWindows( struct graphics_priv* gr, HMENU hMenu )
-static void graphics_destroy(struct graphics_priv *gr)
-{
+static void graphics_destroy(struct graphics_priv *gr) {
g_free( gr );
}
-static void gc_destroy(struct graphics_gc_priv *gc)
-{
+static void gc_destroy(struct graphics_gc_priv *gc) {
DeleteObject( gc->hpen );
DeleteObject( gc->hbrush );
g_free( gc );
}
-static void gc_set_linewidth(struct graphics_gc_priv *gc, int w)
-{
+static void gc_set_linewidth(struct graphics_gc_priv *gc, int w) {
DeleteObject (gc->hpen);
gc->line_width = w;
gc->hpen = CreatePen(gc->dashed?PS_DASH:PS_SOLID, gc->line_width, gc->fg_color );
}
-static void gc_set_dashes(struct graphics_gc_priv *gc, int width, int offset, unsigned char dash_list[], int n)
-{
- gc->dashed=n>0;
- DeleteObject (gc->hpen);
- gc->hpen = CreatePen(gc->dashed?PS_DASH:PS_SOLID, gc->line_width, gc->fg_color );
+static void gc_set_dashes(struct graphics_gc_priv *gc, int width, int offset, unsigned char dash_list[], int n) {
+ gc->dashed=n>0;
+ DeleteObject (gc->hpen);
+ gc->hpen = CreatePen(gc->dashed?PS_DASH:PS_SOLID, gc->line_width, gc->fg_color );
// gdk_gc_set_dashes(gc->gc, 0, (gint8 *)dash_list, n);
// gdk_gc_set_line_attributes(gc->gc, 1, GDK_LINE_ON_OFF_DASH, GDK_CAP_ROUND, GDK_JOIN_ROUND);
}
-static void gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
-{
+static void gc_set_foreground(struct graphics_gc_priv *gc, struct color *c) {
gc->fg_color = RGB( c->r >> 8, c->g >> 8, c->b >> 8);
gc->fg_alpha = c->a;
@@ -799,15 +753,13 @@ static void gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
DeleteObject (gc->hbrush);
gc->hpen = CreatePen(gc->dashed?PS_DASH:PS_SOLID, gc->line_width, gc->fg_color );
gc->hbrush = CreateSolidBrush( gc->fg_color );
- if ( gc->gr && c->a < 0xFFFF )
- {
- gc->gr->transparent_color = *c;
+ if ( gc->gr && c->a < 0xFFFF ) {
+ gc->gr->transparent_color = *c;
}
}
-static void gc_set_background(struct graphics_gc_priv *gc, struct color *c)
-{
+static void gc_set_background(struct graphics_gc_priv *gc, struct color *c) {
gc->bg_color = RGB( c->r >> 8, c->g >> 8, c->b >> 8);
gc->bg_alpha = c->a;
if ( gc->gr && gc->gr->hMemDC )
@@ -815,8 +767,7 @@ static void gc_set_background(struct graphics_gc_priv *gc, struct color *c)
}
-static struct graphics_gc_methods gc_methods =
-{
+static struct graphics_gc_methods gc_methods = {
gc_destroy,
gc_set_linewidth,
gc_set_dashes,
@@ -824,8 +775,7 @@ static struct graphics_gc_methods gc_methods =
gc_set_background,
};
-static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
-{
+static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth) {
struct graphics_gc_priv *gc=g_new(struct graphics_gc_priv, 1);
*meth=gc_methods;
gc->hwnd = gr->wnd_handle;
@@ -842,23 +792,18 @@ static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics
}
-static void draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
+static void draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
int i;
HPEN hpenold = SelectObject( gr->hMemDC, gc->hpen );
int oldbkmode=SetBkMode( gr->hMemDC, TRANSPARENT);
int first = 1;
- for ( i = 0; i< count; i++ )
- {
- if ( first )
- {
+ for ( i = 0; i< count; i++ ) {
+ if ( first ) {
first = 0;
MoveToEx( gr->hMemDC, p[0].x, p[0].y, NULL );
- }
- else
- {
+ } else {
LineTo( gr->hMemDC, p[i].x, p[i].y );
}
}
@@ -866,28 +811,25 @@ static void draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, st
SelectObject( gr->hMemDC, hpenold);
}
-static void draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
-{
+static void draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count) {
HPEN holdpen = SelectObject( gr->hMemDC, gc->hpen );
HBRUSH holdbrush = SelectObject( gr->hMemDC, gc->hbrush );
if (sizeof(POINT) != sizeof(struct point)) {
- int i;
- POINT* points=g_alloca(sizeof(POINT)*count);
- for ( i=0;i< count; i++ )
- {
- points[i].x = p[i].x;
- points[i].y = p[i].y;
- }
- Polygon( gr->hMemDC, points,count );
+ int i;
+ POINT* points=g_alloca(sizeof(POINT)*count);
+ for ( i=0; i< count; i++ ) {
+ points[i].x = p[i].x;
+ points[i].y = p[i].y;
+ }
+ Polygon( gr->hMemDC, points,count );
} else
- Polygon( gr->hMemDC, (POINT *)p, count);
+ Polygon( gr->hMemDC, (POINT *)p, count);
SelectObject( gr->hMemDC, holdbrush);
SelectObject( gr->hMemDC, holdpen);
}
-static void draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h)
-{
+static void draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int w, int h) {
HPEN holdpen = SelectObject( gr->hMemDC, gc->hpen );
HBRUSH holdbrush = SelectObject( gr->hMemDC, gc->hbrush );
@@ -897,8 +839,7 @@ static void draw_rectangle(struct graphics_priv *gr, struct graphics_gc_priv *gc
SelectObject( gr->hMemDC, holdpen);
}
-static void draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r)
-{
+static void draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int r) {
HPEN holdpen = SelectObject( gr->hMemDC, gc->hpen );
HBRUSH holdbrush = SelectObject( gr->hMemDC, GetStockObject(NULL_BRUSH));
@@ -911,43 +852,32 @@ static void draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, s
}
-static void draw_drag(struct graphics_priv *gr, struct point *p)
-{
- if ( p )
- {
+static void draw_drag(struct graphics_priv *gr, struct point *p) {
+ if ( p ) {
gr->p.x = p->x;
gr->p.y = p->y;
if ( p->x < 0 || p->y < 0 ||
- ( gr->parent && ((p->x + gr->width > gr->parent->width) || (p->y + gr->height > gr->parent->height) )))
- {
+ ( gr->parent && ((p->x + gr->width > gr->parent->width) || (p->y + gr->height > gr->parent->height) ))) {
gr->disabled = TRUE;
- }
- else
- {
+ } else {
gr->disabled = FALSE;
}
}
}
-static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
-{
+static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) {
dbg(lvl_debug, "set draw_mode to %x, %d", gr, (int)mode );
- if ( mode == draw_mode_begin )
- {
- if ( gr->wnd_handle == NULL )
- {
+ if ( mode == draw_mode_begin ) {
+ if ( gr->wnd_handle == NULL ) {
CreateGraphicsWindows( gr, (HMENU)ID_CHILD_GFX );
}
- if ( gr->mode != draw_mode_begin )
- {
- if ( gr->hMemDC )
- {
+ if ( gr->mode != draw_mode_begin ) {
+ if ( gr->hMemDC ) {
dbg(lvl_debug, "Erase dc: %x, w: %d, h: %d, bg_color: %x", gr, gr->width, gr->height, gr->bg_color);
#ifdef FAST_TRANSPARENCY
- if ( gr->hPrebuildDC )
- {
+ if ( gr->hPrebuildDC ) {
(void)SelectBitmap(gr->hPrebuildDC, gr->hOldPrebuildBitmap );
DeleteBitmap(gr->hPrebuildBitmap);
DeleteDC(gr->hPrebuildDC);
@@ -957,8 +887,7 @@ static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
}
}
#ifdef FAST_TRANSPARENCY
- else if ( gr->hPrebuildDC )
- {
+ else if ( gr->hPrebuildDC ) {
(void)SelectBitmap(gr->hPrebuildDC, gr->hOldPrebuildBitmap );
DeleteBitmap(gr->hPrebuildBitmap);
DeleteDC(gr->hPrebuildDC);
@@ -968,8 +897,7 @@ static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
}
// force paint
- if (mode == draw_mode_end && gr->mode == draw_mode_begin)
- {
+ if (mode == draw_mode_end && gr->mode == draw_mode_begin) {
InvalidateRect( gr->wnd_handle, NULL, FALSE );
}
@@ -977,20 +905,16 @@ static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
}
-static void * get_data(struct graphics_priv *this_, const char *type)
-{
- if ( strcmp( "wnd_parent_handle_ptr", type ) == 0 )
- {
+static void * get_data(struct graphics_priv *this_, const char *type) {
+ if ( strcmp( "wnd_parent_handle_ptr", type ) == 0 ) {
return &( this_->wnd_parent_handle );
}
- if ( strcmp( "START_CLIENT", type ) == 0 )
- {
+ if ( strcmp( "START_CLIENT", type ) == 0 ) {
CreateGraphicsWindows( this_, (HMENU)ID_CHILD_GFX );
return NULL;
}
- if (!strcmp(type, "window"))
- {
- CreateGraphicsWindows( this_ , NULL);
+ if (!strcmp(type, "window")) {
+ CreateGraphicsWindows( this_, NULL);
this_->window.fullscreen = fullscreen;
this_->window.disable_suspend = disable_suspend;
@@ -1003,8 +927,7 @@ static void * get_data(struct graphics_priv *this_, const char *type)
}
-static void background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
-{
+static void background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc) {
RECT rcClient = { 0, 0, gr->width, gr->height };
HBRUSH bgBrush;
@@ -1015,15 +938,14 @@ static void background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
DeleteObject( bgBrush );
}
-struct graphics_font_priv
-{
+struct graphics_font_priv {
LOGFONT lf;
HFONT hfont;
int size;
};
-static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy)
-{
+static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg,
+ struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy) {
RECT rcClient;
int prevBkMode;
HFONT hOldFont;
@@ -1033,8 +955,7 @@ static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, str
prevBkMode = SetBkMode( gr->hMemDC, TRANSPARENT );
- if ( NULL == font->hfont )
- {
+ if ( NULL == font->hfont ) {
#ifdef WIN_USE_SYSFONT
font->hfont = (HFONT) GetStockObject (SYSTEM_FONT);
GetObject (font->hfont, sizeof (LOGFONT), &font->lf);
@@ -1064,22 +985,21 @@ static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, str
SetBkMode (gr->hMemDC, TRANSPARENT);
if (ConvertUTF8toUTF16(&utf8, utf8+strlen(text),
&utf16p, utf16p+sizeof(utf16),
- lenientConversion) == conversionOK)
- {
- if(bg && bg->fg_alpha) {
- SetTextColor(gr->hMemDC, bg->fg_color);
- ExtTextOutW(gr->hMemDC, -1, -1, 0, NULL,
- utf16, (wchar_t*) utf16p - utf16, NULL);
- ExtTextOutW(gr->hMemDC, 1, 1, 0, NULL,
- utf16, (wchar_t*) utf16p - utf16, NULL);
- ExtTextOutW(gr->hMemDC, -1, 1, 0, NULL,
- utf16, (wchar_t*) utf16p - utf16, NULL);
- ExtTextOutW(gr->hMemDC, 1, -1, 0, NULL,
- utf16, (wchar_t*) utf16p - utf16, NULL);
+ lenientConversion) == conversionOK) {
+ if(bg && bg->fg_alpha) {
+ SetTextColor(gr->hMemDC, bg->fg_color);
+ ExtTextOutW(gr->hMemDC, -1, -1, 0, NULL,
+ utf16, (wchar_t*) utf16p - utf16, NULL);
+ ExtTextOutW(gr->hMemDC, 1, 1, 0, NULL,
+ utf16, (wchar_t*) utf16p - utf16, NULL);
+ ExtTextOutW(gr->hMemDC, -1, 1, 0, NULL,
+ utf16, (wchar_t*) utf16p - utf16, NULL);
+ ExtTextOutW(gr->hMemDC, 1, -1, 0, NULL,
+ utf16, (wchar_t*) utf16p - utf16, NULL);
}
- SetTextColor(gr->hMemDC, fg->fg_color);
+ SetTextColor(gr->hMemDC, fg->fg_color);
ExtTextOutW(gr->hMemDC, 0, 0, 0, NULL,
- utf16, (wchar_t*) utf16p - utf16, NULL);
+ utf16, (wchar_t*) utf16p - utf16, NULL);
}
}
@@ -1092,22 +1012,19 @@ static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, str
SetViewportOrgEx (gr->hMemDC, 0, 0, NULL) ;
}
-static void font_destroy(struct graphics_font_priv *font)
-{
- if ( font->hfont )
- {
+static void font_destroy(struct graphics_font_priv *font) {
+ if ( font->hfont ) {
DeleteObject(font->hfont);
}
g_free(font);
}
-static struct graphics_font_methods font_methods =
-{
+static struct graphics_font_methods font_methods = {
font_destroy
};
-static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth, char *name, int size, int flags)
-{
+static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth, char *name,
+ int size, int flags) {
struct graphics_font_priv *font=g_new(struct graphics_font_priv, 1);
*meth = font_methods;
@@ -1120,8 +1037,7 @@ static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct grap
#include "png.h"
static int
-pngdecode(struct graphics_priv *gr, char *name, struct graphics_image_priv *img)
-{
+pngdecode(struct graphics_priv *gr, char *name, struct graphics_image_priv *img) {
png_struct *png_ptr = NULL;
png_info *info_ptr = NULL;
png_byte buf[8];
@@ -1138,8 +1054,7 @@ pngdecode(struct graphics_priv *gr, char *name, struct graphics_image_priv *img)
dbg(lvl_debug,"enter %s",name);
png_file=fopen(name, "rb");
- if (!png_file)
- {
+ if (!png_file) {
dbg(lvl_warning,"failed to open %s",name);
return FALSE;
}
@@ -1147,15 +1062,13 @@ pngdecode(struct graphics_priv *gr, char *name, struct graphics_image_priv *img)
/* read and check signature in PNG file */
ret = fread (buf, 1, 8, png_file);
- if (ret != 8)
- {
+ if (ret != 8) {
fclose(png_file);
return FALSE;
}
ret = png_check_sig (buf, 8);
- if (!ret)
- {
+ if (!ret) {
fclose(png_file);
return FALSE;
}
@@ -1164,22 +1077,19 @@ pngdecode(struct graphics_priv *gr, char *name, struct graphics_image_priv *img)
png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL);
- if (!png_ptr)
- {
+ if (!png_ptr) {
fclose(png_file);
return FALSE; /* out of memory */
}
info_ptr = png_create_info_struct (png_ptr);
- if (!info_ptr)
- {
+ if (!info_ptr) {
fclose(png_file);
png_destroy_read_struct (&png_ptr, NULL, NULL);
return FALSE; /* out of memory */
}
- if (setjmp (png_jmpbuf(png_ptr)))
- {
+ if (setjmp (png_jmpbuf(png_ptr))) {
fclose(png_file);
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
return FALSE;
@@ -1204,20 +1114,20 @@ pngdecode(struct graphics_priv *gr, char *name, struct graphics_image_priv *img)
png_set_palette_to_rgb(png_ptr);
/* expand images to bit-depth 8 (only applicable for grayscale images) */
- if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA && bit_depth < 8)
- png_set_gray_1_2_4_to_8(png_ptr);
+ if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA && bit_depth < 8)
+ png_set_gray_1_2_4_to_8(png_ptr);
/* Expand grayscale to rgb */
if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
- png_set_gray_to_rgb(png_ptr);
+ png_set_gray_to_rgb(png_ptr);
/* expand colored images to bit-depth 8 */
if (color_type == PNG_COLOR_TYPE_RGB && bit_depth < 8)
png_set_packing(png_ptr);
/* transform transparency maps into full alpha-channel */
- if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
- png_set_tRNS_to_alpha(png_ptr);
+ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
+ png_set_tRNS_to_alpha(png_ptr);
/* Add opaque alpha channel if no alpha channel exist */
if (color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_PALETTE)
@@ -1236,7 +1146,7 @@ pngdecode(struct graphics_priv *gr, char *name, struct graphics_image_priv *img)
img->channels = 4;
alpha_present = 1;
-
+
/* row_bytes is the width x number of channels x (bit-depth / 8) */
img->row_bytes = png_get_rowbytes (png_ptr, info_ptr);
@@ -1248,11 +1158,10 @@ pngdecode(struct graphics_priv *gr, char *name, struct graphics_image_priv *img)
pnginfo.bmiHeader.biCompression = BI_RGB;
pnginfo.bmiHeader.biPlanes = 1;
dc = CreateCompatibleDC(NULL);
- img->hBitmap = CreateDIBSection(dc, &pnginfo, DIB_RGB_COLORS , (void **)&img->png_pixels, NULL, 0);
+ img->hBitmap = CreateDIBSection(dc, &pnginfo, DIB_RGB_COLORS, (void **)&img->png_pixels, NULL, 0);
DeleteDC(dc);
- if ((row_pointers = (png_byte **) g_malloc (img->height * sizeof (png_bytep))) == NULL)
- {
+ if ((row_pointers = (png_byte **) g_malloc (img->height * sizeof (png_bytep))) == NULL) {
fclose(png_file);
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
g_free (img->png_pixels);
@@ -1284,122 +1193,112 @@ pngdecode(struct graphics_priv *gr, char *name, struct graphics_image_priv *img)
} /* end of source */
-static void pngscale(struct graphics_image_priv *img, struct graphics_priv *gr, int width, int height)
-{
- HBITMAP origBmp;
+static void pngscale(struct graphics_image_priv *img, struct graphics_priv *gr, int width, int height) {
+ HBITMAP origBmp;
+ BITMAPINFO pnginfo;
+ HDC dc1, dc2;
+ png_byte *origPixels;
+
+ origBmp=img->hBitmap;
+ origPixels=img->png_pixels;
+
+ memset(&pnginfo, 0, sizeof(pnginfo));
+ pnginfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+ pnginfo.bmiHeader.biWidth = width;
+ pnginfo.bmiHeader.biHeight = -height;
+ pnginfo.bmiHeader.biBitCount = 32;
+ pnginfo.bmiHeader.biCompression = BI_RGB;
+ pnginfo.bmiHeader.biPlanes = 1;
+ dc1 = CreateCompatibleDC(NULL);
+ dc2 = CreateCompatibleDC(NULL);
+ img->hBitmap = CreateDIBSection(dc1, &pnginfo, DIB_RGB_COLORS, (void **)&(img->png_pixels), NULL, 0);
+
+ if(gr->SetStretchBltMode) {
+ gr->SetStretchBltMode(dc1,STRETCH_HALFTONE);
+ SetBrushOrgEx(dc1,0,0,NULL);
+ }
+
+ SelectBitmap(dc1,img->hBitmap);
+ SelectBitmap(dc2,origBmp);
+
+ StretchBlt(dc1,0,0,width, height, dc2, 0,0, img->width, img->height,SRCCOPY);
+ img->width=width;
+ img->height=height;
+ img->hot.x=width/2-1;
+ img->hot.y=height/2-1;
+
+ DeleteDC(dc1);
+ DeleteDC(dc2);
+ DeleteObject(origBmp);
+}
+
+
+static void
+pngrender(struct graphics_image_priv *img, struct graphics_priv *gr, int x0, int y0) {
+ if (gr->AlphaBlend && img->hBitmap) {
+ HDC hdc;
+ HBITMAP oldBitmap;
+ BLENDFUNCTION blendFunction ;
+ blendFunction.BlendOp = AC_SRC_OVER;
+ blendFunction.BlendFlags = 0;
+ blendFunction.SourceConstantAlpha = 255;
+ blendFunction.AlphaFormat = AC_SRC_ALPHA;
+ hdc = CreateCompatibleDC(NULL);
+ oldBitmap = SelectBitmap(hdc, img->hBitmap);
+ gr->AlphaBlend(gr->hMemDC, x0, y0, img->width, img->height, hdc, 0, 0, img->width, img->height, blendFunction);
+ (void)SelectBitmap(hdc, oldBitmap);
+ DeleteDC(hdc);
+ } else {
+ int x, y;
+ HDC hdc=gr->hMemDC;
+ png_byte *pix_ptr = img->png_pixels;
+ COLORREF *pixeldata;
+ HDC dc;
+ HBITMAP bitmap;
+ HBITMAP oldBitmap;
+
BITMAPINFO pnginfo;
- HDC dc1, dc2;
- png_byte *origPixels;
-
- origBmp=img->hBitmap;
- origPixels=img->png_pixels;
memset(&pnginfo, 0, sizeof(pnginfo));
pnginfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- pnginfo.bmiHeader.biWidth = width;
- pnginfo.bmiHeader.biHeight = -height;
+ pnginfo.bmiHeader.biWidth = img->width;
+ pnginfo.bmiHeader.biHeight = -img->height;
pnginfo.bmiHeader.biBitCount = 32;
pnginfo.bmiHeader.biCompression = BI_RGB;
pnginfo.bmiHeader.biPlanes = 1;
- dc1 = CreateCompatibleDC(NULL);
- dc2 = CreateCompatibleDC(NULL);
- img->hBitmap = CreateDIBSection(dc1, &pnginfo, DIB_RGB_COLORS , (void **)&(img->png_pixels), NULL, 0);
-
- if(gr->SetStretchBltMode) {
- gr->SetStretchBltMode(dc1,STRETCH_HALFTONE);
- SetBrushOrgEx(dc1,0,0,NULL);
- }
-
- SelectBitmap(dc1,img->hBitmap);
- SelectBitmap(dc2,origBmp);
-
- StretchBlt(dc1,0,0,width, height, dc2, 0,0, img->width, img->height,SRCCOPY);
- img->width=width;
- img->height=height;
- img->hot.x=width/2-1;
- img->hot.y=height/2-1;
-
- DeleteDC(dc1);
- DeleteDC(dc2);
- DeleteObject(origBmp);
-}
-
+ dc = CreateCompatibleDC(NULL);
+ bitmap = CreateDIBSection(hdc, &pnginfo, DIB_RGB_COLORS, (void **)&pixeldata, NULL, 0);
+ oldBitmap = SelectBitmap(dc, bitmap);
+ BitBlt(dc, 0, 0, img->width, img->height, hdc, x0, y0, SRCCOPY);
+ for (y=0 ; y < img->width ; y++) {
+ for (x=0 ; x < img->height ; x++) {
+ int b = pix_ptr[0];
+ int g = pix_ptr[1];
+ int r = pix_ptr[2];
+ int a = pix_ptr[3];
+ if (a != 0xff) {
+ int p = *pixeldata;
+ int ai = 0xff - a;
+ r = (r * a + ((p >> 16) & 0xff) * ai) / 255;
+ g = (g * a + ((p >> 8) & 0xff) * ai) / 255;
+ b = (b * a + ((p >> 0) & 0xff) * ai) / 255;
+ }
+ *pixeldata++ = (r << 16) | (g << 8) | b;
+ pix_ptr+=img->channels;
+ }
+ }
-static void
-pngrender(struct graphics_image_priv *img, struct graphics_priv *gr, int x0, int y0)
-{
- if (gr->AlphaBlend && img->hBitmap)
- {
- HDC hdc;
- HBITMAP oldBitmap;
- BLENDFUNCTION blendFunction ;
- blendFunction.BlendOp = AC_SRC_OVER;
- blendFunction.BlendFlags = 0;
- blendFunction.SourceConstantAlpha = 255;
- blendFunction.AlphaFormat = AC_SRC_ALPHA;
- hdc = CreateCompatibleDC(NULL);
- oldBitmap = SelectBitmap(hdc, img->hBitmap);
- gr->AlphaBlend(gr->hMemDC, x0, y0, img->width, img->height, hdc, 0, 0, img->width, img->height, blendFunction);
- (void)SelectBitmap(hdc, oldBitmap);
- DeleteDC(hdc);
- }
- else
- {
- int x, y;
- HDC hdc=gr->hMemDC;
- png_byte *pix_ptr = img->png_pixels;
- COLORREF *pixeldata;
- HDC dc;
- HBITMAP bitmap;
- HBITMAP oldBitmap;
-
- BITMAPINFO pnginfo;
-
- memset(&pnginfo, 0, sizeof(pnginfo));
- pnginfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- pnginfo.bmiHeader.biWidth = img->width;
- pnginfo.bmiHeader.biHeight = -img->height;
- pnginfo.bmiHeader.biBitCount = 32;
- pnginfo.bmiHeader.biCompression = BI_RGB;
- pnginfo.bmiHeader.biPlanes = 1;
- dc = CreateCompatibleDC(NULL);
- bitmap = CreateDIBSection(hdc, &pnginfo, DIB_RGB_COLORS, (void **)&pixeldata, NULL, 0);
- oldBitmap = SelectBitmap(dc, bitmap);
- BitBlt(dc, 0, 0, img->width, img->height, hdc, x0, y0, SRCCOPY);
- for (y=0 ; y < img->width ; y++)
- {
- for (x=0 ; x < img->height ; x++)
- {
- int b = pix_ptr[0];
- int g = pix_ptr[1];
- int r = pix_ptr[2];
- int a = pix_ptr[3];
- if (a != 0xff)
- {
- int p = *pixeldata;
- int ai = 0xff - a;
- r = (r * a + ((p >> 16) & 0xff) * ai) / 255;
- g = (g * a + ((p >> 8) & 0xff) * ai) / 255;
- b = (b * a + ((p >> 0) & 0xff) * ai) / 255;
- }
- *pixeldata++ = (r << 16) | (g << 8) | b;
- pix_ptr+=img->channels;
- }
- }
-
- BitBlt(hdc, x0, y0, img->width, img->height, dc, 0, 0, SRCCOPY);
- (void)SelectBitmap(dc, oldBitmap);
- DeleteBitmap(bitmap);
- DeleteDC(dc);
- }
+ BitBlt(hdc, x0, y0, img->width, img->height, dc, 0, 0, SRCCOPY);
+ (void)SelectBitmap(dc, oldBitmap);
+ DeleteBitmap(bitmap);
+ DeleteDC(dc);
+ }
}
static int
-xpmdecode(char *name, struct graphics_image_priv *img)
-{
+xpmdecode(char *name, struct graphics_image_priv *img) {
img->pxpm = Xpm2bmp_new();
- if (Xpm2bmp_load( img->pxpm, name ) != 0)
- {
+ if (Xpm2bmp_load( img->pxpm, name ) != 0) {
g_free(img->pxpm);
return FALSE;
}
@@ -1412,19 +1311,17 @@ xpmdecode(char *name, struct graphics_image_priv *img)
-static struct graphics_image_priv *image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name, int *w, int *h, struct point *hot, int rotation)
-{
+static struct graphics_image_priv *image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name,
+ int *w, int *h, struct point *hot, int rotation) {
struct graphics_image_priv* ret;
-
+
char* hash_key = g_strdup_printf("%s_%d_%d_%d",name,*w,*h,rotation);
-
- if ( !g_hash_table_lookup_extended( gr->image_cache_hash, hash_key, NULL, (gpointer)&ret) )
- {
+
+ if ( !g_hash_table_lookup_extended( gr->image_cache_hash, hash_key, NULL, (gpointer)&ret) ) {
int len=strlen(name);
int rc=0;
- if (len >= 4)
- {
+ if (len >= 4) {
char *ext;
dbg(lvl_info, "loading image '%s'", name );
ret = g_new0( struct graphics_image_priv, 1 );
@@ -1453,11 +1350,11 @@ static struct graphics_image_priv *image_new(struct graphics_priv *gr, struct gr
if(ret->png_pixels && ret->hBitmap)
pngscale(ret, gr, *w, *h);
}
- }
+ }
}
if (ret) {
- *w=ret->width;
- *h=ret->height;
+ *w=ret->width;
+ *h=ret->height;
if (hot)
*hot=ret->hot;
}
@@ -1466,23 +1363,21 @@ static struct graphics_image_priv *image_new(struct graphics_priv *gr, struct gr
}
-static void draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img)
-{
+static void draw_image(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p,
+ struct graphics_image_priv *img) {
if (img->pxpm)
- Xpm2bmp_paint( img->pxpm , gr->hMemDC, p->x, p->y );
+ Xpm2bmp_paint( img->pxpm, gr->hMemDC, p->x, p->y );
if (img->png_pixels)
pngrender(img, gr, p->x, p->y);
}
static struct graphics_priv *
- graphics_win32_new_helper(struct graphics_methods *meth);
+graphics_win32_new_helper(struct graphics_methods *meth);
-static void overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h, int wraparound)
-{
+static void overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h, int wraparound) {
dbg(lvl_debug, "resize overlay: %x, x: %d, y: %d, w: %d, h: %d, wraparound: %d", gr, p->x, p->y, w, h, wraparound);
- if ( gr->width != w || gr->height != h )
- {
+ if ( gr->width != w || gr->height != h ) {
gr->width = w;
gr->height = h;
create_memory_dc(gr);
@@ -1494,8 +1389,7 @@ static void overlay_resize(struct graphics_priv *gr, struct point *p, int w, int
static struct graphics_priv *
- overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound)
-{
+overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound) {
struct graphics_priv *this=graphics_win32_new_helper(meth);
dbg(lvl_debug, "overlay: %x, x: %d, y: %d, w: %d, h: %d, wraparound: %d", this, p->x, p->y, w, h, wraparound);
this->width = w;
@@ -1507,20 +1401,17 @@ static struct graphics_priv *
this->hPrebuildDC = 0;
this->AlphaBlend = gr->AlphaBlend;
this->image_cache_hash = gr->image_cache_hash;
-
+
this->next = gr->overlays;
gr->overlays = this;
this->wnd_handle = gr->wnd_handle;
- if (wraparound)
- {
- if ( p->x < 0 )
- {
+ if (wraparound) {
+ if ( p->x < 0 ) {
this->p.x += gr->width;
}
- if ( p->y < 0 )
- {
+ if ( p->y < 0 ) {
this->p.y += gr->height;
}
}
@@ -1529,14 +1420,13 @@ static struct graphics_priv *
return this;
}
-static void overlay_disable(struct graphics_priv *gr, int disable)
-{
+static void overlay_disable(struct graphics_priv *gr, int disable) {
dbg(lvl_debug, "overlay: %x, disable: %d", gr, disable);
gr->disabled = disable;
}
-static void get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy, struct point *ret, int estimate)
-{
+static void get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy,
+ struct point *ret, int estimate) {
int len = g_utf8_strlen(text, -1);
int xMin = 0;
int yMin = 0;
@@ -1556,8 +1446,7 @@ static void get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *f
}
-static struct graphics_methods graphics_methods =
-{
+static struct graphics_methods graphics_methods = {
graphics_destroy,
draw_mode,
draw_lines,
@@ -1582,22 +1471,20 @@ static struct graphics_methods graphics_methods =
get_text_bbox,
overlay_disable,
overlay_resize,
- NULL, /* show_native_keyboard */
- NULL, /* hide_native_keyboard */
+ NULL, /* show_native_keyboard */
+ NULL, /* hide_native_keyboard */
};
static struct graphics_priv *
- graphics_win32_new_helper(struct graphics_methods *meth)
-{
+graphics_win32_new_helper(struct graphics_methods *meth) {
struct graphics_priv *this_=g_new0(struct graphics_priv,1);
*meth=graphics_methods;
this_->mode = -1;
return this_;
}
-static void bind_late(struct graphics_priv* gra_priv)
-{
+static void bind_late(struct graphics_priv* gra_priv) {
#if HAVE_API_WIN32_CE
gra_priv->hCoreDll = LoadLibrary(TEXT("coredll.dll"));
#else
@@ -1605,11 +1492,9 @@ static void bind_late(struct graphics_priv* gra_priv)
gra_priv->hGdi32Dll = LoadLibrary(TEXT("gdi32.dll"));
gra_priv->hUser32Dll = GetModuleHandle("user32.dll");
#endif
- if ( gra_priv->hCoreDll )
- {
+ if ( gra_priv->hCoreDll ) {
gra_priv->AlphaBlend = (FP_AlphaBlend)GetProcAddress(gra_priv->hCoreDll, TEXT("AlphaBlend") );
- if (!gra_priv->AlphaBlend)
- {
+ if (!gra_priv->AlphaBlend) {
dbg(lvl_warning, "AlphaBlend not supported");
}
#if HAVE_API_WIN32_CE
@@ -1617,27 +1502,23 @@ static void bind_late(struct graphics_priv* gra_priv)
#else
gra_priv->SetStretchBltMode= (FP_SetStretchBltMode)GetProcAddress(gra_priv->hGdi32Dll, TEXT("SetStretchBltMode") );
#endif
- if (!gra_priv->SetStretchBltMode)
- {
+ if (!gra_priv->SetStretchBltMode) {
dbg(lvl_warning, "SetStretchBltMode not supported");
}
- }
- else
- {
+ } else {
dbg(lvl_error, "Error loading coredll");
}
-
+
if(gra_priv->hUser32Dll) {
- gra_priv->ChangeWindowMessageFilterEx=GetProcAddress(gra_priv->hUser32Dll,"ChangeWindowMessageFilterEx");
- gra_priv->ChangeWindowMessageFilter=GetProcAddress(gra_priv->hUser32Dll,"ChangeWindowMessageFilter");
+ gra_priv->ChangeWindowMessageFilterEx=GetProcAddress(gra_priv->hUser32Dll,"ChangeWindowMessageFilterEx");
+ gra_priv->ChangeWindowMessageFilter=GetProcAddress(gra_priv->hUser32Dll,"ChangeWindowMessageFilter");
}
}
static struct graphics_priv*
- graphics_win32_new( struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl)
-{
+graphics_win32_new( struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl) {
struct attr *attr;
struct graphics_priv* this_;
@@ -1674,21 +1555,18 @@ static struct graphics_priv*
static void
-event_win32_main_loop_run(void)
-{
+event_win32_main_loop_run(void) {
MSG msg;
dbg(lvl_debug,"enter");
- while (GetMessage(&msg, 0, 0, 0))
- {
+ while (GetMessage(&msg, 0, 0, 0)) {
TranslateMessage(&msg); /* Keyboard input. */
DispatchMessage(&msg);
}
}
-static void event_win32_main_loop_quit(void)
-{
+static void event_win32_main_loop_quit(void) {
#ifdef HAVE_API_WIN32_CE
HWND hwndTaskbar;
HWND hwndSip;
@@ -1708,41 +1586,34 @@ static void event_win32_main_loop_quit(void)
}
static struct event_watch *
- event_win32_add_watch(int h, enum event_watch_cond cond, struct callback *cb)
-{
+event_win32_add_watch(int h, enum event_watch_cond cond, struct callback *cb) {
dbg(lvl_debug,"enter");
return NULL;
}
static void
-event_win32_remove_watch(struct event_watch *ev)
-{
+event_win32_remove_watch(struct event_watch *ev) {
dbg(lvl_debug,"enter");
}
static GList *timers;
-struct event_timeout
-{
+struct event_timeout {
UINT_PTR timer_id;
int multi;
struct callback *cb;
struct event_timeout *next;
};
-static void run_timer(UINT_PTR idEvent)
-{
+static void run_timer(UINT_PTR idEvent) {
GList *l;
struct event_timeout *t;
l = timers;
- while (l)
- {
+ while (l) {
t = l->data;
- if (t->timer_id == idEvent)
- {
+ if (t->timer_id == idEvent) {
struct callback *cb = t->cb;
dbg(lvl_info, "Timer %d (multi: %d)", t->timer_id, t->multi);
- if (!t->multi)
- {
+ if (!t->multi) {
KillTimer(NULL, t->timer_id);
timers = g_list_remove(timers, t);
g_free(t);
@@ -1757,14 +1628,12 @@ static void run_timer(UINT_PTR idEvent)
static VOID CALLBACK win32_timer_cb(HWND hwnd, UINT uMsg,
UINT_PTR idEvent,
- DWORD dwTime)
-{
+ DWORD dwTime) {
run_timer(idEvent);
}
static struct event_timeout *
- event_win32_add_timeout(int timeout, int multi, struct callback *cb)
-{
+event_win32_add_timeout(int timeout, int multi, struct callback *cb) {
struct event_timeout *t;
t = g_new0(struct event_timeout, 1);
if (!t)
@@ -1778,20 +1647,16 @@ static struct event_timeout *
}
static void
-event_win32_remove_timeout(struct event_timeout *to)
-{
- if (to)
- {
+event_win32_remove_timeout(struct event_timeout *to) {
+ if (to) {
GList *l;
struct event_timeout *t=NULL;
dbg(lvl_debug, "Try stopping timer %d", to->timer_id);
l = timers;
- while (l)
- {
+ while (l) {
t = l->data;
/* Use the pointer not the ID, IDs are reused */
- if (t == to)
- {
+ if (t == to) {
KillTimer(NULL, t->timer_id);
timers = g_list_remove(timers, t);
g_free(t);
@@ -1805,25 +1670,21 @@ event_win32_remove_timeout(struct event_timeout *to)
}
static struct event_idle *
- event_win32_add_idle(int priority, struct callback *cb)
-{
- return (struct event_idle *)event_win32_add_timeout(1, 1, cb);
+event_win32_add_idle(int priority, struct callback *cb) {
+ return (struct event_idle *)event_win32_add_timeout(1, 1, cb);
}
static void
-event_win32_remove_idle(struct event_idle *ev)
-{
+event_win32_remove_idle(struct event_idle *ev) {
event_win32_remove_timeout((struct event_timeout *)ev);
}
static void
-event_win32_call_callback(struct callback_list *cb)
-{
- PostMessage(g_hwnd, WM_USER+2, (WPARAM)cb , (LPARAM)0);
+event_win32_call_callback(struct callback_list *cb) {
+ PostMessage(g_hwnd, WM_USER+2, (WPARAM)cb, (LPARAM)0);
}
-static struct event_methods event_win32_methods =
-{
+static struct event_methods event_win32_methods = {
event_win32_main_loop_run,
event_win32_main_loop_quit,
event_win32_add_watch,
@@ -1836,15 +1697,13 @@ static struct event_methods event_win32_methods =
};
static struct event_priv *
- event_win32_new(struct event_methods *meth)
-{
+event_win32_new(struct event_methods *meth) {
*meth=event_win32_methods;
return NULL;
}
void
-plugin_init(void)
-{
+plugin_init(void) {
plugin_register_category_graphics("win32", graphics_win32_new);
plugin_register_category_event("win32", event_win32_new);
}
diff --git a/navit/graphics/win32/xpm2bmp.c b/navit/graphics/win32/xpm2bmp.c
index 455d69941..3885a5107 100644
--- a/navit/graphics/win32/xpm2bmp.c
+++ b/navit/graphics/win32/xpm2bmp.c
@@ -11,8 +11,7 @@
static int CreateBitmapFromXpm( const char* filename, PXPM2BMP pXpm2bmp );
// typedefs
-static XPMCOLORENTRY theRGBRecords[] =
-{
+static XPMCOLORENTRY theRGBRecords[] = {
{"ALICEBLUE", 240, 248, 255},
{"ANTIQUEWHITE", 250, 235, 215},
{"AQUAMARINE", 50, 191, 193},
@@ -250,348 +249,321 @@ static XPMCOLORENTRY theRGBRecords[] =
};
-PXPM2BMP Xpm2bmp_new(void)
-{
- PXPM2BMP preturn = g_malloc0( sizeof(XPM2BMP) );
- return preturn;
+PXPM2BMP Xpm2bmp_new(void) {
+ PXPM2BMP preturn = g_malloc0( sizeof(XPM2BMP) );
+ return preturn;
}
-int Xpm2bmp_load( PXPM2BMP pXpm2bmp, const char* filename )
-{
- return CreateBitmapFromXpm( filename, pXpm2bmp );
+int Xpm2bmp_load( PXPM2BMP pXpm2bmp, const char* filename ) {
+ return CreateBitmapFromXpm( filename, pXpm2bmp );
}
-int Xpm2bmp_paint( PXPM2BMP pXpm2bmp, HDC hdc, int x1,int y1 )
-{
- StretchDIBits(hdc,
- x1, y1, pXpm2bmp->size_x, pXpm2bmp->size_y,
- 0, 0, pXpm2bmp->size_x, pXpm2bmp->size_y,
- pXpm2bmp->wimage_data_trans,
- (BITMAPINFO *)pXpm2bmp->bmih_trans,
- DIB_RGB_COLORS,
- SRCAND );
-
- StretchDIBits(hdc,
- x1, y1, pXpm2bmp->size_x, pXpm2bmp->size_y,
- 0, 0, pXpm2bmp->size_x, pXpm2bmp->size_y,
- pXpm2bmp->wimage_data,
- (BITMAPINFO *)pXpm2bmp->bmih,
- DIB_RGB_COLORS,
- SRCPAINT );
-
- return 0;
+int Xpm2bmp_paint( PXPM2BMP pXpm2bmp, HDC hdc, int x1,int y1 ) {
+ StretchDIBits(hdc,
+ x1, y1, pXpm2bmp->size_x, pXpm2bmp->size_y,
+ 0, 0, pXpm2bmp->size_x, pXpm2bmp->size_y,
+ pXpm2bmp->wimage_data_trans,
+ (BITMAPINFO *)pXpm2bmp->bmih_trans,
+ DIB_RGB_COLORS,
+ SRCAND );
+
+ StretchDIBits(hdc,
+ x1, y1, pXpm2bmp->size_x, pXpm2bmp->size_y,
+ 0, 0, pXpm2bmp->size_x, pXpm2bmp->size_y,
+ pXpm2bmp->wimage_data,
+ (BITMAPINFO *)pXpm2bmp->bmih,
+ DIB_RGB_COLORS,
+ SRCPAINT );
+
+ return 0;
}
-static int parse_line_values( const char* line, PXPM2BMP pXpm2bmp )
-{
- int return_value = 0;
- char* parse_line = (char*)line;
- char* tok;
- int value_pos = 0;
-
- parse_line = strchr( parse_line, '"' );
- parse_line++;
-
- tok = strtok( parse_line, " \t\n" );
-
- while ( tok != 0 )
- {
- int val = atoi( tok );
- switch ( value_pos )
- {
- case 0: pXpm2bmp->size_x = val; break;
- case 1: pXpm2bmp->size_y = val; break;
- case 2: pXpm2bmp->colors = val; break;
- case 3: pXpm2bmp->chars_per_pixel = val; break;
- case 4: pXpm2bmp->hotspot_x = val; break;
- case 5: pXpm2bmp->hotspot_y = val; break;
- }
- tok = strtok( NULL, " \t" );
- value_pos ++;
-
- }
-
- return return_value;
+static int parse_line_values( const char* line, PXPM2BMP pXpm2bmp ) {
+ int return_value = 0;
+ char* parse_line = (char*)line;
+ char* tok;
+ int value_pos = 0;
+
+ parse_line = strchr( parse_line, '"' );
+ parse_line++;
+
+ tok = strtok( parse_line, " \t\n" );
+
+ while ( tok != 0 ) {
+ int val = atoi( tok );
+ switch ( value_pos ) {
+ case 0:
+ pXpm2bmp->size_x = val;
+ break;
+ case 1:
+ pXpm2bmp->size_y = val;
+ break;
+ case 2:
+ pXpm2bmp->colors = val;
+ break;
+ case 3:
+ pXpm2bmp->chars_per_pixel = val;
+ break;
+ case 4:
+ pXpm2bmp->hotspot_x = val;
+ break;
+ case 5:
+ pXpm2bmp->hotspot_y = val;
+ break;
+ }
+ tok = strtok( NULL, " \t" );
+ value_pos ++;
+
+ }
+
+ return return_value;
}
-static int hex2int( char c )
-{
- if ((c >= '0') && (c <='9' )) return c - '0';
- if ((c >= 'A') && (c <= 'F')) return c - 'A' + 10;
- if ((c >= 'a') && (c <= 'f')) return c - 'a' + 10;
- return -1;
+static int hex2int( char c ) {
+ if ((c >= '0') && (c <='9' )) return c - '0';
+ if ((c >= 'A') && (c <= 'F')) return c - 'A' + 10;
+ if ((c >= 'a') && (c <= 'f')) return c - 'a' + 10;
+ return -1;
}
-static DWORD string2hex16( const char* str )
-{
- int i1 = hex2int( str[0] );
- int i2 = hex2int( str[1] );
- if ( ( i1 >= 0 ) && ( i2 >= 0 ) )
- return i1*16+i2;
- return -1;
+static DWORD string2hex16( const char* str ) {
+ int i1 = hex2int( str[0] );
+ int i2 = hex2int( str[1] );
+ if ( ( i1 >= 0 ) && ( i2 >= 0 ) )
+ return i1*16+i2;
+ return -1;
}
-static int parse_color_values( const char* line, PXPM2BMP pXpm2bmp )
-{
- int return_value = 0;
- char* cq = strchr( line, '"' );
- char* cchar = strchr( cq+pXpm2bmp->chars_per_pixel+1, 'c' );
- char* chash = strchr( cq+pXpm2bmp->chars_per_pixel+1, '#' );
- char* qe = strchr( cq+pXpm2bmp->chars_per_pixel+1, '"' );
+static int parse_color_values( const char* line, PXPM2BMP pXpm2bmp ) {
+ int return_value = 0;
+ char* cq = strchr( line, '"' );
+ char* cchar = strchr( cq+pXpm2bmp->chars_per_pixel+1, 'c' );
+ char* chash = strchr( cq+pXpm2bmp->chars_per_pixel+1, '#' );
+ char* qe = strchr( cq+pXpm2bmp->chars_per_pixel+1, '"' );
- cq++;
+ cq++;
- if ( cq )
- {
- memcpy( pXpm2bmp->color_entires[ pXpm2bmp-> color_entires_size].color_str, cq, pXpm2bmp->chars_per_pixel + 1 );
- pXpm2bmp->color_entires[ pXpm2bmp-> color_entires_size].color_str[ pXpm2bmp->chars_per_pixel ] = '\0';
+ if ( cq ) {
+ memcpy( pXpm2bmp->color_entires[ pXpm2bmp-> color_entires_size].color_str, cq, pXpm2bmp->chars_per_pixel + 1 );
+ pXpm2bmp->color_entires[ pXpm2bmp-> color_entires_size].color_str[ pXpm2bmp->chars_per_pixel ] = '\0';
- if ( cchar && chash && qe)
- {
- int len;
- chash++;
- *qe = 0;
- len = strlen( chash );
+ if ( cchar && chash && qe) {
+ int len;
+ chash++;
+ *qe = 0;
+ len = strlen( chash );
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].r = string2hex16( &chash[0] );
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].g = string2hex16( &chash[len / 3] );
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].b = string2hex16( &chash[len * 2 / 3] );
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].r = string2hex16( &chash[0] );
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].g = string2hex16( &chash[len / 3] );
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].b = string2hex16( &chash[len * 2 / 3] );
#ifdef _DBG
-printf( "adding color %s => %d RGB %x %x %x to index %d\n",
- line,
- pXpm2bmp->color_entires_size,
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].r,
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].g,
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].b,
- pXpm2bmp->color_entires_size );
+ printf( "adding color %s => %d RGB %x %x %x to index %d\n",
+ line,
+ pXpm2bmp->color_entires_size,
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].r,
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].g,
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].b,
+ pXpm2bmp->color_entires_size );
#endif
- }
- else
- {
- int q;
- char *start = cchar + 1;
- char *end = start;
-
- while ( *start != 0 )
- {
- if ( ( *start != '\t' ) && ( *start != ' ' ) )
- {
- break;
- }
- start++;
- }
-
- end = start;
- while ( *end != 0 )
- {
- if ( ( *end == '\t' ) || ( *end == ' ' ) || ( *end == '"' ))
- {
- *end = 0;
- }
- end++;
- }
-
- start = _strupr( start );
-
- for ( q=0; q < sizeof( theRGBRecords ) / sizeof( theRGBRecords[0] ); q++ )
- {
-
- if ( 0 == strcmp( start, theRGBRecords[q].color_str ) )
- {
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].r = theRGBRecords[q].r;
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].g = theRGBRecords[q].g;
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].b = theRGBRecords[q].b;
- }
- }
- if ( 0 == strcmp( start, "NONE" ) )
- {
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].r = 255;
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].g = 0;
- pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].b = 255;
- }
- }
- }
- pXpm2bmp->color_entires_size++;
-
- return return_value;
+ } else {
+ int q;
+ char *start = cchar + 1;
+ char *end = start;
+
+ while ( *start != 0 ) {
+ if ( ( *start != '\t' ) && ( *start != ' ' ) ) {
+ break;
+ }
+ start++;
+ }
+
+ end = start;
+ while ( *end != 0 ) {
+ if ( ( *end == '\t' ) || ( *end == ' ' ) || ( *end == '"' )) {
+ *end = 0;
+ }
+ end++;
+ }
+
+ start = _strupr( start );
+
+ for ( q=0; q < sizeof( theRGBRecords ) / sizeof( theRGBRecords[0] ); q++ ) {
+
+ if ( 0 == strcmp( start, theRGBRecords[q].color_str ) ) {
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].r = theRGBRecords[q].r;
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].g = theRGBRecords[q].g;
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].b = theRGBRecords[q].b;
+ }
+ }
+ if ( 0 == strcmp( start, "NONE" ) ) {
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].r = 255;
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].g = 0;
+ pXpm2bmp->color_entires[ pXpm2bmp->color_entires_size].b = 255;
+ }
+ }
+ }
+ pXpm2bmp->color_entires_size++;
+
+ return return_value;
}
static int vv = 0;
-static int parse_pixel_line_values( const char* line, PXPM2BMP pXpm2bmp, unsigned char* pixel_data, unsigned char* pixel_data_trans )
-{
- int return_value = 0;
- int i,j;
-
-
- char* cq = strchr( line, '"' );
- int pix_idx = 0;
- int size_x = pXpm2bmp->size_x;
- int len = strlen( cq );
-
- cq++;
-
- if ( len > pXpm2bmp->chars_per_pixel * size_x )
- {
- for ( i=0; i< size_x; i++ )
- {
- int found = 0;
- char* cmp = &cq[ i * pXpm2bmp->chars_per_pixel];
-
- for ( j=0; j< pXpm2bmp-> color_entires_size; j++ )
- {
- if ( strncmp( cmp, pXpm2bmp->color_entires[ j ].color_str, pXpm2bmp->chars_per_pixel ) == 0 )
- {
- int r = pXpm2bmp->color_entires[ j ].r;
- int g = pXpm2bmp->color_entires[ j ].g;
- int b = pXpm2bmp->color_entires[ j ].b;
-
- if ( ( r == 255 ) && ( g == 0 ) && ( r == 255 ) )
- {
- r=g=b=0;
- pixel_data_trans[ pix_idx ] = 255;
- pixel_data_trans[ pix_idx+1 ] = 255;
- pixel_data_trans[ pix_idx+2 ] = 255;
- }
- else
- {
- pixel_data_trans[ pix_idx ] = 0;
- pixel_data_trans[ pix_idx+1 ] = 0;
- pixel_data_trans[ pix_idx+2 ] = 0;
- }
-
- // pixel_data[ pix_idx++ ] = pXpm2bmp->color_entires[ j ].r;
- // pixel_data[ pix_idx++ ] = pXpm2bmp->color_entires[ j ].g;
- // pixel_data[ pix_idx++ ] = pXpm2bmp->color_entires[ j ].b;
- pixel_data[ pix_idx++ ] = b;
- pixel_data[ pix_idx++ ] = g;
- pixel_data[ pix_idx++ ] = r;
- found = 1;
- vv++;
- break;
- }
- }
- if ( !found )
- {
- fprintf( stderr, "XPMLIB: error color not found\n" );
- }
-
- }
- }
- else
- {
- return_value = -1;
- fprintf( stderr, "XPMLIB: invalid line length\n" );
- }
- return return_value;
+static int parse_pixel_line_values( const char* line, PXPM2BMP pXpm2bmp, unsigned char* pixel_data,
+ unsigned char* pixel_data_trans ) {
+ int return_value = 0;
+ int i,j;
+
+
+ char* cq = strchr( line, '"' );
+ int pix_idx = 0;
+ int size_x = pXpm2bmp->size_x;
+ int len = strlen( cq );
+
+ cq++;
+
+ if ( len > pXpm2bmp->chars_per_pixel * size_x ) {
+ for ( i=0; i< size_x; i++ ) {
+ int found = 0;
+ char* cmp = &cq[ i * pXpm2bmp->chars_per_pixel];
+
+ for ( j=0; j< pXpm2bmp-> color_entires_size; j++ ) {
+ if ( strncmp( cmp, pXpm2bmp->color_entires[ j ].color_str, pXpm2bmp->chars_per_pixel ) == 0 ) {
+ int r = pXpm2bmp->color_entires[ j ].r;
+ int g = pXpm2bmp->color_entires[ j ].g;
+ int b = pXpm2bmp->color_entires[ j ].b;
+
+ if ( ( r == 255 ) && ( g == 0 ) && ( r == 255 ) ) {
+ r=g=b=0;
+ pixel_data_trans[ pix_idx ] = 255;
+ pixel_data_trans[ pix_idx+1 ] = 255;
+ pixel_data_trans[ pix_idx+2 ] = 255;
+ } else {
+ pixel_data_trans[ pix_idx ] = 0;
+ pixel_data_trans[ pix_idx+1 ] = 0;
+ pixel_data_trans[ pix_idx+2 ] = 0;
+ }
+
+ // pixel_data[ pix_idx++ ] = pXpm2bmp->color_entires[ j ].r;
+ // pixel_data[ pix_idx++ ] = pXpm2bmp->color_entires[ j ].g;
+ // pixel_data[ pix_idx++ ] = pXpm2bmp->color_entires[ j ].b;
+ pixel_data[ pix_idx++ ] = b;
+ pixel_data[ pix_idx++ ] = g;
+ pixel_data[ pix_idx++ ] = r;
+ found = 1;
+ vv++;
+ break;
+ }
+ }
+ if ( !found ) {
+ fprintf( stderr, "XPMLIB: error color not found\n" );
+ }
+
+ }
+ } else {
+ return_value = -1;
+ fprintf( stderr, "XPMLIB: invalid line length\n" );
+ }
+ return return_value;
}
-static int CreateBitmapFromXpm( const char* filename, PXPM2BMP pXpm2bmp )
-{
- int return_val = 0;
+static int CreateBitmapFromXpm( const char* filename, PXPM2BMP pXpm2bmp ) {
+ int return_val = 0;
unsigned char i, row;
- char line[ 1024 ];
- int nbytes ;
- int padding, rowsize = 0;
- FILE* file_xpm = fopen( filename, "r" );
-
- int phase = 0;
- row = 0;
-
- if ( file_xpm )
- {
- while ( fgets(line, sizeof( line ), file_xpm ) )
- {
+ char line[ 1024 ];
+ int nbytes ;
+ int padding, rowsize = 0;
+ FILE* file_xpm = fopen( filename, "r" );
+
+ int phase = 0;
+ row = 0;
+
+ if ( file_xpm ) {
+ while ( fgets(line, sizeof( line ), file_xpm ) ) {
#ifdef _DBG
- printf( "PARSING: %s\n", line );
+ printf( "PARSING: %s\n", line );
#endif
- if ( line[ 0 ] != '"' )
- continue;
+ if ( line[ 0 ] != '"' )
+ continue;
- switch ( phase )
- {
- case 0:
- parse_line_values( line, pXpm2bmp );
+ switch ( phase ) {
+ case 0:
+ parse_line_values( line, pXpm2bmp );
#ifdef _DBG
- printf( "size_x %d\n", pXpm2bmp->size_x );
- printf( "size_y %d\n", pXpm2bmp->size_y );
+ printf( "size_x %d\n", pXpm2bmp->size_x );
+ printf( "size_y %d\n", pXpm2bmp->size_y );
#endif
- phase = 1;
-
- pXpm2bmp->color_entires_size = 0;
- nbytes = ( pXpm2bmp->chars_per_pixel + 1 ) * pXpm2bmp->colors;
-
- pXpm2bmp->color_entires = g_malloc0( sizeof(XPMCOLORENTRY) * (pXpm2bmp->colors + 100) );
- pXpm2bmp->color_entires[0].color_str = g_malloc0( nbytes * pXpm2bmp->colors );
- for ( i = 1; i< pXpm2bmp->colors; i++ )
- {
- pXpm2bmp->color_entires[i].color_str = pXpm2bmp->color_entires[0].color_str + ( pXpm2bmp->chars_per_pixel + 1 ) * i;
- }
-
- rowsize=pXpm2bmp->size_x * 3;
- padding=4-(rowsize%4);
- if(padding<4)
- rowsize+=padding;
-
-
- if (!(pXpm2bmp->dib = (unsigned char *)g_malloc(sizeof(BITMAPINFOHEADER) + rowsize * pXpm2bmp->size_y )))
- {
- return 4;
- }
- if (!(pXpm2bmp->dib_trans = (unsigned char *)g_malloc0(sizeof(BITMAPINFOHEADER) + rowsize * pXpm2bmp->size_y )))
- {
- return 4;
- }
-
- memset(pXpm2bmp->dib, 0, sizeof(BITMAPINFOHEADER));
- pXpm2bmp->bmih = (BITMAPINFOHEADER *)pXpm2bmp->dib;
- pXpm2bmp->bmih->biSize = sizeof(BITMAPINFOHEADER);
- pXpm2bmp->bmih->biWidth = pXpm2bmp->size_x;
- pXpm2bmp->bmih->biHeight = -((long)pXpm2bmp->size_y);
- pXpm2bmp->bmih->biPlanes = 1;
- pXpm2bmp->bmih->biBitCount = 24;
- pXpm2bmp->bmih->biCompression = 0;
- pXpm2bmp->wimage_data = pXpm2bmp->dib + sizeof(BITMAPINFOHEADER);
-
-
- pXpm2bmp->bmih_trans = (BITMAPINFOHEADER *)pXpm2bmp->dib_trans;
- pXpm2bmp->bmih_trans->biSize = sizeof(BITMAPINFOHEADER);
- pXpm2bmp->bmih_trans->biWidth = pXpm2bmp->size_x;
- pXpm2bmp->bmih_trans->biHeight = -((long)pXpm2bmp->size_y);
- pXpm2bmp->bmih_trans->biPlanes = 1;
- pXpm2bmp->bmih_trans->biBitCount = 24;
- pXpm2bmp->bmih_trans->biCompression = 0;
- pXpm2bmp->wimage_data_trans = pXpm2bmp->dib_trans + sizeof(BITMAPINFOHEADER);
+ phase = 1;
+
+ pXpm2bmp->color_entires_size = 0;
+ nbytes = ( pXpm2bmp->chars_per_pixel + 1 ) * pXpm2bmp->colors;
+
+ pXpm2bmp->color_entires = g_malloc0( sizeof(XPMCOLORENTRY) * (pXpm2bmp->colors + 100) );
+ pXpm2bmp->color_entires[0].color_str = g_malloc0( nbytes * pXpm2bmp->colors );
+ for ( i = 1; i< pXpm2bmp->colors; i++ ) {
+ pXpm2bmp->color_entires[i].color_str = pXpm2bmp->color_entires[0].color_str + ( pXpm2bmp->chars_per_pixel + 1 ) * i;
+ }
+
+ rowsize=pXpm2bmp->size_x * 3;
+ padding=4-(rowsize%4);
+ if(padding<4)
+ rowsize+=padding;
+
+
+ if (!(pXpm2bmp->dib = (unsigned char *)g_malloc(sizeof(BITMAPINFOHEADER) + rowsize * pXpm2bmp->size_y ))) {
+ return 4;
+ }
+ if (!(pXpm2bmp->dib_trans = (unsigned char *)g_malloc0(sizeof(BITMAPINFOHEADER) + rowsize * pXpm2bmp->size_y ))) {
+ return 4;
+ }
+
+ memset(pXpm2bmp->dib, 0, sizeof(BITMAPINFOHEADER));
+ pXpm2bmp->bmih = (BITMAPINFOHEADER *)pXpm2bmp->dib;
+ pXpm2bmp->bmih->biSize = sizeof(BITMAPINFOHEADER);
+ pXpm2bmp->bmih->biWidth = pXpm2bmp->size_x;
+ pXpm2bmp->bmih->biHeight = -((long)pXpm2bmp->size_y);
+ pXpm2bmp->bmih->biPlanes = 1;
+ pXpm2bmp->bmih->biBitCount = 24;
+ pXpm2bmp->bmih->biCompression = 0;
+ pXpm2bmp->wimage_data = pXpm2bmp->dib + sizeof(BITMAPINFOHEADER);
+
+
+ pXpm2bmp->bmih_trans = (BITMAPINFOHEADER *)pXpm2bmp->dib_trans;
+ pXpm2bmp->bmih_trans->biSize = sizeof(BITMAPINFOHEADER);
+ pXpm2bmp->bmih_trans->biWidth = pXpm2bmp->size_x;
+ pXpm2bmp->bmih_trans->biHeight = -((long)pXpm2bmp->size_y);
+ pXpm2bmp->bmih_trans->biPlanes = 1;
+ pXpm2bmp->bmih_trans->biBitCount = 24;
+ pXpm2bmp->bmih_trans->biCompression = 0;
+ pXpm2bmp->wimage_data_trans = pXpm2bmp->dib_trans + sizeof(BITMAPINFOHEADER);
// memset( pXpm2bmp->wimage_data_trans, 255, 5* 22 * 3 );
- break;
- case 1:
- parse_color_values( line, pXpm2bmp );
- if ( pXpm2bmp->color_entires_size >= pXpm2bmp->colors )
- {
- phase = 2;
- }
-
- break;
- case 2:
- parse_pixel_line_values( line, pXpm2bmp,
- pXpm2bmp->wimage_data + row * rowsize,
- pXpm2bmp->wimage_data_trans + row * rowsize );
-
- row++;
- if ( row >= pXpm2bmp->size_y )
- {
- phase = 3;
- }
- break;
- }
-
- }
-
- fclose( file_xpm );
- }
- return return_val;
+ break;
+ case 1:
+ parse_color_values( line, pXpm2bmp );
+ if ( pXpm2bmp->color_entires_size >= pXpm2bmp->colors ) {
+ phase = 2;
+ }
+
+ break;
+ case 2:
+ parse_pixel_line_values( line, pXpm2bmp,
+ pXpm2bmp->wimage_data + row * rowsize,
+ pXpm2bmp->wimage_data_trans + row * rowsize );
+
+ row++;
+ if ( row >= pXpm2bmp->size_y ) {
+ phase = 3;
+ }
+ break;
+ }
+
+ }
+
+ fclose( file_xpm );
+ }
+ return return_val;
}