Minsky
windowInformation.h
Go to the documentation of this file.
1 /*
2  @copyright Steve Keen 2021
3  @author Janak Porwal
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 WINDOW_INFORMATION_H
21 #define WINDOW_INFORMATION_H
22 
23 #include <cairoSurfaceImage.h>
24 #if defined(CAIRO_HAS_WIN32_SURFACE) && !defined(__CYGWIN__)
25 #define USE_WIN32_SURFACE
26 #include <windows.h>
27 #include <wingdi.h>
28 #elif defined(MAC_OSX_TK)
29 #include "getContext.h"
30 #elif defined(CAIRO_HAS_XLIB_SURFACE)
31 #define USE_X11
32 #include <cairo/cairo-xlib.h>
33 #include <X11/Xlib.h>
34 #endif
35 
36 #include <atomic>
37 #include <functional>
38 #include <mutex>
39 #include <future>
40 #include <thread>
41 
42 namespace minsky
43 {
44  struct Winfo
45  {
46 #ifdef USE_WIN32_SURFACE
47  HWND parentWindowId, childWindowId;
48  HBITMAP hbmMem; // backing buffer pixmap
49  HDC hdcMem; // backing buffer bitmap device context
50  HANDLE hOld; //
51 #elif defined(MAC_OSX_TK)
52  NSContext nsContext;
53  Winfo(NSContext&& nsContext): nsContext(std::move(nsContext)) {}
54 #elif defined(USE_X11)
55  Window parentWindowId;
56  Window childWindowId, bufferWindowId;
57 
58  Display* display; // Weak reference, returned by system
59  GC graphicsContext;
60  XWindowAttributes wAttr;
61 #endif
65  int offsetTop;
66  };
67 
68  class WindowInformation: public Winfo
69  {
70  friend class RenderNativeWindow;
71 #if defined(MAC_OSX_TK)
72  friend struct NSContext;
73 #elif defined(USE_X11)
74  struct EventThread: public Winfo, public std::thread
75  {
76  void run();
77  EventThread(const Winfo& w): Winfo(w), thread([this]{run();}) {}
78  ~EventThread() {XDestroyWindow(display, childWindowId); join();}
79  };
80 
81  std::unique_ptr<EventThread> eventThread;
82 #endif
83 
84  public:
85 
86  const bool hasScrollBars=false;
87  ecolab::cairo::SurfacePtr bufferSurface;
88  std::function<void()> draw;
89  void copyBufferToMain();
90 
91  public:
93  // TODO refactor all these classes to avoid this dependency inversion
94  WindowInformation(uint64_t parentWin, int left, int top, int cWidth, int cHeight,double scalingFactor,bool hasScrollBars,const std::function<void()>& draw);
95 
96  const ecolab::cairo::SurfacePtr& getBufferSurface() const;
97  void requestRedraw();
98 
99  WindowInformation(const WindowInformation&)=delete;
100  void operator=(const WindowInformation&)=delete;
101  };
102 } // namespace minsky
103 
104 #endif
const ecolab::cairo::SurfacePtr & getBufferSurface() const
ecolab::cairo::SurfacePtr bufferSurface
WindowInformation(uint64_t parentWin, int left, int top, int cWidth, int cHeight, double scalingFactor, bool hasScrollBars, const std::function< void()> &draw)
void operator=(const WindowInformation &)=delete
Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky&#39;s state cha...
Definition: constMap.h:22
std::function< void()> draw