//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
+void graphics_register_keypress_callback(struct graphics *this_, void (*callback)(void *data, int key), void *data)
+{
+ this_->meth.register_keypress_callback(this_->priv, callback, data);
+}
+
+//##############################################################################################################
+//# Description:
+//# Comment:
+//# Authors: Martin Schaller (04/2008)
+//##############################################################################################################
struct graphics_font * graphics_font_new(struct graphics *gra, int size, int flags)
{
struct graphics_font *this_;
void (*image_free)(struct graphics_priv *gr, struct graphics_image_priv *priv);
void (*get_text_bbox)(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy, struct point *ret);
void (*overlay_disable)(struct graphics_priv *gr, int disable);
- void (*register_key_callback)(struct graphics_priv *gr, void (*callback)(void *data, struct point *p), void *data);
+ void (*register_keypress_callback)(struct graphics_priv *gr, void (*callback)(void *data, int key), void *data);
};
void graphics_register_resize_callback(struct graphics *this_, void (*callback)(void *data, int w, int h), void *data);
void graphics_register_button_callback(struct graphics *this_, void (*callback)(void *data, int pressed, int button, struct point *p), void *data);
void graphics_register_motion_callback(struct graphics *this_, void (*callback)(void *data, struct point *p), void *data);
+void graphics_register_keypress_callback(struct graphics *this_, void (*callback)(void *data, int key), void *data);
struct graphics_font *graphics_font_new(struct graphics *gra, int size, int flags);
struct graphics_gc *graphics_gc_new(struct graphics *gra);
void graphics_gc_destroy(struct graphics_gc *gc);
#define GDK_ENABLE_BROKEN
#include "config.h"
#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+#if !defined(GDK_Book) || !defined(GDK_Calendar)
+#include <X11/XF86keysym.h>
+#endif
#include <fontconfig/fontconfig.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include "color.h"
#include "item.h"
#include "window.h"
+#include "keys.h"
#include "plugin.h"
+#ifndef GDK_Book
+#define GDK_Book XF86XK_Book
+#endif
+#ifndef GDK_Calendar
+#define GDK_Calendar XF86XK_Calendar
+#endif
+
+
struct graphics_priv {
GdkEventButton button_event;
int button_timeout;
void *motion_callback_data;
void (*button_callback)(void *data, int press, int button, struct point *p);
void *button_callback_data;
- void (*key_callback)(void *data, int key);
- void *key_callback_data;
+ void (*keypress_callback)(void *data, int key);
+ void *keypress_callback_data;
};
return FALSE;
}
+
+
static gint
scroll(GtkWidget * widget, GdkEventScroll * event, gpointer user_data)
{
return FALSE;
}
+static gint
+keypress(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
+{
+ struct graphics_priv *this=user_data;
+ if (! this->keypress_callback)
+ return FALSE;
+ if (event->keyval >= 32 && event->keyval < 127) {
+ (*this->keypress_callback)(this->motion_callback_data, event->keyval);
+ return FALSE;
+ }
+ switch (event->keyval) {
+ case GDK_Up:
+ (*this->keypress_callback)(this->motion_callback_data, NAVIT_KEY_UP);
+ break;
+ case GDK_Down:
+ (*this->keypress_callback)(this->motion_callback_data, NAVIT_KEY_DOWN);
+ break;
+ case GDK_Left:
+ (*this->keypress_callback)(this->motion_callback_data, NAVIT_KEY_LEFT);
+ break;
+ case GDK_Right:
+ (*this->keypress_callback)(this->motion_callback_data, NAVIT_KEY_RIGHT);
+ break;
+ case GDK_Book:
+ (*this->keypress_callback)(this->motion_callback_data, NAVIT_KEY_ZOOM_IN);
+ break;
+ case GDK_Calendar:
+ (*this->keypress_callback)(this->motion_callback_data, NAVIT_KEY_ZOOM_OUT);
+ break;
+ default:
+ break;
+ }
+ return FALSE;
+}
+
static struct graphics_priv *graphics_gtk_drawing_area_new_helper(struct graphics_methods *meth);
static void
}
static void
-register_key_callback(struct graphics_priv *this, void (*callback)(void *data, int press, int button, struct point *p), void *data)
+register_keypress_callback(struct graphics_priv *this, void (*callback)(void *data, int key), void *data)
{
- this->key_callback=callback;
- this->key_callback_data=data;
+ dbg(0,"enter\n");
+ GTK_WIDGET_SET_FLAGS (this->widget, GTK_CAN_FOCUS);
+ gtk_widget_set_sensitive(this->widget, TRUE);
+ gtk_widget_grab_focus(this->widget);
+ g_signal_connect(G_OBJECT(this->widget), "key-press-event", G_CALLBACK(keypress), this);
+ this->keypress_callback=callback;
+ this->keypress_callback_data=data;
}
static struct graphics_methods graphics_methods = {
image_free,
get_text_bbox,
overlay_disable,
- register_key_callback,
+ register_keypress_callback,
};
static struct graphics_priv *
#include "vehicle.h"
#include "window.h"
#include "main.h"
+#include "keys.h"
#include "config.h"
#define STATE_VISIBLE 1
gui_internal_menu_root(this);
}
+//##############################################################################################################
+//# Description:
+//# Comment:
+//# Authors: Martin Schaller (04/2008)
+//##############################################################################################################
+static void gui_internal_keypress(void *data, int key)
+{
+ struct gui_priv *this=data;
+ int w,h;
+ struct point p;
+ transform_get_size(navit_get_trans(this->nav), &w, &h);
+ switch (key) {
+ case NAVIT_KEY_UP:
+ p.x=w/2;
+ p.y=0;
+ navit_set_center_screen(this->nav, &p);
+ break;
+ case NAVIT_KEY_DOWN:
+ p.x=w/2;
+ p.y=h;
+ navit_set_center_screen(this->nav, &p);
+ break;
+ case NAVIT_KEY_LEFT:
+ p.x=0;
+ p.y=h/2;
+ navit_set_center_screen(this->nav, &p);
+ break;
+ case NAVIT_KEY_RIGHT:
+ p.x=w;
+ p.y=h/2;
+ navit_set_center_screen(this->nav, &p);
+ break;
+ case NAVIT_KEY_ZOOM_IN:
+ navit_zoom_in(this->nav, 2, NULL);
+ break;
+ case NAVIT_KEY_ZOOM_OUT:
+ navit_zoom_out(this->nav, 2, NULL);
+ break;
+ default:
+ dbg(0,"key=%d\n", key);
+ }
+}
+
//##############################################################################################################
//# Description:
graphics_register_resize_callback(gra, gui_internal_resize, this);
graphics_register_button_callback(gra, gui_internal_button, this);
graphics_register_motion_callback(gra, gui_internal_motion, this);
+ graphics_register_keypress_callback(gra, gui_internal_keypress, this);
this->background=graphics_gc_new(gra);
graphics_gc_set_foreground(this->background, &cb);
this->background2=graphics_gc_new(gra);