Commit 38fd17b4 authored by Vivien Kraus's avatar Vivien Kraus

Merge branch '27-clean-the-main-application' into 'develop'

Resolve "Clean the main application"

Closes #27

See merge request gugurumbe/tarot!25
parents 4f10b59b 31863087
Pipeline #103122 passed with stages
in 8 minutes and 19 seconds
......@@ -32,7 +32,7 @@ gnulib-tool --libtool \
--source-base=lib-program \
--m4-base=lib-program/m4 \
--macro-prefix=gl_program \
--import assert readline git-version-gen getopt-gnu gitlog-to-changelog setenv xalloc || exit 1
--import assert git-version-gen getopt-gnu gitlog-to-changelog setenv xalloc || exit 1
./gitlog-to-changelog > ChangeLog
rm -rf libopts libopts-* || exit 1
gunzip -c `autoopts-config libsrc` | tar -xvf - || exit 1
......
......@@ -24,7 +24,7 @@ mkdir -p host-config || exit 1
&& (cd lib-library && make -j) \
&& (cd lib-program && make -j) \
&& make -j flatpak \
&& echo "help" | flatpak-builder --run build-dir ../tarot-$VERSION/eu.planete_kraus.Tarot.json tarot --batch) \
&& echo "help" | flatpak-builder --run build-dir ../tarot-$VERSION/eu.planete_kraus.Tarot.json tarot-cli --help) \
|| exit 1
cat > tarot.flatpakrepo <<EOF
[Flatpak Repo]
......
......@@ -63,11 +63,6 @@ PKG_INSTALLDIR
# Checks for libraries.
gl_lib_INIT
gl_program_INIT
AC_SEARCH_LIBS([add_history], [history], [
AC_DEFINE([HAVE_HISTORY], [1], [Whether the add_history function is available])
], [
AC_DEFINE([HAVE_HISTORY], [0], [Whether the add_history function is available])
])
AX_LIB_NETTLE([yes])
PKG_CHECK_MODULES([XML], [libxml-2.0])
LIBOPTS_CHECK
......
......@@ -30,5 +30,4 @@ indent-org: %reldir%/tarot.org
include %reldir%/texinfo.am
include %reldir%/export-html.am
include %reldir%/export-docbook.am
include %reldir%/org-tangle.am
include %reldir%/org-export-texinfo.am
# org-tangle.am
#
# Copyright (C) 2017, 2018 Vivien Kraus <vivien@planete-kraus.eu>
#
# This program 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.
#
# This program 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 this program. If not, see
# <http://www.gnu.org/licenses/>.
EXTRA_DIST += \
src/main.c \
src/tarot-opts.def \
src/gtk/engine.vala \
%reldir%/tarot.org \
%reldir%/setup.el \
$(srcdir)/%reldir%/org-tangle-stamp
MAINTAINERCLEANFILES += \
$(srcdir)/src/main.c \
$(srcdir)/src/gtk/engine.vala \
$(srcdir)/%reldir%/org-tangle-stamp
tangle_verbose = $(tangle_verbose_@AM_V@)
tangle_verbose_ = $(tangle_verbose_@AM_DEFAULT_V@)
tangle_verbose_0 = @echo " TANGLE " $@;
$(srcdir)/%reldir%/org-tangle-stamp: %reldir%/tarot.org %reldir%/setup.el
@rm -f $(srcdir)/%reldir%/org-tangle-temp
@touch $(srcdir)/%reldir%/org-tangle-temp
$(tangle_verbose) cd $(srcdir) && $(EMACS) --batch \
-l %reldir%/setup.el \
--eval "(defun package-version () \"$(VERSION)\")" \
--file %reldir%/tarot.org \
-f org-babel-tangle
@mv -f $(srcdir)/%reldir%/org-tangle-temp $(srcdir)/%reldir%/org-tangle-stamp
$(srcdir)/src/main.c \
$(srcdir)/src/gtk/engine.vala: %reldir%/org-tangle-stamp
## Recover from the removal of $@
@dry=; for f in x $$MAKEFLAGS; do \
case $$f in \
*=*|--*);; \
*n*) dry=:;; \
esac; \
done; \
if test -f $@; then :; else \
$$dry trap 'rm -rf $(srcdir)/%reldir%/org-tangle-lock $(srcdir)/%reldir%/org-tangle-stamp' 1 2 13 15; \
if $$dry mkdir $(srcdir)/%reldir%/org-tangle-lock 2>/dev/null; then \
## This code is being executed by the first process.
$$dry rm -f $(srcdir)/%reldir%/org-tangle-stamp; \
$(MAKE) $(AM_MAKEFLAGS) $(srcdir)/%reldir%/org-tangle-stamp; \
$$dry rmdir $(srcdir)/%reldir%/org-tangle-lock; \
else \
## This code is being executed by the follower processes.
## Wait until the first process is done.
while test -d $(srcdir)/%reldir%/org-tangle-lock && test -z "$$dry"; do \
sleep 1; \
done; \
## Succeed if and only if the first process succeeded.
$$dry test -f $(srcdir)/%reldir%/org-tangle-stamp; exit $$?; \
fi; \
fi
This diff is collapsed.
......@@ -23,14 +23,12 @@ dist_tarotfigures_DATA = \
%canon_reldir%_tarot_TEXINFOS = \
%reldir%/fdl.texi \
%reldir%/invoke-tarot-body.texi \
%reldir%/invoke-tarot-render-body.texi \
%reldir%/invoke-tarot-generate-body.texi \
%reldir%/invoke-tarot-cli-body.texi
EXTRA_DIST += \
%reldir%/tarot-figures/example.eps \
%reldir%/invoke-tarot-body.texi \
%reldir%/invoke-tarot-render-body.texi \
%reldir%/invoke-tarot-generate-body.texi \
%reldir%/invoke-tarot-cli-body.texi
......@@ -38,7 +36,6 @@ EXTRA_DIST += \
MAINTAINERCLEANFILES += \
$(srcdir)/%reldir%/tarot-figures/example.png \
$(srcdir)/%reldir%/tarot-figures/example.eps \
$(srcdir)/%reldir%/invoke-tarot-body.texi \
$(srcdir)/%reldir%/invoke-tarot-render-body.texi \
$(srcdir)/%reldir%/invoke-tarot-generate-body.texi \
$(srcdir)/%reldir%/invoke-tarot-cli-body.texi
......
......@@ -22,7 +22,6 @@ include %reldir%/tarot-enums.am
include %reldir%/libtarot-vapi.am
include %reldir%/libtarot-gir.am
include %reldir%/libtarot-typelib.am
include %reldir%/tarot-program.am
include %reldir%/tarot-cli-program.am
AM_CPPFLAGS += -I $(srcdir)/%reldir% -I %reldir%
......
......@@ -16,34 +16,19 @@
# along with this program. If not, see
# <http://www.gnu.org/licenses/>.
noinst_LTLIBRARIES += \
%reldir%/libtarot-painter.la
%canon_reldir%_libtarot_painter_la_SOURCES =
if WITH_CAIRO
%canon_reldir%_libtarot_painter_la_SOURCES += \
noinst_LTLIBRARIES += \
%reldir%/libtarot-painter.la
%canon_reldir%_libtarot_painter_la_SOURCES = \
%reldir%/card_painter.c \
%reldir%/card_painter_default.c
endif # WITH_CAIRO
%canon_reldir%_libtarot_painter_la_CFLAGS = \
$(AM_CFLAGS) \
-include "config.h" \
-w
if WITH_CAIRO
%canon_reldir%_libtarot_painter_la_CFLAGS += \
$(CAIRO_CFLAGS)
else # not WITH_CAIRO
%canon_reldir%_libtarot_painter_la_CFLAGS += \
$(GOBJECT_CFLAGS)
endif # not WITH_CAIRO
%canon_reldir%_libtarot_painter_la_LIBS = $(AM_LIBS)
if WITH_CAIRO
%canon_reldir%_libtarot_painter_la_LIBS += \
%canon_reldir%_libtarot_painter_la_LIBS = $(AM_LIBS) \
$(CAIRO_LIBS)
else # not WITH_CAIRO
%canon_reldir%_libtarot_painter_la_LIBS += \
$(GOBJECT_LIBS)
endif # not WITH_CAIRO
endif # WITH_CAIRO
# Makefile.am
#
# Copyright (C) 2018 Vivien Kraus <vivien@planete-kraus.eu>
# Copyright (C) 2019 Vivien Kraus <vivien@planete-kraus.eu>
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
......@@ -16,7 +16,7 @@
# along with this program. If not, see
# <http://www.gnu.org/licenses/>.
include %reldir%/libtarot-application.am
include %reldir%/tarot-application.am
include %reldir%/gresources.am
AM_VALAFLAGS += \
......
......@@ -32,9 +32,7 @@ $(srcdir)/%reldir%/tarot-resources.c: %reldir%/tarot-resources.xml %reldir%/main
&& touch tarot-resources.c
if WITH_GTK
if WITH_GOBJECT
src_tarot_SOURCES += %reldir%/tarot-resources.c
endif # WITH_GOBJECT
%canon_reldir%_tarot_SOURCES += %reldir%/tarot-resources.c
endif # WITH_GTK
MAINTAINERCLEANFILES += $(srcdir)/%reldir%/tarot-resources.c
# libtarot-application.am
#
# Copyright (C) 2018 Vivien Kraus <vivien@planete-kraus.eu>
#
# This program 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.
#
# This program 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 this program. If not, see
# <http://www.gnu.org/licenses/>.
EXTRA_DIST += \
%reldir%/application-@LIBTOOL_CURRENT@.0.vapi \
%reldir%/application.h \
%reldir%/tarot_application_without_gui.c \
%reldir%/tarot_application_with_gui.c \
%reldir%/engine.c \
%reldir%/tarot_application_without_gui.vala \
%reldir%/tarot_application_with_gui.vala \
%reldir%/engine.vala \
%reldir%/application-vapi-stamp
MAINTAINERCLEANFILES += \
$(srcdir)/%reldir%/application-@LIBTOOL_CURRENT@.0.vapi \
$(srcdir)/%reldir%/application.h \
$(srcdir)/%reldir%/tarot_application_without_gui.c \
$(srcdir)/%reldir%/tarot_application_with_gui.c \
$(srcdir)/%reldir%/engine.c \
$(srcdir)/%reldir%/application-vapi-stamp
noinst_LTLIBRARIES += \
%reldir%/libtarot-application.la
%canon_reldir%_libtarot_application_la_SOURCES = \
%reldir%/tarot_application_without_gui.c \
%reldir%/engine.c
if WITH_GTK
%canon_reldir%_libtarot_application_la_SOURCES += \
%reldir%/tarot_application_with_gui.c
endif # WITH_GTK
%canon_reldir%_libtarot_application_la_CFLAGS = \
$(AM_CFLAGS) \
-include "config.h" \
-w
if WITH_GTK
%canon_reldir%_libtarot_application_la_CFLAGS += \
$(GTK_CFLAGS)
else # not WITH_GTK
%canon_reldir%_libtarot_application_la_CFLAGS += \
$(GOBJECT_CFLAGS)
endif # not WITH_GTK
%canon_reldir%_libtarot_application_la_LIBS = \
$(AM_LIBS)
if WITH_GTK
%canon_reldir%_libtarot_application_la_LIBS += \
$(GTK_LIBS)
else # not WITH_GTK
%canon_reldir%_libtarot_application_la_LIBS += \
$(GOBJECT_LIBS)
endif # not WITH_GTK
%canon_reldir%_libtarot_application_la_LIBADD = \
src/libtarot.la \
src/libtarot-gobject.la
if WITH_GTK
%canon_reldir%_libtarot_application_la_LIBADD += \
src/cairo/libtarot-painter.la
endif # WITH_GTK
$(srcdir)/%reldir%/application-vapi-stamp: %reldir%/tarot_application_without_gui.vala %reldir%/tarot_application_with_gui.vala %reldir%/engine.vala src/tarot-@LIBTOOL_CURRENT@.0.vapi src/cairo/cardpainter-@LIBTOOL_CURRENT@.0.vapi %reldir%/tarot-resources.xml %reldir%/main_window.ui
$(AM_V_VALAC) cd $(srcdir) && $(VALAC) $(AM_VALAFLAGS) $(VALAFLAGS) \
--library application-@LIBTOOL_CURRENT@.0 \
--vapi %reldir%/application-@LIBTOOL_CURRENT@.0.vapi \
-H %reldir%/application.h \
-C \
%reldir%/tarot_application_with_gui.vala \
%reldir%/tarot_application_without_gui.vala \
%reldir%/engine.vala \
src/tarot-@LIBTOOL_CURRENT@.0.vapi \
src/cairo/cardpainter-@LIBTOOL_CURRENT@.0.vapi
@touch $(srcdir)/%reldir%/application.h
@touch $(srcdir)/%reldir%/application-@LIBTOOL_CURRENT@.0.vapi
@touch $(srcdir)/%reldir%/tarot_application_with_gui.c
@touch $(srcdir)/%reldir%/tarot_application_without_gui.c
@touch $(srcdir)/%reldir%/engine.c
@touch $(srcdir)/%reldir%/application-vapi-stamp
$(srcdir)/%reldir%/application-@LIBTOOL_CURRENT@.0.vapi \
$(srcdir)/%reldir%/application.h \
$(srcdir)/%reldir%/tarot_application_without_gui.c \
$(srcdir)/%reldir%/tarot_application_with_gui.c \
$(srcdir)/%reldir%/engine.c: %reldir%/application-vapi-stamp
@dry=; for f in x $$MAKEFLAGS; do \
case $$f in \
*=*|--*);; \
*n*) dry=:;; \
esac; \
done; \
if test -f $@; then :; else \
$$dry trap 'rm -rf $(srcdir)/%reldir%/application-vapi-lock $(srcdir)/%reldir%/application-vapi-stamp' 1 2 13 15; \
if $$dry mkdir $(srcdir)/%reldir%/application-vapi-lock 2>/dev/null; then \
$$dry rm -f $(srcdir)/%reldir%/application-vapi-stamp || exit 1; \
$(MAKE) $(AM_MAKEFLAGS) %reldir%/application-vapi-stamp; \
$$dry rmdir $(srcdir)/%reldir%/application-vapi-lock; \
else \
while test -d $(srcdir)/%reldir%/application-vapi-lock && test -z "$$dry"; do \
sleep 1; \
done; \
$$dry test -f $(srcdir)/%reldir%/application-vapi-stamp; exit $$?; \
fi; \
fi
#+title: The tarot-playing application
#+language: en
#+author: Vivien Kraus
#+email: vivien@planete-kraus.eu
* Introduction
We already have a library to paint some /Tarot.Card/'s on a cairo
surface. How do we transform that into a useful application? This
document is here to implement exactly that in vala.
At its core, the program is simply a wrapper around a /Tarot.Game/,
dealt at random, for a given number of players.
* The main window
The main window uses a template file in order to simplify things. So,
we only have to implement the callback to actually paint the game.
#+name: window-class
#+BEGIN_SRC vala
[GtkTemplate (ui = "/eu/planete_kraus/Tarot/main_window.ui")]
public class Window: Gtk.ApplicationWindow {
public Tarot.Game game = new Tarot.Game.alloc ();
private Tarot.CardPainter painter = new Tarot.DefaultCardPainter ();
[GtkChild]
private Gtk.DrawingArea tarot_drawing_area;
[GtkCallback]
private bool paint_game (Cairo.Context context) {
uint width = tarot_drawing_area.get_allocated_width ();
uint height = tarot_drawing_area.get_allocated_height ();
context.translate (width / 2.0, height / 2.0);
context.scale (1, -1);
bool success = painter.paint_game (width, height, game, context);
if (! success) {
painter.paint_game_as (width, height, game, 0, context);
}
return true;
}
public Window (Gtk.Application app) {
Object (application: app);
}
}
#+END_SRC
* The Gtk+ application
In order to summarize the application, we wrap everything in a main function.
#+BEGIN_SRC vala :noweb no-export :tangle main.vala
// file main.vala
//
// Copyright (C) 2017, 2018, 2019 Vivien Kraus <vivien@planete-kraus.eu>
//
// This program 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.
//
// This program 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 this program. If not, see
// <http://www.gnu.org/licenses/>.
namespace Tarot {
<<window-class>>
}
int main (string[] args) {
var app = new Gtk.Application ("eu.planete_kraus.Tarot", ApplicationFlags.FLAGS_NONE);
app.activate.connect (() => {
var window = app.active_window;
if (window == null) {
window = new Tarot.Window (app);
}
window.present ();
});
return app.run (args);
}
#+END_SRC
# Local Variables:
# tab-width: 4
# End:
......@@ -7,73 +7,10 @@
<property name="default_width">600</property>
<property name="default_height">300</property>
<child>
<object class="GtkBox" id="main_box">
<object class="GtkDrawingArea" id="tarot_drawing_area">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkDrawingArea" id="tarot_drawing_area">
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="draw" handler="paint_game" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkTextView" id="console">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="editable">False</property>
<property name="monospace">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkEntry" id="input">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="is_focus">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="send">
<property name="label" translatable="yes">Send</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="send_clicked_cb" swapped="no"/>
<accelerator key="m" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<signal name="draw" handler="paint_game" swapped="no"/>
</object>
</child>
<child type="titlebar">
......
# tarot-program.am
# tarot-application.am
#
# Copyright (C) 2017, 2018 Vivien Kraus <vivien@planete-kraus.eu>
# Copyright (C) 2019 Vivien Kraus <vivien@planete-kraus.eu>
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
......@@ -16,53 +16,41 @@
# along with this program. If not, see
# <http://www.gnu.org/licenses/>.
if WITH_GOBJECT
bin_PROGRAMS += %reldir%/tarot
dist_man6_MANS += %reldir%/tarot.man
%canon_reldir%_tarot_SOURCES = \
EXTRA_DIST += \
%reldir%/main.c \
%reldir%/main.vala \
%reldir%/main.org
MAINTAINERCLEANFILES += \
%reldir%/main.c \
%reldir%/tarot-opts.c \
%reldir%/tarot-opts.h
%canon_reldir%_tarot_CFLAGS = \
$(AM_CFLAGS) \
$(LIBOPTS_CFLAGS) \
$(GOBJECT_CFLAGS)
%canon_reldir%_tarot_CPPFLAGS = \
$(AM_CPPFLAGS) \
-include config.h
%reldir%/main.vala
if WITH_GTK
bin_PROGRAMS += %reldir%/tarot
%canon_reldir%_tarot_SOURCES = %reldir%/main.c
%canon_reldir%_tarot_CFLAGS = $(AM_CFLAGS) $(GTK_CFLAGS) -include "config.h" -w
%canon_reldir%_tarot_LDADD = \
%reldir%/libtarot.la \
%reldir%/libtarot-gobject.la \
src/gtk/libtarot-application.la \
$(AM_LDADD) \
src/libtarot.la \
src/libtarot-gobject.la \
src/cairo/libtarot-painter.la \
lib-program/libgnuprogram.la \
$(LTLIBREADLINE) \
$(LIBOPTS_LDADD) \
$(GOBJECT_LIBS) \
$(GTK_LIBS)
endif # WITH_OBJECT
endif # WITH_GTK
$(%canon_reldir%_tarot_OBJECTS): %reldir%/tarot-opts.h src/cards/tarot/cards.h
$(srcdir)/%reldir%/tarot-opts.h: %reldir%/tarot-opts.c
$(srcdir)/%reldir%/tarot-opts.c: %reldir%/tarot-opts.def
$(AM_V_GEN) cd $(srcdir)/%reldir% && $(AUTOGEN) --writable tarot-opts.def
$(srcdir)/%reldir%/tarot.man: %reldir%/tarot-opts.def
$(AM_V_GEN) cd $(srcdir)/%reldir% && $(AUTOGEN) --writable -Tagman-cmd.tpl -btarot tarot-opts.def \
&& mv tarot.1 tarot.man
$(srcdir)/doc/invoke-tarot-body.texi: %reldir%/tarot-opts.def
@rm -rf %reldir%/autogen-texi-tarot
@mkdir %reldir%/autogen-texi-tarot
@cp $(srcdir)/%reldir%/tarot-opts.def %reldir%/autogen-texi-tarot/
$(AM_V_GEN) cd %reldir%/autogen-texi-tarot && $(AUTOGEN) --writable -Tagtexi-cmd.tpl tarot-opts.def
@tail -n +3 %reldir%/autogen-texi-tarot/invoke-tarot.texi > $(srcdir)/doc/invoke-tarot-body.texi
@rm -rf %reldir%/autogen-texi-tarot
tangle_verbose = $(tangle_verbose_@AM_V@)
tangle_verbose_ = $(tangle_verbose_@AM_DEFAULT_V@)
tangle_verbose_0 = @echo " TANGLE " $@;
EXTRA_DIST += %reldir%/tarot.man \
%reldir%/main.c \
%reldir%/tarot-opts.c \
%reldir%/tarot-opts.h \
%reldir%/tarot-opts.def
$(srcdir)/%reldir%/main.c: %reldir%/main.vala \
src/tarot-@LIBTOOL_CURRENT@.0.vapi \
src/cairo/cardpainter-@LIBTOOL_CURRENT@.0.vapi
$(AM_V_VALAC) cd $(srcdir) && $(VALAC) $(AM_VALAFLAGS) $(VALAFLAGS) \
-C %reldir%/main.vala \
src/tarot-@LIBTOOL_CURRENT@.0.vapi \
src/cairo/cardpainter-@LIBTOOL_CURRENT@.0.vapi
@touch $(srcdir)/%reldir%/main.c
MAINTAINERCLEANFILES += \
$(srcdir)/%reldir%/tarot.man \
$(srcdir)/%reldir%/tarot-opts.c \
$(srcdir)/%reldir%/tarot-opts.h
$(srcdir)/%reldir%/main.vala: %reldir%/main.org
$(tangle_verbose) cd $(srcdir) \
&& $(EMACS) --batch --file %reldir%/main.org -f org-babel-tangle
// file tarot_application.vala
//
// Copyright (C) 2017, 2018 Vivien Kraus <vivien@planete-kraus.eu>
//
// This program 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.
//
// This program 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 this program. If not, see
// <http://www.gnu.org/licenses/>.
namespace Tarot {
[GtkTemplate (ui = "/eu/planete_kraus/Tarot/main_window.ui")]
public class Window: Gtk.ApplicationWindow {
private Tarot.Engine engine = new Tarot.Engine ();
private Tarot.Cli cli = new Tarot.Cli.alloc ();
private Tarot.CardPainter painter = new Tarot.DefaultCardPainter ();
[GtkChild]
private Gtk.TextView console;
[GtkChild]
private Gtk.Entry input;
[GtkChild]
private Gtk.DrawingArea tarot_drawing_area;
[GtkCallback]
private void send_clicked_cb () {
console.buffer.text = "";
string line = input.text;
input.text = "";
if (line != "") {
if (cli.push (line, false) != 0) {
GLib.Process.abort ();
}
while (cli.has_command ()) {
if (engine.command (ref cli)) {
close ();
}
cli.next ();
}
}
}
[GtkCallback]
private bool paint_game (Cairo.Context context) {
uint width = tarot_drawing_area.get_allocated_width ();
uint height = tarot_drawing_area.get_allocated_height ();
context.translate (width / 2.0, height / 2.0);
context.scale (1, -1);
bool success = painter.paint_game (width, height, engine.game, context);
if (! success) {
painter.paint_game_as (width, height, engine.game, 0, context);
}
return true;
}
public Window (Gtk.Application app) {
Object (application: app);
engine.print.connect ((str) => {
console.buffer.text += str;
});
engine.print_error.connect ((str) => {
console.buffer.text += "!! {" + str + "}";
});
engine.game_updated.connect ((game) => {
tarot_drawing_area.queue_draw ();
});
engine.print_user_greeting ();
}
}
namespace Gui {
public static int try_run_with_gui (bool brief) {
var app = new Gtk.Application ("eu.planete_kraus.Tarot", ApplicationFlags.FLAGS_NONE);
app.activate.connect (() => {
var window = app.active_window;
if (window == null) {
window = new Window (app);
window.show_all ();
}
window.present ();
});
return app.run (null);
}
}
}
\ No newline at end of file
// file tarot_application_without_gui.vala
//
// Copyright (C) 2017, 2018 Vivien Kraus <vivien@planete-kraus.eu>
//
// This program 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.
//
// This program 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 this program. If not, see
// <http://www.gnu.org/licenses/>.
extern string? readline (string prompt);
extern void add_history (string command);
namespace Tarot {
namespace Gui {
public static int try_run_without_gui (bool brief) {
string? new_line = null;
var cli = new Tarot.Cli.alloc ();
bool done = false;
var app = new Tarot.Engine ();
app.print.connect ((str) => { stdout.printf ("%s", str); });
app.print_error.connect ((str) => { stderr.printf ("%s", str); });
if (!brief) {
app.print_user_greeting ();
}
while (!done) {
string prompt_primary = "> ";
string prompt_secondary = ". ";
string prompt = prompt_primary;
if (cli.is_continuation ()) {
prompt = prompt_secondary;
}
new_line = readline (prompt);
if (new_line == null) {
if (cli.push ("", true) != 0) {
GLib.Process.abort ();
}
done = true;
} else if (new_line != "") {
if (cli.push (new_line, false) != 0) {
GLib.Process.abort ();
}
add_history (new_line);
}
while (cli.has_command ()) {
if (app.command (ref cli)) {
done = true;
}
cli.next ();