home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MAGAZINE / MISC / PCTV2N5.ZIP / DLG.ZIP / OGLFIX.TXT < prev    next >
Encoding:
Text File  |  1991-10-02  |  6.0 KB  |  183 lines

  1. Object Graphics Update
  2. Received from Whitewater 06-Sep-91
  3.  
  4. ===============================================================================
  5.  
  6. 1) replace TMathRect.Contains and TGraphic.MarkCorners as shown
  7.    below to allow the selection of a graphic will no width and/or
  8.    no height (including horizontal and vertical lines).  
  9.  
  10. {------------------------------------------------------------------
  11.   Returns True if Self contains the specified point.  Normalizes a
  12.   copy of Self, and returns the result of a call to the WhatSide
  13.   method of the normalized copy.
  14.  ------------------------------------------------------------------
  15. }
  16. function TMathRect.Contains(APoint: PGPoint): Boolean;
  17. var
  18.   AMathRect: TMathRect;
  19. begin
  20.   AMathRect.Init(Left, Top, Right, Bottom);
  21.   AMathRect.Normalize;
  22.   Contains := AMathRect.WhatSide(APoint) = 0;
  23.   AMathRect.Done;
  24. end;
  25.  
  26. modified TGraphic.MarkCorners as follows:
  27.  
  28. {------------------------------------------------------------------
  29.   Marks the corners of a TLine.  Adds markers centered at Self's
  30.   corners to the specified polymark.  Adds 4 markers when Self
  31.   has non-zero width and height, adds 2 markers when Self has
  32.   width but not height or vice-versa, adds 1 marker when Self
  33.   has neither width nor height.  These checks are made to prevent
  34.   markers from being positioned on top of eachother - when two
  35.   markers with cb_NXor combination are drawn on top of eachother
  36.   they become invisible).
  37.  ------------------------------------------------------------------
  38. }
  39. procedure TGraphic.MarkCorners(NewMarker: PPolymark);
  40. var
  41.   BRect : TMathRect;
  42.   APoint: TGPoint;
  43. begin
  44.   BRect.InitDefault;
  45.   GetBoundsRect(BRect);
  46.   BRect.Normalize;
  47.   NewMarker^.AddMark(BRect.Origin);
  48.   if BRect.Width <> 0 then
  49.   begin
  50.     APoint.Init(BRect.Right, BRect.Top);
  51.     NewMarker^.AddMark(@APoint);
  52.   end;
  53.   if BRect.Height <> 0 then
  54.   begin
  55.     APoint.Init(BRect.Left, BRect.Bottom);
  56.     NewMarker^.AddMark(@APoint);
  57.     if BRect.Width <> 0 then
  58.       NewMarker^.AddMark(BRect.Corner);
  59.   end;
  60.   BRect.Done;
  61. end;
  62.  
  63. ================================================================================
  64.  
  65. 2) replace EndSelectDrag in DRAWWIN.PAS below to allow the scaling of
  66.    selected graphics when the selected graphics (as a group) have no
  67.    width and/or no height (including horizontal and vertical lines).  
  68.  
  69.   procedure EndSelectDrag;
  70.   var
  71.     TempChosen    : PSubPicture;
  72.     XScale, YScale: Integer;
  73.   begin
  74.     if (TheChosen^.Count > 0) and ((KeyStates and mk_Shift) = 0) then
  75.     begin
  76.       if Cursor <> cs_User1 then
  77.       begin
  78.         TheMarks^.GetBoundsRect(BRect);
  79.         BRect.Invalidate(Port);
  80.         TheChosen^.PositionAt(AGraphic^.Origin);
  81.         Picture^.FindBounds;     { In case TheChosen moved outside them }
  82.         TheMarks^.SetMark(nil);  { Set to standard marker in case it was changed }
  83.         TheMarks^.FreeAll;
  84.         TheChosen^.MarkCorners(TheMarks);
  85.         TheMarks^.GetBoundsRect(BRect);
  86.         BRect.Invalidate(Port);
  87.       end
  88.       else
  89.       begin
  90.         if TheChosen^.Width > 0 then
  91.           XScale := Integer(((LongInt(AGraphic^.Width)  * 100) + 50)
  92.             div TheChosen^.Width)
  93.         else XScale := 0;
  94.         if TheChosen^.Height > 0 then
  95.           YScale := Integer(((LongInt(AGraphic^.Height)  * 100) + 50)
  96.             div TheChosen^.Height)
  97.         else YScale := 0;
  98.         TheChosen^.MarkCorners(TheMarks);  { Needed by ScaleChosen }
  99.         ScaleChosen(XScale, YScale);
  100.       end;
  101.       Dispose(HitPt, Done);
  102.     end
  103.     else
  104.     begin
  105.       TempChosen := TheChosen^.Copy;
  106.       TheChosen^.FreeAll;
  107.       if (TempChosen^.Count > 0) and ((KeyStates and mk_Shift) <> 0) then
  108.         PChooser(AGraphic)^.ChooseNext(Picture, TempChosen^.At(0), TheChosen^)
  109.       else
  110.         PChooser(AGraphic)^.Choose(Picture, TheChosen^);
  111.       Dispose(TempChosen, Done);
  112.  
  113.       if TheChosen^.Count > 0 then
  114.       begin
  115.         TheChosen^.MarkCorners(TheMarks);
  116.         TheMarks^.Draw(Port);
  117.       end;
  118.     end;
  119.     PGWindow(Parent)^.SetPicture(TheChosen); {Indicate what was chosen}
  120.   end;
  121.  
  122. ===============================================================================
  123.  
  124. 3) replace TDrawWindow.MouseMove to prevent cursor flicker when the mouse
  125.    is positioned over a marker of a selected graphic.
  126.  
  127. {------------------------------------------------------------------
  128.   Tracks movement of the mouse when not dragging.  Changes the
  129.   cursor when the mouse is positioned over a selection marker.
  130.  ------------------------------------------------------------------
  131. }
  132. procedure TDrawWindow.MouseMove(MousePt: PGPoint; KeyStates: Word);
  133. begin
  134.   if TheChosen^.Count > 0 then
  135.     if TheMarks^.Contains(MousePt) then
  136.     begin
  137.       if Cursor <> cs_User1 then
  138.         SavedCursor := Cursor;
  139.       SetGCursor(cs_User1);
  140.     end
  141.     else
  142.       SetGCursor(SavedCursor)
  143. end;
  144.  
  145. ===============================================================================
  146.  
  147. 4)  replace TMainWindow.CMFileOpen so that rulers are automatically turned
  148.     off when a OGL file is opened which contains a graph space with
  149.     device units.
  150.  
  151. procedure TMainWindow.CMFileOpen(var Msg: TMessage);
  152. var
  153.   TmpFile   : array [0..fsPathName] of Char;
  154.   APicture  : PPicture;
  155.   ASpace    : PGraphSpace;
  156.   FileStream: TGStream;
  157.   Header    : TFileHeader;
  158. begin
  159.   if Application^.ExecDialog(New(PFileDialog, Init(@Self,
  160.     PChar(sd_FileOpen), StrCopy(TmpFile, '*.ogl')))) = id_Ok
  161.   then
  162.   begin
  163.     StrCopy(FileName, TmpFile);
  164.     FileStream.Init(FileName, stOpen, 10000);
  165.     if ReadOGLHeader(FileStream, Header) then
  166.     begin
  167.       ASpace  := PGraphSpace(FileStream.Get);
  168.       APicture:= PPicture(FileStream.Get);
  169.     end;
  170.     FileStream.Done;
  171.  
  172.     DrawWindow^.SetSpace(ASpace);
  173.     if (ASpace^.Units = gs_Device) and ViewRulers then
  174.       CMToggleRulers(Msg);
  175.     DrawWindow^.SetPicture(APicture);
  176.     SetKidSpaces;
  177.     SetCaption;
  178.   end;
  179. end;
  180.  
  181. ================================================================================
  182.  
  183.