- now re-calcing scrollbar size whenever diagram is modified

- can no longer accidentally change maps while scrolling vertically
- fixed graphical glitch when editting text while scrolled
- clicking mouse while entering text is now the same as pressing enter
- findnext now works again 
- when searching, the found object is more obviously highlighted
This commit is contained in:
Rob Pearce 2006-06-20 01:50:21 +00:00
parent 15b28974be
commit 9d04b4f215
3 changed files with 174 additions and 28 deletions

View File

@ -1,4 +1,4 @@
#define VERSION "1.8b"
#define VERSION "1.8c"
/* variable sizes */
#define SMALLBUFLEN 64 /* small text buffer */
@ -22,6 +22,7 @@
#define SIDEBARW 100 /* how width the toolbox/mapbox/objectbox are */
#define ERRORFLASHSPEED 5 /* how fast to fade out the statusbar error highlight */
#define INFOFLASHSPEED 2 /* how fast to fade out the statusbar information highlight */
#define SEARCHFLASHSPEED 5 /* how fast to fade out the search result box */
/* defaults */
#define DEFTEXTW 8 /* default text width (in pixels) for new text items */

197
netmapr.c
View File

@ -43,6 +43,12 @@ SDL_Color grey4 = { 30, 30, 30, USECOLOUR};
SDL_Color statusbarcolour = { 255, 255, 255, 0 };
SDL_Surface *searchbg;
int searchflash = 0;
int searchcounter = 0;
int searchticks = 0;
int oldsearchticks = 0;
int errorflash = 0;
int errorcounter = 0;
int errorticks = 0;
@ -225,6 +231,30 @@ int main (int argc, char **argv) {
done = 0;
while (!done) {
/* fade search result indicator */
if (searchflash > 0) {
searchticks = SDL_GetTicks();
if (searchticks - oldsearchticks >= SEARCHFLASHSPEED) {
searchflash--;
/* show the found object */
switch (state) {
case S_SAVING:
case S_LOADING:
case S_FGCOL:
case S_MAPNAMING:
case S_CREATETELE:
case S_REALLYQUIT:
case S_FILLCOL:
case S_SEARCH:
break;
default:
drawsearchflash();
break;
}
oldsearchticks = searchticks;
}
}
/* fade error panel */
if (errorflash > 0) {
errorticks = SDL_GetTicks();
@ -261,7 +291,7 @@ int main (int argc, char **argv) {
/* check for input */
//while (SDL_PollEvent(&event)) {
isevent = TRUE;
if (infoflash || errorflash) {
if (infoflash || errorflash || searchflash) {
if (!SDL_PollEvent(&event)) isevent = FALSE;
} else {
if (!SDL_WaitEvent(&event)) isevent = FALSE;
@ -283,6 +313,7 @@ int main (int argc, char **argv) {
drawscreen();
break;
case SDL_MOUSEBUTTONDOWN:
searchflash = 0;
if (isonxscrollbar(event.button.x, event.button.y)) {
/* middle of the screen goes to where we clicked */
screenx = (((double)event.button.x / (double)(screen->w - SIDEBARW)) * map[curmap].width)
@ -415,7 +446,7 @@ int main (int argc, char **argv) {
lowerselected(amt);
}
}
}
} /* end if state = none */
} else if (isonobox(event.button.x, event.button.y)) {
int amt = 1;
@ -432,6 +463,7 @@ int main (int argc, char **argv) {
}
break;
case SDL_MOUSEBUTTONUP:
searchflash = 0;
mod = SDL_GetModState();
if ((event.button.button == SDL_BUTTON_LEFT) && ((mod & KMOD_CTRL) == 0)) {
ticks = SDL_GetTicks();
@ -445,9 +477,11 @@ int main (int argc, char **argv) {
if ((state == S_XSCROLL) || (state == S_YSCROLL)) {
changestate(S_NONE);
drawmap();
}
if (isonmap(event.button.x, event.button.y)) {
} else if (state == S_EDITTEXT) {
endtextedit();
} else if (state == S_TYPETEXT) {
endtext();
} else if (isonmap(event.button.x, event.button.y)) {
event.button.x += screenx;
event.button.y += screeny;
if (state != S_REALLYQUIT) {
@ -878,21 +912,23 @@ int main (int argc, char **argv) {
drawmap();
break;
} else if (isonmapboxchildren(event.button.x, event.button.y)) {
int pos;
int th;
if ((state != S_XSCROLL) && (state != S_YSCROLL)) {
int pos;
int th;
/* calculate pixel size of mapbox text */
th = TTF_FontHeight(font[MAPBOXTEXTHEIGHT]);
/* change to child */
pos = (event.button.y - (mapbox.y+(th*2)+1)) / th;
/* adjust for offset if not a special value */
pos += mapbox.offset;
if (pos >= numchildren) {
seterror(255);
sprintf(statustext, "ERROR: Invalid child map %d (max is %d).",pos,numchildren);
drawstatusbar();
} else {
drillto(children[pos]);
/* calculate pixel size of mapbox text */
th = TTF_FontHeight(font[MAPBOXTEXTHEIGHT]);
/* change to child */
pos = (event.button.y - (mapbox.y+(th*2)+1)) / th;
/* adjust for offset if not a special value */
pos += mapbox.offset;
if (pos >= numchildren) {
seterror(255);
sprintf(statustext, "ERROR: Invalid child map %d (max is %d).",pos,numchildren);
drawstatusbar();
} else {
drillto(children[pos]);
}
}
break;
} else if (isontoolbox(event.button.x, event.button.y)) {
@ -1681,9 +1717,11 @@ int main (int argc, char **argv) {
if (dosearch()) {
seterror(255);
sprintf(statustext, "Not found: '%s'",searchtext);
setsearchflash(0);
} else {
setinfo(255);
sprintf(statustext, "Found '%s' in text object #%d (map '%s')",searchtext, map[curmap].selecteditem, map[curmap].name);
setsearchflash(255);
}
drawmap();
} else if (state == S_MAPNAMING) {
@ -1726,9 +1764,11 @@ int main (int argc, char **argv) {
if (dosearchnext()) {
seterror(255);
sprintf(statustext, "Not foundnext: '%s'",searchtext);
setsearchflash(0);
} else {
setinfo(255);
sprintf(statustext, "Foundnext %s'%s' in text object #%d (map '%s')",searchwrap ? "(wrapped) " : "",searchtext, map[curmap].selecteditem, map[curmap].name);
setsearchflash(255);
}
drawmap();
}
@ -2886,6 +2926,11 @@ int dosearchnext(void) {
searchwrap = TRUE;
}
if ((m == searchmap) && (numtextfound == 0) && (!firsttime)) {
/* no text objects exist */
return TRUE;
}
if ((firsttime) && (m == searchmap)) {
i = searchtob+1;
firsttime = FALSE;
@ -2893,10 +2938,6 @@ int dosearchnext(void) {
i = 0;
}
if ((m == searchmap) && (numtextfound == 0) && (!firsttime)) {
/* no text objects exist */
return TRUE;
}
for (; i < map[m].numtext; i++) { /* for each text object */
@ -2927,6 +2968,7 @@ int dosearchnext(void) {
return TRUE;
}
void drawarrowhead(SDL_Surface *screen, double x1, double y1, double x2, double y2, SDL_Color c, int arrowstyle, int arrowpos) {
double angle;
int arrowpointx,arrowpointy;
@ -4211,6 +4253,56 @@ void validatescreenpos(void) {
if (screeny < 0) screeny = 0;
}
void drawsearchflash(void) {
SDL_Surface *temps;
SDL_Rect area;
int txoff,tyoff;
int anchoreditem;
if (!searchflash) {
return;
}
/* highlight the object just found in a search */
if (map[curmap].selecteditem != -1) {
if (map[curmap].selecteditemtype == T_TEXT) {
int th;
/* calculate text's height */
th = TTF_FontHeight(font[map[curmap].textob[map[curmap].selecteditem].h]);
area.w = map[curmap].textob[map[curmap].selecteditem].w;
area.h = th;
anchoreditem = map[curmap].textob[map[curmap].selecteditem].anchor;
if (anchoreditem == -1) {
txoff = 0;
tyoff = 0;
} else {
txoff = map[curmap].obj[anchoreditem].x;
tyoff = map[curmap].obj[anchoreditem].y;
}
area.x = map[curmap].textob[map[curmap].selecteditem].x - screenx + txoff;
area.y = map[curmap].textob[map[curmap].selecteditem].y - screeny + tyoff;
/* restore background */
SDL_BlitSurface(searchbg, NULL, screen, &area);
/* draw hilight */
temps = SDL_CreateRGBSurface(SDL_HWSURFACE,area.w, area.h,
screen->format->BitsPerPixel, screen->format->Rmask,
screen->format->Gmask,screen->format->Bmask,
screen->format->Amask);
SDL_FillRect(temps, 0, SDL_MapRGB(temps->format, 0, 0, 255));
SDL_SetColorKey(temps, SDL_SRCCOLORKEY|SDL_RLEACCEL, SDL_MapRGB(temps->format, 255, 255, 255));
SDL_SetAlpha(temps, SDL_SRCALPHA, searchflash);
SDL_BlitSurface(temps, NULL, screen, &area);
SDL_FreeSurface(temps);
SDL_UpdateRect(screen, area.x, area.y, area.w, area.h);
}
}
}
void drawstatusbar(void) {
Uint32 col;
SDL_Rect area;
@ -7533,9 +7625,56 @@ void setinfo (int infonum) {
oldinfoticks = SDL_GetTicks();
}
void setsearchflash (int num) {
searchflash = num;
oldsearchticks = SDL_GetTicks();
/* copy background */
if (searchbg != NULL) {
SDL_FreeSurface(searchbg);
searchbg = NULL;
}
if (map[curmap].selecteditem != -1) {
if (map[curmap].selecteditemtype == T_TEXT) {
int th;
SDL_Rect area;
int txoff,tyoff;
int anchoreditem;
/* calculate text's height */
th = TTF_FontHeight(font[map[curmap].textob[map[curmap].selecteditem].h]);
area.w = map[curmap].textob[map[curmap].selecteditem].w;
area.h = th;
anchoreditem = map[curmap].textob[map[curmap].selecteditem].anchor;
if (anchoreditem == -1) {
txoff = 0;
tyoff = 0;
} else {
txoff = map[curmap].obj[anchoreditem].x;
tyoff = map[curmap].obj[anchoreditem].y;
}
area.x = map[curmap].textob[map[curmap].selecteditem].x - screenx + txoff;
area.y = map[curmap].textob[map[curmap].selecteditem].y - screeny + tyoff;
searchbg = SDL_CreateRGBSurface(SDL_HWSURFACE,area.w, area.h,
screen->format->BitsPerPixel, screen->format->Rmask,
screen->format->Gmask,screen->format->Bmask,
screen->format->Amask);
SDL_BlitSurface(screen, &area, searchbg, NULL);
}
}
}
void setmod(int tf) {
modified = tf;
needtocalc = TRUE;
/* can't just set needtocalc to TRUE as we can't guarantee when
* the screen will next be redrawn */
calcmapdimensions();
needtocalc = FALSE;
updatewm();
}
@ -7831,8 +7970,8 @@ void startedittext(int o) {
startx += map[curmap].obj[textanchor].x;
starty += map[curmap].obj[textanchor].y;
}
area.x = startx;
area.y = starty;
area.x = startx - screenx;
area.y = starty - screeny;
area.w = map[curmap].textob[o].w;
area.h = TTF_FontHeight(font[map[curmap].textob[o].h]);
bgcol = SDL_MapRGB(screen->format, map[curmap].bgcol.r,map[curmap].bgcol.g,map[curmap].bgcol.b);
@ -8725,12 +8864,16 @@ int updatetextcursor(void) {
/* paste old background */
if (bg != NULL) {
/*
area.x = bgx - screenx;
area.y = bgy - screeny;
*/
area.x = bgx;
area.y = bgy;
area.w = bg->w;
area.h = bg->h;
SDL_BlitSurface(bg,0,screen, &area);
SDL_UpdateRect(screen, bgx, bgy, bg->w, bg->h);
SDL_UpdateRect(screen, area.x,area.y, area.w, area.h);
// free it
SDL_FreeSurface(bg);
bg = NULL;

View File

@ -210,6 +210,7 @@ void drawmap(void);
void drawmapbox(void);
void drawobox(void);
void drawscreen(void);
void drawsearchflash(void);
void drawstatusbar(void);
void drawtext(SDL_Surface *dest, text_t *t, int adjust);
void drawtextat(SDL_Surface *dest, int x, int y, char *text, int size, SDL_Color c);
@ -276,6 +277,7 @@ void initvars(void);
void raiseselected(int amt);
void seterror(int errnum);
void setinfo(int infonum);
void setsearchflash(int num);
void setmod(int tf);
int savemap(void);
void scrollmaplist(int amt);