Minsky: 3.17.0
renderNativeWindow.h
Go to the documentation of this file.
1 /*
2  @copyright Steve Keen 2021
3  @author Russell Standish
4  This file is part of Minsky.
5 
6  Minsky is free software: you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Minsky is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Minsky. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef RENDER_NATIVE_WINDOW_H
21 #define RENDER_NATIVE_WINDOW_H
22 
23 #include "eventInterface.h"
24 
25 #include <cairoSurfaceImage.h>
26 #include <plot.h>
27 
28 #ifndef CLASSDESC_TYPENAME___std__lock_guard__mutex___
29 #define CLASSDESC_TYPENAME___std__lock_guard__mutex___
30 namespace classdesc
31 {
32  template <> struct tn<std::lock_guard<std::mutex>>
33  {
34  static string name() {return "std::lock_guard<std::mutex>";}
35  };
36 }
37 #endif
38 
39 namespace minsky
40 {
41  class WindowInformation;
42  class RenderNativeWindow : public ecolab::CairoSurface, public EventInterface
43  {
44  public:
45  static ecolab::cairo::Colour backgroundColour;
46 
48  {
49  std::string parentWindowId;
50  double offsetLeft;
51  double offsetTop;
52  double childWidth;
53  double childHeight;
54  double scalingFactor=0;
55  };
56 
57 
58  const RenderFrameArgs& frameArgs() const {return m_frameArgs;}
59 
60  ~RenderNativeWindow() override;
62  virtual void init() {};
63  void renderFrame(const RenderFrameArgs& args);
64  void destroyFrame();
65  void draw();
66  void requestRedraw();
67  // implemented as a free function to avoid Classdesc exposing this to Typescript
68  friend void macOSXRedraw(RenderNativeWindow&,const std::shared_ptr<std::lock_guard<std::mutex>>&);
69  // do not clobber winInfoPtr on load of model
70  RenderNativeWindow& operator=(const RenderNativeWindow& x) {ecolab::CairoSurface::operator=(x); return *this;}
71  RenderNativeWindow()=default;
72  RenderNativeWindow(const RenderNativeWindow&)=default;
73  static double scaleFactor();
75  virtual bool hasScrollBars() const {return false;}
76 
77  private:
79  classdesc::Exclude<std::shared_ptr<WindowInformation>> winInfoPtr;
81 
83  struct CopiableMutux: public std::mutex
84  {
85  CopiableMutux()=default;
87  };
88  classdesc::Exclude<CopiableMutux> drawMutex;
89  };
90 
91  //void macOSXRedraw(RenderNativeWindow&,const std::shared_ptr<std::lock_guard<std::mutex>>&);
92 
93 } // namespace minsky
94 
95 #include "renderNativeWindow.cd"
96 #endif
const RenderFrameArgs & frameArgs() const
friend void macOSXRedraw(RenderNativeWindow &, const std::shared_ptr< std::lock_guard< std::mutex >> &)
STL namespace.
classdesc::Exclude< std::shared_ptr< WindowInformation > > winInfoPtr
classdesc::Exclude< CopiableMutux > drawMutex
virtual bool hasScrollBars() const
return whether this window has scrollbars (needed for MacOSX).
void renderFrame(const RenderFrameArgs &args)
CLASSDESC_ACCESS(RenderNativeWindow)
static ecolab::cairo::Colour backgroundColour
a copiable mutex where each copy has a distinct mutex
virtual void init()
perform any initialisation of any subclasses of this
RenderNativeWindow & operator=(const RenderNativeWindow &x)