[swell-foop] Support window resizing
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [swell-foop] Support window resizing
- Date: Fri, 5 Feb 2021 18:20:27 +0000 (UTC)
commit 10759b3edbb6b249576702886b6146bf29a2c4f8
Author: Robert Mibus <mibus mibus org>
Date: Fri Jan 29 20:56:58 2021 +1100
Support window resizing
Fixes #1
data/ui/swell-foop.ui | 2 +-
src/game-view.vala | 28 ++++++++++++++++++++++++++--
2 files changed, 27 insertions(+), 3 deletions(-)
---
diff --git a/data/ui/swell-foop.ui b/data/ui/swell-foop.ui
index f7a3f20..b99a037 100644
--- a/data/ui/swell-foop.ui
+++ b/data/ui/swell-foop.ui
@@ -135,7 +135,7 @@
</menu>
<requires lib="gtk+" version="3.12"/>
<template class="SwellFoopWindow" parent="GtkApplicationWindow">
- <property name="resizable">False</property>
+ <property name="resizable">True</property>
<property name="icon-name">org.gnome.SwellFoop</property>
<!-- Translators: title of the window displayed by window managers; name of the application -->
<property name="title" translatable="yes">Swell Foop</property>
diff --git a/src/game-view.vala b/src/game-view.vala
index 69b50b8..e388be3 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -32,12 +32,36 @@ private class GameView : GtkClutter.Embed
/* Request an appropriate size for the game view */
init_size ();
+
+ /* Window resizes should trigger view scaling updates */
+ this.configure_event.connect(configure_event_cb);
}
private void init_size ()
{
- stage.set_size (group.width, group.height);
- set_size_request ((int) stage.width, (int) stage.height);
+ // Force the clutter widget to have a minimum size of the Game View's
+ // size (this will be based on the tile size and arrangement).
+ set_size_request ((int) group.width, (int) group.height);
+
+ // Work out what the largest scale factor we can use is, to fit within
+ // the window.
+ var w_scale = stage.width / group.width;
+ var h_scale = stage.height / group.height;
+ var scale = w_scale < h_scale ? w_scale : h_scale;
+
+ // Set the view to that scale, and move the view within the clutter
+ // widget to match (creating implicit black borders for windows that
+ // aren't perfectly shaped for the board.
+ group.set_scale(scale, scale);
+ group.set_position(
+ (stage.width - scale * group.width) / 2,
+ (stage.height - scale * group.height) / 2);
+ }
+
+ private bool configure_event_cb (Gtk.Widget widget, Gdk.Event event)
+ {
+ init_size ();
+ return false;
}
/*\
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]