THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 11/05/2012 at 23:55, xxxxxxxx wrote:
I don't think so, but afaik you can subclass a CustomGui, can't you? CustomGui's can be added in both.
Cheers,
PS: Here ya go, ready for the script-manager, you only have to add some paths to your icons you want to show.
import c4d
class BaseElement(object) :
def __init__(self) :
self.last_region = 0, 0, 0, 0
def __contains__(self, (x, y)) :
x1, y1, x2, y2 = self.last_region
return (x1 <= x <= x2 and y1 <= y <= y2)
def render(self, area, x, y) :
pass
class BitmapElement(BaseElement) :
def __init__(self, id, bmp, x, y) :
super(BitmapElement, self).__init__()
self.id = id
self.bmp = bmp
self.x = x
self.y = y
def render(self, area, x=0, y=0) :
x += self.x
y += self.y
w, h = self.bmp.GetSize()
self.last_region = (x, y, x + w, y + h)
area.DrawBitmap(self.bmp, x, y, w, h,
0, 0, w, h, c4d.BMP_NORMAL)
class BitmapGroup(BaseElement) :
COLOR_BG = c4d.Vector(0.21, 0.19, 0.27)
def __init__(self, x, y, w, h) :
super(BitmapGroup, self).__init__()
self.x = x
self.y = y
self.w = w
self.h = h
self.bmps = []
def add_bitmap(self, bmp) :
self.bmps.append(bmp)
def render(self, area, x=0, y=0) :
x += self.x
y += self.y
w = self.w
h = self.h
self.last_region = (x, y, x + w, y + h)
area.SetClippingRegion(self.x, self.y, self.x + w, self.y + h)
if self.COLOR_BG:
area.DrawSetPen(self.COLOR_BG)
area.DrawRectangle(x, y, x + w, y + h)
for bmp in self.bmps:
bmp.render(area, x, y)
area.ClearClippingRegion()
def what_bitmap(self, x, y) :
if (x, y) not in self:
return
hit_bmp = None
for bmp in self.bmps:
if (x, y) in bmp:
hit_bmp = bmp
return hit_bmp
class UserArea(c4d.gui.GeUserArea) :
COLOR_BG = c4d.Vector(.21)
def __init__(self) :
self.bmpgroup = BitmapGroup(0, 0, 0, 0)
def GetMinSize(self) :
return (100, 80)
def DrawMsg(self, x1, y1, x2, y2, msg) :
self.DrawSetPen(self.COLOR_BG)
self.DrawRectangle(x1, y1, x2, y2)
# adapt size of the bmpgroup
self.bmpgroup.x = x1
self.bmpgroup.y = y1
self.bmpgroup.w = x2 - x1
self.bmpgroup.h = y2 - y1
self.bmpgroup.render(self, x1, y1)
def InputEvent(self, msg) :
if msg[c4d.BFM_INPUT_DEVICE] == c4d.BFM_INPUT_MOUSE:
x, y = msg[c4d.BFM_INPUT_X], msg[c4d.BFM_INPUT_Y]
g2l = self.Global2Local()
x += g2l['x']
y += g2l['y']
if msg[c4d.BFM_INPUT_CHANNEL] == c4d.BFM_INPUT_MOUSELEFT:
bmp = self.bmpgroup.what_bitmap(x, y)
if bmp:
self.bitmap_clicked(bmp, bmp.id)
return True
# new
def bitmap_clicked(self, bmp, id) :
# TODO: implement what happens when Bitmap is clicked
print "Bitmap with id", id, "was clicked!"
pass
class Dialog(c4d.gui.GeDialog) :
def __init__(self, ua) :
self.ua = ua
def CreateLayout(self) :
self.AddUserArea(1000, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT)
self.AttachUserArea(self.ua, 1000)
return True
def main() :
ua = UserArea()
dlg = Dialog(ua)
# Add bitmaps to the BitmapGroup with an offset of 50 pixels
paths = [] # add your icons or whatever here
for i, path in enumerate(paths) :
bmp = c4d.bitmaps.BaseBitmap()
bmp.InitWith(path)
bmp = BitmapElement(i, bmp, i * 50, 0)
ua.bmpgroup.add_bitmap(bmp)
dlg.Open(c4d.DLG_TYPE_MODAL_RESIZEABLE)
if __name__ == "__main__":
main()