Skip to content

Commit ae4b16f

Browse files
author
Lionel Laské
committed
Merge branch 'pr/1954' into dev
2 parents f4efca8 + 0ae7d6f commit ae4b16f

File tree

3 files changed

+108
-4
lines changed

3 files changed

+108
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3030
- Use of '=' instead of '==' in if else statement in Physics game activity.js #1870
3131
- Camera remains active when toggling off in QRCode activity (Web/Desktop) #1911
3232
- Delete key deleted wrong character in Calculator #1935
33+
- Fototoon don't handle window resize #559
3334

3435
## [1.9.0] - 2025-03-25
3536
### Added

activities/Fototoon.activity/js/activity.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ define(["sugar-web/activity/activity","sugar-web/datastore","sugar-web/env","tex
4141
mainCanvas.width = mainCanvas.height * 4 / 3;
4242
mainCanvas.style.left = ((window.innerWidth - mainCanvas.width) / 2) + "px";
4343

44+
// Handle window resize
45+
window.addEventListener('resize', function () {
46+
// Calculate new dimensions
47+
var newHeight = window.innerHeight - sugarCellSize - 5;
48+
var newWidth = newHeight * 4 / 3;
49+
50+
// Round to prevent sub-pixel scaling issues with canvas
51+
newWidth = Math.floor(newWidth);
52+
newHeight = Math.floor(newHeight);
53+
54+
// Center the canvas
55+
mainCanvas.style.left = ((window.innerWidth - newWidth) / 2) + "px";
56+
57+
// Call the resize method which preserves state
58+
toonModel.resize(newWidth, newHeight);
59+
});
60+
61+
4462
var previousButton = document.getElementById("previous-button");
4563
previousButton.title = _("Previous");
4664
previousButton.addEventListener('click', function (e) {
@@ -151,8 +169,11 @@ define(["sugar-web/activity/activity","sugar-web/datastore","sugar-web/env","tex
151169

152170
// clone the data to remove the images
153171
var dataWithoutImages = {}
154-
dataWithoutImages['version'] = toonModel.getData()['version'];
155-
dataWithoutImages['boxs'] = toonModel.getData()['boxs'];
172+
var modelData = toonModel.getData();
173+
dataWithoutImages['version'] = modelData['version'];
174+
dataWithoutImages['boxs'] = modelData['boxs'];
175+
dataWithoutImages['canvas_width'] = modelData['canvas_width'];
176+
dataWithoutImages['canvas_height'] = modelData['canvas_height'];
156177

157178
dataImages = {};
158179
for(var key in toonModel.getData()['images']) {
@@ -287,4 +308,4 @@ define(["sugar-web/activity/activity","sugar-web/datastore","sugar-web/env","tex
287308

288309
});
289310

290-
});
311+
});

activities/Fototoon.activity/js/toon.js

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,93 @@ define(["easel","sugar-web/datastore","sugar-web/env","l10n","humane"], function
242242
this._updatePageCounter();
243243
};
244244

245-
this.setData = function(data) {
245+
this._scaleData = function (data, scale) {
246+
console.log("Scaling data by factor: " + scale);
247+
if (!data['boxs']) return;
248+
249+
for (var i = 0; i < data['boxs'].length; i++) {
250+
var box = data['boxs'][i];
251+
252+
// Scale image properties
253+
if (box['img_x'] !== undefined) box['img_x'] *= scale;
254+
if (box['img_y'] !== undefined) box['img_y'] *= scale;
255+
if (box['img_w'] !== undefined) box['img_w'] *= scale;
256+
if (box['img_h'] !== undefined) box['img_h'] *= scale;
257+
258+
// Scale globes
259+
if (box['globes']) {
260+
for (var j = 0; j < box['globes'].length; j++) {
261+
var globe = box['globes'][j];
262+
globe['x'] *= scale;
263+
globe['y'] *= scale;
264+
globe['width'] *= scale;
265+
globe['height'] *= scale;
266+
globe['radio'] *= scale;
267+
268+
if (globe['point_0'] !== undefined) globe['point_0'] *= scale;
269+
if (globe['point_1'] !== undefined) globe['point_1'] *= scale;
270+
271+
// Globe text scaling
272+
if (globe['text_width'] !== undefined) globe['text_width'] *= scale;
273+
if (globe['text_height'] !== undefined) globe['text_height'] *= scale;
274+
275+
// Font scaling
276+
if (globe['text_font_description']) {
277+
// Format: "Sans 30" or "Sans bold 30"
278+
var parts = globe['text_font_description'].split(' ');
279+
var sizeIndex = parts.length - 1;
280+
var size = parseFloat(parts[sizeIndex]);
281+
if (!isNaN(size)) {
282+
parts[sizeIndex] = Math.max(1, Math.round(size * scale));
283+
globe['text_font_description'] = parts.join(' ');
284+
}
285+
}
286+
}
287+
}
288+
}
289+
};
290+
291+
this.setData = function (data) {
246292
this._data = data;
293+
// Check for canvas scaling
294+
if (this._data['canvas_width'] && this._data['canvas_width'] > 0) {
295+
var scale = this._canvas.width / this._data['canvas_width'];
296+
// Allow small epsilon difference
297+
if (Math.abs(scale - 1.0) > 0.01) {
298+
this._scaleData(this._data, scale);
299+
this._data['canvas_width'] = this._canvas.width;
300+
this._data['canvas_height'] = this._canvas.height;
301+
}
302+
} else {
303+
// New or legacy data - assume simple fit or do nothing.
304+
// We just set current dimensions so next save is correct.
305+
this._data['canvas_width'] = this._canvas.width;
306+
this._data['canvas_height'] = this._canvas.height;
307+
}
247308
this._data['previews'] = [];
248309
this.init();
249310
};
311+
this.resize = function (width, height) {
312+
if (this._canvas.width === width && this._canvas.height === height) {
313+
return;
314+
}
315+
// Capture current state from screen before scaling to assume continuity
316+
this.updateData();
317+
318+
var scale = width / this._canvas.width;
319+
320+
// Update canvas dimensions
321+
this._canvas.width = width;
322+
this._canvas.height = height;
323+
324+
// Update underlying data model
325+
this._scaleData(this._data, scale);
326+
this._data['canvas_width'] = width;
327+
this._data['canvas_height'] = height;
328+
329+
// re-init current box
330+
this.comicBox.init(this._data['boxs'][this.activeBox], this._data['images'], (this.activeBox > 0));
331+
};
250332

251333
this.showWait = function () {
252334
this._waitMsg.style.display = 'block';

0 commit comments

Comments
 (0)