libcm is a C development framework with an emphasis on audio signal processing applications.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

cmGrPlot.c 36KB

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