guiParticleGraphCtrl.cpp 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "gfx/gfxInit.h"
  23. #include "gfx/primBuilder.h"
  24. #include "gfx/gfxDrawUtil.h"
  25. #include "console/console.h"
  26. #include "console/consoleTypes.h"
  27. #include "gui/core/guiCanvas.h"
  28. #include "gui/editor/guiParticleGraphCtrl.h"
  29. IMPLEMENT_CONOBJECT(GuiParticleGraphCtrl);
  30. ConsoleDocClass( GuiParticleGraphCtrl,
  31. "@brief Legacy remnant from old Torque particle editor\n\n"
  32. "Editor use only.\n\n"
  33. "@internal"
  34. );
  35. GuiParticleGraphCtrl::GuiParticleGraphCtrl()
  36. {
  37. for(int i = 0; i < MaxPlots; i++)
  38. {
  39. mPlots[i].mGraphColor = ColorF(1.0, 1.0, 1.0);
  40. VECTOR_SET_ASSOCIATION(mPlots[i].mGraphData);
  41. mPlots[i].mGraphMax.x = 1;
  42. mPlots[i].mGraphMax.y = 50;
  43. mPlots[i].mGraphMin.x = 0;
  44. mPlots[i].mGraphMin.y = 0;
  45. mPlots[i].mGraphType = Polyline;
  46. mPlots[i].mGraphName = StringTable->insert("");
  47. mPlots[i].mHidden = false;
  48. mPlots[i].mGraphScale = 0.05f;
  49. }
  50. mPlots[0].mGraphColor = ColorF(1.0f, 0.2f, 0.2f);
  51. mPlots[1].mGraphColor = ColorF(1.0f, 0.5f, 0.5f);
  52. mPlots[2].mGraphColor = ColorF(0.0f, 1.0f, 0.0f);
  53. mPlots[3].mGraphColor = ColorF(0.0f, 0.0f, 1.0f);
  54. mPlots[4].mGraphColor = ColorF(0.0f, 1.0f, 1.0f);
  55. mPlots[5].mGraphColor = ColorF(0.0f, 0.0f, 0.0f);
  56. mPlots[6].mGraphColor = ColorF(0.5f, 0.5f, 0.5f);
  57. mPlots[7].mGraphColor = ColorF(0.5f, 0.0f, 0.0f);
  58. mPlots[8].mGraphColor = ColorF(0.0f, 0.5f, 0.0f);
  59. mPlots[9].mGraphColor = ColorF(0.0f, 0.0f, 0.5f);
  60. mPlots[10].mGraphColor = ColorF(0.0f, 0.5f, 0.5f);
  61. mPlots[11].mGraphColor = ColorF(0.25f, 0.25f, 0.25f);
  62. mPlots[12].mGraphColor = ColorF(0.5f, 0.5f, 0.5f);
  63. mPlots[13].mGraphColor = ColorF(0.5f, 0.0f, 0.0f);
  64. mPlots[14].mGraphColor = ColorF(0.0f, 0.5f, 0.0f);
  65. mPlots[15].mGraphColor = ColorF(0.0f, 0.0f, 0.5f);
  66. mPlots[16].mGraphColor = ColorF(0.0f, 0.5f, 0.5f);
  67. mPlots[17].mGraphColor = ColorF(0.25f, 0.25f, 0.25f);
  68. mPlots[18].mGraphColor = ColorF(1.0f, 0.2f, 0.2f);
  69. mPlots[19].mGraphColor = ColorF(1.0f, 0.5f, 0.5f);
  70. mPlots[20].mGraphColor = ColorF(0.0f, 1.0f, 0.0f);
  71. mPlots[21].mGraphColor = ColorF(0.0f, 0.0f, 1.0f);
  72. mPlots[22].mGraphColor = ColorF(0.0f, 1.0f, 1.0f);
  73. mPlots[23].mGraphColor = ColorF(0.0f, 0.0f, 0.0f);
  74. mPlots[24].mGraphColor = ColorF(0.5f, 0.5f, 0.5f);
  75. mPlots[25].mGraphColor = ColorF(0.5f, 0.0f, 0.0f);
  76. mPlots[26].mGraphColor = ColorF(0.0f, 0.5f, 0.0f);
  77. mPlots[27].mGraphColor = ColorF(0.0f, 0.0f, 0.5f);
  78. mPlots[28].mGraphColor = ColorF(1.0f, 0.0f, 0.0f);
  79. mPlots[29].mGraphColor = ColorF(0.0f, 1.0f, 0.0f);
  80. mPlots[30].mGraphColor = ColorF(0.0f, 0.0f, 1.0f);
  81. mPlots[31].mGraphColor = ColorF(0.5f, 0.0f, 0.0f);
  82. mVertexClickSize = 6;
  83. mSelectedPlot = 0;
  84. mSelectedPoint = -1;
  85. mOriginalSelectedPoint = -1;
  86. mLastSelectedPoint = -1;
  87. mAddedPointIndex = -1;
  88. mAutoMax = false;
  89. mAutoRemove = false;
  90. mRenderAllPoints = false;
  91. mRenderGraphTooltip = true;
  92. mPointWasAdded = false;
  93. mPointXMovementClamped = false;
  94. mOutlineColor = ColorI(1, 1, 1);
  95. mCursorPos = Point2I(0, 0);
  96. }
  97. ImplementEnumType( GuiParticleGraphType,
  98. "\n\n"
  99. "@ingroup GuiCore"
  100. "@internal")
  101. { GuiParticleGraphCtrl::Bar, "bar" },
  102. { GuiParticleGraphCtrl::Filled, "filled" },
  103. { GuiParticleGraphCtrl::Point, "point" },
  104. { GuiParticleGraphCtrl::Polyline , "polyline" },
  105. EndImplementEnumType;
  106. bool GuiParticleGraphCtrl::onWake()
  107. {
  108. if (! Parent::onWake())
  109. return false;
  110. setActive(true);
  111. return true;
  112. }
  113. void GuiParticleGraphCtrl::onRender(Point2I offset, const RectI &updateRect)
  114. {
  115. // Fetch Draw Utility.
  116. GFXDrawUtil* pDrawUtil = GFX->getDrawUtil();
  117. if (mProfile->mBorder)
  118. {
  119. const RectI bounds = getBounds();
  120. RectI rect(offset.x, offset.y, bounds.extent.x, bounds.extent.y);
  121. pDrawUtil->drawRect(rect, mProfile->mBorderColor);
  122. }
  123. GuiControlProfile* profile = dynamic_cast<GuiControlProfile*>(Sim::findObject("GuiDefaultProfile"));
  124. Resource<GFont> font = profile->mFont;
  125. GFXVideoMode videoMode = GFXInit::getDesktopResolution();
  126. ColorF color(1.0f, 1.0f, 1.0f, 0.5f);
  127. pDrawUtil->drawRectFill(updateRect, color);
  128. for (int k = 0; k < MaxPlots; k++)
  129. {
  130. // Nothing to graph
  131. if ((mPlots[k].mGraphData.size() == 0) || (mPlots[k].mHidden == true))
  132. continue;
  133. Point2F graphExtent = getGraphExtent(k);
  134. // Adjust scale to max value + 5% so we can see high value
  135. F32 ScaleX = (F32(getExtent().x) / (graphExtent.x*(1.00 + (mPlots[k].mGraphScale))));
  136. F32 ScaleY = (F32(getExtent().y) / (graphExtent.y*(1.00 + (mPlots[k].mGraphScale))));
  137. if((mPlots[k].mGraphType == Point) || (mPlots[k].mGraphType == Polyline))
  138. {
  139. S32 posX;
  140. S32 posY;
  141. S32 lastPosX = 0;
  142. S32 lastPosY = 0;
  143. Point2F plotPoint;
  144. S32 size = 32;
  145. for (S32 sample = 0; sample < mPlots[k].mGraphData.size(); sample++)
  146. {
  147. S32 temp;
  148. temp = (S32)(((F32)getExtent().x / (F32)mPlots[k].mGraphData.size()) * (F32)sample);
  149. // calculate the point positions
  150. plotPoint = getPlotPoint(k, sample);
  151. posX = (S32)((plotPoint.x - mPlots[k].mGraphMin.x) * (ScaleX /(1.00 + mPlots[k].mGraphScale)));
  152. posY = (getExtent().y) - (S32)((plotPoint.y - mPlots[k].mGraphMin.y) * ScaleY);
  153. posX += getExtent().x * (mPlots[k].mGraphScale);
  154. posY /= (1.00 + (mPlots[k].mGraphScale));
  155. posX = localToGlobalCoord(Point2I(posX, posY)).x;
  156. posY = localToGlobalCoord(Point2I(posX, posY)).y;
  157. // check if this isn't our first loop through, if it is we won't have starting points
  158. if(sample > 0)
  159. {
  160. pDrawUtil->drawLine( lastPosX, lastPosY , posX, posY , mPlots[k].mGraphColor );
  161. } else
  162. {
  163. mPlots[k].mNutList.clear();
  164. }
  165. mPlots[k].mNutList.push_back( Point2F(posX, posY) );
  166. // store the last positions to be the starting points drawn into a line next loop
  167. lastPosX = posX;
  168. lastPosY = posY;
  169. //Con::printf("red %f green %f blue %f", mPlots[k].mGraphColor.red, mPlots[k].mGraphColor.green, mPlots[k].mGraphColor.blue);
  170. if(mSelectedPoint != -1)
  171. {
  172. mLastSelectedPoint = mSelectedPoint;
  173. }
  174. ColorI nutColor (mPlots[k].mGraphColor);
  175. if(k == mSelectedPlot && sample == mLastSelectedPoint)
  176. {
  177. // grab the colors for the nut
  178. F32 red = mPlots[k].mGraphColor.red;
  179. F32 green = mPlots[k].mGraphColor.green;
  180. F32 blue = mPlots[k].mGraphColor.blue;
  181. // invert the colors for the nut since this is a selected nut
  182. red = 1.0 - red;
  183. green = 1.0 - green;
  184. blue = 1.0 - blue;
  185. // nut color
  186. nutColor = ColorI(ColorF(red, green, blue));
  187. }
  188. // draw the seleciton nut
  189. drawNut( Point2I(posX, posY), 3, mOutlineColor, nutColor );
  190. if((mLastSelectedPoint != -1) || (mRenderAllPoints == true))
  191. {
  192. if((k == mSelectedPlot && sample == mLastSelectedPoint) || (mRenderAllPoints == true))
  193. {
  194. char number[32];
  195. Point2I comparePos = localToGlobalCoord(Point2I(getPosition().x, getPosition().y));
  196. dSprintf(number, 32, "%4.3f %4.3f", plotPoint.x, plotPoint.y);
  197. S32 textWidth = (S32)font->getStrWidth((const UTF8*)number);;
  198. textWidth /= 2;
  199. if((((S32)posX - (textWidth/2)) < comparePos.x) || (((S32)posX - textWidth) <= 0))
  200. {
  201. posX += (textWidth/1.5);
  202. } else if((posX + (textWidth * 1.8)) > (comparePos.x + getExtent().x) || ((posX + textWidth) >= videoMode.resolution.x))
  203. {
  204. posX -= (textWidth * 1.5);
  205. }
  206. if((((S32)posY) < comparePos.y) || (((S32)posY - textWidth) <= 0))
  207. {
  208. posY += 40;
  209. }
  210. pDrawUtil->setBitmapModulation( profile->mFontColor );
  211. pDrawUtil->drawText( font, Point2I(posX, posY + 5) - Point2I(size >> 1, size), number );
  212. pDrawUtil->clearBitmapModulation();
  213. }
  214. }
  215. }
  216. }
  217. }
  218. if(mRenderNextGraphTooltip == true && mRenderGraphTooltip == true)
  219. {
  220. char argBuffer[1][32];
  221. dSprintf(argBuffer[0], 32, "%s", getGraphName(mTooltipSelectedPlot));
  222. renderGraphTooltip(mCursorPos, argBuffer[0]);
  223. }
  224. }
  225. S32 GuiParticleGraphCtrl::addPlotPoint(S32 plotID, Point2F v, bool setAdded)
  226. {
  227. S32 mPlotIndex = 0;
  228. bool plotChanged = false;
  229. bool plotAdded = false;
  230. if(mAutoMax == false)
  231. {
  232. if(v.x < mPlots[plotID].mGraphMin.x)
  233. {
  234. v.x = mPlots[plotID].mGraphMin.x;
  235. }
  236. if(v.x > mPlots[plotID].mGraphMax.x)
  237. {
  238. v.x = mPlots[plotID].mGraphMax.x;
  239. }
  240. if(v.y < mPlots[plotID].mGraphMin.y)
  241. {
  242. v.y = mPlots[plotID].mGraphMin.y;
  243. }
  244. if(v.y > mPlots[plotID].mGraphMax.y)
  245. {
  246. v.y = mPlots[plotID].mGraphMax.y;
  247. }
  248. }
  249. for(S32 i = 0; i < mPlots[plotID].mGraphData.size(); i++)
  250. {
  251. if(mFabs(v.x - mPlots[plotID].mGraphData[i].x) < 0.001)
  252. {
  253. if(mAutoRemove == true)
  254. {
  255. changePlotPoint(plotID, i, v);
  256. plotChanged = true;
  257. mPlotIndex = i;
  258. } else
  259. {
  260. mPlotIndex = -1;
  261. }
  262. plotAdded = true;
  263. break;
  264. } else if(v.x < mPlots[plotID].mGraphData[i].x)
  265. {
  266. insertPlotPoint(plotID, i, v);
  267. plotAdded = true;
  268. mPlotIndex = i;
  269. break;
  270. }
  271. }
  272. if(plotAdded == false)
  273. {
  274. mPlots[plotID].mGraphData.push_back( v );
  275. mPlotIndex = mPlots[plotID].mGraphData.size() - 1;
  276. }
  277. if(mAutoMax == true)
  278. {
  279. // Keep record of maximum data value for scaling purposes.
  280. if(v.y > mPlots[plotID].mGraphMax.y)
  281. mPlots[plotID].mGraphMax.y = v.y;
  282. if(v.x > mPlots[plotID].mGraphMax.x)
  283. mPlots[plotID].mGraphMax.x = v.x;
  284. }
  285. if(plotChanged == true)
  286. {
  287. mPointWasAdded = false;
  288. } else if(mPlotIndex != -1 && setAdded)
  289. {
  290. mPointWasAdded = true;
  291. mAddedPoint = v;
  292. mAddedPointIndex = mPlotIndex;
  293. }
  294. return mPlotIndex;
  295. }
  296. void GuiParticleGraphCtrl::insertPlotPoint(S32 plotID, S32 i, Point2F v)
  297. {
  298. //AssertFatal(plotID > -1 && plotID < MaxPlots, "Invalid plot specified!");
  299. // Add the data and trim the vector...
  300. mPlots[plotID].mGraphData.insert( i );
  301. mPlots[plotID].mGraphData[ i ] = v;
  302. if(mAutoMax == true)
  303. {
  304. // Keep record of maximum data value for scaling purposes.
  305. if(v.y > mPlots[plotID].mGraphMax.y)
  306. mPlots[plotID].mGraphMax.y = v.y;
  307. if(v.x > mPlots[plotID].mGraphMax.x)
  308. mPlots[plotID].mGraphMax.x = v.x;
  309. }
  310. // Argument Buffer.
  311. char argBuffer[2][32];
  312. dSprintf(argBuffer[0], 32, "%d", plotID);
  313. dSprintf(argBuffer[1], 32, "%f %f", v.x, v.y);
  314. // Call Scripts.
  315. Con::executef(this, "onPlotPointInserted", argBuffer[0], argBuffer[1]);
  316. }
  317. S32 GuiParticleGraphCtrl::changePlotPoint(S32 plotID, S32 i, Point2F v)
  318. {
  319. //AssertFatal(plotID > -1 && plotID < MaxPlots, "Invalid plot specified!");
  320. // Add the data and trim the vector...
  321. S32 point = removePlotPoint(plotID, i);
  322. // Argument Buffer.
  323. char argBuffer[3][32];
  324. dSprintf(argBuffer[0], 32, "%d", mSelectedPlot);
  325. dSprintf(argBuffer[1], 32, "%d", point);
  326. dSprintf(argBuffer[2], 32, "%f %f", v.x, v.y);
  327. // Call Scripts.
  328. Con::executef(this, "onPlotPointRemoved", argBuffer[0], argBuffer[1], argBuffer[2]);
  329. // call the insert function
  330. S32 index = addPlotPoint(plotID, v);
  331. return index;
  332. }
  333. S32 GuiParticleGraphCtrl::removePlotPoint(S32 plotID, S32 i)
  334. {
  335. if((plotID < MaxPlots && plotID >= 0) && (i < mPlots[plotID].mGraphData.size()))
  336. {
  337. Point2F v = mPlots[plotID].mGraphData[i];
  338. mPlots[plotID].mGraphData.erase(i);
  339. if(i == mPlots[plotID].mGraphData.size() && mSelectedPlot == plotID && mLastSelectedPoint == i)
  340. {
  341. setSelectedPoint(i-1);
  342. } else if(i < mLastSelectedPoint)
  343. {
  344. setSelectedPoint(mLastSelectedPoint-1);
  345. }
  346. }
  347. return i;
  348. }
  349. S32 GuiParticleGraphCtrl::getSelectedPlot()
  350. {
  351. return mSelectedPlot;
  352. }
  353. S32 GuiParticleGraphCtrl::getSelectedPoint()
  354. {
  355. return mLastSelectedPoint;
  356. }
  357. bool GuiParticleGraphCtrl::isExistingPoint(S32 plotID, S32 sample)
  358. {
  359. if (((plotID < 0) || (plotID > MaxPlots)) || ((sample < 0) || (sample > MaxDataPoints)) || (sample >= mPlots[plotID].mGraphData.size()))
  360. {
  361. return false;
  362. } else
  363. {
  364. return true;
  365. }
  366. }
  367. Point2F GuiParticleGraphCtrl::getPlotPoint(S32 plotID, S32 sample)
  368. {
  369. Point2F val;
  370. val.x = -1;
  371. val.y = -1;
  372. if (((plotID < 0) || (plotID > MaxPlots)) || ((sample < 0) || (sample > MaxDataPoints)))
  373. {
  374. return val;
  375. }
  376. return mPlots[plotID].mGraphData[sample];
  377. }
  378. S32 GuiParticleGraphCtrl::getPlotIndex(S32 plotID, F32 x, F32 y)
  379. {
  380. if ((plotID < 0) || (plotID > MaxPlots))
  381. {
  382. return -1;
  383. }
  384. F32 compareX = 0.0;
  385. F32 compareY = 0.0;
  386. for(S32 i = 0; i < mPlots[plotID].mGraphData.size(); i++)
  387. {
  388. compareX = mPlots[plotID].mGraphData[i].x;
  389. compareY = mPlots[plotID].mGraphData[i].y;
  390. //
  391. //if((x == compareX) && (y == compareY))
  392. if((mFabs(x - compareX) < 0.001) && (mFabs(y - compareY) < 0.001))
  393. return i;
  394. }
  395. return -1;
  396. }
  397. void GuiParticleGraphCtrl::setGraphType(S32 plotID, const char *graphType)
  398. {
  399. AssertFatal(plotID > -1 && plotID < MaxPlots, "Invalid plot specified!");
  400. if(!dStricmp(graphType,"Bar"))
  401. mPlots[plotID].mGraphType = Bar;
  402. else if(!dStricmp(graphType,"Filled"))
  403. mPlots[plotID].mGraphType = Filled;
  404. else if(!dStricmp(graphType,"Point"))
  405. mPlots[plotID].mGraphType = Point;
  406. else if(!dStricmp(graphType,"Polyline"))
  407. mPlots[plotID].mGraphType = Polyline;
  408. else AssertWarn(true, "Invalid graph type!");
  409. }
  410. void GuiParticleGraphCtrl::setSelectedPlot(S32 plotID)
  411. {
  412. mSelectedPlot = plotID;
  413. // Argument Buffer.
  414. char argBuffer[32];
  415. dSprintf(argBuffer, 32, "%d", plotID);
  416. // Call Scripts.
  417. Con::executef(this, "onSetSelected", argBuffer);
  418. }
  419. void GuiParticleGraphCtrl::setSelectedPoint(S32 point)
  420. {
  421. if(point != mSelectedPoint && point < mPlots[mSelectedPlot].mGraphData.size() && point >= 0)
  422. {
  423. mSelectedPoint = point;
  424. mLastSelectedPoint = point;
  425. char argBuffer[32];
  426. dSprintf(argBuffer, 32, "%d", point);
  427. // Call Scripts.
  428. Con::executef(this, "onPlotPointSelected", argBuffer);
  429. }
  430. }
  431. void GuiParticleGraphCtrl::resetSelectedPoint()
  432. {
  433. mSelectedPoint = -1;
  434. }
  435. void GuiParticleGraphCtrl::setAutoGraphMax(bool autoMax)
  436. {
  437. mAutoMax = autoMax;
  438. }
  439. void GuiParticleGraphCtrl::setAutoRemove(bool autoRemove)
  440. {
  441. mAutoRemove = autoRemove;
  442. }
  443. void GuiParticleGraphCtrl::setGraphHidden(S32 plotID, bool isHidden)
  444. {
  445. mPlots[plotID].mHidden = isHidden;
  446. }
  447. void GuiParticleGraphCtrl::setRenderAll(bool renderAll)
  448. {
  449. mRenderAllPoints = renderAll;
  450. }
  451. void GuiParticleGraphCtrl::setPointXMovementClamped(bool clamped)
  452. {
  453. mPointXMovementClamped = clamped;
  454. }
  455. void GuiParticleGraphCtrl::setRenderGraphTooltip(bool renderGraphTooltip)
  456. {
  457. mRenderGraphTooltip = renderGraphTooltip;
  458. }
  459. void GuiParticleGraphCtrl::drawNut(const Point2I &nut, S32 size, ColorI &outlineColor, ColorI &nutColor)
  460. {
  461. // Fetch Draw Utility.
  462. GFXDrawUtil* pDrawUtil = GFX->getDrawUtil();
  463. //Con::printf("r %d g %d b %d", nutColor.red, nutColor.green, nutColor.blue);
  464. S32 NUT_SIZE = size;
  465. RectI r(nut.x - NUT_SIZE, nut.y - NUT_SIZE, 2 * NUT_SIZE + 1, 2 * NUT_SIZE + 1);
  466. r.inset(1, 1);
  467. pDrawUtil->drawRectFill(r, nutColor);
  468. r.inset(-1, -1);
  469. pDrawUtil->drawRect(r, outlineColor);
  470. }
  471. bool GuiParticleGraphCtrl::inNut(const Point2I &pt, S32 x, S32 y)
  472. {
  473. S32 dx = pt.x - x;
  474. S32 dy = pt.y - y;
  475. return dx <= mVertexClickSize && dx >= -mVertexClickSize && dy <= mVertexClickSize && dy >= -mVertexClickSize;
  476. }
  477. Point2I GuiParticleGraphCtrl::findHitNut( Point2I hitPoint )
  478. {
  479. for(S32 i = 0; i < MaxPlots; i++)
  480. {
  481. if ( (mPlots[i].mGraphData.size() == 0) || (mPlots[i].mHidden == true))
  482. continue;
  483. for (S32 j = 0 ; j < mPlots[i].mNutList.size(); j++ )
  484. {
  485. if( inNut (Point2I( mPlots[i].mNutList[j].x, mPlots[i].mNutList[j].y), hitPoint.x, hitPoint.y) )
  486. {
  487. mTooltipSelectedPlot = i;
  488. return Point2I(i,j);
  489. }
  490. }
  491. }
  492. return Point2I(-1,-1);
  493. }
  494. Point2F GuiParticleGraphCtrl::convertToGraphCoord(S32 plotID, Point2I v)
  495. {
  496. Point2F resultV;
  497. v = globalToLocalCoord( v );
  498. v.y = getExtent().y - v.y;
  499. resultV = Point2F(v.x, v.y);
  500. resultV.x /= getExtent().x;
  501. resultV.y /= getExtent().y;
  502. resultV.x *= getGraphExtent(plotID).x;
  503. resultV.y *= getGraphExtent(plotID).y;
  504. resultV.x *= 1.00 + (mPlots[plotID].mGraphScale*2);
  505. resultV.y *= 1.00 + (mPlots[plotID].mGraphScale*2);
  506. resultV.x -= getGraphExtent(plotID).x * ((mPlots[plotID].mGraphScale));
  507. resultV.y -= getGraphExtent(plotID).y * ((mPlots[plotID].mGraphScale));
  508. resultV.x += mPlots[plotID].mGraphMin.x;
  509. resultV.y += mPlots[plotID].mGraphMin.y;
  510. if(mAutoMax == false)
  511. {
  512. if(resultV.x < mPlots[plotID].mGraphMin.x)
  513. {
  514. resultV.x = mPlots[plotID].mGraphMin.x;
  515. }
  516. if(resultV.x > mPlots[plotID].mGraphMax.x)
  517. {
  518. resultV.x = mPlots[plotID].mGraphMax.x;
  519. }
  520. if(resultV.y < mPlots[plotID].mGraphMin.y)
  521. {
  522. resultV.y = mPlots[plotID].mGraphMin.y;
  523. }
  524. if(resultV.y > mPlots[plotID].mGraphMax.y)
  525. {
  526. resultV.y = mPlots[plotID].mGraphMax.y;
  527. }
  528. }
  529. return resultV;
  530. }
  531. Point2F GuiParticleGraphCtrl::getGraphExtent(S32 plotID)
  532. {
  533. Point2F resultV;
  534. resultV.x = mPlots[plotID].mGraphMax.x - mPlots[plotID].mGraphMin.x;
  535. resultV.y = mPlots[plotID].mGraphMax.y - mPlots[plotID].mGraphMin.y;
  536. return resultV;
  537. }
  538. ColorF GuiParticleGraphCtrl::getGraphColor(S32 plotID)
  539. {
  540. return mPlots[plotID].mGraphColor;
  541. }
  542. Point2F GuiParticleGraphCtrl::getGraphMax(S32 plotID)
  543. {
  544. return mPlots[plotID].mGraphMax;
  545. }
  546. Point2F GuiParticleGraphCtrl::getGraphMin(S32 plotID)
  547. {
  548. return mPlots[plotID].mGraphMin;
  549. }
  550. void GuiParticleGraphCtrl::setGraphMin(S32 plotID, Point2F graphMin)
  551. {
  552. mPlots[plotID].mGraphMin = graphMin;
  553. }
  554. void GuiParticleGraphCtrl::setGraphMax(S32 plotID, Point2F graphMax)
  555. {
  556. mPlots[plotID].mGraphMax = graphMax;
  557. }
  558. void GuiParticleGraphCtrl::setGraphMinX(S32 plotID, F32 graphMinX)
  559. {
  560. mPlots[plotID].mGraphMin.x = graphMinX;
  561. }
  562. void GuiParticleGraphCtrl::setGraphMinY(S32 plotID, F32 graphMinY)
  563. {
  564. mPlots[plotID].mGraphMin.y = graphMinY;
  565. }
  566. void GuiParticleGraphCtrl::setGraphMaxX(S32 plotID, F32 graphMaxX)
  567. {
  568. mPlots[plotID].mGraphMax.x = graphMaxX;
  569. }
  570. void GuiParticleGraphCtrl::setGraphMaxY(S32 plotID, F32 graphMaxY)
  571. {
  572. mPlots[plotID].mGraphMax.y = graphMaxY;
  573. }
  574. void GuiParticleGraphCtrl::setGraphName(S32 plotID, StringTableEntry graphName)
  575. {
  576. mPlots[plotID].mGraphName = StringTable->insert(graphName);
  577. }
  578. StringTableEntry GuiParticleGraphCtrl::getGraphName(S32 plotID)
  579. {
  580. return mPlots[plotID].mGraphName;
  581. }
  582. void GuiParticleGraphCtrl::onMouseMove(const GuiEvent &event)
  583. {
  584. mCursorPos = event.mousePoint;
  585. Point2I hitNut = findHitNut(event.mousePoint);
  586. if( hitNut != Point2I(-1,-1) )
  587. {
  588. mRenderNextGraphTooltip = true;
  589. } else
  590. {
  591. mRenderNextGraphTooltip = false;
  592. }
  593. // Argument Buffer.
  594. char argBuffer[32];
  595. dSprintf(argBuffer, 32, "%f %f", convertToGraphCoord(mSelectedPlot, event.mousePoint).x, convertToGraphCoord(mSelectedPlot, event.mousePoint).y);
  596. // Call Scripts.
  597. Con::executef(this, "onMouseMove", argBuffer);
  598. }
  599. void GuiParticleGraphCtrl::onMouseDown(const GuiEvent &event)
  600. {
  601. Point2I hitNut = findHitNut(event.mousePoint);
  602. if( hitNut != Point2I(-1,-1) )
  603. {
  604. if(event.mouseClickCount == 2)
  605. {
  606. Point2F plotPoint = getPlotPoint(hitNut.x, hitNut.y);
  607. Point2F mousePos = convertToGraphCoord(mSelectedPlot, event.mousePoint);
  608. S32 point = removePlotPoint(hitNut.x, hitNut.y);
  609. // Argument Buffer.
  610. char argBuffer[3][32];
  611. dSprintf(argBuffer[0], 32, "%d", mSelectedPlot);
  612. dSprintf(argBuffer[1], 32, "%d", point);
  613. dSprintf(argBuffer[2], 32, "%f %f", plotPoint.x, plotPoint.y);
  614. // Call Scripts.
  615. Con::executef(this, "onPlotPointRemoved", argBuffer[0], argBuffer[1], argBuffer[2]);
  616. } else
  617. {
  618. setSelectedPlot(hitNut.x);
  619. setSelectedPoint(hitNut.y);
  620. mOriginalSelectedPoint = hitNut.y;
  621. char argBuffer[32];
  622. dSprintf(argBuffer, 32, "%d", hitNut.y);
  623. // Call Scripts.
  624. Con::executef(this, "onPlotPointSelectedMouseDown", argBuffer);
  625. }
  626. } else if( mSelectedPlot != -1 )
  627. {
  628. Point2F mousePos = convertToGraphCoord(mSelectedPlot, event.mousePoint);
  629. mLastSelectedPoint = addPlotPoint(mSelectedPlot, mousePos);
  630. // Argument Buffer.
  631. char argBuffer[32];
  632. dSprintf(argBuffer, 32, "%f %f", convertToGraphCoord(mSelectedPlot, event.mousePoint).x, convertToGraphCoord(mSelectedPlot, event.mousePoint).y);
  633. // Call Scripts.
  634. Con::executef(this, "onMouseDragged", argBuffer);
  635. return;
  636. }
  637. }
  638. void GuiParticleGraphCtrl::onMouseUp(const GuiEvent &event)
  639. {
  640. if(mSelectedPoint != -1)
  641. mLastSelectedPoint = mSelectedPoint;
  642. if(mPointWasAdded == true)
  643. {
  644. if(mSelectedPoint == -1)
  645. {
  646. // Argument Buffer.
  647. char argBuffer[3][32];
  648. dSprintf(argBuffer[0], 32, "%d", mSelectedPlot);
  649. dSprintf(argBuffer[1], 32, "%f %f", mAddedPoint.x, mAddedPoint.y);
  650. dSprintf(argBuffer[2], 32, "%d", mAddedPointIndex);
  651. // Call Scripts.
  652. Con::executef(this, "onPlotPointAdded", argBuffer[0], argBuffer[1], argBuffer[2]);
  653. } else
  654. {
  655. // Argument Buffer.
  656. char argBuffer[4][32];
  657. dSprintf(argBuffer[0], 32, "%d", mSelectedPlot);
  658. dSprintf(argBuffer[1], 32, "%f %f", mAddedPoint.x, mAddedPoint.y);
  659. dSprintf(argBuffer[2], 32, "%d", mOriginalSelectedPoint);
  660. dSprintf(argBuffer[3], 32, "%d", mAddedPointIndex);
  661. // Call Scripts.
  662. Con::executef(this, "onPlotPointChangedUp", argBuffer[0], argBuffer[1], argBuffer[2], argBuffer[3]);
  663. }
  664. }
  665. mPointWasAdded = false;
  666. mSelectedPoint = -1;
  667. }
  668. void GuiParticleGraphCtrl::onMouseDragged(const GuiEvent &event)
  669. {
  670. mRenderNextGraphTooltip = false;
  671. if(mSelectedPoint != -1)
  672. {
  673. Point2F mousePos = convertToGraphCoord(mSelectedPlot, event.mousePoint);
  674. if(mPointXMovementClamped == true)
  675. {
  676. F32 prevXPos = getPlotPoint(mSelectedPlot, mSelectedPoint).x;
  677. if(mousePos.x != prevXPos)
  678. {
  679. mousePos.x = prevXPos;
  680. }
  681. }
  682. removePlotPoint(mSelectedPlot, mSelectedPoint);
  683. S32 point = addPlotPoint(mSelectedPlot, mousePos);
  684. if(point != -1)
  685. {
  686. setSelectedPoint(point);
  687. mLastMousePos = mousePos;
  688. // Argument Buffer.
  689. char argBuffer[3][32];
  690. dSprintf(argBuffer[0], 32, "%d", mSelectedPlot);
  691. dSprintf(argBuffer[1], 32, "%f %f", mAddedPoint.x, mAddedPoint.y);
  692. dSprintf(argBuffer[2], 32, "%d", point);
  693. // Call Scripts.
  694. Con::executef(this, "onPlotPointChangedMove", argBuffer[0], argBuffer[1], argBuffer[2]);
  695. } else
  696. {
  697. point = addPlotPoint(mSelectedPlot, mLastMousePos);
  698. }
  699. }
  700. // Argument Buffer.
  701. char argBuffer[32];
  702. dSprintf(argBuffer, 32, "%f %f", convertToGraphCoord(mSelectedPlot, event.mousePoint).x, convertToGraphCoord(mSelectedPlot, event.mousePoint).y);
  703. // Call Scripts.
  704. Con::executef(this, "onMouseDragged", argBuffer);
  705. }
  706. void GuiParticleGraphCtrl::onRightMouseDown(const GuiEvent &event)
  707. {
  708. Point2I hitNut = findHitNut(event.mousePoint);
  709. if( hitNut != Point2I(-1,-1) )
  710. {
  711. Point2F plotPoint = getPlotPoint(hitNut.x, hitNut.y);
  712. Point2F mousePos = convertToGraphCoord(mSelectedPlot, event.mousePoint);
  713. S32 point = removePlotPoint(hitNut.x, hitNut.y);
  714. // Argument Buffer.
  715. char argBuffer[3][32];
  716. dSprintf(argBuffer[0], 32, "%d", mSelectedPlot);
  717. dSprintf(argBuffer[1], 32, "%d", point);
  718. dSprintf(argBuffer[2], 32, "%f %f", plotPoint.x, plotPoint.y);
  719. // Call Scripts.
  720. Con::executef(this, "onPlotPointRemoved", argBuffer[0], argBuffer[1], argBuffer[2]);
  721. }
  722. }
  723. void GuiParticleGraphCtrl::onRightMouseUp(const GuiEvent &event)
  724. {
  725. }
  726. void GuiParticleGraphCtrl::onRightMouseDragged(const GuiEvent &event)
  727. {
  728. Point2I hitNut = findHitNut(event.mousePoint);
  729. if( hitNut != Point2I(-1,-1) )
  730. {
  731. Point2F plotPoint = getPlotPoint(hitNut.x, hitNut.y);
  732. Point2F mousePos = convertToGraphCoord(mSelectedPlot, event.mousePoint);
  733. S32 point = removePlotPoint(hitNut.x, hitNut.y);
  734. // Argument Buffer.
  735. char argBuffer[3][32];
  736. dSprintf(argBuffer[0], 32, "%d", mSelectedPlot);
  737. dSprintf(argBuffer[1], 32, "%d", point);
  738. dSprintf(argBuffer[2], 32, "%f %f", plotPoint.x, plotPoint.y);
  739. // Call Scripts.
  740. Con::executef(this, "onPlotPointRemoved", argBuffer[0], argBuffer[1], argBuffer[2]);
  741. }
  742. }
  743. void GuiParticleGraphCtrl::clearAllGraphs()
  744. {
  745. for(S32 i = 0;i < MaxPlots;i++)
  746. {
  747. clearGraph(i);
  748. }
  749. }
  750. void GuiParticleGraphCtrl::clearGraph(S32 plotID)
  751. {
  752. mPlots[plotID].mGraphData.clear();
  753. mPlots[plotID].mNutList.clear();
  754. }
  755. bool GuiParticleGraphCtrl::renderGraphTooltip(Point2I cursorPos, StringTableEntry tooltip)
  756. {
  757. // Short Circuit.
  758. if (!mAwake)
  759. return false;
  760. if ( dStrlen( tooltip ) == 0 )
  761. return false;
  762. // Need to have root.
  763. GuiCanvas *root = getRoot();
  764. if ( !root )
  765. return false;
  766. if (!mTooltipProfile)
  767. setTooltipProfile( mProfile );
  768. GFont *font = mTooltipProfile->mFont;
  769. // Fetch Canvas.
  770. GuiCanvas *pCanvas = getRoot();
  771. //Vars used:
  772. //Screensize (for position check)
  773. //Offset to get position of cursor
  774. //textBounds for text extent.
  775. Point2I screensize = pCanvas->getWindowSize();
  776. Point2I offset = cursorPos;
  777. Point2I textBounds;
  778. S32 textWidth = font->getStrWidth(tooltip);
  779. //Offset below cursor image
  780. offset.y -= root->getCursorExtent().y;
  781. //Create text bounds.
  782. textBounds.x = textWidth+8;
  783. textBounds.y = font->getHeight() + 4;
  784. // Check position/width to make sure all of the tooltip will be rendered
  785. // 5 is given as a buffer against the edge
  786. if (screensize.x < offset.x + textBounds.x + 5)
  787. offset.x = screensize.x - textBounds.x - 5;
  788. // And ditto for the height
  789. if(screensize.y < offset.y + textBounds.y + 5)
  790. offset.y = cursorPos.y - textBounds.y - 5;
  791. // Set rectangle for the box, and set the clip rectangle.
  792. RectI rect(offset, textBounds);
  793. GFX->setClipRect(rect);
  794. // Fetch Draw Utility.
  795. GFXDrawUtil* pDrawUtil = GFX->getDrawUtil();
  796. // Draw Filler bit, then border on top of that
  797. pDrawUtil->drawRectFill(rect, ColorI(mTooltipProfile->mFillColor.red, mTooltipProfile->mFillColor.green, mTooltipProfile->mFillColor.blue, 200) );
  798. pDrawUtil->drawRect( rect, mTooltipProfile->mBorderColor );
  799. // Draw the text centered in the tool tip box
  800. pDrawUtil->setBitmapModulation( mTooltipProfile->mFontColor );
  801. Point2I start;
  802. start.set( ( textBounds.x - textWidth) / 2, ( textBounds.y - font->getHeight() ) / 2 );
  803. pDrawUtil->drawText( font, start + offset, tooltip, mProfile->mFontColors );
  804. pDrawUtil->clearBitmapModulation();
  805. return true;
  806. }
  807. ConsoleMethod(GuiParticleGraphCtrl, setSelectedPoint, void, 3, 3, "(int point)"
  808. "Set the selected point on the graph.\n"
  809. "@return No return value")
  810. {
  811. S32 point = dAtoi(argv[2]);
  812. if(point >= object->mPlots[object->mSelectedPlot].mGraphData.size() || point < 0)
  813. {
  814. Con::errorf("Invalid point to select.");
  815. return;
  816. }
  817. object->setSelectedPoint( point );
  818. }
  819. ConsoleMethod(GuiParticleGraphCtrl, setSelectedPlot, void, 3, 3, "(int plotID)"
  820. "Set the selected plot (a.k.a. graph)."
  821. "@return No return value" )
  822. {
  823. S32 plotID = dAtoi(argv[2]);
  824. if(plotID > object->MaxPlots)
  825. {
  826. Con::errorf("Invalid plotID.");
  827. return;
  828. }
  829. object->setSelectedPlot( plotID );
  830. }
  831. ConsoleMethod(GuiParticleGraphCtrl, clearGraph, void, 3, 3, "(int plotID)"
  832. "Clear the graph of the given plot."
  833. "@return No return value")
  834. {
  835. S32 plotID = dAtoi(argv[2]);
  836. if(plotID > object->MaxPlots)
  837. {
  838. Con::errorf("Invalid plotID.");
  839. return;
  840. }
  841. object->clearGraph( plotID );
  842. }
  843. ConsoleMethod(GuiParticleGraphCtrl, clearAllGraphs, void, 2, 2, "()"
  844. "Clear all of the graphs."
  845. "@return No return value")
  846. {
  847. object->clearAllGraphs();
  848. }
  849. ConsoleMethod(GuiParticleGraphCtrl, addPlotPoint, const char*, 5, 6, "(int plotID, float x, float y, bool setAdded = true;)"
  850. "Add a data point to the given plot."
  851. "@return")
  852. {
  853. S32 plotID = dAtoi(argv[2]);
  854. S32 pointAdded = 0;
  855. char *retBuffer = Con::getReturnBuffer(32);
  856. if(plotID > object->MaxPlots)
  857. {
  858. Con::errorf("Invalid plotID.");
  859. dSprintf(retBuffer, 32, "%d", -2);
  860. return retBuffer;
  861. }
  862. if(argc == 5)
  863. {
  864. pointAdded = object->addPlotPoint( plotID, Point2F(dAtof(argv[3]), dAtof(argv[4])));
  865. } else if(argc == 6)
  866. {
  867. pointAdded = object->addPlotPoint( plotID, Point2F(dAtof(argv[3]), dAtof(argv[4])), dAtob(argv[5]));
  868. }
  869. dSprintf(retBuffer, 32, "%d", pointAdded);
  870. return retBuffer;
  871. }
  872. ConsoleMethod(GuiParticleGraphCtrl, insertPlotPoint, void, 6, 6, "(int plotID, int i, float x, float y)\n"
  873. "Insert a data point to the given plot and plot position.\n"
  874. "@param plotID The plot you want to access\n"
  875. "@param i The data point.\n"
  876. "@param x,y The plot position.\n"
  877. "@return No return value.")
  878. {
  879. S32 plotID = dAtoi(argv[2]);
  880. if(plotID > object->MaxPlots)
  881. {
  882. Con::errorf("Invalid plotID.");
  883. return;
  884. }
  885. object->insertPlotPoint( plotID, dAtoi(argv[3]), Point2F(dAtof(argv[4]), dAtof(argv[5])));
  886. }
  887. ConsoleMethod(GuiParticleGraphCtrl, changePlotPoint, const char*, 6, 6, "(int plotID, int i, float x, float y)"
  888. "Change a data point to the given plot and plot position.\n"
  889. "@param plotID The plot you want to access\n"
  890. "@param i The data point.\n"
  891. "@param x,y The plot position.\n"
  892. "@return No return value.")
  893. {
  894. S32 plotID = dAtoi(argv[2]);
  895. if(plotID > object->MaxPlots)
  896. {
  897. Con::errorf("Invalid plotID.");
  898. char *retBuffer = Con::getReturnBuffer(64);
  899. const S32 index = -1;
  900. dSprintf(retBuffer, 64, "%d", index);
  901. return retBuffer;
  902. }
  903. char *retBuffer = Con::getReturnBuffer(64);
  904. const S32 index = object->changePlotPoint( plotID, dAtoi(argv[3]), Point2F(dAtof(argv[4]), dAtof(argv[5])));
  905. dSprintf(retBuffer, 64, "%d", index);
  906. return retBuffer;
  907. }
  908. ConsoleMethod(GuiParticleGraphCtrl, getSelectedPlot, const char*, 2, 2, "() "
  909. "Gets the selected Plot (a.k.a. graph).\n"
  910. "@return The plot's ID.")
  911. {
  912. char *retBuffer = Con::getReturnBuffer(32);
  913. const S32 plot = object->getSelectedPlot();
  914. dSprintf(retBuffer, 32, "%d", plot);
  915. return retBuffer;
  916. }
  917. ConsoleMethod(GuiParticleGraphCtrl, getSelectedPoint, const char*, 2, 2, "()"
  918. "Gets the selected Point on the Plot (a.k.a. graph)."
  919. "@return The last selected point ID")
  920. {
  921. char *retBuffer = Con::getReturnBuffer(32);
  922. const S32 point = object->getSelectedPoint();
  923. dSprintf(retBuffer, 32, "%d", point);
  924. return retBuffer;
  925. }
  926. ConsoleMethod(GuiParticleGraphCtrl, isExistingPoint, const char*, 4, 4, "(int plotID, int samples)"
  927. "@return Returns true or false whether or not the point in the plot passed is an existing point.")
  928. {
  929. S32 plotID = dAtoi(argv[2]);
  930. S32 samples = dAtoi(argv[3]);
  931. if(plotID > object->MaxPlots)
  932. {
  933. Con::errorf("Invalid plotID.");
  934. }
  935. if(samples > object->MaxDataPoints)
  936. {
  937. Con::errorf("Invalid sample.");
  938. }
  939. char *retBuffer = Con::getReturnBuffer(32);
  940. const bool isPoint = object->isExistingPoint(plotID, samples);
  941. dSprintf(retBuffer, 32, "%d", isPoint);
  942. return retBuffer;
  943. }
  944. ConsoleMethod(GuiParticleGraphCtrl, getPlotPoint, const char*, 4, 4, "(int plotID, int samples)"
  945. "Get a data point from the plot specified, samples from the start of the graph."
  946. "@return The data point ID")
  947. {
  948. S32 plotID = dAtoi(argv[2]);
  949. S32 samples = dAtoi(argv[3]);
  950. if(plotID > object->MaxPlots)
  951. {
  952. Con::errorf("Invalid plotID.");
  953. }
  954. if(samples > object->MaxDataPoints)
  955. {
  956. Con::errorf("Invalid sample.");
  957. }
  958. char *retBuffer = Con::getReturnBuffer(64);
  959. const Point2F &pos = object->getPlotPoint(plotID, samples);
  960. dSprintf(retBuffer, 64, "%f %f", pos.x, pos.y);
  961. return retBuffer;
  962. }
  963. ConsoleMethod(GuiParticleGraphCtrl, getPlotIndex, const char*, 5, 5, "(int plotID, float x, float y)\n"
  964. "Gets the index of the point passed on the plotID passed (graph ID).\n"
  965. "@param plotID The plot you wish to check.\n"
  966. "@param x,y The coordinates of the point to get.\n"
  967. "@return Returns the index of the point.\n")
  968. {
  969. S32 plotID = dAtoi(argv[2]);
  970. F32 x = dAtof(argv[3]);
  971. F32 y = dAtof(argv[4]);
  972. if(plotID > object->MaxPlots)
  973. {
  974. Con::errorf("Invalid plotID.");
  975. }
  976. char *retBuffer = Con::getReturnBuffer(32);
  977. const S32 &index = object->getPlotIndex(plotID, x, y);
  978. dSprintf(retBuffer, 32, "%d", index);
  979. return retBuffer;
  980. }
  981. ConsoleMethod(GuiParticleGraphCtrl, getGraphColor, const char*, 3, 3, "(int plotID)"
  982. "Get the color of the graph passed."
  983. "@return Returns the color of the graph as a string of RGB values formatted as \"R G B\"")
  984. {
  985. S32 plotID = dAtoi(argv[2]);
  986. if(plotID > object->MaxPlots)
  987. {
  988. Con::errorf("Invalid plotID.");
  989. }
  990. char *retBuffer = Con::getReturnBuffer(64);
  991. const ColorF &color = object->getGraphColor(plotID);
  992. dSprintf(retBuffer, 64, "%f %f %f", color.red, color.green, color.blue);
  993. return retBuffer;
  994. }
  995. ConsoleMethod(GuiParticleGraphCtrl, getGraphMin, const char*, 3, 3, "(int plotID) "
  996. "Get the minimum values of the graph ranges.\n"
  997. "@return Returns the minimum of the range formatted as \"x-min y-min\"")
  998. {
  999. S32 plotID = dAtoi(argv[2]);
  1000. if(plotID > object->MaxPlots)
  1001. {
  1002. Con::errorf("Invalid plotID.");
  1003. }
  1004. char *retBuffer = Con::getReturnBuffer(64);
  1005. const Point2F graphMin = object->getGraphMin(plotID);
  1006. dSprintf(retBuffer, 64, "%f %f", graphMin.x, graphMin.y);
  1007. return retBuffer;
  1008. }
  1009. ConsoleMethod(GuiParticleGraphCtrl, getGraphMax, const char*, 3, 3, "(int plotID) "
  1010. "Get the maximum values of the graph ranges.\n"
  1011. "@return Returns the maximum of the range formatted as \"x-max y-max\"")
  1012. {
  1013. S32 plotID = dAtoi(argv[2]);
  1014. if(plotID > object->MaxPlots)
  1015. {
  1016. Con::errorf("Invalid plotID.");
  1017. }
  1018. char *retBuffer = Con::getReturnBuffer(64);
  1019. const Point2F graphMax = object->getGraphMax(plotID);
  1020. dSprintf(retBuffer, 64, "%f %f", graphMax.x, graphMax.y);
  1021. return retBuffer;
  1022. }
  1023. ConsoleMethod(GuiParticleGraphCtrl, getGraphName, const char*, 3, 3, "(int plotID) "
  1024. "Get the name of the graph passed.\n"
  1025. "@return Returns the name of the plot")
  1026. {
  1027. S32 plotID = dAtoi(argv[2]);
  1028. if(plotID > object->MaxPlots)
  1029. {
  1030. Con::errorf("Invalid plotID.");
  1031. }
  1032. char *retBuffer = Con::getReturnBuffer(64);
  1033. const StringTableEntry graphName = object->getGraphName(plotID);
  1034. dSprintf(retBuffer, 64, "%s", graphName);
  1035. return retBuffer;
  1036. }
  1037. ConsoleMethod(GuiParticleGraphCtrl, setGraphMin, void, 5, 5, "(int plotID, float minX, float minY) "
  1038. "Set the min values of the graph of plotID.\n"
  1039. "@param plotID The plot to modify\n"
  1040. "@param minX,minY The minimum bound of the value range.\n"
  1041. "@return No return value.")
  1042. {
  1043. S32 plotID = dAtoi(argv[2]);
  1044. if(plotID > object->MaxPlots)
  1045. {
  1046. Con::errorf("Invalid plotID.");
  1047. return;
  1048. }
  1049. object->setGraphMin(dAtoi(argv[2]), Point2F(dAtof(argv[3]), dAtof(argv[4])));
  1050. }
  1051. ConsoleMethod(GuiParticleGraphCtrl, setGraphMinX, void, 4, 4, "(int plotID, float minX) "
  1052. "Set the min X value of the graph of plotID.\n"
  1053. "@param plotID The plot to modify.\n"
  1054. "@param minX The minimum x value.\n"
  1055. "@return No return Value.")
  1056. {
  1057. S32 plotID = dAtoi(argv[2]);
  1058. if(plotID > object->MaxPlots)
  1059. {
  1060. Con::errorf("Invalid plotID.");
  1061. return;
  1062. }
  1063. object->setGraphMinX(dAtoi(argv[2]), dAtof(argv[3]));
  1064. }
  1065. ConsoleMethod(GuiParticleGraphCtrl, setGraphMinY, void, 4, 4, "(int plotID, float minY) "
  1066. "Set the min Y value of the graph of plotID."
  1067. "@param plotID The plot to modify.\n"
  1068. "@param minY The minimum y value.\n"
  1069. "@return No return Value.")
  1070. {
  1071. S32 plotID = dAtoi(argv[2]);
  1072. if(plotID > object->MaxPlots)
  1073. {
  1074. Con::errorf("Invalid plotID.");
  1075. return;
  1076. }
  1077. object->setGraphMinY(dAtoi(argv[2]), dAtof(argv[3]));
  1078. }
  1079. ConsoleMethod(GuiParticleGraphCtrl, setGraphMax, void, 5, 5, "(int plotID, float maxX, float maxY) "
  1080. "Set the max values of the graph of plotID."
  1081. "@param plotID The plot to modify\n"
  1082. "@param maxX,maxY The maximum bound of the value range.\n"
  1083. "@return No return value.")
  1084. {
  1085. S32 plotID = dAtoi(argv[2]);
  1086. if(plotID > object->MaxPlots)
  1087. {
  1088. Con::errorf("Invalid plotID.");
  1089. return;
  1090. }
  1091. object->setGraphMax(dAtoi(argv[2]), Point2F(dAtof(argv[3]), dAtof(argv[4])));
  1092. }
  1093. ConsoleMethod(GuiParticleGraphCtrl, setGraphMaxX, void, 4, 4, "(int plotID, float maxX)"
  1094. "Set the max X value of the graph of plotID."
  1095. "@param plotID The plot to modify.\n"
  1096. "@param maxX The maximum x value.\n"
  1097. "@return No return Value.")
  1098. {
  1099. S32 plotID = dAtoi(argv[2]);
  1100. if(plotID > object->MaxPlots)
  1101. {
  1102. Con::errorf("Invalid plotID.");
  1103. return;
  1104. }
  1105. object->setGraphMaxX(dAtoi(argv[2]), dAtof(argv[3]));
  1106. }
  1107. ConsoleMethod(GuiParticleGraphCtrl, setGraphMaxY, void, 4, 4, "(int plotID, float maxY)"
  1108. "Set the max Y value of the graph of plotID."
  1109. "@param plotID The plot to modify.\n"
  1110. "@param maxY The maximum y value.\n"
  1111. "@return No return Value.")
  1112. {
  1113. S32 plotID = dAtoi(argv[2]);
  1114. if(plotID > object->MaxPlots)
  1115. {
  1116. Con::errorf("Invalid plotID.");
  1117. return;
  1118. }
  1119. object->setGraphMaxY(dAtoi(argv[2]), dAtof(argv[3]));
  1120. }
  1121. ConsoleMethod(GuiParticleGraphCtrl, setGraphHidden, void, 4, 4, "(int plotID, bool isHidden)"
  1122. "Set whether the graph number passed is hidden or not."
  1123. "@return No return value.")
  1124. {
  1125. S32 plotID = dAtoi(argv[2]);
  1126. if(plotID > object->MaxPlots)
  1127. {
  1128. Con::errorf("Invalid plotID.");
  1129. return;
  1130. }
  1131. object->setGraphHidden(dAtoi(argv[2]), dAtob(argv[3]));
  1132. }
  1133. ConsoleMethod(GuiParticleGraphCtrl, setAutoGraphMax, void, 3, 3, "(bool autoMax) "
  1134. "Set whether the max will automatically be set when adding points "
  1135. "(ie if you add a value over the current max, the max is increased to that value).\n"
  1136. "@return No return value.")
  1137. {
  1138. object->setAutoGraphMax(dAtob(argv[2]));
  1139. }
  1140. ConsoleMethod(GuiParticleGraphCtrl, setAutoRemove, void, 3, 3, "(bool autoRemove) "
  1141. "Set whether or not a point should be deleted when you drag another one over it."
  1142. "@return No return value.")
  1143. {
  1144. object->setAutoRemove(dAtob(argv[2]));
  1145. }
  1146. ConsoleMethod(GuiParticleGraphCtrl, setRenderAll, void, 3, 3, "(bool renderAll)"
  1147. "Set whether or not a position should be rendered on every point or just the last selected."
  1148. "@return No return value.")
  1149. {
  1150. object->setRenderAll(dAtob(argv[2]));
  1151. }
  1152. ConsoleMethod(GuiParticleGraphCtrl, setPointXMovementClamped, void, 3, 3, "(bool clamped)"
  1153. "Set whether the x position of the selected graph point should be clamped"
  1154. "@return No return value.")
  1155. {
  1156. object->setPointXMovementClamped(dAtob(argv[2]));
  1157. }
  1158. ConsoleMethod(GuiParticleGraphCtrl, setRenderGraphTooltip, void, 3, 3, "(bool renderGraphTooltip)"
  1159. "Set whether or not to render the graph tooltip."
  1160. "@return No return value.")
  1161. {
  1162. object->setRenderGraphTooltip(dAtob(argv[2]));
  1163. }
  1164. ConsoleMethod(GuiParticleGraphCtrl, setGraphName, void, 4, 4, "(int plotID, string graphName) "
  1165. "Set the name of the given plot.\n"
  1166. "@param plotID The plot to modify.\n"
  1167. "@param graphName The name to set on the plot.\n"
  1168. "@return No return value.")
  1169. {
  1170. S32 plotID = dAtoi(argv[2]);
  1171. if(plotID > object->MaxPlots)
  1172. {
  1173. Con::errorf("Invalid plotID.");
  1174. return;
  1175. }
  1176. object->setGraphName(dAtoi(argv[2]), argv[3]);
  1177. }
  1178. ConsoleMethod(GuiParticleGraphCtrl, resetSelectedPoint, void, 2, 2, "()"
  1179. "This will reset the currently selected point to nothing."
  1180. "@return No return value.")
  1181. {
  1182. object->resetSelectedPoint();
  1183. }