Changeset 166


Ignore:
Timestamp:
Aug 22, 2010, 7:52:11 PM (10 years ago)
Author:
sam
Message:

Keyboard scrolling in the editor.

Location:
trunk/src/gtk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gtk/editor.cpp

    r163 r166  
    4747    new DebugFps();
    4848    glmapview->LoadMap("maps/testmap.tmx");
     49    glmapview->SetFocus();
    4950
    5051    gtk_main();
  • trunk/src/gtk/editor.xml

    r165 r166  
    2424                      <object class="GtkImageMenuItem" id="imagemenuitem1">
    2525                        <property name="visible">True</property>
     26                        <property name="related_action">action_new</property>
    2627                        <property name="use_action_appearance">True</property>
    27                         <property name="related_action">action_new</property>
    2828                        <property name="use_underline">True</property>
    2929                        <property name="use_stock">True</property>
     
    3333                      <object class="GtkImageMenuItem" id="imagemenuitem2">
    3434                        <property name="visible">True</property>
     35                        <property name="related_action">action_open</property>
    3536                        <property name="use_action_appearance">True</property>
    36                         <property name="related_action">action_open</property>
    3737                        <property name="use_underline">True</property>
    3838                        <property name="use_stock">True</property>
     
    159159              <object class="GtkToolButton" id="toolbutton2">
    160160                <property name="visible">True</property>
     161                <property name="related_action">action_new</property>
    161162                <property name="use_action_appearance">True</property>
    162                 <property name="related_action">action_new</property>
    163163                <property name="label" translatable="yes">toolbutton</property>
    164164                <property name="use_underline">True</property>
     
    172172              <object class="GtkToolButton" id="toolbutton1">
    173173                <property name="visible">True</property>
     174                <property name="related_action">action_open</property>
    174175                <property name="use_action_appearance">True</property>
    175                 <property name="related_action">action_open</property>
    176176                <property name="label" translatable="yes">Open...</property>
    177177                <property name="use_underline">True</property>
     
    185185              <object class="GtkToolButton" id="toolbutton4">
    186186                <property name="visible">True</property>
     187                <property name="related_action">action_save</property>
    187188                <property name="use_action_appearance">True</property>
    188                 <property name="related_action">action_save</property>
    189189                <property name="label" translatable="yes">Save</property>
    190190                <property name="use_underline">True</property>
     
    346346  <object class="GtkAction" id="action_new">
    347347    <property name="stock_id">gtk-new</property>
     348    <property name="always_show_image">True</property>
    348349  </object>
    349350  <object class="GtkAction" id="action_save">
    350351    <property name="label">Save</property>
    351352    <property name="stock_id">gtk-save</property>
     353    <property name="always_show_image">True</property>
    352354  </object>
    353355</interface>
  • trunk/src/gtk/glmapview.cpp

    r163 r166  
    1010#include <gtk/gtk.h>
    1111#include <gtkgl/gtkglarea.h>
     12#include <gdk/gdkkeysyms.h>
    1213
    1314#include "core.h"
     
    4041                                  GDK_BUTTON_PRESS_MASK |
    4142                                  GDK_BUTTON_RELEASE_MASK);
     43    gtk_widget_set_can_focus(glarea, TRUE);
     44
    4245    GtkContainer *cont = GTK_CONTAINER(gtk_builder_get_object(builder,
    4346                                                              "gl_container"));
     
    6467    gtk_signal_connect(GTK_OBJECT(glarea), "motion_notify_event",
    6568                       GTK_SIGNAL_FUNC(MouseMotionSignal), this);
     69
     70    gtk_signal_connect(GTK_OBJECT(glarea), "key_press_event",
     71                       GTK_SIGNAL_FUNC(KeyPressSignal), this);
    6672}
    6773
     
    7278
    7379    UpdateAdjustments();
     80}
     81
     82void GlMapView::SetFocus()
     83{
     84    gtk_widget_grab_focus(glarea);
    7485}
    7586
     
    159170        }
    160171    }
     172
     173    return TRUE;
     174}
     175
     176gboolean GlMapView::MoveAdjustments(double dx, double dy)
     177{
     178    if (dx)
     179        gtk_adjustment_set_value(hadj, gtk_adjustment_get_value(hadj) + dx);
     180
     181    if (dy)
     182        gtk_adjustment_set_value(vadj, gtk_adjustment_get_value(vadj) + dy);
     183
     184    UpdateAdjustments();
    161185
    162186    return TRUE;
     
    217241}
    218242
     243gboolean GlMapView::KeyPress(GdkEventKey *event)
     244{
     245    switch (event->keyval)
     246    {
     247    case GDK_Up:    MoveAdjustments(  0.0, -10.0); break;
     248    case GDK_Down:  MoveAdjustments(  0.0,  10.0); break;
     249    case GDK_Left:  MoveAdjustments(-10.0,  0.0); break;
     250    case GDK_Right: MoveAdjustments( 10.0,  0.0); break;
     251    default: return FALSE;
     252    }
     253
     254    return TRUE;
     255}
     256
    219257/* Private signal slots */
    220258gboolean GlMapView::IdleTickSignal(GlMapView *that)
     
    264302}
    265303
     304gboolean GlMapView::KeyPressSignal(GtkWidget *w, GdkEventKey *event,
     305                                   GlMapView *that)
     306{
     307    (void)w;
     308    return that->KeyPress(event);
     309}
     310
  • trunk/src/gtk/glmapview.h

    r163 r166  
    1414    GlMapView(GtkBuilder *builder);
    1515    void LoadMap(char const *path);
     16    void SetFocus();
    1617
    1718private:
     
    2223    gboolean Draw(GdkEventExpose *event);
    2324    gboolean UpdateAdjustments();
     25    gboolean MoveAdjustments(double dx, double dy);
    2426    gboolean MouseButton(GdkEventButton *event);
    2527    gboolean MouseMotion(GdkEventMotion *event);
     28    gboolean KeyPress(GdkEventKey *event);
    2629
    2730    /* Private signal slots */
     
    3740    static gboolean MouseMotionSignal(GtkWidget *w, GdkEventMotion *event,
    3841                                      GlMapView *that);
     42    static gboolean KeyPressSignal(GtkWidget *w, GdkEventKey *event,
     43                                   GlMapView *that);
    3944
    4045private:
Note: See TracChangeset for help on using the changeset viewer.