Drawing text on IPXV_DocumentViewsArea via IUIX_RenderContext.DrawString  SOLVED

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Drawing text on IPXV_DocumentViewsArea via IUIX_RenderContext.DrawString

Post by zarkogajic »

Hi Support,

I'm trying to draw some text on IPXV_DocumentViewsArea using IUIX_RenderContext.DrawString - but no luck - nothing is drawn.

I've pushed my custom IUIX_ObjImpl and in the OnEvent I'm getting the IUIX_RenderContext when pEvent.Code = e_Render.

Using FillUpdateRegion works as expected (read: I can change the "coloring" of the DocumentViewsArea).

Now, I'd like to add some custom text to the DocsViewArea. I've tried with the below - but noting gets displayed.

Code: Select all

IUIX_RenderContext pRC;
...
pRC.DrawString(
  'some string',
  Length('some string'),
  tagRct,
  InstUI.Theme.StdFont[UIX_StdFont_Default],
  $FF0000,
  0,
  clipRct,
  InstUI.CreateColorsTbl,
  InstUI.CreateDrawStringTags);
Any help on how to use DrawString and if I'm doing that at the right moment (e_render)... ?

p.s.
The idea behind this: https://forum.pdf-xchange.com/viewtopic.php?f=66&t=33760&p=139756&hilit=double+clicking#p142502 but I'd like some custom text instead of "Double clicking ...."

-žarko
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Drawing text on IPXV_DocumentViewsArea via IUIX_RenderContext.DrawString

Post by Vasyl-Tracker Dev Team »

Hi Zarko.

In your OnRender handler try this:

// first call the original paint-procedure
m_pObj->CallNextEventProcess((IUIX_ObjImpl*)this, pEvent);
pEvent.Handled = true;

// now the add your custom painting code...

OR you may try to use other way:

1. add m_pObj->SetStyleEx(UIX_ObjStyleEx_NeedPostRenderEvent, UIX_ObjStyleEx_NeedPostRenderEvent);
2. cath the e_PostRender and draw over the standard content.

HTH
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Drawing text on IPXV_DocumentViewsArea via IUIX_RenderContext.DrawString

Post by Vasyl-Tracker Dev Team »

Also you may remove this tip by:

Inst.Setting["Docs.CanOpenByDblClk"] = false;

but it will also stop this option from working...
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: Drawing text on IPXV_DocumentViewsArea via IUIX_RenderContext.DrawString

Post by zarkogajic »

Hi Vasyl,

Thanks. Yes, I cannot use Inst.Setting as I do want double click function in frames where I want it :)

Here's again what I'm trying to do: have some different text drawn over DocsViewArea.

1. If in OnEvent / e_Render I set pEvent.Handled = true -> the default ("double click..") text is not drawn.

If I call CallNextEventProcess, even if pEvent.Handled = true, the text does get drawn.

So: not the approach I can use.

2. I've tried OnPostEvent with e_PostRender and e_Render -> still my custom text using DrawString does not get displayed.

Maybe I'm using DrawString wrongly?

p.s.
For the UIX_ObjStyleEx_NeedPostRenderEvent I also had to SetStyle(UIX_ObjStyle_NeedPostEvent)

User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Drawing text on IPXV_DocumentViewsArea via IUIX_RenderContext.DrawString

Post by Vasyl-Tracker Dev Team »

Well, for DocsViewArea you may override its e_Render by setting e.Handled = true. In that case the default label not be drawn (as you noticed). And instead of it you should be able to draw text/lines/rectangles etc. in your OnRender-handler. And, as I see, you have a slightly incorrect code: the $FF0000 value for nFlags argument is strange and wrong because you specified such flags:
UIX_DrawString_HighlightOnly = 0x00010000, // text not be drawn!
UIX_DrawString_KeepWordsOnWrap = 0x00020000,
UIX_DrawString_SmallLineSpacing = 0x00040000,
Why you used such 'random' value here?

So simple and working example:

Code: Select all

IUIX_RenderContext pRC;
...
pRC.DrawString(
  'some string',
  Length('some string'),
  tagRct, // is not empty
  InstUI.Theme.StdFont[UIX_StdFont_Default],
  $FF000000, 
  UIX_DrawString_VCenter | UIX_DrawString_Center ...,
  clipRct, // intersect(clipRct, tagRct) - it isn't empty,
  nil,
  nil);
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: Drawing text on IPXV_DocumentViewsArea via IUIX_RenderContext.DrawString

Post by zarkogajic »

Hi Vasyl,

https://sdkhelp.pdf-xchange.com/view/PXV:IUIX_RenderContext_DrawString

The parameter after Font is Color - that's what $FF0000 is in my code.

I'm now using:

Code: Select all

//pSender is IPXV_DocumentViewsArea

pRC := IUIX_RenderContext(Pointer(pEvent.Param1));
pRC.FillUpdateRegion($eeeeee, false);

tagRct := pSender.Get_Rect; //NOT empty
clipRct := tagRct;

pRC.DrawString(
  'some string',
  Length('some string'),
  tagRct,
  PDFXHelper.InstUI.Theme.StdFont[UIX_StdFont_Bold],
  0,
  UIX_DrawString_VCenter OR UIX_DrawString_Center,
  clipRct,
  nil,
  nil);
  
pEvent.Handled := true;  
Still, nothing is drawn :(

I've tried FillSolidRect and DrawIcon and this also works as expected. Seems like "only" string drawing fails:

image.png

Code: Select all

pRc.FillSolidRect(tagRct, $0000FF, false);

pRc.DrawIcon(InstUI.Theme.GetIcon('ico.msg.info'), tagRct, clipRct, 0, 0, 50);
-žarko
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Drawing text on IPXV_DocumentViewsArea via IUIX_RenderContext.DrawString

Post by Vasyl-Tracker Dev Team »

The parameter after Font is Color - that's what $FF0000 is in my code.
Yes, you are right and sorry for my mistake. So I fixed code my previous post. :(

Unfortunately I haven't the Delphi IDE at the moment and cannot try your code - so please:

1. Fix $FF0000 -> $FF000000 because $FF0000 specifies the blue color but with zero alpha!
2. Fix tagRct = pSender.Get_Rect -> tagRct = pSender.Get_ClientRect
because Get_Rect - returns rectangle relative to pSender's parent object. But IUIX_RenderContext is relative to pSender's client area (top-left corner has the {0,0} coordinates).

Cheers.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: Drawing text on IPXV_DocumentViewsArea via IUIX_RenderContext.DrawString

Post by zarkogajic »

Hi Vasyl,

Omg. It was the Color value as you suggested. I was suspecting this (drawn but not visible due to color) but was not sure what's happening.

In short: it works! :)

One final question here: since IUIX_Font (pFont parameter to DrawString) only has Get properties -> how to specify a different font size for example?

-žarko
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Drawing text on IPXV_DocumentViewsArea via IUIX_RenderContext.DrawString

Post by Vasyl-Tracker Dev Team »

You may create new font using:

font = uiInst.CreateFontFromFont(srcFont, newFontSize, flags, flagsMask);

newFontSize:
0 - keep current
>0 - new size in pt
<0 - coefficient to enlarge/reduce the current font size

flags, flagsMask: use UIX_CreateFont_XXX flags.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: Drawing text on IPXV_DocumentViewsArea via IUIX_RenderContext.DrawString  SOLVED

Post by zarkogajic »

Hi Vasyl,

Great, thanks!

ž
Post Reply