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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364
  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. return kOkGrPlRC;
  84. }
  85. void _cmGrPlotObjUnlink( cmGrPlotObj_t* op )
  86. {
  87. cmGrPl_t* p = op->p;
  88. if( op->next != NULL )
  89. op->next->prev = op->prev;
  90. if( op->prev != NULL )
  91. op->prev->next = op->next;
  92. if( p->list == op )
  93. p->list = op->next;
  94. }
  95. void _cmGrPlotObjLink( cmGrPl_t* p, cmGrPlotObj_t* op )
  96. {
  97. if( p->list != NULL )
  98. p->list->prev = op;
  99. op->next = p->list;
  100. op->prev = NULL;
  101. p->list = op;
  102. }
  103. // Destroy all objects
  104. cmGrPlRC_t _cmGrPlotClear( cmGrPl_t* p )
  105. {
  106. cmGrPlRC_t rc = kOkGrPlRC;
  107. cmGrPlotObj_t* op = p->list;
  108. while( op!=NULL )
  109. {
  110. cmGrPlotObj_t* t = op->next;
  111. if((rc = _cmGrPlotObjDelete(op)) != kOkGrPlRC )
  112. break;
  113. op = t;
  114. }
  115. return rc;
  116. }
  117. // Destroy the plot mgr
  118. cmGrPlRC_t _cmGrPlotDestroy( cmGrPl_t* p )
  119. {
  120. cmGrPlRC_t rc;
  121. if((rc = _cmGrPlotClear(p)) != kOkGrPlRC )
  122. return rc;
  123. cmMemFree(p);
  124. return kOkGrPlRC;
  125. }
  126. bool _cmGrPlotObjIsVisible( cmGrPlotObj_t* op )
  127. { return cmIsNotFlag(op->cfgFlags,kNoDrawGrPlFl); }
  128. bool _cmGrPlotObjIsEnabled( cmGrPlotObj_t* op )
  129. {
  130. // invisible objects are never enabled
  131. if( _cmGrPlotObjIsVisible(op) == false )
  132. return false;
  133. return cmIsFlag(op->stateFlags,kEnabledGrPlFl);
  134. }
  135. bool _cmGrPlotObjIsFocused(cmGrPlotObj_t* op)
  136. { return _cmGrPlotObjIsEnabled(op) && op->p->fop==op; }
  137. bool _cmGrPlotObjIsSelected(cmGrPlotObj_t* op)
  138. { return _cmGrPlotObjIsFocused(op) || cmIsFlag(op->stateFlags,kSelectGrPlFl); }
  139. void _cmGrPlotObjSetupCbArg( cmGrPlotCbArg_t* a, cmGrPlotObj_t* op, cmGrPlCbSelId_t selId )
  140. {
  141. cmGrPlObjH_t oH;
  142. oH.h = op;
  143. memset(a,0,sizeof(a));
  144. a->ctx = op->p->ctx;
  145. a->cbArg = op->cbArg;
  146. a->selId = selId;
  147. a->objH = oH;
  148. }
  149. bool _cmGrPlotObjCb( cmGrPlotObj_t* op, cmGrPlCbSelId_t selId, unsigned deltaFlags )
  150. {
  151. if( op->cbFunc != NULL )
  152. {
  153. cmGrPlotCbArg_t a;
  154. _cmGrPlotObjSetupCbArg(&a,op,selId);
  155. a.deltaFlags = deltaFlags;
  156. return op->cbFunc(&a);
  157. }
  158. return true;
  159. }
  160. void _cmGrPlotObjSetFocus( cmGrPlotObj_t* op )
  161. {
  162. // if 'op' is not enabled then it cannot receive the focus
  163. if( _cmGrPlotObjIsEnabled(op) == false )
  164. return;
  165. // if the focus cannot be set on 'op' - then try op->parent
  166. for(; op!=NULL; op=op->parent)
  167. if( cmIsNotFlag(op->cfgFlags,kNoFocusGrPlFl) && cmIsNotFlag(op->cfgFlags,kNoDrawGrPlFl) )
  168. break;
  169. // if the focus is changing to a new object
  170. if( op != NULL && op->p->fop != op )
  171. {
  172. if( op->p->fop != NULL )
  173. {
  174. // if the application callback returns false then do no release focus from the current object
  175. if(_cmGrPlotObjCb(op->p->fop, kPreEventCbSelGrPlId, kFocusGrPlFl ) == false )
  176. return;
  177. cmGrPlotObj_t* fop = op->p->fop;
  178. op->p->fop = NULL;
  179. // notify focus loser
  180. _cmGrPlotObjCb(fop, kStateChangeGrPlId, kFocusGrPlFl );
  181. }
  182. // if the application callback returns false then do not give focus to the selected object
  183. if(_cmGrPlotObjCb(op, kPreEventCbSelGrPlId, kFocusGrPlFl ) == false )
  184. return;
  185. op->p->fop = op;
  186. // notify focus winner
  187. _cmGrPlotObjCb(op, kStateChangeGrPlId, kFocusGrPlFl );
  188. }
  189. }
  190. void _cmGrPlotObjSetSelect( cmGrPlotObj_t* op, bool clearFl )
  191. {
  192. // if the object is disabled or not selectable
  193. if( _cmGrPlotObjIsEnabled(op)==false || cmIsFlag(op->cfgFlags,kNoSelectGrPlFl | kNoDrawGrPlFl) )
  194. return;
  195. unsigned stateFlags = op->stateFlags;
  196. // if the application callback returns false then do change the select state of the object
  197. if(_cmGrPlotObjCb(op, kPreEventCbSelGrPlId, kSelectGrPlFl ) == false )
  198. return;
  199. if( clearFl )
  200. {
  201. cmGrObjH_t parentObjH = cmGrObjParent(op->grObjH);
  202. cmGrPlotObj_t* cop = op->p->list;
  203. // clear the select flag on all objects that share op->parent
  204. for(; cop!=NULL; cop=cop->next)
  205. if( cmHandlesAreEqual(cmGrObjParent(cop->grObjH),parentObjH) )
  206. cop->stateFlags = cmClrFlag(cop->stateFlags,kSelectGrPlFl);
  207. }
  208. op->stateFlags = cmTogFlag(stateFlags,kSelectGrPlFl);
  209. // notify state change
  210. _cmGrPlotObjCb(op, kStateChangeGrPlId, kSelectGrPlFl );
  211. }
  212. const cmGrColor_t _cmGrPlotColor( cmGrPlotObj_t* op, cmGrColor_t* array )
  213. {
  214. if( _cmGrPlotObjIsFocused(op) )
  215. return array[kFocusPlGrId];
  216. if( _cmGrPlotObjIsSelected(op) )
  217. return array[kSelectPlGrId];
  218. if( _cmGrPlotObjIsEnabled(op) )
  219. return array[kEnablePlGrId];
  220. return array[kDisablePlGrId];
  221. }
  222. unsigned _cmGrPlotObjTriShapeToFlags( unsigned typeId)
  223. {
  224. switch(typeId)
  225. {
  226. case kUTriGrPlId: return kTopGrFl;
  227. case kDTriGrPlId: return kBottomGrFl;
  228. case kLTriGrPlId: return kLeftGrFl;
  229. case kRTriGrPlId: return kRightGrFl;
  230. default:
  231. { assert(0); }
  232. }
  233. return 0;
  234. }
  235. //------------------------------------------------------------------------------------------------------------------
  236. // Plot Object Callback Functions
  237. //------------------------------------------------------------------------------------------------------------------
  238. cmGrRC_t _cmGrPlotObjCreate( cmGrObjFuncArgs_t* args )
  239. {
  240. cmGrPlotObj_t* op = args->cbArg;
  241. _cmGrPlotObjCb(op,kCreatedCbSelGrPlId,0);
  242. // return kOkGrRC to indicate that the create was successful
  243. return kOkGrRC;
  244. }
  245. void _cmGrPlotObjDestroy( cmGrObjFuncArgs_t* args )
  246. {
  247. cmGrPlotObj_t* op = args->cbArg;
  248. // TODO: is it possible to prevent destruction by returning
  249. // 'false' from the used defined callback. This feature is
  250. // slightly complicated by the fact
  251. // that in some circumstances the destroy request is not
  252. // optional - for example when the program is closing.
  253. _cmGrPlotObjCb(op,kDestroyedCbSelGrPlId,0);
  254. _cmGrPlotObjUnlink( op );
  255. if( op->userByteCnt != 0 )
  256. {
  257. cmMemFree(op->userPtr);
  258. op->userByteCnt = 0;
  259. }
  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. }