diff --git a/Makefile.windows b/Makefile.windows index 12447bd..c92eb11 100644 --- a/Makefile.windows +++ b/Makefile.windows @@ -1,5 +1,5 @@ netmapr: netmapr.c constants.h netmapr.h Makefile - gcc -Wall -g netmapr.c -I/usr/local/include -onetmapr -lmingw32 -L/usr/local/lib -lSDLmain -lSDL -mwindows + gcc -mwindows -mno-cygwin -Wall -onetmapr.exe -g netmapr.c windows_files/attachicon.res -I/usr/local/include -lmingw32 -L/usr/local/lib -lSDLmain -lSDL -lSDL_ttf convert: convert.c convert.h Makefile gcc -Wall -g convert.c -I/usr/local/include -oconvert -lmingw32 -L/usr/local/lib -lSDLmain -lSDL diff --git a/constants.h b/constants.h index 8e4f95a..9f98026 100644 --- a/constants.h +++ b/constants.h @@ -1,4 +1,4 @@ -#define VERSION "0.99a" +#define VERSION "0.99b" #define BUFLEN 512 @@ -47,6 +47,10 @@ #define LINESELHANDLESIZE (5) #define OBJSELHANDLEPCT (15) +/* used as a NULL value for colours */ +#define NOCOLOUR (99) +#define USECOLOUR (100) + #define GRIDBRIGHTNESS 100 #define T_EMPTY (0) @@ -91,6 +95,7 @@ #define S_MATCHY (19) #define S_CREATETELE (20) #define S_REALLYQUIT (21) +#define S_FILLCOL (22) #define TB_POINTER (0) diff --git a/dist.sh b/dist.sh index 7be0b04..10a525b 100755 --- a/dist.sh +++ b/dist.sh @@ -3,12 +3,15 @@ VERSION=`cat constants.h | grep VERSION | awk '{ v=$3; gsub("\"","",v); print v FULLNAME=netmapr-${VERSION} TARFILE=${FULLNAME}.tar.gz +WINFILE=${FULLNAME}-win32.zip mkdir ${FULLNAME} -cp Makefile.linux Makefile.freebsd Makefile.windows objects.dat buttons.dat netmapr.c netmapr.h constants.h convert.c convert.h verdana.ttf example.map ${FULLNAME}/ - +cp Makefile.linux Makefile.freebsd Makefile.windows objects.dat buttons.dat netmapr.c netmapr.h constants.h convert.c convert.h icon.bmp verdana.ttf example.map ${FULLNAME}/ tar zcvf ${TARFILE} ${FULLNAME} - rm -rf ${FULLNAME} +mkdir ${FULLNAME} +cp objects.dat buttons.dat netmapr.exe netmapr.c netmapr.h constants.h convert.c convert.h verdana.ttf example.map icon.bmp windows_files/*.dll ${FULLNAME}/ +zip -r ${WINFILE} ${FULLNAME} +rm -rf ${FULLNAME} diff --git a/icon.bmp b/icon.bmp new file mode 100644 index 0000000..e5c1195 Binary files /dev/null and b/icon.bmp differ diff --git a/netmapr.c b/netmapr.c index 33fa664..f90ebfb 100644 --- a/netmapr.c +++ b/netmapr.c @@ -16,6 +16,7 @@ SDL_Surface *screen, *buffer; SDL_Surface *emptyimg; +SDL_Surface *icon; SDL_Event event; TTF_Font *font[MAXLETTERHEIGHT]; @@ -425,6 +426,22 @@ int main (int argc, char **argv) { updatetextcursor(); changestate(S_TYPETEXT); + } else if (state == S_FILLCOL) { + getcolor(screen, event.button.x, event.button.y, &objfillcol); + objfillcol.unused = USECOLOUR; /* clear NOCOLOUR flag */ + if (map[curmap].selecteditem != -1) { + if (map[curmap].selecteditemtype == T_OBJECT) { + map[curmap].obj[map[curmap].selecteditem].fillcol = objfillcol; + map[curmap].obj[map[curmap].selecteditem].fillcol.unused = USECOLOUR; + sprintf(statustext, "Fill colour of object #%d changed to R=%d,G=%d,B=%d",map[curmap].selecteditem, objfillcol.r,objfillcol.g,objfillcol.b); + } else { + sprintf(statustext, "Fill colour selected: R=%d,G=%d,B=%d",objfillcol.r,objfillcol.g,objfillcol.b); + } + } else { + sprintf(statustext, "Fill colour selected: R=%d,G=%d,B=%d",objfillcol.r,objfillcol.g,objfillcol.b); + } + changestate(S_NONE); + drawmap(); } else if (state == S_FGCOL) { getcolor(screen, event.button.x, event.button.y, &fgcol); if (map[curmap].selecteditem != -1) { @@ -520,6 +537,32 @@ int main (int argc, char **argv) { tempx = (event.button.x - toolbox.x) / (toolbox.gridsize+3); tempy = (event.button.y - toolbox.y) / (toolbox.gridsize+3); + + /* are we in a colour selection state? */ + if (state == S_FGCOL) { + changestate(S_NONE); + drawmap(); + break; + } else if (state == S_FILLCOL) { + /* set bgcol to 'nothing' */ + objfillcol = black; + objfillcol.unused = NOCOLOUR; + if (map[curmap].selecteditem != -1) { + if (map[curmap].selecteditemtype == T_OBJECT) { + map[curmap].obj[map[curmap].selecteditem].fillcol = black; + map[curmap].obj[map[curmap].selecteditem].fillcol.unused = NOCOLOUR; + sprintf(statustext, "Fill colour of object #%d removed.", map[curmap].selecteditem); + } else { + sprintf(statustext, "Fill colour removed."); + } + } else { + sprintf(statustext, "Fill colour removed."); + } + changestate(S_NONE); + drawmap(); + break; + } + selection = tempy*toolbox.gridrowlen + tempx; switch (selection) { case TB_POINTER: @@ -566,12 +609,39 @@ int main (int argc, char **argv) { } break; case TB_FGCOL: - changestate(S_FGCOL); + /* change selected item to match fgcol */ + if (map[curmap].selecteditem != -1) { + if (map[curmap].selecteditemtype == T_LINK) { + map[curmap].olink[map[curmap].selecteditem].col = fgcol; + sprintf(statustext, "Colour of link #%d changed to R=%d,G=%d,B=%d",map[curmap].selecteditem, fgcol.r,fgcol.g,fgcol.b); + } else if (map[curmap].selecteditemtype == T_TEXT) { + map[curmap].textob[map[curmap].selecteditem].c = fgcol; + sprintf(statustext, "Colour of text item #%d changed to R=%d,G=%d,B=%d",map[curmap].selecteditem, fgcol.r,fgcol.g,fgcol.b); + } else { + sprintf(statustext, "No object selected! (use RMB to select new foreground colour)"); + } + } else { + sprintf(statustext, "No object selected! (use RMB to select new foreground colour)"); + } drawmap(); break; case TB_FILLCOL: - sprintf(statustext, "Select Fill Colour feature not yet implemented."); - drawstatusbar(); + if (map[curmap].selecteditem != -1) { + if (map[curmap].selecteditemtype == T_OBJECT) { + map[curmap].obj[map[curmap].selecteditem].fillcol = objfillcol; + map[curmap].obj[map[curmap].selecteditem].fillcol.unused = objfillcol.unused; + if (objfillcol.unused == USECOLOUR) { + sprintf(statustext, "Fill colour of object #%d changed to R=%d,G=%d,B=%d",map[curmap].selecteditem, objfillcol.r,objfillcol.g,objfillcol.b); + } else { + sprintf(statustext, "Fill colour of object #%d removed.",map[curmap].selecteditem); + } + } else { + sprintf(statustext, "No object selected! (use RMB to select new fill colour)"); + } + } else { + sprintf(statustext, "No object selected! (use RMB to select new fill colour)"); + } + drawmap(); break; case TB_LINESTYLE: sprintf(statustext, "Select Line Style feature not yet implemented."); @@ -658,6 +728,24 @@ int main (int argc, char **argv) { // end text resize endtextresize(event.button.x, event.button.y); changestate(S_NONE); + } + /* check for right click on toolbox */ + if (isontoolbox(event.button.x, event.button.y)) { + int tempx,tempy, selection; + + tempx = (event.button.x - toolbox.x) / (toolbox.gridsize+3); + tempy = (event.button.y - toolbox.y) / (toolbox.gridsize+3); + selection = tempy*toolbox.gridrowlen + tempx; + switch (selection) { + case TB_FGCOL: + changestate(S_FGCOL); + drawmap(); + break; + case TB_FILLCOL: + changestate(S_FILLCOL); + drawmap(); + break; + } } } break; @@ -1362,7 +1450,7 @@ int drawletter(SDL_Surface *dest,int x, int y, int w, int h, char let, SDL_Color return TRUE; } - drawvector(dest, &letter[let-FIRSTLET].vect, x, y, w,h, &col); + drawvector(dest, &letter[let-FIRSTLET].vect, x, y, w,h, &col, NULL); return FALSE; } @@ -1505,7 +1593,11 @@ void drawobject(SDL_Surface *dest, mapobject_t *o) { printf("About to drawvector ..."); fflush(stdout); } - drawvector(temps, &objtype[o->type].vimg, 0, 0, o->w, o->h, NULL); + if (o->fillcol.unused == USECOLOUR) { + drawvector(temps, &objtype[o->type].vimg, 0, 0, o->w, o->h, NULL, &o->fillcol); + } else { + drawvector(temps, &objtype[o->type].vimg, 0, 0, o->w, o->h, NULL, NULL); + } /* set transparent colour on temp surface */ if (testing) { @@ -1604,7 +1696,7 @@ void drawmap(void) { return; } - if (state == S_FGCOL) { + if ((state == S_FGCOL) || (state == S_FILLCOL)) { drawcolorchart(screen); return; } @@ -2264,7 +2356,13 @@ void drawtoolbox(void) { floodfill(screen, area.x + 5, area.y + 5, fgcol); } if (i == TB_FILLCOL) { - floodfill(screen, area.x + 5, area.y + 5, objfillcol); + if (objfillcol.unused != NOCOLOUR) { + floodfill(screen, area.x + 5, area.y + 5, objfillcol); + } else { + floodfill(screen, area.x + 5, area.y + 5, black); + drawline(screen, area.x+(area.w/2)-3, area.y+(area.h/2)-3-4, area.x+(area.w/2)+3, area.y+(area.h/2)+3-4,white); + drawline(screen, area.x+(area.w/2)+3, area.y+(area.h/2)-3-4, area.x+(area.w/2)-3, area.y+(area.h/2)+3-4,white); + } } SDL_UpdateRect(screen, x, y, toolbox.gridsize+3,toolbox.gridsize+3); @@ -2309,7 +2407,7 @@ void drawtoolboxselector(int buttonid) { } -void drawvector(SDL_Surface *dest, vectorimg_t *vimg, int x, int y, int w, int h, SDL_Color *overridefg) { +void drawvector(SDL_Surface *dest, vectorimg_t *vimg, int x, int y, int w, int h, SDL_Color *overridefg, SDL_Color *overridebg) { float xscale,yscale; int realx1, realy1; int realx2, realy2; @@ -2333,10 +2431,15 @@ void drawvector(SDL_Surface *dest, vectorimg_t *vimg, int x, int y, int w, int h linecol = *overridefg; } - if (vimg->vector[i].c.unused == 255) { - fillcol = objfillcol; + if (overridebg == NULL) { + if (vimg->vector[i].c.unused == 255) { + /* used to display current colour in foreground/background buttons */ + fillcol = objfillcol; + } else { + fillcol = vimg->vector[i].c; + } } else { - fillcol = vimg->vector[i].c; + fillcol = *overridebg; } // scale the coords of this vector @@ -2674,7 +2777,12 @@ int loadmap(void) { char filename[BUFLEN]; FILE *f; int namelen; - int i; + int i,n; + char vers[8], *p; + + mapobject099a_t tempmapobjects[MAXOBJECTS]; + + /* TODO: validate */ strcpy(filename, text); @@ -2690,41 +2798,109 @@ int loadmap(void) { /* TODO: free() variables! */ + /* TODO: read version string */ + fread(&vers, 8, 1, f); + /* if no version string, then this is an old version */ + if (vers[0] != 'V') { + strcpy(vers, "OLD"); + /* go back to start of file */ + fseek(f, 0, SEEK_SET); + } else { + /* if we found a version string, remove trailling spaces */ + for (p = vers; *p != '\0' ; p++) { + if (*p == ' ') { + *p = '\0'; + break; + } + } + } - /* read in number maps */ - fread(&nummaps, sizeof(int), 1, f); + /* current version(s) */ + if (!strcmp(vers, "V0.99b")) { + /* read in number maps */ + fread(&nummaps, sizeof(int), 1, f); - for (i = 0; i < nummaps; i++) { - fread(&map[i].width, sizeof(int), 1, f); - fread(&map[i].height, sizeof(int), 1, f); - fread(&map[i].bpp, sizeof(int), 1, f); - fread(&map[i].bgcol, sizeof(SDL_Color), 1, f); - fread(&map[i].boxcol, sizeof(SDL_Color), 1, f); - fread(&map[i].numthings, sizeof(int), 1, f); - fread(&map[i].numobjects, sizeof(int), 1, f); - fread(&map[i].numlinks, sizeof(int), 1, f); - fread(&map[i].numtext, sizeof(int), 1, f); - map[i].selecteditem = -1; - map[i].selecteditemtype = -1; - map[i].selectedlinkpoint = -1; - map[i].selectedtype = 0; - map[i].curobj = -1; - map[i].curlink = -1; - map[i].curlinkpoint = -1; - map[i].curtext = -1; - map[i].startx = -1; - map[i].starty = -1; - map[i].textanchor = -1; - strcpy(map[i].text, ""); + for (i = 0; i < nummaps; i++) { + fread(&map[i].width, sizeof(int), 1, f); + fread(&map[i].height, sizeof(int), 1, f); + fread(&map[i].bpp, sizeof(int), 1, f); + fread(&map[i].bgcol, sizeof(SDL_Color), 1, f); + fread(&map[i].boxcol, sizeof(SDL_Color), 1, f); + fread(&map[i].numthings, sizeof(int), 1, f); + fread(&map[i].numobjects, sizeof(int), 1, f); + fread(&map[i].numlinks, sizeof(int), 1, f); + fread(&map[i].numtext, sizeof(int), 1, f); + map[i].selecteditem = -1; + map[i].selecteditemtype = -1; + map[i].selectedlinkpoint = -1; + map[i].selectedtype = 0; + map[i].curobj = -1; + map[i].curlink = -1; + map[i].curlinkpoint = -1; + map[i].curtext = -1; + map[i].startx = -1; + map[i].starty = -1; + map[i].textanchor = -1; + strcpy(map[i].text, ""); - fread(&namelen, sizeof(int), 1, f); - fread(&map[i].name, (namelen+1) * sizeof(char), 1, f); + fread(&namelen, sizeof(int), 1, f); + fread(&map[i].name, (namelen+1) * sizeof(char), 1, f); - /* read objects */ - fread(&map[i].thing, sizeof(thing_t), map[i].numthings, f); - fread(&map[i].olink, sizeof(link_t), map[i].numlinks, f); - fread(&map[i].obj, sizeof(mapobject_t), map[i].numobjects, f); - fread(&map[i].textob, sizeof(text_t), map[i].numtext, f); + /* read objects */ + fread(&map[i].thing, sizeof(thing_t), map[i].numthings, f); + fread(&map[i].olink, sizeof(link_t), map[i].numlinks, f); + fread(&map[i].obj, sizeof(mapobject_t), map[i].numobjects, f); + fread(&map[i].textob, sizeof(text_t), map[i].numtext, f); + } + } else { /* old versions without version string */ + /* 0.99a didn't have the fillcol field in mapobject_t */ + + /* read in number maps */ + fread(&nummaps, sizeof(int), 1, f); + + for (i = 0; i < nummaps; i++) { + fread(&map[i].width, sizeof(int), 1, f); + fread(&map[i].height, sizeof(int), 1, f); + fread(&map[i].bpp, sizeof(int), 1, f); + fread(&map[i].bgcol, sizeof(SDL_Color), 1, f); + fread(&map[i].boxcol, sizeof(SDL_Color), 1, f); + fread(&map[i].numthings, sizeof(int), 1, f); + fread(&map[i].numobjects, sizeof(int), 1, f); + fread(&map[i].numlinks, sizeof(int), 1, f); + fread(&map[i].numtext, sizeof(int), 1, f); + map[i].selecteditem = -1; + map[i].selecteditemtype = -1; + map[i].selectedlinkpoint = -1; + map[i].selectedtype = 0; + map[i].curobj = -1; + map[i].curlink = -1; + map[i].curlinkpoint = -1; + map[i].curtext = -1; + map[i].startx = -1; + map[i].starty = -1; + map[i].textanchor = -1; + strcpy(map[i].text, ""); + + fread(&namelen, sizeof(int), 1, f); + fread(&map[i].name, (namelen+1) * sizeof(char), 1, f); + + /* read objects */ + fread(&map[i].thing, sizeof(thing_t), map[i].numthings, f); + fread(&map[i].olink, sizeof(link_t), map[i].numlinks, f); + /* read into temp area, then copy to real structure */ + fread(&tempmapobjects, sizeof(mapobject099a_t), map[i].numobjects, f); + for (n = 0; n < map[i].numobjects; n++) { + map[i].obj[n].type = tempmapobjects[n].type; + map[i].obj[n].x = tempmapobjects[n].x; + map[i].obj[n].y = tempmapobjects[n].y; + map[i].obj[n].w = tempmapobjects[n].w; + map[i].obj[n].h = tempmapobjects[n].h; + map[i].obj[n].child = tempmapobjects[n].child; + map[i].obj[n].fillcol = black; + map[i].obj[n].fillcol.unused = NOCOLOUR; + } + fread(&map[i].textob, sizeof(text_t), map[i].numtext, f); + } } fclose(f); @@ -2732,7 +2908,7 @@ int loadmap(void) { curmap = 0; modified = FALSE; - sprintf(statustext,"Successfully loaded map from '%s' (%d maps).\n",filename,nummaps); fflush(stdout); + sprintf(statustext,"Successfully loaded map from '%s' (%d maps). [file version: '%s']\n",filename,nummaps, vers); strcpy(currentfilename, filename); drawmap(); @@ -2914,8 +3090,30 @@ int initgraphics(void) { exit(1); } + initvars(); + /* set up icon */ + sprintf(file, "icon.bmp"); + for (i = 1; i < MAXLETTERHEIGHT; i++) { + icon = SDL_LoadBMP("icon.bmp"); + if (!icon) { + sprintf(file, "/usr/local/share/netmapr/icon.bmp"); + icon = SDL_LoadBMP(file); + } + if (!icon) { + sprintf(file, "%s/icon.bmp",progdir); + icon = SDL_LoadBMP(file); + } + + if (!icon) { + printf("Error opening icon.bmp: %s\n", TTF_GetError()); + exit(1); + } + } + SDL_WM_SetIcon(icon, NULL); + + /* load fonts */ TTF_Init(); sprintf(file, "verdana.ttf"); @@ -3327,7 +3525,7 @@ int initgraphics(void) { } } else if (!strcmp(p, "end")) { /* draw vector image into button's bitmap field */ - drawvector(button[numbuttons].img, &tempv, 1, 1, toolbox.gridsize-2,toolbox.gridsize-2, NULL); + drawvector(button[numbuttons].img, &tempv, 1, 1, toolbox.gridsize-2,toolbox.gridsize-2, NULL, NULL); //printf("Adding button: '%s' (vnum = %d).\n",button[numbuttons].name,tempv.vnum); @@ -3357,7 +3555,7 @@ int initgraphics(void) { int lw,lh; lw = 8; lh = 10; - drawvector(screen, &letter[i].vect, x, y, lw,lh); + drawvector(screen, &letter[i].vect, x, y, lw,lh, NULL, NULL); x = x + lw + 2; if (x >= (map[curmap].width - lw)) { x = 0; @@ -3784,7 +3982,8 @@ void initvars(void) { fgcol = black; - objfillcol = yellow; + objfillcol = black; + objfillcol.unused = NOCOLOUR; } @@ -3823,6 +4022,7 @@ int savemap(void) { int eoff; SDL_Surface *exportmap; SDL_Rect area; + char vers[8]; /* TODO: validate */ strcpy(filename, text); @@ -3870,6 +4070,10 @@ int savemap(void) { return TRUE; } + /* dump version, 8 bytes, right padded with 0s */ + sprintf(vers, "V%-7s", VERSION); + fwrite(vers, 8, 1, f); + /* dump out numbers of map[curmap].objects */ fwrite(&nummaps, sizeof(int), 1, f); diff --git a/netmapr.exe b/netmapr.exe new file mode 100755 index 0000000..ee68285 Binary files /dev/null and b/netmapr.exe differ diff --git a/netmapr.h b/netmapr.h index c3a15a3..538e6f5 100644 --- a/netmapr.h +++ b/netmapr.h @@ -104,8 +104,20 @@ typedef struct { int w; int h; int child; + /* fillcol.unused = 1 means to fill with this colour */ + /* fillcol.unused = NOCOLOUR means to ignore this*/ + SDL_Color fillcol; } mapobject_t; +typedef struct { + int type; /* index into objtype[] */ + int x; + int y; + int w; + int h; + int child; +} mapobject099a_t; + typedef struct { char name[BUFLEN]; SDL_Surface *img; @@ -175,7 +187,7 @@ void drawstatusbar(void); void drawtext(SDL_Surface *dest, text_t *t); void drawtoolbox(void); void drawtoolboxselector(int buttonid); -void drawvector(SDL_Surface *dest, vectorimg_t *vimg, int x, int y, int w, int h,SDL_Color *overridefg ); +void drawvector(SDL_Surface *dest, vectorimg_t *vimg, int x, int y, int w, int h,SDL_Color *overridefg, SDL_Color *overridebg ); void drillto(int mapnum); int endobjmove(int x, int y); int endresize(int x, int y);