vec3
A three-dimenstional vector, in Teeworlds commonly used for colors
Attributes:
x
/
r
/
h
– x-part of the vector / the red-part of the RGB-color / the hue-part of the HSL-color
y
/
g
/
s
– y-part of the vector / the green-part of the RGB-color / the saturation-part of the HSL-color
z
/
b
/
l
– z-part of the vector / the blue-part of the RGB-color / the lighting-part of the HSL-color
Usage:
MyVec = vec3(20.4, 30.6, 40.8)
print(Vector3.x, Vector3.y, Vector3.z) -- > 20,39999961853 30,60000038147 40,799999237061
print(Vector3.r, Vector3.g, Vector3.b) -- > 20,39999961853 30,60000038147 40,799999237061
print(Vector3.h, Vector3.s, Vector3.l) -- > 20,39999961853 30,60000038147 40,799999237061
-- // again floating-point-error!
MyVec.x = 1
MyVec.g = 2
MyVec.l = 3
print(Vector3.x, Vector3.y, Vector3.z) -- > 1 2 3
print(Vector3.r, Vector3.g, Vector3.b) -- > 1 2 3
print(Vector3.h, Vector3.s, Vector3.l) -- > 1 2 3
vec4
A four-dimensional vector, commonly used for RGBA-colors (other rare use case: three dimensional vector with time)
Attributes:
r
/
x
– red-part of the RGBA-colors / the x-part of the four-dimensional vector
g
/
y
– green-part of the RGBA-colors / the y-part of the four-dimensional vector
b
/
z
– blue-part of the RGBA-colors / the z-part of the four-dimensional vector
a
/
w
– alpha-part of the RGBA-colors / the time-part of the four-dimensional vector
Usage:
Vector4 = vec4(20.4, 30.6, 40.8, 50.1)
-- To get the data of a vec4 simply do this with:
print(Vector4.x,Vector4.y,Vector4.z) -- > 20,39999961853 30,60000038147 40,799999237061
print(Vector4.r,Vector4.g,Vector4.b,Vector4.a) -- > 20,39999961853 30,60000038147 40,799999237061 50,099998474121
-- I don't know if i used this rightly.
print(Vector4.w,Vector4.u,Vector4.v) -- > 50,099998474121 40,799999237061 50,099998474121
-- I don't know why its returning such unrounded values.
UIRect
Represents a rectangle used for user interface rendering
Attributes:
x
– the x-coordinate
y
– the y-coordinate
w
– the width
h
– the height
Methods:
HSplitMid
splits the rect horizontally in the middle, putting the resulting parts into
Top and
Bottom
void HSplitMid(out UIRect Top, out UIRect Bottom) [const]
HSplitTop
splits the rect horizontally at
Offset units from the top, putting the resulting parts into
Top and
Bottom
void HSplitTop(float Offset, out UIRect Top, out UIRect Bottom> [const]
HSplitBottom
splits the rect horizontally at
Offset units from the bottom, putting the resulting parts into
Top and
Bottom
void HSplitBottom(float Offset, out UIRect Top, out UIRect Bottom) [const]
VSplitMid
splits the rect vertically in the middle, putting the resulting parts into
Left and
Right
void VSplitMid(out UIRect Left, out UIRect Right) [const]
VSplitLeft
splits the rect vertically at
Offset units from the left, putting the resulting parts into
Left and
Right
void VSplitLeft(float Offset, out UIRect Left, out UIRect Right) [const]
VSplitRight
splits the rect vertically at
Offset units from the right, putting the resulting parts into
Left and
Right
void VSplitRight(float Offset, out UIRect Left, out UIRect Right) [const]
HMargin
cuts away
Offset units from both the top and the bottom of the rect, and stores the result in
Dest
void HMargin(float Offset, out UIRect Dest) [const]
VMargin
cuts away
Offset units from both the right and the left of the rect, and stores the result in
Dest
void VMargin(float Offset, out UIRect Dest) [const]
Margin
cuts away
Offset units from all sides of the rect and stores the result in
Dest
void Margin(float Offset, out UIRect Dest) [const]
copy
creates a new UIRect that is equal to the current one, and returns a reference to this new copy
UIRect copy() [const]
Usage:
NewRect = UIRect(0,0,0,0) -- UIRect(x, y, width, height)
-- To get an UIRect which is as large as the entire screen (=teeworlds window), use:
Screen = Game.Ui:Screen()
-- IMPORTANT! If you want to COPY a rect use:
Screen2 = Screen:copy()
-- insteed of:
Screen2 = Screen
-- Using the copy function is necessary because otherwise Screen2 and Screen would both point to the same UIRect, thus chaning one would change the other!
-- Output (without copy):
local Screen = Game.Ui:Screen()
local MainView = Screen
print(MainView.x,MainView.y,MainView.h,MainView.w) -- > 0 0 600 960
MainView.x = 100
print(MainView.x,MainView.y,MainView.h,MainView.w) -- > 100 0 600 960
print(Screen.x,Screen.y,Screen.h,Screen.w) -- > 100 0 600 960
-- Output (with copy):
local Screen = Game.Ui:Screen()
local MainView = Screen:copy()
print(MainView.x,MainView.y,MainView.h,MainView.w) -- > 0 0 600 960
MainView.x = 100
print(MainView.x,MainView.y,MainView.h,MainView.w) -- > 100 0 600 960
print(Screen.x,Screen.y,Screen.h,Screen.w) -- > 0 0 600 960
-- Now the complicated things about the UIRect... :)
-- To split a rect horizontally, defining a margin from top, you can use:
NewRect = UIRect(0,0,100,100)
local NewRect1 = UIRect(0,0,0,0)
local NewRect2 = UIRect(0,0,0,0)
NewRect:HSplitTop(10,NewRect1,NewRect2) -- Splits NewRect by 10 pixel from TOP in NewRect1 and NewRect2
print(NewRect1.x,NewRect1.y,NewRect1.w,NewRect1.h) -- > 0 0 100 10 -- This is the top part which's size you've defined (here 10)
print(NewRect2.x,NewRect2.y,NewRect2.w,NewRect2.h) -- > 0 10 100 90 -- This is the rest of the old rect, thus the bottom part
-- You can also split rects with: NewRect:HSplitBottom(N,UIRect1,UIRect2) and NewRect:HSplitMid(N,UIRect1,UIRect2) the principe is the same. (N = pixels, UIRect1 = 1st UIRect, UIRect2 = 2nd UIRect)
-- To split a rect vertically, defining a margin from the right, you can use:
NewRect = UIRect(0,0,100,100)
local NewRect1 = UIRect(0,0,0,0)
local NewRect2 = UIRect(0,0,0,0)
NewRect:VSplitRight(10,NewRect1,NewRect2) -- Splits NewRect by 10 pixel from the right in NewRect1 and NewRect2
print(NewRect1.x,NewRect1.y,NewRect1.w,NewRect1.h) -- > 0 0 90 100 -- This is now right part of the old rect
print(NewRect2.x,NewRect2.y,NewRect2.w,NewRect2.h) -- > 90 0 10 100 -- This is the rest of the old rect
-- You can also split rects with: NewRect:VSplitLeft(N,UIRect1,UIRect2) and NewRect:VSplitMid(N,UIRect1,UIRect2) the principe is the same. (N = pixels, UIRect1 = 1st UIRect, UIRect2 = 2nd UIRect)
-- You can also cut away a margin at multiple sides of the rect, spacing it out evenly:
-- For a margin all around the rect:
NewRect = UIRect(0,0,100,100)
NewRect:Margin(10,NewRect) -- Modifies 'NewRect' to contain the result
print(NewRect.x,NewRect.y,NewRect.w,NewRect.h) -- > 10 10 80 80
-- For a margin from the right and left:
NewRect = UIRect(0,0,100,100)
NewRect:VMargin(10,NewRect) -- Returns the new Rect in NewRect
print(NewRect.x,NewRect.y,NewRect.w,NewRect.h) -- > 10 0 80 100
-- And for a margin from the top and bottom:
NewRect = UIRect(0,0,100,100)
NewRect:HMargin(10,NewRect) -- Returns the new Rect in NewRect
print(NewRect.x,NewRect.y,NewRect.w,NewRect.h) -- > 0 10 100 80
See also:
Game.Ui:Screen
Game.RenderTools:DrawUIRect