annotate Libs/DF/pictureedit.lua @ 63:3552946c0b9a tip

Added tag v8.2.0.062 for changeset d6704922ef5d
author Tercioo
date Fri, 28 Jun 2019 20:06:18 -0300
parents 0682d738499b
children
rev   line source
Tercio@11 1
Tercio@11 2 local DF = _G ["DetailsFramework"]
Tercio@20 3 if (not DF or not DetailsFrameworkCanLoad) then
Tercio@20 4 return
Tercio@20 5 end
Tercio@20 6
Tercio@11 7 local _
Tercio@11 8
Tercio@11 9 local window = DF:NewPanel (UIParent, nil, "DetailsFrameworkImageEdit", nil, 100, 100, false)
Tercio@11 10 window:SetPoint ("center", UIParent, "center")
Tercio@11 11 window:SetResizable (true)
Tercio@11 12 window:SetMovable (true)
Tercio@11 13 tinsert (UISpecialFrames, "DetailsFrameworkImageEdit")
Tercio@11 14 window:SetFrameStrata ("TOOLTIP")
Tercio@49 15 window:SetMaxResize (650, 500)
Tercio@11 16
Tercio@11 17 window.hooks = {}
Tercio@11 18
Tercio@11 19 local background = DF:NewImage (window, nil, nil, nil, "background", nil, nil, "$parentBackground")
Tercio@11 20 background:SetAllPoints()
Tercio@11 21 background:SetTexture (0, 0, 0, .8)
Tercio@11 22
Tercio@49 23 local edit_texture = DF:NewImage (window, nil, 650, 500, "artwork", nil, nil, "$parentImage")
Tercio@11 24 edit_texture:SetAllPoints()
Tercio@11 25
Tercio@11 26 local background_frame = CreateFrame ("frame", "DetailsFrameworkImageEditBackground", DetailsFrameworkImageEdit)
Tercio@11 27 background_frame:SetPoint ("topleft", DetailsFrameworkImageEdit, "topleft", -10, 12)
Tercio@11 28 background_frame:SetFrameStrata ("DIALOG")
Tercio@49 29 background_frame:SetSize (800, 540)
Tercio@11 30
Tercio@11 31 background_frame:SetResizable (true)
Tercio@11 32 background_frame:SetMovable (true)
Tercio@11 33
Tercio@11 34 background_frame:SetScript ("OnMouseDown", function()
Tercio@11 35 window:StartMoving()
Tercio@11 36 end)
Tercio@11 37 background_frame:SetScript ("OnMouseUp", function()
Tercio@11 38 window:StopMovingOrSizing()
Tercio@11 39 end)
Tercio@11 40
Tercio@22 41 background_frame:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
Tercio@22 42 background_frame:SetBackdropColor (0, 0, 0, 0.9)
Tercio@22 43 background_frame:SetBackdropBorderColor (0, 0, 0, 1)
Tercio@11 44
Tercio@11 45 local haveHFlip = false
Tercio@11 46 local haveVFlip = false
Tercio@11 47
Tercio@11 48 --> Top Slider
Tercio@11 49
Tercio@11 50 local topCoordTexture = DF:NewImage (window, nil, nil, nil, "overlay", nil, nil, "$parentImageTopCoord")
Tercio@11 51 topCoordTexture:SetPoint ("topleft", window, "topleft")
Tercio@11 52 topCoordTexture:SetPoint ("topright", window, "topright")
Tercio@49 53 topCoordTexture:SetColorTexture (1, 0, 0)
Tercio@11 54 topCoordTexture.height = 1
Tercio@11 55 topCoordTexture.alpha = .2
Tercio@11 56
Tercio@11 57 local topSlider = DF:NewSlider (window, nil, "$parentTopSlider", "topSlider", 100, 100, 0.1, 100, 0.1, 0)
Tercio@11 58 topSlider:SetAllPoints (window.widget)
Tercio@11 59 topSlider:SetOrientation ("VERTICAL")
Tercio@11 60 topSlider.backdrop = nil
Tercio@11 61 topSlider.fractional = true
Tercio@11 62 topSlider:SetHook ("OnEnter", function() return true end)
Tercio@11 63 topSlider:SetHook ("OnLeave", function() return true end)
Tercio@11 64
Tercio@11 65 local topSliderThumpTexture = topSlider:CreateTexture (nil, "overlay")
Tercio@49 66 topSliderThumpTexture:SetColorTexture (1, 1, 1)
Tercio@11 67 topSliderThumpTexture:SetWidth (512)
Tercio@49 68 topSliderThumpTexture:SetHeight (1)
Tercio@11 69 topSlider:SetThumbTexture (topSliderThumpTexture)
Tercio@11 70
Tercio@11 71 topSlider:SetHook ("OnValueChange", function (_, _, value)
Tercio@11 72 topCoordTexture.image:SetHeight (window.frame:GetHeight()/100*value)
Tercio@11 73 if (window.callback_func) then
Tercio@22 74 window.accept (nil, nil, true)
Tercio@11 75 end
Tercio@11 76 end)
Tercio@11 77
Tercio@11 78 topSlider:Hide()
Tercio@11 79
Tercio@11 80 --> Bottom Slider
Tercio@11 81
Tercio@11 82 local bottomCoordTexture = DF:NewImage (window, nil, nil, nil, "overlay", nil, nil, "$parentImageBottomCoord")
Tercio@11 83 bottomCoordTexture:SetPoint ("bottomleft", window, "bottomleft", 0, 0)
Tercio@11 84 bottomCoordTexture:SetPoint ("bottomright", window, "bottomright", 0, 0)
Tercio@49 85 bottomCoordTexture:SetColorTexture (1, 0, 0)
Tercio@11 86 bottomCoordTexture.height = 1
Tercio@11 87 bottomCoordTexture.alpha = .2
Tercio@11 88
Tercio@11 89 local bottomSlider= DF:NewSlider (window, nil, "$parentBottomSlider", "bottomSlider", 100, 100, 0.1, 100, 0.1, 100)
Tercio@11 90 bottomSlider:SetAllPoints (window.widget)
Tercio@11 91 bottomSlider:SetOrientation ("VERTICAL")
Tercio@11 92 bottomSlider.backdrop = nil
Tercio@11 93 bottomSlider.fractional = true
Tercio@11 94 bottomSlider:SetHook ("OnEnter", function() return true end)
Tercio@11 95 bottomSlider:SetHook ("OnLeave", function() return true end)
Tercio@11 96
Tercio@11 97 local bottomSliderThumpTexture = bottomSlider:CreateTexture (nil, "overlay")
Tercio@49 98 bottomSliderThumpTexture:SetColorTexture (1, 1, 1)
Tercio@11 99 bottomSliderThumpTexture:SetWidth (512)
Tercio@49 100 bottomSliderThumpTexture:SetHeight (1)
Tercio@11 101 bottomSlider:SetThumbTexture (bottomSliderThumpTexture)
Tercio@11 102
Tercio@11 103 bottomSlider:SetHook ("OnValueChange", function (_, _, value)
Tercio@11 104 value = math.abs (value-100)
Tercio@11 105 bottomCoordTexture.image:SetHeight (math.max (window.frame:GetHeight()/100*value, 1))
Tercio@11 106 if (window.callback_func) then
Tercio@22 107 window.accept (nil, nil, true)
Tercio@11 108 end
Tercio@11 109 end)
Tercio@11 110
Tercio@11 111 bottomSlider:Hide()
Tercio@11 112
Tercio@11 113 --> Left Slider
Tercio@11 114
Tercio@11 115 local leftCoordTexture = DF:NewImage (window, nil, nil, nil, "overlay", nil, nil, "$parentImageLeftCoord")
Tercio@11 116 leftCoordTexture:SetPoint ("topleft", window, "topleft", 0, 0)
Tercio@11 117 leftCoordTexture:SetPoint ("bottomleft", window, "bottomleft", 0, 0)
Tercio@49 118 leftCoordTexture:SetColorTexture (1, 0, 0)
Tercio@11 119 leftCoordTexture.width = 1
Tercio@11 120 leftCoordTexture.alpha = .2
Tercio@11 121
Tercio@11 122 local leftSlider = DF:NewSlider (window, nil, "$parentLeftSlider", "leftSlider", 100, 100, 0.1, 100, 0.1, 0.1)
Tercio@11 123 leftSlider:SetAllPoints (window.widget)
Tercio@11 124 leftSlider.backdrop = nil
Tercio@11 125 leftSlider.fractional = true
Tercio@11 126 leftSlider:SetHook ("OnEnter", function() return true end)
Tercio@11 127 leftSlider:SetHook ("OnLeave", function() return true end)
Tercio@11 128
Tercio@11 129 local leftSliderThumpTexture = leftSlider:CreateTexture (nil, "overlay")
Tercio@49 130 leftSliderThumpTexture:SetColorTexture (1, 1, 1)
Tercio@49 131 leftSliderThumpTexture:SetWidth (1)
Tercio@11 132 leftSliderThumpTexture:SetHeight (512)
Tercio@11 133 leftSlider:SetThumbTexture (leftSliderThumpTexture)
Tercio@11 134
Tercio@11 135 leftSlider:SetHook ("OnValueChange", function (_, _, value)
Tercio@11 136 leftCoordTexture.image:SetWidth (window.frame:GetWidth()/100*value)
Tercio@11 137 if (window.callback_func) then
Tercio@22 138 window.accept (nil, nil, true)
Tercio@11 139 end
Tercio@11 140 end)
Tercio@11 141
Tercio@11 142 leftSlider:Hide()
Tercio@11 143
Tercio@11 144 --> Right Slider
Tercio@11 145
Tercio@11 146 local rightCoordTexture = DF:NewImage (window, nil, nil, nil, "overlay", nil, nil, "$parentImageRightCoord")
Tercio@11 147 rightCoordTexture:SetPoint ("topright", window, "topright", 0, 0)
Tercio@11 148 rightCoordTexture:SetPoint ("bottomright", window, "bottomright", 0, 0)
Tercio@49 149 rightCoordTexture:SetColorTexture (1, 0, 0)
Tercio@11 150 rightCoordTexture.width = 1
Tercio@11 151 rightCoordTexture.alpha = .2
Tercio@11 152
Tercio@11 153 local rightSlider = DF:NewSlider (window, nil, "$parentRightSlider", "rightSlider", 100, 100, 0.1, 100, 0.1, 100)
Tercio@11 154 rightSlider:SetAllPoints (window.widget)
Tercio@11 155 rightSlider.backdrop = nil
Tercio@11 156 rightSlider.fractional = true
Tercio@11 157 rightSlider:SetHook ("OnEnter", function() return true end)
Tercio@11 158 rightSlider:SetHook ("OnLeave", function() return true end)
Tercio@11 159 --[
Tercio@11 160 local rightSliderThumpTexture = rightSlider:CreateTexture (nil, "overlay")
Tercio@49 161 rightSliderThumpTexture:SetColorTexture (1, 1, 1)
Tercio@49 162 rightSliderThumpTexture:SetWidth (1)
Tercio@11 163 rightSliderThumpTexture:SetHeight (512)
Tercio@11 164 rightSlider:SetThumbTexture (rightSliderThumpTexture)
Tercio@11 165 --]]
Tercio@11 166 rightSlider:SetHook ("OnValueChange", function (_, _, value)
Tercio@11 167 value = math.abs (value-100)
Tercio@11 168 rightCoordTexture.image:SetWidth (math.max (window.frame:GetWidth()/100*value, 1))
Tercio@11 169 if (window.callback_func) then
Tercio@22 170 window.accept (nil, nil, true)
Tercio@11 171 end
Tercio@11 172 end)
Tercio@11 173
Tercio@11 174 rightSlider:Hide()
Tercio@11 175
Tercio@11 176 --> Edit Buttons
Tercio@11 177
Tercio@11 178 local buttonsBackground = DF:NewPanel (UIParent, nil, "DetailsFrameworkImageEditButtonsBg", nil, 115, 230)
Tercio@11 179 --buttonsBackground:SetPoint ("topleft", window, "topright", 2, 0)
Tercio@11 180 buttonsBackground:SetPoint ("topright", background_frame, "topright", -8, -10)
Tercio@11 181 buttonsBackground:Hide()
Tercio@11 182 --buttonsBackground:SetMovable (true)
Tercio@11 183 tinsert (UISpecialFrames, "DetailsFrameworkImageEditButtonsBg")
Tercio@11 184 buttonsBackground:SetFrameStrata ("TOOLTIP")
Tercio@11 185
Tercio@11 186 local alphaFrameShown = false
Tercio@11 187
Tercio@11 188 local editingSide = nil
Tercio@11 189 local lastButton = nil
Tercio@11 190 local alphaFrame
Tercio@11 191 local originalColor = {0.9999, 0.8196, 0}
Tercio@11 192
Tercio@22 193 local enableTexEdit = function (button, b, side)
Tercio@11 194
Tercio@11 195 if (alphaFrameShown) then
Tercio@11 196 alphaFrame:Hide()
Tercio@11 197 alphaFrameShown = false
Tercio@11 198 button.text:SetTextColor (unpack (originalColor))
Tercio@11 199 end
Tercio@11 200
Tercio@11 201 if (ColorPickerFrame:IsShown()) then
Tercio@11 202 ColorPickerFrame:Hide()
Tercio@11 203 end
Tercio@11 204
Tercio@11 205 if (lastButton) then
Tercio@11 206 lastButton.text:SetTextColor (unpack (originalColor))
Tercio@11 207 end
Tercio@11 208
Tercio@11 209 if (editingSide == side) then
Tercio@11 210 window [editingSide.."Slider"]:Hide()
Tercio@11 211 editingSide = nil
Tercio@11 212 return
Tercio@11 213
Tercio@11 214 elseif (editingSide) then
Tercio@11 215 window [editingSide.."Slider"]:Hide()
Tercio@11 216 end
Tercio@11 217
Tercio@11 218 editingSide = side
Tercio@11 219 button.text:SetTextColor (1, 1, 1)
Tercio@11 220 lastButton = button
Tercio@11 221
Tercio@11 222 window [side.."Slider"]:Show()
Tercio@11 223 end
Tercio@11 224
Tercio@11 225 local leftTexCoordButton = DF:NewButton (buttonsBackground, nil, "$parentLeftTexButton", nil, 100, 20, enableTexEdit, "left", nil, nil, "Crop Left", 1)
Tercio@11 226 leftTexCoordButton:SetPoint ("topright", buttonsBackground, "topright", -8, -10)
Tercio@11 227 local rightTexCoordButton = DF:NewButton (buttonsBackground, nil, "$parentRightTexButton", nil, 100, 20, enableTexEdit, "right", nil, nil, "Crop Right", 1)
Tercio@11 228 rightTexCoordButton:SetPoint ("topright", buttonsBackground, "topright", -8, -30)
Tercio@11 229 local topTexCoordButton = DF:NewButton (buttonsBackground, nil, "$parentTopTexButton", nil, 100, 20, enableTexEdit, "top", nil, nil, "Crop Top", 1)
Tercio@11 230 topTexCoordButton:SetPoint ("topright", buttonsBackground, "topright", -8, -50)
Tercio@11 231 local bottomTexCoordButton = DF:NewButton (buttonsBackground, nil, "$parentBottomTexButton", nil, 100, 20, enableTexEdit, "bottom", nil, nil, "Crop Bottom", 1)
Tercio@11 232 bottomTexCoordButton:SetPoint ("topright", buttonsBackground, "topright", -8, -70)
Tercio@11 233 leftTexCoordButton:InstallCustomTexture()
Tercio@11 234 rightTexCoordButton:InstallCustomTexture()
Tercio@11 235 topTexCoordButton:InstallCustomTexture()
Tercio@11 236 bottomTexCoordButton:InstallCustomTexture()
Tercio@11 237
Tercio@11 238 local Alpha = DF:NewButton (buttonsBackground, nil, "$parentBottomAlphaButton", nil, 100, 20, alpha, nil, nil, nil, "Alpha", 1)
Tercio@11 239 Alpha:SetPoint ("topright", buttonsBackground, "topright", -8, -115)
Tercio@11 240 Alpha:InstallCustomTexture()
Tercio@11 241
Tercio@11 242 --> overlay color
Tercio@11 243 local selectedColor = function (default)
Tercio@11 244 if (default) then
Tercio@11 245 edit_texture:SetVertexColor (unpack (default))
Tercio@11 246 if (window.callback_func) then
Tercio@22 247 window.accept (nil, nil, true)
Tercio@11 248 end
Tercio@11 249 else
Tercio@11 250 edit_texture:SetVertexColor (ColorPickerFrame:GetColorRGB())
Tercio@11 251 if (window.callback_func) then
Tercio@22 252 window.accept (nil, nil, true)
Tercio@11 253 end
Tercio@11 254 end
Tercio@11 255 end
Tercio@11 256
Tercio@11 257 local changeColor = function()
Tercio@11 258
Tercio@11 259 ColorPickerFrame.func = nil
Tercio@11 260 ColorPickerFrame.opacityFunc = nil
Tercio@11 261 ColorPickerFrame.cancelFunc = nil
Tercio@11 262 ColorPickerFrame.previousValues = nil
Tercio@11 263
Tercio@11 264 local r, g, b = edit_texture:GetVertexColor()
Tercio@11 265 ColorPickerFrame:SetColorRGB (r, g, b)
Tercio@11 266 ColorPickerFrame:SetParent (buttonsBackground.widget)
Tercio@11 267 ColorPickerFrame.hasOpacity = false
Tercio@11 268 ColorPickerFrame.previousValues = {r, g, b}
Tercio@11 269 ColorPickerFrame.func = selectedColor
Tercio@11 270 ColorPickerFrame.cancelFunc = selectedColor
Tercio@11 271 ColorPickerFrame:ClearAllPoints()
Tercio@11 272 ColorPickerFrame:SetPoint ("left", buttonsBackground.widget, "right")
Tercio@11 273 ColorPickerFrame:Show()
Tercio@11 274
Tercio@11 275 if (alphaFrameShown) then
Tercio@11 276 alphaFrame:Hide()
Tercio@11 277 alphaFrameShown = false
Tercio@11 278 Alpha.button.text:SetTextColor (unpack (originalColor))
Tercio@11 279 end
Tercio@11 280
Tercio@11 281 if (lastButton) then
Tercio@11 282 lastButton.text:SetTextColor (unpack (originalColor))
Tercio@11 283 if (editingSide) then
Tercio@11 284 window [editingSide.."Slider"]:Hide()
Tercio@11 285 end
Tercio@11 286 end
Tercio@11 287 end
Tercio@11 288
Tercio@11 289 local changeColorButton = DF:NewButton (buttonsBackground, nil, "$parentOverlayColorButton", nil, 100, 20, changeColor, nil, nil, nil, "Color", 1)
Tercio@11 290 changeColorButton:SetPoint ("topright", buttonsBackground, "topright", -8, -95)
Tercio@11 291 changeColorButton:InstallCustomTexture()
Tercio@11 292
Tercio@11 293 alphaFrame = DF:NewPanel (buttonsBackground, nil, "DetailsFrameworkImageEditAlphaBg", nil, 40, 225)
Tercio@11 294 alphaFrame:SetPoint ("topleft", buttonsBackground, "topright", 2, 0)
Tercio@11 295 alphaFrame:Hide()
Tercio@11 296 local alphaSlider = DF:NewSlider (alphaFrame, nil, "$parentAlphaSlider", "alphaSlider", 30, 220, 1, 100, 1, edit_texture:GetAlpha()*100)
Tercio@11 297 alphaSlider:SetPoint ("top", alphaFrame, "top", 0, -5)
Tercio@11 298 alphaSlider:SetOrientation ("VERTICAL")
Tercio@11 299 alphaSlider.thumb:SetSize (40, 30)
Tercio@11 300 --leftSlider.backdrop = nil
Tercio@11 301 --leftSlider.fractional = true
Tercio@11 302
Tercio@22 303 local alpha = function (button)
Tercio@11 304
Tercio@11 305 if (ColorPickerFrame:IsShown()) then
Tercio@11 306 ColorPickerFrame:Hide()
Tercio@11 307 end
Tercio@11 308
Tercio@11 309 if (lastButton) then
Tercio@11 310 lastButton.text:SetTextColor (unpack (originalColor))
Tercio@11 311 if (editingSide) then
Tercio@11 312 window [editingSide.."Slider"]:Hide()
Tercio@11 313 end
Tercio@11 314 end
Tercio@11 315
Tercio@11 316 if (not alphaFrameShown) then
Tercio@11 317 alphaFrame:Show()
Tercio@11 318 alphaSlider:SetValue (edit_texture:GetAlpha()*100)
Tercio@11 319 alphaFrameShown = true
Tercio@11 320 button.text:SetTextColor (1, 1, 1)
Tercio@11 321 else
Tercio@11 322 alphaFrame:Hide()
Tercio@11 323 alphaFrameShown = false
Tercio@11 324 button.text:SetTextColor (unpack (originalColor))
Tercio@11 325 end
Tercio@11 326 end
Tercio@11 327
Tercio@11 328 Alpha.clickfunction = alpha
Tercio@11 329
Tercio@11 330 alphaSlider:SetHook ("OnValueChange", function (_, _, value)
Tercio@11 331 edit_texture:SetAlpha (value/100)
Tercio@11 332 if (window.callback_func) then
Tercio@22 333 window.accept (nil, nil, true)
Tercio@11 334 end
Tercio@11 335 end)
Tercio@11 336
Tercio@11 337 local resizer = CreateFrame ("Button", nil, window.widget)
Tercio@11 338 resizer:SetNormalTexture ([[Interface\AddOns\Details\images\skins\default_skin]])
Tercio@11 339 resizer:SetHighlightTexture ([[Interface\AddOns\Details\images\skins\default_skin]])
Tercio@11 340 resizer:GetNormalTexture():SetTexCoord (0.00146484375, 0.01513671875, 0.24560546875, 0.25927734375)
Tercio@11 341 resizer:GetHighlightTexture():SetTexCoord (0.00146484375, 0.01513671875, 0.24560546875, 0.25927734375)
Tercio@11 342 resizer:SetWidth (16)
Tercio@11 343 resizer:SetHeight (16)
Tercio@11 344 resizer:SetPoint ("BOTTOMRIGHT", window.widget, "BOTTOMRIGHT", 0, 0)
Tercio@11 345 resizer:EnableMouse (true)
Tercio@11 346 resizer:SetFrameLevel (window.widget:GetFrameLevel() + 2)
Tercio@11 347
Tercio@11 348 resizer:SetScript ("OnMouseDown", function (self, button)
Tercio@11 349 window.widget:StartSizing ("BOTTOMRIGHT")
Tercio@11 350 end)
Tercio@11 351
Tercio@11 352 resizer:SetScript ("OnMouseUp", function (self, button)
Tercio@11 353 window.widget:StopMovingOrSizing()
Tercio@11 354 end)
Tercio@11 355
Tercio@11 356 window.widget:SetScript ("OnMouseDown", function()
Tercio@11 357 window.widget:StartMoving()
Tercio@11 358 end)
Tercio@11 359 window.widget:SetScript ("OnMouseUp", function()
Tercio@11 360 window.widget:StopMovingOrSizing()
Tercio@11 361 end)
Tercio@11 362
Tercio@11 363 window.widget:SetScript ("OnSizeChanged", function()
Tercio@11 364 edit_texture.width = window.width
Tercio@11 365 edit_texture.height = window.height
Tercio@11 366 leftSliderThumpTexture:SetHeight (window.height)
Tercio@11 367 rightSliderThumpTexture:SetHeight (window.height)
Tercio@11 368 topSliderThumpTexture:SetWidth (window.width)
Tercio@11 369 bottomSliderThumpTexture:SetWidth (window.width)
Tercio@11 370
Tercio@11 371 rightCoordTexture.image:SetWidth (math.max ( (window.frame:GetWidth() / 100 * math.abs (rightSlider:GetValue()-100)), 1))
Tercio@11 372 leftCoordTexture.image:SetWidth (window.frame:GetWidth()/100*leftSlider:GetValue())
Tercio@11 373 bottomCoordTexture:SetHeight (math.max ( (window.frame:GetHeight() / 100 * math.abs (bottomSlider:GetValue()-100)), 1))
Tercio@11 374 topCoordTexture:SetHeight (window.frame:GetHeight()/100*topSlider:GetValue())
Tercio@11 375
Tercio@11 376 if (window.callback_func) then
Tercio@22 377 window.accept (nil, nil, true)
Tercio@11 378 end
Tercio@11 379 end)
Tercio@11 380
Tercio@11 381
Tercio@11 382
Tercio@11 383 --> flip
Tercio@22 384 local flip = function (button, b, side)
Tercio@11 385 if (side == 1) then
Tercio@11 386 haveHFlip = not haveHFlip
Tercio@11 387 if (window.callback_func) then
Tercio@22 388 window.accept (nil, nil, true)
Tercio@11 389 end
Tercio@11 390 elseif (side == 2) then
Tercio@11 391 haveVFlip = not haveVFlip
Tercio@11 392 if (window.callback_func) then
Tercio@22 393 window.accept (nil, nil, true)
Tercio@11 394 end
Tercio@11 395 end
Tercio@11 396 end
Tercio@11 397
Tercio@11 398 local flipButtonH = DF:NewButton (buttonsBackground, nil, "$parentFlipButton", nil, 100, 20, flip, 1, nil, nil, "Flip H", 1)
Tercio@11 399 flipButtonH:SetPoint ("topright", buttonsBackground, "topright", -8, -140)
Tercio@11 400 flipButtonH:InstallCustomTexture()
Tercio@11 401 --
Tercio@49 402
Tercio@49 403
Tercio@49 404 --> select area to crop
Tercio@49 405 local DragFrame = CreateFrame ("frame", nil, background_frame)
Tercio@49 406 DragFrame:EnableMouse (false)
Tercio@49 407 DragFrame:SetFrameStrata ("TOOLTIP")
Tercio@49 408 DragFrame:SetPoint ("topleft", edit_texture.widget, "topleft")
Tercio@49 409 DragFrame:SetPoint ("bottomright", edit_texture.widget, "bottomright")
Tercio@49 410 DragFrame:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Worldmap\UI-QuestBlob-Inside]], tileSize = 256, tile = true})
Tercio@49 411 DragFrame:SetBackdropColor (1, 1, 1, .2)
Tercio@49 412 DragFrame:Hide()
Tercio@49 413
Tercio@49 414 local SelectionBox_Up = DragFrame:CreateTexture (nil, "overlay")
Tercio@49 415 SelectionBox_Up:SetHeight (1)
Tercio@49 416 SelectionBox_Up:SetColorTexture (1, 1, 1)
Tercio@49 417 local SelectionBox_Down = DragFrame:CreateTexture (nil, "overlay")
Tercio@49 418 SelectionBox_Down:SetHeight (1)
Tercio@49 419 SelectionBox_Down:SetColorTexture (1, 1, 1)
Tercio@49 420 local SelectionBox_Left = DragFrame:CreateTexture (nil, "overlay")
Tercio@49 421 SelectionBox_Left:SetWidth (1)
Tercio@49 422 SelectionBox_Left:SetColorTexture (1, 1, 1)
Tercio@49 423 local SelectionBox_Right = DragFrame:CreateTexture (nil, "overlay")
Tercio@49 424 SelectionBox_Right:SetWidth (1)
Tercio@49 425 SelectionBox_Right:SetColorTexture (1, 1, 1)
Tercio@49 426
Tercio@49 427 function DragFrame.ClearSelectionBoxPoints()
Tercio@49 428 SelectionBox_Up:ClearAllPoints()
Tercio@49 429 SelectionBox_Down:ClearAllPoints()
Tercio@49 430 SelectionBox_Left:ClearAllPoints()
Tercio@49 431 SelectionBox_Right:ClearAllPoints()
Tercio@49 432 end
Tercio@49 433
Tercio@49 434 local StartCrop = function()
Tercio@49 435 DragFrame:Show()
Tercio@49 436 DragFrame:EnableMouse (true)
Tercio@49 437 end
Tercio@49 438
Tercio@49 439 local CropSelection = DF:NewButton (buttonsBackground, nil, "$parentCropSelection", nil, 100, 20, StartCrop, 2, nil, nil, "Crop Selection", 1)
Tercio@49 440 --CropSelection:SetPoint ("topright", buttonsBackground, "topright", -8, -260)
Tercio@49 441 CropSelection:InstallCustomTexture()
Tercio@49 442
Tercio@49 443 DragFrame.OnTick = function (self, deltaTime)
Tercio@49 444 local x1, y1 = unpack (self.ClickedAt)
Tercio@49 445 local x2, y2 = GetCursorPosition()
Tercio@49 446 DragFrame.ClearSelectionBoxPoints()
Tercio@49 447
Tercio@49 448 print (x1, y1, x2, y2)
Tercio@49 449
Tercio@49 450 if (x2 > x1) then
Tercio@49 451 --right
Tercio@49 452 if (y1 > y2) then
Tercio@49 453 --top
Tercio@49 454 SelectionBox_Up:SetPoint ("topleft", UIParent, "bottomleft", x1, y1)
Tercio@49 455 SelectionBox_Up:SetPoint ("topright", UIParent, "bottomleft", x2, y1)
Tercio@49 456
Tercio@49 457 SelectionBox_Left:SetPoint ("topleft", UIParent, "bottomleft", x1, y1)
Tercio@49 458 SelectionBox_Left:SetPoint ("bottomleft", UIParent, "bottomleft", x1, y2)
Tercio@49 459
Tercio@49 460 print (1)
Tercio@49 461 else
Tercio@49 462 --bottom
Tercio@49 463
Tercio@49 464 end
Tercio@49 465 else
Tercio@49 466 --left
Tercio@49 467 if (y2 > y1) then
Tercio@49 468 --top
Tercio@49 469
Tercio@49 470 else
Tercio@49 471 --bottom
Tercio@49 472
Tercio@49 473 end
Tercio@49 474 end
Tercio@49 475
Tercio@49 476 end
Tercio@49 477
Tercio@49 478 DragFrame:SetScript ("OnMouseDown", function (self, MouseButton)
Tercio@49 479 if (MouseButton == "LeftButton") then
Tercio@49 480 self.ClickedAt = {GetCursorPosition()}
Tercio@49 481 DragFrame:SetScript ("OnUpdate", DragFrame.OnTick)
Tercio@49 482
Tercio@49 483 end
Tercio@49 484 end)
Tercio@49 485 DragFrame:SetScript ("OnMouseUp", function (self, MouseButton)
Tercio@49 486 if (MouseButton == "LeftButton") then
Tercio@49 487 self.ReleaseAt = {GetCursorPosition()}
Tercio@49 488 DragFrame:EnableMouse (false)
Tercio@49 489 DragFrame:Hide()
Tercio@49 490 DragFrame:SetScript ("OnUpdate", nil)
Tercio@49 491 print (self.ClickedAt[1], self.ClickedAt[2], self.ReleaseAt[1], self.ReleaseAt[2])
Tercio@49 492 end
Tercio@49 493 end)
Tercio@11 494
Tercio@11 495 --> accept
Tercio@22 496 window.accept = function (self, b, keep_editing)
Tercio@11 497
Tercio@11 498 if (not keep_editing) then
Tercio@11 499 buttonsBackground:Hide()
Tercio@11 500 window:Hide()
Tercio@11 501 alphaFrame:Hide()
Tercio@11 502 ColorPickerFrame:Hide()
Tercio@11 503 end
Tercio@11 504
Tercio@11 505 local coords = {}
Tercio@11 506 local l, r, t, b = leftSlider.value/100, rightSlider.value/100, topSlider.value/100, bottomSlider.value/100
Tercio@11 507
Tercio@11 508 if (haveHFlip) then
Tercio@11 509 coords [1] = r
Tercio@11 510 coords [2] = l
Tercio@11 511 else
Tercio@11 512 coords [1] = l
Tercio@11 513 coords [2] = r
Tercio@11 514 end
Tercio@11 515
Tercio@11 516 if (haveVFlip) then
Tercio@11 517 coords [3] = b
Tercio@11 518 coords [4] = t
Tercio@11 519 else
Tercio@11 520 coords [3] = t
Tercio@11 521 coords [4] = b
Tercio@11 522 end
Tercio@11 523
Tercio@11 524 return window.callback_func (edit_texture.width, edit_texture.height, {edit_texture:GetVertexColor()}, edit_texture:GetAlpha(), coords, window.extra_param)
Tercio@11 525 end
Tercio@11 526
Tercio@11 527 local acceptButton = DF:NewButton (buttonsBackground, nil, "$parentAcceptButton", nil, 100, 20, window.accept, nil, nil, nil, "Done", 1)
Tercio@11 528 acceptButton:SetPoint ("topright", buttonsBackground, "topright", -8, -200)
Tercio@11 529 acceptButton:InstallCustomTexture()
Tercio@11 530
Tercio@11 531
Tercio@11 532
Tercio@11 533 window:Hide()
Tercio@11 534 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 535
Tercio@11 536 local ttexcoord
Tercio@11 537 function DF:ImageEditor (callback, texture, texcoord, colors, width, height, extraParam, alpha, maximize)
Tercio@11 538
Tercio@11 539 texcoord = texcoord or {0, 1, 0, 1}
Tercio@11 540 ttexcoord = texcoord
Tercio@11 541
Tercio@11 542 colors = colors or {1, 1, 1, 1}
Tercio@11 543
Tercio@11 544 alpha = alpha or 1
Tercio@11 545
Tercio@11 546 edit_texture:SetTexture (texture)
Tercio@11 547 edit_texture.width = width
Tercio@11 548 edit_texture.height = height
Tercio@11 549 edit_texture.maximize = maximize
Tercio@11 550
Tercio@11 551 edit_texture:SetVertexColor (colors [1], colors [2], colors [3])
Tercio@11 552
Tercio@11 553 edit_texture:SetAlpha (alpha)
Tercio@11 554
Tercio@11 555 DF:ScheduleTimer ("RefreshImageEditor", 0.2)
Tercio@11 556
Tercio@11 557 window:Show()
Tercio@11 558 window.callback_func = callback
Tercio@11 559 window.extra_param = extraParam
Tercio@11 560 buttonsBackground:Show()
Tercio@22 561 buttonsBackground.widget:SetBackdrop (nil)
Tercio@11 562
Tercio@11 563 table.wipe (window.hooks)
Tercio@11 564 end
Tercio@11 565
Tercio@11 566 function DF:RefreshImageEditor()
Tercio@11 567
Tercio@11 568 if (edit_texture.maximize) then
Tercio@11 569 DetailsFrameworkImageEdit:SetSize (266, 226)
Tercio@11 570 else
Tercio@11 571 DetailsFrameworkImageEdit:SetSize (edit_texture.width, edit_texture.height)
Tercio@11 572 end
Tercio@11 573
Tercio@11 574 local l, r, t, b = unpack (ttexcoord)
Tercio@11 575
Tercio@11 576 if (l > r) then
Tercio@11 577 haveHFlip = true
Tercio@11 578 leftSlider:SetValue (r * 100)
Tercio@11 579 rightSlider:SetValue (l * 100)
Tercio@11 580 else
Tercio@11 581 haveHFlip = false
Tercio@11 582 leftSlider:SetValue (l * 100)
Tercio@11 583 rightSlider:SetValue (r * 100)
Tercio@11 584 end
Tercio@11 585
Tercio@11 586 if (t > b) then
Tercio@11 587 haveVFlip = true
Tercio@11 588 topSlider:SetValue (b * 100)
Tercio@11 589 bottomSlider:SetValue (t * 100)
Tercio@11 590 else
Tercio@11 591 haveVFlip = false
Tercio@11 592 topSlider:SetValue (t * 100)
Tercio@11 593 bottomSlider:SetValue (b * 100)
Tercio@11 594 end
Tercio@11 595
Tercio@11 596 if (window.callback_func) then
Tercio@22 597 window.accept (nil, nil, true)
Tercio@11 598 end
Tercio@11 599
Tercio@11 600 end
Tercio@58 601