|
From: <hba...@us...> - 2010-02-01 03:51:31
|
Revision: 10791
http://plplot.svn.sourceforge.net/plplot/?rev=10791&view=rev
Author: hbabcock
Date: 2010-02-01 03:51:24 +0000 (Mon, 01 Feb 2010)
Log Message:
-----------
Improvements to the wincairo driver:
(1) Handle redraw events.
(2) Handle window resizing.
Modified Paths:
--------------
trunk/drivers/cairo.c
Modified: trunk/drivers/cairo.c
===================================================================
--- trunk/drivers/cairo.c 2010-01-31 23:59:04 UTC (rev 10790)
+++ trunk/drivers/cairo.c 2010-02-01 03:51:24 UTC (rev 10791)
@@ -116,11 +116,15 @@
char bigendian;
#endif
#if defined ( PLD_wincairo )
+ cairo_surface_t *cairoSurface_win;
+ cairo_t *cairoContext_win;
WNDCLASSEX wndclass;
HWND hwnd;
MSG msg;
HDC hdc;
HDC SCRN_hdc;
+ COLORREF oldcolour;
+ RECT rect;
#endif
} PLCairo;
@@ -2586,9 +2590,21 @@
void plD_init_wincairo( PLStream * );
//void plD_bop_extcairo( PLStream * );
void plD_eop_wincairo( PLStream * );
-//void plD_esc_extcairo( PLStream *, PLINT, void * );
+void plD_esc_extcairo( PLStream *, PLINT, void * );
void plD_tidy_wincairo( PLStream * );
+/*---------------------------------------------------------------------
+ * blit_to_win()
+ *
+ * Blit the offscreen image to the Windows window.
+ * ---------------------------------------------------------------------*/
+
+void blit_to_win( PLCairo *aStream )
+{
+ cairo_set_source_surface( aStream->cairoContext_win, aStream->cairoSurface, 0.0, 0.0 );
+ cairo_paint( aStream->cairoContext_win );
+}
+
/*--------------------------------------------------------------------------*\
* This is the window function for the plot window. Whenever a message is
* dispatched using DispatchMessage (or sent with SendMessage) this function
@@ -2604,7 +2620,7 @@
* The window carries a 32bit user defined pointer which points to the
* plplot stream (pls). This is used for tracking the window.
* Unfortunately, this is "attached" to the window AFTER it is created
- * so we can not initialise PLStream or wingcc_Dev "blindly" because
+ * so we can not initialise PLStream or wincairo "blindly" because
* they may not yet have been initialised.
* WM_CREATE is called before we get to initialise those variables, so
* we wont try to set them.
@@ -2643,10 +2659,12 @@
break;
case WM_PAINT:
+ blit_to_win( dev );
return ( 1 );
break;
case WM_SIZE:
+ GetClientRect( dev->hwnd, &dev->rect );
return ( 0 );
break;
@@ -2659,7 +2677,13 @@
break;
case WM_ERASEBKGND:
- return ( 0 );
+ if ( dev )
+ {
+ dev->oldcolour = SetBkColor( dev->hdc, RGB( pls->cmap0[0].r, pls->cmap0[0].g, pls->cmap0[0].b ) );
+ ExtTextOut( dev->hdc, 0, 0, ETO_OPAQUE, &dev->rect, "", 0, 0 );
+ SetBkColor( dev->hdc, dev->oldcolour );
+ }
+ return ( 1 );
break;
case WM_COMMAND:
@@ -2813,7 +2837,12 @@
* Initialize Cairo Surface using the windows hdc.
*/
- aStream->cairoSurface = (cairo_surface_t *) cairo_win32_surface_create( aStream->hdc );
+ /* This is the Win32 Cairo surface. */
+ aStream->cairoSurface_win = (cairo_surface_t *) cairo_win32_surface_create( aStream->hdc );
+ aStream->cairoContext_win = cairo_create( aStream->cairoSurface_win );
+
+ /* This is the Cairo surface PLplot will actually plot to. */
+ aStream->cairoSurface = cairo_image_surface_create( CAIRO_FORMAT_RGB24, pls->xlength, pls->ylength );
aStream->cairoContext = cairo_create( aStream->cairoSurface );
/* Invert the surface so that the graphs are drawn right side up. */
@@ -2868,6 +2897,12 @@
{
PLCairo *aStream = (PLCairo *) pls->dev;
+ plD_tidy_cairo( pls );
+
+ /* Also free up the Cairo win32 surface and context */
+ cairo_destroy( aStream->cairoContext_win );
+ cairo_surface_destroy( aStream->cairoSurface_win );
+
if ( aStream != NULL )
{
if ( aStream->hdc != NULL ) ReleaseDC( aStream->hwnd, aStream->hdc );
@@ -2875,4 +2910,29 @@
}
}
+/*---------------------------------------------------------------------
+ * plD_esc_wincairo()
+ *
+ * Escape function, specialized for the wincairo driver
+ * ---------------------------------------------------------------------*/
+
+void plD_esc_wincairo( PLStream *pls, PLINT op, void *ptr )
+{
+ PLCairo *aStream;
+
+ aStream = (PLCairo *) pls->dev;
+
+ switch ( op )
+ {
+ case PLESC_FLUSH:
+ InvalidateRect( aStream->hwnd, NULL, TRUE);
+ break;
+ case PLESC_GETC:
+ break;
+ default:
+ plD_esc_cairo( pls, op, ptr );
+ break;
+ }
+}
+
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|