guiParticleGraphCtrl.cpp 40 KB

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