home *** CD-ROM | disk | FTP | other *** search
- (***************************************
- * WG-VISION 1.0 DEMONSTRATION *
- ****************************************
- * *
- * Unit: Malprogramm *
- * *
- *--------------------------------------*
- * Achtung: Nur VGA ! *
- ****************************************
- * (c) 1993 Dipl.Phys. Mathias Scholz *
- ***************************************)
-
- {$I COMPILER.INC}
- {$F+,O+}
-
- UNIT DEMPAINT;
-
- INTERFACE
-
- USES WDecl,
- WViews,
- WDlg,
- WEvent,
- WDriver,
- WFileDlg,
- WUtils,
- WPCX,
- dos,
- graph;
-
-
- const cmLoadPic = 40; {Unterkommando Malprogramm}
- cmSavePic = 41;
- cmClearPic = 42;
- cmPinsel = 43;
- cmBrush = 44;
- cmLine = 45;
- cmRectangle = 46;
- cmDrawBar = 47;
- cmDrawCirc = 48;
- cmFillCirc = 49;
- cmSetParam = 50;
-
- type PPaint=^TPaint;
- TPaint=object(TDlgWindow)
- 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;
- procedure SetPalette; virtual;
- procedure InitBackground; virtual;
- procedure CM_SaveAs;
- procedure CM_LoadPCX;
- procedure CM_SetParameters;
- procedure HandleEvent; virtual;
- private
- Error:integer;
- end;
-
- PPaintBgrd=^TPaintBgrd;
- TPaintBgrd=object(TBackground)
- procedure Draw;virtual;
- end;
-
- PParameter=^TParameter;
- TParameter=object(TDlgWindow)
- constructor Init;
- destructor Done; virtual;
- procedure InitBackground; virtual;
- procedure HandleEvent; virtual;
- end;
-
- PParamBgrd=^TParamBgrd;
- TParamBgrd=object(TBackground)
- procedure Draw; virtual;
- end;
-
- tParameterType=record
- Schalter:string[16];
- BType:string[2];
- Pencel:byte;
- Muster:byte;
- end;
-
-
- tDrawMode=(NoMode,Brush,Pinsel,DrawLine,DrawRect,DrawBar,DrawCircle,FillCircle);
-
- IMPLEMENTATION
-
- var Param : tParameterType;
- Modi : tDrawMode;
- ActMode : tDrawMode;
- AktivPinsel : byte;
- BrushType : byte;
- FuellMuster : byte;
-
- {Implementation TPaint}
-
- constructor TPaint.Init;
- var Bounds:TRect;
- i:integer;
- begin
- Bounds:=WorkArea; Bounds.A.y:=Bounds.A.y-25; Bounds.B.y:=Bounds.B.y+24;
- TDlgWindow.Init(Bounds,'',winSingle);
- SetPushButton(6,4,0,0,'#DEMO.I16/1',cmLoadPic);
- ChangePalColor(8,LightGray);
- SetPushButton(31,4,0,0,'#DEMO.I16/2',cmSavePic);
- ChangePalColor(8,LightGray);
- SetPushButton(56,4,0,0,'#DEMO.I16/3',cmClearPic);
- ChangePalColor(8,LightGray);
- SetPushButton(6,30,0,0,'#DEMO.I16/4',cmPinsel);
- ChangePalColor(8,LightGray);
- SetPushButton(31,30,0,0,'#DEMO.I16/5',cmBrush);
- ChangePalColor(8,LightGray);
- SetPushButton(56,30,0,0,'#DEMO.I16/6',cmLine);
- ChangePalColor(8,LightGray);
- SetPushButton(6,56,0,0,'#DEMO.I16/7',cmRectangle);
- ChangePalColor(8,LightGray);
- SetPushButton(31,56,0,0,'#DEMO.I16/8',cmDrawBar);
- ChangePalColor(8,LightGray);
- SetPushButton(56,56,0,0,'#DEMO.I16/9',cmDrawCirc);
- ChangePalColor(8,LightGray);
- SetPushButton(6,82,0,0,'#DEMO.I16/10',cmFillCirc);
- ChangePalColor(8,LightGray);
- SetPushButton(31,82,0,0,'#DEMO.I16/11',cmSetParam);
- ChangePalColor(8,LightGray);
- SetPushButton(56,82,0,0,'#DEMO.I16/12',cmCloseWindow);
- ChangePalColor(8,LightGray);
- 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,132+i*32,45,160+i*32);
- Colors[i+7].Assign(48,132+i*32,86,160+i*32);
- Stift:=White; Radiergummi:=DarkGray;
- end;
- Modi:=Pinsel; ActMode:=Modi;
- AktivPinsel:=0; BrushType:=25; FuellMuster:=SolidFill;
- with Param do
- begin
- Schalter:='TSRrrLRrrrrrrrrr';
- BType:='25';
- Pencel:=0;
- Muster:=1;
- end;
- 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.CM_SaveAs;
- var ODlg:POutPutDialog;
- begin
- ODlg:=New(POutPutDialog, Init('Bild sichern'));
- FrameDeAktivated:=true;
- DrawNewFrame;
- ODlg^.Draw;
- InsertChildWindow(ODlg);
- end;
-
- procedure TPaint.CM_LoadPCX;
- var IDlg:PInputDialog;
- begin
- IDlg:=New(PInputDialog, Init('PCX-Bild laden','*.PCX'));
- FrameDeAktivated:=true;
- DrawNewFrame;
- IDlg^.Draw;
- InsertChildWindow(IDlg);
- end;
-
- procedure TPaint.CM_SetParameters;
- var IDlg:PParameter;
- begin
- IDlg:=New(PParameter, Init);
- FrameDeAktivated:=true;
- DrawNewFrame;
- IDlg^.Draw;
- InsertChildWindow(IDlg);
- end;
-
- procedure TPaint.HandleEvent;
- var i,xxp,yyp,xxm,yym,Radius:integer;
- RR:TRect;
- xp,yp:single;
-
- 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 : CM_LoadPCX;
- cmSavePic : CM_SaveAs;
- 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;
- cmSetParam : CM_SetParameters;
- cmBrush : Modi:=Brush;
- cmPinsel : Modi:=Pinsel;
- cmLine : Modi:=DrawLine;
- cmRectangle : Modi:=DrawRect;
- cmDrawBar : Modi:=DrawBar;
- cmDrawCirc : Modi:=DrawCircle;
- cmFillCirc : Modi:=FillCircle;
- end; {case}
- case Event.Message of
- msgLoadFile: 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;
- msgSaveFile: 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);
- with PaintArea do
- begin
- SetViewPort(A.x,A.y,B.x,B.y,true);
- if LeftButton then
- begin
- HideMouse;
- SetColor(Stift);
- SetFillStyle(SolidFill,Stift);
- case Modi of
- Brush : repeat
- if Mouse.MouseHandler then;
- xp:=Random(BrushType)-(BrushType/2);
- yp:=Random(BrushType)-(BrushType/2);
- if sqrt(xp*xp+yp*yp)<=BrushType/2 then
- PutPixel(Position.X-A.x+trunc(xp),Position.Y-A.y+trunc(yp),Stift);
- until Mouse.LButtonRel;
- Pinsel : case AktivPinsel of
- 0,1 : repeat
- xx:=Position.X-A.x; yy:=Position.Y-A.y;
- if Mouse.MouseHandler then;
- if AktivPinsel=1 then SetLineStyle(SolidLn,0,ThickWidth);
- line(xx,yy,Position.X-A.x,Position.Y-A.y);
- SetLineStyle(SolidLn,0,NormWidth);
- until Mouse.LButtonRel;
- 2 : repeat
- xx:=Position.X-A.x; yy:=Position.Y-A.y;
- if Mouse.MouseHandler then;
- SetLineStyle(SolidLn,0,ThickWidth);
- line(xx,yy-2,Position.X-A.x,Position.Y-A.y-2);
- line(xx,yy,Position.X-A.x,Position.Y-A.y);
- line(xx,yy+2,Position.X-A.x,Position.Y-A.y+2);
- SetLineStyle(SolidLn,0,NormWidth);
- until Mouse.LButtonRel;
- end; {case}
- DrawRect,
- DrawBar : begin
- if AktivPinsel>0 then SetLineStyle(SolidLn,0,ThickWidth);
- xx:=Position.X-A.x; yy:=Position.Y-A.y;
- repeat
- xxp:=Position.X-A.x; yyp:=Position.Y-A.y;
- if Mouse.MouseHandler then;
- xxm:=Position.X-A.x; yym:=Position.Y-A.y;
- if (xxp<>xxm) or (yyp<>yym) then
- begin
- SetWriteMode(XOrPut);
- Mouse.HideMouse;
- RectAngle(xx,yy,xxp,yyp);
- RectAngle(xx,yy,xxm,yym);
- Mouse.ShowMouse;
- end;
- until Mouse.LButtonRel;
- SetWriteMode(CopyPut);
- SetFillStyle(FuellMuster,Stift);
- if Modi=DrawRect then RectAngle(xx,yy,xxm,yym)
- else Bar(xx,yy,Position.X-A.x,Position.Y-A.y);
- SetLineStyle(SolidLn,0,NormWidth);
- end;
- DrawLine,
- DrawCircle,
- FillCircle : begin
- if AktivPinsel>0 then SetLineStyle(SolidLn,0,ThickWidth);
- xx:=Position.X-A.x; yy:=Position.Y-A.y;
- repeat
- xxp:=Position.X-A.x; yyp:=Position.Y-A.y;
- if Mouse.MouseHandler then;
- xxm:=Position.X-A.x; yym:=Position.Y-A.y;
- if (xxp<>xxm) or (yyp<>yym) then
- begin
- SetWriteMode(XOrPut);
- Mouse.HideMouse;
- line(xx,yy,xxp,yyp);
- line(xx,yy,xxm,yym);
- Mouse.ShowMouse;
- end;
- until Mouse.LButtonRel;
- line(xx,yy,xxm,yym);
- SetWriteMode(CopyPut);
- SetFillStyle(FuellMuster,Stift);
- xp:=xx-xxm; yp:=yy-yym;
- Radius:=trunc(sqrt(sqr(xp)+sqr(yp)));
- if Modi=DrawCircle then Circle(xx,yy,Radius)
- else if Modi=FillCircle then FillEllipse(xx,yy,Radius,Radius)
- else line(xx,yy,xxm,yym);
- SetLineStyle(SolidLn,0,NormWidth);
- end;
- end; {case}
- end;
- if RightButton then
- begin
- HideMouse;
- SetFillStyle(SolidFill,Radiergummi);
- Bar(Position.X-4-A.x,Position.Y-4-A.y,Position.X+4-A.x,Position.Y+4-A.y);
- ShowMouse;
- end;
- SetViewPort(0,0,GetMaxX,GetMaxY,true);
- ShowMouse;
- end;
- end
- else if CursorTyp<>10 then SetCursorTyp(10);
- if Event.Command=cmCloseWindow then SetCursorTyp(1);
- end;
- 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,132+i*32,45,160+i*32);
- RectAngle(7,132+i*32,45,160+i*32);
- SetFillStyle(SolidFill,i+7);
- Bar(48,132+i*32,86,160+i*32);
- RectAngle(48,132+i*32,86,160+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;
-
- {Implementation TParameter}
-
- constructor TParameter.Init;
- var RR:TRect;
- begin
- RR.Assign(120,80,420,420);
- TDlgWindow.Init(RR,'Parameter',winDouble+winPanel+winMenu);
- SetPushButton(110,300,80,22,'OK',cmCloseWindow);
- ChangePalColor(8,LightGray);
- SetStaticText(20,45,'Pinselstärke',LeftText);
- SetRadioButton(25,85,'s~c~hmal',1);
- ChangePalColor(2,LightGray);
- SetRadioButton(115,85,'~m~ittel',1);
- ChangePalColor(2,LightGray);
- SetRadioButton(205,85,'~b~reit',1);
- ChangePalColor(2,LightGray);
- SetNumButton(55,137,2,'~B~rush Spot',2,2,5,95,5,2.0);
- ChangePalColor(2,LightGray);
- SetRadioButton(30,190,'S~o~lid',2);
- ChangePalColor(2,LightGray);
- SetTextPosition(80,184);
- SetRadioButton(30,210,'~L~ine',2);
- ChangePalColor(2,LightGray);
- SetTextPosition(80,204);
- SetRadioButton(30,230,'L~t~Slash',2);
- ChangePalColor(2,LightGray);
- SetTextPosition(80,224);
- SetRadioButton(30,250,'~S~lash',2);
- ChangePalColor(2,LightGray);
- SetTextPosition(80,244);
- SetRadioButton(30,270,'B~k~Slash',2);
- ChangePalColor(2,LightGray);
- SetTextPosition(80,264);
- SetRadioButton(165,190,'LBSl~a~sh',2);
- ChangePalColor(2,LightGray);
- SetTextPosition(215,184);
- SetRadioButton(165,210,'~H~atch',2);
- ChangePalColor(2,LightGray);
- SetTextPosition(215,204);
- SetRadioButton(165,230,'~X~Hatch',2);
- ChangePalColor(2,LightGray);
- SetTextPosition(215,224);
- SetRadioButton(165,250,'~I~nterl.',2);
- ChangePalColor(2,LightGray);
- SetTextPosition(215,244);
- SetRadioButton(165,270,'~W~ideDot',2);
- ChangePalColor(2,LightGray);
- SetTextPosition(215,264);
- SetData(Param);
- ActMode:=Modi;
- Modi:=NoMode;
- end;
-
- destructor TParameter.Done;
- begin
- TDlgWindow.Done;
- Modi:=ActMode;
- end;
-
- procedure TParameter.InitBackground;
- var RR:TRect;
- begin
- RR:=Frame^.Area;
- Bgrd:=new(PParamBgrd, Init(RR));
- List^.InsertItem(Bgrd);
- end;
-
- procedure TParameter.HandleEvent;
- var i:integer;
- begin
- TDlgWindow.HandleEvent;
- with Param do
- begin
- for i:=3 to 5 do
- if Schalter[i]='R' then AktivPinsel:=i-3;
- for i:=7 to 16 do
- if Schalter[i]='R' then FuellMuster:=i-6;
- val(BType,BrushType,i);
- end;
- end;
-
- {Implementation TParamBgrd}
-
- procedure TParamBgrd.Draw;
- var i:integer;
- begin
- with Border do
- begin
- FBar(A.x,A.y,B.x,B.y,LightGray);
- D3Frame(A.x+10,A.y+40,B.x-10,A.y+80,Black,White);
- D3Frame(A.x+10,A.y+150,B.x-10,A.y+261,Black,White);
- for i:=0 to 4 do
- begin
- SetFillStyle(i+1,LightBlue);
- Bar(A.x+47,A.y+158+i*20,A.x+70,A.y+173+i*20);
- RectAngle(A.x+47,A.y+158+i*20,A.x+70,A.y+173+i*20);
- SetFillStyle(i+6,LightBlue);
- Bar(A.x+182,A.y+158+i*20,A.x+205,A.y+173+i*20);
- RectAngle(A.x+182,A.y+158+i*20,A.x+205,A.y+173+i*20);
- end;
- end;
- end;
-
- END.