Tercio@11: Tercio@11: local DF = _G ["DetailsFramework"] Tercio@20: if (not DF or not DetailsFrameworkCanLoad) then Tercio@20: return Tercio@20: end Tercio@20: Tercio@11: local _ Tercio@11: Tercio@11: local window = DF:NewPanel (UIParent, nil, "DetailsFrameworkImageEdit", nil, 100, 100, false) Tercio@11: window:SetPoint ("center", UIParent, "center") Tercio@11: window:SetResizable (true) Tercio@11: window:SetMovable (true) Tercio@11: tinsert (UISpecialFrames, "DetailsFrameworkImageEdit") Tercio@11: window:SetFrameStrata ("TOOLTIP") Tercio@49: window:SetMaxResize (650, 500) Tercio@11: Tercio@11: window.hooks = {} Tercio@11: Tercio@11: local background = DF:NewImage (window, nil, nil, nil, "background", nil, nil, "$parentBackground") Tercio@11: background:SetAllPoints() Tercio@11: background:SetTexture (0, 0, 0, .8) Tercio@11: Tercio@49: local edit_texture = DF:NewImage (window, nil, 650, 500, "artwork", nil, nil, "$parentImage") Tercio@11: edit_texture:SetAllPoints() Tercio@11: Tercio@11: local background_frame = CreateFrame ("frame", "DetailsFrameworkImageEditBackground", DetailsFrameworkImageEdit) Tercio@11: background_frame:SetPoint ("topleft", DetailsFrameworkImageEdit, "topleft", -10, 12) Tercio@11: background_frame:SetFrameStrata ("DIALOG") Tercio@49: background_frame:SetSize (800, 540) Tercio@11: Tercio@11: background_frame:SetResizable (true) Tercio@11: background_frame:SetMovable (true) Tercio@11: Tercio@11: background_frame:SetScript ("OnMouseDown", function() Tercio@11: window:StartMoving() Tercio@11: end) Tercio@11: background_frame:SetScript ("OnMouseUp", function() Tercio@11: window:StopMovingOrSizing() Tercio@11: end) Tercio@11: Tercio@22: background_frame:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true}) Tercio@22: background_frame:SetBackdropColor (0, 0, 0, 0.9) Tercio@22: background_frame:SetBackdropBorderColor (0, 0, 0, 1) Tercio@11: Tercio@11: local haveHFlip = false Tercio@11: local haveVFlip = false Tercio@11: Tercio@11: --> Top Slider Tercio@11: Tercio@11: local topCoordTexture = DF:NewImage (window, nil, nil, nil, "overlay", nil, nil, "$parentImageTopCoord") Tercio@11: topCoordTexture:SetPoint ("topleft", window, "topleft") Tercio@11: topCoordTexture:SetPoint ("topright", window, "topright") Tercio@49: topCoordTexture:SetColorTexture (1, 0, 0) Tercio@11: topCoordTexture.height = 1 Tercio@11: topCoordTexture.alpha = .2 Tercio@11: Tercio@11: local topSlider = DF:NewSlider (window, nil, "$parentTopSlider", "topSlider", 100, 100, 0.1, 100, 0.1, 0) Tercio@11: topSlider:SetAllPoints (window.widget) Tercio@11: topSlider:SetOrientation ("VERTICAL") Tercio@11: topSlider.backdrop = nil Tercio@11: topSlider.fractional = true Tercio@11: topSlider:SetHook ("OnEnter", function() return true end) Tercio@11: topSlider:SetHook ("OnLeave", function() return true end) Tercio@11: Tercio@11: local topSliderThumpTexture = topSlider:CreateTexture (nil, "overlay") Tercio@49: topSliderThumpTexture:SetColorTexture (1, 1, 1) Tercio@11: topSliderThumpTexture:SetWidth (512) Tercio@49: topSliderThumpTexture:SetHeight (1) Tercio@11: topSlider:SetThumbTexture (topSliderThumpTexture) Tercio@11: Tercio@11: topSlider:SetHook ("OnValueChange", function (_, _, value) Tercio@11: topCoordTexture.image:SetHeight (window.frame:GetHeight()/100*value) Tercio@11: if (window.callback_func) then Tercio@22: window.accept (nil, nil, true) Tercio@11: end Tercio@11: end) Tercio@11: Tercio@11: topSlider:Hide() Tercio@11: Tercio@11: --> Bottom Slider Tercio@11: Tercio@11: local bottomCoordTexture = DF:NewImage (window, nil, nil, nil, "overlay", nil, nil, "$parentImageBottomCoord") Tercio@11: bottomCoordTexture:SetPoint ("bottomleft", window, "bottomleft", 0, 0) Tercio@11: bottomCoordTexture:SetPoint ("bottomright", window, "bottomright", 0, 0) Tercio@49: bottomCoordTexture:SetColorTexture (1, 0, 0) Tercio@11: bottomCoordTexture.height = 1 Tercio@11: bottomCoordTexture.alpha = .2 Tercio@11: Tercio@11: local bottomSlider= DF:NewSlider (window, nil, "$parentBottomSlider", "bottomSlider", 100, 100, 0.1, 100, 0.1, 100) Tercio@11: bottomSlider:SetAllPoints (window.widget) Tercio@11: bottomSlider:SetOrientation ("VERTICAL") Tercio@11: bottomSlider.backdrop = nil Tercio@11: bottomSlider.fractional = true Tercio@11: bottomSlider:SetHook ("OnEnter", function() return true end) Tercio@11: bottomSlider:SetHook ("OnLeave", function() return true end) Tercio@11: Tercio@11: local bottomSliderThumpTexture = bottomSlider:CreateTexture (nil, "overlay") Tercio@49: bottomSliderThumpTexture:SetColorTexture (1, 1, 1) Tercio@11: bottomSliderThumpTexture:SetWidth (512) Tercio@49: bottomSliderThumpTexture:SetHeight (1) Tercio@11: bottomSlider:SetThumbTexture (bottomSliderThumpTexture) Tercio@11: Tercio@11: bottomSlider:SetHook ("OnValueChange", function (_, _, value) Tercio@11: value = math.abs (value-100) Tercio@11: bottomCoordTexture.image:SetHeight (math.max (window.frame:GetHeight()/100*value, 1)) Tercio@11: if (window.callback_func) then Tercio@22: window.accept (nil, nil, true) Tercio@11: end Tercio@11: end) Tercio@11: Tercio@11: bottomSlider:Hide() Tercio@11: Tercio@11: --> Left Slider Tercio@11: Tercio@11: local leftCoordTexture = DF:NewImage (window, nil, nil, nil, "overlay", nil, nil, "$parentImageLeftCoord") Tercio@11: leftCoordTexture:SetPoint ("topleft", window, "topleft", 0, 0) Tercio@11: leftCoordTexture:SetPoint ("bottomleft", window, "bottomleft", 0, 0) Tercio@49: leftCoordTexture:SetColorTexture (1, 0, 0) Tercio@11: leftCoordTexture.width = 1 Tercio@11: leftCoordTexture.alpha = .2 Tercio@11: Tercio@11: local leftSlider = DF:NewSlider (window, nil, "$parentLeftSlider", "leftSlider", 100, 100, 0.1, 100, 0.1, 0.1) Tercio@11: leftSlider:SetAllPoints (window.widget) Tercio@11: leftSlider.backdrop = nil Tercio@11: leftSlider.fractional = true Tercio@11: leftSlider:SetHook ("OnEnter", function() return true end) Tercio@11: leftSlider:SetHook ("OnLeave", function() return true end) Tercio@11: Tercio@11: local leftSliderThumpTexture = leftSlider:CreateTexture (nil, "overlay") Tercio@49: leftSliderThumpTexture:SetColorTexture (1, 1, 1) Tercio@49: leftSliderThumpTexture:SetWidth (1) Tercio@11: leftSliderThumpTexture:SetHeight (512) Tercio@11: leftSlider:SetThumbTexture (leftSliderThumpTexture) Tercio@11: Tercio@11: leftSlider:SetHook ("OnValueChange", function (_, _, value) Tercio@11: leftCoordTexture.image:SetWidth (window.frame:GetWidth()/100*value) Tercio@11: if (window.callback_func) then Tercio@22: window.accept (nil, nil, true) Tercio@11: end Tercio@11: end) Tercio@11: Tercio@11: leftSlider:Hide() Tercio@11: Tercio@11: --> Right Slider Tercio@11: Tercio@11: local rightCoordTexture = DF:NewImage (window, nil, nil, nil, "overlay", nil, nil, "$parentImageRightCoord") Tercio@11: rightCoordTexture:SetPoint ("topright", window, "topright", 0, 0) Tercio@11: rightCoordTexture:SetPoint ("bottomright", window, "bottomright", 0, 0) Tercio@49: rightCoordTexture:SetColorTexture (1, 0, 0) Tercio@11: rightCoordTexture.width = 1 Tercio@11: rightCoordTexture.alpha = .2 Tercio@11: Tercio@11: local rightSlider = DF:NewSlider (window, nil, "$parentRightSlider", "rightSlider", 100, 100, 0.1, 100, 0.1, 100) Tercio@11: rightSlider:SetAllPoints (window.widget) Tercio@11: rightSlider.backdrop = nil Tercio@11: rightSlider.fractional = true Tercio@11: rightSlider:SetHook ("OnEnter", function() return true end) Tercio@11: rightSlider:SetHook ("OnLeave", function() return true end) Tercio@11: --[ Tercio@11: local rightSliderThumpTexture = rightSlider:CreateTexture (nil, "overlay") Tercio@49: rightSliderThumpTexture:SetColorTexture (1, 1, 1) Tercio@49: rightSliderThumpTexture:SetWidth (1) Tercio@11: rightSliderThumpTexture:SetHeight (512) Tercio@11: rightSlider:SetThumbTexture (rightSliderThumpTexture) Tercio@11: --]] Tercio@11: rightSlider:SetHook ("OnValueChange", function (_, _, value) Tercio@11: value = math.abs (value-100) Tercio@11: rightCoordTexture.image:SetWidth (math.max (window.frame:GetWidth()/100*value, 1)) Tercio@11: if (window.callback_func) then Tercio@22: window.accept (nil, nil, true) Tercio@11: end Tercio@11: end) Tercio@11: Tercio@11: rightSlider:Hide() Tercio@11: Tercio@11: --> Edit Buttons Tercio@11: Tercio@11: local buttonsBackground = DF:NewPanel (UIParent, nil, "DetailsFrameworkImageEditButtonsBg", nil, 115, 230) Tercio@11: --buttonsBackground:SetPoint ("topleft", window, "topright", 2, 0) Tercio@11: buttonsBackground:SetPoint ("topright", background_frame, "topright", -8, -10) Tercio@11: buttonsBackground:Hide() Tercio@11: --buttonsBackground:SetMovable (true) Tercio@11: tinsert (UISpecialFrames, "DetailsFrameworkImageEditButtonsBg") Tercio@11: buttonsBackground:SetFrameStrata ("TOOLTIP") Tercio@11: Tercio@11: local alphaFrameShown = false Tercio@11: Tercio@11: local editingSide = nil Tercio@11: local lastButton = nil Tercio@11: local alphaFrame Tercio@11: local originalColor = {0.9999, 0.8196, 0} Tercio@11: Tercio@22: local enableTexEdit = function (button, b, side) Tercio@11: Tercio@11: if (alphaFrameShown) then Tercio@11: alphaFrame:Hide() Tercio@11: alphaFrameShown = false Tercio@11: button.text:SetTextColor (unpack (originalColor)) Tercio@11: end Tercio@11: Tercio@11: if (ColorPickerFrame:IsShown()) then Tercio@11: ColorPickerFrame:Hide() Tercio@11: end Tercio@11: Tercio@11: if (lastButton) then Tercio@11: lastButton.text:SetTextColor (unpack (originalColor)) Tercio@11: end Tercio@11: Tercio@11: if (editingSide == side) then Tercio@11: window [editingSide.."Slider"]:Hide() Tercio@11: editingSide = nil Tercio@11: return Tercio@11: Tercio@11: elseif (editingSide) then Tercio@11: window [editingSide.."Slider"]:Hide() Tercio@11: end Tercio@11: Tercio@11: editingSide = side Tercio@11: button.text:SetTextColor (1, 1, 1) Tercio@11: lastButton = button Tercio@11: Tercio@11: window [side.."Slider"]:Show() Tercio@11: end Tercio@11: Tercio@11: local leftTexCoordButton = DF:NewButton (buttonsBackground, nil, "$parentLeftTexButton", nil, 100, 20, enableTexEdit, "left", nil, nil, "Crop Left", 1) Tercio@11: leftTexCoordButton:SetPoint ("topright", buttonsBackground, "topright", -8, -10) Tercio@11: local rightTexCoordButton = DF:NewButton (buttonsBackground, nil, "$parentRightTexButton", nil, 100, 20, enableTexEdit, "right", nil, nil, "Crop Right", 1) Tercio@11: rightTexCoordButton:SetPoint ("topright", buttonsBackground, "topright", -8, -30) Tercio@11: local topTexCoordButton = DF:NewButton (buttonsBackground, nil, "$parentTopTexButton", nil, 100, 20, enableTexEdit, "top", nil, nil, "Crop Top", 1) Tercio@11: topTexCoordButton:SetPoint ("topright", buttonsBackground, "topright", -8, -50) Tercio@11: local bottomTexCoordButton = DF:NewButton (buttonsBackground, nil, "$parentBottomTexButton", nil, 100, 20, enableTexEdit, "bottom", nil, nil, "Crop Bottom", 1) Tercio@11: bottomTexCoordButton:SetPoint ("topright", buttonsBackground, "topright", -8, -70) Tercio@11: leftTexCoordButton:InstallCustomTexture() Tercio@11: rightTexCoordButton:InstallCustomTexture() Tercio@11: topTexCoordButton:InstallCustomTexture() Tercio@11: bottomTexCoordButton:InstallCustomTexture() Tercio@11: Tercio@11: local Alpha = DF:NewButton (buttonsBackground, nil, "$parentBottomAlphaButton", nil, 100, 20, alpha, nil, nil, nil, "Alpha", 1) Tercio@11: Alpha:SetPoint ("topright", buttonsBackground, "topright", -8, -115) Tercio@11: Alpha:InstallCustomTexture() Tercio@11: Tercio@11: --> overlay color Tercio@11: local selectedColor = function (default) Tercio@11: if (default) then Tercio@11: edit_texture:SetVertexColor (unpack (default)) Tercio@11: if (window.callback_func) then Tercio@22: window.accept (nil, nil, true) Tercio@11: end Tercio@11: else Tercio@11: edit_texture:SetVertexColor (ColorPickerFrame:GetColorRGB()) Tercio@11: if (window.callback_func) then Tercio@22: window.accept (nil, nil, true) Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local changeColor = function() Tercio@11: Tercio@11: ColorPickerFrame.func = nil Tercio@11: ColorPickerFrame.opacityFunc = nil Tercio@11: ColorPickerFrame.cancelFunc = nil Tercio@11: ColorPickerFrame.previousValues = nil Tercio@11: Tercio@11: local r, g, b = edit_texture:GetVertexColor() Tercio@11: ColorPickerFrame:SetColorRGB (r, g, b) Tercio@11: ColorPickerFrame:SetParent (buttonsBackground.widget) Tercio@11: ColorPickerFrame.hasOpacity = false Tercio@11: ColorPickerFrame.previousValues = {r, g, b} Tercio@11: ColorPickerFrame.func = selectedColor Tercio@11: ColorPickerFrame.cancelFunc = selectedColor Tercio@11: ColorPickerFrame:ClearAllPoints() Tercio@11: ColorPickerFrame:SetPoint ("left", buttonsBackground.widget, "right") Tercio@11: ColorPickerFrame:Show() Tercio@11: Tercio@11: if (alphaFrameShown) then Tercio@11: alphaFrame:Hide() Tercio@11: alphaFrameShown = false Tercio@11: Alpha.button.text:SetTextColor (unpack (originalColor)) Tercio@11: end Tercio@11: Tercio@11: if (lastButton) then Tercio@11: lastButton.text:SetTextColor (unpack (originalColor)) Tercio@11: if (editingSide) then Tercio@11: window [editingSide.."Slider"]:Hide() Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local changeColorButton = DF:NewButton (buttonsBackground, nil, "$parentOverlayColorButton", nil, 100, 20, changeColor, nil, nil, nil, "Color", 1) Tercio@11: changeColorButton:SetPoint ("topright", buttonsBackground, "topright", -8, -95) Tercio@11: changeColorButton:InstallCustomTexture() Tercio@11: Tercio@11: alphaFrame = DF:NewPanel (buttonsBackground, nil, "DetailsFrameworkImageEditAlphaBg", nil, 40, 225) Tercio@11: alphaFrame:SetPoint ("topleft", buttonsBackground, "topright", 2, 0) Tercio@11: alphaFrame:Hide() Tercio@11: local alphaSlider = DF:NewSlider (alphaFrame, nil, "$parentAlphaSlider", "alphaSlider", 30, 220, 1, 100, 1, edit_texture:GetAlpha()*100) Tercio@11: alphaSlider:SetPoint ("top", alphaFrame, "top", 0, -5) Tercio@11: alphaSlider:SetOrientation ("VERTICAL") Tercio@11: alphaSlider.thumb:SetSize (40, 30) Tercio@11: --leftSlider.backdrop = nil Tercio@11: --leftSlider.fractional = true Tercio@11: Tercio@22: local alpha = function (button) Tercio@11: Tercio@11: if (ColorPickerFrame:IsShown()) then Tercio@11: ColorPickerFrame:Hide() Tercio@11: end Tercio@11: Tercio@11: if (lastButton) then Tercio@11: lastButton.text:SetTextColor (unpack (originalColor)) Tercio@11: if (editingSide) then Tercio@11: window [editingSide.."Slider"]:Hide() Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: if (not alphaFrameShown) then Tercio@11: alphaFrame:Show() Tercio@11: alphaSlider:SetValue (edit_texture:GetAlpha()*100) Tercio@11: alphaFrameShown = true Tercio@11: button.text:SetTextColor (1, 1, 1) Tercio@11: else Tercio@11: alphaFrame:Hide() Tercio@11: alphaFrameShown = false Tercio@11: button.text:SetTextColor (unpack (originalColor)) Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: Alpha.clickfunction = alpha Tercio@11: Tercio@11: alphaSlider:SetHook ("OnValueChange", function (_, _, value) Tercio@11: edit_texture:SetAlpha (value/100) Tercio@11: if (window.callback_func) then Tercio@22: window.accept (nil, nil, true) Tercio@11: end Tercio@11: end) Tercio@11: Tercio@11: local resizer = CreateFrame ("Button", nil, window.widget) Tercio@11: resizer:SetNormalTexture ([[Interface\AddOns\Details\images\skins\default_skin]]) Tercio@11: resizer:SetHighlightTexture ([[Interface\AddOns\Details\images\skins\default_skin]]) Tercio@11: resizer:GetNormalTexture():SetTexCoord (0.00146484375, 0.01513671875, 0.24560546875, 0.25927734375) Tercio@11: resizer:GetHighlightTexture():SetTexCoord (0.00146484375, 0.01513671875, 0.24560546875, 0.25927734375) Tercio@11: resizer:SetWidth (16) Tercio@11: resizer:SetHeight (16) Tercio@11: resizer:SetPoint ("BOTTOMRIGHT", window.widget, "BOTTOMRIGHT", 0, 0) Tercio@11: resizer:EnableMouse (true) Tercio@11: resizer:SetFrameLevel (window.widget:GetFrameLevel() + 2) Tercio@11: Tercio@11: resizer:SetScript ("OnMouseDown", function (self, button) Tercio@11: window.widget:StartSizing ("BOTTOMRIGHT") Tercio@11: end) Tercio@11: Tercio@11: resizer:SetScript ("OnMouseUp", function (self, button) Tercio@11: window.widget:StopMovingOrSizing() Tercio@11: end) Tercio@11: Tercio@11: window.widget:SetScript ("OnMouseDown", function() Tercio@11: window.widget:StartMoving() Tercio@11: end) Tercio@11: window.widget:SetScript ("OnMouseUp", function() Tercio@11: window.widget:StopMovingOrSizing() Tercio@11: end) Tercio@11: Tercio@11: window.widget:SetScript ("OnSizeChanged", function() Tercio@11: edit_texture.width = window.width Tercio@11: edit_texture.height = window.height Tercio@11: leftSliderThumpTexture:SetHeight (window.height) Tercio@11: rightSliderThumpTexture:SetHeight (window.height) Tercio@11: topSliderThumpTexture:SetWidth (window.width) Tercio@11: bottomSliderThumpTexture:SetWidth (window.width) Tercio@11: Tercio@11: rightCoordTexture.image:SetWidth (math.max ( (window.frame:GetWidth() / 100 * math.abs (rightSlider:GetValue()-100)), 1)) Tercio@11: leftCoordTexture.image:SetWidth (window.frame:GetWidth()/100*leftSlider:GetValue()) Tercio@11: bottomCoordTexture:SetHeight (math.max ( (window.frame:GetHeight() / 100 * math.abs (bottomSlider:GetValue()-100)), 1)) Tercio@11: topCoordTexture:SetHeight (window.frame:GetHeight()/100*topSlider:GetValue()) Tercio@11: Tercio@11: if (window.callback_func) then Tercio@22: window.accept (nil, nil, true) Tercio@11: end Tercio@11: end) Tercio@11: Tercio@11: Tercio@11: Tercio@11: --> flip Tercio@22: local flip = function (button, b, side) Tercio@11: if (side == 1) then Tercio@11: haveHFlip = not haveHFlip Tercio@11: if (window.callback_func) then Tercio@22: window.accept (nil, nil, true) Tercio@11: end Tercio@11: elseif (side == 2) then Tercio@11: haveVFlip = not haveVFlip Tercio@11: if (window.callback_func) then Tercio@22: window.accept (nil, nil, true) Tercio@11: end Tercio@11: end Tercio@11: end Tercio@11: Tercio@11: local flipButtonH = DF:NewButton (buttonsBackground, nil, "$parentFlipButton", nil, 100, 20, flip, 1, nil, nil, "Flip H", 1) Tercio@11: flipButtonH:SetPoint ("topright", buttonsBackground, "topright", -8, -140) Tercio@11: flipButtonH:InstallCustomTexture() Tercio@11: -- Tercio@49: Tercio@49: Tercio@49: --> select area to crop Tercio@49: local DragFrame = CreateFrame ("frame", nil, background_frame) Tercio@49: DragFrame:EnableMouse (false) Tercio@49: DragFrame:SetFrameStrata ("TOOLTIP") Tercio@49: DragFrame:SetPoint ("topleft", edit_texture.widget, "topleft") Tercio@49: DragFrame:SetPoint ("bottomright", edit_texture.widget, "bottomright") Tercio@49: DragFrame:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Worldmap\UI-QuestBlob-Inside]], tileSize = 256, tile = true}) Tercio@49: DragFrame:SetBackdropColor (1, 1, 1, .2) Tercio@49: DragFrame:Hide() Tercio@49: Tercio@49: local SelectionBox_Up = DragFrame:CreateTexture (nil, "overlay") Tercio@49: SelectionBox_Up:SetHeight (1) Tercio@49: SelectionBox_Up:SetColorTexture (1, 1, 1) Tercio@49: local SelectionBox_Down = DragFrame:CreateTexture (nil, "overlay") Tercio@49: SelectionBox_Down:SetHeight (1) Tercio@49: SelectionBox_Down:SetColorTexture (1, 1, 1) Tercio@49: local SelectionBox_Left = DragFrame:CreateTexture (nil, "overlay") Tercio@49: SelectionBox_Left:SetWidth (1) Tercio@49: SelectionBox_Left:SetColorTexture (1, 1, 1) Tercio@49: local SelectionBox_Right = DragFrame:CreateTexture (nil, "overlay") Tercio@49: SelectionBox_Right:SetWidth (1) Tercio@49: SelectionBox_Right:SetColorTexture (1, 1, 1) Tercio@49: Tercio@49: function DragFrame.ClearSelectionBoxPoints() Tercio@49: SelectionBox_Up:ClearAllPoints() Tercio@49: SelectionBox_Down:ClearAllPoints() Tercio@49: SelectionBox_Left:ClearAllPoints() Tercio@49: SelectionBox_Right:ClearAllPoints() Tercio@49: end Tercio@49: Tercio@49: local StartCrop = function() Tercio@49: DragFrame:Show() Tercio@49: DragFrame:EnableMouse (true) Tercio@49: end Tercio@49: Tercio@49: local CropSelection = DF:NewButton (buttonsBackground, nil, "$parentCropSelection", nil, 100, 20, StartCrop, 2, nil, nil, "Crop Selection", 1) Tercio@49: --CropSelection:SetPoint ("topright", buttonsBackground, "topright", -8, -260) Tercio@49: CropSelection:InstallCustomTexture() Tercio@49: Tercio@49: DragFrame.OnTick = function (self, deltaTime) Tercio@49: local x1, y1 = unpack (self.ClickedAt) Tercio@49: local x2, y2 = GetCursorPosition() Tercio@49: DragFrame.ClearSelectionBoxPoints() Tercio@49: Tercio@49: print (x1, y1, x2, y2) Tercio@49: Tercio@49: if (x2 > x1) then Tercio@49: --right Tercio@49: if (y1 > y2) then Tercio@49: --top Tercio@49: SelectionBox_Up:SetPoint ("topleft", UIParent, "bottomleft", x1, y1) Tercio@49: SelectionBox_Up:SetPoint ("topright", UIParent, "bottomleft", x2, y1) Tercio@49: Tercio@49: SelectionBox_Left:SetPoint ("topleft", UIParent, "bottomleft", x1, y1) Tercio@49: SelectionBox_Left:SetPoint ("bottomleft", UIParent, "bottomleft", x1, y2) Tercio@49: Tercio@49: print (1) Tercio@49: else Tercio@49: --bottom Tercio@49: Tercio@49: end Tercio@49: else Tercio@49: --left Tercio@49: if (y2 > y1) then Tercio@49: --top Tercio@49: Tercio@49: else Tercio@49: --bottom Tercio@49: Tercio@49: end Tercio@49: end Tercio@49: Tercio@49: end Tercio@49: Tercio@49: DragFrame:SetScript ("OnMouseDown", function (self, MouseButton) Tercio@49: if (MouseButton == "LeftButton") then Tercio@49: self.ClickedAt = {GetCursorPosition()} Tercio@49: DragFrame:SetScript ("OnUpdate", DragFrame.OnTick) Tercio@49: Tercio@49: end Tercio@49: end) Tercio@49: DragFrame:SetScript ("OnMouseUp", function (self, MouseButton) Tercio@49: if (MouseButton == "LeftButton") then Tercio@49: self.ReleaseAt = {GetCursorPosition()} Tercio@49: DragFrame:EnableMouse (false) Tercio@49: DragFrame:Hide() Tercio@49: DragFrame:SetScript ("OnUpdate", nil) Tercio@49: print (self.ClickedAt[1], self.ClickedAt[2], self.ReleaseAt[1], self.ReleaseAt[2]) Tercio@49: end Tercio@49: end) Tercio@11: Tercio@11: --> accept Tercio@22: window.accept = function (self, b, keep_editing) Tercio@11: Tercio@11: if (not keep_editing) then Tercio@11: buttonsBackground:Hide() Tercio@11: window:Hide() Tercio@11: alphaFrame:Hide() Tercio@11: ColorPickerFrame:Hide() Tercio@11: end Tercio@11: Tercio@11: local coords = {} Tercio@11: local l, r, t, b = leftSlider.value/100, rightSlider.value/100, topSlider.value/100, bottomSlider.value/100 Tercio@11: Tercio@11: if (haveHFlip) then Tercio@11: coords [1] = r Tercio@11: coords [2] = l Tercio@11: else Tercio@11: coords [1] = l Tercio@11: coords [2] = r Tercio@11: end Tercio@11: Tercio@11: if (haveVFlip) then Tercio@11: coords [3] = b Tercio@11: coords [4] = t Tercio@11: else Tercio@11: coords [3] = t Tercio@11: coords [4] = b Tercio@11: end Tercio@11: Tercio@11: return window.callback_func (edit_texture.width, edit_texture.height, {edit_texture:GetVertexColor()}, edit_texture:GetAlpha(), coords, window.extra_param) Tercio@11: end Tercio@11: Tercio@11: local acceptButton = DF:NewButton (buttonsBackground, nil, "$parentAcceptButton", nil, 100, 20, window.accept, nil, nil, nil, "Done", 1) Tercio@11: acceptButton:SetPoint ("topright", buttonsBackground, "topright", -8, -200) Tercio@11: acceptButton:InstallCustomTexture() Tercio@11: Tercio@11: Tercio@11: Tercio@11: window:Hide() Tercio@11: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Tercio@11: Tercio@11: local ttexcoord Tercio@11: function DF:ImageEditor (callback, texture, texcoord, colors, width, height, extraParam, alpha, maximize) Tercio@11: Tercio@11: texcoord = texcoord or {0, 1, 0, 1} Tercio@11: ttexcoord = texcoord Tercio@11: Tercio@11: colors = colors or {1, 1, 1, 1} Tercio@11: Tercio@11: alpha = alpha or 1 Tercio@11: Tercio@11: edit_texture:SetTexture (texture) Tercio@11: edit_texture.width = width Tercio@11: edit_texture.height = height Tercio@11: edit_texture.maximize = maximize Tercio@11: Tercio@11: edit_texture:SetVertexColor (colors [1], colors [2], colors [3]) Tercio@11: Tercio@11: edit_texture:SetAlpha (alpha) Tercio@11: Tercio@11: DF:ScheduleTimer ("RefreshImageEditor", 0.2) Tercio@11: Tercio@11: window:Show() Tercio@11: window.callback_func = callback Tercio@11: window.extra_param = extraParam Tercio@11: buttonsBackground:Show() Tercio@22: buttonsBackground.widget:SetBackdrop (nil) Tercio@11: Tercio@11: table.wipe (window.hooks) Tercio@11: end Tercio@11: Tercio@11: function DF:RefreshImageEditor() Tercio@11: Tercio@11: if (edit_texture.maximize) then Tercio@11: DetailsFrameworkImageEdit:SetSize (266, 226) Tercio@11: else Tercio@11: DetailsFrameworkImageEdit:SetSize (edit_texture.width, edit_texture.height) Tercio@11: end Tercio@11: Tercio@11: local l, r, t, b = unpack (ttexcoord) Tercio@11: Tercio@11: if (l > r) then Tercio@11: haveHFlip = true Tercio@11: leftSlider:SetValue (r * 100) Tercio@11: rightSlider:SetValue (l * 100) Tercio@11: else Tercio@11: haveHFlip = false Tercio@11: leftSlider:SetValue (l * 100) Tercio@11: rightSlider:SetValue (r * 100) Tercio@11: end Tercio@11: Tercio@11: if (t > b) then Tercio@11: haveVFlip = true Tercio@11: topSlider:SetValue (b * 100) Tercio@11: bottomSlider:SetValue (t * 100) Tercio@11: else Tercio@11: haveVFlip = false Tercio@11: topSlider:SetValue (t * 100) Tercio@11: bottomSlider:SetValue (b * 100) Tercio@11: end Tercio@11: Tercio@11: if (window.callback_func) then Tercio@22: window.accept (nil, nil, true) Tercio@11: end Tercio@11: Tercio@11: end Tercio@58: