Browse Source

Add an about dialogue and fix an initialisation bug in the map viewer

scrollbar handling.
legacy
Sam Hocevar sam 14 years ago
parent
commit
11305698a3
4 changed files with 77 additions and 30 deletions
  1. +1
    -1
      src/gtk/editor.cpp
  2. +39
    -1
      src/gtk/editor.xml
  3. +36
    -28
      src/gtk/glmapview.cpp
  4. +1
    -0
      src/gtk/glmapview.h

+ 1
- 1
src/gtk/editor.cpp View File

@@ -41,7 +41,7 @@ int main(int argc, char **argv)
GlMapView *glmapview = new GlMapView(builder);

/* Show window. We're good to go! */
gtk_widget_show_all(GTK_WIDGET(gtk_builder_get_object(builder, "window1")));
gtk_widget_show_all(GTK_WIDGET(gtk_builder_get_object(builder, "window")));
g_object_unref(G_OBJECT(builder));

new DebugFps();


+ 39
- 1
src/gtk/editor.xml View File

@@ -2,7 +2,7 @@
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="window1">
<object class="GtkWindow" id="window">
<property name="title" translatable="yes">Deus Hax Editor</property>
<signal name="delete_event" handler="gtk_main_quit"/>
<child>
@@ -63,6 +63,8 @@
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
<signal name="activate" handler="gtk_main_quit"/>
</object>
</child>
</object>
@@ -134,6 +136,8 @@
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
<signal name="activate" handler="gtk_widget_show" object="aboutdialog"/>
</object>
</child>
</object>
@@ -244,4 +248,38 @@
<property name="page_increment">10</property>
<property name="page_size">10</property>
</object>
<object class="GtkAboutDialog" id="aboutdialog">
<property name="border_width">5</property>
<property name="modal">True</property>
<property name="window_position">center</property>
<property name="type_hint">normal</property>
<property name="program_name">Deus Hax Editor</property>
<property name="copyright" translatable="yes">&#xA9; 2010 Sam Hocevar &lt;sam@hocevar.net&gt;</property>
<property name="website">http://deushax.zoy.org/</property>
<signal name="close" handler="gtk_widget_hide" object="aboutdialog"/>
<signal name="response" handler="gtk_widget_hide" object="aboutdialog"/>
<signal name="delete_event" handler="gtk_widget_hide" object="aboutdialog"/>
<signal name="delete_event" handler="gtk_true"/>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<placeholder/>
</child>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="layout_style">end</property>
</object>
<packing>
<property name="expand">False</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

+ 36
- 28
src/gtk/glmapview.cpp View File

@@ -69,12 +69,13 @@ void GlMapView::LoadMap(char const *path)
{
// FIXME: detect when the map viewer is killed
mapviewer = new MapViewer(path);

UpdateAdjustments();
}

gboolean GlMapView::IdleTick()
{
// FIXME: do not do anything if the previous tick was too recent?

ticking = TRUE;

if (mapviewer)
@@ -91,37 +92,12 @@ gboolean GlMapView::IdleTick()

gboolean GlMapView::Setup()
{
if (mapviewer)
{
/* Manage adjustments */
struct { GtkAdjustment *adj; float map_size, sw_size; } s[2] =
{
{ hadj, mapviewer->GetWidth(), glarea->allocation.width },
{ vadj, mapviewer->GetHeight(), glarea->allocation.height },
};

for (int i = 0; i < 2; i++)
{
gtk_adjustment_set_lower(s[i].adj, 0);
gtk_adjustment_set_upper(s[i].adj, s[i].map_size);
gtk_adjustment_set_step_increment(s[i].adj, 1);
gtk_adjustment_set_page_increment(s[i].adj, s[i].sw_size);
gtk_adjustment_set_page_size(s[i].adj, s[i].sw_size);

float val = gtk_adjustment_get_value(s[i].adj);
if (val + s[i].sw_size > s[i].map_size)
{
gtk_adjustment_set_value(s[i].adj,
s[i].map_size - s[i].sw_size);
gtk_adjustment_value_changed(s[i].adj);
}
}
}

/* Set up display */
if (gtk_gl_area_make_current(GTK_GL_AREA(glarea)))
Video::Setup(glarea->allocation.width, glarea->allocation.height);

UpdateAdjustments();

return TRUE;
}

@@ -154,6 +130,38 @@ gboolean GlMapView::Draw(GdkEventExpose *event)
return TRUE;
}

gboolean GlMapView::UpdateAdjustments()
{
float w = mapviewer ? mapviewer->GetWidth() : glarea->allocation.width;
float h = mapviewer ? mapviewer->GetHeight() : glarea->allocation.height;

/* Manage adjustments */
struct { GtkAdjustment *adj; float map_size, sw_size; } s[2] =
{
{ hadj, w, glarea->allocation.width },
{ vadj, h, glarea->allocation.height },
};

for (int i = 0; i < 2; i++)
{
gtk_adjustment_set_lower(s[i].adj, 0);
gtk_adjustment_set_upper(s[i].adj, s[i].map_size);
gtk_adjustment_set_step_increment(s[i].adj, 1);
gtk_adjustment_set_page_increment(s[i].adj, s[i].sw_size);
gtk_adjustment_set_page_size(s[i].adj, s[i].sw_size);

float val = gtk_adjustment_get_value(s[i].adj);
if (val + s[i].sw_size > s[i].map_size)
{
gtk_adjustment_set_value(s[i].adj,
s[i].map_size - s[i].sw_size);
gtk_adjustment_value_changed(s[i].adj);
}
}

return TRUE;
}

gboolean GlMapView::MouseButton(GdkEventButton *event)
{
if (event->type == GDK_BUTTON_PRESS && event->button == 2)


+ 1
- 0
src/gtk/glmapview.h View File

@@ -20,6 +20,7 @@ private:
gboolean Setup();
gboolean Destroy();
gboolean Draw(GdkEventExpose *event);
gboolean UpdateAdjustments();
gboolean MouseButton(GdkEventButton *event);
gboolean MouseMotion(GdkEventMotion *event);



Loading…
Cancel
Save