home *** CD-ROM | disk | FTP | other *** search
- {$A+,B-,D+,E-,F+,I-,L+,N-,O+,R-,S-,V-}
- UNIT GPaint;
-
- INTERFACE
-
- USES GDecl,
- GViews,
- GDlg,
- GEvent,
- GDrivers,
- GFileDlg,
- GUtils,
- GPCX,
- Dos,
- Graph;
-
-
- const cmLoadPic = 40; {Unterkommando Malprogramm}
- cmSavePic = 41;
- cmClearPic = 42;
- { cmPencel = 43;}
- cmTools = 44;
- cmPLoad = 45;
- cmPSave = 46;
- cmBrush = 47;
- cmFill = 48;
- { cmBar = 49;
- cmCircle = 50;
- } cmPinsel = 51;
-
- msgBrush = 40;
- msgPinsel = 41;
- msgFill = 42;
-
- type PPaint=^TPaint;
- TPaint=object(TDlgWindow)
- Modi : (Normal,Brush,Pinsel,Fill);
- PicFile : TPCXImage; {PCX-Bilddatei}
- Colors : array[0..15] of TRect; {Farbflächen}
- Stift : byte; {Stiftfarbe}
- Radiergummi : byte; {Hintergrundfarbe}
- PaintArea : TRect; {Zeichenfläche}
- xx,yy : integer; {letzte Mausposition}
- constructor Init(var Bounds:TRect;ATitle:str80;AType:byte);
- procedure SetPalette; virtual;
- procedure InitBackground; virtual;
- procedure HandleEvent; virtual;
- private
- Error:integer;
- end;
-
- PToolBar=^TToolBar;
- TToolBar=object(TDlgWindow)
- procedure HandleEvent; virtual;
- end;
-
- PPaintBgrd=^TPaintBgrd;
- TPaintBgrd=object(TBackground)
- procedure Draw;virtual;
- end;
-
-
- IMPLEMENTATION
-
-
- {Implementation TPaint}
-
- constructor TPaint.Init(var Bounds:TRect;ATitle:str80;AType:byte);
- var i:integer;
- begin
- TDlgWindow.Init(Bounds,ATitle,AType);
- with Bounds do
- PaintArea.Assign(A.x+84,A.y+1,B.x-1,B.y-1);
- PicFile.Init(PaintArea,'NONAME.PCX');
- for i:=1 to 8 do
- begin
- Colors[i-1].Assign(7,142+i*32,45,170+i*32);
- Colors[i+7].Assign(48,142+i*32,86,170+i*32);
- Stift:=White; Radiergummi:=DarkGray;
- end;
- Modi:=(Normal);
- end;
-
- procedure TPaint.SetPalette;
- begin
- Palette:=Pal[palRed];
- end;
-
- procedure TPaint.InitBackground;
- var RR:TRect;
- begin
- RR:=Frame^.Area;
- Bgrd:=new(PPaintBgrd, Init(RR));
- List^.InsertItem(Bgrd);
- end;
-
- procedure TPaint.HandleEvent;
- var i:integer;
- RR:TRect;
-
- procedure DrawColorView;
- begin
- Mouse.HideMouse;
- SetColor(Black);
- SetFillStyle(SolidFill,Radiergummi);
- Bar(7,429,86,472);
- RectAngle(7,429,86,472);
- SetFillStyle(SolidFill,Stift);
- Bar(20,442,73,459);
- RectAngle(20,442,73,459);
- Mouse.ShowMouse;
- end;
-
- begin
- TDlgWindow.HandleEvent;
- case Event.Command of
- cmLoadPic : Event.Command:=cmPLoad;
- cmSavePic : Event.Command:=cmPSave;
- cmClearPic : begin
- Mouse.HideMouse;
- SetFillStyle(SolidFill,Radiergummi);
- with PaintArea do Bar(A.x,A.y,B.x,B.y);
- Mouse.ShowMouse;
- Event.Command:=cmNothing;
- end;
- end; {case}
- case Event.Message of
- msgBrush : begin
- Modi:=Brush;
- Event.Message:=msgNothing;
- end;
- msgPinsel : begin
- Modi:=Pinsel;
- Event.Message:=msgNothing;
- end;
- msgFill : begin
- Modi:=Fill;
- Event.Message:=msgNothing;
- end;
- msgLoadPic : begin
- RR:=PaintArea;
- RR.Move(-5,0);
- PicFile.Init(RR,Event.InfoString);
- Mouse.HideMouse;
- SetFillStyle(SolidFill,DarkGray);
- with PaintArea do Bar(A.x,A.y,B.x,B.y);
- PicFile.LoadPCXImage(0);
- Mouse.ShowMouse;
- Event.Command:=cmNothing;
- Event.Message:=msgNothing;
- Event.InfoString:='';
- end;
- msgSavePic : begin
- RR:=PaintArea;
- RR.Move(-5,0);
- Mouse.HideMouse;
- with PaintArea do Error:=SavePCXImage(A.x,A.y,B.x,B.y,Event.InfoString);
- Mouse.ShowMouse;
- if not Error=0 then Beep(400);
- Event.Command:=cmNothing;
- Event.Message:=msgNothing;
- Event.InfoString:='';
- end;
- end; {case}
- with Mouse do
- begin
- for i:=0 to 15 do
- if Colors[i].Contains(Position) then
- begin
- if LButtonKlick then
- begin
- Stift:=i;
- DrawColorView;
- end;
- if RButtonKlick then
- begin
- RadierGummi:=i;
- DrawColorView;
- end;
- end;
- if PaintArea.Contains(Position) then
- begin
- if CursorTyp<>1 then SetCursorTyp(1);
- if LeftButton then
- begin
- HideMouse;
- SetColor(Stift);
- SetFillStyle(SolidFill,Stift);
- case Modi of
- Normal : line(xx,yy,XPos,YPos);
- Brush : for i:=1 to 10 do
- PutPixel(XPos+Random(20),YPos+Random(20),Stift);
- Pinsel : begin
- SetLineStyle(SolidLn,0,ThickWidth);
- line(xx,yy,XPos,YPos);
- SetLineStyle(SolidLn,0,NormWidth);
- end;
- Fill : begin
- with PaintArea do
- SetViewPort(A.x,A.y,B.x,B.y,true);
- SetFillStyle(SolidFill,Radiergummi);
- FloodFill(XPos-88,YPos-47,Stift);
- SetViewPort(0,0,GetMaxX,GetMaxY,true);
- end;
- end; {case}
- ShowMouse;
- end;
- if RightButton then
- begin
- HideMouse;
- SetFillStyle(SolidFill,Radiergummi);
- Bar(XPos-4,YPos-4,XPos+4,YPos+4);
- ShowMouse;
- end;
- xx:=XPos; yy:=YPos;
- end
- else if CursorTyp<>10 then SetCursorTyp(10);
- if Event.Command=cmCloseWindow then SetCursorTyp(1);
- end;
- end;
-
- {Implementation TToolBar}
-
- procedure TToolBar.HandleEvent;
- begin
- TDlgWindow.HandleEvent;
- case Event.Command of
- cmBrush : begin
- Event.Message:=msgBrush;
- Event.Command:=cmCloseWindow;
- end;
- cmPinsel : begin
- Event.Message:=msgPinsel;
- Event.Command:=cmCloseWindow;
- end;
- cmFill : begin
- Event.Message:=msgFill;
- Event.Command:=cmCloseWindow;
- end;
-
- end; {case}
- end;
-
-
- {Implementation TPaintBgrd}
-
- procedure TPaintBgrd.Draw;
- var i:integer;
- begin
- with Border do
- begin
- SetFillStyle(SolidFill,DarkGray);
- Bar(A.x+83,A.y,B.x,B.y);
- SetFillStyle(SolidFill,LightGray);
- Bar(A.x,A.y,A.x+83,B.y);
- for i:=1 to 8 do
- begin
- SetFillStyle(SolidFill,i-1);
- Bar(7,142+i*32,45,170+i*32);
- RectAngle(7,142+i*32,45,170+i*32);
- SetFillStyle(SolidFill,i+7);
- Bar(48,142+i*32,86,170+i*32);
- RectAngle(48,142+i*32,86,170+i*32);
- end;
- SetFillStyle(SolidFill,DarkGray);
- Bar(7,429,86,472);
- RectAngle(7,429,86,472);
- SetFillStyle(SolidFill,White);
- Bar(20,442,73,459);
- RectAngle(20,442,73,459);
- end;
- end;
-
-
- END.