home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / grafik / wgraph1 / demoq / gpaint.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-12-25  |  7.3 KB  |  275 lines

  1. {$A+,B-,D+,E-,F+,I-,L+,N-,O+,R-,S-,V-}
  2. UNIT GPaint;
  3.  
  4. INTERFACE
  5.  
  6. USES GDecl,
  7.      GViews,
  8.      GDlg,
  9.      GEvent,
  10.      GDrivers,
  11.      GFileDlg,
  12.      GUtils,
  13.      GPCX,
  14.      Dos,
  15.      Graph;
  16.  
  17.  
  18. const cmLoadPic  = 40;  {Unterkommando Malprogramm}
  19.       cmSavePic  = 41;
  20.       cmClearPic = 42;
  21.     {  cmPencel   = 43;}
  22.       cmTools    = 44; 
  23.       cmPLoad    = 45;
  24.       cmPSave    = 46;
  25.       cmBrush    = 47;
  26.       cmFill     = 48;
  27.    {   cmBar      = 49;
  28.       cmCircle   = 50;
  29.     }  cmPinsel   = 51;
  30.  
  31.       msgBrush   = 40;
  32.       msgPinsel  = 41;
  33.       msgFill    = 42;
  34.  
  35. type PPaint=^TPaint;
  36.      TPaint=object(TDlgWindow)
  37.        Modi        : (Normal,Brush,Pinsel,Fill);
  38.        PicFile     : TPCXImage;              {PCX-Bilddatei}
  39.        Colors      : array[0..15] of TRect;  {Farbflächen}
  40.        Stift       : byte;                   {Stiftfarbe}
  41.        Radiergummi : byte;                   {Hintergrundfarbe}
  42.        PaintArea   : TRect;                  {Zeichenfläche}
  43.        xx,yy       : integer;                {letzte Mausposition}
  44.        constructor Init(var Bounds:TRect;ATitle:str80;AType:byte);
  45.        procedure SetPalette; virtual;
  46.        procedure InitBackground; virtual;
  47.        procedure HandleEvent; virtual;
  48.      private
  49.        Error:integer;
  50.      end;
  51.  
  52.      PToolBar=^TToolBar;
  53.      TToolBar=object(TDlgWindow)
  54.       procedure HandleEvent; virtual;
  55.      end;
  56.  
  57.      PPaintBgrd=^TPaintBgrd;
  58.      TPaintBgrd=object(TBackground)
  59.        procedure Draw;virtual;
  60.      end;
  61.  
  62.  
  63. IMPLEMENTATION
  64.  
  65.  
  66. {Implementation TPaint}
  67.  
  68. constructor TPaint.Init(var Bounds:TRect;ATitle:str80;AType:byte);
  69. var i:integer;
  70. begin
  71.   TDlgWindow.Init(Bounds,ATitle,AType);
  72.   with Bounds do
  73.    PaintArea.Assign(A.x+84,A.y+1,B.x-1,B.y-1);
  74.   PicFile.Init(PaintArea,'NONAME.PCX');
  75.   for i:=1 to 8 do
  76.    begin
  77.      Colors[i-1].Assign(7,142+i*32,45,170+i*32);
  78.      Colors[i+7].Assign(48,142+i*32,86,170+i*32);
  79.      Stift:=White; Radiergummi:=DarkGray;
  80.    end;
  81.   Modi:=(Normal);
  82. end;
  83.  
  84. procedure TPaint.SetPalette;
  85. begin
  86.   Palette:=Pal[palRed];
  87. end;
  88.  
  89. procedure TPaint.InitBackground;
  90. var RR:TRect;
  91. begin
  92.   RR:=Frame^.Area;
  93.   Bgrd:=new(PPaintBgrd, Init(RR));
  94.   List^.InsertItem(Bgrd);
  95. end;
  96.  
  97. procedure TPaint.HandleEvent;
  98. var i:integer;
  99.     RR:TRect;
  100.  
  101. procedure DrawColorView;
  102. begin
  103.   Mouse.HideMouse;
  104.   SetColor(Black);
  105.   SetFillStyle(SolidFill,Radiergummi);
  106.   Bar(7,429,86,472);
  107.   RectAngle(7,429,86,472);
  108.   SetFillStyle(SolidFill,Stift);
  109.   Bar(20,442,73,459);
  110.   RectAngle(20,442,73,459);
  111.   Mouse.ShowMouse;
  112. end;
  113.  
  114. begin
  115.   TDlgWindow.HandleEvent;
  116.   case Event.Command of
  117.    cmLoadPic  : Event.Command:=cmPLoad;
  118.    cmSavePic  : Event.Command:=cmPSave;
  119.    cmClearPic : begin
  120.                   Mouse.HideMouse;
  121.                   SetFillStyle(SolidFill,Radiergummi);
  122.                   with PaintArea do Bar(A.x,A.y,B.x,B.y);
  123.                   Mouse.ShowMouse;
  124.                   Event.Command:=cmNothing;
  125.                 end;
  126.   end; {case}
  127.   case Event.Message of
  128.    msgBrush   : begin
  129.                   Modi:=Brush;
  130.                   Event.Message:=msgNothing;
  131.                 end;
  132.    msgPinsel  : begin
  133.                   Modi:=Pinsel;
  134.                   Event.Message:=msgNothing;
  135.                 end;
  136.    msgFill    : begin
  137.                   Modi:=Fill;
  138.                   Event.Message:=msgNothing;
  139.                 end;
  140.    msgLoadPic : begin
  141.                   RR:=PaintArea;
  142.                   RR.Move(-5,0);
  143.                   PicFile.Init(RR,Event.InfoString);
  144.                   Mouse.HideMouse;
  145.                   SetFillStyle(SolidFill,DarkGray);
  146.                   with PaintArea do Bar(A.x,A.y,B.x,B.y);
  147.                   PicFile.LoadPCXImage(0);
  148.                   Mouse.ShowMouse;
  149.                   Event.Command:=cmNothing;
  150.                   Event.Message:=msgNothing;
  151.                   Event.InfoString:='';
  152.                 end;
  153.    msgSavePic : begin
  154.                   RR:=PaintArea;
  155.                   RR.Move(-5,0);
  156.                   Mouse.HideMouse;
  157.                   with PaintArea do Error:=SavePCXImage(A.x,A.y,B.x,B.y,Event.InfoString);
  158.                   Mouse.ShowMouse;
  159.                   if not Error=0 then Beep(400);
  160.                   Event.Command:=cmNothing;
  161.                   Event.Message:=msgNothing;
  162.                   Event.InfoString:='';
  163.                 end;
  164.   end; {case}
  165.   with Mouse do
  166.    begin
  167.      for i:=0 to 15 do
  168.       if Colors[i].Contains(Position) then
  169.        begin
  170.          if LButtonKlick then
  171.            begin
  172.              Stift:=i;
  173.              DrawColorView;
  174.            end;
  175.          if RButtonKlick then
  176.           begin
  177.             RadierGummi:=i;
  178.             DrawColorView;
  179.           end;
  180.        end;
  181.      if PaintArea.Contains(Position) then
  182.       begin
  183.         if CursorTyp<>1 then SetCursorTyp(1);
  184.         if LeftButton then
  185.          begin
  186.            HideMouse;
  187.            SetColor(Stift);
  188.            SetFillStyle(SolidFill,Stift);
  189.            case Modi of
  190.             Normal : line(xx,yy,XPos,YPos);
  191.             Brush  : for i:=1 to 10 do
  192.                       PutPixel(XPos+Random(20),YPos+Random(20),Stift);
  193.             Pinsel : begin
  194.                        SetLineStyle(SolidLn,0,ThickWidth);
  195.                        line(xx,yy,XPos,YPos);
  196.                        SetLineStyle(SolidLn,0,NormWidth);
  197.                      end;
  198.             Fill   : begin
  199.                        with PaintArea do 
  200.                         SetViewPort(A.x,A.y,B.x,B.y,true);
  201.                        SetFillStyle(SolidFill,Radiergummi);
  202.                        FloodFill(XPos-88,YPos-47,Stift);
  203.                        SetViewPort(0,0,GetMaxX,GetMaxY,true);
  204.                       end;
  205.            end; {case}
  206.            ShowMouse;
  207.          end;
  208.         if RightButton then
  209.          begin
  210.            HideMouse;
  211.            SetFillStyle(SolidFill,Radiergummi);
  212.            Bar(XPos-4,YPos-4,XPos+4,YPos+4);
  213.            ShowMouse;
  214.          end;
  215.         xx:=XPos; yy:=YPos;
  216.       end
  217.       else if CursorTyp<>10 then SetCursorTyp(10);
  218.      if Event.Command=cmCloseWindow then SetCursorTyp(1);
  219.    end;
  220. end;
  221.  
  222. {Implementation TToolBar}
  223.  
  224. procedure TToolBar.HandleEvent;
  225. begin
  226.   TDlgWindow.HandleEvent;
  227.   case Event.Command of
  228.    cmBrush  : begin
  229.                 Event.Message:=msgBrush;
  230.                 Event.Command:=cmCloseWindow;
  231.               end;
  232.    cmPinsel : begin
  233.                 Event.Message:=msgPinsel;
  234.                 Event.Command:=cmCloseWindow;
  235.               end;
  236.    cmFill   : begin
  237.                 Event.Message:=msgFill;
  238.                 Event.Command:=cmCloseWindow;
  239.               end;
  240.  
  241.   end; {case}
  242. end;
  243.  
  244.  
  245. {Implementation TPaintBgrd}
  246.  
  247. procedure TPaintBgrd.Draw;
  248. var i:integer;
  249. begin
  250.   with Border do
  251.    begin
  252.      SetFillStyle(SolidFill,DarkGray);
  253.      Bar(A.x+83,A.y,B.x,B.y);
  254.      SetFillStyle(SolidFill,LightGray);
  255.      Bar(A.x,A.y,A.x+83,B.y);
  256.      for i:=1 to 8 do
  257.       begin
  258.         SetFillStyle(SolidFill,i-1);
  259.         Bar(7,142+i*32,45,170+i*32);
  260.         RectAngle(7,142+i*32,45,170+i*32);
  261.         SetFillStyle(SolidFill,i+7);
  262.         Bar(48,142+i*32,86,170+i*32);
  263.         RectAngle(48,142+i*32,86,170+i*32);
  264.       end;
  265.      SetFillStyle(SolidFill,DarkGray);
  266.      Bar(7,429,86,472);
  267.      RectAngle(7,429,86,472);
  268.      SetFillStyle(SolidFill,White);
  269.      Bar(20,442,73,459);
  270.      RectAngle(20,442,73,459);
  271.    end;
  272. end;
  273.  
  274.  
  275. END.