[rkward-cvs] SF.net SVN: rkward-code:[4996] trunk/rkward

tfry at users.sf.net tfry at users.sf.net
Fri Nov 7 18:58:54 UTC 2014


Revision: 4996
          http://sourceforge.net/p/rkward/code/4996
Author:   tfry
Date:     2014-11-07 18:58:53 +0000 (Fri, 07 Nov 2014)
Log Message:
-----------
Implement polyPath()

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/doc/rkwardplugins/index.docbook
    trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
    trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.h
    trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp
    trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice_protocol_shared.h
    trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp
    trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2014-11-07 14:50:10 UTC (rev 4995)
+++ trunk/rkward/ChangeLog	2014-11-07 18:58:53 UTC (rev 4996)
@@ -1,3 +1,4 @@
+- Implement polyPath()-drawing in RK() device
 - Pre-compile the common js code included in every plugin (only when compiled with Qt >= 4.7)
 - Improve crash recovery dialog to not prompt again for the same files
 - Fixed potential crash while the "RKWard Debug Messages" window is visible

Modified: trunk/rkward/doc/rkwardplugins/index.docbook
===================================================================
--- trunk/rkward/doc/rkwardplugins/index.docbook	2014-11-07 14:50:10 UTC (rev 4995)
+++ trunk/rkward/doc/rkwardplugins/index.docbook	2014-11-07 18:58:53 UTC (rev 4996)
@@ -1871,7 +1871,8 @@
 </radio>
 		</programlisting>
 		<para>
-			Note that you will omit the <replaceable>label</replaceable>-attribute, then, and specify <replaceable>noi18n_label</replaceable>, instead.
+			Note that you will omit the <replaceable>label</replaceable>-attribute, then, and specify <replaceable>noi18n_label</replaceable>, instead. Also, note that in contrast to
+			<replaceable>i18n_context</replaceable> and comments, using <replaceable>noi18n_label</replaceable> will make your plugin incompatible with versions of &rkward; prior to 0.6.3.
 		</para>
 	</sect1>
 	<sect1 id="i18n_js"><title>i18n in &rkward;'s js files and sections</title>

Modified: trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp	2014-11-07 14:50:10 UTC (rev 4995)
+++ trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp	2014-11-07 18:58:53 UTC (rev 4996)
@@ -237,6 +237,21 @@
 	triggerUpdate ();
 }
 
+void RKGraphicsDevice::polypath (const QVector<QPolygonF>& polygons, bool winding, const QPen& pen, const QBrush& brush) {
+	RK_TRACE (GRAPHICS_DEVICE);
+
+	painter.setPen (pen);
+	painter.setBrush (brush);
+	QPainterPath path;
+	if (winding) path.setFillRule (Qt::WindingFill);
+	for (int i = 0; i < polygons.size (); ++i) {
+		path.addPolygon (polygons[i]);
+		path.closeSubpath ();
+	}
+	painter.drawPath (path);
+	triggerUpdate ();
+}
+
 void RKGraphicsDevice::image (const QImage& image, const QRectF& target_rect, double rot, bool interpolate) {
 	RK_TRACE (GRAPHICS_DEVICE);
 

Modified: trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.h
===================================================================
--- trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.h	2014-11-07 14:50:10 UTC (rev 4995)
+++ trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice.h	2014-11-07 18:58:53 UTC (rev 4996)
@@ -2,7 +2,7 @@
                           rkgraphicsdevice_backendtransmitter  -  description
                              -------------------
     begin                : Mon Mar 18 20:06:08 CET 2013
-    copyright            : (C) 2013 by Thomas Friedrichsmeier 
+    copyright            : (C) 2013-2014 by Thomas Friedrichsmeier 
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -64,6 +64,7 @@
 	void setClip (const QRectF& new_clip);
 	void polygon (const QPolygonF& pol, const QPen& pen, const QBrush &brush);
 	void polyline (const QPolygonF& pol, const QPen& pen);
+	void polypath (const QVector<QPolygonF>& polygons, bool winding, const QPen& pen, const QBrush& brush);
 	void clear (const QColor& col=QColor());
 	void image (const QImage &image, const QRectF &target_rect, double rot, bool interpolate);
 	QImage capture () const;

Modified: trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp	2014-11-07 14:50:10 UTC (rev 4995)
+++ trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp	2014-11-07 18:58:53 UTC (rev 4996)
@@ -2,7 +2,7 @@
                           rkgraphicsdevice_frontendtransmitter  -  description
                              -------------------
     begin                : Mon Mar 18 20:06:08 CET 2013
-    copyright            : (C) 2013 by Thomas Friedrichsmeier 
+    copyright            : (C) 2013-2014 by Thomas Friedrichsmeier 
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -227,6 +227,18 @@
 		} else if (opcode == RKDPolyline) {
 			QPolygonF pol (readPoints (streamer.instream));
 			device->polyline (pol, readPen (streamer.instream));
+		} else if (opcode == RKDPath) {
+			quint32 npol;
+			streamer.instream >> npol;
+			QVector<QPolygonF> polygons;
+			polygons.reserve (npol);
+			for (quint32 i = 0; i < npol; ++i) {
+				polygons.append (readPoints (streamer.instream));
+			}
+			bool winding;
+			streamer.instream >> winding;
+			QPen pen = readPen (streamer.instream);
+			device->polypath (polygons, winding, pen, readBrush (streamer.instream));
 		} else if (opcode == RKDRect) {
 			QRectF rect;
 			streamer.instream >> rect;

Modified: trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice_protocol_shared.h
===================================================================
--- trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice_protocol_shared.h	2014-11-07 14:50:10 UTC (rev 4995)
+++ trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice_protocol_shared.h	2014-11-07 18:58:53 UTC (rev 4996)
@@ -67,31 +67,32 @@
 	RKDLine,
 	RKDPolygon,
 	RKDPolyline,
-	RKDRect,               // 5
+	RKDPath,               // 5
+	RKDRect,
 	RKDTextUTF8,
 	RKDNewPage,
 	RKDClose,
-	RKDActivate,
-	RKDDeActivate,         // 10
+	RKDActivate,           // 10
+	RKDDeActivate,
 	RKDClip,
 	RKDMode,
 	RKDRaster,
-	RKDSetSize,
-	RKDStartGettingEvents, // 15
+	RKDSetSize,            // 15
+	RKDStartGettingEvents,
 	RKDStopGettingEvents,
 
 	// Synchronous operations
 	RKDFetchNextEvent,
 	RKDStrWidthUTF8,
-	RKDMetricInfo, 
-	RKDLocator,            // 20
+	RKDMetricInfo,         // 20
+	RKDLocator,
 	RKDNewPageConfirm,
 	RKDCapture,
 	RKDQueryResolution,
-	RKDGetSize,
+	RKDGetSize,            // 25
 
 	// Protocol operations
-	RKDCancel              // 25
+	RKDCancel
 };
 
 enum RKDEventCodes {

Modified: trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp	2014-11-07 14:50:10 UTC (rev 4995)
+++ trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp	2014-11-07 18:58:53 UTC (rev 4996)
@@ -2,7 +2,7 @@
                           rkgraphicsdevice_setup  -  description
                              -------------------
     begin                : Mon Mar 18 20:06:08 CET 2013
-    copyright            : (C) 2013 by Thomas Friedrichsmeier 
+    copyright            : (C) 2013-2014 by Thomas Friedrichsmeier 
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -194,6 +194,9 @@
 	dev->newPage = RKD_NewPage;
 	dev->polygon = RKD_Polygon;
 	dev->polyline = RKD_Polyline;
+#if R_VERSION >= R_Version (2, 12, 0)
+	dev->path = RKD_Path;
+#endif
 	dev->rect = RKD_Rect;
 	dev->size = RKD_Size;
 	// dev->onexit = RKD_OnExit; Called on user interrupts. NULL is OK.

Modified: trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp	2014-11-07 14:50:10 UTC (rev 4995)
+++ trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp	2014-11-07 18:58:53 UTC (rev 4996)
@@ -2,7 +2,7 @@
                           rkgraphicsdevice_stubs  -  description
                              -------------------
     begin                : Mon Mar 18 20:06:08 CET 2013
-    copyright            : (C) 2013 by Thomas Friedrichsmeier 
+    copyright            : (C) 2013-2014 by Thomas Friedrichsmeier 
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -269,6 +269,26 @@
 	WRITE_LINE_ENDS ();
 }
 
+static void RKD_Path (double *x, double *y, int npoly, int *nper, Rboolean winding, R_GE_gcontext *gc, pDevDesc dev) {
+	RKGraphicsDataStreamWriteGuard guard;
+	WRITE_HEADER (RKDPath, dev);
+	quint32 total_points = 0;
+	quint32 _n = qMin (npoly, 1 << 24);	// skip stuff exceeding reasonable limits to keep protocol simple
+	RKD_OUT_STREAM << _n;
+	for (quint32 i = 0; i < _n; ++i) {
+		quint32 np = nper[i];	// Actually, a quint8 would probably do?
+		RKD_OUT_STREAM << np;
+		for (quint32 j = 0; j < np; ++j) {
+			RKD_OUT_STREAM << x[total_points] << y[total_points];
+			total_points++;
+		}
+	}
+	RKD_OUT_STREAM << (bool) winding;
+	WRITE_PEN ();
+	WRITE_LINE_ENDS ();
+	WRITE_FILL ();
+}
+
 static void RKD_Rect (double x0, double y0, double x1, double y1, R_GE_gcontext *gc, pDevDesc dev) {
 	RKGraphicsDataStreamWriteGuard guard;
 	WRITE_HEADER (RKDRect, dev);





More information about the rkward-tracker mailing list