Guest User

Board

a guest
Jun 25th, 2016
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.14 KB | None | 0 0
  1. class Board(Window):
  2.  
  3.     CORNER_WIDTH = 55
  4.     CORNER_HEIGHT = 55
  5.     LINE_WIDTH = 128
  6.     LINE_HEIGHT = 128
  7.    
  8.     D = 0
  9.     LT = 0
  10.     LB = 1
  11.     RT = 2
  12.     RB = 3
  13.     L = 0
  14.     R = 1
  15.     T = 2
  16.     B = 3
  17.  
  18.     def __init__(self):
  19.         Window.__init__(self)
  20.  
  21.         self.MakeBoard("kanort_work/images/controls/common/board/corner_", "kanort_work/images/controls/common/board/bar_", "kanort_work/images/controls/common/board/decoration_")
  22.         self.MakeBase()
  23.  
  24.     def MakeBoard(self, cornerPath, linePath, decorPath):
  25.  
  26.         CornerFileNames = [ cornerPath+dir+".tga" for dir in ("lefttop", "leftbottom", "righttop", "rightbottom", ) ]
  27.         LineFileNames = [ linePath+dir+".tga" for dir in ("left", "right", "top", "bottom", ) ]
  28.         DecorFileNames = [ decorPath+dir+".tga" for dir in ("leftbottom", ) ]
  29.  
  30.         self.Corners = []
  31.         for fileName in CornerFileNames:
  32.             Corner = ExpandedImageBox()
  33.             Corner.AddFlag("not_pick")
  34.             Corner.LoadImage(fileName)
  35.             Corner.SetParent(self)
  36.             Corner.SetPosition(0, 0)
  37.             Corner.Show()
  38.             self.Corners.append(Corner)
  39.  
  40.         self.Lines = []
  41.         for fileName in LineFileNames:
  42.             Line = ExpandedImageBox()
  43.             Line.AddFlag("not_pick")
  44.             Line.LoadImage(fileName)
  45.             Line.SetParent(self)
  46.             Line.SetPosition(0, 0)
  47.             Line.Show()
  48.             self.Lines.append(Line)
  49.        
  50.         self.Decor = []
  51.         for fileName in DecorFileNames:
  52.             Decor = ExpandedImageBox()
  53.             Decor.AddFlag("not_pick")
  54.             Decor.LoadImage(fileName)
  55.             Decor.SetParent(self)
  56.             Decor.SetPosition(0, 0)
  57.             Decor.Show()
  58.             self.Decor.append(Decor)
  59.  
  60.         self.Lines[self.L].SetPosition(0, self.CORNER_HEIGHT)
  61.         self.Lines[self.T].SetPosition(self.CORNER_WIDTH, 0)
  62.  
  63.     def MakeBase(self):
  64.         self.Base = ExpandedImageBox()
  65.         self.Base.AddFlag("not_pick")
  66.         self.Base.LoadImage("kanort_work/images/controls/common/board/fill.tga")
  67.         self.Base.SetParent(self)
  68.         self.Base.SetPosition(self.CORNER_WIDTH, self.CORNER_HEIGHT)
  69.         self.Base.Show()
  70.  
  71.     def __del__(self):
  72.         Window.__del__(self)
  73.  
  74.     def SetSize(self, width, height):
  75.  
  76.         width = max(self.CORNER_WIDTH*2, width)
  77.         height = max(self.CORNER_HEIGHT*2, height)
  78.         Window.SetSize(self, width, height)
  79.  
  80.         self.Corners[self.LB].SetPosition(0, height - self.CORNER_HEIGHT)
  81.         self.Corners[self.RT].SetPosition(width - self.CORNER_WIDTH, 0)
  82.         self.Corners[self.RB].SetPosition(width - self.CORNER_WIDTH, height - self.CORNER_HEIGHT)
  83.         self.Decor[self.D].SetPosition(0 - 5, height - self.CORNER_HEIGHT)
  84.         self.Lines[self.R].SetPosition(width - self.CORNER_WIDTH, self.CORNER_HEIGHT)
  85.         self.Lines[self.B].SetPosition(self.CORNER_HEIGHT, height - self.CORNER_HEIGHT)
  86.  
  87.         verticalShowingPercentage = float((height - self.CORNER_HEIGHT*2) - self.LINE_HEIGHT) / self.LINE_HEIGHT
  88.         horizontalShowingPercentage = float((width - self.CORNER_WIDTH*2) - self.LINE_WIDTH) / self.LINE_WIDTH
  89.         self.Lines[self.L].SetRenderingRect(0, 0, 0, verticalShowingPercentage)
  90.         self.Lines[self.R].SetRenderingRect(0, 0, 0, verticalShowingPercentage)
  91.         self.Lines[self.T].SetRenderingRect(0, 0, horizontalShowingPercentage, 0)
  92.         self.Lines[self.B].SetRenderingRect(0, 0, horizontalShowingPercentage, 0)
  93.  
  94.         if self.Base:
  95.             self.Base.SetRenderingRect(0, 0, horizontalShowingPercentage, verticalShowingPercentage)
Advertisement
Add Comment
Please, Sign In to add comment