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