Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import c4d
- import c4d.gui as gui
- DATA = [ 'One',
- 'Two',
- 'Three' ]
- class ListViewElement(object):
- COLOR_01 = c4d.Vector(.34)
- COLOR_02 = c4d.Vector(.38)
- COLOR_TEXT = c4d.Vector(.85)
- TEXT_X = 10
- TEXT_X_ABS = True
- TEXT_Y = 0.5
- TEXT_Y_ABS = False
- TEXT_Y_CNTR = True
- def __init__(self, index, text = ''):
- self.text = text
- if not index % 2:
- self.color = self.COLOR_01
- else:
- self.color = self.COLOR_02
- def render(self, area, x1, y1, x2, y2):
- width = x2 - x1
- height = y2 - y1
- if self.TEXT_X_ABS:
- x = x1 + self.TEXT_X
- else:
- x = x1 + width * self.TEXT_X
- if self.TEXT_Y_ABS:
- y = y1 + self.TEXT_Y
- else:
- y = y1 + height * self.TEXT_Y
- if self.TEXT_Y_CNTR:
- th = area.DrawGetFontHeight()
- y = y - (th / 2.)
- x = int(round(x))
- y = int(round(y))
- area.DrawSetPen(self.color)
- area.DrawSetTextCol(self.COLOR_TEXT, c4d.COLOR_TRANS)
- area.DrawRectangle(x1, y1, x2, y2)
- area.DrawText(self.text, x, y)
- class ListViewArea(gui.GeUserArea):
- COLOR_BG = c4d.Vector(.29)
- ELEM_HEIGT = 23
- minSize = 200, 120
- def __init__(self):
- self.elems = [ListViewElement(i, e) for i, e in enumerate(DATA)]
- def DrawMsg(self, x1, y1, x2, y2, msg):
- self.OffScreenOn(x1, y1, x2, y2) # enable double buffer
- self.DrawSetPen(self.COLOR_BG)
- self.DrawRectangle(x1, y1, x2, y2)
- prevY = x1
- for elem in self.elems:
- elem.render(self, x1, prevY, x2, prevY + self.ELEM_HEIGT)
- prevY = prevY + self.ELEM_HEIGT
- def GetMinSize(self):
- return self.minSize
- class Dialog(gui.GeDialog):
- def __init__(self, area):
- self.area = area
- def CreateLayout(self):
- self.AddUserArea(1000, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT)
- self.AttachUserArea(self.area, 1000)
- return True
- def main():
- area = ListViewArea()
- dlg = Dialog(area)
- dlg.Open(c4d.DLG_TYPE_MODAL_RESIZEABLE)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement