diff Console.lua @ 99:7d94df3804a7

- Console drag buttons for resizing - While dragging a console frame, other frames are ghosted out - Dropdown menu includes Toggle, Pin, and MinMax
author Nenue
date Thu, 27 Oct 2016 06:11:04 -0400
parents 33bc8baba858
children 790dca545f1d
line wrap: on
line diff
--- a/Console.lua	Wed Oct 26 10:17:43 2016 -0400
+++ b/Console.lua	Thu Oct 27 06:11:04 2016 -0400
@@ -2,17 +2,53 @@
 local _, D = ...
 DevianConsoleMixin = {}
 
+local print = function(...) print('Dvn', ...) end
+function D.IterateChannels(callback, sender)
+  for index, channel in ipairs(D.console) do
+    if channel ~= sender then
+      callback(channel)
+    end
+  end
+end
+
 function DevianConsoleMixin:OnLoad()
   self:SetMaxResize(GetScreenWidth(), GetScreenHeight())
   self:SetMinResize(100, 24)
-
   self:EnableMouse(true)
   self:RegisterForDrag('LeftButton')
   self:SetMovable(true)
   self:SetResizable(true)
+  self:SetClampedToScreen(true)
   self.out:SetFont("Interface\\Addons\\Devian\\font\\SourceCodePro-Regular.ttf", 13, 'NORMAL')
   self.out:SetJustifyH('LEFT')
   self.out:SetFading(false)
+  self.out:SetMaxLines(2048)
+
+  self:RegisterEvent('PLAYER_STARTED_MOVING')
+  self:RegisterEvent('PLAYER_STOPPED_MOVING')
+
+  UIDropDownMenu_Initialize(self.DropdownFrame, function()
+    local info = UIDropDownMenu_CreateInfo()
+    info.notCheckable = 1
+    info.text = 'Pin'
+    info.func = function() self:Pin() end
+    UIDropDownMenu_AddButton(info)
+    if self.minimized then
+      info.text = 'Maximize'
+      info.func = function() self:Maximize() end
+    else
+      info.text = 'Minimize'
+      info.func = function() self:Minimize() end
+    end
+    UIDropDownMenu_AddButton(info)
+    info.text = 'Close'
+    info.func = function() self:Toggle() end
+    UIDropDownMenu_AddButton(info)
+
+  end, 'MENU')
+  self.DropdownButton:SetScript('OnClick', function(button)
+    ToggleDropDownMenu(1, nil, self.DropdownFrame, button, 0, 0)
+  end)
 
   self.width = self:GetWidth()
   self.height = self:GetWidth()
@@ -27,10 +63,47 @@
   self:Update()
 end
 
-function DevianConsoleMixin:Update()
+local blockedType = {['table'] = true, ['function'] = true }
+local blockedKey = {[0] = true }
+
+-- Synchronize vars
+function DevianConsoleMixin:Finalize()
+  local id = self:GetID()
+  for k,v in pairs(D.channels[id]) do
+    if not self[k] then
+      D.channels[id][k] = nil
+    end
+  end
+  for k,v in pairs(self) do
+    if not (blockedType[type(v)] or blockedKey[k]) then
+      if D.channels[id][k] ~= v then
+        D.channels[id][k] = v
+      end
+    end
+  end
+end
+
+function DevianConsoleMixin:Pin(pinned)
+  self.pinned = pinned or (not self.pinned)
+  self:Update(true)
+end
+
+function DevianConsoleMixin:Update(setFinal)
   self.title:SetText(self.index..' '.. (self.signature or '?'))
-  self:SetSize(self.width, self.height)
   self:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', self.x, self.y)
+
+  if self.minimized then
+    self:SetHeight(20)
+    self:SetMaxResize(GetScreenWidth(),20)
+    self.GripBottom:Hide()
+    self.GripSide:Hide()
+  else
+    self:SetSize(self.width, self.height)
+    self.GripBottom:Show()
+    self.GripSide:Show()
+  end
+
+
   --  oldprint(self:GetName(), self.x, self.y)
 
   local isFront = D.currentProfile.current_channel == self.index
@@ -49,10 +122,18 @@
   --oldprint(self:GetID(), self.enabled, self.minimized, self.x, self.y)
   self.isFront = isFront
   self:SetShown(self.enabled)
-  self.out:SetShown(self.enabled)
+  self.backdrop:SetShown(self.enabled)
+  self.out:SetShown((not self.minimized))
+
+
+  if setFinal then
+    self:Finalize()
+  end
+
 end
 
 
+
 function DevianConsoleMixin:OnShow()
   self:Update()
 end
@@ -85,22 +166,23 @@
 end
 
 function DevianConsoleMixin:Minimize()
-  self:SetHeight(20)
-  self:SetMaxResize(GetScreenWidth(),20)
   self.minimized = true
-  self.out:Hide()
-  D.channels[self.index].minimized = true
+  self:Update(true)
 end
 
 function DevianConsoleMixin:Maximize()
-  local db = D.channels[self.index]
-  self:SetHeight(db.height)
-  self:SetMaxResize(GetScreenWidth(),GetScreenHeight())
-  self.minimized = nil
-  self.out:Show()
-  D.channels[self.index].minimized = nil
+  self.minimized = nilnil
+  self:Update(true)
 end
 
+function DevianConsoleMixin:OnMouseDown(button)
+
+  if button == 'LeftButton' then
+    self:ToFront()
+  end
+end
+
+
 function DevianConsoleMixin:OnMouseUp(button)
   if button == 'LeftButton' then
     self:ToFront()
@@ -116,19 +198,33 @@
 end
 
 function DevianConsoleMixin:OnDragStart()
-
-    self:StartMoving()
+  self:ToFront()
+  self:StartMoving()
+  D.IterateChannels(function(frame)
+    frame.out:SetShown(false)
+    frame.backdrop:Hide()
+  end, self)
 end
 
 function DevianConsoleMixin:OnDragStop()
+
+  local channelEntry = D.channels[self:GetID()]
   self.x = self:GetLeft()
   self.y = self:GetTop() - GetScreenHeight()
-  D.currentProfile.channels[self:GetID()].x = self:GetLeft()
-  D.currentProfile.channels[self:GetID()].y = self:GetTop() - GetScreenHeight()
+  if not self.minimized then
+    self.width = self:GetWidth()
+    self.height = self:GetHeight()
+  end
+
+  --print(channelEntry.x, channelEntry.y, channelEntry.width, channelEntry.height)
   self:StopMovingOrSizing()
-end
+  self:SetClampRectInsets(0,0,0,0)
 
-function DevianConsoleMixin:Reset()
+  self:Update(true)
+
+  D.IterateChannels(function(frame)
+    frame:Update()
+  end, self)
 end
 
 function DevianConsoleMixin:ToFront()
@@ -143,4 +239,52 @@
   self.enabled = (not self.enabled)
   --oldprint(self:GetID(), self.enabled)
   self:Update()
-end
\ No newline at end of file
+end
+
+function DevianConsoleMixin:OnEvent(event, arg)
+  oldprint(event, arg)
+  local db = D.db
+  if self.enabled then
+    if event == 'PLAYER_STARTED_MOVING' then
+      self.moveFade:GetProgress()
+      self.moveFade:Stop()
+      local F1 = self.moveFade.alphaOut
+      F1:SetFromAlpha(db.movement_fade_from)
+      F1:SetToAlpha(db.movement_fade_to)
+      F1:SetDuration(db.movement_fade_time)
+      self.moveFade:Play()
+      self:EnableMouse(false)
+    else
+      self.moveFade:Stop()
+      local F1 = self.moveFade.alphaOut
+      F1:SetToAlpha(db.movement_fade_from)
+      F1:SetFromAlpha(db.movement_fade_to)
+      F1:SetDuration(db.movement_fade_time)
+      self.moveFade:Play()
+      self:EnableMouse(true)
+    end
+  end
+end
+
+DevianConsoleSizeButtonMixin = {}
+function DevianConsoleSizeButtonMixin:OnLoad()
+  self:RegisterForDrag('LeftButton')
+end
+function DevianConsoleSizeButtonMixin:OnDragStart()
+  local anchor = self:GetPoint(2)
+  local frame = self:GetParent()
+  if anchor == 'BOTTOMLEFT' then
+    frame:SetClampRectInsets(frame:GetLeft(), GetScreenWidth()- frame:GetRight(), GetScreenHeight() - frame:GetTop(), 0)
+    frame:SetMinResize(frame.width, 24)
+    frame:SetMaxResize(frame.width, GetScreenHeight())
+  elseif anchor == 'BOTTOM' then
+    frame:SetClampRectInsets(frame:GetLeft(), 0, GetScreenHeight() - frame:GetTop(), GetScreenHeight() - frame:GetBottom())
+    frame:SetMinResize(200, frame.height)
+    frame:SetMaxResize(GetScreenWidth(), frame.height)
+  end
+  frame:StartSizing()
+end
+function DevianConsoleSizeButtonMixin:OnDragStop()
+  local frame = self:GetParent()
+  frame:OnDragStop()
+end