Add simple possibility to draw a line on the draw layer

master
Zwarf 2022-04-26 21:54:18 +02:00
rodzic d4874ffc2c
commit 6ec2bb3678
5 zmienionych plików z 45 dodań i 98 usunięć

Wyświetl plik

@ -15,9 +15,8 @@ typedef struct
gboolean stroke;
double stroke_width;
GList *nodes;
double *nodes_coordinates;
size_t nodes_len;
uint nodes_len;
} PicplannerDrawLayerPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (PicplannerDrawLayer, picplanner_draw_layer, SHUMATE_TYPE_LAYER);
@ -130,7 +129,7 @@ picplanner_draw_layer_dispose (GObject *object)
g_signal_handlers_disconnect_by_data (viewport, self);
if (priv->nodes)
if (priv->nodes_coordinates)
picplanner_draw_layer_remove_all (PICPLANNER_DRAW_LAYER (object));
while ((child = gtk_widget_get_first_child (GTK_WIDGET (object))))
@ -169,7 +168,6 @@ picplanner_draw_layer_snapshot (GtkWidget *widget,
PicplannerDrawLayerPrivate *priv = picplanner_draw_layer_get_instance_private (self);
int width, height;
cairo_t *cr;
GList *elem;
width = gtk_widget_get_allocated_width (widget);
height = gtk_widget_get_allocated_height (widget);
@ -181,14 +179,12 @@ picplanner_draw_layer_snapshot (GtkWidget *widget,
cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);
for (elem = priv->nodes; elem != NULL; elem = elem->next)
for (uint i = 0; i < priv->nodes_len; i++)
{
double *location = elem->data;
double x, y;
x = location[0];
y = location[1];
x = priv->nodes_coordinates[i*2];
y = priv->nodes_coordinates[i*2+1];
g_print ("x: %f,y: %f\n",x,y);
cairo_line_to (cr, x, y);
}
@ -230,7 +226,6 @@ picplanner_draw_layer_init (PicplannerDrawLayer *self)
priv->stroke = TRUE;
priv->stroke_width = 2.0;
priv->nodes = NULL;
priv->nodes_coordinates = NULL;
priv->nodes_len = 0;
@ -246,32 +241,6 @@ picplanner_draw_layer_new (ShumateViewport *viewport)
NULL);
}
static void
position_notify (ShumateLocation *location,
GParamSpec *pspec,
PicplannerDrawLayer *layer)
{
(void) location;
(void) pspec;
gtk_widget_queue_draw (GTK_WIDGET (layer));
}
static void
add_node (PicplannerDrawLayer *layer,
double *location,
gboolean prepend,
guint position)
{
PicplannerDrawLayerPrivate *priv = picplanner_draw_layer_get_instance_private (layer);
if (prepend)
priv->nodes = g_list_prepend (priv->nodes, location);
else
priv->nodes = g_list_insert (priv->nodes, location, position);
gtk_widget_queue_draw (GTK_WIDGET (layer));
}
void
picplanner_draw_layer_add_marker (PicplannerDrawLayer *layer,
@ -285,16 +254,24 @@ picplanner_draw_layer_add_marker (PicplannerDrawLayer *layer,
}
void
picplanner_draw_layer_add_node (PicplannerDrawLayer *layer,
double *location)
picplanner_draw_layer_add_node_coordinates (PicplannerDrawLayer *layer,
double x,
double y)
{
g_return_if_fail (PICPLANNER_IS_DRAW_LAYER (layer));
add_node (layer, location, TRUE, 0);
}
PicplannerDrawLayerPrivate *priv = picplanner_draw_layer_get_instance_private (layer);
priv->nodes_coordinates = (double *) realloc (priv->nodes_coordinates, sizeof (double) * (priv->nodes_len+1) * 2);
priv->nodes_coordinates[priv->nodes_len*2] = x;
priv->nodes_coordinates[priv->nodes_len*2+1] = y;
priv->nodes_len ++;
gtk_widget_queue_draw (GTK_WIDGET (layer));
}
void
picplanner_draw_layer_remove_all (PicplannerDrawLayer *layer)
@ -303,11 +280,6 @@ picplanner_draw_layer_remove_all (PicplannerDrawLayer *layer)
g_return_if_fail (PICPLANNER_IS_DRAW_LAYER (layer));
g_clear_pointer (&priv->nodes, g_list_free);
gtk_widget_queue_draw (GTK_WIDGET (layer));
GtkWidget *child;
child = gtk_widget_get_first_child (GTK_WIDGET (layer));
@ -320,49 +292,15 @@ picplanner_draw_layer_remove_all (PicplannerDrawLayer *layer)
child = next;
}
}
g_free (priv->nodes_coordinates);
priv->nodes_coordinates = NULL;
priv->nodes_len = 0;
GList *
picplanner_draw_layer_get_nodes (PicplannerDrawLayer *layer)
{
PicplannerDrawLayerPrivate *priv = picplanner_draw_layer_get_instance_private (layer);
GList *lst;
g_return_val_if_fail (PICPLANNER_IS_DRAW_LAYER (layer), NULL);
lst = g_list_copy (priv->nodes);
return g_list_reverse (lst);
}
void
picplanner_draw_layer_remove_node (PicplannerDrawLayer *layer,
double *location)
{
PicplannerDrawLayerPrivate *priv = picplanner_draw_layer_get_instance_private (layer);
g_return_if_fail (PICPLANNER_IS_DRAW_LAYER (layer));
g_signal_handlers_disconnect_by_func (G_OBJECT (location), G_CALLBACK (position_notify), layer);
priv->nodes = g_list_remove (priv->nodes, location);
g_object_unref (location);
gtk_widget_queue_draw (GTK_WIDGET (layer));
}
void
picplanner_draw_layer_insert_node (PicplannerDrawLayer *layer,
double *location,
guint position)
{
g_return_if_fail (PICPLANNER_IS_DRAW_LAYER (layer));
add_node (layer, location, FALSE, position);
}
void
picplanner_draw_layer_set_stroke_color (PicplannerDrawLayer *layer,
const GdkRGBA *color)

Wyświetl plik

@ -30,25 +30,14 @@ void
picplanner_draw_layer_add_marker (PicplannerDrawLayer *layer,
PicplannerMarker *marker);
void
picplanner_draw_layer_add_node (PicplannerDrawLayer *layer,
double *location);
void
picplanner_draw_layer_remove_node (PicplannerDrawLayer *layer,
double *location);
picplanner_draw_layer_add_node_coordinates (PicplannerDrawLayer *layer,
double x,
double y);
void
picplanner_draw_layer_remove_all (PicplannerDrawLayer *layer);
void
picplanner_draw_layer_insert_node (PicplannerDrawLayer *layer,
double *location,
guint position);
GList
*picplanner_draw_layer_get_nodes (PicplannerDrawLayer *layer);
GdkRGBA
*picplanner_draw_layer_get_stroke_color (PicplannerDrawLayer *layer);

Wyświetl plik

@ -246,6 +246,11 @@ picplanner_overview_update_map_sun (PicplannerOverview *overview,
x_sunset = x + sin(calc_deg_to_rad (azimuth_sunset)) * min_size * LENGTH_SCALE_FACTOR;
y_sunset = y - cos(calc_deg_to_rad (azimuth_sunset)) * min_size * LENGTH_SCALE_FACTOR;
picplanner_draw_layer_add_node_coordinates (overview->pp_layer_sun, x_sunrise, y_sunrise);
picplanner_draw_layer_add_node_coordinates (overview->pp_layer_sun, x, y);
picplanner_draw_layer_add_node_coordinates (overview->pp_layer_sun, x_sunset, y_sunset);
/*
* TODO:
* - Add *location pointer to draw-layer
@ -427,6 +432,8 @@ picplanner_overview_init (PicplannerOverview *overview)
g_object_ref (overview->pp_marker_center);
overview->pp_layer_center = picplanner_draw_layer_new (overview->viewport);
shumate_simple_map_add_overlay_layer (overview->map, SHUMATE_LAYER (overview->pp_layer_center));
overview->pp_layer_sun = picplanner_draw_layer_new (overview->viewport);
shumate_simple_map_add_overlay_layer (overview->map, SHUMATE_LAYER (overview->pp_layer_sun));

Wyświetl plik

@ -29,4 +29,11 @@ picplanner_overview_update_map_center (PicplannerOverview *overview,
double latitude,
double longitude);
void
picplanner_overview_update_map_sun (PicplannerOverview *overview,
double latitude,
double longitude,
double *array_coordinates_sun,
int *rise_upper_set_sun);
G_END_DECLS

Wyświetl plik

@ -299,6 +299,12 @@ calculate_positions (PicplannerWindow *window)
latitude,
longitude);
picplanner_overview_update_map_sun (PICPLANNER_OVERVIEW (window->overview_box),
latitude,
longitude,
array_coordinates_sun,
rise_upper_set_index_sun);
g_free (rise_upper_set_index_sun);
g_free (rise_upper_set_index_moon);