diff --git a/Makefile b/Makefile index 3f3c2d5..12447bd 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ netmapr: netmapr.c constants.h netmapr.h Makefile - gcc -Wall -g netmapr.c -onetmapr `sdl-config --libs --cflags` -L/usr/X11R6/lib -lX11 -lpthread -lXext + gcc -Wall -g netmapr.c -I/usr/local/include -onetmapr -lmingw32 -L/usr/local/lib -lSDLmain -lSDL -mwindows -install: netmapr - cp -f netmapr /usr/local/bin ; [ ! -d ~/.netmapr ] && mkdir ~/.netmapr ; cp -f *.dat ~/.netmapr/ +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/Makefile.windows b/Makefile.windows index 94a42f0..12447bd 100644 --- a/Makefile.windows +++ b/Makefile.windows @@ -1,2 +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 + gcc -Wall -g netmapr.c -I/usr/local/include -onetmapr -lmingw32 -L/usr/local/lib -lSDLmain -lSDL -mwindows + +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 39008cf..475caeb 100644 --- a/constants.h +++ b/constants.h @@ -1,4 +1,4 @@ -#define VERSION "0.97" +#define VERSION "0.99" #define BUFLEN 512 @@ -10,7 +10,7 @@ #define MAXPOINTS 20 #define MAXBUTTONS 40 -#define MAXMAPS 20 +#define MAXMAPS 100 #define MAXHISTORY 50 #define MAXCHILDREN 10 @@ -29,14 +29,15 @@ #define MAXLETTERWIDTH 100 #define MAXLETTERHEIGHT 100 -#define MAXOBJWIDTH 300 -#define MAXOBJHEIGHT 300 +#define MAXOBJWIDTH 750 +#define MAXOBJHEIGHT 550 #define MINOBJWIDTH 20 #define MINOBJHEIGHT 20 #define MAXFILLSTACK 500000 -#define MAXVECTORSPERIMAGE (60) +#define OLDMAXVECTORSPERIMAGE (60) +#define MAXVECTORSPERIMAGE (120) #define LINESELTHRESHOLD (4) #define LINESELHANDLESIZE (5) diff --git a/convert.c b/convert.c new file mode 100644 index 0000000..18c6a93 --- /dev/null +++ b/convert.c @@ -0,0 +1,163 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include "convert.h" +#include "constants.h" + +char text[BUFLEN]; + +int nummaps; +int curmap; +int modified; + +int main (int argc, char **argv) { + if (argc != 3) { + printf("convert - converts old netmapr 0.98 maps to new format.\n",argv[0]); + printf("usage: %s source dest\n",argv[0]); + exit(1); + } + + strcpy(text, argv[1]); + loadmap(); + + strcpy(text, argv[2]); + savemap(); + + return 0; +} + +int loadmap(void) { + char filename[BUFLEN]; + FILE *f; + int namelen; + int i; + /* TODO: validate */ + strcpy(filename, text); + + + f = fopen(filename, "rb"); + if (!f) { + printf("ERROR: Cannot open '%s'.\n",filename); + return TRUE; + } + + /* TODO: free() variables! */ + + + /* 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); + fread(&map[i].obj, sizeof(object_t), map[i].numobjects, f); + fread(&map[i].textob, sizeof(text_t), map[i].numtext, f); + } + + fclose(f); + + curmap = 0; + + modified = FALSE; + printf("Successfully loaded map from '%s' (%d maps).\n",filename,nummaps); fflush(stdout); + + return FALSE; +} + + +int savemap(void) { + char filename[BUFLEN]; + FILE *f; + int namelen; + int i; + + /* TODO: validate */ + strcpy(filename, text); + + + printf("Saving map...\n"); + + + if ((f = fopen(filename, "wb")) == NULL) { + printf("ERROR: Could not open '%s'.\n",filename); + return TRUE; + } + + /* dump out numbers of map[curmap].objects */ + fwrite(&nummaps, sizeof(int), 1, f); + + for (i = 0; i < nummaps; i++) { + fwrite(&map[i].width, sizeof(int), 1, f); + fwrite(&map[i].height, sizeof(int), 1, f); + fwrite(&map[i].bpp, sizeof(int), 1, f); + fwrite(&map[i].bgcol, sizeof(SDL_Color), 1, f); + fwrite(&map[i].boxcol, sizeof(SDL_Color), 1, f); + fwrite(&map[i].numthings, sizeof(int), 1, f); + fwrite(&map[i].numobjects, sizeof(int), 1, f); + fwrite(&map[i].numlinks, sizeof(int), 1, f); + fwrite(&map[i].numtext, sizeof(int), 1, f); + /* selecteditem*/ + /* selecteditemtype*/ + /* selectedlinkpoint*/ + /* selectedtype*/ + /* curobj*/ + /* curlink*/ + /* curlinkpoint*/ + /* curtext*/ + /* startx,starty */ + /* textanchor */ + /* text*/ + namelen = strlen(map[i].name); + fwrite(&namelen, sizeof(int), 1, f); + fwrite(&map[i].name, (namelen+1) * sizeof(char), 1, f); + + /* write objects */ + fwrite(&map[i].thing, sizeof(thing_t), map[i].numthings, f); + fwrite(&map[i].olink, sizeof(link_t), map[i].numlinks, f); + fwrite(&map[i].obj, sizeof(mapobject_t), map[i].numobjects, f); + fwrite(&map[i].textob, sizeof(text_t), map[i].numtext, f); + } + + fclose(f); + + + modified = FALSE; + printf("Successfully saved map to '%s'.\n",filename); + + + return 0; +} diff --git a/convert.h b/convert.h new file mode 100644 index 0000000..3e8ae77 --- /dev/null +++ b/convert.h @@ -0,0 +1,243 @@ +#include "constants.h" + +typedef struct { + int x; + int y; +} xy_t; + +struct { + int x; + int y; + int width; + int height; + int pos; + int gridsize; + int gridrowlen; + SDL_Color gridcol; + SDL_Color gridbgcol; + SDL_Color bgcol; +} obox; + +struct { + int x; + int y; + int width; + int height; + int gridsize; + int gridrowlen; + SDL_Color gridcol; + SDL_Color bgcol; +} toolbox; + +struct { + int x; + int y; + int width; + int height; +} mapbox; + + +typedef struct { + char text[BUFLEN]; + int x; + int y; + int w; + int h; + SDL_Color c; + int anchor; +} text_t; + + +typedef struct { + int srcobj; + int srcxoff; + int srcyoff; + int dstobj; + int dstxoff; + int dstyoff; + int npoints; + xy_t point[MAXPOINTS]; + SDL_Color col; + int style; +} link_t; + + +typedef struct { + int type; /* line, square */ + int x1,y1; + int x2,y2; + SDL_Color c; +} vector_t; + +typedef struct { + int w; + int h; + vector_t vector[OLDMAXVECTORSPERIMAGE]; + int vnum; +} vectorimg_t; + +typedef struct { + char name[BUFLEN]; + int canscale; + int defw; + int defh; + vectorimg_t vimg; +} object_t; + +struct { + vectorimg_t vect; + char name; +} letter[MAXLETTERVECTS]; + +typedef struct { + int id; + int type; +} thing_t; + +object_t objtype[MAXOBJTYPES]; + +typedef struct { + int type; /* index into objtype[] */ + int x; + int y; + int w; + int h; + int child; +} mapobject_t; + +typedef struct { + char name[BUFLEN]; + SDL_Surface *img; +} button_t; +button_t button[MAXBUTTONS]; + +typedef struct { + int width; + int height; + int bpp; + SDL_Color bgcol; + SDL_Color boxcol; + int numthings; + int numobjects; + int numlinks; + int numtext; + + int selecteditem; + int selecteditemtype; + int selectedlinkpoint; + int selectedtype; + + int curobj; /* object being moved/dragged/etc */ + int curlink; /* link being moved/dragged/etc */ + int curlinkpoint; /* link point being moved/dragged/etc */ + int curtext; /* text being moved/dragged/etc */ + int startx,starty; + int textanchor; + char text[BUFLEN]; + + char name[BUFLEN]; + + /* actual data */ + text_t textob[MAXTEXT]; + mapobject_t obj[MAXOBJECTS]; + thing_t thing[MAXOBJECTS + MAXLINKS]; + link_t olink[MAXLINKS]; + +} map_t; + +map_t map[MAXMAPS]; + + +void addlinkpoint(int linkid, int x, int y); +int addvector(vectorimg_t *vimg, int type, int x1, int y1, int x2, int y2, SDL_Color *c); +void changestate(int newstate); +void cleanup(void); +int createobject(int type, int x, int y); +void copyline(SDL_Surface *screen,int x1, int y1, int x2, int y2, int *lbuf); +void deletething(int id, int type); +void deletelink(int linkid); +void deleteobject(int oid ); +void deletetext(int textid); +void drawbox(SDL_Surface *screen, int x1, int y1, int x2, int y2, SDL_Color c); +void drawcolorchart(SDL_Surface *dest); +void drawmaplist(SDL_Surface *dest); +int drawletter(SDL_Surface *dest,int x, int y, int w, int h, char let, SDL_Color col); +void drawline(SDL_Surface *screen, int x1, int y1, int x2, int y2, SDL_Color c); +void drawlinebehind(SDL_Surface *screen, int x1, int y1, int x2, int y2, SDL_Color c); +void drawlink(SDL_Surface *dest, link_t *l); +void drawpixel(SDL_Surface *screen, int x, int y, SDL_Color c); +void drawmap(void); +void drawmapbox(void); +void drawobox(void); +void drawscreen(void); +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 drillto(int mapnum); +int endobjmove(int x, int y); +int endresize(int x, int y); +int endtextresize(int x, int y); +int endlink(int x, int y); +int endlinkmove(int x, int y); +int endlinkdstmove(int x, int y); +int endlinkpointmove(int x, int y); +int endlinksrcmove(int x, int y); +int endtext(void); +int endtextmove(int x, int y); +int findpointpos(link_t *l, int px, int py); +void floodfill(SDL_Surface *dest, int x, int y, SDL_Color fillcol); +void floodfill2(SDL_Surface *dest, int x, int y, SDL_Color fillcol, SDL_Color bgcol); +void floodfill3(SDL_Surface *dest, int x1, int x2, int y, SDL_Color fillcol, SDL_Color bgcol); +void floodfill4(SDL_Surface *dest, int x, int y, SDL_Color fillcol, SDL_Color bgcol); +int getcolor(SDL_Surface *dest, int x, int y, SDL_Color *col); +void drawyn(char *prompt); +int getyn(int x, int y); +void goback(void); +int linelen(int x1,int y1,int x2,int y2); +int linkat(int x, int y); +int loadmap(void); +void lowerselected(void); +int objat(int x, int y); +void pasteline(SDL_Surface *screen, int *lbuf); +void pop(int *x, int *y); +void push(int x, int y); +int initgraphics(void); +void initmap(int mapnum); +int initobject(int onum); +int isonline (int fx, int fy, int x1, int y1, int x2, int y2); +int isonlink(int linkid, int mx, int my); +int isonlinkdst(int lineid, int mx, int my); +int isonlinkpoint(int lineid, int mx, int my); +int isonlinksrc(int lineid, int mx, int my); +int isonmap (int x, int y); +int isonobox (int x, int y); +int isontoolbox (int x, int y); +int isonmapbox (int x, int y); +int isonmapboxchildren (int x, int y); +int isonmapname (int x, int y); +int isongoback (int x, int y); +void initvars(void); +void raiseselected(void); +int savemap(void); +int showfiledialog(void); +int startlink (int x, int y); +int startlinkdstmove(int x, int y); +int startlinkpointmove(int x, int y); +int startlinksrcmove(int x, int y); +int startlinkmove(int x, int y); +int startobjmove(int x, int y); +int startresize (int x, int y); +int startresizetext (int x, int y); +int starttextmove(int x, int y); +int textat(int x, int y); +int thingat(int x, int y); +int updatefilename(void); +int updatelinkshadow(int x, int y); +int updatelinkpointshadow(int x, int y); +int updatemoveshadow(int x, int y); +int updateresizeshadow(int x, int y); +int updateresizetextshadow(int x, int y); +int updatetextcursor(void); +int updatetextshadow(int x, int y); diff --git a/netmapr.c b/netmapr.c index 7a79828..04878d0 100644 --- a/netmapr.c +++ b/netmapr.c @@ -72,6 +72,8 @@ int textanchor; char text[BUFLEN]; int startobj,endobj; +char progdir[BUFLEN]; + int shift; int main (int argc, char **argv) { @@ -89,6 +91,12 @@ int main (int argc, char **argv) { autoload = TRUE; } + if (getenv("NETMAPRDIR") != NULL) { + strncpy(progdir, getenv("NETMAPRDIR"), BUFLEN); + } else { + strcpy(progdir, "/usr/local/share/netmapr"); + } + if (initgraphics()) { printf("Error initialising graphics.\n"); exit(1); @@ -201,13 +209,17 @@ int main (int argc, char **argv) { oldticks = ticks; if (isonmap(event.button.x, event.button.y)) { if (state != S_REALLYQUIT) { - if ((doubleclick) && (objat(event.button.x, event.button.y) == map[curmap].selecteditem)) { + //if ((doubleclick) && (objat(event.button.x, event.button.y) == map[curmap].selecteditem)) { + if (doubleclick) { + o = objat(event.button.x, event.button.y); + /* only works on an object */ - if (map[curmap].selecteditem != -1) { + //if (map[curmap].selecteditem != -1) { + if (o != -1) { /* can't create a new child via double click */ - if (map[curmap].obj[map[curmap].selecteditem].child != -1) { + if (map[curmap].obj[o].child != -1) { changestate(S_NONE); - drillto(map[curmap].obj[map[curmap].selecteditem].child); + drillto(map[curmap].obj[o].child); } else { sprintf(statustext, "Cannot drill down - object has no children (use drill tool to create one)."); map[curmap].selecteditem = -1; @@ -239,9 +251,21 @@ int main (int argc, char **argv) { sprintf(statustext, "Size match mode aborted."); drawstatusbar(); } else { + int n; /* resize selected item to match one which was clicked */ map[curmap].obj[map[curmap].selecteditem].w = map[curmap].obj[o].w; map[curmap].obj[map[curmap].selecteditem].h = map[curmap].obj[o].h; + /* adjust offsets on all links to/from object */ + for (n = 0; n < map[curmap].numlinks; n++) { + if (map[curmap].olink[n].srcobj == map[curmap].selecteditem) { + map[curmap].olink[n].srcxoff = (map[curmap].obj[o].w / 2); + map[curmap].olink[n].srcyoff = (map[curmap].obj[o].h / 2); + } + if (map[curmap].olink[n].dstobj == map[curmap].selecteditem) { + map[curmap].olink[n].dstxoff = (map[curmap].obj[o].w / 2); + map[curmap].olink[n].dstyoff = (map[curmap].obj[o].h / 2); + } + } changestate(S_NONE); sprintf(statustext, "Object #%d resized to match object #%d.",map[curmap].selecteditem,o); drawmap(); @@ -436,7 +460,7 @@ int main (int argc, char **argv) { tempx = (event.button.x - obox.x) / obox.gridsize; tempy = (event.button.y - obox.y) / obox.gridsize; - map[curmap].selectedtype = tempy*obox.gridrowlen + tempx; + map[curmap].selectedtype = tempy*obox.gridrowlen + tempx + (obox.pos*3); if (map[curmap].selectedtype >= numobjtypes) map[curmap].selectedtype = numobjtypes-1; sprintf(statustext,"Object type '%s' selected.\n",objtype[map[curmap].selectedtype].name); drawstatusbar(); @@ -755,6 +779,26 @@ int main (int argc, char **argv) { changestate(S_LOADING); drawmap(); } + if ((c == ',') || (c == 'q')) { /* scroll object box up */ + if (obox.pos > 0) { + obox.pos--; + drawobox(); + } + } + if ((c == '.') || (c == 'w')) { /* scroll object box down */ + int fitx,fity,fit; + + /* figure out how many objects we can fit in the box */ + fitx = (obox.width / obox.gridsize); + fity = ((obox.height+3) / obox.gridsize); + fit = fitx * fity; + + /* check if incrementing position is okay or not */ + if (((obox.pos+1)*3 + fit) <= (numobjtypes+2)) { + obox.pos++; + drawobox(); + } + } if (c == 'x') { if (map[curmap].selecteditem != -1) { if (map[curmap].selecteditemtype == T_OBJECT) { @@ -771,6 +815,14 @@ int main (int argc, char **argv) { } } } + if (c == 'b') { + if (map[curmap].selecteditem != -1) { + if (map[curmap].selecteditemtype == T_OBJECT) { + changestate(S_MATCHSIZE); + drawmap(); + } + } + } if (c == 'd') { /* drill down */ if (state == S_NONE) { if ((map[curmap].selecteditemtype == T_OBJECT) && (map[curmap].selecteditem != -1)) { @@ -857,7 +909,9 @@ void addlinkpoint(int linkid, int x, int y) { sprintf(statustext, "Point added to link #%d",linkid); } -void addvector(vectorimg_t *vimg, int type, int x1, int y1, int x2, int y2, SDL_Color *c) { +int addvector(vectorimg_t *vimg, int type, int x1, int y1, int x2, int y2, SDL_Color *c) { + + if ((vimg->vnum + 1) >= MAXVECTORSPERIMAGE) return TRUE; vimg->vector[vimg->vnum].type = type; vimg->vector[vimg->vnum].x1 = x1; vimg->vector[vimg->vnum].y1 = y1; @@ -867,6 +921,8 @@ void addvector(vectorimg_t *vimg, int type, int x1, int y1, int x2, int y2, SDL_ vimg->vector[vimg->vnum].c.g = c->g; vimg->vector[vimg->vnum].c.b = c->b; vimg->vnum = vimg->vnum + 1; + + return FALSE; } void changestate(int newstate) { @@ -1400,11 +1456,17 @@ void drawobject(SDL_Surface *dest, mapobject_t *o) { Uint32 bgcol; /* create temp surface */ - temps = SDL_CreateRGBSurface(SDL_SWSURFACE,o->w, o->h, + temps = SDL_CreateRGBSurface(SDL_SWSURFACE,(o->w + 3), (o->h + 3), screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask,screen->format->Bmask, screen->format->Amask); + if (temps == NULL) { + printf("temp surface is NULL!\n"); + fflush(stdout); + exit(1); + } + bgcol = SDL_MapRGB(temps->format, map[curmap].bgcol.r,map[curmap].bgcol.g,map[curmap].bgcol.b); SDL_FillRect(temps, NULL, bgcol); @@ -1415,6 +1477,9 @@ void drawobject(SDL_Surface *dest, mapobject_t *o) { SDL_SetColorKey(temps, SDL_SRCCOLORKEY|SDL_RLEACCEL, bgcol); /* blit to screen */ + /*printf("set area params: x=%d,y=%d w=%d,h=%d x2=%d,y2=%d\n", + o->x, o->y,o->w,o->h,o->x+o->w,o->y+o->h); fflush(stdout); + */ area.x = o->x; area.y = o->y; area.w = o->w; @@ -1513,23 +1578,33 @@ void drawmap(void) { fillcol = SDL_MapRGB(buffer->format, map[curmap].bgcol.r,map[curmap].bgcol.g,map[curmap].bgcol.b); SDL_FillRect(buffer, NULL, fillcol); - /* draw all map[curmap].objects links etc*/ + /* draw all objects links etc*/ for (i = 0; i < map[curmap].numthings; i++) { if (map[curmap].thing[i].type == T_OBJECT) { - if (testing) printf("Drawing thing #%d (%d, %s)\n",i,map[curmap].thing[i].id,objtype[map[curmap].obj[map[curmap].thing[i].id].type].name); + if (testing) { + printf("Drawing thing #%d (%d, %s)\n",i,map[curmap].thing[i].id,objtype[map[curmap].obj[map[curmap].thing[i].id].type].name); + fflush(stdout); + } drawobject(buffer, &map[curmap].obj[map[curmap].thing[i].id]); } else if (map[curmap].thing[i].type == T_LINK) { - if (testing) printf ("Drawing thing #%d (%d, link)\n",i,map[curmap].thing[i].id); + if (testing) { + printf ("Drawing thing #%d (%d, link)\n",i,map[curmap].thing[i].id); + fflush(stdout); + } drawlink(buffer, &map[curmap].olink[map[curmap].thing[i].id]); } else if (map[curmap].thing[i].type == T_TEXT) { - if (testing) printf ("Drawing thing #%d (%d, text)\n",i,map[curmap].thing[i].id); + if (testing) { + printf ("Drawing thing #%d (%d, text)\n",i,map[curmap].thing[i].id); + fflush(stdout); + } drawtext(buffer, &map[curmap].textob[map[curmap].thing[i].id]); } else { printf("WARNING: Thing #%d has unknown type %d!\n",i,map[curmap].thing[i].type); + fflush(stdout); } } - /* highlight the selected map[curmap].object */ + /* highlight the selected object */ /* by drawing boxes in its corners */ if (map[curmap].selecteditem != -1) { if (map[curmap].selecteditemtype == T_OBJECT) { @@ -1668,8 +1743,10 @@ void drawmap(void) { /* draw status bar */ drawstatusbar(); + /* flip */ SDL_UpdateRect(screen, 0, 0, map[curmap].width, map[curmap].height); + } void drawstatusbar(void) { @@ -1877,6 +1954,8 @@ void drawobox(void) { mapobject_t temp; Uint32 fillcol; SDL_Color outlinecol; + int outlinepos; + int fitx,fity,fit; fillcol = SDL_MapRGB(screen->format, obox.bgcol.r,obox.bgcol.g,obox.bgcol.b); area.x = obox.x; @@ -1888,7 +1967,14 @@ void drawobox(void) { x = obox.x; y = obox.y; - for (i = 0; i < numobjtypes; i++) { + + /* calculate how many items we can fit in the obox */ + /* figure out how many objects we can fit in the box */ + fitx = (obox.width / obox.gridsize); + fity = ((obox.height+3) / obox.gridsize); + fit = fitx * fity; + + for (i = (obox.pos*3); i < numobjtypes; i++) { if ((x + obox.gridsize) >= (map[curmap].width + SIDEBARW)) { x = obox.x; if ((y + obox.gridsize) >= (map[curmap].height)) { @@ -1924,15 +2010,20 @@ void drawobox(void) { } + /* oooo */ /* draw selector */ outlinecol = red; - y = (map[curmap].selectedtype / obox.gridrowlen) * obox.gridsize + obox.y; - x = (map[curmap].selectedtype % obox.gridrowlen) * obox.gridsize + obox.x; + outlinepos = map[curmap].selectedtype - (obox.pos*3); - drawline(screen, x, y,x+obox.gridsize,y,outlinecol); /* top */ - drawline(screen, x, y+obox.gridsize,x+obox.gridsize,y+obox.gridsize,outlinecol); /* bottom */ - drawline(screen, x, y,x,y+obox.gridsize,outlinecol); /* left */ - drawline(screen, x+obox.gridsize, y,x+obox.gridsize,y+obox.gridsize,outlinecol); /* right */ + if ((outlinepos >= 0) && (outlinepos < fit)) { + y = ((map[curmap].selectedtype - (obox.pos*3)) / obox.gridrowlen) * obox.gridsize + obox.y; + x = ((map[curmap].selectedtype - (obox.pos*3)) % obox.gridrowlen) * obox.gridsize + obox.x; + + drawline(screen, x, y,x+obox.gridsize,y,outlinecol); /* top */ + drawline(screen, x, y+obox.gridsize,x+obox.gridsize,y+obox.gridsize,outlinecol); /* bottom */ + drawline(screen, x, y,x,y+obox.gridsize,outlinecol); /* left */ + drawline(screen, x+obox.gridsize, y,x+obox.gridsize,y+obox.gridsize,outlinecol); /* right */ + } //SDL_UpdateRect(screen, x, y, obox.gridsize+1,obox.gridsize+1); @@ -2438,6 +2529,7 @@ int linkat(int x, int y) { return -1; } + int loadmap(void) { char filename[BUFLEN]; FILE *f; @@ -2491,7 +2583,7 @@ int loadmap(void) { /* 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(object_t), map[i].numobjects, f); + fread(&map[i].obj, sizeof(mapobject_t), map[i].numobjects, f); fread(&map[i].textob, sizeof(text_t), map[i].numtext, f); } @@ -2677,7 +2769,7 @@ int initgraphics(void) { int x1,x2,y1,y2; SDL_Color c; - if(SDL_Init(SDL_INIT_VIDEO)==-1) { + if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE)==-1) { printf("SDL_Init: %s\n", SDL_GetError()); exit(1); } @@ -2786,16 +2878,20 @@ int initgraphics(void) { printf("Reading shapes...\n"); - /* read map[curmap].objects from file */ f = fopen("objects.dat","rt"); if (!f) { - sprintf(file, "%s/.netmapr/objects.dat",getenv("HOME")); + sprintf(file, "/usr/local/share/netmapr/objects.dat"); f = fopen(file,"rt"); - if (!f) { - printf("Cannot open objects file!\n"); - exit(1); - } } + if (!f) { + sprintf(file, "%s/objects.dat",progdir); + f = fopen(file,"rt"); + } + if (!f) { + printf("Cannot open objects file!\n"); + exit(1); + } + state = 0; line = 0; numobjtypes = 0; @@ -2861,7 +2957,11 @@ int initgraphics(void) { if (p == NULL) { printf("Missing token on line #%d of objects file.\n",line); exit(1); } c.b = atoi(p); - addvector(&objtype[numobjtypes].vimg,VT_LINE,x1,y1,x2,y2,&c); + if (addvector(&objtype[numobjtypes].vimg,VT_LINE,x1,y1,x2,y2,&c)) { + printf("Too many vectors on line %d of objects file.\n",line); + exit(1); + } + } else if (!strcmp(p, "fill")) { p = strtok(NULL, " "); if (p == NULL) { printf("Missing token on line #%d of objects file.\n",line); exit(1); } @@ -2879,7 +2979,10 @@ int initgraphics(void) { if (p == NULL) { printf("Missing token on line #%d of objects file.\n",line); exit(1); } c.b = atoi(p); - addvector(&objtype[numobjtypes].vimg,VT_FILL,x1,y1,0,0,&c); + if (addvector(&objtype[numobjtypes].vimg,VT_FILL,x1,y1,0,0,&c)) { + printf("Too many vectors on line %d of objects file.\n",line); + exit(1); + } } else if (!strcmp(p, "box")) { p = strtok(NULL, " "); if (p == NULL) { printf("Missing token on line #%d of objects file.\n",line); exit(1); } @@ -2903,7 +3006,10 @@ int initgraphics(void) { if (p == NULL) { printf("Missing token on line #%d of objects file.\n",line); exit(1); } c.b = atoi(p); - addvector(&objtype[numobjtypes].vimg,VT_BOX,x1,y1,x2,y2,&c); + if (addvector(&objtype[numobjtypes].vimg,VT_BOX,x1,y1,x2,y2,&c)) { + printf("Too many vectors on line %d of objects file.\n",line); + exit(1); + } } else if (!strcmp(p, "end")) { state = 0; numobjtypes++; @@ -2926,18 +3032,21 @@ int initgraphics(void) { fclose(f); printf("Shape load complete - %d objects found.\n",numobjtypes); - /* read in button images */ printf("Reading buttons...\n"); - /* read buttons from file */ f = fopen("buttons.dat","rt"); if (!f) { - sprintf(file, "%s/.netmapr/buttons.dat",getenv("HOME")); + sprintf(file, "/usr/local/share/netmapr/buttons.dat"); f = fopen(file,"rt"); - if (!f) { - printf("Cannot open buttons file!\n"); - exit(1); - } } + if (!f) { + sprintf(file, "%s/buttons.dat",progdir); + f = fopen(file,"rt"); + } + if (!f) { + printf("Cannot open buttons file!\n"); + exit(1); + } + state = 0; line = 0; numbuttons = 0; @@ -3005,7 +3114,10 @@ int initgraphics(void) { if (p == NULL) { printf("Missing token on line #%d of buttons file.\n",line); exit(1); } c.b = atoi(p); - addvector(&tempv,VT_LINE,x1,y1,x2,y2,&c); + if (addvector(&tempv,VT_LINE,x1,y1,x2,y2,&c)) { + printf("Too many vectors on line %d of objects file.\n",line); + exit(1); + } } else if (!strcmp(p, "fill")) { p = strtok(NULL, " "); if (p == NULL) { printf("Missing token on line #%d of buttons file.\n",line); exit(1); } @@ -3023,7 +3135,10 @@ int initgraphics(void) { if (p == NULL) { printf("Missing token on line #%d of buttons file.\n",line); exit(1); } c.b = atoi(p); - addvector(&tempv,VT_FILL,x1,y1,0,0,&c); + if (addvector(&tempv,VT_FILL,x1,y1,0,0,&c)) { + printf("Too many vectors on line %d of objects file.\n",line); + exit(1); + } } else if (!strcmp(p, "box")) { p = strtok(NULL, " "); if (p == NULL) { printf("Missing token on line #%d of buttons file.\n",line); exit(1); } @@ -3047,7 +3162,10 @@ int initgraphics(void) { if (p == NULL) { printf("Missing token on line #%d of buttons file.\n",line); exit(1); } c.b = atoi(p); - addvector(&tempv,VT_BOX,x1,y1,x2,y2,&c); + if (addvector(&tempv,VT_BOX,x1,y1,x2,y2,&c)) { + printf("Too many vectors on line %d of buttons file.\n",line); + exit(1); + } } 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); @@ -3071,18 +3189,21 @@ int initgraphics(void) { fclose(f); printf("Button load complete - %d buttons found.\n",numbuttons); - /* read in letter images */ printf("Reading letters...\n"); - /* read letters from file */ f = fopen("letters.dat","rt"); if (!f) { - sprintf(file, "%s/.netmapr/letters.dat",getenv("HOME")); + sprintf(file, "/usr/local/share/netmapr/letters.dat"); f = fopen(file,"rt"); - if (!f) { - printf("Cannot open letters file!\n"); - exit(1); - } } + if (!f) { + sprintf(file, "%s/letters.dat",progdir); + f = fopen(file,"rt"); + } + if (!f) { + printf("Cannot open letters file!\n"); + exit(1); + } + state = 0; line = 0; numletters = 0; @@ -3137,7 +3258,10 @@ int initgraphics(void) { c = fgcol; - addvector(&letter[numletters].vect,VT_LINE,x1,y1,x2,y2,&c); + if (addvector(&letter[numletters].vect,VT_LINE,x1,y1,x2,y2,&c)) { + printf("Too many vectors on line %d of letters file.\n",line); + exit(1); + } } else if (!strcmp(p, "fill")) { p = strtok(NULL, " "); if (p == NULL) { printf("Missing token on line #%d of letters file.\n",line); exit(1); } @@ -3148,7 +3272,10 @@ int initgraphics(void) { c = fgcol; - addvector(&letter[numletters].vect,VT_FILL,x1,y1,0,0,&c); + if (addvector(&letter[numletters].vect,VT_FILL,x1,y1,0,0,&c)) { + printf("Too many vectors on line %d of letters file.\n",line); + exit(1); + } } else if (!strcmp(p, "box")) { p = strtok(NULL, " "); if (p == NULL) { printf("Missing token on line #%d of letters file.\n",line); exit(1); } @@ -3165,7 +3292,10 @@ int initgraphics(void) { c = fgcol; - addvector(&letter[numletters].vect,VT_BOX,x1,y1,x2,y2,&c); + if (addvector(&letter[numletters].vect,VT_BOX,x1,y1,x2,y2,&c)) { + printf("Too many vectors on line %d of letters file.\n",line); + exit(1); + } } else if (!strcmp(p, "end")) { //printf("Adding letter %d: '%c' (vnum = %d).\n",numletters,letter[numletters].name,letter[numletters].vect.vnum); @@ -3608,7 +3738,7 @@ int savemap(void) { /* write objects */ fwrite(&map[i].thing, sizeof(thing_t), map[i].numthings, f); fwrite(&map[i].olink, sizeof(link_t), map[i].numlinks, f); - fwrite(&map[i].obj, sizeof(object_t), map[i].numobjects, f); + fwrite(&map[i].obj, sizeof(mapobject_t), map[i].numobjects, f); fwrite(&map[i].textob, sizeof(text_t), map[i].numtext, f); } diff --git a/netmapr.h b/netmapr.h index 13be453..c3a15a3 100644 --- a/netmapr.h +++ b/netmapr.h @@ -150,7 +150,7 @@ map_t map[MAXMAPS]; void addlinkpoint(int linkid, int x, int y); -void addvector(vectorimg_t *vimg, int type, int x1, int y1, int x2, int y2, SDL_Color *c); +int addvector(vectorimg_t *vimg, int type, int x1, int y1, int x2, int y2, SDL_Color *c); void changestate(int newstate); void cleanup(void); int createobject(int type, int x, int y); diff --git a/objects.dat b/objects.dat index 6422a4e..0a73d47 100644 --- a/objects.dat +++ b/objects.dat @@ -1,55 +1,152 @@ -object router 120 120 -# outline -line 0 40 40 0 0 0 0 -line 40 0 80 0 0 0 0 -line 80 0 119 40 0 0 0 -line 119 40 119 80 0 0 0 -line 119 80 80 119 0 0 0 -line 80 119 40 119 0 0 0 -line 40 119 0 80 0 0 0 -line 0 80 0 40 0 0 0 +object router3d 200 200 +# top left +line 0 50 0 38 170 230 255 +line 0 38 10 26 170 230 255 +line 10 26 30 14 170 230 255 +line 30 14 60 0 170 230 255 +line 60 0 100 0 170 230 255 +# bottom left +line 0 50 0 62 170 230 255 +line 0 62 10 74 170 230 255 +line 10 74 30 86 170 230 255 +line 30 86 60 99 170 230 255 +line 60 99 100 99 170 230 255 +# top right +line 199 50 199 38 170 230 255 +line 199 38 190 26 170 230 255 +line 190 26 170 14 170 230 255 +line 170 14 140 0 170 230 255 +line 140 0 100 0 170 230 255 +# bottom right +line 199 50 199 62 170 230 255 +line 199 62 190 74 170 230 255 +line 190 74 170 86 170 230 255 +line 170 86 140 99 170 230 255 +line 140 99 100 99 170 230 255 +# fill top +fill 100 50 0 180 255 +# bottom half - sides +line 0 50 0 162 170 230 255 +line 199 50 199 150 170 230 255 +# bottom half - bottom left +# next line not being drawn on windows?? +line 0 150 0 112 170 230 255 +line 0 162 10 174 170 230 255 +line 10 174 30 186 170 230 255 +line 30 186 60 199 170 230 255 +line 60 199 100 199 170 230 255 +# bottom half - bottom right +line 199 150 199 162 170 230 255 +line 199 162 190 174 170 230 255 +line 190 174 170 186 170 230 255 +line 170 186 140 199 170 230 255 +line 140 199 100 199 170 230 255 +# fill bottom half +fill 100 162 0 120 170 # arrows -line 30 30 50 50 0 0 0 -line 89 30 69 50 0 0 0 -line 89 89 69 69 0 0 0 -line 30 89 50 69 0 0 0 -# arrowheads -line 50 50 40 50 0 0 0 -line 50 50 50 40 0 0 0 +# top left arrow +line 35 25 65 40 0 0 0 +line 55 15 85 30 0 0 0 +line 35 25 55 15 0 0 0 +# arrowhead /____ +line 55 47 65 40 0 0 0 +line 55 47 90 47 0 0 0 +# arrowhead /| +line 95 20 90 47 0 0 0 +line 95 20 85 30 0 0 0 +# fill it +fill 60 30 250 250 250 +# +# +# bottom left arrow +line 95 65 65 80 0 0 0 +line 75 55 45 70 0 0 0 +line 95 65 75 55 0 0 0 +# arrowhead /____ +line 75 87 65 80 0 0 0 +line 75 87 40 87 0 0 0 +# arrowhead /| +line 45 60 40 87 0 0 0 +line 45 60 45 70 0 0 0 +# fill it +fill 70 70 250 250 250 +# top right arrow +line 110 40 140 25 0 0 0 +line 130 50 160 35 0 0 0 +line 110 40 130 50 0 0 0 +# arrowhead /____ +line 130 18 140 25 0 0 0 +line 130 18 165 18 0 0 0 +# arrowhead /| +line 160 45 165 18 0 0 0 +line 160 45 160 35 0 0 0 +# fill it +fill 135 35 250 250 250 +# bottom right arrow +line 165 80 135 65 0 0 0 +line 145 90 115 75 0 0 0 +# joining +line 165 80 145 90 0 0 0 +# arrowhead /____ +line 145 58 135 65 0 0 0 +line 145 58 110 58 0 0 0 +# arrowhead /| +line 115 85 110 58 0 0 0 +line 115 85 115 75 0 0 0 +# fill it +fill 140 75 250 250 250 # -line 89 30 79 30 0 0 0 -line 89 30 89 40 0 0 0 # -line 69 69 79 69 0 0 0 -line 69 69 69 79 0 0 0 # -line 30 89 40 89 0 0 0 -line 30 89 30 79 0 0 0 -# fill in with blue -fill 20 40 0 175 254 end -object firewall 120 120 -# outline -line 0 0 119 0 0 0 0 -line 119 0 119 119 0 0 0 -line 0 0 0 119 0 0 0 -line 0 119 119 119 0 0 0 -# fill -fill 20 20 255 0 0 -# horizontal mortar lines -line 0 30 119 30 0 0 0 -line 0 60 119 60 0 0 0 -line 0 90 119 90 0 0 0 -# vertical mortar lines - top -line 60 0 60 30 0 0 0 -# vertical mortar lines - second top -line 30 30 30 60 0 0 0 -line 90 30 90 60 0 0 0 -# vertical mortar lines - second bottom -line 60 60 60 90 0 0 0 -# vertical mortar lines - bottom -line 30 90 30 119 0 0 0 -line 90 90 90 119 0 0 0 +object fw3d 60 140 +# front of wall +box 0 20 30 139 199 199 199 +# right side +line 30 20 59 0 199 199 199 +line 59 0 59 120 199 199 199 +line 30 139 59 120 199 199 199 +# top of wall +line 0 20 30 0 199 199 199 +line 30 0 59 0 199 199 199 +# fill with red +# front +fill 10 50 170 0 0 +# right +fill 50 50 119 0 0 +# top +fill 30 10 255 85 93 +# horiz. mortar lines - front +line 0 40 30 40 199 199 199 +line 0 60 30 60 199 199 199 +line 0 80 30 80 199 199 199 +line 0 100 30 100 199 199 199 +line 0 120 30 120 199 199 199 +# horiz. mortar lines - side +line 30 40 59 20 170 170 170 +line 30 60 59 40 170 170 170 +line 30 80 59 60 170 170 170 +line 30 100 59 80 170 170 170 +line 30 120 59 100 170 170 170 +# vert. mortar lines - front +line 10 20 10 40 199 199 199 +line 20 40 20 60 199 199 199 +line 10 60 10 80 199 199 199 +line 20 80 20 100 199 199 199 +line 10 100 10 120 199 199 199 +line 20 120 20 140 199 199 199 +# vert. mortar lines - top +line 10 20 40 0 227 227 227 +# horiz. mortar lines - top +line 20 13 40 13 227 227 227 +line 20 7 30 7 227 227 227 +# vert. mortar lines - side +line 40 13 40 33 170 170 170 +line 50 27 50 46 170 170 170 +line 40 53 40 73 170 170 170 +line 50 67 50 86 170 170 170 +line 40 93 40 113 170 170 170 +line 50 107 50 126 170 170 170 end object switch 120 120 # outline @@ -216,32 +313,6 @@ fill 57 55 255 0 0 fill 82 55 255 0 0 fill 106 55 255 0 0 end -object floppy 120 120 -# border -box 10 10 109 109 0 0 0 -# hole -line 15 15 20 15 0 0 0 -line 15 15 15 20 0 0 0 -line 15 20 20 20 0 0 0 -line 20 15 20 20 0 0 0 -# border fill -fill 50 50 0 0 255 -# label -line 30 10 30 50 0 0 0 -line 30 50 89 50 0 0 0 -line 89 10 89 50 0 0 0 -fill 50 30 210 190 130 -# metal bit -line 35 109 35 80 0 0 0 -line 35 80 84 80 0 0 0 -line 84 80 84 109 0 0 0 -# -line 50 109 50 90 0 0 0 -line 50 90 60 90 0 0 0 -line 60 90 60 109 0 0 0 -# fill metal bit -fill 80 100 200 200 200 -end object printer 120 120 # outline box 40 30 119 119 0 0 0 @@ -283,7 +354,7 @@ line 65 55 100 15 0 0 0 line 100 15 98 25 0 0 0 line 100 15 96 13 0 0 0 end -object switchrouter 120 120 +object layer3switch 135 135 # outside border box 0 0 119 119 0 0 0 # router @@ -322,3 +393,38 @@ line 66 73 109 50 250 250 250 line 66 88 109 109 250 250 250 line 54 73 10 50 250 250 250 end +object firewall 120 120 +# outline +line 0 0 119 0 0 0 0 +line 119 0 119 119 0 0 0 +line 0 0 0 119 0 0 0 +line 0 119 119 119 0 0 0 +# fill +fill 20 20 255 0 0 +# horizontal mortar lines +line 0 30 119 30 0 0 0 +line 0 60 119 60 0 0 0 +line 0 90 119 90 0 0 0 +# vertical mortar lines - top +line 60 0 60 30 0 0 0 +# vertical mortar lines - second top +line 30 30 30 60 0 0 0 +line 90 30 90 60 0 0 0 +# vertical mortar lines - second bottom +line 60 60 60 90 0 0 0 +# vertical mortar lines - bottom +line 30 90 30 119 0 0 0 +line 90 90 90 119 0 0 0 +end +object redbox 120 120 +box 0 0 119 119 0 0 0 +fill 50 50 255 0 0 +end +object greenbox 120 120 +box 0 0 119 119 0 0 0 +fill 50 50 0 255 0 +end +object bluebox 120 120 +box 0 0 119 119 0 0 0 +fill 50 50 0 0 255 +end