comparison Libs/DF/pictureedit.lua @ 22:dbd417f413a8

- framework update.
author Tercio
date Tue, 08 Sep 2015 13:16:49 -0300
parents dc1c77254f80
children 7d5934415ad0
comparison
equal deleted inserted replaced
21:7fef991992f6 22:dbd417f413a8
10 window:SetPoint ("center", UIParent, "center") 10 window:SetPoint ("center", UIParent, "center")
11 window:SetResizable (true) 11 window:SetResizable (true)
12 window:SetMovable (true) 12 window:SetMovable (true)
13 tinsert (UISpecialFrames, "DetailsFrameworkImageEdit") 13 tinsert (UISpecialFrames, "DetailsFrameworkImageEdit")
14 window:SetFrameStrata ("TOOLTIP") 14 window:SetFrameStrata ("TOOLTIP")
15
16 window:SetMaxResize (266, 226) 15 window:SetMaxResize (266, 226)
17 16
18 window.hooks = {} 17 window.hooks = {}
19 18
20 local background = DF:NewImage (window, nil, nil, nil, "background", nil, nil, "$parentBackground") 19 local background = DF:NewImage (window, nil, nil, nil, "background", nil, nil, "$parentBackground")
37 end) 36 end)
38 background_frame:SetScript ("OnMouseUp", function() 37 background_frame:SetScript ("OnMouseUp", function()
39 window:StopMovingOrSizing() 38 window:StopMovingOrSizing()
40 end) 39 end)
41 40
42 local background_frame_image = background_frame:CreateTexture (nil, "background") 41 background_frame:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
43 background_frame_image:SetAllPoints (background_frame) 42 background_frame:SetBackdropColor (0, 0, 0, 0.9)
44 background_frame_image:SetTexture ([[Interface\AddOns\Details\images\welcome]]) 43 background_frame:SetBackdropBorderColor (0, 0, 0, 1)
45 44
46 local haveHFlip = false 45 local haveHFlip = false
47 local haveVFlip = false 46 local haveVFlip = false
48 47
49 --> Top Slider 48 --> Top Slider
70 topSlider:SetThumbTexture (topSliderThumpTexture) 69 topSlider:SetThumbTexture (topSliderThumpTexture)
71 70
72 topSlider:SetHook ("OnValueChange", function (_, _, value) 71 topSlider:SetHook ("OnValueChange", function (_, _, value)
73 topCoordTexture.image:SetHeight (window.frame:GetHeight()/100*value) 72 topCoordTexture.image:SetHeight (window.frame:GetHeight()/100*value)
74 if (window.callback_func) then 73 if (window.callback_func) then
75 window.accept (true) 74 window.accept (nil, nil, true)
76 end 75 end
77 end) 76 end)
78 77
79 topSlider:Hide() 78 topSlider:Hide()
80 79
103 102
104 bottomSlider:SetHook ("OnValueChange", function (_, _, value) 103 bottomSlider:SetHook ("OnValueChange", function (_, _, value)
105 value = math.abs (value-100) 104 value = math.abs (value-100)
106 bottomCoordTexture.image:SetHeight (math.max (window.frame:GetHeight()/100*value, 1)) 105 bottomCoordTexture.image:SetHeight (math.max (window.frame:GetHeight()/100*value, 1))
107 if (window.callback_func) then 106 if (window.callback_func) then
108 window.accept (true) 107 window.accept (nil, nil, true)
109 end 108 end
110 end) 109 end)
111 110
112 bottomSlider:Hide() 111 bottomSlider:Hide()
113 112
134 leftSlider:SetThumbTexture (leftSliderThumpTexture) 133 leftSlider:SetThumbTexture (leftSliderThumpTexture)
135 134
136 leftSlider:SetHook ("OnValueChange", function (_, _, value) 135 leftSlider:SetHook ("OnValueChange", function (_, _, value)
137 leftCoordTexture.image:SetWidth (window.frame:GetWidth()/100*value) 136 leftCoordTexture.image:SetWidth (window.frame:GetWidth()/100*value)
138 if (window.callback_func) then 137 if (window.callback_func) then
139 window.accept (true) 138 window.accept (nil, nil, true)
140 end 139 end
141 end) 140 end)
142 141
143 leftSlider:Hide() 142 leftSlider:Hide()
144 143
166 --]] 165 --]]
167 rightSlider:SetHook ("OnValueChange", function (_, _, value) 166 rightSlider:SetHook ("OnValueChange", function (_, _, value)
168 value = math.abs (value-100) 167 value = math.abs (value-100)
169 rightCoordTexture.image:SetWidth (math.max (window.frame:GetWidth()/100*value, 1)) 168 rightCoordTexture.image:SetWidth (math.max (window.frame:GetWidth()/100*value, 1))
170 if (window.callback_func) then 169 if (window.callback_func) then
171 window.accept (true) 170 window.accept (nil, nil, true)
172 end 171 end
173 end) 172 end)
174 173
175 rightSlider:Hide() 174 rightSlider:Hide()
176 175
189 local editingSide = nil 188 local editingSide = nil
190 local lastButton = nil 189 local lastButton = nil
191 local alphaFrame 190 local alphaFrame
192 local originalColor = {0.9999, 0.8196, 0} 191 local originalColor = {0.9999, 0.8196, 0}
193 192
194 local enableTexEdit = function (side, _, button) 193 local enableTexEdit = function (button, b, side)
195 194
196 if (alphaFrameShown) then 195 if (alphaFrameShown) then
197 alphaFrame:Hide() 196 alphaFrame:Hide()
198 alphaFrameShown = false 197 alphaFrameShown = false
199 button.text:SetTextColor (unpack (originalColor)) 198 button.text:SetTextColor (unpack (originalColor))
243 --> overlay color 242 --> overlay color
244 local selectedColor = function (default) 243 local selectedColor = function (default)
245 if (default) then 244 if (default) then
246 edit_texture:SetVertexColor (unpack (default)) 245 edit_texture:SetVertexColor (unpack (default))
247 if (window.callback_func) then 246 if (window.callback_func) then
248 window.accept (true) 247 window.accept (nil, nil, true)
249 end 248 end
250 else 249 else
251 edit_texture:SetVertexColor (ColorPickerFrame:GetColorRGB()) 250 edit_texture:SetVertexColor (ColorPickerFrame:GetColorRGB())
252 if (window.callback_func) then 251 if (window.callback_func) then
253 window.accept (true) 252 window.accept (nil, nil, true)
254 end 253 end
255 end 254 end
256 end 255 end
257 256
258 local changeColor = function() 257 local changeColor = function()
299 alphaSlider:SetOrientation ("VERTICAL") 298 alphaSlider:SetOrientation ("VERTICAL")
300 alphaSlider.thumb:SetSize (40, 30) 299 alphaSlider.thumb:SetSize (40, 30)
301 --leftSlider.backdrop = nil 300 --leftSlider.backdrop = nil
302 --leftSlider.fractional = true 301 --leftSlider.fractional = true
303 302
304 local alpha = function(_, _, button) 303 local alpha = function (button)
305 304
306 if (ColorPickerFrame:IsShown()) then 305 if (ColorPickerFrame:IsShown()) then
307 ColorPickerFrame:Hide() 306 ColorPickerFrame:Hide()
308 end 307 end
309 308
329 Alpha.clickfunction = alpha 328 Alpha.clickfunction = alpha
330 329
331 alphaSlider:SetHook ("OnValueChange", function (_, _, value) 330 alphaSlider:SetHook ("OnValueChange", function (_, _, value)
332 edit_texture:SetAlpha (value/100) 331 edit_texture:SetAlpha (value/100)
333 if (window.callback_func) then 332 if (window.callback_func) then
334 window.accept (true) 333 window.accept (nil, nil, true)
335 end 334 end
336 end) 335 end)
337 336
338 local resizer = CreateFrame ("Button", nil, window.widget) 337 local resizer = CreateFrame ("Button", nil, window.widget)
339 resizer:SetNormalTexture ([[Interface\AddOns\Details\images\skins\default_skin]]) 338 resizer:SetNormalTexture ([[Interface\AddOns\Details\images\skins\default_skin]])
373 leftCoordTexture.image:SetWidth (window.frame:GetWidth()/100*leftSlider:GetValue()) 372 leftCoordTexture.image:SetWidth (window.frame:GetWidth()/100*leftSlider:GetValue())
374 bottomCoordTexture:SetHeight (math.max ( (window.frame:GetHeight() / 100 * math.abs (bottomSlider:GetValue()-100)), 1)) 373 bottomCoordTexture:SetHeight (math.max ( (window.frame:GetHeight() / 100 * math.abs (bottomSlider:GetValue()-100)), 1))
375 topCoordTexture:SetHeight (window.frame:GetHeight()/100*topSlider:GetValue()) 374 topCoordTexture:SetHeight (window.frame:GetHeight()/100*topSlider:GetValue())
376 375
377 if (window.callback_func) then 376 if (window.callback_func) then
378 window.accept (true) 377 window.accept (nil, nil, true)
379 end 378 end
380 end) 379 end)
381 380
382 381
383 382
384 --> flip 383 --> flip
385 local flip = function (side) 384 local flip = function (button, b, side)
386 if (side == 1) then 385 if (side == 1) then
387 haveHFlip = not haveHFlip 386 haveHFlip = not haveHFlip
388 if (window.callback_func) then 387 if (window.callback_func) then
389 window.accept (true) 388 window.accept (nil, nil, true)
390 end 389 end
391 elseif (side == 2) then 390 elseif (side == 2) then
392 haveVFlip = not haveVFlip 391 haveVFlip = not haveVFlip
393 if (window.callback_func) then 392 if (window.callback_func) then
394 window.accept (true) 393 window.accept (nil, nil, true)
395 end 394 end
396 end 395 end
397 end 396 end
398 397
399 local flipButtonH = DF:NewButton (buttonsBackground, nil, "$parentFlipButton", nil, 100, 20, flip, 1, nil, nil, "Flip H", 1) 398 local flipButtonH = DF:NewButton (buttonsBackground, nil, "$parentFlipButton", nil, 100, 20, flip, 1, nil, nil, "Flip H", 1)
403 local flipButtonV = DF:NewButton (buttonsBackground, nil, "$parentFlipButton2", nil, 100, 20, flip, 2, nil, nil, "Flip V", 1) 402 local flipButtonV = DF:NewButton (buttonsBackground, nil, "$parentFlipButton2", nil, 100, 20, flip, 2, nil, nil, "Flip V", 1)
404 flipButtonV:SetPoint ("topright", buttonsBackground, "topright", -8, -160) 403 flipButtonV:SetPoint ("topright", buttonsBackground, "topright", -8, -160)
405 flipButtonV:InstallCustomTexture() 404 flipButtonV:InstallCustomTexture()
406 405
407 --> accept 406 --> accept
408 window.accept = function (keep_editing) 407 window.accept = function (self, b, keep_editing)
409 408
410 if (not keep_editing) then 409 if (not keep_editing) then
411 buttonsBackground:Hide() 410 buttonsBackground:Hide()
412 window:Hide() 411 window:Hide()
413 alphaFrame:Hide() 412 alphaFrame:Hide()
468 467
469 window:Show() 468 window:Show()
470 window.callback_func = callback 469 window.callback_func = callback
471 window.extra_param = extraParam 470 window.extra_param = extraParam
472 buttonsBackground:Show() 471 buttonsBackground:Show()
472 buttonsBackground.widget:SetBackdrop (nil)
473 473
474 table.wipe (window.hooks) 474 table.wipe (window.hooks)
475 end 475 end
476 476
477 function DF:RefreshImageEditor() 477 function DF:RefreshImageEditor()
503 topSlider:SetValue (t * 100) 503 topSlider:SetValue (t * 100)
504 bottomSlider:SetValue (b * 100) 504 bottomSlider:SetValue (b * 100)
505 end 505 end
506 506
507 if (window.callback_func) then 507 if (window.callback_func) then
508 window.accept (true) 508 window.accept (nil, nil, true)
509 end 509 end
510 510
511 end 511 end
512 512