1 // Ryzom Core MMORPG framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "nel3d_widget.h"
21 #include "nel/3d/u_driver.h"
22 #include "nel/3d/text_context.h"
23 #include "nel/3d/driver_user.h"
24 #include "nel/misc/rgba.h"
25 #include "nel/misc/path.h"
31 #include <QResizeEvent>
33 Nel3DWidget::Nel3DWidget( QWidget
*parent
) :
39 // Need to set this attribute with a NULL paintengine returned to Qt
40 // so that we can render the widget normally ourselves, without the image
41 // disappearing when a widget is resized or shown on top of us
42 setAttribute( Qt::WA_PaintOnScreen
, true );
43 setAttribute( Qt::WA_OpaquePaintEvent
, true );
44 setAttribute( Qt::WA_NoSystemBackground
, true );
47 Nel3DWidget::~Nel3DWidget()
51 if( textContext
!= NULL
)
53 driver
->deleteTextContext( textContext
);
63 void Nel3DWidget::init()
65 nlassert( driver
== NULL
);
67 driver
= NL3D::UDriver::createDriver( 0, false, 0 );
68 driver
->setDisplay( winId(), NL3D::UDriver::CMode( width(), height(), 32, true ) );
71 void Nel3DWidget::createTextContext( std::string fontFile
)
80 font
= NLMISC::CPath::lookup( fontFile
);
84 nlinfo( "Font %s cannot be found, cannot create textcontext!", fontFile
.c_str() );
88 if( textContext
!= NULL
)
90 driver
->deleteTextContext( textContext
);
94 textContext
= driver
->createTextContext( font
);
97 void Nel3DWidget::clear()
101 driver
->clearBuffers( NLMISC::CRGBA::Black
);
102 driver
->swapBuffers();
105 void Nel3DWidget::showEvent( QShowEvent
*evnt
)
107 QWidget::showEvent( evnt
);
113 void Nel3DWidget::resizeEvent( QResizeEvent
*evnt
)
115 QWidget::resizeEvent( evnt
);
117 Q_EMIT( evnt
->size().width(), evnt
->size().height() );
120 #if defined ( NL_OS_WINDOWS )
122 typedef bool ( *winProc
)( NL3D::IDriver
*driver
, HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
124 bool Nel3DWidget::winEvent( MSG
*message
, long *result
)
128 NL3D::IDriver
*iDriver
= dynamic_cast< NL3D::CDriverUser
* >( driver
)->getDriver();
129 if( iDriver
!= NULL
)
131 winProc proc
= (winProc
)iDriver
->getWindowProc();
132 return proc( iDriver
, message
->hwnd
, message
->message
, message
->wParam
, message
->lParam
);
139 #elif defined( NL_OS_MAC )
141 typedef bool ( *cocoaProc
)( NL3D::IDriver
*, const void *e
);
143 bool Nel3DWidget::macEvent( EventHandlerCallRef caller
, EventRef event
)
146 nlerror( "You are using QtCarbon! Only QtCocoa supported, please upgrade Qt" );
150 NL3D::IDriver
*iDriver
= dynamic_cast< NL3D::CDriverUser
* >( driver
)->getDriver();
151 if( iDriver
!= NULL
)
153 cocoaProc proc
= ( cocoaProc
)iDriver
->getWindowProc();
154 return proc( iDriver
, event
);
161 #elif defined( NL_OS_UNIX )
163 typedef bool ( *x11Proc
)( NL3D::IDriver
*drv
, XEvent
*e
);
165 bool Nel3DWidget::x11Event( XEvent
*event
)
169 NL3D::IDriver
*iDriver
= dynamic_cast< NL3D::CDriverUser
* >( driver
)->getDriver();
172 x11Proc proc
= ( x11Proc
)iDriver
->getWindowProc();
173 return proc( iDriver
, event
);