Minsky
minsky::RenderNativeWindow Class Reference

#include <renderNativeWindow.h>

Inheritance diagram for minsky::RenderNativeWindow:
Inheritance graph
Collaboration diagram for minsky::RenderNativeWindow:
Collaboration graph

Classes

struct  CopiableMutux
 a copiable mutex where each copy has a distinct mutex More...
 
struct  RenderFrameArgs
 

Public Member Functions

const RenderFrameArgsframeArgs () const
 
 ~RenderNativeWindow () override
 
virtual void init ()
 perform any initialisation of any subclasses of this More...
 
void renderFrame (const RenderFrameArgs &args)
 
void destroyFrame ()
 
void draw ()
 
void requestRedraw ()
 
void macOSXRedraw ()
 
RenderNativeWindowoperator= (const RenderNativeWindow &x)
 
 RenderNativeWindow ()=default
 
 RenderNativeWindow (const RenderNativeWindow &)=default
 
virtual bool hasScrollBars () const
 return whether this window has scrollbars (needed for MacOSX). More...
 
- Public Member Functions inherited from minsky::EventInterface
virtual void mouseDown (float x, float y)
 
virtual void controlMouseDown (float x, float y)
 
virtual void mouseUp (float x, float y)
 
virtual void mouseMove (float x, float y)
 
virtual void zoom (double x, double y, double z)
 
virtual void moveTo (float x, float y)
 move this so that (x,y) is centred More...
 
virtual std::vector< float > position () const
 current centre coordinates More...
 
virtual double zoomFactor () const
 
virtual bool keyPress (const KeyPressArgs &)
 handle key press over current itemFocus, More...
 
virtual bool getItemAt (float x, float y)
 item or wire obtained by get*At() calls More...
 
virtual bool getWireAt (float x, float y)
 item or wire obtained by get*At() calls More...
 

Static Public Member Functions

static double scaleFactor ()
 

Static Public Attributes

static ecolab::cairo::Colour backgroundColour {0.8,0.8,0.8,1}
 

Private Member Functions

 CLASSDESC_ACCESS (RenderNativeWindow)
 

Private Attributes

classdesc::Exclude< std::shared_ptr< WindowInformation > > winInfoPtr
 
RenderFrameArgs m_frameArgs
 
classdesc::Exclude< CopiableMutuxdrawMutex
 

Additional Inherited Members

- Public Attributes inherited from minsky::EventInterface
ItemPtr item
 item or wire obtained by get*At() calls More...
 
WirePtr wire
 item or wire obtained by get*At() calls More...
 

Detailed Description

Definition at line 31 of file renderNativeWindow.h.

Constructor & Destructor Documentation

◆ ~RenderNativeWindow()

minsky::RenderNativeWindow::~RenderNativeWindow ( )
override

Definition at line 72 of file renderNativeWindow.cc.

References pyminsky::minsky.

73  {
74  minsky().nativeWindowsToRedraw.erase(this);
75  }
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51

◆ RenderNativeWindow() [1/2]

minsky::RenderNativeWindow::RenderNativeWindow ( )
default

◆ RenderNativeWindow() [2/2]

minsky::RenderNativeWindow::RenderNativeWindow ( const RenderNativeWindow )
default

Member Function Documentation

◆ CLASSDESC_ACCESS()

minsky::RenderNativeWindow::CLASSDESC_ACCESS ( RenderNativeWindow  )
private

◆ destroyFrame()

void minsky::RenderNativeWindow::destroyFrame ( )

Definition at line 89 of file renderNativeWindow.cc.

Referenced by minsky::GodleyIcon::destroyFrame(), and minsky::PlotWidget::destroyFrame().

89  {
90  const lock_guard lock(drawMutex);
91  winInfoPtr.reset();
92  }
classdesc::Exclude< std::shared_ptr< WindowInformation > > winInfoPtr
classdesc::Exclude< CopiableMutux > drawMutex
Here is the caller graph for this function:

◆ draw()

void minsky::RenderNativeWindow::draw ( )

Definition at line 111 of file renderNativeWindow.cc.

Referenced by minsky::GodleyTableWindow::redraw().

112  {
113  const lock_guard lock(drawMutex);
114  if (!winInfoPtr.get())
115  {
116  return;
117  }
118 
119 #ifdef FPS_PROFILING_ON
120  unsigned long t0_render_start = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
121 #endif
122 
123 
124  auto surfaceToDraw = winInfoPtr->getBufferSurface();
125  if (!surfaceToDraw) return;
126  surfaceToDraw.swap(surface);
127 
128  cairo_reset_clip(surface->cairo());
129  const ecolab::cairo::CairoSave cs(surface->cairo());
130  cairo_set_source_rgba(surface->cairo(), backgroundColour.r,backgroundColour.g,backgroundColour.b,backgroundColour.a);
131  cairo_rectangle(surface->cairo(), 0, 0, winInfoPtr->childWidth, winInfoPtr->childHeight);
132  cairo_fill(surface->cairo());
133  cairo_set_source_rgb(surface->cairo(), 0, 0, 0);
134  redraw(0, 0, winInfoPtr->childWidth, winInfoPtr->childHeight);
135 
136 #ifdef FPS_PROFILING_ON
137  unsigned long t1_png_stream_start = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
138 #endif
139 
140 #ifdef FPS_PROFILING_ON
141  unsigned long t2_window_copy_start = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
142 #endif
143 
144  surfaceToDraw.swap(surface);
145  winInfoPtr->copyBufferToMain();
146 
147 
148 #ifdef FPS_PROFILING_ON
149  unsigned long t3_render_over = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
150 
151  unsigned long windowCopyTime = t3_render_over - t2_window_copy_start;
152  unsigned long pngStreamWriteTime = t2_window_copy_start - t1_png_stream_start;
153  unsigned long totalTime = t3_render_over - t0_render_start;
154 
155  cout << "Rendering Time (ms): " << totalTime << " (total) | " << windowCopyTime << " (window copy) | " << pngStreamWriteTime << " (png stream overhead) " << endl;
156 #endif
157  }
classdesc::Exclude< std::shared_ptr< WindowInformation > > winInfoPtr
classdesc::Exclude< CopiableMutux > drawMutex
static ecolab::cairo::Colour backgroundColour
Here is the caller graph for this function:

◆ frameArgs()

const RenderFrameArgs& minsky::RenderNativeWindow::frameArgs ( ) const
inline

Definition at line 47 of file renderNativeWindow.h.

References m_frameArgs.

47 {return m_frameArgs;}

◆ hasScrollBars()

virtual bool minsky::RenderNativeWindow::hasScrollBars ( ) const
inlinevirtual

return whether this window has scrollbars (needed for MacOSX).

Reimplemented in minsky::Canvas, minsky::GodleyTableWindow, minsky::PhillipsDiagram, minsky::PubTab, and minsky::EquationDisplay.

Definition at line 63 of file renderNativeWindow.h.

63 {return false;}

◆ init()

virtual void minsky::RenderNativeWindow::init ( )
inlinevirtual

perform any initialisation of any subclasses of this

Reimplemented in minsky::PhillipsDiagram.

Definition at line 51 of file renderNativeWindow.h.

51 {};

◆ macOSXRedraw()

void minsky::RenderNativeWindow::macOSXRedraw ( )

Definition at line 94 of file renderNativeWindow.cc.

95  {
96 #ifdef MAC_OSX_TK
97  if (!winInfoPtr.get()) return;
98  winInfoPtr->requestRedraw();
99 #endif
100  }
classdesc::Exclude< std::shared_ptr< WindowInformation > > winInfoPtr

◆ operator=()

RenderNativeWindow& minsky::RenderNativeWindow::operator= ( const RenderNativeWindow x)
inline

Definition at line 58 of file renderNativeWindow.h.

Referenced by minsky::EquationDisplay::operator=().

58 {ecolab::CairoSurface::operator=(x); return *this;}
Here is the caller graph for this function:

◆ renderFrame()

void minsky::RenderNativeWindow::renderFrame ( const RenderFrameArgs args)

Definition at line 77 of file renderNativeWindow.cc.

References minsky::RenderNativeWindow::RenderFrameArgs::childHeight, minsky::RenderNativeWindow::RenderFrameArgs::childWidth, TCLcmd::trap::init, minsky::RenderNativeWindow::RenderFrameArgs::offsetLeft, minsky::RenderNativeWindow::RenderFrameArgs::offsetTop, minsky::RenderNativeWindow::RenderFrameArgs::parentWindowId, and minsky::RenderNativeWindow::RenderFrameArgs::scalingFactor.

78  {
79  {
80  const lock_guard lock(drawMutex);
81  m_frameArgs=args;
82  init();
83  winInfoPtr = std::make_shared<WindowInformation>(stoull(args.parentWindowId), args.offsetLeft, args.offsetTop, args.childWidth, args.childHeight, args.scalingFactor, hasScrollBars(), [this](){draw();});
84  surface.reset(new NativeSurface(*this)); // ensure callback on requestRedraw works
85  }
86  draw();
87  }
classdesc::Exclude< std::shared_ptr< WindowInformation > > winInfoPtr
classdesc::Exclude< CopiableMutux > drawMutex
virtual bool hasScrollBars() const
return whether this window has scrollbars (needed for MacOSX).
virtual void init()
perform any initialisation of any subclasses of this

◆ requestRedraw()

void minsky::RenderNativeWindow::requestRedraw ( )

Definition at line 103 of file renderNativeWindow.cc.

References pyminsky::minsky.

Referenced by minsky::RavelPopup::keyPress(), minsky::RavelPopup::mouseDown(), minsky::RavelPopup::mouseLeave(), minsky::RavelPopup::mouseMove(), minsky::RavelPopup::mouseOver(), minsky::RavelPopup::mouseUp(), and minsky::anonymous_namespace{renderNativeWindow.cc}::NativeSurface::requestRedraw().

104  {
105  if (!winInfoPtr.get()) return;
106  macOSXRedraw();
107  minsky().nativeWindowsToRedraw.insert(this);
108  }
classdesc::Exclude< std::shared_ptr< WindowInformation > > winInfoPtr
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the caller graph for this function:

◆ scaleFactor()

double minsky::RenderNativeWindow::scaleFactor ( )
static

Definition at line 160 of file renderNativeWindow.cc.

161  {
162 #ifdef WIN32
163  DEVICE_SCALE_FACTOR scaleFactor;
164  GetScaleFactorForMonitor(MonitorFromPoint(POINT{0,0}, MONITOR_DEFAULTTOPRIMARY), &scaleFactor);
165  return int(scaleFactor)/100.0;
166 #else
167  return 1;
168 #endif
169  }

Member Data Documentation

◆ backgroundColour

ecolab::cairo::Colour minsky::RenderNativeWindow::backgroundColour {0.8,0.8,0.8,1}
static

Definition at line 34 of file renderNativeWindow.h.

◆ drawMutex

classdesc::Exclude<CopiableMutux> minsky::RenderNativeWindow::drawMutex
private

Definition at line 76 of file renderNativeWindow.h.

◆ m_frameArgs

RenderFrameArgs minsky::RenderNativeWindow::m_frameArgs
private

Definition at line 68 of file renderNativeWindow.h.

Referenced by frameArgs().

◆ winInfoPtr

classdesc::Exclude<std::shared_ptr<WindowInformation> > minsky::RenderNativeWindow::winInfoPtr
private

Definition at line 67 of file renderNativeWindow.h.


The documentation for this class was generated from the following files: