home *** CD-ROM | disk | FTP | other *** search
- Program paletti;
- (*****************************************************************************
- Name: PALETTI
- Version: 1.0
- Edit Datum: 1. März 1992
- Autor: Andreas Schumm
- Kurzbeschreibung: Palettendialog
- *****************************************************************************)
-
- Uses API, Kernel, Dialogs;
-
- CONST ProjektName = 'paletti';
-
- VAR LaunchResult : integer;
- MyEvent : EventTyp;
- StillRunning : boolean;
-
- Type ColorUserRadioButton = object(UserRadioButton)
- constructor Init(x1,y1, dx,dy,xb,yb,TheID: Integer; col: byte; TheIcon: Pointer; nextB: PUserRadio);
- procedure Draw; virtual;
- private
- MyColor : byte;
- end;
-
- PColorRadio = ^ColorUserRadioButton;
-
-
- constructor ColorUserRadioButton.Init;
- begin
- UserRadioButton.Init(x1,y1,dx,dy,xb,yb,theid,Theicon,nextB);
- MyColor := col;
- end;
-
-
- procedure ColorUserRadioButton.Draw;
- var lx,ly : integer;
- col : byte;
- begin
- With Area Do
- if (not IsChecked) and ((status and sfMarked) = 0) then
- begin
- Rectangle(P1.x,P1.y,P2.x,P2.y, DlgItemColor); { schwarzer Rahmen }
- Line(P1.x+1,P1.y+1,P2.x-1,P1.y+1, DlgItemBkColor); { weiss }
- Line(P1.x+1,P1.y+2,P2.x-2,P1.y+2, DlgItemBkColor);
- Line(P1.x+1,P1.y+1,P1.x+1,P2.y-1, DlgItemBkColor);
- Line(P1.x+2,P1.y+1,P1.x+2,P2.y-2, DlgItemBkColor);
- Bar(P1.x+3,P1.y+3,P2.x-3,P2.y-3, MyColor);
- Line(P1.x+2,P2.y-2,P2.x-1,P2.y-2, DlgButtonShadow);
- Line(P1.x+1,P2.y-1,P2.x-1,P2.y-1, DlgButtonShadow);
- Line(P2.x-1,P1.y+1,P2.x-1,P2.y-1, DlgButtonShadow);
- Line(P2.x-2,P1.y+2,P2.x-2,P2.y-1, DlgButtonShadow);
- lx := dxb div 2;
- ly := dyb div 2;
- if IconPtr <> NIL then
- DrawNormIcon(P1.X + (P2.x-P1.x) div 2 - lx, P1.y + (P2.y-P1.y) div 2 - ly,
- dxb,dyb,0, DlgItemColor, IconPtr);
- end
- else
- if IsChecked and ((status and sfMarked) = 0) then
- begin
- Rectangle(P1.x,P1.y,P2.x,P2.y, DlgItemColor); { schwarzer Rahmen }
- Line(P1.x+1,P1.y+1,P2.x-1,P1.y+1, DlgButtonShadow);
- Line(P1.x+1,P1.y+1,P1.x+1,P2.y-1, DlgButtonShadow);
- Bar(P1.x+2,P1.y+2,P2.x-1,P2.y-1, MyColor);
- lx := dxb div 2;
- ly := dyb div 2;
- If IconPtr <> NIL then
- DrawNormIcon(P1.X + (P2.x-P1.x) div 2 - lx+1, P1.y + (P2.y-P1.y) div 2 - ly+1,
- dxb,dyb,0, DlgItemColor, IconPtr);
- end
- else
- if (Status and sfMarked) <> 0 then
- begin
- Rectangle(P1.x,P1.y,P2.x,P2.y, DlgItemColor); { schwarzer Rahmen }
- Bar(P1.x+2,P1.y+2,P2.x-1,P2.y-1, MyColor);
- Line(P1.x+1,P1.y+1,P2.x-1,P1.y+1, DlgButtonShadow);
- Line(P1.x+1,P1.y+2,P2.x-2,P1.y+2, DlgButtonShadow);
- Line(P1.x+1,P1.y+1,P1.x+1,P2.y-1, DlgButtonShadow);
- Line(P1.x+2,P1.y+2,P1.x+2,P2.y-2, DlgButtonShadow);
- lx := dxb div 2;
- ly := dyb div 2;
- If IconPtr <> NIL then
- DrawNormIcon(P1.X + (P2.x-P1.x) div 2 - lx+2, P1.y + (P2.y-P1.y) div 2 - ly+2,
- dxb,dyb,0, DlgItemColor, IconPtr);
- end;
- End;
-
-
- procedure PaletteHandler(TheEvent: EventTyp); far;
- var MYDLG : PDialog;
- MyRadios : PUserRadios;
- MySlider : PSlider;
- color : Byte;
- r,g,b : Byte;
- begin
- MYDLG := TheEvent.DlgAdr;
- If TheEvent.Class = DialogEvent then
- Case TheEvent.MSG of
- DLG_SLIDERMOVED :
- begin
- MySlider := MYDLG^.FindDlgItem(301);
- r := MySlider^.GetPos;
- MySlider := MYDLG^.FindDlgItem(302);
- g := MySlider^.GetPos;
- MySlider := MYDLG^.FindDlgItem(303);
- b := MySlider^.GetPos;
- MyRadios := MYDLG^.FindDlgItem(411);
- color := MyRadios^.WhosChecked-412;
- SetPalette(color,r,g,b);
- end;
- DLG_OK : MYDLG^.DestroyDialog;
- DLG_CANCEL : begin
- MYDLG^.flags := MYDLG^.flags or MF_CANCELLED;
- MYDLG^.DestroyDialog;
- end;
- DLG_BUTTON : if TheEvent.ID = 103 then { Standard gedrückt }
- begin
- SetCursor(LoadCursor(HourGlassCursor));
- SetPalette(0, 0, 0, 0);
- SetPalette(1, 0, 0,42);
- SetPalette(2, 0,42, 0);
- SetPalette(3, 0,42,42);
- SetPalette(4,42, 0, 0);
- SetPalette(5,42, 0,42);
- SetPalette(6,42,21, 0);
- SetPalette(7,42,42,42);
- SetPalette(8,21,21,21);
- SetPalette(9,21,21,63);
- SetPalette(10,21,63,21);
- SetPalette(11,21,63,63);
- SetPalette(12,63,21,21);
- SetPalette(13,63,21,63);
- SetPalette(14,63,63,21);
- SetPalette(15,63,63,63);
- SetCursor(LoadCursor(DefaultCursor));
- end;
- DLG_RADIO : begin
- MyRadios := MYDLG^.FindDlgItem(411);
- color := MyRadios^.WhosChecked-412;
- Bar(20,120,307,140,color);
- GetPalette(color,r,g,b);
- MySlider := MYDLG^.FindDlgItem(301);
- MySlider^.SetPos(r);
- MySlider := MYDLG^.FindDlgItem(302);
- MySlider^.SetPos(g);
- MySlider := MYDLG^.FindDlgItem(303);
- MySlider^.SetPos(b);
- end;
- end;
- end;
-
- procedure ReadPaletteFromIni;
- var i : integer;
- r,g,b : longint;
- rr,gg,bb : byte;
- ws : string[5];
- begin
- SetCursor(LoadCursor(HourGlassCursor));
- for i := 0 to 15 do
- begin
- str(i,ws);
- GetPalette(i,rr,gg,bb);
- if GetInitFileInteger('Palette','Color'+ws+'R',r) then rr := r;
- if GetInitFileInteger('Palette','Color'+ws+'G',g) then gg := g;
- if GetInitFileInteger('Palette','Color'+ws+'B',b) then bb := b;
- SetPalette(i,rr,gg,bb);
- end;
- SetCursor(LoadCursor(DefaultCursor));
- end;
-
-
- procedure PaletteDialog;
- var MyDialog : Dialog;
- MySlider : PSlider;
- MyButton : PButton;
- MyUserRadios : PUserRadios;
- MyLabel : PLabelText;
- MyFrame : PLabelFrame;
- r,g,b : Byte;
- i : Integer;
- ws : String[5];
- MyBitsPerPlane : Byte;
- MyMonoFlag : Boolean;
- MyColorSteps : Integer;
- begin
- MyBitsPerPlane := BitsPerPlane;
-
- If Not IsMono Then MyBitsPerPlane := MyBitsPerPlane div 3;
-
- MyColorSteps := Round(Exp(1.0 * MyBitsPerPlane * Ln(2))) - 1;
-
- MyDialog.Init(330,180, MF_CAPTION, PaletteHandler);
- MyDialog.SetCaption('Farbpalette einstellen');
-
- new(MyUserRadios, Init(3,155,400,39,411,
- new(PColorRadio, Init( 0, 0,39,19,39,39,412, 0,nil,
- new(PColorRadio, Init( 40, 0,39,19,39,39,413, 1,nil,
- new(PColorRadio, Init( 80, 0,39,19,39,39,414, 2,nil,
- new(PColorRadio, Init(120, 0,39,19,39,39,415, 3,nil,
- new(PColorRadio, Init(160, 0,39,19,39,39,416, 4,nil,
- new(PColorRadio, Init(200, 0,39,19,39,39,417, 5,nil,
- new(PColorRadio, Init(240, 0,39,19,39,39,418, 6,nil,
- new(PColorRadio, Init(280, 0,39,19,39,39,419, 7,nil,
- new(PColorRadio, Init( 0,20,39,19,39,39,420, 8,nil,
- new(PColorRadio, Init( 40,20,39,19,39,39,421, 9,nil,
- new(PColorRadio, Init( 80,20,39,19,39,39,422,10,nil,
- new(PColorRadio, Init(120,20,39,19,39,39,423,11,nil,
- new(PColorRadio, Init(160,20,39,19,39,39,424,12,nil,
- new(PColorRadio, Init(200,20,39,19,39,39,425,13,nil,
- new(PColorRadio, Init(240,20,39,19,39,39,426,14,nil,
- new(PColorRadio, Init(280,20,39,19,39,39,427,15,nil,nil))))))))))))))))))))))))))))))))));
- MyDialog.AddItem(MyUserRadios);
-
- MyUserRadios^.CheckButton(412);
-
- new(MyButton, Init(200, 20,110,24,101,'OK'));
- MyDialog.AddItem(MyButton);
- MyButton^.MakeDefaultItem;
-
- new(MyButton, Init(200, 50,110,24,102,'Abbruch'));
- MyDialog.AddItem(MyButton);
- MyButton^.MakeCancelItem;
-
- new(MyButton, Init(200, 80,110,24,103,'Standard'));
- MyDialog.AddItem(MyButton);
-
- new(MyFrame, Init(20,20,130, 90,0,'Palette'));
- MyDialog.AddItem(MyFrame);
-
- GetPalette(black,r,g,b);
-
- new(MyLabel, Init(30,30,0,'R'));
- MyDialog.AddItem(MyLabel);
- new(MySlider,Init(45,30,90,301,0,MyColorSteps,hor));
- MySlider^.SetPos(r);
- MyDialog.AddItem(MySlider);
-
- new(MyLabel, Init(30,55,0,'G'));
- MyDialog.AddItem(MyLabel);
- new(MySlider,Init(45,55,90,302,0,MyColorSteps,hor));
- MySlider^.SetPos(g);
- MyDialog.AddItem(MySlider);
-
- new(MyLabel, Init(30,80,0,'B'));
- MyDialog.AddItem(MyLabel);
- new(MySlider,Init(45,80,90,303,0,MyColorSteps,hor));
- MySlider^.SetPos(b);
- MyDialog.AddItem(MySlider);
-
- MyDialog.Show;
- Bar(20,120,307,140,black);
- MyDialog.DoDialog;
- if MyDialog.WasNotCancelled then
- begin
- SetCursor(LoadCursor(HourGlassCursor));
- for i := 0 to 15 do
- begin
- str(i,ws);
- GetPalette(i,r,g,b);
- SetInitFileInteger('Palette','Color'+ws+'R',r);
- SetInitFileInteger('Palette','Color'+ws+'G',g);
- SetInitFileInteger('Palette','Color'+ws+'B',b);
- end;
- SetCursor(LoadCursor(DefaultCursor));
- end;
- MyDialog.Done;
- end;
-
-
- Procedure HandleMsg(MyMessage: EventTyp); far;
- { Hier werden die Botschaften behandelt. }
- Begin
- With MyMessage Do
- Case Class Of
- Menu : begin
- Case MenuItemID of
- 0 : StillRunning := false;
- 100 : PaletteDialog;
- end;
- end;
- end; { Case Class }
- End;
-
-
- Begin
- StillRunning := true;
- DebugOn;
- LaunchResult := OpenMainApplication(HandleMsg,
- APP_NOFONT,
- ProjektName);
-
- If LaunchResult = 0 then
- begin
- ReadPaletteFromIni;
- while StillRunning Do
- begin
- GetEvent(MyEvent);
- DispatchMessage(MyEvent);
- end;
- CloseMainApplication;
- end
- Else
- Writeln('Programm kann nicht gestartet werden. Fehler: ',LaunchResult);
- End.