2007-11-04 03:51:54 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant 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 General Public License for more details.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GtkRadiant; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DESCRIPTION:
|
|
|
|
// implementation of IMessaging specific interface
|
2012-03-17 20:01:54 +00:00
|
|
|
//
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
CPtrArray l_Listeners[RADIANT_MSGCOUNT];
|
|
|
|
CPtrArray l_WindowListeners;
|
|
|
|
CXYWndWrapper l_XYWndWrapper;
|
|
|
|
|
|
|
|
// CGtkWindow implementation -------------------------------------
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void button_press( GtkWidget *widget, GdkEventButton *event, gpointer data ){
|
|
|
|
IWindowListener *pListen = static_cast<IWindowListener *>( data );
|
|
|
|
switch ( event->button )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
pListen->OnLButtonDown( event->state, event->x, event->y ); break;
|
|
|
|
case 3:
|
|
|
|
pListen->OnRButtonDown( event->state, event->x, event->y ); break;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void button_release( GtkWidget *widget, GdkEventButton *event, gpointer data ){
|
|
|
|
IWindowListener *pListen = static_cast<IWindowListener *>( data );
|
|
|
|
switch ( event->button )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
pListen->OnLButtonUp( event->state, event->x, event->y ); break;
|
|
|
|
case 3:
|
|
|
|
pListen->OnRButtonUp( event->state, event->x, event->y ); break;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void motion( GtkWidget *widget, GdkEventMotion *event, gpointer data ){
|
|
|
|
IWindowListener *pListen = static_cast<IWindowListener *>( data );
|
|
|
|
pListen->OnMouseMove( event->state, event->x, event->y );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static gint expose( GtkWidget *widget, GdkEventExpose *event, gpointer data ){
|
|
|
|
if ( event->count > 0 ) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
CGtkWindow *pWindow = static_cast<CGtkWindow *>( data );
|
|
|
|
pWindow->DoExpose();
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
return TRUE;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// we use the string versions of the keys for now..
|
2012-03-17 20:01:54 +00:00
|
|
|
static gint keypress( GtkWidget* widget, GdkEventKey* event, gpointer data ){
|
|
|
|
gint ret;
|
|
|
|
|
|
|
|
IWindowListener *pListen = static_cast<IWindowListener *>( data );
|
|
|
|
ret = pListen->OnKeyPressed( gdk_keyval_name( event->keyval ) );
|
|
|
|
if ( ret ) {
|
2017-03-15 10:58:36 +00:00
|
|
|
g_signal_stop_emission_by_name( widget, "key-press-event" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
return ret;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// close_widget is not hooked on the listener but on the CGtkWindow object to handle the closure
|
2012-03-17 20:01:54 +00:00
|
|
|
static gint close_widget( GtkWidget *widget, GdkEvent* event, gpointer data ){
|
|
|
|
CGtkWindow *pWindow = static_cast<CGtkWindow *>( data );
|
|
|
|
pWindow->Close();
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
return TRUE;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void CGtkWindow::DoExpose(){
|
|
|
|
gtk_glwidget_make_current( m_pGLWidget );
|
|
|
|
if ( m_pListen->Paint() ) {
|
|
|
|
gtk_glwidget_swap_buffers( m_pGLWidget );
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void CGtkWindow::Redraw(){
|
|
|
|
gtk_widget_queue_draw( m_pGLWidget );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void CGtkWindow::Close(){
|
|
|
|
// similar to a destructor, except we warn first
|
|
|
|
m_pListen->Close();
|
|
|
|
m_pListen->DecRef(); m_pListen = NULL;
|
|
|
|
gtk_widget_destroy( m_pWnd ); m_pWnd = NULL;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool CGtkWindow::Show(){
|
|
|
|
// check we got everything and are reading to instanciate
|
|
|
|
if ( m_nWidthParam == 0 || m_nHeightParam == 0 ) {
|
|
|
|
Sys_FPrintf( SYS_ERR, "Height and Width params not set in CGtkWindow::Show\n" );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ( !m_pListen ) {
|
|
|
|
Sys_FPrintf( SYS_ERR, "No listener set in CGtkWindow::Show\n" );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// seems all good, here we go
|
|
|
|
m_pWnd = gtk_window_new( GTK_WINDOW_TOPLEVEL );
|
|
|
|
gtk_window_set_title( GTK_WINDOW( m_pWnd ), m_Name.GetBuffer() );
|
|
|
|
gtk_window_set_default_size( GTK_WINDOW( m_pWnd ), m_nWidthParam, m_nHeightParam );
|
|
|
|
gtk_widget_show( m_pWnd );
|
|
|
|
|
|
|
|
// GL widget creation
|
|
|
|
m_pGLWidget = gtk_glwidget_new( FALSE, g_qeglobals_gui.d_glBase );
|
|
|
|
|
|
|
|
gtk_widget_set_events( m_pGLWidget, GDK_DESTROY | GDK_EXPOSURE_MASK | GDK_KEY_PRESS_MASK |
|
|
|
|
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK );
|
|
|
|
|
|
|
|
// Connect signal handlers
|
2017-03-15 10:58:36 +00:00
|
|
|
g_signal_connect( G_OBJECT( m_pGLWidget ), "expose-event", G_CALLBACK( expose ), this );
|
|
|
|
g_signal_connect( G_OBJECT( m_pGLWidget ), "motion-notify-event",
|
|
|
|
G_CALLBACK( motion ), m_pListen );
|
|
|
|
g_signal_connect( G_OBJECT( m_pGLWidget ), "button-press-event",
|
|
|
|
G_CALLBACK( button_press ), m_pListen );
|
|
|
|
g_signal_connect( G_OBJECT( m_pGLWidget ), "button-release-event",
|
|
|
|
G_CALLBACK( button_release ), m_pListen );
|
|
|
|
|
|
|
|
g_signal_connect( G_OBJECT( m_pWnd ), "delete-event", G_CALLBACK( close_widget ), this );
|
|
|
|
g_signal_connect( G_OBJECT( m_pWnd ), "key-press-event",
|
|
|
|
G_CALLBACK( keypress ), m_pListen );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
gtk_widget_show( m_pGLWidget );
|
|
|
|
gtk_container_add( GTK_CONTAINER( m_pWnd ), m_pGLWidget );
|
|
|
|
|
|
|
|
return true;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
IWindow* WINAPI QERApp_CreateGLWindow(){
|
|
|
|
return new CGtkWindow;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void WINAPI QERApp_HookWindow( IWindowListener* pListen ){
|
|
|
|
l_WindowListeners.Add( pListen );
|
|
|
|
pListen->IncRef();
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void WINAPI QERApp_UnHookWindow( IWindowListener* pListen ){
|
|
|
|
for ( int i = 0; i < l_WindowListeners.GetSize(); i++ )
|
|
|
|
{
|
|
|
|
if ( l_WindowListeners.GetAt( i ) == pListen ) {
|
|
|
|
l_WindowListeners.RemoveAt( i );
|
|
|
|
pListen->DecRef();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
#ifdef _DEBUG
|
2016-05-16 19:20:20 +00:00
|
|
|
Sys_FPrintf( SYS_WRN, "WARNING: IWindowListener not found in QERApp_UnHookWindow\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DispatchOnMouseMove( guint32 nFlags, int x, int y ){
|
|
|
|
for ( int i = 0; i < l_WindowListeners.GetSize(); i++ )
|
|
|
|
static_cast<IWindowListener*>( l_WindowListeners.GetAt( i ) )->OnMouseMove( nFlags, x, y );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool DispatchOnLButtonDown( guint32 nFlags, int x, int y ){
|
|
|
|
for ( int i = 0; i < l_WindowListeners.GetSize(); i++ )
|
|
|
|
if ( static_cast<IWindowListener*>( l_WindowListeners.GetAt( i ) )->OnLButtonDown( nFlags, x, y ) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool DispatchOnLButtonUp( guint32 nFlags, int x, int y ){
|
|
|
|
for ( int i = 0; i < l_WindowListeners.GetSize(); i++ )
|
|
|
|
if ( static_cast<IWindowListener*>( l_WindowListeners.GetAt( i ) )->OnLButtonUp( nFlags, x, y ) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void WINAPI QERApp_HookListener( IListener* pListen, int Msg ){
|
2007-11-04 03:51:54 +00:00
|
|
|
#ifdef _DEBUG
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( Msg >= RADIANT_MSGCOUNT ) {
|
2016-05-16 19:20:20 +00:00
|
|
|
Sys_FPrintf( SYS_ERR, "ERROR: bad index in QERApp_HookListener\n" );
|
2012-03-17 20:01:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
#endif
|
2012-03-17 20:01:54 +00:00
|
|
|
l_Listeners[Msg].Add( pListen );
|
|
|
|
pListen->IncRef();
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int WINAPI QERApp_UnHookListener( IListener* pListen ){
|
|
|
|
int count = 0;
|
|
|
|
for ( int i = 0; i < RADIANT_MSGCOUNT; i++ )
|
|
|
|
for ( int j = 0; j < l_Listeners[i].GetSize(); j++ )
|
|
|
|
if ( l_Listeners[i].GetAt( j ) == pListen ) {
|
|
|
|
l_Listeners[i].RemoveAt( j );
|
|
|
|
pListen->DecRef();
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
return count;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DispatchRadiantMsg( int Msg ){
|
2007-11-04 03:51:54 +00:00
|
|
|
#ifdef _DEBUG
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( Msg >= RADIANT_MSGCOUNT ) {
|
2016-05-16 19:20:20 +00:00
|
|
|
Sys_FPrintf( SYS_ERR, "ERROR: bad index in DispatchRadiantMsg\n" );
|
2012-03-17 20:01:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
#endif
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( int i = 0; i < l_Listeners[Msg].GetSize(); i++ )
|
|
|
|
static_cast<IListener *>( l_Listeners[Msg].GetAt( i ) )->DispatchRadiantMsg( Msg );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void CXYWndWrapper::SnapToGrid( int x1, int y1, vec3_t pt ){
|
|
|
|
int height = g_pParentWnd->ActiveXY()->GetWidget()->allocation.height;
|
|
|
|
g_pParentWnd->ActiveXY()->SnapToPoint( x1, height - 1 - y1, pt );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
VIEWTYPE CXYWndWrapper::GetViewType( void ){
|
|
|
|
return (VIEWTYPE)g_pParentWnd->ActiveXY()->GetViewType();
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
IXYWndWrapper* WINAPI QERApp_GetXYWndWrapper(){
|
|
|
|
return &l_XYWndWrapper;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|