- fixed yes/no selection dialogue in resized windows

- Scrollbars now more accurate
- Added shortcuts: HOME goes to top-left, END goes to bottom right
- Fixed various graphical glitches in dialogue screens
- Reduced "automatic grow" size
- Fixed infinite loop bug when performing a "findnext" in a map with no 
  text objects
This commit is contained in:
Rob Pearce 2006-05-23 01:16:23 +00:00
parent 8fd5f8d260
commit f2a1804571
2 changed files with 56 additions and 47 deletions

101
netmapr.c
View File

@ -516,7 +516,7 @@ int main (int argc, char **argv) {
drawmap(); drawmap();
} }
} else if (state == S_REALLYQUIT) { } else if (state == S_REALLYQUIT) {
o = getyn(event.button.x, event.button.y); o = getyn(event.button.x-screenx, event.button.y-screeny);
if (o == YES) { if (o == YES) {
done = TRUE; done = TRUE;
} else { } else {
@ -1696,13 +1696,14 @@ int main (int argc, char **argv) {
} }
} }
} else { } else {
if (c2 == SDLK_F3) { if (c2 == SDLK_HOME) {
movescreenx(-100); screenx = 0;
if (screenx < 0) screenx = 0; screeny = 0;
drawmap(); drawmap();
} }
if (c2 == SDLK_F4) { if (c2 == SDLK_END) {
movescreenx(100); screenx = map[curmap].width - (screen->w-SIDEBARW);
screeny = map[curmap].height - (screen->h-STATUSH);
drawmap(); drawmap();
} }
if (c == 'a') { /* add map[curmap].object */ if (c == 'a') { /* add map[curmap].object */
@ -1713,7 +1714,7 @@ int main (int argc, char **argv) {
if (c == '/') { /* search/find */ if (c == '/') { /* search/find */
if (state == S_NONE) { if (state == S_NONE) {
startx = 1; startx = 1;
starty = (map[curmap].height/2)-2; starty = ((screen->h-STATUSH)/2)-2;
bg = NULL; bg = NULL;
strcpy(text, ""); strcpy(text, "");
changestate(S_SEARCH); changestate(S_SEARCH);
@ -1755,7 +1756,7 @@ int main (int argc, char **argv) {
} }
if (c == 's') { /* save */ if (c == 's') { /* save */
startx = 1; startx = 1;
starty = (map[curmap].height/2)-2; starty = ((screen->h-STATUSH)/2)-2;
bg = NULL; bg = NULL;
strcpy(text, currentfilename); strcpy(text, currentfilename);
changestate(S_SAVING); changestate(S_SAVING);
@ -1763,7 +1764,7 @@ int main (int argc, char **argv) {
} }
if ((c == 'l') || (c == 'o')) { /* load, open */ if ((c == 'l') || (c == 'o')) { /* load, open */
startx = 1; startx = 1;
starty = (map[curmap].height/2)-2; starty = ((screen->h-STATUSH)/2)-2;
bg = NULL; bg = NULL;
strcpy(text, currentfilename); strcpy(text, currentfilename);
changestate(S_LOADING); changestate(S_LOADING);
@ -2091,11 +2092,17 @@ void calcmapdimensions(void) {
} }
} }
/* set map dimensions */ /* set map dimensions - automatically grow/shrink to be a bit bigger than required size */
if (maxx <= (map[curmap].width - 400)) map[curmap].width = maxx + 100; if (maxx <= (map[curmap].width - 300)) map[curmap].width = maxx + 100;
if (maxy <= (map[curmap].height - 400)) map[curmap].height = maxx + 100; if (maxy <= (map[curmap].height - 300)) map[curmap].height = maxx + 100;
if (maxx+400 > map[curmap].width) map[curmap].width = maxx + 400; if (maxx+200 > map[curmap].width) map[curmap].width = maxx + 200;
if (maxy+400 > map[curmap].height) map[curmap].height = maxy + 400; if (maxy+200 > map[curmap].height) map[curmap].height = maxy + 200;
/* make sure map is always at least as big as the visible screen size */
if (map[curmap].width < screen->w - SIDEBARW) map[curmap].width = screen->w - SIDEBARW;
if (map[curmap].height < screen->h - STATUSH) map[curmap].height = screen->h - STATUSH;
/* determine position of sidebar */ /* determine position of sidebar */
obox.x = screen->w - SIDEBARW; obox.x = screen->w - SIDEBARW;
@ -2868,12 +2875,13 @@ int dosearchnext(void) {
int i = -1; int i = -1;
int firsttime = TRUE; int firsttime = TRUE;
int m; int m;
int numtextfound = 0;
/* go through each text object until we find what we're looking for */ /* go through each text object until we find what we're looking for */
for (m = searchmap; ; m++) { /* for each map */ for (m = searchmap; ; m++) { /* for each map */
if (m >= nummaps) { if (m >= nummaps) {
printf("wrapped\n");
fflush(stdout);
m = 0; m = 0;
searchwrap = TRUE; searchwrap = TRUE;
} }
@ -2885,6 +2893,12 @@ fflush(stdout);
i = 0; i = 0;
} }
if ((m == searchmap) && (numtextfound == 0) && (!firsttime)) {
/* no text objects exist */
return TRUE;
}
for (; i < map[m].numtext; i++) { /* for each text object */ for (; i < map[m].numtext; i++) { /* for each text object */
/* back to start - not found */ /* back to start - not found */
@ -2893,8 +2907,6 @@ fflush(stdout);
return TRUE; return TRUE;
} }
printf("searching map %d text %d\n",m,i);
fflush(stdout);
/* does it contain the search string? */ /* does it contain the search string? */
if (strstr(map[m].textob[i].text, searchtext)) { if (strstr(map[m].textob[i].text, searchtext)) {
drillto(m); drillto(m);
@ -2907,6 +2919,9 @@ fflush(stdout);
return FALSE; return FALSE;
} }
} }
numtextfound += (map[m].numtext);
} }
return TRUE; return TRUE;
@ -4146,6 +4161,9 @@ void drawmap(void) {
void drawxscrollbar(void) { void drawxscrollbar(void) {
int barw; int barw;
double barx;
barx = ((double)screenx / (double)map[curmap].width) * (screen->w - SIDEBARW - SBSIZE);
/* scrollbar outline */ /* scrollbar outline */
drawbox(screen, 0, screen->h - STATUSH - SBSIZE, drawbox(screen, 0, screen->h - STATUSH - SBSIZE,
@ -4153,16 +4171,19 @@ void drawxscrollbar(void) {
/* screen position */ /* screen position */
barw = (((double)(screen->w - SIDEBARW - SBSIZE) / (double)map[curmap].width) * (screen->w - SIDEBARW - SBSIZE)); barw = (((double)(screen->w - SIDEBARW - SBSIZE) / (double)map[curmap].width) * (screen->w - SIDEBARW - SBSIZE));
if (screenx+barw > (screen->w - SIDEBARW-SBSIZE)) barw = screen->w - SIDEBARW - SBSIZE - screenx; if (barx+barw > (screen->w - SIDEBARW-SBSIZE)) barw = screen->w - SIDEBARW - SBSIZE - barx;
drawbox(screen, screenx, screen->h - STATUSH - SBSIZE+1, drawbox(screen, barx, screen->h - STATUSH - SBSIZE+1,
screenx + barw, screen->h - STATUSH - 2, blue , &blue); barx + barw, screen->h - STATUSH - 2, blue , &blue);
SDL_UpdateRect(screen, 0,screen->h - STATUSH - SBSIZE, screen->w, SBSIZE); SDL_UpdateRect(screen, 0,screen->h - STATUSH - SBSIZE, screen->w, SBSIZE);
} }
void drawyscrollbar(void) { void drawyscrollbar(void) {
int barh; int barh;
double bary;
bary = ((double)screeny / (double)map[curmap].height) * (screen->h - STATUSH - SBSIZE);
/* scrollbar outline */ /* scrollbar outline */
drawbox(screen, screen->w - SIDEBARW - SBSIZE, 0, drawbox(screen, screen->w - SIDEBARW - SBSIZE, 0,
@ -4170,24 +4191,14 @@ void drawyscrollbar(void) {
/* screen position */ /* screen position */
barh = (((double)(screen->h - STATUSH - SBSIZE) / (double)map[curmap].height) * (screen->h - STATUSH - SBSIZE)); barh = (((double)(screen->h - STATUSH - SBSIZE) / (double)map[curmap].height) * (screen->h - STATUSH - SBSIZE));
if (screeny+barh > (screen->h - STATUSH - SBSIZE)) barh = screen->h - STATUSH - SBSIZE - screeny; if (bary+barh > (screen->h - STATUSH - SBSIZE)) barh = screen->h - STATUSH - SBSIZE - bary;
drawbox(screen, screen->w - SIDEBARW - SBSIZE+1, screeny, drawbox(screen, screen->w - SIDEBARW - SBSIZE+1, bary,
screen->w - SIDEBARW - 3, screeny + barh, blue , &blue); screen->w - SIDEBARW - 3, bary + barh, blue , &blue);
SDL_UpdateRect(screen, screen->w - SIDEBARW - SBSIZE, 0, SBSIZE, screen->h - STATUSH - SBSIZE - 1); SDL_UpdateRect(screen, screen->w - SIDEBARW - SBSIZE, 0, SBSIZE, screen->h - STATUSH - SBSIZE - 1);
} }
void movescreenx(int amt) {
screenx += amt;
validatescreenpos();
}
void movescreeny(int amt) {
screeny += amt;
validatescreenpos();
}
void validatescreenpos(void) { void validatescreenpos(void) {
if (screenx + (screen->w - SIDEBARW) > map[curmap].width) { if (screenx + (screen->w - SIDEBARW) > map[curmap].width) {
screenx = map[curmap].width - (screen->w - SIDEBARW); screenx = map[curmap].width - (screen->w - SIDEBARW);
@ -4545,8 +4556,8 @@ void drawmaplist(SDL_Surface *dest) {
fillcol = SDL_MapRGB(screen->format, map[curmap].bgcol.r,map[curmap].bgcol.g,map[curmap].bgcol.b); fillcol = SDL_MapRGB(screen->format, map[curmap].bgcol.r,map[curmap].bgcol.g,map[curmap].bgcol.b);
area.x = 0; area.x = 0;
area.y = 0; area.y = 0;
area.w = map[curmap].width; area.w = screen->w - SIDEBARW;
area.h = map[curmap].height-1; area.h = screen->h - STATUSH;
SDL_FillRect(screen, &area, fillcol); SDL_FillRect(screen, &area, fillcol);
x = 10; x = 10;
@ -4556,14 +4567,14 @@ void drawmaplist(SDL_Surface *dest) {
y = 50; y = 50;
drawbox(dest, x, y, map[curmap].width-1,y+(DEFTEXTH*2),blue, NULL); drawbox(dest, x, y, screen->w-SIDEBARW-1,y+(DEFTEXTH*2),blue, NULL);
drawtextat(screen, x+1, y+1, "(none)", (DEFTEXTH*2)-2, blue); drawtextat(screen, x+1, y+1, "(none)", (DEFTEXTH*2)-2, blue);
y += (DEFTEXTH*2); y += (DEFTEXTH*2);
for (i = maplistpos; i < nummaps; i++) { for (i = maplistpos; i < nummaps; i++) {
drawbox(dest, x, y, map[curmap].width-1,y+(DEFTEXTH*2),blue, NULL); drawbox(dest, x, y, screen->w-SIDEBARW-1,y+(DEFTEXTH*2),blue, NULL);
drawtextat(dest, x+1, y+1, map[i].name, (DEFTEXTH*2)-2, blue); drawtextat(dest, x+1, y+1, map[i].name, (DEFTEXTH*2)-2, blue);
y += (DEFTEXTH*2); y += (DEFTEXTH*2);
@ -4756,12 +4767,12 @@ void drawtextat(SDL_Surface *dest, int x, int y, char *text, int size, SDL_Color
if (x >= 0) { if (x >= 0) {
temp.x = x; temp.x = x;
} else { } else {
temp.x = (screen->w / 2) - (tw / 2); temp.x = ((screen->w-SIDEBARW) / 2) - (tw / 2);
} }
if (y >= 0) { if (y >= 0) {
temp.y = y; temp.y = y;
} else { } else {
temp.y = (screen->h / 2) - (th / 2); temp.y = ((screen->h-STATUSH) / 2) - (th / 2);
} }
temp.c.r = c.r; temp.c.r = c.r;
temp.c.g = c.g; temp.c.g = c.g;
@ -5772,7 +5783,7 @@ void drawyn(char *prompt) {
} }
int getyn(int x, int y) { int getyn(int x, int y) {
if (x >= (screen->w - SIDEBARW)/2) { if (x >= ((screen->w - SIDEBARW)/2)) {
return NO; return NO;
} else { } else {
return YES; return YES;
@ -7737,15 +7748,15 @@ int showfiledialog(void) {
TTF_SizeText(font[DEFTEXTH*2], t, &tw,&th); TTF_SizeText(font[DEFTEXTH*2], t, &tw,&th);
drawtextat(buffer, -1, (map[curmap].height / 2) - (th*4), t, DEFTEXTH*2, black); drawtextat(buffer, -1, (map[curmap].height / 4), t, DEFTEXTH*2, black);
if (state == S_SAVING) { if (state == S_SAVING) {
drawtextat(buffer, -1, (map[curmap].height / 2) - (th*3), "(use extension of .SVG or .BMP to export)", DEFTEXTH*2, black); drawtextat(buffer, -1, (map[curmap].height / 4) + (th*2), "(use extension of .SVG or .BMP to export)", DEFTEXTH*2, black);
} }
/* draw outlines */ /* draw outlines */
drawbox(buffer,0,0,map[curmap].width-1,map[curmap].height-th-3,blue, NULL); drawbox(buffer,0,0,screen->w - SIDEBARW, screen->h - STATUSH, blue, NULL);
drawbox(buffer,0,(map[curmap].height/2)-2,map[curmap].width-1,(map[curmap].height/2)+th+2,blue, NULL); drawbox(buffer,0,((screen->h-STATUSH)/2)-2,screen->w - SIDEBARW - 1,((screen->h-STATUSH)/2)+th+2,blue, NULL);
/* actually draw the text */ /* actually draw the text */
TTF_SizeText(font[DEFTEXTH*2], text, &tw,&th); TTF_SizeText(font[DEFTEXTH*2], text, &tw,&th);

View File

@ -273,8 +273,6 @@ int isongoback (int x, int y);
int isonxscrollbar(int x, int y); int isonxscrollbar(int x, int y);
int isonyscrollbar(int x, int y); int isonyscrollbar(int x, int y);
void initvars(void); void initvars(void);
void movescreenx(int amt);
void movescreeny(int amt);
void raiseselected(int amt); void raiseselected(int amt);
void seterror(int errnum); void seterror(int errnum);
void setinfo(int infonum); void setinfo(int infonum);