Commit 7294fa2d authored by Karuna Grewal's avatar Karuna Grewal Committed by Robert Roth

Split five-or-more.c The current code existing in five-or-more.c has been split into:

* five-or-more-app.c : Here all  the callbacks to the application are connected,
  followed by the general setting related to the application like background
  color etc. are moved to this file

* game-area.c: Drawing area related code ,say, binding signals to callbacks,
  or rendering the graphics, controlling the animation are handled here.

* balls-preview.c: This has the necessary functions for previewing.

Getters are used to access the static variables used across the appliaction
which weren't currently required since all the code was mash-up into
a single file.

https://bugzilla.gnome.org/show_bug.cgi?id=794273
parent 2c9624cd
......@@ -9,3 +9,6 @@ data/org.gnome.five-or-more.gschema.xml
data/translatable_themes.h
src/five-or-more.c
src/games-scores-dialog.c
src/five-or-more-app.c
src/game-area.c
src/balls-preview.c
......@@ -2,7 +2,6 @@ bin_PROGRAMS = five-or-more
five_or_more_SOURCES = \
five-or-more.c \
five-or-more.h \
games-file-list.c \
games-file-list.h \
games-gridframe.c \
......@@ -16,7 +15,13 @@ five_or_more_SOURCES = \
games-scores-dialog.c \
games-scores-dialog.h \
games-scores-backend.c \
games-scores-backend.h
games-scores-backend.h \
five-or-more-app.h \
five-or-more-app.c \
balls-preview.c \
balls-preview.h \
game-area.h \
game-area.c
five_or_more_CPPFLAGS = \
-I$(top_srcdir) \
......
/* -*- mode:C; indent-tabs-mode:t; tab-width:8; c-basic-offset:8; -*- */
/*
* Color lines for GNOME
* Copyright © 1999 Free Software Foundation
* Authors: Robert Szokovacs <szo@appaloosacorp.hu>
* Szabolcs Ban <shooby@gnome.hu>
* Karuna Grewal <karunagrewal98@gmail.com>
* Copyright © 2007 Christian Persch
*
* This game 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 2, 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 <https://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <stdlib.h>
#include <locale.h>
#include <math.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk/gdkkeysyms.h>
#include "games-preimage.h"
#include "balls-preview.h"
#include "game-area.h"
#define MAXNPIECES 10
#define PREVIEW_IMAGE_WIDTH 20
#define PREVIEW_IMAGE_HEIGHT 20
static GtkImage* preview_images[MAXNPIECES];
static GdkPixbuf* preview_pixbufs[MAXNPIECES];
static int preview[MAXNPIECES];
void
init_preview (void)
{
int i;
gint npieces = get_npieces();
for (i = 0; i < npieces; i++) {
preview[i] = g_rand_int_range (*get_rgen(), 1, get_ncolors() + 1);
}
}
void
draw_preview (void)
{
guint i;
gint npieces = get_npieces();
/* This function can be called before the images are initialized */
if (!GTK_IS_IMAGE (preview_images[0]))
return;
for (i = 0; i < MAXNPIECES; i++) {
if (i < npieces)
gtk_image_set_from_pixbuf (preview_images[i], preview_pixbufs[preview[i] - 1]);
else
gtk_image_clear (preview_images[i]);
}
}
void
refresh_preview_surfaces (void)
{
guint i;
GdkPixbuf *scaled = NULL;
GtkWidget *widget = GTK_WIDGET (preview_images[0]);
GtkStyleContext *context;
GdkRGBA bg;
cairo_t *cr;
GdkRectangle preview_rect;
cairo_surface_t *blank_preview_surface = NULL;
/* The balls rendered to a size appropriate for the preview. */
cairo_surface_t *preview_surface = NULL;
context = gtk_widget_get_style_context (widget);
gtk_style_context_get_background_color (context, gtk_style_context_get_state (context), &bg);
/* Like the refresh_pixmaps() function, we may be called before
* the window is ready. */
if (PREVIEW_IMAGE_HEIGHT == 0)
return;
preview_rect.x = 0;
preview_rect.y = 0;
preview_rect.width = PREVIEW_IMAGE_WIDTH;
preview_rect.height = PREVIEW_IMAGE_HEIGHT;
/* We create pixmaps for each of the ball colours and then
* set them as the background for each widget in the preview array.
* This code assumes that each preview window is identical. */
GamesPreimage *ball_preimage = get_ball_preimage();
if (ball_preimage)
scaled = games_preimage_render (ball_preimage, 4 * PREVIEW_IMAGE_WIDTH,
7 * PREVIEW_IMAGE_HEIGHT);
if (!scaled) {
scaled = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
4 * PREVIEW_IMAGE_WIDTH, 7 * PREVIEW_IMAGE_HEIGHT);
gdk_pixbuf_fill (scaled, 0x00000000);
}
for (i = 0; i < 7; i++) {
preview_surface = gdk_window_create_similar_image_surface (gtk_widget_get_window (widget),
CAIRO_FORMAT_ARGB32,
PREVIEW_IMAGE_WIDTH, PREVIEW_IMAGE_HEIGHT, 1);
cr = cairo_create (preview_surface);
gdk_cairo_set_source_rgba (cr, &bg);
gdk_cairo_rectangle (cr, &preview_rect);
cairo_fill (cr);
gdk_cairo_set_source_pixbuf (cr, scaled, 0, -1.0 * PREVIEW_IMAGE_HEIGHT * i);
cairo_mask (cr, cairo_get_source (cr));
if (preview_pixbufs[i])
g_object_unref (preview_pixbufs[i]);
preview_pixbufs[i] = gdk_pixbuf_get_from_surface (preview_surface, 0, 0,
PREVIEW_IMAGE_WIDTH, PREVIEW_IMAGE_HEIGHT);
cairo_destroy (cr);
cairo_surface_destroy (preview_surface);
}
blank_preview_surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget),
CAIRO_CONTENT_COLOR_ALPHA,
PREVIEW_IMAGE_WIDTH, PREVIEW_IMAGE_HEIGHT);
cr = cairo_create (blank_preview_surface);
gdk_cairo_set_source_rgba (cr, &bg);
gdk_cairo_rectangle (cr, &preview_rect);
cairo_fill (cr);
cairo_surface_destroy (blank_preview_surface);
cairo_destroy (cr);
g_object_unref (scaled);
}
GtkImage **
get_preview_images()
{
return preview_images;
}
int *
get_preview()
{
return preview;
}
GdkPixbuf **
get_preview_pixbufs()
{
return preview_pixbufs;
}
\ No newline at end of file
/*
* Color lines for GNOME
* Copyright © 1999 Free Software Foundation
* Authors: Robert Szokovacs <szo@appaloosacorp.hu>
* Szabolcs Ban <shooby@gnome.hu>
* Karuna Grewal <karunagrewal98@gmail.com>
* Copyright © 2007 Christian Persch
*
* This game 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 2, 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 <https://www.gnu.org/licenses/>.
*/
#ifndef BALLS_PREVIEW_H
#define BALLS_PREVIEW_H
#include <gtk/gtk.h>
void init_preview (void);
void draw_preview (void);
void refresh_preview_surfaces (void);
GtkImage **get_preview_images ();
int * get_preview ();
GdkPixbuf **get_preview_pixbufs ();
#endif
\ No newline at end of file
This diff is collapsed.
/*
* Color lines for GNOME
* Copyright © 1999 Free Software Foundation
* Authors: Robert Szokovacs <szo@appaloosacorp.hu>
* Szabolcs Ban <shooby@gnome.hu>
* Karuna Grewal <karunagrewal98@gmail.com>
* Copyright © 2007 Christian Persch
*
* This game 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 2, 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 <https://www.gnu.org/licenses/>.
*/
#ifndef FIVE_OR_MORE_APP_H
#define FIVE_OR_MORE_APP_H
#include <gtk/gtk.h>
#include "games-scores.h"
typedef struct _background background;
struct _background{
GdkRGBA color;
gchar *name;
gint set;
} ;
GamesScores *get_highscores ();
GtkWidget *get_gridframe ();
char *get_ball_filename ();
background get_backgnd ();
void set_status_message (gchar * message);
void game_over (void);
void set_application_callbacks (GtkApplication *application);
gint *get_game_size ();
const GamesScoresCategory *get_scorecats ();
GSettings **get_settings ();
int get_move_timeout ();
void game_props_callback (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
void update_score (guint value);
#endif
\ No newline at end of file
This diff is collapsed.
#ifndef glines_h
#define glines_h
#define STEPSIZE 4
typedef struct {
int num;
int score;
} scoretable;
typedef struct {
int color;
int pathsearch;
int phase;
int active;
int tag;
} field_props;
void draw_box (GtkWidget * widget, int x, int y);
void draw_ball (GtkWidget * widget, int x, int y);
int find_route (void);
void set_inmove (int i);
void init_preview (void);
void draw_preview (void);
int init_new_balls (int num, int prev);
gint animate (gpointer gp);
void game_new_callback (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
void game_top_ten_callback (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
void game_quit_callback (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
void game_props_callback (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
void game_help_callback (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
void game_about_callback (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
void pref_dialog_response (GtkDialog * dialog, gint response, gpointer data);
#endif
This diff is collapsed.
/*
* Color lines for GNOME
* Copyright © 1999 Free Software Foundation
* Authors: Robert Szokovacs <szo@appaloosacorp.hu>
* Szabolcs Ban <shooby@gnome.hu>
* Karuna Grewal <karunagrewal98@gmail.com>
* Copyright © 2007 Christian Persch
*
* This game 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 2, 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 <https://www.gnu.org/licenses/>.
*/
#ifndef GAME_AREA_H
#define GAME_AREA_H
#include <gtk/gtk.h>
#include "games-preimage.h"
typedef struct {
int num;
int score;
} scoretable;
typedef struct {
int color;
int pathsearch;
int phase;
int active;
int tag;
} field_props;
GRand **get_rgen ();
GamesPreimage *get_ball_preimage ();
gint get_npieces ();
void set_inmove (int i);
void refresh_pixmaps (void);
void refresh_screen (void);
void load_theme (void);
GtkWidget * game_area_init (void);
gint get_ncolors ();
void set_sizes (gint size);
void reset_game (void);
gint get_hfieldsize ();
gint get_vfieldsize ();
#endif
\ No newline at end of file
......@@ -3,6 +3,12 @@
five_or_more_c_sources = [
'five-or-more.c',
'five-or-more.h',
'game-area.h',
'game-area.c',
'five-or-more-app.c',
'five-or-more-app.h',
'balls-preview.c',
'balls-preview.h',
'games-file-list.c',
'games-file-list.h',
'games-gridframe.c',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment