- Changed from dodgy homemade vector font to TTF font (verdana)

- Now requires SDL_ttf (and hence freetype)
- Can now resize text on top of objects without having to move the text off
  the object first!
- Added example network diagram.
- Updated screenshots to show TTF fonts
This commit is contained in:
Rob Pearce 2005-10-27 04:46:38 +00:00
parent ee62393d37
commit d398112fab
9 changed files with 280 additions and 126 deletions

View File

@ -1,5 +1,5 @@
netmapr: netmapr.c constants.h netmapr.h Makefile 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 install: netmapr
cp -f netmapr /usr/local/bin ; [ ! -d ~/.netmapr ] && mkdir ~/.netmapr ; cp -f *.dat ~/.netmapr/ cp -f netmapr /usr/local/bin ; [ ! -d ~/.netmapr ] && mkdir ~/.netmapr ; cp -f *.dat ~/.netmapr/

View File

@ -1,5 +1,5 @@
netmapr: netmapr.c constants.h netmapr.h Makefile 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 install: netmapr
cp -f netmapr /usr/local/bin ; [ ! -d ~/.netmapr ] && mkdir ~/.netmapr ; cp -f *.dat ~/.netmapr/ cp -f netmapr /usr/local/bin ; [ ! -d ~/.netmapr ] && mkdir ~/.netmapr ; cp -f *.dat ~/.netmapr/

View File

@ -1,4 +1,4 @@
#define VERSION "0.99" #define VERSION "0.99a"
#define BUFLEN 512 #define BUFLEN 512
@ -10,7 +10,7 @@
#define MAXPOINTS 20 #define MAXPOINTS 20
#define MAXBUTTONS 40 #define MAXBUTTONS 40
#define MAXMAPS 100 #define MAXMAPS 20
#define MAXHISTORY 50 #define MAXHISTORY 50
#define MAXCHILDREN 10 #define MAXCHILDREN 10
@ -21,6 +21,8 @@
#define MAXLETTERVECTS 95 #define MAXLETTERVECTS 95
#define MAXTEXT 512 #define MAXTEXT 512
#define CURSORWIDTH 6
#define FIRSTLET 33 #define FIRSTLET 33
#define LASTLET 122 #define LASTLET 122
@ -29,11 +31,13 @@
#define MAXLETTERWIDTH 100 #define MAXLETTERWIDTH 100
#define MAXLETTERHEIGHT 100 #define MAXLETTERHEIGHT 100
#define MAXOBJWIDTH 750 #define MAXOBJWIDTH 300
#define MAXOBJHEIGHT 550 #define MAXOBJHEIGHT 300
#define MINOBJWIDTH 20 #define MINOBJWIDTH 20
#define MINOBJHEIGHT 20 #define MINOBJHEIGHT 20
#define MAPBOXTEXTHEIGHT 10
#define MAXFILLSTACK 500000 #define MAXFILLSTACK 500000
#define OLDMAXVECTORSPERIMAGE (60) #define OLDMAXVECTORSPERIMAGE (60)

View File

@ -5,7 +5,7 @@ FULLNAME=netmapr-${VERSION}
TARFILE=${FULLNAME}.tar.gz TARFILE=${FULLNAME}.tar.gz
mkdir ${FULLNAME} 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} tar zcvf ${TARFILE} ${FULLNAME}

BIN
example.map Normal file

Binary file not shown.

BIN
netmapr-small.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

382
netmapr.c
View File

@ -8,6 +8,7 @@
#include <unistd.h> #include <unistd.h>
#include <SDL/SDL.h> #include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
#include <SDL/SDL_keysym.h> #include <SDL/SDL_keysym.h>
#include "netmapr.h" #include "netmapr.h"
@ -17,6 +18,8 @@ SDL_Surface *screen, *buffer;
SDL_Surface *emptyimg; SDL_Surface *emptyimg;
SDL_Event event; SDL_Event event;
TTF_Font *font[MAXLETTERHEIGHT];
SDL_Color white = { 255, 255, 255, 0}; SDL_Color white = { 255, 255, 255, 0};
SDL_Color black = { 0, 0, 0, 0}; SDL_Color black = { 0, 0, 0, 0};
SDL_Color red = { 255, 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"); strcpy(progdir, "/usr/local/share/netmapr");
} }
printf("Starting netmapr v%s...\n", VERSION);
if (initgraphics()) { if (initgraphics()) {
printf("Error initialising graphics.\n"); printf("Error initialising graphics.\n");
exit(1); exit(1);
} }
atexit(cleanup); atexit(cleanup);
/* TEST */
if (autoload) { if (autoload) {
loadmap(); loadmap();
strcpy(text, ""); strcpy(text, "");
@ -170,6 +175,22 @@ int main (int argc, char **argv) {
startlink(event.button.x,event.button.y); startlink(event.button.x,event.button.y);
} }
} else if (event.button.button == SDL_BUTTON_RIGHT) { } 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 // resize object
o = objat(event.button.x, event.button.y); o = objat(event.button.x, event.button.y);
if (o != -1) { if (o != -1) {
@ -183,6 +204,7 @@ int main (int argc, char **argv) {
startresizetext(event.button.x,event.button.y); startresizetext(event.button.x,event.button.y);
} }
} }
*/
} else if (event.button.button == SDL_BUTTON_WHEELUP) { } else if (event.button.button == SDL_BUTTON_WHEELUP) {
if (map[curmap].selecteditem != -1) { if (map[curmap].selecteditem != -1) {
/* raise the selected object */ /* raise the selected object */
@ -480,8 +502,12 @@ int main (int argc, char **argv) {
break; break;
} else if (isonmapboxchildren(event.button.x, event.button.y)) { } else if (isonmapboxchildren(event.button.x, event.button.y)) {
int pos; int pos;
int th;
/* calculate pixel size of mapbox text */
th = TTF_FontHeight(font[MAPBOXTEXTHEIGHT]);
/* change to child */ /* 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) { if (pos >= numchildren) {
sprintf(statustext, "ERROR: Invalid child map %d (max is %d).",pos,numchildren); sprintf(statustext, "ERROR: Invalid child map %d (max is %d).",pos,numchildren);
drawstatusbar(); drawstatusbar();
@ -974,8 +1000,13 @@ void changestate(int newstate) {
} }
void cleanup(void) { void cleanup(void) {
int i;
SDL_FreeCursor(textmouse); SDL_FreeCursor(textmouse);
SDL_FreeCursor(objmouse); SDL_FreeCursor(objmouse);
for (i = 1; i < MAXLETTERHEIGHT; i++) {
TTF_CloseFont(font[i]);
}
TTF_Quit();
SDL_Quit(); SDL_Quit();
} }
@ -1454,38 +1485,51 @@ void drawobject(SDL_Surface *dest, mapobject_t *o) {
SDL_Surface *temps; SDL_Surface *temps;
SDL_Rect area; SDL_Rect area;
Uint32 bgcol; Uint32 bgcol;
int testing = 0;
/* create temp surface */ /* 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->BitsPerPixel, screen->format->Rmask,
screen->format->Gmask,screen->format->Bmask, screen->format->Gmask,screen->format->Bmask,
screen->format->Amask); 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); bgcol = SDL_MapRGB(temps->format, map[curmap].bgcol.r,map[curmap].bgcol.g,map[curmap].bgcol.b);
SDL_FillRect(temps, NULL, bgcol); SDL_FillRect(temps, NULL, bgcol);
/* draw onto temp surface */ /* 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); drawvector(temps, &objtype[o->type].vimg, 0, 0, o->w, o->h, NULL);
/* set transparent colour on temp surface */ /* set transparent colour on temp surface */
if (testing) {
printf("About to setcolour ...");
fflush(stdout);
}
SDL_SetColorKey(temps, SDL_SRCCOLORKEY|SDL_RLEACCEL, bgcol); SDL_SetColorKey(temps, SDL_SRCCOLORKEY|SDL_RLEACCEL, bgcol);
/* blit to screen */ /* 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.x = o->x;
area.y = o->y; area.y = o->y;
area.w = o->w; area.w = o->w;
area.h = o->h; area.h = o->h;
if (testing) {
printf("About to blitsurface ...");
fflush(stdout);
}
SDL_BlitSurface(temps, 0, dest, &area); 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) { void drawpixel(SDL_Surface *screen, int x, int y, SDL_Color c) {
@ -1553,6 +1597,7 @@ void drawmap(void) {
int txoff,tyoff; int txoff,tyoff;
int anchoreditem; int anchoreditem;
if ((state == S_SAVING) || (state == S_LOADING) || (state == S_MAPNAMING)) { if ((state == S_SAVING) || (state == S_LOADING) || (state == S_MAPNAMING)) {
/* show file dialog */ /* show file dialog */
showfiledialog(); showfiledialog();
@ -1574,37 +1619,41 @@ void drawmap(void) {
return; return;
} }
if (testing) {
printf("START DRAWMAP\n"); fflush(stdout);
}
/* clear map */ /* clear map */
fillcol = SDL_MapRGB(buffer->format, map[curmap].bgcol.r,map[curmap].bgcol.g,map[curmap].bgcol.b); fillcol = SDL_MapRGB(buffer->format, map[curmap].bgcol.r,map[curmap].bgcol.g,map[curmap].bgcol.b);
SDL_FillRect(buffer, NULL, fillcol); 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++) { for (i = 0; i < map[curmap].numthings; i++) {
if (map[curmap].thing[i].type == T_OBJECT) { if (map[curmap].thing[i].type == T_OBJECT) {
if (testing) { 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); }
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]); drawobject(buffer, &map[curmap].obj[map[curmap].thing[i].id]);
} else if (map[curmap].thing[i].type == T_LINK) { } else if (map[curmap].thing[i].type == T_LINK) {
if (testing) { if (testing) { printf ("Drawing thing #%d (%d, link)\n",i,map[curmap].thing[i].id); fflush(stdout); }
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]); drawlink(buffer, &map[curmap].olink[map[curmap].thing[i].id]);
} else if (map[curmap].thing[i].type == T_TEXT) { } else if (map[curmap].thing[i].type == T_TEXT) {
if (testing) { if (testing) { printf ("Drawing thing #%d (%d, text)\n",i,map[curmap].thing[i].id); fflush(stdout); }
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]); drawtext(buffer, &map[curmap].textob[map[curmap].thing[i].id]);
} else { } else {
printf("WARNING: Thing #%d has unknown type %d!\n",i,map[curmap].thing[i].type); 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 */ /* by drawing boxes in its corners */
if (map[curmap].selecteditem != -1) { if (map[curmap].selecteditem != -1) {
if (map[curmap].selecteditemtype == T_OBJECT) { 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 */ /* blit buffer to screen */
SDL_BlitSurface(buffer, 0, screen,0); SDL_BlitSurface(buffer, 0, screen,0);
if (testing) {
printf("START MAPBOX\n"); fflush(stdout);
}
drawmapbox(); drawmapbox();
/* draw status bar */ /* draw status bar */
if (testing) {
printf("START STATUSBAR\n"); fflush(stdout);
}
drawstatusbar(); drawstatusbar();
if (testing) {
printf("FLIP\n"); fflush(stdout);
}
/* flip */ /* flip */
SDL_UpdateRect(screen, 0, 0, map[curmap].width, map[curmap].height); SDL_UpdateRect(screen, 0, 0, map[curmap].width, map[curmap].height);
} }
void drawstatusbar(void) { void drawstatusbar(void) {
@ -1780,14 +1840,19 @@ void drawstatusbar(void) {
/* show modified status */ /* show modified status */
if (modified) { if (modified) {
temp.x = map[curmap].width - 25; int tw,th;
temp.x = map[curmap].width - 30;
temp.y = map[curmap].height+2; temp.y = map[curmap].height+2;
temp.w = 20; temp.h = DEFTEXTH-1;
temp.h = DEFTEXTH;
/* calculate width */
TTF_SizeText(font[temp.h], "MOD", &tw,&th);
temp.w = tw;
temp.c = blue; temp.c = blue;
temp.anchor = -1; temp.anchor = -1;
strcpy(temp.text, "MOD"); 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); drawtext(screen, &temp);
} }
@ -1798,11 +1863,12 @@ void drawmapbox(void) {
text_t temp; text_t temp;
int x,y; int x,y;
int i; int i;
int lh = DEFTEXTH -2; int lh = MAPBOXTEXTHEIGHT;
int found; int found;
int n; int n;
Uint32 fillcol; Uint32 fillcol;
SDL_Rect area; SDL_Rect area;
int tw,th;
x = mapbox.x+1; x = mapbox.x+1;
@ -1826,14 +1892,16 @@ void drawmapbox(void) {
sprintf(temp.text, map[curmap].name); sprintf(temp.text, map[curmap].name);
temp.x = x; temp.x = x;
temp.y = y; temp.y = y;
temp.w = strlen(temp.text) * DEFTEXTW;
temp.h = lh; temp.h = lh;
TTF_SizeText(font[lh], temp.text, &tw,&th);
temp.w = tw;
temp.anchor = -1; temp.anchor = -1;
temp.c = white; temp.c = white;
drawtext(screen, &temp); drawtext(screen, &temp);
y += DEFTEXTH; //y += DEFTEXTH;
y += th;
/* seperator line */ /* seperator line */
drawline(screen, x, y, x+mapbox.width-2, y, white); drawline(screen, x, y, x+mapbox.width-2, y, white);
@ -1842,12 +1910,12 @@ void drawmapbox(void) {
/* show .. */ /* show .. */
if (numhistory >= 1) { if (numhistory >= 1) {
/* draw arrow */ /* draw arrow */
drawline(screen, x+5,y+(DEFTEXTH/2),x+mapbox.width-15,y+(DEFTEXTH/2),white); drawline(screen, x+5,y+(lh/2),x+mapbox.width-15,y+(lh/2),white);
drawline(screen, x+5,y+(DEFTEXTH/2),x+15,y+1,white); drawline(screen, x+5,y+(lh/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+15,y+(lh-1),white);
} }
y += DEFTEXTH; y += th;
/* children ... */ /* children ... */
@ -1867,8 +1935,9 @@ void drawmapbox(void) {
//temp.x = x+DEFTEXTW; //temp.x = x+DEFTEXTW;
temp.x = x; temp.x = x;
temp.y = y; temp.y = y;
temp.w = strlen(temp.text) * DEFTEXTW;
temp.h = lh; temp.h = lh;
TTF_SizeText(font[lh], temp.text, &tw,&th);
temp.w = tw;
temp.anchor = -1; temp.anchor = -1;
temp.c = white; temp.c = white;
@ -1877,7 +1946,7 @@ void drawmapbox(void) {
children[numchildren] = map[curmap].obj[i].child; children[numchildren] = map[curmap].obj[i].child;
numchildren++; numchildren++;
y += DEFTEXTH; y += th;
} }
} }
} }
@ -2010,7 +2079,6 @@ void drawobox(void) {
} }
/* oooo */
/* draw selector */ /* draw selector */
outlinecol = red; outlinecol = red;
outlinepos = map[curmap].selectedtype - (obox.pos*3); outlinepos = map[curmap].selectedtype - (obox.pos*3);
@ -2038,12 +2106,12 @@ void drawscreen(void){
} }
void drawtext(SDL_Surface *dest, text_t *t) { void drawtext(SDL_Surface *dest, text_t *t) {
int x,y;
int tw,th; int tw,th;
int i;
int txoff,tyoff; int txoff,tyoff;
SDL_Rect area;
SDL_Surface *ts;
if (strlen(t->text) == 0) { if (strlen(t->text) == 0) {
return; return;
} }
@ -2062,7 +2130,19 @@ void drawtext(SDL_Surface *dest, text_t *t) {
} }
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); //printf("drawtext() of: '%s' (len %d)\n",t->text, strlen(t->text)); fflush(stdout);
/*
for (i = 0; i < strlen(t->text); i++) { for (i = 0; i < strlen(t->text); i++) {
x = t->x + (i * tw) + txoff; x = t->x + (i * tw) + txoff;
y = t->y + tyoff; 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); //printf("drawing letter: '%c' at %d,%d\n",t->text[i],x, t->y); fflush(stdout);
} }
} }
*/
} }
void drawtoolbox(void) { 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) { int endtext(void) {
SDL_Rect area; SDL_Rect area;
int tw,th;
/* paste old background */ /* paste old background */
if (bg != NULL) { if (bg != NULL) {
area.x = bgx; 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].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].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].h = DEFTEXTH;
map[curmap].textob[map[curmap].numtext].c = fgcol; 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) { void drawyn(char *prompt) {
SDL_Rect area; SDL_Rect area;
text_t text; text_t text;
int promptsize = 40;
int yesnosize = 100;
int tw,th;
/* clear map to red */ /* clear map to red */
area.x = 0; area.x = 0;
@ -2433,8 +2524,9 @@ void drawyn(char *prompt) {
drawbox(screen, 0, 200,399,500,blue); drawbox(screen, 0, 200,399,500,blue);
drawbox(screen, 400, 200,799,500,blue); drawbox(screen, 400, 200,799,500,blue);
text.w = strlen(prompt)*DEFTEXTW*2; TTF_SizeText(font[promptsize], prompt, &tw,&th);
text.h = 50; text.w = tw;
text.h = promptsize;
text.x = (map[curmap].width/2) - (text.w/2); text.x = (map[curmap].width/2) - (text.w/2);
text.y = 100; text.y = 100;
text.anchor = -1; text.anchor = -1;
@ -2443,18 +2535,22 @@ void drawyn(char *prompt) {
drawtext(screen, &text); drawtext(screen, &text);
/* draw yes & no */ /* 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.y = 300;
text.w = 300;
text.h = 100;
text.anchor = -1; text.anchor = -1;
text.c = blue; text.c = blue;
strcpy(text.text, "Yes"); strcpy(text.text, "Yes");
drawtext(screen, &text); 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.y = 300;
text.w = 200;
text.h = 100;
text.anchor = -1; text.anchor = -1;
text.c = blue; text.c = blue;
strcpy(text.text, "No"); strcpy(text.text, "No");
@ -2776,6 +2872,27 @@ int initgraphics(void) {
initvars(); 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 */ /* initialise mouse cursors */
/* regular cursor */ /* regular cursor */
@ -2877,7 +2994,6 @@ int initgraphics(void) {
} }
printf("Reading shapes...\n");
f = fopen("objects.dat","rt"); f = fopen("objects.dat","rt");
if (!f) { if (!f) {
sprintf(file, "/usr/local/share/netmapr/objects.dat"); sprintf(file, "/usr/local/share/netmapr/objects.dat");
@ -3032,7 +3148,6 @@ int initgraphics(void) {
fclose(f); fclose(f);
printf("Shape load complete - %d objects found.\n",numobjtypes); printf("Shape load complete - %d objects found.\n",numobjtypes);
printf("Reading buttons...\n");
f = fopen("buttons.dat","rt"); f = fopen("buttons.dat","rt");
if (!f) { if (!f) {
sprintf(file, "/usr/local/share/netmapr/buttons.dat"); sprintf(file, "/usr/local/share/netmapr/buttons.dat");
@ -3189,6 +3304,42 @@ int initgraphics(void) {
fclose(f); fclose(f);
printf("Button load complete - %d buttons found.\n",numbuttons); 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"); printf("Reading letters...\n");
f = fopen("letters.dat","rt"); f = fopen("letters.dat","rt");
if (!f) { if (!f) {
@ -3318,41 +3469,9 @@ int initgraphics(void) {
line++; line++;
} }
fclose(f); 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);
}
}
}
*/
////////////////////////////////////////////////////////////
#endif
return 0;
}
int isonline (int fx, int fy, int x1, int y1, int x2, int y2) { int isonline (int fx, int fy, int x1, int y1, int x2, int y2) {
int deltax, deltay; int deltax, deltay;
@ -3760,6 +3879,7 @@ int showfiledialog(void) {
SDL_Rect area,sarea; SDL_Rect area,sarea;
int y; int y;
SDL_Color ccol; SDL_Color ccol;
int tw,th;
/* clear map */ /* clear map */
fillcol = SDL_MapRGB(buffer->format, map[curmap].bgcol.r,map[curmap].bgcol.g,map[curmap].bgcol.b); 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:"); strcpy(temp.text,"Enter filename:");
break; break;
} }
temp.w = strlen(temp.text) * (DEFTEXTW * 2);
temp.h = DEFTEXTH*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.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.c = black;
temp.anchor = -1; temp.anchor = -1;
drawtext(buffer, &temp); drawtext(buffer, &temp);
/* draw outlines */ /* 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 */ /* actually draw the text */
TTF_SizeText(font[DEFTEXTH*2], text, &tw,&th);
/* paste old background */ /* paste old background */
if (bg != NULL) { if (bg != NULL) {
@ -3810,7 +3932,7 @@ int showfiledialog(void) {
/* copy new background */ /* copy new background */
sarea.x = startx; sarea.x = startx;
sarea.y = starty; 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; sarea.h = DEFTEXTH*2;
bg = SDL_CreateRGBSurface(SDL_SWSURFACE,sarea.w, sarea.h, bg = SDL_CreateRGBSurface(SDL_SWSURFACE,sarea.w, sarea.h,
buffer->format->BitsPerPixel, buffer->format->Rmask, buffer->format->BitsPerPixel, buffer->format->Rmask,
@ -3823,7 +3945,7 @@ int showfiledialog(void) {
strcpy(temp.text, text); strcpy(temp.text, text);
temp.x = startx; temp.x = startx;
temp.y = starty; temp.y = starty;
temp.w = strlen(temp.text) * (DEFTEXTW*2); temp.w = tw;
temp.h = DEFTEXTH*2; temp.h = DEFTEXTH*2;
temp.c = fgcol; temp.c = fgcol;
temp.anchor = -1; temp.anchor = -1;
@ -3832,8 +3954,8 @@ int showfiledialog(void) {
/* draw cursor (a solid block) */ /* draw cursor (a solid block) */
ccol = blue; ccol = blue;
for (y = starty ; y < (starty + DEFTEXTH*2); y++ ) { for (y = starty ; y < (starty + th); y++ ) {
drawline(buffer, startx + temp.w, y, startx + temp.w + (DEFTEXTW*2),y,ccol); drawline(buffer, startx + tw, y, startx + tw + CURSORWIDTH,y,ccol);
} }
/* blit to screen */ /* blit to screen */
@ -4447,6 +4569,10 @@ int updateresizetextshadow(int x, int y) {
int xdiff,ydiff; int xdiff,ydiff;
int txoff,tyoff; int txoff,tyoff;
int textsize;
char *tp;
int tw,th;
if (map[curmap].textob[map[curmap].curtext].anchor == -1) { if (map[curmap].textob[map[curmap].curtext].anchor == -1) {
txoff = 0; txoff = 0;
tyoff = 0; tyoff = 0;
@ -4454,16 +4580,26 @@ int updateresizetextshadow(int x, int y) {
txoff = map[curmap].obj[map[curmap].textob[map[curmap].curtext].anchor].x; txoff = map[curmap].obj[map[curmap].textob[map[curmap].curtext].anchor].x;
tyoff = map[curmap].obj[map[curmap].textob[map[curmap].curtext].anchor].y; tyoff = map[curmap].obj[map[curmap].textob[map[curmap].curtext].anchor].y;
} }
//
xdiff = x - startx;
ydiff = y - starty; 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) * 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].w + xdiff) < strlen(map[curmap].textob[map[curmap].curtext].text) * MINLETTERWIDTH) if ((map[curmap].textob[map[curmap].curtext].h + ydiff) > MAXLETTERHEIGHT) ydiff = MAXLETTERHEIGHT - map[curmap].textob[map[curmap].curtext].h - 1;
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) * 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 ; 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 */ /* replace old bg */
area.x = bgx; area.x = bgx;
@ -4516,6 +4652,7 @@ int updatetextcursor(void) {
SDL_Rect area; SDL_Rect area;
SDL_Color ccol = blue; SDL_Color ccol = blue;
text_t temp; text_t temp;
int tw,th;
if ((state == S_SAVING) || (state == S_LOADING) || (state == S_MAPNAMING)) { if ((state == S_SAVING) || (state == S_LOADING) || (state == S_MAPNAMING)) {
showfiledialog(); showfiledialog();
@ -4537,8 +4674,12 @@ int updatetextcursor(void) {
/* copy new background */ /* copy new background */
sarea.x = startx; sarea.x = startx;
sarea.y = starty; sarea.y = starty;
sarea.w = ((strlen(text)+1) * (DEFTEXTW)) +2; // include space for cursor /* calculate text width */
sarea.h = DEFTEXTH; 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, bg = SDL_CreateRGBSurface(SDL_SWSURFACE,sarea.w, sarea.h,
screen->format->BitsPerPixel, screen->format->Rmask, screen->format->BitsPerPixel, screen->format->Rmask,
screen->format->Gmask,screen->format->Bmask, screen->format->Gmask,screen->format->Bmask,
@ -4550,7 +4691,7 @@ int updatetextcursor(void) {
strcpy(temp.text, text); strcpy(temp.text, text);
temp.x = startx; temp.x = startx;
temp.y = starty; temp.y = starty;
temp.w = strlen(text) * (DEFTEXTW); temp.w = tw;
temp.h = DEFTEXTH; temp.h = DEFTEXTH;
temp.c = fgcol; temp.c = fgcol;
temp.anchor = -1; temp.anchor = -1;
@ -4558,11 +4699,11 @@ int updatetextcursor(void) {
drawtext(screen, &temp); drawtext(screen, &temp);
/* draw cursor (a solid block) */ /* draw cursor (a solid block) */
for (y = starty ; y < (starty + DEFTEXTH); y++ ) { for (y = starty ; y < (starty + th); y++ ) {
drawline(screen, startx + temp.w, y, startx + temp.w + DEFTEXTW,y,ccol); 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; return FALSE;
@ -4863,6 +5004,8 @@ int endtextresize(int x, int y) {
int origw,origh; int origw,origh;
int neww,newh; int neww,newh;
char *tp;
int tw,th;
SDL_FreeSurface(bg); SDL_FreeSurface(bg);
@ -4872,20 +5015,27 @@ int endtextresize(int x, int y) {
newh = map[curmap].textob[map[curmap].curtext].h; 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) { if (map[curmap].textob[map[curmap].curtext].h + (y - starty) > 0) {
newh = map[curmap].textob[map[curmap].curtext].h + (y - starty); 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 < 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 (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 ((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].w = neww;
map[curmap].textob[map[curmap].curtext].h = newh; map[curmap].textob[map[curmap].curtext].h = newh;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 64 KiB

BIN
verdana.ttf Normal file

Binary file not shown.