Legacy:Canvas - Unreal Wiki

# Legacy:Canvas

### From Unreal Wiki, The Unreal Engine Documentation Site

UT2003 :: Object >> Canvas (Package: Engine)

The Canvas is a wrapper for methods for drawing text, Textures and meshes on the local player's screen. Canvas objects are passed to various events and functions in the various classes, e.g. HUD, Weapon, GUI classes and Interactions.

See Canvas (UT) for Canvas properties and methods available in UT.

## Properties

bool bCenter
  Whether to center the text.
bool bNoSmooth
  Whether bilinear filtering should not be applied.
bool bRenderLevel
  Will render the level if enabled.
float ClipX, ClipY
  Width and height of the clipping region.
float CurX, CurY
  Current position for drawing relative to origin set by OrgX/OrgY.
float OrgX, OrgY
  Origin for drawing and upper left corner of the clipping window.
int SizeX, SizeY
  Zero-based actual dimensions.
float SpaceX, SpaceY
  Spacing for after executing one of the Draw* methods, i.e. this contains the screen size of the last drawn element.
byte Style
  The values of this variable correspond to the ERenderStyle enum of the Actor class.
color DrawColor
  Color to use for drawing. White (R=255,G=255,B=255) means draw everything in its default colors. If any color component is lower than 255 the specific color component of the Material or Font will be drawn darker. Alpha values specify the opacity of the drawn Material or Font. (A=255 means completely opaque) Also see color blending.
Plane ColorModulate
  Modulate all colors by this before rendering.
float CurYL
  Largest Y size since DrawText.
float FontScaleX, FontScaleY
font Font
  Font for DrawText.
font MedFont
font SmallFont
font TinyFont
string MedFontName, SmallFontName, TinyFontName
Viewport Viewport (const)
  Viewport that owns the canvas.
pointer pCanvasUtil (const)
  Used internally.

### UT2004 only

bool bForceAlpha
  Force all drawing to be alpha'ed.
float ForcedAlpha
  How much to force.

## Methods

### Texture Drawing

DrawTile( Material Mat, float XL, float YL, float U, float V, float UL, float VL )
  This draws a rectangle within the material onto the screen. The upper left of the material will be at the current pen position.

Mat
  The material to draw.
  XL, YL
    Width and height of the material on the screen, in number of pixels.
  U, V
    coordinates, within the material, of the upper left of the rectangular window.
  UL, VL
    width and height, in pixels, of the window within the material.

DrawTileClipped( Material Mat, float XL, float YL, float U, float V, float UL, float VL )
  Like DrawTile, but the material is clipped according to the region set by OrgX/OrgY and ClipX/ClipY.
DrawTileStretched( Material Mat, float XL, float YL )
  Draws the whole material stretched to the specified size. The texture is divided into four parts and only the pixels along the horizontal and vertical center lines are stretched.
DrawTileJustified( Material Mat, byte Justification, float XL, float YL )
DrawTileScaled( Material Mat, float XScale, float YScale )
  Draws the whole material scaled as specified by the multipliers.
DrawPattern( Material Tex, float XL, float YL, float Scale )
  Draws the scaled material and repeats it to fill a rectangle of the specified size.
DrawIcon( Texture Tex, float Scale )
  Draws the whole texture once with the specified scaling. Unlike most other draw functions, this one doesn't work with all Material classes. Only materials subclassed from Texture can be used, i.e. you can't use it to draw modifiers (shaders, etc.) or ScriptedTextures.
DrawRect( Texture Tex, float RectX, float RectY )
  Draws the whole texture stretched to the specified size.
DrawVertical( float X, float height )
  Draw a vertical line. The line's color is specified through DrawColor.
DrawHorizontal( float Y, float width )
  Draw a horizontal line.
DrawLine( int direction, float size )
  DrawLine is special as it saves it's original position. Direction: 0 = up, 1 = down, 2 = left, 3 = right
DrawBracket( float width, float height, float bracket_size )
DrawBox( Canvas canvas, float width, float height )
  Draws a box of the specified size. For some reason this function doesn't draw on the Canvas object you call it from, but needs a Canvas object as the first parameter.

### Text Drawing

DrawText( coerce string Text, optional bool CR )
DrawTextClipped( coerce string Text, optional bool bCheckHotKey )
StrLen( coerce string String, out float XL, out float YL )
  Get the size of a string when it would be drawn using the current font. The text will be wrapped according to the canvas width.
TextSize( coerce string String, out float XL, out float YL )
  Get the size of a string when it would be drawn using the current font. The text will be clipped at the
WrapStringToArray( string Text, out array<string> OutArray, float dx, string EOL )
  Takes Text and splits it based on how it would fit in the limitation of dx. Also will make a split when it encounters the characters contained in EOL. You can then use the strings of OutArray to make wrapped text by iterating through the array and placing each line of text one step lower than the last. dx would work best as an equation like Canvas.SizeX * 0.2 (20% of the Canvas width).
WrapText( out String Text, out String Line, float dx, Font F, float FontScaleX ) (static)
DrawTextJustified( coerce string String, byte Justification, float x1, float y1, float x2, float y2 )
  Draws String into the box starting at (x1, y1) and ending at (x2, y2). It justifies the text left, center or right, if justification is 0, 1 or 2 respectively.
DrawScreenText( string Text, float X, float Y, EDrawPivot Pivot )

### Actor Drawing

DrawActor( Actor A, bool WireFrame, optional bool ClearZ, optional float DisplayFOV )
DrawScreenActor( Actor A, optional float FOV, optional bool WireFrame, optional bool ClearZ )
DrawPortal( int X, int Y, int Width, int Height, Actor CamActor, vector CamLocation, rotator CamRotation, optional int FOV, optional bool ClearZ )
  It doesn't work when using OpenGL. (Note: The ClearZ argument does nothing, you have to manually clear the Z-buffer or you get strange results. Call the Clear function below with ClearZ true before DrawPortal)

  - kiff: no longer supported in UT3

vector WorldToScreen( vector WorldLoc )
  Converts the given absolute world coordinates to canvas coordinates. The returned vector's X and Y components contain the coordinates. What is the Z component? a dot product of an angle maybe? – Wormbo

  - Missilemaster: If WorldLoc is behind you, X and Y are the same as when it's ahead of you, but Z changes from being < 1 to being > 1. So, you'll probably want to put "if( Z < 1.0 )" in front of any drawing functions with this or whatever you draw will also appear when WorldLoc is behind you. ( Worked for me, at least. )
  - Sonic: Also when Z == 1.0 the teambeacon above players heads dissapears but doing if(Z == 1.0) wont work you will need to do if(float(string(Z)) == 1) so that it limits Z to 2 decimal places, i noticed without the float > string > float conversion it doesnt want to work.

GetCameraLocation( out vector CameraLocation, out rotator CameraRotation )
  Returns the camera's location and rotation.
Clear( optional bool ClearRGB, optional bool ClearZ )
SetScreenLight( int index, vector Position, color lightcolor, float radius )
SetScreenProjector( int index, vector Position, color color, float radius, Texture tex )

### Other Functions

Reset()
  Resets the canvas properties.
SetPos( float X, float Y )
  Sets CurX/Y.
SetOrigin( float X, float Y )
  Sets OrgX/Y.
SetClip( float X, float Y )
  Sets ClipX/Y.
SetDrawColor( byte R, byte G, byte B, optional byte A )
  Sets the DrawColor.
Color MakeColor( byte R, byte G, byte B, optional byte A ) (static)
  Returns a Color struct with the specified values. When A is not specified or set to 0, then A=255 is used.

### Native Functions

    native(464) final function StrLen( coerce string String, out float XL, out float YL ); // Wrapped!

    native(465) final function DrawText( coerce string Text, optional bool CR );

    native(466) final function DrawTile( material Mat, float XL, float YL, float U, float V, float UL, float VL );

    native(467) final function DrawActor( Actor A, bool WireFrame, optional bool ClearZ, optional float DisplayFOV );

    native(468) final function DrawTileClipped( Material Mat, float XL, float YL, float U, float V, float UL, float VL );

    native(469) final function DrawTextClipped( coerce string Text, optional bool bCheckHotKey );

    native(470) final function TextSize( coerce string String, out float XL, out float YL ); // Clipped!

    native(480) final function DrawPortal( int X, int Y, int Width, int Height, actor CamActor, vector CamLocation, rotator CamRotation, optional int FOV, optional bool ClearZ );

    native final function vector WorldToScreen( vector WorldLoc );

    native final function GetCameraLocation( out vector CameraLocation, out rotator CameraRotation );

    native final function SetScreenLight( int index, vector Position, color lightcolor, float radius );

    native final function SetScreenProjector( int index, vector Position, color color, float radius, texture tex );

    native final function DrawScreenActor( Actor A, optional float FOV, optional bool WireFrame, optional bool ClearZ );

    native final function Clear(optional bool ClearRGB, optional bool ClearZ);

    native final function WrapStringToArray(string Text, out array<string> OutArray, float dx, optional string EOL);

    static native final function WrapText( out String Text, out String Line, float dx, Font F, float FontScaleX );

    native final function DrawTilePartialStretched( Material Mat, float XL, float YL ); // rjp

    native final function DrawTileStretched(material Mat, float XL, float YL);

    native final function DrawTileJustified(material Mat, byte Justification, float XL, float YL);

    native final function DrawTileScaled(material Mat, float XScale, float YScale);

    native final function DrawTextJustified(coerce string String, byte Justification, float x1, float y1, float x2, float y2);

    native final function DrawActorClipped( Actor A, bool WireFrame, float Left, float Top, float Width, float Height, optional bool ClearZ, optional float DisplayFOV);

## External Links

- udn2:CanvasReference

## Related Topics

- HUD and HUD Interactions
- HudOverlay
  - ScriptedHudOverlay

## Discussion

TurkeyFromHell: Dude idk when you stuck those in here, but i am eternally grateful you did.. because i can't really do a google search through all my class sources for "native render" and find the DrawActor function now can I? :D <3 Maybe I'll finally be able to draw stuff through walls -.-... we'll see :P

OlympusMons: Added the native functions, Im not sure if they are ut2k4 only or not so someone might want to check that. I hope Im doing good here, not sure if this is where these native functions should be going or not, the formatting might need to be changed also. Help please :P

Categories: Legacy Class (UT2003) | Legacy Class (UT2004)

##### Views

- Legacy
- Discussion
- Current revision

##### Search