Program PropGad ;

{
 Erstellt mit KICKPASCAL V2.0 von MAXON COMPUTER
 Author : Wittemann Manfred
          Am Rischbacher - Rech 30
          6670 St.Ingbert

          Letzte Änderung 29.09.1991
                          06.10.1991
                          08.10.1991
}

{$path "ram:"include","pascal:include"}
{$path "pascal:include"}
{$incl "intuition.lib","graphics.lib"}

Var Prop_1      : Gadget ;
    Prop_2      : Gadget ;
    Prop_3      : Gadget ;
    Prop_Info_1 : PropInfo ;
    Prop_Info_2 : PropInfo ;
    Prop_Info_3 : PropInfo ;
    Mover1      : Array [1..6] Of Integer ;
    Mover2      : Array [1..6] Of Integer ;
    Mover3      : Array [1..6] Of Integer ;
    MyWin       : ^Window ;
    MyText      : IntuiText ;
    Msg         : ^IntuiMessage ;
    Signals     : Long ;
    By          : Boolean ;
    Zaehler1    : Word ;
    Zaehler2    : Word ;
    Zaehler3    : Word ;
    AktGadget   : ^Gadget ;
    Buffer1     : String[2] ;
    Buffer2     : String[2] ;
    Buffer3     : String[2] ;
    ColorWert   : String[7] ;
    ColorOld    : Word ;

Procedure PrintText(S : Str ; x,y : Integer) ;

Var Text1 : IntuiText ;

Begin
  Text1 := IntuiText(1,0,1,0,0,NIL,S,NIL) ;
  PrintIText(MyWin^.RPort,^Text1,x,y) ;
End ;

Procedure Init ;

Begin
  Prop_1 := Gadget(NIL,30,30,150,10,GadGHComp,RelVerify,PropGadget,^Mover1,
                  NIL,NIL,0,^Prop_Info_1,1,0) ;
  Prop_2 := Gadget(NIL,30,50,150,10,GadGHComp,RelVerify,PropGadget,^Mover2,
                  NIL,NIL,0,^Prop_Info_2,2,0) ;
  Prop_3 := Gadget(NIL,30,70,150,10,GadGHComp,RelVerify,PropGadget,^Mover3,
                  NIL,NIL,0,^Prop_Info_3,3,0) ;
  Prop_Info_1 := PropInfo(AutoKnob Or FreeHoriz,$0000,$0f00,$100f,
                          $FFFF Div 16,0,0,0,0,0,0) ;
  Prop_Info_2 := PropInfo(AutoKnob Or FreeHoriz,$0000,$0f00,$100f,
                          $FFFF Div 16,0,0,0,0,0,0) ;
  Prop_Info_3 := PropInfo(AutoKnob Or FreeHoriz,$0000,$0f00,$100f,
                          $FFFF Div 16,0,0,0,0,0,0) ;
  MyText := IntuiText(1,0,1,0,0,NIL,^ColorWert,NIL) ;

  Buffer1 := "0" ; Buffer2 := "0" ; Buffer3 := "0"
  By := False ;
  Zaehler1 := 0 ; Zaehler2 := 0 ; Zaehler3 := 0 ;
  OpenLib(IntBase,"intuition.library",0) ;
    If IntBase = NIL Then Error("Intuition konnte nicht geöffnet werden") ;
  OpenLib(GFXBase,"graphics.library",0) ;
    If GFXBase = NIL Then Error("Graphics konnte nicht geöffnet werden") ;
  MyWin := Open_Window(0,0,350,100,$0201,_CloseWindow Or GadgetUp,
           WindowClose Or WindowDrag Or WindowDepth,"Color",NIL,400,
           120,640,256) ;
    If MyWin = NIL Then Error("Window konnte nicht geöffnet werden") ;
  ColorOld := GetRGB4(^MyWin^.WScreen^.ViewPort.ColorMap^,3) ;
  PrintText("R",10,31) ;
  PrintText("G",10,51) ;
  PrintText("B",10,71) ;
  AddGadget(MyWin,^Prop_1,NIL) ;
  AddGadget(MyWin,^Prop_2,NIL) ;
  AddGadget(MyWin,^Prop_3,NIL) ;
  RefreshGadgets(MyWin^.FirstGadget,MyWin,NIL) ;
  SetRGB4(^MyWin^.WScreen^.ViewPort,3,0,0,0) ;
  SetAPen(MyWin^.RPort,3)
  RectFill(MyWin^.RPort,200,30,260,80) ;
End ;

Procedure DecodeHex(p:Ptr; Zahl:Long; Len:Integer) ;

  Var i,z:integer;
      pp:^Array[0..7] of char;

  Begin
    pp:=p;
    For i:=Len-1 Downto 0 Do
      Begin
        z:=Zahl and 15;
        If Zahl>=0 Then Zahl:= Zahl div 16
                   Else Zahl:=(Zahl and $7fffffff) div 16 + $8000000;
        If z<10 Then pp^[i]:=chr(ord('0')+z)
                Else pp^[i]:=chr(ord('A')+z-10)
      End
  End;

Procedure Counter ;

Begin

  AktGadget := Msg^.IAddress ;
  Case AktGadget^.GadgetID Of
    1 : Begin
          Zaehler1 := (Prop_Info_1. HorizPot) div 4096 ;
          DecodeHex(^Buffer1,Zaehler1,1) ;
          Colorwert := "$0" + Buffer1 + Buffer2 + Buffer3 ;
          SetRGB4(^MyWin^.WScreen^.ViewPort,3,Zaehler1,Zaehler2,Zaehler3) ;
          PrintText(ColorWert,280,50) ;
        End ;
    2 : Begin
          Zaehler2 := (Prop_Info_2. HorizPot) div 4096 ;
          DecodeHex(^Buffer2,Zaehler2,1) ;
          Colorwert := "$0" + Buffer1 + Buffer2 + Buffer3 ;
          SetRGB4(^MyWin^.WScreen^.ViewPort,3,Zaehler1,Zaehler2,Zaehler3) ;
          PrintText(ColorWert,280,50) ;
        End ;
    3 : Begin
          Zaehler3 := (Prop_Info_3. HorizPot) div 4096 ;
          DecodeHex(^Buffer3,Zaehler3,1) ;
          Colorwert := "$0" + Buffer1 + Buffer2 + Buffer3 ;
          SetRGB4(^MyWin^.WScreen^.ViewPort,3,Zaehler1,Zaehler2,Zaehler3) ;
          PrintText(ColorWert,280,50) ;
        End ;
    Otherwise ;
  End ;
End ;

{---------------------}
{*** Hauptprogramm ***}
{---------------------}

Begin
  Init ;
  Colorwert := "$0000" ;
  PrintText("Farbe  von   Manfred    Wittemann",42,17) ;
  PrintText("Geschrieben mit KICK - PASCAL 2.0",42,88) ;
  PrintIText(MyWin^.RPort,^MyText,280,50) ;
  Repeat
    Repeat
      Msg := Get_Msg(MyWin^.UserPort) ;
      If Msg <> NIL Then
        Signals := Wait(1 shl MyWin^.UserPort^.mp_SigBit) ;
    Until Msg <> NIL ;

    Case Msg^.Class Of
      _CloseWindow : By := True ;
      GadgetUp     : Counter ;
      Otherwise
    End ;
    Reply_Msg(Msg) ;
  Until By ;

  SetRGB4(^MyWin^.WScreen^.ViewPort,3,ColorOld Div 256,((ColorOld Mod 256) Div 16) ,(ColorOld Mod 256) Mod 16  ) ;

End.







