| Home Page | Recent Changes

Wormbo/WUtils

For the full list of classes, methods, etc. go to the wUtils page.

wString

Methods

FloatToString (maybe in v105)
Converts a float to string.
static final function string FloatToString(float Value, optional int Precision)
{
    local int IntPart;
    local float FloatPart;
    local string IntString, FloatString;
    
    Precision = Max(Precision, 1);  // otherwise a simple int cast should be used
    
    if ( Value < 0 ) {
        IntString = "-";
        Value *= -1;
    }
    IntPart = int(Value);
    FloatPart = Value - IntPart;
    IntString = IntString $ string(IntPart);
    FloatString = string(int(FloatPart * 10 ** Precision));
    while (Len(FloatString) < Precision)
        FloatString = "0" $ FloatString;
    
    return IntString$"."$FloatString;
}

wDraw

Structs

MaterialRegion
struct MaterialRegion {
    var Material Tex;
    var IntBox TexCoords;   // absolute material coordinates
    var FloatBox ScreenCoords;  // relative screen coordinates
    var ERenderStyle RenderStyle;
    var Color DrawColor;
}

Methods

DrawMaterialRegion
Draws a MaterialRegion to a Canvas. The canvas' clipping region (determined by OrgX/Y and ClipX/Y) is used to convert the MaterialRegion's screen coordinates.
static final function DrawMaterialRegion(Canvas C, MaterialRegion M,
        optional float ScaleX, optional float ScaleY, optional bool bClipped)
{
    local byte OldStyle;
    local Color OldColor;
    local float X, Y, W, H, CenterX, CenterY;
   
    if ( ScaleX == 0 )
        ScaleX = 1.0;
   
    if ( ScaleY == 0 )
        ScaleY = ScaleX;
   
    X = M.ScreenCoords.X1 * C.ClipX;
    Y = M.ScreenCoords.Y1 * C.ClipY;
    W = (M.ScreenCoords.X2 - M.ScreenCoords.X1) * C.ClipX;
    H = (M.ScreenCoords.Y2 - M.ScreenCoords.Y1) * C.ClipY;
    CenterX = (M.ScreenCoords.X1 + M.ScreenCoords.X2) * 0.5 * C.ClipX;
    CenterY = (M.ScreenCoords.Y1 + M.ScreenCoords.Y2) * 0.5 * C.ClipY;
       
    W *= ScaleX;
    H *= ScaleY;
    X = CenterX - 0.5 * W;
    Y = CenterY - 0.5 * H;
   
    OldStyle = C.Style;
    OldColor = C.DrawColor;
   
    C.Style = M.RenderStyle;
    C.DrawColor = M.DrawColor;
    C.SetPos(X, Y);
    if ( !bClipped )
        C.DrawTile(M.Tex, W, H, M.TexCoords.X1, M.TexCoords.Y1,
                M.TexCoords.X2 - M.TexCoords.X1, M.TexCoords.Y2 - M.TexCoords.Y1);
    else
        C.DrawTileClipped(M.Tex, W, H, M.TexCoords.X1, M.TexCoords.Y1,
                M.TexCoords.X2 - M.TexCoords.X1, M.TexCoords.Y2 - M.TexCoords.Y1);
    
    C.Style = OldStyle;
    C.DrawColor = OldColor;
}
DrawDecimalNumberAt (updated for v105)
Draws a float value. The coordinates specify the upper left corner of the decimal point character, i.e. when you specify the upper right corner of the screen the decimal point would not be visible. (added optional int Precision and fixed draw position getting changed)
static final function DrawDecimalNumberAt(Canvas C, float Value, float X, float Y, optional bool bClipped, optional int Precision)
{
    local int IntPart;
    local float FloatPart;
    local float XL, YL, OldX, OldY;
    local string IntString, FloatString;
    
    OldX = C.CurX; OldY = C.CurY;
    
    if ( Precision == 0 )
        Precision = 2; // default UT2k3 setting
    else
        Precision = Max(Precision, 1);  // otherwise Canvas.DrawScreenText should be used
    
    if ( Value < 0 ) {
        IntString = "-";
        Value *= -1;
    }
    IntPart = int(Value);
    FloatPart = Value - IntPart;
    IntString = IntString $ string(IntPart);
    IntString = string(int(IntPart));
    FloatString = string(int(FloatPart * 10 ** Precision));
    while (Len(FloatString) < Precision)
        FloatString = "0" $ FloatString;
    
    C.TextSize(IntString, XL, YL);
    C.SetPos(X - XL, Y);
    if ( !bClipped )
        C.DrawText(IntString$"."$FloatString);
    else
        C.DrawTextClipped(IntString$"."$FloatString);
    
    C.SetPos(OldX, OldY);   // reset draw position
}
FloatBox GetActorBox (Canvas C, Actor A)
Calculates a box around an actor in relative screen coordinates.
static final function FloatBox GetActorBox(Canvas C, Actor A)
{
    local float Left, Right;
    local vector CamLoc, X, Y, Z;
    local rotator CamRot;
    local array<float> Height;
    local FloatBox box;
    
    if ( A == None )
        return box;
    
    C.GetCameraLocation(CamLoc, CamRot);
    GetAxes(CamRot, X, Y, Z);
    Right = C.WorldToScreen(A.Location + Y * A.CollisionRadius).X;
    Left = C.WorldToScreen(A.Location - Y * A.CollisionRadius).X;
    X = Normal(X * vect(1,1,0)) * A.CollisionRadius;
    Z = vect(0,0,1) * A.CollisionHeight;
    Height[0] = C.WorldToScreen(A.Location + X + Z).Y;
    Height[1] = C.WorldToScreen(A.Location - X + Z).Y;
    Height[2] = C.WorldToScreen(A.Location + X - Z).Y;
    Height[3] = C.WorldToScreen(A.Location - X - Z).Y;
    
    box.X1 = Left / C.SizeX;
    box.X2 = Right / C.SizeX;
    box.Y1 = class'wArray'.static.MinF(Height) / C.SizeY;
    box.Y2 = class'wArray'.static.MaxF(Height) / C.SizeY;
    
    return box;
}
SetClipRegion (Canvas C, FloatBox ClipRegion)
Sets the canvas' clipping region. Can use a FloatBox like it is returned by the GetActorBox method.
static final function SetClipRegion(Canvas C, FloatBox ClipRegion)
{
    C.SetOrigin(ClipRegion.X1 * C.SizeX, ClipRegion.Y1 * C.SizeY);
    C.SetClip((ClipRegion.X2 - ClipRegion.X1) * C.SizeX, (ClipRegion.Y2 - ClipRegion.Y1) * C.SizeY);
}
ResetClipRegion (Canvas C)
Resets the canvas' clipping region.
static final function ResetClipRegion(Canvas C)
{
    C.SetOrigin(C.Default.OrgX, C.Default.OrgY);
    C.SetClip(C.Default.ClipX, C.Default.ClipY);
}
DrawBracket (Canvas C, float width, float height, float bracket_size) (maybe in v105)
This function is a corrected version of the function with the same name in the Canvas class. The bracket drawn by the Canvas version will be two pixels wider and higher than specified and the bottom right corner misses a small 2x2 square.
static final function DrawBracket(Canvas C, float width, float height, float bracket_size)
{
    local float X, Y;
    X = C.CurX;
    Y = C.CurY;

    Width  = max(width,5);
    Height = max(height,5);
    
    // top left
    C.DrawLine(3, bracket_size);    // to left
    C.DrawLine(1, bracket_size);    // down
    
    // top right
    C.SetPos(X + width, Y);
    C.DrawLine(2, bracket_size);    // to right
    C.SetPos(X + width - 2, Y);
    C.DrawLine(1, bracket_size);    // down
    
    // bottom right
    C.SetPos(X + width - 2, Y + height);
    C.DrawLine(0, bracket_size);    // up
    C.SetPos(X + width, Y + height - 2);
    C.DrawLine(2, bracket_size);    // to right
    
    // bottom left
    C.SetPos(X, Y + height - 2);
    C.DrawLine(3, bracket_size);    // to left
    C.SetPos(X, Y + height);
    C.DrawLine( 0, bracket_size);   // up

    C.SetPos(X, Y);
}

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

FAQs

Help Desk

Mapping Topics

Mapping Lessons

UnrealEd Interface

UnrealScript Topics

UnrealScript Lessons

Making Mods

Class Tree

Modeling Topics

Chongqing Page

Log In