guiParticleGraphCtrl.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422
  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. Point2F mousePos = convertToGraphCoord(mSelectedPlot, event.mousePoint);
  609. S32 point = removePlotPoint(hitNut.x, hitNut.y);
  610. // Argument Buffer.
  611. char argBuffer[3][32];
  612. dSprintf(argBuffer[0], 32, "%d", mSelectedPlot);
  613. dSprintf(argBuffer[1], 32, "%d", point);
  614. dSprintf(argBuffer[2], 32, "%f %f", plotPoint.x, plotPoint.y);
  615. // Call Scripts.
  616. Con::executef(this, "onPlotPointRemoved", argBuffer[0], argBuffer[1], argBuffer[2]);
  617. } else
  618. {
  619. setSelectedPlot(hitNut.x);
  620. setSelectedPoint(hitNut.y);
  621. mOriginalSelectedPoint = hitNut.y;
  622. char argBuffer[32];
  623. dSprintf(argBuffer, 32, "%d", hitNut.y);
  624. // Call Scripts.
  625. Con::executef(this, "onPlotPointSelectedMouseDown", argBuffer);
  626. }
  627. } else if( mSelectedPlot != -1 )
  628. {
  629. Point2F mousePos = convertToGraphCoord(mSelectedPlot, event.mousePoint);
  630. mLastSelectedPoint = addPlotPoint(mSelectedPlot, mousePos);
  631. // Argument Buffer.
  632. char argBuffer[32];
  633. dSprintf(argBuffer, 32, "%f %f", convertToGraphCoord(mSelectedPlot, event.mousePoint).x, convertToGraphCoord(mSelectedPlot, event.mousePoint).y);
  634. // Call Scripts.
  635. Con::executef(this, "onMouseDragged", argBuffer);
  636. return;
  637. }
  638. }
  639. void GuiParticleGraphCtrl::onMouseUp(const GuiEvent &event)
  640. {
  641. if(mSelectedPoint != -1)
  642. mLastSelectedPoint = mSelectedPoint;
  643. if(mPointWasAdded == true)
  644. {
  645. if(mSelectedPoint == -1)
  646. {
  647. // Argument Buffer.
  648. char argBuffer[3][32];
  649. dSprintf(argBuffer[0], 32, "%d", mSelectedPlot);
  650. dSprintf(argBuffer[1], 32, "%f %f", mAddedPoint.x, mAddedPoint.y);
  651. dSprintf(argBuffer[2], 32, "%d", mAddedPointIndex);
  652. // Call Scripts.
  653. Con::executef(this, "onPlotPointAdded", argBuffer[0], argBuffer[1], argBuffer[2]);
  654. } else
  655. {
  656. // Argument Buffer.
  657. char argBuffer[4][32];
  658. dSprintf(argBuffer[0], 32, "%d", mSelectedPlot);
  659. dSprintf(argBuffer[1], 32, "%f %f", mAddedPoint.x, mAddedPoint.y);
  660. dSprintf(argBuffer[2], 32, "%d", mOriginalSelectedPoint);
  661. dSprintf(argBuffer[3], 32, "%d", mAddedPointIndex);
  662. // Call Scripts.
  663. Con::executef(this, "onPlotPointChangedUp", argBuffer[0], argBuffer[1], argBuffer[2], argBuffer[3]);
  664. }
  665. }
  666. mPointWasAdded = false;
  667. mSelectedPoint = -1;
  668. }
  669. void GuiParticleGraphCtrl::onMouseDragged(const GuiEvent &event)
  670. {
  671. mRenderNextGraphTooltip = false;
  672. if(mSelectedPoint != -1)
  673. {
  674. Point2F mousePos = convertToGraphCoord(mSelectedPlot, event.mousePoint);
  675. if(mPointXMovementClamped == true)
  676. {
  677. F32 prevXPos = getPlotPoint(mSelectedPlot, mSelectedPoint).x;
  678. if(mousePos.x != prevXPos)
  679. {
  680. mousePos.x = prevXPos;
  681. }
  682. }
  683. removePlotPoint(mSelectedPlot, mSelectedPoint);
  684. S32 point = addPlotPoint(mSelectedPlot, mousePos);
  685. if(point != -1)
  686. {
  687. setSelectedPoint(point);
  688. mLastMousePos = mousePos;
  689. // Argument Buffer.
  690. char argBuffer[3][32];
  691. dSprintf(argBuffer[0], 32, "%d", mSelectedPlot);
  692. dSprintf(argBuffer[1], 32, "%f %f", mAddedPoint.x, mAddedPoint.y);
  693. dSprintf(argBuffer[2], 32, "%d", point);
  694. // Call Scripts.
  695. Con::executef(this, "onPlotPointChangedMove", argBuffer[0], argBuffer[1], argBuffer[2]);
  696. } else
  697. {
  698. point = addPlotPoint(mSelectedPlot, mLastMousePos);
  699. }
  700. }
  701. // Argument Buffer.
  702. char argBuffer[32];
  703. dSprintf(argBuffer, 32, "%f %f", convertToGraphCoord(mSelectedPlot, event.mousePoint).x, convertToGraphCoord(mSelectedPlot, event.mousePoint).y);
  704. // Call Scripts.
  705. Con::executef(this, "onMouseDragged", argBuffer);
  706. }
  707. void GuiParticleGraphCtrl::onRightMouseDown(const GuiEvent &event)
  708. {
  709. Point2I hitNut = findHitNut(event.mousePoint);
  710. if( hitNut != Point2I(-1,-1) )
  711. {
  712. Point2F plotPoint = getPlotPoint(hitNut.x, hitNut.y);
  713. Point2F mousePos = convertToGraphCoord(mSelectedPlot, event.mousePoint);
  714. S32 point = removePlotPoint(hitNut.x, hitNut.y);
  715. // Argument Buffer.
  716. char argBuffer[3][32];
  717. dSprintf(argBuffer[0], 32, "%d", mSelectedPlot);
  718. dSprintf(argBuffer[1], 32, "%d", point);
  719. dSprintf(argBuffer[2], 32, "%f %f", plotPoint.x, plotPoint.y);
  720. // Call Scripts.
  721. Con::executef(this, "onPlotPointRemoved", argBuffer[0], argBuffer[1], argBuffer[2]);
  722. }
  723. }
  724. void GuiParticleGraphCtrl::onRightMouseUp(const GuiEvent &event)
  725. {
  726. }
  727. void GuiParticleGraphCtrl::onRightMouseDragged(const GuiEvent &event)
  728. {
  729. Point2I hitNut = findHitNut(event.mousePoint);
  730. if( hitNut != Point2I(-1,-1) )
  731. {
  732. Point2F plotPoint = getPlotPoint(hitNut.x, hitNut.y);
  733. Point2F mousePos = convertToGraphCoord(mSelectedPlot, event.mousePoint);
  734. S32 point = removePlotPoint(hitNut.x, hitNut.y);
  735. // Argument Buffer.
  736. char argBuffer[3][32];
  737. dSprintf(argBuffer[0], 32, "%d", mSelectedPlot);
  738. dSprintf(argBuffer[1], 32, "%d", point);
  739. dSprintf(argBuffer[2], 32, "%f %f", plotPoint.x, plotPoint.y);
  740. // Call Scripts.
  741. Con::executef(this, "onPlotPointRemoved", argBuffer[0], argBuffer[1], argBuffer[2]);
  742. }
  743. }
  744. void GuiParticleGraphCtrl::clearAllGraphs()
  745. {
  746. for(S32 i = 0;i < MaxPlots;i++)
  747. {
  748. clearGraph(i);
  749. }
  750. }
  751. void GuiParticleGraphCtrl::clearGraph(S32 plotID)
  752. {
  753. mPlots[plotID].mGraphData.clear();
  754. mPlots[plotID].mNutList.clear();
  755. }
  756. bool GuiParticleGraphCtrl::renderGraphTooltip(Point2I cursorPos, StringTableEntry tooltip)
  757. {
  758. // Short Circuit.
  759. if (!mAwake)
  760. return false;
  761. if ( dStrlen( tooltip ) == 0 )
  762. return false;
  763. // Need to have root.
  764. GuiCanvas *root = getRoot();
  765. if ( !root )
  766. return false;
  767. if (!mTooltipProfile)
  768. setTooltipProfile( mProfile );
  769. GFont *font = mTooltipProfile->mFont;
  770. // Fetch Canvas.
  771. GuiCanvas *pCanvas = getRoot();
  772. //Vars used:
  773. //Screensize (for position check)
  774. //Offset to get position of cursor
  775. //textBounds for text extent.
  776. Point2I screensize = pCanvas->getWindowSize();
  777. Point2I offset = cursorPos;
  778. Point2I textBounds;
  779. S32 textWidth = font->getStrWidth(tooltip);
  780. //Offset below cursor image
  781. offset.y -= root->getCursorExtent().y;
  782. //Create text bounds.
  783. textBounds.x = textWidth+8;
  784. textBounds.y = font->getHeight() + 4;
  785. // Check position/width to make sure all of the tooltip will be rendered
  786. // 5 is given as a buffer against the edge
  787. if (screensize.x < offset.x + textBounds.x + 5)
  788. offset.x = screensize.x - textBounds.x - 5;
  789. // And ditto for the height
  790. if(screensize.y < offset.y + textBounds.y + 5)
  791. offset.y = cursorPos.y - textBounds.y - 5;
  792. // Set rectangle for the box, and set the clip rectangle.
  793. RectI rect(offset, textBounds);
  794. GFX->setClipRect(rect);
  795. // Fetch Draw Utility.
  796. GFXDrawUtil* pDrawUtil = GFX->getDrawUtil();
  797. // Draw Filler bit, then border on top of that
  798. pDrawUtil->drawRectFill(rect, ColorI(mTooltipProfile->mFillColor.red, mTooltipProfile->mFillColor.green, mTooltipProfile->mFillColor.blue, 200) );
  799. pDrawUtil->drawRect( rect, mTooltipProfile->mBorderColor );
  800. // Draw the text centered in the tool tip box
  801. pDrawUtil->setBitmapModulation( mTooltipProfile->mFontColor );
  802. Point2I start;
  803. start.set( ( textBounds.x - textWidth) / 2, ( textBounds.y - font->getHeight() ) / 2 );
  804. pDrawUtil->drawText( font, start + offset, tooltip, mProfile->mFontColors );
  805. pDrawUtil->clearBitmapModulation();
  806. return true;
  807. }
  808. DefineConsoleMethod(GuiParticleGraphCtrl, setSelectedPoint, void, (S32 point), , "(int point)"
  809. "Set the selected point on the graph.\n"
  810. "@return No return value")
  811. {
  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. DefineConsoleMethod(GuiParticleGraphCtrl, setSelectedPlot, void, (S32 plotID), , "(int plotID)"
  820. "Set the selected plot (a.k.a. graph)."
  821. "@return No return value" )
  822. {
  823. if(plotID > object->MaxPlots)
  824. {
  825. Con::errorf("Invalid plotID.");
  826. return;
  827. }
  828. object->setSelectedPlot( plotID );
  829. }
  830. DefineConsoleMethod(GuiParticleGraphCtrl, clearGraph, void, (S32 plotID), , "(int plotID)"
  831. "Clear the graph of the given plot."
  832. "@return No return value")
  833. {
  834. if(plotID > object->MaxPlots)
  835. {
  836. Con::errorf("Invalid plotID.");
  837. return;
  838. }
  839. object->clearGraph( plotID );
  840. }
  841. DefineConsoleMethod(GuiParticleGraphCtrl, clearAllGraphs, void, (), , "()"
  842. "Clear all of the graphs."
  843. "@return No return value")
  844. {
  845. object->clearAllGraphs();
  846. }
  847. DefineConsoleMethod(GuiParticleGraphCtrl, addPlotPoint, const char*, (S32 plotID, F32 x, F32 y, bool setAdded), (true), "(int plotID, float x, float y, bool setAdded = true;)"
  848. "Add a data point to the given plot."
  849. "@return")
  850. {
  851. S32 pointAdded = 0;
  852. char *retBuffer = Con::getReturnBuffer(32);
  853. if(plotID > object->MaxPlots)
  854. {
  855. Con::errorf("Invalid plotID.");
  856. dSprintf(retBuffer, 32, "%d", -2);
  857. return retBuffer;
  858. }
  859. pointAdded = object->addPlotPoint( plotID, Point2F(x, y), setAdded);
  860. dSprintf(retBuffer, 32, "%d", pointAdded);
  861. return retBuffer;
  862. }
  863. DefineConsoleMethod(GuiParticleGraphCtrl, insertPlotPoint, void, (S32 plotID, S32 i, F32 x, F32 y), , "(int plotID, int i, float x, float y)\n"
  864. "Insert a data point to the given plot and plot position.\n"
  865. "@param plotID The plot you want to access\n"
  866. "@param i The data point.\n"
  867. "@param x,y The plot position.\n"
  868. "@return No return value.")
  869. {
  870. if(plotID > object->MaxPlots)
  871. {
  872. Con::errorf("Invalid plotID.");
  873. return;
  874. }
  875. object->insertPlotPoint( plotID, i, Point2F(x, y));
  876. }
  877. DefineConsoleMethod(GuiParticleGraphCtrl, changePlotPoint, const char*, (S32 plotID, S32 i, F32 x, F32 y), , "(int plotID, int i, float x, float y)"
  878. "Change a data point to the given plot and plot position.\n"
  879. "@param plotID The plot you want to access\n"
  880. "@param i The data point.\n"
  881. "@param x,y The plot position.\n"
  882. "@return No return value.")
  883. {
  884. if(plotID > object->MaxPlots)
  885. {
  886. Con::errorf("Invalid plotID.");
  887. char *retBuffer = Con::getReturnBuffer(64);
  888. const S32 index = -1;
  889. dSprintf(retBuffer, 64, "%d", index);
  890. return retBuffer;
  891. }
  892. char *retBuffer = Con::getReturnBuffer(64);
  893. const S32 index = object->changePlotPoint( plotID, i, Point2F(x, y));
  894. dSprintf(retBuffer, 64, "%d", index);
  895. return retBuffer;
  896. }
  897. DefineConsoleMethod(GuiParticleGraphCtrl, getSelectedPlot, const char*, (), , "() "
  898. "Gets the selected Plot (a.k.a. graph).\n"
  899. "@return The plot's ID.")
  900. {
  901. char *retBuffer = Con::getReturnBuffer(32);
  902. const S32 plot = object->getSelectedPlot();
  903. dSprintf(retBuffer, 32, "%d", plot);
  904. return retBuffer;
  905. }
  906. DefineConsoleMethod(GuiParticleGraphCtrl, getSelectedPoint, const char*, (), , "()"
  907. "Gets the selected Point on the Plot (a.k.a. graph)."
  908. "@return The last selected point ID")
  909. {
  910. char *retBuffer = Con::getReturnBuffer(32);
  911. const S32 point = object->getSelectedPoint();
  912. dSprintf(retBuffer, 32, "%d", point);
  913. return retBuffer;
  914. }
  915. DefineConsoleMethod(GuiParticleGraphCtrl, isExistingPoint, const char*, (S32 plotID, S32 samples), , "(int plotID, int samples)"
  916. "@return Returns true or false whether or not the point in the plot passed is an existing point.")
  917. {
  918. if(plotID > object->MaxPlots)
  919. {
  920. Con::errorf("Invalid plotID.");
  921. }
  922. if(samples > object->MaxDataPoints)
  923. {
  924. Con::errorf("Invalid sample.");
  925. }
  926. char *retBuffer = Con::getReturnBuffer(32);
  927. const bool isPoint = object->isExistingPoint(plotID, samples);
  928. dSprintf(retBuffer, 32, "%d", isPoint);
  929. return retBuffer;
  930. }
  931. DefineConsoleMethod(GuiParticleGraphCtrl, getPlotPoint, const char*, (S32 plotID, S32 samples), , "(int plotID, int samples)"
  932. "Get a data point from the plot specified, samples from the start of the graph."
  933. "@return The data point ID")
  934. {
  935. if(plotID > object->MaxPlots)
  936. {
  937. Con::errorf("Invalid plotID.");
  938. }
  939. if(samples > object->MaxDataPoints)
  940. {
  941. Con::errorf("Invalid sample.");
  942. }
  943. char *retBuffer = Con::getReturnBuffer(64);
  944. const Point2F &pos = object->getPlotPoint(plotID, samples);
  945. dSprintf(retBuffer, 64, "%f %f", pos.x, pos.y);
  946. return retBuffer;
  947. }
  948. DefineConsoleMethod(GuiParticleGraphCtrl, getPlotIndex, const char*, (S32 plotID, F32 x, F32 y), , "(int plotID, float x, float y)\n"
  949. "Gets the index of the point passed on the plotID passed (graph ID).\n"
  950. "@param plotID The plot you wish to check.\n"
  951. "@param x,y The coordinates of the point to get.\n"
  952. "@return Returns the index of the point.\n")
  953. {
  954. if(plotID > object->MaxPlots)
  955. {
  956. Con::errorf("Invalid plotID.");
  957. }
  958. char *retBuffer = Con::getReturnBuffer(32);
  959. const S32 &index = object->getPlotIndex(plotID, x, y);
  960. dSprintf(retBuffer, 32, "%d", index);
  961. return retBuffer;
  962. }
  963. DefineConsoleMethod(GuiParticleGraphCtrl, getGraphColor, const char*, (S32 plotID), , "(int plotID)"
  964. "Get the color of the graph passed."
  965. "@return Returns the color of the graph as a string of RGB values formatted as \"R G B\"")
  966. {
  967. if(plotID > object->MaxPlots)
  968. {
  969. Con::errorf("Invalid plotID.");
  970. }
  971. char *retBuffer = Con::getReturnBuffer(64);
  972. const ColorF &color = object->getGraphColor(plotID);
  973. dSprintf(retBuffer, 64, "%f %f %f", color.red, color.green, color.blue);
  974. return retBuffer;
  975. }
  976. DefineConsoleMethod(GuiParticleGraphCtrl, getGraphMin, const char*, (S32 plotID), , "(int plotID) "
  977. "Get the minimum values of the graph ranges.\n"
  978. "@return Returns the minimum of the range formatted as \"x-min y-min\"")
  979. {
  980. if(plotID > object->MaxPlots)
  981. {
  982. Con::errorf("Invalid plotID.");
  983. }
  984. char *retBuffer = Con::getReturnBuffer(64);
  985. const Point2F graphMin = object->getGraphMin(plotID);
  986. dSprintf(retBuffer, 64, "%f %f", graphMin.x, graphMin.y);
  987. return retBuffer;
  988. }
  989. DefineConsoleMethod(GuiParticleGraphCtrl, getGraphMax, const char*, (S32 plotID), , "(int plotID) "
  990. "Get the maximum values of the graph ranges.\n"
  991. "@return Returns the maximum of the range formatted as \"x-max y-max\"")
  992. {
  993. if(plotID > object->MaxPlots)
  994. {
  995. Con::errorf("Invalid plotID.");
  996. }
  997. char *retBuffer = Con::getReturnBuffer(64);
  998. const Point2F graphMax = object->getGraphMax(plotID);
  999. dSprintf(retBuffer, 64, "%f %f", graphMax.x, graphMax.y);
  1000. return retBuffer;
  1001. }
  1002. DefineConsoleMethod(GuiParticleGraphCtrl, getGraphName, const char*, (S32 plotID), , "(int plotID) "
  1003. "Get the name of the graph passed.\n"
  1004. "@return Returns the name of the plot")
  1005. {
  1006. if(plotID > object->MaxPlots)
  1007. {
  1008. Con::errorf("Invalid plotID.");
  1009. }
  1010. char *retBuffer = Con::getReturnBuffer(64);
  1011. const StringTableEntry graphName = object->getGraphName(plotID);
  1012. dSprintf(retBuffer, 64, "%s", graphName);
  1013. return retBuffer;
  1014. }
  1015. DefineConsoleMethod(GuiParticleGraphCtrl, setGraphMin, void, (S32 plotID, F32 minX, F32 minY), , "(int plotID, float minX, float minY) "
  1016. "Set the min values of the graph of plotID.\n"
  1017. "@param plotID The plot to modify\n"
  1018. "@param minX,minY The minimum bound of the value range.\n"
  1019. "@return No return value.")
  1020. {
  1021. if(plotID > object->MaxPlots)
  1022. {
  1023. Con::errorf("Invalid plotID.");
  1024. return;
  1025. }
  1026. object->setGraphMin(plotID, Point2F(minX, minY));
  1027. }
  1028. DefineConsoleMethod(GuiParticleGraphCtrl, setGraphMinX, void, (S32 plotID, F32 minX), , "(int plotID, float minX) "
  1029. "Set the min X value of the graph of plotID.\n"
  1030. "@param plotID The plot to modify.\n"
  1031. "@param minX The minimum x value.\n"
  1032. "@return No return Value.")
  1033. {
  1034. if(plotID > object->MaxPlots)
  1035. {
  1036. Con::errorf("Invalid plotID.");
  1037. return;
  1038. }
  1039. object->setGraphMinX(plotID, minX);
  1040. }
  1041. DefineConsoleMethod(GuiParticleGraphCtrl, setGraphMinY, void, (S32 plotID, F32 minX), , "(int plotID, float minY) "
  1042. "Set the min Y value of the graph of plotID."
  1043. "@param plotID The plot to modify.\n"
  1044. "@param minY The minimum y value.\n"
  1045. "@return No return Value.")
  1046. {
  1047. if(plotID > object->MaxPlots)
  1048. {
  1049. Con::errorf("Invalid plotID.");
  1050. return;
  1051. }
  1052. object->setGraphMinY(plotID, minX);
  1053. }
  1054. DefineConsoleMethod(GuiParticleGraphCtrl, setGraphMax, void, (S32 plotID, F32 maxX, F32 maxY), , "(int plotID, float maxX, float maxY) "
  1055. "Set the max values of the graph of plotID."
  1056. "@param plotID The plot to modify\n"
  1057. "@param maxX,maxY The maximum bound of the value range.\n"
  1058. "@return No return value.")
  1059. {
  1060. if(plotID > object->MaxPlots)
  1061. {
  1062. Con::errorf("Invalid plotID.");
  1063. return;
  1064. }
  1065. object->setGraphMax(plotID, Point2F(maxX, maxY));
  1066. }
  1067. DefineConsoleMethod(GuiParticleGraphCtrl, setGraphMaxX, void, (S32 plotID, F32 maxX), , "(int plotID, float maxX)"
  1068. "Set the max X value of the graph of plotID."
  1069. "@param plotID The plot to modify.\n"
  1070. "@param maxX The maximum x value.\n"
  1071. "@return No return Value.")
  1072. {
  1073. if(plotID > object->MaxPlots)
  1074. {
  1075. Con::errorf("Invalid plotID.");
  1076. return;
  1077. }
  1078. object->setGraphMaxX(plotID, maxX);
  1079. }
  1080. DefineConsoleMethod(GuiParticleGraphCtrl, setGraphMaxY, void, (S32 plotID, F32 maxX), , "(int plotID, float maxY)"
  1081. "Set the max Y value of the graph of plotID."
  1082. "@param plotID The plot to modify.\n"
  1083. "@param maxY The maximum y value.\n"
  1084. "@return No return Value.")
  1085. {
  1086. if(plotID > object->MaxPlots)
  1087. {
  1088. Con::errorf("Invalid plotID.");
  1089. return;
  1090. }
  1091. object->setGraphMaxY(plotID, maxX);
  1092. }
  1093. DefineConsoleMethod(GuiParticleGraphCtrl, setGraphHidden, void, (S32 plotID, bool isHidden), , "(int plotID, bool isHidden)"
  1094. "Set whether the graph number passed is hidden or not."
  1095. "@return No return value.")
  1096. {
  1097. if(plotID > object->MaxPlots)
  1098. {
  1099. Con::errorf("Invalid plotID.");
  1100. return;
  1101. }
  1102. object->setGraphHidden(plotID, isHidden);
  1103. }
  1104. DefineConsoleMethod(GuiParticleGraphCtrl, setAutoGraphMax, void, (bool autoMax), , "(bool autoMax) "
  1105. "Set whether the max will automatically be set when adding points "
  1106. "(ie if you add a value over the current max, the max is increased to that value).\n"
  1107. "@return No return value.")
  1108. {
  1109. object->setAutoGraphMax(autoMax);
  1110. }
  1111. DefineConsoleMethod(GuiParticleGraphCtrl, setAutoRemove, void, (bool autoRemove), , "(bool autoRemove) "
  1112. "Set whether or not a point should be deleted when you drag another one over it."
  1113. "@return No return value.")
  1114. {
  1115. object->setAutoRemove(autoRemove);
  1116. }
  1117. DefineConsoleMethod(GuiParticleGraphCtrl, setRenderAll, void, (bool autoRemove), , "(bool renderAll)"
  1118. "Set whether or not a position should be rendered on every point or just the last selected."
  1119. "@return No return value.")
  1120. {
  1121. object->setRenderAll(autoRemove);
  1122. }
  1123. DefineConsoleMethod(GuiParticleGraphCtrl, setPointXMovementClamped, void, (bool autoRemove), , "(bool clamped)"
  1124. "Set whether the x position of the selected graph point should be clamped"
  1125. "@return No return value.")
  1126. {
  1127. object->setPointXMovementClamped(autoRemove);
  1128. }
  1129. DefineConsoleMethod(GuiParticleGraphCtrl, setRenderGraphTooltip, void, (bool autoRemove), , "(bool renderGraphTooltip)"
  1130. "Set whether or not to render the graph tooltip."
  1131. "@return No return value.")
  1132. {
  1133. object->setRenderGraphTooltip(autoRemove);
  1134. }
  1135. DefineConsoleMethod(GuiParticleGraphCtrl, setGraphName, void, (S32 plotID, const char * graphName), , "(int plotID, string graphName) "
  1136. "Set the name of the given plot.\n"
  1137. "@param plotID The plot to modify.\n"
  1138. "@param graphName The name to set on the plot.\n"
  1139. "@return No return value.")
  1140. {
  1141. if(plotID > object->MaxPlots)
  1142. {
  1143. Con::errorf("Invalid plotID.");
  1144. return;
  1145. }
  1146. object->setGraphName(plotID, graphName);
  1147. }
  1148. DefineConsoleMethod(GuiParticleGraphCtrl, resetSelectedPoint, void, (), , "()"
  1149. "This will reset the currently selected point to nothing."
  1150. "@return No return value.")
  1151. {
  1152. object->resetSelectedPoint();
  1153. }