GTK3 compatibility

This commit is contained in:
Pan7 2017-03-25 07:01:49 +01:00
parent 43e9164c9e
commit 236e9183cb
12 changed files with 60 additions and 36 deletions

View file

@ -0,0 +1,5 @@
#if ! GTK_CHECK_VERSION(3, 0, 0)
# define gtk_widget_get_allocated_height(widget) (((GtkWidget *) (widget))->allocation.height)
# define gtk_widget_get_allocated_width(widget) (((GtkWidget *) (widget))->allocation.width)
#endif

View file

@ -21,6 +21,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "gensurf.h" #include "gensurf.h"
#include "gtkcompat.h"
#undef ISOMETRIC #undef ISOMETRIC
@ -101,7 +102,7 @@ void ShowPreview(){
} }
static void draw_preview(){ static void draw_preview(){
int width = g_pPreviewWidget->allocation.width, height = g_pPreviewWidget->allocation.height; int width = gtk_widget_get_allocated_width( g_pPreviewWidget ), height = gtk_widget_get_allocated_height( g_pPreviewWidget );
g_GLTable.m_pfn_qglClearColor( 0, 0, 0, 1 ); g_GLTable.m_pfn_qglClearColor( 0, 0, 0, 1 );
g_GLTable.m_pfn_qglViewport( 0, 0, width, height ); g_GLTable.m_pfn_qglViewport( 0, 0, width, height );
@ -181,7 +182,7 @@ static gint expose( GtkWidget *widget, GdkEventExpose *event, gpointer data ){
} }
static void button_press( GtkWidget *widget, GdkEventButton *event, gpointer data ){ static void button_press( GtkWidget *widget, GdkEventButton *event, gpointer data ){
POINT pt = { (long)event->x, widget->allocation.height - (long)event->y }; POINT pt = { (long)event->x, gtk_widget_get_allocated_height( widget ) - (long)event->y };
bool Selected; bool Selected;
double x,y; double x,y;
int i, j, k, ks; int i, j, k, ks;
@ -290,7 +291,7 @@ static void button_press( GtkWidget *widget, GdkEventButton *event, gpointer dat
} }
static void motion( GtkWidget *widget, GdkEventMotion *event, gpointer data ){ static void motion( GtkWidget *widget, GdkEventMotion *event, gpointer data ){
POINT pt = { (long)event->x, widget->allocation.height - (long)event->y }; POINT pt = { (long)event->x, gtk_widget_get_allocated_height( widget ) - (long)event->y };
if ( !VertexMode ) { if ( !VertexMode ) {
return; return;

View file

@ -27,6 +27,7 @@
// //
#include "StdAfx.h" #include "StdAfx.h"
#include "gtkcompat.h"
static void dialog_button_callback( GtkWidget *widget, gpointer data ){ static void dialog_button_callback( GtkWidget *widget, gpointer data ){
GtkWidget *parent; GtkWidget *parent;
@ -588,8 +589,8 @@ static gint expose( GtkWidget *widget, GdkEventExpose *event, gpointer data ){
} }
if ( g_bTexViewReady ) { if ( g_bTexViewReady ) {
g_2DView.m_rect.bottom = widget->allocation.height; g_2DView.m_rect.bottom = gtk_widget_get_allocated_height( widget );
g_2DView.m_rect.right = widget->allocation.width; g_2DView.m_rect.right = gtk_widget_get_allocated_width( widget );
if ( !g_QglTable.m_pfn_glwidget_make_current( g_pToolWidget ) ) { if ( !g_QglTable.m_pfn_glwidget_make_current( g_pToolWidget ) ) {
Sys_Printf( "TexTool: glMakeCurrent failed\n" ); Sys_Printf( "TexTool: glMakeCurrent failed\n" );

View file

@ -0,0 +1,5 @@
#if ! GTK_CHECK_VERSION(3, 0, 0)
# define gtk_widget_get_allocated_height(widget) (((GtkWidget *) (widget))->allocation.height)
# define gtk_widget_get_allocated_width(widget) (((GtkWidget *) (widget))->allocation.width)
#endif

View file

@ -26,6 +26,7 @@
// //
#include "stdafx.h" #include "stdafx.h"
#include "gtkcompat.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <GL/gl.h> #include <GL/gl.h>
@ -140,7 +141,7 @@ void update_xor_rectangle( XORRectangle& xor_rectangle ){
} }
void CamWnd::OnMouseMove( guint32 flags, int pointx, int pointy ){ void CamWnd::OnMouseMove( guint32 flags, int pointx, int pointy ){
int height = m_pWidget->allocation.height; int height = gtk_widget_get_allocated_height( m_pWidget );
// NOTE RR2DO2 this hasn't got any use anymore really. It is an old qeradiant feature // NOTE RR2DO2 this hasn't got any use anymore really. It is an old qeradiant feature
// that can be re-enabled by removing the checks for HasCapture and not shift/ctrl down // that can be re-enabled by removing the checks for HasCapture and not shift/ctrl down
// but the scaling/rotating (unless done with the steps set in the surface inspector // but the scaling/rotating (unless done with the steps set in the surface inspector
@ -208,7 +209,7 @@ void CamWnd::OnRButtonUp( guint32 nFlags, int pointx, int pointy ){
} }
void CamWnd::OriginalMouseUp( guint32 nFlags, int pointx, int pointy ){ void CamWnd::OriginalMouseUp( guint32 nFlags, int pointx, int pointy ){
int height = m_pWidget->allocation.height; int height = gtk_widget_get_allocated_height( m_pWidget );
if ( g_qeglobals.d_select_mode == sel_facets_on || g_qeglobals.d_select_mode == sel_facets_off ) { if ( g_qeglobals.d_select_mode == sel_facets_on || g_qeglobals.d_select_mode == sel_facets_off ) {
g_qeglobals.d_select_mode = sel_brush; g_qeglobals.d_select_mode = sel_brush;
@ -221,7 +222,7 @@ void CamWnd::OriginalMouseUp( guint32 nFlags, int pointx, int pointy ){
} }
void CamWnd::OriginalMouseDown( guint32 nFlags, int pointx, int pointy ){ void CamWnd::OriginalMouseDown( guint32 nFlags, int pointx, int pointy ){
int height = m_pWidget->allocation.height; int height = gtk_widget_get_allocated_height( m_pWidget );
SetFocus(); SetFocus();
SetCapture(); SetCapture();

5
radiant/gtkcompat.h Normal file
View file

@ -0,0 +1,5 @@
#if ! GTK_CHECK_VERSION(3, 0, 0)
# define gtk_widget_get_allocated_height(widget) (((GtkWidget *) (widget))->allocation.height)
# define gtk_widget_get_allocated_width(widget) (((GtkWidget *) (widget))->allocation.width)
#endif

View file

@ -40,6 +40,7 @@
#endif #endif
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "gtkcompat.h"
#ifdef _WIN32 #ifdef _WIN32
#include <gdk/gdkwin32.h> #include <gdk/gdkwin32.h>
@ -70,8 +71,8 @@ void save_window_pos( GtkWidget *wnd, window_position_t& pos ){
get_window_pos( wnd, &pos.x, &pos.y ); get_window_pos( wnd, &pos.x, &pos.y );
pos.w = wnd->allocation.width; pos.w = gtk_widget_get_allocated_width( wnd );
pos.h = wnd->allocation.height; pos.h = gtk_widget_get_allocated_height( wnd );
#ifdef DBG_WINDOWPOS #ifdef DBG_WINDOWPOS
//Sys_Printf("save_window_pos 'Window %s'\n",buf); //Sys_Printf("save_window_pos 'Window %s'\n",buf);
@ -94,9 +95,9 @@ void win32_get_window_pos( GtkWidget *widget, gint *x, gint *y ){
*x = point.x; *x = point.x;
*y = point.y; *y = point.y;
*x = max( *x,-widget->allocation.width + 10 ); *x = max( *x,-gtk_widget_get_allocated_width( widget ) + 10 );
*x = min( *x,primaryMonitorRect.width - 10 ); *x = min( *x,primaryMonitorRect.width - 10 );
*y = max( *y,-widget->allocation.height + 10 ); *y = max( *y,-gtk_widget_get_allocated_height( widget ) + 10 );
*y = min( *y,primaryMonitorRect.height - 10 ); *y = min( *y,primaryMonitorRect.height - 10 );
} }
else { else {

View file

@ -39,6 +39,7 @@ extern "C" {
#if defined ( __linux__ ) || defined ( __APPLE__ ) #if defined ( __linux__ ) || defined ( __APPLE__ )
#include <unistd.h> #include <unistd.h>
#endif #endif
#include "gtkcompat.h"
#include "gtkmisc.h" #include "gtkmisc.h"
#include "groupdialog.h" #include "groupdialog.h"
#include "patchdialog.h" #include "patchdialog.h"
@ -2274,9 +2275,9 @@ GtkWidget *watchit = NULL;
void CheckWatchit( char *msg ){ void CheckWatchit( char *msg ){
static int width = 0; static int width = 0;
if ( ( watchit != NULL ) && ( watchit->allocation.width != width ) ) { if ( ( watchit != NULL ) && ( gtk_widget_get_allocated_width( watchit ) != width ) ) {
Sys_Printf( "CheckWatchit %s: %d\n", msg, watchit->allocation.width ); Sys_Printf( "CheckWatchit %s: %d\n", msg, gtk_widget_get_allocated_width( watchit ) );
width = watchit->allocation.width; width = gtk_widget_get_allocated_width( watchit );
} }
} }
#endif #endif

View file

@ -48,6 +48,7 @@
#include "str.h" #include "str.h"
#include "missing.h" #include "missing.h"
#include "texmanip.h" #include "texmanip.h"
#include "gtkcompat.h"
#define TYP_MIPTEX 68 #define TYP_MIPTEX 68
@ -1702,7 +1703,7 @@ void TexWnd::OnExpose() {
else else
{ {
QE_CheckOpenGLForErrors(); QE_CheckOpenGLForErrors();
Texture_Draw( m_pWidget->allocation.width, m_pWidget->allocation.height - g_nTextureOffset ); Texture_Draw( gtk_widget_get_allocated_width( m_pWidget ), gtk_widget_get_allocated_height( m_pWidget ) - g_nTextureOffset );
QE_CheckOpenGLForErrors(); QE_CheckOpenGLForErrors();
SwapBuffers(); SwapBuffers();
} }
@ -1710,8 +1711,8 @@ void TexWnd::OnExpose() {
GtkAdjustment *vadjustment = gtk_range_get_adjustment( GTK_RANGE( g_qeglobals_gui.d_texture_scroll ) ); GtkAdjustment *vadjustment = gtk_range_get_adjustment( GTK_RANGE( g_qeglobals_gui.d_texture_scroll ) );
gtk_adjustment_set_value( vadjustment, -g_qeglobals.d_texturewin.originy ); gtk_adjustment_set_value( vadjustment, -g_qeglobals.d_texturewin.originy );
gtk_adjustment_set_page_size( vadjustment, m_pWidget->allocation.height ); gtk_adjustment_set_page_size( vadjustment, gtk_widget_get_allocated_height( m_pWidget ) );
gtk_adjustment_set_page_increment( vadjustment, m_pWidget->allocation.height / 2 ); gtk_adjustment_set_page_increment( vadjustment, gtk_widget_get_allocated_height( m_pWidget ) / 2 );
gtk_adjustment_set_step_increment( vadjustment, 20 ); gtk_adjustment_set_step_increment( vadjustment, 20 );
gtk_adjustment_set_lower( vadjustment, 0 ); gtk_adjustment_set_lower( vadjustment, 0 );
gtk_adjustment_set_upper( vadjustment, g_qeglobals.d_texturewin.m_nTotalHeight ); gtk_adjustment_set_upper( vadjustment, g_qeglobals.d_texturewin.m_nTotalHeight );
@ -1842,8 +1843,8 @@ void TexWnd::DragDropTexture( guint32 flags, int pointx, int pointy ){
get_window_pos( widget, &x, &y ); get_window_pos( widget, &x, &y );
if ( m_ptX < x || m_ptY < y || if ( m_ptX < x || m_ptY < y ||
m_ptX > x + widget->allocation.width || m_ptX > x + gtk_widget_get_allocated_width( widget ) ||
m_ptY > y + widget->allocation.height ) { m_ptY > y + gtk_widget_get_allocated_height( widget ) ) {
return; return;
} }

View file

@ -26,6 +26,7 @@
// //
#include "stdafx.h" #include "stdafx.h"
#include "gtkcompat.h"
CPtrArray l_Listeners[RADIANT_MSGCOUNT]; CPtrArray l_Listeners[RADIANT_MSGCOUNT];
CPtrArray l_WindowListeners; CPtrArray l_WindowListeners;
@ -230,7 +231,7 @@ void DispatchRadiantMsg( int Msg ){
} }
void CXYWndWrapper::SnapToGrid( int x1, int y1, vec3_t pt ){ void CXYWndWrapper::SnapToGrid( int x1, int y1, vec3_t pt ){
int height = g_pParentWnd->ActiveXY()->GetWidget()->allocation.height; int height = gtk_widget_get_allocated_height( g_pParentWnd->ActiveXY()->GetWidget() );
g_pParentWnd->ActiveXY()->SnapToPoint( x1, height - 1 - y1, pt ); g_pParentWnd->ActiveXY()->SnapToPoint( x1, height - 1 - y1, pt );
} }

View file

@ -26,6 +26,7 @@
// //
#include "stdafx.h" #include "stdafx.h"
#include "gtkcompat.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <assert.h> #include <assert.h>
@ -461,7 +462,7 @@ void CreateEntityFromName( const char* name, const vec3_t origin ){
} }
void CreateRightClickEntity( XYWnd* pWnd, int x, int y, const char* pName ){ void CreateRightClickEntity( XYWnd* pWnd, int x, int y, const char* pName ){
int height = pWnd->GetWidget()->allocation.height; int height = gtk_widget_get_allocated_height( pWnd->GetWidget() );
vec3_t point; vec3_t point;
pWnd->SnapToPoint( x, height - 1 - y, point ); pWnd->SnapToPoint( x, height - 1 - y, point );
@ -1875,19 +1876,19 @@ void XYWnd::XY_MouseMoved( int x, int y, int buttons ){
void XYWnd::OriginalButtonDown( guint32 nFlags, int pointx, int pointy ){ void XYWnd::OriginalButtonDown( guint32 nFlags, int pointx, int pointy ){
SetFocus(); SetFocus();
SetCapture(); SetCapture();
XY_MouseDown( pointx, m_pWidget->allocation.height - 1 - pointy, nFlags ); XY_MouseDown( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, nFlags );
m_nScrollFlags = nFlags; m_nScrollFlags = nFlags;
} }
void XYWnd::OriginalButtonUp( guint32 nFlags, int pointx, int pointy ){ void XYWnd::OriginalButtonUp( guint32 nFlags, int pointx, int pointy ){
XY_MouseUp( pointx, m_pWidget->allocation.height - 1 - pointy, nFlags ); XY_MouseUp( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, nFlags );
ReleaseCapture(); ReleaseCapture();
} }
void XYWnd::DropClipPoint( guint32 nFlags, int pointx, int pointy ){ void XYWnd::DropClipPoint( guint32 nFlags, int pointx, int pointy ){
if ( g_pMovingClip ) { if ( g_pMovingClip ) {
SetCapture(); SetCapture();
SnapToPoint( pointx, m_pWidget->allocation.height - 1 - pointy, *g_pMovingClip ); SnapToPoint( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, *g_pMovingClip );
} }
else else
{ {
@ -1920,7 +1921,7 @@ void XYWnd::DropClipPoint( guint32 nFlags, int pointx, int pointy ){
g_Clip1.m_ptScreenX = pointx; g_Clip1.m_ptScreenX = pointx;
g_Clip1.m_ptScreenY = pointy; g_Clip1.m_ptScreenY = pointy;
} }
SnapToPoint( pointx, m_pWidget->allocation.height - 1 - pointy, *pPt ); SnapToPoint( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, *pPt );
// third coordinates for clip point: use d_work_max // third coordinates for clip point: use d_work_max
// Arnout: changed to use center of selection for clipping, saves level designers moving points all over the map // Arnout: changed to use center of selection for clipping, saves level designers moving points all over the map
// g_pParentWnd->ActiveXY()->GetViewType() // g_pParentWnd->ActiveXY()->GetViewType()
@ -1938,14 +1939,14 @@ void XYWnd::DropClipPoint( guint32 nFlags, int pointx, int pointy ){
void XYWnd::DropPathPoint( guint32 nFlags, int pointx, int pointy ){ void XYWnd::DropPathPoint( guint32 nFlags, int pointx, int pointy ){
if ( g_pMovingPath ) { if ( g_pMovingPath ) {
SetCapture(); SetCapture();
SnapToPoint( pointx, m_pWidget->allocation.height - 1 - pointy, *g_pMovingPath ); SnapToPoint( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, *g_pMovingPath );
} }
else else
{ {
g_PathPoints[g_nPathCount].Set( true ); g_PathPoints[g_nPathCount].Set( true );
g_PathPoints[g_nPathCount].m_ptScreenX = pointx; g_PathPoints[g_nPathCount].m_ptScreenX = pointx;
g_PathPoints[g_nPathCount].m_ptScreenY = pointy; g_PathPoints[g_nPathCount].m_ptScreenY = pointy;
SnapToPoint( pointx, m_pWidget->allocation.height - 1 - pointy, g_PathPoints[g_nPathCount] ); SnapToPoint( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, g_PathPoints[g_nPathCount] );
// third coordinates for dropped point: use d_work_max // third coordinates for dropped point: use d_work_max
// g_pParentWnd->ActiveXY()->GetViewType() // g_pParentWnd->ActiveXY()->GetViewType()
// cf VIEWTYPE definition: enum VIEWTYPE {YZ, XZ, XY}; // cf VIEWTYPE definition: enum VIEWTYPE {YZ, XZ, XY};

View file

@ -27,6 +27,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "zwindow.h" #include "zwindow.h"
#include "gtkcompat.h"
// ============================================================================= // =============================================================================
// ZWnd class // ZWnd class
@ -49,43 +50,43 @@ void ZWnd::OnCreate(){
void ZWnd::OnLButtonDown( guint32 nFlags, int pointx, int pointy ){ void ZWnd::OnLButtonDown( guint32 nFlags, int pointx, int pointy ){
SetFocus(); SetFocus();
SetCapture(); SetCapture();
Z_MouseDown( pointx, m_pWidget->allocation.height - 1 - pointy, nFlags ); Z_MouseDown( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, nFlags );
} }
void ZWnd::OnMButtonDown( guint32 nFlags, int pointx, int pointy ){ void ZWnd::OnMButtonDown( guint32 nFlags, int pointx, int pointy ){
SetFocus(); SetFocus();
SetCapture(); SetCapture();
Z_MouseDown( pointx, m_pWidget->allocation.height - 1 - pointy, nFlags ); Z_MouseDown( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, nFlags );
} }
void ZWnd::OnRButtonDown( guint32 nFlags, int pointx, int pointy ){ void ZWnd::OnRButtonDown( guint32 nFlags, int pointx, int pointy ){
SetFocus(); SetFocus();
SetCapture(); SetCapture();
Z_MouseDown( pointx, m_pWidget->allocation.height - 1 - pointy, nFlags ); Z_MouseDown( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, nFlags );
} }
void ZWnd::OnLButtonUp( guint32 nFlags, int pointx, int pointy ){ void ZWnd::OnLButtonUp( guint32 nFlags, int pointx, int pointy ){
Z_MouseUp( pointx, m_pWidget->allocation.height - 1 - pointy, nFlags ); Z_MouseUp( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, nFlags );
ReleaseCapture(); ReleaseCapture();
} }
void ZWnd::OnMButtonUp( guint32 nFlags, int pointx, int pointy ){ void ZWnd::OnMButtonUp( guint32 nFlags, int pointx, int pointy ){
Z_MouseUp( pointx, m_pWidget->allocation.height - 1 - pointy, nFlags ); Z_MouseUp( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, nFlags );
ReleaseCapture(); ReleaseCapture();
} }
void ZWnd::OnRButtonUp( guint32 nFlags, int pointx, int pointy ){ void ZWnd::OnRButtonUp( guint32 nFlags, int pointx, int pointy ){
Z_MouseUp( pointx, m_pWidget->allocation.height - 1 - pointy, nFlags ); Z_MouseUp( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, nFlags );
ReleaseCapture(); ReleaseCapture();
} }
void ZWnd::OnMouseMove( guint32 nFlags, int pointx, int pointy ){ void ZWnd::OnMouseMove( guint32 nFlags, int pointx, int pointy ){
float fz = z.origin[2] + ( ( m_pWidget->allocation.height - 1 - pointy ) - ( z.height / 2 ) ) / z.scale; float fz = z.origin[2] + ( ( gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy ) - ( z.height / 2 ) ) / z.scale;
fz = floor( fz / g_qeglobals.d_gridsize + 0.5 ) * g_qeglobals.d_gridsize; fz = floor( fz / g_qeglobals.d_gridsize + 0.5 ) * g_qeglobals.d_gridsize;
CString strStatus; CString strStatus;
strStatus.Format( "Z:: %.1f", fz ); strStatus.Format( "Z:: %.1f", fz );
g_pParentWnd->SetStatusText( 1, strStatus ); g_pParentWnd->SetStatusText( 1, strStatus );
Z_MouseMoved( pointx, m_pWidget->allocation.height - 1 - pointy, nFlags ); Z_MouseMoved( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, nFlags );
} }
void ZWnd::OnExpose(){ void ZWnd::OnExpose(){