Skip to content

Commit

Permalink
Turtle canvas now handles resize scale and tab switching
Browse files Browse the repository at this point in the history
  • Loading branch information
deadprogram committed May 15, 2011
1 parent 083fd99 commit 6c78183
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
5 changes: 5 additions & 0 deletions public/css/master.css
Expand Up @@ -123,3 +123,8 @@ iframe h1 {
width: 90%;
}

/*canvas {
height: 100%;
width: 100%;
}
*/
25 changes: 14 additions & 11 deletions public/js/app.js
@@ -1,7 +1,5 @@
function selectTab(n) {
if ($("#tabs").data("mytabs").tabs('option', 'selected') != n) {
$("#tabs").data("mytabs").tabs('select', n);
}
$("#tabs").data("mytabs").tabs('select', n);
}

function deleteLastStdIn() {
Expand Down Expand Up @@ -104,6 +102,13 @@ function setTurtleBackground(color) {
$("#turtle").css('backgroundColor', unescape(color));
}

function resizeCanvas() {
var pnl = $("#tabs").find(".ui-tabs-panel:visible");
canvas = document.getElementById( 'turtle-canvas' );
canvas.width = pnl.width();
canvas.height = pnl.height();
}

$(document).ready(function() {
var docWidth = $("body").width();
var docHeight = $(document).height();
Expand Down Expand Up @@ -133,25 +138,23 @@ $(document).ready(function() {
$("#tabs").data("mytabs", tabs);

$("#run").click(function(e) {
resizeCanvas();
startRun(editor);
return false;
});

$("#open").click(function(e) {
openRubyCode(editor);
return false;
});

$("#save").click(function(e) {
saveRubyCode(editor);
return false;
});

$("#turtle").resizable({ stop: function(event, ui) {
$("canvas", this).each(function() {
$(this).attr({ width: ui.size.width, height: ui.size.height });
// Adjusting the width or height attribute clears the canvas of
// its contents, so you are forced to redraw.
reDraw(this);
});
}
$("#turtle").resize(function() {
resizeCanvas();
});

initTurtle();
Expand Down

0 comments on commit 6c78183

Please sign in to comment.