# An FvwmScript GUI to change colorsets
# I can't believe how big this is
# I haven't got the energy to implement a Save button
# Just goes to show that command lines are better
# Don't switch on Dynamic update unless using ReadWriteColors
WindowTitle	{Colorset Editor}
WindowSize	380 290
Colorset 0

Init
 Begin
  # This is the colorset being worked on
  Set $Cset = 0
  Set $OldCset = 0
  Set $Color = (GetBack 1)
  Do {Colorset } $Cset { Pixmap, Background #} $Color {, Foreground Contrast}
  # Sliders are initially hidden
  HideWidget 1
  HideWidget 2
  HideWidget 3
  HideWidget 21
  HideWidget 22
  HideWidget 23
 End

# radio buttons to pick the colorset aspect to change
Widget 13
Property
 Position	120 10
 Type		RadioButton
 Title		{Background}
Main
 Case message of
 SingleClic :
 Begin
  Set $Color = (GetBack 1)
  ChangeValue 1 (HexToNum (StrCopy $Color 1 2))
  ChangeValue 2 (HexToNum (StrCopy $Color 3 4))
  ChangeValue 3 (HexToNum (StrCopy $Color 5 6))
  ChangeValue 10 0
  ChangeValue 11 0
  ChangeValue 12 0
  ShowWidget 1
  ShowWidget 2
  ShowWidget 3
  ShowWidget 21
  ShowWidget 22
  ShowWidget 23
 End
End

Widget 10
Property
 Position	220 10
 Type		RadioButton
 Title		{Foreground}
Main
 Case message of
 SingleClic :
 Begin
  Set $Color = (GetFore 1)
  ChangeValue 1 (HexToNum (StrCopy $Color 1 2))
  ChangeValue 2 (HexToNum (StrCopy $Color 3 4))
  ChangeValue 3 (HexToNum (StrCopy $Color 5 6))
  ChangeValue 11 0
  ChangeValue 12 0
  ChangeValue 13 0
  ShowWidget 1
  ShowWidget 2
  ShowWidget 3
  ShowWidget 21
  ShowWidget 22
  ShowWidget 23
 End
End

Widget 11
Property
 Position	120 30
 Type		RadioButton
 Title		{Hilite}
Main
 Case message of
 SingleClic :
 Begin
  Set $Color = (GetHilight 1)
  ChangeValue 1 (HexToNum (StrCopy $Color 1 2))
  ChangeValue 2 (HexToNum (StrCopy $Color 3 4))
  ChangeValue 3 (HexToNum (StrCopy $Color 5 6))
  ChangeValue 10 0
  ChangeValue 12 0
  ChangeValue 13 0
  ShowWidget 1
  ShowWidget 2
  ShowWidget 3
  ShowWidget 21
  ShowWidget 22
  ShowWidget 23
 End
End

Widget 12
Property
 Position	220 30
 Type		RadioButton
 Title		{Shadow}
Main
 Case message of
 SingleClic :
 Begin
  Set $Color = (GetShadow 1)
  ChangeValue 1 (HexToNum (StrCopy $Color 1 2))
  ChangeValue 2 (HexToNum (StrCopy $Color 3 4))
  ChangeValue 3 (HexToNum (StrCopy $Color 5 6))
  ChangeValue 10 0
  ChangeValue 11 0
  ChangeValue 13 0
  ShowWidget 1
  ShowWidget 2
  ShowWidget 3
  ShowWidget 21
  ShowWidget 22
  ShowWidget 23
 End
End

# colorset selector
# miniscrolls clic on button press and release hence the (div x 2)
# and they roll over which is bad for defining colorsets
Widget 4
Property
 Position       10 10
 Type           MiniScroll
 Value		0
 MinValue	0
 MaxValue	101
Main
 Case message of
 SingleClic :
 Begin
  # hold at max value
  If (GetValue 4) == 100 Then
   ChangeValue 4 99
  # hold at min value
  If (GetValue 4) > 100 Then
   ChangeValue 4 0
  Set $OldCset = $Cset
  Set $Cset = (Div (GetValue 4) 2)
  Set $CsetName = {Colorset } $Cset
  ChangeTitle 5 $CsetName
  # redisplay in new colorset
  ChangeColorset 0 $Cset
  ChangeColorset 1 $Cset
  ChangeColorset 2 $Cset
  ChangeColorset 3 $Cset
  ChangeColorset 4 $Cset
  ChangeColorset 5 $Cset
  ChangeColorset 6 $Cset
  ChangeColorset 7 $Cset
  ChangeColorset 10 $Cset
  ChangeColorset 11 $Cset
  ChangeColorset 12 $Cset
  ChangeColorset 13 $Cset
  ChangeColorset 21 $Cset
  ChangeColorset 22 $Cset
  ChangeColorset 23 $Cset
  ChangeColorset 0 $Cset
  # unselect all radio buttons
  ChangeValue 10 0
  ChangeValue 11 0
  ChangeValue 12 0
  ChangeValue 13 0
  # hide the sliders
  HideWidget 1
  HideWidget 2
  HideWidget 3
  HideWidget 21
  HideWidget 22
  HideWidget 23
  # change current colorset to be just plain
  If $OldCset == $Cset Then
   Begin
   End
  Else
   Begin
    # I think there might be a bug in Colorset that resets a colorset to a copy of 0
    # if {pixmap} is used to select a plain background
    Set $Color = (GetBack 1)
    Do {Colorset } $Cset { Pixmap, Background #} $Color {, Foreground Contrast}
    Set $OldCset = $Cset
   End
 End
End

# Example
Widget 5
Property
 Size           80 34
 Position       29 10
 Type           ItemDraw
 Title		{Colorset 0}
End

# auto apply selector
# handles signals from color selectors and passes them on to the apply
# button if enabled
Widget 6
Property
 Position       120 250
 Type           CheckBox
 Title		{Auto Apply}
Main
 Case message of
 1 :
 Begin
  If (GetValue 6) == 1 Then
   SendSignal 7 1
 End
End

# apply button (does the main processing)
# sends a signal to itself when clicked
# sets the colorset when it receives a signal
Widget 7
Property
 Position       10 250
 Type           PushButton
 Title		{Apply}
Main
 Case message of
 SingleClic :
 Begin
  SendSignal 7 1
 End
 1 :
 Begin
  # calculate the current color in RGB hex terms
  Set $Color = {rgb:} (NumToHex (GetValue 1) 2)
  Set $Color = $Color {/} (NumToHex (GetValue 2) 2)
  Set $Color = $Color {/} (NumToHex (GetValue 3) 2)
  # pick the current colorset
  Set $Command = {Colorset } $Cset
  # pick the type to set
  If (GetValue 10) == 1 Then
   Set $Command = $Command { Foreground } $Color
  If (GetValue 11) == 1 Then
   Set $Command = $Command { Hilite } $Color
  If (GetValue 12) == 1 Then
   Set $Command = $Command { Shadow } $Color
  If (GetValue 13) == 1 Then
   Set $Command = $Command { Background } $Color {, Foreground Contrast}
  Do $Command
 End
End

# RGB sliders
Widget 1
Property
 Size		320 0
 Position	50 60
 Type		HScrollBar
 MinValue	0
 MaxValue	255
Main
 Case message of
 SingleClic :
 Begin
  SendSignal 6 1
 End
End

Widget 21
Property
 Size		10 0
 Position	10 80
 Type		ItemDraw
 Title		{Red}
End

Widget 2
Property
 Size		320 0
 Position	50 120
 Type		HScrollBar
 MinValue	0
 MaxValue	255
Main
 Case message of
 SingleClic :
 Begin
  SendSignal 6 1
 End
End

Widget 22
Property
 Size		10 0
 Position	10 140
 Type		ItemDraw
 Title		{Green}
End

Widget 3
Property
 Size		320 0
 Position	50 180
 Type		HScrollBar
 MinValue	0
 MaxValue	255
Main
 Case message of
 SingleClic :
 Begin
  SendSignal 6 1
 End
End

Widget 23
Property
 Size		10 0
 Position	10 200
 Type		ItemDraw
 Title		{Blue}
End
