forked from AuroraMiddleware/gtk
Merge branch 'matthiasc/for-master' into 'master'
gtk-demo: Add a little extra in peg solitaire Closes #3051 See merge request GNOME/gtk!2424
This commit is contained in:
commit
bc20fe3cca
@ -4,6 +4,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
/* Create an object for the pegs that get moved around in the game.
|
||||
@ -115,6 +116,57 @@ solitaire_peg_new (void)
|
||||
return g_object_new (SOLITAIRE_TYPE_PEG, NULL);
|
||||
}
|
||||
|
||||
/*** Helper for finding a win ***/
|
||||
|
||||
static void
|
||||
ended (GObject *object)
|
||||
{
|
||||
g_object_unref (object);
|
||||
}
|
||||
|
||||
static void
|
||||
celebrate (void)
|
||||
{
|
||||
char *path;
|
||||
GtkMediaStream *stream;
|
||||
|
||||
path = g_build_filename (GTK_DATADIR, "sounds", "freedesktop", "stereo", "complete.oga", NULL);
|
||||
stream = gtk_media_file_new_for_filename (path);
|
||||
gtk_media_stream_set_volume (stream, 1.0);
|
||||
gtk_media_stream_play (stream);
|
||||
|
||||
g_signal_connect (stream, "notify::ended", G_CALLBACK (ended), NULL);
|
||||
g_free (path);
|
||||
}
|
||||
|
||||
static void
|
||||
check_for_win (GtkGrid *grid)
|
||||
{
|
||||
GtkWidget *image;
|
||||
int x, y;
|
||||
int pegs;
|
||||
|
||||
pegs = 0;
|
||||
for (x = 0; x < 7; x++)
|
||||
{
|
||||
for (y = 0; y < 7; y++)
|
||||
{
|
||||
image = gtk_grid_get_child_at (grid, x, y);
|
||||
if (GTK_IS_IMAGE (image) &&
|
||||
SOLITAIRE_IS_PEG (gtk_image_get_paintable (GTK_IMAGE (image))))
|
||||
pegs++;
|
||||
}
|
||||
}
|
||||
|
||||
if (pegs > 1)
|
||||
return;
|
||||
|
||||
image = gtk_grid_get_child_at (grid, 3, 3);
|
||||
if (SOLITAIRE_IS_PEG (gtk_image_get_paintable (GTK_IMAGE (image))))
|
||||
celebrate ();
|
||||
}
|
||||
|
||||
|
||||
/*** DRAG AND DROP ***/
|
||||
|
||||
/* The user tries to start a drag operation.
|
||||
@ -267,6 +319,9 @@ drop_drop (GtkDropTarget *target,
|
||||
solitaire_peg_set_position (peg, image_x, image_y);
|
||||
gtk_image_set_from_paintable (GTK_IMAGE (image), GDK_PAINTABLE (peg));
|
||||
|
||||
/* Maybe we have something to celebrate */
|
||||
check_for_win (grid);
|
||||
|
||||
/* Success! */
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -20,11 +20,11 @@ executable('gtk4-node-editor',
|
||||
link_args: extra_demo_ldflags,
|
||||
install: false)
|
||||
|
||||
# icons
|
||||
icontheme_dir = join_paths(gtk_datadir, 'icons/hicolor')
|
||||
# icons, don't install them until we decide to install gtk4-node-editor
|
||||
#icontheme_dir = join_paths(gtk_datadir, 'icons/hicolor')
|
||||
|
||||
foreach size: ['scalable', 'symbolic']
|
||||
install_subdir('data/' + size,
|
||||
install_dir: icontheme_dir
|
||||
)
|
||||
endforeach
|
||||
#foreach size: ['scalable', 'symbolic']
|
||||
# install_subdir('data/' + size,
|
||||
# install_dir: icontheme_dir
|
||||
# )
|
||||
#endforeach
|
||||
|
@ -60,8 +60,15 @@ activate_about (GSimpleAction *action,
|
||||
GString *s;
|
||||
GskRenderer *gsk_renderer;
|
||||
const char *renderer;
|
||||
char *os_name;
|
||||
char *os_version;
|
||||
GtkWidget *dialog;
|
||||
|
||||
os_name = g_get_os_info (G_OS_INFO_KEY_NAME);
|
||||
os_version = g_get_os_info (G_OS_INFO_KEY_VERSION_ID);
|
||||
s = g_string_new ("");
|
||||
if (os_name && os_version)
|
||||
g_string_append_printf (s, "OS\t%s %s\n\n", os_name, os_version);
|
||||
|
||||
g_string_append (s, "System libraries\n");
|
||||
g_string_append_printf (s, "\tGLib\t%d.%d.%d\n",
|
||||
@ -93,7 +100,8 @@ activate_about (GSimpleAction *action,
|
||||
gtk_get_minor_version (),
|
||||
gtk_get_micro_version ());
|
||||
|
||||
gtk_show_about_dialog (GTK_WINDOW (gtk_application_get_active_window (app)),
|
||||
dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
|
||||
"transient-for", gtk_application_get_active_window (app),
|
||||
"program-name", "GTK Node Editor",
|
||||
"version", version,
|
||||
"copyright", "© 2019—2020 The GTK Team",
|
||||
@ -105,9 +113,15 @@ activate_about (GSimpleAction *action,
|
||||
"title", "About GTK Node Editor",
|
||||
"system-information", s->str,
|
||||
NULL);
|
||||
gtk_about_dialog_add_credit_section (GTK_ABOUT_DIALOG (dialog),
|
||||
"Artwork by", (const char *[]) { "Jakub Steiner", NULL });
|
||||
|
||||
gtk_window_present (GTK_WINDOW (dialog));
|
||||
|
||||
g_string_free (s, TRUE);
|
||||
g_free (version);
|
||||
g_free (os_name);
|
||||
g_free (os_version);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -4,5 +4,6 @@
|
||||
<file preprocess="xml-stripblanks">node-editor-window.ui</file>
|
||||
<file preprocess="xml-stripblanks">help-window.ui</file>
|
||||
<file>node-format.md</file>
|
||||
<file alias='icons/apps/org.gtk.gtk4.NodeEditor.Devel.svg'>data/scalable/apps/org.gtk.gtk4.NodeEditor.Devel.svg</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
@ -604,6 +604,10 @@ activate_about (GSimpleAction *action,
|
||||
"Alexander Larsson",
|
||||
NULL
|
||||
};
|
||||
const char *artists[] = {
|
||||
"Jakub Steiner",
|
||||
NULL
|
||||
};
|
||||
const char *maintainers[] = {
|
||||
"The GTK Team",
|
||||
NULL
|
||||
@ -656,6 +660,8 @@ activate_about (GSimpleAction *action,
|
||||
"title", "About GTK Print Editor",
|
||||
"system-information", sysinfo->str,
|
||||
NULL);
|
||||
gtk_about_dialog_add_credit_section (GTK_ABOUT_DIALOG (dialog),
|
||||
_("Artwork by"), artists);
|
||||
gtk_about_dialog_add_credit_section (GTK_ABOUT_DIALOG (dialog),
|
||||
_("Maintained by"), maintainers);
|
||||
|
||||
@ -663,6 +669,8 @@ activate_about (GSimpleAction *action,
|
||||
|
||||
g_string_free (sysinfo, TRUE);
|
||||
g_free (version);
|
||||
g_free (os_name);
|
||||
g_free (os_version);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user