2011-12-23 12:59:20 -05:00
|
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
2012-03-18 03:54:46 -04:00
|
|
|
|
const Cogl = imports.gi.Cogl;
|
2011-12-23 12:59:20 -05:00
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
|
const St = imports.gi.St;
|
|
|
|
|
|
|
|
|
|
const UI = imports.testcommon.ui;
|
|
|
|
|
|
|
|
|
|
UI.init();
|
|
|
|
|
let stage = Clutter.Stage.get_default();
|
2012-03-18 04:13:19 -04:00
|
|
|
|
stage.user_resizable = true;
|
2011-12-23 12:59:20 -05:00
|
|
|
|
stage.width = 1024;
|
|
|
|
|
stage.height = 768;
|
|
|
|
|
|
2012-03-18 04:13:19 -04:00
|
|
|
|
let vbox = new St.BoxLayout({ style: 'background: #ffee88;' });
|
|
|
|
|
vbox.add_constraint(new Clutter.BindConstraint({ source: stage,
|
|
|
|
|
coordinate: Clutter.BindCoordinate.SIZE }));
|
2011-12-23 12:59:20 -05:00
|
|
|
|
stage.add_actor(vbox);
|
|
|
|
|
|
|
|
|
|
let scroll = new St.ScrollView();
|
|
|
|
|
vbox.add(scroll, { expand: true });
|
|
|
|
|
|
|
|
|
|
let vbox = new St.BoxLayout({ vertical: true,
|
|
|
|
|
style: 'padding: 10px;'
|
|
|
|
|
+ 'spacing: 20px;' });
|
|
|
|
|
scroll.add_actor(vbox);
|
|
|
|
|
|
|
|
|
|
let tbox = null;
|
|
|
|
|
|
2012-03-18 03:54:46 -04:00
|
|
|
|
function addTestCase(image, size, backgroundSize, useCairo) {
|
|
|
|
|
// Using a border in CSS forces cairo rendering.
|
|
|
|
|
// To get a border using cogl, we paint a border using
|
|
|
|
|
// paint signal hacks.
|
|
|
|
|
|
|
|
|
|
let obin = new St.Bin();
|
|
|
|
|
if (useCairo)
|
|
|
|
|
obin.style = 'border: 3px solid green;';
|
|
|
|
|
else
|
|
|
|
|
obin.connect_after('paint', function(actor) {
|
|
|
|
|
Cogl.set_source_color4f(0, 1, 0, 1);
|
|
|
|
|
|
|
|
|
|
let geom = actor.get_allocation_geometry();
|
|
|
|
|
let width = 3;
|
|
|
|
|
|
|
|
|
|
// clockwise order
|
|
|
|
|
Cogl.rectangle(0, 0, geom.width, width);
|
|
|
|
|
Cogl.rectangle(geom.width - width, width,
|
|
|
|
|
geom.width, geom.height);
|
|
|
|
|
Cogl.rectangle(0, geom.height,
|
|
|
|
|
geom.width - width, geom.height - width);
|
|
|
|
|
Cogl.rectangle(0, geom.height - width,
|
|
|
|
|
width, width);
|
|
|
|
|
});
|
2011-12-23 12:59:20 -05:00
|
|
|
|
tbox.add(obin);
|
|
|
|
|
|
2012-03-18 04:13:19 -04:00
|
|
|
|
let [width, height] = size;
|
2011-12-23 12:59:20 -05:00
|
|
|
|
let bin = new St.Bin({ style_class: 'background-image-' + image,
|
2012-03-18 04:13:19 -04:00
|
|
|
|
width: width,
|
|
|
|
|
height: height,
|
2011-12-23 12:59:20 -05:00
|
|
|
|
style: 'border: 1px solid transparent;'
|
|
|
|
|
+ 'background-size: ' + backgroundSize + ';',
|
|
|
|
|
x_fill: true,
|
|
|
|
|
y_fill: true
|
|
|
|
|
});
|
|
|
|
|
obin.set_child(bin);
|
|
|
|
|
|
2012-03-18 03:54:46 -04:00
|
|
|
|
bin.set_child(new St.Label({ text: backgroundSize + (useCairo ? ' (cairo)' : ' (cogl)'),
|
2011-12-23 12:59:20 -05:00
|
|
|
|
style: 'font-size: 15px;'
|
|
|
|
|
+ 'text-align: center;'
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-18 04:13:19 -04:00
|
|
|
|
function addTestLine(image, size, useCairo) {
|
|
|
|
|
const backgroundSizes = ["auto", "contain", "cover", "200px 200px", "100px 100px", "100px 200px"];
|
|
|
|
|
|
|
|
|
|
let [width, height] = size;
|
|
|
|
|
vbox.add(new St.Label({ text: image + '.svg / ' + width + '×' + height,
|
2011-12-23 12:59:20 -05:00
|
|
|
|
style: 'font-size: 15px;'
|
|
|
|
|
+ 'text-align: center;'
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
tbox = new St.BoxLayout({ style: 'spacing: 20px;' });
|
|
|
|
|
vbox.add(tbox);
|
|
|
|
|
|
|
|
|
|
for each (let s in backgroundSizes)
|
2012-03-18 03:54:46 -04:00
|
|
|
|
addTestCase(image, size, s, false);
|
|
|
|
|
for each (let s in backgroundSizes)
|
|
|
|
|
addTestCase(image, size, s, true);
|
2011-12-23 12:59:20 -05:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-18 04:13:19 -04:00
|
|
|
|
function addTestImage(image) {
|
|
|
|
|
const containerSizes = [[100, 100], [200, 200], [250, 250], [100, 250], [250, 100]];
|
2011-12-23 12:59:20 -05:00
|
|
|
|
|
2012-03-18 04:13:19 -04:00
|
|
|
|
for each (let size in containerSizes)
|
|
|
|
|
addTestLine(image, size);
|
|
|
|
|
}
|
2011-12-23 12:59:20 -05:00
|
|
|
|
|
2012-03-18 04:13:19 -04:00
|
|
|
|
addTestImage ('200-200');
|
|
|
|
|
addTestImage ('200-100');
|
|
|
|
|
addTestImage ('100-200');
|
2011-12-23 12:59:20 -05:00
|
|
|
|
|
|
|
|
|
stage.show();
|
|
|
|
|
Clutter.main();
|
|
|
|
|
stage.destroy();
|