X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=tools%2Fgen-styles;h=23920c54bd29fcf3ac02d22295894b0aebdcbf1c;hb=e7a2fe989ab244998347c82c002e281246916186;hp=21388fe3826d57338a9f9997a82171c27626e42f;hpb=01f62b66cbef1915f20c8b42cab9260efac39498;p=mobile-ledger.git diff --git a/tools/gen-styles b/tools/gen-styles index 21388fe3..23920c54 100644 --- a/tools/gen-styles +++ b/tools/gen-styles @@ -1,10 +1,19 @@ #!/usr/bin/perl -use strict; use warnings; use utf8; +use strict; use warnings; use utf8::all; use autodie; use Math::Trig; use File::Basename qw(basename dirname); use File::Temp qw(tempfile); +use Getopt::Long; + +my $opt_night; + +GetOptions( + 'night!' => \$opt_night, +) or exit 1; + +my $DEFAULT_HUE = 261.2245; sub hexTuple { my ($r, $g, $b) = @_; @@ -84,7 +93,7 @@ sub hexToHSL { my $hexTriplet = shift; my ($r,$g,$b) = hexToRGB($hexTriplet); - warn "$hexTriplet -> $r:$g:$b"; + #warn "$hexTriplet -> $r:$g:$b"; for ($r, $g, $b ) { $_ = $_ / 255.0 } @@ -116,11 +125,11 @@ sub hexToHSL { return( $H, $S, $L ); } -my $baseColorHSV = [ hexToHSL('#935ff2') ]; +my $baseColor = '#935ff2'; +my $baseColorHSV = [ hexToHSL($baseColor) ]; my $baseColorHue = $baseColorHSV->[0]; -warn sprintf( 'H:%1.4f S:%1.4f V:%1.4f', @$baseColorHSV ); -warn sprintf( 'H:%1.4f S:%1.4f L:%1.4f', hexToHSL('#3e148c') ); -my @target = hexToRGB('#935ff2'); +warn sprintf( '%s → H:%1.4f S:%1.4f V:%1.4f', $baseColor, @$baseColorHSV ); +my @target = hexToRGB($baseColor); my ($best, $min_dist); for (my $s = 0.50; $s < 0.90; $s += 0.001) { for ( my $l = 0.50; $l <= 0.80; $l += 0.001 ) { @@ -135,14 +144,16 @@ for (my $s = 0.50; $s < 0.90; $s += 0.001) { } } } -warn sprintf( 's%1.3f, l%1.3f -> %s', +warn sprintf( 's%1.3f, l%1.3f → %s', @$best ); -my $baseTheme = "AppTheme.NoActionBar"; +my $baseTheme = "AppTheme"; + +use constant STEP_DEGREES => 5; # # hsb -# for( my $hue = 0; $hue < 360; $hue += 15 ) { -# printf "\n"; + $result .= sprintf "$indent#%s\n", + 'colorPrimary', hslHex( $hue, $S, $l1 ); + $result .= sprintf "$indent#00%s\n", + 'colorPrimaryTransparent', hslHex( $hue, $S, $l1 ); + $result .= sprintf "$indent#%s\n", + 'colorSecondary', hslHex( $hue, $S, $l2 ); + $result .= sprintf "$indent#%s\n", + 'colorAccent', hslHex( $hue, $S, $l2 ); + $result .= sprintf "$indent#%s\n", + 'colorPrimaryDark', hslHex( $hue, $S, $l2 ); + $result .= sprintf "$indent#%s\n", + 'table_row_dark_bg', hslHex( $hue, $S, $l3 ); + $result .= sprintf "$indent#%s\n", + 'table_row_light_bg', hslHex( $hue, $S, $l4 ); + $result .= "$baseIndent\n"; return $result; } @@ -220,17 +251,20 @@ if ($xml) { my $start_marker = ''; my $end_marker = ''; my ($fh, $filename) = tempfile(basename($0).'.XXXXXXXX', DIR => dirname($xml)); + $fh->binmode(':utf8'); open(my $in, '<', $xml); + my $base_indent = ''; my $state = 'waiting-for-start-marker'; while (<$in>) { if ( $state eq 'waiting-for-start-marker' ) { print $fh $_; - $state = 'skipping-styles' if /^\s*\Q$start_marker\E/; + $state = 'skipping-styles', $base_indent = $1 + if /^(\s*)\Q$start_marker\E/; next; } if ( $state eq 'skipping-styles' ) { next unless /^\s*\Q$end_marker\E/; - outputThemes($fh); + outputThemes($fh, $base_indent); print $fh $_; $state = 'copying-the-rest'; next;