theme.c/h: consistent indentation
This commit is contained in:
parent
a43f2eb39b
commit
373a362b01
102
src/theme.c
102
src/theme.c
@ -1,7 +1,7 @@
|
||||
/* theme.c - functions related to theme handling
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* modif (y it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*/
|
||||
@ -30,7 +30,9 @@ gchar *THEMEPREFIX="/.gtkballs/themes/";
|
||||
#define DELTA(d, h) \
|
||||
d = h < 0 ? (d > -h ? d + h : 0) : (d + h < 255 ? d + h : 255)
|
||||
|
||||
void hilight_pixbuff8(GdkPixbuf *pb, gint dr, gint dg, gint db) {
|
||||
|
||||
void hilight_pixbuff8(GdkPixbuf *pb, gint dr, gint dg, gint db)
|
||||
{
|
||||
/* pb created with 8b/rgb without alpha */
|
||||
gint i;
|
||||
gint nc = gdk_pixbuf_get_n_channels(pb);
|
||||
@ -53,7 +55,9 @@ void hilight_pixbuff8(GdkPixbuf *pb, gint dr, gint dg, gint db) {
|
||||
}
|
||||
}
|
||||
|
||||
gchar *find_theme_path(gchar *themename) {
|
||||
|
||||
gchar *find_theme_path(gchar *themename)
|
||||
{
|
||||
gchar *homedir;
|
||||
gchar *themepath;
|
||||
struct stat buf;
|
||||
@ -74,7 +78,9 @@ gchar *find_theme_path(gchar *themename) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gint gtkb_load_pixmap(GtkbPixmap *pixmap, gchar *path, gchar *pixmapname) {
|
||||
|
||||
gint gtkb_load_pixmap(GtkbPixmap *pixmap, gchar *path, gchar *pixmapname)
|
||||
{
|
||||
gchar *fname;
|
||||
GError *error = NULL;
|
||||
gint rv = 1;
|
||||
@ -82,7 +88,9 @@ gint gtkb_load_pixmap(GtkbPixmap *pixmap, gchar *path, gchar *pixmapname) {
|
||||
if (!(fname = g_strconcat(path, pixmapname, NULL))) {
|
||||
return 0;
|
||||
}
|
||||
if(pixmap->pixbuf) g_object_unref(pixmap->pixbuf);
|
||||
if (pixmap->pixbuf) {
|
||||
g_object_unref(pixmap->pixbuf);
|
||||
}
|
||||
pixmap->pixbuf = gdk_pixbuf_new_from_file(fname, &error);
|
||||
if (!pixmap->pixbuf) {
|
||||
ut_simple_message_box(error->message);
|
||||
@ -102,7 +110,9 @@ void gtkb_pixmap_free(GtkbPixmap pixmap) {
|
||||
}
|
||||
}
|
||||
|
||||
void gtkb_theme_free(GtkbTheme *theme) {
|
||||
|
||||
void gtkb_theme_free(GtkbTheme *theme)
|
||||
{
|
||||
gint i, j;
|
||||
|
||||
if (!theme) {
|
||||
@ -141,14 +151,18 @@ void gtkb_theme_free(GtkbTheme *theme) {
|
||||
g_free (theme);
|
||||
}
|
||||
|
||||
|
||||
/* warning! tmpname will be free()'d! */
|
||||
gint gtkb_load_pixmap_from(gchar **trc, gchar *themepath, gchar *tmpname, GtkbPixmap *pixmap) {
|
||||
gint gtkb_load_pixmap_from(gchar **trc, gchar *themepath, gchar *tmpname, GtkbPixmap *pixmap)
|
||||
{
|
||||
gchar *val;
|
||||
gint ret;
|
||||
|
||||
val = trc_get_str(trc, tmpname);
|
||||
g_free (tmpname);
|
||||
if(val == NULL) return 0;
|
||||
if (val == NULL) {
|
||||
return 0;
|
||||
}
|
||||
ret = gtkb_load_pixmap(pixmap, themepath, val);
|
||||
g_free (val);
|
||||
|
||||
@ -172,7 +186,9 @@ void gtkb_make_hl_pixmap(GtkbTheme *theme) {
|
||||
hilight_pixbuff8(theme->hemptycell.pixbuf, prefs_get_hl_dr(), prefs_get_hl_dg(), prefs_get_hl_db());
|
||||
}
|
||||
|
||||
GtkbTheme *gtkb_load_theme(gchar *themepath) {
|
||||
|
||||
GtkbTheme *gtkb_load_theme(gchar *themepath)
|
||||
{
|
||||
gchar **trc, *opt;
|
||||
gchar *paws[] = {"down_up", "left_right", "up_down", "right_left",
|
||||
"down_right", "down_left", "up_right", "up_left", NULL};
|
||||
@ -205,38 +221,38 @@ GtkbTheme *gtkb_load_theme(gchar *themepath) {
|
||||
/* find and load "footprints" pixmaps. */
|
||||
for (i = 0; paws[i]; i++) {
|
||||
CHECKRET(gtkb_load_pixmap_from(trc, themepath, g_strconcat("paw.", paws[i], NULL),
|
||||
&theme->paws[i]),
|
||||
0);
|
||||
&theme->paws[i]), 0);
|
||||
}
|
||||
|
||||
/* query number of available balls in theme */
|
||||
theme->numballs = trc_get_uint(trc, "ball.numbers");
|
||||
CHECKRET(theme->numballs, -1);
|
||||
if(theme->numballs < rules_get_colors()) CHECKRET(0, 0); /* yes, i know. its ugly =) */
|
||||
if (theme->numballs < rules_get_colors()) {
|
||||
CHECKRET(0, 0); /* yes, i know. its ugly =) */
|
||||
}
|
||||
theme->balls = g_new0(GtkbBall, theme->numballs);
|
||||
|
||||
/* find and load all balls data. */
|
||||
for (i = 0; i < theme->numballs; i++) {
|
||||
CHECKRET(gtkb_load_pixmap_from(trc, themepath, g_strdup_printf("ball.%d.still", i + 1),
|
||||
&theme->balls[i].ball),
|
||||
0);
|
||||
&theme->balls[i].ball), 0);
|
||||
CHECKRET(gtkb_load_pixmap_from(trc, themepath, g_strdup_printf("ball.%d.small", i + 1),
|
||||
&theme->balls[i].small),
|
||||
0);
|
||||
&theme->balls[i].small), 0);
|
||||
|
||||
opt = g_strdup_printf("ball.%d.jump.numbers", i + 1);
|
||||
theme->balls[i].jumpphases = trc_get_uint(trc, opt);
|
||||
g_free (opt);
|
||||
CHECKRET(theme->balls[i].jumpphases, -1);
|
||||
if(theme->balls[i].jumpphases < 2) CHECKRET(0, 0); /* yes, i know. its ugly =) */
|
||||
if (theme->balls[i].jumpphases < 2) {
|
||||
CHECKRET(0, 0); /* yes, i know. its ugly =) */
|
||||
}
|
||||
theme->balls[i].jump = g_new0(GtkbPixmap, theme->balls[i].jumpphases);
|
||||
theme->balls[i].jumpdelays = g_new0(gint, theme->balls[i].jumpphases);
|
||||
|
||||
for (j = 0; j < theme->balls[i].jumpphases; j++) {
|
||||
CHECKRET(gtkb_load_pixmap_from(trc, themepath,
|
||||
g_strdup_printf("ball.%d.jump.%d", i + 1, j + 1),
|
||||
&theme->balls[i].jump[j]),
|
||||
0);
|
||||
&theme->balls[i].jump[j]), 0);
|
||||
opt = g_strdup_printf("ball.%d.jump.%d.usec", i + 1, j + 1);
|
||||
theme->balls[i].jumpdelays[j] = trc_get_uint(trc, opt);
|
||||
g_free (opt);
|
||||
@ -247,18 +263,18 @@ GtkbTheme *gtkb_load_theme(gchar *themepath) {
|
||||
theme->balls[i].destroyphases = trc_get_uint(trc, opt);
|
||||
g_free (opt);
|
||||
CHECKRET(theme->balls[i].destroyphases, -1);
|
||||
if(theme->balls[i].destroyphases < 2) CHECKRET(0, 0); /* yes, i know. its ugly =) */
|
||||
if (theme->balls[i].destroyphases < 2) {
|
||||
CHECKRET(0, 0); /* yes, i know. its ugly =) */
|
||||
}
|
||||
if (theme->balls[i].destroyphases > theme->maxdestphases) {
|
||||
theme->maxdestphases = theme->balls[i].destroyphases;
|
||||
}
|
||||
theme->balls[i].destroy = g_new0(GtkbPixmap, theme->balls[i].destroyphases);
|
||||
theme->balls[i].destroydelays = g_new0(gint, theme->balls[i].destroyphases);
|
||||
|
||||
for (j = 0; j < theme->balls[i].destroyphases; j++) {
|
||||
CHECKRET(gtkb_load_pixmap_from(trc, themepath,
|
||||
g_strdup_printf("ball.%d.destroy.%d", i + 1, j + 1),
|
||||
&theme->balls[i].destroy[j]),
|
||||
0);
|
||||
&theme->balls[i].destroy[j]), 0);
|
||||
opt = g_strdup_printf("ball.%d.destroy.%d.usec", i + 1, j + 1);
|
||||
theme->balls[i].destroydelays[j] = trc_get_uint(trc, opt);
|
||||
g_free (opt);
|
||||
@ -270,16 +286,22 @@ GtkbTheme *gtkb_load_theme(gchar *themepath) {
|
||||
return theme;
|
||||
}
|
||||
|
||||
gint load_theme(gchar *themename) {
|
||||
|
||||
gint load_theme(gchar *themename)
|
||||
{
|
||||
gchar *themepath;
|
||||
GtkbTheme *theme;
|
||||
|
||||
if(!(themepath = find_theme_path(themename))) return 0;
|
||||
if (!(themepath = find_theme_path(themename))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
theme = gtkb_load_theme(themepath);
|
||||
g_free (themepath);
|
||||
|
||||
if(!theme) return 0;
|
||||
if (!theme) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
gtkb_theme_free(gtkbTheme);
|
||||
gtkbTheme = theme;
|
||||
@ -287,25 +309,33 @@ gint load_theme(gchar *themename) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
gint gtkb_theme_free_handler(GtkWidget *widget, gpointer data) {
|
||||
|
||||
gint gtkb_theme_free_handler(GtkWidget *widget, gpointer data)
|
||||
{
|
||||
gtkb_theme_free(gtkbTheme);
|
||||
gtkbTheme = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
gint gtkb_theme_get_balls_num(void) {
|
||||
|
||||
gint gtkb_theme_get_balls_num(void)
|
||||
{
|
||||
return gtkbTheme ? gtkbTheme->numballs : 0;
|
||||
}
|
||||
|
||||
|
||||
/* returns board coordinate of the pointer */
|
||||
gint gtkb_theme_get_coord_at_x(gint x) {
|
||||
gint gtkb_theme_get_coord_at_x(gint x)
|
||||
{
|
||||
if (gtkbTheme) {
|
||||
return (x - 1) / gtkbTheme->emptycell.xsize;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
gint gtkb_theme_get_coord_at_y(gint y) {
|
||||
|
||||
gint gtkb_theme_get_coord_at_y(gint y)
|
||||
{
|
||||
if (gtkbTheme) {
|
||||
return (y - 1) / gtkbTheme->emptycell.ysize;
|
||||
}
|
||||
@ -320,8 +350,10 @@ gint theme_get_height(void) {
|
||||
return gtkbTheme->emptycell.xsize;
|
||||
}
|
||||
|
||||
|
||||
/* find all available themes. */
|
||||
gchar **get_available_themes(void) {
|
||||
gchar **get_available_themes(void)
|
||||
{
|
||||
DIR *directory;
|
||||
struct dirent *dir_entry;
|
||||
struct stat entry_stat;
|
||||
@ -334,11 +366,14 @@ gchar **get_available_themes(void) {
|
||||
} else {
|
||||
hdir = g_strdup("./"); /* FIXME: does it work on non unix os? */
|
||||
}
|
||||
for(j = 0, currdir = INSTALLPATH, num = 0; j < 2; j++, currdir = hdir) {
|
||||
|
||||
for (j = 0, currdir = INSTALLPATH, num = 0; j < 2; j++, currdir = hdir)
|
||||
{
|
||||
if (!(directory = opendir(currdir))) {
|
||||
continue;
|
||||
}
|
||||
while((dir_entry = readdir(directory))) {
|
||||
while((dir_entry = readdir(directory)))
|
||||
{
|
||||
if (!strncmp(dir_entry->d_name, ".", 2) ||
|
||||
!strncmp(dir_entry->d_name, "..", 3)) {
|
||||
continue;
|
||||
@ -365,6 +400,7 @@ gchar **get_available_themes(void) {
|
||||
}
|
||||
closedir(directory);
|
||||
}
|
||||
|
||||
g_free (hdir);
|
||||
tlist = g_realloc(tlist, (num + 1) * sizeof(gchar *));
|
||||
tlist[num] = NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user