File size: 3,105 Bytes
b6a38d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
-- ========== GENERATED BY XTemplate Editor (Alt-F3) DO NOT EDIT MANUALLY! ==========

PlaceObj('XTemplate', {
	group = "GedApps",
	id = "GedImageViewer",
	save_in = "Ged",
	PlaceObj('XTemplateWindow', {
		'__class', "GedApp",
		'LayoutMethod', "Box",
		'Translate', true,
		'Title', "File Editor",
	}, {
		PlaceObj('XTemplateAction', {
			'ActionId', "ToggleAlpha",
			'ActionName', T(982004005762, --[[XTemplate GedImageViewer ActionName]] "Toggle Alpha Only"),
			'ActionMenubar', "main",
			'ActionToggle', true,
			'ActionToggled', function (self, host)
				return host.show_alpha_only
			end,
			'OnAction', function (self, host, source, ...)
				rawset(host, "show_alpha_only", not rawget(host, "show_alpha_only"))
				if host.show_alpha_only then
					host.idFile:AddShaderModifier({
						modifier_type = const.modShader,
						shader_flags = const.modImageCompAlpha
					})
				else
					host.idFile:RemoveModifiers(const.modShader)
				end
			end,
		}),
		PlaceObj('XTemplateWindow', {
			'__class', "XImage",
			'Id', "idFile",
			'ImageFit', "scale-down",
		}),
		PlaceObj('XTemplateWindow', {
			'__class', "XText",
			'Id', "idError",
			'Dock', "top",
			'FoldWhenHidden', true,
			'TextStyle', "GedError",
			'HideOnEmpty', true,
		}),
		PlaceObj('XTemplateWindow', {
			'__class', "XText",
			'Id', "idTextureInfo",
			'Dock', "top",
			'FoldWhenHidden', true,
			'HideOnEmpty', true,
		}),
		PlaceObj('XTemplateWindow', {
			'__class', "XText",
			'Id', "idStreamingInfo",
			'Dock', "top",
			'FoldWhenHidden', true,
			'HideOnEmpty', true,
		}),
		PlaceObj('XTemplateCode', {
			'comment', "read file",
			'run', function (self, parent, context)
				local os_path = ConvertToOSPath(context.file_name)
				if not os_path or os_path == "" then
					parent.idError:SetText(string.format("Could not convert %s to os path.", context.file_name))
					parent:SetTitle("File " .. context.file_name)
				else
					parent:SetTitle("File " .. os_path)
				end
				
				parent:SetTitle("File " .. os_path)
				parent.idFile:SetImage(context.file_name)
				if context.show_alpha_only then
					parent.idFile:AddShaderModifier({
						modifier_type = const.modShader,
						shader_flags = const.modImageCompAlpha
					})
				end
				
				local texId = ResourceManager.GetResourceID(context.file_name)
				if texId == const.InvalidResourceID then
					parent.idError:SetText(string.format("Image by name %s not found.", context.file_name))
				else
					local metadata = ResourceManager.GetMetadata(texId)
					local format = GetDataFormatName(metadata.Format)
				
					parent.idTextureInfo:SetText(string.format("ResourceID: %d; Size: %dx%d; Mips: %d; Format: %s", texId, metadata.Width, metadata.Height, metadata.NumLevels, format))
				
					if not Platform.ged then
						parent:CreateThread("UpdateTextureData", function(self)
							local resource = AsyncGetResource(texId)
							while true do
								self.idStreamingInfo:SetText(string.format("Resident Mips: %d", resource:GetResidentMips()))
								WaitNextFrame(5)
							end
						end, parent)
					end
				end
			end,
		}),
		}),
})