Minsky: 3.17.0
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 ()
 
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
 

Friends

void macOSXRedraw (RenderNativeWindow &, const std::shared_ptr< std::lock_guard< std::mutex >> &)
 

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 42 of file renderNativeWindow.h.

Constructor & Destructor Documentation

◆ ~RenderNativeWindow()

minsky::RenderNativeWindow::~RenderNativeWindow ( )
override

Definition at line 74 of file renderNativeWindow.cc.

References pyminsky::minsky.

75  {
76  minsky().nativeWindowsToRedraw.erase(this);
77  }
Minsky & minsky()
global minsky object
Definition: addon.cc:545

◆ 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 91 of file renderNativeWindow.cc.

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

91  {
92  const lock_guard lock(drawMutex);
93  winInfoPtr.reset();
94  }
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 113 of file renderNativeWindow.cc.

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

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

References m_frameArgs.

58 {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 75 of file renderNativeWindow.h.

75 {return false;}

◆ init()

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

perform any initialisation of any subclasses of this

Reimplemented in minsky::PhillipsDiagram.

Definition at line 62 of file renderNativeWindow.h.

62 {};

◆ operator=()

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

Definition at line 70 of file renderNativeWindow.h.

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

70 {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 79 of file renderNativeWindow.cc.

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

80  {
81  {
82  const lock_guard lock(drawMutex);
83  m_frameArgs=args;
84  init();
85  winInfoPtr = std::make_shared<WindowInformation>(stoull(args.parentWindowId), args.offsetLeft, args.offsetTop, args.childWidth, args.childHeight, args.scalingFactor, hasScrollBars(), [this](){draw();});
86  surface.reset(new NativeSurface(*this)); // ensure callback on requestRedraw works
87  }
88  draw();
89  }
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 106 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().

107  {
108  if (!winInfoPtr.get()) return;
109  minsky().nativeWindowsToRedraw.insert(this);
110  }
classdesc::Exclude< std::shared_ptr< WindowInformation > > winInfoPtr
Minsky & minsky()
global minsky object
Definition: addon.cc:545
Here is the caller graph for this function:

◆ scaleFactor()

double minsky::RenderNativeWindow::scaleFactor ( )
static

Definition at line 162 of file renderNativeWindow.cc.

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

Friends And Related Function Documentation

◆ macOSXRedraw

void macOSXRedraw ( RenderNativeWindow window,
const std::shared_ptr< std::lock_guard< std::mutex >> &  lock 
)
friend

Definition at line 96 of file renderNativeWindow.cc.

97  {
98 #ifdef MAC_OSX_TK
99  if (!window.winInfoPtr.get()) return;
100  window.winInfoPtr->lock=lock;
101  window.winInfoPtr->requestRedraw();
102 #endif
103  }

Member Data Documentation

◆ backgroundColour

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

Definition at line 45 of file renderNativeWindow.h.

◆ drawMutex

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

Definition at line 88 of file renderNativeWindow.h.

◆ m_frameArgs

RenderFrameArgs minsky::RenderNativeWindow::m_frameArgs
private

Definition at line 80 of file renderNativeWindow.h.

Referenced by frameArgs().

◆ winInfoPtr

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

Definition at line 79 of file renderNativeWindow.h.

Referenced by minsky::macOSXRedraw().


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