annotate Libs/DF/pictureedit.lua @ 11:2f09fe4be15c

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