View Single Post
09-15-15, 11:52 AM   #12
Gethe
RealUI Developer
 
Gethe's Avatar
Premium Member
Featured
Join Date: Sep 2008
Posts: 942
First, your OnDragStart/Stop hooks do not call your custom Move and StopMoveSize methods.

Second, instead of ceil() (not sure why I mentioned it tbh), I would round the vars using floor(var + 0.5). This is mostly to combat the fact that the numbers from GetPoint/GetSize could be +/- 0.0000002430 from the actual value. Rounding it simply gets the value back to what it should be, because when dealing with exact pixels such details make a difference.

UIParent can in most cases be assumed to have even numbered sides, and since the editor is anchored to UIParent it would be easier to just clamp the frame down the the nearest even number rather than worrying about half pixel positioning. This can easily be done using modulus (%). (Var % 2) evals to 1 if Var is odd, and evals to 0 if it's even.

The SetPoint was taken out of the if block to account for the width/height potentially being odd, and changing it to even. After using :StartSizing() the anchors of the frame are updated dynamically in the background, so if the width ends up being odd (e.g. 345) and you are anchored to the CENTER, the x offset might end up with a half (e.g. 45.5). When the side is then resized (e.g. 344), that point still remains and results in the border looking off.

Lua Code:
  1. function Editor:StopMoveSize()
  2.     if  Notepad.reFocus then
  3.         Notepad:Enable()
  4.         Notepad:SetFocus()
  5.         Notepad.reFocus = false
  6.     end
  7.     Editor:StopMovingOrSizing()
  8.  
  9.     if Editor.isSizing then
  10.         local width, height = Editor:GetSize()
  11.         width, height = floor(width + 0.5), floor(height + 0.5)
  12.         Editor:SetSize(width - (width % 2), height - (height % 2))
  13.     end
  14.  
  15.     local point, _, _, x, y = Editor:GetPoint()
  16.     Editor:SetPoint(point, UIParent, floor(x + 0.5), floor(y + 0.5))
  17.  
  18.     Editor.isSizing = false
  19.     Editor.isMoving = false
  20. end
__________________
Knowledge = Power; Be OP

  Reply With Quote