summaryrefslogtreecommitdiff
path: root/src/gui/gtk/gui_gtk.c
blob: b29e780f86fcf402a9a32dfa8930573b972ae34e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <stdio.h>
#include <gtk/gtk.h>
#include <glib/gprintf.h>
#include <glade/glade.h>
#include "coord.h"
#include "graphics.h"
#include "transform.h"
#include "container.h"
#include "gui_gtk.h"
#include "menu.h"
#include "destination.h"


extern void container_init_gra(struct container *co);

void on_Zoom_in_clicked(GtkWidget *widget, gpointer user_data);
void on_Zoom_out_clicked(GtkWidget *widget, gpointer user_data);
void on_Refresh_clicked(GtkWidget *widget, gpointer user_data);
void on_Cursor_toggled(GtkWidget *widget, gpointer user_data);
void  on_Orientation_toggled(GtkWidget *widget, gpointer user_data);
void on_Destination_clicked(GtkWidget *widget, gpointer user_data);
void on_Quit_clicked(GtkWidget *widget, gpointer user_data);
void on_mainwindow_delete_event(GtkWidget *widget, gpointer user_data);


static struct container *
get_container(GtkWidget *widget)
{
	GtkWidget *map_widget;
	GladeXML *xml=glade_get_widget_tree(widget);
	map_widget = glade_xml_get_widget(xml,"map");
	return g_object_get_data(G_OBJECT(map_widget), "navit_container");
}

void on_Zoom_in_clicked(GtkWidget *widget, gpointer user_data)
{
	unsigned long scale;
	struct container *co;

	co=get_container(widget);
        graphics_get_view(co, NULL, NULL, &scale);
        scale/=2;
        if (scale < 1)
                scale=1;
        graphics_set_view(co, NULL, NULL, &scale);
}

void on_Zoom_out_clicked(GtkWidget *widget, gpointer user_data)
{
	unsigned long scale;
	struct container *co;

	co=get_container(widget);
        graphics_get_view(co, NULL, NULL, &scale);
        scale*=2;
        graphics_set_view(co, NULL, NULL, &scale);
}

void on_Refresh_clicked(GtkWidget *widget, gpointer user_data)
{
	struct container *co;

	co=get_container(widget);
	menu_route_update(co);
}

void on_Cursor_toggled(GtkWidget *widget, gpointer user_data)
{
	struct container *co;

	co=get_container(widget);
	co->flags->track=gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(widget));
}

void  on_Orientation_toggled(GtkWidget *widget, gpointer user_data)
{
	struct container *co;

	co=get_container(widget);
	co->flags->orient_north=gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(widget));
}

void on_Destination_clicked(GtkWidget *widget, gpointer user_data)
{
	struct container *co;

	co=get_container(widget);
	destination_address(co);
}

void on_Quit_clicked(GtkWidget *widget, gpointer user_data)
{
	gtk_main_quit ();
}

void on_mainwindow_delete_event(GtkWidget *widget, gpointer user_data)
{
	gtk_main_quit ();
}


static struct container *
container_new(GtkWidget **widget)
{
	struct container *co=g_new0(struct container, 1);
	extern struct map_data *map_data_default;
	struct transformation *t=g_new0(struct transformation, 1);
	struct map_flags *flags=g_new0(struct map_flags, 1);
	struct graphics *gra;

	co->map_data=map_data_default;	
#if 1
	extern struct graphics *graphics_gtk_drawing_area_new(struct container *co, GtkWidget **widget);
	gra=graphics_gtk_drawing_area_new(co, widget);
#else
	extern struct graphics *graphics_gtk_gl_area_new(struct container *co, GtkWidget **widget);
	gra=graphics_gtk_gl_area_new(co, widget);
#endif
	co->gra=gra;
	co->trans=t;	
	co->flags=flags;

	return co;
}

struct container *
gui_gtk_window(int x, int y, int scale)
{
	GladeXML *window;
	GtkWidget *map_widget=NULL;
	struct container *co;


	window = glade_xml_new("navit.glade", NULL, NULL);


	map_widget = glade_xml_get_widget(window,"map");
	co=container_new(&map_widget);
	g_object_set_data(G_OBJECT(map_widget), "navit_container", co);
	transform_setup(co->trans, x, y, scale, 0);

	co->win=(struct window *) window;
	co->statusbar=gui_gtk_statusbar_new(window);


	/* connect all signals */
	glade_xml_signal_autoconnect(window);

	container_init_gra(co);
	return co;
}