libcm is a C development framework with an emphasis on audio signal processing applications.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

cmGrPlot.c 34KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329
  1. #include "cmGlobal.h"
  2. #include "cmFloatTypes.h"
  3. #include "cmRpt.h"
  4. #include "cmErr.h"
  5. #include "cmCtx.h"
  6. #include "cmMem.h"
  7. #include "cmMallocDebug.h"
  8. #include "cmGr.h"
  9. #include "cmGrDevCtx.h"
  10. #include "cmGrPlot.h"
  11. #include "cmVectOpsTemplateMain.h"
  12. //------------------------------------------------------------------------------------------------------------------
  13. //------------------------------------------------------------------------------------------------------------------
  14. //------------------------------------------------------------------------------------------------------------------
  15. //------------------------------------------------------------------------------------------------------------------
  16. struct cmGrPl_str;
  17. typedef struct cmGrPlotObj_str
  18. {
  19. cmGrH_t grH; // the canvas this object is drawn on
  20. cmGrObjH_t grObjH; // the grObj this object is based on
  21. cmGrPlObjTypeId_t typeId;
  22. unsigned cfgFlags;
  23. unsigned stateFlags;
  24. cmGrVExt_t vext;
  25. cmChar_t* label;
  26. unsigned labelFlags;
  27. int labelAngle;
  28. cmGrColor_t labelColor;
  29. int loffs;
  30. int toffs;
  31. int roffs;
  32. int boffs;
  33. cmGrColor_t drawColors[ kMaxPlGrId ];
  34. cmGrColor_t fillColors[ kMaxPlGrId ];
  35. unsigned fontId;
  36. unsigned fontSize;
  37. unsigned fontStyle;
  38. void* userPtr;
  39. unsigned userByteCnt; // 0 if userPtr does not need to be realease on object destruction
  40. cmGrPlotCbFunc_t cbFunc;
  41. void* cbArg;
  42. struct cmGrPl_str* p; // owning plot object manager
  43. struct cmGrPlotObj_str* parent; // containing object
  44. struct cmGrPlotObj_str* xAnchor; // x-location reference object
  45. struct cmGrPlotObj_str* yAnchor; // y-location reference object
  46. struct cmGrPlotObj_str* next;
  47. struct cmGrPlotObj_str* prev;
  48. } cmGrPlotObj_t;
  49. typedef struct cmGrPl_str
  50. {
  51. cmCtx_t* ctx; //
  52. cmErr_t err; //
  53. cmGrPlotObj_t* list; // plot object linked list
  54. cmGrPlotObj_t* fop; // focused object ptr
  55. cmGrPlotCbFunc_t cbFunc; // dflt callback function
  56. void* cbArg; // dflt callback function arg.
  57. } cmGrPl_t;
  58. cmGrPlH_t cmGrPlNullHandle = cmSTATIC_NULL_HANDLE;
  59. cmGrPlObjH_t cmGrPlObjNullHandle = cmSTATIC_NULL_HANDLE;
  60. //------------------------------------------------------------------------------------------------------------------
  61. // Plot Private Functions
  62. //------------------------------------------------------------------------------------------------------------------
  63. cmGrPl_t* _cmGrPlHandleToPtr( cmGrPlH_t h )
  64. {
  65. cmGrPl_t* p = (cmGrPl_t*)h.h;
  66. assert(p!=NULL);
  67. return p;
  68. }
  69. cmGrPlotObj_t* _cmGrPlObjHandleToPtr( cmGrPlObjH_t oh )
  70. {
  71. cmGrPlotObj_t* op = (cmGrPlotObj_t*)oh.h;
  72. assert( op!=NULL);
  73. return op;
  74. }
  75. cmGrPlRC_t _cmGrPlotObjDelete( cmGrPlotObj_t* op )
  76. {
  77. if( op==NULL || cmGrObjIsValid( op->grH, op->grObjH)==false )
  78. return kOkGrPlRC;
  79. cmGrPl_t* p = op->p;
  80. // destroy the cmGrObj - which will call _cmGrPlotObjDestroy()
  81. if( cmGrObjDestroy( op->grH, &op->grObjH ) != kOkGrRC )
  82. return cmErrMsg( &p->err, kGrFailGrPlRC, "Delete failed on the object label='%s' id=%i\n",cmStringNullGuard( op->label ), cmGrObjId(op->grObjH) );
  83. if( op->userByteCnt != 0 )
  84. {
  85. cmMemFree(op->userPtr);
  86. op->userByteCnt = 0;
  87. }
  88. return kOkGrPlRC;
  89. }
  90. void _cmGrPlotObjUnlink( cmGrPlotObj_t* op )
  91. {
  92. cmGrPl_t* p = op->p;
  93. if( op->next != NULL )
  94. op->next->prev = op->prev;
  95. if( op->prev != NULL )
  96. op->prev->next = op->next;
  97. if( p->list == op )
  98. p->list = op->next;
  99. }
  100. void _cmGrPlotObjLink( cmGrPl_t* p, cmGrPlotObj_t* op )
  101. {
  102. if( p->list != NULL )
  103. p->list->prev = op;
  104. op->next = p->list;
  105. op->prev = NULL;
  106. p->list = op;
  107. }
  108. // Destroy all objects
  109. cmGrPlRC_t _cmGrPlotClear( cmGrPl_t* p )
  110. {
  111. cmGrPlRC_t rc = kOkGrPlRC;
  112. cmGrPlotObj_t* op = p->list;
  113. while( op!=NULL )
  114. {
  115. cmGrPlotObj_t* t = op->next;
  116. if((rc = _cmGrPlotObjDelete(op)) != kOkGrPlRC )
  117. break;
  118. op = t;
  119. }
  120. return rc;
  121. }
  122. // Destroy the plot mgr
  123. cmGrPlRC_t _cmGrPlotDestroy( cmGrPl_t* p )
  124. {
  125. cmGrPlRC_t rc;
  126. if((rc = _cmGrPlotClear(p)) != kOkGrPlRC )
  127. return rc;
  128. cmMemFree(p);
  129. return kOkGrPlRC;
  130. }
  131. bool _cmGrPlotObjIsVisible( cmGrPlotObj_t* op )
  132. { return cmIsNotFlag(op->cfgFlags,kNoDrawGrPlFl); }
  133. bool _cmGrPlotObjIsEnabled( cmGrPlotObj_t* op )
  134. {
  135. // invisible objects are never enabled
  136. if( _cmGrPlotObjIsVisible(op) == false )
  137. return false;
  138. return cmIsFlag(op->stateFlags,kEnabledGrPlFl);
  139. }
  140. bool _cmGrPlotObjIsFocused(cmGrPlotObj_t* op)
  141. { return _cmGrPlotObjIsEnabled(op) && op->p->fop==op; }
  142. bool _cmGrPlotObjIsSelected(cmGrPlotObj_t* op)
  143. { return _cmGrPlotObjIsFocused(op) || cmIsFlag(op->stateFlags,kSelectGrPlFl); }
  144. void _cmGrPlotObjSetupCbArg( cmGrPlotCbArg_t* a, cmGrPlotObj_t* op, cmGrPlCbSelId_t selId )
  145. {
  146. cmGrPlObjH_t oH;
  147. oH.h = op;
  148. memset(a,0,sizeof(a));
  149. a->ctx = op->p->ctx;
  150. a->cbArg = op->cbArg;
  151. a->selId = selId;
  152. a->objH = oH;
  153. }
  154. bool _cmGrPlotObjCb( cmGrPlotObj_t* op, cmGrPlCbSelId_t selId, unsigned deltaFlags )
  155. {
  156. if( op->cbFunc != NULL )
  157. {
  158. cmGrPlotCbArg_t a;
  159. _cmGrPlotObjSetupCbArg(&a,op,selId);
  160. a.deltaFlags = deltaFlags;
  161. return op->cbFunc(&a);
  162. }
  163. return true;
  164. }
  165. void _cmGrPlotObjSetFocus( cmGrPlotObj_t* op )
  166. {
  167. // if 'op' is not enabled then it cannot receive the focus
  168. if( _cmGrPlotObjIsEnabled(op) == false )
  169. return;
  170. // if the focus cannot be set on 'op' - then try op->parent
  171. for(; op!=NULL; op=op->parent)
  172. if( cmIsNotFlag(op->cfgFlags,kNoFocusGrPlFl) && cmIsNotFlag(op->cfgFlags,kNoDrawGrPlFl) )
  173. break;
  174. // if the focus is changing to a new object
  175. if( op != NULL && op->p->fop != op )
  176. {
  177. if( op->p->fop != NULL )
  178. {
  179. // if the application callback returns false then do no release focus from the current object
  180. if(_cmGrPlotObjCb(op->p->fop, kPreEventCbSelGrPlId, kFocusGrPlFl ) == false )
  181. return;
  182. cmGrPlotObj_t* fop = op->p->fop;
  183. op->p->fop = NULL;
  184. // notify focus loser
  185. _cmGrPlotObjCb(fop, kStateChangeGrPlId, kFocusGrPlFl );
  186. }
  187. // if the application callback returns false then do not give focus to the selected object
  188. if(_cmGrPlotObjCb(op, kPreEventCbSelGrPlId, kFocusGrPlFl ) == false )
  189. return;
  190. op->p->fop = op;
  191. // notify focus winner
  192. _cmGrPlotObjCb(op, kStateChangeGrPlId, kFocusGrPlFl );
  193. }
  194. }
  195. void _cmGrPlotObjSetSelect( cmGrPlotObj_t* op, bool clearFl )
  196. {
  197. // if the object is disabled or not selectable
  198. if( _cmGrPlotObjIsEnabled(op)==false || cmIsFlag(op->cfgFlags,kNoSelectGrPlFl | kNoDrawGrPlFl) )
  199. return;
  200. unsigned stateFlags = op->stateFlags;
  201. // if the application callback returns false then do change the select state of the object
  202. if(_cmGrPlotObjCb(op, kPreEventCbSelGrPlId, kSelectGrPlFl ) == false )
  203. return;
  204. if( clearFl )
  205. {
  206. cmGrObjH_t parentObjH = cmGrObjParent(op->grObjH);
  207. cmGrPlotObj_t* cop = op->p->list;
  208. // clear the select flag on all objects that share op->parent
  209. for(; cop!=NULL; cop=cop->next)
  210. if( cmHandlesAreEqual(cmGrObjParent(cop->grObjH),parentObjH) )
  211. cop->stateFlags = cmClrFlag(cop->stateFlags,kSelectGrPlFl);
  212. }
  213. op->stateFlags = cmTogFlag(stateFlags,kSelectGrPlFl);
  214. // notify state change
  215. _cmGrPlotObjCb(op, kStateChangeGrPlId, kSelectGrPlFl );
  216. }
  217. const cmGrColor_t _cmGrPlotColor( cmGrPlotObj_t* op, cmGrColor_t* array )
  218. {
  219. if( _cmGrPlotObjIsFocused(op) )
  220. return array[kFocusPlGrId];
  221. if( _cmGrPlotObjIsSelected(op) )
  222. return array[kSelectPlGrId];
  223. if( _cmGrPlotObjIsEnabled(op) )
  224. return array[kEnablePlGrId];
  225. return array[kDisablePlGrId];
  226. }
  227. unsigned _cmGrPlotObjTriShapeToFlags( unsigned typeId)
  228. {
  229. switch(typeId)
  230. {
  231. case kUTriGrPlId: return kTopGrFl;
  232. case kDTriGrPlId: return kBottomGrFl;
  233. case kLTriGrPlId: return kLeftGrFl;
  234. case kRTriGrPlId: return kRightGrFl;
  235. default:
  236. { assert(0); }
  237. }
  238. return 0;
  239. }
  240. //------------------------------------------------------------------------------------------------------------------
  241. // Plot Object Callback Functions
  242. //------------------------------------------------------------------------------------------------------------------
  243. cmGrRC_t _cmGrPlotObjCreate( cmGrObjFuncArgs_t* args )
  244. {
  245. cmGrPlotObj_t* op = args->cbArg;
  246. _cmGrPlotObjCb(op,kCreatedCbSelGrPlId,0);
  247. // return kOkGrRC to indicate that the create was successful
  248. return kOkGrRC;
  249. }
  250. void _cmGrPlotObjDestroy( cmGrObjFuncArgs_t* args )
  251. {
  252. cmGrPlotObj_t* op = args->cbArg;
  253. // TODO: is it possible to prevent destruction by returning
  254. // 'false' from the used defined callback. This feature is
  255. // slightly complicated by the fact
  256. // that in some circumstances the destroy request is not
  257. // optional - for example when the program is closing.
  258. _cmGrPlotObjCb(op,kDestroyedCbSelGrPlId,0);
  259. _cmGrPlotObjUnlink( op );
  260. cmMemFree(op->label);
  261. cmMemFree(op);
  262. }
  263. void _cmGrPlotObjGetVExt( cmGrPlotObj_t* op, cmGrVExt_t* vext )
  264. {
  265. switch( op->typeId )
  266. {
  267. case kStarGrPlId:
  268. case kCrossGrPlId:
  269. case kPlusGrPlId:
  270. case kDiamondGrPlId:
  271. case kUTriGrPlId:
  272. case kDTriGrPlId:
  273. case kLTriGrPlId:
  274. case kRTriGrPlId:
  275. case kRectGrPlId:
  276. case kLineGrPlId:
  277. case kEllipseGrPlId:
  278. {
  279. *vext = op->vext;
  280. }
  281. break;
  282. case kHLineGrPlId:
  283. case kVLineGrPlId:
  284. {
  285. cmGrVExt_t wext;
  286. cmGrObjH_t oh = cmGrObjParent(op->grObjH);
  287. cmGrObjWorldExt(oh,&wext);
  288. // TODO: Put a check somewhere which can report an error
  289. // message when the parents world extent is not yet set.
  290. // Horz and Vert lines depend on the their parent's
  291. // world extents being set first. There is no automatic
  292. // way to set the parent world extents because we don't
  293. // know the range of values which the data set will cover.
  294. // Any number picked could result in a range much to large
  295. // thereby leaving the data invisible. It therefore must
  296. // be up to the application to set a good range.
  297. assert( cmGrVExtIsNotNullOrEmpty(&wext) );
  298. vext->loc.x = op->typeId==kHLineGrPlId ? wext.loc.x : op->vext.loc.x;
  299. vext->loc.y = op->typeId==kVLineGrPlId ? wext.loc.y : op->vext.loc.y;
  300. vext->sz.w = op->typeId==kHLineGrPlId ? wext.sz.w : op->vext.sz.w;
  301. vext->sz.h = op->typeId==kVLineGrPlId ? wext.sz.h : op->vext.sz.h;
  302. }
  303. break;
  304. default:
  305. { assert(0); }
  306. }
  307. // add up the anchor offsets until the first object in the container
  308. cmGrPlotObj_t* ap = op->xAnchor;
  309. for(; ap!=NULL; ap=ap->xAnchor)
  310. {
  311. vext->loc.x += ap->vext.loc.x;
  312. if( ap->xAnchor==ap->parent)
  313. break;
  314. }
  315. ap = op->yAnchor;
  316. for(; ap!=NULL; ap=ap->yAnchor)
  317. {
  318. vext->loc.y += ap->vext.loc.y;
  319. if( ap->yAnchor==ap->parent)
  320. break;
  321. }
  322. }
  323. void _cmGrPlotObjVExt( cmGrObjFuncArgs_t* args, cmGrVExt_t* vext )
  324. {
  325. cmGrPlotObj_t* op = args->cbArg;
  326. _cmGrPlotObjGetVExt(op, vext);
  327. }
  328. bool _cmGrPlotObjRender( cmGrObjFuncArgs_t* args, cmGrDcH_t dcH )
  329. {
  330. cmGrPlotObj_t* op = args->cbArg;
  331. cmGrPExt_t pext;
  332. cmGrVExt_t vext;
  333. if( !_cmGrPlotObjIsVisible(op) )
  334. return false;
  335. // get the virtual extents of this object
  336. _cmGrPlotObjVExt( args, &vext );
  337. // convert the virtual ext's to phys ext's
  338. cmGrVExt_VtoP( op->grH, op->grObjH, &vext, &pext);
  339. // expand the ext's according to the physical offsets
  340. cmGrPExtExpand(&pext,op->loffs,op->toffs,op->roffs,op->boffs);
  341. switch( op->typeId )
  342. {
  343. case kLineGrPlId:
  344. //cmGrDcSetColor( dcH, _cmGrPlotColor(op,op->drawColors) );
  345. //cmGrDcDrawLine( dcH, cmGrPExtL(&pext), cmGrPExtT(&pext), cmGrPExtR(&pext), cmGrPExtB(&pext) );
  346. //break;
  347. case kStarGrPlId:
  348. case kCrossGrPlId:
  349. case kPlusGrPlId:
  350. case kEllipseGrPlId:
  351. case kDiamondGrPlId:
  352. case kUTriGrPlId:
  353. case kDTriGrPlId:
  354. case kLTriGrPlId:
  355. case kRTriGrPlId:
  356. case kRectGrPlId:
  357. case kHLineGrPlId:
  358. case kVLineGrPlId:
  359. {
  360. if( cmIsNotFlag(op->cfgFlags,kNoFillGrPlFl) )
  361. {
  362. // set the fill color
  363. cmGrDcSetColor( dcH, _cmGrPlotColor(op,op->fillColors) );
  364. // draw the fill
  365. switch(op->typeId)
  366. {
  367. case kEllipseGrPlId:
  368. cmGrDcFillEllipse( dcH, pext.loc.x, pext.loc.y, pext.sz.w, pext.sz.h);
  369. break;
  370. case kDiamondGrPlId:
  371. cmGrDcFillDiamond( dcH, pext.loc.x, pext.loc.y, pext.sz.w, pext.sz.h);
  372. break;
  373. case kUTriGrPlId:
  374. case kDTriGrPlId:
  375. case kLTriGrPlId:
  376. case kRTriGrPlId:
  377. cmGrDcFillTriangle( dcH, pext.loc.x, pext.loc.y, pext.sz.w, pext.sz.h, _cmGrPlotObjTriShapeToFlags(op->typeId));
  378. break;
  379. case kStarGrPlId:
  380. case kCrossGrPlId:
  381. case kPlusGrPlId:
  382. case kRectGrPlId:
  383. case kHLineGrPlId:
  384. case kVLineGrPlId:
  385. cmGrDcFillRect( dcH, pext.loc.x, pext.loc.y, pext.sz.w, pext.sz.h);
  386. break;
  387. case kLineGrPlId:
  388. break;
  389. default:
  390. { assert(0); }
  391. }
  392. }
  393. if( cmIsNotFlag(op->cfgFlags,kNoBorderGrPlFl) )
  394. {
  395. // set the border color
  396. cmGrDcSetColor( dcH, _cmGrPlotColor(op,op->drawColors) );
  397. // draw the border
  398. switch(op->typeId)
  399. {
  400. case kEllipseGrPlId:
  401. cmGrDcDrawEllipse( dcH, pext.loc.x, pext.loc.y, pext.sz.w, pext.sz.h);
  402. break;
  403. case kDiamondGrPlId:
  404. cmGrDcDrawDiamond( dcH, pext.loc.x, pext.loc.y, pext.sz.w, pext.sz.h);
  405. break;
  406. case kUTriGrPlId:
  407. case kDTriGrPlId:
  408. case kLTriGrPlId:
  409. case kRTriGrPlId:
  410. cmGrDcDrawTriangle( dcH, pext.loc.x, pext.loc.y, pext.sz.w, pext.sz.h, _cmGrPlotObjTriShapeToFlags(op->typeId));
  411. break;
  412. case kStarGrPlId:
  413. cmGrDcDrawLine( dcH, cmGrPExtL(&pext), cmGrPExtT(&pext), cmGrPExtR(&pext), cmGrPExtB(&pext));
  414. cmGrDcDrawLine( dcH, cmGrPExtL(&pext), cmGrPExtB(&pext), cmGrPExtR(&pext), cmGrPExtT(&pext));
  415. cmGrDcDrawLine( dcH, cmGrPExtL(&pext) + cmGrPExtW(&pext)/2, cmGrPExtT(&pext), cmGrPExtL(&pext) + cmGrPExtW(&pext)/2, cmGrPExtB(&pext));
  416. cmGrDcDrawLine( dcH, cmGrPExtL(&pext), cmGrPExtT(&pext) + cmGrPExtH(&pext)/2, cmGrPExtR(&pext), cmGrPExtT(&pext) + cmGrPExtH(&pext)/2);
  417. break;
  418. case kCrossGrPlId:
  419. cmGrDcDrawLine( dcH, cmGrPExtL(&pext), cmGrPExtT(&pext), cmGrPExtR(&pext), cmGrPExtB(&pext));
  420. cmGrDcDrawLine( dcH, cmGrPExtR(&pext), cmGrPExtT(&pext), cmGrPExtL(&pext), cmGrPExtB(&pext));
  421. break;
  422. case kPlusGrPlId:
  423. cmGrDcDrawLine( dcH, cmGrPExtL(&pext) + cmGrPExtW(&pext)/2, cmGrPExtT(&pext), cmGrPExtL(&pext) + cmGrPExtW(&pext)/2, cmGrPExtB(&pext));
  424. cmGrDcDrawLine( dcH, cmGrPExtL(&pext), cmGrPExtT(&pext) + cmGrPExtH(&pext)/2, cmGrPExtR(&pext), cmGrPExtT(&pext) + cmGrPExtH(&pext)/2);
  425. break;
  426. case kLineGrPlId:
  427. cmGrDcDrawLine( dcH, cmGrPExtL(&pext), cmGrPExtT(&pext), cmGrPExtR(&pext), cmGrPExtB(&pext) );
  428. break;
  429. case kRectGrPlId:
  430. case kHLineGrPlId:
  431. case kVLineGrPlId:
  432. cmGrDcDrawRect( dcH, pext.loc.x, pext.loc.y, pext.sz.w, pext.sz.h);
  433. break;
  434. default:
  435. { assert(0); }
  436. }
  437. }
  438. if( (op->label != NULL) && cmIsNotFlag(op->cfgFlags, kNoLabelGrPlFl) )
  439. {
  440. unsigned cc = cmGrDcColor(dcH);
  441. cmGrDcSetColor(dcH,op->labelColor);
  442. cmGrDcDrawTextJustify( dcH, op->fontId, op->fontSize, op->fontStyle, op->label, &pext, op->labelFlags );
  443. cmGrDcSetColor(dcH,cc);
  444. /*
  445. cmGrPSz_t sz;
  446. cmGrPPt_t pt;
  447. cmGrDcFontSetAndMeasure( dcH, op->fontId, op->fontSize, op->fontStyle, op->label, &sz );
  448. cmGrPExtCtr( &pext, &pt );
  449. cmGrDcDrawText( dcH, op->label, pt.x - sz.w/2, pt.y + sz.h/2 );
  450. */
  451. }
  452. }
  453. break;
  454. default:
  455. { assert(0); }
  456. }
  457. return true;
  458. }
  459. int _cmGrPlotObjDistance( cmGrObjFuncArgs_t* args, int x, int y )
  460. {
  461. return 0;
  462. }
  463. bool _cmGrPlotObjEvent( cmGrObjFuncArgs_t* args, unsigned flags, unsigned key, int px, int py )
  464. {
  465. cmGrPlotObj_t* op = args->cbArg;
  466. bool fl = false;
  467. cmGrPlotCbArg_t a;
  468. if( op->cbFunc != NULL )
  469. {
  470. cmGrPlotObj_t* cb_op = op;
  471. // if this is a key up/dn event and 'op' is not the 'focused op' then callback
  472. // callback on the 'focused op' instead of this 'op'.
  473. if( (cmIsFlag(flags,kKeyDnGrFl) || cmIsFlag(flags,kKeyUpGrFl)) && op->p->fop != op )
  474. cb_op = op->p->fop;
  475. _cmGrPlotObjSetupCbArg(&a,cb_op,kPreEventCbSelGrPlId);
  476. a.eventFlags = flags;
  477. a.eventKey = key;
  478. a.eventX = px;
  479. a.eventY = py;
  480. if( op->cbFunc(&a) == false )
  481. return true;
  482. }
  483. switch( flags & kEvtMask )
  484. {
  485. case kMsDownGrFl:
  486. break;
  487. case kMsUpGrFl:
  488. _cmGrPlotObjSetFocus( op );
  489. fl = true;
  490. break;
  491. case kMsClickGrFl:
  492. _cmGrPlotObjSetSelect(op, cmIsNotFlag(flags,kCtlKeyGrFl) );
  493. fl = true;
  494. break;
  495. case kMsDragGrFl:
  496. {
  497. cmGrVExt_t vext;
  498. cmGrVExt_t wext;
  499. if( cmIsFlag(op->cfgFlags,kNoDragGrPlFl | kNoDrawGrPlFl) )
  500. return false;
  501. // get the parent world extents
  502. cmGrObjWorldExt( cmGrObjParent( args->objH ), &wext );
  503. // calc the new position of the obj
  504. cmGrV_t x = args->msVPt.x - args->msDnVOffs.w;
  505. cmGrV_t y = args->msVPt.y - args->msDnVOffs.h;
  506. cmGrVExtSet(&vext,x,y,op->vext.sz.w,op->vext.sz.h);
  507. // the obj must be remain inside the parent wext
  508. cmGrVExtContain(&wext,&vext);
  509. // calculate the obj's location as an offset from it's anchors
  510. cmGrPlotObj_t* ap = op->xAnchor;
  511. for(; ap!=NULL; ap=ap->xAnchor)
  512. vext.loc.x -= ap->vext.loc.x;
  513. ap = op->yAnchor;
  514. for(; ap!=NULL; ap=ap->yAnchor)
  515. vext.loc.y -= ap->vext.loc.y;
  516. if( !cmGrVExtIsEqual(&op->vext,&vext) )
  517. {
  518. // move the object
  519. op->vext.loc.x = vext.loc.x;
  520. op->vext.loc.y = vext.loc.y;
  521. fl = true;
  522. }
  523. }
  524. break;
  525. case kKeyDnGrFl:
  526. case kKeyUpGrFl:
  527. break;
  528. }
  529. // notify the app of the event
  530. if( op->cbFunc != NULL )
  531. {
  532. a.selId = kEventCbSelGrPlId;
  533. op->cbFunc(&a);
  534. }
  535. return fl;
  536. }
  537. bool _cmGrPlotObjIsInside( cmGrObjFuncArgs_t* args, int px, int py, cmGrV_t vx, cmGrV_t vy )
  538. {
  539. cmGrVExt_t vext;
  540. cmGrPExt_t pext;
  541. cmGrPlotObj_t* op = args->cbArg;
  542. // get the virtual extents of this object
  543. _cmGrPlotObjVExt( args, &vext );
  544. // convert the virtual ext's to phys ext's
  545. cmGrVExt_VtoP(args->grH,args->objH,&vext,&pext);
  546. // expand the ext's according to the off's
  547. cmGrPExtExpand(&pext,op->loffs,op->toffs,op->roffs,op->boffs);
  548. if( op->typeId == kLineGrPlId )
  549. if( cmVOR_PtToLineDistance(cmGrPExtL(&pext),cmGrPExtT(&pext),cmGrPExtR(&pext),cmGrPExtB(&pext),px,py) < 3 )
  550. return true;
  551. // check if the px,py is inside pext
  552. return cmGrPExtIsXyInside(&pext,px,py);
  553. }
  554. void _cmGrPlotFuncObjSetupDefault(cmGrObjFunc_t *f, void* arg )
  555. {
  556. f->createCbFunc = _cmGrPlotObjCreate;
  557. f->createCbArg = arg;
  558. f->destroyCbFunc = _cmGrPlotObjDestroy;
  559. f->destroyCbArg = arg;
  560. f->renderCbFunc = _cmGrPlotObjRender;
  561. f->renderCbArg = arg;
  562. f->distanceCbFunc = _cmGrPlotObjDistance;
  563. f->distanceCbArg = arg;
  564. f->eventCbFunc = _cmGrPlotObjEvent;
  565. f->eventCbArg = arg;
  566. f->vextCbFunc = _cmGrPlotObjVExt;
  567. f->vextCbArg = arg;
  568. f->isInsideCbFunc = _cmGrPlotObjIsInside;
  569. f->isInsideCbArg = arg;
  570. }
  571. //------------------------------------------------------------------------------------------------------------------
  572. // Plot Object Public Functions
  573. //------------------------------------------------------------------------------------------------------------------
  574. cmGrPlRC_t cmGrPlotObjCreate(
  575. cmGrPlH_t hh,
  576. cmGrH_t grH,
  577. cmGrPlObjH_t* hp,
  578. unsigned id,
  579. cmGrPlObjH_t parentPlObjH,
  580. cmGrPlObjH_t xAnchorPlObjH,
  581. cmGrPlObjH_t yAnchorPlObjH,
  582. cmGrPlObjTypeId_t typeId,
  583. unsigned cfgFlags,
  584. cmReal_t x,
  585. cmReal_t y,
  586. cmReal_t w,
  587. cmReal_t h,
  588. const cmChar_t* label,
  589. const cmGrVExt_t* wext )
  590. {
  591. cmGrPlRC_t rc;
  592. cmGrObjFunc_t funcs;
  593. if((rc = cmGrPlotObjDestroy(hp)) != kOkGrPlRC )
  594. return rc;
  595. cmGrPl_t* p = _cmGrPlHandleToPtr(hh);
  596. cmGrPlotObj_t* op = cmMemAllocZ(cmGrPlotObj_t,1);
  597. _cmGrPlotObjLink(p,op);
  598. _cmGrPlotFuncObjSetupDefault(&funcs,op);
  599. // setup the object
  600. op->grH = grH;
  601. op->typeId = typeId;
  602. op->cfgFlags = cfgFlags;
  603. op->stateFlags = kEnabledGrPlFl;
  604. op->label = label==NULL ?NULL : cmMemAllocStr(label);
  605. op->labelFlags = kHorzCtrJsGrFl | kVertCtrJsGrFl;
  606. op->labelAngle = 0;
  607. op->labelColor = kBlackGrId;
  608. op->grObjH = cmGrObjNullHandle;
  609. op->parent = cmGrPlotObjIsValid(parentPlObjH) ? _cmGrPlObjHandleToPtr(parentPlObjH) : NULL;
  610. op->xAnchor = cmGrPlotObjIsValid(xAnchorPlObjH) ? _cmGrPlObjHandleToPtr(xAnchorPlObjH) : NULL;
  611. op->yAnchor = cmGrPlotObjIsValid(yAnchorPlObjH) ? _cmGrPlObjHandleToPtr(yAnchorPlObjH) : NULL;
  612. op->p = p;
  613. op->fontId = kHelveticaFfGrId;
  614. op->fontSize = 12;
  615. op->fontStyle = kNormalFsGrFl;
  616. op->cbFunc = p->cbFunc;
  617. op->cbArg = p->cbArg;
  618. if( cmIsFlag(op->cfgFlags,kSymbolGrPlFl) )
  619. {
  620. int ww = w==0 ? kDefaultSymW : w;
  621. int hh = h==0 ? kDefaultSymH : h;
  622. op->loffs = ww/2;
  623. op->roffs = ww/2;
  624. op->toffs = hh/2;
  625. op->boffs = hh/2;
  626. w = 0;
  627. h = 0;
  628. }
  629. cmGrVExtSet(&op->vext,x,y,w,h);
  630. // set the default colors
  631. op->drawColors[kFocusPlGrId] = 0xcd853f;
  632. op->fillColors[kFocusPlGrId] = 0xdeb887;
  633. op->drawColors[kSelectPlGrId] = 0x483d8b;
  634. op->fillColors[kSelectPlGrId] = 0x8470ff;
  635. op->drawColors[kEnablePlGrId] = 0x000000;
  636. op->fillColors[kEnablePlGrId] = 0x009ff7;
  637. op->drawColors[kDisablePlGrId] = 0xbebebe;
  638. op->fillColors[kDisablePlGrId] = 0xd3d3de;
  639. unsigned grObjCfgFlags = 0;
  640. cmGrObjH_t parentGrH = op->parent == NULL ? cmGrObjNullHandle : op->parent->grObjH;
  641. // create the graphics system object - during this call a
  642. // call is made to funcs.create().
  643. if( cmGrObjCreate(grH, &op->grObjH, parentGrH, &funcs, id, grObjCfgFlags, wext ) != kOkGrRC )
  644. {
  645. rc = cmErrMsg(&p->err,kGrFailGrPlRC,"Graphic system object create failed for object (id=%i).",id);
  646. goto errLabel;
  647. }
  648. if( hp != NULL )
  649. hp->h = op;
  650. errLabel:
  651. if( rc != kOkGrPlRC )
  652. _cmGrPlotObjDelete(op);
  653. return rc;
  654. }
  655. cmGrPlRC_t cmGrPlotObjDestroy( cmGrPlObjH_t* hp )
  656. {
  657. cmGrPlRC_t rc = kOkGrPlRC;
  658. if( hp==NULL || cmGrPlotObjIsValid(*hp)==false )
  659. return kOkGrPlRC;
  660. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(*hp);
  661. if((rc = _cmGrPlotObjDelete(op)) != kOkGrPlRC )
  662. return rc;
  663. hp->h = NULL;
  664. return rc;
  665. }
  666. bool cmGrPlotObjIsValid( cmGrPlObjH_t h )
  667. { return h.h != NULL; }
  668. cmGrPlH_t cmGrPlotObjMgrHandle( cmGrPlObjH_t oh )
  669. {
  670. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  671. cmGrPlH_t grPlH;
  672. grPlH.h = op->p;
  673. return grPlH;
  674. }
  675. cmGrObjH_t cmGrPlotObjHandle( cmGrPlObjH_t oh )
  676. {
  677. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  678. return op->grObjH;
  679. }
  680. cmGrPlObjH_t cmGrPlotObjParent( cmGrPlObjH_t oh )
  681. {
  682. cmGrPlObjH_t p_oh;
  683. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  684. p_oh.h = op->parent;
  685. return p_oh;
  686. }
  687. cmGrPlObjH_t cmGrPlotObjXAnchor( cmGrPlObjH_t oh )
  688. {
  689. cmGrPlObjH_t p_oh;
  690. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  691. p_oh.h = op->xAnchor;
  692. return p_oh;
  693. }
  694. cmGrPlObjH_t cmGrPlotObjYAnchor( cmGrPlObjH_t oh )
  695. {
  696. cmGrPlObjH_t p_oh;
  697. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  698. p_oh.h = op->yAnchor;
  699. return p_oh;
  700. }
  701. void cmGrPlotObjSetId( cmGrPlObjH_t oh, unsigned id )
  702. {
  703. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  704. cmGrObjSetId( op->grObjH, id );
  705. }
  706. void cmGrPlotObjSetUserPtr( cmGrPlObjH_t oh, void* userPtr )
  707. {
  708. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  709. if( op->userByteCnt != 0 )
  710. {
  711. cmMemFree(op->userPtr);
  712. op->userByteCnt = 0;
  713. }
  714. op->userPtr = userPtr;
  715. }
  716. void cmGrPlotObjAllocUser( cmGrPlObjH_t oh, const void* data, unsigned byteCnt )
  717. {
  718. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  719. if( op->userByteCnt != byteCnt )
  720. {
  721. if( op->userByteCnt != 0 )
  722. {
  723. cmMemFree(op->userPtr);
  724. op->userByteCnt = 0;
  725. }
  726. op->userPtr = cmMemAlloc(char,byteCnt);
  727. op->userByteCnt = byteCnt;
  728. }
  729. memcpy(op->userPtr,data,byteCnt);
  730. }
  731. void* cmGrPlotObjUserPtr( cmGrPlObjH_t oh )
  732. {
  733. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  734. return op->userPtr;
  735. }
  736. unsigned cmGrPlotObjId( cmGrPlObjH_t oh )
  737. {
  738. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  739. return cmGrObjId(op->grObjH);
  740. }
  741. void cmGrPlotObjSetLabel( cmGrPlObjH_t oh, const cmChar_t* label )
  742. {
  743. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  744. if( label == op->label || (label != NULL && op->label!=NULL && strcmp(label,op->label)==0 ))
  745. return;
  746. cmMemPtrFree(&op->label);
  747. if( label != NULL )
  748. {
  749. assert( op->label == NULL );
  750. op->label = cmMemAllocStr(label);
  751. }
  752. }
  753. const cmChar_t* cmGrPlotObjLabel( cmGrPlObjH_t oh )
  754. {
  755. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  756. return op->label;
  757. }
  758. void cmGrPlotObjSetLabelAttr( cmGrPlObjH_t oh, unsigned flags, int angle, const cmGrColor_t color )
  759. {
  760. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  761. op->labelFlags = flags;
  762. op->labelAngle = angle;
  763. op->labelColor = color;
  764. }
  765. unsigned cmGrPlotObjLabelFlags( cmGrPlObjH_t oh )
  766. {
  767. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  768. return op->labelFlags;
  769. }
  770. int cmGrPlotObjLabelAngle( cmGrPlObjH_t oh )
  771. {
  772. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  773. return op->labelAngle;
  774. }
  775. const cmGrColor_t cmGrPlotObjLabelColor( cmGrPlObjH_t oh )
  776. {
  777. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  778. return op->labelColor;
  779. }
  780. void cmGrPlotObjSetStateFlags( cmGrPlObjH_t oh, unsigned flags )
  781. {
  782. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  783. if( cmIsFlag(flags,kVisibleGrPlFl) != _cmGrPlotObjIsVisible(op) )
  784. {
  785. if( _cmGrPlotObjCb(op, kPreEventCbSelGrPlId, kVisibleGrPlFl ) == false )
  786. return;
  787. op->cfgFlags = cmTogFlag(op->cfgFlags,kNoDrawGrPlFl);
  788. _cmGrPlotObjCb(op, kStateChangeGrPlId, kVisibleGrPlFl );
  789. }
  790. if( cmIsFlag(flags,kEnabledGrPlFl) != _cmGrPlotObjIsEnabled(op) )
  791. {
  792. if( _cmGrPlotObjCb(op, kPreEventCbSelGrPlId, kEnabledGrPlFl ) == false )
  793. return;
  794. op->stateFlags = cmTogFlag(op->cfgFlags,kEnabledGrPlFl);
  795. _cmGrPlotObjCb(op, kStateChangeGrPlId, kEnabledGrPlFl );
  796. }
  797. bool fl;
  798. if( cmIsFlag(flags,kSelectGrPlFl) != (fl=_cmGrPlotObjIsSelected(op)) )
  799. _cmGrPlotObjSetSelect(op, !fl );
  800. if( cmIsFlag(flags,kFocusGrPlFl) != (fl=_cmGrPlotObjIsFocused(op)) )
  801. if( fl )
  802. _cmGrPlotObjSetFocus(op);
  803. }
  804. unsigned cmGrPlotObjStateFlags( cmGrPlObjH_t oh )
  805. {
  806. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  807. return
  808. (_cmGrPlotObjIsEnabled(op) ? kEnabledGrPlFl : 0)
  809. | (_cmGrPlotObjIsVisible(op) ? kVisibleGrPlFl : 0)
  810. | (_cmGrPlotObjIsFocused(op) ? kFocusGrPlFl : 0)
  811. | (_cmGrPlotObjIsSelected(op) ? kSelectGrPlFl : 0);
  812. }
  813. void cmGrPlotObjSetCfgFlags( cmGrPlObjH_t oh, unsigned flags )
  814. {
  815. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  816. op->cfgFlags = flags;
  817. }
  818. void cmGrPlotObjClrCfgFlags( cmGrPlObjH_t oh, unsigned flags )
  819. {
  820. unsigned curFlags = cmGrPlotObjCfgFlags(oh);
  821. cmGrPlotObjSetCfgFlags(oh, cmClrFlag(curFlags,flags));
  822. }
  823. void cmGrPlotObjTogCfgFlags( cmGrPlObjH_t oh, unsigned flags )
  824. {
  825. unsigned curFlags = cmGrPlotObjCfgFlags(oh);
  826. cmGrPlotObjSetCfgFlags(oh, cmTogFlag(curFlags,flags));
  827. }
  828. unsigned cmGrPlotObjCfgFlags( cmGrPlObjH_t oh )
  829. {
  830. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  831. return op->cfgFlags;
  832. }
  833. cmGrPlRC_t cmGrPlotObjSetPhysExt( cmGrPlObjH_t oh, int loffs, int toffs, int roffs, int boffs )
  834. {
  835. cmGrPlRC_t rc = kOkGrPlRC;
  836. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  837. op->loffs = loffs;
  838. op->toffs = toffs;
  839. op->roffs = roffs;
  840. op->boffs = boffs;
  841. return rc;
  842. }
  843. void cmGrPlotObjPhysExt( cmGrPlObjH_t oh, int* loffs, int* toffs, int* roffs, int* boffs )
  844. {
  845. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  846. if( loffs != NULL )
  847. *loffs = op->loffs;
  848. if( toffs != NULL )
  849. *toffs = op->toffs;
  850. if( roffs != NULL )
  851. *roffs = op->roffs;
  852. if( boffs != NULL )
  853. *boffs = op->boffs;
  854. }
  855. void cmGrPlotObjVExt( cmGrPlObjH_t oh, cmGrVExt_t* vext )
  856. {
  857. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  858. _cmGrPlotObjGetVExt(op, vext);
  859. }
  860. void cmGrPlotObjSetFontFamily( cmGrPlObjH_t oh, unsigned id )
  861. {
  862. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  863. op->fontId = id;
  864. }
  865. unsigned cmGrPlotObjFontFamily( cmGrPlObjH_t oh )
  866. {
  867. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  868. return op->fontId;
  869. }
  870. void cmGrPlotObjSetFontStyle( cmGrPlObjH_t oh, unsigned style )
  871. {
  872. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  873. op->fontStyle = style;
  874. }
  875. unsigned cmGrPlotObjFontStyle( cmGrPlObjH_t oh )
  876. {
  877. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  878. return op->fontStyle;
  879. }
  880. void cmGrPlotObjSetFontSize( cmGrPlObjH_t oh, unsigned size )
  881. {
  882. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  883. op->fontSize = size;
  884. }
  885. unsigned cmGrPlotObjFontSize( cmGrPlObjH_t oh )
  886. {
  887. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  888. return op->fontSize;
  889. }
  890. void cmGrPlotObjSetLineColor( cmGrPlObjH_t oh, cmGrPlStateId_t id, const cmGrColor_t c )
  891. {
  892. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  893. assert( id < kMaxPlGrId );
  894. op->drawColors[ id ] = c;
  895. }
  896. const cmGrColor_t cmGrPlotObjLineColor( cmGrPlObjH_t oh, cmGrPlStateId_t id )
  897. {
  898. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  899. assert( id < kMaxPlGrId );
  900. return op->drawColors[id];
  901. }
  902. const cmGrColor_t cmGrPlotObjCurLineColor( cmGrPlObjH_t h )
  903. {
  904. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(h);
  905. return _cmGrPlotColor(op,op->drawColors);
  906. }
  907. void cmGrPlotObjSetFillColor( cmGrPlObjH_t oh, cmGrPlStateId_t id, const cmGrColor_t c )
  908. {
  909. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  910. assert( id < kMaxPlGrId );
  911. op->fillColors[ id ] = c;
  912. }
  913. const cmGrColor_t cmGrPlotObjFillColor( cmGrPlObjH_t oh, cmGrPlStateId_t id )
  914. {
  915. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  916. assert( id < kMaxPlGrId );
  917. return op->fillColors[id];
  918. }
  919. const cmGrColor_t cmGrPlotObjCurFillColor( cmGrPlObjH_t h )
  920. {
  921. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(h);
  922. return _cmGrPlotColor(op,op->fillColors);
  923. }
  924. void cmGrPlotObjSetCb( cmGrPlObjH_t h, cmGrPlotCbFunc_t func, void* arg )
  925. {
  926. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(h);
  927. op->cbFunc = func;
  928. op->cbArg = arg;
  929. }
  930. cmGrPlotCbFunc_t cmGrPlotObjCbFunc( cmGrPlObjH_t h )
  931. {
  932. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(h);
  933. return op->cbFunc;
  934. }
  935. void* cmGrPlotObjCbArg( cmGrPlObjH_t h )
  936. {
  937. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(h);
  938. return op->cbArg;
  939. }
  940. void cmGrPlotObjDrawAbove( cmGrPlObjH_t bH, cmGrPlObjH_t aH )
  941. {
  942. cmGrPlotObj_t* bop = _cmGrPlObjHandleToPtr(bH);
  943. cmGrPlotObj_t* aop = _cmGrPlObjHandleToPtr(aH);
  944. cmGrObjDrawAbove(bop->grObjH,aop->grObjH);
  945. }
  946. //------------------------------------------------------------------------------------------------------------------
  947. // Plot Object Manager Functions
  948. //------------------------------------------------------------------------------------------------------------------
  949. cmGrPlRC_t cmGrPlotCreate( cmCtx_t* ctx, cmGrPlH_t* hp )
  950. {
  951. cmGrPlRC_t rc;
  952. if((rc = cmGrPlotDestroy(hp)) != kOkGrPlRC )
  953. return rc;
  954. cmGrPl_t* p = cmMemAllocZ(cmGrPl_t,1);
  955. cmErrSetup(&p->err,&ctx->rpt,"cmGrPlot");
  956. p->ctx = ctx;
  957. hp->h = p;
  958. if( rc != kOkGrPlRC )
  959. _cmGrPlotDestroy(p);
  960. return rc;
  961. }
  962. cmGrPlRC_t cmGrPlotDestroy( cmGrPlH_t* hp )
  963. {
  964. cmGrPlRC_t rc;
  965. if( hp==NULL || cmGrPlotIsValid(*hp) == false )
  966. return kOkGrPlRC;
  967. cmGrPl_t* p = _cmGrPlHandleToPtr(*hp);
  968. if((rc = _cmGrPlotDestroy(p)) != kOkGrPlRC )
  969. return rc;
  970. hp->h = NULL;
  971. return rc;
  972. }
  973. bool cmGrPlotIsValid( cmGrPlH_t h )
  974. { return h.h != NULL; }
  975. cmGrPlRC_t cmGrPlotClear( cmGrPlH_t h )
  976. {
  977. cmGrPl_t* p = _cmGrPlHandleToPtr(h);
  978. return _cmGrPlotClear(p);
  979. }
  980. cmErr_t* cmGrPlotErr( cmGrPlH_t h )
  981. {
  982. cmGrPl_t* p = _cmGrPlHandleToPtr(h);
  983. return &p->err;
  984. }
  985. cmRpt_t* cmGrPlotRpt( cmGrPlH_t h )
  986. {
  987. cmGrPl_t* p = _cmGrPlHandleToPtr(h);
  988. return p->err.rpt;
  989. }
  990. cmGrPlObjH_t cmGrPlotObjectIdToHandle( cmGrPlH_t h, unsigned id )
  991. {
  992. cmGrPl_t* p = _cmGrPlHandleToPtr(h);
  993. cmGrPlObjH_t oh = cmGrPlObjNullHandle;
  994. cmGrPlotObj_t* op = p->list;
  995. for(; op!=NULL; op=op->next)
  996. if( cmGrObjId(op->grObjH) == id )
  997. {
  998. oh.h = op;
  999. break;
  1000. }
  1001. return oh;
  1002. }
  1003. unsigned cmGrPlotObjectCount( cmGrPlH_t h )
  1004. {
  1005. cmGrPl_t* p = _cmGrPlHandleToPtr(h);
  1006. cmGrPlotObj_t* op = p->list;
  1007. unsigned n = 0;
  1008. for(; op!=NULL; ++n )
  1009. op=op->next;
  1010. return n;
  1011. }
  1012. cmGrPlObjH_t cmGrPlotObjectIndexToHandle( cmGrPlH_t h, unsigned index )
  1013. {
  1014. cmGrPl_t* p = _cmGrPlHandleToPtr(h);
  1015. cmGrPlotObj_t* op = p->list;
  1016. unsigned i = 0;
  1017. cmGrPlObjH_t oh = cmGrPlObjNullHandle;
  1018. for(; i<index && op!=NULL; ++i)
  1019. op = op->next;
  1020. if( op != NULL )
  1021. oh.h = op;
  1022. return oh;
  1023. }
  1024. void cmGrPlotKeyEvent( cmGrPlH_t h, cmGrH_t grH, unsigned eventFlags, cmGrKeyCodeId_t keycode )
  1025. {
  1026. assert( cmIsFlag(eventFlags,kKeyDnGrFl | kKeyUpGrFl));
  1027. cmGrPl_t* p = _cmGrPlHandleToPtr(h);
  1028. if( p->fop != NULL && cmHandlesAreEqual(p->fop->grH,grH) )
  1029. {
  1030. cmGrObjFuncArgs_t a;
  1031. memset(&a,0,sizeof(a));
  1032. a.cbArg = p->fop;
  1033. a.ctx = p->ctx;
  1034. a.grH = grH;
  1035. a.objH = p->fop->grObjH;
  1036. _cmGrPlotObjEvent(&a, eventFlags, keycode, 0, 0 );
  1037. }
  1038. }
  1039. void cmGrPlotSetCb( cmGrPlH_t h, cmGrPlotCbFunc_t func, void* arg )
  1040. {
  1041. cmGrPl_t* p = _cmGrPlHandleToPtr(h);
  1042. p->cbFunc = func;
  1043. p->cbArg = arg;
  1044. }