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