2012-08-14 23:17:19 +02:00
|
|
|
#!/usr/bin/env php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once dirname(dirname(__FILE__)).'/__init_script__.php';
|
|
|
|
|
|
|
|
$args = new PhutilArgumentParser($argv);
|
|
|
|
$args->setTagline('regenerate CSS sprite sheets');
|
|
|
|
$args->setSynopsis(<<<EOHELP
|
|
|
|
**sprites**
|
|
|
|
Rebuild CSS sprite sheets.
|
|
|
|
|
|
|
|
EOHELP
|
|
|
|
);
|
|
|
|
$args->parseStandardArguments();
|
|
|
|
$args->parse(
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'name' => 'source',
|
|
|
|
'param' => 'directory',
|
|
|
|
'help' => 'Directory with sprite sources.',
|
2012-11-27 23:03:25 +01:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'force',
|
|
|
|
'help' => 'Force regeneration even if sources have not changed.',
|
|
|
|
),
|
2012-08-14 23:17:19 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
$srcroot = $args->getArg('source');
|
|
|
|
if (!$srcroot) {
|
|
|
|
throw new Exception(
|
|
|
|
"You must specify a source directory with '--source'.");
|
|
|
|
}
|
|
|
|
|
2012-11-24 01:35:39 +01:00
|
|
|
$root = dirname(phutil_get_library_root('phabricator'));
|
|
|
|
$webroot = $root.'/webroot/rsrc';
|
2012-08-14 23:17:19 +02:00
|
|
|
$webroot = Filesystem::readablePath($webroot);
|
|
|
|
|
|
|
|
function glx($x) {
|
|
|
|
return (60 + (48 * $x));
|
|
|
|
}
|
|
|
|
|
|
|
|
function gly($y) {
|
|
|
|
return (110 + (48 * $y));
|
|
|
|
}
|
|
|
|
|
|
|
|
$sheet = new PhutilSpriteSheet();
|
2012-10-01 21:45:42 +02:00
|
|
|
$at = '@';
|
2012-08-14 23:23:55 +02:00
|
|
|
$sheet->setCSSHeader(<<<EOCSS
|
2012-08-14 23:17:19 +02:00
|
|
|
/**
|
|
|
|
* @provides autosprite-css
|
2012-10-01 21:45:42 +02:00
|
|
|
* {$at}generated
|
2012-08-14 23:17:19 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
.autosprite {
|
2012-08-14 23:23:55 +02:00
|
|
|
background-image: url(/rsrc/image/autosprite.png);
|
2012-08-14 23:17:19 +02:00
|
|
|
background-repeat: no-repeat;
|
|
|
|
}
|
|
|
|
EOCSS
|
|
|
|
);
|
|
|
|
|
|
|
|
$menu_normal_template = id(new PhutilSprite())
|
|
|
|
->setSourceFile($srcroot.'/menu_normal_1x.png')
|
2012-11-24 01:19:06 +01:00
|
|
|
->setSourceSize(30, 30);
|
2012-08-14 23:17:19 +02:00
|
|
|
|
|
|
|
$menu_hover_template = id(new PhutilSprite())
|
|
|
|
->setSourceFile($srcroot.'/menu_hover_1x.png')
|
2012-11-24 01:19:06 +01:00
|
|
|
->setSourceSize(30, 30);
|
2012-08-14 23:17:19 +02:00
|
|
|
|
|
|
|
$menu_selected_template = id(new PhutilSprite())
|
|
|
|
->setSourceFile($srcroot.'/menu_selected_1x.png')
|
2012-11-24 01:19:06 +01:00
|
|
|
->setSourceSize(30, 30);
|
2012-08-14 23:17:19 +02:00
|
|
|
|
|
|
|
$menu_map = array(
|
|
|
|
'' => $menu_normal_template,
|
|
|
|
'-selected' => $menu_selected_template,
|
|
|
|
':hover' => $menu_hover_template,
|
|
|
|
);
|
|
|
|
|
|
|
|
$icon_map = array(
|
|
|
|
'help' => array(4, 19),
|
|
|
|
'settings' => array(0, 28),
|
|
|
|
'logout' => array(3, 6),
|
|
|
|
'task' => array(1, 15),
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($icon_map as $icon => $coords) {
|
|
|
|
list($x, $y) = $coords;
|
|
|
|
foreach ($menu_map as $suffix => $template) {
|
|
|
|
$sheet->addSprite(
|
|
|
|
id(clone $template)
|
2012-12-07 22:35:49 +01:00
|
|
|
->setName('menu-item-'.$icon.'-'.$suffix)
|
2012-08-14 23:17:19 +02:00
|
|
|
->setSourcePosition(glx($x), gly($y))
|
|
|
|
->setTargetCSS('.main-menu-item-icon-'.$icon.$suffix));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-06 23:48:46 +02:00
|
|
|
$app_template_large = id(new PhutilSprite())
|
|
|
|
->setSourceFile($srcroot.'/application_large_1x.png')
|
2012-08-14 23:17:19 +02:00
|
|
|
->setSourceSize(60, 60);
|
|
|
|
|
2012-10-06 23:48:46 +02:00
|
|
|
$app_template_large_hover = id(new PhutilSprite())
|
|
|
|
->setSourceFile($srcroot.'/application_large_hover_1x.png')
|
|
|
|
->setSourceSize(60, 60);
|
|
|
|
|
|
|
|
$app_template_small = id(new PhutilSprite())
|
2012-08-20 23:13:15 +02:00
|
|
|
->setSourceFile($srcroot.'/menu_normal_1x.png')
|
2012-08-14 23:23:55 +02:00
|
|
|
->setSourceSize(30, 30);
|
2012-08-14 23:17:19 +02:00
|
|
|
|
2012-10-06 23:48:46 +02:00
|
|
|
$app_template_small_hover = id(new PhutilSprite())
|
|
|
|
->setSourceFile($srcroot.'/menu_hover_1x.png')
|
|
|
|
->setSourceSize(30, 30);
|
|
|
|
|
|
|
|
$app_template_small_selected = id(new PhutilSprite())
|
|
|
|
->setSourceFile($srcroot.'/menu_selected_1x.png')
|
|
|
|
->setSourceSize(30, 30);
|
|
|
|
|
2012-08-14 23:17:19 +02:00
|
|
|
$app_source_map = array(
|
2012-10-06 23:48:46 +02:00
|
|
|
'-large' => array($app_template_large, 2),
|
|
|
|
|
|
|
|
// For the application launch view, we only show hover state on the desktop
|
|
|
|
// because it looks glitchy on touch devices. We show the hover state when
|
|
|
|
// the surrounding <a> is hovered, not the icon itself.
|
|
|
|
'-large /* hover */' => array(
|
|
|
|
$app_template_large_hover,
|
|
|
|
2,
|
|
|
|
'.device-desktop .phabricator-application-launch-container:hover '),
|
|
|
|
|
|
|
|
'' => array($app_template_small, 1),
|
|
|
|
|
|
|
|
// Show hover state only for the desktop.
|
|
|
|
':hover' => array(
|
|
|
|
$app_template_small_hover,
|
|
|
|
1,
|
|
|
|
'.device-desktop ',
|
|
|
|
),
|
|
|
|
'-selected' => array($app_template_small_selected, 1),
|
2012-08-14 23:17:19 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$app_map = array(
|
|
|
|
'differential' => array(9, 1),
|
|
|
|
'fact' => array(2, 4),
|
|
|
|
'mail' => array(0, 1),
|
|
|
|
'diffusion' => array(7, 13),
|
|
|
|
'slowvote' => array(1, 4),
|
|
|
|
'phriction' => array(1, 7),
|
|
|
|
'maniphest' => array(3, 24),
|
|
|
|
'flags' => array(6, 26),
|
|
|
|
'settings' => array(9, 11),
|
|
|
|
'applications' => array(0, 34),
|
|
|
|
'default' => array(9, 9),
|
|
|
|
'people' => array(3, 0),
|
|
|
|
'ponder' => array(4, 35),
|
|
|
|
'calendar' => array(5, 4),
|
|
|
|
'files' => array(6, 3),
|
|
|
|
'projects' => array(7, 35),
|
|
|
|
'daemons' => array(7, 6),
|
|
|
|
'herald' => array(1, 5),
|
|
|
|
'countdown' => array(7, 5),
|
|
|
|
'conduit' => array(7, 30),
|
|
|
|
'feed' => array(3, 11),
|
2012-08-15 19:45:06 +02:00
|
|
|
'paste' => array(9, 2),
|
2012-08-20 23:13:15 +02:00
|
|
|
'audit' => array(8, 19),
|
2012-09-11 18:56:40 +02:00
|
|
|
'uiexample' => array(7, 28),
|
2012-10-01 21:56:33 +02:00
|
|
|
'phpast' => array(6, 31),
|
|
|
|
'owners' => array(5, 32),
|
|
|
|
'phid' => array(9, 25),
|
|
|
|
'diviner' => array(1, 35),
|
|
|
|
'repositories' => array(8, 13),
|
2012-10-01 22:53:16 +02:00
|
|
|
'phame' => array(8, 4),
|
2012-10-01 23:04:03 +02:00
|
|
|
'macro' => array(0, 31),
|
2012-10-22 00:56:17 +02:00
|
|
|
'releeph' => array(5, 18),
|
2012-10-31 17:57:57 +01:00
|
|
|
'drydock' => array(5, 25),
|
2012-08-14 23:17:19 +02:00
|
|
|
);
|
|
|
|
|
2012-08-14 23:23:55 +02:00
|
|
|
$xadj = -1;
|
2012-08-14 23:17:19 +02:00
|
|
|
foreach ($app_map as $icon => $coords) {
|
|
|
|
list($x, $y) = $coords;
|
|
|
|
foreach ($app_source_map as $suffix => $spec) {
|
|
|
|
list($template, $scale) = $spec;
|
2012-10-06 23:48:46 +02:00
|
|
|
if (isset($spec[2])) {
|
|
|
|
$prefix = $spec[2];
|
|
|
|
} else {
|
|
|
|
$prefix = '';
|
|
|
|
}
|
2012-08-14 23:17:19 +02:00
|
|
|
$sheet->addSprite(
|
|
|
|
id(clone $template)
|
2012-12-07 22:35:49 +01:00
|
|
|
->setName('app-'.$icon.'-'.$suffix)
|
2012-08-14 23:23:55 +02:00
|
|
|
->setSourcePosition(($xadj + glx($x)) * $scale, gly($y) * $scale)
|
2012-10-06 23:48:46 +02:00
|
|
|
->setTargetCSS($prefix.'.app-'.$icon.$suffix));
|
2012-08-14 23:17:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-24 01:19:06 +01:00
|
|
|
$sheet->generateImage($webroot.'/image/autosprite.png');
|
|
|
|
$sheet->generateCSS($webroot.'/css/autosprite.css');
|
2012-10-07 01:21:25 +02:00
|
|
|
|
|
|
|
|
2012-11-24 01:19:06 +01:00
|
|
|
/* -( Icons Sheet )-------------------------------------------------------- */
|
2012-10-07 01:21:25 +02:00
|
|
|
|
2012-11-24 01:19:06 +01:00
|
|
|
$generator = new CeleritySpriteGenerator();
|
2012-10-07 01:21:25 +02:00
|
|
|
|
2012-11-27 23:03:25 +01:00
|
|
|
$sheets = array(
|
|
|
|
'icon' => $generator->buildIconSheet(),
|
|
|
|
'menu' => $generator->buildMenuSheet(),
|
2012-12-07 22:35:49 +01:00
|
|
|
'gradient' => $generator->buildGradientSheet(),
|
2012-11-27 23:03:25 +01:00
|
|
|
);
|
|
|
|
|
2012-12-07 22:36:35 +01:00
|
|
|
list($err) = exec_manual('optipng');
|
|
|
|
if ($err) {
|
|
|
|
$have_optipng = false;
|
|
|
|
echo phutil_console_format(
|
|
|
|
"<bg:red> WARNING </bg> `optipng` not found in PATH.\n".
|
|
|
|
"Sprites will not be optimized! Install `optipng`!\n");
|
|
|
|
} else {
|
|
|
|
$have_optipng = true;
|
|
|
|
}
|
|
|
|
|
2012-11-27 23:03:25 +01:00
|
|
|
foreach ($sheets as $name => $sheet) {
|
|
|
|
$manifest_path = $root.'/resources/sprite/manifest/'.$name.'.json';
|
|
|
|
if (!$args->getArg('force')) {
|
|
|
|
if (Filesystem::pathExists($manifest_path)) {
|
|
|
|
$data = Filesystem::readFile($manifest_path);
|
|
|
|
$data = json_decode($data, true);
|
|
|
|
if (!$sheet->needsRegeneration($data)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$sheet
|
|
|
|
->generateCSS($webroot."/css/sprite-{$name}.css")
|
|
|
|
->generateManifest($root."/resources/sprite/manifest/{$name}.json");
|
2012-12-07 22:35:49 +01:00
|
|
|
|
|
|
|
foreach ($sheet->getScales() as $scale) {
|
|
|
|
if ($scale == 1) {
|
|
|
|
$sheet_name = "sprite-{$name}.png";
|
|
|
|
} else {
|
|
|
|
$sheet_name = "sprite-{$name}-X{$scale}.png";
|
|
|
|
}
|
2012-12-07 22:36:35 +01:00
|
|
|
|
|
|
|
$full_path = "{$webroot}/image/{$sheet_name}";
|
|
|
|
$sheet->generateImage($full_path, $scale);
|
|
|
|
|
|
|
|
if ($have_optipng) {
|
|
|
|
echo "Optimizing...\n";
|
|
|
|
phutil_passthru('optipng -o7 -clobber %s', $full_path);
|
|
|
|
}
|
2012-12-07 22:35:49 +01:00
|
|
|
}
|
2012-11-27 23:03:25 +01:00
|
|
|
}
|
2012-08-14 23:17:19 +02:00
|
|
|
|
|
|
|
echo "Done.\n";
|