mirror of
https://github.com/brl/mutter.git
synced 2024-12-24 12:02:04 +00:00
test-text-perf: Scale the text if the settings will not fit
If the font size or the number of characters causes the label not to fit on the stage, instead of aborting it will now scale the labels so that it fits within one of the dimensions. This makes it easier to test with large glyph sizes.
This commit is contained in:
parent
89c535f50d
commit
c26d2c5ef9
@ -75,6 +75,7 @@ main (int argc, char *argv[])
|
||||
ClutterActor *label;
|
||||
int w, h;
|
||||
int row, col;
|
||||
float scale = 1.0f;
|
||||
|
||||
g_setenv ("CLUTTER_VBLANK", "none", FALSE);
|
||||
g_setenv ("CLUTTER_DEFAULT_FPS", "1000", FALSE);
|
||||
@ -101,21 +102,43 @@ main (int argc, char *argv[])
|
||||
label = create_label ();
|
||||
w = clutter_actor_get_width (label);
|
||||
h = clutter_actor_get_height (label);
|
||||
cols = STAGE_WIDTH / w;
|
||||
rows = STAGE_HEIGHT / h;
|
||||
clutter_actor_destroy (label);
|
||||
|
||||
if (cols == 0 || rows == 0)
|
||||
/* If the label is too big to fit on the stage then scale it so that
|
||||
it will fit */
|
||||
if (w > STAGE_WIDTH || h > STAGE_HEIGHT)
|
||||
{
|
||||
g_printerr("Too many characters to fit in stage\n");
|
||||
exit(1);
|
||||
float x_scale = STAGE_WIDTH / (float) w;
|
||||
float y_scale = STAGE_HEIGHT / (float) h;
|
||||
|
||||
if (x_scale < y_scale)
|
||||
{
|
||||
scale = x_scale;
|
||||
cols = 1;
|
||||
rows = STAGE_HEIGHT / (h * scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
scale = y_scale;
|
||||
cols = STAGE_WIDTH / (w * scale);
|
||||
rows = 1;
|
||||
}
|
||||
|
||||
g_print ("Text scaled by %f to fit on the stage\n", scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
cols = STAGE_WIDTH / w;
|
||||
rows = STAGE_HEIGHT / h;
|
||||
}
|
||||
|
||||
clutter_actor_destroy (label);
|
||||
|
||||
for (row=0; row<rows; row++)
|
||||
for (col=0; col<cols; col++)
|
||||
{
|
||||
label = create_label();
|
||||
clutter_actor_set_position (label, w * col, h * row);
|
||||
clutter_actor_set_scale (label, scale, scale);
|
||||
clutter_actor_set_position (label, w * col * scale, h * row * scale);
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), label);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user