[cairo-commit] roadster/src mainwindow.c, 1.16, 1.17 map_draw_gdk.c, 1.3, 1.4

Ian McIntosh commit at pdx.freedesktop.org
Fri Mar 4 21:47:53 PST 2005


Committed by: ian

Update of /cvs/cairo/roadster/src
In directory gabe:/tmp/cvs-serv11992/src

Modified Files:
	mainwindow.c map_draw_gdk.c 
Log Message:
	* README: Provide URL to Wiki for help with compiling.
	* src/mainwindow.c: Use 'implicit pointer grab' instead of gdk_pointer_grab() due to bitching of Carl, Owen and Keith :)
	* src/map_draw_gdk.c: Better support for dashed lines (not complete).


Index: mainwindow.c
===================================================================
RCS file: /cvs/cairo/roadster/src/mainwindow.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- mainwindow.c	4 Mar 2005 21:08:23 -0000	1.16
+++ mainwindow.c	5 Mar 2005 05:47:51 -0000	1.17
@@ -94,7 +94,7 @@
 #define DRAW_PRETTY_TIMEOUT_MS		(110)	// how long after stopping various movements should we redraw in high-quality mode
 #define SCROLL_TIMEOUT_MS		(100)	// how often (in MS) to move (SHORTER THAN ABOVE TIME)
 #define SCROLL_DISTANCE_IN_PIXELS	(100)	// how far to move every (above) MS
-#define BORDER_SCROLL_CLICK_TARGET_SIZE	(25)	// the size of the click target (distance from edge of map view) to begin scrolling
+#define BORDER_SCROLL_CLICK_TARGET_SIZE	(17)	// the size of the click target (distance from edge of map view) to begin scrolling
 
 typedef enum {
 	DIRECTION_NONE, DIRECTION_N, DIRECTION_NE, DIRECTION_E, DIRECTION_SE, DIRECTION_S, DIRECTION_SW, DIRECTION_W, DIRECTION_NW
@@ -250,7 +250,7 @@
 	map_new(&g_MainWindow.m_pMap, GTK_WIDGET(g_MainWindow.m_pDrawingArea));
 
 	// add signal handlers to drawing area
-	gtk_widget_add_events(GTK_WIDGET(g_MainWindow.m_pDrawingArea), GDK_POINTER_MOTION_MASK | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK);
+	gtk_widget_add_events(GTK_WIDGET(g_MainWindow.m_pDrawingArea), GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
 	g_signal_connect(G_OBJECT(g_MainWindow.m_pDrawingArea), "expose_event", G_CALLBACK(mainwindow_on_expose_event), NULL);
 	g_signal_connect(G_OBJECT(g_MainWindow.m_pDrawingArea), "configure_event", G_CALLBACK(mainwindow_on_configure_event), NULL);
 	g_signal_connect(G_OBJECT(g_MainWindow.m_pDrawingArea), "button_press_event", G_CALLBACK(mainwindow_on_mouse_button_click), NULL);
@@ -692,33 +692,46 @@
 			eScrollDirection = match_border(nX, nY, nWidth, nHeight, BORDER_SCROLL_CLICK_TARGET_SIZE);
 			if(eScrollDirection != DIRECTION_NONE) {
 				// begin a scroll
+				//GdkCursor* pCursor = gdk_cursor_new(g_aDirectionCursors[eScrollDirection].m_nCursor);
+				//if(GDK_GRAB_SUCCESS == gdk_pointer_grab(GTK_WIDGET(g_MainWindow.m_pDrawingArea)->window, FALSE, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_RELEASE_MASK, NULL, pCursor, GDK_CURRENT_TIME)) {
 				GdkCursor* pCursor = gdk_cursor_new(g_aDirectionCursors[eScrollDirection].m_nCursor);
-				if(GDK_GRAB_SUCCESS == gdk_pointer_grab(GTK_WIDGET(g_MainWindow.m_pDrawingArea)->window, FALSE, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_RELEASE_MASK, NULL, pCursor, GDK_CURRENT_TIME)) {
-					g_MainWindow.m_bScrolling = TRUE;
-					g_MainWindow.m_eScrollDirection = eScrollDirection;
-
-					mainwindow_set_scroll_timeout();
-				}
+				gdk_window_set_cursor(GTK_WIDGET(g_MainWindow.m_pDrawingArea)->window, pCursor);
 				gdk_cursor_unref(pCursor);
 
+				g_MainWindow.m_bScrolling = TRUE;
+				g_MainWindow.m_eScrollDirection = eScrollDirection;
+
+				mainwindow_set_scroll_timeout();
+				//}
+				//gdk_cursor_unref(pCursor);
+
 			}
 			else {
 				// else begin a drag
+//                                 GdkCursor* pCursor = gdk_cursor_new(GDK_HAND2);
+//                                 if(GDK_GRAB_SUCCESS == gdk_pointer_grab(GTK_WIDGET(g_MainWindow.m_pDrawingArea)->window, FALSE, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_RELEASE_MASK, NULL, pCursor, GDK_CURRENT_TIME)) {
 				GdkCursor* pCursor = gdk_cursor_new(GDK_HAND2);
-				if(GDK_GRAB_SUCCESS == gdk_pointer_grab(GTK_WIDGET(g_MainWindow.m_pDrawingArea)->window, FALSE, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_RELEASE_MASK, NULL, pCursor, GDK_CURRENT_TIME)) {
-					g_MainWindow.m_bMouseDragging = TRUE;
-					g_MainWindow.m_ptClickLocation.m_nX = nX;
-					g_MainWindow.m_ptClickLocation.m_nY = nY;
-				}
+				gdk_window_set_cursor(GTK_WIDGET(g_MainWindow.m_pDrawingArea)->window, pCursor);
 				gdk_cursor_unref(pCursor);
+
+				g_MainWindow.m_bMouseDragging = TRUE;
+				g_MainWindow.m_ptClickLocation.m_nX = nX;
+				g_MainWindow.m_ptClickLocation.m_nY = nY;
+//                                 }
+//                                 gdk_cursor_unref(pCursor);
 			}
 		}
 		// Left mouse button up?
 		else if(event->type == GDK_BUTTON_RELEASE) {
+			// restore cursor
+			GdkCursor* pCursor = gdk_cursor_new(GDK_LEFT_PTR);
+			gdk_window_set_cursor(GTK_WIDGET(g_MainWindow.m_pDrawingArea)->window, pCursor);
+			gdk_cursor_unref(pCursor);
+
 			// end mouse dragging, if active
 			if(g_MainWindow.m_bMouseDragging == TRUE) {
 				g_MainWindow.m_bMouseDragging = FALSE;
-				gdk_pointer_ungrab(GDK_CURRENT_TIME);
+//                                 gdk_pointer_ungrab(GDK_CURRENT_TIME);
 
 				mainwindow_cancel_draw_pretty_timeout();
 				mainwindow_draw_map(DRAWFLAG_ALL);
@@ -728,7 +741,7 @@
 			if(g_MainWindow.m_bScrolling == TRUE) {
 				g_MainWindow.m_bScrolling = FALSE;
 				g_MainWindow.m_eScrollDirection = DIRECTION_NONE;
-				gdk_pointer_ungrab(GDK_CURRENT_TIME);
+//                                 gdk_pointer_ungrab(GDK_CURRENT_TIME);
 
 				mainwindow_cancel_draw_pretty_timeout();
 				mainwindow_draw_map(DRAWFLAG_ALL);
@@ -757,6 +770,8 @@
 
 	gint nWidth = GTK_WIDGET(g_MainWindow.m_pDrawingArea)->allocation.width;
 	gint nHeight = GTK_WIDGET(g_MainWindow.m_pDrawingArea)->allocation.height;
+	
+	EDirection eScrollDirection = match_border(nX, nY, nWidth, nHeight, BORDER_SCROLL_CLICK_TARGET_SIZE);
 
 	if(g_MainWindow.m_bMouseDragging) {
 		gint nDeltaX = g_MainWindow.m_ptClickLocation.m_nX - nX;
@@ -773,23 +788,27 @@
 		g_MainWindow.m_ptClickLocation.m_nX = nX;
 		g_MainWindow.m_ptClickLocation.m_nY = nY;
 	}
-
-	EDirection eScrollDirection = match_border(nX, nY, nWidth, nHeight, BORDER_SCROLL_CLICK_TARGET_SIZE);
-	
 	// set appropriate mouse cursor whether scrolling or not
-	if(g_MainWindow.m_bScrolling) {
+	else if(g_MainWindow.m_bScrolling) {
+		// just set the cursor the window
+
 		if(g_MainWindow.m_eScrollDirection != eScrollDirection) {
-			// update direction if actively scrolling
-			g_MainWindow.m_eScrollDirection = eScrollDirection;
-			
+			// update cursor
 			GdkCursor* pCursor = gdk_cursor_new(g_aDirectionCursors[eScrollDirection].m_nCursor);
-			gdk_pointer_ungrab(GDK_CURRENT_TIME);
-			gdk_pointer_grab(GTK_WIDGET(g_MainWindow.m_pDrawingArea)->window, FALSE, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_RELEASE_MASK, NULL, pCursor, GDK_CURRENT_TIME);
+			gdk_window_set_cursor(GTK_WIDGET(g_MainWindow.m_pDrawingArea)->window, pCursor);
 			gdk_cursor_unref(pCursor);
+
+			// update direction if actively scrolling
+			g_MainWindow.m_eScrollDirection = eScrollDirection;
+
+			//GdkCursor* pCursor = gdk_cursor_new(g_aDirectionCursors[eScrollDirection].m_nCursor);
+			//gdk_pointer_ungrab(GDK_CURRENT_TIME);
+			//gdk_pointer_grab(GTK_WIDGET(g_MainWindow.m_pDrawingArea)->window, FALSE, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_RELEASE_MASK, NULL, pCursor, GDK_CURRENT_TIME);
+			//gdk_cursor_unref(pCursor);
 		}
 	}
 	else {
-		// just set the cursor the window
+		// just set cursor based on what we're hovering over
 		GdkCursor* pCursor = gdk_cursor_new(g_aDirectionCursors[eScrollDirection].m_nCursor);
 		gdk_window_set_cursor(GTK_WIDGET(g_MainWindow.m_pDrawingArea)->window, pCursor);
 		gdk_cursor_unref(pCursor);

Index: map_draw_gdk.c
===================================================================
RCS file: /cvs/cairo/roadster/src/map_draw_gdk.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- map_draw_gdk.c	4 Mar 2005 21:08:23 -0000	1.3
+++ map_draw_gdk.c	5 Mar 2005 05:47:51 -0000	1.4
@@ -149,21 +149,25 @@
 	if(fLineWidth <= 0.0) return;	// Don't draw invisible lines
 	if(pSubLayerStyle->m_clrColor.m_fAlpha == 0.0) return;	// invisible?  (not that we respect it in gdk drawing anyway)
 
-	// Raise the tolerance way up for thin lines
-	gint nCapStyle = pSubLayerStyle->m_nCapStyle;
+	// Use GDK dash style if ANY dash pattern is set
+	gint nDashStyle = GDK_LINE_SOLID;
+	if(pSubLayerStyle->m_nDashStyle != 0) {
+		nDashStyle = GDK_LINE_ON_OFF_DASH;
+
+		// gdk_gc_set_dashes
+	}
 
 	// XXX: Don't use round at low zoom levels
+	// gint nCapStyle = pSubLayerStyle->m_nCapStyle;
+	gint nCapStyle = GDK_CAP_ROUND;
 	if(fLineWidth < 8) {
-		// Set line style
-		gdk_gc_set_line_attributes(pMap->m_pTargetWidget->style->fg_gc[GTK_WIDGET_STATE(pMap->m_pTargetWidget)],
-				   ((gint)fLineWidth), GDK_LINE_SOLID, GDK_CAP_PROJECTING, GDK_JOIN_MITER);
-	}
-	else {
-		// Set line style
-		gdk_gc_set_line_attributes(pMap->m_pTargetWidget->style->fg_gc[GTK_WIDGET_STATE(pMap->m_pTargetWidget)],
-				   ((gint)fLineWidth), GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_MITER);
+		nCapStyle = GDK_CAP_PROJECTING;
 	}
 
+	// Set line style
+	gdk_gc_set_line_attributes(pMap->m_pTargetWidget->style->fg_gc[GTK_WIDGET_STATE(pMap->m_pTargetWidget)],
+			   ((gint)fLineWidth), nDashStyle, nCapStyle, GDK_JOIN_MITER);
+
 	GdkColor clr;
 	clr.red = pSubLayerStyle->m_clrColor.m_fRed * 65535;
 	clr.green = pSubLayerStyle->m_clrColor.m_fGreen * 65535;




More information about the cairo-commit mailing list