guiParticleGraphCtrl.cpp 41 KB

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