kopia lustrzana https://gitlab.com/Zwarf/picplanner
Preparing simpler posibility to add nodes to the 'PicplannerDrawLayer'
rodzic
e8026fd706
commit
d4874ffc2c
|
@ -1,15 +1,12 @@
|
|||
/*
|
||||
* Code mainly taken from https://gitlab.gnome.org/GNOME/libshumate/-/blob/main/shumate/shumate-path-layer.c
|
||||
* This is a copy of the shumate-path-layer adjusted for the needs of PicPlanner
|
||||
* Code mainly taken from:
|
||||
* https://gitlab.gnome.org/GNOME/libshumate/-/blob/main/shumate/shumate-path-layer.c
|
||||
* https://gitlab.gnome.org/GNOME/libshumate/-/blob/main/shumate/shumate-marker-layer.c
|
||||
* This is a combination of the 'ShumatePathLayer' and 'ShumateMarkerLayer' classes adjusted for the needs of PicPlanner.
|
||||
*/
|
||||
|
||||
#include "draw-layer.h"
|
||||
|
||||
#include <cairo/cairo-gobject.h>
|
||||
#include <gdk/gdk.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <glib.h>
|
||||
|
||||
static GdkRGBA DEFAULT_STROKE_COLOR = { 0.64, 0.0, 0.0, 1.0 };
|
||||
|
||||
typedef struct
|
||||
|
@ -19,13 +16,15 @@ typedef struct
|
|||
double stroke_width;
|
||||
|
||||
GList *nodes;
|
||||
double *nodes_coordinates;
|
||||
size_t nodes_len;
|
||||
} PicplannerDrawLayerPrivate;
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (PicplannerDrawLayer, picplanner_draw_layer, SHUMATE_TYPE_LAYER);
|
||||
|
||||
static void
|
||||
update_marker_visibility (PicplannerDrawLayer *layer,
|
||||
PicplannerMarker *marker)
|
||||
PicplannerMarker *marker)
|
||||
{
|
||||
ShumateViewport *viewport;
|
||||
ShumateMapSource *map_source;
|
||||
|
@ -164,7 +163,7 @@ shumate_marker_layer_constructed (GObject *object)
|
|||
|
||||
static void
|
||||
picplanner_draw_layer_snapshot (GtkWidget *widget,
|
||||
GtkSnapshot *snapshot)
|
||||
GtkSnapshot *snapshot)
|
||||
{
|
||||
PicplannerDrawLayer *self = (PicplannerDrawLayer *)widget;
|
||||
PicplannerDrawLayerPrivate *priv = picplanner_draw_layer_get_instance_private (self);
|
||||
|
@ -232,6 +231,8 @@ 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;
|
||||
|
||||
priv->stroke_color = gdk_rgba_copy (&DEFAULT_STROKE_COLOR);
|
||||
}
|
||||
|
@ -246,9 +247,9 @@ picplanner_draw_layer_new (ShumateViewport *viewport)
|
|||
}
|
||||
|
||||
static void
|
||||
position_notify (ShumateLocation *location,
|
||||
GParamSpec *pspec,
|
||||
PicplannerDrawLayer *layer)
|
||||
position_notify (ShumateLocation *location,
|
||||
GParamSpec *pspec,
|
||||
PicplannerDrawLayer *layer)
|
||||
{
|
||||
(void) location;
|
||||
(void) pspec;
|
||||
|
@ -274,7 +275,7 @@ add_node (PicplannerDrawLayer *layer,
|
|||
|
||||
void
|
||||
picplanner_draw_layer_add_marker (PicplannerDrawLayer *layer,
|
||||
PicplannerMarker *marker)
|
||||
PicplannerMarker *marker)
|
||||
{
|
||||
g_return_if_fail (PICPLANNER_IS_DRAW_LAYER (layer));
|
||||
g_return_if_fail (PICPLANNER_IS_MARKER (marker));
|
||||
|
@ -287,7 +288,7 @@ picplanner_draw_layer_add_marker (PicplannerDrawLayer *layer,
|
|||
|
||||
void
|
||||
picplanner_draw_layer_add_node (PicplannerDrawLayer *layer,
|
||||
double *location)
|
||||
double *location)
|
||||
{
|
||||
g_return_if_fail (PICPLANNER_IS_DRAW_LAYER (layer));
|
||||
|
||||
|
@ -336,8 +337,8 @@ picplanner_draw_layer_get_nodes (PicplannerDrawLayer *layer)
|
|||
|
||||
|
||||
void
|
||||
picplanner_draw_layer_remove_node (PicplannerDrawLayer *layer,
|
||||
double *location)
|
||||
picplanner_draw_layer_remove_node (PicplannerDrawLayer *layer,
|
||||
double *location)
|
||||
{
|
||||
PicplannerDrawLayerPrivate *priv = picplanner_draw_layer_get_instance_private (layer);
|
||||
|
||||
|
@ -352,9 +353,9 @@ picplanner_draw_layer_remove_node (PicplannerDrawLayer *layer,
|
|||
|
||||
|
||||
void
|
||||
picplanner_draw_layer_insert_node (PicplannerDrawLayer *layer,
|
||||
double *location,
|
||||
guint position)
|
||||
picplanner_draw_layer_insert_node (PicplannerDrawLayer *layer,
|
||||
double *location,
|
||||
guint position)
|
||||
{
|
||||
g_return_if_fail (PICPLANNER_IS_DRAW_LAYER (layer));
|
||||
|
||||
|
@ -364,7 +365,7 @@ picplanner_draw_layer_insert_node (PicplannerDrawLayer *layer,
|
|||
|
||||
void
|
||||
picplanner_draw_layer_set_stroke_color (PicplannerDrawLayer *layer,
|
||||
const GdkRGBA *color)
|
||||
const GdkRGBA *color)
|
||||
{
|
||||
PicplannerDrawLayerPrivate *priv = picplanner_draw_layer_get_instance_private (layer);
|
||||
|
||||
|
@ -395,7 +396,7 @@ picplanner_draw_layer_get_stroke_color (PicplannerDrawLayer *layer)
|
|||
|
||||
void
|
||||
picplanner_draw_layer_set_stroke (PicplannerDrawLayer *layer,
|
||||
gboolean value)
|
||||
gboolean value)
|
||||
{
|
||||
PicplannerDrawLayerPrivate *priv = picplanner_draw_layer_get_instance_private (layer);
|
||||
|
||||
|
@ -420,7 +421,7 @@ picplanner_draw_layer_get_stroke (PicplannerDrawLayer *layer)
|
|||
|
||||
void
|
||||
picplanner_draw_layer_set_stroke_width (PicplannerDrawLayer *layer,
|
||||
double value)
|
||||
double value)
|
||||
{
|
||||
PicplannerDrawLayerPrivate *priv = picplanner_draw_layer_get_instance_private (layer);
|
||||
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
/*
|
||||
* Code mainly taken from https://gitlab.gnome.org/GNOME/libshumate/-/blob/main/shumate/shumate-path-layer.h
|
||||
* This is a copy of the shumate-path-layer adjusted for the needs of PicPlanner
|
||||
* Code mainly taken from:
|
||||
* https://gitlab.gnome.org/GNOME/libshumate/-/blob/main/shumate/shumate-path-layer.h
|
||||
* https://gitlab.gnome.org/GNOME/libshumate/-/blob/main/shumate/shumate-marker-layer.h
|
||||
* This is a combination of the 'ShumatePathLayer' and 'ShumateMarkerLayer' classes adjusted for the needs of PicPlanner.
|
||||
*/
|
||||
|
||||
#ifndef PICPLANNER_DRAW_LAYER_H
|
||||
#define PICPLANNER_DRAW_LAYER_H
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <shumate/shumate.h>
|
||||
#include <gdk/gdk.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "marker.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
@ -21,41 +23,53 @@ struct _PicplannerDrawLayerClass
|
|||
ShumateLayerClass parent_class;
|
||||
};
|
||||
|
||||
PicplannerDrawLayer *picplanner_draw_layer_new (ShumateViewport *viewport);
|
||||
PicplannerDrawLayer
|
||||
*picplanner_draw_layer_new (ShumateViewport *viewport);
|
||||
|
||||
void
|
||||
picplanner_draw_layer_add_marker (PicplannerDrawLayer *layer,
|
||||
PicplannerMarker *marker);
|
||||
PicplannerMarker *marker);
|
||||
|
||||
|
||||
void picplanner_draw_layer_add_node (PicplannerDrawLayer *layer,
|
||||
double *location);
|
||||
void
|
||||
picplanner_draw_layer_add_node (PicplannerDrawLayer *layer,
|
||||
double *location);
|
||||
|
||||
void picplanner_draw_layer_remove_node (PicplannerDrawLayer *layer,
|
||||
double *location);
|
||||
void
|
||||
picplanner_draw_layer_remove_node (PicplannerDrawLayer *layer,
|
||||
double *location);
|
||||
|
||||
void picplanner_draw_layer_remove_all (PicplannerDrawLayer *layer);
|
||||
void
|
||||
picplanner_draw_layer_remove_all (PicplannerDrawLayer *layer);
|
||||
|
||||
void picplanner_draw_layer_insert_node (PicplannerDrawLayer *layer,
|
||||
double *location,
|
||||
guint position);
|
||||
void
|
||||
picplanner_draw_layer_insert_node (PicplannerDrawLayer *layer,
|
||||
double *location,
|
||||
guint position);
|
||||
|
||||
GList *picplanner_draw_layer_get_nodes (PicplannerDrawLayer *layer);
|
||||
GList
|
||||
*picplanner_draw_layer_get_nodes (PicplannerDrawLayer *layer);
|
||||
|
||||
GdkRGBA *picplanner_draw_layer_get_stroke_color (PicplannerDrawLayer *layer);
|
||||
GdkRGBA
|
||||
*picplanner_draw_layer_get_stroke_color (PicplannerDrawLayer *layer);
|
||||
|
||||
void picplanner_draw_layer_set_stroke_color (PicplannerDrawLayer *layer,
|
||||
const GdkRGBA *color);
|
||||
void
|
||||
picplanner_draw_layer_set_stroke_color (PicplannerDrawLayer *layer,
|
||||
const GdkRGBA *color);
|
||||
|
||||
gboolean picplanner_draw_layer_get_stroke (PicplannerDrawLayer *layer);
|
||||
gboolean
|
||||
picplanner_draw_layer_get_stroke (PicplannerDrawLayer *layer);
|
||||
|
||||
void picplanner_draw_layer_set_stroke (PicplannerDrawLayer *layer,
|
||||
gboolean value);
|
||||
void
|
||||
picplanner_draw_layer_set_stroke (PicplannerDrawLayer *layer,
|
||||
gboolean value);
|
||||
|
||||
double picplanner_draw_layer_get_stroke_width (PicplannerDrawLayer *layer);
|
||||
double
|
||||
picplanner_draw_layer_get_stroke_width (PicplannerDrawLayer *layer);
|
||||
|
||||
void picplanner_draw_layer_set_stroke_width (PicplannerDrawLayer *layer,
|
||||
double value);
|
||||
void
|
||||
picplanner_draw_layer_set_stroke_width (PicplannerDrawLayer *layer,
|
||||
double value);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
/*
|
||||
* Code mainly taken from https://gitlab.gnome.org/GNOME/libshumate/-/blob/main/shumate/shumate-marker.c
|
||||
* This is a copy of the shumate-path-layer adjusted for the needs of PicPlanner
|
||||
* This is a copy of the 'ShumateMarker' class adjusted for the needs of PicPlanner
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include "marker.h"
|
||||
|
||||
typedef struct
|
||||
|
@ -26,8 +23,8 @@ static GtkBuildableIface *parent_buildable_iface;
|
|||
|
||||
void
|
||||
picplanner_marker_set_location (PicplannerMarker *marker,
|
||||
double x,
|
||||
double y)
|
||||
double x,
|
||||
double y)
|
||||
{
|
||||
PicplannerMarkerPrivate *priv = picplanner_marker_get_instance_private (marker);
|
||||
|
||||
|
@ -55,9 +52,9 @@ picplanner_marker_get_y (PicplannerMarker *marker)
|
|||
|
||||
static void
|
||||
picplanner_marker_add_child (GtkBuildable *buildable,
|
||||
GtkBuilder *builder,
|
||||
GObject *child,
|
||||
const char *type)
|
||||
GtkBuilder *builder,
|
||||
GObject *child,
|
||||
const char *type)
|
||||
{
|
||||
if (GTK_IS_WIDGET (child))
|
||||
picplanner_marker_set_child (PICPLANNER_MARKER (buildable), GTK_WIDGET (child));
|
||||
|
@ -123,7 +120,7 @@ picplanner_marker_get_child (PicplannerMarker *marker)
|
|||
|
||||
void
|
||||
picplanner_marker_set_child (PicplannerMarker *marker,
|
||||
GtkWidget *child)
|
||||
GtkWidget *child)
|
||||
{
|
||||
PicplannerMarkerPrivate *priv = picplanner_marker_get_instance_private (marker);
|
||||
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
/*
|
||||
* Code mainly taken from https://gitlab.gnome.org/GNOME/libshumate/-/blob/main/shumate/shumate-marker.h
|
||||
* This is a copy of the shumate-path-layer adjusted for the needs of PicPlanner
|
||||
* This is a copy of the 'ShumateMarker' class adjusted for the needs of PicPlanner
|
||||
*/
|
||||
|
||||
#ifndef PICPLANNER_MARKER_H
|
||||
#define PICPLANNER_MARKER_H
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <glib-object.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
@ -37,8 +35,9 @@ PicplannerMarker
|
|||
GtkWidget
|
||||
*picplanner_marker_get_child (PicplannerMarker *marker);
|
||||
|
||||
void picplanner_marker_set_child (PicplannerMarker *marker,
|
||||
GtkWidget *child);
|
||||
void
|
||||
picplanner_marker_set_child (PicplannerMarker *marker,
|
||||
GtkWidget *child);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
|
||||
/*
|
||||
* TODO:
|
||||
* - Catching Azimuth 0 deg errors
|
||||
*/
|
||||
|
||||
#include "overview-view.h"
|
||||
#include "calculations/calculations_transformations.h"
|
||||
#include "calculations/calculations_sun.h"
|
||||
|
@ -6,38 +12,42 @@
|
|||
#include "map/draw-layer.h"
|
||||
#include "map/marker.h"
|
||||
|
||||
|
||||
#define LENGTH_SCALE_FACTOR 0.38
|
||||
|
||||
static guint signal_input_changed;
|
||||
|
||||
/*
|
||||
* TODO: Catching Azimuth 0 deg errors
|
||||
*/
|
||||
|
||||
|
||||
struct _PicplannerOverview
|
||||
{
|
||||
GtkBox parent_instance;
|
||||
GtkWidget *calendar;
|
||||
GtkWidget *calendar_popover;
|
||||
GtkWidget *calendar_button;
|
||||
|
||||
GtkWidget *spin_button_hour;
|
||||
GtkWidget *spin_button_minute;
|
||||
|
||||
GtkWidget *label_sun_rise;
|
||||
GtkWidget *label_sun_set;
|
||||
GtkWidget *label_moon_rise;
|
||||
GtkWidget *label_moon_set;
|
||||
GtkWidget *label_milky_way_rise;
|
||||
GtkWidget *label_milky_way_set;
|
||||
|
||||
GtkWidget *expander_date_time;
|
||||
GtkWidget *expander_basic_information;
|
||||
|
||||
ShumateSimpleMap *map;
|
||||
ShumateViewport *viewport;
|
||||
|
||||
PicplannerMarker *pp_marker_center;
|
||||
PicplannerDrawLayer *pp_layer_center;
|
||||
PicplannerDrawLayer *pp_layer_sun;
|
||||
PicplannerDrawLayer *pp_layer_moon;
|
||||
PicplannerDrawLayer *pp_layer_milkyway;
|
||||
|
||||
PicplannerMarker *pp_marker_center;
|
||||
PicplannerMarker *pp_marker_sun;
|
||||
PicplannerMarker *pp_marker_moon;
|
||||
PicplannerMarker *pp_marker_milkyway;
|
||||
|
||||
GDateTime *date_time;
|
||||
|
||||
|
@ -85,27 +95,6 @@ picplanner_overview_set_current_coordinates_sun (PicplannerOverview *overview,
|
|||
date_time_rise = g_date_time_add_minutes (overview->date_time, rise_upper_set_index[0]*24*60/NUM_DATA_POINTS-12*60);
|
||||
date_time_set = g_date_time_add_minutes (overview->date_time, rise_upper_set_index[2]*24*60/NUM_DATA_POINTS-12*60);
|
||||
|
||||
/*
|
||||
GDateTime *from_time;
|
||||
GDateTime *to_time;
|
||||
from_time = g_date_time_add_minutes (overview->date_time, -12*60);
|
||||
to_time = g_date_time_add_minutes (overview->date_time, 12*60);
|
||||
|
||||
* TODO: With the method of the calculations centered around the chosen time
|
||||
* some unintuitive behaviour can occure
|
||||
g_print ("From: %02d.%02d.%02d %02d:%02d, To: %02d.%02d.%02d %02d:%02d\n",
|
||||
g_date_time_get_day_of_month (from_time),
|
||||
g_date_time_get_month (from_time),
|
||||
g_date_time_get_year (from_time),
|
||||
g_date_time_get_hour (from_time),
|
||||
g_date_time_get_minute (from_time),
|
||||
g_date_time_get_day_of_month (to_time),
|
||||
g_date_time_get_month (to_time),
|
||||
g_date_time_get_year (to_time),
|
||||
g_date_time_get_hour (to_time),
|
||||
g_date_time_get_minute (to_time));
|
||||
*/
|
||||
|
||||
char_sun_rise = g_strdup_printf ("%02d:%02d",
|
||||
g_date_time_get_hour (date_time_rise),
|
||||
g_date_time_get_minute (date_time_rise));
|
||||
|
@ -197,17 +186,71 @@ picplanner_overview_update_map_center (PicplannerOverview *overview,
|
|||
gtk_image_set_icon_size (GTK_IMAGE (image_center), GTK_ICON_SIZE_LARGE);
|
||||
|
||||
shumate_viewport_location_to_widget_coords (overview->viewport,
|
||||
GTK_WIDGET (overview->map),
|
||||
latitude, longitude,
|
||||
&x, &y);
|
||||
GTK_WIDGET (overview->map),
|
||||
latitude, longitude,
|
||||
&x, &y);
|
||||
|
||||
picplanner_marker_set_location (overview->pp_marker_center, x, y);
|
||||
picplanner_marker_set_child (overview->pp_marker_center, image_center);
|
||||
picplanner_draw_layer_add_marker (overview->pp_layer_center, overview->pp_marker_center);
|
||||
}
|
||||
|
||||
g_print ("Picplanner Marker x: %f, y: %f\n",
|
||||
picplanner_marker_get_x (overview->pp_marker_center),
|
||||
picplanner_marker_get_y (overview->pp_marker_center));
|
||||
void
|
||||
picplanner_overview_update_map_sun (PicplannerOverview *overview,
|
||||
double latitude,
|
||||
double longitude,
|
||||
double *array_coordinates_sun,
|
||||
int *rise_upper_set_sun)
|
||||
{
|
||||
int width, height, min_size;
|
||||
|
||||
double x, y;
|
||||
double x_sun, y_sun;
|
||||
double x_sunrise, y_sunrise;
|
||||
double x_sunset, y_sunset;
|
||||
double azimuth_sun, azimuth_sunrise, azimuth_sunset;
|
||||
|
||||
gboolean visible_sun = TRUE;
|
||||
|
||||
GtkWidget *image_sun;
|
||||
|
||||
picplanner_draw_layer_remove_all (overview->pp_layer_sun);
|
||||
|
||||
if (array_coordinates_sun[NUM_DATA_POINTS+1]<0)
|
||||
visible_sun = FALSE;
|
||||
image_sun = gtk_image_new_from_icon_name ("sun");
|
||||
gtk_image_set_icon_size (GTK_IMAGE (image_sun), GTK_ICON_SIZE_LARGE);
|
||||
gtk_widget_set_visible (image_sun, visible_sun);
|
||||
|
||||
shumate_viewport_location_to_widget_coords (overview->viewport,
|
||||
GTK_WIDGET (overview->map),
|
||||
latitude, longitude,
|
||||
&x, &y);
|
||||
|
||||
width = gtk_widget_get_allocated_width (GTK_WIDGET (overview->map));
|
||||
height = gtk_widget_get_allocated_height (GTK_WIDGET (overview->map));
|
||||
if (width<height)
|
||||
min_size = width;
|
||||
else
|
||||
min_size = height;
|
||||
|
||||
azimuth_sun = array_coordinates_sun[NUM_DATA_POINTS];
|
||||
x_sun = x + sin(calc_deg_to_rad (azimuth_sun)) * min_size * LENGTH_SCALE_FACTOR;
|
||||
y_sun = y - cos(calc_deg_to_rad (azimuth_sun)) * min_size * LENGTH_SCALE_FACTOR;
|
||||
|
||||
azimuth_sunrise = array_coordinates_sun[rise_upper_set_sun[0]*2];
|
||||
x_sunrise = x + sin(calc_deg_to_rad (azimuth_sunrise)) * min_size * LENGTH_SCALE_FACTOR;
|
||||
y_sunrise = y - cos(calc_deg_to_rad (azimuth_sunrise)) * min_size * LENGTH_SCALE_FACTOR;
|
||||
|
||||
azimuth_sunset = array_coordinates_sun[rise_upper_set_sun[2]*2];
|
||||
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;
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* - Add *location pointer to draw-layer
|
||||
* - Only add x,y via Function
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -296,8 +296,8 @@ calculate_positions (PicplannerWindow *window)
|
|||
* Update Shumate Map
|
||||
*/
|
||||
picplanner_overview_update_map_center (PICPLANNER_OVERVIEW (window->overview_box),
|
||||
latitude,
|
||||
longitude);
|
||||
latitude,
|
||||
longitude);
|
||||
|
||||
|
||||
g_free (rise_upper_set_index_sun);
|
||||
|
|
Ładowanie…
Reference in New Issue