[AD] Grabber Patch

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Greets!

I tried to send it without subscribing, but didn't work. So let's
try now...
This is a patch to extend Grabber ability to crop tiles from
several bitmaps with the same name. The patch has been done
under MS-DOS, so I am not responsible. More information about it
at: http://www.allegro.cc/forums/view_thread.php?_id=183791
It was done with the 4.0.1 version (no CVS).

[PATCH START]
--- datgrid.c	Sun Mar 17 18:53:18 2002
+++ newgrid.c	Sun May 12 12:54:20 2002
@@ -31,6 +31,7 @@
 
 static void *added_item[1024];
 static int added_count;
+static char griddle_start[4] = "0";
 
 
 
@@ -250,6 +251,9 @@
    int x, y, w, h;
    int c = 0;
 
+   if (griddle_start[0] != '\0')
+       c = atoi(griddle_start);
+
    x = 0;
    y = 0;
 
@@ -280,6 +284,9 @@
    int x, y;
    int c = 0;
 
+   if (griddle_start[0] != '\0')
+       c = atoi(griddle_start);
+
    for (y=0; y+ygrid<=grabber_graphic->h; y+=ygrid) {
       for (x=0; x+xgrid<=grabber_graphic->w; x+=xgrid) {
 	 item = griddlit(parent, name, c, type, skipempty, autocrop, depth, x, y, xgrid, ygrid);
@@ -350,24 +357,26 @@
 static DIALOG griddle_dlg[] =
 {
    /* (dialog proc)     (x)   (y)   (w)   (h)   (fg)  (bg)  (key)    (flags)     (d1)           (d2)     (dp)                     (dp2) (dp3) */
-   { d_shadow_box_proc, 0,    0,    277,  305,  0,    0,    0,       0,          0,             0,       NULL,                    NULL, NULL  },
+   { d_shadow_box_proc, 0,    0,    277,  329,  0,    0,    0,       0,          0,             0,       NULL,                    NULL, NULL  },
    { d_ctext_proc,      138,  8,    0,    0,    0,    0,    0,       0,          0,             0,       "Grab from Grid",        NULL, NULL  },
    { d_radio_proc,      16,   32,   121,  13,   0,    0,    0,       D_SELECTED, 0,             0,       "Use col #255",          NULL, NULL  },
    { d_radio_proc,      16,   56,   121,  13,   0,    0,    0,       0,          0,             0,       "Regular grid",          NULL, NULL  },
-   { gg_text_proc,      160,  58,   0,    0,    0,    0,    0,       0,          0,             0,       "X-grid:",               NULL, NULL  },
-   { gg_edit_proc,      224,  58,   40,   8,    0,    0,    0,       0,          4,             0,       griddle_xgrid,           NULL, NULL  },
-   { gg_text_proc,      160,  80,   0,    0,    0,    0,    0,       0,          0,             0,       "Y-grid:",               NULL, NULL  },
-   { gg_edit_proc,      224,  82,   40,   8,    0,    0,    0,       0,          4,             0,       griddle_ygrid,           NULL, NULL  },
-   { d_check_proc,      16,   82,   123,  13,   0,    0,    0,       0,          0,             0,       "Skip empties:",         NULL, NULL  },
-   { d_check_proc,      16,   106,  91,   13,   0,    0,    0,       0,          0,             0,       "Autocrop:",             NULL, NULL  },
-   { d_text_proc,       16,   138,  0,    0,    0,    0,    0,       0,          0,             0,       "Name:",                 NULL, NULL  },
-   { d_edit_proc,       64,   138,  204,  8,    0,    0,    0,       0,          255,           0,       griddle_name,            NULL, NULL  },
-   { d_text_proc,       16,   160,  0,    0,    0,    0,    0,       0,          0,             0,       "Type:",                 NULL, NULL  },
-   { d_list_proc,       64,   160,  197,  36,   0,    0,    0,       0,          0,             0,       (void*)typelist_getter,  NULL, NULL  },
-   { d_text_proc,       16,   208,  0,    0,    0,    0,    0,       0,          0,             0,       "Cols:",                 NULL, NULL  },
-   { d_list_proc,       64,   208,  197,  44,   0,    0,    0,       0,          0,             0,       (void*)depthlist_getter, NULL, NULL  },
-   { d_button_proc,     50,   272,  81,   17,   0,    0,    13,      D_EXIT,     0,             0,       "OK",                    NULL, NULL  }, 
-   { d_button_proc,     146,  272,  81,   17,   0,    0,    27,      D_EXIT,     0,             0,       "Cancel",                NULL, NULL  }, 
+   { gg_text_proc,      160,  34,   0,    0,    0,    0,    0,       0,          0,             0,       "X-grid:",               NULL, NULL  },
+   { gg_edit_proc,      224,  34,   40,   8,    0,    0,    0,       0,          4,             0,       griddle_xgrid,           NULL, NULL  },
+   { gg_text_proc,      160,  58,   0,    0,    0,    0,    0,       0,          0,             0,       "Y-grid:",               NULL, NULL  },
+   { gg_edit_proc,      224,  58,   40,   8,    0,    0,    0,       0,          4,             0,       griddle_ygrid,           NULL, NULL  },
+   { d_text_proc,       16,   86,   0,    0,    0,    0,    0,       0,          0,             0,       "From:",                 NULL, NULL  },
+   { d_edit_proc,       64,   86,   123,  13,   0,    0,    0,       0,          3,             0,       griddle_start,           NULL, NULL  },
+   { d_check_proc,      16,   106,   123,  13,   0,    0,    0,       0,          0,             0,       "Skip empties:",         NULL, NULL  },
+   { d_check_proc,      16,   130,  91,   13,   0,    0,    0,       0,          0,             0,       "Autocrop:",             NULL, NULL  },
+   { d_text_proc,       16,   162,  0,    0,    0,    0,    0,       0,          0,             0,       "Name:",                 NULL, NULL  },
+   { d_edit_proc,       64,   162,  204,  8,    0,    0,    0,       0,          255,           0,       griddle_name,            NULL, NULL  },
+   { d_text_proc,       16,   184,  0,    0,    0,    0,    0,       0,          0,             0,       "Type:",                 NULL, NULL  },
+   { d_list_proc,       64,   184,  197,  36,   0,    0,    0,       0,          0,             0,       (void*)typelist_getter,  NULL, NULL  },
+   { d_text_proc,       16,   232,  0,    0,    0,    0,    0,       0,          0,             0,       "Cols:",                 NULL, NULL  },
+   { d_list_proc,       64,   232,  197,  44,   0,    0,    0,       0,          0,             0,       (void*)depthlist_getter, NULL, NULL  },
+   { d_button_proc,     50,   296,  81,   17,   0,    0,    13,      D_EXIT,     0,             0,       "OK",                    NULL, NULL  }, 
+   { d_button_proc,     146,  296,  81,   17,   0,    0,    27,      D_EXIT,     0,             0,       "Cancel",                NULL, NULL  }, 
    { NULL,              0,    0,    0,    0,    0,    0,    0,       0,          0,             0,       NULL,                    NULL, NULL  }
 };
 
@@ -376,13 +385,13 @@
 #define GRIDDLE_DLG_GRID         3
 #define GRIDDLE_DLG_XGRID        5
 #define GRIDDLE_DLG_YGRID        7
-#define GRIDDLE_DLG_EMPTIES      8
-#define GRIDDLE_DLG_AUTOCROP     9
-#define GRIDDLE_DLG_NAME         11
-#define GRIDDLE_DLG_TYPE         13
-#define GRIDDLE_DLG_DEPTH        15
-#define GRIDDLE_DLG_OK           16
-#define GRIDDLE_DLG_CANCEL       17
+#define GRIDDLE_DLG_EMPTIES      10
+#define GRIDDLE_DLG_AUTOCROP     11
+#define GRIDDLE_DLG_NAME         13
+#define GRIDDLE_DLG_TYPE         15
+#define GRIDDLE_DLG_DEPTH        17
+#define GRIDDLE_DLG_OK           18
+#define GRIDDLE_DLG_CANCEL       19
 
 
 
@@ -441,22 +450,7 @@
 /* checks whether an object name matches the grid grab base name */
 static int grid_name_matches(AL_CONST char *gn, AL_CONST char *n)
 {
-   AL_CONST char *s;
-
-   if (strncmp(gn, n, strlen(gn)) != 0)
-      return FALSE;
-
-   s = n + strlen(gn);
-   if (*s == 0)
-      return FALSE;
-
-   while (*s) {
-      if (!uisdigit(*s))
-	 return FALSE;
-      s++;
-   }
-
-   return TRUE;
+   return ((strcmp(gn, n) != 0)? FALSE : TRUE);
 }
 
 
@@ -467,8 +461,9 @@
    DATAFILE *dat;
    DATAFILE **parent;
    void *selitem;
+   char i[256];
    char *s;
-   int c;
+   int c, d = 0;
    int xgrid, ygrid;
    int done, type, skipempty, autocrop;
    int depth = 8;
@@ -531,12 +526,16 @@
 
    grabber_sel_palette(grabber_palette);
 
+   if (griddle_start[0] != '\0')
+       d = atoi(griddle_start);
+   sprintf(i, "%s%03d", griddle_name, d);
    do {
       done = TRUE;
 
       for (c=0; (*parent)[c].type != DAT_END; c++) {
-	 if (grid_name_matches(griddle_name, get_datafile_property((*parent)+c, DAT_NAME))) {
+	 if (grid_name_matches(i, get_datafile_property((*parent)+c, DAT_NAME))) {
 	    *parent = datedit_delete(*parent, c);
+        sprintf(i, "%s%03d", griddle_name, ++d);
 	    done = FALSE;
 	    break;
 	 }
[PATCH END]

I was thinking about some more changes:

 1. Don't show unsupported colors (ie: 16 bpp if not compiled
    with ALLEGRO_COLOR16).
 2. Possible problem with "%03d" (since now it is possible to
    grab several bitmaps with the same name, you might be able
    to have +999 objects). Adding maximun amount of numbers as
    a new parameter to modify?
 3. Upgrading box_out(char *) function (speeding it up, maybe
    by using a double buffer to prevent those set_clip(), or
    replacing it with a progress bar displaying object names).
    Or as a plugin?
 4. Don't allow user to input two equal names, or an option to
    automagically add the type to the name (_SAMP, _PCX, etc).
 5. Multiple "Set/Edit/Delete Property", (only if the property
    is not NAME, like setting the MANA to all wizards in the
    datafile).
 6. save() shows an alert that might be very long if there are
    many directories. Maybe only a maximun of characters in
    each alert() line to prevent the box being clipped?
 7. Export datafile plugin (multiple selection as a new one)?
 8. Help system as a new plugin?

Thanks for listening/reading!
Roberto Alfonso



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/