-
Notifications
You must be signed in to change notification settings - Fork 7
/
base.gfx.renderconfig.bmx
executable file
·105 lines (83 loc) · 2.81 KB
/
base.gfx.renderconfig.bmx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
SuperStrict
Import Brl.LinkedList
Import "base.util.color.bmx"
Import "base.util.rectangle.bmx"
Import "base.util.vector.bmx"
Import "base.util.graphicsmanagerbase.bmx"
Type TRenderConfig
Field clsColor:SColor8
Field color:SColor8
Field alpha:Float
Field blendMode:Int
Field scaleX:Float, scaleY:Float
Field originX:Float, originY:Float
Field rotation:Float
Field viewport:SRect
Global list:TList = CreateList()
Global _stackedViewport:TRectangle = new TRectangle
Global _stackedViewportValid:Int = False
'fetch the last render configuration from the list
'and use its values
'returns the popped config
Function Pop:TRenderconfig()
local config:TRenderConfig = TRenderConfig(list.RemoveLast())
if not config then return Null
SetColor(config.color)
SetAlpha(config.alpha)
SetCLSColor(config.clsColor)
SetBlend(config.blendMode)
SetOrigin(config.originX, config.originY)
SetScale(config.scaleX, config.scaleY)
SetRotation(config.rotation)
GetGraphicsManager().setViewPort(int(config.viewport.x), int(config.viewport.y), int(config.viewport.w), int(config.viewport.h))
return config
End Function
'remove a specific configuration
Function RemoveConfig:Int(config:TRenderConfig)
if list.Remove(config)
_stackedViewport = null
endif
End Function
'store the current render configuration in the list
Function Push:TRenderConfig()
local config:TRenderConfig = new TRenderConfig
GetColor(config.color)
config.alpha = GetAlpha()
local r:int, g:int, b:int; GetClsColor(r,g,b)
config.clsColor = new SColor8(r,g,b)
config.blendMode = GetBlend()
config.rotation = GetRotation()
GetOrigin(config.originX, config.originY)
GetScale(config.scaleX, config.scaleY)
config.rotation = GetRotation()
local x:int,y:int,w:int,h:int; GetGraphicsManager().GetViewPort(x, y, w, h)
config.viewport = new SRect(x,y,w,h)
list.AddLast(config)
return config
End Function
'returns the viewport of all configurations overlayed (passepartout)
Function GetStackedViewPort:SRect()
local result:SRect
local isFirst:Int = True
For local config:TRenderConfig = EachIn list
'if first configuration: copy as first viewport rect
if isFirst
result = config.viewport
isFirst = False
continue
endif
'all other configurations intersect with the base rect (they
'keep decreasing the viewport)
result = result.IntersectRect(config.viewport)
Next
return result
End Function
'Sets the viewport of all configurations overlayed (passepartout)
Function SetStackedViewPort()
if not list or list.count() = 0
GetGraphicsManager().SetViewPort(0, 0, GetGraphicsManager().realWidth, GetGraphicsManager().realHeight)
EndIf
local result:SRect = GetStackedViewPort()
GetGraphicsManager().SetViewPort(int(result.x), int(result.y), int(result.w), int(result.h))
End Function
End Type