private function buildSheet($name, $has_retina, $type = null, $extra_css = '')
    {
        $sheet = new PhutilSpriteSheet();
        $at = '@';
        switch ($type) {
            case PhutilSpriteSheet::TYPE_STANDARD:
            default:
                $type = PhutilSpriteSheet::TYPE_STANDARD;
                $repeat_rule = 'no-repeat';
                break;
            case PhutilSpriteSheet::TYPE_REPEAT_X:
                $repeat_rule = 'repeat-x';
                break;
            case PhutilSpriteSheet::TYPE_REPEAT_Y:
                $repeat_rule = 'repeat-y';
                break;
        }
        $retina_rules = null;
        if ($has_retina) {
            $retina_rules = <<<EOCSS
@media
only screen and (min-device-pixel-ratio: 1.5),
only screen and (-webkit-min-device-pixel-ratio: 1.5),
only screen and (min-resolution: 1.5dppx) {
  .sprite-{$name}{$extra_css} {
    background-image: url(/rsrc/image/sprite-{$name}-X2.png);
    background-size: {X}px {Y}px;
  }
}
EOCSS;
        }
        $sheet->setSheetType($type);
        $sheet->setCSSHeader(<<<EOCSS
/**
 * @provides sprite-{$name}-css
 * {$at}generated
 */

.sprite-{$name}{$extra_css} {
  background-image: url(/rsrc/image/sprite-{$name}.png);
  background-repeat: {$repeat_rule};
}

{$retina_rules}

EOCSS
);
        return $sheet;
    }
예제 #2
0
$args->parse(array(array('name' => 'source', 'param' => 'directory', 'help' => 'Directory with sprite sources.')));
$srcroot = $args->getArg('source');
if (!$srcroot) {
    throw new Exception("You must specify a source directory with '--source'.");
}
$webroot = dirname(phutil_get_library_root('phabricator')) . '/webroot/rsrc';
$webroot = Filesystem::readablePath($webroot);
function glx($x)
{
    return 60 + 48 * $x;
}
function gly($y)
{
    return 110 + 48 * $y;
}
$sheet = new PhutilSpriteSheet();
$at = '@';
$sheet->setCSSHeader(<<<EOCSS
/**
 * @provides autosprite-css
 * {$at}generated
 */

.autosprite {
  background-image: url(/rsrc/image/autosprite.png);
  background-repeat: no-repeat;
}
EOCSS
);
$menu_normal_template = id(new PhutilSprite())->setSourceFile($srcroot . '/menu_normal_1x.png')->setSourceSize(26, 26);
$menu_hover_template = id(new PhutilSprite())->setSourceFile($srcroot . '/menu_hover_1x.png')->setSourceSize(26, 26);