diff options
author | Vasily_Makarov <danilka.pro@gmail.com> | 2011-06-10 13:05:27 +0400 |
---|---|---|
committer | Vasily_Makarov <danilka.pro@gmail.com> | 2011-06-10 13:05:27 +0400 |
commit | d453d6488125405018bb066f80d8799309b323a6 (patch) | |
tree | 778d111dd631f4909c8799312106ad9e285d4447 /saedit | |
parent | 313e47124a149c26b0e004b0d249bceeb2a61559 (diff) | |
download | evol-tools-d453d6488125405018bb066f80d8799309b323a6.tar.gz evol-tools-d453d6488125405018bb066f80d8799309b323a6.tar.bz2 evol-tools-d453d6488125405018bb066f80d8799309b323a6.tar.xz evol-tools-d453d6488125405018bb066f80d8799309b323a6.zip |
saedit: Add background support
Diffstat (limited to 'saedit')
-rw-r--r-- | saedit/main.c | 56 | ||||
-rw-r--r-- | saedit/main.h | 23 |
2 files changed, 58 insertions, 21 deletions
diff --git a/saedit/main.c b/saedit/main.c index cf31128..b6ea880 100644 --- a/saedit/main.c +++ b/saedit/main.c @@ -18,18 +18,37 @@ sprite_info *sprite_info_new(int index, int offsetX, int offsetY) { res->offsetY = offsetY; return res; } +cairo_surface_t *get_grid_surface(int w, int h) { + cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, (w + 2) * GRID_SIZE, (h + 2) * GRID_SIZE); + cairo_t *cr = cairo_create(surface); + int x, y; + + cairo_surface_t *gridsurf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w * GRID_SIZE + 1, h * GRID_SIZE + 1); + cairo_t *scr = cairo_create(gridsurf); + + cairo_set_line_width(scr, 1); + + for (x = 0; x < w; x++) + for (y = 0; y < h; y++) { + gdk_cairo_set_source_pixbuf(cr, imageset->ground, x * GRID_SIZE, y * GRID_SIZE); + cairo_paint(cr); + cairo_rectangle(scr, x*GRID_SIZE+0.5, y*GRID_SIZE+0.5, GRID_SIZE, GRID_SIZE); + cairo_stroke(scr); + } + cairo_set_source_surface(cr, gridsurf, GRID_SIZE, GRID_SIZE); + cairo_paint(cr); + return surface; +} gboolean on_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data) { int width = widget->allocation.width, height = widget->allocation.height; + int w = 3, h = 3; + cairo_t *cr = gdk_cairo_create(widget->window); - cairo_surface_t *gridsurf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); - cairo_t *scr = cairo_create(gridsurf); - cairo_set_line_width(scr, 0.1); - cairo_rectangle(scr, width/2 -GRID_SIZE/2, height/2, GRID_SIZE, GRID_SIZE); - cairo_stroke(scr); - cairo_set_source_surface(cr, gridsurf, 0, 0); + + cairo_set_source_surface(cr, get_grid_surface(w, h), width/2 - GRID_SIZE * (w + 2) * 0.5, height/2 - GRID_SIZE * ((h + 2) * 0.5 - 0.5)); cairo_paint(cr); GdkPixbuf *pbuf = get_sprite_by_index(current_sprite->index); @@ -62,7 +81,7 @@ void open_xml_file(GtkButton *button, gpointer buffer) { } void free_imagesets() { - spriteset = NULL; + imageset->spriteset = NULL; imageset = imageset_info_new(); imagesets = NULL; gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(imagesetscombobox)))); @@ -133,8 +152,8 @@ gint xml_node_compare_with_name_attr(gconstpointer node, gconstpointer name) { GdkPixbuf* get_sprite_by_index(size_t index) { size_t w = spriteset_width/sprite_width; - if (spriteset == NULL) return NULL; - return gdk_pixbuf_new_subpixbuf(spriteset, index%w*sprite_width, index/w*sprite_height, sprite_width, sprite_height); + if (imageset->spriteset == NULL) return NULL; + return gdk_pixbuf_new_subpixbuf(imageset->spriteset, index%w*sprite_width, index/w*sprite_height, sprite_width, sprite_height); } void set_sprite_by_index(size_t index) { @@ -340,15 +359,26 @@ void set_up_imageset_by_node(XMLNode *node) { gchar path[255]; g_sprintf(path, "%s/%s", datapath, src); - spriteset = gdk_pixbuf_new_from_file(path, NULL); - spriteset_width = gdk_pixbuf_get_width(spriteset); - spriteset_height = gdk_pixbuf_get_height(spriteset); + imageset->spriteset = gdk_pixbuf_new_from_file(path, NULL); + spriteset_width = gdk_pixbuf_get_width(imageset->spriteset); + spriteset_height = gdk_pixbuf_get_height(imageset->spriteset); gchar *width = xml_node_get_attr_value(imageset->node, "width"); sscanf(width, "%d", &sprite_width); gchar *height = xml_node_get_attr_value(imageset->node, "height"); sscanf(height, "%d", &sprite_height); + GList *list = g_list_find_custom(root->sub_nodes, "background", xml_node_compare_with_name); + if (list != NULL) { + gchar *image_attr = xml_node_get_attr_value((XMLNode *)list->data, "image"); + if (image_attr != NULL) { + image_attr = g_strjoin(NULL, BACKGROUNDS_DIR, "/", image_attr, ".png", NULL); + GdkPixbuf *pbuf = gdk_pixbuf_new_from_file(image_attr, NULL); + if(pbuf != NULL) + imageset->ground = pbuf; + } + } + set_sprite_by_index(0); } @@ -522,7 +552,7 @@ gboolean frame_image_button_press_event(GtkWidget *widget, GdkEventButton *butto } void show_imageset_window() { - if (spriteset == NULL) return; + if (imageset->spriteset == NULL) return; GtkWidget *iwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(iwin), "Imageset preview"); gtk_window_set_position(GTK_WINDOW(iwin), GTK_WIN_POS_CENTER); diff --git a/saedit/main.h b/saedit/main.h index b211603..12f5f5a 100644 --- a/saedit/main.h +++ b/saedit/main.h @@ -17,6 +17,13 @@ #include <cairo.h> #include <glib/gi18n.h> +const int MIN_WIDTH = 600; +const int MIN_HEIGHT = 600; +const int SPRITE_WIDTH_DEFAULT = 64; +const int SPRITE_HEIGHT_DEFAULT = 64; +const int GRID_SIZE = 32; +const gchar *BACKGROUNDS_DIR = "backgrounds"; + typedef struct { XMLNode *node; GList *next; @@ -34,17 +41,15 @@ typedef struct { XMLNode *node; int offsetX; int offsetY; + GdkPixbuf *spriteset; + GdkPixbuf *ground; } imageset_info; static imageset_info *imageset_info_new() { - return g_new0(imageset_info, 1); + imageset_info *res = g_new0(imageset_info, 1); + res->ground = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, GRID_SIZE * 3, GRID_SIZE * 3); + return res; } -const int MIN_WIDTH = 600; -const int MIN_HEIGHT = 600; -const int SPRITE_WIDTH_DEFAULT = 64; -const int SPRITE_HEIGHT_DEFAULT = 64; -const int GRID_SIZE = 32; - int sprite_width = 64, sprite_height = 64; int spriteset_width, spriteset_height; @@ -59,7 +64,8 @@ GtkWidget *actionscombobox = NULL; GtkWidget *animationscombobox = NULL; GtkSourceBuffer *sbuf = NULL; -GdkPixbuf *spriteset = NULL; +//GdkPixbuf *spriteset = NULL; +//GdkPixbuf *ground = NULL; GList *imagesets = NULL; GList *actions = NULL; @@ -103,3 +109,4 @@ static void set_up_interface(); static void show_about_dialog(); static void show_imageset_window(); static gboolean frame_image_button_press_event(GtkWidget *widget, GdkEventButton *button, int index); +static cairo_surface_t *get_grid_surface(int w, int h); |