Diff of /trunk/src/map-tool.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 45 by harbaum, Tue Aug 4 19:27:39 2009 UTC revision 47 by harbaum, Thu Aug 6 20:23:12 2009 UTC
# Line 169  typedef struct { Line 169  typedef struct {
169    GMainLoop *loop;    GMainLoop *loop;
170  } popup_context_t;  } popup_context_t;
171    
172    /* draw shape */
173    #define ARROW_BORDER   20
174    #define CORNER_RADIUS  10
175    
176  #ifndef USE_HILDON  #ifndef USE_MAEMO
177  #define POPUP_WIDTH  300  #define POPUP_WIDTH  300
178  #define POPUP_HEIGHT 100  #define POPUP_HEIGHT 100
179  #else  #else
180  #define POPUP_WIDTH  600  #define POPUP_WIDTH  350
181  #define POPUP_HEIGHT 200  #define POPUP_HEIGHT 120
182  #endif  #endif
183    
184  static gboolean  static gboolean
# Line 242  run_unmap_handler(GtkWindow *window, pop Line 245  run_unmap_handler(GtkWindow *window, pop
245    shutdown_loop(context);    shutdown_loop(context);
246  }  }
247    
248    static void popup_window_shape(GtkWidget *window, int tip_x, int tip_y) {
249      GdkBitmap *mask = gdk_pixmap_new(NULL, POPUP_WIDTH, POPUP_HEIGHT, 1);
250    
251      GdkGC *gc = gdk_gc_new(mask);
252      GdkColormap *colormap;
253      GdkColor black;
254      GdkColor white;
255    
256      /* get black/white color values */
257      colormap = gdk_colormap_get_system();
258      gdk_color_black(colormap, &black);
259      gdk_color_white(colormap, &white);
260    
261      /* erase */
262      gdk_gc_set_foreground(gc, &black);
263      gdk_gc_set_background(gc, &white);
264    
265      /* erase background */
266      gdk_draw_rectangle(mask, gc, TRUE, 0, 0, POPUP_WIDTH, POPUP_HEIGHT);
267    
268      gdk_gc_set_foreground(gc, &white);
269      gdk_gc_set_background(gc, &black);
270    
271      /* the tip is always above or below the "bubble" but never at its side */
272      guint tip_offset = (tip_y == 0)?ARROW_BORDER:0;
273    
274      gdk_draw_rectangle(mask, gc, TRUE,
275                         0, tip_offset + CORNER_RADIUS,
276                         POPUP_WIDTH,
277                         POPUP_HEIGHT - 2*CORNER_RADIUS - ARROW_BORDER);
278    
279      gdk_draw_rectangle(mask, gc, TRUE,
280                         CORNER_RADIUS, tip_offset,
281                         POPUP_WIDTH  - 2*CORNER_RADIUS,
282                         POPUP_HEIGHT - ARROW_BORDER);
283    
284      int off[][2] = {
285              { CORNER_RADIUS,               tip_offset + CORNER_RADIUS },
286              { POPUP_WIDTH - CORNER_RADIUS, tip_offset + CORNER_RADIUS },
287              { POPUP_WIDTH - CORNER_RADIUS,
288                POPUP_HEIGHT - CORNER_RADIUS - ARROW_BORDER + tip_offset},
289              { CORNER_RADIUS,
290                POPUP_HEIGHT - CORNER_RADIUS  - ARROW_BORDER + tip_offset}};
291    
292      int i;
293      for(i=0;i<4;i++) {
294        gdk_draw_arc(mask, gc, TRUE,
295                     off[i][0]-CORNER_RADIUS, off[i][1]-CORNER_RADIUS,
296                     2*CORNER_RADIUS,         2*CORNER_RADIUS,
297                     0, 360*64);
298      }
299    
300      GdkPoint points[3] = { {POPUP_WIDTH*1/3, POPUP_HEIGHT/2},
301                             {POPUP_WIDTH*2/3, POPUP_HEIGHT/2},
302                             {tip_x,tip_y} };
303      gdk_draw_polygon(mask, gc, TRUE, points, 3);
304    
305    
306      gdk_window_shape_combine_mask(window->window, mask, 0, 0);
307    }
308    
309    /* create a left aligned label (normal ones are centered) */
310    static GtkWidget *gtk_label_left_new(char *str) {
311      GtkWidget *label = gtk_label_new(str);
312      gtk_misc_set_alignment(GTK_MISC(label), 0.f, .5f);
313      return label;
314    }
315    
316    /* the small labels are actually only on maemo small */
317    #ifdef USE_MAEMO
318    #define MARKUP_SMALL "<span size='small'>%s</span>"
319    GtkWidget *gtk_label_small_left_new(char *str) {
320      GtkWidget *label = gtk_label_new("");
321      char *markup = g_markup_printf_escaped(MARKUP_SMALL, str);
322      gtk_label_set_markup(GTK_LABEL(label), markup);
323      g_free(markup);
324      gtk_misc_set_alignment(GTK_MISC(label), 0.f, .5f);
325      return label;
326    }
327    #define gtk_label_big_left_new(a) gtk_label_left_new(a)
328    #else
329    #define gtk_label_small_left_new(a) gtk_label_left_new(a)
330    #define MARKUP_BIG "<span size='x-large'>%s</span>"
331    GtkWidget *gtk_label_big_left_new(char *str) {
332      GtkWidget *label = gtk_label_new("");
333      char *markup = g_markup_printf_escaped(MARKUP_BIG, str);
334      gtk_label_set_markup(GTK_LABEL(label), markup);
335      g_free(markup);
336      gtk_misc_set_alignment(GTK_MISC(label), 0.f, .5f);
337      return label;
338    }
339    #endif
340    
341  void cache_popup(map_context_t *mcontext, cache_t *cache) {  void cache_popup(map_context_t *mcontext, cache_t *cache) {
342    popup_context_t pcontext;    popup_context_t pcontext;
343    pcontext.appdata = mcontext->appdata;    pcontext.appdata = mcontext->appdata;
# Line 282  void cache_popup(map_context_t *mcontext Line 378  void cache_popup(map_context_t *mcontext
378                                     cache->pos.lat, cache->pos.lon,                                     cache->pos.lat, cache->pos.lon,
379                                     &sx, &sy);                                     &sx, &sy);
380    
   printf("screen pos %d/%d\n", sx, sy);  
   
381    gdk_window_get_origin(mcontext->widget->window, &x, &y);    gdk_window_get_origin(mcontext->widget->window, &x, &y);
   printf("window = %d/%d +%d+%d %d*%d\n", x, y,  
          mcontext->widget->allocation.x,  
          mcontext->widget->allocation.y,  
          mcontext->widget->allocation.width,  
          mcontext->widget->allocation.height  
          );  
382    
383    gint ax = 0, ay = 0;    gint ax = 0, ay = 0;
384    if(sx > mcontext->widget->allocation.width/2)    if(sx > mcontext->widget->allocation.width/2)
# Line 299  void cache_popup(map_context_t *mcontext Line 387  void cache_popup(map_context_t *mcontext
387    if(sy > mcontext->widget->allocation.height/2)    if(sy > mcontext->widget->allocation.height/2)
388      ay = POPUP_HEIGHT;      ay = POPUP_HEIGHT;
389    
390    #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
391      GdkColor color;
392      gdk_color_parse("darkgray", &color);
393      gtk_widget_modify_bg(GTK_WIDGET(pcontext.window), GTK_STATE_NORMAL, &color);
394    #endif
395    
396    gtk_window_move(GTK_WINDOW(pcontext.window),    gtk_window_move(GTK_WINDOW(pcontext.window),
397                    x + mcontext->widget->allocation.x + sx - ax,                    x + mcontext->widget->allocation.x + sx - ax,
398                    y + mcontext->widget->allocation.y + sy - ay);                    y + mcontext->widget->allocation.y + sy - ay);
399    
   /* a frame with a vscale inside */  
   GtkWidget *frame = gtk_frame_new(NULL);  
   gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT);  
400    
401    gtk_container_add(GTK_CONTAINER(frame), gtk_label_new(cache->name));    GtkWidget *alignment = gtk_alignment_new(0.5, 0.5, 1.0, 1.0);
402    gtk_container_add(GTK_CONTAINER(pcontext.window), frame);    gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
403                                CORNER_RADIUS/2 + (ay?0:ARROW_BORDER),
404                                CORNER_RADIUS/2 + (ay?ARROW_BORDER:0),
405                                CORNER_RADIUS, CORNER_RADIUS);
406    
407      /* --- actual content ---- */
408      GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
409    
410      if(cache->id) {
411        GtkWidget *ihbox = gtk_hbox_new(FALSE, 0);
412    
413        gtk_box_pack_start(GTK_BOX(ihbox),
414           icon_get_widget(ICON_CACHE_TYPE, cache->type),
415           FALSE, FALSE, 5);
416    
417        gtk_box_pack_start_defaults(GTK_BOX(ihbox),
418                    gtk_label_big_left_new(cache->id));
419    
420        gtk_box_pack_start_defaults(GTK_BOX(vbox), ihbox);
421      }
422    
423      if(cache->name) {
424        GtkWidget *label = gtk_label_small_left_new(cache->name);
425        gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END);
426        gtk_box_pack_start_defaults(GTK_BOX(vbox), label);
427      }
428    
429      GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
430      if(cache->terrain) {
431        GtkWidget *ihbox = gtk_hbox_new(FALSE, 0);
432        gtk_box_pack_start(GTK_BOX(ihbox),
433           gtk_label_small_left_new(_("Terrain:")), FALSE, FALSE, 0);
434        gtk_box_pack_start(GTK_BOX(ihbox),
435           icon_get_widget(ICON_STARS, (int)(cache->terrain*2-2)),
436           FALSE, FALSE, 5);
437        gtk_box_pack_start_defaults(GTK_BOX(hbox), ihbox);
438      }
439    
440      if(cache->difficulty) {
441        GtkWidget *ihbox = gtk_hbox_new(FALSE, 0);
442        gtk_box_pack_start(GTK_BOX(ihbox),
443           gtk_label_small_left_new(_("Difficulty:")), FALSE, FALSE, 0);
444        gtk_box_pack_start(GTK_BOX(ihbox),
445           icon_get_widget(ICON_STARS, (int)(cache->difficulty*2-2)),
446           FALSE, FALSE, 5);
447        gtk_box_pack_start_defaults(GTK_BOX(hbox), ihbox);
448      }
449    
450      gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
451    
452      gtk_container_add(GTK_CONTAINER(alignment), vbox);
453      /* ----------------------- */
454    
455    
456      gtk_container_add(GTK_CONTAINER(pcontext.window), alignment);
457    
458      /* give window its shape */
459      popup_window_shape(pcontext.window, ax, ay);
460    
461    gtk_widget_show_all(pcontext.window);    gtk_widget_show_all(pcontext.window);
462    
463    /* handle this popup until it's gone */    /* handle this popup until it's gone */
# Line 384  static int dist2pixel(map_context_t *con Line 532  static int dist2pixel(map_context_t *con
532    return 1000.0*km/m_per_pix;    return 1000.0*km/m_per_pix;
533  }  }
534    
535  #define CLICK_FUZZ (16)  #define CLICK_FUZZ (24)
536    
537  static gboolean  static gboolean
538  on_map_button_press_event(GtkWidget *widget,  on_map_button_press_event(GtkWidget *widget,

Legend:
Removed from v.45  
changed lines
  Added in v.47