Changeset 561

Show
Ignore:
Timestamp:
09/15/07 23:14:11 (1 year ago)
Author:
shanoah
Message:

Lower the gtk ports memory consumption, fix a few possible leaks, and fix the birth options issue from [557].

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/cairo-utils.c

    r560 r561  
    2525void set_foreground_color(cairo_t *cr, byte a) 
    2626{ 
    27         double red, green, blue; 
    28  
    29         red   = angband_color_table[a][1] * 256; 
    30         green = angband_color_table[a][2] * 256; 
    31         blue  = angband_color_table[a][3] * 256; 
    32          
    33         cairo_set_source_rgb(cr, red / 65536, green / 65536, blue / 65536); 
     27        cairo_set_source_rgb(cr,  
     28        (double)angband_color_table[a][1] / 256,  
     29        (double)angband_color_table[a][2] / 256,  
     30        (double)angband_color_table[a][3] / 256); 
    3431} 
    3532 
     
    4441void c_rect(cairo_t *cr, cairo_rectangle_t r) 
    4542{ 
    46         cairo_rectangle (cr, r.x, r.y, r.width, r.height); 
     43        if (cr !=NULL) 
     44                cairo_rectangle (cr, r.x, r.y, r.width, r.height); 
    4745} 
    4846 
     
    5250void cairo_clear(cairo_t *cr, cairo_rectangle_t r, byte c) 
    5351{ 
    54         cairo_save(cr); 
    55         c_rect(cr, r); 
    56         set_foreground_color(cr, c); 
    57         cairo_fill(cr); 
    58         cairo_close_path(cr); 
    59         cairo_restore(cr); 
     52        if (cr !=NULL) 
     53        { 
     54                cairo_save(cr); 
     55                c_rect(cr, r); 
     56                set_foreground_color(cr, c); 
     57                cairo_fill(cr); 
     58                cairo_close_path(cr); 
     59                cairo_restore(cr); 
     60        } 
    6061} 
    6162 
    6263void cairo_cursor(cairo_t *cr, cairo_rectangle_t r, byte c) 
    6364{ 
    64         cairo_save(cr); 
    65         c_rect(cr, r); 
    66         set_foreground_color(cr, c); 
    67          
    68         cairo_set_operator(cr, CAIRO_OPERATOR_ADD); 
    69         cairo_fill(cr); 
    70         cairo_close_path(cr); 
    71         cairo_restore(cr); 
     65        if (cr !=NULL) 
     66        { 
     67                cairo_save(cr); 
     68                c_rect(cr, r); 
     69                set_foreground_color(cr, c); 
     70         
     71                cairo_set_operator(cr, CAIRO_OPERATOR_ADD); 
     72                cairo_fill(cr); 
     73                cairo_close_path(cr); 
     74                cairo_restore(cr); 
     75        } 
    7276} 
    7377 
    7478void draw_tile(cairo_t *cr, cairo_matrix_t m, cairo_rectangle_t r, int tx, int ty) 
    7579{ 
    76          
    77         cairo_save(cr);  
    78          
    79         /* Use the rect and pattern */ 
    80         c_rect(cr, r); 
    81         cairo_set_source (cr, tile_pattern); 
    82          
    83         /* Pull the tile we need */ 
    84         cairo_surface_set_device_offset(graphical_tiles, tx - r.x, ty - r.y); 
    85          
    86         /* Use transparency */ 
    87         cairo_set_operator(cr, CAIRO_OPERATOR_ADD); 
    88          
    89         /* Use the matrix with our pattern */ 
    90         cairo_pattern_set_matrix(tile_pattern, &m); 
    91          
    92         /* Draw it */ 
    93         cairo_fill(cr); 
    94          
    95         cairo_restore(cr); 
     80        if (cr !=NULL) 
     81        { 
     82                cairo_save(cr);  
     83         
     84                /* Use the rect and pattern */ 
     85                c_rect(cr, r); 
     86                cairo_set_source (cr, tile_pattern); 
     87         
     88                /* Pull the tile we need */ 
     89                cairo_surface_set_device_offset(graphical_tiles, tx - r.x, ty - r.y); 
     90         
     91                /* Use transparency */ 
     92                cairo_set_operator(cr, CAIRO_OPERATOR_ADD); 
     93         
     94                /* Use the matrix with our pattern */ 
     95                cairo_pattern_set_matrix(tile_pattern, &m); 
     96         
     97                /* Draw it */ 
     98                cairo_fill(cr); 
     99         
     100                cairo_restore(cr); 
     101        } 
    96102} 
    97103 
     
    101107        double sx, sy; 
    102108 
    103         /* Get a matrix set up to scale the graphics. */ 
    104         cairo_get_matrix(cr, &m); 
    105         sx = (tile_w)/(font_w); 
    106         sy = (tile_h)/(font_h); 
    107          
    108         cairo_matrix_scale(&m, sx, sy); 
     109        if (cr !=NULL) 
     110        { 
     111                /* Get a matrix set up to scale the graphics. */ 
     112                cairo_get_matrix(cr, &m); 
     113                sx = (tile_w)/(font_w); 
     114                sy = (tile_h)/(font_h); 
     115         
     116                cairo_matrix_scale(&m, sx, sy); 
     117        } 
    109118        return(m); 
    110119} 
    111120 
    112121void cairo_draw_from_surface(cairo_t *cr, cairo_surface_t *surface, cairo_rectangle_t r) 
    113 
    114         cairo_save(cr); 
    115         c_rect(cr, r); 
    116         cairo_set_source_surface(cr, surface, 0, 0); 
    117         cairo_fill(cr); 
    118         cairo_restore(cr); 
     122{        
     123        if (cr !=NULL) 
     124        { 
     125                cairo_save(cr); 
     126                c_rect(cr, r); 
     127                cairo_set_source_surface(cr, surface, 0, 0); 
     128                cairo_fill(cr); 
     129                cairo_restore(cr); 
     130        } 
    119131} 
    120132 
     
    136148        int cx, cy; 
    137149         
     150        if (cr !=NULL) 
     151        { 
    138152        /* Get a matrix set up to scale the graphics. */ 
    139153        m = cairo_font_scaling(cr, tile.w, tile.h, font.w, font.h); 
     
    164178                draw_tile(cr, m, char_rect, tx, ty); 
    165179        } 
     180        } 
    166181} 
    167182 
     
    194209        font->w = r.width; 
    195210        font->h = r.height; 
    196  
     211         
     212        pango_font_description_free(temp_font); 
    197213        cairo_destroy(cr); 
    198214        cairo_surface_destroy(surface); 
    199215        g_object_unref(temp); 
    200216} 
     217 
    201218void draw_text(cairo_t *cr, font_info *font, int x, int y, int n, byte a, cptr s) 
    202219{ 
     
    205222        PangoFontDescription *temp_font; 
    206223         
     224        if (cr !=NULL) 
     225        { 
    207226        init_cairo_rect(&r, x * font->w, y * font->h,  font->w * n, font->h); 
    208227         
     
    220239        pango_cairo_show_layout(cr, layout); 
    221240        g_object_unref(G_OBJECT(layout)); 
     241        } 
    222242} 
    223243 
  • trunk/src/main-gtk.c

    r560 r561  
    3636 */ 
    3737 /*#define DISABLE_GTK_TESTING*/ 
    38   
    39 static game_command cmd = { CMD_NULL, 0 };  
     38 
     39static int max_win_width(term_data *td) 
     40
     41        return (255 * td->font.w); 
     42
     43 
     44static int max_win_height(term_data *td) 
     45
     46        return(255 * td->font.h); 
     47
     48 
     49static int drawing_win_width(term_data *td) 
     50
     51        return (td->cols * td->font.w); 
     52
     53 
     54static int drawing_win_height(term_data *td) 
     55
     56        return(td->rows * td->font.h); 
     57
     58 
     59static int row_in_pixels(term_data *td, int x) 
     60
     61        return(x * td->font.w); 
     62
     63 
     64static int col_in_pixels(term_data *td, int y) 
     65
     66        return(y * td->font.h); 
     67
     68 
     69/* 
     70 * Find the square a particular pixel is part of. 
     71 */ 
     72static void pixel_to_square(int * const x, int * const y, const int ox, const int oy) 
     73
     74        term_data *td = (term_data*)(Term->data); 
     75 
     76        (*x) = (ox / td->font.w); 
     77        (*y) = (oy / td->font.h); 
     78
    4079 
    4180static GdkRectangle cairo_rect_to_gdk(cairo_rectangle_t *r) 
     
    71110} 
    72111 
     112static void term_data_resize(term_data *td) 
     113{ 
     114        term *old = Term; 
     115        /* Activate the term */ 
     116        Term_activate(&td->t); 
     117 
     118        Term_resize(td->cols, td->rows); 
     119         
     120        /* Redraw the contents */ 
     121        Term_redraw(); 
     122 
     123        /* Flush the output */ 
     124        Term_fresh(); 
     125        Term_key_push(KTRL('R')); 
     126        Term_activate(old); 
     127} 
    73128/*  
    74129 * Get the position of the window and save it. Gtk being what it is, this is a major hack. 
     
    141196                if (((w != 200) && (h != 190)) || ((w <= 100) && (h <= 100))) 
    142197                { 
     198                        /*int cols = td->cols; 
     199                        int rows = td->rows;*/ 
     200                         
    143201                        if (w != 0)  
    144202                        { 
     
    151209                                td->rows= td->size.h / td->font.h; 
    152210                        } 
     211                        /*if ((cols != td->cols) || (rows != td->rows)) 
     212                                term_data_resize(td);*/ 
    153213                } 
    154214                 
     
    199259        geo.height_inc = td->font.h; 
    200260         
    201         /*geo.max_width = td->font.w * 255
    202         geo.max_height = td->font.h * 255;*/ 
     261        /*geo.max_width = max_win_width()
     262        geo.max_height = max_win_height();*/ 
    203263         
    204264        /*geo.min_width = td->font.w; 
     
    273333        cairo_rectangle_t r; 
    274334         
    275         init_cairo_rect(&r, 0, 0, 255 * td->font.w, 255 * td->font.h); 
     335        init_cairo_rect(&r, 0, 0, max_win_width(td), max_win_height(td)); 
    276336        cairo_clear(td->cr, r, TERM_DARK); 
    277337        invalidate_rect(td, r); 
     
    290350         
    291351        /* Set dimensions */ 
    292         init_cairo_rect(&r, (x * td->font.w), (y * td->font.h), (td->font.w * n), (td->font.h)); 
     352        init_cairo_rect(&r, row_in_pixels(td, x), col_in_pixels(td, y), (td->font.w * n), (td->font.h)); 
    293353        cairo_clear(td->cr, r, TERM_DARK); 
    294354        invalidate_rect(td, r); 
     
    307367         
    308368        /* Set dimensions */ 
    309         init_cairo_rect(&r, x * td->font.w, y * td->font.h,  td->font.w * n, td->font.h); 
     369        init_cairo_rect(&r, row_in_pixels(td, x), col_in_pixels(td, y),  td->font.w * n, td->font.h); 
    310370         
    311371        /* Clear the line */ 
     
    327387         
    328388        /* Set dimensions */ 
    329         init_cairo_rect(&r, x * td->font.w, y * td->font.h,  td->font.w * n, td->font.h); 
     389        init_cairo_rect(&r, row_in_pixels(td, x), col_in_pixels(td, y),  td->font.w * n, td->font.h); 
    330390         
    331391        /* Clear the line */ 
     
    353413        cairo_rectangle_t r; 
    354414         
    355         init_cairo_rect(&r, 0, 0, 255 * td->font.w, 255 * td->font.h); 
     415        init_cairo_rect(&r, 0, 0, max_win_width(td), max_win_height(td)); 
    356416        invalidate_rect(td, r); 
    357417        gdk_window_process_updates(td->window->window, 1); 
     
    416476 
    417477        /* Set dimensions */ 
    418         init_cairo_rect(&r, (x * td->font.w) +1, (y * td->font.h) + 1,  (td->font.w) - 2, (td->font.h) - 2); 
     478        init_cairo_rect(&r, row_in_pixels(td, x)+1, col_in_pixels(td, y) + 1,  (td->font.w) - 2, (td->font.h) - 2); 
    419479        cairo_cursor(td->cr, r, TERM_SLATE); 
    420480        invalidate_rect(td, r); 
     
    486546        save_prefs(); 
    487547        do_cmd_save_game(); 
     548        release_memory(); 
    488549        gtk_exit(0); 
    489550} 
     
    515576{ 
    516577        term_data *td = user_data; 
    517         term_data *main_term = &data[0]; 
    518578        GtkWidget *menu_item; 
    519579        char item_name[20]; 
     
    522582        { 
    523583        strnfmt(item_name, 16+1,  "term_menu_item_%i", td->number); 
    524         menu_item = glade_xml_get_widget(main_term->xml, item_name); 
     584        menu_item = glade_xml_get_widget(gtk_xml, item_name); 
    525585        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_item), FALSE); 
    526586        } 
     
    561621         
    562622        get_font_size(&td->font); 
    563         td->size.w = td->font.w * td->cols
    564         td->size.h = td->font.h * td->rows
     623        td->size.w =drawing_win_width(td)
     624        td->size.h = drawing_win_height(td)
    565625         
    566626        if (td->window != NULL)  
     
    570630        set_window_size(td); 
    571631                 
    572         Term_flush(); 
    573         term_data_redraw(td); 
     632        create_term_cairo(td); 
    574633        } 
    575634} 
     
    791850        switch (event->keyval) 
    792851        { 
    793                 /*case 's': 
    794                 { 
    795                         if (mc) 
    796                         { 
    797                                 GtkWidget *menu; 
    798                                 term_data* main_term = &data[0]; 
    799                                  
    800                                 menu = glade_xml_get_widget(main_term->xml, "save_menu_item"); 
    801                                 gtk_widget_activate(menu); 
    802                         } 
    803                 }*/ 
    804852                case GDK_Escape: 
    805853                { 
     
    11031151                if (td->rows == 0) td->rows = 24; 
    11041152                         
    1105                 if (td->size.w <=0) td->size.w = td->font.w * td->cols
    1106                 if (td->size.h <=0) td->size.h = td->font.h * td->rows
     1153                if (td->size.w <=0) td->size.w = drawing_win_width(td)
     1154                if (td->size.h <=0) td->size.h = drawing_win_height(td)
    11071155                if (td->tile.w <= 0) td->tile.w = td->font.w; 
    11081156                if (td->tile.h <= 0) td->tile.h = td->font.h; 
     
    11411189} 
    11421190 
    1143 /* 
    1144  * Find the square a particular pixel is part of. 
    1145  */ 
    1146 static void pixel_to_square(int * const x, int * const y, const int ox, const int oy) 
    1147 { 
    1148         term_data *td = (term_data*)(Term->data); 
    1149  
    1150         (*x) = (ox / td->font.w); 
    1151         (*y) = (oy / td->font.h); 
    1152 } 
    1153  
    11541191gboolean on_mouse_click(GtkWidget *widget, GdkEventButton *event, gpointer user_data) 
    11551192{ 
     
    12261263} 
    12271264 
     1265static void create_term_cairo(term_data *td) 
     1266{        
     1267                measurements size; 
     1268                 
     1269                if (td->surface != NULL) 
     1270                {        
     1271                        cairo_surface_destroy(td->surface); 
     1272                        cairo_destroy(td->cr); 
     1273                } 
     1274         
     1275                size.w = max_win_width(td); 
     1276                size.h = max_win_height(td); 
     1277                 
     1278                td->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, size.w, size.h); 
     1279                td->cr = cairo_create(td->surface); 
     1280                 
     1281                term_data_redraw(td); 
     1282} 
     1283 
    12281284gboolean toggle_term_window(GtkWidget *widget, GdkEvent *event, gpointer user_data) 
    12291285{ 
     
    12421298                         
    12431299        if (td->visible) 
     1300        { 
     1301                create_term_cairo(td); 
    12441302                gtk_widget_show(td->window); 
     1303        } 
    12451304        else 
    12461305                gtk_widget_hide(td->window); 
     
    13451404static void setup_graphics_menu() 
    13461405{ 
    1347         term_data *main_term= &data[0]; 
    13481406        int i = 0; 
    13491407         
     
    13551413                 
    13561414                strnfmt(s, 12, "graphics_%d", i); 
    1357                 menu = glade_xml_get_widget(main_term->xml, s); 
     1415                menu = glade_xml_get_widget(gtk_xml, s); 
    13581416                if (checked) 
    13591417                        if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu))) 
     
    13701428        s = (char*)gtk_widget_get_name(widget); 
    13711429        sscanf(s, "graphics_%d", &g); 
     1430         
     1431        /* Free up old graphics */ 
     1432        if (graphical_tiles != NULL) 
     1433                cairo_surface_destroy(graphical_tiles); 
     1434        if (tile_pattern != NULL) 
     1435                cairo_pattern_destroy(tile_pattern); 
     1436         
    13721437        init_graf(g); 
    13731438        return(FALSE); 
     
    14081473                 
    14091474                strnfmt(temp, 14, "xtra_font_%d", i); 
    1410                 temp_widget = glade_xml_get_widget(main_term->xml, temp); 
     1475                temp_widget = glade_xml_get_widget(gtk_xml, temp); 
    14111476                gtk_font_button_set_font_name(GTK_FONT_BUTTON (temp_widget), xd->font.name); 
    14121477 
    1413                 xd->win = glade_xml_get_widget(main_term->xml, xd->win_name); 
     1478                xd->win = glade_xml_get_widget(gtk_xml, xd->win_name); 
    14141479                g_signal_connect(xd->win, "delete_event", GTK_SIGNAL_FUNC(xtra_hide_event_handler), xd); 
    14151480                g_signal_connect(xd->win, "configure_event", G_CALLBACK(configure_xtra_event_handler), xd); 
    14161481                gtk_window_set_title(GTK_WINDOW(xd->win), xd->name); 
    14171482                 
    1418                 xd->menu = glade_xml_get_widget(main_term->xml, xd->item_name); 
     1483                xd->menu = glade_xml_get_widget(gtk_xml, xd->item_name); 
    14191484                g_signal_connect(xd->menu, "activate", G_CALLBACK(toggle_xtra_window), (gpointer) xd->name); 
    14201485                 
     
    14231488                #endif 
    14241489                 
    1425                 xd->text_view = glade_xml_get_widget(main_term->xml, xd->text_view_name); 
    1426                 xd->drawing_area = glade_xml_get_widget(main_term->xml, xd->drawing_area_name); 
     1490                xd->text_view = glade_xml_get_widget(gtk_xml, xd->text_view_name); 
     1491                xd->drawing_area = glade_xml_get_widget(gtk_xml, xd->drawing_area_name); 
    14271492                if (xd->text_view != NULL) 
    14281493                { 
     
    14471512        int i = 0; 
    14481513        bool err; 
    1449         term_data *main_term= &data[0]; 
    14501514         
    14511515        /* Build the paths */ 
    14521516        path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA, "angband.glade"); 
     1517        gtk_xml = glade_xml_new(buf, NULL, NULL); 
     1518         
     1519        if (gtk_xml == NULL) 
     1520        { 
     1521                gtk_log_fmt(TERM_RED, "%s is Missing. Unrecoverable error. Aborting!", buf); 
     1522                quit(NULL); 
     1523                gtk_exit(0); 
     1524        } 
     1525                         
    14531526        path_build(logo, sizeof(logo), ANGBAND_DIR_XTRA, "graf/mr_att.png"); 
    14541527        err = gtk_window_set_default_icon_from_file(logo, NULL); 
     
    14601533                if (!MAIN_WINDOW(td)) 
    14611534                { 
     1535                        GladeXML *xml; 
     1536                         
    14621537                        /* Set up the Glade file */ 
    1463                         td->xml = glade_xml_new(buf, "term-window", NULL); 
    1464                  
    1465                         td->window = glade_xml_get_widget(td->xml, "term-window"); 
    1466                         td->drawing_area = glade_xml_get_widget(td->xml, "drawingarea2"); 
     1538                        xml = glade_xml_new(buf, "term-window", NULL); 
     1539                 
     1540                        td->window = glade_xml_get_widget(xml, "term-window"); 
     1541                        td->drawing_area = glade_xml_get_widget(xml, "drawingarea2"); 
     1542                         
     1543                        g_object_unref (xml); 
    14671544                } 
    14681545                else 
    14691546                { 
    1470                         td->xml = glade_xml_new(buf, NULL, NULL); 
    1471                         td->window = glade_xml_get_widget(td->xml, "main-window"); 
     1547                        td->window = glade_xml_get_widget(gtk_xml, "main-window"); 
     1548                        td->drawing_area = glade_xml_get_widget(gtk_xml, "drawingarea1"); 
     1549                        options = glade_xml_get_widget(gtk_xml, "options_window"); 
    14721550                         
    1473                         if (td->xml == NULL) 
    1474                         { 
    1475                                 gtk_log_fmt(TERM_RED, "%s is Missing. Unrecoverable error. Aborting!", buf); 
    1476                                 quit(NULL); 
    1477                                 gtk_exit(0); 
    1478                         } 
    1479                         td->drawing_area = glade_xml_get_widget(td->xml, "drawingarea1"); 
    1480                          
    1481                         options = glade_xml_get_widget(td->xml, "options_window"); 
    14821551                        g_signal_connect(options, "delete_event", GTK_SIGNAL_FUNC(hide_options), NULL); 
    14831552                } 
     
    15001569 
    15011570        /* connect signal handlers that aren't passed data */ 
    1502         glade_xml_signal_autoconnect(main_term->xml); 
     1571        glade_xml_signal_autoconnect(gtk_xml); 
    15031572         
    15041573        setup_graphics_menu(); 
     
    15071576        for (i = 0; i < num_term; i++) 
    15081577        { 
    1509                 measurements size; 
    15101578                term_data *td = &data[i]; 
     1579                GdkColor black =  { 0, 0x0000, 0x0000, 0x0000 }; 
    15111580                 
    15121581                gtk_widget_realize(td->window); 
    15131582                gtk_widget_realize(td->drawing_area);  
    1514          
    1515                 size.w = 255 * td->font.w; 
    1516                 size.h = 255 * td->font.h; 
    1517                  
    1518                 td->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, size.w, size.h); 
    1519                 td->cr = cairo_create(td->surface); 
     1583                 
     1584                gtk_widget_modify_bg(td->window, GTK_STATE_NORMAL, &black); 
     1585                gtk_widget_modify_bg(td->drawing_area, GTK_STATE_NORMAL, &black); 
    15201586                 
    15211587                strnfmt(temp, 14, "term_font_%d", i); 
    1522                 temp_widget = glade_xml_get_widget(main_term->xml, temp); 
     1588                temp_widget = glade_xml_get_widget(gtk_xml, temp); 
    15231589                gtk_widget_realize(temp_widget); 
    15241590                 
     
    15261592        } 
    15271593} 
    1528  
    15291594static void show_windows() 
    15301595{ 
    15311596        int i; 
    15321597        GtkWidget *menu_item; 
    1533         term_data *main_term = &data[0]; 
    15341598         
    15351599        /* Initialize the windows */ 
     
    15421606                Term_activate(&data[i].t); 
    15431607                 
    1544                 Term_clear_gtk();  
    1545                  
    15461608                set_window_size(td); 
    15471609                 
    15481610                strnfmt(item_name, 16+1,  "term_menu_item_%i", i); 
    1549                  
    1550                 menu_item = glade_xml_get_widget(main_term->xml, item_name); 
    1551                  
     1611                menu_item = glade_xml_get_widget(gtk_xml, item_name); 
     1612                 
     1613        if (td->visible) 
     1614                        create_term_cairo(td); 
     1615                         
    15521616                if (i == 0) 
     1617                { 
    15531618                        gtk_widget_show(td->window); 
     1619                } 
    15541620                else if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_item)) != td->visible) 
    15551621                        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_item), td->visible); 
     1622                 
     1623                Term_clear_gtk();  
    15561624        } 
    15571625         
     
    15661634        } 
    15671635} 
     1636 
     1637 
     1638static void xtra_data_destroy(xtra_win_data *xd) 
     1639{ 
     1640        if GTK_IS_WIDGET(xd->win) 
     1641                gtk_widget_destroy(xd->win); 
     1642        if GTK_IS_WIDGET(xd->text_view) 
     1643                gtk_widget_destroy(xd->text_view); 
     1644        if GTK_IS_WIDGET(xd->menu) 
     1645                gtk_widget_destroy(xd->menu); 
     1646        if GTK_IS_WIDGET(xd->drawing_area) 
     1647                gtk_widget_destroy(xd->drawing_area); 
     1648         
     1649        cairo_surface_destroy(xd->surface); 
     1650        cairo_destroy(xd->cr); 
     1651} 
     1652 
     1653static void term_data_destroy(term_data *td) 
     1654{        
     1655        if GTK_IS_WIDGET(td->window) 
     1656                gtk_widget_destroy(td->window); 
     1657        if GTK_IS_WIDGET(td->drawing_area) 
     1658                gtk_widget_destroy(td->drawing_area); 
     1659         
     1660        cairo_surface_destroy(td->surface); 
     1661        cairo_destroy(td->cr); 
     1662} 
     1663 
     1664static void release_memory() 
     1665{ 
     1666        int i; 
     1667         
     1668        cairo_pattern_destroy(tile_pattern); 
     1669        cairo_surface_destroy(graphical_tiles); 
     1670         
     1671        /* Load Extra Windows */ 
     1672        for (i = 0; i < MAX_XTRA_WIN_DATA; i++) 
     1673        { 
     1674                xtra_win_data *xd = &xdata[i]; 
     1675                 
     1676                xtra_data_destroy(xd); 
     1677        } 
     1678         
     1679        /* Initialize the windows */ 
     1680        for (i = 0; i < num_term; i++) 
     1681        { 
     1682                term_data *td = &data[i]; 
     1683                 
     1684                term_data_destroy(td); 
     1685        } 
     1686         
     1687        g_object_unref (gtk_xml); 
     1688} 
     1689 
    15681690static errr term_data_init(term_data *td, int i) 
    15691691{ 
  • trunk/src/main-gtk.h

    r560 r561  
    7676        GtkWidget *window; 
    7777        GtkWidget *drawing_area; 
    78         GladeXML *xml; 
    7978}; 
    8079 
     
    8483        cptr name, win_name, text_view_name, item_name, drawing_area_name; 
    8584        bool visible; 
    86         /*char font_name[256];*/ 
    8785        font_info font; 
    8886         
     
    163161/*  Path to the Gtk settings file */ 
    164162static char settings[1024]; 
     163static game_command cmd = { CMD_NULL, 0 };  
     164 
     165GladeXML *gtk_xml; 
     166 
     167/* Abstracted out for future changes */ 
     168static int max_win_width(term_data *td); 
     169static int max_win_height(term_data *td); 
     170static int drawing_win_width(term_data *td); 
     171static int drawing_win_height(term_data *td); 
     172static int drawing_win_width(term_data *td); 
     173static int drawing_win_height(term_data *td); 
     174 
     175/* 
     176 * Find the square a particular pixel is part of. 
     177 */ 
     178static void pixel_to_square(int * const x, int * const y, const int ox, const int oy); 
    165179 
    166180/* Cairo's rect type to Gdks */ 
     
    172186/* Mark part of a window as invalid, so it gets redrawn */ 
    173187static void invalidate_rect(term_data *td, cairo_rectangle_t r); 
    174  
    175188 
    176189/*  
     
    235248static void term_data_redraw(term_data *td); 
    236249 
     250static void create_term_cairo(term_data *td); 
    237251/* Check for events - Traditional */ 
    238252static errr CheckEvent(bool wait); 
     
    296310/* Load the prefs */ 
    297311static void load_prefs(); 
    298  
    299 /* Find the square a particular pixel is part of. */ 
    300 static void pixel_to_square(int * const x, int * const y, const int ox, const int oy); 
    301312 
    302313/* Register a mouse click */ 
     
    414425errr init_gtk(int argc, char **argv); 
    415426 
     427/* Nuke things */ 
     428static void xtra_data_destroy(xtra_win_data *xd); 
     429static void term_data_destroy(term_data *td); 
     430static void release_memory(); 
    416431#endif /* INCLUDED_MAIN_GTK_H */  
  • trunk/src/option.c

    r557 r561  
    9797                OPT_birth_ai_cheat, 
    9898                OPT_birth_ai_smart, 
     99                OPT_NONE, 
    99100        }, 
    100101