From: Garux <garux@mail.ru>
Date: Tue, 1 Aug 2017 11:25:00 +0000 (+0300)
Subject: Radiant:
X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=9d6e27e4e37e7406e8691594fb0b74aab89e954b;p=xonotic%2Fnetradiant.git

Radiant:

misc...
	* fix: texbro m2 drag in 2x2 layout
	* fix: crash in (texbro + freezePointer)
	* fix: all sorts of problems with freezePointer drags near widget borders
---

diff --git a/libs/gtkutil/cursor.cpp b/libs/gtkutil/cursor.cpp
index f0538a50..ae19afe0 100644
--- a/libs/gtkutil/cursor.cpp
+++ b/libs/gtkutil/cursor.cpp
@@ -27,7 +27,7 @@
 #include <gdk/gdkcursor.h>
 #include <gdk/gdkpixmap.h>
 
-
+#if 0
 GdkCursor* create_blank_cursor(){
 	GdkPixmap *pixmap;
 	GdkBitmap *mask;
@@ -53,6 +53,7 @@ void blank_cursor( GtkWidget* widget ){
 void default_cursor( GtkWidget* widget ){
 	gdk_window_set_cursor( widget->window, 0 );
 }
+#endif
 
 
 void Sys_GetCursorPos( GtkWindow* window, int *x, int *y ){
diff --git a/libs/gtkutil/cursor.h b/libs/gtkutil/cursor.h
index dfcc962c..0a6a495d 100644
--- a/libs/gtkutil/cursor.h
+++ b/libs/gtkutil/cursor.h
@@ -26,6 +26,7 @@
 #include <gdk/gdkevents.h>
 #include <gtk/gtkwidget.h>
 #include <gtk/gtkwindow.h>
+#include <gtk/gtkmain.h>
 
 #include "debugging/debugging.h"
 
@@ -33,9 +34,11 @@ typedef struct _GdkCursor GdkCursor;
 typedef struct _GtkWidget GtkWidget;
 typedef struct _GtkWindow GtkWindow;
 
+#if 0
 GdkCursor* create_blank_cursor();
 void blank_cursor( GtkWidget* widget );
 void default_cursor( GtkWidget* widget );
+#endif
 void Sys_GetCursorPos( GtkWindow* window, int *x, int *y );
 void Sys_SetCursorPos( GtkWindow* window, int x, int y );
 
@@ -114,7 +117,8 @@ void motion_delta( int x, int y, unsigned int state ){
 class FreezePointer
 {
 unsigned int handle_motion;
-int recorded_x, recorded_y, last_x, last_y;
+int recorded_x, recorded_y, last_x, last_y, center_x, center_y;
+GtkWidget* weedjet;
 typedef void ( *MotionDeltaFunction )( int x, int y, unsigned int state, void* data );
 MotionDeltaFunction m_function;
 void* m_data;
@@ -126,23 +130,23 @@ static gboolean motion_delta( GtkWidget *widget, GdkEventMotion *event, FreezePo
 	Sys_GetCursorPos( GTK_WINDOW( widget ), &current_x, &current_y );
 	int dx = current_x - self->last_x;
 	int dy = current_y - self->last_y;
-	int ddx = current_x - self->recorded_x;
-	int ddy = current_y - self->recorded_y;
+	int ddx = current_x - self->center_x;
+	int ddy = current_y - self->center_y;
 	self->last_x = current_x;
 	self->last_y = current_y;
 	if ( dx != 0 || dy != 0 ) {
 		//globalOutputStream() << "motion x: " << dx << ", y: " << dy << "\n";
 		if (ddx < -32 || ddx > 32 || ddy < -32 || ddy > 32) {
-			Sys_SetCursorPos( GTK_WINDOW( widget ), self->recorded_x, self->recorded_y );
-			self->last_x = self->recorded_x;
-			self->last_y = self->recorded_y;
+			Sys_SetCursorPos( GTK_WINDOW( widget ), self->center_x, self->center_y );
+			self->last_x = self->center_x;
+			self->last_y = self->center_y;
 		}
 		self->m_function( dx, dy, event->state, self->m_data );
 	}
 	return FALSE;
 }
 
-void freeze_pointer( GtkWindow* window, MotionDeltaFunction function, void* data ){
+void freeze_pointer( GtkWindow* window, GtkWidget* widget, MotionDeltaFunction function, void* data ){
 	ASSERT_MESSAGE( m_function == 0, "can't freeze pointer" );
 
 	const GdkEventMask mask = static_cast<GdkEventMask>( GDK_POINTER_MOTION_MASK
@@ -155,17 +159,30 @@ void freeze_pointer( GtkWindow* window, MotionDeltaFunction function, void* data
 														 | GDK_BUTTON_RELEASE_MASK
 														 | GDK_VISIBILITY_NOTIFY_MASK );
 
-	GdkCursor* cursor = create_blank_cursor();
+	GdkCursor* cursor = gdk_cursor_new( GDK_BLANK_CURSOR );
+	//GdkCursor* cursor = create_blank_cursor();
 	//GdkGrabStatus status =
+	/*	fixes cursor runaways during srsly quick drags in camera
+	drags with pressed buttons have no problem at all w/o this	*/
 	gdk_pointer_grab( GTK_WIDGET( window )->window, TRUE, mask, 0, cursor, GDK_CURRENT_TIME );
+	//gdk_window_set_cursor ( GTK_WIDGET( window )->window, cursor );
+	/*	is needed to fix activating neighbour widgets, that happens, if using upper one	*/
+	gtk_grab_add( widget );
+	weedjet = widget;
+
 	gdk_cursor_unref( cursor );
 
 	Sys_GetCursorPos( window, &recorded_x, &recorded_y );
 
-	Sys_SetCursorPos( window, recorded_x, recorded_y );
+	/*	using center for tracking for max safety	*/
+	gdk_window_get_origin( widget->window, &center_x, &center_y );
+	center_y += widget->allocation.height / 2;
+	center_x += widget->allocation.width / 2;
+
+	Sys_SetCursorPos( window, center_x, center_y );
 
-	last_x = recorded_x;
-	last_y = recorded_y;
+	last_x = center_x;
+	last_y = center_y;
 
 	m_function = function;
 	m_data = data;
@@ -181,7 +198,9 @@ void unfreeze_pointer( GtkWindow* window ){
 
 	Sys_SetCursorPos( window, recorded_x, recorded_y );
 
+//	gdk_window_set_cursor( GTK_WIDGET( window )->window, 0 );
 	gdk_pointer_ungrab( GDK_CURRENT_TIME );
+	gtk_grab_remove( weedjet );
 }
 };
 
diff --git a/radiant/camwindow.cpp b/radiant/camwindow.cpp
index 20fcb853..9a9e6bf2 100644
--- a/radiant/camwindow.cpp
+++ b/radiant/camwindow.cpp
@@ -1325,7 +1325,7 @@ void CamWnd::EnableFreeMove(){
 
 	gtk_window_set_focus( m_parent, m_gl_widget );
 	m_freemove_handle_focusout = g_signal_connect( G_OBJECT( m_gl_widget ), "focus_out_event", G_CALLBACK( camwindow_freemove_focusout ), this );
-	m_freezePointer.freeze_pointer( m_parent, Camera_motionDelta, &m_Camera );
+	m_freezePointer.freeze_pointer( m_parent, m_gl_widget, Camera_motionDelta, &m_Camera );
 
 	CamWnd_Update( *this );
 }
diff --git a/radiant/gtkdlgs.cpp b/radiant/gtkdlgs.cpp
index 57479b32..8cc7aeb6 100644
--- a/radiant/gtkdlgs.cpp
+++ b/radiant/gtkdlgs.cpp
@@ -1083,7 +1083,7 @@ void DoTextEditor( const char* filename, int cursorpos, int length ){
 			ShellExecute( (HWND)GDK_WINDOW_HWND( GTK_WIDGET( MainFrame_getWindow() )->window ), "open", path.c_str(), 0, 0, SW_SHOW );
 		}
 		else{
-			globalOutputStream() << "Failed to open '" << filename << "\n";
+			globalOutputStream() << "Failed to open '" << filename << "'\nOne sits in .pk3 most likely!\n";
 		}
 		return;
 	}
@@ -1104,7 +1104,7 @@ void DoTextEditor( const char* filename, int cursorpos, int length ){
 			DoGtkTextEditor( path.c_str(), cursorpos, length );
 		}
 		else{
-			globalOutputStream() << "Failed to open '" << filename << "\n";
+			globalOutputStream() << "Failed to open '" << filename << "'\nOne sits in .pk3 most likely!\n";
 		}
 		return;
 	}
diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp
index 6fbb4669..2758e8ee 100644
--- a/radiant/mainframe.cpp
+++ b/radiant/mainframe.cpp
@@ -3028,7 +3028,7 @@ void MainFrame::Create(){
 		gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( split ), TRUE, TRUE, 0 );
 
 		{
-			GtkFrame* frame = create_framed_widget( TextureBrowser_constructWindow( window ) );
+			GtkFrame* frame = create_framed_widget( TextureBrowser_constructWindow( GroupDialog_getWindow() ) );
 			g_page_textures = GroupDialog_addPage( "Textures", GTK_WIDGET( frame ), TextureBrowserExportTitleCaller() );
 			/* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
 			g_object_set_data( G_OBJECT( GroupDialog_getWindow() ), "glwidget", TextureBrowser_getGLWidget() );
diff --git a/radiant/texwindow.cpp b/radiant/texwindow.cpp
index 8bf0efb0..36d6eb84 100644
--- a/radiant/texwindow.cpp
+++ b/radiant/texwindow.cpp
@@ -272,49 +272,11 @@ bool m_hideUnused;
 bool m_rmbSelected;
 bool m_searchedTags;
 bool m_tags;
+bool m_move_started;
 // The uniform size (in pixels) that textures are resized to when m_resizeTextures is true.
 int m_uniformTextureSize;
 int m_uniformTextureMinSize;
 // Return the display width of a texture in the texture browser
-/*void getTextureWH( qtexture_t* tex, int *width, int *height ){
-	if ( !g_TextureBrowser_fixedSize ) {
-		// Don't use uniform size
-		*width = (int)( tex->width * ( (float)m_textureScale / 100 ) );
-		*height = (int)( tex->height * ( (float)m_textureScale / 100 ) );
-
-	}
-	else if	( tex->width >= tex->height ) {
-		// Texture is square, or wider than it is tall
-		if ( tex->width >= m_uniformTextureSize ){
-			*width = m_uniformTextureSize;
-			*height = (int)( m_uniformTextureSize * ( (float)tex->height / tex->width ) );
-		}
-		else if ( tex->width <= m_uniformTextureMinSize ){
-			*width = m_uniformTextureMinSize;
-			*height = (int)( m_uniformTextureMinSize * ( (float)tex->height / tex->width ) );
-		}
-		else {
-			*width = tex->width;
-			*height = tex->height;
-		}
-	}
-	else {
-		// Texture taller than it is wide
-		if ( tex->height >= m_uniformTextureSize ){
-			*height = m_uniformTextureSize;
-			*width = (int)( m_uniformTextureSize * ( (float)tex->width / tex->height ) );
-		}
-		else if ( tex->height <= m_uniformTextureMinSize ){
-			*height = m_uniformTextureMinSize;
-			*width = (int)( m_uniformTextureMinSize * ( (float)tex->width / tex->height ) );
-		}
-		else {
-			*width = tex->width;
-			*height = tex->height;
-		}
-	}
-}
-*/
 void getTextureWH( qtexture_t* tex, int &W, int &H ){
 		// Don't use uniform size
 		W = (int)( tex->width * ( (float)m_textureScale / 100 ) );
@@ -372,7 +334,8 @@ TextureBrowser() :
 	m_searchedTags( false ),
 	m_tags( false ),
 	m_uniformTextureSize( 160 ),
-	m_uniformTextureMinSize( 48 ){
+	m_uniformTextureMinSize( 48 ),
+	m_move_started( false ){
 }
 };
 
@@ -1055,14 +1018,19 @@ void TextureBrowser_trackingDelta( int x, int y, unsigned int state, void* data
 	}
 }
 
-void TextureBrowser_Tracking_MouseDown( TextureBrowser& textureBrowser ){
-	textureBrowser.m_freezePointer.freeze_pointer( textureBrowser.m_parent, TextureBrowser_trackingDelta, &textureBrowser );
-}
-
 void TextureBrowser_Tracking_MouseUp( TextureBrowser& textureBrowser ){
+	textureBrowser.m_move_started = false;
 	textureBrowser.m_freezePointer.unfreeze_pointer( textureBrowser.m_parent );
 }
 
+void TextureBrowser_Tracking_MouseDown( TextureBrowser& textureBrowser ){
+	if( textureBrowser.m_move_started ){
+		TextureBrowser_Tracking_MouseUp( textureBrowser );
+	}
+	textureBrowser.m_move_started = true;
+	textureBrowser.m_freezePointer.freeze_pointer( textureBrowser.m_parent, textureBrowser.m_gl_widget, TextureBrowser_trackingDelta, &textureBrowser );
+}
+
 void TextureBrowser_Selection_MouseDown( TextureBrowser& textureBrowser, guint32 flags, int pointx, int pointy ){
 	SelectTexture( textureBrowser, pointx, textureBrowser.height - 1 - pointy, ( flags & GDK_SHIFT_MASK ) != 0 );
 }
diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp
index 393a957a..4d4d7517 100644
--- a/radiant/xywindow.cpp
+++ b/radiant/xywindow.cpp
@@ -1205,7 +1205,7 @@ void XYWnd::Move_Begin(){
 		Move_End();
 	}
 	m_move_started = true;
-	g_xywnd_freezePointer.freeze_pointer( m_parent != 0 ? m_parent : MainFrame_getWindow(), XYWnd_moveDelta, this );
+	g_xywnd_freezePointer.freeze_pointer( m_parent != 0 ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_moveDelta, this );
 	m_move_focusOut = g_signal_connect( G_OBJECT( m_gl_widget ), "focus_out_event", G_CALLBACK( XYWnd_Move_focusOut ), this );
 }
 
@@ -1250,7 +1250,7 @@ void XYWnd::Zoom_Begin(){
 	}
 	m_zoom_started = true;
 	g_dragZoom = 0;
-	g_xywnd_freezePointer.freeze_pointer( m_parent != 0 ? m_parent : MainFrame_getWindow(), XYWnd_zoomDelta, this );
+	g_xywnd_freezePointer.freeze_pointer( m_parent != 0 ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_zoomDelta, this );
 	m_zoom_focusOut = g_signal_connect( G_OBJECT( m_gl_widget ), "focus_out_event", G_CALLBACK( XYWnd_Zoom_focusOut ), this );
 }