[four-in-a-row: 11/13] Introduce HistoryButton.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [four-in-a-row: 11/13] Introduce HistoryButton.
- Date: Fri, 20 Dec 2019 17:45:13 +0000 (UTC)
commit f6be096aa5bd9085e92b5c5a53fd614fbb9c2868
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Dec 19 18:50:31 2019 +0100
Introduce HistoryButton.
data/ui/four-in-a-row.ui | 34 --------------------------------
data/ui/history-button.ui | 43 +++++++++++++++++++++++++++++++++++++++++
po/POTFILES.in | 2 ++
po/POTFILES.skip | 1 +
src/four-in-a-row.gresource.xml | 1 +
src/four-in-a-row.vala | 5 ++++-
src/game-window.vala | 17 ++++++++++++----
src/history-button.vala | 35 +++++++++++++++++++++++++++++++++
src/meson.build | 1 +
9 files changed, 100 insertions(+), 39 deletions(-)
---
diff --git a/data/ui/four-in-a-row.ui b/data/ui/four-in-a-row.ui
index f480687..5d4d4df 100644
--- a/data/ui/four-in-a-row.ui
+++ b/data/ui/four-in-a-row.ui
@@ -17,20 +17,6 @@
-->
<interface>
<requires lib="gtk+" version="3.12"/>
- <menu id="game-menu">
- <section>
- <item>
- <!-- Translators: during a game, entry in the game menu, for undoing the last move -->
- <attribute name="label" translatable="yes">_Undo last move</attribute>
- <attribute name="action">ui.undo</attribute>
- </item>
- <item>
- <!-- Translators: during a game, entry in the game menu, for suggesting where to play -->
- <attribute name="label" translatable="yes">_Hint</attribute>
- <attribute name="action">ui.hint</attribute>
- </item>
- </section>
- </menu>
<template class="GameWindow" parent="AdaptativeWindow">
<!-- <initial-focus name="view"/> -->
<child type="titlebar">
@@ -80,26 +66,6 @@
<property name="position">1</property>
</packing>
</child>
- <child>
- <object class="GtkMenuButton" id="game_button">
- <property name="visible">True</property>
- <property name="valign">center</property>
- <property name="can-focus">True</property>
- <property name="focus-on-click">False</property>
- <property name="menu-model">game-menu</property>
- <child>
- <object class="GtkImage">
- <property name="visible">True</property>
- <property name="icon-name">pan-down-symbolic</property>
- <property name="icon-size">1</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="pack-type">end</property>
- <property name="position">1</property>
- </packing>
- </child>
<child>
<object class="GtkMenuButton" id="info_button">
<property name="visible">True</property>
diff --git a/data/ui/history-button.ui b/data/ui/history-button.ui
new file mode 100644
index 0000000..0cefaf2
--- /dev/null
+++ b/data/ui/history-button.ui
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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/>.
+-->
+<interface>
+ <requires lib="gtk+" version="3.12"/>
+ <menu id="game-menu">
+ <section>
+ <item>
+ <!-- Translators: during a game, entry in the game menu, for undoing the last move -->
+ <attribute name="label" translatable="yes">_Undo last move</attribute>
+ <attribute name="action">ui.undo</attribute>
+ </item>
+ <item>
+ <!-- Translators: during a game, entry in the game menu, for suggesting where to play -->
+ <attribute name="label" translatable="yes">_Hint</attribute>
+ <attribute name="action">ui.hint</attribute>
+ </item>
+ </section>
+ </menu>
+ <template class="HistoryButton" parent="GtkMenuButton">
+ <property name="visible">True</property>
+ <property name="valign">center</property>
+ <property name="can-focus">True</property>
+ <property name="focus-on-click">False</property>
+ <property name="menu-model">game-menu</property>
+ </template>
+</interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3301afb..59d9c91 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,10 +2,12 @@
# Please keep this file in alphabetical order.
data/ui/fiar-screens.ui
data/ui/four-in-a-row.ui
+data/ui/history-button.ui
data/org.gnome.Four-in-a-row.appdata.xml.in
data/org.gnome.Four-in-a-row.desktop.in
data/org.gnome.Four-in-a-row.gschema.xml
src/four-in-a-row.vala
+src/history-button.vala
src/new-game-screen.vala
src/prefs.vala
src/scorebox.vala
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index d86310f..6e480b8 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -1,4 +1,5 @@
src/four-in-a-row.c
+src/history-button.c
src/new-game-screen.c
src/prefs.c
src/scorebox.c
diff --git a/src/four-in-a-row.gresource.xml b/src/four-in-a-row.gresource.xml
index 2143cd1..d6739c3 100644
--- a/src/four-in-a-row.gresource.xml
+++ b/src/four-in-a-row.gresource.xml
@@ -13,5 +13,6 @@
<file preprocess="xml-stripblanks" compressed="true"
alias="adaptative-window.ui">../data/ui/adaptative-window.ui</file>
<file preprocess="xml-stripblanks" compressed="true"
alias="fiar-screens.ui">../data/ui/fiar-screens.ui</file>
<file preprocess="xml-stripblanks" compressed="true"
alias="game-window.ui">../data/ui/four-in-a-row.ui</file>
+ <file preprocess="xml-stripblanks" compressed="true"
alias="history-button.ui">../data/ui/history-button.ui</file>
</gresource>
</gresources>
diff --git a/src/four-in-a-row.vala b/src/four-in-a-row.vala
index d31bac0..08fae3f 100644
--- a/src/four-in-a-row.vala
+++ b/src/four-in-a-row.vala
@@ -830,6 +830,8 @@ private class FourInARow : Gtk.Application
app_menu.freeze ();
+ MenuButton history_button = new HistoryButton (/* direction: down */ false);
+
/* Window */
window = new GameWindow ("/org/gnome/Four-in-a-row/ui/four-in-a-row.css",
PROGRAM_NAME,
@@ -837,7 +839,8 @@ private class FourInARow : Gtk.Application
GameWindowFlags.SHOW_START_BUTTON,
(Box) new_game_screen,
game_board_view,
- app_menu);
+ app_menu,
+ history_button);
scorebox = new Scorebox (window, this);
diff --git a/src/game-window.vala b/src/game-window.vala
index f1f5df9..87f2582 100644
--- a/src/game-window.vala
+++ b/src/game-window.vala
@@ -49,13 +49,13 @@ private class GameWindow : AdaptativeWindow
private Button? start_game_button = null;
[GtkChild] private Button new_game_button;
[GtkChild] private Button back_button;
- [GtkChild] private Button game_button;
[GtkChild] private Button unfullscreen_button;
[GtkChild] private Box game_box;
[GtkChild] private Box new_game_box;
private Widget view;
+ private Widget? game_widget;
/* signals */
internal signal void play ();
@@ -66,7 +66,7 @@ private class GameWindow : AdaptativeWindow
// internal signal void redo ();
internal signal void hint ();
- internal GameWindow (string? css_resource, string name, bool start_now, GameWindowFlags flags, Box
new_game_screen, Widget _view, GLib.Menu app_menu)
+ internal GameWindow (string? css_resource, string name, bool start_now, GameWindowFlags flags, Box
new_game_screen, Widget _view, GLib.Menu app_menu, Widget? _game_widget)
{
Object (window_title: name,
specific_css_class_or_empty: "",
@@ -82,6 +82,7 @@ private class GameWindow : AdaptativeWindow
}
view = _view;
+ game_widget = _game_widget;
/* window config */
install_ui_action_entries ();
@@ -91,6 +92,12 @@ private class GameWindow : AdaptativeWindow
info_button.set_menu_model (app_menu);
/* add widgets */
+ if (game_widget != null)
+ {
+ headerbar.pack_end ((!) game_widget);
+ add_adaptative_child ((AdaptativeWidget) (!) game_widget);
+ }
+
new_game_box.pack_start (new_game_screen, true, true, 0);
add_adaptative_child ((AdaptativeWidget) new_game_screen);
if (GameWindowFlags.SHOW_START_BUTTON in flags)
@@ -236,7 +243,8 @@ private class GameWindow : AdaptativeWindow
headerbar.set_title (program_name);
stack.set_visible_child_name ("start-box");
- game_button.hide ();
+ if (game_widget != null)
+ ((!) game_widget).hide ();
new_game_button.hide ();
if (!game_finished && back_button.visible)
@@ -251,7 +259,8 @@ private class GameWindow : AdaptativeWindow
stack.set_visible_child_name ("game-box");
back_button.hide (); // TODO transition?
- game_button.show ();
+ if (game_widget != null)
+ ((!) game_widget).show ();
new_game_button.show ();
if (game_finished)
diff --git a/src/history-button.vala b/src/history-button.vala
new file mode 100644
index 0000000..d90712b
--- /dev/null
+++ b/src/history-button.vala
@@ -0,0 +1,35 @@
+/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ This file is part of GNOME Four-in-a-row.
+
+ Copyright © 2015, 2016, 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/>.
+*/
+
+using Gtk;
+
+[GtkTemplate (ui = "/org/gnome/Four-in-a-row/ui/history-button.ui")]
+private class HistoryButton : MenuButton, AdaptativeWidget
+{
+ internal HistoryButton (bool invert_arrow)
+ {
+ if (invert_arrow)
+ set_direction (ArrowType.UP);
+ }
+
+ protected override void set_window_size (AdaptativeWidget.WindowSize new_size)
+ {
+ }
+}
diff --git a/src/meson.build b/src/meson.build
index dbb2617..a0a06dd 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -24,6 +24,7 @@ sources = files(
'game-board-view.vala',
'game-board.vala',
'game-window.vala',
+ 'history-button.vala',
'new-game-screen.vala',
'prefs.vala',
'scorebox.vala',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]