Entropy Piano Tuner  1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
drawerbase.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2015 Haye Hinrichsen, Christoph Wick
3  *
4  * This file is part of Entropy Piano Tuner.
5  *
6  * Entropy Piano Tuner is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * Entropy Piano Tuner is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * Entropy Piano Tuner. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
20 //=============================================================================
21 // Drawer base class
22 //=============================================================================
23 
24 #include "drawerbase.h"
25 
26 //-----------------------------------------------------------------------------
27 // Constructor
28 //-----------------------------------------------------------------------------
29 
36 
37 DrawerBase::DrawerBase (GraphicsViewAdapter *graphics, double intervall)
38  : mGraphics(graphics),
39  mTimeLastDrawn(std::chrono::high_resolution_clock::now()),
40  mRedrawIntervalInSecs(intervall)
41 {
42 }
43 
44 
45 //-----------------------------------------------------------------------------
46 // Redraw
47 //-----------------------------------------------------------------------------
48 
56 
57 void DrawerBase::redraw (bool force)
58 {
59  if (requestRedraw(force))
60  {
61  mGraphics->clear();
62  draw();
63  }
64 }
65 
66 
67 //-----------------------------------------------------------------------------
68 // Check for redrawing. If true, set redraw timer to zero
69 //-----------------------------------------------------------------------------
70 
80 
81 bool DrawerBase::requestRedraw (bool force)
82 {
83  auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>
84  (std::chrono::high_resolution_clock::now() - mTimeLastDrawn);
85 
86  if (force or elapsed.count() >= mRedrawIntervalInSecs * 1000)
87  {
88  mTimeLastDrawn = std::chrono::high_resolution_clock::now();
89  return true;
90  }
91  return false;
92 }
93 
system_time_point mTimeLastDrawn
Timeposition when last drawn.
Definition: drawerbase.h:57
virtual void draw()=0
Abstract function : draw the content.
GraphicsViewAdapter * mGraphics
Pointer to the graphics view adapter.
Definition: drawerbase.h:53
bool requestRedraw(bool force=false)
Check whether the content has to be redrawn.
Definition: drawerbase.cpp:81
void redraw(bool force=false)
Function to completely redraw the scene.
Definition: drawerbase.cpp:57
double mRedrawIntervalInSecs
Update time.
Definition: drawerbase.h:58
Abstract base class for implementations rendering graphics.
DrawerBase(GraphicsViewAdapter *graphics, double intervall=1.0/24.0)
Constructor of a drawer.
Definition: drawerbase.cpp:37
virtual void clear()
Clear the graphics panel.