* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef HAVE_MATH_H
+#include <math.h>
+#endif
+#include <glib/gi18n.h>
#include "viking.h"
-#include "vikcoordlayer_pixmap.h"
+#include "icons/icons.h"
-static VikCoordLayer *coord_layer_copy ( VikCoordLayer *vcl, gpointer vp );
-static gboolean coord_layer_set_param ( VikCoordLayer *vcl, guint16 id, VikLayerParamData data, VikViewport *vp );
-static VikLayerParamData coord_layer_get_param ( VikCoordLayer *vcl, guint16 id );
+static void coord_layer_marshall( VikCoordLayer *vcl, guint8 **data, gint *len );
+static VikCoordLayer *coord_layer_unmarshall( guint8 *data, gint len, VikViewport *vvp );
+static gboolean coord_layer_set_param ( VikCoordLayer *vcl, guint16 id, VikLayerParamData data, VikViewport *vp, gboolean is_file_operation );
+static VikLayerParamData coord_layer_get_param ( VikCoordLayer *vcl, guint16 id, gboolean is_file_operation );
static void coord_layer_update_gc ( VikCoordLayer *vcl, VikViewport *vp, const gchar *color );
-static void coord_layer_post_read ( VikCoordLayer *vcl, VikViewport *vp );
+static void coord_layer_post_read ( VikLayer *vl, VikViewport *vp, gboolean from_file );
-VikLayerParamScale param_scales[] = {
+static VikLayerParamScale param_scales[] = {
{ 0.05, 60.0, 0.25, 10 },
{ 1, 10, 1, 0 },
};
-VikLayerParam coord_layer_params[] = {
- { "color", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, "Color:", VIK_LAYER_WIDGET_ENTRY },
- { "min_inc", VIK_LAYER_PARAM_DOUBLE, VIK_LAYER_GROUP_NONE, "Minutes Width:", VIK_LAYER_WIDGET_SPINBUTTON, param_scales + 0 },
- { "line_thickness", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, "Line Thickness:", VIK_LAYER_WIDGET_SPINBUTTON, param_scales + 1 },
+static VikLayerParam coord_layer_params[] = {
+ { "color", VIK_LAYER_PARAM_COLOR, VIK_LAYER_GROUP_NONE, N_("Color:"), VIK_LAYER_WIDGET_COLOR, 0 },
+ { "min_inc", VIK_LAYER_PARAM_DOUBLE, VIK_LAYER_GROUP_NONE, N_("Minutes Width:"), VIK_LAYER_WIDGET_SPINBUTTON, param_scales + 0 },
+ { "line_thickness", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Line Thickness:"), VIK_LAYER_WIDGET_SPINBUTTON, param_scales + 1 },
};
enum { PARAM_COLOR = 0, PARAM_MIN_INC, PARAM_LINE_THICKNESS, NUM_PARAMS };
VikLayerInterface vik_coord_layer_interface = {
- "Coord",
- &coordlayer_pixbuf,
+ N_("Coordinate"),
+ NULL,
+ &vikcoordlayer_pixbuf,
NULL,
0,
NULL,
0,
+ VIK_MENU_ITEM_ALL,
+
(VikLayerFuncCreate) vik_coord_layer_create,
(VikLayerFuncRealize) NULL,
(VikLayerFuncPostRead) coord_layer_post_read,
(VikLayerFuncDraw) vik_coord_layer_draw,
(VikLayerFuncChangeCoordMode) NULL,
+ (VikLayerFuncSetMenuItemsSelection) NULL,
+ (VikLayerFuncGetMenuItemsSelection) NULL,
+
(VikLayerFuncAddMenuItems) NULL,
(VikLayerFuncSublayerAddMenuItems) NULL,
(VikLayerFuncSublayerRenameRequest) NULL,
(VikLayerFuncSublayerToggleVisible) NULL,
+ (VikLayerFuncSublayerTooltip) NULL,
+ (VikLayerFuncLayerTooltip) NULL,
+ (VikLayerFuncLayerSelected) NULL,
- (VikLayerFuncCopy) coord_layer_copy,
+ (VikLayerFuncMarshall) coord_layer_marshall,
+ (VikLayerFuncUnmarshall) coord_layer_unmarshall,
(VikLayerFuncSetParam) coord_layer_set_param,
(VikLayerFuncGetParam) coord_layer_get_param,
(VikLayerFuncReadFileData) NULL,
(VikLayerFuncWriteFileData) NULL,
+ (VikLayerFuncDeleteItem) NULL,
+ (VikLayerFuncCutItem) NULL,
(VikLayerFuncCopyItem) NULL,
(VikLayerFuncPasteItem) NULL,
(VikLayerFuncFreeCopiedItem) NULL,
(VikLayerFuncDragDropRequest) NULL,
+
+ (VikLayerFuncSelectClick) NULL,
+ (VikLayerFuncSelectMove) NULL,
+ (VikLayerFuncSelectRelease) NULL,
+ (VikLayerFuncSelectedViewportMenu) NULL,
};
struct _VikCoordLayer {
GdkGC *gc;
gdouble deg_inc;
guint8 line_thickness;
- gchar *color;
+ GdkColor *color;
};
GType vik_coord_layer_get_type ()
return vcl_type;
}
-static VikCoordLayer *coord_layer_copy ( VikCoordLayer *vcl, gpointer vp )
+static void coord_layer_marshall( VikCoordLayer *vcl, guint8 **data, gint *len )
{
- VikCoordLayer *rv = vik_coord_layer_new ( );
+ vik_layer_marshall_params ( VIK_LAYER(vcl), data, len );
+}
- rv->color = g_strdup ( vcl->color );
- rv->deg_inc = vcl->deg_inc;
- rv->line_thickness = vcl->line_thickness;
- rv->gc = vcl->gc;
- g_object_ref ( rv->gc );
+static VikCoordLayer *coord_layer_unmarshall( guint8 *data, gint len, VikViewport *vvp )
+{
+ VikCoordLayer *rv = vik_coord_layer_new ();
+ vik_layer_unmarshall_params ( VIK_LAYER(rv), data, len, vvp );
return rv;
}
-gboolean coord_layer_set_param ( VikCoordLayer *vcl, guint16 id, VikLayerParamData data, VikViewport *vp )
+gboolean coord_layer_set_param ( VikCoordLayer *vcl, guint16 id, VikLayerParamData data, VikViewport *vp, gboolean is_file_operation )
{
switch ( id )
{
- case PARAM_COLOR: if ( vcl->color ) g_free ( vcl->color ); vcl->color = g_strdup ( data.s ); break;
+ case PARAM_COLOR: if ( vcl->color ) gdk_color_free ( vcl->color ); vcl->color = gdk_color_copy( &(data.c)); break;
case PARAM_MIN_INC: vcl->deg_inc = data.d / 60.0; break;
case PARAM_LINE_THICKNESS: if ( data.u >= 1 && data.u <= 15 ) vcl->line_thickness = data.u; break;
}
return TRUE;
}
-static VikLayerParamData coord_layer_get_param ( VikCoordLayer *vcl, guint16 id )
+static VikLayerParamData coord_layer_get_param ( VikCoordLayer *vcl, guint16 id, gboolean is_file_operation )
{
VikLayerParamData rv;
switch ( id )
{
- case PARAM_COLOR: rv.s = vcl->color ? vcl->color : ""; break;
+ case PARAM_COLOR:
+ if (vcl->color)
+ {
+ rv.c.pixel = vcl->color->pixel;
+ rv.c.red = vcl->color->red;
+ rv.c.green = vcl->color->green;
+ rv.c.blue = vcl->color->blue;
+ }
+ break;
case PARAM_MIN_INC: rv.d = vcl->deg_inc * 60.0; break;
case PARAM_LINE_THICKNESS: rv.i = vcl->line_thickness; break;
}
return rv;
}
-static void coord_layer_post_read ( VikCoordLayer *vcl, VikViewport *vp )
+static void coord_layer_post_read ( VikLayer *vl, VikViewport *vp, gboolean from_file )
{
+ VikCoordLayer *vcl = VIK_COORD_LAYER(vl);
if ( vcl->gc )
g_object_unref ( G_OBJECT(vcl->gc) );
- vcl->gc = vik_viewport_new_gc ( vp, vcl->color, vcl->line_thickness );
+ vcl->gc = vik_viewport_new_gc_from_color ( vp, vcl->color, vcl->line_thickness );
+
}
VikCoordLayer *vik_coord_layer_new ( )
{
+ GdkColor InitColor;
+
VikCoordLayer *vcl = VIK_COORD_LAYER ( g_object_new ( VIK_COORD_LAYER_TYPE, NULL ) );
vik_layer_init ( VIK_LAYER(vcl), VIK_LAYER_COORD );
+ InitColor.pixel = 0;
+ InitColor.red = 65535;
+ InitColor.green = 65535;
+ InitColor.blue = 65535;
+
vcl->gc = NULL;
vcl->deg_inc = 1.0/60.0;
vcl->line_thickness = 3;
- vcl->color = NULL;
+ vcl->color = gdk_color_copy (&InitColor);
return vcl;
}
void vik_coord_layer_draw ( VikCoordLayer *vcl, gpointer data )
{
VikViewport *vp = (VikViewport *) data;
- if ( vik_viewport_get_coord_mode(vp) != VIK_COORD_UTM )
+
+ if ( !vcl->gc ) {
+ return;
+ }
+
+ if ( vik_viewport_get_coord_mode(vp) != VIK_COORD_UTM )
+ {
+ VikCoord left, right, left2, right2;
+ gdouble l, r, i, j;
+ gint x1, y1, x2, y2, smod = 1, mmod = 1;
+ gboolean mins = FALSE, secs = FALSE;
+ GdkGC *dgc = vik_viewport_new_gc_from_color(vp, vcl->color, vcl->line_thickness);
+ GdkGC *mgc = vik_viewport_new_gc_from_color(vp, vcl->color, MAX(vcl->line_thickness/2, 1));
+ GdkGC *sgc = vik_viewport_new_gc_from_color(vp, vcl->color, MAX(vcl->line_thickness/5, 1));
+
+ vik_viewport_screen_to_coord ( vp, 0, 0, &left );
+ vik_viewport_screen_to_coord ( vp, vik_viewport_get_width(vp), 0, &right );
+ vik_viewport_screen_to_coord ( vp, 0, vik_viewport_get_height(vp), &left2 );
+ vik_viewport_screen_to_coord ( vp, vik_viewport_get_width(vp), vik_viewport_get_height(vp), &right2 );
+
+#define CLINE(gc, c1, c2) { \
+ vik_viewport_coord_to_screen(vp, (c1), &x1, &y1); \
+ vik_viewport_coord_to_screen(vp, (c2), &x2, &y2); \
+ vik_viewport_draw_line (vp, (gc), x1, y1, x2, y2); \
+ }
+
+ l = left.east_west;
+ r = right.east_west;
+ if (60*fabs(l-r) < 4) {
+ secs = TRUE;
+ smod = MIN(6, (int)ceil(3600*fabs(l-r)/30.0));
+ }
+ if (fabs(l-r) < 4) {
+ mins = TRUE;
+ mmod = MIN(6, (int)ceil(60*fabs(l-r)/30.0));
+ }
+ for (i=floor(l*60); i<ceil(r*60); i+=1.0) {
+ if (secs) {
+ for (j=i*60+1; j<(i+1)*60; j+=1.0) {
+ left.east_west = j/3600.0;
+ left2.east_west = j/3600.0;
+ if ((int)j % smod == 0) CLINE(sgc, &left, &left2);
+ }
+ }
+ if (mins) {
+ left.east_west = i/60.0;
+ left2.east_west = i/60.0;
+ if ((int)i % mmod == 0) CLINE(mgc, &left, &left2);
+ }
+ if ((int)i % 60 == 0) {
+ left.east_west = i/60.0;
+ left2.east_west = i/60.0;
+ CLINE(dgc, &left, &left2);
+ }
+ }
+
+ vik_viewport_screen_to_coord ( vp, 0, 0, &left );
+ l = left2.north_south;
+ r = left.north_south;
+ for (i=floor(l*60); i<ceil(r*60); i+=1.0) {
+ if (secs) {
+ for (j=i*60+1; j<(i+1)*60; j+=1.0) {
+ left.north_south = j/3600.0;
+ right.north_south = j/3600.0;
+ if ((int)j % smod == 0) CLINE(sgc, &left, &right);
+ }
+ }
+ if (mins) {
+ left.north_south = i/60.0;
+ right.north_south = i/60.0;
+ if ((int)i % mmod == 0) CLINE(mgc, &left, &right);
+ }
+ if ((int)i % 60 == 0) {
+ left.north_south = i/60.0;
+ right.north_south = i/60.0;
+ CLINE(dgc, &left, &right);
+ }
+ }
+#undef CLINE
+ g_object_unref(dgc);
+ g_object_unref(sgc);
+ g_object_unref(mgc);
return;
- if ( vcl->gc != NULL)
+ }
+
+ if ( vik_viewport_get_coord_mode(vp) == VIK_COORD_UTM )
{
const struct UTM *center = (const struct UTM *)vik_viewport_get_center ( vp );
gdouble xmpp = vik_viewport_get_xmpp ( vp ), ympp = vik_viewport_get_ympp ( vp );
max.lat = (topleft.lat > topright.lat) ? topleft.lat : topright.lat;
}
+ /* Can zoom out more than whole world and so the above can give invalid positions */
+ /* Restrict values properly so drawing doesn't go into a near 'infinite' loop */
+ if ( min.lon < -180.0 )
+ min.lon = -180.0;
+ if ( max.lon > 180.0 )
+ max.lon = 180.0;
+ if ( min.lat < -90.0 )
+ min.lat = -90.0;
+ if ( max.lat > 90.0 )
+ max.lat = 90.0;
+
lon = ((double) ((long) ((min.lon)/ vcl->deg_inc))) * vcl->deg_inc;
ll.lon = ll2.lon = lon;
g_object_unref ( G_OBJECT(vcl->gc) );
if ( vcl->color != NULL )
- g_free ( vcl->color );
+ gdk_color_free ( vcl->color );
}
static void coord_layer_update_gc ( VikCoordLayer *vcl, VikViewport *vp, const gchar *color )
{
+ GdkColor InitColor;
+
if ( vcl->color )
- g_free ( vcl->color );
+ gdk_color_free ( vcl->color );
- vcl->color = g_strdup ( color );
+ gdk_color_parse( color, &InitColor);
+ vcl->color = gdk_color_copy( &InitColor );
if ( vcl->gc )
g_object_unref ( G_OBJECT(vcl->gc) );
- vcl->gc = vik_viewport_new_gc ( vp, vcl->color, vcl->line_thickness );
+ vcl->gc = vik_viewport_new_gc_from_color ( vp, vcl->color, vcl->line_thickness );
}
VikCoordLayer *vik_coord_layer_create ( VikViewport *vp )