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 114 by harbaum, Wed Sep 16 20:04:38 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 287  osd_balloon_check(osm_gps_map_osd_t *osd Line 288  osd_balloon_check(osm_gps_map_osd_t *osd
288      xs += priv->balloon.rect.x + priv->balloon.offset_x;      xs += priv->balloon.rect.x + priv->balloon.offset_x;
289      ys += priv->balloon.rect.y + priv->balloon.offset_y;      ys += priv->balloon.rect.y + priv->balloon.offset_y;
290    
291      return (priv->balloon.surface &&      /* handle the fact that the balloon may have been created by the */
292              (x > xs) && (x < xs + priv->balloon.rect.w) &&      /* button down event */
293              (y > ys) && (y < ys + priv->balloon.rect.h));  
294        gboolean is_in =
295            (x > xs) && (x < xs + priv->balloon.rect.w) &&
296            (y > ys) && (y < ys + priv->balloon.rect.h);
297    
298        if(!is_in && !down && !priv->balloon.just_created) {
299            /* the user actually clicked outside the balloon */
300    
301            /* close the balloon! */
302            osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(osd->widget));
303        }
304    
305        return is_in;
306  }  }
307    
308  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 314  void osm_gps_map_osd_clear_balloon (OsmG
314      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
315      g_return_if_fail (priv);      g_return_if_fail (priv);
316    
     printf("request to clear balloon\n");  
   
317      if(priv->balloon.surface) {      if(priv->balloon.surface) {
318          cairo_surface_destroy(priv->balloon.surface);          cairo_surface_destroy(priv->balloon.surface);
319          priv->balloon.surface = NULL;          priv->balloon.surface = NULL;
# Line 325  osm_gps_map_osd_draw_balloon (OsmGpsMap Line 336  osm_gps_map_osd_draw_balloon (OsmGpsMap
336    
337      osm_gps_map_osd_clear_balloon (map);      osm_gps_map_osd_clear_balloon (map);
338    
     printf("request to draw balloon at %f %f\n", latitude, longitude);  
   
339      /* allocate balloon surface */      /* allocate balloon surface */
340      priv->balloon.surface =      priv->balloon.surface =
341          cairo_image_surface_create(CAIRO_FORMAT_ARGB32,          cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
# Line 336  osm_gps_map_osd_draw_balloon (OsmGpsMap Line 345  osm_gps_map_osd_draw_balloon (OsmGpsMap
345      priv->balloon.lon = longitude;      priv->balloon.lon = longitude;
346      priv->balloon.cb = cb;      priv->balloon.cb = cb;
347      priv->balloon.data = data;      priv->balloon.data = data;
348        priv->balloon.just_created = TRUE;
349    
350      priv->balloon.orientation = -1;      priv->balloon.orientation = -1;
351    
# Line 856  osd_source_toggle(osm_gps_map_osd_t *osd Line 866  osd_source_toggle(osm_gps_map_osd_t *osd
866    
867  /* check if the user clicked inside the source selection area */  /* check if the user clicked inside the source selection area */
868  static osd_button_t  static osd_button_t
869  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) {
870      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
871    
872      if(!priv->source_sel.expanded)      if(!priv->source_sel.expanded)
# Line 874  osd_source_check(osm_gps_map_osd_t *osd, Line 884  osd_source_check(osm_gps_map_osd_t *osd,
884          /* really within puller shape? */          /* really within puller shape? */
885          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)) {
886              /* expand source selector */              /* expand source selector */
887              osd_source_toggle(osd);              if(down)
888                    osd_source_toggle(osd);
889    
890              /* tell upper layers that user clicked some background element */              /* tell upper layers that user clicked some background element */
891              /* of the OSD */              /* of the OSD */
# Line 900  osd_source_check(osm_gps_map_osd_t *osd, Line 911  osd_source_check(osm_gps_map_osd_t *osd,
911              y /= step;              y /= step;
912              y += 1;              y += 1;
913    
914              gint old = 0;              if(down) {
915              g_object_get(osd->widget, "map-source", &old, NULL);                  gint old = 0;
916                    g_object_get(osd->widget, "map-source", &old, NULL);
917              if(y > OSM_GPS_MAP_SOURCE_NULL &&  
918                 y <= OSM_GPS_MAP_SOURCE_LAST &&                  if(y > OSM_GPS_MAP_SOURCE_NULL &&
919                 old != y) {                     y <= OSM_GPS_MAP_SOURCE_LAST &&
920                  g_object_set(osd->widget, "map-source", y, NULL);                     old != y) {
921                        g_object_set(osd->widget, "map-source", y, NULL);
922                  osd_render_source_sel(osd, TRUE);  
923                  osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));                      osd_render_source_sel(osd, TRUE);
924                        osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
925                    }
926              }              }
927    
928              /* 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 936  osd_source_check(osm_gps_map_osd_t *osd,
936  #endif // OSD_SOURCE_SEL  #endif // OSD_SOURCE_SEL
937    
938  static osd_button_t  static osd_button_t
939  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) {
940      osd_button_t but = OSD_NONE;      osd_button_t but = OSD_NONE;
941    
942  #ifdef OSD_BALLOON  #ifdef OSD_BALLOON
943      /* check if user clicked into balloon */      if(down) {
944      if(osd_balloon_check(osd, x, y))          /* needed to handle balloons that are created at click */
945          return OSD_BG;          osd_priv_t *priv = (osd_priv_t*)osd->priv;
946            priv->balloon.just_created = FALSE;
947        }
948  #endif  #endif
949    
950  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
951      /* the source selection area is handles internally */      /* the source selection area is handles internally */
952      but = osd_source_check(osd, x, y);      but = osd_source_check(osd, down, x, y);
     if(but != OSD_NONE)  
         return but;  
953  #endif  #endif
954    
955      x -= OSD_X;      if(but == OSD_NONE) {
956      y -= OSD_Y;          x -= OSD_X;
957            y -= OSD_Y;
958      if(OSD_X < 0)  
959          x -= (osd->widget->allocation.width - OSD_W);          if(OSD_X < 0)
960                x -= (osd->widget->allocation.width - OSD_W);
961      if(OSD_Y < 0)  
962          y -= (osd->widget->allocation.height - OSD_H);          if(OSD_Y < 0)
963                y -= (osd->widget->allocation.height - OSD_H);
964      /* first do a rough test for the OSD area. */  
965      /* this is just to avoid an unnecessary detailed test */          /* first do a rough test for the OSD area. */
966      if(x > 0 && x < OSD_W && y > 0 && y < OSD_H) {          /* this is just to avoid an unnecessary detailed test */
967            if(x > 0 && x < OSD_W && y > 0 && y < OSD_H) {
968  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
969          but = osd_check_dpad(x, y);              but = osd_check_dpad(x, y);
970  #endif  #endif
971            }
972    
973          if(but == OSD_NONE)          if(but == OSD_NONE)
974              but = osd_check_zoom(x, y);              but = osd_check_zoom(x, y);
975      }      }
976    
977    #ifdef OSD_BALLOON
978        if(but == OSD_NONE) {
979            /* check if user clicked into balloon */
980            if(osd_balloon_check(osd, down, x, y))
981                but = OSD_BG;
982        }
983    #endif
984    
985      return but;      return but;
986  }  }
987    
# Line 1745  osm_gps_map_osd_check(OsmGpsMap *map, gi Line 1768  osm_gps_map_osd_check(OsmGpsMap *map, gi
1768      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
1769      g_return_val_if_fail (osd, OSD_NONE);      g_return_val_if_fail (osd, OSD_NONE);
1770    
1771      return osd_check(osd, x, y);      return osd_check(osd, TRUE, x, y);
1772  }  }

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