Diff of /trunk/src/osm-gps-map-osd-classic.c

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

revision 113 by harbaum, Wed Sep 16 13:45:10 2009 UTC revision 120 by harbaum, Sat Sep 19 19:19:42 2009 UTC
# Line 52  typedef struct { Line 52  typedef struct {
52          cairo_surface_t *surface;          cairo_surface_t *surface;
53          int orientation, offset_x, offset_y;          int orientation, offset_x, offset_y;
54    
55            gboolean just_created;
56          float lat, lon;          float lat, lon;
57          OsmGpsMapRect_t rect;          OsmGpsMapRect_t rect;
58    
# Line 272  osd_render_balloon(osm_gps_map_osd_t *os Line 273  osd_render_balloon(osm_gps_map_osd_t *os
273  /* return true if balloon is being displayed and if */  /* return true if balloon is being displayed and if */
274  /* the given coordinate is within this balloon */  /* the given coordinate is within this balloon */
275  static gboolean  static gboolean
276  osd_balloon_check(osm_gps_map_osd_t *osd, gint x, gint y)  osd_balloon_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y)
277  {  {
278      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
279    
# Line 284  osd_balloon_check(osm_gps_map_osd_t *osd Line 285  osd_balloon_check(osm_gps_map_osd_t *osd
285                                        priv->balloon.lat, priv->balloon.lon,                                        priv->balloon.lat, priv->balloon.lon,
286                                        &xs, &ys);                                        &xs, &ys);
287    
288        printf("click at %d/%d\n", x, y);
289    
290      xs += priv->balloon.rect.x + priv->balloon.offset_x;      xs += priv->balloon.rect.x + priv->balloon.offset_x;
291      ys += priv->balloon.rect.y + priv->balloon.offset_y;      ys += priv->balloon.rect.y + priv->balloon.offset_y;
292    
293      return (priv->balloon.surface &&      printf("balloon at %d/%d/%d/%d\n",
294              (x > xs) && (x < xs + priv->balloon.rect.w) &&             xs, ys,
295              (y > ys) && (y < ys + priv->balloon.rect.h));             xs + priv->balloon.rect.w,
296               ys + priv->balloon.rect.h);
297    
298        gboolean is_in =
299            (x > xs) && (x < xs + priv->balloon.rect.w) &&
300            (y > ys) && (y < ys + priv->balloon.rect.h);
301    
302        /* handle the fact that the balloon may have been created by the */
303        /* button down event */
304        if(!is_in && !down && !priv->balloon.just_created) {
305            /* the user actually clicked outside the balloon */
306    
307            /* close the balloon! */
308            osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(osd->widget));
309        }
310    
311        return is_in;
312  }  }
313    
314  void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) {  void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) {
# Line 301  void osm_gps_map_osd_clear_balloon (OsmG Line 320  void osm_gps_map_osd_clear_balloon (OsmG
320      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
321      g_return_if_fail (priv);      g_return_if_fail (priv);
322    
     printf("request to clear balloon\n");  
   
323      if(priv->balloon.surface) {      if(priv->balloon.surface) {
324          cairo_surface_destroy(priv->balloon.surface);          cairo_surface_destroy(priv->balloon.surface);
325          priv->balloon.surface = NULL;          priv->balloon.surface = NULL;
# Line 325  osm_gps_map_osd_draw_balloon (OsmGpsMap Line 342  osm_gps_map_osd_draw_balloon (OsmGpsMap
342    
343      osm_gps_map_osd_clear_balloon (map);      osm_gps_map_osd_clear_balloon (map);
344    
     printf("request to draw balloon at %f %f\n", latitude, longitude);  
   
345      /* allocate balloon surface */      /* allocate balloon surface */
346      priv->balloon.surface =      priv->balloon.surface =
347          cairo_image_surface_create(CAIRO_FORMAT_ARGB32,          cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
# Line 336  osm_gps_map_osd_draw_balloon (OsmGpsMap Line 351  osm_gps_map_osd_draw_balloon (OsmGpsMap
351      priv->balloon.lon = longitude;      priv->balloon.lon = longitude;
352      priv->balloon.cb = cb;      priv->balloon.cb = cb;
353      priv->balloon.data = data;      priv->balloon.data = data;
354        priv->balloon.just_created = TRUE;
355    
356      priv->balloon.orientation = -1;      priv->balloon.orientation = -1;
357    
# Line 856  osd_source_toggle(osm_gps_map_osd_t *osd Line 872  osd_source_toggle(osm_gps_map_osd_t *osd
872    
873  /* check if the user clicked inside the source selection area */  /* check if the user clicked inside the source selection area */
874  static osd_button_t  static osd_button_t
875  osd_source_check(osm_gps_map_osd_t *osd, gint x, gint y) {  osd_source_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) {
876      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
877    
878      if(!priv->source_sel.expanded)      if(!priv->source_sel.expanded)
# Line 874  osd_source_check(osm_gps_map_osd_t *osd, Line 890  osd_source_check(osm_gps_map_osd_t *osd,
890          /* really within puller shape? */          /* really within puller shape? */
891          if(x > Z_RAD || osm_gps_map_in_circle(x, y, Z_RAD, Z_RAD, Z_RAD)) {          if(x > Z_RAD || osm_gps_map_in_circle(x, y, Z_RAD, Z_RAD, Z_RAD)) {
892              /* expand source selector */              /* expand source selector */
893              osd_source_toggle(osd);              if(down)
894                    osd_source_toggle(osd);
895    
896              /* tell upper layers that user clicked some background element */              /* tell upper layers that user clicked some background element */
897              /* of the OSD */              /* of the OSD */
# Line 900  osd_source_check(osm_gps_map_osd_t *osd, Line 917  osd_source_check(osm_gps_map_osd_t *osd,
917              y /= step;              y /= step;
918              y += 1;              y += 1;
919    
920              gint old = 0;              if(down) {
921              g_object_get(osd->widget, "map-source", &old, NULL);                  gint old = 0;
922                    g_object_get(osd->widget, "map-source", &old, NULL);
923              if(y > OSM_GPS_MAP_SOURCE_NULL &&  
924                 y <= OSM_GPS_MAP_SOURCE_LAST &&                  if(y > OSM_GPS_MAP_SOURCE_NULL &&
925                 old != y) {                     y <= OSM_GPS_MAP_SOURCE_LAST &&
926                  g_object_set(osd->widget, "map-source", y, NULL);                     old != y) {
927                        g_object_set(osd->widget, "map-source", y, NULL);
928                  osd_render_source_sel(osd, TRUE);  
929                  osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));                      osd_render_source_sel(osd, TRUE);
930                        osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
931                    }
932              }              }
933    
934              /* return "clicked in OSD background" to prevent further */              /* return "clicked in OSD background" to prevent further */
# Line 923  osd_source_check(osm_gps_map_osd_t *osd, Line 942  osd_source_check(osm_gps_map_osd_t *osd,
942  #endif // OSD_SOURCE_SEL  #endif // OSD_SOURCE_SEL
943    
944  static osd_button_t  static osd_button_t
945  osd_check(osm_gps_map_osd_t *osd, gint x, gint y) {  osd_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) {
946      osd_button_t but = OSD_NONE;      osd_button_t but = OSD_NONE;
947    
948  #ifdef OSD_BALLOON  #ifdef OSD_BALLOON
949      /* check if user clicked into balloon */      if(down) {
950      if(osd_balloon_check(osd, x, y))          /* needed to handle balloons that are created at click */
951          return OSD_BG;          osd_priv_t *priv = (osd_priv_t*)osd->priv;
952            priv->balloon.just_created = FALSE;
953        }
954  #endif  #endif
955    
956  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
957      /* the source selection area is handles internally */      /* the source selection area is handles internally */
958      but = osd_source_check(osd, x, y);      but = osd_source_check(osd, down, x, y);
     if(but != OSD_NONE)  
         return but;  
959  #endif  #endif
960    
961      x -= OSD_X;      if(but == OSD_NONE) {
962      y -= OSD_Y;          gint mx = x - OSD_X;
963            gint my = y - OSD_Y;
964      if(OSD_X < 0)  
965          x -= (osd->widget->allocation.width - OSD_W);          if(OSD_X < 0)
966                mx -= (osd->widget->allocation.width - OSD_W);
967      if(OSD_Y < 0)  
968          y -= (osd->widget->allocation.height - OSD_H);          if(OSD_Y < 0)
969                my -= (osd->widget->allocation.height - OSD_H);
970      /* first do a rough test for the OSD area. */  
971      /* this is just to avoid an unnecessary detailed test */          /* first do a rough test for the OSD area. */
972      if(x > 0 && x < OSD_W && y > 0 && y < OSD_H) {          /* this is just to avoid an unnecessary detailed test */
973            if(mx > 0 && mx < OSD_W && my > 0 && my < OSD_H) {
974  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
975          but = osd_check_dpad(x, y);              but = osd_check_dpad(mx, my);
976  #endif  #endif
977            }
978    
979          if(but == OSD_NONE)          if(but == OSD_NONE)
980              but = osd_check_zoom(x, y);              but = osd_check_zoom(mx, my);
981      }      }
982    
983    #ifdef OSD_BALLOON
984        if(but == OSD_NONE) {
985            /* check if user clicked into balloon */
986            if(osd_balloon_check(osd, down, x, y))
987                but = OSD_BG;
988        }
989    #endif
990    
991      return but;      return but;
992  }  }
993    
# Line 1745  osm_gps_map_osd_check(OsmGpsMap *map, gi Line 1774  osm_gps_map_osd_check(OsmGpsMap *map, gi
1774      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
1775      g_return_val_if_fail (osd, OSD_NONE);      g_return_val_if_fail (osd, OSD_NONE);
1776    
1777      return osd_check(osd, x, y);      return osd_check(osd, TRUE, x, y);
1778  }  }

Legend:
Removed from v.113  
changed lines
  Added in v.120