[four-in-a-row/arnaudb/new-ui: 4/12] Add Unfullscreen button.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [four-in-a-row/arnaudb/new-ui: 4/12] Add Unfullscreen button.
- Date: Thu, 19 Dec 2019 19:50:14 +0000 (UTC)
commit 70fa3c60ea0617c91f47727deb4f8abc60807af2
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Mon Dec 16 03:00:39 2019 +0100
Add Unfullscreen button.
data/four-in-a-row.css | 26 ++++++++
data/ui/four-in-a-row.ui | 137 ++++++++++++++++++++++++----------------
src/four-in-a-row.gresource.xml | 1 +
src/four-in-a-row.vala | 70 ++++++++++++++------
4 files changed, 157 insertions(+), 77 deletions(-)
---
diff --git a/data/four-in-a-row.css b/data/four-in-a-row.css
new file mode 100644
index 0000000..7072288
--- /dev/null
+++ b/data/four-in-a-row.css
@@ -0,0 +1,26 @@
+/*
+ This file is part of GNOME Four-in-a-row.
+
+ Copyright © 2019 Arnaud Bonatti
+
+ GNOME Four-in-a-row is free software: you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ GNOME Four-in-a-row is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with GNOME Four-in-a-row. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+button.unfullscreen-button {
+ margin:6px;
+}
+
+GtkButtonBox {
+ -GtkButtonBox-child-internal-pad-x:0;
+}
diff --git a/data/ui/four-in-a-row.ui b/data/ui/four-in-a-row.ui
index 7a37328..80dfa4d 100644
--- a/data/ui/four-in-a-row.ui
+++ b/data/ui/four-in-a-row.ui
@@ -19,7 +19,6 @@
<requires lib="gtk+" version="3.12"/>
<object class="GtkApplicationWindow" id="fiar-window">
<property name="can-focus">False</property>
- <property name="border-width">25</property>
<property name="title" translatable="yes">Four-in-a-row</property>
<child type="titlebar">
<object class="GtkHeaderBar" id="headerbar">
@@ -73,88 +72,114 @@
</object>
</child>
<child>
- <object class="GtkAspectFrame">
+ <object class="GtkOverlay">
<property name="visible">True</property>
- <property name="can-focus">False</property>
- <property name="label-xalign">0</property>
- <property name="shadow-type">none</property>
- <property name="ratio">1.3999999761581421</property>
- <property name="obey-child">False</property>
<child>
- <object class="GtkBox">
+ <object class="GtkAspectFrame">
<property name="visible">True</property>
<property name="can-focus">False</property>
- <property name="spacing">25</property>
+ <property name="label-xalign">0</property>
+ <property name="shadow-type">none</property>
+ <property name="ratio">1.3999999761581421</property>
+ <property name="obey-child">False</property>
+ <property name="border-width">25</property>
<child>
- <object class="GtkAspectFrame" id="frame">
+ <object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
- <property name="label-xalign">0</property>
- <property name="shadow-type">none</property>
- <property name="obey-child">False</property>
+ <property name="spacing">25</property>
<child>
- <placeholder/>
- </child>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkButtonBox">
- <property name="visible">True</property>
- <property name="can-focus">False</property>
- <property name="valign">end</property>
- <property name="orientation">vertical</property>
- <property name="spacing">6</property>
- <child>
- <object class="GtkButton">
- <property name="label" translatable="yes">_Hint</property>
- <property name="width-request">120</property>
- <property name="height-request">60</property>
+ <object class="GtkAspectFrame" id="frame">
<property name="visible">True</property>
<property name="can-focus">False</property>
- <property name="receives-default">False</property>
- <property name="tooltip-text" translatable="yes">Receive a hint for your next
move</property>
- <property name="valign">center</property>
- <property name="action-name">app.hint</property>
- <property name="use-underline">True</property>
+ <property name="label-xalign">0</property>
+ <property name="shadow-type">none</property>
+ <property name="obey-child">False</property>
+ <child>
+ <placeholder/>
+ </child>
</object>
<packing>
- <property name="expand">False</property>
+ <property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
- <object class="GtkButton">
- <property name="label" translatable="yes">_Start Over</property>
- <property name="width-request">120</property>
- <property name="height-request">60</property>
+ <object class="GtkButtonBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
- <property name="receives-default">False</property>
- <property name="tooltip-text" translatable="yes">Start a new game</property>
- <property name="valign">center</property>
- <property name="action-name">app.new-game</property>
- <property name="use-underline">True</property>
+ <property name="valign">end</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkButton">
+ <property name="label" translatable="yes">_Hint</property>
+ <property name="width-request">120</property>
+ <property name="height-request">60</property>
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="receives-default">False</property>
+ <property name="tooltip-text" translatable="yes">Receive a hint for your next
move</property>
+ <property name="valign">center</property>
+ <property name="action-name">app.hint</property>
+ <property name="use-underline">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton">
+ <property name="label" translatable="yes">_Start Over</property>
+ <property name="width-request">120</property>
+ <property name="height-request">60</property>
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="receives-default">False</property>
+ <property name="tooltip-text" translatable="yes">Start a new game</property>
+ <property name="valign">center</property>
+ <property name="action-name">app.new-game</property>
+ <property name="use-underline">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="pack-type">end</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
- <property name="fill">False</property>
+ <property name="fill">True</property>
<property name="pack-type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="pack-type">end</property>
- <property name="position">1</property>
- </packing>
+ </child>
+ </object>
+ </child>
+ <child type="overlay">
+ <object class="GtkButton" id="unfullscreen_button">
+ <property name="visible">False</property>
+ <property name="halign">end</property>
+ <property name="valign">start</property>
+ <property name="action-name">app.unfullscreen</property>
+ <style>
+ <class name="image-button"/>
+ <class name="unfullscreen-button"/>
+ <class name="flat"/>
+ </style>
+ <child>
+ <object class="GtkImage">
+ <property name="icon-name">view-restore-symbolic</property>
+ <property name="visible">True</property>
+ <property name="icon-size">1</property>
+ </object>
</child>
</object>
</child>
diff --git a/src/four-in-a-row.gresource.xml b/src/four-in-a-row.gresource.xml
index ed6911a..a574494 100644
--- a/src/four-in-a-row.gresource.xml
+++ b/src/four-in-a-row.gresource.xml
@@ -9,6 +9,7 @@
<file alias="bg_toplight.png">../data/bg_toplight.png</file>
</gresource>
<gresource prefix="/org/gnome/Four-in-a-row/ui">
+ <file alias="four-in-a-row.css">../data/four-in-a-row.css</file>
<file preprocess="xml-stripblanks" compressed="true"
alias="four-in-a-row.ui">../data/ui/four-in-a-row.ui</file>
</gresource>
</gresources>
diff --git a/src/four-in-a-row.vala b/src/four-in-a-row.vala
index 84a0f33..a19aaf9 100644
--- a/src/four-in-a-row.vala
+++ b/src/four-in-a-row.vala
@@ -52,32 +52,42 @@ private class FourInARow : Gtk.Application
HINT
}
+ // actions
private SimpleAction hint_action;
private SimpleAction undo_action;
private SimpleAction new_game_action;
+
+ // game status
private bool gameover;
private bool player_active;
private PlayerID player;
private PlayerID winner;
internal PlayerID who_starts;
- private PrefsBox? prefsbox = null;
- private Scorebox scorebox;
- private GameBoardView game_board_view;
- private Board game_board;
- private ApplicationWindow window;
/**
* score:
*
* The scores for the current instance (Player 1, Player 2, Draw)
*/
private int score [3];
- private static AnimID anim;
+
+ // widgets
+ private PrefsBox? prefsbox = null;
+ private Scorebox scorebox;
+ private GameBoardView game_board_view;
+ private Board game_board;
+ private ApplicationWindow window;
+ private Button unfullscreen_button;
+
+ // game state
private char vstr [53];
private int moves;
private int column;
private int column_moveto;
private int row;
private int row_dropto;
+
+ // animation
+ private static AnimID anim;
private int blink_r1 = 0;
private int blink_c1 = 0;
private int blink_r2 = 0;
@@ -89,11 +99,12 @@ private class FourInARow : Gtk.Application
private const GLib.ActionEntry app_entries [] = // see also add_actions()
{
- { "scores", on_game_scores },
- { "quit", on_game_exit },
- { "preferences", on_settings_preferences },
- { "help", on_help_contents },
- { "about", on_help_about }
+ { "unfullscreen", on_unfullscreen },
+ { "scores", on_game_scores },
+ { "quit", on_game_exit },
+ { "preferences", on_settings_preferences },
+ { "help", on_help_contents },
+ { "about", on_help_about }
};
internal void game_reset ()
@@ -247,7 +258,7 @@ private class FourInARow : Gtk.Application
if (window.is_visible ())
return;
- window.show_all ();
+ window.show ();
game_board_view.refresh_pixmaps ();
game_board_view.queue_draw ();
scorebox.update (score); /* update visible player descriptions */
@@ -541,6 +552,24 @@ private class FourInARow : Gtk.Application
return;
}
+ private bool window_is_fullscreen = false;
+ private bool window_state_event_cb (Gdk.EventWindowState event)
+ {
+ bool window_was_fullscreen = window_is_fullscreen;
+ if ((event.changed_mask & Gdk.WindowState.FULLSCREEN) != 0)
+ window_is_fullscreen = (event.new_window_state & Gdk.WindowState.FULLSCREEN) != 0;
+ if (window_was_fullscreen && !window_is_fullscreen)
+ unfullscreen_button.hide ();
+ else if (!window_was_fullscreen && window_is_fullscreen)
+ unfullscreen_button.show ();
+ return false;
+ }
+
+ private inline void on_unfullscreen (/* SimpleAction action, Variant? parameter */)
+ {
+ window.unfullscreen ();
+ }
+
private inline void on_game_exit (/* SimpleAction action, Variant? parameter */)
{
stop_anim ();
@@ -734,22 +763,21 @@ private class FourInARow : Gtk.Application
base.startup ();
CssProvider css_provider = new CssProvider ();
- try {
- css_provider.load_from_data ("GtkButtonBox {-GtkButtonBox-child-internal-pad-x:0;}\0");
- } catch (Error error) {
- stderr.printf ("Could not load UI: %s\n", error.message);
- return;
- }
- StyleContext.add_provider_for_screen (Gdk.Screen.get_default (),
- css_provider,
- STYLE_PROVIDER_PRIORITY_APPLICATION);
+ css_provider.load_from_resource ("/org/gnome/Four-in-a-row/ui/four-in-a-row.css");
+ Gdk.Screen? gdk_screen = Gdk.Screen.get_default ();
+ if (gdk_screen != null) // else..?
+ StyleContext.add_provider_for_screen ((!) gdk_screen, css_provider,
STYLE_PROVIDER_PRIORITY_APPLICATION);
+
game_board_view = new GameBoardView (game_board);
+ game_board_view.show ();
Builder builder = new Builder.from_resource ("/org/gnome/Four-in-a-row/ui/four-in-a-row.ui");
window = (ApplicationWindow) builder.get_object ("fiar-window");
window.application = this;
+ window.window_state_event.connect (window_state_event_cb);
window.set_default_size (DEFAULT_WIDTH, DEFAULT_HEIGHT); /* TODO save size & state */
+ unfullscreen_button = (Button) builder.get_object ("unfullscreen_button");
headerbar = (HeaderBar) builder.get_object ("headerbar");
scorebox = new Scorebox (window, this);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]