graph.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. #ifndef _XBOX
  2. #include "graph.h"
  3. #include "..\..\system\datasource\datagraph.h"
  4. extern GUIGraphLine* CopyGraphLineMax;
  5. extern GUIGraphLine* CopyGraphLineMin;
  6. extern bool CopyBooleanRelative;
  7. GraphEditor::GraphEditor ()
  8. {
  9. bRelative = false;
  10. GraphLineMax = NEW GUIGraphLine (Vector (0.0f, 1.0f, 0.0f), Vector(99999.0f, 1.0f, 0.0f));
  11. GraphLineMin = NEW GUIGraphLine (Vector (0.0f), Vector(99999.0f, 0.0f, 0.0f));
  12. GraphLineMax->color = 0xFFFF0000;
  13. GraphLineMin->color = 0xFF0000FF;
  14. pGraphEditor = NULL;
  15. btnMove = NULL;
  16. btnScale = NULL;
  17. btnScaleX = NULL;
  18. btnScaleY = NULL;
  19. btnMoveLineY = NULL;
  20. btnScaleLineY = NULL;
  21. btnScaleLineX = NULL;
  22. btnMoveLineX = NULL;
  23. btnPaste = NULL;
  24. btnCopy = NULL;
  25. btnInsertParabols = NULL;
  26. btnCopyMaxToMin = NULL;
  27. btnCopyMinToMax = NULL;
  28. btnFindZeroAxis = NULL;
  29. PercentGraph = NULL;
  30. }
  31. GraphEditor::~GraphEditor ()
  32. {
  33. delete GraphLineMax;
  34. delete GraphLineMin;
  35. }
  36. void GraphEditor::Release ()
  37. {
  38. delete this;
  39. }
  40. void GraphEditor::BeginEdit (GUIControl* form, DataGraph* EditedGraph)
  41. {
  42. this->EditedGraph = EditedGraph;
  43. pGraphEditor = NEW GUIGraphEditor (form, 0, 30, form->GetDrawRect().w, form->GetDrawRect().h-30);
  44. int btnsHeight = 4;
  45. btnMove = NEW GUIButton(form, 4, btnsHeight, 24, 24);
  46. btnMove->Glyph->Load ("peditor\\move");
  47. btnMove->FontColor = 0xFF000000;
  48. btnMove->pFont->SetSize (16);
  49. btnMove->Down = true;
  50. btnMove->OnMouseClick = (CONTROL_EVENT)&GraphEditor::btnMovePressed;
  51. btnMove->Hint = "Move point";
  52. btnMove->GroupIndex = 1;
  53. btnMove->FlatButton = true;
  54. btnScale = NEW GUIButton(form, 4+27, btnsHeight, 24, 24);
  55. btnScale->Glyph->Load ("peditor\\scale");
  56. btnScale->FontColor = 0xFF000000;
  57. btnScale->pFont->SetSize (16);
  58. btnScale->OnMouseClick = (CONTROL_EVENT)&GraphEditor::btnScalePressed;
  59. btnScale->Hint = "Scale grid";
  60. btnScale->GroupIndex = 1;
  61. btnScale->FlatButton = true;
  62. btnScaleX = NEW GUIButton(form, 4+(27*2), btnsHeight, 24, 24);
  63. btnScaleX->Glyph->Load ("peditor\\scalex");
  64. btnScaleX->FontColor = 0xFF000000;
  65. btnScaleX->pFont->SetSize (16);
  66. btnScaleX->OnMouseClick = (CONTROL_EVENT)&GraphEditor::btnScaleXPressed;
  67. btnScaleX->Hint = "Scale grid, X-axis";
  68. btnScaleX->GroupIndex = 1;
  69. btnScaleX->FlatButton = true;
  70. btnScaleY = NEW GUIButton(form, 4+(27*3), btnsHeight, 24, 24);
  71. btnScaleY->Glyph->Load ("peditor\\scaley");
  72. btnScaleY->FontColor = 0xFF000000;
  73. btnScaleY->pFont->SetSize (16);
  74. btnScaleY->OnMouseClick = (CONTROL_EVENT)&GraphEditor::btnScaleYPressed;
  75. btnScaleY->Hint = "Scale grid, Y-axis";
  76. btnScaleY->GroupIndex = 1;
  77. btnScaleY->FlatButton = true;
  78. btnMoveLineY = NEW GUIButton(form, 4+(27*4), btnsHeight, 24, 24);
  79. btnMoveLineY->Glyph->Load ("peditor\\movey");
  80. btnMoveLineY->FontColor = 0xFF000000;
  81. btnMoveLineY->pFont->SetSize (16);
  82. btnMoveLineY->OnMouseClick = (CONTROL_EVENT)&GraphEditor::btnMoveYPressed;
  83. btnMoveLineY->Hint = "Move Line, Y-Axis";
  84. btnMoveLineY->GroupIndex = 1;
  85. btnMoveLineY->FlatButton = true;
  86. btnScaleLineY = NEW GUIButton(form, 4+(27*5), btnsHeight, 24, 24);
  87. btnScaleLineY->Glyph->Load ("peditor\\scalegy");
  88. btnScaleLineY->FontColor = 0xFF000000;
  89. btnScaleLineY->pFont->SetSize (16);
  90. btnScaleLineY->OnMouseClick = (CONTROL_EVENT)&GraphEditor::btnScaleLineYPressed;
  91. btnScaleLineY->Hint = "Scale Line, Y-Axis";
  92. btnScaleLineY->GroupIndex = 1;
  93. btnScaleLineY->FlatButton = true;
  94. btnScaleLineX = NEW GUIButton(form, 4+(27*6), btnsHeight, 24, 24);
  95. btnScaleLineX->Glyph->Load ("peditor\\scalegx");
  96. btnScaleLineX->FontColor = 0xFF000000;
  97. btnScaleLineX->pFont->SetSize (16);
  98. btnScaleLineX->OnMouseClick = (CONTROL_EVENT)&GraphEditor::btnScaleLineXPressed;
  99. btnScaleLineX->Hint = "Scale Line, X-Axis";
  100. btnScaleLineX->GroupIndex = 1;
  101. btnScaleLineX->FlatButton = true;
  102. btnMoveLineX = NEW GUIButton(form, 4+(27*7), btnsHeight, 24, 24);
  103. btnMoveLineX->Glyph->Load ("peditor\\movex");
  104. btnMoveLineX->FontColor = 0xFF000000;
  105. btnMoveLineX->pFont->SetSize (16);
  106. btnMoveLineX->OnMouseClick = (CONTROL_EVENT)&GraphEditor::btnMoveXPressed;
  107. btnMoveLineX->Hint = "Move Line, X-Axis";
  108. btnMoveLineX->GroupIndex = 1;
  109. btnMoveLineX->FlatButton = true;
  110. btnCopy = NEW GUIButton(form, 4+(27*8), btnsHeight, 24, 24);
  111. btnCopy->Glyph->Load ("peditor\\copy");
  112. btnCopy->FontColor = 0xFF000000;
  113. btnCopy->pFont->SetSize (16);
  114. btnCopy->OnMousePressed = (CONTROL_EVENT)&GraphEditor::btnCopyPressed;
  115. btnCopy->Hint = "Copy all graph lines";
  116. btnCopy->FlatButton = true;
  117. btnPaste = NEW GUIButton(form, 4+(27*9), btnsHeight, 24, 24);
  118. btnPaste->Glyph->Load ("peditor\\paste");
  119. btnPaste->FontColor = 0xFF000000;
  120. btnPaste->pFont->SetSize (16);
  121. btnPaste->OnMousePressed = (CONTROL_EVENT)&GraphEditor::btnPastePressed;
  122. btnPaste->Hint = "Paste all graph lines";
  123. btnPaste->FlatButton = true;
  124. btnCopyMaxToMin = NEW GUIButton(form, 4+(27*10), btnsHeight, 24, 24);
  125. btnCopyMaxToMin->Glyph->Load ("peditor\\minmax");
  126. btnCopyMaxToMin->Hint = "Copy Blue line to Red line";
  127. btnCopyMaxToMin->FontColor = 0xFF000000;
  128. btnCopyMaxToMin->pFont->SetSize (16);
  129. btnCopyMaxToMin->OnMousePressed = (CONTROL_EVENT)&GraphEditor::btnMax2Min;
  130. btnCopyMaxToMin->FlatButton = true;
  131. btnCopyMinToMax = NEW GUIButton(form, 4+(27*11), btnsHeight, 24, 24);
  132. btnCopyMinToMax->Glyph->Load ("peditor\\maxmin");
  133. btnCopyMinToMax->Hint = "Copy Red line to Blue line";
  134. btnCopyMinToMax->FontColor = 0xFF000000;
  135. btnCopyMinToMax->pFont->SetSize (16);
  136. btnCopyMinToMax->OnMousePressed = (CONTROL_EVENT)&GraphEditor::btnMin2Max;
  137. btnCopyMinToMax->FlatButton = true;
  138. btnFindZeroAxis = NEW GUIButton(form, 4+(27*12), btnsHeight, 24, 24);
  139. btnFindZeroAxis->Glyph->Load ("peditor\\zero");
  140. btnFindZeroAxis->FontColor = 0xFF000000;
  141. btnFindZeroAxis->pFont->SetSize (16);
  142. btnFindZeroAxis->OnMousePressed = (CONTROL_EVENT)&GraphEditor::btnFindZero;
  143. btnFindZeroAxis->Hint = "Find zero axis";
  144. btnFindZeroAxis->FlatButton = true;
  145. btnInsertParabols = NEW GUIButton(form, 4+(27*13), btnsHeight, 24, 24);
  146. btnInsertParabols->Glyph->Load ("peditor\\parabols");
  147. btnInsertParabols->FontColor = 0xFF000000;
  148. btnInsertParabols->pFont->SetSize (16);
  149. btnInsertParabols->OnMousePressed = (CONTROL_EVENT)&GraphEditor::btnInsertParabolsPressed;
  150. btnInsertParabols->Hint = "Insert parabol's";
  151. btnInsertParabols->FlatButton = true;
  152. PercentGraph = NEW GUICheckBox (form, 4+(27*15), btnsHeight, 56, 24);
  153. PercentGraph->ImageChecked->Load ("checked");
  154. PercentGraph->ImageNormal->Load ("normal");
  155. PercentGraph->Caption = "Relative graph";
  156. PercentGraph->OnChange = (CONTROL_EVENT)&GraphEditor::RelativeChanged;
  157. PercentGraph->pFont->SetName("arialcyrsmall");
  158. CreateDataForEdit ();
  159. }
  160. void GraphEditor::CreateDataForEdit ()
  161. {
  162. DWORD n = 0;
  163. pGraphEditor->NegativeValues = EditedGraph->GetNegative();
  164. if (EditedGraph->GetRelative())
  165. {
  166. pGraphEditor->FitViewWidth (0, 100);
  167. pGraphEditor->HorizontalAxeDesc = "Life %";
  168. PercentGraph->Checked = true;
  169. bRelative = true;
  170. } else
  171. {
  172. pGraphEditor->FitViewWidth (0, EditedGraph->GetMaxTime ());
  173. pGraphEditor->HorizontalAxeDesc = "time";
  174. PercentGraph->Checked = false;
  175. bRelative = false;
  176. }
  177. DWORD MaxCount = EditedGraph->GetMaxCount();
  178. GraphLineMax->SetSize(MaxCount);
  179. for (n = 0; n < MaxCount; n++)
  180. {
  181. const GraphVertex& gVrx = EditedGraph->GetMaxVertex(n);
  182. GraphLineMax->Change(n, Vector (gVrx.Time, gVrx.Val, 0.0f));
  183. }
  184. DWORD MinCount = EditedGraph->GetMinCount();
  185. GraphLineMin->SetSize(MinCount);
  186. for (n = 0; n < MinCount; n++)
  187. {
  188. const GraphVertex& gVrx = EditedGraph->GetMinVertex(n);
  189. GraphLineMin->Change(n, Vector (gVrx.Time, gVrx.Val, 0.0f));
  190. }
  191. pGraphEditor->Lines->Add(GraphLineMax);
  192. pGraphEditor->Lines->Add(GraphLineMin);
  193. pGraphEditor->FitViewHeight(pGraphEditor->GetMinValueY(), pGraphEditor->GetMaxValueY());
  194. }
  195. void GraphEditor::EndEdit ()
  196. {
  197. GraphLineMax->SelectedPoint = -1;
  198. GraphLineMin->SelectedPoint = -1;
  199. GraphLineMax->bActive = false;
  200. GraphLineMin->bActive = false;
  201. delete pGraphEditor;
  202. delete btnMove;
  203. delete btnScale;
  204. delete btnScaleX;
  205. delete btnScaleY;
  206. delete btnMoveLineY;
  207. delete btnScaleLineY;
  208. delete btnScaleLineX;
  209. delete btnMoveLineX;
  210. delete btnPaste;
  211. delete btnCopy;
  212. delete btnInsertParabols;
  213. delete btnCopyMaxToMin;
  214. delete btnCopyMinToMax;
  215. delete btnFindZeroAxis;
  216. delete PercentGraph;
  217. pGraphEditor = NULL;
  218. btnMove = NULL;
  219. btnScale = NULL;
  220. btnScaleX = NULL;
  221. btnScaleY = NULL;
  222. btnMoveLineY = NULL;
  223. btnScaleLineY = NULL;
  224. btnScaleLineX = NULL;
  225. btnMoveLineX = NULL;
  226. btnPaste = NULL;
  227. btnCopy = NULL;
  228. btnInsertParabols = NULL;
  229. btnCopyMaxToMin = NULL;
  230. btnCopyMinToMax = NULL;
  231. btnFindZeroAxis = NULL;
  232. PercentGraph = NULL;
  233. }
  234. void _cdecl GraphEditor::btnMovePressed (GUIControl* sender)
  235. {
  236. pGraphEditor->Mode = GEM_EDIT;
  237. }
  238. void _cdecl GraphEditor::btnScalePressed (GUIControl* sender)
  239. {
  240. pGraphEditor->Mode = GEM_SCALE;
  241. }
  242. void _cdecl GraphEditor::btnScaleXPressed (GUIControl* sender)
  243. {
  244. pGraphEditor->Mode = GEM_SCALEX;
  245. }
  246. void _cdecl GraphEditor::btnScaleYPressed (GUIControl* sender)
  247. {
  248. pGraphEditor->Mode = GEM_SCALEY;
  249. }
  250. void _cdecl GraphEditor::btnMoveYPressed (GUIControl* sender)
  251. {
  252. pGraphEditor->Mode = GEM_MOVELINEY;
  253. }
  254. void _cdecl GraphEditor::btnScaleLineXPressed (GUIControl* sender)
  255. {
  256. pGraphEditor->Mode = GEM_SCALELINEX;
  257. }
  258. void _cdecl GraphEditor::btnScaleLineYPressed (GUIControl* sender)
  259. {
  260. pGraphEditor->Mode = GEM_SCALELINEY;
  261. }
  262. void _cdecl GraphEditor::btnMoveXPressed (GUIControl* sender)
  263. {
  264. pGraphEditor->Mode = GEM_MOVELINEX;
  265. }
  266. void _cdecl GraphEditor::btnMin2Max (GUIControl* sender)
  267. {
  268. GraphLineMin->Copy(GraphLineMax);
  269. }
  270. void _cdecl GraphEditor::btnMax2Min (GUIControl* sender)
  271. {
  272. GraphLineMax->Copy(GraphLineMin);
  273. }
  274. void _cdecl GraphEditor::btnFindZero (GUIControl* sender)
  275. {
  276. pGraphEditor->OffsetY = -10;
  277. pGraphEditor->OffsetX = 10;
  278. }
  279. void _cdecl GraphEditor::btnInsertParabolsPressed (GUIControl* sender)
  280. {
  281. GUIGraphLine* GraphLineP = NEW GUIGraphLine (Vector (0.0f, 1.0f, 0.0f), Vector(99999.0f, 1.0f, 0.0f));
  282. float speed = 1.0f;
  283. float starty = GraphLineP->GetPoint(0).y;
  284. float maxy = starty + (10.0f * 10.0f);
  285. float y = 0;
  286. for (int n = 0; n < 10; n++)
  287. {
  288. y = maxy-(starty+((float)(9.0f-n) * (float)(9.0f-n)));
  289. GraphLineP->Insert(n+1, Vector((float)n+1.0f, y, 0.0f));
  290. }
  291. for ( n = 0; n < 10; n++)
  292. {
  293. y = maxy-(starty+((float)n * (float)n));
  294. GraphLineP->Insert(n+11, Vector((float)n+11.0f, y, 0.0f));
  295. }
  296. GraphLineMax->Copy(GraphLineP);
  297. delete GraphLineP;
  298. }
  299. void _cdecl GraphEditor::RelativeChanged (GUIControl* sender)
  300. {
  301. if (PercentGraph->Checked)
  302. {
  303. bRelative = true;
  304. pGraphEditor->FitViewWidth (0, 100);
  305. pGraphEditor->HorizontalAxeDesc = "Life %";
  306. return;
  307. }
  308. bRelative = false;
  309. pGraphEditor->FitViewWidth (0, EditedGraph->GetMaxTime ());
  310. pGraphEditor->HorizontalAxeDesc = "time";
  311. }
  312. void GraphEditor::Apply ()
  313. {
  314. EditedGraph->SetRelative(bRelative);
  315. DWORD n = 0;
  316. DWORD MaxCount = GraphLineMax->GetCount();
  317. DWORD MinCount = GraphLineMin->GetCount();
  318. GraphVertex* pMaxArray = NEW GraphVertex[MaxCount];
  319. GraphVertex* pMinArray = NEW GraphVertex[MinCount];
  320. for (n = 0; n < MaxCount; n++)
  321. {
  322. Vector ptMax = GraphLineMax->GetPoint(n);
  323. pMaxArray[n].Time = ptMax.x;
  324. pMaxArray[n].Val = ptMax.y;
  325. }
  326. for (n = 0; n < MinCount; n++)
  327. {
  328. Vector ptMin = GraphLineMin->GetPoint(n);
  329. pMinArray[n].Time = ptMin.x;
  330. pMinArray[n].Val = ptMin.y;
  331. }
  332. EditedGraph->SetValues(pMinArray, MinCount, pMaxArray, MaxCount);
  333. delete pMaxArray;
  334. delete pMinArray;
  335. }
  336. void _cdecl GraphEditor::btnCopyPressed (GUIControl* sender)
  337. {
  338. CopyGraphLineMax->Copy(GraphLineMax);
  339. CopyGraphLineMin->Copy(GraphLineMin);
  340. CopyBooleanRelative = bRelative;
  341. }
  342. void _cdecl GraphEditor::btnPastePressed (GUIControl* sender)
  343. {
  344. GraphLineMax->Copy(CopyGraphLineMax);
  345. GraphLineMin->Copy(CopyGraphLineMin);
  346. bRelative = CopyBooleanRelative;
  347. }
  348. #endif