1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471 |
- #include "cmGlobal.h"
- #include "cmFloatTypes.h"
- #include "cmRpt.h"
- #include "cmErr.h"
- #include "cmCtx.h"
- #include "cmErr.h"
- #include "cmMem.h"
- #include "cmMallocDebug.h"
- #include "cmGr.h"
- #include "cmGrDevCtx.h"
- #include "cmGrPlot.h"
- #include "cmGrPage.h"
- #include "cmVectOpsTemplateMain.h"
-
-
- enum
- {
- kHashLength = 6,
- kHashCharCnt = 10,
- kMaxHashCnt = 10
- };
-
- enum
- {
- kNotValidFl = 0x01,
- kDirtyFl = 0x02, // set if the layout is dirty
- kFocusFl = 0x04
- };
-
- typedef struct
- {
- cmGrPPt_t xy0; //
- cmGrPPt_t xy1; // xy1 is on iext
- } cmGrPgHash_t;
-
- struct cmGrPgVw_str;
- struct cmGrPgAxis_str;
- struct cmGrPg_str;
-
- typedef struct cmGrPgLabelFunc_str
- {
- unsigned id;
- cmGrLabelFunc_t func;
- void* arg;
- cmChar_t* label;
- struct cmGrPgLabelFunc_str* link;
- } cmGrPgLabelFunc_t;
-
- typedef struct cmGrPgAxis_str
- {
- struct cmGrPgVw_str* vp;
- unsigned flags; // kHashMarkGrFl | kHashLabelGrFl
- unsigned hashCnt;
- unsigned hashLength;
- cmChar_t* title;
-
- cmGrPgHash_t* hash;
-
- unsigned maxHashCnt;
-
- cmGrPPt_t titlePt; // position of the axis title
- unsigned titleFontId; // title font id
- unsigned titleFontStyle; // title font style
- unsigned titleFontSize; // title font size
-
- cmGrPPt_t labelPt; // x = l/r label pos. and y=t/b label pos.
- unsigned labelFontId; // label font id
- unsigned labelFontStyle; // label font style
- unsigned labelFontSize; // label font size
-
- cmGrPgLabelFunc_t* func;
- } cmGrPgAxis_t;
-
- typedef struct cmGrPgVw_str
- {
- struct cmGrPg_str* p;
- cmGrH_t grH;
- unsigned ri; // row index
- unsigned ci; // column index
- cmGrPExt_t pext; // page around outside of view
- cmGrPExt_t iext; // view physical extents
- cmGrPgAxis_t axis[ kAxisGrCnt ]; //
- cmGrPPt_t titlePt; // lower/center position of the view title
- cmChar_t* title; // view title (upper center)
- unsigned fontId; // title font id
- unsigned fontStyle; // title font style
- unsigned fontSize; // title font size
-
- cmGrPgLabelFunc_t* xfunc;
- cmGrPgLabelFunc_t* yfunc;
- } cmGrPgVw_t;
-
- typedef struct cmGrPg_str
- {
- cmCtx_t ctx;
- cmErr_t err;
- cmGrCbFunc_t cbFunc;
- void* cbArg;
- unsigned flags; // kNotValidFl
- cmGrPExt_t pext; // outer border around all views
- unsigned rn; // count of rows
- unsigned cn; // count of columns
- unsigned vn; // view count (rn*cn)
- double* rpropV; // sum(rprop[rn]) == 1.0 pgaction of r.w() assigned to each row
- double* cpropV; // sum(cprop[cn]) == 1.0 pgaction of r.h() assigned to each row
- cmGrPgVw_t* viewV; // viewV[vn]
- unsigned focusIdx; // focused view index
-
- cmGrPPt_t titlePt; //
- cmChar_t* title; // page title
- unsigned fontId; // title font id
- unsigned fontStyle; // title font style
- unsigned fontSize; // title font size
-
- unsigned labelFuncId; // next page label function id
- cmGrPgLabelFunc_t* funcs; // linked list of value to string translation functions
-
- } cmGrPg_t;
-
- cmGrPgH_t cmGrPgNullHandle = cmSTATIC_NULL_HANDLE;
- cmGrVwH_t cmGrVwNullHandle = cmSTATIC_NULL_HANDLE;
- cmGrAxH_t cmGrAxNullHandle = cmSTATIC_NULL_HANDLE;
-
- cmGrPg_t* _cmGrPgHandleToPtr( cmGrPgH_t h )
- {
- cmGrPg_t* p = (cmGrPg_t*)h.h;
- assert( p!=NULL);
- return p;
- }
-
- cmGrPgVw_t* _cmGrPgVwHandleToPtr( cmGrVwH_t h )
- {
- cmGrPgVw_t* p = (cmGrPgVw_t*)h.h;
- assert( p!=NULL);
- return p;
- }
-
- cmGrPgAxis_t* _cmGrPgAxisHandleToPtr( cmGrAxH_t h )
- {
- cmGrPgAxis_t* p = (cmGrPgAxis_t*)h.h;
- assert( p!=NULL);
- return p;
- }
-
-
- void _cmGrPgVwAxisDestroy( cmGrPgAxis_t* ap )
- {
- ap->func = NULL;
-
- cmMemFree(ap->hash);
- cmMemFree(ap->title);
- }
-
- void _cmGrPgVwDestroy( cmGrPgVw_t* vp )
- {
- unsigned i;
-
- cmGrDestroy( &vp->grH );
-
- cmMemFree(vp->title);
- for(i=0; i<kAxisGrCnt; ++i)
- _cmGrPgVwAxisDestroy(vp->axis + i );
- }
-
- void _cmGrPgFinal( cmGrPg_t* p )
- {
- unsigned i;
- for(i=0; i<p->vn; ++i)
- _cmGrPgVwDestroy( p->viewV + i );
-
- cmGrPgLabelFunc_t* lfp = p->funcs;
- while( lfp != NULL )
- {
- cmGrPgLabelFunc_t* np = lfp->link;
- cmMemFree(lfp->label);
- cmMemFree(lfp);
- lfp = np;
- }
-
- p->funcs = NULL;
-
- cmMemFree(p->viewV);
- cmMemFree(p->title);
- cmMemFree(p->rpropV);
- cmMemFree(p->cpropV);
- }
-
- cmGrRC_t _cmGrPgDestroy( cmGrPg_t* p )
- {
- cmGrRC_t rc = kOkGrRC;
- _cmGrPgFinal(p);
- cmMemFree(p);
- return rc;
- }
-
- unsigned _cmGrPgGrHandleToVwIndex( cmGrPg_t* p, cmGrH_t grH )
- {
- unsigned i;
- for(i=0; i<p->vn; ++i)
- if( cmHandlesAreEqual(p->viewV[i].grH,grH) )
- return i;
-
- return cmInvalidIdx;
- }
-
- void _cmGrPageCallback( void* arg, cmGrH_t grH, cmGrCbId_t id, unsigned eventFlags, cmGrKeyCodeId_t keycode )
- {
- cmGrPg_t* p = (cmGrPg_t*)arg;
-
- switch(id)
- {
- case kCreateCbGrId:
- case kDestroyCbGrId:
- case kLocalPtCbGrId:
- case kGlobalPtCbGrId:
- case kPhysExtCbGrId:
- case kViewExtCbGrId:
- case kSelectExtCbGrId:
- if( p->cbFunc != NULL )
- p->cbFunc(p->cbArg,grH,id,eventFlags,keycode);
- break;
-
- case kKeyUpCbGrId:
- case kKeyDnCbGrId:
- {
- cmGrVwH_t vwH;
- cmGrPgH_t pgH;
- pgH.h = p;
- if(cmGrViewIsValid(vwH =cmGrPageFocusedView(pgH)))
- if( p->cbFunc != NULL )
- p->cbFunc(p->cbArg,cmGrViewGrHandle(vwH),id,eventFlags,keycode);
-
- }
- break;
-
- case kFocusCbGrId:
- {
- unsigned i;
- if((i = _cmGrPgGrHandleToVwIndex(p,grH)) != cmInvalidIdx )
- {
- cmGrPgH_t h;
- h.h = p;
-
- // if the focus is changing
- if( i != p->focusIdx )
- {
- // inform the prev view that it is losing focus
- if( p->focusIdx != cmInvalidIdx )
- cmGrPageViewFocus(h,p->focusIdx,false);
-
- // inform the new view that it is gaining focus
- cmGrPageViewFocus(h,i,true);
-
- if( p->cbFunc != NULL )
- p->cbFunc(p->cbArg,grH,id,eventFlags,keycode);
- }
- }
- }
- break;
-
- default:
- { assert(0); }
- }
- }
-
-
-
- cmGrRC_t cmGrPageCreate( cmCtx_t* ctx, cmGrPgH_t* hp, cmGrCbFunc_t cbFunc, void* cbArg )
- {
- cmGrRC_t rc;
- if((rc = cmGrPageDestroy(hp)) != kOkGrRC )
- return rc;
-
- cmGrPg_t* p = cmMemAllocZ(cmGrPg_t,1);
-
- cmErrSetup(&p->err,&ctx->rpt,"cmGrPage");
- p->cbFunc = cbFunc;
- p->cbArg = cbArg;
- p->ctx = *ctx;
- hp->h = p;
-
- if(rc != kOkGrRC )
- _cmGrPgDestroy(p);
- return rc;
- }
-
- cmGrRC_t cmGrPageDestroy( cmGrPgH_t* hp )
- {
- cmGrRC_t rc;
- if(hp==NULL || cmGrPageIsValid(*hp) == false )
- return kOkGrRC;
-
- cmGrPg_t* p = _cmGrPgHandleToPtr(*hp);
-
- if((rc = _cmGrPgDestroy(p)) != kOkGrRC )
- return rc;
-
- hp->h = NULL;
-
- return rc;
- }
-
- bool cmGrPageIsValid( cmGrPgH_t h )
- { return h.h != NULL; }
-
- cmGrRC_t cmGrPageClear( cmGrPgH_t h )
- {
- cmGrRC_t rc = kOkGrRC;
- unsigned i;
- for(i=0; i<cmGrPageViewCount(h); ++i)
- {
- cmGrVwH_t vwH = cmGrPageViewHandle(h,i);
- assert( cmGrViewIsValid(vwH) );
- if((rc = cmGrViewClear(vwH)) != kOkGrRC )
- break;
- }
-
- return rc;
- }
-
-
- // Calcuate the position of each view using the p->pext, and the row/col proportion vectors
- // This function calculates the outer page around each view.
- // It must be called whenever the size of the window holding the page changes.
- bool _cmGrPgLayoutVwPosition( cmGrPg_t* p )
- {
- enum { kVBord=4, kHBord=4 };
-
- // verify that the page state is sane
- if( p->rn==0 || p->cn==0 || p->pext.sz.h==0 || p->pext.sz.w==0)
- goto errLabel;
-
- else
- {
- unsigned i,j;
- int x=p->pext.loc.x;
- int y=p->pext.loc.y;
-
- // calculate the total page width/height w/o internal borders
- int h = p->pext.sz.h - ((p->rn - 1) * kVBord);
- int w = p->pext.sz.w - ((p->cn - 1) * kHBord);
-
- // verify that the page area exists
- if( h<=0 || w<=0 )
- goto errLabel;
-
- // force the row/col proportion vectors to sum to 1.0
- cmVOD_NormalizeProbability(p->rpropV,p->rn);
- cmVOD_NormalizeProbability(p->cpropV,p->cn);
-
- // determine the row height
- for(i=0; i<p->rn; ++i)
- {
- unsigned hh = (unsigned)floor(p->rpropV[i] * h);
-
- if( hh == 0 )
- goto errLabel;
-
- for(j=0; j<p->vn; ++j)
- if( p->viewV[j].ri == i )
- {
- p->viewV[j].pext.loc.y = y;
- p->viewV[j].pext.sz.h = hh;
- }
-
- y += hh + kVBord;
- }
-
- // determine the column width
- for(i=0; i<p->cn; ++i)
- {
- unsigned ww = (unsigned)floor(p->cpropV[i] * w);
-
- if( ww == 0 )
- goto errLabel;
-
- for(j=0; j<p->vn; ++j)
- if( p->viewV[j].ci == i )
- {
- p->viewV[j].pext.loc.x = x;
- p->viewV[j].pext.sz.w = ww;
- }
-
- x += ww + kHBord;
- }
-
- p->flags = cmClrFlag(p->flags,kNotValidFl);
-
-
- return true;
- }
-
- errLabel:
- p->flags = cmSetFlag(p->flags,kNotValidFl);
-
- return false;
- }
-
- // Calculate the layout for a given view.
- // txW = max hash label width on x-axis
- // txH = hash label height on x-axis
- void _cmGrPgLayoutView( cmGrPg_t* p, cmGrPgVw_t* vp, cmGrDcH_t dcH )
- {
- enum { kVBord=2, kHBord=2 };
-
- int x0 = vp->pext.loc.x + kHBord;
- int y0 = vp->pext.loc.y + kVBord;
- int w = vp->pext.sz.w - 2*kHBord;
- int h = vp->pext.sz.h - 2*kVBord;
-
- int y = y0;
- int x = x0;
-
- cmGrPSz_t sz;
-
-
- // Create a negative string with a repeating decimal to simulate an arbitrary hash label
- // Use the measurements from this string to compute the geometry of the view layouts.
- char label[ kHashCharCnt + 1];
- snprintf(label,kHashCharCnt,"%f",-4.0/3.0);
- label[kHashCharCnt] = 0;
-
- int mlx,mrx,mty,mby;
- int i;
-
- // add vertical space for the view title
- if( vp->title != NULL )
- {
- cmGrDcFontSetAndMeasure(dcH, vp->fontId, vp->fontSize, vp->fontStyle, vp->title, &sz );
- y += sz.h;
- vp->titlePt.y = y;
- vp->titlePt.x = vp->pext.loc.x + vp->pext.sz.w/2;
- y += 2;
- }
-
- cmGrPgAxis_t* ap = vp->axis + kTopGrIdx;
-
- // add vertical space for the top axis title
- if( ap->title != NULL )
- {
- cmGrDcFontSetAndMeasure(dcH, ap->titleFontId, ap->titleFontSize, ap->titleFontStyle, ap->title, &sz );
- y += sz.h;
- ap->titlePt.y = y;
- y += 4;
- }
-
- // add vertical space for top axis hash labels
- if( cmIsFlag(ap->flags,kHashLabelGrFl ) )
- {
- cmGrDcFontSetAndMeasure(dcH, ap->labelFontId, ap->labelFontSize, ap->labelFontStyle, label, &sz );
- y += sz.h;
- ap->labelPt.y = y;
- y += 1;
- }
-
- // calc vertical space for top axis hash marks
- if( cmIsFlag(ap->flags,kHashMarkGrFl ) )
- {
- mty = y;
- y += ap->hashLength + 1;
- }
-
- // set the internal pext vertical location
- vp->iext.loc.y = y;
-
- ap = vp->axis + kBottomGrIdx;
- y = y0 + h - 1 - kVBord;
-
- // subtract vertical space for bottom axis title
- if( ap->title != NULL )
- {
- cmGrDcFontSetAndMeasure(dcH, ap->titleFontId, ap->titleFontSize, ap->titleFontStyle, ap->title, &sz );
- ap->titlePt.y = y;
- y -= sz.h + 4;
- }
-
- // calc vertical space for bottom axis hash label
- if( cmIsFlag(ap->flags,kHashLabelGrFl) )
- {
- cmGrDcFontSetAndMeasure(dcH, ap->labelFontId, ap->labelFontSize, ap->labelFontStyle, label, &sz );
- ap->labelPt.y = y;
- y -= sz.h + 2;
- }
-
- // calc vertical space for bottom axis hash mark
- if( cmIsFlag(ap->flags,kHashMarkGrFl) )
- {
- mby = y;
- y -= ap->hashLength + 1;
- }
-
- // set the internal pext height
- vp->iext.sz.h = y - vp->iext.loc.y + 1;
-
-
- ap = vp->axis + kLeftGrIdx;
-
- // add horizontal space for the left axis title
- if( ap->title != NULL )
- {
- cmGrDcFontSetAndMeasure(dcH, ap->titleFontId, ap->titleFontSize, ap->titleFontStyle, ap->title, &sz );
-
- x += sz.h; // use txH as approx of char. width for rotated title
- ap->titlePt.x = x;
- x += 4;
- }
-
- // add horizontal space for left axis hash labels
- if( cmIsFlag(ap->flags,kHashLabelGrFl ) )
- {
- cmGrDcFontSetAndMeasure(dcH, ap->labelFontId, ap->labelFontSize, ap->labelFontStyle, label, &sz );
-
- ap->labelPt.x = x;
- x += sz.w + 3;
- }
-
- // calc horizontal space for left axis hash marks
- if( cmIsFlag(ap->flags,kHashMarkGrFl ) )
- {
- mlx = x;
- x += ap->hashLength + 1;
- }
-
- // set the internal pext horz location
- vp->iext.loc.x = x;
-
- ap = vp->axis + kRightGrIdx;
- x = x0 + w - 1 - kVBord;
-
- // subtract horizontal space for right axis title
- if( ap->title != NULL )
- {
- cmGrDcFontSetAndMeasure(dcH, ap->titleFontId, ap->titleFontSize, ap->titleFontStyle, ap->title, &sz );
-
- ap->titlePt.x = x;
- x -= sz.h + 2; // use txH as approx of char. width for rotated title
- }
-
- // calc horizontal space for right axis hash label
- if( cmIsFlag(ap->flags,kHashLabelGrFl) )
- {
- cmGrDcFontSetAndMeasure(dcH, ap->labelFontId, ap->labelFontSize, ap->labelFontStyle, label, &sz );
-
- x -= sz.w + 1;
- ap->labelPt.x = x;
- x -= 3;
- }
-
- // calc horizontal space for right axis hash mark
- if( cmIsFlag(ap->flags,kHashMarkGrFl) )
- {
- mrx = x;
- x -= ap->hashLength + 1;
- }
-
- // set the internal pext width
- vp->iext.sz.w = x - vp->iext.loc.x + 1;
-
-
- // calc the top hash count and alloc hash array
- ap = vp->axis + kTopGrIdx;
- cmGrDcFontSetAndMeasure(dcH, ap->labelFontId, ap->labelFontSize, ap->labelFontStyle, label, &sz );
- ap->hashCnt = cmMin(ap->maxHashCnt,(vp->iext.sz.w + sz.w) / sz.w);
- ap->hash = cmMemResizeZ( cmGrPgHash_t, ap->hash, vp->axis[ kTopGrIdx ].hashCnt );
-
- // calc the bottom hash count and alloc hash array
- ap = vp->axis + kBottomGrIdx;
- cmGrDcFontSetAndMeasure(dcH, ap->labelFontId, ap->labelFontSize, ap->labelFontStyle, label, &sz );
- ap->hashCnt = cmMin(ap->maxHashCnt,(vp->iext.sz.w + sz.w) / sz.w);
- ap->hash = cmMemResizeZ( cmGrPgHash_t, ap->hash, vp->axis[ kBottomGrIdx ].hashCnt );
-
- // calc the top hash mark line beg/end
- for(i=0; i< vp->axis[ kTopGrIdx ].hashCnt; ++i)
- {
- int x0 = round(vp->iext.loc.x - 1 + ((i * (vp->iext.sz.w + 1.0))/(vp->axis[ kTopGrIdx ].hashCnt-1)));
-
- vp->axis[kTopGrIdx].hash[i].xy0.y = mty;
- vp->axis[kTopGrIdx].hash[i].xy0.x = x0;
- vp->axis[kTopGrIdx].hash[i].xy1.y = vp->iext.loc.y - 1;
- vp->axis[kTopGrIdx].hash[i].xy1.x = x0;
- }
-
- // calc the bottom hash mark line beg/end
- for(i=0; i< vp->axis[ kBottomGrIdx ].hashCnt; ++i)
- {
- int x0 = round(vp->iext.loc.x - 1 + ((i * (vp->iext.sz.w + 1.0))/(vp->axis[ kBottomGrIdx ].hashCnt-1)));
-
- vp->axis[kBottomGrIdx].hash[i].xy0.y = mby;
- vp->axis[kBottomGrIdx].hash[i].xy0.x = x0;
- vp->axis[kBottomGrIdx].hash[i].xy1.y = cmGrPExtB(&vp->iext) + 1;
- vp->axis[kBottomGrIdx].hash[i].xy1.x = x0;
- }
-
- // calc the left hash count and alloc hash array
- ap = vp->axis + kLeftGrIdx;
- cmGrDcFontSetAndMeasure(dcH, ap->labelFontId, ap->labelFontSize, ap->labelFontStyle, label, &sz );
- ap->hashCnt = cmMin(ap->maxHashCnt,(vp->iext.sz.h + sz.h) / sz.h);
- ap->hash = cmMemResizeZ( cmGrPgHash_t, ap->hash, vp->axis[ kLeftGrIdx ].hashCnt );
-
- // calc right hash count and alloc hash array
- ap = vp->axis + kRightGrIdx;
- cmGrDcFontSetAndMeasure(dcH, ap->labelFontId, ap->labelFontSize, ap->labelFontStyle, label, &sz );
- ap->hashCnt = cmMin(ap->maxHashCnt,(vp->iext.sz.h + sz.h) / sz.h);
- ap->hash = cmMemResizeZ( cmGrPgHash_t, ap->hash, vp->axis[ kRightGrIdx ].hashCnt );
-
-
- // calc the left hash mark beg/end
- for(i=0; i< vp->axis[ kLeftGrIdx ].hashCnt; ++i)
- {
- int y0 = round(vp->iext.loc.y - 1 + ((i * (vp->iext.sz.h + 1.0))/(vp->axis[ kLeftGrIdx ].hashCnt-1)));
-
- vp->axis[kLeftGrIdx].hash[i].xy0.x = mlx;
- vp->axis[kLeftGrIdx].hash[i].xy0.y = y0;
- vp->axis[kLeftGrIdx].hash[i].xy1.x = vp->iext.loc.x - 1;
- vp->axis[kLeftGrIdx].hash[i].xy1.y = y0;
- }
-
- // calc the right hash mark beg/end
- for(i=0; i< vp->axis[ kRightGrIdx ].hashCnt; ++i)
- {
- int y0 = round(vp->iext.loc.y - 1 + ((i * (vp->iext.sz.h + 1.0))/(vp->axis[ kRightGrIdx ].hashCnt-1)));
-
- vp->axis[kRightGrIdx].hash[i].xy0.x = mrx;
- vp->axis[kRightGrIdx].hash[i].xy0.y = y0;
- vp->axis[kRightGrIdx].hash[i].xy1.x = cmGrPExtR(&vp->iext) + 1;
- vp->axis[kRightGrIdx].hash[i].xy1.y = y0;
- }
-
- // change the location of the view to match vp->iext
- if( cmGrIsValid( vp->grH ) )
- cmGrSetPhysExtentsE( vp->grH, &vp->iext );
-
- }
-
- bool _cmGrPageLayout( cmGrPg_t* p, cmGrDcH_t dcH )
- {
- unsigned i;
-
- if( cmIsNotFlag(p->flags,kDirtyFl) )
- return false;
-
- cmGrDcSetFontFamily(dcH,kHelveticaFfGrId);
- cmGrDcSetFontSize(dcH,10);
-
- // Create a negative string with a repeating decimal to simulate an arbitrary hash label
- // Use the measurements pgom this string to compute the geometry of the view layouts.
- /*
- char label[ kHashCharCnt + 1];
- cmGrPSz_t sz;
- snprintf(label,kHashCharCnt,"%f",-4.0/3.0);
- label[kHashCharCnt] = 0;
- cmGrDcMeasure(dcH,label,&sz);
- */
-
- _cmGrPgLayoutVwPosition(p);
-
- for(i=0; i<p->vn; ++i)
- {
- cmGrPgVw_t* vp = p->viewV + i;
-
- _cmGrPgLayoutView(p, vp, dcH );
- }
-
- p->flags = cmClrFlag(p->flags,kDirtyFl);
-
- return true;
- }
-
- cmGrRC_t cmGrPageInit( cmGrPgH_t h, const cmGrPExt_t* r, unsigned rn, unsigned cn, cmGrDcH_t dcH )
- {
- cmGrRC_t rc = kOkGrRC;
- cmGrPg_t* p = _cmGrPgHandleToPtr(h);
- unsigned i;
-
- _cmGrPgFinal(p);
-
- if( rn*cn > 0 )
- {
- p->pext = *r;
- p->rn = rn;
- p->cn = cn;
- p->vn = rn*cn;
- p->rpropV = cmMemAllocZ(double, rn);
- p->cpropV = cmMemAllocZ(double, cn);
- p->viewV = cmMemAllocZ(cmGrPgVw_t, p->vn);
- p->flags = kDirtyFl;
- p->focusIdx = cmInvalidIdx;
- p->fontId = kHelveticaFfGrId;
- p->fontStyle = kNormalFsGrFl;
- p->fontSize = 16;
-
- // setup the view defaults
- for(i=0; i<p->vn; ++i)
- {
- cmGrPgVw_t* vp = p->viewV + i;
-
- vp->p = p;
- vp->ri = i % p->rn;
- vp->ci = i / p->rn;
- vp->fontId = kHelveticaFfGrId;
- vp->fontStyle = kNormalFsGrFl;
- vp->fontSize = 14;
-
- unsigned j;
- for(j=0; j<kAxisGrCnt; ++j)
- {
- cmGrPgAxis_t* ap = vp->axis + j;
-
- ap->vp = p->viewV + i;
- ap->maxHashCnt = kMaxHashCnt;
- ap->hashLength = kHashLength;
- ap->flags = kHashMarkGrFl | kHashLabelGrFl;
- ap->titleFontId = kHelveticaFfGrId;
- ap->titleFontStyle = kNormalFsGrFl;
- ap->titleFontSize = 10;
- ap->labelFontId = kHelveticaFfGrId;
- ap->labelFontStyle = kNormalFsGrFl;
- ap->labelFontSize = 10;
- }
-
- }
-
- // setup the default row proportions
- for(i=0; i<p->rn; ++i)
- p->rpropV[i] = 1.0/p->rn;
-
- // setup the default col proportions
- for(i=0; i<p->cn; ++i)
- p->cpropV[i] = 1.0/p->cn;
-
- // _cmGrPgLayoutVw() needs to be called.
- p->flags = cmSetFlag(p->flags,kDirtyFl);
-
- // layout the page
- // kpl _cmGrPageLayout(p, dcH );
-
- // notify the application that views have been created
- for(i=0; i<rn*cn; ++i)
- {
- cmGrPgVw_t* vp = p->viewV + i;
-
- // Set the 'id' assoc'd with this views cmGrH_t handle to 'i'.
- // This will allow the grH to return the index of the plot.
- if((rc = cmGrCreate(&p->ctx,&vp->grH,i,kExpandViewGrFl,_cmGrPageCallback,p,NULL)) != kOkGrRC )
- break;
- }
- }
- return rc;
- }
-
-
-
- cmGrRC_t cmGrPageResize( cmGrPgH_t h, const cmGrPExt_t* r, cmGrDcH_t dcH )
- {
- cmGrPg_t* p = _cmGrPgHandleToPtr(h);
- p->pext = *r;
-
- // _cmGrPgLayoutVw() needs to be called.
- p->flags = cmSetFlag(p->flags,kDirtyFl);
-
- // layout the page
- // kpl _cmGrPageLayout(p, dcH );
-
- return kOkGrRC;
- }
-
- void cmGrPageRect( cmGrPgH_t h, cmGrPExt_t* r )
- {
- cmGrPg_t* p = _cmGrPgHandleToPtr(h);
- *r = p->pext;
- }
-
- unsigned cmGrPageViewCount( cmGrPgH_t h )
- {
- cmGrPg_t* p = _cmGrPgHandleToPtr(h);
- return p->vn;
- }
-
- void _cmGrViewSetTitle(cmGrPgVw_t* vp, const cmChar_t* title )
- {
- if( title == vp->title || (title != NULL && vp->title!=NULL && strcmp(title,vp->title)==0 ))
- return;
-
- cmMemPtrFree(&vp->title);
- if( title != NULL )
- {
- assert( vp->title == NULL );
- vp->title = cmMemAllocStr(title);
- }
-
- vp->p->flags = cmSetFlag(vp->p->flags, kDirtyFl);
- }
-
- void _cmGrAxisSetTitle( cmGrPgAxis_t* ap, const cmChar_t* title )
- {
- if( title == ap->title || (title != NULL && ap->title!=NULL && strcmp(title,ap->title)==0 ))
- return;
-
- cmMemPtrFree(&ap->title);
- if( title != NULL )
- {
- assert( ap->title == NULL );
- ap->title = cmMemAllocStr(title);
- }
-
- ap->vp->p->flags = cmSetFlag(ap->vp->p->flags, kDirtyFl);
-
- }
-
-
- void _cmGrPgDrawHashMarks( cmGrPg_t* p, cmGrPgVw_t* vp, cmGrDcH_t dcH, unsigned lineColor )
- {
- int i,j;
- cmGrDcSetColor(dcH, lineColor );
- cmGrDcSetPenWidth( dcH, 1 );
-
- for(j=0; j<kAxisGrCnt; ++j )
- {
- cmGrPgAxis_t* ap = vp->axis + j;
-
- if( cmIsFlag(ap->flags, kHashMarkGrFl) )
- for(i=0; i<ap->hashCnt; ++i)
- {
- cmGrPgHash_t* hp = ap->hash + i;
- cmGrDcDrawLine(dcH, hp->xy0.x, hp->xy0.y, hp->xy1.x, hp->xy1.y);
- }
- }
-
- // draw border 1 pixel outside of iext
- cmGrDcDrawRect(dcH,vp->iext.loc.x-1,vp->iext.loc.y-1,vp->iext.sz.w+2,vp->iext.sz.h+2);
-
- //printf("pgm: x:%i y:%i\n", vp->iext.loc.x, vp->iext.loc.y);
-
- // draw the view border
- //cmGrDcDrawRect(dcH,vp->pext.loc.x,vp->pext.loc.y,vp->pext.sz.w,vp->pext.sz.h);
-
- }
-
- void _cmGrPgHashValueToLabel( cmGrPgAxis_t* ap, cmChar_t* label, unsigned labelCharCnt, cmGrV_t value )
- {
- if( ap->func == NULL )
- snprintf(label,labelCharCnt,"%f",value);
- else
- {
- ap->func->func( ap->func->arg, label, labelCharCnt, value );
- }
- }
-
- void _cmGrPgDrawHashLabels( cmGrPg_t* p, cmGrPgVw_t* vp, cmGrDcH_t dcH, unsigned textColor )
- {
- int i;
- cmGrVExt_t vext;
- char s[ kHashCharCnt+1 ];
- s[kHashCharCnt]=0;
-
- cmGrViewExtents( vp->grH, &vext );
- //cmGrVExtPrint("hash:",&vext);
-
- cmGrDcSetColor(dcH, textColor );
-
- cmGrPgAxis_t* ap = vp->axis + kLeftGrIdx;
- cmGrDcSetFont( dcH, ap->labelFontId, ap->labelFontSize, ap->labelFontStyle );
-
- // draw the left axis hash labels
- if( cmIsFlag(ap->flags, kHashLabelGrFl ) )
- {
- for(i=0; i<vp->axis[ kLeftGrIdx ].hashCnt; ++i)
- {
- cmGrPSz_t sz;
- double v = vext.loc.y + vext.sz.h - (i * vext.sz.h / (ap->hashCnt-1) );
- _cmGrPgHashValueToLabel(ap,s,kHashCharCnt,v);
- cmGrDcMeasure(dcH,s,&sz);
-
- int y = ap->hash[i].xy0.y;
- cmGrDcDrawText(dcH, s, ap->labelPt.x, y + (sz.h/2) );
- }
- }
-
- ap = vp->axis + kRightGrIdx;
- cmGrDcSetFont( dcH, ap->labelFontId, ap->labelFontSize, ap->labelFontStyle );
-
- // draw the right axis hash labels
- if( cmIsFlag(ap->flags, kHashLabelGrFl ))
- {
- for(i=0; i<ap->hashCnt; ++i)
- {
- cmGrPSz_t sz;
- double v = vext.loc.y + vext.sz.h - (i * vext.sz.h / (ap->hashCnt-1) );
- _cmGrPgHashValueToLabel(ap,s,kHashCharCnt,v);
- cmGrDcMeasure(dcH,s,&sz);
-
- int y = ap->hash[i].xy0.y;
- cmGrDcDrawText(dcH, s, ap->labelPt.x, y + (sz.h/2));
- }
- }
-
-
- // draw the top axis hash labels
- ap = vp->axis + kTopGrIdx;
- cmGrDcSetFont( dcH, ap->labelFontId, ap->labelFontSize, ap->labelFontStyle );
-
- if( cmIsFlag(ap->flags, kHashLabelGrFl ) )
- {
- for(i=0; i<ap->hashCnt; ++i)
- {
- cmGrPSz_t sz;
- double v = vext.loc.x + (i * vext.sz.w / (ap->hashCnt-1));
- _cmGrPgHashValueToLabel(ap,s,kHashCharCnt,v);
- cmGrDcMeasure(dcH,s,&sz);
-
- cmGrDcDrawText(dcH, s, ap->hash[i].xy0.x - sz.w/2, ap->labelPt.y );
- }
- }
-
- // draw the bottom axis hash labels
- ap = vp->axis + kBottomGrIdx;
- cmGrDcSetFont( dcH, ap->labelFontId, ap->labelFontSize, ap->labelFontStyle );
-
- if( cmIsFlag(ap->flags, kHashLabelGrFl ) )
- {
- for(i=0; i<ap->hashCnt; ++i)
- {
- cmGrPSz_t sz;
- double v = vext.loc.x + (i * vext.sz.w / (ap->hashCnt-1));
- _cmGrPgHashValueToLabel(ap,s,kHashCharCnt,v);
- cmGrDcMeasure(dcH,s,&sz);
-
- cmGrDcDrawText(dcH, s, ap->hash[i].xy0.x - sz.w/2, ap->labelPt.y );
- }
- }
-
- }
-
- void _cmGrPgDrawAxisTitles( cmGrPg_t* p, cmGrPgVw_t* vp, cmGrDcH_t dcH )
- {
- unsigned i;
- for(i=0; i<kAxisGrCnt; ++i)
- {
- cmGrPgAxis_t* ap = vp->axis + i;
-
- if( ap->title != NULL )
- {
- cmGrPSz_t sz;
- cmGrDcFontSetAndMeasure( dcH, ap->titleFontId, ap->titleFontSize, ap->titleFontStyle, ap->title, &sz );
-
- if( i==kBottomGrIdx || i==kTopGrIdx )
- {
- int x = vp->iext.loc.x + (vp->iext.sz.w/2) - (sz.w/2);
- cmGrDcDrawText( dcH, ap->title, x, ap->titlePt.y );
- }
-
- if( i==kLeftGrIdx || i==kRightGrIdx )
- {
- int y = vp->iext.loc.y + (vp->iext.sz.h/2) + (sz.w/2);
- cmGrDcDrawTextRot( dcH, ap->title, ap->titlePt.x, y, 90 );
- }
- }
- }
- }
-
- void cmGrPageViewFocus( cmGrPgH_t h, unsigned vwIdx, bool enableFl )
- {
- cmGrPg_t* p = _cmGrPgHandleToPtr(h);
- assert( vwIdx < p->vn );
- if( enableFl )
- p->focusIdx = vwIdx;
- else
- {
- if( p->focusIdx == vwIdx )
- p->focusIdx = cmInvalidId;
- }
- }
-
- cmGrVwH_t cmGrPageFocusedView( cmGrPgH_t h )
- {
- cmGrPg_t* p = _cmGrPgHandleToPtr(h);
- cmGrVwH_t vwH = cmGrVwNullHandle;
-
- if( p->focusIdx != cmInvalidIdx )
- vwH.h = p->viewV + p->focusIdx;
-
- return vwH;
- }
-
-
- bool cmGrPageLayout( cmGrPgH_t h, cmGrDcH_t dcH )
- {
- cmGrPg_t* p = _cmGrPgHandleToPtr(h);
- cmGrDcPushCtx(dcH);
- bool fl = _cmGrPageLayout(p,dcH);
- cmGrDcPopCtx(dcH);
- return fl;
- }
-
- void cmGrPageDraw( cmGrPgH_t h, cmGrDcH_t dcH )
- {
- unsigned i;
- cmGrPg_t* p = _cmGrPgHandleToPtr(h);
-
- cmGrDcPushCtx(dcH);
-
- _cmGrPageLayout(p,dcH);
-
- cmGrDcSetColor(dcH,kBlackGrId);
-
- // for each view
- for(i=0; i<p->vn; ++i)
- {
- cmGrPgVw_t* vp = p->viewV + i;
-
- unsigned lineColor = p->focusIdx==i ? kRedGrId : kBlackGrId;
- _cmGrPgDrawHashMarks( p, vp, dcH, lineColor );
- _cmGrPgDrawHashLabels( p, vp, dcH, kBlackGrId);
- _cmGrPgDrawAxisTitles( p, vp, dcH );
-
- if( vp->title != NULL )
- {
- cmGrPSz_t sz;
- cmGrDcFontSetAndMeasure(dcH,vp->fontId,vp->fontSize,vp->fontStyle,vp->title,&sz);
- cmGrDcDrawText(dcH,vp->title, vp->titlePt.x - sz.w/2, vp->titlePt.y );
- }
-
- }
-
- cmGrDcPopCtx(dcH);
-
-
- }
-
- cmGrPgLabelFunc_t* _cmGrPageLabelIndexToRecd( cmGrPg_t* p, unsigned idx )
- {
- cmGrPgLabelFunc_t* lfp = p->funcs;
- unsigned i;
- for(i=0; i<idx && lfp!=NULL; ++i)
- lfp=lfp->link;
-
- return lfp;
- }
-
- cmGrPgLabelFunc_t* _cmGrPageLabelIdToRecd( cmGrPg_t* p, unsigned id )
- {
- cmGrPgLabelFunc_t* lfp = p->funcs;
- for(; lfp!=NULL; lfp=lfp->link)
- if( lfp->id == id )
- return lfp;
-
- return lfp;
- }
-
- unsigned cmGrPageLabelFuncRegister( cmGrPgH_t h, cmGrLabelFunc_t func, void* arg, const cmChar_t* label )
- {
- cmGrPg_t* p = _cmGrPgHandleToPtr(h);
- cmGrPgLabelFunc_t* lfp = cmMemAllocZ(cmGrPgLabelFunc_t,1);
-
- lfp->id = p->labelFuncId++;
- lfp->func = func;
- lfp->arg = arg;
- lfp->label = cmMemAllocStr(label);
- lfp->link = p->funcs;
- p->funcs = lfp;
- return lfp->id;
- }
-
- unsigned cmGrPageLabelFuncCount( cmGrPgH_t h )
- {
- cmGrPg_t* p = _cmGrPgHandleToPtr(h);
- cmGrPgLabelFunc_t* lfp = p->funcs;
- unsigned n = 0;
-
- for(; lfp != NULL; lfp=lfp->link )
- ++n;
- return n;
- }
-
- unsigned cmGrPageLabelFuncIndexToId( cmGrPgH_t h, unsigned index )
- {
- cmGrPgLabelFunc_t* lfp;
- cmGrPg_t* p = _cmGrPgHandleToPtr(h);
-
- if((lfp = _cmGrPageLabelIndexToRecd(p,index)) == NULL )
- return cmInvalidId;
- return lfp->id;
- }
-
- unsigned cmGrPageLabelFuncLabelToId( cmGrPgH_t h, const cmChar_t* label )
- {
- cmGrPg_t* p = _cmGrPgHandleToPtr(h);
- cmGrPgLabelFunc_t* lfp = p->funcs;
- unsigned i;
- for(i=0; lfp!=NULL; lfp=lfp->link,++i)
- if( lfp->label!=NULL && strcmp(label,lfp->label)==0 )
- return lfp->id;
-
- return cmInvalidId;
- }
-
-
- cmGrLabelFunc_t cmGrPageLabelFunc( cmGrPgH_t h, unsigned id )
- {
- cmGrPg_t* p = _cmGrPgHandleToPtr(h);
- cmGrPgLabelFunc_t* lfp = _cmGrPageLabelIdToRecd(p,id);
- assert( lfp != NULL );
- return lfp->func;
- }
-
- const cmChar_t* cmGrPageLabelFuncLabel( cmGrPgH_t h, unsigned id )
- {
- cmGrPg_t* p = _cmGrPgHandleToPtr(h);
- cmGrPgLabelFunc_t* lfp = _cmGrPageLabelIdToRecd(p,id);
- assert( lfp != NULL );
- return lfp->label;
- }
-
- void* cmGrPageLabelFuncArg( cmGrPgH_t h, unsigned id )
- {
- cmGrPg_t* p = _cmGrPgHandleToPtr(h);
- cmGrPgLabelFunc_t* lfp = _cmGrPageLabelIdToRecd(p,id);
- assert( lfp != NULL );
- return lfp->arg;
- }
-
-
- cmGrVwH_t cmGrPageViewHandle( cmGrPgH_t h, unsigned vwIdx )
- {
- cmGrPg_t* p = _cmGrPgHandleToPtr(h);
- cmGrVwH_t vwH;
- assert( vwIdx < p->vn );
- vwH.h = p->viewV + vwIdx;
- return vwH;
- }
-
- cmGrVwH_t cmGrPageGrHandleToView( cmGrPgH_t pgH, cmGrH_t grH )
- {
- cmGrPg_t* p = _cmGrPgHandleToPtr(pgH);
- cmGrVwH_t vwH = cmGrVwNullHandle;
- int i;
- for(i=0; i<p->vn; ++i)
- if( cmHandlesAreEqual(grH,p->viewV[i].grH) )
- {
- vwH.h = p->viewV + i;
- break;
- }
- return vwH;
- }
-
-
- bool cmGrViewIsValid( cmGrVwH_t h )
- { return h.h != NULL; }
-
- cmGrRC_t cmGrViewInit( cmGrVwH_t h, cmGrH_t grH, const cmChar_t* vwTitle, const cmChar_t* xLabel, const cmChar_t* yLabel )
- {
- cmGrPgVw_t* vp = _cmGrPgVwHandleToPtr(h);
-
- vp->grH = grH;
-
- _cmGrViewSetTitle( vp, vwTitle );
- _cmGrAxisSetTitle( vp->axis + kBottomGrIdx, xLabel );
- _cmGrAxisSetTitle( vp->axis + kLeftGrIdx, yLabel );
-
- vp->p->flags = cmSetFlag(vp->p->flags, kDirtyFl);
-
- return kOkGrRC;
- }
-
- cmGrRC_t cmGrViewClear( cmGrVwH_t h )
- {
- cmGrPgVw_t* vp = _cmGrPgVwHandleToPtr(h);
- cmGrH_t grH = cmGrViewGrHandle(h);
- assert( cmGrIsValid(grH) );
- cmGrRC_t rc = cmGrClear( grH );
-
- vp->p->flags = cmSetFlag(vp->p->flags, kDirtyFl);
-
- return rc;
- }
-
- cmGrRC_t cmGrViewPExt( cmGrVwH_t h, cmGrPExt_t* pext )
- {
- cmGrPgVw_t* vp = _cmGrPgVwHandleToPtr(h);
- *pext = vp->iext;
- return kOkGrRC;
- }
-
- bool cmGrViewHasFocus( cmGrVwH_t h )
- {
- if( cmGrViewIsValid(h) == false )
- return false;
-
- cmGrPgVw_t* vp = _cmGrPgVwHandleToPtr(h);
-
- if( vp->p->focusIdx == cmInvalidIdx )
- return false;
-
- return cmGrId(vp->grH) == vp->p->focusIdx;
- }
-
- cmGrH_t cmGrViewGrHandle( cmGrVwH_t h )
- {
- cmGrPgVw_t* vp = _cmGrPgVwHandleToPtr(h);
- return vp->grH;
- }
-
- void cmGrViewSetCfg( cmGrVwH_t h, unsigned cfgFlags )
- {
- cmGrPgVw_t* vp = _cmGrPgVwHandleToPtr(h);
- cmGrSetCfgFlags( vp->grH, cfgFlags );
- vp->p->flags = cmSetFlag(vp->p->flags, kDirtyFl);
- }
-
- unsigned cmGrViewCfg( cmGrVwH_t h )
- {
- cmGrPgVw_t* vp = _cmGrPgVwHandleToPtr(h);
- return cmGrCfgFlags( vp->grH );
- }
- void cmGrViewSetTitle( cmGrVwH_t h, const cmChar_t* title )
- {
- cmGrPgVw_t* vp = _cmGrPgVwHandleToPtr(h);
- _cmGrViewSetTitle( vp, title );
- }
- const cmChar_t* cmGrViewTitle( cmGrVwH_t h )
- {
- cmGrPgVw_t* vp = _cmGrPgVwHandleToPtr(h);
- return vp->title;
- }
- void cmGrViewSetFontFamily( cmGrVwH_t h, unsigned id )
- {
- cmGrPgVw_t* vp = _cmGrPgVwHandleToPtr(h);
- if( vp->fontId != id )
- {
- vp->fontId = id;
- vp->p->flags = cmSetFlag(vp->p->flags, kDirtyFl);
- }
-
- }
- unsigned cmGrViewFontFamily( cmGrVwH_t h )
- {
- cmGrPgVw_t* vp = _cmGrPgVwHandleToPtr(h);
- return vp->fontId;
- }
- void cmGrViewSetFontStyle( cmGrVwH_t h, unsigned flags )
- {
- cmGrPgVw_t* vp = _cmGrPgVwHandleToPtr(h);
- if( vp->fontStyle != flags )
- {
- vp->fontStyle = flags;
- vp->p->flags = cmSetFlag(vp->p->flags, kDirtyFl);
- }
- }
- unsigned cmGrViewFontStyle( cmGrVwH_t h )
- {
- cmGrPgVw_t* vp = _cmGrPgVwHandleToPtr(h);
- return vp->fontStyle;
- }
- void cmGrViewSetFontSize( cmGrVwH_t h, unsigned size )
- {
- cmGrPgVw_t* vp = _cmGrPgVwHandleToPtr(h);
- if( vp->fontSize != size )
- {
- vp->fontSize = size;
- vp->p->flags = cmSetFlag(vp->p->flags, kDirtyFl);
- }
- }
- unsigned cmGrViewFontSize( cmGrVwH_t h )
- {
- cmGrPgVw_t* vp = _cmGrPgVwHandleToPtr(h);
- return vp->fontSize;
- }
-
- void cmGrViewSetLabelFunc( cmGrVwH_t h, cmGrAxisIdx_t axisId, unsigned pgLabelFuncId )
- {
- cmGrPgVw_t* vp = _cmGrPgVwHandleToPtr(h);
- cmGrPgLabelFunc_t** lfpp = NULL;
-
- switch( axisId )
- {
- case kLeftGrIdx:
- case kRightGrIdx:
- lfpp = &vp->yfunc;
- break;
-
- case kTopGrIdx:
- case kBottomGrIdx:
- lfpp = &vp->xfunc;
- break;
-
- default:
- { assert(0); }
- }
-
- assert( lfpp != NULL );
-
- *lfpp = _cmGrPageLabelIdToRecd(vp->p, pgLabelFuncId );
- }
-
- const cmChar_t* cmGrViewValue( cmGrVwH_t h, cmGrViewValueId_t id, cmChar_t* buf, unsigned bufCharCnt )
- {
- cmGrPgVw_t* vp = _cmGrPgVwHandleToPtr(h);
- cmGrPgLabelFunc_t* lfp = NULL;
- cmGrH_t grH = vp->grH;
- cmGrV_t v;
- cmGrVPt_t pt0,pt1;
-
- switch( id )
- {
- case kLocalX_VwId:
- v = cmGrLocalPt(grH)->x;
- lfp = vp->xfunc;
- break;
-
- case kLocalY_VwId:
- v = cmGrLocalPt(grH)->y;
- lfp = vp->yfunc;
- break;
-
- case kGlobalX_VwId:
- v = cmGrGlobalPt(grH)->x;
- lfp = vp->xfunc;
- break;
-
- case kGlobalY_VwId:
- v = cmGrGlobalPt(grH)->y;
- lfp = vp->yfunc;
- break;
-
- case kSelX0_VwId:
- cmGrSelectPoints(grH,&pt0,NULL);
- v = pt0.x;
- lfp = vp->xfunc;
- break;
-
- case kSelY0_VwId:
- cmGrSelectPoints(grH,&pt0,NULL);
- v = pt0.y;
- lfp = vp->yfunc;
- break;
-
- case kSelX1_VwId:
- cmGrSelectPoints(grH,NULL,&pt1);
- v = pt1.x;
- lfp = vp->xfunc;
- break;
-
- case kSelY1_VwId:
- cmGrSelectPoints(grH,NULL,&pt1);
- v = pt1.y;
- lfp = vp->yfunc;
- break;
-
- case kSelW_VwId:
- cmGrSelectPoints(grH,&pt0,&pt1);
- v = fabs(pt1.x - pt0.x);
- lfp = vp->xfunc;
- break;
-
- case kSelH_VwId:
- cmGrSelectPoints(grH,&pt0,&pt1);
- v = fabs(pt1.y - pt0.y);
- lfp = vp->yfunc;
- break;
-
- default:
- { assert(0); }
- }
-
- if( bufCharCnt > 0 )
- {
- buf[0]=0;
- if( lfp != NULL )
- lfp->func( lfp->arg, buf, bufCharCnt, v );
- else
- snprintf(buf,bufCharCnt,"%f",v);
- }
-
- return buf;
- }
-
-
- cmGrAxH_t cmGrViewAxisHandle( cmGrVwH_t h, cmGrAxisIdx_t axisIdx )
- {
- cmGrPgVw_t* vp = _cmGrPgVwHandleToPtr(h);
- cmGrAxH_t axH;
- assert( axisIdx < kAxisGrCnt );
- axH.h = vp->axis + axisIdx;
- return axH;
- }
-
- bool cmGrAxisIsValid( cmGrAxH_t h )
- { return h.h != NULL; }
-
- void cmGrAxisSetCfg( cmGrAxH_t h, unsigned flags )
- {
- cmGrPgAxis_t* ap = _cmGrPgAxisHandleToPtr(h);
- if( ap->flags != flags )
- {
- ap->flags = flags;
- ap->vp->p->flags = cmSetFlag(ap->vp->p->flags, kDirtyFl);
- }
- }
-
- unsigned cmGrAxisCfg( cmGrAxH_t h )
- {
- cmGrPgAxis_t* ap = _cmGrPgAxisHandleToPtr(h);
- return ap->flags;
- }
-
- void cmGrAxisSetTitle( cmGrAxH_t h, const cmChar_t* title )
- {
- cmGrPgAxis_t* ap = _cmGrPgAxisHandleToPtr(h);
- _cmGrAxisSetTitle(ap,title);
- }
-
- const cmChar_t* cmGrAxisTitle( cmGrAxH_t h )
- {
- cmGrPgAxis_t* ap = _cmGrPgAxisHandleToPtr(h);
- return ap->title;
- }
-
- void cmGrAxisSetTitleFontFamily( cmGrAxH_t h, unsigned id )
- {
- cmGrPgAxis_t* ap = _cmGrPgAxisHandleToPtr(h);
- if( ap->titleFontId != id )
- {
- ap->titleFontId = id;
- ap->vp->p->flags = cmSetFlag(ap->vp->p->flags, kDirtyFl);
- }
- }
-
- unsigned cmGrAxisTitleFontFamily( cmGrAxH_t h )
- {
- cmGrPgAxis_t* ap = _cmGrPgAxisHandleToPtr(h);
- return ap->titleFontId;
- }
-
- void cmGrAxisTitleSetFontStyle( cmGrAxH_t h, unsigned flags )
- {
- cmGrPgAxis_t* ap = _cmGrPgAxisHandleToPtr(h);
- if( ap->titleFontStyle != flags )
- {
- ap->titleFontStyle = flags;
- ap->vp->p->flags = cmSetFlag(ap->vp->p->flags, kDirtyFl);
- }
- }
-
- unsigned cmGrAxisTitleFontStyle( cmGrAxH_t h )
- {
- cmGrPgAxis_t* ap = _cmGrPgAxisHandleToPtr(h);
- return ap->titleFontStyle;
- }
-
- void cmGrAxisTitleSetFontSize( cmGrAxH_t h, unsigned size )
- {
- cmGrPgAxis_t* ap = _cmGrPgAxisHandleToPtr(h);
- if( ap->titleFontSize != size )
- {
- ap->titleFontSize = size;
- ap->vp->p->flags = cmSetFlag(ap->vp->p->flags, kDirtyFl);
- }
- }
-
- unsigned cmGrAxisTitleFontSize( cmGrAxH_t h )
- {
- cmGrPgAxis_t* ap = _cmGrPgAxisHandleToPtr(h);
- return ap->titleFontSize;
- }
-
- void cmGrAxisSetLabelFunc( cmGrAxH_t h, unsigned id )
- {
- cmGrPgAxis_t* ap = _cmGrPgAxisHandleToPtr(h);
-
- ap->func = _cmGrPageLabelIdToRecd( ap->vp->p, id );
- }
|