diff --git a/CHANGELOG b/CHANGELOG index 1f60641..a6b9e6b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,14 @@ Ideas for future versions: Solaris (and possibly other platforms) - Perhaps change to SVG for objects +Version 1.8a: +- Netmapr window can now be re-sized + +Version 1.8: +- Fixed many crashes +- Maplist is now scrollable + + Version 1.7h: - Fixed crash when moving link points diff --git a/constants.h b/constants.h index 8f2e60d..266b991 100644 --- a/constants.h +++ b/constants.h @@ -1,4 +1,4 @@ -#define VERSION "1.8" +#define VERSION "1.8a" /* variable sizes */ #define SMALLBUFLEN 64 /* small text buffer */ @@ -27,7 +27,18 @@ #define DEFTEXTW 8 /* default text width (in pixels) for new text items */ #define DEFTEXTH 10 /* default text height (in POINTS) for new text items */ +#define STATUSH (DEFTEXTH + 4) + +#define SBSIZE 15 + +#define DEFSCREENW 900 +#define DEFSCREENH 600 + + /* maximum/minimum values */ +#define MINSCREENX 100 +#define MINSCREENY 100 + #define MAXBUTTONS 18 /* maximum number of toolbox buttons from buttons.dat */ #define MAXOBJTYPES 50 /* maximum amount of different types from objects.dat */ @@ -116,6 +127,8 @@ #define S_CHANGEOBJECT (24) #define S_DRAWFLOW (25) #define S_SEARCH (26) +#define S_XSCROLL (27) +#define S_YSCROLL (28) /* toolbox buttons */ #define TB_POINTER (0) diff --git a/netmapr.c b/netmapr.c index 05f1336..63b471b 100644 --- a/netmapr.c +++ b/netmapr.c @@ -32,6 +32,7 @@ SDL_Color black = { 0, 0, 0, USECOLOUR}; SDL_Color red = { 255, 0, 0, USECOLOUR}; SDL_Color green = { 0, 255, 0, USECOLOUR}; SDL_Color blue = { 0, 0, 255, USECOLOUR}; +SDL_Color blue2 = { 0, 0, 70, USECOLOUR}; SDL_Color yellow = { 255, 255, 0, USECOLOUR}; SDL_Color cyan = { 0, 255, 255, USECOLOUR}; SDL_Color purple = { 255, 0, 255, USECOLOUR}; @@ -66,7 +67,9 @@ int linemask[MAXLINESTYLE][LINESTYLESIZE]; xy_t fillstack[MAXFILLSTACK]; int fillstackptr = 0; - +/* screen "viewpane" position */ +int screenx = 0; +int screeny = 0; int thingdrawn[MAXOBJECTS + MAXLINKS]; @@ -78,6 +81,7 @@ Uint8 defarrow = 0; int modified = FALSE; int readonly = FALSE; +int needtocalc = FALSE; int maplistpos = 0; /* scroll position in map list */ @@ -161,6 +165,7 @@ int main (int argc, char **argv) { Uint32 ticks; int doubleclick = FALSE; int n,found,delmap; + int mx,my,mb; if (argc >= 2) { int i; @@ -264,11 +269,48 @@ int main (int argc, char **argv) { while (isevent) { switch (event.type) { + case SDL_VIDEORESIZE: + /* set screen size */ + screen = SDL_SetVideoMode(event.resize.w > MINSCREENX ? event.resize.w : MINSCREENX, + event.resize.h > MINSCREENY ? event.resize.h : MINSCREENY, + map[curmap].bpp, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_RESIZABLE); + SDL_FreeSurface(buffer); + buffer = SDL_CreateRGBSurface(SDL_HWSURFACE,screen->w - SIDEBARW,screen->h - STATUSH, + screen->format->BitsPerPixel, screen->format->Rmask, + screen->format->Gmask,screen->format->Bmask, + screen->format->Amask); + calcmapdimensions(); + drawscreen(); + break; case SDL_MOUSEBUTTONDOWN: - if (isonmap(event.button.x, event.button.y)) { + 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) + - ((screen->w - SIDEBARW)/2); + + validatescreenpos(); + drawxscrollbar(); + changestate(S_XSCROLL); + } else if (isonyscrollbar(event.button.x, event.button.y)) { + /* middle of the screen goes to where we clicked */ + screeny = (((double)event.button.y / (double)(screen->h - STATUSH - SBSIZE)) * map[curmap].height) + - ((screen->h - STATUSH - SBSIZE)/2); + + validatescreenpos(); + drawyscrollbar(); + changestate(S_YSCROLL); + } else if (isonmap(event.button.x, event.button.y)) { + event.button.x += screenx; + event.button.y += screeny; if (state == S_NONE) { mod = SDL_GetModState(); - if ((event.button.button == SDL_BUTTON_LEFT) && ((mod & KMOD_CTRL) == 0)) { + if ((event.button.button == SDL_BUTTON_LEFT) && ((mod & KMOD_SHIFT))) { + /* centre map on clicked position */ + screenx = event.button.x - ((screen->w - SIDEBARW)/2); + screeny = event.button.y - ((screen->h - STATUSH)/2); + validatescreenpos(); + drawmap(); + } else if ((event.button.button == SDL_BUTTON_LEFT) && ((mod & KMOD_CTRL) == 0)) { /* is there a selected link? if so check for it first */ if ((map[curmap].selecteditemtype == T_LINK) && (map[curmap].selecteditem != -1) && (isonlinkdst(map[curmap].selecteditem, event.button.x,event.button.y)) ) { @@ -399,7 +441,15 @@ int main (int argc, char **argv) { doubleclick = FALSE; } oldticks = ticks; + + if ((state == S_XSCROLL) || (state == S_YSCROLL)) { + changestate(S_NONE); + drawmap(); + } + if (isonmap(event.button.x, event.button.y)) { + event.button.x += screenx; + event.button.y += screeny; if (state != S_REALLYQUIT) { //if ((doubleclick) && (objat(event.button.x, event.button.y) == map[curmap].selecteditem)) { if (doubleclick) { @@ -623,7 +673,7 @@ int main (int argc, char **argv) { } } else if (state == S_LINKMOVING) { /* has mouse actually moved? */ - if ((event.button.x == startx) && (event.button.y == starty)) { + if ((event.button.x - screenx == startx) && (event.button.y - screeny == starty)) { /* select the link */ map[curmap].selecteditem = map[curmap].curlink; map[curmap].selecteditemtype = T_LINK; @@ -1180,7 +1230,7 @@ int main (int argc, char **argv) { ((event.button.button == SDL_BUTTON_LEFT) && (mod & KMOD_CTRL))) { if (state == S_DRAWLINK) { // finish drawing link - o = objat(event.button.x, event.button.y); + o = objat(event.button.x + screenx, event.button.y + screeny); if ((o != -1) && (o != startobj)) { endobj = o; endlink(event.button.x,event.button.y); @@ -1194,9 +1244,9 @@ int main (int argc, char **argv) { changestate(S_NONE); } else if (state == S_NONE) { /* are we on a link? if so, add a point to it */ - o = linkat(event.button.x, event.button.y); + o = linkat(event.button.x + screenx, event.button.y + screeny); if (o != -1) { - addlinkpoint(o, event.button.x, event.button.y); + addlinkpoint(o, event.button.x+screenx, event.button.y+screeny); /* select the link */ map[curmap].selecteditemtype = T_LINK; map[curmap].selecteditem = o; @@ -1514,6 +1564,28 @@ int main (int argc, char **argv) { break; } + /* scrollbar drags */ + mb = SDL_GetMouseState(&mx,&my); + //if (isonxscrollbar(mx,my)) { + if (state == S_XSCROLL) { + if (mb & SDL_BUTTON(1)) { /* if lmb is depressed */ + screenx = (((double)event.button.x / (double)(screen->w - SIDEBARW)) * map[curmap].width) + - ((screen->w - SIDEBARW)/2); + + validatescreenpos(); + drawxscrollbar(); + } + } + //if (isonyscrollbar(mx,my)) { + if (state == S_YSCROLL) { + if (mb & SDL_BUTTON(1)) { /* if lmb is depressed */ + screeny = (((double)event.button.y / (double)(screen->h - STATUSH - SBSIZE)) * map[curmap].height) + - ((screen->h - STATUSH - SBSIZE)/2); + + validatescreenpos(); + drawyscrollbar(); + } + } break; case SDL_QUIT: if (modified) { @@ -1624,6 +1696,15 @@ int main (int argc, char **argv) { } } } else { + if (c2 == SDLK_F3) { + movescreenx(-100); + if (screenx < 0) screenx = 0; + drawmap(); + } + if (c2 == SDLK_F4) { + movescreenx(100); + drawmap(); + } if (c == 'a') { /* add map[curmap].object */ if (state == S_NONE) { changestate(S_ADDOBJ); @@ -1973,6 +2054,76 @@ int addvector(vectorimg_t *vimg, int type, int x1, int y1, int x2, int y2, SDL_C return FALSE; } +void calcmapdimensions(void) { + int thismaxx,thismaxy; /* used to calculate map size */ + int maxx = -1,maxy = -1; /* used to calculate map size */ + int i; + + /* draw all map[curmap].objects links etc*/ + for (i = 0; i < map[curmap].numthings; i++) { + if (map[curmap].thing[i].type == T_OBJECT) { + /* calculate max map size */ + thismaxx = map[curmap].obj[map[curmap].thing[i].id].x + map[curmap].obj[map[curmap].thing[i].id].w; + thismaxy = map[curmap].obj[map[curmap].thing[i].id].y + map[curmap].obj[map[curmap].thing[i].id].h; + if (thismaxx > maxx) maxx = thismaxx; + if (thismaxy > maxy) maxy = thismaxy; + } else if (map[curmap].thing[i].type == T_LINK) { + int p; + thismaxx = -1; + thismaxy = -1; + for (p = 0; p < map[curmap].olink[map[curmap].thing[i].id].npoints; p++) { + if (map[curmap].olink[map[curmap].thing[i].id].point[p].x > thismaxx) + thismaxx = map[curmap].olink[map[curmap].thing[i].id].point[p].x; + if (map[curmap].olink[map[curmap].thing[i].id].point[p].y > thismaxy) + thismaxy = map[curmap].olink[map[curmap].thing[i].id].point[p].y; + } + /* calculate max map size */ + if (thismaxx > maxx) maxx = thismaxx; + if (thismaxy > maxy) maxy = thismaxy; + } else if (map[curmap].thing[i].type == T_TEXT) { + /* calculate max map size */ + thismaxx = map[curmap].textob[map[curmap].thing[i].id].x + map[curmap].textob[map[curmap].thing[i].id].w; + thismaxy = map[curmap].textob[map[curmap].thing[i].id].y + map[curmap].textob[map[curmap].thing[i].id].h; + if (thismaxx > maxx) maxx = thismaxx; + if (thismaxy > maxy) maxy = thismaxy; + } else { + printf("WARNING: Thing #%d has unknown type %d!\n",i,map[curmap].thing[i].type); + } + } + + /* 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; + + /* determine position of sidebar */ + obox.x = screen->w - SIDEBARW; + obox.y = ((screen->h / 4) * 3) - 10; + obox.width = SIDEBARW; + obox.height = screen->h - obox.y; + obox.bgcol = black; + obox.gridbgcol = grey; + obox.gridcol = grey; + obox.gridsize = 30; + obox.gridrowlen = SIDEBARW / obox.gridsize; + + toolbox.x = screen->w - SIDEBARW; + toolbox.y = 0; + toolbox.width = SIDEBARW; + toolbox.height = screen->h / 3; + toolbox.bgcol = black; + toolbox.gridsize = 30; + toolbox.gridrowlen = SIDEBARW / toolbox.gridsize; + + mapbox.x = screen->w - SIDEBARW; + mapbox.y = toolbox.y+toolbox.height+10; + mapbox.width = SIDEBARW; + mapbox.height = obox.y - mapbox.y - 20; + mapbox.offset = 0; + +} + void changegridsize(void) { if (++gridsizeindex >= gridsizenum) { gridsizeindex = 0; @@ -2140,6 +2291,12 @@ void changestate(int newstate) { case S_LOADING: sprintf(statustext,"Load mode entered.\n"); break; + case S_XSCROLL: + sprintf(statustext,"Scrolling horizontally...\n"); + break; + case S_YSCROLL: + sprintf(statustext,"Scrolling vertically...\n"); + break; } drawstatusbar(); } @@ -2614,7 +2771,7 @@ void adjustendpoint(SDL_Surface *screen, int *adjx, int *adjy, double x1, double the object hasn't been drawn yet */ - drawobject(temps, &map[curmap].obj[o], FALSE); + drawobject(temps, &map[curmap].obj[o], FALSE, TRUE); /* @@ -3264,13 +3421,13 @@ void drawlink(SDL_Surface *dest, link_t *l) { flow = l->col.unused & ISFLOW; - x = map[curmap].obj[l->srcobj].x + l->srcxoff; - y = map[curmap].obj[l->srcobj].y + l->srcyoff; + x = map[curmap].obj[l->srcobj].x + l->srcxoff - screenx; + y = map[curmap].obj[l->srcobj].y + l->srcyoff - screeny; arrow = (l->style & 0x00ff0000) >> 16; for (i = 0; i < l->npoints; i++) { - x2 = l->point[i].x; - y2 = l->point[i].y; + x2 = l->point[i].x - screenx; + y2 = l->point[i].y - screeny; /* if this is the first point and the line is of type "arrowhead at start" then draw an arrow */ @@ -3302,8 +3459,8 @@ void drawlink(SDL_Surface *dest, link_t *l) { } /* draw line to final map[curmap].object */ - x2 = map[curmap].obj[l->dstobj].x + l->dstxoff; - y2 = map[curmap].obj[l->dstobj].y + l->dstyoff; + x2 = map[curmap].obj[l->dstobj].x + l->dstxoff - screenx; + y2 = map[curmap].obj[l->dstobj].y + l->dstyoff - screeny; /* adjust end */ if (l->npoints >= 1) { @@ -3484,7 +3641,7 @@ void drawlinkSVG(link_t *l) { } -void drawobject(SDL_Surface *dest, mapobject_t *o, int doublebuffer) { +void drawobject(SDL_Surface *dest, mapobject_t *o, int doublebuffer, int adjust) { SDL_Surface *temps; SDL_Rect area; Uint32 bgcol; @@ -3529,6 +3686,10 @@ void drawobject(SDL_Surface *dest, mapobject_t *o, int doublebuffer) { if (doublebuffer) { area.x = o->x; area.y = o->y; + if (adjust) { + area.x -= screenx; + area.y -= screeny; + } area.w = o->w; area.h = o->h; if (testing) { @@ -3672,17 +3833,17 @@ void drawmap(void) { SDL_FillRect(buffer, NULL, fillcol); /* always draw grid */ - for (x = 0; x < map[curmap].width; x += (gridsize*2)) { - drawline(buffer,x,0,x,map[curmap].height-1, gridcol, (LS_BIGDASH << 8) | 1); - if ((x+gridsize) < map[curmap].width) { - drawline(buffer,x+gridsize,0,x+gridsize,map[curmap].height-1, gridcol, (LS_DOTTED << 8) | 1); + for (x = 0; x < screen->w - SIDEBARW; x += (gridsize*2)) { + drawline(buffer,x,0,x,(screen->h - STATUSH), gridcol, (LS_BIGDASH << 8) | 1); + if ((x+gridsize) < screen->w - SIDEBARW) { + drawline(buffer,x+gridsize,0,x+gridsize,(screen->h - DEFTEXTH-2), gridcol, (LS_DOTTED << 8) | 1); } } - for (y = 0; y < map[curmap].height; y += (gridsize*2)) { - drawline(buffer,0,y,map[curmap].width-1, y,gridcol, (LS_BIGDASH << 8) | 1); - if ((y+gridsize) < map[curmap].height) { - drawline(buffer,0,y+gridsize,map[curmap].width-1, y+gridsize,gridcol, (LS_DOTTED << 8) | 1); + for (y = 0; y < screen->h - STATUSH; y += (gridsize*2)) { + drawline(buffer,0,y,screen->w - SIDEBARW, y,gridcol, (LS_BIGDASH << 8) | 1); + if ((y+gridsize) < (screen->h - STATUSH)) { + drawline(buffer,0,y+gridsize,screen->w - SIDEBARW, y+gridsize,gridcol, (LS_DOTTED << 8) | 1); } } @@ -3696,7 +3857,7 @@ void drawmap(void) { 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 (!isflow(map[curmap].thing[i].id, T_OBJECT)) { - drawobject(buffer, &map[curmap].obj[map[curmap].thing[i].id], TRUE); + drawobject(buffer, &map[curmap].obj[map[curmap].thing[i].id], TRUE, TRUE); thingdrawn[i] = TRUE; } } else if (map[curmap].thing[i].type == T_LINK) { @@ -3705,10 +3866,11 @@ void drawmap(void) { drawlink(buffer, &map[curmap].olink[map[curmap].thing[i].id]); thingdrawn[i] = TRUE; } + } 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 (!isflow(map[curmap].thing[i].id, T_TEXT)) { - drawtext(buffer, &map[curmap].textob[map[curmap].thing[i].id]); + drawtext(buffer, &map[curmap].textob[map[curmap].thing[i].id], TRUE); thingdrawn[i] = TRUE; } } else { @@ -3717,13 +3879,12 @@ void drawmap(void) { } } - /* show traffic flows (these should be on top of everything else) */ if (showflows) { for (i = 0; i < map[curmap].numthings; i++) { if (map[curmap].thing[i].type == T_OBJECT) { if (isflow(map[curmap].thing[i].id, T_OBJECT)) { - drawobject(buffer, &map[curmap].obj[map[curmap].thing[i].id], TRUE); + drawobject(buffer, &map[curmap].obj[map[curmap].thing[i].id], TRUE, TRUE); if (state == S_DRAWFLOW) drawflowbox(buffer, map[curmap].thing[i].id, T_OBJECT); thingdrawn[i] = TRUE; } @@ -3735,7 +3896,7 @@ void drawmap(void) { } } else if (map[curmap].thing[i].type == T_TEXT) { if (isflow(map[curmap].thing[i].id, T_TEXT)) { - drawtext(buffer, &map[curmap].textob[map[curmap].thing[i].id]); + drawtext(buffer, &map[curmap].textob[map[curmap].thing[i].id], TRUE); if (state == S_DRAWFLOW) drawflowbox(buffer, map[curmap].thing[i].id, T_TEXT); thingdrawn[i] = TRUE; } @@ -3766,16 +3927,20 @@ void drawmap(void) { fillcol = SDL_MapRGB(buffer->format, 0, 0, 0); /* top left */ - area.x = map[curmap].obj[map[curmap].selecteditem].x; area.y = map[curmap].obj[map[curmap].selecteditem].y; + area.x = map[curmap].obj[map[curmap].selecteditem].x - screenx; + area.y = map[curmap].obj[map[curmap].selecteditem].y - screeny; SDL_FillRect(buffer, &area, fillcol); /* top right */ - area.x = map[curmap].obj[map[curmap].selecteditem].x + map[curmap].obj[map[curmap].selecteditem].w - area.w; area.y = map[curmap].obj[map[curmap].selecteditem].y; + area.x = map[curmap].obj[map[curmap].selecteditem].x + map[curmap].obj[map[curmap].selecteditem].w - area.w - screenx; + area.y = map[curmap].obj[map[curmap].selecteditem].y - screeny; SDL_FillRect(buffer, &area, fillcol); /* bottom left */ - area.x = map[curmap].obj[map[curmap].selecteditem].x ; area.y = map[curmap].obj[map[curmap].selecteditem].y + map[curmap].obj[map[curmap].selecteditem].h - area.h; + area.x = map[curmap].obj[map[curmap].selecteditem].x - screenx; + area.y = map[curmap].obj[map[curmap].selecteditem].y + map[curmap].obj[map[curmap].selecteditem].h - area.h - screeny; SDL_FillRect(buffer, &area, fillcol); /* bottom right */ - area.x = map[curmap].obj[map[curmap].selecteditem].x + map[curmap].obj[map[curmap].selecteditem].w - area.w; area.y = map[curmap].obj[map[curmap].selecteditem].y + map[curmap].obj[map[curmap].selecteditem].h - area.h; + area.x = map[curmap].obj[map[curmap].selecteditem].x + map[curmap].obj[map[curmap].selecteditem].w - area.w - screenx; + area.y = map[curmap].obj[map[curmap].selecteditem].y + map[curmap].obj[map[curmap].selecteditem].h - area.h - screeny; SDL_FillRect(buffer, &area, fillcol); /* Also highlight any text anchored to this object */ @@ -3804,16 +3969,20 @@ void drawmap(void) { fillcol = SDL_MapRGB(buffer->format, 0, 255, 0); /* top left */ - area.x = map[curmap].textob[n].x + txoff; area.y = map[curmap].textob[n].y + tyoff; + area.x = map[curmap].textob[n].x + txoff - screenx; + area.y = map[curmap].textob[n].y + tyoff - screeny; SDL_FillRect(buffer, &area, fillcol); /* top right */ - area.x = map[curmap].textob[n].x +txoff + map[curmap].textob[n].w - area.w; area.y = map[curmap].textob[n].y + tyoff; + area.x = map[curmap].textob[n].x +txoff + map[curmap].textob[n].w - area.w - screenx; + area.y = map[curmap].textob[n].y + tyoff - screeny; SDL_FillRect(buffer, &area, fillcol); /* bottom left */ - area.x = map[curmap].textob[n].x +txoff ; area.y = map[curmap].textob[n].y + tyoff + th - area.h; + area.x = map[curmap].textob[n].x +txoff - screenx; + area.y = map[curmap].textob[n].y + tyoff + th - area.h - screeny; SDL_FillRect(buffer, &area, fillcol); /* bottom right */ - area.x = map[curmap].textob[n].x+txoff + map[curmap].textob[n].w - area.w; area.y = map[curmap].textob[n].y +tyoff+ th - area.h; + area.x = map[curmap].textob[n].x+txoff + map[curmap].textob[n].w - area.w - screenx; + area.y = map[curmap].textob[n].y +tyoff+ th - area.h - screeny; SDL_FillRect(buffer, &area, fillcol); } } @@ -3842,16 +4011,20 @@ void drawmap(void) { fillcol = SDL_MapRGB(buffer->format, 0, 0, 0); /* top left */ - area.x = map[curmap].textob[map[curmap].selecteditem].x + txoff; area.y = map[curmap].textob[map[curmap].selecteditem].y + tyoff; + area.x = map[curmap].textob[map[curmap].selecteditem].x + txoff - screenx; + area.y = map[curmap].textob[map[curmap].selecteditem].y + tyoff - screeny; SDL_FillRect(buffer, &area, fillcol); /* top right */ - area.x = map[curmap].textob[map[curmap].selecteditem].x +txoff + map[curmap].textob[map[curmap].selecteditem].w - area.w; area.y = map[curmap].textob[map[curmap].selecteditem].y + tyoff; + area.x = map[curmap].textob[map[curmap].selecteditem].x +txoff + map[curmap].textob[map[curmap].selecteditem].w - area.w - screenx; + area.y = map[curmap].textob[map[curmap].selecteditem].y + tyoff - screeny; SDL_FillRect(buffer, &area, fillcol); /* bottom left */ - area.x = map[curmap].textob[map[curmap].selecteditem].x +txoff ; area.y = map[curmap].textob[map[curmap].selecteditem].y + tyoff + th - area.h; + area.x = map[curmap].textob[map[curmap].selecteditem].x +txoff - screenx; + area.y = map[curmap].textob[map[curmap].selecteditem].y + tyoff + th - area.h - screeny; SDL_FillRect(buffer, &area, fillcol); /* bottom right */ - area.x = map[curmap].textob[map[curmap].selecteditem].x+txoff + map[curmap].textob[map[curmap].selecteditem].w - area.w; area.y = map[curmap].textob[map[curmap].selecteditem].y +tyoff+ th - area.h; + area.x = map[curmap].textob[map[curmap].selecteditem].x+txoff + map[curmap].textob[map[curmap].selecteditem].w - area.w - screenx; + area.y = map[curmap].textob[map[curmap].selecteditem].y +tyoff+ th - area.h - screeny; SDL_FillRect(buffer, &area, fillcol); /* if this text is anchored, highlight the map[curmap].object which it is anchored to */ @@ -3864,16 +4037,20 @@ void drawmap(void) { fillcol = SDL_MapRGB(buffer->format, 0, 255, 0); /* top left */ - area.x = map[curmap].obj[anchoreditem].x; area.y = map[curmap].obj[anchoreditem].y; + area.x = map[curmap].obj[anchoreditem].x - screenx; + area.y = map[curmap].obj[anchoreditem].y - screeny; SDL_FillRect(buffer, &area, fillcol); /* top right */ - area.x = map[curmap].obj[anchoreditem].x + map[curmap].obj[anchoreditem].w - area.w; area.y = map[curmap].obj[anchoreditem].y; + area.x = map[curmap].obj[anchoreditem].x + map[curmap].obj[anchoreditem].w - area.w - screenx; + area.y = map[curmap].obj[anchoreditem].y - screeny; SDL_FillRect(buffer, &area, fillcol); /* bottom left */ - area.x = map[curmap].obj[anchoreditem].x ; area.y = map[curmap].obj[anchoreditem].y + map[curmap].obj[anchoreditem].h - area.h; + area.x = map[curmap].obj[anchoreditem].x - screenx; + area.y = map[curmap].obj[anchoreditem].y + map[curmap].obj[anchoreditem].h - area.h - screeny; SDL_FillRect(buffer, &area, fillcol); /* bottom right */ - area.x = map[curmap].obj[anchoreditem].x + map[curmap].obj[anchoreditem].w - area.w; area.y = map[curmap].obj[anchoreditem].y + map[curmap].obj[anchoreditem].h - area.h; + area.x = map[curmap].obj[anchoreditem].x + map[curmap].obj[anchoreditem].w - area.w - screenx; + area.y = map[curmap].obj[anchoreditem].y + map[curmap].obj[anchoreditem].h - area.h - screeny; SDL_FillRect(buffer, &area, fillcol); } @@ -3885,18 +4062,18 @@ void drawmap(void) { fillcol = SDL_MapRGB(buffer->format, 0, 0, 0); /* start of line */ - area.x = map[curmap].obj[map[curmap].olink[map[curmap].selecteditem].srcobj].x + map[curmap].olink[map[curmap].selecteditem].srcxoff - (LINESELHANDLESIZE/2); - area.y = map[curmap].obj[map[curmap].olink[map[curmap].selecteditem].srcobj].y + map[curmap].olink[map[curmap].selecteditem].srcyoff - (LINESELHANDLESIZE/2); + area.x = map[curmap].obj[map[curmap].olink[map[curmap].selecteditem].srcobj].x + map[curmap].olink[map[curmap].selecteditem].srcxoff - (LINESELHANDLESIZE/2) - screenx; + area.y = map[curmap].obj[map[curmap].olink[map[curmap].selecteditem].srcobj].y + map[curmap].olink[map[curmap].selecteditem].srcyoff - (LINESELHANDLESIZE/2) - screeny; SDL_FillRect(buffer, &area, fillcol); /* end of line */ - area.x = map[curmap].obj[map[curmap].olink[map[curmap].selecteditem].dstobj].x + map[curmap].olink[map[curmap].selecteditem].dstxoff - (LINESELHANDLESIZE/2); - area.y = map[curmap].obj[map[curmap].olink[map[curmap].selecteditem].dstobj].y + map[curmap].olink[map[curmap].selecteditem].dstyoff - (LINESELHANDLESIZE/2); + area.x = map[curmap].obj[map[curmap].olink[map[curmap].selecteditem].dstobj].x + map[curmap].olink[map[curmap].selecteditem].dstxoff - (LINESELHANDLESIZE/2) - screenx; + area.y = map[curmap].obj[map[curmap].olink[map[curmap].selecteditem].dstobj].y + map[curmap].olink[map[curmap].selecteditem].dstyoff - (LINESELHANDLESIZE/2) - screeny; SDL_FillRect(buffer, &area, fillcol); /* points on the line */ for (i = 0; i < map[curmap].olink[map[curmap].selecteditem].npoints; i++) { - area.x = map[curmap].olink[map[curmap].selecteditem].point[i].x - (LINESELHANDLESIZE/2); - area.y = map[curmap].olink[map[curmap].selecteditem].point[i].y - (LINESELHANDLESIZE/2); + area.x = map[curmap].olink[map[curmap].selecteditem].point[i].x - (LINESELHANDLESIZE/2) - screenx; + area.y = map[curmap].olink[map[curmap].selecteditem].point[i].y - (LINESELHANDLESIZE/2) - screeny; SDL_FillRect(buffer, &area, fillcol); } } else if (map[curmap].selecteditemtype == T_LINKPOINT) { @@ -3908,12 +4085,12 @@ void drawmap(void) { fillcol = SDL_MapRGB(buffer->format, 0, 255, 0); /* start of line */ - area.x = map[curmap].obj[map[curmap].olink[map[curmap].selecteditem].srcobj].x + map[curmap].olink[map[curmap].selecteditem].srcxoff - (LINESELHANDLESIZE/2); - area.y = map[curmap].obj[map[curmap].olink[map[curmap].selecteditem].srcobj].y + map[curmap].olink[map[curmap].selecteditem].srcyoff - (LINESELHANDLESIZE/2); + area.x = map[curmap].obj[map[curmap].olink[map[curmap].selecteditem].srcobj].x + map[curmap].olink[map[curmap].selecteditem].srcxoff - (LINESELHANDLESIZE/2) - screenx; + area.y = map[curmap].obj[map[curmap].olink[map[curmap].selecteditem].srcobj].y + map[curmap].olink[map[curmap].selecteditem].srcyoff - (LINESELHANDLESIZE/2) - screeny; SDL_FillRect(buffer, &area, fillcol); /* end of line */ - area.x = map[curmap].obj[map[curmap].olink[map[curmap].selecteditem].dstobj].x + map[curmap].olink[map[curmap].selecteditem].dstxoff - (LINESELHANDLESIZE/2); - area.y = map[curmap].obj[map[curmap].olink[map[curmap].selecteditem].dstobj].y + map[curmap].olink[map[curmap].selecteditem].dstyoff - (LINESELHANDLESIZE/2); + area.x = map[curmap].obj[map[curmap].olink[map[curmap].selecteditem].dstobj].x + map[curmap].olink[map[curmap].selecteditem].dstxoff - (LINESELHANDLESIZE/2) - screenx; + area.y = map[curmap].obj[map[curmap].olink[map[curmap].selecteditem].dstobj].y + map[curmap].olink[map[curmap].selecteditem].dstyoff - (LINESELHANDLESIZE/2) - screeny; SDL_FillRect(buffer, &area, fillcol); /* points on the line */ @@ -3923,8 +4100,8 @@ void drawmap(void) { } else { fillcol = SDL_MapRGB(buffer->format, 0, 255, 0); } - area.x = map[curmap].olink[map[curmap].selecteditem].point[i].x - (LINESELHANDLESIZE/2); - area.y = map[curmap].olink[map[curmap].selecteditem].point[i].y - (LINESELHANDLESIZE/2); + area.x = map[curmap].olink[map[curmap].selecteditem].point[i].x - (LINESELHANDLESIZE/2) - screenx; + area.y = map[curmap].olink[map[curmap].selecteditem].point[i].y - (LINESELHANDLESIZE/2) - screeny; SDL_FillRect(buffer, &area, fillcol); } } @@ -3947,8 +4124,80 @@ void drawmap(void) { if (testing) { printf("FLIP\n"); fflush(stdout); } + + /* draw scrollbars, if required */ + if (map[curmap].width > (screen->w - SIDEBARW)) { + drawxscrollbar(); + } + if (map[curmap].height > (screen->h - STATUSH)) { + drawyscrollbar(); + } + + /* calculate mapdimensions if diagram has been modified */ + if (needtocalc) { + calcmapdimensions(); + needtocalc = FALSE; + } + /* flip */ - SDL_UpdateRect(screen, 0, 0, map[curmap].width, map[curmap].height); + SDL_Flip(screen); + //SDL_UpdateRect(screen, 0, 0, map[curmap].width, map[curmap].height); +} + +void drawxscrollbar(void) { + int barw; + + /* scrollbar outline */ + drawbox(screen, 0, screen->h - STATUSH - SBSIZE, + screen->w - SIDEBARW - SBSIZE, screen->h - STATUSH - 1, blue2 , &blue2); + + /* 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; + + drawbox(screen, screenx, screen->h - STATUSH - SBSIZE+1, + screenx + barw, screen->h - STATUSH - 2, blue , &blue); + + SDL_UpdateRect(screen, 0,screen->h - STATUSH - SBSIZE, screen->w, SBSIZE); +} + +void drawyscrollbar(void) { + int barh; + + /* scrollbar outline */ + drawbox(screen, screen->w - SIDEBARW - SBSIZE, 0, + screen->w - SIDEBARW - 2, screen->h - STATUSH - SBSIZE - 1, blue2, &blue2); + + /* 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; + + drawbox(screen, screen->w - SIDEBARW - SBSIZE+1, screeny, + screen->w - SIDEBARW - 3, screeny + 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); + } + if (screenx < 0) screenx = 0; + + if (screeny + (screen->h - STATUSH) > map[curmap].height) { + screeny = map[curmap].height - (screen->h - STATUSH); + } + if (screeny < 0) screeny = 0; } void drawstatusbar(void) { @@ -3969,9 +4218,9 @@ void drawstatusbar(void) { /*col = SDL_MapRGB(screen->format, map[curmap].bgcol.r, map[curmap].bgcol.g, map[curmap].bgcol.b);*/ col = SDL_MapRGB(screen->format, statusbarcolour.r, statusbarcolour.g, statusbarcolour.b); area.x = 0; - area.y = map[curmap].height; - area.w = map[curmap].width; - area.h = map[curmap].height + DEFTEXTH + 3; + area.y = screen->h - STATUSH; + area.w = screen->w - SIDEBARW; + area.h = DEFTEXTH + 4; SDL_FillRect(screen, &area, col); if ((errorflash) || (infoflash)) { @@ -3980,13 +4229,13 @@ void drawstatusbar(void) { statusbarcolour.b = 255; } - drawline(screen, 0, map[curmap].height, map[curmap].width, map[curmap].height, blue,1); + drawline(screen, 0, screen->h - STATUSH, screen->w - SIDEBARW, screen->h - STATUSH, blue,1); /* strip newlines from text */ if (statustext[strlen(statustext)-1] == '\n') statustext[strlen(statustext)-1] = '\0'; - drawtextat(screen, 2, map[curmap].height+2, statustext, DEFTEXTH, black); + drawtextat(screen, 2, screen->h - DEFTEXTH-2, statustext, DEFTEXTH, black); /* show modified status */ if (modified) { @@ -3994,10 +4243,10 @@ void drawstatusbar(void) { /* calculate width */ TTF_SizeText(font[DEFTEXTH-1], "MOD", &tw,&th); - drawbox(screen, map[curmap].width-33,map[curmap].height+1, - map[curmap].width-30+tw+1,map[curmap].height+2+th,blue, NULL); + drawbox(screen, screen->w - SIDEBARW-33,screen->h - STATUSH+1, + screen->w - SIDEBARW-30+tw+1,screen->h - STATUSH+2+th,blue, NULL); - drawtextat(screen, map[curmap].width-30, map[curmap].height+2, "MOD", DEFTEXTH-1, blue); + drawtextat(screen, screen->w - SIDEBARW-30, screen->h - DEFTEXTH - 2, "MOD", DEFTEXTH-1, blue); } /* show readonly status */ if (readonly) { @@ -4006,10 +4255,9 @@ void drawstatusbar(void) { TTF_SizeText(font[DEFTEXTH-1], "RO", &tw,&th); /* same place as 'mod' box, as in readonly mode map can't be modified */ - drawbox(screen, map[curmap].width-33,map[curmap].height+1, - map[curmap].width-30+tw+1,map[curmap].height+2+th,blue, NULL); - drawtextat(screen, map[curmap].width-30, map[curmap].height+2, "RO", DEFTEXTH-1, blue); - + drawbox(screen, screen->w - SIDEBARW-33,screen->h - STATUSH+1, + screen->w - SIDEBARW-30+tw+1,screen->h - STATUSH+2+th,blue, NULL); + drawtextat(screen, screen->w - SIDEBARW-30, screen->h - DEFTEXTH - 2, "RO", DEFTEXTH-1, blue); } SDL_UpdateRect(screen, area.x, area.y, area.w, area.h); @@ -4276,7 +4524,7 @@ void drawmapbox(void) { break; } - drawtext(screen, &temp); + drawtext(screen, &temp, FALSE); } y += th; @@ -4354,9 +4602,9 @@ void drawobox(void) { for (i = (obox.pos*3); i < numobjtypes; i++) { int n; - if ((x + obox.gridsize) >= (map[curmap].width + SIDEBARW)) { + if ((x + obox.gridsize) >= (screen->w)) { x = obox.x; - if ((y + obox.gridsize) >= (map[curmap].height)) { + if ((y + obox.gridsize) >= (screen->h)) { break; } y += obox.gridsize + 3; @@ -4385,7 +4633,7 @@ void drawobox(void) { temp.fillcol.g = 0; temp.fillcol.b = 0; temp.fillcol.unused = 0; - drawobject(screen, &temp, TRUE); + drawobject(screen, &temp, TRUE, FALSE); /* show keyboard shortcuts */ for (n = 0; n < shortcutnum; n++) { @@ -4443,16 +4691,18 @@ void drawobox(void) { //SDL_UpdateRect(screen, x, y, obox.gridsize+1,obox.gridsize+1); - SDL_UpdateRect(screen,obox.x, obox.y, obox.width-1, obox.height+5); + //SDL_UpdateRect(screen,obox.x, obox.y, obox.width-1, obox.height+5); + SDL_Flip(screen); } void drawscreen(void){ drawmap(); drawtoolbox(); drawobox(); + SDL_Flip(screen); } -void drawtext(SDL_Surface *dest, text_t *t) { +void drawtext(SDL_Surface *dest, text_t *t, int adjust) { int tw,th; int txoff,tyoff; @@ -4483,6 +4733,11 @@ void drawtext(SDL_Surface *dest, text_t *t) { area.w = t->w; area.h = t->h; + if (adjust) { + area.x -= screenx; + area.y -= screeny; + } + SDL_BlitSurface(ts, 0, dest, &area); SDL_FreeSurface(ts); ts = NULL; @@ -4501,19 +4756,19 @@ void drawtextat(SDL_Surface *dest, int x, int y, char *text, int size, SDL_Color if (x >= 0) { temp.x = x; } else { - temp.x = (map[curmap].width / 2) - (tw / 2); + temp.x = (screen->w / 2) - (tw / 2); } if (y >= 0) { temp.y = y; } else { - temp.y = (map[curmap].height / 2) - (th / 2); + temp.y = (screen->h / 2) - (th / 2); } temp.c.r = c.r; temp.c.g = c.g; temp.c.b = c.b; temp.anchor = -1; - drawtext(dest, &temp); + drawtext(dest, &temp, FALSE); } void drawtextSVG(text_t *t) { @@ -4574,7 +4829,7 @@ void drawtoolbox(void) { /* draw each button */ for (i = 0; i < numbuttons; i++) { - if ((x + toolbox.gridsize) >= (map[curmap].width + SIDEBARW)) { + if ((x + toolbox.gridsize) >= (screen->w)) { x = toolbox.x; y += toolbox.gridsize+3; if ((y + toolbox.gridsize) >= (toolbox.height)) { @@ -5495,33 +5750,33 @@ void drawyn(char *prompt) { /* clear map to red */ area.x = 0; area.y = 0; - area.w = map[curmap].width; - area.h = map[curmap].height-1; + area.w = screen->w - 1; + area.h = screen->h - 1; SDL_FillRect(screen, &area, SDL_MapRGB(screen->format, 255, 0, 0)); - drawbox(screen, 0, 200,399,500,blue, NULL); - drawbox(screen, 400, 200,799,500,blue, NULL); + drawbox(screen, 0, 200,(screen->w/2)-1,500,blue, NULL); + drawbox(screen, screen->w/2, 200,screen->w-1,500,blue, NULL); drawtextat(screen, -1,100,prompt, promptsize, blue); /* draw yes & no */ TTF_SizeText(font[promptsize], "Yes", &tw,&th); - drawtextat(screen, ((map[curmap].width-SIDEBARW) / 4) - (tw / 2),300,"Yes", yesnosize, blue); + drawtextat(screen, ((screen->w-SIDEBARW) / 4) - (tw / 2),300,"Yes", yesnosize, blue); TTF_SizeText(font[promptsize], "No", &tw,&th); - drawtextat(screen, (((map[curmap].width-SIDEBARW) / 4)*3) - (tw / 2),300,"No", yesnosize, blue); + drawtextat(screen, (((screen->w-SIDEBARW) / 4)*3) - (tw / 2),300,"No", yesnosize, blue); SDL_Flip(screen); } int getyn(int x, int y) { - if ((x >= 0) && (x <= 399) && (y >= 200) && (y <= 500)) { - return YES; - } else if ((x >= 400) && (x <= 799) && (y >= 200) && (y <= 500)) { + if (x >= (screen->w - SIDEBARW)/2) { return NO; - } + } else { + return YES; + } return MAYBE; } @@ -6065,7 +6320,8 @@ void pasteline(SDL_Surface *screen, int *lbuf) { } - SDL_UpdateRect(screen, tlx, tly,w,h); + //SDL_UpdateRect(screen, tlx, tly,w,h); + SDL_Flip(screen); } @@ -6094,6 +6350,24 @@ int initgraphics(void) { exit(1); } + /* open window */ + screen = SDL_SetVideoMode(DEFSCREENW, DEFSCREENH, 16, (SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_RESIZABLE)); + + if(!screen) { + printf("SDL_SetVideoMode: %s\n", SDL_GetError()); + return -1; + } + if (screen->flags & SDL_HWSURFACE) { + printf("SWSurface set ok.\n"); fflush(stdout); + } + if (screen->flags & SDL_HWSURFACE) { + printf("HWSurface set ok.\n"); fflush(stdout); + } + if (screen->flags & SDL_DOUBLEBUF) { + printf("Doublebuf set ok.\n"); fflush(stdout); + } + + initvars(); @@ -6238,22 +6512,6 @@ int initgraphics(void) { textmouse = SDL_CreateCursor(data, mask, normalmouse->area.w, normalmouse->area.h, 0, 0); - /* open window */ - screen = SDL_SetVideoMode(map[curmap].width + SIDEBARW, map[curmap].height + DEFTEXTH+4, map[curmap].bpp, SDL_HWSURFACE|SDL_DOUBLEBUF); - if(!screen) { - printf("SDL_SetVideoMode: %s\n", SDL_GetError()); - return -1; - } - if (screen->flags & SDL_HWSURFACE) { - printf("SWSurface set ok.\n"); fflush(stdout); - } - if (screen->flags & SDL_HWSURFACE) { - printf("HWSurface set ok.\n"); fflush(stdout); - } - if (screen->flags & SDL_DOUBLEBUF) { - printf("Doublebuf set ok.\n"); fflush(stdout); - } - updatewm(); /* set up toolbox highlight image */ @@ -6271,10 +6529,10 @@ screen->format->Amask); SDL_SetAlpha(toolhilite, SDL_SRCALPHA, 128); /* initialise buffer */ - buffer = SDL_CreateRGBSurface(SDL_HWSURFACE,map[curmap].width,map[curmap].height, - screen->format->BitsPerPixel, screen->format->Rmask, - screen->format->Gmask,screen->format->Bmask, - screen->format->Amask); + buffer = SDL_CreateRGBSurface(SDL_HWSURFACE,screen->w - SIDEBARW,screen->h - STATUSH, + screen->format->BitsPerPixel, screen->format->Rmask, + screen->format->Gmask,screen->format->Bmask, + screen->format->Amask); if (!buffer) { printf("Cannot create buffer!\n"); @@ -7021,7 +7279,7 @@ int isonlinksrc(int lineid, int x, int y) { } int isonmap(int x, int y) { - if ((x >= 0) && ( y >= 0) && (x <= map[curmap].width) && (y <= map[curmap].height)) { + if ((x >= 0) && ( y >= 0) && (x <= (screen->w - SIDEBARW)) && (y <= (screen->h - STATUSH))) { return TRUE; } return FALSE; @@ -7069,9 +7327,25 @@ int isontoolbox(int x, int y) { return FALSE; } +int isonxscrollbar(int x, int y) { + if ((y >= (screen->h - STATUSH - SBSIZE)) && (y < (screen->h - STATUSH))) { + return TRUE; + } + + return FALSE; +} + +int isonyscrollbar(int x, int y) { + if ((x >= (screen->w - SIDEBARW - SBSIZE)) && (x < (screen->w - SIDEBARW))) { + return TRUE; + } + + return FALSE; +} + void initmap(int mapnum) { - map[mapnum].width = 800; - map[mapnum].height = 600 - DEFTEXTH; + map[mapnum].width = DEFSCREENW - SIDEBARW; + map[mapnum].height = DEFSCREENH - STATUSH; map[mapnum].bpp = 16; map[mapnum].bgcol.r = 255; map[mapnum].bgcol.g = 255; @@ -7144,6 +7418,31 @@ void initvars(void) { curmap = 0; + obox.x = screen->w - SIDEBARW; + obox.y = ((screen->h / 4) * 3) - 10; + obox.width = SIDEBARW; + obox.height = screen->h - obox.y; + obox.bgcol = black; + obox.gridbgcol = grey; + obox.gridcol = grey; + obox.gridsize = 30; + obox.gridrowlen = SIDEBARW / obox.gridsize; + + toolbox.x = screen->w - SIDEBARW; + toolbox.y = 0; + toolbox.width = SIDEBARW; + toolbox.height = screen->h / 3; + toolbox.bgcol = black; + toolbox.gridsize = 30; + toolbox.gridrowlen = SIDEBARW / toolbox.gridsize; + + mapbox.x = screen->w - SIDEBARW; + mapbox.y = toolbox.y+toolbox.height+10; + mapbox.width = SIDEBARW; + mapbox.height = obox.y - mapbox.y - 20; + mapbox.offset = 0; + + /* obox.x = map[curmap].width + 1; obox.y = ((map[curmap].height / 4) * 3) - 10; obox.width = SIDEBARW; @@ -7167,6 +7466,7 @@ void initvars(void) { mapbox.width = SIDEBARW; mapbox.height = obox.y - mapbox.y - 20; mapbox.offset = 0; + */ fgcol = black; @@ -7224,6 +7524,7 @@ void setinfo (int infonum) { void setmod(int tf) { modified = tf; + needtocalc = TRUE; updatewm(); } @@ -7489,7 +7790,7 @@ int showfiledialog(void) { /* blit to screen */ SDL_BlitSurface(buffer, 0, screen, 0); - SDL_UpdateRect(screen, 0, 0, map[curmap].width, map[curmap].height); + SDL_UpdateRect(screen, 0, 0, screen->w - SIDEBARW, screen->h - STATUSH); return FALSE; } @@ -7535,12 +7836,14 @@ int startlink(int x, int y) { int linex1,liney1,linex2,liney2; int len; - xoff = x - map[curmap].obj[map[curmap].curobj].x; - yoff = y - map[curmap].obj[map[curmap].curobj].y; + xoff = (x - screenx) + (map[curmap].obj[map[curmap].curobj].x - screenx); + yoff = (y - screeny) + (map[curmap].obj[map[curmap].curobj].y - screeny); - startx = x; + startx = x ; starty = y; + if (startx < 0) printf("ERRIR!#@\n"); + startobj = map[curmap].curobj; changestate(S_DRAWLINK); @@ -7669,14 +7972,14 @@ int startlinkmove (int x, int y) { int linex2,liney2; int len; - startx = x; - starty = y; + startx = x - screenx; + starty = y - screeny; changestate(S_LINKMOVING); /* copy background */ - linex1 = map[curmap].obj[map[curmap].olink[map[curmap].curlink].srcobj].x + map[curmap].olink[map[curmap].olink[map[curmap].curlink].srcobj].srcxoff; - liney1 = map[curmap].obj[map[curmap].olink[map[curmap].curlink].srcobj].y + map[curmap].olink[map[curmap].olink[map[curmap].curlink].srcobj].srcyoff; - linex2 = map[curmap].obj[map[curmap].olink[map[curmap].curlink].dstobj].x + map[curmap].olink[map[curmap].olink[map[curmap].curlink].dstobj].dstxoff; - liney2 = map[curmap].obj[map[curmap].olink[map[curmap].curlink].dstobj].y + map[curmap].olink[map[curmap].olink[map[curmap].curlink].dstobj].dstyoff; + linex1 = map[curmap].obj[map[curmap].olink[map[curmap].curlink].srcobj].x - screenx + map[curmap].olink[map[curmap].olink[map[curmap].curlink].srcobj].srcxoff; + liney1 = map[curmap].obj[map[curmap].olink[map[curmap].curlink].srcobj].y - screeny + map[curmap].olink[map[curmap].olink[map[curmap].curlink].srcobj].srcyoff; + linex2 = map[curmap].obj[map[curmap].olink[map[curmap].curlink].dstobj].x - screenx + map[curmap].olink[map[curmap].olink[map[curmap].curlink].dstobj].dstxoff; + liney2 = map[curmap].obj[map[curmap].olink[map[curmap].curlink].dstobj].y - screeny + map[curmap].olink[map[curmap].olink[map[curmap].curlink].dstobj].dstyoff; len = linelen(linex1,liney1,linex2,liney2); if (len <= 0) { @@ -7735,7 +8038,7 @@ int startobjmove (int x, int y) { screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask,screen->format->Bmask, screen->format->Amask); - drawobject(shadow, &map[curmap].obj[map[curmap].curobj], FALSE); + drawobject(shadow, &map[curmap].obj[map[curmap].curobj], FALSE, TRUE); /* make it transparent */ SDL_SetAlpha(shadow, SDL_SRCALPHA, 128); @@ -7748,8 +8051,8 @@ int startobjmove (int x, int y) { int startresize (int x, int y) { SDL_Rect area; - startx = x; - starty = y; + startx = x - screenx; + starty = y - screeny; changestate(S_RESIZING); /* copy background */ @@ -7761,8 +8064,8 @@ int startresize (int x, int y) { screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask,screen->format->Bmask, screen->format->Amask); - area.x = map[curmap].obj[map[curmap].curobj].x; - area.y = map[curmap].obj[map[curmap].curobj].y; + area.x = map[curmap].obj[map[curmap].curobj].x - screenx; + area.y = map[curmap].obj[map[curmap].curobj].y - screeny; area.w = map[curmap].obj[map[curmap].curobj].w+2; area.h = map[curmap].obj[map[curmap].curobj].h+2; SDL_BlitSurface(screen,&area,bg,0); @@ -8079,11 +8382,10 @@ int updatelinkshadow(int x, int y) { len = linelen(linex1,liney1,linex2,liney2); linebg = malloc((len + 4) * sizeof(int)); - copyline(screen, linex1,liney1,linex2,liney2, linebg); + copyline(screen, linex1 - screenx,liney1 - screeny,linex2,liney2, linebg); /* draw line */ - drawline(screen,startx,starty,x,y, map[curmap].boxcol,1); - + drawline(screen,linex1 - screenx,liney1 - screeny,linex2,liney2, map[curmap].boxcol,1); if (x < startx) { if (y < starty) { @@ -8111,7 +8413,8 @@ int updatelinkshadow(int x, int y) { } } - SDL_UpdateRect(screen, tlx, tly,w,h); + //SDL_UpdateRect(screen, tlx, tly ,w,h); + SDL_Flip(screen); return 0; } @@ -8209,7 +8512,8 @@ int updatemoveshadow(int x, int y) { /* draw box */ - if ((x > 0) && (y > 0) && (x+map[curmap].obj[map[curmap].curobj].w-1 < map[curmap].width) && (y+map[curmap].obj[map[curmap].curobj].h-1 < map[curmap].height)) { + if ((x > 0) && (y > 0) && (x+map[curmap].obj[map[curmap].curobj].w-1 < screen->w) && + (y+map[curmap].obj[map[curmap].curobj].h-1 < screen->h)) { drawbox(screen, x, y, x+map[curmap].obj[map[curmap].curobj].w-1, y+map[curmap].obj[map[curmap].curobj].h-1, @@ -8250,13 +8554,15 @@ int updateresizeshadow(int x, int y) { if ((map[curmap].obj[map[curmap].curobj].h + ydiff) < MINOBJHEIGHT) ydiff = MINOBJHEIGHT - map[curmap].obj[map[curmap].curobj].h ; /* check for edges of screen */ - if ((map[curmap].obj[map[curmap].curobj].x + map[curmap].obj[map[curmap].curobj].w + xdiff) >= map[curmap].width) { + /* + if ((map[curmap].obj[map[curmap].curobj].x + map[curmap].obj[map[curmap].curobj].w + xdiff) >= screen->w) { xdiff = 0; } - if ((map[curmap].obj[map[curmap].curobj].y + map[curmap].obj[map[curmap].curobj].h + ydiff) >= map[curmap].height) { + if ((map[curmap].obj[map[curmap].curobj].y + map[curmap].obj[map[curmap].curobj].h + ydiff) >= screen->h) { ydiff = 0; //ydiff = (map[curmap].height - map[curmap].obj[map[curmap].curobj].h); } + */ /* replace old bg */ @@ -8273,8 +8579,8 @@ int updateresizeshadow(int x, int y) { SDL_BlitSurface(bg, &sarea, screen, &area); SDL_UpdateRect(screen, area.x, area.y, area.w, area.h); /* copy current bg */ - area.x = map[curmap].obj[map[curmap].curobj].x; - area.y = map[curmap].obj[map[curmap].curobj].y; + area.x = map[curmap].obj[map[curmap].curobj].x - screenx; + area.y = map[curmap].obj[map[curmap].curobj].y - screeny; area.w = map[curmap].obj[map[curmap].curobj].w + xdiff + 2; area.h = map[curmap].obj[map[curmap].curobj].h + ydiff + 2; if (area.w < MINOBJWIDTH) area.w = MINOBJWIDTH; @@ -8287,10 +8593,10 @@ int updateresizeshadow(int x, int y) { /* draw box */ - drawbox(screen, map[curmap].obj[map[curmap].curobj].x, - map[curmap].obj[map[curmap].curobj].y, - map[curmap].obj[map[curmap].curobj].x+map[curmap].obj[map[curmap].curobj].w + xdiff, - map[curmap].obj[map[curmap].curobj].y+map[curmap].obj[map[curmap].curobj].h + ydiff, + drawbox(screen, map[curmap].obj[map[curmap].curobj].x - screenx, + map[curmap].obj[map[curmap].curobj].y - screeny, + map[curmap].obj[map[curmap].curobj].x - screenx+map[curmap].obj[map[curmap].curobj].w + xdiff, + map[curmap].obj[map[curmap].curobj].y - screeny+map[curmap].obj[map[curmap].curobj].h + ydiff, map[curmap].boxcol, NULL); @@ -8360,8 +8666,8 @@ int updateresizetextshadow(int x, int y) { SDL_BlitSurface(bg, &sarea, screen, &area); SDL_UpdateRect(screen, area.x, area.y, area.w, area.h); /* copy current bg */ - area.x = map[curmap].textob[ct].x + txoff; - area.y = map[curmap].textob[ct].y + tyoff; + area.x = map[curmap].textob[ct].x + txoff - screenx; + area.y = map[curmap].textob[ct].y + tyoff - screeny; area.w = tw+2; area.h = th+4; @@ -8379,10 +8685,10 @@ int updateresizetextshadow(int x, int y) { /* draw box */ - x1 = map[curmap].textob[ct].x + txoff; - y1 = map[curmap].textob[ct].y + tyoff; - x2 = map[curmap].textob[ct].x + txoff + tw; - y2 = map[curmap].textob[ct].y + tyoff + th; + x1 = map[curmap].textob[ct].x + txoff - screenx; + y1 = map[curmap].textob[ct].y + tyoff - screeny; + x2 = map[curmap].textob[ct].x + txoff + tw - screenx; + y2 = map[curmap].textob[ct].y + tyoff + th - screeny; drawbox(screen, x1, y1, x2, y2, map[curmap].boxcol, NULL); @@ -8408,8 +8714,8 @@ int updatetextcursor(void) { /* paste old background */ if (bg != NULL) { - area.x = bgx; - area.y = bgy; + area.x = bgx - screenx; + area.y = bgy - screeny; area.w = bg->w; area.h = bg->h; SDL_BlitSurface(bg,0,screen, &area); @@ -8419,8 +8725,8 @@ int updatetextcursor(void) { bg = NULL; } /* copy new background */ - sarea.x = startx; - sarea.y = starty; + sarea.x = startx - screenx; + sarea.y = starty - screeny; /* calculate text width */ TTF_SizeText(font[updateheight], text, &tw, &th); sarea.w = tw + CURSORWIDTH + 3; @@ -8440,14 +8746,14 @@ int updatetextcursor(void) { bgy = sarea.y; /* draw text */ - drawtextat(screen, startx, starty, text, updateheight, fgcol); + drawtextat(screen, startx - screenx, starty - screeny, text, updateheight, fgcol); /* draw cursor (a solid block) */ for (y = starty ; y < (starty + th); y++ ) { - drawline(screen, startx + tw+1, y, startx + tw + CURSORWIDTH,y,ccol,1); + drawline(screen, startx + tw+1 - screenx, y - screeny, startx + tw + CURSORWIDTH - screenx,y - screeny,ccol,1); } - SDL_UpdateRect(screen, startx, starty, tw + CURSORWIDTH + 3 , th); + SDL_UpdateRect(screen, startx - screenx, starty - screeny, tw + CURSORWIDTH + 3 , th); return FALSE; @@ -8726,12 +9032,13 @@ int endobjmove(int x, int y) { shadow = NULL; /* check position */ - if ((map[curmap].obj[map[curmap].curobj].x + x - startx) >= (map[curmap].width - map[curmap].obj[map[curmap].curobj].w)) { + /*if ((map[curmap].obj[map[curmap].curobj].x + x - startx) >= (map[curmap].width - map[curmap].obj[map[curmap].curobj].w)) { return -1; } if ((map[curmap].obj[map[curmap].curobj].y + y - starty) >= (map[curmap].height - map[curmap].obj[map[curmap].curobj].h)) { return -1; } + */ if (map[curmap].obj[map[curmap].curobj].y + y - starty <= 0) { return -1; } diff --git a/netmapr.h b/netmapr.h index cac2d8d..6d8f5fb 100644 --- a/netmapr.h +++ b/netmapr.h @@ -181,6 +181,7 @@ void changestate(int newstate); void cleanup(void); void copy(void); int createobject(int type, int x, int y); +void calcmapdimensions(void); void copyline(SDL_Surface *screen,int x1, int y1, int x2, int y2, int *lbuf); void deletething(int id, int type); void deletelink(int linkid); @@ -202,7 +203,7 @@ void drawline(SDL_Surface *screen, int x1, int y1, int x2, int y2, SDL_Color c, void drawlinebehind(SDL_Surface *screen, int x1, int y1, int x2, int y2, SDL_Color c); void drawlink(SDL_Surface *dest, link_t *l); void drawlinkSVG(link_t *l); -void drawobject(SDL_Surface *dest, mapobject_t *o, int doublebuffer); +void drawobject(SDL_Surface *dest, mapobject_t *o, int doublebuffer, int adjust); void drawobjectSVG(SDL_Surface *dest, mapobject_t *o, int doublebuffer); void drawpixel(SDL_Surface *screen, int x, int y, SDL_Color c); void drawmap(void); @@ -210,7 +211,7 @@ void drawmapbox(void); void drawobox(void); void drawscreen(void); void drawstatusbar(void); -void drawtext(SDL_Surface *dest, text_t *t); +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); void drawtextSVG(text_t *t); void drawtoolbox(void); @@ -218,6 +219,8 @@ void drawtoolboxselector(int buttonid, int altcolour); void drawvector(SDL_Surface *dest, vectorimg_t *vimg, int x, int y, int w, int h,SDL_Color *overridefg, SDL_Color *overridebg ); void drawvectorSVG(vectorimg_t *vimg, int x, int y, int w, int h, SDL_Color *overridefg, SDL_Color *overridebg); int drawSVG(char *svgfilename); +void drawxscrollbar(void); +void drawyscrollbar(void); void drillto(int mapnum); int endobjmove(int x, int y); int endresize(int x, int y); @@ -267,7 +270,11 @@ int isonmapbox (int x, int y); int isonmapboxchildren (int x, int y); int isonmapname (int x, int y); 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); @@ -300,3 +307,4 @@ int updateresizetextshadow(int x, int y); int updatetextcursor(void); int updatetextshadow(int x, int y); void updatewm(void); +void validatescreenpos(void);