easy_frame_rate_viewer.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /************************************************************************
  2. * file name : easy_frame_rate_viewer.cpp
  3. * ----------------- :
  4. * creation time : 2017/04/02
  5. * author : Victor Zarubkin
  6. * email : [email protected]
  7. * ----------------- :
  8. * description : This file contains declaration of EasyFrameRateViewer widget.
  9. * ----------------- :
  10. * change log : * 2017/04/02 Victor Zarubkin: Initial commit.
  11. * :
  12. * : *
  13. * ----------------- :
  14. * license : Lightweight profiler library for c++
  15. * : Copyright(C) 2016-2017 Sergey Yagovtsev, Victor Zarubkin
  16. * :
  17. * : Licensed under either of
  18. * : * MIT license (LICENSE.MIT or http://opensource.org/licenses/MIT)
  19. * : * Apache License, Version 2.0, (LICENSE.APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  20. * : at your option.
  21. * :
  22. * : The MIT License
  23. * :
  24. * : Permission is hereby granted, free of charge, to any person obtaining a copy
  25. * : of this software and associated documentation files (the "Software"), to deal
  26. * : in the Software without restriction, including without limitation the rights
  27. * : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  28. * : of the Software, and to permit persons to whom the Software is furnished
  29. * : to do so, subject to the following conditions:
  30. * :
  31. * : The above copyright notice and this permission notice shall be included in all
  32. * : copies or substantial portions of the Software.
  33. * :
  34. * : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  35. * : INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  36. * : PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  37. * : LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  38. * : TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  39. * : USE OR OTHER DEALINGS IN THE SOFTWARE.
  40. * :
  41. * : The Apache License, Version 2.0 (the "License")
  42. * :
  43. * : You may not use this file except in compliance with the License.
  44. * : You may obtain a copy of the License at
  45. * :
  46. * : http://www.apache.org/licenses/LICENSE-2.0
  47. * :
  48. * : Unless required by applicable law or agreed to in writing, software
  49. * : distributed under the License is distributed on an "AS IS" BASIS,
  50. * : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  51. * : See the License for the specific language governing permissions and
  52. * : limitations under the License.
  53. ************************************************************************/
  54. #ifndef EASY__FRAME_RATE_VIEWER__H
  55. #define EASY__FRAME_RATE_VIEWER__H
  56. #include <QGraphicsView>
  57. #include <QGraphicsItem>
  58. #include <QTimer>
  59. #include <vector>
  60. #include <deque>
  61. #include <easy/profiler.h>
  62. //////////////////////////////////////////////////////////////////////////
  63. class EasyFPSGraphicsItem : public QGraphicsItem
  64. {
  65. typedef QGraphicsItem Parent;
  66. typedef EasyFPSGraphicsItem This;
  67. typedef std::deque<std::pair<uint32_t, uint32_t> > FrameTimes;
  68. std::vector<QPointF> m_points1, m_points2;
  69. FrameTimes m_frames;
  70. QRectF m_boundingRect;
  71. public:
  72. explicit EasyFPSGraphicsItem();
  73. virtual ~EasyFPSGraphicsItem();
  74. QRectF boundingRect() const override;
  75. void paint(QPainter* _painter, const QStyleOptionGraphicsItem* _option, QWidget* _widget = nullptr) override;
  76. void setBoundingRect(const QRectF& _boundingRect);
  77. void setBoundingRect(qreal x, qreal y, qreal w, qreal h);
  78. void clear();
  79. void addPoint(uint32_t _maxFrameTime, uint32_t _avgFrameTime);
  80. }; // END of class EasyFPSGraphicsItem.
  81. //////////////////////////////////////////////////////////////////////////
  82. class EasyFrameRateViewer : public QGraphicsView
  83. {
  84. Q_OBJECT
  85. private:
  86. typedef QGraphicsView Parent;
  87. typedef EasyFrameRateViewer This;
  88. EasyFPSGraphicsItem* m_fpsItem;
  89. public:
  90. explicit EasyFrameRateViewer(QWidget* _parent = nullptr);
  91. virtual ~EasyFrameRateViewer();
  92. void resizeEvent(QResizeEvent* _event) override;
  93. void hideEvent(QHideEvent* _event) override;
  94. void showEvent(QShowEvent* _event) override;
  95. void contextMenuEvent(QContextMenuEvent* _event) override;
  96. public slots:
  97. void clear();
  98. void addPoint(uint32_t _maxFrameTime, uint32_t _avgFrameTime);
  99. }; // END of class EasyFrameRateViewer.
  100. //////////////////////////////////////////////////////////////////////////
  101. #endif // EASY__FRAME_RATE_VIEWER__H