diff --git a/Makefile b/Makefile index 3f3c2d5..503c5bd 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 -onetmapr `sdl-config --libs --cflags` -L/usr/X11R6/lib -lX11 -lpthread -lXext -lSDL_ttf install: netmapr cp -f netmapr /usr/local/bin ; [ ! -d ~/.netmapr ] && mkdir ~/.netmapr ; cp -f *.dat ~/.netmapr/ diff --git a/Makefile.linux b/Makefile.linux index 3f3c2d5..503c5bd 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -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 -onetmapr `sdl-config --libs --cflags` -L/usr/X11R6/lib -lX11 -lpthread -lXext -lSDL_ttf install: netmapr cp -f netmapr /usr/local/bin ; [ ! -d ~/.netmapr ] && mkdir ~/.netmapr ; cp -f *.dat ~/.netmapr/ diff --git a/constants.h b/constants.h index 475caeb..8e4f95a 100644 --- a/constants.h +++ b/constants.h @@ -1,4 +1,4 @@ -#define VERSION "0.99" +#define VERSION "0.99a" #define BUFLEN 512 @@ -10,7 +10,7 @@ #define MAXPOINTS 20 #define MAXBUTTONS 40 -#define MAXMAPS 100 +#define MAXMAPS 20 #define MAXHISTORY 50 #define MAXCHILDREN 10 @@ -21,6 +21,8 @@ #define MAXLETTERVECTS 95 #define MAXTEXT 512 +#define CURSORWIDTH 6 + #define FIRSTLET 33 #define LASTLET 122 @@ -29,11 +31,13 @@ #define MAXLETTERWIDTH 100 #define MAXLETTERHEIGHT 100 -#define MAXOBJWIDTH 750 -#define MAXOBJHEIGHT 550 +#define MAXOBJWIDTH 300 +#define MAXOBJHEIGHT 300 #define MINOBJWIDTH 20 #define MINOBJHEIGHT 20 +#define MAPBOXTEXTHEIGHT 10 + #define MAXFILLSTACK 500000 #define OLDMAXVECTORSPERIMAGE (60) diff --git a/dist.sh b/dist.sh index d4fe9a7..7be0b04 100755 --- a/dist.sh +++ b/dist.sh @@ -5,7 +5,7 @@ FULLNAME=netmapr-${VERSION} TARFILE=${FULLNAME}.tar.gz mkdir ${FULLNAME} -cp Makefile Makefile.linux Makefile.freebsd Makefile.windows *.dat netmapr.c netmapr.h constants.h convert.c convert.h ${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}/ tar zcvf ${TARFILE} ${FULLNAME} diff --git a/example.map b/example.map new file mode 100644 index 0000000..c9b3120 Binary files /dev/null and b/example.map differ diff --git a/netmapr-small.jpg b/netmapr-small.jpg new file mode 100644 index 0000000..903f912 Binary files /dev/null and b/netmapr-small.jpg differ diff --git a/netmapr.c b/netmapr.c index 04878d0..be1b73e 100644 --- a/netmapr.c +++ b/netmapr.c @@ -8,6 +8,7 @@ #include #include +#include #include #include "netmapr.h" @@ -17,6 +18,8 @@ SDL_Surface *screen, *buffer; SDL_Surface *emptyimg; SDL_Event event; +TTF_Font *font[MAXLETTERHEIGHT]; + SDL_Color white = { 255, 255, 255, 0}; SDL_Color black = { 0, 0, 0, 0}; SDL_Color red = { 255, 0, 0, 0}; @@ -97,14 +100,16 @@ int main (int argc, char **argv) { strcpy(progdir, "/usr/local/share/netmapr"); } + printf("Starting netmapr v%s...\n", VERSION); + + + if (initgraphics()) { printf("Error initialising graphics.\n"); exit(1); } atexit(cleanup); - /* TEST */ - if (autoload) { loadmap(); strcpy(text, ""); @@ -170,6 +175,22 @@ int main (int argc, char **argv) { startlink(event.button.x,event.button.y); } } else if (event.button.button == SDL_BUTTON_RIGHT) { + // resize text + o = textat(event.button.x, event.button.y); + if (o != -1) { + map[curmap].curtext = o; + startresizetext(event.button.x,event.button.y); + } else { + // resize object + o = objat(event.button.x, event.button.y); + if (o != -1) { + map[curmap].curobj = o; + startresize(event.button.x,event.button.y); + } + } + + + /* // resize object o = objat(event.button.x, event.button.y); if (o != -1) { @@ -183,6 +204,7 @@ int main (int argc, char **argv) { startresizetext(event.button.x,event.button.y); } } + */ } else if (event.button.button == SDL_BUTTON_WHEELUP) { if (map[curmap].selecteditem != -1) { /* raise the selected object */ @@ -480,8 +502,12 @@ int main (int argc, char **argv) { break; } else if (isonmapboxchildren(event.button.x, event.button.y)) { int pos; + int th; + + /* calculate pixel size of mapbox text */ + th = TTF_FontHeight(font[MAPBOXTEXTHEIGHT]); /* change to child */ - pos = (event.button.y - (mapbox.y+(DEFTEXTH*2)+2)) / DEFTEXTH; + pos = (event.button.y - (mapbox.y+(th*2)+1)) / th; if (pos >= numchildren) { sprintf(statustext, "ERROR: Invalid child map %d (max is %d).",pos,numchildren); drawstatusbar(); @@ -974,8 +1000,13 @@ void changestate(int newstate) { } void cleanup(void) { + int i; SDL_FreeCursor(textmouse); SDL_FreeCursor(objmouse); + for (i = 1; i < MAXLETTERHEIGHT; i++) { + TTF_CloseFont(font[i]); + } + TTF_Quit(); SDL_Quit(); } @@ -1454,38 +1485,51 @@ void drawobject(SDL_Surface *dest, mapobject_t *o) { SDL_Surface *temps; SDL_Rect area; Uint32 bgcol; + int testing = 0; /* create temp surface */ - temps = SDL_CreateRGBSurface(SDL_SWSURFACE,(o->w + 3), (o->h + 3), + if (testing) { + printf("About to create surface..."); + fflush(stdout); + } + 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); /* draw onto temp surface */ + if (testing) { + printf("About to drawvector ..."); + fflush(stdout); + } drawvector(temps, &objtype[o->type].vimg, 0, 0, o->w, o->h, NULL); /* set transparent colour on temp surface */ + if (testing) { + printf("About to setcolour ..."); + fflush(stdout); + } 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; area.h = o->h; + if (testing) { + printf("About to blitsurface ..."); + fflush(stdout); + } SDL_BlitSurface(temps, 0, dest, &area); + if (testing) { + printf("About to return ..."); + fflush(stdout); + } + } void drawpixel(SDL_Surface *screen, int x, int y, SDL_Color c) { @@ -1553,6 +1597,7 @@ void drawmap(void) { int txoff,tyoff; int anchoreditem; + if ((state == S_SAVING) || (state == S_LOADING) || (state == S_MAPNAMING)) { /* show file dialog */ showfiledialog(); @@ -1574,37 +1619,41 @@ void drawmap(void) { return; } + if (testing) { + printf("START DRAWMAP\n"); fflush(stdout); + } + /* clear map */ fillcol = SDL_MapRGB(buffer->format, map[curmap].bgcol.r,map[curmap].bgcol.g,map[curmap].bgcol.b); SDL_FillRect(buffer, NULL, fillcol); - /* draw all objects links etc*/ + if (testing) { + printf("DRAWING THINGS \n"); fflush(stdout); + } + /* draw all map[curmap].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); - fflush(stdout); - } + 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); - fflush(stdout); - } + 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); - fflush(stdout); - } + 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); } } + if (testing) { + printf("FINISHED THINGS \n"); fflush(stdout); + } - /* highlight the selected object */ + if (testing) { + printf("DRAWING HIGHLIGHT\n"); fflush(stdout); + } + + /* highlight the selected map[curmap].object */ /* by drawing boxes in its corners */ if (map[curmap].selecteditem != -1) { if (map[curmap].selecteditemtype == T_OBJECT) { @@ -1734,19 +1783,30 @@ void drawmap(void) { } } + if (testing) { + printf("BLIT BUFFER TO SCREEN\n"); fflush(stdout); + } + /* blit buffer to screen */ SDL_BlitSurface(buffer, 0, screen,0); + if (testing) { + printf("START MAPBOX\n"); fflush(stdout); + } drawmapbox(); /* draw status bar */ + if (testing) { + printf("START STATUSBAR\n"); fflush(stdout); + } drawstatusbar(); - + if (testing) { + printf("FLIP\n"); fflush(stdout); + } /* flip */ SDL_UpdateRect(screen, 0, 0, map[curmap].width, map[curmap].height); - } void drawstatusbar(void) { @@ -1780,14 +1840,19 @@ void drawstatusbar(void) { /* show modified status */ if (modified) { - temp.x = map[curmap].width - 25; + int tw,th; + + temp.x = map[curmap].width - 30; temp.y = map[curmap].height+2; - temp.w = 20; - temp.h = DEFTEXTH; + temp.h = DEFTEXTH-1; + + /* calculate width */ + TTF_SizeText(font[temp.h], "MOD", &tw,&th); + temp.w = tw; temp.c = blue; temp.anchor = -1; strcpy(temp.text, "MOD"); - drawbox(screen, temp.x-3,temp.y-1,temp.x+temp.w+1,temp.y+temp.h+1,blue); + drawbox(screen, temp.x-3,temp.y-1,temp.x+tw+1,temp.y+th,blue); drawtext(screen, &temp); } @@ -1798,11 +1863,12 @@ void drawmapbox(void) { text_t temp; int x,y; int i; - int lh = DEFTEXTH -2; + int lh = MAPBOXTEXTHEIGHT; int found; int n; Uint32 fillcol; SDL_Rect area; + int tw,th; x = mapbox.x+1; @@ -1826,14 +1892,16 @@ void drawmapbox(void) { sprintf(temp.text, map[curmap].name); temp.x = x; temp.y = y; - temp.w = strlen(temp.text) * DEFTEXTW; temp.h = lh; + TTF_SizeText(font[lh], temp.text, &tw,&th); + temp.w = tw; temp.anchor = -1; temp.c = white; drawtext(screen, &temp); - y += DEFTEXTH; + //y += DEFTEXTH; + y += th; /* seperator line */ drawline(screen, x, y, x+mapbox.width-2, y, white); @@ -1842,12 +1910,12 @@ void drawmapbox(void) { /* show .. */ if (numhistory >= 1) { /* draw arrow */ - drawline(screen, x+5,y+(DEFTEXTH/2),x+mapbox.width-15,y+(DEFTEXTH/2),white); - drawline(screen, x+5,y+(DEFTEXTH/2),x+15,y+1,white); - drawline(screen, x+5,y+(DEFTEXTH/2),x+15,y+(DEFTEXTH-1),white); + drawline(screen, x+5,y+(lh/2),x+mapbox.width-15,y+(lh/2),white); + drawline(screen, x+5,y+(lh/2),x+15,y+1,white); + drawline(screen, x+5,y+(lh/2),x+15,y+(lh-1),white); } - y += DEFTEXTH; + y += th; /* children ... */ @@ -1867,8 +1935,9 @@ void drawmapbox(void) { //temp.x = x+DEFTEXTW; temp.x = x; temp.y = y; - temp.w = strlen(temp.text) * DEFTEXTW; temp.h = lh; + TTF_SizeText(font[lh], temp.text, &tw,&th); + temp.w = tw; temp.anchor = -1; temp.c = white; @@ -1877,7 +1946,7 @@ void drawmapbox(void) { children[numchildren] = map[curmap].obj[i].child; numchildren++; - y += DEFTEXTH; + y += th; } } } @@ -2010,7 +2079,6 @@ void drawobox(void) { } - /* oooo */ /* draw selector */ outlinecol = red; outlinepos = map[curmap].selectedtype - (obox.pos*3); @@ -2038,12 +2106,12 @@ void drawscreen(void){ } void drawtext(SDL_Surface *dest, text_t *t) { - int x,y; int tw,th; - int i; - int txoff,tyoff; + SDL_Rect area; + SDL_Surface *ts; + if (strlen(t->text) == 0) { return; } @@ -2060,9 +2128,21 @@ void drawtext(SDL_Surface *dest, text_t *t) { txoff = map[curmap].obj[t->anchor].x; tyoff = map[curmap].obj[t->anchor].y; } - + + if (th >= MAXLETTERHEIGHT) th = MAXLETTERHEIGHT-1; + ts = TTF_RenderText_Blended(font[th], t->text, t->c); + area.x = t->x + txoff; + area.y = t->y + tyoff; + area.w = t->w; + area.h = t->h; + + SDL_BlitSurface(ts, 0, dest, &area); + SDL_FreeSurface(ts); + + //printf("drawtext() of: '%s' (len %d)\n",t->text, strlen(t->text)); fflush(stdout); + /* for (i = 0; i < strlen(t->text); i++) { x = t->x + (i * tw) + txoff; y = t->y + tyoff; @@ -2074,6 +2154,7 @@ void drawtext(SDL_Surface *dest, text_t *t) { //printf("drawing letter: '%c' at %d,%d\n",t->text[i],x, t->y); fflush(stdout); } } + */ } void drawtoolbox(void) { @@ -2237,6 +2318,8 @@ void drawvector(SDL_Surface *dest, vectorimg_t *vimg, int x, int y, int w, int h int endtext(void) { SDL_Rect area; + int tw,th; + /* paste old background */ if (bg != NULL) { area.x = bgx; @@ -2264,7 +2347,12 @@ int endtext(void) { map[curmap].textob[map[curmap].numtext].x = startx - map[curmap].obj[textanchor].x; map[curmap].textob[map[curmap].numtext].y = starty - map[curmap].obj[textanchor].y; } - map[curmap].textob[map[curmap].numtext].w = strlen(text) * (DEFTEXTW); + + /* calculate width */ + TTF_SizeText(font[DEFTEXTH], text, &tw,&th); + + + map[curmap].textob[map[curmap].numtext].w = tw; map[curmap].textob[map[curmap].numtext].h = DEFTEXTH; map[curmap].textob[map[curmap].numtext].c = fgcol; @@ -2422,6 +2510,9 @@ int getcolor(SDL_Surface *dest, int x, int y, SDL_Color *col) { void drawyn(char *prompt) { SDL_Rect area; text_t text; + int promptsize = 40; + int yesnosize = 100; + int tw,th; /* clear map to red */ area.x = 0; @@ -2433,8 +2524,9 @@ void drawyn(char *prompt) { drawbox(screen, 0, 200,399,500,blue); drawbox(screen, 400, 200,799,500,blue); - text.w = strlen(prompt)*DEFTEXTW*2; - text.h = 50; + TTF_SizeText(font[promptsize], prompt, &tw,&th); + text.w = tw; + text.h = promptsize; text.x = (map[curmap].width/2) - (text.w/2); text.y = 100; text.anchor = -1; @@ -2443,18 +2535,22 @@ void drawyn(char *prompt) { drawtext(screen, &text); /* draw yes & no */ - text.x = 50; + text.h = yesnosize; + TTF_SizeText(font[promptsize], "Yes", &tw,&th); + text.w = tw; + text.x = ((map[curmap].width-SIDEBARW) / 4) - (tw / 2); text.y = 300; - text.w = 300; - text.h = 100; text.anchor = -1; text.c = blue; strcpy(text.text, "Yes"); drawtext(screen, &text); - text.x = 500; + + + text.h = yesnosize; + TTF_SizeText(font[promptsize], "No", &tw,&th); + text.w = tw; + text.x = (((map[curmap].width-SIDEBARW) / 4) * 3) - (tw / 2); text.y = 300; - text.w = 200; - text.h = 100; text.anchor = -1; text.c = blue; strcpy(text.text, "No"); @@ -2776,6 +2872,27 @@ int initgraphics(void) { initvars(); + /* load fonts */ + TTF_Init(); + sprintf(file, "verdana.ttf"); + for (i = 1; i < MAXLETTERHEIGHT; i++) { + font[i] = TTF_OpenFont(file,i); + if (!font[i]) { + sprintf(file, "/usr/local/share/netmapr/verdata.ttf"); + font[i] = TTF_OpenFont(file,i); + } + if (!font[i]) { + sprintf(file, "%s/verdana.ttf",progdir); + font[i] = TTF_OpenFont(file,i); + } + if (!font[i]) { + printf("Error opening font: %s\n", TTF_GetError()); + exit(1); + } + } + printf("Font load complete - %d sizes read.\n",MAXLETTERHEIGHT); + + /* initialise mouse cursors */ /* regular cursor */ @@ -2877,7 +2994,6 @@ int initgraphics(void) { } - printf("Reading shapes...\n"); f = fopen("objects.dat","rt"); if (!f) { sprintf(file, "/usr/local/share/netmapr/objects.dat"); @@ -3032,7 +3148,6 @@ int initgraphics(void) { fclose(f); printf("Shape load complete - %d objects found.\n",numobjtypes); - printf("Reading buttons...\n"); f = fopen("buttons.dat","rt"); if (!f) { sprintf(file, "/usr/local/share/netmapr/buttons.dat"); @@ -3189,6 +3304,42 @@ int initgraphics(void) { fclose(f); printf("Button load complete - %d buttons found.\n",numbuttons); + //////////////////////////////////////////////////////////// + /// XXX: TESTING /// + +/* + x = 10; y = 10; + for (i = 0; i < numletters; i++) { + int lw,lh; + lw = 8; + lh = 10; + drawvector(screen, &letter[i].vect, x, y, lw,lh); + x = x + lw + 2; + if (x >= (map[curmap].width - lw)) { + x = 0; + y = y + lh + 2; + } + } + SDL_Flip(screen); + while(1) { + while (SDL_PollEvent(&event)) { + switch (event.type) { + case SDL_KEYDOWN: + exit(1); + } + } + } +*/ + //////////////////////////////////////////////////////////// + + + + return 0; + +} + +#if 0 +int readletters() { printf("Reading letters...\n"); f = fopen("letters.dat","rt"); if (!f) { @@ -3318,42 +3469,10 @@ int initgraphics(void) { line++; } fclose(f); - printf("Letter load complete - %d letters found.\n",numletters); - - //////////////////////////////////////////////////////////// - /// XXX: TESTING /// - -/* - x = 10; y = 10; - for (i = 0; i < numletters; i++) { - int lw,lh; - lw = 8; - lh = 10; - drawvector(screen, &letter[i].vect, x, y, lw,lh); - x = x + lw + 2; - if (x >= (map[curmap].width - lw)) { - x = 0; - y = y + lh + 2; - } - } - SDL_Flip(screen); - while(1) { - while (SDL_PollEvent(&event)) { - switch (event.type) { - case SDL_KEYDOWN: - exit(1); - } - } - } -*/ - //////////////////////////////////////////////////////////// - - - - return 0; - } +#endif + int isonline (int fx, int fy, int x1, int y1, int x2, int y2) { int deltax, deltay; int numpixels; @@ -3760,6 +3879,7 @@ int showfiledialog(void) { SDL_Rect area,sarea; int y; SDL_Color ccol; + int tw,th; /* clear map */ fillcol = SDL_MapRGB(buffer->format, map[curmap].bgcol.r,map[curmap].bgcol.g,map[curmap].bgcol.b); @@ -3780,21 +3900,23 @@ int showfiledialog(void) { strcpy(temp.text,"Enter filename:"); break; } - temp.w = strlen(temp.text) * (DEFTEXTW * 2); temp.h = DEFTEXTH*2; + TTF_SizeText(font[DEFTEXTH*2], temp.text, &tw,&th); + temp.w = tw; temp.x = (map[curmap].width / 2) - (temp.w / 2); - temp.y = (map[curmap].height / 2) - (temp.h*4); + temp.y = (map[curmap].height / 2) - (th*4); temp.c = black; temp.anchor = -1; drawtext(buffer, &temp); /* draw outlines */ - drawbox(buffer,0,0,map[curmap].width-1,map[curmap].height-DEFTEXTH-3,blue); + drawbox(buffer,0,0,map[curmap].width-1,map[curmap].height-th-3,blue); - drawbox(buffer,0,(map[curmap].height/2)-2,map[curmap].width-1,(map[curmap].height/2)+(DEFTEXTH*2)+2,blue); + drawbox(buffer,0,(map[curmap].height/2)-2,map[curmap].width-1,(map[curmap].height/2)+th+2,blue); /* actually draw the text */ + TTF_SizeText(font[DEFTEXTH*2], text, &tw,&th); /* paste old background */ if (bg != NULL) { @@ -3810,7 +3932,7 @@ int showfiledialog(void) { /* copy new background */ sarea.x = startx; sarea.y = starty; - sarea.w = ((strlen(text)+1) * (DEFTEXTW*2)) +2; // include space for cursor + sarea.w = tw + CURSORWIDTH; // include space for cursor sarea.h = DEFTEXTH*2; bg = SDL_CreateRGBSurface(SDL_SWSURFACE,sarea.w, sarea.h, buffer->format->BitsPerPixel, buffer->format->Rmask, @@ -3823,7 +3945,7 @@ int showfiledialog(void) { strcpy(temp.text, text); temp.x = startx; temp.y = starty; - temp.w = strlen(temp.text) * (DEFTEXTW*2); + temp.w = tw; temp.h = DEFTEXTH*2; temp.c = fgcol; temp.anchor = -1; @@ -3832,8 +3954,8 @@ int showfiledialog(void) { /* draw cursor (a solid block) */ ccol = blue; - for (y = starty ; y < (starty + DEFTEXTH*2); y++ ) { - drawline(buffer, startx + temp.w, y, startx + temp.w + (DEFTEXTW*2),y,ccol); + for (y = starty ; y < (starty + th); y++ ) { + drawline(buffer, startx + tw, y, startx + tw + CURSORWIDTH,y,ccol); } /* blit to screen */ @@ -4447,6 +4569,10 @@ int updateresizetextshadow(int x, int y) { int xdiff,ydiff; int txoff,tyoff; + int textsize; + char *tp; + int tw,th; + if (map[curmap].textob[map[curmap].curtext].anchor == -1) { txoff = 0; tyoff = 0; @@ -4454,15 +4580,25 @@ int updateresizetextshadow(int x, int y) { txoff = map[curmap].obj[map[curmap].textob[map[curmap].curtext].anchor].x; tyoff = map[curmap].obj[map[curmap].textob[map[curmap].curtext].anchor].y; } - - xdiff = x - startx; + // + ydiff = y - starty; - if ((map[curmap].textob[map[curmap].curtext].w + xdiff) > strlen(map[curmap].textob[map[curmap].curtext].text) * MAXLETTERWIDTH) xdiff = (strlen(map[curmap].textob[map[curmap].curtext].text) * MAXLETTERWIDTH)-map[curmap].textob[map[curmap].curtext].w; - if ((map[curmap].textob[map[curmap].curtext].h + ydiff) > MAXLETTERHEIGHT) ydiff = MAXLETTERHEIGHT - map[curmap].textob[map[curmap].curtext].h; - if ((map[curmap].textob[map[curmap].curtext].w + xdiff) < strlen(map[curmap].textob[map[curmap].curtext].text) * MINLETTERWIDTH) - xdiff = (strlen(map[curmap].textob[map[curmap].curtext].text) * MINLETTERWIDTH) - map[curmap].textob[map[curmap].curtext].w ; + + //if ((map[curmap].textob[map[curmap].curtext].w + xdiff) > strlen(map[curmap].textob[map[curmap].curtext].text) * MAXLETTERWIDTH) xdiff = (strlen(map[curmap].textob[map[curmap].curtext].text) * MAXLETTERWIDTH)-map[curmap].textob[map[curmap].curtext].w; + if ((map[curmap].textob[map[curmap].curtext].h + ydiff) > MAXLETTERHEIGHT) ydiff = MAXLETTERHEIGHT - map[curmap].textob[map[curmap].curtext].h - 1; + //if ((map[curmap].textob[map[curmap].curtext].w + xdiff) < strlen(map[curmap].textob[map[curmap].curtext].text) * MINLETTERWIDTH) + // xdiff = (strlen(map[curmap].textob[map[curmap].curtext].text) * MINLETTERWIDTH) - map[curmap].textob[map[curmap].curtext].w ; if ((map[curmap].textob[map[curmap].curtext].h + ydiff) < MINLETTERHEIGHT) ydiff = MINLETTERHEIGHT - map[curmap].textob[map[curmap].curtext].h ; + + + /* calculate x based on text height and length */ + textsize = map[curmap].textob[map[curmap].curtext].h + ydiff; + tp = map[curmap].textob[map[curmap].curtext].text; + TTF_SizeText(font[textsize], tp, &tw, &th); + x = startx + tw; + xdiff = tw - map[curmap].textob[map[curmap].curtext].w; + /* replace old bg */ @@ -4516,6 +4652,7 @@ int updatetextcursor(void) { SDL_Rect area; SDL_Color ccol = blue; text_t temp; + int tw,th; if ((state == S_SAVING) || (state == S_LOADING) || (state == S_MAPNAMING)) { showfiledialog(); @@ -4537,8 +4674,12 @@ int updatetextcursor(void) { /* copy new background */ sarea.x = startx; sarea.y = starty; - sarea.w = ((strlen(text)+1) * (DEFTEXTW)) +2; // include space for cursor - sarea.h = DEFTEXTH; + /* calculate text width */ + TTF_SizeText(font[DEFTEXTH], text, &tw, &th); + sarea.w = tw + CURSORWIDTH + 3; + sarea.h = th; + //sarea.h = DEFTEXTH; + //sarea.w = ((strlen(text)+1) * (DEFTEXTW)) +2; // include space for cursor bg = SDL_CreateRGBSurface(SDL_SWSURFACE,sarea.w, sarea.h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask,screen->format->Bmask, @@ -4550,7 +4691,7 @@ int updatetextcursor(void) { strcpy(temp.text, text); temp.x = startx; temp.y = starty; - temp.w = strlen(text) * (DEFTEXTW); + temp.w = tw; temp.h = DEFTEXTH; temp.c = fgcol; temp.anchor = -1; @@ -4558,11 +4699,11 @@ int updatetextcursor(void) { drawtext(screen, &temp); /* draw cursor (a solid block) */ - for (y = starty ; y < (starty + DEFTEXTH); y++ ) { - drawline(screen, startx + temp.w, y, startx + temp.w + DEFTEXTW,y,ccol); + for (y = starty ; y < (starty + th); y++ ) { + drawline(screen, startx + tw+1, y, startx + tw + CURSORWIDTH,y,ccol); } - SDL_UpdateRect(screen, startx, starty, temp.w + DEFTEXTW, DEFTEXTH); + SDL_UpdateRect(screen, startx, starty, tw + CURSORWIDTH + 3 , th); return FALSE; @@ -4863,6 +5004,8 @@ int endtextresize(int x, int y) { int origw,origh; int neww,newh; + char *tp; + int tw,th; SDL_FreeSurface(bg); @@ -4872,20 +5015,27 @@ int endtextresize(int x, int y) { newh = map[curmap].textob[map[curmap].curtext].h; - if (map[curmap].textob[map[curmap].curtext].w + (x - startx) > 0) { - neww = map[curmap].textob[map[curmap].curtext].w + (x - startx); - } if (map[curmap].textob[map[curmap].curtext].h + (y - starty) > 0) { newh = map[curmap].textob[map[curmap].curtext].h + (y - starty); } - if (neww < strlen(map[curmap].textob[map[curmap].curtext].text) * MINLETTERWIDTH) neww = strlen(map[curmap].textob[map[curmap].curtext].text) * MINLETTERWIDTH; + /* check for valid height */ if (newh < MINLETTERHEIGHT) newh = MINLETTERHEIGHT; + if (newh >= MAXLETTERHEIGHT) newh = MAXLETTERHEIGHT-1; + if ((map[curmap].textob[map[curmap].curtext].y + newh) >= map[curmap].height ) newh = map[curmap].height - map[curmap].textob[map[curmap].curtext].y - 1; + + /* calculate new width based on height */ + tp = map[curmap].textob[map[curmap].curtext].text; + TTF_SizeText(font[newh], tp, &tw, &th); + + //if (map[curmap].textob[map[curmap].curtext].w + tw > 0) { + neww = tw; + //} + + if (neww < strlen(map[curmap].textob[map[curmap].curtext].text) * MINLETTERWIDTH) neww = strlen(map[curmap].textob[map[curmap].curtext].text) * MINLETTERWIDTH; if (neww > strlen(map[curmap].textob[map[curmap].curtext].text) * MAXLETTERWIDTH ) neww = strlen(map[curmap].textob[map[curmap].curtext].text) * MAXLETTERWIDTH; if ((map[curmap].textob[map[curmap].curtext].x + neww) >= map[curmap].width ) neww = map[curmap].width - map[curmap].textob[map[curmap].curtext].x - 1; - if (newh > MAXLETTERHEIGHT) newh = MAXLETTERHEIGHT; - if ((map[curmap].textob[map[curmap].curtext].y + newh) >= map[curmap].height ) newh = map[curmap].height - map[curmap].textob[map[curmap].curtext].y - 1; map[curmap].textob[map[curmap].curtext].w = neww; map[curmap].textob[map[curmap].curtext].h = newh; diff --git a/netmapr.jpg b/netmapr.jpg index a11fb09..20b4099 100755 Binary files a/netmapr.jpg and b/netmapr.jpg differ diff --git a/verdana.ttf b/verdana.ttf new file mode 100644 index 0000000..118b7eb Binary files /dev/null and b/verdana.ttf differ