annotate Libs/DF/pictureedit.lua @ 20:dc1c77254f80

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