29 GX::Window(m_base_display,dx,dy,m_base_display.white(),config.m_title) ,
30 m_xloop(m_base_xloop) ,
31 m_window_handler(window_handler) ,
36 m_mask(dx,dy,m_config.m_mask_file)
38 G_DEBUG(
"Gv::ViewerWindowX::ctor: window-fd=" <<
windowDisplay().fd() ) ;
51 m_xloop.runUntil( MapNotify ) ;
54 void Gv::ViewerWindowX::onChar(
char c )
56 m_window_handler.onChar( c ) ;
59 void Gv::ViewerWindowX::onLeftMouseButtonDown(
int x ,
int y ,
bool shift ,
bool control )
61 m_window_handler.onMouseButtonDown( x , y , shift , control ) ;
64 void Gv::ViewerWindowX::onLeftMouseButtonUp(
int x ,
int y ,
bool shift ,
bool control )
66 m_window_handler.onMouseButtonUp( x , y , shift , control ) ;
69 void Gv::ViewerWindowX::onMouseMove(
int x ,
int y )
71 m_window_handler.onMouseMove( x , y ) ;
76 const unsigned char * p =
reinterpret_cast<const unsigned char*
>(data_p) ;
77 if( m_mask.empty() && data_channels == 3 )
78 update( m_canvas.dx() , m_canvas.dy() , data_dx , data_dy , p , data_n ) ;
80 update( m_canvas.dx() , m_canvas.dy() , data_dx , data_dy , data_channels , p , data_n ) ;
85 int n = XPending(m_base_display.x()) ;
87 m_xloop.handlePendingEvents() ;
90 void Gv::ViewerWindowX::update(
int x_max ,
int y_max ,
int data_dx ,
int data_dy ,
91 const unsigned char * p ,
size_t data_n )
95 if( !m_canvas.fastable() )
97 update( x_max , y_max , data_dx , data_dy , 3 , p , data_n ) ;
101 G_ASSERT( data_n == static_cast<size_t>(data_dx*data_dy*3) ) ;
102 int y_out = y_max - 1 ;
103 for(
int y = 0 ; y < data_dy && y < y_max ; y++ , y_out-- )
105 for(
int x = 0 ; x < data_dx ; x++ )
107 const unsigned int r = *p++ ;
108 const unsigned int g = *p++ ;
109 const unsigned int b = *p++ ;
112 m_canvas.fastpoint( x , y_out ,
Gr::Colour(r,g,b) ) ;
118 void Gv::ViewerWindowX::update(
int x_max ,
int y_max ,
int data_dx ,
int data_dy ,
int data_channels ,
119 const unsigned char * p ,
size_t data_n )
121 size_t mask_offset = 0U ;
122 int y_out = y_max - 1 ;
123 for(
int y = 0 ; y < data_dy && y < y_max ; y++ , y_out-- )
125 for(
int x = 0 ; x < data_dx ; x++ )
127 const unsigned int r = *p++ ;
128 const unsigned int g = data_channels > 1 ? *p++ : r ;
129 const unsigned int b = data_channels > 2 ? *p++ : r ;
132 if( m_mask.masked( mask_offset++ ) )
133 m_canvas.point( x , y_out ,
Gr::Colour(r>>1,g>>3,b>>3) ) ;
135 m_canvas.point( x , y_out ,
Gr::Colour(r,g,b) ) ;
141 void Gv::ViewerWindowX::onExpose( XExposeEvent & event )
143 G_DEBUG(
"Gv::ViewerWindowX::onExpose: exposed" ) ;
144 if( event.count == 0 )
148 void Gv::ViewerWindowX::readEvent()
150 int n = XEventsQueued( m_base_display.x() , QueuedAlready ) ;
151 G_DEBUG(
"Gv::ViewerWindowX::readEvent: event on xwindow fd: " << n ) ;
153 G_WARNING(
"Gv::ViewerWindowX::readEvent: backlog: " << n ) ;
155 m_xloop.handlePendingEvents() ;
158 void Gv::ViewerWindowX::onException( std::exception & e )
160 G_WARNING(
"Gv::ViewerWindowX::onException: " << e.what() ) ;
ViewerWindowX(ViewerWindowHandler &, ViewerWindowConfig, int dx, int dy)
Constructor.
A simple rgb colour structure.
virtual void dropRead(Descriptor fd)=0
Removes the given event source descriptor from the list of read sources.
A class that encapsulates a network file descriptor and hides knowledge of its o/s-spefific error val...
GX::Display & windowDisplay()
Returns a reference to the display as passed in to the ctor.
virtual void addRead(Descriptor fd, EventHandler &handler)=0
Adds the given event source descriptor and associated handler to the read list.
A configuration structure for Gv::ViewerWindow.
virtual int dy() const override
Override from ViewerWindow.
virtual void init() override
Override from ViewerWindow.
static long events(bool with_mouse_moves)
Returns a default event mask for enableEvents().
virtual ~ViewerWindowX()
Destructor.
virtual void display(int, int, int, const char *, size_t) override
Override from ViewerWindow.
static EventLoop & instance()
Returns a reference to an instance of the class, if any.
A callback interface for Gv::ViewerWindow.
virtual int dx() const override
Override from ViewerWindow.