/usr/include/plplot/wxPLplotwindow.h is in libplplot-dev 5.13.0+dfsg-6ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | // Copyright (C) 2015 Phil Rosenberg
// Copyright (C) 2005 Werner Smekal
//
// This file is part of PLplot.
//
// PLplot is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License as published
// by the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// PLplot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with PLplot; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#if !defined ( WXPLPLOTWINDOW_H__INCLUDED_ )
#define WXPLPLOTWINDOW_H__INCLUDED_
#include "plplot.h"
#include "wxPLplotstream.h"
#include <wx/window.h>
#include <wx/dcmemory.h>
#include <wx/dcclient.h>
#include <wx/dcgraph.h>
#include <wx/dcbuffer.h>
// A plplot wxWindow template. To create an actual plplot wxWindow use
// the type of wxWindow you wish to inherit from at the template parameter
// For example to create a plplot wxFrame create a wxPLplotwindow<wxFrame>
// then call the base wxWindow's Create method to initialise.
template <class WXWINDOW>
class wxPLplotwindow : public WXWINDOW
{
public:
wxPLplotwindow( bool useGraphicsContext = true, wxSize clientSize = wxDefaultSize ); //!< Constructor.
virtual ~wxPLplotwindow( void ); //!< Destructor.
void RenewPlot( void ); //!< Redo plot.
bool SavePlot( const wxString& driver, const wxString& filename ); //!< Save plot using a different driver.
wxPLplotstream* GetStream() { return m_created ? &m_stream : NULL; } //!< Get pointer to wxPLplotstream of this widget.
void setUseGraphicsContext( bool useGraphicsContext );
void setCanvasColour( const wxColour &colour );
bool IsReady() { return GetStream() != NULL; }
protected:
virtual void OnPaint( wxPaintEvent& event ); //!< Paint event
virtual void OnSize( wxSizeEvent & event ); //!< Size event
virtual void OnErase( wxEraseEvent &event ); //!< Background erase event
virtual void OnCreate( wxWindowCreateEvent &event ); //!< Window created event
void OnMouse( wxMouseEvent &event ); //!< Mouse events
wxPLplotstream m_stream; //!< The wxPLplotstream which belongs to this plot widget
bool m_created; //!< Flag to indicate the window has been Created
private:
bool m_useGraphicsContext; //!< Flag to indicate whether we should use a wxGCDC
wxBitmap m_bitmap;
// The memory dc and wrapping gc dc for drawing. Note we
//use pointers and reallocate them whenever the bitmap is
//resized because reusing either of these causes problems
//for rendering on a wxGCDC - at least on Windows.
wxMemoryDC *m_memoryDc;
wxSize m_initialSize;
#ifdef wxUSE_GRAPHICS_CONTEXT
wxGCDC *m_gcDc;
#endif
wxColour m_canvasColour;
virtual void OnLocate( const PLGraphicsIn &graphicsIn ){}
};
//! Constructor initialises variables, creates the wxStream and
//! connects methods with events. The WXWINDOW default constructor is
//! used.
//!
template<class WXWINDOW>
wxPLplotwindow<WXWINDOW>::wxPLplotwindow( bool useGraphicsContext, wxSize clientSize )
: m_created( false ), m_initialSize( clientSize )
{
PLPLOT_wxLogDebug( "wxPLplotwindow::wxPLplotwindow" );
m_memoryDc = NULL;
#ifdef wxUSE_GRAPHICS_CONTEXT
m_gcDc = NULL;
// Force initialization of m_useGraphicsContext and
// drawDc when setUseGraphicsContext is called below.
m_useGraphicsContext = !useGraphicsContext;
#endif
setUseGraphicsContext( useGraphicsContext );
m_canvasColour = *wxBLACK;
//We use connect instead of Bind for compatibility with wxWidgets 2.8
//but should move to bind in the future.
WXWINDOW::Connect( wxEVT_SIZE, wxSizeEventHandler( wxPLplotwindow<WXWINDOW>::OnSize ) );
WXWINDOW::Connect( wxEVT_PAINT, wxPaintEventHandler( wxPLplotwindow<WXWINDOW>::OnPaint ) );
WXWINDOW::Connect( wxEVT_ERASE_BACKGROUND, wxEraseEventHandler( wxPLplotwindow<WXWINDOW>::OnErase ) );
WXWINDOW::Connect( wxEVT_CREATE, wxWindowCreateEventHandler( wxPLplotwindow<WXWINDOW>::OnCreate ) );
WXWINDOW::Connect( wxEVT_MOTION, wxMouseEventHandler( wxPLplotwindow<WXWINDOW>::OnMouse ) );
WXWINDOW::Connect( wxEVT_LEFT_UP, wxMouseEventHandler( wxPLplotwindow<WXWINDOW>::OnMouse ) );
WXWINDOW::Connect( wxEVT_MIDDLE_UP, wxMouseEventHandler( wxPLplotwindow<WXWINDOW>::OnMouse ) );
WXWINDOW::Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( wxPLplotwindow<WXWINDOW>::OnMouse ) );
}
//! Destructor - delete the dc and gcdc if needed.
//!
template<class WXWINDOW>
wxPLplotwindow<WXWINDOW>::~wxPLplotwindow( void )
{
if ( m_memoryDc )
delete m_memoryDc;
if ( m_gcDc )
delete m_gcDc;
}
//! In the OnPaint Method we check if the Windows was resized (will be
//! moved to OnSize() sometimes later), we also implement our own
//! double buffering here (since the PLplot wxWidgets driver draws
//! into a wxMemoryDC).
//!
template<class WXWINDOW>
void wxPLplotwindow<WXWINDOW>::OnPaint( wxPaintEvent &WXUNUSED( event ) )
{
//Really this should be in the constructor, but it caused a segfault
//on at least one system (CentOS with intel compiler and wxWidgets 2.8.12).
//Moving it here after WXWINDOW::Create has been called stops this and
//the call does nothing if the style is the same as previous calls so
//should be safe to call here.
//WXWINDOW::SetBackgroundStyle( wxBG_STYLE_CUSTOM );
//wxAutoBufferedPaintDC dc( (WXWINDOW*)this );
int width = WXWINDOW::GetClientSize().GetWidth();
int height = WXWINDOW::GetClientSize().GetHeight();
wxPaintDC paintDc( this );
//resize the plot if needed
bool needResize = width != m_bitmap.GetWidth() || height != m_bitmap.GetHeight();
if ( needResize )
{
m_bitmap.Create( width, height, 32 );
if ( m_memoryDc )
delete m_memoryDc;
m_memoryDc = new wxMemoryDC;
m_memoryDc->SelectObject( m_bitmap );
wxDC *drawDc = m_memoryDc;
#ifdef wxUSE_GRAPHICS_CONTEXT
if ( m_useGraphicsContext )
{
if ( m_gcDc )
delete m_gcDc;
m_gcDc = new wxGCDC( *m_memoryDc );
drawDc = m_gcDc;
}
#endif
if ( IsReady() )
m_stream.SetDC( drawDc );
drawDc->SetBackground( wxBrush( m_canvasColour ) );
drawDc->Clear();
if ( IsReady() )
m_stream.SetSize( width, height );
}
paintDc.Blit( 0, 0, width, height, m_memoryDc, 0, 0 );
}
//! This is called when the plot is resized
//!
template<class WXWINDOW>
void wxPLplotwindow<WXWINDOW>::OnSize( wxSizeEvent& WXUNUSED( event ) )
{
//Invalidate the whole window so it is all redrawn, otherwise only
//newly exposed parts of the window get redrawn
RenewPlot();
}
//! This is called before each paint event
//!
template<class WXWINDOW>
void wxPLplotwindow<WXWINDOW>::OnErase( wxEraseEvent& WXUNUSED( event ) )
{
//Do nothing. This stops screen flicker.
}
//! This is called when the window is created, i.e., after
//! WXWINDOW::Create has been called. We note that this has been
//! called to avoid attempting to redraw a plot on a window that
//! hasn't been created yet.
//!
template<class WXWINDOW>
void wxPLplotwindow<WXWINDOW>::OnCreate( wxWindowCreateEvent &event )
{
PLPLOT_wxLogDebug( "wxPLplotwindow::OnCreate" );
if ( !m_created )
{
//set the client size if requested
if ( m_initialSize != wxDefaultSize )
WXWINDOW::SetClientSize( m_initialSize );
//create the stream
int width = WXWINDOW::GetClientSize().GetWidth();
int height = WXWINDOW::GetClientSize().GetHeight();
m_bitmap.Create( width, height );
if ( m_memoryDc )
delete m_memoryDc;
m_memoryDc = new wxMemoryDC;
m_memoryDc->SelectObject( m_bitmap );
wxDC * drawDc = m_memoryDc;
#ifdef wxUSE_GRAPHICS_CONTEXT
if ( m_useGraphicsContext )
{
if ( m_gcDc )
delete m_gcDc;
m_gcDc = new wxGCDC( *m_memoryDc );
drawDc = m_gcDc;
}
#endif
if ( !m_stream.IsValid() )
m_stream.Create( drawDc, width, height, wxPLPLOT_DRAW_TEXT );
else
m_stream.SetDC( drawDc );
drawDc->SetBackground( wxBrush( m_canvasColour ) );
drawDc->Clear();
m_created = true;
RenewPlot();
}
}
//Capture Mouse events and pass the
template<class WXWINDOW>
void wxPLplotwindow<WXWINDOW>::OnMouse( wxMouseEvent &event )
{
PLGraphicsIn graphicsIn;
wxPoint cursorPosition = event.GetPosition();
wxSize clientSize = WXWINDOW::GetClientSize();
graphicsIn.pX = cursorPosition.x;
graphicsIn.pY = cursorPosition.y;
graphicsIn.dX = PLFLT( cursorPosition.x + 0.5 ) / PLFLT( clientSize.GetWidth() );
graphicsIn.dY = 1.0 - PLFLT( cursorPosition.y + 0.5 ) / PLFLT( clientSize.GetHeight() );
graphicsIn.keysym = 0x20;
graphicsIn.state = 0;
graphicsIn.subwindow = -1;
graphicsIn.type = 0;
graphicsIn.string[0] = '\0';
if ( event.LeftUp() )
{
graphicsIn.button = 1;
graphicsIn.state |= PL_MASK_BUTTON1;
}
else if ( event.MiddleUp() )
{
graphicsIn.button = 2;
graphicsIn.state |= PL_MASK_BUTTON2;
}
else if ( event.RightUp() )
{
graphicsIn.button = 3;
graphicsIn.state |= PL_MASK_BUTTON3;
}
else if ( event.Aux1Up() )
{
graphicsIn.button = 4;
graphicsIn.state |= PL_MASK_BUTTON4;
}
else if ( event.Aux2Up() )
{
graphicsIn.button = 5;
graphicsIn.state |= PL_MASK_BUTTON5;
}
else
{
//If we get here we have just captured motion
//not a click
graphicsIn.button = 0;
graphicsIn.state = 0;
graphicsIn.keysym = 0;
}
if ( wxGetKeyState( WXK_SHIFT ) )
graphicsIn.state |= PL_MASK_SHIFT;
if ( wxGetKeyState( WXK_CAPITAL ) )
graphicsIn.state |= PL_MASK_CAPS;
if ( wxGetKeyState( WXK_ALT ) && wxGetKeyState( WXK_CONTROL ) )
graphicsIn.state |= PL_MASK_ALTGR;
else if ( wxGetKeyState( WXK_CONTROL ) )
graphicsIn.state |= PL_MASK_CONTROL;
else if ( wxGetKeyState( WXK_ALT ) )
graphicsIn.state |= PL_MASK_ALT;
if ( wxGetKeyState( WXK_NUMLOCK ) )
graphicsIn.state |= PL_MASK_NUM;
if ( wxGetKeyState( WXK_SCROLL ) )
graphicsIn.state |= PL_MASK_SCROLL;
//Note I can't find a way to catch the windows key
if ( IsReady() )
m_stream.translatecursor( &graphicsIn );
this->OnLocate( graphicsIn );
}
//! Redo the whole plot, only if the window has been Created
//!
template<class WXWINDOW>
void wxPLplotwindow<WXWINDOW>::RenewPlot( void )
{
if ( m_created )
{
WXWINDOW::Refresh();
}
}
//! Save plot.
//!
template<class WXWINDOW>
bool wxPLplotwindow<WXWINDOW>::SavePlot( const wxString& devname, const wxString& filename )
{
int pls, pls_save;
FILE *sfile;
if ( ( sfile = fopen( filename.mb_str(), "wb+" ) ) == NULL )
{
return false;
}
plgstrm( &pls );
plmkstrm( &pls_save );
if ( pls_save < 0 )
{
fclose( sfile );
return false;
}
plsdev( devname.mb_str() );
plsfile( sfile );
plspage( 0., 0., 800, 600, 0, 0 );
plcpstrm( pls, 0 );
pladv( 0 );
plreplot();
plend1();
plsstrm( pls );
return true;
}
//! Set whether we wish to use wxGCDC instead of a wxDC.
//!
template<class WXWINDOW>
void wxPLplotwindow<WXWINDOW>::setUseGraphicsContext( bool useGraphicsContext )
{
wxDC *drawDc;
#ifdef wxUSE_GRAPHICS_CONTEXT
if ( useGraphicsContext != m_useGraphicsContext )
{
m_useGraphicsContext = useGraphicsContext;
drawDc = m_useGraphicsContext ? (wxDC *) m_gcDc : (wxDC *) m_memoryDc;
}
#else
drawDc = &m_memoryDc;
m_useGraphicsContext = false;
#endif
if ( IsReady() )
{
m_stream.SetDC( drawDc );
RenewPlot();
}
}
template<class WXWINDOW>
void wxPLplotwindow<WXWINDOW>::setCanvasColour( const wxColour &colour )
{
m_canvasColour = colour;
RenewPlot();
}
#endif // !defined( WXPLPLOTWINDOW_H__INCLUDED_ )
|