Drawing in TSRichViewEdit

General TRichView support forum. Please post your questions here
Post Reply
vit
Posts: 115
Joined: Tue Feb 03, 2009 3:11 pm

Drawing in TSRichViewEdit

Post 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!
proxy3d
ScaleRichView Developer
Posts: 307
Joined: Mon Aug 07, 2006 9:37 am

Post 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;
vit
Posts: 115
Joined: Tue Feb 03, 2009 3:11 pm

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17287
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
vit
Posts: 115
Joined: Tue Feb 03, 2009 3:11 pm

Post 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.
proxy3d
ScaleRichView Developer
Posts: 307
Joined: Mon Aug 07, 2006 9:37 am

Post by proxy3d »

Yes, your code is correct
vit
Posts: 115
Joined: Tue Feb 03, 2009 3:11 pm

Post by vit »

How I can draw rectangles in table inplace editor? Should I use it OnPaint event or something else?
Sergey Tkachenko
Site Admin
Posts: 17287
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17287
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
vit
Posts: 115
Joined: Tue Feb 03, 2009 3:11 pm

Post by vit »

I think we should disable SRVDEBUG directive in SRV_Defs.inc
Sergey Tkachenko
Site Admin
Posts: 17287
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Yes, it was activated by mistake.
We will upload a fixed version today.
Post Reply