2005-10-25 16:35:55 +10:00
# include <stdio.h>
# include <stdarg.h>
# include <stdlib.h>
# include <string.h>
# include <time.h>
# include <sys/time.h>
# include <sys/types.h>
# include <unistd.h>
2005-10-30 19:45:37 +11:00
# include <math.h>
2005-10-25 16:35:55 +10:00
# include <SDL/SDL.h>
2005-10-27 14:46:38 +10:00
# include <SDL/SDL_ttf.h>
2005-10-25 16:35:55 +10:00
# include <SDL/SDL_keysym.h>
# include "netmapr.h"
# include "constants.h"
SDL_Surface * screen , * buffer ;
SDL_Surface * emptyimg ;
2005-10-28 16:05:57 +10:00
SDL_Surface * icon ;
2005-10-25 16:35:55 +10:00
SDL_Event event ;
2005-10-27 14:46:38 +10:00
TTF_Font * font [ MAXLETTERHEIGHT ] ;
2005-10-25 16:35:55 +10:00
SDL_Color white = { 255 , 255 , 255 , 0 } ;
SDL_Color black = { 0 , 0 , 0 , 0 } ;
SDL_Color red = { 255 , 0 , 0 , 0 } ;
SDL_Color green = { 0 , 255 , 0 , 0 } ;
SDL_Color blue = { 0 , 0 , 255 , 0 } ;
SDL_Color yellow = { 255 , 255 , 0 , 0 } ;
SDL_Color cyan = { 0 , 255 , 255 , 0 } ;
SDL_Color purple = { 255 , 0 , 255 , 0 } ;
SDL_Color grey = { 90 , 90 , 90 , 0 } ;
SDL_Color grey2 = { 70 , 70 , 70 , 0 } ;
SDL_Color grey3 = { 50 , 50 , 50 , 0 } ;
SDL_Color grey4 = { 30 , 30 , 30 , 0 } ;
SDL_Cursor * normalmouse ;
SDL_Cursor * objmouse ;
SDL_Cursor * textmouse ;
2005-10-30 19:45:37 +11:00
int linemask [ MAXLINESTYLE ] [ LINESTYLESIZE ] ;
2005-10-25 16:35:55 +10:00
xy_t fillstack [ MAXFILLSTACK ] ;
int fillstackptr = 0 ;
SDL_Color fgcol ;
SDL_Color objfillcol ;
2005-10-30 19:45:37 +11:00
Uint8 defthickness = 1 ;
Uint8 defstyle = LS_SOLID ;
Uint8 defarrow = 0 ;
2005-10-25 16:35:55 +10:00
int modified = FALSE ;
2005-10-30 00:23:10 +10:00
int readonly = FALSE ;
2005-11-05 14:22:50 +11:00
int copyfrom = - 1 ;
int copymap = - 1 ;
int copytype = T_MAP ;
2005-10-25 16:35:55 +10:00
int numobjtypes = 0 ;
int numletters = 0 ;
int numbuttons = 0 ;
int nummaps = 1 ;
int history [ MAXHISTORY ] ;
int numhistory = 0 ;
int children [ MAXCHILDREN ] ;
int numchildren = 0 ;
char currentfilename [ BUFLEN ] ;
int state = S_NONE ;
SDL_Surface * bg ; /* background for temp images*/
int * linebg ; /* background for temp lines */
int bgx , bgy ;
int bgw , bgh ;
int xoff , yoff ;
SDL_Rect temparea ;
char statustext [ BUFLEN ] ;
2005-11-05 14:22:50 +11:00
char oldstatustext [ BUFLEN ] ;
int rollover = FALSE ;
int oldmousepos = - 1 ;
int mousepos = 0 ;
int oldselection = - 1 ;
int dontpaste = FALSE ;
SDL_Surface * toolbg ;
SDL_Surface * toolhilite ;
2005-10-25 16:35:55 +10:00
int curmap = 0 ;
int startx , starty ;
int textanchor ;
char text [ BUFLEN ] ;
int startobj , endobj ;
2005-10-29 16:37:41 +10:00
int updateheight ;
2005-10-25 16:35:55 +10:00
2005-10-25 16:45:19 +10:00
char progdir [ BUFLEN ] ;
2005-10-25 16:35:55 +10:00
int shift ;
int main ( int argc , char * * argv ) {
int done ;
int c ;
int mod ;
2005-10-30 22:23:14 +11:00
int tmod ;
2005-10-25 16:35:55 +10:00
int o ;
Uint32 oldticks = 0 ;
Uint32 ticks ;
int doubleclick = FALSE ;
int autoload = FALSE ;
2005-10-30 22:23:14 +11:00
int n , found , delmap ;
2005-10-25 16:35:55 +10:00
if ( argc = = 2 ) {
strcpy ( text , argv [ 1 ] ) ;
autoload = TRUE ;
}
2005-10-25 16:45:19 +10:00
if ( getenv ( " NETMAPRDIR " ) ! = NULL ) {
strncpy ( progdir , getenv ( " NETMAPRDIR " ) , BUFLEN ) ;
} else {
strcpy ( progdir , " /usr/local/share/netmapr " ) ;
}
2005-10-30 00:23:10 +10:00
if ( strstr ( argv [ 0 ] , " view " ) ) {
readonly = TRUE ;
}
if ( readonly ) {
printf ( " Starting netmapr viewer v%s... \n " , VERSION ) ;
} else {
printf ( " Starting netmapr v%s... \n " , VERSION ) ;
}
2005-10-27 14:46:38 +10:00
2005-10-25 16:35:55 +10:00
if ( initgraphics ( ) ) {
printf ( " Error initialising graphics. \n " ) ;
exit ( 1 ) ;
}
atexit ( cleanup ) ;
2005-11-05 14:22:50 +11:00
strcpy ( oldstatustext , " " ) ;
2005-10-25 16:35:55 +10:00
if ( autoload ) {
loadmap ( ) ;
strcpy ( text , " " ) ;
}
drawscreen ( ) ;
/* main loop */
done = 0 ;
while ( ! done ) {
/* check for input */
while ( SDL_PollEvent ( & event ) ) {
switch ( event . type ) {
case SDL_MOUSEBUTTONDOWN :
if ( isonmap ( event . button . x , event . button . y ) ) {
if ( state = = S_NONE ) {
mod = SDL_GetModState ( ) ;
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 ) ) ) {
map [ curmap ] . curlink = map [ curmap ] . selecteditem ;
startlinkdstmove ( event . button . x , event . button . y ) ;
} else if ( ( map [ curmap ] . selecteditemtype = = T_LINK ) & & ( map [ curmap ] . selecteditem ! = - 1 ) & &
( isonlinksrc ( map [ curmap ] . selecteditem , event . button . x , event . button . y ) ) ) {
map [ curmap ] . curlink = map [ curmap ] . selecteditem ;
startlinksrcmove ( event . button . x , event . button . y ) ;
} else if ( ( ( map [ curmap ] . selecteditemtype = = T_LINK ) | | ( map [ curmap ] . selecteditemtype = = T_LINKPOINT ) )
& & ( map [ curmap ] . selecteditem ! = - 1 ) & &
( isonlinkpoint ( map [ curmap ] . selecteditem , event . button . x , event . button . y ) ! = - 1 ) ) {
map [ curmap ] . curlink = map [ curmap ] . selecteditem ;
map [ curmap ] . curlinkpoint = isonlinkpoint ( map [ curmap ] . selecteditem , event . button . x , event . button . y ) ;
startlinkpointmove ( event . button . x , event . button . y ) ;
} else {
// move/select object
o = thingat ( event . button . x , event . button . y ) ;
if ( o ! = - 1 ) {
switch ( map [ curmap ] . thing [ o ] . type ) {
case T_OBJECT :
map [ curmap ] . curobj = map [ curmap ] . thing [ o ] . id ;
startobjmove ( event . button . x , event . button . y ) ;
break ;
case T_LINK :
map [ curmap ] . curlink = map [ curmap ] . thing [ o ] . id ;
startlinkmove ( event . button . x , event . button . y ) ;
break ;
case T_TEXT :
map [ curmap ] . curtext = map [ curmap ] . thing [ o ] . id ;
starttextmove ( event . button . x , event . button . y ) ;
break ;
}
}
}
} else if ( ( event . button . button = = SDL_BUTTON_MIDDLE ) | |
( ( event . button . button = = SDL_BUTTON_LEFT ) & & ( mod & KMOD_CTRL ) ) ) {
// if we're over an object, start drawing a new link
o = objat ( event . button . x , event . button . y ) ;
if ( o ! = - 1 ) {
map [ curmap ] . curobj = o ;
startlink ( event . button . x , event . button . y ) ;
}
} else if ( event . button . button = = SDL_BUTTON_RIGHT ) {
2005-10-27 14:46:38 +10:00
// 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 ) ;
}
}
/*
2005-10-25 16:35:55 +10:00
// resize object
o = objat ( event . button . x , event . button . y ) ;
if ( o ! = - 1 ) {
map [ curmap ] . curobj = o ;
startresize ( event . button . x , event . button . y ) ;
} else {
// resize text
o = textat ( event . button . x , event . button . y ) ;
if ( o ! = - 1 ) {
map [ curmap ] . curtext = o ;
startresizetext ( event . button . x , event . button . y ) ;
}
}
2005-10-27 14:46:38 +10:00
*/
2005-10-25 16:35:55 +10:00
} else if ( event . button . button = = SDL_BUTTON_WHEELUP ) {
if ( map [ curmap ] . selecteditem ! = - 1 ) {
/* raise the selected object */
raiseselected ( ) ;
}
} else if ( event . button . button = = SDL_BUTTON_WHEELDOWN ) {
if ( map [ curmap ] . selecteditem ! = - 1 ) {
/* lower the selected object */
lowerselected ( ) ;
}
}
}
}
break ;
case SDL_MOUSEBUTTONUP :
mod = SDL_GetModState ( ) ;
if ( ( event . button . button = = SDL_BUTTON_LEFT ) & & ( ( mod & KMOD_CTRL ) = = 0 ) ) {
ticks = SDL_GetTicks ( ) ;
if ( ( ticks - oldticks ) < = DOUBLECLICKTHRES ) {
doubleclick = TRUE ;
} else {
doubleclick = FALSE ;
}
oldticks = ticks ;
if ( isonmap ( event . button . x , event . button . y ) ) {
if ( state ! = S_REALLYQUIT ) {
2005-10-25 16:45:19 +10:00
//if ((doubleclick) && (objat(event.button.x, event.button.y) == map[curmap].selecteditem)) {
if ( doubleclick ) {
o = objat ( event . button . x , event . button . y ) ;
2005-10-25 16:35:55 +10:00
/* only works on an object */
2005-10-25 16:45:19 +10:00
//if (map[curmap].selecteditem != -1) {
if ( o ! = - 1 ) {
2005-10-25 16:35:55 +10:00
/* can't create a new child via double click */
2005-10-25 16:45:19 +10:00
if ( map [ curmap ] . obj [ o ] . child ! = - 1 ) {
2005-10-25 16:35:55 +10:00
changestate ( S_NONE ) ;
2005-10-25 16:45:19 +10:00
drillto ( map [ curmap ] . obj [ o ] . child ) ;
2005-10-25 16:35:55 +10:00
} else {
sprintf ( statustext , " Cannot drill down - object has no children (use drill tool to create one). " ) ;
map [ curmap ] . selecteditem = - 1 ;
changestate ( S_NONE ) ;
drawmap ( ) ;
}
2005-10-29 16:37:41 +10:00
} else {
o = textat ( event . button . x , event . button . y ) ;
if ( o ! = - 1 ) {
startedittext ( o ) ;
}
2005-10-25 16:35:55 +10:00
}
}
}
if ( state = = S_NONE ) {
if ( map [ curmap ] . selecteditem ! = - 1 ) {
map [ curmap ] . selecteditem = - 1 ;
map [ curmap ] . selecteditemtype = T_EMPTY ;
sprintf ( statustext , " Objects/lines deselected. \n " ) ;
drawmap ( ) ;
}
} else if ( state = = S_REALLYQUIT ) {
o = getyn ( event . button . x , event . button . y ) ;
if ( o = = YES ) {
done = TRUE ;
} else {
changestate ( S_NONE ) ;
drawmap ( ) ;
}
} else if ( state = = S_MATCHSIZE ) {
o = objat ( event . button . x , event . button . y ) ;
if ( o = = - 1 ) {
changestate ( S_NONE ) ;
sprintf ( statustext , " Size match mode aborted. " ) ;
drawstatusbar ( ) ;
} else {
2005-10-25 16:45:19 +10:00
int n ;
2005-10-25 16:35:55 +10:00
/* resize selected item to match one which was clicked */
map [ curmap ] . obj [ map [ curmap ] . selecteditem ] . w = map [ curmap ] . obj [ o ] . w ;
map [ curmap ] . obj [ map [ curmap ] . selecteditem ] . h = map [ curmap ] . obj [ o ] . h ;
2005-10-25 16:45:19 +10:00
/* adjust offsets on all links to/from object */
for ( n = 0 ; n < map [ curmap ] . numlinks ; n + + ) {
if ( map [ curmap ] . olink [ n ] . srcobj = = map [ curmap ] . selecteditem ) {
map [ curmap ] . olink [ n ] . srcxoff = ( map [ curmap ] . obj [ o ] . w / 2 ) ;
map [ curmap ] . olink [ n ] . srcyoff = ( map [ curmap ] . obj [ o ] . h / 2 ) ;
}
if ( map [ curmap ] . olink [ n ] . dstobj = = map [ curmap ] . selecteditem ) {
map [ curmap ] . olink [ n ] . dstxoff = ( map [ curmap ] . obj [ o ] . w / 2 ) ;
map [ curmap ] . olink [ n ] . dstyoff = ( map [ curmap ] . obj [ o ] . h / 2 ) ;
}
}
2005-10-25 16:35:55 +10:00
changestate ( S_NONE ) ;
sprintf ( statustext , " Object #%d resized to match object #%d. " , map [ curmap ] . selecteditem , o ) ;
drawmap ( ) ;
}
} else if ( state = = S_MATCHX ) {
o = objat ( event . button . x , event . button . y ) ;
if ( o = = - 1 ) {
changestate ( S_NONE ) ;
sprintf ( statustext , " X position match mode aborted. " ) ;
drawstatusbar ( ) ;
} else {
/* move selected item to match one which was clicked */
/* match middle of objects! */
map [ curmap ] . obj [ map [ curmap ] . selecteditem ] . x =
( map [ curmap ] . obj [ o ] . x + ( map [ curmap ] . obj [ o ] . w / 2 ) )
-
( map [ curmap ] . obj [ map [ curmap ] . selecteditem ] . w / 2 ) ;
changestate ( S_NONE ) ;
sprintf ( statustext , " Object #%d X relocated to match object #%d. " , map [ curmap ] . selecteditem , o ) ;
drawmap ( ) ;
}
} else if ( state = = S_MATCHY ) {
o = objat ( event . button . x , event . button . y ) ;
if ( o = = - 1 ) {
changestate ( S_NONE ) ;
sprintf ( statustext , " Y position match mode aborted. " ) ;
drawstatusbar ( ) ;
} else {
/* move selected item to match one which was clicked */
map [ curmap ] . obj [ map [ curmap ] . selecteditem ] . y =
( map [ curmap ] . obj [ o ] . y + ( map [ curmap ] . obj [ o ] . h / 2 ) )
-
map [ curmap ] . obj [ map [ curmap ] . selecteditem ] . h / 2 ;
changestate ( S_NONE ) ;
sprintf ( statustext , " Object #%d Y relocated to match object #%d. " , map [ curmap ] . selecteditem , o ) ;
drawmap ( ) ;
}
} else if ( state = = S_OBJMOVING ) {
/* has mouse actually moved? */
if ( ( event . button . x = = startx ) & & ( event . button . y = = starty ) ) {
/* select the object */
map [ curmap ] . selecteditem = map [ curmap ] . curobj ;
map [ curmap ] . selecteditemtype = T_OBJECT ;
changestate ( S_NONE ) ;
sprintf ( statustext , " Object #%d (%s) selected. \n " , map [ curmap ] . selecteditem , objtype [ map [ curmap ] . obj [ map [ curmap ] . selecteditem ] . type ] . name ) ;
drawmap ( ) ;
} else {
// actually move the object
if ( ! endobjmove ( event . button . x , event . button . y ) ) {
sprintf ( statustext , " Object #%d moved to (%d,%d). \n " , map [ curmap ] . curobj , event . button . x , event . button . y ) ;
}
changestate ( S_NONE ) ;
drawmap ( ) ;
}
} else if ( state = = S_LINKMOVING ) {
/* has mouse actually moved? */
if ( ( event . button . x = = startx ) & & ( event . button . y = = starty ) ) {
/* select the link */
map [ curmap ] . selecteditem = map [ curmap ] . curlink ;
map [ curmap ] . selecteditemtype = T_LINK ;
changestate ( S_NONE ) ;
sprintf ( statustext , " Link #%d selected. \n " , map [ curmap ] . selecteditem ) ;
drawmap ( ) ;
} else {
// actually move the link
endlinkmove ( event . button . x , event . button . y ) ;
changestate ( S_NONE ) ;
sprintf ( statustext , " Link #%d moved to (%d,%d). \n " , map [ curmap ] . curlink , event . button . x , event . button . y ) ;
drawmap ( ) ;
}
} else if ( state = = S_LINKPOINTMOVE ) {
/* has mouse actually moved? */
if ( ( event . button . x = = startx ) & & ( event . button . y = = starty ) ) {
/* select the link point */
map [ curmap ] . selecteditem = map [ curmap ] . curlink ;
map [ curmap ] . selecteditemtype = T_LINKPOINT ;
map [ curmap ] . selectedlinkpoint = map [ curmap ] . curlinkpoint ;
changestate ( S_NONE ) ;
sprintf ( statustext , " Link #%d point #%d selected. \n " , map [ curmap ] . selecteditem , map [ curmap ] . selectedlinkpoint ) ;
drawmap ( ) ;
} else {
// actually move the link
endlinkpointmove ( event . button . x , event . button . y ) ;
changestate ( S_NONE ) ;
sprintf ( statustext , " Link #%d moved to (%d,%d). \n " , map [ curmap ] . curlink , event . button . x , event . button . y ) ;
drawmap ( ) ;
}
} else if ( state = = S_TEXTMOVING ) {
/* has mouse actually moved? */
if ( ( event . button . x = = startx ) & & ( event . button . y = = starty ) ) {
/* select the object */
map [ curmap ] . selecteditem = map [ curmap ] . curtext ;
map [ curmap ] . selecteditemtype = T_TEXT ;
changestate ( S_NONE ) ;
sprintf ( statustext , " Text item #%d selected. \n " , map [ curmap ] . selecteditem ) ;
drawmap ( ) ;
} else {
// actually move the text
if ( ! endtextmove ( event . button . x , event . button . y ) ) {
sprintf ( statustext , " Text item #%d moved to (%d,%d). \n " , map [ curmap ] . curtext , event . button . x , event . button . y ) ;
}
changestate ( S_NONE ) ;
drawmap ( ) ;
}
} else if ( state = = S_LINKSRCMOVE ) {
// actually move the link src endpoint
endlinksrcmove ( event . button . x , event . button . y ) ;
changestate ( S_NONE ) ;
drawmap ( ) ;
} else if ( state = = S_LINKDSTMOVE ) {
// actually move the link dst endpoint
endlinkdstmove ( event . button . x , event . button . y ) ;
changestate ( S_NONE ) ;
drawmap ( ) ;
} else if ( state = = S_ADDOBJ ) {
/* create a new object */
createobject ( map [ curmap ] . selectedtype , event . button . x , event . button . y ) ;
drawmap ( ) ;
changestate ( S_NONE ) ;
} else if ( state = = S_ADDTEXT ) {
/* start listening for text input */
startx = event . button . x ;
starty = event . button . y ;
textanchor = objat ( event . button . x , event . button . y ) ;
if ( textanchor ! = - 1 ) {
startx = map [ curmap ] . obj [ textanchor ] . x ;
starty = map [ curmap ] . obj [ textanchor ] . y + map [ curmap ] . obj [ textanchor ] . h + 3 ;
}
2005-10-29 16:37:41 +10:00
updateheight = DEFTEXTH ;
2005-10-25 16:35:55 +10:00
strcpy ( text , " " ) ;
bg = NULL ;
updatetextcursor ( ) ;
changestate ( S_TYPETEXT ) ;
2005-10-28 16:05:57 +10:00
} else if ( state = = S_FILLCOL ) {
getcolor ( screen , event . button . x , event . button . y , & objfillcol ) ;
objfillcol . unused = USECOLOUR ; /* clear NOCOLOUR flag */
if ( map [ curmap ] . selecteditem ! = - 1 ) {
if ( map [ curmap ] . selecteditemtype = = T_OBJECT ) {
map [ curmap ] . obj [ map [ curmap ] . selecteditem ] . fillcol = objfillcol ;
map [ curmap ] . obj [ map [ curmap ] . selecteditem ] . fillcol . unused = USECOLOUR ;
sprintf ( statustext , " Fill colour of object #%d changed to R=%d,G=%d,B=%d " , map [ curmap ] . selecteditem , objfillcol . r , objfillcol . g , objfillcol . b ) ;
} else {
sprintf ( statustext , " Fill colour selected: R=%d,G=%d,B=%d " , objfillcol . r , objfillcol . g , objfillcol . b ) ;
}
} else {
sprintf ( statustext , " Fill colour selected: R=%d,G=%d,B=%d " , objfillcol . r , objfillcol . g , objfillcol . b ) ;
}
changestate ( S_NONE ) ;
drawmap ( ) ;
2005-10-25 16:35:55 +10:00
} else if ( state = = S_FGCOL ) {
getcolor ( screen , event . button . x , event . button . y , & fgcol ) ;
if ( map [ curmap ] . selecteditem ! = - 1 ) {
if ( map [ curmap ] . selecteditemtype = = T_LINK ) {
map [ curmap ] . olink [ map [ curmap ] . selecteditem ] . col = fgcol ;
sprintf ( statustext , " Colour of link #%d changed to R=%d,G=%d,B=%d " , map [ curmap ] . selecteditem , fgcol . r , fgcol . g , fgcol . b ) ;
} else if ( map [ curmap ] . selecteditemtype = = T_TEXT ) {
map [ curmap ] . textob [ map [ curmap ] . selecteditem ] . c = fgcol ;
sprintf ( statustext , " Colour of text item #%d changed to R=%d,G=%d,B=%d " , map [ curmap ] . selecteditem , fgcol . r , fgcol . g , fgcol . b ) ;
} else {
sprintf ( statustext , " Foreground colour selected: R=%d,G=%d,B=%d " , fgcol . r , fgcol . g , fgcol . b ) ;
}
} else {
sprintf ( statustext , " Foreground colour selected: R=%d,G=%d,B=%d " , fgcol . r , fgcol . g , fgcol . b ) ;
}
changestate ( S_NONE ) ;
drawmap ( ) ;
} else if ( state = = S_CREATETELE ) {
int pos ;
if ( event . button . y > = 50 ) {
pos = ( event . button . y - 50 ) / ( DEFTEXTH * 2 ) ;
pos - - ;
if ( pos = = - 1 ) {
map [ curmap ] . obj [ map [ curmap ] . selecteditem ] . child = pos ;
sprintf ( statustext , " Map link removed. " ) ;
changestate ( S_NONE ) ;
drawmap ( ) ;
} else if ( pos < = ( nummaps - 1 ) ) {
if ( ( map [ curmap ] . selecteditem ! = - 1 ) & & ( map [ curmap ] . selecteditemtype = = T_OBJECT ) ) {
if ( pos ! = curmap ) {
map [ curmap ] . obj [ map [ curmap ] . selecteditem ] . child = pos ;
sprintf ( statustext , " Map link created. " ) ;
changestate ( S_NONE ) ;
drawmap ( ) ;
} else {
sprintf ( statustext , " ERROR: Cannot link to current map! " ) ;
drawstatusbar ( ) ;
}
}
} else { /* mouse is not over a map name */
sprintf ( statustext , " Map link creation cancelled. " ) ;
changestate ( S_NONE ) ;
drawmap ( ) ;
}
} else {
sprintf ( statustext , " Map link creation cancelled. " ) ;
changestate ( S_NONE ) ;
drawmap ( ) ;
}
}
} else if ( isonobox ( event . button . x , event . button . y ) ) {
int tempx , tempy ;
tempx = ( event . button . x - obox . x ) / obox . gridsize ;
tempy = ( event . button . y - obox . y ) / obox . gridsize ;
2005-10-25 16:45:19 +10:00
map [ curmap ] . selectedtype = tempy * obox . gridrowlen + tempx + ( obox . pos * 3 ) ;
2005-10-25 16:35:55 +10:00
if ( map [ curmap ] . selectedtype > = numobjtypes ) map [ curmap ] . selectedtype = numobjtypes - 1 ;
sprintf ( statustext , " Object type '%s' selected. \n " , objtype [ map [ curmap ] . selectedtype ] . name ) ;
drawstatusbar ( ) ;
drawobox ( ) ;
} else if ( isongoback ( event . button . x , event . button . y ) ) {
/* go back */
goback ( ) ;
} else if ( isonmapname ( event . button . x , event . button . y ) ) {
/* rename current map */
startx = 1 ;
starty = ( map [ curmap ] . height / 2 ) - 2 ;
bg = NULL ;
strcpy ( text , map [ curmap ] . name ) ;
changestate ( S_MAPNAMING ) ;
drawmap ( ) ;
break ;
} else if ( isonmapboxchildren ( event . button . x , event . button . y ) ) {
int pos ;
2005-10-27 14:46:38 +10:00
int th ;
/* calculate pixel size of mapbox text */
th = TTF_FontHeight ( font [ MAPBOXTEXTHEIGHT ] ) ;
2005-10-25 16:35:55 +10:00
/* change to child */
2005-10-27 14:46:38 +10:00
pos = ( event . button . y - ( mapbox . y + ( th * 2 ) + 1 ) ) / th ;
2005-10-31 13:20:14 +11:00
/* adjust for offset if not a special value */
pos + = mapbox . offset ;
2005-10-25 16:35:55 +10:00
if ( pos > = numchildren ) {
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 ) ) {
int tempx , tempy , selection ;
2005-10-30 19:45:37 +11:00
int boxy ;
2005-10-25 16:35:55 +10:00
tempx = ( event . button . x - toolbox . x ) / ( toolbox . gridsize + 3 ) ;
tempy = ( event . button . y - toolbox . y ) / ( toolbox . gridsize + 3 ) ;
2005-10-28 16:05:57 +10:00
2005-10-30 19:45:37 +11:00
boxy = toolbox . y + ( tempy * ( toolbox . gridsize + 3 ) ) ;
2005-10-28 16:05:57 +10:00
/* are we in a colour selection state? */
if ( state = = S_FGCOL ) {
changestate ( S_NONE ) ;
drawmap ( ) ;
break ;
} else if ( state = = S_FILLCOL ) {
/* set bgcol to 'nothing' */
objfillcol = black ;
objfillcol . unused = NOCOLOUR ;
if ( map [ curmap ] . selecteditem ! = - 1 ) {
if ( map [ curmap ] . selecteditemtype = = T_OBJECT ) {
map [ curmap ] . obj [ map [ curmap ] . selecteditem ] . fillcol = black ;
map [ curmap ] . obj [ map [ curmap ] . selecteditem ] . fillcol . unused = NOCOLOUR ;
sprintf ( statustext , " Fill colour of object #%d removed. " , map [ curmap ] . selecteditem ) ;
} else {
sprintf ( statustext , " Fill colour removed. " ) ;
}
} else {
sprintf ( statustext , " Fill colour removed. " ) ;
}
changestate ( S_NONE ) ;
drawmap ( ) ;
break ;
}
2005-10-25 16:35:55 +10:00
selection = tempy * toolbox . gridrowlen + tempx ;
switch ( selection ) {
case TB_POINTER :
/* special case - update sbar */
sprintf ( statustext , " Selection mode entered. " ) ;
drawstatusbar ( ) ;
changestate ( S_NONE ) ;
map [ curmap ] . curobj = - 1 ;
break ;
case TB_ADDOBJ :
changestate ( S_ADDOBJ ) ;
if ( map [ curmap ] . selectedtype < 0 ) map [ curmap ] . selectedtype = 0 ;
break ;
case TB_ADDTEXT :
changestate ( S_ADDTEXT ) ;
break ;
case TB_NEW :
2005-11-05 14:22:50 +11:00
tmod = SDL_GetModState ( ) ;
if ( ! ( mod & KMOD_SHIFT ) ) {
sprintf ( statustext , " Must hold down SHIFT to start new project (avoids accidental loss of data)! " ) ;
drawstatusbar ( ) ;
break ;
}
2005-10-25 16:35:55 +10:00
initvars ( ) ;
changestate ( S_NONE ) ;
drawmap ( ) ;
break ;
2005-10-30 19:45:37 +11:00
case TB_LINESTYLE :
if ( map [ curmap ] . selecteditemtype = = T_LINK ) {
if ( map [ curmap ] . selecteditem ! = - 1 ) {
int si = map [ curmap ] . selecteditem ;
/* TODO: add arrow */
/* where are we? */
if ( event . button . y < = ( boxy + 9 ) ) {
/* clear thickness */
map [ curmap ] . olink [ si ] . style & = 0xFFFF00 ;
/* set to default */
map [ curmap ] . olink [ si ] . style | = defthickness ;
} else if ( event . button . y < = ( boxy + 19 ) ) {
/* clear style */
map [ curmap ] . olink [ si ] . style & = 0xFF00FF ;
/* set to default */
map [ curmap ] . olink [ si ] . style | = ( defstyle < < 8 ) ;
} else {
/* clear arrow */
map [ curmap ] . olink [ si ] . style & = 0x00FFFF ;
/* set to default */
map [ curmap ] . olink [ si ] . style | = ( defarrow < < 16 ) ;
}
modified = TRUE ;
drawmap ( ) ;
} else {
sprintf ( statustext , " No link selected! " ) ;
}
} else {
sprintf ( statustext , " No link selected! " ) ;
}
drawstatusbar ( ) ;
break ;
2005-10-25 16:35:55 +10:00
case TB_MATCHSIZE :
if ( map [ curmap ] . selecteditem ! = - 1 ) {
if ( map [ curmap ] . selecteditemtype = = T_OBJECT ) {
changestate ( S_MATCHSIZE ) ;
drawmap ( ) ;
}
}
break ;
case TB_MATCHX :
if ( map [ curmap ] . selecteditem ! = - 1 ) {
if ( map [ curmap ] . selecteditemtype = = T_OBJECT ) {
changestate ( S_MATCHX ) ;
drawmap ( ) ;
}
}
break ;
case TB_MATCHY :
if ( map [ curmap ] . selecteditem ! = - 1 ) {
if ( map [ curmap ] . selecteditemtype = = T_OBJECT ) {
changestate ( S_MATCHY ) ;
drawmap ( ) ;
}
}
break ;
case TB_FGCOL :
2005-10-28 16:05:57 +10:00
/* change selected item to match fgcol */
if ( map [ curmap ] . selecteditem ! = - 1 ) {
if ( map [ curmap ] . selecteditemtype = = T_LINK ) {
map [ curmap ] . olink [ map [ curmap ] . selecteditem ] . col = fgcol ;
2005-10-30 19:45:37 +11:00
modified = TRUE ;
2005-10-28 16:05:57 +10:00
sprintf ( statustext , " Colour of link #%d changed to R=%d,G=%d,B=%d " , map [ curmap ] . selecteditem , fgcol . r , fgcol . g , fgcol . b ) ;
} else if ( map [ curmap ] . selecteditemtype = = T_TEXT ) {
map [ curmap ] . textob [ map [ curmap ] . selecteditem ] . c = fgcol ;
2005-10-30 19:45:37 +11:00
modified = TRUE ;
2005-10-28 16:05:57 +10:00
sprintf ( statustext , " Colour of text item #%d changed to R=%d,G=%d,B=%d " , map [ curmap ] . selecteditem , fgcol . r , fgcol . g , fgcol . b ) ;
} else {
sprintf ( statustext , " No object selected! (use RMB to select new foreground colour) " ) ;
}
} else {
sprintf ( statustext , " No object selected! (use RMB to select new foreground colour) " ) ;
}
2005-10-25 16:35:55 +10:00
drawmap ( ) ;
break ;
case TB_FILLCOL :
2005-10-28 16:05:57 +10:00
if ( map [ curmap ] . selecteditem ! = - 1 ) {
if ( map [ curmap ] . selecteditemtype = = T_OBJECT ) {
map [ curmap ] . obj [ map [ curmap ] . selecteditem ] . fillcol = objfillcol ;
map [ curmap ] . obj [ map [ curmap ] . selecteditem ] . fillcol . unused = objfillcol . unused ;
2005-10-30 19:45:37 +11:00
modified = TRUE ;
2005-10-28 16:05:57 +10:00
if ( objfillcol . unused = = USECOLOUR ) {
sprintf ( statustext , " Fill colour of object #%d changed to R=%d,G=%d,B=%d " , map [ curmap ] . selecteditem , objfillcol . r , objfillcol . g , objfillcol . b ) ;
} else {
sprintf ( statustext , " Fill colour of object #%d removed. " , map [ curmap ] . selecteditem ) ;
}
} else {
sprintf ( statustext , " No object selected! (use RMB to select new fill colour) " ) ;
}
} else {
sprintf ( statustext , " No object selected! (use RMB to select new fill colour) " ) ;
}
drawmap ( ) ;
2005-10-25 16:35:55 +10:00
break ;
case TB_DELETEMAP :
2005-11-05 14:22:50 +11:00
/* safety - must hold down SHIFT to delete maps */
2005-10-30 22:23:14 +11:00
tmod = SDL_GetModState ( ) ;
if ( ! ( mod & KMOD_SHIFT ) ) {
2005-11-05 14:22:50 +11:00
sprintf ( statustext , " Must hold down SHIFT to delete maps (avoids accidental loss of data)! " ) ;
2005-10-30 22:23:14 +11:00
drawstatusbar ( ) ;
break ;
}
if ( curmap = = 0 ) {
sprintf ( statustext , " Cannot delete toplevel map! " ) ;
drawstatusbar ( ) ;
break ;
}
delmap = curmap ;
/* any children in curent map? */
found = FALSE ;
for ( n = 0 ; n < map [ delmap ] . numobjects ; n + + ) {
if ( map [ delmap ] . obj [ n ] . child ! = - 1 ) {
found = TRUE ;
break ;
}
}
if ( found ) {
sprintf ( statustext , " Cannot delete a map with children. " ) ;
drawstatusbar ( ) ;
break ;
}
/* shuffle numbers on all other objects */
for ( n = 0 ; n < nummaps ; n + + ) {
int o ;
for ( o = 0 ; o < map [ n ] . numobjects ; o + + ) {
if ( map [ n ] . obj [ o ] . child = = delmap ) {
map [ n ] . obj [ o ] . child = - 1 ;
} else if ( map [ n ] . obj [ o ] . child > delmap ) {
map [ n ] . obj [ o ] . child - - ;
}
}
}
/* move all higher maps down by one */
for ( n = delmap ; n < ( nummaps - 1 ) ; n + + ) {
map [ n ] = map [ n + 1 ] ;
}
nummaps - - ;
/* move far enough back to avoid all occurences of this map */
found = FALSE ;
for ( n = 0 ; n < ( numhistory - 1 ) ; n + + ) {
if ( history [ n + 1 ] = = delmap ) {
if ( history [ n ] > delmap ) {
2005-10-30 22:50:06 +11:00
changemap ( history [ n ] - 1 ) ;
2005-10-30 22:23:14 +11:00
} else {
2005-10-30 22:50:06 +11:00
changemap ( history [ n ] ) ;
2005-10-30 22:23:14 +11:00
}
numhistory = n + 1 ;
found = TRUE ;
break ;
}
}
if ( ! found ) {
2005-10-30 22:50:06 +11:00
goback ( ) ;
sprintf ( statustext , " Deleted map #%d. \n " , delmap ) ;
2005-10-30 22:23:14 +11:00
}
/* fix history array */
for ( n = 0 ; n < numhistory ; n + + ) {
if ( history [ n ] > delmap ) {
history [ n ] - - ;
}
}
drawmap ( ) ;
2005-10-25 16:35:55 +10:00
break ;
case TB_CREATETELE :
if ( ( map [ curmap ] . selecteditemtype = = T_OBJECT ) & & ( map [ curmap ] . selecteditem ! = - 1 ) ) {
changestate ( S_CREATETELE ) ;
drawmap ( ) ;
} else {
sprintf ( statustext , " Cannot create map link - no object selected! " ) ;
drawstatusbar ( ) ;
}
break ;
case TB_DRILLDOWN :
if ( ( map [ curmap ] . selecteditemtype = = T_OBJECT ) & & ( map [ curmap ] . selecteditem ! = - 1 ) ) {
drillto ( map [ curmap ] . obj [ map [ curmap ] . selecteditem ] . child ) ;
} else {
sprintf ( statustext , " Cannot drill down - no object selected! " ) ;
drawstatusbar ( ) ;
}
break ;
case TB_SAVE :
startx = 1 ;
starty = ( map [ curmap ] . height / 2 ) - 2 ;
bg = NULL ;
strcpy ( text , currentfilename ) ;
changestate ( S_SAVING ) ;
drawmap ( ) ;
break ;
case TB_LOAD :
startx = 1 ;
starty = ( map [ curmap ] . height / 2 ) - 2 ;
bg = NULL ;
strcpy ( text , currentfilename ) ;
changestate ( S_LOADING ) ;
drawmap ( ) ;
break ;
}
drawtoolbox ( ) ;
} /* end if is on map */
} else if ( ( event . button . button = = SDL_BUTTON_MIDDLE ) | |
( ( event . button . button = = SDL_BUTTON_LEFT ) & & ( mod & KMOD_CTRL ) ) ) {
if ( state = = S_DRAWLINK ) {
// finish drawing link
o = objat ( event . button . x , event . button . y ) ;
if ( ( o ! = - 1 ) & & ( o ! = startobj ) ) {
endobj = o ;
endlink ( event . button . x , event . button . y ) ;
changestate ( S_NONE ) ;
drawmap ( ) ;
} else {
pasteline ( screen , linebg ) ;
sprintf ( statustext , " Aborting link #%d. \n " , map [ curmap ] . numlinks ) ;
drawstatusbar ( ) ;
}
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 ) ;
if ( o ! = - 1 ) {
addlinkpoint ( o , event . button . x , event . button . y ) ;
/* select the link */
map [ curmap ] . selecteditemtype = T_LINK ;
map [ curmap ] . selecteditem = o ;
drawmap ( ) ;
}
}
} else if ( event . button . button = = SDL_BUTTON_RIGHT ) {
if ( state = = S_RESIZING ) {
// end resize
endresize ( event . button . x , event . button . y ) ;
changestate ( S_NONE ) ;
} else if ( state = = S_TEXTRESIZING ) {
// end text resize
endtextresize ( event . button . x , event . button . y ) ;
changestate ( S_NONE ) ;
2005-10-28 16:05:57 +10:00
}
/* check for right click on toolbox */
if ( isontoolbox ( event . button . x , event . button . y ) ) {
2005-10-30 19:45:37 +11:00
int tempx , tempy , selection , boxy ;
2005-10-28 16:05:57 +10:00
tempx = ( event . button . x - toolbox . x ) / ( toolbox . gridsize + 3 ) ;
tempy = ( event . button . y - toolbox . y ) / ( toolbox . gridsize + 3 ) ;
2005-10-30 19:45:37 +11:00
boxy = toolbox . y + ( tempy * ( toolbox . gridsize + 3 ) ) ;
2005-10-28 16:05:57 +10:00
selection = tempy * toolbox . gridrowlen + tempx ;
switch ( selection ) {
case TB_FGCOL :
changestate ( S_FGCOL ) ;
drawmap ( ) ;
break ;
case TB_FILLCOL :
changestate ( S_FILLCOL ) ;
drawmap ( ) ;
break ;
2005-10-30 19:45:37 +11:00
case TB_LINESTYLE :
/* figure out where in the box we are */
if ( event . button . y < = ( boxy + 9 ) ) {
changelinethickness ( 1 ) ;
} else if ( event . button . y < = ( boxy + 19 ) ) {
changelinestyle ( 1 ) ;
} else {
changelinearrow ( 1 ) ;
}
drawstatusbar ( ) ;
break ;
2005-10-28 16:05:57 +10:00
}
2005-10-25 16:35:55 +10:00
}
}
break ;
case SDL_MOUSEMOTION :
switch ( state ) {
case S_OBJMOVING :
updatemoveshadow ( event . button . x , event . button . y ) ;
break ;
case S_RESIZING :
updateresizeshadow ( event . button . x , event . button . y ) ;
break ;
case S_DRAWLINK :
updatelinkshadow ( event . button . x , event . button . y ) ;
break ;
case S_TEXTMOVING :
updatetextshadow ( event . button . x , event . button . y ) ;
break ;
case S_TEXTRESIZING :
updateresizetextshadow ( event . button . x , event . button . y ) ;
break ;
case S_LINKPOINTMOVE :
updatelinkpointshadow ( event . button . x , event . button . y ) ;
break ;
2005-11-05 14:22:50 +11:00
case S_NONE :
/* has mouse moved since last time? */
mousepos = getmousepos ( event . button . x , event . button . y ) ;
if ( ( mousepos ! = oldmousepos ) | | ( mousepos = = MP_TOOLBOX ) ) {
/* rollovers */
if ( mousepos = = MP_TOOLBOX ) {
SDL_Rect area ;
int tempx , tempy , selection ;
int boxy ;
if ( ! rollover ) strcpy ( oldstatustext , statustext ) ;
rollover = TRUE ;
/* determine which button we're over */
tempx = ( event . button . x - toolbox . x ) / ( toolbox . gridsize + 3 ) ;
tempy = ( event . button . y - toolbox . y ) / ( toolbox . gridsize + 3 ) ;
boxy = toolbox . y + ( tempy * ( toolbox . gridsize + 3 ) ) ;
selection = tempy * toolbox . gridrowlen + tempx ;
/* replace old button */
if ( toolbg ! = NULL ) {
SDL_Rect area ;
if ( oldselection > = 0 ) {
if ( dontpaste = = FALSE ) {
area . x = toolbox . x + ( ( oldselection % 3 ) * ( toolbox . gridsize + 3 ) ) ;
area . y = toolbox . y + ( ( oldselection / 3 ) * ( toolbox . gridsize + 3 ) ) ;
area . w = toolbox . gridsize ;
area . h = toolbox . gridsize ;
SDL_BlitSurface ( toolbg , NULL , screen , & area ) ;
SDL_UpdateRect ( screen , area . x , area . y , area . w , area . h ) ;
} else {
dontpaste = FALSE ;
}
}
SDL_FreeSurface ( toolbg ) ;
toolbg = NULL ;
}
/* copy background of this button */
if ( selection < = TB_SAVE ) {
toolbg = SDL_CreateRGBSurface ( SDL_SWSURFACE , toolbox . gridsize + 3 , toolbox . gridsize + 3 ,
screen - > format - > BitsPerPixel , screen - > format - > Rmask ,
screen - > format - > Gmask , screen - > format - > Bmask ,
screen - > format - > Amask ) ;
area . x = toolbox . x + ( ( selection % 3 ) * ( toolbox . gridsize + 3 ) ) ;
area . y = toolbox . y + ( ( selection / 3 ) * ( toolbox . gridsize + 3 ) ) ;
area . w = toolbox . gridsize + 1 ;
area . h = toolbox . gridsize + 1 ;
SDL_BlitSurface ( screen , & area , toolbg , 0 ) ;
/* draw highlight */
if ( selection = = TB_LINESTYLE ) {
SDL_Rect sarea ;
if ( event . button . y < = ( boxy + 9 ) ) {
sarea . x = 0 ;
sarea . y = 0 ;
sarea . w = toolbox . gridsize ;
sarea . h = 11 ;
area . h = 11 ;
area . y + = 1 ;
} else if ( event . button . y < = ( boxy + 19 ) ) {
sarea . x = 0 ;
sarea . y = 0 ;
sarea . w = toolbox . gridsize ;
sarea . h = 10 ;
area . h = 10 ;
area . y + = 12 ;
} else {
sarea . x = 0 ;
sarea . y = 0 ;
sarea . w = toolbox . gridsize ;
sarea . h = 8 ;
area . h = 8 ;
area . y + = 21 ;
}
SDL_BlitSurface ( toolhilite , & sarea , screen , & area ) ;
} else {
SDL_BlitSurface ( toolhilite , NULL , screen , & area ) ;
}
SDL_UpdateRect ( screen , area . x , area . y , area . w , area . h ) ;
}
if ( selection ! = oldselection ) {
switch ( selection ) {
case TB_POINTER :
sprintf ( statustext , " LMB = Enter object selection mode " ) ;
drawstatusbar ( ) ;
break ;
case TB_ADDOBJ :
sprintf ( statustext , " LMB = Add an object to the map " ) ;
drawstatusbar ( ) ;
break ;
case TB_ADDTEXT :
sprintf ( statustext , " LMB (on map) = Add text to the map, LMB (on object) = Add text to an object " ) ;
drawstatusbar ( ) ;
break ;
case TB_FGCOL :
sprintf ( statustext , " LMB = Apply default foreground colour to current selection, RMB = Change default foreground colour " ) ;
drawstatusbar ( ) ;
break ;
case TB_FILLCOL :
sprintf ( statustext , " LMB = Apply default fill colour to current selection, RMB = Change default fill colour " ) ;
drawstatusbar ( ) ;
break ;
case TB_LINESTYLE :
if ( event . button . y < = ( boxy + 9 ) ) {
sprintf ( statustext , " LMB = Apply default thickness to current line, RMB = Change default line thickness " ) ;
} else if ( event . button . y < = ( boxy + 19 ) ) {
sprintf ( statustext , " LMB = Apply default style to current line, RMB = Change default line style " ) ;
} else {
sprintf ( statustext , " LMB = Apply default arrowhead type to current line, RMB = Change default arrowhead type " ) ;
}
drawstatusbar ( ) ;
break ;
case TB_MATCHSIZE :
sprintf ( statustext , " LMB = Match size of current selection to next object clicked " ) ;
drawstatusbar ( ) ;
break ;
case TB_MATCHX :
sprintf ( statustext , " LMB = Match horizontal position of currently selected object to next object clicked " ) ;
drawstatusbar ( ) ;
break ;
case TB_MATCHY :
sprintf ( statustext , " LMB = Match vertical position of currently selected object to next object clicked " ) ;
drawstatusbar ( ) ;
break ;
case TB_DRILLDOWN :
sprintf ( statustext , " LMB = Drill down to create new map under current object " ) ;
drawstatusbar ( ) ;
break ;
case TB_CREATETELE :
sprintf ( statustext , " LMB = Set destination map for when current object is double-clicked " ) ;
drawstatusbar ( ) ;
break ;
case TB_DELETEMAP :
sprintf ( statustext , " LMB = Delete current map (hold down SHIFT to confirm) " ) ;
drawstatusbar ( ) ;
break ;
case TB_NEW :
sprintf ( statustext , " LMB = Delete ALL maps and start a fresh project (hold SHIFT to confirm) " ) ;
drawstatusbar ( ) ;
break ;
case TB_LOAD :
sprintf ( statustext , " LMB = Load a new map " ) ;
drawstatusbar ( ) ;
break ;
case TB_SAVE :
sprintf ( statustext , " LMB = Save the current map to disk (use a .BMP extension to export to bitmap format) " ) ;
drawstatusbar ( ) ;
break ;
default :
break ;
}
}
oldselection = selection ;
} else if ( mousepos = = MP_MAPBOXNAME ) {
if ( ! rollover ) strcpy ( oldstatustext , statustext ) ;
rollover = TRUE ;
sprintf ( statustext , " LMB = Change the name of the current map. " ) ;
drawstatusbar ( ) ;
} else if ( mousepos = = MP_MAPBOXCHILDREN ) {
if ( ! rollover ) strcpy ( oldstatustext , statustext ) ;
rollover = TRUE ;
sprintf ( statustext , " LMB = Drill down into a submap. " ) ;
drawstatusbar ( ) ;
} else if ( mousepos = = MP_OBJECTBOX ) {
if ( ! rollover ) strcpy ( oldstatustext , statustext ) ;
rollover = TRUE ;
sprintf ( statustext , " LMB = Select a new object type. " ) ;
drawstatusbar ( ) ;
} else {
strcpy ( statustext , oldstatustext ) ;
strcpy ( oldstatustext , " " ) ;
drawstatusbar ( ) ;
rollover = FALSE ;
}
}
oldmousepos = mousepos ;
break ;
2005-10-25 16:35:55 +10:00
}
break ;
case SDL_QUIT :
if ( modified ) {
strcpy ( text , " Changes not saved - really quit? " ) ;
changestate ( S_REALLYQUIT ) ;
drawmap ( ) ;
} else {
done = TRUE ;
}
break ;
case SDL_VIDEOEXPOSE :
/* redraw screen */
drawscreen ( ) ;
break ;
case SDL_KEYDOWN :
c = event . key . keysym . sym ;
mod = SDL_GetModState ( ) ;
/* state independant */
if ( mod & KMOD_SHIFT ) {
if ( ( c > = ' a ' ) & & ( c < = ' z ' ) ) {
c - = 32 ;
} else if ( c = = ' 1 ' ) {
c = ' ! ' ;
} else if ( c = = ' 2 ' ) {
c = ' @ ' ;
} else if ( c = = ' 3 ' ) {
c = ' # ' ;
} else if ( c = = ' 4 ' ) {
c = ' $ ' ;
} else if ( c = = ' 5 ' ) {
c = ' % ' ;
} else if ( c = = ' 6 ' ) {
c = ' ^ ' ;
} else if ( c = = ' 7 ' ) {
c = ' & ' ;
} else if ( c = = ' 8 ' ) {
c = ' * ' ;
} else if ( c = = ' 9 ' ) {
c = ' ( ' ;
} else if ( c = = ' 0 ' ) {
c = ' ) ' ;
} else if ( c = = ' - ' ) {
c = ' _ ' ;
} else if ( c = = ' = ' ) {
c = ' + ' ;
} else if ( c = = ' \\ ' ) {
c = ' | ' ;
} else if ( c = = ' ; ' ) {
c = ' : ' ;
} else if ( c = = ' \' ' ) {
c = ' " ' ;
} else if ( c = = ' , ' ) {
c = ' < ' ;
} else if ( c = = ' . ' ) {
c = ' > ' ;
} else if ( c = = ' / ' ) {
c = ' ? ' ;
}
}
/* state dependant */
2005-10-29 16:37:41 +10:00
if ( ( state = = S_TYPETEXT ) | | ( state = = S_SAVING ) | | ( state = = S_LOADING ) | | ( state = = S_MAPNAMING ) | | ( state = = S_EDITTEXT ) ) {
2005-10-25 16:35:55 +10:00
if ( ( c > = FIRSTLET ) & & ( c < = LASTLET ) ) {
char temptext [ 2 ] ;
sprintf ( temptext , " %c " , c ) ;
strcat ( text , temptext ) ;
updatetextcursor ( ) ;
} else if ( c = = SDLK_ESCAPE ) {
sprintf ( statustext , " Aborted. " ) ;
changestate ( S_NONE ) ;
drawmap ( ) ;
} else if ( c = = ' ' ) {
strcat ( text , " " ) ;
updatetextcursor ( ) ;
} else if ( c = = SDLK_BACKSPACE ) {
text [ strlen ( text ) - 1 ] = ' \0 ' ;
updatetextcursor ( ) ;
} else if ( c = = 13 ) { /* enter */
if ( state = = S_TYPETEXT ) {
endtext ( ) ;
2005-10-29 16:37:41 +10:00
} else if ( state = = S_EDITTEXT ) {
endtextedit ( ) ;
2005-10-25 16:35:55 +10:00
} else if ( state = = S_SAVING ) {
savemap ( ) ;
changestate ( S_NONE ) ;
drawmap ( ) ;
} else if ( state = = S_LOADING ) {
loadmap ( ) ;
changestate ( S_NONE ) ;
drawmap ( ) ;
} else if ( state = = S_MAPNAMING ) {
/* rename map */
strcpy ( map [ curmap ] . name , text ) ;
changestate ( S_NONE ) ;
sprintf ( statustext , " Map #%d renamed to '%s'. " , curmap , map [ curmap ] . name ) ;
drawmap ( ) ;
}
}
} else {
if ( c = = ' a ' ) { /* add map[curmap].object */
if ( state = = S_NONE ) {
changestate ( S_ADDOBJ ) ;
}
}
if ( c = = ' t ' ) { /* add text */
if ( state = = S_NONE ) {
changestate ( S_ADDTEXT ) ;
}
}
2005-10-29 16:37:41 +10:00
if ( ( c = = ' e ' ) | | ( c = = SDLK_F2 ) ) { /* edit current text */
if ( state = = S_NONE ) {
if ( ( map [ curmap ] . selecteditemtype = = T_TEXT ) & &
( map [ curmap ] . selecteditem ! = - 1 ) ) {
startedittext ( map [ curmap ] . selecteditem ) ;
} else {
sprintf ( statustext , " Cannot edit text - no text item selected! " ) ;
drawstatusbar ( ) ;
}
}
}
2005-10-25 16:35:55 +10:00
if ( c = = ' s ' ) { /* save */
startx = 1 ;
starty = ( map [ curmap ] . height / 2 ) - 2 ;
bg = NULL ;
strcpy ( text , currentfilename ) ;
changestate ( S_SAVING ) ;
drawmap ( ) ;
}
if ( ( c = = ' l ' ) | | ( c = = ' o ' ) ) { /* load, open */
startx = 1 ;
starty = ( map [ curmap ] . height / 2 ) - 2 ;
bg = NULL ;
strcpy ( text , currentfilename ) ;
changestate ( S_LOADING ) ;
drawmap ( ) ;
}
2005-10-25 16:45:19 +10:00
if ( ( c = = ' , ' ) | | ( c = = ' q ' ) ) { /* scroll object box up */
if ( obox . pos > 0 ) {
obox . pos - - ;
drawobox ( ) ;
}
}
if ( ( c = = ' . ' ) | | ( c = = ' w ' ) ) { /* scroll object box down */
int fitx , fity , fit ;
/* figure out how many objects we can fit in the box */
fitx = ( obox . width / obox . gridsize ) ;
fity = ( ( obox . height + 3 ) / obox . gridsize ) ;
fit = fitx * fity ;
/* check if incrementing position is okay or not */
if ( ( ( obox . pos + 1 ) * 3 + fit ) < = ( numobjtypes + 2 ) ) {
obox . pos + + ;
drawobox ( ) ;
}
}
2005-10-25 16:35:55 +10:00
if ( c = = ' x ' ) {
if ( map [ curmap ] . selecteditem ! = - 1 ) {
if ( map [ curmap ] . selecteditemtype = = T_OBJECT ) {
changestate ( S_MATCHX ) ;
drawmap ( ) ;
}
}
}
if ( c = = ' y ' ) {
if ( map [ curmap ] . selecteditem ! = - 1 ) {
if ( map [ curmap ] . selecteditemtype = = T_OBJECT ) {
changestate ( S_MATCHY ) ;
drawmap ( ) ;
}
}
}
2005-10-25 16:45:19 +10:00
if ( c = = ' b ' ) {
if ( map [ curmap ] . selecteditem ! = - 1 ) {
if ( map [ curmap ] . selecteditemtype = = T_OBJECT ) {
changestate ( S_MATCHSIZE ) ;
drawmap ( ) ;
}
}
}
2005-11-05 14:22:50 +11:00
if ( c = = ' c ' ) { /* copy */
if ( map [ curmap ] . selecteditem = = - 1 ) {
/* copy entire map */
copytype = T_MAP ;
copyfrom = - 1 ;
copymap = curmap ;
sprintf ( statustext , " Map %d ('%s') set as copy source. " , curmap , map [ curmap ] . name ) ;
drawstatusbar ( ) ;
} else {
if ( map [ curmap ] . selecteditemtype = = T_OBJECT ) {
copytype = T_OBJECT ;
copymap = curmap ;
copyfrom = map [ curmap ] . selecteditem ;
sprintf ( statustext , " Object %d set as copy source. " , copyfrom ) ;
drawstatusbar ( ) ;
} else if ( map [ curmap ] . selecteditemtype = = T_TEXT ) {
copytype = T_TEXT ;
copymap = curmap ;
copyfrom = map [ curmap ] . selecteditem ;
sprintf ( statustext , " Text %d ('%s') set as copy source. " , copyfrom , map [ curmap ] . textob [ copyfrom ] . text ) ;
drawstatusbar ( ) ;
}
}
}
2005-10-25 16:35:55 +10:00
if ( c = = ' d ' ) { /* drill down */
if ( state = = S_NONE ) {
if ( ( map [ curmap ] . selecteditemtype = = T_OBJECT ) & & ( map [ curmap ] . selecteditem ! = - 1 ) ) {
drillto ( map [ curmap ] . obj [ map [ curmap ] . selecteditem ] . child ) ;
} else {
sprintf ( statustext , " Cannot drill down - no object selected! " ) ;
drawstatusbar ( ) ;
}
} else {
sprintf ( statustext , " Cannot drill down in state %d. " , state ) ;
drawstatusbar ( ) ;
}
}
2005-11-05 14:22:50 +11:00
if ( c = = ' p ' ) { /* paste */
if ( copytype = = T_MAP ) {
if ( copymap = = curmap ) {
sprintf ( statustext , " Error: copy source and destination are the same! " ) ;
drawstatusbar ( ) ;
} else if ( copymap < 0 ) {
sprintf ( statustext , " Error: No copy source selected! " ) ;
drawstatusbar ( ) ;
} else {
map [ curmap ] = map [ copymap ] ;
sprintf ( map [ curmap ] . name , " Copy of map%d " , copymap ) ;
modified = TRUE ;
sprintf ( statustext , " Map %d ('%s') copied to map %d. " , copymap , map [ copymap ] . name , curmap ) ;
copytype = - 1 ;
copymap = - 1 ;
drawmap ( ) ;
}
} else if ( copytype = = T_TEXT ) {
int tnum ;
/* create new text object */
if ( ( map [ copymap ] . textob [ copyfrom ] . x + 10 ) > = map [ curmap ] . width ) {
startx = map [ copymap ] . textob [ copyfrom ] . x - 10 ;
} else {
startx = map [ copymap ] . textob [ copyfrom ] . x + 10 ;
}
if ( ( map [ copymap ] . textob [ copyfrom ] . y + 10 ) > = map [ curmap ] . height ) {
starty = map [ copymap ] . textob [ copyfrom ] . y - 10 ;
} else {
starty = map [ copymap ] . textob [ copyfrom ] . y + 10 ;
}
if ( copymap = = curmap ) {
textanchor = map [ copymap ] . textob [ copyfrom ] . anchor ;
if ( textanchor ! = - 1 ) {
startx + = map [ copymap ] . obj [ textanchor ] . x ;
starty + = map [ copymap ] . obj [ textanchor ] . y ;
}
} else {
textanchor = - 1 ;
}
strcpy ( text , map [ copymap ] . textob [ copyfrom ] . text ) ;
/* create it */
endtext ( ) ;
sprintf ( statustext , " Text object pasted at %d,%d. " , startx , starty ) ;
/* update its size */
tnum = map [ curmap ] . numtext - 1 ;
map [ curmap ] . textob [ tnum ] . h = map [ copymap ] . textob [ copyfrom ] . h ;
map [ curmap ] . textob [ tnum ] . w = map [ copymap ] . textob [ copyfrom ] . w ;
map [ curmap ] . textob [ tnum ] . c = map [ copymap ] . textob [ copyfrom ] . c ;
/* select new item */
map [ curmap ] . selecteditemtype = T_TEXT ;
map [ curmap ] . selecteditem = tnum ;
/* clear buffer */
copytype = - 1 ;
copymap = - 1 ;
drawmap ( ) ;
} else {
sprintf ( statustext , " Error: No copy source selected! " ) ;
drawstatusbar ( ) ;
}
}
2005-10-25 16:35:55 +10:00
if ( c = = SDLK_BACKSPACE ) {
goback ( ) ;
}
if ( c = = SDLK_DELETE ) {
if ( map [ curmap ] . selecteditem ! = - 1 ) {
if ( map [ curmap ] . selecteditemtype = = T_LINKPOINT ) {
int i ;
for ( i = map [ curmap ] . selectedlinkpoint ; i < ( map [ curmap ] . olink [ map [ curmap ] . selecteditem ] . npoints - 1 ) ; i + + ) {
map [ curmap ] . olink [ map [ curmap ] . selecteditem ] . point [ i ] . x = map [ curmap ] . olink [ map [ curmap ] . selecteditem ] . point [ i + 1 ] . x ;
map [ curmap ] . olink [ map [ curmap ] . selecteditem ] . point [ i ] . y = map [ curmap ] . olink [ map [ curmap ] . selecteditem ] . point [ i + 1 ] . y ;
}
map [ curmap ] . olink [ map [ curmap ] . selecteditem ] . npoints - - ;
/* move selection to next point on same line */
if ( map [ curmap ] . olink [ map [ curmap ] . selecteditem ] . npoints > 0 ) {
if ( map [ curmap ] . selectedlinkpoint > = map [ curmap ] . olink [ map [ curmap ] . selecteditem ] . npoints ) {
map [ curmap ] . selectedlinkpoint = map [ curmap ] . olink [ map [ curmap ] . selecteditem ] . npoints - 1 ;
}
} else {
/* deselect point (leave link selected) */
map [ curmap ] . selectedlinkpoint = - 1 ;
map [ curmap ] . selecteditemtype = T_LINK ;
}
sprintf ( statustext , " Deleted link #%d point #%d. " , map [ curmap ] . selecteditem , map [ curmap ] . selectedlinkpoint ) ;
drawmap ( ) ;
} else {
deletething ( map [ curmap ] . selecteditem , map [ curmap ] . selecteditemtype ) ;
}
}
}
if ( c = = ' ] ' ) { /* raise */
if ( map [ curmap ] . selecteditem ! = - 1 ) {
/* raise the selected map[curmap].object */
raiseselected ( ) ;
}
}
if ( c = = ' [ ' ) { /* lower */
if ( map [ curmap ] . selecteditem ! = - 1 ) {
/* lower the selected map[curmap].object */
lowerselected ( ) ;
}
}
}
break ;
}
}
} /* end main loop */
return 0 ;
}
void addlinkpoint ( int linkid , int x , int y ) {
int pos ;
int i ;
pos = findpointpos ( & map [ curmap ] . olink [ linkid ] , x , y ) ;
map [ curmap ] . olink [ linkid ] . npoints + + ;
/* shuffle points from that point upwards */
for ( i = ( map [ curmap ] . olink [ linkid ] . npoints - 1 ) ; i > pos ; i - - ) {
map [ curmap ] . olink [ linkid ] . point [ i ] = map [ curmap ] . olink [ linkid ] . point [ i - 1 ] ;
}
map [ curmap ] . olink [ linkid ] . point [ pos ] . x = x ;
map [ curmap ] . olink [ linkid ] . point [ pos ] . y = y ;
modified = TRUE ;
sprintf ( statustext , " Point added to link #%d " , linkid ) ;
}
2005-10-25 16:45:19 +10:00
int addvector ( vectorimg_t * vimg , int type , int x1 , int y1 , int x2 , int y2 , SDL_Color * c ) {
if ( ( vimg - > vnum + 1 ) > = MAXVECTORSPERIMAGE ) return TRUE ;
2005-10-25 16:35:55 +10:00
vimg - > vector [ vimg - > vnum ] . type = type ;
vimg - > vector [ vimg - > vnum ] . x1 = x1 ;
vimg - > vector [ vimg - > vnum ] . y1 = y1 ;
vimg - > vector [ vimg - > vnum ] . x2 = x2 ;
vimg - > vector [ vimg - > vnum ] . y2 = y2 ;
vimg - > vector [ vimg - > vnum ] . c . r = c - > r ;
vimg - > vector [ vimg - > vnum ] . c . g = c - > g ;
vimg - > vector [ vimg - > vnum ] . c . b = c - > b ;
vimg - > vnum = vimg - > vnum + 1 ;
2005-10-25 16:45:19 +10:00
return FALSE ;
2005-10-25 16:35:55 +10:00
}
2005-10-30 19:45:37 +11:00
void changelinearrow ( int changeby ) {
if ( ( changeby < 0 ) & & ( defarrow = = 0 ) ) {
2005-11-05 14:22:50 +11:00
defarrow = AP_BOTH ;
2005-10-30 19:45:37 +11:00
} else {
defarrow + = changeby ;
}
/* wrap around */
2005-11-05 14:22:50 +11:00
if ( defarrow > AP_BOTH ) defarrow = 0 ;
2005-10-30 19:45:37 +11:00
/* change arrow style on currently selected line */
if ( map [ curmap ] . selecteditemtype = = T_LINK ) {
if ( map [ curmap ] . selecteditem ! = - 1 ) {
map [ curmap ] . olink [ map [ curmap ] . selecteditem ] . style & = 0x00ffff ;
map [ curmap ] . olink [ map [ curmap ] . selecteditem ] . style | = ( defarrow < < 16 ) ;
modified = TRUE ;
drawmap ( ) ;
}
}
/* redraw toolbox */
drawtoolbox ( ) ;
}
void changelinestyle ( int changeby ) {
if ( ( changeby < 0 ) & & ( defstyle = = 0 ) ) {
defstyle = MAXLINESTYLE - 1 ;
} else {
defstyle + = changeby ;
}
/* wrap around */
if ( defstyle > = MAXLINESTYLE ) defstyle = 0 ;
/* change line style of currently selected line */
if ( map [ curmap ] . selecteditemtype = = T_LINK ) {
if ( map [ curmap ] . selecteditem ! = - 1 ) {
map [ curmap ] . olink [ map [ curmap ] . selecteditem ] . style & = 0xff00ff ;
map [ curmap ] . olink [ map [ curmap ] . selecteditem ] . style | = ( defstyle < < 8 ) ;
modified = TRUE ;
drawmap ( ) ;
}
}
/* redraw toolbox */
drawtoolbox ( ) ;
}
void changelinethickness ( int changeby ) {
defthickness + = changeby ;
/* wrap around */
if ( defthickness < = 0 ) defthickness = 5 ;
if ( defthickness > 5 ) defthickness = 1 ;
/* change thickness of currently selected line */
if ( map [ curmap ] . selecteditemtype = = T_LINK ) {
if ( map [ curmap ] . selecteditem ! = - 1 ) {
map [ curmap ] . olink [ map [ curmap ] . selecteditem ] . style & = 0xffff00 ;
map [ curmap ] . olink [ map [ curmap ] . selecteditem ] . style | = defthickness ;
modified = TRUE ;
drawmap ( ) ;
}
}
/* redraw toolbox */
drawtoolbox ( ) ;
}
2005-10-30 22:50:06 +11:00
void changemap ( int newmap ) {
map [ newmap ] . selecteditem = - 1 ;
map [ newmap ] . selecteditemtype = - 1 ;
map [ newmap ] . selectedtype = map [ curmap ] . selectedtype ;
curmap = newmap ;
}
2005-10-25 16:35:55 +10:00
void changestate ( int newstate ) {
2005-10-30 00:23:10 +10:00
/* can't do most things in readonly mode */
if ( readonly ) {
switch ( newstate ) {
case S_NONE :
case S_LOADING :
case S_REALLYQUIT :
break ;
default :
newstate = S_NONE ;
break ;
}
}
2005-10-25 16:35:55 +10:00
if ( newstate ! = state ) {
if ( ( state = = S_ADDOBJ ) | | ( state = = S_ADDTEXT ) ) {
/* change mouse back to normal */
SDL_SetCursor ( normalmouse ) ;
}
if ( newstate = = S_ADDOBJ ) SDL_SetCursor ( objmouse ) ;
if ( newstate = = S_ADDTEXT ) SDL_SetCursor ( textmouse ) ;
state = newstate ;
drawtoolbox ( ) ;
switch ( state ) {
case S_NONE :
//sprintf(statustext,"Selection mode enabled.\n"); fflush(stdout);
break ;
case S_ADDOBJ :
sprintf ( statustext , " Object creation mode enabled. \n " ) ; fflush ( stdout ) ;
break ;
case S_ADDTEXT :
sprintf ( statustext , " Text creation mode entered. \n " ) ; fflush ( stdout ) ;
break ;
case S_TYPETEXT :
sprintf ( statustext , " Text entry mode entered. \n " ) ; fflush ( stdout ) ;
break ;
2005-10-29 16:37:41 +10:00
case S_EDITTEXT :
sprintf ( statustext , " Text edit mode entered. \n " ) ; fflush ( stdout ) ;
break ;
2005-10-25 16:35:55 +10:00
case S_MATCHSIZE :
sprintf ( statustext , " Size-matching mode entered - select object to copy size from... \n " ) ; fflush ( stdout ) ;
break ;
case S_MATCHX :
sprintf ( statustext , " X-matching mode entered - select object to align with... \n " ) ; fflush ( stdout ) ;
break ;
case S_MATCHY :
sprintf ( statustext , " Y-matching mode entered - select object to align with... \n " ) ; fflush ( stdout ) ;
break ;
case S_MAPNAMING :
sprintf ( statustext , " Map rename mode entered. \n " ) ; fflush ( stdout ) ;
break ;
case S_SAVING :
sprintf ( statustext , " Save mode entered. \n " ) ; fflush ( stdout ) ;
break ;
case S_LOADING :
sprintf ( statustext , " Load mode entered. \n " ) ; fflush ( stdout ) ;
break ;
}
drawstatusbar ( ) ;
}
}
void cleanup ( void ) {
2005-10-27 14:46:38 +10:00
int i ;
2005-10-25 16:35:55 +10:00
SDL_FreeCursor ( textmouse ) ;
SDL_FreeCursor ( objmouse ) ;
2005-10-27 14:46:38 +10:00
for ( i = 1 ; i < MAXLETTERHEIGHT ; i + + ) {
TTF_CloseFont ( font [ i ] ) ;
}
TTF_Quit ( ) ;
2005-10-25 16:35:55 +10:00
SDL_Quit ( ) ;
}
int createobject ( int type , int x , int y ) {
map [ curmap ] . obj [ map [ curmap ] . numobjects ] . type = type ;
map [ curmap ] . obj [ map [ curmap ] . numobjects ] . w = objtype [ type ] . defw ;
map [ curmap ] . obj [ map [ curmap ] . numobjects ] . h = objtype [ type ] . defh ;
if ( ( x + map [ curmap ] . obj [ map [ curmap ] . numobjects ] . w ) > = map [ curmap ] . width ) {
x = map [ curmap ] . width - map [ curmap ] . obj [ map [ curmap ] . numobjects ] . w - 1 ;
}
if ( ( y + map [ curmap ] . obj [ map [ curmap ] . numobjects ] . h ) > = map [ curmap ] . height ) {
y = map [ curmap ] . height - map [ curmap ] . obj [ map [ curmap ] . numobjects ] . h - 1 ;
}
map [ curmap ] . obj [ map [ curmap ] . numobjects ] . x = x ;
map [ curmap ] . obj [ map [ curmap ] . numobjects ] . y = y ;
map [ curmap ] . obj [ map [ curmap ] . numobjects ] . child = - 1 ;
modified = TRUE ;
sprintf ( statustext , " Object #%d (%s) created at (%d,%d). \n " , map [ curmap ] . numobjects , objtype [ type ] . name , x , y ) ;
drawstatusbar ( ) ;
/* add to 'thing' list */
map [ curmap ] . thing [ map [ curmap ] . numthings ] . type = T_OBJECT ;
map [ curmap ] . thing [ map [ curmap ] . numthings ] . id = map [ curmap ] . numobjects ;
map [ curmap ] . numobjects + + ;
map [ curmap ] . numthings + + ;
return 0 ;
}
void copyline ( SDL_Surface * screen , int x1 , int y1 , int x2 , int y2 , int * lbuf ) {
int deltax , deltay ;
int numpixels ;
int d ;
int dinc1 , dinc2 , xinc1 , xinc2 , yinc1 , yinc2 ;
int i ;
int x ;
int y ;
SDL_Color bgcol ;
/* store coords */
lbuf [ 0 ] = x1 ;
lbuf [ 1 ] = y1 ;
lbuf [ 2 ] = x2 ;
lbuf [ 3 ] = y2 ;
deltax = ( x2 - x1 ) ;
if ( deltax < 0 ) deltax = - deltax ;
deltay = ( y2 - y1 ) ;
if ( deltay < 0 ) deltay = - deltay ;
if ( deltax > = deltay ) {
numpixels = deltax + 1 ;
d = ( deltay * 2 ) - deltax ;
dinc1 = deltay < < 1 ;
dinc2 = ( deltay - deltax ) < < 1 ;
xinc1 = 1 ;
xinc2 = 1 ;
yinc1 = 0 ;
yinc2 = 1 ;
} else {
numpixels = deltay + 1 ;
d = ( deltax * 2 ) - deltay ;
dinc1 = deltax < < 1 ;
dinc2 = ( deltax - deltay ) < < 1 ;
xinc1 = 0 ;
xinc2 = 1 ;
yinc1 = 1 ;
yinc2 = 1 ;
}
if ( x1 > x2 ) {
xinc1 = - xinc1 ;
xinc2 = - xinc2 ;
}
if ( y1 > y2 ) {
yinc1 = - yinc1 ;
yinc2 = - yinc2 ;
}
x = x1 ; y = y1 ;
for ( i = 0 ; i < numpixels ; i + + ) {
getcolor ( screen , x , y , & bgcol ) ;
lbuf [ i + 4 ] = SDL_MapRGB ( screen - > format , bgcol . r , bgcol . g , bgcol . b ) ;
if ( d < 0 ) {
d + = dinc1 ;
x + = xinc1 ;
y + = yinc1 ;
} else {
d + = dinc2 ;
x + = xinc2 ;
y + = yinc2 ;
}
}
}
void deletething ( int id , int type ) {
int i ;
int found ;
if ( type = = T_LINK ) {
/* remove the link*/
deletelink ( id ) ;
} else if ( type = = T_TEXT ) {
deletetext ( id ) ;
} else if ( type = = T_OBJECT ) {
/* remove any links connecting to this map[curmap].object */
found = 0 ;
while ( found > = 0 ) {
found = - 1 ;
for ( i = 0 ; i < map [ curmap ] . numlinks ; i + + ) {
if ( ( map [ curmap ] . olink [ i ] . srcobj = = id ) | | ( map [ curmap ] . olink [ i ] . dstobj = = id ) ) {
found = i ;
break ;
}
}
if ( found > = 0 ) {
deletelink ( found ) ;
}
}
/* remove any text anchored to this map[curmap].object */
found = 0 ;
while ( found > = 0 ) {
found = - 1 ;
for ( i = 0 ; i < map [ curmap ] . numtext ; i + + ) {
if ( map [ curmap ] . textob [ i ] . anchor = = id ) {
found = i ;
break ;
}
}
if ( found > = 0 ) {
deletetext ( found ) ;
}
}
/* remove the map[curmap].object */
deleteobject ( id ) ;
/* shuffle ids on any link referencing this object */
for ( i = 0 ; i < map [ curmap ] . numlinks ; i + + ) {
if ( map [ curmap ] . olink [ i ] . srcobj > id ) {
map [ curmap ] . olink [ i ] . srcobj - - ;
}
if ( map [ curmap ] . olink [ i ] . dstobj > id ) {
map [ curmap ] . olink [ i ] . dstobj - - ;
}
}
/* shuffle ids on any text referencing this object */
for ( i = 0 ; i < map [ curmap ] . numtext ; i + + ) {
if ( map [ curmap ] . textob [ i ] . anchor > id ) {
map [ curmap ] . textob [ i ] . anchor - - ;
}
}
}
modified = TRUE ;
map [ curmap ] . selecteditem = - 1 ;
map [ curmap ] . selecteditemtype = - 1 ;
drawmap ( ) ;
}
void deletelink ( int linkid ) {
int i ;
int n ;
int found ;
for ( i = linkid ; i < ( map [ curmap ] . numlinks - 1 ) ; i + + ) {
map [ curmap ] . olink [ i ] = map [ curmap ] . olink [ i + 1 ] ;
}
map [ curmap ] . numlinks - - ;
/* shuffle thing # */
for ( n = 0 ; n < map [ curmap ] . numthings ; n + + ) {
/* mark for deletion */
if ( ( map [ curmap ] . thing [ n ] . id = = linkid ) & & ( map [ curmap ] . thing [ n ] . type = = T_LINK ) ) {
map [ curmap ] . thing [ n ] . id = - 1 ;
}
/* shuffle id */
if ( ( map [ curmap ] . thing [ n ] . id > linkid ) & & ( map [ curmap ] . thing [ n ] . type = = T_LINK ) ) {
map [ curmap ] . thing [ n ] . id - - ;
}
}
found = - 1 ;
for ( n = 0 ; n < map [ curmap ] . numthings ; n + + ) {
if ( ( map [ curmap ] . thing [ n ] . type = = T_LINK ) & & ( map [ curmap ] . thing [ n ] . id = = - 1 ) ) {
found = n ;
}
}
if ( found ! = - 1 ) {
// remove the thing
for ( n = found ; n < ( map [ curmap ] . numthings - 1 ) ; n + + ) {
map [ curmap ] . thing [ n ] = map [ curmap ] . thing [ n + 1 ] ;
}
map [ curmap ] . numthings - - ;
} else {
sprintf ( statustext , " Can't find matching thing for link #%d! \n " , linkid ) ;
}
modified = TRUE ;
sprintf ( statustext , " Deleted link #%d. \n " , linkid ) ;
drawstatusbar ( ) ;
}
void deleteobject ( int oid ) {
int i ;
int n ;
int found ;
for ( i = oid ; i < ( map [ curmap ] . numobjects - 1 ) ; i + + ) {
map [ curmap ] . obj [ i ] = map [ curmap ] . obj [ i + 1 ] ;
}
map [ curmap ] . numobjects - - ;
/* shuffle thing # */
for ( n = 0 ; n < map [ curmap ] . numthings ; n + + ) {
if ( ( map [ curmap ] . thing [ n ] . id = = oid ) & & ( map [ curmap ] . thing [ n ] . type = = T_OBJECT ) ) {
map [ curmap ] . thing [ n ] . id = - 1 ;
}
if ( ( map [ curmap ] . thing [ n ] . id > oid ) & & ( map [ curmap ] . thing [ n ] . type = = T_OBJECT ) ) {
map [ curmap ] . thing [ n ] . id - - ;
}
}
found = - 1 ;
for ( n = 0 ; n < map [ curmap ] . numthings ; n + + ) {
if ( ( map [ curmap ] . thing [ n ] . type = = T_OBJECT ) & & ( map [ curmap ] . thing [ n ] . id = = - 1 ) ) {
found = n ;
}
}
if ( found ! = - 1 ) {
// remove the thing
for ( n = found ; n < ( map [ curmap ] . numthings - 1 ) ; n + + ) {
map [ curmap ] . thing [ n ] = map [ curmap ] . thing [ n + 1 ] ;
}
map [ curmap ] . numthings - - ;
} else {
sprintf ( statustext , " Can't find matching thing for object #%d! \n " , oid ) ;
}
modified = TRUE ;
sprintf ( statustext , " Deleted object #%d. \n " , oid ) ;
drawstatusbar ( ) ;
}
void deletetext ( int textid ) {
int i ;
int n ;
int found ;
for ( i = textid ; i < ( map [ curmap ] . numtext - 1 ) ; i + + ) {
map [ curmap ] . textob [ i ] = map [ curmap ] . textob [ i + 1 ] ;
}
map [ curmap ] . numtext - - ;
/* shuffle thing # */
for ( n = 0 ; n < map [ curmap ] . numthings ; n + + ) {
/* mark for deletion */
if ( ( map [ curmap ] . thing [ n ] . id = = textid ) & & ( map [ curmap ] . thing [ n ] . type = = T_TEXT ) ) {
map [ curmap ] . thing [ n ] . id = - 1 ;
}
/* shuffle id */
if ( ( map [ curmap ] . thing [ n ] . id > textid ) & & ( map [ curmap ] . thing [ n ] . type = = T_TEXT ) ) {
map [ curmap ] . thing [ n ] . id - - ;
}
}
found = - 1 ;
for ( n = 0 ; n < map [ curmap ] . numthings ; n + + ) {
if ( ( map [ curmap ] . thing [ n ] . type = = T_TEXT ) & & ( map [ curmap ] . thing [ n ] . id = = - 1 ) ) {
found = n ;
}
}
if ( found ! = - 1 ) {
// remove the thing
for ( n = found ; n < ( map [ curmap ] . numthings - 1 ) ; n + + ) {
map [ curmap ] . thing [ n ] = map [ curmap ] . thing [ n + 1 ] ;
}
map [ curmap ] . numthings - - ;
} else {
sprintf ( statustext , " Can't find matching thing for text item #%d! \n " , textid ) ;
}
modified = TRUE ;
sprintf ( statustext , " Deleted text item #%d. \n " , textid ) ;
drawstatusbar ( ) ;
}
2005-10-30 19:45:37 +11:00
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 ;
int arrowend1x , arrowend1y ;
int arrowend2x , arrowend2y ;
int middlex , middley ;
int deltax , deltay ;
int numpixels ;
int d ;
int dinc1 , dinc2 , xinc1 , xinc2 , yinc1 , yinc2 ;
int i ;
int x ;
int y ;
int tempx , tempy ;
int arrowlength = 5 ;
int o , oldo ;
SDL_Surface * temps ;
int arrowthickness ;
arrowthickness = ( arrowstyle & 0x0000ff ) ;
/* calculate where the arrowpoint should go - follow the line until
we ' re not on an object */
if ( arrowpos = = AP_END ) {
/* temporarily reverse endpoints */
tempx = x1 ;
tempy = y1 ;
x1 = x2 ;
y1 = y2 ;
x2 = tempx ;
y2 = tempy ;
}
deltax = ( x2 - x1 ) ;
if ( deltax < 0 ) deltax = - deltax ;
deltay = ( y2 - y1 ) ;
if ( deltay < 0 ) deltay = - deltay ;
if ( deltax > = deltay ) {
numpixels = deltax + 1 ;
d = ( deltay * 2 ) - deltax ;
dinc1 = deltay < < 1 ;
dinc2 = ( deltay - deltax ) < < 1 ;
xinc1 = 1 ;
xinc2 = 1 ;
yinc1 = 0 ;
yinc2 = 1 ;
} else {
numpixels = deltay + 1 ;
d = ( deltax * 2 ) - deltay ;
dinc1 = deltax < < 1 ;
dinc2 = ( deltax - deltay ) < < 1 ;
xinc1 = 0 ;
xinc2 = 1 ;
yinc1 = 1 ;
yinc2 = 1 ;
}
if ( x1 > x2 ) {
xinc1 = - xinc1 ;
xinc2 = - xinc2 ;
}
if ( y1 > y2 ) {
yinc1 = - yinc1 ;
yinc2 = - yinc2 ;
}
x = x1 ; y = y1 ;
/* calculate arrow length based on line length
line length > 40 means arrow length is 5 ,
otherwise it ' s 3 */
if ( numpixels > 40 ) {
arrowlength = 5 ;
} else {
arrowlength = 3 ;
}
/* adjust for line thickness */
arrowlength = arrowlength + arrowthickness - 1 ;
middlex = - 1 ;
middley = - 1 ;
temps = SDL_CreateRGBSurface ( SDL_SWSURFACE , 10 , 10 ,
screen - > format - > BitsPerPixel , screen - > format - > Rmask ,
screen - > format - > Gmask , screen - > format - > Bmask ,
screen - > format - > Amask ) ;
o = - 1 ;
oldo = - 99 ;
for ( i = 0 ; i < numpixels ; i + + ) {
o = objat ( x , y ) ;
if ( o = = - 1 ) {
middlex = x ;
middley = y ;
break ;
} else {
int ox , oy ;
SDL_Color tempc ;
if ( o ! = oldo ) {
/* free temporary surface */
SDL_FreeSurface ( temps ) ;
/* create temp surface */
temps = SDL_CreateRGBSurface ( SDL_SWSURFACE , map [ curmap ] . obj [ o ] . w + 3 , map [ curmap ] . obj [ o ] . h + 3 ,
screen - > format - > BitsPerPixel , screen - > format - > Rmask ,
screen - > format - > Gmask , screen - > format - > Bmask ,
screen - > format - > Amask ) ;
/* draw into temporary surface */
drawobject ( temps , & map [ curmap ] . obj [ o ] , FALSE ) ;
oldo = o ;
}
/* we can start drawing if we're on the object but on a transparent bit */
ox = x - map [ curmap ] . obj [ o ] . x ;
oy = y - map [ curmap ] . obj [ o ] . y ;
getcolor ( temps , ox + arrowthickness - 1 , oy + arrowthickness - 1 , & tempc ) ;
if ( ( tempc . r = = map [ curmap ] . bgcol . r ) & &
( tempc . g = = map [ curmap ] . bgcol . g ) & &
( tempc . b = = map [ curmap ] . bgcol . b ) ) {
/* free temporary surface */
SDL_FreeSurface ( temps ) ;
middlex = x ;
middley = y ;
break ;
}
}
if ( d < 0 ) {
d + = dinc1 ;
x + = xinc1 ;
y + = yinc1 ;
} else {
d + = dinc2 ;
x + = xinc2 ;
y + = yinc2 ;
}
}
if ( ( middlex = = - 1 ) | | ( middley = = - 1 ) ) {
printf ( " no place for arrowhead, quitting \n " ) ;
exit ( 1 ) ;
}
if ( arrowpos = = AP_END ) {
/* put endpoints back */
tempx = x1 ;
tempy = y1 ;
x1 = x2 ;
y1 = y2 ;
x2 = tempx ;
y2 = tempy ;
}
/* calculate angle of line */
angle = atan2 ( y2 - y1 , x2 - x1 ) ;
if ( arrowpos = = AP_END ) {
angle + = M_PI ;
//if (angle > 360) angle -= 360;
}
angle = - angle ;
/* original arrowhead is:
*
* / ( 5 , - 5 )
* /
* ( 0 , 0 ) <
* \
* \ ( 5 , 5 )
*/
/* rotate arrowhead */
arrowpointx = 0 ;
arrowpointy = 0 ;
arrowend1x = ( arrowlength * cos ( angle ) ) + ( - arrowlength * sin ( angle ) ) ;
arrowend1y = ( - arrowlength * sin ( angle ) ) + ( - arrowlength * cos ( angle ) ) ;
arrowend2x = ( arrowlength * cos ( angle ) ) + ( arrowlength * sin ( angle ) ) ;
arrowend2y = ( - arrowlength * sin ( angle ) ) + ( arrowlength * cos ( angle ) ) ;
/* translate arrowhead into position */
arrowpointx = middlex ;
arrowpointy = middley ;
arrowend1x + = middlex ;
arrowend1y + = middley ;
arrowend2x + = middlex ;
arrowend2y + = middley ;
/* get rid of the 'linestyle' and 'arrow' parts of arrowstyle to
* ( respectively ) make sure the arrow looks okay and
* avoid an infinite loop ! */
arrowstyle & = 0x0000ff ;
drawline ( screen , arrowpointx , arrowpointy , arrowend1x , arrowend1y , c , arrowstyle ) ;
drawline ( screen , arrowpointx , arrowpointy , arrowend2x , arrowend2y , c , arrowstyle ) ;
}
2005-10-25 16:35:55 +10:00
void drawbox ( SDL_Surface * screen , int x1 , int y1 , int x2 , int y2 , SDL_Color c ) {
2005-10-30 19:45:37 +11:00
drawline ( screen , x1 , y1 , x2 , y1 , c , 1 ) ;
drawline ( screen , x1 , y1 , x1 , y2 , c , 1 ) ;
drawline ( screen , x1 , y2 , x2 , y2 , c , 1 ) ;
drawline ( screen , x2 , y1 , x2 , y2 , c , 1 ) ;
2005-10-25 16:35:55 +10:00
}
void drawcolorchart ( SDL_Surface * dest ) {
int x , y ;
int i ;
SDL_Color c ;
int speed ;
int finished = FALSE ;
int size = 18 ;
c . r = 0 ;
c . g = 0 ;
c . b = 0 ;
speed = 24 ;
for ( y = 0 ; ( y < ( map [ curmap ] . height - size ) ) & & ( ! finished ) ; y + = size ) {
for ( x = 0 ; ( x < ( map [ curmap ] . width - size ) ) & & ( ! finished ) ; x + = size ) {
drawbox ( dest , x , y , x + ( size - 1 ) , y + ( size - 1 ) , black ) ;
/* fill box */
for ( i = 1 ; i < = ( size - 2 ) ; i + + ) {
2005-10-30 19:45:37 +11:00
drawline ( dest , x + 1 , y + i , x + ( size - 2 ) , y + i , c , 1 ) ;
2005-10-25 16:35:55 +10:00
}
/* change color */
if ( c . b + speed > 255 ) {
c . b = 0 ;
if ( c . g + speed > 255 ) {
c . g = 0 ;
if ( c . r + speed > 255 ) {
finished = TRUE ;
} else c . r + = speed ;
} else c . g + = speed ;
} else c . b + = speed ;
if ( c . r > = 240 ) c . r = 255 ;
if ( c . g > = 240 ) c . g = 255 ;
if ( c . b > = 240 ) c . b = 255 ;
}
}
SDL_Flip ( screen ) ;
}
int drawletter ( SDL_Surface * dest , int x , int y , int w , int h , char let , SDL_Color col ) {
if ( ( let < FIRSTLET ) | | ( let > LASTLET ) ) {
return TRUE ;
}
2005-10-28 16:05:57 +10:00
drawvector ( dest , & letter [ let - FIRSTLET ] . vect , x , y , w , h , & col , NULL ) ;
2005-10-25 16:35:55 +10:00
return FALSE ;
}
int findpointpos ( link_t * l , int px , int py ) {
int i ;
int x , y , x2 , y2 ;
int pos = 0 ;
x = map [ curmap ] . obj [ l - > srcobj ] . x + l - > srcxoff ;
y = map [ curmap ] . obj [ l - > srcobj ] . y + l - > srcyoff ;
for ( i = 0 ; i < l - > npoints ; i + + ) {
x2 = l - > point [ i ] . x ;
y2 = l - > point [ i ] . y ;
if ( isonline ( px , py , x , y , x2 , y2 ) ) {
return pos ;
}
pos + + ;
x = x2 ;
y = y2 ;
}
/* 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 ;
return pos ;
}
2005-10-30 19:45:37 +11:00
void drawline ( SDL_Surface * screen , int x1 , int y1 , int x2 , int y2 , SDL_Color c , int linestyle ) {
2005-10-25 16:35:55 +10:00
int deltax , deltay ;
int numpixels ;
int d ;
int dinc1 , dinc2 , xinc1 , xinc2 , yinc1 , yinc2 ;
int i ;
int x ;
int y ;
2005-10-30 19:45:37 +11:00
int xx , yy ;
int maskcount = 0 ;
int maskindex = 0 ;
Uint8 arrow , style , thickness ;
arrow = ( linestyle & ( 0x00ff0000 ) ) > > 16 ;
style = ( linestyle & ( 0x0000ff00 ) ) > > 8 ;
thickness = ( linestyle & ( 0x000000ff ) ) ;
2005-10-25 16:35:55 +10:00
deltax = ( x2 - x1 ) ;
if ( deltax < 0 ) deltax = - deltax ;
deltay = ( y2 - y1 ) ;
if ( deltay < 0 ) deltay = - deltay ;
if ( deltax > = deltay ) {
numpixels = deltax + 1 ;
d = ( deltay * 2 ) - deltax ;
dinc1 = deltay < < 1 ;
dinc2 = ( deltay - deltax ) < < 1 ;
xinc1 = 1 ;
xinc2 = 1 ;
yinc1 = 0 ;
yinc2 = 1 ;
} else {
numpixels = deltay + 1 ;
d = ( deltax * 2 ) - deltay ;
dinc1 = deltax < < 1 ;
dinc2 = ( deltax - deltay ) < < 1 ;
xinc1 = 0 ;
xinc2 = 1 ;
yinc1 = 1 ;
yinc2 = 1 ;
}
if ( x1 > x2 ) {
xinc1 = - xinc1 ;
xinc2 = - xinc2 ;
}
if ( y1 > y2 ) {
yinc1 = - yinc1 ;
yinc2 = - yinc2 ;
}
x = x1 ; y = y1 ;
2005-10-30 19:45:37 +11:00
maskcount = 0 ;
maskindex = 0 ;
2005-10-25 16:35:55 +10:00
for ( i = 0 ; i < numpixels ; i + + ) {
2005-10-30 19:45:37 +11:00
if ( linemask [ style ] [ maskindex ] = = 1 ) {
/* plot point */
for ( yy = 0 ; yy < thickness ; yy + + ) {
for ( xx = 0 ; xx < thickness ; xx + + ) {
drawpixel ( screen , x + xx , y + yy , c ) ;
}
}
}
/* increment mask count */
if ( + + maskcount > = thickness ) {
maskcount = 0 ;
/* increment mask index */
maskindex + + ;
if ( maskindex > = LINESTYLESIZE ) {
maskindex = 0 ;
}
if ( linemask [ style ] [ maskindex ] = = - 1 ) maskindex = 0 ;
}
2005-10-25 16:35:55 +10:00
if ( d < 0 ) {
d + = dinc1 ;
x + = xinc1 ;
y + = yinc1 ;
} else {
d + = dinc2 ;
x + = xinc2 ;
y + = yinc2 ;
}
}
2005-10-30 19:45:37 +11:00
/* draw arrowheads if required */
if ( arrow ) {
2005-11-05 14:22:50 +11:00
if ( ( arrow = = AP_START ) | | ( arrow = = AP_END ) ) {
drawarrowhead ( screen , x1 , y1 , x2 , y2 , c , linestyle , arrow ) ;
} else if ( arrow = = AP_BOTH ) {
drawarrowhead ( screen , x1 , y1 , x2 , y2 , c , linestyle , AP_START ) ;
drawarrowhead ( screen , x1 , y1 , x2 , y2 , c , linestyle , AP_END ) ;
}
2005-10-30 19:45:37 +11:00
}
2005-10-25 16:35:55 +10:00
}
void drawlink ( SDL_Surface * dest , link_t * l ) {
int i ;
int x , y , x2 , y2 ;
x = map [ curmap ] . obj [ l - > srcobj ] . x + l - > srcxoff ;
y = map [ curmap ] . obj [ l - > srcobj ] . y + l - > srcyoff ;
for ( i = 0 ; i < l - > npoints ; i + + ) {
x2 = l - > point [ i ] . x ;
y2 = l - > point [ i ] . y ;
2005-10-30 19:45:37 +11:00
drawline ( dest , x , y , x2 , y2 , l - > col , l - > style ) ;
2005-10-25 16:35:55 +10:00
x = x2 ;
y = y2 ;
}
/* 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 ;
2005-10-30 19:45:37 +11:00
drawline ( dest , x , y , x2 , y2 , l - > col , l - > style ) ;
2005-10-25 16:35:55 +10:00
}
2005-10-30 19:45:37 +11:00
void drawobject ( SDL_Surface * dest , mapobject_t * o , int doublebuffer ) {
2005-10-25 16:35:55 +10:00
SDL_Surface * temps ;
SDL_Rect area ;
Uint32 bgcol ;
2005-10-27 14:46:38 +10:00
int testing = 0 ;
2005-10-25 16:35:55 +10:00
/* create temp surface */
2005-10-27 14:46:38 +10:00
if ( testing ) {
printf ( " About to create surface... " ) ;
fflush ( stdout ) ;
}
2005-10-30 19:45:37 +11:00
if ( doublebuffer ) {
temps = SDL_CreateRGBSurface ( SDL_SWSURFACE , o - > w + 3 , o - > h + 3 ,
screen - > format - > BitsPerPixel , screen - > format - > Rmask ,
screen - > format - > Gmask , screen - > format - > Bmask ,
screen - > format - > Amask ) ;
} else {
temps = dest ;
}
2005-10-25 16:35:55 +10:00
bgcol = SDL_MapRGB ( temps - > format , map [ curmap ] . bgcol . r , map [ curmap ] . bgcol . g , map [ curmap ] . bgcol . b ) ;
SDL_FillRect ( temps , NULL , bgcol ) ;
/* draw onto temp surface */
2005-10-27 14:46:38 +10:00
if ( testing ) {
printf ( " About to drawvector ... " ) ;
fflush ( stdout ) ;
}
2005-10-28 16:05:57 +10:00
if ( o - > fillcol . unused = = USECOLOUR ) {
drawvector ( temps , & objtype [ o - > type ] . vimg , 0 , 0 , o - > w , o - > h , NULL , & o - > fillcol ) ;
} else {
drawvector ( temps , & objtype [ o - > type ] . vimg , 0 , 0 , o - > w , o - > h , NULL , NULL ) ;
}
2005-10-25 16:35:55 +10:00
/* set transparent colour on temp surface */
2005-10-27 14:46:38 +10:00
if ( testing ) {
printf ( " About to setcolour ... " ) ;
fflush ( stdout ) ;
}
2005-10-25 16:35:55 +10:00
SDL_SetColorKey ( temps , SDL_SRCCOLORKEY | SDL_RLEACCEL , bgcol ) ;
/* blit to screen */
2005-10-30 19:45:37 +11:00
if ( doublebuffer ) {
area . x = o - > x ;
area . y = o - > y ;
area . w = o - > w ;
area . h = o - > h ;
if ( testing ) {
printf ( " About to blitsurface ... " ) ;
fflush ( stdout ) ;
}
SDL_BlitSurface ( temps , 0 , dest , & area ) ;
} else {
SDL_UpdateRect ( temps , 0 , 0 , o - > w , o - > h ) ;
2005-10-27 14:46:38 +10:00
}
2005-10-25 16:35:55 +10:00
2005-10-27 14:46:38 +10:00
if ( testing ) {
printf ( " About to return ... " ) ;
fflush ( stdout ) ;
}
2005-10-25 16:35:55 +10:00
}
void drawpixel ( SDL_Surface * screen , int x , int y , SDL_Color c ) {
Uint32 color = SDL_MapRGB ( screen - > format , c . r , c . g , c . b ) ;
/*if ( SDL_MUSTLOCK(screen) ) {
if ( SDL_LockSurface ( screen ) < 0 ) {
return ;
}
} */
switch ( screen - > format - > BytesPerPixel ) {
case 1 : { /* Assuming 8-bpp */
Uint8 * bufp ;
bufp = ( Uint8 * ) screen - > pixels + y * screen - > pitch + x ;
* bufp = color ;
}
break ;
case 2 : { /* Probably 15-bpp or 16-bpp */
Uint16 * bufp ;
bufp = ( Uint16 * ) screen - > pixels + y * screen - > pitch / 2 + x ;
* bufp = color ;
}
break ;
case 3 : { /* Slow 24-bpp mode, usually not used */
Uint8 * bufp ;
bufp = ( Uint8 * ) screen - > pixels + y * screen - > pitch + x * 3 ;
if ( SDL_BYTEORDER = = SDL_LIL_ENDIAN ) {
bufp [ 0 ] = color ;
bufp [ 1 ] = color > > 8 ;
bufp [ 2 ] = color > > 16 ;
} else {
bufp [ 2 ] = color ;
bufp [ 1 ] = color > > 8 ;
bufp [ 0 ] = color > > 16 ;
}
}
break ;
case 4 : { /* Probably 32-bpp */
Uint32 * bufp ;
bufp = ( Uint32 * ) screen - > pixels + y * screen - > pitch / 4 + x ;
* bufp = color ;
}
break ;
}
/*
if ( SDL_MUSTLOCK ( screen ) ) {
SDL_UnlockSurface ( screen ) ;
}
*/
//SDL_UpdateRect(screen, x, y, 1, 1);
}
void drawmap ( void ) {
int i ;
int testing = 0 ;
SDL_Rect area ;
Uint32 fillcol ;
int txoff , tyoff ;
int anchoreditem ;
2005-10-27 14:46:38 +10:00
2005-10-25 16:35:55 +10:00
if ( ( state = = S_SAVING ) | | ( state = = S_LOADING ) | | ( state = = S_MAPNAMING ) ) {
/* show file dialog */
showfiledialog ( ) ;
return ;
}
2005-10-28 16:05:57 +10:00
if ( ( state = = S_FGCOL ) | | ( state = = S_FILLCOL ) ) {
2005-10-25 16:35:55 +10:00
drawcolorchart ( screen ) ;
return ;
}
if ( state = = S_CREATETELE ) {
drawmaplist ( screen ) ;
return ;
}
if ( state = = S_REALLYQUIT ) {
drawyn ( text ) ;
return ;
}
2005-10-27 14:46:38 +10:00
if ( testing ) {
printf ( " START DRAWMAP \n " ) ; fflush ( stdout ) ;
}
2005-10-25 16:35:55 +10:00
/* clear map */
fillcol = SDL_MapRGB ( buffer - > format , map [ curmap ] . bgcol . r , map [ curmap ] . bgcol . g , map [ curmap ] . bgcol . b ) ;
SDL_FillRect ( buffer , NULL , fillcol ) ;
2005-10-27 14:46:38 +10:00
if ( testing ) {
printf ( " DRAWING THINGS \n " ) ; fflush ( stdout ) ;
}
/* draw all map[curmap].objects links etc*/
2005-10-25 16:35:55 +10:00
for ( i = 0 ; i < map [ curmap ] . numthings ; i + + ) {
if ( map [ curmap ] . thing [ i ] . type = = T_OBJECT ) {
2005-10-27 14:46:38 +10:00
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 ) ; }
2005-10-30 19:45:37 +11:00
drawobject ( buffer , & map [ curmap ] . obj [ map [ curmap ] . thing [ i ] . id ] , TRUE ) ;
2005-10-25 16:35:55 +10:00
} else if ( map [ curmap ] . thing [ i ] . type = = T_LINK ) {
2005-10-27 14:46:38 +10:00
if ( testing ) { printf ( " Drawing thing #%d (%d, link) \n " , i , map [ curmap ] . thing [ i ] . id ) ; fflush ( stdout ) ; }
2005-10-25 16:35:55 +10:00
drawlink ( buffer , & map [ curmap ] . olink [ map [ curmap ] . thing [ i ] . id ] ) ;
} else if ( map [ curmap ] . thing [ i ] . type = = T_TEXT ) {
2005-10-27 14:46:38 +10:00
if ( testing ) { printf ( " Drawing thing #%d (%d, text) \n " , i , map [ curmap ] . thing [ i ] . id ) ; fflush ( stdout ) ; }
2005-10-25 16:35:55 +10:00
drawtext ( buffer , & map [ curmap ] . textob [ map [ curmap ] . thing [ i ] . id ] ) ;
} else {
printf ( " WARNING: Thing #%d has unknown type %d! \n " , i , map [ curmap ] . thing [ i ] . type ) ;
}
}
2005-10-27 14:46:38 +10:00
if ( testing ) {
printf ( " FINISHED THINGS \n " ) ; fflush ( stdout ) ;
}
if ( testing ) {
printf ( " DRAWING HIGHLIGHT \n " ) ; fflush ( stdout ) ;
}
2005-10-25 16:35:55 +10:00
2005-10-27 14:46:38 +10:00
/* highlight the selected map[curmap].object */
2005-10-25 16:35:55 +10:00
/* by drawing boxes in its corners */
if ( map [ curmap ] . selecteditem ! = - 1 ) {
if ( map [ curmap ] . selecteditemtype = = T_OBJECT ) {
2005-10-27 17:00:32 +10:00
int n ;
2005-10-25 16:35:55 +10:00
/* 10% of map[curmap].object's size */
area . w = map [ curmap ] . obj [ map [ curmap ] . selecteditem ] . w / OBJSELHANDLEPCT ;
area . h = map [ curmap ] . obj [ map [ curmap ] . selecteditem ] . h / OBJSELHANDLEPCT ;
if ( area . w < 2 ) area . w = 2 ;
if ( area . h < 2 ) area . h = 2 ;
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 ;
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 ;
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 ;
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 ;
SDL_FillRect ( buffer , & area , fillcol ) ;
2005-10-27 17:00:32 +10:00
/* Also highlight any text anchored to this object */
for ( n = 0 ; n < map [ curmap ] . numtext ; n + + ) {
if ( map [ curmap ] . textob [ n ] . anchor = = map [ curmap ] . selecteditem ) {
int th ;
/* calculate text's height */
th = TTF_FontHeight ( font [ map [ curmap ] . textob [ n ] . h ] ) ;
/* 10% of text's size */
area . w = map [ curmap ] . textob [ n ] . w / OBJSELHANDLEPCT ;
area . h = th / OBJSELHANDLEPCT ;
if ( area . w < 2 ) area . w = 2 ;
if ( area . h < 2 ) area . h = 2 ;
anchoreditem = map [ curmap ] . textob [ n ] . anchor ;
if ( anchoreditem = = - 1 ) {
txoff = 0 ;
tyoff = 0 ;
} else {
txoff = map [ curmap ] . obj [ anchoreditem ] . x ;
tyoff = map [ curmap ] . obj [ anchoreditem ] . y ;
}
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 ;
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 ;
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 ;
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 ;
SDL_FillRect ( buffer , & area , fillcol ) ;
}
}
2005-10-25 16:35:55 +10:00
} else if ( map [ curmap ] . selecteditemtype = = T_TEXT ) {
2005-10-27 17:00:32 +10:00
int th ;
/* calculate text's height */
th = TTF_FontHeight ( font [ map [ curmap ] . textob [ map [ curmap ] . selecteditem ] . h ] ) ;
2005-10-25 16:35:55 +10:00
/* 10% of text's size */
area . w = map [ curmap ] . textob [ map [ curmap ] . selecteditem ] . w / OBJSELHANDLEPCT ;
2005-10-27 17:00:32 +10:00
area . h = th / OBJSELHANDLEPCT ;
2005-10-25 16:35:55 +10:00
if ( area . w < 2 ) area . w = 2 ;
if ( area . h < 2 ) area . h = 2 ;
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 ;
}
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 ;
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 ;
SDL_FillRect ( buffer , & area , fillcol ) ;
/* bottom left */
2005-10-27 17:00:32 +10:00
area . x = map [ curmap ] . textob [ map [ curmap ] . selecteditem ] . x + txoff ; area . y = map [ curmap ] . textob [ map [ curmap ] . selecteditem ] . y + tyoff + th - area . h ;
2005-10-25 16:35:55 +10:00
SDL_FillRect ( buffer , & area , fillcol ) ;
/* bottom right */
2005-10-27 17:00:32 +10:00
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 ;
2005-10-25 16:35:55 +10:00
SDL_FillRect ( buffer , & area , fillcol ) ;
/* if this text is anchored, highlight the map[curmap].object which it is anchored to */
if ( anchoreditem ! = - 1 ) {
area . w = map [ curmap ] . obj [ anchoreditem ] . w / OBJSELHANDLEPCT ;
area . h = map [ curmap ] . obj [ anchoreditem ] . h / OBJSELHANDLEPCT ;
if ( area . w < 2 ) area . w = 2 ;
if ( area . h < 2 ) area . h = 2 ;
fillcol = SDL_MapRGB ( buffer - > format , 0 , 255 , 0 ) ;
/* top left */
area . x = map [ curmap ] . obj [ anchoreditem ] . x ; area . y = map [ curmap ] . obj [ anchoreditem ] . y ;
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 ;
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 ;
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 ;
SDL_FillRect ( buffer , & area , fillcol ) ;
}
2005-10-27 17:00:32 +10:00
2005-10-25 16:35:55 +10:00
} else if ( map [ curmap ] . selecteditemtype = = T_LINK ) {
/* 10% of map[curmap].object's size */
area . w = LINESELHANDLESIZE ;
area . h = LINESELHANDLESIZE ;
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 ) ;
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 ) ;
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 ) ;
SDL_FillRect ( buffer , & area , fillcol ) ;
}
} else if ( map [ curmap ] . selecteditemtype = = T_LINKPOINT ) {
/* highlight the line in green */
/* 10% of map[curmap].object's size */
area . w = LINESELHANDLESIZE ;
area . h = LINESELHANDLESIZE ;
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 ) ;
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 ) ;
SDL_FillRect ( buffer , & area , fillcol ) ;
/* points on the line */
for ( i = 0 ; i < map [ curmap ] . olink [ map [ curmap ] . selecteditem ] . npoints ; i + + ) {
if ( i = = map [ curmap ] . selectedlinkpoint ) {
fillcol = SDL_MapRGB ( buffer - > format , 0 , 0 , 0 ) ;
} 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 ) ;
SDL_FillRect ( buffer , & area , fillcol ) ;
}
}
}
/* blit buffer to screen */
SDL_BlitSurface ( buffer , 0 , screen , 0 ) ;
2005-10-27 14:46:38 +10:00
if ( testing ) {
printf ( " START MAPBOX \n " ) ; fflush ( stdout ) ;
}
2005-10-25 16:35:55 +10:00
drawmapbox ( ) ;
/* draw status bar */
2005-10-27 14:46:38 +10:00
if ( testing ) {
printf ( " START STATUSBAR \n " ) ; fflush ( stdout ) ;
}
2005-10-25 16:35:55 +10:00
drawstatusbar ( ) ;
2005-10-27 14:46:38 +10:00
if ( testing ) {
printf ( " FLIP \n " ) ; fflush ( stdout ) ;
}
2005-10-25 16:35:55 +10:00
/* flip */
SDL_UpdateRect ( screen , 0 , 0 , map [ curmap ] . width , map [ curmap ] . height ) ;
}
void drawstatusbar ( void ) {
//int x,y;
Uint32 col ;
SDL_Rect area ;
text_t temp ;
col = SDL_MapRGB ( screen - > format , map [ curmap ] . bgcol . r , map [ curmap ] . bgcol . g , map [ curmap ] . bgcol . b ) ;
area . x = 0 ;
area . y = map [ curmap ] . height ;
area . w = map [ curmap ] . width ;
area . h = map [ curmap ] . height + DEFTEXTH + 3 ;
SDL_FillRect ( screen , & area , col ) ;
2005-10-30 19:45:37 +11:00
drawline ( screen , 0 , map [ curmap ] . height , map [ curmap ] . width , map [ curmap ] . height , blue , 1 ) ;
2005-10-25 16:35:55 +10:00
/* strip newlines from text */
if ( statustext [ strlen ( statustext ) - 1 ] = = ' \n ' )
statustext [ strlen ( statustext ) - 1 ] = ' \0 ' ;
strcpy ( temp . text , statustext ) ;
temp . x = 2 ;
temp . y = map [ curmap ] . height + 2 ;
temp . w = strlen ( temp . text ) * DEFTEXTW ;
temp . h = DEFTEXTH ;
temp . c = black ;
temp . anchor = - 1 ;
drawtext ( screen , & temp ) ;
/* show modified status */
if ( modified ) {
2005-10-27 14:46:38 +10:00
int tw , th ;
temp . x = map [ curmap ] . width - 30 ;
2005-10-25 16:35:55 +10:00
temp . y = map [ curmap ] . height + 2 ;
2005-10-27 14:46:38 +10:00
temp . h = DEFTEXTH - 1 ;
/* calculate width */
TTF_SizeText ( font [ temp . h ] , " MOD " , & tw , & th ) ;
temp . w = tw ;
2005-10-25 16:35:55 +10:00
temp . c = blue ;
temp . anchor = - 1 ;
strcpy ( temp . text , " MOD " ) ;
2005-10-27 14:46:38 +10:00
drawbox ( screen , temp . x - 3 , temp . y - 1 , temp . x + tw + 1 , temp . y + th , blue ) ;
2005-10-25 16:35:55 +10:00
drawtext ( screen , & temp ) ;
}
2005-10-30 00:23:10 +10:00
/* show readonly status */
if ( readonly ) {
int tw , th ;
/* same place as 'mod' box, as in readonly mode map can't be modified */
temp . x = map [ curmap ] . width - 30 ;
temp . y = map [ curmap ] . height + 2 ;
temp . h = DEFTEXTH - 1 ;
TTF_SizeText ( font [ temp . h ] , " RO " , & tw , & th ) ;
temp . w = tw ;
temp . c = blue ;
temp . anchor = - 1 ;
strcpy ( temp . text , " RO " ) ;
drawbox ( screen , temp . x - 3 , temp . y - 1 , temp . x + tw + 1 , temp . y + th , blue ) ;
drawtext ( screen , & temp ) ;
}
2005-10-25 16:35:55 +10:00
SDL_UpdateRect ( screen , area . x , area . y , area . w , area . h ) ;
}
void drawmapbox ( void ) {
text_t temp ;
int x , y ;
int i ;
2005-10-27 14:46:38 +10:00
int lh = MAPBOXTEXTHEIGHT ;
2005-10-25 16:35:55 +10:00
int found ;
int n ;
Uint32 fillcol ;
SDL_Rect area ;
2005-10-27 14:46:38 +10:00
int tw , th ;
2005-10-25 16:35:55 +10:00
x = mapbox . x + 1 ;
y = mapbox . y + 1 ;
/* clear it */
area . x = mapbox . x ;
area . y = mapbox . y ;
area . w = screen - > w - mapbox . x ;
area . h = mapbox . height ;
fillcol = SDL_MapRGB ( screen - > format , 90 , 90 , 90 ) ;
SDL_FillRect ( screen , & area , fillcol ) ;
SDL_UpdateRect ( screen , area . x , area . y , area . w , area . h ) ;
/* box around edge */
drawbox ( screen , mapbox . x , mapbox . y , mapbox . x + mapbox . width - 2 , mapbox . y + mapbox . height , white ) ;
/* current map */
sprintf ( temp . text , map [ curmap ] . name ) ;
temp . x = x ;
temp . y = y ;
temp . h = lh ;
2005-10-27 14:46:38 +10:00
TTF_SizeText ( font [ lh ] , temp . text , & tw , & th ) ;
temp . w = tw ;
2005-10-25 16:35:55 +10:00
temp . anchor = - 1 ;
temp . c = white ;
drawtext ( screen , & temp ) ;
2005-10-27 14:46:38 +10:00
//y += DEFTEXTH;
y + = th ;
2005-10-25 16:35:55 +10:00
/* seperator line */
2005-10-30 19:45:37 +11:00
drawline ( screen , x , y , x + mapbox . width - 2 , y , white , 1 ) ;
2005-10-25 16:35:55 +10:00
y + + ;
/* show .. */
if ( numhistory > = 1 ) {
2005-10-31 13:20:14 +11:00
/* draw back arrow */
2005-10-30 19:45:37 +11:00
drawline ( screen , x + 5 , y + ( lh / 2 ) , x + mapbox . width - 15 , y + ( lh / 2 ) , white , 1 ) ;
drawline ( screen , x + 5 , y + ( lh / 2 ) , x + 15 , y + 1 , white , 1 ) ;
drawline ( screen , x + 5 , y + ( lh / 2 ) , x + 15 , y + ( lh - 1 ) , white , 1 ) ;
2005-10-25 16:35:55 +10:00
}
2005-10-27 14:46:38 +10:00
y + = th ;
2005-10-25 16:35:55 +10:00
/* children ... */
2005-10-31 13:20:14 +11:00
/* first generate list of children */
2005-10-25 16:35:55 +10:00
numchildren = 0 ;
2005-10-31 13:20:14 +11:00
2005-10-25 16:35:55 +10:00
for ( i = 0 ; i < map [ curmap ] . numobjects ; i + + ) {
if ( map [ curmap ] . obj [ i ] . child ! = - 1 ) {
/* make sure we haven't already drawn this name */
found = FALSE ;
for ( n = 0 ; n < numchildren ; n + + ) {
if ( children [ n ] = = map [ curmap ] . obj [ i ] . child ) {
found = TRUE ;
break ;
}
}
if ( ! found ) {
children [ numchildren ] = map [ curmap ] . obj [ i ] . child ;
numchildren + + ;
2005-10-31 13:20:14 +11:00
}
}
}
2005-10-25 16:35:55 +10:00
2005-10-31 13:20:14 +11:00
/* now draw all children, starting at mapbox.offset */
for ( i = mapbox . offset ; i < numchildren ; i + + ) {
if ( ( i = = mapbox . offset ) & & ( mapbox . offset > 0 ) ) {
/* replace this entry with an arrow */
children [ i ] = C_SCROLLUP ;
/* draw an up arrow */
TTF_SizeText ( font [ lh ] , " unused " , & tw , & th ) ;
drawline ( screen , x + ( mapbox . width / 2 ) - 3 , y + th - 4 ,
x + ( mapbox . width / 2 ) , y + th - 7 ,
white , 1 ) ;
drawline ( screen , x + ( mapbox . width / 2 ) + 3 , y + th - 4 ,
x + ( mapbox . width / 2 ) , y + th - 7 ,
white , 1 ) ;
} else {
/* get its name */
sprintf ( temp . text , " *Unknown* " ) ; /* default, shouldn't actually ever be used */
for ( n = 0 ; n < map [ curmap ] . numobjects ; n + + ) {
if ( map [ curmap ] . obj [ n ] . child = = children [ i ] ) {
sprintf ( temp . text , map [ map [ curmap ] . obj [ n ] . child ] . name ) ;
break ;
}
2005-10-25 16:35:55 +10:00
}
2005-10-31 13:20:14 +11:00
temp . x = x ;
temp . y = y ;
temp . h = lh ;
TTF_SizeText ( font [ lh ] , temp . text , & tw , & th ) ;
temp . w = tw ;
temp . anchor = - 1 ;
temp . c = white ;
if ( temp . y + temp . h > = ( mapbox . y + mapbox . height ) ) {
SDL_Rect ar ;
/* off the bottom of the page - replace previous item with an arrow */
printf ( " showing arrow \n " ) ; fflush ( stdout ) ;
y = y - th - 1 ; /* go back one line */
/* clear previous text */
ar . x = x ;
ar . y = y ;
ar . w = mapbox . width - 3 ;
ar . h = th ;
SDL_FillRect ( screen , & ar , fillcol ) ;
/* draw arrow */
drawline ( screen , x + ( mapbox . width / 2 ) - 3 , y + th - 7 ,
x + ( mapbox . width / 2 ) , y + th - 4 ,
white , 1 ) ;
drawline ( screen , x + ( mapbox . width / 2 ) + 3 , y + th - 7 ,
x + ( mapbox . width / 2 ) , y + th - 4 ,
white , 1 ) ;
children [ i - 1 ] = C_SCROLLDOWN ;
break ;
}
drawtext ( screen , & temp ) ;
2005-10-25 16:35:55 +10:00
}
2005-10-31 13:20:14 +11:00
y + = th ;
2005-10-25 16:35:55 +10:00
}
SDL_UpdateRect ( screen , mapbox . x , mapbox . y , screen - > w - mapbox . x , mapbox . height + 2 ) ;
//SDL_Flip(screen);
}
void drawmaplist ( SDL_Surface * dest ) {
int x , y ;
int i ;
text_t temp ;
Uint32 fillcol ;
SDL_Rect area ;
/* clear screen*/
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 ;
SDL_FillRect ( screen , & area , fillcol ) ;
x = 10 ;
y = 10 ;
strcpy ( temp . text , " Select map to link to: " ) ;
temp . x = x ;
temp . y = y ;
temp . w = strlen ( temp . text ) * ( DEFTEXTW * 2 ) ;
temp . h = DEFTEXTH * 2 ;
temp . c = black ;
temp . anchor = - 1 ;
drawtext ( dest , & temp ) ;
y = 50 ;
drawbox ( dest , x , y , map [ curmap ] . width - 1 , y + ( DEFTEXTH * 2 ) , blue ) ;
strcpy ( temp . text , " (none) " ) ;
temp . x = x + 1 ;
temp . y = y + 1 ;
temp . w = strlen ( temp . text ) * ( DEFTEXTW * 2 ) ;
temp . h = ( DEFTEXTH * 2 ) - 2 ;
temp . c = blue ;
temp . anchor = - 1 ;
drawtext ( dest , & temp ) ;
y + = ( DEFTEXTH * 2 ) ;
for ( i = 0 ; i < nummaps ; i + + ) {
drawbox ( dest , x , y , map [ curmap ] . width - 1 , y + ( DEFTEXTH * 2 ) , blue ) ;
strcpy ( temp . text , map [ i ] . name ) ;
temp . x = x + 1 ;
temp . y = y + 1 ;
temp . w = strlen ( temp . text ) * ( DEFTEXTW * 2 ) ;
temp . h = ( DEFTEXTH * 2 ) - 2 ;
temp . c = blue ;
temp . anchor = - 1 ;
drawtext ( dest , & temp ) ;
y + = ( DEFTEXTH * 2 ) ;
}
SDL_Flip ( screen ) ;
}
void drawobox ( void ) {
int x , y , i ;
SDL_Rect area ;
mapobject_t temp ;
Uint32 fillcol ;
SDL_Color outlinecol ;
2005-10-25 16:45:19 +10:00
int outlinepos ;
int fitx , fity , fit ;
2005-10-25 16:35:55 +10:00
fillcol = SDL_MapRGB ( screen - > format , obox . bgcol . r , obox . bgcol . g , obox . bgcol . b ) ;
area . x = obox . x ;
area . y = obox . y ;
area . w = obox . width ;
area . h = obox . height + 3 ;
SDL_FillRect ( screen , & area , fillcol ) ;
x = obox . x ;
y = obox . y ;
2005-10-25 16:45:19 +10:00
/* calculate how many items we can fit in the obox */
/* figure out how many objects we can fit in the box */
fitx = ( obox . width / obox . gridsize ) ;
fity = ( ( obox . height + 3 ) / obox . gridsize ) ;
fit = fitx * fity ;
for ( i = ( obox . pos * 3 ) ; i < numobjtypes ; i + + ) {
2005-10-25 16:35:55 +10:00
if ( ( x + obox . gridsize ) > = ( map [ curmap ] . width + SIDEBARW ) ) {
x = obox . x ;
if ( ( y + obox . gridsize ) > = ( map [ curmap ] . height ) ) {
break ;
}
y + = obox . gridsize ;
}
/* draw box */
outlinecol = obox . gridcol ;
2005-10-30 19:45:37 +11:00
drawline ( screen , x , y , x + obox . gridsize , y , outlinecol , 1 ) ; /* top */
drawline ( screen , x , y + obox . gridsize , x + obox . gridsize , y + obox . gridsize , outlinecol , 1 ) ; /* bottom */
drawline ( screen , x , y , x , y + obox . gridsize , outlinecol , 1 ) ; /* left */
drawline ( screen , x + obox . gridsize , y , x + obox . gridsize , y + obox . gridsize , outlinecol , 1 ) ; /* right */
2005-10-25 16:35:55 +10:00
/* fill it */
fillcol = SDL_MapRGB ( screen - > format , obox . gridbgcol . r , obox . gridbgcol . g , obox . gridbgcol . b ) ;
area . x = x + 1 ;
area . y = y + 1 ;
area . w = obox . gridsize - 1 ;
area . h = obox . gridsize - 1 ;
SDL_FillRect ( screen , & area , fillcol ) ;
/* draw map[curmap].object */
temp . type = i ;
temp . x = x + 1 ;
temp . y = y + 1 ;
temp . w = obox . gridsize - 2 ;
temp . h = obox . gridsize - 2 ;
2005-10-30 19:45:37 +11:00
drawobject ( screen , & temp , TRUE ) ;
2005-10-25 16:35:55 +10:00
//SDL_UpdateRect(screen, x, y, obox.gridsize+1,obox.gridsize+1);
x + = obox . gridsize ;
}
/* draw selector */
outlinecol = red ;
2005-10-25 16:45:19 +10:00
outlinepos = map [ curmap ] . selectedtype - ( obox . pos * 3 ) ;
2005-10-25 16:35:55 +10:00
2005-10-25 16:45:19 +10:00
if ( ( outlinepos > = 0 ) & & ( outlinepos < fit ) ) {
y = ( ( map [ curmap ] . selectedtype - ( obox . pos * 3 ) ) / obox . gridrowlen ) * obox . gridsize + obox . y ;
x = ( ( map [ curmap ] . selectedtype - ( obox . pos * 3 ) ) % obox . gridrowlen ) * obox . gridsize + obox . x ;
2005-10-30 19:45:37 +11:00
drawline ( screen , x , y , x + obox . gridsize , y , outlinecol , 1 ) ; /* top */
drawline ( screen , x , y + obox . gridsize , x + obox . gridsize , y + obox . gridsize , outlinecol , 1 ) ; /* bottom */
drawline ( screen , x , y , x , y + obox . gridsize , outlinecol , 1 ) ; /* left */
drawline ( screen , x + obox . gridsize , y , x + obox . gridsize , y + obox . gridsize , outlinecol , 1 ) ; /* right */
2005-10-25 16:45:19 +10:00
}
2005-10-25 16:35:55 +10:00
//SDL_UpdateRect(screen, x, y, obox.gridsize+1,obox.gridsize+1);
SDL_UpdateRect ( screen , obox . x , obox . y , obox . width - 1 , obox . height + 3 ) ;
}
void drawscreen ( void ) {
2005-10-30 00:23:10 +10:00
if ( readonly ) {
sprintf ( statustext , " Welcome to netmapr viewer v%s. " , VERSION ) ;
} else {
sprintf ( statustext , " Welcome to netmapr v%s. " , VERSION ) ;
}
2005-10-25 16:35:55 +10:00
drawmap ( ) ;
drawtoolbox ( ) ;
drawobox ( ) ;
}
void drawtext ( SDL_Surface * dest , text_t * t ) {
int tw , th ;
int txoff , tyoff ;
2005-10-27 14:46:38 +10:00
SDL_Rect area ;
SDL_Surface * ts ;
2005-10-25 16:35:55 +10:00
if ( strlen ( t - > text ) = = 0 ) {
return ;
}
/* calculate letter width, letter height */
tw = t - > w / strlen ( t - > text ) ;
//tw = DEFTEXTW;
th = t - > h ;
if ( t - > anchor = = - 1 ) {
txoff = 0 ;
tyoff = 0 ;
} else {
txoff = map [ curmap ] . obj [ t - > anchor ] . x ;
tyoff = map [ curmap ] . obj [ t - > anchor ] . y ;
}
2005-10-27 14:46:38 +10:00
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 ) ;
2005-10-25 16:35:55 +10:00
//printf("drawtext() of: '%s' (len %d)\n",t->text, strlen(t->text)); fflush(stdout);
2005-10-27 14:46:38 +10:00
/*
2005-10-25 16:35:55 +10:00
for ( i = 0 ; i < strlen ( t - > text ) ; i + + ) {
x = t - > x + ( i * tw ) + txoff ;
y = t - > y + tyoff ;
if ( drawletter ( dest , x , y , tw , th , t - > text [ i ] , t - > c ) ) {
if ( t - > text [ i ] ! = ' ' ) {
printf ( " INVALID letter: '%c' \n " , t - > text [ i ] ) ; fflush ( stdout ) ;
}
} else {
//printf("drawing letter: '%c' at %d,%d\n",t->text[i],x, t->y); fflush(stdout);
}
}
2005-10-27 14:46:38 +10:00
*/
2005-10-25 16:35:55 +10:00
}
void drawtoolbox ( void ) {
int x , y , i ;
SDL_Rect area ;
Uint32 fillcol ;
Uint32 bcol ;
int z ;
SDL_Color gridhigh = { 255 , 255 , 255 , 0 } ;
SDL_Color gridmiddle = { 90 , 90 , 90 , 0 } ;
SDL_Color gridlow = { 50 , 50 , 50 , 0 } ;
2005-11-05 14:22:50 +11:00
dontpaste = TRUE ;
2005-10-25 16:35:55 +10:00
fillcol = SDL_MapRGB ( screen - > format , toolbox . bgcol . r , toolbox . bgcol . g , toolbox . bgcol . b ) ;
area . x = toolbox . x ;
area . y = toolbox . y ;
area . w = toolbox . width ;
area . h = toolbox . height ;
SDL_FillRect ( screen , & area , fillcol ) ;
x = toolbox . x ;
y = toolbox . y ;
/* draw each button */
for ( i = 0 ; i < numbuttons ; i + + ) {
if ( ( x + toolbox . gridsize ) > = ( map [ curmap ] . width + SIDEBARW ) ) {
x = toolbox . x ;
y + = toolbox . gridsize + 3 ;
if ( ( y + toolbox . gridsize ) > = ( toolbox . height ) ) {
break ;
}
}
/* draw box */
2005-10-30 19:45:37 +11:00
drawline ( screen , x , y , x + toolbox . gridsize , y , gridhigh , 1 ) ; /* top */
drawline ( screen , x , y + 1 , x + toolbox . gridsize , y + 1 , gridhigh , 1 ) ; /* top */
2005-10-25 16:35:55 +10:00
2005-10-30 19:45:37 +11:00
drawline ( screen , x , y + toolbox . gridsize - 1 , x + toolbox . gridsize , y + toolbox . gridsize - 1 , gridlow , 1 ) ; /* bottom */
drawline ( screen , x , y + toolbox . gridsize , x + toolbox . gridsize , y + toolbox . gridsize , gridlow , 1 ) ; /* bottom */
2005-10-25 16:35:55 +10:00
2005-10-30 19:45:37 +11:00
drawline ( screen , x , y , x , y + toolbox . gridsize , gridhigh , 1 ) ; /* left */
drawline ( screen , x + 1 , y , x + 1 , y + toolbox . gridsize - 1 , gridhigh , 1 ) ; /* left */
2005-10-25 16:35:55 +10:00
2005-10-30 19:45:37 +11:00
drawline ( screen , x + toolbox . gridsize , y + 1 , x + toolbox . gridsize , y + toolbox . gridsize , gridlow , 1 ) ; /* right */
drawline ( screen , x + toolbox . gridsize - 1 , y + 1 , x + toolbox . gridsize - 1 , y + toolbox . gridsize , gridlow , 1 ) ; /* right */
2005-10-25 16:35:55 +10:00
for ( z = y + 2 ; z < y + toolbox . gridsize ; z + + ) {
2005-10-30 19:45:37 +11:00
drawline ( screen , x + 2 , z , x + toolbox . gridsize - 2 , z , gridmiddle , 1 ) ;
2005-10-25 16:35:55 +10:00
}
area . x = x + 2 ;
area . y = y + 2 ;
area . w = toolbox . gridsize - 4 ;
area . h = toolbox . gridsize - 4 ;
/* set transparent colour on temp surface */
bcol = SDL_MapRGB ( buffer - > format , 0 , 0 , 0 ) ;
/* blit button image onto button */
SDL_SetColorKey ( button [ i ] . img , SDL_SRCCOLORKEY | SDL_RLEACCEL , bcol ) ;
SDL_BlitSurface ( button [ i ] . img , 0 , screen , & area ) ;
/* special cases */
if ( i = = TB_FGCOL ) {
floodfill ( screen , area . x + 5 , area . y + 5 , fgcol ) ;
}
if ( i = = TB_FILLCOL ) {
2005-10-28 16:05:57 +10:00
if ( objfillcol . unused ! = NOCOLOUR ) {
floodfill ( screen , area . x + 5 , area . y + 5 , objfillcol ) ;
} else {
floodfill ( screen , area . x + 5 , area . y + 5 , black ) ;
2005-10-30 19:45:37 +11:00
drawline ( screen , area . x + ( area . w / 2 ) - 3 , area . y + ( area . h / 2 ) - 3 - 4 , area . x + ( area . w / 2 ) + 3 , area . y + ( area . h / 2 ) + 3 - 4 , white , 1 ) ;
drawline ( screen , area . x + ( area . w / 2 ) + 3 , area . y + ( area . h / 2 ) - 3 - 4 , area . x + ( area . w / 2 ) - 3 , area . y + ( area . h / 2 ) + 3 - 4 , white , 1 ) ;
2005-10-28 16:05:57 +10:00
}
2005-10-25 16:35:55 +10:00
}
2005-10-30 19:45:37 +11:00
if ( i = = TB_LINESTYLE ) {
int style ;
/* show line thickness */
style = defthickness ;
drawline ( screen , area . x + 5 , area . y + 5 - ( defthickness / 2 ) , area . x + area . w - 5 - defthickness , area . y + 5 - ( defthickness / 2 )
, white , style ) ;
/* show line style (dotted, dashed, etc)*/
style = ( defstyle < < 8 ) | 1 ;
//drawline(screen, area.x + 5,area.y+15,area.x + area.w - 5-defthickness, area.y+15 ,white,style);
drawline ( screen , area . x + 5 , area . y + 15 , area . x + area . w - 5 , area . y + 15 , white , style ) ;
/* show arrow style (start, end, none) */
style = ( defarrow < < 16 ) | 1 ;
drawline ( screen , area . x + 5 , area . y + 24 , area . x + area . w - 5 , area . y + 24 , white , style ) ;
}
2005-10-25 16:35:55 +10:00
SDL_UpdateRect ( screen , x , y , toolbox . gridsize + 3 , toolbox . gridsize + 3 ) ;
x + = toolbox . gridsize + 3 ;
}
/* draw selectors */
if ( state = = S_NONE ) drawtoolboxselector ( TB_POINTER ) ;
if ( state = = S_ADDOBJ ) drawtoolboxselector ( TB_ADDOBJ ) ;
if ( state = = S_ADDTEXT ) drawtoolboxselector ( TB_ADDTEXT ) ;
if ( state = = S_SAVING ) drawtoolboxselector ( TB_SAVE ) ;
if ( state = = S_LOADING ) drawtoolboxselector ( TB_LOAD ) ;
if ( state = = S_MATCHSIZE ) drawtoolboxselector ( TB_MATCHSIZE ) ;
if ( state = = S_MATCHX ) drawtoolboxselector ( TB_MATCHX ) ;
if ( state = = S_MATCHY ) drawtoolboxselector ( TB_MATCHY ) ;
if ( state = = S_CREATETELE ) drawtoolboxselector ( TB_CREATETELE ) ;
}
void drawtoolboxselector ( int buttonid ) {
SDL_Color outlinecol ;
int x , y ;
/* draw selector */
outlinecol = red ;
y = ( buttonid / toolbox . gridrowlen ) * ( toolbox . gridsize + 3 ) + toolbox . y ;
x = ( buttonid % toolbox . gridrowlen ) * ( toolbox . gridsize + 3 ) + toolbox . x ;
2005-10-30 19:45:37 +11:00
drawline ( screen , x , y , x + toolbox . gridsize , y , outlinecol , 1 ) ; /* top */
drawline ( screen , x , y + 1 , x + toolbox . gridsize , y + 1 , outlinecol , 1 ) ; /* top */
drawline ( screen , x , y + toolbox . gridsize , x + toolbox . gridsize , y + toolbox . gridsize , outlinecol , 1 ) ; /* bottom */
drawline ( screen , x , y + toolbox . gridsize - 1 , x + toolbox . gridsize , y + toolbox . gridsize - 1 , outlinecol , 1 ) ; /* bottom */
drawline ( screen , x , y , x , y + toolbox . gridsize , outlinecol , 1 ) ; /* left */
drawline ( screen , x + 1 , y , x + 1 , y + toolbox . gridsize , outlinecol , 1 ) ; /* left */
drawline ( screen , x + toolbox . gridsize , y , x + toolbox . gridsize , y + toolbox . gridsize , outlinecol , 1 ) ; /* right */
drawline ( screen , x + toolbox . gridsize - 1 , y , x + toolbox . gridsize - 1 , y + toolbox . gridsize , outlinecol , 1 ) ; /* right */
2005-10-25 16:35:55 +10:00
SDL_UpdateRect ( screen , x , y , toolbox . gridsize + 3 , toolbox . gridsize + 3 ) ;
}
2005-10-28 16:05:57 +10:00
void drawvector ( SDL_Surface * dest , vectorimg_t * vimg , int x , int y , int w , int h , SDL_Color * overridefg , SDL_Color * overridebg ) {
2005-10-25 16:35:55 +10:00
float xscale , yscale ;
int realx1 , realy1 ;
int realx2 , realy2 ;
int i ;
SDL_Color linecol , fillcol ;
xscale = ( float ) w / ( float ) vimg - > w ;
yscale = ( float ) h / ( float ) vimg - > h ;
for ( i = 0 ; i < vimg - > vnum ; i + + ) {
// select colour
if ( overridefg = = NULL ) {
if ( vimg - > vector [ i ] . c . unused = = 255 ) {
linecol = fgcol ;
} else {
linecol = vimg - > vector [ i ] . c ;
}
} else {
linecol = * overridefg ;
}
2005-10-28 16:05:57 +10:00
if ( overridebg = = NULL ) {
if ( vimg - > vector [ i ] . c . unused = = 255 ) {
/* used to display current colour in foreground/background buttons */
fillcol = objfillcol ;
} else {
fillcol = vimg - > vector [ i ] . c ;
}
2005-10-25 16:35:55 +10:00
} else {
2005-10-28 16:05:57 +10:00
fillcol = * overridebg ;
2005-10-25 16:35:55 +10:00
}
// scale the coords of this vector
realx1 = x + ( ( float ) vimg - > vector [ i ] . x1 * xscale ) ;
realy1 = y + ( ( float ) vimg - > vector [ i ] . y1 * yscale ) ;
realx2 = x + ( ( float ) vimg - > vector [ i ] . x2 * xscale ) ;
realy2 = y + ( ( float ) vimg - > vector [ i ] . y2 * yscale ) ;
// draw this vector
switch ( vimg - > vector [ i ] . type ) {
case VT_LINE :
2005-10-30 19:45:37 +11:00
drawline ( dest , realx1 , realy1 , realx2 , realy2 , linecol , 1 ) ;
2005-10-25 16:35:55 +10:00
break ;
case VT_BOX :
drawbox ( dest , realx1 , realy1 , realx2 , realy2 , linecol ) ;
break ;
case VT_FILL :
floodfill ( dest , realx1 , realy1 , fillcol ) ;
break ;
}
}
}
int endtext ( void ) {
SDL_Rect area ;
2005-10-27 14:46:38 +10:00
int tw , th ;
2005-10-25 16:35:55 +10:00
/* paste old background */
if ( bg ! = NULL ) {
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 ) ;
// free it
SDL_FreeSurface ( bg ) ;
}
if ( strlen ( text ) = = 0 ) {
2005-11-05 14:22:50 +11:00
sprintf ( statustext , " Text entry aborted. " ) ;
changestate ( S_NONE ) ;
drawmap ( ) ;
2005-10-25 16:35:55 +10:00
return TRUE ;
}
strcpy ( map [ curmap ] . textob [ map [ curmap ] . numtext ] . text , text ) ;
map [ curmap ] . textob [ map [ curmap ] . numtext ] . anchor = textanchor ;
if ( map [ curmap ] . textob [ map [ curmap ] . numtext ] . anchor = = - 1 ) {
/* x,y = normal (ie. offset from 0,0) */
map [ curmap ] . textob [ map [ curmap ] . numtext ] . x = startx ;
map [ curmap ] . textob [ map [ curmap ] . numtext ] . y = starty ;
} else {
/* x,y = offset from anchor map[curmap].object's coordinates */
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 ;
}
2005-10-27 14:46:38 +10:00
/* calculate width */
TTF_SizeText ( font [ DEFTEXTH ] , text , & tw , & th ) ;
map [ curmap ] . textob [ map [ curmap ] . numtext ] . w = tw ;
2005-10-25 16:35:55 +10:00
map [ curmap ] . textob [ map [ curmap ] . numtext ] . h = DEFTEXTH ;
map [ curmap ] . textob [ map [ curmap ] . numtext ] . c = fgcol ;
/* add to 'thing' list */
map [ curmap ] . thing [ map [ curmap ] . numthings ] . type = T_TEXT ;
map [ curmap ] . thing [ map [ curmap ] . numthings ] . id = map [ curmap ] . numtext ;
2005-11-05 14:22:50 +11:00
2005-10-25 16:35:55 +10:00
modified = TRUE ;
2005-11-05 14:22:50 +11:00
sprintf ( statustext , " Added text object #%d: '%s'. " , map [ curmap ] . numtext , map [ curmap ] . textob [ map [ curmap ] . numtext ] . text ) ;
2005-10-25 16:35:55 +10:00
drawstatusbar ( ) ;
map [ curmap ] . numtext + + ;
map [ curmap ] . numthings + + ;
changestate ( S_NONE ) ;
drawmap ( ) ;
return FALSE ;
}
2005-10-29 16:37:41 +10:00
int endtextedit ( void ) {
SDL_Rect area ;
int tw , th ;
int si ;
/* paste old background */
if ( bg ! = NULL ) {
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 ) ;
// free it
SDL_FreeSurface ( bg ) ;
}
if ( strlen ( text ) = = 0 ) {
return TRUE ;
}
si = map [ curmap ] . selecteditem ;
/* update text */
strcpy ( map [ curmap ] . textob [ si ] . text , text ) ;
/* anchor, x, y, height don't change */
//map[curmap].textob[si].anchor = textanchor;
//map[curmap].textob[si].x = startx;
//map[curmap].textob[si].y = starty;
/* calculate & update width */
TTF_SizeText ( font [ map [ curmap ] . textob [ si ] . h ] , text , & tw , & th ) ;
map [ curmap ] . textob [ si ] . w = tw ;
modified = TRUE ;
sprintf ( statustext , " Updated text object #%d to '%s' \n " , si , map [ curmap ] . textob [ si ] . text ) ;
drawstatusbar ( ) ;
changestate ( S_NONE ) ;
drawmap ( ) ;
return FALSE ;
}
2005-10-25 16:35:55 +10:00
int endtextmove ( int x , int y ) {
int txoff , tyoff ;
SDL_FreeSurface ( bg ) ;
if ( map [ curmap ] . textob [ map [ curmap ] . curtext ] . anchor = = - 1 ) {
txoff = 0 ;
tyoff = 0 ;
} else {
txoff = map [ curmap ] . obj [ map [ curmap ] . textob [ map [ curmap ] . curtext ] . anchor ] . x ;
tyoff = map [ curmap ] . obj [ map [ curmap ] . textob [ map [ curmap ] . curtext ] . anchor ] . y ;
}
/* check position */
if ( ( map [ curmap ] . textob [ map [ curmap ] . curtext ] . x + txoff + x - startx ) > = ( map [ curmap ] . width - map [ curmap ] . textob [ map [ curmap ] . curtext ] . w ) ) {
return - 1 ;
}
if ( ( map [ curmap ] . textob [ map [ curmap ] . curtext ] . y + tyoff + y - starty ) > = ( map [ curmap ] . height - map [ curmap ] . textob [ map [ curmap ] . curtext ] . h ) ) {
return - 1 ;
}
if ( map [ curmap ] . textob [ map [ curmap ] . curtext ] . x + txoff < = 0 ) {
return - 1 ;
}
if ( map [ curmap ] . textob [ map [ curmap ] . curtext ] . y + tyoff < = 0 ) {
return - 1 ;
}
map [ curmap ] . textob [ map [ curmap ] . curtext ] . x + = ( x - startx ) ;
map [ curmap ] . textob [ map [ curmap ] . curtext ] . y + = ( y - starty ) ;
modified = TRUE ;
return 0 ;
}
void floodfill ( SDL_Surface * dest , int x , int y , SDL_Color fillcol ) {
int testing ;
SDL_Color bgcolor ;
testing = 0 ;
//XXX: testing
if ( testing ) {
drawpixel ( dest , x , y , fillcol ) ;
} else {
getcolor ( dest , x , y , & bgcolor ) ;
if ( ( bgcolor . r = = fillcol . r ) & & ( bgcolor . g = = fillcol . g ) & & ( bgcolor . b = = fillcol . b ) ) {
return ;
}
floodfill4 ( dest , x , y , fillcol , bgcolor ) ;
}
}
void push ( int x , int y ) {
fillstack [ fillstackptr ] . x = x ;
fillstack [ fillstackptr ] . y = y ;
fillstackptr + + ;
}
void pop ( int * x , int * y ) {
fillstackptr - - ;
* x = fillstack [ fillstackptr ] . x ;
* y = fillstack [ fillstackptr ] . y ;
}
void floodfill4 ( SDL_Surface * dest , int x , int y , SDL_Color fillcol , SDL_Color bgcol ) {
SDL_Color curcolor ;
push ( x , y ) ;
while ( fillstackptr ! = 0 ) {
pop ( & x , & y ) ;
getcolor ( dest , x , y , & curcolor ) ;
if ( ( curcolor . r = = bgcol . r ) & & ( curcolor . g = = bgcol . g ) & & ( curcolor . b = = bgcol . b ) ) {
drawpixel ( dest , x , y , fillcol ) ;
}
if ( x > 0 ) {
getcolor ( dest , x - 1 , y , & curcolor ) ;
if ( ( curcolor . r = = bgcol . r ) & & ( curcolor . g = = bgcol . g ) & & ( curcolor . b = = bgcol . b ) ) {
push ( x - 1 , y ) ;
}
}
if ( y > 0 ) {
getcolor ( dest , x , y - 1 , & curcolor ) ;
if ( ( curcolor . r = = bgcol . r ) & & ( curcolor . g = = bgcol . g ) & & ( curcolor . b = = bgcol . b ) ) {
push ( x , y - 1 ) ;
}
}
if ( x < ( dest - > w - 1 ) ) {
getcolor ( dest , x + 1 , y , & curcolor ) ;
if ( ( curcolor . r = = bgcol . r ) & & ( curcolor . g = = bgcol . g ) & & ( curcolor . b = = bgcol . b ) ) {
push ( x + 1 , y ) ;
}
}
if ( y < ( dest - > h - 1 ) ) {
getcolor ( dest , x , y + 1 , & curcolor ) ;
if ( ( curcolor . r = = bgcol . r ) & & ( curcolor . g = = bgcol . g ) & & ( curcolor . b = = bgcol . b ) ) {
push ( x , y + 1 ) ;
}
}
}
}
2005-11-05 14:22:50 +11:00
int getmousepos ( int x , int y ) {
if ( isontoolbox ( x , y ) ) {
return MP_TOOLBOX ;
} else if ( isonmapbox ( x , y ) ) {
if ( isonmapname ( x , y ) ) {
return MP_MAPBOXNAME ;
} else {
return MP_MAPBOXCHILDREN ;
}
} else if ( isonobox ( x , y ) ) {
return MP_OBJECTBOX ;
}
return MP_NONE ;
}
2005-10-25 16:35:55 +10:00
int getcolor ( SDL_Surface * dest , int x , int y , SDL_Color * col ) {
Uint32 * pixel ;
int bpp ;
/* SHOULD ALWAYS BE 2!! */
bpp = dest - > format - > BytesPerPixel ;
if ( bpp ! = 2 ) {
printf ( " bpp isnt 2!!! \n " ) ;
fflush ( stdout ) ;
}
//pixel = (Uint32 *) (dest->pixels + (y * dest->w) + x) ;
pixel = ( Uint32 * ) ( dest - > pixels + y * dest - > pitch + x * bpp ) ;
SDL_GetRGB ( * pixel , dest - > format ,
& col - > r ,
& col - > g ,
& col - > b ) ;
return 0 ;
}
void drawyn ( char * prompt ) {
SDL_Rect area ;
text_t text ;
2005-10-27 14:46:38 +10:00
int promptsize = 40 ;
int yesnosize = 100 ;
int tw , th ;
2005-10-25 16:35:55 +10:00
/* clear map to red */
area . x = 0 ;
area . y = 0 ;
area . w = map [ curmap ] . width ;
area . h = map [ curmap ] . height - 1 ;
SDL_FillRect ( screen , & area , SDL_MapRGB ( screen - > format , 255 , 0 , 0 ) ) ;
drawbox ( screen , 0 , 200 , 399 , 500 , blue ) ;
drawbox ( screen , 400 , 200 , 799 , 500 , blue ) ;
2005-10-27 14:46:38 +10:00
TTF_SizeText ( font [ promptsize ] , prompt , & tw , & th ) ;
text . w = tw ;
text . h = promptsize ;
2005-10-25 16:35:55 +10:00
text . x = ( map [ curmap ] . width / 2 ) - ( text . w / 2 ) ;
text . y = 100 ;
text . anchor = - 1 ;
text . c = blue ;
strcpy ( text . text , prompt ) ;
drawtext ( screen , & text ) ;
/* draw yes & no */
2005-10-27 14:46:38 +10:00
text . h = yesnosize ;
TTF_SizeText ( font [ promptsize ] , " Yes " , & tw , & th ) ;
text . w = tw ;
text . x = ( ( map [ curmap ] . width - SIDEBARW ) / 4 ) - ( tw / 2 ) ;
2005-10-25 16:35:55 +10:00
text . y = 300 ;
text . anchor = - 1 ;
text . c = blue ;
strcpy ( text . text , " Yes " ) ;
drawtext ( screen , & text ) ;
2005-10-27 14:46:38 +10:00
text . h = yesnosize ;
TTF_SizeText ( font [ promptsize ] , " No " , & tw , & th ) ;
text . w = tw ;
text . x = ( ( ( map [ curmap ] . width - SIDEBARW ) / 4 ) * 3 ) - ( tw / 2 ) ;
2005-10-25 16:35:55 +10:00
text . y = 300 ;
text . anchor = - 1 ;
text . c = blue ;
strcpy ( text . text , " No " ) ;
drawtext ( screen , & text ) ;
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 ) ) {
return NO ;
}
return MAYBE ;
}
void goback ( void ) {
if ( numhistory > = 1 ) {
2005-10-30 22:50:06 +11:00
changemap ( history [ numhistory - 1 ] ) ;
2005-10-25 16:35:55 +10:00
numhistory - - ;
sprintf ( statustext , " Changed map to map #%d (%s). " , curmap , map [ curmap ] . name ) ;
drawmap ( ) ;
} else {
sprintf ( statustext , " Already at top level! " ) ;
drawstatusbar ( ) ;
}
}
int linelen ( int x1 , int y1 , int x2 , int y2 ) {
int deltax , deltay ;
int numpixels ;
int d ;
int dinc1 , dinc2 , xinc1 , xinc2 , yinc1 , yinc2 ;
deltax = ( x2 - x1 ) ;
if ( deltax < 0 ) deltax = - deltax ;
deltay = ( y2 - y1 ) ;
if ( deltay < 0 ) deltay = - deltay ;
if ( deltax > = deltay ) {
numpixels = deltax + 1 ;
d = ( deltay * 2 ) - deltax ;
dinc1 = deltay < < 1 ;
dinc2 = ( deltay - deltax ) < < 1 ;
xinc1 = 1 ;
xinc2 = 1 ;
yinc1 = 0 ;
yinc2 = 1 ;
} else {
numpixels = deltay + 1 ;
d = ( deltax * 2 ) - deltay ;
dinc1 = deltax < < 1 ;
dinc2 = ( deltax - deltay ) < < 1 ;
xinc1 = 0 ;
xinc2 = 1 ;
yinc1 = 1 ;
yinc2 = 1 ;
}
return numpixels ;
}
int linkat ( int x , int y ) {
int i ;
for ( i = 0 ; i < map [ curmap ] . numlinks ; i + + ) {
/* is (x,y) on the line? */
if ( isonlink ( i , x , y ) ) return i ;
}
return - 1 ;
}
2005-10-25 16:45:19 +10:00
2005-10-25 16:35:55 +10:00
int loadmap ( void ) {
char filename [ BUFLEN ] ;
FILE * f ;
int namelen ;
2005-10-28 16:05:57 +10:00
int i , n ;
char vers [ 8 ] , * p ;
mapobject099a_t tempmapobjects [ MAXOBJECTS ] ;
2005-10-25 16:35:55 +10:00
/* TODO: validate */
strcpy ( filename , text ) ;
sprintf ( statustext , " Loading map... \n " ) ;
drawstatusbar ( ) ;
f = fopen ( filename , " rb " ) ;
if ( ! f ) {
sprintf ( statustext , " ERROR: Cannot open '%s'. \n " , filename ) ;
return TRUE ;
}
/* TODO: free() variables! */
2005-10-28 16:05:57 +10:00
/* TODO: read version string */
fread ( & vers , 8 , 1 , f ) ;
/* if no version string, then this is an old version */
if ( vers [ 0 ] ! = ' V ' ) {
strcpy ( vers , " OLD " ) ;
/* go back to start of file */
fseek ( f , 0 , SEEK_SET ) ;
} else {
/* if we found a version string, remove trailling spaces */
for ( p = vers ; * p ! = ' \0 ' ; p + + ) {
if ( * p = = ' ' ) {
* p = ' \0 ' ;
break ;
}
}
}
2005-10-30 00:23:10 +10:00
if ( ! strcmp ( vers , " OLD " ) ) {
/* old versions without version string */
/* 0.99a didn't have the fillcol field in mapobject_t */
2005-10-25 16:35:55 +10:00
2005-10-28 16:05:57 +10:00
/* read in number maps */
fread ( & nummaps , sizeof ( int ) , 1 , f ) ;
for ( i = 0 ; i < nummaps ; i + + ) {
fread ( & map [ i ] . width , sizeof ( int ) , 1 , f ) ;
fread ( & map [ i ] . height , sizeof ( int ) , 1 , f ) ;
fread ( & map [ i ] . bpp , sizeof ( int ) , 1 , f ) ;
fread ( & map [ i ] . bgcol , sizeof ( SDL_Color ) , 1 , f ) ;
fread ( & map [ i ] . boxcol , sizeof ( SDL_Color ) , 1 , f ) ;
fread ( & map [ i ] . numthings , sizeof ( int ) , 1 , f ) ;
fread ( & map [ i ] . numobjects , sizeof ( int ) , 1 , f ) ;
fread ( & map [ i ] . numlinks , sizeof ( int ) , 1 , f ) ;
fread ( & map [ i ] . numtext , sizeof ( int ) , 1 , f ) ;
map [ i ] . selecteditem = - 1 ;
map [ i ] . selecteditemtype = - 1 ;
map [ i ] . selectedlinkpoint = - 1 ;
map [ i ] . selectedtype = 0 ;
map [ i ] . curobj = - 1 ;
map [ i ] . curlink = - 1 ;
map [ i ] . curlinkpoint = - 1 ;
map [ i ] . curtext = - 1 ;
map [ i ] . startx = - 1 ;
map [ i ] . starty = - 1 ;
map [ i ] . textanchor = - 1 ;
strcpy ( map [ i ] . text , " " ) ;
fread ( & namelen , sizeof ( int ) , 1 , f ) ;
fread ( & map [ i ] . name , ( namelen + 1 ) * sizeof ( char ) , 1 , f ) ;
/* read objects */
fread ( & map [ i ] . thing , sizeof ( thing_t ) , map [ i ] . numthings , f ) ;
fread ( & map [ i ] . olink , sizeof ( link_t ) , map [ i ] . numlinks , f ) ;
2005-10-30 00:23:10 +10:00
/* read into temp area, then copy to real structure */
fread ( & tempmapobjects , sizeof ( mapobject099a_t ) , map [ i ] . numobjects , f ) ;
for ( n = 0 ; n < map [ i ] . numobjects ; n + + ) {
map [ i ] . obj [ n ] . type = tempmapobjects [ n ] . type ;
map [ i ] . obj [ n ] . x = tempmapobjects [ n ] . x ;
map [ i ] . obj [ n ] . y = tempmapobjects [ n ] . y ;
map [ i ] . obj [ n ] . w = tempmapobjects [ n ] . w ;
map [ i ] . obj [ n ] . h = tempmapobjects [ n ] . h ;
map [ i ] . obj [ n ] . child = tempmapobjects [ n ] . child ;
map [ i ] . obj [ n ] . fillcol = black ;
map [ i ] . obj [ n ] . fillcol . unused = NOCOLOUR ;
}
2005-10-28 16:05:57 +10:00
fread ( & map [ i ] . textob , sizeof ( text_t ) , map [ i ] . numtext , f ) ;
}
2005-10-30 00:23:10 +10:00
} else {
2005-10-28 16:05:57 +10:00
/* read in number maps */
fread ( & nummaps , sizeof ( int ) , 1 , f ) ;
for ( i = 0 ; i < nummaps ; i + + ) {
fread ( & map [ i ] . width , sizeof ( int ) , 1 , f ) ;
fread ( & map [ i ] . height , sizeof ( int ) , 1 , f ) ;
fread ( & map [ i ] . bpp , sizeof ( int ) , 1 , f ) ;
fread ( & map [ i ] . bgcol , sizeof ( SDL_Color ) , 1 , f ) ;
fread ( & map [ i ] . boxcol , sizeof ( SDL_Color ) , 1 , f ) ;
fread ( & map [ i ] . numthings , sizeof ( int ) , 1 , f ) ;
fread ( & map [ i ] . numobjects , sizeof ( int ) , 1 , f ) ;
fread ( & map [ i ] . numlinks , sizeof ( int ) , 1 , f ) ;
fread ( & map [ i ] . numtext , sizeof ( int ) , 1 , f ) ;
map [ i ] . selecteditem = - 1 ;
map [ i ] . selecteditemtype = - 1 ;
map [ i ] . selectedlinkpoint = - 1 ;
map [ i ] . selectedtype = 0 ;
map [ i ] . curobj = - 1 ;
map [ i ] . curlink = - 1 ;
map [ i ] . curlinkpoint = - 1 ;
map [ i ] . curtext = - 1 ;
map [ i ] . startx = - 1 ;
map [ i ] . starty = - 1 ;
map [ i ] . textanchor = - 1 ;
strcpy ( map [ i ] . text , " " ) ;
fread ( & namelen , sizeof ( int ) , 1 , f ) ;
fread ( & map [ i ] . name , ( namelen + 1 ) * sizeof ( char ) , 1 , f ) ;
/* read objects */
fread ( & map [ i ] . thing , sizeof ( thing_t ) , map [ i ] . numthings , f ) ;
fread ( & map [ i ] . olink , sizeof ( link_t ) , map [ i ] . numlinks , f ) ;
2005-10-30 00:23:10 +10:00
fread ( & map [ i ] . obj , sizeof ( mapobject_t ) , map [ i ] . numobjects , f ) ;
2005-10-28 16:05:57 +10:00
fread ( & map [ i ] . textob , sizeof ( text_t ) , map [ i ] . numtext , f ) ;
}
2005-10-25 16:35:55 +10:00
}
fclose ( f ) ;
2005-10-30 19:45:37 +11:00
/* do some fixes for common issues (whether due to old map versions or not) */
for ( i = 0 ; i < nummaps ; i + + ) {
for ( n = 0 ; n < map [ i ] . numlinks ; n + + ) {
/* old maps have line thickness = 0, change this to 1 */
if ( map [ i ] . olink [ n ] . style = = 0 ) {
map [ i ] . olink [ n ] . style = 1 ;
}
}
}
2005-10-25 16:35:55 +10:00
curmap = 0 ;
modified = FALSE ;
2005-10-28 16:05:57 +10:00
sprintf ( statustext , " Successfully loaded map from '%s' (%d maps). [file version: '%s'] \n " , filename , nummaps , vers ) ;
2005-10-25 16:35:55 +10:00
strcpy ( currentfilename , filename ) ;
drawmap ( ) ;
return FALSE ;
}
void lowerselected ( void ) {
int i ;
int temptype , tempid ;
int target ;
/* find map[curmap].object */
for ( i = 0 ; i < map [ curmap ] . numthings ; i + + ) {
if ( ( map [ curmap ] . thing [ i ] . id = = map [ curmap ] . selecteditem ) & & ( map [ curmap ] . thing [ i ] . type = = map [ curmap ] . selecteditemtype ) ) {
/* swap with one below */
if ( i = = 0 ) {
break ;
} else {
target = i - 1 ;
}
tempid = map [ curmap ] . thing [ target ] . id ;
temptype = map [ curmap ] . thing [ target ] . type ;
map [ curmap ] . thing [ target ] . id = map [ curmap ] . thing [ i ] . id ;
map [ curmap ] . thing [ target ] . type = map [ curmap ] . thing [ i ] . type ;
map [ curmap ] . thing [ i ] . id = tempid ;
map [ curmap ] . thing [ i ] . type = temptype ;
break ;
}
}
modified = TRUE ;
/* redraw map */
drawmap ( ) ;
}
int objat ( int x , int y ) {
int i ;
for ( i = 0 ; i < map [ curmap ] . numobjects ; i + + ) {
if ( ( x > = map [ curmap ] . obj [ i ] . x ) & & ( x < = ( map [ curmap ] . obj [ i ] . x + map [ curmap ] . obj [ i ] . w ) ) & &
( y > = map [ curmap ] . obj [ i ] . y ) & & ( y < = ( map [ curmap ] . obj [ i ] . y + map [ curmap ] . obj [ i ] . h ) ) ) {
return i ;
}
}
return - 1 ;
}
void pasteline ( SDL_Surface * screen , int * lbuf ) {
int deltax , deltay ;
int numpixels ;
int d ;
int dinc1 , dinc2 , xinc1 , xinc2 , yinc1 , yinc2 ;
int i ;
int x ;
int y ;
SDL_Color bgcol ;
int x1 , y1 , x2 , y2 ;
int tlx , tly , w , h ;
x1 = lbuf [ 0 ] ;
y1 = lbuf [ 1 ] ;
x2 = lbuf [ 2 ] ;
y2 = lbuf [ 3 ] ;
deltax = ( x2 - x1 ) ;
if ( deltax < 0 ) deltax = - deltax ;
deltay = ( y2 - y1 ) ;
if ( deltay < 0 ) deltay = - deltay ;
if ( deltax > = deltay ) {
numpixels = deltax + 1 ;
d = ( deltay * 2 ) - deltax ;
dinc1 = deltay < < 1 ;
dinc2 = ( deltay - deltax ) < < 1 ;
xinc1 = 1 ;
xinc2 = 1 ;
yinc1 = 0 ;
yinc2 = 1 ;
} else {
numpixels = deltay + 1 ;
d = ( deltax * 2 ) - deltay ;
dinc1 = deltax < < 1 ;
dinc2 = ( deltax - deltay ) < < 1 ;
xinc1 = 0 ;
xinc2 = 1 ;
yinc1 = 1 ;
yinc2 = 1 ;
}
if ( x1 > x2 ) {
xinc1 = - xinc1 ;
xinc2 = - xinc2 ;
}
if ( y1 > y2 ) {
yinc1 = - yinc1 ;
yinc2 = - yinc2 ;
}
x = x1 ; y = y1 ;
for ( i = 0 ; i < numpixels ; i + + ) {
SDL_GetRGB ( lbuf [ i + 4 ] , screen - > format ,
& bgcol . r ,
& bgcol . g ,
& bgcol . b ) ;
drawpixel ( screen , x , y , bgcol ) ;
if ( d < 0 ) {
d + = dinc1 ;
x + = xinc1 ;
y + = yinc1 ;
} else {
d + = dinc2 ;
x + = xinc2 ;
y + = yinc2 ;
}
}
/* update screen */
x1 = lbuf [ 0 ] ;
y1 = lbuf [ 1 ] ;
x2 = lbuf [ 2 ] ;
y2 = lbuf [ 3 ] ;
if ( x2 < x1 ) {
if ( y2 < y1 ) {
tlx = x2 ;
tly = y2 ;
w = x1 - x2 ;
h = y1 - y2 ;
} else {
tlx = x2 ;
tly = y1 ;
w = x1 - x2 ;
h = y2 - y1 ;
}
} else {
if ( y2 < y1 ) {
tlx = x1 ;
tly = y2 ;
w = x2 - x1 ;
h = y1 - y2 ;
} else {
tlx = x1 ;
tly = y1 ;
w = x2 - x1 ;
h = y2 - y1 ;
}
}
SDL_UpdateRect ( screen , tlx , tly , w , h ) ;
}
int initgraphics ( void ) {
FILE * f ;
char * p ;
int line ;
int state ;
int n ;
vectorimg_t tempv ;
char buf [ BUFLEN ] ;
int x , y ;
Uint8 data [ 32 ] ;
Uint8 mask [ 32 ] ;
int i ;
char verstring [ BUFLEN ] ;
char file [ BUFLEN ] ;
2005-11-05 14:22:50 +11:00
Uint32 fillcol ;
SDL_Rect area ;
2005-10-25 16:35:55 +10:00
int x1 , x2 , y1 , y2 ;
SDL_Color c ;
2005-10-25 16:45:19 +10:00
if ( SDL_Init ( SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE ) = = - 1 ) {
2005-10-25 16:35:55 +10:00
printf ( " SDL_Init: %s \n " , SDL_GetError ( ) ) ;
exit ( 1 ) ;
}
2005-10-28 16:05:57 +10:00
2005-10-25 16:35:55 +10:00
initvars ( ) ;
2005-11-05 14:22:50 +11:00
2005-10-28 16:05:57 +10:00
/* set up icon */
sprintf ( file , " icon.bmp " ) ;
2005-10-30 22:50:06 +11:00
icon = SDL_LoadBMP ( file ) ;
if ( ! icon ) {
sprintf ( file , " /usr/local/share/netmapr/icon.bmp " ) ;
icon = SDL_LoadBMP ( file ) ;
}
if ( ! icon ) {
sprintf ( file , " %s/icon.bmp " , progdir ) ;
icon = SDL_LoadBMP ( file ) ;
}
2005-10-28 16:05:57 +10:00
2005-10-30 22:50:06 +11:00
if ( ! icon ) {
printf ( " Error opening icon.bmp: %s \n " , TTF_GetError ( ) ) ;
exit ( 1 ) ;
2005-10-28 16:05:57 +10:00
}
SDL_WM_SetIcon ( icon , NULL ) ;
2005-10-27 14:46:38 +10:00
/* 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 ) ;
2005-10-30 19:45:37 +11:00
/* initialise line styles */
linemask [ LS_SOLID ] [ 0 ] = 1 ;
linemask [ LS_SOLID ] [ 1 ] = - 1 ;
linemask [ LS_DOTTED ] [ 0 ] = 1 ;
linemask [ LS_DOTTED ] [ 1 ] = 0 ;
linemask [ LS_DOTTED ] [ 2 ] = - 1 ;
linemask [ LS_BIGDASH ] [ 0 ] = 1 ;
linemask [ LS_BIGDASH ] [ 1 ] = 1 ;
linemask [ LS_BIGDASH ] [ 2 ] = 1 ;
linemask [ LS_BIGDASH ] [ 3 ] = 0 ;
linemask [ LS_BIGDASH ] [ 4 ] = 0 ;
linemask [ LS_BIGDASH ] [ 5 ] = 0 ;
linemask [ LS_BIGDASH ] [ 6 ] = - 1 ;
linemask [ LS_DASHDOT ] [ 0 ] = 1 ;
linemask [ LS_DASHDOT ] [ 1 ] = 1 ;
linemask [ LS_DASHDOT ] [ 2 ] = 0 ;
linemask [ LS_DASHDOT ] [ 3 ] = 0 ;
linemask [ LS_DASHDOT ] [ 4 ] = 0 ;
linemask [ LS_DASHDOT ] [ 5 ] = 1 ;
linemask [ LS_DASHDOT ] [ 6 ] = 0 ;
linemask [ LS_DASHDOT ] [ 7 ] = 0 ;
linemask [ LS_DASHDOT ] [ 8 ] = 0 ;
linemask [ LS_DASHDOT ] [ 9 ] = - 1 ;
2005-10-25 16:35:55 +10:00
/* initialise mouse cursors */
/* regular cursor */
normalmouse = SDL_GetCursor ( ) ;
/* object placement cursor */
for ( i = 0 ; i < 32 ; i + + ) {
data [ i ] = normalmouse - > data [ i ] ;
mask [ i ] = normalmouse - > mask [ i ] ;
}
/* add square top+bottom */
for ( x = 10 ; x < 16 ; x + + ) {
y = 10 ;
data [ ( x / 8 ) + ( y * 2 ) ] | = ( 128 > > ( x % 8 ) ) ;
mask [ ( x / 8 ) + ( y * 2 ) ] | = ( 128 > > ( x % 8 ) ) ;
y = 15 ;
data [ ( x / 8 ) + ( y * 2 ) ] | = ( 128 > > ( x % 8 ) ) ;
mask [ ( x / 8 ) + ( y * 2 ) ] | = ( 128 > > ( x % 8 ) ) ;
}
/* sides */
for ( y = 10 ; y < 16 ; y + + ) {
x = 10 ;
data [ ( x / 8 ) + ( y * 2 ) ] | = ( 128 > > ( x % 8 ) ) ;
mask [ ( x / 8 ) + ( y * 2 ) ] | = ( 128 > > ( x % 8 ) ) ;
x = 15 ;
data [ ( x / 8 ) + ( y * 2 ) ] | = ( 128 > > ( x % 8 ) ) ;
mask [ ( x / 8 ) + ( y * 2 ) ] | = ( 128 > > ( x % 8 ) ) ;
}
objmouse = SDL_CreateCursor ( data , mask , normalmouse - > area . w , normalmouse - > area . h , 0 , 0 ) ;
/* text placement cursor */
for ( i = 0 ; i < 32 ; i + + ) {
data [ i ] = normalmouse - > data [ i ] ;
mask [ i ] = normalmouse - > mask [ i ] ;
}
/* add A crossstroke*/
for ( x = 10 ; x < 15 ; x + + ) {
y = 13 ;
data [ ( x / 8 ) + ( y * 2 ) ] | = ( 128 > > ( x % 8 ) ) ;
mask [ ( x / 8 ) + ( y * 2 ) ] | = ( 128 > > ( x % 8 ) ) ;
}
/* downstrokes */
for ( y = 11 ; y < 16 ; y + + ) {
x = 10 ;
data [ ( x / 8 ) + ( y * 2 ) ] | = ( 128 > > ( x % 8 ) ) ;
mask [ ( x / 8 ) + ( y * 2 ) ] | = ( 128 > > ( x % 8 ) ) ;
x = 14 ;
data [ ( x / 8 ) + ( y * 2 ) ] | = ( 128 > > ( x % 8 ) ) ;
mask [ ( x / 8 ) + ( y * 2 ) ] | = ( 128 > > ( x % 8 ) ) ;
}
/* pointy bit */
x = 11 ; y = 10 ;
data [ ( x / 8 ) + ( y * 2 ) ] | = ( 128 > > ( x % 8 ) ) ;
mask [ ( x / 8 ) + ( y * 2 ) ] | = ( 128 > > ( x % 8 ) ) ;
x = 13 ; y = 10 ;
data [ ( x / 8 ) + ( y * 2 ) ] | = ( 128 > > ( x % 8 ) ) ;
mask [ ( x / 8 ) + ( y * 2 ) ] | = ( 128 > > ( x % 8 ) ) ;
x = 12 ; y = 9 ;
data [ ( x / 8 ) + ( y * 2 ) ] | = ( 128 > > ( x % 8 ) ) ;
mask [ ( x / 8 ) + ( y * 2 ) ] | = ( 128 > > ( x % 8 ) ) ;
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_SWSURFACE ) {
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 ) ;
}
2005-10-30 00:23:10 +10:00
if ( readonly ) {
sprintf ( verstring , " netmapr viewer v%s, by rpearce 2005 " , VERSION ) ;
SDL_WM_SetCaption ( verstring , " netmapr viewer " ) ;
} else {
sprintf ( verstring , " netmapr v%s, by rpearce 2005 " , VERSION ) ;
SDL_WM_SetCaption ( verstring , " netmapr " ) ;
}
2005-10-25 16:35:55 +10:00
2005-11-05 14:22:50 +11:00
/* set up toolbox highlight image */
toolhilite = SDL_CreateRGBSurface ( SDL_SWSURFACE , toolbox . gridsize + 3 , toolbox . gridsize + 3 ,
screen - > format - > BitsPerPixel , screen - > format - > Rmask ,
screen - > format - > Gmask , screen - > format - > Bmask ,
screen - > format - > Amask ) ;
fillcol = SDL_MapRGB ( screen - > format , 250 , 250 , 250 ) ;
area . x = 0 ;
area . y = 0 ;
area . w = toolbox . gridsize + 1 ;
area . h = toolbox . gridsize + 1 ;
SDL_FillRect ( toolhilite , & area , fillcol ) ;
SDL_SetAlpha ( toolhilite , SDL_SRCALPHA , 128 ) ;
2005-10-25 16:35:55 +10:00
/* initialise buffer */
buffer = SDL_CreateRGBSurface ( SDL_SWSURFACE , map [ curmap ] . width , map [ curmap ] . height ,
screen - > format - > BitsPerPixel , screen - > format - > Rmask ,
screen - > format - > Gmask , screen - > format - > Bmask ,
screen - > format - > Amask ) ;
if ( ! buffer ) {
printf ( " Cannot create buffer! \n " ) ;
exit ( 1 ) ;
}
f = fopen ( " objects.dat " , " rt " ) ;
if ( ! f ) {
2005-10-25 16:45:19 +10:00
sprintf ( file , " /usr/local/share/netmapr/objects.dat " ) ;
f = fopen ( file , " rt " ) ;
}
if ( ! f ) {
sprintf ( file , " %s/objects.dat " , progdir ) ;
2005-10-25 16:35:55 +10:00
f = fopen ( file , " rt " ) ;
}
2005-10-25 16:45:19 +10:00
if ( ! f ) {
printf ( " Cannot open objects file! \n " ) ;
exit ( 1 ) ;
}
2005-10-25 16:35:55 +10:00
state = 0 ;
line = 0 ;
numobjtypes = 0 ;
n = 0 ;
fgets ( buf , BUFLEN , f ) ;
buf [ strlen ( buf ) - 1 ] = ' \0 ' ;
line + + ;
while ( ! feof ( f ) ) {
/* ignore comments */
if ( buf [ 0 ] ! = ' # ' ) {
if ( state = = 0 ) {
p = strtok ( buf , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
if ( strcmp ( p , " object " ) ) {
printf ( " Expecting 'object' on line #%d of objects file (got '%s'). \n " , line , p ) ;
exit ( 1 ) ;
}
/* name */
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
strncpy ( objtype [ numobjtypes ] . name , p , BUFLEN ) ;
/* width */
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
objtype [ numobjtypes ] . vimg . w = atoi ( p ) ;
/* height */
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
objtype [ numobjtypes ] . vimg . h = atoi ( p ) ;
/* no vectors to start with */
objtype [ numobjtypes ] . vimg . vnum = 0 ;
objtype [ numobjtypes ] . canscale = TRUE ;
/* default size is minimum */
objtype [ numobjtypes ] . defw = MINOBJWIDTH ;
objtype [ numobjtypes ] . defh = MINOBJHEIGHT ;
state = 1 ;
} else if ( state = = 1 ) {
p = strtok ( buf , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
if ( ! strcmp ( p , " line " ) ) {
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
x1 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
y1 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
x2 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
y2 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
c . r = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
c . g = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
c . b = atoi ( p ) ;
2005-10-25 16:45:19 +10:00
if ( addvector ( & objtype [ numobjtypes ] . vimg , VT_LINE , x1 , y1 , x2 , y2 , & c ) ) {
printf ( " Too many vectors on line %d of objects file. \n " , line ) ;
exit ( 1 ) ;
}
2005-10-25 16:35:55 +10:00
} else if ( ! strcmp ( p , " fill " ) ) {
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
x1 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
y1 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
c . r = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
c . g = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
c . b = atoi ( p ) ;
2005-10-25 16:45:19 +10:00
if ( addvector ( & objtype [ numobjtypes ] . vimg , VT_FILL , x1 , y1 , 0 , 0 , & c ) ) {
printf ( " Too many vectors on line %d of objects file. \n " , line ) ;
exit ( 1 ) ;
}
2005-10-25 16:35:55 +10:00
} else if ( ! strcmp ( p , " box " ) ) {
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
x1 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
y1 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
x2 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
y2 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
c . r = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
c . g = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of objects file. \n " , line ) ; exit ( 1 ) ; }
c . b = atoi ( p ) ;
2005-10-25 16:45:19 +10:00
if ( addvector ( & objtype [ numobjtypes ] . vimg , VT_BOX , x1 , y1 , x2 , y2 , & c ) ) {
printf ( " Too many vectors on line %d of objects file. \n " , line ) ;
exit ( 1 ) ;
}
2005-10-25 16:35:55 +10:00
} else if ( ! strcmp ( p , " end " ) ) {
state = 0 ;
numobjtypes + + ;
if ( numobjtypes > = MAXOBJTYPES ) {
printf ( " FATAL: Too many object types found (max is %d). \n " , MAXOBJTYPES ) ;
exit ( 1 ) ;
}
} else {
printf ( " Invalid command '%s' on line #%d of objects file. \n " , p , line ) ;
exit ( 1 ) ;
}
}
}
fgets ( buf , BUFLEN , f ) ;
buf [ strlen ( buf ) - 1 ] = ' \0 ' ;
line + + ;
}
fclose ( f ) ;
printf ( " Shape load complete - %d objects found. \n " , numobjtypes ) ;
f = fopen ( " buttons.dat " , " rt " ) ;
if ( ! f ) {
2005-10-25 16:45:19 +10:00
sprintf ( file , " /usr/local/share/netmapr/buttons.dat " ) ;
2005-10-25 16:35:55 +10:00
f = fopen ( file , " rt " ) ;
}
2005-10-25 16:45:19 +10:00
if ( ! f ) {
sprintf ( file , " %s/buttons.dat " , progdir ) ;
f = fopen ( file , " rt " ) ;
}
if ( ! f ) {
printf ( " Cannot open buttons file! \n " ) ;
exit ( 1 ) ;
}
2005-10-25 16:35:55 +10:00
state = 0 ;
line = 0 ;
numbuttons = 0 ;
n = 0 ;
fgets ( buf , BUFLEN , f ) ;
buf [ strlen ( buf ) - 1 ] = ' \0 ' ;
line + + ;
while ( ! feof ( f ) ) {
/* ignore comments */
if ( buf [ 0 ] ! = ' # ' ) {
if ( state = = 0 ) {
p = strtok ( buf , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
if ( strcmp ( p , " button " ) ) {
printf ( " Expecting 'button' on line #%d of buttons file (got '%s'). \n " , line , p ) ;
exit ( 1 ) ;
}
/* name */
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
strncpy ( button [ numbuttons ] . name , p , BUFLEN ) ;
/* width */
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
tempv . w = atoi ( p ) ;
/* height */
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
tempv . h = atoi ( p ) ;
/* allocate mem */
button [ numbuttons ] . img = SDL_CreateRGBSurface ( SDL_SWSURFACE , toolbox . gridsize - 2 , toolbox . gridsize - 2 ,
screen - > format - > BitsPerPixel , screen - > format - > Rmask ,
screen - > format - > Gmask , screen - > format - > Bmask ,
screen - > format - > Amask ) ;
tempv . vnum = 0 ;
state = 1 ;
} else if ( state = = 1 ) {
p = strtok ( buf , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
if ( ! strcmp ( p , " line " ) ) {
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
x1 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
y1 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
x2 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
y2 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
c . r = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
c . g = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
c . b = atoi ( p ) ;
2005-10-25 16:45:19 +10:00
if ( addvector ( & tempv , VT_LINE , x1 , y1 , x2 , y2 , & c ) ) {
printf ( " Too many vectors on line %d of objects file. \n " , line ) ;
exit ( 1 ) ;
}
2005-10-25 16:35:55 +10:00
} else if ( ! strcmp ( p , " fill " ) ) {
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
x1 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
y1 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
c . r = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
c . g = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
c . b = atoi ( p ) ;
2005-10-25 16:45:19 +10:00
if ( addvector ( & tempv , VT_FILL , x1 , y1 , 0 , 0 , & c ) ) {
printf ( " Too many vectors on line %d of objects file. \n " , line ) ;
exit ( 1 ) ;
}
2005-10-25 16:35:55 +10:00
} else if ( ! strcmp ( p , " box " ) ) {
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
x1 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
y1 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
x2 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
y2 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
c . r = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
c . g = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of buttons file. \n " , line ) ; exit ( 1 ) ; }
c . b = atoi ( p ) ;
2005-10-25 16:45:19 +10:00
if ( addvector ( & tempv , VT_BOX , x1 , y1 , x2 , y2 , & c ) ) {
printf ( " Too many vectors on line %d of buttons file. \n " , line ) ;
exit ( 1 ) ;
}
2005-10-25 16:35:55 +10:00
} else if ( ! strcmp ( p , " end " ) ) {
/* draw vector image into button's bitmap field */
2005-10-28 16:05:57 +10:00
drawvector ( button [ numbuttons ] . img , & tempv , 1 , 1 , toolbox . gridsize - 2 , toolbox . gridsize - 2 , NULL , NULL ) ;
2005-10-25 16:35:55 +10:00
//printf("Adding button: '%s' (vnum = %d).\n",button[numbuttons].name,tempv.vnum);
state = 0 ;
numbuttons + + ;
} else {
printf ( " Invalid command '%s' on line #%d of buttons file. \n " , p , line ) ;
exit ( 1 ) ;
}
}
}
fgets ( buf , BUFLEN , f ) ;
buf [ strlen ( buf ) - 1 ] = ' \0 ' ;
line + + ;
}
fclose ( f ) ;
printf ( " Button load complete - %d buttons found. \n " , numbuttons ) ;
2005-10-27 14:46:38 +10:00
////////////////////////////////////////////////////////////
/// XXX: TESTING ///
/*
x = 10 ; y = 10 ;
for ( i = 0 ; i < numletters ; i + + ) {
int lw , lh ;
lw = 8 ;
lh = 10 ;
2005-10-28 16:05:57 +10:00
drawvector ( screen , & letter [ i ] . vect , x , y , lw , lh , NULL , NULL ) ;
2005-10-27 14:46:38 +10:00
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 ( ) {
2005-10-25 16:35:55 +10:00
printf ( " Reading letters... \n " ) ;
f = fopen ( " letters.dat " , " rt " ) ;
if ( ! f ) {
2005-10-25 16:45:19 +10:00
sprintf ( file , " /usr/local/share/netmapr/letters.dat " ) ;
f = fopen ( file , " rt " ) ;
}
if ( ! f ) {
sprintf ( file , " %s/letters.dat " , progdir ) ;
2005-10-25 16:35:55 +10:00
f = fopen ( file , " rt " ) ;
}
2005-10-25 16:45:19 +10:00
if ( ! f ) {
printf ( " Cannot open letters file! \n " ) ;
exit ( 1 ) ;
}
2005-10-25 16:35:55 +10:00
state = 0 ;
line = 0 ;
numletters = 0 ;
n = 0 ;
fgets ( buf , BUFLEN , f ) ;
buf [ strlen ( buf ) - 1 ] = ' \0 ' ;
line + + ;
while ( ! feof ( f ) ) {
// ignore comments
if ( buf [ 0 ] ! = ' # ' ) {
if ( state = = 0 ) {
p = strtok ( buf , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of letters file. \n " , line ) ; exit ( 1 ) ; }
if ( strcmp ( p , " letter " ) ) {
printf ( " Expecting 'letter' on line #%d of letters file (got '%s'). \n " , line , p ) ;
exit ( 1 ) ;
}
// name
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of letters file. \n " , line ) ; exit ( 1 ) ; }
letter [ numletters ] . name = p [ 0 ] ;
// width
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of letters file. \n " , line ) ; exit ( 1 ) ; }
letter [ numletters ] . vect . w = atoi ( p ) ;
// height
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of letters file. \n " , line ) ; exit ( 1 ) ; }
letter [ numletters ] . vect . h = atoi ( p ) ;
letter [ numletters ] . vect . vnum = 0 ;
state = 1 ;
} else if ( state = = 1 ) {
p = strtok ( buf , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of letters file. \n " , line ) ; exit ( 1 ) ; }
if ( ! strcmp ( p , " line " ) ) {
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of letters file. \n " , line ) ; exit ( 1 ) ; }
x1 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of letters file. \n " , line ) ; exit ( 1 ) ; }
y1 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of letters file. \n " , line ) ; exit ( 1 ) ; }
x2 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of letters file. \n " , line ) ; exit ( 1 ) ; }
y2 = atoi ( p ) ;
c = fgcol ;
2005-10-25 16:45:19 +10:00
if ( addvector ( & letter [ numletters ] . vect , VT_LINE , x1 , y1 , x2 , y2 , & c ) ) {
printf ( " Too many vectors on line %d of letters file. \n " , line ) ;
exit ( 1 ) ;
}
2005-10-25 16:35:55 +10:00
} else if ( ! strcmp ( p , " fill " ) ) {
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of letters file. \n " , line ) ; exit ( 1 ) ; }
x1 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of letters file. \n " , line ) ; exit ( 1 ) ; }
y1 = atoi ( p ) ;
c = fgcol ;
2005-10-25 16:45:19 +10:00
if ( addvector ( & letter [ numletters ] . vect , VT_FILL , x1 , y1 , 0 , 0 , & c ) ) {
printf ( " Too many vectors on line %d of letters file. \n " , line ) ;
exit ( 1 ) ;
}
2005-10-25 16:35:55 +10:00
} else if ( ! strcmp ( p , " box " ) ) {
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of letters file. \n " , line ) ; exit ( 1 ) ; }
x1 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of letters file. \n " , line ) ; exit ( 1 ) ; }
y1 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of letters file. \n " , line ) ; exit ( 1 ) ; }
x2 = atoi ( p ) ;
p = strtok ( NULL , " " ) ;
if ( p = = NULL ) { printf ( " Missing token on line #%d of letters file. \n " , line ) ; exit ( 1 ) ; }
y2 = atoi ( p ) ;
c = fgcol ;
2005-10-25 16:45:19 +10:00
if ( addvector ( & letter [ numletters ] . vect , VT_BOX , x1 , y1 , x2 , y2 , & c ) ) {
printf ( " Too many vectors on line %d of letters file. \n " , line ) ;
exit ( 1 ) ;
}
2005-10-25 16:35:55 +10:00
} else if ( ! strcmp ( p , " end " ) ) {
//printf("Adding letter %d: '%c' (vnum = %d).\n",numletters,letter[numletters].name,letter[numletters].vect.vnum);
state = 0 ;
numletters + + ;
if ( numletters > = MAXLETTERVECTS ) {
printf ( " FATAL: Too many letters found (max is %d). \n " , MAXLETTERVECTS ) ;
exit ( 1 ) ;
}
} else {
printf ( " Invalid command '%s' on line #%d of letters file. \n " , p , line ) ;
exit ( 1 ) ;
}
}
}
fgets ( buf , BUFLEN , f ) ;
buf [ strlen ( buf ) - 1 ] = ' \0 ' ;
line + + ;
}
fclose ( f ) ;
}
2005-10-27 14:46:38 +10:00
# endif
2005-10-25 16:35:55 +10:00
int isonline ( int fx , int fy , int x1 , int y1 , int x2 , int y2 ) {
int deltax , deltay ;
int numpixels ;
int d ;
int dinc1 , dinc2 , xinc1 , xinc2 , yinc1 , yinc2 ;
int i ;
int x ;
int y ;
deltax = ( x2 - x1 ) ;
if ( deltax < 0 ) deltax = - deltax ;
deltay = ( y2 - y1 ) ;
if ( deltay < 0 ) deltay = - deltay ;
if ( deltax > = deltay ) {
numpixels = deltax + 1 ;
d = ( deltay * 2 ) - deltax ;
dinc1 = deltay < < 1 ;
dinc2 = ( deltay - deltax ) < < 1 ;
xinc1 = 1 ;
xinc2 = 1 ;
yinc1 = 0 ;
yinc2 = 1 ;
} else {
numpixels = deltay + 1 ;
d = ( deltax * 2 ) - deltay ;
dinc1 = deltax < < 1 ;
dinc2 = ( deltax - deltay ) < < 1 ;
xinc1 = 0 ;
xinc2 = 1 ;
yinc1 = 1 ;
yinc2 = 1 ;
}
if ( x1 > x2 ) {
xinc1 = - xinc1 ;
xinc2 = - xinc2 ;
}
if ( y1 > y2 ) {
yinc1 = - yinc1 ;
yinc2 = - yinc2 ;
}
x = x1 ; y = y1 ;
for ( i = 0 ; i < numpixels ; i + + ) {
if ( ( fx > = ( x - LINESELTHRESHOLD ) ) & & ( fx < = ( x + LINESELTHRESHOLD ) ) & &
( fy > = ( y - LINESELTHRESHOLD ) ) & & ( fy < = ( y + LINESELTHRESHOLD ) ) ) {
return TRUE ;
}
if ( d < 0 ) {
d + = dinc1 ;
x + = xinc1 ;
y + = yinc1 ;
} else {
d + = dinc2 ;
x + = xinc2 ;
y + = yinc2 ;
}
}
return FALSE ;
}
int isonlink ( int linkid , int mx , int my ) {
int i ;
int x , y , x2 , y2 ;
x = map [ curmap ] . obj [ map [ curmap ] . olink [ linkid ] . srcobj ] . x + map [ curmap ] . olink [ linkid ] . srcxoff ;
y = map [ curmap ] . obj [ map [ curmap ] . olink [ linkid ] . srcobj ] . y + map [ curmap ] . olink [ linkid ] . srcyoff ;
for ( i = 0 ; i < map [ curmap ] . olink [ linkid ] . npoints ; i + + ) {
x2 = map [ curmap ] . olink [ linkid ] . point [ i ] . x ;
y2 = map [ curmap ] . olink [ linkid ] . point [ i ] . y ;
if ( isonline ( mx , my , x , y , x2 , y2 ) ) return TRUE ;
x = x2 ;
y = y2 ;
}
/* draw line to final map[curmap].object */
x2 = map [ curmap ] . obj [ map [ curmap ] . olink [ linkid ] . dstobj ] . x + map [ curmap ] . olink [ linkid ] . dstxoff ;
y2 = map [ curmap ] . obj [ map [ curmap ] . olink [ linkid ] . dstobj ] . y + map [ curmap ] . olink [ linkid ] . dstyoff ;
if ( isonline ( mx , my , x , y , x2 , y2 ) ) return TRUE ;
return FALSE ;
}
int isonlinkdst ( int lineid , int x , int y ) {
int hx1 , hy1 , hx2 , hy2 ;
hx1 = map [ curmap ] . obj [ map [ curmap ] . olink [ lineid ] . dstobj ] . x + map [ curmap ] . olink [ lineid ] . dstxoff - ( LINESELHANDLESIZE / 2 ) ;
hy1 = map [ curmap ] . obj [ map [ curmap ] . olink [ lineid ] . dstobj ] . y + map [ curmap ] . olink [ lineid ] . dstyoff - ( LINESELHANDLESIZE / 2 ) ;
hx2 = hx1 + LINESELHANDLESIZE ;
hy2 = hy1 + LINESELHANDLESIZE ;
if ( ( x > = hx1 ) & & ( x < = hx2 ) & & ( y > = hy1 ) & ( y < = hy2 ) ) {
return TRUE ;
}
return FALSE ;
}
int isonlinkpoint ( int lineid , int mx , int my ) {
int i ;
for ( i = 0 ; i < map [ curmap ] . olink [ lineid ] . npoints ; i + + ) {
int x , y ;
x = map [ curmap ] . olink [ lineid ] . point [ i ] . x ;
y = map [ curmap ] . olink [ lineid ] . point [ i ] . y ;
if ( ( mx > = ( x - LINESELTHRESHOLD ) ) & & ( mx < = ( x + LINESELTHRESHOLD ) ) & &
( my > = ( y - LINESELTHRESHOLD ) ) & & ( my < = ( y + LINESELTHRESHOLD ) ) ) {
return i ;
}
}
return - 1 ;
}
int isonlinksrc ( int lineid , int x , int y ) {
int hx1 , hy1 , hx2 , hy2 ;
hx1 = map [ curmap ] . obj [ map [ curmap ] . olink [ lineid ] . srcobj ] . x + map [ curmap ] . olink [ lineid ] . srcxoff - ( LINESELHANDLESIZE / 2 ) ;
hy1 = map [ curmap ] . obj [ map [ curmap ] . olink [ lineid ] . srcobj ] . y + map [ curmap ] . olink [ lineid ] . srcyoff - ( LINESELHANDLESIZE / 2 ) ;
hx2 = hx1 + LINESELHANDLESIZE ;
hy2 = hy1 + LINESELHANDLESIZE ;
if ( ( x > = hx1 ) & & ( x < = hx2 ) & & ( y > = hy1 ) & ( y < = hy2 ) ) {
return TRUE ;
}
return FALSE ;
}
int isonmap ( int x , int y ) {
if ( ( x > = 0 ) & & ( y > = 0 ) & & ( x < = map [ curmap ] . width ) & & ( y < = map [ curmap ] . height ) ) {
return TRUE ;
}
return FALSE ;
}
int isonmapbox ( int x , int y ) {
if ( ( x > = mapbox . x ) & & ( y > = mapbox . y ) & & ( x < = mapbox . x + mapbox . width ) & & ( y < = mapbox . y + mapbox . height ) ) {
return TRUE ;
}
return FALSE ;
}
int isonmapboxchildren ( int x , int y ) {
2005-10-27 17:00:32 +10:00
if ( ( x > = mapbox . x ) & & ( y > = mapbox . y + ( TTF_FontHeight ( font [ MAPBOXTEXTHEIGHT ] ) * 2 ) + 2 ) & & ( x < = mapbox . x + mapbox . width ) & & ( y < = mapbox . y + mapbox . height ) ) {
2005-10-25 16:35:55 +10:00
return TRUE ;
}
return FALSE ;
}
int isonmapname ( int x , int y ) {
if ( ( x > = mapbox . x ) & & ( y > = mapbox . y ) & & ( x < = mapbox . x + mapbox . width ) & & ( y < = mapbox . y + DEFTEXTH + 2 ) ) {
return TRUE ;
}
return FALSE ;
}
int isongoback ( int x , int y ) {
2005-10-27 17:00:32 +10:00
if ( ( x > = mapbox . x ) & & ( y > = ( mapbox . y + TTF_FontHeight ( font [ MAPBOXTEXTHEIGHT ] ) ) )
& & ( x < = mapbox . x + mapbox . width ) & & ( y < = mapbox . y + ( TTF_FontHeight ( font [ MAPBOXTEXTHEIGHT ] ) * 2 ) ) ) {
2005-10-25 16:35:55 +10:00
return TRUE ;
}
return FALSE ;
}
int isonobox ( int x , int y ) {
if ( ( x > = obox . x ) & & ( y > = obox . y ) & & ( x < = obox . x + obox . width ) & & ( y < = obox . y + obox . height ) ) {
return TRUE ;
}
return FALSE ;
}
int isontoolbox ( int x , int y ) {
if ( ( x > = toolbox . x ) & & ( y > = toolbox . y ) & & ( x < = toolbox . x + toolbox . width ) & & ( y < = toolbox . y + toolbox . height ) ) {
return TRUE ;
}
return FALSE ;
}
void initmap ( int mapnum ) {
map [ mapnum ] . width = 800 ;
map [ mapnum ] . height = 600 - DEFTEXTH ;
map [ mapnum ] . bpp = 16 ;
map [ mapnum ] . bgcol . r = 255 ;
map [ mapnum ] . bgcol . g = 255 ;
map [ mapnum ] . bgcol . b = 255 ;
map [ mapnum ] . boxcol . r = 90 ;
map [ mapnum ] . boxcol . g = 90 ;
map [ mapnum ] . boxcol . b = 90 ;
map [ mapnum ] . numthings = 0 ;
map [ mapnum ] . numobjects = 0 ;
map [ mapnum ] . numlinks = 0 ;
map [ mapnum ] . numtext = 0 ;
map [ mapnum ] . selecteditem = - 1 ;
map [ mapnum ] . selecteditemtype = - 1 ;
map [ mapnum ] . selectedlinkpoint = - 1 ;
map [ mapnum ] . selectedtype = 0 ;
map [ mapnum ] . curobj = - 1 ; /* map[curmap].object being moved/dragged/etc */
map [ mapnum ] . curlink = - 1 ; /* link being moved/dragged/etc */
map [ mapnum ] . curlinkpoint = - 1 ; /* link pomap[mapnum].being moved/dragged/etc */
map [ mapnum ] . curtext = - 1 ; /* text being moved/dragged/etc */
map [ mapnum ] . startx = - 1 ;
map [ mapnum ] . starty = - 1 ;
map [ mapnum ] . textanchor = - 1 ;
strcpy ( map [ mapnum ] . text , " " ) ;
if ( mapnum = = 0 ) {
sprintf ( map [ mapnum ] . name , " Toplevel " ) ;
} else {
sprintf ( map [ mapnum ] . name , " Map #%d " , mapnum ) ;
}
modified = FALSE ;
}
void initvars ( void ) {
nummaps = 1 ;
strcpy ( currentfilename , " " ) ;
/* set globals */
initmap ( 0 ) ;
curmap = 0 ;
obox . x = map [ curmap ] . width + 1 ;
obox . y = ( map [ curmap ] . height / 4 ) * 3 ;
obox . width = SIDEBARW ;
obox . height = map [ curmap ] . height - obox . y ;
obox . pos = 0 ;
obox . bgcol = black ;
obox . gridbgcol = grey4 ;
obox . gridcol = grey ;
obox . gridsize = 30 ;
obox . gridrowlen = SIDEBARW / obox . gridsize ;
toolbox . x = map [ curmap ] . width + 1 ;
toolbox . y = 0 ;
toolbox . width = SIDEBARW ;
toolbox . height = map [ curmap ] . height / 3 ;
toolbox . bgcol = black ;
//toolbox.gridcol = grey3;
toolbox . gridsize = 30 ;
toolbox . gridrowlen = SIDEBARW / toolbox . gridsize ;
mapbox . x = map [ curmap ] . width + 1 ;
mapbox . y = toolbox . y + toolbox . height + 1 ;
mapbox . width = SIDEBARW ;
mapbox . height = obox . y - mapbox . y - 20 ;
2005-10-31 13:20:14 +11:00
mapbox . offset = 0 ;
2005-10-25 16:35:55 +10:00
fgcol = black ;
2005-10-28 16:05:57 +10:00
objfillcol = black ;
objfillcol . unused = NOCOLOUR ;
2005-10-25 16:35:55 +10:00
}
void raiseselected ( void ) {
int i ;
int temptype , tempid ;
int target ;
/* find map[curmap].object */
for ( i = 0 ; i < map [ curmap ] . numthings ; i + + ) {
if ( ( map [ curmap ] . thing [ i ] . id = = map [ curmap ] . selecteditem ) & & ( map [ curmap ] . thing [ i ] . type = = map [ curmap ] . selecteditemtype ) ) {
/* swap with one above */
if ( i = = ( map [ curmap ] . numthings - 1 ) ) {
break ;
} else {
target = i + 1 ;
}
tempid = map [ curmap ] . thing [ target ] . id ;
temptype = map [ curmap ] . thing [ target ] . type ;
map [ curmap ] . thing [ target ] . id = map [ curmap ] . thing [ i ] . id ;
map [ curmap ] . thing [ target ] . type = map [ curmap ] . thing [ i ] . type ;
map [ curmap ] . thing [ i ] . id = tempid ;
map [ curmap ] . thing [ i ] . type = temptype ;
break ;
}
}
modified = TRUE ;
/* redraw map */
drawmap ( ) ;
}
int savemap ( void ) {
char filename [ BUFLEN ] ;
FILE * f ;
int namelen ;
int i ;
int eoff ;
SDL_Surface * exportmap ;
SDL_Rect area ;
2005-10-28 16:05:57 +10:00
char vers [ 8 ] ;
2005-10-25 16:35:55 +10:00
/* TODO: validate */
strcpy ( filename , text ) ;
sprintf ( statustext , " Saving map... \n " ) ;
drawstatusbar ( ) ;
/* is this an export? (use extenstion) */
if ( strlen ( filename ) > = 5 ) {
eoff = strlen ( filename ) - 4 ;
if ( ( filename [ eoff ] = = ' . ' ) & &
( ( filename [ eoff + 1 ] = = ' b ' ) | | ( filename [ eoff + 1 ] = = ' B ' ) ) & &
( ( filename [ eoff + 2 ] = = ' m ' ) | | ( filename [ eoff + 2 ] = = ' M ' ) ) & &
( ( filename [ eoff + 3 ] = = ' p ' ) | | ( filename [ eoff + 3 ] = = ' P ' ) )
) {
exportmap = SDL_CreateRGBSurface ( SDL_SWSURFACE , map [ curmap ] . width , map [ curmap ] . height ,
buffer - > format - > BitsPerPixel , buffer - > format - > Rmask ,
buffer - > format - > Gmask , buffer - > format - > Bmask ,
buffer - > format - > Amask ) ;
state = S_NONE ;
drawmap ( ) ;
area . x = 0 ;
area . y = 0 ;
area . w = map [ curmap ] . width ;
area . h = map [ curmap ] . height ;
SDL_BlitSurface ( screen , & area , exportmap , 0 ) ;
if ( SDL_SaveBMP ( exportmap , filename ) ) {
sprintf ( statustext , " ERROR: Could not export to BMP file '%s'. \n " , filename ) ;
drawstatusbar ( ) ;
return TRUE ;
}
sprintf ( statustext , " Successfully exported map to BMP file '%s'. \n " , filename ) ;
drawstatusbar ( ) ;
return FALSE ;
}
}
if ( ( f = fopen ( filename , " wb " ) ) = = NULL ) {
sprintf ( statustext , " ERROR: Could not open '%s'. \n " , filename ) ;
drawstatusbar ( ) ;
return TRUE ;
}
2005-10-28 16:05:57 +10:00
/* dump version, 8 bytes, right padded with 0s */
sprintf ( vers , " V%-7s " , VERSION ) ;
fwrite ( vers , 8 , 1 , f ) ;
2005-10-25 16:35:55 +10:00
/* dump out numbers of map[curmap].objects */
fwrite ( & nummaps , sizeof ( int ) , 1 , f ) ;
for ( i = 0 ; i < nummaps ; i + + ) {
fwrite ( & map [ i ] . width , sizeof ( int ) , 1 , f ) ;
fwrite ( & map [ i ] . height , sizeof ( int ) , 1 , f ) ;
fwrite ( & map [ i ] . bpp , sizeof ( int ) , 1 , f ) ;
fwrite ( & map [ i ] . bgcol , sizeof ( SDL_Color ) , 1 , f ) ;
fwrite ( & map [ i ] . boxcol , sizeof ( SDL_Color ) , 1 , f ) ;
fwrite ( & map [ i ] . numthings , sizeof ( int ) , 1 , f ) ;
fwrite ( & map [ i ] . numobjects , sizeof ( int ) , 1 , f ) ;
fwrite ( & map [ i ] . numlinks , sizeof ( int ) , 1 , f ) ;
fwrite ( & map [ i ] . numtext , sizeof ( int ) , 1 , f ) ;
/* selecteditem*/
/* selecteditemtype*/
/* selectedlinkpoint*/
/* selectedtype*/
/* curobj*/
/* curlink*/
/* curlinkpoint*/
/* curtext*/
/* startx,starty */
/* textanchor */
/* text*/
namelen = strlen ( map [ i ] . name ) ;
fwrite ( & namelen , sizeof ( int ) , 1 , f ) ;
fwrite ( & map [ i ] . name , ( namelen + 1 ) * sizeof ( char ) , 1 , f ) ;
/* write objects */
fwrite ( & map [ i ] . thing , sizeof ( thing_t ) , map [ i ] . numthings , f ) ;
fwrite ( & map [ i ] . olink , sizeof ( link_t ) , map [ i ] . numlinks , f ) ;
2005-10-25 16:45:19 +10:00
fwrite ( & map [ i ] . obj , sizeof ( mapobject_t ) , map [ i ] . numobjects , f ) ;
2005-10-25 16:35:55 +10:00
fwrite ( & map [ i ] . textob , sizeof ( text_t ) , map [ i ] . numtext , f ) ;
}
fclose ( f ) ;
modified = FALSE ;
sprintf ( statustext , " Successfully saved map to '%s'. \n " , filename ) ;
/* save filename */
strcpy ( currentfilename , filename ) ;
return 0 ;
}
int showfiledialog ( void ) {
Uint32 fillcol ;
text_t temp ;
SDL_Rect area , sarea ;
int y ;
SDL_Color ccol ;
2005-10-27 14:46:38 +10:00
int tw , th ;
2005-10-25 16:35:55 +10:00
/* clear map */
fillcol = SDL_MapRGB ( buffer - > format , map [ curmap ] . bgcol . r , map [ curmap ] . bgcol . g , map [ curmap ] . bgcol . b ) ;
SDL_FillRect ( buffer , NULL , fillcol ) ;
/* */
switch ( state ) {
case S_SAVING :
strcpy ( temp . text , " Enter save filename: " ) ;
break ;
case S_LOADING :
strcpy ( temp . text , " Enter load filename: " ) ;
break ;
case S_MAPNAMING :
strcpy ( temp . text , " Enter new map name: " ) ;
break ;
default :
strcpy ( temp . text , " Enter filename: " ) ;
break ;
}
temp . h = DEFTEXTH * 2 ;
2005-10-27 14:46:38 +10:00
TTF_SizeText ( font [ DEFTEXTH * 2 ] , temp . text , & tw , & th ) ;
temp . w = tw ;
2005-10-25 16:35:55 +10:00
temp . x = ( map [ curmap ] . width / 2 ) - ( temp . w / 2 ) ;
2005-10-27 14:46:38 +10:00
temp . y = ( map [ curmap ] . height / 2 ) - ( th * 4 ) ;
2005-10-25 16:35:55 +10:00
temp . c = black ;
temp . anchor = - 1 ;
drawtext ( buffer , & temp ) ;
/* draw outlines */
2005-10-27 14:46:38 +10:00
drawbox ( buffer , 0 , 0 , map [ curmap ] . width - 1 , map [ curmap ] . height - th - 3 , blue ) ;
2005-10-25 16:35:55 +10:00
2005-10-27 14:46:38 +10:00
drawbox ( buffer , 0 , ( map [ curmap ] . height / 2 ) - 2 , map [ curmap ] . width - 1 , ( map [ curmap ] . height / 2 ) + th + 2 , blue ) ;
2005-10-25 16:35:55 +10:00
/* actually draw the text */
2005-10-27 14:46:38 +10:00
TTF_SizeText ( font [ DEFTEXTH * 2 ] , text , & tw , & th ) ;
2005-10-25 16:35:55 +10:00
/* paste old background */
if ( bg ! = NULL ) {
area . x = bgx ;
area . y = bgy ;
area . w = bg - > w ;
area . h = bg - > h ;
SDL_BlitSurface ( bg , 0 , screen , & area ) ;
// free it
//SDL_UpdateRect(screen,area.x, area.y, area.w, area.h);
SDL_FreeSurface ( bg ) ;
}
/* copy new background */
sarea . x = startx ;
sarea . y = starty ;
2005-10-27 14:46:38 +10:00
sarea . w = tw + CURSORWIDTH ; // include space for cursor
2005-10-25 16:35:55 +10:00
sarea . h = DEFTEXTH * 2 ;
bg = SDL_CreateRGBSurface ( SDL_SWSURFACE , sarea . w , sarea . h ,
buffer - > format - > BitsPerPixel , buffer - > format - > Rmask ,
buffer - > format - > Gmask , buffer - > format - > Bmask ,
buffer - > format - > Amask ) ;
SDL_BlitSurface ( screen , & sarea , bg , 0 ) ;
bgx = sarea . x ;
bgy = sarea . y ;
/* draw text */
strcpy ( temp . text , text ) ;
temp . x = startx ;
temp . y = starty ;
2005-10-27 14:46:38 +10:00
temp . w = tw ;
2005-10-25 16:35:55 +10:00
temp . h = DEFTEXTH * 2 ;
2005-10-30 22:50:06 +11:00
temp . c = black ;
2005-10-25 16:35:55 +10:00
temp . anchor = - 1 ;
drawtext ( buffer , & temp ) ;
/* draw cursor (a solid block) */
ccol = blue ;
2005-10-27 14:46:38 +10:00
for ( y = starty ; y < ( starty + th ) ; y + + ) {
2005-10-30 19:45:37 +11:00
drawline ( buffer , startx + tw , y , startx + tw + CURSORWIDTH , y , ccol , 1 ) ;
2005-10-25 16:35:55 +10:00
}
/* blit to screen */
SDL_BlitSurface ( buffer , 0 , screen , 0 ) ;
SDL_UpdateRect ( screen , 0 , 0 , map [ curmap ] . width , map [ curmap ] . height ) ;
return FALSE ;
}
2005-10-29 16:37:41 +10:00
void startedittext ( int o ) {
SDL_Rect area ;
Uint32 bgcol ;
/* edit text */
map [ curmap ] . selecteditem = o ;
map [ curmap ] . selecteditemtype = T_TEXT ;
/* start listening for text input */
startx = map [ curmap ] . textob [ o ] . x ;
starty = map [ curmap ] . textob [ o ] . y ;
textanchor = map [ curmap ] . textob [ o ] . anchor ;
strcpy ( text , map [ curmap ] . textob [ o ] . text ) ;
updateheight = map [ curmap ] . textob [ o ] . h ;
bg = NULL ;
/* blank out where the old text was */
if ( textanchor ! = - 1 ) {
startx + = map [ curmap ] . obj [ textanchor ] . x ;
starty + = map [ curmap ] . obj [ textanchor ] . y ;
}
area . x = startx ;
area . y = starty ;
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 ) ;
SDL_FillRect ( screen , & area , bgcol ) ;
SDL_UpdateRect ( screen , area . x , area . y , area . w , area . h ) ;
updatetextcursor ( ) ;
changestate ( S_EDITTEXT ) ;
}
2005-10-25 16:35:55 +10:00
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 ;
startx = x ;
starty = y ;
startobj = map [ curmap ] . curobj ;
changestate ( S_DRAWLINK ) ;
/* copy line */
linex1 = startx ;
liney1 = starty ;
linex2 = x ;
liney2 = y ;
len = linelen ( linex1 , liney1 , linex2 , liney2 ) ;
linebg = malloc ( ( len + 4 ) * sizeof ( int ) ) ;
copyline ( screen , linex1 , liney1 , linex2 , liney2 , linebg ) ;
sprintf ( statustext , " Creating link #%d... \n " , map [ curmap ] . numlinks ) ;
drawstatusbar ( ) ;
return 0 ;
}
int startlinkdstmove ( int x , int y ) {
int linex1 , liney1 , linex2 , liney2 ;
int len ;
startx = x ;
starty = y ;
changestate ( S_LINKDSTMOVE ) ;
/* copy background */
linex1 = map [ curmap ] . obj [ map [ curmap ] . olink [ map [ curmap ] . curlink ] . dstobj ] . x + map [ curmap ] . olink [ map [ curmap ] . olink [ map [ curmap ] . curlink ] . dstobj ] . dstxoff ;
liney1 = map [ curmap ] . obj [ map [ curmap ] . olink [ map [ curmap ] . curlink ] . dstobj ] . y + map [ curmap ] . olink [ map [ curmap ] . olink [ map [ curmap ] . curlink ] . dstobj ] . dstyoff ;
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 ;
len = linelen ( linex1 , liney1 , linex2 , liney2 ) ;
linebg = malloc ( ( len + 4 ) * sizeof ( int ) ) ;
copyline ( screen , linex1 , liney1 , linex2 , liney2 , linebg ) ;
sprintf ( statustext , " Starting dst endpoint move for link #%d... \n " , map [ curmap ] . curlink ) ; fflush ( stdout ) ;
drawstatusbar ( ) ;
return 0 ;
}
int startlinkpointmove ( int x , int y ) {
int linex1 , liney1 , linex2 , liney2 ;
SDL_Rect area ;
startx = x ;
starty = y ;
changestate ( S_LINKPOINTMOVE ) ;
/* copy background */
linex1 = map [ curmap ] . olink [ map [ curmap ] . curlink ] . point [ map [ curmap ] . curlinkpoint ] . x - ( LINESELHANDLESIZE / 2 ) ;
liney1 = map [ curmap ] . olink [ map [ curmap ] . curlink ] . point [ map [ curmap ] . curlinkpoint ] . y - ( LINESELHANDLESIZE / 2 ) ;
linex2 = map [ curmap ] . olink [ map [ curmap ] . curlink ] . point [ map [ curmap ] . curlinkpoint ] . x + ( LINESELHANDLESIZE / 2 ) + 2 ;
liney2 = map [ curmap ] . olink [ map [ curmap ] . curlink ] . point [ map [ curmap ] . curlinkpoint ] . y + ( LINESELHANDLESIZE / 2 ) + 2 ;
bg = SDL_CreateRGBSurface ( SDL_SWSURFACE , LINESELHANDLESIZE , LINESELHANDLESIZE ,
screen - > format - > BitsPerPixel , screen - > format - > Rmask ,
screen - > format - > Gmask , screen - > format - > Bmask ,
screen - > format - > Amask ) ;
bgx = linex1 ;
bgy = liney1 ;
area . x = linex1 ;
area . y = liney1 ;
area . w = LINESELHANDLESIZE + 4 ;
area . h = LINESELHANDLESIZE + 4 ;
SDL_BlitSurface ( screen , & area , bg , 0 ) ;
sprintf ( statustext , " Starting link point move for link #%d poinrt #%d... \n " , map [ curmap ] . curlink , map [ curmap ] . curlinkpoint ) ;
drawstatusbar ( ) ;
return 0 ;
}
int startlinksrcmove ( int x , int y ) {
int linex1 , liney1 , linex2 , liney2 ;
int len ;
startx = x ;
starty = y ;
changestate ( S_LINKSRCMOVE ) ;
/* 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 ;
len = linelen ( linex1 , liney1 , linex2 , liney2 ) ;
if ( len < = 0 ) {
printf ( " ERROR: length is zero or negative - %d \n " , len ) ;
fflush ( stdout ) ;
exit ( 1 ) ;
}
linebg = malloc ( ( len + 4 ) * sizeof ( int ) ) ;
if ( linebg = = NULL ) {
printf ( " ERROR: cannot malloc() \n " ) ; fflush ( stdout ) ;
}
copyline ( screen , linex1 , liney1 , linex2 , liney2 , linebg ) ;
sprintf ( statustext , " Starting src endpoint move for link #%d... \n " , map [ curmap ] . curlink ) ; fflush ( stdout ) ;
drawstatusbar ( ) ;
return 0 ;
}
int startlinkmove ( int x , int y ) {
int linex1 , liney1 ;
int linex2 , liney2 ;
int len ;
startx = x ;
starty = y ;
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 ;
len = linelen ( linex1 , liney1 , linex2 , liney2 ) ;
if ( len < = 0 ) {
printf ( " ERROR: length is zero or negative - %d \n " , len ) ;
fflush ( stdout ) ;
exit ( 1 ) ;
}
linebg = malloc ( ( len + 4 ) * sizeof ( int ) ) ;
if ( linebg = = NULL ) {
printf ( " ERROR: cannot malloc() \n " ) ; fflush ( stdout ) ;
}
copyline ( screen , linex1 , liney1 , linex2 , liney2 , linebg ) ;
sprintf ( statustext , " Starting move of link #%d... \n " , map [ curmap ] . curlink ) ; fflush ( stdout ) ;
drawstatusbar ( ) ;
return 0 ;
}
int startobjmove ( int x , int y ) {
SDL_Rect area ;
xoff = map [ curmap ] . obj [ map [ curmap ] . curobj ] . x - x ;
yoff = map [ curmap ] . obj [ map [ curmap ] . curobj ] . y - y ;
startx = x ;
starty = y ;
changestate ( S_OBJMOVING ) ;
/* copy background */
bg = SDL_CreateRGBSurface ( SDL_SWSURFACE , map [ curmap ] . obj [ map [ curmap ] . curobj ] . w , map [ curmap ] . obj [ map [ curmap ] . curobj ] . h ,
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 . w = map [ curmap ] . obj [ map [ curmap ] . curobj ] . w ;
area . h = map [ curmap ] . obj [ map [ curmap ] . curobj ] . h ;
SDL_BlitSurface ( screen , & area , bg , 0 ) ;
bgx = area . x ;
bgy = area . y ;
bgw = area . w ;
bgh = area . h ;
return 0 ;
}
int startresize ( int x , int y ) {
SDL_Rect area ;
startx = x ;
starty = y ;
changestate ( S_RESIZING ) ;
/* copy background */
bg = SDL_CreateRGBSurface ( SDL_SWSURFACE , MAXOBJWIDTH + 2 , MAXOBJHEIGHT + 2 ,
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 . 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 ) ;
bgx = area . x ;
bgy = area . y ;
bgw = area . w ;
bgh = area . h ;
return 0 ;
}
int startresizetext ( int x , int y ) {
SDL_Rect area ;
int txoff , tyoff ;
if ( map [ curmap ] . textob [ map [ curmap ] . curtext ] . anchor = = - 1 ) {
txoff = 0 ;
tyoff = 0 ;
} else {
txoff = map [ curmap ] . obj [ map [ curmap ] . textob [ map [ curmap ] . curtext ] . anchor ] . x ;
tyoff = map [ curmap ] . obj [ map [ curmap ] . textob [ map [ curmap ] . curtext ] . anchor ] . y ;
}
startx = x ;
starty = y ;
changestate ( S_TEXTRESIZING ) ;
/* copy background */
bg = SDL_CreateRGBSurface ( SDL_SWSURFACE , map [ curmap ] . width , map [ curmap ] . height ,
screen - > format - > BitsPerPixel , screen - > format - > Rmask ,
screen - > format - > Gmask , screen - > format - > Bmask ,
screen - > format - > Amask ) ;
area . x = map [ curmap ] . textob [ map [ curmap ] . curtext ] . x + txoff ;
area . y = map [ curmap ] . textob [ map [ curmap ] . curtext ] . y + tyoff ;
area . w = map [ curmap ] . textob [ map [ curmap ] . curtext ] . w + 2 ;
area . h = map [ curmap ] . textob [ map [ curmap ] . curtext ] . h + 2 ;
SDL_BlitSurface ( screen , & area , bg , 0 ) ;
bgx = area . x ;
bgy = area . y ;
bgw = area . w ;
bgh = area . h ;
return 0 ;
}
int starttextmove ( int x , int y ) {
SDL_Rect area ;
int txoff , tyoff ;
if ( map [ curmap ] . textob [ map [ curmap ] . curtext ] . anchor = = - 1 ) {
txoff = 0 ;
tyoff = 0 ;
} else {
txoff = map [ curmap ] . obj [ map [ curmap ] . textob [ map [ curmap ] . curtext ] . anchor ] . x ;
tyoff = map [ curmap ] . obj [ map [ curmap ] . textob [ map [ curmap ] . curtext ] . anchor ] . y ;
}
xoff = map [ curmap ] . textob [ map [ curmap ] . curtext ] . x - x + txoff ;
yoff = map [ curmap ] . textob [ map [ curmap ] . curtext ] . y - y + tyoff ;
startx = x ;
starty = y ;
changestate ( S_TEXTMOVING ) ;
/* copy background */
bg = SDL_CreateRGBSurface ( SDL_SWSURFACE , map [ curmap ] . textob [ map [ curmap ] . curtext ] . w , map [ curmap ] . textob [ map [ curmap ] . curtext ] . h ,
screen - > format - > BitsPerPixel , screen - > format - > Rmask ,
screen - > format - > Gmask , screen - > format - > Bmask ,
screen - > format - > Amask ) ;
area . x = map [ curmap ] . textob [ map [ curmap ] . curtext ] . x + txoff ;
area . y = map [ curmap ] . textob [ map [ curmap ] . curtext ] . y + tyoff ;
area . w = map [ curmap ] . textob [ map [ curmap ] . curtext ] . w ;
area . h = map [ curmap ] . textob [ map [ curmap ] . curtext ] . h ;
SDL_BlitSurface ( screen , & area , bg , 0 ) ;
bgx = area . x ;
bgy = area . y ;
bgw = area . w ;
bgh = area . h ;
return 0 ;
}
int textat ( int x , int y ) {
int i , anchor ;
for ( i = 0 ; i < map [ curmap ] . numtext ; i + + ) {
anchor = map [ curmap ] . textob [ i ] . anchor ;
if ( anchor = = - 1 ) {
if ( ( x > = map [ curmap ] . textob [ i ] . x ) & & ( x < = ( map [ curmap ] . textob [ i ] . x + map [ curmap ] . textob [ i ] . w ) ) & &
( y > = map [ curmap ] . textob [ i ] . y ) & & ( y < = ( map [ curmap ] . textob [ i ] . y + map [ curmap ] . textob [ i ] . h ) ) ) {
return i ;
}
} else {
if ( ( x > = map [ curmap ] . textob [ i ] . x + map [ curmap ] . obj [ anchor ] . x ) & & ( x < = ( map [ curmap ] . textob [ i ] . x + map [ curmap ] . obj [ anchor ] . x + map [ curmap ] . textob [ i ] . w ) ) & &
( y > = map [ curmap ] . textob [ i ] . y + map [ curmap ] . obj [ anchor ] . y ) & & ( y < = ( map [ curmap ] . textob [ i ] . y + map [ curmap ] . obj [ anchor ] . y + map [ curmap ] . textob [ i ] . h ) ) ) {
return i ;
}
}
}
return - 1 ;
}
int thingat ( int x , int y ) {
int i ;
int anchor ;
for ( i = ( map [ curmap ] . numthings - 1 ) ; i > = 0 ; i - - ) {
switch ( map [ curmap ] . thing [ i ] . type ) {
case T_OBJECT :
if ( ( x > = map [ curmap ] . obj [ map [ curmap ] . thing [ i ] . id ] . x ) & &
( x < = ( map [ curmap ] . obj [ map [ curmap ] . thing [ i ] . id ] . x + map [ curmap ] . obj [ map [ curmap ] . thing [ i ] . id ] . w ) ) & &
( y > = map [ curmap ] . obj [ map [ curmap ] . thing [ i ] . id ] . y ) & &
( y < = ( map [ curmap ] . obj [ map [ curmap ] . thing [ i ] . id ] . y + map [ curmap ] . obj [ map [ curmap ] . thing [ i ] . id ] . h ) ) ) {
return i ;
}
break ;
case T_LINK :
if ( isonlink ( map [ curmap ] . thing [ i ] . id , x , y ) ) {
return i ;
}
break ;
case T_TEXT :
anchor = map [ curmap ] . textob [ map [ curmap ] . thing [ i ] . id ] . anchor ;
if ( anchor = = - 1 ) {
if ( ( x > = map [ curmap ] . textob [ map [ curmap ] . thing [ i ] . id ] . x ) & & ( x < = ( map [ curmap ] . textob [ map [ curmap ] . thing [ i ] . id ] . x + map [ curmap ] . textob [ map [ curmap ] . thing [ i ] . id ] . w ) ) & &
( y > = map [ curmap ] . textob [ map [ curmap ] . thing [ i ] . id ] . y ) & & ( y < = ( map [ curmap ] . textob [ map [ curmap ] . thing [ i ] . id ] . y + map [ curmap ] . textob [ map [ curmap ] . thing [ i ] . id ] . h ) ) ) {
return i ;
}
} else {
if ( ( x > = map [ curmap ] . textob [ map [ curmap ] . thing [ i ] . id ] . x + map [ curmap ] . obj [ anchor ] . x ) & & ( x < = ( map [ curmap ] . textob [ map [ curmap ] . thing [ i ] . id ] . x + map [ curmap ] . obj [ anchor ] . x + map [ curmap ] . textob [ map [ curmap ] . thing [ i ] . id ] . w ) ) & &
( y > = map [ curmap ] . textob [ map [ curmap ] . thing [ i ] . id ] . y + map [ curmap ] . obj [ anchor ] . y ) & & ( y < = ( map [ curmap ] . textob [ map [ curmap ] . thing [ i ] . id ] . y + map [ curmap ] . obj [ anchor ] . y + map [ curmap ] . textob [ map [ curmap ] . thing [ i ] . id ] . h ) ) ) {
return i ;
}
}
break ;
}
}
return - 1 ;
}
int updatefilename ( void ) {
int y ;
SDL_Rect sarea ;
SDL_Rect area ;
SDL_Color ccol = blue ;
text_t temp ;
/* paste old background */
if ( bg ! = NULL ) {
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 ) ;
// free it
SDL_FreeSurface ( bg ) ;
}
/* copy new background */
sarea . x = startx ;
sarea . y = starty ;
sarea . w = ( ( strlen ( text ) + 1 ) * ( DEFTEXTW * 2 ) ) + 2 ; // include space for cursor
sarea . h = DEFTEXTH * 2 ;
bg = SDL_CreateRGBSurface ( SDL_SWSURFACE , sarea . w , sarea . h ,
screen - > format - > BitsPerPixel , screen - > format - > Rmask ,
screen - > format - > Gmask , screen - > format - > Bmask ,
screen - > format - > Amask ) ;
SDL_BlitSurface ( screen , & sarea , bg , 0 ) ;
bgx = sarea . x ;
bgy = sarea . y ;
/* draw text */
strcpy ( temp . text , text ) ;
temp . x = startx ;
temp . y = starty ;
temp . w = strlen ( text ) * ( DEFTEXTW * 2 ) ;
temp . h = DEFTEXTH * 2 ;
temp . c = black ;
temp . anchor = - 1 ;
drawtext ( screen , & temp ) ;
/* draw cursor (a solid block) */
for ( y = starty ; y < ( starty + ( DEFTEXTH * 2 ) ) ; y + + ) {
2005-10-30 19:45:37 +11:00
drawline ( screen , startx + temp . w , y , startx + temp . w + DEFTEXTW * 2 , y , ccol , 1 ) ;
2005-10-25 16:35:55 +10:00
}
SDL_UpdateRect ( screen , startx , starty , temp . w + DEFTEXTW * 2 , DEFTEXTH * 2 ) ;
return FALSE ;
}
int updatelinkshadow ( int x , int y ) {
int len ;
int w , h ;
int tlx , tly ;
int linex1 , liney1 , linex2 , liney2 ;
/* replace old bg */
pasteline ( screen , linebg ) ;
/* copy current bg */
linex1 = startx ;
liney1 = starty ;
linex2 = x ;
liney2 = y ;
len = linelen ( linex1 , liney1 , linex2 , liney2 ) ;
linebg = malloc ( ( len + 4 ) * sizeof ( int ) ) ;
copyline ( screen , linex1 , liney1 , linex2 , liney2 , linebg ) ;
/* draw line */
2005-10-30 19:45:37 +11:00
drawline ( screen , startx , starty , x , y , map [ curmap ] . boxcol , 1 ) ;
2005-10-25 16:35:55 +10:00
if ( x < startx ) {
if ( y < starty ) {
tlx = x ;
tly = y ;
w = startx - x ;
h = starty - y ;
} else {
tlx = x ;
tly = starty ;
w = startx - x ;
h = y - starty ;
}
} else {
if ( y < starty ) {
tlx = startx ;
tly = y ;
w = x - startx ;
h = starty - y ;
} else {
tlx = startx ;
tly = starty ;
w = x - startx ;
h = y - starty ;
}
}
SDL_UpdateRect ( screen , tlx , tly , w , h ) ;
return 0 ;
}
int updatelinkpointshadow ( int x , int y ) {
int linex1 , liney1 , linex2 , liney2 ;
SDL_Rect area ;
int ty ;
/* paste old bg */
area . x = bgx ;
area . y = bgy ;
area . w = bg - > w ;
area . h = bg - > h ;
SDL_BlitSurface ( bg , 0 , screen , & area ) ;
SDL_UpdateRect ( screen , area . x , area . y , area . w , area . h ) ;
/* copy background */
linex1 = x - ( LINESELHANDLESIZE / 2 ) ;
liney1 = y - ( LINESELHANDLESIZE / 2 ) ;
linex2 = x + ( LINESELHANDLESIZE / 2 ) + 4 ;
liney2 = y + ( LINESELHANDLESIZE / 2 ) + 4 ;
bg = SDL_CreateRGBSurface ( SDL_SWSURFACE , LINESELHANDLESIZE , LINESELHANDLESIZE ,
screen - > format - > BitsPerPixel , screen - > format - > Rmask ,
screen - > format - > Gmask , screen - > format - > Bmask ,
screen - > format - > Amask ) ;
bgx = linex1 ;
bgy = liney1 ;
bgw = LINESELHANDLESIZE + 4 ;
bgh = LINESELHANDLESIZE + 4 ;
area . x = linex1 ;
area . y = liney1 ;
area . w = LINESELHANDLESIZE ;
area . h = LINESELHANDLESIZE ;
SDL_BlitSurface ( screen , & area , bg , 0 ) ;
/* draw link point */
for ( ty = liney1 ; ty < ( liney1 + LINESELHANDLESIZE - 1 ) ; ty + + ) {
2005-10-30 19:45:37 +11:00
drawline ( screen , linex1 , ty , linex1 + LINESELHANDLESIZE - 1 , ty , black , 1 ) ;
2005-10-25 16:35:55 +10:00
}
//SDL_UpdateRect(screen, linex1, liney1, linex2, liney2);
SDL_Flip ( screen ) ;
return FALSE ;
}
int updatemoveshadow ( int x , int y ) {
SDL_Rect area ;
if ( ( x + xoff ) < 0 ) xoff = - x ;
if ( ( y + yoff ) < 0 ) yoff = - y ;
x + = xoff ;
y + = yoff ;
/* replace old bg */
area . x = bgx ;
area . y = bgy ;
area . w = bgw ;
area . h = bgh ;
SDL_BlitSurface ( bg , 0 , screen , & area ) ;
SDL_UpdateRect ( screen , area . x , area . y , area . w , area . h ) ;
/* copy current bg */
area . x = x ;
area . y = y ;
area . w = map [ curmap ] . obj [ map [ curmap ] . curobj ] . w ;
area . h = map [ curmap ] . obj [ map [ curmap ] . curobj ] . h ;
SDL_BlitSurface ( screen , & area , bg , 0 ) ;
bgx = area . x ;
bgy = area . y ;
bgw = area . w ;
bgh = area . h ;
/* 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 ) ) {
2005-10-30 19:45:37 +11:00
drawline ( screen , x , y , x + map [ curmap ] . obj [ map [ curmap ] . curobj ] . w - 1 , y , map [ curmap ] . boxcol , 1 ) ;
drawline ( screen , x , y , x , y + map [ curmap ] . obj [ map [ curmap ] . curobj ] . h - 1 , map [ curmap ] . boxcol , 1 ) ;
drawline ( screen , x , y + map [ curmap ] . obj [ map [ curmap ] . curobj ] . h - 1 , x + map [ curmap ] . obj [ map [ curmap ] . curobj ] . w - 1 , y + map [ curmap ] . obj [ map [ curmap ] . curobj ] . h - 1 , map [ curmap ] . boxcol , 1 ) ;
drawline ( screen , x + map [ curmap ] . obj [ map [ curmap ] . curobj ] . w - 1 , y , x + map [ curmap ] . obj [ map [ curmap ] . curobj ] . w - 1 , y + map [ curmap ] . obj [ map [ curmap ] . curobj ] . h - 1 , map [ curmap ] . boxcol , 1 ) ;
2005-10-25 16:35:55 +10:00
}
SDL_UpdateRect ( screen , area . x , area . y , area . w , area . h ) ;
return 0 ;
}
int updateresizeshadow ( int x , int y ) {
SDL_Rect sarea ;
SDL_Rect area ;
int xdiff , ydiff ;
xdiff = x - startx ;
ydiff = y - starty ;
/* check for maximum object sizes */
if ( ( map [ curmap ] . obj [ map [ curmap ] . curobj ] . w + xdiff ) > MAXOBJWIDTH ) xdiff = MAXOBJWIDTH - map [ curmap ] . obj [ map [ curmap ] . curobj ] . w ;
if ( ( map [ curmap ] . obj [ map [ curmap ] . curobj ] . h + ydiff ) > MAXOBJHEIGHT ) ydiff = MAXOBJHEIGHT - map [ curmap ] . obj [ map [ curmap ] . curobj ] . h ;
if ( ( map [ curmap ] . obj [ map [ curmap ] . curobj ] . w + xdiff ) < MINOBJWIDTH ) xdiff = MINOBJWIDTH - map [ curmap ] . obj [ map [ curmap ] . curobj ] . w ;
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 ) {
xdiff = 0 ;
}
if ( ( map [ curmap ] . obj [ map [ curmap ] . curobj ] . y + map [ curmap ] . obj [ map [ curmap ] . curobj ] . h + ydiff ) > = map [ curmap ] . height ) {
ydiff = 0 ;
//ydiff = (map[curmap].height - map[curmap].obj[map[curmap].curobj].h);
}
/* replace old bg */
area . x = bgx ;
area . y = bgy ;
area . w = bgw ;
area . h = bgh ;
sarea . x = 0 ;
sarea . y = 0 ;
sarea . w = bgw ;
sarea . h = bgh ;
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 . 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 ;
if ( area . h < MINOBJHEIGHT ) area . h = MINOBJHEIGHT ;
SDL_BlitSurface ( screen , & area , bg , 0 ) ;
bgx = area . x ;
bgy = area . y ;
bgw = area . w ;
bgh = area . h ;
/* draw box */
drawline ( screen , map [ curmap ] . obj [ map [ curmap ] . curobj ] . x , map [ curmap ] . obj [ map [ curmap ] . curobj ] . y ,
2005-10-30 19:45:37 +11:00
map [ curmap ] . obj [ map [ curmap ] . curobj ] . x + map [ curmap ] . obj [ map [ curmap ] . curobj ] . w + xdiff , map [ curmap ] . obj [ map [ curmap ] . curobj ] . y , map [ curmap ] . boxcol , 1 ) ;
2005-10-25 16:35:55 +10:00
drawline ( screen , map [ curmap ] . obj [ map [ curmap ] . curobj ] . x , map [ curmap ] . obj [ map [ curmap ] . curobj ] . y ,
2005-10-30 19:45:37 +11:00
map [ curmap ] . obj [ map [ curmap ] . curobj ] . x , map [ curmap ] . obj [ map [ curmap ] . curobj ] . y + map [ curmap ] . obj [ map [ curmap ] . curobj ] . h + ydiff , map [ curmap ] . boxcol , 1 ) ;
2005-10-25 16:35:55 +10:00
drawline ( screen , map [ curmap ] . obj [ map [ curmap ] . curobj ] . x + map [ curmap ] . obj [ map [ curmap ] . curobj ] . w + xdiff , map [ curmap ] . obj [ map [ curmap ] . curobj ] . y ,
2005-10-30 19:45:37 +11:00
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 , map [ curmap ] . boxcol , 1 ) ;
2005-10-25 16:35:55 +10:00
drawline ( screen , map [ curmap ] . obj [ map [ curmap ] . curobj ] . x , map [ curmap ] . obj [ map [ curmap ] . curobj ] . y + map [ curmap ] . obj [ map [ curmap ] . curobj ] . h + ydiff ,
2005-10-30 19:45:37 +11:00
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 , map [ curmap ] . boxcol , 1 ) ;
2005-10-25 16:35:55 +10:00
SDL_UpdateRect ( screen , area . x , area . y , area . w , area . h ) ;
return 0 ;
}
int updateresizetextshadow ( int x , int y ) {
SDL_Rect sarea ;
SDL_Rect area ;
int xdiff , ydiff ;
int txoff , tyoff ;
2005-10-27 14:46:38 +10:00
int textsize ;
char * tp ;
int tw , th ;
2005-10-25 16:35:55 +10:00
if ( map [ curmap ] . textob [ map [ curmap ] . curtext ] . anchor = = - 1 ) {
txoff = 0 ;
tyoff = 0 ;
} else {
txoff = map [ curmap ] . obj [ map [ curmap ] . textob [ map [ curmap ] . curtext ] . anchor ] . x ;
tyoff = map [ curmap ] . obj [ map [ curmap ] . textob [ map [ curmap ] . curtext ] . anchor ] . y ;
}
2005-10-27 14:46:38 +10:00
//
2005-10-25 16:35:55 +10:00
ydiff = y - starty ;
2005-10-27 14:46:38 +10:00
//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;
2005-10-29 16:37:41 +10:00
if ( ( map [ curmap ] . textob [ map [ curmap ] . curtext ] . h + ydiff ) > = MAXLETTERHEIGHT ) ydiff = MAXLETTERHEIGHT - map [ curmap ] . textob [ map [ curmap ] . curtext ] . h - 1 ;
2005-10-27 14:46:38 +10:00
//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 ;
2005-10-25 16:35:55 +10:00
if ( ( map [ curmap ] . textob [ map [ curmap ] . curtext ] . h + ydiff ) < MINLETTERHEIGHT ) ydiff = MINLETTERHEIGHT - map [ curmap ] . textob [ map [ curmap ] . curtext ] . h ;
2005-10-27 14:46:38 +10:00
/* 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 ;
2005-10-25 16:35:55 +10:00
/* replace old bg */
area . x = bgx ;
area . y = bgy ;
area . w = bgw ;
area . h = bgh ;
sarea . x = 0 ;
sarea . y = 0 ;
sarea . w = bgw ;
sarea . h = bgh ;
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 [ map [ curmap ] . curtext ] . x + txoff ;
area . y = map [ curmap ] . textob [ map [ curmap ] . curtext ] . y + tyoff ;
area . w = map [ curmap ] . textob [ map [ curmap ] . curtext ] . w + xdiff + 2 ;
area . h = map [ curmap ] . textob [ map [ curmap ] . curtext ] . h + ydiff + 2 ;
if ( area . w < strlen ( map [ curmap ] . textob [ map [ curmap ] . curtext ] . text ) * MINLETTERWIDTH ) area . w = strlen ( map [ curmap ] . textob [ map [ curmap ] . curtext ] . text ) * MINLETTERWIDTH ;
if ( area . h < MINLETTERHEIGHT ) area . h = MINLETTERHEIGHT ;
if ( area . w > strlen ( map [ curmap ] . textob [ map [ curmap ] . curtext ] . text ) * MAXLETTERWIDTH ) area . w = strlen ( map [ curmap ] . textob [ map [ curmap ] . curtext ] . text ) * MAXLETTERWIDTH ;
if ( area . h > MAXLETTERHEIGHT ) area . h = MAXLETTERHEIGHT ;
SDL_BlitSurface ( screen , & area , bg , 0 ) ;
bgx = area . x ;
bgy = area . y ;
bgw = area . w ;
bgh = area . h ;
/* draw box */
drawline ( screen , map [ curmap ] . textob [ map [ curmap ] . curtext ] . x + txoff , map [ curmap ] . textob [ map [ curmap ] . curtext ] . y + tyoff ,
2005-10-30 19:45:37 +11:00
map [ curmap ] . textob [ map [ curmap ] . curtext ] . x + txoff + map [ curmap ] . textob [ map [ curmap ] . curtext ] . w + xdiff , map [ curmap ] . textob [ map [ curmap ] . curtext ] . y + tyoff , map [ curmap ] . boxcol , 1 ) ;
2005-10-25 16:35:55 +10:00
drawline ( screen , map [ curmap ] . textob [ map [ curmap ] . curtext ] . x + txoff , map [ curmap ] . textob [ map [ curmap ] . curtext ] . y + tyoff ,
2005-10-30 19:45:37 +11:00
map [ curmap ] . textob [ map [ curmap ] . curtext ] . x + txoff , map [ curmap ] . textob [ map [ curmap ] . curtext ] . y + tyoff + map [ curmap ] . textob [ map [ curmap ] . curtext ] . h + ydiff , map [ curmap ] . boxcol , 1 ) ;
2005-10-25 16:35:55 +10:00
drawline ( screen , map [ curmap ] . textob [ map [ curmap ] . curtext ] . x + txoff + map [ curmap ] . textob [ map [ curmap ] . curtext ] . w + xdiff , map [ curmap ] . textob [ map [ curmap ] . curtext ] . y + tyoff ,
2005-10-30 19:45:37 +11:00
map [ curmap ] . textob [ map [ curmap ] . curtext ] . x + txoff + map [ curmap ] . textob [ map [ curmap ] . curtext ] . w + xdiff , map [ curmap ] . textob [ map [ curmap ] . curtext ] . y + tyoff + map [ curmap ] . textob [ map [ curmap ] . curtext ] . h + ydiff , map [ curmap ] . boxcol , 1 ) ;
2005-10-25 16:35:55 +10:00
drawline ( screen , map [ curmap ] . textob [ map [ curmap ] . curtext ] . x + txoff , map [ curmap ] . textob [ map [ curmap ] . curtext ] . y + tyoff + map [ curmap ] . textob [ map [ curmap ] . curtext ] . h + ydiff ,
2005-10-30 19:45:37 +11:00
map [ curmap ] . textob [ map [ curmap ] . curtext ] . x + txoff + map [ curmap ] . textob [ map [ curmap ] . curtext ] . w + xdiff , map [ curmap ] . textob [ map [ curmap ] . curtext ] . y + tyoff + map [ curmap ] . textob [ map [ curmap ] . curtext ] . h + ydiff , map [ curmap ] . boxcol , 1 ) ;
2005-10-25 16:35:55 +10:00
SDL_UpdateRect ( screen , area . x , area . y , area . w , area . h ) ;
return 0 ;
}
int updatetextcursor ( void ) {
int y ;
SDL_Rect sarea ;
SDL_Rect area ;
SDL_Color ccol = blue ;
text_t temp ;
2005-10-27 14:46:38 +10:00
int tw , th ;
2005-10-25 16:35:55 +10:00
if ( ( state = = S_SAVING ) | | ( state = = S_LOADING ) | | ( state = = S_MAPNAMING ) ) {
showfiledialog ( ) ;
return 0 ;
}
/* paste old background */
if ( bg ! = NULL ) {
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 ) ;
// free it
SDL_FreeSurface ( bg ) ;
}
/* copy new background */
sarea . x = startx ;
sarea . y = starty ;
2005-10-27 14:46:38 +10:00
/* calculate text width */
2005-10-29 16:37:41 +10:00
TTF_SizeText ( font [ updateheight ] , text , & tw , & th ) ;
2005-10-27 14:46:38 +10:00
sarea . w = tw + CURSORWIDTH + 3 ;
sarea . h = th ;
//sarea.h = DEFTEXTH;
//sarea.w = ((strlen(text)+1) * (DEFTEXTW)) +2; // include space for cursor
2005-10-25 16:35:55 +10:00
bg = SDL_CreateRGBSurface ( SDL_SWSURFACE , sarea . w , sarea . h ,
screen - > format - > BitsPerPixel , screen - > format - > Rmask ,
screen - > format - > Gmask , screen - > format - > Bmask ,
screen - > format - > Amask ) ;
SDL_BlitSurface ( screen , & sarea , bg , 0 ) ;
bgx = sarea . x ;
bgy = sarea . y ;
/* draw text */
strcpy ( temp . text , text ) ;
temp . x = startx ;
temp . y = starty ;
2005-10-27 14:46:38 +10:00
temp . w = tw ;
2005-10-29 16:37:41 +10:00
temp . h = updateheight ;
2005-10-25 16:35:55 +10:00
temp . c = fgcol ;
temp . anchor = - 1 ;
drawtext ( screen , & temp ) ;
/* draw cursor (a solid block) */
2005-10-27 14:46:38 +10:00
for ( y = starty ; y < ( starty + th ) ; y + + ) {
2005-10-30 19:45:37 +11:00
drawline ( screen , startx + tw + 1 , y , startx + tw + CURSORWIDTH , y , ccol , 1 ) ;
2005-10-25 16:35:55 +10:00
}
2005-10-27 14:46:38 +10:00
SDL_UpdateRect ( screen , startx , starty , tw + CURSORWIDTH + 3 , th ) ;
2005-10-25 16:35:55 +10:00
return FALSE ;
}
int endlink ( int x , int y ) {
int endxoff , endyoff ;
int i ;
2005-10-30 19:45:37 +11:00
Uint8 style , arrow , thickness ;
2005-10-25 16:35:55 +10:00
/* replace old bg */
pasteline ( screen , linebg ) ;
/* check if we've exceeded the max number of links */
if ( ( map [ curmap ] . numlinks + 1 ) > = MAXLINKS ) {
sprintf ( statustext , " ERROR: Maximum link count (%d) exceeded. " , MAXLINKS ) ;
return TRUE ;
}
/*
endxoff = x - map [ curmap ] . obj [ endobj ] . x ;
endyoff = y - map [ curmap ] . obj [ endobj ] . y ;
*/
/* centre offsets*/
xoff = ( map [ curmap ] . obj [ startobj ] . w / 2 ) ;
yoff = ( map [ curmap ] . obj [ startobj ] . h / 2 ) ;
endxoff = ( map [ curmap ] . obj [ endobj ] . w / 2 ) ;
endyoff = ( map [ curmap ] . obj [ endobj ] . h / 2 ) ;
map [ curmap ] . olink [ map [ curmap ] . numlinks ] . srcobj = startobj ;
map [ curmap ] . olink [ map [ curmap ] . numlinks ] . srcxoff = xoff ;
map [ curmap ] . olink [ map [ curmap ] . numlinks ] . srcyoff = yoff ;
map [ curmap ] . olink [ map [ curmap ] . numlinks ] . dstobj = endobj ;
map [ curmap ] . olink [ map [ curmap ] . numlinks ] . dstxoff = endxoff ;
map [ curmap ] . olink [ map [ curmap ] . numlinks ] . dstyoff = endyoff ;
map [ curmap ] . olink [ map [ curmap ] . numlinks ] . col = fgcol ;
map [ curmap ] . olink [ map [ curmap ] . numlinks ] . npoints = 0 ;
2005-10-30 19:45:37 +11:00
arrow = defarrow ;
style = defstyle ;
thickness = defthickness ;
map [ curmap ] . olink [ map [ curmap ] . numlinks ] . style = ( arrow < < 16 ) | ( style < < 8 ) | ( thickness ) ;
2005-10-25 16:35:55 +10:00
/* add to 'thing' list */
/* links start at the bottom of the thing list */
/* shuffle all things up */
for ( i = ( map [ curmap ] . numthings - 1 ) ; i > = 0 ; i - - ) {
map [ curmap ] . thing [ i + 1 ] . type = map [ curmap ] . thing [ i ] . type ;
map [ curmap ] . thing [ i + 1 ] . id = map [ curmap ] . thing [ i ] . id ;
}
map [ curmap ] . thing [ 0 ] . type = T_LINK ;
map [ curmap ] . thing [ 0 ] . id = map [ curmap ] . numlinks ;
modified = TRUE ;
sprintf ( statustext , " Link #%d created (from obj #%d to obj #%d). \n " , map [ curmap ] . numlinks , startobj , endobj ) ;
map [ curmap ] . numlinks + + ;
map [ curmap ] . numthings + + ;
drawstatusbar ( ) ;
return 0 ;
}
int endlinkdstmove ( int x , int y ) {
int o ;
/* free variable */
if ( linebg ) free ( linebg ) ;
/* find which map[curmap].object it's over */
o = objat ( x , y ) ;
if ( o = = - 1 ) {
/* if it's not over an map[curmap].object, abort the move */
changestate ( S_NONE ) ;
map [ curmap ] . curlink = - 1 ;
sprintf ( statustext , " Move of link #%d dst endpoint aborted. \n " , map [ curmap ] . curlink ) ;
} else if ( o = = map [ curmap ] . olink [ map [ curmap ] . curlink ] . dstobj ) {
/* if over the same map[curmap].object, update offsets */
map [ curmap ] . olink [ map [ curmap ] . curlink ] . dstxoff = x - map [ curmap ] . obj [ o ] . x ;
map [ curmap ] . olink [ map [ curmap ] . curlink ] . dstyoff = y - map [ curmap ] . obj [ o ] . y ;
modified = TRUE ;
sprintf ( statustext , " Link #%d dst endpoint moved to offset (+%d,+%d). \n " , map [ curmap ] . curlink , map [ curmap ] . olink [ map [ curmap ] . curlink ] . dstxoff , map [ curmap ] . olink [ map [ curmap ] . curlink ] . dstyoff ) ;
} else {
/* else if over a new map[curmap].object, update map[curmap].objid and offsets */
map [ curmap ] . olink [ map [ curmap ] . curlink ] . dstobj = o ;
map [ curmap ] . olink [ map [ curmap ] . curlink ] . dstxoff = x - map [ curmap ] . obj [ o ] . x ;
map [ curmap ] . olink [ map [ curmap ] . curlink ] . dstyoff = y - map [ curmap ] . obj [ o ] . y ;
modified = TRUE ;
sprintf ( statustext , " Link #%d dst endpoint moved to object %d(+%d,+%d). \n " , map [ curmap ] . curlink , o , map [ curmap ] . olink [ map [ curmap ] . curlink ] . dstxoff , map [ curmap ] . olink [ map [ curmap ] . curlink ] . dstyoff ) ;
}
drawstatusbar ( ) ;
return 0 ;
}
int endlinkpointmove ( int x , int y ) {
/* free variable */
if ( bg ) free ( bg ) ;
map [ curmap ] . olink [ map [ curmap ] . curlink ] . point [ map [ curmap ] . curlinkpoint ] . x = x ;
map [ curmap ] . olink [ map [ curmap ] . curlink ] . point [ map [ curmap ] . curlinkpoint ] . y = y ;
modified = TRUE ;
sprintf ( statustext , " Link #%d point #%d moved to (%d,%d). \n " , map [ curmap ] . curlink , map [ curmap ] . curlinkpoint , map [ curmap ] . olink [ map [ curmap ] . curlink ] . point [ map [ curmap ] . curlinkpoint ] . x , map [ curmap ] . olink [ map [ curmap ] . curlink ] . point [ map [ curmap ] . curlinkpoint ] . y ) ;
drawstatusbar ( ) ;
return 0 ;
}
int endlinksrcmove ( int x , int y ) {
int o ;
/* free variable */
if ( linebg ) free ( linebg ) ;
/* find which map[curmap].object it's over */
o = objat ( x , y ) ;
if ( o = = - 1 ) {
/* if it's not over an map[curmap].object, abort the move */
changestate ( S_NONE ) ;
map [ curmap ] . curlink = - 1 ;
sprintf ( statustext , " Move of link #%d src endpoint aborted. \n " , map [ curmap ] . curlink ) ;
} else if ( o = = map [ curmap ] . olink [ map [ curmap ] . curlink ] . srcobj ) {
/* if over the same map[curmap].object, update offsets */
map [ curmap ] . olink [ map [ curmap ] . curlink ] . srcxoff = x - map [ curmap ] . obj [ o ] . x ;
map [ curmap ] . olink [ map [ curmap ] . curlink ] . srcyoff = y - map [ curmap ] . obj [ o ] . y ;
modified = TRUE ;
sprintf ( statustext , " Link #%d src endpoint moved to offset (+%d,+%d). \n " , map [ curmap ] . curlink , map [ curmap ] . olink [ map [ curmap ] . curlink ] . srcxoff , map [ curmap ] . olink [ map [ curmap ] . curlink ] . srcyoff ) ;
} else {
/* else if over a new map[curmap].object, update map[curmap].objid and offsets */
map [ curmap ] . olink [ map [ curmap ] . curlink ] . srcobj = o ;
map [ curmap ] . olink [ map [ curmap ] . curlink ] . srcxoff = x - map [ curmap ] . obj [ o ] . x ;
map [ curmap ] . olink [ map [ curmap ] . curlink ] . srcyoff = y - map [ curmap ] . obj [ o ] . y ;
modified = TRUE ;
sprintf ( statustext , " Link #%d src endpoint moved to object %d(+%d,+%d). \n " , map [ curmap ] . curlink , o , map [ curmap ] . olink [ map [ curmap ] . curlink ] . srcxoff , map [ curmap ] . olink [ map [ curmap ] . curlink ] . srcyoff ) ;
}
drawstatusbar ( ) ;
return 0 ;
}
int endlinkmove ( int x , int y ) {
/* free variable */
//printf("about to free linebg (0x%x)\n",linebg); fflush(stdout);
if ( linebg ) free ( linebg ) ;
modified = TRUE ;
/* TODO: move the line */
return 0 ;
}
void drillto ( int mapnum ) {
2005-10-31 13:20:14 +11:00
printf ( " drilling to: %d \n " , mapnum ) ;
if ( mapnum = = C_NONE ) {
2005-10-25 16:35:55 +10:00
if ( nummaps < ( MAXMAPS - 1 ) ) {
/* push current map */
history [ numhistory ] = curmap ;
numhistory + + ;
/* change child */
map [ curmap ] . obj [ map [ curmap ] . selecteditem ] . child = nummaps ;
/* create a new map */
initmap ( nummaps ) ;
/* select the new map */
2005-10-30 22:50:06 +11:00
changemap ( nummaps ) ;
2005-10-25 16:35:55 +10:00
nummaps + + ;
sprintf ( statustext , " Drilled down (new map created). " ) ;
startx = 1 ;
starty = ( map [ curmap ] . height / 2 ) - 2 ;
bg = NULL ;
strcpy ( text , map [ curmap ] . name ) ;
changestate ( S_MAPNAMING ) ;
drawmap ( ) ;
} else {
sprintf ( statustext , " ERROR: Maximum number of maps reached. " ) ;
drawstatusbar ( ) ;
}
2005-10-31 13:20:14 +11:00
} else if ( mapnum = = C_SCROLLUP ) {
mapbox . offset - - ;
drawmapbox ( ) ;
} else if ( mapnum = = C_SCROLLDOWN ) {
mapbox . offset + + ;
drawmapbox ( ) ;
2005-10-25 16:35:55 +10:00
} else {
/* push current map */
history [ numhistory ] = curmap ;
numhistory + + ;
2005-10-30 22:50:06 +11:00
changemap ( mapnum ) ;
2005-10-25 16:35:55 +10:00
sprintf ( statustext , " Drilled down into map #%d (%s). " , curmap , map [ curmap ] . name ) ;
drawmap ( ) ;
}
}
int endobjmove ( int x , int y ) {
SDL_FreeSurface ( bg ) ;
/* check position */
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 ;
}
if ( map [ curmap ] . obj [ map [ curmap ] . curobj ] . x + x - startx < = 0 ) {
return - 1 ;
}
modified = TRUE ;
map [ curmap ] . obj [ map [ curmap ] . curobj ] . x + = ( x - startx ) ;
map [ curmap ] . obj [ map [ curmap ] . curobj ] . y + = ( y - starty ) ;
return 0 ;
}
int endresize ( int x , int y ) {
int origw , origh ;
int neww , newh ;
int i ;
float xscale , yscale ;
SDL_FreeSurface ( bg ) ;
origw = map [ curmap ] . obj [ map [ curmap ] . curobj ] . w ;
origh = map [ curmap ] . obj [ map [ curmap ] . curobj ] . h ;
neww = map [ curmap ] . obj [ map [ curmap ] . curobj ] . w ;
newh = map [ curmap ] . obj [ map [ curmap ] . curobj ] . h ;
if ( map [ curmap ] . obj [ map [ curmap ] . curobj ] . w + ( x - startx ) > 0 ) {
neww = map [ curmap ] . obj [ map [ curmap ] . curobj ] . w + ( x - startx ) ;
}
if ( map [ curmap ] . obj [ map [ curmap ] . curobj ] . h + ( y - starty ) > 0 ) {
newh = map [ curmap ] . obj [ map [ curmap ] . curobj ] . h + ( y - starty ) ;
}
if ( neww < MINOBJWIDTH ) neww = MINOBJWIDTH ;
if ( newh < MINOBJHEIGHT ) newh = MINOBJHEIGHT ;
if ( neww > MAXOBJWIDTH ) neww = MAXOBJWIDTH ;
if ( newh > MAXOBJHEIGHT ) newh = MAXOBJHEIGHT ;
if ( map [ curmap ] . obj [ map [ curmap ] . curobj ] . x + neww > = map [ curmap ] . width ) {
neww = map [ curmap ] . width - map [ curmap ] . obj [ map [ curmap ] . curobj ] . x - 1 ;
}
if ( map [ curmap ] . obj [ map [ curmap ] . curobj ] . y + newh > = map [ curmap ] . height ) {
newh = map [ curmap ] . height - map [ curmap ] . obj [ map [ curmap ] . curobj ] . y - 1 ;
}
map [ curmap ] . obj [ map [ curmap ] . curobj ] . w = neww ;
map [ curmap ] . obj [ map [ curmap ] . curobj ] . h = newh ;
/* update default map[curmap].object size */
objtype [ map [ curmap ] . obj [ map [ curmap ] . curobj ] . type ] . defw = neww ;
objtype [ map [ curmap ] . obj [ map [ curmap ] . curobj ] . type ] . defh = newh ;
/* scale all link endpoints in this map[curmap].object */
xscale = ( float ) neww / ( float ) origw ;
yscale = ( float ) newh / ( float ) origh ;
for ( i = 0 ; i < map [ curmap ] . numlinks ; i + + ) {
if ( map [ curmap ] . olink [ i ] . srcobj = = map [ curmap ] . curobj ) {
map [ curmap ] . olink [ i ] . srcxoff = map [ curmap ] . olink [ i ] . srcxoff * xscale ;
map [ curmap ] . olink [ i ] . srcyoff = map [ curmap ] . olink [ i ] . srcyoff * yscale ;
}
if ( map [ curmap ] . olink [ i ] . dstobj = = map [ curmap ] . curobj ) {
map [ curmap ] . olink [ i ] . dstxoff = map [ curmap ] . olink [ i ] . dstxoff * xscale ;
map [ curmap ] . olink [ i ] . dstyoff = map [ curmap ] . olink [ i ] . dstyoff * yscale ;
}
}
/* scale x,y of any text anchored to this map[curmap].object */
for ( i = 0 ; i < map [ curmap ] . numtext ; i + + ) {
if ( map [ curmap ] . textob [ i ] . anchor = = map [ curmap ] . curobj ) {
map [ curmap ] . textob [ i ] . x = map [ curmap ] . textob [ i ] . x * xscale ;
map [ curmap ] . textob [ i ] . y = map [ curmap ] . textob [ i ] . y * yscale ;
}
}
modified = TRUE ;
drawmap ( ) ;
return 0 ;
}
int endtextresize ( int x , int y ) {
int origw , origh ;
int neww , newh ;
2005-10-27 14:46:38 +10:00
char * tp ;
int tw , th ;
2005-10-25 16:35:55 +10:00
SDL_FreeSurface ( bg ) ;
origw = map [ curmap ] . textob [ map [ curmap ] . curtext ] . w ;
origh = map [ curmap ] . textob [ map [ curmap ] . curtext ] . h ;
neww = map [ curmap ] . textob [ map [ curmap ] . curtext ] . w ;
newh = map [ curmap ] . textob [ map [ curmap ] . curtext ] . h ;
if ( map [ curmap ] . textob [ map [ curmap ] . curtext ] . h + ( y - starty ) > 0 ) {
newh = map [ curmap ] . textob [ map [ curmap ] . curtext ] . h + ( y - starty ) ;
}
2005-10-27 14:46:38 +10:00
/* check for valid height */
2005-10-25 16:35:55 +10:00
if ( newh < MINLETTERHEIGHT ) newh = MINLETTERHEIGHT ;
2005-10-27 14:46:38 +10:00
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 ) ;
2005-10-27 17:00:32 +10:00
neww = tw ;
2005-10-25 16:35:55 +10:00
if ( ( map [ curmap ] . textob [ map [ curmap ] . curtext ] . x + neww ) > = map [ curmap ] . width ) neww = map [ curmap ] . width - map [ curmap ] . textob [ map [ curmap ] . curtext ] . x - 1 ;
map [ curmap ] . textob [ map [ curmap ] . curtext ] . w = neww ;
map [ curmap ] . textob [ map [ curmap ] . curtext ] . h = newh ;
/* update default text size */
/* TODO: is this useful? */
/*
objtype [ map [ curmap ] . obj [ map [ curmap ] . curobj ] . type ] . defw = neww ;
objtype [ map [ curmap ] . obj [ map [ curmap ] . curobj ] . type ] . defh = newh ;
*/
modified = TRUE ;
drawmap ( ) ;
return 0 ;
}
int updatetextshadow ( int x , int y ) {
SDL_Rect area ;
x + = xoff ;
y + = yoff ;
if ( x < 0 ) x = 0 ;
if ( y < 0 ) y = 0 ;
/* replace old bg */
area . x = bgx ;
area . y = bgy ;
area . w = bgw ;
area . h = bgh ;
SDL_BlitSurface ( bg , 0 , screen , & area ) ;
SDL_UpdateRect ( screen , area . x , area . y , area . w , area . h ) ;
/* copy current bg */
area . x = x ;
area . y = y ;
area . w = map [ curmap ] . textob [ map [ curmap ] . curtext ] . w ;
area . h = map [ curmap ] . textob [ map [ curmap ] . curtext ] . h ;
SDL_BlitSurface ( screen , & area , bg , 0 ) ;
bgx = area . x ;
bgy = area . y ;
bgw = area . w ;
bgh = area . h ;
/* draw box */
if ( ( x > 0 ) & & ( y > 0 ) & & ( x + map [ curmap ] . textob [ map [ curmap ] . curtext ] . w - 1 < map [ curmap ] . width ) & & ( y + map [ curmap ] . textob [ map [ curmap ] . curtext ] . h - 1 < map [ curmap ] . height ) ) {
2005-10-30 19:45:37 +11:00
drawline ( screen , x , y , x + map [ curmap ] . textob [ map [ curmap ] . curtext ] . w - 1 , y , map [ curmap ] . boxcol , 1 ) ;
drawline ( screen , x , y , x , y + map [ curmap ] . textob [ map [ curmap ] . curtext ] . h - 1 , map [ curmap ] . boxcol , 1 ) ;
drawline ( screen , x , y + map [ curmap ] . textob [ map [ curmap ] . curtext ] . h - 1 , x + map [ curmap ] . textob [ map [ curmap ] . curtext ] . w - 1 , y + map [ curmap ] . textob [ map [ curmap ] . curtext ] . h - 1 , map [ curmap ] . boxcol , 1 ) ;
drawline ( screen , x + map [ curmap ] . textob [ map [ curmap ] . curtext ] . w - 1 , y , x + map [ curmap ] . textob [ map [ curmap ] . curtext ] . w - 1 , y + map [ curmap ] . textob [ map [ curmap ] . curtext ] . h - 1 , map [ curmap ] . boxcol , 1 ) ;
2005-10-25 16:35:55 +10:00
}
SDL_UpdateRect ( screen , area . x , area . y , area . w , area . h ) ;
return 0 ;
}