x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Clipping a HUD/Canvas DrawText

Is there a way in unreal engine to clip HUD/Canvas Draw Text to a certain region? I tried setting the TextItem BlendMode to translucent however the really long test text string still goes over the bounds of the rectangle I draw below it. I have looked at Slate and it seems to do it (though I'm not sure how) and I wish to avoid it as both the layout management syntax is strange and the widgets don't fit with the native operating system.

I know you can get the pixel dimensions for the text and so limit it on the x axis length, however there seems no way to just draw the bottom of half of the text for a scrolling widget that only partially shows that text.

Code

         DrawTextureSimple(texture, 500, 175, 1.0f, false);

     FCanvasTextItem TextItem(FVector2D(300, 175), FText::FromString("REALLY LONG TEXT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"), HUDFont, FColor::Black);
     TextItem.Scale = FVector2D(0.5, 0.5);
     TextItem.BlendMode = SE_BLEND_Translucent;
     FFontRenderInfo fri = FFontRenderInfo();
     fri.bClipText = true;
     TextItem.FontRenderInfo = fri;
     Canvas->DrawItem(TextItem);


Yet the text goes right over the drawn texture

Product Version: Not Selected
Tags:
more ▼

asked Aug 08 '14 at 07:59 PM in Rendering

avatar image

djmoreho
8 4 8 8

avatar image Shadowriver Aug 08 '14 at 11:12 PM

Can't you just process string based on text area?

avatar image djmoreho Aug 10 '14 at 04:27 AM

@Shadowriver that works great for horizontal text but not for vertical cutoffs that occur when having a panel scroll. The editor has plenty of these, where if you scroll to show only half of the text it works. So it must be able to be done however UE doesn't present an obvious way to clip a region. I have looked through the slate code with no avail.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Here is one way to achieve clipping of the canvas / HUD using RHI scissor rects.

https://gist.github.com/pixeltris/40fde2a6b4d8b68caeee

I added blueprint functionality as well but you will need to re-parent your HUD to HUDEx as it requires access to the protected member Canvas.

alt text

I believe Slate can also clip non axis aligned rectangles. To do this with Canvas you would probably need to either use masks with materials or cut up the triangles and update the UV coords. This would require replacing all existing canvas items to work correctly so materials may be easier with better masking options if anyone is interested in going beyond singular axis aligned clipping rects.

This should answer these related questions

https://answers.unrealengine.com/questions/53845/canvas-clipping-region.html https://answers.unrealengine.com/questions/52349/hud-clipping.html

clip.png (112.7 kB)
more ▼

answered Nov 30 '14 at 04:20 PM

avatar image

PixelTris
1

avatar image Pseudocorpus Mar 12 '15 at 02:52 PM

Doesn't work for me:

 Error    1    error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl SetScissorRect_Internal(bool,unsigned int,unsigned int,unsigned int,unsigned int)" (__imp_?SetScissorRect_Internal@@YAX_NIIII@Z) referenced in function "public: void __cdecl `public: virtual bool __cdecl FCanvasScissorRectRenderItem::Render_GameThread(class FCanvas const *)'::`2'::EURCMacro_CanvasScissorRectCommand::DoTask(enum ENamedThreads::Type,class TRefCountPtr<class FGraphEvent> const &)" (?DoTask@EURCMacro_CanvasScissorRectCommand@?1??Render_GameThread@FCanvasScissorRectRenderItem@@UEAA_NPEBVFCanvas@@@Z@QEAAXW4Type@ENamedThreads@@AEBV?$TRefCountPtr@VFGraphEvent@@@@@Z)    C:\Users\HW 685\Documents\Unreal Projects\StruggleOfMages\Intermediate\ProjectFiles\ClipCanvas.cpp.obj    StruggleOfMages
 
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question