Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

Engine.Canvas


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
//=============================================================================
// Canvas: A drawing canvas.
// Copyright 1998-2008 Epic Games, Inc. All Rights Reserved.
//=============================================================================
class Canvas extends Object
	native
	noexport
	transient;

/**
 * Holds texture information with UV coordinates as well.
 */
struct CanvasIcon
{
	/** Source texture */
	var Texture2D Texture;
	/** UV coords */
	var float U, V, UL, VL;
};

// Modifiable properties.
var font    Font;            // Font for DrawText.
var float   OrgX, OrgY;      // Origin for drawing.
var float   ClipX, ClipY;    // Bottom right clipping region.
var float   CurX, CurY;      // Current position for drawing.
var float   CurYL;           // Largest Y size since DrawText.
var color   DrawColor;       // Color for drawing.
var bool    bCenter;         // Whether to center the text.
var bool    bNoSmooth;       // Don't bilinear filter.
var const int SizeX, SizeY;  // Zero-based actual dimensions.

// Internal.
var native const pointer Canvas{FCanvas};
var native const pointer SceneView{FSceneView};

var Plane ColorModulate;
var Texture2D DefaultTexture;

// native functions.
native final function DrawTile( Texture2D Tex, float XL, float YL, float U, float V, float UL, float VL );
/** the only difference in this new version is you can pass in other types of textures (e.g. ScriptedTexture) */
native final function DrawTileNew(Texture Tex, float XL, float YL, float U, float V, float UL, float VL);

/**
 * Draws the emissive channel of a material to an axis-aligned quad at CurX,CurY.
 *
 * @param	Mat - The material which contains the emissive expression to render.
 * @param	XL - The width of the quad in pixels.
 * @param	YL - The height of the quad in pixels.
 * @param	U - The U coordinate of the quad's upper left corner, in normalized coordinates.
 * @param	V - The V coordinate of the quad's upper left corner, in normalized coordinates.
 * @param	UL - The range of U coordinates which is mapped to the quad.
 * @param	VL - The range of V coordinates which is mapped to the quad.
 */
native final function DrawMaterialTile
(
				MaterialInterface	Mat,
				float				XL,
				float				YL,
	optional	float				U,
	optional	float				V,
	optional	float				UL,
	optional	float				VL
);

native final function DrawMaterialTileClipped
(
				MaterialInterface	Mat,
				float				XL,
				float				YL,
	optional	float				U,
	optional	float				V,
	optional	float				UL,
	optional	float				VL
);

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

native final function DrawText( coerce string Text, optional bool CR, optional float XScale, optional float YScale );
native final function DrawTextClipped( coerce string Text, optional bool bCheckHotKey, optional float XScale, optional float YScale );

/**
 * Draws text right aligned from the current position.
 */
final function DrawTextRA(coerce string Text, optional bool CR)
{
	local float XL, YL;
	TextSize(Text,XL,YL);
	SetPos(CurX - XL,CurY);
	DrawText(Text,CR);
}



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


native final function vector Project(vector location);			// Convert a 3D vector to a 2D screen coords.
native final function vector DeProject(vector location);		// Convert a 2D screen position to a 3D vector.

/**
 * Pushes a translation matrix onto the canvas.
 *
 * @param TranslationVector		Translation vector to use to create the translation matrix.
 */
native final function PushTranslationMatrix(vector TranslationVector);

/** Pops the topmost matrix from the canvas transform stack. */
native final function PopTransform();

native final function DrawTileStretched(Texture2D Tex, float XL, float YL,  float U, float V, float UL, float VL, LinearColor LColor, optional bool bStretchHorizontally=true, optional bool bStretchVertically=true,optional float ScalingFactor=1.0);
native final function DrawColorizedTile( Texture2D Tex, float XL, float YL, float U, float V, float UL, float VL, LinearColor LColor );

/* rjp - unused
native final function WrapStringToArray(string Text, out array<string> OutArray, float dx, optional string EOL);
*/

/* rjp - unused
// jmw - These are two helper functions.  The use the whole texture only.  If you need better support, use DrawTile
native final function DrawTileJustified(Texture2D Tex, byte Justification, float XL, float YL);
native final function DrawTileScaled(Texture2D Tex, float XScale, float YScale);
native final function DrawTextJustified(coerce string String, byte Justification, float x1, float y1, float x2, float y2);
*/
// UnrealScript functions.
event Reset(optional bool bKeepOrigin)
{
	Font        = Default.Font;
	if ( !bKeepOrigin )
	{
		OrgX        = Default.OrgX;
		OrgY        = Default.OrgY;
	}
	CurX        = Default.CurX;
	CurY        = Default.CurY;
	DrawColor   = Default.DrawColor;
	CurYL       = Default.CurYL;
	bCenter     = false;
	bNoSmooth   = false;
}

native final function SetPos( float PosX, float PosY );
final function SetOrigin( float X, float Y )
{
	OrgX = X;
	OrgY = Y;
}
final function SetClip( float X, float Y )
{
	ClipX = X;
	ClipY = Y;
}
/* rjp - unused
final function DrawPattern( Texture2D Tex, float XL, float YL, float Scale )
{
	DrawTile( Tex, XL, YL, (CurX-OrgX)*Scale, (CurY-OrgY)*Scale, XL*Scale, YL*Scale );
}
*/
final function DrawTexture(Texture2D Tex, float Scale)
{
	if (Tex != None)
	{
		DrawTile( Tex, Tex.SizeX*Scale, Tex.SizeY*Scale, 0, 0, Tex.SizeX, Tex.SizeY );
	}
}

/**
 * Fake CanvasIcon constructor.
 */
final function CanvasIcon MakeIcon(Texture2D Texture, optional float U, optional float V, optional float UL, optional float VL)
{
	local CanvasIcon Icon;
	if (Texture != None)
	{
		Icon.Texture = Texture;
		Icon.U = U;
		Icon.V = V;
		Icon.UL = (UL != 0.f ? UL : float(Texture.SizeX));
		Icon.VL = (VL != 0.f ? VL : float(Texture.SizeY));
	}
	return Icon;
}

/**
 * Draw a CanvasIcon at the desired canvas position.
 */
final function DrawIcon(CanvasIcon Icon, float X, float Y, optional float Scale)
{
	if (Icon.Texture != None)
	{
		// verify properties are valid
		if (Scale <= 0.f)
		{
			Scale = 1.f;
		}
		if (Icon.UL == 0.f)
		{
			Icon.UL = Icon.Texture.SizeX;
		}
		if (Icon.VL == 0.f)
		{
			Icon.VL = Icon.Texture.SizeY;
		}
		// set the canvas position
		CurX = X;
		CurY = Y;
		// and draw the texture
		DrawTile(Icon.Texture, Icon.UL*Scale, Icon.VL*Scale, Icon.U, Icon.V, Icon.UL, Icon.VL);
	}
}

/**
 * Draw a subsection of a CanvasIcon at the desired canvas position.
 */
final function DrawIconSection(CanvasIcon Icon, float X, float Y, float UStartPct, float VStartPct, float UEndPct, float VEndPct, optional float Scale)
{
	if (Icon.Texture != None)
	{
		// verify properties are valid
		if (Scale <= 0.f)
		{
			Scale = 1.f;
		}
		if (Icon.UL == 0.f)
		{
			Icon.UL = Icon.Texture.SizeX;
		}
		if (Icon.VL == 0.f)
		{
			Icon.VL = Icon.Texture.SizeY;
		}
		// set the canvas position
		CurX = X + (UStartPct * Icon.UL * Scale);
		CurY = Y + (VStartPct * Icon.VL * Scale);
		// and draw the texture
		DrawTile(Icon.Texture, Icon.UL * UEndPct * Scale, Icon.VL * VEndPct * Scale, Icon.U + (UStartPct * Icon.UL), Icon.V + (VStartPct * Icon.VL), Icon.UL * UEndPct, Icon.VL * VEndPct);
	}
}

final function DrawRect(float RectX, float RectY, optional Texture2D Tex = DefaultTexture )
{
	DrawTile( Tex, RectX, RectY, 0, 0, Tex.SizeX, Tex.SizeY );
}

final simulated function DrawBox(float width, float height)
{
	local int X, Y;

	X = CurX;
	Y = CurY;

	// normalize CurX, CurY (eliminate float precision errors)
	SetPos(X, Y);

	// draw the left side
	DrawRect(2, height);
	// then move cursor to top-right
	SetPos(X + width - 2, Y);

	// draw the right face
	DrawRect(2, height);
	// then move the cursor to the top-left (+2 to account for the line we already drew for the left-face)
	SetPos(X + 2, Y);

	// draw the top face
	DrawRect(width - 4, 2);
	// then move the cursor to the bottom-left (+2 to account for the line we already drew for the left-face)
	SetPos(X + 2, Y + height - 2);

	// draw the bottom face
	DrawRect(width - 4, 2);
	// move the cursor back to its original position
	SetPos(X, Y);
}

native final function SetDrawColor(byte R, byte G, byte B, optional byte A /*= 255*/);

/* rjp - unused
// Draw a vertical line
final function DrawVertical(float X, float height)
{
    SetPos( X, CurY);
    DrawRect(2, height);
}

// Draw a horizontal line
final function DrawHorizontal(float Y, float width)
{
    SetPos(CurX, Y);
    DrawRect(width, 2);
}

// Draw Line is special as it saves it's original position

final function DrawLine(int direction, float size)
{
    local float X, Y;

    // Save current position
    X = CurX;
    Y = CurY;

    switch (direction)
    {
      case 0:
		  SetPos(X, Y - size);
		  DrawRect(2, size);
		  break;

      case 1:
		  DrawRect(2, size);
		  break;

      case 2:
		  SetPos(X - size, Y);
		  DrawRect(size, 2);
		  break;

	  case 3:
		  DrawRect(size, 2);
		  break;
    }
    // Restore position
    SetPos(X, Y);
}

final simulated function DrawBracket(float width, float height, float bracket_size)
{
    local float X, Y;
    X = CurX;
    Y = CurY;

	Width  = max(width,5);
	Height = max(height,5);

    DrawLine(3, bracket_size);
    DrawLine(1, bracket_size);
    SetPos(X + width, Y);
    DrawLine(2, bracket_size);
    DrawLine(1, bracket_size);
    SetPos(X + width, Y + height);
    DrawLine(0, bracket_size);
    DrawLine(2, bracket_size);
    SetPos(X, Y + height);
    DrawLine(3, bracket_size);
    DrawLine( 0, bracket_size);

    SetPos(X, Y);
}
*/

native final function DrawRotatedTile( Texture2D Tex, rotator Rotation, float XL, float YL,  float U, float V,float UL, float VL,
											optional float AnchorX, optional float AnchorY);

native final function DrawRotatedMaterialTile( MaterialInterface Mat, rotator Rotation, float XL, float YL,  optional float U, optional float V,
													optional float UL, optional float VL, optional float AnchorX, optional float AnchorY);


native final function Draw2DLine(float X1, float Y1, float X2, float Y2, color LineColor);

native final function DrawTextureLine(vector StartPoint, vector EndPoint, float Perc, float Width, color LineColor, Texture2D LineTexture, float U, float V, float UL, float VL );
native final function DrawTextureDoubleLine(vector StartPoint, vector EndPoint, float Perc, float Spacing, float Width,	color LineColor, color AltLineColor, Texture2D Tex, float U, float V, float UL, float VL);

defaultproperties
{
   Font=Font'EngineFonts.SmallFont'
   DrawColor=(B=127,G=127,R=127,A=255)
   ColorModulate=(W=1.000000,X=1.000000,Y=1.000000,Z=1.000000)
   DefaultTexture=Texture2D'EngineResources.WhiteSquareTexture'
   Name="Default__Canvas"
   ObjectArchetype=Object'Core.Default__Object'
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: tr 31-1-2018 17:17:52.000 - Creation time: sk 18-3-2018 10:01:06.363 - Created with UnCodeX