/* Everything related to representation of special points */ #include "common.h" #include "archive.h" #include "datalib.h" #include "visual.h" #include "diagram.h" #include "curve.h" #include "function.h" #include "help.h" #include "point.h" extern Global(CharPtr PNTR) PointTxt; /* defined in text.c */ enum { /* see setup.c, init[], /point */ OPT_C, /* Waiting for attributes changing */ POINT_I, /* Special points */ TYPE_P, /* Set options for points of type */ LABEL_B, /* Label */ MARKER_B, /* marker */ SETCOLOR_B, /* Set color */ DEFCOLOR_B, /* Default color */ SAMPLE_T, /* Sample */ SCALE_T /* Scale factor */ } PointTxtIndex; #define SIDE 9 /* canonical size of a marker is SIDExSIDE */ #define HALF (SIDE/2) /***********************/ /* List of curve types */ /***********************/ typedef struct { CharPtr title; /* full name */ CharPtr label; /* short label */ Int2 type; /* code */ Color color; /* -1 - default */ Int1 marker; /* -1 - default */ Boolean labelyes; /* FALSE - no label */ } SPType, PNTR SPTypePtr; Local(Int2) SPTypeNum=0; Local(SPTypePtr) SPTypes=NULL; /* Returns label and color for special points */ Global(Boolean) GetSPAttr(Int2 type, CharPtr PNTR Label, ColorPtr Color) { Int2 i; for (i=0; i=0 && num=0 || (pb && SPTypes[i].labelyes); return FALSE; } /* Hardcopy data (see llString & STRMARKER in visual.c) */ Local(float) Q1[6]={ 0.25, 0.25, 0, 0, HALF, HALF}; Local(float) Q2[6]={-0.25, 0.25,-1, 0,-HALF, HALF}; Local(float) Q3[6]={-0.25,-0.25,-1,-1,-HALF,-HALF}; Local(float) Q4[6]={ 0.25,-0.25, 0,-1, HALF,-HALF}; /* Draws Special Point using its current attributes */ Global(void) DrawSpecialPoint(Int2 x, Int2 y, Int2 pointtype, Color bg, Boolean labelyes) { CharPtr lp; Int2 i,w,h; Int2 off,lx,ly; float PNTR Qp; DrawAttr attr; for (i=0; i=0 || SPTypes[i].labelyes) { if (SPTypes[i].marker>=0) { InvertColors(); ColorSet(bg); InvertColors(); lMoveTo(x,y); attr.style=1; attr.width=1; SetCurrentPen(&attr); DrawMarker(SPTypes[i].marker); } /* Label */ if (pb && SPTypes[i].labelyes && labelyes) { lp=ccd.localpointType&USERPOINT ? GetSPname(ccd.localpointType,FALSE) : SPTypes[i].label; h=LineHeight()-Descent(); w=StringWidth(lp)+2; off=HALF*scale[Scale]+1; /* canonical size of marker is 9x9 */ if (dx*dy<0) { /* [0,90]+[180,270] */ if (dx>-dy) { /* [0,45]+[225,270] */ lx=x-off-w; ly=y-off; Qp=Q2; } else { /* (45,90]+[180,225) */ lx=x+off; ly=y+off+h; Qp=Q4; } } else { /* (90,180)+(270,360) */ if (dx>dy) { /* (90,135]+[315,360) */ lx=x-off-w; ly=y+off+h; Qp=Q3; } else { /* (135,180)+(270,315) */ lx=x+off; ly=y-off; Qp=Q1; } } llString(lx,ly,lp,Qp); } goto done; } else break; } lPoint(x,y); done: pb=FALSE; } Local(ButtoN) cbLabel; Local(ButtoN) cbMarker; Local(ButtoN) cbDefColor; Local(ButtoN) btSetColor; Local(PopuP) plTypes; /* Names of special points */ Local(PaneL) paMarkers; /* Markers */ Local(PaneL) paCurType; /* name of current type */ Local(PaneL) paCurMarker; /* panel with current marker */ Local(PaneL) paCurLabel; /* current label */ Local(BaR) mbar; /* marker panel's bar */ Local(Int2) CurType; /* currently selected list item-1 */ Local(void) RedrawCurrent(void); /* Type of special point callback */ /* Note that index zero to SPTypes corresponds to ordinary points which aren't represented in plTypes list */ Local(void) TypeProc(PopuP pl) { CurType=GetValue(pl); RedrawCurrent(); } /* Label yes/no callback */ Local(void) LabelProc(ButtoN b) { SPTypes[CurType].labelyes=GetStatus(b); RedrawCurrent(); } /* Marker draw callback */ Local(void) MarkerDrawProc(PaneL marker) { RecT r,rr; PoinT pt; Int2 l,i,n,o; o=GetValue(mbar); Select(marker); GetPosition(marker,&r); l=r.bottom-r.top-1; n=(r.right-r.left)/l; rr.top=r.top+1; rr.bottom=r.bottom-1; if (o+n>=MarkerNum) n=MarkerNum-o; for (i=0; i>1; pt.y=(rr.top+rr.bottom)>>1; SetPen(pt); DrawMarker(o+i); } } #if _WIN #pragma argsused #endif /* Marker scroll calback */ Local(void) MarkerScrollProc(BaR bar, GraphiC g, Int2 new, Int2 old) { Redraw(paMarkers); } /* Marker selection callback */ Local(void) MarkerSelProc(PaneL marker, PoinT pt) { RecT r; Int2 l; Select(marker); GetPosition(marker,&r); l=r.bottom-r.top-1; SPTypes[CurType].marker=(pt.x-r.left)/l+GetValue(mbar); SetStatus(cbMarker,TRUE); RedrawCurrent(); } /* Marker chechbox callback */ Local(void) MarkerProc(ButtoN cb) { SPTypes[CurType].marker=GetStatus(cb) ? 0 : -1; RedrawCurrent(); } Local(void) DefColorProc(ButtoN cb) { if (GetStatus(cb)) SPTypes[CurType].color=-1; else SPTypes[CurType].color=ColorAsk(SPTypes[CurType].color); RedrawCurrent(); } #if _WIN #pragma argsused #endif Local(void) ColorProc(ButtoN bt) { SPTypes[CurType].color=ColorAsk(SPTypes[CurType].color); SetStatus(cbDefColor,FALSE); RedrawCurrent(); } Local(void) ScaleProc(GrouP gScale) { Scale=GetValue(gScale); Redraw(paMarkers); RedrawCurrent(); } Local(void) PrepRect(PaneL p, RectPtr r) { Int2 h; Select(p); SelectFont(SystemFont); GetPosition(p,r); h=(r->bottom-r->top)>>1; r->top+=h-((sysAscent>>1)+sysLeading); r->bottom-=h-((sysAscent>>1)+sysDescent); } Local(void) CurTypeProc(PaneL paCurType) { RecT r; PrepRect(paCurType,&r); DrawString(&r,SPTypes[CurType].title,'l',FALSE); } Local(void) CurMarkerProc(PaneL paCurMarker) { RecT r; PoinT pt; Select(paCurMarker); GetPosition(paCurMarker,&r); ColorSet(SPTypes[CurType].color); InvertColors(); PaintRect(&r); InvertColors(); if (SPTypes[CurType].marker>=0) { pt.x=(r.left+r.right)>>1; pt.y=(r.top+r.bottom)>>1; SetPen(pt); DrawMarker(SPTypes[CurType].marker); } } Local(void) CurLabelProc(PaneL paCurLabel) { RecT r; PrepRect(paCurLabel,&r); ColorSet(SPTypes[CurType].color); DrawString(&r,SPTypes[CurType].labelyes ? SPTypes[CurType].label : "",'l',FALSE); } /* Reads diagram related map type-marker-color-label; Otherwise [creates and] reads default map */ Global(void) ReadMarkerMap(void) { FloatLo sc=0; Int2 i,j,num; SPType sp; Int1 n; Boolean lib; if (CurDiagram) { DataLibSavePos(&DiagramLib); while (!DataLibUp(&DiagramLib)); lib=DataLibFind(&DiagramLib,CURM_PART)==0; if (lib) { DataLibRead(&DiagramLib,(CharPtr)(&sc), sizeof(scale[0])); for (; DataLibRead(&DiagramLib,(CharPtr)&n,sizeof(n))==sizeof(n); ) { /* entry 0 is unused (ordinaty points) */ DataLibRead(&DiagramLib,(CharPtr)&SPTypes[0].marker, sizeof(SPTypes[0].marker)); DataLibRead(&DiagramLib,(CharPtr)&SPTypes[0].color, sizeof(SPTypes[0].color)); DataLibRead(&DiagramLib,(CharPtr)&SPTypes[0].labelyes, sizeof(SPTypes[0].labelyes)); for (i=0 ; i1) DataLibUp(&ArchivesLib); if (DataLibFind(&ArchivesLib,PART_DEFM)==0) { DataLibRead(&ArchivesLib,(CharPtr)&sc,sizeof(sc)); DataLibRead(&ArchivesLib,(CharPtr)&num,sizeof(num)); for (i=0; i1) DataLibUp(&ArchivesLib); if (DataLibFind(&ArchivesLib,PART_DEFM)==0) DataLibDelete(&ArchivesLib); DataLibCreate(&ArchivesLib,PART_DEFM); DataLibWrite(&ArchivesLib,(CharPtr)&scale[Scale],sizeof(scale[Scale])); DataLibWrite(&ArchivesLib,(CharPtr)&SPTypeNum,sizeof(SPTypeNum)); for (i=0; i=0) { n=(Int1)i; fscanf(in," %i %li %i\n",&i,&rgb,&l); /* entry 0 is unused (ordinaty points) */ SPTypes[0].marker=(Int1)i; SPTypes[0].color=ColorIn(rgb); SPTypes[0].labelyes=(Boolean)l; DataLibWrite(dgm,(CharPtr)&n,sizeof(n)); DataLibWrite(dgm,(CharPtr)&SPTypes[0].marker,sizeof(SPTypes[0].marker)); DataLibWrite(dgm,(CharPtr)&SPTypes[0].color,sizeof(SPTypes[0].color)); DataLibWrite(dgm,(CharPtr)&SPTypes[0].labelyes,sizeof(SPTypes[0].labelyes)); } }