guiParticleGraphCtrl.cpp 40 KB

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