changeset 449:39bef21fe550

svg-edit: patch r722 added (http://code.google.com/p/svg-edit/issues/detail?id=193) Make canvas relatively positioned in workarea, centered in the workarea if small enough
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Thu, 08 Oct 2009 22:49:56 +0200
parents 89b8539eebd9
children ad5213d60ae5
files htdocs/svg-edit/editor/svg-editor.css htdocs/svg-edit/editor/svg-editor.js htdocs/svg-edit/editor/svgcanvas.js
diffstat 3 files changed, 21 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/htdocs/svg-edit/editor/svg-editor.css	Sat Sep 26 19:37:17 2009 +0200
+++ b/htdocs/svg-edit/editor/svg-editor.css	Thu Oct 08 22:49:56 2009 +0200
@@ -36,6 +36,7 @@
 	width: 640px;
 	height: 480px;
 	-apple-dashboard-region:dashboard-region(control rectangle 0px 0px 0px 0px); /* for widget regions that shouldn't react to dragging */
+	position: relative;
 }
 
 #svg_editor div#palette_holder {
--- a/htdocs/svg-edit/editor/svg-editor.js	Sat Sep 26 19:37:17 2009 +0200
+++ b/htdocs/svg-edit/editor/svg-editor.js	Thu Oct 08 22:49:56 2009 +0200
@@ -1228,6 +1228,17 @@
 		$('#svgcanvas').css( { 'width': w, 'height': h } );
 		$('#canvas_width').val(w);
 		$('#canvas_height').val(h);
+		// this centers the canvas in the workarea if it's small enough
+		var wa = {w: parseInt($('#workarea').css('width')),
+				h: parseInt($('#workarea').css('height'))};
+		var ca = {w: parseInt($('#svgcanvas').css('width')),
+				h: parseInt($('#svgcanvas').css('height'))};
+		if (wa.w > ca.w) {
+			$('#svgcanvas').css({'left': (wa.w-ca.w)/2});
+		}
+		if (wa.h > ca.h) {
+			$('#svgcanvas').css({'top': (wa.h-ca.h)/2});
+		}
 		if(center) {
 			var w_area = $('#workarea');
 			var scroll_y = h/2 - w_area.height()/2;
@@ -1270,7 +1281,8 @@
 			svgCanvas.bind("saved", opts.save);
 		}
 	}
-	
+	// set starting resolution (centers canvas)
+	setResolution(640,480);
 	return svgCanvas;
 };
 
--- a/htdocs/svg-edit/editor/svgcanvas.js	Sat Sep 26 19:37:17 2009 +0200
+++ b/htdocs/svg-edit/editor/svgcanvas.js	Thu Oct 08 22:49:56 2009 +0200
@@ -1397,9 +1397,9 @@
 	//   and do nothing else
 	var mouseDown = function(evt)
 	{
-		var mouse_x = evt.pageX - container.parentNode.offsetLeft + container.parentNode.scrollLeft;
-		var mouse_y = evt.pageY - container.parentNode.offsetTop + container.parentNode.scrollTop;
-		
+		console.dir(container);
+		var mouse_x = evt.pageX - container.parentNode.offsetLeft + container.parentNode.scrollLeft - container.offsetLeft;
+		var mouse_y = evt.pageY - container.parentNode.offsetTop + container.parentNode.scrollTop - container.offsetTop;	
 		evt.preventDefault();
     
 		if($.inArray(current_mode, ['select', 'resize']) == -1) {
@@ -1682,8 +1682,8 @@
 	{
 		if (!started) return;
 		var selected = selectedElements[0];
-		var mouse_x = evt.pageX - container.parentNode.offsetLeft + container.parentNode.scrollLeft;
-		var mouse_y = evt.pageY - container.parentNode.offsetTop + container.parentNode.scrollTop;
+		var mouse_x = evt.pageX - container.parentNode.offsetLeft + container.parentNode.scrollLeft - container.offsetLeft;
+		var mouse_y = evt.pageY - container.parentNode.offsetTop + container.parentNode.scrollTop - container.offsetTop;
 		var shape = svgdoc.getElementById(getId());
     
     	x = mouse_x / current_zoom;
@@ -2099,8 +2099,8 @@
 		justSelected = null;
 		if (!started) return;
 
-		var mouse_x = evt.pageX - container.parentNode.offsetLeft + container.parentNode.scrollLeft;
-		var mouse_y = evt.pageY - container.parentNode.offsetTop + container.parentNode.scrollTop;
+		var mouse_x = evt.pageX - container.parentNode.offsetLeft + container.parentNode.scrollLeft - container.offsetLeft;
+		var mouse_y = evt.pageY - container.parentNode.offsetTop + container.parentNode.scrollTop - container.offsetTop;
 		var x = mouse_x / current_zoom;
 		var y = mouse_y / current_zoom;