From Karbust, 3 Years ago, written in Python.
Embed
  1. class Window(object):
  2.         def NoneMethod(cls):
  3.                 pass
  4.  
  5.         NoneMethod = classmethod(NoneMethod)
  6.  
  7.         def __init__(self, layer = "UI"):
  8.                 self.hWnd = None
  9.                 self.parentWindow = 0
  10.                 self.onMouseLeftButtonUpEvent = None
  11.                 self.RegisterWindow(layer)
  12.                 self.Hide()
  13.                 if app.ENABLE_SEND_TARGET_INFO:
  14.                         self.mouseLeftButtonDownEvent = None
  15.                         self.mouseLeftButtonDownArgs = None
  16.                         self.mouseLeftButtonUpEvent = None
  17.                         self.mouseLeftButtonUpArgs = None
  18.                         self.mouseLeftButtonDoubleClickEvent = None
  19.                         self.mouseRightButtonDownEvent = None
  20.                         self.mouseRightButtonDownArgs = None
  21.                         self.moveWindowEvent = None
  22.                         self.renderEvent = None
  23.                         self.renderArgs = None
  24.  
  25.                         self.overInEvent = None
  26.                         self.overInArgs = None
  27.  
  28.                         self.overOutEvent = None
  29.                         self.overOutArgs = None
  30.  
  31.                         self.baseX = 0
  32.                         self.baseY = 0
  33.  
  34.                         self.SetWindowName("NONAME_Window")
  35.  
  36.         def __del__(self):
  37.                 wndMgr.Destroy(self.hWnd)
  38.  
  39.         def RegisterWindow(self, layer):
  40.                 self.hWnd = wndMgr.Register(self, layer)
  41.  
  42.         def Destroy(self):
  43.                 pass
  44.  
  45.         def GetWindowHandle(self):
  46.                 return self.hWnd
  47.  
  48.         def AddFlag(self, style):
  49.                 wndMgr.AddFlag(self.hWnd, style)
  50.  
  51.         def IsRTL(self):
  52.                 return wndMgr.IsRTL(self.hWnd)
  53.  
  54.         def SetWindowName(self, Name):
  55.                 wndMgr.SetName(self.hWnd, Name)
  56.  
  57.         def GetWindowName(self):
  58.                 return wndMgr.GetName(self.hWnd)
  59.  
  60.         if app.ENABLE_SEND_TARGET_INFO:
  61.                 def SetParent(self, parent):
  62.                         if parent:
  63.                                 wndMgr.SetParent(self.hWnd, parent.hWnd)
  64.                         else:
  65.                                 wndMgr.SetParent(self.hWnd, 0)
  66.        
  67.                 def SetAttachParent(self, parent):
  68.                         wndMgr.SetAttachParent(self.hWnd, parent.hWnd)
  69.         else:
  70.                 def SetParent(self, parent):
  71.                         wndMgr.SetParent(self.hWnd, parent.hWnd)
  72.                        
  73.         def SetParentProxy(self, parent):
  74.                 self.parentWindow=proxy(parent)
  75.                 wndMgr.SetParent(self.hWnd, parent.hWnd)
  76.  
  77.        
  78.         def GetParentProxy(self):
  79.                 return self.parentWindow
  80.  
  81.         def SetPickAlways(self):
  82.                 wndMgr.SetPickAlways(self.hWnd)
  83.  
  84.         def SetWindowHorizontalAlignLeft(self):
  85.                 wndMgr.SetWindowHorizontalAlign(self.hWnd, wndMgr.HORIZONTAL_ALIGN_LEFT)
  86.  
  87.         def SetWindowHorizontalAlignCenter(self):
  88.                 wndMgr.SetWindowHorizontalAlign(self.hWnd, wndMgr.HORIZONTAL_ALIGN_CENTER)
  89.  
  90.         def SetWindowHorizontalAlignRight(self):
  91.                 wndMgr.SetWindowHorizontalAlign(self.hWnd, wndMgr.HORIZONTAL_ALIGN_RIGHT)
  92.  
  93.         def SetWindowVerticalAlignTop(self):
  94.                 wndMgr.SetWindowVerticalAlign(self.hWnd, wndMgr.VERTICAL_ALIGN_TOP)
  95.  
  96.         def SetWindowVerticalAlignCenter(self):
  97.                 wndMgr.SetWindowVerticalAlign(self.hWnd, wndMgr.VERTICAL_ALIGN_CENTER)
  98.  
  99.         def SetWindowVerticalAlignBottom(self):
  100.                 wndMgr.SetWindowVerticalAlign(self.hWnd, wndMgr.VERTICAL_ALIGN_BOTTOM)
  101.  
  102.         def SetTop(self):
  103.                 wndMgr.SetTop(self.hWnd)
  104.  
  105.         def Show(self):
  106.                 wndMgr.Show(self.hWnd)
  107.  
  108.         def Hide(self):
  109.                 wndMgr.Hide(self.hWnd)
  110.                
  111.         if app.ENABLE_SEND_TARGET_INFO:
  112.                 def SetVisible(self, is_show):
  113.                         if is_show:
  114.                                 self.Show()
  115.                         else:
  116.                                 self.Hide()
  117.  
  118.         def Lock(self):
  119.                 wndMgr.Lock(self.hWnd)
  120.  
  121.         def Unlock(self):
  122.                 wndMgr.Unlock(self.hWnd)
  123.  
  124.         def IsShow(self):
  125.                 return wndMgr.IsShow(self.hWnd)
  126.  
  127.         def UpdateRect(self):
  128.                 wndMgr.UpdateRect(self.hWnd)
  129.  
  130.         def SetSize(self, width, height):
  131.                 wndMgr.SetWindowSize(self.hWnd, width, height)
  132.  
  133.         def GetWidth(self):
  134.                 return wndMgr.GetWindowWidth(self.hWnd)
  135.  
  136.         def GetHeight(self):
  137.                 return wndMgr.GetWindowHeight(self.hWnd)
  138.  
  139.         def GetLocalPosition(self):
  140.                 return wndMgr.GetWindowLocalPosition(self.hWnd)
  141.                
  142.         if app.ENABLE_SEND_TARGET_INFO:
  143.                 def GetLeft(self):
  144.                         x, y = self.GetLocalPosition()
  145.                         return x
  146.        
  147.                 def GetGlobalLeft(self):
  148.                         x, y = self.GetGlobalPosition()
  149.                         return x
  150.        
  151.                 def GetTop(self):
  152.                         x, y = self.GetLocalPosition()
  153.                         return y
  154.        
  155.                 def GetGlobalTop(self):
  156.                         x, y = self.GetGlobalPosition()
  157.                         return y
  158.        
  159.                 def GetRight(self):
  160.                         return self.GetLeft() + self.GetWidth()
  161.        
  162.                 def GetBottom(self):
  163.                         return self.GetTop() + self.GetHeight()
  164.  
  165.         def GetGlobalPosition(self):
  166.                 return wndMgr.GetWindowGlobalPosition(self.hWnd)
  167.  
  168.         def GetMouseLocalPosition(self):
  169.                 return wndMgr.GetMouseLocalPosition(self.hWnd)
  170.  
  171.         def GetRect(self):
  172.                 return wndMgr.GetWindowRect(self.hWnd)
  173.                
  174.         if app.ENABLE_SEND_TARGET_INFO:
  175.                 def SetLeft(self, x):
  176.                         wndMgr.SetWindowPosition(self.hWnd, x, self.GetTop())
  177.  
  178.         def SetPosition(self, x, y):
  179.                 wndMgr.SetWindowPosition(self.hWnd, x, y)
  180.  
  181.         def SetCenterPosition(self, x = 0, y = 0):
  182.                 self.SetPosition((wndMgr.GetScreenWidth() - self.GetWidth()) / 2 + x, (wndMgr.GetScreenHeight() - self.GetHeight()) / 2 + y)
  183.  
  184.         if app.ENABLE_SEND_TARGET_INFO:
  185.                 def SavePosition(self):
  186.                         self.baseX = self.GetLeft()
  187.                         self.baseY = self.GetTop()
  188.        
  189.                 def UpdatePositionByScale(self, scale):
  190.                         self.SetPosition(self.baseX * scale, self.baseY * scale)
  191.                        
  192.         def IsFocus(self):
  193.                 return wndMgr.IsFocus(self.hWnd)
  194.  
  195.         def SetFocus(self):
  196.                 wndMgr.SetFocus(self.hWnd)
  197.  
  198.         def KillFocus(self):
  199.                 wndMgr.KillFocus(self.hWnd)
  200.  
  201.         def GetChildCount(self):
  202.                 return wndMgr.GetChildCount(self.hWnd)
  203.  
  204.         def IsIn(self):
  205.                 return wndMgr.IsIn(self.hWnd)
  206.  
  207.         if app.ENABLE_SEND_TARGET_INFO:
  208.                 def IsInPosition(self):
  209.                         xMouse, yMouse = wndMgr.GetMousePosition()
  210.                         x, y = self.GetGlobalPosition()
  211.                         return xMouse >= x and xMouse < x + self.GetWidth() and yMouse >= y and yMouse < y + self.GetHeight()
  212.        
  213.                 def SetMouseLeftButtonDownEvent(self, event, *args):
  214.                         self.mouseLeftButtonDownEvent = event
  215.                         self.mouseLeftButtonDownArgs = args
  216.        
  217.                 def OnMouseLeftButtonDown(self):
  218.                         if self.mouseLeftButtonDownEvent:
  219.                                 apply(self.mouseLeftButtonDownEvent, self.mouseLeftButtonDownArgs)
  220.                                
  221.  
  222.         if app.ENABLE_SEND_TARGET_INFO:
  223.                 def SetMouseLeftButtonUpEvent(self, event, *args):
  224.                         self.mouseLeftButtonUpEvent = event
  225.                         self.mouseLeftButtonUpArgs = args
  226.         else:
  227.                 def SetOnMouseLeftButtonUpEvent(self, event):
  228.                         self.onMouseLeftButtonUpEvent = ev
  229.  
  230.         if app.ENABLE_SEND_TARGET_INFO:
  231.                 def SetMouseLeftButtonDoubleClickEvent(self, event):
  232.                         self.mouseLeftButtonDoubleClickEvent = event
  233.        
  234.                 def OnMouseLeftButtonDoubleClick(self):
  235.                         if self.mouseLeftButtonDoubleClickEvent:
  236.                                 self.mouseLeftButtonDoubleClickEvent()
  237.        
  238.                 def SetMouseRightButtonDownEvent(self, event, *args):
  239.                         self.mouseRightButtonDownEvent = event
  240.                         self.mouseRightButtonDownArgs = args
  241.        
  242.                 def OnMouseRightButtonDown(self):
  243.                         if self.mouseRightButtonDownEvent:
  244.                                 apply(self.mouseRightButtonDownEvent, self.mouseRightButtonDownArgs)
  245.        
  246.                 def SetMoveWindowEvent(self, event):
  247.                         self.moveWindowEvent = event
  248.        
  249.                 def OnMoveWindow(self, x, y):
  250.                         if self.moveWindowEvent:
  251.                                 self.moveWindowEvent(x, y)
  252.        
  253.                 def SAFE_SetOverInEvent(self, func, *args):
  254.                         self.overInEvent = __mem_func__(func)
  255.                         self.overInArgs = args
  256.        
  257.                 def SetOverInEvent(self, func, *args):
  258.                         self.overInEvent = func
  259.                         self.overInArgs = args
  260.        
  261.                 def SAFE_SetOverOutEvent(self, func, *args):
  262.                         self.overOutEvent = __mem_func__(func)
  263.                         self.overOutArgs = args
  264.        
  265.                 def SetOverOutEvent(self, func, *args):
  266.                         self.overOutEvent = func
  267.                         self.overOutArgs = args
  268.        
  269.                 def OnMouseOverIn(self):
  270.                         if self.overInEvent:
  271.                                 apply(self.overInEvent, self.overInArgs)
  272.        
  273.                 def OnMouseOverOut(self):
  274.                         if self.overOutEvent:
  275.                                 apply(self.overOutEvent, self.overOutArgs)
  276.        
  277.                 def SAFE_SetRenderEvent(self, event, *args):
  278.                         self.renderEvent = __mem_func__(event)
  279.                         self.renderArgs = args
  280.        
  281.                 def ClearRenderEvent(self):
  282.                         self.renderEvent = None
  283.                         self.renderArgs = None
  284.        
  285.                 def OnRender(self):
  286.                         if self.renderEvent:
  287.                                 apply(self.renderEvent, self.renderArgs)
  288.                
  289.         def OnMouseLeftButtonUp(self):
  290.                 if self.onMouseLeftButtonUpEvent:
  291.                         self.onMouseLeftButtonUpEvent()
  292.