diff --git a/bin/mb-canvas b/bin/mb-canvas index cf2d026..b9f6dc1 100755 --- a/bin/mb-canvas +++ b/bin/mb-canvas @@ -2,7 +2,19 @@ ## An Imagemagick Script To Generate Wallpapers. ## Based on https://github.com/adi1090x/canvas by Aditya Shakya (adi1090x) ## Modified by Daniel Napora for Mabox Linux to run from menu +# TODO: add missing options to some effects +# TODO: add ability to pick and use 4 predefined colors +# TODO: choose picker: xcolor or gpick +CONFIG_DIR="$HOME/.config/mbxutils/imgw" +CONFIG_FILE="$CONFIG_DIR/imgw.cfg" +mkdir -p $CONFIG_DIR +if [ ! -f $CONFIG_FILE ]; then +cat < ${CONFIG_FILE} +show_preview=yes +EOF +fi +source <(grep = $CONFIG_FILE) case $LANG in @@ -13,6 +25,9 @@ case $LANG in PICKEDCOLOR="Pobrany kolor" PICKNEXT="Pobierz nastepny" PICKEDALL="Generuję tapetę..." + SETASWP="Ustawić jako tapetę?" + YES="Tak" + NO="Nie" ;; *) IMWG="ImageMagick Wallpaper Generator" @@ -21,6 +36,9 @@ case $LANG in PICKEDCOLOR="Picked color" PICKNEXT="Please pick next..." PICKEDALL="Generating Wallpaper..." + SETASWP="Set as Wallpaper?" + YES="Yes" + NO="No" ;; esac @@ -39,7 +57,25 @@ if [[ ! -d "$DIR" ]]; then fi set_bg() { + if [[ "$show_preview" == "yes" ]];then + X="${size%x*}" + Y="${size#*x}" + P_X=$((X/4)) + P_Y=$((Y/4+30)) + + yad --title="$SETASWP" --window-icon=mbcc --borders=0 --geometry="${P_X}x${P_Y}+200+30" \ + --picture --size=fit --filename="$DIR/$name" \ + --button="$NO":1 --button="$YES":2 \ + + ODP="$?" + + [[ "$ODP" -eq "1" ]] && exit 0 + if [[ "$ODP" -eq "2" ]]; then + $SETTER "$DIR/$name" && exit 0 + fi + else $SETTER "$DIR/$name" + fi } @@ -49,7 +85,7 @@ color_picker() { if [[ "$SOLID" == "true" ]]; then notify-send.sh "$IMWG" "$PICKCOLOR" -i mbcc --expire-time=120000 color=$($picker_app) - elif [[ "$GRADIENT" == "true" ]] || [[ "$RGRADIENT" == "true" ]] || [[ "$TGRADIENT" == "true" ]]; then + elif [[ "$GRADIENT" == "true" ]] || [[ "$RGRADIENT" == "true" ]] || [[ "$TGRADIENT" == "true" ]] || "$PLASMA" == "true" ]]; then notify-send.sh "$IMWG" "$PICKCOLORS: 2" -i mbcc --expire-time=120000 color1=$($picker_app) FNAME="/tmp/${color1:1:6}.png" @@ -110,7 +146,7 @@ linear_gradient() { angle="$RNUM" else get_color - #{ echo; read -p ${ORANGE}"Enter the rotation angle (default is 0): "${BLUE} angle; } + angle=$(yad --center --window-icon=mbcc --title="Linear gradient" --text="\tRotation angle (default is 0):" --width=400 --scale --min-value=0 --max-value=360 --step=45 --enforce-step --inc-buttons) fi name="linear_$name" convert -size "$size" -define gradient:angle="${angle:-0}" gradient:"$color" "$DIR/$name" @@ -132,17 +168,8 @@ radial_gradient() { shape="$RSHAPE" else get_color - { echo; read -p ${ORANGE}"Shape? [ 1.diagonal | 2.ellipse | 3.maximum | 4.minimum ] (1/2/3/4): "${BLUE}; } - if [[ $REPLY == "1" ]]; then - shape='diagonal' - elif [[ $REPLY == "2" ]]; then - shape='ellipse' - elif [[ $REPLY == "3" ]]; then - shape='maximum' - elif [[ $REPLY == "4" ]]; then - shape='minimum' - fi - { echo; read -p ${ORANGE}"Enter the rotation angle (default is 0): "${BLUE} angle; } + shape=$(yad --center --window-icon=mbcc --title='Choose Shape' --width=180 --height=145 --button=Ok:0 --list --no-headers --column=Shape diagonal ellipse maximum minimum | tr -d '|') + angle=$(yad --center --window-icon=mbcc --title="Radial gradient" --text="\tRotation angle:" --width=400 --scale --min-value=0 --max-value=360 --step=45 --enforce-step --inc-buttons) fi name="radial_$name" convert -size "$size" -define gradient:extent="${shape:-maximum}" -define gradient:angle="${angle:-0}" radial-gradient:"$color" "$DIR/$name" @@ -161,7 +188,7 @@ twisted_gradient() { twist="$RNUM" else get_color - { echo; read -p ${ORANGE}"Enter the twisting amount (maximum 500): "${BLUE} twist; } + twist=$(yad --center --window-icon=mbcc --title="Radial gradient" --text="\tTwisting amount (default is 150):" --width=400 --scale --value=150 --min-value=0 --max-value=500 --step=20 --inc-buttons) fi name="twisted_$name" convert -size "$size" gradient:"$color" -swirl "${twist:-150}" "$DIR/$name" @@ -182,17 +209,17 @@ bilinear_gradient() { get_random_number "2" if [[ "$RNUM" == "1" ]]; then - answer="s" + answer="Smooth" else - answer="r" + answer="Regular" fi else get_color - { echo; read -p ${ORANGE}"Smooth or Regular? (s/r): "${BLUE} answer; } + answer=$(yad --title='Choose Style' --width=220 --height=120 --button=Ok:0 --list --no-headers --column=Style Smooth Regular | tr -d '|') fi name="bilinear_$name" - if [[ $answer == "s" ]] || [[ $answer == "S" ]]; then - { echo; echo -n ${CYAN}"Please wait... "; } + if [[ $answer == "Smooth" ]] || [[ $answer == "S" ]]; then + convert \( xc:"$color1" xc:"$color2" +append \) \( xc:"$color3" xc:"$color4" +append \) -append -size "$size" xc: +swap -fx 'v.p{i/(w-1),j/(h-1)}' "$DIR/$name" else convert \( xc:"$color1" xc:"$color2" +append \) \( xc:"$color3" xc:"$color4" +append \) -append -filter triangle -resize "$size"\! "$DIR/$name" @@ -206,9 +233,9 @@ plasma() { get_random_number "3" if [[ "$RNUM" == "1" ]]; then - answer="r" + answer="Random" elif [[ "$RNUM" == "2" ]]; then - answer="t" + answer="Twisted" get_random_number "500" twist="$RNUM" else @@ -217,19 +244,19 @@ plasma() { color="$RCOLOR" fi else - { echo; read -p ${ORANGE}"Random, Twisted or Custom colors? (r/t/c): "${BLUE} answer; } + answer=$(yad --title='Choose Style' --width=190 --height=150 --button=Ok:0 --list --no-headers --column=Style Random Twisted 'Custom colors' | tr -d '|') fi name="plasma_$name" - if [[ $answer == "r" ]] || [[ $answer == "R" ]]; then + if [[ $answer == "r" ]] || [[ $answer == "Random" ]]; then convert -size "$size" plasma: "$DIR/$name" - elif [[ $answer == "t" ]] || [[ $answer == "T" ]]; then + elif [[ $answer == "t" ]] || [[ $answer == "Twisted" ]]; then if [[ "$RANDOMIZE" != "true" ]]; then - { echo; read -p ${ORANGE}"Enter the twisting amount (maximum 500): "${BLUE} twist; } + twist=$(yad --center --window-icon=mbcc --title="Plasma" --text="\tTwisting amount (default is 150):" --width=400 --scale --value=150 --min-value=0 --max-value=500 --step=20 --inc-buttons) fi convert -size "$size" plasma:fractal -swirl "${twist:-150}" "$DIR/$name" else if [[ "$RANDOMIZE" != "true" ]]; then - { echo; read -p ${ORANGE}"Enter the colors name or hex (format: color1-color2): "${GREEN} color; } + get_color fi convert -size "$size" plasma:"$color" "$DIR/$name" fi @@ -309,7 +336,7 @@ randomize() { ## Parse the arguments -options=$(getopt -o S:,s,l,r,t,b,p,B,h,a,R,n --long size:,solid,linear,radial,twisted,bilinear,plasma,blurred,help,autobg,randomize,no-preview -- "$@") +options=$(getopt -o S:,s,l,r,t,b,p,B,h,a,R --long size:,solid,linear,radial,twisted,bilinear,plasma,blurred,help,autobg,randomize -- "$@") eval set -- "$options" while true; do @@ -346,9 +373,6 @@ while true; do -R|--randomize) RANDOMIZE="true" ;; - -n|--no-preview) - NOFEH="true" - ;; -h|--help) usage exit @@ -363,7 +387,6 @@ done ## Main Execution -Prerequisite if [[ "$SOLID" == "true" ]]; then solid