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

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

revision 46 by harbaum, Wed Aug 5 14:11:00 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    
 /* draw shape */  
 #define ARROW_BORDER   20  
 #define CORNER_RADIUS  10  
   
248  static void popup_window_shape(GtkWidget *window, int tip_x, int tip_y) {  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);    GdkBitmap *mask = gdk_pixmap_new(NULL, POPUP_WIDTH, POPUP_HEIGHT, 1);
250    
# Line 269  static void popup_window_shape(GtkWidget Line 268  static void popup_window_shape(GtkWidget
268    gdk_gc_set_foreground(gc, &white);    gdk_gc_set_foreground(gc, &white);
269    gdk_gc_set_background(gc, &black);    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,    gdk_draw_rectangle(mask, gc, TRUE,
275                       0, ARROW_BORDER + CORNER_RADIUS,                       0, tip_offset + CORNER_RADIUS,
276                       POPUP_WIDTH,                       POPUP_WIDTH,
277                       POPUP_HEIGHT - 2*CORNER_RADIUS - 2*ARROW_BORDER);                       POPUP_HEIGHT - 2*CORNER_RADIUS - ARROW_BORDER);
278    
279    gdk_draw_rectangle(mask, gc, TRUE,    gdk_draw_rectangle(mask, gc, TRUE,
280                       CORNER_RADIUS, ARROW_BORDER,                       CORNER_RADIUS, tip_offset,
281                       POPUP_WIDTH  - 2*CORNER_RADIUS,                       POPUP_WIDTH  - 2*CORNER_RADIUS,
282                       POPUP_HEIGHT - 2*ARROW_BORDER);                       POPUP_HEIGHT - ARROW_BORDER);
283    
284    int off[][2] = {    int off[][2] = {
285            { CORNER_RADIUS, ARROW_BORDER + CORNER_RADIUS },            { CORNER_RADIUS,               tip_offset + CORNER_RADIUS },
286            { POPUP_WIDTH - CORNER_RADIUS,            { POPUP_WIDTH - CORNER_RADIUS, tip_offset + CORNER_RADIUS },
             ARROW_BORDER + CORNER_RADIUS },  
287            { POPUP_WIDTH - CORNER_RADIUS,            { POPUP_WIDTH - CORNER_RADIUS,
288              POPUP_HEIGHT - CORNER_RADIUS - ARROW_BORDER },              POPUP_HEIGHT - CORNER_RADIUS - ARROW_BORDER + tip_offset},
289            { CORNER_RADIUS,            { CORNER_RADIUS,
290              POPUP_HEIGHT - CORNER_RADIUS  - ARROW_BORDER}};              POPUP_HEIGHT - CORNER_RADIUS  - ARROW_BORDER + tip_offset}};
291    
292    int i;    int i;
293    for(i=0;i<4;i++) {    for(i=0;i<4;i++) {
# Line 305  static void popup_window_shape(GtkWidget Line 306  static void popup_window_shape(GtkWidget
306    gdk_window_shape_combine_mask(window->window, mask, 0, 0);    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 345  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 362  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_HILDON) || (MAEMO_VERSION_MAJOR < 5)  #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
391    GdkColor color;    GdkColor color;
392    gdk_color_parse("darkgray", &color);    gdk_color_parse("darkgray", &color);
393    gtk_widget_modify_bg(GTK_WIDGET(pcontext.window), GTK_STATE_NORMAL, &color);    gtk_widget_modify_bg(GTK_WIDGET(pcontext.window), GTK_STATE_NORMAL, &color);
# Line 373  void cache_popup(map_context_t *mcontext Line 398  void cache_popup(map_context_t *mcontext
398                    y + mcontext->widget->allocation.y + sy - ay);                    y + mcontext->widget->allocation.y + sy - ay);
399    
400    
401    GtkWidget *frame = gtk_frame_new(NULL);    GtkWidget *alignment = gtk_alignment_new(0.5, 0.5, 1.0, 1.0);
402    gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE);    gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
403    gtk_container_set_border_width(GTK_CONTAINER(frame),                              CORNER_RADIUS/2 + (ay?0:ARROW_BORDER),
404                                   ARROW_BORDER+CORNER_RADIUS);                              CORNER_RADIUS/2 + (ay?ARROW_BORDER:0),
405    gtk_container_add(GTK_CONTAINER(frame),                              CORNER_RADIUS, CORNER_RADIUS);
406                      gtk_button_new_with_label(cache->name));  
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), frame);    gtk_container_add(GTK_CONTAINER(pcontext.window), alignment);
457    
458    /* --------- give the window its shape ----------- */    /* give window its shape */
459    popup_window_shape(pcontext.window, ax, ay);    popup_window_shape(pcontext.window, ax, ay);
460    
461    gtk_widget_show_all(pcontext.window);    gtk_widget_show_all(pcontext.window);
# Line 459  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.46  
changed lines
  Added in v.47