@@ -46,6 +46,7 @@ int main(int argc, char **argv) | |||
new DebugFps(); | |||
glmapview->LoadMap("maps/testmap.tmx"); | |||
glmapview->SetFocus(); | |||
gtk_main(); | |||
@@ -23,8 +23,8 @@ | |||
<child> | |||
<object class="GtkImageMenuItem" id="imagemenuitem1"> | |||
<property name="visible">True</property> | |||
<property name="use_action_appearance">True</property> | |||
<property name="related_action">action_new</property> | |||
<property name="use_action_appearance">True</property> | |||
<property name="use_underline">True</property> | |||
<property name="use_stock">True</property> | |||
</object> | |||
@@ -32,8 +32,8 @@ | |||
<child> | |||
<object class="GtkImageMenuItem" id="imagemenuitem2"> | |||
<property name="visible">True</property> | |||
<property name="use_action_appearance">True</property> | |||
<property name="related_action">action_open</property> | |||
<property name="use_action_appearance">True</property> | |||
<property name="use_underline">True</property> | |||
<property name="use_stock">True</property> | |||
</object> | |||
@@ -158,8 +158,8 @@ | |||
<child> | |||
<object class="GtkToolButton" id="toolbutton2"> | |||
<property name="visible">True</property> | |||
<property name="use_action_appearance">True</property> | |||
<property name="related_action">action_new</property> | |||
<property name="use_action_appearance">True</property> | |||
<property name="label" translatable="yes">toolbutton</property> | |||
<property name="use_underline">True</property> | |||
</object> | |||
@@ -171,8 +171,8 @@ | |||
<child> | |||
<object class="GtkToolButton" id="toolbutton1"> | |||
<property name="visible">True</property> | |||
<property name="use_action_appearance">True</property> | |||
<property name="related_action">action_open</property> | |||
<property name="use_action_appearance">True</property> | |||
<property name="label" translatable="yes">Open...</property> | |||
<property name="use_underline">True</property> | |||
</object> | |||
@@ -184,8 +184,8 @@ | |||
<child> | |||
<object class="GtkToolButton" id="toolbutton4"> | |||
<property name="visible">True</property> | |||
<property name="use_action_appearance">True</property> | |||
<property name="related_action">action_save</property> | |||
<property name="use_action_appearance">True</property> | |||
<property name="label" translatable="yes">Save</property> | |||
<property name="use_underline">True</property> | |||
</object> | |||
@@ -345,9 +345,11 @@ | |||
</object> | |||
<object class="GtkAction" id="action_new"> | |||
<property name="stock_id">gtk-new</property> | |||
<property name="always_show_image">True</property> | |||
</object> | |||
<object class="GtkAction" id="action_save"> | |||
<property name="label">Save</property> | |||
<property name="stock_id">gtk-save</property> | |||
<property name="always_show_image">True</property> | |||
</object> | |||
</interface> |
@@ -9,6 +9,7 @@ | |||
#include <gtk/gtk.h> | |||
#include <gtkgl/gtkglarea.h> | |||
#include <gdk/gdkkeysyms.h> | |||
#include "core.h" | |||
#include "glmapview.h" | |||
@@ -39,6 +40,8 @@ GlMapView::GlMapView(GtkBuilder *builder) | |||
GDK_POINTER_MOTION_MASK | | |||
GDK_BUTTON_PRESS_MASK | | |||
GDK_BUTTON_RELEASE_MASK); | |||
gtk_widget_set_can_focus(glarea, TRUE); | |||
GtkContainer *cont = GTK_CONTAINER(gtk_builder_get_object(builder, | |||
"gl_container")); | |||
gtk_container_add(cont, glarea); | |||
@@ -63,6 +66,9 @@ GlMapView::GlMapView(GtkBuilder *builder) | |||
GTK_SIGNAL_FUNC(MouseButtonSignal), this); | |||
gtk_signal_connect(GTK_OBJECT(glarea), "motion_notify_event", | |||
GTK_SIGNAL_FUNC(MouseMotionSignal), this); | |||
gtk_signal_connect(GTK_OBJECT(glarea), "key_press_event", | |||
GTK_SIGNAL_FUNC(KeyPressSignal), this); | |||
} | |||
void GlMapView::LoadMap(char const *path) | |||
@@ -73,6 +79,11 @@ void GlMapView::LoadMap(char const *path) | |||
UpdateAdjustments(); | |||
} | |||
void GlMapView::SetFocus() | |||
{ | |||
gtk_widget_grab_focus(glarea); | |||
} | |||
gboolean GlMapView::IdleTick() | |||
{ | |||
// FIXME: do not do anything if the previous tick was too recent? | |||
@@ -162,6 +173,19 @@ gboolean GlMapView::UpdateAdjustments() | |||
return TRUE; | |||
} | |||
gboolean GlMapView::MoveAdjustments(double dx, double dy) | |||
{ | |||
if (dx) | |||
gtk_adjustment_set_value(hadj, gtk_adjustment_get_value(hadj) + dx); | |||
if (dy) | |||
gtk_adjustment_set_value(vadj, gtk_adjustment_get_value(vadj) + dy); | |||
UpdateAdjustments(); | |||
return TRUE; | |||
} | |||
gboolean GlMapView::MouseButton(GdkEventButton *event) | |||
{ | |||
if (event->type == GDK_BUTTON_PRESS && event->button == 2) | |||
@@ -216,6 +240,20 @@ gboolean GlMapView::MouseMotion(GdkEventMotion *event) | |||
return TRUE; | |||
} | |||
gboolean GlMapView::KeyPress(GdkEventKey *event) | |||
{ | |||
switch (event->keyval) | |||
{ | |||
case GDK_Up: MoveAdjustments( 0.0, -10.0); break; | |||
case GDK_Down: MoveAdjustments( 0.0, 10.0); break; | |||
case GDK_Left: MoveAdjustments(-10.0, 0.0); break; | |||
case GDK_Right: MoveAdjustments( 10.0, 0.0); break; | |||
default: return FALSE; | |||
} | |||
return TRUE; | |||
} | |||
/* Private signal slots */ | |||
gboolean GlMapView::IdleTickSignal(GlMapView *that) | |||
{ | |||
@@ -263,3 +301,10 @@ gboolean GlMapView::MouseMotionSignal(GtkWidget *w, GdkEventMotion *event, | |||
return that->MouseMotion(event); | |||
} | |||
gboolean GlMapView::KeyPressSignal(GtkWidget *w, GdkEventKey *event, | |||
GlMapView *that) | |||
{ | |||
(void)w; | |||
return that->KeyPress(event); | |||
} | |||
@@ -13,6 +13,7 @@ class GlMapView | |||
public: | |||
GlMapView(GtkBuilder *builder); | |||
void LoadMap(char const *path); | |||
void SetFocus(); | |||
private: | |||
/* Private methods */ | |||
@@ -21,8 +22,10 @@ private: | |||
gboolean Destroy(); | |||
gboolean Draw(GdkEventExpose *event); | |||
gboolean UpdateAdjustments(); | |||
gboolean MoveAdjustments(double dx, double dy); | |||
gboolean MouseButton(GdkEventButton *event); | |||
gboolean MouseMotion(GdkEventMotion *event); | |||
gboolean KeyPress(GdkEventKey *event); | |||
/* Private signal slots */ | |||
static gboolean IdleTickSignal(GlMapView *that); | |||
@@ -36,6 +39,8 @@ private: | |||
GlMapView *that); | |||
static gboolean MouseMotionSignal(GtkWidget *w, GdkEventMotion *event, | |||
GlMapView *that); | |||
static gboolean KeyPressSignal(GtkWidget *w, GdkEventKey *event, | |||
GlMapView *that); | |||
private: | |||
GtkAdjustment *hadj, *vadj; | |||