guiParticleGraphCtrl.cpp 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382
  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, S32, (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. if(plotID > object->MaxPlots)
  852. {
  853. Con::errorf("Invalid plotID.");
  854. return -2;
  855. }
  856. return object->addPlotPoint( plotID, Point2F(x, y), setAdded);
  857. }
  858. DefineConsoleMethod(GuiParticleGraphCtrl, insertPlotPoint, void, (S32 plotID, S32 i, F32 x, F32 y), , "(int plotID, int i, float x, float y)\n"
  859. "Insert a data point to the given plot and plot position.\n"
  860. "@param plotID The plot you want to access\n"
  861. "@param i The data point.\n"
  862. "@param x,y The plot position.\n"
  863. "@return No return value.")
  864. {
  865. if(plotID > object->MaxPlots)
  866. {
  867. Con::errorf("Invalid plotID.");
  868. return;
  869. }
  870. object->insertPlotPoint( plotID, i, Point2F(x, y));
  871. }
  872. DefineConsoleMethod(GuiParticleGraphCtrl, changePlotPoint, S32, (S32 plotID, S32 i, F32 x, F32 y), , "(int plotID, int i, float x, float y)"
  873. "Change a data point to the given plot and plot position.\n"
  874. "@param plotID The plot you want to access\n"
  875. "@param i The data point.\n"
  876. "@param x,y The plot position.\n"
  877. "@return No return value.")
  878. {
  879. if(plotID > object->MaxPlots)
  880. {
  881. Con::errorf("Invalid plotID.");
  882. return -1;
  883. }
  884. return object->changePlotPoint( plotID, i, Point2F(x, y));
  885. }
  886. DefineConsoleMethod(GuiParticleGraphCtrl, getSelectedPlot, S32, (), , "() "
  887. "Gets the selected Plot (a.k.a. graph).\n"
  888. "@return The plot's ID.")
  889. {
  890. return object->getSelectedPlot();
  891. }
  892. DefineConsoleMethod(GuiParticleGraphCtrl, getSelectedPoint, S32, (), , "()"
  893. "Gets the selected Point on the Plot (a.k.a. graph)."
  894. "@return The last selected point ID")
  895. {
  896. return object->getSelectedPoint();
  897. }
  898. DefineConsoleMethod(GuiParticleGraphCtrl, isExistingPoint, bool, (S32 plotID, S32 samples), , "(int plotID, int samples)"
  899. "@return Returns true or false whether or not the point in the plot passed is an existing point.")
  900. {
  901. if(plotID > object->MaxPlots)
  902. {
  903. Con::errorf("Invalid plotID.");
  904. }
  905. if(samples > object->MaxDataPoints)
  906. {
  907. Con::errorf("Invalid sample.");
  908. }
  909. return object->isExistingPoint(plotID, samples);
  910. }
  911. DefineConsoleMethod(GuiParticleGraphCtrl, getPlotPoint, Point2F, (S32 plotID, S32 samples), , "(int plotID, int samples)"
  912. "Get a data point from the plot specified, samples from the start of the graph."
  913. "@return The data point ID")
  914. {
  915. if(plotID > object->MaxPlots)
  916. {
  917. Con::errorf("Invalid plotID.");
  918. }
  919. if(samples > object->MaxDataPoints)
  920. {
  921. Con::errorf("Invalid sample.");
  922. }
  923. return object->getPlotPoint(plotID, samples);
  924. }
  925. DefineConsoleMethod(GuiParticleGraphCtrl, getPlotIndex, S32, (S32 plotID, F32 x, F32 y), , "(int plotID, float x, float y)\n"
  926. "Gets the index of the point passed on the plotID passed (graph ID).\n"
  927. "@param plotID The plot you wish to check.\n"
  928. "@param x,y The coordinates of the point to get.\n"
  929. "@return Returns the index of the point.\n")
  930. {
  931. if(plotID > object->MaxPlots)
  932. {
  933. Con::errorf("Invalid plotID.");
  934. }
  935. return object->getPlotIndex(plotID, x, y);
  936. }
  937. DefineConsoleMethod(GuiParticleGraphCtrl, getGraphColor, ColorF, (S32 plotID), , "(int plotID)"
  938. "Get the color of the graph passed."
  939. "@return Returns the color of the graph as a string of RGB values formatted as \"R G B\"")
  940. {
  941. if(plotID > object->MaxPlots)
  942. {
  943. Con::errorf("Invalid plotID.");
  944. }
  945. return object->getGraphColor(plotID);
  946. }
  947. DefineConsoleMethod(GuiParticleGraphCtrl, getGraphMin, Point2F, (S32 plotID), , "(int plotID) "
  948. "Get the minimum values of the graph ranges.\n"
  949. "@return Returns the minimum of the range formatted as \"x-min y-min\"")
  950. {
  951. if(plotID > object->MaxPlots)
  952. {
  953. Con::errorf("Invalid plotID.");
  954. }
  955. return object->getGraphMin(plotID);
  956. }
  957. DefineConsoleMethod(GuiParticleGraphCtrl, getGraphMax, Point2F, (S32 plotID), , "(int plotID) "
  958. "Get the maximum values of the graph ranges.\n"
  959. "@return Returns the maximum of the range formatted as \"x-max y-max\"")
  960. {
  961. if(plotID > object->MaxPlots)
  962. {
  963. Con::errorf("Invalid plotID.");
  964. }
  965. return object->getGraphMax(plotID);
  966. }
  967. DefineConsoleMethod(GuiParticleGraphCtrl, getGraphName, const char*, (S32 plotID), , "(int plotID) "
  968. "Get the name of the graph passed.\n"
  969. "@return Returns the name of the plot")
  970. {
  971. if(plotID > object->MaxPlots)
  972. {
  973. Con::errorf("Invalid plotID.");
  974. }
  975. const U32 bufSize = 64;
  976. char *retBuffer = Con::getReturnBuffer(bufSize);
  977. const StringTableEntry graphName = object->getGraphName(plotID);
  978. dSprintf(retBuffer, bufSize, "%s", graphName);
  979. return retBuffer;
  980. }
  981. DefineConsoleMethod(GuiParticleGraphCtrl, setGraphMin, void, (S32 plotID, F32 minX, F32 minY), , "(int plotID, float minX, float minY) "
  982. "Set the min values of the graph of plotID.\n"
  983. "@param plotID The plot to modify\n"
  984. "@param minX,minY The minimum bound of the value range.\n"
  985. "@return No return value.")
  986. {
  987. if(plotID > object->MaxPlots)
  988. {
  989. Con::errorf("Invalid plotID.");
  990. return;
  991. }
  992. object->setGraphMin(plotID, Point2F(minX, minY));
  993. }
  994. DefineConsoleMethod(GuiParticleGraphCtrl, setGraphMinX, void, (S32 plotID, F32 minX), , "(int plotID, float minX) "
  995. "Set the min X value of the graph of plotID.\n"
  996. "@param plotID The plot to modify.\n"
  997. "@param minX The minimum x value.\n"
  998. "@return No return Value.")
  999. {
  1000. if(plotID > object->MaxPlots)
  1001. {
  1002. Con::errorf("Invalid plotID.");
  1003. return;
  1004. }
  1005. object->setGraphMinX(plotID, minX);
  1006. }
  1007. DefineConsoleMethod(GuiParticleGraphCtrl, setGraphMinY, void, (S32 plotID, F32 minX), , "(int plotID, float minY) "
  1008. "Set the min Y value of the graph of plotID."
  1009. "@param plotID The plot to modify.\n"
  1010. "@param minY The minimum y value.\n"
  1011. "@return No return Value.")
  1012. {
  1013. if(plotID > object->MaxPlots)
  1014. {
  1015. Con::errorf("Invalid plotID.");
  1016. return;
  1017. }
  1018. object->setGraphMinY(plotID, minX);
  1019. }
  1020. DefineConsoleMethod(GuiParticleGraphCtrl, setGraphMax, void, (S32 plotID, F32 maxX, F32 maxY), , "(int plotID, float maxX, float maxY) "
  1021. "Set the max values of the graph of plotID."
  1022. "@param plotID The plot to modify\n"
  1023. "@param maxX,maxY The maximum bound of the value range.\n"
  1024. "@return No return value.")
  1025. {
  1026. if(plotID > object->MaxPlots)
  1027. {
  1028. Con::errorf("Invalid plotID.");
  1029. return;
  1030. }
  1031. object->setGraphMax(plotID, Point2F(maxX, maxY));
  1032. }
  1033. DefineConsoleMethod(GuiParticleGraphCtrl, setGraphMaxX, void, (S32 plotID, F32 maxX), , "(int plotID, float maxX)"
  1034. "Set the max X value of the graph of plotID."
  1035. "@param plotID The plot to modify.\n"
  1036. "@param maxX The maximum x value.\n"
  1037. "@return No return Value.")
  1038. {
  1039. if(plotID > object->MaxPlots)
  1040. {
  1041. Con::errorf("Invalid plotID.");
  1042. return;
  1043. }
  1044. object->setGraphMaxX(plotID, maxX);
  1045. }
  1046. DefineConsoleMethod(GuiParticleGraphCtrl, setGraphMaxY, void, (S32 plotID, F32 maxX), , "(int plotID, float maxY)"
  1047. "Set the max Y value of the graph of plotID."
  1048. "@param plotID The plot to modify.\n"
  1049. "@param maxY The maximum y value.\n"
  1050. "@return No return Value.")
  1051. {
  1052. if(plotID > object->MaxPlots)
  1053. {
  1054. Con::errorf("Invalid plotID.");
  1055. return;
  1056. }
  1057. object->setGraphMaxY(plotID, maxX);
  1058. }
  1059. DefineConsoleMethod(GuiParticleGraphCtrl, setGraphHidden, void, (S32 plotID, bool isHidden), , "(int plotID, bool isHidden)"
  1060. "Set whether the graph number passed is hidden or not."
  1061. "@return No return value.")
  1062. {
  1063. if(plotID > object->MaxPlots)
  1064. {
  1065. Con::errorf("Invalid plotID.");
  1066. return;
  1067. }
  1068. object->setGraphHidden(plotID, isHidden);
  1069. }
  1070. DefineConsoleMethod(GuiParticleGraphCtrl, setAutoGraphMax, void, (bool autoMax), , "(bool autoMax) "
  1071. "Set whether the max will automatically be set when adding points "
  1072. "(ie if you add a value over the current max, the max is increased to that value).\n"
  1073. "@return No return value.")
  1074. {
  1075. object->setAutoGraphMax(autoMax);
  1076. }
  1077. DefineConsoleMethod(GuiParticleGraphCtrl, setAutoRemove, void, (bool autoRemove), , "(bool autoRemove) "
  1078. "Set whether or not a point should be deleted when you drag another one over it."
  1079. "@return No return value.")
  1080. {
  1081. object->setAutoRemove(autoRemove);
  1082. }
  1083. DefineConsoleMethod(GuiParticleGraphCtrl, setRenderAll, void, (bool autoRemove), , "(bool renderAll)"
  1084. "Set whether or not a position should be rendered on every point or just the last selected."
  1085. "@return No return value.")
  1086. {
  1087. object->setRenderAll(autoRemove);
  1088. }
  1089. DefineConsoleMethod(GuiParticleGraphCtrl, setPointXMovementClamped, void, (bool autoRemove), , "(bool clamped)"
  1090. "Set whether the x position of the selected graph point should be clamped"
  1091. "@return No return value.")
  1092. {
  1093. object->setPointXMovementClamped(autoRemove);
  1094. }
  1095. DefineConsoleMethod(GuiParticleGraphCtrl, setRenderGraphTooltip, void, (bool autoRemove), , "(bool renderGraphTooltip)"
  1096. "Set whether or not to render the graph tooltip."
  1097. "@return No return value.")
  1098. {
  1099. object->setRenderGraphTooltip(autoRemove);
  1100. }
  1101. DefineConsoleMethod(GuiParticleGraphCtrl, setGraphName, void, (S32 plotID, const char * graphName), , "(int plotID, string graphName) "
  1102. "Set the name of the given plot.\n"
  1103. "@param plotID The plot to modify.\n"
  1104. "@param graphName The name to set on the plot.\n"
  1105. "@return No return value.")
  1106. {
  1107. if(plotID > object->MaxPlots)
  1108. {
  1109. Con::errorf("Invalid plotID.");
  1110. return;
  1111. }
  1112. object->setGraphName(plotID, graphName);
  1113. }
  1114. DefineConsoleMethod(GuiParticleGraphCtrl, resetSelectedPoint, void, (), , "()"
  1115. "This will reset the currently selected point to nothing."
  1116. "@return No return value.")
  1117. {
  1118. object->resetSelectedPoint();
  1119. }