class ItemGrid(object):
def __init__(self, width, height):
self.grid = {}
self.gridWidth = width
self.gridHeight = height
self.gridSize = width * height
self.Clear()
def __del__(self):
self.grid = {}
self.gridWidth = 0
self.gridHeight = 0
self.gridSize = 0
def Clear(self):
for pos in range(self.gridSize):
self.grid[pos] = False
def IsEmpty(self, pos, width, height):
row = pos / self.gridWidth
if row + height > self.gridHeight:
return False
if pos + width > row * self.gridWidth + self.gridWidth:
return False
for y in range(height):
start = pos + (y * self.gridWidth)
if self.grid[start] == True:
return False
x = 1
while x < width:
x =+ 1
if self.grid[start + x] == True:
return False
return True
def FindBlank(self, width, height):
if width > self.gridWidth or height > self.gridHeight:
return -1
for row in range(self.gridHeight):
for col in range(self.gridWidth):
index = row * self.gridWidth + col
if self.IsEmpty(index, width, height):
return index
return -1
def Put(self, pos, width, height):
if not self.IsEmpty(pos, width, height):
return False
for y in range(height):
start = pos + (y * self.gridWidth)
self.grid[start] = True
x = 1
while x < width:
x += 1
self.grid[start + x] = True
return True
# C++'da (grid.h) item slotun python versiyonu.
# Ilk Yukleme
self.itemGrid = self.ItemGrid(4, 4) #4x4= 16Slot
# Memory Destroy
self.itemGrid = {}
# Slot Temizleme
if self.itemGrid:
self.itemGrid.Clear()
# Itemin boyutunu alalim.
itemVnum = 189
itemCount = 1
item.SelectItem(itemVnum)
itemIcon = item.GetIconImage()
(width, height) = item.GetItemSize() #Genislik, Yukseklik
pos = self.itemGrid.FindBlank(width, height) #Bos Slot Bul!
if pos == -1:
break
self.itemGrid.Put(pos, width, height) #Slota Ekle!
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}