/* viDOOM - level editor for DOOM Copyright (C) 2000 Ian Cowburn (ianc@noddybox.demon.co.uk) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ------------------------------------------------------------------------- General editor drawing routines */ static const char rcs_id[]="$Id$"; #include "config.h" #include "globals.h" #include #include "editvar.h" /* ---------------------------------------- DRAWING FUNCTIONS */ void DrawArrow(int x1,int y1,int x2,int y2,int c) { int dx,dy; double ang; int x,y; VIDOOM_TRACE; dx=x1-x2; dy=y1-y2; /* Calc angle that the line is at */ if (dx==0) if (dy<0) ang=RAD(0); else ang=RAD(180); else if (dy==0) if (dx<0) ang=RAD(90); else ang=RAD(270); else { ang=atan((double)dx/(double)dy); if (dy>0) ang-=RAD(180); } MapLine(x1,y1,x2,y2,c); x=(int)(x2-sin(ang-RAD(25))*12.0); y=(int)(y2-cos(ang-RAD(25))*12.0); MapLine(x2,y2,x,y,c); x=(int)(x2-sin(ang+RAD(25))*12.0); y=(int)(y2-cos(ang+RAD(25))*12.0); MapLine(x2,y2,x,y,c); } void DrawGrid(void) { int c; VIDOOM_TRACE; if (!grid_onoff) return; agrid=grid_size; while((agrid/scale)<8) agrid*=2; c=YToMap(0); while(c%agrid) c++; while(c>YToMap(SCRH-1)) { GFX_line(0,MapToY(c),SCRW-1,MapToY(c),GRIDCOL); c-=agrid; } c=ox; while(c%agrid) c--; while(cdata; if (l) { /* LINEDEFS can move if we're in certain edit modes */ if (edit_mode!=THING_MODE) LineCalcBounding(l); if (edit_mode!=SECTOR_MODE) if (LineOnDisplay(l)) switch(edit_mode) { case VERTEX_MODE: case MULTI_MODE: DrawArrow(l->v[0]->v.x,l->v[0]->v.y, l->v[1]->v.x,l->v[1]->v.y,LINECOL); break; case LINEDEF_MODE: DrawObject_LINEDEF(l,o->select); break; case THING_MODE: MapLineD(l,LINECOL); break; } } } if ((edit_mode==VERTEX_MODE)||(edit_mode==MULTI_MODE)) for(f=0;fdata; if (v) if (PointOnDisplay(v->v.x,v->v.y,vertex_rad)) DrawObject_VERTEX(v,o->select); } /* Sectors are drawn in a number of passes as selected sectors can quite easily be overdrtawn by unselected ones */ if (edit_mode==SECTOR_MODE) { for(f=0;fdata; if (s) { SectorCalcBounding(s); if (SectorOnDisplay(s)) DrawObject_SECTOR(s,o->select); } } i=ListIterator(selected); while(i) { sv=IteratorData(i); o=MapElem(sector,*sv); s=o->data; if (s) { SectorCalcBounding(s); if (SectorOnDisplay(s)) DrawObject_SECTOR(s,o->select); } i=IteratorNext(i); } /* This slightly dodgy check is because sectors (as explained) do not order themselves very well. This check wil put the currently hovered-over object back on top of the display. */ if (current!=-1) { o=MapElem(sector,current); s=o->data; if (s) { SectorCalcBounding(s); if (SectorOnDisplay(s)) DrawObject_SECTOR(s,o->select); } } } for(f=0;fdata; if (t) if ((edit_mode==THING_MODE)||(edit_mode==MULTI_MODE)) { if (PointOnDisplay(t->t.x,t->t.y,ThingRadius(t->t.type,NULL))) DrawObject_THING(t,o->select); } else if (PointOnDisplay(t->t.x,t->t.y,8)) { MapLine(t->t.x-8,t->t.y,t->t.x+8,t->t.y,THINGCOL); MapLine(t->t.x,t->t.y-8,t->t.x,t->t.y+8,THINGCOL); } } } void DrawHeader(void) { #ifdef VIDOOM_DEBUG static int chk=TRUE; static int db=FALSE; #endif VIDOOM_TRACE; if (hexen_mode) GFX_frect(0,0,SCRW,FH*2,RED); else GFX_frect(0,0,SCRW,FH*2,BLUE); GFX_print(0,0,WHITE,"Mode: %-8s Pos: %d,%d", edit_str[edit_mode],XToMap(ms.x),YToMap(ms.y)); if (grid_onoff) GFX_print(SCRW/2,0,WHITE,"Scale: %-2d Lock: %-3s Grid : %d/%d", scale,YESNO(grid_lock),grid_size,agrid); else GFX_print(SCRW/2,0,WHITE,"Scale: %-2d Lock: %-3s Grid : %d", scale,YESNO(grid_lock),grid_size); DrawObjectHeader(); #ifdef VIDOOM_DEBUG /* Debug */ if (chk) { if ((getenv("VIDOOM_VDEBUG"))&&(!strcmp(getenv("VIDOOM_VDEBUG"),"Y"))) db=TRUE; else db=FALSE; chk=FALSE; } if (db) { static char ds[128]; int y; Iterator i; int *f; GFX_frect(0,FH*2,SCRW,FH*2,RED); GFX_print(0,FH*2,WHITE,"ox=%d oy=%d " "SectorHoldingPoint(%d,%d)=%d " "ListSize(selected)=%d", ox,oy, XToMap(ms.x),YToMap(ms.y), SectorHoldingPoint(XToMap(ms.x),YToMap(ms.y)), ListSize(selected)); i=ListIterator(selected); ds[0]=0; y=FH*3; while(i) { f=IteratorData(i); if (strlen(ds)>70) { GFX_print(0,y,WHITE,ds); ds[0]=0; y+=FH; } sprintf(ds+strlen(ds),"%d, ",*f); i=IteratorNext(i); } strcat(ds,""); GFX_print(0,y,WHITE,"%s",ds); } #endif } void FullRedraw(void) { VIDOOM_TRACE; GFX_mouse(&ms.x,&ms.y); GFX_clear(BLACK); DrawGrid(); DrawMap(); DrawObjectInfo(); DrawHeader(); } /* END OF FILE */