From acd62c5323bcdaa9b5ee24a1b70f943065446a9c Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Sat, 29 Oct 2005 14:23:10 +0000 Subject: [PATCH] - Added readonly mode if argv[0] contains "view" - Modified makefiles to include netmapr-viewer - Fixed "make install" - now actually uses install(1) - Replaced icon with better one - Modified loadmap() function to better cope with future versions - Bumped version to v0.99d --- Makefile | 8 ++- Makefile.freebsd | 10 +++- Makefile.linux | 8 ++- constants.h | 2 +- icon.bmp | Bin 1254 -> 2286 bytes netmapr.c | 134 +++++++++++++++++++++++++++++++---------------- 6 files changed, 114 insertions(+), 48 deletions(-) diff --git a/Makefile b/Makefile index 503c5bd..b291354 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,11 @@ 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 -lSDL_ttf + ln -f netmapr netmapr-viewer install: netmapr - cp -f netmapr /usr/local/bin ; [ ! -d ~/.netmapr ] && mkdir ~/.netmapr ; cp -f *.dat ~/.netmapr/ + install -C -D -o root -m 755 netmapr /usr/local/bin/netmapr + ln -f /usr/local/bin/netmapr /usr/local/bin/netmapr-viewer + install -C -D -o root -m 644 buttons.dat /usr/local/share/buttons.dat + install -C -D -o root -m 644 objects.dat /usr/local/share/objects.dat + install -C -D -o root -m 644 verdana.ttf /usr/local/share/verdana.ttf + install -C -D -o root -m 644 icon.bmp /usr/local/share/icon.bmp diff --git a/Makefile.freebsd b/Makefile.freebsd index 66ffd36..bd2d52e 100644 --- a/Makefile.freebsd +++ b/Makefile.freebsd @@ -1,2 +1,10 @@ netmapr: netmapr.c constants.h netmapr.h Makefile - gcc -Wall -g netmapr.c -onetmapr `sdl11-config --libs --cflags` -L/usr/X11R6/lib -lX11 -lpthread -lXext + gcc -Wall -g netmapr.c -onetmapr `sdl11-config --libs --cflags` -L/usr/X11R6/lib -lX11 -lpthread -lXext -lSDL_ttf + +install: netmapr + install -C -D -o root -m 755 netmapr /usr/local/bin/netmapr + ln -f /usr/local/bin/netmapr /usr/local/bin/netmapr-viewer + install -C -D -o root -m 644 buttons.dat /usr/local/share/buttons.dat + install -C -D -o root -m 644 objects.dat /usr/local/share/objects.dat + install -C -D -o root -m 644 verdana.ttf /usr/local/share/verdana.ttf + install -C -D -o root -m 644 icon.bmp /usr/local/share/icon.bmp diff --git a/Makefile.linux b/Makefile.linux index 503c5bd..b291354 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -1,5 +1,11 @@ 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 -lSDL_ttf + ln -f netmapr netmapr-viewer install: netmapr - cp -f netmapr /usr/local/bin ; [ ! -d ~/.netmapr ] && mkdir ~/.netmapr ; cp -f *.dat ~/.netmapr/ + install -C -D -o root -m 755 netmapr /usr/local/bin/netmapr + ln -f /usr/local/bin/netmapr /usr/local/bin/netmapr-viewer + install -C -D -o root -m 644 buttons.dat /usr/local/share/buttons.dat + install -C -D -o root -m 644 objects.dat /usr/local/share/objects.dat + install -C -D -o root -m 644 verdana.ttf /usr/local/share/verdana.ttf + install -C -D -o root -m 644 icon.bmp /usr/local/share/icon.bmp diff --git a/constants.h b/constants.h index 083dda7..9c9a37a 100644 --- a/constants.h +++ b/constants.h @@ -1,4 +1,4 @@ -#define VERSION "0.99c" +#define VERSION "0.99d" #define BUFLEN 512 diff --git a/icon.bmp b/icon.bmp index e5c119510cc9d37f228e8f033c515f4c810f833a..70316ea3e69c55f91a86e0d22aa4df8565a21942 100644 GIT binary patch literal 2286 zcmbW2c~FvR9LL-Lc6OV#V^Z?g2oGGlEwwDQyKTE1%>y}wP!1JBJn%|Q3(TWK6R|Qc zFxM@!!^%a&gTw<66wxG6Yig=#rW(uI{TVY(>$*F&&+z=_eV_OH`#itnd3k;Jz4(6K z=iv_438pzrTbSR?Lx7z(?-o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!{I3Z{vlQ>dt+i) z-^%Ik?mm3@kY29`$B!RBwzkR+?BA!;4Sp*J^zem^<;F+S8FWUJK#(&wHZ~^&79p>{ E0Ho5w!T<*&f$X%r<>u40g`jOSq1mNBCYT1_7^J*j2BP?o0sI}5NZzb>h2J*UC XsRv;T?$U{yUTzx*(h#T)H3YyP5%iS1 diff --git a/netmapr.c b/netmapr.c index e6fae0c..1a4dcd7 100644 --- a/netmapr.c +++ b/netmapr.c @@ -47,6 +47,8 @@ SDL_Color objfillcol; int modified = FALSE; +int readonly = FALSE; + int numobjtypes = 0; int numletters = 0; int numbuttons = 0; @@ -102,7 +104,15 @@ int main (int argc, char **argv) { strcpy(progdir, "/usr/local/share/netmapr"); } - printf("Starting netmapr v%s...\n", VERSION); + if (strstr(argv[0], "view")) { + readonly = TRUE; + } + + if (readonly) { + printf("Starting netmapr viewer v%s...\n", VERSION); + } else { + printf("Starting netmapr v%s...\n", VERSION); + } @@ -1060,8 +1070,19 @@ int addvector(vectorimg_t *vimg, int type, int x1, int y1, int x2, int y2, SDL_C } void changestate(int newstate) { + /* can't do most things in readonly mode */ + if (readonly) { + switch (newstate) { + case S_NONE: + case S_LOADING: + case S_REALLYQUIT: + break; + default: + newstate = S_NONE; + break; + } + } if (newstate != state) { - if ((state == S_ADDOBJ) || (state == S_ADDTEXT)) { /* change mouse back to normal */ SDL_SetCursor(normalmouse); @@ -2014,6 +2035,23 @@ void drawstatusbar(void) { drawbox(screen, temp.x-3,temp.y-1,temp.x+tw+1,temp.y+th,blue); drawtext(screen, &temp); } + /* show readonly status */ + if (readonly) { + int tw,th; + + /* same place as 'mod' box, as in readonly mode map can't be modified */ + temp.x = map[curmap].width - 30; + temp.y = map[curmap].height+2; + temp.h = DEFTEXTH-1; + + TTF_SizeText(font[temp.h], "RO", &tw, &th); + temp.w = tw; + temp.c = blue; + temp.anchor = -1; + strcpy(temp.text, "RO"); + drawbox(screen, temp.x-3,temp.y-1,temp.x+tw+1,temp.y+th,blue); + drawtext(screen, &temp); + } SDL_UpdateRect(screen, area.x, area.y, area.w, area.h); } @@ -2258,7 +2296,11 @@ void drawobox(void) { } void drawscreen(void){ - sprintf(statustext, "Welcome to netmapr v%s.", VERSION); + if (readonly) { + sprintf(statustext, "Welcome to netmapr viewer v%s.", VERSION); + } else { + sprintf(statustext, "Welcome to netmapr v%s.", VERSION); + } drawmap(); drawtoolbox(); drawobox(); @@ -2883,45 +2925,8 @@ int loadmap(void) { } } } - - /* current version(s) */ - if (!strcmp(vers, "V0.99b") || !strcmp(vers, "V0.99c")) { - /* 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(mapobject_t), map[i].numobjects, f); - fread(&map[i].textob, sizeof(text_t), map[i].numtext, f); - } - } else { /* old versions without version string */ + if (!strcmp(vers, "OLD")) { + /* old versions without version string */ /* 0.99a didn't have the fillcol field in mapobject_t */ /* read in number maps */ @@ -2970,6 +2975,42 @@ int loadmap(void) { } fread(&map[i].textob, sizeof(text_t), map[i].numtext, f); } + } else { + /* 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(mapobject_t), map[i].numobjects, f); + fread(&map[i].textob, sizeof(text_t), map[i].numtext, f); + } } fclose(f); @@ -3290,8 +3331,13 @@ int initgraphics(void) { printf("Doublebuf set ok.\n"); fflush(stdout); } - sprintf(verstring, "netmapr v%s, by rpearce 2005", VERSION); - SDL_WM_SetCaption(verstring,"netmapr"); + if (readonly) { + sprintf(verstring, "netmapr viewer v%s, by rpearce 2005", VERSION); + SDL_WM_SetCaption(verstring,"netmapr viewer"); + } else { + sprintf(verstring, "netmapr v%s, by rpearce 2005", VERSION); + SDL_WM_SetCaption(verstring,"netmapr"); + } /* initialise buffer */ buffer = SDL_CreateRGBSurface(SDL_SWSURFACE,map[curmap].width,map[curmap].height,