cmGrPlot.h/c Added default plot obj callback function to mgr.

This commit is contained in:
kpl 2012-11-14 20:04:42 -08:00
parent 41a33a0333
commit 9d4c82ae37
2 changed files with 27 additions and 7 deletions

View File

@ -66,6 +66,8 @@ typedef struct cmGrPl_str
cmErr_t err; // cmErr_t err; //
cmGrPlotObj_t* list; // plot object linked list cmGrPlotObj_t* list; // plot object linked list
cmGrPlotObj_t* fop; // focused object ptr cmGrPlotObj_t* fop; // focused object ptr
cmGrPlotCbFunc_t cbFunc; // dflt callback function
void* cbArg; // dflt callback function arg.
} cmGrPl_t; } cmGrPl_t;
cmGrPlH_t cmGrPlNullHandle = cmSTATIC_NULL_HANDLE; cmGrPlH_t cmGrPlNullHandle = cmSTATIC_NULL_HANDLE;
@ -196,7 +198,7 @@ bool _cmGrPlotObjCb( cmGrPlotObj_t* op, cmGrPlCbSelId_t selId, unsigned deltaFla
{ {
cmGrPlotCbArg_t a; cmGrPlotCbArg_t a;
_cmGrPlotObjSetupCbArg(&a,op,kPreEventCbSelGrPlId); _cmGrPlotObjSetupCbArg(&a,op,selId);
a.deltaFlags = deltaFlags; a.deltaFlags = deltaFlags;
return op->cbFunc(&a); return op->cbFunc(&a);
} }
@ -743,6 +745,8 @@ cmGrPlRC_t cmGrPlotObjCreate(
op->fontId = kHelveticaFfGrId; op->fontId = kHelveticaFfGrId;
op->fontSize = 12; op->fontSize = 12;
op->fontStyle = kNormalFsGrFl; op->fontStyle = kNormalFsGrFl;
op->cbFunc = p->cbFunc;
op->cbArg = p->cbArg;
if( cmIsFlag(op->cfgFlags,kSymbolGrPlFl) ) if( cmIsFlag(op->cfgFlags,kSymbolGrPlFl) )
{ {
@ -1232,3 +1236,10 @@ void cmGrPlotKeyEvent( cmGrPlH_t h, cmGrH_t grH, unsigned eventFlags, cmGrKey
_cmGrPlotObjEvent(&a, eventFlags, keycode, 0, 0 ); _cmGrPlotObjEvent(&a, eventFlags, keycode, 0, 0 );
} }
} }
void cmGrPlotSetCb( cmGrPlH_t h, cmGrPlotCbFunc_t func, void* arg )
{
cmGrPl_t* p = _cmGrPlHandleToPtr(h);
p->cbFunc = func;
p->cbArg = arg;
}

View File

@ -94,7 +94,7 @@ extern "C" {
cmGrKeyCodeId_t eventKey; // Event keys (See the cmGrEvent() keys) cmGrKeyCodeId_t eventKey; // Event keys (See the cmGrEvent() keys)
int eventX; // Mouse X,Y location when event was generated (Same as cmGrEvent()) int eventX; // Mouse X,Y location when event was generated (Same as cmGrEvent())
int eventY; // int eventY; //
unsigned deltaFlags; // Event caused an object state change (See kXXXGrPlFl flags) unsigned deltaFlags; // Event which caused an object state change (See kXXXGrPlFl flags)
} cmGrPlotCbArg_t; } cmGrPlotCbArg_t;
@ -104,7 +104,8 @@ extern "C" {
// the object has not yet been changed. This may be confusing because if // the object has not yet been changed. This may be confusing because if
// the state of the object is queried inside the callback it will have the // the state of the object is queried inside the callback it will have the
// pre-change state - but this state will be automatically toggled when the // pre-change state - but this state will be automatically toggled when the
// callback returns 'true'. // callback returns 'true'. Examine the arg->deltaFlags to determine the
// state attribute which is changing.
typedef bool (*cmGrPlotCbFunc_t)( cmGrPlotCbArg_t* arg ); typedef bool (*cmGrPlotCbFunc_t)( cmGrPlotCbArg_t* arg );
extern cmGrPlH_t cmGrPlNullHandle; extern cmGrPlH_t cmGrPlNullHandle;
@ -201,13 +202,21 @@ extern "C" {
cmGrPlRC_t cmGrPlotClear( cmGrPlH_t h ); // destroy all objects cmGrPlRC_t cmGrPlotClear( cmGrPlH_t h ); // destroy all objects
cmErr_t* cmGrPlotErr( cmGrPlH_t h ); cmErr_t* cmGrPlotErr( cmGrPlH_t h );
cmRpt_t* cmGrPlotRpt( cmGrPlH_t h ); cmRpt_t* cmGrPlotRpt( cmGrPlH_t h );
// Return the count of plot objects.
unsigned cmGrPlotObjectCount( cmGrPlH_t h ); unsigned cmGrPlotObjectCount( cmGrPlH_t h );
// Return the handle of the ith object (0<=index<cmGrPlotObjectCount())
cmGrPlObjH_t cmGrPlotObjectIndexToHandle( cmGrPlH_t h, unsigned index ); cmGrPlObjH_t cmGrPlotObjectIndexToHandle( cmGrPlH_t h, unsigned index );
// Given a plot object id return the associated object handle.
cmGrPlObjH_t cmGrPlotObjectIdToHandle( cmGrPlH_t h, unsigned id ); cmGrPlObjH_t cmGrPlotObjectIdToHandle( cmGrPlH_t h, unsigned id );
// Pass a keyboard event to the plot system. // Pass a keyboard event to the plot system.
void cmGrPlotKeyEvent( cmGrPlH_t h, cmGrH_t grH, unsigned eventFlags, cmGrKeyCodeId_t keycode ); void cmGrPlotKeyEvent( cmGrPlH_t h, cmGrH_t grH, unsigned eventFlags, cmGrKeyCodeId_t keycode );
// Set the default object callback and arg.
void cmGrPlotSetCb( cmGrPlH_t h, cmGrPlotCbFunc_t func, void* arg );
#ifdef __cplusplus #ifdef __cplusplus