[rkward-cvs] SF.net SVN: rkward-code:[4684] branches/development_branches/ rkward_graphpics_device/rkward

tfry at users.sf.net tfry at users.sf.net
Thu Apr 11 10:38:09 UTC 2013


Revision: 4684
          http://sourceforge.net/p/rkward/code/4684
Author:   tfry
Date:     2013-04-11 10:38:08 +0000 (Thu, 11 Apr 2013)
Log Message:
-----------
Some adjustments all over the place. Importantly: Try to support reported screen resolution.

Modified Paths:
--------------
    branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
    branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp
    branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_protocol_shared.h
    branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp
    branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
    branches/development_branches/rkward_graphpics_device/rkward/rbackend/rpackages/rkward/R/public_graphics.R
    branches/development_branches/rkward_graphpics_device/rkward/windows/rkwindowcatcher.cpp
    branches/development_branches/rkward_graphpics_device/rkward/windows/rkwindowcatcher.h

Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp	2013-04-10 18:01:10 UTC (rev 4683)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp	2013-04-11 10:38:08 UTC (rev 4684)
@@ -100,16 +100,17 @@
 	RK_TRACE (GRAPHICS_DEVICE);
 
 	if (painter.isActive ()) painter.end ();
- 	if (col.isValid ()) area.fill (col);
+	if (col.isValid ()) area.fill (col);
 	else area.fill (QColor (255, 255, 255, 255));
 	updateNow ();
+	setClip (area.rect ());	// R's devX11.c resets clip on clear, so we do this, too.
 }
 
 void RKGraphicsDevice::setClip (const QRectF& new_clip) {
 	RK_TRACE (GRAPHICS_DEVICE);
 
 	if (!painter.isActive ()) painter.begin (&area);
-//	painter.setClipRect (new_clip);
+	painter.setClipRect (new_clip);
 }
 
 void RKGraphicsDevice::circle (double x, double y, double r, const QPen& pen, const QBrush& brush) {

Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp	2013-04-10 18:01:10 UTC (rev 4683)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp	2013-04-11 10:38:08 UTC (rev 4684)
@@ -24,6 +24,10 @@
 #include <kmessagebox.h>
 #include <klocale.h>
 
+// for screen resolution
+#include <QApplication>
+#include <QDesktopWidget>
+
 // NOTE: This is but the latest nail in the coffin of the single process variant of RKWard.
 // *IF* the RKWard Graphics Device works out as hoped, the single process variant can finally be ditched for good.
 #define RKWARD_SPLIT_PROCESS 1
@@ -80,6 +84,7 @@
 	connection = con;
 	streamer.setIODevice (con);
 	connect (connection, SIGNAL (readyRead ()), this, SLOT (newData ()));
+	newData ();	// might already be available
 }
 
 static QRgb readRgb (QDataStream &instream) {
@@ -184,12 +189,17 @@
 			connect (device, SIGNAL (locatorDone(bool,double,double)), this, SLOT (locatorDone(bool,double,double)));
 			connect (device, SIGNAL (newPageConfirmDone(bool)), this, SLOT (newPageConfirmDone(bool)));
 			connect (this, SIGNAL (stopInteraction()), device, SLOT (stopInteraction()));
+			continue;
 		} else {
 			if (devnum) device = RKGraphicsDevice::devices.value (devnum);
 			if (!device) {
 				if (opcode == RKDCancel) {
 					RK_DEBUG (GRAPHICS_DEVICE, DL_WARNING, "Graphics operation cancelled");
 					emit (stopInteraction());
+				} else if (opcode == RKDQueryResolution) {
+					QDesktopWidget *desktop = QApplication::desktop ();
+					streamer.outstream << (qint32) desktop->physicalDpiX () << (qint32) desktop->physicalDpiY ();
+					streamer.writeOutBuffer ();
 				} else {
 					RK_DEBUG (GRAPHICS_DEVICE, DL_ERROR, "Received transmission of type %d for unknown device number %d. Skippping.", opcode, devnum);
 					sendDummyReply (opcode);

Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_protocol_shared.h
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_protocol_shared.h	2013-04-10 18:01:10 UTC (rev 4683)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_protocol_shared.h	2013-04-11 10:38:08 UTC (rev 4684)
@@ -83,9 +83,10 @@
 	RKDLocator,
 	RKDNewPageConfirm,
 	RKDCapture,
+	RKDQueryResolution,
 
 	// Protocol operations
-	RKDCancel
+	RKDCancel      // 20
 };
 
 #include <QIODevice>

Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp	2013-04-10 18:01:10 UTC (rev 4683)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp	2013-04-11 10:38:08 UTC (rev 4684)
@@ -44,9 +44,10 @@
 #endif
 
 struct RKGraphicsDeviceDesc {
-	bool initRDevDesc (pDevDesc dev, double pointsize, rcolor bg);
+	bool init (pDevDesc dev, double pointsize, const QStringList &family, rcolor bg);
 	int devnum;
 	double width, height;
+	int dpix, dpiy;
 	QString getFontFamily (bool symbolfont) const {
 		if (symbolfont) return default_symbol_family;
 		return default_family;
@@ -58,17 +59,17 @@
 
 #include "rkgraphicsdevice_stubs.cpp"
 
-#define RKGD_DPI 72
+// No, I do not really understand what this is for.
+// Mostly trying to mimick the X11 device's behavior, here.
+#define RKGD_DPI 72.0
 
 void RKStartGraphicsDevice (double width, double height, double pointsize, const QStringList &family, rcolor bg, const char* title, bool antialias) {
 	if (width <= 0 || height <= 0) {
 		Rf_error ("Invalid width or height: (%g, %g)", width, height);
 	}
 	RKGraphicsDeviceDesc *desc = new RKGraphicsDeviceDesc;
-	desc->width = width * RKGD_DPI;
-	desc->height = height * RKGD_DPI;
-	desc->default_family = family.value (0, "Helvetica");
-	desc->default_symbol_family = family.value (0, "Symbol");
+	desc->width = width;
+	desc->height = height;
 
 	R_GE_checkVersionOrDie (R_GE_version);
 	R_CheckDeviceAvailable ();
@@ -76,7 +77,8 @@
 	BEGIN_SUSPEND_INTERRUPTS {
 		/* Allocate and initialize the device driver data */
 		dev = (pDevDesc) calloc (1, sizeof(DevDesc));
-		if (!(dev && desc->initRDevDesc (dev, pointsize, bg) && RKGraphicsDeviceBackendTransmitter::instance ())) {
+		// NOTE: The call to RKGraphicsDeviceBackendTransmitter::instance(), here is important beyond error checking. It might *create* the instance and connection, if this is the first use.
+		if (!(dev && RKGraphicsDeviceBackendTransmitter::instance () && desc->init (dev, pointsize, family, bg))) {
 			free (dev);
 			delete (desc);
 			desc = 0;
@@ -103,7 +105,16 @@
 	return R_NilValue;
 }
 
-bool RKGraphicsDeviceDesc::initRDevDesc (pDevDesc dev, double pointsize, rcolor bg) {
+bool RKGraphicsDeviceDesc::init (pDevDesc dev, double pointsize, const QStringList &family, rcolor bg) {
+	default_family = family.value (0, "Helvetica");
+	default_symbol_family = family.value (0, "Symbol");
+	RKD_QueryResolution (&dpix, &dpiy);
+	if (dpix <= 1) dpix = RKGD_DPI;
+	if (dpiy <= 1) dpiy = RKGD_DPI;
+	width *= dpix;
+	height *= dpiy;
+//	Rprintf ("dpi: %d * %d, dims: %f * %f\n", dpix, dpiy, width, height);
+
 	dev->deviceSpecific = (void *) this;
 
 	// pointsize?
@@ -124,17 +135,17 @@
 	dev->right  = dev->clipRight  = width;
 	dev->bottom = dev->clipBottom = height;
 	dev->top    = dev->clipTop    = 0;
-	dev->cra[0] = 0.9 * pointsize * 96/72;
-	dev->cra[1] = 1.2 * pointsize * 96/72;
+	dev->cra[0] = 0.9 * pointsize * (dpix / RKGD_DPI);
+	dev->cra[1] = 1.2 * pointsize * (dpiy / RKGD_DPI);
 	dev->xCharOffset = 0.4900;
 	dev->yCharOffset = 0.3333;
 	dev->yLineBias = 0.1;
-	dev->ipr[0] = 1.0 / RKGD_DPI;
-	dev->ipr[1] = 1.0 / RKGD_DPI;
+	dev->ipr[0] = 1.0 / dpix;
+	dev->ipr[1] = 1.0 / dpiy;
 	/*
 	* Device capabilities
 	*/
-	dev->canClip = FALSE; // FIXME. can clip, but then selection becomes weird
+	dev->canClip = TRUE;
 	dev->canHAdj = 2;
 	dev->canChangeGamma = FALSE;
 	dev->displayListOn = TRUE;
@@ -181,7 +192,7 @@
 	dev->polyline = RKD_Polyline;
 	dev->rect = RKD_Rect;
 	dev->size = RKD_Size;
-	// dev->onexit = RKD_OnExit; NULL is OK
+	// dev->onexit = RKD_OnExit; Called on user interrupts. NULL is OK.
 	// dev->getEvent = SEXP (*getEvent)(SEXP, const char *);
 	dev->raster = RKD_Raster;
 	dev->cap = RKD_Capture;

Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp	2013-04-10 18:01:10 UTC (rev 4683)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp	2013-04-11 10:38:08 UTC (rev 4684)
@@ -73,6 +73,8 @@
 
 private:
 	bool checkHandleInterrupt (QIODevice *connection) {
+		// NOTE: It would be possible, but not exactly easier to rely on GEonExit() rather than R_interrupts_pending
+		// Might be an option, if R_interrupts_pending gets hidden one day, though
 		if (!R_interrupts_pending) return false;
 
 		// Tell the frontend to finish whatever it was doing ASAP. Don't process any other events until that has happened
@@ -128,8 +130,10 @@
 #define WRITE_COLOR_BYTES(col) \
 	if (col == NA_INTEGER) RKD_OUT_STREAM << (quint8) 0xFF << (quint8) 0xFF << (quint8) 0xFF << (quint8) 0x00; \
 	else RKD_OUT_STREAM << (quint8) R_RED (col) << (quint8) R_GREEN (col) << (quint8) R_BLUE (col) << (quint8) R_ALPHA (col)
+#define WRITE_HEADER_NUM(x,devnum) \
+	RKD_OUT_STREAM << (qint8) x << (quint8) devnum
 #define WRITE_HEADER(x,dev) \
-	RKD_OUT_STREAM << (qint8) x << (quint8) static_cast<RKGraphicsDeviceDesc*> (dev->deviceSpecific)->devnum
+	WRITE_HEADER_NUM (x,static_cast<RKGraphicsDeviceDesc*> (dev->deviceSpecific)->devnum)
 #define WRITE_COL() \
 	WRITE_COLOR_BYTES (gc->col)
 #define WRITE_PEN() \
@@ -142,6 +146,19 @@
 #define WRITE_FONT(dev) \
 	RKD_OUT_STREAM << gc->cex << gc->ps << gc->lineheight << (quint8) gc->fontface << (gc->fontfamily[0] ? QString (gc->fontfamily) : (static_cast<RKGraphicsDeviceDesc*> (dev->deviceSpecific)->getFontFamily (gc->fontface == 5)))
 
+static void RKD_QueryResolution (int *dpix, int *dpiy) {
+	{
+		RKGraphicsDataStreamWriteGuard wguard;
+		WRITE_HEADER_NUM (RKDQueryResolution, 0);
+	}
+	{
+		RKGraphicsDataStreamReadGuard rguard;
+		qint32 _dpix, _dpiy;
+		RKD_IN_STREAM >> _dpix >> _dpiy;
+		*dpix = _dpix; *dpiy = _dpiy;
+	}
+}
+
 static void RKD_Create (double width, double height, pDevDesc dev, const char *title, bool antialias) {
 	RKGraphicsDataStreamWriteGuard guard;
 	WRITE_HEADER (RKDCreate, dev);
@@ -260,6 +277,7 @@
 static void RKD_Close (pDevDesc dev) {
 	RKGraphicsDataStreamWriteGuard guard;
 	WRITE_HEADER (RKDClose, dev);
+	delete static_cast<RKGraphicsDeviceDesc*> (dev->deviceSpecific);
 }
 
 static void RKD_Activate (pDevDesc dev) {

Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rpackages/rkward/R/public_graphics.R
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rpackages/rkward/R/public_graphics.R	2013-04-10 18:01:10 UTC (rev 4683)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rpackages/rkward/R/public_graphics.R	2013-04-11 10:38:08 UTC (rev 4684)
@@ -108,7 +108,8 @@
 "RK" <- function (width=getOption("rk.screendevice.width"), height=getOption("rk.screendevice.height"), pointsize=12, family=NULL, bg="white", title="", antialias=TRUE) {
 	if (is.null (width)) width <- 7
 	if (is.null (height)) height <- 7
-	.Call ("rk.graphics.device", as.integer (width), as.integer (height), as.integer (pointsize), family, bg, title, isTRUE (antialias), PACKAGE="(embedding)")
+	ret <- .Call ("rk.graphics.device", as.integer (width), as.integer (height), as.integer (pointsize), family, bg, title, isTRUE (antialias), PACKAGE="(embedding)")
+	inivisble (ret)	# Current always NULL
 }
 
 #' \code{rk.graph.off()} closes the device that was opened by \code{rk.graph.on}. 

Modified: branches/development_branches/rkward_graphpics_device/rkward/windows/rkwindowcatcher.cpp
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/windows/rkwindowcatcher.cpp	2013-04-10 18:01:10 UTC (rev 4683)
+++ branches/development_branches/rkward_graphpics_device/rkward/windows/rkwindowcatcher.cpp	2013-04-11 10:38:08 UTC (rev 4684)
@@ -143,8 +143,8 @@
 RKCaughtX11Window::RKCaughtX11Window (WId window_to_embed, int device_number) : RKMDIWindow (0, X11Window), RCommandReceiver () {
 	RK_TRACE (MISC);
 
+	commonInit (device_number);
 	embedded = window_to_embed;
-	commonInit (device_number);
 
 #ifdef Q_WS_WIN
 	// unfortunately, trying to get KWindowInfo as below hangs on windows (KDElibs 4.2.3)
@@ -178,14 +178,20 @@
 	RK_TRACE (MISC);
 
 	commonInit (device_number);
-	rk_native_device_view = rkward_device->viewPort ();
-	rk_native_device_view->setParent (xembed_container);
+	rk_native_device = rkward_device;
+	xembed_container->setFixedSize (rk_native_device->viewPort ()->size ());
+	rk_native_device->viewPort ()->setParent (xembed_container);
+
+// adjust to size
+//	dynamic_size_action->setChecked (true);
+	fixedSizeToggled ();
 }
 
 void RKCaughtX11Window::commonInit (int device_number) {
 	RK_TRACE (MISC);
 
 	capture = 0;
+	rk_native_device = 0;
 	killed_in_r = false;
 	RKCaughtX11Window::device_number = device_number;
 	RK_ASSERT (!device_windows.contains (device_number));
@@ -268,6 +274,7 @@
 		return RKMDIWindow::close (also_delete);
 	}
 
+	if (rk_native_device) rk_native_device->stopInteraction ();
 	RCommand* c = new RCommand ("dev.off (" + QString::number (device_number) + ')', RCommand::App, i18n ("Shutting down device number %1", device_number), error_dialog);
 	setStatusMessage (i18n ("Closing device (saving history)"), c);
 	RKGlobals::rInterface ()->issueCommand (c);

Modified: branches/development_branches/rkward_graphpics_device/rkward/windows/rkwindowcatcher.h
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/windows/rkwindowcatcher.h	2013-04-10 18:01:10 UTC (rev 4683)
+++ branches/development_branches/rkward_graphpics_device/rkward/windows/rkwindowcatcher.h	2013-04-11 10:38:08 UTC (rev 4684)
@@ -182,7 +182,7 @@
 	// a dummy to make things compile for now
 	QWidget *capture;
 #endif
-	QWidget *rk_native_device_view;
+	RKGraphicsDevice *rk_native_device;
 
 	bool dynamic_size;
 	KToggleAction *dynamic_size_action;





More information about the rkward-tracker mailing list