libcm is a C development framework with an emphasis on audio signal processing applications.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

cmGrPlot.c 36KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  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 _cmGrPlotObjIsBorderClick( const cmGrPExt_t* pext, int px, int py )
  538. {
  539. int dist = 3;
  540. if( cmVOR_PtToLineDistance(cmGrPExtL(pext),cmGrPExtT(pext),cmGrPExtL(pext),cmGrPExtB(pext),px,py) < dist )
  541. return true;
  542. if(cmVOR_PtToLineDistance(cmGrPExtR(pext),cmGrPExtT(pext),cmGrPExtR(pext),cmGrPExtB(pext),px,py) < dist )
  543. return true;
  544. if( cmVOR_PtToLineDistance(cmGrPExtL(pext),cmGrPExtT(pext),cmGrPExtR(pext),cmGrPExtT(pext),px,py) < dist )
  545. return true;
  546. if(cmVOR_PtToLineDistance(cmGrPExtL(pext),cmGrPExtB(pext),cmGrPExtR(pext),cmGrPExtB(pext),px,py) < dist )
  547. return true;
  548. return false;
  549. }
  550. bool _cmGrPlotObjIsInside( cmGrObjFuncArgs_t* args, unsigned evtFlags, int px, int py, cmGrV_t vx, cmGrV_t vy )
  551. {
  552. cmGrVExt_t vext;
  553. cmGrPExt_t pext;
  554. cmGrPlotObj_t* op = args->cbArg;
  555. // no matter the type of event the object must be visible and enabled to respond to it
  556. if(!_cmGrPlotObjIsVisible(op)|| !_cmGrPlotObjIsEnabled(op) )
  557. return false;
  558. // objects that are not selectable are also not clickable
  559. if( cmIsFlag(evtFlags,kMsClickGrFl) && cmIsFlag(op->cfgFlags,kNoSelectGrPlFl) )
  560. return false;
  561. // non-draggable objects can't be dragged.
  562. if( cmIsFlag(evtFlags,kMsDragGrFl) && cmIsFlag(op->cfgFlags,kNoDragGrPlFl) )
  563. return false;
  564. // get the virtual extents of this object
  565. _cmGrPlotObjVExt( args, &vext );
  566. // convert the virtual ext's to phys ext's
  567. cmGrVExt_VtoP(args->grH,args->objH,&vext,&pext);
  568. // expand the ext's according to the off's
  569. cmGrPExtExpand(&pext,op->loffs,op->toffs,op->roffs,op->boffs);
  570. if( op->typeId == kLineGrPlId )
  571. if( cmVOR_PtToLineDistance(cmGrPExtL(&pext),cmGrPExtT(&pext),cmGrPExtR(&pext),cmGrPExtB(&pext),px,py) < 3 )
  572. return true;
  573. // if this is a click event and this is a border selectable object
  574. if( cmIsFlag(evtFlags,kMsClickGrFl) && cmIsFlag(op->cfgFlags,kBorderSelGrPlFl) )
  575. return _cmGrPlotObjIsBorderClick(&pext,px,py);
  576. // check if the px,py is inside pext
  577. return cmGrPExtIsXyInside(&pext,px,py);
  578. }
  579. void _cmGrPlotFuncObjSetupDefault(cmGrObjFunc_t *f, void* arg )
  580. {
  581. f->createCbFunc = _cmGrPlotObjCreate;
  582. f->createCbArg = arg;
  583. f->destroyCbFunc = _cmGrPlotObjDestroy;
  584. f->destroyCbArg = arg;
  585. f->renderCbFunc = _cmGrPlotObjRender;
  586. f->renderCbArg = arg;
  587. f->distanceCbFunc = _cmGrPlotObjDistance;
  588. f->distanceCbArg = arg;
  589. f->eventCbFunc = _cmGrPlotObjEvent;
  590. f->eventCbArg = arg;
  591. f->vextCbFunc = _cmGrPlotObjVExt;
  592. f->vextCbArg = arg;
  593. f->isInsideCbFunc = _cmGrPlotObjIsInside;
  594. f->isInsideCbArg = arg;
  595. }
  596. //------------------------------------------------------------------------------------------------------------------
  597. // Plot Object Public Functions
  598. //------------------------------------------------------------------------------------------------------------------
  599. cmGrPlRC_t cmGrPlotObjCreate(
  600. cmGrPlH_t hh,
  601. cmGrH_t grH,
  602. cmGrPlObjH_t* hp,
  603. unsigned id,
  604. cmGrPlObjH_t parentPlObjH,
  605. cmGrPlObjH_t xAnchorPlObjH,
  606. cmGrPlObjH_t yAnchorPlObjH,
  607. cmGrPlObjTypeId_t typeId,
  608. unsigned cfgFlags,
  609. cmReal_t x,
  610. cmReal_t y,
  611. cmReal_t w,
  612. cmReal_t h,
  613. const cmChar_t* label,
  614. const cmGrVExt_t* wext )
  615. {
  616. cmGrPlRC_t rc;
  617. cmGrObjFunc_t funcs;
  618. if((rc = cmGrPlotObjDestroy(hp)) != kOkGrPlRC )
  619. return rc;
  620. cmGrPl_t* p = _cmGrPlHandleToPtr(hh);
  621. cmGrPlotObj_t* op = cmMemAllocZ(cmGrPlotObj_t,1);
  622. _cmGrPlotObjLink(p,op);
  623. _cmGrPlotFuncObjSetupDefault(&funcs,op);
  624. // setup the object
  625. op->grH = grH;
  626. op->typeId = typeId;
  627. op->cfgFlags = cfgFlags;
  628. op->stateFlags = kEnabledGrPlFl;
  629. op->label = label==NULL ?NULL : cmMemAllocStr(label);
  630. op->labelFlags = kHorzCtrJsGrFl | kVertCtrJsGrFl;
  631. op->labelAngle = 0;
  632. op->labelColor = kBlackGrId;
  633. op->grObjH = cmGrObjNullHandle;
  634. op->parent = cmGrPlotObjIsValid(parentPlObjH) ? _cmGrPlObjHandleToPtr(parentPlObjH) : NULL;
  635. op->xAnchor = cmGrPlotObjIsValid(xAnchorPlObjH) ? _cmGrPlObjHandleToPtr(xAnchorPlObjH) : NULL;
  636. op->yAnchor = cmGrPlotObjIsValid(yAnchorPlObjH) ? _cmGrPlObjHandleToPtr(yAnchorPlObjH) : NULL;
  637. op->p = p;
  638. op->fontId = kHelveticaFfGrId;
  639. op->fontSize = 12;
  640. op->fontStyle = kNormalFsGrFl;
  641. op->cbFunc = p->cbFunc;
  642. op->cbArg = p->cbArg;
  643. if( cmIsFlag(op->cfgFlags,kSymbolGrPlFl) )
  644. {
  645. int ww = w==0 ? kDefaultSymW : w;
  646. int hh = h==0 ? kDefaultSymH : h;
  647. op->loffs = ww/2;
  648. op->roffs = ww/2;
  649. op->toffs = hh/2;
  650. op->boffs = hh/2;
  651. w = 0;
  652. h = 0;
  653. }
  654. cmGrVExtSet(&op->vext,x,y,w,h);
  655. // set the default colors
  656. op->drawColors[kSelectPlGrId] = 0xcd853f;
  657. op->fillColors[kSelectPlGrId] = 0xdeb887;
  658. op->drawColors[kFocusPlGrId] = 0x483d8b;
  659. op->fillColors[kFocusPlGrId] = 0x8470ff;
  660. op->drawColors[kEnablePlGrId] = 0x000000;
  661. op->fillColors[kEnablePlGrId] = 0x009ff7;
  662. op->drawColors[kDisablePlGrId] = 0xbebebe;
  663. op->fillColors[kDisablePlGrId] = 0xd3d3de;
  664. unsigned grObjCfgFlags = 0;
  665. cmGrObjH_t parentGrH = op->parent == NULL ? cmGrObjNullHandle : op->parent->grObjH;
  666. // create the graphics system object - during this call a
  667. // call is made to funcs.create().
  668. if( cmGrObjCreate(grH, &op->grObjH, parentGrH, &funcs, id, grObjCfgFlags, wext ) != kOkGrRC )
  669. {
  670. rc = cmErrMsg(&p->err,kGrFailGrPlRC,"Graphic system object create failed for object (id=%i).",id);
  671. goto errLabel;
  672. }
  673. if( hp != NULL )
  674. hp->h = op;
  675. errLabel:
  676. if( rc != kOkGrPlRC )
  677. _cmGrPlotObjDelete(op);
  678. return rc;
  679. }
  680. cmGrPlRC_t cmGrPlotObjDestroy( cmGrPlObjH_t* hp )
  681. {
  682. cmGrPlRC_t rc = kOkGrPlRC;
  683. if( hp==NULL || cmGrPlotObjIsValid(*hp)==false )
  684. return kOkGrPlRC;
  685. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(*hp);
  686. if((rc = _cmGrPlotObjDelete(op)) != kOkGrPlRC )
  687. return rc;
  688. hp->h = NULL;
  689. return rc;
  690. }
  691. bool cmGrPlotObjIsValid( cmGrPlObjH_t h )
  692. { return h.h != NULL; }
  693. cmGrPlH_t cmGrPlotObjMgrHandle( cmGrPlObjH_t oh )
  694. {
  695. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  696. cmGrPlH_t grPlH;
  697. grPlH.h = op->p;
  698. return grPlH;
  699. }
  700. cmGrObjH_t cmGrPlotObjHandle( cmGrPlObjH_t oh )
  701. {
  702. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  703. return op->grObjH;
  704. }
  705. cmGrPlObjH_t cmGrPlotObjParent( cmGrPlObjH_t oh )
  706. {
  707. cmGrPlObjH_t p_oh;
  708. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  709. p_oh.h = op->parent;
  710. return p_oh;
  711. }
  712. cmGrPlObjH_t cmGrPlotObjXAnchor( cmGrPlObjH_t oh )
  713. {
  714. cmGrPlObjH_t p_oh;
  715. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  716. p_oh.h = op->xAnchor;
  717. return p_oh;
  718. }
  719. cmGrPlObjH_t cmGrPlotObjYAnchor( cmGrPlObjH_t oh )
  720. {
  721. cmGrPlObjH_t p_oh;
  722. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  723. p_oh.h = op->yAnchor;
  724. return p_oh;
  725. }
  726. void cmGrPlotObjSetId( cmGrPlObjH_t oh, unsigned id )
  727. {
  728. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  729. cmGrObjSetId( op->grObjH, id );
  730. }
  731. void cmGrPlotObjSetUserPtr( cmGrPlObjH_t oh, void* userPtr )
  732. {
  733. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  734. if( op->userByteCnt != 0 )
  735. {
  736. cmMemFree(op->userPtr);
  737. op->userByteCnt = 0;
  738. }
  739. op->userPtr = userPtr;
  740. }
  741. void cmGrPlotObjAllocUser( cmGrPlObjH_t oh, const void* data, unsigned byteCnt )
  742. {
  743. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  744. if( op->userByteCnt != byteCnt )
  745. {
  746. if( op->userByteCnt != 0 )
  747. {
  748. cmMemFree(op->userPtr);
  749. op->userByteCnt = 0;
  750. }
  751. op->userPtr = cmMemAlloc(char,byteCnt);
  752. op->userByteCnt = byteCnt;
  753. }
  754. memcpy(op->userPtr,data,byteCnt);
  755. }
  756. void* cmGrPlotObjUserPtr( cmGrPlObjH_t oh )
  757. {
  758. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  759. return op->userPtr;
  760. }
  761. unsigned cmGrPlotObjId( cmGrPlObjH_t oh )
  762. {
  763. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  764. return cmGrObjId(op->grObjH);
  765. }
  766. void cmGrPlotObjSetLabel( cmGrPlObjH_t oh, const cmChar_t* label )
  767. {
  768. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  769. if( label == op->label || (label != NULL && op->label!=NULL && strcmp(label,op->label)==0 ))
  770. return;
  771. cmMemPtrFree(&op->label);
  772. if( label != NULL )
  773. {
  774. assert( op->label == NULL );
  775. op->label = cmMemAllocStr(label);
  776. }
  777. }
  778. const cmChar_t* cmGrPlotObjLabel( cmGrPlObjH_t oh )
  779. {
  780. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  781. return op->label;
  782. }
  783. void cmGrPlotObjSetLabelAttr( cmGrPlObjH_t oh, unsigned flags, int angle, const cmGrColor_t color )
  784. {
  785. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  786. op->labelFlags = flags;
  787. op->labelAngle = angle;
  788. op->labelColor = color;
  789. }
  790. unsigned cmGrPlotObjLabelFlags( cmGrPlObjH_t oh )
  791. {
  792. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  793. return op->labelFlags;
  794. }
  795. int cmGrPlotObjLabelAngle( cmGrPlObjH_t oh )
  796. {
  797. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  798. return op->labelAngle;
  799. }
  800. const cmGrColor_t cmGrPlotObjLabelColor( cmGrPlObjH_t oh )
  801. {
  802. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  803. return op->labelColor;
  804. }
  805. void cmGrPlotObjSetStateFlags( cmGrPlObjH_t oh, unsigned flags )
  806. {
  807. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  808. if( cmIsFlag(flags,kVisibleGrPlFl) != _cmGrPlotObjIsVisible(op) )
  809. {
  810. if( _cmGrPlotObjCb(op, kPreEventCbSelGrPlId, kVisibleGrPlFl ) == false )
  811. return;
  812. op->cfgFlags = cmTogFlag(op->cfgFlags,kNoDrawGrPlFl);
  813. _cmGrPlotObjCb(op, kStateChangeGrPlId, kVisibleGrPlFl );
  814. }
  815. if( cmIsFlag(flags,kEnabledGrPlFl) != _cmGrPlotObjIsEnabled(op) )
  816. {
  817. if( _cmGrPlotObjCb(op, kPreEventCbSelGrPlId, kEnabledGrPlFl ) == false )
  818. return;
  819. op->stateFlags = cmTogFlag(op->cfgFlags,kEnabledGrPlFl);
  820. _cmGrPlotObjCb(op, kStateChangeGrPlId, kEnabledGrPlFl );
  821. }
  822. bool fl;
  823. if( cmIsFlag(flags,kSelectGrPlFl) != (fl=_cmGrPlotObjIsSelected(op)) )
  824. _cmGrPlotObjSetSelect(op, !fl );
  825. if( cmIsFlag(flags,kFocusGrPlFl) != (fl=_cmGrPlotObjIsFocused(op)) )
  826. if( fl )
  827. _cmGrPlotObjSetFocus(op);
  828. }
  829. unsigned cmGrPlotObjStateFlags( cmGrPlObjH_t oh )
  830. {
  831. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  832. return
  833. (_cmGrPlotObjIsEnabled(op) ? kEnabledGrPlFl : 0)
  834. | (_cmGrPlotObjIsVisible(op) ? kVisibleGrPlFl : 0)
  835. | (_cmGrPlotObjIsFocused(op) ? kFocusGrPlFl : 0)
  836. | (_cmGrPlotObjIsSelected(op) ? kSelectGrPlFl : 0);
  837. }
  838. void cmGrPlotObjSetCfgFlags( cmGrPlObjH_t oh, unsigned flags )
  839. {
  840. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  841. op->cfgFlags = flags;
  842. }
  843. void cmGrPlotObjClrCfgFlags( cmGrPlObjH_t oh, unsigned flags )
  844. {
  845. unsigned curFlags = cmGrPlotObjCfgFlags(oh);
  846. cmGrPlotObjSetCfgFlags(oh, cmClrFlag(curFlags,flags));
  847. }
  848. void cmGrPlotObjTogCfgFlags( cmGrPlObjH_t oh, unsigned flags )
  849. {
  850. unsigned curFlags = cmGrPlotObjCfgFlags(oh);
  851. cmGrPlotObjSetCfgFlags(oh, cmTogFlag(curFlags,flags));
  852. }
  853. unsigned cmGrPlotObjCfgFlags( cmGrPlObjH_t oh )
  854. {
  855. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  856. return op->cfgFlags;
  857. }
  858. cmGrPlRC_t cmGrPlotObjSetPhysExt( cmGrPlObjH_t oh, int loffs, int toffs, int roffs, int boffs )
  859. {
  860. cmGrPlRC_t rc = kOkGrPlRC;
  861. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  862. op->loffs = loffs;
  863. op->toffs = toffs;
  864. op->roffs = roffs;
  865. op->boffs = boffs;
  866. return rc;
  867. }
  868. void cmGrPlotObjPhysExt( cmGrPlObjH_t oh, int* loffs, int* toffs, int* roffs, int* boffs )
  869. {
  870. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  871. if( loffs != NULL )
  872. *loffs = op->loffs;
  873. if( toffs != NULL )
  874. *toffs = op->toffs;
  875. if( roffs != NULL )
  876. *roffs = op->roffs;
  877. if( boffs != NULL )
  878. *boffs = op->boffs;
  879. }
  880. void cmGrPlotObjVExt( cmGrPlObjH_t oh, cmGrVExt_t* vext )
  881. {
  882. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  883. _cmGrPlotObjGetVExt(op, vext);
  884. }
  885. void cmGrPlotObjSetFontFamily( cmGrPlObjH_t oh, unsigned id )
  886. {
  887. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  888. op->fontId = id;
  889. }
  890. unsigned cmGrPlotObjFontFamily( cmGrPlObjH_t oh )
  891. {
  892. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  893. return op->fontId;
  894. }
  895. void cmGrPlotObjSetFontStyle( cmGrPlObjH_t oh, unsigned style )
  896. {
  897. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  898. op->fontStyle = style;
  899. }
  900. unsigned cmGrPlotObjFontStyle( cmGrPlObjH_t oh )
  901. {
  902. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  903. return op->fontStyle;
  904. }
  905. void cmGrPlotObjSetFontSize( cmGrPlObjH_t oh, unsigned size )
  906. {
  907. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  908. op->fontSize = size;
  909. }
  910. unsigned cmGrPlotObjFontSize( cmGrPlObjH_t oh )
  911. {
  912. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  913. return op->fontSize;
  914. }
  915. void cmGrPlotObjSetLineColor( cmGrPlObjH_t oh, cmGrPlStateId_t id, const cmGrColor_t c )
  916. {
  917. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  918. assert( id < kMaxPlGrId );
  919. op->drawColors[ id ] = c;
  920. }
  921. const cmGrColor_t cmGrPlotObjLineColor( cmGrPlObjH_t oh, cmGrPlStateId_t id )
  922. {
  923. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  924. assert( id < kMaxPlGrId );
  925. return op->drawColors[id];
  926. }
  927. const cmGrColor_t cmGrPlotObjCurLineColor( cmGrPlObjH_t h )
  928. {
  929. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(h);
  930. return _cmGrPlotColor(op,op->drawColors);
  931. }
  932. void cmGrPlotObjSetFillColor( cmGrPlObjH_t oh, cmGrPlStateId_t id, const cmGrColor_t c )
  933. {
  934. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  935. assert( id < kMaxPlGrId );
  936. op->fillColors[ id ] = c;
  937. }
  938. const cmGrColor_t cmGrPlotObjFillColor( cmGrPlObjH_t oh, cmGrPlStateId_t id )
  939. {
  940. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(oh);
  941. assert( id < kMaxPlGrId );
  942. return op->fillColors[id];
  943. }
  944. const cmGrColor_t cmGrPlotObjCurFillColor( cmGrPlObjH_t h )
  945. {
  946. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(h);
  947. return _cmGrPlotColor(op,op->fillColors);
  948. }
  949. void cmGrPlotObjSetCb( cmGrPlObjH_t h, cmGrPlotCbFunc_t func, void* arg )
  950. {
  951. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(h);
  952. op->cbFunc = func;
  953. op->cbArg = arg;
  954. }
  955. cmGrPlotCbFunc_t cmGrPlotObjCbFunc( cmGrPlObjH_t h )
  956. {
  957. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(h);
  958. return op->cbFunc;
  959. }
  960. void* cmGrPlotObjCbArg( cmGrPlObjH_t h )
  961. {
  962. cmGrPlotObj_t* op = _cmGrPlObjHandleToPtr(h);
  963. return op->cbArg;
  964. }
  965. void cmGrPlotObjDrawAbove( cmGrPlObjH_t bH, cmGrPlObjH_t aH )
  966. {
  967. cmGrPlotObj_t* bop = _cmGrPlObjHandleToPtr(bH);
  968. cmGrPlotObj_t* aop = _cmGrPlObjHandleToPtr(aH);
  969. cmGrObjDrawAbove(bop->grObjH,aop->grObjH);
  970. }
  971. //------------------------------------------------------------------------------------------------------------------
  972. // Plot Object Manager Functions
  973. //------------------------------------------------------------------------------------------------------------------
  974. cmGrPlRC_t cmGrPlotCreate( cmCtx_t* ctx, cmGrPlH_t* hp )
  975. {
  976. cmGrPlRC_t rc;
  977. if((rc = cmGrPlotDestroy(hp)) != kOkGrPlRC )
  978. return rc;
  979. cmGrPl_t* p = cmMemAllocZ(cmGrPl_t,1);
  980. cmErrSetup(&p->err,&ctx->rpt,"cmGrPlot");
  981. p->ctx = ctx;
  982. hp->h = p;
  983. if( rc != kOkGrPlRC )
  984. _cmGrPlotDestroy(p);
  985. return rc;
  986. }
  987. cmGrPlRC_t cmGrPlotDestroy( cmGrPlH_t* hp )
  988. {
  989. cmGrPlRC_t rc;
  990. if( hp==NULL || cmGrPlotIsValid(*hp) == false )
  991. return kOkGrPlRC;
  992. cmGrPl_t* p = _cmGrPlHandleToPtr(*hp);
  993. if((rc = _cmGrPlotDestroy(p)) != kOkGrPlRC )
  994. return rc;
  995. hp->h = NULL;
  996. return rc;
  997. }
  998. bool cmGrPlotIsValid( cmGrPlH_t h )
  999. { return h.h != NULL; }
  1000. cmGrPlRC_t cmGrPlotClear( cmGrPlH_t h )
  1001. {
  1002. cmGrPl_t* p = _cmGrPlHandleToPtr(h);
  1003. return _cmGrPlotClear(p);
  1004. }
  1005. cmErr_t* cmGrPlotErr( cmGrPlH_t h )
  1006. {
  1007. cmGrPl_t* p = _cmGrPlHandleToPtr(h);
  1008. return &p->err;
  1009. }
  1010. cmRpt_t* cmGrPlotRpt( cmGrPlH_t h )
  1011. {
  1012. cmGrPl_t* p = _cmGrPlHandleToPtr(h);
  1013. return p->err.rpt;
  1014. }
  1015. cmGrPlObjH_t cmGrPlotObjectIdToHandle( cmGrPlH_t h, unsigned id )
  1016. {
  1017. cmGrPl_t* p = _cmGrPlHandleToPtr(h);
  1018. cmGrPlObjH_t oh = cmGrPlObjNullHandle;
  1019. cmGrPlotObj_t* op = p->list;
  1020. for(; op!=NULL; op=op->next)
  1021. if( cmGrObjId(op->grObjH) == id )
  1022. {
  1023. oh.h = op;
  1024. break;
  1025. }
  1026. return oh;
  1027. }
  1028. unsigned cmGrPlotObjectCount( cmGrPlH_t h )
  1029. {
  1030. cmGrPl_t* p = _cmGrPlHandleToPtr(h);
  1031. cmGrPlotObj_t* op = p->list;
  1032. unsigned n = 0;
  1033. for(; op!=NULL; ++n )
  1034. op=op->next;
  1035. return n;
  1036. }
  1037. cmGrPlObjH_t cmGrPlotObjectIndexToHandle( cmGrPlH_t h, unsigned index )
  1038. {
  1039. cmGrPl_t* p = _cmGrPlHandleToPtr(h);
  1040. cmGrPlotObj_t* op = p->list;
  1041. unsigned i = 0;
  1042. cmGrPlObjH_t oh = cmGrPlObjNullHandle;
  1043. for(; i<index && op!=NULL; ++i)
  1044. op = op->next;
  1045. if( op != NULL )
  1046. oh.h = op;
  1047. return oh;
  1048. }
  1049. void cmGrPlotKeyEvent( cmGrPlH_t h, cmGrH_t grH, unsigned eventFlags, cmGrKeyCodeId_t keycode )
  1050. {
  1051. assert( cmIsFlag(eventFlags,kKeyDnGrFl | kKeyUpGrFl));
  1052. cmGrPl_t* p = _cmGrPlHandleToPtr(h);
  1053. if( p->fop != NULL && cmHandlesAreEqual(p->fop->grH,grH) )
  1054. {
  1055. cmGrObjFuncArgs_t a;
  1056. memset(&a,0,sizeof(a));
  1057. a.cbArg = p->fop;
  1058. a.ctx = p->ctx;
  1059. a.grH = grH;
  1060. a.objH = p->fop->grObjH;
  1061. _cmGrPlotObjEvent(&a, eventFlags, keycode, 0, 0 );
  1062. }
  1063. }
  1064. void cmGrPlotSetCb( cmGrPlH_t h, cmGrPlotCbFunc_t func, void* arg )
  1065. {
  1066. cmGrPl_t* p = _cmGrPlHandleToPtr(h);
  1067. p->cbFunc = func;
  1068. p->cbArg = arg;
  1069. }