Page 1 of 1

Drawing in TSRichViewEdit

Posted: Fri Sep 17, 2010 8:05 am
by vit
Hi!
I want to draw rectangle around items in TSRichViewEdit with specified tags. How I can do this?

I know how to find items by tags in SRVE, I can't understand how calculate items coordinates in Canvas (I use OnPaint event).

P.S. is needed account for that items can be placed in tables cells.

Thank you!

Posted: Fri Sep 17, 2010 9:48 am
by proxy3d
use the

Code: Select all

ConvertRVtoSRV (p: TPoint): TPoint;
converts the coordinates of the RV in the coordinates of the SRV.

or function (see their description in help):

Code: Select all

    procedure GetItemCoords100 (RVData: TCustomRVFormattedData; ItemNo: Integer; var ALeft, ATop: Integer; var PageNo: Integer);
    procedure GetItemBounds100 (RVData: TCustomRVFormattedData; ItemNo: Integer; var ARect: TRect; var PageNoB, PageNoE: Integer);
    function GetItemBounds (RVData: TCustomRVData; ItemNo: Integer): TRect;

Posted: Fri Sep 17, 2010 1:27 pm
by vit
proxy3d wrote:use the

Code: Select all

ConvertRVtoSRV (p: TPoint): TPoint;
converts the coordinates of the RV in the coordinates of the SRV.

or function (see their description in help):

Code: Select all

    procedure GetItemCoords100 (RVData: TCustomRVFormattedData; ItemNo: Integer; var ALeft, ATop: Integer; var PageNo: Integer);
    procedure GetItemBounds100 (RVData: TCustomRVFormattedData; ItemNo: Integer; var ARect: TRect; var PageNoB, PageNoE: Integer);
    function GetItemBounds (RVData: TCustomRVData; ItemNo: Integer): TRect;
Thank you!

P.S. There is no description for GetItemCoords100 and GetItemBounds100 in help.

Posted: Fri Sep 17, 2010 1:55 pm
by Sergey Tkachenko
100 at the end of the method means that coordinates are calculated in 100% zoom.

If your item is a text item, you can consider using SRichViewEdit.RichViewEdit.Style.OnDrawStyleText event.

Posted: Fri Sep 17, 2010 2:38 pm
by vit
Sergey Tkachenko wrote:100 at the end of the method means that coordinates are calculated in 100% zoom.
Will this code work correctly with any zoom?

Code: Select all

function GetItemRect(ItemNo: Integer; RVData: TCustomRVFormattedData): TRect;
var
  FirstPageNo: Integer;
  LastPageNo: Integer;
  PageRect: TRect;
begin
  srve.GetItemPages(RVData, ItemNo, FirstPageNo, LastPageNo);
  PageRect := srve.GetPageClientRect(FirstPageNo);

  Result := srve.GetItemBounds(RVData, ItemNo);
  Result.Left := Result.Left + PageRect.Left;
  Result.Right := Result.Right + PageRect.Left;
  Result.Top := Result.Top + PageRect.Top;
  Result.Bottom := Result.Bottom + PageRect.Top;
end;

procedure TForm1.srveContentPaint(Sender: TSRichViewEdit; Canvas: TCanvas; Prepaint: Boolean);
var
  i: Integer;
begin
  Canvas.Brush.Style := bsClear;
  for i := 0 to Sender.RichViewEdit.ItemCount - 1 do
    Canvas.Rectangle(GetItemRect(i, Sender.RichViewEdit.RVData));
end;
Sergey Tkachenko wrote:If your item is a text item, you can consider using SRichViewEdit.RichViewEdit.Style.OnDrawStyleText event.

My items may be of any kind.

Posted: Fri Sep 17, 2010 9:42 pm
by proxy3d
Yes, your code is correct

Posted: Tue Sep 21, 2010 6:48 am
by vit
How I can draw rectangles in table inplace editor? Should I use it OnPaint event or something else?

Posted: Tue Sep 21, 2010 12:55 pm
by Sergey Tkachenko
Your cycle iterates only through items in the main editor (from 0 to ItemCount-1). To include items in cells, you need to iterates through items in cells too.
In the next ScaleRichView update, we will include functions allowing to do this work more efficiently (to draw only for items on visible pages, drawing for multiline text items)
We will post updated example here.

Posted: Tue Sep 28, 2010 4:33 pm
by Sergey Tkachenko
In ScaleRichView version 3.6 (available for registered users) we included several new custom drawing demos.
The demo CustomDraw\Rectangles\DrawAll\ draws rectangles around all items in the document.

Posted: Wed Sep 29, 2010 7:57 am
by vit
I think we should disable SRVDEBUG directive in SRV_Defs.inc

Posted: Thu Sep 30, 2010 8:29 am
by Sergey Tkachenko
Yes, it was activated by mistake.
We will upload a fixed version today.