Board.bf 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using Beefy;
  3. using Beefy.gfx;
  4. using Beefy.widgets;
  5. using Beefy.geom;
  6. using System.Collections;
  7. using Beefy.utils;
  8. using System.Diagnostics;
  9. using Beefy.theme.dark;
  10. using Beefy.events;
  11. namespace MemProfiler
  12. {
  13. class Board : Widget
  14. {
  15. DarkListView mListView;
  16. DarkButton mGetButton;
  17. public this()
  18. {
  19. mListView = new DarkListView();
  20. AddWidget(mListView);
  21. mListView.AddColumn(200, "Name");
  22. mListView.AddColumn(200, "Self");
  23. mListView.AddColumn(200, "Total");
  24. mListView.InitScrollbars(false, true);
  25. mGetButton = (DarkButton)DarkTheme.sDarkTheme.CreateButton(this, "Get", 0, 0, 0, 0);
  26. mGetButton.mMouseClickHandler.Add(new (evt) => { GetData(); });
  27. }
  28. public override void Resize(float x, float y, float width, float height)
  29. {
  30. base.Resize(x, y, width, height);
  31. mListView.Resize(x, y, width, height - 20);
  32. mGetButton.Resize(20, mHeight - 20, 128, 20);
  33. }
  34. public override void Draw(Graphics g)
  35. {
  36. base.Draw(g);
  37. g.DrawBox(DarkTheme.sDarkTheme.GetImage(DarkTheme.ImageIdx.Bkg), 0, 0, mWidth, mHeight);
  38. g.SetFont(DarkTheme.sDarkTheme.mSmallFont);
  39. g.DrawString(StackStringFormat!("FPS: {0}", gApp.mLastFPS), mWidth - 128, mHeight - 18);
  40. g.FillRect(mUpdateCnt % 200 + 200, mHeight - 2, 2, 2);
  41. }
  42. void ValueClicked(MouseEvent theEvent)
  43. {
  44. DarkListViewItem clickedItem = (DarkListViewItem)theEvent.mSender;
  45. DarkListViewItem item = (DarkListViewItem)clickedItem.GetSubItem(0);
  46. mListView.GetRoot().SelectItemExclusively(item);
  47. mListView.SetFocus();
  48. }
  49. void GetData()
  50. {
  51. //const char* cmd = "Get";
  52. //DWORD bytesRead = 0;
  53. mListView.GetRoot().Clear();
  54. String pipeName = scope String();
  55. pipeName.FormatInto(@"\\.\pipe\HeapDbg_{0}", gApp.mProcessInformation.mProcessId);
  56. String cmd = "Get";
  57. char8[] charData = new char8[16*1024*1024];
  58. defer delete charData;
  59. int32 bytesRead = 0;
  60. if (Windows.CallNamedPipeA(pipeName, (void*)cmd, (int32)cmd.Length, (void*)charData.CArray(), (int32)charData.Count, &bytesRead, 0))
  61. {
  62. String data = scope String();
  63. data.Reference(charData.CArray(), bytesRead, charData.Count);
  64. ListViewItem curItem = mListView.GetRoot();
  65. for (var lineView in data.Split('\n'))
  66. {
  67. String lineViewStr = scope String(lineView);
  68. if (lineViewStr == "-")
  69. {
  70. curItem = curItem.mParentItem;
  71. }
  72. else
  73. {
  74. var childItem = curItem.CreateChildItem();
  75. childItem.mMouseDownHandler.Add(new => ValueClicked);
  76. int32 idx = 0;
  77. for (var dataStr in lineViewStr.Split('\t'))
  78. {
  79. if (idx == 0)
  80. childItem.Label = scope String(dataStr);
  81. else
  82. {
  83. var subItem = childItem.CreateSubItem(idx);
  84. subItem.Label = scope String(dataStr);
  85. subItem.mMouseDownHandler.Add(new => ValueClicked);
  86. }
  87. idx++;
  88. }
  89. curItem = childItem;
  90. }
  91. }
  92. //tree->InsertItem()
  93. }
  94. }
  95. }
  96. }