--- trunk/src/map-tool.c 2009/08/04 19:27:39 45 +++ trunk/src/map-tool.c 2009/08/05 14:11:00 46 @@ -242,6 +242,69 @@ shutdown_loop(context); } +/* draw shape */ +#define ARROW_BORDER 20 +#define CORNER_RADIUS 10 + +static void popup_window_shape(GtkWidget *window, int tip_x, int tip_y) { + GdkBitmap *mask = gdk_pixmap_new(NULL, POPUP_WIDTH, POPUP_HEIGHT, 1); + + GdkGC *gc = gdk_gc_new(mask); + GdkColormap *colormap; + GdkColor black; + GdkColor white; + + /* get black/white color values */ + colormap = gdk_colormap_get_system(); + gdk_color_black(colormap, &black); + gdk_color_white(colormap, &white); + + /* erase */ + gdk_gc_set_foreground(gc, &black); + gdk_gc_set_background(gc, &white); + + /* erase background */ + gdk_draw_rectangle(mask, gc, TRUE, 0, 0, POPUP_WIDTH, POPUP_HEIGHT); + + gdk_gc_set_foreground(gc, &white); + gdk_gc_set_background(gc, &black); + + gdk_draw_rectangle(mask, gc, TRUE, + 0, ARROW_BORDER + CORNER_RADIUS, + POPUP_WIDTH, + POPUP_HEIGHT - 2*CORNER_RADIUS - 2*ARROW_BORDER); + + gdk_draw_rectangle(mask, gc, TRUE, + CORNER_RADIUS, ARROW_BORDER, + POPUP_WIDTH - 2*CORNER_RADIUS, + POPUP_HEIGHT - 2*ARROW_BORDER); + + int off[][2] = { + { CORNER_RADIUS, ARROW_BORDER + CORNER_RADIUS }, + { POPUP_WIDTH - CORNER_RADIUS, + ARROW_BORDER + CORNER_RADIUS }, + { POPUP_WIDTH - CORNER_RADIUS, + POPUP_HEIGHT - CORNER_RADIUS - ARROW_BORDER }, + { CORNER_RADIUS, + POPUP_HEIGHT - CORNER_RADIUS - ARROW_BORDER}}; + + int i; + for(i=0;i<4;i++) { + gdk_draw_arc(mask, gc, TRUE, + off[i][0]-CORNER_RADIUS, off[i][1]-CORNER_RADIUS, + 2*CORNER_RADIUS, 2*CORNER_RADIUS, + 0, 360*64); + } + + GdkPoint points[3] = { {POPUP_WIDTH*1/3, POPUP_HEIGHT/2}, + {POPUP_WIDTH*2/3, POPUP_HEIGHT/2}, + {tip_x,tip_y} }; + gdk_draw_polygon(mask, gc, TRUE, points, 3); + + + gdk_window_shape_combine_mask(window->window, mask, 0, 0); +} + void cache_popup(map_context_t *mcontext, cache_t *cache) { popup_context_t pcontext; pcontext.appdata = mcontext->appdata; @@ -299,17 +362,29 @@ if(sy > mcontext->widget->allocation.height/2) ay = POPUP_HEIGHT; +#if !defined(USE_HILDON) || (MAEMO_VERSION_MAJOR < 5) + GdkColor color; + gdk_color_parse("darkgray", &color); + gtk_widget_modify_bg(GTK_WIDGET(pcontext.window), GTK_STATE_NORMAL, &color); +#endif + gtk_window_move(GTK_WINDOW(pcontext.window), x + mcontext->widget->allocation.x + sx - ax, y + mcontext->widget->allocation.y + sy - ay); - /* a frame with a vscale inside */ + GtkWidget *frame = gtk_frame_new(NULL); - gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT); + gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE); + gtk_container_set_border_width(GTK_CONTAINER(frame), + ARROW_BORDER+CORNER_RADIUS); + gtk_container_add(GTK_CONTAINER(frame), + gtk_button_new_with_label(cache->name)); - gtk_container_add(GTK_CONTAINER(frame), gtk_label_new(cache->name)); gtk_container_add(GTK_CONTAINER(pcontext.window), frame); + /* --------- give the window its shape ----------- */ + popup_window_shape(pcontext.window, ax, ay); + gtk_widget_show_all(pcontext.window); /* handle this popup until it's gone */