from retail

This commit is contained in:
NoM0Re
2025-01-26 21:52:59 +01:00
parent f9bf9c3c16
commit 0e761a6814
6 changed files with 416 additions and 69 deletions
+20 -69
View File
@@ -84,7 +84,7 @@ local function create(parent)
region:SetResizable(true);
region:SetMinResize(1, 1);
local texture = region:CreateTexture();
local texture = Private.TextureBase.create(region)
region.texture = texture;
texture:SetAllPoints(region);
@@ -93,73 +93,40 @@ local function create(parent)
return region;
end
local SQRT2 = sqrt(2)
local function GetRotatedPoints(degrees, scaleForFullRotate)
local angle = rad(135 - degrees);
local factor = scaleForFullRotate and 1 or SQRT2
local vx = math.cos(angle) / factor
local vy = math.sin(angle) / factor
return 0.5+vx,0.5-vy , 0.5-vy,0.5-vx , 0.5+vy,0.5+vx , 0.5-vx,0.5+vy
end
local function modify(parent, region, data)
Private.regionPrototype.modify(parent, region, data);
region.texture:SetDesaturated(data.desaturate)
region:SetWidth(data.width);
region:SetHeight(data.height);
region.width = data.width;
region.height = data.height;
region.scalex = 1;
region.scaley = 1;
region.texture:SetBlendMode(data.blendMode);
region.mirror = data.mirror
local function DoTexCoord()
local mirror_h, mirror_v = region.mirror_h, region.mirror_v;
if(region.mirror) then
mirror_h = not mirror_h;
end
local ulx,uly , llx,lly , urx,ury , lrx,lry
= GetRotatedPoints(region.effectiveRotation, data.rotate)
if(mirror_h) then
if(mirror_v) then
region.texture:SetTexCoord(lrx,lry , urx,ury , llx,lly , ulx,uly);
else
region.texture:SetTexCoord(urx,ury , lrx,lry , ulx,uly , llx,lly);
end
else
if(mirror_v) then
region.texture:SetTexCoord(llx,lly , ulx,uly , lrx,lry , urx,ury);
else
region.texture:SetTexCoord(ulx,uly , llx,lly , urx,ury , lrx,lry);
end
end
end
region.rotation = data.rotation
region.effectiveRotation = region.rotation
Private.TextureBase.modify(region.texture, {
canRotate = data.rotate,
desaturate = data.desaturate,
blendMode = data.blendMode,
mirror = data.mirror,
rotation = data.rotation,
textureWrapMode = data.textureWrapMode
})
function region:Scale(scalex, scaley)
region.scalex = scalex;
region.scaley = scaley;
local mirror_h, mirror_v
if(scalex < 0) then
region.mirror_h = true;
mirror_h = true
scalex = scalex * -1;
else
region.mirror_h = nil;
end
region:SetWidth(region.width * scalex);
if(scaley < 0) then
scaley = scaley * -1;
region.mirror_v = true;
else
region.mirror_v = nil;
mirror_v = true
end
region:SetHeight(region.height * scaley);
DoTexCoord();
region.texture:SetMirrorFromScale(mirror_h, mirror_v)
end
function region:SetRegionWidth(width)
@@ -173,26 +140,17 @@ local function modify(parent, region, data)
end
function region:SetMirror(mirror)
region.mirror = mirror
DoTexCoord()
self.texture:SetMirror(mirror)
end
function region:Update()
if self.state.texture then
self:SetTexture(self.state.texture)
self.texture:SetTexture(self.state.texture)
end
self:UpdateProgress()
end
function region:SetTexture(texture)
if self.textureName == texture then
return
end
self.textureName = texture
self.texture:SetTexture(self.textureName);
DoTexCoord()
end
region:SetTexture(data.texture)
region.texture:SetTexture(data.texture)
function region:Color(r, g, b, a)
region.color_r = r;
@@ -224,26 +182,19 @@ local function modify(parent, region, data)
region:Color(data.color[1], data.color[2], data.color[3], data.color[4]);
function region:SetDesaturated(b)
region.texture:SetDesaturated(b);
self.texture:SetDesaturated(b)
end
function region:SetAnimRotation(degrees)
region.animRotation = degrees
region:UpdateEffectiveRotation()
self.texture:SetAnimRotation(degrees)
end
function region:SetRotation(degrees)
region.rotation = degrees
region:UpdateEffectiveRotation()
end
function region:UpdateEffectiveRotation()
region.effectiveRotation = region.animRotation or region.rotation
DoTexCoord()
self.texture:SetRotation(degrees)
end
function region:GetBaseRotation()
return region.rotation
return self.texture:GetBaseRotation()
end
region:SetRotation(data.rotation)